fwdloop 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fwdloop +143 -64
- package/package.json +3 -3
- package/src/ask.js +260 -6
- package/src/books.js +209 -2
- package/src/flow.js +247 -2
- package/src/index.js +9 -3
- 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 +136 -41
- package/src/provider.js +57 -41
- package/src/runner.js +393 -54
- package/src/send.js +20 -1
- package/src/types.js +18 -0
- package/types/ask.d.ts +77 -0
- package/types/books.d.ts +70 -2
- package/types/flow.d.ts +135 -0
- package/types/index.d.ts +5 -3
- package/types/panel/data.d.ts +433 -0
- package/types/panel/server.d.ts +45 -0
- package/types/primitives.d.ts +29 -0
- package/types/provider.d.ts +11 -0
- package/types/runner.d.ts +66 -5
- package/types/types.d.ts +41 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The glyph + human-words label for one run — ported verbatim (in spirit,
|
|
3
|
+
* from real derivation, not a shortcut) from `poc/m4/panel-data.mjs`'s
|
|
4
|
+
* `computeGlyph`, the derivation the M4a POC proved against every real run
|
|
5
|
+
* on disk. Ladder wording (M4a scope item 4):
|
|
6
|
+
* - `[✓]` passed — a history row with `outcome:'complete'`.
|
|
7
|
+
* - `[✗]` failed — a history row with any other outcome (never `[?]`).
|
|
8
|
+
* - `[·]` waiting on you — parked (`ask.json` present), no consumed answer,
|
|
9
|
+
* NOT past its own `expiresAt`.
|
|
10
|
+
* - `[!]` ask expired, not resumed yet — parked, no consumed answer, but
|
|
11
|
+
* its own `expiresAt` is already past (hamr's 2026-09-27 browser-walk bug
|
|
12
|
+
* #3: the runs list/header glyph disagreed with the Inbox, which already
|
|
13
|
+
* reports `expired` correctly off the exact same `askJson.expiresAt` —
|
|
14
|
+
* `[!]` is not in the ladder's signed M4a vocabulary; picked here as an
|
|
15
|
+
* honest fourth state, distinct from every signed glyph, pending a
|
|
16
|
+
* ruling — see the report). Never `[·]` waiting (nobody can still answer
|
|
17
|
+
* it in time), never `[✗]` (the run itself never failed a check), never
|
|
18
|
+
* `[?]` (the books DO know what happened here).
|
|
19
|
+
* - `[·]` answered, not resumed yet — parked, a consumed answer exists, but
|
|
20
|
+
* no history row yet (resume hasn't finished) — always in words, never
|
|
21
|
+
* the same line as "waiting on you", never `[?]`.
|
|
22
|
+
* - `[?]` died / unknown — no history row, no open ask, no consumed answer:
|
|
23
|
+
* `resume.lock` carries no pid and nothing checks liveness (M4a's own
|
|
24
|
+
* open POC question), so a crashed resumer and a live one look the same
|
|
25
|
+
* on disk. Never guessed into `[✗]` or `[✓]`.
|
|
26
|
+
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean}} ctx
|
|
27
|
+
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[?]', label: string}}
|
|
28
|
+
*/
|
|
29
|
+
export function computeGlyph({ historyRow, askJson, consumedAnswerExists, hasStateJson, }: {
|
|
30
|
+
historyRow: any;
|
|
31
|
+
askJson: any;
|
|
32
|
+
consumedAnswerExists: boolean;
|
|
33
|
+
hasStateJson: boolean;
|
|
34
|
+
}): {
|
|
35
|
+
glyph: "[\u2713]" | "[\u2717]" | "[\u00B7]" | "[!]" | "[?]";
|
|
36
|
+
label: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* "$X.XXXX" or, when the book itself says the number is a floor
|
|
40
|
+
* (`spendComplete:false`), "at least $X.XXXX" — never a bare total presented
|
|
41
|
+
* as complete when it isn't (negative scenario iv), and never `$0` standing
|
|
42
|
+
* in for a missing/unknown number (project rule).
|
|
43
|
+
* @param {number|null|undefined} spentUsd
|
|
44
|
+
* @param {boolean|undefined} spendComplete
|
|
45
|
+
* @returns {{ok:true, display:string}|{ok:false, why:string}}
|
|
46
|
+
*/
|
|
47
|
+
export function costDisplay(spentUsd: number | null | undefined, spendComplete: boolean | undefined): {
|
|
48
|
+
ok: true;
|
|
49
|
+
display: string;
|
|
50
|
+
} | {
|
|
51
|
+
ok: false;
|
|
52
|
+
why: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The model this run's own book rows actually name — hamr's review #1/#7:
|
|
56
|
+
* no `declaration.json`/`signature.json` field records a model at all (the
|
|
57
|
+
* flow's steps carry primitives and a close class, never a model choice),
|
|
58
|
+
* so `audit.jsonl`'s own per-attempt `model` field (`src/books.js`'s
|
|
59
|
+
* `appendAudit` row shape) is the ONLY book that can answer "what model did
|
|
60
|
+
* this run use" — never invented, never defaulted to a catalogue/provider
|
|
61
|
+
* default the run may not have actually hit. Reads book order BACKWARDS and
|
|
62
|
+
* returns the LAST row that names a model (the most recent attempt's own
|
|
63
|
+
* choice), so a run that changed model slot mid-run (would show as a
|
|
64
|
+
* `modelMatch:"substituted"` row) still reports what actually ran last,
|
|
65
|
+
* never a stale first-attempt value. `null` (never a guess) when no row in
|
|
66
|
+
* this run ever named one (e.g. every step is `hitl`, no model step ran).
|
|
67
|
+
* No provider/API-kind field exists in ANY book (`src/provider.js`'s
|
|
68
|
+
* `PROVIDER_SLOTS` maps a slot name to a model, but nothing writes which
|
|
69
|
+
* slot served a given run back to `audit.jsonl`/`spend.jsonl`) — provider is
|
|
70
|
+
* never shown alongside it (hamr's own instruction: "if the provider isn't
|
|
71
|
+
* in any book, show model only").
|
|
72
|
+
* @param {any[]} auditRows
|
|
73
|
+
* @returns {string|null}
|
|
74
|
+
*/
|
|
75
|
+
export function deriveRunModel(auditRows: any[]): string | null;
|
|
76
|
+
/**
|
|
77
|
+
* The Audit tab's "Action" column (hamr's review #6, tightened by hamr's
|
|
78
|
+
* 2026-09-27 live check): exactly three words, derived STRICTLY from a
|
|
79
|
+
* row's own fields — never the step name/id, never a model name, never
|
|
80
|
+
* "unknown action":
|
|
81
|
+
* - "model call" — a row with a non-empty `model` field (the model itself
|
|
82
|
+
* still shows in the Cost/Verdict area elsewhere; this column names only
|
|
83
|
+
* the KIND of action).
|
|
84
|
+
* - "human" — an ask-slot row: `src/runner.js`'s `runAskSlot` is the ONLY
|
|
85
|
+
* place that ever passes a third argument (`unjudgedCount`) into
|
|
86
|
+
* `recordAudit`, so `Object.prototype.hasOwnProperty.call(row,
|
|
87
|
+
* 'unjudgedCount')` is true for exactly that step's own rows (paused,
|
|
88
|
+
* and the human's own accept/reject/rerun/refused answers) and false for
|
|
89
|
+
* every other row shape in the book — a real, always-present marker
|
|
90
|
+
* (`unjudgedCount` is a number, 0 included, never omitted on an ask row),
|
|
91
|
+
* never the step's close class (a NON-ask hitl step, e.g. a plain write
|
|
92
|
+
* step, is ALSO `class:'hitl'` — that was the exact bug this replaces:
|
|
93
|
+
* class alone can't tell "the ask" apart from "any other hitl step").
|
|
94
|
+
* - "no model call" — everything else: a mechanical green/not-done/red
|
|
95
|
+
* close, a cap-halt, a send confirmation, a non-ask hitl pass-through
|
|
96
|
+
* (e.g. a write step) — no model ran and no human answered THIS row.
|
|
97
|
+
* @param {any} row one `audit.jsonl` row
|
|
98
|
+
* @returns {'model call'|'human'|'no model call'}
|
|
99
|
+
*/
|
|
100
|
+
export function deriveAuditAction(row: any): "model call" | "human" | "no model call";
|
|
101
|
+
/**
|
|
102
|
+
* The Audit tab's Cost cell token phrase (hamr's 2026-09-27 review item c):
|
|
103
|
+
* a per-ROW token total, read through `auditRowTokens` (`src/books.js`) so
|
|
104
|
+
* this module never re-derives "was this row written before M4a-2" itself.
|
|
105
|
+
* Three honest outcomes, never folded into one another:
|
|
106
|
+
* - `{kind:'total', total}` — a real (post-M4a-2) model-call row: `total`
|
|
107
|
+
* sums ALL three fields the row's own `tokens` object carries
|
|
108
|
+
* (`inputTokens + outputTokens + cacheReadTokens`) — every token this
|
|
109
|
+
* row's call actually touched, cache-read included (labelled plainly as
|
|
110
|
+
* "N tokens", never split out here; a cache-read token is still a token
|
|
111
|
+
* the call processed, so folding it into the total is the honest sum,
|
|
112
|
+
* not a hidden discount).
|
|
113
|
+
* - `{kind:'not-recorded'}` — a row written before Amendment M4a-2 (no
|
|
114
|
+
* `tokens` key at all) — shown as "tokens not recorded", never a 0 or a
|
|
115
|
+
* blank.
|
|
116
|
+
* - `{kind:'no-model'}` — a post-M4a-2 row that genuinely carries no model
|
|
117
|
+
* call (`tokens:null`, `model:null` — an ask/hitl row) — the tokens
|
|
118
|
+
* phrase is omitted entirely rather than shown as "0 tokens" or "not
|
|
119
|
+
* recorded" (there was never anything to record).
|
|
120
|
+
* @param {any} row one `audit.jsonl` row
|
|
121
|
+
* @returns {{kind:'total', total:number}|{kind:'not-recorded'}|{kind:'no-model'}}
|
|
122
|
+
*/
|
|
123
|
+
export function deriveAuditTokensDisplay(row: any): {
|
|
124
|
+
kind: "total";
|
|
125
|
+
total: number;
|
|
126
|
+
} | {
|
|
127
|
+
kind: "not-recorded";
|
|
128
|
+
} | {
|
|
129
|
+
kind: "no-model";
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* hamr's request (Amendment M4a-3): the Audit tab's Action cell gets a
|
|
133
|
+
* one-line tool tally appended for a MODEL-call row whose own `tools` was
|
|
134
|
+
* actually recorded (Amendment M4a-3) — `", read 3, write 1"` — read
|
|
135
|
+
* straight through `auditRowTools` (`src/books.js`), never re-derived. Three
|
|
136
|
+
* honest outcomes, matching `deriveAuditTokensDisplay`'s own shape exactly:
|
|
137
|
+
* `null` for a non-model row (nothing to append — a human/no-model-call row
|
|
138
|
+
* never claims a tool tally), `null` for a pre-M4a-3 model row (`why` set —
|
|
139
|
+
* appending nothing beats guessing a tally that was never recorded), and a
|
|
140
|
+
* real phrase, sorted by count desc then name, for a model row that DOES
|
|
141
|
+
* carry `tools` (including `{}` — zero tool calls that round — which still
|
|
142
|
+
* returns `null`: there is nothing to list, so nothing is appended).
|
|
143
|
+
* @param {any} row one `audit.jsonl` row
|
|
144
|
+
* @returns {string|null}
|
|
145
|
+
*/
|
|
146
|
+
export function deriveAuditToolsPhrase(row: any): string | null;
|
|
147
|
+
/**
|
|
148
|
+
* The Audit tab's new Time column (hamr's 2026-09-27 review item d): this
|
|
149
|
+
* row's own `why` when `at` predates Amendment M4a-2, else `null` (the row
|
|
150
|
+
* DOES carry a real `at` — the client formats it with `readableDateTime`,
|
|
151
|
+
* the same local-time formatter every other timestamp on this page already
|
|
152
|
+
* uses; formatting to the viewer's own locale belongs in the browser, not
|
|
153
|
+
* here). Read through `auditRowAt` (`src/books.js`) — never re-derived.
|
|
154
|
+
* @param {any} row one `audit.jsonl` row
|
|
155
|
+
* @returns {string|null}
|
|
156
|
+
*/
|
|
157
|
+
export function deriveAuditAtWhy(row: any): string | null;
|
|
158
|
+
export function isBlockedVerdict(verdict: any): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* One mark per try, in try order — mirrors `computeTryCount`'s own pairing
|
|
161
|
+
* exactly (a `hitl` step's `paused` row plus its next resolving row is ONE
|
|
162
|
+
* try; every other step's own row is ONE try each) so a group header's
|
|
163
|
+
* `tryMarks.length` always equals its own `tryCount`. A `paused` row with no
|
|
164
|
+
* resolution yet in this run's own book order keeps its `·` mark (still
|
|
165
|
+
* open, not resolved).
|
|
166
|
+
* @param {string|null} closeClass
|
|
167
|
+
* @param {Array<{verdict:string}>} rows one step's own audit rows, book order
|
|
168
|
+
* @returns {Array<'✓'|'✗'|'·'>}
|
|
169
|
+
*/
|
|
170
|
+
export function deriveStepTryMarks(closeClass: string | null, rows: Array<{
|
|
171
|
+
verdict: string;
|
|
172
|
+
}>): Array<"\u2713" | "\u2717" | "\u00B7">;
|
|
173
|
+
/**
|
|
174
|
+
* A step group's own state word for the Audit tab's collapsed header —
|
|
175
|
+
* the SAME rule `src/panel/index.html`'s client-side `stepBoxState` already
|
|
176
|
+
* applies to the Run tab's map/cards (ported here so the Audit header can
|
|
177
|
+
* be computed server-side too, off the SAME last-row-wins logic): `waiting`
|
|
178
|
+
* (the run is currently parked on this step — its last attempt's verdict is
|
|
179
|
+
* `paused`/`refused`), `done` (the last attempt passed — `green`/`hitl`),
|
|
180
|
+
* `stopped` (the last attempt failed for any other reason). A group only
|
|
181
|
+
* ever exists for a step with at least one row, so `pending` never appears
|
|
182
|
+
* here (unlike the Run tab's map, which also covers never-attempted steps).
|
|
183
|
+
* @param {Array<{verdict:string}>} rows one step's own audit rows, book order
|
|
184
|
+
* @returns {'done'|'waiting'|'stopped'}
|
|
185
|
+
*/
|
|
186
|
+
export function deriveStepGroupState(rows: Array<{
|
|
187
|
+
verdict: string;
|
|
188
|
+
}>): "done" | "waiting" | "stopped";
|
|
189
|
+
/**
|
|
190
|
+
* hamr's 2026-09-27 exit-check review #1: the Audit tab's grouped-by-step
|
|
191
|
+
* header pieces, computed HERE (server-side) so `src/panel/index.html` only
|
|
192
|
+
* ever renders them, never re-derives them. One entry per step, first-seen
|
|
193
|
+
* order preserved (never re-sorted): `step` (the emits id, the header IS the
|
|
194
|
+
* step's own name — no separate Step column in Grouped view), `state`
|
|
195
|
+
* (`deriveStepGroupState`), `closeClass`, `timeMs` (this step's own attempts'
|
|
196
|
+
* `wallMs` summed — "total time from wallMs", never a guess), `cost`/
|
|
197
|
+
* `costWhy` (a bare `$X` sum when every priced row is complete, `"at least
|
|
198
|
+
* $X"` when any priced row in this step is a floor, `null`+why when no row
|
|
199
|
+
* in this step has ever priced), `tokensTotal` (the sum of every row's own
|
|
200
|
+
* token total, ONLY when every row in the step either carries real
|
|
201
|
+
* (post-M4a-2) tokens or genuinely made no model call — one row missing
|
|
202
|
+
* tokens (a pre-M4a-2 row) means the WHOLE step's total is withheld, never a
|
|
203
|
+
* partial sum shown as complete; `null` also when the step made no model
|
|
204
|
+
* call at all, nothing to sum), `toolsTotal`/`toolsWhy`/`ungranted`
|
|
205
|
+
* (Amendment M4a-3, `summarizeStepTools` — the same "no partial sum" honesty
|
|
206
|
+
* rule as `tokensTotal`, plus the deduped union of every row's own
|
|
207
|
+
* `ungranted` calls), `tryCount`/`tryMarks` (`deriveStepTryMarks`),
|
|
208
|
+
* `rows` (this step's own enriched audit rows, for the group's own table —
|
|
209
|
+
* never a second, separately-filtered copy on the client).
|
|
210
|
+
* @param {any[]} enrichedRows `getRunAudit`'s own rows, already carrying
|
|
211
|
+
* `action`/`tokensDisplay`/`atWhy`/`blocked` (this function never
|
|
212
|
+
* re-derives any of those, only groups and sums them)
|
|
213
|
+
* @returns {any[]}
|
|
214
|
+
*/
|
|
215
|
+
export function deriveAuditGroups(enrichedRows: any[]): any[];
|
|
216
|
+
/**
|
|
217
|
+
* Run-level totals from `spend.jsonl` (hamr's review #1): rounds, input/
|
|
218
|
+
* output/cache-read tokens — shown ONLY as a run-wide sum, never attributed
|
|
219
|
+
* to a step (a spend row carries no `step` field at all — `src/model-step.js`
|
|
220
|
+
* appends it before any step identity is threaded through, so per-step
|
|
221
|
+
* attribution would be invented, not read). Honest about partial data: a
|
|
222
|
+
* field this run's rows never populated (e.g. no row ever carried
|
|
223
|
+
* `tokens.cacheReadTokens`) is `null` with its own `*Why`, never folded into
|
|
224
|
+
* a 0. `null` `rows`/`empty:true` (with a why) when spend.jsonl has no rows
|
|
225
|
+
* at all yet.
|
|
226
|
+
* @param {any[]} spendRows
|
|
227
|
+
* @returns {{empty:true, why:string}|{empty:false, rounds:number, tokensIn:number|null, tokensInWhy:string|null, tokensOut:number|null, tokensOutWhy:string|null, cacheReadTokens:number|null, cacheReadTokensWhy:string|null}}
|
|
228
|
+
*/
|
|
229
|
+
export function summarizeSpendRows(spendRows: any[]): {
|
|
230
|
+
empty: true;
|
|
231
|
+
why: string;
|
|
232
|
+
} | {
|
|
233
|
+
empty: false;
|
|
234
|
+
rounds: number;
|
|
235
|
+
tokensIn: number | null;
|
|
236
|
+
tokensInWhy: string | null;
|
|
237
|
+
tokensOut: number | null;
|
|
238
|
+
tokensOutWhy: string | null;
|
|
239
|
+
cacheReadTokens: number | null;
|
|
240
|
+
cacheReadTokensWhy: string | null;
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* `GET /api/runs` — every flow under `root`, every run under each flow
|
|
244
|
+
* (M4a scope item 2). A flow with zero runs still gets one row (`runId:
|
|
245
|
+
* null`, an explicit `why`) — no flow is silently missing from the list.
|
|
246
|
+
* Newest-first by history `at` where known; a row with no history row (died
|
|
247
|
+
* or still parked) sorts after every row that has one, in flow/run order
|
|
248
|
+
* (a real ordering, never `Date.now()` guessed in for a missing `at`).
|
|
249
|
+
* @param {{root: string, catalogue: any}} opts
|
|
250
|
+
* @returns {any[]}
|
|
251
|
+
*/
|
|
252
|
+
export function listRuns({ root, catalogue }: {
|
|
253
|
+
root: string;
|
|
254
|
+
catalogue: any;
|
|
255
|
+
}): any[];
|
|
256
|
+
/**
|
|
257
|
+
* `GET /api/runs/:flow/:runId` — the Run tab (M4a scope item 2): the step
|
|
258
|
+
* map from `declaration.steps`, step cards -> attempts from `audit.jsonl`
|
|
259
|
+
* (verdict, gap, cost, model, strike), and what the model wrote from
|
|
260
|
+
* `log.json`. `null` when the flow/runId doesn't resolve to a real run
|
|
261
|
+
* directory at all (caller renders 404); a `red` field names why a
|
|
262
|
+
* sub-derivation couldn't fill (never invented).
|
|
263
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
264
|
+
* @returns {any|null}
|
|
265
|
+
*/
|
|
266
|
+
export function getRunDetail({ root, flow, runId, catalogue, }: {
|
|
267
|
+
root: string;
|
|
268
|
+
flow: string;
|
|
269
|
+
runId: string;
|
|
270
|
+
catalogue: any;
|
|
271
|
+
}): any | null;
|
|
272
|
+
/**
|
|
273
|
+
* `GET /api/runs/:flow/:runId/audit` — the Audit/logs tab (M4a scope item
|
|
274
|
+
* 2): the raw `audit.jsonl` rows, scoped strictly to this run (each run's
|
|
275
|
+
* own `audit.jsonl` file already carries only its own rows — there is no
|
|
276
|
+
* shared-sidecar contamination risk here the way bareloop's gate-audit
|
|
277
|
+
* sidecar had). `null` when the flow/runId doesn't resolve (404).
|
|
278
|
+
* @param {{root: string, flow: string, runId: string}} opts
|
|
279
|
+
* @returns {{flow:string, runId:string, rows:any[], groups:any[], empty:boolean, why:string|null}|null}
|
|
280
|
+
*/
|
|
281
|
+
export function getRunAudit({ root, flow, runId }: {
|
|
282
|
+
root: string;
|
|
283
|
+
flow: string;
|
|
284
|
+
runId: string;
|
|
285
|
+
}): {
|
|
286
|
+
flow: string;
|
|
287
|
+
runId: string;
|
|
288
|
+
rows: any[];
|
|
289
|
+
groups: any[];
|
|
290
|
+
empty: boolean;
|
|
291
|
+
why: string | null;
|
|
292
|
+
} | null;
|
|
293
|
+
/**
|
|
294
|
+
* `GET /api/runs/:flow/:runId/job` — the Job tab (M4a scope item 2): the
|
|
295
|
+
* signed prose, the arbiter block (cap, asks with TTL, redo cap, sends,
|
|
296
|
+
* sources), and the signature (who, when, hash). Derived purely from the
|
|
297
|
+
* flow's own signed files (`readFlow`) — fwdloop always has exactly one
|
|
298
|
+
* signed `declaration.json` + `signature.json` per flow, so there is no
|
|
299
|
+
* multi-source provenance chain to resolve (unlike bareloop's `getRunJob` —
|
|
300
|
+
* DROPPED per the fit-check). `runId` is only used to confirm the run
|
|
301
|
+
* exists at all; `null` when it doesn't (404).
|
|
302
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
303
|
+
* @returns {any|null}
|
|
304
|
+
*/
|
|
305
|
+
/**
|
|
306
|
+
* hamr's 2026-09-27 exit-check review #5: one plain-words sentence for a
|
|
307
|
+
* declared step's own close rule — the Job tab's "Success" field. Derived
|
|
308
|
+
* STRICTLY from `step.close` (and, for the "your accept" wording, whether
|
|
309
|
+
* this step is the one line `arbiter.asks[]` itself binds to) — never a
|
|
310
|
+
* fabricated cite/shape value:
|
|
311
|
+
* - `hitl`: "human check", or "human check (your accept)" when this step's
|
|
312
|
+
* own `fromLine` is a signed ask line (the ask step itself — the one a
|
|
313
|
+
* human pauses a run on, distinct from an ordinary hitl pass-through
|
|
314
|
+
* step with no ask binding).
|
|
315
|
+
* - `softgreen`: "shape: N headings (a / b / c)" when `close.shape.sections`
|
|
316
|
+
* is signed, "max W words" appended when `close.shape.maxWords` is
|
|
317
|
+
* signed, "blocks of L lines" / "must carry: a, b" for the invoice-block
|
|
318
|
+
* shape keys (`linesPerInvoice`/`mustCarry`) — every signed shape key
|
|
319
|
+
* shown, nothing invented; "shape (no shape rules signed)" when a
|
|
320
|
+
* softgreen step signs no `close.shape` at all (declaration.js allows
|
|
321
|
+
* this — an empty/absent shape is not itself a red).
|
|
322
|
+
* - `green`: "cited" — `CLOSE_ALLOWED` (`src/declaration.js`) never lets a
|
|
323
|
+
* step declare WHAT it cites ahead of time (that's the drafted
|
|
324
|
+
* artifact's own per-run field data, not signed prose), so there is
|
|
325
|
+
* never anything honest to append here.
|
|
326
|
+
* - anything else: the raw class name, named as unknown, never silently
|
|
327
|
+
* dropped or guessed into one of the three above; no class at all names
|
|
328
|
+
* that plainly too.
|
|
329
|
+
* @param {{close?: {class?: string, shape?: any}, fromLine?: number|null}} step one `declaration.steps` entry
|
|
330
|
+
* @param {Array<{line:number}>} arbiterAsks `arbiter.asks`, for the "your accept" check
|
|
331
|
+
* @returns {string}
|
|
332
|
+
*/
|
|
333
|
+
export function deriveStepSuccessText(step: {
|
|
334
|
+
close?: {
|
|
335
|
+
class?: string;
|
|
336
|
+
shape?: any;
|
|
337
|
+
};
|
|
338
|
+
fromLine?: number | null;
|
|
339
|
+
}, arbiterAsks: Array<{
|
|
340
|
+
line: number;
|
|
341
|
+
}>): string;
|
|
342
|
+
/**
|
|
343
|
+
* `GET /api/runs/:flow/:runId/job` — the Job tab (hamr's 2026-09-27
|
|
344
|
+
* exit-check review #5: bareloop-style one-field-per-piece layout,
|
|
345
|
+
* replacing the old split asks/sends/sources/signed-lines blocks). Every
|
|
346
|
+
* field is read straight off `readFlow`'s own signed declaration.json/
|
|
347
|
+
* signature.json/prose lines — nothing invented; a piece the books can't
|
|
348
|
+
* name carries its own why, never a blank or a guess. Field order (server
|
|
349
|
+
* order matches the page's own render order): prose, asks, model, cap
|
|
350
|
+
* (+redo cap), sources, sends, guardrails, success (one row per step, off
|
|
351
|
+
* `deriveStepSuccessText`), signature.
|
|
352
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
353
|
+
* @returns {any|null}
|
|
354
|
+
*/
|
|
355
|
+
export function getRunJob({ root, flow, runId, catalogue, }: {
|
|
356
|
+
root: string;
|
|
357
|
+
flow: string;
|
|
358
|
+
runId: string;
|
|
359
|
+
catalogue: any;
|
|
360
|
+
}): any | null;
|
|
361
|
+
/**
|
|
362
|
+
* hamr's 2026-09-27 exit-check review #3: which declared step (and its
|
|
363
|
+
* signed prose line) each ask in `orderedAsks` belongs to — no book field
|
|
364
|
+
* names this directly (`ask.json`/the archive carry only question/evidence,
|
|
365
|
+
* never a step id), so this is derived by POSITION, the same honest
|
|
366
|
+
* correlation technique this module already uses for `afterReject`
|
|
367
|
+
* (`getRunDetail`, above): `src/runner.js`'s `runAskSlot` writes exactly one
|
|
368
|
+
* `verdict:'paused'` audit row per park, in the SAME real-time order the
|
|
369
|
+
* asks themselves were parked in, and that row's own `step` field (set by
|
|
370
|
+
* `makeAuditRow` from the step object's `emits`) names the real step. Paired
|
|
371
|
+
* 1:1, in order, with `orderedAsks` (already sorted oldest-askedAt-first) —
|
|
372
|
+
* NEVER when the counts disagree (a crash between the ask.json/archive write
|
|
373
|
+
* and the audit-row write, or a pre-M4a-1 run with no paused rows at all
|
|
374
|
+
* left to correlate): every entry gets `step:null, line:null` with a stated
|
|
375
|
+
* why, rather than a guessed pairing. `line` is read off the matching
|
|
376
|
+
* `declaration.steps` entry's own `fromLine` (`src/declaration.js`) — never
|
|
377
|
+
* invented when no step matches the paused row's name.
|
|
378
|
+
* @param {any[]} orderedAsks `runAsksInOrder`'s own return, oldest-first
|
|
379
|
+
* @param {any[]} auditRows this run's own `audit.jsonl` rows, book order
|
|
380
|
+
* @param {any[]|null} declSteps `readFlow(...).declaration.steps`, or null
|
|
381
|
+
* when the flow itself didn't resolve
|
|
382
|
+
* @returns {Array<{step:string|null, line:number|null, why:string|null}>}
|
|
383
|
+
*/
|
|
384
|
+
export function deriveAskStepInfo(orderedAsks: any[], auditRows: any[], declSteps: any[] | null): Array<{
|
|
385
|
+
step: string | null;
|
|
386
|
+
line: number | null;
|
|
387
|
+
why: string | null;
|
|
388
|
+
}>;
|
|
389
|
+
/**
|
|
390
|
+
* `GET /api/runs/:flow/:runId/asks` — the Ask tab (M4a-1 scope item 1):
|
|
391
|
+
* every ask this run's books can name, in order, each carrying full
|
|
392
|
+
* evidence (`readAskEvidence`'s draft + unjudged, or the pre-M4a-1 `why`).
|
|
393
|
+
* `null` when the flow/runId doesn't resolve (caller renders 404).
|
|
394
|
+
*
|
|
395
|
+
* hamr's 2026-09-27 exit-check review #3: each ask also carries `index`/
|
|
396
|
+
* `total` (its own 1-based position among this run's own asks, e.g. "2 of
|
|
397
|
+
* 3" — a plain array position, not derived from any book) and `stepName`/
|
|
398
|
+
* `stepLine`/`stepWhy` (`deriveAskStepInfo`) so the Ask tab's header can
|
|
399
|
+
* name which ask is open without the client re-deriving any of it.
|
|
400
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
401
|
+
* @returns {{flow:string, runId:string, asks:any[]}|null}
|
|
402
|
+
*/
|
|
403
|
+
export function getRunAsks({ root, flow, runId, catalogue, }: {
|
|
404
|
+
root: string;
|
|
405
|
+
flow: string;
|
|
406
|
+
runId: string;
|
|
407
|
+
catalogue: any;
|
|
408
|
+
}): {
|
|
409
|
+
flow: string;
|
|
410
|
+
runId: string;
|
|
411
|
+
asks: any[];
|
|
412
|
+
} | null;
|
|
413
|
+
/**
|
|
414
|
+
* `GET /api/inbox` — every stop (parked ask, open or past) across every
|
|
415
|
+
* flow under `root` (M4a-1 scope item 1), read-only, no answer controls
|
|
416
|
+
* (those are M4b). Sorted open-first (soonest-expiring first — the most
|
|
417
|
+
* urgent), then every past stop newest-answered-first; a row with neither a
|
|
418
|
+
* known time-left nor a known answeredAt sorts last within its group rather
|
|
419
|
+
* than being guessed into either end.
|
|
420
|
+
*
|
|
421
|
+
* hamr's 2026-09-27 live check: a run that has ended (its flow's own
|
|
422
|
+
* history.jsonl carries a row for it) never contributes an open/unanswered
|
|
423
|
+
* stop, no matter what its own ask.json/archive says — `legacyRunAsks`
|
|
424
|
+
* already refuses to rebuild a stale slot into one, but `open` is ALSO
|
|
425
|
+
* force-`false` here as a second, independent check (belt-and-braces on the
|
|
426
|
+
* one thing the brief calls out by name: "the Inbox tab's open count counts
|
|
427
|
+
* only truly open asks — parked run, no history row, unexpired, unanswered").
|
|
428
|
+
* @param {{root: string}} opts
|
|
429
|
+
* @returns {any[]}
|
|
430
|
+
*/
|
|
431
|
+
export function listStops({ root }: {
|
|
432
|
+
root: string;
|
|
433
|
+
}): any[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handle one request against the read-only API + the page. Exported
|
|
3
|
+
* separately from {@link createPanelServer} so tests can drive it without a
|
|
4
|
+
* real listening socket where that is simpler.
|
|
5
|
+
* @param {import('node:http').IncomingMessage} req
|
|
6
|
+
* @param {import('node:http').ServerResponse} res
|
|
7
|
+
* @param {{ root: string, port: number }} opts
|
|
8
|
+
*/
|
|
9
|
+
export function handleRequest(req: import("node:http").IncomingMessage, res: import("node:http").ServerResponse, opts: {
|
|
10
|
+
root: string;
|
|
11
|
+
port: number;
|
|
12
|
+
}): void;
|
|
13
|
+
/**
|
|
14
|
+
* Start the panel server. Binds `127.0.0.1` ONLY. A taken port is a LOUD,
|
|
15
|
+
* non-zero-exit failure — this never falls back to another port (see file
|
|
16
|
+
* header). Resolves once actually listening; rejects on a bind error
|
|
17
|
+
* (including `EADDRINUSE`) with a `.port` field on the error for the
|
|
18
|
+
* caller's message.
|
|
19
|
+
* @param {{ port?: number, root: string }} opts
|
|
20
|
+
* @returns {Promise<{ server: import('node:http').Server, port: number, close: () => Promise<void> }>}
|
|
21
|
+
*/
|
|
22
|
+
export function createPanelServer(opts: {
|
|
23
|
+
port?: number;
|
|
24
|
+
root: string;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
server: import("node:http").Server;
|
|
27
|
+
port: number;
|
|
28
|
+
close: () => Promise<void>;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* `fwdloop panel [--port N] [--root <dir>]` — the CLI entry (`bin/fwdloop`
|
|
32
|
+
* dispatch). Never picks a different port on collision (see file header):
|
|
33
|
+
* prints a loud, named error to stderr and returns 1.
|
|
34
|
+
* @param {string[]} argv
|
|
35
|
+
* @param {{ out: (s: string) => void, err: (s: string) => void }} ctx
|
|
36
|
+
* @returns {Promise<number>}
|
|
37
|
+
*/
|
|
38
|
+
export function panelMain(argv: string[], ctx: {
|
|
39
|
+
out: (s: string) => void;
|
|
40
|
+
err: (s: string) => void;
|
|
41
|
+
}): Promise<number>;
|
|
42
|
+
/** Default bind port. Ruling, hamr 2026-09-27: fwdloop's panel default port
|
|
43
|
+
* is 4800 — bareloop owns 4700, and the two panels must be able to run
|
|
44
|
+
* side by side. */
|
|
45
|
+
export const DEFAULT_PORT: 4800;
|
package/types/primitives.d.ts
CHANGED
|
@@ -24,3 +24,32 @@ export function resolvePrimitives(catalogue: import("./types.js").CatalogueEntry
|
|
|
24
24
|
tools: Record<string, any>;
|
|
25
25
|
reds: string[];
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a model-given path string against `runDir` and pass it through the
|
|
29
|
+
* step's bareguard `Gate`. A `~`-prefixed or already-absolute path is handed
|
|
30
|
+
* to `resolveToolPath` as-is (it expands `~`/normalizes); anything else is
|
|
31
|
+
* joined onto `runDir` first, THEN resolved — so a relative path always
|
|
32
|
+
* lands inside the run dir before the gate ever sees it, matching
|
|
33
|
+
* bareguard's own "agent paths must be absolute" rule (`fs.invalidPath`
|
|
34
|
+
* otherwise). The SAME resolved string that was checked is what the caller
|
|
35
|
+
* must hand to the real tool's `execute` — never re-derive a second string
|
|
36
|
+
* after the decision (F48's own re-check rule: check and open the same
|
|
37
|
+
* value). Throws naming the verb, the path, and bareguard's own rule name
|
|
38
|
+
* on a deny; returns the resolved path on allow.
|
|
39
|
+
*/
|
|
40
|
+
/** Typed carrier for a bareguard fs-gate deny: `model-step` catches it by
|
|
41
|
+
* `instanceof` and records `{verb, path, rule}` on the attempt's audit row —
|
|
42
|
+
* never parsed back out of the message string. */
|
|
43
|
+
export class GateRefusal extends Error {
|
|
44
|
+
constructor(verb: any, resolved: any, rule: any);
|
|
45
|
+
verb: any;
|
|
46
|
+
path: any;
|
|
47
|
+
rule: any;
|
|
48
|
+
}
|
|
49
|
+
/** The verbs this piece actually implements (the switch below, as data) —
|
|
50
|
+
* one writer for "is this verb wired": `resolvePrimitives`'s own reds use
|
|
51
|
+
* it, and `src/runner.js`'s preflight (F46: a step granted a
|
|
52
|
+
* catalogue-present-but-unwired verb, e.g. litectx's `compress`, must
|
|
53
|
+
* refuse before any model call or spend) imports this SAME set rather than
|
|
54
|
+
* keeping a second copy of the list. */
|
|
55
|
+
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;
|
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"). */
|