fwdloop 0.36.0 → 0.38.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 +6 -20
- package/bin/fwdloop +35 -12
- package/package.json +3 -3
- package/src/action-stop.js +1 -1
- package/src/auditchecks.js +41 -9
- package/src/authoring.js +78 -20
- package/src/blockasks.js +10 -12
- package/src/blockassemble.js +49 -46
- package/src/blockdraft.js +4 -2
- package/src/blockpick.js +10 -0
- package/src/canrun.js +2 -1
- package/src/cardlist.js +28 -5
- package/src/checkblock.js +598 -61
- package/src/checked.js +27 -33
- package/src/checklistsign.js +3 -3
- package/src/checklook.js +45 -0
- package/src/checkrows.js +202 -0
- package/src/cited-record.js +2 -2
- package/src/citedcheck.js +53 -12
- package/src/citedwords.js +7 -4
- package/src/closers.js +49 -2
- package/src/declaration.js +34 -10
- package/src/drafter.js +99 -74
- package/src/factwords.js +7 -4
- package/src/globprefix.js +26 -0
- package/src/isrec.js +2 -0
- package/src/line-checks.js +1 -2
- package/src/minrule.js +16 -0
- package/src/model-step.js +22 -4
- package/src/pageask.js +0 -3
- package/src/pagedropwords.js +3 -11
- package/src/pagedry.js +75 -1
- package/src/pagefetch.js +11 -6
- package/src/pagelook.js +2 -1
- package/src/pagerules.js +8 -2
- package/src/panel/author.js +33 -8
- package/src/panel/data.js +3 -2
- package/src/panel/index.html +177 -37
- package/src/panel/result.js +34 -1
- package/src/pickrecord.js +14 -0
- package/src/planrebuild.js +55 -19
- package/src/ratelimit.js +117 -0
- package/src/report.js +14 -2
- package/src/rowresults.js +111 -0
- package/src/rubricstep.js +65 -2
- package/src/runner.js +38 -5
- package/src/shapebuild.js +281 -0
- package/src/shapelook.js +91 -0
- package/src/shapemenu.js +64 -0
- package/src/shaperesult.js +104 -0
- package/src/shaperows.js +263 -0
- package/src/shapewords.js +140 -0
- package/src/sheet-record.js +1 -2
- package/src/sheetblock.js +1 -2
- package/src/sheetbuild.js +41 -29
- package/src/sheetchecks.js +1 -2
- package/src/sheetclaims.js +1 -2
- package/src/sheetoffer.js +1 -1
- package/src/sheetrows.js +10 -64
- package/src/sheetrun.js +1 -2
- package/src/ticketrows.js +2 -3
- package/src/try-checks.js +39 -6
- package/src/types.js +1 -0
- package/src/whole-job.js +24 -8
- package/types/action-stop.d.ts +1 -1
- package/types/auditchecks.d.ts +13 -2
- package/types/authoring.d.ts +21 -2
- package/types/blockasks.d.ts +6 -10
- package/types/blockassemble.d.ts +12 -13
- package/types/blockdraft.d.ts +3 -2
- package/types/blockpick.d.ts +4 -0
- package/types/cardlist.d.ts +18 -2
- package/types/checkblock.d.ts +276 -27
- package/types/checked.d.ts +15 -6
- package/types/checklook.d.ts +36 -0
- package/types/checkrows.d.ts +119 -0
- package/types/citedcheck.d.ts +4 -2
- package/types/closers.d.ts +10 -1
- package/types/drafter.d.ts +9 -4
- package/types/globprefix.d.ts +5 -0
- package/types/isrec.d.ts +1 -0
- package/types/minrule.d.ts +6 -0
- package/types/model-step.d.ts +43 -2
- package/types/pageask.d.ts +0 -1
- package/types/pagedropwords.d.ts +0 -1
- package/types/pagedry.d.ts +27 -0
- package/types/pagefetch.d.ts +3 -2
- package/types/pagerules.d.ts +4 -0
- package/types/panel/result.d.ts +16 -1
- package/types/pickrecord.d.ts +10 -0
- package/types/ratelimit.d.ts +59 -0
- package/types/report.d.ts +2 -1
- package/types/rowresults.d.ts +28 -0
- package/types/rubricstep.d.ts +21 -0
- package/types/runner.d.ts +3 -1
- package/types/shapebuild.d.ts +97 -0
- package/types/shapelook.d.ts +76 -0
- package/types/shapemenu.d.ts +40 -0
- package/types/shaperesult.d.ts +40 -0
- package/types/shaperows.d.ts +102 -0
- package/types/shapewords.d.ts +43 -0
- package/types/sheetbuild.d.ts +31 -13
- package/types/sheetrows.d.ts +5 -36
- package/types/ticketrows.d.ts +1 -1
- package/types/try-checks.d.ts +2 -1
- package/types/types.d.ts +4 -0
- package/types/whole-job.d.ts +20 -4
package/src/pagedropwords.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
// borrowed-from: bareloop src/pagedropwords.js@v0.56.0 (3383cce) (the four reasons the block's drops carry, and the sign-twice sentence by `d.other`; FACT_LANGS lives with the facts in src/citedcheck.js)
|
|
10
10
|
import { FACT_LANGS } from './citedcheck.js';
|
|
11
|
+
import { REASON } from './checkblock.js';
|
|
11
12
|
|
|
12
13
|
/** the two ways a sign listed twice can be used once (v0.56.0 spells the sentence from `d.other`; no other -> "currency", the sentence fwd has always written) */
|
|
13
14
|
const SIGN_TWICE_AS = ['currency', 'unit'];
|
|
@@ -35,10 +36,7 @@ const WORDS = /** @type {Record<string, (d: Dropped) => string>} */ ({
|
|
|
35
36
|
'decimal-not-on-page': () => 'the page shows no amount written with a comma before the decimals, so it is not checked.',
|
|
36
37
|
// borrowed-from: bareloop src/pagedropwords.js@c550dc8 (the phrase dry read's sentence)
|
|
37
38
|
'phrase-no-result': (d) => `"${d.other}" is on the page but in none of its results, so it is not checked.`,
|
|
38
|
-
'person-left': () =>
|
|
39
|
-
// M10 am16 (items 4, 5): a shape guardrail with no check picked is Not checked, and you judge it at the Ask
|
|
40
|
-
'no-pick': () => 'No check was picked for it, so you judge it at the Ask.',
|
|
41
|
-
'own-words': () => 'Your own words are on the line; the machine has no check for them, so you judge it at the Ask.',
|
|
39
|
+
'person-left': () => REASON.left,
|
|
42
40
|
// M10 piece 5 (item 7, am8 item 1): the signed Not-checked reasons for a job word that is not a column. `fact` = the job's word.
|
|
43
41
|
'no-column': (d) => `there is no column '${d.fact}'`,
|
|
44
42
|
'no-fit': (d) => `no column fits '${d.fact}'`,
|
|
@@ -53,17 +51,11 @@ const WORDS = /** @type {Record<string, (d: Dropped) => string>} */ ({
|
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* M10 am2 item 3: the plan card row for a `~` rule the person chose to leave Not checked ("drop it"), word for word:
|
|
56
|
-
* `not checked · "<rule>" — You chose to leave it Not checked.` (the rule as the person wrote it; the sentence is the one table's).
|
|
54
|
+
* `not checked · "<rule>" — You chose to leave it Not checked.` (the rule as the person wrote it; the sentence is REASON.left, the one table's: src/checkblock.js).
|
|
57
55
|
* @param {string} rule @returns {string}
|
|
58
56
|
*/
|
|
59
57
|
export const leftRuleLine = (rule) => `not checked · "${rule}" — ${WORDS['person-left'](/** @type {Dropped} */ ({}))}`;
|
|
60
58
|
|
|
61
|
-
/**
|
|
62
|
-
* M10 am16 (item 5): the plan card row for a shape guardrail that has no picked check, in the same form as {@link leftRuleLine}: `not checked · "<rule>" — <reason>`.
|
|
63
|
-
* @param {string} rule @param {'no-pick'|'own-words'} reason @returns {string}
|
|
64
|
-
*/
|
|
65
|
-
export const pickNoteLine = (rule, reason) => `not checked · "${rule}" — ${WORDS[reason](/** @type {Dropped} */ ({}))}`;
|
|
66
|
-
|
|
67
59
|
/** @param {Dropped} d @returns {string} the plain sentence for one drop */
|
|
68
60
|
export function dropSentence(d) {
|
|
69
61
|
const f = WORDS[d.reason];
|
package/src/pagedry.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import { checkCited, factsOfLook } from './citedcheck.js';
|
|
9
9
|
import { linesOf, numberAtEnd } from './pagerules.js';
|
|
10
|
+
import { asList } from './pagebits.js';
|
|
11
|
+
import { redactSecrets } from './redact.js';
|
|
10
12
|
|
|
11
13
|
/** @typedef {import('./pagerules.js').KeptFact} KeptFact @typedef {import('./pagerules.js').Dropped} Dropped */
|
|
12
14
|
|
|
@@ -128,7 +130,8 @@ export async function dryReadPhrases(text, facts) {
|
|
|
128
130
|
const reads = {};
|
|
129
131
|
for (const k of facts) {
|
|
130
132
|
if (k.shape !== 'phrase' || quotes.length === 0 || !k.words.length) { kept.push(k); continue; }
|
|
131
|
-
|
|
133
|
+
// M19 am5: a plain phrase fact is read on all its words (any one); a place keeps its one
|
|
134
|
+
const part = { source: SOURCE, facts: factsOfLook({ name: CLAIM, shape: 'phrase', words: Array.isArray(/** @type {any} */ (k).phrases) ? [k.words[0]] : k.words }) };
|
|
132
135
|
let n = 0;
|
|
133
136
|
for (const quote of quotes) {
|
|
134
137
|
const g = await checkCited({ part, text, results: [{ quote, values: {} }] });
|
|
@@ -140,3 +143,74 @@ export async function dryReadPhrases(text, facts) {
|
|
|
140
143
|
}
|
|
141
144
|
return { facts: kept, dropped, reads };
|
|
142
145
|
}
|
|
146
|
+
|
|
147
|
+
// borrowed-from: bareloop src/pagedry.js@v0.60.0 (timeCandidateLines, CLOCK: the loose time finder asSeenOf reads; asSeenOf, AS_SEEN_MAX_LINES, AS_SEEN_MAX_CHARS: F337; hamr 2026-11-19. Not taken: dryReadTimes)
|
|
148
|
+
/** a clock time as the page writes it: H:MM or HH:MM, then an optional AM/PM (any case, a space between allowed) */
|
|
149
|
+
const CLOCK = /\d{1,2}:\d{2}(?:\s?[AaPp][Mm])?/;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The candidate lines of a kept time fact: a LOOSE finder (it only collects). Every page line where a kept label word has a clock time anywhere
|
|
153
|
+
* after it; the value is that line's first time after the label. Whether the run's checker can read it is not decided here.
|
|
154
|
+
* @param {string} text @param {KeptFact} k @returns {{quote: string, value: string}[]}
|
|
155
|
+
*/
|
|
156
|
+
export function timeCandidateLines(text, k) {
|
|
157
|
+
const raw = text.split('\n');
|
|
158
|
+
const squashed = linesOf(text);
|
|
159
|
+
/** @type {{quote: string, value: string}[]} */
|
|
160
|
+
const out = [];
|
|
161
|
+
squashed.forEach((ln, i) => {
|
|
162
|
+
for (const w of k.words) {
|
|
163
|
+
for (let at = ln.indexOf(w); at !== -1; at = ln.indexOf(w, at + w.length)) {
|
|
164
|
+
const m = CLOCK.exec(ln.slice(at + w.length));
|
|
165
|
+
if (m) { out.push({ quote: raw[i].trim(), value: m[0] }); return; }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** the longest "as seen" example kept: more lines or characters than this is not a result's few label lines, so nothing is stored */
|
|
173
|
+
export const AS_SEEN_MAX_LINES = 12;
|
|
174
|
+
export const AS_SEEN_MAX_CHARS = 3000;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* AS SEEN (F337): the planner's example of one result's shape. When a signed fact's label sits on a different line than the result's first line
|
|
178
|
+
* (a hosted flights site: the price line, then `Departure time:` on the next), the worker must copy those lines whole; the planner is the one who can
|
|
179
|
+
* tell it, so the signed record keeps the exact input lines from the drafting copy. Result and label lines are found by the SAME finders the dry
|
|
180
|
+
* reads use (`moneyResultLines`, `timeCandidateLines`), one line at a time, so there is no second reader of "what holds this label". The first
|
|
181
|
+
* result is the first line holding the first labelled fact (money or time); its block runs to the next such line. Every other labelled fact must
|
|
182
|
+
* have its label on the first line or inside the block, else nothing is stored (never a half-example). Lines are the input's own bytes (secret-masked).
|
|
183
|
+
* @param {string} text the drafting copy of the input @param {any[]} facts the signed facts of one part @param {string} input the input's label
|
|
184
|
+
* @returns {{input: string, lines: string[], labels: string[]} | null} null when every label is on the first line, or nothing fits
|
|
185
|
+
*/
|
|
186
|
+
export function asSeenOf(text, facts, input) {
|
|
187
|
+
const lab = (Array.isArray(facts) ? facts : []).filter((f) => f && typeof f.anchor === 'string' && f.anchor !== '' && (f.shape === 'money' || f.shape === 'time'));
|
|
188
|
+
if (lab.length === 0) return null;
|
|
189
|
+
const raw = text.split('\n');
|
|
190
|
+
/** @type {(line: string, f: any) => boolean} */
|
|
191
|
+
const holds = (line, f) => {
|
|
192
|
+
/** @type {KeptFact} */
|
|
193
|
+
const k = { line: 0, name: String(f.name ?? ''), shape: f.shape, from: '', words: [f.anchor], ...(f.shape === 'money' ? { unit: asList(f.unit), currency: asList(f.currency), ...(f.decimal === undefined ? {} : { decimal: f.decimal }) } : {}) };
|
|
194
|
+
return (f.shape === 'money' ? moneyResultLines(line, k) : timeCandidateLines(line, k)).length > 0;
|
|
195
|
+
};
|
|
196
|
+
const starts = [];
|
|
197
|
+
for (let i = 0; i < raw.length && starts.length < 2; i++) if (holds(raw[i], lab[0])) starts.push(i);
|
|
198
|
+
if (starts.length === 0) return null;
|
|
199
|
+
const s = starts[0];
|
|
200
|
+
const end = starts[1] ?? raw.length;
|
|
201
|
+
/** @type {string[]} */
|
|
202
|
+
const labels = [];
|
|
203
|
+
let last = s;
|
|
204
|
+
for (const f of lab.slice(1)) {
|
|
205
|
+
if (holds(raw[s], f)) continue;
|
|
206
|
+
let at = -1;
|
|
207
|
+
for (let i = s + 1; i < end; i++) if (holds(raw[i], f)) { at = i; break; }
|
|
208
|
+
if (at < 0) return null;
|
|
209
|
+
labels.push(f.anchor);
|
|
210
|
+
last = Math.max(last, at);
|
|
211
|
+
}
|
|
212
|
+
if (labels.length === 0) return null;
|
|
213
|
+
const lines = raw.slice(s, last + 1);
|
|
214
|
+
if (lines.length > AS_SEEN_MAX_LINES || lines.join('\n').length > AS_SEEN_MAX_CHARS) return null;
|
|
215
|
+
return { input, lines: lines.map((l) => redactSecrets(l)), labels };
|
|
216
|
+
}
|
package/src/pagefetch.js
CHANGED
|
@@ -87,11 +87,11 @@ export function pageContentChars(text) {
|
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* @typedef {{goto: (url: string, timeout?: number) => Promise<{url: string, status: number}>, waitForNetworkIdle: (o?: {idle?: number, timeout?: number}) => Promise<void>,
|
|
90
|
-
* snapshot: (o?: {mode?: string}) => Promise<string>, close: () => Promise<void
|
|
90
|
+
* snapshot: (o?: {mode?: string}) => Promise<string>, close: () => Promise<void>, botBlocked?: boolean}} FetchPage the part of barebrowse's page handle the fetch uses
|
|
91
91
|
*/
|
|
92
92
|
|
|
93
|
-
/** the oldest barebrowse we accept: 0.21.0 honours CONNECT_OPTIONS (incognito, blockPrivateNetwork; an older one would drop both guards without a word); 0.24.1 tethers Chromium to its launcher, so a killed run or an Abandoned draft leaves no browser behind; 0.26.0 makes goto() resolve to {url, status}, the HTTP status an error page is refused on (M10 am13) */
|
|
94
|
-
export const MIN_BAREBROWSE = [0,
|
|
93
|
+
/** the oldest barebrowse we accept: 0.21.0 honours CONNECT_OPTIONS (incognito, blockPrivateNetwork; an older one would drop both guards without a word); 0.24.1 tethers Chromium to its launcher, so a killed run or an Abandoned draft leaves no browser behind; 0.26.0 makes goto() resolve to {url, status}, the HTTP status an error page is refused on (M10 am13); 0.30.0 sets page.botBlocked, the flag a bot challenge is refused on (F222) */
|
|
94
|
+
export const MIN_BAREBROWSE = [0, 30, 0];
|
|
95
95
|
|
|
96
96
|
/** @param {string} v @returns {boolean} true when `v` (x.y.z) is at least MIN_BAREBROWSE */
|
|
97
97
|
export function barebrowseNewEnough(v) {
|
|
@@ -108,7 +108,7 @@ async function loadConnect() {
|
|
|
108
108
|
try {
|
|
109
109
|
const mod = /** @type {any} */ (await import('barebrowse'));
|
|
110
110
|
const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.resolve('barebrowse'))), '..', 'package.json'), 'utf8'));
|
|
111
|
-
if (!barebrowseNewEnough(pkg.version)) return { ok: /** @type {const} */ (false), error: `the page reader (barebrowse ${pkg.version}) is too old: a web page needs 0.
|
|
111
|
+
if (!barebrowseNewEnough(pkg.version)) return { ok: /** @type {const} */ (false), error: `the page reader (barebrowse ${pkg.version}) is too old: a web page needs 0.30.0 or newer, which keeps the browser private, off the local network, closed when the run ends, and says whether the page loaded` };
|
|
112
112
|
return { ok: /** @type {const} */ (true), connect: /** @type {(opts: Record<string, any>) => Promise<FetchPage>} */ (mod.connect) };
|
|
113
113
|
} catch (e) { return { ok: /** @type {const} */ (false), error: `the page reader (barebrowse) could not be loaded: ${/** @type {Error} */ (e).message}` }; }
|
|
114
114
|
}
|
|
@@ -137,6 +137,8 @@ export async function fetchPageText(url, { connect, timeoutMs = PAGE_FETCH_TIMEO
|
|
|
137
137
|
let timer;
|
|
138
138
|
/** @type {Promise<FetchPage>|undefined} */
|
|
139
139
|
let opening;
|
|
140
|
+
/** @type {FetchPage|undefined} */
|
|
141
|
+
let shot;
|
|
140
142
|
try {
|
|
141
143
|
opening = open({ ...CONNECT_OPTIONS });
|
|
142
144
|
const page = opening;
|
|
@@ -150,13 +152,16 @@ export async function fetchPageText(url, { connect, timeoutMs = PAGE_FETCH_TIMEO
|
|
|
150
152
|
if (st < 200 || st > 299) return { refused: `${u.href} came back as an error page (HTTP ${st}), so there is nothing to read` };
|
|
151
153
|
// bounded: a page that never goes quiet (polling, streaming) is read as it stands (bareloop); the size and chrome floors below then decide
|
|
152
154
|
try { await p.waitForNetworkIdle({ idle: idleMs, timeout: idleTimeoutMs }); } catch { /* read what is there */ }
|
|
153
|
-
|
|
155
|
+
const t = await p.snapshot({ ...SNAPSHOT_OPTIONS });
|
|
156
|
+
shot = p;
|
|
157
|
+
return t;
|
|
154
158
|
})(),
|
|
155
159
|
new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(`no answer inside ${Math.round(timeoutMs / 1000)} seconds`)), timeoutMs); }),
|
|
156
160
|
]);
|
|
157
161
|
if (text && typeof text === 'object' && 'refused' in text) return { ok: false, error: String(text.refused) };
|
|
158
162
|
if (typeof text !== 'string') return { ok: false, error: `${u.href} did not come back as text` };
|
|
159
|
-
|
|
163
|
+
// F222: barebrowse 0.30.0 sets page.botBlocked exactly when it writes its marker; only a strict true counts
|
|
164
|
+
if (/** @type {FetchPage|undefined} */ (shot)?.botBlocked === true) return { ok: false, error: `${u.href} asked for a human check (a bot challenge), so the page could not be read` };
|
|
160
165
|
const size = text.trim().length;
|
|
161
166
|
if (size < MIN_PAGE_CHARS) return { ok: false, error: `${u.href} came back with ${size === 0 ? 'no text' : `only ${size} characters of text`} (less than ${MIN_PAGE_CHARS}) - the page did not load, or holds nothing to read` };
|
|
162
167
|
if (pageContentChars(text) < MIN_CONTENT_CHARS) return { ok: false, error: `${u.href} came back with only the site's own header and menus - the page did not load its content, so there is nothing to read` };
|
package/src/pagelook.js
CHANGED
|
@@ -85,7 +85,8 @@ export const notCheckedLines = (dropped, jobLines) => dropRows(dropped).map((row
|
|
|
85
85
|
export function lookFactOf(k, source) {
|
|
86
86
|
/** @type {any} */
|
|
87
87
|
const out = { line: k.line, name: k.name, shape: k.shape, source, words: [...k.words] };
|
|
88
|
-
|
|
88
|
+
// M19 am5: a phrase fact with several words keeps ALL of them (`words`; signed by `factsOfLook` as one any-of fact); `phrase` is only the one-word fact's. Diverges from bareloop's lookFactOf, which keeps the first word.
|
|
89
|
+
if (k.shape === 'phrase' && k.words.length <= 1) out.phrase = k.words[0];
|
|
89
90
|
if (Array.isArray(/** @type {any} */ (k).phrases)) out.phrases = [.../** @type {any} */ (k).phrases];
|
|
90
91
|
else { out.labels = [...k.words]; if (k.words.length) out.label = k.words[0]; }
|
|
91
92
|
if (k.unit) out.unit = [...k.unit];
|
package/src/pagerules.js
CHANGED
|
@@ -12,7 +12,7 @@ import { countExact, countPhrase, squash, normLabel } from './pagebits.js';
|
|
|
12
12
|
/**
|
|
13
13
|
* @typedef {{op: string, value?: string|number, lo?: string|number, hi?: string|number}} Reading what a `~` rule means as a limit (PRD v1.107 Part 5b): the same shape as a signed fact rule
|
|
14
14
|
* @typedef {{name: string, from?: string, shape: string, words?: string[], currency?: string[], unit?: string[], reading?: Reading}} MapFact the AI's map, one fact
|
|
15
|
-
* @typedef {{facts: MapFact[]}} PageMap
|
|
15
|
+
* @typedef {{facts: MapFact[], cannot?: {from?: string, why?: string}[]}} PageMap
|
|
16
16
|
* @typedef {{line: number, name: string, shape: string, from: string, words: string[], unit?: string[], currency?: string[], forRule?: number, reading?: Reading}} KeptFact
|
|
17
17
|
* `words` = what the page proves: the labels of a money/number/time fact, or the alternative phrases of a phrase fact (a place is a phrase)
|
|
18
18
|
* @typedef {{line: number, rule?: number, fact: string, word?: string, reason: string, other?: string}} Dropped `other` = what the drop is compared to: the first label (R1), the primary form (R1L), the fact it would have repeated (S1)
|
|
@@ -185,8 +185,14 @@ export function applyPageRules(text, mapping, jobLines) {
|
|
|
185
185
|
/** @type {Dropped[]} */
|
|
186
186
|
const dropped = [];
|
|
187
187
|
const all = Array.isArray(mapping?.facts) ? mapping.facts.filter(isRec) : [];
|
|
188
|
+
// borrowed-from: bareloop src/pagerules.js@v0.61.0 (fc56e1f3) (the contested set and tieOfFact, copied unchanged)
|
|
189
|
+
const contested = new Set((Array.isArray(mapping?.cannot) ? mapping.cannot : []).filter(isRec).map((c) => tieOf(c.from, jobLines)).filter((t) => t.rule !== undefined).map((t) => `${t.line}:${t.rule}`));
|
|
190
|
+
const tieOfFact = (/** @type {MapFact} */ f) => {
|
|
191
|
+
const t = tieOf(f.from, jobLines);
|
|
192
|
+
return t.rule !== undefined && contested.has(`${t.line}:${t.rule}`) ? { line: t.line } : t;
|
|
193
|
+
};
|
|
188
194
|
/** @type {Map<MapFact, {line: number, rule?: number}>} */
|
|
189
|
-
const ties = new Map(all.map((f) => [f,
|
|
195
|
+
const ties = new Map(all.map((f) => [f, tieOfFact(f)]));
|
|
190
196
|
const drop = (/** @type {MapFact} */ f, /** @type {string|undefined} */ word, /** @type {string} */ reason, /** @type {string|undefined} */ other = undefined) => {
|
|
191
197
|
const t = /** @type {{line: number, rule?: number}} */ (ties.get(f));
|
|
192
198
|
dropped.push({ line: t.line, ...(t.rule === undefined ? {} : { rule: t.rule }), fact: String(f.name ?? ''), ...(word === undefined ? {} : { word }), reason, ...(other === undefined ? {} : { other }) });
|
package/src/panel/author.js
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
// One at a time with no lock table: `start` is fully synchronous (check live -> create the folder -> spawn ->
|
|
28
28
|
// write pid.json, no await between), so two requests that arrive together run one after the other and the second
|
|
29
29
|
// sees the first's live child and is refused. A dead child never blocks (its pid is read, never assumed).
|
|
30
|
+
import { ncRowsOf } from '../checklook.js';
|
|
31
|
+
import { planCard } from '../checkrows.js';
|
|
30
32
|
import { randomBytes } from 'node:crypto';
|
|
31
33
|
import {
|
|
32
34
|
mkdirSync, realpathSync, rmSync, writeFileSync,
|
|
@@ -78,6 +80,8 @@ import {
|
|
|
78
80
|
|
|
79
81
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
80
82
|
const BIN = join(HERE, '..', '..', 'bin', 'fwdloop');
|
|
83
|
+
/** M19 am14b: the prefix of the one log line `bin/fwdloop`'s `refuseDraft` writes (JSON `{box, words}`). */
|
|
84
|
+
const REFUSAL_RECORD = 'fwdloop: refusal-record ';
|
|
81
85
|
|
|
82
86
|
/** A draft id: `d-` + the start time in base 36 (so ids sort oldest to newest) + 4 random hex. */
|
|
83
87
|
const ID_RE = /^d-[0-9a-z]{10}-[0-9a-f]{4}$/;
|
|
@@ -175,13 +179,29 @@ export function createAuthor(opts) {
|
|
|
175
179
|
if (first) return { ...base, ...first };
|
|
176
180
|
// no result yet: the child is the only thing that can still produce one
|
|
177
181
|
if (running) return { ...base, phase: 'drafting' };
|
|
178
|
-
return { ...base, phase: 'stopped', say: logTail(dir, 'child.log', keys) || STOPPED_SAY };
|
|
182
|
+
return { ...base, phase: 'stopped', say: logTail(dir, 'child.log', keys) || STOPPED_SAY, refusal: refusalOf(dir, 'child.log', keys) };
|
|
179
183
|
}
|
|
180
184
|
|
|
181
185
|
/** The tail of a child's log, scrubbed and without its `fwdloop: ` prefix; '' when there is none. */
|
|
182
186
|
function logTail(dir, rel, keys) {
|
|
183
187
|
const logText = readFileInside(dir, rel);
|
|
184
|
-
|
|
188
|
+
// the typed refusal record (`refusalOf` reads it) is machine text, never part of what the person is told
|
|
189
|
+
return logText.ok ? scrub(logText.text, keys).split('\n').filter((l) => !l.startsWith(REFUSAL_RECORD)).join('\n').trim().slice(-LOG_TAIL_CHARS).replace(/^fwdloop: /, '') : '';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* M19 am14b: the typed refusal `{box, words}` the child's `refuseDraft` wrote as its last `fwdloop: refusal-record {...}` log line (scrubbed), or null when the child
|
|
194
|
+
* stopped for any other reason. The box is what the refusing check named; the words are never read to find it. `say` stays the whole tail.
|
|
195
|
+
*/
|
|
196
|
+
function refusalOf(dir, rel, keys) {
|
|
197
|
+
const log = readFileInside(dir, rel);
|
|
198
|
+
if (!log.ok) return null;
|
|
199
|
+
const lines = scrub(log.text, keys).split('\n').filter((l) => l.startsWith(REFUSAL_RECORD));
|
|
200
|
+
if (lines.length === 0) return null;
|
|
201
|
+
try {
|
|
202
|
+
const r = JSON.parse(lines[lines.length - 1].slice(REFUSAL_RECORD.length));
|
|
203
|
+
return { box: typeof r.box === 'string' ? r.box : null, words: String(r.words) };
|
|
204
|
+
} catch { return null; }
|
|
185
205
|
}
|
|
186
206
|
|
|
187
207
|
/**
|
|
@@ -273,16 +293,17 @@ export function createAuthor(opts) {
|
|
|
273
293
|
if (res && res.phase === 'green') return { n, kind, phase: 'green', hash: res.hash, name, lines: scrubbed };
|
|
274
294
|
if (res) return { n, kind, phase: 'red', reds: res.reds, say: kind === 'answers' ? REDRAFT_RED_SAY : REVISE_RED_SAY, name, lines: scrubbed };
|
|
275
295
|
if (running) return { n, kind, phase: 'running', name };
|
|
276
|
-
|
|
296
|
+
const logRel = `${kind === 'answers' ? 'redraft' : 'revise'}-${n}.log`;
|
|
297
|
+
return { n, kind, name, phase: 'stopped', say: logTail(dir, logRel, keys) || STOPPED_SAY, refusal: refusalOf(dir, logRel, keys) };
|
|
277
298
|
});
|
|
278
|
-
const cur = /** @type {{ phase: string, kind: string, say?: string }} */ (newest > 0 ? revises[revises.length - 1] : { phase: first.phase, kind: 'first' });
|
|
299
|
+
const cur = /** @type {{ phase: string, kind: string, say?: string, refusal?: {box: string|null, words: string} | null }} */ (newest > 0 ? revises[revises.length - 1] : { phase: first.phase, kind: 'first' });
|
|
279
300
|
// a first plan that asked questions did not end red, it ended by asking (open or answered): its plan-checks line is never the red one (am15 item 3)
|
|
280
301
|
const firstQs = firstQsRead ?? readQuestions(join(dir, 'draft')); // the first plan's questions, read once per poll
|
|
281
302
|
const asked = firstQs.questions.length > 0;
|
|
282
303
|
const shared = { ...base, card, revises, revisesLeft, stepList: asked ? stepListOf(dir, 'draft', keys, true) : (first.stepList ?? null) };
|
|
283
304
|
const rel = newest > 0 ? `draft-${newest}` : 'draft';
|
|
284
305
|
if (cur.phase === 'running') return { ...shared, phase: cur.kind === 'answers' ? 'redrafting' : 'revising' };
|
|
285
|
-
if (cur.phase === 'stopped') return { ...shared, phase: 'stopped', say: cur.say };
|
|
306
|
+
if (cur.phase === 'stopped') return { ...shared, phase: 'stopped', say: cur.say, refusal: cur.refusal ?? null };
|
|
286
307
|
const res = newest > 0 ? resultOf(dir, rel, keys) : first;
|
|
287
308
|
// the plan's questions: any open one makes the phase `questions-open`, whatever colour the plan is (the answers are what it was waiting for)
|
|
288
309
|
const q = rel === 'draft' ? firstQs : readQuestions(join(dir, rel));
|
|
@@ -356,15 +377,19 @@ export function createAuthor(opts) {
|
|
|
356
377
|
const ncFile = readJson(dir, `${rel}/${NOT_CHECKED_FILE}`);
|
|
357
378
|
const view = notCheckedView(ncFile?.notChecked, decl);
|
|
358
379
|
// M16 item 5: the plan card's list - the rows with their tags and Drop, the suggestions with Add - read from the card the draft saved (src/cardlist.js); a plan without a list has none
|
|
359
|
-
|
|
360
|
-
const
|
|
380
|
+
// M19 am6: a saved draft with a signed list draws its card rows read from the plan (a card saved with the old words is rebuilt); the suggestions, the restorable rows and the Drop flags are the saved card's
|
|
381
|
+
const savedLog = cardLinesOf(decl).size > 0 ? readJson(dir, `${rel}/log.json`) : undefined;
|
|
382
|
+
const card = savedLog?.checkCard && parsed?.ok === true && Array.isArray(savedLog.checkCard.rows)
|
|
383
|
+
? planCard(savedLog.checkCard, { declaration: decl, lines: parsed.lines, csvRoles: csvRolesOf(parsed.arbiter), kept: Array.isArray(kept) ? kept.filter((/** @type {any} */ k) => k && Number.isInteger(k.line)) : [], log: savedLog.log })
|
|
384
|
+
: savedLog?.checkCard;
|
|
385
|
+
const list = card && Array.isArray(card.rows) && Array.isArray(card.suggested) ? { lines: [...cardLinesOf(decl)].sort((a, b) => a - b), rows: card.rows, notChecked: Array.isArray(card.notChecked) ? card.notChecked : [], suggested: card.suggested, restorable: Array.isArray(card.restorable) ? card.restorable : [] } : null;
|
|
361
386
|
// M16 P4c (bareloop's plan view): the job's lines with their `~` rules (the signed text's own, split at its "; " joins) and the two checks every step has; a plan with a list draws them
|
|
362
387
|
const planLines = parsed?.ok === true ? parsed.lines.map((/** @type {any} */ l) => ({ n: l.n, text: l.text, rules: l.guardrail ? l.guardrail.split('; ') : [] })) : [];
|
|
363
388
|
// M13 am11: the job's action (its last line, when the AI named it or the person agreed or typed it), drawn as `› line <n> writes everything before it [agent]` (no Drop, am11c)
|
|
364
389
|
const act = readJson(dir, `${rel}/log.json`)?.action;
|
|
365
390
|
const action = isObj(act) && Number.isInteger(act.line) && act.dropped !== true ? { line: act.line, ...(act.by === 'agent' || act.by === 'you' ? { by: act.by } : {}) } : null;
|
|
366
391
|
return {
|
|
367
|
-
...(action ? { action } : {}), checked: checkedLines(decl, opts), notChecked: { ...view, ...(isObj(ncFile?.by) ? { by: ncFile.by } : {}) }, ...(list ? { list, planLines, always: [...EVERY_STEP_TEXTS] } : {}),
|
|
392
|
+
...(action ? { action } : {}), checked: checkedLines(decl, opts), notChecked: { ...view, ...(isObj(ncFile?.by) ? { by: ncFile.by } : {}), rows: ncRowsOf(view.items, isObj(ncFile?.by) ? ncFile.by : {}) }, ...(list ? { list, planLines, always: [...EVERY_STEP_TEXTS] } : {}),
|
|
368
393
|
};
|
|
369
394
|
}
|
|
370
395
|
|
package/src/panel/data.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
// same things at the route level, but this module refuses on its own too
|
|
20
20
|
// (negative scenario v: nothing outside `--root` is ever read).
|
|
21
21
|
|
|
22
|
+
import { ncRowsOf } from '../checklook.js';
|
|
22
23
|
import {
|
|
23
24
|
existsSync, realpathSync,
|
|
24
25
|
} from 'node:fs';
|
|
@@ -2114,7 +2115,7 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /*
|
|
|
2114
2115
|
const declSteps = Array.isArray(declaration?.steps) ? declaration.steps : [];
|
|
2115
2116
|
const steps = declSteps.map((st, i) => {
|
|
2116
2117
|
const ak = asks.find((x) => x.line === st.fromLine);
|
|
2117
|
-
const listRows = onList.has(st.fromLine) ? listPartRows(declaration, st).map((r) => ({ text: r.text, by: r.by })) : null;
|
|
2118
|
+
const listRows = onList.has(st.fromLine) ? listPartRows(declaration, st, { lines: Array.isArray(jobLines) ? jobLines : [] }).map((r) => ({ text: r.text, by: r.by, kind: 'truth' })) : null;
|
|
2118
2119
|
return {
|
|
2119
2120
|
step: i + 1,
|
|
2120
2121
|
line: Number.isInteger(st.fromLine) ? st.fromLine : null,
|
|
@@ -2139,7 +2140,7 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /*
|
|
|
2139
2140
|
const recorded = !!nc && Array.isArray(nc.items);
|
|
2140
2141
|
const view = recorded ? notCheckedView(nc.items, declaration) : { items: [], readNotes: [] };
|
|
2141
2142
|
return {
|
|
2142
|
-
steps, notChecked: { label: notCheckedLabelOf(declaration), items: view.items, readNotes: view.readNotes, recorded, ...(onList.size > 0 && nc?.by && typeof nc.by === 'object' ? { by: nc.by } : {}) },
|
|
2143
|
+
steps, notChecked: { label: notCheckedLabelOf(declaration), items: view.items, readNotes: view.readNotes, recorded, ...(onList.size > 0 && nc?.by && typeof nc.by === 'object' ? { by: nc.by } : {}), ...(onList.size > 0 ? { rows: ncRowsOf(view.items, nc?.by && typeof nc.by === 'object' ? nc.by : {}) } : {}) },
|
|
2143
2144
|
...(onList.size > 0 ? { always: [...EVERY_STEP_TEXTS] } : {}),
|
|
2144
2145
|
};
|
|
2145
2146
|
}
|