fwdloop 0.23.0 → 0.24.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 +31 -8
- package/package.json +1 -1
- package/src/ask.js +15 -1
- package/src/attemptdiff.js +118 -0
- package/src/audit-fold.js +2 -0
- package/src/authoring.js +32 -2
- package/src/citedwords.js +36 -2
- package/src/config.js +5 -1
- package/src/drafter.js +6 -2
- package/src/flowmodel.js +56 -1
- package/src/learn.js +952 -0
- package/src/learnstore.js +346 -0
- package/src/model-step.js +2 -0
- package/src/pagedry.js +3 -4
- package/src/pagefetch.js +9 -2
- package/src/pagerules.js +28 -5
- package/src/panel/data.js +61 -13
- package/src/panel/index.html +143 -11
- package/src/redact.js +6 -6
- package/src/runner.js +127 -17
- package/src/thinking.js +11 -0
- package/types/ask.d.ts +7 -2
- package/types/attemptdiff.d.ts +38 -0
- package/types/citedwords.d.ts +14 -0
- package/types/drafter.d.ts +6 -1
- package/types/flowmodel.d.ts +36 -0
- package/types/learn.d.ts +576 -0
- package/types/learnstore.d.ts +168 -0
- package/types/pagerules.d.ts +7 -0
- package/types/panel/data.d.ts +2 -1
- package/types/panel/result.d.ts +1 -1
- package/types/runner.d.ts +11 -2
- package/types/thinking.d.ts +11 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M8 item 5a (loose end): the ONE function that turns a source as written into a place. The run-end notes (`learnAtRunEnd`: a path the panel/CLI gave the run) and
|
|
3
|
+
* the drafter's hints (`hintsForRun`: the step's first input, or at draft time the path as typed in the prose) both pass through it, so the same file cannot be two places. A leading `~` or `~/` is the
|
|
4
|
+
* home folder (`path.resolve` alone would make it `<cwd>/~/...`); then `path.resolve` (lexical, no fs: the F48 guard keeps realpathSync out of this file).
|
|
5
|
+
* A web address stays its host (placeOf). Not copied from bareloop: this is the fwdloop-only part of the place.
|
|
6
|
+
* @param {string} p @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function resolvePlace(p: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* M8 am8: the ONE function that gives a run's place spec: `{job, inputs}` for `placeOf`, from the run's first input AS THE RUN READS IT (`inputsManifest[0].source`,
|
|
11
|
+
* a path the panel or CLI gave the run), never the path written in the signed job. The step's hints (`stepHintsReader`), the run-end tally (`learnAtRunEnd`) and the
|
|
12
|
+
* drafter's hints (src/authoring.js) all build their spec here. No source (a job with no file input) is no place.
|
|
13
|
+
* @param {string} job the workflow name
|
|
14
|
+
* @param {string|null|undefined} source the run's first input as it reads it
|
|
15
|
+
* @returns {{job: string, inputs: {value: string}[]}}
|
|
16
|
+
*/
|
|
17
|
+
export function placeSpecOf(job: string, source: string | null | undefined): {
|
|
18
|
+
job: string;
|
|
19
|
+
inputs: {
|
|
20
|
+
value: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* `<configHome>/learn/ledger.json`. Under a test process (NODE_ENV=test or node --test) the home is the explicit one or
|
|
25
|
+
* FWDLOOP_CONFIG_HOME; with neither it THROWS rather than fall back to the real ~/.config/fwdloop.
|
|
26
|
+
* @param {string} [home] test seam; production never passes it
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
export function ledgerPath(home?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Read the ledger. A missing file is an empty ledger; an unreadable or wrong-shaped one is reported as `problem` (and the
|
|
32
|
+
* writer then refuses to replace it: an append-only record is never silently reset).
|
|
33
|
+
* @param {string} [home]
|
|
34
|
+
* @returns {{ledger: import('./learn.js').Ledger, exists: boolean, problem: string|null}}
|
|
35
|
+
*/
|
|
36
|
+
export function readLedger(home?: string): {
|
|
37
|
+
ledger: import("./learn.js").Ledger;
|
|
38
|
+
exists: boolean;
|
|
39
|
+
problem: string | null;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Write the ledger atomically (temp + rename, mode 600), every string masked through the one secret inventory.
|
|
43
|
+
* @param {import('./learn.js').Ledger} ledger @param {string} [home]
|
|
44
|
+
* @returns {string} the file written
|
|
45
|
+
*/
|
|
46
|
+
export function writeLedger(ledger: import("./learn.js").Ledger, home?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Fold ONE finished run into the ledger on disk: every run's cards COUNT now, rubric jobs too (trust kept on new rows;
|
|
49
|
+
* bareloop v0.47.0). `held` is always 0 (kept in the shape for callers). The run's health line is recorded. Never throws on a bad ledger file: it reports `problem` and writes nothing.
|
|
50
|
+
* @param {{home?: string, runid: string, build: import('./learn.js').CardBuild, workflow: string, place: string|null, specHash: string|null, trust: 'deterministic'|'rubric', at: string, now?: Date}} o
|
|
51
|
+
* @returns {{wrote: boolean, counted: number, held: number, problem: string|null}}
|
|
52
|
+
*/
|
|
53
|
+
export function foldRunIntoLedger({ home, runid, build, workflow, place, specHash, trust, at, now }: {
|
|
54
|
+
home?: string;
|
|
55
|
+
runid: string;
|
|
56
|
+
build: import("./learn.js").CardBuild;
|
|
57
|
+
workflow: string;
|
|
58
|
+
place: string | null;
|
|
59
|
+
specHash: string | null;
|
|
60
|
+
trust: "deterministic" | "rubric";
|
|
61
|
+
at: string;
|
|
62
|
+
now?: Date;
|
|
63
|
+
}): {
|
|
64
|
+
wrote: boolean;
|
|
65
|
+
counted: number;
|
|
66
|
+
held: number;
|
|
67
|
+
problem: string | null;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The human Accept at the review door: release a hold an older version wrote for the run so it counts (new runs write none; only forward, only here).
|
|
71
|
+
* @param {{home?: string, runid: string, now?: Date}} o
|
|
72
|
+
* @returns {{released: number, problem: string|null}}
|
|
73
|
+
*/
|
|
74
|
+
export function releaseRun({ home, runid, now }: {
|
|
75
|
+
home?: string;
|
|
76
|
+
runid: string;
|
|
77
|
+
now?: Date;
|
|
78
|
+
}): {
|
|
79
|
+
released: number;
|
|
80
|
+
problem: string | null;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* M8 am1: the ONE setting, `learningHints` in config.json. Ships OFF (absent = off). OFF still writes the tally ($0); the drafter
|
|
84
|
+
* is simply handed nothing. Copied from bareloop learnstore.js@v0.47.0:96 (borrowed-from header above). Difference: bareloop's
|
|
85
|
+
* `readConfig` returns a problem, fwdloop's THROWS ConfigError on an unreadable / non-JSON / invalid file. The safe reading is kept:
|
|
86
|
+
* a bad or unreadable config reads as OFF (never ON). Under a test process with no explicit home and no FWDLOOP_CONFIG_HOME it
|
|
87
|
+
* reads nothing (OFF), so a test can never reach the real ~/.config/fwdloop.
|
|
88
|
+
* @param {string} [home]
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*/
|
|
91
|
+
export function learningHintsOn(home?: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* One finished run's folder -> the event list buildCards reads, plus the check texts and the model. ONE adapter, map never invent
|
|
94
|
+
* (F79). Check name = `<step> (line <job line>, <close class>)`; a try with verdict red or not-done and a gap = a red moment (the gap
|
|
95
|
+
* verbatim = B1's flagged line); a later try of the same check that is not red = the pass; Fix touched = `artifacts/<step>.json`;
|
|
96
|
+
* What changed = a -U1 line diff of the try's modelOutput (log.json) against the step's previous try. Reads only the run's own books.
|
|
97
|
+
* Refused drafts make no run folder, and a human redo is not a try (isTry), so neither makes a note.
|
|
98
|
+
* @param {string} runDir @param {string} workflow
|
|
99
|
+
* @returns {{events: any[], questions: Map<string, string|null>, model: string|null, source: string|null}|null} null when the run has no try
|
|
100
|
+
*/
|
|
101
|
+
export function eventsOfRun(runDir: string, workflow: string): {
|
|
102
|
+
events: any[];
|
|
103
|
+
questions: Map<string, string | null>;
|
|
104
|
+
model: string | null;
|
|
105
|
+
source: string | null;
|
|
106
|
+
} | null;
|
|
107
|
+
/**
|
|
108
|
+
* THE RUN-END TALLY ($0, code only, no model; M8 item 2): turn a finished run's folder into cards and fold them into the ledger.
|
|
109
|
+
* The place is the first input's source made absolute lexically (`path.resolve`, no fs: the F48 guard keeps realpathSync out of this file, so a symlinked source is not followed). The ledger run id is `<workflow>/<runId>` (fwdloop's run ids repeat across workflows, bareloop's do not). M8 am4: every run's notes COUNT at once (trust 'deterministic'), a run
|
|
110
|
+
* with a signed ask included; there is no hold. It runs whether `learningHints` is on or off. `questions` (bareloop's stageQuestionsByName) is, here, the failing check's own text from
|
|
111
|
+
* the run's checks.jsonl, so a check with no checks.jsonl row (a run from before am29) has no `meaning`.
|
|
112
|
+
* Borrowed-from: bareloop src/learnstore.js@v0.47.0:124 (learnAtRunEnd).
|
|
113
|
+
* @param {{home?: string, workflow: string, runId: string, runDir: string, specHash: string|null, now?: Date}} o
|
|
114
|
+
* @returns {{wrote: boolean, counted: number, held: number, problem: string|null, noise: string|null, cards: number}}
|
|
115
|
+
*/
|
|
116
|
+
export function learnAtRunEnd({ home, workflow, runId, runDir, specHash, now }: {
|
|
117
|
+
home?: string;
|
|
118
|
+
workflow: string;
|
|
119
|
+
runId: string;
|
|
120
|
+
runDir: string;
|
|
121
|
+
specHash: string | null;
|
|
122
|
+
now?: Date;
|
|
123
|
+
}): {
|
|
124
|
+
wrote: boolean;
|
|
125
|
+
counted: number;
|
|
126
|
+
held: number;
|
|
127
|
+
problem: string | null;
|
|
128
|
+
noise: string | null;
|
|
129
|
+
cards: number;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* M8 am6: seed the ledger from every run already recorded under `root` (every job, every ended run), oldest first by the run's own end time
|
|
133
|
+
* (the last history row that is a run end). Each run goes through `learnAtRunEnd` (the one note builder) with `now` = its own end time, so
|
|
134
|
+
* ages, decay and lastSeen come from the run. A run already in the ledger (its `<workflow>/<runId>` has a health line) is skipped, so a second seed adds nothing.
|
|
135
|
+
* Code only, $0. A run it cannot read is counted and the seed goes on; a bad ledger file stops it at once (nothing is rewritten).
|
|
136
|
+
* Under a test process with no door nothing is read or written (`skippedNoDoor`).
|
|
137
|
+
* @param {{root: string, home?: string}} o `home` is a test seam; production leaves it out
|
|
138
|
+
* @returns {{read: number, added: number, skipped: Record<'already-in'|'still-waiting'|'no-end'|'unreadable'|'noise', number>, problem: string|null, skippedNoDoor: boolean}}
|
|
139
|
+
*/
|
|
140
|
+
export function seedLedger({ root, home }: {
|
|
141
|
+
root: string;
|
|
142
|
+
home?: string;
|
|
143
|
+
}): {
|
|
144
|
+
read: number;
|
|
145
|
+
added: number;
|
|
146
|
+
skipped: Record<"already-in" | "still-waiting" | "no-end" | "unreadable" | "noise", number>;
|
|
147
|
+
problem: string | null;
|
|
148
|
+
skippedNoDoor: boolean;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* M8 item 5a: the block the DRAFTER is handed for this job, made from the ledger as it stood: null when `learningHints` is off,
|
|
152
|
+
* when there is no ledger, or when nothing is readable; an unreadable ledger THROWS (the caller hands nothing and records why). The one `renderHints` render (2,000 characters at most),
|
|
153
|
+
* never a second. Age (56 days), job version and level are worked out here, at read time, by renderHints.
|
|
154
|
+
* Borrowed-from: bareloop src/learnstore.js@v0.47.0:140 (hintsForRun). `spec` is `{job, inputs: [{value}]}` (job = the workflow name).
|
|
155
|
+
* @param {{home?: string, spec: any, specHash: string|null, now?: Date}} o
|
|
156
|
+
* @returns {{text: string, ids: string[]}|null}
|
|
157
|
+
*/
|
|
158
|
+
export function hintsForRun({ home, spec, specHash, now }: {
|
|
159
|
+
home?: string;
|
|
160
|
+
spec: any;
|
|
161
|
+
specHash: string | null;
|
|
162
|
+
now?: Date;
|
|
163
|
+
}): {
|
|
164
|
+
text: string;
|
|
165
|
+
ids: string[];
|
|
166
|
+
} | null;
|
|
167
|
+
/** M8 am4 item 2: a run waiting at an ask has not ended ('paused', or a Stop whose set-aside failed). ONE decider: the runner's run-end tally and the seed both read it. */
|
|
168
|
+
export const NOT_A_RUN_END: Set<string>;
|
package/types/pagerules.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export function tieOf(from: unknown, jobLines: {
|
|
|
19
19
|
* @param {unknown} shape @param {unknown} r @returns {boolean}
|
|
20
20
|
*/
|
|
21
21
|
export function validReading(shape: unknown, r: unknown): boolean;
|
|
22
|
+
/** a number as the page writes it: digits, thousands commas, optional decimals (a currency sign next to it is not part of it) */
|
|
23
|
+
/**
|
|
24
|
+
* The number written at the very end of `s` (only whitespace after it): the leftmost match of NUM followed by `\s*$`. Shared with src/pagedry.js (one copy). Scans back from the end, so a
|
|
25
|
+
* long run of digits and commas costs O(n) where a backtracking regex is quadratic.
|
|
26
|
+
* @param {string} s @returns {string|undefined}
|
|
27
|
+
*/
|
|
28
|
+
export function numberAtEnd(s: string): string | undefined;
|
|
22
29
|
/**
|
|
23
30
|
* Apply the rules to the AI's map over one saved page. Returns the kept facts and, for everything a rule removed, one `dropped` entry.
|
|
24
31
|
* The order of the rules is the POC's (apply-v3.mjs): found-on-page, then the rules that read the page. A place is read as a phrase.
|
package/types/panel/data.d.ts
CHANGED
|
@@ -658,7 +658,7 @@ export function getDraftBlock(flowDir: string, runDir: string): {
|
|
|
658
658
|
* shared-sidecar contamination risk here the way bareloop's gate-audit
|
|
659
659
|
* sidecar had). `null` when the flow/runId doesn't resolve (404).
|
|
660
660
|
* @param {{root: string, flow: string, runId: string, scheduleRead?: (flow: string) => any, home?: string, catalogue?: any, resumeAttempt?: (flow: string, runId: string) => any, startingRun?: (flow: string, runId: string) => boolean, now?: () => number}} opts
|
|
661
|
-
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, needsLeft: string|null, schedule: ReturnType<typeof scheduleAuditWords>, empty:boolean, why:string|null}|null}
|
|
661
|
+
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, learnings: any[], needsLeft: string|null, schedule: ReturnType<typeof scheduleAuditWords>, empty:boolean, why:string|null}|null}
|
|
662
662
|
*/
|
|
663
663
|
export function getRunAudit({ root, flow, runId, scheduleRead, home, catalogue, resumeAttempt, startingRun, now, }: {
|
|
664
664
|
root: string;
|
|
@@ -676,6 +676,7 @@ export function getRunAudit({ root, flow, runId, scheduleRead, home, catalogue,
|
|
|
676
676
|
rows: any[];
|
|
677
677
|
groups: any[];
|
|
678
678
|
draft: ReturnType<typeof getDraftBlock>;
|
|
679
|
+
learnings: any[];
|
|
679
680
|
needsLeft: string | null;
|
|
680
681
|
schedule: ReturnType<typeof scheduleAuditWords>;
|
|
681
682
|
empty: boolean;
|
package/types/panel/result.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ export function buildResult({ flow, runId, runDir, root, flowRead, arbiter, hist
|
|
|
109
109
|
path: string;
|
|
110
110
|
name: string;
|
|
111
111
|
bytes: number | null;
|
|
112
|
-
state: "ok" | "
|
|
112
|
+
state: "ok" | "changed" | "gone";
|
|
113
113
|
words: string | null;
|
|
114
114
|
}[];
|
|
115
115
|
gap: {
|
package/types/runner.d.ts
CHANGED
|
@@ -29,12 +29,13 @@ export function readHaltRecord(runDir: string): {
|
|
|
29
29
|
missing?: undefined;
|
|
30
30
|
red?: undefined;
|
|
31
31
|
};
|
|
32
|
-
/** @param {{goal:string, primitives?:string[], reads?:Record<string,any>, gap?:string|null}} opts */
|
|
32
|
+
/** @param {{goal:string, primitives?:string[], reads?:Record<string,any>, gap?:string|null, hints?:string|null}} opts `hints` (M8 am7): the earlier runs' block, text only, for a retry / redo / rerun try */
|
|
33
33
|
export function buildExecutorContext(opts: {
|
|
34
34
|
goal: string;
|
|
35
35
|
primitives?: string[];
|
|
36
36
|
reads?: Record<string, any>;
|
|
37
37
|
gap?: string | null;
|
|
38
|
+
hints?: string | null;
|
|
38
39
|
}): Readonly<{
|
|
39
40
|
goal: string;
|
|
40
41
|
primitives: readonly string[];
|
|
@@ -42,6 +43,7 @@ export function buildExecutorContext(opts: {
|
|
|
42
43
|
[x: string]: any;
|
|
43
44
|
}>;
|
|
44
45
|
gap: string | null;
|
|
46
|
+
hints: string | null;
|
|
45
47
|
}>;
|
|
46
48
|
/**
|
|
47
49
|
* @param {unknown} value
|
|
@@ -232,6 +234,7 @@ export function readArtifactsMapChecked(runDir: any, ids: any, { docxRoles }?: {
|
|
|
232
234
|
* @param {(row: any, modelOutput?: any) => void} opts.recordAudit
|
|
233
235
|
* @param {string|null} [opts.initialGap]
|
|
234
236
|
* @param {number} [opts.attemptOffset]
|
|
237
|
+
* @param {(() => {text: string, ids: string[]}|null)|null} [opts.learnHints] - M8 am7: `stepHintsReader`'s closure (the drafter's one block function); asked only on a retry, redo or rerun try
|
|
235
238
|
* @param {boolean} [opts.thinkingBox] - M4d am25: the job's "Thinking on" box as this run's copy keeps it (default off)
|
|
236
239
|
* @param {() => string} [opts.now] - M4a-2: stamps each audit row's `at`;
|
|
237
240
|
* defaults to the real wall clock.
|
|
@@ -242,7 +245,7 @@ export function readArtifactsMapChecked(runDir: any, ids: any, { docxRoles }?: {
|
|
|
242
245
|
* @param {string|null} [opts.runDir] - M4d am29 item 2: the run's folder, where each try saves its checks
|
|
243
246
|
* @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}}>}
|
|
244
247
|
*/
|
|
245
|
-
export function runStepRalph({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, now, readStop, stepNo, triesDone, runDir, prevStepId, }: {
|
|
248
|
+
export function runStepRalph({ step, primitivesMap, readsMap, businessDate, modelStep, spent, capUsd, ceilingUsd, recordAudit, initialGap, attemptOffset, thinkingBox, learnHints, now, readStop, stepNo, triesDone, runDir, prevStepId, }: {
|
|
246
249
|
step: any;
|
|
247
250
|
primitivesMap?: Record<string, any> | undefined;
|
|
248
251
|
readsMap: Record<string, any>;
|
|
@@ -260,6 +263,10 @@ export function runStepRalph({ step, primitivesMap, readsMap, businessDate, mode
|
|
|
260
263
|
recordAudit: (row: any, modelOutput?: any) => void;
|
|
261
264
|
initialGap?: string | null | undefined;
|
|
262
265
|
attemptOffset?: number | undefined;
|
|
266
|
+
learnHints?: (() => {
|
|
267
|
+
text: string;
|
|
268
|
+
ids: string[];
|
|
269
|
+
} | null) | null | undefined;
|
|
263
270
|
thinkingBox?: boolean | undefined;
|
|
264
271
|
now?: (() => string) | undefined;
|
|
265
272
|
readStop?: (() => boolean) | null | undefined;
|
|
@@ -544,3 +551,5 @@ export const MAX_ATTEMPTS: 4;
|
|
|
544
551
|
export const SPEND_TOLERANCE_USD: 1e-9;
|
|
545
552
|
export const STOP_FILE: "stop.request";
|
|
546
553
|
export const HALT_FILE: "halt.json";
|
|
554
|
+
/** where a failure of learnings work that must not stop the run is recorded (one appended row, in the run's own folder): the run-end tally (`recordRunNotes`) and the take of the draft's learnings record (`takeLearningsRecord`, in runFlow). The run itself is unaffected */
|
|
555
|
+
export const LEARN_ERROR_FILE: "learn-error.jsonl";
|
package/types/thinking.d.ts
CHANGED
|
@@ -50,6 +50,17 @@ export function stepThinkingMode({ boxOn, attempt }: {
|
|
|
50
50
|
boxOn: boolean;
|
|
51
51
|
attempt: number;
|
|
52
52
|
}): "on" | "off";
|
|
53
|
+
/**
|
|
54
|
+
* M8 am7 item 2: the ONE owner of whether a step's try is handed the earlier runs' block. The places thinking switches on, but NOT the Chat "Thinking on" box:
|
|
55
|
+
* a retry (2nd or later try), a redo at an ask (numbered after the step's last try, so 2nd or later), and a rerun (the fresh run's first step, which starts
|
|
56
|
+
* from the human's rerun reason). A step's plain first try never gets it, whatever the box says.
|
|
57
|
+
* @param {{attempt: number, rerunReason: string|null}} a `rerunReason`: the reason this try starts from when it is a fresh run's first try, else null
|
|
58
|
+
* @returns {boolean}
|
|
59
|
+
*/
|
|
60
|
+
export function stepHintsWanted({ attempt, rerunReason }: {
|
|
61
|
+
attempt: number;
|
|
62
|
+
rerunReason: string | null;
|
|
63
|
+
}): boolean;
|
|
53
64
|
/** The sentence under a greyed "Thinking on" box (amendment 7 item 2). */
|
|
54
65
|
export const THINKING_FIXED_SAY: "can't change this for this model";
|
|
55
66
|
/** The note beside the Chat "Thinking on" box, before any draft, for a model bareagent has not checked (M4d am11 item 2). */
|