ShtukbaseStandard
package file→ .shtukbase/packages/tasks/checks/w16_task_value.ts

checks/w16_task_value.ts

84 lines, 4.6 KB.

  1. // W16. Every agent task has value for the product. A task passes if one of three holds:
  2. //
  3. // a) `implements` leads to a requirement or capability of the product (the page exists, the requirement is not
  4. // rejected or replaced);
  5. // b) there is no specification yet: `value` is one phrase "what changes for the user", and `implements` leads
  6. // to a draft requirement (`status: proposal`) made next to it; the owner confirms the draft later;
  7. // c) a technical task with no product meaning: `kind: chore` and `enables` — the task with value it serves.
  8. //
  9. // "Move a file" alone is not a task. Dropped and postponed tasks (category dropped) are not checked.
  10. // A copy of tools/checks/spec-checks/w16_task_value.py of the standard with one change of the package "Tasks": if the
  11. // project has no layer "Product" (no collection of requirements and none of capabilities), path b) is simpler —
  12. // `value` is enough, there is nowhere to make a draft requirement.
  13. import { type Project, type Rec, type Result, addr, pystr, truthy } from '../../collections/checks/lib/speclib.ts';
  14. import { main } from '../../collections/checks/lib/runner.ts';
  15. import { cat, fld, has, status } from './lib/worklib.ts';
  16. export const RULE = {
  17. id: 'w16', title: 'The value of a task: a requirement, a draft with value, or a chore with enables',
  18. scope: 'agent tasks, except dropped and postponed ones',
  19. };
  20. const DEAD = ['rejected', 'replaced'];
  21. const HOW =
  22. 'a) implements: a requirement or capability of the product; ' +
  23. 'b) value: "what changes for the user" + implements: a draft requirement with status: proposal; ' +
  24. 'c) kind: chore + enables: the task with value that this one serves';
  25. function vals(rec: Rec, field: string): string[] {
  26. const v = rec.fm[field];
  27. return (Array.isArray(v) ? v : [v]).filter((x) => x !== null && x !== undefined && pystr(x).trim()).map((x) => pystr(x).trim());
  28. }
  29. export function check(p: Project, res: Result): void {
  30. const reason = p.need('TASK');
  31. if (reason) {
  32. res.part('scope', reason);
  33. return;
  34. }
  35. const tasks = p.records('TASK').filter((t) => cat(p, t, 'TASK') !== 'dropped');
  36. res.scope = tasks.map((t) => addr(t.id));
  37. res.scopeText = `agent tasks ${p.coll('TASK')} (${tasks.length}), except dropped and postponed ones`;
  38. if (!res.part('agent task', null)) return;
  39. const fImpl = fld(p, 'TASK', 'REQ');
  40. const product: Record<string, Rec> = {};
  41. for (const key of ['REQ', 'CAP']) if (p.coll(key)) Object.assign(product, p.index(key));
  42. const taskIds = new Set(Object.keys(p.index('TASK')));
  43. const noProduct = !p.coll('REQ') && !p.coll('CAP');
  44. for (const t of tasks) {
  45. const where = addr(t.id);
  46. const lbl = p.label(t, 'TASK');
  47. const kind = pystr(truthy(t.fm.kind) ? t.fm.kind : '').trim();
  48. if (kind === 'chore') {
  49. const targets = p.links(t, 'enables', 'TASK');
  50. if (!targets.length)
  51. res.hole(where, `${lbl}: kind: chore without enables — it is not visible which task with value it serves`,
  52. 'c) write enables: a task with value for the product; or remove kind: chore and choose a) or b)', 'chore-no-enables');
  53. for (const x of targets)
  54. if (!taskIds.has(x))
  55. res.hole(where, `${lbl}: enables points to ${x}, there is no such task`, 'fix the link in enables', 'dangling-enables');
  56. continue;
  57. }
  58. const links = fImpl ? p.links(t, fImpl, 'REQ') : [];
  59. if (!links.length) {
  60. if (has(t, 'value') && noProduct) continue;
  61. if (has(t, 'value'))
  62. res.hole(where, `${lbl}: there is value, but no implements — the draft requirement is not created`,
  63. 'b) create a requirement with status: proposal (the wording from value) and refer to it in implements', 'value-no-draft');
  64. else if (vals(t, 'enables').length)
  65. res.hole(where, `${lbl}: there is enables, but no kind: chore`, 'c) write kind: chore; or choose a) or b)', 'enables-no-chore');
  66. else
  67. res.hole(where, `${lbl}: no value for the product is visible — no implements, value, or kind: chore + enables`, HOW, 'no-product-value');
  68. continue;
  69. }
  70. for (const x of links) {
  71. const rec = product[x];
  72. if (rec === undefined)
  73. res.hole(where, `${lbl}: implements points to ${x}, there is no such requirement or capability page`,
  74. 'fix the link in implements; if there is no specification — b) create a draft with status: proposal and value', 'dangling-implements');
  75. else if (DEAD.includes(status(rec)))
  76. res.hole(where, `${lbl}: implements points to ${x} with status: ${status(rec)}`, 'refer to a live requirement or drop the task', 'dead-implements');
  77. }
  78. }
  79. }
  80. if (import.meta.main) main({ RULE, check });