fwdloop 0.15.0 → 0.17.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 (72) hide show
  1. package/README.md +2 -0
  2. package/bin/fwdloop +113 -36
  3. package/package.json +2 -2
  4. package/src/authoring.js +27 -15
  5. package/src/catalogue.json +9 -3
  6. package/src/closers.js +5 -0
  7. package/src/config.js +66 -4
  8. package/src/ctx-tools.js +245 -0
  9. package/src/declaration.js +25 -1
  10. package/src/draft-steps.js +138 -0
  11. package/src/drafter.js +81 -18
  12. package/src/draftspend.js +109 -3
  13. package/src/flowmodel.js +30 -0
  14. package/src/input-facts.js +12 -3
  15. package/src/keysfile.js +51 -16
  16. package/src/liveness.js +34 -10
  17. package/src/model-step.js +13 -11
  18. package/src/monthly.js +9 -1
  19. package/src/panel/author.js +170 -43
  20. package/src/panel/authorcard.js +32 -20
  21. package/src/panel/authorflows.js +34 -19
  22. package/src/panel/authorresume.js +11 -9
  23. package/src/panel/authorstart.js +11 -9
  24. package/src/panel/authorvalues.js +5 -3
  25. package/src/panel/data.js +20 -8
  26. package/src/panel/index.html +584 -182
  27. package/src/panel/resume.js +3 -3
  28. package/src/panel/server.js +12 -6
  29. package/src/panel/settings.js +138 -80
  30. package/src/panel/spawn.js +15 -9
  31. package/src/plain-checks.js +51 -0
  32. package/src/primitives.js +34 -3
  33. package/src/provider.js +148 -181
  34. package/src/providershapes.js +7 -7
  35. package/src/run-store.js +47 -0
  36. package/src/runner.js +40 -22
  37. package/src/setup.js +3 -0
  38. package/src/thinking.js +55 -0
  39. package/src/version.js +13 -0
  40. package/types/authoring.d.ts +11 -6
  41. package/types/closers.d.ts +2 -0
  42. package/types/config.d.ts +9 -1
  43. package/types/ctx-tools.d.ts +18 -0
  44. package/types/draft-steps.d.ts +47 -0
  45. package/types/drafter.d.ts +15 -12
  46. package/types/draftspend.d.ts +56 -0
  47. package/types/flowmodel.d.ts +16 -0
  48. package/types/input-facts.d.ts +6 -1
  49. package/types/keysfile.d.ts +23 -6
  50. package/types/liveness.d.ts +7 -1
  51. package/types/model-step.d.ts +1 -1
  52. package/types/monthly.d.ts +1 -0
  53. package/types/panel/author.d.ts +47 -9
  54. package/types/panel/authorcard.d.ts +33 -10
  55. package/types/panel/authorflows.d.ts +32 -9
  56. package/types/panel/authorresume.d.ts +2 -1
  57. package/types/panel/authorstart.d.ts +16 -6
  58. package/types/panel/authorvalues.d.ts +3 -1
  59. package/types/panel/data.d.ts +2 -2
  60. package/types/panel/resume.d.ts +2 -1
  61. package/types/panel/server.d.ts +6 -2
  62. package/types/panel/settings.d.ts +3 -1
  63. package/types/panel/spawn.d.ts +13 -4
  64. package/types/plain-checks.d.ts +22 -0
  65. package/types/primitives.d.ts +0 -6
  66. package/types/provider.d.ts +100 -284
  67. package/types/providershapes.d.ts +3 -4
  68. package/types/run-store.d.ts +11 -0
  69. package/types/runner.d.ts +2 -4
  70. package/types/setup.d.ts +8 -0
  71. package/types/thinking.d.ts +25 -0
  72. package/types/version.d.ts +2 -0
@@ -27,11 +27,12 @@ import {
27
27
  applyRunValues, flowValues, pickRunValues, valuesHash,
28
28
  } from '../runvalues.js';
29
29
  import {
30
- capFloorFor, capFloorText, cardFromSigned, checkInputRows, runInputRows,
30
+ capFloorOf, cardFromSigned, checkInputRows, runInputRows,
31
31
  } from './authorcard.js';
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: capFloorOf(hasRound, home, pick).usd, floorModel: capFloorOf(hasRound, home, pick).model,
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, floorModel: formFacts(read, home, join(realRoot, flow), newPick).floorModel, 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';
@@ -22,20 +22,21 @@ import { auditSpend } from '../runner.js';
22
22
  import {
23
23
  flowValues, pickRunValues, valuesHash, writeRunValues,
24
24
  } from '../runvalues.js';
25
- import { capFloorFor, capFloorText } from './authorcard.js';
25
+ import { capFloorFor, capFloorOf } from './authorcard.js';
26
26
  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))), floorModel: capFloorOf(hasRound, home, readModelRecord(join(realRoot, flow))).model, 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,12 @@ 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 floor = capFloorOf(s.hasRound, home, readModelRecord(dirname(dirname(s.runDir))));
