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.
- // HK-R02, right after the write (PostToolUse on Write, Edit, MultiEdit). The schema checks of the package
- // `collections` (s01 links, s02 values, s03 required fields) run on this one record. A finding → exit 2: the file is
- // 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`.
- import { only } from '../../collections/checks/lib/schemalib.ts';
- import { Project, type Rule, runRule } from '../../collections/checks/lib/speclib.ts';
- import * as s01 from '../../collections/checks/s01_relations.ts';
- import * as s02 from '../../collections/checks/s02_values.ts';
- import * as s03 from '../../collections/checks/s03_required.ts';
- import { BLOCK, collectionOf, projectPath, projectRoot, readPayload } from '../lib/hooklib.ts';
- const { p } = readPayload();
- if (!p) process.exit(0);
- const root = projectRoot(p);
- const rel = projectPath(root, p.tool_input?.file_path);
- const coll = rel ? collectionOf(root, rel) : null;
- if (!rel || !coll) process.exit(0);
- only([rel]);
- const project = new Project(root);
- const out: string[] = [];
- for (const mod of [s01, s02, s03] as Rule[]) {
- const res = runRule(mod, project);
- if (res.error) out.push(`${mod.RULE.id}: schema error: ${res.error}`);
- for (const h of res.holes) out.push(`${mod.RULE.id}: ${h.missing} → ${h.fix}`);
- }
- if (out.length) {
- 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`);
- process.exit(BLOCK);
- }