fwdloop 0.36.0 → 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 +74 -16
- 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 +85 -61
- package/src/factwords.js +7 -4
- package/src/globprefix.js +26 -0
- package/src/model-step.js +22 -4
- package/src/pageask.js +0 -3
- 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 +9 -3
- package/src/panel/data.js +3 -2
- package/src/panel/index.html +143 -33
- package/src/panel/result.js +34 -1
- package/src/pickrecord.js +14 -0
- package/src/planrebuild.js +55 -19
- package/src/ratelimit.js +117 -0
- package/src/report.js +14 -3
- package/src/rowresults.js +111 -0
- package/src/rubricstep.js +65 -2
- package/src/runner.js +38 -5
- 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 +1 -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 +24 -8
- package/types/action-stop.d.ts +1 -1
- package/types/auditchecks.d.ts +13 -2
- package/types/authoring.d.ts +20 -2
- 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 +0 -1
- 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 +16 -1
- package/types/pickrecord.d.ts +10 -0
- package/types/ratelimit.d.ts +59 -0
- package/types/report.d.ts +2 -1
- package/types/rowresults.d.ts +28 -0
- package/types/rubricstep.d.ts +21 -0
- package/types/runner.d.ts +3 -1
- 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 +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 +20 -4
package/src/checkblock.js
CHANGED
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
// borrowed-from: bareloop src/checkblock.js@v0.57.0 (c18df406)
|
|
2
|
+
// borrowed-from: bareloop src/checkblock.js@v0.60.0 (M19 S3: caught up from the earlier port; sheet rows, repo rows, droppable, choiceEntries and lineWordKeys as the tag has them)
|
|
3
|
+
// borrowed-from: bareloop src/checkblock.js@v0.61.0 (fc56e1f3) (M19 S3: the shape rows, setShape and the shape Drops; where a hunk is not taken the line says `fwd keeps`)
|
|
4
|
+
// Where a signed fwd rule stays instead of the tag's line, the line says `fwd keeps` (hamr 2026-11-19: "checks move inside with the same flow we have, don't make unneccessary drift"): the own-words answer to any question (M10 am16), no `$prose` row and no floor row on the card (the card draws neither today), no `corrected` flag, and fwd's own sheet Not-checked words.
|
|
5
|
+
// fwd never sets `repo` (it has no repo job), so the repo rows below are inert here and stay as the tag has them.
|
|
2
6
|
// first ported from: bareloop src/checkblock.js@v0.56.0 (3383cce) + f148028e (M16 am2: an agreed answer's follower row takes its parent's check after the parts are numbered, 4 lines in build())
|
|
3
7
|
// Ported, not copied whole (M16 am3 (1)): the imports point at fwd's files (src/blockpick.js is bareloop's checkpick.js under another name), and the three patterns built from text
|
|
4
8
|
// (the whole-word test in `inText`, the number test in `inJob` and `matchCount`) are written by hand, because src/ builds no pattern from text (test/signed-text.test.js).
|
|
5
|
-
// THE CHECK BLOCK of a
|
|
9
|
+
// THE CHECK BLOCK of a job (hamr 2026-11-12: "goal again is simplfication and one flow one place ai suggestes ! code adds $ and code decides what worked/doable").
|
|
6
10
|
// ONE store: `rows`. Nothing else holds a check. Rows are `~` (the person's own rule), `!` (the agent's suggestion: a look fact, or an AI edit) and `$` (code's defaults).
|
|
7
11
|
// The AI's whole part is a list of proposed ROW EDITS; code judges each edit alone, matches every row against the saved page, builds every check through the bareguard-backed
|
|
8
12
|
// shapes, and says why a row it cannot build is Not checked. The block never removes a row: only the person (`applyAnswer`) or code (`match`) changes one.
|
|
9
13
|
// fromJob -> addLook -> reconcile( match -> build -> ask ), then, while a question is open or a reply waits: apply it and reconcile the WHOLE list again.
|
|
10
|
-
// Pure: no I/O, no clock, no model.
|
|
14
|
+
// Pure: no I/O, no clock, no model. ONE block for every job (hamr 2026-11-15: "same flow as rubric, no exceptions; same CheckBlock, only the TYPE of checks varies"). A rubric job's rows are facts, phrases and
|
|
15
|
+
// counts built into rubric-step parts; a repo job (`repo` option) holds `~` rule rows the write fence keeps (or that the person answers about), `!` rows for the drafter's catalogue work stages, and the same `$` rows.
|
|
16
|
+
// The same rows store, the same asks, the same Drop/carry, the same signedRows and closeView serve both.
|
|
17
|
+
import { globToPrefix } from './globprefix.js';
|
|
11
18
|
import { countExact, countPhrase } from './pagebits.js';
|
|
12
19
|
import { checkFactWords, keptSetOf } from './factwords.js';
|
|
13
|
-
import { isCountable, keepOrDrop, countCheck, obviousCheck, partOfPick, plainWords
|
|
20
|
+
import { isCountable, keepOrDrop, countCheck, obviousCheck, partOfPick, plainWords } from './blockpick.js';
|
|
14
21
|
import { dropRows, dropSentence } from './pagedropwords.js';
|
|
15
|
-
import { phraseInNoResult } from './pagedry.js';
|
|
16
|
-
import { boundInWords, rubricStepShapeReds, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
|
|
22
|
+
import { phraseInNoResult, asSeenOf } from './pagedry.js';
|
|
23
|
+
import { boundInWords, rubricStepShapeReds, stageKeyOf, guardKeyOf, FENCE_KEY, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
|
|
17
24
|
import { validReading } from './pagerules.js';
|
|
18
25
|
import { weekOnly, weekTokens, WEEK_ONLY_WORDS, MAX_BANG } from './checklist.js';
|
|
19
26
|
import { fitPlacePhrase } from './placerule.js';
|
|
20
27
|
import { ruleWords } from './pageask.js';
|
|
21
28
|
import { SIGNED_ROW_FIELDS } from './declaredclose.js';
|
|
22
29
|
import { factSentence, countSentence, factsOfLook } from './citedcheck.js';
|
|
30
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
31
|
+
import { sheetCheckSentence } from './sheetchecks.js';
|
|
32
|
+
import { sheetCheckName, sheetPlainText, coversWords } from './sheetblock.js';
|
|
33
|
+
import { sheetCheckBody, sheetRowKey } from './sheetrows.js';
|
|
34
|
+
import { shapeRowKey, shapeDefaultKey, shapeFieldText, buildShapePart, itemCountOf } from './shaperows.js';
|
|
35
|
+
import { fieldSpec } from './shapebuild.js';
|
|
23
36
|
|
|
24
37
|
/**
|
|
25
38
|
* A row. `kind`: rule, fact, phrase, count, cited, numbers, floor. `by`: you (`~`), agent (`!`), default (`$`). A `~` row may carry `links` (the look's facts tied to it),
|
|
@@ -27,11 +40,10 @@ import { factSentence, countSentence, factsOfLook } from './citedcheck.js';
|
|
|
27
40
|
* @typedef {Record<string, any>} Row
|
|
28
41
|
*/
|
|
29
42
|
|
|
30
|
-
/**
|
|
31
|
-
export const CARD_T = Object.freeze({ count: 'result count', cited: 'every claim is backed by a quote copied from', theInput: 'the input', numbers: 'every number in the text is in a checked quote of line', withWords: 'with the words' });
|
|
43
|
+
/** what `setSheet` is given: code's build of a job's sheet checks, per sheet line @typedef {Awaited<ReturnType<typeof import('./sheetbuild.js').buildSheetChecks>>} SheetBuilt */
|
|
32
44
|
|
|
33
45
|
/** the four row edits an AI reply may hold */
|
|
34
|
-
export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable']);
|
|
46
|
+
export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable', 'fence']);
|
|
35
47
|
|
|
36
48
|
const norm = (/** @type {unknown} */ t) => String(t ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
|
|
37
49
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -64,11 +76,13 @@ const numberIn = (text, n) => {
|
|
|
64
76
|
};
|
|
65
77
|
const wordSet = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}]+/gu) ?? []);
|
|
66
78
|
|
|
79
|
+
// fwd (F251): what a row says when its check cannot ride a line that has no guardrail of its own (the class of a line comes from its guardrail); one writer, here (blockassemble.js re-exports it)
|
|
80
|
+
export const NO_GUARDRAIL_WORDS = 'This line has no guardrail of yours, so a check on it cannot be signed; you judge it at Accept.';
|
|
81
|
+
|
|
67
82
|
/** the plain reasons code gives, in one place (the card, the Job tab and the Audit read them from the row) */
|
|
68
83
|
export const REASON = Object.freeze({
|
|
69
84
|
left: 'You chose to leave it Not checked, so you judge it at Accept.',
|
|
70
85
|
nothingOnPage: 'Your own words are on the line; the machine has no check for them, so you judge it at Accept.',
|
|
71
|
-
cantCheck: "I can't check this on the page; waiting for your answer",
|
|
72
86
|
noRule: 'No rule can check this, so you judge it at Accept.',
|
|
73
87
|
waitingPick: 'waiting for your answer on the proposed check',
|
|
74
88
|
waitingReading: 'waiting for your answer on the reading',
|
|
@@ -76,30 +90,35 @@ export const REASON = Object.freeze({
|
|
|
76
90
|
manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
|
|
77
91
|
oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
|
|
78
92
|
countNeedsFact: 'a result count needs a fact to count; this line has none',
|
|
79
|
-
// borrowed-from: bareloop src/checkblock.js@v0.58.0
|
|
80
93
|
countNeedsSuggested: 'a result count needs a fact to count; add the suggested fact on this line to count its results',
|
|
81
94
|
lookNoWords: "the page does not hold the words of the look's fact for this rule",
|
|
82
95
|
afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
|
|
83
96
|
noPick: 'No check was picked for it, so you judge it at Accept.',
|
|
97
|
+
itemCountByRule: 'your rule on this line sets the item count',
|
|
84
98
|
negated: 'it says what is not needed, so there is nothing to check',
|
|
85
99
|
dropped: 'You dropped it.',
|
|
86
100
|
suggested: 'Suggested: not in your job, so it is not checked unless you add it.',
|
|
101
|
+
sheetLine: 'this line reads a sheet and its rules are checked by the sheet checks, so a row edit about it is not used',
|
|
102
|
+
sheetFacts: 'this line reads a sheet, so it is checked by its sheet checks and not by page facts',
|
|
103
|
+
columnRule: "this rule only names a column; the agent's checks on this line use it",
|
|
87
104
|
});
|
|
88
105
|
|
|
89
|
-
/** the card
|
|
106
|
+
/** the card's rows: which rows show, and their key, line, tag, state and reason. NO words: the words of a row are the plan reader's (src/checkrows.js `planCard`), one writer (M19 am6 item 4). @param {Row[]} rows */
|
|
90
107
|
export function renderCard(rows) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (r.kind === 'rule') body = `"${r.text}"${r.pick && !sameRuleWords(r.text, plainWords(r.pick)) ? ` -> ${plainWords(r.pick)}` : ''}`;
|
|
94
|
-
else if (r.kind === 'count') body = `${CARD_T.count} ${r.min ?? ''}-${r.max ?? ''}`;
|
|
95
|
-
else if (r.kind === 'cited') body = `${CARD_T.cited} "${r.source ?? CARD_T.theInput}"`;
|
|
96
|
-
else if (r.kind === 'note') body = defaultNoteText(r.line);
|
|
97
|
-
else if (r.kind === 'numbers') body = `${CARD_T.numbers} ${(r.after ?? []).join(', ')}`;
|
|
98
|
-
else body = `${r.kind} "${r.name ?? r.words?.[0] ?? ''}"${(r.grown ?? r.words)?.length ? ` ${CARD_T.withWords} ${(r.grown ?? r.words).map((/** @type {string} */ w) => `"${w}"`).join(', ')}` : ''}`;
|
|
99
|
-
return { key: r.key, line: r.line, by: r.by, state: r.state, reason: r.reason ?? null, text: `${r.by === 'you' ? '~' : r.by === 'agent' ? '!' : '$'} ${body}` };
|
|
100
|
-
});
|
|
108
|
+
// fwd keeps: the card draws no floor row (and there is no prose row) today
|
|
109
|
+
return rows.filter((r) => r.kind !== 'floor' && r.state !== 'suggested' && r.state !== 'dropped' && !r.hidden).map((r) => ({ key: r.key, line: r.line, by: r.by, state: r.state, reason: r.reason ?? null }));
|
|
101
110
|
}
|
|
102
111
|
|
|
112
|
+
/**
|
|
113
|
+
* M19 am5: the fields a phrase fact is signed with: several different proved words sign as ONE any-of fact (`anyOf`, a quote holds any one, on word edges); one word signs `phrase`, exactly as before.
|
|
114
|
+
* @param {string[]} words the proved words @param {string} first the word used when there is one or none
|
|
115
|
+
* @returns {{shape: 'phrase', phrase: string} | {shape: 'phrase', anyOf: string[]}}
|
|
116
|
+
*/
|
|
117
|
+
const phraseSigned = (words, first) => {
|
|
118
|
+
const alts = [...new Set(words)];
|
|
119
|
+
return alts.length > 1 ? { shape: 'phrase', anyOf: alts } : { shape: 'phrase', phrase: alts[0] ?? first };
|
|
120
|
+
};
|
|
121
|
+
|
|
103
122
|
/**
|
|
104
123
|
* The facts a place fit builds (hamr 2026-11-11, plain split names): one value keeps the fact's own name; a version AND a date become TWO facts, "<name> version" and "<name> date", each with its
|
|
105
124
|
* own place rule. The words version, date and "and" leave the base name first, so "release version" is not named "release version version".
|
|
@@ -112,11 +131,27 @@ function placeFacts(name, strips, mk) {
|
|
|
112
131
|
return strips.map((s) => mk(nm(s.kind), { shape: 'phrase', phrase: s.value, place: s.rule }));
|
|
113
132
|
}
|
|
114
133
|
|
|
134
|
+
/**
|
|
135
|
+
* The Drop/Add choices of rows, tied to the line's words (not its number) and the row's own name, so a Revise keeps them. ONE owner for the block's own record and for a Drop made on a signed card.
|
|
136
|
+
* @param {{n: number, text: string}[]} lines @param {{line: number, key: string, choice: string}[]} picks @returns {{lineWords: string, occurrence: number, tail: string, choice: string}[]}
|
|
137
|
+
*/
|
|
138
|
+
export function choiceEntries(lines, picks) {
|
|
139
|
+
const seen = new Map();
|
|
140
|
+
const key = new Map(lines.map((l) => { const w = norm(l.text); const o = seen.get(w) ?? 0; seen.set(w, o + 1); return [l.n, { lineWords: w, occurrence: o }]; }));
|
|
141
|
+
return picks.map((p) => ({ ...(key.get(p.line) ?? { lineWords: '', occurrence: 0 }), tail: p.key.replace(/^L\d+\./, ''), choice: String(p.choice) }));
|
|
142
|
+
}
|
|
143
|
+
|
|
115
144
|
export class CheckBlock {
|
|
116
|
-
/** @param {{texts: Record<string, string>, labels: string[], maxTries?: number, countScope?: (ruleText: string) => boolean, asks?: boolean, split?: boolean, cited?: boolean}} o the frozen input texts, their labels, how many AI replies (tries) may still change a row, whether code scopes a counting `~` rule in (a pick is asked), and whether a person can be asked at all (`asks`: false = a rule code cannot settle is Not checked, a reading code proposes is built as the AI's proposal) */
|
|
117
|
-
constructor({ texts, labels, maxTries = 3, countScope = () => true, asks = true, split = false, cited = true }) {
|
|
145
|
+
/** @param {{texts: Record<string, string>, labels: string[], maxTries?: number, countScope?: (ruleText: string) => boolean, asks?: boolean, split?: boolean, cited?: boolean, repo?: {files: string[]|null, writeScope: string[]|null}|null}} o the frozen input texts, their labels, how many AI replies (tries) may still change a row, whether code scopes a counting `~` rule in (a pick is asked), and whether a person can be asked at all (`asks`: false = a rule code cannot settle is Not checked, a reading code proposes is built as the AI's proposal) */
|
|
146
|
+
constructor({ texts, labels, maxTries = 3, countScope = () => true, asks = true, split = false, cited = true, repo = null }) {
|
|
118
147
|
// M16 am1: `cited: false` = no `$` cited default row on this job's lines (fwd's own quote checks stay as they are); the `$` floor stays
|
|
119
148
|
this.cited = cited;
|
|
149
|
+
/** a repo job's check TYPE (the only thing that varies): `files` = the repo listing at the seed (null until it is read), `writeScope` = the signed write fence. Null = a rubric job @type {{files: string[]|null, writeScope: string[]|null}|null} */
|
|
150
|
+
this.repo = repo;
|
|
151
|
+
/** @type {any[]} a repo job's drafted stages as the drafter wrote them (guards included); the rows of the work stages are in `rows`, the close's stages are these minus the dropped ones */
|
|
152
|
+
this.declared = [];
|
|
153
|
+
/** the job lines a mandatory guard already covers (`guardLines`): a repo stage is never dropped when it is the last thing covering a line @type {Set<number>} */
|
|
154
|
+
this.guardCover = new Set();
|
|
120
155
|
/** the product path sets it: `!` rows split into job-derived and suggested, a suggestion code cannot build is hidden (hamr 2026-11-13). Off, every `!` row is built as before (the older callers and their tests) */
|
|
121
156
|
this.split = split;
|
|
122
157
|
this.countScope = countScope;
|
|
@@ -145,6 +180,166 @@ export class CheckBlock {
|
|
|
145
180
|
this.closeCache = null;
|
|
146
181
|
/** @type {Map<number, 'yes'|'no'|'failed'>} the note question's answer per facts-only line (src/noteask.js; code decides what it means) */
|
|
147
182
|
this.notes = new Map();
|
|
183
|
+
/** @type {string[]} the NAMES of the mandatory guards the close carries (Addendum 2026-11-14 (c) piece 2): each is a job-level `$` row of the signed list, never a row of `rows` (no line, so no check of a line) */
|
|
184
|
+
this.guards = [];
|
|
185
|
+
/** @type {string[]|null} the write fence of the job: a job-level `$` row of the signed list (hamr 2026-11-15), never a row of `rows` */
|
|
186
|
+
this.fence = null;
|
|
187
|
+
/** S4: the job lines that read a sheet (a CSV input and a `~` rule): every rule of such a line is decided by the sheet checks alone, never by the page path (`src/sheetrows.js` `sheetLineNumbers`) @type {Set<number>} */
|
|
188
|
+
this.sheetLines = new Set();
|
|
189
|
+
/** S4: what code built from the AI's `sheetChecks` (src/sheetbuild.js `buildSheetChecks`), null until the row-edit turn has answered @type {SheetBuilt|null} */
|
|
190
|
+
this.sheetBuilt = null;
|
|
191
|
+
/** shape jobs (clause 4): what code built from the AI's `itemShape` (src/shapebuild.js `buildShapes`), null until the row-edit turn has answered. A line in `built` is a SHAPE line: a line is exactly one class, facts, sheet or shape @type {ReturnType<typeof import('./shapebuild.js').buildShapes>|null} */
|
|
192
|
+
this.shapeBuilt = null;
|
|
193
|
+
/** shape jobs: the Drops the person made, kept beside the rows (`agent` = `<line>:<field name>`, `rules` = `<line>:<rule number>`) @type {{agent: Set<string>, rules: Set<string>}} */
|
|
194
|
+
this.shapeDrops = { agent: new Set(), rules: new Set() };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** the mandatory guards of this job's class, by name: signedRows() adds one `$` guard row for each, once for the whole job @param {string[]} names @param {string[]|null} [fence] the signed write fence, when the job has one */
|
|
198
|
+
setGuards(names, fence = null) { this.guards = [...new Set(names)]; this.fence = Array.isArray(fence) && fence.length ? [...fence] : null; }
|
|
199
|
+
|
|
200
|
+
/** S4: the job lines that read a sheet. Their rules are decided by the sheet checks alone (no page path, no pick question, no row edit), from here on @param {number[]} nums */
|
|
201
|
+
setSheetLines(nums) { this.sheetLines = new Set(nums); }
|
|
202
|
+
/** @param {number} n */
|
|
203
|
+
isSheetLine(n) { return this.sheetLines.has(n); }
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* S4: the checks code built from the AI's `sheetChecks` become rows of the one list: an `[agent]` row for each check that is no rule row's. A `[you]` row is the `~` rule's own row (its state comes from the sheet,
|
|
207
|
+
* `matchSheetRule`). A Drop the person made on a check is kept for the same check (same typed fields) when the checks are built again; every row is reconciled.
|
|
208
|
+
* fwd keeps: no `[default]` sheet row (the tag adds one per sheet line, bareloop S4); fwd's list has none (M16 am4 (2): "a `[default]` sheet check does not exist").
|
|
209
|
+
* @param {SheetBuilt} built
|
|
210
|
+
*/
|
|
211
|
+
setSheet(built) {
|
|
212
|
+
const dropped = this.rows.filter((r) => r.kind === 'sheet' && r.by === 'agent' && r.choice === 'drop').map((r) => ({ line: r.line, body: sheetCheckBody(r.check) }));
|
|
213
|
+
this.sheetBuilt = built;
|
|
214
|
+
this.rows = this.rows.filter((r) => r.kind !== 'sheet');
|
|
215
|
+
for (const n of this.sheetLines) {
|
|
216
|
+
const b = built.built[n];
|
|
217
|
+
if (!b) continue;
|
|
218
|
+
for (const p of b.agentRows) {
|
|
219
|
+
const row = this.addRow({ key: sheetRowKey(n, p.check.id), line: n, kind: 'sheet', by: 'agent', from: 'agent', check: p.check });
|
|
220
|
+
if (dropped.some((d) => d.line === n && isDeepStrictEqual(d.body, sheetCheckBody(p.check)))) row.choice = 'drop';
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
this.reconcile();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** shape jobs, rules first: does job line `n` hold a rule that took its shape field (no truth check could take it)? Only such a line carries shape rows and a shape part @param {number} n */
|
|
227
|
+
isShapeLine(n) { return !this.isSheetLine(n) && this.rows.some((r) => r.kind === 'rule' && r.line === n && r.can?.how === 'shape'); }
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Shape jobs, rules first (hamr 2026-11-19): remember the shape code built from the shape look (src/shapebuild.js `buildShapes`). It decides nothing by itself: `matchRule` tries every rule's truth check (fact, cite, count, phrase, pick) FIRST,
|
|
231
|
+
* and a rule that ends with none and no open ask may take its shape field (`takesShape`). A line where no rule did has no shape rows at all (`syncShapeRows`), so a page job's rows stay as they were. A Drop the person made
|
|
232
|
+
* (an `[agent]` field, or a rule's own shape field) is kept for the same field when the shape is built again. Every row is reconciled.
|
|
233
|
+
* @param {ReturnType<typeof import('./shapebuild.js').buildShapes>} built
|
|
234
|
+
*/
|
|
235
|
+
setShape(built) {
|
|
236
|
+
this.keepShapeDrops();
|
|
237
|
+
this.shapeBuilt = built;
|
|
238
|
+
this.reconcile();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** the Drops the shape rows carry now, remembered beside the rows (a row can leave the list and come back) */
|
|
242
|
+
keepShapeDrops() {
|
|
243
|
+
for (const r of this.rows) {
|
|
244
|
+
if (r.kind === 'shape' && r.by === 'agent' && r.choice === 'drop' && r.field?.name !== undefined) this.shapeDrops.agent.add(`${r.line}:${r.field.name}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Rules first: may this rule, which no truth check could take, take the shape field the shape look proposed for it? Its own `[you]` row then carries the field. Null when it may not (no shape, a sheet or repo job, no field for the rule).
|
|
250
|
+
* @param {Row} r @returns {{name: string}|null}
|
|
251
|
+
*/
|
|
252
|
+
takesShape(r) {
|
|
253
|
+
// a rule code marks as negating says what is NOT needed: it stays with the person (NEGATING_RE, the old ruling), never a shape field ("no nonstop" must not become nonstop = false)
|
|
254
|
+
if (this.repo !== null || r.kind !== 'rule' || this.isSheetLine(r.line) || NEGATING_RE.test(String(r.text))) return null;
|
|
255
|
+
const rs = this.shapeBuilt?.built[r.line]?.rows.find((x) => x.rule === r.rule && x.text === r.text);
|
|
256
|
+
return rs && rs.state === 'built' && typeof rs.name === 'string' ? { name: rs.name } : null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The rules that are still Not checked once every truth check, the person's answers and the pending asks are settled, and that may still take a shape field (not a sheet or repo job, not left or negating by the person's words):
|
|
261
|
+
* the ONLY rules the shape look is asked about, and only when there is one. Call after `reconcile`.
|
|
262
|
+
* @returns {{line: number, rule: number}[]}
|
|
263
|
+
*/
|
|
264
|
+
shapeCandidates() {
|
|
265
|
+
if (this.repo !== null) return [];
|
|
266
|
+
return this.rows.filter((r) => r.kind === 'rule' && !r.left && (!r.can?.ok || r.truthRefused) && !r.can?.ask && !this.isSheetLine(r.line) && !NEGATING_RE.test(String(r.text))).map((r) => ({ line: r.line, rule: Number(r.rule) }));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Shape rows live only on a line where a rule took its shape field: its `[agent]` extra fields (job-derived on, no-word Suggested) and its `$` count row are added there, and removed from any line where none did.
|
|
271
|
+
* Called after the rules are matched.
|
|
272
|
+
*/
|
|
273
|
+
syncShapeRows() {
|
|
274
|
+
const built = this.shapeBuilt?.built ?? {};
|
|
275
|
+
for (const [k, b] of Object.entries(built)) {
|
|
276
|
+
const n = Number(k);
|
|
277
|
+
const live = this.isShapeLine(n);
|
|
278
|
+
const have = this.rows.filter((r) => r.kind === 'shape' && r.line === n);
|
|
279
|
+
if (!live) { if (have.length) { this.keepShapeDrops(); this.rows = this.rows.filter((r) => !(r.kind === 'shape' && r.line === n)); } continue; }
|
|
280
|
+
for (const f of b.fields.filter((x) => x.by === 'agent')) {
|
|
281
|
+
if (have.some((r) => r.key === shapeRowKey(n, f.name))) continue;
|
|
282
|
+
const row = this.addRow({ key: shapeRowKey(n, f.name), line: n, kind: 'shape', by: 'agent', from: 'agent', field: f, state: 'not-checked', reason: 'not yet matched' });
|
|
283
|
+
if (this.shapeDrops.agent.has(`${n}:${f.name}`)) row.choice = 'drop';
|
|
284
|
+
}
|
|
285
|
+
if (b.itemCount && !have.some((r) => r.key === shapeDefaultKey(n))) this.addRow({ key: shapeDefaultKey(n), line: n, kind: 'shape', by: 'default', from: 'default', state: 'not-checked', reason: 'not yet matched' });
|
|
286
|
+
}
|
|
287
|
+
// a line the shape look built nothing for keeps no shape rows
|
|
288
|
+
this.rows = this.rows.filter((r) => !(r.kind === 'shape' && built[r.line] === undefined));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** the dropped shape fields the record keeps, tied to the line's words (not its number): an `[agent]` field by its name, a rule's own shape field by its rule number @returns {{lineWords: string, occurrence: number, name?: string, rule?: number}[]} */
|
|
292
|
+
shapeDroppedRecord() {
|
|
293
|
+
this.keepShapeDrops();
|
|
294
|
+
const keys = this.lineWordKeys();
|
|
295
|
+
const at = (/** @type {number} */ n) => keys.get(n) ?? { lineWords: '', occurrence: 0 };
|
|
296
|
+
return [
|
|
297
|
+
...[...this.shapeDrops.agent].map((x) => { const i = x.indexOf(':'); return { n: Number(x.slice(0, i)), name: x.slice(i + 1) }; }).filter((d) => this.lines.some((l) => l.n === d.n)).map((d) => ({ ...at(d.n), name: d.name })),
|
|
298
|
+
...[...this.shapeDrops.rules].map((x) => { const [n, rule] = x.split(':').map(Number); return { ...at(n), rule }; }).filter((d) => d.lineWords !== ''),
|
|
299
|
+
];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** a Revise keeps a Drop of the very same field (same line words, same name or rule number); a field this draft did not build is not dropped @param {{lineWords: string, occurrence: number, name?: string, rule?: number}[]} rec */
|
|
303
|
+
carryShapeDropped(rec) {
|
|
304
|
+
const keys = this.lineWordKeys();
|
|
305
|
+
for (const d of Array.isArray(rec) ? rec : []) {
|
|
306
|
+
if (!d || typeof d.lineWords !== 'string' || !Number.isInteger(d.occurrence)) continue;
|
|
307
|
+
const n = [...keys].find(([, k]) => k.lineWords === d.lineWords && k.occurrence === d.occurrence)?.[0];
|
|
308
|
+
if (n === undefined) continue;
|
|
309
|
+
if (typeof d.name === 'string') {
|
|
310
|
+
this.shapeDrops.agent.add(`${n}:${d.name}`);
|
|
311
|
+
const row = this.rows.find((r) => r.kind === 'shape' && r.by === 'agent' && r.line === n && r.field?.name === d.name);
|
|
312
|
+
if (row) { row.choice = 'drop'; row.keptFromLast = true; }
|
|
313
|
+
} else if (Number.isInteger(d.rule)) this.shapeDrops.rules.add(`${n}:${d.rule}`);
|
|
314
|
+
}
|
|
315
|
+
this.reconcile();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The dropped sheet checks the record keeps, as fwd's picks record has always written them (`{key, line, index, check, text}`, M17 am3): `index` is the check's place among its line's checks, `check` the check as built.
|
|
320
|
+
* fwd keeps this record shape (the tag ties each entry to the line's words instead, `{lineWords, occurrence, check, text}`): the record is a file of the plan folder, and a draft saved before this carries the old shape.
|
|
321
|
+
* @returns {{key: string, line: number, index: number, check: Record<string, any>, text: string}[]}
|
|
322
|
+
*/
|
|
323
|
+
sheetDroppedRecord() {
|
|
324
|
+
return this.rows.filter((r) => r.kind === 'sheet' && r.by === 'agent' && r.choice === 'drop').map((r) => ({
|
|
325
|
+
key: r.key, line: r.line, index: Math.max(0, (this.sheetBuilt?.built[r.line]?.checks ?? []).findIndex((/** @type {any} */ c) => c.id === r.check.id)), check: r.check, text: String(r.offer?.text ?? ''),
|
|
326
|
+
}));
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** a Revise keeps a Drop of the very same check: the record's entries, matched on the line and the check's own fields (never its id: code names every check); a check this draft did not build is not dropped @param {{line: number, check: Record<string, any>}[]} rec */
|
|
330
|
+
carrySheetDropped(rec) {
|
|
331
|
+
for (const d of Array.isArray(rec) ? rec : []) {
|
|
332
|
+
if (!d || !Number.isInteger(d.line) || !isRec(d.check)) continue;
|
|
333
|
+
const row = this.rows.find((r) => r.kind === 'sheet' && r.by === 'agent' && r.line === d.line && isDeepStrictEqual(sheetCheckBody(r.check), sheetCheckBody(d.check)));
|
|
334
|
+
if (row) row.choice = 'drop';
|
|
335
|
+
}
|
|
336
|
+
this.reconcile();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** each job line's words and its order among equal lines (the key a record ties a choice to) @returns {Map<number, {lineWords: string, occurrence: number}>} */
|
|
340
|
+
lineWordKeys() {
|
|
341
|
+
const seen = new Map();
|
|
342
|
+
return new Map(this.lines.map((l) => { const w = norm(l.text); const o = seen.get(w) ?? 0; seen.set(w, o + 1); return [l.n, { lineWords: w, occurrence: o }]; }));
|
|
148
343
|
}
|
|
149
344
|
|
|
150
345
|
textOf(/** @type {string|undefined} */ source) { return this.texts[source ?? this.labels[0] ?? ''] ?? Object.values(this.texts)[0] ?? ''; }
|
|
@@ -169,7 +364,7 @@ export class CheckBlock {
|
|
|
169
364
|
for (const l of jobLines) {
|
|
170
365
|
this.lines.push({ n: l.n, text: l.text });
|
|
171
366
|
(l.rules ?? []).forEach((t, i) => this.addRow({ key: `L${l.n}.~${i + 1}`, line: l.n, kind: 'rule', by: 'you', from: 'rule', origin: 'job', text: t, rule: i + 1 }));
|
|
172
|
-
this.addRow({ key: `L${l.n}.$floor`, line: l.n, kind: 'floor', by: 'default', from: 'default', state: 'built', reason: null, text: "the file exists and its text is not empty (code's own floor)" });
|
|
367
|
+
if (this.repo === null) this.addRow({ key: `L${l.n}.$floor`, line: l.n, kind: 'floor', by: 'default', from: 'default', state: 'built', reason: null, text: "the file exists and its text is not empty (code's own floor)" });
|
|
173
368
|
}
|
|
174
369
|
}
|
|
175
370
|
|
|
@@ -198,6 +393,19 @@ export class CheckBlock {
|
|
|
198
393
|
}
|
|
199
394
|
}
|
|
200
395
|
|
|
396
|
+
/**
|
|
397
|
+
* S1 (the sheet look, src/sheetlook.js): a `~` rule whose word is no column of its CSV carries ONE column question. Agree writes `reading` (the rule's own words with the column in place of the word) as the rule's words,
|
|
398
|
+
* through the same one-rule-in, one-rule-out answer as any reading (`applyAnswer`); no line is added. Code builds the question; nothing here reads a model field.
|
|
399
|
+
* A tie (`columns`, `readings`: the rule's words for each tied column) has no single reading: the person picks a column (`applyAnswer` `column`) and the rule is that column's reading.
|
|
400
|
+
* @param {{line: number, rule: number|null, question: string, reading?: string, columns?: string[], readings?: Record<string, string>}[]} asks
|
|
401
|
+
*/
|
|
402
|
+
addSheetAsks(asks) {
|
|
403
|
+
for (const a of asks) {
|
|
404
|
+
const r = a.rule === null ? undefined : this.ruleRows(a.line).find((x) => x.rule === a.rule);
|
|
405
|
+
if (r) r.sheetAsk = { ruleText: r.text, question: a.question, proposal: a.reading ?? null, ...(Array.isArray(a.columns) ? { columns: [...a.columns], readings: { ...a.readings } } : {}) };
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
201
409
|
// 3. can code check it on the saved page? Never the AI. `row.can` = {ok, how, ...} or {ok:false, why} or {ok:false, ask, ...}
|
|
202
410
|
match() {
|
|
203
411
|
// live draft 3 (hamr 2026-11-13: "anything not in your original job that code can check goes to Suggested"): a `!` fact whose page words are longer than what the job says ("Boston Logan International
|
|
@@ -208,10 +416,13 @@ export class CheckBlock {
|
|
|
208
416
|
if (r.kind === 'floor') continue;
|
|
209
417
|
if (r.left) r.can = { ok: false, why: REASON.left };
|
|
210
418
|
else if (r.lookWhy && r.kind === 'fact' && !r.words.length) r.can = { ok: false, why: r.lookWhy };
|
|
419
|
+
else if (r.kind === 'stage') r.can = r.refusal ? { ok: false, why: r.said } : { ok: true, how: 'stage' };
|
|
211
420
|
else if (r.kind === 'rule') this.matchRule(r);
|
|
212
421
|
else if (r.kind === 'fact' || r.kind === 'phrase') this.matchBang(r);
|
|
213
422
|
else if (r.kind === 'count') this.matchCount(r);
|
|
423
|
+
else if (r.kind === 'sheet') r.can = { ok: true, how: 'sheet' };
|
|
214
424
|
}
|
|
425
|
+
this.takeItemCounts();
|
|
215
426
|
// N-1 (hamr 2026-11-13): code splits the `!` rows. Words (or the count number) in the job line or its ~ rules = JOB-DERIVED (built, Drop). Not in the job = SUGGESTED: held out of the close, offered
|
|
216
427
|
// only when code has already proved it can build it (build() trials it), and switched on by the person's Add. The person's Drop removes a row for good. Never the AI.
|
|
217
428
|
for (const r of this.split ? this.rows : []) {
|
|
@@ -221,6 +432,18 @@ export class CheckBlock {
|
|
|
221
432
|
// a Drop is undone through Suggested (live draft 3): the row was proved buildable, so it is offered again with Add; only a row code can still build is offered
|
|
222
433
|
if (r.can?.ok && r.choice !== 'add' && (!r.derived || r.choice === 'drop')) r.held = true;
|
|
223
434
|
}
|
|
435
|
+
// shape rows live only on a line where a rule took its shape field (rules first): added or removed now that the rules are matched; their own state is set below
|
|
436
|
+
this.syncShapeRows();
|
|
437
|
+
for (const r of this.rows) if (r.kind === 'shape') r.can = { ok: true, how: 'shape' };
|
|
438
|
+
// S4: an `[agent]` sheet row the person dropped is held out of the close and offered again under Suggested (Add); it is code's own check, already built, so no trial is needed
|
|
439
|
+
// shape jobs: an `[agent]` field the person dropped, or one with no word of the job (R2), is held out of the close and offered under Suggested (Add); it is code's own field, already built, so no trial is needed
|
|
440
|
+
for (const r of this.rows) if (r.kind === 'shape' && r.by === 'agent') { r.held = r.choice === 'drop' || (r.field?.held === true && r.choice !== 'add'); r.offer = { text: shapeFieldText({ name: r.field.name, spec: fieldSpec(r.field), rule: null }, []) }; }
|
|
441
|
+
for (const r of this.rows) if (r.kind === 'sheet' && r.by === 'agent') { r.held = r.choice === 'drop'; r.offer = { text: sheetPlainText(sheetCheckName(r.check), sheetCheckSentence(r.check), coversWords(this.coverTexts(r))) }; }
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** the person's own words of the rules an `[agent]` sheet row shows (its `covers`) @param {Row} r @returns {string[]} */
|
|
445
|
+
coverTexts(r) {
|
|
446
|
+
return (Array.isArray(r.check?.covers) ? r.check.covers : []).map((/** @type {number} */ n) => this.ruleRows(r.line).find((x) => x.rule === n)?.text).filter((/** @type {unknown} */ t) => typeof t === 'string');
|
|
224
447
|
}
|
|
225
448
|
|
|
226
449
|
/** a `!` row: the agent's fact, phrase or count (a look fact tied to a rule is a link on that rule's row, never a row of its own) */
|
|
@@ -244,12 +467,26 @@ export class CheckBlock {
|
|
|
244
467
|
inJob(/** @type {Row} */ r) {
|
|
245
468
|
const said = this.said(r.line);
|
|
246
469
|
if (r.kind === 'count') return [r.min, r.max].filter((x) => Number.isInteger(x)).some((n) => numberIn(said, n));
|
|
247
|
-
// a fact the person asked for BY NAME ("the release heading") is in the job too: the look's page words rarely echo the job's own words
|
|
248
|
-
//
|
|
249
|
-
// A phrase or place is job-derived only when its own words are in the person's text: a name the AI gave it is no proof (hamr 2026-11-15, live run mwi76vh8: "friendly" for "Select flight")
|
|
470
|
+
// a money, time, number or date fact the person asked for BY NAME ("the release heading") is in the job too: the look's page words rarely echo the job's own words. A phrase or place is job-derived
|
|
471
|
+
// only when its own words are in the person's text: a name the AI gave it is no proof (hamr 2026-11-15, live run mwi76vh8: "friendly" for "Select flight")
|
|
250
472
|
return (r.words ?? []).some((/** @type {string} */ w) => inText(said, w)) || (r.kind === 'fact' && r.shape !== 'phrase' && r.shape !== 'place' && typeof r.name === 'string' && inText(said, r.name));
|
|
251
473
|
}
|
|
252
474
|
|
|
475
|
+
/**
|
|
476
|
+
* M19 am11 item 1: on a line with item fields (a shape line), a `~` rule that counts list items is the shape part's own item count, not a count pick over `text`. Run after every rule is matched, so the order of the rules does not matter.
|
|
477
|
+
* The ONE writer of such a row's `can` and of its `from` (it is the person's rule again, not a pick). A text line, a sheet line and a repo line are unchanged. A Drop of the rule is kept (`shapeDrops.rules`).
|
|
478
|
+
*/
|
|
479
|
+
takeItemCounts() {
|
|
480
|
+
if (this.repo !== null) return;
|
|
481
|
+
for (const r of this.rows) {
|
|
482
|
+
if (r.kind !== 'rule' || r.left || r.can?.how === 'shape' || this.isSheetLine(r.line) || NEGATING_RE.test(String(r.text)) || !this.isShapeLine(r.line)) continue;
|
|
483
|
+
const count = itemCountOf(String(r.text));
|
|
484
|
+
if (count === null) continue;
|
|
485
|
+
r.can = this.shapeDrops.rules.has(`${r.line}:${r.rule}`) ? { ok: false, why: REASON.dropped } : { ok: true, how: 'shape', count };
|
|
486
|
+
if (r.can.ok) r.from = 'rule';
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
253
490
|
/** a `!` count row is built unless a `~` rule on its line already names the number */
|
|
254
491
|
matchCount(/** @type {Row} */ r) {
|
|
255
492
|
const nums = [r.min, r.max].filter((x) => Number.isInteger(x)).map(String);
|
|
@@ -257,7 +494,21 @@ export class CheckBlock {
|
|
|
257
494
|
r.can = said ? { ok: false, why: `a ~ rule already says it: line ${r.line} rule ${said.rule} names the number` } : { ok: true, how: 'count' };
|
|
258
495
|
}
|
|
259
496
|
|
|
260
|
-
|
|
497
|
+
/** RULES FIRST (hamr 2026-11-19): today's truth check for the rule; only a rule that ends with none and no open ask takes the shape field proposed for it (the strongest check wins, no ask) @param {Row} r */
|
|
498
|
+
matchRule(r) {
|
|
499
|
+
this.matchTruthRule(r);
|
|
500
|
+
// a truth check code picked but REFUSED when it built the line (live mwnbs3np: 4 results, a title said once) is no check: the rule is still Not checked, so it may take its shape field (hamr: shape for what code could not check)
|
|
501
|
+
if (r.can?.ask || (r.can?.ok && !r.truthRefused)) return;
|
|
502
|
+
const sh = this.takesShape(r);
|
|
503
|
+
if (sh === null) return;
|
|
504
|
+
r.can = this.shapeDrops.rules.has(`${r.line}:${r.rule}`) ? { ok: false, why: REASON.dropped } : { ok: true, how: 'shape', name: sh.name };
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
matchTruthRule(/** @type {Row} */ r) {
|
|
508
|
+
if (this.repo !== null) { this.matchRepoRule(r); return; }
|
|
509
|
+
// S1: the sheet look's column question, while the rule still says the words it was asked about (an answered, dropped or retyped rule is not asked again)
|
|
510
|
+
if (r.sheetAsk && this.asks && !r.agreed && !r.left && r.text === r.sheetAsk.ruleText) { r.can = { ok: false, ask: 'reading', proposal: r.sheetAsk.proposal, question: r.sheetAsk.question, ...(r.sheetAsk.columns ? { columns: r.sheetAsk.columns, readings: r.sheetAsk.readings } : {}), why: REASON.waitingReading }; return; }
|
|
511
|
+
if (this.isSheetLine(r.line)) { this.matchSheetRule(r); return; }
|
|
261
512
|
if (isCountable(r.text)) { this.matchCountRule(r); return; }
|
|
262
513
|
// F-a (hamr 2026-11-13): a rule that carries a negation ("nonstop is not mandatory") says what is NOT needed; its words can never give a phrase bound ("must say"). The one negation reader is NEGATING_RE.
|
|
263
514
|
const negated = NEGATING_RE.test(r.text);
|
|
@@ -305,14 +556,30 @@ export class CheckBlock {
|
|
|
305
556
|
}
|
|
306
557
|
if (otherCurrency) { r.can = { ok: false, why: `the amount in your rule is in another currency than the page's prices, so it is not checked.` }; return; }
|
|
307
558
|
if (r.links?.length && !links.length) { r.can = { ok: false, why: REASON.lookNoWords }; return; }
|
|
308
|
-
if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: r.aiReason ?? r.lookWhy ?? REASON.
|
|
559
|
+
if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: r.aiReason ?? r.lookWhy ?? REASON.noPick }; return; }
|
|
309
560
|
if (r.links?.length) { r.can = { ok: false, why: r.aiReason ?? `the look tied a fact to this rule but gave no limit, and ${ownWhy ? `in your words ${ownWhy}` : 'your own words give none code can read'}, so you judge it at Accept.` }; return; }
|
|
310
|
-
|
|
561
|
+
// borrowed-from: bareloop src/checkblock.js@v0.61.0 (fc56e1f3) (M19 am3: a rule no check can prove is Not checked at once, never asked; the shape look can take it)
|
|
562
|
+
r.can = { ok: false, why: r.lookWhy ?? REASON.noPick };
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* S4: a `~` rule of a sheet line. The sheet checks code built decide it, and nothing else does (ONE owner: a rule has never two rows): built = this rule's own `[you]` row carries the check; an `[agent]` row that shows it carries it
|
|
567
|
+
* (and a Drop of that row leaves the rule Not checked); a table check only named it, a refusal, or nothing picked = Not checked with that plain reason. Before the AI's turn has answered, nothing is picked yet.
|
|
568
|
+
* @param {Row} r
|
|
569
|
+
*/
|
|
570
|
+
matchSheetRule(r) {
|
|
571
|
+
const b = this.sheetBuilt?.built[r.line];
|
|
572
|
+
const rs = b?.rows.find((x) => x.rule === r.rule && x.text === r.text);
|
|
573
|
+
if (!rs) { r.can = { ok: false, why: r.lookWhy ?? REASON.noPick }; return; }
|
|
574
|
+
if (rs.state === 'built') r.can = { ok: true, how: 'sheet', id: rs.id };
|
|
575
|
+
else if (rs.state === 'agent-row') r.can = this.rows.some((x) => x.kind === 'sheet' && x.line === r.line && x.check?.id === rs.id && x.choice === 'drop') ? { ok: false, why: REASON.dropped } : { ok: true, how: 'sheet', id: rs.id };
|
|
576
|
+
else if (rs.state === 'column') r.can = { ok: false, why: REASON.columnRule };
|
|
577
|
+
else r.can = { ok: false, why: rs.reason === REASON.noPick ? (r.lookWhy ?? REASON.noPick) : String(rs.reason) };
|
|
311
578
|
}
|
|
312
579
|
|
|
313
580
|
/** a `~` rule that counts words, bullets, lines or sections: a settled pick builds it; else code proposes the check and asks */
|
|
314
581
|
matchCountRule(/** @type {Row} */ r) {
|
|
315
|
-
if (!r.pick && (r.cantAsked || !this.countScope(r.text))) { r.can = { ok: false, why: r.aiReason ?? REASON.
|
|
582
|
+
if (!r.pick && (r.cantAsked || !this.countScope(r.text))) { r.can = { ok: false, why: r.aiReason ?? REASON.noPick }; return; }
|
|
316
583
|
if (r.pick) { r.can = { ok: true, how: 'pick' }; return; }
|
|
317
584
|
// no obvious asks (hamr 2026-11-14): a rule whose words ARE the check ("exactly 3 list items") is settled as it stands, so a replaced rule never re-asks on a re-draft or a Reuse
|
|
318
585
|
const obvious = obviousCheck(r.text);
|
|
@@ -321,9 +588,10 @@ export class CheckBlock {
|
|
|
321
588
|
if (res.kept) { r.pick = res.check; r.from = 'pick'; r.can = { ok: true, how: 'pick' }; return; }
|
|
322
589
|
}
|
|
323
590
|
const proposal = r.pickProposal ?? countCheck(r.text);
|
|
324
|
-
if (!this.asks) r.can = { ok: false, why: REASON.
|
|
591
|
+
if (!this.asks) r.can = { ok: false, why: REASON.noPick };
|
|
325
592
|
else if (proposal) r.can = { ok: false, ask: 'check', proposal, why: REASON.waitingPick };
|
|
326
|
-
|
|
593
|
+
// borrowed-from: bareloop src/checkblock.js@v0.61.0 (fc56e1f3) (M19 am3: no count proposal is Not checked at once, never asked)
|
|
594
|
+
else r.can = { ok: false, why: REASON.noPick };
|
|
327
595
|
}
|
|
328
596
|
|
|
329
597
|
/** a `!` fact or phrase row: its words must be on the page; a version or a date is true only today, so only a place rule's fit may carry it */
|
|
@@ -354,6 +622,7 @@ export class CheckBlock {
|
|
|
354
622
|
|
|
355
623
|
// 4. code makes every check from the rows; a row it cannot build keeps its place with its plain reason. Returns the close's stages, parts and the row map.
|
|
356
624
|
build() {
|
|
625
|
+
if (this.repo !== null) return this.buildRepo();
|
|
357
626
|
/** @type {any[]} */ const stages = [];
|
|
358
627
|
/** @type {any[]} */ const parts = [];
|
|
359
628
|
/** @type {{part: number, line: number, rows: string[], origin: string}[]} */ const map = [];
|
|
@@ -363,6 +632,11 @@ export class CheckBlock {
|
|
|
363
632
|
/** @type {string[][]} */ const lineRows = [];
|
|
364
633
|
this.buildLine(l, lineParts, lineRows, factLines);
|
|
365
634
|
if (lineParts.length) stages.push({ name: `line-${l.n}`, kind: 'rubric-step', fromLine: [l.n], params: { step: l.n, parts: lineParts } });
|
|
635
|
+
// fwd keeps: no `carriesText` on the floor row and no `$prose` row (the tag sets the first for the card's floor words and adds the second for each text line; fwd's card draws neither today, and the v0.56.0 parity
|
|
636
|
+
// test (test/m16-block-parity.test.js) holds the rows as they are; M19 S6 draws the floor row and brings both)
|
|
637
|
+
// only a shape line's floor row carries the flag: every other row stays byte-identical to what it was
|
|
638
|
+
const hasShape = lineParts.some((p) => p.class === 'shape');
|
|
639
|
+
for (const f of this.rowsOn(l.n, 'floor')) { if (hasShape && !lineParts.some((p) => p.class === 'fact') && !lineParts.some((p) => p.class === 'countable')) f.listLine = true; else delete f.listLine; }
|
|
366
640
|
lineParts.forEach((p, i) => {
|
|
367
641
|
for (const k of lineRows[i] ?? []) { const row = this.rows.find((x) => x.key === k); if (row) row.part = { line: l.n, part: i }; }
|
|
368
642
|
map.push({ part: parts.length, line: l.n, rows: lineRows[i] ?? [], origin: 'code' });
|
|
@@ -370,8 +644,8 @@ export class CheckBlock {
|
|
|
370
644
|
});
|
|
371
645
|
}
|
|
372
646
|
// a suggestion code has not built stays off the card (Audit only, F-b); a held one is trialled: shown under Suggested only when code has proved it builds (hamr 2026-11-13)
|
|
373
|
-
for (const r of this.rows.filter((x) => x.held)) this.trialOffer(r);
|
|
374
|
-
if (this.split) for (const r of this.rows) r.hidden = this.isBang(r) && r.state === 'not-checked' && !r.lookWhy;
|
|
647
|
+
for (const r of this.rows.filter((x) => x.held && x.kind !== 'sheet' && x.kind !== 'shape')) this.trialOffer(r);
|
|
648
|
+
if (this.split) for (const r of this.rows) r.hidden = this.isBang(r) && r.state === 'not-checked' && !r.lookWhy && r.reason !== NO_GUARDRAIL_WORDS;
|
|
375
649
|
this.closeCache = { stages, parts, map };
|
|
376
650
|
return this.closeCache;
|
|
377
651
|
}
|
|
@@ -385,7 +659,7 @@ export class CheckBlock {
|
|
|
385
659
|
r.held = false;
|
|
386
660
|
/** @type {any[]} */ const parts = [];
|
|
387
661
|
/** @type {string[][]} */ const rows = [];
|
|
388
|
-
this.buildLine(l, parts, rows, new Set());
|
|
662
|
+
this.buildLine(l, parts, rows, new Set(), true);
|
|
389
663
|
const ok = r.state === 'built';
|
|
390
664
|
const reason = r.reason;
|
|
391
665
|
const i = rows.findIndex((k) => k.includes(r.key));
|
|
@@ -398,20 +672,31 @@ export class CheckBlock {
|
|
|
398
672
|
else { r.offer = null; r.held = false; r.state = 'not-checked'; r.reason = String(reason ?? 'not checked'); }
|
|
399
673
|
}
|
|
400
674
|
|
|
675
|
+
// fwd (F251): `offer` = the Suggested trial (trialOffer): it asks whether code can build the row, not whether the line can sign it, so the no-guardrail gate below is skipped
|
|
401
676
|
/** one line's parts: a pick part per count rule, ONE fact part carrying every fact row of the line (and its result count), then the `$` defaults */
|
|
402
|
-
buildLine(/** @type {{n: number, text: string}} */ l, /** @type {any[]} */ lineParts, /** @type {string[][]} */ lineRows, /** @type {Set<number>} */ factLines) {
|
|
677
|
+
buildLine(/** @type {{n: number, text: string}} */ l, /** @type {any[]} */ lineParts, /** @type {string[][]} */ lineRows, /** @type {Set<number>} */ factLines, /** @type {boolean} */ offer = false) {
|
|
678
|
+
// fwd (F251): a line with no ~ guardrail of the person's own holds no signable check; one decider, here
|
|
679
|
+
const unguarded = this.ruleRows(l.n).length === 0 && !this.isSheetLine(l.n);
|
|
680
|
+
let foundFact = false;
|
|
403
681
|
/** @type {any[]} */ const facts = [];
|
|
404
682
|
/** @type {{r: Row, src: string}[]} */ const factRows = [];
|
|
405
683
|
/** @type {Row|null} */ let countRow = null;
|
|
406
684
|
/** @type {number[]} */ const rulesCarried = [];
|
|
407
685
|
/** the person's picks of this line: they follow the line's fact part on the card, as they always did (the facts, then the picks, then the defaults) @type {{p: any, key: string}[]} */
|
|
408
686
|
const pickParts = [];
|
|
687
|
+
/** S4: the rows a sheet part carries (a `~` rule row the sheet built, an `[agent]` row, the `[default]` row) @type {Row[]} */
|
|
688
|
+
const sheetRows = [];
|
|
689
|
+
/** shape jobs: the rows a shape part carries (a `~` rule row with a field, an `[agent]` field row, the `[default]` row) @type {Row[]} */
|
|
690
|
+
const shapeRows = [];
|
|
409
691
|
for (const r of this.rowsOn(l.n)) {
|
|
410
692
|
if (r.kind === 'floor') continue;
|
|
411
693
|
r.part = null;
|
|
412
|
-
r.grown = undefined;
|
|
413
694
|
if (!r.can?.ok) { r.state = 'not-checked'; r.reason = r.can?.why ?? 'not checked'; continue; }
|
|
414
695
|
if (r.held) { r.state = 'suggested'; r.reason = r.choice === 'drop' ? REASON.dropped : REASON.suggested; continue; }
|
|
696
|
+
if (r.can.how === 'sheet') { sheetRows.push(r); continue; }
|
|
697
|
+
if (r.can.how === 'shape') { shapeRows.push(r); continue; }
|
|
698
|
+
// a line is a sheet line or a facts line, never both (a stage-shape red): a page fact on a sheet line is Not checked in plain words
|
|
699
|
+
if (this.isSheetLine(l.n) && (r.kind === 'fact' || r.kind === 'phrase' || r.kind === 'count')) { r.state = 'not-checked'; r.reason = REASON.sheetFacts; continue; }
|
|
415
700
|
if (r.can.how === 'pick') {
|
|
416
701
|
const p = partOfPick(r.pick, r.text, [r.rule]);
|
|
417
702
|
const reds = rubricStepShapeReds({ step: l.n, parts: [p] }, 'trial');
|
|
@@ -421,40 +706,93 @@ export class CheckBlock {
|
|
|
421
706
|
}
|
|
422
707
|
if (r.can.how === 'count') { countRow = r; continue; }
|
|
423
708
|
const built = this.factsOf(r, facts);
|
|
424
|
-
if ('why' in built) { r.state = 'not-checked'; r.reason = `code could not build a legal check from it: ${built.why}`; continue; }
|
|
709
|
+
if ('why' in built) { r.state = 'not-checked'; r.reason = `code could not build a legal check from it: ${built.why}`; if (r.kind === 'rule') r.truthRefused = true; continue; }
|
|
425
710
|
facts.push(...built.fresh);
|
|
426
711
|
r.factNames = built.names;
|
|
427
712
|
factRows.push({ r, src: built.src });
|
|
428
713
|
if (r.kind === 'rule') rulesCarried.push(r.rule);
|
|
429
714
|
r.state = 'built'; r.reason = null;
|
|
430
715
|
}
|
|
716
|
+
if (sheetRows.length > 0) this.buildSheetPartOf(l, sheetRows, lineParts, lineRows);
|
|
431
717
|
if (facts.length) {
|
|
718
|
+
// borrowed-from: bareloop src/checkblock.js@v0.60.0 (F337: the planner's example when a label sits off the result's first line; from the drafting copy, only here at signing)
|
|
719
|
+
const asSeen = asSeenOf(this.textOf(factRows[0]?.src), facts, factRows[0]?.src ?? '');
|
|
432
720
|
const part = {
|
|
433
721
|
text: facts.map((f) => f.name).join('; '), class: 'fact', source: factRows[0]?.src, facts,
|
|
722
|
+
...(asSeen ? { asSeen } : {}),
|
|
434
723
|
...(rulesCarried.length ? { rules: rulesCarried } : {}),
|
|
435
724
|
...(countRow ? { count: { ...(Number.isInteger(countRow.min) ? { min: countRow.min } : {}), ...(Number.isInteger(countRow.max) ? { max: countRow.max } : {}) } } : {}),
|
|
436
725
|
};
|
|
437
726
|
const reds = rubricStepShapeReds({ step: l.n, parts: [part] }, 'trial');
|
|
438
727
|
if (reds.length) for (const x of [...factRows.map((f) => f.r), ...(countRow ? [countRow] : [])]) { x.state = 'not-checked'; x.reason = `code could not build the line's fact part: ${reds[0]?.detail}`; x.part = null; }
|
|
439
728
|
else {
|
|
440
|
-
// M17 am4 (B3): the ONE writer of a place's grown phrases (fwd's signed R2c, M10 am7 item 2): the part holds EVERY phrase as a fact of its own
|
|
441
|
-
//
|
|
729
|
+
// M17 am4 (B3): the ONE writer of a place's grown phrases (fwd's signed R2c, M10 am7 item 2): the part holds EVERY phrase as a fact of its own; the plan and the Job tab say what the plan checks
|
|
730
|
+
// (M19 am6 item 4: the row copies of the words, `grown` and `oneOf`, are gone). A place the look did not grow keeps the one word.
|
|
442
731
|
const src = factRows[0]?.src;
|
|
443
732
|
const grownOf = (/** @type {any} */ f) => {
|
|
444
733
|
const k = f && f.shape === 'phrase' ? /** @type {any[]} */ (this.lookFacts).find((x) => x.line === l.n && Array.isArray(x.phrases) && String(x.name) === f.name && (x.source === undefined || x.source === src)) : undefined;
|
|
445
734
|
return k ? factsOfLook(k) : null;
|
|
446
735
|
};
|
|
447
|
-
|
|
448
|
-
const words = (r.factNames ?? []).flatMap((/** @type {string} */ n) => (grownOf(facts.find((f) => f.name === n)) ?? []).map((x) => String(x.phrase)));
|
|
449
|
-
r.grown = words.length ? words : undefined;
|
|
450
|
-
}
|
|
451
|
-
lineParts.push({ ...part, facts: facts.flatMap((f) => grownOf(f) ?? [f]) }); lineRows.push([...factRows.map((f) => f.r.key), ...(countRow ? [countRow.key] : [])]); factLines.add(l.n); if (countRow) { countRow.state = 'built'; countRow.reason = null; } }
|
|
452
|
-
// borrowed-from: bareloop src/checkblock.js@v0.58.0
|
|
736
|
+
lineParts.push({ ...part, facts: facts.flatMap((f) => grownOf(f) ?? [f]) }); lineRows.push([...factRows.map((f) => f.r.key), ...(countRow ? [countRow.key] : [])]); foundFact = true; if (countRow) { countRow.state = 'built'; countRow.reason = null; } }
|
|
453
737
|
} else if (countRow) { countRow.state = 'not-checked'; countRow.reason = this.rowsOn(l.n).some((x) => x.held && (x.kind === 'fact' || x.kind === 'phrase')) ? REASON.countNeedsSuggested : REASON.countNeedsFact; }
|
|
738
|
+
// facts+shape: the shape part follows the fact part (the same `results` list); its fields are the rules no truth check could take
|
|
739
|
+
if (shapeRows.length > 0) this.buildShapePartOf(l, shapeRows, lineParts, lineRows);
|
|
454
740
|
for (const { p, key } of pickParts) { lineParts.push(p); lineRows.push([key]); }
|
|
741
|
+
// fwd (F251): the one decider. A line with no ~ guardrail keeps no fact, pick or shape part: its built rows are Not checked in the words the Accept reads, and it is never a fact line (so no numbers tie points at it)
|
|
742
|
+
if (unguarded && !offer) {
|
|
743
|
+
for (const k of lineRows.flat()) { const row = this.rows.find((x) => x.key === k); if (row) { row.state = 'not-checked'; row.reason = NO_GUARDRAIL_WORDS; row.part = null; } }
|
|
744
|
+
lineParts.length = 0; lineRows.length = 0;
|
|
745
|
+
} else if (foundFact) factLines.add(l.n);
|
|
455
746
|
this.buildDefaults(l, lineParts, lineRows, factLines);
|
|
456
747
|
}
|
|
457
748
|
|
|
749
|
+
/**
|
|
750
|
+
* S4: ONE sheet part per sheet line, from the checks code built (the `[you]` rule rows' checks, then the `[agent]` checks the person has not dropped). Every row it carries points at it. A part code cannot legally build leaves its rows Not checked
|
|
751
|
+
* in the stage-shape red's own words; a line whose checks were all dropped has no part and no `[default]` row.
|
|
752
|
+
* @param {{n: number}} l @param {Row[]} sheetRows @param {any[]} lineParts @param {string[][]} lineRows
|
|
753
|
+
*/
|
|
754
|
+
buildSheetPartOf(l, sheetRows, lineParts, lineRows) {
|
|
755
|
+
const b = this.sheetBuilt?.built[l.n];
|
|
756
|
+
const held = new Set(this.rows.filter((r) => r.kind === 'sheet' && r.line === l.n && r.held).map((r) => r.check.id));
|
|
757
|
+
const checks = b ? [...b.ruleRows.map((p) => p.check), ...b.agentRows.map((p) => p.check).filter((c) => !held.has(c.id))] : [];
|
|
758
|
+
if (checks.length === 0) { for (const r of sheetRows) { r.state = 'dropped'; r.reason = null; } return; }
|
|
759
|
+
const rules = [...new Set(sheetRows.filter((r) => r.kind === 'rule').map((r) => Number(r.rule)))].sort((x, y) => x - y);
|
|
760
|
+
// fwd keeps: the checks stay exactly as built (the tag's `buildSheetPart` shares one claim between a sum and a count of one condition for bareloop's worker; fwd's close.sheet keeps them apart, M15 am3a), and the part is
|
|
761
|
+
// not tried by `rubricStepShapeReds`: fwd's one gate for a sheet check is the declaration validator (src/sheetchecks.js `sheetCheckReds`), which runs on the assembled close
|
|
762
|
+
const part = { text: `the checks of line ${l.n} on the sheet`, class: 'sheet', checks: checks.map((c) => ({ ...c })), ...(rules.length ? { rules } : {}) };
|
|
763
|
+
lineParts.push(part);
|
|
764
|
+
lineRows.push(sheetRows.map((r) => r.key));
|
|
765
|
+
for (const r of sheetRows) { r.state = 'built'; r.reason = null; }
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Shape jobs: ONE shape part per shape line, from the fields that stand (a `[you]` rule row's field, then the `[agent]` fields the person has not dropped and that are not Suggested) and the item count the person's words gave. Every
|
|
770
|
+
* row it carries points at it. A line left with no field has no part and no `[default]` row.
|
|
771
|
+
* The part is validated by `rubricStepShapeReds` (names, kinds, count, and bareguard's own `createRubric` over the `itemShape` check): a part code cannot legally build leaves its rows Not checked in that red's own words, as `buildSheetPartOf` does.
|
|
772
|
+
* @param {{n: number, text: string}} l @param {Row[]} shapeRows @param {any[]} lineParts @param {string[][]} lineRows
|
|
773
|
+
*/
|
|
774
|
+
buildShapePartOf(l, shapeRows, lineParts, lineRows) {
|
|
775
|
+
const b = this.shapeBuilt?.built[l.n];
|
|
776
|
+
const fields = (b?.fields ?? []).filter((f) => shapeRows.some((r) => (f.by === 'you' && r.kind === 'rule' && r.rule === f.rule) || (f.by === 'agent' && r.key === shapeRowKey(l.n, f.name))));
|
|
777
|
+
if (!b || !fields.some((f) => f.by === 'you')) { for (const r of shapeRows) { r.state = 'dropped'; r.reason = null; } return; }
|
|
778
|
+
// M19 am11 items 1, 2: the `~` rules that count items set the line's count (all of them: the largest at-least and the smallest at-most hold); then code's own per-input count is Not checked, with its reason
|
|
779
|
+
const countRows = shapeRows.filter((r) => r.kind === 'rule' && r.can?.count);
|
|
780
|
+
const ruleCount = countRows.length === 0 ? null : {
|
|
781
|
+
...(countRows.some((r) => Number.isInteger(r.can.count.min)) ? { min: Math.max(...countRows.map((r) => r.can.count.min).filter(Number.isInteger)) } : {}),
|
|
782
|
+
...(countRows.some((r) => Number.isInteger(r.can.count.max)) ? { max: Math.min(...countRows.map((r) => r.can.count.max).filter(Number.isInteger)) } : {}),
|
|
783
|
+
};
|
|
784
|
+
if (ruleCount !== null) {
|
|
785
|
+
for (const r of shapeRows.filter((x) => x.kind === 'shape' && x.by === 'default')) { r.state = 'not-checked'; r.reason = REASON.itemCountByRule; }
|
|
786
|
+
shapeRows = shapeRows.filter((r) => !(r.kind === 'shape' && r.by === 'default'));
|
|
787
|
+
}
|
|
788
|
+
const part = buildShapePart({ text: `the items of line ${l.n}`, fields: fields.map((f) => ({ name: f.name, spec: fieldSpec(f), rule: f.rule, by: f.by })), itemCount: ruleCount ?? b.itemCount, countRules: countRows.map((r) => Number(r.rule)) });
|
|
789
|
+
const reds = rubricStepShapeReds({ step: l.n, parts: [...lineParts.filter((p) => p.class === 'fact'), part] }, 'trial');
|
|
790
|
+
if (reds.length) { for (const r of shapeRows) { r.state = 'not-checked'; r.reason = `code could not build the line's shape part: ${reds[0]?.detail}`; } return; }
|
|
791
|
+
lineParts.push(part);
|
|
792
|
+
lineRows.push(shapeRows.map((r) => r.key));
|
|
793
|
+
for (const r of shapeRows) { r.state = 'built'; r.reason = null; }
|
|
794
|
+
}
|
|
795
|
+
|
|
458
796
|
/**
|
|
459
797
|
* The fact(s) a fact-like row builds, checked alone through the bareguard shapes and against the facts already on the line.
|
|
460
798
|
* @param {Row} r @param {any[]} onLine the facts already built on this line @returns {{fresh: any[], src: string, names: string[]} | {why: string}}
|
|
@@ -471,10 +809,10 @@ export class CheckBlock {
|
|
|
471
809
|
if (r.kind === 'rule') {
|
|
472
810
|
const w = base.words.find((/** @type {string} */ x) => proved(this.textOf(src), x)) ?? base.words[0];
|
|
473
811
|
fs = r.can.strips ? placeFacts(base.name, r.can.strips, mk)
|
|
474
|
-
: base.shape === 'phrase' ? [mk(base.name, {
|
|
812
|
+
: base.shape === 'phrase' ? [mk(base.name, phraseSigned(base.words.filter((/** @type {string} */ x) => proved(this.textOf(src), x)), w))]
|
|
475
813
|
: [kindFields(base, w, { ...(r.can.reading ? { rule: r.can.reading } : {}), ...(r.can.aiProposal ? { aiProposal: true } : {}) })];
|
|
476
814
|
} else if (r.can.how === 'place') fs = placeFacts(r.name ?? 'phrase', r.can.strips, mk);
|
|
477
|
-
else if (r.shape === 'phrase' || r.kind === 'phrase') fs = [mk(r.name ?? `phrase ${r.words[0]}`, {
|
|
815
|
+
else if (r.shape === 'phrase' || r.kind === 'phrase') fs = [mk(r.name ?? `phrase ${r.words[0]}`, phraseSigned((r.words ?? []).filter((/** @type {string} */ x) => proved(this.textOf(src), x)), r.can.word))];
|
|
478
816
|
else fs = [kindFields(r, r.can.word, {})];
|
|
479
817
|
const fresh = [];
|
|
480
818
|
const names = fs.map((f) => f.name);
|
|
@@ -497,6 +835,8 @@ export class CheckBlock {
|
|
|
497
835
|
/** the `$` defaults of a line, decided from what the line ended with: a text line quotes its input (one input only) and ties its numbers to the fact lines before it */
|
|
498
836
|
buildDefaults(/** @type {{n: number}} */ l, /** @type {any[]} */ lineParts, /** @type {string[][]} */ lineRows, /** @type {Set<number>} */ factLines) {
|
|
499
837
|
// M16 am1: with `cited: false` the cited row is never added and the numbers default below still runs
|
|
838
|
+
// S4: a sheet line quotes nothing and ties no number to a quote: its `$cited` default is never added (a cited part beside a sheet part is a stage-shape red)
|
|
839
|
+
if (this.isSheetLine(l.n)) return;
|
|
500
840
|
const cited = !this.cited ? null : this.rowsOn(l.n, 'cited')[0] ?? this.addRow({ key: `L${l.n}.$cited`, line: l.n, kind: 'cited', by: 'default', from: 'default', source: this.labels[0] });
|
|
501
841
|
const numbers = this.rowsOn(l.n, 'numbers')[0] ?? null;
|
|
502
842
|
if (cited) cited.part = null;
|
|
@@ -506,7 +846,7 @@ export class CheckBlock {
|
|
|
506
846
|
else if (cited) { cited.state = 'not-checked'; cited.reason = REASON.manyInputs; }
|
|
507
847
|
const earlier = [...factLines].filter((n) => n < l.n);
|
|
508
848
|
if (!earlier.length) return;
|
|
509
|
-
const nr = numbers ?? this.addRow({ key: `L${l.n}.$numbers`, line: l.n, kind: 'numbers', by: 'default', from: 'default'
|
|
849
|
+
const nr = numbers ?? this.addRow({ key: `L${l.n}.$numbers`, line: l.n, kind: 'numbers', by: 'default', from: 'default' });
|
|
510
850
|
lineParts.push({ text: 'every number in the text is in a checked quote', class: 'countable', check: 'numbersFromFacts', from: earlier });
|
|
511
851
|
lineRows.push([nr.key]); nr.state = 'built'; nr.reason = null; nr.part = null;
|
|
512
852
|
}
|
|
@@ -534,21 +874,179 @@ export class CheckBlock {
|
|
|
534
874
|
/** the note question's answers, `{line, answer: 'yes'|'no'|'failed'}`; the whole list is reconciled again @param {{line: number, answer: 'yes'|'no'|'failed'}[]} answers */
|
|
535
875
|
setNotes(answers) { for (const a of answers) this.notes.set(a.line, a.answer); this.reconcile(); }
|
|
536
876
|
|
|
877
|
+
// ── a repo job's check TYPE (hamr 2026-11-15: "same flow as rubric, no exceptions; only the TYPE of checks varies") ──────────────────────────────────────────────────────────────────────────
|
|
878
|
+
// The rows are the same rows. A `~` rule is kept (built) only when CODE finds a repo path in the person's own words that the write fence keeps; every other rule is asked about (Agree / Drop it / own
|
|
879
|
+
// words, the same ask the rubric flow uses) or Not checked with a REASON. A `!` row is a work stage the drafter wrote from the catalogue (the check type), droppable like any `!` row, never the last one on a line.
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* The person's job lines as they stand now (a try-3 answer replaced or added a `~` rule): a rule whose words changed is the person's own typed words (its old answer is void), a new rule is a new row, a rule that is gone leaves.
|
|
883
|
+
* @param {{n: number, text: string, rules?: string[]}[]} jobLines
|
|
884
|
+
*/
|
|
885
|
+
syncJob(jobLines) {
|
|
886
|
+
this.lines = jobLines.map((l) => ({ n: l.n, text: l.text }));
|
|
887
|
+
const keep = new Set();
|
|
888
|
+
for (const l of jobLines) {
|
|
889
|
+
(l.rules ?? []).forEach((t, i) => {
|
|
890
|
+
const key = `L${l.n}.~${i + 1}`;
|
|
891
|
+
keep.add(key);
|
|
892
|
+
const row = this.rows.find((r) => r.key === key);
|
|
893
|
+
if (!row) { this.addRow({ key, line: l.n, kind: 'rule', by: 'you', from: 'rule', origin: 'typed', cantAsked: true, text: t, rule: i + 1 }); return; }
|
|
894
|
+
if (row.text !== t) { row.text = t; row.origin = 'typed'; row.left = false; row.cantAsked = true; }
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
this.rows = this.rows.filter((r) => r.kind !== 'rule' || keep.has(r.key));
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/** the repo listing at the seed, once it is read (the rule rows are judged against it) @param {string[]|null} files */
|
|
901
|
+
setListing(files) { if (this.repo !== null) this.repo.files = Array.isArray(files) ? [...files] : null; }
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* The drafter's work stages as `!` rows (a mandatory guard is not one), and a Not checked `!` row for each line the drafter refused: the refusal is only the SIGNAL, the reason is code's (`REASON.noRule`, the one table). Idempotent: the stage rows are made again from `stages`.
|
|
905
|
+
* @param {any[]} stages the declaration's stages, guards included @param {{guardNames?: string[], refused?: any[], guardLines?: any[]}} [o]
|
|
906
|
+
*/
|
|
907
|
+
addStages(stages, { guardNames = [], refused = [], guardLines = [] } = {}) {
|
|
908
|
+
this.rows = this.rows.filter((r) => r.kind !== 'stage');
|
|
909
|
+
this.declared = Array.isArray(stages) ? stages : [];
|
|
910
|
+
this.guardCover = new Set((Array.isArray(guardLines) ? guardLines : []).flatMap((/** @type {any} */ g) => (Array.isArray(g?.lines) ? g.lines : [])));
|
|
911
|
+
const guards = new Set(guardNames);
|
|
912
|
+
// a line a live stage or a guard's `guardLines` covers is never refused (the rubric's rule: only a line no check could be built for is refused)
|
|
913
|
+
const covered = new Set([...this.guardCover, ...this.declared.filter((st) => st && !guards.has(st.name) && Array.isArray(st.fromLine)).flatMap((st) => st.fromLine)]);
|
|
914
|
+
for (const l of this.lines) {
|
|
915
|
+
for (const st of this.declared) {
|
|
916
|
+
if (!st || typeof st.name !== 'string' || guards.has(st.name) || !Array.isArray(st.fromLine) || st.fromLine.length === 0 || Math.min(...st.fromLine) !== l.n) continue;
|
|
917
|
+
this.addRow({ key: stageKeyOf(st.name), line: l.n, kind: 'stage', by: 'agent', from: 'agent', stageName: st.name, cover: [...st.fromLine] });
|
|
918
|
+
}
|
|
919
|
+
(Array.isArray(refused) ? refused : []).filter((/** @type {any} */ x) => x && x.line === l.n && !Number.isInteger(x.rule) && typeof x.reason === 'string' && !covered.has(l.n))
|
|
920
|
+
.forEach((/** @type {any} */ x, /** @type {number} */ i) => this.addRow({ key: `L${l.n}.refused.${i + 1}`, line: l.n, kind: 'stage', by: 'agent', from: 'agent', refusal: true, said: REASON.noRule }));
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/** the repo paths outside the write scope (the pointing call is shown these); empty when there is no listing or no fence @returns {string[]} */
|
|
925
|
+
outsideScope() {
|
|
926
|
+
const files = this.repo?.files;
|
|
927
|
+
const scope = this.repo?.writeScope;
|
|
928
|
+
return Array.isArray(files) && Array.isArray(scope) && scope.length ? files.filter((f) => !this.inScope(f)) : [];
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/** the folders every file of which lies outside the write scope (a rule may ask such a folder to stay as it is, written `folder/`); the pointing call is shown them beside the files @returns {string[]} */
|
|
932
|
+
outsideFolders() {
|
|
933
|
+
const files = this.repo?.files;
|
|
934
|
+
if (!Array.isArray(files) || this.outsideScope().length === 0) return [];
|
|
935
|
+
const all = new Set();
|
|
936
|
+
/** the folders above at least one file the run may change (one pass over the listing) */
|
|
937
|
+
const open = new Set();
|
|
938
|
+
for (const f of files) {
|
|
939
|
+
const inside = this.inScope(f);
|
|
940
|
+
for (let i = f.indexOf('/'); i > 0; i = f.indexOf('/', i + 1)) { all.add(f.slice(0, i)); if (inside) open.add(f.slice(0, i)); }
|
|
941
|
+
}
|
|
942
|
+
return [...all].filter((d) => !open.has(d));
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/** is this repo file a place the run may change? @param {string} f */
|
|
946
|
+
inScope(f) {
|
|
947
|
+
return (this.repo?.writeScope ?? []).some((s) => { const pre = String(globToPrefix(String(s))).trim().replace(/^\.\//, '').replace(/\/+$/, ''); return pre === '' || pre === '.' || pre === '/' || f === pre || f.startsWith(`${pre}/`); });
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/** the listing paths (a file, or a folder written `folder/`) a text names as whole tokens @param {string} text @returns {string[]} */
|
|
951
|
+
namedPaths(text) {
|
|
952
|
+
const files = this.repo?.files;
|
|
953
|
+
if (!Array.isArray(files)) return [];
|
|
954
|
+
const said = ` ${String(text).replace(/(^|[\s"'(])\.\//g, '$1')} `;
|
|
955
|
+
const all = new Set(files);
|
|
956
|
+
for (const f of files) for (let i = f.indexOf('/'); i > 0; i = f.indexOf('/', i + 1)) all.add(f.slice(0, i));
|
|
957
|
+
// borrowed-from: bareloop src/checkblock.js@v0.60.0 (`namedPaths`): the tag builds a pattern from each path; src/ builds none (test/signed-text.test.js), so the same two tests are written by hand:
|
|
958
|
+
// before the path no word character, `.`, `/` or `-`; after a file no word character or `-`, and no `.` that starts an extension; after a folder written `folder/` no word character, `.` or `-`
|
|
959
|
+
const wordy = (/** @type {string} */ c) => /\w/.test(c);
|
|
960
|
+
const holds = (/** @type {string} */ p) => {
|
|
961
|
+
const tail = files.includes(p) ? '' : '/';
|
|
962
|
+
for (let i = said.indexOf(p + tail); i !== -1; i = said.indexOf(p + tail, i + 1)) {
|
|
963
|
+
const before = said[i - 1] ?? '';
|
|
964
|
+
const after = said[i + p.length + tail.length] ?? '';
|
|
965
|
+
const afterNext = said[i + p.length + tail.length + 1] ?? '';
|
|
966
|
+
if (before !== '' && (wordy(before) || before === '.' || before === '/' || before === '-')) continue;
|
|
967
|
+
if (files.includes(p) ? (after !== '' && (wordy(after) || after === '-' || (after === '.' && wordy(afterNext)))) : (after !== '' && (wordy(after) || after === '.' || after === '-'))) continue;
|
|
968
|
+
return true;
|
|
969
|
+
}
|
|
970
|
+
return false;
|
|
971
|
+
};
|
|
972
|
+
return [...all].filter((p) => said.includes(p) && holds(p));
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Code's proof of a fence pointer: `path` is on the listing, the rule's own words name it (whole token; a folder as `folder/`), and neither it nor any other path those words name holds a place the run may change.
|
|
977
|
+
* @param {string} text the rule's own words @param {string} path @returns {boolean}
|
|
978
|
+
*/
|
|
979
|
+
provesFence(text, path) {
|
|
980
|
+
const files = this.repo?.files;
|
|
981
|
+
if (!Array.isArray(files) || this.outsideScope().length === 0) return false;
|
|
982
|
+
const p = String(path).trim().replace(/^\.\//, '').replace(/\/+$/, '');
|
|
983
|
+
const named = this.namedPaths(text);
|
|
984
|
+
if (!named.includes(p)) return false;
|
|
985
|
+
return !named.some((n) => files.some((f) => (f === n || f.startsWith(`${n}/`)) && this.inScope(f)));
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/** the AI's pointer at a repo `~` rule ({op:'fence', line, rule, path}): judged ALONE; code's proof decides, the AI only points @param {any} e */
|
|
989
|
+
editFence(e) {
|
|
990
|
+
if (this.repo === null) return { refusedBecause: 'a fence pointer is for a repo job' };
|
|
991
|
+
const r = this.ruleRows(e.line).find((x) => x.rule === e.rule);
|
|
992
|
+
if (!r) return { refusedBecause: 'names no ~ rule of this line' };
|
|
993
|
+
const path = typeof e.path === 'string' ? e.path.trim().replace(/^\.\//, '').replace(/\/+$/, '') : '';
|
|
994
|
+
if (!path) return { refusedBecause: 'no path given' };
|
|
995
|
+
if (!(this.repo.files ?? []).some((f) => f === path || f.startsWith(`${path}/`))) return { refusedBecause: `${path} is not on the repo listing` };
|
|
996
|
+
if (!this.provesFence(r.text, path)) return { refusedBecause: `the rule's own words do not name ${path}, or it names a place the run may change` };
|
|
997
|
+
r.pointed = path;
|
|
998
|
+
return { accepted: true, landedKey: r.key };
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/** a repo `~` rule: kept by the write fence when the AI pointed at a path and code proves it from the person's words; else the same ask the rubric flow uses (the person's Agree / Drop it / own words), Not checked when nobody can be asked @param {Row} r */
|
|
1002
|
+
matchRepoRule(r) {
|
|
1003
|
+
// the AI points, code proves (never kept without a pointer; own words that replaced the rule are proved again against the same pointer)
|
|
1004
|
+
if (typeof r.pointed === 'string' && this.provesFence(r.text, r.pointed)) { r.can = { ok: true, how: 'fence', path: r.pointed }; return; }
|
|
1005
|
+
if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: REASON.noPick }; return; }
|
|
1006
|
+
r.can = { ok: false, why: REASON.noPick };
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/** a repo job's rows: a rule is built with the path the fence keeps for it or Not checked with its reason; a work stage is built, or dropped when the person dropped it and it is not the last thing on its line */
|
|
1010
|
+
buildRepo() {
|
|
1011
|
+
for (const r of this.rows) {
|
|
1012
|
+
if (r.kind !== 'rule' && r.kind !== 'stage') continue;
|
|
1013
|
+
r.part = null;
|
|
1014
|
+
if (r.can?.ok) { r.state = 'built'; r.reason = null; if (r.kind === 'rule') r.fence = r.can.path; } else { r.state = 'not-checked'; r.reason = r.can?.why ?? 'not checked'; delete r.fence; }
|
|
1015
|
+
}
|
|
1016
|
+
for (const r of this.rows) {
|
|
1017
|
+
if (r.kind !== 'stage' || r.state !== 'built' || r.choice !== 'drop') continue;
|
|
1018
|
+
if (this.dropOk(r)) { r.state = 'dropped'; r.reason = REASON.dropped; } else r.choice = undefined;
|
|
1019
|
+
}
|
|
1020
|
+
const gone = new Set(this.rows.filter((r) => r.kind === 'stage' && r.state === 'dropped').map((r) => r.stageName));
|
|
1021
|
+
this.closeCache = { stages: this.declared.filter((st) => !gone.has(st?.name)), parts: [], map: [] };
|
|
1022
|
+
return this.closeCache;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/** may this repo work-stage row be dropped? Never the last check on a line it serves (another live stage, a guard's `guardLines` or a line refusal still covers it), and never the last work stage of the job @param {Row} r */
|
|
1026
|
+
dropOk(r) {
|
|
1027
|
+
const others = this.rows.filter((x) => x !== r && x.kind === 'stage');
|
|
1028
|
+
const live = others.filter((x) => !x.refusal && x.state === 'built');
|
|
1029
|
+
return live.length > 0 && (r.cover ?? [r.line]).every((/** @type {number} */ n) => this.guardCover.has(n) || live.some((x) => (x.cover ?? []).includes(n)) || others.some((x) => x.refusal && x.line === n));
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/** a row the person can Drop (and Add back): a `!` fact, phrase or count; in a repo job also a work stage the drafter wrote @param {Row} r */
|
|
1033
|
+
droppable(r) { return this.isBang(r) || (this.repo !== null && r.kind === 'stage' && r.refusal !== true) || (r.kind === 'sheet' && r.by === 'agent') || (r.kind === 'shape' && r.by === 'agent') || (r.kind === 'rule' && r.can?.how === 'shape'); }
|
|
1034
|
+
|
|
537
1035
|
// 5. the code-forced questions for rows code cannot settle (a person answers; the CHOICE decides, never the words). Cap 3 is the caller's (MAX_QUESTIONS).
|
|
538
1036
|
ask() {
|
|
539
1037
|
this.open = [];
|
|
540
1038
|
for (const r of this.rows) {
|
|
541
1039
|
if (!r.can?.ask) continue;
|
|
542
|
-
this.open.push({ key: `${r.key}:${r.can.ask}`, rowKey: r.key, line: r.line, ruleText: r.text, ask: r.can.ask, proposal: r.can.proposal ?? null, offers: { agree: r.can.proposal != null, drop: true } });
|
|
1040
|
+
this.open.push({ key: `${r.key}:${r.can.ask}`, rowKey: r.key, line: r.line, ruleText: r.text, ask: r.can.ask, proposal: r.can.proposal ?? null, ...(typeof r.can.question === 'string' ? { question: r.can.question } : {}), ...(Array.isArray(r.can.columns) ? { columns: r.can.columns, readings: r.can.readings } : {}), offers: { agree: r.can.proposal != null, drop: true } });
|
|
543
1041
|
}
|
|
544
1042
|
return this.open;
|
|
545
1043
|
}
|
|
546
1044
|
hasOpenQuestions() { return this.open.length > 0; }
|
|
547
1045
|
hasPendingDelta() { return this.queue.length > 0; }
|
|
548
1046
|
|
|
549
|
-
// 6. the person's answer: a row edit from the typed CHOICE (agree | drop
|
|
550
|
-
//
|
|
551
|
-
/** @param {string} qKey @param {string} choice @param {string} [text] @returns {{ok: true} | {ok: false, why: string}} */
|
|
1047
|
+
// 6. the person's answer: a row edit from the typed CHOICE (agree | drop), buttons only (hamr 2026-11-15: a typed own-words answer is retired; a rule is changed by Revise). ONE rule in, ONE rule out (hamr 2026-11-14):
|
|
1048
|
+
// an agreed answer REPLACES the asked rule, same line and same rule number; this list is the one owner (the job text is rebuilt from it, `jobLinesView`).
|
|
1049
|
+
/** @param {string} qKey @param {string} choice @param {string} [text] the person's correction (a reading question only) @returns {{ok: true} | {ok: false, why: string}} */
|
|
552
1050
|
applyAnswer(qKey, choice, text) {
|
|
553
1051
|
const q = this.open.find((x) => x.key === qKey);
|
|
554
1052
|
const r = q ? this.rows.find((x) => x.key === q.rowKey) : undefined;
|
|
@@ -565,7 +1063,16 @@ export class CheckBlock {
|
|
|
565
1063
|
r.text = said;
|
|
566
1064
|
return { ok: true };
|
|
567
1065
|
}
|
|
1066
|
+
// S1 tie: the person picked one of the tied columns (`text` = its name); the rule is the rule's own words with that column in place, one rule in, one rule out
|
|
1067
|
+
if (choice === 'column') {
|
|
1068
|
+
if (!Array.isArray(q.columns)) return { ok: false, why: 'that choice is not offered for this question' };
|
|
1069
|
+
const col = String(text ?? '');
|
|
1070
|
+
if (!q.columns.includes(col)) return { ok: false, why: 'that is not one of the columns offered' };
|
|
1071
|
+
r.text = String(q.readings?.[col]); r.agreed = true;
|
|
1072
|
+
return { ok: true };
|
|
1073
|
+
}
|
|
568
1074
|
if (choice === 'drop') { r.left = true; return { ok: true }; }
|
|
1075
|
+
// fwd keeps: the tag takes the person's own words only for a READING question (and marks them `corrected`); fwd takes them for any question (M10 am16)
|
|
569
1076
|
if (choice === 'rule') {
|
|
570
1077
|
const said = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
571
1078
|
if (!said) return { ok: false, why: 'an answer is needed' };
|
|
@@ -622,12 +1129,15 @@ export class CheckBlock {
|
|
|
622
1129
|
applyEdit(/** @type {any} */ e, /** @type {{adds: number}} */ kept) {
|
|
623
1130
|
if (!isRec(e) || !EDIT_OPS.includes(e.op)) return { refusedBecause: `"${e?.op}" is not a row edit (the AI never sends a check or a part)` };
|
|
624
1131
|
if (!Number.isInteger(e.line) || !this.lines.some((l) => l.n === e.line)) return { refusedBecause: 'names a job line that does not exist' };
|
|
1132
|
+
// S4: a rule has never two rows: the rules of a sheet line belong to the sheet checks, so a row edit about the line cannot add a second check or a second reason
|
|
1133
|
+
if (this.isSheetLine(e.line)) return { refusedBecause: REASON.sheetLine };
|
|
625
1134
|
if (e.op === 'add') {
|
|
626
1135
|
if (kept.adds >= MAX_BANG) return { refusedBecause: `more than ${MAX_BANG} checks proposed` };
|
|
627
1136
|
const res = this.editAdd(e);
|
|
628
1137
|
if (res.accepted) kept.adds += 1;
|
|
629
1138
|
return res;
|
|
630
1139
|
}
|
|
1140
|
+
if (e.op === 'fence') return this.editFence(e);
|
|
631
1141
|
if (e.op === 'reading') return this.editReading(e);
|
|
632
1142
|
if (e.op === 'pick') return this.editPick(e);
|
|
633
1143
|
return this.editNot(e);
|
|
@@ -731,7 +1241,7 @@ export class CheckBlock {
|
|
|
731
1241
|
// 8. whole-list reconcile, every time
|
|
732
1242
|
reconcile() { this.match(); const c = this.build(); this.ask(); return c; }
|
|
733
1243
|
|
|
734
|
-
/** the loop: while a question is open or a reply waits, apply it and reconcile the WHOLE list again. `answer(q)` gives {choice, text} or null (a person who did not answer) */
|
|
1244
|
+
/** the loop: while a question is open or a reply waits, apply it and reconcile the WHOLE list again. `answer(q)` gives {choice, text?} or null (a person who did not answer) */
|
|
735
1245
|
drive({ answer }) {
|
|
736
1246
|
this.unanswered = [];
|
|
737
1247
|
this.reconcile();
|
|
@@ -752,15 +1262,13 @@ export class CheckBlock {
|
|
|
752
1262
|
return this;
|
|
753
1263
|
}
|
|
754
1264
|
|
|
755
|
-
card() { return renderCard(this.rows); }
|
|
756
|
-
|
|
757
1265
|
/**
|
|
758
1266
|
* The rows as the close shape the card readers (`checksOfClose`, `refusedOf`, `cardOfClose`) already read: the block's stages, the picks code records and the signed list. The confirm card
|
|
759
1267
|
* and the signed card read the rows through the SAME readers, so a row shown at confirm is the row signed. Reconciles first (the whole list, every time).
|
|
760
1268
|
*/
|
|
761
1269
|
closeView() {
|
|
762
1270
|
const c = this.reconcile();
|
|
763
|
-
return { stages: c.stages, picks: this.picksOf(c), list: this.signedRows() };
|
|
1271
|
+
return { stages: c.stages, picks: this.picksOf(c), list: this.signedRows(), ...(this.fence ? { fence: [...this.fence] } : {}) };
|
|
764
1272
|
}
|
|
765
1273
|
|
|
766
1274
|
/** the picks code records: a countable part carrying the `~` rule numbers it settles @param {{parts: any[], map: {part: number, line: number}[]}} c the build @returns {{line: number, part: any}[]} */
|
|
@@ -768,6 +1276,17 @@ export class CheckBlock {
|
|
|
768
1276
|
return c.map.flatMap((m) => { const part = c.parts[m.part]; return part && part.class === 'countable' && Array.isArray(part.rules) ? [{ line: m.line, part }] : []; });
|
|
769
1277
|
}
|
|
770
1278
|
|
|
1279
|
+
/**
|
|
1280
|
+
* The rules and lines the close has no check for, as the signed close's `refused` (one owner: the draft's assembled declaration and a final-card Drop both read it): each `~` rule row that is not built, then each job line no stage serves.
|
|
1281
|
+
* @param {{n: number}[]|null|undefined} jobLines @param {any[]} stages the block's stages @returns {{line: number, rule?: number, reason: string}[]}
|
|
1282
|
+
*/
|
|
1283
|
+
refusedView(jobLines, stages) {
|
|
1284
|
+
/** @type {{line: number, rule?: number, reason: string}[]} */
|
|
1285
|
+
const refused = this.rows.filter((r) => r.kind === 'rule' && r.state !== 'built').map((r) => ({ line: r.line, rule: r.rule, reason: String(r.reason ?? 'not checked') }));
|
|
1286
|
+
for (const l of jobLines ?? []) if (!stages.some((st) => Array.isArray(st.fromLine) && st.fromLine.includes(l.n))) refused.push({ line: l.n, reason: REASON.noRule });
|
|
1287
|
+
return refused;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
771
1290
|
/** the standing ruling "a run needs one check": one row that is not the floor is built */
|
|
772
1291
|
hasBuiltCheck() { return this.rows.some((r) => r.state === 'built' && r.kind !== 'floor'); }
|
|
773
1292
|
|
|
@@ -776,11 +1295,17 @@ export class CheckBlock {
|
|
|
776
1295
|
* `dropped` with code's reason (it is on the Audit, never on the card), and a built row carries the names of the facts it made (`facts`), so every reader can tag each fact by its row's kind.
|
|
777
1296
|
*/
|
|
778
1297
|
signedRows() {
|
|
779
|
-
|
|
1298
|
+
const rows = (this.repo !== null ? [...this.rows].sort((a, b) => a.line - b.line) : this.rows).map((r) => {
|
|
780
1299
|
const gone = r.state === 'suggested' || r.hidden === true;
|
|
781
1300
|
const row = { ...r, ...(gone ? { state: 'dropped' } : {}), ...(r.state === 'built' && r.factNames?.length ? { facts: r.factNames } : {}) };
|
|
782
1301
|
return Object.fromEntries(SIGNED_ROW_FIELDS.filter((f) => row[f] !== undefined && row[f] !== null).map((f) => [f, row[f]]));
|
|
783
1302
|
});
|
|
1303
|
+
return [...rows, ...this.guards.map((name) => ({ line: 0, key: guardKeyOf(name), from: 'default', by: 'default', kind: 'guard', state: 'built' })), ...(this.fence ? [{ line: 0, key: FENCE_KEY, from: 'default', by: 'default', kind: 'fence', state: 'built' }] : [])];
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
/** the `[you]` rule rows the person dropped (Not checked, "You dropped it."): the card gives each an Add back button @returns {{key: string, line: number, text: string}[]} */
|
|
1307
|
+
droppedRulesView() {
|
|
1308
|
+
return this.rows.filter((r) => r.kind === 'rule' && this.shapeDrops.rules.has(`${r.line}:${r.rule}`)).map((r) => ({ key: r.key, line: r.line, text: String(r.text ?? '') }));
|
|
784
1309
|
}
|
|
785
1310
|
|
|
786
1311
|
/** the suggestions code has proved it can build, as the card offers them (Add): `{key, line, text}` */
|
|
@@ -802,9 +1327,32 @@ export class CheckBlock {
|
|
|
802
1327
|
rowChoice(key, choice) {
|
|
803
1328
|
const r = this.rows.find((x) => x.key === key);
|
|
804
1329
|
if (!r) return { ok: false, why: 'there is no such check on the list' };
|
|
1330
|
+
// a rule's own shape field (rules first: the rule had no truth check) can be dropped: that rule goes Not checked; to get it back, Revise
|
|
1331
|
+
if (r.kind === 'rule' && r.can?.how === 'shape') {
|
|
1332
|
+
if (choice !== 'drop') return { ok: false, why: 'that check is already on the card' };
|
|
1333
|
+
this.shapeDrops.rules.add(`${r.line}:${r.rule}`);
|
|
1334
|
+
this.reconcile();
|
|
1335
|
+
return { ok: true };
|
|
1336
|
+
}
|
|
1337
|
+
if (r.kind === 'rule' && this.shapeDrops.rules.has(`${r.line}:${r.rule}`)) {
|
|
1338
|
+
// Add back: the inverse of the Drop above; the rule is judged again by code, so it returns to its own row (Checked) exactly as before the drop
|
|
1339
|
+
if (choice !== 'add') return { ok: false, why: 'that check is already dropped' };
|
|
1340
|
+
this.shapeDrops.rules.delete(`${r.line}:${r.rule}`);
|
|
1341
|
+
this.reconcile();
|
|
1342
|
+
return { ok: true };
|
|
1343
|
+
}
|
|
805
1344
|
if (r.by === 'you') return { ok: false, why: 'that check comes from a rule you wrote; edit the job to change it' };
|
|
806
|
-
if (r.by !== 'agent' || !this.
|
|
1345
|
+
if (r.by !== 'agent' || !this.droppable(r)) return { ok: false, why: 'that check is code\'s own and stays' };
|
|
807
1346
|
if (choice !== 'drop' && choice !== 'add') return { ok: false, why: 'not one of the choices' };
|
|
1347
|
+
if (r.kind === 'stage') {
|
|
1348
|
+
// a repo work stage: Drop takes it out of the close (never the last check on its line), Add puts it back
|
|
1349
|
+
if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
|
|
1350
|
+
if (choice === 'add' && r.state !== 'dropped') return { ok: false, why: 'only a dropped check can be added back' };
|
|
1351
|
+
if (choice === 'drop' && !this.dropOk(r)) return { ok: false, why: `Dropping that check would leave line ${r.line} with no check, so it stays.` };
|
|
1352
|
+
r.choice = choice === 'drop' ? 'drop' : undefined;
|
|
1353
|
+
this.reconcile();
|
|
1354
|
+
return { ok: true };
|
|
1355
|
+
}
|
|
808
1356
|
if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
|
|
809
1357
|
if (choice === 'add' && r.state !== 'suggested') return { ok: false, why: 'only a suggested check can be added' };
|
|
810
1358
|
const before = r.choice;
|
|
@@ -816,9 +1364,7 @@ export class CheckBlock {
|
|
|
816
1364
|
|
|
817
1365
|
/** the person's Drop/Add choices, tied to the line's words (not its number) and the row's own name, so a Revise keeps them @returns {{lineWords: string, occurrence: number, tail: string, choice: string}[]} */
|
|
818
1366
|
choicesRecord() {
|
|
819
|
-
|
|
820
|
-
const key = new Map(this.lines.map((l) => { const w = norm(l.text); const o = seen.get(w) ?? 0; seen.set(w, o + 1); return [l.n, { lineWords: w, occurrence: o }]; }));
|
|
821
|
-
return this.rows.filter((r) => r.choice === 'drop' || r.choice === 'add').map((r) => ({ ...(key.get(r.line) ?? { lineWords: '', occurrence: 0 }), tail: r.key.replace(/^L\d+\./, ''), choice: String(r.choice) }));
|
|
1367
|
+
return choiceEntries(this.lines, this.rows.filter((r) => r.kind !== 'sheet' && r.kind !== 'shape' && (r.choice === 'drop' || r.choice === 'add')).map((r) => ({ line: r.line, key: r.key, choice: String(r.choice) })));
|
|
822
1368
|
}
|
|
823
1369
|
|
|
824
1370
|
/** a Revise keeps the last draft's Drop/Add choices on the rows that are still there (same line words, same row); code still judges every one @param {{lineWords: string, occurrence: number, tail: string, choice: string}[]} rec */
|
|
@@ -828,7 +1374,7 @@ export class CheckBlock {
|
|
|
828
1374
|
for (const c of Array.isArray(rec) ? rec : []) {
|
|
829
1375
|
if (!c || (c.choice !== 'drop' && c.choice !== 'add')) continue;
|
|
830
1376
|
const line = lines.find((l) => l.w === c.lineWords && l.o === c.occurrence);
|
|
831
|
-
const r = line ? this.rows.find((x) => x.line === line.n && this.
|
|
1377
|
+
const r = line ? this.rows.find((x) => x.line === line.n && this.droppable(x) && x.key.replace(/^L\d+\./, '') === c.tail) : undefined;
|
|
832
1378
|
if (r) { r.choice = c.choice; r.keptFromLast = true; }
|
|
833
1379
|
}
|
|
834
1380
|
}
|