feat(observability): serve session traces to the IDE extension
Issue for this PR
The IDE extension's chat has no /traces: users who rely on it in the TUI cannot view a session's trace from VS Code.
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
/traces exists only in the TUI (plugin/tui/altimate/trace-viewer.tsx). The VS Code chat runs altimate serve headless and builds its slash menu from GET /command, so it could never list or open a trace. This adds two routes for it:
GET /altimate/trace?offset&limitโ a page of traces (newest first, default 50) with title, status, duration, tokens, cost and tool calls. UsesTrace.listTracesPaginated.GET /altimate/trace/:sessionID/viewโ the trace's viewer page fromrenderTraceViewer.
Both read tracing.dir like the CLI and TUI. The session ID must match [A-Za-z0-9_-] before it names a file (../../etc โ 400). Trace content includes prompts and tool output, so browser-originated requests are refused on the same terms as the workspace routes. That check moved from workspaceRouteRefusal into browserOriginRefusal so both can use it; the workspace messages are byte-identical.
renderTraceViewer gets an embedded option that leaves out Copy Link: inside an editor tab the page URL is an internal webview URL. The Copy Link handler is null-guarded so the rest of the viewer script still runs.
The extension's /traces (quick pick + editor-tab viewer) consumes these routes; an older CLI without them gets an "update Altimate Code" reply there.
How did you verify your code works?
test/server/altimate-trace-routes.test.ts(8 tests: list order and fields, paging, empty, view page, 404, path-like ID โ 400, cross-site and foreign-origin refusals). Existing workspace, skill-publish and tracing-viewer tests pass;tsgo --noEmitclean.servefrom this branch against 89 real local traces: list total 89, viewer 200, unknown ID 404,../../etc400,Origin: https://evil.example403.- Built linux-arm64, ran it in the extension's code-server container:
/traceslists traces and the viewer renders and works (tabs, Share Trace download).
Screenshots / recordings
Routes only; the UI lives in the IDE extension.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
๐ค Generated with Claude Code
Summary by cubic
Adds /traces support to the IDE extension by serving session traces over HTTP, since VS Code runs altimate serve headless and can't use the TUI's /traces command.
GET /altimate/tracereturns a paginated list of traces, newest first, with title, status, duration, tokens, cost, and tool calls; page size defaults to 50 and caps at 200.GET /altimate/trace/:sessionID/viewserves one trace's viewer page, honoringtracing.dirlike the CLI and TUI.- Both routes validate the session ID before it names a file and refuse browser-originated requests; the refusal logic moved from
workspaceRouteRefusalinto a sharedbrowserOriginRefusalhelper with unchanged workspace messages. Trace.listTracesskips a.jsonthat parses but isn't trace-shaped, so a foreign file in a user-settracing.dirno longer fails the listing.renderTraceViewergains anembeddedoption that omits the Copy Link button, since an editor-tab webview URL isn't shareable.
Summary by CodeRabbit
- New Features
- Added trace browsing with a paginated summary and a detailed viewer for individual sessions.
- Embedded trace viewers omit the Copy Link button.
- Trace listings support pages of up to 200 entries and display a title based on the prompt when one is unavailable.
- Bug Fixes
- Invalid or unrelated JSON files are skipped in trace listings.
- Security
- Trace pages reject disallowed cross-site and browser-originated requests.