fwdloop 0.32.0 → 0.34.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 (114) hide show
  1. package/bin/fwdloop +20 -2
  2. package/package.json +2 -2
  3. package/src/auditchecks.js +55 -0
  4. package/src/authoring.js +53 -12
  5. package/src/blockasks.js +45 -0
  6. package/src/blockassemble.js +159 -0
  7. package/src/blockdraft.js +86 -0
  8. package/src/blocklines.js +30 -0
  9. package/src/blockpick.js +175 -0
  10. package/src/cardlist.js +19 -0
  11. package/src/checkblock.js +843 -0
  12. package/src/checked.js +48 -9
  13. package/src/checklist.js +99 -0
  14. package/src/checklistsign.js +93 -0
  15. package/src/checkpick.js +7 -73
  16. package/src/checkwords.js +20 -1
  17. package/src/cited-record.js +21 -1
  18. package/src/citedcheck.js +162 -7
  19. package/src/closers.js +41 -3
  20. package/src/declaration.js +34 -9
  21. package/src/declaredclose.js +4 -0
  22. package/src/draft-steps.js +3 -1
  23. package/src/drafter.js +311 -206
  24. package/src/factwords.js +112 -0
  25. package/src/inputlook.js +53 -0
  26. package/src/labelscan.js +162 -0
  27. package/src/noteask.js +62 -0
  28. package/src/pageask.js +9 -69
  29. package/src/pagedropwords.js +11 -1
  30. package/src/pagedry.js +27 -4
  31. package/src/pagerules.js +19 -3
  32. package/src/panel/author.js +76 -7
  33. package/src/panel/authorcard.js +43 -17
  34. package/src/panel/data.js +41 -9
  35. package/src/panel/index.html +208 -13
  36. package/src/panel/result.js +4 -3
  37. package/src/panel/server.js +3 -1
  38. package/src/pickrecord.js +70 -54
  39. package/src/placerule.js +398 -0
  40. package/src/planrebuild.js +216 -0
  41. package/src/rowedit.js +148 -0
  42. package/src/rubricstep.js +272 -0
  43. package/src/runfile.js +4 -2
  44. package/src/runner.js +67 -10
  45. package/src/setup.js +11 -5
  46. package/src/sheetblock.js +22 -8
  47. package/src/sheetbuild.js +151 -0
  48. package/src/sheetchecks.js +52 -66
  49. package/src/sheetclaims.js +12 -32
  50. package/src/sheetfind.js +4 -4
  51. package/src/sheetlook.js +14 -3
  52. package/src/sheetoffer.js +74 -57
  53. package/src/sheetrows.js +123 -0
  54. package/src/sheetrun.js +13 -10
  55. package/src/summary-words.js +3 -3
  56. package/src/ticket-draft.js +4 -21
  57. package/src/ticketrows.js +100 -0
  58. package/src/try-checks.js +31 -12
  59. package/src/types.js +1 -0
  60. package/types/auditchecks.d.ts +25 -0
  61. package/types/authoring.d.ts +21 -2
  62. package/types/blockasks.d.ts +36 -0
  63. package/types/blockassemble.d.ts +50 -0
  64. package/types/blockdraft.d.ts +75 -0
  65. package/types/blocklines.d.ts +31 -0
  66. package/types/blockpick.d.ts +46 -0
  67. package/types/cardlist.d.ts +21 -0
  68. package/types/checkblock.d.ts +378 -0
  69. package/types/checked.d.ts +16 -2
  70. package/types/checklist.d.ts +115 -0
  71. package/types/checklistsign.d.ts +27 -0
  72. package/types/checkpick.d.ts +4 -34
  73. package/types/checkwords.d.ts +5 -0
  74. package/types/cited-record.d.ts +9 -0
  75. package/types/citedcheck.d.ts +33 -2
  76. package/types/closers.d.ts +24 -2
  77. package/types/declaration.d.ts +7 -0
  78. package/types/declaredclose.d.ts +2 -0
  79. package/types/drafter.d.ts +29 -715
  80. package/types/factwords.d.ts +38 -0
  81. package/types/inputlook.d.ts +49 -0
  82. package/types/labelscan.d.ts +35 -0
  83. package/types/noteask.d.ts +52 -0
  84. package/types/pageask.d.ts +2 -35
  85. package/types/pagedry.d.ts +13 -0
  86. package/types/pagerules.d.ts +7 -0
  87. package/types/panel/author.d.ts +41 -0
  88. package/types/panel/authorcard.d.ts +14 -9
  89. package/types/panel/authorflows.d.ts +4 -4
  90. package/types/panel/data.d.ts +5 -3
  91. package/types/panel/jobgrid.d.ts +1 -1
  92. package/types/pickrecord.d.ts +69 -13
  93. package/types/placerule.d.ts +208 -0
  94. package/types/planrebuild.d.ts +52 -0
  95. package/types/provider.d.ts +1 -1
  96. package/types/rowedit.d.ts +48 -0
  97. package/types/rubricstep.d.ts +63 -0
  98. package/types/runfile.d.ts +5 -2
  99. package/types/runner.d.ts +45 -1
  100. package/types/sheetblock.d.ts +12 -4
  101. package/types/sheetbuild.d.ts +84 -0
  102. package/types/sheetchecks.d.ts +12 -18
  103. package/types/sheetclaims.d.ts +2 -1
  104. package/types/sheetfind.d.ts +2 -2
  105. package/types/sheetoffer.d.ts +31 -6
  106. package/types/sheetrows.d.ts +81 -0
  107. package/types/sheetrun.d.ts +4 -4
  108. package/types/summary-words.d.ts +2 -1
  109. package/types/ticket-draft.d.ts +3 -49
  110. package/types/ticketrows.d.ts +61 -0
  111. package/types/try-checks.d.ts +4 -2
  112. package/types/types.d.ts +8 -0
  113. package/src/repairs.js +0 -38
  114. package/types/repairs.d.ts +0 -13
@@ -1,16 +1,15 @@
1
1
  // M10b piece 1 (docs/wiki/the-module-ladder.md "M10b scope" item 4 and amendment 1): the signed checks of a sheet live in the job, in the step's close
2
2
  // (`close.sheet`). Each entry is a bareguard `cells` / `table` check object, kept as DATA exactly as bareguard defines it (src/primitives/rubric.js
3
3
  // `rubricVocabulary`); fwdloop has no check language of its own. Three things live here, each once:
