fwdloop 0.38.0 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fwdloop +21 -19
- package/package.json +1 -1
- package/src/ask.js +70 -148
- package/src/audit-fold.js +5 -4
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +32 -60
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +3 -2
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +5 -5
- package/src/books.js +217 -12
- package/src/checkblock.js +20 -41
- package/src/checklistsign.js +25 -3
- package/src/checklook.js +3 -1
- package/src/checkpick.js +5 -76
- package/src/cited-source.js +4 -4
- package/src/citedcheck.js +6 -11
- package/src/citedwords.js +9 -8
- package/src/closers.js +9 -6
- package/src/declaration.js +14 -49
- package/src/diary.js +23 -1
- package/src/draft-steps.js +11 -1
- package/src/drafter.js +13 -9
- package/src/draftfiles.js +127 -0
- package/src/draftspend.js +165 -17
- package/src/flow.js +42 -87
- package/src/flowmodel.js +1 -1
- package/src/index.js +3 -2
- package/src/inside.js +86 -0
- package/src/jsonl-append.js +33 -1
- package/src/learn.js +1 -1
- package/src/learnstore.js +20 -22
- package/src/line-checks.js +1 -1
- package/src/liveness.js +3 -0
- package/src/mcp-use.js +8 -9
- package/src/memo.js +13 -16
- package/src/model-step.js +2 -2
- package/src/page-words.js +8 -0
- package/src/pageask.js +8 -3
- package/src/pagebits.js +8 -1
- package/src/pagedropwords.js +1 -1
- package/src/pagerules.js +6 -3
- package/src/panel/author.js +99 -75
- package/src/panel/authorcard.js +21 -8
- package/src/panel/authorflows.js +3 -3
- package/src/panel/authorresume.js +3 -3
- package/src/panel/authorstart.js +15 -16
- package/src/panel/authortrigger.js +43 -70
- package/src/panel/data.js +125 -168
- package/src/panel/index.html +122 -61
- package/src/panel/jobgrid.js +3 -7
- package/src/panel/result.js +7 -10
- package/src/panel/resume.js +4 -3
- package/src/panel/scheduler.js +9 -9
- package/src/panel/server.js +8 -4
- package/src/panel/spawn.js +22 -11
- package/src/panel/tickets.js +2 -2
- package/src/pickrecord.js +51 -31
- package/src/placerule.js +3 -4
- package/src/planrebuild.js +19 -19
- package/src/primitives.js +1 -1
- package/src/provider.js +1 -1
- package/src/reasons.js +25 -0
- package/src/runfile.js +26 -2
- package/src/runner.js +57 -105
- package/src/runvalues.js +47 -24
- package/src/schedule-choices.js +41 -0
- package/src/schedule-shape.js +39 -0
- package/src/schedule.js +9 -8
- package/src/setup.js +20 -36
- package/src/shaperows.js +2 -2
- package/src/sheetblock.js +2 -2
- package/src/sheetbuild.js +5 -5
- package/src/sheetrun.js +4 -5
- package/src/summary-words.js +2 -1
- package/src/thinking.js +5 -2
- package/src/ticketrows.js +7 -28
- package/src/trigger-clock.js +9 -23
- package/src/trigger-files.js +30 -22
- package/src/trigger-tickets.js +15 -14
- package/src/try-checks.js +2 -1
- package/src/types.js +2 -0
- package/types/ask.d.ts +25 -20
- package/types/authoring.d.ts +7 -42
- package/types/blockpick.d.ts +1 -1
- package/types/books.d.ts +256 -4
- package/types/checkblock.d.ts +1 -23
- package/types/checklist.d.ts +3 -3
- package/types/checklistsign.d.ts +7 -0
- package/types/checkpick.d.ts +0 -21
- package/types/citedwords.d.ts +7 -4
- package/types/closers.d.ts +1 -0
- package/types/declaration.d.ts +4 -14
- package/types/diary.d.ts +14 -1
- package/types/draft-steps.d.ts +7 -0
- package/types/drafter.d.ts +1 -1
- package/types/draftfiles.d.ts +89 -0
- package/types/draftspend.d.ts +74 -0
- package/types/flow.d.ts +32 -54
- package/types/index.d.ts +3 -3
- package/types/inside.d.ts +58 -0
- package/types/jsonl-append.d.ts +20 -0
- package/types/learnstore.d.ts +0 -2
- package/types/liveness.d.ts +1 -0
- package/types/page-words.d.ts +6 -0
- package/types/pageask.d.ts +2 -0
- package/types/pagebits.d.ts +3 -0
- package/types/pagerules.d.ts +1 -0
- package/types/panel/author.d.ts +7 -3
- package/types/panel/authorcard.d.ts +0 -6
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/authortrigger.d.ts +16 -2
- package/types/panel/data.d.ts +36 -11
- package/types/panel/spawn.d.ts +18 -2
- package/types/pickrecord.d.ts +29 -0
- package/types/reasons.d.ts +23 -0
- package/types/runfile.d.ts +14 -0
- package/types/runner.d.ts +6 -38
- package/types/runvalues.d.ts +17 -2
- package/types/schedule-choices.d.ts +9 -0
- package/types/schedule-shape.d.ts +15 -0
- package/types/sheetbuild.d.ts +1 -1
- package/types/thinking.d.ts +1 -0
- package/types/ticketrows.d.ts +0 -9
- package/types/trigger-clock.d.ts +3 -2
- package/types/trigger-files.d.ts +15 -4
- package/types/types.d.ts +8 -0
package/src/checkblock.js
CHANGED
|
@@ -15,15 +15,16 @@
|
|
|
15
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
16
|
// The same rows store, the same asks, the same Drop/carry, the same signedRows and closeView serve both.
|
|
17
17
|
import { globToPrefix } from './globprefix.js';
|
|
18
|
-
import { countExact, countPhrase } from './pagebits.js';
|
|
18
|
+
import { countExact, countPhrase, isAmountShape, isPhraseShape, isLegalCount } from './pagebits.js';
|
|
19
19
|
import { checkFactWords, keptSetOf } from './factwords.js';
|
|
20
20
|
import { isCountable, keepOrDrop, countCheck, obviousCheck, partOfPick, plainWords } from './blockpick.js';
|
|
21
21
|
import { dropRows, dropSentence } from './pagedropwords.js';
|
|
22
22
|
import { phraseInNoResult, asSeenOf } from './pagedry.js';
|
|
23
23
|
import { boundInWords, rubricStepShapeReds, stageKeyOf, guardKeyOf, FENCE_KEY, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
|
|
24
|
-
import { validReading } from './pagerules.js';
|
|
24
|
+
import { validReading, canReadLimit } from './pagerules.js';
|
|
25
25
|
import { weekOnly, weekTokens, WEEK_ONLY_WORDS, MAX_BANG } from './checklist.js';
|
|
26
26
|
import { fitPlacePhrase } from './placerule.js';
|
|
27
|
+
import { isRowChoice } from './pickrecord.js';
|
|
27
28
|
import { ruleWords } from './pageask.js';
|
|
28
29
|
import { SIGNED_ROW_FIELDS } from './declaredclose.js';
|
|
29
30
|
import { factSentence, countSentence, factsOfLook } from './citedcheck.js';
|
|
@@ -33,6 +34,7 @@ import { sheetCheckName, sheetPlainText, coversWords } from './sheetblock.js';
|
|
|
33
34
|
import { sheetCheckBody, sheetRowKey } from './sheetrows.js';
|
|
34
35
|
import { shapeRowKey, shapeDefaultKey, shapeFieldText, buildShapePart, itemCountOf } from './shaperows.js';
|
|
35
36
|
import { fieldSpec } from './shapebuild.js';
|
|
37
|
+
import { REASON } from './reasons.js';
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* 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),
|
|
@@ -44,6 +46,8 @@ import { fieldSpec } from './shapebuild.js';
|
|
|
44
46
|
|
|
45
47
|
/** the four row edits an AI reply may hold */
|
|
46
48
|
export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable', 'fence']);
|
|
49
|
+
/** M20 am8: the one question "is this check row's kind a fact or a phrase" (a page-word row, not a count) @param {unknown} kind @returns {boolean} */
|
|
50
|
+
export const isFactKind = (kind) => kind === 'fact' || kind === 'phrase';
|
|
47
51
|
|
|
48
52
|
const norm = (/** @type {unknown} */ t) => String(t ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
|
|
49
53
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -76,30 +80,6 @@ const numberIn = (text, n) => {
|
|
|
76
80
|
};
|
|
77
81
|
const wordSet = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}]+/gu) ?? []);
|
|
78
82
|
|
|
79
|
-
/** the plain reasons code gives, in one place (the card, the Job tab and the Audit read them from the row) */
|
|
80
|
-
export const REASON = Object.freeze({
|
|
81
|
-
left: 'You chose to leave it Not checked, so you judge it at Accept.',
|
|
82
|
-
nothingOnPage: 'Your own words are on the line; the machine has no check for them, so you judge it at Accept.',
|
|
83
|
-
noRule: 'No rule can check this, so you judge it at Accept.',
|
|
84
|
-
waitingPick: 'waiting for your answer on the proposed check',
|
|
85
|
-
waitingReading: 'waiting for your answer on the reading',
|
|
86
|
-
onePerLine: 'this line finds facts, so it has no text to quote',
|
|
87
|
-
manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
|
|
88
|
-
oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
|
|
89
|
-
countNeedsFact: 'a result count needs a fact to count; this line has none',
|
|
90
|
-
countNeedsSuggested: 'a result count needs a fact to count; add the suggested fact on this line to count its results',
|
|
91
|
-
lookNoWords: "the page does not hold the words of the look's fact for this rule",
|
|
92
|
-
afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
|
|
93
|
-
noPick: 'No check was picked for it, so you judge it at Accept.',
|
|
94
|
-
itemCountByRule: 'your rule on this line sets the item count',
|
|
95
|
-
negated: 'it says what is not needed, so there is nothing to check',
|
|
96
|
-
dropped: 'You dropped it.',
|
|
97
|
-
suggested: 'Suggested: not in your job, so it is not checked unless you add it.',
|
|
98
|
-
sheetLine: 'this line reads a sheet and its rules are checked by the sheet checks, so a row edit about it is not used',
|
|
99
|
-
sheetFacts: 'this line reads a sheet, so it is checked by its sheet checks and not by page facts',
|
|
100
|
-
columnRule: "this rule only names a column; the agent's checks on this line use it",
|
|
101
|
-
});
|
|
102
|
-
|
|
103
83
|
/** 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 */
|
|
104
84
|
export function renderCard(rows) {
|
|
105
85
|
// fwd keeps: the card draws no floor row (and there is no prose row) today
|
|
@@ -407,7 +387,7 @@ export class CheckBlock {
|
|
|
407
387
|
match() {
|
|
408
388
|
// 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
|
|
409
389
|
// Airport" for the job's "Boston") says the JOB's word; the row is then job-derived (inJob below, the one owner) and its phrase check uses that word
|
|
410
|
-
if (this.split) for (const r of this.rows) if (this.isBang(r) && (r.kind
|
|
390
|
+
if (this.split) for (const r of this.rows) if (this.isBang(r) && isFactKind(r.kind)) this.takeJobWord(r);
|
|
411
391
|
for (const r of this.rows) {
|
|
412
392
|
r.can = null;
|
|
413
393
|
if (r.kind === 'floor') continue;
|
|
@@ -415,7 +395,7 @@ export class CheckBlock {
|
|
|
415
395
|
else if (r.lookWhy && r.kind === 'fact' && !r.words.length) r.can = { ok: false, why: r.lookWhy };
|
|
416
396
|
else if (r.kind === 'stage') r.can = r.refusal ? { ok: false, why: r.said } : { ok: true, how: 'stage' };
|
|
417
397
|
else if (r.kind === 'rule') this.matchRule(r);
|
|
418
|
-
else if (r.kind
|
|
398
|
+
else if (isFactKind(r.kind)) this.matchBang(r);
|
|
419
399
|
else if (r.kind === 'count') this.matchCount(r);
|
|
420
400
|
else if (r.kind === 'sheet') r.can = { ok: true, how: 'sheet' };
|
|
421
401
|
}
|
|
@@ -466,7 +446,7 @@ export class CheckBlock {
|
|
|
466
446
|
if (r.kind === 'count') return [r.min, r.max].filter((x) => Number.isInteger(x)).some((n) => numberIn(said, n));
|
|
467
447
|
// 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
|
|
468
448
|
// 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")
|
|
469
|
-
return (r.words ?? []).some((/** @type {string} */ w) => inText(said, w)) || (r.kind === 'fact' && r.shape
|
|
449
|
+
return (r.words ?? []).some((/** @type {string} */ w) => inText(said, w)) || (r.kind === 'fact' && !isPhraseShape(r.shape) && typeof r.name === 'string' && inText(said, r.name));
|
|
470
450
|
}
|
|
471
451
|
|
|
472
452
|
/**
|
|
@@ -509,7 +489,7 @@ export class CheckBlock {
|
|
|
509
489
|
if (isCountable(r.text)) { this.matchCountRule(r); return; }
|
|
510
490
|
// 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.
|
|
511
491
|
const negated = NEGATING_RE.test(r.text);
|
|
512
|
-
const isPhrase = (/** @type {any} */ l) => l.shape
|
|
492
|
+
const isPhrase = (/** @type {any} */ l) => isPhraseShape(l.shape);
|
|
513
493
|
if (negated && (r.links ?? []).length && (r.links ?? []).every(isPhrase)) { r.can = { ok: false, why: REASON.negated }; return; }
|
|
514
494
|
const links = (r.links ?? []).filter((/** @type {any} */ l) => !(negated && isPhrase(l)) && l.words.some((/** @type {string} */ w) => proved(this.textOf(l.source), w)));
|
|
515
495
|
const said = this.said(r.line);
|
|
@@ -518,7 +498,7 @@ export class CheckBlock {
|
|
|
518
498
|
for (const l of links) {
|
|
519
499
|
let reading = l.reading;
|
|
520
500
|
let ownWords = false;
|
|
521
|
-
if (l.shape
|
|
501
|
+
if (canReadLimit(l.shape)) {
|
|
522
502
|
// the person's words win (hamr 2026-11-13): code's reading of the `~` words beats the look's and the AI's; theirs is used only when code cannot read the words
|
|
523
503
|
const rd = this.wordsReading(l, r.text);
|
|
524
504
|
// fwdloop run walk-m16-flights run-1: "under $150" on a euro fact fell back to the look's reading and checked 150 euros; a bound in another currency than the page fact is never replaced by the look's or the AI's reading
|
|
@@ -728,7 +708,7 @@ export class CheckBlock {
|
|
|
728
708
|
return k ? factsOfLook(k) : null;
|
|
729
709
|
};
|
|
730
710
|
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; } }
|
|
731
|
-
} else if (countRow) { countRow.state = 'not-checked'; countRow.reason = this.rowsOn(l.n).some((x) => x.held && (x.kind
|
|
711
|
+
} else if (countRow) { countRow.state = 'not-checked'; countRow.reason = this.rowsOn(l.n).some((x) => x.held && isFactKind(x.kind)) ? REASON.countNeedsSuggested : REASON.countNeedsFact; }
|
|
732
712
|
// facts+shape: the shape part follows the fact part (the same `results` list); its fields are the rules no truth check could take
|
|
733
713
|
if (shapeRows.length > 0) this.buildShapePartOf(l, shapeRows, lineParts, lineRows);
|
|
734
714
|
for (const { p, key } of pickParts) { lineParts.push(p); lineRows.push([key]); }
|
|
@@ -794,7 +774,7 @@ export class CheckBlock {
|
|
|
794
774
|
const mk = (/** @type {string} */ name, /** @type {any} */ extra) => ({ name: cleanName(name), ...extra });
|
|
795
775
|
const kindFields = (/** @type {any} */ f, /** @type {string} */ anchor, /** @type {any} */ extra) => mk(f.name, {
|
|
796
776
|
shape: f.shape, anchor, ...(f.unit ? { unit: f.unit } : {}), ...(f.currency ? { currency: f.currency } : {}),
|
|
797
|
-
...(f.decimal && (f.shape
|
|
777
|
+
...(f.decimal && isAmountShape(f.shape) ? { decimal: f.decimal } : {}), ...(f.lang && f.shape === 'date' ? { lang: f.lang } : {}), ...extra,
|
|
798
778
|
});
|
|
799
779
|
/** @type {any[]} */ let fs;
|
|
800
780
|
if (r.kind === 'rule') {
|
|
@@ -1136,7 +1116,7 @@ export class CheckBlock {
|
|
|
1136
1116
|
|
|
1137
1117
|
editAdd(/** @type {any} */ e) {
|
|
1138
1118
|
if (e.kind === 'count') return this.addCount(e);
|
|
1139
|
-
if (e.kind
|
|
1119
|
+
if (!isFactKind(e.kind)) return { refusedBecause: 'an add is a fact, a phrase or a count' };
|
|
1140
1120
|
// an input the job does not have is refused alone (it would otherwise reach the draft gate as a red on code's own plan and stop the whole draft)
|
|
1141
1121
|
if (e.source !== undefined && e.source !== null && !this.labels.includes(e.source)) return { refusedBecause: `"${String(e.source).slice(0, 60)}" is not one of the inputs` };
|
|
1142
1122
|
// a job with more than one input never guesses which one an add quotes (code fills a missing source only when there is exactly one)
|
|
@@ -1165,13 +1145,12 @@ export class CheckBlock {
|
|
|
1165
1145
|
const rs = wordSet(rr.text);
|
|
1166
1146
|
if (wset.size && [...wset].every((w) => rs.has(w))) return `already on the list: a ~ rule says it (line ${line} rule ${rr.rule})`;
|
|
1167
1147
|
}
|
|
1168
|
-
if (this.rows.some((r) => (r.kind
|
|
1148
|
+
if (this.rows.some((r) => isFactKind(r.kind) && r.line === line && (norm(r.name) === norm(name) || norm(r.words?.[0]) === norm(words[0])))) return 'already on the list';
|
|
1169
1149
|
return null;
|
|
1170
1150
|
}
|
|
1171
1151
|
|
|
1172
1152
|
addCount(/** @type {any} */ e) {
|
|
1173
|
-
|
|
1174
|
-
if (![e.min, e.max].some(Number.isInteger) || [e.min, e.max].some((x) => x !== undefined && !ok(x)) || (Number.isInteger(e.min) && Number.isInteger(e.max) && e.min > e.max)) return { refusedBecause: 'no legal number given' };
|
|
1153
|
+
if (!isLegalCount({ min: e.min, max: e.max })) return { refusedBecause: 'no legal number given' };
|
|
1175
1154
|
if (this.rowsOn(e.line, 'count').length) return { refusedBecause: 'already on the list: this line has a result count' };
|
|
1176
1155
|
const row = this.addRow({ key: `L${e.line}.count.${e.min ?? ''}-${e.max ?? ''}`, line: e.line, kind: 'count', by: 'agent', from: 'agent', min: e.min, max: e.max });
|
|
1177
1156
|
return { accepted: true, landedKey: row.key };
|
|
@@ -1184,7 +1163,7 @@ export class CheckBlock {
|
|
|
1184
1163
|
|
|
1185
1164
|
/** the one owner of "what do the person's own words say": code's reading of a `~` rule for a money/time fact, or undefined when it cannot read it */
|
|
1186
1165
|
wordsReading(/** @type {any} */ l, /** @type {string} */ text) {
|
|
1187
|
-
if (l.shape
|
|
1166
|
+
if (!canReadLimit(l.shape)) return undefined;
|
|
1188
1167
|
const own = readLimit(l.shape, text, l);
|
|
1189
1168
|
const rd = 'reading' in own ? own.reading : undefined;
|
|
1190
1169
|
return rd && validReading(l.shape, rd) && (rd.op === 'between' ? [rd.lo, rd.hi] : [rd.value]).every((b) => boundInWords(b, text)) ? rd : undefined;
|
|
@@ -1334,7 +1313,7 @@ export class CheckBlock {
|
|
|
1334
1313
|
}
|
|
1335
1314
|
if (r.by === 'you') return { ok: false, why: 'that check comes from a rule you wrote; edit the job to change it' };
|
|
1336
1315
|
if (r.by !== 'agent' || !this.droppable(r)) return { ok: false, why: 'that check is code\'s own and stays' };
|
|
1337
|
-
if (choice
|
|
1316
|
+
if (!isRowChoice(choice)) return { ok: false, why: 'not one of the choices' };
|
|
1338
1317
|
if (r.kind === 'stage') {
|
|
1339
1318
|
// a repo work stage: Drop takes it out of the close (never the last check on its line), Add puts it back
|
|
1340
1319
|
if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
|
|
@@ -1355,7 +1334,7 @@ export class CheckBlock {
|
|
|
1355
1334
|
|
|
1356
1335
|
/** 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}[]} */
|
|
1357
1336
|
choicesRecord() {
|
|
1358
|
-
return choiceEntries(this.lines, this.rows.filter((r) => r.kind !== 'sheet' && r.kind !== 'shape' && (r.choice
|
|
1337
|
+
return choiceEntries(this.lines, this.rows.filter((r) => r.kind !== 'sheet' && r.kind !== 'shape' && isRowChoice(r.choice)).map((r) => ({ line: r.line, key: r.key, choice: String(r.choice) })));
|
|
1359
1338
|
}
|
|
1360
1339
|
|
|
1361
1340
|
/** 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 */
|
|
@@ -1363,7 +1342,7 @@ export class CheckBlock {
|
|
|
1363
1342
|
const seen = new Map();
|
|
1364
1343
|
const lines = this.lines.map((l) => { const w = norm(l.text); const o = seen.get(w) ?? 0; seen.set(w, o + 1); return { n: l.n, w, o }; });
|
|
1365
1344
|
for (const c of Array.isArray(rec) ? rec : []) {
|
|
1366
|
-
if (!c || (c.choice
|
|
1345
|
+
if (!c || !isRowChoice(c.choice)) continue;
|
|
1367
1346
|
const line = lines.find((l) => l.w === c.lineWords && l.o === c.occurrence);
|
|
1368
1347
|
const r = line ? this.rows.find((x) => x.line === line.n && this.droppable(x) && x.key.replace(/^L\d+\./, '') === c.tail) : undefined;
|
|
1369
1348
|
if (r) { r.choice = c.choice; r.keptFromLast = true; }
|
package/src/checklistsign.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Equivalent of bareloop src/rubricstep.js@v0.56.0 (3383cce) `listMatchesClose`, read over fwdloop's close fields instead of a rubric-step stage: the checks of one line, in the order the check block
|
|
3
3
|
// builds them, are [close.cited (the fact part)], [close.itemShape (the shape part, M19 S5)], then each entry of close.picked / close.shape.picked, then close.numbersFrom (the numbers tie). A signed row points at one of them by `part: {line, part: <index>}`.
|
|
4
4
|
import { isRec } from './isrec.js';
|
|
5
|
+
import { tagOf } from './checkwords.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* The checks of one step's close in the block's part order. M16 am4: with `withSheet` (a plan whose list has sheet rows) each `close.sheet` check is a part too, after the others.
|
|
@@ -77,17 +78,38 @@ const builtOn = (declaration, line) => (isRec(declaration) && Array.isArray(decl
|
|
|
77
78
|
*/
|
|
78
79
|
export function partByOf(declaration, line, idx) {
|
|
79
80
|
const r = builtOn(declaration, line).find((x) => isRec(x.part) && x.part.part === idx);
|
|
80
|
-
return r && (r.by
|
|
81
|
+
return r && tagOf(r.by) !== '' ? r.by : null;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
/** who made the fact named `name` of a list line's quote check (the row that built it), else null @param {any} declaration @param {number} line @param {string} name @returns {'you'|'agent'|'default'|null} */
|
|
84
85
|
export function factByOf(declaration, line, name) {
|
|
85
86
|
const r = builtOn(declaration, line).find((x) => Array.isArray(x.facts) && x.facts.includes(name));
|
|
86
|
-
return r && (r.by
|
|
87
|
+
return r && tagOf(r.by) !== '' ? r.by : null;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
/** who made the result count of a list line's quote check, else null @param {any} declaration @param {number} line @returns {'you'|'agent'|'default'|null} */
|
|
90
91
|
export function countByOf(declaration, line) {
|
|
91
92
|
const r = builtOn(declaration, line).find((x) => x.kind === 'count');
|
|
92
|
-
return r && (r.by
|
|
93
|
+
return r && tagOf(r.by) !== '' ? r.by : null;
|
|
93
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The proof of a plan whose list has ticket rows (a plan with none is not examined): a built ticket row needs the declaration's field, and a field the declaration holds needs a built row for it.
|
|
98
|
+
* @param {any} declaration @returns {string[]}
|
|
99
|
+
*/
|
|
100
|
+
export function ticketListReds(declaration) {
|
|
101
|
+
const list = isRec(declaration) && Array.isArray(declaration.checkList) ? declaration.checkList.filter((/** @type {any} */ r) => isRec(r) && r.kind === 'ticket') : [];
|
|
102
|
+
if (list.length === 0) return [];
|
|
103
|
+
/** @type {string[]} */
|
|
104
|
+
const reds = [];
|
|
105
|
+
for (const f of TICKET_FIELDS) {
|
|
106
|
+
const built = list.some((/** @type {any} */ r) => r.field === f && r.state === 'built');
|
|
107
|
+
const has = Object.hasOwn(declaration, f);
|
|
108
|
+
if (built && !has) reds.push(`declaration: checkList: a row says "${f}" is its check, but the plan has no "${f}". Nothing was signed - draft again.`);
|
|
109
|
+
if (has && !built) reds.push(`declaration: "${f}" is not the check of any rule on the list. Nothing was signed - draft again.`);
|
|
110
|
+
}
|
|
111
|
+
return reds;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** @type {readonly ('ticketFilter'|'ticketWatch')[]} */
|
|
115
|
+
export const TICKET_FIELDS = Object.freeze(['ticketFilter', 'ticketWatch']);
|
package/src/checklook.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// The card (src/cardlist.js), the Audit (src/auditchecks.js), the draft readout (src/authoring.js) and the page all take their kind word and their Not-checked split from these.
|
|
4
4
|
// What this throws away: a Not checked item's own quotes round a whole rule and the reason "you judge it at Accept" (the group title says it).
|
|
5
5
|
|
|
6
|
+
import { tagOf } from './checkwords.js';
|
|
7
|
+
|
|
6
8
|
/** the group titles and the tail of the Not checked one (section 3.7, copied unchanged) */
|
|
7
9
|
export const LOOK = Object.freeze({
|
|
8
10
|
checked: 'CHECKED', notChecked: 'NOT CHECKED', notCheckedTail: 'you judge these at Accept', suggested: 'SUGGESTED · add if you want it', everyLine: 'Every line',
|
|
@@ -40,6 +42,6 @@ export function ncRowsOf(items, by = {}) {
|
|
|
40
42
|
const m = /^line (\d+): ([\s\S]*)$/.exec(raw);
|
|
41
43
|
const body = (m ? m[2] : raw).replace(/^not checked · /, '');
|
|
42
44
|
const tag = by[raw];
|
|
43
|
-
return { line: m ? Number(m[1]) : 0, ...splitNotChecked(body), ...(tag
|
|
45
|
+
return { line: m ? Number(m[1]) : 0, ...splitNotChecked(body), ...(tagOf(tag) !== '' ? { by: /** @type {'you'|'agent'|'default'} */ (tag) } : {}) };
|
|
44
46
|
});
|
|
45
47
|
}
|
package/src/checkpick.js
CHANGED
|
@@ -10,15 +10,14 @@ import { isCellsPath } from './closers.js';
|
|
|
10
10
|
import { plainWords, OFFERED } from './checkwords.js';
|
|
11
11
|
|
|
12
12
|
export { plainWords, OFFERED };
|
|
13
|
-
import {
|
|
13
|
+
import { isCountable, keepOrDrop, countCheck } from './blockpick.js';
|
|
14
|
+
import { HOW_TO_ANSWER } from './pageask.js';
|
|
14
15
|
|
|
15
16
|
/** the one tool the suggestion call is forced to use */
|
|
16
17
|
export const SUGGEST_TOOL = 'suggest_checks';
|
|
17
18
|
const VOCAB = /** @type {Record<string, {description: string, fields: Record<string, {type: string, required?: boolean}>}>} */ (rubricVocabulary.rules);
|
|
18
19
|
/** fields code sets, or that never decide: never offered, never kept */
|
|
19
20
|
const IGNORED = new Set(['id', 'field', 'text', 'strict']);
|
|
20
|
-
const NUM_FIELDS = ['value', 'size', 'wordsPerSection'];
|
|
21
|
-
const WORD_FIELDS = ['names', 'phrases'];
|
|
22
21
|
|
|
23
22
|
// ---- scope, decided by CODE before the call ------------------------------------------------------------------------------------------------
|
|
24
23
|
/** @param {any[]|undefined} sources the job's signed inputs @returns {boolean} a CSV file or a web page routes its guardrails to another signed part (M10 items 1-3, M12) */
|
|
@@ -28,7 +27,7 @@ export const hasRoutingInput = (sources) => (sources ?? []).some((s) => (s.kind
|
|
|
28
27
|
* (the one thing the shape reader still takes in such a job). A page job whose guardrail is a count therefore counts as in (F144b caveat).
|
|
29
28
|
* @param {any[]|undefined} sources @param {string} g @returns {'in'|'out'}
|
|
30
29
|
*/
|
|
31
|
-
export const codeScope = (sources, g) => (hasRoutingInput(sources) && !
|
|
30
|
+
export const codeScope = (sources, g) => (hasRoutingInput(sources) && !isCountable(g) ? 'out' : 'in');
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* Every guardrail rule on a step line (not a signed ask or send line) that this call settles, in line order. `rule` is the rule's number on its line (the one
|
|
@@ -57,57 +56,9 @@ export function scopedRules(lines, arbiter) {
|
|
|
57
56
|
* The rules the suggestion call offers for a draft: `scopedRules` less the ones a kept page or sheet fact already serves (the look tied it: line + rule number).
|
|
58
57
|
* @param {{n: number, guardrail?: string}[]} lines @param {any} arbiter @param {{line: number, forRule?: number}[]} facts `look.facts` + the sheets' facts
|
|
59
58
|
*/
|
|
60
|
-
export const offerRules = (lines, arbiter, facts) => scopedRules(lines, arbiter).filter((r) =>
|
|
59
|
+
export const offerRules = (lines, arbiter, facts) => scopedRules(lines, arbiter).filter((r) => isCountable(r.text) || !facts.some((f) => f.line === r.line && f.forRule === r.rule));
|
|
61
60
|
|
|
62
|
-
// ---- code's keep-or-drop (
|
|
63
|
-
const norm = (/** @type {unknown} */ t) => String(t).toLowerCase().replace(/\s+/g, ' ').trim();
|
|
64
|
-
const tokens = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}]+/gu) ?? []);
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Keep a suggestion only if its rule is on bareguard's list, it carries only that rule's own fields, every number in it is a number the guardrail names and
|
|
68
|
-
* every word in it is a word of the guardrail. Anything else is dropped, with the reason. `none` is a drop with the reason `none`.
|
|
69
|
-
* @param {string} guardrail @param {any} sug the model's entry for this guardrail
|
|
70
|
-
* @returns {{kept: true, check: Record<string, any>}|{kept: false, why: string}}
|
|
71
|
-
*/
|
|
72
|
-
export function keepOrDrop(guardrail, sug) {
|
|
73
|
-
if (sug == null || typeof sug !== 'object') return { kept: false, why: 'unreadable suggestion' };
|
|
74
|
-
const { rule } = sug;
|
|
75
|
-
if (rule === 'none' || rule === undefined || rule === null) return { kept: false, why: 'none' };
|
|
76
|
-
if (typeof rule !== 'string' || !Object.hasOwn(VOCAB, rule)) return { kept: false, why: `rule "${rule}" is not on bareguard's list` };
|
|
77
|
-
if (!OFFERED.includes(rule)) return { kept: false, why: `rule "${rule}" is on bareguard's list but is not offered here` };
|
|
78
|
-
const own = Object.keys(VOCAB[rule].fields).filter((k) => !IGNORED.has(k));
|
|
79
|
-
for (const k of own) if (VOCAB[rule].fields[k].required && sug[k] == null) return { kept: false, why: `${rule} needs ${k}` };
|
|
80
|
-
const allowed = new Set([...own, 'rule', 'line', 'guardrail']);
|
|
81
|
-
for (const k of Object.keys(sug)) if (sug[k] != null && !allowed.has(k)) return { kept: false, why: `${rule} does not take ${k}` };
|
|
82
|
-
/** @type {Record<string, any>} */
|
|
83
|
-
const check = { rule };
|
|
84
|
-
for (const k of own) {
|
|
85
|
-
const v = sug[k];
|
|
86
|
-
if (v == null) continue;
|
|
87
|
-
if (NUM_FIELDS.includes(k)) {
|
|
88
|
-
if (!Number.isInteger(v) || v < 1) return { kept: false, why: `${k} ${JSON.stringify(v)} is not a whole number >= 1` };
|
|
89
|
-
const named = rule === 'maxWords' || rule === 'minWords' ? guardrailWordNumbers(guardrail)
|
|
90
|
-
: k === 'wordsPerSection' ? [guardrailWordsPerSection(guardrail)].filter((x) => x !== null)
|
|
91
|
-
: guardrailStandaloneNumbers(guardrail);
|
|
92
|
-
if (!named.includes(v)) return { kept: false, why: `${k} ${v} is not a number the guardrail names (${named.join(', ') || 'it names none'})` };
|
|
93
|
-
check[k] = v;
|
|
94
|
-
} else if (WORD_FIELDS.includes(k)) {
|
|
95
|
-
if (!Array.isArray(v) || v.length === 0 || v.some((s) => typeof s !== 'string' || s.trim() === '')) return { kept: false, why: `${k} is not a list of words` };
|
|
96
|
-
const gTok = tokens(guardrail);
|
|
97
|
-
const gNorm = norm(guardrail);
|
|
98
|
-
for (const s of v) {
|
|
99
|
-
if (!gNorm.includes(norm(s))) return { kept: false, why: `${k} "${s}" is not in the guardrail's words` };
|
|
100
|
-
for (const t of tokens(s)) if (!gTok.has(t)) return { kept: false, why: `${k} word "${t}" is not a word of the guardrail` };
|
|
101
|
-
}
|
|
102
|
-
check[k] = v;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (rule === 'sections' || rule === 'sectionOrder' || rule === 'sectionWords') {
|
|
106
|
-
const want = guardrailSectionCount(guardrail);
|
|
107
|
-
if (want !== null && check.names.length !== want) return { kept: false, why: `the guardrail says ${want} sections; the check has ${check.names.length}` };
|
|
108
|
-
}
|
|
109
|
-
return { kept: true, check };
|
|
110
|
-
}
|
|
61
|
+
// ---- code's keep-or-drop: src/blockpick.js (M20 am8 item 3: keepOrDrop and countCheck have one body there) ----------------------------------------------------------
|
|
111
62
|
|
|
112
63
|
// ---- the call: prompt, answer form -------------------------------------------------------------------------------------------------------
|
|
113
64
|
const vocabBlock = OFFERED.map((r) => `- ${VOCAB[r].description}`).join('\n');
|
|
@@ -181,31 +132,9 @@ export function rowsFromAnswer(scoped, args) {
|
|
|
181
132
|
});
|
|
182
133
|
}
|
|
183
134
|
|
|
184
|
-
// borrowed-from: bareloop src/checkpick.js@0408a8f (countCheck, 5a81681; one reader file differs: fwdloop's declaration.js has the same three readers)
|
|
185
|
-
/**
|
|
186
|
-
* The check CODE proposes for a count rule when the call yields none: a bullets / list-items / points count -> listItems N, a lines count -> maxLines N, ONE word number ->
|
|
187
|
-
* minWords N when the rule says "at least / minimum / more than", else maxWords N. A section count names no sections, so none is built; a rule naming two different counts is
|
|
188
|
-
* not built either; a rule with several word numbers or a range is not guessed. The result passes `keepOrDrop`, so every number is one the rule names.
|
|
189
|
-
* @param {string} text @returns {Record<string, any>|null}
|
|
190
|
-
*/
|
|
191
|
-
export function countCheck(text) {
|
|
192
|
-
const items = guardrailItemCount(text);
|
|
193
|
-
const words = guardrailWordNumbers(text);
|
|
194
|
-
/** @type {Record<string, any>|null} */
|
|
195
|
-
let built = null;
|
|
196
|
-
if (items !== null && (words.length > 0 || guardrailSectionCount(text) !== null)) return null;
|
|
197
|
-
if (items !== null) built = { rule: /\blines?\b/i.test(text) && !/\b(bullets?|items?|points?)\b/i.test(text) ? 'maxLines' : 'listItems', value: items };
|
|
198
|
-
else if (words.length === 1 && !/\bbetween\b|\d\s*(?:-|–|to)\s*\d/i.test(text)) built = { rule: /\b(at least|min(?:imum)?|more than|over|no fewer than)\b/i.test(text) ? 'minWords' : 'maxWords', value: words[0] };
|
|
199
|
-
if (built === null) return null;
|
|
200
|
-
const res = keepOrDrop(text, built);
|
|
201
|
-
return res.kept ? res.check : null;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
135
|
// ---- the asks (words are item 4's) -----------------------------------------------------------------------------------------------------
|
|
205
136
|
/** the can't-check ask, as the signed words say it */
|
|
206
137
|
export const CANT_CHECK_WORDS = "I can't check this. Your own words, or Not checked?";
|
|
207
|
-
/** how every answer is told, once (am2 item 2's words) */
|
|
208
|
-
export const HOW_TO_ANSWER = (/** @type {number} */ line, /** @type {boolean} */ agree) => `${agree ? 'Answer "agree" to use it, or type your own words' : 'Type your own words'} (your answer replaces that ~ rule on line ${line}), or answer "drop it" to leave it Not checked.`;
|
|
209
138
|
|
|
210
139
|
/**
|
|
211
140
|
* The asks for the rows: `Line n, guardrail "<…>": I propose <check in plain words>.` for a kept check, `Line n, guardrail "<…>": I can't check this. Your own words, or
|
package/src/cited-source.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// the copy is missing or changed); a step that merely READS a role (src/runner.js readArtifactsMapChecked) halts only on 'unreadable'.
|
|
8
8
|
import { createHash } from 'node:crypto';
|
|
9
9
|
import { basename } from 'node:path';
|
|
10
|
-
import { readFileInside, resolveInside } from './
|
|
11
|
-
import { readRunInputs } from './runfile.js';
|
|
10
|
+
import { readFileInside, resolveInside } from './inside.js';
|
|
11
|
+
import { readRunInputs, frozenRel } from './runfile.js';
|
|
12
12
|
import { readDocxSource } from './docx.js';
|
|
13
13
|
|
|
14
14
|
/** the frozen files served as text: a saved page (.txt) or a text/markdown document. Any other kind (a spreadsheet, a .docx, a binary) is never served as text. */
|
|
@@ -28,7 +28,7 @@ export function readRunSource(runDir, role, { docx = false } = {}) {
|
|
|
28
28
|
const lower = entry.frozen.toLowerCase();
|
|
29
29
|
if (docx && lower.endsWith('.docx')) return readRunDocx(runDir, role, entry);
|
|
30
30
|
if (!TEXT_EXTS.some((x) => lower.endsWith(x))) return { ok: false, code: 'not-text', red: `input "${role}": a quote can be checked against a web page, a text file or a .docx here, not "${basename(entry.frozen)}"` };
|
|
31
|
-
const file = readFileInside(runDir,
|
|
31
|
+
const file = readFileInside(runDir, frozenRel(entry.frozen));
|
|
32
32
|
if (!file.ok) return { ok: false, code: 'unreadable', red: file.missing ? `input "${role}": the frozen copy is missing` : `input "${role}": ${file.red}` };
|
|
33
33
|
const sha256 = createHash('sha256').update(file.text, 'utf8').digest('hex');
|
|
34
34
|
if (sha256 !== entry.sha256) return { ok: false, code: 'unreadable', red: `input "${role}": the frozen copy changed since it was frozen` };
|
|
@@ -39,7 +39,7 @@ export function readRunSource(runDir, role, { docx = false } = {}) {
|
|
|
39
39
|
* @param {string} runDir @param {string} role @param {{frozen: string, sha256: string}} entry
|
|
40
40
|
* @returns {{ok: true, text: string, sha256: string, frozen: string}|{ok: false, red: string, code: 'unreadable'}} */
|
|
41
41
|
function readRunDocx(runDir, role, entry) {
|
|
42
|
-
const where = resolveInside(runDir,
|
|
42
|
+
const where = resolveInside(runDir, frozenRel(entry.frozen));
|
|
43
43
|
if (!where.ok) return { ok: false, code: 'unreadable', red: where.missing ? `input "${role}": the frozen copy is missing` : `input "${role}": ${where.red}` };
|
|
44
44
|
const doc = readDocxSource(where.full);
|
|
45
45
|
if (!doc.ok) return { ok: false, code: 'unreadable', red: `input "${role}": ${doc.red}` };
|
package/src/citedcheck.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { createHash } from 'node:crypto';
|
|
17
17
|
import { createRubric, checkStep } from 'bareguard';
|
|
18
18
|
import { plainWords } from './checkwords.js';
|
|
19
|
-
import { asList, FACT_OPS, boundOk, MAX_CURRENCIES, MAX_UNITS, MAX_UNIT_CHARS } from './pagebits.js';
|
|
19
|
+
import { asList, FACT_OPS, boundOk, isAmountShape, isPhraseShape, isLegalCount, MAX_CURRENCIES, MAX_UNITS, MAX_UNIT_CHARS } from './pagebits.js';
|
|
20
20
|
import { ruleWords, moneyAs } from './pageask.js';
|
|
21
21
|
import { placeRuleProblem } from './placerule.js';
|
|
22
22
|
|
|
@@ -69,7 +69,7 @@ function unitsOnce(units) {
|
|
|
69
69
|
* @param {any} k a fact from `lookFactOf` (src/pagelook.js) @returns {Record<string, any>[]}
|
|
70
70
|
*/
|
|
71
71
|
export function factsOfLook(k) {
|
|
72
|
-
if (k.shape
|
|
72
|
+
if (isPhraseShape(k.shape)) {
|
|
73
73
|
// M19 am5: a plain phrase fact (no `phrases`) with several look words signs ALL of them as one fact (any one, on word edges); one word signs `phrase` as before
|
|
74
74
|
const alts = Array.isArray(k.phrases) ? [] : [...new Set(/** @type {unknown[]} */ (Array.isArray(k.words) ? k.words : []).map(String))];
|
|
75
75
|
if (alts.length > 1) return [{ name: String(k.name), shape: 'phrase', anyOf: alts }];
|
|
@@ -121,7 +121,7 @@ export function factPartReds(part) {
|
|
|
121
121
|
if (f.shape !== 'phrase' && (f.phrase !== undefined || f.anyOf !== undefined)) reds.push(`${w} "${f.name}": only a phrase fact carries phrase`);
|
|
122
122
|
// the four fields of bareloop v0.56.0 (M16 am3 (3)); each is checked only when present, so a fact without them is judged exactly as before
|
|
123
123
|
if (f.lang !== undefined && (f.shape !== 'date' || typeof f.lang !== 'string' || !Object.hasOwn(FACT_LANGS, f.lang))) reds.push(`${w} "${f.name}": lang is for a date fact, one of ${Object.keys(FACT_LANGS).join(', ')}`);
|
|
124
|
-
if (f.decimal !== undefined && ((f.shape
|
|
124
|
+
if (f.decimal !== undefined && (!isAmountShape(f.shape) || !FACT_DECIMALS.includes(f.decimal))) reds.push(`${w} "${f.name}": decimal is for a number or money fact, "." or ","`);
|
|
125
125
|
if (f.place !== undefined) { const bad = f.shape === 'phrase' ? placeRuleProblem(f.place) : 'only a phrase fact carries a place rule'; if (bad !== null) reds.push(`${w} "${f.name}": ${bad}`); }
|
|
126
126
|
if (f.aiProposal !== undefined && typeof f.aiProposal !== 'boolean') reds.push(`${w} "${f.name}": aiProposal is true or false`);
|
|
127
127
|
if (f.until !== undefined && (f.anchor === undefined || f.shape !== 'text')) reds.push(`${w} "${f.name}": until closes a text fact that has an anchor, and nothing else`);
|
|
@@ -136,9 +136,7 @@ export function factPartReds(part) {
|
|
|
136
136
|
});
|
|
137
137
|
const c = part.count;
|
|
138
138
|
if (c !== undefined) {
|
|
139
|
-
|
|
140
|
-
&& ['min', 'max'].every((k) => c[k] === undefined || (Number.isInteger(c[k]) && c[k] >= 1)) && (c.min === undefined || c.max === undefined || c.min <= c.max);
|
|
141
|
-
if (!ok) reds.push('the result count is {min, max}: whole numbers, 1 or more, min no more than max');
|
|
139
|
+
if (!isLegalCount(c)) reds.push('the result count is {min, max}: whole numbers, 1 or more, min no more than max');
|
|
142
140
|
}
|
|
143
141
|
return reds;
|
|
144
142
|
}
|
|
@@ -320,7 +318,7 @@ export function factShapeReds(part, w, red) {
|
|
|
320
318
|
else if (typeof f.lang !== 'string' || !Object.hasOwn(FACT_LANGS, f.lang)) red('invalid-value', `${fw}.lang`, `one of ${Object.keys(FACT_LANGS).join(' | ')}`);
|
|
321
319
|
}
|
|
322
320
|
if (has('decimal')) {
|
|
323
|
-
if (f.shape
|
|
321
|
+
if (!isAmountShape(f.shape)) red('invalid-value', `${fw}.decimal`, 'only a number or money fact carries decimal (the mark the page writes before the decimals)');
|
|
324
322
|
else if (!FACT_DECIMALS.includes(f.decimal)) red('invalid-value', `${fw}.decimal`, 'one of "." | ","');
|
|
325
323
|
}
|
|
326
324
|
if (f.shape === 'phrase') {
|
|
@@ -349,10 +347,7 @@ export function factShapeReds(part, w, red) {
|
|
|
349
347
|
}
|
|
350
348
|
if (Object.hasOwn(part, 'count')) {
|
|
351
349
|
const c = part.count;
|
|
352
|
-
|
|
353
|
-
&& ['min', 'max'].every((k) => !Object.hasOwn(c, k) || (Number.isInteger(c[k]) && c[k] >= 1))
|
|
354
|
-
&& (!Object.hasOwn(c, 'min') || !Object.hasOwn(c, 'max') || c.min <= c.max);
|
|
355
|
-
if (!ok) red('invalid-value', `${w}.count`, '{min?, max?} — how many results the person asked for (integers, 1 or more, min no more than max)');
|
|
350
|
+
if (!isLegalCount(c)) red('invalid-value', `${w}.count`, '{min?, max?} — how many results the person asked for (integers, 1 or more, min no more than max)');
|
|
356
351
|
}
|
|
357
352
|
}
|
|
358
353
|
|
package/src/citedwords.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// Pure: no I/O, no model. Compared white-space blind. Third outcome, named: a source with no page-read (md text, a page the look never read) is a red
|
|
10
10
|
// `unread` - a check whose words were never proved against the source is never signed. What this throws away: nothing; every red is a sentence.
|
|
11
11
|
|
|
12
|
-
import { asList, boundInWords, countExact, countPhrase, normLabel, wordsSaidOn } from './pagebits.js';
|
|
12
|
+
import { asList, boundInWords, countExact, countPhrase, isAmountShape, normLabel, wordsSaidOn } from './pagebits.js';
|
|
13
13
|
import { validReading } from './pagerules.js';
|
|
14
14
|
import { ruleWords } from './pageask.js';
|
|
15
15
|
import { dropSentence } from './pagedropwords.js';
|
|
@@ -123,7 +123,7 @@ export function numberRuleReds({ part, jobLine }) {
|
|
|
123
123
|
const reds = [];
|
|
124
124
|
const said = numbersSaid(wordsSaidOn(jobLine));
|
|
125
125
|
const isSaid = (/** @type {string} */ shape, /** @type {unknown} */ b) => {
|
|
126
|
-
if (shape
|
|
126
|
+
if (isAmountShape(shape)) return typeof b === 'number' && (said.bare.has(b) || said.amount.has(b));
|
|
127
127
|
if (shape === 'time') return typeof b === 'string' && said.time.has(timeKey(b));
|
|
128
128
|
if (shape === 'date') return typeof b === 'string' && said.date.has(b);
|
|
129
129
|
return false;
|
|
@@ -148,9 +148,10 @@ const NUMBER_WORDS = Object.freeze({ one: 1, two: 2, three: 3, four: 4, five: 5,
|
|
|
148
148
|
/**
|
|
149
149
|
* Signed (am7 item 1): "List 3 ..." is the count, 3 results. A count the person never said as a bare number or a word number (not inside a time, a date or an
|
|
150
150
|
* amount) is refused. Same reader as the number rules.
|
|
151
|
-
*
|
|
151
|
+
* M20 am4: a number the person switched on with Add (`added`, src/pickrecord.js `addedCountsOf`: `<line>:min:<n>` / `<line>:max:<n>`) reads as said.
|
|
152
|
+
* @param {{part: any, jobLine: {n: number, text?: string, rule?: string, rules?: string[]}, added?: Set<string>}} o @returns {WordRed[]}
|
|
152
153
|
*/
|
|
153
|
-
export function countReds({ part, jobLine }) {
|
|
154
|
+
export function countReds({ part, jobLine, added }) {
|
|
154
155
|
/** @type {WordRed[]} */
|
|
155
156
|
const reds = [];
|
|
156
157
|
const text = wordsSaidOn(jobLine);
|
|
@@ -158,7 +159,7 @@ export function countReds({ part, jobLine }) {
|
|
|
158
159
|
for (const w of text.toLowerCase().split(/[^\p{L}\p{N}]+/u)) { const n = NUMBER_WORDS[/** @type {'one'} */ (w)]; if (n !== undefined) said.add(n); }
|
|
159
160
|
const c = part.count && typeof part.count === 'object' ? part.count : {};
|
|
160
161
|
for (const k of ['min', 'max']) {
|
|
161
|
-
if (c[k] === undefined || said.has(c[k])) continue;
|
|
162
|
+
if (c[k] === undefined || said.has(c[k]) || added?.has(`${jobLine.n}:${k}:${c[k]}`)) continue;
|
|
162
163
|
reds.push({ code: 'count-unsigned', detail: `line ${jobLine.n}: the result count has the number ${c[k]}, but ${c[k]} is not in your words on line ${jobLine.n}. The count is the number you asked for ("List 3" is 3 results); say it on the line, or leave the count out.` });
|
|
163
164
|
}
|
|
164
165
|
return reds;
|
|
@@ -220,15 +221,15 @@ export function boundReds({
|
|
|
220
221
|
|
|
221
222
|
/**
|
|
222
223
|
* Every word red for one cited part, in the order a person fixes them.
|
|
223
|
-
* @param {{part: any, text: string|undefined, line: number, jobLine: any, look: {facts?: any[], dropped?: any[]}|null|undefined, doc?: boolean}} o @returns {WordRed[]}
|
|
224
|
+
* @param {{part: any, text: string|undefined, line: number, jobLine: any, look: {facts?: any[], dropped?: any[]}|null|undefined, doc?: boolean, added?: Set<string>}} o @returns {WordRed[]}
|
|
224
225
|
*/
|
|
225
226
|
export function citedWordReds({
|
|
226
|
-
part, text, line, jobLine, look, doc = false,
|
|
227
|
+
part, text, line, jobLine, look, doc = false, added,
|
|
227
228
|
}) {
|
|
228
229
|
// M10 piece 5 (item 2): a DOCUMENT has no page-word map; its words are proved on its text alone (a label need not be one a map kept)
|
|
229
230
|
const kept = doc ? { labels: null, words: new Set(), dropped: new Map() } : keptSetOf(look, part.source);
|
|
230
231
|
if (typeof text !== 'string' || kept === null) {
|
|
231
232
|
return [{ code: 'unread', detail: `line ${line}: the input "${part.source}" was not read here to prove the words against it, so a check on it cannot be drafted. A check on quotes works on a saved web page.` }];
|
|
232
233
|
}
|
|
233
|
-
return [...factWordReds({ part, text, line, kept }), ...numberRuleReds({ part, jobLine }), ...countReds({ part, jobLine }), ...placeReds({ part, line, look }), ...boundReds({ part, line, jobLine, look })];
|
|
234
|
+
return [...factWordReds({ part, text, line, kept }), ...numberRuleReds({ part, jobLine }), ...countReds({ part, jobLine, added }), ...placeReds({ part, line, look }), ...boundReds({ part, line, jobLine, look })];
|
|
234
235
|
}
|
package/src/closers.js
CHANGED
|
@@ -120,10 +120,13 @@ export async function closeItemShape(step, artifact) {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/** M20 am8: the one question "did the closer render NO judgment" (a third outcome: crash or unparseable, never green and never red) @param {unknown} verdict a CloseVerdict's `verdict` @returns {boolean} */
|
|
124
|
+
export const noJudgment = (verdict) => verdict === 'crash' || verdict === 'unparseable';
|
|
125
|
+
|
|
123
126
|
/** the items check beside the facts line's own verdict: red if either is red (both told, the fact half first); a third outcome of either is never turned into green, the fact half's winning when it has one @param {any} base @param {any} sh @returns {CloseVerdict} */
|
|
124
127
|
function withItemShape(base, sh) {
|
|
125
|
-
if (base.verdict
|
|
126
|
-
if (sh.verdict
|
|
128
|
+
if (noJudgment(base.verdict)) return base;
|
|
129
|
+
if (noJudgment(sh.verdict)) return { ...sh, ...(base.cited ? { cited: base.cited } : {}) };
|
|
127
130
|
if (sh.verdict === 'green') return base;
|
|
128
131
|
const reds = [...(base.verdict === 'red' ? String(base.red).split('\n') : []), ...sh.reds];
|
|
129
132
|
return { ...base, verdict: 'red', red: reds.join('\n'), reds, shapeGaps: sh.shapeGaps };
|
|
@@ -350,8 +353,8 @@ export function closeNumbers(step, artifact, from, numbers) {
|
|
|
350
353
|
/** the numbers tie beside the class's own verdict: red if either is red (both told); a third outcome of either is never turned into green, the class's own winning when it has one @param {any} base @param {ReturnType<typeof closeNumbers>} num @returns {CloseVerdict} */
|
|
351
354
|
function withNumbers(base, num) {
|
|
352
355
|
const numbersCheck = { text: num.text, ok: num.verdict === 'green', result: num.verdict === 'green' ? null : num.verdict === 'red' ? num.red : num.verdict };
|
|
353
|
-
if (base.verdict
|
|
354
|
-
if (num.verdict
|
|
356
|
+
if (noJudgment(base.verdict)) return { ...base, numbersCheck };
|
|
357
|
+
if (noJudgment(num.verdict)) return { ...num, verdict: num.verdict, red: num.red, ...(base.cited ? { cited: base.cited } : {}), numbersCheck };
|
|
355
358
|
if (num.verdict === 'green') return { ...base, numbersCheck };
|
|
356
359
|
const reds = [...(base.verdict === 'red' ? [base.red] : []), num.red].filter(Boolean);
|
|
357
360
|
return { ...base, verdict: 'red', red: reds.join('\n'), ...(base.reds || reds.length > 1 ? { reds } : {}), numbersCheck };
|
|
@@ -380,8 +383,8 @@ async function closeFactAndPicks(step, artifact, ctx) {
|
|
|
380
383
|
? await closeSoftgreen({ text }, { picked })
|
|
381
384
|
: { verdict: 'red', red: 'no text: the answer has no "text" for your checks to read', checks: [{ id: 'text', text: plainWords({ rule: 'nonEmpty' }), ok: false, result: 'no text' }] });
|
|
382
385
|
const pickChecks = Array.isArray(picks.checks) ? picks.checks.filter((/** @type {any} */ c) => c.id !== 'keys') : picks.checks; // the one-key row is code's, always true here
|
|
383
|
-
if (fact.verdict
|
|
384
|
-
if (picks.verdict
|
|
386
|
+
if (noJudgment(fact.verdict)) return { ...fact, pickChecks };
|
|
387
|
+
if (noJudgment(picks.verdict)) return fact.verdict === 'red' ? { ...fact, pickChecks } : { ...picks, cited: fact.cited, sheetRecord: fact.sheetRecord, checks: fact.checks };
|
|
385
388
|
if (fact.verdict === 'green' && picks.verdict === 'green') return { ...fact, pickChecks };
|
|
386
389
|
const reds = [...(fact.verdict === 'red' ? [fact.red] : []), ...(picks.verdict === 'red' ? [picks.red] : [])].filter(Boolean);
|
|
387
390
|
return { ...fact, verdict: 'red', red: reds.join('\n'), reds, pickChecks };
|