Skip to content

feat(assistant): improve the chat for daily and heavy use - #249

Merged
omznc merged 19 commits into
mainfrom
feat/better-ai
Nov 11, 2026
Merged

omznc merged 19 commits into
mainfrom
feat/better-ai

Conversation

@omznc

@omznc omznc commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

This PR makes the assistant chat better for daily use and for heavy use. It changes the web app and the mobile app together.

Changes

  • Loader: a new "Sprout" loader replaces the grid loader. The wheat of the Farmer logo grows from the stalk, then the grains drop. With reduced motion, the mark does not move.
  • Settings → AI: a new settings section. It holds the OpenRouter settings, which move from Integrations. An admin also sees the cost of the assistant for the organization, for each person and for each model.
    • A new table, assistant_usage, keeps one row for each billed model call.
  • Long chats: old tool results that are large become a short stub in the prompt. The four newest turns keep their full results.
    • A context meter shows when a chat uses 70% or more of the model's context.
  • Undo: a write by the assistant shows an Undo button. Undo is available for create_time_entry, update_time_entry, update_entry_description and set_overtime.
    • Undo refuses when the entry changed after the write, or when commits or PR activity are linked to it.
    • Undo is not available for an update to a fill-day entry, because the service calculates its duration again.
  • Edit and retry: the person can edit or retry the last question. This is blocked while a write from that turn still stands.
    • A rewind and a running turn cannot leave an answer that has no question. A rewind locks the question row first, and each turn keeps its question id from the start.
  • Suggestions: an empty chat shows suggested questions, built from the person's data for today.
  • Ctrl K / Cmd K: a shortcut opens a small "Ask the assistant" dialog on every page. A chip adds one sentence about the current page, and the person can remove it.
  • Export: a table in an answer exports as CSV or TSV, or copies to the clipboard. A chart exports as PNG. CSV cells that start like a formula get a leading '.
  • Search: the chat list has a search field. Search matches titles and message text, and shows a short snippet around the match.
  • Share: the owner can share a chat. Anyone in the organization can then open it read-only. A warning tells the owner that the chat can show data that only the owner can see. An admin can stop a share, and the audit log records each share and unshare.
    • Mobile has the same search, share and shared-chat screen.

Migrations

  • 0084: the assistant_usage table.
  • 0085: undo and undone_at on assistant_message.
  • 0086: shared_at and shared_by on assistant_conversation.

All three migrations only add a table or a column.

Out of scope

  • Saved prompts and scheduled prompts.
  • An in-app microphone. Keyboard dictation is enough.

