From de16be38a943454b1292c9c3b2b95c9652fe1c2c Mon Sep 17 00:00:00 2001 From: josedario87 Date: Sat, 21 Feb 2026 04:37:43 -0600 Subject: [PATCH] feat: refresh agent session state on terminal switch Add refreshAgentState() to session-state store that fetches fresh state (hookHistory, status, etc.) via GET /session-state/{agent} from the terminal server. Called in switchToTerminal() to ensure the UI shows accurate hook counts when changing between terminals. --- .../transcript-debug/useTranscriptDebug.ts | 6 ++++++ frontend/src/stores/session-state.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/frontend/src/composables/transcript-debug/useTranscriptDebug.ts b/frontend/src/composables/transcript-debug/useTranscriptDebug.ts index 171e4f3..985cb9b 100644 --- a/frontend/src/composables/transcript-debug/useTranscriptDebug.ts +++ b/frontend/src/composables/transcript-debug/useTranscriptDebug.ts @@ -254,6 +254,12 @@ export function useTranscriptDebug() { await fetchSessions() } + // Refresh agent session state (hookHistory, status, etc.) from server + const targetAgent = entry?.agent || selectedAgent.value + if (targetAgent) { + await sessionStore.refreshAgentState(targetAgent) + } + // Load the target session's transcript (skip for __new__ — no transcript yet) selectedSessionId.value = transcriptSessionId if (transcriptSessionId === '__new__') { diff --git a/frontend/src/stores/session-state.ts b/frontend/src/stores/session-state.ts index 43ee0cd..e4e2057 100644 --- a/frontend/src/stores/session-state.ts +++ b/frontend/src/stores/session-state.ts @@ -1,5 +1,6 @@ import { defineStore } from 'pinia' import { ref, computed } from 'vue' +import { terminalApiUrl } from '../config/endpoints' // ── Types (mirror server/services/session-state.ts) ── @@ -210,6 +211,16 @@ export const useSessionState = defineStore('session-state', () => { }) } + async function refreshAgentState(agent: string) { + try { + const res = await fetch(terminalApiUrl(`/session-state/${agent}`)) + if (!res.ok) return + const state = await res.json() as AgentSessionState + agents.value = { ...agents.value, [agent]: state } + lastUpdate.value = Date.now() + } catch { /* silent — WS patches will catch up */ } + } + function setConnected(value: boolean) { connected.value = value } @@ -229,6 +240,7 @@ export const useSessionState = defineStore('session-state', () => { hasErrors, visibleNotifications, handleMessage, + refreshAgentState, respondApproval, respondPlanApproval, setConnected,