|
| 1 | +import { spawnSync } from "node:child_process"; |
| 2 | + |
| 3 | +const SKILLS_SOURCE = "chtnnh/know-code"; |
| 4 | + |
| 5 | +/** |
| 6 | + * Install know-code + know-code-teach via the agentskills `skills` CLI. |
| 7 | + * --global puts skills in user harness dirs (e.g. ~/.cursor/skills) so they |
| 8 | + * apply across all repositories. |
| 9 | + */ |
| 10 | +export function cmdSkills(opts: { |
| 11 | + global?: boolean; |
| 12 | + agents?: string; |
| 13 | + yes?: boolean; |
| 14 | +}): void { |
| 15 | + const args = ["skills", "add", SKILLS_SOURCE]; |
| 16 | + if (opts.global) args.push("--global"); |
| 17 | + if (opts.yes) args.push("--yes"); |
| 18 | + if (opts.agents) { |
| 19 | + for (const a of opts.agents.split(",").map((s) => s.trim()).filter(Boolean)) { |
| 20 | + args.push("--agent", a); |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + console.log(`know-code: running npx ${args.join(" ")}`); |
| 25 | + if (opts.global) { |
| 26 | + console.log( |
| 27 | + "know-code: global install → user skill dirs (available in every repo for selected harnesses)", |
| 28 | + ); |
| 29 | + } else { |
| 30 | + console.log("know-code: project install → .agents/skills (or agent-specific project dirs)"); |
| 31 | + } |
| 32 | + |
| 33 | + const result = spawnSync("npx", ["--yes", ...args], { |
| 34 | + stdio: "inherit", |
| 35 | + shell: process.platform === "win32", |
| 36 | + }); |
| 37 | + |
| 38 | + if (result.error) { |
| 39 | + throw new Error( |
| 40 | + `Failed to run npx skills: ${result.error.message}\n` + |
| 41 | + `Install Node/npm, then: npx skills add ${SKILLS_SOURCE}${opts.global ? " --global" : ""}`, |
| 42 | + ); |
| 43 | + } |
| 44 | + if (result.status !== 0) { |
| 45 | + process.exit(result.status ?? 1); |
| 46 | + } |
| 47 | + |
| 48 | + console.log(""); |
| 49 | + console.log("know-code: skills installed."); |
| 50 | + if (opts.global) { |
| 51 | + console.log(" Tip: restart or reload the agent window if skills don’t appear yet."); |
| 52 | + console.log(" List: npx skills ls -g"); |
| 53 | + } |
| 54 | +} |
0 commit comments