fwdloop 0.5.0 → 0.6.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 +480 -0
- package/package.json +5 -1
- package/src/ask.js +104 -5
- package/src/declaration.js +12 -1
- package/src/index.js +2 -1
- package/src/model-step.js +2 -2
- package/src/runner.js +865 -110
- package/types/ask.d.ts +18 -1
- package/types/index.d.ts +2 -1
- package/types/runner.d.ts +71 -23
package/types/ask.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @param {{ timeoutMs?: number, pollMs?: number, clock?: () => string, writeLine?: (line:string) => void }} [opts]
|
|
3
|
-
* @returns {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:string, reason?:string}>}
|
|
3
|
+
* @returns {(opts:{question:string, evidence:unknown, runDir:string, ttlMs?: number}) => Promise<{decision:string, reason?:string}>}
|
|
4
4
|
*/
|
|
5
5
|
export function makeFileAskStep({ timeoutMs, pollMs, clock, writeLine, }?: {
|
|
6
6
|
timeoutMs?: number;
|
|
@@ -11,7 +11,24 @@ export function makeFileAskStep({ timeoutMs, pollMs, clock, writeLine, }?: {
|
|
|
11
11
|
question: string;
|
|
12
12
|
evidence: unknown;
|
|
13
13
|
runDir: string;
|
|
14
|
+
ttlMs?: number;
|
|
14
15
|
}) => Promise<{
|
|
15
16
|
decision: string;
|
|
16
17
|
reason?: string;
|
|
17
18
|
}>;
|
|
19
|
+
/**
|
|
20
|
+
* @param {{ runDir: string, askId: string, decision: 'accept'|'reject'|'rerun', reason?: string, clock?: () => string }} opts
|
|
21
|
+
* @returns {{ ok: true } | { ok: false, red: string }}
|
|
22
|
+
*/
|
|
23
|
+
export function answerAsk({ runDir, askId, decision, reason, clock, }: {
|
|
24
|
+
runDir: string;
|
|
25
|
+
askId: string;
|
|
26
|
+
decision: "accept" | "reject" | "rerun";
|
|
27
|
+
reason?: string;
|
|
28
|
+
clock?: () => string;
|
|
29
|
+
}): {
|
|
30
|
+
ok: true;
|
|
31
|
+
} | {
|
|
32
|
+
ok: false;
|
|
33
|
+
red: string;
|
|
34
|
+
};
|
package/types/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { signFlow, verifyFlow, canonicalBytes, SIGNATURE_FIELDS } from "./signat
|
|
|
4
4
|
export { validateDeclaration, DECLARATION_FIELDS } from "./declaration.js";
|
|
5
5
|
export { parseCatalogue, loadCatalogue, menu, primitiveFor, resolveEntry, CATALOGUE_FIELDS } from "./catalogue.js";
|
|
6
6
|
export { checkFlowName, writeFlow, readFlow, FLOW_FILES } from "./flow.js";
|
|
7
|
-
export { runFlow, STRIKE_LIMIT, MAX_ATTEMPTS } from "./runner.js";
|
|
7
|
+
export { runFlow, resumeRun, makeParkingAskStep, STRIKE_LIMIT, MAX_ATTEMPTS } from "./runner.js";
|
|
8
|
+
export { makeFileAskStep, answerAsk } from "./ask.js";
|
package/types/runner.d.ts
CHANGED
|
@@ -86,14 +86,21 @@ export function readArtifact(runDir: any, id: any): any;
|
|
|
86
86
|
* @param {Array<{id:string, path:string}>} opts.sources - the real files to freeze for this run.
|
|
87
87
|
* @param {unknown} opts.catalogue - passed straight through to `readFlow`.
|
|
88
88
|
* @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
|
|
89
|
+
* @param {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:'accept'|'reject'|'rerun'|'timeout'|'park', reason?:string}>} opts.askStep
|
|
90
90
|
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
|
|
91
91
|
* @param {Record<string, any>} [opts.primitives] - injected primitive implementations, keyed by catalogue verb.
|
|
92
92
|
* @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
|
|
93
93
|
* @param {string} opts.businessDate - the run's explicit "as of today", never the wall clock.
|
|
94
94
|
* @param {number} [opts.ceilingUsd] - per-attempt ceiling override; defaults to `resolveCeilingUsd(null)`.
|
|
95
|
+
* @param {string|null} [opts.initialGap] - M3 scope item 7 (rerun as a fresh
|
|
96
|
+
* run): a human's rerun reason, carried as the FIRST ordinary step's
|
|
97
|
+
* starting gap. Never used by a plain `runFlow` call outside `resumeRun`'s
|
|
98
|
+
* own rerun path.
|
|
99
|
+
* @param {() => number} [opts.nowMs] - F45 finding 3: returns the current
|
|
100
|
+
* epoch ms; defaults to the wall clock. Mirrors `clock` (ISO) so a test
|
|
101
|
+
* can advance wall time across a park/resume boundary without a real wait.
|
|
95
102
|
*/
|
|
96
|
-
export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, clock, businessDate, ceilingUsd, }: {
|
|
103
|
+
export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, clock, businessDate, ceilingUsd, initialGap, nowMs, }: {
|
|
97
104
|
root: string;
|
|
98
105
|
name: string;
|
|
99
106
|
runId: string;
|
|
@@ -118,7 +125,7 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
|
|
|
118
125
|
evidence: unknown;
|
|
119
126
|
runDir: string;
|
|
120
127
|
}) => Promise<{
|
|
121
|
-
decision: "accept" | "reject" | "rerun" | "timeout";
|
|
128
|
+
decision: "accept" | "reject" | "rerun" | "timeout" | "park";
|
|
122
129
|
reason?: string;
|
|
123
130
|
}>;
|
|
124
131
|
sendStep: (target: string, filename: string, content: unknown) => Promise<{
|
|
@@ -130,27 +137,58 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
|
|
|
130
137
|
clock?: (() => string) | undefined;
|
|
131
138
|
businessDate: string;
|
|
132
139
|
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;
|
|
140
|
+
initialGap?: string | null | undefined;
|
|
141
|
+
nowMs?: (() => number) | undefined;
|
|
142
|
+
}): Promise<any>;
|
|
143
|
+
/** An ask step that never waits — it immediately tells the fold to park.
|
|
144
|
+
* The counterpart to `makeFileAskStep`'s in-process poll (M2 scope item 6);
|
|
145
|
+
* a caller wanting park-and-exit behaviour from a FRESH `runFlow` call
|
|
146
|
+
* passes this (or an equivalent) as `askStep`.
|
|
147
|
+
* @returns {(opts?: any) => Promise<{decision: 'park'}>} */
|
|
148
|
+
export function makeParkingAskStep(): (opts?: any) => Promise<{
|
|
149
|
+
decision: "park";
|
|
153
150
|
}>;
|
|
151
|
+
/**
|
|
152
|
+
* M3 scope items 4-6: re-enter a parked run's SAME fold from a separate
|
|
153
|
+
* process. Takes an exclusive `resume.lock` (refuses by name if already
|
|
154
|
+
* held; a lock left behind by a killed resumer is a red naming it, never
|
|
155
|
+
* stolen), re-reads the flow, refuses by name at $0 on any signature/input/
|
|
156
|
+
* missing-artifact mismatch, consumes `answer.json` by atomic rename BEFORE
|
|
157
|
+
* acting (F44), then either cancels an expired ask ($0, nothing sent) or
|
|
158
|
+
* resolves it and folds on to `complete`/the next pause/a halt.
|
|
159
|
+
*
|
|
160
|
+
* @param {object} opts
|
|
161
|
+
* @param {string} opts.root
|
|
162
|
+
* @param {string} opts.name
|
|
163
|
+
* @param {string} opts.runId
|
|
164
|
+
* @param {unknown} opts.catalogue
|
|
165
|
+
* @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
|
|
166
|
+
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
|
|
167
|
+
* @param {Record<string, any>} [opts.primitives]
|
|
168
|
+
* @param {() => string} [opts.clock]
|
|
169
|
+
* @param {string} opts.businessDate
|
|
170
|
+
* @param {number} [opts.ceilingUsd]
|
|
171
|
+
* @param {() => number} [opts.nowMs] - F45 finding 3; see `runFlow`'s own.
|
|
172
|
+
*/
|
|
173
|
+
export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, primitives, clock, businessDate, ceilingUsd, nowMs, }: {
|
|
174
|
+
root: string;
|
|
175
|
+
name: string;
|
|
176
|
+
runId: string;
|
|
177
|
+
catalogue: unknown;
|
|
178
|
+
modelStep: (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
|
|
179
|
+
class: string | null;
|
|
180
|
+
}) => Promise<any>;
|
|
181
|
+
sendStep: (target: string, filename: string, content: unknown) => Promise<{
|
|
182
|
+
ok: boolean;
|
|
183
|
+
red?: string;
|
|
184
|
+
bytes?: number;
|
|
185
|
+
}>;
|
|
186
|
+
primitives?: Record<string, any> | undefined;
|
|
187
|
+
clock?: (() => string) | undefined;
|
|
188
|
+
businessDate: string;
|
|
189
|
+
ceilingUsd?: number | undefined;
|
|
190
|
+
nowMs?: (() => number) | undefined;
|
|
191
|
+
}): Promise<any>;
|
|
154
192
|
/** The strike governor — a run-owned constant, never raised by a caller,
|
|
155
193
|
* never carried in the arbiter block or the declaration (M2 scope item 5,
|
|
156
194
|
* signed 2026-09-24 "2A"). */
|
|
@@ -159,3 +197,13 @@ export const STRIKE_LIMIT: 2;
|
|
|
159
197
|
* fallback, never the governor" — it never raises the strike bound, it only
|
|
160
198
|
* bounds the case the strike governor doesn't catch). */
|
|
161
199
|
export const MAX_ATTEMPTS: 4;
|
|
200
|
+
/** Debrief round 2: `state.spent` (accumulated by repeated `spent.value +=`
|
|
201
|
+
* during the run) and `sumAuditUsd`'s re-summed total are two independent
|
|
202
|
+
* float summations of the same rows in a different order — IEEE 754
|
|
203
|
+
* addition is not associative, so they can differ by a single ULP (e.g.
|
|
204
|
+
* 0.006874 vs 0.006874000000000001) with no real discrepancy. The books
|
|
205
|
+
* (audit.jsonl) stay the source of truth; this tolerance only absorbs
|
|
206
|
+
* summation-order noise, not a real gap. A billionth of a dollar is ~6
|
|
207
|
+
* orders of magnitude below the cheapest real round (audit rows here run
|
|
208
|
+
* $0.0006+), so nothing a real tamper produces can hide inside it. */
|
|
209
|
+
export const SPEND_TOLERANCE_USD: 1e-9;
|