fwdloop 0.38.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +6 -9
  2. package/bin/fwdloop +21 -19
  3. package/package.json +1 -1
  4. package/src/ask.js +70 -148
  5. package/src/audit-fold.js +6 -5
  6. package/src/auditchecks.js +6 -4
  7. package/src/authoring.js +32 -60
  8. package/src/blockasks.js +2 -1
  9. package/src/blockassemble.js +15 -3
  10. package/src/blockdraft.js +2 -2
  11. package/src/blockpick.js +42 -16
  12. package/src/books.js +237 -12
  13. package/src/checkblock.js +24 -44
  14. package/src/checklistsign.js +25 -3
  15. package/src/checklook.js +3 -1
  16. package/src/checkpick.js +6 -77
  17. package/src/cited-source.js +4 -4
  18. package/src/citedcheck.js +6 -11
  19. package/src/citedwords.js +9 -8
  20. package/src/closers.js +9 -6
  21. package/src/declaration.js +14 -49
  22. package/src/diary.js +23 -1
  23. package/src/draft-steps.js +11 -1
  24. package/src/drafter.js +18 -12
  25. package/src/draftfiles.js +127 -0
  26. package/src/draftspend.js +165 -17
  27. package/src/flow.js +42 -87
  28. package/src/flowmodel.js +1 -1
  29. package/src/index.js +3 -2
  30. package/src/inside.js +106 -0
  31. package/src/jsonl-append.js +33 -1
  32. package/src/learn.js +1 -1
  33. package/src/learnstore.js +20 -22
  34. package/src/line-checks.js +1 -1
  35. package/src/liveness.js +3 -0
  36. package/src/mcp-use.js +8 -9
  37. package/src/memo.js +13 -16
  38. package/src/model-step.js +2 -2
  39. package/src/page-words.js +8 -0
  40. package/src/pageask.js +8 -3
  41. package/src/pagebits.js +8 -1
  42. package/src/pagedropwords.js +1 -1
  43. package/src/pagerules.js +6 -3
  44. package/src/panel/author.js +99 -75
  45. package/src/panel/authorcard.js +21 -8
  46. package/src/panel/authorflows.js +3 -3
  47. package/src/panel/authorresume.js +3 -3
  48. package/src/panel/authorstart.js +15 -16
  49. package/src/panel/authortrigger.js +43 -70
  50. package/src/panel/data.js +186 -188
  51. package/src/panel/index.html +139 -115
  52. package/src/panel/jobgrid.js +3 -7
  53. package/src/panel/result.js +7 -10
  54. package/src/panel/resume.js +4 -3
  55. package/src/panel/scheduler.js +9 -9
  56. package/src/panel/server.js +8 -4
  57. package/src/panel/spawn.js +22 -11
  58. package/src/panel/tickets.js +2 -2
  59. package/src/pickrecord.js +51 -31
  60. package/src/placerule.js +3 -4
  61. package/src/plain-checks.js +1 -1
  62. package/src/planrebuild.js +19 -19
  63. package/src/primitives.js +1 -1
  64. package/src/provider.js +1 -1
  65. package/src/reasons.js +25 -0
  66. package/src/runfile.js +26 -2
  67. package/src/runner.js +57 -105
  68. package/src/runvalues.js +47 -24
  69. package/src/schedule-choices.js +41 -0
  70. package/src/schedule-shape.js +39 -0
  71. package/src/schedule.js +9 -8
  72. package/src/setup.js +20 -36
  73. package/src/shaperows.js +2 -2
  74. package/src/sheetblock.js +2 -2
  75. package/src/sheetbuild.js +5 -5
  76. package/src/sheetrun.js +4 -5
  77. package/src/summary-words.js +2 -1
  78. package/src/thinking.js +5 -2
  79. package/src/ticketrows.js +7 -28
  80. package/src/trigger-clock.js +9 -23
  81. package/src/trigger-files.js +30 -22
  82. package/src/trigger-tickets.js +15 -14
  83. package/src/try-checks.js +2 -1
  84. package/src/types.js +2 -0
  85. package/types/ask.d.ts +25 -20
  86. package/types/authoring.d.ts +7 -42
  87. package/types/blockpick.d.ts +1 -1
  88. package/types/books.d.ts +380 -4
  89. package/types/checkblock.d.ts +1 -23
  90. package/types/checklist.d.ts +3 -3
  91. package/types/checklistsign.d.ts +7 -0
  92. package/types/checkpick.d.ts +0 -21
  93. package/types/citedwords.d.ts +7 -4
  94. package/types/closers.d.ts +1 -0
  95. package/types/declaration.d.ts +4 -14
  96. package/types/diary.d.ts +14 -1
  97. package/types/draft-steps.d.ts +7 -0
  98. package/types/drafter.d.ts +1 -1
  99. package/types/draftfiles.d.ts +89 -0
  100. package/types/draftspend.d.ts +74 -0
  101. package/types/flow.d.ts +32 -54
  102. package/types/index.d.ts +3 -3
  103. package/types/inside.d.ts +71 -0
  104. package/types/jsonl-append.d.ts +20 -0
  105. package/types/learnstore.d.ts +0 -2
  106. package/types/liveness.d.ts +1 -0
  107. package/types/page-words.d.ts +6 -0
  108. package/types/pageask.d.ts +2 -0
  109. package/types/pagebits.d.ts +3 -0
  110. package/types/pagerules.d.ts +1 -0
  111. package/types/panel/author.d.ts +7 -3
  112. package/types/panel/authorcard.d.ts +0 -6
  113. package/types/panel/authorflows.d.ts +4 -4
  114. package/types/panel/authortrigger.d.ts +16 -2
  115. package/types/panel/data.d.ts +50 -16
  116. package/types/panel/spawn.d.ts +18 -2
  117. package/types/pickrecord.d.ts +29 -0
  118. package/types/reasons.d.ts +23 -0
  119. package/types/runfile.d.ts +14 -0
  120. package/types/runner.d.ts +6 -38
  121. package/types/runvalues.d.ts +17 -2
  122. package/types/schedule-choices.d.ts +9 -0
  123. package/types/schedule-shape.d.ts +15 -0
  124. package/types/sheetbuild.d.ts +1 -1
  125. package/types/thinking.d.ts +1 -0
  126. package/types/ticketrows.d.ts +0 -9
  127. package/types/trigger-clock.d.ts +3 -2
  128. package/types/trigger-files.d.ts +15 -4
  129. package/types/types.d.ts +8 -0
