fwdloop 0.36.0 → 0.37.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 (98) hide show
  1. package/README.md +1 -1
  2. package/bin/fwdloop +5 -2
  3. package/package.json +3 -3
  4. package/src/action-stop.js +1 -1
  5. package/src/auditchecks.js +41 -9
  6. package/src/authoring.js +74 -16
  7. package/src/blockasks.js +10 -12
  8. package/src/blockassemble.js +49 -43
  9. package/src/blockdraft.js +4 -2
  10. package/src/blockpick.js +10 -0
  11. package/src/canrun.js +2 -1
  12. package/src/cardlist.js +28 -5
  13. package/src/checkblock.js +610 -64
  14. package/src/checked.js +28 -33
  15. package/src/checklistsign.js +2 -1
  16. package/src/checklook.js +45 -0
  17. package/src/checkrows.js +202 -0
  18. package/src/cited-record.js +2 -2
  19. package/src/citedcheck.js +53 -12
  20. package/src/citedwords.js +7 -4
  21. package/src/closers.js +49 -2
  22. package/src/declaration.js +26 -4
  23. package/src/drafter.js +85 -61
  24. package/src/factwords.js +7 -4
  25. package/src/globprefix.js +26 -0
  26. package/src/model-step.js +22 -4
  27. package/src/pageask.js +0 -3
  28. package/src/pagedropwords.js +3 -11
  29. package/src/pagedry.js +75 -1
  30. package/src/pagefetch.js +11 -6
  31. package/src/pagelook.js +2 -1
  32. package/src/pagerules.js +8 -2
  33. package/src/panel/author.js +9 -3
  34. package/src/panel/data.js +3 -2
  35. package/src/panel/index.html +143 -33
  36. package/src/panel/result.js +34 -1
  37. package/src/pickrecord.js +14 -0
  38. package/src/planrebuild.js +55 -19
  39. package/src/ratelimit.js +117 -0
  40. package/src/report.js +14 -3
  41. package/src/rowresults.js +111 -0
  42. package/src/rubricstep.js +65 -2
  43. package/src/runner.js +38 -5
  44. package/src/shapebuild.js +281 -0
  45. package/src/shapelook.js +91 -0
  46. package/src/shapemenu.js +64 -0
  47. package/src/shaperesult.js +104 -0
  48. package/src/shaperows.js +263 -0
  49. package/src/shapewords.js +140 -0
  50. package/src/sheetbuild.js +41 -29
  51. package/src/sheetclaims.js +1 -1
  52. package/src/sheetrows.js +10 -64
  53. package/src/ticketrows.js +1 -1
  54. package/src/try-checks.js +39 -6
  55. package/src/types.js +1 -0
  56. package/src/whole-job.js +24 -8
  57. package/types/action-stop.d.ts +1 -1
  58. package/types/auditchecks.d.ts +13 -2
  59. package/types/authoring.d.ts +20 -2
  60. package/types/blockasks.d.ts +6 -10
  61. package/types/blockassemble.d.ts +13 -13
  62. package/types/blockdraft.d.ts +3 -2
  63. package/types/blockpick.d.ts +4 -0
  64. package/types/cardlist.d.ts +18 -2
  65. package/types/checkblock.d.ts +278 -28
  66. package/types/checked.d.ts +15 -6
  67. package/types/checklook.d.ts +36 -0
  68. package/types/checkrows.d.ts +119 -0
  69. package/types/citedcheck.d.ts +4 -2
  70. package/types/closers.d.ts +10 -1
  71. package/types/drafter.d.ts +8 -4
  72. package/types/globprefix.d.ts +5 -0
  73. package/types/model-step.d.ts +43 -2
  74. package/types/pageask.d.ts +0 -1
  75. package/types/pagedropwords.d.ts +0 -1
  76. package/types/pagedry.d.ts +27 -0
  77. package/types/pagefetch.d.ts +3 -2
  78. package/types/pagerules.d.ts +4 -0
  79. package/types/panel/result.d.ts +16 -1
  80. package/types/pickrecord.d.ts +10 -0
  81. package/types/ratelimit.d.ts +59 -0
  82. package/types/report.d.ts +2 -1
  83. package/types/rowresults.d.ts +28 -0
  84. package/types/rubricstep.d.ts +21 -0
  85. package/types/runner.d.ts +3 -1
  86. package/types/shapebuild.d.ts +97 -0
  87. package/types/shapelook.d.ts +76 -0
  88. package/types/shapemenu.d.ts +40 -0
  89. package/types/shaperesult.d.ts +40 -0
  90. package/types/shaperows.d.ts +102 -0
  91. package/types/shapewords.d.ts +43 -0
  92. package/types/sheetbuild.d.ts +31 -13
  93. package/types/sheetclaims.d.ts +1 -0
  94. package/types/sheetrows.d.ts +5 -36
  95. package/types/ticketrows.d.ts +1 -1
  96. package/types/try-checks.d.ts +2 -1
  97. package/types/types.d.ts +4 -0
  98. package/types/whole-job.d.ts +20 -4
package/README.md CHANGED
@@ -36,7 +36,7 @@ Like a CNC machine, fwdloop builds the thing that does the work, then lets a gau
36
36
 
37
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
38
 
39
- **Verification.** The check sits outside the agent's loop: code decides, built on bareguard. 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.
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
40
 
41
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.
42
42
 
package/bin/fwdloop CHANGED
@@ -52,7 +52,7 @@ 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
54
  import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal } from '../src/authoring.js';
55
- import { readRecordFile, readRowChoices, readSheetDropped, readColumns } from '../src/pickrecord.js';
55
+ import { readRecordFile, readRowChoices, readSheetDropped, readShapeDropped, readColumns } from '../src/pickrecord.js';
56
56
  import { userInfo } from 'node:os';
57
57
  import { pageAddressesOf, pageAddressRefusal } from '../src/pagefetch.js';
58
58
  import { ticketListsOf, isTicketNumber, TICKET_NUMBER_WORDS } from '../src/ticket-shape.js';
