fwdloop 0.38.0 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fwdloop +21 -19
- package/package.json +1 -1
- package/src/ask.js +70 -148
- package/src/audit-fold.js +5 -4
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +32 -60
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +3 -2
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +5 -5
- package/src/books.js +217 -12
- package/src/checkblock.js +20 -41
- package/src/checklistsign.js +25 -3
- package/src/checklook.js +3 -1
- package/src/checkpick.js +5 -76
- package/src/cited-source.js +4 -4
- package/src/citedcheck.js +6 -11
- package/src/citedwords.js +9 -8
- package/src/closers.js +9 -6
- package/src/declaration.js +14 -49
- package/src/diary.js +23 -1
- package/src/draft-steps.js +11 -1
- package/src/drafter.js +13 -9
- package/src/draftfiles.js +127 -0
- package/src/draftspend.js +165 -17
- package/src/flow.js +42 -87
- package/src/flowmodel.js +1 -1
- package/src/index.js +3 -2
- package/src/inside.js +86 -0
- package/src/jsonl-append.js +33 -1
- package/src/learn.js +1 -1
- package/src/learnstore.js +20 -22
- package/src/line-checks.js +1 -1
- package/src/liveness.js +3 -0
- package/src/mcp-use.js +8 -9
- package/src/memo.js +13 -16
- package/src/model-step.js +2 -2
- package/src/page-words.js +8 -0
- package/src/pageask.js +8 -3
- package/src/pagebits.js +8 -1
- package/src/pagedropwords.js +1 -1
- package/src/pagerules.js +6 -3
- package/src/panel/author.js +99 -75
- package/src/panel/authorcard.js +21 -8
- package/src/panel/authorflows.js +3 -3
- package/src/panel/authorresume.js +3 -3
- package/src/panel/authorstart.js +15 -16
- package/src/panel/authortrigger.js +43 -70
- package/src/panel/data.js +125 -168
- package/src/panel/index.html +122 -61
- package/src/panel/jobgrid.js +3 -7
- package/src/panel/result.js +7 -10
- package/src/panel/resume.js +4 -3
- package/src/panel/scheduler.js +9 -9
- package/src/panel/server.js +8 -4
- package/src/panel/spawn.js +22 -11
- package/src/panel/tickets.js +2 -2
- package/src/pickrecord.js +51 -31
- package/src/placerule.js +3 -4
- package/src/planrebuild.js +19 -19
- package/src/primitives.js +1 -1
- package/src/provider.js +1 -1
- package/src/reasons.js +25 -0
- package/src/runfile.js +26 -2
- package/src/runner.js +57 -105
- package/src/runvalues.js +47 -24
- package/src/schedule-choices.js +41 -0
- package/src/schedule-shape.js +39 -0
- package/src/schedule.js +9 -8
- package/src/setup.js +20 -36
- package/src/shaperows.js +2 -2
- package/src/sheetblock.js +2 -2
- package/src/sheetbuild.js +5 -5
- package/src/sheetrun.js +4 -5
- package/src/summary-words.js +2 -1
- package/src/thinking.js +5 -2
- package/src/ticketrows.js +7 -28
- package/src/trigger-clock.js +9 -23
- package/src/trigger-files.js +30 -22
- package/src/trigger-tickets.js +15 -14
- package/src/try-checks.js +2 -1
- package/src/types.js +2 -0
- package/types/ask.d.ts +25 -20
- package/types/authoring.d.ts +7 -42
- package/types/blockpick.d.ts +1 -1
- package/types/books.d.ts +256 -4
- package/types/checkblock.d.ts +1 -23
- package/types/checklist.d.ts +3 -3
- package/types/checklistsign.d.ts +7 -0
- package/types/checkpick.d.ts +0 -21
- package/types/citedwords.d.ts +7 -4
- package/types/closers.d.ts +1 -0
- package/types/declaration.d.ts +4 -14
- package/types/diary.d.ts +14 -1
- package/types/draft-steps.d.ts +7 -0
- package/types/drafter.d.ts +1 -1
- package/types/draftfiles.d.ts +89 -0
- package/types/draftspend.d.ts +74 -0
- package/types/flow.d.ts +32 -54
- package/types/index.d.ts +3 -3
- package/types/inside.d.ts +58 -0
- package/types/jsonl-append.d.ts +20 -0
- package/types/learnstore.d.ts +0 -2
- package/types/liveness.d.ts +1 -0
- package/types/page-words.d.ts +6 -0
- package/types/pageask.d.ts +2 -0
- package/types/pagebits.d.ts +3 -0
- package/types/pagerules.d.ts +1 -0
- package/types/panel/author.d.ts +7 -3
- package/types/panel/authorcard.d.ts +0 -6
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/authortrigger.d.ts +16 -2
- package/types/panel/data.d.ts +36 -11
- package/types/panel/spawn.d.ts +18 -2
- package/types/pickrecord.d.ts +29 -0
- package/types/reasons.d.ts +23 -0
- package/types/runfile.d.ts +14 -0
- package/types/runner.d.ts +6 -38
- package/types/runvalues.d.ts +17 -2
- package/types/schedule-choices.d.ts +9 -0
- package/types/schedule-shape.d.ts +15 -0
- package/types/sheetbuild.d.ts +1 -1
- package/types/thinking.d.ts +1 -0
- package/types/ticketrows.d.ts +0 -9
- package/types/trigger-clock.d.ts +3 -2
- package/types/trigger-files.d.ts +15 -4
- package/types/types.d.ts +8 -0
package/src/panel/server.js
CHANGED
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
|
|
49
49
|
import { createServer } from 'node:http';
|
|
50
50
|
import { readFileSync, realpathSync } from 'node:fs';
|
|
51
|
+
import { scheduleChoices } from '../schedule-choices.js';
|
|
52
|
+
import { pageWords } from '../page-words.js';
|
|
51
53
|
import { pageRules } from '../plain-checks.js';
|
|
52
54
|
import { readOwnVersion } from '../version.js';
|
|
53
55
|
import path, { dirname, join } from 'node:path';
|
|
@@ -60,7 +62,7 @@ import { resolveRunDir } from '../flow.js';
|
|
|
60
62
|
import { readAsk, requestStop, stopParkedRun } from '../runner.js';
|
|
61
63
|
import { removeFromNeedsYou } from './needsyou.js';
|
|
62
64
|
import {
|
|
63
|
-
listRuns, listScheduled, summarizeJobs, RUNS_LIST_LIMITS, getRunDetail, getRunControls, getRunAudit, getRunJob, listStops, inboxOpenCount, getRunAsks, getRunResult, getJobGrid, getTicketList, getRunDownload,
|
|
65
|
+
listRuns, listScheduled, summarizeJobs, RUNS_LIST_LIMITS, getRunDetail, getRunControls, getRunAudit, getRunJob, listStops, inboxOpenCount, getRunAsks, getRunResult, getJobGrid, getTicketList, getRunDownload, savedAnswerOf, hasConsumedAnswer, resolveFlowDir,
|
|
64
66
|
} from './data.js';
|
|
65
67
|
import { ticketAnyway, arriveAnywayOf } from './tickets.js';
|
|
66
68
|
import { createResumer } from './resume.js';
|
|
@@ -157,7 +159,7 @@ function resolveRun(res, root, flow, runId) {
|
|
|
157
159
|
* for it and none was consumed? Then a resume child still alive for the run is only closing.
|
|
158
160
|
* @param {string} runDir @param {string} askId */
|
|
159
161
|
function parkedOnYou(runDir, askId) {
|
|
160
|
-
return readAsk(runDir)?.askId === askId &&
|
|
162
|
+
return readAsk(runDir)?.askId === askId && savedAnswerOf(runDir) === null && !hasConsumedAnswer(runDir, askId);
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
/**
|
|
@@ -243,7 +245,7 @@ function removeLockRoute(res, body, root, resumer) {
|
|
|
243
245
|
const { flow, runId } = b;
|
|
244
246
|
const runDir = resolveRun(res, root, flow, runId);
|
|
245
247
|
if (runDir === null) return;
|
|
246
|
-
const saved =
|
|
248
|
+
const saved = savedAnswerOf(runDir);
|
|
247
249
|
if (!saved) {
|
|
248
250
|
refuse(res, 409, 'no-saved-answer', 'this run has no saved, unconsumed answer — a resume would have nothing to apply');
|
|
249
251
|
return;
|
|
@@ -328,7 +330,7 @@ function resumeRoute(res, body, root, resumer) {
|
|
|
328
330
|
const { flow, runId } = b;
|
|
329
331
|
const runDir = resolveRun(res, root, flow, runId);
|
|
330
332
|
if (runDir === null) return;
|
|
331
|
-
const saved =
|
|
333
|
+
const saved = savedAnswerOf(runDir);
|
|
332
334
|
if (!saved) {
|
|
333
335
|
refuse(res, 409, 'no-saved-answer', 'this run has no saved, unconsumed answer — a resume would have nothing to apply');
|
|
334
336
|
return;
|
|
@@ -532,6 +534,8 @@ export function handleRequest(req, res, opts) {
|
|
|
532
534
|
const version = opts.version !== undefined ? opts.version : readOwnVersion(opts.packagePath); // M4d am17: the header's number from fwdloop's own package.json; M4b am5 item 5: the one read at panel start (opts.version), not at serve time
|
|
533
535
|
html = version === null ? html.replace(/v__FWDLOOP_VERSION__/g, 'version unknown').replace(/__FWDLOOP_VERSION__/g, '') : html.replace(/__FWDLOOP_VERSION__/g, version);
|
|
534
536
|
html = html.replace(/__FWDLOOP_PLAN_CHECK_RULES__/g, () => JSON.stringify(pageRules())); // M4d am15: the one copy of the plain words
|
|
537
|
+
html = html.replace(/__FWDLOOP_SCHEDULE_CHOICES__/g, () => JSON.stringify(scheduleChoices())); // M20 am5 item 1: the one list of schedule choices per flow type
|
|
538
|
+
html = html.replace(/__FWDLOOP_PAGE_WORDS__/g, () => JSON.stringify(pageWords())); // M20 am8a item 1: the origin tags, the decisions that need a reason and the draft phases, from their owners
|
|
535
539
|
if (method === 'HEAD') {
|
|
536
540
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'content-length': Buffer.byteLength(html) });
|
|
537
541
|
res.end();
|
package/src/panel/spawn.js
CHANGED
|
@@ -10,7 +10,7 @@ import { spawn } from 'node:child_process';
|
|
|
10
10
|
import { closeSync, openSync, writeFileSync } from 'node:fs';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { readJsonFile } from '../flow.js';
|
|
14
14
|
import { isFwdloopAlive, procStartOf } from '../liveness.js';
|
|
15
15
|
import { keyValues } from '../keysfile.js';
|
|
16
16
|
|
|
@@ -44,11 +44,23 @@ export function writePidFile(dir, child) {
|
|
|
44
44
|
writeFileSync(join(dir, 'pid.json'), `${JSON.stringify({ pid: child.pid, procStart: procStartOf(/** @type {number} */ (child.pid)), startedAt: Date.now() })}\n`, { mode: 0o600 });
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
/**
|
|
48
|
+
* M20 am3 item 8: the ONE owner of "is the draft/start child alive": the child recorded in `<dir>/pid.json` (null when none is
|
|
49
|
+
* recorded) and whether it is ours and running now: true / false, or null when it cannot be told (no /proc). `childRunning` and the
|
|
50
|
+
* draft door's abandon both ask it.
|
|
51
|
+
* @param {string} dir
|
|
52
|
+
* @returns {{pid: number, procStart: string|null, startedAt: unknown, alive: boolean|null}|null}
|
|
53
|
+
*/
|
|
54
|
+
export function childState(dir) {
|
|
55
|
+
const rec = readJsonFile(dir, 'pid.json');
|
|
56
|
+
if (!rec || !Number.isInteger(rec.pid)) return null;
|
|
57
|
+
const child = { pid: rec.pid, procStart: typeof rec.procStart === 'string' ? rec.procStart : null, startedAt: rec.startedAt };
|
|
58
|
+
return { ...child, alive: childAlive(child) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The same question again for a child `childState` returned (the abandon loop asks it after each signal). @param {{pid: number, procStart: string|null}} child @returns {boolean|null} */
|
|
62
|
+
export function childAlive(child) {
|
|
63
|
+
return isFwdloopAlive(child.pid, child.procStart);
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
/**
|
|
@@ -57,11 +69,10 @@ export function readJsonFile(dir, rel) {
|
|
|
57
69
|
* @param {string} dir
|
|
58
70
|
*/
|
|
59
71
|
export function childRunning(dir) {
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return typeof pid.startedAt === 'number' && Date.now() - pid.startedAt <= UNKNOWN_FRESH_MS;
|
|
72
|
+
const child = childState(dir);
|
|
73
|
+
if (!child) return false;
|
|
74
|
+
if (child.alive !== null) return child.alive;
|
|
75
|
+
return typeof child.startedAt === 'number' && Date.now() - child.startedAt <= UNKNOWN_FRESH_MS;
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
/**
|
package/src/panel/tickets.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
|
|
7
7
|
import { readSchedule, ledgerOf } from '../schedule.js';
|
|
8
|
-
import { readSeen } from '../trigger-files.js';
|
|
9
8
|
import { compareNatural } from '../natural.js';
|
|
10
9
|
import { readRunInputs } from '../runfile.js';
|
|
11
10
|
import { recordAnyway } from '../trigger-tickets.js';
|
|
12
11
|
import { isTicketNumber, TICKET_NUMBER_WORDS } from '../ticket-shape.js';
|
|
12
|
+
import { readTriggerLedger } from '../jsonl-append.js';
|
|
13
13
|
|
|
14
14
|
/** the four groups, in the mockup's order: key, label, open at first. The page draws them; it types none of these words. */
|
|
15
15
|
export const TICKET_GROUPS = Object.freeze([
|
|
@@ -41,7 +41,7 @@ export function ticketListOf({ flowDir, runId, runIdsOf, glyphOf, atOf = () => n
|
|
|
41
41
|
const sched = ticketScheduleOf(flowDir, runId, readSched);
|
|
42
42
|
if (!sched) return null;
|
|
43
43
|
const arrivals = new Map();
|
|
44
|
-
for (const r of /** @type {any[]} */ (
|
|
44
|
+
for (const r of /** @type {any[]} */ (readTriggerLedger(ledgerOf(flowDir), sched.sig))) {
|
|
45
45
|
if (r.kind !== 'arrived' || !Number.isInteger(r.number)) continue;
|
|
46
46
|
const a = arrivals.get(r.number) ?? { first: r.at, last: r.at, count: 0, reason: null };
|
|
47
47
|
arrivals.set(r.number, { first: Math.min(a.first, r.at), last: Math.max(a.last, r.at), count: a.count + 1, reason: typeof r.reason === 'string' ? r.reason : a.reason });
|
package/src/pickrecord.js
CHANGED
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
// (`entriesFromAnswers`) and the only reader that decides keep-or-ask (`matchRecord`); the logic is the one F146 / F146b proved (poc/m10-am17/keep-picks-am18.mjs).
|
|
5
5
|
// Throws away: line and rule numbers (recomputed), the model's words (it never sees a pick), a pick whose line or guardrail words no longer match.
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
import { readFileInside } from './
|
|
7
|
+
import { readFileInside } from './inside.js';
|
|
8
|
+
import { readJsonFile } from './flow.js';
|
|
9
|
+
|
|
10
|
+
/** M20 am8: the one list of a person's row choices on the plan card, and the one question "is this a legal Drop or Add choice" (the row-edit door, the record's reader and the check block ask it) */
|
|
11
|
+
export const ROW_CHOICES = Object.freeze(['drop', 'add']);
|
|
12
|
+
/** @param {unknown} choice @returns {boolean} */
|
|
13
|
+
export const isRowChoice = (choice) => ROW_CHOICES.includes(/** @type {string} */ (choice));
|
|
8
14
|
|
|
9
15
|
/** the record's file, inside a drafting folder only (never a run folder) */
|
|
10
16
|
export const RECORD_FILE = 'picks-record.json';
|
|
@@ -96,12 +102,8 @@ export function matchRecord(entries, lines, rules) {
|
|
|
96
102
|
* @param {string} file @returns {Entry[]|null}
|
|
97
103
|
*/
|
|
98
104
|
export function readRecordFile(file) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!g.ok) return null;
|
|
102
|
-
const j = JSON.parse(g.text);
|
|
103
|
-
return Array.isArray(j?.picks) ? j.picks.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.ruleText === 'string') : null;
|
|
104
|
-
} catch { return null; }
|
|
105
|
+
const j = readJsonFile(path.dirname(file), path.basename(file));
|
|
106
|
+
return Array.isArray(j?.picks) ? j.picks.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.ruleText === 'string') : null;
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
// borrowed-from: bareloop src/pickrecord.js@v0.56.0 (3383cce) (readRowChoices; read through readFileInside; writeRecordPart not taken, see the M16 p1 report)
|
|
@@ -110,12 +112,8 @@ export function readRecordFile(file) {
|
|
|
110
112
|
* @param {string} file @returns {{lineWords: string, occurrence: number, tail: string, choice: string}[]|null}
|
|
111
113
|
*/
|
|
112
114
|
export function readRowChoices(file) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (!g.ok) return null;
|
|
116
|
-
const j = JSON.parse(g.text);
|
|
117
|
-
return Array.isArray(j?.rowChoices) ? j.rowChoices.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.tail === 'string' && (e.choice === 'drop' || e.choice === 'add')) : null;
|
|
118
|
-
} catch { return null; }
|
|
115
|
+
const j = readJsonFile(path.dirname(file), path.basename(file));
|
|
116
|
+
return Array.isArray(j?.rowChoices) ? j.rowChoices.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.tail === 'string' && isRowChoice(e.choice)) : null;
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
// borrowed-from: bareloop src/pickrecord.js@v0.61.0 (fc56e1f3) (readShapeDropped; read through readFileInside like readSheetDropped; writeRecordPart not taken: fwd's writers are src/authoring.js and src/planrebuild.js)
|
|
@@ -124,12 +122,8 @@ export function readRowChoices(file) {
|
|
|
124
122
|
* @param {string} file @returns {{lineWords: string, occurrence: number, name?: string, rule?: number}[]|null}
|
|
125
123
|
*/
|
|
126
124
|
export function readShapeDropped(file) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (!g.ok) return null;
|
|
130
|
-
const j = JSON.parse(g.text);
|
|
131
|
-
return Array.isArray(j?.shapeDropped) ? j.shapeDropped.filter((/** @type {any} */ d) => d && typeof d.lineWords === 'string' && Number.isInteger(d.occurrence) && (typeof d.name === 'string' || Number.isInteger(d.rule))) : null;
|
|
132
|
-
} catch { return null; }
|
|
125
|
+
const j = readJsonFile(path.dirname(file), path.basename(file));
|
|
126
|
+
return Array.isArray(j?.shapeDropped) ? j.shapeDropped.filter((/** @type {any} */ d) => d && typeof d.lineWords === 'string' && Number.isInteger(d.occurrence) && (typeof d.name === 'string' || Number.isInteger(d.rule))) : null;
|
|
133
127
|
}
|
|
134
128
|
|
|
135
129
|
/**
|
|
@@ -138,12 +132,8 @@ export function readShapeDropped(file) {
|
|
|
138
132
|
* @param {string} file @returns {{key: string, line: number, index: number, check: Record<string, any>, text: string}[]|null}
|
|
139
133
|
*/
|
|
140
134
|
export function readSheetDropped(file) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (!g.ok) return null;
|
|
144
|
-
const j = JSON.parse(g.text);
|
|
145
|
-
return Array.isArray(j?.sheetDropped) ? j.sheetDropped.filter((/** @type {any} */ d) => d && typeof d.key === 'string' && Number.isInteger(d.line) && d.check && typeof d.check === 'object' && !Array.isArray(d.check)) : null;
|
|
146
|
-
} catch { return null; }
|
|
135
|
+
const j = readJsonFile(path.dirname(file), path.basename(file));
|
|
136
|
+
return Array.isArray(j?.sheetDropped) ? j.sheetDropped.filter((/** @type {any} */ d) => d && typeof d.key === 'string' && Number.isInteger(d.line) && d.check && typeof d.check === 'object' && !Array.isArray(d.check)) : null;
|
|
147
137
|
}
|
|
148
138
|
|
|
149
139
|
/**
|
|
@@ -152,12 +142,8 @@ export function readSheetDropped(file) {
|
|
|
152
142
|
* @param {string} file @returns {{lineWords: string, occurrence: number, word: string, column: string}[]|null}
|
|
153
143
|
*/
|
|
154
144
|
export function readColumns(file) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (!g.ok) return null;
|
|
158
|
-
const j = JSON.parse(g.text);
|
|
159
|
-
return Array.isArray(j?.columns) ? j.columns.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.word === 'string' && typeof e.column === 'string') : null;
|
|
160
|
-
} catch { return null; }
|
|
145
|
+
const j = readJsonFile(path.dirname(file), path.basename(file));
|
|
146
|
+
return Array.isArray(j?.columns) ? j.columns.filter((/** @type {any} */ e) => e && typeof e.lineWords === 'string' && Number.isInteger(e.occurrence) && typeof e.word === 'string' && typeof e.column === 'string') : null;
|
|
161
147
|
}
|
|
162
148
|
|
|
163
149
|
/** @param {{n: number, text: string}[]} lines @param {{line: number, word: string, column: string}[]} cols @returns {{lineWords: string, occurrence: number, word: string, column: string}[]} the answers as the record keeps them */
|
|
@@ -172,5 +158,39 @@ export function columnsOnLines(entries, lines) {
|
|
|
172
158
|
return entries.flatMap((e) => { const n = byKey.get(`${e.lineWords}#${e.occurrence}`); return n === undefined ? [] : [{ line: n, word: e.word, column: e.column }]; });
|
|
173
159
|
}
|
|
174
160
|
|
|
161
|
+
/**
|
|
162
|
+
* M20 am3e item 19: the record's `kept` list, the ONE reader (the plan card, the setup row and the sign-time card check all ask it). `kept` is the list as written, or null
|
|
163
|
+
* when there is none to read (no file, refused by the gateway, not a JSON object, no list). `torn` tells an unreadable record from an empty one: the file was read and
|
|
164
|
+
* is not JSON. The sign-time card check skips on a torn record; the other two read it as no list.
|
|
165
|
+
* @param {string} dir the folder that holds the plan folder @param {string} [rel] `draft`, `draft-<n>` or `.` (the plan folder itself)
|
|
166
|
+
* @returns {{kept: any[]|null, torn: boolean}}
|
|
167
|
+
*/
|
|
168
|
+
export function readKept(dir, rel = '.') {
|
|
169
|
+
const g = readFileInside(dir, `${rel}/${RECORD_FILE}`);
|
|
170
|
+
if (!g.ok) return { kept: null, torn: false };
|
|
171
|
+
let j;
|
|
172
|
+
try { j = JSON.parse(g.text); } catch { return { kept: null, torn: true }; }
|
|
173
|
+
return { kept: j !== null && typeof j === 'object' && !Array.isArray(j) && Array.isArray(j.kept) ? j.kept : null, torn: false };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* M20 am4: the counts the person switched on with Add, from the plan's `rowChoices` (the entries `readRowChoices` gives, or the block's own `choicesRecord()`): a set of
|
|
178
|
+
* `<line>:min:<n>` / `<line>:max:<n>` strings, one per number of an Added `count.<min>-<max>` row, the line found by its words as the record ties it. The count check
|
|
179
|
+
* (src/citedwords.js `countReds`) reads a number in this set as said: the Add says it.
|
|
180
|
+
* @param {{lineWords: string, occurrence: number, tail: string, choice: string}[]|null|undefined} entries @param {{n: number, text: string}[]} lines @returns {Set<string>}
|
|
181
|
+
*/
|
|
182
|
+
export function addedCountsOf(entries, lines) {
|
|
183
|
+
const out = new Set();
|
|
184
|
+
const keys = lineKeys(lines);
|
|
185
|
+
for (const e of entries ?? []) {
|
|
186
|
+
const m = e.choice === 'add' ? /^count\.(\d*)-(\d*)$/.exec(e.tail) : null;
|
|
187
|
+
const line = m === null ? undefined : [...keys].find(([, k]) => k.lineWords === e.lineWords && k.occurrence === e.occurrence)?.[0];
|
|
188
|
+
if (m === null || line === undefined) continue;
|
|
189
|
+
if (m[1] !== '') out.add(`${line}:min:${m[1]}`);
|
|
190
|
+
if (m[2] !== '') out.add(`${line}:max:${m[2]}`);
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
|
|
175
195
|
/** where a plan folder keeps its record @param {string} planDir */
|
|
176
196
|
export const recordPath = (planDir) => path.join(planDir, RECORD_FILE);
|
package/src/placerule.js
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
// This module is the graduation (a REWRITE, never a copy) of the round-3 POC (F321). Pure except `lastPlaceRead`, which reads earlier runs' spines.
|
|
10
10
|
|
|
11
11
|
import path from 'node:path';
|
|
12
|
-
import { readFileInside, readdirInside } from './
|
|
13
|
-
import {
|
|
12
|
+
import { readFileInside, readdirInside } from './inside.js';
|
|
13
|
+
import { readPlaceRows } from './runfile.js';
|
|
14
14
|
|
|
15
15
|
/** the two rule kinds on the menu: the version in a heading, and the date on the same heading line */
|
|
16
16
|
export const PLACE_KINDS = Object.freeze(['headingBetween', 'headingDateAfter']);
|
|
@@ -390,8 +390,7 @@ export function lastRunPlaceRead({ flowDir, runId }) {
|
|
|
390
390
|
/** @type {Record<string, string>} */
|
|
391
391
|
const out = {};
|
|
392
392
|
for (const r of earlier) {
|
|
393
|
-
const
|
|
394
|
-
const rows = got.ok && Array.isArray(got.rec.placeRules?.rows) ? got.rec.placeRules.rows : [];
|
|
393
|
+
const rows = readPlaceRows(path.join(flowDir, 'runs', r.id)) ?? [];
|
|
395
394
|
for (const row of rows) if (isRec(row) && row.found === true && typeof row.value === 'string' && !Object.hasOwn(out, String(row.key))) out[String(row.key)] = row.value;
|
|
396
395
|
}
|
|
397
396
|
return out;
|
package/src/planrebuild.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
// What this throws away: nothing of the old plan (it is never rewritten, records are write-once).
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { parseSignedText } from './signed-text.js';
|
|
10
|
-
import {
|
|
10
|
+
import { readDraftLog, readJsonFile } from './flow.js';
|
|
11
|
+
import { readFileInside, readdirInside } from './inside.js';
|
|
11
12
|
import { readInputFacts } from './input-facts.js';
|
|
12
13
|
import { blockJobLines } from './blocklines.js';
|
|
13
14
|
import { setUpBlock, ticketLeaveOut, pickEdits, ledgerEdits } from './blockdraft.js';
|
|
@@ -17,7 +18,7 @@ import { ledgerRowsOf } from './checkrows.js';
|
|
|
17
18
|
import { editsOf } from './rowedit.js';
|
|
18
19
|
import { NOTE_KIND } from './noteask.js';
|
|
19
20
|
import { offerRules, rowsFromAnswer, codeScope } from './checkpick.js';
|
|
20
|
-
import { matchRecord, readRowChoices, RECORD_FILE } from './pickrecord.js';
|
|
21
|
+
import { matchRecord, readRowChoices, addedCountsOf, RECORD_FILE } from './pickrecord.js';
|
|
21
22
|
import { listLinesOf, cardLinesOf } from './checklistsign.js';
|
|
22
23
|
import { csvRolesOf } from './sheetblock.js';
|
|
23
24
|
import { withTicketRows } from './ticketrows.js';
|
|
@@ -30,7 +31,8 @@ import { docRolesOf } from './drafter.js';
|
|
|
30
31
|
import { buildShapes } from './shapebuild.js';
|
|
31
32
|
import { parseShapeAnswer, SHAPE_CALL_LABEL } from './shapelook.js';
|
|
32
33
|
import { lineRules } from './pagebits.js';
|
|
33
|
-
import { buildReadout, specHash, PAGES_DIR
|
|
34
|
+
import { buildReadout, specHash, PAGES_DIR } from './authoring.js';
|
|
35
|
+
import { NOT_CHECKED_FILE, SPEC_HASH_FILE, readNotCheckedFile, readPlanTexts } from './draftfiles.js';
|
|
34
36
|
|
|
35
37
|
/** what a person is told when the saved inputs no longer give the saved list: nothing is written */
|
|
36
38
|
export const REBUILD_CHANGED_SAY = 'The inputs of this plan have changed since it was drafted, so its checks cannot be changed here. Draft again from the card. Nothing was changed.';
|
|
@@ -38,7 +40,6 @@ export const REBUILD_CHANGED_SAY = 'The inputs of this plan have changed since i
|
|
|
38
40
|
export const NO_LIST_SAY = 'This plan has no list of checks to change. Nothing was changed.';
|
|
39
41
|
|
|
40
42
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
41
|
-
const readJson = (/** @type {string} */ dir, /** @type {string} */ rel) => { const r = readFileInside(dir, rel); if (!r.ok) return null; try { return JSON.parse(r.text); } catch { return null; } };
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
45
|
* Rebuild the block of a saved plan at $0. `choices` = the Drop/Add choices the plan was made with (its record's `rowChoices`).
|
|
@@ -47,17 +48,15 @@ const readJson = (/** @type {string} */ dir, /** @type {string} */ rel) => { con
|
|
|
47
48
|
*/
|
|
48
49
|
export function rebuildBlock({ planDir, asks }) {
|
|
49
50
|
const no = (/** @type {string} */ say) => ({ ok: /** @type {const} */ (false), say });
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const declaration = readJson(planDir, 'declaration.json');
|
|
53
|
-
if (!prose.ok || !parsed || !parsed.ok || !isRec(declaration)) return no('This plan could not be read. Nothing was changed.');
|
|
51
|
+
const { proseText, parsed, declaration } = readPlanTexts(planDir);
|
|
52
|
+
if (proseText === null || !parsed || !parsed.ok || !isRec(declaration)) return no('This plan could not be read. Nothing was changed.');
|
|
54
53
|
// the lines the block was given; a CSV job's sheet lines (M16 am4) have rows on the list too, but the block never had them
|
|
55
54
|
const lineSet = listLinesOf(declaration);
|
|
56
55
|
if (cardLinesOf(declaration).size === 0) return no(NO_LIST_SAY);
|
|
57
|
-
const log =
|
|
58
|
-
const pageLook =
|
|
56
|
+
const log = readDraftLog(planDir);
|
|
57
|
+
const pageLook = readJsonFile(planDir, 'page-look.json');
|
|
59
58
|
const look = isRec(pageLook?.look) ? { facts: Array.isArray(pageLook.look.facts) ? pageLook.look.facts : [], dropped: Array.isArray(pageLook.look.dropped) ? pageLook.look.dropped : [] } : { facts: [], dropped: [] };
|
|
60
|
-
const record =
|
|
59
|
+
const record = readJsonFile(planDir, RECORD_FILE) ?? {};
|
|
61
60
|
// the frozen copies of the page inputs, then the document inputs as the draft read them (they are not copied into the folder: an input that changed is caught below)
|
|
62
61
|
/** @type {Record<string, {text: string}>} */
|
|
63
62
|
const pages = {};
|
|
@@ -70,10 +69,10 @@ export function rebuildBlock({ planDir, asks }) {
|
|
|
70
69
|
if (!facts.ok) return no(REBUILD_CHANGED_SAY);
|
|
71
70
|
const texts = { ...(facts.docs ?? {}), ...Object.fromEntries(Object.entries(pages).map(([role, pg]) => [role, pg.text])) };
|
|
72
71
|
// the lines the block was given are the lines the saved list has rows on
|
|
73
|
-
const all = blockJobLines(
|
|
72
|
+
const all = blockJobLines(proseText, undefined, []);
|
|
74
73
|
if (!all.ok) return no('This plan could not be read. Nothing was changed.');
|
|
75
74
|
const tied = all.jobLines.filter((l) => !lineSet.has(l.n)).map((l) => l.n);
|
|
76
|
-
const plan = blockJobLines(
|
|
75
|
+
const plan = blockJobLines(proseText, undefined, tied);
|
|
77
76
|
if (!plan.ok) return no('This plan could not be read. Nothing was changed.');
|
|
78
77
|
const blockLineNums = new Set(plan.jobLines.map((l) => l.n));
|
|
79
78
|
const inBlock = (/** @type {{line: number}} */ x) => blockLineNums.has(x.line);
|
|
@@ -129,7 +128,7 @@ export function rebuildBlock({ planDir, asks }) {
|
|
|
129
128
|
if (sheetBuilt !== null) { block.setSheet(sheetBuilt); block.carrySheetDropped(Array.isArray(record.sheetDropped) ? record.sheetDropped : []); }
|
|
130
129
|
if (Array.isArray(record.shapeDropped) && record.shapeDropped.length) block.carryShapeDropped(record.shapeDropped);
|
|
131
130
|
block.reconcile();
|
|
132
|
-
return { ok: true, block, declaration, lines, lineSet, parsed, texts, look, record, log, proseText
|
|
131
|
+
return { ok: true, block, declaration, lines, lineSet, parsed, texts, look, record, log, proseText };
|
|
133
132
|
}
|
|
134
133
|
|
|
135
134
|
/**
|
|
@@ -158,7 +157,7 @@ function assembleAgain(b, from = b.declaration) {
|
|
|
158
157
|
const planFacts = b.look.facts.filter((f) => !b.lineSet.has(f.line) || inPlan.has(`${f.line}:${f.name}`));
|
|
159
158
|
const pageSources = (b.parsed.arbiter.sources ?? []).some((/** @type {any} */ s) => s.kind === 'page');
|
|
160
159
|
const verdict = validateDeclaration(a.declaration, {
|
|
161
|
-
arbiter: b.parsed.arbiter, lines: b.lines, catalogue: cat.primitives, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true,
|
|
160
|
+
arbiter: b.parsed.arbiter, lines: b.lines, catalogue: cat.primitives, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true, addedCounts: addedCountsOf(b.block.choicesRecord(), b.lines),
|
|
162
161
|
pageWords: { texts: b.texts, look: pageSources ? { facts: planFacts, dropped: b.look.dropped } : null, docs: docRolesOf(b.parsed.arbiter.sources) },
|
|
163
162
|
});
|
|
164
163
|
if (!verdict.ok) return { ok: false, say: `The changed list did not pass the plan's checks (${String(verdict.reds[0])}). Nothing was changed.` };
|
|
@@ -196,18 +195,19 @@ export function rowEditPlan({ planDir, op, key, asks = true }) {
|
|
|
196
195
|
const shapeDroppedNow = b.block.shapeDroppedRecord();
|
|
197
196
|
const after = assembleAgain(b);
|
|
198
197
|
if (!after.ok) return { ok: false, say: after.say, refused: 'rebuild' };
|
|
199
|
-
const target =
|
|
198
|
+
const target = readJsonFile(planDir, 'target.json');
|
|
200
199
|
const inputFactsText = readFileInside(planDir, 'input-facts.json');
|
|
201
200
|
const targetText = readFileInside(planDir, 'target.json');
|
|
202
201
|
if (!targetText.ok || !inputFactsText.ok || !isRec(target)) return { ok: false, say: 'This plan could not be read. Nothing was changed.', refused: 'rebuild' };
|
|
203
202
|
const dj = (/** @type {unknown} */ o) => `${JSON.stringify(o, null, 2)}\n`;
|
|
204
203
|
const declarationText = dj(after.declaration);
|
|
205
204
|
// the "Not checked" list: what the old plan listed, less what the old list made, plus what the changed list makes (the AI's own list stays)
|
|
206
|
-
const
|
|
205
|
+
const oldNcFile = readNotCheckedFile(planDir);
|
|
206
|
+
const oldNc = oldNcFile.notChecked;
|
|
207
207
|
const oldList = Array.isArray(oldNc) ? oldNc.filter((x) => typeof x === 'string') : [];
|
|
208
208
|
const was = new Set(before.notChecked);
|
|
209
209
|
const notChecked = [...new Set([...oldList.filter((x) => !was.has(x)), ...after.notChecked])];
|
|
210
|
-
const oldBy =
|
|
210
|
+
const oldBy = oldNcFile.by ?? {};
|
|
211
211
|
const by = { ...Object.fromEntries(Object.entries(oldBy).filter(([t]) => !was.has(t))), ...after.notCheckedBy };
|
|
212
212
|
// M19 am4: the plan card the new plan saves is the one its readout reads (one model)
|
|
213
213
|
// M19 am8 item 1, am9 item 5: the new plan's ledger rows, one per Not checked row, in its own log; the card is read from the new plan (am6)
|
|
@@ -246,7 +246,7 @@ export function rowEditPlan({ planDir, op, key, asks = true }) {
|
|
|
246
246
|
[NOT_CHECKED_FILE]: dj({ notChecked, ...(Object.keys(by).length ? { by } : {}) }),
|
|
247
247
|
[RECORD_FILE]: dj({ ...record, rowChoices: b.block.choicesRecord(), ...(droppedNow.length ? { sheetDropped: droppedNow } : {}), ...(shapeDroppedNow.length ? { shapeDropped: shapeDroppedNow } : {}) }),
|
|
248
248
|
'log.json': dj({ ...(isRec(b.log) ? b.log : {}), log: [...(Array.isArray(b.log?.log) ? b.log.log : []), logRow, ...ledger], checkCard: card }),
|
|
249
|
-
|
|
249
|
+
[SPEC_HASH_FILE]: `${h.hash}\n`,
|
|
250
250
|
},
|
|
251
251
|
};
|
|
252
252
|
}
|
package/src/primitives.js
CHANGED
|
@@ -33,7 +33,7 @@ import { readDocxText } from './docx.js';
|
|
|
33
33
|
import { parseCsv } from './csv.js';
|
|
34
34
|
import { makeCtxTools } from './ctx-tools.js';
|
|
35
35
|
import { diaryPaths } from './diary.js';
|
|
36
|
-
import { readdirInside } from './
|
|
36
|
+
import { readdirInside } from './inside.js';
|
|
37
37
|
|
|
38
38
|
// bare-agent >=0.47.0: `noFollowSymlinks: true` makes shell_read/write/edit/
|
|
39
39
|
// grep throw `err.code === 'ELOOP'` when the path's FINAL component is a
|
package/src/provider.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
mkdirSync,
|
|
20
20
|
} from 'node:fs';
|
|
21
21
|
import { dirname, basename } from 'node:path';
|
|
22
|
-
import { readFileInside } from './
|
|
22
|
+
import { readFileInside } from './inside.js';
|
|
23
23
|
import { appendRow } from './jsonl-append.js';
|
|
24
24
|
import { readConfig, configDoorHome, cleanBaseUrl } from './config.js';
|
|
25
25
|
import { isKeyName } from './keysfile.js';
|
package/src/reasons.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// M20 am3b item 2 (loop map): the plain reasons code gives, moved verbatim out of src/checkblock.js so the words that quote them (src/pagedropwords.js) need not import the block.
|
|
2
|
+
|
|
3
|
+
/** the plain reasons code gives, in one place (the card, the Job tab and the Audit read them from the row) */
|
|
4
|
+
export const REASON = Object.freeze({
|
|
5
|
+
left: 'You chose to leave it Not checked, so you judge it at Accept.',
|
|
6
|
+
nothingOnPage: 'Your own words are on the line; the machine has no check for them, so you judge it at Accept.',
|
|
7
|
+
noRule: 'No rule can check this, so you judge it at Accept.',
|
|
8
|
+
waitingPick: 'waiting for your answer on the proposed check',
|
|
9
|
+
waitingReading: 'waiting for your answer on the reading',
|
|
10
|
+
onePerLine: 'this line finds facts, so it has no text to quote',
|
|
11
|
+
manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
|
|
12
|
+
oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
|
|
13
|
+
countNeedsFact: 'a result count needs a fact to count; this line has none',
|
|
14
|
+
countNeedsSuggested: 'a result count needs a fact to count; add the suggested fact on this line to count its results',
|
|
15
|
+
lookNoWords: "the page does not hold the words of the look's fact for this rule",
|
|
16
|
+
afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
|
|
17
|
+
noPick: 'No check was picked for it, so you judge it at Accept.',
|
|
18
|
+
itemCountByRule: 'your rule on this line sets the item count',
|
|
19
|
+
negated: 'it says what is not needed, so there is nothing to check',
|
|
20
|
+
dropped: 'You dropped it.',
|
|
21
|
+
suggested: 'Suggested: not in your job, so it is not checked unless you add it.',
|
|
22
|
+
sheetLine: 'this line reads a sheet and its rules are checked by the sheet checks, so a row edit about it is not used',
|
|
23
|
+
sheetFacts: 'this line reads a sheet, so it is checked by its sheet checks and not by page facts',
|
|
24
|
+
columnRule: "this rule only names a column; the agent's checks on this line use it",
|
|
25
|
+
});
|
package/src/runfile.js
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
// `writeRunStart` and nothing else; every reader of those three goes through this file's readers (`readRunModel` is in src/flowmodel.js, which owns the provider's
|
|
4
4
|
// key-name check). Kept free of the provider on purpose: the learnings note code reads `inputs` and must reach no provider module.
|
|
5
5
|
import { writeFileSync } from 'node:fs';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
-
import { readFileInside } from './
|
|
6
|
+
import { basename, join } from 'node:path';
|
|
7
|
+
import { readFileInside } from './inside.js';
|
|
8
8
|
|
|
9
9
|
/** the file's name in the run's folder */
|
|
10
10
|
export const RUN_FILE = 'run.json';
|
|
11
|
+
/** the folder inside a run that holds the frozen copy of each input */
|
|
12
|
+
export const INPUTS_DIR = 'inputs';
|
|
13
|
+
/** where the frozen copy named `name` lives, relative to the run folder (a name only; any folder part is dropped) @param {string} name */
|
|
14
|
+
export const frozenRel = (name) => `${INPUTS_DIR}/${basename(name)}`;
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* The record as parsed, or why not. `missing` = no file; `unreadable` = the gateway refused it (a symlink, outside the folder); `invalid` = not a JSON object.
|
|
@@ -23,6 +27,16 @@ export function readRunRecord(runDir) {
|
|
|
23
27
|
} catch (err) { return { ok: false, code: 'invalid', red: `${RUN_FILE} is not valid JSON — ${/** @type {any} */ (err).message}` }; }
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
/**
|
|
31
|
+
* M20 am3 item 12: the ONE test for "this run began as a rerun": the human's words its `run.json` carries (`rerun.decision` is `rerun` and
|
|
32
|
+
* `rerun.words` is a string), or null. The Audit's first step and the carry memo ask it. @param {string|null} runDir @returns {string|null}
|
|
33
|
+
*/
|
|
34
|
+
export function readRerunWords(runDir) {
|
|
35
|
+
const rec = readRunRecord(runDir);
|
|
36
|
+
const rr = rec.ok ? rec.rec.rerun : null;
|
|
37
|
+
return rr && typeof rr === 'object' && rr.decision === 'rerun' && typeof rr.words === 'string' ? rr.words : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
/**
|
|
27
41
|
* M4d am26: the run's OWN record of the box (`thinking` in `<run>/run.json`) and nothing else: `true`/`false`, or `null` when the run has none (a run from before am25).
|
|
28
42
|
* An unreadable record is box off, as `readJobThinking` has always read it. @param {string|null} runDir @returns {boolean|null}
|
|
@@ -46,6 +60,16 @@ export function readRunInputs(runDir) {
|
|
|
46
60
|
return Array.isArray(got.rec.inputs) ? { ok: true, entries: got.rec.inputs } : { ok: false, code: 'invalid', red: `${RUN_FILE}: inputs is not a list` };
|
|
47
61
|
}
|
|
48
62
|
|
|
63
|
+
/**
|
|
64
|
+
* M20 am3e item 16: the place-rule rows the run recorded at its start (`placeRules.rows`), or null when there are none to read (no record, a refused or torn file,
|
|
65
|
+
* no `placeRules` section, rows that are not a list). Each caller maps null to its own none: the carry-forward reads it as no rows, a resume refuses by name.
|
|
66
|
+
* @param {string|null} runDir @returns {any[]|null}
|
|
67
|
+
*/
|
|
68
|
+
export function readPlaceRows(runDir) {
|
|
69
|
+
const got = readRunRecord(runDir);
|
|
70
|
+
return got.ok && Array.isArray(got.rec.placeRules?.rows) ? got.rec.placeRules.rows : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
49
73
|
/**
|
|
50
74
|
* 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
75
|
* 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
|