Skip to content

feat(terminal): find bar over the scrollback, and opt-in saved history search - #842

Open
opticon454 wants to merge 1 commit into
Ark0N:masterfrom
opticon454:feature/terminal-search
Open

opticon454 wants to merge 1 commit into
Ark0N:masterfrom
opticon454:feature/terminal-search

Conversation

@opticon454

Copy link
Copy Markdown
Contributor

What

Two ways to find text from earlier in a session, without asking the AI to recall it.

  1. Find bar over the live terminal scrollback: Ctrl/Cmd+Shift+F, on by default (terminalFindEnabled, Settings; an absent key means on). Uses @xterm/addon-search, bundled like the other xterm addons.
  2. Saved history search, opt-in (transcriptSearchEnabled, default off, Settings > Cross-session features). While on, each live session is saved as plain text and searched from the same box: the find bar searches the terminal as you type and the saved copy a moment later, and the count says where a match is ("Not in terminal, 1 in history"). A hit opens in place with 20 lines of context and a Copy button.

Why a saved copy

Claude Code's fullscreen UI keeps its older text in its own scrollback, so the xterm buffer holds only the screen and the find bar cannot see it. A local Claude session is therefore saved from its conversation file (your prompts, Claude's text, one line per tool call; no tool results or thinking). Other CLIs are saved from the tmux pane scrollback, which is as deep as that CLI leaves it.

Storage and clearing

Off means no files. Files are ~/.codeman/transcripts/<sessionId>.txt (folder 0700, file 0600, newest 16 MiB, written through tmp and rename), the same pattern as the agent inbox snapshot. They are deleted with the session (the edit-history deletion call sites), by a startup sweep, by Settings > Clear saved history, and by switching the setting off. They are never fed to /api/v1/search, and sensitive-path.ts keeps the file viewer off the folder.

Known limit

Because a fullscreen CLI keeps its older text itself, Find in terminal can only reach text that is on screen. When it cannot, the toast says why, and the expanded hit and Copy are the way to read it. Scrolling the CLI's own view from the find bar is not done.

API

GET /api/sessions/:id/transcript/search, GET /api/sessions/:id/transcript/lines, DELETE /api/sessions/:id/transcript, DELETE /api/transcripts (admin only in multi-user mode). Documented in docs/api-reference.md and docs/wiki/Settings-Reference.md.

Testing

New tests: transcript-store, transcript-recorder, transcript-routes, claude-transcript-text, terminal-find. npm run typecheck, eslint and format:check are clean. Full npm test on a rebased tree: 17348 passed, 1 failed, test/remote-pane-command-shell.test.ts "starts /bin/sh when SHELL is unset", which fails identically on a clean upstream/master and is unrelated. Also driven in headless Chromium against a running server (open, type, hit, expand, copy, clear, Esc).

No changeset added (generated at release).

…y search

Find bar (Ctrl/Cmd+Shift+F, on by default, Settings > terminalFindEnabled)
searches the live xterm scrollback with @xterm/addon-search.

Saved history search (transcriptSearchEnabled, off by default) saves each
live session as plain text under ~/.codeman/transcripts, searches it from
the same box, shows a hit with 20 lines of context and a Copy button, and
deletes it with the session, on a startup sweep, from Settings (Clear
saved) and when the setting is switched off. A local Claude session is
saved from its conversation file, because Claude's fullscreen UI keeps its
older text in its own scrollback and the terminal holds only the screen;
other CLIs are saved from the pane scrollback.

Files are 0600 in a 0700 folder, never read by /api/v1/search, and the
file routes refuse the folder as sensitive.
@Ark0N