package/README.md CHANGED
@@ -28,17 +28,14 @@ change.
28
28
  It is built mainly for that shape of work: gather, decide, pause, hand off, continue. Not a
29
29
  general agent. Not a chat bot. A workflow that a person can read, approve, rerun, and edit.
30
30
 
31
- ## The machine that makes machines
31
+ ## The factory that builds the factory
32
32
 
33
- Like a CNC machine, fwdloop builds the thing that does the work, then lets a gauge it can't touch decide if the work is good, and stops for you where you said. Trust needs four things. Miss one and trust is zero. fwdloop has all four.
33
+ Software factories run a flow someone wrote in advance. fwdloop builds the flow for each job, then lets a gauge it can't touch decide if the work is good, and stops for you where you said. Trust needs four things. Miss one and trust is zero. fwdloop has all four.
34
34
 
35
- **Intent.** You write the job as plain numbered lines, and `~` rules under each say what success means. Every rule gets a check or a written reason why not. You sign before a dollar is spent.
36
-
37
- **Guide rails, not just guardrails.** Guardrails stop the agent going off the road: a money cap per run, a monthly limit, a time limit on every Ask, and a send destination you signed that it can't move. Nothing leaves the machine without that signed destination and your accept in the same run. Guide rails keep it on the road: each new try hears what earlier tries in the run did; lessons from past runs go to the drafter and to retries; a rule it can't settle comes back as a question with buttons (Agree, Drop it, or your own words), not a guess.
38
-
39
- **Verification.** The check sits outside the agent's loop: code decides, built on bareguard. For a list of items (one per flight, resume or topic), code checks each item's fields against the limits your rules give, and how many items there are when you said. Anything code can't check is listed as Not checked, and you judge it at the Ask. A red step goes back with the real gap to be fixed, up to four tries a step; the same miss twice stops it.
40
-
41
- **Evidence.** Every try, its cost and its check result is recorded, and the books balance to the cent. You can read it all in the Audit tab, including exactly what each try was told. Page facts are quoted from a saved copy of the page.
35
+ - **Intent.** You write the job as plain numbered lines, and `~` rules under each say what success means. Every rule gets a check or a written reason why not. You sign before a dollar is spent.
36
+ - **Guide rails, not just guardrails.** Guardrails stop the agent going off the road: a money cap per run, a monthly limit, a time limit on every Ask, and a send destination you signed that it can't move. Nothing leaves the machine without that signed destination and your accept in the same run. Guide rails keep it on the road: each new try hears what earlier tries in the run did; lessons from past runs go to the drafter and to retries; a rule it can't settle comes back as a question with buttons (Agree, Drop it, or your own words), not a guess.
37
+ - **Verification.** The check sits outside the agent's loop: code decides, built on bareguard. For a list of items (one per flight, resume or topic), code checks each item's fields against the limits your rules give, and how many items there are when you said. Anything code can't check is listed as Not checked, and you judge it at the Ask. A red step goes back with the real gap to be fixed, up to four tries a step; the same miss twice stops it.
38
+ - **Evidence.** Every try, its cost and its check result is recorded, and the books balance to the cent. You can read it all in the Audit tab, including exactly what each try was told. Page facts are quoted from a saved copy of the page.
42
39
 
43
40
  The one difference from a lights-out machine: a person stands at the gate. The run parks at your Ask, spending nothing, and only after your accept does it act on the world.
44
41
 
package/bin/fwdloop CHANGED
@@ -22,13 +22,13 @@ import { basename, dirname, extname, join, resolve } from 'node:path';
22
22
  import { draftHoldUsd } from '../src/draftspend.js';
23
23
  import { pathToFileURL } from 'node:url';
24
24
 
25
- import {
26
- readPlan, readRunPlan, checkFlowName, resolveRunDir, listFlowNames, listRunIds, readFileInside, claimRunId,
27
- } from '../src/flow.js';
25
+ import { readPlan, readRunPlan, checkFlowName, resolveRunDir, listFlowNames, listRunIds, claimRunId } from '../src/flow.js';
26
+ import { readFileInside } from '../src/inside.js';
28
27
  import { loadCatalogue } from '../src/catalogue.js';
29
28
  import {
30
- runFlow, resumeRun, continueRun, auditSpend, makeParkingAskStep, readAsk, readRunState,
29
+ runFlow, resumeRun, continueRun, auditSpend, makeParkingAskStep, readAsk,
31
30
  } from '../src/runner.js';
31
+ import { readRunState, consumedAnswerName } from '../src/books.js';
32
32
  import { applyRunValues, pickRunValues, dropUnstartedValues, runModelOf } from '../src/runvalues.js';
33
33
  import { TRIGGER_RECORD_FILE } from '../src/trigger-line.js';
34
34
  import { makeLiveModelStep } from '../src/model-step.js';
@@ -39,25 +39,25 @@ import {
39
39
  checkKeyPreflight, resolveUsableModel, pickTicked, readPriceConfig, ceilingCostUsd,
40
40
  } from '../src/provider.js';
41
41
  import { readModelRecord, readRunModel, LEARNINGS_FILE } from '../src/flowmodel.js';
42
- import { readRunInputs } from '../src/runfile.js';
42
+ import { readRunInputs, INPUTS_DIR } from '../src/runfile.js';
43
43
  import { configDoorHome, defaultFlowsRoot } from '../src/config.js';
44
44
  import {
45
45
  claimHold, settleHold, nameRunDir, monthlyRefusalText, ConfigError,
46
46
  } from '../src/monthly.js';
47
47
  import { keysForDoor } from '../src/keysfile.js';
48
48
  import {
49
- answerAsk, readAskEvidence, normalizeDecision, stripControl, withReopen,
49
+ answerAsk, readAskEvidence, normalizeDecision, stripControl, withReopen, readAskFile,
50
50
  } from '../src/ask.js';
51
51
  import { panelMain } from '../src/panel/server.js';
52
52
  import { launcherMain } from '../src/launcher.js';
53
53
  import { isInteractive, confirmTypedName, NEEDS_TTY } from '../src/sign-confirm.js';
