fwdloop 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/bin/fwdloop +155 -27
  2. package/package.json +2 -2
  3. package/src/ask.js +3 -0
  4. package/src/authoring.js +135 -16
  5. package/src/books.js +23 -2
  6. package/src/canrun.js +106 -0
  7. package/src/catalogue.json +2 -2
  8. package/src/checked.js +50 -0
  9. package/src/closers.js +112 -91
  10. package/src/config.js +2 -1
  11. package/src/declaration.js +175 -3
  12. package/src/drafter.js +148 -10
  13. package/src/draftspend.js +70 -0
  14. package/src/flow.js +43 -0
  15. package/src/keysfile.js +4 -2
  16. package/src/liveness.js +1 -1
  17. package/src/model-step.js +31 -5
  18. package/src/monthly.js +195 -28
  19. package/src/panel/author.js +638 -0
  20. package/src/panel/authorcard.js +340 -0
  21. package/src/panel/authorflows.js +317 -0
  22. package/src/panel/authorresume.js +149 -0
  23. package/src/panel/authorstart.js +257 -0
  24. package/src/panel/authorvalues.js +110 -0
  25. package/src/panel/data.js +318 -99
  26. package/src/panel/index.html +2000 -330
  27. package/src/panel/resume.js +6 -8
  28. package/src/panel/server.js +122 -119
  29. package/src/panel/settings.js +8 -6
  30. package/src/panel/spawn.js +77 -0
  31. package/src/provider.js +12 -17
  32. package/src/runner.js +707 -104
  33. package/src/runvalues.js +178 -0
  34. package/src/send.js +10 -3
  35. package/src/setup.js +127 -0
  36. package/types/authoring.d.ts +56 -2
  37. package/types/books.d.ts +14 -2
  38. package/types/canrun.d.ts +64 -0
  39. package/types/checked.d.ts +23 -0
  40. package/types/closers.d.ts +47 -28
  41. package/types/config.d.ts +1 -0
  42. package/types/declaration.d.ts +23 -1
  43. package/types/drafter.d.ts +151 -2
  44. package/types/draftspend.d.ts +21 -0
  45. package/types/flow.d.ts +23 -0
  46. package/types/liveness.d.ts +2 -2
  47. package/types/model-step.d.ts +4 -7
  48. package/types/monthly.d.ts +46 -1
  49. package/types/panel/author.d.ts +316 -0
  50. package/types/panel/authorcard.d.ts +142 -0
  51. package/types/panel/authorflows.d.ts +175 -0
  52. package/types/panel/authorresume.d.ts +32 -0
  53. package/types/panel/authorstart.d.ts +115 -0
  54. package/types/panel/authorvalues.d.ts +62 -0
  55. package/types/panel/data.d.ts +105 -63
  56. package/types/panel/server.d.ts +11 -33
  57. package/types/panel/spawn.d.ts +30 -0
  58. package/types/provider.d.ts +6 -9
  59. package/types/runner.d.ts +129 -6
  60. package/types/runvalues.d.ts +97 -0
  61. package/types/send.d.ts +5 -1
  62. package/types/setup.d.ts +77 -0
@@ -11,52 +11,70 @@ export function closeGreen(artifact: any, ctx: {
11
11
  businessDate: string;
12
12
  }): CloseVerdict;
13
13
  /**
14
- * The declared-shape word-cap + ordered-sections check, F38 version (every
15
- * failing check reported, not just the first). Identical rules to
16
- * poc/m0/shape.mjs's own `closeWordsAndSections`.
14
+ * M4e amendment 18: the soft checks run on bareguard 0.21.0. `softgreenSpec(shape)` is the ONE place a declared shape
15
+ * becomes a rubric spec (signing and the run both build through `buildSoftgreenRubric`, so a shape that signs is a shape
16
+ * that builds). The checks are in this fixed order, which is the order their sentences read in:
17
+ * allowedKeys, maxWords, sectionOrder, sectionWords, blockLines.
18
+ * A key that is declared at all gets its check built, so a half-declared shape (wordsPerSection with no sections, one of
19
+ * linesPerInvoice/mustCarry) cannot build and is a crash at run time, never silently skipped.
17
20
  *
18
- * @param {unknown} text
19
- * @param {{ maxWords: number, sections: string[] }} declared
20
- * @returns {CloseVerdict}
21
+ * @param {Record<string, any>} shape
21
22
  */
