feat: add compact Ink agent dock and Enter live tail

This commit is contained in:
Teknium
2026-09-08 03:21:09 -07:00
parent 34e539ebeb
commit f7fe32bfde
8 changed files with 104 additions and 25 deletions
@@ -0,0 +1,70 @@
import { PassThrough } from 'node:stream'
import { Box, renderSync } from '@hermes/ink'
import React from 'react'
import stripAnsi from 'strip-ansi'
import { expect, it, vi } from 'vitest'
import { renderToScreen } from '../../packages/hermes-ink/src/ink/render-to-screen.js'
import { cellAtIndex } from '../../packages/hermes-ink/src/ink/screen.js'
import { applyAgentSnapshot } from '../app/agentRoster.js'
import { patchUiState, resetUiState } from '../app/uiStore.js'
import { AgentsOverlay } from '../components/agentsOverlay.js'
import { AgentsPanelView } from '../components/agentsPanel.js'
import type { GatewayClient } from '../gatewayClient.js'
import { buildAgentRows } from '../lib/agentRows.js'
import { DEFAULT_THEME } from '../theme.js'
it('keeps collapsed live chrome to one row without losing count or restore controls', () => {
const rows = buildAgentRows([], [{ delegation_id: 'work', status: 'running', goal: 'Review the boundary' }], 1000)
for (const cols of [78, 98]) {
const view = renderToScreen(<AgentsPanelView collapsed cols={cols} {...rows} t={DEFAULT_THEME} />, cols)
expect(view.height).toBe(1)
const text = Array.from({ length: cols }, (_, i) => cellAtIndex(view.screen, i).char).join('')
expect(text).toContain(`${rows.running} live agents`)
expect(text).toContain('Ctrl+T expand')
expect(text).toContain('F7 restore')
expect(renderToScreen(<AgentsPanelView cols={cols} {...rows} t={DEFAULT_THEME} />, cols).height).toBeGreaterThan(view.height)
}
})
it('opens the selected live transcript on Enter while details remain independently accessible', async () => {
patchUiState({ sid: 'owner' })
applyAgentSnapshot('owner', { subagents: [{ subagent_id: 'child', goal: 'Inspect ownership', status: 'running' }], delegations: [] })
const request = vi.fn(async (method: string) => method === 'subagent.tail'
? { available: true, text: 'CHILD_TOOL_OUTPUT', truncated: false }
: {})
const stdout = Object.assign(new PassThrough(), { columns: 80, rows: 20, isTTY: false })
const stdin = Object.assign(new PassThrough(), { isTTY: true, setRawMode: () => {}, ref: () => {}, unref: () => {} })
let output = ''
stdout.on('data', chunk => { output += stripAnsi(chunk.toString()) })
const view = renderSync(<Box height={20}><AgentsOverlay gw={{ request } as unknown as GatewayClient} 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(output).toContain('Inspect ownership'))
stdin.write('\r')
await vi.waitFor(() => expect(request).toHaveBeenCalledWith('subagent.tail', { session_id: 'owner', subagent_id: 'child' }))
await vi.waitFor(() => expect(output).toContain('CHILD_TOOL_OUTPUT'))
output = ''
stdin.write('d')
await vi.waitFor(() => expect(output).toContain('Inspect ownership'))
expect(output).not.toContain('CHILD_TOOL_OUTPUT')
output = ''
stdin.write('t')
await vi.waitFor(() => expect(output).toContain('CHILD_TOOL_OUTPUT'))
} finally {
view.unmount()
view.cleanup()
applyAgentSnapshot(null)
resetUiState()
}
})
+3
View File
@@ -8,6 +8,9 @@ import type { SubagentProgress } from '../types.js'
import { useTurnSelector } from './turnStore.js'
import { $uiState } from './uiStore.js'
// Session-local presentation only; never persisted to config.
export const $agentDockCollapsed = atom(false)
const EMPTY: SubagentListResponse = { subagents: [], delegations: [] }
export const $agentSnapshot = atom<{ sid: string | null; data: SubagentListResponse }>({ sid: null, data: EMPTY })
+8 -1
View File
@@ -17,6 +17,7 @@ import { computePrecisionWheelStep, initPrecisionWheel } from '../lib/precisionW
import { computeWheelStep, initWheelAccelForHost } from '../lib/wheelAccel.js'
import { closeWidget, dispatchWidgetInput } from '../sdk/host.js'
import { $agentDockCollapsed } from './agentRoster.js'
import { getInputSelection } from './inputSelectionStore.js'
import {
type GatewayRpc,
@@ -366,7 +367,7 @@ export function useInputHandlers(ctx: InputHandlerContext): InputHandlerResult {
// still the dedicated discard (pushes the draft to history so Up recalls it).
const lastEscRef = useRef(0)
useInput((ch, key) => {
useInput((ch, key, event) => {
const live = getUiState()
if (key.escape) {
@@ -631,6 +632,12 @@ export function useInputHandlers(ctx: InputHandlerContext): InputHandlerResult {
// typed to run the command. Works mid-stream: picking a model writes the
// session model (config.set), which the next turn reads while the in-flight
// turn keeps streaming.
if (event.keypress.name === 'f7' && !key.ctrl && !key.meta && !key.shift && !key.super) {
$agentDockCollapsed.set(!$agentDockCollapsed.get())
return
}
if (isCtrl(key, ch, 't')) {
return patchOverlayState({ agents: true, agentsInitialHistoryIndex: 0 })
}
+7 -13
View File
@@ -772,9 +772,9 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agent
return setMode('steer')
}
if (ch === 't' && selected) {
return setMode('tail')
}
if (ch === 't' && !key.ctrl && selected) {return setMode('tail')}
if (ch === 'd' && !key.ctrl && selected) {return setMode('detail')}
if (ch === 'q') {
return closeWithCleanup()
@@ -847,7 +847,7 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agent
// List mode.
if ((key.return || key.rightArrow || ch === 'l') && selected) {
return setMode('detail')
return setMode(key.return && !replayMode ? 'tail' : 'detail')
}
if (key.upArrow || ch === 'k' || key.wheelUp) {
@@ -980,18 +980,12 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agent
)}
<Box flexDirection="column" marginTop={1}>
<Text color={t.color.accent} wrap="truncate-end">
Enter detail · e steer · t tail · x stop · Esc back
</Text>
{flash ? (
<Text color={t.color.accent} wrap="truncate-end">
{flash}
</Text>
) : null}
<Text color={t.color.accent} wrap="truncate-end">{replayMode ? 'Enter/d detail' : 'Enter/t tail · d detail'} · e steer · x stop · Esc back</Text>
{flash ? <Text color={t.color.accent} wrap="truncate-end">{flash}</Text> : null}
{mode === 'list' ? (
<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:
↑↓/jk move · g/G top/bottom · {replayMode ? 'Enter/→ detail' : 'Enter tail · d/→ detail'}{controlsHint} · s sort:{SORT_LABEL[sort]} · f filter:
{FILTER_LABEL[filter]}
{history.length > 0 ? ` · [ / ] history ${historyIndex}/${history.length}` : ''}
{' · q close'}
+13 -9
View File
@@ -1,8 +1,8 @@
import { Box, Text, useStdout } from '@hermes/ink'
import { Box, stringWidth, Text, useStdout } from '@hermes/ink'
import { useStore } from '@nanostores/react'
import { useEffect, useState } from 'react'
import { useAgentRoster } from '../app/agentRoster.js'
import { $agentDockCollapsed, useAgentRoster } from '../app/agentRoster.js'
import { $uiState } from '../app/uiStore.js'
import { type AgentRows, buildAgentRows, dockRowLimit } from '../lib/agentRows.js'
import { mix } from '../lib/color.js'
@@ -11,10 +11,13 @@ import { fmtDuration } from '../lib/subagentTree.js'
import { compactPreview } from '../lib/text.js'
import type { Theme } from '../theme.js'
export function AgentsPanelView({ cols, hidden, rows, running, t }: AgentRows & { cols: number; t: Theme }) {
if (!running) {
return null
}
export function AgentsPanelView({ collapsed = false, cols, hidden, rows, running, t }: AgentRows & { collapsed?: boolean; cols: number; t: Theme }) {
if (!running) {return null}
const summary = `▸ ${running} live agents`
const hints = ' · Ctrl+T expand · F7 restore'
const activityWidth = cols - stringWidth(summary + hints) - 3
const activity = rows[0]?.detail && activityWidth >= 12 ? ` · ${compactPreview(rows[0].detail, activityWidth)}` : ''
return (
<Box
@@ -24,9 +27,9 @@ export function AgentsPanelView({ cols, hidden, rows, running, t }: AgentRows &
width={cols}
>
<Text bold color={t.color.accent} wrap="truncate-end">
{`▾ ${running} live agents${hidden ? ` · +${hidden} more` : ''} · Ctrl+T expand`}
{collapsed ? summary + activity + hints : `▾ ${running} live agents${hidden ? ` · +${hidden} more` : ''} · Ctrl+T expand · F7 collapse`}
</Text>
{rows.map(row => (
{!collapsed && rows.map(row => (
<Box flexDirection="column" key={row.key}>
<Text wrap="truncate-end">
<Text color={statusGlyph(row.status, t).color}>{statusGlyph(row.status, t).glyph} </Text>
@@ -42,6 +45,7 @@ export function AgentsPanelView({ cols, hidden, rows, running, t }: AgentRows &
export function LiveAgentsPanel({ cols }: { cols: number }) {
const { theme } = useStore($uiState)
const collapsed = useStore($agentDockCollapsed)
const { stdout } = useStdout()
const subagents = useAgentRoster()
const live = subagents.some(s => s.status === 'running' || s.status === 'queued')
@@ -57,6 +61,6 @@ export function LiveAgentsPanel({ cols }: { cols: number }) {
}, [live])
return (
<AgentsPanelView cols={cols} {...buildAgentRows(subagents, [], now, dockRowLimit(stdout?.rows ?? 24))} t={theme} />
<AgentsPanelView collapsed={collapsed} cols={cols} {...buildAgentRows(subagents, [], now, dockRowLimit(stdout?.rows ?? 24))} t={theme} />
)
}
+1 -1
View File
@@ -1350,7 +1350,7 @@ export function TextInput({
// actually get voice toggled instead of a paste (Copilot round-7
// follow-up on #19835). The pass-through predicate is a no-op for
// ordinary typing and plain paste when voice is unbound to 'v'.
if (shouldPassThroughToGlobalHandler(inp, k, voiceRecordKey)) {
if (event.keypress.name === 'f7' || shouldPassThroughToGlobalHandler(inp, k, voiceRecordKey)) {
flushKeyBurst()
return
+1
View File
@@ -26,6 +26,7 @@ export const HOTKEYS: [string, string][] = [
['↑/↓', 'completions / queue edit / history'],
['Ctrl+X', 'open live session switcher (deletes queued message while editing)'],
['Ctrl+T', 'expand live agents (keeps your draft)'],
['F7', 'collapse / restore live agent preview'],
['Ctrl+O', 'open model picker (keeps your draft; applies to next turn mid-stream)'],
[action + '+A/E', 'home / end of line'],
[action + '+Z / ' + action + '+Y', 'undo / redo input edits'],
+1 -1
View File
@@ -28,7 +28,7 @@ declare module '@hermes/ink' {
export type InputEvent = {
readonly input: string
readonly key: Key
readonly keypress: { readonly isPasted?: boolean; readonly raw?: string }
readonly keypress: { readonly isPasted?: boolean; readonly name?: string; readonly raw?: string }
}
export type InputHandler = (input: string, key: Key, event: InputEvent) => void