feat: add History tab to resume prior agent sessions from disk @W-22434464@#205
feat: add History tab to resume prior agent sessions from disk @W-22434464@#205marcelinollano wants to merge 19 commits into
Conversation
Surfaces a new History tab in the agent webview that lists prior cached sessions read from .sfdx/agents/<key>/sessions/, the same on-disk format the sf CLI plugin uses. Clicking a row reattaches the agent via SDK resumeSession(sessionId), restores the transcript and traces, and hands control back to the Preview tab without restarting if the chosen session is already active. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
npiccolo
left a comment
There was a problem hiding this comment.
Manual testing ✅
Setup: Extension Development Host launched from ml/W-22434464-navigate-history, agent script project afdx-pro-code-testdrive opened in the test window.
History tab
New clock icon tab appears next to Agent Preview and Agent Tracer. Sessions are listed newest first with correct Simulation badge, first user message, and formatted timestamp.
Resume session
Clicking a row switches to Preview with the transcript restored. Clicking the same row again is a no-op — no restart, jumps straight back to Preview.
Multiple sessions
After running a second simulation, both sessions appear in History newest first with correct entries.
Tab switching regression
Switching between Agent Preview → Agent Tracer → History → Agent Preview keeps the agent selector populated throughout with no loading state.
Automated tests: npm run test:backend (397/397) and npm run test:frontend (392/392) all pass.
LGTM ✅
|
@marcelinollano , i think you tagged me to review something, but there's a lot of code here and I'm not sure where the public-facing text is. Maybe you can @mention me on the specific lines? Thx. |
I tagged you @jshackell-sfdc because I saw the story has a green border on the sprint board =D |
…e-history # Conflicts: # webview/src/App.tsx
Clicking a History row now loads that session's transcript and traces into the chat without starting a session. The Start button flips to Resume, the live-mode toggle syncs to the previewed session's type, and a new Clear Loaded Session toolbar action drops the loaded conversation. If a session is already active when a row is clicked, the SDK session is ended first with a Stopping... spinner, then the previewed conversation is rendered. Also moves the toolbar order so Refresh sits leftmost, followed by Activate, Save Chat History, and Clear, and removes the Create Agent button from the empty agent toolbar.
The pre-init getDefaultConnection fallback reads ~/.sfdx and resolves a real Connection on developer machines with cached sf orgs, causing the test that expects rejection to fail locally. Mock ConfigAggregator and Org so the test passes regardless of host environment.
Multiple symptoms during the mid-session History click stem from the same race between the empty setConversation, sessionStarting, and the SDK round-trip: - Reorder backend messages so sessionStarting precedes the empty setConversation, and update the webview's isSessionStartingRef synchronously inside the listener so it sees the new value before setConversation runs. - Flip sessionActive context to false at the start of the stop so toolbar actions gated on it (Start Debug Mode, Stop, etc.) hide immediately instead of after the round-trip. - Hide Activate Version and Clear Loaded Session in the error state. - Suppress the empty-state placeholder while the spinner is showing.
…e-history # Conflicts: # test/services/coreExtensionService.test.ts # webview/src/App.tsx # webview/src/components/AgentPreview/AgentSelector.tsx
Toolbar Stop button no longer flickers through Start when stopping. After a normal stop, the just-ended session is marked as previewable so the toolbar shows Resume and Clear without reloading the chat. Also covers the same flicker on history-row clicks during an active session.
Mode switch and agent change end the current session before starting a new one. Without a restart signal, the just-ended session was marked previewable, causing the next startSession to route through resumeSession and resume the prior session instead of starting fresh in the new mode.
What does this PR do?
Adds a new History tab to the Agentforce DX webview that lists prior cached agent sessions and lets you resume them. Also rounds out the post-session UX so a just-stopped session behaves like a history entry (Resume + Clear), and renders the new
GuardrailsStepin the tracer.History tab
.sfdx/agents/<storageKey>/sessions/(same on-disk format as thesfCLI plugin), so the list works regardless of which tool wrote the session.Stopping…spinner, then the previewed conversation renders.Stop-then-resume flow
sessionEnded(no chat reload). Toolbar transitions Stop → Resume directly with no flicker through Start, and Clear Chat Session becomes available.restartingflag so the next start does not accidentally route through resume.Tracer
GuardrailsSteprendered with display name "Guardrails Check", a Codicon shield icon, and the adherence level (e.g.HIGH) as the timeline description.generatedResponseandinstructionAdherence.What issues does this PR fix or reference?
@W-22434464@ — [AFDX] [UX] Navigate history
@W-22497762@ — agent preview session lifecycle continuity (merged from main)
Functionality Before
GuardrailsStepevents were not surfaced in the tracer.Functionality After
Resuming session…spinner and disables input — no flicker through the "no session" toolbar state.GuardrailsSteprenders in the tracer with a shield icon, level badge, and clickable detail panel.Testing Setup Notes
Stopping…spinner, then preview lands and toolbar shows Resume with the new session's mode.HIGH); clicking it opens the detail panel showinggeneratedResponseandinstructionAdherence.Tests
sessionHistoryService.test.ts— disk-read fallback chain (5 cases).sessionManager.test.ts—resumeSessionhappy path / end-previous / error / no-webview, andendSessionresumable-preview flow (simulated/live/published, restarting flag, ordering).webviewMessageHandlers.test.ts—listSessions,previewSessionflows, andendSessionrestartingflag wiring.SessionHistory.test.tsx— placeholder, list rendering, empty state, click-to-resume,onPreviewStartcallback, no-eager-mode-flip.App.sessionLifecycle.test.tsx— Stop label persistence, history-row stopping transition,sessionEndedpreview flip,setConversationhandler flows.AgentSelector.test.tsx— Stop label acrossisStopPendingfor script and published agents.AgentTracer.helpers.test.tsx—GuardrailsStepdisplay name, description, detail data, clickability.912 tests total (429 backend + 483 frontend), all passing.
🤖 Generated with Claude Code