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
@@ -37,6 +37,11 @@
37
37
  // greps all of src/ for that, and it must keep passing with this file added.
38
38
 
39
39
  import { buildSoftgreenRubric, isCellsPath } from './closers.js';
40
+ import { factPartReds } from './citedcheck.js';
41
+ import { numberRuleReds, countReds, citedWordReds } from './citedwords.js';
42
+ import { SHEET_RULES, MAX_SHEET_CHECKS, sheetCheckColumns, sheetCheckReds, sheetCheckWordReds, sheetNoClaimReds, sheetCoversReds } from './sheetchecks.js';
43
+ import { lineRules } from './pagebits.js';
44
+ import { isColumnChoiceRule } from './sheetoffer.js';
40
45
 
41
46
  /** @typedef {import('./types.js').Arbiter} Arbiter */
42
47
  /** @typedef {import('./types.js').SignedLine} SignedLine */
@@ -64,6 +69,9 @@ export const DECLARATION_FIELDS = Object.freeze([
64
69
  // close level
65
70
  'class',
66
71
  'shape',
72
+ 'cited',
73
+ 'columns',
74
+ 'sheet',
67
75
  ]);
68
76
 
69
77
  const VALID_CLASSES = Object.freeze(['green', 'softgreen', 'hitl']);
@@ -76,7 +84,7 @@ const ARBITER_KEYS = Object.freeze(['cap', 'ask', 'ttl', 'send', 'source', 'trig
76
84
 
77
85
  const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts']);
78
86
  const STEP_ALLOWED = Object.freeze(['goal', 'primitives', 'reads', 'emits', 'fromLine', 'close', 'picks']);
79
- const CLOSE_ALLOWED = Object.freeze(['class', 'shape']);
87
+ const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet']);
80
88
 
81
89
  /** @returns {value is Record<string, any>} */
82
90
  function isPlainObject(value) {
@@ -403,6 +411,113 @@ function checkShapeBuilds(shape, label, reds, redsBefore) {
403
411
  }
404
412
  }
405
413
 
414
+ /**
415
+ * M10 amendment 7 item 1: `close.cited` is the facts a green step checks its quotes against, written by the drafter (a fact part:
416
+ * `{source, facts, count?}`, src/citedcheck.js). Its SHAPE is checked in every mode (a signed flow is read the same way). With `fitJobLine` the number rules
417
+ * must be the person's own words on the job line; with `pageWords` (the drafting copy of each page and what the page-word map kept) every word is proved on
418
+ * the page at $0 (src/citedwords.js). Each red names the job line, so a redraft can be told which line.
419
+ * @param {any} step @param {string} label @param {{sourceRoles: any[], reads: string[]|null, effectiveClass: string, lines: SignedLine[], fitJobLine?: boolean, pageWords?: {texts: Record<string, string>, look: any, docs?: string[]}}} c @param {string[]} reds
420
+ */
421
+ function checkCitedKey(step, label, c, reds) {
422
+ const at = `declaration: ${label}.close.cited`;
423
+ const part = step.close.cited;
424
+ if (!isPlainObject(part)) { reds.push(`${at} must be an object {source, facts, count}`); return; }
425
+ if (step.close.class !== 'green' || c.effectiveClass !== 'green') reds.push(`${at} is for a green step only (its quotes are checked against the page); this step's check is "${step.close.class ?? c.effectiveClass}"`);
426
+ for (const r of factPartReds(part)) reds.push(`${at}: ${r}`);
427
+ if (typeof part.source === 'string' && part.source.trim() !== '') {
428
+ if (!c.sourceRoles.includes(part.source)) reds.push(`${at}.source "${part.source}" is not one of the signed source roles`);
429
+ else if (c.reads !== null && !c.reads.includes(part.source)) reds.push(`${at}.source "${part.source}" is not in ${label}.reads - the step must read the input its quotes come from`);
430
+ }
431
+ if (c.fitJobLine !== true || !Number.isInteger(step.fromLine)) return;
432
+ const jobLine = c.lines.find((l) => l.n === step.fromLine);
433
+ if (!jobLine) return;
434
+ const jl = { n: jobLine.n, text: jobLine.text, ...(jobLine.guardrail ? { rule: jobLine.guardrail } : {}) };
435
+ // a part that is not valid is not read further: its words would only repeat the same red
436
+ if (factPartReds(part).length) return;
437
+ const words = c.pageWords ? citedWordReds({ part, text: c.pageWords.texts[part.source], line: jl.n, jobLine: jl, look: c.pageWords.look, doc: Array.isArray(c.pageWords.docs) && c.pageWords.docs.includes(part.source) }) : [...numberRuleReds({ part, jobLine: jl }), ...countReds({ part, jobLine: jl })];
438
+ for (const r of words) reds.push(`declaration: ${r.detail}`);
439
+ }
440
+
441
+ /**
442
+ * M10 am8 item 2: `close.columns` is the column choice of a green step that reads a sheet: `[{source, column}]`, written by the drafter and checked by code (the old cell-cite check that enforced it at run time retired in M10b piece 5; a job signed with it still reads). Its SHAPE is
443
+ * checked in every mode; with `sheetWords` (draft time) every column is proved to be a real column of its sheet and a column the sheet look kept for this step's
444
+ * line must be in the list. M10b am3: a step with `close.sheet` is exempt from the list; an AGREED column must instead be used by one of its checks.
445
+ * @param {any} step @param {string} label @param {{cellsRoles: string[], reads: string[]|null, effectiveClass: string, lines?: SignedLine[], sheetWords?: {headers: Record<string, string[]>, facts: any[]}}} c @param {string[]} reds
446
+ */
447
+ function checkColumnsKey(step, label, c, reds) {
448
+ const at = `declaration: ${label}.close.columns`;
449
+ const cols = step.close.columns;
450
+ if (cols !== undefined) {
451
+ if (step.close.class !== 'green' || c.effectiveClass !== 'green') reds.push(`${at} is for a green step only (its cells are checked); this step's check is "${step.close.class ?? c.effectiveClass}"`);
452
+ if (!Array.isArray(cols) || cols.length === 0 || cols.length > 10) { reds.push(`${at} must be a list of 1 to 10 {source, column}`); return; }
453
+ for (const [j, e] of cols.entries()) {
454
+ if (!isPlainObject(e) || Object.keys(e).some((k) => k !== 'source' && k !== 'column') || typeof e.source !== 'string' || typeof e.column !== 'string' || e.column.trim() === '') {
455
+ reds.push(`${at}[${j}] must be {source, column}, both words`);
456
+ } else if (!c.cellsRoles.includes(e.source)) {
457
+ reds.push(`${at}[${j}].source "${e.source}" is not a signed spreadsheet input`);
458
+ } else if (c.reads !== null && !c.reads.includes(e.source)) {
459
+ reds.push(`${at}[${j}].source "${e.source}" is not in ${label}.reads - the step must read the sheet its cells come from`);
460
+ }
461
+ }
462
+ }
463
+ const sw = c.sheetWords;
464
+ if (!sw || !Number.isInteger(step.fromLine)) return;
465
+ const list = Array.isArray(cols) ? cols.filter((e) => isPlainObject(e) && typeof e.column === 'string') : [];
466
+ for (const e of list) {
467
+ const header = sw.headers?.[e.source];
468
+ if (Array.isArray(header) && !header.includes(e.column)) reds.push(`declaration: line ${step.fromLine}: '${e.column}' is not a real column of "${e.source}" (its columns: ${header.map((h) => `'${h}'`).join(', ')}). Copy a column name exactly.`);
469
+ }
470
+ const sheet = Array.isArray(step.close.sheet) ? step.close.sheet : null;
471
+ const covLine = (c.lines ?? []).find((l) => l.n === step.fromLine);
472
+ for (const f of sw.facts ?? []) {
473
+ if (f.line !== step.fromLine || f.shape !== 'column') continue;
474
+ if (sheet !== null) {
475
+ // M10b am3: with sheet checks a job word that matches a header does nothing by itself; only a column the person AGREED to (a column ask wrote
476
+ // "use the column 'X' for 'Y'" on the line) must be used by at least one of this line's checks
477
+ const agreed = f.agreed === true || lineRules(covLine).some((r) => isColumnChoiceRule(r) && r.startsWith(`use the column '${f.column}' for '`));
478
+ if (agreed && !sheet.some((chk) => chk?.table === f.source && sheetCheckColumns(chk).includes(f.column))) reds.push(`declaration: line ${step.fromLine}: a check must use the column '${f.column}' of "${f.source}" - the column you agreed to for this line.`);
479
+ continue;
480
+ }
481
+ if (!list.some((e) => e.source === f.source && e.column === f.column)) reds.push(`declaration: line ${step.fromLine}: the check must name the column '${f.column}' of "${f.source}" in close.columns - the code kept it for this line${f.agreed ? ' (the column you agreed to)' : ''}, and every cell must come from it.`);
482
+ }
483
+ }
484
+
485
+ /**
486
+ * M10b piece 1: `close.sheet` is the signed bareguard checks of a green step that reads a CSV sheet: a list of bareguard `cells` / `table` check objects
487
+ * (src/sheetchecks.js), each naming the step's sheet input in `table`. The drafter will offer them (piece 3); fwdloop stores them as data. Its SHAPE is checked in
488
+ * every mode (a signed flow is read the same way). With `sheetWords.tables` (the drafting copy's table of each sheet, draft time) every column is proved an exact
489
+ * header of its sheet and bareguard's own sign-time test (`createRubric` over the sheet's `tableSha`) must accept the list; each red names the job line.
490
+ * @param {any} step @param {string} label @param {{cellsRoles: string[], reads: string[]|null, effectiveClass: string, lines?: SignedLine[], fitJobLine?: boolean, sheetWords?: {tables?: Record<string, {header: string[], rows: any[]}>}}} c @param {string[]} reds
491
+ * M10b piece 3: with `fitJobLine` a number or a date in a check must be in the person's own words on the job line (src/sheetchecks.js `sheetCheckWordReds`), and a list of
492
+ * only `table` checks (nothing for the step to answer) is refused; each red names the line.
493
+ */
494
+ function checkSheetKey(step, label, c, reds) {
495
+ const at = `declaration: ${label}.close.sheet`;
496
+ const list = step.close.sheet;
497
+ if (step.close.class !== 'green' || c.effectiveClass !== 'green') reds.push(`${at} is for a green step only (its sheet is checked by bareguard); this step's check is "${step.close.class ?? c.effectiveClass}"`);
498
+ if (!Array.isArray(list) || list.length === 0 || list.length > MAX_SHEET_CHECKS) { reds.push(`${at} must be a list of 1 to ${MAX_SHEET_CHECKS} bareguard checks`); return; }
499
+ let shapeOk = true;
500
+ for (const [j, e] of list.entries()) {
501
+ if (!isPlainObject(e)) { reds.push(`${at}[${j}] must be a check object`); shapeOk = false; continue; }
502
+ scanForArbiterKeys(e, `${at}[${j}]`, reds);
503
+ if (!SHEET_RULES.includes(e.rule)) { reds.push(`${at}[${j}].rule must be one of ${SHEET_RULES.join(', ')}`); shapeOk = false; }
504
+ if (typeof e.table !== 'string' || !c.cellsRoles.includes(e.table)) { reds.push(`${at}[${j}].table ${JSON.stringify(e.table)} is not a signed spreadsheet input`); shapeOk = false; }
505
+ else if (c.reads !== null && !c.reads.includes(e.table)) { reds.push(`${at}[${j}].table "${e.table}" is not in ${label}.reads - the step must read the sheet its checks come from`); shapeOk = false; }
506
+ }
507
+ if (shapeOk && Number.isInteger(step.fromLine)) {
508
+ const covLine = (c.lines ?? []).find((l) => l.n === step.fromLine);
509
+ if (covLine) for (const r of sheetCoversReds(list, { n: covLine.n, ...(covLine.guardrail ? { rule: covLine.guardrail } : {}) })) reds.push(r);
510
+ }
511
+ if (shapeOk && c.fitJobLine === true && Number.isInteger(step.fromLine)) {
512
+ const jobLine = (c.lines ?? []).find((l) => l.n === step.fromLine);
513
+ if (jobLine) for (const r of sheetCheckWordReds(list, { n: jobLine.n, text: jobLine.text, ...(jobLine.guardrail ? { rule: jobLine.guardrail } : {}) })) reds.push(r);
514
+ for (const r of sheetNoClaimReds(list, step.fromLine)) reds.push(r);
515
+ }
516
+ const tables = c.sheetWords?.tables;
517
+ if (!shapeOk || !tables || !Number.isInteger(step.fromLine)) return;
518
+ for (const r of sheetCheckReds(list, step.fromLine, tables)) reds.push(r);
519
+ }
520
+
406
521
  /**
407
522
  * Validate a drafter declaration against the M1 closed schema. `arbiter`
408
523
  * and `lines` are `parseSignedText`'s output; `catalogue` is a plain array
@@ -417,11 +532,17 @@ function checkShapeBuilds(shape, label, reds, redsBefore) {
417
532
  * text as its goal, exactly. Off by default so already-signed flows keep running; draft and sign turn it on.
418
533
  * `fitJobLine` (optional boolean; M4e amendment 6): when true, a `close.shape` whose sections/maxWords fight the step's job
419
534
  * line or its guardrail is a red. Draft, change and sign turn it on; readFlow does not (signed flows keep running).
420
- * @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown, wired?: Set<string>, verbatimGoals?: boolean, fitJobLine?: boolean }} [context]
535
+ * `pageWords` (optional; M10 am7 item 1): `{texts: {role: drafting copy}, look: {facts, dropped}}`. With `fitJobLine`, the words of every `close.cited` fact are
536
+ * proved on the page at $0; the drafter passes it, sign does not (the draft was already proved, and its files are hash-bound).
537
+ * `pageWords.docs` (M10 piece 5): the roles that are documents (.docx / .md / .txt): their words are proved on their text alone, with no page-word map.
538
+ * `sheetWords` (optional; M10 am8 item 2): `{headers: {role: header names}, facts: the columns the sheet look kept}`. With `fitJobLine`, every column a step's `close.columns` names
539
+ * is proved a real column of its sheet, and a column the code kept for the step's line (an agreed one included) must be in it.
540
+ * `sheetWords.tables` (optional; M10b piece 1): `{role: bareguard table}` of the drafting copy. With it, every `close.sheet` check passes bareguard's sign-time test at $0.
541
+ * @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown, wired?: Set<string>, verbatimGoals?: boolean, fitJobLine?: boolean, pageWords?: {texts: Record<string, string>, look: any, docs?: string[]}, sheetWords?: {headers: Record<string, string[]>, facts: any[], tables?: Record<string, {header: string[], rows: any[]}>} }} [context]
421
542
  * @returns {ValidateDeclarationResult}
422
543
  */
423
544
  export function validateDeclaration(declaration, context = {}) {
424
- const { arbiter, lines, catalogue, wired, verbatimGoals, fitJobLine } = context;
545
+ const { arbiter, lines, catalogue, wired, verbatimGoals, fitJobLine, pageWords, sheetWords } = context;
425
546
  const reds = [];
426
547
 
427
548
  if (!isPlainObject(declaration)) {
@@ -445,6 +566,10 @@ export function validateDeclaration(declaration, context = {}) {
445
566
  // M4d amendment 8: the inputs with cells (a spreadsheet file). A step may read one by its role; a green step must.
446
567
  const cellsRoles = Array.isArray(safeArbiter.sources)
447
568
  ? safeArbiter.sources.filter((s) => s?.kind === 'file' && isCellsPath(s.path)).map((s) => s.role) : [];
569
+ // M10 am7 item 3: a web page is an input too, frozen at run start; a step reads it by its role (its quotes are checked against the run's own copy)
570
+ const pageRoles = Array.isArray(safeArbiter.sources) ? safeArbiter.sources.filter((s) => s?.kind === 'page').map((s) => s.role) : [];
571
+ // M10 piece 5 (item 2): a document (.docx / .md / .txt) may be READ by a step that quotes it (its close.cited.source), and by no other step
572
+ const docRoles = Array.isArray(safeArbiter.sources) ? safeArbiter.sources.filter((s) => s?.kind === 'file' && ['.docx', '.md', '.txt'].some((x) => String(s.path).toLowerCase().endsWith(x))).map((s) => s.role) : [];
448
573
  const asks = Array.isArray(safeArbiter.asks) ? safeArbiter.asks : [];
449
574
  const askLines = asks.map((a) => a.line);
450
575
  const sends = Array.isArray(safeArbiter.sends) ? safeArbiter.sends : [];
@@ -637,6 +762,8 @@ export function validateDeclaration(declaration, context = {}) {
637
762
  if (reads !== null && emits !== null) {
638
763
  for (const readId of reads) {
639
764
  if (cellsRoles.includes(readId) && !declaredEmits.has(readId)) continue; // an input with cells, frozen at run start (M4d amendment 8)
765
+ if (pageRoles.includes(readId) && !declaredEmits.has(readId)) continue; // a web page, frozen at run start (M10 am7 item 3)
766
+ if (docRoles.includes(readId) && !declaredEmits.has(readId) && step.close?.cited?.source === readId) continue; // a document the step quotes (M10 piece 5)
640
767
  if (readId === emits || !declaredEmits.has(readId)) {
641
768
  reds.push(`declaration: ${label} reads artifact "${readId}" that no earlier step declared`);
642
769
  }
@@ -644,7 +771,7 @@ export function validateDeclaration(declaration, context = {}) {
644
771
  }
645
772
  const earlierEmits = [...declaredEmits]; // outputs of EARLIER steps, in order (the nearest is last)
646
773
  if (emits !== null) declaredEmits.add(emits);
647
- if (fitJobLine === true && emits !== null && cellsRoles.includes(emits)) reds.push(`declaration: ${label}.emits "${emits}" is also a signed input — one id, one meaning`);
774
+ if (fitJobLine === true && emits !== null && (cellsRoles.includes(emits) || pageRoles.includes(emits))) reds.push(`declaration: ${label}.emits "${emits}" is also a signed input — one id, one meaning`);
648
775
 
649
776
  // fromLine + class derivation — the key itself is required (value may be
650
777
  // null, meaning "no line"; the key being entirely absent is not the same
@@ -690,6 +817,9 @@ export function validateDeclaration(declaration, context = {}) {
690
817
  if (fitJobLine === true) checkShapeFitsJobLine(step, i, safeLines, reds);
691
818
  }
692
819
  }
820
+ if (step.close.cited !== undefined) checkCitedKey(step, label, { sourceRoles, reads, effectiveClass, lines: safeLines, fitJobLine, pageWords }, reds);
821
+ if (step.close.sheet !== undefined) checkSheetKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, fitJobLine, sheetWords }, reds);
822
+ if (step.close.columns !== undefined || (fitJobLine === true && sheetWords)) checkColumnsKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, sheetWords }, reds);
693
823
  }
694
824
  }
695
825
 
@@ -701,13 +831,21 @@ export function validateDeclaration(declaration, context = {}) {
701
831
 
702
832
  // M4d amendment 8: a step whose check is green (every figure cites a source cell) must read an input with cells; a text
703
833
  // output of an earlier step has no cells to cite.
704
- if (fitJobLine === true && effectiveClass === 'green' && reads !== null && !reads.some((r) => cellsRoles.includes(r))) {
834
+ // M10 am7: a green step that cites quotes (`close.cited`) reads a web page, which has no cells; its source is checked above.
835
+ if (fitJobLine === true && effectiveClass === 'green' && reads !== null && !reads.some((r) => cellsRoles.includes(r)) && !isPlainObject(step.close?.cited)) {
705
836
  const n = fromLine;
706
837
  const reading = reads.length === 0 ? 'it reads nothing' : `it reads only ${reads.join(', ')}`;
707
838
  const want = cellsRoles.length === 0 ? 'a spreadsheet input, and this job signs none' : cellsRoles.join(' or ');
708
839
  reds.push(`declaration: Line ${n}'s check needs cells, but ${reading}. Line ${n} must read ${want}.`);
709
840
  }
710
841
 
842
+ // M10b piece 5 (item 8): the old cell cite retires for CSV. A green step that reads a spreadsheet answers in bareguard's claim boxes (`close.sheet`);
843
+ // one with neither `close.sheet` nor `close.cited` would be the old cite close, which a new plan no longer offers. Signed flows keep running (fitJobLine only).
844
+ if (fitJobLine === true && effectiveClass === 'green' && reads !== null && reads.some((r) => cellsRoles.includes(r))
845
+ && !isPlainObject(step.close?.cited) && !Array.isArray(step.close?.sheet)) {
846
+ reds.push(`declaration: Line ${fromLine}'s check cannot cite cells any more. Line ${fromLine} must carry close.sheet: bareguard's checks of ${reads.filter((r) => cellsRoles.includes(r)).join(' or ')}.`);
847
+ }
848
+
711
849
  // M4d amendment 9: an ask step shows you something: its FIRST read must be the output of an earlier step. A read is not a
712
850
  // grant (the ask stays a pure stop); the check is for the plan checker only (fitJobLine), so signed flows still run.
713
851
  if (fitJobLine === true && reads !== null && fromLine !== null && askLines.includes(fromLine)
package/src/diary.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // tools.jsonl one row per TOOL CALL: step, try, round, tool, path, the guard's decision (allow / deny + rule / no check)
5
5
  // checks.jsonl one row per TRY that ran checks: each check numbered, ✓/✗, its result, where it comes from, and the output it judged
6
6
  // Never saved: what the model said, what was in any file (a tool row names a path, never its content). Every string is scrubbed with the
7
- // ONE secret inventory (`redactSecrets`, src/ctx-tools.js) before the row is written. The model can never read these files: the step's
7
+ // ONE secret inventory (`redactSecrets`, src/redact.js) before the row is written. The model can never read these files: the step's
8
8
  // bareguard Gate denies them (src/primitives.js) and a grep over the run folder drops their hits.
9
9
  // Rounds count from 1 in EACH STEP (they keep counting across that step's tries); `nextRound` reads the count off the diary.
10
10
  //
@@ -12,7 +12,7 @@
12
12
  import { join } from 'node:path';
13
13
  import { appendRow } from './jsonl-append.js';
14
14
  import { readLines } from './books.js';
15
- import { redactSecrets } from './ctx-tools.js';
15
+ import { redactSecrets } from './redact.js';
16
16
 
17
17
  export const DIARY_FILES = Object.freeze({ calls: 'calls.jsonl', tools: 'tools.jsonl', checks: 'checks.jsonl' });
18
18
 
package/src/docx.js CHANGED
@@ -12,6 +12,7 @@
12
12
  // is over raw paragraph markup, not a parsed tree).
13
13
 
14
14
  import { readFileSync } from 'node:fs';
15
+ import { createHash } from 'node:crypto';
15
16
  import { inflateRawSync } from 'node:zlib';
16
17
 
17
18
  const EOCD_SIG = 0x06054b50;
@@ -128,7 +129,8 @@ function extractText(xml) {
128
129
  }
129
130
 
130
131
  /** One reader for word/document.xml: the file, the zip entry, the bounded inflate.
131
- * @param {string} path @returns {{ok:true,xml:string}|{ok:false,red:string}} */
132
+ * `sha256` is of the file's bytes, taken from the SAME read the text comes from (so a text and its hash can never be of two different files).
133
+ * @param {string} path @returns {{ok:true,xml:string,sha256:string}|{ok:false,red:string}} */
132
134
  function loadDocumentXml(path) {
133
135
  let buf;
134
136
  try {
@@ -140,7 +142,7 @@ function loadDocumentXml(path) {
140
142
  if (entry.red) return { ok: false, red: entry.red };
141
143
  const read = readEntryBytes(buf, entry);
142
144
  if (read.red || !read.data) return { ok: false, red: read.red ?? 'no data decoded' };
143
- return { ok: true, xml: read.data.toString('utf8') };
145
+ return { ok: true, xml: read.data.toString('utf8'), sha256: createHash('sha256').update(buf).digest('hex') };
144
146
  }
145
147
 
146
148
  /** @param {string} path @returns {{ok:true,text:string,paragraphs:number}|{ok:false,red:string}} */
@@ -151,6 +153,18 @@ export function readDocxText(path) {
151
153
  return { ok: true, text, paragraphs };
152
154
  }
153
155
 
156
+ /**
157
+ * M10 piece 5 (item 2, "a quote in a doc"): the text of a .docx AND the sha256 of its bytes from one read, so a cited check can prove the run's own frozen copy is
158
+ * the file that was frozen. Same text as {@link readDocxText} (what it throws away is declared at the top of this file).
159
+ * @param {string} path @returns {{ok:true,text:string,paragraphs:number,sha256:string}|{ok:false,red:string}}
160
+ */
161
+ export function readDocxSource(path) {
162
+ const doc = loadDocumentXml(path);
163
+ if (!doc.ok) return doc;
164
+ const { text, paragraphs } = extractText(doc.xml);
165
+ return { ok: true, text, paragraphs, sha256: doc.sha256 };
166
+ }
167
+
154
168
  // Heading paragraphs: <w:pStyle w:val="Heading1"/> .. HeadingN, or Title. The
155
169
  // style ID is matched, not styles.xml's display name — Word writes the ID
156
170
  // "Heading1" for the built-in "heading 1"; a custom-named heading style is
@@ -69,7 +69,7 @@ export function draftStepList({ log, declaration, questionOpen = false }) {
69
69
  const reds = Array.isArray(log.reds) ? log.reds.map(String) : [];
70
70
  const facts = ['drafted', who, `${n} round${n === 1 ? '' : 's'}`, money(log)];
71
71
  if (!gotPlan && reds.length > 0) facts.push(reds[0]); // no plan at all (provider red, cut off): its own words, there is no checker text
72
- out.push({ id: 'drafted', label: facts.join(' · '), status: /** @type {'done'|'failed'} */ (gotPlan ? 'done' : 'failed'), details: [] });
72
+ out.push({ id: 'drafted', label: facts.join(' · '), status: /** @type {'done'|'failed'} */ (gotPlan || (questionOpen && reds.length === 0) ? 'done' : 'failed'), details: [] }); // a draft that stopped to ask (the page look's question, no plan yet) has not failed
73
73
 
74
74
  const steps = Array.isArray(declaration?.steps) ? declaration.steps : [];
75
75
  const rubricReds = [];