fwdloop 0.32.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 +205 -122
- package/src/factwords.js +112 -0
- package/src/inputlook.js +53 -0
- package/src/labelscan.js +162 -0
- package/src/pageask.js +4 -1
- package/src/pagedropwords.js +11 -1
- package/src/panel/author.js +73 -4
- 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/sheetoffer.js +24 -52
- package/src/sheetrows.js +107 -0
- package/src/sheetrun.js +13 -10
- 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/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 +4 -4
- 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/rowedit.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/rowedit.js@v0.56.0 (3383cce)
|
|
2
|
+
// THE DRAFTER'S ROW-EDIT TURN of a rubric job (the check block, docs/product/ITEM33-BUILD.md "CHECK BLOCK BUILD SPEC" section 4 and hamr's rulings of 2026-11-12).
|
|
3
|
+
// The AI never writes a part, a check or a declaration: it sends EDITS to the list of checks code keeps in the CheckBlock (src/checkblock.js). Code reads the inputs, proves every
|
|
4
|
+
// word, builds every check and decides what can be checked; every edit is judged on its own. The confirm turn owns the goal (ruling 5), so the reply has none. A Tickets job's reply
|
|
5
|
+
// may also carry the optional `ticketFilter` (ruling 2, R5), checked by its own reader. No text here restates the list of checks (the block's invariant 5): the only list-shaped input is
|
|
6
|
+
// the look's report, an input the drafter already had, and the person's own job lines.
|
|
7
|
+
import { lineRules } from './pagebits.js';
|
|
8
|
+
import { renderLookReport } from './inputlook.js';
|
|
9
|
+
import { OFFERED } from './checkwords.js';
|
|
10
|
+
import { rubricVocabulary } from 'bareguard';
|
|
11
|
+
|
|
12
|
+
// borrowed-from: bareloop src/ticketfilter.js@v0.56.0 (3383cce) (TICKET_FILTER_SCHEMA_WORDS only: the one sentence; fwd's own ticketFilter schema, src/ticket-draft.js, words it another way)
|
|
13
|
+
export const TICKET_FILTER_SCHEMA_WORDS = 'REQUIRED when a job line names a priority or a label (leave it out only when none does). The person signs it; code decides at run start. Listing the line under "refused" does not filter anything: only this key does';
|
|
14
|
+
|
|
15
|
+
/** the tool a row-edit reply is delivered through */
|
|
16
|
+
export const ROW_EDIT_TOOL = 'submit_edits';
|
|
17
|
+
/** what an acknowledged reply returns (the loop ends the call the moment the tool fires) */
|
|
18
|
+
export const ROW_EDIT_ACK = 'edits received';
|
|
19
|
+
|
|
20
|
+
const IGNORED_FIELDS = new Set(['id', 'field', 'text', 'strict']);
|
|
21
|
+
const GLOSS = /** @type {Record<string, string>} */ ({ nonEmpty: 'the output is not empty', maxWords: 'at most value words in all', minWords: 'at least value words in all', maxLines: 'at most value lines', listItems: 'exactly value list items (bullets)', maxListItems: 'at most value list items', minListItems: 'at least value list items', sections: 'the output has sections with these names', sectionOrder: 'the sections come in this order', sectionWords: 'each named section has at most wordsPerSection words', mustCarry: 'the output carries these phrases', blockLines: 'blocks of size lines carry these phrases' });
|
|
22
|
+
/** the checks a `pick` edit may name: the checker's own list (the same bareguard vocabulary src/checkpick.js reads) */
|
|
23
|
+
const pickMenu = () => OFFERED.map((r) => {
|
|
24
|
+
const fields = Object.entries(/** @type {any} */ (rubricVocabulary).rules[r].fields).filter(([k]) => !IGNORED_FIELDS.has(k)).map(([k, v]) => `${k}${/** @type {any} */ (v).required ? '' : '?'}`);
|
|
25
|
+
return `- ${r}${fields.length ? ` { ${fields.join(', ')} }` : ''}: ${GLOSS[r] ?? ''}`;
|
|
26
|
+
}).join('\n');
|
|
27
|
+
|
|
28
|
+
/** the drafter's system text for the row-edit turn (a prompt register: src/promptregisters.js) */
|
|
29
|
+
export const ROW_EDIT_SYSTEM = `You help turn the lines of a job into checks, by sending EDITS to a list of checks that code keeps. You never write a check, a stage, a part or a declaration: code reads the inputs, proves every word, builds every check and decides what can be checked. Each edit you send is judged on its own: a refused edit is dropped and says why, and it never costs your other edits.
|
|
30
|
+
|
|
31
|
+
HOW TO ANSWER
|
|
32
|
+
Deliver ONE reply with an "edits" list (the ${ROW_EDIT_TOOL} tool, or one JSON object {"edits": [ ... ]} and nothing else when no tool is offered). An empty "edits" list is a good answer when you have nothing sure to send.
|
|
33
|
+
|
|
34
|
+
THE FOUR EDITS (each has "op"; the op is exactly one of: add, reading, pick, not-checkable. A count is an add with "kind":"count"; "count" is never an op)
|
|
35
|
+
1. add - a check the inputs support that the person did not write and the look did not give:
|
|
36
|
+
{"op":"add","kind":"fact","line":N,"name":"price label","shape":"money","words":["words copied exactly from the input"],"unit":["US dollars"],"currency":["$"],"source":"<input label>"}
|
|
37
|
+
{"op":"add","kind":"phrase","line":N,"name":"letters and spaces only","words":["fixed words copied exactly from the input"],"source":"<input label>"}
|
|
38
|
+
{"op":"add","kind":"count","line":N,"min":3,"max":3} (how many results the job line itself asks for; whole numbers of 1 or more; only when the line states it)
|
|
39
|
+
"shape" is one of phrase, money, number, date, time. A name uses letters, spaces, "-" or "_" only (no digits). "words" are copied exactly from the input, never typed from memory; words the input does not hold are refused. At most 3 adds in one reply: the later ones are refused.
|
|
40
|
+
2. reading - the limit a ~ rule means, for a ~ rule the look tied to a fact ("carries ~ rule N") without giving the limit:
|
|
41
|
+
{"op":"reading","line":N,"rules":[n],"fact":"<that look fact's name>","reading":{"op":"lt","value":450}} (reading op is lt, lte, gt or gte)
|
|
42
|
+
{"op":"reading","line":N,"rules":[n],"fact":"<that look fact's name>","reading":{"op":"between","lo":"05:00","hi":"21:00"}}
|
|
43
|
+
A money limit is a number. A time limit is a 24-hour "HH:MM" string. A limit the person WROTE ("under $450") is a rule that can be checked: give its reading with its number. A number YOU make out of their words ("not a red-eye" becomes a departure time between 06:00 and 21:00) is your proposal for the person to check, and a time limit that you propose is a RANGE (between), never one-sided. A rule that holds more than one amount or range gets no reading.
|
|
44
|
+
3. pick - for a ~ rule that counts words, bullets, lines or sections: the one check that says exactly what that rule says:
|
|
45
|
+
{"op":"pick","line":N,"rules":[n],"check":{"rule":"<one of the checks below>", ...that check's own fields}}
|
|
46
|
+
Use only numbers the ~ rule itself states and only words it contains. The checks (field? = optional):
|
|
47
|
+
${pickMenu()}
|
|
48
|
+
4. not-checkable - a ~ rule no check on the inputs can carry ("the cheapest", "the best", "the newest one"):
|
|
49
|
+
{"op":"not-checkable","line":N,"rule":n,"reason":"plain words, the person's own"}
|
|
50
|
+
|
|
51
|
+
RULES
|
|
52
|
+
- Names, labels and units are the input's own words, copied exactly as the input writes them. When the input does not use the person's word, use the words the input uses; never invent a word the input holds nowhere, and never add a code (like SFO) that the person did not write and the input does not hold.
|
|
53
|
+
- The look (below) is what a read of the inputs already found and code already checks: do not send it again as an add. Use it to name the fact a reading belongs to.
|
|
54
|
+
- Send only what you are sure of. A fact or ~ rule you cannot name from the look and the input is not guessed at.
|
|
55
|
+
- "line" is the job line's number; "rule" and "rules" are the ~ rule numbers shown under that line (1 = the first).`;
|
|
56
|
+
|
|
57
|
+
/** the fixed sentence that follows the refusals in a revise turn (the turn carries each refusal's own reason and nothing else) */
|
|
58
|
+
export const ROW_EDIT_REVISE = 'Send corrected edits only (an empty "edits" list is a good answer).';
|
|
59
|
+
|
|
60
|
+
/** how much of each input the turn is shown (the bound src/checklist.js used) */
|
|
61
|
+
const SHOWN_CHARS = 8000;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The ONE user message: the person's job lines (their `~` rules numbered), the look, the inputs (bounded).
|
|
65
|
+
* @param {{jobLines: any[], look: any, texts: Record<string, string>}} o
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
export function rowEditUserText({ jobLines, look, texts }) {
|
|
69
|
+
const out = ["THE JOB (the person's own words)"];
|
|
70
|
+
for (const l of jobLines) {
|
|
71
|
+
out.push(`${l.n}. ${l.text}`);
|
|
72
|
+
lineRules(l).forEach((r, i) => out.push(` ~ rule ${i + 1}: ${r}`));
|
|
73
|
+
}
|
|
74
|
+
const report = look && typeof look === 'object' ? renderLookReport(look).replace(/^WHAT THE LOOK AT THE INPUTS FOUND[^\n]*/, 'WHAT THE LOOK AT THE INPUTS FOUND - code checks each of these itself; you do not write them') : '';
|
|
75
|
+
if (report) out.push('', report);
|
|
76
|
+
for (const [label, t] of Object.entries(texts)) out.push('', `INPUT "${label}" (first ${SHOWN_CHARS} characters):`, String(t).slice(0, SHOWN_CHARS));
|
|
77
|
+
return out.join('\n');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @param {boolean} ticket @returns {Record<string, any>} the tool's schema: the edits list (each edit judged by code, so an item is any object), and for a Tickets job the optional ticketFilter */
|
|
81
|
+
const rowEditSchema = (ticket) => ({
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
edits: { type: 'array', items: { type: 'object', properties: { op: { enum: ['add', 'reading', 'pick', 'not-checkable'] } }, required: ['op'] }, description: 'row edits; each is judged on its own' },
|
|
85
|
+
...(ticket ? {
|
|
86
|
+
ticketFilter: {
|
|
87
|
+
type: 'object',
|
|
88
|
+
properties: {
|
|
89
|
+
priority: { type: 'array', items: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] }, description: 'priorities a ticket must have; only when a job line names them' },
|
|
90
|
+
labels: { type: 'array', items: { type: 'string' }, description: 'label names, one of which a ticket must carry; only when a job line names them' },
|
|
91
|
+
},
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
description: TICKET_FILTER_SCHEMA_WORDS,
|
|
94
|
+
},
|
|
95
|
+
} : {}),
|
|
96
|
+
},
|
|
97
|
+
required: ['edits'],
|
|
98
|
+
additionalProperties: false,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/** @param {boolean} ticket the channel `askStructured` reads (src/authorflow.js) */
|
|
102
|
+
export const rowEditChannel = (ticket = false) => ({
|
|
103
|
+
name: ROW_EDIT_TOOL,
|
|
104
|
+
instruction: `Your reply did not deliver exactly one ${ROW_EDIT_TOOL} call. Call ${ROW_EDIT_TOOL} exactly once, with the edits list as its arguments. Do not write the answer as text.`,
|
|
105
|
+
textPath: 'edits',
|
|
106
|
+
tool: (/** @type {{calls: any[]}} */ box) => ({
|
|
107
|
+
name: ROW_EDIT_TOOL,
|
|
108
|
+
description: 'Deliver your row edits (or an empty list). Call this exactly once.',
|
|
109
|
+
parameters: rowEditSchema(ticket),
|
|
110
|
+
execute: async (/** @type {any} */ args) => { box.calls.push(args); return ROW_EDIT_ACK; },
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The edits a reply holds, as a list (a reply whose `edits` is not a list holds none; each edit is still judged by the block).
|
|
116
|
+
* @param {any} artifact @returns {any[]}
|
|
117
|
+
*/
|
|
118
|
+
export const editsOf = (artifact) => (artifact && typeof artifact === 'object' && Array.isArray(artifact.edits) ? artifact.edits : []);
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/rubricstep.js@v0.56.0 (3383cce) (rubricStepShapeReds, readLimit, holdsManyBounds, defaultCitedText, NEGATING_RE, boundInWords and what they call; the five patterns built from text are literals here, src/ builds none, test/signed-text.test.js; fwd's own boundInWords and lineRules, src/pagebits.js, are an older copy: boundInWords reads time and date bounds only in this one)
|
|
2
|
+
// The part of the rubric step the check block calls: the shape reds of a step's parts, the limit reader (code reads ONE amount or ONE range from the person's rule words)
|
|
3
|
+
// and the default cited text. The rest of the rubric step (building, grading and reading a step file) is not wanted here.
|
|
4
|
+
import { lineRules } from './pagebits.js';
|
|
5
|
+
import { factShapeReds } from './citedcheck.js';
|
|
6
|
+
|
|
7
|
+
// ── the `rubric-step` stage: its parameters, and the rubric they build ───────────────────────────────────────────────
|
|
8
|
+
//
|
|
9
|
+
// A stage serves exactly ONE job line N and reads exactly one file, output/steps/N.json. Its parameters are
|
|
10
|
+
//
|
|
11
|
+
// step N
|
|
12
|
+
// parts [ { text, class, ... } ] — the person's constraints on that line, each SORTED by the drafter
|
|
13
|
+
//
|
|
14
|
+
// A part's class is one of `countable` (a limit a machine counts, or a quote a claim must show), `judged` (needs the
|
|
15
|
+
// judge — stored, never run in this build), `guard` (a rule about web sources — needs a web input, none exist yet) or
|
|
16
|
+
// `none` (the drafter could not sort it). Only `countable` parts become checks; the others are REDS at drafting
|
|
17
|
+
// (src/authoring.js `checkRubricParts`) so no signed stage ever carries one.
|
|
18
|
+
|
|
19
|
+
/** the closed set of classes a part is sorted into; `none` = "I could not sort this one" (a red, in plain words, never a guess) */
|
|
20
|
+
export const PART_CLASSES = Object.freeze(['countable', 'fact', 'judged', 'guard', 'none']);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The counted/quoted checks a `countable` part may name, with the fields each needs — read off bareguard's own rule table
|
|
24
|
+
* (`rubricVocabulary`): the names are bareguard's, so a check this build cannot run is inexpressible, not rejected late.
|
|
25
|
+
* (`max`/`min` need a numeric field the step file does not have, so they are not offered.)
|
|
26
|
+
* @type {Readonly<Record<string, readonly string[]>>}
|
|
27
|
+
*/
|
|
28
|
+
export const COUNT_CHECKS = Object.freeze({
|
|
29
|
+
maxWords: Object.freeze(['value']),
|
|
30
|
+
minWords: Object.freeze(['value']),
|
|
31
|
+
maxLines: Object.freeze(['value']),
|
|
32
|
+
sections: Object.freeze(['names']),
|
|
33
|
+
sectionWords: Object.freeze(['names', 'wordsPerSection']),
|
|
34
|
+
// R10 (bareguard 0.31, fwdloop v0.29.0 OFFERED): the five text checks a person's pick may carry; the drafter never writes them
|
|
35
|
+
nonEmpty: Object.freeze([]),
|
|
36
|
+
listItems: Object.freeze(['value']),
|
|
37
|
+
maxListItems: Object.freeze(['value']), // bareguard 0.35 (F315): an at-most / at-least bound on the list items, beside the exact listItems
|
|
38
|
+
minListItems: Object.freeze(['value']),
|
|
39
|
+
sectionOrder: Object.freeze(['names']),
|
|
40
|
+
mustCarry: Object.freeze(['phrases']),
|
|
41
|
+
blockLines: Object.freeze(['size', 'phrases']),
|
|
42
|
+
cited: Object.freeze(['source']),
|
|
43
|
+
// a COUNT of the claims listed under an input: the code counts the list (flattenStep), bareguard's own min/max compares it
|
|
44
|
+
minClaims: Object.freeze(['value', 'source']),
|
|
45
|
+
maxClaims: Object.freeze(['value', 'source']),
|
|
46
|
+
// PART 1b: put on every prose step by CODE (`withFactBindings`) when an earlier line is a fact step — every number in the text
|
|
47
|
+
// must be in a checked quote of those lines. The model never writes it; bareguard's `numbersInQuote` reads it (gradeStep).
|
|
48
|
+
numbersFromFacts: Object.freeze(['from']),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/** every field a part may carry, whatever its class */
|
|
52
|
+
const PART_FIELDS = Object.freeze(['text', 'class', 'check', 'value', 'names', 'wordsPerSection', 'source', 'domains', 'phrases', 'size', 'covers', 'rules', 'from', 'record', 'facts', 'count', 'tested', 'sample']);
|
|
53
|
+
|
|
54
|
+
/** @typedef {{code: string, path: string, detail: string}} ShapeRed */
|
|
55
|
+
|
|
56
|
+
/** @param {unknown} v @returns {v is Record<string, any>} */
|
|
57
|
+
const isRec = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
58
|
+
|
|
59
|
+
/** @param {unknown} v @returns {v is string} */
|
|
60
|
+
const nonEmpty = (v) => typeof v === 'string' && v.trim() !== '';
|
|
61
|
+
|
|
62
|
+
/** @param {unknown} v @returns {v is string[]} */
|
|
63
|
+
const nameList = (v) => Array.isArray(v) && v.length > 0 && v.every((x) => nonEmpty(x) && x.length <= 1000);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The SHAPE of a `rubric-step` stage's parameters — what a part may carry — and nothing about which class is allowed in
|
|
67
|
+
* this build (that is `checkRubricParts`, which also sees the whole job). Pure, never throws.
|
|
68
|
+
* @param {unknown} p the stage's `params`
|
|
69
|
+
* @param {string} at the path prefix for reds, e.g. `stages[1].params`
|
|
70
|
+
* @returns {ShapeRed[]}
|
|
71
|
+
*/
|
|
72
|
+
export function rubricStepShapeReds(p, at) {
|
|
73
|
+
/** @type {ShapeRed[]} */
|
|
74
|
+
const reds = [];
|
|
75
|
+
const red = (/** @type {string} */ code, /** @type {string} */ path, /** @type {string} */ detail) => reds.push({ code, path, detail });
|
|
76
|
+
if (!isRec(p)) { red('invalid-value', at, 'an object {step, parts}'); return reds; }
|
|
77
|
+
if (!(Number.isInteger(p.step) && p.step >= 1)) red('invalid-value', `${at}.step`, 'the number of the job line this stage serves (an integer, 1 or more)');
|
|
78
|
+
if (!Array.isArray(p.parts)) { red('invalid-value', `${at}.parts`, 'an array of {text, class, ...} — one entry per constraint the person put on this line (may be empty)'); return reds; }
|
|
79
|
+
p.parts.forEach((/** @type {any} */ part, /** @type {number} */ i) => {
|
|
80
|
+
const w = `${at}.parts[${i}]`;
|
|
81
|
+
if (!isRec(part)) { red('invalid-value', w, '{text, class, ...}'); return; }
|
|
82
|
+
for (const k of Object.keys(part)) {
|
|
83
|
+
if (!PART_FIELDS.includes(k)) red('invalid-value', `${w}.${k}`, `"${k}" is not a field of a part — fields: ${PART_FIELDS.join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
if (!nonEmpty(part.text)) red('missing-field', `${w}.text`, 'the part, in the person\'s own words (a non-empty string)');
|
|
86
|
+
if (!PART_CLASSES.includes(part.class)) { red('invalid-value', `${w}.class`, `one of ${PART_CLASSES.join(' | ')}`); return; }
|
|
87
|
+
if (Object.hasOwn(part, 'covers') && !(Array.isArray(part.covers) && part.covers.length > 0 && new Set(part.covers).size === part.covers.length
|
|
88
|
+
&& part.covers.every((/** @type {unknown} */ x) => Number.isInteger(x) && /** @type {number} */ (x) >= 1))) {
|
|
89
|
+
red('invalid-value', `${w}.covers`, 'the numbers of the confirmed checks this part carries out (distinct integers, 1 or more)');
|
|
90
|
+
}
|
|
91
|
+
if (Object.hasOwn(part, 'rules') && !(Array.isArray(part.rules) && part.rules.length > 0 && new Set(part.rules).size === part.rules.length
|
|
92
|
+
&& part.rules.every((/** @type {unknown} */ x) => Number.isInteger(x) && /** @type {number} */ (x) >= 1))) {
|
|
93
|
+
red('invalid-value', `${w}.rules`, 'the numbers of the line\'s ~ rules this part carries out (distinct integers, 1 or more)');
|
|
94
|
+
}
|
|
95
|
+
if (part.class === 'fact') { factShapeReds(part, w, (c, path, d) => red(c, path, d)); return; }
|
|
96
|
+
if (part.class === 'guard') {
|
|
97
|
+
if (!nameList(part.domains)) red('invalid-value', `${w}.domains`, 'a non-empty array of web domains the rule is about');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (part.class !== 'countable') return;
|
|
101
|
+
if (!Object.hasOwn(COUNT_CHECKS, part.check)) { red('invalid-value', `${w}.check`, `one of ${Object.keys(COUNT_CHECKS).join(' | ')}`); return; }
|
|
102
|
+
for (const f of COUNT_CHECKS[part.check]) {
|
|
103
|
+
const ok = f === 'value' || f === 'wordsPerSection' || f === 'size' ? Number.isInteger(part[f]) && part[f] >= 1
|
|
104
|
+
: f === 'names' || f === 'phrases' ? nameList(part[f])
|
|
105
|
+
: f === 'from' ? Array.isArray(part.from) && part.from.length > 0 && new Set(part.from).size === part.from.length && part.from.every((/** @type {unknown} */ x) => Number.isInteger(x) && /** @type {number} */ (x) >= 1)
|
|
106
|
+
: nonEmpty(part.source) && part.source.length <= 128;
|
|
107
|
+
if (!ok) {
|
|
108
|
+
red('invalid-value', `${w}.${f}`, f === 'names' ? 'a non-empty array of section names'
|
|
109
|
+
: f === 'phrases' ? 'a non-empty array of words or phrases'
|
|
110
|
+
: f === 'source' ? 'the label of the input a quote must come from'
|
|
111
|
+
: f === 'from' ? 'the numbers of the earlier fact lines whose checked quotes the text\'s numbers come from (distinct integers, 1 or more)'
|
|
112
|
+
: 'an integer, 1 or more');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return reds;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** @param {string} t @returns {string} a time token as compared: no spaces, lower case, no leading zero on the hour */
|
|
120
|
+
const timeKey = (t) => t.replace(/\s+/g, '').toLowerCase().replace(/^0(?=\d:)/, '');
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The person's words read by KIND, so a digit inside a time, a date or an amount belongs to that token only (F242).
|
|
124
|
+
* @param {string} text @returns {{bare: Set<number>, amount: Set<number>, time: Set<string>, date: Set<string>}}
|
|
125
|
+
*/
|
|
126
|
+
const tokensSaid = (text) => {
|
|
127
|
+
const out = { bare: new Set(), amount: new Set(), time: new Set(), date: new Set() };
|
|
128
|
+
const re = /(\d{1,2}:\d{2}(?:\s?[AaPp][Mm])?)|(\d{4}-\d{1,2}-\d{1,2}|\d{1,2}[/.]\d{1,2}[/.]\d{2,4})|([$\u20ac\u00a3]\s?\d[\d,]*(?:\.\d+)?|\d[\d,]*(?:\.\d+)?\s?(?:US\s)?(?:dollars?|euros?|pounds?|USD|EUR|GBP)\b)|(\d[\d,]*(?:\.\d+)?)/gi;
|
|
129
|
+
for (const m of text.matchAll(re)) {
|
|
130
|
+
if (m[1]) out.time.add(timeKey(m[1]));
|
|
131
|
+
else if (m[2]) out.date.add(m[2]);
|
|
132
|
+
else if (m[3]) out.amount.add(Number(m[3].match(/\d[\d,]*(?:\.\d+)?/)?.[0].replace(/,/g, '')));
|
|
133
|
+
else out.bare.add(Number(m[4].replace(/,/g, '')));
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Is this rule bound in the words the person wrote? The ONE test for "a number the AI made" (`rubric-fact-unmarked`, the L3 settle, and
|
|
140
|
+
* the early ask of PRD v1.107 Part 5b all read it; never a second spelling). By kind: a number is said only as a bare number or an
|
|
141
|
+
* amount's number; a time only as a time token (hour leading zero ignored); a date only as a date token. Never a piece of a token.
|
|
142
|
+
* @param {unknown} b @param {string} said @returns {boolean}
|
|
143
|
+
*/
|
|
144
|
+
export const boundInWords = (b, said) => {
|
|
145
|
+
const t = tokensSaid(said);
|
|
146
|
+
if (typeof b === 'number') return t.bare.has(b) || t.amount.has(b);
|
|
147
|
+
if (typeof b !== 'string') return false;
|
|
148
|
+
return /^\s*\d{1,2}:\d{2}/.test(b) ? t.time.has(timeKey(b)) : t.date.has(b.trim());
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
const TIME_RANGE_RE = /\b(?:between|from)\s+(\d{1,2}:\d{2}(?:\s?[AaPp][Mm])?)\s+(?:and|to|-)\s+(\d{1,2}:\d{2}(?:\s?[AaPp][Mm])?)/i;
|
|
153
|
+
const TIME_RANGE_ALL_RE = /\b(?:between|from)\s+(\d{1,2}:\d{2}(?:\s?[AaPp][Mm])?)\s+(?:and|to|-)\s+(\d{1,2}:\d{2}(?:\s?[AaPp][Mm])?)/gi;
|
|
154
|
+
|
|
155
|
+
export const NEGATING_RE = /\b(?:not|no|never|outside|except|before|after|without)\b/i;
|
|
156
|
+
|
|
157
|
+
// The limit reader (hamr ruling A, 2026-11-12): when the look tied a money or time fact to a `~` rule but gave no limit, CODE reads the limit
|
|
158
|
+
// from the person's own rule words. ONE amount or ONE range only; every other text is a plain reason (Not checked), never a wrong check.
|
|
159
|
+
// The direction words are the FACT_OPS words of src/facts.js (lt under, lte at most, gt over, gte at least) plus their plain synonyms.
|
|
160
|
+
|
|
161
|
+
const AMOUNT_ALL_RE = /(?:[$\u20ac\u00a3]\s?(\d[\d,]*(?:\.\d+)?)|(\d[\d,]*(?:\.\d+)?)\s?(?:US\s)?(?:dollars?|euros?|pounds?|USD|EUR|GBP)\b)/gi;
|
|
162
|
+
|
|
163
|
+
const MONEY_BETWEEN_RE = /\bbetween\s+(?:[$\u20ac\u00a3]\s?(\d[\d,]*(?:\.\d+)?)|(\d[\d,]*(?:\.\d+)?)\s?(?:US\s)?(?:dollars?|euros?|pounds?|USD|EUR|GBP)\b)\s+(?:and|to|-)\s+(?:[$\u20ac\u00a3]\s?(\d[\d,]*(?:\.\d+)?)|(\d[\d,]*(?:\.\d+)?)\s?(?:US\s)?(?:dollars?|euros?|pounds?|USD|EUR|GBP)\b)/i;
|
|
164
|
+
|
|
165
|
+
const MONEY_DIRECTION_RE = /\b(under|below|less than|fewer than|at most|up to|no more than|over|above|more than|at least|no less than|no fewer than)\s+(?:[$\u20ac\u00a3]\s?(\d[\d,]*(?:\.\d+)?)|(\d[\d,]*(?:\.\d+)?)\s?(?:US\s)?(?:dollars?|euros?|pounds?|USD|EUR|GBP)\b)/i;
|
|
166
|
+
|
|
167
|
+
const MONEY_OR_LESS_RE = /(?:[$\u20ac\u00a3]\s?(\d[\d,]*(?:\.\d+)?)|(\d[\d,]*(?:\.\d+)?)\s?(?:US\s)?(?:dollars?|euros?|pounds?|USD|EUR|GBP)\b)\s+or\s+(less|fewer|under|below|lower|more|over|above|higher)\b/i;
|
|
168
|
+
|
|
169
|
+
const DIRECTION_OP = /** @type {Record<string, 'lt'|'lte'|'gt'|'gte'>} */ ({ under: 'lt', below: 'lt', 'less than': 'lt', 'fewer than': 'lt', 'at most': 'lte', 'up to': 'lte', 'no more than': 'lte', over: 'gt', above: 'gt', 'more than': 'gt', 'at least': 'gte', 'no less than': 'gte', 'no fewer than': 'gte' });
|
|
170
|
+
|
|
171
|
+
const CURRENCY_STEM = /** @type {Record<string, string>} */ ({ $: 'dollar', '€': 'euro', '£': 'pound', usd: 'dollar', eur: 'euro', gbp: 'pound' });
|
|
172
|
+
|
|
173
|
+
const num = (/** @type {string|undefined} */ a, /** @type {string|undefined} */ b) => Number(String(a ?? b).replace(/,/g, ''));
|
|
174
|
+
|
|
175
|
+
const hhmm = (/** @type {string} */ t) => (/[AaPp][Mm]/.test(t) ? null : t.replace(/\s+/g, '').replace(/^(\d):/, '0$1:'));
|
|
176
|
+
|
|
177
|
+
/** does the amount token's currency (sign or word) fit the look fact's currency and unit lists? A fact with neither list fits anything. */
|
|
178
|
+
function currencyFits(/** @type {string} */ tok, /** @type {any} */ fact) {
|
|
179
|
+
const cur = (Array.isArray(fact?.currency) ? fact.currency : fact?.currency ? [fact.currency] : []).map(String);
|
|
180
|
+
const unit = (Array.isArray(fact?.unit) ? fact.unit : fact?.unit ? [fact.unit] : []).map((/** @type {unknown} */ u) => String(u).toLowerCase());
|
|
181
|
+
if (!cur.length && !unit.length) return true;
|
|
182
|
+
const sym = /^[$€£]/.test(tok) ? tok.charAt(0) : null;
|
|
183
|
+
const last = String(tok.trim().split(/\s+/).at(-1)).toLowerCase();
|
|
184
|
+
const stem = sym ? CURRENCY_STEM[sym] : (CURRENCY_STEM[last] ?? last.replace(/s$/, ''));
|
|
185
|
+
return (sym !== null && cur.includes(sym)) || unit.some((/** @type {string} */ u) => u.includes(String(stem)));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Does this rule text hold more than one amount (money) or more than one time range (time)? The ONE guard code's own limit read and an AI
|
|
190
|
+
* reading edit both use: "under $450 or over $900" is two limits, and one reading of it would be a wrong check.
|
|
191
|
+
* @param {string} shape @param {string} text @returns {boolean}
|
|
192
|
+
*/
|
|
193
|
+
export function holdsManyBounds(shape, text) {
|
|
194
|
+
const t = String(text ?? '');
|
|
195
|
+
if (shape === 'time') return [...t.matchAll(TIME_RANGE_ALL_RE)].length > 1 || (t.match(/\d{1,2}:\d{2}/g) ?? []).length > 2;
|
|
196
|
+
if (shape === 'money') { const amts = [...t.matchAll(AMOUNT_ALL_RE)]; return amts.length > 1 && !(MONEY_BETWEEN_RE.test(t) && amts.length === 2); }
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The limit the person's own words give a fact of this shape: `{reading}` or `{why}` (a plain reason; the rule then stays Not checked).
|
|
202
|
+
* @param {string} shape money or time @param {string} text the `~` rule's words @param {any} [fact] the look fact (its currency and unit lists must fit)
|
|
203
|
+
* @returns {{reading: {op: 'lt'|'lte'|'gt'|'gte', value: number} | {op: 'between', lo: number|string, hi: number|string}} | {why: string}}
|
|
204
|
+
*/
|
|
205
|
+
export function readLimit(shape, text, fact = {}) {
|
|
206
|
+
const t = String(text ?? '');
|
|
207
|
+
if (shape === 'time') {
|
|
208
|
+
if (NEGATING_RE.test(t)) return { why: 'a one-sided or negated time (before, after, not) is not a range code can read' };
|
|
209
|
+
if (/\b\d{1,2}(?::\d{2})?\s?[ap]\.?m\b/i.test(t)) return { why: 'a 12-hour time (am or pm) is not read, write it like 06:00' };
|
|
210
|
+
if (holdsManyBounds('time', t)) return { why: 'more than one time range in the rule' };
|
|
211
|
+
const m = TIME_RANGE_RE.exec(t);
|
|
212
|
+
if (!m) return { why: 'no range between two times in the rule' };
|
|
213
|
+
const lo = hhmm(String(m[1])), hi = hhmm(String(m[2]));
|
|
214
|
+
if (!lo || !hi) return { why: 'a 12-hour time (am or pm) is not read, write it like 06:00' };
|
|
215
|
+
if (lo >= hi) return { why: 'a range whose end is not after its start is not read' };
|
|
216
|
+
return { reading: { op: 'between', lo, hi } };
|
|
217
|
+
}
|
|
218
|
+
if (shape === 'money') {
|
|
219
|
+
if (/\b(?:not|never|outside|except|without)\b/i.test(t)) return { why: 'a negated limit (not, except, without) is not read' };
|
|
220
|
+
const amts = [...t.matchAll(AMOUNT_ALL_RE)];
|
|
221
|
+
if (!amts.length) return { why: 'no amount with a currency sign or word in the rule' };
|
|
222
|
+
for (const a of amts) if (!currencyFits(a[0], fact)) return { why: 'the amount is in another currency than the page fact' };
|
|
223
|
+
if (holdsManyBounds('money', t)) return { why: 'more than one amount in the rule' };
|
|
224
|
+
const b = MONEY_BETWEEN_RE.exec(t);
|
|
225
|
+
if (b) { const lo = num(b[1], b[2]), hi = num(b[3], b[4]); return lo < hi ? { reading: { op: 'between', lo, hi } } : { why: 'a range whose end is not above its start is not read' }; }
|
|
226
|
+
const d = MONEY_DIRECTION_RE.exec(t);
|
|
227
|
+
if (d) return { reading: { op: /** @type {'lt'|'lte'|'gt'|'gte'} */ (DIRECTION_OP[String(d[1]).toLowerCase()]), value: num(d[2], d[3]) } };
|
|
228
|
+
const o = MONEY_OR_LESS_RE.exec(t);
|
|
229
|
+
if (o) return { reading: { op: /^(less|fewer|under|below|lower)$/i.test(String(o[3])) ? 'lte' : 'gte', value: num(o[1], o[2]) } };
|
|
230
|
+
return { why: 'the rule gives an amount but no direction (under, over, at most, at least, between)' };
|
|
231
|
+
}
|
|
232
|
+
return { why: 'code reads a limit only for money or time' };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** the words of the default cited check code adds to a text line of a one-input job (the one list's `$` row); the card reads a part with exactly these words as `[default]` @param {string} label @returns {string} */
|
|
236
|
+
export const defaultCitedText = (label) => `every claim is backed by a quote copied from "${label}"`;
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
// borrowed-from: bareloop src/rubricstep.js@v0.56.0 (3383cce) (listMatchesClose: the signing door's test of the list against the close; bareloop's stages shape, the block's own closeCache.stages; fwd's close is shaped differently, so wiring it to fwd's close is a later piece)
|
|
240
|
+
/**
|
|
241
|
+
* The sign-time check of a close that carries the one check list: every BUILT row (the mechanical floor aside) points at a part that is really in the close, and every real check part
|
|
242
|
+
* (countable or fact) has at least one built row pointing at it, so a check cannot be in the close with no row and a row cannot claim a check the close does not run. A close with no list is
|
|
243
|
+
* not examined here. Pure.
|
|
244
|
+
* @param {any} closeDecl @returns {{ok: true}|{ok: false, error: string}}
|
|
245
|
+
*/
|
|
246
|
+
export function listMatchesClose(closeDecl) {
|
|
247
|
+
const list = isRec(closeDecl) && Array.isArray(closeDecl.list) ? closeDecl.list : null;
|
|
248
|
+
if (list === null) return { ok: true };
|
|
249
|
+
const stages = Array.isArray(closeDecl.stages) ? closeDecl.stages : [];
|
|
250
|
+
const partsOn = (/** @type {number} */ n) => stages.filter((/** @type {any} */ st) => isRec(st) && st.kind === 'rubric-step' && isRec(st.params) && st.params.step === n && Array.isArray(st.params.parts)).flatMap((/** @type {any} */ st) => st.params.parts);
|
|
251
|
+
const built = list.filter((/** @type {any} */ r) => isRec(r) && r.state === 'built' && r.kind !== 'floor');
|
|
252
|
+
const bad = built.filter((/** @type {any} */ r) => !(isRec(r.part) && r.part.line === r.line && Number.isInteger(r.part.part) && isRec(partsOn(r.line)[r.part.part])));
|
|
253
|
+
const lines = [...new Set(stages.filter((/** @type {any} */ st) => isRec(st) && st.kind === 'rubric-step' && isRec(st.params)).map((/** @type {any} */ st) => st.params.step))];
|
|
254
|
+
const bare = lines.flatMap((/** @type {number} */ n) => partsOn(n).map((/** @type {any} */ p, /** @type {number} */ i) => ({ n, i, p })))
|
|
255
|
+
.filter(({ p }) => isRec(p) && (p.class === 'countable' || p.class === 'fact'))
|
|
256
|
+
// a part has its row when a built row points at it, or when the part lists (in its `rules`) the number of a built `~` row of its line (a row points at ONE part, a rule may be carried by several)
|
|
257
|
+
.filter(({ n, i, p }) => !built.some((/** @type {any} */ r) => (isRec(r.part) && r.part.line === n && r.part.part === i)
|
|
258
|
+
|| (r.kind === 'rule' && r.line === n && Array.isArray(p.rules) && p.rules.includes(r.rule))));
|
|
259
|
+
if (bad.length === 0 && bare.length === 0) return { ok: true };
|
|
260
|
+
const parts = [];
|
|
261
|
+
if (bad.length) parts.push(`a row points at a check the close does not run: ${bad.map((/** @type {any} */ r) => r.key).join('; ')}`);
|
|
262
|
+
if (bare.length) parts.push(`a check in the close has no row: line ${bare.map(({ n, i }) => `${n} part ${i + 1}`).join('; ')}`);
|
|
263
|
+
return { ok: false, error: `The list of checks does not match the signed close (${parts.join(' | ')}). Nothing was signed — draft again.` };
|
|
264
|
+
}
|
package/src/runfile.js
CHANGED
|
@@ -50,12 +50,14 @@ export function readRunInputs(runDir) {
|
|
|
50
50
|
* M8b item 1: the ONE writer of `run.json`, called once when a fresh run has frozen its inputs (`runFlow`); never over an existing record. `model` is the pick
|
|
51
51
|
* the run started on (M4d am33; null = the section is left out), `thinking` the job's "Thinking on" box as it was at the start (M4d am25: written for every fresh
|
|
52
52
|
* run, ticked or not), `inputs` the manifest `freezeInputs` returned. A fresh run always has `thinking` and `inputs`.
|
|
53
|
-
* @param {string} runDir @param {{ model: { slot: string, model: string }|null, thinking: boolean, inputs: any[], rerun?: {decision: 'rerun', words: string, afterStep: string|null}|null }} start
|
|
53
|
+
* @param {string} runDir @param {{ model: { slot: string, model: string }|null, thinking: boolean, inputs: any[], rerun?: {decision: 'rerun', words: string, afterStep: string|null}|null, placeRules?: {rows: any[]}|null }} start
|
|
54
54
|
*/
|
|
55
|
-
export function writeRunStart(runDir, { model, thinking, inputs, rerun = null }) {
|
|
55
|
+
export function writeRunStart(runDir, { model, thinking, inputs, rerun = null, placeRules = null }) {
|
|
56
56
|
writeFileSync(join(runDir, RUN_FILE), `${JSON.stringify({
|
|
57
57
|
...(model ? { model: { slot: model.slot, model: model.model } } : {}), thinking, inputs,
|
|
58
58
|
// M14 am1 item 1: a rerun keeps the reason it was started with (the decision, the human's words, the step the old run's ask followed); a fresh run has no such key
|
|
59
59
|
...(rerun ? { rerun: { decision: rerun.decision, words: rerun.words, afterStep: rerun.afterStep } } : {}),
|
|
60
|
+
// M16 item 1 / am3 (3): the values the run read for its place-rule facts at its start (a resume rebinds them from here); a job with no place rule has no such key
|
|
61
|
+
...(placeRules ? { placeRules } : {}),
|
|
60
62
|
}, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
61
63
|
}
|
package/src/runner.js
CHANGED
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
import { configHome, configDoorHome } from './config.js';
|
|
60
60
|
import { closeByClass, isCellsPath } from './closers.js';
|
|
61
61
|
import { readRunSource } from './cited-source.js';
|
|
62
|
-
import { citedLineOf, writeCitedLine } from './cited-record.js';
|
|
62
|
+
import { citedLineOf, writeCitedLine, quotesOfLines } from './cited-record.js';
|
|
63
63
|
import { sheetRolesOf, tableShaOfFrozen, readRunSheets } from './sheetrun.js';
|
|
64
64
|
import { writeSheetLine } from './sheet-record.js';
|
|
65
65
|
import {
|
|
@@ -75,7 +75,9 @@ import {
|
|
|
75
75
|
doneRecord, happenedRecord, outputRecord, closeRecords,
|
|
76
76
|
} from './try-checks.js';
|
|
77
77
|
import { readJobThinking, readModelRecord, takeLearningsRecord } from './flowmodel.js';
|
|
78
|
-
import { readRunInputs, writeRunStart } from './runfile.js';
|
|
78
|
+
import { readRunInputs, readRunRecord, writeRunStart } from './runfile.js';
|
|
79
|
+
// borrowed-from: bareloop src/userrun.js@v0.56.0 (3383cce) (the place-rule read at run start and its stop words; fwd keeps the read value in run.json, not a spine)
|
|
80
|
+
import { citedPlaceFactsOf, bindCitedPlaceValues, readPlaceRules, valueInWords, stopWords, placeValuesOfEvents, lastRunPlaceRead, PLACE_EVENT, NO_PLACE_RECORD_WORDS } from './placerule.js';
|
|
79
81
|
import { buildMemo } from './memo.js';
|
|
80
82
|
import { wholeJobAskIndex, wholeJobText } from './whole-job.js';
|
|
81
83
|
import { fetchPageText, isWebUrl } from './pagefetch.js';
|
|
@@ -483,6 +485,36 @@ export async function freezeInputs(runDir, sources, { fetchPage, tableRoles = []
|
|
|
483
485
|
return { ok: true, manifest, skip };
|
|
484
486
|
}
|
|
485
487
|
|
|
488
|
+
/**
|
|
489
|
+
* M16 item 1: read every place-rule fact of the job's steps from the run's OWN frozen copy of its input, by code, before any provider call. `{ok:false, words}` = a rule
|
|
490
|
+
* was not found (bareloop's stop words); `{ok:true, rows, values}` = the rows to record in run.json and the key-to-value map to bind in memory. No place fact = nothing read.
|
|
491
|
+
* @param {string} runDir @param {any[]} steps @param {any[]} manifest freezeInputs' manifest @param {Record<string, string>} [earlier] key to the value the newest earlier run read ("was")
|
|
492
|
+
*/
|
|
493
|
+
export function readRunPlaceRules(runDir, steps, manifest, earlier = {}) {
|
|
494
|
+
const facts = citedPlaceFactsOf(steps);
|
|
495
|
+
if (facts.length === 0) return { ok: /** @type {true} */ (true), rows: null, values: {} };
|
|
496
|
+
const read = readPlaceRules(facts.map((fact) => {
|
|
497
|
+
const entry = manifest.find((e) => e?.id === fact.source);
|
|
498
|
+
const file = entry && typeof entry.frozen === 'string' ? readFileInside(runDir, `inputs/${basename(entry.frozen)}`) : null;
|
|
499
|
+
return { fact, text: file && file.ok ? file.text : null, was: earlier[fact.key] ?? valueInWords(fact.place, fact.phrase) };
|
|
500
|
+
}));
|
|
501
|
+
if (!read.proceed) return { ok: /** @type {false} */ (false), words: stopWords(read.rows) };
|
|
502
|
+
return { ok: /** @type {true} */ (true), rows: read.rows.map(({ name: _n, ...r }) => r), values: read.values };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* M16 item 1: the steps a RESUMED / continued run carries on with: the signed steps, each place fact's phrase set to the value its own run.json recorded at the start.
|
|
507
|
+
* A job with no place fact returns its steps as they are; a run whose record is missing or has a rule not found is `{ok:false, words: NO_PLACE_RECORD_WORDS}`.
|
|
508
|
+
* @param {string} runDir @param {any[]} steps
|
|
509
|
+
*/
|
|
510
|
+
export function stepsWithRecordedPlaces(runDir, steps) {
|
|
511
|
+
if (citedPlaceFactsOf(steps).length === 0) return { ok: /** @type {true} */ (true), steps };
|
|
512
|
+
const got = readRunRecord(runDir);
|
|
513
|
+
const values = got.ok && Array.isArray(got.rec.placeRules?.rows) ? placeValuesOfEvents([{ type: PLACE_EVENT, rows: got.rec.placeRules.rows }]) : null;
|
|
514
|
+
if (values === null) return { ok: /** @type {false} */ (false), words: NO_PLACE_RECORD_WORDS };
|
|
515
|
+
return { ok: /** @type {true} */ (true), steps: bindCitedPlaceValues(steps, values) };
|
|
516
|
+
}
|
|
517
|
+
|
|
486
518
|
/**
|
|
487
519
|
* The sources a rerun re-freezes: each input's original source. M13 item 9.1: a ticket input's source is the ticket's own address; it goes back as its LIST address with the
|
|
488
520
|
* ticket mark, so the rerun reads the ticket through the job's MCP tools and the signed filter, not as a web page.
|
|
@@ -893,6 +925,7 @@ function makeAuditRow({
|
|
|
893
925
|
* @param {string|null} [opts.prevStepId] - the id of step stepNo-1 (null for step 1): the step a "stopped after step N-1" row is filed under
|
|
894
926
|
* @param {number} [opts.triesDone] - tries a Stop already closed on this step (they count against its limit)
|
|
895
927
|
* @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
|
|
928
|
+
* @param {any[]} [opts.checkList] - M16 item 5: the plan's signed list; a list line's checks carry the row's `by`
|
|
896
929
|
* @param {Record<string, any>} [opts.mcpGranted] - M13 item 5: this step's signed MCP tools, already bound to its bridge (`runStepRalph` builds them); handed to the model with the verbs
|
|
897
930
|
* @returns {Promise<{ok:true, artifact:any, attempts:number, hitl?:boolean} | {ok:false, outcome:string, red:string, stop?:{where:string, book:Record<string, any>, step?:string|null}}>}
|
|
898
931
|
*/
|
|
@@ -917,6 +950,8 @@ async function runStepTries({
|
|
|
917
950
|
// the id of step stepNo-1 (null for step 1): a Stop before this step's first call words itself "after step N-1" and is filed under that step
|
|
918
951
|
prevStepId = null,
|
|
919
952
|
mcpGranted = {},
|
|
953
|
+
// M16 item 5: the signed list (declaration.checkList), so a check of a list line is tagged by its row in the Audit
|
|
954
|
+
checkList = undefined,
|
|
920
955
|
}) {
|
|
921
956
|
/** @type {string|null} */
|
|
922
957
|
let gap = initialGap ?? null;
|
|
@@ -1159,14 +1194,16 @@ async function runStepTries({
|
|
|
1159
1194
|
// said is written by the one writer, `writeSheetLine`, whatever the verdict.
|
|
1160
1195
|
const sheetPart = step?.close?.class === 'green' && Array.isArray(step?.close?.sheet) ? step.close.sheet : undefined;
|
|
1161
1196
|
const sheet = sheetPart && runDir !== null ? readRunSheets(runDir, sheetPart) : undefined;
|
|
1162
|
-
|
|
1197
|
+
// M16 R7: a text step with the numbers tie (`close.numbersFrom`) is checked against the quotes the earlier lines' cited checks passed on, read from this run's own record
|
|
1198
|
+
const numbers = Array.isArray(step?.close?.numbersFrom) && runDir !== null ? quotesOfLines(runDir, step.close.numbersFrom) : undefined;
|
|
1199
|
+
const closed = await closeByClass(step, artifact, { reads: readsMap, businessDate, source, sheet, numbers });
|
|
1163
1200
|
if (sheetPart && runDir !== null && closed.sheetRecord) writeSheetLine(runDir, { n: step.fromLine, try: attempt, checks: sheetPart, closed });
|
|
1164
1201
|
if (citedPart && runDir !== null && closed.cited) {
|
|
1165
1202
|
writeCitedLine(runDir, citedLineOf({
|
|
1166
1203
|
n: step.fromLine, part: closed.cited.part, results: closed.cited.results, check: closed.cited.check,
|
|
1167
1204
|
}));
|
|
1168
1205
|
}
|
|
1169
|
-
tryChecks.push(...closeRecords(step, artifact, closed));
|
|
1206
|
+
tryChecks.push(...closeRecords(step, artifact, closed, checkList));
|
|
1170
1207
|
saveTry();
|
|
1171
1208
|
|
|
1172
1209
|
if (closed.verdict === 'green' || closed.verdict === 'hitl') {
|
|
@@ -1413,7 +1450,14 @@ export async function runFlow({
|
|
|
1413
1450
|
}
|
|
1414
1451
|
|
|
1415
1452
|
// M8b item 1: the run's start record, written once: the model it started on (M4d am33), the "Thinking on" box (M4d am25) and the frozen inputs
|
|
1416
|
-
|
|
1453
|
+
// M16 item 1: the place-rule facts are read from this run's own frozen copy, before any provider call; a rule not found stops here at $0 (a skipped ticket reads nothing)
|
|
1454
|
+
const placed = frozen.skip ? { ok: /** @type {true} */ (true), rows: null, values: {} } : readRunPlaceRules(runDir, declaration.steps, /** @type {any[]} */ (frozen.manifest), lastRunPlaceRead({ flowDir, runId }));
|
|
1455
|
+
if (!placed.ok) {
|
|
1456
|
+
return haltRun({
|
|
1457
|
+
flowDir, runDir, runId, capUsd, startedAt, now, nowMs: getNowMs, signatureHash: signature.flow, outcome: 'preflight-red', red: placed.words, spent: { value: 0 },
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
writeRunStart(runDir, { model: runModel ?? null, thinking: thinkingBox, inputs: /** @type {any[]} */ (frozen.manifest), rerun: rerunOf ?? null, placeRules: placed.rows ? { rows: placed.rows } : null });
|
|
1417
1461
|
// M12 piece 3 (item 9): a ticket the signed labels do not match, or a closed one, ends here: skipped, $0, nothing else runs
|
|
1418
1462
|
if (frozen.skip) {
|
|
1419
1463
|
return haltRun({
|
|
@@ -1458,7 +1502,7 @@ export async function runFlow({
|
|
|
1458
1502
|
/** @type {Array<{step:string|null, emits:string, artifact:unknown}>} */
|
|
1459
1503
|
let unjudgedSinceLastAsk = [];
|
|
1460
1504
|
|
|
1461
|
-
const steps = declaration.steps;
|
|
1505
|
+
const steps = Object.keys(placed.values).length > 0 ? bindCitedPlaceValues(declaration.steps, placed.values) : declaration.steps;
|
|
1462
1506
|
// M2 fix: the send's content is identified by IDENTITY (the artifact
|
|
1463
1507
|
// emitted by a signed ask step), never by position in `reads` — every id
|
|
1464
1508
|
// in a send step's `reads` names an earlier step, so picking `reads[0]`
|
|
@@ -1474,6 +1518,7 @@ export async function runFlow({
|
|
|
1474
1518
|
|
|
1475
1519
|
const result = await foldFromStep({
|
|
1476
1520
|
mcpServer: declaration.mcp?.server ?? null,
|
|
1521
|
+
checkList: declaration.checkList,
|
|
1477
1522
|
i0: 0,
|
|
1478
1523
|
steps,
|
|
1479
1524
|
askLines,
|
|
@@ -1608,6 +1653,8 @@ async function runAskSlot({
|
|
|
1608
1653
|
mcpServer = /** @type {string|null} */ (null),
|
|
1609
1654
|
// M13 am9: set only for the Ask that shows the whole job; rebuilds `{text}` from the saved outputs after a redo changed one
|
|
1610
1655
|
rebuildPrior = /** @type {null | (() => ({ok:true,value:any}|{ok:false,red:string}))} */ (null),
|
|
1656
|
+
// M16 item 5: the signed list, handed on to a redo's tries
|
|
1657
|
+
checkList = /** @type {any[]|undefined} */ (undefined),
|
|
1611
1658
|
}) {
|
|
1612
1659
|
let redone = initialRedone;
|
|
1613
1660
|
let currentPrior = priorArtifact;
|
|
@@ -1784,7 +1831,7 @@ async function runAskSlot({
|
|
|
1784
1831
|
}
|
|
1785
1832
|
// eslint-disable-next-line no-await-in-loop
|
|
1786
1833
|
const redoResult = await runStepRalph({
|
|
1787
|
-
step: priorStep, primitivesMap: primitives, readsMap: priorReadsResult.map, businessDate, modelStep, spent, capUsd, ceilingUsd: effectiveCeilingUsd, recordAudit, mcpServer, initialGap: reason, attemptOffset: lastTryNumber(runDir, priorStep.emits ?? priorStep.goal ?? null), thinkingBox: readJobThinking(flowDir, runDir), learnHints: stepHintsReader({ flowName, source: inputsManifest?.[0]?.source ?? null, now }), now, runDir,
|
|
1834
|
+
step: priorStep, primitivesMap: primitives, readsMap: priorReadsResult.map, businessDate, modelStep, spent, capUsd, ceilingUsd: effectiveCeilingUsd, recordAudit, mcpServer, checkList, initialGap: reason, attemptOffset: lastTryNumber(runDir, priorStep.emits ?? priorStep.goal ?? null), thinkingBox: readJobThinking(flowDir, runDir), learnHints: stepHintsReader({ flowName, source: inputsManifest?.[0]?.source ?? null, now }), now, runDir,
|
|
1788
1835
|
readStop: () => stopPending(runDir), stepNo: priorStepNo, prevStepId: priorPrevStepId,
|
|
1789
1836
|
});
|
|
1790
1837
|
if (!redoResult.ok) {
|
|
@@ -1849,6 +1896,8 @@ async function foldFromStep({
|
|
|
1849
1896
|
resumeRedone = 0,
|
|
1850
1897
|
// M13 item 5: the job's signed `mcp.server`, for a step that grants MCP tools (`runStepRalph` starts its bridge)
|
|
1851
1898
|
mcpServer = /** @type {string|null} */ (null),
|
|
1899
|
+
// M16 item 5: the signed list (declaration.checkList): a list line's checks are tagged by their row in the Audit
|
|
1900
|
+
checkList = /** @type {any[]|undefined} */ (undefined),
|
|
1852
1901
|
}) {
|
|
1853
1902
|
let runAcceptedThisRun = acceptedThisRun;
|
|
1854
1903
|
let runUnjudged = unjudgedSinceLastAsk;
|
|
@@ -1989,6 +2038,7 @@ async function foldFromStep({
|
|
|
1989
2038
|
// eslint-disable-next-line no-await-in-loop
|
|
1990
2039
|
const askResult = await runAskSlot({
|
|
1991
2040
|
mcpServer,
|
|
2041
|
+
checkList,
|
|
1992
2042
|
step,
|
|
1993
2043
|
stepIndex: i,
|
|
1994
2044
|
askSlot,
|
|
@@ -2062,7 +2112,7 @@ async function foldFromStep({
|
|
|
2062
2112
|
// redo's `initialGap` above.
|
|
2063
2113
|
// eslint-disable-next-line no-await-in-loop
|
|
2064
2114
|
const stepResult = await runStepRalph({
|
|
2065
|
-
step, primitivesMap: primitives, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd: effectiveCeilingUsd, recordAudit, mcpServer, initialGap: i === i0 ? firstStepGap : null, thinkingBox: readJobThinking(flowDir, runDir), learnHints: stepHintsReader({ flowName, source: inputsManifest?.[0]?.source ?? null, now }), now, runDir,
|
|
2115
|
+
step, primitivesMap: primitives, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd: effectiveCeilingUsd, recordAudit, mcpServer, checkList, initialGap: i === i0 ? firstStepGap : null, thinkingBox: readJobThinking(flowDir, runDir), learnHints: stepHintsReader({ flowName, source: inputsManifest?.[0]?.source ?? null, now }), now, runDir,
|
|
2066
2116
|
readStop: () => stopPending(runDir), stepNo: i + 1, prevStepId: i > 0 ? (steps[i - 1].emits ?? steps[i - 1].goal ?? null) : null, attemptOffset: i === i0 ? resumeTries.numbered : 0, triesDone: i === i0 ? resumeTries.done : 0,
|
|
2067
2117
|
});
|
|
2068
2118
|
if (!stepResult.ok) {
|
|
@@ -2370,7 +2420,9 @@ export async function resumeRun({
|
|
|
2370
2420
|
// like `missing` — never silently treated as "not done yet" and redone,
|
|
2371
2421
|
// which could spend money or re-ask a human for a step that already
|
|
2372
2422
|
// completed.
|
|
2373
|
-
const
|
|
2423
|
+
const placedSteps = stepsWithRecordedPlaces(runDir, declaration.steps);
|
|
2424
|
+
if (!placedSteps.ok) return { outcome: 'refused', red: placedSteps.words };
|
|
2425
|
+
const steps = placedSteps.steps;
|
|
2374
2426
|
for (let i = 0; i < state.stepIndex; i += 1) {
|
|
2375
2427
|
const artifactResult = readArtifactResult(runDir, steps[i].emits);
|
|
2376
2428
|
if (!artifactResult.ok) {
|
|
@@ -2678,6 +2730,7 @@ export async function resumeRun({
|
|
|
2678
2730
|
|
|
2679
2731
|
const askResult = await runAskSlot({
|
|
2680
2732
|
mcpServer: declaration.mcp?.server ?? null,
|
|
2733
|
+
checkList: declaration.checkList,
|
|
2681
2734
|
step,
|
|
2682
2735
|
stepIndex: state.stepIndex,
|
|
2683
2736
|
askSlot,
|
|
@@ -2734,6 +2787,7 @@ export async function resumeRun({
|
|
|
2734
2787
|
|
|
2735
2788
|
const result = await foldFromStep({
|
|
2736
2789
|
mcpServer: declaration.mcp?.server ?? null,
|
|
2790
|
+
checkList: declaration.checkList,
|
|
2737
2791
|
i0: state.stepIndex + 1,
|
|
2738
2792
|
steps,
|
|
2739
2793
|
askLines,
|
|
@@ -2872,7 +2926,9 @@ export async function continueRun({
|
|
|
2872
2926
|
}
|
|
2873
2927
|
}
|
|
2874
2928
|
|
|
2875
|
-
const
|
|
2929
|
+
const placedSteps = stepsWithRecordedPlaces(runDir, declaration.steps);
|
|
2930
|
+
if (!placedSteps.ok) return refused(placedSteps.words);
|
|
2931
|
+
const steps = placedSteps.steps;
|
|
2876
2932
|
if (halt.stepIndex > steps.length) return refused(`run "${runId}" halt.json names step ${halt.stepIndex}, past this flow's ${steps.length} steps`);
|
|
2877
2933
|
/** @type {Record<string, any>} */
|
|
2878
2934
|
const artifacts = {};
|
|
@@ -2940,6 +2996,7 @@ export async function continueRun({
|
|
|
2940
2996
|
|
|
2941
2997
|
const result = await foldFromStep({
|
|
2942
2998
|
mcpServer: declaration.mcp?.server ?? null,
|
|
2999
|
+
checkList: declaration.checkList,
|
|
2943
3000
|
i0: halt.stepIndex,
|
|
2944
3001
|
resumeTries,
|
|
2945
3002
|
steps,
|