@@ -939,11 +939,13 @@ async function cmdDraft(rest) {
939
939
  let carriedChoices;
940
940
  /** @type {any[]|undefined} */
941
941
  let carriedSheetDropped;
942
+ /** @type {any[]|undefined} */
943
+ let carriedShapeDropped;
942
944
  let carriedColumns;
943
945
  if (values.carry !== undefined) {
944
946
  const abs = resolve(values.carry);
945
947
  const g = readFileInside(dirname(abs), basename(abs));
946
- if (g.ok) { carriedPicks = readRecordFile(abs) ?? undefined; carriedChoices = readRowChoices(abs) ?? undefined; carriedSheetDropped = readSheetDropped(abs) ?? undefined; carriedColumns = readColumns(abs) ?? undefined; } // a missing or unreadable record is no record: every guardrail is asked, as before
948
+ if (g.ok) { carriedPicks = readRecordFile(abs) ?? undefined; carriedChoices = readRowChoices(abs) ?? undefined; carriedSheetDropped = readSheetDropped(abs) ?? undefined; carriedShapeDropped = readShapeDropped(abs) ?? undefined; carriedColumns = readColumns(abs) ?? undefined; } // a missing or unreadable record is no record: every guardrail is asked, as before
947
949
  }
948
950
 
949
951
  let injected = {};
@@ -1010,6 +1012,7 @@ async function cmdDraft(rest) {
1010
1012
  ...(carriedPicks === undefined ? {} : { carriedPicks }),
1011
1013
  ...(carriedChoices === undefined ? {} : { carriedChoices }),
1012
1014
  ...(carriedSheetDropped === undefined ? {} : { carriedSheetDropped }),
1015
+ ...(carriedShapeDropped === undefined ? {} : { carriedShapeDropped }),
1013
1016
  ...(carriedColumns === undefined ? {} : { carriedColumns }),
1014
1017
  draftThinking: values.thinking === true ? 'on' : 'off',
1015
1018
  flowType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwdloop",
3
- "version": "0.36.0",
3
+ "version": "0.37.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",
@@ -50,8 +50,8 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "bare-agent": "^0.59.0",
53
- "barebrowse": "^0.26.0",
54
- "bareguard": "^0.36.0",
53
+ "barebrowse": "^0.31.0",
54
+ "bareguard": "^0.37.0",
55
55
  "litectx": "^0.32.0"
56
56
  },
57
57
  "devDependencies": {
@@ -32,7 +32,7 @@ export function lastAcceptedSha(steps, i, acceptedAskEmitsThisRun) {
32
32
  }
33
33
 
34
34
  /**
35
- * am11a 1/2: the wait of the stop. The LAST Ask's own wait when the job has an Ask before the action; else the card's Ask wait kept in the run's signed values (`arbiter.actionWaitMs`), else 1h.
35
+ * am11a 1/2: the wait of the stop. The LAST Ask's own wait when the job has an Ask before the action; else the card's Ask wait kept in the run's signed values (`sendSlot.waitMs`, src/runvalues.js), else 1h.
36
36
  * @param {{ fromLine: number }[]} steps @param {number} i @param {Map<number, {ttlMs: number}>} askLines @param {number|undefined} actionWaitMs
37
37
  */
38
38
  export function stopWaitMs(steps, i, askLines, actionWaitMs) {
@@ -1,11 +1,13 @@
1
1
  // M16 item 5 (docs/wiki/the-module-ladder.md, "M16"): the Audit's "Checks" fold, the card's own sections (Checks, Not checked, Always checked), each row with its tag and, after the run, its recorded result.
2
2
  // borrowed-from: bareloop src/panel/jobplan.js@v0.56.0 (3383cce) (auditChecksOf: the sections, the row shape {text, by, result}, a row no verdict was recorded for is "none", never "passed")
3
+ // borrowed-from: bareloop src/panel/jobplan.js@v0.61.0 (fc56e1f3) auditChecksOf: `lines` (one block per job line: its checks and its Not checked rows) and `jobNotChecked` (the Not checked rows no line owns), ported onto fwdloop's diary reader
3
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
4
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).
5
6
  import { listLinesOf } from './checklistsign.js';
6
7
  import { listPartRows, notCheckedView } from './checked.js';
7
8
  import { EVERY_STEP, EVERY_STEP_TEXTS } from './try-checks.js';
8
9
  import { sheetRowsOf } from './sheetrows.js';
10
+ import { splitNotChecked, ncRowsOf } from './checklook.js';
9
11
 
10
12
  /** the words of a row no result was recorded for: never "passed" */
11
13
  export const AUDIT_NO_RESULT = 'no result recorded';
@@ -13,8 +15,9 @@ export const AUDIT_NO_RESULT = 'no result recorded';
13
15
  /**
14
16
  * @param {any} declaration the signed plan @param {any[]} diary the run's `checks` rows (src/diary.js readChecks) @param {{items?: string[], by?: Record<string, string>}|null} notChecked the sign row's Not-checked block
15
17
  * @param {{lines?: any[], csvRoles?: string[]}} [sheet] the signed job lines and CSV roles: a plan whose list has sheet rows (M16 am4) shows them here, tagged by where each comes from (hamr 2026-11-14)
16
- * @returns {{checks: AuditCheckRow[], notChecked: AuditCheckRow[], readNotes: string[], always: AuditCheckRow[]}|null} null for a plan with no list (it keeps its own Audit rows)
17
- * @typedef {{text: string, by: 'you'|'agent'|'default'|null, result: 'passed'|'failed'|'none'|'not-checked'}} AuditCheckRow
18
+ * @returns {{checks: AuditCheckRow[], notChecked: AuditCheckRow[], readNotes: string[], always: AuditCheckRow[], lines: AuditLine[], jobNotChecked: AuditCheckRow[]}|null} null for a plan with no list (it keeps its own Audit rows)
19
+ * @typedef {{n: number, text: string, checks: AuditCheckRow[], notChecked: AuditCheckRow[]}} AuditLine
20
+ * @typedef {{text: string, by: 'you'|'agent'|'default'|null, result: 'passed'|'failed'|'none'|'not-checked', kind?: 'truth'|'shape'|'file', why?: string}} AuditCheckRow
18
21
  */
19
22
  export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines = [], csvRoles = [] } = {}) {
20
23
  const lines = listLinesOf(declaration);
@@ -25,11 +28,25 @@ export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines
25
28
  const lastTry = (/** @type {any} */ st) => (Array.isArray(diary) ? diary : []).filter((d) => d.step === (st.emits ?? st.goal ?? null)).at(-1);
26
29
  /** @type {AuditCheckRow[]} */
27
30
  const checks = [];
31
+ // the same rows by the job line that owns them, their words without the `line N · ` prefix (S7: one block per line)
32
+ /** @type {{line: number, row: AuditCheckRow}[]} */
33
+ const owned = [];
34
+ // a failed row's reason is the words its check recorded (the diary's `result`); a row that passed or has no record carries none
35
+ const whyOf = (/** @type {any} */ got) => (got !== undefined && !got.ok && typeof got.result === 'string' && got.result !== '' ? { why: got.result } : {});
28
36
  for (const st of steps) {
29
37
  const rec = lastTry(st);
30
- for (const r of listPartRows(declaration, st)) {
31
- const got = rec?.checks?.find((/** @type {any} */ c) => c.part === r.part);
32
- checks.push({ text: `line ${st.fromLine} · ${r.text}`, by: r.by, result: got === undefined ? 'none' : got.ok ? 'passed' : 'failed' });
38
+ for (const r of listPartRows(declaration, st, { lines: Array.isArray(jobLines) ? jobLines : [] })) {
39
+ // M19 am11 item 4: a list line's own rows are recorded by their key (each item field, the count rule); any other row, and a record made before, is read by its part
40
+ const got = rec?.checks?.find((/** @type {any} */ c) => c.key === r.key) ?? rec?.checks?.find((/** @type {any} */ c) => c.key === undefined && c.part === r.part);
41
+ const row = /** @type {AuditCheckRow} */ ({ text: r.text, kind: 'truth', by: r.by, result: got === undefined ? 'none' : got.ok ? 'passed' : 'failed', ...whyOf(got) });
42
+ checks.push({ ...row, text: `line ${st.fromLine} · ${r.text}` });
43
+ owned.push({ line: st.fromLine, row });
44
+ }
45
+ // a red no row owns (a whole-list red): told on its own, never left as passed rows
46
+ for (const c of (rec?.checks ?? []).filter((/** @type {any} */ x) => x.unclaimed === true && !x.ok)) {
47
+ const row = /** @type {AuditCheckRow} */ ({ text: c.text, kind: 'truth', by: null, result: 'failed' });
48
+ checks.push({ ...row, text: `line ${st.fromLine} · ${c.text}` });
49
+ owned.push({ line: st.fromLine, row });
33
50
  }
34
51
  }
35
52
  // a sheet row: its check's words and the `by` of its row; what the run recorded is read by the row's `part`, as for any list row
@@ -37,19 +54,34 @@ export function auditChecksOf(declaration, diary, notChecked, { lines: jobLines
37
54
  const st = (Array.isArray(declaration?.steps) ? declaration.steps : []).find((/** @type {any} */ x) => x?.fromLine === r.line && Array.isArray(x?.close?.sheet));
38
55
  const rec = st ? lastTry(st) : undefined;
39
56
  const got = rec?.checks?.find((/** @type {any} */ c) => c.part === sheetRows?.signed[i].part.part && c.by !== undefined);
40
- checks.push({ text: `line ${r.line} \u00b7 ${r.text}`, by: r.by, result: got === undefined ? 'none' : got.ok ? 'passed' : 'failed' });
57
+ const row = /** @type {AuditCheckRow} */ ({ text: r.text, kind: 'truth', by: r.by, result: got === undefined ? 'none' : got.ok ? 'passed' : 'failed', ...whyOf(got) });
58
+ checks.push({ ...row, text: `line ${r.line} \u00b7 ${r.text}` });
59
+ owned.push({ line: r.line, row });
41
60
  }
42
61
  const by = notChecked?.by ?? {};
43
62
  // M17 am4 (C3): the Audit splits a reading note from Not checked as the card and the Job tab do (src/checked.js notCheckedView)
44
63
  const view = notCheckedView(notChecked?.items ?? [], declaration);
45
64
  /** @type {AuditCheckRow[]} */
46
- const notRows = view.items.map((t) => ({ text: t, by: by[t] === 'you' || by[t] === 'agent' || by[t] === 'default' ? /** @type {'you'|'agent'|'default'} */ (by[t]) : null, result: 'not-checked' }));
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' }));
47
66
  // 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
48
67
  const every = (/** @type {string} */ text) => {
49
68
  const seen = (Array.isArray(diary) ? diary : []).flatMap((d) => (d.checks ?? []).filter((/** @type {any} */ c) => c.source === EVERY_STEP && c.text === text));
50
69
  return seen.length === 0 ? 'none' : seen.every((/** @type {any} */ c) => c.ok) ? 'passed' : 'failed';
51
70
  };
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));
52
72
  /** @type {AuditCheckRow[]} */
53
- const always = EVERY_STEP_TEXTS.map((text) => ({ text, by: /** @type {'default'} */ ('default'), result: every(text) }));
54
- return { checks, notChecked: notRows, readNotes: view.readNotes, always };
73
+ const always = EVERY_STEP_TEXTS.map((text) => ({ text, kind: 'file', by: /** @type {'default'} */ ('default'), result: every(text), ...everyWhy(text) }));
74
+ // 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)
75
+ // a row owned by a line the job text does not carry would be lost from the blocks: then no blocks (`lines` empty) and the page draws the flat groups
76
+ const known = new Set(jobLines.map((/** @type {any} */ l) => l.n));
77
+ const ncAll = ncRowsOf(view.items, by);
78
+ const ncOf = (/** @type {any} */ n) => ({ text: n.text, by: n.by ?? null, result: /** @type {'not-checked'} */ ('not-checked'), ...(n.why ? { why: n.why } : {}) });
79
+ /** @type {AuditLine[]} */
80
+ const lineBlocks = owned.some((o) => !known.has(o.line)) ? [] : jobLines.map((/** @type {any} */ l) => ({
81
+ n: l.n, text: l.text,
82
+ checks: owned.filter((o) => o.line === l.n).map((o) => o.row),
83
+ notChecked: ncAll.filter((n) => n.line === l.n).map(ncOf),
84
+ }));
85
+ const jobNotChecked = ncAll.filter((n) => !known.has(n.line)).map(ncOf);
86
+ return { checks, notChecked: notRows, readNotes: view.readNotes, always, lines: lineBlocks, jobNotChecked };
55
87
  }
