fwdloop 0.35.2 → 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 (104) 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 +78 -20
  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 +86 -62
  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 +6 -4
  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 +20 -8
  34. package/src/panel/authorcard.js +3 -3
  35. package/src/panel/data.js +3 -2
  36. package/src/panel/index.html +176 -41
  37. package/src/panel/result.js +40 -3
  38. package/src/pickrecord.js +14 -0
  39. package/src/planrebuild.js +55 -19
  40. package/src/ratelimit.js +117 -0
  41. package/src/report.js +216 -0
  42. package/src/rowresults.js +111 -0
  43. package/src/rubricstep.js +65 -2
  44. package/src/runner.js +61 -9
  45. package/src/send.js +19 -82
  46. package/src/shapebuild.js +281 -0
  47. package/src/shapelook.js +91 -0
  48. package/src/shapemenu.js +64 -0
  49. package/src/shaperesult.js +104 -0
  50. package/src/shaperows.js +263 -0
  51. package/src/shapewords.js +140 -0
  52. package/src/sheetbuild.js +41 -29
  53. package/src/sheetclaims.js +49 -1
  54. package/src/sheetfind.js +8 -0
  55. package/src/sheetlook.js +11 -1
  56. package/src/sheetrows.js +10 -64
  57. package/src/ticketrows.js +1 -1
  58. package/src/try-checks.js +39 -6
  59. package/src/types.js +1 -0
  60. package/src/whole-job.js +108 -16
  61. package/types/action-stop.d.ts +1 -1
  62. package/types/auditchecks.d.ts +13 -2
  63. package/types/authoring.d.ts +24 -4
  64. package/types/blockasks.d.ts +6 -10
  65. package/types/blockassemble.d.ts +13 -13
  66. package/types/blockdraft.d.ts +3 -2
  67. package/types/blockpick.d.ts +4 -0
  68. package/types/cardlist.d.ts +18 -2
  69. package/types/checkblock.d.ts +278 -28
  70. package/types/checked.d.ts +15 -6
  71. package/types/checklook.d.ts +36 -0
  72. package/types/checkrows.d.ts +119 -0
  73. package/types/citedcheck.d.ts +4 -2
  74. package/types/closers.d.ts +10 -1
  75. package/types/drafter.d.ts +8 -4
  76. package/types/globprefix.d.ts +5 -0
  77. package/types/model-step.d.ts +43 -2
  78. package/types/pageask.d.ts +5 -3
  79. package/types/pagedropwords.d.ts +0 -1
  80. package/types/pagedry.d.ts +27 -0
  81. package/types/pagefetch.d.ts +3 -2
  82. package/types/pagerules.d.ts +4 -0
  83. package/types/panel/result.d.ts +19 -2
  84. package/types/pickrecord.d.ts +10 -0
  85. package/types/ratelimit.d.ts +59 -0
  86. package/types/report.d.ts +46 -0
  87. package/types/rowresults.d.ts +28 -0
  88. package/types/rubricstep.d.ts +21 -0
  89. package/types/runner.d.ts +3 -1
  90. package/types/send.d.ts +13 -12
  91. package/types/shapebuild.d.ts +97 -0
  92. package/types/shapelook.d.ts +76 -0
  93. package/types/shapemenu.d.ts +40 -0
  94. package/types/shaperesult.d.ts +40 -0
  95. package/types/shaperows.d.ts +102 -0
  96. package/types/shapewords.d.ts +43 -0
  97. package/types/sheetbuild.d.ts +31 -13
  98. package/types/sheetclaims.d.ts +16 -0
  99. package/types/sheetfind.d.ts +1 -0
  100. package/types/sheetrows.d.ts +5 -36
  101. package/types/ticketrows.d.ts +1 -1
  102. package/types/try-checks.d.ts +2 -1
  103. package/types/types.d.ts +4 -0
  104. package/types/whole-job.d.ts +69 -3
package/src/checked.js CHANGED
@@ -15,14 +15,16 @@ export const LIST_NOT_CHECKED_LABEL = 'Not checked';
15
15
  /** the label that sits with a plan's Not checked list: a plan with a list says "Not checked", an older plan keeps the words it was signed with @param {any} declaration */
16
16
  export const notCheckedLabelOf = (declaration) => (listLinesOf(declaration).size > 0 ? LIST_NOT_CHECKED_LABEL : NOT_CHECKED_LABEL);
17
17
 
18
- import { factRows, factSentence, countSentence } from './citedcheck.js';
18
+ import { factRows } from './citedcheck.js';
19
19
  import { plainWords, labelled, tagged } from './checkwords.js';
20
- import { listLinesOf, partByOf, factByOf, countByOf } from './checklistsign.js';
21
- import { CARD_T } from './checkblock.js';
20
+ import { listLinesOf } from './checklistsign.js';
21
+ import { stepRowsOf } from './checkrows.js';
22
22
  import { sheetCheckRows } from './sheetchecks.js';
23
23
  import { sheetLineBlocks } from './sheetblock.js';
24
24
  import { splitReadNotes, signedFactNames } from './pagedropwords.js';
25
25
 
26
+ /** the quote check's lead sentence (one writer: both the listed and the unlisted line) @param {string} source */
27
+ const citedLead = (source) => `Each result must be quoted word for word from the saved page "${source}", and the machine checks every quote, every value and the count against that copy.`;
26
28
  const list = (xs) => xs.join(', ');
27
29
 
28
30
  /** The words for a step with no machine check of its content: the ONE owner (the card and the draft readout both call it). @param {boolean} hasAsk the job has a signed ask @param {boolean} afterLastAsk the step comes after the last ask */
@@ -37,7 +39,7 @@ export function hitlWords(hasAsk, afterLastAsk) {
37
39
  * Checked with `covers`, Not checked), and its sentences are only the lead sentence; the surfaces draw the block. Without `lines` the older one-row-per-check sentences.
38
40
  * @param {{ steps?: any[] }} declaration @param {{ hasAsk?: boolean, askLines?: number[], lines?: any[], csvRoles?: string[], keptChecks?: {line: number, check: any}[], keptWords?: string }} [opts] hasAsk = the job has a signed ask line (so "you check it at the ask" is true);
39
41
  * askLines = the job lines of the signed asks, which also lets a step after the LAST ask read "you check it after you accept" (am41 item 2, am42: the ONE place for these words)
40
- * @returns {{ step: number, line: number|null, goal: string, class: string, sentences: string[], sheet?: ReturnType<typeof sheetLineBlocks>[number] }[]}
42
+ * @returns {{ step: number, line: number|null, goal: string, class: string, lead: string|null, sentences: string[], sheet?: ReturnType<typeof sheetLineBlocks>[number] }[]}
41
43
  */
