package file→ .shtukbase/packages/content/checks/c01_approval.ts
checks/c01_approval.ts
28 lines, 1.8 KB.
- // CNT-R01. Approved and published drafts (and approved ideas) were approved by a person: approvedBy is filled and is
- // not an agent (an /agents/ path, an agent page name or title, a harness or model name); a draft has approvedOn, and
- // publishedOn is not before it.
- import { FOLDERS, agentNames, phase, records, report, text } from '../lib/content.ts';
- const out: string[] = [];
- const agents = agentNames();
- const isAgent = (who: string) => {
- const w = who.toLowerCase().replace(/\.md$/, '');
- return w.startsWith('/agents/') || w.startsWith('agents/') || agents.has(w) || [...agents].some((a) => a.length > 3 && w.includes(a) && a.startsWith('/agents/'));
- };
- const scope: string[] = [];
- for (const [folder, states] of [[FOLDERS.drafts, ['approved', 'published']], [FOLDERS.ideas, ['approved', 'drafted']]] as const) {
- for (const r of records(folder)) {
- const st = phase(r.fm.status);
- if (!(states as readonly string[]).includes(st)) continue;
- scope.push(r.id);
- const who = text(r.fm.approvedBy);
- if (!who) out.push(`${r.id}: state ${st}, but approvedBy is empty → a person approves and writes their name [no-approver]`);
- else if (isAgent(who)) out.push(`${r.id}: approved by "${who}", which is an agent, and only a person approves → return status: ${folder === FOLDERS.drafts ? 'review' : 'new'} and clear approvedBy [agent-approver]`);
- if (folder !== FOLDERS.drafts) continue;
- const on = text(r.fm.approvedOn);
- if (!on) out.push(`${r.id}: no approval day approvedOn → write YYYY-MM-DD [no-date]`);
- const pub = text(r.fm.publishedOn);
- if (st === 'published' && on && pub && pub < on) out.push(`${r.id}: published ${pub}, before the approval ${on} → fix the dates [published-before-approved]`);
- }
- }
- report(out, `approved drafts and ideas (${scope.length})`);