105
+ const floorUsd = floor.usd;
104
106
  return {
105
107
  status: 200,
106
108
  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,
109
+ ok: true, flow: s.flow, runId: s.runId, version: s.version, values: s.base, spentUsd: s.spentUsd, inputs, floorUsd, floorModel: floor.model, jobLines: formFacts(s.read, home, dirname(dirname(s.runDir))).jobLines, model: formFacts(s.read, home, dirname(dirname(s.runDir))).model,
108
110
  },
109
111
  };
110
112
  },
@@ -138,10 +140,10 @@ export function createResumeDoor(opts) {
138
140
  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
141
  });
140
142
  if (!w.ok) {
141
- const keys = providerKeys(loaded.env);
143
+ const keys = providerKeys(loaded);
142
144
  return { status: 409, body: { ok: false, refused: 'sign-refused', say: `${scrub(w.red, keys)}. Nothing was started.` } };
143
145
  }
144
- const started = starter.startContinue({ flow: s.flow, runId: s.runId, version: s.version }, loaded.env);
146
+ const started = starter.startContinue({ flow: s.flow, runId: s.runId, version: s.version }, loaded);
145
147
  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
148
  return { status: 202, body: { ...started.body, signed: true, version: s.version } };
147
149
  },
@@ -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();
@@ -5,7 +5,8 @@
5
5
  //
6
6
  // What a run can change without a new flow is exactly these values; a job line, an ask's words or position, or the steps are not a run
7
7
  // (the body may not even carry them: an unknown key is refused by name with the new-flow sentence).
8
- import { capFloorText, destinationRefusal } from './authorcard.js';
8
+ import { destinationRefusal } from './authorcard.js';
9
+ import { capTooSmallText } from '../draftspend.js';
9
10
  import { monthlyRefusalText } from '../monthly.js';
10
11
  import { parseWaitMs, valuesHash, sameValues } from '../runvalues.js';
11
12
 
@@ -33,6 +34,7 @@ const typed = (v) => (typeof v === 'string' ? v.trim() : v);
33
34
  * @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)
34
35
  * @param {string} a.realRoot the flows root (real path)
35
36
  * @param {boolean} a.capOnly Resume: destination and waits are never read from the body
37
+ * @param {string|null} [a.floorModel] the model id the floor was computed for (named in the refusal, M4d am20)
36
38
  * @param {number} a.floorUsd the smallest cap that funds one round of a step (amendment 4 item 2); 0 = none
37
39
  * @param {number} [a.spentUsd] what the run has already spent (Resume): the cap must be above it
38
40
  * @param {boolean} [a.always] Resume: the floor and the monthly check always apply. A Run applies them only when its cap differs from the
@@ -41,7 +43,7 @@ const typed = (v) => (typeof v === 'string' ? v.trim() : v);
41
43
  * @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 }}
42
44
  */
