ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/hooks/hooks/record-post.ts

hooks/record-post.ts

29 líneas, 1.5 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // HK-R02, right after the write (PostToolUse on Write, Edit, MultiEdit). The schema checks of the package
  2. // `collections` (s01 links, s02 values, s03 required fields) run on this one record. A finding → exit 2: the file is
  3. // on disk, and the agent is told at once what breaks and how to fix it — it is not left for a later `shtuk check`.
  4. import { only } from '../../collections/checks/lib/schemalib.ts';
  5. import { Project, type Rule, runRule } from '../../collections/checks/lib/speclib.ts';
  6. import * as s01 from '../../collections/checks/s01_relations.ts';
  7. import * as s02 from '../../collections/checks/s02_values.ts';
  8. import * as s03 from '../../collections/checks/s03_required.ts';
  9. import { BLOCK, collectionOf, projectPath, projectRoot, readPayload } from '../lib/hooklib.ts';
  10. const { p } = readPayload();
  11. if (!p) process.exit(0);
  12. const root = projectRoot(p);
  13. const rel = projectPath(root, p.tool_input?.file_path);
  14. const coll = rel ? collectionOf(root, rel) : null;
  15. if (!rel || !coll) process.exit(0);
  16. only([rel]);
  17. const project = new Project(root);
  18. const out: string[] = [];
  19. for (const mod of [s01, s02, s03] as Rule[]) {
  20. const res = runRule(mod, project);
  21. if (res.error) out.push(`${mod.RULE.id}: schema error: ${res.error}`);
  22. for (const h of res.holes) out.push(`${mod.RULE.id}: ${h.missing} → ${h.fix}`);
  23. }
  24. if (out.length) {
  25. process.stderr.write(`The record ${rel} was written, but it breaks the schema checks (norm HK-R02) — fix it now:\n${out.join('\n')}\n`);
  26. process.exit(BLOCK);
  27. }