ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/tasks/checks/w07_task_chain.ts

checks/w07_task_chain.ts

56 líneas, 2.9 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // W7. A task sits in the chain of work: an agent task → an existing initiative, has "done when", "done" — with
  2. // evidence. An owner task: "done when" (or "what to do"), "done" — with a result. Dropped and postponed tasks
  3. // (category dropped) are not checked: their chain is no longer needed.
  4. import { type Project, type Result, addr } from '../../collections/checks/lib/speclib.ts';
  5. import { main } from '../../collections/checks/lib/runner.ts';
  6. import { cat, fld, has } from './lib/worklib.ts';
  7. export const RULE = {
  8. id: 'w07', title: 'The chain of a task: initiative, done-when, evidence',
  9. scope: 'agent tasks and owner tasks, except dropped and postponed ones',
  10. };
  11. export function check(p: Project, res: Result): void {
  12. const reason = p.need('TASK');
  13. if (reason && !p.records('OWNER').length) {
  14. res.part('scope', reason);
  15. return;
  16. }
  17. const tasks = p.records('TASK').filter((t) => cat(p, t, 'TASK') !== 'dropped');
  18. const owners = p.records('OWNER').filter((t) => cat(p, t, 'OWNER') !== 'dropped');
  19. res.scope = [...tasks, ...owners].map((t) => addr(t.id));
  20. res.scopeText = `agent tasks ${p.coll('TASK') || '—'} (${tasks.length}) and owner tasks ${p.coll('OWNER') || '—'} (${owners.length}), except dropped and postponed ones`;
  21. if (res.part('agent task', reason)) {
  22. const fTi = fld(p, 'TASK', 'INIT');
  23. const inits = p.coll('INIT') ? new Set(Object.keys(p.index('INIT'))) : null;
  24. for (const t of tasks) {
  25. const where = addr(t.id);
  26. const lbl = p.label(t, 'TASK');
  27. if (!has(t, fTi)) {
  28. res.hole(where, `${lbl}: not linked to an initiative`, `fill in ${fTi}`, 'no-initiative');
  29. } else if (inits !== null) {
  30. const bad = p.links(t, fTi, 'INIT').filter((x) => !inits.has(x));
  31. if (bad.length)
  32. res.hole(where, `${lbl}: initiatives ${bad.join(', ')} are not in ${p.coll('INIT')}`, `fix the link in ${fTi}`, 'dangling-initiative');
  33. }
  34. if (!has(t, 'doneWhen'))
  35. res.hole(where, `${lbl}: no doneWhen (when the task is done)`, 'write doneWhen: a checkable condition of readiness', 'no-done-when');
  36. if (cat(p, t, 'TASK') === 'done' && !has(t, 'evidence'))
  37. res.hole(where, `${lbl} is done without evidence`, 'fill in evidence: a PR, a commit, a test, a record', 'no-evidence');
  38. }
  39. }
  40. if (res.part('owner task', p.coll('OWNER') ? null : 'no owner tasks collection')) {
  41. for (const t of owners) {
  42. const where = addr(t.id);
  43. const lbl = t.file.slice(0, -3);
  44. if (!has(t, 'doneWhen') && !has(t, 'action'))
  45. res.hole(where, `${lbl}: neither doneWhen nor action`, 'write doneWhen (when it is done) or choose an action', 'owner-no-done-when');
  46. if (cat(p, t, 'OWNER') === 'done' && !has(t, 'result'))
  47. res.hole(where, `${lbl} is done without a result`, 'fill in result: how it ended', 'owner-no-result');
  48. }
  49. }
  50. }
  51. if (import.meta.main) main({ RULE, check });