fwdloop 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/send.js CHANGED
@@ -32,8 +32,27 @@ export async function sendViaPrimitive(target, filename, content) {
32
32
  const destination = checkSendDestination(target);
33
33
  if (!destination.ok) return { ok: false, red: destination.red };
34
34
 
35
+ // F48 round 4 (redesign) defense in depth: `src/runner.js`'s send slot
36
+ // now halts BEFORE calling this function on a missing/refused read, so
37
+ // `content` should never arrive `undefined` here — but this function must
38
+ // never again paper over that with `?? null` the way it used to (that is
39
+ // exactly what turned a swapped/deleted accepted artifact into a
40
+ // recorded-green 4-byte `null` shipped to the signed destination). A
41
+ // legitimate on-disk artifact is always a non-null object: every step's
42
+ // model output is validated to carry a boolean `done` before it is ever
43
+ // written (src/runner.js's checkDoneBlocker), and `done`/`blocker` are
44
+ // stripped afterward (stripDoneBlocker) — the stripped artifact that
45
+ // actually reaches disk (and this function) is always the remaining
46
+ // object, never `null` and never a bare non-object value.
47
+ if (content === undefined) {
48
+ return { ok: false, red: 'send: no content to send (artifact missing or its read was refused) — refused' };
49
+ }
50
+ if (content === null || typeof content !== 'object' || Array.isArray(content)) {
51
+ return { ok: false, red: `send: content is not an artifact object (got ${JSON.stringify(content)}) — refused` };
52
+ }
53
+
35
54
  const path = join(destination.dir, filename);
36
- const serialised = JSON.stringify(content ?? null, null, 2);
55
+ const serialised = JSON.stringify(content, null, 2);
37
56
  await WRITE_TOOL.execute({ path, content: serialised });
38
57
 
39
58
  const bytes = readFileSync(path);
@@ -0,0 +1,27 @@
1
+ // M6a amendment 2 — only a person at a keyboard can sign. The CLI's `sign` verb calls this
2
+ // BEFORE signDraft; signDraft itself stays a library (tests) and the CLI has no path around this.
3
+ // Raises the bar, is not proof of a person: a determined script can fake a TTY.
4
+ import { createInterface } from 'node:readline';
5
+
6
+ export const NEEDS_TTY = 'sign needs an interactive terminal — run it yourself';
7
+ export const NAME_MISMATCH = 'typed name does not match';
8
+
9
+ /** stdin AND stdout must both be TTYs. */
10
+ export function isInteractive(stdin = process.stdin, stdout = process.stdout) {
11
+ return Boolean(stdin && stdin.isTTY && stdout && stdout.isTTY);
12
+ }
13
+
14
+ /** Show the flow name, read one line, compare exactly (trimmed). Empty answer / EOF / mismatch refuse by name. */
15
+ export function confirmTypedName({ name, input = process.stdin, output = process.stdout }) {
16
+ return new Promise((resolve) => {
17
+ const rl = createInterface({ input, output, terminal: false });
18
+ let done = false;
19
+ const finish = (r) => { if (!done) { done = true; rl.close(); resolve(r); } };
20
+ rl.on('close', () => finish({ ok: false, red: `${NAME_MISMATCH} (no answer)` }));
21
+ output.write(`Signing flow "${name}". Type the flow name to confirm: `);
22
+ rl.once('line', (line) => {
23
+ const typed = line.trim();
24
+ finish(typed !== '' && typed === name ? { ok: true } : { ok: false, red: NAME_MISMATCH });
25
+ });
26
+ });
27
+ }
@@ -38,7 +38,7 @@ const CAP_RE = /^cap \$([^\s]+) per run$/i;
38
38
  // M1 amendment 3 (docs/wiki/the-module-ladder.md, "M1 amendment 3 — the ask
39
39
  // is a mark on its own line — SIGNED by hamr 2026-09-21"): the ask is no
40
40
  // longer a bottom-block arbiter line — it is a mark at the START of a
41
- // numbered job line's own text: `ask:` (default 30m wait) or
41
+ // numbered job line's own text: `ask:` (30m wait — a legacy default, see `unsignedAskTtls`) or
42
42
  // `ask <int><s|m|h>:` (explicit wait), the words after the mark being the
43
43
  // human's own question. OLD_ASK_ARBITER_RE below only detects the RETIRED
44
44
  // bottom-block form (`guardrail: ask at line N`) so it can be refused by
@@ -80,7 +80,7 @@ const DEFAULT_ROUND_BUDGET_MS = 120000;
80
80
  * @param {string} text
81
81
  * @returns {{ attempted: false }
82
82
  * | { attempted: true, ok: false, error: string }
83
- * | { attempted: true, ok: true, ttlMs: number, question: string }}
83
+ * | { attempted: true, ok: true, ttlMs: number, ttlSigned: boolean, question: string }}
84
84
  */
