Skip to content

feat(sessions): full-text search, live updates and in-progress sessions - #93

Merged
sylearn merged 5 commits into
mainfrom
feat/session-search-live
Nov 2, 2026
Merged

sylearn merged 5 commits into
mainfrom
feat/session-search-live

Conversation

@sylearn

@sylearn sylearn commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #92: the first two items of the Session Center roadmap. Design notes are in docs/SESSION_CENTER_DESIGN.md §3.2, §3.4 and §3.5.

Full-text search (opt-in)

  • SessionSearchIndex: SQLite FTS5 with the trigram tokenizer, so Chinese works without word segmentation. Terms shorter than three characters (e.g. 登录) can't use trigram and fall back to LIKE with %/_ escaped.
  • Indexes what the reader shows: prompts, replies and tool steps (name, command or path, failure reason). Raw tool output (file contents, command output) stays out; it would multiply the index size and make common words match almost every session.
  • One row per transcript item with its position, so a hit can be scrolled to. Multi-word queries are AND across both list metadata and content ("app 缓存" can match the folder and a reply).
  • Incremental per session by version (updated time + prompt count); running sessions wait until they stop; removed sessions are dropped; user_version mismatch rebuilds.
  • Off by default: it stores a copy of session text, which the page otherwise promises not to do. Turning it on shows a prompt explaining the index (~/Library/Caches/AIUsage/Sessions, 0700/0600, never uploaded); turning it off deletes it.
  • UI: hint under the search field ("titles, folders and prompts only · include replies"), build progress, a matching-line excerpt under each result with highlighted terms, and the reader scrolls to the hit. Long replies are aligned by the hit's relative position so a match near the end is on screen.

Live updates

  • SessionSourceMonitor: FSEvents on the three data directories, filtered to session records. Codex's log database, -shm files and Claude debug output are ignored.
  • Only runs while the Session Center page or the menu bar Recent Sessions is visible. Changes are coalesced into at most one scan every 1.5 s. The 30 s timer stays as a fallback for process exits and expiring in-progress state.
  • Claude session files are append-only, so changed files are now read from the last offset instead of from the start. An inode change, a smaller file, or an offset not right after a record falls back to a full read. Before this, a 14.7 MB session cost ~0.25 s on every change; during an active session that is a steady 10%+ CPU.
  • The open transcript keeps its content and scroll position while it reloads, and follows new content when scrolled to the bottom.

In progress

  • Claude Code: ~/.claude/sessions/<pid>.json. The pid must be alive and its start time (sysctl) must match procStart, the same check Claude Code uses, so reused PIDs don't count. idle shows "Waiting for input", anything else shows "In progress".
  • Codex: the thread's latest turn is inProgress in thread_turns and had activity in the last 30 minutes. This Mac has four crash-leftover inProgress turns (oldest from June) that the window excludes.
  • OpenCode: v1 database only (last message is an assistant message without time.completed, within 30 minutes). The legacy JSON storage rewrites message files in place, so the scan cache can't see completion. v2 has no sample yet.
  • Resuming an in-progress session asks first.

Testing

  • swift test --package-path QuotaBackend: 503 tests pass (3 skipped, as on main), including 14 new SessionLiveSearchTests:
    • incremental reads match a full read, and rewritten or replaced files are re-read from the start
    • registry: busy/idle, reused pid, dead pid, parked job
    • Codex/OpenCode time windows
    • index: excerpts with scroll positions, mixed metadata/content queries, 2-character Chinese, % _ and quotes, incremental updates, schema rebuild, permissions, no recreation after delete
    • a real FSEvents round trip
  • Debug app build passes with no warnings in touched files.
  • Real data (163 sessions): first index build 1.2 s, 3.8 MB; no-change sync 0.2 ms; searches 1–11 ms. Searching 缓存 went from 1 result to 9.
  • End to end in a fake home, driving the real SessionCenterStore:
    • an appended turn reached the list and the open reader in 1.5 s, with no flash back to loading
    • registering/removing a process toggled the label in ~1.5 s
    • no scans after the views closed
  • UI checked with offscreen renders from real data (light, dark, narrow, English, menu bar). They caught three bugs, fixed here:
    • events under /private/var were filtered out
    • excerpts could push the hit past the two visible lines
    • re-selecting a session under a new query didn't jump to the new hit

Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01V35ctfkV86ww1dY6Gs1d9d

sylearn and others added 3 commits November 2, 2026 11:00
- SessionSearchIndex: opt-in SQLite FTS5 (trigram) index of what the
  reader shows (prompts, replies, tool steps with their errors), one row
  per transcript item so a hit can be scrolled to. Terms shorter than
  three characters fall back to LIKE. Updated per session by version;
  running sessions wait until they stop, gone sessions are dropped, and a
  schema version mismatch rebuilds it. Lives in
  ~/Library/Caches/AIUsage/Sessions (directory 0700, file 0600).
- SessionSourceMonitor: FSEvents on the three data directories, filtered
  to session records (Codex logs, -shm files and Claude debug output are
  ignored). Roots go through realpath, because
  URL.resolvingSymlinksInPath strips /private and events under
  /private/var never matched.
- Claude: appended records are read from the last offset instead of
  re-parsing the whole file; an inode change, a smaller file or an offset
  not right after a record falls back to a full read. A 14.7 MB session
  took ~0.25 s on every change before.
- In progress: Claude Code's sessions/<pid>.json registry (pid alive and
  its start time matches procStart), Codex's latest inProgress turn and
  OpenCode v1's unfinished assistant message, the last two only within
  30 minutes so crash leftovers expire.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V35ctfkV86ww1dY6Gs1d9d
- The Session Center page and the menu bar Recent Sessions watch for
  changes while visible and rescan within ~1.5 s; nothing runs when both
  are hidden. The open transcript keeps its content and scroll position
  while it reloads, and follows new content when scrolled to the bottom.
- "In progress" / "Waiting for input" labels in list rows, the reader
  header and the menu bar. Resuming an active session asks first, since
  two processes would write to the same session.
- Full-text search is off by default. It is turned on from the hint under
  the search field or the "…" menu, after a prompt that explains the
  local index; turning it off deletes the index. Results show the
  matching line, and opening one scrolls to it with the terms
  highlighted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V35ctfkV86ww1dY6Gs1d9d
Copilot AI balanced review requested due to automatic review settings November 2, 2026 02:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

sylearn and others added 2 commits November 2, 2026 11:07
The Xcode 26 compiler on the macos-26 runner crashed ("failed to produce
diagnostic") on an expression that declared a local `excerpt` while
calling the `excerpt(session:…)` method inside its own initializer,
through nested optionals. Swift 6.4 accepted it. That expression and two
similar ones (a double-optional `?? nil`, and the same shadowing in the
store's `select`) are now plain `if let` code.

Also fixes two warnings the earlier build check missed: the app target
defaults to MainActor isolation, so the cancellation flag read by the
background indexer is now `nonisolated`, and the file-watcher callback
unwraps `self` before hopping to the main actor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V35ctfkV86ww1dY6Gs1d9d
- Reader header stays on one line: the resume label shortens, then the tool
  name, the copy button and the status text fold away as space runs out.
- Metadata is fixed at two lines (location, then facts) and truncates
  instead of running past the edge; long titles stop at three lines.
- Resume is an accent split button (resume / choose terminal); copy and
  more are matching icon buttons.
- Collapsed step groups hug their summary; inline code gets a background;
  English plurals are correct ("1 step", "ran 1 command").
- Working sessions show in green, waiting-for-input in amber.
- Tool filter segments size to their labels; footer fits on one line with
  key hints; empty search offers the next step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V35ctfkV86ww1dY6Gs1d9d
@sylearn
sylearn merged commit dd8ca2d into main Nov 2, 2026
2 checks passed
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