fwdloop 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/bin/fwdloop +85 -34
  2. package/package.json +4 -3
  3. package/src/ask.js +20 -4
  4. package/src/audit-fold.js +5 -1
  5. package/src/authoring.js +36 -6
  6. package/src/canrun.js +5 -0
  7. package/src/checked.js +32 -4
  8. package/src/cited-record.js +138 -0
  9. package/src/cited-source.js +49 -0
  10. package/src/citedcheck.js +321 -0
  11. package/src/citedwords.js +197 -0
  12. package/src/closers.js +37 -198
  13. package/src/csv.js +69 -12
  14. package/src/ctx-tools.js +2 -14
  15. package/src/declaration.js +143 -5
  16. package/src/diary.js +2 -2
  17. package/src/docx.js +16 -2
  18. package/src/draft-steps.js +1 -1
  19. package/src/drafter.js +322 -33
  20. package/src/flow.js +33 -7
  21. package/src/flowmodel.js +21 -0
  22. package/src/input-facts.js +20 -3
  23. package/src/model-step.js +38 -21
  24. package/src/pageask.js +136 -0
  25. package/src/pagebits.js +107 -0
  26. package/src/pagedropwords.js +171 -0
  27. package/src/pagedry.js +120 -0
  28. package/src/pagefetch.js +164 -0
  29. package/src/pagelook.js +155 -0
  30. package/src/pagemap.js +55 -0
  31. package/src/pageplace.js +103 -0
  32. package/src/pagerules.js +318 -0
  33. package/src/panel/author.js +43 -21
  34. package/src/panel/authorcard.js +20 -3
  35. package/src/panel/authorflows.js +21 -15
  36. package/src/panel/authorstart.js +2 -4
  37. package/src/panel/authortrigger.js +14 -4
  38. package/src/panel/data.js +102 -6
  39. package/src/panel/index.html +321 -12
  40. package/src/panel/result.js +301 -0
  41. package/src/panel/server.js +27 -3
  42. package/src/primitives.js +2 -3
  43. package/src/provider.js +5 -2
  44. package/src/redact.js +17 -0
  45. package/src/runner.js +102 -14
  46. package/src/schedule.js +3 -3
  47. package/src/setup.js +16 -1
  48. package/src/sheet-record.js +57 -0
  49. package/src/sheetblock.js +170 -0
  50. package/src/sheetchecks.js +206 -0
  51. package/src/sheetclaims.js +78 -0
  52. package/src/sheetfind.js +50 -0
  53. package/src/sheetlook.js +157 -0
  54. package/src/sheetoffer.js +125 -0
  55. package/src/sheetrun.js +105 -0
  56. package/src/signed-text.js +11 -1
  57. package/src/thinking.js +1 -1
  58. package/src/try-checks.js +12 -0
  59. package/src/types.js +4 -11
  60. package/types/ask.d.ts +2 -1
  61. package/types/authoring.d.ts +19 -2
  62. package/types/checked.d.ts +19 -3
  63. package/types/cited-record.d.ts +21 -0
  64. package/types/cited-source.d.ts +18 -0
  65. package/types/citedcheck.d.ts +95 -0
  66. package/types/citedwords.d.ts +97 -0
  67. package/types/closers.d.ts +37 -10
  68. package/types/csv.d.ts +25 -4
  69. package/types/ctx-tools.d.ts +0 -1
  70. package/types/declaration.d.ts +20 -1
  71. package/types/docx.d.ts +14 -0
  72. package/types/drafter.d.ts +264 -8
  73. package/types/flow.d.ts +21 -0
  74. package/types/flowmodel.d.ts +15 -0
  75. package/types/input-facts.d.ts +12 -2
  76. package/types/model-step.d.ts +40 -19
  77. package/types/pageask.d.ts +75 -0
  78. package/types/pagebits.d.ts +32 -0
  79. package/types/pagedropwords.d.ts +40 -0
  80. package/types/pagedry.d.ts +38 -0
  81. package/types/pagefetch.d.ts +86 -0
  82. package/types/pagelook.d.ts +75 -0
  83. package/types/pagemap.d.ts +31 -0
  84. package/types/pageplace.d.ts +22 -0
  85. package/types/pagerules.d.ts +86 -0
  86. package/types/panel/authorcard.d.ts +4 -1
  87. package/types/panel/authorflows.d.ts +2 -0
  88. package/types/panel/data.d.ts +26 -0
  89. package/types/panel/result.d.ts +156 -0
  90. package/types/provider.d.ts +3 -1
  91. package/types/redact.d.ts +1 -0
  92. package/types/runner.d.ts +162 -9
  93. package/types/schedule.d.ts +0 -11
  94. package/types/setup.d.ts +13 -0
  95. package/types/sheet-record.d.ts +24 -0
  96. package/types/sheetblock.d.ts +116 -0
  97. package/types/sheetchecks.d.ts +70 -0
  98. package/types/sheetclaims.d.ts +26 -0
  99. package/types/sheetfind.d.ts +46 -0
  100. package/types/sheetlook.d.ts +120 -0
  101. package/types/sheetoffer.d.ts +25 -0
  102. package/types/sheetrun.d.ts +35 -0
  103. package/types/thinking.d.ts +1 -1
  104. package/types/types.d.ts +27 -14