Ark0N commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you for this PR. It adds a Ctrl/Cmd+Shift+F find bar over the terminal scrollback (xterm's SearchAddon) and an opt-in saved history: a server timer writes each session's text to ~/.codeman/transcripts/<id>.txt every minute, so the bar can search further back than the browser holds. The find bar is careful work. The store follows the house rules for secrets on disk: 0600, tmp + rename, dataPath(), findSessionOrFail with req, kept off /api/search, listed in sensitive-path.ts, and the boot sweep runs only after a successful restore. Typecheck, lint, format, the frontend checks and your new tests all pass here.

Open question (for the maintainer, not for you to resolve)

Should saved history be a second copy on disk that a timer refreshes, or a search that reads the live sources when the user searches (the tail of the Claude conversation file, or one async capture-pane for other CLIs)? That is still open. What it rests on: save() replaces the whole file on each tick, so for non-Claude sessions the copy is never deeper than tmux's own history, and for local Claude sessions it is the tail of a JSONL that is already on disk. The copy is deleted with its session, and the routes resolve it through findSessionOrFail, which only finds live sessions, so it can only be searched while those sources exist. The sibling Edit history panel was built "reads only on request, no timer" (docs/architecture-invariants.md, Edit history panel). On this machine, parsing a 32 MiB JSONL took about 86 ms and searching a 16 MiB copy about 103 ms. Please hold further work on the saved-history half until this is answered.

Splitting

The find bar does not depend on the store, so if you move it into its own PR it does not have to wait for that question. It needs two changes.

  1. Shortcut registry and Escape (src/web/public/terminal-ui.js:7621-7633). src/web/CLAUDE.md asks for shortcuts to live in the rebindable registry (DEFAULT_SHORTCUTS in app.js) and to be listed in its keyboard-shortcut paragraph. The hard-coded chord can't be rebound and doesn't show in the Ctrl+? overlay. Separately, the global capture-phase Escape handler (src/web/public/app.js:1425) runs before the bar's own listener and calls closeAllPanels() and friends, so pressing Esc in the bar also closes App Settings or an open side panel. Please add an early return there for an Escape inside #terminalFindBar, the way tabRailSearch has one.
  2. Tile grid (src/web/public/terminal-ui.js:7740). The SearchAddon is loaded on the main terminal only. While the tile grid is open, that terminal is parked and hidden with stale content and activeSessionId is the focused tile's session, so the match count and the history hits come from two different sessions. Please skip opening the bar while _tilesOwnTerminal() is true, or search the focused tile instead.

Saved history, if it keeps its current shape

These apply only if the copy on disk stays.

  1. The delete buttons do not stick (src/web/transcript-recorder.ts:62). After "Clear saved" or "Delete all saved history now", the next tick sees a new generation, captures with force and writes the same text back within 60 seconds. test/transcript-recorder.test.ts:62 asserts exactly that, while the tooltip and docs/wiki/Settings-Reference.md:152 say the copy is deleted. Please either drop the two buttons and say that switching the setting off is the delete, or make a delete stick for that session.
  2. Only the current Claude conversation is kept (src/web/server.ts:2848). After /clear the watcher follows the new JSONL and the copy is replaced, so everything before the clear is gone, and every respawn cycle clears. Session.claudeSessionChain already lists the conversations. Please read across it (bounded) or document the limit.
  3. Multi-user tests (test/routes/transcript-routes.test.ts). Please add one where another user's session answers 404 on search, lines and delete, and one where a non-admin DELETE /api/transcripts answers 403.
  4. Reuse the existing locator (src/claude-transcript-text.ts:84). resolveClaudeTranscript / findClaudeTranscript in src/edit-history-local-source.ts already do this, taking the newest mtime across project folders. Keep your bounded probe of a relocated config dir in front of it.
  5. Docs. docs/wiki/Settings-Reference.md:147-149 describes a History button that lists lines and a click that jumps, but the shipped bar searches automatically and a click expands the hit. src/web/public/index.html:2315 says it saves "each session's terminal", though a Claude session is saved from its conversation file. The State Files list in CLAUDE.md should include transcripts/<id>.txt.

Smaller items, which can also be done at merge time:

  • src/web/server.ts:2829 and :3566: two existing comments now sit above the new code instead of the code they describe.
  • src/claude-transcript-text.ts:128: signatures is never pruned (forget() has no caller). It is also set before the save runs, so a failed save is not retried until the file changes.
  • src/transcript-store.ts:109-110: if the setting is switched off between the enabled check and the rename, one file is left behind until the next boot.
  • src/web/public/terminal-ui.js:7848: "Find in terminal" overwrites the user's query with a prefix of the hit.
  • src/web/public/index.html:2305: the find bar row sits under "Cross-session features".

Next

The saved-history half waits on the open question above. The find bar items apply either way, so a separate find bar PR with the two changes under Splitting can be reviewed without waiting for it. Thanks again for the careful work on the store's lifecycle and the docs.

@opticon454

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review. I have split the find bar out as #843, with both requested changes (the rebindable find-in-terminal registry entry plus the Escape early return, and the find bar staying off while the tile grid owns the terminal).

I am holding the saved history work here until you have answered the open question about a copy on disk versus reading the live sources on search. The other saved-history items (the delete buttons not sticking, only the current Claude conversation being kept, the multi-user tests, reusing the edit-history locator, the docs and the smaller items) will be done once that is settled. When #843 merges I will rebase this PR onto it so it carries only the saved history.

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.

2 participants