package/src/authoring.js CHANGED
@@ -23,9 +23,10 @@ import { draft } from './drafter.js';
23
23
  import { parseSignedText, unsignedAskTtls } from './signed-text.js';
24
24
  import { validateDeclaration, flowTypeOf } from './declaration.js';
25
25
  import { factRows, factSentence, countSentence } from './citedcheck.js';
26
- import { plainWords, labelled, tagged } from './checkwords.js';
27
- import { listLinesOf, partByOf, factByOf, countByOf } from './checklistsign.js';
28
- import { CARD_T } from './checkblock.js';
26
+ import { plainWords, labelled } from './checkwords.js';
27
+ import { listLinesOf, cardLinesOf, partByOf, factByOf, countByOf } from './checklistsign.js';
28
+ import { LOOK, ncRowsOf } from './checklook.js';
29
+ import { EVERY_STEP_TEXTS } from './try-checks.js';
29
30
  import { sheetLineBlocks } from './sheetblock.js';
30
31
  import { loadCatalogue } from './catalogue.js';
31
32
  import { WIRED_VERBS } from './primitives.js';
@@ -42,8 +43,10 @@ import { redactSecrets } from './redact.js';
42
43
  import { sessionPriorSpend, writeDraftSpend } from './draftspend.js';
43
44
  import { writeSetup } from './setup.js';
44
45
  import { RECORD_FILE } from './pickrecord.js';
46
+ import { planMatchesCard, numbersWords } from './checkrows.js';
47
+ import { csvRolesOf } from './sheetblock.js';
45
48
  import { mcpPickHere } from './mcp-pick.js';
46
- import { hitlWords } from './checked.js';
49
+ import { hitlWords, notCheckedView } from './checked.js';
47
50
 
48
51
  export const SPEC_HASH_FILE = 'spec.hash';
49
52
  /** The one folder under the flows root where the panel keeps its draft folders (M4e). Starts with a dot, so it is never a flow name. */
@@ -193,9 +196,21 @@ export function readoutHeadIndexes(text) {
193
196
  return idx;
194
197
  }
195
198
 
199
+ // borrowed-from: bareloop src/authorreadout.js@v0.61.0 (fc56e1f3) readoutGroups (the signed look's groups as readout rows, section 3.7): tag column first, kind word second; an empty group is not told
200
+ /** @param {{checks: {text: string, by?: string|null, kind?: string}[], nc: {text: string, why?: string, by?: string}[], suggested: {text: string, key?: string, dropped?: boolean}[]}} g @returns {string[]} */
201
+ function readoutGroups({ checks, nc, suggested }) {
202
+ const row = (by, kind, text) => ` ${`[${by ?? 'default'}]`.padEnd(9)} ${kind.padEnd(5)} ${text}`;
203
+ const out = [];
204
+ if (checks.length) out.push(` ${LOOK.checked} \u00B7 ${checks.length}`, ...checks.map((c) => row(c.by, c.kind ?? 'truth', c.text)));
205
+ if (nc.length) out.push(` ${LOOK.notChecked} \u00B7 ${nc.length} \u00B7 ${LOOK.notCheckedTail}`, ...nc.map((n) => row(n.by, '', `${n.text}${n.why ? ` \u2014 ${n.why}` : ''}`)));
206
+ if (suggested.length) out.push(` ${LOOK.suggested}`, ...suggested.map((x) => row('agent', /\.shape\./.test(x.key ?? '') ? 'shape' : 'truth', `${x.text}${x.dropped ? ' (you dropped it)' : ''}`)));
207
+ return out;
208
+ }
209
+
196
210
  /** Plain-text readout of what the human is about to sign. Pure. */