@@ -0,0 +1,105 @@
1
+ // M10b piece 2 (docs/wiki/the-module-ladder.md "M10b scope" items 5-6 and amendment 1): a sheet check at RUN time.
2
+ // - the lock: at run start each CSV input a step's `close.sheet` names gets its `tableSha` (bareguard's fingerprint of the table made from the run's frozen copy)
3
+ // written down once with that run's inputs (`freezeInputs` is the one writer of inputs.json and calls `tableShaOfFile`); here is how it is read back;
4
+ // - the judge: `closeSheet` hands the signed checks, the step's typed answer and the run's table to bareguard's `checkStep`. No model grades.
5
+ // Third outcomes, each named, never green: a sheet the run recorded no fingerprint for, a frozen copy that is missing, a table that no longer gives the recorded
6
+ // `tableSha` (bareguard stops the check; the red names the input), any other stopped check.
7
+ // Throws away: bareguard's `full` (expected values, evidence) is not kept - the red keeps the gaps, which name rows and counts and never a cell's text.
8
+ import { basename } from 'node:path';
9
+ import { createRubric, checkStep, renderGaps, tableSha } from 'bareguard';
10
+ import { parseCsv, sheetTable } from './csv.js';
11
+ import { readFileInside } from './flow.js';
12
+ import { sheetCheckSentence, bareguardChecks } from './sheetchecks.js';
13
+ import { sheetCheckName, sheetFoundWords } from './sheetblock.js';
14
+
15
+ const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
16
+
17
+ /** The sheet inputs any step's `close.sheet` reads, once each, in order. @param {any[]} steps @returns {string[]} */
18
+ export function sheetRolesOf(steps) {
19
+ const roles = [];
20
+ for (const s of Array.isArray(steps) ? steps : []) {
21
+ const list = s?.close?.class === 'green' && Array.isArray(s.close.sheet) ? s.close.sheet : [];
22
+ for (const c of list) if (isRec(c) && typeof c.table === 'string' && !roles.includes(c.table)) roles.push(c.table);
23
+ }
24
+ return roles;
25
+ }
26
+
27
+ /**
28
+ * bareguard's `tableSha` of the run's frozen CSV `<runDir>/inputs/<name>` (its table from src/csv.js `sheetTable`), read through the one safe gateway; null when the copy
29
+ * cannot be read or bareguard cannot read it as a table (a ragged row, a repeated header).
30
+ * @param {string} runDir @param {string} name the frozen file's name @returns {string|null}
31
+ */
32
+ export function tableShaOfFrozen(runDir, name) {
33
+ const file = readFileInside(runDir, `inputs/${name}`);
34
+ return file.ok ? tableSha(sheetTable(parseCsv(file.text))) : null;
35
+ }
36
+
37
+ const SHA_RE = /^[0-9a-f]{64}$/;
38
+
39
+ /**
40
+ * What a sheet check reads in a run: the run's OWN frozen copy of each sheet its checks name, as bareguard's table, and the `tableSha` recorded in `inputs.json` at
41
+ * the run's start. The table is NOT compared here: bareguard compares it to the recorded sha when it checks (and stops if it differs).
42
+ * @param {string} runDir @param {any[]} checks the step's `close.sheet`
43
+ * @returns {{ok: true, tables: Record<string, {header: string[], rows: any[]}>, inputs: Array<{name: string, sha256: string}>}|{ok: false, red: string}}
44
+ */
45
+ export function readRunSheets(runDir, checks) {
46
+ const manifest = readFileInside(runDir, 'inputs.json');
47
+ if (!manifest.ok) return { ok: false, red: manifest.missing ? 'this run has no frozen inputs' : `inputs.json: ${manifest.red}` };
48
+ let entries;
49
+ try { entries = JSON.parse(manifest.text); } catch (err) { return { ok: false, red: `inputs.json is not valid JSON - ${/** @type {any} */ (err).message}` }; }
50
+ /** @type {Record<string, any>} */
51
+ const tables = {};
52
+ const inputs = [];
53
+ for (const c of checks) {
54
+ const role = isRec(c) ? c.table : undefined;
55
+ if (typeof role !== 'string' || role in tables) continue;
56
+ const entry = Array.isArray(entries) ? entries.find((e) => e?.id === role) : undefined;
57
+ if (!entry || typeof entry.frozen !== 'string') return { ok: false, red: `input "${role}": this run froze no input with that name` };
58
+ if (typeof entry.tableSha !== 'string' || !SHA_RE.test(entry.tableSha)) return { ok: false, red: `input "${role}": this run recorded no table fingerprint for it at its start` };
59
+ const file = readFileInside(runDir, `inputs/${basename(entry.frozen)}`);
60
+ if (!file.ok) return { ok: false, red: file.missing ? `input "${role}": the frozen copy is missing` : `input "${role}": ${file.red}` };
61
+ tables[role] = sheetTable(parseCsv(file.text));
62
+ inputs.push({ name: role, sha256: entry.tableSha });
63
+ }
64
+ return { ok: true, tables, inputs };
65
+ }
66
+
67
+ /**
68
+ * The close of a green step that reads a sheet. `sheet` = `readRunSheets`' answer. `artifact` is the step's typed answer (its claim boxes). Gaps come from bareguard
69
+ * (`renderGaps`: row numbers and counts, a data problem first); each signed check is also listed with its own pass or fail for the Checked list.
70
+ * @param {any[]} checks the step's `close.sheet` @param {unknown} artifact @param {ReturnType<typeof readRunSheets>|null|undefined} sheet
71
+ * @returns {Promise<import('./types.js').CloseVerdict>}
72
+ */
73
+ export async function closeSheet(checks, artifact, sheet) {
74
+ try {
75
+ if (!sheet || sheet.ok !== true) {
76
+ const red = sheet && sheet.ok === false ? sheet.red : 'the run gave the check no saved sheet to read';
77
+ return /** @type {any} */ ({ verdict: 'unparseable', red: `sheet close: ${red}` });
78
+ }
79
+ if (!isRec(artifact)) return /** @type {any} */ ({ verdict: 'unparseable', red: 'a sheet step must answer with an object, one field per check named in its job' });
80
+ const rubric = createRubric({ schema: 1, goal: 'sheet', inputs: sheet.inputs, checkpoints: { sheet: { gating: true, checks: bareguardChecks(checks) } }, maxReds: 3 });
81
+ const res = await checkStep(rubric, 'sheet', artifact, { tables: sheet.tables });
82
+ if (res.verdict === 'stopped') {
83
+ const moved = sheet.inputs.filter((i) => tableSha(sheet.tables[i.name]) !== i.sha256).map((i) => i.name);
84
+ if (moved.length > 0) {
85
+ return /** @type {any} */ ({ verdict: 'crash', red: `sheet close stopped: input ${moved.map((n) => `"${n}"`).join(', ')} - the saved sheet no longer gives the table this run recorded at its start` });
86
+ }
87
+ const fault = res.fault;
88
+ return /** @type {any} */ ({ verdict: 'crash', red: `sheet close stopped: the ${fault?.id ?? 'sheet'} check stopped (${fault?.kind ?? 'no detail'}${fault?.detail ? `: ${fault.detail}` : ''})` });
89
+ }
90
+ const gaps = res.verdict === 'red' ? res.gaps : [];
91
+ const rows = checks.map((c) => {
92
+ const mine = gaps.filter((g) => g.id === c.id);
93
+ // M10b piece 4: the Audit / Checked row is `<short name> — <plain words>`, with what the step claimed (green) or bareguard's gap words (red) as its result
94
+ return { id: c.id, text: `${sheetCheckName(c)} \u2014 ${sheetCheckSentence(c)}`, ok: mine.length === 0, result: mine.length === 0 ? sheetFoundWords(c, artifact) : renderGaps(mine) };
95
+ });
96
+ const sheetRecord = { inputs: sheet.inputs, claims: artifact, checks: rows.map((r) => ({ id: r.id, text: r.text, ok: r.ok, result: r.ok ? null : r.result })) };
97
+ if (res.verdict === 'red') {
98
+ const red = renderGaps(gaps) || 'a sheet check failed';
99
+ return /** @type {any} */ ({ verdict: 'red', red, reds: [red], checks: rows, sheetRecord });
100
+ }
101
+ return /** @type {any} */ ({ verdict: 'green', red: null, reds: [], checks: rows, sheetRecord });
102
+ } catch (err) {
103
+ return /** @type {any} */ ({ verdict: 'crash', red: `sheet close crashed: ${/** @type {any} */ (err).message}` });
104
+ }
105
+ }
@@ -357,7 +357,7 @@ function parseArbiter(arbiterRawLines, lineNumbers, reds, asks) {
357
357
  }