85
85
  function parseAskMark(text) {
86
86
  if (!ASK_MARK_ATTEMPT_RE.test(text)) {
@@ -92,7 +92,7 @@ function parseAskMark(text) {
92
92
  if (question.length === 0) {
93
93
  return { attempted: true, ok: false, error: 'has no words after the mark' };
94
94
  }
95
- return { attempted: true, ok: true, ttlMs: DEFAULT_ASK_TTL_MS, question };
95
+ return { attempted: true, ok: true, ttlMs: DEFAULT_ASK_TTL_MS, ttlSigned: false, question };
96
96
  }
97
97
  const timed = ASK_MARK_TIMED_RE.exec(text);
98
98
  if (timed) {
@@ -105,11 +105,25 @@ function parseAskMark(text) {
105
105
  if (question.length === 0) {
106
106
  return { attempted: true, ok: false, error: 'has no words after the mark' };
107
107
  }
108
- return { attempted: true, ok: true, ttlMs: value * UNIT_MS[unit], question };
108
+ return { attempted: true, ok: true, ttlMs: value * UNIT_MS[unit], ttlSigned: true, question };
109
109
  }
110
110
  return { attempted: true, ok: false, error: 'is not "ask:" or "ask <int><s|m|h>:"' };
111
111
  }
112
112
 
113
+ /**
114
+ * M6a amendment 1: a NEW flow (draft, sign) may not carry an ask whose wait the human never typed. The
115
+ * parser still fills the legacy 30m default for `ask:` so flows signed before the amendment keep running;
116
+ * this names each ask that relies on it. Returns [] when every ask carries `ask <int><s|m|h>:`.
117
+ *
118
+ * @param {{ asks?: Array<{ line: number, ttlSigned?: boolean }> }} arbiter
119
+ * @returns {string[]}
120
+ */
121
+ export function unsignedAskTtls(arbiter) {
122
+ return (arbiter?.asks ?? [])
123
+ .filter((a) => a.ttlSigned !== true)
124
+ .map((a) => `signed-text: the ask on line ${a.line} has no signed wait — write it as "ask <int><s|m|h>:" (e.g. "ask 30m:"); the wait is never a code default`);
125
+ }
126
+
113
127
  /**
114
128
  * Parse the human's signed text. Never throws — any input that isn't a
115
129
  * usable signed text comes back as `{ ok: false, reds }`, never an
@@ -168,7 +182,7 @@ export function parseSignedText(rawText) {
168
182
  reds.push(`signed-text: line ${fileLine} field "asks" ${mark.error}: "${rawLineText}"`);
169
183
  } else {
170
184
  lineText = mark.question;
171
- asks.push({ line: n, ttlMs: mark.ttlMs, question: mark.question });
185
+ asks.push({ line: n, ttlMs: mark.ttlMs, ttlSigned: mark.ttlSigned, question: mark.question });
172
186
  }
173
187
  }
174
188
  current = { n, text: lineText, guardrail: '' };
package/src/types.js CHANGED
@@ -15,6 +15,7 @@
15
15
  * @property {number} line - the numbered line this ask binds to (the line
16
16
  * carries the `ask:`/`ask <int><s|m|h>:` mark itself, M1 amendment 3).
17
17
  * @property {number} ttlMs - the ask's time-to-live in milliseconds.
18
+ * @property {boolean} [ttlSigned] - true when the human typed the wait (`ask <int><s|m|h>:`); false on the legacy `ask:` 30m default, which draft and sign refuse (M6a amendment 1).
18
19
  * @property {string} question - the words after the mark, trimmed — the
19
20
  * human's own question. Nothing reads this yet outside signed-text.js.
20
21
  */
@@ -263,6 +264,11 @@
263
264
 
264
265
  /**
265
266
  * One row appended to `runs/<run-id>/audit.jsonl` (M2 scope item 9).
267
+ * `at`/`tokens` were added by Amendment M4a-2 and `tools`/`ungranted` by
268
+ * Amendment M4a-3 (docs/wiki/the-module-ladder.md, "M4a" section) — every
269
+ * row `appendAudit` writes from here on carries `at`/`tokens`/`tools`; a row
270
+ * written before its amendment simply lacks the newer keys (read back as-is,
271
+ * never backfilled) — see `auditRowTokens`/`auditRowTools` in `src/books.js`.
266
272
  * @typedef {object} AuditRow
267
273
  * @property {string|null} step
268
274
  * @property {number} attempt
@@ -275,6 +281,19 @@
275
281
  * @property {string|null} model
276
282
  * @property {boolean|null} modelMatch
277
283
  * @property {boolean} strike
284
+ * @property {string} at - ISO time this attempt finished.
285
+ * @property {{inputTokens:number, outputTokens:number, cacheReadTokens:number} | null} tokens -
286
+ * summed over this attempt's model calls; `null` only when `model` is
287
+ * `null` (no model call this row).
288
+ * @property {Record<string, number> | null} tools - a {toolName: count}
289
+ * tally of every GRANTED tool the model actually invoked this attempt,
290
+ * summed across every round; `{}` when the model called no tool; `null`
291
+ * only when `model` is `null` (no model call this row).
292
+ * @property {string[]} [ungranted] - tool names the model called that this
293
+ * step never granted; absent when empty, never an invented empty array.
294
+ * @property {Array<{verb:string, path:string, rule:string}>} [refused] - bareguard
295
+ * fs-gate refusals during this attempt; `[]` (never omitted) on every row
296
+ * written by a model attempt, absent on rows with no model call.
278
297
  */
279
298
 
280
299
  /**
package/types/ask.d.ts CHANGED
@@ -16,6 +16,24 @@ export function makeFileAskStep({ timeoutMs, pollMs, clock, writeLine, }?: {
16
16
  decision: string;
17
17
  reason?: string;
18
18
  }>;
19
+ /**
20
+ * @param {any} ask the parsed ask.json object (or its `evidence` field's
21
+ * container — pass the whole ask so a missing `evidence` key is itself a
22
+ * handled case, not the caller's problem).
23
+ * @returns {{ draft: {step?: string, text: string} | null, unjudged: Array<{step: string, emits?: string, text: string}>, why?: string }}
24
+ */
25
+ export function readAskEvidence(ask: any): {
26
+ draft: {
27
+ step?: string;
28
+ text: string;
29
+ } | null;
30
+ unjudged: Array<{
31
+ step: string;
32
+ emits?: string;
33
+ text: string;
34
+ }>;
35
+ why?: string;
36
+ };
19
37
  /**
20
38
  * @param {{ runDir: string, askId: string, decision: 'accept'|'reject'|'rerun', reason?: string, clock?: () => string }} opts
21
39
  * @returns {{ ok: true } | { ok: false, red: string }}
@@ -32,3 +50,62 @@ export function answerAsk({ runDir, askId, decision, reason, clock, }: {
32
50
  ok: false;
33
51
  red: string;
34
52
  };
53
+ /**
54
+ * Writes `asks/<askId>.json` in `runDir`, creating the `asks/` directory if
55
+ * needed. Called by `src/runner.js` right after it writes `ask.json` for a
56
+ * fresh park (same `askId`/`question`/`askedAt`/`expiresAt`/`evidence` — the
57
+ * archive is a permanent copy of the SAME content, not a second source of
58
+ * truth). Exclusive-create: a second call for an already-archived `askId`
59
+ * is refused (a red naming the file) rather than silently overwriting it —
60
+ * proven by the write itself failing (`EEXIST`), not by a separate
61
+ * existence check that a concurrent writer could race past.
62
+ *
63
+ * Crash-order note: this is called AFTER `ask.json` is written, so a crash
64
+ * between the two writes leaves `ask.json` present and `asks/<askId>.json`
65
+ * missing — the run is still correctly parked and resumable (ask.json/
66
+ * state.json govern resume, unchanged), just without its archive entry for
67
+ * that one askId. `listArchivedAsks` below tolerates this (it only reports
68
+ * what is actually on disk); it is never treated as "before M4a-1" (that
69
+ * `why` is reserved for a run with NO `asks/` directory at all).
70
+ *
71
+ * @param {{ runDir: string, askId: string, question: string, askedAt: string, expiresAt: string, evidence: unknown }} opts
72
+ * @returns {{ ok: true } | { ok: false, red: string }}
73
+ */
74
+ export function writeAskArchive({ runDir, askId, question, askedAt, expiresAt, evidence, }: {
75
+ runDir: string;
76
+ askId: string;
77
+ question: string;
78
+ askedAt: string;
79
+ expiresAt: string;
80
+ evidence: unknown;
81
+ }): {
82
+ ok: true;
83
+ } | {
84
+ ok: false;
85
+ red: string;
86
+ };
87
+ /**
88
+ * @param {string} runDir
89
+ * @returns {{ archived: true, asks: Array<{ askId: string, question?: string, askedAt?: string, expiresAt?: string,
90
+ * evidence: ReturnType<typeof readAskEvidence>,
91
+ * answer: { status: string, reason?: string, answeredAt?: string, why?: string } }> } | { archived: false, why: string }}
92
+ */
93
+ export function listArchivedAsks(runDir: string): {
94
+ archived: true;
95
+ asks: Array<{
96
+ askId: string;
97
+ question?: string;
98
+ askedAt?: string;
99
+ expiresAt?: string;
100
+ evidence: ReturnType<typeof readAskEvidence>;
101
+ answer: {
102
+ status: string;
103
+ reason?: string;
104
+ answeredAt?: string;
105
+ why?: string;
106
+ };
107
+ }>;
108
+ } | {
109
+ archived: false;
110
+ why: string;
111
+ };
@@ -0,0 +1,132 @@
1
+ /**
2
+ * The one spec hash. sha256 over the four canonical parts, JSON-array framed so no part can
3
+ * bleed into the next. Never throws.
4
+ * @param {{proseText:string, declarationText:string, inputFactsText:string, readoutText:string, targetText:string}} p
5
+ * @returns {{ok:true, hash:string}|{ok:false, red:string}}
6
+ */
7
+ export function specHash({ proseText, declarationText, inputFactsText, readoutText, targetText, }: {
8
+ proseText: string;
9
+ declarationText: string;
10
+ inputFactsText: string;
11
+ readoutText: string;
12
+ targetText: string;
13
+ }): {
14
+ ok: true;
15
+ hash: string;
16
+ } | {
17
+ ok: false;
18
+ red: string;
19
+ };
20
+ /** Literal (never RegExp) key scrub; a secret under 8 chars is skipped so it can't blank ordinary text. */
21
+ export function scrub(text: any, secrets: any): any;
22
+ /** Count files directly inside `dir` that contain a secret literally. */
23
+ export function sweepForSecrets(dir: any, secrets: any): number;
24
+ /** Exact signed TTL with its unit, never rounded: 2h / 30m / 20s / 1500ms (the largest unit that divides it exactly). */
25
+ export function fmtTtl(ms: any): string;
26
+ /** Plain-text readout of what the human is about to sign. Pure. */
27
+ export function buildReadout({ declaration, arbiter, lines, name, modelId, costUsd, rounds, spendComplete }: {
28
+ declaration: any;
29
+ arbiter: any;
30
+ lines: any;
31
+ name: any;
32
+ modelId: any;
33
+ costUsd: any;
34
+ rounds: any;
35
+ spendComplete: any;
36
+ }): string;
37
+ /** Read the prose file. Refuses (a red, never a throw) on unreadable or blank. */
38
+ export function readProseFile(file: any): {
39
+ ok: boolean;
40
+ red: string;
41
+ text?: undefined;
42
+ } | {
43
+ ok: boolean;
44
+ text: string;
45
+ red?: undefined;
46
+ };
47
+ /**
48
+ * Draft into `dir`. $0 refusals (return {ok:false, wrote:false}, nothing on disk): bad key,
49
+ * unreadable/blank prose, prose that contains the key, missing inputs / bad signed text, dir
50
+ * already exists. After a paid round the dir is ALWAYS written — green (spec.hash present) or
51
+ * red (reds, no spec.hash). Spend is booked in `<dir>/spend.jsonl` with the runner's own
52
+ * writer (appendSpendRow); an unpriced round books null, never 0.
53
+ *
54
+ * Test seam: `provider`/`rates`/`modelId` are injected; without them a live provider is built.
55
+ */
56
+ export function draftToDir({ proseFile, dir, root, name, slot, model, budgetUsd, env, provider, rates, modelId, }: {
57
+ proseFile: any;
58
+ dir: any;
59
+ root: any;
60
+ name: any;
61
+ slot?: string | undefined;
62
+ model: any;
63
+ budgetUsd?: number | undefined;
64
+ env?: NodeJS.ProcessEnv | undefined;
65
+ provider: any;
66
+ rates: any;
67
+ modelId: any;
68
+ }): Promise<{
69
+ ok: boolean;
70
+ wrote: boolean;
71
+ reds: any;
72
+ costUsd: number;
73
+ } | {
74
+ ok: boolean;
75
+ wrote: boolean;
76
+ dir: any;
77
+ reds: any[];
78
+ costUsd: number | null;
79
+ spendComplete: boolean;
80
+ stop: string;
81
+ rounds: number;
82
+ calls: number;
83
+ leaks: number;
84
+ } | {
85
+ ok: boolean;
86
+ wrote: boolean;
87
+ reds: string[];
88
+ costUsd: number | null;
89
+ spendComplete: boolean;
90
+ leaks: number;
91
+ dir?: undefined;
92
+ hash?: undefined;
93
+ stop?: undefined;
94
+ rounds?: undefined;
95
+ calls?: undefined;
96
+ } | {
97
+ ok: boolean;
98
+ wrote: boolean;
99
+ dir: any;
100
+ hash: string | null;
101
+ reds: string[];
102
+ costUsd: number | null;
103
+ spendComplete: boolean;
104
+ stop: string | null;
105
+ rounds: number;
106
+ calls: number;
107
+ leaks: number;
108
+ }>;
109
+ /**
110
+ * The human step, $0. Every refusal returns reds and writes NO flow.
111
+ * `signedBy` must come from the human's own invocation (the CLI's --signed-by/username).
112
+ */
113
+ export function signDraft({ dir, approve, signedBy, signedAt, env, }: {
114
+ dir: any;
115
+ approve: any;
116
+ signedBy: any;
117
+ signedAt?: string | undefined;
118
+ env?: NodeJS.ProcessEnv | undefined;
119
+ }): {
120
+ ok: boolean;
121
+ reds: any[];
122
+ } | {
123
+ ok: boolean;
124
+ flowDir: string;
125
+ signature: import("./types.js").Signature;
126
+ };
127
+ export const DRAFT_BUDGET_USD: 0.1;
128
+ export const SPEC_HASH_FILE: "spec.hash";
129
+ /** Written when the end sweep finds a key in the draft dir; sign refuses a dir that has it. */
130
+ export const LEAK_MARKER_FILE: "scrub-leak.red";
131
+ export function SIGN_LINE(dir: any, hash: any): string;
132
+ export function costText(n: any, spendComplete?: boolean): string;
package/types/books.d.ts CHANGED
@@ -1,13 +1,73 @@
1
1
  /**
2
2
  * One row per attempt (also used for one row per ask and one row per send —
3
3
  * M2 scope item 9). `row` shape: `{ step, attempt, class, verdict, gap, usd,
4
- * spendComplete, wallMs, model, modelMatch, strike }`. Append-only, one
5
- * writer.
4
+ * spendComplete, wallMs, model, modelMatch, strike, at, tokens }` (`at`/
5
+ * `tokens` added by Amendment M4a-2 — every row appended from here on must
6
+ * carry both; a pre-M4a-2 row already on disk simply lacks them, read back
7
+ * as-is by `readAudit`). Append-only, one writer.
6
8
  *
7
9
  * @param {string} runDir
8
10
  * @param {Record<string, any>} row
9
11
  */
10
12
  export function appendAudit(runDir: string, row: Record<string, any>): void;
13
+ /**
14
+ * Amendment M4a-2's own reader helper: the honest reading of one audit
15
+ * row's `tokens`, whether or not it was written before M4a-2 landed. A row
16
+ * that never had a `tokens` key at all (any row appended before this
17
+ * amendment) reads as "not recorded", never as `null` standing in for a
18
+ * genuine zero-token model call and never an invented number. A row that
19
+ * does carry the key (including a post-M4a-2 `tokens: null` no-model-call
20
+ * row) reads back exactly what was written.
21
+ *
22
+ * @param {Record<string, any>} row
23
+ * @returns {{tokens: {inputTokens:number, outputTokens:number, cacheReadTokens:number} | null, why?: string}}
24
+ */
25
+ export function auditRowTokens(row: Record<string, any>): {
26
+ tokens: {
27
+ inputTokens: number;
28
+ outputTokens: number;
29
+ cacheReadTokens: number;
30
+ } | null;
31
+ why?: string;
32
+ };
33
+ /**
34
+ * Amendment M4a-3's own reader helper, the same honest-read shape as
35
+ * `auditRowTokens`/`auditRowAt`: a row written before M4a-3 never had a
36
+ * `tools` key at all, and reads as "not recorded", never as an invented
37
+ * empty tally. A row that does carry the key reads back exactly what was
38
+ * written — `tools` (object or `null`) and `ungranted` (defaulted to `[]`
39
+ * when the writer left it out, never `undefined`).
40
+ *
41
+ * @param {Record<string, any>} row
42
+ * @returns {{tools: Record<string, number> | null, ungranted: string[], why?: string}}
43
+ */
44
+ export function auditRowTools(row: Record<string, any>): {
45
+ tools: Record<string, number> | null;
46
+ ungranted: string[];
47
+ why?: string;
48
+ };
49
+ /**
50
+ * Amendment M4a-2's own reader helper for `at`, the same honest-read shape
51
+ * as `auditRowTokens`: a row written before M4a-2 (any row appended before
52
+ * this amendment, or a raw/legacy line on disk) never had an `at` key at
53
+ * all, and reads as "not recorded", never as `undefined` silently rendered
54
+ * blank. A row that does carry the key reads back exactly what was written.
55
+ *
56
+ * @param {Record<string, any>} row
57
+ * @returns {{at: string|null, why?: string}}
58
+ */
59
+ export function auditRowAt(row: Record<string, any>): {
60
+ at: string | null;
61
+ why?: string;
62
+ };
63
+ /**
64
+ * Read back every row `appendAudit` has written for one run, in file order
65
+ * (append order — never re-sorted). `[]` when the file doesn't exist yet
66
+ * (a run that hasn't made an attempt), never a thrown error.
67
+ * @param {string} runDir
68
+ * @returns {any[]}
69
+ */
70
+ export function readAudit(runDir: string): any[];
11
71
  /**
12
72
  * One row per run. `row` shape: `{ runId, at, outcome, spentUsd,
13
73
  * spendComplete, capUsd, wallMs, signatureHash }`. Append-only, one writer.
@@ -16,3 +76,11 @@ export function appendAudit(runDir: string, row: Record<string, any>): void;
16
76
  * @param {Record<string, any>} row
17
77
  */
18
78
  export function appendHistory(flowDir: string, row: Record<string, any>): void;
79
+ /**
80
+ * Read back every row `appendHistory` has written for one flow, in file
81
+ * order. `[]` when the file doesn't exist yet (a flow with no completed/
82
+ * halted run), never a thrown error.
83
+ * @param {string} flowDir
84
+ * @returns {any[]}
85
+ */
86
+ export function readHistory(flowDir: string): any[];
@@ -27,13 +27,19 @@ export function checkShapes(declaration: any): {
27
27
  * exception.
28
28
  *
29
29
  * @param {unknown} declaration
30
- * @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown }} [context]
30
+ * `wired` (optional Set of verbs): when given, a granted verb outside it is a red
31
+ * by name, even if the catalogue lists it. Omitted = no wired check (existing callers).
32
+ * `verbatimGoals` (optional boolean; M6a amendment 1): when true, a step naming a signed line must carry that line's
33
+ * 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]
31
35
  * @returns {ValidateDeclarationResult}
