feat: add preview session store functions to utils#270
Conversation
W-22203667 - Add createPreviewSessionCache, validatePreviewSession, removePreviewSessionCache, getCachedPreviewSessionIds, getCurrentPreviewSessionId, listCachedPreviewSessions to utils.ts so VS Code extension and CLI share the same storage layer - Introduce SessionType, PreviewSessionMeta, CachedPreviewSessionInfo, CachedPreviewSessionEntry types - Use atomic write (temp file + rename) for the index to avoid partial writes - Export all new functions and types from index.ts - Add tests covering create, validate, remove, list, ordering, fallback dir scan Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| * Caller must set sessionId on the agent (agent.setSessionId) before calling. | ||
| * Throws SfError if the session marker is not found. | ||
| */ | ||
| export async function validatePreviewSession(agent: { getHistoryDir: () => Promise<string> }): Promise<void> { |
There was a problem hiding this comment.
do we need to update something on the Agents class so that we can just pass one in here, instead of just an object with getHistoryDir method defined?
There was a problem hiding this comment.
agentBase.ts already imports from utils.ts (getHistoryDir, SessionHistoryBuffer, TranscriptEntry), so importing AgentBase back into utils.ts would create a circular dependency. The structural type ({ getHistoryDir: () => Promise<string> }) avoids the cycle and still accepts any AgentBase subclass at the call sites. Happy to restructure if you have a preferred way to break the cycle (e.g. a separate types.ts for the interface), but wanted to flag the constraint.
| try { | ||
| await readFile(metaPath, 'utf-8'); | ||
| } catch { | ||
| throw new SfError( |
There was a problem hiding this comment.
this should be SfError.create()
There was a problem hiding this comment.
Fixed — pushed in the latest commit.
| * Remove the session marker so this session is no longer considered "active" for send/end without --session-id. | ||
| * Call after ending the session. Caller must set sessionId on the agent before calling. | ||
| */ | ||
| export async function removePreviewSessionCache(agent: { getHistoryDir: () => Promise<string> }): Promise<void> { |
There was a problem hiding this comment.
it seems like a growing issue that we're putting these file manipulator methods in a utils file... we probably need to figure out a better, and more accessible way to manage all of the different files... if you want to try, that'd be great, but we can also create a new WI to consolidate
There was a problem hiding this comment.
Agreed — utils.ts is getting unwieldy. I'll create a follow-up WI to consolidate the file I/O helpers into a dedicated module so this doesn't keep growing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…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>
Summary
plugin-agentand into this library so the VS Code extension and the CLI share the same storage layer (per review feedback on W-22203667: add timestamp, session type, and index to agent preview sessions output salesforcecli/plugin-agent#400)createPreviewSessionCache,validatePreviewSession,removePreviewSessionCache,getCachedPreviewSessionIds,getCurrentPreviewSessionId,listCachedPreviewSessionstosrc/utils.tsSessionType,PreviewSessionMeta,CachedPreviewSessionInfo,CachedPreviewSessionEntrytypesrename) for the sessions index to reduce race conditions on concurrentstartcallssrc/index.tsTest plan
test/utils.test.tscovering create, validate, remove, list, index ordering, removal from index, and directory-scan fallbackyarn test:only)yarn lint)@W-22203667@
🤖 Generated with Claude Code