ipal-skills --external: vendored third-party agent skills, pinned
- docs/agent/external: Vercel react-best-practices and composition-patterns (MIT), Addy Osmani accessibility (MIT), Anthropic frontend-design (Apache-2.0), official Payload skill at v3.92.1 (MIT) — text only, each with its licence, SOURCE.md (repo, commit) and an override note in front of the SKILL.md (ipal-kit first, Payload fetching over swr, DESIGN.md tokens, Payload 3 not 4); manifest.json with sha256 per file - scripts/vendor-external-skills.mjs (maintainer, not shipped): fetches by full commit SHA only, rejects non-text or executable files, regenerates the manifest; --check verifies it - ipal-skills --external [names]: copies ext-* after checking every file against the manifest, downloads nothing, never touches ext-* folders without ipal-kit's SOURCE.md, removes only retired ones it installed; an unknown name stops the run before anything is copied - AGENT.md §14, ipal-setup stage 2 (optional step), README: usage, overrides, how to update the pins - test/externalSkills.test.ts: pins are SHAs, no branch fetch, checksums, text only, licences, override note, installer leaves other folders alone Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
25719ae7ec
commit
e1f82ce387
+54
-1
@@ -4,22 +4,30 @@
|
||||
// pnpm ipal-skills --dry-run → show what would change
|
||||
// pnpm ipal-skills --dest .claude/skills
|
||||
// pnpm ipal-skills --no-pointer → skills only, leave AGENTS.md / CLAUDE.md alone
|
||||
// pnpm ipal-skills --external → also the vendored third-party skills (ext-*, pinned, text only)
|
||||
// pnpm ipal-skills --external ext-accessibility,ext-payload → only those
|
||||
// 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).
|
||||
// ext-* folders are touched only with --external, and only those carrying ipal-kit's SOURCE.md.
|
||||
// AGENTS.md (and CLAUDE.md) get a marked ipal-kit block pointing at the guide — only the
|
||||
// text between the markers is ever rewritten; the project's own content stays as it is.
|
||||
|
||||
import { createHash } from 'node:crypto'
|
||||
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
||||
import { dirname, join, relative, 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 <dir>] [--dry-run] [--no-pointer]\nDefault dest: .agents/skills')
|
||||
console.log('Usage: ipal-skills [--dest <dir>] [--dry-run] [--no-pointer] [--external [ext-a,ext-b]]\nDefault dest: .agents/skills')
|
||||
process.exit(0)
|
||||
}
|
||||
const dryRun = args.includes('--dry-run')
|
||||
const pointer = !args.includes('--no-pointer')
|
||||
const externalArg = args.indexOf('--external')
|
||||
const externalPick = externalArg >= 0 && args[externalArg + 1] && !args[externalArg + 1].startsWith('-')
|
||||
? args[externalArg + 1].split(',').map((n) => n.trim()).filter(Boolean)
|
||||
: null
|
||||
const destArg = args.indexOf('--dest')
|
||||
const destValue = destArg >= 0 ? args[destArg + 1] : '.agents/skills'
|
||||
// A missing value would resolve to cwd and remove every ipal-* folder there.
|
||||
@@ -40,6 +48,16 @@ if (!existsSync(src)) {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Validate --external before anything is copied.
|
||||
const extSrc = join(pkgRoot, 'docs', 'agent', 'external')
|
||||
const manifest = externalArg >= 0 ? JSON.parse(readFileSync(join(extSrc, 'manifest.json'), 'utf8')) : { skills: [] }
|
||||
const known = manifest.skills.map((skill) => skill.name)
|
||||
const unknown = (externalPick ?? []).filter((name) => !known.includes(name))
|
||||
if (unknown.length) {
|
||||
console.error(`ipal-skills: unknown external skill(s): ${unknown.join(', ')} — available: ${known.join(', ')}`)
|
||||
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)) : []
|
||||
@@ -60,6 +78,41 @@ for (const name of retired) {
|
||||
}
|
||||
console.log(`${dryRun ? '[dry-run] ' : ''}${shipped.length} skill(s) → ${dest}`)
|
||||
|
||||
// Third-party skills, vendored into the package at pinned commits (docs/agent/external,
|
||||
// scripts/vendor-external-skills.mjs). Nothing is downloaded here: every file is checked
|
||||
// against manifest.json before it is copied.
|
||||
if (externalArg >= 0) {
|
||||
const MARK = 'Vendored by @intecion/ipal-kit'
|
||||
const ours = (name) => existsSync(join(dest, name, 'SOURCE.md')) && readFileSync(join(dest, name, 'SOURCE.md'), 'utf8').includes(MARK)
|
||||
const filesOf = (dir) => readdirSync(dir).flatMap((n) => (statSync(join(dir, n)).isDirectory() ? filesOf(join(dir, n)).map((f) => `${n}/${f}`) : [n]))
|
||||
for (const skill of manifest.skills.filter((s) => !externalPick || externalPick.includes(s.name))) {
|
||||
const from = join(extSrc, skill.name)
|
||||
const files = filesOf(from).sort()
|
||||
const tampered = files.filter((f) => skill.files[f] !== createHash('sha256').update(readFileSync(join(from, f))).digest('hex'))
|
||||
if (tampered.length || files.length !== Object.keys(skill.files).length) {
|
||||
console.error(`ipal-skills: ${skill.name} does not match manifest.json (${tampered.join(', ') || 'file list'}) — skipped`)
|
||||
process.exitCode = 1
|
||||
continue
|
||||
}
|
||||
if (existsSync(join(dest, skill.name)) && !ours(skill.name)) {
|
||||
console.warn(`skip ${skill.name} (a folder of that name exists and is not from ipal-kit)`)
|
||||
continue
|
||||
}
|
||||
console.log(`${existsSync(join(dest, skill.name)) ? 'update' : 'add '} ${skill.name} (${skill.publisher}, ${skill.license}, ${skill.commit.slice(0, 12)})`)
|
||||
if (!dryRun) {
|
||||
rmSync(join(dest, skill.name), { recursive: true, force: true })
|
||||
cpSync(from, join(dest, skill.name), { recursive: true })
|
||||
}
|
||||
}
|
||||
const retiredExt = existsSync(dest)
|
||||
? readdirSync(dest).filter((n) => n.startsWith('ext-') && !known.includes(n) && ours(n))
|
||||
: []
|
||||
for (const name of retiredExt) {
|
||||
console.log(`remove ${name} (no longer in ipal-kit)`)
|
||||
if (!dryRun) rmSync(join(dest, name), { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
// Pointer block: an agent opening the project must find the guide without being told.
|
||||
// AGENTS.md is read by Codex/Cursor/Antigravity, CLAUDE.md by Claude Code (which also
|
||||
// follows `@AGENTS.md` imports, so a CLAUDE.md that imports AGENTS.md needs no copy).
|
||||
|
||||
Reference in New Issue
Block a user