fwdloop 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fwdloop +8 -2
- package/package.json +2 -2
- package/src/auditchecks.js +53 -0
- package/src/authoring.js +52 -12
- package/src/blockasks.js +44 -0
- package/src/blockassemble.js +140 -0
- package/src/blockdraft.js +91 -0
- package/src/blocklines.js +30 -0
- package/src/blockpick.js +165 -0
- package/src/cardlist.js +19 -0
- package/src/checkblock.js +804 -0
- package/src/checked.js +48 -9
- package/src/checklist.js +99 -0
- package/src/checklistsign.js +93 -0
- package/src/checkwords.js +20 -1
- package/src/cited-record.js +21 -1
- package/src/citedcheck.js +162 -7
- package/src/closers.js +41 -3
- package/src/declaration.js +25 -2
- package/src/declaredclose.js +4 -0
- package/src/draft-steps.js +3 -1
- package/src/drafter.js +244 -134
- package/src/factwords.js +112 -0
- package/src/inputlook.js +53 -0
- package/src/jsonbrace.js +21 -0
- package/src/labelscan.js +162 -0
- package/src/pageask.js +4 -1
- package/src/pagedropwords.js +11 -1
- package/src/panel/author.js +76 -5
- package/src/panel/authorcard.js +9 -6
- package/src/panel/data.js +41 -9
- package/src/panel/index.html +202 -13
- package/src/panel/result.js +4 -3
- package/src/panel/server.js +3 -1
- package/src/pickrecord.js +28 -0
- package/src/placerule.js +398 -0
- package/src/planrebuild.js +206 -0
- package/src/rowedit.js +118 -0
- package/src/rubricstep.js +264 -0
- package/src/runfile.js +4 -2
- package/src/runner.js +67 -10
- package/src/setup.js +10 -4
- package/src/sheetblock.js +6 -2
- package/src/sheetchecks.js +49 -64
- package/src/sheetclaims.js +12 -32
- package/src/sheetlook.js +2 -2
- package/src/sheetoffer.js +25 -53
- package/src/sheetrows.js +107 -0
- package/src/sheetrun.js +31 -1
- package/src/summary-words.js +3 -3
- package/src/try-checks.js +31 -12
- package/src/types.js +1 -0
- package/types/auditchecks.d.ts +24 -0
- package/types/authoring.d.ts +18 -1
- package/types/blockasks.d.ts +37 -0
- package/types/blockassemble.d.ts +33 -0
- package/types/blockdraft.d.ts +83 -0
- package/types/blocklines.d.ts +31 -0
- package/types/blockpick.d.ts +41 -0
- package/types/cardlist.d.ts +21 -0
- package/types/checkblock.d.ts +363 -0
- package/types/checked.d.ts +16 -2
- package/types/checklist.d.ts +115 -0
- package/types/checklistsign.d.ts +27 -0
- package/types/checkwords.d.ts +5 -0
- package/types/cited-record.d.ts +9 -0
- package/types/citedcheck.d.ts +33 -2
- package/types/closers.d.ts +24 -2
- package/types/declaredclose.d.ts +2 -0
- package/types/drafter.d.ts +15 -361
- package/types/factwords.d.ts +38 -0
- package/types/inputlook.d.ts +49 -0
- package/types/jsonbrace.d.ts +8 -0
- package/types/labelscan.d.ts +35 -0
- package/types/pageask.d.ts +2 -0
- package/types/panel/author.d.ts +41 -0
- package/types/panel/authorcard.d.ts +1 -1
- package/types/panel/data.d.ts +4 -2
- package/types/panel/jobgrid.d.ts +1 -1
- package/types/pickrecord.d.ts +22 -0
- package/types/placerule.d.ts +208 -0
- package/types/planrebuild.d.ts +52 -0
- package/types/provider.d.ts +1 -1
- package/types/rowedit.d.ts +33 -0
- package/types/rubricstep.d.ts +60 -0
- package/types/runfile.d.ts +5 -2
- package/types/runner.d.ts +45 -1
- package/types/sheetblock.d.ts +1 -0
- package/types/sheetchecks.d.ts +10 -17
- package/types/sheetclaims.d.ts +2 -1
- package/types/sheetoffer.d.ts +5 -5
- package/types/sheetrows.d.ts +73 -0
- package/types/sheetrun.d.ts +12 -0
- package/types/summary-words.d.ts +2 -1
- package/types/try-checks.d.ts +4 -2
- package/types/types.d.ts +8 -0
package/src/checked.js
CHANGED
|
@@ -10,9 +10,15 @@
|
|
|
10
10
|
|
|
11
11
|
/** The label that always sits with the "Not checked" list (am41 item 3: the ONE place these words live; the Job tab and the Chat card read it off their payloads). */
|
|
12
12
|
export const NOT_CHECKED_LABEL = "not checked (the AI's own reading)";
|
|
13
|
+
/** M16 item 5 (replaces M4e am40/am41's words for the checks of a line on the list): the label of a plan that has a list */
|
|
14
|
+
export const LIST_NOT_CHECKED_LABEL = 'Not checked';
|
|
15
|
+
/** the label that sits with a plan's Not checked list: a plan with a list says "Not checked", an older plan keeps the words it was signed with @param {any} declaration */
|
|
16
|
+
export const notCheckedLabelOf = (declaration) => (listLinesOf(declaration).size > 0 ? LIST_NOT_CHECKED_LABEL : NOT_CHECKED_LABEL);
|
|
13
17
|
|
|
14
|
-
import { factRows } from './citedcheck.js';
|
|
15
|
-
import { plainWords, labelled } from './checkwords.js';
|
|
18
|
+
import { factRows, factSentence, countSentence } from './citedcheck.js';
|
|
19
|
+
import { plainWords, labelled, tagged } from './checkwords.js';
|
|
20
|
+
import { listLinesOf, partByOf, factByOf, countByOf } from './checklistsign.js';
|
|
21
|
+
import { CARD_T } from './checkblock.js';
|
|
16
22
|
import { sheetCheckRows } from './sheetchecks.js';
|
|
17
23
|
import { sheetLineBlocks } from './sheetblock.js';
|
|
18
24
|
import { splitReadNotes, signedFactNames } from './pagedropwords.js';
|
|
@@ -30,7 +36,9 @@ const list = (xs) => xs.join(', ');
|
|
|
30
36
|
export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvRoles = [], keptChecks = [], keptWords = '' } = {}) {
|
|
31
37
|
const blocks = Array.isArray(lines) ? sheetLineBlocks({ declaration, lines, csvRoles }) : [];
|
|
32
38
|
const steps = Array.isArray(declaration?.steps) ? declaration.steps : [];
|
|
39
|
+
const keptOf = (/** @type {number} */ line, /** @type {any} */ c) => (keptChecks.some((k) => k.line === line && plainWords(k.check) === plainWords(c)) ? ` (${keptWords})` : '');
|
|
33
40
|
if (Array.isArray(askLines)) hasAsk = askLines.length > 0;
|
|
41
|
+
const onList = listLinesOf(declaration); // M16: a line with a list shows each check with the tag of its row
|
|
34
42
|
const lastAsk = Array.isArray(askLines) ? steps.reduce((m, st, i) => (askLines.includes(st?.fromLine) ? i : m), -1) : -1;
|
|
35
43
|
return steps.map((st, i) => {
|
|
36
44
|
const cls = st?.close?.class;
|
|
@@ -39,7 +47,11 @@ export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvR
|
|
|
39
47
|
const shape = st?.close?.shape && typeof st.close.shape === 'object' ? st.close.shape : {};
|
|
40
48
|
/** @type {string[]} */
|
|
41
49
|
const out = [];
|
|
42
|
-
|
|
50
|
+
const listed = onList.has(st?.fromLine);
|
|
51
|
+
if (listed && cls === 'green' && st.close.cited && typeof st.close.cited === 'object') {
|
|
52
|
+
// M16: a list line states the quote check's lead, then each check as a row with the tag of its own row (below)
|
|
53
|
+
out.push(`Each result must be quoted word for word from the saved page "${st.close.cited.source}", and the machine checks every quote, every value and the count against that copy.`);
|
|
54
|
+
} else if (cls === 'green' && st.close.cited && typeof st.close.cited === 'object') {
|
|
43
55
|
// M10 am7 item 1: the facts the drafter wrote, as plain rows written by code from the typed fields
|
|
44
56
|
out.push(`Each result must be quoted word for word from the saved page "${st.close.cited.source}", and the machine checks every quote, every value and the count against that copy.`, ...factRows(st.close.cited).map((r) => labelled(r, 'agent')));
|
|
45
57
|
} else if (cls === 'green' && Array.isArray(st.close.sheet)) {
|
|
@@ -55,13 +67,15 @@ export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvR
|
|
|
55
67
|
if (Number.isInteger(shape.linesPerInvoice)) out.push(labelled(`The output comes in blocks of ${shape.linesPerInvoice} lines.`, 'agent'));
|
|
56
68
|
if (Array.isArray(shape.mustCarry) && shape.mustCarry.length > 0) out.push(labelled(`Every block carries: ${list(shape.mustCarry)}.`, 'agent'));
|
|
57
69
|
// M10 am16: each check the person picked, in the words it was picked in (src/checkwords.js, the one place)
|
|
58
|
-
if (Array.isArray(shape.picked)) for (const c of shape.picked) out.push(labelled(`You picked: ${plainWords(c)}.${
|
|
70
|
+
if (!listed && Array.isArray(shape.picked)) for (const c of shape.picked) out.push(labelled(`You picked: ${plainWords(c)}.${keptOf(st.fromLine, c)}`, 'picked'));
|
|
59
71
|
} else {
|
|
60
72
|
if (lastAsk !== -1 && i > lastAsk) out.push('No machine check of the content; you check it after you accept.');
|
|
61
73
|
else out.push(hasAsk ? 'No machine check of the content: you check it at the ask.' : 'No machine check of the content; the machine checks only that the step happened.');
|
|
62
74
|
}
|
|
63
75
|
// M10 am22 (1)(4): the checks the person picked for a fact line, beside its fact rows
|
|
64
|
-
if (cls === 'green' && Array.isArray(st.close.picked)) for (const c of st.close.picked) out.push(labelled(`You picked: ${plainWords(c)}.${
|
|
76
|
+
if (!listed && cls === 'green' && Array.isArray(st.close.picked)) for (const c of st.close.picked) out.push(labelled(`You picked: ${plainWords(c)}.${keptOf(st.fromLine, c)}`, 'picked'));
|
|
77
|
+
// M16 item 5: the checks of a list line, one tagged sentence each, from the rows' own reader
|
|
78
|
+
if (listed) out.push(...listPartRows(declaration, st, keptOf).map((r) => tagged(r.text, r.by)));
|
|
65
79
|
return {
|
|
66
80
|
step: i + 1, line: Number.isInteger(st?.fromLine) ? st.fromLine : null, goal: typeof st?.goal === 'string' ? st.goal : '', class: String(cls), sentences: out,
|
|
67
81
|
...(sheet && cls === 'green' ? { sheet } : {}),
|
|
@@ -69,10 +83,10 @@ export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvR
|
|
|
69
83
|
});
|
|
70
84
|
}
|
|
71
85
|
|
|
72
|
-
/** The "Not checked" block the page shows: always the label, then the drafter's items (an empty list says the drafter listed nothing). @param {unknown} items */
|
|
73
|
-
export function notCheckedBlock(items) {
|
|
86
|
+
/** The "Not checked" block the page shows: always the label, then the drafter's items (an empty list says the drafter listed nothing). @param {unknown} items @param {string} [label] */
|
|
87
|
+
export function notCheckedBlock(items, label = NOT_CHECKED_LABEL) {
|
|
74
88
|
const clean = Array.isArray(items) ? items.filter((x) => typeof x === 'string' && x.trim() !== '').map((x) => x.trim()) : [];
|
|
75
|
-
return { label
|
|
89
|
+
return { label, items: clean };
|
|
76
90
|
}
|
|
77
91
|
|
|
78
92
|
/**
|
|
@@ -81,7 +95,32 @@ export function notCheckedBlock(items) {
|
|
|
81
95
|
* @param {unknown} items @param {any} declaration the plan's declaration (its cited facts are the signed ones)
|
|
82
96
|
*/
|
|
83
97
|
export function notCheckedView(items, declaration) {
|
|
84
|
-
const block = notCheckedBlock(items);
|
|
98
|
+
const block = notCheckedBlock(items, notCheckedLabelOf(declaration));
|
|
85
99
|
const { notChecked, readNotes } = splitReadNotes(block.items, signedFactNames(declaration));
|
|
86
100
|
return { label: block.label, items: notChecked, readNotes };
|
|
87
101
|
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The checks of one list line's step as rows `{text, by, part}` in the close's part order (the quote check's facts and count, each picked check, the numbers tie), each with the `by` of the row that built it.
|
|
105
|
+
* ONE reader for the plan card's sentences and the Audit's Checks fold; `part` is the index the signed list's rows point at (src/checklistsign.js). Pure.
|
|
106
|
+
* @param {any} declaration @param {any} st the step @param {(line: number, c: any) => string} [keptOf]
|
|
107
|
+
* @returns {{text: string, by: 'you'|'agent'|'default', part: number}[]}
|
|
108
|
+
*/
|
|
109
|
+
export function listPartRows(declaration, st, keptOf = () => '') {
|
|
110
|
+
const close = st?.close && typeof st.close === 'object' ? st.close : {};
|
|
111
|
+
const line = st?.fromLine;
|
|
112
|
+
/** @type {{text: string, by: 'you'|'agent'|'default', part: number}[]} */
|
|
113
|
+
const out = [];
|
|
114
|
+
let idx = 0;
|
|
115
|
+
if (close.cited && typeof close.cited === 'object') {
|
|
116
|
+
const c = close.cited;
|
|
117
|
+
for (const f of Array.isArray(c.facts) ? c.facts : []) out.push({ text: factSentence(f, c.source), by: factByOf(declaration, line, f.name) ?? 'agent', part: idx });
|
|
118
|
+
const count = countSentence(c);
|
|
119
|
+
if (count) out.push({ text: count, by: countByOf(declaration, line) ?? 'agent', part: idx });
|
|
120
|
+
idx += 1;
|
|
121
|
+
}
|
|
122
|
+
const picked = Array.isArray(close.picked) ? close.picked : Array.isArray(close.shape?.picked) ? close.shape.picked : [];
|
|
123
|
+
for (const c of picked) { out.push({ text: `${plainWords(c)}.${keptOf(line, c)}`, by: partByOf(declaration, line, idx) ?? 'agent', part: idx }); idx += 1; }
|
|
124
|
+
if (Array.isArray(close.numbersFrom) && close.numbersFrom.length > 0) out.push({ text: `${CARD_T.numbers} ${close.numbersFrom.join(', ')}.`, by: partByOf(declaration, line, idx) ?? 'default', part: idx });
|
|
125
|
+
return out;
|
|
126
|
+
}
|
package/src/checklist.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/checklist.js@v0.56.0 (3383cce) (the row vocabulary, weekOnly/weekTokens with the three month patterns written as literals, ledgerRecord and the list call's text and schema; the paid call runLedgerSuggest is NOT taken: it runs over bareloop's askStructured and makeCostBook (src/authorflow.js, which need src/text.js), and fwd meters its own calls)
|
|
2
|
+
// THE ROW VOCABULARY of a rubric job's one check list, and the call that suggests extra `!` checks. The list itself is the CheckBlock (src/checkblock.js): every check the job can have is a row there.
|
|
3
|
+
// `~` rows the person's own rules (by: you; a settled pick builds the rule's check)
|
|
4
|
+
// `!` rows checks the agent suggests once, only from what it sees in the inputs (by: agent): the look's kept facts that carry no `~` rule, plus the call's own
|
|
5
|
+
// proposals (count, phrase). Code proves a word-bearing `!` row against the input text, else drops it with a reason. A `~` always wins over a `!` on the same thing.
|
|
6
|
+
// `$` rows default checks code adds itself (by: default): every claim quotes the input (a text line with one input), the numbers tie (a text line after a fact line);
|
|
7
|
+
// the mechanical floor (file exists, text not empty) is shown as a `$` row but is never counted as a check.
|
|
8
|
+
// Nothing here decides a verdict; the list says what the drafter may build, and code builds the rest.
|
|
9
|
+
import { lineRules } from './pagebits.js';
|
|
10
|
+
|
|
11
|
+
/** at most this many `!` checks come from the call */
|
|
12
|
+
export const MAX_BANG = 3;
|
|
13
|
+
/** the reason a check on a version or a date goes under Not checked: it is true only for the input as it is today */
|
|
14
|
+
export const WEEK_ONLY_WORDS = 'It names a version or a date from the input, true only for the input as it is today, so you judge it at Accept.';
|
|
15
|
+
/** the label of the list call, as the drafting book and the draft log see it */
|
|
16
|
+
export const LEDGER_LABEL = 'ledger-suggest';
|
|
17
|
+
export const LEDGER_TOOL = 'suggest_extra_checks';
|
|
18
|
+
/** how much of each input the call is shown */
|
|
19
|
+
const SHOWN_CHARS = 8000;
|
|
20
|
+
/** the reason the empty list is logged with */
|
|
21
|
+
export const EMPTY_LIST_WORDS = 'empty list: nothing to check';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A check that needs exact words from the input is true only while the input stays as it is when those words hold a VERSION-like token (1.2 or 1.2.3, not after a currency sign or before
|
|
25
|
+
* a percent) or a DATE-like token (2026-11-04, 04/11/2026, "Nov 4, 2026", "4 November 2026", "November 2026"). Code refuses it; a `~` rule is the person's own and is never refused by this.
|
|
26
|
+
* @param {unknown} t @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function weekOnly(t) {
|
|
29
|
+
return weekTokens(t).length > 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The version-like and date-like tokens a text holds (the very tokens {@link weekOnly} reads), each once. Pure.
|
|
34
|
+
* @param {unknown} t @returns {string[]}
|
|
35
|
+
*/
|
|
36
|
+
export function weekTokens(t) {
|
|
37
|
+
const s = String(t ?? '');
|
|
38
|
+
const res = [/(?<![\d.$€£])\d+\.\d+(?:\.\d+)*(?![\d.]*%)/g, /\b\d{4}-\d{2}-\d{2}\b/g, /\b\d{1,2}[/.]\d{1,2}[/.]\d{2,4}\b/g,
|
|
39
|
+
/\b(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|jun(?:e)?|jul(?:y)?|aug(?:ust)?|sep(?:t(?:ember)?)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)\.? \d{1,2}(?:st|nd|rd|th)?(?:,? \d{4})?\b/gi, /\b\d{1,2}(?:st|nd|rd|th)? (?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|jun(?:e)?|jul(?:y)?|aug(?:ust)?|sep(?:t(?:ember)?)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)\.?(?: \d{4})?\b/gi, /\b(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|jun(?:e)?|jul(?:y)?|aug(?:ust)?|sep(?:t(?:ember)?)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)\.? \d{4}\b/gi];
|
|
40
|
+
return [...new Set(res.flatMap((re) => [...s.matchAll(re)].map((m) => m[0])))];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {{key: string, line: number, kind: 'rule'|'fact'|'cited'|'count'|'phrase'|'numbers'|'floor', from: 'rule'|'pick'|'look'|'agent'|'default', by: 'you'|'agent'|'default',
|
|
45
|
+
* words: string[], text?: string, rule?: number, part?: {line: number, part: number}, source?: string, name?: string, min?: number, max?: number, pick?: string, after?: number[],
|
|
46
|
+
* state: 'listed'|'built'|'not-checked'|'dropped', reason: string|null, forRule?: number, reading?: import('./pagerules.js').Reading}} Row
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/** an empty list (no row that stands but the floor) is said so, never left as no record at all @param {Row[]} rows @returns {boolean} */
|
|
50
|
+
export const isEmptyList = (rows) => !rows.some((r) => r.kind !== 'floor' && r.state !== 'dropped');
|
|
51
|
+
|
|
52
|
+
/** the record the draft log keeps, one object per row (key, line, rowKind, from, by, words, state, reason), plus ONE explicit record when nothing stands @param {Row[]} rows */
|
|
53
|
+
export const ledgerRecord = (rows) => [
|
|
54
|
+
...rows.map((r) => ({ key: r.key, line: r.line, rowKind: r.kind, from: r.from, by: r.by, words: r.kind === 'rule' ? [r.text ?? ''] : r.words, state: r.state, reason: r.reason })),
|
|
55
|
+
...(isEmptyList(rows) ? [{ key: 'empty', line: 0, rowKind: 'empty', from: 'default', by: 'default', words: [], state: 'empty', reason: EMPTY_LIST_WORDS }] : []),
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
// ---- the one paid call ---------------------------------------------------------------------------------------------------------------------
|
|
59
|
+
/** the list call's own system text (model-facing; used only by the list call of a rubric job with input text) */
|
|
60
|
+
export const LEDGER_SYSTEM = `You look at the inputs of a job and name checks the inputs themselves support, beyond the guardrails the person wrote.
|
|
61
|
+
Call ${LEDGER_TOOL} once with up to ${MAX_BANG} entries, or with an empty list.
|
|
62
|
+
- kind "count": how many results the input shows or the job asks for (min and/or max, whole numbers).
|
|
63
|
+
- kind "phrase": fixed words copied verbatim from an input (phrase, and source = that input's label).
|
|
64
|
+
Use only what you can see in the inputs. Do not repeat a guardrail the person wrote. If the inputs support none, send an empty list.`;
|
|
65
|
+
|
|
66
|
+
export const LEDGER_SCHEMA = Object.freeze({
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
extra: {
|
|
70
|
+
type: 'array', maxItems: MAX_BANG,
|
|
71
|
+
items: {
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties: {
|
|
74
|
+
line: { type: 'integer', minimum: 1, description: 'the job line number' },
|
|
75
|
+
kind: { enum: ['count', 'phrase'] },
|
|
76
|
+
source: { type: 'string', description: 'the label of the input' },
|
|
77
|
+
phrase: { type: 'string', description: 'phrase only: words copied verbatim from the input' },
|
|
78
|
+
min: { type: 'integer', minimum: 1 },
|
|
79
|
+
max: { type: 'integer', minimum: 1 },
|
|
80
|
+
},
|
|
81
|
+
required: ['line', 'kind'],
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
required: ['extra'],
|
|
87
|
+
additionalProperties: false,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/** @param {{n: number, text: string, rules?: string[], rule?: string}[]} jobLines @param {Record<string, string>} texts @returns {string} */
|
|
91
|
+
export function ledgerUserText(jobLines, texts) {
|
|
92
|
+
const out = ['The job:'];
|
|
93
|
+
for (const l of jobLines) {
|
|
94
|
+
out.push(`${l.n}. ${l.text}`);
|
|
95
|
+
lineRules(l).forEach((r, i) => out.push(` g${i + 1}: ${r}`));
|
|
96
|
+
}
|
|
97
|
+
for (const [label, t] of Object.entries(texts)) out.push('', `Input "${label}":`, String(t).slice(0, SHOWN_CHARS));
|
|
98
|
+
return out.join('\n');
|
|
99
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// M16 (docs/wiki/the-module-ladder.md, "M16" item 2, "a check that reaches the plan is not on the list"): the sign-time and run-start proof that the checks of a plan's list lines are the list's.
|
|
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
|
+
// builds them, are [close.cited (the fact part)], 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
|
+
|
|
5
|
+
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
6
|
+
|
|
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.
|
|
9
|
+
* @param {any} step @param {boolean} [withSheet] @returns {{what: string}[]}
|
|
10
|
+
*/
|
|
11
|
+
export function closePartsOf(step, withSheet = false) {
|
|
12
|
+
const close = isRec(step) && isRec(step.close) ? step.close : {};
|
|
13
|
+
/** @type {{what: string}[]} */
|
|
14
|
+
const parts = [];
|
|
15
|
+
if (isRec(close.cited)) parts.push({ what: 'the quote check (close.cited)' });
|
|
16
|
+
const picked = Array.isArray(close.picked) ? close.picked : isRec(close.shape) && Array.isArray(close.shape.picked) ? close.shape.picked : [];
|
|
17
|
+
picked.forEach((/** @type {unknown} */ _c, /** @type {number} */ i) => parts.push({ what: `the picked check ${i + 1} (close.picked)` }));
|
|
18
|
+
if (Array.isArray(close.numbersFrom) && close.numbersFrom.length > 0) parts.push({ what: 'the numbers tie (close.numbersFrom)' });
|
|
19
|
+
if (withSheet && Array.isArray(close.sheet)) close.sheet.forEach((/** @type {any} */ c) => parts.push({ what: `the sheet check ${isRec(c) ? String(c.id) : '?'} (close.sheet)` }));
|
|
20
|
+
return parts;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Every red of a plan's `checkList` (a plan without one is not examined): a built row must point at a check the close really has, every check a list line's close has must have a built row
|
|
25
|
+
* pointing at it, and a list line's close carries no other check of its own (a `close.shape` key besides `picked`). Each red names the line. Pure.
|
|
26
|
+
* @param {any} declaration @returns {string[]}
|
|
27
|
+
*/
|
|
28
|
+
export function checkListReds(declaration) {
|
|
29
|
+
if (!isRec(declaration) || declaration.checkList === undefined) return [];
|
|
30
|
+
const list = declaration.checkList;
|
|
31
|
+
if (!Array.isArray(list) || !list.every(isRec)) return ['declaration: "checkList" must be a list of rows'];
|
|
32
|
+
const steps = Array.isArray(declaration.steps) ? declaration.steps.filter(isRec) : [];
|
|
33
|
+
// M16 am4: a plan whose list has sheet rows is held to them for EVERY sheet check of its steps (a plan from before am4 has none: its sheet lines are not examined, as before)
|
|
34
|
+
const sheetListed = list.some((r) => r.kind === 'sheet');
|
|
35
|
+
const sheetLines = sheetListed ? steps.filter((st) => isRec(st.close) && Array.isArray(st.close.sheet) && st.close.sheet.length > 0 && Number.isInteger(st.fromLine)).map((st) => /** @type {number} */ (st.fromLine)) : [];
|
|
36
|
+
const lines = [...new Set([...list.filter((r) => Number.isInteger(r.line)).map((r) => /** @type {number} */ (r.line)), ...sheetLines])].sort((a, b) => a - b);
|
|
37
|
+
const stepsOn = (/** @type {number} */ n) => steps.filter((st) => st.fromLine === n);
|
|
38
|
+
const partsOn = (/** @type {number} */ n) => stepsOn(n).flatMap((st) => closePartsOf(st, sheetListed));
|
|
39
|
+
const built = list.filter((r) => r.state === 'built' && r.kind !== 'floor');
|
|
40
|
+
/** @type {string[]} */
|
|
41
|
+
const reds = [];
|
|
42
|
+
for (const r of built) {
|
|
43
|
+
const ok = isRec(r.part) && r.part.line === r.line && Number.isInteger(r.part.part) && r.part.part >= 0 && r.part.part < partsOn(/** @type {number} */ (r.line)).length;
|
|
44
|
+
if (!ok) reds.push(`declaration: checkList line ${r.line}: a row points at a check the close does not run (${String(r.key)}). Nothing was signed - draft again.`);
|
|
45
|
+
}
|
|
46
|
+
for (const n of lines) {
|
|
47
|
+
partsOn(n).forEach((p, i) => {
|
|
48
|
+
if (!built.some((r) => isRec(r.part) && r.part.line === n && r.part.part === i)) reds.push(`declaration: checkList line ${n}: ${p.what} is in the close but has no row on the list. Nothing was signed - draft again.`);
|
|
49
|
+
});
|
|
50
|
+
for (const st of stepsOn(n)) {
|
|
51
|
+
const shape = isRec(st.close) && isRec(st.close.shape) ? st.close.shape : {};
|
|
52
|
+
for (const k of Object.keys(shape)) if (k !== 'picked') reds.push(`declaration: checkList line ${n}: close.shape.${k} is a check that is not on the list. Nothing was signed - draft again.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return reds;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** the job lines that have a list: a plan from before M16 has no `checkList`, so none. Sheet rows (M16 am4, `kind: 'sheet'`) do not make a line a block line: a CSV job's other readers stay as they were. @param {any} declaration @returns {Set<number>} */
|
|
59
|
+
export function listLinesOf(declaration) {
|
|
60
|
+
const list = isRec(declaration) && Array.isArray(declaration.checkList) ? declaration.checkList : [];
|
|
61
|
+
return new Set(list.filter((r) => isRec(r) && Number.isInteger(r.line) && r.kind !== 'sheet').map((r) => /** @type {number} */ (r.line)));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** M16 am4: every line the plan card draws a list on - the block's lines and the sheet lines @param {any} declaration @returns {Set<number>} */
|
|
65
|
+
export function cardLinesOf(declaration) {
|
|
66
|
+
const list = isRec(declaration) && Array.isArray(declaration.checkList) ? declaration.checkList : [];
|
|
67
|
+
return new Set(list.filter((r) => isRec(r) && Number.isInteger(r.line)).map((r) => /** @type {number} */ (r.line)));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** the built rows of the list on one line, the floor aside @param {any} declaration @param {number} line */
|
|
71
|
+
const builtOn = (declaration, line) => (isRec(declaration) && Array.isArray(declaration.checkList) ? declaration.checkList : []).filter((r) => isRec(r) && r.line === line && r.state === 'built' && r.kind !== 'floor');
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Who made the check at part `idx` of a list line's close (`'you'` a `~` rule, `'agent'` a `!` row, `'default'` a `$` row), read from the row that points at it (`part`), else null.
|
|
75
|
+
* ONE reader of the rows' `by` for the close's parts (the readout, the plan card and the Audit tag a check through it). Pure.
|
|
76
|
+
* @param {any} declaration @param {number} line @param {number} idx @returns {'you'|'agent'|'default'|null}
|
|
77
|
+
*/
|
|
78
|
+
export function partByOf(declaration, line, idx) {
|
|
79
|
+
const r = builtOn(declaration, line).find((x) => isRec(x.part) && x.part.part === idx);
|
|
80
|
+
return r && (r.by === 'you' || r.by === 'agent' || r.by === 'default') ? r.by : null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 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
|
+
export function factByOf(declaration, line, name) {
|
|
85
|
+
const r = builtOn(declaration, line).find((x) => Array.isArray(x.facts) && x.facts.includes(name));
|
|
86
|
+
return r && (r.by === 'you' || r.by === 'agent' || r.by === 'default') ? r.by : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 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
|
+
export function countByOf(declaration, line) {
|
|
91
|
+
const r = builtOn(declaration, line).find((x) => x.kind === 'count');
|
|
92
|
+
return r && (r.by === 'you' || r.by === 'agent' || r.by === 'default') ? r.by : null;
|
|
93
|
+
}
|
package/src/checkwords.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// M10 amendment 16: the ONE place a picked check is put in plain words (one fixed phrase per bareguard rule, written by code). The ask, the `~` line an agree writes,
|
|
2
2
|
// the plan card (src/checked.js), the softgreen close's check list (src/closers.js) and the Audit all read it; nothing else writes these words.
|
|
3
3
|
/** the rules of bareguard's list a person may pick here (text rules only: the ones a plain answer can be judged by) */
|
|
4
|
-
export const OFFERED = Object.freeze(['nonEmpty', 'maxWords', 'minWords', 'maxLines', 'listItems', 'sections', 'sectionOrder', 'sectionWords', 'mustCarry', 'blockLines']);
|
|
4
|
+
export const OFFERED = Object.freeze(['nonEmpty', 'maxWords', 'minWords', 'maxLines', 'listItems', 'maxListItems', 'minListItems', 'sections', 'sectionOrder', 'sectionWords', 'mustCarry', 'blockLines']);
|
|
5
5
|
/** M10 am22 (4): who added a check, the ONE place these two words live. The plan card, the Job tab and the Audit trail write them after the check's words. */
|
|
6
6
|
export const LABEL_AGENT = '[agent]';
|
|
7
7
|
export const LABEL_PICKED = '[you picked]';
|
|
@@ -19,6 +19,9 @@ export function plainWords(c) {
|
|
|
19
19
|
case 'minWords': return `at least ${c.value} words`;
|
|
20
20
|
case 'maxLines': return `at most ${c.value} lines`;
|
|
21
21
|
case 'listItems': return `exactly ${c.value} list items`;
|
|
22
|
+
// borrowed-from: bareloop src/checkwords.js@v0.56.0 (3383cce) (maxListItems, minListItems: bareguard 0.35)
|
|
23
|
+
case 'maxListItems': return `at most ${c.value} list items`;
|
|
24
|
+
case 'minListItems': return `at least ${c.value} list items`;
|
|
22
25
|
case 'sections': return `sections named ${listOf(c.names ?? [])}`;
|
|
23
26
|
case 'sectionOrder': return `sections named ${listOf(c.names ?? [])}, in that order`;
|
|
24
27
|
case 'sectionWords': return `sections named ${listOf(c.names ?? [])}, each about ${c.wordsPerSection} words`;
|
|
@@ -27,3 +30,19 @@ export function plainWords(c) {
|
|
|
27
30
|
default: return `a ${c.rule} check`;
|
|
28
31
|
}
|
|
29
32
|
}
|
|
33
|
+
|
|
34
|
+
// M16 item 5 (docs/wiki/the-module-ladder.md, "M16"): the tag of a check on a list line is the `by` of its row, one spelling here for the readout, the plan card, the Audit and the Job tab
|
|
35
|
+
// (replaces M10 am22 (4)'s `[you picked]` for list lines only; a sheet row keeps `labelled`).
|
|
36
|
+
/** @type {Readonly<Record<string, string>>} */
|
|
37
|
+
export const TAG = Object.freeze({ you: '[you]', agent: '[agent]', default: '[default]' });
|
|
38
|
+
/** @param {unknown} by @returns {string} the tag of a row by `you` / `agent` / `default`, '' for anything else */
|
|
39
|
+
export const tagOf = (by) => (typeof by === 'string' && Object.hasOwn(TAG, by) ? TAG[by] : '');
|
|
40
|
+
/** @param {string} text @param {unknown} by */
|
|
41
|
+
export const tagged = (text, by) => (tagOf(by) === '' ? text : `${text} ${tagOf(by)}`);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* hamr 2026-11-14: ~ = [you], ! = [agent], $ = [default]. Where a SHEET check comes from, the ONE rule (the plan card's rows, the Job tab, the Audit, the Result tab and the signed readout all read it):
|
|
45
|
+
* a check whose `covers` names one of the person's `~` rules is `you`, a check that covers none (the AI added it) is `agent`; no code adds a `default` sheet check.
|
|
46
|
+
* @param {unknown[]} covers the person's rules the check covers @returns {'you'|'agent'}
|
|
47
|
+
*/
|
|
48
|
+
export const sheetByOf = (covers) => (Array.isArray(covers) && covers.length > 0 ? 'you' : 'agent');
|
package/src/cited-record.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// Extra keys the reader ignores and the separate checker (scripts/check-cited-run.mjs) reads: per line `check` {sha256 of the frozen text, the signed facts,
|
|
8
8
|
// the count} and per row `values`.
|
|
9
9
|
// Throws away: bareguard's evidence beyond the marks of the claim's own spans; nothing: a red line keeps its judged rows (am9); only a stopped check has none.
|
|
10
|
-
import { writeLineSection } from './line-checks.js';
|
|
10
|
+
import { writeLineSection, readLineSection } from './line-checks.js';
|
|
11
11
|
import { moneyAs } from './pageask.js';
|
|
12
12
|
import { factSentence, countSentence, CITED_ID } from './citedcheck.js';
|
|
13
13
|
|
|
@@ -117,3 +117,23 @@ export function citedLineOf({
|
|
|
117
117
|
export function writeCitedLine(runDir, line) {
|
|
118
118
|
writeLineSection(runDir, 'cited', (had) => [...had.filter((/** @type {any} */ l) => isRec(l) && l.n !== line.n), line].sort((a, b) => a.n - b.n));
|
|
119
119
|
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* M16 R7: the quotes of earlier lines' PASSED cited checks, read from the run's own record (what the numbers tie of a later text line is checked against). A line with no record, or
|
|
123
|
+
* one that did not pass, is `missing`: the tie then reads "its answer is not there yet", a normal red, never a pass. Read through the safe gateway; an unreadable record is every line missing.
|
|
124
|
+
* @param {string} runDir @param {number[]} from @returns {{quotes: Record<string, string[]>, missing: number[]}}
|
|
125
|
+
*/
|
|
126
|
+
export function quotesOfLines(runDir, from) {
|
|
127
|
+
const sec = readLineSection(runDir, 'cited');
|
|
128
|
+
const lines = sec.ok ? sec.lines : [];
|
|
129
|
+
/** @type {Record<string, string[]>} */
|
|
130
|
+
const quotes = {};
|
|
131
|
+
/** @type {number[]} */
|
|
132
|
+
const missing = [];
|
|
133
|
+
for (const n of from) {
|
|
134
|
+
const l = lines.find((/** @type {any} */ x) => isRec(x) && x.n === n && x.passed === true && Array.isArray(x.rows));
|
|
135
|
+
if (l) quotes[String(n)] = l.rows.map((/** @type {any} */ r) => (isRec(r) && typeof r.quote === 'string' ? r.quote : '')).filter((/** @type {string} */ q) => q !== '');
|
|
136
|
+
else missing.push(n);
|
|
137
|
+
}
|
|
138
|
+
return { quotes, missing };
|
|
139
|
+
}
|
package/src/citedcheck.js
CHANGED
|
@@ -18,6 +18,7 @@ import { createRubric, checkStep } from 'bareguard';
|
|
|
18
18
|
import { plainWords } from './checkwords.js';
|
|
19
19
|
import { asList, FACT_OPS, boundOk, MAX_CURRENCIES, MAX_UNITS, MAX_UNIT_CHARS } from './pagebits.js';
|
|
20
20
|
import { ruleWords, moneyAs } from './pageask.js';
|
|
21
|
+
import { placeRuleProblem } from './placerule.js';
|
|
21
22
|
|
|
22
23
|
/** the shapes a fact may have (bareguard's value kinds, plus `phrase` = a presence decide) */
|
|
23
24
|
export const FACT_SHAPES = Object.freeze(['money', 'number', 'date', 'time', 'phrase', 'text']);
|
|
@@ -29,7 +30,8 @@ export const CITED_ID = 'facts';
|
|
|
29
30
|
|
|
30
31
|
/** every field a fact part may carry, and every field a fact may carry */
|
|
31
32
|
const PART_FIELDS = Object.freeze(['source', 'facts', 'count']);
|
|
32
|
-
|
|
33
|
+
// borrowed-from: bareloop src/facts.js@v0.56.0 (3383cce) (M16 am3 (3): the fields lang, decimal, place, aiProposal; FACT_LANGS, FACT_DECIMALS, moneyForms, factPartOf, factShapeReds, writtenSpans below; factDecides, factClaims, factSentence taken up to it)
|
|
34
|
+
const FACT_FIELDS = Object.freeze(['name', 'shape', 'unit', 'currency', 'phrase', 'anchor', 'until', 'rule', 'aiProposal', 'lang', 'decimal', 'place']);
|
|
33
35
|
const NAME_RE = /^[A-Za-z][A-Za-z _-]{0,63}$/;
|
|
34
36
|
|
|
35
37
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -102,6 +104,11 @@ export function factPartReds(part) {
|
|
|
102
104
|
if (f.shape !== 'money' && (f.unit !== undefined || f.currency !== undefined)) reds.push(`${w} "${f.name}": only money has a unit or a currency`);
|
|
103
105
|
if (f.shape === 'phrase') for (const k of ['anchor', 'until', 'rule']) if (f[k] !== undefined) reds.push(`${w} "${f.name}": a phrase is fixed words the quote must contain; it has no ${k}`);
|
|
104
106
|
if (f.shape !== 'phrase' && f.phrase !== undefined) reds.push(`${w} "${f.name}": only a phrase fact carries phrase`);
|
|
107
|
+
// 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
|
|
108
|
+
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(', ')}`);
|
|
109
|
+
if (f.decimal !== undefined && ((f.shape !== 'number' && f.shape !== 'money') || !FACT_DECIMALS.includes(f.decimal))) reds.push(`${w} "${f.name}": decimal is for a number or money fact, "." or ","`);
|
|
110
|
+
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}`); }
|
|
111
|
+
if (f.aiProposal !== undefined && typeof f.aiProposal !== 'boolean') reds.push(`${w} "${f.name}": aiProposal is true or false`);
|
|
105
112
|
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`);
|
|
106
113
|
if (asList(f.currency).length > MAX_CURRENCIES) reds.push(`${w} "${f.name}": at most ${MAX_CURRENCIES} currencies`);
|
|
107
114
|
if (asList(f.unit).length > MAX_UNITS || asList(f.unit).some((u) => u.length > MAX_UNIT_CHARS)) reds.push(`${w} "${f.name}": at most ${MAX_UNITS} units of ${MAX_UNIT_CHARS} characters`);
|
|
@@ -132,6 +139,8 @@ export function factDecides(part) {
|
|
|
132
139
|
const d = { valueKind: f.shape };
|
|
133
140
|
if (f.shape === 'money') { if (f.unit !== undefined) d.unit = f.unit; if (f.currency !== undefined) d.currency = f.currency; }
|
|
134
141
|
if (f.anchor !== undefined) d.anchor = f.anchor;
|
|
142
|
+
if (f.lang !== undefined) d.lang = f.lang;
|
|
143
|
+
if (f.decimal !== undefined) d.decimal = f.decimal;
|
|
135
144
|
if (f.until !== undefined) d.until = f.until;
|
|
136
145
|
if (f.rule) {
|
|
137
146
|
d.op = f.rule.op;
|
|
@@ -145,11 +154,12 @@ export function factDecides(part) {
|
|
|
145
154
|
* The claims bareguard reads, built from the step's `results`. The claim TEXT is written here from the values the step gave (`name: value; name: value`),
|
|
146
155
|
* a phrase fact contributes its own signed words. A result that is not an object, or has no string quote, still becomes a claim (an empty one) so
|
|
147
156
|
* bareguard reds it by name rather than the result vanishing.
|
|
148
|
-
*
|
|
157
|
+
* `asWritten` (bareloop v0.56.0): per result, per fact index, the value as the page writes it, for the claim's words of a date or amount a page form signs.
|
|
158
|
+
* @param {any} part @param {unknown} results @param {Record<number, string>[]} [asWritten] @returns {{claim: string, quote: string, values?: Record<string, string>}[]}
|
|
149
159
|
*/
|
|
150
|
-
export function factClaims(part, results) {
|
|
160
|
+
export function factClaims(part, results, asWritten = []) {
|
|
151
161
|
const list = Array.isArray(results) ? results : [];
|
|
152
|
-
return list.map((/** @type {any} */ r) => {
|
|
162
|
+
return list.map((/** @type {any} */ r, /** @type {number} */ i) => {
|
|
153
163
|
const given = isRec(r) && isRec(r.values) ? r.values : null;
|
|
154
164
|
/** @type {Record<string, any>} */
|
|
155
165
|
const values = {};
|
|
@@ -160,7 +170,7 @@ export function factClaims(part, results) {
|
|
|
160
170
|
const v = given && Object.hasOwn(given, f.name) ? given[f.name] : undefined;
|
|
161
171
|
// a JSON number is the value as written ("389"): converted, never repaired; anything else is left for bareguard to red
|
|
162
172
|
const s = typeof v === 'number' && Number.isFinite(v) ? String(v) : v;
|
|
163
|
-
if (typeof s === 'string') { values[`d${j}`] = s; said.push(`${f.name}: ${s}`); } else if (s !== undefined) values[`d${j}`] = s;
|
|
173
|
+
if (typeof s === 'string') { values[`d${j}`] = s; said.push(`${f.name}: ${asWritten[i]?.[j] ?? s}`); } else if (s !== undefined) values[`d${j}`] = s;
|
|
164
174
|
});
|
|
165
175
|
return { claim: said.join('; '), quote: isRec(r) && typeof r.quote === 'string' ? r.quote : '', values };
|
|
166
176
|
});
|
|
@@ -184,19 +194,164 @@ export function buildCitedSpec(part, sha256) {
|
|
|
184
194
|
* @param {any} f @param {string} source @returns {string}
|
|
185
195
|
*/
|
|
186
196
|
export function factSentence(f, source) {
|
|
197
|
+
// PLACE RULES (v0.56.0): a check that reads WHERE the newest value sits, not what it is; the phrase shown is the signed drafting example
|
|
198
|
+
if (f.shape === 'phrase' && isRec(f.place)) return `${f.place.kind === 'headingDateAfter' ? 'date' : 'version'} in the newest "${f.place.prefix}" heading (last read ${f.phrase})`;
|
|
187
199
|
/** @type {string[]} */
|
|
188
200
|
const bits = [];
|
|
189
201
|
if (f.shape === 'phrase') bits.push('phrase', `must say "${f.phrase}"`);
|
|
190
202
|
else {
|
|
191
|
-
bits.push(f.shape === 'money' ? `money in ${
|
|
203
|
+
bits.push(f.shape === 'money' ? `money in ${moneyForms(f).join(' or ')}` : f.shape);
|
|
204
|
+
if (f.lang !== undefined) bits.push(`month names in ${FACT_LANGS[/** @type {keyof typeof FACT_LANGS} */ (f.lang)] ?? f.lang}`);
|
|
205
|
+
if (f.decimal === ',') bits.push('decimal comma');
|
|
192
206
|
if (f.rule) bits.push(ruleWords(f));
|
|
193
207
|
else if (f.anchor === undefined) bits.push('as the quote writes it');
|
|
194
208
|
if (f.anchor !== undefined) bits.push(f.until !== undefined ? `the words after "${f.anchor}" up to "${f.until}"` : `after "${f.anchor}"`);
|
|
195
209
|
}
|
|
196
210
|
bits.push(`quoted from "${source}"`);
|
|
197
|
-
return `fact · ${f.name} — ${bits.join(', ')}`;
|
|
211
|
+
return `fact · ${f.name} — ${bits.join(', ')}${f.aiProposal ? ' — AI\'s proposal — check it' : ''}`;
|
|
198
212
|
}
|
|
199
213
|
|
|
214
|
+
/** the languages whose month names bareguard 0.27 reads on a `date` fact (its `lang`), each with the name a person reads; absent `lang` = ISO YYYY-MM-DD only */
|
|
215
|
+
export const FACT_LANGS = Object.freeze({ en: 'English', de: 'German', fr: 'French', es: 'Spanish', it: 'Italian', pt: 'Portuguese', nl: 'Dutch' });
|
|
216
|
+
|
|
217
|
+
/** the decimal marks a number or money fact may sign (bareguard 0.27 `decimal`); absent = "." */
|
|
218
|
+
export const FACT_DECIMALS = Object.freeze(['.', ',']);
|
|
219
|
+
|
|
220
|
+
/** every field a part of class `fact` may carry (the shared ones are checked by rubricStepShapeReds) */
|
|
221
|
+
export const FACT_PART_FIELDS = PART_FIELDS;
|
|
222
|
+
|
|
223
|
+
const CURRENCY_SIGNS = ['$', '€', '£'];
|
|
224
|
+
|
|
225
|
+
/** @param {any} f a money fact @returns {string[]} every form the page writes the amount in: the units first (as R1L reads them), then the currency signs */
|
|
226
|
+
export const moneyForms = (f) => [...asList(f.unit), ...asList(f.currency)];
|
|
227
|
+
|
|
228
|
+
/** @param {unknown} v @returns {v is string} */
|
|
229
|
+
const nonEmpty = (v) => typeof v === 'string' && v.trim() !== '';
|
|
230
|
+
|
|
231
|
+
/** the `fact` part of a step's parameters, or null (a step has at most one) @param {any} params @returns {any|null} */
|
|
232
|
+
export function factPartOf(params) {
|
|
233
|
+
const parts = Array.isArray(params?.parts) ? params.parts : [];
|
|
234
|
+
return parts.find((/** @type {any} */ p) => isRec(p) && p.class === 'fact') ?? null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The SHAPE of a `fact` part (what it may carry), pushed as reds in the same form `rubricStepShapeReds` uses. Whether the
|
|
239
|
+
* bareguard rubric it builds is signable is asked of bareguard itself (`checkRubricParts` builds it once at drafting).
|
|
240
|
+
* @param {any} part @param {string} w the path prefix @param {(code: string, path: string, detail: string) => void} red
|
|
241
|
+
*/
|
|
242
|
+
export function factShapeReds(part, w, red) {
|
|
243
|
+
for (const k of Object.keys(part)) {
|
|
244
|
+
if (!['text', 'class', 'covers', 'rules', 'source', 'facts', 'count'].includes(k)) {
|
|
245
|
+
red('invalid-value', `${w}.${k}`, `"${k}" is not a field of a fact part — fields: text, class, covers, rules, ${FACT_PART_FIELDS.join(', ')}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (!(nonEmpty(part.source) && part.source.length <= 128)) red('invalid-value', `${w}.source`, 'the label of the input the quotes come from');
|
|
249
|
+
if (!Array.isArray(part.facts) || part.facts.length === 0 || part.facts.length > MAX_FACTS) {
|
|
250
|
+
red('invalid-value', `${w}.facts`, `a list of 1 to ${MAX_FACTS} facts {name, shape, ...}`);
|
|
251
|
+
} else {
|
|
252
|
+
/** @type {Set<string>} */
|
|
253
|
+
const seen = new Set();
|
|
254
|
+
part.facts.forEach((/** @type {any} */ f, /** @type {number} */ j) => {
|
|
255
|
+
const fw = `${w}.facts[${j}]`;
|
|
256
|
+
if (!isRec(f)) { red('invalid-value', fw, '{name, shape, ...}'); return; }
|
|
257
|
+
for (const k of Object.keys(f)) {
|
|
258
|
+
if (FACT_FIELDS.includes(k)) continue;
|
|
259
|
+
// L4 (smv710w8c3wdh, 3 of 3 tries): "covers" / "rules" are fields of the PART, written once, never of a fact inside it
|
|
260
|
+
red('invalid-value', `${fw}.${k}`, k === 'covers' || k === 'rules'
|
|
261
|
+
? `"${k}" is a field of the PART, not of a fact - write the numbers once on the fact part ("${k}": [..]) and take it off every fact. Fact fields: ${FACT_FIELDS.join(', ')}`
|
|
262
|
+
: `"${k}" is not a field of a fact — fields: ${FACT_FIELDS.join(', ')}`);
|
|
263
|
+
}
|
|
264
|
+
if (!(typeof f.name === 'string' && NAME_RE.test(f.name))) red('invalid-value', `${fw}.name`, 'the fact\'s name: letters, spaces, "_" or "-" only (no digits), at most 64 characters');
|
|
265
|
+
else if (seen.has(f.name)) red('invalid-value', `${fw}.name`, `the name "${f.name}" is used twice on this line`);
|
|
266
|
+
else seen.add(f.name);
|
|
267
|
+
if (!FACT_SHAPES.includes(f.shape)) { red('invalid-value', `${fw}.shape`, `one of ${FACT_SHAPES.join(' | ')}`); return; }
|
|
268
|
+
if (Object.hasOwn(f, 'aiProposal') && typeof f.aiProposal !== 'boolean') red('invalid-value', `${fw}.aiProposal`, 'true when the AI turned the person\'s words into this number');
|
|
269
|
+
const has = (/** @type {string} */ k) => Object.hasOwn(f, k);
|
|
270
|
+
if (f.shape === 'money') {
|
|
271
|
+
if (!has('unit') && !has('currency')) red('invalid-value', `${fw}.unit`, 'money names at least one of unit (words the input writes after the amount, e.g. "US dollars") or currency ("$", "€" or "£"); each may be one value or a list');
|
|
272
|
+
} else if (has('unit') || has('currency')) red('invalid-value', `${fw}.${has('unit') ? 'unit' : 'currency'}`, 'only money has a unit or a currency');
|
|
273
|
+
if (has('unit')) {
|
|
274
|
+
const us = f.unit;
|
|
275
|
+
if (Array.isArray(us) ? us.length === 0 || us.some((/** @type {unknown} */ u) => !nonEmpty(u)) : !nonEmpty(us)) red('invalid-value', `${fw}.unit`, 'a non-empty string copied from the input, or a non-empty list of them');
|
|
276
|
+
else {
|
|
277
|
+
const list = asList(us);
|
|
278
|
+
if (list.length > MAX_UNITS) red('invalid-value', `${fw}.unit`, `at most ${MAX_UNITS} units (${list.length} given)`);
|
|
279
|
+
else if (list.some((u) => u.length > MAX_UNIT_CHARS)) red('invalid-value', `${fw}.unit`, `a unit is at most ${MAX_UNIT_CHARS} characters`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (has('currency')) {
|
|
283
|
+
const cs = f.currency;
|
|
284
|
+
if (Array.isArray(cs) ? cs.length === 0 || cs.some((/** @type {unknown} */ c) => !CURRENCY_SIGNS.includes(/** @type {string} */ (c))) : !CURRENCY_SIGNS.includes(cs)) red('invalid-value', `${fw}.currency`, 'one of $ | € | £, or a list of them');
|
|
285
|
+
else {
|
|
286
|
+
const list = asList(cs);
|
|
287
|
+
if (list.length > MAX_CURRENCIES) red('invalid-value', `${fw}.currency`, `at most ${MAX_CURRENCIES} currencies (${list.length} given)`);
|
|
288
|
+
else if (new Set(list).size !== list.length) red('invalid-value', `${fw}.currency`, 'the currencies are not repeated');
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (has('lang')) {
|
|
292
|
+
if (f.shape !== 'date') red('invalid-value', `${fw}.lang`, 'only a date fact carries lang (the language the page writes its month names in); leave it out for a date written 2026-10-26');
|
|
293
|
+
else if (typeof f.lang !== 'string' || !Object.hasOwn(FACT_LANGS, f.lang)) red('invalid-value', `${fw}.lang`, `one of ${Object.keys(FACT_LANGS).join(' | ')}`);
|
|
294
|
+
}
|
|
295
|
+
if (has('decimal')) {
|
|
296
|
+
if (f.shape !== 'number' && f.shape !== 'money') red('invalid-value', `${fw}.decimal`, 'only a number or money fact carries decimal (the mark the page writes before the decimals)');
|
|
297
|
+
else if (!FACT_DECIMALS.includes(f.decimal)) red('invalid-value', `${fw}.decimal`, 'one of "." | ","');
|
|
298
|
+
}
|
|
299
|
+
if (f.shape === 'phrase') {
|
|
300
|
+
if (!nonEmpty(f.phrase)) red('invalid-value', `${fw}.phrase`, 'the fixed words the quote must contain, copied from the input');
|
|
301
|
+
for (const k of ['anchor', 'until', 'rule']) if (has(k)) red('invalid-value', `${fw}.${k}`, 'a phrase is fixed words the quote must contain; it has no anchor, until or rule');
|
|
302
|
+
} else if (has('phrase')) red('invalid-value', `${fw}.phrase`, 'only a phrase fact carries phrase');
|
|
303
|
+
if (has('place')) {
|
|
304
|
+
const bad = f.shape === 'phrase' ? placeRuleProblem(f.place) : 'only a phrase fact carries a place rule';
|
|
305
|
+
if (bad !== null) red('invalid-value', `${fw}.place`, bad);
|
|
306
|
+
}
|
|
307
|
+
if (has('anchor') && !nonEmpty(f.anchor)) red('invalid-value', `${fw}.anchor`, 'a label copied VERBATIM from the input');
|
|
308
|
+
if (has('until') && !nonEmpty(f.until)) red('invalid-value', `${fw}.until`, 'a label copied VERBATIM from the input');
|
|
309
|
+
if (has('until') && !has('anchor') && f.shape !== 'phrase') red('invalid-value', `${fw}.until`, 'until needs an anchor');
|
|
310
|
+
if (has('until') && f.shape !== 'text' && f.shape !== 'phrase') red('invalid-value', `${fw}.until`, 'until closes a text fact only');
|
|
311
|
+
if (has('rule') && f.shape !== 'phrase') {
|
|
312
|
+
const r = f.rule;
|
|
313
|
+
if (f.shape === 'text') red('invalid-value', `${fw}.rule`, 'a text fact is bind only: it has no rule');
|
|
314
|
+
else if (!isRec(r) || !FACT_OPS.includes(r.op)) red('invalid-value', `${fw}.rule`, `{op: ${FACT_OPS.join(' | ')}, value} or {op: "between", lo, hi}`);
|
|
315
|
+
else if (r.op === 'between' ? !(boundOk(f.shape, r.lo) && boundOk(f.shape, r.hi) && !Object.hasOwn(r, 'value')) : !(boundOk(f.shape, r.value) && !Object.hasOwn(r, 'lo') && !Object.hasOwn(r, 'hi'))) {
|
|
316
|
+
red('invalid-value', `${fw}.rule`, r.op === 'between' ? 'between needs lo and hi (numbers for number/money, strings for date/time) and no value' : 'a comparison needs value (a number for number/money, a string for date/time)');
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
if (Object.hasOwn(part, 'count')) {
|
|
322
|
+
const c = part.count;
|
|
323
|
+
const ok = isRec(c) && Object.keys(c).every((k) => k === 'min' || k === 'max') && (Object.hasOwn(c, 'min') || Object.hasOwn(c, 'max'))
|
|
324
|
+
&& ['min', 'max'].every((k) => !Object.hasOwn(c, k) || (Number.isInteger(c[k]) && c[k] >= 1))
|
|
325
|
+
&& (!Object.hasOwn(c, 'min') || !Object.hasOwn(c, 'max') || c.min <= c.max);
|
|
326
|
+
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)');
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Where bareguard read each page-form fact's value inside each quote, as the quote spells it: from `checkStep`'s `full.evidence` (one entry per
|
|
332
|
+
* claim: `text` = the normalized quote the decides ran on, `spans` = where each decide read its anchor, value and unit/currency). Only a fact that
|
|
333
|
+
* signs `lang` or `decimal` is looked up; the span is the decide's `value` span (the one equal to the claim's own value when bareguard flags it).
|
|
334
|
+
* @param {any} part @param {any[]|undefined} evidence @returns {(Record<number, string>|undefined)[]} per claim index
|
|
335
|
+
*/
|
|
336
|
+
export function writtenSpans(part, evidence) {
|
|
337
|
+
/** @type {(Record<number, string>|undefined)[]} */
|
|
338
|
+
const out = [];
|
|
339
|
+
for (const e of Array.isArray(evidence) ? evidence : []) {
|
|
340
|
+
if (!isRec(e) || !Number.isInteger(e.claim) || typeof e.text !== 'string' || !Array.isArray(e.spans)) continue;
|
|
341
|
+
/** @type {Record<number, string>} */
|
|
342
|
+
const row = {};
|
|
343
|
+
part.facts.forEach((/** @type {any} */ f, /** @type {number} */ j) => {
|
|
344
|
+
if (f.lang === undefined && f.decimal === undefined) return;
|
|
345
|
+
const mine = e.spans.filter((/** @type {any} */ sp) => isRec(sp) && sp.decide === j && sp.role === 'value' && Number.isInteger(sp.start) && Number.isInteger(sp.end));
|
|
346
|
+
const sp = mine.find((/** @type {any} */ x) => x.matched === true) ?? mine[0];
|
|
347
|
+
if (sp) row[j] = e.text.slice(sp.start, sp.end);
|
|
348
|
+
});
|
|
349
|
+
if (Object.keys(row).length) out[e.claim] = row;
|
|
350
|
+
}
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
|
|
200
355
|
/** @param {any} part @returns {string|null} the "N results" row of a fact part */
|
|
201
356
|
export function countSentence(part) {
|
|
202
357
|
const c = isRec(part.count) ? part.count : null;
|