4
- // - `sheetCheckColumns` every column name a check holds, wherever bareguard puts one (the code proves each is an exact header of the sheet);
5
- // - `sheetCheckReds` the $0 sign-time test: the checks are built into a bareguard rubric over the drafting copy's table (its `tableSha`), and a
6
- // refusal comes back as a red naming the job line;
4
+ // - `sheetCheckColumns` every column name a check holds, read from bareguard's vocabulary (`columnAt` on each field; the code proves each is an exact header of the sheet);
5
+ // - `sheetCheckReds` the $0 sign-time test: bareguard's `checkTables` judges the checks over the drafting copy's tables, and each problem it returns comes back
6
+ // as a red naming the job line, in fwdloop's words;
7
7
  // - `sheetCheckSentence` the plain words of one check, written from its typed fields, for the plan card and the readout.
8
8
  // Throws away: nothing is stored here; the sentence leaves out fields that do not change what the check says (id, claim, range, tolerance, valueKind).
9
9
  // Third outcomes, each named, never silently fine: a sheet bareguard cannot read as a table (`tableSha` null: a row with another cell count than the header,
10
10
  // a repeated header), a role with no drafting copy, a refusal by `createRubric`.
11
11
 
12
- import { createRubric, tableSha } from 'bareguard';
13
- import { numbersSaid } from './citedwords.js';
12
+ import { checkTables, tableSha, groundedLiterals, rubricVocabulary } from 'bareguard';
14
13
  import { wordsSaidOn, lineRules } from './pagebits.js';
15
14
 
16
15
  /** the bareguard rules a sheet check may use (`diff` is out of scope for M10b) */
@@ -20,26 +19,22 @@ export const MAX_SHEET_CHECKS = 20;
20
19
 
21
20
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
22
21
 
23
- /** the fields of a check that hold a column name as a plain string (the ONE list: {@link sheetCheckColumns} reads it, the drafter's tool schema offers a header enum on each) */
24
- export const COLUMN_STRING_FIELDS = Object.freeze(['column', 'keyColumn', 'groupColumn', 'result']);
25
- /** the row-math operands: a column name, or (for `b`) `{const}` */
26
- export const COLUMN_OPERAND_FIELDS = Object.freeze(['a', 'b']);
27
- /** the date-cell fields: `{column, row}` */
28
- export const COLUMN_CELL_FIELDS = Object.freeze(['from', 'to', 'cell']);
29
- /** the list fields whose entries hold a `column` */
30
- export const COLUMN_LIST_FIELDS = Object.freeze(['where', 'dateFormats']);
22
+ const V = /** @type {any} */ (rubricVocabulary);
31
23
 
32
24
  /**
33
- * Every column name one check holds: its own `column`, `keyColumn`, `groupColumn`, `result`, a row-math operand `a` / `b` (a name; `{const}` is no column), the
34
- * date cells `from` / `to` / `cell`, and the column of each `where` condition and `dateFormats` entry.
25
+ * Every column name one check holds, read from bareguard's own vocabulary: each field of the check's rule that carries `columnAt` ("self": a name; "self.column": a cell
26
+ * `{column, row}`; "each.column": a list of `{column}`; "each": a list of names). A row-math `b` of `{const}` is no column. bareguard owns which fields these are.
35
27
  * @param {any} check @returns {string[]}
36
28
  */
37
29
  export function sheetCheckColumns(check) {
38
30
  if (!isRec(check)) return [];
39
31
  const out = [];
40
- for (const k of [...COLUMN_STRING_FIELDS, ...COLUMN_OPERAND_FIELDS]) if (typeof check[k] === 'string') out.push(check[k]);
41
- for (const k of COLUMN_CELL_FIELDS) if (isRec(check[k]) && typeof check[k].column === 'string') out.push(check[k].column);
42
- for (const k of COLUMN_LIST_FIELDS) if (Array.isArray(check[k])) for (const e of check[k]) if (isRec(e) && typeof e.column === 'string') out.push(e.column);
32
+ for (const [k, f] of Object.entries(V.rules[check.rule]?.fields ?? {})) {
33
+ const at = /** @type {any} */ (f).columnAt;
34
+ const v = check[k];
35
+ if (!at || v === undefined) continue;
36
+ if (at === 'self') { if (typeof v === 'string') out.push(v); } else if (at === 'self.column') { if (isRec(v) && typeof v.column === 'string') out.push(v.column); } else if (Array.isArray(v)) for (const e of v) { if (at === 'each.column' ? isRec(e) && typeof e.column === 'string' : typeof e === 'string') out.push(at === 'each.column' ? e.column : e); }
37
+ }
43
38
  return out;
44
39
  }
45
40
 
