fwdloop 0.11.0 → 0.13.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 +248 -27
- package/package.json +1 -1
- package/src/ask.js +3 -0
- package/src/authoring.js +103 -13
- package/src/books.js +23 -2
- package/src/canrun.js +36 -0
- package/src/config.js +256 -0
- package/src/declaration.js +72 -2
- package/src/drafter.js +53 -11
- package/src/draftspend.js +70 -0
- package/src/flow.js +43 -0
- package/src/keysfile.js +180 -0
- package/src/liveness.js +1 -1
- package/src/model-step.js +43 -8
- package/src/monthly.js +276 -0
- package/src/panel/author.js +482 -0
- package/src/panel/authorcard.js +297 -0
- package/src/panel/authorflows.js +312 -0
- package/src/panel/authorresume.js +149 -0
- package/src/panel/authorstart.js +257 -0
- package/src/panel/authorvalues.js +110 -0
- package/src/panel/data.js +228 -34
- package/src/panel/index.html +2073 -124
- package/src/panel/resume.js +14 -11
- package/src/panel/server.js +150 -117
- package/src/panel/settings.js +270 -0
- package/src/panel/spawn.js +77 -0
- package/src/provider.js +189 -43
- package/src/providershapes.js +19 -0
- package/src/runner.js +639 -85
- package/src/runvalues.js +178 -0
- package/src/send.js +10 -3
- package/src/setup.js +120 -0
- package/types/authoring.d.ts +24 -2
- package/types/books.d.ts +14 -2
- package/types/canrun.d.ts +32 -0
- package/types/config.d.ts +52 -0
- package/types/declaration.d.ts +9 -1
- package/types/drafter.d.ts +18 -2
- package/types/draftspend.d.ts +21 -0
- package/types/flow.d.ts +23 -0
- package/types/keysfile.d.ts +90 -0
- package/types/liveness.d.ts +2 -2
- package/types/model-step.d.ts +6 -2
- package/types/monthly.d.ts +130 -0
- package/types/panel/author.d.ts +335 -0
- package/types/panel/authorcard.d.ts +120 -0
- package/types/panel/authorflows.d.ts +175 -0
- package/types/panel/authorresume.d.ts +32 -0
- package/types/panel/authorstart.d.ts +115 -0
- package/types/panel/authorvalues.d.ts +62 -0
- package/types/panel/data.d.ts +103 -12
- package/types/panel/resume.d.ts +8 -1
- package/types/panel/server.d.ts +19 -33
- package/types/panel/settings.d.ts +23 -0
- package/types/panel/spawn.d.ts +30 -0
- package/types/provider.d.ts +123 -70
- package/types/providershapes.d.ts +11 -0
- package/types/runner.d.ts +120 -5
- package/types/runvalues.d.ts +97 -0
- package/types/send.d.ts +5 -1
- package/types/setup.d.ts +83 -0
package/types/panel/data.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export function readSavedAnswer(runDir: string): {
|
|
|
65
65
|
* @param {{savedAnswer: {askId:string, decision:string|null, answeredAt?:string|null}|null, attempt: any, ask?: any}} ctx
|
|
66
66
|
* @returns {{state: 'starting'|'not-started'|'broken'|'took-over', askId: string|null, tries: number|null, maxTries: number|null, reason: string|null, label: string}|null}
|
|
67
67
|
*/
|
|
68
|
-
export function deriveResumeState({ savedAnswer:
|
|
68
|
+
export function deriveResumeState({ savedAnswer: savedOnDisk, attempt, ask }: {
|
|
69
69
|
savedAnswer: {
|
|
70
70
|
askId: string;
|
|
71
71
|
decision: string | null;
|
|
@@ -143,6 +143,7 @@ export function glyphPulses(g: {
|
|
|
143
143
|
* `computeGlyph`, the derivation the M4a POC proved against every real run
|
|
144
144
|
* on disk. Ladder wording (M4a scope item 4):
|
|
145
145
|
* - `[✓]` passed — a history row with `outcome:'complete'`.
|
|
146
|
+
* - `[■]` stopped (M4e amendment 4) — a history row `stopped`, or `cap-halt` with a halt record to continue from.
|
|
146
147
|
* - `[✗]` failed — a history row with any other outcome (never `[?]`).
|
|
147
148
|
* - `[·]` waiting on you — parked (`ask.json` present), no consumed answer,
|
|
148
149
|
* NOT past its own `expiresAt`.
|
|
@@ -174,10 +175,10 @@ export function glyphPulses(g: {
|
|
|
174
175
|
* A saved answer with a live process is `[▶]` working on your answer.
|
|
175
176
|
* - `[?]` crashed after taking your answer (amendment 2 (f)) — the answer was
|
|
176
177
|
* consumed, the process is gone, no end row: cannot be carried on.
|
|
177
|
-
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string}} ctx
|
|
178
|
-
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]', label: string}}
|
|
178
|
+
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string, resumable?: boolean}} ctx
|
|
179
|
+
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]'|'[■]', label: string}}
|
|
179
180
|
*/
|
|
180
|
-
export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, }: {
|
|
181
|
+
export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, resumable, }: {
|
|
181
182
|
historyRow: any;
|
|
182
183
|
askJson: any;
|
|
183
184
|
consumedAnswerExists: boolean;
|
|
@@ -186,8 +187,9 @@ export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasSta
|
|
|
186
187
|
liveness?: "running" | "gone" | "unknown";
|
|
187
188
|
booksFresh?: boolean;
|
|
188
189
|
lock?: string;
|
|
190
|
+
resumable?: boolean;
|
|
189
191
|
}): {
|
|
190
|
-
glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[\u25B6]" | "[?]" | "[II]";
|
|
192
|
+
glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[\u25B6]" | "[?]" | "[II]" | "[\u25A0]";
|
|
191
193
|
label: string;
|
|
192
194
|
};
|
|
193
195
|
/**
|
|
@@ -327,20 +329,20 @@ export function deriveStepTryMarks(closeClass: string | null, rows: Array<{
|
|
|
327
329
|
}>): Array<"\u2713" | "\u2717" | "\u00B7">;
|
|
328
330
|
/**
|
|
329
331
|
* A step group's own state word for the Audit tab's collapsed header —
|
|
330
|
-
* the
|
|
331
|
-
*
|
|
332
|
-
* be computed server-side too, off the SAME last-row-wins logic): `waiting`
|
|
332
|
+
* the ONE decider of a step's state: the Run tab's map and cards read it too
|
|
333
|
+
* (`groupState` on each step; the page keeps no rule of its own), last-row-wins: `waiting`
|
|
333
334
|
* (the run is currently parked on this step — its last attempt's verdict is
|
|
334
335
|
* `paused`/`refused`), `done` (the last attempt passed — `green`/`hitl`),
|
|
335
|
-
* `stopped` (
|
|
336
|
+
* `user-stopped` (M4e amendment 10: the step's own last row is `stopped`, a Stop
|
|
337
|
+
* the human asked), `stopped` (the last attempt failed for any other reason). A group only
|
|
336
338
|
* ever exists for a step with at least one row, so `pending` never appears
|
|
337
339
|
* here (unlike the Run tab's map, which also covers never-attempted steps).
|
|
338
340
|
* @param {Array<{verdict:string}>} rows one step's own audit rows, book order
|
|
339
|
-
* @returns {'done'|'waiting'|'stopped'}
|
|
341
|
+
* @returns {'done'|'waiting'|'stopped'|'user-stopped'}
|
|
340
342
|
*/
|
|
341
343
|
export function deriveStepGroupState(rows: Array<{
|
|
342
344
|
verdict: string;
|
|
343
|
-
}>): "done" | "waiting" | "stopped";
|
|
345
|
+
}>): "done" | "waiting" | "stopped" | "user-stopped";
|
|
344
346
|
/**
|
|
345
347
|
* hamr's 2026-09-27 exit-check review #1: the Audit tab's grouped-by-step
|
|
346
348
|
* header pieces, computed HERE (server-side) so `src/panel/index.html` only
|
|
@@ -394,6 +396,44 @@ export function summarizeSpendRows(spendRows: any[]): {
|
|
|
394
396
|
cacheReadTokens: number | null;
|
|
395
397
|
cacheReadTokensWhy: string | null;
|
|
396
398
|
};
|
|
399
|
+
/**
|
|
400
|
+
* M4e amendment 4 item 4: the ONE decision for the Run tab's Stop and Resume buttons (the Stop and Resume doors read the
|
|
401
|
+
* same object, so the page never offers what the door would refuse). `running` is the glyph's own rule (`isRunningNow`);
|
|
402
|
+
* a run with no process record yet is `starting`; a parked run (`[·]`/`[!]`, an open ask) is neither.
|
|
403
|
+
* @param {any} ctx `loadRunContext`'s result @param {string} glyph `computeGlyph`'s sign
|
|
404
|
+
* @returns {{canStop: boolean, atAsk: boolean, stopRequested: boolean, starting: boolean, canResume: boolean, resumeOutcome: string|null, spentUsd: number|null, spendComplete: boolean|null, capUsd: number|null}}
|
|
405
|
+
*/
|
|
406
|
+
export function runControls(ctx: any, glyph: string, label?: string): {
|
|
407
|
+
canStop: boolean;
|
|
408
|
+
atAsk: boolean;
|
|
409
|
+
stopRequested: boolean;
|
|
410
|
+
starting: boolean;
|
|
411
|
+
canResume: boolean;
|
|
412
|
+
resumeOutcome: string | null;
|
|
413
|
+
spentUsd: number | null;
|
|
414
|
+
spendComplete: boolean | null;
|
|
415
|
+
capUsd: number | null;
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* `runControls` for one run read straight from the books (the Stop door's own read). `null` when the run does not resolve.
|
|
419
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
420
|
+
*/
|
|
421
|
+
export function getRunControls({ root, flow, runId, catalogue, }: {
|
|
422
|
+
root: string;
|
|
423
|
+
flow: string;
|
|
424
|
+
runId: string;
|
|
425
|
+
catalogue: any;
|
|
426
|
+
}): {
|
|
427
|
+
canStop: boolean;
|
|
428
|
+
atAsk: boolean;
|
|
429
|
+
stopRequested: boolean;
|
|
430
|
+
starting: boolean;
|
|
431
|
+
canResume: boolean;
|
|
432
|
+
resumeOutcome: string | null;
|
|
433
|
+
spentUsd: number | null;
|
|
434
|
+
spendComplete: boolean | null;
|
|
435
|
+
capUsd: number | null;
|
|
436
|
+
} | null;
|
|
397
437
|
/**
|
|
398
438
|
* `GET /api/runs` — every flow under `root`, every run under each flow
|
|
399
439
|
* (M4a scope item 2). A flow with zero runs still gets one row (`runId:
|
|
@@ -439,6 +479,54 @@ export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, }: {
|
|
|
439
479
|
catalogue: any;
|
|
440
480
|
resumeAttempt?: (flow: string, runId: string) => any;
|
|
441
481
|
}): any | null;
|
|
482
|
+
/**
|
|
483
|
+
* What the Draft adds up to, ONE place (the Map box, the first step card and the Audit group all read it, so the three can never disagree).
|
|
484
|
+
* M4e amendment 9: `timeMs` is the card row's `at` to the sign row's `at` (the whole drafting, human time included), `null` when either has no
|
|
485
|
+
* usable `at`; never a sum of the model rows' `wallMs`. `calls` sums the rows' `calls`, a row with none counts 1 and sets `callsAtLeast`, so an
|
|
486
|
+
* unknown never shows as a smaller exact number; no model rows = `null`. `humanChecks` = the note rows + the sign row + the run's signed-values
|
|
487
|
+
* rows (the card is not a check), given by the caller as `ctx.humanChecks`. Money follows `costDisplay` ("at least $X" for a floor).
|
|
488
|
+
* @param {any[]} modelRows the draft and change rows (`kind` draft | change) of `setup.jsonl`
|
|
489
|
+
* @param {{cardAt?: any, signAt?: any, humanChecks?: number|null}} [ctx]
|
|
490
|
+
* @returns {{calls: number|null, callsAtLeast: boolean, timeMs: number|null, humanChecks: number|null, usd: number|null, spendComplete: boolean, cost: string|null, modelRows: number}}
|
|
491
|
+
*/
|
|
492
|
+
export function draftTotals(modelRows: any[], ctx?: {
|
|
493
|
+
cardAt?: any;
|
|
494
|
+
signAt?: any;
|
|
495
|
+
humanChecks?: number | null;
|
|
496
|
+
}): {
|
|
497
|
+
calls: number | null;
|
|
498
|
+
callsAtLeast: boolean;
|
|
499
|
+
timeMs: number | null;
|
|
500
|
+
humanChecks: number | null;
|
|
501
|
+
usd: number | null;
|
|
502
|
+
spendComplete: boolean;
|
|
503
|
+
cost: string | null;
|
|
504
|
+
modelRows: number;
|
|
505
|
+
};
|
|
506
|
+
/**
|
|
507
|
+
* M4e amendment 6 item 4 / amendment 7 item 2: the Draft of a run — the flow's own `setup.jsonl` (card, drafts, changes, notes, sign), then this
|
|
508
|
+
* run's own signed-values rows (amendment 5: "Sign & run" for version 0, "Sign & resume" for a later version), every row in the SAME shape
|
|
509
|
+
* as the run's audit rows so the page draws both with one row builder. Reads only through the safe gateways; never throws.
|
|
510
|
+
* @param {string} flowDir @param {string} runDir
|
|
511
|
+
* @returns {{present: boolean, why: string|null, rows: any[], summary: {present: boolean, why?: string, calls?: number|null, callsAtLeast?: boolean, humanChecks?: number|null, timeMs?: number|null, usd?: number|null, spendComplete?: boolean, cost?: string|null, modelRows?: number}}}
|
|
512
|
+
*/
|
|
513
|
+
export function getDraftBlock(flowDir: string, runDir: string): {
|
|
514
|
+
present: boolean;
|
|
515
|
+
why: string | null;
|
|
516
|
+
rows: any[];
|
|
517
|
+
summary: {
|
|
518
|
+
present: boolean;
|
|
519
|
+
why?: string;
|
|
520
|
+
calls?: number | null;
|
|
521
|
+
callsAtLeast?: boolean;
|
|
522
|
+
humanChecks?: number | null;
|
|
523
|
+
timeMs?: number | null;
|
|
524
|
+
usd?: number | null;
|
|
525
|
+
spendComplete?: boolean;
|
|
526
|
+
cost?: string | null;
|
|
527
|
+
modelRows?: number;
|
|
528
|
+
};
|
|
529
|
+
};
|
|
442
530
|
/**
|
|
443
531
|
* `GET /api/runs/:flow/:runId/audit` — the Audit/logs tab (M4a scope item
|
|
444
532
|
* 2): the raw `audit.jsonl` rows, scoped strictly to this run (each run's
|
|
@@ -446,7 +534,7 @@ export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, }: {
|
|
|
446
534
|
* shared-sidecar contamination risk here the way bareloop's gate-audit
|
|
447
535
|
* sidecar had). `null` when the flow/runId doesn't resolve (404).
|
|
448
536
|
* @param {{root: string, flow: string, runId: string}} opts
|
|
449
|
-
* @returns {{flow:string, runId:string, rows:any[], groups:any[], empty:boolean, why:string|null}|null}
|
|
537
|
+
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, empty:boolean, why:string|null}|null}
|
|
450
538
|
*/
|
|
451
539
|
export function getRunAudit({ root, flow, runId }: {
|
|
452
540
|
root: string;
|
|
@@ -457,6 +545,7 @@ export function getRunAudit({ root, flow, runId }: {
|
|
|
457
545
|
runId: string;
|
|
458
546
|
rows: any[];
|
|
459
547
|
groups: any[];
|
|
548
|
+
draft: ReturnType<typeof getDraftBlock>;
|
|
460
549
|
empty: boolean;
|
|
461
550
|
why: string | null;
|
|
462
551
|
} | null;
|
|
@@ -672,3 +761,5 @@ export const STUCK_REASONS: {
|
|
|
672
761
|
why: string;
|
|
673
762
|
};
|
|
674
763
|
};
|
|
764
|
+
/** The words the Draft says for a flow with no `setup.jsonl` (M4e amendment 6 item 4; renamed Draft by amendment 7 item 2). */
|
|
765
|
+
export const NO_DRAFT_WORDS: "no draft record";
|
package/types/panel/resume.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {{ root: string, env?: Record<string, string|undefined>, bin?: string, logDir?: string,
|
|
2
|
+
* @param {{ root: string, env?: Record<string, string|undefined>, loadEnv?: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, bin?: string, logDir?: string,
|
|
3
3
|
* maxTries?: number, windowMs?: number, slotMs?: number }} opts
|
|
4
|
+
* `loadEnv` (M4d: the keys-file door, called before EVERY spawn so editing the file needs no panel restart) returns the merged env
|
|
5
|
+
* that is BOTH the child's spawn env AND its scrub list, or a refusal sentence that becomes the attempt's refusal (nothing spawns).
|
|
4
6
|
* `env`/`bin`/`logDir`/`maxTries`/`windowMs`/`slotMs` are injectable so tests neither sleep 10 s
|
|
5
7
|
* nor need a live key; production passes none of them. `slotMs` (default `windowMs / maxTries`,
|
|
6
8
|
* i.e. 2000 ms) is only the spacing between tries: a test sets it small and `windowMs` (the
|
|
@@ -10,6 +12,11 @@
|
|
|
10
12
|
export function createResumer(opts: {
|
|
11
13
|
root: string;
|
|
12
14
|
env?: Record<string, string | undefined>;
|
|
15
|
+
loadEnv?: () => {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
env: Record<string, string | undefined>;
|
|
18
|
+
refusal: string | null;
|
|
19
|
+
};
|
|
13
20
|
bin?: string;
|
|
14
21
|
logDir?: string;
|
|
15
22
|
maxTries?: number;
|
package/types/panel/server.d.ts
CHANGED
|
@@ -1,42 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hamr's 2026-10-03 ruling "1A": the panel token is REUSED across restarts, so a bookmark of
|
|
3
|
-
* `http://127.0.0.1:<port>/` keeps working once the link was opened. Reads the token file (same path
|
|
4
|
-
* `writeTokenFile` writes); a new token only when the file is missing, unreadable, not a regular file,
|
|
5
|
-
* not mode 0600, not ours, or not 64 hex chars (the caller then rewrites it 0600).
|
|
6
|
-
* @param {{ port: number, dir?: string, env?: Record<string, string|undefined> }} a
|
|
7
|
-
* @returns {string}
|
|
8
|
-
*/
|
|
9
|
-
export function loadOrMakeToken({ port, dir, env }: {
|
|
10
|
-
port: number;
|
|
11
|
-
dir?: string;
|
|
12
|
-
env?: Record<string, string | undefined>;
|
|
13
|
-
}): string;
|
|
14
|
-
/**
|
|
15
|
-
* M4c-fix item 2: the token's one on-disk home — `<dir>/panel-<port>.token`, dir 0700, file 0600,
|
|
16
|
-
* `dir` = `$XDG_RUNTIME_DIR/fwdloop`, else `~/.cache/fwdloop`. Refuses a dir that is a symlink or
|
|
17
|
-
* not ours. The file is replaced (unlink, then exclusive create at 0600), never rewritten in place,
|
|
18
|
-
* so it never exists with a looser mode. Returns the file's path.
|
|
19
|
-
* @param {{ port: number, token: string, dir?: string, env?: Record<string, string|undefined> }} a
|
|
20
|
-
*/
|
|
21
|
-
export function writeTokenFile({ port, token, dir, env, }: {
|
|
22
|
-
port: number;
|
|
23
|
-
token: string;
|
|
24
|
-
dir?: string;
|
|
25
|
-
env?: Record<string, string | undefined>;
|
|
26
|
-
}): string;
|
|
27
1
|
/**
|
|
28
2
|
* Handle one request against the API + the page. Exported
|
|
29
3
|
* separately from {@link createPanelServer} so tests can drive it without a
|
|
30
4
|
* real listening socket where that is simpler.
|
|
31
5
|
* @param {import('node:http').IncomingMessage} req
|
|
32
6
|
* @param {import('node:http').ServerResponse} res
|
|
33
|
-
* @param {{ root: string, port: number,
|
|
7
|
+
* @param {{ root: string, port: number, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor> }} opts
|
|
34
8
|
*/
|
|
35
9
|
export function handleRequest(req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse, opts: {
|
|
36
10
|
root: string;
|
|
37
11
|
port: number;
|
|
38
|
-
token: string;
|
|
39
12
|
resumer: ReturnType<typeof createResumer>;
|
|
13
|
+
settings: ReturnType<typeof createSettings>;
|
|
14
|
+
author: ReturnType<typeof createAuthor>;
|
|
40
15
|
}): void;
|
|
41
16
|
/**
|
|
42
17
|
* Start the panel server. Binds `127.0.0.1` ONLY. A taken port is a LOUD,
|
|
@@ -44,14 +19,19 @@ export function handleRequest(req: import("node:http").IncomingMessage, res: imp
|
|
|
44
19
|
* header). Resolves once actually listening; rejects on a bind error
|
|
45
20
|
* (including `EADDRINUSE`) with a `.port` field on the error for the
|
|
46
21
|
* caller's message.
|
|
47
|
-
* @param {{ port?: number, root: string,
|
|
48
|
-
* `resume`
|
|
49
|
-
* @returns {Promise<{ server: import('node:http').Server, port: number,
|
|
22
|
+
* @param {{ port?: number, root: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string } }} opts
|
|
23
|
+
* `resume` and `author` are for tests only (a fake env/bin, a short retry window); the CLI passes none.
|
|
24
|
+
* @returns {Promise<{ server: import('node:http').Server, port: number, close: () => Promise<void> }>}
|
|
50
25
|
*/
|
|
51
26
|
export function createPanelServer(opts: {
|
|
52
27
|
port?: number;
|
|
53
28
|
root: string;
|
|
54
|
-
|
|
29
|
+
settings?: {
|
|
30
|
+
home?: string;
|
|
31
|
+
env?: Record<string, string | undefined>;
|
|
32
|
+
fetch?: typeof fetch;
|
|
33
|
+
now?: () => number;
|
|
34
|
+
};
|
|
55
35
|
resume?: {
|
|
56
36
|
env?: Record<string, string | undefined>;
|
|
57
37
|
bin?: string;
|
|
@@ -60,10 +40,14 @@ export function createPanelServer(opts: {
|
|
|
60
40
|
windowMs?: number;
|
|
61
41
|
slotMs?: number;
|
|
62
42
|
};
|
|
43
|
+
author?: {
|
|
44
|
+
env?: Record<string, string | undefined>;
|
|
45
|
+
loadEnv?: () => any;
|
|
46
|
+
bin?: string;
|
|
47
|
+
};
|
|
63
48
|
}): Promise<{
|
|
64
49
|
server: import("node:http").Server;
|
|
65
50
|
port: number;
|
|
66
|
-
token: string;
|
|
67
51
|
close: () => Promise<void>;
|
|
68
52
|
}>;
|
|
69
53
|
/**
|
|
@@ -83,3 +67,5 @@ export function panelMain(argv: string[], ctx: {
|
|
|
83
67
|
* side by side. */
|
|
84
68
|
export const DEFAULT_PORT: 4800;
|
|
85
69
|
import { createResumer } from './resume.js';
|
|
70
|
+
import { createSettings } from './settings.js';
|
|
71
|
+
import { createAuthor } from './author.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ home?: string, skip?: boolean, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number }} cfg
|
|
3
|
+
* `home` the config home (undefined = the real `~/.config/fwdloop`); `skip` true under a test process
|
|
4
|
+
* with no `FWDLOOP_CONFIG_HOME` (Settings then touches nothing); `env` the shell side (tests only);
|
|
5
|
+
* `fetch` and `now` are test seams.
|
|
6
|
+
*/
|
|
7
|
+
export function createSettings(cfg: {
|
|
8
|
+
home?: string;
|
|
9
|
+
skip?: boolean;
|
|
10
|
+
env?: Record<string, string | undefined>;
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
now?: () => number;
|
|
13
|
+
}): {
|
|
14
|
+
handle: ({ method, pathname, query, body }: {
|
|
15
|
+
method: string;
|
|
16
|
+
pathname: string;
|
|
17
|
+
query: URLSearchParams;
|
|
18
|
+
body: any;
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
status: number;
|
|
21
|
+
body: any;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ bin: string, argv: string[], env: Record<string, string|undefined>, logPath: string }} a
|
|
3
|
+
* @returns {import('node:child_process').ChildProcess} the child (already `unref()`ed; the log fd is closed here)
|
|
4
|
+
*/
|
|
5
|
+
export function spawnDetached({ bin, argv, env, logPath, }: {
|
|
6
|
+
bin: string;
|
|
7
|
+
argv: string[];
|
|
8
|
+
env: Record<string, string | undefined>;
|
|
9
|
+
logPath: string;
|
|
10
|
+
}): import("node:child_process").ChildProcess;
|
|
11
|
+
/**
|
|
12
|
+
* The ONE writer of a panel child's `pid.json` (`<dir>/pid.json`): the pid, its /proc starttime and when it was started.
|
|
13
|
+
* Called right after the spawn by the draft door and the start door. A child with no pid writes nothing.
|
|
14
|
+
* @param {string} dir @param {import('node:child_process').ChildProcess} child
|
|
15
|
+
*/
|
|
16
|
+
export function writePidFile(dir: string, child: import("node:child_process").ChildProcess): void;
|
|
17
|
+
/** One JSON file of a panel folder through the one safe gateway; null when missing, unreadable or not an object. @param {string} dir @param {string} rel */
|
|
18
|
+
export function readJsonFile(dir: string, rel: string): any;
|
|
19
|
+
/**
|
|
20
|
+
* Is the child recorded in `<dir>/pid.json` running? true / false, never null: no pid.json = nothing known to be running =
|
|
21
|
+
* false; a liveness that cannot be told (no /proc) reads as running only while pid.json is fresh (M4c's rule).
|
|
22
|
+
* @param {string} dir
|
|
23
|
+
*/
|
|
24
|
+
export function childRunning(dir: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The provider key VALUES in the merged env — the scrub list. The env that holds them is the SAME object that is the child's
|
|
27
|
+
* spawn env (POC (a), M4d wiring rule), so the list can never differ from what the child was given.
|
|
28
|
+
* @param {Record<string, string|undefined>} env
|
|
29
|
+
*/
|
|
30
|
+
export function providerKeys(env: Record<string, string | undefined>): string[];
|
package/types/provider.d.ts
CHANGED
|
@@ -1,70 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE one lookup of a slot's model, API shape and address (M4d amendment 1). Every model call (run,
|
|
3
|
+
* resume, model step, drafter), Test, Balance and the spend rows read the slot through this and nothing
|
|
4
|
+
* else: a value saved on the Settings page (`config.providers[slot]`) wins per field, else the code
|
|
5
|
+
* default above. A blank saved Base URL means the default FOR THE EFFECTIVE SHAPE: the slot's own code
|
|
6
|
+
* address while the shape is the slot's code shape, else that shape's vendor address ('' = bare-agent's own).
|
|
7
|
+
* Unknown slot throws. `config` is already-read config (see `readPriceConfig`); no I/O here.
|
|
8
|
+
* @param {string} slotName
|
|
9
|
+
* @param {{ config?: Record<string, any> }} [opts]
|
|
10
|
+
* @returns {{ slot: string, envVar: string, legacyMaxTokens: boolean,
|
|
11
|
+
* model: string, shape: string, baseUrl: string,
|
|
12
|
+
* defaults: { model: string, shape: string, baseUrl: string } }}
|
|
13
|
+
*/
|
|
14
|
+
export function resolveSlot(slotName: string, { config }?: {
|
|
15
|
+
config?: Record<string, any>;
|
|
16
|
+
}): {
|
|
17
|
+
slot: string;
|
|
18
|
+
envVar: string;
|
|
19
|
+
legacyMaxTokens: boolean;
|
|
20
|
+
model: string;
|
|
21
|
+
shape: string;
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
defaults: {
|
|
24
|
+
model: string;
|
|
25
|
+
shape: string;
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
1
29
|
/**
|
|
2
30
|
* Strip an `hf:` routing prefix and look up `suffix` with `Object.hasOwn` —
|
|
3
31
|
* never plain truthiness/`in`, which would let a suffix like `"constructor"`
|
|
4
32
|
* resolve to an inherited `Object.prototype` member.
|
|
33
|
+
* @param {string|null|undefined} modelId
|
|
34
|
+
* @param {Record<string, any>} [ratesTable]
|
|
5
35
|
*/
|
|
6
|
-
export function lookupRate(modelId:
|
|
7
|
-
'zai-org/GLM-5.2': {
|
|
8
|
-
in: number;
|
|
9
|
-
out: number;
|
|
10
|
-
source: string;
|
|
11
|
-
};
|
|
12
|
-
'moonshotai/Kimi-K3': {
|
|
13
|
-
in: number;
|
|
14
|
-
out: number;
|
|
15
|
-
source: string;
|
|
16
|
-
};
|
|
17
|
-
'zai-org/GLM-5.3-Flash': {
|
|
18
|
-
in: number;
|
|
19
|
-
out: number;
|
|
20
|
-
source: string;
|
|
21
|
-
};
|
|
22
|
-
'zai-org/GLM-4.7-Flash': {
|
|
23
|
-
in: number;
|
|
24
|
-
out: number;
|
|
25
|
-
source: string;
|
|
26
|
-
};
|
|
27
|
-
'Qwen/Qwen3.8-27B': {
|
|
28
|
-
in: number;
|
|
29
|
-
out: number;
|
|
30
|
-
source: string;
|
|
31
|
-
};
|
|
32
|
-
'openai/gpt-oss-120b': {
|
|
33
|
-
in: number;
|
|
34
|
-
out: number;
|
|
35
|
-
source: string;
|
|
36
|
-
};
|
|
37
|
-
'nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-NVFP4': {
|
|
38
|
-
in: number;
|
|
39
|
-
out: number;
|
|
40
|
-
source: string;
|
|
41
|
-
};
|
|
42
|
-
'syn:large:text': {
|
|
43
|
-
in: number;
|
|
44
|
-
out: number;
|
|
45
|
-
source: string;
|
|
46
|
-
};
|
|
47
|
-
'syn:small:text': {
|
|
48
|
-
in: number;
|
|
49
|
-
out: number;
|
|
50
|
-
source: string;
|
|
51
|
-
};
|
|
52
|
-
'deepseek-v4-flash': {
|
|
53
|
-
in: number;
|
|
54
|
-
out: number;
|
|
55
|
-
source: string;
|
|
56
|
-
};
|
|
57
|
-
'deepseek-flash': {
|
|
58
|
-
in: number;
|
|
59
|
-
out: number;
|
|
60
|
-
source: string;
|
|
61
|
-
};
|
|
62
|
-
'deepseek-v4-pro': {
|
|
63
|
-
in: number;
|
|
64
|
-
out: number;
|
|
65
|
-
source: string;
|
|
66
|
-
};
|
|
67
|
-
}): {
|
|
36
|
+
export function lookupRate(modelId: string | null | undefined, ratesTable?: Record<string, any>): {
|
|
68
37
|
suffix: string;
|
|
69
38
|
rates: any;
|
|
70
39
|
} | null;
|
|
@@ -135,10 +104,71 @@ export function resolveModelRate(modelId: any, ratesTable?: {
|
|
|
135
104
|
suffix: string;
|
|
136
105
|
rates: any;
|
|
137
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* THE one price lookup (M4d scope item 6): every model call — run, resume, model step, drafter —
|
|
109
|
+
* is booked and cap-checked from this. Per field: a Settings price (`config.prices[slot]`, USD per
|
|
110
|
+
* 1M -> per 1K) wins, else the code table's row, else the table's HIGHEST entry for that field
|
|
111
|
+
* (an unknown model; unknown cost is never 0). M4d amendment 2: cached input is priced AS input —
|
|
112
|
+
* `cacheReadMult` is always 1; a saved `cachedInPerM` and a row's `cacheIn` are never read here.
|
|
113
|
+
*
|
|
114
|
+
* @param {string} modelId
|
|
115
|
+
* @param {{ slot?: string, config?: Record<string, any>, ratesTable?: Record<string, any> }} [opts]
|
|
116
|
+
* @returns {{
|
|
117
|
+
* rates: { in: number, out: number, cacheReadMult?: number },
|
|
118
|
+
* perM: { inPerM: number, cachedInPerM: number, outPerM: number },
|
|
119
|
+
* source: { in: 'settings'|'table'|'ceiling', cachedIn: 'input', out: 'settings'|'table'|'ceiling' },
|
|
120
|
+
* suffix: string|null,
|
|
121
|
+
* }}
|
|
122
|
+
*/
|
|
123
|
+
export function resolvePrices(modelId: string, { slot, config, ratesTable }?: {
|
|
124
|
+
slot?: string;
|
|
125
|
+
config?: Record<string, any>;
|
|
126
|
+
ratesTable?: Record<string, any>;
|
|
127
|
+
}): {
|
|
128
|
+
rates: {
|
|
129
|
+
in: number;
|
|
130
|
+
out: number;
|
|
131
|
+
cacheReadMult?: number;
|
|
132
|
+
};
|
|
133
|
+
perM: {
|
|
134
|
+
inPerM: number;
|
|
135
|
+
cachedInPerM: number;
|
|
136
|
+
outPerM: number;
|
|
137
|
+
};
|
|
138
|
+
source: {
|
|
139
|
+
in: "settings" | "table" | "ceiling";
|
|
140
|
+
cachedIn: "input";
|
|
141
|
+
out: "settings" | "table" | "ceiling";
|
|
142
|
+
};
|
|
143
|
+
suffix: string | null;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* The `price` object a spend row records: the per-1M numbers the call was booked at and where each
|
|
147
|
+
* came from. From a `resolvePrices` result; or from INJECTED rates (tests) with source "injected".
|
|
148
|
+
* @param {{ perM: any, source: any }|null|undefined} prices
|
|
149
|
+
* @param {{ in: number, out: number, cacheReadMult?: number }|null|undefined} [injectedRates]
|
|
150
|
+
*/
|
|
151
|
+
export function priceRecord(prices: {
|
|
152
|
+
perM: any;
|
|
153
|
+
source: any;
|
|
154
|
+
} | null | undefined, injectedRates?: {
|
|
155
|
+
in: number;
|
|
156
|
+
out: number;
|
|
157
|
+
cacheReadMult?: number;
|
|
158
|
+
} | null | undefined): any;
|
|
159
|
+
/**
|
|
160
|
+
* The config a model call is priced against, read at the door: `{}` when no config applies
|
|
161
|
+
* (a test process with no `FWDLOOP_CONFIG_HOME`), else the validated `config.json`. A broken
|
|
162
|
+
* config THROWS (ConfigError) — a run's charge never changes silently.
|
|
163
|
+
* @param {string} [home] explicit config home (a test); default: the door's home
|
|
164
|
+
*/
|
|
165
|
+
export function readPriceConfig(home?: string): Record<string, any>;
|
|
138
166
|
/**
|
|
139
167
|
* The ceiling cost (USD) of one round of `modelId` — never 0, never null.
|
|
140
168
|
* A known model prices at its own rate; an unknown/missing model prices at
|
|
141
|
-
* the HIGHEST in/out rate anywhere in `ratesTable`.
|
|
169
|
+
* the HIGHEST in/out rate anywhere in `ratesTable`. `opts.prices` (a
|
|
170
|
+
* `resolvePrices` result, e.g. from `makeProvider`) makes the cap check use the
|
|
171
|
+
* SAME price the round is booked at.
|
|
142
172
|
*/
|
|
143
173
|
export function ceilingCostUsd(modelId: any, ratesTable?: {
|
|
144
174
|
'zai-org/GLM-5.2': {
|
|
@@ -201,7 +231,7 @@ export function ceilingCostUsd(modelId: any, ratesTable?: {
|
|
|
201
231
|
out: number;
|
|
202
232
|
source: string;
|
|
203
233
|
};
|
|
204
|
-
}): number;
|
|
234
|
+
}, opts?: {}): number;
|
|
205
235
|
/**
|
|
206
236
|
* Compare the model asked for against the model actually served.
|
|
207
237
|
* `match` identical; `prefix` identical once a routing prefix is stripped;
|
|
@@ -238,6 +268,17 @@ export function sumMeterings(events: any): {
|
|
|
238
268
|
/** Append one spend row, stamping `modelMatch` — the one writer for
|
|
239
269
|
* spend.jsonl. Warns (never throws) on a `substituted` model. */
|
|
240
270
|
export function appendSpendRow(path: any, row: any): void;
|
|
271
|
+
/**
|
|
272
|
+
* The one rule for what a spend row costs: `usd` and whether it is `complete`. An incomplete row (a call
|
|
273
|
+
* died unmetered, or a round was left unpriced) counts its priced floor PLUS one ceiling per unmetered call
|
|
274
|
+
* (unknown cost is never 0). Same shape as poc/m6a/batch.mjs rowCostUsd.
|
|
275
|
+
* @param {any} row
|
|
276
|
+
* @returns {{usd: number, complete: boolean}}
|
|
277
|
+
*/
|
|
278
|
+
export function spendRowCost(row: any): {
|
|
279
|
+
usd: number;
|
|
280
|
+
complete: boolean;
|
|
281
|
+
};
|
|
241
282
|
/**
|
|
242
283
|
* `appendSpendRow`'s own sibling reader (M4a piece 2, docs/wiki/the-module-
|
|
243
284
|
* ladder.md M4a scope item 2: "one reader per book") — every row as written,
|
|
@@ -281,24 +322,30 @@ export function checkKeyPreflight(slotName: string, env?: Record<string, string
|
|
|
281
322
|
* values this project uses.
|
|
282
323
|
*
|
|
283
324
|
* @param {string} slotName
|
|
284
|
-
* @param {{ model?: string, timeoutMs?: number, deadlineMs?: number, thinking?: object|null }} [options]
|
|
325
|
+
* @param {{ model?: string, timeoutMs?: number, deadlineMs?: number, thinking?: object|null, env?: Record<string,string|undefined>, configHome?: string }} [options]
|
|
326
|
+
* `configHome` (a test) is where `config.json` prices are read; default: the door's home (`readPriceConfig`).
|
|
327
|
+
* `env` (M4d: the merged shell+keys-file env; default process.env) is where the key is read.
|
|
285
328
|
* `thinking` (bare-agent >=0.49) is sent verbatim as body.thinking; unset/null leaves the body unchanged.
|
|
286
|
-
* @returns {{ provider: any, rates: {in:number, out:number}, modelId: string, suffix: string, slot: string }}
|
|
329
|
+
* @returns {{ provider: any, rates: {in:number, out:number, cacheReadMult?:number}, modelId: string, suffix: string|null, slot: string, prices: ReturnType<typeof resolvePrices> }}
|
|
287
330
|
*/
|
|
288
331
|
export function makeProvider(slotName: string, options?: {
|
|
289
332
|
model?: string;
|
|
290
333
|
timeoutMs?: number;
|
|
291
334
|
deadlineMs?: number;
|
|
292
335
|
thinking?: object | null;
|
|
336
|
+
env?: Record<string, string | undefined>;
|
|
337
|
+
configHome?: string;
|
|
293
338
|
}): {
|
|
294
339
|
provider: any;
|
|
295
340
|
rates: {
|
|
296
341
|
in: number;
|
|
297
342
|
out: number;
|
|
343
|
+
cacheReadMult?: number;
|
|
298
344
|
};
|
|
299
345
|
modelId: string;
|
|
300
|
-
suffix: string;
|
|
346
|
+
suffix: string | null;
|
|
301
347
|
slot: string;
|
|
348
|
+
prices: ReturnType<typeof resolvePrices>;
|
|
302
349
|
};
|
|
303
350
|
/** Provider slots. Frozen — add a new slot here, never inline a baseUrl/env
|
|
304
351
|
* var elsewhere. `deepseek` is the baseline (F12); `synthetic` is second. */
|
|
@@ -307,20 +354,26 @@ export const PROVIDER_SLOTS: Readonly<{
|
|
|
307
354
|
baseUrl: "https://api.synthetic.new/openai/v1";
|
|
308
355
|
envVar: "SYNTHETIC_API_KEY";
|
|
309
356
|
defaultModel: "hf:Qwen/Qwen3.8-27B";
|
|
357
|
+
shape: "openai-api";
|
|
310
358
|
legacyMaxTokens: false;
|
|
311
359
|
}>;
|
|
312
360
|
deepseek: Readonly<{
|
|
313
361
|
baseUrl: "https://api.deepseek.com";
|
|
314
362
|
envVar: "DEEPSEEK_API_KEY";
|
|
315
363
|
defaultModel: "deepseek-flash";
|
|
364
|
+
shape: "openai-api";
|
|
316
365
|
legacyMaxTokens: true;
|
|
317
366
|
}>;
|
|
318
367
|
}>;
|
|
319
368
|
/**
|
|
320
369
|
* List-rate ceilings (USD/1K tokens), hand-entered — see
|
|
321
|
-
* poc/m0/spend.mjs@76a3607 for sourcing notes per row.
|
|
322
|
-
*
|
|
323
|
-
*
|
|
370
|
+
* poc/m0/spend.mjs@76a3607 for sourcing notes per row. This table is the DEFAULT
|
|
371
|
+
* price: a price set in Settings (`~/.config/fwdloop/config.json` `prices`, per
|
|
372
|
+
* provider slot) wins over a row here, per field, through `resolvePrices` below —
|
|
373
|
+
* the one lookup every model call is booked and cap-checked by (M4d, signed
|
|
374
|
+
* 2026-10-05; that REPLACES the 2026-09-21 "edit a row here, never a runtime
|
|
375
|
+
* flag" ruling). Cached input is priced as input
|
|
376
|
+
* (M4d amendment 2): a row has no cache rate.
|
|
324
377
|
*/
|
|
325
378
|
export const RATES_BY_SUFFIX: {
|
|
326
379
|
'zai-org/GLM-5.2': {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `id` is the value saved in config.json; `defaultUrl` is the host a blank Base URL means for a slot
|
|
3
|
+
* that has no code default of its own on this shape ('' = bare-agent's own default for that vendor).
|
|
4
|
+
* @type {readonly {id: string, label: string, defaultUrl: string}[]}
|
|
5
|
+
*/
|
|
6
|
+
export const SHAPES: readonly {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
defaultUrl: string;
|
|
10
|
+
}[];
|
|
11
|
+
export const SHAPE_IDS: readonly string[];
|