perf(runtime): gate terminal.list visual layouts (#12450)
* perf(runtime): gate terminal.list visual layouts and stop the false writable claim visualLayouts is ~31% of a large terminal.list payload (44,208 B of 137,412 B on a live 134-terminal remote runtime) and has exactly one consumer: the human-readable CLI formatter. Gate it behind an includeVisualLayouts request param that defaults to included, so pre-flag clients are unaffected, and have every --json/internal caller opt out. Also drop the record-backed builder's writable, which was a verbatim copy of connected. terminal.show now states writability explicitly as exactly what terminal.send's PTY gate enforces. * test(runtime): type the payload-size fixture arrays for tsc * fix(runtime): preserve terminal list compatibility * test(runtime): guard terminal list optimization * fix(cli): preserve agent access to terminal layouts
This commit is contained in:
@@ -28,6 +28,7 @@ export const BOOLEAN_FLAGS = new Set([
|
||||
'help',
|
||||
'inject',
|
||||
'include-archived',
|
||||
'include-visual-layouts',
|
||||
'interrupt',
|
||||
'json',
|
||||
'local',
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -55,7 +55,9 @@ export const TERMINAL_HANDLERS: Record<string, CommandHandler> = {
|
||||
'terminal list': async ({ flags, client, cwd, json }) => {
|
||||
const result = await client.call<RuntimeTerminalListResult>('terminal.list', {
|
||||
worktree: await getOptionalWorktreeSelector(flags, 'worktree', cwd, client),
|
||||
limit: getOptionalPositiveIntegerFlag(flags, 'limit')
|
||||
limit: getOptionalPositiveIntegerFlag(flags, 'limit'),
|
||||
// Why: agent JSON calls dominate; topology stays available through an explicit opt-in.
|
||||
includeVisualLayouts: !json || flags.has('include-visual-layouts')
|
||||
})
|
||||
printResult(result, json, formatTerminalList)
|
||||
},
|
||||
|
||||
+6
-1
@@ -237,7 +237,7 @@ Common Commands:
|
||||
orca file open <path> [--worktree <selector>] [--json]
|
||||
orca file diff <path> [--staged] [--worktree <selector>] [--json]
|
||||
orca file open-changed [--mode edit|diff|both] [--worktree <selector>] [--json]
|
||||
orca terminal list [--worktree <selector>] [--limit <n>] [--json]
|
||||
orca terminal list [--worktree <selector>] [--limit <n>] [--include-visual-layouts] [--json]
|
||||
orca terminal show [--terminal <handle>] [--json]
|
||||
orca terminal read [--terminal <handle>] [--cursor <n>] [--limit <n>] [--json]
|
||||
orca terminal send [--terminal <handle>] [--text <text>] [--enter] [--interrupt] [--json]
|
||||
@@ -272,6 +272,9 @@ Terminal Send Options:
|
||||
--enter Append Enter after sending text
|
||||
--interrupt Send as an interrupt-style input when supported
|
||||
|
||||
Terminal List Options:
|
||||
--include-visual-layouts Include tab and pane topology in JSON output
|
||||
|
||||
Wait Options:
|
||||
--for exit Wait until the target terminal exits
|
||||
--timeout-ms <ms> Maximum wait time before timing out
|
||||
@@ -535,6 +538,8 @@ export function formatFlagHelp(flag: string): string {
|
||||
'from-x': '--from-x <x> Source window-local x coordinate',
|
||||
'from-y': '--from-y <y> Source window-local y coordinate',
|
||||
help: '--help Show this help message',
|
||||
'include-visual-layouts':
|
||||
'--include-visual-layouts Include tab and pane topology in JSON output',
|
||||
interrupt: '--interrupt Send as an interrupt-style input when supported',
|
||||
id: '--id <id> Identifier for a target item or permission',
|
||||
issue: '--issue <number|null> Linked GitHub issue number',
|
||||
|
||||
+67
-1
@@ -426,6 +426,19 @@ describe('orca root help', () => {
|
||||
expect(callMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('documents the machine-readable terminal topology opt-in', async () => {
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
logSpy.mockClear()
|
||||
|
||||
await main(['terminal', 'list', '--help'], '/tmp/repo')
|
||||
|
||||
const help = String(logSpy.mock.calls[0][0])
|
||||
expect(help).toContain('[--include-visual-layouts] [--json]')
|
||||
expect(help).toContain('--include-visual-layouts Include tab and pane topology in JSON output')
|
||||
expect(help).toContain('JSON omits visualLayouts by default')
|
||||
expect(callMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('describes worker-read cursors as opaque', async () => {
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
logSpy.mockClear()
|
||||
@@ -3705,7 +3718,60 @@ describe('orca cli worktree awareness', () => {
|
||||
|
||||
expect(callMock).toHaveBeenNthCalledWith(2, 'terminal.list', {
|
||||
worktree: 'id:repo::/tmp/repo/feature',
|
||||
limit: undefined
|
||||
limit: undefined,
|
||||
includeVisualLayouts: false
|
||||
})
|
||||
})
|
||||
|
||||
it('requests visual layouts only for the human-readable terminal list', async () => {
|
||||
queueFixtures(
|
||||
callMock,
|
||||
worktreeListFixture([buildWorktree('/tmp/repo/feature', 'feature/foo')]),
|
||||
okFixture('req_term', { terminals: [], totalCount: 0, truncated: false })
|
||||
)
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
|
||||
await main(['terminal', 'list', '--worktree', 'active'], '/tmp/repo/feature/src')
|
||||
|
||||
expect(callMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
'terminal.list',
|
||||
expect.objectContaining({ includeVisualLayouts: true })
|
||||
)
|
||||
})
|
||||
|
||||
it('allows agent JSON clients to request visual layouts explicitly', async () => {
|
||||
const visualLayouts = [
|
||||
{
|
||||
worktreeId: 'repo::/tmp/repo/feature',
|
||||
worktreePath: '/tmp/repo/feature',
|
||||
root: { type: 'group', groupId: null, activeTabId: null, tabs: [] }
|
||||
}
|
||||
]
|
||||
queueFixtures(
|
||||
callMock,
|
||||
worktreeListFixture([buildWorktree('/tmp/repo/feature', 'feature/foo')]),
|
||||
okFixture('req_term', {
|
||||
terminals: [],
|
||||
visualLayouts,
|
||||
totalCount: 0,
|
||||
truncated: false
|
||||
})
|
||||
)
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
|
||||
await main(
|
||||
['terminal', 'list', '--worktree', 'active', '--include-visual-layouts', '--json'],
|
||||
'/tmp/repo/feature/src'
|
||||
)
|
||||
|
||||
expect(callMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
'terminal.list',
|
||||
expect.objectContaining({ includeVisualLayouts: true })
|
||||
)
|
||||
expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject({
|
||||
result: { visualLayouts }
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -180,8 +180,12 @@ export const CORE_COMMAND_SPECS: CommandSpec[] = [
|
||||
{
|
||||
path: ['terminal', 'list'],
|
||||
summary: 'List live Orca-managed terminals',
|
||||
usage: 'orca terminal list [--worktree <selector>] [--limit <n>] [--json]',
|
||||
allowedFlags: [...GLOBAL_FLAGS, 'worktree', 'limit']
|
||||
usage:
|
||||
'orca terminal list [--worktree <selector>] [--limit <n>] [--include-visual-layouts] [--json]',
|
||||
allowedFlags: [...GLOBAL_FLAGS, 'worktree', 'limit', 'include-visual-layouts'],
|
||||
notes: [
|
||||
'JSON omits visualLayouts by default; pass --include-visual-layouts when machine-readable tab and pane topology is required.'
|
||||
]
|
||||
},
|
||||
{
|
||||
path: ['terminal', 'show'],
|
||||
|
||||
Reference in New Issue
Block a user