Skip to content

feat(tui): rail-and-tree transcript, ctrl+c/ctrl+x keys, token footer; plain-text titles - #1420

Merged
huichen merged 21 commits into
mainfrom
pr/huichen
Oct 29, 2026
Merged

huichen merged 21 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

What and why

The TUI transcript became a tree: a folded reply opens into a rail that nests whatever that row
opens, the chat list moved onto the header where the app's name used to be, the footer now carries
the session's input/output/cache token counts, and ctrl+c / ctrl+x take over interrupting a run
and quitting. Conversation names are now derived from a conversation's plain text — one
implementation shared by packages/rpc and packages/markdown — and two agent teardown paths were
put in the right order so a stop waits for its durable marker only after the run has stopped.

Commits

  • fix(tui): keep sessions with no message out of the rail
  • fix(desktop): keep a wheel gesture inside the scroll container it started in
  • feat(tui): show the session's input, output and cache tokens in the footer
  • fix(tui): keep the preview's control buttons on their labels
  • feat(tui): remember the workspace a new conversation starts in
  • fix(tui): spell the billion tier B, not G
  • Revert "fix(desktop): keep a wheel gesture inside the scroll container it started in"
  • fix(tui): keep a wheel burst on the surface it began over
  • feat(tui): open a folded reply as a tree that folds back
  • fix(agent): stop the run before waiting on its durable stop marker
  • feat(tui): centre the tree's rail and nest what a row opens
  • feat(tui): put the chat list on the header, where the app's name was
  • feat(tui): ctrl+c interrupts the run, ctrl+x quits
  • fix(tui): carry the tree's rail through the gap under its header
  • feat(tui): draw pasted pictures as thumbnails in the transcript
  • fix(tui): keep a blank row between a folded reply's counts and its answer
  • feat(tui): line the rail's and the picker's tails up in columns
  • fix(agent): index the symbol keys a conversation teardown checks
  • fix(session): name a conversation only after its plain text

Verification

Local pass at the frozen tip (a3e23afda), rustc/clippy 1.99.1 from ~/.rustup, ulimit -n 8192:

  • cargo fmt --all -- --check — clean
  • cargo clippy -p future-agent -p future-tui -p future-rpc --all-targets -- -D warnings — clean
  • cargo test -p future-tui --lib — 1553 passed, 0 failed, 3 ignored
  • cargo test -p future-tui --test i18n_guard — 8 passed
  • cargo test -p future-agent --lib — 2754 passed, 0 failed, 5 ignored
  • cargo test -p future-agent --lib -- session::title_preview session::database — 49 passed, 1 ignored
  • cargo test -p future-rpc --lib — 239 passed
  • npx vitest run --config ../packages/markdown/vitest.config.ts markdown/src/title (from desktop/) — 10 passed

