fwdloop 0.21.0 → 0.23.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 (104) hide show
  1. package/bin/fwdloop +85 -34
  2. package/package.json +4 -3
  3. package/src/ask.js +20 -4
  4. package/src/audit-fold.js +5 -1
  5. package/src/authoring.js +36 -6
  6. package/src/canrun.js +5 -0
  7. package/src/checked.js +32 -4
  8. package/src/cited-record.js +138 -0
  9. package/src/cited-source.js +49 -0
  10. package/src/citedcheck.js +321 -0
  11. package/src/citedwords.js +197 -0
  12. package/src/closers.js +37 -198
  13. package/src/csv.js +69 -12
  14. package/src/ctx-tools.js +2 -14
  15. package/src/declaration.js +143 -5
  16. package/src/diary.js +2 -2
  17. package/src/docx.js +16 -2
  18. package/src/draft-steps.js +1 -1
  19. package/src/drafter.js +322 -33
  20. package/src/flow.js +33 -7
  21. package/src/flowmodel.js +21 -0
  22. package/src/input-facts.js +20 -3
  23. package/src/model-step.js +38 -21
  24. package/src/pageask.js +136 -0
  25. package/src/pagebits.js +107 -0
  26. package/src/pagedropwords.js +171 -0
  27. package/src/pagedry.js +120 -0
  28. package/src/pagefetch.js +164 -0
  29. package/src/pagelook.js +155 -0
  30. package/src/pagemap.js +55 -0
  31. package/src/pageplace.js +103 -0
  32. package/src/pagerules.js +318 -0
  33. package/src/panel/author.js +43 -21
  34. package/src/panel/authorcard.js +20 -3
  35. package/src/panel/authorflows.js +21 -15
  36. package/src/panel/authorstart.js +2 -4
  37. package/src/panel/authortrigger.js +14 -4
  38. package/src/panel/data.js +102 -6
  39. package/src/panel/index.html +321 -12
  40. package/src/panel/result.js +301 -0
  41. package/src/panel/server.js +27 -3
  42. package/src/primitives.js +2 -3
  43. package/src/provider.js +5 -2
  44. package/src/redact.js +17 -0
  45. package/src/runner.js +102 -14
  46. package/src/schedule.js +3 -3
  47. package/src/setup.js +16 -1
  48. package/src/sheet-record.js +57 -0
  49. package/src/sheetblock.js +170 -0
  50. package/src/sheetchecks.js +206 -0
  51. package/src/sheetclaims.js +78 -0
  52. package/src/sheetfind.js +50 -0
  53. package/src/sheetlook.js +157 -0
  54. package/src/sheetoffer.js +125 -0
  55. package/src/sheetrun.js +105 -0
  56. package/src/signed-text.js +11 -1
  57. package/src/thinking.js +1 -1
  58. package/src/try-checks.js +12 -0
  59. package/src/types.js +4 -11
  60. package/types/ask.d.ts +2 -1
  61. package/types/authoring.d.ts +19 -2
  62. package/types/checked.d.ts +19 -3
  63. package/types/cited-record.d.ts +21 -0
  64. package/types/cited-source.d.ts +18 -0
  65. package/types/citedcheck.d.ts +95 -0
  66. package/types/citedwords.d.ts +97 -0
  67. package/types/closers.d.ts +37 -10
  68. package/types/csv.d.ts +25 -4
  69. package/types/ctx-tools.d.ts +0 -1
  70. package/types/declaration.d.ts +20 -1
  71. package/types/docx.d.ts +14 -0
  72. package/types/drafter.d.ts +264 -8
  73. package/types/flow.d.ts +21 -0
  74. package/types/flowmodel.d.ts +15 -0
  75. package/types/input-facts.d.ts +12 -2
  76. package/types/model-step.d.ts +40 -19
  77. package/types/pageask.d.ts +75 -0
  78. package/types/pagebits.d.ts +32 -0
  79. package/types/pagedropwords.d.ts +40 -0
  80. package/types/pagedry.d.ts +38 -0
  81. package/types/pagefetch.d.ts +86 -0
  82. package/types/pagelook.d.ts +75 -0
  83. package/types/pagemap.d.ts +31 -0
  84. package/types/pageplace.d.ts +22 -0
  85. package/types/pagerules.d.ts +86 -0
  86. package/types/panel/authorcard.d.ts +4 -1
  87. package/types/panel/authorflows.d.ts +2 -0
  88. package/types/panel/data.d.ts +26 -0
  89. package/types/panel/result.d.ts +156 -0
  90. package/types/provider.d.ts +3 -1
  91. package/types/redact.d.ts +1 -0
  92. package/types/runner.d.ts +162 -9
  93. package/types/schedule.d.ts +0 -11
  94. package/types/setup.d.ts +13 -0
  95. package/types/sheet-record.d.ts +24 -0
  96. package/types/sheetblock.d.ts +116 -0
  97. package/types/sheetchecks.d.ts +70 -0
  98. package/types/sheetclaims.d.ts +26 -0
  99. package/types/sheetfind.d.ts +46 -0
  100. package/types/sheetlook.d.ts +120 -0
  101. package/types/sheetoffer.d.ts +25 -0
  102. package/types/sheetrun.d.ts +35 -0
  103. package/types/thinking.d.ts +1 -1
  104. package/types/types.d.ts +27 -14
