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.
| const query = options.query?.trim().toLocaleLowerCase() ?? ""; | ||
| const cursor = options.cursor ?? 0; | ||
| const limit = options.limit ?? 50; | ||
| const sessions = (await SessionManager.listAll()) |
There was a problem hiding this comment.
[P2] Scope history discovery before reading every workspace transcript
SessionManager.listAll() without a directory enumerates all default Pi workspaces; its buildSessionInfo reads each whole JSONL and retains allMessagesText. Filtering by the current workspace and slicing the page afterward does not bound that work. getReadOnlyTerminalSession at line488 repeats the same scan before the bounded preview loader. Reproduction with one target Session plus ten unrelated workspace Sessions of512KiB each: list(limit=1) and then preview each independently load11 Sessions, including10 unrelated workspaces, and retain5,242,886 message characters while returning only one row/two preview messages. Every page and preview therefore scales with all personal history and has no source-byte/time/cancellation bound. Restrict discovery to the selected workspace before loading transcripts and keep lookup/preview work bounded and cancellable; add coverage proving unrelated workspace files are not parsed for this route.
Problem
Related to #347. The Web workbench has no way to discover compatible terminal/default Pi Sessions without copying them into Web storage or switching the active Web controller. This makes existing history invisible and risks conflating observer access with control.
Value
Provides a bounded, explicit read-only bridge to Pi's default Session source so users and future UI work can inspect terminal history while preserving Pi files and controller ownership as the authority.
Approach
GET /api/terminal-sessionslisting with bounded query, cursor, and limit validation.SessionManager.listAll()(Pi's default Session source).pathinspection returning a bounded preview from the existingloadSessionPreviewDataloader, including omission/byte evidence.source: "pi-default",origin: "terminal", andreadOnly: true.Validation
biome format/biome lint --error-on-warnings: passed.tsc --noEmit: passed.SESSION_NOT_FOUNDreceipt to a generic 500; the boundary was restored.bunis not installed in this environment, so equivalent repository scripts were run with the bundled Node 24 executable and local Biome/Vitest binaries.Impact