archivo del paquete→ .shtukbase/packages/runs/checks/r02_evidence.ts
checks/r02_evidence.ts
44 líneas, 2.2 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // RUN-R02. The end of a run is explained: a done run carries evidence (the `evidence` field, an answer the run gave,
- // or a result written in the body), and every evidence item that is a path leads to something that exists; a failed
- // or cancelled run says why in `message`.
- import { main } from '../../collections/checks/lib/runner.ts';
- import { type Project, type Rec, type Result, addr, filled, findFile, map, pageExists, phase, recordsOf, text } from '../../agents/lib/factlib.ts';
- export const RULE = {
- id: 'RUN-R02', title: 'The end of a run is explained',
- scope: 'finished runs: done, failed, cancelled',
- };
- /** The body without headings and blank lines: what the run wrote as its result or transcript. */
- function bodyText(r: Rec): string {
- return r.body.split('\n').filter((l) => l.trim() && !/^\s{0,3}#/.test(l)).join('\n').trim();
- }
- /** Evidence items that look like paths: start with `/` or `./`, no spaces. */
- function paths(v: unknown): string[] {
- const items = Array.isArray(v) ? v : [v];
- return items.map((x) => text(x)).filter((s) => /^\.?\/\S+$/.test(s));
- }
- export function check(p: Project, res: Result): void {
- const recs = recordsOf(p, 'RUN').filter((r) => ['done', 'failed', 'cancelled'].includes(phase(r.fm.status)));
- res.scope = recs.map((r) => addr(r.id));
- res.scopeText = `finished runs ${p.coll('RUN') || '—'} (${recs.length})`;
- if (!res.part('runs', p.coll('RUN') ? null : 'no runs collection')) return;
- for (const r of recs) {
- const at = addr(r.id);
- const st = phase(r.fm.status);
- if (st === 'done') {
- const said = map(r.fm.answer)?.said;
- if (!filled(r.fm.evidence) && !filled(said) && !bodyText(r))
- res.hole(at, 'the run is done, but there is no evidence', 'write evidence: a commit, a path, a link or an output line', 'no-evidence');
- for (const s of paths(r.fm.evidence))
- if (!pageExists(p, s.replace(/^\.\//, '/')) && !findFile(p, s))
- res.hole(at, `evidence ${s} is not found`, 'fix the path in evidence', 'missing-evidence');
- } else if (!filled(r.fm.message)) {
- res.hole(at, `the run ${st === 'failed' ? 'failed' : 'was cancelled'}, but there is no reason`, 'write message: why', 'no-message');
- }
- }
- }
- if (import.meta.main) main({ RULE, check });