42
44
  export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvRoles = [], keptChecks = [], keptWords = '' } = {}) {
43
45
  const blocks = Array.isArray(lines) ? sheetLineBlocks({ declaration, lines, csvRoles }) : [];
@@ -51,22 +53,29 @@ export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvR
51
53
  const firstGreen = steps.findIndex((x) => x?.fromLine === st?.fromLine && x?.close?.class === 'green') === i;
52
54
  const sheet = firstGreen ? (blocks.find((b) => b.line === st?.fromLine) ?? null) : null;
53
55
  const shape = st?.close?.shape && typeof st.close.shape === 'object' ? st.close.shape : {};
56
+ /** F252: the ONE lead sentence of the step (null when it states none); `sentences` is the lead, then the rows */
57
+ /** @type {string|null} */
58
+ let lead = null;
54
59
  /** @type {string[]} */
55
60
  const out = [];
56
61
  const listed = onList.has(st?.fromLine);
57
62
  if (listed && cls === 'green' && st.close.cited && typeof st.close.cited === 'object') {
58
63
  // M16: a list line states the quote check's lead, then each check as a row with the tag of its own row (below)
59
- out.push(`Each result must be quoted word for word from the saved page "${st.close.cited.source}", and the machine checks every quote, every value and the count against that copy.`);
64
+ lead = citedLead(st.close.cited.source);
60
65
  } else if (cls === 'green' && st.close.cited && typeof st.close.cited === 'object') {
61
66
  // M10 am7 item 1: the facts the drafter wrote, as plain rows written by code from the typed fields
62
- out.push(`Each result must be quoted word for word from the saved page "${st.close.cited.source}", and the machine checks every quote, every value and the count against that copy.`, ...factRows(st.close.cited).map((r) => labelled(r, 'agent')));
67
+ lead = citedLead(st.close.cited.source);
68
+ out.push(...factRows(st.close.cited).map((r) => labelled(r, 'agent')));
63
69
  } else if (cls === 'green' && Array.isArray(st.close.sheet)) {
64
70
  // M10b piece 1: the signed sheet checks, one row each, written by code from the typed fields
65
- out.push('The machine recomputes each of these from the saved sheet and compares it with what the step gave:', ...(sheet ? [] : sheetCheckRows(st.close.sheet).map((r) => labelled(r, 'agent'))));
71
+ lead = 'The machine recomputes each of these from the saved sheet and compares it with what the step gave:';
72
+ out.push(...(sheet ? [] : sheetCheckRows(st.close.sheet).map((r) => labelled(r, 'agent'))));
73
+ } else if (cls === 'green' && st.close.itemShape && typeof st.close.itemShape === 'object') {
74
+ // M19 am11 item 6: a list line states no lead sentence; its checks are the rows below (listPartRows)
66
75
  } else if (cls === 'green') {
67
- out.push('Every figure must cite its source cell, or a formula over cells, and the machine recomputes it and compares it with its source.');
76
+ lead = 'Every figure must cite its source cell, or a formula over cells, and the machine recomputes it and compares it with its source.';
68
77
  } else if (cls === 'softgreen') {
69
- out.push('The reply is checked as plain text only.');
78
+ lead = 'The reply is checked as plain text only.';
70
79
  if (Number.isInteger(shape.maxWords)) out.push(labelled(`The whole output is under ${shape.maxWords} words.`, 'agent'));
71
80
  if (Array.isArray(shape.sections) && shape.sections.length > 0) out.push(labelled(`These section headings are there, in this order: ${list(shape.sections)}.`, 'agent'));
72
81
  if (Number.isInteger(shape.wordsPerSection) && Array.isArray(shape.sections) && shape.sections.length > 0) out.push(labelled(`Each of those sections is about ${shape.wordsPerSection} words.`, 'agent'));
@@ -75,14 +84,14 @@ export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvR
75
84
  // M10 am16: each check the person picked, in the words it was picked in (src/checkwords.js, the one place)
76
85
  if (!listed && Array.isArray(shape.picked)) for (const c of shape.picked) out.push(labelled(`You picked: ${plainWords(c)}.${keptOf(st.fromLine, c)}`, 'picked'));
77
86
  } else {
78
- out.push(hitlWords(hasAsk, lastAsk !== -1 && i > lastAsk));
87
+ lead = hitlWords(hasAsk, lastAsk !== -1 && i > lastAsk);
79
88
  }
80
89
  // M10 am22 (1)(4): the checks the person picked for a fact line, beside its fact rows
81
90
  if (!listed && cls === 'green' && Array.isArray(st.close.picked)) for (const c of st.close.picked) out.push(labelled(`You picked: ${plainWords(c)}.${keptOf(st.fromLine, c)}`, 'picked'));
82
91
  // M16 item 5: the checks of a list line, one tagged sentence each, from the rows' own reader
83
- if (listed) out.push(...listPartRows(declaration, st, keptOf).map((r) => tagged(r.text, r.by)));
92
+ if (listed) out.push(...listPartRows(declaration, st, { lines: Array.isArray(lines) ? lines : [], kept: keptChecks }).map((r) => tagged(r.text, r.by)));
84
93
  return {
85
- step: i + 1, line: Number.isInteger(st?.fromLine) ? st.fromLine : null, goal: typeof st?.goal === 'string' ? st.goal : '', class: String(cls), sentences: out,
94
+ step: i + 1, line: Number.isInteger(st?.fromLine) ? st.fromLine : null, goal: typeof st?.goal === 'string' ? st.goal : '', class: String(cls), lead, sentences: lead === null ? out : [lead, ...out],
86
95
  ...(sheet && cls === 'green' ? { sheet } : {}),
87
96
  };
88
97
  });
@@ -106,26 +115,12 @@ export function notCheckedView(items, declaration) {
106
115
  }
107
116
 
108
117
  /**
109
- * The checks of one list line's step as rows `{text, by, part}` in the close's part order (the quote check's facts and count, each picked check, the numbers tie), each with the `by` of the row that built it.
110
- * ONE reader for the plan card's sentences and the Audit's Checks fold; `part` is the index the signed list's rows point at (src/checklistsign.js). Pure.
111
- * @param {any} declaration @param {any} st the step @param {(line: number, c: any) => string} [keptOf]
112
- * @returns {{text: string, by: 'you'|'agent'|'default', part: number}[]}
118
+ * The checks of one list line's step as rows `{text, by, part}` in the close's part order (the quote check's facts and count, the field rows of a list of items, each picked check, the numbers tie), each with the `by` of the row that built it.
119
+ * M19 am7 items 1 to 3 and 8: the words are the card's, from the one reader (src/checkrows.js `stepRowsOf`); `part` is the index the signed list's rows point at (src/checklistsign.js), with a list line's shape part counted.
120
+ * ONE reader for the plan card's sentences, the Job tab and the Audit's Checks fold. Pure.
121
+ * @param {any} declaration @param {any} st the step @param {{lines?: any[], kept?: {line: number, check: any}[]}} [o] `lines` = the signed job lines (a field row's words read the person's rule), `kept` = the picks a Revise carried
122
+ * @returns {{text: string, by: 'you'|'agent'|'default', part: number, key: string}[]}
113
123
  */