@@ -96,10 +91,11 @@ export function sheetCheckSentence(check) {
96
91
  /**
97
92
  * M10b piece 4: a signed check may carry fwdloop's own `covers` (the numbers of the job line's `~` rules the drafter tagged it to; signed, so the person sees it).
98
93
  * bareguard does not know it, so the checks are cleaned HERE, the ONE place, on the way into bareguard (`createRubric` at sign time and at run time).
99
- * @param {any[]} checks @returns {any[]} a copy without `covers`
94
+ * M17 am3: `row` (fwdloop's own typed tag of a check code made an `[agent]` row) is cleaned here too.
95
+ * @param {any[]} checks @returns {any[]} a copy without `covers` and `row`
100
96
  */
101
97
  export function bareguardChecks(checks) {
102
- return checks.map((c) => { if (!isRec(c) || !('covers' in c)) return c; const { covers: _kept, ...rest } = c; return rest; });
98
+ return checks.map((c) => { if (!isRec(c) || !('covers' in c || 'row' in c)) return c; const { covers: _kept, row: _row, ...rest } = c; return rest; });
103
99
  }
104
100
 
105
101
  /**
@@ -124,73 +120,63 @@ export function sheetCheckRows(sheet) {
124
120
  }
125
121
 
126
122
  /**
127
- * The $0 sign-time test of one step's sheet checks (M10b item 4): bareguard's `createRubric` is given the checks and the signed fingerprint of each sheet
128
- * they read (`tableSha` of the drafting copy's table). A refusal is a red that names the job line (and the check). A column that is no header of its sheet is
129
- * a red naming the line and the column. Never throws.
123
+ * The $0 sign-time test of one step's sheet checks (M10b item 4): bareguard's `checkTables` is given the checks and the signed fingerprint of each sheet they read
124
+ * (`tableSha` of the drafting copy's table) and returns every problem; each becomes a red that names the job line (and the check) in fwdloop's words. A sheet with no
125
+ * saved copy, a sheet bareguard cannot read as a table, or a column that is no header of its sheet is reported first; a check bareguard refuses only when none of those is.
126
+ * Never throws.
130
127
  * @param {any[]} checks the step's `close.sheet` (already known to be a list of objects) @param {number} line the job line the step comes from
131
128
  * @param {Record<string, {header: string[], rows: any[]}>} tables the drafting copy's table of each sheet role @returns {string[]} reds, each naming the line
132
129
  */
133
130
  export function sheetCheckReds(checks, line, tables) {
134
- const reds = [];
135
131
  const at = `declaration: line ${line}:`;
136
- /** @type {Map<string, string|null>} */
132
+ /** @type {Map<string, string>} */
137
133
  const shas = new Map();
138
- for (const c of checks) {
139
- if (!isRec(c) || typeof c.table !== 'string' || shas.has(c.table)) continue;
140
- const t = tables[c.table];
141
- if (!t) { shas.set(c.table, null); reds.push(`${at} the sheet check reads "${c.table}", which has no saved copy to test against`); continue; }
142
- shas.set(c.table, tableSha(t));
143
- if (shas.get(c.table) === null) reds.push(`${at} bareguard cannot read "${c.table}" as a table (a row with more or fewer cells than the header, or a repeated column name); fix the sheet`);
144
- }
145
- for (const c of checks) {
146
- const t = isRec(c) && typeof c.table === 'string' ? tables[c.table] : undefined;
147
- if (!t) continue;
148
- for (const name of sheetCheckColumns(c)) {
149
- if (!t.header.includes(name)) reds.push(`${at} '${name}' is not a real column of "${c.table}" (its columns: ${t.header.map((h) => `'${h}'`).join(', ')}). Copy a column name exactly.`);
134
+ for (const c of checks) if (isRec(c) && typeof c.table === 'string' && !shas.has(c.table)) shas.set(c.table, (tables[c.table] ? tableSha(tables[c.table]) : null) ?? '0'.repeat(64));
135
+ const inputs = [...shas].map(([name, sha256]) => ({ name, sha256 }));
136
+ const problems = checkTables({ schema: 1, goal: `line ${line}`, inputs, checkpoints: { sheet: { gating: true, checks: bareguardChecks(checks) } }, maxReds: 3 }, tables);
137
+ const reds = [];
138
+ const seen = new Set();
139
+ /** @param {string} name @param {string} table */
140
+ const columnRed = (name, table) => `${at} '${name}' is not a real column of "${table}" (its columns: ${tables[table].header.map((h) => `'${h}'`).join(', ')}). Copy a column name exactly.`;
141
+ for (const p of problems) {
142
+ const key = `${p.kind}\u0000${p.table}`;
143
+ if (p.kind === 'no-table' && !seen.has(key)) reds.push(`${at} the sheet check reads "${p.table}", which has no saved copy to test against`);
144
+ else if (p.kind === 'unreadable-table' && !seen.has(key)) reds.push(`${at} bareguard cannot read "${p.table}" as a table (a row with more or fewer cells than the header, or a repeated column name); fix the sheet`);
145
+ else if (p.kind === 'not-a-column') reds.push(columnRed(String(p.column), String(p.table)));
146
+ else if (p.kind === 'refused' && typeof p.index === 'number' && isRec(checks[p.index]) && tables[checks[p.index].table]) {
147
+ // bareguard names no column of a check it refuses; the person is told the wrong column first, as before
148
+ for (const name of sheetCheckColumns(checks[p.index])) if (!tables[checks[p.index].table].header.includes(name)) reds.push(columnRed(name, checks[p.index].table));
150
149
  }
150
+ seen.add(key);
151
151
  }
152
152
  if (reds.length > 0) return reds;
153
- const inputs = [...shas].map(([name, sha256]) => ({ name, sha256 }));
154
- try {
155
- createRubric({ schema: 1, goal: `line ${line}`, inputs, checkpoints: { sheet: { gating: true, checks: bareguardChecks(checks) } }, maxReds: 3 });
156
- } catch (err) {
157
- const msg = String(/** @type {any} */ (err).message).replace(/^invalid rubric: /, '');
158
- const idx = /checks\[(\d+)\]/.exec(String(/** @type {any} */ (err).path ?? msg));
159
- const who = idx && isRec(checks[Number(idx[1])]) && typeof checks[Number(idx[1])].id === 'string' ? ` '${checks[Number(idx[1])].id}'` : '';
160
- reds.push(`${at} bareguard refuses the sheet check${who}: ${msg}`);
153
+ const refused = problems.find((p) => p.kind === 'refused' || p.kind === 'sha-mismatch');
154
+ if (refused) {
155
+ const msg = String(refused.message ?? refused.kind).replace(/^invalid rubric: /, '');
156
+ reds.push(`${at} bareguard refuses the sheet check${typeof refused.id === 'string' ? ` '${refused.id}'` : ''}: ${msg}`);
161
157
  }
162
158
  return reds;
163
159
  }
164
160
 
165
- const NUMBER_CMPS = Object.freeze(['gt', 'gte', 'lt', 'lte', 'eq', 'between']);
166
- const DATE_CMPS = Object.freeze(['before', 'after', 'dateOn', 'dateBetween']);
167
-
168
161
  /**
169
- * M10b piece 3: a number or a date in a check comes from the job, never from the model. Every number in a `where` condition (gt gte lt lte eq between) must be a
170
- * number the person said on the job line or its `~` rules (the SAME reader as the page number rules, src/citedwords.js `numbersSaid`: a bare number or an amount,
171
- * not a piece of a time, a date or another amount), and every date (`asOf`, and the values of before / after / dateOn / dateBetween) must be a date they wrote
172
- * exactly. Throws away: a text value (`equals`, `needle`), band bounds, `n`, `tolerance`, `range` are not read here (the job's words do not have to carry them).
162
+ * M10b piece 3: a number or a date in a check comes from the job, never from the model. bareguard's `groundedLiterals` judges every number and date the check carries
163
+ * against the person's words on the job line or its `~` rules (one string, `wordsSaidOn`); each literal it reports missing becomes a red in fwdloop's words. A literal of the
164
+ * wrong type or an unreadable condition is not "not in your words": `createRubric` refuses it (sheetCheckReds), so it is no red here.
165
+ * Throws away: a text value (`equals`, `needle`), band bounds, `n`, `tolerance`, `range` are not read (bareguard does not read them either).
173
166
  * @param {any[]} checks the step's `close.sheet` @param {{n: number, text?: string, rule?: string, rules?: string[]}} jobLine @returns {string[]} reds, each naming the line
174
167
  */
175
168
  export function sheetCheckWordReds(checks, jobLine) {
176
- const said = numbersSaid(wordsSaidOn(jobLine));
169
+ const text = wordsSaidOn(jobLine);
177
170
  const reds = [];
178
171
  const n = jobLine.n;
179
- const who = (/** @type {any} */ c) => (isRec(c) && typeof c.id === 'string' ? ` '${c.id}'` : '');
180
- const num = (/** @type {any} */ c, /** @type {unknown} */ v, /** @type {string} */ where) => {
181
- if (typeof v === 'number' && !said.bare.has(v) && !said.amount.has(v)) reds.push(`declaration: line ${n}: the sheet check${who(c)} has the number ${v} (${where}), but ${v} is not in your words on line ${n}. A number in a check must come from the job line or a ~ rule you wrote. Say it there, or leave the condition out.`);
182
- };
183
- const date = (/** @type {any} */ c, /** @type {unknown} */ v, /** @type {string} */ where) => {
184
- if (typeof v === 'string' && !said.date.has(v)) reds.push(`declaration: line ${n}: the sheet check${who(c)} has the date ${v} (${where}), but ${v} is not a date in your words on line ${n}. A date in a check must be written on the job line or a ~ rule, as YYYY-MM-DD. Say it there, or leave it out.`);
185
- };
186
172
  for (const c of checks) {
187
173
  if (!isRec(c)) continue;
188
- if (c.asOf !== undefined) date(c, c.asOf, 'as of');
189
- for (const w of Array.isArray(c.where) ? c.where : []) {
190
- if (!isRec(w)) continue;
191
- const at = `where ${String(w.column)}`;
192
- if (NUMBER_CMPS.includes(w.cmp)) for (const k of w.cmp === 'between' ? ['lo', 'hi'] : ['value']) num(c, w[k], at);
193
- else if (DATE_CMPS.includes(w.cmp)) for (const k of w.cmp === 'dateBetween' ? ['lo', 'hi'] : ['value']) date(c, w[k], at);
174
+ const who = typeof c.id === 'string' ? ` '${c.id}'` : '';
175
+ for (const m of groundedLiterals(bareguardChecks([c])[0], text).missing) {
176
+ const w = /^where\[(\d+)\]/.exec(m.path);
177
+ const where = m.path === 'asOf' ? 'as of' : m.path === 'b.const' ? 'row math b' : w ? `where ${String(c.where[Number(w[1])].column)}` : m.path;
178
+ if (m.kind === 'number' && typeof m.value === 'number') reds.push(`declaration: line ${n}: the sheet check${who} has the number ${m.value} (${where}), but ${m.value} is not in your words on line ${n}. A number in a check must come from the job line or a ~ rule you wrote. Say it there, or leave the condition out.`);
179
+ else if (m.kind === 'date' && typeof m.value === 'string') reds.push(`declaration: line ${n}: the sheet check${who} has the date ${m.value} (${where}), but ${m.value} is not a date in your words on line ${n}. A date in a check must be written on the job line or a ~ rule, as YYYY-MM-DD. Say it there, or leave it out.`);
194
180
  }
195
181
  }
196
182
  return reds;
@@ -1,33 +1,13 @@
1
1
  // M10b piece 2 (docs/wiki/the-module-ladder.md "M10b scope" item 5): what a step that reads a sheet is told and what box it answers in.
2
- // A step answers each `cells` check's CLAIM in bareguard's typed box ({value}, {rows}, {days}, {bands}, ...), never a cite or a formula. The shape of every box is
3
- // generated from bareguard's own worked example for the op (`rubricVocabulary.rules.cells.ops.<op>.example`), never hand-copied here. The step is told the box, not the
2
+ // A step answers each `cells` check's CLAIM in bareguard's typed box ({value}, {rows}, {days}, {bands}, ...), never a cite or a formula. The schema of every box is
3
+ // bareguard's `claimSchema` of the check; the box the step is TOLD is bareguard's own worked example for the op (`rubricVocabulary.rules.cells.ops.<op>.example`). Never hand-copied here. The step is told the box, not the
4
4
  // check: no op, no condition, no bound, no column ever reaches it (the construction test in test/m10b-sheet-run.test.js proves the request carries none).
5
5
  // Throws away: a check with no claim (a `table` check judges the sheet itself) adds no box; two checks with the same claim name share one box.
6
- import { rubricVocabulary } from 'bareguard';
6
+ import { rubricVocabulary, claimSchema } from 'bareguard';
7
+ import { bareguardChecks } from './sheetchecks.js';
7
8
 
8
9
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
9
10
 
10
- /** whole-number boxes: a row number list, and a days map (bareguard compares these as integers) */
11
- const INTEGER_KEYS = Object.freeze(['rows', 'days']);
12
-
13
- /**
14
- * The JSON schema of one value in a worked example. Typed from the example's own value; `intKey` = the box key it sits under.
15
- * @param {any} v @param {string} [intKey] @returns {Record<string, any>}
16
- */
17
- function schemaOf(v, intKey = '') {
18
- if (typeof v === 'boolean') return { type: 'boolean' };
19
- if (typeof v === 'number') return { type: INTEGER_KEYS.includes(intKey) ? 'integer' : 'number' };
20
- if (typeof v === 'string') return { type: 'string' };
21
- if (Array.isArray(v)) return v.length > 0 ? { type: 'array', items: schemaOf(v[0], intKey) } : { type: 'array' };
22
- if (isRec(v)) {
23
- const keys = Object.keys(v);
24
- // a map keyed by row number (days, bands): every value has the first one's type
25
- if (keys.length > 0 && keys.every((k) => /^\d+$/.test(k))) return { type: 'object', additionalProperties: schemaOf(v[keys[0]], intKey) };
26
- return { type: 'object', properties: Object.fromEntries(keys.map((k) => [k, schemaOf(v[k], k)])), required: keys };
27
- }
28
- return {};
29
- }
30
-
31
11
  /**
32
12
  * The claim box of every `cells` check in the list: `[{claim, example}]`, one per claim name, in order. `example` is the op's worked-example answer (the box's shape
33
13
  * with example values). A check bareguard has no example for, and a `table` check, add nothing.
@@ -49,19 +29,19 @@ export function sheetClaims(checks) {
49
29
  }
50
30
 
51
31
  /**
52
- * The `emit_artifact` tool's properties for a step that reads a sheet: one typed box per claim, each required. (`done` is added by the caller, as for every step.)
32
+ * The `emit_artifact` tool's properties for a step that reads a sheet: one typed box per claim, each required, the box's schema bareguard's `claimSchema` of the check
33
+ * (two checks that share a claim name share one box: their keys merge). `covers` is fwdloop's own and is stripped before bareguard reads the check. (`done` is added by the caller.)
53
34
  * @param {any[]} checks @returns {{properties: Record<string, any>, required: string[]}}
54
35
  */
55
36
  export function sheetAnswerProps(checks) {
56
37
  /** @type {Record<string, any>} */
57
38
  const properties = {};
58
- for (const { claim, example, ops } of sheetClaims(checks)) {
59
- const keys = Object.keys(example);
60
- properties[claim] = {
61
- type: 'object',
62
- properties: Object.fromEntries(keys.map((k) => [k, ops.includes('lookup') && k === 'value' ? { type: ['string', 'number'] } : schemaOf(example[k], k)])),
63
- required: keys,
64
- };
39
+ for (const c of Array.isArray(checks) ? checks : []) {
40
+ if (!isRec(c) || c.rule !== 'cells' || typeof c.claim !== 'string') continue;
41
+ const box = /** @type {any} */ (claimSchema(bareguardChecks([c])[0]));
42
+ if (box === null) continue;
43
+ const have = properties[c.claim];
44
+ properties[c.claim] = have === undefined ? box : { ...have, ...box, properties: { ...have.properties, ...box.properties }, required: [...new Set([...(have.required ?? []), ...(box.required ?? [])])] };
65
45
  }
66
46
  return { properties, required: Object.keys(properties) };
67
47
  }
package/src/sheetfind.js CHANGED
@@ -44,9 +44,9 @@ export function findColumn(csvText, word) {
44
44
 
45
45
  /**
46
46
  * The question, as signed (item 7's example, then am8 item 1's answer words):
47
- * `no column 'Price'; 'Amount' has numbers in 40 of 40 rows. Use it? Answer "agree", or type your own words (your answer is added as a new ~ rule on line N).`
47
+ * `no column 'Price'; 'Amount' has numbers in 40 of 40 rows. Use it? Answer "agree", or type your own words (your answer becomes the agent's check on line N).`
48
48
  * @param {string} word @param {FoundAsk} found @param {number} line @returns {string}
49
49
  */
50
- export const columnQuestion = (word, found, line) => `no column '${word}'; '${found.column}' has numbers in ${found.numbers} of ${found.rows} rows. Use it?${columnTail(line)}`;
51
- /** @param {number} line @returns {string} the answer words the column question ends with (M10 am29: the panel cuts exactly this) */
52
- export const columnTail = (line) => ` Answer "agree", or type your own words (your answer is added as a new ~ rule on line ${line}).`;
50
+ export const columnQuestion = (word, found, line, tied = false) => `no column '${word}'; '${found.column}' has numbers in ${found.numbers} of ${found.rows} rows. Use it?${columnTail(line, tied)}`;
51
+ /** @param {number} line @param {boolean} [tied] the question is about one of the person's `~` rules (M17 ruling 1: the answer replaces that rule; the words are the page asks' own) @returns {string} the answer words the column question ends with (M10 am29: the panel cuts exactly this) */
52
+ export const columnTail = (line, tied = false) => (tied ? ` Answer "agree", or type your own words (your answer replaces that ~ rule on line ${line}).` : ` Answer "agree", or type your own words (your answer becomes the agent's check on line ${line}).`);
package/src/sheetlook.js CHANGED
@@ -83,6 +83,13 @@ export function applySheetWords(text, words, jobLines, label) {
83
83
  /** @type {import('./pagerules.js').Dropped[]} */
84
84
  const dropped = [];
85
85
  const seen = new Set();
86
+ // the person's word is a header of the sheet: the word is theirs when the line or its `~` rules say it (a header the model picked in the person's place is not)
87
+ const isYours = (/** @type {any} */ jl, /** @type {string} */ word) => jl !== undefined && wordForms(word).some((f) => countPhrase(wordsSaidOn(jl), f) > 0);
88
+ // F196: a `~` rule whose own words contain a header of the sheet is tied to it by CODE (not by what the model returned): none of its words is asked (M10 am32, F180)
89
+ const headers = parseCsv(text).header;
90
+ const tiedRules = new Set(jobLines.flatMap((l) => lineRules(l).flatMap((r, i) => (headers.some((h) => h.trim() !== '' && countPhrase(r, h) > 0) ? [`${l.n}\u0000${i + 1}`] : []))));
91
+ /** the words (line + word) a `~` rule asked about or settled: the line's own prose never asks that word again (one word, one question; the rule's ask wins) */
92
+ const ruleWords = new Set();
86
93
  for (const w of words) {
87
94
  const at = tieOf(w.from, jobLines);
88
95
  const key = `${at.line}\u0000${at.rule ?? ''}\u0000${w.word.toLowerCase()}`;
@@ -97,7 +104,7 @@ export function applySheetWords(text, words, jobLines, label) {
97
104
  if (found.kind === 'header') {
98
105
  // a real header is kept only when the word is the PERSON'S: in the line or its ~ rules. A header the model picked in the person's place is not a check the person
99
106
  // asked for (live walk 2026-10-21: "Price over 500" kept as "Amount", nothing asked)
100
- if (jl === undefined || !wordForms(w.word).some((f) => countPhrase(wordsSaidOn(jl), f) > 0)) dropped.push({ ...rec, reason: 'word-not-yours' });
107
+ if (!isYours(jl, w.word)) dropped.push({ ...rec, reason: 'word-not-yours' });
101
108
  else facts.push(fact(found.column));
102
109
  continue;
103
110
  }
@@ -106,11 +113,15 @@ export function applySheetWords(text, words, jobLines, label) {
106
113
  if (found.kind === 'none') { dropped.push({ ...rec, reason: 'no-fit', other: String(found.rows) }); continue; }
107
114
  // the person already named this column in a rule of the line (an answer they gave, or their own words): the word is that column, asked no more
108
115
  if (rules.some((r, i) => countPhrase(r, found.column) > 0)) { facts.push(fact(found.column)); continue; }
116
+ if (at.rule !== undefined) ruleWords.add(`${at.line}\u0000${w.word.toLowerCase()}`);
117
+ if (at.rule !== undefined && tiedRules.has(`${at.line}\u0000${at.rule}`)) continue;
118
+ // F196: the line's prose word that a tied `~` rule of the line also says is settled by that rule (one word, one question, whichever the look tied the ask to)
119
+ if (at.rule === undefined && rules.some((r, i) => tiedRules.has(`${at.line}\u0000${i + 1}`) && wordForms(w.word).some((f) => countPhrase(r, f) > 0))) continue;
109
120
  asks.push({
110
- line: at.line, rule: at.rule ?? null, source: 'look', ask: 'reading', ruleText, question: columnQuestion(w.word, found, at.line), reading: columnRuleWords(w.word, found.column), word: w.word, column: found.column,
121
+ line: at.line, rule: at.rule ?? null, source: 'look', ask: 'reading', ruleText, question: columnQuestion(w.word, found, at.line, at.rule !== undefined), reading: columnRuleWords(w.word, found.column), word: w.word, column: found.column,
111
122
  });
112
123
  }
113
- return { facts, asks, dropped };
124
+ return { facts, asks: asks.filter((a) => a.rule !== null || !ruleWords.has(`${a.line}\u0000${a.word.toLowerCase()}`)), dropped };
114
125
  }
115
126
 
116
127
  /**
package/src/sheetoffer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // M10b piece 3 (docs/wiki/the-module-ladder.md "M10b scope" item 4): what the drafter is OFFERED for a sheet. Things, each once:
2
- // - `sheetChecksProp` the tool schema of `close.sheet`, GENERATED from bareguard's `rubricVocabulary` (fields, ops, date formats), never hand-copied. Every field that
2
+ // - `sheetChecksProp` the tool schema of `close.sheet`: bareguard's `checkSchema` (fields, ops, date formats), never hand-copied, plus fwdloop's own `covers`. Every field that
3
3
  // names a column is a JSON-schema `enum` of the sheet's exact header strings, so the model can only pick one (code still re-checks, piece 1);
4
4
  // - `sheetOpsBrief` the plain list of every op with its summary, what it requires and allows, and bareguard's worked example check, generated the same way;
5
5
  // - `isColumnChoiceRule` the agreed-column rule, covered by the column lock.
@@ -7,80 +7,52 @@
7
7
  // stripped only on the way into bareguard (src/sheetchecks.js `bareguardChecks`) and read by src/sheetblock.js. A field type the vocabulary gains that this file does not know
8
8
  // THROWS at build time (a bareguard upgrade fails loud, it never silently drops a field).
9
9
  // Third outcomes, named: a sheet with no header (no enum can be built: no sheet schema is offered).
10
- import { rubricVocabulary } from 'bareguard';
11
- import {
12
- SHEET_RULES, MAX_SHEET_CHECKS, COLUMN_STRING_FIELDS, COLUMN_OPERAND_FIELDS, COLUMN_CELL_FIELDS, COLUMN_LIST_FIELDS,
13
- } from './sheetchecks.js';
10
+ import { rubricVocabulary, checkSchema } from 'bareguard';
11
+ import { SHEET_RULES, MAX_SHEET_CHECKS } from './sheetchecks.js';
14
12
  import { columnRuleWords } from './sheetlook.js';
15
13
 
16
14
  const V = /** @type {any} */ (rubricVocabulary);
17
15
  const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
18
16
 
19
- /** The comparisons of a `where` condition. bareguard publishes them only inside the `where` description (no list), so this is the one copy; a test proves each is named there. */
20
- export const WHERE_CMPS = Object.freeze(['gt', 'gte', 'lt', 'lte', 'eq', 'between', 'before', 'after', 'dateBetween', 'dateOn', 'equals', 'empty', 'notEmpty']);
17
+ /** The comparisons of a `where` condition, as bareguard's vocabulary lists them. */
18
+ export const WHERE_CMPS = Object.freeze([...V.rules.cells.fields.where.cmps]);
21
19
 
22
20
  /** @param {Record<string, {header: string[]}>} tables @returns {string[]} the exact header strings of every sheet, once each, in order */
23
21
  const headerUnion = (tables) => [...new Set(Object.values(tables).flatMap((t) => t.header))];
24
22
 
25
- /**
26
- * The JSON schema of one vocabulary field. `col` = the schema every column name uses (an enum of the header).
27
- * @param {string} key @param {any} f @param {Record<string, any>} col @param {string[]} roles @returns {Record<string, any>|null} null = not offered
28
- */
29
- function fieldSchema(key, f, col, roles) {
30
- const d = f.description ? { description: f.description } : {};
31
- if (key === 'table') return { type: 'string', enum: roles, description: 'the role of the CSV input this check reads (also in the step\'s reads)' };
32
- if (key === 'claim') return { type: 'string', minLength: 1, maxLength: 128, description: 'a cells check only: a short name for the field that holds the step\'s answer to this check; the step is told the shape of the answer, never the check', };
33
- if (COLUMN_STRING_FIELDS.includes(key)) return { ...col, ...d };
34
- if (COLUMN_OPERAND_FIELDS.includes(key)) return { anyOf: [col, { type: 'object', properties: { const: { type: 'number' } }, required: ['const'], additionalProperties: false }], ...d };
35
- switch (f.type) {
36
- case 'name': case 'string': return { type: 'string', ...d };
37
- case 'explanation': return null; // free text: never offered (a check carries no prose)
38
- case 'date': return { type: 'string', ...d };
39
- case 'integer': return { type: 'integer', ...d };
40
- case 'number': return { type: 'number', ...d };
41
- case 'boolean': return { type: 'boolean', ...d };
42
- case 'enum': return { type: 'string', enum: f.enum, ...d };
43
- case 'range': return { type: 'object', properties: { from: { type: 'integer' }, to: { type: 'integer' } }, required: ['from', 'to'], additionalProperties: false, ...d };
44
- case 'cell': return { type: 'object', properties: { column: col, row: { type: 'integer' } }, required: ['column', 'row'], additionalProperties: false, ...d };
45
- case 'condition-list': return { type: 'array', items: { type: 'object', properties: { column: col, cmp: { type: 'string', enum: [...WHERE_CMPS] }, value: {}, lo: {}, hi: {} }, required: ['column', 'cmp'], additionalProperties: false }, ...d };
46
- case 'date-format-list': return { type: 'array', items: { type: 'object', properties: { column: col, format: { type: 'string', enum: V.cells.dateFormats } }, required: ['column', 'format'], additionalProperties: false }, ...d };
47
- case 'band-list': return { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, gt: { type: 'number' }, gte: { type: 'number' }, lt: { type: 'number' }, lte: { type: 'number' } }, required: ['name'], additionalProperties: false }, ...d };
48
- default: throw new Error(`sheetoffer: bareguard's rubricVocabulary has a field type "${f.type}" (${key}) this file does not know - add it before offering sheet checks`);
49
- }
50
- }
23
+ /** what the drafter is told about a field, in fwdloop's words where they steer a draft better than bareguard's */
24
+ const DRAFTER_WORDS = Object.freeze({
25
+ id: 'a short unique name for this check',
26
+ rule: 'cells: the step gives a value that bareguard recomputes; table: bareguard judges the sheet itself',
27
+ table: 'the role of the CSV input this check reads (also in the step\'s reads)',
28
+ claim: 'a cells check only: a short name for the field that holds the step\'s answer to this check; the step is told the shape of the answer, never the check',
29
+ op: 'a cells op goes with rule "cells", a table op with rule "table" (listed in the system prompt)',
30
+ });
51
31
 
52
32
  /**
53
- * The tool schema of `close.sheet`: a list of bareguard cells / table checks. Every field is a field of bareguard's vocabulary; every column-bearing field
54
- * (`column keyColumn groupColumn result a b from to cell where[].column dateFormats[].column`) is an enum of the sheet's exact header. `covers` is fwdloop's own field
55
- * (which `~` rules of the job line the check covers), kept and signed.
33
+ * The tool schema of `close.sheet`: a list of bareguard cells / table checks. The check's schema is bareguard's `checkSchema` (every column-bearing field an enum of the sheet's
34
+ * exact header, `table` an enum of the roles, one `op` enum); fwdloop drops what a check must not carry (the free-text `explanation` fields: a check carries no prose), puts its
35
+ * own words on id / rule / table / claim / op, and adds `covers` (which `~` rules of the job line the check covers), kept and signed.
56
36
  * @param {Record<string, {header: string[]}>} tables the drafting copy's table of each CSV input role
57
37
  * @returns {Record<string, any>|null} null when there is no sheet with a header to pick from
58
38
  */
59
39
  export function sheetChecksProp(tables) {
60
40
  const roles = Object.keys(tables);
61
- const headers = headerUnion(tables);
62
- if (roles.length === 0 || headers.length === 0) return null;
63
- const col = { type: 'string', enum: headers };
41
+ const schema = /** @type {any} */ (checkSchema({ rules: /** @type {('cells'|'table')[]} */ ([...SHEET_RULES]), columns: headerUnion(tables), tables: roles }));
42
+ if (roles.length === 0 || schema === null) return null;
64
43
  /** @type {Record<string, any>} */
65
- const props = {
66
- id: { type: 'string', minLength: 1, description: 'a short unique name for this check' },
67
- rule: { type: 'string', enum: [...SHEET_RULES], description: 'cells: the step gives a value that bareguard recomputes; table: bareguard judges the sheet itself' },
68
- };
69
- for (const r of SHEET_RULES) {
70
- for (const [k, f] of Object.entries(V.rules[r].fields)) {
71
- if (k === 'op' || props[k] !== undefined) continue;
72
- const s = fieldSchema(k, f, col, roles);
73
- if (s !== null) props[k] = s;
74
- }
75
- }
76
- props.op = { type: 'string', enum: [...new Set(SHEET_RULES.flatMap((r) => Object.keys(V.rules[r].ops)))], description: 'a cells op goes with rule "cells", a table op with rule "table" (listed in the system prompt)' };
44
+ const props = { ...schema.properties };
45
+ for (const r of SHEET_RULES) for (const [k, f] of Object.entries(V.rules[r].fields)) if (/** @type {any} */ (f).type === 'explanation') delete props[k];
46
+ for (const [k, d] of Object.entries(DRAFTER_WORDS)) if (props[k]) props[k] = { ...props[k], description: d };
47
+ // the left operand `a` is offered the same two shapes as `b` (bareguard's own `b` schema; a `{const}` there is refused by createRubric, as before)
48
+ if (props.a && props.b?.anyOf) props.a = { ...props.b, description: props.a.description, anyOf: [props.a, props.b.anyOf[1]] };
77
49
  props.covers = { type: 'array', items: { type: 'integer', minimum: 1 }, description: 'the numbers of the line\'s ~ guardrail rules this check verifies (1 is its first rule); [] when it verifies none of them' };
78
50
  return {
79
51
  type: 'array',
80
52
  minItems: 1,
81
53
  maxItems: MAX_SHEET_CHECKS,
82
54
  description: 'only on a green step that reads a CSV input: the checks bareguard runs on the step\'s answer. Omit on any other step',
83
- items: { type: 'object', properties: props, required: ['id', 'rule', 'table', 'op', 'covers'], additionalProperties: false },
55
+ items: { type: 'object', properties: props, required: [...schema.required, 'covers'], additionalProperties: false },
84
56
  };
85
57
  }
86
58
 
@@ -106,20 +78,65 @@ export function sheetOpsBrief() {
106
78
  * The rules the validator enforces on `close.sheet`, as lines for the drafter (every one of them is a refusal at $0 in src/declaration.js / src/sheetchecks.js).
107
79
  * @param {string[]} roles the CSV input roles @returns {string[]}
108
80
  */
109
- export function sheetOfferRules(roles) {
81
+ export function sheetOfferRules(roles, lineNums = /** @type {number[]} */ ([])) {
110
82
  return [
111
- `- A green step whose line has a guardrail about values in a CSV input (${roles.join(', ')}) lists that input's role in its reads and carries close.sheet = a list of 1 to ${MAX_SHEET_CHECKS} checks, each a bareguard check object from the ops below, with "table" = the CSV input's role. Write the checks the line's guardrail needs and nothing else; the person signs them. close.sheet is for a green step only.`,
112
- '- A column name in a check is picked from the sheet\'s header, spelled exactly; the tool only lets you pick a header name. A check that bareguard refuses (a wrong field for the op, overlapping bands, a missing dateFormats entry) is refused at $0 naming the job line.',
83
+ ...(lineNums.length ? [`- The job's sheet lines are ${lineNums.join(', ')} (the lines shown with their ~ rules that are not on the list's own rows): "line" in a sheetChecks suggestion is one of those numbers, exactly as shown. The checks of a sheet line are sent only in sheetChecks: an edit that names a sheet line is refused.`] : []),
84
+ `- M17: you write NO sheet check in the declaration (it has no "close.sheet"). A job line whose step reads a CSV input (${roles.join(', ')}) and has a guardrail about values in it lists that input's role in the step's reads and gets its checks from your row-edit reply: "sheetChecks", 1 to ${MAX_SHEET_CHECKS} suggestions, each a bareguard check object from the ops below with "line" = the job line's number and "table" = the CSV input's role. Suggest the checks the line's guardrail needs and nothing else; code builds each one on bareguard or refuses it with its reason, and the person sees every one and can drop it.`,
85
+ '- A column name in a suggestion is picked from the sheet\'s header, spelled exactly; the tool only lets you pick a header name.',
113
86
  '- A number in a where condition (gt, gte, lt, lte, eq, between) must be a number the person wrote on that job line or its guardrail; a date (asOf, and the values of before, after, dateOn, dateBetween) must be a date they wrote there as YYYY-MM-DD. Never make a number or a date up: if the person gave none, leave that condition out.',
114
- '- A "cells" check names "claim", a short name for the answer the step gives; the step is told only the shape of the answer, never the check. A "table" check has no claim and judges the input sheet itself, so it must already hold on that sheet (one that fails on it is refused); to check what a step gives, use a cells check. If every check of a step is a table check the step has nothing to answer and the line is refused: pair a table check with at least one cells check.',
115
- '- "covers" on each check lists the numbers of the line\'s guardrail rules (the ~ parts, counted from 1 in the order shown) that this check really verifies; [] if none. A guardrail rule that no check covers is shown to the person as Not checked, so cover every rule you can with a real check, and never claim a rule a check does not verify. A rule shaped like "use the column \'X\' for \'Y\'" is a column choice, not a rule to cover.',
87
+ '- A "cells" check names "claim", any short name (code renames it); the step is told only the shape of the answer, never the check. A "table" check has no claim and judges the input sheet itself, so it must already hold on that sheet; to check what a step gives, use a cells check. If every check of a step is a table check the step has nothing to answer: suggest at least one cells check too.',
88
+ '- "covers" on each suggestion lists the numbers of the line\'s guardrail rules (the ~ parts, counted from 1 in the order shown) that this check really verifies; [] if none. A guardrail rule that no check covers is shown to the person as Not checked, so cover every rule you can with a real check, and never claim a rule a check does not verify. A rule shaped like "use the column \'X\' for \'Y\'" is a column choice, not a rule to cover.',
116
89
  ...sheetOpsBrief(),
117
90
  ];
118
91
  }
119
92
 
93
+ /**
94
+ * M17 am2 item 2: the row-edit reply's `sheetChecks` property: bareguard's `checkSchema` items (src/sheetoffer.js `sheetChecksProp`) plus the job line each suggestion is for. Typed suggestions only; code builds or refuses each.
95
+ * @param {Record<string, {header: string[]}>} tables @param {number[]} [lineNums] the job's sheet lines: `line` can only name one of them @returns {Record<string, any>|null}
96
+ */
97
+ export function sheetSuggestProp(tables, lineNums = /** @type {number[]} */ ([])) {
98
+ const p = sheetChecksProp(tables);
99
+ if (p === null) return null;
100
+ return { ...p, description: 'suggested sheet checks, only for a job line whose step reads a CSV input: code builds or refuses each one on bareguard; you never write a check into the plan', items: { ...p.items, properties: { line: { type: 'integer', ...(lineNums.length ? { enum: lineNums } : { minimum: 1 }), description: 'the number of the job line this check is for (one of the sheet lines shown)' }, ...p.items.properties }, required: ['line', ...p.items.required] } };
101
+ }
102
+
120
103
  /** @param {unknown} rule @returns {boolean} true for the `use the column 'X' for 'Y'` rule an agreed column ask writes ({@link columnRuleWords}) */
121
104
  export function isColumnChoiceRule(rule) {
122
105
  const r = String(rule);
123
106
  const head = columnRuleWords('', '').split("''")[0]; // "use the column '"
124
107
  return r.startsWith(head) && r.endsWith("'") && r.includes("' for '");
125
108
  }
109
+
110
+ /**
111
+ * M17 ruling 1 (hamr 2026-11-14): the parts of an agreed column rule (`use the column 'Amount' for 'Price'`), read from the words code wrote ({@link columnRuleWords}); null for any other text.
112
+ * @param {unknown} rule @returns {{column: string, word: string}|null}
113
+ */
114
+ export function columnChoiceParts(rule) {
115
+ if (!isColumnChoiceRule(rule)) return null;
116
+ const r = String(rule);
117
+ const head = "use the column '";
118
+ const mid = r.indexOf("' for '", head.length);
119
+ if (mid < 0) return null;
120
+ return { column: r.slice(head.length, mid), word: r.slice(mid + "' for '".length, r.length - 1) };
121
+ }
122
+
123
+ /**
124
+ * M17 ruling 1: the rule's own words with the job's word (case aside, whole word) swapped for the agreed column: "Price over 500" + Amount -> "Amount over 500". Null when the word is not in the rule.
125
+ * @param {string} text @param {string} word @param {string} column @returns {string|null}
126
+ */
127
+ export function swapColumnWord(text, word, column) {
128
+ const w = word.trim().toLowerCase();
129
+ if (w === '') return null;
130
+ const low = text.toLowerCase();
131
+ const isWordChar = (/** @type {string|undefined} */ c) => c !== undefined && c.toLowerCase() !== c.toUpperCase() || (c !== undefined && c >= '0' && c <= '9');
132
+ let from = 0;
133
+ for (;;) {
134
+ const at = low.indexOf(w, from);
135
+ if (at < 0) return null;
136
+ if (!isWordChar(text[at - 1]) && !isWordChar(text[at + w.length])) return `${text.slice(0, at)}${column}${text.slice(at + w.length)}`;
137
+ from = at + 1;
138
+ }
139
+ }
140
+
141
+ /** M17 ruling 2: what the AI is told of a column the person agreed for a word of the job's prose (no `~` rule): the word and the column, typed @param {{line: number, word: string, column: string}} c @returns {string} */
142
+ export const agreedColumnWords = (c) => `- The person agreed that on line ${c.line} the word '${c.word}' means the column '${c.column}'. If a check on that line needs it, suggest it on that column.`;