UNPKG

paqad-ai

Version:

Spec-driven development framework — AI agents that think before they type

63 lines (55 loc) • 1.81 kB
#!/usr/bin/env node import { join } from 'node:path'; import { applyRuleScriptMap, loadRuleScriptMap, parseScriptHeader, runFixtures, upsertScriptEntry, } from 'paqad-ai/rule-scripts'; import { readFileSync } from 'node:fs'; const [, , projectRoot, scriptRel, ruleId, kind, scope] = process.argv; const help = projectRoot === '--help' || projectRoot === '-h'; if (help || !projectRoot || !scriptRel || !ruleId || !kind || !scope) { process.stdout.write( 'Usage: node scripts/register-script.mjs <project-root> <script-path-rel> <rule-id> <kind> <scope>\n', ); process.exit(help ? 0 : 1); } const scriptAbs = join(projectRoot, scriptRel); const header = parseScriptHeader(readFileSync(scriptAbs, 'utf8')); const fixtures = runFixtures(scriptAbs); const deferred = (fixtures.missing_binaries ?? []).length > 0; if (deferred) { process.stdout.write( `${JSON.stringify({ registered: false, deferred: true, fixtures }, null, 2)}\n`, ); process.exit(2); } if (!header.ok || !fixtures.passed) { process.stdout.write( `${JSON.stringify({ registered: false, header_errors: header.errors, fixtures }, null, 2)}\n`, ); process.exit(1); } const map = loadRuleScriptMap(projectRoot); if (!map) { process.stderr.write('rule-script-map.yml not found; run `analyze rules` first.\n'); process.exit(1); } const now = new Date().toISOString(); const next = upsertScriptEntry(map, ruleId, { path: scriptRel, kind, runtime: 'node', scope, last_validated_at: now, fixtures_passed: true, }); const result = applyRuleScriptMap({ projectRoot, map: next, via: `rule-script-generator:${ruleId}`, event: { action: 'generate', rule_ids: [ruleId], note: scriptRel }, }); process.stdout.write(`${JSON.stringify({ registered: true, fixtures, ...result }, null, 2)}\n`);