package file→ .shtukbase/packages/tasks/checks/w07_task_chain.ts
checks/w07_task_chain.ts
56 lines, 2.9 KB.
- // W7. A task sits in the chain of work: an agent task → an existing initiative, has "done when", "done" — with
- // evidence. An owner task: "done when" (or "what to do"), "done" — with a result. Dropped and postponed tasks
- // (category dropped) are not checked: their chain is no longer needed.
- import { type Project, type Result, addr } from '../../collections/checks/lib/speclib.ts';
- import { main } from '../../collections/checks/lib/runner.ts';
- import { cat, fld, has } from './lib/worklib.ts';
- export const RULE = {
- id: 'w07', title: 'The chain of a task: initiative, done-when, evidence',
- scope: 'agent tasks and owner tasks, except dropped and postponed ones',
- };
- export function check(p: Project, res: Result): void {
- const reason = p.need('TASK');
- if (reason && !p.records('OWNER').length) {
- res.part('scope', reason);
- return;
- }
- const tasks = p.records('TASK').filter((t) => cat(p, t, 'TASK') !== 'dropped');
- const owners = p.records('OWNER').filter((t) => cat(p, t, 'OWNER') !== 'dropped');
- res.scope = [...tasks, ...owners].map((t) => addr(t.id));
- res.scopeText = `agent tasks ${p.coll('TASK') || '—'} (${tasks.length}) and owner tasks ${p.coll('OWNER') || '—'} (${owners.length}), except dropped and postponed ones`;
- if (res.part('agent task', reason)) {
- const fTi = fld(p, 'TASK', 'INIT');
- const inits = p.coll('INIT') ? new Set(Object.keys(p.index('INIT'))) : null;
- for (const t of tasks) {
- const where = addr(t.id);
- const lbl = p.label(t, 'TASK');
- if (!has(t, fTi)) {
- res.hole(where, `${lbl}: not linked to an initiative`, `fill in ${fTi}`, 'no-initiative');
- } else if (inits !== null) {
- const bad = p.links(t, fTi, 'INIT').filter((x) => !inits.has(x));
- if (bad.length)
- res.hole(where, `${lbl}: initiatives ${bad.join(', ')} are not in ${p.coll('INIT')}`, `fix the link in ${fTi}`, 'dangling-initiative');
- }
- if (!has(t, 'doneWhen'))
- res.hole(where, `${lbl}: no doneWhen (when the task is done)`, 'write doneWhen: a checkable condition of readiness', 'no-done-when');
- if (cat(p, t, 'TASK') === 'done' && !has(t, 'evidence'))
- res.hole(where, `${lbl} is done without evidence`, 'fill in evidence: a PR, a commit, a test, a record', 'no-evidence');
- }
- }
- if (res.part('owner task', p.coll('OWNER') ? null : 'no owner tasks collection')) {
- for (const t of owners) {
- const where = addr(t.id);
- const lbl = t.file.slice(0, -3);
- if (!has(t, 'doneWhen') && !has(t, 'action'))
- res.hole(where, `${lbl}: neither doneWhen nor action`, 'write doneWhen (when it is done) or choose an action', 'owner-no-done-when');
- if (cat(p, t, 'OWNER') === 'done' && !has(t, 'result'))
- res.hole(where, `${lbl} is done without a result`, 'fill in result: how it ended', 'owner-no-result');
- }
- }
- }
- if (import.meta.main) main({ RULE, check });