Files
orca/src/shared/cli-argument-boundary.ts
T
Kelvin Amoaba dcaeaaa1fc feat(browser): typed snapshot flags, screenshots saved as files, and a guide that keeps browser work in Orca (#36257)
* feat(browser): typed snapshot flags and screenshots saved as files for agents

orca snapshot takes --interactive, --compact, --depth, --selector, --urls,
--delta and --full, passed to agent-browser on every route. The header
now shows the page title and URL. orca screenshot and full-screenshot save
the image where the CLI runs and print its path, in CSS pixels, with
--if-changed and --annotate. Flag help for exec, wait and download is
written for those commands, and the orca-cli guide sends web pages to
Orca's browser unless the user picked another tool.

* fix(browser): scale screenshots by the scrollbar-free axis and keep snapshot metadata behind SSH admission

* fix(browser): upscale low-DPR screenshots and wrap a torn-down tab's screenshot error

* fix(browser): give each screenshot its own file and keep typed screenshot errors

* refactor(browser): share the agent-browser screenshot reader between Electron and orcad

* refactor(browser): move snapshot and screenshot params under the line cap
2026-10-30 15:07:05 +00:00

122 lines
2.6 KiB
TypeScript

export const CLI_GLOBAL_VALUE_FLAGS: readonly string[] = ['pairing-code', 'environment']
export const CLI_GLOBAL_FLAGS: readonly string[] = ['help', 'json', ...CLI_GLOBAL_VALUE_FLAGS]
export const CLI_BOOLEAN_FLAGS = new Set([
'accept-changed-state',
'agent-wait',
'all',
'allow-failed-archive-hook',
'annotate',
'attachments',
'children',
'comments',
'compact',
'connect',
'current',
'current-json',
'current-sqlite',
'debug',
'delete-branch',
'delta',
'dry-run',
'enter',
'focus',
'grant-desktop-control',
'force',
'fresh',
'full',
'full-tree',
'help',
'if-changed',
'inject',
'include-archived',
'include-remote',
'include-visual-layouts',
'index-status',
'interactive',
'interrupt',
'json',
'latest-json',
'local',
'messages',
'me',
'mobile',
'mobile-pairing',
'no-pairing',
'screen',
'parent-current',
'provision',
'ready',
'recipe-json',
'reclaim-stale-lock',
'references',
'relations',
'removed',
'reinstall',
'restore-window',
'return-preamble',
'run-hooks',
'show-profile',
'staged',
'supervise',
'tab',
'takeover-legacy',
'tasks',
'text-stdin',
'unread',
'urls',
'value-stdin',
'wait',
'yes'
])
function commandPathStartsAt(
argv: readonly string[],
tokenIndex: number,
path: readonly string[]
): boolean {
let cursor = tokenIndex
for (const part of path) {
while (argv[cursor]?.startsWith('--')) {
const assignment = argv[cursor].slice(2)
const flag = assignment.split('=', 1)[0]
cursor += assignment.includes('=') || CLI_BOOLEAN_FLAGS.has(flag) ? 1 : 2
}
if (argv[cursor] !== part) {
return false
}
cursor += 1
}
return true
}
export function findCliCommandIndex(
argv: readonly string[],
commandPaths: readonly (readonly string[])[],
knownValueFlags: readonly string[] = []
): number {
const startsCommandAt = (index: number): boolean =>
commandPaths.some((path) => commandPathStartsAt(argv, index, path))
for (let index = 0; index < argv.length;) {
const token = argv[index]
if (!token.startsWith('--')) {
return startsCommandAt(index) ? index : -1
}
const assignment = token.slice(2)
const flag = assignment.split('=', 1)[0]
const next = argv[index + 1]
const takesNext =
!assignment.includes('=') &&
!CLI_BOOLEAN_FLAGS.has(flag) &&
next !== undefined &&
!next.startsWith('--') &&
(knownValueFlags.includes(flag) ||
!(startsCommandAt(index + 1) && !startsCommandAt(index + 2)))
index += takesNext ? 2 : 1
}
return -1
}