197
211
  export function buildReadout({
198
- declaration, arbiter, lines, name, modelId, costUsd, rounds, spendComplete, root,
212
+ declaration, arbiter, lines, name, modelId, costUsd, rounds, spendComplete, root, notChecked = /** @type {string[]} */ ([]), notCheckedBy = /** @type {Record<string, string>} */ ({}), suggested = /** @type {{line: number, text: string, key?: string, dropped?: boolean}[]} */ ([]),
213
+ checkCard = /** @type {{rows: {line: number, by: string, state: string, text: string, kind?: string}[]}|null} */ (null),
199
214
  }) {
200
215
  const out = [];
201
216
  out.push(`${READOUT_HEADER_PREFIX}"${name}"`, '');
@@ -224,11 +239,23 @@ export function buildReadout({
224
239
  out.push('', READOUT_HEADS.steps);
225
240
  const sheetBlocks = sheetLineBlocks({ declaration, lines });
226
241
  const onList = listLinesOf(declaration);
242
+ // borrowed-from: bareloop src/authorreadout.js@v0.61.0 (fc56e1f3) buildReadout (the check rows of a line are the card's rows, one model): M19 am4. A line the card draws a list on takes its CHECKED rows from the saved card (`checkCard`, the page's planOfState rule: the line's built rows in the card's order); a plan with no card keeps the readout's own rows
243
+ const onCard = checkCard !== null && Array.isArray(checkCard.rows) ? cardLinesOf(declaration) : new Set();
227
244
  // display only: a hitl step that is not an Ask line prints the card's words (src/checked.js hitlWords); an Ask line (pure stop) keeps `hitl`
228
245
  const askLineNos = (arbiter.asks ?? []).map((a) => a.line);
229
246
  const lastAskIdx = declaration.steps.reduce((m, st, i) => (askLineNos.includes(st.fromLine) ? i : m), -1);
230
247
  const checkText = (st, i) => (st.close?.class === 'hitl' && !askLineNos.includes(st.fromLine) ? hitlWords(askLineNos.length > 0, lastAskIdx !== -1 && i > lastAskIdx) : st.close?.class);
248
+ // M19 S6 (section 3.7): the rows of a list line and the Not checked items are told in the signed look's groups; the rows no one line owns are one `EVERY LINE` block (a one-line job's join its line)
249
+ // M19 am4: the Not checked rows are the card's (src/checked.js notCheckedView, the one split): a note about a written form the page did not use is "How the page was read", not a Not checked row
250
+ // a plan with no card list (drafted before M16) keeps today's readout (signed am4 item 2): the split is for a plan the card draws a list on
251
+ const ncRows = ncRowsOf(onCard.size > 0 ? notCheckedView(notChecked, declaration).items : notChecked, notCheckedBy);
252
+ const many = lines.length > 1;
253
+ const alwaysRows = onList.size > 0 ? EVERY_STEP_TEXTS.map((text) => ({ text, by: 'default', kind: 'file' })) : [];
254
+ const owned = new Set(declaration.steps.map((st) => st.fromLine));
255
+ const told = new Set();
231
256
  declaration.steps.forEach((st, i) => {
257
+ /** @type {{text: string, by: string, kind?: string}[]} */
258
+ const rows = [];
232
259
  out.push(` ${i + 1}. (line ${st.fromLine}) ${st.goal}`);
233
260
  out.push(` grants: ${st.primitives?.length ? st.primitives.join(', ') : 'none (pure stop)'}`
234
261
  + ` | reads: ${st.reads?.length ? st.reads.join(', ') : '-'} | emits: ${st.emits} | check: ${checkText(st, i)}`);
@@ -236,23 +263,24 @@ export function buildReadout({
236
263
  // M10 am7 item 1: the facts a cited step checks its quotes against, signed with the readout (typed fields, never model prose)
237
264
  // M16: a list line's checks carry the tag of the row that built each (`[you]`, `[agent]`, `[default]`); any other line keeps today's words
238
265
  const listed = onList.has(st.fromLine);
239
- if (listed && st.close?.cited && typeof st.close.cited === 'object') {
266
+ const cardLine = onCard.has(st.fromLine);
267
+ if (cardLine) { /* M19 am4: the card's rows stand in for the hand-built ones (below) */ } else if (listed && st.close?.cited && typeof st.close.cited === 'object') {
240
268
  const c = st.close.cited;
241
- for (const f of Array.isArray(c.facts) ? c.facts : []) out.push(` ${tagged(factSentence(f, c.source), factByOf(declaration, st.fromLine, f.name) ?? 'agent')}`);
242
- if (countSentence(c)) out.push(` ${tagged(/** @type {string} */ (countSentence(c)), countByOf(declaration, st.fromLine) ?? 'agent')}`);
269
+ for (const f of Array.isArray(c.facts) ? c.facts : []) rows.push({ text: factSentence(f, c.source), by: factByOf(declaration, st.fromLine, f.name) ?? 'agent' });
270
+ if (countSentence(c)) rows.push({ text: /** @type {string} */ (countSentence(c)), by: countByOf(declaration, st.fromLine) ?? 'agent' });
243
271
  } else if (st.close?.cited && typeof st.close.cited === 'object') for (const row of factRows(st.close.cited)) out.push(` ${labelled(row, 'agent')}`);
244
272
  // M10b piece 1: the signed sheet checks, one row each, written by code from the typed fields
245
- if (Array.isArray(st.close?.sheet)) for (const row of sheetBlocks.find((b) => b.line === st.fromLine)?.checked ?? []) out.push(` sheet check: ${row.text}`);
273
+ if (!cardLine && Array.isArray(st.close?.sheet)) for (const row of sheetBlocks.find((b) => b.line === st.fromLine)?.checked ?? []) out.push(` sheet check: ${row.text}`);
246
274
  // M10 am8 item 2: the column lock, signed with the readout (typed fields)
247
275
  if (Array.isArray(st.close?.columns)) for (const c of st.close.columns) if (typeof c?.column === 'string' && typeof c?.source === 'string') out.push(` cells only from column '${c.column}' of ${c.source}`);
248
276
  // M10 am16: the checks the person picked, signed with the readout, each in the one set of plain words (typed fields, never model prose)
249
- if (Array.isArray(st.close?.shape?.picked)) st.close.shape.picked.forEach((c, j) => out.push(listed ? ` ${tagged(plainWords(c), partByOf(declaration, st.fromLine, j) ?? 'agent')}` : ` ${labelled(`you picked: ${plainWords(c)}`, 'picked')}`));
277
+ if (!cardLine && Array.isArray(st.close?.shape?.picked)) st.close.shape.picked.forEach((c, j) => (listed ? rows.push({ text: plainWords(c), by: partByOf(declaration, st.fromLine, j) ?? 'agent' }) : out.push(` ${labelled(`you picked: ${plainWords(c)}`, 'picked')}`)));
250
278
  // M10 am22 (1): the checks the person picked for a fact line are signed with the readout too, in the same words
251
- if (st.close?.class === 'green' && Array.isArray(st.close.picked)) st.close.picked.forEach((c, j) => out.push(listed ? ` ${tagged(plainWords(c), partByOf(declaration, st.fromLine, (st.close.cited && typeof st.close.cited === 'object' ? 1 : 0) + j) ?? 'agent')}` : ` ${labelled(`you picked: ${plainWords(c)}`, 'picked')}`));
279
+ if (!cardLine && st.close?.class === 'green' && Array.isArray(st.close.picked)) st.close.picked.forEach((c, j) => (listed ? rows.push({ text: plainWords(c), by: partByOf(declaration, st.fromLine, (st.close.cited && typeof st.close.cited === 'object' ? 1 : 0) + j) ?? 'agent' }) : out.push(` ${labelled(`you picked: ${plainWords(c)}`, 'picked')}`)));
252
280
  // M16 R7: the numbers tie of a list line (the `$` row)
253
- if (listed && Array.isArray(st.close?.numbersFrom) && st.close.numbersFrom.length > 0) {
281
+ if (!cardLine && listed && Array.isArray(st.close?.numbersFrom) && st.close.numbersFrom.length > 0) {
254
282
  const before = (st.close.cited && typeof st.close.cited === 'object' ? 1 : 0) + (Array.isArray(st.close.picked) ? st.close.picked.length : Array.isArray(st.close.shape?.picked) ? st.close.shape.picked.length : 0);
255
- out.push(` ${tagged(`${CARD_T.numbers} ${st.close.numbersFrom.join(', ')}`, partByOf(declaration, st.fromLine, before) ?? 'default')}`);
283
+ rows.push({ text: numbersWords(st.close.numbersFrom), by: partByOf(declaration, st.fromLine, before) ?? 'default' });
256
284
  }
257
285
  // M4e amendment 14 item 5: the check's sections in its order (+ word limit); fixed text from typed fields, never model prose.
258
286
  const shape = st.close?.shape;
@@ -261,7 +289,20 @@ export function buildReadout({
261
289
  const lim = Number.isInteger(shape.maxWords) ? ` · under ${shape.maxWords} words` : '';
262
290
  out.push(` ${labelled(`sections: ${shape.sections.join(' · ')}${per}${lim}`, 'agent')}`);
263
291
  }
292
+ const first = !told.has(st.fromLine);
293
+ told.add(st.fromLine);
294
+ const joins = !many && first;
295
+ if (cardLine && first) rows.push(...(checkCard?.rows ?? []).filter((r) => r.line === st.fromLine && r.state === 'built').map((r) => ({ text: r.text, by: r.by, kind: r.kind || 'truth' })));
296
+ out.push(...readoutGroups({
297
+ checks: [...rows, ...(joins ? alwaysRows : [])],
298
+ nc: first ? ncRows.filter((n) => n.line === st.fromLine || (joins && !owned.has(n.line))) : [],
299
+ suggested: first ? suggested.filter((x) => x.line === st.fromLine || (joins && !owned.has(x.line))) : [],
300
+ }));
264
301
  });
302
+ if (many) {
303
+ const rest = readoutGroups({ checks: alwaysRows, nc: ncRows.filter((n) => !owned.has(n.line)), suggested: [] });
304
+ if (rest.length) out.push(` ${LOOK.everyLine.toUpperCase()}`, ...rest);
305
+ }
265
306
  out.push('', READOUT_HEADS.asks);
266
307
  for (const a of arbiter.asks) out.push(` line ${a.line}: "${a.question}" (ttl ${fmtTtl(a.ttlMs)})`);
267
308
  if (arbiter.asks.length === 0) out.push(' none');
@@ -344,7 +385,7 @@ export function writePlanFiles(dir, files, opts = {}) {
344
385
  * `onResult({ ok })` (M4d am32): called once, after the spend is booked and just before the result files are written (the CLI gives its monthly hold back there).
345
386
  */
346
387
  export async function draftToDir({
347
- proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, fetchPage, leftRules, columnAnswers, carriedColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, proseRead,
388
+ proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, fetchPage, leftRules, columnAnswers, carriedColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, carriedShapeDropped, proseRead,
348
389
  flowType = /** @type {'plain'|'mcp'|'tickets'} */ ('plain'), mcpServer = /** @type {string|undefined} */ (undefined), mcpPick = /** @type {any} */ (undefined), mcpServers = /** @type {string[]|undefined} */ (undefined),
349
390
  // M13 am11: what the card's tentative send line is (see draft()); null = the prose file is the truth
350
391
  actionMode = /** @type {null|'check'|'known'} */ (null),
@@ -428,10 +469,11 @@ export async function draftToDir({
428
469
  /** @type {any[]} */
429
470
  let columnRecord = []; // the agreed columns of this plan (fresh and carried), kept in the same record (M17 ruling 2)
430
471
  let sheetDropped = []; // the sheet checks this plan has dropped (a Revise's carried ones, applied by draft()), kept in the same record
472
+ let shapeDropped = []; // the shape fields this plan has dropped, kept beside them in the same record (no new file)
431
473
  /** @type {any} */
432
474
  let pickRecord = null; // M10 am17: handed by draft() as it learns it; the last one handed is this draft's (written below, the one writer)
433
475
  const result = await draft({
434
- proseText: prose.text, slot, model, provider, rates, modelId, env, onBook, priorSpend, offerQuestions: !noQuestions, draftThinking, draftDir: path.join(dir, PAGES_DIR), fetchPage, learnHints, ...(leftRules === undefined ? {} : { leftRules }), ...(columnAnswers === undefined ? {} : { columnAnswers }), ...(carriedColumns === undefined ? {} : { carriedColumns }), onColumns: (rec) => { columnRecord = rec; }, ...(checkPicks === undefined ? {} : { checkPicks }), ...(carriedPicks === undefined ? {} : { carriedPicks }), ...(carriedChoices === undefined ? {} : { carriedChoices, onChoices: (rec) => { rowChoices = rec; } }), ...(carriedSheetDropped === undefined ? {} : { carriedSheetDropped }), onSheetDropped: (rec) => { sheetDropped = rec; }, onPickRecord: (r) => { pickRecord = r; },
476
+ proseText: prose.text, slot, model, provider, rates, modelId, env, onBook, priorSpend, offerQuestions: !noQuestions, draftThinking, draftDir: path.join(dir, PAGES_DIR), fetchPage, learnHints, ...(leftRules === undefined ? {} : { leftRules }), ...(columnAnswers === undefined ? {} : { columnAnswers }), ...(carriedColumns === undefined ? {} : { carriedColumns }), onColumns: (rec) => { columnRecord = rec; }, ...(checkPicks === undefined ? {} : { checkPicks }), ...(carriedPicks === undefined ? {} : { carriedPicks }), ...(carriedChoices === undefined ? {} : { carriedChoices, onChoices: (rec) => { rowChoices = rec; } }), ...(carriedSheetDropped === undefined ? {} : { carriedSheetDropped }), onSheetDropped: (rec) => { sheetDropped = rec; }, ...(carriedShapeDropped === undefined ? {} : { carriedShapeDropped }), onShapeDropped: (rec) => { shapeDropped = rec; }, onPickRecord: (r) => { pickRecord = r; },
435
477
  flowType, mcp, ...(mcpServers === undefined ? {} : { mcpServers }), actionMode,
436
478
  });
437
479
  if (result.stop === 'pre-flight') {
@@ -466,7 +508,7 @@ export async function draftToDir({
466
508
  // Amendments 24/25: the questions and the drafter's own "not checked" reading are written BEFORE log.json/spec.hash (the panel reads those
467
509
  // two as "the draft finished"), as their own files: never in the readout, so never in the hash.
468
510
  if (result.questions?.length) files[QUESTIONS_FILE] = scrub(dj({ questions: result.questions }), secrets);
469
- if (pickRecord !== null) files[RECORD_FILE] = scrub(dj({ ...pickRecord, ...(rowChoices === null ? {} : { rowChoices }), ...(sheetDropped.length ? { sheetDropped } : {}), ...(columnRecord.length ? { columns: columnRecord } : {}) }), secrets); // M10 am17: the picks carried to the next plan (this drafting folder only, never a run folder)
511
+ if (pickRecord !== null) files[RECORD_FILE] = scrub(dj({ ...pickRecord, ...(rowChoices === null ? {} : { rowChoices }), ...(sheetDropped.length ? { sheetDropped } : {}), ...(shapeDropped.length ? { shapeDropped } : {}), ...(columnRecord.length ? { columns: columnRecord } : {}) }), secrets); // M10 am17: the picks carried to the next plan (this drafting folder only, never a run folder)
470
512
  files[NOT_CHECKED_FILE] = scrub(dj({ notChecked: result.notChecked ?? [], ...(result.notCheckedBy && Object.keys(result.notCheckedBy).length ? { by: result.notCheckedBy } : {}) }), secrets); // M16 item 5: the tag of each line that tells a row
471
513
  if (result.pageLooks || result.sheetLooks) files[PAGE_LOOK_FILE] = scrub(dj({ pages: result.pageLooks ?? [], ...(result.sheetLooks ? { sheets: result.sheetLooks } : {}), look: result.look ?? { facts: [], dropped: [] } }), secrets);
472
514
  files['log.json'] = scrub(dj({
@@ -475,6 +517,8 @@ export async function draftToDir({
475
517
  revisions: result.revisions, thinking: result.thinking, inputs: result.inputs, log: result.log,
476
518
  // M16 P4: what the plan card shows of the list (rows with tags and reasons, the suggestions), drawn by the page; Drop and Add rebuild it
477
519
  ...(result.checkCard ? { checkCard: result.checkCard } : {}),
520
+ // M19 S3: what code built from the AI's sheet suggestions (the block's `setSheet` input): Drop and Add rebuild the block from it at $0, never by asking again
521
+ ...(result.sheetBuilt ? { sheetBuilt: result.sheetBuilt } : {}),
478
522
  // M13 am11: the job's action (the last line the AI named, or the person agreed or typed), or null: the plan card's row `› line <n> writes everything before it`
479
523
  action: result.action ?? null,
480
524
  }), secrets);
@@ -484,6 +528,7 @@ export async function draftToDir({
484
528
  const inputFactsText = scrub(dj(result.declaration.inputFacts), secrets);
485
529
  const readoutText = scrub(buildReadout({
486
530
  declaration: result.declaration, arbiter: parsed.arbiter, lines: parsed.lines, name, modelId: result.modelId, costUsd: result.costUsd, rounds: result.rounds, spendComplete: result.spendComplete, root,
531
+ notChecked: result.notChecked ?? [], notCheckedBy: result.notCheckedBy ?? {}, suggested: result.checkCard?.suggested ?? [], checkCard: result.checkCard ?? null,
487
532
  }), secrets);
488
533
  files['declaration.json'] = declarationText;
489
534
  files['input-facts.json'] = inputFactsText;
@@ -590,6 +635,19 @@ export function signDraft({
590
635
  arbiter: signed.arbiter, lines: signed.lines, catalogue: cat.primitives, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true,
591
636
  });
592
637
  if (!verdict.ok) return { ok: false, reds: verdict.reds };
638
+ // M19 am6 item 3 (bareloop `planMatchesClose`): the card a draft saved must equal the checks the signed plan runs, line by line; a difference refuses the sign at $0, naming the line.
639
+ // Only a card saved with its own Not checked list (this build) is compared; an older saved card is drawn from the plan and not held to it.
640
+ const cardReds = (() => {
641
+ if (!Array.isArray(declaration.checkList)) return [];
642
+ const lg = read('log.json');
643
+ const rec = read(RECORD_FILE);
644
+ /** @type {any} */ let log = null; /** @type {any} */ let record = null;
645
+ try { log = lg.ok ? JSON.parse(lg.text) : null; record = rec.ok ? JSON.parse(rec.text) : null; } catch { return []; }
646
+ if (!log?.checkCard || !Array.isArray(log.checkCard.notChecked)) return [];
647
+ const kept = Array.isArray(record?.kept) ? record.kept.filter((/** @type {any} */ k) => k && Number.isInteger(k.line)) : [];
648
+ return planMatchesCard({ declaration, lines: signed.lines, csvRoles: csvRolesOf(signed.arbiter), kept, log: log.log }, log.checkCard);
649
+ })();
650
+ if (cardReds.length) return { ok: false, reds: cardReds };
593
651
 
594
652
  const reds = [];
595
653
  for (const s of signed.arbiter.sources) {
package/src/blockasks.js CHANGED
@@ -1,20 +1,19 @@
1
1
  // borrowed-from: bareloop src/blockasks.js@v0.57.0 (c18df406)
2
2
  // borrowed-from: bareloop src/blockasks.js@v0.56.0 (3383cce)
3
3
  // The questions of the check block, as the answer gate reads them (`answerQuestions`, src/questionbox.js): ONE spelling of the question words, written by code from a row that
4
- // code could not settle (reading | cant-check | check). The block's `open` list is the source; the person's CHOICE (agree | drop | rule) goes back through `block.applyAnswer`.
5
- import { readingQuestion, cantCheckQuestion } from './pageask.js';
6
- import { plainWords, HOW_TO_ANSWER, CANT_CHECK_WORDS } from './checkpick.js';
4
+ // code could not settle (reading | check). The block's `open` list is the source; the person's CHOICE (agree | drop | rule) goes back through `block.applyAnswer`.
5
+ import { readingQuestion } from './pageask.js';
6
+ import { plainWords, HOW_TO_ANSWER } from './checkpick.js';
7
7
 
8
- /** @typedef {{key: string, rowKey: string, line: number, rule: number, source: 'look', ask: 'reading'|'cant-check'|'no-check'|'check', ruleText: string, question: string, counted: boolean, reading?: string, check?: Record<string, any>}} BlockAsk */
8
+ /** @typedef {{key: string, rowKey: string, line: number, rule: number, source: 'look', ask: 'reading'|'check', ruleText: string, question: string, counted: boolean, reading?: string, check?: Record<string, any>}} BlockAsk */
9
9
 
10
10
  /**
11
- * The questions the block has open, in the order the person meets them: the look's readings, then the look's can't-checks, then the pick path's asks (a proposal or a can't-check about a rule the pick path owns) in rule order (a proposal is not counted toward the 3-ask cap).
12
- * A can't-check about a rule the PICK path owns (`scoped`: src/checkpick.js scopedRules, every `~` rule of a file job) is the pick path's own ask, `no-check`, in fwd's words (a "Line N, guardrail ...: I can't check this" ask
13
- * whose answer the panel records as a pick, so Revise carries it: am17/am18/am21); any other can't-check is the look's own ask about a page.
14
- * @param {import('./checkblock.js').CheckBlock} block @param {{line: number, rule: number}[]} [scoped] @returns {BlockAsk[]}
11
+ * The questions the block has open, in the order the person meets them: the look's readings, then the pick path's proposals (a proposal is not counted toward the 3-ask cap).
12
+ * M19 am3: a rule no check can settle is no longer asked, so `block.open` holds only `reading` and `check` asks; any other kind is a bug and throws.
13
+ * @param {import('./checkblock.js').CheckBlock} block @returns {BlockAsk[]}
15
14
  */
16
- export function questionsOfBlock(block, scoped = []) {
17
- const rank = { reading: 0, 'cant-check': 1, 'no-check': 2, check: 2 };
15
+ export function questionsOfBlock(block) {
16
+ const rank = { reading: 0, check: 1 };
18
17
  return block.open.map((/** @type {any} */ q) => {
19
18
  const row = block.rows.find((r) => r.key === q.rowKey);
20
19
  const rule = Number(row?.rule);
@@ -24,8 +23,7 @@ export function questionsOfBlock(block, scoped = []) {
24
23
  const words = plainWords(q.proposal);
25
24
  return { ...base, ask: /** @type {'check'} */ ('check'), counted: false, reading: words, check: q.proposal, question: `Line ${q.line}, guardrail "${q.ruleText}": I propose ${words}. ${HOW_TO_ANSWER(q.line, true)}` };
26
25
  }
27
- if (scoped.some((x) => x.line === q.line && x.rule === rule)) return { ...base, ask: /** @type {'no-check'} */ ('no-check'), counted: true, question: `Line ${q.line}, guardrail "${q.ruleText}": ${CANT_CHECK_WORDS} ${HOW_TO_ANSWER(q.line, false)}` };
28
- return { ...base, ask: /** @type {'cant-check'} */ ('cant-check'), counted: true, question: cantCheckQuestion(q.line, String(q.ruleText)) };
26
+ throw new Error(`questionsOfBlock: unexpected ask kind "${q.ask}" on row ${q.rowKey}`);
29
27
  }).sort((a, b) => rank[a.ask] - rank[b.ask]);
30
28
  }
31
29
 
@@ -1,6 +1,6 @@
1
1
  // M16 item 2 (docs/wiki/the-module-ladder.md, "M16"): "the AI sends only edits to that list; code proves each one and builds every check. The AI never writes a check."
2
2
  // The declaration of a draft with the list on keeps the AI's steps, reads, primitives and asks, and takes the CHECKS of every line the block was given from the block's built parts:
3
- // a fact part -> close.cited = {source, facts, count}, class green; the source is added to the step's reads by code
3
+ // a fact part -> close.cited = {source, facts, count, asSeen}, class green; the source is added to the step's reads by code
4
4
  // a countable part -> a picked check (M10 am22 (1)-(3)): close.shape.picked on a softgreen step, close.picked on a fact (or sheet) step with the line in pickedLines
5
5
  // the numbers tie -> close.numbersFrom (M16 am3 (2), R7)
6
6
  // no part -> hitl; the rows' Not-checked reasons are the list's own (no `unjudgeable` record, M17 am4)
@@ -11,33 +11,23 @@
11
11
  /** M17 am5 item 2 (D3): the reason a `~` rule on a signed Ask line is Not checked, the signed words */
12
12
  export const ASK_LINE_REASON = 'you judge it at the Ask';
13
13
 
14
- /** what a row says when its check cannot ride a line that has no guardrail of its own (the class of a line comes from its guardrail) */
15
- export const NO_GUARDRAIL_WORDS = 'This line has no guardrail of yours, so a check on it cannot be signed; you judge it at the Ask.';
14
+ /**
15
+ * M19 amendment 1 (signed 2026-11-20): a line that is a list of items and nothing else (no quote) signs class `green` with `itemShape` and no `cited`; the person's own rules on its text still ride beside it. `null` (tests only) signs no
16
+ * list-of-items check and the rows are Not checked (REASON.noRule). A facts+shape line keeps its class (green, `cited` plus `itemShape`, amendment E) whatever this says.
17
+ * @type {'green'|null}
18
+ */
19
+ export const SHAPE_ONLY_CLASS = 'green';
20
+
21
+ // fwd (F251): the no-guardrail words are the check block's (src/checkblock.js), the one writer; re-exported for the readers that import them from here
22
+ export { NO_GUARDRAIL_WORDS } from './checkblock.js';
16
23
 
17
- import { REASON, renderCard } from './checkblock.js';
18
- import { dropSentence } from './pagedropwords.js';
24
+ import { REASON } from './checkblock.js';
19
25
  import { KEPT_WORDS } from './pickrecord.js';
20
26
  import { lineRules } from './pagebits.js';
27
+ import { isListedNotChecked, notCheckedItem, ruleTextOf } from './checkrows.js';
21
28
 
22
29
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
23
30
 
24
- /** the words the card draws a row with, without its `~` / `!` / `$` mark (the one renderer, src/checkblock.js renderCard) @param {Record<string, any>} row */
25
- const rowWords = (row) => String(renderCard([{ ...row, hidden: false, state: row.state === 'suggested' || row.state === 'dropped' ? 'not-checked' : row.state }])[0]?.text ?? '').slice(2);
26
-
27
- /**
28
- * The words a Not-checked row says. A rule the person left, wrote in their own words, or left with no pick keeps fwd's signed table (M10 am16 (5): src/pagedropwords.js), the words the plan card and the
29
- * Audit already had; any other reason is the block's own (what code could not build and why).
30
- * @param {string|null|undefined} reason @param {{cantAsked?: boolean}} [row]
31
- */
32
- export function notCheckedWords(reason, row = undefined) {
33
- // a rule the person answered with their own words says so, whatever bareguard-free reason the block holds for it (a countable one reads "no rule can check this")
34
- if (row?.cantAsked === true && (reason === REASON.noRule || reason === REASON.nothingOnPage)) return dropSentence({ line: 0, fact: '', reason: 'own-words' });
35
- if (reason === REASON.left) return dropSentence({ line: 0, fact: '', reason: 'person-left' });
36
- if (reason === REASON.nothingOnPage) return dropSentence({ line: 0, fact: '', reason: 'own-words' });
37
- if (reason === REASON.noRule || reason === REASON.noPick || reason === REASON.cantCheck) return dropSentence({ line: 0, fact: '', reason: 'no-pick' });
38
- return String(reason ?? 'not checked');
39
- }
40
-
41
31
  /** a countable part as the picked check the softgreen close runs: its own fields, the rule named `rule` (the inverse of the block's partOfPick) @param {Record<string, any>} part */
42
32
  export function pickedOf(part) {
43
33
  const { text: _t, class: _c, check, rules: _r, source: _s, from: _f, oldIndex: _o, ...fields } = part;
@@ -45,11 +35,12 @@ export function pickedOf(part) {
45
35
  }
46
36
 
47
37
  /**
48
- * @param {{declaration: Record<string, any>, block: import('./checkblock.js').CheckBlock, lines: {n: number, guardrail?: string|null}[], lineSet: Set<number>, askLines?: Set<number>}} o
49
- * `lineSet` = the lines the block was given; `lines` = the signed lines (a guardrail decides the class); `askLines` = the signed Ask lines: each `~` rule on one is a Not-checked line here, never skipped (M17 am5 item 2)
38
+ * @param {{declaration: Record<string, any>, block: import('./checkblock.js').CheckBlock, lines: {n: number, guardrail?: string|null}[], lineSet: Set<number>, askLines?: Set<number>, sheetRoles?: string[], shapeOnlyClass?: 'green'|null}} o
39
+ * `lineSet` = the lines of the list (the block's step lines that are not sheet lines); `lines` = the signed lines (a guardrail decides the class); `askLines` = the signed Ask lines: each `~` rule on one is a Not-checked line here, never skipped (M17 am5 item 2);
40
+ * `sheetRoles` = the CSV inputs: the block's sheet part of a sheet line is the `close.sheet` of the line's first green step that reads one (M19 S3: the checks the block holds, drops and all)
50
41
  * @returns {{declaration: Record<string, any>, notChecked: string[], notCheckedBy: Record<string, 'you'|'agent'|'default'>, built: Set<number>}} `built` = the lines that got a check from the block (a red naming one of them is a fault of the build)
51
42
  */
52
- export function assembleFromBlock({ declaration, block, lines, lineSet, askLines = new Set() }) {
43
+ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines = new Set(), sheetRoles = [], shapeOnlyClass = SHAPE_ONLY_CLASS }) {
53
44
  if (!isRec(declaration) || !Array.isArray(declaration.steps)) return { declaration, notChecked: [], notCheckedBy: {}, built: new Set() };
54
45
  const c = block.reconcile();
55
46
  const partsOf = (/** @type {number} */ n) => c.map.filter((m) => m.line === n).map((m) => ({ ...c.parts[m.part], oldIndex: c.map.filter((x) => x.line === n).findIndex((x) => x.part === m.part) }));
@@ -57,37 +48,53 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
57
48
  /** @type {Set<number>} */ const built = new Set();
58
49
  /** @type {Map<number, Map<number, number|null>>} old part index -> new close-part index (null = the part is not in the close), per line */
59
50
  const remap = new Map();
60
- /** @type {Set<number>} */ const notSignable = new Set();
51
+ /** M19 S5 (O1): the lines whose shape part has no class to ride (a list of items and no quote, none ruled): their rows are signed Not checked @type {Set<number>} */ const noShapeClass = new Set();
61
52
  /** @type {Set<number>} */ const pickedLines = new Set(Array.isArray(declaration.pickedLines) ? declaration.pickedLines : []);
62
53
  const guardrailClasses = isRec(declaration.guardrailClasses) ? { ...declaration.guardrailClasses } : {};
54
+ /** the sheet part the block built for a sheet line, or null (no check is left on it) @param {number} n */
55
+ const sheetPartOn = (n) => { const m = c.map.find((x) => x.line === n); const p = m ? c.parts[m.part] : null; return p && p.class === 'sheet' ? p : null; };
56
+ /** @type {Set<number>} the sheet lines that already gave their checks to a step: the first green step that reads a sheet takes them */
57
+ const given = new Set();
63
58
  const steps = declaration.steps.map((/** @type {any} */ st) => {
64
59
  const n = st?.fromLine;
60
+ // M19 S3: a sheet line's checks are the block's (rows, drops), written into `close.sheet` of the line's first green step that reads a sheet; every other step of the line keeps the AI's own close
61
+ if (isRec(st) && Number.isInteger(n) && block.isSheetLine(n) && !lineSet.has(n)) {
62
+ const part = sheetPartOn(n);
63
+ const { sheet: _ai, ...close } = isRec(st.close) ? st.close : /** @type {Record<string, any>} */ ({});
64
+ if (!part || !isRec(st.close) || st.close.class !== 'green' || !Array.isArray(st.reads) || !st.reads.some((/** @type {string} */ r) => sheetRoles.includes(r)) || given.has(n)) return isRec(st.close) ? { ...st, close } : st;
65
+ given.add(n);
66
+ return { ...st, close: { ...close, sheet: part.checks.map((/** @type {any} */ x) => ({ ...x })) } };
67
+ }
65
68
  if (!isRec(st) || !Number.isInteger(n) || !lineSet.has(n)) return st;
66
69
  const parts = partsOf(n);
67
- const signable = guarded(n);
68
- const fact = signable ? parts.find((p) => p.class === 'fact') : undefined;
69
- const picks = signable ? parts.filter((p) => p.class === 'countable' && p.check !== 'cited' && p.check !== 'numbersFromFacts') : [];
70
+ // fwd (F251): the check block is the one decider that a line with no ~ guardrail holds no check (src/checkblock.js buildLine), so every part it holds is kept here
71
+ const fact = parts.find((p) => p.class === 'fact');
72
+ // M19 S5: the shape part rides the fact part (facts+shape, class green); a line with no fact part takes it only when a class is ruled for it (`shapeOnlyClass`)
73
+ const picks = parts.filter((p) => p.class === 'countable' && p.check !== 'cited' && p.check !== 'numbersFromFacts');
74
+ const shape = parts.find((p) => p.class === 'shape' && (fact !== undefined || shapeOnlyClass === 'green'));
70
75
  const tie = parts.find((p) => p.class === 'countable' && p.check === 'numbersFromFacts');
71
76
  const old = isRec(st.close) ? st.close : {};
72
77
  const sheet = Array.isArray(old.sheet) ? old.sheet : null;
73
- // the part order the close lists them in (src/checklistsign.js closePartsOf): the fact part, each pick, the tie
74
- const keptOrder = [...(fact ? [fact] : []), ...picks, ...(tie ? [tie] : [])];
78
+ // the part order the close lists them in (src/checklistsign.js closePartsOf): the fact part, the shape part, each pick, the tie
79
+ const keptOrder = [...(fact ? [fact] : []), ...(shape ? [shape] : []), ...picks, ...(tie ? [tie] : [])];
75
80
  const map = remap.get(n) ?? new Map();
76
81
  for (const p of parts) map.set(p.oldIndex, keptOrder.includes(p) ? keptOrder.indexOf(p) : null);
77
82
  remap.set(n, map);
78
- if (!signable && parts.some((p) => p !== tie)) notSignable.add(n);
83
+ if (!shape && parts.some((p) => p.class === 'shape')) noShapeClass.add(n);
79
84
  /** @type {Record<string, any>} */
80
85
  const close = { ...(sheet ? { sheet } : {}), ...(Array.isArray(old.columns) ? { columns: old.columns } : {}) };
81
86
  if (fact) {
82
87
  close.class = 'green';
83
- close.cited = { source: fact.source, facts: fact.facts, ...(isRec(fact.count) ? { count: fact.count } : {}) };
84
- } else close.class = sheet ? 'green' : picks.length ? 'softgreen' : 'hitl';
88
+ close.cited = { source: fact.source, facts: fact.facts, ...(isRec(fact.count) ? { count: fact.count } : {}), ...(isRec(fact.asSeen) ? { asSeen: fact.asSeen } : {}) };
89
+ } else close.class = sheet ? 'green' : shape ? /** @type {'green'} */ (shapeOnlyClass) : picks.length ? 'softgreen' : 'hitl';
90
+ // the list-of-items check is its own close key, never `close.shape` (amendment E): the signed fields and the item count of the part
91
+ if (shape) close.itemShape = { fields: shape.fields, ...(Number.isInteger(shape.minItems) ? { minItems: shape.minItems } : {}), ...(Number.isInteger(shape.maxItems) ? { maxItems: shape.maxItems } : {}) };
85
92
  if (picks.length) {
86
93
  const checks = picks.map(pickedOf);
87
94
  if (close.class === 'green') { close.picked = checks; pickedLines.add(n); } else close.shape = { picked: checks };
88
95
  }
89
96
  if (tie) close.numbersFrom = [...tie.from];
90
- if (fact || picks.length || tie) built.add(n);
97
+ if (fact || shape || picks.length || tie) built.add(n);
91
98
  const reads = Array.isArray(st.reads) && fact && !st.reads.includes(fact.source) ? [...st.reads, fact.source] : st.reads;
92
99
  return { ...st, reads, close };
93
100
  });
@@ -101,25 +108,24 @@ export function assembleFromBlock({ declaration, block, lines, lineSet, askLines
101
108
  }
102
109
  const served = new Set(steps.filter((/** @type {any} */ st) => isRec(st)).map((/** @type {any} */ st) => st.fromLine));
103
110
  /** the signed list: the block's signed fields per row, the parts renumbered to the close's order, a row whose check cannot ride its line signed Not checked @type {any[]} */
104
- const checkList = block.signedRows().map((/** @type {any} */ r) => {
111
+ // M19 S3: the rows of a sheet line are the block's own (state, Drop); the signed list and the Not-checked lines of a sheet line stay fwd's (src/sheetrows.js reads the close.sheet written above, src/sheetblock.js the reasons)
112
+ const checkList = block.signedRows().filter((/** @type {any} */ r) => !block.isSheetLine(r.line)).map((/** @type {any} */ r) => {
105
113
  const m = remap.get(r.line);
106
114
  const idx = isRec(r.part) && m ? m.get(r.part.part) : undefined;
107
115
  if (r.state === 'built' && r.kind !== 'floor' && (idx === null || idx === undefined)) {
108
116
  const { part: _p, ...rest } = r;
109
- return { ...rest, state: 'not-checked', reason: notSignable.has(r.line) ? NO_GUARDRAIL_WORDS : String(r.reason ?? 'not checked') };
117
+ return { ...rest, state: 'not-checked', reason: noShapeClass.has(r.line) ? (r.kind === 'rule' ? REASON.noPick : REASON.noRule) : String(r.reason ?? 'not checked') };
110
118
  }
111
119
  return isRec(r.part) && typeof idx === 'number' ? { ...r, part: { line: r.part.line, part: idx } } : r;
112
120
  });
113
121
  /** @type {Record<string, 'you'|'agent'|'default'>} the tag of each Not-checked line, by the row it tells (M16 item 5: one tag per row) */
114
122
  const notCheckedBy = {};
115
- const notChecked = checkList.filter((r) => r.state === 'not-checked' && r.kind !== 'floor').map((r) => {
123
+ // M19 am8 item 2, am9 items 1 to 4: the items are the reader's (src/checkrows.js `notCheckedItem`, the one writer): a `~` rule `line <n>: "<rule text>" \u2014 <reason>`, any other row its name (`<kind> "<words>"`)
124
+ const notChecked = checkList.filter((r) => isListedNotChecked(checkList, r)).map((r) => {
116
125
  const own = block.rows.find((x) => x.key === r.key);
117
126
  if (own?.hidden) return null;
118
- const row = own;
119
- // any other row is told in the words the card draws it with (renderCard; never the row's key)
120
- // a `~` rule is told in the signed table's form, `not checked · "<rule>" — <reason>` (M10 am16 (5)); any other row names its line
121
- const kept = row?.keptFromLast === true ? ` (${KEPT_WORDS})` : ''; // M10 am17 (6)
122
- const line = r.kind === 'rule' && row?.text ? `not checked · "${row.text}" — ${notCheckedWords(r.reason, row)}${kept}` : `line ${r.line}: ${rowWords(own ?? r)} - ${notCheckedWords(r.reason, row)}${kept}`;
127
+ // the reason is the signed row's own `reason` (src/checkblock.js REASON, the one table); M10 am17 (6): `kept` words
128
+ const line = notCheckedItem(r, ruleTextOf(lines, r) ?? own?.text, own ? (own.name ? [own.name] : own.words) : undefined, own?.keptFromLast === true);
123
129
  if (r.by === 'you' || r.by === 'agent' || r.by === 'default') notCheckedBy[line] = r.by;
124
130
  return line;
125
131
  }).filter((x) => x !== null);