fwdloop 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fwdloop +20 -2
- package/package.json +2 -2
- package/src/auditchecks.js +55 -0
- package/src/authoring.js +53 -12
- package/src/blockasks.js +45 -0
- package/src/blockassemble.js +159 -0
- package/src/blockdraft.js +86 -0
- package/src/blocklines.js +30 -0
- package/src/blockpick.js +175 -0
- package/src/cardlist.js +19 -0
- package/src/checkblock.js +843 -0
- package/src/checked.js +48 -9
- package/src/checklist.js +99 -0
- package/src/checklistsign.js +93 -0
- package/src/checkpick.js +7 -73
- package/src/checkwords.js +20 -1
- package/src/cited-record.js +21 -1
- package/src/citedcheck.js +162 -7
- package/src/closers.js +41 -3
- package/src/declaration.js +34 -9
- package/src/declaredclose.js +4 -0
- package/src/draft-steps.js +3 -1
- package/src/drafter.js +311 -206
- package/src/factwords.js +112 -0
- package/src/inputlook.js +53 -0
- package/src/labelscan.js +162 -0
- package/src/noteask.js +62 -0
- package/src/pageask.js +9 -69
- package/src/pagedropwords.js +11 -1
- package/src/pagedry.js +27 -4
- package/src/pagerules.js +19 -3
- package/src/panel/author.js +76 -7
- package/src/panel/authorcard.js +43 -17
- package/src/panel/data.js +41 -9
- package/src/panel/index.html +208 -13
- package/src/panel/result.js +4 -3
- package/src/panel/server.js +3 -1
- package/src/pickrecord.js +70 -54
- package/src/placerule.js +398 -0
- package/src/planrebuild.js +216 -0
- package/src/rowedit.js +148 -0
- package/src/rubricstep.js +272 -0
- package/src/runfile.js +4 -2
- package/src/runner.js +67 -10
- package/src/setup.js +11 -5
- package/src/sheetblock.js +22 -8
- package/src/sheetbuild.js +151 -0
- package/src/sheetchecks.js +52 -66
- package/src/sheetclaims.js +12 -32
- package/src/sheetfind.js +4 -4
- package/src/sheetlook.js +14 -3
- package/src/sheetoffer.js +74 -57
- package/src/sheetrows.js +123 -0
- package/src/sheetrun.js +13 -10
- package/src/summary-words.js +3 -3
- package/src/ticket-draft.js +4 -21
- package/src/ticketrows.js +100 -0
- package/src/try-checks.js +31 -12
- package/src/types.js +1 -0
- package/types/auditchecks.d.ts +25 -0
- package/types/authoring.d.ts +21 -2
- package/types/blockasks.d.ts +36 -0
- package/types/blockassemble.d.ts +50 -0
- package/types/blockdraft.d.ts +75 -0
- package/types/blocklines.d.ts +31 -0
- package/types/blockpick.d.ts +46 -0
- package/types/cardlist.d.ts +21 -0
- package/types/checkblock.d.ts +378 -0
- package/types/checked.d.ts +16 -2
- package/types/checklist.d.ts +115 -0
- package/types/checklistsign.d.ts +27 -0
- package/types/checkpick.d.ts +4 -34
- package/types/checkwords.d.ts +5 -0
- package/types/cited-record.d.ts +9 -0
- package/types/citedcheck.d.ts +33 -2
- package/types/closers.d.ts +24 -2
- package/types/declaration.d.ts +7 -0
- package/types/declaredclose.d.ts +2 -0
- package/types/drafter.d.ts +29 -715
- package/types/factwords.d.ts +38 -0
- package/types/inputlook.d.ts +49 -0
- package/types/labelscan.d.ts +35 -0
- package/types/noteask.d.ts +52 -0
- package/types/pageask.d.ts +2 -35
- package/types/pagedry.d.ts +13 -0
- package/types/pagerules.d.ts +7 -0
- package/types/panel/author.d.ts +41 -0
- package/types/panel/authorcard.d.ts +14 -9
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/data.d.ts +5 -3
- package/types/panel/jobgrid.d.ts +1 -1
- package/types/pickrecord.d.ts +69 -13
- package/types/placerule.d.ts +208 -0
- package/types/planrebuild.d.ts +52 -0
- package/types/provider.d.ts +1 -1
- package/types/rowedit.d.ts +48 -0
- package/types/rubricstep.d.ts +63 -0
- package/types/runfile.d.ts +5 -2
- package/types/runner.d.ts +45 -1
- package/types/sheetblock.d.ts +12 -4
- package/types/sheetbuild.d.ts +84 -0
- package/types/sheetchecks.d.ts +12 -18
- package/types/sheetclaims.d.ts +2 -1
- package/types/sheetfind.d.ts +2 -2
- package/types/sheetoffer.d.ts +31 -6
- package/types/sheetrows.d.ts +81 -0
- package/types/sheetrun.d.ts +4 -4
- package/types/summary-words.d.ts +2 -1
- package/types/ticket-draft.d.ts +3 -49
- package/types/ticketrows.d.ts +61 -0
- package/types/try-checks.d.ts +4 -2
- package/types/types.d.ts +8 -0
- package/src/repairs.js +0 -38
- package/types/repairs.d.ts +0 -13
package/src/runner.js
CHANGED
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
import { configHome, configDoorHome } from './config.js';
|
|
60
60
|
import { closeByClass, isCellsPath } from './closers.js';
|
|
61
61
|
import { readRunSource } from './cited-source.js';
|
|
62
|
-
import { citedLineOf, writeCitedLine } from './cited-record.js';
|
|
62
|
+
import { citedLineOf, writeCitedLine, quotesOfLines } from './cited-record.js';
|
|
63
63
|
import { sheetRolesOf, tableShaOfFrozen, readRunSheets } from './sheetrun.js';
|
|
64
64
|
import { writeSheetLine } from './sheet-record.js';
|
|
65
65
|
import {
|
|
@@ -75,7 +75,9 @@ import {
|
|
|
75
75
|
doneRecord, happenedRecord, outputRecord, closeRecords,
|
|
76
76
|
} from './try-checks.js';
|
|
77
77
|
import { readJobThinking, readModelRecord, takeLearningsRecord } from './flowmodel.js';
|
|
78
|
-
import { readRunInputs, writeRunStart } from './runfile.js';
|
|
78
|
+
import { readRunInputs, readRunRecord, writeRunStart } from './runfile.js';
|
|
79
|
+
// borrowed-from: bareloop src/userrun.js@v0.56.0 (3383cce) (the place-rule read at run start and its stop words; fwd keeps the read value in run.json, not a spine)
|
|
80
|
+
import { citedPlaceFactsOf, bindCitedPlaceValues, readPlaceRules, valueInWords, stopWords, placeValuesOfEvents, lastRunPlaceRead, PLACE_EVENT, NO_PLACE_RECORD_WORDS } from './placerule.js';
|
|
79
81
|
import { buildMemo } from './memo.js';
|
|
80
82
|
import { wholeJobAskIndex, wholeJobText } from './whole-job.js';
|
|
81
83
|
import { fetchPageText, isWebUrl } from './pagefetch.js';
|
|
@@ -483,6 +485,36 @@ export async function freezeInputs(runDir, sources, { fetchPage, tableRoles = []
|
|
|
483
485
|
return { ok: true, manifest, skip };
|
|
484
486
|
}
|
|
485
487
|
|
|
488
|
+
/**
|
|
489
|
+
* M16 item 1: read every place-rule fact of the job's steps from the run's OWN frozen copy of its input, by code, before any provider call. `{ok:false, words}` = a rule
|
|
490
|
+
* was not found (bareloop's stop words); `{ok:true, rows, values}` = the rows to record in run.json and the key-to-value map to bind in memory. No place fact = nothing read.
|
|
491
|
+
* @param {string} runDir @param {any[]} steps @param {any[]} manifest freezeInputs' manifest @param {Record<string, string>} [earlier] key to the value the newest earlier run read ("was")
|
|
492
|
+
*/
|
|
493
|
+
export function readRunPlaceRules(runDir, steps, manifest, earlier = {}) {
|
|
494
|
+
const facts = citedPlaceFactsOf(steps);
|
|
495
|
+
if (facts.length === 0) return { ok: /** @type {true} */ (true), rows: null, values: {} };
|
|
496
|
+
const read = readPlaceRules(facts.map((fact) => {
|
|
497
|
+
const entry = manifest.find((e) => e?.id === fact.source);
|
|
498
|
+
const file = entry && typeof entry.frozen === 'string' ? readFileInside(runDir, `inputs/${basename(entry.frozen)}`) : null;
|
|
499
|
+
return { fact, text: file && file.ok ? file.text : null, was: earlier[fact.key] ?? valueInWords(fact.place, fact.phrase) };
|
|
500
|
+
}));
|
|
501
|
+
if (!read.proceed) return { ok: /** @type {false} */ (false), words: stopWords(read.rows) };
|
|
502
|
+
return { ok: /** @type {true} */ (true), rows: read.rows.map(({ name: _n, ...r }) => r), values: read.values };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* M16 item 1: the steps a RESUMED / continued run carries on with: the signed steps, each place fact's phrase set to the value its own run.json recorded at the start.
|
|
507
|
+
* A job with no place fact returns its steps as they are; a run whose record is missing or has a rule not found is `{ok:false, words: NO_PLACE_RECORD_WORDS}`.
|
|
508
|
+
* @param {string} runDir @param {any[]} steps
|
|
509
|
+
*/
|
|
510
|
+
export function stepsWithRecordedPlaces(runDir, steps) {
|
|
511
|
+
if (citedPlaceFactsOf(steps).length === 0) return { ok: /** @type {true} */ (true), steps };
|
|
512
|
+
const got = readRunRecord(runDir);
|
|
513
|
+
const values = got.ok && Array.isArray(got.rec.placeRules?.rows) ? placeValuesOfEvents([{ type: PLACE_EVENT, rows: got.rec.placeRules.rows }]) : null;
|
|
514
|
+
if (values === null) return { ok: /** @type {false} */ (false), words: NO_PLACE_RECORD_WORDS };
|
|
515
|
+
return { ok: /** @type {true} */ (true), steps: bindCitedPlaceValues(steps, values) };
|
|
516
|
+
}
|
|
517
|
+
|
|
486
518
|
/**
|
|
487
519
|
* The sources a rerun re-freezes: each input's original source. M13 item 9.1: a ticket input's source is the ticket's own address; it goes back as its LIST address with the
|
|
488
520
|
* ticket mark, so the rerun reads the ticket through the job's MCP tools and the signed filter, not as a web page.
|
|
@@ -893,6 +925,7 @@ function makeAuditRow({
|
|
|
893
925
|
* @param {string|null} [opts.prevStepId] - the id of step stepNo-1 (null for step 1): the step a "stopped after step N-1" row is filed under
|
|
894
926
|
* @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
|
|
895
927
|
* @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
|
|
928
|
+
* @param {any[]} [opts.checkList] - M16 item 5: the plan's signed list; a list line's checks carry the row's `by`
|
|
896
929
|
* @param {Record<string, any>} [opts.mcpGranted] - M13 item 5: this step's signed MCP tools, already bound to its bridge (`runStepRalph` builds them); handed to the model with the verbs
|
|
897
930
|
* @returns {Promise<{ok:true, artifact:any, attempts:number, hitl?:boolean} | {ok:false, outcome:string, red:string, stop?:{where:string, book:Record<string, any>, step?:string|null}}>}
|
|
898
931
|
*/
|
|
@@ -917,6 +950,8 @@ async function runStepTries({
|
|
|
917
950
|
// the id of step stepNo-1 (null for step 1): a Stop before this step's first call words itself "after step N-1" and is filed under that step
|
|
918
951
|
prevStepId = null,
|
|
919
952
|
mcpGranted = {},
|
|
953
|
+
// M16 item 5: the signed list (declaration.checkList), so a check of a list line is tagged by its row in the Audit
|
|
954
|
+
checkList = undefined,
|
|
920
955
|
}) {
|
|
921
956
|
/** @type {string|null} */
|
|
922
957
|
let gap = initialGap ?? null;
|
|
@@ -1159,14 +1194,16 @@ async function runStepTries({
|
|
|
1159
1194
|
// said is written by the one writer, `writeSheetLine`, whatever the verdict.
|
|
1160
1195
|
const sheetPart = step?.close?.class === 'green' && Array.isArray(step?.close?.sheet) ? step.close.sheet : undefined;
|
|
1161
1196
|
const sheet = sheetPart && runDir !== null ? readRunSheets(runDir, sheetPart) : undefined;
|
|
1162
|
-
|
|
1197
|
+
// M16 R7: a text step with the numbers tie (`close.numbersFrom`) is checked against the quotes the earlier lines' cited checks passed on, read from this run's own record
|
|
1198
|
+
const numbers = Array.isArray(step?.close?.numbersFrom) && runDir !== null ? quotesOfLines(runDir, step.close.numbersFrom) : undefined;
|
|
1199
|
+
const closed = await closeByClass(step, artifact, { reads: readsMap, businessDate, source, sheet, numbers });
|
|
1163
1200
|
if (sheetPart && runDir !== null && closed.sheetRecord) writeSheetLine(runDir, { n: step.fromLine, try: attempt, checks: sheetPart, closed });
|
|
1164
1201
|
if (citedPart && runDir !== null && closed.cited) {
|
|
1165
1202
|
writeCitedLine(runDir, citedLineOf({
|
|
1166
1203
|
n: step.fromLine, part: closed.cited.part, results: closed.cited.results, check: closed.cited.check,
|
|
1167
1204
|
}));
|
|
1168
1205
|
}
|
|
1169
|
-
tryChecks.push(...closeRecords(step, artifact, closed));
|
|
1206
|
+
tryChecks.push(...closeRecords(step, artifact, closed, checkList));
|
|
1170
1207
|
saveTry();
|
|
1171
1208
|
|
|
1172
1209
|
if (closed.verdict === 'green' || closed.verdict === 'hitl') {
|
|
@@ -1413,7 +1450,14 @@ export async function runFlow({
|
|
|
1413
1450
|
}
|
|
1414
1451
|
|
|
1415
1452
|
// M8b item 1: the run's start record, written once: the model it started on (M4d am33), the "Thinking on" box (M4d am25) and the frozen inputs
|
|
1416
|
-
|
|
1453
|
+
// M16 item 1: the place-rule facts are read from this run's own frozen copy, before any provider call; a rule not found stops here at $0 (a skipped ticket reads nothing)
|
|
1454
|
+
const placed = frozen.skip ? { ok: /** @type {true} */ (true), rows: null, values: {} } : readRunPlaceRules(runDir, declaration.steps, /** @type {any[]} */ (frozen.manifest), lastRunPlaceRead({ flowDir, runId }));
|
|
1455
|
+
if (!placed.ok) {
|
|
1456
|
+
return haltRun({
|
|
1457
|
+
flowDir, runDir, runId, capUsd, startedAt, now, nowMs: getNowMs, signatureHash: signature.flow, outcome: 'preflight-red', red: placed.words, spent: { value: 0 },
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
writeRunStart(runDir, { model: runModel ?? null, thinking: thinkingBox, inputs: /** @type {any[]} */ (frozen.manifest), rerun: rerunOf ?? null, placeRules: placed.rows ? { rows: placed.rows } : null });
|
|
1417
1461
|
// M12 piece 3 (item 9): a ticket the signed labels do not match, or a closed one, ends here: skipped, $0, nothing else runs
|
|
1418
1462
|
if (frozen.skip) {
|
|
1419
1463
|
return haltRun({
|
|
@@ -1458,7 +1502,7 @@ export async function runFlow({
|
|
|
1458
1502
|
/** @type {Array<{step:string|null, emits:string, artifact:unknown}>} */
|
|
1459
1503
|
let unjudgedSinceLastAsk = [];
|
|
1460
1504
|
|
|
1461
|
-
const steps = declaration.steps;
|
|
1505
|
+
const steps = Object.keys(placed.values).length > 0 ? bindCitedPlaceValues(declaration.steps, placed.values) : declaration.steps;
|
|
1462
1506
|
// M2 fix: the send's content is identified by IDENTITY (the artifact
|
|
1463
1507
|
// emitted by a signed ask step), never by position in `reads` — every id
|
|
1464
1508
|
// in a send step's `reads` names an earlier step, so picking `reads[0]`
|
|
@@ -1474,6 +1518,7 @@ export async function runFlow({
|
|
|
1474
1518
|
|
|
1475
1519
|
const result = await foldFromStep({
|
|
1476
1520
|
mcpServer: declaration.mcp?.server ?? null,
|
|
1521
|
+
checkList: declaration.checkList,
|
|
1477
1522
|
i0: 0,
|
|
1478
1523
|
steps,
|
|
1479
1524
|
askLines,
|
|
@@ -1608,6 +1653,8 @@ async function runAskSlot({
|
|
|
1608
1653
|
mcpServer = /** @type {string|null} */ (null),
|
|
1609
1654
|
// M13 am9: set only for the Ask that shows the whole job; rebuilds `{text}` from the saved outputs after a redo changed one
|
|
1610
1655
|
rebuildPrior = /** @type {null | (() => ({ok:true,value:any}|{ok:false,red:string}))} */ (null),
|
|
1656
|
+
// M16 item 5: the signed list, handed on to a redo's tries
|
|
1657
|
+
checkList = /** @type {any[]|undefined} */ (undefined),
|
|
1611
1658
|
}) {
|
|
1612
1659
|
let redone = initialRedone;
|
|
1613
1660
|
let currentPrior = priorArtifact;
|
|
@@ -1784,7 +1831,7 @@ async function runAskSlot({
|
|
|
1784
1831
|
}
|
|
1785
1832
|
// eslint-disable-next-line no-await-in-loop
|
|
1786
1833
|
const redoResult = await runStepRalph({
|
|
1787
|
-
step: priorStep, primitivesMap: primitives, readsMap: priorReadsResult.map, businessDate, modelStep, spent, capUsd, ceilingUsd: effectiveCeilingUsd, recordAudit, mcpServer, initialGap: reason, attemptOffset: lastTryNumber(runDir, priorStep.emits ?? priorStep.goal ?? null), thinkingBox: readJobThinking(flowDir, runDir), learnHints: stepHintsReader({ flowName, source: inputsManifest?.[0]?.source ?? null, now }), now, runDir,
|
|
1834
|
+
step: priorStep, primitivesMap: primitives, readsMap: priorReadsResult.map, businessDate, modelStep, spent, capUsd, ceilingUsd: effectiveCeilingUsd, recordAudit, mcpServer, checkList, initialGap: reason, attemptOffset: lastTryNumber(runDir, priorStep.emits ?? priorStep.goal ?? null), thinkingBox: readJobThinking(flowDir, runDir), learnHints: stepHintsReader({ flowName, source: inputsManifest?.[0]?.source ?? null, now }), now, runDir,
|
|
1788
1835
|
readStop: () => stopPending(runDir), stepNo: priorStepNo, prevStepId: priorPrevStepId,
|
|
1789
1836
|
});
|
|
1790
1837
|
if (!redoResult.ok) {
|
|
@@ -1849,6 +1896,8 @@ async function foldFromStep({
|
|
|
1849
1896
|
resumeRedone = 0,
|
|
1850
1897
|
// M13 item 5: the job's signed `mcp.server`, for a step that grants MCP tools (`runStepRalph` starts its bridge)
|
|
1851
1898
|
mcpServer = /** @type {string|null} */ (null),
|
|
1899
|
+
// M16 item 5: the signed list (declaration.checkList): a list line's checks are tagged by their row in the Audit
|
|
1900
|
+
checkList = /** @type {any[]|undefined} */ (undefined),
|
|
1852
1901
|
}) {
|
|
1853
1902
|
let runAcceptedThisRun = acceptedThisRun;
|
|
1854
1903
|
let runUnjudged = unjudgedSinceLastAsk;
|
|
@@ -1989,6 +2038,7 @@ async function foldFromStep({
|
|
|
1989
2038
|
// eslint-disable-next-line no-await-in-loop
|
|
1990
2039
|
const askResult = await runAskSlot({
|
|
1991
2040
|
mcpServer,
|
|
2041
|
+
checkList,
|
|
1992
2042
|
step,
|
|
1993
2043
|
stepIndex: i,
|
|
1994
2044
|
askSlot,
|
|
@@ -2062,7 +2112,7 @@ async function foldFromStep({
|
|
|
2062
2112
|
// redo's `initialGap` above.
|
|
2063
2113
|
// eslint-disable-next-line no-await-in-loop
|
|
2064
2114
|
const stepResult = await runStepRalph({
|
|
2065
|
-
step, primitivesMap: primitives, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd: effectiveCeilingUsd, recordAudit, mcpServer, initialGap: i === i0 ? firstStepGap : null, thinkingBox: readJobThinking(flowDir, runDir), learnHints: stepHintsReader({ flowName, source: inputsManifest?.[0]?.source ?? null, now }), now, runDir,
|
|
2115
|
+
step, primitivesMap: primitives, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd: effectiveCeilingUsd, recordAudit, mcpServer, checkList, initialGap: i === i0 ? firstStepGap : null, thinkingBox: readJobThinking(flowDir, runDir), learnHints: stepHintsReader({ flowName, source: inputsManifest?.[0]?.source ?? null, now }), now, runDir,
|
|
2066
2116
|
readStop: () => stopPending(runDir), stepNo: i + 1, prevStepId: i > 0 ? (steps[i - 1].emits ?? steps[i - 1].goal ?? null) : null, attemptOffset: i === i0 ? resumeTries.numbered : 0, triesDone: i === i0 ? resumeTries.done : 0,
|
|
2067
2117
|
});
|
|
2068
2118
|
if (!stepResult.ok) {
|
|
@@ -2370,7 +2420,9 @@ export async function resumeRun({
|
|
|
2370
2420
|
// like `missing` — never silently treated as "not done yet" and redone,
|
|
2371
2421
|
// which could spend money or re-ask a human for a step that already
|
|
2372
2422
|
// completed.
|
|
2373
|
-
const
|
|
2423
|
+
const placedSteps = stepsWithRecordedPlaces(runDir, declaration.steps);
|
|
2424
|
+
if (!placedSteps.ok) return { outcome: 'refused', red: placedSteps.words };
|
|
2425
|
+
const steps = placedSteps.steps;
|
|
2374
2426
|
for (let i = 0; i < state.stepIndex; i += 1) {
|
|
2375
2427
|
const artifactResult = readArtifactResult(runDir, steps[i].emits);
|
|
2376
2428
|
if (!artifactResult.ok) {
|
|
@@ -2678,6 +2730,7 @@ export async function resumeRun({
|
|
|
2678
2730
|
|
|
2679
2731
|
const askResult = await runAskSlot({
|
|
2680
2732
|
mcpServer: declaration.mcp?.server ?? null,
|
|
2733
|
+
checkList: declaration.checkList,
|
|
2681
2734
|
step,
|
|
2682
2735
|
stepIndex: state.stepIndex,
|
|
2683
2736
|
askSlot,
|
|
@@ -2734,6 +2787,7 @@ export async function resumeRun({
|
|
|
2734
2787
|
|
|
2735
2788
|
const result = await foldFromStep({
|
|
2736
2789
|
mcpServer: declaration.mcp?.server ?? null,
|
|
2790
|
+
checkList: declaration.checkList,
|
|
2737
2791
|
i0: state.stepIndex + 1,
|
|
2738
2792
|
steps,
|
|
2739
2793
|
askLines,
|
|
@@ -2872,7 +2926,9 @@ export async function continueRun({
|
|
|
2872
2926
|
}
|
|
2873
2927
|
}
|
|
2874
2928
|
|
|
2875
|
-
const
|
|
2929
|
+
const placedSteps = stepsWithRecordedPlaces(runDir, declaration.steps);
|
|
2930
|
+
if (!placedSteps.ok) return refused(placedSteps.words);
|
|
2931
|
+
const steps = placedSteps.steps;
|
|
2876
2932
|
if (halt.stepIndex > steps.length) return refused(`run "${runId}" halt.json names step ${halt.stepIndex}, past this flow's ${steps.length} steps`);
|
|
2877
2933
|
/** @type {Record<string, any>} */
|
|
2878
2934
|
const artifacts = {};
|
|
@@ -2940,6 +2996,7 @@ export async function continueRun({
|
|
|
2940
2996
|
|
|
2941
2997
|
const result = await foldFromStep({
|
|
2942
2998
|
mcpServer: declaration.mcp?.server ?? null,
|
|
2999
|
+
checkList: declaration.checkList,
|
|
2943
3000
|
i0: halt.stepIndex,
|
|
2944
3001
|
resumeTries,
|
|
2945
3002
|
steps,
|
package/src/setup.js
CHANGED
|
@@ -56,7 +56,8 @@ function planRow(sessionDir, rel, kind, n) {
|
|
|
56
56
|
structureRetries: Number.isInteger(log?.structureRetries) ? log.structureRetries : null,
|
|
57
57
|
verdict, hash, gap,
|
|
58
58
|
// M4d am15: every try of this plan (label, passed, the checker's raw refusals, the round's words), for the Audit Draft group; only when a retry happened
|
|
59
|
-
|
|
59
|
+
// M16: tries are the declaration rounds only (triesOf), so the list's own turns do not make a one-try draft look retried
|
|
60
|
+
...(Array.isArray(log?.log) && triesOf(log.log).length > 1 ? { tries: triesOf(log.log) } : {}),
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -83,7 +84,7 @@ function humanRows(sessionDir, rel) {
|
|
|
83
84
|
const [ask] = checkAsks([{ line: k.line, rule: k.rule, text: k.ruleText, check: k.check ?? null, why: null }]);
|
|
84
85
|
return {
|
|
85
86
|
kind: 'human', n: lookAnswered + i + 1, at: null, source: 'look', ask: ask.ask, question: ask.question, answer: KEPT_WORDS, line: k.line,
|
|
86
|
-
ruleNo: k.rule, ruleText: k.ruleText, proposal: ask.reading ?? null, rule: k.
|
|
87
|
+
ruleNo: k.rule, ruleText: k.ruleText, proposal: ask.reading ?? null, rule: k.ruleText ?? null,
|
|
87
88
|
};
|
|
88
89
|
});
|
|
89
90
|
return [...answered, ...keptRows];
|
|
@@ -111,8 +112,11 @@ export function buildSetupRows({
|
|
|
111
112
|
const card = readJson(sessionDir, `card-${n}.json`);
|
|
112
113
|
if (card) rows.push({ kind: 'card', n, at: mtimeIso(sessionDir, `card-${n}.json`), card });
|
|
113
114
|
// M4e amendment 24 item 4: a plan drafted again after the human's answers is booked as `redraft`, not `revise` (it uses none of the 2 revises)
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
// M16 item 5: a plan made by a Drop or an Add of the person is booked as that, not as a redraft; it asked nothing, and what it kept is the earlier plan's row, not its own
|
|
116
|
+
const marker = readJson(sessionDir, `redraft-${n}.json`);
|
|
117
|
+
const rowEdit = marker && marker.rowEdit && typeof marker.rowEdit === 'object' ? marker.rowEdit : null;
|
|
118
|
+
rows.push({ ...planRow(sessionDir, `draft-${n}`, rowEdit ? 'rowedit' : marker ? 'redraft' : 'revise', n), ...(rowEdit ? { op: rowEdit.op, key: rowEdit.key } : {}) });
|
|
119
|
+
if (!rowEdit) rows.push(...humanRows(sessionDir, `draft-${n}`));
|
|
116
120
|
}
|
|
117
121
|
} else {
|
|
118
122
|
const r = planRow(planDir, '.', 'draft', 0);
|
|
@@ -120,7 +124,9 @@ export function buildSetupRows({
|
|
|
120
124
|
}
|
|
121
125
|
// M4e amendment 36: the drafter's own "Not checked" list (the green plan folder's not-checked.json), kept word for word with its label. Not signed,
|
|
122
126
|
// not in any hash. An unreadable or missing file is an empty list (a plan from before amendment 25 has none).
|
|
123
|
-
const
|
|
127
|
+
const ncFile = readJson(planDir, 'not-checked.json');
|
|
128
|
+
// M16 item 5: the tag of each line that tells a list row rides the sign row (the Audit's Checks fold draws it); a plan with no list has none
|
|
129
|
+
const notChecked = { ...notCheckedBlock(ncFile?.notChecked), ...(ncFile?.by && typeof ncFile.by === 'object' && !Array.isArray(ncFile.by) ? { by: ncFile.by } : {}) };
|
|
124
130
|
rows.push({
|
|
125
131
|
kind: 'sign', n: 0, at: signedAt, signedBy, hash, flowHash: flowHash ?? null, notChecked,
|
|
126
132
|
});
|
package/src/sheetblock.js
CHANGED
|
@@ -7,12 +7,13 @@
|
|
|
7
7
|
// A green "found" is the step's OWN claimed value in plain words (a number, or a count of rows / days / bands / groups); a string claim (a looked-up cell) is never
|
|
8
8
|
// repeated, because it is cell text. A red "found" is bareguard's gap words (row numbers and counts), never a cell's text.
|
|
9
9
|
// Third outcomes, named: a line the run never reached (no record) carries no verdict; a check the record lacks carries none (the page shows no mark).
|
|
10
|
-
import { labelled } from './checkwords.js';
|
|
10
|
+
import { labelled, tagged, sheetByOf } from './checkwords.js';
|
|
11
11
|
import { isDeepStrictEqual } from 'node:util';
|
|
12
12
|
import { rubricVocabulary } from 'bareguard';
|
|
13
13
|
import { lineRules } from './pagebits.js';
|
|
14
14
|
import { sheetCheckSentence } from './sheetchecks.js';
|
|
15
15
|
import { isColumnChoiceRule } from './sheetoffer.js';
|
|
16
|
+
import { NO_VALUE_WHY } from './ticketrows.js';
|
|
16
17
|
|
|
17
18
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
18
19
|
|
|
@@ -56,9 +57,18 @@ export function sheetFoundWords(check, claims) {
|
|
|
56
57
|
return null;
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
/** M17 am2: a check code built has code's own name: `l<line>r<rules>` (a rule row's) or `l<line>a<k>` (an `[agent]` row's); a plan whose checks all have one is an M17 plan (its card shows the list only) @param {unknown} id */
|
|
61
|
+
export const isCodeBuiltId = (id) => typeof id === 'string' && /^l\d+[ra]\d+(_\d+)*$/.test(id);
|
|
62
|
+
|
|
63
|
+
/** M17 am3: who a sheet check comes from: code's `row: 'agent'` (a second check on a rule, its own `[agent]` row) is `agent` whatever it shows; else the one rule (`sheetByOf`) @param {any} c @param {string[]} rules */
|
|
64
|
+
export const sheetByCheck = (c, rules) => (c?.row === 'agent' ? 'agent' : sheetByOf(rules));
|
|
65
|
+
|
|
59
66
|
/** @param {any} l a job line `{rules?, guardrail?, rule?}` @returns {string[]} its `~` rules, numbered from 1 by position */
|
|
60
67
|
export const rulesOfLine = (l) => lineRules({ ...(Array.isArray(l?.rules) ? { rules: l.rules } : {}), rule: l?.guardrail ?? l?.rule });
|
|
61
68
|
|
|
69
|
+
/** M16 am4: the words of one sheet check without its tag - the ONE composition (the block's `text` and the list row both use it) @param {string} name @param {string} words @param {string} cw @returns {string} */
|
|
70
|
+
export const sheetPlainText = (name, words, cw) => [name, ...(words === name ? [] : [words]), ...(cw ? [cw] : [])].join(' \u2014 ');
|
|
71
|
+
|
|
62
72
|
/** the "covers ..." words of one check @param {string[]} rules @returns {string} "" when it covers none */
|
|
63
73
|
export const coversWords = (rules) => rules.map((r) => `covers "${r}"`).join(' · ');
|
|
64
74
|
|
|
@@ -67,12 +77,13 @@ export const coversWords = (rules) => rules.map((r) => `covers "${r}"`).join('
|
|
|
67
77
|
* older `close.columns` / `close.cited` check (then every guardrail is Not checked).
|
|
68
78
|
* @param {{declaration: any, lines: Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>, csvRoles?: string[], record?: any}} o
|
|
69
79
|
* `record` = the `sheet` section of `line-checks.json` (`{lines: [...]}`), only after a run
|
|
70
|
-
* @returns {Array<{line: number, guardrails: string[], checked: Array<{id: string, name: string, words: string, covers: string[], coversWords: string, text: string, ok?: boolean, found?: string}>, notChecked: string[]|'none'}>}
|
|
80
|
+
* @returns {Array<{line: number, codeBuilt: boolean, guardrails: string[], checked: Array<{id: string, name: string, words: string, covers: string[], coversWords: string, by: 'you'|'agent', text: string, ok?: boolean, found?: string}>, notChecked: string[]|'none'}>}
|
|
71
81
|
*/
|
|
72
82
|
export function sheetLineBlocks({ declaration, lines, csvRoles = [], record }) {
|
|
73
83
|
const out = [];
|
|
74
84
|
if (!isRec(declaration) || !Array.isArray(declaration.steps)) return out;
|
|
75
85
|
const seen = new Set();
|
|
86
|
+
const onList = Array.isArray(declaration.checkList) && declaration.checkList.some((/** @type {any} */ r) => isRec(r) && r.kind === 'sheet');
|
|
76
87
|
for (const st of declaration.steps) {
|
|
77
88
|
if (!isRec(st) || !isRec(st.close) || st.close.class !== 'green' || !Number.isInteger(st.fromLine) || seen.has(st.fromLine)) continue;
|
|
78
89
|
const hasSheet = Array.isArray(st.close.sheet) && st.close.sheet.length > 0;
|
|
@@ -91,7 +102,8 @@ export function sheetLineBlocks({ declaration, lines, csvRoles = [], record }) {
|
|
|
91
102
|
const words = sheetCheckSentence(c);
|
|
92
103
|
const cw = coversWords(rules);
|
|
93
104
|
/** @type {any} */
|
|
94
|
-
const
|
|
105
|
+
const by = sheetByCheck(c, rules);
|
|
106
|
+
const e = { id: typeof c.id === 'string' ? c.id : '', name, words, covers: rules, coversWords: cw, by, text: onList ? tagged(sheetPlainText(name, words, cw), by) : labelled(sheetPlainText(name, words, cw), 'agent') }; // hamr 2026-11-14: a plan whose list has sheet rows tags a check by where it comes from; an older plan keeps M10 am22 (4)'s `[agent]`
|
|
95
107
|
const res = newest && Array.isArray(newest.results) ? newest.results.find((/** @type {any} */ r) => isRec(r) && r.id === c.id) : undefined;
|
|
96
108
|
if (isRec(res) && typeof res.ok === 'boolean') {
|
|
97
109
|
e.ok = res.ok;
|
|
@@ -106,19 +118,21 @@ export function sheetLineBlocks({ declaration, lines, csvRoles = [], record }) {
|
|
|
106
118
|
return e;
|
|
107
119
|
});
|
|
108
120
|
const notChecked = guardrails.filter((r, i) => !isColumnChoiceRule(r) && !covered.has(i + 1));
|
|
109
|
-
out.push({ line: st.fromLine, guardrails, checked, notChecked: notChecked.length === 0 ? /** @type {'none'} */ ('none') : notChecked });
|
|
121
|
+
out.push({ line: st.fromLine, guardrails, checked, codeBuilt: hasSheet && st.close.sheet.every((/** @type {any} */ c) => isCodeBuiltId(c?.id)), notChecked: notChecked.length === 0 ? /** @type {'none'} */ ('none') : notChecked });
|
|
110
122
|
}
|
|
111
123
|
return out;
|
|
112
124
|
}
|
|
113
125
|
|
|
114
126
|
/**
|
|
115
|
-
* The guardrail rules of a sheet step that no check covers, as the drafter's Not-checked lines (`line N: "rule" -
|
|
127
|
+
* The guardrail rules of a sheet step that no check covers, as the drafter's Not-checked lines (`line N: "rule" - <reason>`): the block's own
|
|
116
128
|
* `notChecked`, one list for the plan card and the drafter's saved record.
|
|
117
|
-
*
|
|
129
|
+
* M17 am2: `built` (the builder's answer, src/sheetbuild.js) gives the reason a rule is Not checked (the refusal that named it).
|
|
130
|
+
* @param {any} declaration @param {Array<{n: number, rules?: string[], guardrail?: string, rule?: string}>} lines @param {string[]} csvRoles @param {{notChecked: Record<string, string>}} [built] @returns {string[]}
|
|
118
131
|
*/
|
|
119
|
-
export function uncoveredRules(declaration, lines, csvRoles) {
|
|
132
|
+
export function uncoveredRules(declaration, lines, csvRoles, built) {
|
|
120
133
|
if (csvRoles.length === 0) return [];
|
|
121
|
-
return sheetLineBlocks({ declaration, lines, csvRoles }).flatMap((b) => (b.notChecked === 'none' ? [] : b.notChecked
|
|
134
|
+
return sheetLineBlocks({ declaration, lines, csvRoles }).flatMap((b) => (b.notChecked === 'none' ? [] : b.notChecked
|
|
135
|
+
.map((r) => `line ${b.line}: "${r}" \u2014 ${built?.notChecked[`line ${b.line}: "${r}"`] ?? NO_VALUE_WHY}`)));
|
|
122
136
|
}
|
|
123
137
|
|
|
124
138
|
/** @param {any} arbiter @returns {string[]} the roles of the signed sources that are a CSV file (the sheets a check reads) */
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// M17 am2 + am3 (docs/wiki/the-module-ladder.md "M17 am2", "M17 am3"): the ONE builder of the sheet checks of a line. The AI never writes a sheet check: what it sends in the declaration round's
|
|
2
|
+
// `close.sheet` is read here only as a typed SUGGESTION (bareguard's rule fields plus the `covers` numbers); code refuses or builds every one on bareguard's shapes and writes the check itself.
|
|
3
|
+
// Ported from poc/f195-agentrows/build.mjs (F195 PASS, $0); no class code, no send-back loop, no word-to-column guess, no per-case validator patch.
|
|
4
|
+
// refusals (each by bareguard, in this order): the vocabulary (rule, op), the line's sheets, the schema (a field of the rule), `columnAt` (a column of the sheet's header), `checkTables`
|
|
5
|
+
// (and its problems), `groundedLiterals` (a number or date in the person's own words), `claimSchema` (an answer box), and for a `table` check `runTableChecks` on the sheet frozen at draft time.
|
|
6
|
+
// placement (am3 item 1): every suggestion that passes all of them is BUILT. A cells (answer) check is placed before a table check, then in the order sent. A cells check is a RULE ROW's check when none of the
|
|
7
|
+
// rules it covers is held by an earlier rule row, else (or when it covers no rule) its own `[agent]` row. M17 am7: a `table` check reads only the input sheet, so it is never a rule row: it is always
|
|
8
|
+
// its own `[agent]` row, on by default, and covers no rule (a rule only a table check named is Not checked). Nothing is hidden; nothing sits beside a rule's row.
|
|
9
|
+
// One writer per field: `id`, `claim`, `covers` and `table` (when absent and the line reads one sheet) are assigned here. A rule row's id is `l<line>r<rules>`, an agent row's `l<line>a<k>`; the claim is the id.
|
|
10
|
+
// What this throws away: a suggestion's `id`, `claim`, `text` (and its `covers`: an agent row's is only the rule no rule row holds); a refused suggestion's check (only its reason is kept, on the rules it named).
|
|
11
|
+
// Third outcomes, named: a suggestion that is not an object, names no rule or op bareguard has, a table it cannot read, a column that is no header: refused with that helper's words; a rule that no
|
|
12
|
+
// check holds is Not checked with the last refusal that named it, or the no-pick sentence (`NO_SUGGESTION`).
|
|
13
|
+
import { rubricVocabulary, claimSchema, groundedLiterals } from 'bareguard';
|
|
14
|
+
import { SHEET_RULES, sheetCheckColumns, sheetCheckReds, bareguardChecks } from './sheetchecks.js';
|
|
15
|
+
import { tableChecksFailingOnInput } from './sheetrun.js';
|
|
16
|
+
import { isColumnChoiceRule } from './sheetoffer.js';
|
|
17
|
+
import { rulesOfLine } from './sheetblock.js';
|
|
18
|
+
import { wordsSaidOn } from './pagebits.js';
|
|
19
|
+
import { NO_VALUE_WHY } from './ticketrows.js';
|
|
20
|
+
|
|
21
|
+
const V = /** @type {any} */ (rubricVocabulary);
|
|
22
|
+
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
23
|
+
|
|
24
|
+
/** the fields of a suggestion code does not read: it names every check itself */
|
|
25
|
+
export const SUGGESTION_DROPPED = Object.freeze(['id', 'claim', 'text', 'covers']);
|
|
26
|
+
|
|
27
|
+
/** M17 am7 item 2: the words of a rule no check holds and nothing refused: the one no-pick sentence (src/ticketrows.js), not a third copy */
|
|
28
|
+
export const NO_SUGGESTION = NO_VALUE_WHY;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {any} ai a suggestion as the AI sent it @returns {{covers: number[], fields: Record<string, any>}}
|
|
32
|
+
*/
|
|
33
|
+
export function toSuggestion(ai) {
|
|
34
|
+
/** @type {Record<string, any>} */
|
|
35
|
+
const fields = {};
|
|
36
|
+
if (isRec(ai)) for (const [k, v] of Object.entries(ai)) if (!SUGGESTION_DROPPED.includes(k)) fields[k] = v;
|
|
37
|
+
return { covers: isRec(ai) && Array.isArray(ai.covers) ? ai.covers : [], fields };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {{check: any, covers: number[]}} Placed
|
|
42
|
+
* @typedef {{rule: number, text: string, state: 'built'|'column'|'agent-row'|'not-checked', reason: string|null, id: string|null}} RuleState
|
|
43
|
+
* @param {{line: {n: number, text?: string, rules?: string[], guardrail?: string, rule?: string}, tables: Record<string, {header: string[], rows: any[]}>, suggestions: any[]}} o
|
|
44
|
+
* @returns {Promise<{rows: RuleState[], ruleRows: Placed[], agentRows: Placed[], checks: any[], refused: {helper: string, why: string}[]}>}
|
|
45
|
+
*/
|
|
46
|
+
export async function buildSheetLine({ line, tables, suggestions }) {
|
|
47
|
+
const rules = rulesOfLine(line);
|
|
48
|
+
const roles = Object.keys(tables);
|
|
49
|
+
const words = wordsSaidOn({ text: line.text, rules });
|
|
50
|
+
/** @type {{helper: string, why: string}[]} */
|
|
51
|
+
const refused = [];
|
|
52
|
+
/** @type {Map<number, string>} */
|
|
53
|
+
const refusedFor = new Map();
|
|
54
|
+
/** @type {{nums: number[], fields: Record<string, any>}[]} */
|
|
55
|
+
const buildable = [];
|
|
56
|
+
for (const src of suggestions) {
|
|
57
|
+
const s = toSuggestion(src);
|
|
58
|
+
const nums = [...new Set(s.covers)].filter((n) => Number.isInteger(n) && n >= 1 && n <= rules.length && !isColumnChoiceRule(rules[n - 1])).sort((a, b) => a - b);
|
|
59
|
+
const refuse = (/** @type {string} */ helper, /** @type {string} */ why) => { refused.push({ helper, why }); for (const n of nums) if (!refusedFor.has(n)) refusedFor.set(n, `suggestion refused: ${helper}: ${why}`); };
|
|
60
|
+
const f = s.fields;
|
|
61
|
+
if (!SHEET_RULES.includes(f.rule) || !isRec(V.rules[f.rule]?.ops) || !Object.hasOwn(V.rules[f.rule].ops, f.op)) { refuse('vocabulary', `no ${String(f.rule)} op "${String(f.op)}"`); continue; }
|
|
62
|
+
const role = typeof f.table === 'string' ? f.table : roles.length === 1 ? roles[0] : null;
|
|
63
|
+
if (role === null || !roles.includes(role)) { refuse('tables', `"${String(f.table)}" is not one of the line's sheets`); continue; }
|
|
64
|
+
const check = { ...f, table: role };
|
|
65
|
+
const bad = Object.keys(check).filter((k) => k !== 'rule' && !Object.hasOwn(V.rules[f.rule].fields, k));
|
|
66
|
+
if (bad.length > 0) { refuse('schema', `field ${bad.join(', ')} is not a ${f.rule} field`); continue; }
|
|
67
|
+
const probe = { id: 'probe', ...check, ...(f.rule === 'cells' ? { claim: 'probe' } : {}) };
|
|
68
|
+
const cols = sheetCheckColumns(probe).filter((c) => !tables[role].header.includes(c));
|
|
69
|
+
if (cols.length > 0) { refuse('columnAt', `'${cols[0]}' is not a column of "${role}"`); continue; }
|
|
70
|
+
const reds = sheetCheckReds([probe], line.n, tables);
|
|
71
|
+
if (reds.length > 0) { refuse('checkTables', reds[0].replace(/^declaration: line \d+: /, '')); continue; }
|
|
72
|
+
const miss = groundedLiterals(bareguardChecks([probe])[0], words).missing;
|
|
73
|
+
if (miss.length > 0) { refuse('groundedLiterals', `${miss[0].kind} ${JSON.stringify(miss[0].value)} (${miss[0].path}) is not in your words`); continue; }
|
|
74
|
+
if (f.rule === 'cells' && claimSchema(bareguardChecks([probe])[0]) === null) { refuse('claimSchema', 'no answer box for this check'); continue; }
|
|
75
|
+
if (f.rule === 'table') {
|
|
76
|
+
const fails = await tableChecksFailingOnInput({ steps: [{ fromLine: line.n, close: { class: 'green', sheet: [probe] } }] }, tables);
|
|
77
|
+
if (fails.length > 0) { refuse('runTableChecks', 'the table check already fails on the sheet'); continue; }
|
|
78
|
+
}
|
|
79
|
+
buildable.push({ nums, fields: check });
|
|
80
|
+
}
|
|
81
|
+
// placement: answer (cells) checks first, then the order sent (a stable sort)
|
|
82
|
+
const order = buildable.map((b, i) => ({ b, i })).sort((x, y) => (x.b.fields.rule === 'cells' ? 0 : 1) - (y.b.fields.rule === 'cells' ? 0 : 1) || x.i - y.i).map((x) => x.b);
|
|
83
|
+
/** @type {Map<number, string>} */
|
|
84
|
+
const held = new Map();
|
|
85
|
+
/** @type {Map<number, string>} */
|
|
86
|
+
const coveredByAgent = new Map();
|
|
87
|
+
/** @type {Placed[]} */
|
|
88
|
+
const ruleRows = [];
|
|
89
|
+
/** @type {Placed[]} */
|
|
90
|
+
const agentRows = [];
|
|
91
|
+
for (const b of order) {
|
|
92
|
+
const asRule = b.fields.rule !== 'table' && b.nums.length > 0 && b.nums.every((n) => !held.has(n) && !coveredByAgent.has(n));
|
|
93
|
+
const id = asRule ? `l${line.n}r${b.nums.join('_')}` : `l${line.n}a${agentRows.length + 1}`;
|
|
94
|
+
// an [agent] row shows only a rule no rule row holds and no earlier [agent] row shows (F195's rule: never shown nowhere, never two rows); `row: 'agent'` is the tag's own typed field (src/sheetblock.js)
|
|
95
|
+
const shown = asRule ? b.nums : b.fields.rule === 'table' ? [] : b.nums.filter((n) => !held.has(n) && !coveredByAgent.has(n));
|
|
96
|
+
const check = { id, ...b.fields, ...(b.fields.rule === 'cells' ? { claim: id } : {}), covers: shown, ...(asRule ? {} : { row: 'agent' }) };
|
|
97
|
+
if (asRule) { for (const n of b.nums) held.set(n, id); ruleRows.push({ check, covers: b.nums }); } else { for (const n of shown) coveredByAgent.set(n, id); agentRows.push({ check, covers: shown }); }
|
|
98
|
+
}
|
|
99
|
+
/** @type {RuleState[]} */
|
|
100
|
+
const rows = rules.map((text, i) => {
|
|
101
|
+
const n = i + 1;
|
|
102
|
+
if (isColumnChoiceRule(text)) return { rule: n, text, state: 'column', reason: null, id: null };
|
|
103
|
+
if (held.has(n)) return { rule: n, text, state: 'built', reason: null, id: /** @type {string} */ (held.get(n)) };
|
|
104
|
+
if (coveredByAgent.has(n)) return { rule: n, text, state: 'agent-row', reason: null, id: /** @type {string} */ (coveredByAgent.get(n)) };
|
|
105
|
+
return { rule: n, text, state: 'not-checked', reason: refusedFor.get(n) ?? NO_SUGGESTION, id: null };
|
|
106
|
+
});
|
|
107
|
+
return { rows, ruleRows, agentRows, checks: [...ruleRows, ...agentRows].map((p) => p.check), refused };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The declaration with every green sheet step's `close.sheet` REWRITTEN by code from what the AI suggested there (`buildSheetLine`). A step with no suggestion is left alone; a step none of whose
|
|
112
|
+
* suggestions can be built loses `close.sheet` (its rules are Not checked with their reasons). Pure over the declaration it is given (a copy is returned).
|
|
113
|
+
* @param {{declaration: any, lines: {n: number, text?: string, rules?: string[], guardrail?: string, rule?: string}[], tables: Record<string, {header: string[], rows: any[]}>}} o
|
|
114
|
+
* @returns {Promise<{declaration: any, notChecked: Record<string, string>, refused: {line: number, helper: string, why: string}[], unbuilt: {line: number, lost: string[]}[]}>} `unbuilt`: the green sheet steps left with no check, each with its rules as Not-checked lines. `notChecked`: `line N: "rule"` -> the refusal that named it (or `NO_SUGGESTION`), for each rule of a
|
|
115
|
+
* rewritten line that no check holds
|
|
116
|
+
*/
|
|
117
|
+
export async function buildSheetChecks({ declaration, lines, tables }) {
|
|
118
|
+
/** @type {Record<string, string>} */
|
|
119
|
+
const notChecked = {};
|
|
120
|
+
/** @type {{line: number, helper: string, why: string}[]} */
|
|
121
|
+
const refused = [];
|
|
122
|
+
if (!isRec(declaration) || !Array.isArray(declaration.steps)) return { declaration, notChecked, refused, unbuilt: [] };
|
|
123
|
+
/** @type {Set<number>} */
|
|
124
|
+
const done = new Set();
|
|
125
|
+
const steps = [];
|
|
126
|
+
for (const st of declaration.steps) {
|
|
127
|
+
if (!isRec(st) || !isRec(st.close) || st.close.class !== 'green' || !Array.isArray(st.close.sheet) || !Number.isInteger(st.fromLine) || done.has(st.fromLine)) { steps.push(st); continue; }
|
|
128
|
+
done.add(st.fromLine);
|
|
129
|
+
const line = lines.find((l) => l.n === st.fromLine);
|
|
130
|
+
if (!line) { steps.push(st); continue; }
|
|
131
|
+
const built = await buildSheetLine({ line, tables, suggestions: st.close.sheet });
|
|
132
|
+
for (const x of built.refused) refused.push({ line: st.fromLine, ...x });
|
|
133
|
+
for (const r of built.rows) if (r.state === 'not-checked') notChecked[`line ${st.fromLine}: "${r.text}"`] = /** @type {string} */ (r.reason);
|
|
134
|
+
const { sheet: _suggested, ...close } = st.close;
|
|
135
|
+
steps.push({ ...st, close: built.checks.length > 0 ? { ...close, sheet: built.checks } : close });
|
|
136
|
+
}
|
|
137
|
+
// M17 am5 / P5: a green step that reads a sheet and holds no check after the build (no suggestion, or none code could build) is REPORTED here, with each of its rules and the refusal that named it
|
|
138
|
+
// (else the no-pick sentence). What class such a step gets is the caller's to decide (src/blockassemble.js closeUnbuiltSheetSteps); this file writes no class.
|
|
139
|
+
/** @type {{line: number, lost: string[]}[]} */
|
|
140
|
+
const unbuilt = [];
|
|
141
|
+
const roles = Object.keys(tables);
|
|
142
|
+
for (const st of steps) {
|
|
143
|
+
if (!isRec(st) || !isRec(st.close) || st.close.class !== 'green' || (Array.isArray(st.close.sheet) && st.close.sheet.length > 0) || isRec(st.close.cited) || !Number.isInteger(st.fromLine)) continue;
|
|
144
|
+
if (!Array.isArray(st.reads) || !st.reads.some((/** @type {string} */ r) => roles.includes(r)) || unbuilt.some((u) => u.line === st.fromLine)) continue;
|
|
145
|
+
const line = lines.find((l) => l.n === st.fromLine);
|
|
146
|
+
const rules = line ? rulesOfLine(line).filter((r) => !isColumnChoiceRule(r)) : [];
|
|
147
|
+
if (rules.length === 0) continue;
|
|
148
|
+
unbuilt.push({ line: st.fromLine, lost: rules.map((r) => `line ${st.fromLine}: "${r}" \u2014 ${notChecked[`line ${st.fromLine}: "${r}"`] ?? NO_SUGGESTION}`) });
|
|
149
|
+
}
|
|
150
|
+
return { declaration: { ...declaration, steps }, notChecked, refused, unbuilt };
|
|
151
|
+
}
|