54
- import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal } from '../src/authoring.js';
54
+ import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal, readTargetName } from '../src/authoring.js';
55
55
  import { minRuleRefusal } from '../src/minrule.js';
56
56
  import { readRecordFile, readRowChoices, readSheetDropped, readShapeDropped, readColumns } from '../src/pickrecord.js';
57
57
  import { userInfo } from 'node:os';
58
58
  import { pageAddressesOf, pageAddressRefusal } from '../src/pagefetch.js';
59
59
  import { ticketListsOf, isTicketNumber, TICKET_NUMBER_WORDS } from '../src/ticket-shape.js';
60
- import { flowTypeOf } from '../src/declaration.js';
60
+ import { flowTypeOf, isFlowType } from '../src/declaration.js';
61
61
  import { LOOK_TOOL } from '../src/ticket-draft.js';
62
62
  import { newestUnrunTicket } from '../src/ticket-next.js';
63
63
 
@@ -472,7 +472,7 @@ async function cmdRun(rest) {
472
472
  // refusal (moved to `src/runner.js` so any caller — this CLI, M4's web
473
473
  // panel — gets it for free); it also owns the ONLY `mkdirSync`/
474
474
  // `freezeInputs` for this run dir, so a refusal leaves nothing behind.
475
- const predictedInputs = sources.map((s) => ({ id: s.id, frozen: join(runDir, 'inputs', `${s.id}${extname(s.path)}`) }));
475
+ const predictedInputs = sources.map((s) => ({ id: s.id, frozen: join(runDir, INPUTS_DIR, `${s.id}${extname(s.path)}`) }));
476
476
  const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
477
477
  const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, { runDir, inputs: predictedInputs, mcp: stepMcp(declaration) });
478
478
 
