fwdloop 0.12.0 → 0.14.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 +155 -27
- package/package.json +2 -2
- package/src/ask.js +3 -0
- package/src/authoring.js +135 -16
- package/src/books.js +23 -2
- package/src/canrun.js +106 -0
- package/src/catalogue.json +2 -2
- package/src/checked.js +50 -0
- package/src/closers.js +112 -91
- package/src/config.js +2 -1
- package/src/declaration.js +175 -3
- package/src/drafter.js +148 -10
- package/src/draftspend.js +70 -0
- package/src/flow.js +43 -0
- package/src/keysfile.js +4 -2
- package/src/liveness.js +1 -1
- package/src/model-step.js +31 -5
- package/src/monthly.js +195 -28
- package/src/panel/author.js +638 -0
- package/src/panel/authorcard.js +340 -0
- package/src/panel/authorflows.js +317 -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 +318 -99
- package/src/panel/index.html +2000 -330
- package/src/panel/resume.js +6 -8
- package/src/panel/server.js +122 -119
- package/src/panel/settings.js +8 -6
- package/src/panel/spawn.js +77 -0
- package/src/provider.js +12 -17
- package/src/runner.js +707 -104
- package/src/runvalues.js +178 -0
- package/src/send.js +10 -3
- package/src/setup.js +127 -0
- package/types/authoring.d.ts +56 -2
- package/types/books.d.ts +14 -2
- package/types/canrun.d.ts +64 -0
- package/types/checked.d.ts +23 -0
- package/types/closers.d.ts +47 -28
- package/types/config.d.ts +1 -0
- package/types/declaration.d.ts +23 -1
- package/types/drafter.d.ts +151 -2
- package/types/draftspend.d.ts +21 -0
- package/types/flow.d.ts +23 -0
- package/types/liveness.d.ts +2 -2
- package/types/model-step.d.ts +4 -7
- package/types/monthly.d.ts +46 -1
- package/types/panel/author.d.ts +316 -0
- package/types/panel/authorcard.d.ts +142 -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 +105 -63
- package/types/panel/server.d.ts +11 -33
- package/types/panel/spawn.d.ts +30 -0
- package/types/provider.d.ts +6 -9
- package/types/runner.d.ts +129 -6
- package/types/runvalues.d.ts +97 -0
- package/types/send.d.ts +5 -1
- package/types/setup.d.ts +77 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ root: string, bin?: string }} opts
|
|
3
|
+
*/
|
|
4
|
+
export function createStarter(opts: {
|
|
5
|
+
root: string;
|
|
6
|
+
bin?: string;
|
|
7
|
+
}): {
|
|
8
|
+
checkRun: (flow: string, runId: unknown) => {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
say: string;
|
|
11
|
+
runDir?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
runDir: string;
|
|
15
|
+
say?: undefined;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Start `fwdloop run` for a flow whose every $0 check already passed at the calling door. Re-checks the run id here (nothing
|
|
19
|
+
* awaits between this check and the spawn). 202 { startId, runId } or a refusal; a refusal creates nothing.
|
|
20
|
+
* `runId` '' = no typed id: the start CLAIMS the next `run-<n>` itself (claimRunId, folder created exclusively; amendment 3).
|
|
21
|
+
* `values` (M4e amendment 5 item 3): the human's signed values for THIS run (the page's second click), written once into the run's own
|
|
22
|
+
* folder as `signed-values.json` BEFORE the spawn; the run then uses them (`pickRunValues`). None = the flow's own.
|
|
23
|
+
* @param {{ kind: 'run'|'sign', flow: string, runId: string, sources: {role: string, path: string}[], values?: any }} a
|
|
24
|
+
* @param {Record<string, string|undefined>} env the merged keys env: the child's env AND the scrub list
|
|
25
|
+
* @returns {{ status: number, body: any }}
|
|
26
|
+
*/
|
|
27
|
+
start({ kind, flow, runId, sources, values, }: {
|
|
28
|
+
kind: "run" | "sign";
|
|
29
|
+
flow: string;
|
|
30
|
+
runId: string;
|
|
31
|
+
sources: {
|
|
32
|
+
role: string;
|
|
33
|
+
path: string;
|
|
34
|
+
}[];
|
|
35
|
+
values?: any;
|
|
36
|
+
}, env: Record<string, string | undefined>): {
|
|
37
|
+
status: number;
|
|
38
|
+
body: any;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Start `fwdloop continue <runId>` (M4e amendment 4 item 4): Resume of a stopped or cap-halted run, after the door wrote the run's new
|
|
42
|
+
* signed values version. The same detached-child shape as `start`; the start folder reads as `starting` until the child consumes
|
|
43
|
+
* `halt.json`, then `started`; a child that died with `halt.json` still there is `refused` with its own sentence. One start at a time per flow.
|
|
44
|
+
* @param {{ flow: string, runId: string, version: number }} a @param {Record<string, string|undefined>} env the merged keys env
|
|
45
|
+
* @returns {{ status: number, body: any }}
|
|
46
|
+
*/
|
|
47
|
+
startContinue({ flow, runId, version }: {
|
|
48
|
+
flow: string;
|
|
49
|
+
runId: string;
|
|
50
|
+
version: number;
|
|
51
|
+
}, env: Record<string, string | undefined>): {
|
|
52
|
+
status: number;
|
|
53
|
+
body: any;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The newest start the human has not cleared, for a page that was reloaded: `starting` (re-attach the poll) or `refused` (show the
|
|
57
|
+
* CLI's sentence). Null when that start began (`started`: the run is in Runs) or there is none.
|
|
58
|
+
* @param {string[]} keys
|
|
59
|
+
*/
|
|
60
|
+
newestOpen(keys: string[]): {
|
|
61
|
+
phase: string;
|
|
62
|
+
startId: string;
|
|
63
|
+
kind: any;
|
|
64
|
+
flow: any;
|
|
65
|
+
runId: any;
|
|
66
|
+
} | null;
|
|
67
|
+
/**
|
|
68
|
+
* `POST /api/author/start/:startId/clear`: the human dismisses a REFUSED start. Writes `cleared.json` once; any other phase is refused.
|
|
69
|
+
* @param {string} id @param {string[]} keys
|
|
70
|
+
*/
|
|
71
|
+
clear(id: string, keys: string[]): {
|
|
72
|
+
status: number;
|
|
73
|
+
body: {
|
|
74
|
+
ok: boolean;
|
|
75
|
+
refused: string;
|
|
76
|
+
say?: undefined;
|
|
77
|
+
startId?: undefined;
|
|
78
|
+
};
|
|
79
|
+
} | {
|
|
80
|
+
status: number;
|
|
81
|
+
body: {
|
|
82
|
+
ok: boolean;
|
|
83
|
+
refused: string;
|
|
84
|
+
say: string;
|
|
85
|
+
startId?: undefined;
|
|
86
|
+
};
|
|
87
|
+
} | {
|
|
88
|
+
status: number;
|
|
89
|
+
body: {
|
|
90
|
+
ok: boolean;
|
|
91
|
+
startId: string;
|
|
92
|
+
refused?: undefined;
|
|
93
|
+
say?: undefined;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/** `GET /api/author/start/:startId`. @param {string} id @param {string[]} keys */
|
|
97
|
+
get(id: string, keys: string[]): {
|
|
98
|
+
status: number;
|
|
99
|
+
body: {
|
|
100
|
+
ok: boolean;
|
|
101
|
+
refused: string;
|
|
102
|
+
};
|
|
103
|
+
} | {
|
|
104
|
+
status: number;
|
|
105
|
+
body: {
|
|
106
|
+
phase: string;
|
|
107
|
+
startId: string;
|
|
108
|
+
kind: any;
|
|
109
|
+
flow: any;
|
|
110
|
+
runId: any;
|
|
111
|
+
ok: boolean;
|
|
112
|
+
refused?: undefined;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The smallest cap a Resume accepts: the next whole cent above what is spent, but never under the cap floor. ONE function for the
|
|
3
|
+
* door's refusal and the page's note, so the "at least $X" it names is itself accepted.
|
|
4
|
+
* @param {number} spentUsd @param {number} floorUsd
|
|
5
|
+
*/
|
|
6
|
+
export function leastResumeCapUsd(spentUsd: number, floorUsd: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* @param {object} a
|
|
9
|
+
* @param {string[]} a.allowedKeys the body keys this door takes; any other key is refused by name
|
|
10
|
+
* @param {any} a.body
|
|
11
|
+
* @param {{capUsd: number, destination: string|null, askWaits: Record<string,string>}} a.base the values in force now (the flow's own, or the run's newest signed version)
|
|
12
|
+
* @param {string} a.realRoot the flows root (real path)
|
|
13
|
+
* @param {boolean} a.capOnly Resume: destination and waits are never read from the body
|
|
14
|
+
* @param {number} a.floorUsd the smallest cap that funds one round of a step (amendment 4 item 2); 0 = none
|
|
15
|
+
* @param {number} [a.spentUsd] what the run has already spent (Resume): the cap must be above it
|
|
16
|
+
* @param {boolean} [a.always] Resume: the floor and the monthly check always apply. A Run applies them only when its cap differs from the
|
|
17
|
+
* flow's own (a plain Run keeps the CLI's own gate, as it always did), so an old flow signed below today's floor still runs plain.
|
|
18
|
+
* @param {(remainingUsd: number) => null | { problem: string } | { ok: boolean, room: any }} a.monthlyClaim the one monthly check
|
|
19
|
+
* @returns {{ ok: true, values: {capUsd: number, destination: string|null, askWaits: Record<string,string>}, differs: boolean, remainingUsd: number } | { ok: false, status: number, refusals: {field: string, say: string}[], refused?: string, say?: string }}
|
|
20
|
+
*/
|
|
21
|
+
export function checkValues({ allowedKeys, body, base, realRoot, capOnly, floorUsd, spentUsd, monthlyClaim, always, }: {
|
|
22
|
+
allowedKeys: string[];
|
|
23
|
+
body: any;
|
|
24
|
+
base: {
|
|
25
|
+
capUsd: number;
|
|
26
|
+
destination: string | null;
|
|
27
|
+
askWaits: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
realRoot: string;
|
|
30
|
+
capOnly: boolean;
|
|
31
|
+
floorUsd: number;
|
|
32
|
+
spentUsd?: number | undefined;
|
|
33
|
+
always?: boolean | undefined;
|
|
34
|
+
monthlyClaim: (remainingUsd: number) => null | {
|
|
35
|
+
problem: string;
|
|
36
|
+
} | {
|
|
37
|
+
ok: boolean;
|
|
38
|
+
room: any;
|
|
39
|
+
};
|
|
40
|
+
}): {
|
|
41
|
+
ok: true;
|
|
42
|
+
values: {
|
|
43
|
+
capUsd: number;
|
|
44
|
+
destination: string | null;
|
|
45
|
+
askWaits: Record<string, string>;
|
|
46
|
+
};
|
|
47
|
+
differs: boolean;
|
|
48
|
+
remainingUsd: number;
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
status: number;
|
|
52
|
+
refusals: {
|
|
53
|
+
field: string;
|
|
54
|
+
say: string;
|
|
55
|
+
}[];
|
|
56
|
+
refused?: string;
|
|
57
|
+
say?: string;
|
|
58
|
+
};
|
|
59
|
+
export const NEW_FLOW_SAY: "Only the files, the destination, the money cap and an ask's wait can change from one run to the next. A change to a job line, an ask's words or the steps is a new flow: use New job.";
|
|
60
|
+
export const RESUME_ONLY_CAP_SAY: "A resume changes only the cap. New files or a new destination or ask wait is a new run of this flow (Run a signed flow); a change to a job line or an ask is a new flow (New job).";
|
|
61
|
+
export { valuesHash };
|
|
62
|
+
import { valuesHash } from '../runvalues.js';
|
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, stoppedAtAsk?: string|null}} 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, stoppedAtAsk, }: {
|
|
181
182
|
historyRow: any;
|
|
182
183
|
askJson: any;
|
|
183
184
|
consumedAnswerExists: boolean;
|
|
@@ -186,8 +187,10 @@ export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasSta
|
|
|
186
187
|
liveness?: "running" | "gone" | "unknown";
|
|
187
188
|
booksFresh?: boolean;
|
|
188
189
|
lock?: string;
|
|
190
|
+
resumable?: boolean;
|
|
191
|
+
stoppedAtAsk?: string | null;
|
|
189
192
|
}): {
|
|
190
|
-
glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[\u25B6]" | "[?]" | "[II]";
|
|
193
|
+
glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[\u25B6]" | "[?]" | "[II]" | "[\u25A0]";
|
|
191
194
|
label: string;
|
|
192
195
|
};
|
|
193
196
|
/**
|
|
@@ -327,20 +330,20 @@ export function deriveStepTryMarks(closeClass: string | null, rows: Array<{
|
|
|
327
330
|
}>): Array<"\u2713" | "\u2717" | "\u00B7">;
|
|
328
331
|
/**
|
|
329
332
|
* 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`
|
|
333
|
+
* the ONE decider of a step's state: the Run tab's map and cards read it too
|
|
334
|
+
* (`groupState` on each step; the page keeps no rule of its own), last-row-wins: `waiting`
|
|
333
335
|
* (the run is currently parked on this step — its last attempt's verdict is
|
|
334
336
|
* `paused`/`refused`), `done` (the last attempt passed — `green`/`hitl`),
|
|
335
|
-
* `stopped` (
|
|
337
|
+
* `user-stopped` (M4e amendment 10: the step's own last row is `stopped`, a Stop
|
|
338
|
+
* the human asked), `stopped` (the last attempt failed for any other reason). A group only
|
|
336
339
|
* ever exists for a step with at least one row, so `pending` never appears
|
|
337
340
|
* here (unlike the Run tab's map, which also covers never-attempted steps).
|
|
338
341
|
* @param {Array<{verdict:string}>} rows one step's own audit rows, book order
|
|
339
|
-
* @returns {'done'|'waiting'|'stopped'}
|
|
342
|
+
* @returns {'done'|'waiting'|'stopped'|'user-stopped'}
|
|
340
343
|
*/
|
|
341
344
|
export function deriveStepGroupState(rows: Array<{
|
|
342
345
|
verdict: string;
|
|
343
|
-
}>): "done" | "waiting" | "stopped";
|
|
346
|
+
}>): "done" | "waiting" | "stopped" | "user-stopped";
|
|
344
347
|
/**
|
|
345
348
|
* hamr's 2026-09-27 exit-check review #1: the Audit tab's grouped-by-step
|
|
346
349
|
* header pieces, computed HERE (server-side) so `src/panel/index.html` only
|
|
@@ -394,6 +397,44 @@ export function summarizeSpendRows(spendRows: any[]): {
|
|
|
394
397
|
cacheReadTokens: number | null;
|
|
395
398
|
cacheReadTokensWhy: string | null;
|
|
396
399
|
};
|
|
400
|
+
/**
|
|
401
|
+
* M4e amendment 4 item 4: the ONE decision for the Run tab's Stop and Resume buttons (the Stop and Resume doors read the
|
|
402
|
+
* same object, so the page never offers what the door would refuse). `running` is the glyph's own rule (`isRunningNow`);
|
|
403
|
+
* a run with no process record yet is `starting`; a parked run (`[·]`/`[!]`, an open ask) is neither.
|
|
404
|
+
* @param {any} ctx `loadRunContext`'s result @param {string} glyph `computeGlyph`'s sign
|
|
405
|
+
* @returns {{canStop: boolean, atAsk: boolean, stopRequested: boolean, starting: boolean, canResume: boolean, resumeOutcome: string|null, spentUsd: number|null, spendComplete: boolean|null, capUsd: number|null}}
|
|
406
|
+
*/
|
|
407
|
+
export function runControls(ctx: any, glyph: string, label?: string): {
|
|
408
|
+
canStop: boolean;
|
|
409
|
+
atAsk: boolean;
|
|
410
|
+
stopRequested: boolean;
|
|
411
|
+
starting: boolean;
|
|
412
|
+
canResume: boolean;
|
|
413
|
+
resumeOutcome: string | null;
|
|
414
|
+
spentUsd: number | null;
|
|
415
|
+
spendComplete: boolean | null;
|
|
416
|
+
capUsd: number | null;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* `runControls` for one run read straight from the books (the Stop door's own read). `null` when the run does not resolve.
|
|
420
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
421
|
+
*/
|
|
422
|
+
export function getRunControls({ root, flow, runId, catalogue, }: {
|
|
423
|
+
root: string;
|
|
424
|
+
flow: string;
|
|
425
|
+
runId: string;
|
|
426
|
+
catalogue: any;
|
|
427
|
+
}): {
|
|
428
|
+
canStop: boolean;
|
|
429
|
+
atAsk: boolean;
|
|
430
|
+
stopRequested: boolean;
|
|
431
|
+
starting: boolean;
|
|
432
|
+
canResume: boolean;
|
|
433
|
+
resumeOutcome: string | null;
|
|
434
|
+
spentUsd: number | null;
|
|
435
|
+
spendComplete: boolean | null;
|
|
436
|
+
capUsd: number | null;
|
|
437
|
+
} | null;
|
|
397
438
|
/**
|
|
398
439
|
* `GET /api/runs` — every flow under `root`, every run under each flow
|
|
399
440
|
* (M4a scope item 2). A flow with zero runs still gets one row (`runId:
|
|
@@ -439,6 +480,54 @@ export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, }: {
|
|
|
439
480
|
catalogue: any;
|
|
440
481
|
resumeAttempt?: (flow: string, runId: string) => any;
|
|
441
482
|
}): any | null;
|
|
483
|
+
/**
|
|
484
|
+
* 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).
|
|
485
|
+
* 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
|
|
486
|
+
* 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
|
|
487
|
+
* unknown never shows as a smaller exact number; no model rows = `null`. `humanChecks` = the note rows + the revise rows (each is the card the human edited and sent) + the sign row + the run's signed-values
|
|
488
|
+
* rows (the card is not a check), given by the caller as `ctx.humanChecks`. Money follows `costDisplay` ("at least $X" for a floor).
|
|
489
|
+
* @param {any[]} modelRows the draft and change rows (`kind` draft | change) of `setup.jsonl`
|
|
490
|
+
* @param {{cardAt?: any, signAt?: any, humanChecks?: number|null}} [ctx]
|
|
491
|
+
* @returns {{calls: number|null, callsAtLeast: boolean, timeMs: number|null, humanChecks: number|null, usd: number|null, spendComplete: boolean, cost: string|null, modelRows: number}}
|
|
492
|
+
*/
|
|
493
|
+
export function draftTotals(modelRows: any[], ctx?: {
|
|
494
|
+
cardAt?: any;
|
|
495
|
+
signAt?: any;
|
|
496
|
+
humanChecks?: number | null;
|
|
497
|
+
}): {
|
|
498
|
+
calls: number | null;
|
|
499
|
+
callsAtLeast: boolean;
|
|
500
|
+
timeMs: number | null;
|
|
501
|
+
humanChecks: number | null;
|
|
502
|
+
usd: number | null;
|
|
503
|
+
spendComplete: boolean;
|
|
504
|
+
cost: string | null;
|
|
505
|
+
modelRows: number;
|
|
506
|
+
};
|
|
507
|
+
/**
|
|
508
|
+
* 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
|
|
509
|
+
* 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
|
|
510
|
+
* as the run's audit rows so the page draws both with one row builder. Reads only through the safe gateways; never throws.
|
|
511
|
+
* @param {string} flowDir @param {string} runDir
|
|
512
|
+
* @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}}}
|
|
513
|
+
*/
|
|
514
|
+
export function getDraftBlock(flowDir: string, runDir: string): {
|
|
515
|
+
present: boolean;
|
|
516
|
+
why: string | null;
|
|
517
|
+
rows: any[];
|
|
518
|
+
summary: {
|
|
519
|
+
present: boolean;
|
|
520
|
+
why?: string;
|
|
521
|
+
calls?: number | null;
|
|
522
|
+
callsAtLeast?: boolean;
|
|
523
|
+
humanChecks?: number | null;
|
|
524
|
+
timeMs?: number | null;
|
|
525
|
+
usd?: number | null;
|
|
526
|
+
spendComplete?: boolean;
|
|
527
|
+
cost?: string | null;
|
|
528
|
+
modelRows?: number;
|
|
529
|
+
};
|
|
530
|
+
};
|
|
442
531
|
/**
|
|
443
532
|
* `GET /api/runs/:flow/:runId/audit` — the Audit/logs tab (M4a scope item
|
|
444
533
|
* 2): the raw `audit.jsonl` rows, scoped strictly to this run (each run's
|
|
@@ -446,7 +535,7 @@ export function getRunDetail({ root, flow, runId, catalogue, resumeAttempt, }: {
|
|
|
446
535
|
* shared-sidecar contamination risk here the way bareloop's gate-audit
|
|
447
536
|
* sidecar had). `null` when the flow/runId doesn't resolve (404).
|
|
448
537
|
* @param {{root: string, flow: string, runId: string}} opts
|
|
449
|
-
* @returns {{flow:string, runId:string, rows:any[], groups:any[], empty:boolean, why:string|null}|null}
|
|
538
|
+
* @returns {{flow:string, runId:string, rows:any[], groups:any[], draft:ReturnType<typeof getDraftBlock>, empty:boolean, why:string|null}|null}
|
|
450
539
|
*/
|
|
451
540
|
export function getRunAudit({ root, flow, runId }: {
|
|
452
541
|
root: string;
|
|
@@ -457,58 +546,10 @@ export function getRunAudit({ root, flow, runId }: {
|
|
|
457
546
|
runId: string;
|
|
458
547
|
rows: any[];
|
|
459
548
|
groups: any[];
|
|
549
|
+
draft: ReturnType<typeof getDraftBlock>;
|
|
460
550
|
empty: boolean;
|
|
461
551
|
why: string | null;
|
|
462
552
|
} | null;
|
|
463
|
-
/**
|
|
464
|
-
* `GET /api/runs/:flow/:runId/job` — the Job tab (M4a scope item 2): the
|
|
465
|
-
* signed prose, the arbiter block (cap, asks with TTL, redo cap, sends,
|
|
466
|
-
* sources), and the signature (who, when, hash). Derived purely from the
|
|
467
|
-
* flow's own signed files (`readFlow`) — fwdloop always has exactly one
|
|
468
|
-
* signed `declaration.json` + `signature.json` per flow, so there is no
|
|
469
|
-
* multi-source provenance chain to resolve (unlike bareloop's `getRunJob` —
|
|
470
|
-
* DROPPED per the fit-check). `runId` is only used to confirm the run
|
|
471
|
-
* exists at all; `null` when it doesn't (404).
|
|
472
|
-
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
473
|
-
* @returns {any|null}
|
|
474
|
-
*/
|
|
475
|
-
/**
|
|
476
|
-
* hamr's 2026-09-27 exit-check review #5: one plain-words sentence for a
|
|
477
|
-
* declared step's own close rule — the Job tab's "Success" field. Derived
|
|
478
|
-
* STRICTLY from `step.close` (and, for the "your accept" wording, whether
|
|
479
|
-
* this step is the one line `arbiter.asks[]` itself binds to) — never a
|
|
480
|
-
* fabricated cite/shape value:
|
|
481
|
-
* - `hitl`: "human check", or "human check (your accept)" when this step's
|
|
482
|
-
* own `fromLine` is a signed ask line (the ask step itself — the one a
|
|
483
|
-
* human pauses a run on, distinct from an ordinary hitl pass-through
|
|
484
|
-
* step with no ask binding).
|
|
485
|
-
* - `softgreen`: "shape: N headings (a / b / c)" when `close.shape.sections`
|
|
486
|
-
* is signed, "max W words" appended when `close.shape.maxWords` is
|
|
487
|
-
* signed, "blocks of L lines" / "must carry: a, b" for the invoice-block
|
|
488
|
-
* shape keys (`linesPerInvoice`/`mustCarry`) — every signed shape key
|
|
489
|
-
* shown, nothing invented; "shape (no shape rules signed)" when a
|
|
490
|
-
* softgreen step signs no `close.shape` at all (declaration.js allows
|
|
491
|
-
* this — an empty/absent shape is not itself a red).
|
|
492
|
-
* - `green`: "cited" — `CLOSE_ALLOWED` (`src/declaration.js`) never lets a
|
|
493
|
-
* step declare WHAT it cites ahead of time (that's the drafted
|
|
494
|
-
* artifact's own per-run field data, not signed prose), so there is
|
|
495
|
-
* never anything honest to append here.
|
|
496
|
-
* - anything else: the raw class name, named as unknown, never silently
|
|
497
|
-
* dropped or guessed into one of the three above; no class at all names
|
|
498
|
-
* that plainly too.
|
|
499
|
-
* @param {{close?: {class?: string, shape?: any}, fromLine?: number|null}} step one `declaration.steps` entry
|
|
500
|
-
* @param {Array<{line:number}>} arbiterAsks `arbiter.asks`, for the "your accept" check
|
|
501
|
-
* @returns {string}
|
|
502
|
-
*/
|
|
503
|
-
export function deriveStepSuccessText(step: {
|
|
504
|
-
close?: {
|
|
505
|
-
class?: string;
|
|
506
|
-
shape?: any;
|
|
507
|
-
};
|
|
508
|
-
fromLine?: number | null;
|
|
509
|
-
}, arbiterAsks: Array<{
|
|
510
|
-
line: number;
|
|
511
|
-
}>): string;
|
|
512
553
|
/**
|
|
513
554
|
* `GET /api/runs/:flow/:runId/job` — the Job tab (hamr's 2026-09-27
|
|
514
555
|
* exit-check review #5: bareloop-style one-field-per-piece layout,
|
|
@@ -517,8 +558,7 @@ export function deriveStepSuccessText(step: {
|
|
|
517
558
|
* signature.json/prose lines — nothing invented; a piece the books can't
|
|
518
559
|
* name carries its own why, never a blank or a guess. Field order (server
|
|
519
560
|
* order matches the page's own render order): prose, asks, model, cap
|
|
520
|
-
* (+redo cap), sources, sends, guardrails,
|
|
521
|
-
* `deriveStepSuccessText`), signature.
|
|
561
|
+
* (+redo cap), sources, sends, guardrails, plan (one row per step, amendment 34), signature.
|
|
522
562
|
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
523
563
|
* @returns {any|null}
|
|
524
564
|
*/
|
|
@@ -672,3 +712,5 @@ export const STUCK_REASONS: {
|
|
|
672
712
|
why: string;
|
|
673
713
|
};
|
|
674
714
|
};
|
|
715
|
+
/** The words the Draft says for a flow with no `setup.jsonl` (M4e amendment 6 item 4; renamed Draft by amendment 7 item 2). */
|
|
716
|
+
export const NO_DRAFT_WORDS: "no draft record";
|
package/types/panel/server.d.ts
CHANGED
|
@@ -1,43 +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>;
|
|
40
13
|
settings: ReturnType<typeof createSettings>;
|
|
14
|
+
author: ReturnType<typeof createAuthor>;
|
|
41
15
|
}): void;
|
|
42
16
|
/**
|
|
43
17
|
* Start the panel server. Binds `127.0.0.1` ONLY. A taken port is a LOUD,
|
|
@@ -45,14 +19,13 @@ export function handleRequest(req: import("node:http").IncomingMessage, res: imp
|
|
|
45
19
|
* header). Resolves once actually listening; rejects on a bind error
|
|
46
20
|
* (including `EADDRINUSE`) with a `.port` field on the error for the
|
|
47
21
|
* caller's message.
|
|
48
|
-
* @param {{ port?: number, root: string,
|
|
49
|
-
* `resume`
|
|
50
|
-
* @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> }>}
|
|
51
25
|
*/
|
|
52
26
|
export function createPanelServer(opts: {
|
|
53
27
|
port?: number;
|
|
54
28
|
root: string;
|
|
55
|
-
token?: string;
|
|
56
29
|
settings?: {
|
|
57
30
|
home?: string;
|
|
58
31
|
env?: Record<string, string | undefined>;
|
|
@@ -67,10 +40,14 @@ export function createPanelServer(opts: {
|
|
|
67
40
|
windowMs?: number;
|
|
68
41
|
slotMs?: number;
|
|
69
42
|
};
|
|
43
|
+
author?: {
|
|
44
|
+
env?: Record<string, string | undefined>;
|
|
45
|
+
loadEnv?: () => any;
|
|
46
|
+
bin?: string;
|
|
47
|
+
};
|
|
70
48
|
}): Promise<{
|
|
71
49
|
server: import("node:http").Server;
|
|
72
50
|
port: number;
|
|
73
|
-
token: string;
|
|
74
51
|
close: () => Promise<void>;
|
|
75
52
|
}>;
|
|
76
53
|
/**
|
|
@@ -91,3 +68,4 @@ export function panelMain(argv: string[], ctx: {
|
|
|
91
68
|
export const DEFAULT_PORT: 4800;
|
|
92
69
|
import { createResumer } from './resume.js';
|
|
93
70
|
import { createSettings } from './settings.js';
|
|
71
|
+
import { createAuthor } from './author.js';
|
|
@@ -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
|
@@ -92,7 +92,6 @@ export function resolveModelRate(modelId: any, ratesTable?: {
|
|
|
92
92
|
};
|
|
93
93
|
'deepseek-flash': {
|
|
94
94
|
in: number;
|
|
95
|
-
cacheIn: number;
|
|
96
95
|
out: number;
|
|
97
96
|
source: string;
|
|
98
97
|
};
|
|
@@ -109,15 +108,15 @@ export function resolveModelRate(modelId: any, ratesTable?: {
|
|
|
109
108
|
* THE one price lookup (M4d scope item 6): every model call — run, resume, model step, drafter —
|
|
110
109
|
* is booked and cap-checked from this. Per field: a Settings price (`config.prices[slot]`, USD per
|
|
111
110
|
* 1M -> per 1K) wins, else the code table's row, else the table's HIGHEST entry for that field
|
|
112
|
-
* (an unknown model; unknown cost is never 0).
|
|
113
|
-
*
|
|
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.
|
|
114
113
|
*
|
|
115
114
|
* @param {string} modelId
|
|
116
115
|
* @param {{ slot?: string, config?: Record<string, any>, ratesTable?: Record<string, any> }} [opts]
|
|
117
116
|
* @returns {{
|
|
118
117
|
* rates: { in: number, out: number, cacheReadMult?: number },
|
|
119
118
|
* perM: { inPerM: number, cachedInPerM: number, outPerM: number },
|
|
120
|
-
* source: { in: 'settings'|'table'|'ceiling', cachedIn: '
|
|
119
|
+
* source: { in: 'settings'|'table'|'ceiling', cachedIn: 'input', out: 'settings'|'table'|'ceiling' },
|
|
121
120
|
* suffix: string|null,
|
|
122
121
|
* }}
|
|
123
122
|
*/
|
|
@@ -138,7 +137,7 @@ export function resolvePrices(modelId: string, { slot, config, ratesTable }?: {
|
|
|
138
137
|
};
|
|
139
138
|
source: {
|
|
140
139
|
in: "settings" | "table" | "ceiling";
|
|
141
|
-
cachedIn: "
|
|
140
|
+
cachedIn: "input";
|
|
142
141
|
out: "settings" | "table" | "ceiling";
|
|
143
142
|
};
|
|
144
143
|
suffix: string | null;
|
|
@@ -224,7 +223,6 @@ export function ceilingCostUsd(modelId: any, ratesTable?: {
|
|
|
224
223
|
};
|
|
225
224
|
'deepseek-flash': {
|
|
226
225
|
in: number;
|
|
227
|
-
cacheIn: number;
|
|
228
226
|
out: number;
|
|
229
227
|
source: string;
|
|
230
228
|
};
|
|
@@ -374,8 +372,8 @@ export const PROVIDER_SLOTS: Readonly<{
|
|
|
374
372
|
* provider slot) wins over a row here, per field, through `resolvePrices` below —
|
|
375
373
|
* the one lookup every model call is booked and cap-checked by (M4d, signed
|
|
376
374
|
* 2026-10-05; that REPLACES the 2026-09-21 "edit a row here, never a runtime
|
|
377
|
-
* flag" ruling).
|
|
378
|
-
*
|
|
375
|
+
* flag" ruling). Cached input is priced as input
|
|
376
|
+
* (M4d amendment 2): a row has no cache rate.
|
|
379
377
|
*/
|
|
380
378
|
export const RATES_BY_SUFFIX: {
|
|
381
379
|
'zai-org/GLM-5.2': {
|
|
@@ -430,7 +428,6 @@ export const RATES_BY_SUFFIX: {
|
|
|
430
428
|
};
|
|
431
429
|
'deepseek-flash': {
|
|
432
430
|
in: number;
|
|
433
|
-
cacheIn: number;
|
|
434
431
|
out: number;
|
|
435
432
|
source: string;
|
|
436
433
|
};
|