22
- export function closeWordsAndSections(text: unknown, { maxWords, sections }: {
23
- maxWords: number;
24
- sections: string[];
25
- }): CloseVerdict;
23
+ export function softgreenSpec(shape: Record<string, any>): {
24
+ schema: number;
25
+ goal: string;
26
+ checkpoints: {
27
+ close: {
28
+ gating: boolean;
29
+ checks: Record<string, any>[];
30
+ };
31
+ };
32
+ };
33
+ /** Throws bareguard's `invalid rubric: ...` for a shape it cannot build. @param {Record<string, any>} shape @returns {ReturnType<typeof createRubric>} */
34
+ export function buildSoftgreenRubric(shape: Record<string, any>): ReturnType<typeof createRubric>;
26
35
  /**
27
- * `linesPerInvoice`/`mustCarry`: group `text`'s own non-empty lines into
28
- * blocks of `linesPerInvoice` lines; every `mustCarry` string must appear
29
- * (case-insensitive substring) somewhere in each block. Returns an array of
30
- * red strings (empty when clean) — the caller folds these into its own
31
- * `reds` list alongside `closeWordsAndSections`'s.
36
+ * The ONE render function (amendment 18 item 4A): bareguard's typed gaps in, fwdloop's plain-English sentences out, byte for byte
37
+ * what the hand-written checks said before the switch (test/m4e-am18-parity.test.js proves it on 142 inputs); past bareguard's own
38
+ * offender-list bound the "N more" tail is ours (amendment 19 2), derived from each gap's `itemsTotal` and list length, never a number.
39
+ * What it throws away: bareguard bounds every offender list; past that the sentence says how many more there were.
40
+ * A gap it has no sentence for is still a red, worded generically, never dropped.
41
+ *
42
+ * @param {any[]} gaps
43
+ * @param {{ linesPerInvoice?: number, mustCarry?: string[] }} shape
44
+ * @returns {{ red: string, reds: string[] }}
32
45
  */
33
- export function closeLinesAndCarry(text: any, { linesPerInvoice, mustCarry }: {
34
- linesPerInvoice: any;
35
- mustCarry: any;
36
- }): string[];
46
+ export function renderSoftgreenGaps(gaps: any[], shape: {
47
+ linesPerInvoice?: number;
48
+ mustCarry?: string[];
49
+ }): {
50
+ red: string;
51
+ reds: string[];
52
+ };
37
53
  /**
38
- * `softgreen` close: dispatches to `closeWordsAndSections` (when the shape
39
- * declares `maxWords`/`sections`) and/or `closeLinesAndCarry` (when it
40
- * declares `linesPerInvoice`/`mustCarry`) and reports every failing check
41
- * from both, one sentence each (F38's rule, never widened to first-red-only).
54
+ * `softgreen` close: the declared shape (`maxWords`, `sections`, `wordsPerSection`, `linesPerInvoice` + `mustCarry`, and the
55
+ * one-key rule) is checked by bareguard's rubric (amendment 18 item 1) and every failing check is reported, one sentence each
56
+ * (F38's rule, never widened to first-red-only). Our front door stays: an answer that is not `{text: string}` is `unparseable`
57
+ * before bareguard sees it. A shape that cannot be built, or a check that stopped, is `crash`: never green.
58
+ * Async because bareguard's `checkStep` is.
42
59
  *
43
60
  * @param {any} artifact
44
- * @param {{ maxWords?: number, sections?: string[], linesPerInvoice?: number, mustCarry?: string[] }} shape
45
- * @returns {CloseVerdict}
61
+ * @param {{ maxWords?: number, sections?: string[], wordsPerSection?: number, linesPerInvoice?: number, mustCarry?: string[] }} shape
62
+ * @returns {Promise<CloseVerdict>}
46
63
  */
