fwdloop 0.32.0 → 0.33.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 (93) hide show
  1. package/bin/fwdloop +8 -2
  2. package/package.json +2 -2
  3. package/src/auditchecks.js +53 -0
  4. package/src/authoring.js +52 -12
  5. package/src/blockasks.js +44 -0
  6. package/src/blockassemble.js +140 -0
  7. package/src/blockdraft.js +91 -0
  8. package/src/blocklines.js +30 -0
  9. package/src/blockpick.js +165 -0
  10. package/src/cardlist.js +19 -0
  11. package/src/checkblock.js +804 -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/checkwords.js +20 -1
  16. package/src/cited-record.js +21 -1
  17. package/src/citedcheck.js +162 -7
  18. package/src/closers.js +41 -3
  19. package/src/declaration.js +25 -2
  20. package/src/declaredclose.js +4 -0
  21. package/src/draft-steps.js +3 -1
  22. package/src/drafter.js +205 -122
  23. package/src/factwords.js +112 -0
  24. package/src/inputlook.js +53 -0
  25. package/src/labelscan.js +162 -0
  26. package/src/pageask.js +4 -1
  27. package/src/pagedropwords.js +11 -1
  28. package/src/panel/author.js +73 -4
  29. package/src/panel/authorcard.js +9 -6
  30. package/src/panel/data.js +41 -9
  31. package/src/panel/index.html +202 -13
  32. package/src/panel/result.js +4 -3
  33. package/src/panel/server.js +3 -1
  34. package/src/pickrecord.js +28 -0
  35. package/src/placerule.js +398 -0
  36. package/src/planrebuild.js +206 -0
  37. package/src/rowedit.js +118 -0
  38. package/src/rubricstep.js +264 -0
  39. package/src/runfile.js +4 -2
  40. package/src/runner.js +67 -10
  41. package/src/setup.js +10 -4
  42. package/src/sheetblock.js +6 -2
  43. package/src/sheetchecks.js +49 -64
  44. package/src/sheetclaims.js +12 -32
  45. package/src/sheetoffer.js +24 -52
  46. package/src/sheetrows.js +107 -0
  47. package/src/sheetrun.js +13 -10
  48. package/src/summary-words.js +3 -3
  49. package/src/try-checks.js +31 -12
  50. package/src/types.js +1 -0
  51. package/types/auditchecks.d.ts +24 -0
  52. package/types/authoring.d.ts +18 -1
  53. package/types/blockasks.d.ts +37 -0
  54. package/types/blockassemble.d.ts +33 -0
  55. package/types/blockdraft.d.ts +83 -0
  56. package/types/blocklines.d.ts +31 -0
  57. package/types/blockpick.d.ts +41 -0
  58. package/types/cardlist.d.ts +21 -0
  59. package/types/checkblock.d.ts +363 -0
  60. package/types/checked.d.ts +16 -2
  61. package/types/checklist.d.ts +115 -0
  62. package/types/checklistsign.d.ts +27 -0
  63. package/types/checkwords.d.ts +5 -0
  64. package/types/cited-record.d.ts +9 -0
  65. package/types/citedcheck.d.ts +33 -2
  66. package/types/closers.d.ts +24 -2
  67. package/types/declaredclose.d.ts +2 -0
  68. package/types/drafter.d.ts +15 -361
  69. package/types/factwords.d.ts +38 -0
  70. package/types/inputlook.d.ts +49 -0
  71. package/types/labelscan.d.ts +35 -0
  72. package/types/pageask.d.ts +2 -0
  73. package/types/panel/author.d.ts +41 -0
  74. package/types/panel/authorcard.d.ts +1 -1
  75. package/types/panel/data.d.ts +4 -2
  76. package/types/panel/jobgrid.d.ts +1 -1
  77. package/types/pickrecord.d.ts +22 -0
  78. package/types/placerule.d.ts +208 -0
  79. package/types/planrebuild.d.ts +52 -0
  80. package/types/provider.d.ts +1 -1
  81. package/types/rowedit.d.ts +33 -0
  82. package/types/rubricstep.d.ts +60 -0
  83. package/types/runfile.d.ts +5 -2
  84. package/types/runner.d.ts +45 -1
  85. package/types/sheetblock.d.ts +1 -0
  86. package/types/sheetchecks.d.ts +10 -17
  87. package/types/sheetclaims.d.ts +2 -1
  88. package/types/sheetoffer.d.ts +5 -5
  89. package/types/sheetrows.d.ts +73 -0
  90. package/types/sheetrun.d.ts +4 -4
  91. package/types/summary-words.d.ts +2 -1
  92. package/types/try-checks.d.ts +4 -2
  93. package/types/types.d.ts +8 -0
