Files
archived-orca/src/cli/discovery/agent-context.ts
T
Neil 560a22e00f refactor(cli): organize command dispatch and orchestration owners (#41562)
* refactor(cli): organize command dispatch and orchestration owners

* test(orchestration): retire superseded unbound mail refusal case
2026-11-12 08:12:55 -08:00

60 lines
1.8 KiB
TypeScript

import type { CommandSpec } from './command-spec'
import { effectiveAllowedFlags } from '../arguments/args'
const SCHEMA_VERSION = 1
export type AgentContextCommand = {
command: string
path: string[]
aliases: string[][]
argumentMode: 'parsed' | 'passthrough'
summary: string
usage: string
flags: string[]
positionalArgs: string[]
variadicPositional?: boolean
repeatableFlags?: string[]
examples: string[]
notes: string[]
}
export type AgentContextSchema = {
schemaVersion: number
commandCount: number
commands: AgentContextCommand[]
}
export function buildAgentContext(specs: CommandSpec[]): AgentContextSchema {
const commands = specs
// Hidden commands dispatch but stay off discovery surfaces.
.filter((spec) => spec.hidden !== true)
.map((spec) => ({
command: spec.path.join(' '),
path: spec.path,
aliases: spec.aliases ?? [],
argumentMode: spec.argumentMode ?? 'parsed',
summary: spec.summary,
usage: spec.usage,
// Include globals and conditional flags so discovery matches validation.
flags: effectiveAllowedFlags(spec),
positionalArgs: spec.positionalArgs ?? [],
...(spec.variadicPositional ? { variadicPositional: true } : {}),
...(spec.repeatableFlags ? { repeatableFlags: spec.repeatableFlags } : {}),
examples: spec.examples ?? [],
notes: spec.notes ?? []
}))
.sort((a, b) => a.command.localeCompare(b.command))
return {
schemaVersion: SCHEMA_VERSION,
commandCount: commands.length,
commands
}
}
export function formatAgentContextSummary(schema: AgentContextSchema): string {
return [
`${schema.commandCount} commands (schema v${schema.schemaVersion}).`,
'Run `orca agent-context --json` for the full machine-readable command schema.'
].join('\n')
}