fwdloop 0.37.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/README.md +5 -19
- package/bin/fwdloop +51 -29
- 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 +36 -64
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +7 -9
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +5 -5
- package/src/books.js +217 -12
- package/src/checkblock.js +25 -55
- package/src/checked.js +2 -3
- package/src/checklistsign.js +26 -5
- 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 +22 -55
- package/src/diary.js +23 -1
- package/src/draft-steps.js +11 -1
- package/src/drafter.js +28 -23
- 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/isrec.js +2 -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 +2 -3
- package/src/liveness.js +3 -0
- package/src/mcp-use.js +8 -9
- package/src/memo.js +13 -16
- package/src/minrule.js +16 -0
- package/src/model-step.js +3 -3
- 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 +121 -78
- 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 +154 -63
- 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/report.js +2 -1
- 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/sheet-record.js +1 -2
- package/src/sheetblock.js +3 -4
- package/src/sheetbuild.js +5 -5
- package/src/sheetchecks.js +1 -2
- package/src/sheetclaims.js +1 -2
- package/src/sheetoffer.js +1 -1
- package/src/sheetrun.js +5 -7
- package/src/summary-words.js +2 -1
- package/src/thinking.js +5 -2
- package/src/ticketrows.js +8 -30
- 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 +8 -42
- package/types/blockassemble.d.ts +0 -1
- package/types/blockpick.d.ts +1 -1
- package/types/books.d.ts +256 -4
- package/types/checkblock.d.ts +2 -25
- 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 +3 -2
- 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/isrec.d.ts +1 -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/minrule.d.ts +6 -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/sheetclaims.d.ts +0 -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/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 };
|
package/src/declaration.js
CHANGED
|
@@ -46,7 +46,8 @@ import { lineRules } from './pagebits.js';
|
|
|
46
46
|
import { OFFERED as OFFERED_RULES } from './checkwords.js';
|
|
47
47
|
import { isColumnChoiceRule } from './sheetoffer.js';
|
|
48
48
|
import { checkListReds } from './checklistsign.js';
|
|
49
|
-
import { ticketListReds } from './
|
|
49
|
+
import { ticketListReds } from './checklistsign.js';
|
|
50
|
+
import { guardrailWordNumbers, guardrailWordsPerSection, guardrailSectionCount } from './blockpick.js';
|
|
50
51
|
|
|
51
52
|
/** @typedef {import('./types.js').Arbiter} Arbiter */
|
|
52
53
|
/** @typedef {import('./types.js').SignedLine} SignedLine */
|
|
@@ -104,13 +105,16 @@ const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'shee
|
|
|
104
105
|
/** M13 piece 4 (signed item 4): the job's flow type, set by code from the job card, signed with the job. */
|
|
105
106
|
export const FLOW_TYPES = Object.freeze(['plain', 'mcp', 'tickets']);
|
|
106
107
|
|
|
108
|
+
/** M20 am8: the one question "is this a flow type" (plain, mcp or tickets): the card doors, the CLI and the schedule choices ask it @param {unknown} t @returns {boolean} */
|
|
109
|
+
export const isFlowType = (t) => typeof t === 'string' && FLOW_TYPES.includes(t);
|
|
110
|
+
|
|
107
111
|
/**
|
|
108
112
|
* M13 piece 4: the ONE reader of a job's flow type. The field when present; a job signed before it existed (M12 shape: an `mcp` block, no `flowType`) is a Tickets
|
|
109
113
|
* job, since M12 only had ticket jobs; no `mcp` block is plain.
|
|
110
114
|
* @param {Record<string, any>} declaration @returns {'plain'|'mcp'|'tickets'}
|
|
111
115
|
*/
|
|
112
116
|
export function flowTypeOf(declaration) {
|
|
113
|
-
if (
|
|
117
|
+
if (isFlowType(declaration?.flowType)) return /** @type {any} */ (declaration.flowType);
|
|
114
118
|
return declaration?.mcp ? 'tickets' : 'plain';
|
|
115
119
|
}
|
|
116
120
|
|
|
@@ -119,7 +123,7 @@ export function flowTypeOf(declaration) {
|
|
|
119
123
|
function checkFlowType(declaration, reds) {
|
|
120
124
|
if (!Object.hasOwn(declaration, 'flowType')) return;
|
|
121
125
|
const t = declaration.flowType;
|
|
122
|
-
if (
|
|
126
|
+
if (!isFlowType(t)) { reds.push('declaration: flowType must be plain, mcp or tickets'); return; }
|
|
123
127
|
const hasMcp = Object.hasOwn(declaration, 'mcp');
|
|
124
128
|
if (t === 'plain' && hasMcp) reds.push('declaration: flowType "plain" takes no "mcp" server');
|
|
125
129
|
if (t !== 'plain' && !hasMcp) reds.push(`declaration: flowType "${t}" needs an "mcp" server`);
|
|
@@ -341,8 +345,8 @@ export function checkShapes(declaration) {
|
|
|
341
345
|
* safe); an invented proposal is a red, never normalised to hitl.
|
|
342
346
|
* Returns `{ ok: true, class }` or `{ ok: false, error }`.
|
|
343
347
|
*/
|
|
344
|
-
function resolveGuardrailClass(line, guardrailClasses) {
|
|
345
|
-
if (!line || !line.guardrail) {
|
|
348
|
+
function resolveGuardrailClass(line, guardrailClasses, added = new Set()) {
|
|
349
|
+
if (!line || (!line.guardrail && !added.has(line.n))) {
|
|
346
350
|
return { ok: true, class: 'hitl' };
|
|
347
351
|
}
|
|
348
352
|
const key = String(line.n);
|
|
@@ -363,7 +367,7 @@ function resolveGuardrailClass(line, guardrailClasses) {
|
|
|
363
367
|
/** Same shape as poc/m0/validator.mjs's `deriveFromLine`: a step with no
|
|
364
368
|
* `fromLine` is silence -> hitl; a malformed or non-existent `fromLine` is
|
|
365
369
|
* a red; otherwise the class derives from that line's guardrail proposal. */
|
|
366
|
-
function deriveFromLine(fromLine, lines, guardrailClasses) {
|
|
370
|
+
function deriveFromLine(fromLine, lines, guardrailClasses, added = new Set()) {
|
|
367
371
|
if (fromLine === null || fromLine === undefined) {
|
|
368
372
|
return { ok: true, class: 'hitl', line: null };
|
|
369
373
|
}
|
|
@@ -374,29 +378,11 @@ function deriveFromLine(fromLine, lines, guardrailClasses) {
|
|
|
374
378
|
if (!line) {
|
|
375
379
|
return { ok: false, error: `fromLine ${fromLine} does not name any of the signed numbered lines` };
|
|
376
380
|
}
|
|
377
|
-
const resolved = resolveGuardrailClass(line, guardrailClasses);
|
|
381
|
+
const resolved = resolveGuardrailClass(line, guardrailClasses, added);
|
|
378
382
|
if (!resolved.ok) return { ok: false, error: resolved.error };
|
|
379
383
|
return { ok: true, class: resolved.class, line };
|
|
380
384
|
}
|
|
381
385
|
|
|
382
|
-
/** M4e amendment 16 C14: a guardrail number, with or without thousands separators ("1,000" -> 1000). Commas must group by exactly three
|
|
383
|
-
* ("1,00" and "1,0000" match nothing), and the number cannot start in the middle of another one. */
|
|
384
|
-
const readNumber = (t) => Number(t.replace(/,/g, ''));
|
|
385
|
-
|
|
386
|
-
/** Every whole-output word number in a guardrail ("3 sections, under 600 words, each heading at most 3 words" -> [600, 3]), in order; [] when
|
|
387
|
-
* there is none. Code does not decide which one is the limit: the AI picks `maxWords` and the validator checks the pick is one of these
|
|
388
|
-
* (M4e amendments 28 + 29). A "<n> words each" / "<n> words per section" is the per-section size (amendment 15), never listed here. */
|
|
389
|
-
export function guardrailWordNumbers(guardrail) {
|
|
390
|
-
if (typeof guardrail !== 'string') return [];
|
|
391
|
-
return [...guardrail.matchAll(/(?<![\d,])(\d{1,3}(?:,\d{3})+|\d+)\s*words?\b(?!\s*(?:each|per\s+section)\b)/gi)].map((m) => readNumber(m[1]));
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/** M10 amendment 14 item 2: every standalone number in a guardrail's own text (digits not joined to letters: "P1" and "250ish" are not one; "1,000" and "2.5" are one number each). */
|
|
395
|
-
export function guardrailStandaloneNumbers(guardrail) {
|
|
396
|
-
if (typeof guardrail !== 'string') return [];
|
|
397
|
-
return [...guardrail.matchAll(/(?<![A-Za-z0-9_.,])(\d{1,3}(?:,\d{3})+|\d+(?:\.\d+)?)(?![A-Za-z0-9_])/g)].map((m) => Number(m[1].replace(/,/g, '')));
|
|
398
|
-
}
|
|
399
|
-
|
|
400
386
|
/** M10 amendment 14 item 1: the send line (a signed send) is where the accepted result is written out and no AI runs, so a guardrail under it is refused at $0, naming the line.
|
|
401
387
|
* Pure; the card (src/panel/authorcard.js checkCard) and the drafter's pre-flight both call it. @param {any[]} lines `parseSignedText`'s lines @param {{sends?: {line: number}[]}} arbiter */
|
|
402
388
|
export function checkSendLineGuardrail(lines, arbiter) {
|
|
@@ -410,29 +396,8 @@ export function checkSendLineGuardrail(lines, arbiter) {
|
|
|
410
396
|
return reds;
|
|
411
397
|
}
|
|
412
398
|
|
|
413
|
-
|
|
414
|
-
export
|
|
415
|
-
const m = typeof guardrail === 'string' ? /(?<![\d,])(\d{1,3}(?:,\d{3})+|\d+)(?:\s*words?|ish(?:\s+words?)?)\s+(?:each|per\s+section)\b/i.exec(guardrail) : null;
|
|
416
|
-
return m ? readNumber(m[1]) : null;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const NUMBER_WORDS = { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10 };
|
|
420
|
-
/** M4e amendment 7 item 1: the first "<N> sections" in a guardrail (N digits, or the words one..ten), or null. */
|
|
421
|
-
export function guardrailSectionCount(guardrail) {
|
|
422
|
-
const m = typeof guardrail === 'string' ? /\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?sections?\b/i.exec(guardrail) : null;
|
|
423
|
-
if (!m) return null;
|
|
424
|
-
return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/** M10 amendment 23: the first "<N> bullets / list items / items / lines / points" in a guardrail (N digits, or the words one..ten; not a price like "$5 per item"), or null. */
|
|
428
|
-
export function guardrailItemCount(guardrail) {
|
|
429
|
-
const m = typeof guardrail === 'string' ? /(?<![$€£\d.,])\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?(?:bullets?|list items?|items?|lines?|points?)\b/i.exec(guardrail) : null;
|
|
430
|
-
if (!m) return null;
|
|
431
|
-
return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/** M10 amendment 23: the ONE place that says a guardrail is a count code can check: N words, N bullets / list items / items / lines / points, or N sections. */
|
|
435
|
-
export const isCountGuardrail = (guardrail) => guardrailWordNumbers(guardrail).length > 0 || guardrailItemCount(guardrail) !== null || guardrailSectionCount(guardrail) !== null;
|
|
399
|
+
// M20 am8 item 2: the guardrail readers and the count-rule test have one owner, src/blockpick.js; they are named here for the callers that read them from this file
|
|
400
|
+
export { guardrailWordNumbers, guardrailStandaloneNumbers, guardrailWordsPerSection, guardrailSectionCount, guardrailItemCount } from './blockpick.js';
|
|
436
401
|
|
|
437
402
|
/** M4e amendment 15 item 2: for each line whose guardrail gives a size for each section, a section count AND a word number,
|
|
438
403
|
* size x count more than the LARGEST word number (no possible pick fits) is a red naming the line and the numbers. $0; run before any model
|
|
@@ -632,7 +597,7 @@ function checkNumbersFromKey(step, label, steps, reds) {
|
|
|
632
597
|
* `{source, facts, count?}`, src/citedcheck.js). Its SHAPE is checked in every mode (a signed flow is read the same way). With `fitJobLine` the number rules
|
|
633
598
|
* must be the person's own words on the job line; with `pageWords` (the drafting copy of each page and what the page-word map kept) every word is proved on
|
|
634
599
|
* the page at $0 (src/citedwords.js). Each red names the job line, so a redraft can be told which line.
|
|
635
|
-
* @param {any} step @param {string} label @param {{sourceRoles: any[], reads: string[]|null, effectiveClass: string, lines: SignedLine[], fitJobLine?: boolean, pageWords?: {texts: Record<string, string>, look: any, docs?: string[]}}} c @param {string[]} reds
|
|
600
|
+
* @param {any} step @param {string} label @param {{sourceRoles: any[], reads: string[]|null, effectiveClass: string, lines: SignedLine[], fitJobLine?: boolean, addedCounts?: Set<string>, pageWords?: {texts: Record<string, string>, look: any, docs?: string[]}}} c @param {string[]} reds
|
|
636
601
|
*/
|
|
637
602
|
function checkCitedKey(step, label, c, reds) {
|
|
638
603
|
const at = `declaration: ${label}.close.cited`;
|
|
@@ -650,7 +615,7 @@ function checkCitedKey(step, label, c, reds) {
|
|
|
650
615
|
const jl = { n: jobLine.n, text: jobLine.text, ...(jobLine.guardrail ? { rule: jobLine.guardrail } : {}) };
|
|
651
616
|
// a part that is not valid is not read further: its words would only repeat the same red
|
|
652
617
|
if (factPartReds(part).length) return;
|
|
653
|
-
const words = c.pageWords ? citedWordReds({ part, text: c.pageWords.texts[part.source], line: jl.n, jobLine: jl, look: c.pageWords.look, doc: Array.isArray(c.pageWords.docs) && c.pageWords.docs.includes(part.source) }) : [...numberRuleReds({ part, jobLine: jl }), ...countReds({ part, jobLine: jl })];
|
|
618
|
+
const words = c.pageWords ? citedWordReds({ part, text: c.pageWords.texts[part.source], line: jl.n, jobLine: jl, look: c.pageWords.look, doc: Array.isArray(c.pageWords.docs) && c.pageWords.docs.includes(part.source), added: c.addedCounts }) : [...numberRuleReds({ part, jobLine: jl }), ...countReds({ part, jobLine: jl, added: c.addedCounts })];
|
|
654
619
|
for (const r of words) reds.push(`declaration: ${r.detail}`);
|
|
655
620
|
}
|
|
656
621
|
|
|
@@ -763,11 +728,11 @@ function inputReachVerbs(source) {
|
|
|
763
728
|
* `sheetWords` (optional; M10 am8 item 2): `{headers: {role: header names}, facts: the columns the sheet look kept}`. With `fitJobLine`, every column a step's `close.columns` names
|
|
764
729
|
* is proved a real column of its sheet, and a column the code kept for the step's line (an agreed one included) must be in it.
|
|
765
730
|
* `sheetWords.tables` (optional; M10b piece 1): `{role: bareguard table}` of the drafting copy. With it, every `close.sheet` check passes bareguard's sign-time test at $0.
|
|
766
|
-
* @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown, wired?: Set<string>, verbatimGoals?: boolean, fitJobLine?: boolean, pageWords?: {texts: Record<string, string>, look: any, docs?: string[]}, sheetWords?: {headers: Record<string, string[]>, facts: any[], tables?: Record<string, {header: string[], rows: any[]}>} }} [context]
|
|
731
|
+
* @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown, wired?: Set<string>, verbatimGoals?: boolean, fitJobLine?: boolean, addedCounts?: Set<string>, pageWords?: {texts: Record<string, string>, look: any, docs?: string[]}, sheetWords?: {headers: Record<string, string[]>, facts: any[], tables?: Record<string, {header: string[], rows: any[]}>} }} [context]
|
|
767
732
|
* @returns {ValidateDeclarationResult}
|
|
768
733
|
*/
|
|
769
734
|
export function validateDeclaration(declaration, context = {}) {
|
|
770
|
-
const { arbiter, lines, catalogue, wired, verbatimGoals, fitJobLine, pageWords, sheetWords } = context;
|
|
735
|
+
const { arbiter, lines, catalogue, wired, verbatimGoals, fitJobLine, pageWords, sheetWords, addedCounts } = context;
|
|
771
736
|
const reds = [];
|
|
772
737
|
|
|
773
738
|
if (!isPlainObject(declaration)) {
|
|
@@ -819,6 +784,8 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
819
784
|
|
|
820
785
|
// --- guardrailClasses (REQUIRED — the harness always writes it; empty {}
|
|
821
786
|
// is fine, missing entirely is not) ------------------------------------
|
|
787
|
+
// M19 am15 (F257): a line with no `~` of the person's own may carry a class only when the plan's list holds a built `!` check on that line (one the person Added, or one code built from the line's own words, M19 am15a)
|
|
788
|
+
const addedLines = new Set((Array.isArray(declaration.checkList) ? declaration.checkList : []).filter((r) => isPlainObject(r) && r.by === 'agent' && r.state === 'built' && r.kind !== 'floor' && Number.isInteger(r.line)).map((r) => r.line));
|
|
822
789
|
let guardrailClasses = {};
|
|
823
790
|
if (!Object.prototype.hasOwnProperty.call(declaration, 'guardrailClasses')) {
|
|
824
791
|
reds.push('declaration: "guardrailClasses" is required (an object keyed by line number; {} is fine)');
|
|
@@ -827,7 +794,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
827
794
|
for (const key of Object.keys(guardrailClasses)) {
|
|
828
795
|
const n = Number(key);
|
|
829
796
|
const line = Number.isInteger(n) ? safeLines.find((l) => l.n === n) : undefined;
|
|
830
|
-
if (!line || !line.guardrail) {
|
|
797
|
+
if (!line || (!line.guardrail && !addedLines.has(n))) {
|
|
831
798
|
reds.push(`declaration: guardrailClasses key "${key}" does not name a signed line with a guardrail`);
|
|
832
799
|
continue;
|
|
833
800
|
}
|
|
@@ -1032,7 +999,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1032
999
|
if (fromLine !== null && typeof fromLine !== 'number') {
|
|
1033
1000
|
reds.push(`declaration: ${label}.fromLine must be an integer or null`);
|
|
1034
1001
|
} else {
|
|
1035
|
-
const resolved = deriveFromLine(fromLine, safeLines, guardrailClasses);
|
|
1002
|
+
const resolved = deriveFromLine(fromLine, safeLines, guardrailClasses, addedLines);
|
|
1036
1003
|
if (!resolved.ok) {
|
|
1037
1004
|
reds.push(`declaration: ${label} ${resolved.error}`);
|
|
1038
1005
|
} else {
|
|
@@ -1069,7 +1036,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1069
1036
|
reds.push(`declaration: ${label}.close.shape: a step that checks facts carries no count check of the drafter's own; only a check you picked (close.picked, on a line recorded in pickedLines) can sit beside its fact check`);
|
|
1070
1037
|
}
|
|
1071
1038
|
if (step.close.numbersFrom !== undefined) checkNumbersFromKey(step, label, steps, reds);
|
|
1072
|
-
if (step.close.cited !== undefined) checkCitedKey(step, label, { sourceRoles, reads, effectiveClass, lines: safeLines, fitJobLine, pageWords }, reds);
|
|
1039
|
+
if (step.close.cited !== undefined) checkCitedKey(step, label, { sourceRoles, reads, effectiveClass, lines: safeLines, fitJobLine, pageWords, addedCounts }, reds);
|
|
1073
1040
|
if (step.close.itemShape !== undefined) checkItemShapeKey(step, label, effectiveClass, reds);
|
|
1074
1041
|
if (step.close.sheet !== undefined) checkSheetKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, fitJobLine, sheetWords }, reds);
|
|
1075
1042
|
if (step.close.columns !== undefined || (fitJobLine === true && sheetWords)) checkColumnsKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, sheetWords }, reds);
|
package/src/diary.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// (src/planrun.js: `new Gate({ audit: { path } })`, the path denied to the worker with `fs.deny`). Every row carries `kind`, in the order the rows were written:
|
|
3
3
|
// kind 'call' one row per MODEL CALL: step, try, round, cost, tokens, time, stop reason, thinking asked and status
|
|
4
4
|
// kind 'tool' one row per TOOL CALL: step, try, round, tool, path, the guard's decision (allow / deny + rule / no check)
|
|
5
|
+
// kind 'try-start' one row per model-step TRY, written when it begins: step, try, at (M20 am1 item 8; report-only, the Run tab's NOW row reads it; no check, cost or count reads it)
|
|
5
6
|
// kind 'checks' one row per TRY that ran checks: each check numbered, ✓/✗, its result, where it comes from, and the output it judged
|
|
6
7
|
// Never saved: what the model said, what was in any file (a tool row names a path, never its content). Every string is scrubbed with the
|
|
7
8
|
// ONE secret inventory (`redactSecrets`, src/redact.js) before the row is written. The model can never read this file: the step's
|
|
@@ -19,7 +20,7 @@ export const DIARY_FILE = 'diary.jsonl';
|
|
|
19
20
|
/** The diary's absolute path for a run, for the model's deny list (a list, as the deny lists take one). @param {string} runDir @returns {string[]} */
|
|
20
21
|
export const diaryPaths = (runDir) => [join(runDir, DIARY_FILE)];
|
|
21
22
|
|
|
22
|
-
/** @typedef {'call'|'tool'|'checks'} DiaryKind */
|
|
23
|
+
/** @typedef {'call'|'tool'|'checks'|'try-start'} DiaryKind */
|
|
23
24
|
|
|
24
25
|
/** A copy of a JSON value with every string scrubbed. @param {any} v @returns {any} */
|
|
25
26
|
function scrub(v) {
|
|
@@ -39,6 +40,9 @@ export const appendTool = (runDir, row) => write(runDir, 'tool', row);
|
|
|
39
40
|
/** @param {string} runDir @param {{step:string|null, try:number, at:string, lastRound:number, checks:Array<{n:number, text:string, ok:boolean, result:string|null, source:string}>, output:{file:string, bytes:number, sha256:string}|null}} row */
|
|
40
41
|
export const appendChecks = (runDir, row) => write(runDir, 'checks', row);
|
|
41
42
|
|
|
43
|
+
/** @param {string} runDir @param {{step:string|null, try:number, at:string}} row */
|
|
44
|
+
export const appendTryStart = (runDir, row) => write(runDir, 'try-start', row);
|
|
45
|
+
|
|
42
46
|
/** The rows of one kind, in the order they were written; a torn or unparseable line is skipped (the writer's fresh-line rule is its other half). @param {string} runDir @param {DiaryKind} kind @returns {any[]} */
|
|
43
47
|
const readKind = (runDir, kind) => readLines(runDir, DIARY_FILE).filter((r) => r.kind === kind);
|
|
44
48
|
/** @param {string} runDir @returns {any[]} */
|
|
@@ -48,6 +52,24 @@ export const readTools = (runDir) => readKind(runDir, 'tool');
|
|
|
48
52
|
/** @param {string} runDir @returns {any[]} */
|
|
49
53
|
export const readChecks = (runDir) => readKind(runDir, 'checks');
|
|
50
54
|
|
|
55
|
+
/** @param {string} runDir @returns {any[]} */
|
|
56
|
+
export const readTryStarts = (runDir) => readKind(runDir, 'try-start');
|
|
57
|
+
|
|
51
58
|
/** The round number of this step's next model call: one more than the highest round it has in the diary, so it counts on across tries and across resumes.
|
|
52
59
|
* Read off the file each time (the diary is the one record), never a copy held in memory. @param {string} runDir @param {string|null} step */
|
|
53
60
|
export const nextRound = (runDir, step) => readCalls(runDir).filter((r) => r.step === step).reduce((m, r) => Math.max(m, r.round), 0) + 1;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* M20 am3g item 23: the ONE rule for a step's newest-try checks, over the run's `checks` rows (`readChecks`): a row of this step with a whole-number `try` and a `checks` list;
|
|
64
|
+
* the highest `try`, a tie going to the later row; the row, or null when the step has none. The Audit, the Result tab and the ticket grid ask it and keep their own words
|
|
65
|
+
* and tags; the Audit card's "checks on the last try" count asks it too (its per-try fold is another question).
|
|
66
|
+
* @param {any[]|null|undefined} diary @param {unknown} stepId @returns {any|null}
|
|
67
|
+
*/
|
|
68
|
+
export function newestChecksOf(diary, stepId) {
|
|
69
|
+
let newest = null;
|
|
70
|
+
for (const r of diary ?? []) {
|
|
71
|
+
if (!r || r.step !== stepId || !Number.isInteger(r.try) || !Array.isArray(r.checks)) continue;
|
|
72
|
+
if (newest === null || r.try >= newest.try) newest = r;
|
|
73
|
+
}
|
|
74
|
+
return newest;
|
|
75
|
+
}
|
package/src/draft-steps.js
CHANGED
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
// Third outcomes: no log -> null (nothing to list); a cost that is null reads "cost unknown", an incomplete sum reads "at least $X", never 0.
|
|
9
9
|
|
|
10
10
|
import { plainPlanCheck, pickPlanRed } from './plain-checks.js';
|
|
11
|
+
import { isThinkingMode } from './thinking.js';
|
|
12
|
+
|
|
13
|
+
/** a plan folder's card file: `card-<n>.json` (n = the redraft or revise number) */
|
|
14
|
+
export const CARD_RE = /^card-(\d+)\.json$/;
|
|
15
|
+
/** how much of the end of a child's log a person is shown when it stopped or refused */
|
|
16
|
+
export const LOG_TAIL_CHARS = 1500;
|
|
17
|
+
/** a revise's or an answer redraft's own log in a plan folder; `kind` is 'answers' for the redraft, anything else for the revise @param {string} kind @param {number} n */
|
|
18
|
+
export const draftLogName = (kind, n) => `${kind === 'answers' ? 'redraft' : 'revise'}-${n}.log`;
|
|
19
|
+
/** a name that is a revise's or a redraft's log */
|
|
20
|
+
export const DRAFT_LOG_RE = /^(revise|redraft)-\d+\.log$/;
|
|
11
21
|
|
|
12
22
|
const REBUILD_RE = /^declaration: steps\[(\d+)\]\.close\.shape cannot be built into a check — (.*)$/s;
|
|
13
23
|
|
|
@@ -55,7 +65,7 @@ export function draftStepList({ log, declaration, questionOpen = false }) {
|
|
|
55
65
|
const out = [];
|
|
56
66
|
|
|
57
67
|
const t = log.thinking;
|
|
58
|
-
if (t && (t.asked
|
|
68
|
+
if (t && isThinkingMode(t.asked) && typeof t.status === 'string') {
|
|
59
69
|
if (t.status === 'applied') out.push({ id: 'thinking', label: `thinking ${t.asked}`, status: 'done', details: [] });
|
|
60
70
|
else if (typeof t.say === 'string' && t.say !== '') out.push({ id: 'thinking', label: t.say, status: 'failed', details: [] });
|
|
61
71
|
}
|