diff --git a/plugins/cli/docs/cli.md b/plugins/cli/docs/cli.md index 74c1a785..3ebf8157 100644 --- a/plugins/cli/docs/cli.md +++ b/plugins/cli/docs/cli.md @@ -72,9 +72,15 @@ that is CPython 3.13 behaviour the program reproduces on purpose (`ts/src/pylib` included, is refused with the folder's path; `--replace` removes that one folder (a link itself, never its target) and installs fresh. Each folder it wrote goes into `$ARDIA_CLI_HOME/skills.json`. `ardia skills refresh` never adopts: it rewrites every marked folder in that list and every marked user-level folder above, prints - `skipped ` for the rest, refuses a linked subfolder, and keeps only our folders in the list. `install.sh` runs it after - each upgrade, so installed copies follow the CLI. Both also install cua-driver's skill next to ours (see Computer - use); `--no-cua` skips it. + `skipped ` for the rest, refuses a linked subfolder, and keeps our folders in the list plus every user-level one it + recorded, so `install --auto` keeps skipping a copy the user removed, or took over by deleting its marker, after later + updates. `install.sh` runs it after each upgrade, so installed copies follow the CLI. Both also install cua-driver's + skill next to ours (see Computer use); `--no-cua` skips it and records `"companions": []` in the marker. `refresh` and `install --auto` keep + to that: next to an existing copy they put cua-driver's skill back only where ardia's cua-driver copy is still there + and the marker names it (or predates the `companions` field, which also brings back a missing one), and a fresh + folder gets it unless another cua-driver skill is already there. Either way the marker then records the choice, so + `--no-cua` once, or deleting the `cua-driver` folder, keeps it out across updates. A plain `install` without + `--no-cua` brings it back. - `ardia skills status` says, for every recorded and user- or project-level copy, whether it is `current` (its stamp is this CLI's skill and its files still hash to it), `stale` (an older CLI wrote it, or a copy from before the stamp), `edited` (its files no longer match its own stamp) or `foreign` (not ardia's), and ends with the shipped version and diff --git a/plugins/cli/ts/src/skills.ts b/plugins/cli/ts/src/skills.ts index 10c83370..0bc61bee 100644 --- a/plugins/cli/ts/src/skills.ts +++ b/plugins/cli/ts/src/skills.ts @@ -387,7 +387,9 @@ function absolute(path: string): string { return normalized(isAbsolute(path) ? path : join(process.cwd(), path)); } -export async function install(targets: string[], project: boolean, computerUse = true, replace = false): Promise { +export type ComputerUse = boolean | "unless-opted-out"; + +export async function install(targets: string[], project: boolean, computerUse: ComputerUse = true, replace = false): Promise { const written = new Map(); for (const target of new Set(targets)) { const folder = destination(target, project); @@ -400,7 +402,7 @@ export async function install(targets: string[], project: boolean, computerUse = const label = names.join(", "); await stepBoundary(); try { - installInto(folder, computerUse ? undefined : [], true, replace); + installInto(folder, computerUse === false ? [] : undefined, true, replace); } catch (error) { if (!(error instanceof SkillError) && !errnoOf(error)) throw error; out.push(`${label}: error ${osError(error)}`); @@ -409,13 +411,17 @@ export async function install(targets: string[], project: boolean, computerUse = } installed.push(absolute(folder)); out.push(`${label}: ${folder}`); - if (computerUse) { + const companions = computerUse === "unless-opted-out" ? readMarker(folder)?.get("companions") ?? undefined : undefined; + if (computerUse === true || (computerUse === "unless-opted-out" && wantsCompanion(folder, companions))) { await stepBoundary(); const [line, failed] = await companionLine(companionFolder(folder)); out.push(`${label}: ${line}`); await stepBoundary(); if (failed) status = 1; else noteCompanions(folder, [...COMPANIONS]); + } else if (computerUse === "unless-opted-out" && companions === undefined) { + await stepBoundary(); + noteCompanions(folder, [...COMPANIONS]); } } await stepBoundary(); @@ -450,7 +456,7 @@ export async function installDetected(computerUse = true): Promise { ["skills_skipped", detectedTargets().length - targets.length], ]; if (targets.length === 0) return { status: 0, out, counts }; - const done = await install(targets, false, computerUse); + const done = await install(targets, false, computerUse ? "unless-opted-out" : false); return { status: done.status, out: [...out, ...done.out], counts }; } @@ -461,18 +467,26 @@ function mentions(companions: Value, name: string): boolean { throw new TypeError("argument of this type is not iterable"); } +function wantsCompanion(folder: string, companions: Value | undefined): boolean { + const cua = companionFolder(folder); + const ours = !isLink(cua) && markedFiles(cua, CUA_SKILL) !== undefined; + return (companions === undefined && !present(cua)) || (ours && (companions === undefined || mentions(companions, CUA_SKILL))); +} + export async function refresh(): Promise { const userFolders = Object.keys(TARGETS).map((target) => destination(target, false)); let status = 0; - const kept: string[] = []; + const recorded = recordedFolders(); + const userLevel = new Set(userFolders.map(absolute)); + const remembered = recorded.filter((folder) => userLevel.has(folder)); const out: string[] = []; - for (const folder of new Set([...recordedFolders(), ...userFolders])) { + for (const folder of new Set([...recorded, ...userFolders])) { if (!present(folder)) continue; if (ownedFiles(folder) === undefined) { out.push(`skipped ${folder}: not installed by ardia skills install (no ${MARKER} marker)`); continue; } - kept.push(folder); + remembered.push(folder); await stepBoundary(); try { installInto(folder, undefined); @@ -485,8 +499,7 @@ export async function refresh(): Promise { out.push(`refreshed ${folder}`); const companions = readMarker(folder)?.get("companions") ?? undefined; const cua = companionFolder(folder); - const ours = markedFiles(cua, CUA_SKILL) !== undefined && !isLink(cua); - if ((companions === undefined && !present(cua)) || (ours && (companions === undefined || mentions(companions, CUA_SKILL)))) { + if (wantsCompanion(folder, companions)) { await stepBoundary(); const [line, failed] = await companionLine(cua); out.push(line.startsWith("error") ? line : `refreshed ${cua}`); @@ -499,7 +512,7 @@ export async function refresh(): Promise { if (companions === undefined) noteCompanions(folder, [...COMPANIONS]); } await stepBoundary(); - saveRecord(kept); + saveRecord(remembered); return { status, out }; }