W-22203667: add timestamp, session type, and index to agent preview sessions output#400
Conversation
…s output W-22203667 - Add `timestamp` (ISO string) and `sessionType` (simulated/live/published) to `session-meta.json` written by `agent preview start` - Introduce `index.json` in the sessions directory to maintain creation-ordered session metadata for easier browsing by humans and agents - Surface new fields as "Started At" and "Session Type" columns in `agent preview sessions` table and JSON output - `listCachedSessions` prefers the index for ordered results, falls back to directory scan for sessions created before this change - Update JSON schema and add tests for index write, removal, ordering, and fallback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The NUT failures in this run are pre-existing and unrelated to this PR's changes. The same assertion failure at |
| const sessionsDir = dirname(historyDir); | ||
| const indexPath = join(sessionsDir, SESSION_INDEX_FILE); | ||
| const index = await readSessionIndex(indexPath); | ||
| if (!index.some((e) => e.sessionId === sessionId)) { |
There was a problem hiding this comment.
If we're writing a file in the session history, it should be done in the library, so VSC and plugin conversations save the same data to the same locations
| /** | ||
| * Read the sessions index file, returning an empty array if missing or unreadable. | ||
| */ | ||
| async function readSessionIndex(indexPath: string): Promise<SessionIndex> { |
There was a problem hiding this comment.
this should be in the library, reading/writing files
|
and then claude review: |
- Fix race condition on concurrent createCache/removeCache calls by using atomic write (temp file + rename) via updateSessionIndex helper - Remove export from SessionIndex type — used only internally - Fix sessionType widening: use SessionType union instead of string in AgentPreviewSessionsResult and resolveSessionType return type - Replace inline import() type annotation with top-level named import - Eliminate double-read in fallback dir scan by capturing displayName during the first pass - Update JSON schema to use $ref for SessionType enum Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
W-22203667 Per review feedback from WillieRuemmele: file I/O for the session cache should live in the library so VS Code extension and CLI share the same storage layer. previewSessionStore.ts is now a thin re-export shim that maps to the new library functions (createPreviewSessionCache → createCache, etc.) so all command callsites remain unchanged. Update @salesforce/agents to local file reference while library PR is in review. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Addressed @WillieRuemmele's feedback about file I/O belonging in the library. What changed:
Library branch: |
|
Library PR is open: forcedotcom/agents#270 — once that merges and is published, the |
The file:../agents dependency breaks CI since runners only clone this repo. Restore the full inline implementation and ^1.1.2 semver until forcedotcom/agents#269 merges and a new version is published, at which point previewSessionStore.ts can become the thin shim again. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| const SESSION_INDEX_FILE = 'index.json'; | ||
|
|
||
| export type SessionMeta = { displayName?: string }; | ||
| export type SessionType = 'simulated' | 'live' | 'published'; |
There was a problem hiding this comment.
should these types be in the library?
| * the window for concurrent-write races (last writer wins, no silent drops). | ||
| * Propagates errors so callers are aware of index failures. | ||
| */ | ||
| async function updateSessionIndex(indexPath: string, updater: (index: SessionIndex) => SessionIndex): Promise<void> { |
There was a problem hiding this comment.
There was a problem hiding this comment.
Yes, exactly — it is the same implementation. The logic in previewSessionStore.ts here is a temporary copy while forcedotcom/agents#270 is under review. Once that PR merges and a new version is published, this file will be replaced with a thin shim that re-exports the library functions (the same approach shown in the PR description). The duplication is intentional to keep CI green in the meantime.
…agents All session store logic now lives in the agents library (forcedotcom/agents#270). This file is a thin re-export shim; the plugin-agent tests are removed since the library ships its own test coverage. CI will fail until agents#270 merges and the dependency is updated to the published semver. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
QA Notes✅ : adds timestamp / session type to output ┌──────────────────────────────────────┬──────────────────────────────────────┬──────────────────────────┬──────────────┐
│ Agent (authoring bundle or API name) │ Session ID │ Started At │ Session Type │
├──────────────────────────────────────┼──────────────────────────────────────┼──────────────────────────┼──────────────┤
│ WilliePublish │ 019dd09b-823e-75ef-890f-fb7fcf0b0589 │ 2026-04-27T20:22:28.329Z │ published │
│ Local_Info_Agent │ 40a31439-63c7-409d-8c2f-9135cb236919 │ │ │
│ Local_Info_Agent │ 85b4d4c5-956e-4bc0-b952-8ea162ac3b22 │ │ │
│ Local_Info_Agent │ d5013b06-b355-4127-8891-d4d805d4ed43 │ │ │
│ Station_Commander │ 4defc2f9-8939-44f3-95a6-09875b6d78f7 │ │ │
└──────────────────────────────────────┴──────────────────────────────────────┴──────────────────────────┴──────────────┘✅ : {
"status": 0,
"result": [
{
"agentId": "0Xxed0000000DGbCAM",
"displayName": "WilliePublish",
"sessionId": "019dd09b-823e-75ef-890f-fb7fcf0b0589",
"timestamp": "2026-04-27T20:22:28.329Z",
"sessionType": "published"
},
{
"agentId": "Local_Info_Agent",
"displayName": "Local_Info_Agent",
"sessionId": "40a31439-63c7-409d-8c2f-9135cb236919"
},
|
Summary
timestamp(ISO string) andsessionType(simulated/live/published) tosession-meta.jsonwritten onagent preview startindex.jsonin the sessions directory to maintain creation-ordered session metadata for easier browsing by humans and agentsagent preview sessionstable and JSON outputlistCachedSessionsprefers the index for ordered results, falls back to directory scan for sessions created before this changeTest plan
yarn test)agent-preview-sessionscommand@W-22203667@
🤖 Generated with Claude Code