47
64
  export function closeSoftgreen(artifact: any, shape: {
48
65
  maxWords?: number;
49
66
  sections?: string[];
67
+ wordsPerSection?: number;
50
68
  linesPerInvoice?: number;
51
69
  mustCarry?: string[];
52
- }): CloseVerdict;
70
+ }): Promise<CloseVerdict>;
53
71
  /**
54
72
  * The one dispatcher — `close by declared class` (M2 scope item 4).
55
73
  *
56
74
  * @param {{ close?: { class?: string, shape?: Record<string, any> } }} step
57
75
  * @param {unknown} artifact
58
76
  * @param {{ reads: Record<string, any>, businessDate: string }} ctx
59
- * @returns {CloseVerdict}
77
+ * @returns {Promise<CloseVerdict>}
60
78
  */
61
79
  export function closeByClass(step: {
62
80
  close?: {
@@ -66,5 +84,6 @@ export function closeByClass(step: {
66
84
  }, artifact: unknown, ctx: {
67
85
  reads: Record<string, any>;
68
86
  businessDate: string;
69
- }): CloseVerdict;
87
+ }): Promise<CloseVerdict>;
70
88
  export type CloseVerdict = import("./types.js").CloseVerdict;
89
+ import { createRubric } from 'bareguard';
package/types/config.d.ts CHANGED
@@ -46,6 +46,7 @@ export function updateConfig(patch: Record<string, any>, opts?: {
46
46
  /** A plain-words config failure (bad value, secret-shaped string, unreadable file). */
47
47
  export class ConfigError extends Error {
48
48
  }
49
+ /** Fields a config file may hold; `cachedInPerM` stays so an older file still loads, but nothing prices from it. */
49
50
  export const PRICE_FIELDS: readonly string[];
50
51
  export const PROVIDER_FIELDS: readonly string[];
51
52
  export function cleanBaseUrl(v: any): any;
@@ -19,6 +19,23 @@ export function checkShapes(declaration: any): {
19
19
  reds: any[];
20
20
  shapedSteps: number;
21
21
  };
22
+ /** Every whole-output word number in a guardrail ("3 sections, under 600 words, each heading at most 3 words" -> [600, 3]), in order; [] when
23
+ * there is none. Code does not decide which one is the limit: the AI picks `maxWords` and the validator checks the pick is one of these
24
+ * (M4e amendments 28 + 29). A "<n> words each" / "<n> words per section" is the per-section size (amendment 15), never listed here. */
25
+ export function guardrailWordNumbers(guardrail: any): number[];
26
+ /** M4e amendment 15 item 1: the "<n> words each" / "<n> words per section" size in a guardrail ("about 250 words each", "250ish each" -> 250), or null. */
27
+ export function guardrailWordsPerSection(guardrail: any): number | null;
28
+ /** M4e amendment 7 item 1: the first "<N> sections" in a guardrail (N digits, or the words one..ten), or null. */
29
+ export function guardrailSectionCount(guardrail: any): any;
30
+ /** M4e amendment 15 item 2: for each line whose guardrail gives a size for each section, a section count AND a word number,
31
+ * size x count more than the LARGEST word number (no possible pick fits) is a red naming the line and the numbers. $0; run before any model
32
+ * call, when there is no AI pick yet (amendment 29). After the draft the AI's `maxWords` is checked in checkShapeFitsJobLine. */
33
+ export function checkGuardrailSums(lines: any): string[];
34
+ /** M4e amendment 6 item 1 (+ amendment 7 item 1): a step's check cannot fight its own job line. Sections must be found in the line's words
35
+ * (case-insensitive substring of the goal, first occurrence) and in the line's order; `maxWords` (the AI's pick, amendment 29) must be one
36
+ * of the line's guardrail word numbers when that guardrail has any. A shape key a note may still change (mustCarry, linesPerInvoice)
37
+ * is untouched. Pushes reds naming the step and both orders/values. */
38
+ export function checkShapeFitsJobLine(step: any, i: any, lines: any, reds: any): void;
22
39
  /**
23
40
  * Validate a drafter declaration against the M1 closed schema. `arbiter`
24
41
  * and `lines` are `parseSignedText`'s output; `catalogue` is a plain array
@@ -31,7 +48,9 @@ export function checkShapes(declaration: any): {
31
48
  * by name, even if the catalogue lists it. Omitted = no wired check (existing callers).
32
49
  * `verbatimGoals` (optional boolean; M6a amendment 1): when true, a step naming a signed line must carry that line's
33
50
  * text as its goal, exactly. Off by default so already-signed flows keep running; draft and sign turn it on.
34
- * @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown, wired?: Set<string>, verbatimGoals?: boolean }} [context]
51
+ * `fitJobLine` (optional boolean; M4e amendment 6): when true, a `close.shape` whose sections/maxWords fight the step's job
52
+ * line or its guardrail is a red. Draft, change and sign turn it on; readFlow does not (signed flows keep running).
53
+ * @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown, wired?: Set<string>, verbatimGoals?: boolean, fitJobLine?: boolean }} [context]
35
54
  * @returns {ValidateDeclarationResult}
36
55
  */
37
56
  export function validateDeclaration(declaration: unknown, context?: {
@@ -40,6 +59,7 @@ export function validateDeclaration(declaration: unknown, context?: {
40
59
  catalogue?: unknown;
41
60
  wired?: Set<string>;
42
61
  verbatimGoals?: boolean;
62
+ fitJobLine?: boolean;
43
63
  }): ValidateDeclarationResult;
44
64
  /** @typedef {import('./types.js').Arbiter} Arbiter */
45
65
  /** @typedef {import('./types.js').SignedLine} SignedLine */
@@ -53,6 +73,8 @@ export const DECLARATION_FIELDS: readonly string[];
53
73
  * exactly these four top-level keys. Anything else inside `shape` reds by
54
74
  * name. */
55
75
  export const SHAPE_KEYS: readonly string[];
76
+ /** Shape keys only the MACHINE sets (M4e amendment 15): read from the line's guardrail, never offered to the drafter's model. */
77
+ export const MACHINE_SHAPE_KEYS: readonly string[];
56
78
  export type Arbiter = import("./types.js").Arbiter;
57
79
  export type SignedLine = import("./types.js").SignedLine;
58
80
  export type CatalogueEntry = import("./types.js").CatalogueEntry;
@@ -102,6 +102,133 @@ export function buildDeclarationSchema(menu: any): {
102
102
  required: string[];
103
103
  additionalProperties: boolean;
104
104
  };
105
+ /** The declaration schema plus the optional `notChecked` (every try) and, on try 3 only, `questions`. Neither is in `required`. */
106
+ export function buildRoundSchema(menu: any, { questions }?: {
107
+ questions?: boolean | undefined;
108
+ }): {
109
+ properties: {
110
+ notChecked: {
111
+ type: string;
112
+ items: {
113
+ type: string;
114
+ };
115
+ description: string;
116
+ };
117
+ steps: {
118
+ type: string;
119
+ minItems: number;
120
+ items: {
121
+ type: string;
122
+ properties: {
123
+ primitives: {
124
+ type: string;
125
+ items: {
126
+ type: string;
127
+ enum: any;
128
+ };
129
+ description: string;
130
+ };
131
+ reads: {
132
+ type: string;
133
+ items: {
134
+ type: string;
135
+ };
136
+ description: string;
137
+ };
138
+ emits: {
139
+ type: string;
140
+ minLength: number;
141
+ description: string;
142
+ };
143
+ fromLine: {
144
+ type: string[];
145
+ description: string;
146
+ };
147
+ picks: {
148
+ type: string;
149
+ additionalProperties: {
150
+ type: string;
151
+ items: {
152
+ type: string;
153
+ };
154
+ };
155
+ description: string;
156
+ };
157
+ close: {
158
+ type: string;
159
+ properties: {
160
+ class: {
161
+ type: string;
162
+ enum: string[];
163
+ description: string;
164
+ };
165
+ shape: {
166
+ type: string;
167
+ properties: {};
168
+ additionalProperties: boolean;
169
+ description: string;
170
+ };
171
+ };
172
+ required: string[];
173
+ additionalProperties: boolean;
174
+ };
175
+ };
176
+ required: string[];
177
+ additionalProperties: boolean;
178
+ };
179
+ };
180
+ guardrailClasses: {
181
+ type: string;
182
+ additionalProperties: {
183
+ type: string;
184
+ enum: string[];
185
+ };
186
+ description: string;
187
+ };
188
+ unjudgeable: {
189
+ type: string;
190
+ additionalProperties: {
191
+ type: string;
192
+ };
193
+ description: string;
194
+ };
195
+ refused: {
196
+ type: string;
197
+ items: {
198
+ type: string;
199
+ properties: {
200
+ line: {
201
+ type: string;
202
+ };
203
+ reason: {
204
+ type: string;
205
+ minLength: number;
206
+ };
207
+ };
208
+ required: string[];
209
+ additionalProperties: boolean;
210
+ };
211
+ description: string;
212
+ };
213
+ };
214
+ type: string;
215
+ required: string[];
216
+ additionalProperties: boolean;
217
+ };
218
+ /**
219
+ * Which job lines did these reds name? Reds name a line three ways: "line N" (also "ask at line N", "(line N)",
220
+ * "guardrailClasses key \"N\""), "steps[i]" (mapped through that declaration's steps[i].fromLine), and "step N's check"
221
+ * (1-based). A red naming none (a missing top-level key, an unknown key) names no line. Returns sorted real line numbers.
222
+ */
223
+ export function linesNamedByReds(reds: any, declaration: any, lineNums: any): any[];
224
+ /**
225
+ * Amendment 25: a question is kept only if its line is one try 2's reds named; no line, a blank question or a third question is
226
+ * dropped. Every drop comes back with its reason, for the draft's log. Returns {kept, dropped}.
227
+ */
228
+ export function normalizeQuestions(raw: any, failedLines: any): {
229
+ kept: any[];
230
+ dropped: any[];
231
+ };
105
232
  export function buildSystemPrompt({ menu, lines, arbiter, factsInfo }: {
106
233
  menu: any;
107
234
  lines: any;
@@ -119,11 +246,16 @@ export function goalForLine(fromLine: any, lines: any): any;
119
246
  * the batch); otherwise a live provider is built from `slot` (throws on a bad
120
247
  * key — the batch preflights first). `budgetUsd` is this draft's hard cap.
121
248
  * `makeProviderFn` is a test seam: the live-provider factory (default `makeProvider`).
249
+ * `onBook` (M4e piece 2a, scope 13): called right BEFORE each provider call (`inFlight: true`, the call counted in
250
+ * `calls`) and right AFTER it (`inFlight: false`), with what is known so far, so the caller can book spend per call
251
+ * and a draft killed between rounds still has its paid rounds on disk. It may throw before a call (nothing is
252
+ * spent then and the draft stops); after a call it is the caller's to keep from throwing.
122
253
  *
123
254
  * @returns {Promise<{ok:boolean, declaration:object|null, reds:string[], rounds:number, calls:number, spendComplete:boolean,
124
- * costUsd:number|null, modelReturned:string|null, modelId?:string, price?:object|null, tokens?:object|null, structureRetries:number, revisions:number, stop:string|null, log:object[]}>}
255
+ * costUsd:number|null, modelReturned:string|null, modelId?:string, price?:object|null, tokens?:object|null, structureRetries:number, revisions:number, stop:string|null, log:object[],
256
+ * questions?:{line:number, question:string}[], droppedQuestions?:object[], notChecked?:string[]}>}
125
257
  */
126
- export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, budgetUsd, skills, makeProviderFn, }: {
258
+ export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, budgetUsd, skills, makeProviderFn, onBook, offerQuestions, }: {
127
259
  proseText: any;
128
260
  slot?: string | undefined;
129
261
  model: any;
@@ -134,6 +266,8 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
134
266
  budgetUsd?: number | undefined;
135
267
  skills?: readonly string[] | undefined;
136
268
  makeProviderFn?: typeof makeProvider | undefined;
269
+ onBook: any;
270
+ offerQuestions?: boolean | undefined;
137
271
  }): Promise<{
138
272
  ok: boolean;
139
273
  declaration: object | null;
@@ -150,12 +284,27 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
150
284
  revisions: number;
151
285
  stop: string | null;
152
286
  log: object[];
287
+ questions?: {
288
+ line: number;
289
+ question: string;
290
+ }[];
291
+ droppedQuestions?: object[];
292
+ notChecked?: string[];
153
293
  }>;
154
294
  export const MAX_STRUCTURE_RETRIES: 2;
155
295
  export const MAX_REVISIONS: 2;
156
296
  export const DRAFT_MAX_TOKENS: 16000;
157
297
  export const DRAFT_SKILLS: readonly string[];
158
298
  export const CLASSES: readonly string[];
299
+ /** The whole-output-ceiling rule, told once to the drafter (schema and prompt use this string). Amendment 29; no number words (am25). */
300
+ export const WHOLE_OUTPUT_CEILING_RULE: "use the guardrail's ceiling for the whole output";
301
+ export const MAX_QUESTIONS: 2;
302
+ /** What fwdloop's typed checks can really check (bareloop F174: give the model the real list, or "Not checked" is invented). */
303
+ export const CHECKABLE: readonly string[];
304
+ /** Offered on EVERY try (it is information, not asking). */
305
+ export const NOTCHECKED_PROMPT: string;
306
+ /** Try 3 only, and only after tries 1 and 2 both failed validation. No digit and no number word anywhere (a test greps this): the machine, not the prompt, bounds the count. */
307
+ export const QUESTIONS_PROMPT: string;
159
308
  export const DRAFT_PROVIDER_OPTIONS: Readonly<{
160
309
  thinking: Readonly<{
161
310
  type: "disabled";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * (Re)write `<dir>/draft-spend.json` atomically (tmp + rename), so a reader never sees a torn file.
3
+ * @param {string} dir the draft dir
4
+ * @param {Record<string, any>} rec
5
+ */
6
+ export function writeDraftSpend(dir: string, rec: Record<string, any>): void;
7
+ /**
8
+ * The draft dir's live spend record as a spend row, or null when the file is not there. A file that is there but
9
+ * cannot be read is unknown spend: one unmetered call (priced at the ceiling), never $0 and never skipped.
10
+ * @param {string} dir
11
+ * @returns {Record<string, any>|null}
12
+ */
13
+ export function readDraftSpend(dir: string): Record<string, any> | null;
14
+ /**
15
+ * Every spend row of one run/draft dir: its `spend.jsonl` rows; and, only when there are none, the draft dir's
16
+ * `draft-spend.json` record (see the file header: a finished draft's spend.jsonl supersedes it).
17
+ * @param {string} dir
18
+ * @returns {Record<string, any>[]}
19
+ */
20
+ export function readDirSpendRows(dir: string): Record<string, any>[];
21
+ export const DRAFT_SPEND_FILE: "draft-spend.json";
package/types/flow.d.ts CHANGED
@@ -87,6 +87,27 @@ export function listFlowNames(root: string): string[];
87
87
  * @returns {string[]}
88
88
  */
89
89
  export function listRunIds(flowDir: string): string[];
90
+ /**
91
+ * M4e amendment 3 item 2: the ONE place a run gets its default name. `run-<n>`, counting up per flow (the run lives in its flow's
92
+ * folder, so the name only has to be unique there). `nextRunId` only LOOKS (max existing `run-<n>` + 1; the page's prefill);
93
+ * `claimRunId` CLAIMS: it creates the run folder exclusively (mkdir with no `recursive` on the final component, so a second
94
+ * starter gets EEXIST, never the same folder) and bumps n on EEXIST, a bounded number of times. Runs already made keep their ids.
95
+ * @param {string} flowDir
96
+ * @returns {string}
97
+ */
98
+ export function nextRunId(flowDir: string): string;
99
+ /**
100
+ * @param {string} flowDir
101
+ * @returns {{ok:true, runId:string, runDir:string}|{ok:false, red:string}}
102
+ */
103
+ export function claimRunId(flowDir: string): {
104
+ ok: true;
105
+ runId: string;
106
+ runDir: string;
107
+ } | {
108
+ ok: false;
109
+ red: string;
110
+ };
90
111
  /**
91
112
  * F48 round 3 (docs/logs/FINDINGS.md): the ONE mechanism every book reader
92
113
  * in src/ and bin/ routes through to read a file that lives inside a run
@@ -185,6 +206,8 @@ export function readFlow({ root, name, catalogue }: {
185
206
  /** The three files a signed flow directory carries. Every place in this
186
207
  * module that names a flow file uses this — never a literal string. */
187
208
  export const FLOW_FILES: readonly string[];
209
+ /** The one folder under the flows root where the panel keeps each run start's own files (M4e piece 2b). A dot-name, so never a flow. */
210
+ export const PANEL_STARTS_DIR: ".starts";
188
211
  export type WriteFlowResult = import("./types.js").WriteFlowResult;
189
212
  export type ReadFlowResult = import("./types.js").ReadFlowResult;
190
213
  export type CheckFlowNameResult = import("./types.js").CheckFlowNameResult;
@@ -21,10 +21,10 @@ export function isFwdloopAlive(pid: number, procStart?: string | null): boolean
21
21
  * The one writer call: this process records itself in the run dir's
22
22
  * `pids.jsonl`, before its first step.
23
23
  * @param {string} runDir
24
- * @param {'run'|'resume'} leg
24
+ * @param {'run'|'resume'|'continue'} leg
25
25
  * @param {string} at ISO timestamp from the run's own clock
26
26
  */
27
- export function recordPid(runDir: string, leg: "run" | "resume", at: string): void;
27
+ export function recordPid(runDir: string, leg: "run" | "resume" | "continue", at: string): void;
28
28
  /**
29
29
  * Is the process that last worked on this run still alive? Reads the newest
30
30
  * `pids.jsonl` row (the one reader, `readPidRows`).
@@ -54,14 +54,9 @@ export function buildEmitArtifactSchema(stepClass: any): Readonly<{
54
54
  text: {
55
55
  type: string;
56
56
  };
57
- lines: {
58
- type: string;
59
- items: {
60
- type: string;
61
- };
62
- };
63
57
  };
64
58
  required: string[];
59
+ additionalProperties: false;
65
60
  }> | Readonly<{
66
61
  type: "object";
67
62
  properties: {
@@ -92,7 +87,7 @@ export function buildEmitArtifactSchema(stepClass: any): Readonly<{
92
87
  * @param {{in:number,out:number}} [opts.rates]
93
88
  * @param {string} [opts.modelId]
94
89
  * @param {Record<string,string|undefined>} [opts.env] - the merged shell+keys-file env the key is read from (default process.env).
95
- * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string}) => Promise<any>}
90
+ * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
96
91
  */
97
92
  export function makeLiveModelStep({ slot, model, spendPath, provider: injectedProvider, rates: injectedRates, modelId: injectedModelId, env, }: {
98
93
  slot?: string | undefined;
@@ -107,6 +102,8 @@ export function makeLiveModelStep({ slot, model, spendPath, provider: injectedPr
107
102
  env?: Record<string, string | undefined> | undefined;
108
103
  }): (executorContext: object, grantedTools: Record<string, any>, stepMeta?: {
109
104
  class?: string;
105
+ }, seam?: {
106
+ stopRequested?: () => boolean;
110
107
  }) => Promise<any>;
111
108
  export const LIVE_PROVIDER_OPTIONS: Readonly<{
112
109
  timeoutMs: 300000;
@@ -4,11 +4,13 @@ export function realpathLoose(p: string): string;
4
4
  export function readRuns(home?: string): any[];
5
5
  /**
6
6
  * The Money tab's figures (piece 4 reads this) and the check's month total.
7
- * @param {{ home?: string, now?: () => number }} [opts]
7
+ * `rows` (a caller that has just read the record, like the claim) saves a second parse of the same file.
8
+ * @param {{ home?: string, now?: () => number, rows?: any[] }} [opts]
8
9
  */
9
10
  export function spendSummary(opts?: {
10
11
  home?: string;
11
12
  now?: () => number;
13
+ rows?: any[];
12
14
  }): {
13
15
  month: {
14
16
  modelMinutes: number | null;
@@ -46,6 +48,27 @@ export function spendSummary(opts?: {
46
48
  undatedRows: number;
47
49
  preM4dRunsNotCounted: boolean;
48
50
  };
51
+ /**
52
+ * Read-only: would a run holding `capUsd` fit this month? The same numbers `claimHold` decides on, but no hold row and no settle is
53
+ * written — it is what the panel's note under Cap shows. Throws ConfigError when config.json is broken.
54
+ * @param {{ capUsd: number, home?: string, now?: () => number }} a
55
+ * @returns {Claim}
56
+ */
57
+ export function checkMonthlyRoom({ capUsd, home, now }: {
58
+ capUsd: number;
59
+ home?: string;
60
+ now?: () => number;
61
+ }): Claim;
62
+ /**
63
+ * The short line under the Cap box (M4e amendment 4 item 1), from the same room: `needs $0.50 ($0.10 left monthly)` (red) when the
64
+ * cap does not fit, `$4.90 left monthly` when it does; '' when no limit is set. Money is never rounded down to look like it fits.
65
+ * @param {Claim} claim
66
+ * @returns {{ text: string, red: boolean }}
67
+ */
68
+ export function monthlyNote(claim: Claim): {
69
+ text: string;
70
+ red: boolean;
71
+ };
49
72
  /**
50
73
  * @typedef {object} Claim
51
74
  * @property {boolean} ok the hold fits (or no limit is set)
@@ -68,6 +91,28 @@ export function claimHold({ what, flow, runId, runDir, holdUsd, spentAtHold, hom
68
91
  home?: string;
69
92
  now?: () => number;
70
93
  }): Claim;
94
+ /**
95
+ * Amendment 16 C2: a hold's process starts spending into one more run dir (a rerun's new run): name it NOW, so a process killed hard
96
+ * still has that dir's spend counted. Append-only; `namedDirs` dedupes, so the settle note naming it again never counts it twice.
97
+ * Never throws (a failed note is closed by the settle note's `alsoRunDirs` on a normal exit).
98
+ * @param {{ holdId: string|null, runDir: string, home?: string, now?: () => number }} a
99
+ */
100
+ export function nameRunDir({ holdId, runDir, home, now, }: {
101
+ holdId: string | null;
102
+ runDir: string;
103
+ home?: string;
104
+ now?: () => number;
105
+ }): void;
106
+ /**
107
+ * I1 (amendment 16): fold the spend of every run/draft dir whose holds have ALL ended (settled, released or refused) into `rolled`
108
+ * rows, so the next month figure or Money load reads one record instead of one file per run. Append-only; a dir already rolled and not
109
+ * named since is left alone. Reads the dirs it folds exactly as `spendSummary` would, so no total changes. Never throws.
110
+ * @param {{ home?: string, now?: () => number }} [a]
111
+ */
112
+ export function rollSettled({ home, now }?: {
113
+ home?: string;
114
+ now?: () => number;
115
+ }): void;
71
116
  /**
72
117
  * The run's own process ends or parks: give the hold back. Never throws (a failed settle is closed by the
73
118
  * next check as "process gone"). `alsoRunDirs` names dirs this process also spent into (a rerun's new run).