The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): Ink agent steer/kill and the status-bar title on the shared gateway
Teknium9ff778d341ab
diff --git a/ui-tui/src/__tests__/canonicalSidecarSessionVerbs.test.tsx b/ui-tui/src/__tests__/canonicalSidecarSessionVerbs.test.tsxnew file mode 100644index 00000000000..1f6308a57d7--- /dev/null+++ b/ui-tui/src/__tests__/canonicalSidecarSessionVerbs.test.tsx@@ -0,0 +1,111 @@+import { PassThrough } from 'node:stream'++import { Box, renderSync } from '@hermes/ink'+import React from 'react'+import { afterEach, expect, it, vi } from 'vitest'++import { applyAgentSnapshot } from '../app/agentRoster.js'+import { requestLiveSessions } from '../app/liveSessions.js'+import { patchUiState, resetUiState } from '../app/uiStore.js'+import { sendAgentSteer } from '../components/agentControls.js'+import { AgentsOverlay } from '../components/agentsOverlay.js'+import type { GatewayClient } from '../gatewayClient.js'+import { DEFAULT_THEME } from '../theme.js'++// Ink verbs that resolve their session_id in the legacy sidecar's own map. On the shared gateway the+// sidecar never holds the session, so each answered "session not found" (or an empty roster). Every+// site here must either use what the owner serves or refuse by name, never reach the sidecar verb.+const SIDECAR_SESSION_VERBS = ['subagent.steer', 'subagent.interrupt', 'session.active_list']++const owner = (answer: (method: string) => unknown = () => ({})) => {+ const request = vi.fn(async (method: string, _params?: unknown) => {+ if (SIDECAR_SESSION_VERBS.includes(method)) {+ throw new Error('session not found')+ }++ return answer(method)+ })++ return { gw: { isCanonical: true, request } as unknown as GatewayClient, request }+}++const sidecarCalls = (request: ReturnType<typeof vi.fn>) =>+ request.mock.calls.map(([method]) => method as string).filter(method => SIDECAR_SESSION_VERBS.includes(method))++afterEach(() => resetUiState())++async function overlayKey(gw: GatewayClient, key: string) {+ patchUiState({ sid: 'owner' })+ applyAgentSnapshot('owner', {+ delegations: [],+ subagents: [{ depth: 0, goal: 'child', status: 'running', subagent_id: 'c1' } as never]+ })+ const stdout = Object.assign(new PassThrough(), { columns: 100, rows: 24, isTTY: false })+ const stdin = Object.assign(new PassThrough(), { isTTY: true, setRawMode: () => {}, ref: () => {}, unref: () => {} })+ let frame = ''+ stdout.on('data', chunk => (frame += String(chunk)))++ const view = renderSync(+ <Box height={24}>+ <AgentsOverlay gw={gw} onClose={() => {}} t={DEFAULT_THEME} />+ </Box>,+ {+ stdout: stdout as unknown as NodeJS.WriteStream,+ stdin: stdin as unknown as NodeJS.ReadStream,+ stderr: new PassThrough() as unknown as NodeJS.WriteStream,+ patchConsole: false+ }+ )++ try {+ await vi.waitFor(() => expect(frame).toContain('child'))+ stdin.write(key)+ await vi.waitFor(() => expect(frame).toContain('/agents kill is not available on the shared gateway yet'))+ } finally {+ view.unmount()+ view.cleanup()+ applyAgentSnapshot(null)+ }+}++const SITES: [string, () => Promise<void>][] = [+ [+ 'agentControls::sendAgentSteer',+ async () => {+ const { gw, request } = owner()+ const result = await sendAgentSteer(gw, 'owner', 'c1', 'check tests')+ expect(result).toEqual({ accepted: false, message: '/agents steer is not available on the shared gateway yet' })+ expect(sidecarCalls(request)).toEqual([])+ }+ ],+ [+ 'agentsOverlay::killOne (x)',+ async () => {+ const { gw, request } = owner()+ await overlayKey(gw, 'x')+ expect(sidecarCalls(request)).toEqual([])+ }+ ],+ [+ 'agentsOverlay::killSubtree (X)',+ async () => {+ const { gw, request } = owner()+ await overlayKey(gw, 'X')+ expect(sidecarCalls(request)).toEqual([])+ }+ ],+ [+ 'useMainApp::live-session poll (status-bar title + count)',+ async () => {+ const { gw, request } = owner(() => ({ sessions: [{ id: 'owner', title: 'Refactor plan' }] }))+ const result = (await requestLiveSessions(gw, 'owner')) as { sessions: { title: string }[] }+ expect(result.sessions[0]?.title).toBe('Refactor plan')+ expect(request).toHaveBeenCalledWith('session.list', { limit: 200 })+ expect(sidecarCalls(request)).toEqual([])+ }+ ]+]++it.each(SITES)('%s never reaches a sidecar session verb on the shared gateway', async (_site, run) => {+ await run()+})diff --git a/ui-tui/src/app/liveSessions.ts b/ui-tui/src/app/liveSessions.tsnew file mode 100644index 00000000000..a9dbe5f472a--- /dev/null+++ b/ui-tui/src/app/liveSessions.ts@@ -0,0 +1,9 @@+import type { GatewayClient } from '../gatewayClient.js'+import type { SessionActiveListResponse } from '../gatewayTypes.js'++/** The live-session roster the status bar's title and count read: on the shared owner its own+ * `session.list` (live scope); the sidecar's `session.active_list` never holds those sessions. */+export const requestLiveSessions = (gw: Pick<GatewayClient, 'isCanonical' | 'request'>, currentSid: null | string) =>+ gw.isCanonical+ ? gw.request<SessionActiveListResponse>('session.list', { limit: 200 })+ : gw.request<SessionActiveListResponse>('session.active_list', { current_session_id: currentSid })diff --git a/ui-tui/src/app/useMainApp.ts b/ui-tui/src/app/useMainApp.tsindex 4df40528a62..1a69a70b48f 100644--- a/ui-tui/src/app/useMainApp.ts+++ b/ui-tui/src/app/useMainApp.ts@@ -60,6 +60,7 @@ 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 { $overlayState, capturePromptResponseGuard, hasSensitivePrompt, patchOverlayState } from './overlayStore.js'import { $goodVibesTick } from './petFlashStore.js'import { applyProcessSnapshot, type ProcessEntry } from './processRoster.js'@@ -703,7 +704,7 @@ export function useMainApp(gw: GatewayClient) {}}).catch(() => {})- gw.request<SessionActiveListResponse>('session.active_list', { current_session_id: getUiState().sid })+ requestLiveSessions(gw, getUiState().sid).then(raw => {const result = asRpcResult<SessionActiveListResponse>(raw)diff --git a/ui-tui/src/components/agentControls.tsx b/ui-tui/src/components/agentControls.tsxindex 145d3ee05bb..00e202226a0 100644--- a/ui-tui/src/components/agentControls.tsx+++ b/ui-tui/src/components/agentControls.tsx@@ -18,6 +18,11 @@ export function rosterViewport(height: number, count: number, cursor: number) {}export async function sendAgentSteer(gw: GatewayClient, sid: string, id: string, text: string) {+ // The shared owner serves no subagent.steer: the sidecar would answer "session not found".+ if (gw.isCanonical) {+ return { accepted: false, message: messages().canonical.controls.notAvailable('agents steer') }+ }+const result = asRpcResult<{ status: string }>(await gw.request('subagent.steer', { session_id: sid, subagent_id: id, text }))diff --git a/ui-tui/src/components/agentsOverlay.tsx b/ui-tui/src/components/agentsOverlay.tsxindex 5c787fbae1d..c1e4db3be27 100644--- a/ui-tui/src/components/agentsOverlay.tsx+++ b/ui-tui/src/components/agentsOverlay.tsx@@ -768,6 +768,11 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agentconst killOne = (id: string) =>guardLive(() => {+ // The shared owner serves no subagent.interrupt: the sidecar would answer "session not found".+ if (gw.isCanonical) {+ return setFlash(messages().canonical.controls.notAvailable('agents kill'))+ }+interrupt(id).then(raw => {const r = asRpcResult<SubagentInterruptResponse>(raw)@@ -778,6 +783,10 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agentconst killSubtree = (node: SubagentNode) =>guardLive(() => {+ if (gw.isCanonical) {+ return setFlash(messages().canonical.controls.notAvailable('agents kill'))+ }+const ids = [node.item.id, ...descendantIds(node)]ids.forEach(id => interrupt(id).catch(() => {}))setFlash((ids.length === 1 ? T.flash.killingSubtreeOne : T.flash.killingSubtreeOther)(ids.length))