fwdloop 0.6.0 → 0.8.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 +221 -64
- package/package.json +5 -5
- package/src/ask.js +260 -6
- package/src/authoring.js +313 -0
- package/src/books.js +209 -2
- package/src/catalogue.json +1 -1
- package/src/declaration.js +16 -2
- package/src/docx.js +33 -4
- package/src/drafter.js +324 -0
- package/src/flow.js +247 -2
- package/src/index.js +9 -3
- package/src/input-facts.js +45 -0
- package/src/model-step.js +151 -12
- 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 +146 -42
- package/src/provider.js +61 -43
- package/src/runner.js +393 -54
- package/src/send.js +20 -1
- package/src/sign-confirm.js +27 -0
- package/src/signed-text.js +19 -5
- package/src/types.js +19 -0
- package/types/ask.d.ts +77 -0
- package/types/authoring.d.ts +132 -0
- package/types/books.d.ts +70 -2
- package/types/declaration.d.ts +7 -1
- package/types/docx.d.ts +8 -0
- package/types/drafter.d.ts +164 -0
- package/types/flow.d.ts +135 -0
- package/types/index.d.ts +5 -3
- package/types/input-facts.d.ts +14 -0
- package/types/panel/data.d.ts +433 -0
- package/types/panel/server.d.ts +45 -0
- package/types/primitives.d.ts +33 -0
- package/types/provider.d.ts +14 -1
- package/types/runner.d.ts +66 -5
- package/types/sign-confirm.d.ts +18 -0
- package/types/signed-text.d.ts +14 -0
- package/types/types.d.ts +45 -0
package/types/primitives.d.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* `.csv` belongs to `addressCells`, anything else has no text primitive.
|
|
4
4
|
* Pure and exported so tests can hit the four cases directly (F41 item 3). */
|
|
5
5
|
export function rolePrimitiveFor(frozenPath: any): "read" | "readDocx" | "addressCells" | null;
|
|
6
|
+
/** The wired menu, one place: the catalogue entries whose verb is in
|
|
7
|
+
* WIRED_VERBS (and, when `skills` is given, in a signed skill). Absence,
|
|
8
|
+
* not refusal. Throws only if catalogue.json itself is unreadable. */
|
|
9
|
+
export function wiredMenu(skills: any): import("./types.js").CatalogueEntry[];
|
|
6
10
|
/**
|
|
7
11
|
* Resolve the granted tools for one step's model call. Never throws —
|
|
8
12
|
* a verb absent from the catalogue, or present but unimplemented here, is
|
|
@@ -24,3 +28,32 @@ export function resolvePrimitives(catalogue: import("./types.js").CatalogueEntry
|
|
|
24
28
|
tools: Record<string, any>;
|
|
25
29
|
reds: string[];
|
|
26
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Resolve a model-given path string against `runDir` and pass it through the
|
|
33
|
+
* step's bareguard `Gate`. A `~`-prefixed or already-absolute path is handed
|
|
34
|
+
* to `resolveToolPath` as-is (it expands `~`/normalizes); anything else is
|
|
35
|
+
* joined onto `runDir` first, THEN resolved — so a relative path always
|
|
36
|
+
* lands inside the run dir before the gate ever sees it, matching
|
|
37
|
+
* bareguard's own "agent paths must be absolute" rule (`fs.invalidPath`
|
|
38
|
+
* otherwise). The SAME resolved string that was checked is what the caller
|
|
39
|
+
* must hand to the real tool's `execute` — never re-derive a second string
|
|
40
|
+
* after the decision (F48's own re-check rule: check and open the same
|
|
41
|
+
* value). Throws naming the verb, the path, and bareguard's own rule name
|
|
42
|
+
* on a deny; returns the resolved path on allow.
|
|
43
|
+
*/
|
|
44
|
+
/** Typed carrier for a bareguard fs-gate deny: `model-step` catches it by
|
|
45
|
+
* `instanceof` and records `{verb, path, rule}` on the attempt's audit row —
|
|
46
|
+
* never parsed back out of the message string. */
|
|
47
|
+
export class GateRefusal extends Error {
|
|
48
|
+
constructor(verb: any, resolved: any, rule: any);
|
|
49
|
+
verb: any;
|
|
50
|
+
path: any;
|
|
51
|
+
rule: any;
|
|
52
|
+
}
|
|
53
|
+
/** The verbs this piece actually implements (the switch below, as data) —
|
|
54
|
+
* one writer for "is this verb wired": `resolvePrimitives`'s own reds use
|
|
55
|
+
* it, and `src/runner.js`'s preflight (F46: a step granted a
|
|
56
|
+
* catalogue-present-but-unwired verb, e.g. litectx's `compress`, must
|
|
57
|
+
* refuse before any model call or spend) imports this SAME set rather than
|
|
58
|
+
* keeping a second copy of the list. */
|
|
59
|
+
export const WIRED_VERBS: Set<string>;
|
package/types/provider.d.ts
CHANGED
|
@@ -238,6 +238,17 @@ export function sumMeterings(events: any): {
|
|
|
238
238
|
/** Append one spend row, stamping `modelMatch` — the one writer for
|
|
239
239
|
* spend.jsonl. Warns (never throws) on a `substituted` model. */
|
|
240
240
|
export function appendSpendRow(path: any, row: any): void;
|
|
241
|
+
/**
|
|
242
|
+
* `appendSpendRow`'s own sibling reader (M4a piece 2, docs/wiki/the-module-
|
|
243
|
+
* ladder.md M4a scope item 2: "one reader per book") — every row as written,
|
|
244
|
+
* raw, in file order. `[]` when the file doesn't exist yet, and a malformed
|
|
245
|
+
* line is skipped rather than thrown on (an honest best-effort read, same
|
|
246
|
+
* posture as `src/books.js`'s readers — a caller that needs to know the row
|
|
247
|
+
* count decides how to treat a gap, this function never crashes over it).
|
|
248
|
+
* @param {string} path
|
|
249
|
+
* @returns {any[]}
|
|
250
|
+
*/
|
|
251
|
+
export function readSpendRows(path: string): any[];
|
|
241
252
|
/** Throws once total spend (every null row repriced at its ceiling) is at
|
|
242
253
|
* or over `capUsd`. */
|
|
243
254
|
export function assertUnderGlobalCap(path: any, capUsd: any): number;
|
|
@@ -270,13 +281,15 @@ export function checkKeyPreflight(slotName: string, env?: Record<string, string
|
|
|
270
281
|
* values this project uses.
|
|
271
282
|
*
|
|
272
283
|
* @param {string} slotName
|
|
273
|
-
* @param {{ model?: string, timeoutMs?: number, deadlineMs?: number }} [options]
|
|
284
|
+
* @param {{ model?: string, timeoutMs?: number, deadlineMs?: number, thinking?: object|null }} [options]
|
|
285
|
+
* `thinking` (bare-agent >=0.49) is sent verbatim as body.thinking; unset/null leaves the body unchanged.
|
|
274
286
|
* @returns {{ provider: any, rates: {in:number, out:number}, modelId: string, suffix: string, slot: string }}
|
|
275
287
|
*/
|
|
276
288
|
export function makeProvider(slotName: string, options?: {
|
|
277
289
|
model?: string;
|
|
278
290
|
timeoutMs?: number;
|
|
279
291
|
deadlineMs?: number;
|
|
292
|
+
thinking?: object | null;
|
|
280
293
|
}): {
|
|
281
294
|
provider: any;
|
|
282
295
|
rates: {
|
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
|
|
@@ -89,6 +120,7 @@ export function readArtifact(runDir: any, id: any): any;
|
|
|
89
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)`.
|
|
@@ -100,7 +132,7 @@ export function readArtifact(runDir: any, id: any): any;
|
|
|
100
132
|
* epoch ms; defaults to the wall clock. Mirrors `clock` (ISO) so a test
|
|
101
133
|
* can advance wall time across a park/resume boundary without a real wait.
|
|
102
134
|
*/
|
|
103
|
-
export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, clock, businessDate, ceilingUsd, initialGap, nowMs, }: {
|
|
135
|
+
export function runFlow({ root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, nowMs, }: {
|
|
104
136
|
root: string;
|
|
105
137
|
name: string;
|
|
106
138
|
runId: string;
|
|
@@ -134,6 +166,7 @@ export function runFlow({ root, name, runId, sources, catalogue, modelStep, askS
|
|
|
134
166
|
bytes?: number;
|
|
135
167
|
}>;
|
|
136
168
|
primitives?: Record<string, any> | undefined;
|
|
169
|
+
primitiveReds?: string[] | undefined;
|
|
137
170
|
clock?: (() => string) | undefined;
|
|
138
171
|
businessDate: string;
|
|
139
172
|
ceilingUsd?: number | undefined;
|
|
@@ -165,12 +198,13 @@ export function makeParkingAskStep(): (opts?: any) => Promise<{
|
|
|
165
198
|
* @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
|
|
166
199
|
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
|
|
167
200
|
* @param {Record<string, any>} [opts.primitives]
|
|
201
|
+
* @param {string[]} [opts.primitiveReds] - see `runFlow`'s own.
|
|
168
202
|
* @param {() => string} [opts.clock]
|
|
169
203
|
* @param {string} opts.businessDate
|
|
170
204
|
* @param {number} [opts.ceilingUsd]
|
|
171
205
|
* @param {() => number} [opts.nowMs] - F45 finding 3; see `runFlow`'s own.
|
|
172
206
|
*/
|
|
173
|
-
export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, primitives, clock, businessDate, ceilingUsd, nowMs, }: {
|
|
207
|
+
export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, nowMs, }: {
|
|
174
208
|
root: string;
|
|
175
209
|
name: string;
|
|
176
210
|
runId: string;
|
|
@@ -184,11 +218,38 @@ export function resumeRun({ root, name, runId, catalogue, modelStep, sendStep, p
|
|
|
184
218
|
bytes?: number;
|
|
185
219
|
}>;
|
|
186
220
|
primitives?: Record<string, any> | undefined;
|
|
221
|
+
primitiveReds?: string[] | undefined;
|
|
187
222
|
clock?: (() => string) | undefined;
|
|
188
223
|
businessDate: string;
|
|
189
224
|
ceilingUsd?: number | undefined;
|
|
190
225
|
nowMs?: (() => number) | undefined;
|
|
191
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;
|
|
192
253
|
/** The strike governor — a run-owned constant, never raised by a caller,
|
|
193
254
|
* never carried in the arbiter block or the declaration (M2 scope item 5,
|
|
194
255
|
* signed 2026-09-24 "2A"). */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** stdin AND stdout must both be TTYs. */
|
|
2
|
+
export function isInteractive(stdin?: NodeJS.ReadStream & {
|
|
3
|
+
fd: 0;
|
|
4
|
+
}, stdout?: NodeJS.WriteStream & {
|
|
5
|
+
fd: 1;
|
|
6
|
+
}): boolean;
|
|
7
|
+
/** Show the flow name, read one line, compare exactly (trimmed). Empty answer / EOF / mismatch refuse by name. */
|
|
8
|
+
export function confirmTypedName({ name, input, output }: {
|
|
9
|
+
name: any;
|
|
10
|
+
input?: (NodeJS.ReadStream & {
|
|
11
|
+
fd: 0;
|
|
12
|
+
}) | undefined;
|
|
13
|
+
output?: (NodeJS.WriteStream & {
|
|
14
|
+
fd: 1;
|
|
15
|
+
}) | undefined;
|
|
16
|
+
}): Promise<any>;
|
|
17
|
+
export const NEEDS_TTY: "sign needs an interactive terminal \u2014 run it yourself";
|
|
18
|
+
export const NAME_MISMATCH: "typed name does not match";
|
package/types/signed-text.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M6a amendment 1: a NEW flow (draft, sign) may not carry an ask whose wait the human never typed. The
|
|
3
|
+
* parser still fills the legacy 30m default for `ask:` so flows signed before the amendment keep running;
|
|
4
|
+
* this names each ask that relies on it. Returns [] when every ask carries `ask <int><s|m|h>:`.
|
|
5
|
+
*
|
|
6
|
+
* @param {{ asks?: Array<{ line: number, ttlSigned?: boolean }> }} arbiter
|
|
7
|
+
* @returns {string[]}
|
|
8
|
+
*/
|
|
9
|
+
export function unsignedAskTtls(arbiter: {
|
|
10
|
+
asks?: Array<{
|
|
11
|
+
line: number;
|
|
12
|
+
ttlSigned?: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
}): string[];
|
|
1
15
|
/**
|
|
2
16
|
* Parse the human's signed text. Never throws — any input that isn't a
|
|
3
17
|
* usable signed text comes back as `{ ok: false, reds }`, never an
|
package/types/types.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export type AskSlot = {
|
|
|
23
23
|
* - the ask's time-to-live in milliseconds.
|
|
24
24
|
*/
|
|
25
25
|
ttlMs: number;
|
|
26
|
+
/**
|
|
27
|
+
* - true when the human typed the wait (`ask <int><s|m|h>:`); false on the legacy `ask:` 30m default, which draft and sign refuse (M6a amendment 1).
|
|
28
|
+
*/
|
|
29
|
+
ttlSigned?: boolean | undefined;
|
|
26
30
|
/**
|
|
27
31
|
* - the words after the mark, trimmed — the
|
|
28
32
|
* human's own question. Nothing reads this yet outside signed-text.js.
|
|
@@ -272,6 +276,11 @@ export type CloseVerdict = {
|
|
|
272
276
|
};
|
|
273
277
|
/**
|
|
274
278
|
* One row appended to `runs/<run-id>/audit.jsonl` (M2 scope item 9).
|
|
279
|
+
* `at`/`tokens` were added by Amendment M4a-2 and `tools`/`ungranted` by
|
|
280
|
+
* Amendment M4a-3 (docs/wiki/the-module-ladder.md, "M4a" section) — every
|
|
281
|
+
* row `appendAudit` writes from here on carries `at`/`tokens`/`tools`; a row
|
|
282
|
+
* written before its amendment simply lacks the newer keys (read back as-is,
|
|
283
|
+
* never backfilled) — see `auditRowTokens`/`auditRowTools` in `src/books.js`.
|
|
275
284
|
*/
|
|
276
285
|
export type AuditRow = {
|
|
277
286
|
step: string | null;
|
|
@@ -285,6 +294,42 @@ export type AuditRow = {
|
|
|
285
294
|
model: string | null;
|
|
286
295
|
modelMatch: boolean | null;
|
|
287
296
|
strike: boolean;
|
|
297
|
+
/**
|
|
298
|
+
* - ISO time this attempt finished.
|
|
299
|
+
*/
|
|
300
|
+
at: string;
|
|
301
|
+
/**
|
|
302
|
+
* -
|
|
303
|
+
* summed over this attempt's model calls; `null` only when `model` is
|
|
304
|
+
* `null` (no model call this row).
|
|
305
|
+
*/
|
|
306
|
+
tokens: {
|
|
307
|
+
inputTokens: number;
|
|
308
|
+
outputTokens: number;
|
|
309
|
+
cacheReadTokens: number;
|
|
310
|
+
} | null;
|
|
311
|
+
/**
|
|
312
|
+
* - a {toolName: count}
|
|
313
|
+
* tally of every GRANTED tool the model actually invoked this attempt,
|
|
314
|
+
* summed across every round; `{}` when the model called no tool; `null`
|
|
315
|
+
* only when `model` is `null` (no model call this row).
|
|
316
|
+
*/
|
|
317
|
+
tools: Record<string, number> | null;
|
|
318
|
+
/**
|
|
319
|
+
* - tool names the model called that this
|
|
320
|
+
* step never granted; absent when empty, never an invented empty array.
|
|
321
|
+
*/
|
|
322
|
+
ungranted?: string[] | undefined;
|
|
323
|
+
/**
|
|
324
|
+
* - bareguard
|
|
325
|
+
* fs-gate refusals during this attempt; `[]` (never omitted) on every row
|
|
326
|
+
* written by a model attempt, absent on rows with no model call.
|
|
327
|
+
*/
|
|
328
|
+
refused?: {
|
|
329
|
+
verb: string;
|
|
330
|
+
path: string;
|
|
331
|
+
rule: string;
|
|
332
|
+
}[] | undefined;
|
|
288
333
|
};
|
|
289
334
|
/**
|
|
290
335
|
* One row appended to `flows/<name>/history.jsonl` (M2 scope item 9).
|