Skip to content

The agent that grows with you

fix(tui): a long slash.exec read from the shared owner opens the pager

Teknium9e933b75fb9d
diff --git a/ui-tui/src/__tests__/createSlashHandler.test.ts b/ui-tui/src/__tests__/createSlashHandler.test.ts
index 3f445714a00..26f47476a75 100644
--- a/ui-tui/src/__tests__/createSlashHandler.test.ts
+++ b/ui-tui/src/__tests__/createSlashHandler.test.ts
@@ -975,6 +975,50 @@ describe('createSlashHandler', () => {
await vi.waitFor(() => expect(ctx.gateway.gw.request).toHaveBeenCalledWith('command.dispatch', expect.anything()))
})
+ it('pages a long owner read from slash.exec like main\'s sidecar output', async () => {
+ // The shared owner answers a read as `{type: 'exec', output}` (gateway/session_commands.py);
+ // main's sidecar sent bare `{output}`, paged when long. /context and /cron must still open
+ // the pager, not collapse to a one-line system row.
+ patchUiState({ sid: 'sid-abc' })
+ const output = ['Conversation: 4 messages', ' user: 2, assistant: 2, tool: 0, system: 0', 'Model: fake-model'].join('\n')
+
+ const ctx = buildCtx({
+ gateway: {
+ gw: {
+ getLogTail: vi.fn(() => ''),
+ request: vi.fn((method: string) =>
+ Promise.resolve(method === 'slash.exec' ? { output, type: 'exec' } : {})
+ )
+ },
+ rpc: vi.fn(() => Promise.resolve({}))
+ }
+ })
+
+ expect(createSlashHandler(ctx)('/context')).toBe(true)
+ await vi.waitFor(() => expect(ctx.transcript.page).toHaveBeenCalledWith(output, 'Context'))
+ expect(ctx.transcript.sys).not.toHaveBeenCalledWith(output)
+ })
+
+ it('keeps a short owner read from slash.exec as a system line', async () => {
+ patchUiState({ sid: 'sid-abc' })
+
+ const ctx = buildCtx({
+ gateway: {
+ gw: {
+ getLogTail: vi.fn(() => ''),
+ request: vi.fn((method: string) =>
+ Promise.resolve(method === 'slash.exec' ? { output: 'Hermes v1', type: 'exec' } : {})
+ )
+ },
+ rpc: vi.fn(() => Promise.resolve({}))
+ }
+ })
+
+ expect(createSlashHandler(ctx)('/version')).toBe(true)
+ await vi.waitFor(() => expect(ctx.transcript.sys).toHaveBeenCalledWith('Hermes v1'))
+ expect(ctx.transcript.page).not.toHaveBeenCalled()
+ })
+
it('handles command.dispatch payloads returned directly by slash.exec', async () => {
patchUiState({ sid: 'sid-abc' })
diff --git a/ui-tui/src/app/createSlashHandler.ts b/ui-tui/src/app/createSlashHandler.ts
index c7d30533578..b52a46e2906 100644
--- a/ui-tui/src/app/createSlashHandler.ts
+++ b/ui-tui/src/app/createSlashHandler.ts
@@ -123,7 +123,14 @@ export function createSlashHandler(ctx: SlashHandlerContext): SlashHandler {
}
}
- const handleDispatch = (raw: unknown): void => {
+ // Main's sidecar slash output: a long reply opens the pager, a short one is a system line.
+ const showOutput = (text: string) => {
+ const long = text.length > 180 || text.split('\n').filter(Boolean).length > 2
+
+ long ? page(text, parsed.name[0]!.toUpperCase() + parsed.name.slice(1)) : sys(text)
+ }
+
+ const handleDispatch = (raw: unknown, fromExec = false): void => {
const d = parseCommandDispatch(raw)
if (!d) {
@@ -131,7 +138,9 @@ export function createSlashHandler(ctx: SlashHandlerContext): SlashHandler {
}
if (d.type === 'exec' || d.type === 'plugin') {
- return sys(d.output || '(no output)')
+ // The shared owner answers its slash.exec reads as `{type: 'exec'}`; they page like
+ // main's bare `{output}` did. command.dispatch output keeps its system line.
+ return fromExec && d.output ? showOutput(d.output) : sys(d.output || '(no output)')
}
if (d.type === 'alias') {
@@ -190,14 +199,12 @@ export function createSlashHandler(ctx: SlashHandlerContext): SlashHandler {
}
if (parseCommandDispatch(r)) {
- return handleDispatch(r)
+ return handleDispatch(r, true)
}
const body = r?.output || `/${parsed.name}: no output`
- const text = r?.warning ? `warning: ${r.warning}\n${body}` : body
- const long = text.length > 180 || text.split('\n').filter(Boolean).length > 2
- long ? page(text, parsed.name[0]!.toUpperCase() + parsed.name.slice(1)) : sys(text)
+ showOutput(r?.warning ? `warning: ${r.warning}\n${body}` : body)
})
.catch((execErr: unknown) => {
if (stale()) {