358
358
 
359
359
  if (lower.startsWith('source ')) {
360
- const fileIdx = lower.indexOf('file:');
360
+ const fileIdx = lower.search(/(?:file|page):/);
361
361
  const afterFile = fileIdx === -1 ? '' : text.slice(fileIdx);
362
362
  if (SECOND_SOURCE_RE.test(afterFile)) {
363
363
  reds.push(`arbiter: line ${fileLine} field "sources" carries more than one source (";"/"," joined), one source per line: "${text}"`);
@@ -378,6 +378,16 @@ function parseArbiter(arbiterRawLines, lineNumbers, reds, asks) {
378
378
  const colon = rhs.indexOf(':');
379
379
  const kind = colon === -1 ? rhs : rhs.slice(0, colon);
380
380
  const path = colon === -1 ? '' : rhs.slice(colon + 1).trim();
381
+ if (kind.toLowerCase() === 'page') {
382
+ // M10 am3: a web page's address is signed with the job (`source <role> = page:<http(s) address>`);
383
+ if (!/^https?:\/\/[^\s/?#]+/i.test(path)) {
384
+ reds.push(`arbiter: line ${fileLine} field "sources" page address must be a full http:// or https:// address: "${text}"`);
385
+ continue;
386
+ }
387
+ sourceRolesSeen.add(role);
388
+ sources.push({ role, kind: 'page', path });
389
+ continue;
390
+ }
381
391
  if (kind.toLowerCase() !== 'file') {
382
392
  reds.push(`arbiter: line ${fileLine} field "sources" source kind "${kind}" is not available until M9`);
383
393
  continue;
package/src/thinking.js CHANGED
@@ -85,7 +85,7 @@ export function thinkingRuleWords(boxOn) {
85
85
  /**
86
86
  * M4d am25 item 1/2: the ONE owner of what thinking a step's model call asks for. Code decides, never the model.
87
87
  * Box ticked (the job's Chat "Thinking on" box, kept with the job): every try 'on'. Box off: the 1st try 'off'; the 2nd and later tries 'on'.
88
- * A step redone after a human Redo is numbered from its redo count (the runner's `attemptOffset`), so it is always a 2nd-or-later try and thinks 'on'.
88
+ * A step redone after a human Redo is numbered after the step's last try (the runner's `attemptOffset`, am30), so it is always a 2nd-or-later try and thinks 'on'.
89
89
  * @param {{boxOn: boolean, attempt: number}} a the runner's 1-based attempt number for this step
90
90
  * @returns {'on'|'off'}
91
91
  */
package/src/try-checks.js CHANGED
@@ -50,6 +50,18 @@ export function closeRecords(step, artifact, closed) {
50
50
  n: 3, text: 'the close could run', ok: false, result: closed.verdict, source,
51
51
  }];
52
52
  }
53
+ if (step?.close?.class === 'green' && Array.isArray(step?.close?.sheet) && Array.isArray(closed.checks)) {
54
+ // M10b piece 2: each signed sheet check is its own row, worded by `sheetCheckSentence`, judged by bareguard
55
+ return closed.checks.map((c, i) => ({
56
+ n: 3 + i, text: c.text, ok: c.ok, result: c.result, source,
57
+ }));
58
+ }
59
+ if (step?.close?.class === 'green' && step?.close?.cited) {
60
+ const n = Array.isArray(artifact?.results) ? artifact.results.length : 0;
61
+ return [{
62
+ n: 3, text: 'every result is quoted from the saved copy and passes its rules', ok: closed.verdict === 'green', result: `${n} result${n === 1 ? '' : 's'}`, source,
63
+ }];
64
+ }
53
65
  if (step?.close?.class === 'green') {
54
66
  const n = Object.keys(artifact?.fields ?? {}).length;
55
67
  return [{
package/src/types.js CHANGED
@@ -35,8 +35,8 @@
35
35
  /**
36
36
  * @typedef {object} SourceSlot
37
37
  * @property {string} role - `[a-z][a-z0-9_-]*`, unique across sources.
38
- * @property {'file'} kind - only `file:` sources are available before M9.
39
- * @property {string} path - everything after `file:` to end of line, trimmed.
38
+ * @property {'file'|'page'} kind - `file:` (a path) or `page:` (a web address, M10 am3); nothing else is available.
39
+ * @property {string} path - everything after `file:` / `page:` to end of line, trimmed.
40
40
  */
41
41
 
42
42
  /**
@@ -244,15 +244,6 @@
244
244
  * @property {string|null} gap
245
245
  */
246
246
 
247
- /**
248
- * A green-class field value: `value` is the number/ISO-date/text claimed;
249
- * `cite` resolves it (src/closers.js's own grammar).
250
- * @typedef {object} GreenField
251
- * @property {string|number} value
252
- * @property {string} cite
253
- */
254
-
255
- /** @typedef {{ fields: Record<string, GreenField> }} GreenArtifact */
256
247
  /** @typedef {{ text: string, lines?: string[] }} SoftgreenArtifact */
257
248
 
258
249
  /**
@@ -262,6 +253,8 @@
262
253
  * @property {string|null} [red]
263
254
  * @property {string[]} [reds]
264
255
  * @property {Array<{id:string, text:string, ok:boolean, result:string|null}>} [checks] a softgreen close: every check it ran (M4d am29 item 2)
256
+ * @property {{part: any, check: any, results?: unknown}} [cited] a cited green close (M10 piece 4): the fact part and the check's own answer, for the run's cited-check record
257
+ * @property {{inputs: Array<{name:string, sha256:string}>, claims: unknown, checks: Array<{id:string, text:string, ok:boolean, result:string|null}>}} [sheetRecord] a sheet close (M10b piece 2): what the run's sheet-check record keeps
265
258
  */
266
259
 
267
260
  /**
package/types/ask.d.ts CHANGED
@@ -51,7 +51,7 @@ export function makeFileAskStep({ timeoutMs, pollMs, clock, writeLine, }?: {
51
51
  * @param {any} ask the parsed ask.json object (or its `evidence` field's
52
52
  * container — pass the whole ask so a missing `evidence` key is itself a
53
53
  * handled case, not the caller's problem).
54
- * @returns {{ draft: {step?: string, text: string} | null, unjudged: Array<{step: string, emits?: string, text: string}>, why?: string }}
54
+ * @returns {{ draft: {step?: string, text: string} | null, unjudged: Array<{step: string, emits?: string, text: string}>, why?: string, claims?: Record<string, any> }}
55
55
  */
56
56
  export function readAskEvidence(ask: any): {
57
57
  draft: {
@@ -64,6 +64,7 @@ export function readAskEvidence(ask: any): {
64
64
  text: string;
65
65
  }>;
66
66
  why?: string;
67
+ claims?: Record<string, any>;
67
68
  };
68
69
  /**
69
70
  * M4b piece 3: the ONE serialisation of an artifact's bytes — what
@@ -22,7 +22,8 @@ export function specHash({ proseText, declarationText, inputFactsText, readoutTe
22
22
  * checks and the page all use it). `questions` = [{ k, line, question, answer|null }], `open` = those with no answer. A blank or unreadable
23
23
  * answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
24
24
  * @param {string} planDir
25
- * @returns {{ questions: {k:number, line:number, question:string, answer:string|null}[], open: {k:number, line:number, question:string, answer:null}[] }}
25
+ * A question the page look raised (M10 piece 3) also carries `source: 'look'`, `ask` ('reading' | 'cant-check'), `ruleNo`, `ruleText` and `proposal`; an answer file carries `at`.
26
+ * @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null}[], open: {k:number, line:number, question:string, answer:null}[] }}
26
27
  */
27
28
  export function readQuestions(planDir: string): {
28
29
  questions: {
@@ -30,6 +31,13 @@ export function readQuestions(planDir: string): {
30
31
  line: number;
31
32
  question: string;
32
33
  answer: string | null;
34
+ at?: string;
35
+ rule?: string | null;
36
+ source?: string;
37
+ ask?: string;
38
+ ruleNo?: number;
39
+ ruleText?: string;
40
+ proposal?: string | null;
33
41
  }[];
34
42
  open: {
35
43
  k: number;
@@ -85,8 +93,9 @@ export function draftKeyRefusal(slot: string, env: Record<string, string | undef
85
93
  * writer (appendSpendRow); an unpriced round books null, never 0.
86
94
  *
87
95
  * Test seam: `provider`/`rates`/`modelId` are injected; without them a live provider is built.
96
+ * `onResult({ ok })` (M4d am32): called once, after the spend is booked and just before the result files are written (the CLI gives its monthly hold back there).
88
97
  */
89
- export function draftToDir({ proseFile, dir, root, name, slot, model, draftThinking, keyNames, env, provider, rates, modelId, noQuestions, }: {
98
+ export function draftToDir({ proseFile, dir, root, name, slot, model, draftThinking, keyNames, env, provider, rates, modelId, noQuestions, onResult, fetchPage, leftRules, proseRead, }: {
90
99
  proseFile: any;
91
100
  dir: any;
92
101
  root: any;
@@ -100,6 +109,10 @@ export function draftToDir({ proseFile, dir, root, name, slot, model, draftThink
100
109
  rates: any;
101
110
  modelId: any;
102
111
  noQuestions?: boolean | undefined;
112
+ onResult: any;
113
+ fetchPage: any;
114
+ leftRules: any;
115
+ proseRead: any;
103
116
  }): Promise<{
104
117
  ok: boolean;
105
118
  wrote: boolean;
@@ -222,6 +235,10 @@ export const LEAK_MARKER_FILE: "scrub-leak.red";
222
235
  * and the drafter's own "not checked" reading (information only; never in the readout, so never in the hash). */
223
236
  export const QUESTIONS_FILE: "questions.json";
224
237
  export const NOT_CHECKED_FILE: "not-checked.json";
238
+ /** M10: the drafting copy of each web page input is kept in this folder of the draft folder (a run freezes its own, never this one). */
239
+ export const PAGES_DIR: "pages";
240
+ /** M10 item 3: what the page-word look kept and dropped, per page input (the map the AI named, the kept facts with their readings, every drop). Not signed. */
241
+ export const PAGE_LOOK_FILE: "page-look.json";
225
242
  export function ANSWER_FILE(k: any): string;
226
243
  export function SIGN_LINE(dir: any, hash: any): string;
227
244
  export const OPEN_QUESTION_SAY: "A question the plan raised is still open. Answer it in the panel (fwdloop panel), then sign the plan it drafts after your answers. Nothing was signed.";
@@ -1,25 +1,41 @@
1
1
  /**
2
2
  * One entry per step, in plan order: the plain sentences for what its typed close checks.
3
- * @param {{ steps?: any[] }} declaration @param {{ hasAsk?: boolean, askLines?: number[] }} [opts] hasAsk = the job has a signed ask line (so "you check it at the ask" is true);
3
+ * M10b piece 4: with `lines` (the signed job lines) a step that reads a sheet also carries `sheet`, its line's block (src/sheetblock.js `sheetLineBlocks`: guardrails,
4
+ * 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.
5
+ * @param {{ steps?: any[] }} declaration @param {{ hasAsk?: boolean, askLines?: number[], lines?: any[], csvRoles?: string[] }} [opts] hasAsk = the job has a signed ask line (so "you check it at the ask" is true);
4
6
  * 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)
5
- * @returns {{ step: number, line: number|null, goal: string, class: string, sentences: string[] }[]}
7
+ * @returns {{ step: number, line: number|null, goal: string, class: string, sentences: string[], sheet?: ReturnType<typeof sheetLineBlocks>[number] }[]}
6
8
  */
7
9
  export function checkedLines(declaration: {
8
10
  steps?: any[];
9
- }, { hasAsk, askLines }?: {
11
+ }, { hasAsk, askLines, lines, csvRoles }?: {
10
12
  hasAsk?: boolean;
11
13
  askLines?: number[];
14
+ lines?: any[];
15
+ csvRoles?: string[];
12
16
  }): {
13
17
  step: number;
14
18
  line: number | null;
15
19
  goal: string;
16
20
  class: string;
17
21
  sentences: string[];
22
+ sheet?: ReturnType<typeof sheetLineBlocks>[number];
18
23
  }[];
19
24
  /** The "Not checked" block the page shows: always the label, then the drafter's items (an empty list says the drafter listed nothing). @param {unknown} items */
20
25
  export function notCheckedBlock(items: unknown): {
21
26
  label: string;
22
27
  items: any[];
23
28
  };
29
+ /**
30
+ * M10 am11: the Not checked block split for showing. The drafter's list and code's drop lines are one list on disk (and in the sign row, unchanged);
31
+ * the page shows code's notes about written forms it did not use apart, as "How the page was read" (`readNotes`). The signed facts decide an s1 note.
32
+ * @param {unknown} items @param {any} declaration the plan's declaration (its cited facts are the signed ones)
33
+ */
34
+ export function notCheckedView(items: unknown, declaration: any): {
35
+ label: string;
36
+ items: string[];
37
+ readNotes: string[];
38
+ };
24
39
  /** The label that always sits with the "Not checked" list (am41 item 3: the ONE place these words live; the Job tab and the Chat card read it off their payloads). */
25
40
  export const NOT_CHECKED_LABEL: "not checked (the AI's own reading)";
41
+ import { sheetLineBlocks } from './sheetblock.js';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * One job line's record from the check's own answer.
3
+ * @param {{n: number, part: any, results: unknown, check: Awaited<ReturnType<typeof import('./citedcheck.js').checkCited>>, confirmed?: string[]}} o
4
+ * `confirmed` = names of facts whose limit the person agreed to (the Result tab's "(you confirmed)")
5
+ * @returns {Record<string, any>}
6
+ */
7
+ export function citedLineOf({ n, part, results, check, confirmed, }: {
8
+ n: number;
9
+ part: any;
10
+ results: unknown;
11
+ check: Awaited<ReturnType<typeof import("./citedcheck.js").checkCited>>;
12
+ confirmed?: string[];
13
+ }): Record<string, any>;
14
+ /**
15
+ * Write one job line into the run's record: the line with the same `n` is replaced (a later try of the same step wins), the others stay, lines are kept in
16
+ * order. An unreadable existing record is started again (this function is its only writer). Atomic: a reader sees the old file or the new one.
17
+ * @param {string} runDir @param {Record<string, any>} line @returns {void}
18
+ */
19
+ export function writeCitedLine(runDir: string, line: Record<string, any>): void;
20
+ /** the record's name in the run's own folder; the Result tab's reader takes it from here */
21
+ export const CITED_CHECKS_FILE: "cited-checks.json";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @param {string} runDir the run's own folder @param {string} role the signed input's role
3
+ * @param {{docx?: boolean}} [o] `docx`: also serve a .docx as its text. Off by default: a step that merely READS a role is never handed a .docx here (it has `readDocx`); only the
4
+ * cited CHECK asks for it, so a quote a step took from a .docx is proved on the same text `readDocx` gives.
5
+ * @returns {{ok: true, text: string, sha256: string, frozen: string}|{ok: false, red: string, code: 'no-manifest'|'not-an-input'|'not-text'|'unreadable'}}
6
+ */
7
+ export function readRunSource(runDir: string, role: string, { docx }?: {
8
+ docx?: boolean;
9
+ }): {
10
+ ok: true;
11
+ text: string;
12
+ sha256: string;
13
+ frozen: string;
14
+ } | {
15
+ ok: false;
16
+ red: string;
17
+ code: "no-manifest" | "not-an-input" | "not-text" | "unreadable";
18
+ };
@@ -0,0 +1,95 @@
1
+ /**
2
+ * A kept look fact as signed facts. The label that comes first becomes the anchor and the limit the look read (`reading`) becomes the number rule. A PLACE
3
+ * fact (the look gave it `phrases`, src/pageplace.js: R2, R2a, R2b) becomes one phrase fact per phrase, because every one of them must be in the quote
4
+ * (R2c); the old choice, the first kept word, is gone (in 2 of 3 saved F71 drafts that word was on no result line, FINDINGS F72). A plain phrase fact
5
+ * ("Nonstop") keeps its first word.
6
+ * @param {any} k a fact from `lookFactOf` (src/pagelook.js) @returns {Record<string, any>[]}
7
+ */
8
+ export function factsOfLook(k: any): Record<string, any>[];
9
+ /**
10
+ * What a fact part may carry, as reds the caller can show before anything is signed or run. Whether bareguard can SIGN the rubric it builds is asked of
11
+ * bareguard itself (`buildCitedSpec` + createRubric); this covers the fields the part owns.
12
+ * @param {any} part @returns {string[]}
13
+ */
14
+ export function factPartReds(part: any): string[];
15
+ /**
16
+ * bareguard's `decides` list for a fact part: one decide per fact, in the fact order (so `d<j>` is the fact's own index).
17
+ * @param {any} part @returns {Record<string, any>[]}
18
+ */
19
+ export function factDecides(part: any): Record<string, any>[];
20
+ /**
21
+ * The claims bareguard reads, built from the step's `results`. The claim TEXT is written here from the values the step gave (`name: value; name: value`),
22
+ * 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
23
+ * bareguard reds it by name rather than the result vanishing.
24
+ * @param {any} part @param {unknown} results @returns {{claim: string, quote: string, values?: Record<string, string>}[]}
25
+ */
26
+ export function factClaims(part: any, results: unknown): {
27
+ claim: string;
28
+ quote: string;
29
+ values?: Record<string, string>;
30
+ }[];
31
+ /**
32
+ * The rubric spec for one fact part: ONE `cited` check (the quote is in the frozen input, every value is in the quote and meets its rule), then the count
33
+ * as a min and a max on the harness-set count of results.
34
+ * @param {any} part @param {string} sha256 the frozen text's sha256 @returns {Record<string, any>}
35
+ */
36
+ export function buildCitedSpec(part: any, sha256: string): Record<string, any>;
37
+ /**
38
+ * One fact as a plain row, written by code from the signed fields: `fact · price — money in US dollars, under 150 US dollars, after "From", quoted from "flights"`.
39
+ * @param {any} f @param {string} source @returns {string}
40
+ */
41
+ export function factSentence(f: any, source: string): string;
42
+ /** @param {any} part @returns {string|null} the "N results" row of a fact part */
43
+ export function countSentence(part: any): string | null;
44
+ /**
45
+ * One fact as the STEP is told it: what to write for it and where in the quote it sits, in plain words, from the signed fields. A phrase fact has no value to
46
+ * write - the quote has to say it. (bareloop's factBrief.)
47
+ * @param {any} f @returns {string}
48
+ */
49
+ export function factBrief(f: any): string;
50
+ /**
51
+ * How a step that quotes a saved page is told to answer: the form of its answer and the facts each result must hold (typed fields in, plain words out).
52
+ * The step is never told a verdict or a way around the check; it is told what to copy and what to write.
53
+ * @param {any} part @returns {{answer: string, eachResultHolds: string[], howMany: string|null}}
54
+ */
55
+ export function citedBrief(part: any): {
56
+ answer: string;
57
+ eachResultHolds: string[];
58
+ howMany: string | null;
59
+ };
60
+ /**
61
+ * Every plan-card row a fact part carries: its facts, then its count (bareloop's factRows).
62
+ * @param {any} part @returns {string[]}
63
+ */
64
+ export function factRows(part: any): string[];
65
+ /**
66
+ * One bareguard `cited` item (`#<result>:d<j>:<reason>[:<detail>]`, or `#<result>:<reason>`) as a sentence. The names and numbers are bareguard's
67
+ * measurements and the signed facts, never inferred here.
68
+ * @param {string} item @param {any} part @returns {string}
69
+ */
70
+ export function plainFactItem(item: string, part: any): string;
71
+ /**
72
+ * Check one step's results against a fact part and the frozen text they must be quoted from.
73
+ * `text` is the run's OWN frozen copy of the source (the caller reads it from the run's folder; this function never reads a file). Its sha256 is taken
74
+ * here and signed into the rubric, so bareguard compares the text it is handed with the text the rubric was built for.
75
+ * @param {{part: any, text: string, results: unknown}} o
76
+ * @returns {Promise<{verdict: 'green'|'red'|'stopped', gapLines: string[], fault: string|null, sha256: string, claims: any[], evidence: any[]}>}
77
+ */
78
+ export function checkCited({ part, text, results }: {
79
+ part: any;
80
+ text: string;
81
+ results: unknown;
82
+ }): Promise<{
83
+ verdict: "green" | "red" | "stopped";
84
+ gapLines: string[];
85
+ fault: string | null;
86
+ sha256: string;
87
+ claims: any[];
88
+ evidence: any[];
89
+ }>;
90
+ /** the shapes a fact may have (bareguard's value kinds, plus `phrase` = a presence decide) */
91
+ export const FACT_SHAPES: readonly string[];
92
+ /** bareguard signs at most this many decides on one `cited` check */
93
+ export const MAX_FACTS: 10;
94
+ export const CITED_ID: "facts";
95
+ export function sha256Text(t: string): string;
@@ -0,0 +1,97 @@
1
+ /** @typedef {{code: string, detail: string}} WordRed */
2
+ /**
3
+ * What the page-word map KEPT and DROPPED for one input: the sets the proof reads.
4
+ * @param {{facts?: any[], dropped?: any[]}|null|undefined} look @param {string} source
5
+ * @returns {{labels: Set<string>|null, words: Set<string>, dropped: Map<string, any>}|null} null = the page was not read by the map; `labels: null` = a document (no map, any label in the text)
6
+ */
7
+ export function keptSetOf(look: {
8
+ facts?: any[];
9
+ dropped?: any[];
10
+ } | null | undefined, source: string): {
11
+ labels: Set<string> | null;
12
+ words: Set<string>;
13
+ dropped: Map<string, any>;
14
+ } | null;
15
+ /**
16
+ * The reds for ONE fact part against its frozen source text and what the page-word map kept.
17
+ * @param {{part: any, text: string, line: number, kept: NonNullable<ReturnType<typeof keptSetOf>>}} o
18
+ * @returns {WordRed[]}
19
+ */
20
+ export function factWordReds({ part, text, line, kept, }: {
21
+ part: any;
22
+ text: string;
23
+ line: number;
24
+ kept: NonNullable<ReturnType<typeof keptSetOf>>;
25
+ }): WordRed[];
26
+ /**
27
+ * The numbers a person said in their words, by KIND. A number inside a time (05:00), a date (2026-11-18) or an amount ($150) is part of that token, not
28
+ * a bare number: "5" is not said by "05:00", "15" and "50" are not said by "$150". (bareloop's `boundInWords` is a substring test and accepts all of those; this
29
+ * reader is ours - FINDINGS-worthy, see the commit.) Times compare without a leading zero on the hour ("05:00" = "5:00"), spaces dropped, case folded.
30
+ * @param {string} text
31
+ * @returns {{bare: Set<number>, amount: Set<number>, time: Set<string>, date: Set<string>}}
32
+ */
33
+ export function numbersSaid(text: string): {
34
+ bare: Set<number>;
35
+ amount: Set<number>;
36
+ time: Set<string>;
37
+ date: Set<string>;
38
+ };
39
+ /**
40
+ * Tighter than bareloop (signed, am7 item 1): every number in a fact's rule must be in the person's own words on this job line (the line and its `~` rules;
41
+ * an agreed reading is a `~` line too), as the right KIND of token: a money or number bound is a bare number or an amount, a time bound is a time, a date bound
42
+ * is a date. A bound the AI made up, or one that only sits inside another token, is refused.
43
+ * @param {{part: any, jobLine: {n: number, text?: string, rule?: string, rules?: string[]}}} o @returns {WordRed[]}
44
+ */
45
+ export function numberRuleReds({ part, jobLine }: {
46
+ part: any;
47
+ jobLine: {
48
+ n: number;
49
+ text?: string;
50
+ rule?: string;
51
+ rules?: string[];
52
+ };
53
+ }): WordRed[];
54
+ /**
55
+ * Signed (am7 item 1): "List 3 ..." is the count, 3 results. A count the person never said as a bare number or a word number (not inside a time, a date or an
56
+ * amount) is refused. Same reader as the number rules.
57
+ * @param {{part: any, jobLine: {n: number, text?: string, rule?: string, rules?: string[]}}} o @returns {WordRed[]}
58
+ */
59
+ export function countReds({ part, jobLine }: {
60
+ part: any;
61
+ jobLine: {
62
+ n: number;
63
+ text?: string;
64
+ rule?: string;
65
+ rules?: string[];
66
+ };
67
+ }): WordRed[];
68
+ /**
69
+ * R2c (am7 item 2): a place the page-read grew to phrases must have EVERY phrase as a phrase fact of the part, or a flipped route passes.
70
+ * @param {{part: any, line: number, look: {facts?: any[]}|null|undefined}} o @returns {WordRed[]}
71
+ */
72
+ export function placeReds({ part, line, look }: {
73
+ part: any;
74
+ line: number;
75
+ look: {
76
+ facts?: any[];
77
+ } | null | undefined;
78
+ }): WordRed[];
79
+ /**
80
+ * Every word red for one cited part, in the order a person fixes them.
81
+ * @param {{part: any, text: string|undefined, line: number, jobLine: any, look: {facts?: any[], dropped?: any[]}|null|undefined, doc?: boolean}} o @returns {WordRed[]}
82
+ */
83
+ export function citedWordReds({ part, text, line, jobLine, look, doc, }: {
84
+ part: any;
85
+ text: string | undefined;
86
+ line: number;
87
+ jobLine: any;
88
+ look: {
89
+ facts?: any[];
90
+ dropped?: any[];
91
+ } | null | undefined;
92
+ doc?: boolean;
93
+ }): WordRed[];
94
+ export type WordRed = {
95
+ code: string;
96
+ detail: string;
97
+ };
@@ -1,17 +1,27 @@
1
+ /** @typedef {import('./types.js').CloseVerdict} CloseVerdict */
1
2
  /** An input with cells (M4d amendment 8): a file whose name ends `.csv`. The one decider for "this input can be cited". */
2
3
  export function isCellsPath(p: any): boolean;
3
4
  /**
4
- * `green` close: every field in `artifact.fields`, in declared order,
5
- * resolves and matches its cite. First red wins.
5
+ * M10 piece 4 (item 2, "green grows"): the green close of a step that cites quotes instead of cells. `part` is the step's fact part (`close.cited`, set by
6
+ * code from the page look's kept facts, never by the model); `source` is the run's OWN frozen copy of the page or doc (`readRunSource`); the artifact is
7
+ * `{ results: [{ quote, values: { <fact name>: "<value as the quote writes it>" } }] }`. bareguard's `cited` check proves each quote is word for word in
8
+ * the frozen text, each value is in its quote and passes its rule, and the number of results is as signed. No model grades.
9
+ * Third outcomes, each named, never green: no readable source or an artifact that is not an object (`unparseable`, a casualty), a part bareguard cannot sign
10
+ * (`crash`). `cited` carries what the runner writes to the run's cited-check record: the part and the check's own answer.
6
11
  *
12
+ * @param {any} part
7
13
  * @param {any} artifact
8
- * @param {{ reads: Record<string, any>, businessDate: string }} ctx
9
- * @returns {CloseVerdict}
14
+ * @param {{ok: true, text: string, sha256: string}|{ok: false, red: string}|null|undefined} source
15
+ * @returns {Promise<CloseVerdict>}
10
16
  */
11
- export function closeGreen(artifact: any, ctx: {
12
- reads: Record<string, any>;
13
- businessDate: string;
14
- }): CloseVerdict;
17
+ export function closeCited(part: any, artifact: any, source: {
18
+ ok: true;
19
+ text: string;
20
+ sha256: string;
21
+ } | {
22
+ ok: false;
23
+ red: string;
24
+ } | null | undefined): Promise<CloseVerdict>;
15
25
  /**
16
26
  * M4e amendment 18: the soft checks run on bareguard 0.21.0. `softgreenSpec(shape)` is the ONE place a declared shape
17
27
  * becomes a rubric spec (signing and the run both build through `buildSoftgreenRubric`, so a shape that signs is a shape
@@ -73,19 +83,36 @@ export function closeSoftgreen(artifact: any, shape: {
73
83
  /**
74
84
  * The one dispatcher — `close by declared class` (M2 scope item 4).
75
85
  *
76
- * @param {{ close?: { class?: string, shape?: Record<string, any> } }} step
86
+ * @param {{ close?: { class?: string, shape?: Record<string, any>, cited?: any, columns?: {source: string, column: string}[], sheet?: any[] } }} step
77
87
  * @param {unknown} artifact
78
- * @param {{ reads: Record<string, any>, businessDate: string }} ctx
88
+ * @param {{ reads: Record<string, any>, businessDate: string, source?: {ok: true, text: string, sha256: string}|{ok: false, red: string}|null, sheet?: any }} ctx
89
+ * `source` (M10 piece 4) = the run's own frozen copy a cited step reads, from `readRunSource`; only a step whose close carries `cited` reads it
90
+ * `sheet` (M10b piece 2) = the run's own tables and recorded `tableSha`s a step with `close.sheet` is checked on, from `readRunSheets`
79
91
  * @returns {Promise<CloseVerdict>}
80
92
  */
81
93
  export function closeByClass(step: {
82
94
  close?: {
83
95
  class?: string;
84
96
  shape?: Record<string, any>;
97
+ cited?: any;
98
+ columns?: {
99
+ source: string;
100
+ column: string;
101
+ }[];
102
+ sheet?: any[];
85
103
  };
86
104
  }, artifact: unknown, ctx: {
87
105
  reads: Record<string, any>;
88
106
  businessDate: string;
107
+ source?: {
108
+ ok: true;
109
+ text: string;
110
+ sha256: string;
111
+ } | {
112
+ ok: false;
113
+ red: string;
114
+ } | null;
115
+ sheet?: any;
89
116
  }): Promise<CloseVerdict>;
90
117
  export type CloseVerdict = import("./types.js").CloseVerdict;
91
118
  import { createRubric } from 'bareguard';