114
- export function listPartRows(declaration, st, keptOf = () => '') {
115
- const close = st?.close && typeof st.close === 'object' ? st.close : {};
116
- const line = st?.fromLine;
117
- /** @type {{text: string, by: 'you'|'agent'|'default', part: number}[]} */
118
- const out = [];
119
- let idx = 0;
120
- if (close.cited && typeof close.cited === 'object') {
121
- const c = close.cited;
122
- for (const f of Array.isArray(c.facts) ? c.facts : []) out.push({ text: factSentence(f, c.source), by: factByOf(declaration, line, f.name) ?? 'agent', part: idx });
123
- const count = countSentence(c);
124
- if (count) out.push({ text: count, by: countByOf(declaration, line) ?? 'agent', part: idx });
125
- idx += 1;
126
- }
127
- const picked = Array.isArray(close.picked) ? close.picked : Array.isArray(close.shape?.picked) ? close.shape.picked : [];
128
- for (const c of picked) { out.push({ text: `${plainWords(c)}.${keptOf(line, c)}`, by: partByOf(declaration, line, idx) ?? 'agent', part: idx }); idx += 1; }
129
- if (Array.isArray(close.numbersFrom) && close.numbersFrom.length > 0) out.push({ text: `${CARD_T.numbers} ${close.numbersFrom.join(', ')}.`, by: partByOf(declaration, line, idx) ?? 'default', part: idx });
130
- return out;
124
+ export function listPartRows(declaration, st, { lines = [], kept = [] } = {}) {
125
+ return stepRowsOf({ declaration, st: st ?? {}, lines, kept }).rows.map((r) => ({ text: r.text, by: r.by, part: r.idx, key: r.key }));
131
126
  }
@@ -1,6 +1,6 @@
1
1
  // M16 (docs/wiki/the-module-ladder.md, "M16" item 2, "a check that reaches the plan is not on the list"): the sign-time and run-start proof that the checks of a plan's list lines are the list's.
2
2
  // Equivalent of bareloop src/rubricstep.js@v0.56.0 (3383cce) `listMatchesClose`, read over fwdloop's close fields instead of a rubric-step stage: the checks of one line, in the order the check block
3
- // builds them, are [close.cited (the fact part)], then each entry of close.picked / close.shape.picked, then close.numbersFrom (the numbers tie). A signed row points at one of them by `part: {line, part: <index>}`.
3
+ // builds them, are [close.cited (the fact part)], [close.itemShape (the shape part, M19 S5)], then each entry of close.picked / close.shape.picked, then close.numbersFrom (the numbers tie). A signed row points at one of them by `part: {line, part: <index>}`.
4
4
 
5
5
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
6
6
 
@@ -13,6 +13,7 @@ export function closePartsOf(step, withSheet = false) {
13
13
  /** @type {{what: string}[]} */
14
14
  const parts = [];
15
15
  if (isRec(close.cited)) parts.push({ what: 'the quote check (close.cited)' });
16
+ if (isRec(close.itemShape)) parts.push({ what: 'the list-of-items check (close.itemShape)' });
16
17
  const picked = Array.isArray(close.picked) ? close.picked : isRec(close.shape) && Array.isArray(close.shape.picked) ? close.shape.picked : [];
17
18
  picked.forEach((/** @type {unknown} */ _c, /** @type {number} */ i) => parts.push({ what: `the picked check ${i + 1} (close.picked)` }));
18
19
  if (Array.isArray(close.numbersFrom) && close.numbersFrom.length > 0) parts.push({ what: 'the numbers tie (close.numbersFrom)' });
@@ -0,0 +1,45 @@
1
+ // borrowed-from: bareloop src/panel/jobplan.js@v0.61.0 (fc56e1f3) (kindOfCheck, splitNotChecked, NcRow)
2
+ // M19 S6 (docs/wiki/the-module-ladder.md, "M19" S6, section 3.7, amendment D): the words and the split every surface of the check-list look reads, written ONCE here.
3
+ // The card (src/cardlist.js), the Audit (src/auditchecks.js), the draft readout (src/authoring.js) and the page all take their kind word and their Not-checked split from these.
4
+ // What this throws away: a Not checked item's own quotes round a whole rule and the reason "you judge it at Accept" (the group title says it).
5
+
6
+ /** the group titles and the tail of the Not checked one (section 3.7, copied unchanged) */
7
+ export const LOOK = Object.freeze({
8
+ checked: 'CHECKED', notChecked: 'NOT CHECKED', notCheckedTail: 'you judge these at Accept', suggested: 'SUGGESTED · add if you want it', everyLine: 'Every line',
9
+ });
10
+
11
+ /**
12
+ * The kind word of a check row (hamr 2026-11-19, signed list look): `shape` = code checks the form of the items, `file` = code checks the files (a guard, a line's output-file floor), `truth` = every other check.
13
+ * @param {{key?: string, shape?: true, fence?: true}} c @returns {'truth'|'shape'|'file'}
14
+ */
15
+ export function kindOfCheck(c) {
16
+ if (c.shape === true) return 'shape';
17
+ if (c.fence === true || (typeof c.key === 'string' && c.key.startsWith('J.$guard.')) || (typeof c.key === 'string' && /^L\d+\.\$floor$/.test(c.key))) return 'file';
18
+ return 'truth';
19
+ }
20
+
21
+ /**
22
+ * A Not checked text `head — reason` split into the row and the reason behind "why"; the quotes round a rule go; "you judge it at Accept" is the group title's, not a reason.
23
+ * @param {string} raw @returns {{text: string, why?: string}}
24
+ */
25
+ export function splitNotChecked(raw) {
26
+ const i = raw.indexOf(' — ');
27
+ if (i < 0) return { text: raw };
28
+ const text = raw.slice(0, i).replace(/^"([\s\S]*)"$/, '$1');
29
+ const why = raw.slice(i + 3);
30
+ return why === 'you judge it at Accept' ? { text } : { text, why };
31
+ }
32
+
33
+ /**
34
+ * The Not checked rows of the look: each item split into row and reason, with its tag and the job line that owns it (0 = no one line: the item names no `line N:`).
35
+ * fwd's own items name their line with the code-written prefix `line N: ` (src/blockassemble.js) and a `~` rule with `not checked · ` (the group title says it now).
36
+ * @param {string[]} items @param {Record<string, string>} [by] @returns {{line: number, text: string, why?: string, by?: 'you'|'agent'|'default'}[]}
37
+ */
38
+ export function ncRowsOf(items, by = {}) {
39
+ return (Array.isArray(items) ? items : []).map((raw) => {
40
+ const m = /^line (\d+): ([\s\S]*)$/.exec(raw);
41
+ const body = (m ? m[2] : raw).replace(/^not checked · /, '');
42
+ const tag = by[raw];
43
+ return { line: m ? Number(m[1]) : 0, ...splitNotChecked(body), ...(tag === 'you' || tag === 'agent' || tag === 'default' ? { by: tag } : {}) };
44
+ });
45
+ }
@@ -0,0 +1,202 @@
1
+ // borrowed-from: bareloop src/rubricstep.js@v0.61.0 (checksOfClose, listRowName, ruleNotCheckedItems, DEFAULT_ROW_WORDS, refusedOf, cardOfClose), src/draftspend.js@v0.61.0 (readDraftLedger), src/checklist.js@v0.61.0 (ledgerRecord), shape of the walk; the words are fwd's own writers
2
+ // M19 am6 to am9 (docs/wiki/the-module-ladder.md): the ONE reader of the plan card's rows. Every check row on the card, the readout and the Job tab takes its words and tag from the SIGNED PLAN through this file,
3
+ // never from a row copy: one row per signed check part, words from fwd's own sentence writers (src/citedcheck.js, src/shaperows.js, src/checkwords.js), the tag and key from the signed list row that built the part.
4
+ // The Not checked rows are a list of their own (am8 item 3), named by am8 item 2 and am9 items 1 to 4; the draft's own ledger rows (am8 item 1) give the words of a row, else its key's tail.
5
+ // What this throws away: the row proofs (`can`, `pick`, parts) and the draft-time words; a Drop flag is joined by key from the saved card, never decided here.
6
+ import { factSentence, countSentence } from './citedcheck.js';
7
+ import { plainWords } from './checkwords.js';
8
+ import { closePartsOf, cardLinesOf } from './checklistsign.js';
9
+ import { sheetRowsOf } from './sheetrows.js';
10
+ import { ticketRowsOf } from './ticketrows.js';
11
+ import { shapeRowsOf, shapeCountWords } from './shaperows.js';
12
+ import { kindOfCheck } from './checklook.js';
13
+ import { rulesOfLine } from './sheetblock.js';
14
+ import { KEPT_WORDS } from './pickrecord.js';
15
+
16
+ const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
17
+
18
+ /** the words of a line's floor row (src/cardlist.js drew them first; the reader is their one owner now) */
19
+ export const FLOOR_WORDS = "the file exists and its text is not empty (code's own floor)";
20
+ export const FLOOR_LIST_WORDS = "the file exists (code's own floor); this line lists items, so it has no text check";
21
+ /** am7 item 3: the numbers tie's words, `on line 1, 2` for several */
22
+ export const numbersWords = (/** @type {number[]} */ from) => `every number in the text is in a quote checked on line ${from.join(', ')}`;
23
+ /** am9 item 3 (bareloop `DEFAULT_ROW_WORDS`) */
24
+ export const DEFAULT_ROW_WORDS = Object.freeze({ cited: 'every claim quotes its input', numbers: 'every number matches a quote', note: 'the note' });
25
+ const FACT_KINDS = new Set(['fact', 'phrase', 'count']);
26
+
27
+ /**
28
+ * am9 item 4: every list row in state not-checked is in the Not checked list, but the floor, a Tickets row (fwd draws those itself, am7 item 5) and a fact line's default cited.
29
+ * @param {any[]} list @param {any} r
30
+ */
31
+ export const isListedNotChecked = (list, r) => isRec(r) && r.state === 'not-checked' && r.kind !== 'floor' && r.kind !== 'ticket' && !(r.kind === 'cited' && list.some((x) => isRec(x) && x.line === r.line && FACT_KINDS.has(x.kind)));
32
+
33
+ /** the person's rule text a signed `rule` row holds (its line's `~` rule at the row's number), else undefined @param {any[]} lines @param {any} r a signed `rule` row */
34
+ export const ruleTextOf = (lines, r) => (Number.isInteger(r.rule) ? rulesOfLine(lines.find((l) => l.n === r.line))[r.rule - 1] : undefined);
35
+
36
+ /**
37
+ * am8 item 1 and am9 item 5: the draft's ledger rows, one per Not checked list row, for the draft's own `log.json` `log` list (no new file). A `~` rule's words are its own text.
38
+ * @param {any} declaration @param {any[]} lines @param {Record<string, string[]>} [wordsByKey] the words the build gave a row (its name)
39
+ * @returns {{kind: 'ledger', phase: 'final', key: string, rowKind: string, words: string[], state: 'not-checked'}[]}
40
+ */
41
+ export function ledgerRowsOf(declaration, lines, wordsByKey = {}) {
42
+ const list = isRec(declaration) && Array.isArray(declaration.checkList) ? declaration.checkList : [];
43
+ return list.filter((r) => isListedNotChecked(list, r)).map((r) => ({ kind: /** @type {const} */ ('ledger'), phase: /** @type {const} */ ('final'), key: String(r.key), rowKind: String(r.kind), words: r.kind === 'rule' ? [ruleTextOf(lines, r) ?? ''] : wordsByKey[r.key] ?? [], state: /** @type {const} */ ('not-checked') }));
44
+ }
45
+
46
+ /** am8 item 1: the last ledger row per key wins (bareloop `readDraftLedger`). @param {unknown} log @returns {Map<string, any>} */
47
+ export function readLedger(log) {
48
+ const m = new Map();
49
+ for (const r of Array.isArray(log) ? log : []) if (isRec(r) && r.kind === 'ledger' && typeof r.key === 'string') m.set(r.key, r);
50
+ return m;
51
+ }
52
+
53
+ /**
54
+ * The name of a Not checked row: am9 item 1 (a `~` rule: `line <n>: "<rule text>" - <reason>`, else `line <n>: rule <n> - <reason>`), item 2 (prose or stage: `line <n>: <reason>`), item 3 (cited, numbers, note: fixed words),
55
+ * item 4 and am8 item 2 (any other: `<kind> "<ledger words>"`, else its key's tail). The dash is an em dash with a space each side.
56
+ * @param {any} r the signed row @param {string|undefined} ruleText @param {string[]|undefined} words
57
+ */
58
+ export function notCheckedName(r, ruleText, words) {
59
+ const reason = r.reason ?? '';
60
+ if (r.kind === 'rule') return ruleText !== undefined ? `line ${r.line}: "${ruleText}" — ${reason}` : `line ${r.line}: rule ${r.rule} — ${reason}`;
61
+ if (r.kind === 'prose' || r.kind === 'stage') return `line ${r.line}: ${reason}`;
62
+ if (r.kind in DEFAULT_ROW_WORDS) return DEFAULT_ROW_WORDS[/** @type {'cited'|'numbers'|'note'} */ (r.kind)];
63
+ const tail = String(r.key).replace(/^L\d+\.(?:[^.]*\.)?/, '').trim();
64
+ const w = Array.isArray(words) && words.length ? words : [tail || r.key];
65
+ return `${r.kind} ${w.map((x) => `"${x}"`).join(', ')}`;
66
+ }
67
+
68
+ /**
69
+ * The Not checked ITEM a plan saves for a list row (the string the readout, the Job tab, the Audit and the card's Not checked group read, src/checklook.js `ncRowsOf`): the row's name, with the code-written prefix `line <n>: ` for a row whose name
70
+ * does not name its line (the prefix is how the surfaces place a row under its job line; `ncRowsOf` strips it), and M10 am17 (6)'s words when a Revise carried the row. ONE writer: src/blockassemble.js and the reader both call it.
71
+ * @param {any} r the signed row @param {string|undefined} ruleText @param {string[]|undefined} words @param {boolean} [keptFromLast]
72
+ */
73
+ export function notCheckedItem(r, ruleText, words, keptFromLast = false) {
74
+ const name = notCheckedName(r, ruleText, words);
75
+ const own = r.kind === 'rule' || r.kind === 'prose' || r.kind === 'stage' ? name : `line ${r.line}: ${name}`;
76
+ return keptFromLast ? `${own} (${KEPT_WORDS})` : own;
77
+ }
78
+
79
+ /**
80
+ * The rows of ONE step's close, in the close's part order (facts, the result count, the field rows of a list of items, each picked check, the numbers tie), each with `idx`, the index of the part the signed list's rows point at (src/checklistsign.js).
81
+ * The ONE place the words of these rows are written: the card, the readout, the Job tab and the Audit's Checks fold all read them from here.
82
+ * @param {{declaration: any, st: any, lines: any[], kept?: {line: number, check?: any, rule?: number}[], idx?: number}} o `idx` = the first part's index (the parts the earlier steps of the line have)
83
+ * @returns {{rows: any[], next: number}}
84
+ */
85
+ export function stepRowsOf({ declaration, st, lines, kept = [], idx = 0 }) {
86
+ const list = isRec(declaration) && Array.isArray(declaration.checkList) ? declaration.checkList.filter(isRec) : [];
87
+ const builtOn = (/** @type {number} */ line) => list.filter((r) => r.line === line && r.state === 'built' && r.kind !== 'floor');
88
+ const owner = (/** @type {any[]} */ rows) => rows.find((r) => r.by === 'you') ?? rows[0] ?? null; // am7 item 5: the first [you] row
89
+ /** @type {any[]} */
90
+ const out = [];
91
+ const line = st.fromLine;
92
+ const close = isRec(st.close) ? st.close : {};
93
+ if (isRec(close.cited)) {
94
+ const c = close.cited;
95
+ for (const f of Array.isArray(c.facts) ? c.facts : []) {
96
+ const own = owner(builtOn(line).filter((r) => Array.isArray(r.facts) && r.facts.includes(f.name)));
97
+ out.push({ line, key: own?.key ?? `L${line}.fact.${f.name}`, by: own?.by ?? 'agent', state: 'built', kind: 'truth', text: factSentence(f, c.source), reason: null, idx, part: `L${line}:fact:${f.name}` });
98
+ }
99
+ const cs = countSentence(c);
100
+ if (cs) {
101
+ const own = builtOn(line).find((r) => r.kind === 'count');
102
+ out.push({ line, key: own?.key ?? `L${line}.count`, by: own?.by ?? 'agent', state: 'built', kind: 'truth', text: cs, reason: null, idx, part: `L${line}:count` });
103
+ }
104
+ idx += 1;
105
+ }
106
+ if (isRec(close.itemShape)) {
107
+ const shim = { stages: [{ kind: 'rubric-step', params: { step: line, parts: [{ ...close.itemShape, class: 'shape' }] } }] };
108
+ for (const x of shapeRowsOf(shim, lines.map((l) => ({ n: l.n, text: l.text, rules: rulesOfLine(l) })))) {
109
+ const signed = list.find((r) => r.key === x.key);
110
+ if (x.by === 'default' && !signed) continue;
111
+ out.push({ line, key: x.key, by: signed?.by ?? x.by, state: 'built', kind: kindOfCheck({ key: x.key, shape: true }), text: x.text, reason: null, idx, part: `L${line}:shape:${/** @type {any} */ (x).name ?? '$'}` });
112
+ }
113
+ // M19 am11 item 1: a `~` rule whose words are the part's item count is its own [you] row on the shape part (the rule points at the part, no field is its rule)
114
+ const fieldRules = new Set(close.itemShape.fields.filter(isRec).map((/** @type {any} */ f) => f.rule));
115
+ const countWords = shapeCountWords(close.itemShape);
116
+ for (const r of builtOn(line).filter((x) => x.kind === 'rule' && x.by === 'you' && isRec(x.part) && x.part.part === idx && !fieldRules.has(x.rule) && !out.some((o) => o.key === x.key))) {
117
+ if (countWords !== null) out.push({ line, key: r.key, by: 'you', state: 'built', kind: kindOfCheck({ key: r.key, shape: true }), text: countWords, reason: null, idx, part: `L${line}:shape:$` });
118
+ }
119
+ idx += 1;
120
+ }
121
+ const picked = Array.isArray(close.picked) ? close.picked : isRec(close.shape) && Array.isArray(close.shape.picked) ? close.shape.picked : [];
122
+ for (const c of picked) {
123
+ const own = owner(builtOn(line).filter((r) => isRec(r.part) && r.part.part === idx));
124
+ const isKept = kept.some((k) => k.line === line && isRec(k.check) && plainWords(k.check) === plainWords(c));
125
+ out.push({ line, key: own?.key ?? `L${line}.pick.${idx}`, by: own?.by ?? 'agent', state: 'built', kind: 'truth', text: `${plainWords(c)}${isKept ? ` · ${KEPT_WORDS}` : ''}`, reason: null, idx, part: `L${line}:pick:${idx}` });
126
+ idx += 1;
127
+ }
128
+ if (Array.isArray(close.numbersFrom) && close.numbersFrom.length > 0) {
129
+ const own = owner(builtOn(line).filter((r) => r.kind === 'numbers' || (isRec(r.part) && r.part.part === idx)));
130
+ out.push({ line, key: own?.key ?? `L${line}.$numbers`, by: own?.by ?? 'default', state: 'built', kind: 'truth', text: numbersWords(close.numbersFrom), reason: null, idx, part: `L${line}:numbers` });
131
+ idx += 1;
132
+ }
133
+ return { rows: out, next: idx };
134
+ }
135
+
136
+ /**
137
+ * The card's rows and its Not checked list, read from the signed plan.
138
+ * @param {{declaration: any, lines: {n: number, text?: string, guardrail?: string}[], csvRoles?: string[], kept?: {line: number, check?: any, rule?: number}[], log?: unknown}} o `log` = the draft's own `log.json` `log` list (the ledger rows are read from it)
139
+ * @returns {{rows: {line: number, key: string, by: string, state: string, kind: string, text: string, reason: string|null, drop?: boolean, part: string}[], notChecked: {line: number, key: string, by: string, state: 'not-checked', kind: string, text: string, reason: string|null, part: string}[]}}
140
+ */
141
+ export function cardOfPlan({ declaration, lines, csvRoles = [], kept = [], log = [] }) {
142
+ const led = readLedger(log);
143
+ const list = isRec(declaration) && Array.isArray(declaration.checkList) ? declaration.checkList.filter(isRec) : [];
144
+ const steps = isRec(declaration) && Array.isArray(declaration.steps) ? declaration.steps.filter(isRec) : [];
145
+ const listed = list.filter((r) => isListedNotChecked(list, r));
146
+ const listedKeys = new Set(listed.map((r) => r.key));
147
+ /** @type {any[]} */
148
+ const out = [];
149
+ const cardLines = cardLinesOf(declaration);
150
+ const offsets = new Map();
151
+ for (const st of steps) {
152
+ const line = st.fromLine;
153
+ if (!Number.isInteger(line) || !cardLines.has(line)) continue;
154
+ const r = stepRowsOf({ declaration, st, lines, kept, idx: offsets.get(line) ?? 0 });
155
+ out.push(...r.rows);
156
+ offsets.set(line, r.next);
157
+ }
158
+ // fwd's own rows keep their own drawing (am6 item 5): sheet rows (`sheetRowsOf`), Tickets rows (`ticketRowsOf`, only where the signed list holds the row, am7 item 7)
159
+ const sheet = sheetRowsOf({ declaration: { ...declaration, checkList: undefined }, lines, csvRoles });
160
+ for (const r of sheet.card) if (!listedKeys.has(r.key)) out.push({ line: r.line, key: r.key, by: r.by, state: r.state, text: r.text, reason: r.reason, drop: r.drop === true, part: r.key }); // fwd's own sheet rows carry no kind word, as before
161
+ const tk = ticketRowsOf({ declaration, lines });
162
+ for (const r of tk.card) if (list.some((x) => x.key === r.key)) out.push({ line: r.line, key: r.key, by: r.by, state: r.state, text: r.text, reason: r.reason, part: r.key });
163
+ // the floor rows
164
+ for (const r of list) {
165
+ if (r.kind !== 'floor') continue;
166
+ const on = steps.filter((s) => s.fromLine === r.line).map((s) => s.close ?? {});
167
+ const listLine = on.some((c) => isRec(c.itemShape)) && !on.some((c) => isRec(c.cited)) && !on.some((c) => (Array.isArray(c.picked) && c.picked.length) || (Array.isArray(c.shape?.picked) && c.shape.picked.length) || (Array.isArray(c.numbersFrom) && c.numbersFrom.length));
168
+ out.push({ line: r.line, key: r.key, by: r.by, state: 'built', kind: kindOfCheck({ key: r.key }), text: listLine ? FLOOR_LIST_WORDS : FLOOR_WORDS, reason: null, part: r.key });
169
+ }
170
+ // am7 item 4: sheet; (a Tickets row after the sheet rows); facts, then the result count; shape; picks; then the defaults (cited, numbers); the floor row last
171
+ const rank = (/** @type {any} */ r) => (/\.sheet\./.test(r.key) ? 0 : /\.ticket\./.test(r.key) ? 0.5 : /:fact:/.test(r.part) ? 1 : /:count$/.test(r.part) ? 2 : /:shape:/.test(r.part) ? 3 : /:pick:/.test(r.part) ? 4 : /:numbers$/.test(r.part) ? 5 : /\$floor$/.test(r.key) ? 6 : 4.5);
172
+ const rows = out.map((r, i) => ({ ...r, rank: rank(r), i })).sort((a, b) => a.line - b.line || a.rank - b.rank || a.i - b.i).map(({ rank: _r, i: _i, ...r }) => r);
173
+ // am8 item 3: the Not checked rows are a list of their own, in the signed list's order
174
+ const notChecked = listed.map((r) => ({ line: /** @type {number} */ (r.line), key: String(r.key), by: String(r.by), state: /** @type {const} */ ('not-checked'), kind: 'truth', reason: r.reason ?? null, part: `nc:${r.key}`, text: notCheckedName(r, ruleTextOf(lines, r), led.get(r.key)?.words) }));
175
+ return { rows, notChecked };
176
+ }
177
+
178
+ /**
179
+ * M19 am6 item 3 (bareloop `planMatchesClose`): the checks a card shows must equal the checks the signed plan runs, line by line. Returns the reds, each naming the line; empty = they match. Pure.
180
+ * @param {{declaration: any, lines: any[], csvRoles?: string[], kept?: any[], log?: unknown}} plan @param {any} card the card as shown
181
+ * @returns {string[]}
182
+ */
183
+ export function planMatchesCard(plan, card) {
184
+ if (!isRec(card) || !Array.isArray(card.rows)) return [];
185
+ const want = cardOfPlan(plan).rows;
186
+ const shown = (/** @type {any[]} */ rows, /** @type {number} */ n) => rows.filter((r) => r.line === n && r.state === 'built').map((r) => `${r.key}|${r.by}|${r.text}`);
187
+ const lines = [...new Set([...want.map((r) => r.line), ...card.rows.filter((r) => isRec(r) && Number.isInteger(r.line)).map((r) => r.line)])].sort((a, b) => a - b);
188
+ return lines.filter((n) => shown(want, n).join('\n') !== shown(card.rows, n).join('\n')).map((n) => `The card shows different checks from the plan on line ${n}. Nothing was signed - draft again.`);
189
+ }
190
+
191
+ /**
192
+ * The card as the draft saves and the panel draws it: the block's own card (suggestions, restorable, the Drop flags) with its rows read from the signed plan and its Not checked list beside them.
193
+ * A Drop flag is joined by key from the block's card; a row the block's card has no flag for keeps the flag its own reader gave it (a sheet row), else false.
194
+ * @param {any} card the block's card (src/cardlist.js, with the sheet and Tickets rows) @param {Parameters<typeof cardOfPlan>[0]} plan
195
+ */
196
+ export function planCard(card, plan) {
197
+ const { rows, notChecked } = cardOfPlan(plan);
198
+ const dropOf = new Map((Array.isArray(card?.rows) ? card.rows : []).filter(isRec).map((/** @type {any} */ r) => [r.key, r.drop === true]));
199
+ // the saved card keeps only what the page draws: a row's key, line, tag, state, words, reason, Drop flag and kind (its part is the reader's own)
200
+ const rowOf = (/** @type {any} */ r) => ({ key: r.key, line: r.line, by: r.by, state: r.state, text: r.text, reason: r.reason ?? null, drop: dropOf.has(r.key) ? dropOf.get(r.key) : r.drop === true, ...(r.kind ? { kind: r.kind } : {}) });
201
+ return { ...card, rows: rows.map(rowOf), notChecked: notChecked.map(({ part: _p, ...r }) => r) };
202
+ }
@@ -9,7 +9,7 @@
9
9
  // Throws away: bareguard's evidence beyond the marks of the claim's own spans; nothing: a red line keeps its judged rows (am9); only a stopped check has none.
10
10
  import { writeLineSection, readLineSection } from './line-checks.js';
11
11
  import { moneyAs } from './pageask.js';
12
- import { factSentence, countSentence, CITED_ID } from './citedcheck.js';
12
+ import { factSentence, countSentence, quotedWords, CITED_ID } from './citedcheck.js';
13
13
 
14
14
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
15
15
 
@@ -84,7 +84,7 @@ export function citedLineOf({
84
84
  quote,
85
85
  ...(proof ? { proof } : {}),
86
86
  cells: part.facts.map((/** @type {any} */ f, /** @type {number} */ j) => {
87
- if (f.shape === 'phrase') return String(f.phrase);
87
+ if (f.shape === 'phrase') return Array.isArray(f.anyOf) ? `one of the words ${quotedWords(f.anyOf)}` : String(f.phrase);
88
88
  const v = cellText(values[f.name]);
89
89
  if (f.shape === 'money') return (proof ? moneyAsRead(ev, j) : null) ?? (/^\d[\d.,]*$/.test(v.trim()) ? moneyAs(f, v.trim(), true) : v);
90
90
  return v;
package/src/citedcheck.js CHANGED
@@ -29,9 +29,16 @@ const CHECKPOINT = 'cited';
29
29
  export const CITED_ID = 'facts';
30
30
 
31
31
  /** every field a fact part may carry, and every field a fact may carry */
32
- const PART_FIELDS = Object.freeze(['source', 'facts', 'count']);
32
+ // borrowed-from: bareloop src/facts.js@v0.60.0 (`asSeen`, F337: optional, written only by code at signing; absent on every older job)
33
+ const PART_FIELDS = Object.freeze(['source', 'facts', 'count', 'asSeen']);
33
34
  // borrowed-from: bareloop src/facts.js@v0.56.0 (3383cce) (M16 am3 (3): the fields lang, decimal, place, aiProposal; FACT_LANGS, FACT_DECIMALS, moneyForms, factPartOf, factShapeReds, writtenSpans below; factDecides, factClaims, factSentence taken up to it)
34
- const FACT_FIELDS = Object.freeze(['name', 'shape', 'unit', 'currency', 'phrase', 'anchor', 'until', 'rule', 'aiProposal', 'lang', 'decimal', 'place']);
35
+ // M19 am5: `anyOf` is the page phrase fact with SEVERAL words (a quote passes on any one of them, on word edges); a fact with one word keeps `phrase`, exactly as before. `phrases` is the place fact's (all-of) and is not a fact field.
36
+ // (diverges from bareloop v0.61.0, whose lookFactOf keeps only the first word)
37
+ const FACT_FIELDS = Object.freeze(['name', 'shape', 'unit', 'currency', 'phrase', 'anyOf', 'anchor', 'until', 'rule', 'aiProposal', 'lang', 'decimal', 'place']);
38
+ /** @param {any} f a phrase fact @returns {string[]} the words it checks: its alternatives, or its one phrase */
39
+ export const phraseWordsOf = (f) => (Array.isArray(f.anyOf) ? f.anyOf.map(String) : [String(f.phrase)]);
40
+ /** @param {string[]} words @returns {string} `"United", "JetBlue"`: the words as the signed texts list them */
41
+ export const quotedWords = (words) => words.map((w) => `"${w}"`).join(', ');
35
42
  const NAME_RE = /^[A-Za-z][A-Za-z _-]{0,63}$/;
36
43
 
37
44
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
@@ -63,6 +70,9 @@ function unitsOnce(units) {
63
70
  */
64
71
  export function factsOfLook(k) {
65
72
  if (k.shape === 'phrase' || k.shape === 'place') {
73
+ // M19 am5: a plain phrase fact (no `phrases`) with several look words signs ALL of them as one fact (any one, on word edges); one word signs `phrase` as before
74
+ const alts = Array.isArray(k.phrases) ? [] : [...new Set(/** @type {unknown[]} */ (Array.isArray(k.words) ? k.words : []).map(String))];
75
+ if (alts.length > 1) return [{ name: String(k.name), shape: 'phrase', anyOf: alts }];
66
76
  const phrases = Array.isArray(k.phrases) ? k.phrases : [k.phrase ?? k.words?.[0] ?? ''];
67
77
  return phrases.map((/** @type {unknown} */ p, /** @type {number} */ i) => ({ name: phrases.length > 1 ? `${k.name} ${String.fromCharCode(97 + i)}` : String(k.name), shape: 'phrase', phrase: String(p) }));
68
78
  }
@@ -88,6 +98,7 @@ export function factPartReds(part) {
88
98
  const reds = [];
89
99
  if (!isRec(part) || typeof part.source !== 'string' || part.source.trim() === '') return ['a fact part needs the role of the input its quotes come from'];
90
100
  if (!Array.isArray(part.facts) || part.facts.length === 0 || part.facts.length > MAX_FACTS) return [`a fact part needs 1 to ${MAX_FACTS} facts${Array.isArray(part.facts) && part.facts.length > MAX_FACTS ? ` (it has ${part.facts.length}; a place counts one fact for each phrase it needs, so a line with many places or many rules is too much for one check)` : ''}`];
101
+ if (Object.hasOwn(part, 'asSeen') && !asSeenOk(part.asSeen)) reds.push('a fact part\'s asSeen is {input, lines: [..], labels: [..]}');
91
102
  for (const k of Object.keys(part)) if (!PART_FIELDS.includes(k)) reds.push(`a fact part has no field "${k}" - its fields are ${PART_FIELDS.join(', ')}`);
92
103
  const seen = new Set();
93
104
  part.facts.forEach((/** @type {any} */ f, /** @type {number} */ j) => {
@@ -99,11 +110,15 @@ export function factPartReds(part) {
99
110
  if (seen.has(f.name)) reds.push(`${w}: the name "${f.name}" is used twice`);
100
111
  seen.add(f.name);
101
112
  if (!FACT_SHAPES.includes(f.shape)) { reds.push(`${w} "${f.name}": the shape is not one of ${FACT_SHAPES.join(', ')}`); return; }
102
- if (f.shape === 'phrase' && (typeof f.phrase !== 'string' || f.phrase === '')) reds.push(`${w} "${f.name}": a phrase fact needs its words`);
113
+ if (f.shape === 'phrase' && f.anyOf !== undefined) {
114
+ if (f.phrase !== undefined || f.place !== undefined || !Array.isArray(f.anyOf) || f.anyOf.length < 2 || f.anyOf.some((/** @type {unknown} */ x) => typeof x !== 'string' || x.trim() === '') || new Set(f.anyOf.map((/** @type {string} */ x) => x.toLowerCase())).size !== f.anyOf.length) reds.push(`${w} "${f.name}": anyOf is two or more different words, and a fact carries either anyOf or phrase (no place rule with anyOf)`);
115
+ // word edges (bareguard's any-of presence decide) need each word to start and end with a letter or digit; refuse it here, never sign a check that stops at the run
116
+ else for (const x of f.anyOf) if (!/^[\p{L}\p{Nd}]/u.test(x) || !/[\p{L}\p{Nd}]$/u.test(x)) reds.push(`${w} "${f.name}": the word ${JSON.stringify(x)} must start and end with a letter or digit`);
117
+ } else if (f.shape === 'phrase' && (typeof f.phrase !== 'string' || f.phrase === '')) reds.push(`${w} "${f.name}": a phrase fact needs its words`);
103
118
  if (f.shape === 'money' && asList(f.unit).length + asList(f.currency).length === 0) reds.push(`${w} "${f.name}": money needs a unit or a currency`);
104
119
  if (f.shape !== 'money' && (f.unit !== undefined || f.currency !== undefined)) reds.push(`${w} "${f.name}": only money has a unit or a currency`);
105
120
  if (f.shape === 'phrase') for (const k of ['anchor', 'until', 'rule']) if (f[k] !== undefined) reds.push(`${w} "${f.name}": a phrase is fixed words the quote must contain; it has no ${k}`);
106
- if (f.shape !== 'phrase' && f.phrase !== undefined) reds.push(`${w} "${f.name}": only a phrase fact carries phrase`);
121
+ if (f.shape !== 'phrase' && (f.phrase !== undefined || f.anyOf !== undefined)) reds.push(`${w} "${f.name}": only a phrase fact carries phrase`);
107
122
  // the four fields of bareloop v0.56.0 (M16 am3 (3)); each is checked only when present, so a fact without them is judged exactly as before
108
123
  if (f.lang !== undefined && (f.shape !== 'date' || typeof f.lang !== 'string' || !Object.hasOwn(FACT_LANGS, f.lang))) reds.push(`${w} "${f.name}": lang is for a date fact, one of ${Object.keys(FACT_LANGS).join(', ')}`);
109
124
  if (f.decimal !== undefined && ((f.shape !== 'number' && f.shape !== 'money') || !FACT_DECIMALS.includes(f.decimal))) reds.push(`${w} "${f.name}": decimal is for a number or money fact, "." or ","`);
@@ -134,7 +149,8 @@ export function factPartReds(part) {
134
149
  */
135
150
  export function factDecides(part) {
136
151
  return part.facts.map((/** @type {any} */ f) => {
137
- if (f.shape === 'phrase') return { phrases: [f.phrase] };
152
+ // M19 am5: several words = any one of them, on word edges (bareguard 0.37.0 presence decide, ruling #79 / #69); one word = the all-of substring decide it always was
153
+ if (f.shape === 'phrase') return Array.isArray(f.anyOf) ? { phrases: f.anyOf, any: true, edges: true } : { phrases: [f.phrase] };
138
154
  /** @type {Record<string, any>} */
139
155
  const d = { valueKind: f.shape };
140
156
  if (f.shape === 'money') { if (f.unit !== undefined) d.unit = f.unit; if (f.currency !== undefined) d.currency = f.currency; }
@@ -155,7 +171,7 @@ export function factDecides(part) {
155
171
  * a phrase fact contributes its own signed words. A result that is not an object, or has no string quote, still becomes a claim (an empty one) so
156
172
  * bareguard reds it by name rather than the result vanishing.
157
173
  * `asWritten` (bareloop v0.56.0): per result, per fact index, the value as the page writes it, for the claim's words of a date or amount a page form signs.
158
- * @param {any} part @param {unknown} results @param {Record<number, string>[]} [asWritten] @returns {{claim: string, quote: string, values?: Record<string, string>}[]}
174
+ * @param {any} part @param {unknown} results @param {(Record<number, string>|undefined)[]} [asWritten] @returns {{claim: string, quote: string, values?: Record<string, string>}[]}
159
175
  */
160
176
  export function factClaims(part, results, asWritten = []) {
161
177
  const list = Array.isArray(results) ? results : [];
@@ -166,7 +182,8 @@ export function factClaims(part, results, asWritten = []) {
166
182
  /** @type {string[]} */
167
183
  const said = [];
168
184
  part.facts.forEach((/** @type {any} */ f, /** @type {number} */ j) => {
169
- if (f.shape === 'phrase') { said.push(`${f.name}: ${f.phrase}`); return; }
185
+ // M19 am5: an anyOf fact's claim carries only its name: the quote may say any one word, and a word with a digit ("1 stop") the quote lacks must not make the claim's number unsupported
186
+ if (f.shape === 'phrase') { said.push(Array.isArray(f.anyOf) ? String(f.name) : `${f.name}: ${f.phrase}`); return; }
170
187
  const v = given && Object.hasOwn(given, f.name) ? given[f.name] : undefined;
171
188
  // a JSON number is the value as written ("389"): converted, never repaired; anything else is left for bareguard to red
172
189
  const s = typeof v === 'number' && Number.isFinite(v) ? String(v) : v;
@@ -195,6 +212,8 @@ export function buildCitedSpec(part, sha256) {
195
212
  */
196
213
  export function factSentence(f, source) {
197
214
  // PLACE RULES (v0.56.0): a check that reads WHERE the newest value sits, not what it is; the phrase shown is the signed drafting example
215
+ // M19 am5 item 3: the row of a several-word phrase fact, in the signed words
216
+ if (f.shape === 'phrase' && Array.isArray(f.anyOf)) return `fact "${f.name}" with one of the words ${quotedWords(f.anyOf)}`;
198
217
  if (f.shape === 'phrase' && isRec(f.place)) return `${f.place.kind === 'headingDateAfter' ? 'date' : 'version'} in the newest "${f.place.prefix}" heading (last read ${f.phrase})`;
199
218
  /** @type {string[]} */
200
219
  const bits = [];
@@ -217,6 +236,12 @@ export const FACT_LANGS = Object.freeze({ en: 'English', de: 'German', fr: 'Fren
217
236
  /** the decimal marks a number or money fact may sign (bareguard 0.27 `decimal`); absent = "." */
218
237
  export const FACT_DECIMALS = Object.freeze(['.', ',']);
219
238
 
239
+ /** @param {unknown} a @returns {boolean} the shape of `asSeen`: {input, lines: [string..], labels: [string..]}, nothing else */
240
+ const asSeenOk = (/** @type {any} */ a) => {
241
+ const strs = (/** @type {unknown} */ v) => Array.isArray(v) && v.length > 0 && v.every((x) => typeof x === 'string');
242
+ return isRec(a) && typeof a.input === 'string' && a.input.trim() !== '' && strs(a.lines) && strs(a.labels) && Object.keys(a).every((k) => ['input', 'lines', 'labels'].includes(k));
243
+ };
244
+
220
245
  /** every field a part of class `fact` may carry (the shared ones are checked by rubricStepShapeReds) */
221
246
  export const FACT_PART_FIELDS = PART_FIELDS;
222
247
 
@@ -241,11 +266,13 @@ export function factPartOf(params) {
241
266
  */
242
267
  export function factShapeReds(part, w, red) {
243
268
  for (const k of Object.keys(part)) {
244
- if (!['text', 'class', 'covers', 'rules', 'source', 'facts', 'count'].includes(k)) {
269
+ if (!['text', 'class', 'covers', 'rules', 'source', 'facts', 'count', 'asSeen'].includes(k)) {
245
270
  red('invalid-value', `${w}.${k}`, `"${k}" is not a field of a fact part — fields: text, class, covers, rules, ${FACT_PART_FIELDS.join(', ')}`);
246
271
  }
247
272
  }
248
273
  if (!(nonEmpty(part.source) && part.source.length <= 128)) red('invalid-value', `${w}.source`, 'the label of the input the quotes come from');
274
+ // F337: the planner's "as seen" example, only ever written by code at signing (src/pagedry.js asSeenOf); optional, absent on every older spec
275
+ if (Object.hasOwn(part, 'asSeen') && !asSeenOk(part.asSeen)) red('invalid-value', `${w}.asSeen`, 'the as-seen example: {input, lines: [..], labels: [..]}');
249
276
  if (!Array.isArray(part.facts) || part.facts.length === 0 || part.facts.length > MAX_FACTS) {
250
277
  red('invalid-value', `${w}.facts`, `a list of 1 to ${MAX_FACTS} facts {name, shape, ...}`);
251
278
  } else {
@@ -297,9 +324,11 @@ export function factShapeReds(part, w, red) {
297
324
  else if (!FACT_DECIMALS.includes(f.decimal)) red('invalid-value', `${fw}.decimal`, 'one of "." | ","');
298
325
  }
299
326
  if (f.shape === 'phrase') {
300
- if (!nonEmpty(f.phrase)) red('invalid-value', `${fw}.phrase`, 'the fixed words the quote must contain, copied from the input');
327
+ if (has('anyOf')) {
328
+ if (has('phrase') || has('place') || !Array.isArray(f.anyOf) || f.anyOf.length < 2 || f.anyOf.some((/** @type {unknown} */ x) => !nonEmpty(x)) || new Set(f.anyOf.map((/** @type {string} */ x) => x.toLowerCase())).size !== f.anyOf.length || f.anyOf.some((/** @type {string} */ x) => !/^[\p{L}\p{Nd}]/u.test(x) || !/[\p{L}\p{Nd}]$/u.test(x))) red('invalid-value', `${fw}.anyOf`, 'two or more different words, each starting and ending with a letter or digit, any one of which the quote must contain; a fact carries anyOf or phrase, not both');
329
+ } else if (!nonEmpty(f.phrase)) red('invalid-value', `${fw}.phrase`, 'the fixed words the quote must contain, copied from the input');
301
330
  for (const k of ['anchor', 'until', 'rule']) if (has(k)) red('invalid-value', `${fw}.${k}`, 'a phrase is fixed words the quote must contain; it has no anchor, until or rule');
302
- } else if (has('phrase')) red('invalid-value', `${fw}.phrase`, 'only a phrase fact carries phrase');
331
+ } else if (has('phrase') || has('anyOf')) red('invalid-value', `${fw}.${has('phrase') ? 'phrase' : 'anyOf'}`, 'only a phrase fact carries phrase');
303
332
  if (has('place')) {
304
333
  const bad = f.shape === 'phrase' ? placeRuleProblem(f.place) : 'only a phrase fact carries a place rule';
305
334
  if (bad !== null) red('invalid-value', `${fw}.place`, bad);
@@ -367,6 +396,8 @@ export function countSentence(part) {
367
396
  * @param {any} f @returns {string}
368
397
  */
369
398
  export function factBrief(f) {
399
+ // M19 am5 item 3: the step is told the alternatives in the signed words
400
+ if (f.shape === 'phrase' && Array.isArray(f.anyOf)) return `${f.name} - no value to write; the quote you copy must say one of: ${quotedWords(f.anyOf)}`;
370
401
  if (f.shape === 'phrase') return `${f.name} - no value to write; the quote you copy must say "${f.phrase}"`;
371
402
  /** @type {string[]} */
372
403
  const bits = [f.shape === 'money' ? `an amount in ${[...asList(f.unit), ...asList(f.currency)].join(' or ')}` : f.shape === 'text' ? 'words' : `a ${f.shape}`];
@@ -441,6 +472,8 @@ export function plainFactItem(item, part) {
441
472
  case 'anchor-ambiguous': return say(`the label "${f ? f.anchor : ''}" is in the quote more than once`);
442
473
  case 'until-missing': return say(`"${f ? f.until : ''}" does not follow the label "${f ? f.anchor : ''}" in the quote`);
443
474
  case 'phrase-missing': return say(`the quote does not say "${detail}"`);
475
+ // M19 am5 item 3: bareguard's any-of presence decide reports `none-found` when no word is in the quote; the red names the signed words
476
+ case 'none-found': return say(f && Array.isArray(f.anyOf) ? `the quote says none of ${quotedWords(f.anyOf)}` : 'the quote says none of the words');
444
477
  case 'claim-value-missing': return say('no value was given in "values"');
445
478
  case 'claim-value-malformed': return say(`the value is not written as a value of this kind${f && f.shape === 'money' ? ' - write only the digits of the amount (for example 30), no unit or sign' : ''}`);
446
479
  case 'claim-value-absent': return say('the value is not in the quote as a whole word');
@@ -480,9 +513,17 @@ export async function checkCited({ part, text, results }) {
480
513
  try { rubric = createRubric(buildCitedSpec(part, sha256)); } catch (e) {
481
514
  return { verdict: 'stopped', gapLines: [], fault: `the check could not be built: ${/** @type {Error} */ (e).message}`, ...none };
482
515
  }
483
- const claims = factClaims(part, results);
516
+ let claims = factClaims(part, results);
484
517
  // `count` is set HERE from the list itself: the step never writes a number the check trusts
485
- const r = await checkStep(rubric, CHECKPOINT, { count: claims.length, claims }, { inputs: { [part.source]: text } });
518
+ let r = await checkStep(rubric, CHECKPOINT, { count: claims.length, claims }, { inputs: { [part.source]: text } });
519
+ // borrowed-from: bareloop src/rubricstep.js@v0.61.0
520
+ if (Array.isArray(part.facts) && part.facts.some((/** @type {any} */ f) => isRec(f) && (f.lang !== undefined || f.decimal !== undefined))) {
521
+ const written = writtenSpans(part, r.full.evidence);
522
+ if (written.some(Boolean)) {
523
+ claims = factClaims(part, results, written);
524
+ r = await checkStep(rubric, CHECKPOINT, { count: claims.length, claims }, { inputs: { [part.source]: text } });
525
+ }
526
+ }
486
527
  if (r.verdict === 'stopped') return { verdict: 'stopped', gapLines: [], fault: r.fault ? `${r.fault.kind}: ${r.fault.detail}` : 'the check stopped', ...none, claims };
487
528
  const evidence = Array.isArray(r.full?.evidence) ? r.full.evidence : [];
488
529
  if (r.verdict === 'green') return { verdict: 'green', gapLines: [], fault: null, sha256, claims, evidence };