包文件→ .shtukbase/packages/tasks/checks/w08_init_closure.ts
checks/w08_init_closure.ts
50 行, 2.4 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // W8. Closing an initiative: "done" — all its tasks (by the field initiative in /work/tasks) are in done or dropped
- // (postponed count as dropped, as in w02). The reverse is a hint, not a hole: all tasks are done and the initiative is
- // not "done" yet → the hint "can be closed".
- import { type Project, type Rec, type Result, addr } from '../../collections/checks/lib/speclib.ts';
- import { main } from '../../collections/checks/lib/runner.ts';
- import { cat, fld, status } from './lib/worklib.ts';
- export const RULE = {
- id: 'w08', title: 'Closing an initiative: its tasks are closed',
- scope: 'initiatives with the status "done" and initiatives whose tasks are all closed',
- };
- const CLOSED = ['done', 'dropped'];
- export function check(p: Project, res: Result): void {
- const reason = p.need('INIT', 'TASK');
- if (reason) {
- res.part('scope', reason);
- return;
- }
- const fTi = fld(p, 'TASK', 'INIT');
- const byInit = new Map<string, Rec[]>();
- for (const t of p.records('TASK'))
- for (const i of p.links(t, fTi, 'INIT')) {
- if (!byInit.has(i)) byInit.set(i, []);
- byInit.get(i)!.push(t);
- }
- const inits = p.records('INIT').filter((r) => cat(p, r, 'INIT') !== 'dropped');
- res.scope = inits.filter((r) => cat(p, r, 'INIT') === 'done' || (byInit.get(r.id) ?? []).length).map((r) => addr(r.id));
- res.scopeText = `initiatives ${p.coll('INIT')}: "done" — tasks are closed; all tasks closed — can be closed (a hint)`;
- const hints: string[] = [];
- if (res.part('done → tasks closed', null)) {
- for (const r of inits) {
- const ts = byInit.get(r.id) ?? [];
- const openT = ts.filter((t) => !CLOSED.includes(cat(p, t, 'TASK') ?? '\0')).map((t) => p.label(t, 'TASK'));
- if (cat(p, r, 'INIT') === 'done') {
- if (openT.length)
- res.hole(addr(r.id), `${p.label(r, 'INIT')} is done, but tasks are open: ${openT.join(', ')}`,
- 'close the tasks with evidence or return the initiative to under-way', 'done-open-tasks');
- } else if (ts.length && !openT.length && ts.some((t) => cat(p, t, 'TASK') === 'done')) {
- hints.push(`${p.label(r, 'INIT')} (${status(r)})`);
- }
- }
- }
- if (hints.length)
- (res.info.lines ??= []).push(`all tasks are closed, but the initiative is not — it can be closed (${hints.length}): ${hints.join(', ')}`);
- res.info.canClose = hints;
- }
- if (import.meta.main) main({ RULE, check });