Files
orca/src/shared/agent-feature-install-commands.ts
T
Sebastián Castañoandscastanoh21 676ef7fab8 feat(cli): add orca skills install and orca skills update for headless skill setup (#9201)
Adds `orca skills install` and `orca skills update` so skills can be set up without the GUI — SSH hosts, containers, CI. Previously `orca skills` had only `list` and `get`, so there was no headless path.

**Agent targeting is scoped explicitly rather than delegated to detection.** The `skills` CLI decides which agents to install into, and with `-y` and zero detected agents it takes `targetAgents = validAgents` — all ~75. That is not a corner case for a headless CLI: a fresh SSH box or container with no agent installed is the normal starting state. Measured on a bare host, the unscoped command created **52 top-level agent directories and 54 junctions** (one real payload in `~/.agents/skills`, the rest links) on Windows, and 52/53 on macOS.

The CLI now passes `--agent` derived from Orca's own detection, mapped to the `skills` key namespace, plus `universal`. Supplying `--agent` makes `runAdd` use it directly and never call `detectInstalledAgents()`, so the fan-out branch is unreachable. On a bare host it now refuses with `No coding agent detected on this host` and exit 1, creating nothing. Same command with scoping: **1 directory, 0 junctions.**

`universal` alone would under-install — Claude Code is not in that set, and 19 of 28 mapped keys write agent-private homes `universal` never touches. `--agent '*'` is the bug itself. The mapping is hedged three ways: `null` for any agent whose key could not be confirmed, `satisfies Record<TuiAgent, …>` so a new Orca agent is a compile error, and a test pinning every mapped key against the CLI's own valid list.

Fixed during review — two holes that each restored the full fan-out through a different door:
- `--agent ','` trimmed to nothing, which skipped the refusal *and* emitted no `--agent`.
- `--agent -y` passed an emptiness check, and the vendor CLI silently drops `-`-leading values, re-emptying its list.

The real invariant is argument *shape*, not emptiness, and it is now enforced at the choke point in `buildAgentFeatureSkillInstallArgs`, so no caller can emit `-y` without a usable target. `*` remains allowed — asking for every agent explicitly is a choice, not an accident. Verified with 51 hostile inputs through the built binary, each recorded argv replayed through the vendor's own parser.

Also fixed: the `ORCA_CLI_CWD` refusal now runs before target resolution (it was quoting the wrong host's agent list), and `--dry-run` is refused in a forwarded shell rather than printing a command naming the wrong machine.

Validated on a real Windows host across PowerShell 7, PowerShell 5.1, cmd.exe and Git Bash: `.cmd` shims route through `cmd.exe` and `.exe` shims spawn directly (proved with instrumented shims, not inferred), the ENOENT path produces an actionable error rather than a silent failure, and `skills update` genuinely restores a corrupted skill byte-for-byte.

Known, not addressed here — both upstream behaviours this only forwards: a partial install failure exits 0, and "no installed skills found" exits 0. Both are invisible to the headless callers this feature exists for.

Co-authored-by: scastanoh21 <scastanoh21@gmail.com>
2026-07-30 11:20:29 -07:00

139 lines
5.1 KiB
TypeScript

import { isSkillsCliAgentKeyShaped } from './skills-cli-agent-keys'
export const ORCA_SKILLS_REPOSITORY_URL = 'https://github.com/stablyai/orca'
export const ORCA_CLI_SKILL_NAME = 'orca-cli'
export const COMPUTER_USE_SKILL_NAME = 'computer-use'
export const ORCHESTRATION_SKILL_NAME = 'orchestration'
export const EPHEMERAL_VMS_SKILL_NAME = 'orca-per-workspace-env'
export const ORCA_LINEAR_SKILL_NAME = 'orca-linear'
export const LINEAR_TICKETS_SKILL_NAME = 'linear-tickets'
export const LINEAR_AGENT_SKILL_NAMES = [ORCA_LINEAR_SKILL_NAME, LINEAR_TICKETS_SKILL_NAME] as const
// Why: `yes` and `agents` default off so every Settings/onboarding string a human
// pastes keeps its interactive prompts and the CLI's own agent detection. Only an
// unattended spawn, which nothing can answer, opts in.
export type AgentFeatureSkillCommandOptions = {
global?: boolean
yes?: boolean
agents?: readonly string[]
}
export function buildAgentFeatureSkillInstallArgs(
skillNames: readonly string[],
options: AgentFeatureSkillCommandOptions = {}
): string[] {
if (skillNames.length === 0) {
throw new Error('At least one skill name is required.')
}
const global = options.global ?? true
// Why: -y with no --agent is the one combination that makes `skills add` install
// into every agent it knows. Refuse it here so no caller can express it.
const agents = options.agents ?? []
if (options.yes && agents.length === 0) {
throw new Error('An install target is required when skipping prompts.')
}
// Why: a value the skills CLI would drop leaves it with no target at all, which
// is the same all-agents install as passing no --agent.
const unusable = agents.find((agent) => !isSkillsCliAgentKeyShaped(agent))
if (unusable !== undefined) {
throw new Error(`"${unusable}" is not a usable install target.`)
}
// Why: one flag per name remains compatible with both single-value and variadic parsers.
const skillArgs = skillNames.flatMap((name) => ['--skill', name])
return [
'skills',
'add',
ORCA_SKILLS_REPOSITORY_URL,
...skillArgs,
...(global ? ['--global'] : []),
// Why: an explicit --agent stops `skills add` calling its own detection, whose
// zero-detected branch installs into all ~75 known agents and litters a bare
// host with agent config directories it has no agent for.
...agents.flatMap((agent) => ['--agent', agent]),
// Why: without -y `skills add` opens an interactive agent picker and blocks
// forever on any TTY, which is every ssh session.
...(options.yes ? ['-y'] : [])
]
}
export function buildAgentFeatureSkillInstallCommand(
skillNames: readonly string[],
options: AgentFeatureSkillCommandOptions = {}
): string {
return `npx ${buildAgentFeatureSkillInstallArgs(skillNames, options).join(' ')}`
}
export function buildAgentFeatureSkillUpdateArgs(
skillNames: string | readonly string[],
options: AgentFeatureSkillCommandOptions = {}
): string[] {
const rawNames = typeof skillNames === 'string' ? [skillNames] : skillNames
const names = rawNames.map((name) => name.trim()).filter((name) => name.length > 0)
if (names.length === 0) {
throw new Error('A skill name is required.')
}
const global = options.global ?? true
return [
'skills',
'update',
...names,
global ? '--global' : '--project',
...(options.yes ? ['-y'] : [])
]
}
export function buildAgentFeatureSkillUpdateCommand(
skillNames: string | readonly string[],
options: AgentFeatureSkillCommandOptions = {}
): string {
return `npx ${buildAgentFeatureSkillUpdateArgs(skillNames, options).join(' ')}`
}
export const ORCA_CLI_SKILL_INSTALL_COMMAND = buildAgentFeatureSkillInstallCommand([
ORCA_CLI_SKILL_NAME
])
export const ORCA_CLI_SKILL_UPDATE_COMMAND =
buildAgentFeatureSkillUpdateCommand(ORCA_CLI_SKILL_NAME)
export const COMPUTER_USE_SKILL_INSTALL_COMMAND = buildAgentFeatureSkillInstallCommand([
COMPUTER_USE_SKILL_NAME
])
export const COMPUTER_USE_SKILL_UPDATE_COMMAND =
buildAgentFeatureSkillUpdateCommand(COMPUTER_USE_SKILL_NAME)
export const ORCHESTRATION_SKILL_INSTALL_COMMAND = buildAgentFeatureSkillInstallCommand([
ORCHESTRATION_SKILL_NAME
])
export const ORCHESTRATION_SKILL_UPDATE_COMMAND =
buildAgentFeatureSkillUpdateCommand(ORCHESTRATION_SKILL_NAME)
export const EPHEMERAL_VMS_SKILL_INSTALL_COMMAND = buildAgentFeatureSkillInstallCommand([
EPHEMERAL_VMS_SKILL_NAME
])
export const EPHEMERAL_VMS_SKILL_UPDATE_COMMAND =
buildAgentFeatureSkillUpdateCommand(EPHEMERAL_VMS_SKILL_NAME)
export const ORCA_CLI_ORCHESTRATION_SKILL_INSTALL_COMMAND = buildAgentFeatureSkillInstallCommand([
ORCA_CLI_SKILL_NAME,
ORCHESTRATION_SKILL_NAME
])
export const ORCA_LINEAR_SKILL_INSTALL_COMMAND = buildAgentFeatureSkillInstallCommand([
ORCA_LINEAR_SKILL_NAME
])
export const ORCA_LINEAR_SKILL_UPDATE_COMMAND =
buildAgentFeatureSkillUpdateCommand(ORCA_LINEAR_SKILL_NAME)
export const LINEAR_TICKETS_SKILL_INSTALL_COMMAND = buildAgentFeatureSkillInstallCommand([
LINEAR_TICKETS_SKILL_NAME
])
export const LINEAR_TICKETS_SKILL_UPDATE_COMMAND =
buildAgentFeatureSkillUpdateCommand(LINEAR_TICKETS_SKILL_NAME)