43
45
  export function checkValues({
44
- allowedKeys, body, base, realRoot, capOnly, floorUsd, spentUsd = 0, monthlyClaim, always = false,
46
+ allowedKeys, body, base, realRoot, capOnly, floorUsd, floorModel = null, spentUsd = 0, monthlyClaim, always = false,
45
47
  }) {
46
48
  /** @type {{field: string, say: string}[]} */
47
49
  const refusals = [];
@@ -64,7 +66,7 @@ export function checkValues({
64
66
  if (refusals.length === 0) {
65
67
  if (spentUsd > 0 && capUsd <= spentUsd + 1e-9) {
66
68
  no('capUsd', `The cap must be above what is already spent (at least $${leastResumeCapUsd(spentUsd, floorUsd).toFixed(2)}).`);
67
- } else if (capUsd < floorUsd && (always || capUsd !== base.capUsd)) no('capUsd', capFloorText(floorUsd));
69
+ } else if (capUsd < floorUsd && (always || capUsd !== base.capUsd)) no('capUsd', capTooSmallText('run', capUsd, floorUsd, String(floorModel)));
68
70
  }
69
71
 
70
72
  let destination = base.destination;
package/src/panel/data.js CHANGED
@@ -22,6 +22,7 @@
22
22
  import {
23
23
  existsSync, realpathSync,
24
24
  } from 'node:fs';
25
+ import { plainPlanCheck } from '../plain-checks.js';
25
26
  import { join, basename, sep } from 'node:path';
26
27
 
27
28
  import {
@@ -466,8 +467,8 @@ function spendFloorDisplay(spendRows) {
466
467
  * never a stale first-attempt value. `null` (never a guess) when no row in
467
468
  * this run ever named one (e.g. every step is `hitl`, no model step ran).
468
469
  * 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
470
+ * a provider row maps to a model, but nothing writes which
471
+ * row served a given run back to `audit.jsonl`/`spend.jsonl`) — provider is
471
472
  * never shown alongside it (hamr's own instruction: "if the provider isn't
472
473
  * in any book, show model only").
473
474
  * @param {any[]} auditRows
@@ -1334,7 +1335,7 @@ export function getRunDetail({
1334
1335
  // a whole finished clean. Checking `historyRow.outcome === 'complete'`
1335
1336
  // FIRST, before ever looking at `auditRows`, is what keeps a passed run
1336
1337
  // 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
1338
+ // against `flows/`, M4a piece 3 fix #1 — a real run, not a staged
1338
1339
  // fixture, is what caught this).
1339
1340
  //
1340
1341
  // hamr's 2026-09-27 browser-walk bug #1: the SAME staleness bug also hit a
@@ -1521,6 +1522,17 @@ export function getDraftBlock(flowDir, runDir) {
1521
1522
  usd: typeof r.costUsd === 'number' ? r.costUsd : undefined, spendComplete: r.spendComplete === true, tokensDisplay: { kind: 'no-model' },
1522
1523
  ...(typeof r.wallMs === 'number' ? { wallMs: r.wallMs } : {}),
1523
1524
  });
1525
+ // M4d am15 item 4: one row per try under the draft's plan row: `try N ✗|✓`, its plain reason (the first refusal, "and k more"), the raw checker text under it.
1526
+ // The free retry after a broken reply reads `try N again`. A flow signed before am15 recorded no tries: nothing is added.
1527
+ const tryRows = (r, n) => (Array.isArray(r.tries) ? r.tries : []).map((t, k) => {
1528
+ const reds = Array.isArray(t.reds) ? t.reds.map(String) : [];
1529
+ const gap = t.passed ? '' : (reds.length > 0 ? `${plainPlanCheck(reds[0]).reason}${reds.length > 1 ? ` (and ${reds.length - 1} more)` : ''}` : String(t.outcome ?? ''));
1530
+ return {
1531
+ attempt: `${n}.${k + 1}`, step: 'drafting', class: null, verdict: t.passed ? 'green' : 'red', gap, at: r.at ?? null, setup: true, blocked: false,
1532
+ action: `${t.label} ${t.passed ? '✓' : '✗'}`, tryRow: true, tokensDisplay: { kind: 'no-model' },
1533
+ ...(t.passed ? {} : { raw: reds.length > 0 ? reds : [String(t.rawOutcome ?? t.outcome ?? '')] }),
1534
+ };
1535
+ });
1524
1536
  // M4e amendment 8 item 1, line 4: one short phrase per Draft row, in order (the drafting card joins them with ` · `)
1525
1537
  const happened = [];
1526
1538
  const retry = (r) => (Number.isInteger(r.structureRetries) && r.structureRetries >= 1 ? ` (retry ${r.structureRetries} of ${MAX_STRUCTURE_RETRIES})` : '');
@@ -1541,11 +1553,11 @@ export function getDraftBlock(flowDir, runDir) {
1541
1553
  typeof c.inputs === 'string' && c.inputs.trim() ? `inputs: ${c.inputs.trim().replace(/\n+/g, ' / ')}` : null, `job: ${String(c.job ?? '').trim().replace(/\n+/g, ' / ')}`].filter(Boolean).join(' · ');
1542
1554
  rows.push(human(r, n, { action: 'card (you)', gap }));
1543
1555
  } else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
1544
- else if (r.kind === 'draft') rows.push(model(r, n, 'draft'));
1545
- else if (r.kind === 'change') rows.push(model(r, n, `change ${r.n}`));
1546
- else if (r.kind === 'startover') rows.push(model(r, n, 'start over'));
1547
- else if (r.kind === 'revise') rows.push(model(r, n, `revise ${r.n}`));
1548
- else if (r.kind === 'redraft') rows.push(model(r, n, `answers redraft ${r.n}`));
1556
+ else if (r.kind === 'draft') { rows.push(model(r, n, 'draft')); rows.push(...tryRows(r, n)); }
1557
+ else if (r.kind === 'change') { rows.push(model(r, n, `change ${r.n}`)); rows.push(...tryRows(r, n)); }
1558
+ else if (r.kind === 'startover') { rows.push(model(r, n, 'start over')); rows.push(...tryRows(r, n)); }
1559
+ else if (r.kind === 'revise') { rows.push(model(r, n, `revise ${r.n}`)); rows.push(...tryRows(r, n)); }
1560
+ else if (r.kind === 'redraft') { rows.push(model(r, n, `answers redraft ${r.n}`)); rows.push(...tryRows(r, n)); }
1549
1561
  else if (r.kind === 'sign') rows.push(human(r, n, { action: `sign (${r.signedBy ?? 'you'})`, gap: `plan ${String(r.hash ?? '').slice(0, 12)}` }));
1550
1562
  });
1551
1563
  }