mirror of
https://github.com/stablyai/orca.git
synced 2026-10-20 08:03:28 +00:00
* feat(cli): make the CLI self-correcting and self-describing for agents Agents build a generalized model of how CLIs work and apply it to every tool. When orca diverged — `rm` where git uses `remove` — a reasonable first guess (`orca worktree remove`) dead-ended on a bare "Unknown command" with no path forward. This makes the CLI degrade gracefully when the orca-cli skill isn't loaded in context. - First-class CommandSpec.aliases, resolved to the canonical path before dispatch (no new handler registrations). `worktree remove`/`delete` now resolve to `rm`; the ad-hoc `terminal focus` duplicate spec/handler is migrated onto the mechanism. - Did-you-mean suggestions on unknown commands and unknown flags, ranked by edit distance over the live registry, surfaced in both stderr and --json error.data (reusing the existing nextSteps channel). - `orca agent-context [--json]`: a versioned, machine-readable dump of the command schema. Pure local read (no RPC), so it works over SSH and when the app isn't running. - CI guards: specs<->handlers parity, and a vocabulary policy that fails on new off-policy deletion/read verbs (existing ones grandfathered). * Address PR review feedback (#6303) - agent-context now emits each command's effective flag set (globals + conditional --page), not just allowedFlags, so the schema no longer under-reports --json/--help. Shared as effectiveAllowedFlags() between validation and the schema. - Collision check now covers alias paths too, so a duplicate alias that would silently shadow a real command fails the build. * fix(cli): harden agent recovery and introspection Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com> Co-authored-by: Orca <help@stably.ai>
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { formatCliError } from './format'
|
|
import { RuntimeClientError, RuntimeRpcFailureError } from './runtime-client'
|
|
|
|
describe('CLI error recovery', () => {
|
|
it('prints did-you-mean next steps for an unknown-command error carrying data', () => {
|
|
const error = new RuntimeClientError('invalid_argument', 'Unknown command: worktree remov', {
|
|
suggestions: ['worktree rm'],
|
|
nextSteps: ['Did you mean: orca worktree rm']
|
|
})
|
|
|
|
const output = formatCliError(error)
|
|
|
|
expect(output).toContain('Unknown command: worktree remov')
|
|
expect(output).toContain('Next step: Did you mean: orca worktree rm')
|
|
})
|
|
|
|
it('prefers structured recovery over generic computer hints in text output', () => {
|
|
const error = new RuntimeClientError('invalid_argument', 'Unknown flag --forcce', {
|
|
nextSteps: ['Did you mean: --force']
|
|
})
|
|
|
|
const output = formatCliError(error, { commandPath: ['computer', 'click'] })
|
|
|
|
expect(output).toContain('Next step: Did you mean: --force')
|
|
expect(output).not.toContain('Fix the command flags or RPC params')
|
|
})
|
|
|
|
it('prefers RPC recovery over generic computer hints in text output', () => {
|
|
const error = new RuntimeRpcFailureError({
|
|
id: 'req_rpc_recovery',
|
|
ok: false,
|
|
error: {
|
|
code: 'invalid_argument',
|
|
message: 'Unknown runtime argument',
|
|
data: { nextSteps: ['Use the runtime-specific option'] }
|
|
},
|
|
_meta: { runtimeId: 'runtime_local' }
|
|
})
|
|
|
|
const output = formatCliError(error, { commandPath: ['computer', 'click'] })
|
|
|
|
expect(output).toContain('Next step: Use the runtime-specific option')
|
|
expect(output).not.toContain('Fix the command flags or RPC params')
|
|
})
|
|
|
|
it('keeps generic computer hints when an RPC error has no recovery data', () => {
|
|
const error = new RuntimeRpcFailureError({
|
|
id: 'req_rpc_fallback',
|
|
ok: false,
|
|
error: { code: 'invalid_argument', message: 'Invalid computer argument' },
|
|
_meta: { runtimeId: 'runtime_local' }
|
|
})
|
|
|
|
const output = formatCliError(error, { commandPath: ['computer', 'click'] })
|
|
|
|
expect(output).toContain('Fix the command flags or RPC params')
|
|
})
|
|
})
|