- New skill ipal-reference: every ipalKit option (incl. nested keys) with default and how to turn it off/override it, what the plugin injects (collections, globals, endpoints, import-map components), every file the project wires with a minimal example and a check, every env var; resources/api.md indexes all 432 exports with import path and purpose - ipal-setup rewritten as a complete start-to-finish install: steps, code, verification and off/override per stage - ipal-skills writes a marked <!-- ipal-kit:start/end --> pointer block into AGENTS.md (creates it if missing) and CLAUDE.md (or creates CLAUDE.md with @AGENTS.md); only the marked block is ever rewritten; --no-pointer skips. tsconfig exclude check now matches whole entries - AGENT.md, PROGRAMISTA, README, docs index: point at ipal-reference and run `pnpm exec ipal-skills` right after install - docsConsistency: the agent guide must mention every export (runtime and types), every plugin option incl. nested keys, every env var the code reads and every @/lib/content helper Co-Authored-By: Claude Opus 5.5 <[email protected]>
122 lines
6.2 KiB
JavaScript
Executable File
122 lines
6.2 KiB
JavaScript
Executable File
#!/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
|
|
// pnpm ipal-skills --no-pointer → skills only, leave AGENTS.md / CLAUDE.md alone
|
|
// 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).
|
|
// 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 { 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')
|
|
process.exit(0)
|
|
}
|
|
const dryRun = args.includes('--dry-run')
|
|
const pointer = !args.includes('--no-pointer')
|
|
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.
|
|
if (!destValue || destValue.startsWith('-')) {
|
|
console.error('ipal-skills: --dest needs a directory, e.g. --dest .claude/skills')
|
|
process.exit(1)
|
|
}
|
|
const dest = resolve(process.cwd(), destValue)
|
|
if (dest === resolve(process.cwd())) {
|
|
console.error('ipal-skills: --dest must be a subdirectory, not the project root')
|
|
process.exit(1)
|
|
}
|
|
|
|
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}`)
|
|
|
|
// 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).
|
|
if (pointer) {
|
|
const START = '<!-- ipal-kit:start -->'
|
|
const END = '<!-- ipal-kit:end -->'
|
|
const version = JSON.parse(readFileSync(join(pkgRoot, 'package.json'), 'utf8')).version
|
|
const skillsDir = relative(process.cwd(), dest).split('\\').join('/')
|
|
const block = [
|
|
START,
|
|
`## ipal-kit ${version} — przewodnik dla agenta`,
|
|
'',
|
|
'<!-- Blok zarządzany przez `pnpm exec ipal-skills` — zmiany między znacznikami zostaną nadpisane. -->',
|
|
'Ten projekt stoi na `@intecion/ipal-kit` (plugin Payload CMS 3). Zanim napiszesz kod:',
|
|
'',
|
|
'1. Reguły: `node_modules/@intecion/ipal-kit/docs/agent/AGENT.md`.',
|
|
`2. Wszystko, co daje plugin (opcje, env, trasy, layout, hooki, kolekcje, globale, każdy eksport): skill \`ipal-reference\` — \`${skillsDir}/ipal-reference/SKILL.md\`.`,
|
|
`3. Nowy projekt albo brak fundamentu: skill \`ipal-setup\`; cała strona: \`ipal-site\`. Lista skilli: \`${skillsDir}/\`.`,
|
|
'4. Szczegóły modułu: `node_modules/@intecion/ipal-kit/docs/<moduł>.md`.',
|
|
'5. Funkcja istnieje w pluginie → użyj jej. Brakuje opcji → skill `ipal-plugin-gap`, nigdy łatka w `node_modules`.',
|
|
END,
|
|
].join('\n')
|
|
const upsert = (file, { create }) => {
|
|
const path = join(process.cwd(), file)
|
|
const text = existsSync(path) ? readFileSync(path, 'utf8') : null
|
|
let next
|
|
if (text === null) {
|
|
if (!create) return
|
|
next = create === 'import' ? '@AGENTS.md\n' : `# ${file.replace('.md', '')}\n\n${block}\n`
|
|
} else if (text.includes(START) && text.includes(END)) {
|
|
next = text.slice(0, text.indexOf(START)) + block + text.slice(text.indexOf(END) + END.length)
|
|
} else {
|
|
next = `${text.replace(/\s*$/, '')}\n\n${block}\n`
|
|
}
|
|
if (next === text) return console.log(`ok ${file}`)
|
|
console.log(`${text === null ? 'create' : 'update'} ${file}`)
|
|
if (!dryRun) writeFileSync(path, next)
|
|
}
|
|
upsert('AGENTS.md', { create: 'block' })
|
|
const claude = join(process.cwd(), 'CLAUDE.md')
|
|
const importsAgents = existsSync(claude) && /^@AGENTS\.md\s*$/m.test(readFileSync(claude, 'utf8'))
|
|
// CLAUDE.md that imports AGENTS.md already sees the block — don't duplicate it.
|
|
if (!importsAgents) upsert('CLAUDE.md', { create: 'import' })
|
|
}
|
|
|
|
// Skills ship .ts/.tsx templates and scripts. A Next tsconfig ("include": ["**/*.tsx"]) would
|
|
// type-check them as project code and break `tsc` / `next build` → they must be excluded.
|
|
const tsconfig = join(process.cwd(), 'tsconfig.json')
|
|
const top = relative(process.cwd(), dest).split(/[\\/]/)[0]
|
|
if (existsSync(tsconfig) && top && !top.startsWith('..')) {
|
|
const text = readFileSync(tsconfig, 'utf8')
|
|
const exclude = text.match(/"exclude"\s*:\s*\[([^\]]*)\]/)?.[1] ?? ''
|
|
const entries = [...exclude.matchAll(/"([^"]*)"/g)].map((m) => m[1].replace(/^\.\//, '').replace(/\/(\*\*)?$/, ''))
|
|
if (!entries.includes(top)) {
|
|
console.warn(`\n⚠ tsconfig.json does not exclude "${top}" — skill templates would be type-checked and break the build.`)
|
|
console.warn(` Add it: "exclude": ["node_modules", "${top}"]`)
|
|
process.exitCode = 1
|
|
}
|
|
}
|