Known gaps

  • On mobile, an admin cannot stop the share of a different person. The web app can.
  • A shared chat opens in the app only through the "Open in the app" button on the web page (farmer://). A signed-out app loses the link at sign-in.
  • Release order: deploy the server before a mobile release. The new app reads new required fields and calls new endpoints, so its assistant fails against an older server.
  • The mobile settings still hold the assistant settings. The web app moved them to Settings → AI.
  • A suggestion calculates today's logged hours on the client. It does not use services/ledger.ts. The fix needs a new server function.
  • Nobody has tested the mobile changes on an iOS or Android device.

Tests

  • bun run check, bun run typecheck and bun run complexity pass.
  • Core: 2448 pass, 2 fail. The two failures are the webhook-url IPv6 tests. They also fail locally on main, and they pass in CI.
  • Web: 327 pass, 0 fail.
  • The web features were checked by hand in a local dev server, against a fake OpenRouter.

omznc added 19 commits November 11, 2026 20:55
The loader was a 3x3 pixel grid with no tie to the brand. It is now
the wheat from the Farmer mark: the stalk draws, the grains spring
out of it, then they drop. The grains come from the MARK path
itself, so the loader and the logo cannot drift apart.
A person who takes data out of an answer had to copy markdown or
read values off a bar. Add actions to export the data.

A table gets "Download CSV" and "Copy as table" (TSV). A chart gets
"Download PNG" and "Download CSV". The actions show on hover or focus
and only on a finished answer, so a half table is never exported.

The files are built from the parsed blocks, not from the DOM. Inline
markdown is removed from each cell. The CSV follows RFC 4180, has a
BOM for Excel, and guards a cell that starts with a formula sign
unless the cell is a plain number.

The chart is HTML and CSS, not SVG. The PNG is drawn again on a
canvas at 2x from the chart spec, with the colors of the current
theme.
Every turn sends the whole thread again, and old tool results are
most of it. The wire copy now replaces a tool result over 400
characters with a short stub when it is older than the last 4 user
messages. Stored rows, call ids and the current turn do not change.

The thread payload (web and api/v1) now carries promptTokens of the
last answer and the contextLength of the thread's model. The web
composer and the mobile chat show a note when the chat uses 70% or
more of the model's memory, with a New chat action.
An admin could not see what the assistant cost. PostHog held the
figures, but the product showed none of them.

Add the assistant_usage table. generate() writes one row for each
billed call (turn step, retry and title), beside the telemetry event.
The cost is null when a stalled attempt has no usage row, so the view
counts it as unknown and not as zero. A failed insert is logged and
never fails the turn. userId has no foreign key and conversationId is
set null, so a removed person or a deleted thread keeps its cost.

Add assistantUsageService.summary (admin only). It sums in SQL for
the organization, each person and each model over a period.

Add Settings -> AI. It holds the assistant settings, moved from
Workspace -> Integrations, and a usage panel with a period picker.
Update every text that named the old place.
# Conflicts:
#	packages/core/src/services/assistant.service.ts
The assistant was only reachable from its own page. The empty chat
also showed a fixed list of questions, one with a month name.

Add Cmd+K and Ctrl+K in the org layout. The shortcut opens a small
dialog that starts a new chat in the run store, so the answer keeps
streaming after the dialog closes. A removable chip adds one sentence
that names the current page, built from the URL only. Add an "Ask
about this" button on Reports and a shortcut hint on the Chat nav row.

Build the empty-chat questions on the client from the targets, the
entries, the unfiled list and the calendar status. Never name a month.
An inline write ran with no way back. A person who saw a wrong entry
had to ask the model to fix it, which is a second write.

A tool can now set an undo capture. Before the write, the tool reads
the old state. After it, the inverse and the new updatedAt go on the
tool row (undo, undone_at). assistantService.undo claims the row and
runs the inverse through timeEntriesService. It refuses when the entry
changed since. The wire copy of an undone result tells the model.

Undo exists for create_time_entry, update_time_entry,
update_entry_description and set_overtime. The other writes have no
exact inverse.

replaceLastTurn removes the last question and the rows after it, in
one transaction under row locks. It refuses after a write that was not
undone. Usage rows stay.

Web, the REST API (undo and rewind routes) and the mobile app get
Undo, Edit and Retry. The migration is 0085.
# Conflicts:
#	apps/web/src/routes/$orgSlug/assistant.tsx
A person could not find an old chat, and could not show one to a
colleague.

Search: assistantService.search matches the title and the text of user
and assistant rows in the caller's own chats. It escapes LIKE wildcards,
as ledger.ts does. It returns at most 30 chats with a short snippet.

Share: a chat gets sharedAt and sharedBy (migration 0086). The owner
shares it. Any member of the org can read it, read only, behind a
warning, because a chat can hold results that were read with the
owner's access. The owner or an Admin stops the share. Both changes
write an audit row.

Web: a search field in the chat rail, a Share dialog, and a read-only
route for a shared chat. REST: search, share and shared-thread routes.
Mobile: search on the thread list, Share in the chat header, and a
read-only shared chat screen.
After a rewind, the question is gone from the thread. If the resend
then failed, the text was lost apart from a toast. The web and the
mobile app now put the text back in the composer and focus it.

The refusal for a turn with a write that has no inverse said "Undo the
change first", which the person cannot do. The core error now depends
on the case, in one pure helper (editBlockReason). The API message
carries a new `changed` field, so the web app and the mobile app show
the same text on the disabled Edit and Retry buttons.
A search snippet was cut from the raw message text. It showed
markdown, chart JSON and directive syntax.

Turn the message into plain text first. Drop fenced blocks, turn
date directives into the date, and strip emphasis, code ticks,
links, heading marks and table pipes. A match that sat only in a
removed block falls back to the start of the text.
Shorten long comments in the AI settings page, the reports tab link
and the sprout loader. Keep each reason, drop the history and the
restated code. Remove one stray comma in the integrations doc.

No behavior change.
Drop the answer of a turn when its question row was removed while the
model wrote. A share lock on the question row makes the check and the
insert one step.

Refuse the undo of a created entry when it holds commits or reviews.
These rows do not change updatedAt, so the staleness guard misses them.

Offer no undo for an update of a fill-day entry. The update recomputes
the duration, so the inverse is not exact.

Count the four refusals that run before a tool as not run, so edit and
retry are not blocked.

Key the model catalogue cache per organization. Cache a failure for 60
seconds and log the error.

Read the sharer name with one query in place of the whole roster.

Read only a window around the match in the chat search.

Let the CSV guard keep durations such as -1:30 and signed currency
amounts such as -EUR 5 unchanged.

Correct a comment on the tool result window.
The form was a grid with an auto column, so a long page sentence
widened the dialog and made it scroll sideways instead of truncating.
Focus also landed on the chip's remove button, not the question field.
Ctrl K opens the same dialog on every page, with the same page
sentence, so the button on Reports only took room from the tabs.
The first fix had three gaps.

replaceLastTurn locked every thread row in one statement. If it
waited on the question row, its snapshot missed an answer that
committed meanwhile, and it left that row behind. Lock the question
row alone first, then read the thread in a second statement.

The question id was read from history at each step. After a rewind
it could name the previous turn, or be null and skip the check.
Capture the id once when the turn starts, keep it on the turn run
state, and drop the answer when the row is missing. A resumed turn
uses the last user row.

claimCalls could write tool rows for a deleted turn. Check the
question row inside its transaction.

applyUndo checks commit evidence outside the delete transaction.
time-entries remove has no refuse option, so keep the check and
note the small window.
Hide tool data from a shared thread. getShared now returns only user
and assistant rows, with toolCalls and approval fields set to null.

Return the undone row from undo. The route no longer calls the full
conversation get, which can call OpenRouter.

Return null from contextLengthOf when the assistant is off. Share one
catalogue load for each organization.

Reset the edit state when the thread changes. Show an error state in
the chat search, and limit the search input to 100 characters.

Limit the Cmd+K question, report a send failure with a toast, and
strip quotes and newlines from the project name in the page sentence.

Keep typed text in the mobile composer when a failed send gives text
back. Append the failed text below it.

Read the first search hit with DISTINCT ON in Postgres. Name the 422
and 404 cases in the OpenAPI text and regenerate the api-client.

Revoke the export object URL after a delay.
A shared chat had a web link only. A phone with the app had no way
to open the chat in the app.

Add an "Open in the app" link to the web page. It shows on a phone
only and points to farmer://assistant/shared/<id>?org=&server=.

The app compares org and server with the signed-in workspace. On a
mismatch it does not fetch. It names the server host and the org, so
the person knows which workspace to switch to.
@omznc
omznc marked this pull request as ready for review November 11, 2026 23:06
@omznc
omznc requested a review from a team as a code owner November 11, 2026 23:06
@omznc
omznc merged commit 916433c into main Nov 11, 2026
7 checks passed
@omznc
omznc deleted the feat/better-ai branch November 11, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant