feat(web): expose read-only terminal session history - #397
Conversation
tt-a1i
left a comment
There was a problem hiding this comment.
The read-only terminal-history bridge is valuable, but its current discovery path introduces a P2 history-size-dependent workload on every page and preview. The inline finding was reproduced with real default Pi Session files; focused adapter/host tests pass42/42. Please correct the source-read boundary before merge. No author code was modified, and no installed/deployed performance measurement is claimed.
|
Source-read follow-up (2026-09-09). This PR is still the leftover file-history slice, not live attach. Status. OPEN, What this PR actually does. What it is not. Opening that JSONL later is history. It does not attach the Web Host to the TUI process that still has the file open. Background Terminal / Subagent / Workflow managers are process-local objects keyed by the live Relation to Please keep the P2 source-read fix on this PR (discover the selected workspace first; bound and cancel transcript work; prove unrelated workspace files are not parsed). Rebase onto current main after that. Do not expand the PR into live attach, and do not treat a future merge as “Web can see my running TUI |
|
Replacement-test follow-up (2026-09-09). Head still Must hold
Missing vs current 42/42 (single-fixture) tests — fail closed
Keep existing label / empty- |
|
Fixed and pushed as
|
|
Review follow-up pushed as |
tt-a1i
left a comment
There was a problem hiding this comment.
Reviewed exact head 11348ee.
This is a useful read-only backend seam for terminal Session history, and the earlier global-history scan, cross-workspace exposure, and unbounded transcript accumulation are fixed. I found no P0/P1. Two P2 correctness/boundedness issues remain:
- The 256 KiB prefix is presented as complete metadata. I reproduced a valid 581,477-byte Session with 2,201 messages being reported as 996; a later session_info rename was omitted and an exact search for that name returned zero results. Expose truncation/approximation explicitly or derive correct bounded metadata.
- Discovery readdir/stat calls are not fully bounded: all .jsonl entries are statted concurrently before WEB_MAX_SESSIONS is applied. Filesystem calls and memory still scale with the whole directory.
Focused exact-head tests pass 44/44 and required CI is green. I am not auto-merging because this changes core Session-history discovery and identity semantics; the remaining P2s directly affect the feature contract, and there is not yet user-facing browser acceptance.
Problem
Related to #347. Web cannot inspect terminal/default Pi Session history without conflating history observation with activation. Review identified global transcript discovery and missing cancellation of preview work.
Value
Expose a workspace-scoped, read-only history API without copying terminal Sessions, switching the Web controller, or attaching to a running TUI process.
Approach
GET /api/terminal-sessionswith bounded query/cursor/limit validation.SessionManager.listAll()or the mkdir-producingSessionManager.list(workspace)path. Read at most 256 KiB per candidate for at mostWEB_MAX_SESSIONScandidates; never retainallMessagesText.loadSessionPreviewData(path, { signal })with 80-message / 1 MiB retained-output limits.source: "pi-default",origin: "terminal",readOnly: true; reject mutations with 405 and unavailable targets with 404SESSION_NOT_FOUND.Validation
Revalidated on 2026-09-09 using Node 24 and Bun 1.3.14:
bun run check: passed.bun run test: Node 1467 passed, 1 skipped; Vitest 130 passed.Impact
/psstate. Metadata scans remain capped prefixes and candidate-directory stat work is not an indexed catalog. Maintainer approval is still required.