fwdloop 0.35.2 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/fwdloop +5 -2
- package/package.json +3 -3
- package/src/action-stop.js +1 -1
- package/src/auditchecks.js +41 -9
- package/src/authoring.js +78 -20
- package/src/blockasks.js +10 -12
- package/src/blockassemble.js +49 -43
- package/src/blockdraft.js +4 -2
- package/src/blockpick.js +10 -0
- package/src/canrun.js +2 -1
- package/src/cardlist.js +28 -5
- package/src/checkblock.js +610 -64
- package/src/checked.js +28 -33
- package/src/checklistsign.js +2 -1
- package/src/checklook.js +45 -0
- package/src/checkrows.js +202 -0
- package/src/cited-record.js +2 -2
- package/src/citedcheck.js +53 -12
- package/src/citedwords.js +7 -4
- package/src/closers.js +49 -2
- package/src/declaration.js +26 -4
- package/src/drafter.js +86 -62
- package/src/factwords.js +7 -4
- package/src/globprefix.js +26 -0
- package/src/model-step.js +22 -4
- package/src/pageask.js +6 -4
- package/src/pagedropwords.js +3 -11
- package/src/pagedry.js +75 -1
- package/src/pagefetch.js +11 -6
- package/src/pagelook.js +2 -1
- package/src/pagerules.js +8 -2
- package/src/panel/author.js +20 -8
- package/src/panel/authorcard.js +3 -3
- package/src/panel/data.js +3 -2
- package/src/panel/index.html +176 -41
- package/src/panel/result.js +40 -3
- package/src/pickrecord.js +14 -0
- package/src/planrebuild.js +55 -19
- package/src/ratelimit.js +117 -0
- package/src/report.js +216 -0
- package/src/rowresults.js +111 -0
- package/src/rubricstep.js +65 -2
- package/src/runner.js +61 -9
- package/src/send.js +19 -82
- package/src/shapebuild.js +281 -0
- package/src/shapelook.js +91 -0
- package/src/shapemenu.js +64 -0
- package/src/shaperesult.js +104 -0
- package/src/shaperows.js +263 -0
- package/src/shapewords.js +140 -0
- package/src/sheetbuild.js +41 -29
- package/src/sheetclaims.js +49 -1
- package/src/sheetfind.js +8 -0
- package/src/sheetlook.js +11 -1
- package/src/sheetrows.js +10 -64
- package/src/ticketrows.js +1 -1
- package/src/try-checks.js +39 -6
- package/src/types.js +1 -0
- package/src/whole-job.js +108 -16
- package/types/action-stop.d.ts +1 -1
- package/types/auditchecks.d.ts +13 -2
- package/types/authoring.d.ts +24 -4
- package/types/blockasks.d.ts +6 -10
- package/types/blockassemble.d.ts +13 -13
- package/types/blockdraft.d.ts +3 -2
- package/types/blockpick.d.ts +4 -0
- package/types/cardlist.d.ts +18 -2
- package/types/checkblock.d.ts +278 -28
- package/types/checked.d.ts +15 -6
- package/types/checklook.d.ts +36 -0
- package/types/checkrows.d.ts +119 -0
- package/types/citedcheck.d.ts +4 -2
- package/types/closers.d.ts +10 -1
- package/types/drafter.d.ts +8 -4
- package/types/globprefix.d.ts +5 -0
- package/types/model-step.d.ts +43 -2
- package/types/pageask.d.ts +5 -3
- package/types/pagedropwords.d.ts +0 -1
- package/types/pagedry.d.ts +27 -0
- package/types/pagefetch.d.ts +3 -2
- package/types/pagerules.d.ts +4 -0
- package/types/panel/result.d.ts +19 -2
- package/types/pickrecord.d.ts +10 -0
- package/types/ratelimit.d.ts +59 -0
- package/types/report.d.ts +46 -0
- package/types/rowresults.d.ts +28 -0
- package/types/rubricstep.d.ts +21 -0
- package/types/runner.d.ts +3 -1
- package/types/send.d.ts +13 -12
- package/types/shapebuild.d.ts +97 -0
- package/types/shapelook.d.ts +76 -0
- package/types/shapemenu.d.ts +40 -0
- package/types/shaperesult.d.ts +40 -0
- package/types/shaperows.d.ts +102 -0
- package/types/shapewords.d.ts +43 -0
- package/types/sheetbuild.d.ts +31 -13
- package/types/sheetclaims.d.ts +16 -0
- package/types/sheetfind.d.ts +1 -0
- package/types/sheetrows.d.ts +5 -36
- package/types/ticketrows.d.ts +1 -1
- package/types/try-checks.d.ts +2 -1
- package/types/types.d.ts +4 -0
- package/types/whole-job.d.ts +69 -3
package/src/citedwords.js
CHANGED
|
@@ -73,12 +73,15 @@ export function factWordReds({
|
|
|
73
73
|
}
|
|
74
74
|
if (f.until !== undefined) dropRed('closing label', f.until);
|
|
75
75
|
if (f.until !== undefined && countExact(text, f.until) < 1) red('word-missing', `${who}: ${JSON.stringify(f.until)} is not in the input "${src}". Copy the closing words from the input, or leave them out.`);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
// M19 am5: a several-word phrase fact (anyOf) holds when the page says ANY of its words; the count of results is the words' counts together
|
|
77
|
+
const phraseOf = f.shape === 'phrase' ? (Array.isArray(f.anyOf) ? f.anyOf : typeof f.phrase === 'string' ? [f.phrase] : null) : null;
|
|
78
|
+
if (phraseOf) {
|
|
79
|
+
const shown = Array.isArray(f.anyOf) ? phraseOf.map((/** @type {string} */ x) => JSON.stringify(x)).join(', ') : JSON.stringify(f.phrase);
|
|
80
|
+
const seen = phraseOf.reduce((/** @type {number} */ n, /** @type {string} */ x) => n + countPhrase(text, x), 0);
|
|
81
|
+
if (seen < 1) red('word-missing', `${who}: ${shown} is not in the input "${src}". Copy the words the input really uses, or remove the check.`);
|
|
79
82
|
else if (Number.isInteger(part.count?.min) && seen < part.count.min) {
|
|
80
83
|
const n = part.count.min;
|
|
81
|
-
red('phrase-rare', `${who}: the words ${
|
|
84
|
+
red('phrase-rare', `${who}: the words ${shown} are in the input "${src}" only ${seen} time${seen === 1 ? '' : 's'}, but this line asks for ${n} results - each result's own quote must say them. Pick words every result says, or drop this check.`);
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
for (const u of asList(f.unit)) dropRed('unit', u);
|
package/src/closers.js
CHANGED
|
@@ -47,6 +47,8 @@ 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';
|
|
50
|
+
import { shapeItemCheck, SHAPE_FIELD } from './shaperows.js';
|
|
51
|
+
import { plainStepGap } from './rubricstep.js';
|
|
50
52
|
|
|
51
53
|
/** @typedef {import('./types.js').CloseVerdict} CloseVerdict */
|
|
52
54
|
|
|
@@ -87,6 +89,46 @@ export async function closeCited(part, artifact, source) {
|
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
|
|
92
|
+
/**
|
|
93
|
+
* M19 S5: the list-of-items check of a line's close (`close.itemShape`, the signed shape part {fields, minItems?, maxItems?}; never `close.shape`, which stays the text shape of M10): ONE bareguard `itemShape` check over the
|
|
94
|
+
* answer's `results`. On a facts+shape line (`close.cited` beside it) the check is closed and also lists `quote` and `values`, and the item count stays with the fact part (src/shaperows.js `shapeItemCheck`), so a count fault is
|
|
95
|
+
* told once. A red names the item and the field in the tag's words (src/shapewords.js). Third outcomes, never green: an answer that is not an object (`unparseable`), a shape bareguard cannot build or a check that stopped (`crash`).
|
|
96
|
+
* `shapeGaps` carries bareguard's own gaps (names, counts and bounds, never a value) for the views that mark an item or a field.
|
|
97
|
+
* @param {any} step @param {unknown} artifact @returns {Promise<CloseVerdict>}
|
|
98
|
+
*/
|
|
99
|
+
export async function closeItemShape(step, artifact) {
|
|
100
|
+
try {
|
|
101
|
+
if (!artifact || typeof artifact !== 'object' || Array.isArray(artifact)) {
|
|
102
|
+
return /** @type {CloseVerdict} */ ({ verdict: 'unparseable', red: 'itemShape artifact must be an object shaped {results: [...]}' });
|
|
103
|
+
}
|
|
104
|
+
const fact = step?.close?.class === 'green' && step.close.cited ? step.close.cited : null;
|
|
105
|
+
const rubric = createRubric({ schema: 1, goal: 'shape', inputs: [], checkpoints: { close: { gating: true, checks: [shapeItemCheck(step.close.itemShape, 'shape', fact)] } } });
|
|
106
|
+
const res = await checkStep(rubric, 'close', Object.hasOwn(artifact, SHAPE_FIELD) ? { [SHAPE_FIELD]: /** @type {any} */ (artifact)[SHAPE_FIELD] } : {});
|
|
107
|
+
if (res.verdict === 'stopped') {
|
|
108
|
+
const fault = /** @type {NonNullable<typeof res.fault>} */ (res.fault);
|
|
109
|
+
return { verdict: 'crash', red: `itemShape close crashed: the ${fault.id} check stopped (${fault.kind}${fault.detail ? `: ${fault.detail}` : ''})` };
|
|
110
|
+
}
|
|
111
|
+
if (res.verdict === 'red') {
|
|
112
|
+
// an answer with no `results` at all reads to bareguard as an empty artifact (`happened`): it is the tag's whole-field gap `missing`
|
|
113
|
+
const gaps = res.gaps.map((/** @type {any} */ g) => (g.check === 'happened' ? { ...g, check: 'itemShape', kind: 'missing', field: SHAPE_FIELD } : g));
|
|
114
|
+
const reds = gaps.map((/** @type {any} */ g) => plainStepGap(step.fromLine, 'empty', g)).flatMap((/** @type {string} */ t) => t.split('\n'));
|
|
115
|
+
return { verdict: 'red', red: reds.join('\n'), reds, shapeGaps: gaps };
|
|
116
|
+
}
|
|
117
|
+
return { verdict: 'green', red: null };
|
|
118
|
+
} catch (err) {
|
|
119
|
+
return { verdict: 'crash', red: `itemShape close crashed: ${err.message}` };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** the items check beside the facts line's own verdict: red if either is red (both told, the fact half first); a third outcome of either is never turned into green, the fact half's winning when it has one @param {any} base @param {any} sh @returns {CloseVerdict} */
|
|
124
|
+
function withItemShape(base, sh) {
|
|
125
|
+
if (base.verdict === 'crash' || base.verdict === 'unparseable') return base;
|
|
126
|
+
if (sh.verdict === 'crash' || sh.verdict === 'unparseable') return { ...sh, ...(base.cited ? { cited: base.cited } : {}) };
|
|
127
|
+
if (sh.verdict === 'green') return base;
|
|
128
|
+
const reds = [...(base.verdict === 'red' ? String(base.red).split('\n') : []), ...sh.reds];
|
|
129
|
+
return { ...base, verdict: 'red', red: reds.join('\n'), reds, shapeGaps: sh.shapeGaps };
|
|
130
|
+
}
|
|
131
|
+
|
|
90
132
|
/**
|
|
91
133
|
* M4e amendment 18: the soft checks run on bareguard 0.21.0. `softgreenSpec(shape)` is the ONE place a declared shape
|
|
92
134
|
* becomes a rubric spec (signing and the run both build through `buildSoftgreenRubric`, so a shape that signs is a shape
|
|
@@ -271,7 +313,7 @@ export async function closeSoftgreen(artifact, shape) {
|
|
|
271
313
|
/**
|
|
272
314
|
* The one dispatcher — `close by declared class` (M2 scope item 4).
|
|
273
315
|
*
|
|
274
|
-
* @param {{ close?: { class?: string, shape?: Record<string, any>, picked?: any[], cited?: any, columns?: {source: string, column: string}[], sheet?: any[], numbersFrom?: number[] } }} step
|
|
316
|
+
* @param {{ close?: { class?: string, shape?: Record<string, any>, picked?: any[], cited?: any, itemShape?: any, columns?: {source: string, column: string}[], sheet?: any[], numbersFrom?: number[] } }} step
|
|
275
317
|
* @param {unknown} artifact
|
|
276
318
|
* @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
319
|
* `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
|
|
@@ -348,7 +390,12 @@ async function closeFactAndPicks(step, artifact, ctx) {
|
|
|
348
390
|
/** @param {any} step @param {unknown} artifact @param {{ reads: Record<string, any>, businessDate: string, source?: any, sheet?: any }} ctx @returns {Promise<CloseVerdict>} */
|
|
349
391
|
async function closeOne(step, artifact, ctx) {
|
|
350
392
|
const cls = step?.close?.class;
|
|
351
|
-
if (cls === 'green' && step?.close?.cited)
|
|
393
|
+
if (cls === 'green' && step?.close?.cited) {
|
|
394
|
+
const base = await closeCited(step.close.cited, artifact, ctx.source);
|
|
395
|
+
return step.close.itemShape ? withItemShape(base, await closeItemShape(step, artifact)) : base;
|
|
396
|
+
}
|
|
397
|
+
// M19 S5, O1: a list of items and no quote reads `results` only (class green: option (ii); class softgreen: option (i)); which class code signs for it is `SHAPE_ONLY_CLASS`, src/blockassemble.js
|
|
398
|
+
if ((cls === 'green' || cls === 'softgreen') && step?.close?.itemShape && !step.close.cited && !Array.isArray(step.close.sheet)) return await closeItemShape(step, artifact);
|
|
352
399
|
if (cls === 'green' && Array.isArray(step?.close?.sheet)) return await closeSheet(step.close.sheet, artifact, ctx.sheet);
|
|
353
400
|
if (cls === 'green') return { verdict: 'crash', red: 'closeByClass: a green step with no close.sheet or close.cited is the retired cell cite' };
|
|
354
401
|
if (cls === 'softgreen') return await closeSoftgreen(artifact, step?.close?.shape ?? {});
|
package/src/declaration.js
CHANGED
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
import { WATCHABLE } from './ticket-shape.js';
|
|
40
40
|
import { buildSoftgreenRubric, isCellsPath } from './closers.js';
|
|
41
41
|
import { factPartReds } from './citedcheck.js';
|
|
42
|
+
import { shapeShapeReds } from './shaperows.js';
|
|
42
43
|
import { numberRuleReds, countReds, citedWordReds } from './citedwords.js';
|
|
43
44
|
import { SHEET_RULES, MAX_SHEET_CHECKS, sheetCheckColumns, sheetCheckReds, sheetCheckWordReds, sheetNoClaimReds, sheetCoversReds } from './sheetchecks.js';
|
|
44
45
|
import { lineRules } from './pagebits.js';
|
|
@@ -85,6 +86,7 @@ export const DECLARATION_FIELDS = Object.freeze([
|
|
|
85
86
|
'sheet',
|
|
86
87
|
'picked',
|
|
87
88
|
'numbersFrom',
|
|
89
|
+
'itemShape',
|
|
88
90
|
]);
|
|
89
91
|
|
|
90
92
|
const VALID_CLASSES = Object.freeze(['green', 'softgreen', 'hitl']);
|
|
@@ -97,7 +99,7 @@ const ARBITER_KEYS = Object.freeze(['cap', 'ask', 'ttl', 'send', 'source', 'trig
|
|
|
97
99
|
|
|
98
100
|
const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts', 'mcp', 'flowType', 'ticketFilter', 'ticketWatch', 'pickedLines', 'checkList']);
|
|
99
101
|
const STEP_ALLOWED = Object.freeze(['goal', 'primitives', 'reads', 'emits', 'fromLine', 'close', 'picks', 'mcpTools']);
|
|
100
|
-
const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet', 'picked', 'numbersFrom']);
|
|
102
|
+
const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet', 'picked', 'numbersFrom', 'itemShape']);
|
|
101
103
|
|
|
102
104
|
/** M13 piece 4 (signed item 4): the job's flow type, set by code from the job card, signed with the job. */
|
|
103
105
|
export const FLOW_TYPES = Object.freeze(['plain', 'mcp', 'tickets']);
|
|
@@ -573,12 +575,13 @@ function checkPickedLines(declaration, reds) {
|
|
|
573
575
|
/**
|
|
574
576
|
* M10 am22: `close.picked` is the checks the person picked for a fact line, kept beside its fact check and run on the answer's `text`. Code sets it (src/checkpick.js
|
|
575
577
|
* assembleFromBlock); here it must be a green step's, a list of bareguard text rules that builds into a check.
|
|
578
|
+
* M19 am10: a green step with item fields (`close.itemShape`) and no quote keeps its picks the same way (the step is checked on its `results` and on each pick over `text`).
|
|
576
579
|
* It is allowed ONLY on a line the signed plan records in `pickedLines` (written by code from the person's picks); a count on any other fact line is refused.
|
|
577
580
|
* @param {any} step @param {string} label @param {string} effectiveClass @param {string[]} reds @param {Record<string, any>} declaration
|
|
578
581
|
*/
|
|
579
582
|
function checkPickedKey(step, label, effectiveClass, reds, declaration) {
|
|
580
583
|
const at = `declaration: ${label}.close.picked`;
|
|
581
|
-
if (step.close.class !== 'green' || effectiveClass !== 'green' || !(isPlainObject(step.close.cited) || Array.isArray(step.close.sheet))) {
|
|
584
|
+
if (step.close.class !== 'green' || effectiveClass !== 'green' || !(isPlainObject(step.close.cited) || Array.isArray(step.close.sheet) || isPlainObject(step.close.itemShape))) {
|
|
582
585
|
reds.push(`${at} is for a step that checks facts (quotes or a sheet) only; this step's check is "${step.close.class ?? effectiveClass}"`);
|
|
583
586
|
return;
|
|
584
587
|
}
|
|
@@ -590,6 +593,24 @@ function checkPickedKey(step, label, effectiveClass, reds, declaration) {
|
|
|
590
593
|
try { buildSoftgreenRubric({ picked: step.close.picked }); } catch (err) { reds.push(`${at} cannot be built into a check - ${String(err.message).replace(/^invalid rubric: /, '')}`); }
|
|
591
594
|
}
|
|
592
595
|
|
|
596
|
+
/**
|
|
597
|
+
* M19 S5: `close.itemShape` is the signed list-of-items check of a line (a shape part `{fields, minItems?, maxItems?}`, src/shaperows.js), one bareguard `itemShape` check over the answer's `results`; never `close.shape`, which stays the text
|
|
598
|
+
* shape of M10 (amendment E). Code sets it (src/blockassemble.js). Beside `close.cited` (a green step) it is a facts+shape line; its fields are named legally and once, its kinds are on the menu and bareguard itself builds the check.
|
|
599
|
+
* @param {any} step @param {string} label @param {string} effectiveClass @param {string[]} reds
|
|
600
|
+
*/
|
|
601
|
+
function checkItemShapeKey(step, label, effectiveClass, reds) {
|
|
602
|
+
const at = `declaration: ${label}.close.itemShape`;
|
|
603
|
+
const part = step.close.itemShape;
|
|
604
|
+
if (!isPlainObject(part)) { reds.push(`${at} must be an object {fields, minItems, maxItems}`); return; }
|
|
605
|
+
for (const k of Object.keys(part)) if (!['fields', 'minItems', 'maxItems'].includes(k)) reds.push(`${at}: "${k}" is not a field of a list-of-items check (fields, minItems, maxItems)`);
|
|
606
|
+
if (step.close.class !== effectiveClass) reds.push(`${at}: this step's check is "${step.close.class ?? effectiveClass}", which is not the class its line earns`);
|
|
607
|
+
if (step.close.class === 'hitl') reds.push(`${at} is for a step whose answer is checked; this step's check is "hitl"`);
|
|
608
|
+
const fact = isPlainObject(step.close.cited) ? step.close.cited : null;
|
|
609
|
+
if (fact === null && step.close.class === 'softgreen' && step.close.shape !== undefined) reds.push(`${at}: a list-of-items line whose check reads its reply cannot also carry a text check (close.shape); its answer has no text`);
|
|
610
|
+
if (fact === null && Array.isArray(step.close.sheet)) reds.push(`${at}: a line is a list-of-items line or a sheet line, not both`);
|
|
611
|
+
shapeShapeReds(part, at, (_c, path, d) => reds.push(`${path}: ${d}`), fact);
|
|
612
|
+
}
|
|
613
|
+
|
|
593
614
|
/**
|
|
594
615
|
* 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.
|
|
595
616
|
* 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.
|
|
@@ -1049,6 +1070,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1049
1070
|
}
|
|
1050
1071
|
if (step.close.numbersFrom !== undefined) checkNumbersFromKey(step, label, steps, reds);
|
|
1051
1072
|
if (step.close.cited !== undefined) checkCitedKey(step, label, { sourceRoles, reads, effectiveClass, lines: safeLines, fitJobLine, pageWords }, reds);
|
|
1073
|
+
if (step.close.itemShape !== undefined) checkItemShapeKey(step, label, effectiveClass, reds);
|
|
1052
1074
|
if (step.close.sheet !== undefined) checkSheetKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, fitJobLine, sheetWords }, reds);
|
|
1053
1075
|
if (step.close.columns !== undefined || (fitJobLine === true && sheetWords)) checkColumnsKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, sheetWords }, reds);
|
|
1054
1076
|
}
|
|
@@ -1063,7 +1085,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1063
1085
|
// M4d amendment 8: a step whose check is green (every figure cites a source cell) must read an input with cells; a text
|
|
1064
1086
|
// output of an earlier step has no cells to cite.
|
|
1065
1087
|
// M10 am7: a green step that cites quotes (`close.cited`) reads a web page, which has no cells; its source is checked above.
|
|
1066
|
-
if (fitJobLine === true && effectiveClass === 'green' && reads !== null && !reads.some((r) => cellsRoles.includes(r)) && !isPlainObject(step.close?.cited)) {
|
|
1088
|
+
if (fitJobLine === true && effectiveClass === 'green' && reads !== null && !reads.some((r) => cellsRoles.includes(r)) && !isPlainObject(step.close?.cited) && !isPlainObject(step.close?.itemShape)) {
|
|
1067
1089
|
const n = fromLine;
|
|
1068
1090
|
const reading = reads.length === 0 ? 'it reads nothing' : `it reads only ${reads.join(', ')}`;
|
|
1069
1091
|
const want = cellsRoles.length === 0 ? 'a spreadsheet input, and this job signs none' : cellsRoles.join(' or ');
|
|
@@ -1073,7 +1095,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1073
1095
|
// 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`);
|
|
1074
1096
|
// 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).
|
|
1075
1097
|
if (fitJobLine === true && effectiveClass === 'green' && reads !== null && reads.some((r) => cellsRoles.includes(r))
|
|
1076
|
-
&& !isPlainObject(step.close?.cited) && !Array.isArray(step.close?.sheet)) {
|
|
1098
|
+
&& !isPlainObject(step.close?.cited) && !isPlainObject(step.close?.itemShape) && !Array.isArray(step.close?.sheet)) {
|
|
1077
1099
|
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 ')}.`);
|
|
1078
1100
|
}
|
|
1079
1101
|
|
package/src/drafter.js
CHANGED
|
@@ -33,6 +33,8 @@ import { freezePage } from './runner.js';
|
|
|
33
33
|
import { removeFrozenPages } from './flow.js';
|
|
34
34
|
import { lookAtPage, pageInfoLines } from './pagelook.js';
|
|
35
35
|
import { lookAtSheet, sheetPrompt } from './sheetlook.js';
|
|
36
|
+
import { lookAtShape, SHAPE_SYSTEM, SHAPE_CALL_LABEL } from './shapelook.js';
|
|
37
|
+
import { buildShapes } from './shapebuild.js';
|
|
36
38
|
import { leftRuleLine, dropRows, dropLine } from './pagedropwords.js';
|
|
37
39
|
import {
|
|
38
40
|
offerRules, rowsFromAnswer, retentionOf, SUGGEST_SYSTEM, SUGGEST_TOOL, SUGGEST_SCHEMA, suggestUserText, codeScope,
|
|
@@ -41,7 +43,8 @@ import {
|
|
|
41
43
|
import { blockJobLines } from './blocklines.js';
|
|
42
44
|
import { setUpBlock, ticketLeaveOut, pickEdits, ledgerEdits, repairedEditsReadable, editRecord, renderRejectBlock, buildFaultWords, isBuildFault } from './blockdraft.js';
|
|
43
45
|
import { assembleFromBlock, closeUnbuiltSheetSteps } from './blockassemble.js';
|
|
44
|
-
import { cardOfBlock } from './cardlist.js';
|
|
46
|
+
import { cardOfBlock, cardOfPlanBlock } from './cardlist.js';
|
|
47
|
+
import { ledgerRowsOf } from './checkrows.js';
|
|
45
48
|
import { questionsOfBlock } from './blockasks.js';
|
|
46
49
|
import { NOTE_KIND, NOTE_TOOL, NOTE_SYSTEM, NOTE_SCHEMA, notePrompt, noteAnswers } from './noteask.js';
|
|
47
50
|
import { ledgerRecord, LEDGER_SYSTEM, LEDGER_SCHEMA, LEDGER_TOOL, ledgerUserText } from './checklist.js';
|
|
@@ -56,8 +59,8 @@ import { isCellsPath } from './closers.js';
|
|
|
56
59
|
import { parseCsv, sheetTable } from './csv.js';
|
|
57
60
|
import { sheetSuggestProp, sheetOfferRules, agreedColumnWords } from './sheetoffer.js';
|
|
58
61
|
import { uncoveredRules, csvRolesOf } from './sheetblock.js';
|
|
59
|
-
import { withSheetRows, withSheetCard
|
|
60
|
-
import { buildSheetChecks } from './sheetbuild.js';
|
|
62
|
+
import { withSheetRows, withSheetCard } from './sheetrows.js';
|
|
63
|
+
import { buildSheetChecks, unbuiltSheetLines } from './sheetbuild.js';
|
|
61
64
|
import { TICKET_FIELDS, ticketRuleField, proposalReds, withTicketRows } from './ticketrows.js';
|
|
62
65
|
import {
|
|
63
66
|
makeProvider, ModelRefusal, sumMeterings, ceilingCostUsd, priceRecord,
|
|
@@ -359,7 +362,7 @@ function isPlainObject(v) { return !!v && typeof v === 'object' && !Array.isArra
|
|
|
359
362
|
* @returns {Promise<{ok:boolean, declaration:object|null, reds:string[], rounds:number, calls:number, spendComplete:boolean,
|
|
360
363
|
* costUsd:number|null, modelReturned:string|null, modelId?:string, price?:object|null, tokens?:object|null, structureRetries:number, revisions:number, stop:string|null, log:object[],
|
|
361
364
|
* questions?:{line:number, question:string}[], proseText?:string, action?:{line:number, by?:'agent'|'you', dropped?:true}|null, droppedQuestions?:object[], notChecked?:string[], thinking?:{asked:string, status:string|null, say:string|null}, inputs?:{role:string, detail:string}[],
|
|
362
|
-
* checkCard?:ReturnType<typeof
|
|
365
|
+
* checkCard?:ReturnType<typeof cardOfPlanBlock>, sheetBuilt?:Awaited<ReturnType<typeof buildSheetChecks>>, notCheckedBy?:Record<string,'you'|'agent'|'default'>, look?:{facts:any[], dropped:any[]}, pageLooks?:{role:string, address:string, sha256:string, bytes:number, frozen:string, attempts:number, mapping:any}[], sheetLooks?:any[]}>}
|
|
363
366
|
* `learnHints` (M8 item 5a): the earlier runs' notes block (src/learnstore.js hintsForRun), appended to the drafter's system prompt; null = nothing.
|
|
364
367
|
* `look` / `pageLooks` (M10 item 3) are there when the job signs a web page: the kept facts (with their `reading`, the input a later ask reads), every drop, and per page its address, sha256 and the AI's map. Each drop is also a line in `notChecked`.
|
|
365
368
|
*/
|
|
@@ -369,7 +372,7 @@ export async function draft({
|
|
|
369
372
|
draftDir = /** @type {string|null} */ (null), fetchPage = undefined, leftRules = /** @type {{line: number, rule: number}[]} */ ([]), columnAnswers = /** @type {{line: number, word: string, column: string}[]} */ ([]), carriedColumns = /** @type {any[]} */ ([]), onColumns = /** @type {(rec: any[]) => void} */ (() => {}),
|
|
370
373
|
checkPicks = /** @type {import('./checkpick.js').Pick[]} */ ([]),
|
|
371
374
|
// M10 am17/am18: the picks of the plan this one follows (src/pickrecord.js entries), and a callback that is handed this draft's record (kept + newly answered) for the one writer
|
|
372
|
-
carriedPicks = /** @type {import('./pickrecord.js').Entry[]} */ ([]), carriedChoices = /** @type {any[]|null} */ (null), carriedSheetDropped = /** @type {any[]} */ ([]), onSheetDropped = /** @type {(rec: any[]) => void} */ (() => {}), onChoices = /** @type {(rec: any[]) => void} */ (() => {}), onPickRecord = /** @type {((r: {picks: import('./pickrecord.js').Entry[], kept: {line: number, rule: number, ruleText: string, check: Record<string, any>|null}[]}) => void)|null} */ (null),
|
|
375
|
+
carriedPicks = /** @type {import('./pickrecord.js').Entry[]} */ ([]), carriedChoices = /** @type {any[]|null} */ (null), carriedSheetDropped = /** @type {any[]} */ ([]), onSheetDropped = /** @type {(rec: any[]) => void} */ (() => {}), carriedShapeDropped = /** @type {any[]} */ ([]), onShapeDropped = /** @type {(rec: any[]) => void} */ (() => {}), onChoices = /** @type {(rec: any[]) => void} */ (() => {}), onPickRecord = /** @type {((r: {picks: import('./pickrecord.js').Entry[], kept: {line: number, rule: number, ruleText: string, check: Record<string, any>|null}[]}) => void)|null} */ (null),
|
|
373
376
|
learnHints = /** @type {{text: string, ids: string[]}|null} */ (null),
|
|
374
377
|
mcpServers = /** @type {string[]|undefined} */ (undefined),
|
|
375
378
|
// M13 piece 4: the job's flow type and its MCP pick (`mcpPickFor`: `{ok, server, tools}`), both set by code from the card; the drafter is told them, never asked for them
|
|
@@ -602,9 +605,9 @@ export async function draft({
|
|
|
602
605
|
const { seenLines, toOriginal } = hideCounts(jobLines, !sheetPath ? new Set(lineNums.filter((n) => !askOrSend.has(n))) : new Set());
|
|
603
606
|
const pageInfo = [];
|
|
604
607
|
/** one map call (a page's or a sheet's): its hold, its metering and its book are the drafting round's own (the `kind` names it in the round log) */
|
|
605
|
-
const makeCallModel = (kind) => async (content, attempt) => {
|
|
608
|
+
const makeCallModel = (kind, system = MAP_SYSTEM) => async (content, attempt) => {
|
|
606
609
|
const spentSoFar = meterings.reduce((sum, ev) => sum + (ev.costUsd ?? roundCeiling), 0);
|
|
607
|
-
if (spentSoFar + ceilingCostUsd(rates, content.length +
|
|
610
|
+
if (spentSoFar + ceilingCostUsd(rates, content.length + system.length) > budgetUsd) { mapCut = 'budget'; return { error: 'the draft budget is spent', budget: true }; }
|
|
608
611
|
const roundEvents = [];
|
|
609
612
|
const mapLoop = new Loop({ provider, rates, onLlmResult: async (ev) => { roundEvents.push(ev); meterings.push(ev); } });
|
|
610
613
|
calls += 1;
|
|
@@ -612,7 +615,7 @@ export async function draft({
|
|
|
612
615
|
let res;
|
|
613
616
|
let threw = null;
|
|
614
617
|
try {
|
|
615
|
-
res = await mapLoop.run([{ role: 'system', content:
|
|
618
|
+
res = await mapLoop.run([{ role: 'system', content: system }, { role: 'user', content }], [], { maxTokens: DRAFT_MAX_TOKENS, thinkingMode: attempt === 1 ? draftThinking : 'on' });
|
|
616
619
|
} catch (err) {
|
|
617
620
|
threw = err;
|
|
618
621
|
if (roundEvents.length === 0) unmetered += 1;
|
|
@@ -621,9 +624,10 @@ export async function draft({
|
|
|
621
624
|
const entry = { round: log.length + 1, kind };
|
|
622
625
|
if (res?.thinkingApplied !== undefined) entry.thinkingApplied = res.thinkingApplied;
|
|
623
626
|
if (res?.thinkingStatus !== undefined) entry.thinkingStatus = res.thinkingStatus;
|
|
624
|
-
if (threw) { entry.outcome = `provider-red: ${threw.message}`; log.push(entry); mapCut = 'provider-red'; return { error: threw.message }; }
|
|
627
|
+
if (threw) { entry.outcome = `provider-red: ${threw.message}`; log.push(entry); mapCut = 'provider-red'; return { error: threw.message, threw }; }
|
|
625
628
|
const cutOff = res?.stopReason === 'max_tokens';
|
|
626
629
|
entry.outcome = cutOff ? 'truncated' : 'answered';
|
|
630
|
+
if (kind === SHAPE_CALL_LABEL && typeof res?.text === 'string' && res.text !== '') entry.rawText = res.text;
|
|
627
631
|
log.push(entry);
|
|
628
632
|
if (res?.error && !cutOff) return { error: String(res.error) };
|
|
629
633
|
return { text: res?.text ?? '', cutOff };
|
|
@@ -728,6 +732,12 @@ export async function draft({
|
|
|
728
732
|
const blockPlan = blockJobLines(proseText, undefined, [...new Set([...sheetFacts.filter((f) => f.forRule !== undefined), ...sheetAsks, ...sheetLooks.flatMap((l) => l.dropped)].map((x) => x.line)), ...csvRuleLines]);
|
|
729
733
|
if (blockPlan && !blockPlan.ok) return fail(blockPlan.reds.map((r) => `signed-text: ${r}`));
|
|
730
734
|
const blockLineNums = new Set(blockPlan ? blockPlan.jobLines.map((l) => l.n) : []);
|
|
735
|
+
// M19 S3: the sheet lines (a CSV input and a line with `~` rules that the list's own rows do not take) are the check block's too: it holds their rules and their sheet checks (src/checkblock.js `setSheet`), the AI names a sheet line by its job number
|
|
736
|
+
const sheetTables = Object.keys(facts.sheets ?? {}).length ? Object.fromEntries(Object.entries(facts.sheets).map(([role, t]) => [role, sheetTable(parseCsv(t))])) : undefined;
|
|
737
|
+
const sheetRoleList = sheetTables ? Object.keys(sheetTables) : [];
|
|
738
|
+
const sendLines = new Set(arbiter.sends.map((x) => x.line));
|
|
739
|
+
const sheetLineNums = sheetRoleList.length > 0 ? jobLines.filter((l) => !askLines.has(l.n) && !sendLines.has(l.n) && !blockLineNums.has(l.n) && lineRules(l).length > 0).map((l) => l.n) : [];
|
|
740
|
+
const sheetTurn = sheetLineNums.length > 0;
|
|
731
741
|
// M17 am4 (A3, B5): the list is the one place a shape rule is asked and picked; a line the list is not given (a sheet line) has no pick path of its own
|
|
732
742
|
const allShape = shapeEverywhere.filter((r) => blockLineNums.has(r.line));
|
|
733
743
|
// M10 am17/am18: a guardrail whose pick is kept from the last draft skips the suggestion call and the asks; only the rest is suggested and asked. The model never sees a pick.
|
|
@@ -740,10 +750,13 @@ export async function draft({
|
|
|
740
750
|
let block = null;
|
|
741
751
|
if (blockPlan?.ok) {
|
|
742
752
|
const inBlock = (/** @type {{line: number}} */ x) => blockLineNums.has(x.line);
|
|
753
|
+
const sheetBlockLines = sheetTurn ? (() => { const all = blockJobLines(proseText); return all.ok ? all.jobLines.filter((l) => sheetLineNums.includes(l.n)) : []; })() : [];
|
|
754
|
+
// the page look is about the page inputs: its facts and drops on a sheet line are not rows of the block
|
|
755
|
+
const notSheet = (/** @type {{line: number}} */ x) => !sheetLineNums.includes(x.line);
|
|
743
756
|
block = setUpBlock({
|
|
744
|
-
texts: { ...(facts.docs ?? {}), ...Object.fromEntries(Object.entries(pages).map(([role, pg]) => [role, pg.text])) }, jobLines: blockPlan.jobLines, look,
|
|
757
|
+
texts: { ...(facts.docs ?? {}), ...Object.fromEntries(Object.entries(pages).map(([role, pg]) => [role, pg.text])) }, jobLines: [...blockPlan.jobLines, ...sheetBlockLines].sort((a, b) => a.n - b.n), look: { facts: look.facts.filter(notSheet), dropped: look.dropped.filter(notSheet) },
|
|
745
758
|
kept: { picks: carried.picks.filter(inBlock), left: carried.left.filter(inBlock), askRules: carried.askRules.filter(inBlock) },
|
|
746
|
-
fresh: { picks: checkPicks.filter(inBlock), left: leftRules.filter(inBlock) }, asks: offerQuestions, countScope: (t) => codeScope(arbiter.sources, t) === 'in', leaveOut: ticketLeaveOut(flowType, blockPlan.jobLines),
|
|
759
|
+
fresh: { picks: checkPicks.filter(inBlock), left: leftRules.filter(inBlock) }, asks: offerQuestions, countScope: (t) => codeScope(arbiter.sources, t) === 'in', leaveOut: ticketLeaveOut(flowType, blockPlan.jobLines), sheetLines: sheetLineNums,
|
|
747
760
|
});
|
|
748
761
|
}
|
|
749
762
|
if (askRules.length && offerQuestions) {
|
|
@@ -766,16 +779,16 @@ export async function draft({
|
|
|
766
779
|
// a Revise keeps the last draft's Drop/Add choices (the suggestions exist now); code still judges every one when the list is reconciled
|
|
767
780
|
if (block && Array.isArray(carriedChoices)) { block.carryChoices(carriedChoices); onChoices(block.choicesRecord()); block.reconcile(); }
|
|
768
781
|
/** the questions of the block, merged below with the sheet's and the look's own, under one cap (M16 S3) */
|
|
769
|
-
const blockAsks = block && offerQuestions ? questionsOfBlock(block
|
|
770
|
-
if (block) pageExtras.checkRows = ledgerRecord(/** @type {any} */ (block.rows));
|
|
782
|
+
const blockAsks = block && offerQuestions ? questionsOfBlock(block) : [];
|
|
783
|
+
if (block) pageExtras.checkRows = ledgerRecord(/** @type {any} */ (block.rows.filter((r) => !block.isSheetLine(r.line))));
|
|
771
784
|
// M10 piece 3 (item 4, am1, am2): CODE decides the early asks from the look, after the one map call and BEFORE any drafting round. A signed ask line's own
|
|
772
785
|
// guardrail is a human stop, not a page check, so it is not asked. More than MAX_LOOK_ASKS is a job to rewrite: nothing is asked, nothing more is spent.
|
|
773
786
|
// The redraft after the answers (offerQuestions false) never asks. A sheet's offers are reading asks: they come first with the page's, in line order.
|
|
774
787
|
if ((sheetAsks.length || blockAsks.length || actionAsk !== null) && offerQuestions) {
|
|
775
788
|
// M17 am4 (A1): a question comes from the list (questionsOfBlock) or is the sheet's column offer (M17 am1 1(a)); no question is asked outside the list
|
|
776
|
-
const lookAsks = [...[...sheetAsks, ...blockAsks.filter((a) => a.ask === 'reading')].sort((a, b) => a.line - b.line)
|
|
789
|
+
const lookAsks = [...[...sheetAsks, ...blockAsks.filter((a) => a.ask === 'reading')].sort((a, b) => a.line - b.line)];
|
|
777
790
|
// am16 (3): a shape guardrail's ask follows, in line order. (5): a proposal is not an ask under am1; only a `can't check` ask counts toward the cap (the 4th stops drafting at $0).
|
|
778
|
-
const blockShape = blockAsks.filter((a) => a.ask === '
|
|
791
|
+
const blockShape = blockAsks.filter((a) => a.ask === 'check');
|
|
779
792
|
const asks = [...lookAsks, ...blockShape, ...(actionAsk === null ? [] : [actionAsk])];
|
|
780
793
|
if (asks.length > 0) {
|
|
781
794
|
const m = sumMeterings(meterings);
|
|
@@ -786,7 +799,7 @@ export async function draft({
|
|
|
786
799
|
return withAction({
|
|
787
800
|
ok: false, declaration: null, reds: tooMany ? [`${tooManyAsksText(counted)} Spent so far: ${spent}.`] : [], rounds: m.rounds, calls, spendComplete: unmetered === 0 && m.costUsd !== null, costUsd: m.costUsd, modelReturned: m.model, modelId, price: priceRecord(prices, rates), tokens: m.tokens, structureRetries: 0, revisions: 0, stop: tooMany ? 'look-asks-too-many' : 'look-asks', log, thinking: thinkingOf(), inputs: facts.list,
|
|
788
801
|
questions: tooMany ? [] : asks.map((a) => ({
|
|
789
|
-
line: a.line, question: a.question, source: a.source, ask: a.ask, ruleNo: 'rule' in a ? a.rule : undefined, ruleText: a.ruleText, proposal: a.reading ?? null, ...('check' in a && a.check ? { check: a.check } : {}),
|
|
802
|
+
line: a.line, question: a.question, source: a.source, ask: a.ask, ruleNo: 'rule' in a ? a.rule : undefined, ruleText: a.ruleText, proposal: a.reading ?? null, ...('check' in a && a.check ? { check: a.check } : {}), ...('columns' in a && Array.isArray(a.columns) ? { columns: a.columns, readings: /** @type {any} */ (a).readings } : {}),
|
|
790
803
|
})),
|
|
791
804
|
droppedQuestions: [], notChecked: pageNotChecked, ...pageExtras,
|
|
792
805
|
});
|
|
@@ -794,20 +807,35 @@ export async function draft({
|
|
|
794
807
|
}
|
|
795
808
|
// the record this draft hands on: what it kept plus what the person just answered (numbered on this card)
|
|
796
809
|
onPickRecord?.({ picks: [...carried.kept.map((k) => k.entry), ...entriesFromAnswers(lines, allShape, checkPicks, leftRules)], kept: keptView });
|
|
810
|
+
// borrowed-from: bareloop src/authorjob.js@v0.61.0 (fc56e1f3) (:788-813, the shape look after the page look, the sheet look, the asks and the person's answers)
|
|
811
|
+
// SHAPE JOBS: the shape look is asked ONLY about the `~` rules still Not checked once every truth check, the answers and the asks are settled (`shapeCandidates`, code decides). No candidate = no call, and the draft is byte-identical.
|
|
812
|
+
// The AI only suggests; code builds or refuses each field (src/shapebuild.js). A look that fails, is unreadable or is capped never stops the draft: its spend stays booked, one draft-log line says so, and it goes on without a shape.
|
|
813
|
+
if (block && blockPlan?.ok) {
|
|
814
|
+
const left = block.shapeCandidates();
|
|
815
|
+
if (left.length > 0) {
|
|
816
|
+
const lineNums = [...new Set(left.map((x) => x.line))].sort((a, b) => a - b);
|
|
817
|
+
const got = await lookAtShape({
|
|
818
|
+
texts: block.texts, jobLines: blockPlan.jobLines, lineNums, left: lineNums.map((n) => ({ line: n, rules: left.filter((x) => x.line === n).map((x) => x.rule) })), ceilingUsd: arbiter.capUsd,
|
|
819
|
+
callModel: makeCallModel(SHAPE_CALL_LABEL, SHAPE_SYSTEM),
|
|
820
|
+
});
|
|
821
|
+
if (!got.ok) log.push({ round: log.length + 1, kind: 'shape-skipped', reason: got.reason, line: `the shape look did not complete: ${got.reason}; going on without a shape` });
|
|
822
|
+
else if (got.shapes.length > 0) {
|
|
823
|
+
block.setShape(buildShapes({ lines: blockPlan.jobLines.filter((l) => lineRules(l).length > 0 && !block.isSheetLine(l.n)), labels: block.labels, suggestions: got.shapes }));
|
|
824
|
+
block.carryShapeDropped(carriedShapeDropped);
|
|
825
|
+
}
|
|
826
|
+
block.reconcile();
|
|
827
|
+
}
|
|
828
|
+
}
|
|
797
829
|
// M16 S2 + S4: the AI's two helpers send edits to the list, then the row-edit turn; code judges every edit alone (src/checkblock.js). The declaration path below runs as before (S5 assembles from the rows).
|
|
798
830
|
// a line with nothing to check (no `~` rule of the person's, no input text for a `!` row to be built from) has no list to edit: no turn is paid for it (M16 item 2, "every job line with checks")
|
|
799
|
-
// M10b piece 3: the drafting copy's table of each CSV input - the header the AI may pick from in its suggestions, the table bareguard's build and sign-time tests run over
|
|
800
|
-
const sheetTables = Object.keys(facts.sheets ?? {}).length ? Object.fromEntries(Object.entries(facts.sheets).map(([role, t]) => [role, sheetTable(parseCsv(t))])) : undefined;
|
|
831
|
+
// M10b piece 3: the drafting copy's table of each CSV input (`sheetTables`, above) - the header the AI may pick from in its suggestions, the table bareguard's build and sign-time tests run over
|
|
801
832
|
/** M17 am2: the sheet checks the AI suggested on the row-edit reply (typed, each with its job line); code builds or refuses each (src/sheetbuild.js) @type {any[]} */
|
|
802
833
|
let sheetSuggested = [];
|
|
834
|
+
/** @type {Awaited<ReturnType<typeof buildSheetChecks>>|null} */
|
|
835
|
+
let sheetBuilt = null;
|
|
803
836
|
/** M17 am6: the Tickets filter and watch the AI suggested as an edit of the list: the last legal value of each, and what was refused (code proves each, src/ticketrows.js) @type {{ticketFilter?: any, ticketWatch?: any, refused: Record<string, string>}} */
|
|
804
837
|
const ticketProposal = { refused: {} };
|
|
805
838
|
const ticketRuleOnJob = flowType === 'tickets' && blockPlan?.ok === true && blockPlan.jobLines.some((l) => (l.rules ?? []).some((t) => ticketRuleField(t) !== null));
|
|
806
|
-
const sheetRoleList = sheetTables ? Object.keys(sheetTables) : [];
|
|
807
|
-
// the sheet lines: a line with `~` rules the list's own rows do not take (and no ask or send line); the AI names a sheet line by its job number, and only one of these
|
|
808
|
-
const sendLines = new Set(arbiter.sends.map((x) => x.line));
|
|
809
|
-
const sheetLineNums = sheetRoleList.length > 0 ? jobLines.filter((l) => !askLines.has(l.n) && !sendLines.has(l.n) && !blockLineNums.has(l.n) && lineRules(l).length > 0).map((l) => l.n) : [];
|
|
810
|
-
const sheetTurn = sheetLineNums.length > 0;
|
|
811
839
|
if (block && blockPlan?.ok && (blockPlan.jobLines.length > 0 || sheetTurn) && (Object.keys(block.texts).length > 0 || block.rows.some((r) => r.kind === 'rule') || ticketRuleOnJob || sheetTurn)) {
|
|
812
840
|
// M17 am2: with a CSV input the turn also shows the sheet lines and the sheets; the sheet checks come back as typed suggestions
|
|
813
841
|
const texts = { ...block.texts, ...(facts.sheets ?? {}) };
|
|
@@ -837,7 +865,18 @@ export async function draft({
|
|
|
837
865
|
if (refused.length === 0 || rev >= MAX_REVISIONS) break;
|
|
838
866
|
turn = [...turn, { role: 'assistant', content: JSON.stringify(got.args) }, { role: 'user', content: `${renderRejectBlock(refused.map((e) => `edit ${String(e?.op)}: ${String(e.refusedBecause)}`))}\n\n${ROW_EDIT_REVISE}` }];
|
|
839
867
|
}
|
|
840
|
-
|
|
868
|
+
// M19 S3 (bareloop's order): the sheet checks code built from the reply's suggestions become the block's own rows after the AI's edits; a Revise keeps a Drop of the very same check
|
|
869
|
+
if (sheetTurn && sheetTables) {
|
|
870
|
+
sheetBuilt = await buildSheetChecks({ lines: lines.filter((l) => sheetLineNums.includes(l.n)), tables: sheetTables, suggestions: sheetSuggested });
|
|
871
|
+
block.setSheet(sheetBuilt);
|
|
872
|
+
block.carrySheetDropped(carriedSheetDropped);
|
|
873
|
+
onSheetDropped(block.sheetDroppedRecord());
|
|
874
|
+
pageExtras.sheetBuilt = sheetBuilt;
|
|
875
|
+
}
|
|
876
|
+
// shape jobs: a Revise keeps a Drop of the very same shape field (the block's own record, beside the sheet's)
|
|
877
|
+
if (carriedShapeDropped.length) block.carryShapeDropped(carriedShapeDropped);
|
|
878
|
+
onShapeDropped(block.shapeDroppedRecord());
|
|
879
|
+
pageExtras.checkRows = ledgerRecord(/** @type {any} */ (block.rows.filter((r) => !block.isSheetLine(r.line))));
|
|
841
880
|
}
|
|
842
881
|
// M17 am1 1(e): the note question, ONE forced turn, only when a line of the list is facts-only after the AI's edits (src/noteask.js). The typed answer goes to the block; code decides what it means.
|
|
843
882
|
// The answers ride the turn's log entry (`notes`), the one place the replay (src/planrebuild.js) reads them from, a failed turn included.
|
|
@@ -850,7 +889,7 @@ export async function draft({
|
|
|
850
889
|
const answers = noteAnswers(asked, nq.args, askedLines);
|
|
851
890
|
nq.entry.notes = answers;
|
|
852
891
|
block.setNotes(answers);
|
|
853
|
-
pageExtras.checkRows = ledgerRecord(/** @type {any} */ (block.rows));
|
|
892
|
+
pageExtras.checkRows = ledgerRecord(/** @type {any} */ (block.rows.filter((r) => !block.isSheetLine(r.line))));
|
|
854
893
|
}
|
|
855
894
|
}
|
|
856
895
|
// The page lines go on the drafter's list of inputs: the first line of a page's block replaces the plain line readInputFacts wrote for it.
|
|
@@ -996,7 +1035,7 @@ export async function draft({
|
|
|
996
1035
|
if (Array.isArray(declaration.steps)) {
|
|
997
1036
|
declaration.steps = declaration.steps.map((st) => (isPlainObject(st) ? { ...st, goal: goalForLine(st.fromLine, lines) } : st));
|
|
998
1037
|
}
|
|
999
|
-
// M13 am9 item 4: the last Ask before the
|
|
1038
|
+
// M13 am9 item 4: the last Ask before the action reads every step; code sets it, whatever the model sent
|
|
1000
1039
|
if (Array.isArray(declaration.steps)) declaration.steps = readEveryStep(declaration.steps, arbiter);
|
|
1001
1040
|
// M10 am16 (4): the drafter writes no check. Whatever `close.shape` it sent (the schema offers none) is dropped here; a check reaches the plan only from the list's built rows (assembleFromBlock).
|
|
1002
1041
|
delete declaration.unjudgeable; // M17 am4 (C8): the hidden can't-judge record is gone; a line's Not checked reasons are the list's rows
|
|
@@ -1011,54 +1050,37 @@ export async function draft({
|
|
|
1011
1050
|
}
|
|
1012
1051
|
// M16 S6: the checks of the block's lines are the block's built parts; whatever the AI wrote for them is gone, and the list that proves it is signed with the plan
|
|
1013
1052
|
delete declaration.checkList;
|
|
1053
|
+
// M17 am2 item 2: the AI writes no sheet check: a declaration that carries `close.sheet` is refused (a red naming the field, no check run). The checks are the block's own (M19 S3: `setSheet`, from the row-edit reply's
|
|
1054
|
+
// suggestions, which code refused or built on bareguard, src/sheetbuild.js); the assembly below writes them into the step that reads the sheet
|
|
1055
|
+
let carriedSheet = false;
|
|
1056
|
+
if (sheetTables) {
|
|
1057
|
+
declaration.steps = (Array.isArray(declaration.steps) ? declaration.steps : []).map((/** @type {any} */ st) => {
|
|
1058
|
+
if (!isPlainObject(st) || !isPlainObject(st.close)) return st;
|
|
1059
|
+
const { sheet: carried, ...close } = st.close;
|
|
1060
|
+
if (carried !== undefined) carriedSheet = true;
|
|
1061
|
+
return { ...st, close };
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1014
1064
|
let assembled = null;
|
|
1015
1065
|
if (block && blockPlan?.ok) {
|
|
1016
|
-
assembled = assembleFromBlock({ declaration, block, lines, lineSet: blockLineNums, askLines });
|
|
1066
|
+
assembled = assembleFromBlock({ declaration, block, lines, lineSet: blockLineNums, askLines, sheetRoles: sheetRoleList });
|
|
1017
1067
|
Object.assign(declaration, assembled.declaration);
|
|
1018
1068
|
if (assembled.declaration.pickedLines === undefined) delete declaration.pickedLines;
|
|
1019
1069
|
}
|
|
1020
|
-
// M17 am2: the AI writes no sheet check. What it sent as `close.sheet` is a typed suggestion; code refuses or builds each one on bareguard (src/sheetbuild.js) and writes the checks, with its own ids
|
|
1021
|
-
/** @type {Awaited<ReturnType<typeof buildSheetChecks>>|null} */
|
|
1022
|
-
let sheetBuilt = null;
|
|
1023
|
-
let carriedSheet = false;
|
|
1024
1070
|
/** @type {ReturnType<typeof closeUnbuiltSheetSteps>|null} */
|
|
1025
1071
|
let sheetHitl = null;
|
|
1026
1072
|
if (sheetTables) {
|
|
1027
|
-
//
|
|
1028
|
-
const
|
|
1029
|
-
const
|
|
1030
|
-
declaration.steps = (Array.isArray(declaration.steps) ? declaration.steps : []).map((/** @type {any} */ st) => {
|
|
1031
|
-
if (!isPlainObject(st) || !isPlainObject(st.close)) return st;
|
|
1032
|
-
const { sheet: carried, ...close } = st.close;
|
|
1033
|
-
if (carried !== undefined) carriedSheet = true;
|
|
1034
|
-
const mine = close.class === 'green' && Array.isArray(st.reads) && st.reads.some((/** @type {string} */ r) => roles.includes(r)) && !given.has(st.fromLine) ? sheetSuggested.filter((x) => x.line === st.fromLine).map(({ line: _l, ...x }) => x) : [];
|
|
1035
|
-
if (mine.length) given.add(st.fromLine);
|
|
1036
|
-
return { ...st, close: mine.length ? { ...close, sheet: mine } : close };
|
|
1037
|
-
});
|
|
1038
|
-
const unplaced = sheetSuggested.filter((x) => !given.has(x.line)).map((x) => ({ line: x.line, helper: 'line', why: `line ${String(x.line)} has no green step that reads a sheet` }));
|
|
1039
|
-
sheetBuilt = await buildSheetChecks({ declaration, lines, tables: sheetTables });
|
|
1040
|
-
Object.assign(declaration, { steps: sheetBuilt.declaration.steps });
|
|
1073
|
+
// a suggestion for a line with no green step that reads a sheet has nowhere to go (recorded, as before)
|
|
1074
|
+
const placedLines = new Set((Array.isArray(declaration.steps) ? declaration.steps : []).filter((/** @type {any} */ st) => isPlainObject(st) && isPlainObject(st.close) && st.close.class === 'green' && Array.isArray(st.reads) && st.reads.some((/** @type {string} */ r) => sheetRoleList.includes(r))).map((/** @type {any} */ st) => st.fromLine));
|
|
1075
|
+
const unplaced = sheetSuggested.filter((x) => !placedLines.has(x.line)).map((x) => ({ line: x.line, helper: 'line', why: `line ${String(x.line)} has no green step that reads a sheet` }));
|
|
1041
1076
|
// M17 am5 / P5: a sheet step the builder built no check for is closed here (its class is the assembly's decision), its rules Not checked below
|
|
1042
|
-
const closed = closeUnbuiltSheetSteps(declaration, sheetBuilt
|
|
1077
|
+
const closed = closeUnbuiltSheetSteps(declaration, unbuiltSheetLines({ declaration, lines, roles: sheetRoleList, notChecked: sheetBuilt?.notChecked ?? {} }));
|
|
1043
1078
|
Object.assign(declaration, closed.declaration);
|
|
1044
1079
|
sheetHitl = closed;
|
|
1045
|
-
if (sheetBuilt
|
|
1080
|
+
if ((sheetBuilt?.refused.length ?? 0) > 0 || unplaced.length) entry.sheetRefused = [...unplaced, ...(sheetBuilt?.refused ?? [])];
|
|
1046
1081
|
}
|
|
1047
|
-
// M16 am4 (2): a sheet line's checks are rows on the same list (
|
|
1082
|
+
// M16 am4 (2): a sheet line's checks are rows on the same list (the block holds them, src/checkblock.js; src/sheetrows.js reads them as rows)
|
|
1048
1083
|
let sheetOnList = null;
|
|
1049
|
-
/** @type {any[]} */
|
|
1050
|
-
let sheetDroppedNow = [];
|
|
1051
|
-
if (block) {
|
|
1052
|
-
// hamr 2026-11-14: a Revise keeps a sheet Drop - a new check with the id of a carried dropped one starts dropped again (only an `[agent]` row can be dropped; one that now covers a `~` rule stays)
|
|
1053
|
-
for (const d of carriedSheetDropped) {
|
|
1054
|
-
// M17 am3: code names every check, so the Drop is kept for the very same check (its typed fields), never for an id that may name another one now
|
|
1055
|
-
const key = keyOfSameCheck(declaration, d);
|
|
1056
|
-
if (key === null) continue;
|
|
1057
|
-
const r = sheetChoice({ declaration, lines, csvRoles: csvRolesOf(arbiter), op: 'drop', key, dropped: sheetDroppedNow });
|
|
1058
|
-
if (r.ok) { Object.assign(declaration, { steps: r.declaration.steps }); sheetDroppedNow = r.dropped; }
|
|
1059
|
-
}
|
|
1060
|
-
onSheetDropped(sheetDroppedNow);
|
|
1061
|
-
}
|
|
1062
1084
|
/** @type {ReturnType<typeof withTicketRows>['tickets']|null} */
|
|
1063
1085
|
let ticketOnList = null;
|
|
1064
1086
|
if (block && flowType === 'tickets') { const w = withTicketRows({ declaration, lines }); ticketOnList = w.tickets; if (w.tickets.signed.length) Object.assign(declaration, { checkList: w.declaration.checkList }); }
|
|
@@ -1117,9 +1139,11 @@ export async function draft({
|
|
|
1117
1139
|
if (verdict.ok) {
|
|
1118
1140
|
entry.outcome = 'valid';
|
|
1119
1141
|
log.push(entry);
|
|
1142
|
+
// M19 am8 item 1, am9 item 5: the draft's ledger rows, one per Not checked row, in its own log (no new file); a row's words are the build's name for it
|
|
1143
|
+
if (block) log.push(...ledgerRowsOf(declaration, lines, Object.fromEntries(block.rows.filter((r) => r.kind !== 'rule').map((r) => [r.key, r.name ? [r.name] : r.words ?? []]))));
|
|
1120
1144
|
const m = sumMeterings(meterings);
|
|
1121
1145
|
return withAction({
|
|
1122
|
-
ok: true, declaration, reds: [], rounds: m.rounds, calls, spendComplete: unmetered === 0 && m.costUsd !== null, costUsd: m.costUsd, modelReturned: m.model, modelId, price: priceRecord(prices, rates), tokens: m.tokens, structureRetries, revisions, stop: null, log, thinking: thinkingOf(), inputs: facts.list, ...extras, ...pageExtras, ...(block ? { checkCard: (() => { const c = sheetOnList ? withSheetCard(cardOfBlock(block), sheetOnList
|
|
1146
|
+
ok: true, declaration, reds: [], rounds: m.rounds, calls, spendComplete: unmetered === 0 && m.costUsd !== null, costUsd: m.costUsd, modelReturned: m.model, modelId, price: priceRecord(prices, rates), tokens: m.tokens, structureRetries, revisions, stop: null, log, thinking: thinkingOf(), inputs: facts.list, ...extras, ...pageExtras, ...(block ? { checkCard: (() => { const c = sheetOnList ? withSheetCard(cardOfBlock(block), sheetOnList) : cardOfBlock(block); return cardOfPlanBlock(block, ticketOnList?.card.length ? withSheetCard(c, { card: ticketOnList.card }) : c, { declaration, lines, csvRoles: csvRolesOf(arbiter), log }); })() } : {}),
|
|
1123
1147
|
});
|
|
1124
1148
|
}
|
|
1125
1149
|
lastReds = [...verdict.reds];
|
package/src/factwords.js
CHANGED
|
@@ -91,14 +91,17 @@ export function checkFactWords({ part, text, line, scan = scanLabels(text), kept
|
|
|
91
91
|
}
|
|
92
92
|
if (f.until !== undefined) dropRed('closing label', f.until);
|
|
93
93
|
if (f.until !== undefined && countExact(text, f.until) < 1) red('rubric-fact-word-missing', `${who}: ${JSON.stringify(f.until)} is not in the input "${src}". Copy the closing words from the input, or leave them out.`);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
// M19 am5: a several-word phrase fact (anyOf) holds when the page says ANY of its words; the count of results is the words' counts together
|
|
95
|
+
const phraseOf = f.shape === 'phrase' ? (Array.isArray(f.anyOf) ? f.anyOf : typeof f.phrase === 'string' ? [f.phrase] : null) : null;
|
|
96
|
+
if (phraseOf) {
|
|
97
|
+
const shown = Array.isArray(f.anyOf) ? phraseOf.map((/** @type {string} */ x) => JSON.stringify(x)).join(', ') : JSON.stringify(f.phrase);
|
|
98
|
+
const seen = phraseOf.reduce((/** @type {number} */ n, /** @type {string} */ x) => n + countPhrase(text, x), 0);
|
|
99
|
+
if (seen < 1) red('rubric-fact-word-missing', `${who}: ${shown} is not in the input "${src}". Copy the words the input really uses, or remove the check.`);
|
|
97
100
|
else if (Number.isInteger(part.count?.min) && seen < part.count.min) {
|
|
98
101
|
// M4: the words each result's quote must say must repeat as often as results were asked for; page-header words (counted
|
|
99
102
|
// once or twice) are in no result, so no one-result quote can say them
|
|
100
103
|
const n = part.count.min;
|
|
101
|
-
red('rubric-fact-phrase-rare', `${who}: the words ${
|
|
104
|
+
red('rubric-fact-phrase-rare', `${who}: the words ${shown} are in the input "${src}" only ${seen} time${seen === 1 ? '' : 's'}, but this line asks for ${n} results - each result's own quote must say them. Pick words every result says, or drop this check.`);
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
// a unit (one string, or every one of a list) must be found as whole words; a currency sign (each of a list) must be found as written
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/validate.js@v0.60.0 (globToPrefix only; the rest of that file is bareloop's job validator and is not wanted here)
|
|
2
|
+
// The one canonical spelling of a scope's path prefix. The check block's repo rows (src/checkblock.js `inScope`) read it; fwd has no repo job and never sets the block's `repo` option, so nothing in fwd calls it.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} scope
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function globToPrefix(scope) {
|
|
9
|
+
// One canonical spelling for equivalent paths — leading "./", interior "/./",
|
|
10
|
+
// doubled "//", trailing "/" all collapse — so the legality rule, the fence
|
|
11
|
+
// comparison, and bareguard enforcement agree on what a scope NAMES. Without
|
|
12
|
+
// this, a validateJob-green fence like "src/" would reject every workflow
|
|
13
|
+
// scope inside it (the F9 red-class across two documents).
|
|
14
|
+
//
|
|
15
|
+
// Order is load-bearing: "//" collapses and interior "/./" drops BEFORE the
|
|
16
|
+
// leading "./" strip, so ".//src" → "src" and never "/src". Stripping first
|
|
17
|
+
// would MINT an absolute prefix from a relative scope — a design-law-#1
|
|
18
|
+
// containment escape (resolve(workdir, "/src") ignores workdir entirely).
|
|
19
|
+
//
|
|
20
|
+
// Deliberately NOT path.posix.normalize: it resolves ".." segments
|
|
21
|
+
// (normalize("src/../etc") === "etc"), which must stay VISIBLE so
|
|
22
|
+
// scopeContained can reject them — the whole point of the containment law.
|
|
23
|
+
let p = scope.replace(/\/\*\*?$/, '');
|
|
24
|
+
p = p.replace(/\/{2,}/g, '/').replace(/\/\.(?=\/|$)/g, '').replace(/^(?:\.\/)+/, '').replace(/\/+$/, '');
|
|
25
|
+
return p;
|
|
26
|
+
}
|