#!/usr/bin/env node // ipal-skills — copies the ipal-kit agent skills into the project. // pnpm ipal-skills → ./.agents/skills/ipal-* // pnpm ipal-skills --dry-run → show what would change // pnpm ipal-skills --dest .claude/skills // Only folders named ipal-* are touched; the project's own skills stay as they are. // ipal-* folders that no longer exist in the package are removed (renamed/retired skills). import { cpSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from 'node:fs' import { dirname, join, resolve } from 'node:path' import { fileURLToPath } from 'node:url' const args = process.argv.slice(2) if (args.includes('--help') || args.includes('-h')) { console.log('Usage: ipal-skills [--dest ] [--dry-run]\nDefault dest: .agents/skills') process.exit(0) } const dryRun = args.includes('--dry-run') const destArg = args.indexOf('--dest') const dest = resolve(process.cwd(), destArg >= 0 ? args[destArg + 1] ?? '' : '.agents/skills') const pkgRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..') const src = join(pkgRoot, 'docs', 'agent', 'skills') if (!existsSync(src)) { console.error(`ipal-skills: no skills found in ${src} — is @intecion/ipal-kit installed with docs?`) process.exit(1) } const isSkillDir = (base, name) => name.startsWith('ipal-') && statSync(join(base, name)).isDirectory() const shipped = readdirSync(src).filter((n) => isSkillDir(src, n)) const existing = existsSync(dest) ? readdirSync(dest).filter((n) => isSkillDir(dest, n)) : [] const retired = existing.filter((n) => !shipped.includes(n)) if (!dryRun) mkdirSync(dest, { recursive: true }) for (const name of shipped) { const action = existing.includes(name) ? 'update' : 'add ' console.log(`${action} ${name}`) if (!dryRun) { rmSync(join(dest, name), { recursive: true, force: true }) // drop files removed upstream cpSync(join(src, name), join(dest, name), { recursive: true }) } } for (const name of retired) { console.log(`remove ${name} (no longer in ipal-kit)`) if (!dryRun) rmSync(join(dest, name), { recursive: true, force: true }) } console.log(`${dryRun ? '[dry-run] ' : ''}${shipped.length} skill(s) → ${dest}`)