32
36
  */
33
37
  export function validateDeclaration(declaration: unknown, context?: {
34
38
  arbiter?: unknown;
35
39
  lines?: unknown;
36
40
  catalogue?: unknown;
41
+ wired?: Set<string>;
42
+ verbatimGoals?: boolean;
37
43
  }): ValidateDeclarationResult;
38
44
  /** @typedef {import('./types.js').Arbiter} Arbiter */
39
45
  /** @typedef {import('./types.js').SignedLine} SignedLine */
package/types/docx.d.ts CHANGED
@@ -7,4 +7,12 @@ export function readDocxText(path: string): {
7
7
  ok: false;
8
8
  red: string;
9
9
  };
10
+ /** @param {string} path @returns {{ok:true,headings:string[]}|{ok:false,red:string}} */
11
+ export function readDocxHeadings(path: string): {
12
+ ok: true;
13
+ headings: string[];
14
+ } | {
15
+ ok: false;
16
+ red: string;
17
+ };
10
18
  export const DOCX_MAX_UNCOMPRESSED_BYTES: number;
@@ -0,0 +1,164 @@
1
+ /** The forced tool's parameter schema. `menu` = wiredMenu(). */
2
+ export function buildDeclarationSchema(menu: any): {
3
+ type: string;
4
+ properties: {
5
+ steps: {
6
+ type: string;
7
+ minItems: number;
8
+ items: {
9
+ type: string;
10
+ properties: {
11
+ primitives: {
12
+ type: string;
13
+ items: {
14
+ type: string;
15
+ enum: any;
16
+ };
17
+ description: string;
18
+ };
19
+ reads: {
20
+ type: string;
21
+ items: {
22
+ type: string;
23
+ };
24
+ description: string;
25
+ };
26
+ emits: {
27
+ type: string;
28
+ minLength: number;
29
+ description: string;
30
+ };
31
+ fromLine: {
32
+ type: string[];
33
+ description: string;
34
+ };
35
+ picks: {
36
+ type: string;
37
+ additionalProperties: {
38
+ type: string;
39
+ items: {
40
+ type: string;
41
+ };
42
+ };
43
+ description: string;
44
+ };
45
+ close: {
46
+ type: string;
47
+ properties: {
48
+ class: {
49
+ type: string;
50
+ enum: string[];
51
+ description: string;
52
+ };
53
+ shape: {
54
+ type: string;
55
+ properties: {};
56
+ additionalProperties: boolean;
57
+ description: string;
58
+ };
59
+ };
60
+ required: string[];
61
+ additionalProperties: boolean;
62
+ };
63
+ };
64
+ required: string[];
65
+ additionalProperties: boolean;
66
+ };
67
+ };
68
+ guardrailClasses: {
69
+ type: string;
70
+ additionalProperties: {
71
+ type: string;
72
+ enum: string[];
73
+ };
74
+ description: string;
75
+ };
76
+ unjudgeable: {
77
+ type: string;
78
+ additionalProperties: {
79
+ type: string;
80
+ };
81
+ description: string;
82
+ };
83
+ refused: {
84
+ type: string;
85
+ items: {
86
+ type: string;
87
+ properties: {
88
+ line: {
89
+ type: string;
90
+ };
91
+ reason: {
92
+ type: string;
93
+ minLength: number;
94
+ };
95
+ };
96
+ required: string[];
97
+ additionalProperties: boolean;
98
+ };
99
+ description: string;
100
+ };
101
+ };
102
+ required: string[];
103
+ additionalProperties: boolean;
104
+ };
105
+ export function buildSystemPrompt({ menu, lines, arbiter, factsInfo }: {
106
+ menu: any;
107
+ lines: any;
108
+ arbiter: any;
109
+ factsInfo: any;
110
+ }): string;
111
+ /**
112
+ * A step's goal = its signed line's text, exactly as parseSignedText's `lines` gives it: the words after
113
+ * "N. " (trailing comma kept; on an ask line the mark is stripped, leaving the question). Continuation
114
+ * lines do not exist in the grammar. A step naming no signed line gets a fixed placeholder, never model prose.
115
+ */
116
+ export function goalForLine(fromLine: any, lines: any): any;
117
+ /**
118
+ * Draft one declaration. `provider`/`rates`/`modelId` may be injected (tests,
119
+ * the batch); otherwise a live provider is built from `slot` (throws on a bad
120
+ * key — the batch preflights first). `budgetUsd` is this draft's hard cap.
121
+ * `makeProviderFn` is a test seam: the live-provider factory (default `makeProvider`).
122
+ *
123
+ * @returns {Promise<{ok:boolean, declaration:object|null, reds:string[], rounds:number, calls:number, spendComplete:boolean,
124
+ * costUsd:number|null, modelReturned:string|null, modelId?:string, tokens?:object|null, structureRetries:number, revisions:number, stop:string|null, log:object[]}>}
125
+ */
126
+ export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, budgetUsd, skills, makeProviderFn, }: {
127
+ proseText: any;
128
+ slot?: string | undefined;
129
+ model: any;
130
+ provider: any;
131
+ rates: any;
132
+ modelId: any;
133
+ budgetUsd?: number | undefined;
134
+ skills?: readonly string[] | undefined;
135
+ makeProviderFn?: typeof makeProvider | undefined;
136
+ }): Promise<{
137
+ ok: boolean;
138
+ declaration: object | null;
139
+ reds: string[];
140
+ rounds: number;
141
+ calls: number;
142
+ spendComplete: boolean;
143
+ costUsd: number | null;
144
+ modelReturned: string | null;
145
+ modelId?: string;
146
+ tokens?: object | null;
147
+ structureRetries: number;
148
+ revisions: number;
149
+ stop: string | null;
150
+ log: object[];
151
+ }>;
152
+ export const MAX_STRUCTURE_RETRIES: 2;
153
+ export const MAX_REVISIONS: 2;
154
+ export const DRAFT_MAX_TOKENS: 16000;
155
+ export const DRAFT_SKILLS: readonly string[];
156
+ export const CLASSES: readonly string[];
157
+ export const DRAFT_PROVIDER_OPTIONS: Readonly<{
158
+ thinking: Readonly<{
159
+ type: "disabled";
160
+ }>;
161
+ timeoutMs: 300000;
162
+ deadlineMs: 240000;
163
+ }>;
164
+ import { makeProvider } from './provider.js';