Repository navigation
Add Orca's own bundled-skill planner and installer (not wired in yet) - #31662
Conversation
One planner decides what installing Orca's bundled skills does to each target folder; execute re-plans under per-path locks and runs only a plan whose digest still matches; a shared summary derives badge, wording and exit code. A copy counts as Orca's untouched one only when its SKILL.md bytes match a version some build shipped (resources/skills/released-digests.json, generated from git history and checked add-only). Nothing calls this yet; the npx path is unchanged.
A leave is no longer a failure: the outcome line says what happened plus "N left alone: <reason>", and the exit code is 1 only for a failed or changed op. Backups for every scope go to <home>/.agents/.orca-skill-backups on the executing host, so a project Replace never writes into the repo; moving there falls back to copy, verify, then remove across filesystems.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
fb084906-1102-402e-9bb8-c855c453a3e2
📒 Files selected for processing: 8
src/main/skills/bundled-skill-install/execute.test.tssrc/main/skills/bundled-skill-install/execute.tssrc/main/skills/bundled-skill-install/filesystem.tssrc/main/skills/bundled-skill-install/layouts.test.tssrc/main/skills/bundled-skill-install/swap.tssrc/shared/bundled-skill-plan.tssrc/shared/bundled-skill-summary.test.tssrc/shared/bundled-skill-summary.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| async function settleCleanup(run: SkillRun, cleanup: BundledSkillCleanup) { | ||
| await requireUnchanged(run, cleanup.path, cleanup.observed) | ||
| await (cleanup.action === 'delete' | ||
| ? removeBundledSkillSibling(run.input.filesystem, cleanup.path) | ||
| : backUpBundledSkillPath(run.input.filesystem, cleanup.path, backupFor(run))) | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '75,165p' src/main/skills/bundled-skill-install/execute.ts
sed -n '45,115p' src/main/skills/bundled-skill-install/swap.ts
rg -n 'cleanup|backupPath|receipt|old sibling' src/main/skills/bundled-skill-install/plan.ts src/main/skills/bundled-skill-install/execute.test.ts src/main/skills/bundled-skill-install/layouts.test.tsRepository: stablyai/orca
Length of output: 8643
🏁 Script executed:
sed -n '110,270p' src/main/skills/bundled-skill-install/plan.ts
sed -n '1,260p' src/main/skills/bundled-skill-install/execute.ts
sed -n '70,125p' src/shared/bundled-skill-plan.ts
sed -n '130,190p' src/shared/bundled-skill-summary.ts
rg -n 'bundledSkillBackupPath|backupPath|BundledSkillInstallResult|summarizeBundledSkillOutcome|settleCleanup|cleanup.*backup|backup.*cleanup|receipt' src/main/skills/bundled-skill-install src/shared/bundled-skill-*Repository: stablyai/orca
Length of output: 22160
🏁 Script executed:
sed -n '1,75p' src/main/skills/bundled-skill-install/swap.ts
sed -n '145,170p' src/main/skills/bundled-skill-install/swap.ts
sed -n '1,235p' src/main/skills/bundled-skill-install/execute.test.ts
sed -n '300,395p' src/main/skills/bundled-skill-install/layouts.test.ts
sed -n '1,80p' src/main/skills/bundled-skill-install/service.ts
rg -n 'executeBundledSkillPlan|buildBundledSkillPlan|BundledSkillOpOutcome|summarizeBundledSkillOutcome' src/main src/shared --glob '*.ts'Repository: stablyai/orca
Length of output: 21794
🏁 Script executed:
sed -n '1,75p' src/main/skills/bundled-skill-install/swap.ts
sed -n '145,170p' src/main/skills/bundled-skill-install/swap.ts
sed -n '1,235p' src/main/skills/bundled-skill-install/execute.test.ts
sed -n '300,395p' src/main/skills/bundled-skill-install/layouts.test.ts
sed -n '1,80p' src/main/skills/bundled-skill-install/service.ts
rg -n 'bundledSkillBackupPath|orca-skill-backups|backupPath|executeBundledSkillPlan|summarizeBundledSkillOutcome' src --glob '*.ts'Repository: stablyai/orca
Length of output: 41457
Return cleanup backup paths in the operation outcome.
When a later plan finds a non-released .orca-old-* sibling, it schedules a backup. settleCleanup discards the path returned by backUpBundledSkillPath. A successful keep can therefore produce a done outcome without the backupPath documented for a moved non-released copy. Carry cleanup backup locations into the result so callers do not have to scan the backup directory.
| return settleOldCopy(run, old).catch(() => undefined) | ||
| } | ||
| case 'replace': { | ||
| const backupPath = backupFor(run) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '105,250p' src/main/skills/bundled-skill-install/execute.ts
sed -n '110,166p' src/main/skills/bundled-skill-install/swap.ts
sed -n '65,118p' src/shared/bundled-skill-plan.tsRepository: stablyai/orca
Length of output: 8425
🏁 Script executed:
printf '%s\n' '--- execute imports and cleanup ---'
sed -n '1,115p' src/main/skills/bundled-skill-install/execute.ts
printf '%s\n' '--- filesystem and error bindings ---'
rg -n -F --glob '*.ts' -e 'interface BundledSkillFilesystem' -e 'type BundledSkillFilesystem' -e 'filesystemErrorCode' -e 'settleCleanup' -e 'function settleCleanup' -e 'class BundledSkillChangedError' src/main/skills/bundled-skill-install src/shared
printf '%s\n' '--- cleanup type ---'
rg -n -F --glob '*.ts' -e 'BundledSkillCleanup' src/main/skills/bundled-skill-install src/shared
printf '%s\n' '--- summaries and backupPath consumers ---'
rg -n -F --glob '*.ts' -e 'backupPath' -e 'filesystemErrorCode' -e 'BundledSkillOpOutcome' src/main/skills/bundled-skill-install src/shared
printf '%s\n' '--- swap replacement implementation ---'
sed -n '1,175p' src/main/skills/bundled-skill-install/swap.ts
printf '%s\n' '--- relevant tests ---'
rg -n -F --glob '*.test.ts' -e 'replaceBundledSkillPath' -e 'cleanup' -e 'backupPath' -e 'filesystemErrorCode' src/main/skills/bundled-skill-install src/sharedRepository: stablyai/orca
Length of output: 25338
🏁 Script executed:
printf '%s\n' '--- filesystem contract and native implementation ---'
sed -n '1,145p' src/main/skills/bundled-skill-install/filesystem.ts
printf '%s\n' '--- summary source ---'
rg --files src | rg 'bundled-skill-summary'
sed -n '1,230p' src/shared/bundled-skill-summary.ts
printf '%s\n' '--- failed outcome/backup summary references ---'
rg -n -F --glob '*.ts' -e 'backupPath' -e 'error:' -e 'failed' src/shared/bundled-skill-summary.ts src/main/skills/bundled-skill-install/execute.test.ts
printf '%s\n' '--- focused execute tests ---'
sed -n '160,235p' src/main/skills/bundled-skill-install/execute.test.ts
printf '%s\n' '--- summary result formatting ---'
rg -n -F --glob '*.ts' -e 'summarizeBundledSkill' -e 'formatBundledSkill' -e 'bundledSkillSummary' srcRepository: stablyai/orca
Length of output: 17501
🏁 Script executed:
printf '%s\n' '--- native moveToBackup and relevant filesystem lines ---'
nl -ba src/main/skills/bundled-skill-install/filesystem.ts | sed -n '85,215p'
printf '%s\n' '--- cleanup producer ---'
nl -ba src/main/skills/bundled-skill-install/plan.ts | sed -n '105,165p'
printf '%s\n' '--- execution/result and summary locations ---'
nl -ba src/main/skills/bundled-skill-install/execute.ts | sed -n '92,110p;128,210p'
nl -ba src/main/skills/bundled-skill-install/swap.ts | sed -n '118,164p'
nl -ba src/shared/bundled-skill-plan.ts | sed -n '48,108p'
nl -ba src/shared/bundled-skill-summary.ts | sed -n '145,185p'Repository: stablyai/orca
Length of output: 16237
🏁 Script executed:
nl -ba src/main/skills/bundled-skill-install/plan.ts | sed -n '158,285p'
nl -ba src/shared/bundled-skill-plan.ts | sed -n '1,48p'Repository: stablyai/orca
Length of output: 7309
Report an existing backup after a failed replacement rollback.
A forced replace moves the user copy to backupPath before placing the new content. If placement fails and the restore also fails, the copy can remain only at the backup path. runSkill then records the error code but omits the path, and the summary does not display backup paths. Preserve the placement error as the cause, retain its error code, and add the path to the failed outcome only when stat confirms that it exists.
🐛 Suggested fix
diff --git a/src/main/skills/bundled-skill-install/swap.ts b/src/main/skills/bundled-skill-install/swap.ts
@@
export class BundledSkillChangedError extends Error {
constructor(path: string) {
super(`bundled-skill-changed: ${path}`)
}
}
+export class BundledSkillReplaceError extends Error {
+ constructor(
+ readonly cause: unknown,
+ readonly backupPath: string
+ ) {
+ super('bundled-skill-replace-failed')
+ }
+}
+
@@
} catch (error) {
await filesystem.moveToBackup(backupPath, target).catch(() => undefined)
await dropStaged()
- throw error
+ throw new BundledSkillReplaceError(error, backupPath)
}
}
diff --git a/src/main/skills/bundled-skill-install/execute.ts b/src/main/skills/bundled-skill-install/execute.ts
@@
BundledSkillChangedError,
+ BundledSkillReplaceError,
@@
- (error: unknown) =>
- error instanceof BundledSkillChangedError
- ? { path: op.path, kind: op.kind, status: 'changed' as const }
- : {
- path: op.path,
- kind: op.kind,
- status: 'failed' as const,
- error: filesystemErrorCode(error)
- }
+ async (error: unknown) => {
+ const replacementError =
+ error instanceof BundledSkillReplaceError ? error : undefined
+ const cause = replacementError ? replacementError.cause : error
+ if (cause instanceof BundledSkillChangedError) {
+ return { path: op.path, kind: op.kind, status: 'changed' as const }
+ }
+ const backupStat = replacementError
+ ? await run.input.filesystem.stat(replacementError.backupPath).catch(() => null)
+ : null
+ return {
+ path: op.path,
+ kind: op.kind,
+ status: 'failed' as const,
+ error: filesystemErrorCode(cause),
+ ...(replacementError && backupStat && backupStat.kind !== 'missing'
+ ? { backupPath: replacementError.backupPath }
+ : {})
+ }
+ }
diff --git a/src/shared/bundled-skill-summary.ts b/src/shared/bundled-skill-summary.ts
@@
const reasons = [...new Set(leftAlone.map((left) => left.reason))].join('; ')
+ const line =
+ leftAlone.length > 0 ? `${text} · ${leftAlone.length} left alone: ${reasons}` : text
+ const backupPaths = outcome.ops.flatMap((op) => (op.backupPath ? [op.backupPath] : []))
return {
name: outcome.name,
text,
leftAlone,
- line: leftAlone.length > 0 ? `${text} · ${leftAlone.length} left alone: ${reasons}` : text
+ line: backupPaths.length > 0 ? `${line} · Backup: ${backupPaths.join(', ')}` : line
}
}The orcad bundle rejects a literal non-ASCII character in a regex.
…s on Windows Directory links in fixtures are junctions on Windows, which need no Developer Mode; the one file-link fixture is skipped there.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
038a44ea-2617-4787-a1aa-4efb5fd4da51
📒 Files selected for processing: 5
src/main/skills/bundled-skill-install/classify.tssrc/main/skills/bundled-skill-install/execute.test.tssrc/main/skills/bundled-skill-install/filesystem.tssrc/main/skills/bundled-skill-install/swap.tssrc/shared/bundled-skill-plan.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
ELI5
Orca ships a few of its own skills (
orca-cli,orchestration, ...). Today Orca installs and updates them by running a third-party command,npx skills add, which needs Node, Git and the network, and which fails in ways Orca can't see (translated Git output, #28914; rate limits; offline machines).This PR adds the replacement: Orca's own small installer for those skills. It is not connected to anything yet, so nothing changes for users in this PR. The next PRs switch the app, the CLI and paired servers over to it and delete the
npxcode.What Changed
Before and after for users: none. No IPC, CLI command, RPC or screen calls the new code. The
npxpath is unchanged.The new code has three parts, with one rule: only the planner decides.
src/main/skills/bundled-skill-install/plan.ts): reads the disk and returns one operation per target folder (the shared~/.agents/skills/<name>plus each detected agent's folder, deduplicated by real path). Operations arekeep,write,update,link,copy,restore,leave(with a reason), andreplace(only for a path the user chose to replace). Each operation records what the folder held when planned. The plan has a digest.execute.ts,swap.ts): takes the existing per-path skill locks in sorted order, plans again, and runs only if the digest still matches what the user previewed. Right before each destructive rename it re-reads the folder with the same reader and stops that operation (changed) if it differs. It never chooses a different operation.src/shared/bundled-skill-summary.ts): the only place that turns a plan or a result into a badge, wording ("You've changed this copy", "A different skill already uses this name"), a result line, and a CLI exit code. The line says what happened plus any folders left alone, e.g. "Updated · 1 left alone: You've changed this copy". Leaving someone else's folder alone is a warning, not a failure: the exit code is 1 only when an operation failed or found the disk changed.How Orca recognises its own untouched copy: the folder holds exactly
SKILL.md(OS files like.DS_Storeignored) and the file's sha256, after converting line endings to LF, is one Orca has shipped.resources/skills/released-digests.jsonlists those digests (124 today, everyskills/*/SKILL.mdinmain's history). The manifest generator builds it from git history, embeds it with the current skill text inbundled-skill-sources.ts(so hosts with no app resources folder can install), and its existing CI step now also fails if the file is missing a digest or drops one the base branch had.Safety rules the code enforces:
removeBundledSkillSibling) refuses anything except Orca's own.<name>.orca-stage-*/.<name>.orca-old-*siblings.<home>/.agents/.orca-skill-backups/on the host doing the install, so a project-scope Replace never writes into the repo. When that is another filesystem, the move copies, verifies the copy byte-for-byte, and only then removes the original.busy); a released copy with a cloud-sharing receipt reads as another skill.Small edits outside the new folder:
createNativeSkillAliasextracted and exported fromskill-placement-reconciliation.ts(no behaviour change), the two new sibling names documented instaging-names.ts(discovery already hides that shape), and the ledger file excluded fromoxfmtbecause it is generated.Why
Two earlier attempts (#29196, #29206) wired a planner into the existing cloud-sharing installer. Four separate parts ended up deciding what to do (planner, installer transaction, placement reconciliation, freshness scanner), so the preview and the actual run drifted apart, and reviews kept finding cases where "Updated" was reported for something that wasn't, or a foreign copy was replaced. This version copies the model of
skill-delete/: one builder used by both preview and execute, and execute re-plans under the lock rather than trusting a client-supplied plan.Recognising Orca's copies by shipped bytes, instead of the
npxlock file's hash, gives one rule for every way a copy got there (npxwith any of its three hash formats, an XDG lock location, a project lock, a hand copy, Orca itself) with no receipts to write. Edits or added files can never read as untouched. The cost is one generated file with an add-only check.Deviations from the design doc (design-rev4), all deliberate:
resolveSkillInstallDestination+resolveSkillProviderRoots); the runtime host wiring that calls it lands with the callers in the next PR.restorereads "Needs attention": it puts back the copy an interrupted update moved aside, which still needs updating. Its exit code is 0, since nothing failed..agents/.orca-skill-backupsfor every scope, not beside each skills folder, so project scope stays out of the repo.copyis planned for hosts whose filesystem says otherwise (WSL/remote come later).Linked Issue
Refs #28914
Visual Proof
N/A: nothing calls this code yet, so there is no visible change.
Testing
src/main/skills/bundled-skill-install/layouts.test.ts: 18 real-disk home layouts (npx shared copy, npx single-agent folder, already current, edited, extra file, CRLF,.DS_Store, link elsewhere, broken link, plugin copy only, read-only folder, a second agent, link-only work, someone else's skill, host that cannot link,~/.claude/skillslinked to~/.agents/skills, Replace of an edited copy, Replace of an outside link). Each asserts the planned operations, that the run did exactly those operations, the files afterwards, the npx lock byte-identical, and that a second preview has nothing left to do. Plus project scope, a Claude profile reached through a link, backups, busy and cloud-receipt cases.Backup placement: a project Replace backs up into the home; a cross-filesystem move copies, verifies, then removes.
execute.test.ts: crash at each step of an update and of a Replace, then recovery; disk edited after the preview; wrong digest; a write racing the rename; a writer changing the old copy before it is deleted; a held lock.classify.test.ts,bundled-skill-sources.test.ts,src/shared/bundled-skill-summary.test.ts, and the generator tests (history scan, add-only, LF embedding).Ran locally on macOS:
pnpm tc, the tests above,pnpm run check:code-quality:changed, oxlint (default, anti-slop, native plugins, type-aware),oxfmt --check ., and thepr.ymlstatic checks (import boundaries, sync-spawn ratchet, reliability gates, ratchets, generated-file checks including the skill manifest, localization coverage, root entries).I manually tested these changes locally (not applicable: nothing calls this code yet; the real-app before/after runs with the next PR)
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
changed, not a loss.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)