The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(tui): inspect live tails and steer from full-height agent roster
Tekniumf3a9ca089f0f
diff --git a/ui-tui/src/__tests__/agentControls.test.ts b/ui-tui/src/__tests__/agentControls.test.tsnew file mode 100644index 00000000000..439b5dd0a74--- /dev/null+++ b/ui-tui/src/__tests__/agentControls.test.ts@@ -0,0 +1,34 @@+import { expect, it } from 'vitest'++import { rosterViewport, sendAgentSteer } from '../components/agentControls.js'+import type { GatewayClient } from '../gatewayClient.js'++it('reports queued acceptance rather than claiming delivery and preserves rejected text', async () => {+ const calls: unknown[] = []++ const gw = {+ request: async (...args: unknown[]) => {+ calls.push(args)++ return { status: 'queued' }+ }+ } as unknown as GatewayClient++ expect(await sendAgentSteer(gw, 'owner', 'child', 'check tests')).toEqual({+ accepted: true,+ message: 'Queued for child — applied at the next tool boundary.'+ })+ expect(calls).toEqual([['subagent.steer', { session_id: 'owner', subagent_id: 'child', text: 'check tests' }]])+ const rejected = { request: async () => ({ status: 'rejected' }) } as unknown as GatewayClient+ expect((await sendAgentSteer(rejected, 'owner', 'child', 'check tests')).accepted).toBe(false)+})++it('keeps every roster selection in the visible viewport including short terminals', () => {+ for (const height of [10, 14, 24, 40])+ {for (const cursor of [0, 9, 19]) {+ const view = rosterViewport(height, 20, cursor)+ expect(view.start).toBeLessThanOrEqual(cursor)+ expect(view.start + view.rows).toBeGreaterThan(cursor)+ expect(view.rows + (view.timelineRows ? view.timelineRows + 4 : 0) + 7).toBeLessThanOrEqual(height)+ }}+})diff --git a/ui-tui/src/components/agentControls.tsx b/ui-tui/src/components/agentControls.tsxnew file mode 100644index 00000000000..e3523d02797--- /dev/null+++ b/ui-tui/src/components/agentControls.tsx@@ -0,0 +1,141 @@+import { Box, Text, useInput } from '@hermes/ink'+import { useEffect, useState } from 'react'++import type { GatewayClient } from '../gatewayClient.js'+import { asRpcResult } from '../lib/rpc.js'+import type { Theme } from '../theme.js'++import { TextInput } from './textInput.js'++export function rosterViewport(height: number, count: number, cursor: number) {+ const timelineRows = height >= 32 ? Math.min(4, count) : 0+ const rows = Math.max(1, height - 7 - (timelineRows ? timelineRows + 4 : 0))+ const start = Math.max(0, Math.min(Math.max(0, count - rows), cursor - Math.floor(rows / 2)))++ return { rows, start, timelineRows }+}++export async function sendAgentSteer(gw: GatewayClient, sid: string, id: string, text: string) {+ const result = asRpcResult<{ status: string }>(+ await gw.request('subagent.steer', { session_id: sid, subagent_id: id, text })+ )++ const accepted = result?.status === 'queued'++ return {+ accepted,+ message: accepted+ ? 'Queued for child — applied at the next tool boundary.'+ : 'Not queued: child has finished or is no longer accepting guidance.'+ }+}++interface ControlProps {+ gw: GatewayClient+ sid: string+ id: string+ t: Theme+}++export function AgentSteerForm({+ gw,+ sid,+ id,+ t,+ cols,+ onClose+}: ControlProps & { cols: number; onClose: () => void }) {+ const [text, setText] = useState('')+ const [feedback, setFeedback] = useState('')+ const [pending, setPending] = useState(false)+ useInput((_ch, key) => {+ if (key.escape && !pending) {onClose()}+ })++ const submit = async () => {+ if (!text.trim() || pending) {return}+ setPending(true)++ try {+ const result = await sendAgentSteer(gw, sid, id, text)+ setFeedback(result.message)++ if (result.accepted) {setText('')}+ } catch (error) {+ setFeedback(`Not queued: ${error instanceof Error ? error.message : String(error)}`)+ } finally {+ setPending(false)+ }+ }++ return (+ <Box flexDirection="column" flexGrow={1}>+ <Text bold color={t.color.accent} wrap="truncate-end">+ Steer {id}+ </Text>+ <Text color={t.color.muted}>Guidance queues at the next tool boundary; current work is not interrupted.</Text>+ <Box marginTop={1}>+ <Text color={t.color.accent}>❯ </Text>+ <TextInput+ color={t.color.text}+ columns={Math.max(1, cols - 6)}+ focus={!pending}+ onChange={setText}+ onSubmit={() => void submit()}+ value={text}+ />+ </Box>+ <Text color={t.color.muted}>{pending ? 'Queueing…' : feedback}</Text>+ <Text color={t.color.muted}>Enter queue · Esc back · main composer draft is preserved</Text>+ </Box>+ )+}++export function AgentLiveTail({ gw, sid, id, t }: ControlProps) {+ const [tail, setTail] = useState('Loading live transcript…')+ useEffect(() => {+ let active = true+ let pending = false++ const refresh = async () => {+ if (pending) {return}+ pending = true++ try {+ const result = asRpcResult<{ available: boolean; text: string; truncated: boolean }>(+ await gw.request('subagent.tail', { session_id: sid, subagent_id: id })+ )++ if (active)+ {setTail(+ result?.available+ ? `${result.truncated ? '[last 16 KiB]\n' : ''}${result.text}`+ : 'Live transcript unavailable; child may have finished. Progress and output remain below.'+ )}+ } catch {+ if (active) {setTail('Could not refresh live transcript.')}+ } finally {+ pending = false+ }+ }++ void refresh()+ const timer = setInterval(() => void refresh(), 1500)++ return () => {+ active = false+ clearInterval(timer)+ }+ }, [gw, sid, id])++ return (+ <Box flexDirection="column">+ <Text bold color={t.color.accent}>+ Live transcript+ </Text>+ <Text color={t.color.text} wrap="wrap">+ {tail}+ </Text>+ </Box>+ )+}diff --git a/ui-tui/src/components/agentsOverlay.tsx b/ui-tui/src/components/agentsOverlay.tsxindex f35856d5578..ef9460f2aa3 100644--- a/ui-tui/src/components/agentsOverlay.tsx+++ b/ui-tui/src/components/agentsOverlay.tsx@@ -11,6 +11,7 @@ import {} from '../app/delegationStore.js'import { patchOverlayState } from '../app/overlayStore.js'import { $spawnDiff, $spawnHistory, clearDiffPair, type SpawnSnapshot } from '../app/spawnHistoryStore.js'+import { $uiState } from '../app/uiStore.js'import type { GatewayClient } from '../gatewayClient.js'import type { DelegationPauseResponse, DelegationStatusResponse, SubagentInterruptResponse } from '../gatewayTypes.js'import { asRpcResult } from '../lib/rpc.js'@@ -32,6 +33,7 @@ import { compactPreview } from '../lib/text.js'import type { Theme } from '../theme.js'import type { SubagentNode, SubagentProgress } from '../types.js'+import { AgentLiveTail, AgentSteerForm, rosterViewport } from './agentControls.js'import { listRowStyle } from './overlayPrimitives.js'import { OverlayScrollbar } from './overlayScrollbar.js'@@ -614,7 +616,8 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agentconst [now, setNow] = useState(() => Date.now())// cc-style view switching: list = full-width row picker, detail = full-width// scrollable pane. Two panes side-by-side in Ink fought Yoga flex.- const [mode, setMode] = useState<'detail' | 'list'>('list')+ const [mode, setMode] = useState<'detail' | 'list' | 'steer' | 'tail'>('list')+ const { sid } = useStore($uiState)const detailScrollRef = useRef<null | ScrollBoxHandle>(null)const prevLiveCountRef = useRef(liveSubagents.length)@@ -639,8 +642,7 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agentconst selected = rows[cursor] ?? nullconst cols = stdout?.columns ?? 80- const rowsH = Math.max(8, (stdout?.rows ?? 24) - 10)- const listWindowStart = Math.max(0, cursor - Math.floor(rowsH / 2))+ const { rows: rowsH, start: listWindowStart, timelineRows } = rosterViewport(stdout?.rows ?? 24, rows.length, cursor)// ── Effects ────────────────────────────────────────────────────────@@ -756,12 +758,20 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agentconst scrollDetail = (dy: number) => detailScrollRef.current?.scrollBy(dy)useInput((ch, key) => {+ if (mode === 'steer') {return}++ if (key.ctrl && ch === 't') {return closeWithCleanup()}++ if (ch === 'e' && selected && sid && !replayMode) {return setMode('steer')}++ if (ch === 't' && selected) {return setMode('tail')}+if (ch === 'q') {return closeWithCleanup()}if (key.escape) {- return mode === 'detail' ? setMode('list') : closeWithCleanup()+ return mode !== 'list' ? setMode('list') : closeWithCleanup()}// Shared actions (both modes).@@ -785,7 +795,7 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agentreturn killSubtree(selected)}- if (mode === 'detail') {+ if (mode === 'detail' || mode === 'tail') {if (key.leftArrow || ch === 'h') {return setMode('list')}@@ -885,7 +895,7 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agentconst controlsHint = replayMode? ' · controls locked'- : ` · x kill · X subtree · p ${delegation.paused ? 'resume' : 'pause'}`+ : ` · e steer · t tail · x stop · X subtree · p ${delegation.paused ? 'resume' : 'pause'}`// ── Rendering ──────────────────────────────────────────────────────@@ -909,13 +919,13 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agent</Text></Box>- {rows.length === 0 ? (+ {mode === 'steer' && selected && sid ? <AgentSteerForm cols={cols} gw={gw} id={selected.item.id} onClose={() => setMode('detail')} sid={sid} t={t} /> : rows.length === 0 ? (<Box flexDirection="column" flexGrow={1}><Text color={t.color.muted}>No subagents this turn. Trigger delegate_task to populate the tree.</Text></Box>) : mode === 'list' ? (<Box flexDirection="column" flexGrow={1} flexShrink={1} minHeight={0}>- <GanttStrip cols={cols} cursor={cursor} flatNodes={rows} maxRows={6} now={now} t={t} />+ {timelineRows > 0 ? <GanttStrip cols={cols - 2} cursor={cursor} flatNodes={rows} maxRows={timelineRows} now={now} t={t} /> : null}<Box flexDirection="column" flexGrow={0} flexShrink={0} overflow="hidden">{rows.slice(listWindowStart, listWindowStart + rowsH).map((node, i) => (@@ -935,7 +945,8 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agent<Box flexDirection="row" flexGrow={1} flexShrink={1} minHeight={0}><ScrollBox flexDirection="column" flexGrow={1} flexShrink={1} ref={detailScrollRef}><Box flexDirection="column" paddingBottom={4} paddingRight={1}>- {selected ? <Detail id={formatRowId(cursor).trim()} node={selected} t={t} /> : null}+ {selected && mode === 'tail' && sid && !replayMode ? <AgentLiveTail gw={gw} id={selected.item.id} key={selected.item.id} sid={sid} t={t} /> : null}+ {selected ? <Detail id={selected.item.id} node={selected} t={t} /> : null}</Box></ScrollBox>@@ -949,14 +960,14 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agent{flash ? <Text color={t.color.accent}>{flash}</Text> : null}{mode === 'list' ? (- <Text color={t.color.muted}>+ <Text color={t.color.muted} wrap="truncate-end">↑↓/jk move · g/G top/bottom · Enter/→ open detail{controlsHint} · s sort:{SORT_LABEL[sort]} · f filter:{FILTER_LABEL[filter]}{history.length > 0 ? ` · [ / ] history ${historyIndex}/${history.length}` : ''}{' · q close'}</Text>) : (- <Text color={t.color.muted}>+ <Text color={t.color.muted} wrap="truncate-end">↑↓/jk scroll · PgUp/PgDn page · g/G top/bottom · Esc/← back to list{controlsHint} · q close</Text>)}