包文件→ .shtukbase/packages/tasks/checks/w16_task_value.ts
checks/w16_task_value.ts
84 行, 4.6 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // W16. Every agent task has value for the product. A task passes if one of three holds:
- //
- // a) `implements` leads to a requirement or capability of the product (the page exists, the requirement is not
- // rejected or replaced);
- // b) there is no specification yet: `value` is one phrase "what changes for the user", and `implements` leads
- // to a draft requirement (`status: proposal`) made next to it; the owner confirms the draft later;
- // c) a technical task with no product meaning: `kind: chore` and `enables` — the task with value it serves.
- //
- // "Move a file" alone is not a task. Dropped and postponed tasks (category dropped) are not checked.
- // A copy of tools/checks/spec-checks/w16_task_value.py of the standard with one change of the package "Tasks": if the
- // project has no layer "Product" (no collection of requirements and none of capabilities), path b) is simpler —
- // `value` is enough, there is nowhere to make a draft requirement.
- import { type Project, type Rec, type Result, addr, pystr, truthy } from '../../collections/checks/lib/speclib.ts';
- import { main } from '../../collections/checks/lib/runner.ts';
- import { cat, fld, has, status } from './lib/worklib.ts';
- export const RULE = {
- id: 'w16', title: 'The value of a task: a requirement, a draft with value, or a chore with enables',
- scope: 'agent tasks, except dropped and postponed ones',
- };
- const DEAD = ['rejected', 'replaced'];
- const HOW =
- 'a) implements: a requirement or capability of the product; ' +
- 'b) value: "what changes for the user" + implements: a draft requirement with status: proposal; ' +
- 'c) kind: chore + enables: the task with value that this one serves';
- function vals(rec: Rec, field: string): string[] {
- const v = rec.fm[field];
- return (Array.isArray(v) ? v : [v]).filter((x) => x !== null && x !== undefined && pystr(x).trim()).map((x) => pystr(x).trim());
- }
- export function check(p: Project, res: Result): void {
- const reason = p.need('TASK');
- if (reason) {
- res.part('scope', reason);
- return;
- }
- const tasks = p.records('TASK').filter((t) => cat(p, t, 'TASK') !== 'dropped');
- res.scope = tasks.map((t) => addr(t.id));
- res.scopeText = `agent tasks ${p.coll('TASK')} (${tasks.length}), except dropped and postponed ones`;
- if (!res.part('agent task', null)) return;
- const fImpl = fld(p, 'TASK', 'REQ');
- const product: Record<string, Rec> = {};
- for (const key of ['REQ', 'CAP']) if (p.coll(key)) Object.assign(product, p.index(key));
- const taskIds = new Set(Object.keys(p.index('TASK')));
- const noProduct = !p.coll('REQ') && !p.coll('CAP');
- for (const t of tasks) {
- const where = addr(t.id);
- const lbl = p.label(t, 'TASK');
- const kind = pystr(truthy(t.fm.kind) ? t.fm.kind : '').trim();
- if (kind === 'chore') {
- const targets = p.links(t, 'enables', 'TASK');
- if (!targets.length)
- res.hole(where, `${lbl}: kind: chore without enables — it is not visible which task with value it serves`,
- 'c) write enables: a task with value for the product; or remove kind: chore and choose a) or b)', 'chore-no-enables');
- for (const x of targets)
- if (!taskIds.has(x))
- res.hole(where, `${lbl}: enables points to ${x}, there is no such task`, 'fix the link in enables', 'dangling-enables');
- continue;
- }
- const links = fImpl ? p.links(t, fImpl, 'REQ') : [];
- if (!links.length) {
- if (has(t, 'value') && noProduct) continue;
- if (has(t, 'value'))
- res.hole(where, `${lbl}: there is value, but no implements — the draft requirement is not created`,
- 'b) create a requirement with status: proposal (the wording from value) and refer to it in implements', 'value-no-draft');
- else if (vals(t, 'enables').length)
- res.hole(where, `${lbl}: there is enables, but no kind: chore`, 'c) write kind: chore; or choose a) or b)', 'enables-no-chore');
- else
- res.hole(where, `${lbl}: no value for the product is visible — no implements, value, or kind: chore + enables`, HOW, 'no-product-value');
- continue;
- }
- for (const x of links) {
- const rec = product[x];
- if (rec === undefined)
- res.hole(where, `${lbl}: implements points to ${x}, there is no such requirement or capability page`,
- 'fix the link in implements; if there is no specification — b) create a draft with status: proposal and value', 'dangling-implements');
- else if (DEAD.includes(status(rec)))
- res.hole(where, `${lbl}: implements points to ${x} with status: ${status(rec)}`, 'refer to a live requirement or drop the task', 'dead-implements');
- }
- }
- }
- if (import.meta.main) main({ RULE, check });