ShtukbaseStandard
package file→ .shtukbase/packages/gate/hooks/baseline.ts

hooks/baseline.ts

20 lines, 1.2 KB.

  1. // FIN-R02 (SessionStart). Runs every check of the project and keeps the red findings as this session's baseline:
  2. // what was red before the agent began is not its doing. Tells the agent what is red at the start.
  3. import { findings, projectRoot, readPayload, runChecks } from '../../hooks/lib/hooklib.ts';
  4. import { load, save } from './lib.ts';
  5. const { p } = readPayload();
  6. if (!p) process.exit(0);
  7. const root = projectRoot(p);
  8. const session = String(p.session_id ?? '');
  9. const old = load(root, session);
  10. const red = findings(runChecks(root));
  11. // A resumed or compacted session keeps the baseline it started with.
  12. if (old.baseline === null) save(root, session, { baseline: red, returns: 0 });
  13. const base = old.baseline ?? red;
  14. if (!base.length) console.log('Gate (package gate): the project checks are green at the start. You can finish the work only if they stay so (norm FIN-R01).');
  15. else
  16. console.log(
  17. `Gate (package gate): ${base.length} red findings at the start. They were there before you and are not yours (norm FIN-R02); you can finish the work if no new ones are added:\n` +
  18. base.slice(0, 15).map((l) => `- ${l}`).join('\n') + (base.length > 15 ? `\n- … and ${base.length - 15} more` : ''),
  19. );