ShtukbaseStandard
файл пакета→ .shtukbase/packages/gate/hooks/stop.ts

hooks/stop.ts

30 строк, 1.7 КБ.

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. // FIN-R01 (Stop). Before the agent ends its turn, every check of the project runs. Findings that were not red at the
  2. // start of the session (baseline.ts) send the agent back: exit 2, the agent reads which ones and goes on working.
  3. // Findings of the baseline are not the agent's and do not hold it. After MAX_RETURNS returns in one session the gate
  4. // lets it stop and names what is still red, so a check the agent cannot make green does not loop the session.
  5. import { BLOCK, findings, projectRoot, readPayload, runChecks } from '../../hooks/lib/hooklib.ts';
  6. import { MAX_RETURNS, load, save } from './lib.ts';
  7. const { p } = readPayload();
  8. if (!p) process.exit(0);
  9. const root = projectRoot(p);
  10. const session = String(p.session_id ?? '');
  11. const st = load(root, session);
  12. const red = findings(runChecks(root));
  13. const base = new Set(st.baseline ?? []);
  14. const fresh = red.filter((l) => !base.has(l));
  15. if (!fresh.length) {
  16. if (st.returns) save(root, session, { ...st, returns: 0 });
  17. process.exit(0);
  18. }
  19. const list = fresh.slice(0, 20).map((l) => `- ${l}`).join('\n') + (fresh.length > 20 ? `\n- … and ${fresh.length - 20} more` : '');
  20. const how = st.baseline === null ? ' (the gate did not see the start of the session, so everything red counts as new)' : '';
  21. if (st.returns >= MAX_RETURNS) {
  22. process.stderr.write(`Gate: new red findings remained after ${MAX_RETURNS} returns — letting go. Name them in the report as not closed:\n${list}\n`);
  23. process.exit(0);
  24. }
  25. save(root, session, { ...st, returns: st.returns + 1 });
  26. process.stderr.write(
  27. `Not ready (norm FIN-R01): after your edits new red checks appeared${how}. Fix them, then finish. Return ${st.returns + 1} of ${MAX_RETURNS}.\n${list}\n`,
  28. );
  29. process.exit(BLOCK);