Skip to content

The agent that grows with you

refactor(tui): apply the goal and loop snapshots from one control payload

Teknium130868cb54b6
diff --git a/ui-tui/src/app/createGatewayEventHandler.ts b/ui-tui/src/app/createGatewayEventHandler.ts
index f826973ffa4..a99d58563bd 100644
--- a/ui-tui/src/app/createGatewayEventHandler.ts
+++ b/ui-tui/src/app/createGatewayEventHandler.ts
@@ -40,9 +40,8 @@ import {
openCanonicalClarify,
settleSharedPrompt
} from './gatewayCanonicalEvents.js'
-import { applyGoalSnapshot } from './goalStatus.js'
import type { GatewayEventHandlerContext, NoticeLevel } from './interfaces.js'
-import { applyLoopSnapshot } from './loopStatus.js'
+import { applyControlSnapshot } from './loopStatus.js'
import { getOverlayState, patchOverlayState, SENSITIVE_PROMPTS } from './overlayStore.js'
import { markBubbleShown, newlyStartedRows } from './pendingBubbles.js'
import { flashGoodVibes, flashPet } from './petFlashStore.js'
@@ -1119,8 +1118,7 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:
}
case 'session.control.update':
- applyGoalSnapshot(sid, ev.payload?.control.goal ?? null)
- applyLoopSnapshot(sid, ev.payload?.control.loop ?? null)
+ applyControlSnapshot(sid, ev.payload?.control)
return
diff --git a/ui-tui/src/app/loopStatus.ts b/ui-tui/src/app/loopStatus.ts
index 2b6b4bd3ecc..95a6f32e40c 100644
--- a/ui-tui/src/app/loopStatus.ts
+++ b/ui-tui/src/app/loopStatus.ts
@@ -1,8 +1,9 @@
-import type { LoopSnapshot } from '@hermes/shared/gateway-events'
+import type { LoopSnapshot, SessionControlSnapshot } from '@hermes/shared/gateway-events'
import { useStore } from '@nanostores/react'
import { atom } from 'nanostores'
import { useEffect, useState } from 'react'
+import { applyGoalSnapshot } from './goalStatus.js'
import { $uiState } from './uiStore.js'
// The session's standing /loop, as `session.control.read` / `session.control.update` report it.
@@ -19,6 +20,12 @@ export function applyLoopSnapshot(sid: string | null, loop: LoopSnapshot | null
}
}
+/** Both bars' state from one `session.control.read` / `session.control.update` payload. */
+export function applyControlSnapshot(sid: string | null, control?: null | SessionControlSnapshot) {
+ applyGoalSnapshot(sid, control?.goal ?? null)
+ applyLoopSnapshot(sid, control?.loop ?? null)
+}
+
export interface LoopLine {
detail: string
glyph: string
diff --git a/ui-tui/src/app/useMainApp.ts b/ui-tui/src/app/useMainApp.ts
index 36d187f9560..310727df1c2 100644
--- a/ui-tui/src/app/useMainApp.ts
+++ b/ui-tui/src/app/useMainApp.ts
@@ -52,11 +52,10 @@ import { createGatewayEventHandler } from './createGatewayEventHandler.js'
import { createServerRequestHandler } from './createServerRequestHandler.js'
import { createSlashHandler } from './createSlashHandler.js'
import { planGatewayRecovery } from './gatewayRecovery.js'
-import { applyGoalSnapshot } from './goalStatus.js'
import { getInputSelection } from './inputSelectionStore.js'
import { type GatewayRpc, type SlashHandler, type StateSetter, type TranscriptRow, type UiState } from './interfaces.js'
import { requestLiveSessions } from './liveSessions.js'
-import { applyLoopSnapshot } from './loopStatus.js'
+import { applyControlSnapshot } from './loopStatus.js'
import { $overlayState, capturePromptResponseGuard, hasSensitivePrompt, patchOverlayState } from './overlayStore.js'
import { $goodVibesTick } from './petFlashStore.js'
import { applyProcessSnapshot, type ProcessEntry } from './processRoster.js'
@@ -694,8 +693,7 @@ export function useMainApp(gw: GatewayClient) {
let stopped = false
applyAgentSnapshot(ui.sid)
applyProcessSnapshot(ui.sid)
- applyGoalSnapshot(ui.sid)
- applyLoopSnapshot(ui.sid)
+ applyControlSnapshot(ui.sid)
// Goal/loop state changes only on their slash commands, a judged turn or a loop wakeup, all of which push
// `session.control.update`; read it once per session instead of polling state.db.
gw.request<{ control: SessionControlSnapshot }>('session.control.read', { session_id: ui.sid })
@@ -703,8 +701,7 @@ export function useMainApp(gw: GatewayClient) {
const result = asRpcResult<{ control: SessionControlSnapshot }>(raw)
if (!stopped && result && getUiState().sid === ui.sid) {
- applyGoalSnapshot(ui.sid, result.control?.goal ?? null)
- applyLoopSnapshot(ui.sid, result.control?.loop ?? null)
+ applyControlSnapshot(ui.sid, result.control)
}
})
.catch(() => {})