@@ -34,6 +34,7 @@ import { checkValues } from './authorvalues.js';
34
34
  import { getRunControls, getRunGlyph } from './data.js';
35
35
  import { SCHEDULE_BUSY_SAY } from '../summary-words.js';
36
36
  import { providerKeys } from './spawn.js';
37
+ import { pageAddressesOf, pageAddressRefusal } from '../pagefetch.js';
37
38
  import { readModelRecord, writeModelRecord } from '../flowmodel.js';
38
39
 
39
40
  /** M6 amendment 1: the sentence the page shows and the sign route refuses with, for a job with a run running or waiting at its ask. @param {string} runId */
@@ -89,22 +90,22 @@ export function createFlowsDoor(opts) {
89
90
  };
90
91
  }
91
92
 
92
- /** The source paths one run froze: role -> path, from that run's `inputs.json`. Blank = none. @param {string} runDir @param {string[]} roles */
93
- function sourcesOf(runDir, roles) {
93
+ /** The source paths one run froze: role -> path, from that run's `inputs.json`. Blank = none. @param {string} runDir @param {string[]} roles @param {Record<string, string>} [pages] M10 am3: page role -> signed address */
94
+ function sourcesOf(runDir, roles, pages = {}) {
94
95
  /** @type {Record<string, string>} */
95
- const out = Object.fromEntries(roles.map((r) => [r, '']));
96
+ const out = Object.fromEntries(roles.map((r) => [r, pages[r] ?? ''])); // M10 am3: a page input shows its signed address, whatever a run froze
96
97
  if (runDir === '') return out;
97
98
  const f = readFileInside(runDir, 'inputs.json');
98
99
  let rows = [];
99
100
  try { rows = f.ok ? JSON.parse(f.text) : []; } catch { rows = []; }
100
101
  for (const row of Array.isArray(rows) ? rows : []) {
101
- if (row && typeof row.id === 'string' && roles.includes(row.id) && typeof row.source === 'string') out[row.id] = row.source;
102
+ if (row && typeof row.id === 'string' && roles.includes(row.id) && !Object.hasOwn(pages, row.id) && typeof row.source === 'string') out[row.id] = row.source;
102
103
  }
103
104
  return out;
104
105
  }
105
106
 
106
- /** The source paths the newest run of this flow used: role -> path, from that run's `inputs.json`. Blank = none. @param {string} flowDir @param {string[]} roles */
107
- function lastSources(flowDir, roles) {
107
+ /** The source paths the newest run of this flow used: role -> path, from that run's `inputs.json`. Blank = none. @param {string} flowDir @param {string[]} roles @param {Record<string, string>} [pages] */
108
+ function lastSources(flowDir, roles, pages = {}) {
108
109
  let newest = null;
109
110
  for (const id of listRunIds(flowDir)) {
110
111
  const r = resolveRunDir(flowDir, id);
@@ -113,8 +114,8 @@ export function createFlowsDoor(opts) {
113
114
  try { t = lstatSync(join(r.runDir, 'inputs.json')).mtimeMs; } catch { continue; }
114
115
  if (newest === null || t > newest.t || (t === newest.t && id > newest.id)) newest = { t, id, runDir: r.runDir };
115
116
  }
116
- if (newest === null) return { runId: null, sources: sourcesOf('', roles) };
117
- return { runId: newest.id, sources: sourcesOf(newest.runDir, roles) };
117
+ if (newest === null) return { runId: null, sources: sourcesOf('', roles, pages) };
118
+ return { runId: newest.id, sources: sourcesOf(newest.runDir, roles, pages) };
118
119
  }
119
120
 
120
121
  /** The values one run ran with: the flow's own, with the run's newest signed version laid over (`applyRunValues`). Unreadable = the flow's own. @param {any} read @param {string} name @param {string} runDir */
@@ -140,7 +141,7 @@ export function createFlowsDoor(opts) {
140
141
  if (end === null) continue; // not ended (running, parked, died): neither green nor not green
141
142
  if (end.outcome === 'complete') {
142
143
  green += 1;
143
- passed.push({ runId: id, ...runValuesOf(read, name, r.runDir), sources: sourcesOf(r.runDir, roles) });
144
+ passed.push({ runId: id, ...runValuesOf(read, name, r.runDir), sources: sourcesOf(r.runDir, roles, pageAddressesOf(read.arbiter)) });
144
145
  } else notGreen += 1;
145
146
  if (end.spendComplete === true && Number.isFinite(end.spentUsd) && end.spentUsd >= 0) { spendSum += end.spentUsd; spendN += 1; }
146
147
  if (Number.isFinite(end.wallMs) && end.wallMs > 0) { wallSum += end.wallMs; wallN += 1; }
@@ -220,11 +221,16 @@ export function createFlowsDoor(opts) {
220
221
  /** @type {{field: string, say: string}[]} */
221
222
  const refusals = checked.ok ? [...modelReds] : [...checked.refusals, ...modelReds];
222
223
  if (!checked.ok && checked.status === 409) return reply(409, { refused: 'monthly', say: checked.say });
223
- const rows = runInputRows(body?.inputs);
224
+ // M10 am3: a page input's address is the job's, signed; the page shows it read-only, a blank row is the signed one, and any other address is refused naming the input
225
+ const pages = pageAddressesOf(read.arbiter);
226
+ const rows = runInputRows(body?.inputs).map((r) => (Object.hasOwn(pages, r.role) && r.path === '' ? { ...r, path: pages[r.role] } : r));
224
227
  refusals.push(...checkInputRows(rows));
228
+ rows.forEach((r, n) => {
229
+ if (Object.hasOwn(pages, r.role) && r.path !== pages[r.role]) refusals.push({ field: `inputs.${n}`, say: pageAddressRefusal(r.role, pages[r.role]) });
230
+ });
225
231
  const declared = (read.arbiter.sources ?? []).map((s) => s.role);
226
232
  for (const role of declared) {
227
- if (!rows.some((r) => r.role === role)) refusals.push({ field: 'inputs', say: `This flow needs an input named "${role}". Add it.` });
233
+ if (!Object.hasOwn(pages, role) && !rows.some((r) => r.role === role)) refusals.push({ field: 'inputs', say: `This flow needs an input named "${role}". Add it.` });
228
234
  }
229
235
  rows.forEach((r, n) => {
230
236
  if (r.role !== '' && !declared.includes(r.role)) refusals.push({ field: `inputs.${n}`, say: `This flow has no input named "${r.role}" (it takes: ${declared.join(', ') || 'none'}).` });
@@ -240,7 +246,7 @@ export function createFlowsDoor(opts) {
240
246
  flow, flowSignatureHash: read.signature.flow, runId: null, version: 0, values,
241
247
  });
242
248
  return {
243
- ok: /** @type {true} */ (true), flow, read, declared, rows, runId, values, differs: checked.differs || runModel !== null, hash, newPick, flowDir: join(realRoot, flow), planFrom,
249
+ ok: /** @type {true} */ (true), flow, read, declared, rows: declared.map((role) => rows.find((r) => r.role === role) ?? { role, path: pages[role] }), runId, values, differs: checked.differs || runModel !== null, hash, newPick, flowDir: join(realRoot, flow), planFrom,
244
250
  };
245
251
  }
246
252
 
@@ -289,10 +295,10 @@ export function createFlowsDoor(opts) {
289
295
  function entryFor(realRoot, name, read, left) {
290
296
  const roles = (read.arbiter.sources ?? []).map((s) => s.role);
291
297
  const flowDir = join(realRoot, name);
292
- const last = lastSources(flowDir, roles);
298
+ const last = lastSources(flowDir, roles, pageAddressesOf(read.arbiter));
293
299
  const { passed, stats } = runsOf(flowDir, name, read, roles);
294
300
  return {
295
- flow: name, capUsd: read.arbiter.capUsd, roles, nextRunId: nextRunId(flowDir), lastRunId: last.runId, lastSources: last.sources, leftThisMonth: left,
301
+ flow: name, capUsd: read.arbiter.capUsd, roles, pages: pageAddressesOf(read.arbiter), nextRunId: nextRunId(flowDir), lastRunId: last.runId, lastSources: last.sources, leftThisMonth: left,
296
302
  runs: passed, stats,
297
303
  ...formFacts(read, home, flowDir),
298
304
  // M6 am5/am6: the job as the card Reuse workflow opens (`ok:true, card`), or why the card cannot hold it (`ok:false, say`). Nothing blocks it: a reuse never changes the job it is opened from.
@@ -411,7 +417,7 @@ export function createFlowsDoor(opts) {
411
417
  return {
412
418
  status: 200,
413
419
  body: {
414
- ok: true, flow: entryFor(realRoot, flow, read, leftThisMonth()), pick: { runId, ...runValuesOf(read, flow, rr.runDir), sources: sourcesOf(rr.runDir, roles) },
420
+ ok: true, flow: entryFor(realRoot, flow, read, leftThisMonth()), pick: { runId, ...runValuesOf(read, flow, rr.runDir), sources: sourcesOf(rr.runDir, roles, pageAddressesOf(read.arbiter)) },
415
421
  },
416
422
  };
417
423
  },
@@ -31,7 +31,7 @@ import { loadCatalogue } from '../catalogue.js';
31
31
  import { scrub } from '../authoring.js';
32
32
  import { readPidRows } from '../books.js';
33
33
  import {
34
- PANEL_STARTS_DIR, checkRunId, claimRunId, nextRunId, readFileInside, readdirInside, resolveRunDir, runOwnsPlan, copyRunPlan, RUN_PLAN_MARKER,
34
+ PANEL_STARTS_DIR, checkRunId, claimRunId, freeRunId, readFileInside, readdirInside, resolveRunDir, runOwnsPlan, copyRunPlan, RUN_PLAN_MARKER,
35
35
  } from '../flow.js';
36
36
  import { booksFresh, runLiveness } from '../liveness.js';
37
37
  import { dropUnstartedValues, writeRunValues } from '../runvalues.js';
@@ -146,10 +146,8 @@ export function createStarter(opts) {
146
146
  if (!planRun) {
147
147
  const flowDir = join(realpathSync(root), flow);
148
148
  if (runId === '') {
149
- const next = nextRunId(flowDir);
150
- const r = resolveRunDir(flowDir, next);
149
+ const r = freeRunId(flowDir); // the decider claimRunId uses: a stray file under a run name is skipped, not refused
151
150
  if (!r.ok) return { status: 400, body: { ok: false, refused: 'run-id', say: `${r.red.replace(/^run: /, '')}.` } };
152
- if (existsSync(r.runDir)) return { status: 400, body: { ok: false, refused: 'run-id', say: `There is already a run "${next}" of this flow. Use a new run id.` } };
153
151
  } else {
154
152
  const run = checkRun(flow, runId);
155
153
  if (!run.ok) return { status: 400, body: { ok: false, refused: 'run-id', say: run.say } };
@@ -32,6 +32,7 @@ import { scheduleHead, scheduledWords } from '../summary-words.js';
32
32
  import { armTrigger, nextSlot, readRows, validateSchedule } from '../trigger-clock.js';
33
33
  import { checkTarget, createFileTrigger } from '../trigger-files.js';
34
34
  import { readModelRecord } from '../flowmodel.js';
35
+ import { pageAddressesOf, pageAddressRefusal } from '../pagefetch.js';
35
36
  import {
36
37
  carryQueue, dropQueue, finishCarry, isArmed, ledgerOf, readSchedule, recordCancelled, removeSchedule, sameTarget, sigOf, writeSchedule,
37
38
  } from '../schedule.js';
@@ -168,6 +169,9 @@ export function createTriggerDoor(opts) {
168
169
  if (trigger !== null && !hasGreenRunForJob(flowDir)) return reply(409, { refused: 'no-green-run', say: NO_GREEN_SAY });
169
170
  // M9 am20 item 3: neither Cancel nor a new schedule is refused because a run is starting, working or waiting: a run carries on from its own copy and
170
171
  // keeps its own signed values; the next fire uses the new schedule. (A schedule never touches the job, so there is nothing for a run to collide with.)
172
+ if (trigger !== null && 'role' in trigger && Object.hasOwn(pageAddressesOf(read.arbiter), trigger.role)) {
173
+ return reply(400, { refused: 'bad-trigger', say: `The input "${trigger.role}" is a web page, not a file, so no file arrival can start a run from it. Nothing was changed.` }); // M10 am3
174
+ }
171
175
  if (trigger !== null && 'role' in trigger) {
172
176
  try {
173
177
  checkTarget(trigger.kind === 'new-file' ? 'new' : 'updated', trigger.kind === 'new-file' ? trigger.folder : trigger.path);
@@ -203,13 +207,16 @@ export function createTriggerDoor(opts) {
203
207
  scheduledDestination = body.destination.trim();
204
208
  }
205
209
  if (Array.isArray(body?.inputs)) {
206
- const rows = runInputRows(body.inputs);
210
+ // M10 am3: a page input's address is the job's, signed: a blank row is the signed one, any other address is refused naming the input
211
+ const pages = pageAddressesOf(read.arbiter);
212
+ const rows = runInputRows(body.inputs).map((r) => (Object.hasOwn(pages, r.role) && r.path === '' ? { ...r, path: pages[r.role] } : r));
207
213
  const declared = roles;
208
214
  const bad = [...checkInputRows(rows)];
209
- for (const role of declared) if (!rows.some((r) => r.role === role)) bad.push({ field: 'inputs', say: `This flow needs an input named "${role}". Add it.` });
215
+ rows.forEach((r, n) => { if (Object.hasOwn(pages, r.role) && r.path !== pages[r.role]) bad.push({ field: `inputs.${n}`, say: pageAddressRefusal(r.role, pages[r.role]) }); });
216
+ for (const role of declared) if (!Object.hasOwn(pages, role) && !rows.some((r) => r.role === role)) bad.push({ field: 'inputs', say: `This flow needs an input named "${role}". Add it.` });
210
217
  for (const r of rows) if (!declared.includes(r.role)) bad.push({ field: 'inputs', say: `This flow has no input named "${r.role}" (it takes: ${declared.join(', ') || 'none'}).` });
211
218
  if (bad.length > 0) return reply(400, { refused: 'bad-inputs', say: `${bad[0].say} Nothing was changed.`, refusals: bad });
212
- scheduledInputs = declared.map((role) => ({ role, path: /** @type {{path: string}} */ (rows.find((r) => r.role === role)).path }));
219
+ scheduledInputs = declared.map((role) => ({ role, path: Object.hasOwn(pages, role) ? pages[role] : /** @type {{path: string}} */ (rows.find((r) => r.role === role)).path }));
213
220
  }
214
221
  }
215
222
  // M6 am9: the schedule uses the plan of the run it was set from. The workflow's own plan = nothing to bind; a different kept plan is verified now and
@@ -399,7 +406,9 @@ export function createTriggerDoor(opts) {
399
406
  let last = flowsDoor.lastSourcesOf(flow, roles).sources;
400
407
  if (schedule.inputs !== null) last = { ...last, ...Object.fromEntries(schedule.inputs.map((r) => [r.role, r.path])) };
401
408
  const sources = [];
409
+ const pages = pageAddressesOf(read.arbiter);
402
410
  for (const role of roles) {
411
+ if (Object.hasOwn(pages, role)) { sources.push({ role, path: pages[role] }); continue; } // M10 am3: a page input is its signed address, never an earlier run's or an arriving file
403
412
  const p = 'role' in trigger && trigger.role === role && cause.kind === 'file' ? cause.path : last[role];
404
413
  if (!p) return done({ outcome: 'refused', why: `There is no earlier run of this job to take the input "${role}" from. Run it by hand once with that input. Nothing started.` });
405
414
  try { sources.push({ role, path: realpathSync(p) }); } catch { return done({ outcome: 'refused', why: `The input "${role}" is not there (${p}). Nothing started.` }); }
@@ -485,7 +494,8 @@ export function createTriggerDoor(opts) {
485
494
  from: sc ? sc.from : null,
486
495
  model: sc && sc.model ? sc.model.model : (rec ? rec.model : null),
487
496
  destination: sc && sc.destination ? sc.destination : (read.ok ? flowValues(read.arbiter).destination : null),
488
- inputs: sources.map((p) => basename(String(p))),
497
+ // M10: a page input shows its FULL signed address (the page cuts it with an ellipsis, the whole on hover); a file shows its name
498
+ inputs: sources.map((p) => (Object.values(read.ok ? pageAddressesOf(read.arbiter) : {}).includes(String(p)) ? String(p) : basename(String(p)))),
489
499
  fires: base.sig === null ? [] : readOutcomes(flowDir).filter((o) => o.sig === base.sig),
490
500
  allFires: readOutcomes(flowDir), // M9 am9 item 4: the Audit's `tries` span every signing
491
501
  };
package/src/panel/data.js CHANGED
@@ -38,11 +38,14 @@ import {
38
38
  import { readSpendRows } from '../provider.js';
39
39
  import { applyRunValues, parseWaitMs, pickRunValues, VALUES_FILE_RE } from '../runvalues.js';
40
40
  import { readSetup } from '../setup.js';
41
- import { checkedLines, notCheckedBlock, NOT_CHECKED_LABEL } from '../checked.js';
41
+ import { checkedLines, notCheckedView, NOT_CHECKED_LABEL } from '../checked.js';
42
+ import { csvRolesOf, askSheetCard } from '../sheetblock.js';
43
+ import { readSheetChecks } from '../sheet-record.js';
42
44
  import {
43
45
  NO_COPY_SAY, catchUpWords, endedLineWords, endedWords, needsLeftWords, nextInWords, nextTimeWords, scheduleAuditWords, scheduleBlockWords, scheduleFieldWords, scheduledNextFor, scheduledWords, startedWords,
44
46
  } from '../summary-words.js';
45
47
  import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
48
+ import { isResultRun, checkTypeOf, buildResult, downloadOf } from './result.js';
46
49
  import { thinkingRuleWords, thinkingTryWords } from '../thinking.js';
47
50
  import { readRunThinking } from '../flowmodel.js';
48
51
  import {
@@ -1769,6 +1772,9 @@ export function getRunDetail({
1769
1772
  needsYou: (({ tag, removable }) => ({ tag, removable }))(needsYouOf({
1770
1773
  runDir: run.runDir, ctx, glyph, controls: runControls(ctx, glyph, label), nowMs: now(), reopenAt: reopenableAt(run.runDir, ctx),
1771
1774
  })),
1775
+ // M10 am4: the Result tab shows for a job that reads a page, a CSV or a .docx; `checkType` is its distinct close classes (the tab's top card)
1776
+ hasResult: isResultRun(ctx.arbiter),
1777
+ checkType: ctx.flowRead.ok ? checkTypeOf(ctx.flowRead.declaration) : '\u2014',
1772
1778
  // M9 piece 6: the block at the top of the run page (ENDED / NEXT, SCHEDULED / NEXT), words set by code
1773
1779
  summary: runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }),
1774
1780
  resume: ctx.resume,
@@ -1881,6 +1887,7 @@ export function getDraftBlock(flowDir, runDir) {
1881
1887
  else if (r.kind === 'startover') happened.push(r.verdict === 'green' ? `starting over${retry(r)}` : 'start over red');
1882
1888
  else if (r.kind === 'revise') happened.push(r.verdict === 'red' ? 'revise red' : `revising${retry(r)}`);
1883
1889
  else if (r.kind === 'redraft') happened.push(r.verdict === 'red' ? 'redraft red' : `redrafting with your answers${retry(r)}`);
1890
+ else if (r.kind === 'human') happened.push('your answer');
1884
1891
  else if (r.kind === 'sign') happened.push(`signed (${r.signedBy ?? 'you'})`);
1885
1892
  if (r.kind === 'card') {
1886
1893
  const c = r.card && typeof r.card === 'object' ? r.card : {};
@@ -1888,6 +1895,8 @@ export function getDraftBlock(flowDir, runDir) {
1888
1895
  typeof c.inputs === 'string' && c.inputs.trim() ? `inputs: ${c.inputs.trim().replace(/\n+/g, ' / ')}` : null, `job: ${String(c.job ?? '').trim().replace(/\n+/g, ' / ')}`].filter(Boolean).join(' · ');
1889
1896
  rows.push(human(r, n, { action: 'card (you)', gap }));
1890
1897
  } else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
1898
+ // M10 am2 item 4: a question the page look raised and your answer, under the drafting step, in bareloop's words (`you were asked:` / `you said:`)
1899
+ else if (r.kind === 'human') rows.push(human(r, n, { action: `you were asked: ${r.question}`, gap: `you said: ${r.answer}` }));
1891
1900
  else if (r.kind === 'draft') { rows.push(model(r, n, 'draft')); rows.push(...tryRows(r, n)); }
1892
1901
  else if (r.kind === 'change') { rows.push(model(r, n, `change ${r.n}`)); rows.push(...tryRows(r, n)); }
1893
1902
  else if (r.kind === 'startover') { rows.push(model(r, n, 'start over')); rows.push(...tryRows(r, n)); }
@@ -2017,8 +2026,8 @@ export function getRunAudit({
2017
2026
  * M6: a sign row that names another signing than the job being shown (`flowHash`) is not this job's record: `recorded:false`, never the new job's words.
2018
2027
  * @param {any} declaration @param {Array<{line:number, ttlMs?:number}>} asks @param {string} flowDir @param {string|null} [flowHash] the signature hash of the job being shown
2019
2028
  */
2020
- function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
2021
- const lines = checkedLines(declaration, { askLines: asks.map((x) => x.line) });
2029
+ function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /** @type {any[]|undefined} */ (undefined), csvRoles = /** @type {string[]} */ ([])) {
2030
+ const lines = checkedLines(declaration, { askLines: asks.map((x) => x.line), lines: jobLines, csvRoles });
2022
2031
  const declSteps = Array.isArray(declaration?.steps) ? declaration.steps : [];
2023
2032
  const steps = declSteps.map((st, i) => {
2024
2033
  const ak = asks.find((x) => x.line === st.fromLine);
@@ -2030,6 +2039,7 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
2030
2039
  mayDo: Array.isArray(st.primitives) ? st.primitives : [],
2031
2040
  check: lines[i].sentences,
2032
2041
  checkClass: lines[i].class,
2042
+ sheet: lines[i].sheet ?? null,
2033
2043
  ask: !!ak,
2034
2044
  waitMs: ak && typeof ak.ttlMs === 'number' ? ak.ttlMs : null,
2035
2045
  };
@@ -2042,7 +2052,8 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
2042
2052
  const ofThisJob = !!signRow && (typeof signRow.flowHash !== 'string' || flowHash === null || signRow.flowHash === flowHash);
2043
2053
  const nc = ofThisJob ? signRow?.notChecked : undefined;
2044
2054
  const recorded = !!nc && Array.isArray(nc.items);
2045
- return { steps, notChecked: { label: NOT_CHECKED_LABEL, items: recorded ? notCheckedBlock(nc.items).items : [], recorded } };
2055
+ const view = recorded ? notCheckedView(nc.items, declaration) : { items: [], readNotes: [] };
2056
+ return { steps, notChecked: { label: NOT_CHECKED_LABEL, items: view.items, readNotes: view.readNotes, recorded } };
2046
2057
  }
2047
2058
 
2048
2059
  /**
@@ -2138,7 +2149,7 @@ export function getRunJob({
2138
2149
  guardrails: flowRead.lines
2139
2150
  .filter((l) => typeof l.guardrail === 'string' && l.guardrail.length > 0)
2140
2151
  .map((l) => ({ line: l.n, guardrail: l.guardrail })),
2141
- plan: buildJobPlan(flowRead.declaration, asks, run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null),
2152
+ plan: buildJobPlan(flowRead.declaration, asks, run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null, flowRead.lines, csvRolesOf(a)),
2142
2153
  signature: (sig && typeof sig.signedBy === 'string' && typeof sig.signedAt === 'string' && typeof sig.flow === 'string')
2143
2154
  ? { signedBy: sig.signedBy, signedAt: sig.signedAt, hash: sig.flow }
2144
2155
  : null,
@@ -2148,6 +2159,79 @@ export function getRunJob({
2148
2159
  };
2149
2160
  }
2150
2161
 
2162
+ /**
2163
+ * M10 am4: what `getRunResult` and `getRunDownload` both need of one run: its books and the signed job it ran. `null` = no such run, the job is
2164
+ * unreadable, or it is not an M10 job (the route answers 404 "no such run, or it has no result tab").
2165
+ * @param {{root: string, flow: string, runId: string, catalogue: any}} a
2166
+ */
2167
+ function resultContext({
2168
+ root, flow, runId, catalogue,
2169
+ }) {
2170
+ const run = resolveRunPath(root, flow, runId);
2171
+ if (!run.ok || !readdirInside(run.flowDir, 'runs').includes(runId)) return null; // the gateway lists real, non-symlink run folders only
2172
+ const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue);
2173
+ if (!ctx.flowRead.ok || !isResultRun(ctx.arbiter)) return null;
2174
+ return { run, ctx };
2175
+ }
2176
+
2177
+ /**
2178
+ * M10 am5 item 2: does this run wait for the person's accept? The Ask tab's own rule (`answerControls` kind "doors"): the newest ask is open and either has no saved
2179
+ * answer or its saved answer could not be read. Read from `getRunAsks`, the Ask tab's one reader, so the two tabs can never disagree.
2180
+ * @param {ReturnType<typeof getRunAsks>} asks @returns {{askId: string, draftNo: number}|null}
2181
+ */
2182
+ function resultDoorOf(asks) {
2183
+ if (asks === null) return null;
2184
+ const block = asks.blocks.at(-1);
2185
+ const ask = block?.current;
2186
+ if (!ask || ask.open !== true) return null;
2187
+ if (asks.resume && asks.resume.askId === ask.askId && asks.resume.state !== 'broken') return null;
2188
+ return { askId: ask.askId, draftNo: block.draftNo };
2189
+ }
2190
+
2191
+ /**
2192
+ * `GET /api/runs/:flow/:runId/result` — the Result tab (M10 am4). The Not checked list is the Job tab's own (`buildJobPlan`), never a second spelling.
2193
+ * @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, now?: () => number}} a
2194
+ * @returns {any|null}
2195
+ */
2196
+ export function getRunResult({
2197
+ root, flow, runId, catalogue, resumeAttempt, now,
2198
+ }) {
2199
+ const got = resultContext({
2200
+ root, flow, runId, catalogue,
2201
+ });
2202
+ if (!got) return null;
2203
+ const { run, ctx } = got;
2204
+ const sig = ctx.flowRead.signature;
2205
+ const plan = buildJobPlan(ctx.flowRead.declaration, ctx.arbiter.asks ?? [], run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null, ctx.flowRead.lines, csvRolesOf(ctx.arbiter));
2206
+ return buildResult({
2207
+ flow, runId, runDir: run.runDir, root, flowRead: ctx.flowRead, arbiter: ctx.arbiter, historyRow: ctx.historyRow, auditRows: ctx.auditRows, logJson: ctx.logJson, notChecked: plan.notChecked.items, readNotes: plan.notChecked.readNotes,
2208
+ setupRows: (() => { const st = readSetup(run.flowDir); return st.present ? st.rows : []; })(),
2209
+ door: resultDoorOf(getRunAsks({
2210
+ root, flow, runId, catalogue, resumeAttempt, now,
2211
+ })),
2212
+ });
2213
+ }
2214
+
2215
+ /**
2216
+ * `GET /api/runs/:flow/:runId/download?i=<n>` (M10 am4): one saved file, or why not.
2217
+ * @param {{root: string, flow: string, runId: string, catalogue: any, index: unknown}} a
2218
+ * @returns {ReturnType<typeof downloadOf>}
2219
+ */
2220
+ export function getRunDownload({
2221
+ root, flow, runId, catalogue, index,
2222
+ }) {
2223
+ const got = resultContext({
2224
+ root, flow, runId, catalogue,
2225
+ });
2226
+ if (!got) return { ok: false, code: 404, error: 'no such run, or it has no result tab' };
2227
+ return downloadOf({
2228
+ index,
2229
+ ctx: {
2230
+ arbiter: got.ctx.arbiter, declaration: got.ctx.flowRead.declaration, runDir: got.run.runDir, root, flow, runId, auditRows: got.ctx.auditRows,
2231
+ },
2232
+ });
2233
+ }
2234
+
2151
2235
  // ---------------------------------------------------------------------------
2152
2236
  // M4a Amendment M4a-1 — the panel's Inbox/Ask surface (docs/wiki/the-module-
2153
2237
  // ladder.md, "M4a" section, signed 2026-09-27). Every stop (parked ask) this
@@ -2256,6 +2340,7 @@ function flattenEvidence(evidence) {
2256
2340
  draft: evidence.draft ? evidence.draft.text : null,
2257
2341
  unjudged: evidence.unjudged,
2258
2342
  why: evidence.why,
2343
+ ...(evidence.claims ? { claims: evidence.claims } : {}),
2259
2344
  };
2260
2345
  }
2261
2346
 
@@ -2605,7 +2690,18 @@ export function getRunAsks({
2605
2690
  }
2606
2691
  }
2607
2692
  const openAskJson = hasHistoryRow ? null : readAsk(run.runDir);
2608
- const asks = ordered.map((ask, i) => ({
2693
+ // M10b am4: an ask whose evidence is a sheet step's claim boxes carries that step's block and answer (the Result tab's block), and loses the "unrecognised shape" line
2694
+ const sheetRecord = ordered.some((a) => a.evidence?.claims) ? readSheetChecks(run.runDir) : null;
2695
+ const sheetArbiter = flowRead.ok ? flowRead.arbiter : null;
2696
+ const withSheet = (/** @type {any} */ ask) => {
2697
+ const { claims, ...ev } = ask.evidence ?? {};
2698
+ if (!claims) return ask;
2699
+ const card = flowRead.ok ? askSheetCard({ claims, declaration: flowRead.declaration, lines: flowRead.lines, csvRoles: csvRolesOf(sheetArbiter), record: sheetRecord }) : null;
2700
+ if (card === null) return { ...ask, evidence: ev };
2701
+ const { why: _gone, ...rest } = ev;
2702
+ return { ...ask, evidence: { ...rest, sheet: card } };
2703
+ };
2704
+ const asks = ordered.map(withSheet).map((ask, i) => ({
2609
2705
  ...ask,
2610
2706
  ...deriveAskOpenFields(ask, hasHistoryRow, resume),
2611
2707
  reopen: reopenOffer(ask, openAskJson, resume, readSavedAnswer(run.runDir)?.askId === ask.askId),