Notes

  • The fix(desktop) wheel-gesture commit and its Revert cancel each other out; the three-dot diff
    against main contains no desktop/ file at all.
  • Documentation follows the UI: docs/guide/tui{,.zh-CN}.md, docs/tui/* and
    docs/architecture/{agent-supervision,compact-stream-layout}{,.zh-CN}.md.
  • No migration, flag or default-value change.

The agent lists a session from the moment a client creates it, before the
first prompt arrives. A session opened and never spoken in therefore stayed
in the rail as a row with neither a name nor a prompt, and the title fell
back to the head of its id — `YYYYMMDD-HHMMSS-<hash>`, so the rail showed
`20261019`: a date that is not a title, on a conversation nobody ever had
(this store carried ten of them, and finding them by eye was the only way to
notice).

The desktop never showed them: its importer waits for the first message
(`host/src/agent_bridge/import.rs`, `has_message`). The rail is the same
view, so it now drops the same rows, decided by the `queryCount` the agent
already sends — the TUI simply never parsed it. Filtering happens in
`SessionList::replace`, so every reader of the list (the rail, the 工作区
filing, the successor a delete slides into place) walks conversations rather
than session records.

A peer that predates `queryCount` omits it, and an unknown count is not an
empty session: those rows stay, so a client talking to an older agent never
loses a history to the filter.

`--continue` reads the same rule: `updatedAtMs` moves when the record is
written (a storage migration restamps every session), so the newest row can
be one nobody ever spoke in, and continuing onto it reopened an empty
transcript.
…rted in

WebKit re-targets every wheel event to whatever scrollable element is under
the pointer, so a gesture begun in the conversation list carried on in the
panel the pointer crossed: that list took the remaining delta and jumped
while the list being read stopped where it was. Chromium latches the gesture
to its starting element, which is what the layout is built around.

Latch it in the app instead: the first wheel of a gesture claims the scroll
container under the pointer, and a later event of that same gesture that
would scroll a different one is cancelled. A gap ends the gesture, so
scrolling one list and then the panel next to it is untouched.
…swer

`▸ 工具调用 62 次 · 思考 39 次` sat on the row directly above the answer's
first line, so the counts read as part of the prose they stand above
(reported 2026-10-29 against a reply that opened with a table).

The summary row is chrome that heads the answer — the demo transcript and
the desktop's process fold both leave a row between them — so the answer
now starts one blank row below it. A fold that rides on a call keeps the
call on the next row: the band already separates the two.
…ooter

The activity row carried the cache hit rate alone, so "命中 50%" was a
number with nothing to check it against. It now reads

    42 tok/s · 输入 92.0k · 输出 3.3k · 缓存 88.0k · 命中 96%

with the counts taken from the same cumulative session usage the panels
report (`inputTokens` is the provider's `prompt_tokens`, so the cache
figure is checkable by eye: 88.0k of 92.0k). `short_count` grows a `G`
tier — a long session's cumulative prompt passes a billion tokens, and
`2978.1M` is not a footer number.

The tail is the right-hand end of a row it shares with what the session
is doing, so it yields cells instead of squeezing that text out: over
`budget` it drops the cache count first, then the output, then the
input, then the rate, never the hit rate — the one figure no panel
repeats. `activity_row` hands it `columns - 22`, the floor the spinner,
kind and detail need.

Labels are the footer's own keys (`RateInput`/`RateOutput`/
`RateCacheTokens`, `in`/`out`/`cache`), and `CacheLabel` becomes
`命中 {}%` / `hit {}%` — two different numbers cannot both be called
缓存 on one row. The demo agent's usage fixture reported more cache than
prompt (9.1k input, 88k cache), which no real session can produce.
The control row is laid out in display columns, but each segment's hit
region was measured with `chars().count()`. A Hanzi is two cells, so
`[缩小]` claimed four cells and painted six, and every later button
drifted further: in the Chinese UI the row looked live while a click on
`[上一张]` landed on the counter beside it and did nothing, and `[适应]`
was dead entirely.

Measure segments in display columns, clip them to the box (a label the
box cuts off is no longer a target), and clip the finished row with
`fit` instead of the character-counting loop that could leave a row
wider than the box.

The existing test clicked the middle of each registered rect, which
resolves whatever the rect says — it could not see the labels move. The
new test clicks the cell each label is *painted* on, and presses through
to the action the key produces.
A fresh `future tui` staged its own working directory as the launchpad's
workspace, so a terminal sitting in `/tmp` filed every new conversation under
a workspace named `tmp` — the workspace picked in the previous session was
never stored anywhere.

`settings.json` now keeps `lastWorkspace`: the launchpad stages it instead of
an ambient start directory (home, a temp directory, the filesystem root), while
`cd project && future tui` still opens that project. The value is written
when a workspace is chosen (the launchpad's staging, a picker row, a worktree
row) and skipped when the directory is gone, so a removed worktree cannot
become the next conversation's directory.
Token counts are quoted in `B` (`1B tokens`); `G` reads as gigabytes on a
terminal. Same tier, same threshold — only the unit changes.
The wheel was routed per report: whatever the pointer was over when an
event arrived got the scroll. A terminal has no gesture, so a trackpad
fling or a free-spinning wheel arrives as a long run of reports that
follows the pointer — scroll the conversation, move the hand across the
divider, and the rest of the gesture walked the rail's session list under
a hand that never aimed at it.

Latch it: reports closer together than 200 ms are one burst, and a burst
stays on the surface it began over (Chromium latches a wheel gesture to
its starting element for the same reason). A longer silence is a new
burst and scrolls whatever the pointer is over by then, which is what
stopping, aiming and rolling again looks like.
Opening a folded reply or a burst of work replaced its summary row with the
rows it stood for, so the only row that could close it again was gone: an
opened fold had no way back (`ctrl+e` changes the level for the whole
session, which is not the same thing).

The summary row now stays as the fold's header — `▸` turned down into `▾` —
and the rows it stands for hang under it, one gutter in, with the rail
carried between them. Pressing the header again (`enter`, or a click) folds
them away; every row inside the tree still opens its own detail, and a
settled reply's answer stays outside the tree because it is the reply's
output rather than part of its process.

The gutter is paid for by the layout, not added on top of it: a tree row is
laid out one gutter narrower and the rail is painted on its band, so a call's
background still runs edge to edge and no row outgrows the terminal.
`ctrl+x` / `/stop` reported `Could not stop the run: Timeout expired` and the
run kept going. The stop wrote the session's durable `run_stop_requested`
marker first and only then asked the runtime to cancel, so the interruption
waited on one append in the store's single ordered writer.

Measured 2026-10-29 03:39-03:40 UTC, session 35e316b8, one live `shell` call:

- 03:39:18.678 an abort entered the handler, created its marker and blocked in
  that append; the next four presses each sat behind it (`fault_recovery`
  serializes stops) past the client's 5 s deadline, so each client reported
  `Timeout expired` while the run streamed on;
- the append finally committed at 03:40:28.6, the cancellation followed in the
  same millisecond, and the shell was interrupted and the session released
  25 ms later — the cancellation works; only its request was late;
- the run's journal shows the 71 s hole between the tool call and its result,
  with the two markers that ever landed.

The marker is still started before the run can be interrupted — recovery
resumes an unterminated run that carries no `run_stop_requested`, which is
exactly what a crash during cancellation must not do — but the stop now waits
for it only `STOP_MARKER_GRACE` (250 ms) and then interrupts regardless; a
slower write finishes on its own thread. A refused write is a warning: the
worst case is a run recovered as `interrupted_by_restart` instead of
`cancelled`, never a stop that silently did not happen.

Both docs that state the ordering say so, and two tests pin it: a stop cancels
a live run even when the journal refuses every insert (it fails on the old
order with `success:false, error:"disk failure"` and no cancellation at all),
and the marker still names the run the stop cancelled.
Three follow-ups on the opened-fold tree:

- The rail sat in column 1, one column left of the header's `▸`, so it read
  as hanging off to the side of the block it groups. It now sits in the
  marker's own column, with a column of air on each side of it.
- A row of air under the header: the tree is a block of its own, not the
  title's next line.
- What a row opens — a call's body, a reasoning block's text — now hangs one
  level deeper, under a rail of its own. At the parent's column it read as
  another sibling of it; the second level is what makes the fold a tree
  rather than a flat list beside a rail.

Both levels are paid for by the layout: a tree row and its details are laid
out narrower and the rail is painted on their band, so no row outgrows the
terminal and a call's background still runs edge to edge.
The header's right corner spent its widest form on `● future-tui v…` — a name
the row already carries twice (the brand at the left end, the window title) —
and on exactly the frames where nothing else fit it was the only thing left.

It is now the build number and the connection dot, and the cells that frees pay
for a `[ctrl+r] 会话` door beside the panel buttons. The chat list had no
pointer route at all: the rail is a keyboard surface, and on a narrow frame it
is not even beside the conversation — which is why this door is the last one a
short row gives up.

The three claims on the row (corner, doors, title) are now spent by one
`fit_row` ladder instead of an all-or-nothing group: the whole group is drawn
with as much decoration as fits — brand and build number, brand alone, neither —
then with doors from the tail, and never with the decoration back. Narrow rows
also measure the title's floor against the *frame's* width (`NARROW_WIDTH`), not
just its height, so a tall phone-sized terminal keeps the button; the brand and,
when it does not fit, the build number are what give way for it.

`app_name` leaves `WorkbenchData` with the label nothing else read.
`ctrl+c` is the one chord whose meaning is not ours to pick: raw mode turns
`ISIG` off, so the byte arrives as a key, and the reader's expectation of it
comes from the shell — interrupt the foreground turn, not close the shell.
Bound to a turn in flight it now does exactly that, and with no run in flight it
does nothing at all: `Live::abort` asks the client whether one is live before it
sends `abort`, where it used to send an empty run id and answer the reader with
an error notice for pressing a key at the wrong moment.

Leaving moves to `ctrl+x`, a chord nothing else in a terminal teaches, so it is
never pressed by reflex; quitting stays the lossless direction (the session and
its run are untouched on the agent). The quit guard that runs before every
overlay still reads the binding rather than a literal, so the way out is never a
modal's to swallow.

The exit-signal path no longer forges a `ctrl+c` byte: SIGINT/SIGTERM/SIGHUP/
SIGQUIT now post their own `TerminalEvent::Signal`, or a `kill` would have
interrupted a run and left the process alive. Attaching to a session that is
already streaming keeps the run `get_state` named — publishing the session id
cleared it, which would have made the new interrupt chord a no-op on a terminal
that had just attached.

Docs follow: the key tables in `docs/guide/tui*.md`, the READMEs (whose TUI
table still described the pre-workbench surface), the `--help` text, the queue
hint and the parity/redesign notes.
The row under an opened fold's header was empty, which cut the rail the
rows underneath hang from: the header, then a gap with nothing in it, then
rows that all start with `│`. The gap now carries the rail too — the spine
runs from the header to the last row of the fold unbroken.

Same row, same column: `push_rail_row` is the one place that draws a
rail-only row, and the separator between two rows of one fold now uses it.
A picture a message carried used to reach the transcript as a markdown caption
— the file's name, linked to its path — so the conversation said a picture was
there without showing anything of it. It now renders as a small preview: a
block of rows the surface reserves, which the terminal fills with the real
bitmap (kitty / iTerm2), and the linked caption underneath.

`tab` still steps onto that caption (one stop per picture, whatever its block
draws) and `enter` opens it in the preview box; a click on the picture itself
does the same, which is what a reader aims at.

- `session_rows` carries attachments as `ChatMessage::pictures` instead of
  splicing `![…](…)` into the content, so the renderer owns the layout
- `chat_area` reserves the slot only on a terminal that can place a bitmap; one
  that cannot keeps exactly the caption it had, and a transcript being copied
  out keeps the caption without the blank rows
- the frame turns each visible block into a placement, and one driver
  (`run::paint_images`) paints a list of pictures rather than a single one,
  deleting what the frame stopped asking for
- thumbnails are decoded off the event loop, scaled to 320px, and cached per
  path: a conversation full of attachments decodes the ones on screen
The session list behind ctrl+r printed `workspace · age` as one string, so the
divider landed wherever the workspace name happened to end — and `now` (three
cells) against `1m` (two) moved it again on the age side. The rail's two panels
had the same problem: 最近's divider drifted with the workspace name, 工作区's
with the conversation count, and a conversation's age sat at a third of the row
instead of beside the age on the heading above it.

Both surfaces now pad each part of the tail to a column measured over the rows
they are about to paint: the divider stands in one cell down the list, and every
age flushes against the same right edge. A row with no workspace keeps its age in
the age column and drops the separator, which otherwise read as a name that had
gone missing. The picker's workspace column is capped (long names ellipsise) so a
heading cannot eat the title; the rail's is capped by the half-row budget it
already had.

Also fixes the 工作区 heading row being one cell short of the panel, which put
its age one column left of every conversation age under it.
Deleting one conversation took 113 s of CPU inside the store's single ordered
writer, and every other session's writes — including a user stop — queued
behind it for 71 s (2026-10-29 03:39 UTC, `session_tombstones` row at
03:39:17.409 through the release at 03:40:28.6; five sessions' journal batches
all ended in the same millisecond, which is a queue behind one head job, not
five slow writes).

The cost was foreign-key lookups. `DELETE FROM sessions` cascades
`stream_runs` → `stream_symbols`, and SQLite resolves each child key once per
deleted symbol row. Seven of those keys had no index starting with the key
column: six symbol references on `stream_contexts` (the scoped indexes lead
with `stream_id`, and three are partial on `event_kind`, so none can serve a
lookup by symbol) and `stream_body_owners.key_id`. Each lookup scanned the
whole child table — 3.7k symbols × 75k context rows.

Measured on a copy of the 1.4 GiB store:

  DELETE FROM sessions WHERE id=<30k-change conversation>
    before: 113 s of CPU (killed at 120 s)
    after:  0.29 s

The same seven indexes cost 0.33 s to build on the real store at next open
(+5.8 MB, 0.4%) and nothing afterwards. They are plain
`CREATE INDEX IF NOT EXISTS`, in the schema batch `initialize_schema` always
runs, so existing databases gain them without a version bump or a client
handshake change, and they are deliberately not part of the compact-storage
compatibility contract (a store without them is still correct, only slow).

Two tests pin it rather than the numbers: every foreign key on the store is
planned, and a lookup that scans fails the test with the child table and
columns named. The second test drops the seven indexes, asserts exactly those
seven lookups start scanning, then reopens the store and asserts the batch
restores them — the upgrade path an existing install takes.
A TUI message that carried a pasted screenshot stores the composer's
attachment marker in its text, so an unnamed session listed as
`[Image #1]现在 tui 中显示展示思考中` — a marker nobody can read, in front of
the topic. Markdown in the first message reached the title the same way
(`**加粗**`, `` `code` ``, `# 标题`, `- 逐条`).

The shared title rule now flattens a message to plain text: composer
placeholders (`[Image #N]`, `[Pasted Content N chars(#N)]`) are dropped,
emphasis/strikethrough/code marks, headings, quotes, bullets, ordered-list
numbers and rules are removed while the text inside them stays, and only
delimiters that pair up go — `2 * 3` and `a_b_c` still read as written.
A title a model mints is flattened too.

`flatten_markup` is the one implementation in `future_rpc::title`; the Agent's
bounded paged preview applies it after its scan and skips placeholders before
they can spend the width budget, and the desktop/mobile `plainTitleText`
mirror carries the same rules with the same tests.

(cherry picked from commit 54fbf061c3129b21d1a406542c4b8920b5328ec1)
@huichen
huichen enabled auto-merge (squash) October 29, 2026 05:12
@huichen
huichen merged commit bbf3e5d into main Oct 29, 2026
34 checks passed
@huichen
huichen deleted the pr/huichen branch October 29, 2026 05:33
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