fwdloop 0.5.0 → 0.7.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 +559 -0
- package/package.json +7 -3
- package/src/ask.js +360 -7
- package/src/books.js +209 -2
- package/src/declaration.js +12 -1
- package/src/flow.js +247 -2
- package/src/index.js +9 -2
- package/src/model-step.js +153 -14
- package/src/panel/data.js +1589 -0
- package/src/panel/index.html +2377 -0
- package/src/panel/server.js +268 -0
- package/src/primitives.js +136 -41
- package/src/provider.js +57 -41
- package/src/runner.js +1231 -137
- package/src/send.js +20 -1
- package/src/types.js +18 -0
- package/types/ask.d.ts +95 -1
- package/types/books.d.ts +70 -2
- package/types/flow.d.ts +135 -0
- package/types/index.d.ts +5 -2
- package/types/panel/data.d.ts +433 -0
- package/types/panel/server.d.ts +45 -0
- package/types/primitives.d.ts +29 -0
- package/types/provider.d.ts +11 -0
- package/types/runner.d.ts +135 -26
- package/types/types.d.ts +41 -0
package/types/runner.d.ts
CHANGED
|
@@ -74,9 +74,40 @@ export function checkSendDestination(target: string): {
|
|
|
74
74
|
export function writeArtifact(runDir: any, id: any, artifact: any, { overwrite }?: {
|
|
75
75
|
overwrite?: boolean | undefined;
|
|
76
76
|
}): void;
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
77
|
+
/**
|
|
78
|
+
* F48 round 4 (redesign, docs/logs/FINDINGS.md): the ONE tri-state reader
|
|
79
|
+
* every artifact-reading call site routes through. Round 3's `readArtifact`
|
|
80
|
+
* collapsed THREE outcomes into one `undefined` — "never written" and
|
|
81
|
+
* "read refused" (symlink escape / outside the run dir / unparseable JSON)
|
|
82
|
+
* were indistinguishable to every caller. That single value with two
|
|
83
|
+
* meanings is exactly what let a swapped/deleted accepted artifact reach
|
|
84
|
+
* the send slot as `undefined`, get `?? null`-ed by `src/send.js`, and ship
|
|
85
|
+
* a 4-byte `null` to the signed destination as a recorded "green" send —
|
|
86
|
+
* the refusal `readFileInside` already computes was thrown away one layer
|
|
87
|
+
* up. Every caller below now sees the real shape and decides, explicitly,
|
|
88
|
+
* whether "missing" is fine (a genuinely not-yet-written read) or whether
|
|
89
|
+
* ANY refusal — missing or red — must halt the run.
|
|
90
|
+
* @returns {{ok:true, value:any} | {ok:false, missing:true} | {ok:false, missing:false, red:string}}
|
|
91
|
+
*/
|
|
92
|
+
export function readArtifactResult(runDir: any, id: any): {
|
|
93
|
+
ok: true;
|
|
94
|
+
value: any;
|
|
95
|
+
} | {
|
|
96
|
+
ok: false;
|
|
97
|
+
missing: true;
|
|
98
|
+
} | {
|
|
99
|
+
ok: false;
|
|
100
|
+
missing: false;
|
|
101
|
+
red: string;
|
|
102
|
+
};
|
|
103
|
+
/** Back-compat convenience collapse of `readArtifactResult`: `undefined` for
|
|
104
|
+
* BOTH "never written" and "read refused" — the exact collapse the F48
|
|
105
|
+
* round 4 redesign says a caller must never reach for on its own. Safe to
|
|
106
|
+
* use ONLY where an explicit tri-state check has already refused any `red`
|
|
107
|
+
* for this same id earlier in the same call (documented at each remaining
|
|
108
|
+
* call site) — never add a NEW call site with this function instead of
|
|
109
|
+
* `readArtifactResult`.
|
|
110
|
+
*/
|
|
80
111
|
export function readArtifact(runDir: any, id: any): any;
|
|
81
112
|
/**
|
|
82
113
|
* @param {object} opts
|
|
@@ -86,14 +117,22 @@ export function readArtifact(runDir: any, id: any): any;
|
|
|
86
117
|
* @param {Array<{id:string, path:string}>} opts.sources - the real files to freeze for this run.
|
|
87
118
|
* @param {unknown} opts.catalogue - passed straight through to `readFlow`.
|
|
88
119
|
* @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<{ok:boolean, artifact?:unknown, costUsd:number|null, red?:string, transport?:boolean, model?:string, modelMatch?:boolean}>} opts.modelStep
|
|
89
|
-
* @param {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:'accept'|'reject'|'rerun'|'timeout', reason?:string}>} opts.askStep
|
|
120
|
+
* @param {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:'accept'|'reject'|'rerun'|'timeout'|'park', reason?:string}>} opts.askStep
|
|
90
121
|
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
|
|
91
122
|
* @param {Record<string, any>} [opts.primitives] - injected primitive implementations, keyed by catalogue verb.
|
|
123
|
+
* @param {string[]} [opts.primitiveReds] - `resolvePrimitives`'s own `reds` (e.g. bareguard refusing a symlinked file scope); any entry refuses the run at $0 like an unwired verb, before the run dir exists.
|
|
92
124
|
* @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
|
|
93
125
|
* @param {string} opts.businessDate - the run's explicit "as of today", never the wall clock.
|
|
94
126
|
* @param {number} [opts.ceilingUsd] - per-attempt ceiling override; defaults to `resolveCeilingUsd(null)`.
|
|
127
|
+
* @param {string|null} [opts.initialGap] - M3 scope item 7 (rerun as a fresh
|
|
128
|
+
* run): a human's rerun reason, carried as the FIRST ordinary step's
|
|
129
|
+
* starting gap. Never used by a plain `runFlow` call outside `resumeRun`'s
|
|
130
|
+
* own rerun path.
|
|
131
|
+
* @param {() => number} [opts.nowMs] - F45 finding 3: returns the current
|
|
132
|
+
* epoch ms; defaults to the wall clock. Mirrors `clock` (ISO) so a test
|
|
133
|
+
* can advance wall time across a park/resume boundary without a real wait.
|
|
95
134
|
*/
|
|
96
|
-
export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, clock, businessDate, ceilingUsd, }: {
|
|
135
|
+
export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, nowMs, }: {
|
|
97
136
|
root: string;
|
|
98
137
|
name: string;
|
|
99
138
|
runId: string;
|
|
@@ -118,7 +157,7 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
|
|
|
118
157
|
evidence: unknown;
|
|
119
158
|
runDir: string;
|
|
120
159
|
}) => Promise<{
|
|
121
|
-
decision: "accept" | "reject" | "rerun" | "timeout";
|
|
160
|
+
decision: "accept" | "reject" | "rerun" | "timeout" | "park";
|
|
122
161
|
reason?: string;
|
|
123
162
|
}>;
|
|
124
163
|
sendStep: (target: string, filename: string, content: unknown) => Promise<{
|
|
@@ -127,30 +166,90 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
|
|
|
127
166
|
bytes?: number;
|
|
128
167
|
}>;
|
|
129
168
|
primitives?: Record<string, any> | undefined;
|
|
169
|
+
primitiveReds?: string[] | undefined;
|
|
130
170
|
clock?: (() => string) | undefined;
|
|
131
171
|
businessDate: string;
|
|
132
172
|
ceilingUsd?: number | undefined;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
spentUsd?: undefined;
|
|
144
|
-
auditRows?: undefined;
|
|
145
|
-
} | {
|
|
146
|
-
outcome: string;
|
|
147
|
-
runDir: string;
|
|
148
|
-
artifacts: {};
|
|
149
|
-
spentUsd: number;
|
|
150
|
-
auditRows: any[];
|
|
151
|
-
red?: undefined;
|
|
152
|
-
reds?: undefined;
|
|
173
|
+
initialGap?: string | null | undefined;
|
|
174
|
+
nowMs?: (() => number) | undefined;
|
|
175
|
+
}): Promise<any>;
|
|
176
|
+
/** An ask step that never waits — it immediately tells the fold to park.
|
|
177
|
+
* The counterpart to `makeFileAskStep`'s in-process poll (M2 scope item 6);
|
|
178
|
+
* a caller wanting park-and-exit behaviour from a FRESH `runFlow` call
|
|
179
|
+
* passes this (or an equivalent) as `askStep`.
|
|
180
|
+
* @returns {(opts?: any) => Promise<{decision: 'park'}>} */
|
|
181
|
+
export function makeParkingAskStep(): (opts?: any) => Promise<{
|
|
182
|
+
decision: "park";
|
|
153
183
|
}>;
|
|
184
|
+
/**
|
|
185
|
+
* M3 scope items 4-6: re-enter a parked run's SAME fold from a separate
|
|
186
|
+
* process. Takes an exclusive `resume.lock` (refuses by name if already
|
|
187
|
+
* held; a lock left behind by a killed resumer is a red naming it, never
|
|
188
|
+
* stolen), re-reads the flow, refuses by name at $0 on any signature/input/
|
|
189
|
+
* missing-artifact mismatch, consumes `answer.json` by atomic rename BEFORE
|
|
190
|
+
* acting (F44), then either cancels an expired ask ($0, nothing sent) or
|
|
191
|
+
* resolves it and folds on to `complete`/the next pause/a halt.
|
|
192
|
+
*
|
|
193
|
+
* @param {object} opts
|
|
194
|
+
* @param {string} opts.root
|
|
195
|
+
* @param {string} opts.name
|
|
196
|
+
* @param {string} opts.runId
|
|
197
|
+
* @param {unknown} opts.catalogue
|
|
198
|
+
* @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
|
|
199
|
+
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
|
|
200
|
+
* @param {Record<string, any>} [opts.primitives]
|
|
201
|
+
* @param {string[]} [opts.primitiveReds] - see `runFlow`'s own.
|
|
202
|
+
* @param {() => string} [opts.clock]
|
|
203
|
+
* @param {string} opts.businessDate
|
|
204
|
+
* @param {number} [opts.ceilingUsd]
|
|
205
|
+
* @param {() => number} [opts.nowMs] - F45 finding 3; see `runFlow`'s own.
|
|
206
|
+
*/
|
|
207
|
+
export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, nowMs, }: {
|
|
208
|
+
root: string;
|
|
209
|
+
name: string;
|
|
210
|
+
runId: string;
|
|
211
|
+
catalogue: unknown;
|
|
212
|
+
modelStep: (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
|
|
213
|
+
class: string | null;
|
|
214
|
+
}) => Promise<any>;
|
|
215
|
+
sendStep: (target: string, filename: string, content: unknown) => Promise<{
|
|
216
|
+
ok: boolean;
|
|
217
|
+
red?: string;
|
|
218
|
+
bytes?: number;
|
|
219
|
+
}>;
|
|
220
|
+
primitives?: Record<string, any> | undefined;
|
|
221
|
+
primitiveReds?: string[] | undefined;
|
|
222
|
+
clock?: (() => string) | undefined;
|
|
223
|
+
businessDate: string;
|
|
224
|
+
ceilingUsd?: number | undefined;
|
|
225
|
+
nowMs?: (() => number) | undefined;
|
|
226
|
+
}): Promise<any>;
|
|
227
|
+
/**
|
|
228
|
+
* `writeLog`'s own sibling reader (M4a piece 2, docs/wiki/the-module-
|
|
229
|
+
* ladder.md M4a scope item 2: "one reader per book") — `null` when the run
|
|
230
|
+
* hasn't reached an exit path yet (still running, or parked before any
|
|
231
|
+
* halt/complete), or the file is present but not valid JSON (a torn write),
|
|
232
|
+
* never a thrown error.
|
|
233
|
+
* @param {string} runDir
|
|
234
|
+
* @returns {any|null}
|
|
235
|
+
*/
|
|
236
|
+
export function readLog(runDir: string): any | null;
|
|
237
|
+
/**
|
|
238
|
+
* `state.json`'s own sibling reader (same rule as {@link readLog}) — `null`
|
|
239
|
+
* when the run has never parked, or the file is present but not valid JSON.
|
|
240
|
+
* @param {string} runDir
|
|
241
|
+
* @returns {any|null}
|
|
242
|
+
*/
|
|
243
|
+
export function readRunState(runDir: string): any | null;
|
|
244
|
+
/**
|
|
245
|
+
* `ask.json`'s own sibling reader (same rule as {@link readLog}) — the
|
|
246
|
+
* parking ask protocol's own writer lives in {@link runAskSlot} above.
|
|
247
|
+
* `null` when there is no open ask for this run, or the file is present but
|
|
248
|
+
* not valid JSON.
|
|
249
|
+
* @param {string} runDir
|
|
250
|
+
* @returns {any|null}
|
|
251
|
+
*/
|
|
252
|
+
export function readAsk(runDir: string): any | null;
|
|
154
253
|
/** The strike governor — a run-owned constant, never raised by a caller,
|
|
155
254
|
* never carried in the arbiter block or the declaration (M2 scope item 5,
|
|
156
255
|
* signed 2026-09-24 "2A"). */
|
|
@@ -159,3 +258,13 @@ export const STRIKE_LIMIT: 2;
|
|
|
159
258
|
* fallback, never the governor" — it never raises the strike bound, it only
|
|
160
259
|
* bounds the case the strike governor doesn't catch). */
|
|
161
260
|
export const MAX_ATTEMPTS: 4;
|
|
261
|
+
/** Debrief round 2: `state.spent` (accumulated by repeated `spent.value +=`
|
|
262
|
+
* during the run) and `sumAuditUsd`'s re-summed total are two independent
|
|
263
|
+
* float summations of the same rows in a different order — IEEE 754
|
|
264
|
+
* addition is not associative, so they can differ by a single ULP (e.g.
|
|
265
|
+
* 0.006874 vs 0.006874000000000001) with no real discrepancy. The books
|
|
266
|
+
* (audit.jsonl) stay the source of truth; this tolerance only absorbs
|
|
267
|
+
* summation-order noise, not a real gap. A billionth of a dollar is ~6
|
|
268
|
+
* orders of magnitude below the cheapest real round (audit rows here run
|
|
269
|
+
* $0.0006+), so nothing a real tamper produces can hide inside it. */
|
|
270
|
+
export const SPEND_TOLERANCE_USD: 1e-9;
|
package/types/types.d.ts
CHANGED
|
@@ -272,6 +272,11 @@ export type CloseVerdict = {
|
|
|
272
272
|
};
|
|
273
273
|
/**
|
|
274
274
|
* One row appended to `runs/<run-id>/audit.jsonl` (M2 scope item 9).
|
|
275
|
+
* `at`/`tokens` were added by Amendment M4a-2 and `tools`/`ungranted` by
|
|
276
|
+
* Amendment M4a-3 (docs/wiki/the-module-ladder.md, "M4a" section) — every
|
|
277
|
+
* row `appendAudit` writes from here on carries `at`/`tokens`/`tools`; a row
|
|
278
|
+
* written before its amendment simply lacks the newer keys (read back as-is,
|
|
279
|
+
* never backfilled) — see `auditRowTokens`/`auditRowTools` in `src/books.js`.
|
|
275
280
|
*/
|
|
276
281
|
export type AuditRow = {
|
|
277
282
|
step: string | null;
|
|
@@ -285,6 +290,42 @@ export type AuditRow = {
|
|
|
285
290
|
model: string | null;
|
|
286
291
|
modelMatch: boolean | null;
|
|
287
292
|
strike: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* - ISO time this attempt finished.
|
|
295
|
+
*/
|
|
296
|
+
at: string;
|
|
297
|
+
/**
|
|
298
|
+
* -
|
|
299
|
+
* summed over this attempt's model calls; `null` only when `model` is
|
|
300
|
+
* `null` (no model call this row).
|
|
301
|
+
*/
|
|
302
|
+
tokens: {
|
|
303
|
+
inputTokens: number;
|
|
304
|
+
outputTokens: number;
|
|
305
|
+
cacheReadTokens: number;
|
|
306
|
+
} | null;
|
|
307
|
+
/**
|
|
308
|
+
* - a {toolName: count}
|
|
309
|
+
* tally of every GRANTED tool the model actually invoked this attempt,
|
|
310
|
+
* summed across every round; `{}` when the model called no tool; `null`
|
|
311
|
+
* only when `model` is `null` (no model call this row).
|
|
312
|
+
*/
|
|
313
|
+
tools: Record<string, number> | null;
|
|
314
|
+
/**
|
|
315
|
+
* - tool names the model called that this
|
|
316
|
+
* step never granted; absent when empty, never an invented empty array.
|
|
317
|
+
*/
|
|
318
|
+
ungranted?: string[] | undefined;
|
|
319
|
+
/**
|
|
320
|
+
* - bareguard
|
|
321
|
+
* fs-gate refusals during this attempt; `[]` (never omitted) on every row
|
|
322
|
+
* written by a model attempt, absent on rows with no model call.
|
|
323
|
+
*/
|
|
324
|
+
refused?: {
|
|
325
|
+
verb: string;
|
|
326
|
+
path: string;
|
|
327
|
+
rule: string;
|
|
328
|
+
}[] | undefined;
|
|
288
329
|
};
|
|
289
330
|
/**
|
|
290
331
|
* One row appended to `flows/<name>/history.jsonl` (M2 scope item 9).
|