Files
orca/src/cli/agent-context.ts
T
Neil 15717a4e53 Add CLI commands to manage and find workspace references (#26807)
* Add CLI commands to manage and find workspace references

* Fix reference review findings: source-context twins, legacy link collapse, closed chats, old-host errors

- Keep same-URL links with different source contexts separate; CLI add/remove no longer drops a twin
- Restore merging a bare legacy link into its single matching URL link (no duplicate PR rows, no resurrection on older-client removal)
- Carry absorbed data through collapse chains; resolve repoId conflicts deterministically
- Identity: ignore www., case-insensitive GitHub/GitLab/Gitea paths (stored URL keeps case), no Jira match on git hosts; find accepts self-hosted issue URLs
- reference find: skip closed native chats, require a session id for linked, include an explicitly named archived workspace, warm-cache fallback for --worktree
- Selector parity: collapse same-host duplicate paths, issue: ignores unlinked rows
- CLI: clear update-host error for hosts without reference.*, local flag checks before host probe, help text fixes

* Fix CI: add reference rm alias for verb policy; expect linkedItems in worktree ps summary

* Simplify reference CLI: share identifier/legacy-match helpers, drop redundant dedupe
2026-10-09 22:22:01 -07:00

67 lines
2.2 KiB
TypeScript

import type { CommandSpec } from './args'
import { effectiveAllowedFlags } from './args'
// Why: serialize the live spec table so agent discovery cannot drift from the
// command surface it describes.
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
// Why: hidden specs dispatch but stay off every discovery surface, including this one.
.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,
// Why: the effective accepted set (globals + conditional --page), not just
// allowedFlags — otherwise agents treat --json/--help as unsupported.
flags: effectiveAllowedFlags(spec),
positionalArgs: spec.positionalArgs ?? [],
...(spec.variadicPositional ? { variadicPositional: true } : {}),
...(spec.repeatableFlags ? { repeatableFlags: spec.repeatableFlags } : {}),
examples: spec.examples ?? [],
notes: spec.notes ?? []
}))
// Why: deterministic ordering so the JSON diffs cleanly across runs.
.sort((a, b) => a.command.localeCompare(b.command))
return {
schemaVersion: SCHEMA_VERSION,
commandCount: commands.length,
commands
}
}
export function formatAgentContextSummary(schema: AgentContextSchema): string {
// Why: keep the default (human) output bounded — the full surface is large, so
// point the reader at --json rather than dumping every command.
return [
`${schema.commandCount} commands (schema v${schema.schemaVersion}).`,
'Run `orca agent-context --json` for the full machine-readable command schema.'
].join('\n')
}