package/src/closers.js CHANGED
@@ -43,7 +43,7 @@
43
43
  // reading, flagged there as an interpretation call, not a rule from the
44
44
  // signed text).
45
45
 
46
- import { createRubric, checkStep } from 'bareguard';
46
+ import { createRubric, checkStep, numbersInQuote } from 'bareguard';
47
47
  import { plainWords } from './checkwords.js';
48
48
  import { checkCited } from './citedcheck.js';
49
49
  import { closeSheet } from './sheetrun.js';
@@ -271,14 +271,52 @@ export async function closeSoftgreen(artifact, shape) {
271
271
  /**
272
272
  * The one dispatcher — `close by declared class` (M2 scope item 4).
273
273
  *
274
- * @param {{ close?: { class?: string, shape?: Record<string, any>, picked?: any[], cited?: any, columns?: {source: string, column: string}[], sheet?: any[] } }} step
274
+ * @param {{ close?: { class?: string, shape?: Record<string, any>, picked?: any[], cited?: any, columns?: {source: string, column: string}[], sheet?: any[], numbersFrom?: number[] } }} step
275
275
  * @param {unknown} artifact
276
- * @param {{ reads: Record<string, any>, businessDate: string, source?: {ok: true, text: string, sha256: string}|{ok: false, red: string}|null, sheet?: any }} ctx
276
+ * @param {{ reads: Record<string, any>, businessDate: string, source?: {ok: true, text: string, sha256: string}|{ok: false, red: string}|null, sheet?: any, numbers?: {quotes: Record<string, string[]>, missing: number[]} }} ctx
277
277
  * `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
278
278
  * `sheet` (M10b piece 2) = the run's own tables and recorded `tableSha`s a step with `close.sheet` is checked on, from `readRunSheets`
279
279
  * @returns {Promise<CloseVerdict>}
280
280
  */
281
281
  export async function closeByClass(step, artifact, ctx) {
282
+ const base = await closeByClassOwn(step, artifact, ctx);
283
+ const from = step?.close?.numbersFrom;
284
+ return Array.isArray(from) && from.length > 0 ? withNumbers(base, closeNumbers(step, artifact, from, ctx.numbers)) : base;
285
+ }
286
+
287
+ /**
288
+ * M16 am3 (2), R7: the `$` numbers default of the check list. Every number in the answer's `text` must be in a quote an EARLIER line's cited check already passed (bareguard's `numbersInQuote`: a token match
289
+ * on the numbers, not a canonical compare, a documented limit; words are free). The quotes are the run's cited record of those lines (`ctx.numbers.quotes`, line -> quotes; `missing` = lines with none).
290
+ * Third outcomes: an answer with no `text` is `unparseable`, quotes that cannot be read (no record, a line not there yet) are `crash`; neither is ever green.
291
+ * What it throws away: only the numbers' token form is compared; a number written another way in the quote (1,000 vs 1000) is a bareguard question, not ours.
292
+ * @borrowed-from bareloop src/rubricstep.js@v0.56.0 (3383cce) gradeStep, PART 1b
293
+ * @param {any} step @param {unknown} artifact @param {number[]} from @param {{quotes: Record<string, string[]>, missing: number[]}|undefined} numbers
294
+ * @returns {{verdict: 'green'|'red'|'unparseable'|'crash', red: string|null, text: string}}
295
+ */
296
+ export function closeNumbers(step, artifact, from, numbers) {
297
+ const text = artifact && typeof artifact === 'object' ? /** @type {any} */ (artifact).text : undefined;
298
+ const words = `every number in the text is in a quote checked on line ${from.join(', ')}`;
299
+ if (typeof text !== 'string') return { verdict: 'unparseable', red: `numbers check: the answer must be shaped {text: string} so its numbers can be read, got ${describeArtifact(artifact)}`, text: words };
300
+ if (!numbers) return { verdict: 'crash', red: `numbers check crashed: the quotes of line ${from.join(', ')} are not available to this run`, text: words };
301
+ const gone = from.filter((n) => numbers.missing.includes(n) || !Array.isArray(numbers.quotes[String(n)]));
302
+ if (gone.length) return { verdict: 'red', red: `line ${gone.join(', ')}'s answer is not there yet, so the numbers in line ${step.fromLine}'s text cannot be tied to it`, text: words };
303
+ const t = numbersInQuote(text, from.flatMap((n) => numbers.quotes[String(n)]).join('\n'));
304
+ if (!t.ok) return { verdict: 'red', red: `line ${step.fromLine}: "text" has number(s) ${t.missing.join(', ')} that no checked quote of line ${from.join(', ')} holds - use only numbers from those quotes, written as they write them`, text: words };
305
+ return { verdict: 'green', red: null, text: words };
306
+ }
307
+
308
+ /** the numbers tie beside the class's own verdict: red if either is red (both told); a third outcome of either is never turned into green, the class's own winning when it has one @param {any} base @param {ReturnType<typeof closeNumbers>} num @returns {CloseVerdict} */
309
+ function withNumbers(base, num) {
310
+ const numbersCheck = { text: num.text, ok: num.verdict === 'green', result: num.verdict === 'green' ? null : num.verdict === 'red' ? num.red : num.verdict };
311
+ if (base.verdict === 'crash' || base.verdict === 'unparseable') return { ...base, numbersCheck };
312
+ if (num.verdict === 'crash' || num.verdict === 'unparseable') return { ...num, verdict: num.verdict, red: num.red, ...(base.cited ? { cited: base.cited } : {}), numbersCheck };
313
+ if (num.verdict === 'green') return { ...base, numbersCheck };
314
+ const reds = [...(base.verdict === 'red' ? [base.red] : []), num.red].filter(Boolean);
315
+ return { ...base, verdict: 'red', red: reds.join('\n'), ...(base.reds || reds.length > 1 ? { reds } : {}), numbersCheck };
316
+ }
317
+
318
+ /** @param {any} step @param {unknown} artifact @param {any} ctx @returns {Promise<CloseVerdict>} */
319
+ async function closeByClassOwn(step, artifact, ctx) {
282
320
  const cls = step?.close?.class;
283
321
  if (cls === 'green' && Array.isArray(step?.close?.picked) && step.close.picked.length > 0) return await closeFactAndPicks(step, artifact, ctx);
284
322
  return await closeOne(step, artifact, ctx);
@@ -44,6 +44,7 @@ import { SHEET_RULES, MAX_SHEET_CHECKS, sheetCheckColumns, sheetCheckReds, sheet
44
44
  import { lineRules } from './pagebits.js';
45
45
  import { OFFERED as OFFERED_RULES } from './checkwords.js';
46
46
  import { isColumnChoiceRule } from './sheetoffer.js';
47
+ import { checkListReds } from './checklistsign.js';
47
48
 
48
49
  /** @typedef {import('./types.js').Arbiter} Arbiter */
49
50
  /** @typedef {import('./types.js').SignedLine} SignedLine */
@@ -65,6 +66,7 @@ export const DECLARATION_FIELDS = Object.freeze([
65
66
  'ticketFilter',
66
67
  'ticketWatch',
67
68
  'pickedLines',
69
+ 'checkList',
68
70
  // step level
69
71
  'goal',
70
72
  'primitives',
@@ -81,6 +83,7 @@ export const DECLARATION_FIELDS = Object.freeze([
81
83
  'columns',
82
84
  'sheet',
83
85
  'picked',
86
+ 'numbersFrom',
84
87
  ]);
85
88
 
86
89
  const VALID_CLASSES = Object.freeze(['green', 'softgreen', 'hitl']);
@@ -91,9 +94,9 @@ const VALID_CLASSES = Object.freeze(['green', 'softgreen', 'hitl']);
91
94
  // an ask's position, an ask's TTL, the egress allow-list...").
92
95
  const ARBITER_KEYS = Object.freeze(['cap', 'ask', 'ttl', 'send', 'source', 'trigger', 'skills']);
93
96
 
94
- const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts', 'mcp', 'flowType', 'ticketFilter', 'ticketWatch', 'pickedLines']);
97
+ const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts', 'mcp', 'flowType', 'ticketFilter', 'ticketWatch', 'pickedLines', 'checkList']);
95
98
  const STEP_ALLOWED = Object.freeze(['goal', 'primitives', 'reads', 'emits', 'fromLine', 'close', 'picks', 'mcpTools']);
96
- const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet', 'picked']);
99
+ const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet', 'picked', 'numbersFrom']);
97
100
 
98
101
  /** M13 piece 4 (signed item 4): the job's flow type, set by code from the job card, signed with the job. */
99
102
  export const FLOW_TYPES = Object.freeze(['plain', 'mcp', 'tickets']);
@@ -586,6 +589,22 @@ function checkPickedKey(step, label, effectiveClass, reds, declaration) {
586
589
  try { buildSoftgreenRubric({ picked: step.close.picked }); } catch (err) { reds.push(`${at} cannot be built into a check - ${String(err.message).replace(/^invalid rubric: /, '')}`); }
587
590
  }
588
591
 
592
+ /**
593
+ * M16 am3 (2): `close.numbersFrom` is the numbers tie of a text step (the `$` default of the check list): the job lines, all EARLIER, whose checked quotes every number in this step's text must be in.
594
+ * Code sets it (src/blockassemble.js). Each line it names must be a green step that checks quotes (`close.cited`); a step that checks quotes has no text of its own to tie.
595
+ * @param {any} step @param {string} label @param {any[]} steps @param {string[]} reds
596
+ */
597
+ function checkNumbersFromKey(step, label, steps, reds) {
598
+ const at = `declaration: ${label}.close.numbersFrom`;
599
+ const v = step.close.numbersFrom;
600
+ if (!Array.isArray(v) || v.length === 0 || !v.every((n) => Number.isInteger(n) && n > 0) || new Set(v).size !== v.length) { reds.push(`${at} must be a non-empty list of distinct job line numbers`); return; }
601
+ if (isPlainObject(step.close.cited)) reds.push(`${at}: line ${step.fromLine} checks quotes, so it has no text whose numbers could be tied to other lines`);
602
+ for (const n of v) {
603
+ if (!Number.isInteger(step.fromLine) || n >= step.fromLine) reds.push(`${at}: line ${n} is not before line ${step.fromLine}`);
604
+ else if (!steps.some((st) => isPlainObject(st) && st.fromLine === n && st.close?.class === 'green' && isPlainObject(st.close?.cited))) reds.push(`${at}: line ${n} is not a line that checks quotes, so its quotes cannot hold line ${step.fromLine}'s numbers`);
605
+ }
606
+ }
607
+
589
608
  /**
590
609
  * M10 amendment 7 item 1: `close.cited` is the facts a green step checks its quotes against, written by the drafter (a fact part:
591
610
  * `{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
@@ -1027,6 +1046,7 @@ export function validateDeclaration(declaration, context = {}) {
1027
1046
  else if (fitJobLine === true && effectiveClass === 'green' && step.close.shape !== undefined && step.close.shape !== null) {
1028
1047
  reds.push(`declaration: ${label}.close.shape: a step that checks facts carries no count check of the drafter's own; only a check you picked (close.picked, on a line recorded in pickedLines) can sit beside its fact check`);
1029
1048
  }
1049
+ if (step.close.numbersFrom !== undefined) checkNumbersFromKey(step, label, steps, reds);
1030
1050
  if (step.close.cited !== undefined) checkCitedKey(step, label, { sourceRoles, reads, effectiveClass, lines: safeLines, fitJobLine, pageWords }, reds);
1031
1051
  if (step.close.sheet !== undefined) checkSheetKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, fitJobLine, sheetWords }, reds);
1032
1052
  if (step.close.columns !== undefined || (fitJobLine === true && sheetWords)) checkColumnsKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, sheetWords }, reds);
@@ -1099,6 +1119,9 @@ export function validateDeclaration(declaration, context = {}) {
1099
1119
  });
1100
1120
  });
1101
1121
 
1122
+ // M16 item 2: the checks of a list line are the signed list's; a plan carrying one proves it here, at sign and at run start ($0)
1123
+ reds.push(...checkListReds(declaration));
1124
+
1102
1125
  // --- ask slots (ported from poc/m1/slots.mjs's checkAskSlots) --------------
1103
1126
  // (a) exactly one hitl step bound to each signed ask line.
1104
1127
  for (const n of askLines) {
@@ -0,0 +1,4 @@
1
+ // borrowed-from: bareloop src/declaredclose.js@v0.56.0 (3383cce) (SIGNED_ROW_FIELDS only: the constant the check block names; the rest of that module (kinds, judged, ralph, validate) is not wanted here)
2
+
3
+ /** the fields of a row of the one check list that the signed close carries (`closeDecl.list`); the row's own words are never signed */
4
+ export const SIGNED_ROW_FIELDS = Object.freeze(['line', 'key', 'from', 'by', 'kind', 'state', 'rule', 'part', 'reason', 'facts']);
@@ -24,7 +24,9 @@ function money(log) {
24
24
  */
25
25
  export function triesOf(rounds) {
26
26
  let no = 0;
27
- return (Array.isArray(rounds) ? rounds : []).map((e, i, all) => {
27
+ // M16: only the declaration rounds are tries; the list's own turns (ledger-suggest, row-edit) and the looks are not
28
+ const declared = (Array.isArray(rounds) ? rounds : []).filter((e) => ['first', 'revision', 'structure-retry'].includes(e?.kind));
29
+ return declared.map((e, i, all) => {
28
30
  const again = e?.kind === 'structure-retry' && i > 0;
29
31
  if (!again) no += 1;
30
32
  const passed = e?.outcome === 'valid';