fwdloop 0.15.0 → 0.16.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.
Files changed (52) hide show
  1. package/bin/fwdloop +106 -31
  2. package/package.json +2 -2
  3. package/src/authoring.js +23 -11
  4. package/src/closers.js +5 -0
  5. package/src/config.js +66 -4
  6. package/src/declaration.js +25 -1
  7. package/src/draft-steps.js +79 -0
  8. package/src/drafter.js +54 -15
  9. package/src/flowmodel.js +30 -0
  10. package/src/input-facts.js +12 -3
  11. package/src/keysfile.js +51 -16
  12. package/src/model-step.js +13 -11
  13. package/src/monthly.js +9 -1
  14. package/src/panel/author.js +81 -22
  15. package/src/panel/authorcard.js +25 -17
  16. package/src/panel/authorflows.js +33 -18
  17. package/src/panel/authorresume.js +9 -8
  18. package/src/panel/authorstart.js +11 -9
  19. package/src/panel/data.js +3 -3
  20. package/src/panel/index.html +516 -146
  21. package/src/panel/resume.js +3 -3
  22. package/src/panel/server.js +4 -3
  23. package/src/panel/settings.js +138 -80
  24. package/src/panel/spawn.js +15 -9
  25. package/src/provider.js +136 -178
  26. package/src/providershapes.js +7 -7
  27. package/src/runner.js +38 -22
  28. package/src/thinking.js +55 -0
  29. package/types/authoring.d.ts +11 -4
  30. package/types/closers.d.ts +2 -0
  31. package/types/config.d.ts +9 -1
  32. package/types/draft-steps.d.ts +14 -0
  33. package/types/drafter.d.ts +13 -10
  34. package/types/flowmodel.d.ts +16 -0
  35. package/types/input-facts.d.ts +6 -1
  36. package/types/keysfile.d.ts +23 -6
  37. package/types/model-step.d.ts +1 -1
  38. package/types/monthly.d.ts +1 -0
  39. package/types/panel/author.d.ts +44 -6
  40. package/types/panel/authorcard.d.ts +21 -8
  41. package/types/panel/authorflows.d.ts +29 -6
  42. package/types/panel/authorresume.d.ts +2 -1
  43. package/types/panel/authorstart.d.ts +16 -6
  44. package/types/panel/data.d.ts +2 -2
  45. package/types/panel/resume.d.ts +2 -1
  46. package/types/panel/server.d.ts +3 -1
  47. package/types/panel/settings.d.ts +3 -1
  48. package/types/panel/spawn.d.ts +13 -4
  49. package/types/provider.d.ts +94 -284
  50. package/types/providershapes.d.ts +3 -4
  51. package/types/runner.d.ts +2 -4
  52. package/types/thinking.d.ts +25 -0
@@ -38,7 +38,8 @@ import { fileURLToPath } from 'node:url';
38
38
  import {
39
39
  ANSWER_FILE, NOT_CHECKED_FILE, OPEN_QUESTION_SAY, PANEL_DRAFTS_DIR, readQuestions, readoutHeadIndexes, scrub, signDraft,
40
40
  } from '../authoring.js';
41
- import { nextRunId, readFileInside, readdirInside } from '../flow.js';
41
+ import { checkFlowName, nextRunId, readFileInside, readdirInside } from '../flow.js';
42
+ import { readModelRecord } from '../flowmodel.js';
42
43
  import { isFwdloopAlive } from '../liveness.js';