@@ -519,11 +519,12 @@ function cmdInbox(rest) {
519
519
  const resolved = resolveRunDir(flowDir, runId);
520
520
  if (!resolved.ok) continue; // eslint-disable-line no-continue
521
521
  const runDir = resolved.runDir;
522
- const askRead = readFileInside(runDir, 'ask.json');
522
+ const askRead = readAskFile(runDir);
523
523
  if (!askRead.ok) continue; // eslint-disable-line no-continue -- missing (or refused) ask.json: nothing to show
524
524
  let ask;
525
525
  try {
526
- ask = withReopen(runDir, JSON.parse(askRead.text)); // the effective deadline (a reopened ask's new one)
526
+ if (askRead.parseError !== null) throw new Error(askRead.parseError);
527
+ ask = withReopen(runDir, askRead.value); // the effective deadline (a reopened ask's new one)
527
528
  } catch (err) {
528
529
  // A malformed/unparseable ask.json must never crash inbox — show it
529
530
  // naming the run as unreadable and move on to the next one.
@@ -546,7 +547,7 @@ function cmdInbox(rest) {
546
547
  // Consumed-marker check also goes through `readFileInside` — a
547
548
  // symlinked consumed marker is treated as "not consumed" (still shown
548
549
  // as open/expired), never as proof the ask was answered.
549
- if (readFileInside(runDir, `answer.${ask.askId}.consumed.json`).ok) continue; // eslint-disable-line no-continue -- this specific ask is already answered
550
+ if (readFileInside(runDir, consumedAnswerName(ask.askId)).ok) continue; // eslint-disable-line no-continue -- this specific ask is already answered
550
551
  // A present-but-unparseable expiresAt (Date.parse -> NaN) must never
551
552
  // read as "not expired" — `Date.now() > NaN` is false, so the naive
552
553
  // compare below would show this as [open] with a "NaNs left"
@@ -607,7 +608,7 @@ function cmdShow(rest) {
607
608
 
608
609
  // F48 round 3: routed through `readFileInside` (`src/flow.js`) — a
609
610
  // symlinked ask.json is refused by name here, never read through.
610
- const askRead = readFileInside(runDir, 'ask.json');
611
+ const askRead = readAskFile(runDir);
611
612
  if (!askRead.ok) {
612
613
  fail(askRead.missing
613
614
  ? `show: no ask.json for askId "${askId}"`
@@ -616,7 +617,8 @@ function cmdShow(rest) {
616
617
  }
617
618
  let ask;
618
619
  try {
619
- ask = withReopen(runDir, JSON.parse(askRead.text)); // the effective deadline (a reopened ask's new one)
620
+ if (askRead.parseError !== null) throw new Error(askRead.parseError);
621
+ ask = withReopen(runDir, askRead.value); // the effective deadline (a reopened ask's new one)
620
622
  } catch (err) {
621
623
  fail(`show: ask.json for askId "${askId}" is not valid JSON — ${err.message}`);
622
624
  return;
@@ -917,7 +919,7 @@ async function cmdDraft(rest) {
917
919
  });
918
920
  if (values.action !== undefined && !['check', 'known'].includes(values.action)) fail(`draft: --action takes check or known, got "${values.action}"`);
919
921
  const flowType = values['flow-type'] ?? 'plain';
920
- if (!['plain', 'mcp', 'tickets'].includes(flowType)) fail(`draft: --flow-type takes plain, mcp or tickets, got "${flowType}"`);
922
+ if (!isFlowType(flowType)) fail(`draft: --flow-type takes plain, mcp or tickets, got "${flowType}"`);
921
923
  if (flowType === 'plain' && values.mcp !== undefined) fail('draft: --mcp goes with --flow-type mcp or tickets');
922
924
  if (flowType !== 'plain' && !values.mcp) fail(`draft: --flow-type ${flowType} needs --mcp <server>`);
923
925
  const keysLoad = keyedLoad();
@@ -1021,6 +1023,8 @@ async function cmdDraft(rest) {
1021
1023
  const result = await draftToDir({
1022
1024
  // M4d am32: the hold is given back when the draft's result is written, not when this process exits (the exit hook stays as the backstop)
1023
1025
  onResult: ({ ok }) => hold.settle(ok ? 'ended or parked' : 'ended (red)'),
1026
+ // M20 am1 item 5: the step lines go to the log like `refusal-record` does (the panel reads child.log)
1027
+ onStepLine: (kind, rec) => process.stderr.write(`fwdloop: ${kind} ${JSON.stringify(rec)}\n`),
1024
1028
  proseFile: resolve(proseFile),
1025
1029
  proseRead,
1026
1030
  dir: resolve(values.out),
@@ -1078,10 +1082,8 @@ async function cmdSign(rest) {
1078
1082
  // Amendment 2: a person at a keyboard. TTY check first (cheapest), then the typed flow name; only then
1079
1083
  // signDraft's own $0 checks (hash, wired, goals, TTL, sources, send, leak). signDraft writes only on success.
1080
1084
  if (!isInteractive()) fail(`sign refused — ${NEEDS_TTY}`);
1081
- let flowName;
1082
- const tj = readFileInside(resolve(dir), 'target.json');
1083
- try { flowName = tj.ok ? JSON.parse(tj.text).name : undefined; } catch { flowName = undefined; }
1084
- if (typeof flowName !== 'string' || flowName === '') fail('sign refused — the draft has no readable target.json name');
1085
+ const flowName = readTargetName(resolve(dir));
1086
+ if (flowName === null) fail('sign refused — the draft has no readable target.json name');
1085
1087
  const typed = await confirmTypedName({ name: flowName });
1086
1088
  if (!typed.ok) fail(`sign refused — ${typed.red}`);
1087
1089
  const result = signDraft({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwdloop",
3
- "version": "0.38.0",
3
+ "version": "0.40.0",
4
4
  "description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/ask.js CHANGED
@@ -1,29 +1,15 @@
1
- // M2 piece 2 (docs/wiki/the-module-ladder.md, "M2 — scope, exit, negative —
2
- // SIGNED", scope item 6): the file-checkpoint ask, in-process. Writes
3
- // `ask.json` (question + evidence + askedAt + attempt) into the run dir and
4
- // polls for `answer.json` (`{ decision: accept|redo|rerun, reason?,
5
- // answeredAt }`). Consumed exactly once (renamed away on read); a stale
6
- // answer — `answeredAt` older than THIS ask's `askedAt` — is quarantined
7
- // (renamed to `answer.stale.<n>.json`, audited `stale-answer-ignored`) and
8
- // never applied; a timeout returns `{ decision: 'timeout' }`, which
9
- // `src/runner.js` must treat as a halt (a pause spends nothing).
10
- //
11
- // borrowed-from: fwdloop poc/m0/runner.mjs@76a3607 (`checkpointAsk`'s file
12
- // protocol: `ask.json` out / poll `answer.json`, and the "ASK OPEN" stderr
13
- // line so a human watching knows a run is waiting on them) and
14
- // fwdloop poc/m0/answer.mjs@76a3607 (the answer file's own shape). Rewritten
15
- // off bare-agent's `Checkpoint` (M0's dependency) onto a plain poll loop —
16
- // M2's signed scope (item 6) calls for "M0's file checkpoint, in-process",
17
- // not a second Checkpoint instance layered on top of the same file protocol.
1
+ // The ask's files and rules: the answer door (`answerAsk`), the reopen record, the archive of asked questions, the
2
+ // one evidence reader, and the one decision table. (M2 piece 2's in-process file-checkpoint step was removed by M20 am3
3
+ // item 5: the runner parks an ask and the Resume path reads the answer.)
18
4
 
19
5
  import {
20
- existsSync, linkSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync,
6
+ existsSync, linkSync, mkdirSync, unlinkSync, writeFileSync,
21
7
  } from 'node:fs';
22
8
  import { join } from 'node:path';
23
- import { createHash, randomUUID } from 'node:crypto';
9
+ import { createHash } from 'node:crypto';
24
10
 
25
- import { appendAudit } from './books.js';
26
- import { readFileInside, resolveInside, readdirInside } from './flow.js';
11
+ import { appendAudit, consumedAnswerName, readSavedAnswer } from './books.js';
12
+ import { readFileInside, resolveInside, readdirInside } from './inside.js';
27
13
 
28
14
  /**
29
15
  * M4c amendment 3: the ONE rule for "was this answer saved in time" — the
@@ -66,6 +52,11 @@ export function stripControl(text) {
66
52
  return String(text).replace(/[\x00-\x08\x0B-\x1F\x7F-\x9F]/g, '');
67
53
  }
68
54
 
55
+ /** M20 am8a: the decisions that need a reason, as a list (the panel hands it to the page, which asks it instead of spelling them) */
56
+ export const REASON_DECISIONS = Object.freeze(['redo', 'rerun']);
57
+ /** M20 am8: the one question "does this decision need a reason" (a redo or a rerun; an accept does not): the answer door and the runner's re-check of a saved answer ask it @param {unknown} decision @returns {boolean} */
58
+ export const needsReason = (decision) => REASON_DECISIONS.includes(/** @type {string} */ (decision));
59
+
69
60
  /** The one decision -> status table, used by `listArchivedAsks` here and by the panel's legacy-ask rows.
70
61
  * Look it up with `normalizeDecision(decision)`. */
71
62
  export const DECISION_STATUS = { accept: 'accepted', redo: 'redo', rerun: 'reran' };
@@ -77,96 +68,6 @@ export function decisionStatus(decision) {
77
68
  return typeof word === 'string' && Object.hasOwn(DECISION_STATUS, word) ? DECISION_STATUS[word] : undefined;
78
69
  }
79
70
 
80
- function sleep(ms) {
81
- return new Promise((resolve) => { setTimeout(resolve, ms); });
82
- }
83
-
84
- function safeStamp(iso) {
85
- return String(iso).replace(/[^0-9A-Za-z]/g, '-');
86
- }
87
-
88
- /**
89
- * @param {{ timeoutMs?: number, pollMs?: number, clock?: () => string, writeLine?: (line:string) => void }} [opts]
90
- * @returns {(opts:{question:string, evidence:unknown, runDir:string, ttlMs?: number}) => Promise<{decision:string, reason?:string}>}
91
- */
92
- export function makeFileAskStep({
93
- timeoutMs = 120_000,
94
- pollMs = 500,
95
- clock = () => new Date().toISOString(),
96
- writeLine = (line) => { process.stderr.write(`${line}\n`); },
97
- } = {}) {
98
- let attemptCounter = 0;
99
-
100
- return async function fileAskStep({
101
- question, evidence, runDir, ttlMs,
102
- }) {
103
- attemptCounter += 1;
104
- const attempt = attemptCounter;
105
-
106
- // M3 scope item 1 (fixes F43): a signed `ttlMs` threaded in by the
107
- // runner always governs — this constructor's own `timeoutMs` is only
108
- // ever the fallback for a DIRECT call that carries no signed ttl (e.g.
109
- // this module's own unit tests). No code default overrides a signed
110
- // value.
111
- const effectiveTimeoutMs = typeof ttlMs === 'number' ? ttlMs : timeoutMs;
112
-
113
- mkdirSync(runDir, { recursive: true });
114
- const askPath = join(runDir, 'ask.json');
115
- const answerPath = join(runDir, 'answer.json');
116
- const askedAt = clock();
117
- const askId = randomUUID();
118
- const expiresAt = new Date(Date.parse(askedAt) + effectiveTimeoutMs).toISOString();
119
-
120
- writeFileSync(askPath, JSON.stringify({
121
- askId, question, evidence, askedAt, expiresAt, attempt,
122
- }, null, 2));
123
- writeLine(`ASK OPEN (expires in ${Math.round(effectiveTimeoutMs / 1000)}s): ${question} — answer by writing ${answerPath}`);
124
-
125
- const deadline = Date.now() + effectiveTimeoutMs;
126
- let staleCount = 0;
127
-
128
- for (;;) {
129
- // F48 round 3: `answer.json` is checked with `resolveInside`
130
- // (`src/flow.js`) before it is ever read — a symlinked answer file (or
131
- // a symlinked run-dir ancestor) is treated exactly like "no answer
132
- // yet" (kept polling), never read through to an outside file's
133
- // content standing in for the human's real decision.
134
- const answerResolved = resolveInside(runDir, 'answer.json');
135
- if (answerResolved.ok) {
136
- let raw = null;
137
- try { raw = readFileSync(answerPath, 'utf8'); } catch { raw = null; }
138
- let parsed = null;
139
- if (raw !== null) { try { parsed = JSON.parse(raw); } catch { parsed = null; } }
140
-
141
- if (parsed) {
142
- const { answeredAt } = parsed;
143
- const isStale = typeof answeredAt === 'string' && typeof askedAt === 'string' && answeredAt < askedAt;
144
- if (isStale) {
145
- staleCount += 1;
146
- let staleName = join(runDir, `answer.stale.${staleCount}.json`);
147
- while (existsSync(staleName)) { staleCount += 1; staleName = join(runDir, `answer.stale.${staleCount}.json`); }
148
- renameSync(answerPath, staleName);
149
- appendAudit(runDir, {
150
- step: 'ask', attempt, class: null, verdict: 'stale-answer-ignored', gap: `answeredAt ${answeredAt} predates this ask's askedAt ${askedAt}`, usd: 0, spendComplete: true, wallMs: 0, model: null, modelMatch: null, strike: false, at: clock(), tokens: null, tools: null, refused: [],
151
- });
152
- // Keep polling — a stale file quarantined does not mean THIS
153
- // ask has been answered.
154
- } else {
155
- renameSync(answerPath, join(runDir, `answer.${safeStamp(askedAt)}.consumed.json`));
156
- return { decision: normalizeDecision(parsed.decision), reason: parsed.reason, artifactSha256: parsed.artifactSha256 };
157
- }
158
- }
159
- }
160
-
161
- if (Date.now() >= deadline) {
162
- return { decision: 'timeout' };
163
- }
164
- // eslint-disable-next-line no-await-in-loop
165
- await sleep(pollMs);
166
- }
167
- };
168
- }
169
-
170
71
  // ---------------------------------------------------------------------------
171
72
  // F47 fix (docs/logs/FINDINGS.md F47, M4a ladder item 1): the ONE shared
172
73
  // reader for ask.json's `evidence` field, across every real shape on disk —
@@ -311,15 +212,14 @@ export function sha256Hex(serialised) {
311
212
  * M4c-fix amendment 1 (a): why a saved `answer.json` is not a usable answer for the open ask `openAskId`, or `null`
312
213
  * when it is usable. The resume refuses each of these by name before it consumes the file, so without a way aside
313
214
  * the file would block every new answer (`answerAsk`'s exclusive create).
314
- * @param {string} text the file's text @param {string} openAskId
215
+ * @param {Extract<ReturnType<typeof readSavedAnswer>, {ok: true}>} saved `readSavedAnswer`'s result (the one reader of the file) @param {string} openAskId
315
216
  * @returns {string|null}
316
217
  */
317
- export function brokenAnswerWhy(text, openAskId) {
318
- let a;
319
- try { a = JSON.parse(text); } catch { return 'it is not valid JSON'; }
320
- if (a === null || typeof a !== 'object' || Array.isArray(a)) return 'it is not a JSON object';
321
- if (a.askId !== openAskId) return `it names another ask ("${a.askId}")`;
322
- if (Number.isNaN(Date.parse(typeof a.answeredAt === 'string' ? a.answeredAt : ''))) return 'it carries no readable saved time';
218
+ export function brokenAnswerWhy(saved, openAskId) {
219
+ if (saved.parseError !== null) return 'it is not valid JSON';
220
+ if (!saved.isObject) return 'it is not a JSON object';
221
+ if (saved.value.askId !== openAskId) return `it names another ask ("${saved.value.askId}")`;
222
+ if (saved.broken) return 'it carries no readable saved time';
323
223
  return null;
324
224
  }
325
225
 
@@ -380,6 +280,20 @@ export function effectiveExpiresAt(runDir, askId, original) {
380
280
  return best ? best.expiresAt : original;
381
281
  }
382
282
 
283
+ /**
284
+ * M20 am3e item 15: the ONE reader of a run's `ask.json`, as found, through the safe gateway: `{ok: false, missing, red}` when the gateway gives nothing (missing, a symlink,
285
+ * outside the folder), else `{ok: true, value, parseError}`: `value` is the parsed JSON as it is (any shape), `parseError` the parser's message when the text is not JSON
286
+ * (`value` is then undefined). It applies nothing: each caller keeps its own refusal words and its own `withReopen` step (`readAsk` in src/runner.js is this plus
287
+ * `withReopen`, null on any trouble).
288
+ * @param {string} runDir
289
+ * @returns {{ok: false, missing: boolean, red?: string}|{ok: true, value: any, parseError: string|null}}
290
+ */
291
+ export function readAskFile(runDir) {
292
+ const r = readFileInside(runDir, 'ask.json');
293
+ if (!r.ok) return r;
294
+ try { return { ok: true, value: JSON.parse(r.text), parseError: null }; } catch (err) { return { ok: true, value: undefined, parseError: /** @type {any} */ (err).message }; }
295
+ }
296
+
383
297
  /**
384
298
  * An `ask.json`-shaped object as every reader should see it: `expiresAt` is the effective deadline, and `waitMs`
385
299
  * is the signed wait the ask was parked with (its own `expiresAt` minus `askedAt`, written from the signed ttl),
@@ -414,22 +328,21 @@ export function reopenAsk({
414
328
  if (typeof runDir !== 'string' || runDir.length === 0) return { ok: false, red: 'reopenAsk: "runDir" must be a non-empty string' };
415
329
  if (typeof askId !== 'string' || askId.length === 0) return { ok: false, red: 'reopenAsk: "askId" must be a non-empty string' };
416
330
  if (typeof by !== 'string' || by.length === 0) return { ok: false, red: 'reopenAsk: "by" must name who reopened it' };
417
- const askRead = readFileInside(runDir, 'ask.json');
331
+ const askRead = readAskFile(runDir);
418
332
  if (!askRead.ok) return { ok: false, red: `reopenAsk: no open ask for run ${runDir}` };
419
- let raw;
420
- try { raw = JSON.parse(askRead.text); } catch (err) { return { ok: false, red: `reopenAsk: ask.json for run ${runDir} is not valid JSON — ${err.message}` }; }
333
+ if (askRead.parseError !== null) return { ok: false, red: `reopenAsk: ask.json for run ${runDir} is not valid JSON — ${askRead.parseError}` };
334
+ const raw = askRead.value;
421
335
  if (raw === null || typeof raw !== 'object' || raw.askId !== askId) return { ok: false, red: `reopenAsk: askId "${askId}" is unknown for run ${runDir}` };
422
336
  const ask = withReopen(runDir, raw);
423
337
  if (Number.isNaN(Date.parse(ask.expiresAt))) return { ok: false, red: `reopenAsk: askId "${askId}" has an unparseable expiresAt — refusing` };
424
338
  if (ask.waitMs === null) return { ok: false, red: `reopenAsk: askId "${askId}" carries no readable wait (askedAt/expiresAt) to repeat — refusing` };
425
- if (existsSync(join(runDir, `answer.${askId}.consumed.json`))) return { ok: false, red: `reopenAsk: askId "${askId}" already answered for run ${runDir}` };
339
+ if (existsSync(join(runDir, consumedAnswerName(askId)))) return { ok: false, red: `reopenAsk: askId "${askId}" already answered for run ${runDir}` };
426
340
  if (Date.parse(nowIso) <= Date.parse(ask.expiresAt)) return { ok: false, red: `reopenAsk: askId "${askId}" has not expired (it runs until ${ask.expiresAt})` };
427
- const saved = readFileInside(runDir, 'answer.json');
341
+ const saved = readSavedAnswer(runDir);
428
342
  let timing = null;
429
343
  if (saved.ok) {
430
- let a = null;
431
- try { a = JSON.parse(saved.text); } catch { /* broken: set aside below */ }
432
- timing = a !== null && typeof a === 'object' && a.askId === askId ? answerTiming(a.answeredAt, ask.expiresAt) : 'unreadable';
344
+ // a broken answer, or one for another ask, is set aside below
345
+ timing = !saved.broken && saved.askId === askId ? answerTiming(saved.answeredAt, ask.expiresAt) : 'unreadable';
433
346
  if (timing === 'on-time') return { ok: false, red: `reopenAsk: askId "${askId}" has an answer saved in time — resume it, it is not expired` };
434
347
  }
435
348
  // Amendment 3 (b): the stale answer is moved aside FIRST. If that fails nothing is written (no record, no audit
@@ -492,19 +405,17 @@ export function answerAsk({
492
405
  // F48 round 3: routed through `readFileInside` — a symlinked `ask.json`
493
406
  // (or a symlinked run-dir ancestor) reads as "no open ask", never as some
494
407
  // outside file's content.
495
- const askRead = readFileInside(runDir, 'ask.json');
408
+ const askRead = readAskFile(runDir);
496
409
  if (!askRead.ok) {
497
410
  if (askRead.missing) {
498
411
  return { ok: false, red: `answerAsk: no open ask for run ${runDir}` };
499
412
  }
500
413
  return { ok: false, red: `answerAsk: ask.json for run ${runDir} — ${askRead.red}` };
501
414
  }
502
- let ask;
503
- try {
504
- ask = JSON.parse(askRead.text);
505
- } catch (err) {
506
- return { ok: false, red: `answerAsk: ask.json for run ${runDir} is not valid JSON — ${err.message}` };
415
+ if (askRead.parseError !== null) {
416
+ return { ok: false, red: `answerAsk: ask.json for run ${runDir} is not valid JSON — ${askRead.parseError}` };
507
417
  }
418
+ const ask = askRead.value;
508
419
  if (ask.askId !== askId) {
509
420
  return { ok: false, red: `answerAsk: askId "${askId}" is unknown for run ${runDir}` };
510
421
  }
@@ -532,12 +443,12 @@ export function answerAsk({
532
443
  // A consumed marker survives long after the run has moved on (or ended) —
533
444
  // it must still refuse a second answer naming the SAME askId, never only
534
445
  // while answer.json happens to still be sitting there.
535
- if (existsSync(join(runDir, `answer.${askId}.consumed.json`))) {
446
+ if (existsSync(join(runDir, consumedAnswerName(askId)))) {
536
447
  return { ok: false, red: `answerAsk: askId "${askId}" already answered for run ${runDir}` };
537
448
  }
538
449
 
539
450
  const trimmedReason = typeof reason === 'string' ? reason.trim() : '';
540
- if ((decision === 'redo' || decision === 'rerun') && trimmedReason.length === 0) {
451
+ if (needsReason(decision) && trimmedReason.length === 0) {
541
452
  return { ok: false, red: `answerAsk: askId "${askId}" needs a non-blank reason to ${decision}` };
542
453
  }
543
454
 
@@ -566,9 +477,9 @@ export function answerAsk({
566
477
  // M4c-fix amendment 1 (a): a saved answer that is broken (not JSON, not an object, names another ask, no readable
567
478
  // time) would block this write for good — it is moved aside as a record first (never deleted). Only a broken one.
568
479
  let setAside = null;
569
- const savedRead = readFileInside(runDir, 'answer.json');
480
+ const savedRead = readSavedAnswer(runDir);
570
481
  if (savedRead.ok) {
571
- const why = brokenAnswerWhy(savedRead.text, askId);
482
+ const why = brokenAnswerWhy(savedRead, askId);
572
483
  if (why !== null) {
573
484
  const moved = setAsideAnswer(runDir, askId, 'broken');
574
485
  if (!moved.ok) return { ok: false, red: `answerAsk: askId "${askId}" — a broken saved answer (${why}) is in the way — ${moved.red}` };
@@ -655,6 +566,18 @@ export function writeAskArchive({
655
566
  return { ok: true };
656
567
  }
657
568
 
569
+ /**
570
+ * The one parse of an archived ask, `asks/<entry>` (entry = `<askId>.json`), through the safe gateway. `unreadable` keeps the gateway's own result in `read`
571
+ * (missing, a symlink, outside the folder); `invalid` is text that is not JSON, with the parser's message. The callers decide what a failure means.
572
+ * @param {string} runDir @param {string} entry
573
+ * @returns {{ok: true, ask: any}|{ok: false, code: 'unreadable', read: any}|{ok: false, code: 'invalid', message: string}}
574
+ */
575
+ function readArchivedAsk(runDir, entry) {
576
+ const read = readFileInside(runDir, join('asks', entry));
577
+ if (!read.ok) return { ok: false, code: 'unreadable', read };
578
+ try { return { ok: true, ask: JSON.parse(read.text) }; } catch (err) { return { ok: false, code: 'invalid', message: err.message }; }
579
+ }
580
+
658
581
  /**
659
582
  * M4b amendment 2: for each archived ask that carries `emits`, joins it BY
660
583
  * askId to its consumed answer and returns the recorded `artifactSha256` of
@@ -674,12 +597,11 @@ export function readAcceptedHashesByEmits(runDir) {
674
597
  for (const entry of readdirInside(runDir, 'asks').sort()) {
675
598
  if (!entry.endsWith('.json')) continue; // eslint-disable-line no-continue
676
599
  const askId = entry.slice(0, -'.json'.length);
677
- const archiveRead = readFileInside(runDir, join('asks', entry));
678
- if (!archiveRead.ok) continue; // eslint-disable-line no-continue
679
- let emits;
680
- try { emits = JSON.parse(archiveRead.text)?.emits; } catch { continue; } // eslint-disable-line no-continue
600
+ const archived = readArchivedAsk(runDir, entry);
601
+ if (!archived.ok) continue; // eslint-disable-line no-continue
602
+ const emits = archived.ask?.emits;
681
603
  if (typeof emits !== 'string' || emits.length === 0) continue; // eslint-disable-line no-continue
682
- const markerRead = readFileInside(runDir, `answer.${askId}.consumed.json`);
604
+ const markerRead = readFileInside(runDir, consumedAnswerName(askId));
683
605
  if (!markerRead.ok) continue; // eslint-disable-line no-continue
684
606
  let marker;
685
607
  try { marker = JSON.parse(markerRead.text); } catch { continue; } // eslint-disable-line no-continue
@@ -730,9 +652,10 @@ export function listArchivedAsks(runDir) {
730
652
  if (!entry.endsWith('.json')) continue; // eslint-disable-line no-continue
731
653
  const askId = entry.slice(0, -'.json'.length);
732
654
  const archivePath = join(runDir, 'asks', entry);
733
- const archiveRead = readFileInside(runDir, join('asks', entry));
655
+ const archived = readArchivedAsk(runDir, entry);
734
656
  let ask;
735
- if (!archiveRead.ok) {
657
+ if (!archived.ok && archived.code === 'unreadable') {
658
+ const archiveRead = archived.read;
736
659
  asks.push({
737
660
  askId, question: undefined, askedAt: undefined, expiresAt: undefined,
738
661
  evidence: {
@@ -746,18 +669,17 @@ export function listArchivedAsks(runDir) {
746
669
  });
747
670
  continue; // eslint-disable-line no-continue
748
671
  }
749
- try {
750
- ask = JSON.parse(archiveRead.text);
751
- } catch (err) {
672
+ if (!archived.ok) {
752
673
  asks.push({
753
674
  askId, question: undefined, askedAt: undefined, expiresAt: undefined,
754
- evidence: { draft: null, unjudged: [], why: `${archivePath} is not valid JSON — ${err.message}` },
675
+ evidence: { draft: null, unjudged: [], why: `${archivePath} is not valid JSON — ${archived.message}` },
755
676
  answer: { status: 'open' },
756
677
  });
757
678
  continue; // eslint-disable-line no-continue
758
679
  }
680
+ ask = archived.ask;
759
681
 
760
- const consumedRelPath = `answer.${askId}.consumed.json`;
682
+ const consumedRelPath = consumedAnswerName(askId);
761
683
  const consumedRead = readFileInside(runDir, consumedRelPath);
762
684
  let answer = { status: 'open' };
763
685
  if (consumedRead.ok) {
package/src/audit-fold.js CHANGED
@@ -1,11 +1,12 @@
1
1
  // M4d am29 items 4-8: the Audit step fold, the Run summary's two lines and the step card's one line, all derived HERE from the run's files on disk
2
2
  // (audit.jsonl's try rows + the three diaries in src/diary.js). Nothing here calls a model ($0 replay), and the page only draws what this returns,
3
3
  // so the Audit rows, the summary and the cards can only agree. A run from before am29 has no diaries: no fold, `—` on the new lines, nothing made up.
4
- import { readCalls, readTools, readChecks } from './diary.js';
4
+ import { readCalls, readTools, readChecks, newestChecksOf } from './diary.js';
5
+ import { isStopNote, isHumanNo, isAskRow } from './books.js';
5
6
 
6
7
  /** A Stop's notes are not tries: the asked/not-honoured rows, and a `stopped` row that cut no try (no attempt number). @param {any} r */
7
8
  export function isTryRow(r) {
8
- return r.verdict !== 'stop-asked' && r.verdict !== 'stop-not-honoured' && !(r.verdict === 'stopped' && !Number.isInteger(r.attempt));
9
+ return !isStopNote(r.verdict) && !(r.verdict === 'stopped' && !Number.isInteger(r.attempt));
9
10
  }
10
11
 
11
12
  /** @param {string} runDir */
@@ -68,7 +69,7 @@ function answerShort(r) {
68
69
  */
69
70
  export function deriveFold(group, d, info = {}) {
70
71
  const step = group.rows[0]?.step ?? null;
71
- const human = group.rows.some((r) => Object.prototype.hasOwnProperty.call(r, 'unjudgedCount'));
72
+ const human = group.rows.some(isAskRow);
72
73
  const calls = d.calls.filter((r) => r.step === step);
73
74
  const tools = d.tools.filter((r) => r.step === step);
74
75
  const checkRows = d.checks.filter((r) => r.step === step);
@@ -95,7 +96,7 @@ export function deriveFold(group, d, info = {}) {
95
96
  tries.push(open);
96
97
  }
97
98
  open.answer = humanWords(r);
98
- open.mark = r.verdict === 'green' ? '✓' : (r.verdict === 'red' || r.verdict === 'stopped' ? '✗' : '·');
99
+ open.mark = r.verdict === 'green' ? '✓' : (isHumanNo(r.verdict) ? '✗' : '·');
99
100
  }
100
101
  }
101
102
  for (const r of group.rows) {
@@ -138,7 +139,7 @@ export function deriveFold(group, d, info = {}) {
138
139
  const tally = {};
139
140
  for (const t of tools) tally[t.tool] = (tally[t.tool] ?? 0) + 1;
140
141
  const tallyWords = Object.entries(tally).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([k, v]) => `${k} ${v}`).join(', ');
141
- const lastChecks = checkRows.length ? checkRows[checkRows.length - 1].checks : null;
142
+ const lastChecks = newestChecksOf(checkRows, step)?.checks ?? null;
142
143
  const answered = human ? group.rows.filter((r) => r.verdict !== 'paused' && isTryRow(r) && humanWords(r) !== null) : [];
143
144
  const lastAnswerRow = answered.length ? answered[answered.length - 1] : null;
144
145
  return {
@@ -4,6 +4,8 @@
4
4
  // What a run recorded for a check is read off its diary (`checks` rows: each check numbered with its `ok`, and for a list line its `part`); nothing is re-derived. What this throws away: the checks of a line off the list
5
5
  // (the sheet and the older plans keep their own Audit rows), and the per-try history (the LAST try of a step is the one that closed it).
6
6
  import { listLinesOf } from './checklistsign.js';
7
+ import { tagOf } from './checkwords.js';
8
+ import { newestChecksOf } from './diary.js';
7
9
  import { listPartRows, notCheckedView } from './checked.js';
8
10
  import { EVERY_STEP, EVERY_STEP_TEXTS } from './try-checks.js';
9
11
  import { sheetRowsOf } from './sheetrows.js';
@@ -25,7 +27,7 @@ export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines
25
27
  const sheetRows = sheetOn ? sheetRowsOf({ declaration, lines: jobLines, csvRoles }) : null;
26
28
  if (lines.size === 0 && !(sheetRows && sheetRows.card.length > 0)) return null;
27
29
  const steps = (Array.isArray(declaration?.steps) ? declaration.steps : []).filter((/** @type {any} */ st) => lines.has(st?.fromLine));
28
- const lastTry = (/** @type {any} */ st) => (Array.isArray(diary) ? diary : []).filter((d) => d.step === (st.emits ?? st.goal ?? null)).at(-1);
30
+ const lastTry = (/** @type {any} */ st) => newestChecksOf(Array.isArray(diary) ? diary : [], st.emits ?? st.goal ?? null) ?? undefined;
29
31
  /** @type {AuditCheckRow[]} */
30
32
  const checks = [];
31
33
  // the same rows by the job line that owns them, their words without the `line N · ` prefix (S7: one block per line)
@@ -62,13 +64,13 @@ export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines
62
64
  // M17 am4 (C3): the Audit splits a reading note from Not checked as the card and the Job tab do (src/checked.js notCheckedView)
63
65
  const view = notCheckedView(notChecked?.items ?? [], declaration);
64
66
  /** @type {AuditCheckRow[]} */
65
- const notRows = view.items.map((t) => ({ ...splitNotChecked(t), by: by[t] === 'you' || by[t] === 'agent' || by[t] === 'default' ? /** @type {'you'|'agent'|'default'} */ (by[t]) : null, result: 'not-checked' }));
67
+ const notRows = view.items.map((t) => ({ ...splitNotChecked(t), by: tagOf(by[t]) !== '' ? /** @type {'you'|'agent'|'default'} */ (by[t]) : null, result: 'not-checked' }));
66
68
  // the two checks every step has (src/try-checks.js #1 and #2): passed when every step that ran them passed, failed when one did not
67
69
  const every = (/** @type {string} */ text) => {
68
- const seen = (Array.isArray(diary) ? diary : []).flatMap((d) => (d.checks ?? []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text));
70
+ const seen = (Array.isArray(diary) ? diary : []).flatMap((d) => (Array.isArray(d.checks) ? d.checks : []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text));
69
71
  return seen.length === 0 ? 'none' : seen.every((/** @type {any} */ c) => c.ok) ? 'passed' : 'failed';
70
72
  };
71
- const everyWhy = (/** @type {string} */ text) => whyOf((Array.isArray(diary) ? diary : []).flatMap((d) => (d.checks ?? []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text)).find((/** @type {any} */ c) => !c.ok));
73
+ const everyWhy = (/** @type {string} */ text) => whyOf((Array.isArray(diary) ? diary : []).flatMap((d) => (Array.isArray(d.checks) ? d.checks : []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text)).find((/** @type {any} */ c) => !c.ok));
72
74
  /** @type {AuditCheckRow[]} */
73
75
  const always = EVERY_STEP_TEXTS.map((text) => ({ text, kind: 'file', by: /** @type {'default'} */ ('default'), result: every(text), ...everyWhy(text) }));
74
76
  // M19 S7: one block per job line (its checks, its Not checked rows) and the Not checked rows no line owns; the two every-step rows are the page's "Every line" block (a one-line job's Line 1 block)