archivo del paquete→ .shtukbase/packages/gate/hooks/stop.ts
hooks/stop.ts
30 líneas, 1.7 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // FIN-R01 (Stop). Before the agent ends its turn, every check of the project runs. Findings that were not red at the
- // start of the session (baseline.ts) send the agent back: exit 2, the agent reads which ones and goes on working.
- // Findings of the baseline are not the agent's and do not hold it. After MAX_RETURNS returns in one session the gate
- // lets it stop and names what is still red, so a check the agent cannot make green does not loop the session.
- import { BLOCK, findings, projectRoot, readPayload, runChecks } from '../../hooks/lib/hooklib.ts';
- import { MAX_RETURNS, load, save } from './lib.ts';
- const { p } = readPayload();
- if (!p) process.exit(0);
- const root = projectRoot(p);
- const session = String(p.session_id ?? '');
- const st = load(root, session);
- const red = findings(runChecks(root));
- const base = new Set(st.baseline ?? []);
- const fresh = red.filter((l) => !base.has(l));
- if (!fresh.length) {
- if (st.returns) save(root, session, { ...st, returns: 0 });
- process.exit(0);
- }
- const list = fresh.slice(0, 20).map((l) => `- ${l}`).join('\n') + (fresh.length > 20 ? `\n- … and ${fresh.length - 20} more` : '');
- const how = st.baseline === null ? ' (the gate did not see the start of the session, so everything red counts as new)' : '';
- if (st.returns >= MAX_RETURNS) {
- 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`);
- process.exit(0);
- }
- save(root, session, { ...st, returns: st.returns + 1 });
- process.stderr.write(
- `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`,
- );
- process.exit(BLOCK);