43
44
  import {
44
45
  checkMonthlyRoom, ConfigError, monthlyNote, monthlyRefusalText,
@@ -47,7 +48,12 @@ import {
47
48
  appendAnswersToJob, capFloorText, capFloorUsd, cardFields, checkCard, checkInputRows, parseInputLines, parseJobBox,
48
49
  } from './authorcard.js';
49
50
  import { checkedLines, notCheckedBlock } from '../checked.js';
51
+ import {
52
+ readPriceConfig, resolveSlot, resolveUsableModel, tickedLines,
53
+ } from '../provider.js';
54
+ import { thinkingSupport as bareagentThinkingSupport, THINKING_FIXED_SAY, THINKING_UNVERIFIED_SAY } from '../thinking.js';
50
55
  import { parseSignedText } from '../signed-text.js';
56
+ import { draftStepList } from '../draft-steps.js';
51
57
  import { leastResumeCapUsd } from './authorvalues.js';
52
58
  import { createFlowsDoor } from './authorflows.js';
53
59
  import { createResumeDoor } from './authorresume.js';
@@ -84,23 +90,23 @@ const KILL_HARD_WAIT_MS = 2000;
84
90
  const sleep = (ms) => new Promise((r) => { setTimeout(r, ms); });
85
91
 
86
92
  /**
87
- * @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, bin?: string, childRunning?: (dir: string) => boolean }} opts
93
+ * @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null, keyNames?: string[] }, bin?: string, childRunning?: (dir: string) => boolean, thinkingSupport?: typeof bareagentThinkingSupport }} opts
88
94
  * `loadEnv` is the keys-file door (`keysForDoor`): called before EVERY spawn and every reply that quotes a log, so editing
89
95
  * the file needs no restart. Its `env` is BOTH the child's spawn env AND the scrub list (POC (a), M4d wiring rule).
90
96
  */
91
97
  export function createAuthor(opts) {
92
98
  const {
93
- root, loadEnv, home, skipMonthly = false, bin = BIN, childRunning = childRunningNow,
99
+ root, loadEnv, home, skipMonthly = false, bin = BIN, childRunning = childRunningNow, thinkingSupport = bareagentThinkingSupport,
94
100
  } = opts;
95
101
  // the ONE run-start path (sign and run both end in `starter.start`) and the Run-a-signed-flow door built on it
96
102
  const starter = createStarter({ root, bin });
97
103
  const flowsDoor = createFlowsDoor({
98
- root, home, skipMonthly, loadEnv, starter, monthlyClaim: (usd) => monthlyClaim(usd),
104
+ root, home, skipMonthly, loadEnv, starter, monthlyClaim: (usd) => monthlyClaim(usd), modelRefusal: (card, loaded) => modelRefusal(card, loaded),
99
105
  });
100
106
 
101
107
  /** The ONE monthly check, defined below (a function declaration, so the doors above may take it now). */
102
108
  const resumeDoor = createResumeDoor({
103
- root, loadEnv, monthlyClaim: (usd) => monthlyClaim(usd), starter,
109
+ root, home, loadEnv, monthlyClaim: (usd) => monthlyClaim(usd), starter,
104
110
  });
105
111
 
106
112
  /** The drafts folder's real path, or null when the flows root does not exist. */
@@ -152,6 +158,19 @@ export function createAuthor(opts) {
152
158
  return logText.ok ? scrub(logText.text, keys).trim().slice(-LOG_TAIL_CHARS).replace(/^fwdloop: /, '') : '';
153
159
  }
154
160
 
161
+ /**
162
+ * M4d am10: the Chat list of what this plan's draft really did, READ from its log.json and declaration (never from the readout, which is signed text),
163
+ * built by the ONE function `draftStepList`; every string scrubbed. `null` when the draft left no log (the page then lists what it always did).
164
+ * @param {string} dir @param {string} rel @param {string[]} keys
165
+ */
166
+ function stepListOf(dir, rel, keys) {
167
+ const declaration = readJson(dir, `${rel}/declaration.json`) ?? readJson(dir, `${rel}/declaration.rejected.json`);
168
+ const list = draftStepList({ log: readJson(dir, `${rel}/log.json`), declaration });
169
+ if (list === null) return null;
170
+ const sc = (x) => scrub(String(x), keys);
171
+ return list.map((st) => ({ ...st, label: sc(st.label), details: st.details.map(sc), ...(st.reds ? { reds: st.reds.map(sc) } : {}) }));
172
+ }
173
+
155
174
  /**
156
175
  * One plan folder's result, READ from its files: green (spec.hash), red (a log that says not ok, or a leak marker), or null (no result yet).
157
176
  * @param {string} dir the draft folder @param {string} rel `draft` or `draft-<n>` @param {string[]} keys
@@ -162,14 +181,14 @@ export function createAuthor(opts) {
162
181
  if (hashFile.ok && hashFile.text.trim() !== '') {
163
182
  const readout = readFileInside(dir, `${rel}/readout.txt`);
164
183
  const text = readout.ok ? scrub(readout.text, keys) : '';
165
- return { phase: 'green', hash: hashFile.text.trim(), readout: text, readoutHeads: readoutHeadIndexes(text) };
184
+ return { phase: 'green', hash: hashFile.text.trim(), readout: text, readoutHeads: readoutHeadIndexes(text), stepList: stepListOf(dir, rel, keys) };
166
185
  }
167
186
  const leak = readFileInside(dir, `${rel}/scrub-leak.red`);
168
187
  const log = readJson(dir, `${rel}/log.json`);
169
188
  if (leak.ok || (log && log.ok === false)) {
170
189
  const reds = Array.isArray(log?.reds) ? log.reds.map((r) => scrub(String(r), keys)) : [];
171
190
  if (leak.ok) reds.push(scrub(leak.text.trim(), keys));
172
- return { phase: 'red', reds, say: RED_SAY };
191
+ return { phase: 'red', reds, say: RED_SAY, stepList: stepListOf(dir, rel, keys) };
173
192
  }
174
193
  return null;
175
194
  }
@@ -201,7 +220,7 @@ export function createAuthor(opts) {
201
220
  return { n, kind, phase: 'stopped', say: logTail(dir, `${kind === 'answers' ? 'redraft' : 'revise'}-${n}.log`, keys) || STOPPED_SAY };
202
221
  });
203
222
  const cur = /** @type {{ phase: string, kind: string, say?: string }} */ (newest > 0 ? revises[revises.length - 1] : { phase: first.phase, kind: 'first' });
204
- const shared = { ...base, card, revises, revisesLeft };
223
+ const shared = { ...base, card, revises, revisesLeft, stepList: first.stepList ?? null };
205
224
  const rel = newest > 0 ? `draft-${newest}` : 'draft';
206
225
  if (cur.phase === 'running') return { ...shared, phase: cur.kind === 'answers' ? 'redrafting' : 'revising' };
207
226
  if (cur.phase === 'stopped') return { ...shared, phase: 'stopped', say: cur.say };
@@ -257,7 +276,7 @@ export function createAuthor(opts) {
257
276
  /** The one request-time read of the keys door: the merged env (scrub list + child env) or null on its refusal. */
258
277
  const keysNow = () => {
259
278
  const loaded = loadEnv();
260
- return { loaded, keys: providerKeys(loaded.env) };
279
+ return { loaded, keys: providerKeys(loaded) };
261
280
  };
262
281
 
263
282
  /**
@@ -282,16 +301,38 @@ export function createAuthor(opts) {
282
301
  };
283
302
  }
284
303
 
304
+ /**
305
+ * M4d amendment 6 item 6: the model the card picked must still be a ticked, priced line of a provider that has its key set up; nothing ticked says
306
+ * what to do. `[]` = fine. Reads Settings now, at the click: a line unticked since Chat drew its menu is refused by name, at $0.
307
+ * @param {any} card @param {{ keyNames?: string[] }} loaded @returns {{ field: string, say: string }[]}
308
+ */
309
+ function modelRefusal(card, loaded) {
310
+ const no = (say) => [{ field: 'model', say }];
311
+ let config;
312
+ try { config = readPriceConfig(home); } catch { return no('Your settings file (config.json) cannot be read. Fix or remove it, then look again. Nothing was spent.'); }
313
+ const rows = loaded.keyNames ?? [];
314
+ if (typeof card.provider !== 'string' || card.provider === '' || typeof card.model !== 'string' || card.model === '') {
315
+ return no(tickedLines(config, rows).length === 0 ? 'Tick a model in Settings > Providers. Nothing was spent.' : 'Pick a model. Nothing was spent.');
316
+ }
317
+ if (!rows.includes(card.provider)) return no(`${card.provider} is not set up: put its key in your keys file and type its Base URL in Settings > Providers. Nothing was spent.`);
318
+ const u = resolveUsableModel(card.provider, { config, model: card.model });
319
+ return u.ok ? [] : no(`${u.say} Nothing was spent.`);
320
+ }
321
+
322
+ /** The flags that make a draft child use the card's model and thinking choice. @param {any} card */
323
+ const modelArgv = (card) => ['--model', card.model, '--provider', card.provider, ...(card.thinking === true ? ['--thinking'] : [])];
324
+
285
325
  /**
286
326
  * The $0 checks both a first draft and a revise run on the card as submitted: the card's own checks (a key value, the flow name,
287
327
  * every field), then the monthly room for its cap. `{ ok: true, card, prose }` or `{ ok: false, reply }`. Writes nothing.
288
- * @param {any} body @param {{ ok: boolean, env: Record<string, string|undefined> }} loaded
328
+ * @param {any} body @param {{ ok: boolean, env: Record<string, string|undefined>, keyNames?: string[] }} loaded
289
329
  * @returns {{ ok: true, card: any, prose: string }|{ ok: false, reply: { status: number, body: any } }}
290
330
  */
291
331
  function vetCard(body, loaded) {
292
332
  const card = cardFields(body);
293
- const checked = checkCard(card, { root: realpathSync(root), env: loaded.env });
294
- if (!checked.ok) return { ok: false, reply: { status: 400, body: { ok: false, refused: 'card', refusals: checked.refusals } } };
333
+ const checked = checkCard(card, { root: realpathSync(root), keys: providerKeys(loaded), home });
334
+ const modelSays = modelRefusal(card, loaded);
335
+ if (!checked.ok || modelSays.length > 0) return { ok: false, reply: { status: 400, body: { ok: false, refused: 'card', refusals: [...(checked.ok ? [] : checked.refusals), ...modelSays] } } };
295
336
  // amendment 4 item 1: a cap that does not fit this month refuses here too, at $0, with the one refusal text (the page's red note is only a courtesy)
296
337
  const claim = monthlyClaim(Number(card.capUsd));
297
338
  if (claim && 'problem' in claim) return { ok: false, reply: { status: 409, body: { ok: false, refused: 'monthly', say: `${claim.problem} — refusing rather than guess the monthly limit. Nothing spent.` } } };
@@ -312,11 +353,13 @@ export function createAuthor(opts) {
312
353
  * `GET /api/author/monthly-check?cap=<usd>`: the note under Cap, one read-only check. `{ text, red }` is what to show (red =
313
354
  * the cap does not fit this month); `floorUsd` is the smallest cap that funds one round of a model step, for the page's
314
355
  * `needs at least $X per run` line. A cap that is not a number above 0 gets no note. Never spends, never writes.
315
- * @param {unknown} cap @param {string|null} [spent] what a resumed run has already spent (amendment 4 item 4)
356
+ * @param {unknown} cap @param {string|null} [spent] what a resumed run has already spent (amendment 4 item 4) @param {{ provider?: string, model?: string, flow?: string }|null} [pick] the card's picked model, or (a Resume) the flow whose recorded model it is: its own prices are the floor (M4d am6)
316
357
  */
317
- monthlyCheck(cap, spent = null) {
358
+ monthlyCheck(cap, spent = null, pick = null) {
318
359
  const n = Number(cap);
319
- const floorUsd = capFloorUsd('x');
360
+ // a Resume names its flow: the model recorded beside the signed job is the one whose prices are the floor
361
+ const recorded = pick?.flow !== undefined && checkFlowName(pick.flow).ok ? readModelRecord(join(root, pick.flow)) : null;
362
+ const floorUsd = capFloorUsd('x', home, recorded ?? pick);
320
363
  if (typeof cap !== 'string' || cap.trim() === '' || !Number.isFinite(n) || n <= 0) return { status: 200, body: { ok: true, text: '', red: false, floorUsd, floorText: capFloorText(floorUsd) } };
321
364
  // a Resume (amendment 4 item 1): only what the run still has to spend is held, so the note asks for `cap - spent`; a cap not above
322
365
  // what is spent says so in the door's own words (red)
@@ -329,6 +372,22 @@ export function createAuthor(opts) {
329
372
  return { status: 200, body: { ok: true, ...monthlyNote(claim), floorUsd, floorText: capFloorText(floorUsd) } };
330
373
  },
331
374
 
375
+ /**
376
+ * `GET /api/author/models` (M4d amendment 6 item 6): what Chat's Model menu offers - every ticked, priced line of a provider whose key is set up, as
377
+ * "provider · model" - and, per line, whether "Thinking on" can change (`canChange`; bareagent's answer through `src/thinking.js`, am7). Read-only.
378
+ */
379
+ models() {
380
+ const { loaded } = keysNow();
381
+ let config;
382
+ try { config = readPriceConfig(home); } catch { return { status: 200, body: { ok: true, lines: [], say: 'Your settings file (config.json) cannot be read. Fix or remove it, then look again.' } }; }
383
+ const lines = tickedLines(config, loaded.keyNames ?? []).map((l) => {
384
+ const row = resolveSlot(l.slot, { config });
385
+ const support = thinkingSupport(row.shape, l.model, { baseUrl: row.baseUrl }); // the Base URL lets bareagent resolve the row by its host, as its request path does
386
+ return { ...l, thinking: { support, canChange: support !== false, say: support === false ? THINKING_FIXED_SAY : (support === 'unverified' ? THINKING_UNVERIFIED_SAY : '') } };
387
+ });
388
+ return { status: 200, body: { ok: true, lines, say: lines.length === 0 ? 'Tick a model in Settings > Providers.' : '' } };
389
+ },
390
+
332
391
  /** `GET /api/author/start/:startId`: the start's phase, read from its files. @param {string} id */
333
392
  startGet(id) { return starter.get(id, keysNow().keys); },
334
393
 
@@ -370,7 +429,7 @@ export function createAuthor(opts) {
370
429
  let child;
371
430
  try {
372
431
  child = spawnDetached({
373
- bin, argv: ['draft', proseFile, '--out', join(dir, 'draft'), '--root', realpathSync(root), '--name', card.flowName], env: loaded.env, logPath: join(dir, 'child.log'),
432
+ bin, argv: ['draft', proseFile, '--out', join(dir, 'draft'), '--root', realpathSync(root), '--name', card.flowName, ...modelArgv(card)], env: loaded.env, logPath: join(dir, 'child.log'),
374
433
  });
375
434
  } catch (e) {
376
435
  return { status: 500, body: { ok: false, refused: 'spawn', say: `The draft could not be started (${/** @type {any} */ (e)?.code ?? 'error'}). Nothing was spent.`, draftId: id } };
@@ -412,7 +471,7 @@ export function createAuthor(opts) {
412
471
  const { v, name, dir } = seen;
413
472
  const b = body && typeof body === 'object' ? body : {};
414
473
  // amendment 4 item 2: a cap that cannot fund one round of the first model step is never signed (it would cap-halt at $0 spent)
415
- const floor = capFloorUsd(typeof v.card.job === 'string' ? v.card.job : '');
474
+ const floor = capFloorUsd(typeof v.card.job === 'string' ? v.card.job : '', home, v.card);
416
475
  if (Number(v.card.capUsd) < floor) return { status: 400, body: { ok: false, refused: 'cap-too-small', say: capFloorText(floor) } };
417
476
  if (typeof b.hash !== 'string' || b.hash !== v.hash) {
418
477
  return { status: 409, body: { ok: false, refused: 'stale-hash', say: 'The plan on disk is not the one you were shown (its hash differs). Nothing was signed. Reload and read the plan again.' } };
@@ -435,10 +494,10 @@ export function createAuthor(opts) {
435
494
  const editBlock = editOf !== null ? flowsDoor.editBlock(name) : null;
436
495
  if (editBlock !== null) return { status: 409, body: { ok: false, refused: 'run-live', say: editBlock } };
437
496
  const result = signDraft({
438
- dir: join(dir, v.plan), approve: v.hash, signedBy, env: loaded.env, sessionDir: dir, replaces: editOf !== null ? { flowHash: String(editOf.flowHash) } : undefined,
497
+ dir: join(dir, v.plan), approve: v.hash, signedBy, env: loaded.env, keyNames: loaded.keyNames, sessionDir: dir, replaces: editOf !== null ? { flowHash: String(editOf.flowHash) } : undefined,
439
498
  });
440
499
  if (!result.ok) {
441
- const keys = providerKeys(loaded.env);
500
+ const keys = providerKeys(loaded);
442
501
  return { status: 409, body: { ok: false, refused: 'sign-refused', say: 'The draft did not pass the signing checks. Nothing was signed.', reds: result.reds.map((r) => scrub(String(r), keys)) } };
443
502
  }
444
503
  writeFileSync(join(dir, 'signed.json'), `${JSON.stringify({
@@ -446,7 +505,7 @@ export function createAuthor(opts) {
446
505
  })}\n`, { mode: 0o600 });
447
506
  const started = starter.start({
448
507
  kind: 'sign', flow: name, runId, sources: inputs.map((r) => ({ role: r.role, path: r.path })),
449
- }, loaded.env);
508
+ }, loaded);
450
509
  if (started.status !== 202) return { status: started.status, body: { ...started.body, signed: true, flow: name, say: `${started.body.say ?? 'The run did not start.'} The flow is signed; start it from "Run a signed flow".` } };
451
510
  return { status: 202, body: { ...started.body, signed: true } };
452
511
  },
@@ -493,7 +552,7 @@ export function createAuthor(opts) {
493
552
  try {
494
553
  child = spawnDetached({
495
554
  bin,
496
- argv: ['draft', proseFile, '--out', join(dir, `draft-${n}`), '--root', realpathSync(root), '--name', vet.card.flowName],
555
+ argv: ['draft', proseFile, '--out', join(dir, `draft-${n}`), '--root', realpathSync(root), '--name', vet.card.flowName, ...modelArgv(vet.card)],
497
556
  env: loaded.env,
498
557
  logPath: join(dir, `revise-${n}.log`),
499
558
  });
@@ -565,7 +624,7 @@ export function createAuthor(opts) {
565
624
  writeFileSync(files[2], `${JSON.stringify({ fromPlan: v.plan, answers: redraft.all.map((x) => ({ line: x.line, question: x.question, answer: x.answer })) })}\n`, { mode: 0o600, flag: 'wx' });
566
625
  child = spawnDetached({
567
626
  bin,
568
- argv: ['draft', files[1], '--out', join(dir, `draft-${n}`), '--root', realpathSync(root), '--name', redraft.vet.card.flowName, '--no-questions'],
627
+ argv: ['draft', files[1], '--out', join(dir, `draft-${n}`), '--root', realpathSync(root), '--name', redraft.vet.card.flowName, '--no-questions', ...modelArgv(redraft.vet.card)],
569
628
  env: loaded.env,
570
629
  logPath: join(dir, `redraft-${n}.log`),
571
630
  });
@@ -15,9 +15,9 @@ import {
15
15
  import { isAbsolute, join } from 'node:path';
16
16
 
17
17
  import { checkFlowName, signedHashOf } from '../flow.js';
18
- import { checkSendDestination, resolveCeilingUsd } from '../runner.js';
18
+ import { checkSendDestination } from '../runner.js';
19
19
  import { parseSignedText } from '../signed-text.js';
20
- import { PROVIDER_SLOTS } from '../provider.js';
20
+ import { readPriceConfig, resolveUsableModel, ceilingCostUsd } from '../provider.js';
21
21
 
22
22
  /** The heading line the prose files use (flows/job2-m6a-3/prose.txt); the parser matches `/^arbiter guardrails\b/i`. */
23
23
  export const ARBITER_HEADING = 'Arbiter guardrails (belong to no line; human-signed, tighten-only — never authored or claimed by the drafter):';
@@ -170,6 +170,9 @@ export function cardFields(body) {
170
170
  inputs: str(b.inputs).replace(/\r\n?/g, '\n'),
171
171
  capUsd: typeof b.capUsd === 'string' && b.capUsd.trim() !== '' ? Number(b.capUsd) : b.capUsd,
172
172
  askWait: str(b.askWait).trim(),
173
+ // M4d amendment 6: the picked model (a key name and a model id from Chat's menu) and the per-job "Thinking on" tick; present only when sent
174
+ ...(str(b.provider).trim() !== '' || str(b.model).trim() !== '' ? { provider: str(b.provider).trim(), model: str(b.model).trim() } : {}),
175
+ ...(b.thinking === true ? { thinking: true } : {}),
173
176
  // M6: present only when this card EDITS a signed job: which job, and the signature hash it was opened at
174
177
  ...(typeof b.editOf?.flow === 'string' && typeof b.editOf?.flowHash === 'string' && b.editOf.flowHash !== '' ? { editOf: { flow: b.editOf.flow, flowHash: b.editOf.flowHash } } : {}),
175
178
  };
@@ -286,17 +289,24 @@ export function checkInputRows(rows) {
286
289
  /**
287
290
  * M4e amendment 4 item 2: the smallest per-run cap that funds ONE round of the first model step. The runner halts a step when
288
291
  * `spent + ceiling > cap` (`runStepRalph`), and every ordinary (non-ask) step is a model step, so the floor is the runner's own
289
- * per-round ceiling (`resolveCeilingUsd`) as soon as the job has one such line; a job of only asks spends nothing before its stop.
292
+ * per-round hold (the picked model's own Settings prices times the token bounds) as soon as the job has one such line; a job of only asks spends nothing before its stop.
290
293
  * ONE function: the card's Draft check, Sign, and the page's note all read it. Returns 0 when no step needs a round.
291
- * @param {string} jobText
294
+ * @param {string} jobText @param {string} [home] the config home the panel reads Settings from (default: the process door)
295
+ * @param {{ slot?: string, provider?: string, model?: string }|null} [pick] the job's picked model (M4d amendment 6): its own Settings prices are the hold (a card names its key as `provider`)
292
296
  */
293
- export function capFloorUsd(jobText) {
294
- return capFloorFor(parseJobBox(jobText).steps.some((s) => s.ask === null));
297
+ export function capFloorUsd(jobText, home, pick) {
298
+ return capFloorFor(parseJobBox(jobText).steps.some((s) => s.ask === null), home, pick);
295
299
  }
296
300
 
297
- /** The floor itself, for a caller that already knows whether the job has a step that is not an ask (a signed flow: any step off an ask line). @param {boolean} hasRoundStep */
298
- export function capFloorFor(hasRoundStep) {
299
- return hasRoundStep ? resolveCeilingUsd(null) : 0;
301
+ /** The floor itself, for a caller that already knows whether the job has a step that is not an ask (a signed flow: any step off an ask line). @param {boolean} hasRoundStep @param {string} [home] @param {{ slot?: string, provider?: string, model?: string }|null} [pick] */
302
+ export function capFloorFor(hasRoundStep, home, pick) {
303
+ const slot = pick?.slot ?? pick?.provider;
304
+ if (!hasRoundStep || !slot) return 0;
305
+ // No usable model (nothing picked or ticked, a broken config): nothing is held here, and the run itself is refused by name (`resolveUsableModel`).
306
+ try {
307
+ const u = resolveUsableModel(slot, { config: readPriceConfig(home), model: pick?.model });
308
+ return u.ok ? ceilingCostUsd(u.rates) : 0;
309
+ } catch { return 0; }
300
310
  }
301
311
 
302
312
  /** The one sentence for a cap under the floor (red under Cap, and the Draft / sign refusal). @param {number} floorUsd */
@@ -320,10 +330,10 @@ export function destinationRefusal(dest, root) {
320
330
  /**
321
331
  * Every $0 check on the card, before any spawn (scope 6). Collects all refusals so the page can name every box.
322
332
  * @param {ReturnType<typeof cardFields>} card
323
- * @param {{ root: string, env?: Record<string, string|undefined> }} ctx `env` = the merged keys env: a key value typed into any box is refused
333
+ * @param {{ root: string, keys?: string[], home?: string }} ctx `keys` = the provider key values (the keys load's scrub list): a key value typed into any box is refused; `home` = the config home Settings is read from (the cap floor)
324
334
  * @returns {{ ok: true, prose: string }|{ ok: false, refusals: {field: string, say: string}[] }}
325
335
  */
326
- export function checkCard(card, { root, env = {} }) {
336
+ export function checkCard(card, { root, keys = [], home }) {
327
337
  /** @type {{field: string, say: string}[]} */
328
338
  const refusals = [];
329
339
  const no = (field, say) => refusals.push({ field, say });
@@ -354,7 +364,7 @@ export function checkCard(card, { root, env = {} }) {
354
364
  // cap
355
365
  if (typeof card.capUsd === 'string' || typeof card.capUsd === 'number') {
356
366
  if (!(Number.isFinite(Number(card.capUsd)) && Number(card.capUsd) > 0)) no('capUsd', 'The cap must be a number above 0 (dollars per run).');
357
- else if (Number(card.capUsd) < capFloorUsd(card.job)) no('capUsd', capFloorText(capFloorUsd(card.job)));
367
+ else if (Number(card.capUsd) < capFloorUsd(card.job, home, card)) no('capUsd', capFloorText(capFloorUsd(card.job, home, card)));
358
368
  } else no('capUsd', 'The cap must be a number above 0 (dollars per run).');
359
369
 
360
370
  // destination: one folder, or empty for no send (it is sent at the last step)
@@ -368,12 +378,10 @@ export function checkCard(card, { root, env = {} }) {
368
378
  refusals.push(...checkInputRows(parseInputLines(card.inputs)));
369
379
 
370
380
  // a provider key typed into any box never reaches a file
371
- /** @type {string[]} */
372
- const keys = [];
373
- for (const p of Object.values(PROVIDER_SLOTS)) { const k = env[p.envVar]; if (typeof k === 'string' && k.length >= 8) keys.push(k); }
374
- if (keys.length > 0) {
381
+ const longKeys = keys.filter((k) => k.length >= 8);
382
+ if (longKeys.length > 0) {
375
383
  const boxes = [['job', card.job], ['flowName', card.flowName], ['destination', dest], ['inputs', card.inputs]];
376
- for (const [field, text] of boxes) if (keys.some((k) => String(text).includes(k))) no(String(field), 'This box contains an API key. Keys go in Settings only. Nothing was saved.');
384
+ for (const [field, text] of boxes) if (longKeys.some((k) => String(text).includes(k))) no(String(field), 'This box contains an API key. Keys go in Settings only. Nothing was saved.');
377
385
  }
378
386
 
379
387
  if (refusals.length > 0) return { ok: false, refusals };
@@ -32,6 +32,7 @@ import {
32
32
  import { checkValues } from './authorvalues.js';
33
33
  import { getRunControls } from './data.js';
34
34
  import { providerKeys } from './spawn.js';
35
+ import { readModelRecord, writeModelRecord } from '../flowmodel.js';
35
36
 
36
37
  /** M6 amendment 1: the sentence the page shows and the sign route refuses with, for a job with a run running or waiting at its ask. @param {string} runId */
37
38
  export const editBlockedSay = (runId) => `finish or stop ${runId} first`;
@@ -39,31 +40,35 @@ export const editBlockedSay = (runId) => `finish or stop ${runId} first`;
39
40
  export const EDIT_STARTING_SAY = 'a run is starting';
40
41
  const NO_LIMIT = 'no monthly limit set';
41
42
  /** The body keys a run start takes (amendment 5 item 2): the open boxes plus the hash of the second click. Any other key is refused by name. */
42
- const RUN_KEYS = ['flow', 'inputs', 'runId', 'destination', 'capUsd', 'askWaits', 'hash'];
43
+ const RUN_KEYS = ['flow', 'inputs', 'runId', 'destination', 'capUsd', 'askWaits', 'hash', 'provider', 'model'];
43
44
 
44
45
  /**
45
46
  * What the Run / Resume forms show of a signed flow (read from its own files, never from a model): the job lines as the signed text has them
46
47
  * (an ask line carries its question and its wait), the values the open boxes start from, and the cap floor. Amendment 5 item 2: all the rest is dimmed.
47
- * @param {any} read `readFlow`'s ok result
48
+ * @param {any} read `readFlow`'s ok result @param {string} [home] the config home Settings is read from @param {string} [flowDir] the signed flow's folder: the model recorded beside it is the one it runs with (M4d amendment 6)
49
+ * @param {{ slot: string, model: string }|null} [picked] a flow with no record runs with the model picked in Chat (M4d amendment 7b): its price is the cap floor
48
50
  */
49
- export function formFacts(read) {
51
+ export function formFacts(read, home, flowDir, picked = null) {
50
52
  const asks = new Map((read.arbiter.asks ?? []).map((a) => [a.line, a]));
51
53
  const values = flowValues(read.arbiter);
52
54
  const jobLines = read.lines.map((l) => ({
53
55
  n: l.n, text: l.text, guardrail: l.guardrail || null, ask: asks.has(l.n) ? { wait: values.askWaits[String(l.n)] } : null,
54
56
  }));
55
57
  const hasRound = read.declaration.steps.some((st) => !asks.has(st.fromLine));
58
+ const recorded = flowDir === undefined ? null : readModelRecord(flowDir);
59
+ const pick = recorded ?? picked;
56
60
  return {
57
- values, jobLines, hasSend: values.destination !== null, capFloorUsd: capFloorFor(hasRound), floorText: capFloorText(capFloorFor(hasRound)),
61
+ values, jobLines, hasSend: values.destination !== null, capFloorUsd: capFloorFor(hasRound, home, pick), floorText: capFloorText(capFloorFor(hasRound, home, pick)),
62
+ model: recorded === null ? null : { slot: recorded.slot, model: recorded.model, label: `${recorded.slot} · ${recorded.model}` },
58
63
  };
59
64
  }
60
65
 
61
66
  /**
62
- * @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, starter: ReturnType<typeof import('./authorstart.js').createStarter>, monthlyClaim: (usd: number) => any }} opts
67
+ * @param {{ root: string, home?: string, skipMonthly?: boolean, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, starter: ReturnType<typeof import('./authorstart.js').createStarter>, monthlyClaim: (usd: number) => any, modelRefusal: (card: any, loaded: any) => { field: string, say: string }[] }} opts
63
68
  */
64
69
  export function createFlowsDoor(opts) {
65
70
  const {
66
- root, home, skipMonthly = false, loadEnv, starter, monthlyClaim,
71
+ root, home, skipMonthly = false, loadEnv, starter, monthlyClaim, modelRefusal,
67
72
  } = opts;
68
73
 
69
74
  /** What is left of the monthly limit, as a courtesy line: the limit minus this month's counted spend (holds are the CLI's business). */
@@ -163,9 +168,10 @@ export function createFlowsDoor(opts) {
163
168
  /**
164
169
  * Every $0 check of a run start, shared by `runPrepare` (the first click) and `run`. `{ok:false, reply}` or the facts a start needs.
165
170
  * Amendment 5 items 2-4: the open boxes are Inputs, Destination, Cap $ and each ask's wait; anything else in the body is refused by name.
166
- * @param {any} body
171
+ * @param {any} body @param {any} loaded the keys load
167
172
  */
168
- function inspect(body, keys) {
173
+ function inspect(body, loaded) {
174
+ const keys = providerKeys(loaded);
169
175
  const reply = (status, b) => ({ ok: /** @type {false} */ (false), reply: { status, body: { ok: false, ...b } } });
170
176
  const realRoot = realRootOrNull();
171
177
  if (realRoot === null) return reply(400, { refused: 'root', say: 'The flows folder this panel serves does not exist.' });
@@ -181,12 +187,16 @@ export function createFlowsDoor(opts) {
181
187
  const red = scrub(String(can.red), keys);
182
188
  return reply(409, { refused: 'flow', say: willNotRunSay(flow, red), refusals: [{ field: 'flow', say: willNotRunSay(flow, red) }] });
183
189
  }
190
+ // M4d amendment 7b: a flow with no recorded model takes the one picked in Chat (checked now, at the click); a flow with a record keeps it and ignores the body's pick
191
+ const noRecord = readModelRecord(join(realRoot, flow)) === null;
192
+ const modelReds = noRecord ? modelRefusal({ provider: body?.provider, model: body?.model }, loaded) : [];
193
+ const newPick = noRecord && modelReds.length === 0 ? { slot: body.provider, model: body.model } : null;
184
194
  const checked = checkValues({
185
- allowedKeys: RUN_KEYS, body, base: flowValues(read.arbiter), realRoot, capOnly: false, floorUsd: formFacts(read).capFloorUsd, monthlyClaim,
195
+ allowedKeys: RUN_KEYS, body, base: flowValues(read.arbiter), realRoot, capOnly: false, floorUsd: formFacts(read, home, join(realRoot, flow), newPick).capFloorUsd, monthlyClaim,
186
196
  });
187
197
  if (!checked.ok && checked.refused) return reply(checked.status, { refused: checked.refused, say: checked.say, refusals: checked.refusals });
188
198
  /** @type {{field: string, say: string}[]} */
189
- const refusals = checked.ok ? [] : [...checked.refusals];
199
+ const refusals = checked.ok ? [...modelReds] : [...checked.refusals, ...modelReds];
190
200
  if (!checked.ok && checked.status === 409) return reply(409, { refused: 'monthly', say: checked.say });
191
201
  const rows = runInputRows(body?.inputs);
192
202
  refusals.push(...checkInputRows(rows));
@@ -207,7 +217,7 @@ export function createFlowsDoor(opts) {
207
217
  flow, flowSignatureHash: read.signature.flow, runId: null, version: 0, values: checked.values,
208
218
  });
209
219
  return {
210
- ok: /** @type {true} */ (true), flow, read, declared, rows, runId, values: checked.values, differs: checked.differs, hash,
220
+ ok: /** @type {true} */ (true), flow, read, declared, rows, runId, values: checked.values, differs: checked.differs, hash, newPick, flowDir: join(realRoot, flow),
211
221
  };
212
222
  }
213
223
 
@@ -239,7 +249,7 @@ export function createFlowsDoor(opts) {
239
249
  return {
240
250
  flow: name, capUsd: read.arbiter.capUsd, roles, nextRunId: nextRunId(flowDir), lastRunId: last.runId, lastSources: last.sources, leftThisMonth: left,
241
251
  runs: passed, stats,
242
- ...formFacts(read),
252
+ ...formFacts(read, home, flowDir),
243
253
  // M6: the job as a card to edit (`ok:true, card, flowHash` = the signature hash it is opened at), or why it cannot be (`ok:false, say`)
244
254
  edit: (() => {
245
255
  const blocked = editBlockOf(realRoot, name);
@@ -293,7 +303,7 @@ export function createFlowsDoor(opts) {
293
303
  const readRaw = readSigned(realRoot, flow);
294
304
  const can = canFlowRun(readRaw);
295
305
  if (!can.ok) {
296
- const red = scrub(String(can.red), providerKeys(loadEnv().env));
306
+ const red = scrub(String(can.red), providerKeys(loadEnv()));
297
307
  return no(409, willNotRunSay(flow, red), { red });
298
308
  }
299
309
  const read = /** @type {Extract<typeof readRaw, { ok: true }>} */ (readRaw); // canFlowRun refuses every failed read above
@@ -313,7 +323,7 @@ export function createFlowsDoor(opts) {
313
323
  * @param {any} body
314
324
  */
315
325
  runPrepare(body) {
316
- const s = inspect(body, providerKeys(loadEnv().env));
326
+ const s = inspect(body, loadEnv());
317
327
  if (!s.ok) return s.reply;
318
328
  return {
319
329
  status: 200, body: {
@@ -331,7 +341,7 @@ export function createFlowsDoor(opts) {
331
341
  run(body) {
332
342
  const loaded = loadEnv();
333
343
  if (!loaded.ok) return { status: 409, body: { ok: false, refused: 'keys-file', say: String(loaded.refusal) } };
334
- const s = inspect(body, providerKeys(loaded.env));
344
+ const s = inspect(body, loaded);
335
345
  if (!s.ok) return s.reply;
336
346
  let values = null;
337
347
  if (s.differs) {
@@ -345,9 +355,14 @@ export function createFlowsDoor(opts) {
345
355
  flow: s.flow, flowSignatureHash: s.read.signature.flow, version: 0, values: s.values, hash: s.hash, signedBy: userInfo().username, at: new Date().toISOString(),
346
356
  };
347
357
  }
348
- return starter.start({
349
- kind: 'run', flow: s.flow, runId: s.runId, sources: s.declared.map((role) => ({ role, path: /** @type {{path: string}} */ (s.rows.find((r) => r.role === role)).path })), values,
350
- }, loaded.env);
358
+ const started = starter.start({
359
+ kind: 'run', flow: s.flow, runId: s.runId, sources: s.declared.map((role) => ({ role, path: /** @type {{path: string}} */ (s.rows.find((r) => r.role === role)).path })), values, pick: s.newPick,
360
+ }, loaded);
361
+ // M4d amendment 7b: the pick of a flow that had no record is written only once the start succeeded (a refused start leaves none), beside the signed files, never in them
362
+ if (started.status === 202 && s.newPick !== null) {
363
+ try { writeModelRecord(s.flowDir, s.newPick); } catch { /* a record that appeared meanwhile stays: written once */ }
364
+ }
365
+ return started;
351
366
  },
352
367
  };
353
368
  }
@@ -11,7 +11,7 @@
11
11
  // One writer of each field: `writeRunValues` writes the version file (this door is its only caller for versions >= 1); the runner reads the
12
12
  // highest version through `pickRunValues` and nothing else. The agent, the chat notes and the drafter have no path here.
13
13
  import { realpathSync } from 'node:fs';
14
- import { join } from 'node:path';
14
+ import { dirname, join } from 'node:path';
15
15
  import { userInfo } from 'node:os';
16
16
 
17
17
  import { scrub } from '../authoring.js';
@@ -27,15 +27,16 @@ import { formFacts } from './authorflows.js';
27
27
  import { checkValues } from './authorvalues.js';
28
28
  import { getRunControls } from './data.js';
29
29
  import { providerKeys } from './spawn.js';
30
+ import { readModelRecord } from '../flowmodel.js';
30
31
 
31
32
  const KEYS = ['flow', 'runId', 'capUsd', 'hash'];
32
33
 
33
34
  /**
34
- * @param {{ root: string, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, monthlyClaim: (usd: number) => any, starter: ReturnType<typeof import('./authorstart.js').createStarter> }} opts
35
+ * @param {{ root: string, home?: string, loadEnv: () => { ok: boolean, env: Record<string, string|undefined>, refusal: string|null }, monthlyClaim: (usd: number) => any, starter: ReturnType<typeof import('./authorstart.js').createStarter> }} opts
35
36
  */
36
37
  export function createResumeDoor(opts) {
37
38
  const {
38
- root, loadEnv, monthlyClaim, starter,
39
+ root, home, loadEnv, monthlyClaim, starter,
39
40
  } = opts;
40
41
 
41
42
  /**
@@ -74,7 +75,7 @@ export function createResumeDoor(opts) {
74
75
  const hasRound = read.declaration.steps.some((st) => !(read.arbiter.asks ?? []).some((a) => a.line === st.fromLine));
75
76
  if (formOnly) return { ok: /** @type {true} */ (true), flow, runId, runDir: rd.runDir, version, base, spentUsd: spent.total, read, hasRound };
76
77
  const checked = checkValues({
77
- allowedKeys: KEYS, body: b, base, realRoot, capOnly: true, floorUsd: capFloorFor(hasRound), spentUsd: spent.total, monthlyClaim, always: true,
78
+ allowedKeys: KEYS, body: b, base, realRoot, capOnly: true, floorUsd: capFloorFor(hasRound, home, readModelRecord(join(realRoot, flow))), spentUsd: spent.total, monthlyClaim, always: true,
78
79
  });
79
80
  if (!checked.ok) {
80
81
  return no(checked.status, checked.refused ? { refused: checked.refused, say: checked.say, refusals: checked.refusals } : { refused: 'resume', refusals: checked.refusals, say: checked.refusals[0]?.say ?? 'Not resumed. Fix the marked box.' });
@@ -100,11 +101,11 @@ export function createResumeDoor(opts) {
100
101
  const inputsRead = readFileInside(s.runDir, 'inputs.json');
101
102
  let inputs = [];
102
103
  try { inputs = inputsRead.ok ? JSON.parse(inputsRead.text).map((m) => ({ role: String(m.id), path: String(m.source) })) : []; } catch { inputs = []; }
103
- const floorUsd = capFloorFor(s.hasRound);
104
+ const floorUsd = capFloorFor(s.hasRound, home, readModelRecord(dirname(dirname(s.runDir))));
104
105
  return {
105
106
  status: 200,
106
107
  body: {
107
- ok: true, flow: s.flow, runId: s.runId, version: s.version, values: s.base, spentUsd: s.spentUsd, inputs, floorUsd, floorText: capFloorText(floorUsd), jobLines: formFacts(s.read).jobLines,
108
+ ok: true, flow: s.flow, runId: s.runId, version: s.version, values: s.base, spentUsd: s.spentUsd, inputs, floorUsd, floorText: capFloorText(floorUsd), jobLines: formFacts(s.read, home, dirname(dirname(s.runDir))).jobLines, model: formFacts(s.read, home, dirname(dirname(s.runDir))).model,
108
109
  },
109
110
  };
110
111
  },
@@ -138,10 +139,10 @@ export function createResumeDoor(opts) {
138
139
  flow: s.flow, flowSignatureHash: s.signatureHash, runId: s.runId, version: s.version, values: s.values, hash: s.hash, signedBy: userInfo().username, at: new Date().toISOString(),
139
140
  });
140
141
  if (!w.ok) {
141
- const keys = providerKeys(loaded.env);
142
+ const keys = providerKeys(loaded);
142
143
  return { status: 409, body: { ok: false, refused: 'sign-refused', say: `${scrub(w.red, keys)}. Nothing was started.` } };
143
144
  }
144
- const started = starter.startContinue({ flow: s.flow, runId: s.runId, version: s.version }, loaded.env);
145
+ const started = starter.startContinue({ flow: s.flow, runId: s.runId, version: s.version }, loaded);
145
146
  if (started.status !== 202) return { status: started.status, body: { ...started.body, signed: true, say: `${started.body.say ?? 'The resume did not start.'} The new cap is signed; try Resume again.` } };
146
147
  return { status: 202, body: { ...started.body, signed: true, version: s.version } };
147
148
  },
@@ -127,13 +127,14 @@ export function createStarter(opts) {
127
127
  * `runId` '' = no typed id: the start CLAIMS the next `run-<n>` itself (claimRunId, folder created exclusively; amendment 3).
128
128
  * `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
129
129
  * folder as `signed-values.json` BEFORE the spawn; the run then uses them (`pickRunValues`). None = the flow's own.
130
- * @param {{ kind: 'run'|'sign', flow: string, runId: string, sources: {role: string, path: string}[], values?: any }} a
131
- * @param {Record<string, string|undefined>} env the merged keys env: the child's env AND the scrub list
130
+ * @param {{ kind: 'run'|'sign', flow: string, runId: string, sources: {role: string, path: string}[], values?: any, pick?: {slot: string, model: string}|null }} a
131
+ * @param {{ env: Record<string, string|undefined>, keyNames?: string[] }} loaded the keys load: its env is the child's env AND (with its key names) the scrub list
132
132
  * @returns {{ status: number, body: any }}
133
133
  */
134
134
  start({
135
- kind, flow, runId, sources, values = null,
136
- }, env) {
135
+ kind, flow, runId, sources, values = null, pick = null,
136
+ }, loaded) {
137
+ const { env } = loaded;
137
138
  const sd = startsDir();
138
139
  if (sd === null) return { status: 400, body: { ok: false, refused: 'root', say: 'The flows folder this panel serves does not exist.' } };
139
140
  /** @type {string|null} */
@@ -160,7 +161,7 @@ export function createStarter(opts) {
160
161
  const w = writeRunValues(runDirOf(), { ...values, runId });
161
162
  if (!w.ok) { unclaim(); return { status: 500, body: { ok: false, refused: 'values', say: `The signed values could not be saved. ${NOTHING_SPENT}` } }; }
162
163
  }
163
- const keys = providerKeys(env);
164
+ const keys = providerKeys(loaded);
164
165
  // one start at a time while one is still spawning for this flow (a double click, two tabs)
165
166
  const startingId = startingFor(flow, keys);
166
167
  if (startingId !== null) {
@@ -174,7 +175,7 @@ export function createStarter(opts) {
174
175
  writeFileSync(join(dir, 'start.json'), `${JSON.stringify({
175
176
  kind, flow, runId, sources, startedAt: new Date().toISOString(),
176
177
  }, null, 2)}\n`, { mode: 0o600 });
177
- const argv = ['run', flow, '--root', realpathSync(root), ...sources.flatMap((s) => ['--source', `${s.role}=${s.path}`]), '--run-id', runId];
178
+ const argv = ['run', flow, '--root', realpathSync(root), ...sources.flatMap((s) => ['--source', `${s.role}=${s.path}`]), '--run-id', runId, ...(pick ? ['--model', pick.model, '--provider', pick.slot] : [])]; // M4d am7b: a flow with no record runs with the model picked in Chat
178
179
  let child;
179
180
  try {
180
181
  child = spawnDetached({
@@ -193,13 +194,14 @@ export function createStarter(opts) {
193
194
  * 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
194
195
  * signed values version. The same detached-child shape as `start`; the start folder reads as `starting` until the child consumes
195
196
  * `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.
196
- * @param {{ flow: string, runId: string, version: number }} a @param {Record<string, string|undefined>} env the merged keys env
197
+ * @param {{ flow: string, runId: string, version: number }} a @param {{ env: Record<string, string|undefined>, keyNames?: string[] }} loaded the keys load
197
198
  * @returns {{ status: number, body: any }}
198
199
  */
199
- startContinue({ flow, runId, version }, env) {
200
+ startContinue({ flow, runId, version }, loaded) {
201
+ const { env } = loaded;
200
202
  const sd = startsDir();
201
203
  if (sd === null) return { status: 400, body: { ok: false, refused: 'root', say: 'The flows folder this panel serves does not exist.' } };
202
- const keys = providerKeys(env);
204
+ const keys = providerKeys(loaded);
203
205
  const startingId = startingFor(flow, keys);
204
206
  if (startingId !== null) return { status: 409, body: { ok: false, refused: 'start-live', startId: startingId, say: 'A run of this flow is already starting. Wait for it.' } };
205
207
  const id = newId();
package/src/panel/data.js CHANGED
@@ -466,8 +466,8 @@ function spendFloorDisplay(spendRows) {
466
466
  * never a stale first-attempt value. `null` (never a guess) when no row in
467
467
  * this run ever named one (e.g. every step is `hitl`, no model step ran).
468
468
  * No provider/API-kind field exists in ANY book (`src/provider.js`'s
469
- * `PROVIDER_SLOTS` maps a slot name to a model, but nothing writes which
470
- * slot served a given run back to `audit.jsonl`/`spend.jsonl`) — provider is
469
+ * a provider row maps to a model, but nothing writes which
470
+ * row served a given run back to `audit.jsonl`/`spend.jsonl`) — provider is
471
471
  * never shown alongside it (hamr's own instruction: "if the provider isn't
472
472
  * in any book, show model only").
473
473
  * @param {any[]} auditRows
@@ -1334,7 +1334,7 @@ export function getRunDetail({
1334
1334
  // a whole finished clean. Checking `historyRow.outcome === 'complete'`
1335
1335
  // FIRST, before ever looking at `auditRows`, is what keeps a passed run
1336
1336
  // from reporting a stale, superseded failure as its own "why" (found live
1337
- // against `flows/`, M4a piece 3 fix #1 — a real run, not a synthetic
1337
+ // against `flows/`, M4a piece 3 fix #1 — a real run, not a staged
1338
1338
  // fixture, is what caught this).
1339
1339
  //
1340
1340
  // hamr's 2026-09-27 browser-walk bug #1: the SAME staleness bug also hit a