bare-agent 0.59.0 → 0.60.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/README.md +2 -2
- package/bareagent.context.md +29 -60
- package/index.d.ts +2 -5
- package/index.js +2 -5
- package/package.json +5 -1
- package/primitives.json +21 -12
- package/src/{recurse-retrieval.d.ts → recurse-adapters.d.ts} +71 -89
- package/src/{recurse-retrieval.js → recurse-adapters.js} +10 -60
- package/src/recurse-brakes.d.ts +111 -0
- package/src/recurse-brakes.js +154 -0
- package/src/recurse-env.d.ts +43 -0
- package/src/recurse-env.js +233 -0
- package/src/recurse-finish.d.ts +46 -0
- package/src/recurse-finish.js +123 -0
- package/src/recurse-prompts.d.ts +38 -0
- package/src/recurse-prompts.js +69 -1
- package/src/recurse.d.ts +114 -503
- package/src/recurse.js +176 -1513
- package/src/refine-worker.d.ts +155 -0
- package/src/refine-worker.js +598 -0
- package/src/recurse-synthesize.d.ts +0 -53
- package/src/recurse-synthesize.js +0 -106
package/src/recurse.d.ts
CHANGED
|
@@ -1,45 +1,34 @@
|
|
|
1
|
+
export type Provider = import("../types").Provider;
|
|
2
|
+
export type ToolDef = import("../types").ToolDef;
|
|
3
|
+
export type Verdict = import("./evaluator").Verdict;
|
|
4
|
+
export type Slice = {
|
|
5
|
+
id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
1
8
|
/**
|
|
2
|
-
* The per-run
|
|
3
|
-
* Loop's `policy`/governance via `options.ctx`). Distinct from `opts` (the policy knobs).
|
|
9
|
+
* The per-run wiring, threaded down the recursion tree and forwarded to every Loop's governance.
|
|
4
10
|
*/
|
|
5
11
|
export type RecurseCtx = {
|
|
6
12
|
/**
|
|
7
|
-
* - The model
|
|
13
|
+
* - The model. Required (here or on `opts.provider`).
|
|
8
14
|
*/
|
|
9
15
|
provider?: import("../types").Provider | undefined;
|
|
10
16
|
/**
|
|
11
|
-
* - bareguard `policy(tool, args, ctx)
|
|
12
|
-
* enforce `limits.maxDepth`/budget/calls. recurse adds NO second guard layer (§6).
|
|
17
|
+
* - bareguard `policy(tool, args, ctx)`; sees `ctx.depth`. Money stays the gate's.
|
|
13
18
|
*/
|
|
14
19
|
policy?: Function | undefined;
|
|
15
20
|
/**
|
|
16
|
-
* -
|
|
17
|
-
* and worker tokens are all real spend (BA1: never invisible).
|
|
21
|
+
* - Metering hook forwarded to every Loop AND the verifier (never invisible spend).
|
|
18
22
|
*/
|
|
19
23
|
onLlmResult?: Function | undefined;
|
|
20
24
|
/**
|
|
21
|
-
* -
|
|
22
|
-
* threaded into `policy`. Callers normally omit it (defaults to 0).
|
|
25
|
+
* - Current recursion depth (0 at the top; callers normally omit it).
|
|
23
26
|
*/
|
|
24
27
|
depth?: number | undefined;
|
|
25
28
|
/**
|
|
26
|
-
* - Optional event stream forwarded to
|
|
27
|
-
* is the observability channel for worker activity (relayfact F15/BA-5): recurse intentionally does NOT take
|
|
28
|
-
* `onToolCall`/`onText` Loop callbacks — instead every worker Loop emits `loop:tool_call` / `loop:tool_result`
|
|
29
|
-
* (and `loop:text`/`loop:done`) to THIS stream (loop.js), so a consumer observes worker tool calls by reading
|
|
30
|
-
* the stream, not via per-call callbacks. The full audit trail is stream + the RC-10 receipts tree + (if a
|
|
31
|
-
* gate is wired) the bareguard audit.
|
|
29
|
+
* - Optional event stream forwarded to the root worker Loop; also gets `recurse:limits`.
|
|
32
30
|
*/
|
|
33
31
|
stream?: object;
|
|
34
|
-
/**
|
|
35
|
-
* - Optional litectx handle (RC-5, §10 step 7). Backs the `search`
|
|
36
|
-
* retrieval mode (`recall`). NOT used by `scan` — litectx has no exhaustive enumerate verb today; scan reads
|
|
37
|
-
* the generic array slice-source `opts.corpus` instead (the litectx-resident scan case waits on the litectx
|
|
38
|
-
* `enumerate` verb and drops in behind the same socket).
|
|
39
|
-
*/
|
|
40
|
-
litectx?: {
|
|
41
|
-
recall: Function;
|
|
42
|
-
} | undefined;
|
|
43
32
|
};
|
|
44
33
|
export type RecurseOptions = {
|
|
45
34
|
/**
|
|
@@ -47,182 +36,89 @@ export type RecurseOptions = {
|
|
|
47
36
|
*/
|
|
48
37
|
provider?: import("../types").Provider | undefined;
|
|
49
38
|
/**
|
|
50
|
-
* -
|
|
51
|
-
*
|
|
52
|
-
*
|
|
39
|
+
* - The data the task is about. Lives in the env var
|
|
40
|
+
* `input`; the root prompt shows ONLY metadata (type, size, short prefix). A function is awaited once. Malformed or
|
|
41
|
+
* duplicate `Slice`s are dropped and counted in `receipts.input.dropped`.
|
|
53
42
|
*/
|
|
54
|
-
|
|
43
|
+
input?: string | Slice[] | (() => Promise<Slice[]>) | undefined;
|
|
55
44
|
/**
|
|
56
|
-
* -
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* NOT applied to the isolated verifier (would defeat the anti-sycophancy isolation, A1) nor the deterministic
|
|
61
|
-
* scan judge. Absent/blank ⇒ the worker prompt is byte-identical to pre-0.21 (backward-compatible).
|
|
62
|
-
* **SECURITY:** this is a PRIVILEGED system-prompt seam — treat `persona` like a system prompt. Do NOT pass
|
|
63
|
-
* untrusted / end-user-controlled text here; a hostile persona is prepended ahead of the decomposition policy
|
|
64
|
-
* and can override it (and any safety framing) for every worker in the tree. Caller-trusted input only.
|
|
45
|
+
* - The answer kind the CALLER expects. `count`/`ids`: the
|
|
46
|
+
* model must cite a classify var with `final(var)` and CODE derives `{count, ids}`; `composite`: `final_parts`
|
|
47
|
+
* gives `{needle, count:{count, ids}}`; `text`: `final_text`/`final(var)`, or a plain reply. A wrong-kind final gets
|
|
48
|
+
* ONE nudge, then `{incomplete, blocker:'wrong-final'}`; no final at all is `blocker:'no-final'`.
|
|
65
49
|
*/
|
|
66
|
-
|
|
50
|
+
kind?: "text" | "count" | "ids" | "composite" | undefined;
|
|
67
51
|
/**
|
|
68
|
-
* -
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* paths / cwd) the Planner strips when it paraphrases the parent goal into child subtasks. CARRIES DOWN the
|
|
72
|
-
* tree (preserved by `forChild`, like `persona`) and, when forced fan-out plans, is forwarded as the Planner's
|
|
73
|
-
* `info` so the slices themselves are path-aware. Also shown to the verifier (neutral FACTS, not a stance, so
|
|
74
|
-
* no anti-sycophancy concern — and an agentic critic needs the path to exercise the artifact). Distinct from
|
|
75
|
-
* `persona`: persona is a privileged SYSTEM-prompt stance; context is run-state facts on the USER message.
|
|
76
|
-
* Absent/blank ⇒ byte-identical to pre-BA-9 (backward-compatible). Validated live (`poc/ba9-context-thread.mjs`:
|
|
77
|
-
* a weak model went 0/3 → 3/3 at locating an unguessable file once the root was threaded).
|
|
78
|
-
* **SECURITY:** this becomes part of every worker's prompt (and the verifier's) — lower-privilege than
|
|
79
|
-
* `persona` (the USER message, not the SYSTEM prompt) but still a prompt-injection surface. Intended for
|
|
80
|
-
* TRUSTED run-state (paths/cwd); do NOT pass untrusted / end-user-controlled text here.
|
|
52
|
+
* - Structural
|
|
53
|
+
* brakes (default ON, even with a gate). `maxCalls` is TIGHTEN-ONLY against a formula cap computed from the input size;
|
|
54
|
+
* `'none'` disables them and every return carries `unbraked:true`. Money/tokens/wall-clock stay with bareguard.
|
|
81
55
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
tools?: import("../types").ToolDef[] | undefined;
|
|
88
|
-
/**
|
|
89
|
-
* (Opt-in, BA-8 / relayfact F17) Turn a DEFINITE LEAF (a node that is offered no `spawn_child` — `simple`
|
|
90
|
-
* tier or at `maxDepth`) into a bounded generate→sense→regenerate loop instead of a single pass, so a failed
|
|
91
|
-
* slice can self-correct. `sensor` is a DETERMINISTIC close (test/compile/lint — NOT a model judge, R-S8) that
|
|
92
|
-
* returns a `Verdict`; on a non-pass its `critique` (the GAP, not the transcript) is fed FRESH into the next
|
|
93
|
-
* attempt (D6/A1 anti-anchoring) and, on models that ACCEPT `temperature`, the **retry temperature ESCALATES**
|
|
94
|
-
* (`temperatures`, default `[0.2,0.7,1.0]`) — the live-validated lever that lets a weak model escape a
|
|
95
|
-
* repeat-the-same-mistake rut (`poc/ba8-leaf-refine.mjs`: 0/5 → 2-3/5; flat temp recovers 0/5). On a
|
|
96
|
-
* temperature-fixed model (BA-10) the provider drops the param, `receipts.refineLeaf.temperatures` records
|
|
97
|
-
* `null`, and the fed-back gap critique carries recovery alone — UNLESS the rejected-attempt buffer engages
|
|
98
|
-
* (below). `maxIterations` defaults to
|
|
99
|
-
* `temperatures.length`; the REAL bound is bareguard (each attempt is gate-checked + metered). CARRIES DOWN the
|
|
100
|
-
* tree (preserved by `forChild`), so it engages at the leaves of a Family-A decomposition. Recovery is PARTIAL
|
|
101
|
-
* (a stubborn blind spot may persist) — `receipts.refineLeaf.passed` reports honestly. Does NOT apply to a node
|
|
102
|
-
* that delegates (its children + the tree verify own quality), nor to the scan/fanout/partition dispatch paths.
|
|
103
|
-
* Absent ⇒ a leaf is a single pass (byte-identical to pre-BA-8). An error-keyed `recall` is the CALLER's tool
|
|
104
|
-
* (`opts.tools`) keyed off the fed-back critique — bareagent stays litectx-agnostic.
|
|
105
|
-
* **Sensor integrity (RSI-learnings #1/#5, "audit the close"):** the `sensor` MUST judge the RETURNED result
|
|
106
|
-
* (tamper-proof — e.g. build/run the returned string in an isolated context, as `poc/ba8-leaf-refine.mjs` does),
|
|
107
|
-
* NEVER a worker side-effect a worker with edit tools could GAME (writing a passing file then returning junk, or
|
|
108
|
-
* editing the failing test itself). A gameable close is the reward-hacking surface every RSI system in the field
|
|
109
|
-
* got bitten by; the loop optimizes against WHATEVER the sensor reads, so keep it outside what the worker can write.
|
|
110
|
-
* **Broken sensor ≠ failing model (BA-15):** a sensor that THROWS (non-Halt) or returns a MALFORMED verdict
|
|
111
|
-
* (anything but `{pass: boolean}` or a valid tri-state `status`) is a faulty ARBITER — the loop stops at the
|
|
112
|
-
* FIRST broken close (never retries against it) and returns a labeled `{incomplete, blocker:'broken-sensor'}`
|
|
113
|
-
* (+ `receipts.blockerDetail`), with `best` preserving the model's last attempt. A `HaltError` thrown by the
|
|
114
|
-
* sensor stays a clean governance halt. The sensor's EXECUTION environment is the caller's: run untrusted /
|
|
115
|
-
* model-generated checks in an isolated child process WITH A TIMEOUT — a sensor that hangs forever hangs the
|
|
116
|
-
* leaf (no bareguard checkpoint fires between sensor start and return; confirmed by `poc/rlmplans-hung-sensor.mjs`).
|
|
117
|
-
* **`rejectedBuffer` (BA-14):** a SkillOpt-shaped rejected-attempt buffer — instead of only the LATEST critique,
|
|
118
|
-
* surface the model's OWN prior failed attempts verbatim ("you wrote these, they failed X — write something
|
|
119
|
-
* STRUCTURALLY DIFFERENT"). This is DIRECTED diversity (attack the specific repeated mistake), where escalation
|
|
120
|
-
* is RANDOM diversity; the two are ANTAGONISTIC (`poc/ba14b-temp-with-buffer.mjs`: temperature monotonically
|
|
121
|
-
* degrades the buffer, 100%→70%→50% across 0.2/0.7/1.0), so when the buffer engages the retry temperature is
|
|
122
|
-
* HELD at `temperatures[0]` (flat-low), never escalated. `true` = force on (also on temperature-accepting
|
|
123
|
-
* models); `false` = force off (pure BA-8 escalation); UNSET = ADAPTIVE — engage only once a prior attempt's
|
|
124
|
-
* temperature was dropped (a temperature-fixed model, BA-10, where escalation is inert and the buffer is the
|
|
125
|
-
* sole lever — `poc/ba14-rejected-buffer.mjs`: flat-temp 50%→100%). `receipts.refineLeaf.rejectedBuffer`
|
|
126
|
-
* reports whether any iteration injected it. Bounded by `maxIterations` (the buffer never outgrows it).
|
|
127
|
-
*/
|
|
128
|
-
refineLeaf?: {
|
|
129
|
-
sensor: (result: any, ctx: {
|
|
130
|
-
task: string;
|
|
131
|
-
context: string | undefined;
|
|
132
|
-
contract: string | null;
|
|
133
|
-
}) => (Verdict | Promise<Verdict>);
|
|
134
|
-
maxIterations?: number;
|
|
135
|
-
temperatures?: number[];
|
|
136
|
-
rejectedBuffer?: boolean;
|
|
56
|
+
limits?: "none" | {
|
|
57
|
+
maxDepth?: number;
|
|
58
|
+
maxCalls?: number;
|
|
59
|
+
maxWidth?: number;
|
|
60
|
+
maxRounds?: number;
|
|
137
61
|
} | undefined;
|
|
138
62
|
/**
|
|
139
|
-
* -
|
|
140
|
-
* not the loose task, and verification always runs.
|
|
63
|
+
* - Shorthand for `limits.maxDepth`.
|
|
141
64
|
*/
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Override the verifier (fills `recurse()`'s verify slot, §7.1). Default = an `Evaluator` rubric pass.
|
|
145
|
-
*/
|
|
146
|
-
evaluate?: ((result: any, ctx: {
|
|
147
|
-
contract: string | null;
|
|
148
|
-
task: string;
|
|
149
|
-
}) => (Verdict | Promise<Verdict>)) | undefined;
|
|
150
|
-
/**
|
|
151
|
-
* Override synthesis/reduce (NB-3). A FUNCTION is a deterministic code-reduce over the child `results` — the
|
|
152
|
-
* §9.1 aggregation path (LLM arithmetic over partials carried ~10–15% error). A STRATEGY string runs the
|
|
153
|
-
* built-in reducer: `'concat'` (lossless no-LLM join) or `'merge'` (an isolated Loop-driven subjective
|
|
154
|
-
* merge); a string is ignored when no child ran. Default (unset) = the worker's own final text (Family A:
|
|
155
|
-
* the parent model already combined the children's results in its closing turn).
|
|
156
|
-
*/
|
|
157
|
-
synthesize?: "concat" | "merge" | ((args: {
|
|
158
|
-
task: string;
|
|
159
|
-
text: string | null;
|
|
160
|
-
results: any[];
|
|
161
|
-
children: object[];
|
|
162
|
-
ctx: RecurseCtx;
|
|
163
|
-
}) => any) | undefined;
|
|
65
|
+
maxDepth?: number | undefined;
|
|
164
66
|
/**
|
|
165
|
-
* - (
|
|
166
|
-
* independent parallel workers via `Planner`→`runPlan`, then reduce. A positive integer here is the count;
|
|
167
|
-
* it OVERRIDES the tier→count map. Setting it (or `mode:'fanout'`) takes the deterministic-parallelism path
|
|
168
|
-
* instead of the model-driven Family-A default. For known-parallel tasks where the caller wants guaranteed
|
|
169
|
-
* fan-out, not the model's adaptive choice.
|
|
67
|
+
* - Caller USD-per-1K token rates (same semantics as `Loop({rates})`): when given, `metrics.costUsd` is priced from them (authoritative); otherwise it is a flagged tier guess, or null if any round carries no usage.
|
|
170
68
|
*/
|
|
171
|
-
|
|
69
|
+
rates?: {
|
|
70
|
+
in: number;
|
|
71
|
+
out: number;
|
|
72
|
+
cacheReadMult?: number;
|
|
73
|
+
cacheWriteMult?: number;
|
|
74
|
+
} | undefined;
|
|
172
75
|
/**
|
|
173
|
-
* -
|
|
174
|
-
* WITHOUT a fixed count — derived from `assessComplexity`'s tier via the calibrated map (medium/complex/
|
|
175
|
-
* critical → 2/4/6; simple → 1); `opts.count` takes precedence. `'partition'` = the DATA-DRIVEN WIDTH path
|
|
176
|
-
* (§11): measure `opts.corpus` and partition it into `max(opts.count floor, ⌈size/workerBudget⌉)` parallel
|
|
177
|
-
* scan-workers (capped by the guards), CODE-reducing the per-chunk counts. Distinct from `'fanout'`: a data
|
|
178
|
-
* partition, not a `Planner` semantic split.
|
|
76
|
+
* - Max sub-calls in flight per fan-out.
|
|
179
77
|
*/
|
|
180
|
-
|
|
78
|
+
concurrency?: number | undefined;
|
|
181
79
|
/**
|
|
182
|
-
* -
|
|
183
|
-
*
|
|
80
|
+
* - Caller stance PREPENDED to every env worker's system prompt (carries down; never the
|
|
81
|
+
* verifier or the classify judge). PRIVILEGED seam: trusted text only.
|
|
184
82
|
*/
|
|
185
|
-
|
|
83
|
+
persona?: string | undefined;
|
|
186
84
|
/**
|
|
187
|
-
* - (
|
|
188
|
-
*
|
|
85
|
+
* - Read-only working-context (paths/cwd) put on the USER message of every worker and shown
|
|
86
|
+
* to the verifier. Carries down. Trusted run-state only.
|
|
189
87
|
*/
|
|
190
|
-
|
|
88
|
+
context?: string | undefined;
|
|
191
89
|
/**
|
|
192
|
-
* -
|
|
193
|
-
* CORPUS, routed by question shape (§9.2.1). `'scan'` (the default WHEN `opts.corpus` is present) = process
|
|
194
|
-
* every slice + LLM-judge + CODE-count — the only COMPLETE path (for "how many / all"). `'search'` = litectx
|
|
195
|
-
* `recall` handle tool offered to the worker (needle; CANNOT count; requires `ctx.litectx`). `'exact'` = a
|
|
196
|
-
* deterministic code-side AND-term filter tool over `opts.corpus`. `'tools'` = the PER-QUERY Family-A face:
|
|
197
|
-
* offer the worker `scan_count` (over `opts.corpus`) + `search_memory` (when `ctx.litectx`) + `exact_match`
|
|
198
|
-
* (array corpus) ALL AT ONCE, and let it pick the shape PER SUB-QUERY — the routing lives in the tool
|
|
199
|
-
* descriptions (scan says "use for how many / all / count"; search says "never count"), so a mixed task gets
|
|
200
|
-
* needle-search AND complete-count without per-sub-query adopter declaration. The completeness guard upgrades a
|
|
201
|
-
* `'search'` on a "how many / all" ask to `'scan'` (UPGRADE-only, never a silent downgrade); it does NOT fire
|
|
202
|
-
* for `'tools'` (the complete `scan_count` is always offered there, so a mixed task keeps its search tool).
|
|
203
|
-
* Absent `corpus` AND `retrieval`, behaviour is unchanged (Family A / single-shot) — fully backward-compatible.
|
|
90
|
+
* - Caller tools appended to the fixed env tools (carry down).
|
|
204
91
|
*/
|
|
205
|
-
|
|
92
|
+
tools?: import("../types").ToolDef[] | undefined;
|
|
206
93
|
/**
|
|
207
|
-
* -
|
|
208
|
-
* reads: an in-hand `{id, text}[]` array, OR an async `() => Promise<Slice[]>` (e.g. `litectxCorpus(litectx,
|
|
209
|
-
* {kind})` materializing a litectx-resident corpus via `enumerate`). recurse depends on this SHAPE, never on
|
|
210
|
-
* litectx. Malformed entries are dropped, never miscounted.
|
|
94
|
+
* - Definition of done; the isolated verifier grades against it (top node only).
|
|
211
95
|
*/
|
|
212
|
-
|
|
96
|
+
contract?: string | undefined;
|
|
213
97
|
/**
|
|
214
|
-
* -
|
|
215
|
-
* calibrated number; per-model).
|
|
98
|
+
* - Override the verifier.
|
|
216
99
|
*/
|
|
217
|
-
|
|
100
|
+
evaluate?: ((result: any, ctx: {
|
|
101
|
+
contract: string | null;
|
|
102
|
+
task: string;
|
|
103
|
+
}) => (Verdict | Promise<Verdict>)) | undefined;
|
|
218
104
|
/**
|
|
219
|
-
*
|
|
105
|
+
* Compat shim ONLY, with `maxDepth:0`: forwards to `refineWorker()` and warns once per process. Use `refineWorker`.
|
|
220
106
|
*/
|
|
221
|
-
|
|
107
|
+
refineLeaf?: {
|
|
108
|
+
sensor: (result: any, ctx: {
|
|
109
|
+
task: string;
|
|
110
|
+
context: string | undefined;
|
|
111
|
+
contract: string | null;
|
|
112
|
+
}) => (Verdict | Promise<Verdict>);
|
|
113
|
+
maxIterations?: number;
|
|
114
|
+
temperatures?: number[];
|
|
115
|
+
rejectedBuffer?: boolean;
|
|
116
|
+
} | undefined;
|
|
222
117
|
};
|
|
223
118
|
/**
|
|
224
|
-
* One
|
|
225
|
-
*
|
|
119
|
+
* One receipts node (RC-10). Besides lineage (`spawned`), it carries the run's own facts, set before the first call:
|
|
120
|
+
* `limits`, `cap`; and updated as it runs: `rounds`, `rootPeakInput` (max per-round input tokens), `vars`, `memoHits`,
|
|
121
|
+
* `nudges`, `toolCalls` (counts by tool), `calls` (root only: whole-tree LLM calls), `input` `{type, items, dropped}`.
|
|
226
122
|
*/
|
|
227
123
|
export type RecurseNode = {
|
|
228
124
|
task: string;
|
|
@@ -232,383 +128,98 @@ export type RecurseNode = {
|
|
|
232
128
|
score: number;
|
|
233
129
|
};
|
|
234
130
|
critical: boolean;
|
|
235
|
-
/**
|
|
236
|
-
* - Child nodes (lineage).
|
|
237
|
-
*/
|
|
238
131
|
spawned: RecurseNode[];
|
|
239
132
|
verdict: Verdict | null;
|
|
240
133
|
incomplete: boolean;
|
|
241
134
|
halted: boolean;
|
|
242
135
|
/**
|
|
243
|
-
* -
|
|
244
|
-
* `RecurseResult.blocker`): `'governance-deny'` (BA-11) — its Loop short-circuited a consecutive-policy-deny
|
|
245
|
-
* spin; `'broken-sensor'` (BA-15) — the caller's `refineLeaf.sensor` threw or returned a malformed verdict;
|
|
246
|
-
* `'broken-verifier'` (BA-15) — the caller's `opts.evaluate` did (the default Evaluator path is never labeled).
|
|
136
|
+
* - This node stopped for a specific reason (`brake`, `halt`, `wrong-final`, `no-final`, `governance-deny`, `verify-failed`, `broken-verifier`, `broken-sensor`, `error`, `input`).
|
|
247
137
|
*/
|
|
248
138
|
blocker?: string | undefined;
|
|
249
|
-
/**
|
|
250
|
-
* - (BA-15) with a `broken-*` blocker: what the arbiter did (threw with
|
|
251
|
-
* which message, or which malformed shape it returned) — the actionable half of the label.
|
|
252
|
-
*/
|
|
253
139
|
blockerDetail?: string | undefined;
|
|
254
140
|
/**
|
|
255
|
-
* - (
|
|
256
|
-
* DESCENDANT's blocker, surfaced here so an aggregating node still reports the fault upward. Deliberately
|
|
257
|
-
* SEPARATE from this node's own `blocker` (which means "THIS node's arbiter/Loop broke"): stamping a
|
|
258
|
-
* descendant's label onto every ancestor made the receipts tree accuse nodes whose sensor never ran, and
|
|
259
|
-
* re-labelled a parent `governance-deny` when only one child was denied. `blockerTask` names the culprit.
|
|
141
|
+
* - A DESCENDANT's blocker (never stamped as this node's own).
|
|
260
142
|
*/
|
|
261
143
|
blockerFrom?: {
|
|
262
144
|
blocker: string;
|
|
263
145
|
blockerDetail?: string;
|
|
264
146
|
blockerTask?: string;
|
|
265
147
|
} | undefined;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
*/
|
|
148
|
+
best?: any;
|
|
149
|
+
missingSlices?: string[] | undefined;
|
|
269
150
|
tokens: object | null;
|
|
270
|
-
/**
|
|
271
|
-
* - (BA-8) when
|
|
272
|
-
* this leaf ran as a bounded refine loop: how many attempts it took and whether the deterministic sensor finally
|
|
273
|
-
* passed (false = honest non-recovery, not a faked success). `temperatures` are the EFFECTIVE per-attempt temps
|
|
274
|
-
* (BA-10): a `null` marks an attempt the model ran at its DEFAULT because it rejected the requested temperature.
|
|
275
|
-
* `rejectedBuffer` (BA-14): whether any iteration injected the rejected-attempt buffer (prior failed attempts
|
|
276
|
-
* surfaced verbatim); when it engages the REQUESTED retry temperature is held flat at `temperatures[0]`, never
|
|
277
|
-
* escalated (ba14b antagonism) — but a temperature-fixed model still drops it, so the EFFECTIVE temp recorded
|
|
278
|
-
* above is `null`, not `temperatures[0]`.
|
|
279
|
-
*/
|
|
280
|
-
refineLeaf?: {
|
|
281
|
-
iterations: number;
|
|
282
|
-
passed: boolean;
|
|
283
|
-
temperatures: (number | null)[];
|
|
284
|
-
rejectedBuffer: boolean;
|
|
285
|
-
} | undefined;
|
|
286
151
|
model: string | null;
|
|
287
152
|
/**
|
|
288
|
-
* -
|
|
289
|
-
* or null/absent for a plain reasoning node.
|
|
153
|
+
* - unused in v2 (kept for the refineWorker node shape).
|
|
290
154
|
*/
|
|
291
155
|
retrieval?: string | null | undefined;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
} | undefined;
|
|
307
|
-
/**
|
|
308
|
-
* - (`mode:'partition'`) the data-driven width audit: corpus size, the budget knob, the count floor, the
|
|
309
|
-
* data-derived width `⌈size/budget⌉`, the chosen `width = max(floor, dataWidth)`, and matched count.
|
|
310
|
-
*/
|
|
311
|
-
partition?: {
|
|
312
|
-
size: number;
|
|
313
|
-
workerBudget: number;
|
|
314
|
-
floor: number;
|
|
315
|
-
dataWidth: number;
|
|
316
|
-
width: number;
|
|
317
|
-
matched?: number;
|
|
156
|
+
refineLeaf?: any;
|
|
157
|
+
limits?: any;
|
|
158
|
+
cap?: number | undefined;
|
|
159
|
+
calls?: number | undefined;
|
|
160
|
+
rounds?: number | undefined;
|
|
161
|
+
rootPeakInput?: number | undefined;
|
|
162
|
+
vars?: number | undefined;
|
|
163
|
+
memoHits?: number | undefined;
|
|
164
|
+
nudges?: number | undefined;
|
|
165
|
+
toolCalls?: Record<string, number> | undefined;
|
|
166
|
+
input?: {
|
|
167
|
+
type: string;
|
|
168
|
+
items: number;
|
|
169
|
+
dropped: number;
|
|
318
170
|
} | undefined;
|
|
319
171
|
};
|
|
320
172
|
export type RecurseResult = {
|
|
321
173
|
/**
|
|
322
|
-
* -
|
|
174
|
+
* - On success: `{count, ids}` (count/ids), `{needle, count}` (composite) or a string (text).
|
|
323
175
|
*/
|
|
324
176
|
result?: any;
|
|
325
|
-
/**
|
|
326
|
-
* - The verifier's gap report (null when verification did not run).
|
|
327
|
-
*/
|
|
328
177
|
verdict?: import("./evaluator").Verdict | null | undefined;
|
|
329
178
|
/**
|
|
330
|
-
* -
|
|
331
|
-
* never a faked pass.
|
|
179
|
+
* - The ONE "not done" signal: brake, gate halt, dead slot, failed verify, wrong/no final. Never a faked pass.
|
|
332
180
|
*/
|
|
333
181
|
incomplete?: boolean | undefined;
|
|
334
182
|
/**
|
|
335
|
-
* -
|
|
183
|
+
* - Last non-empty work when `incomplete` (BA-5).
|
|
336
184
|
*/
|
|
337
185
|
best?: any;
|
|
338
186
|
/**
|
|
339
|
-
* -
|
|
340
|
-
* back incomplete (§9 scenario 1) — the anti-survivor-sum signal, not a quiet undercount.
|
|
187
|
+
* - Pieces that never produced an answer (never survivor-summed).
|
|
341
188
|
*/
|
|
342
189
|
missingSlices?: string[] | undefined;
|
|
343
|
-
/**
|
|
344
|
-
* - Present when `incomplete` for a specific, actionable reason. `'governance-deny'`
|
|
345
|
-
* (BA-11): the worker's Loop short-circuited after N consecutive policy denials rather than burn to the
|
|
346
|
-
* budget cap — the caller can widen scope / re-gate / escalate instead of reading it as a model failure.
|
|
347
|
-
* `'broken-sensor'` (BA-15): the caller's `refineLeaf.sensor` threw or returned a malformed verdict — the
|
|
348
|
-
* ARBITER is faulty, not the model; fix the sensor and re-run (`receipts.blockerDetail` says what it did).
|
|
349
|
-
* `'broken-verifier'` (BA-15): same fault class at the verify slot — the caller's `opts.evaluate` threw
|
|
350
|
-
* (non-Halt) or returned a malformed verdict; the default Evaluator path is never labeled (its failures are
|
|
351
|
-
* provider-class faults). For both `broken-*` blockers `best` preserves the model's last non-empty output
|
|
352
|
-
* (BA-5) — the arbiter broke, so treat it as best-effort work rather than a graded pass.
|
|
353
|
-
*/
|
|
354
190
|
blocker?: string | undefined;
|
|
355
191
|
/**
|
|
356
|
-
* -
|
|
357
|
-
* ACTIONABLE half of the label, surfaced on the result (not only in `receipts`) so a caller branching on
|
|
358
|
-
* `blocker` can report the cause without walking the receipts tree.
|
|
192
|
+
* - With `blocker:'brake'`: `maxCalls`/`maxWidth`/`maxRounds`.
|
|
359
193
|
*/
|
|
194
|
+
brake?: string | undefined;
|
|
360
195
|
blockerDetail?: string | undefined;
|
|
196
|
+
blockerTask?: string | undefined;
|
|
361
197
|
/**
|
|
362
|
-
* - (
|
|
363
|
-
* which sub-task actually broke. Without it a nested failure reports "a sensor broke" with no way to find
|
|
364
|
-
* which one.
|
|
198
|
+
* - Present (true) under `limits:'none'`.
|
|
365
199
|
*/
|
|
366
|
-
|
|
200
|
+
unbraked?: boolean | undefined;
|
|
367
201
|
/**
|
|
368
|
-
* -
|
|
202
|
+
* - Root only: whole-tree calls/tokens/cost (null if any node is unpriced).
|
|
369
203
|
*/
|
|
204
|
+
metrics?: {
|
|
205
|
+
calls: number;
|
|
206
|
+
tokens: object;
|
|
207
|
+
costUsd: number | null;
|
|
208
|
+
} | undefined;
|
|
370
209
|
receipts: RecurseNode;
|
|
371
210
|
};
|
|
372
|
-
export type Provider = import("../types").Provider;
|
|
373
|
-
export type ToolDef = import("../types").ToolDef;
|
|
374
|
-
export type Verdict = import("./evaluator").Verdict;
|
|
375
|
-
export type Slice = {
|
|
376
|
-
id: string;
|
|
377
|
-
text: string;
|
|
378
|
-
};
|
|
379
|
-
/**
|
|
380
|
-
* @typedef {object} RecurseCtx
|
|
381
|
-
* The per-run runtime blob — the wiring, threaded down the whole recursion tree (and forwarded to the worker
|
|
382
|
-
* Loop's `policy`/governance via `options.ctx`). Distinct from `opts` (the policy knobs).
|
|
383
|
-
* @property {Provider} [provider] - The model the workers call. Required (here or on `opts.provider`).
|
|
384
|
-
* @property {Function} [policy] - bareguard `policy(tool, args, ctx)` — the gate. Sees `ctx.depth` so it can
|
|
385
|
-
* enforce `limits.maxDepth`/budget/calls. recurse adds NO second guard layer (§6).
|
|
386
|
-
* @property {Function} [onLlmResult] - Budget hook forwarded to every worker Loop AND the verifier — judge
|
|
387
|
-
* and worker tokens are all real spend (BA1: never invisible).
|
|
388
|
-
* @property {number} [depth] - The current recursion depth (0 at the top). Incremented on each self-call;
|
|
389
|
-
* threaded into `policy`. Callers normally omit it (defaults to 0).
|
|
390
|
-
* @property {object} [stream] - Optional event stream forwarded to each worker Loop (receipts substrate). This
|
|
391
|
-
* is the observability channel for worker activity (relayfact F15/BA-5): recurse intentionally does NOT take
|
|
392
|
-
* `onToolCall`/`onText` Loop callbacks — instead every worker Loop emits `loop:tool_call` / `loop:tool_result`
|
|
393
|
-
* (and `loop:text`/`loop:done`) to THIS stream (loop.js), so a consumer observes worker tool calls by reading
|
|
394
|
-
* the stream, not via per-call callbacks. The full audit trail is stream + the RC-10 receipts tree + (if a
|
|
395
|
-
* gate is wired) the bareguard audit.
|
|
396
|
-
* @property {{recall: Function}} [litectx] - Optional litectx handle (RC-5, §10 step 7). Backs the `search`
|
|
397
|
-
* retrieval mode (`recall`). NOT used by `scan` — litectx has no exhaustive enumerate verb today; scan reads
|
|
398
|
-
* the generic array slice-source `opts.corpus` instead (the litectx-resident scan case waits on the litectx
|
|
399
|
-
* `enumerate` verb and drops in behind the same socket).
|
|
400
|
-
*/
|
|
401
|
-
/**
|
|
402
|
-
* @typedef {object} RecurseOptions
|
|
403
|
-
* @property {Provider} [provider] - Fallback provider if `ctx.provider` is absent.
|
|
404
|
-
* @property {number} [maxDepth=3] - Open topology ceiling (§1): the depth past which the `spawn_child` tool is
|
|
405
|
-
* no longer offered (`maxDepth=1` ⇒ flat fan-out, no nesting). NOT the safety halt — that is bareguard's,
|
|
406
|
-
* and actual depth is always ≤ `limits.maxDepth`.
|
|
407
|
-
* @property {string} [persona] - (Gap 3 / 0.21.0) An optional caller stance PREPENDED to every Family-A worker's
|
|
408
|
-
* system prompt (e.g. "You are a senior security engineer; …"). It AUGMENTS the built-in decomposition policy +
|
|
409
|
-
* depth-scrub, never replaces them (that text drives the spawn mechanics), and CARRIES DOWN the whole tree
|
|
410
|
-
* (preserved by `forChild` — a durable worker stance, unlike the top-only `contract`/`evaluate`). Deliberately
|
|
411
|
-
* NOT applied to the isolated verifier (would defeat the anti-sycophancy isolation, A1) nor the deterministic
|
|
412
|
-
* scan judge. Absent/blank ⇒ the worker prompt is byte-identical to pre-0.21 (backward-compatible).
|
|
413
|
-
* **SECURITY:** this is a PRIVILEGED system-prompt seam — treat `persona` like a system prompt. Do NOT pass
|
|
414
|
-
* untrusted / end-user-controlled text here; a hostile persona is prepended ahead of the decomposition policy
|
|
415
|
-
* and can override it (and any safety framing) for every worker in the tree. Caller-trusted input only.
|
|
416
|
-
* @property {string} [context] - (BA-9 / relayfact F19) An optional caller-supplied READ-ONLY working-context
|
|
417
|
-
* blob (e.g. "project root: /abs/path\nfiles are relative to it") prepended to EVERY worker's task message as
|
|
418
|
-
* a `Working context:` block, so a sliced child can LOCATE its artifact — the concrete context (absolute
|
|
419
|
-
* paths / cwd) the Planner strips when it paraphrases the parent goal into child subtasks. CARRIES DOWN the
|
|
420
|
-
* tree (preserved by `forChild`, like `persona`) and, when forced fan-out plans, is forwarded as the Planner's
|
|
421
|
-
* `info` so the slices themselves are path-aware. Also shown to the verifier (neutral FACTS, not a stance, so
|
|
422
|
-
* no anti-sycophancy concern — and an agentic critic needs the path to exercise the artifact). Distinct from
|
|
423
|
-
* `persona`: persona is a privileged SYSTEM-prompt stance; context is run-state facts on the USER message.
|
|
424
|
-
* Absent/blank ⇒ byte-identical to pre-BA-9 (backward-compatible). Validated live (`poc/ba9-context-thread.mjs`:
|
|
425
|
-
* a weak model went 0/3 → 3/3 at locating an unguessable file once the root was threaded).
|
|
426
|
-
* **SECURITY:** this becomes part of every worker's prompt (and the verifier's) — lower-privilege than
|
|
427
|
-
* `persona` (the USER message, not the SYSTEM prompt) but still a prompt-injection surface. Intended for
|
|
428
|
-
* TRUSTED run-state (paths/cwd); do NOT pass untrusted / end-user-controlled text here.
|
|
429
|
-
* @property {ToolDef[]} [tools] - Handle tools offered to EVERY worker (RC-5 pull-default: litectx
|
|
430
|
-
* `recall`/`get`, wired at build step 7). Workers query on demand; never the whole corpus.
|
|
431
|
-
* @property {{sensor: (result: any, ctx: {task: string, context: string|undefined, contract: string|null}) => (Verdict|Promise<Verdict>), maxIterations?: number, temperatures?: number[], rejectedBuffer?: boolean}} [refineLeaf]
|
|
432
|
-
* (Opt-in, BA-8 / relayfact F17) Turn a DEFINITE LEAF (a node that is offered no `spawn_child` — `simple`
|
|
433
|
-
* tier or at `maxDepth`) into a bounded generate→sense→regenerate loop instead of a single pass, so a failed
|
|
434
|
-
* slice can self-correct. `sensor` is a DETERMINISTIC close (test/compile/lint — NOT a model judge, R-S8) that
|
|
435
|
-
* returns a `Verdict`; on a non-pass its `critique` (the GAP, not the transcript) is fed FRESH into the next
|
|
436
|
-
* attempt (D6/A1 anti-anchoring) and, on models that ACCEPT `temperature`, the **retry temperature ESCALATES**
|
|
437
|
-
* (`temperatures`, default `[0.2,0.7,1.0]`) — the live-validated lever that lets a weak model escape a
|
|
438
|
-
* repeat-the-same-mistake rut (`poc/ba8-leaf-refine.mjs`: 0/5 → 2-3/5; flat temp recovers 0/5). On a
|
|
439
|
-
* temperature-fixed model (BA-10) the provider drops the param, `receipts.refineLeaf.temperatures` records
|
|
440
|
-
* `null`, and the fed-back gap critique carries recovery alone — UNLESS the rejected-attempt buffer engages
|
|
441
|
-
* (below). `maxIterations` defaults to
|
|
442
|
-
* `temperatures.length`; the REAL bound is bareguard (each attempt is gate-checked + metered). CARRIES DOWN the
|
|
443
|
-
* tree (preserved by `forChild`), so it engages at the leaves of a Family-A decomposition. Recovery is PARTIAL
|
|
444
|
-
* (a stubborn blind spot may persist) — `receipts.refineLeaf.passed` reports honestly. Does NOT apply to a node
|
|
445
|
-
* that delegates (its children + the tree verify own quality), nor to the scan/fanout/partition dispatch paths.
|
|
446
|
-
* Absent ⇒ a leaf is a single pass (byte-identical to pre-BA-8). An error-keyed `recall` is the CALLER's tool
|
|
447
|
-
* (`opts.tools`) keyed off the fed-back critique — bareagent stays litectx-agnostic.
|
|
448
|
-
* **Sensor integrity (RSI-learnings #1/#5, "audit the close"):** the `sensor` MUST judge the RETURNED result
|
|
449
|
-
* (tamper-proof — e.g. build/run the returned string in an isolated context, as `poc/ba8-leaf-refine.mjs` does),
|
|
450
|
-
* NEVER a worker side-effect a worker with edit tools could GAME (writing a passing file then returning junk, or
|
|
451
|
-
* editing the failing test itself). A gameable close is the reward-hacking surface every RSI system in the field
|
|
452
|
-
* got bitten by; the loop optimizes against WHATEVER the sensor reads, so keep it outside what the worker can write.
|
|
453
|
-
* **Broken sensor ≠ failing model (BA-15):** a sensor that THROWS (non-Halt) or returns a MALFORMED verdict
|
|
454
|
-
* (anything but `{pass: boolean}` or a valid tri-state `status`) is a faulty ARBITER — the loop stops at the
|
|
455
|
-
* FIRST broken close (never retries against it) and returns a labeled `{incomplete, blocker:'broken-sensor'}`
|
|
456
|
-
* (+ `receipts.blockerDetail`), with `best` preserving the model's last attempt. A `HaltError` thrown by the
|
|
457
|
-
* sensor stays a clean governance halt. The sensor's EXECUTION environment is the caller's: run untrusted /
|
|
458
|
-
* model-generated checks in an isolated child process WITH A TIMEOUT — a sensor that hangs forever hangs the
|
|
459
|
-
* leaf (no bareguard checkpoint fires between sensor start and return; confirmed by `poc/rlmplans-hung-sensor.mjs`).
|
|
460
|
-
* **`rejectedBuffer` (BA-14):** a SkillOpt-shaped rejected-attempt buffer — instead of only the LATEST critique,
|
|
461
|
-
* surface the model's OWN prior failed attempts verbatim ("you wrote these, they failed X — write something
|
|
462
|
-
* STRUCTURALLY DIFFERENT"). This is DIRECTED diversity (attack the specific repeated mistake), where escalation
|
|
463
|
-
* is RANDOM diversity; the two are ANTAGONISTIC (`poc/ba14b-temp-with-buffer.mjs`: temperature monotonically
|
|
464
|
-
* degrades the buffer, 100%→70%→50% across 0.2/0.7/1.0), so when the buffer engages the retry temperature is
|
|
465
|
-
* HELD at `temperatures[0]` (flat-low), never escalated. `true` = force on (also on temperature-accepting
|
|
466
|
-
* models); `false` = force off (pure BA-8 escalation); UNSET = ADAPTIVE — engage only once a prior attempt's
|
|
467
|
-
* temperature was dropped (a temperature-fixed model, BA-10, where escalation is inert and the buffer is the
|
|
468
|
-
* sole lever — `poc/ba14-rejected-buffer.mjs`: flat-temp 50%→100%). `receipts.refineLeaf.rejectedBuffer`
|
|
469
|
-
* reports whether any iteration injected it. Bounded by `maxIterations` (the buffer never outgrows it).
|
|
470
|
-
* @property {string} [contract] - Definition of done (A3). When present, the verifier grades against THIS,
|
|
471
|
-
* not the loose task, and verification always runs.
|
|
472
|
-
* @property {(result: any, ctx: {contract: string|null, task: string}) => (Verdict|Promise<Verdict>)} [evaluate]
|
|
473
|
-
* Override the verifier (fills `recurse()`'s verify slot, §7.1). Default = an `Evaluator` rubric pass.
|
|
474
|
-
* @property {((args: {task: string, text: string|null, results: any[], children: object[], ctx: RecurseCtx}) => any) | 'concat' | 'merge'} [synthesize]
|
|
475
|
-
* Override synthesis/reduce (NB-3). A FUNCTION is a deterministic code-reduce over the child `results` — the
|
|
476
|
-
* §9.1 aggregation path (LLM arithmetic over partials carried ~10–15% error). A STRATEGY string runs the
|
|
477
|
-
* built-in reducer: `'concat'` (lossless no-LLM join) or `'merge'` (an isolated Loop-driven subjective
|
|
478
|
-
* merge); a string is ignored when no child ran. Default (unset) = the worker's own final text (Family A:
|
|
479
|
-
* the parent model already combined the children's results in its closing turn).
|
|
480
|
-
* @property {number} [count] - (Opt-in, NB-2 / Family B) FORCED fan-out: decompose into exactly this many
|
|
481
|
-
* independent parallel workers via `Planner`→`runPlan`, then reduce. A positive integer here is the count;
|
|
482
|
-
* it OVERRIDES the tier→count map. Setting it (or `mode:'fanout'`) takes the deterministic-parallelism path
|
|
483
|
-
* instead of the model-driven Family-A default. For known-parallel tasks where the caller wants guaranteed
|
|
484
|
-
* fan-out, not the model's adaptive choice.
|
|
485
|
-
* @property {'fanout'|'partition'} [mode] - (Opt-in, NB-2 / Family B) `'fanout'` = forced semantic fan-out
|
|
486
|
-
* WITHOUT a fixed count — derived from `assessComplexity`'s tier via the calibrated map (medium/complex/
|
|
487
|
-
* critical → 2/4/6; simple → 1); `opts.count` takes precedence. `'partition'` = the DATA-DRIVEN WIDTH path
|
|
488
|
-
* (§11): measure `opts.corpus` and partition it into `max(opts.count floor, ⌈size/workerBudget⌉)` parallel
|
|
489
|
-
* scan-workers (capped by the guards), CODE-reducing the per-chunk counts. Distinct from `'fanout'`: a data
|
|
490
|
-
* partition, not a `Planner` semantic split.
|
|
491
|
-
* @property {number} [workerBudget] - (`mode:'partition'`) items per worker; width = `⌈corpus.length /
|
|
492
|
-
* workerBudget⌉` (default 100). A calibratable knob (the §9.1 algorithm), not a discovered constant.
|
|
493
|
-
* @property {number} [concurrency] - (Family B) max workers run at once per wave (default 4). The wave
|
|
494
|
-
* structure is `runPlan`'s; bareguard still bounds the family rate independently.
|
|
495
|
-
* @property {'scan'|'search'|'exact'|'tools'} [retrieval] - (§10 step 7) the retrieval shape for a task OVER A
|
|
496
|
-
* CORPUS, routed by question shape (§9.2.1). `'scan'` (the default WHEN `opts.corpus` is present) = process
|
|
497
|
-
* every slice + LLM-judge + CODE-count — the only COMPLETE path (for "how many / all"). `'search'` = litectx
|
|
498
|
-
* `recall` handle tool offered to the worker (needle; CANNOT count; requires `ctx.litectx`). `'exact'` = a
|
|
499
|
-
* deterministic code-side AND-term filter tool over `opts.corpus`. `'tools'` = the PER-QUERY Family-A face:
|
|
500
|
-
* offer the worker `scan_count` (over `opts.corpus`) + `search_memory` (when `ctx.litectx`) + `exact_match`
|
|
501
|
-
* (array corpus) ALL AT ONCE, and let it pick the shape PER SUB-QUERY — the routing lives in the tool
|
|
502
|
-
* descriptions (scan says "use for how many / all / count"; search says "never count"), so a mixed task gets
|
|
503
|
-
* needle-search AND complete-count without per-sub-query adopter declaration. The completeness guard upgrades a
|
|
504
|
-
* `'search'` on a "how many / all" ask to `'scan'` (UPGRADE-only, never a silent downgrade); it does NOT fire
|
|
505
|
-
* for `'tools'` (the complete `scan_count` is always offered there, so a mixed task keeps its search tool).
|
|
506
|
-
* Absent `corpus` AND `retrieval`, behaviour is unchanged (Family A / single-shot) — fully backward-compatible.
|
|
507
|
-
* @property {Slice[] | (() => Promise<Slice[]>)} [corpus] - (§10 step 7) the generic slice-source scan/partition
|
|
508
|
-
* reads: an in-hand `{id, text}[]` array, OR an async `() => Promise<Slice[]>` (e.g. `litectxCorpus(litectx,
|
|
509
|
-
* {kind})` materializing a litectx-resident corpus via `enumerate`). recurse depends on this SHAPE, never on
|
|
510
|
-
* litectx. Malformed entries are dropped, never miscounted.
|
|
511
|
-
* @property {number} [window] - (scan) items per judge window. Default 8 (§9.2.1 recall knee — the one
|
|
512
|
-
* calibrated number; per-model).
|
|
513
|
-
* @property {number} [passes] - (scan) shuffled-boundary passes unioned for recall. Default 2 (~0.91 recall).
|
|
514
|
-
*/
|
|
515
|
-
/**
|
|
516
|
-
* @typedef {object} RecurseNode
|
|
517
|
-
* One audit/receipts node (RC-10) — the recursion tree reconstructs from these alone: parent→child lineage
|
|
518
|
-
* (`spawned`), each subgoal (`task`), each gap report (`verdict`), cost per node (`tokens`).
|
|
519
|
-
* @property {string} task
|
|
520
|
-
* @property {number} depth
|
|
521
|
-
* @property {{level: string, score: number}} complexity
|
|
522
|
-
* @property {boolean} critical
|
|
523
|
-
* @property {RecurseNode[]} spawned - Child nodes (lineage).
|
|
524
|
-
* @property {Verdict|null} verdict
|
|
525
|
-
* @property {boolean} incomplete
|
|
526
|
-
* @property {boolean} halted
|
|
527
|
-
* @property {string} [blocker] - Set when this node stopped for a specific non-model reason (mirrors
|
|
528
|
-
* `RecurseResult.blocker`): `'governance-deny'` (BA-11) — its Loop short-circuited a consecutive-policy-deny
|
|
529
|
-
* spin; `'broken-sensor'` (BA-15) — the caller's `refineLeaf.sensor` threw or returned a malformed verdict;
|
|
530
|
-
* `'broken-verifier'` (BA-15) — the caller's `opts.evaluate` did (the default Evaluator path is never labeled).
|
|
531
|
-
* @property {string} [blockerDetail] - (BA-15) with a `broken-*` blocker: what the arbiter did (threw with
|
|
532
|
-
* which message, or which malformed shape it returned) — the actionable half of the label.
|
|
533
|
-
* @property {{blocker: string, blockerDetail?: string, blockerTask?: string}} [blockerFrom] - (BA-15) a
|
|
534
|
-
* DESCENDANT's blocker, surfaced here so an aggregating node still reports the fault upward. Deliberately
|
|
535
|
-
* SEPARATE from this node's own `blocker` (which means "THIS node's arbiter/Loop broke"): stamping a
|
|
536
|
-
* descendant's label onto every ancestor made the receipts tree accuse nodes whose sensor never ran, and
|
|
537
|
-
* re-labelled a parent `governance-deny` when only one child was denied. `blockerTask` names the culprit.
|
|
538
|
-
* @property {object|null} tokens - The worker Loop's `metrics.tokens`.
|
|
539
|
-
* @property {{iterations: number, passed: boolean, temperatures: (number|null)[], rejectedBuffer: boolean}} [refineLeaf] - (BA-8) when
|
|
540
|
-
* this leaf ran as a bounded refine loop: how many attempts it took and whether the deterministic sensor finally
|
|
541
|
-
* passed (false = honest non-recovery, not a faked success). `temperatures` are the EFFECTIVE per-attempt temps
|
|
542
|
-
* (BA-10): a `null` marks an attempt the model ran at its DEFAULT because it rejected the requested temperature.
|
|
543
|
-
* `rejectedBuffer` (BA-14): whether any iteration injected the rejected-attempt buffer (prior failed attempts
|
|
544
|
-
* surfaced verbatim); when it engages the REQUESTED retry temperature is held flat at `temperatures[0]`, never
|
|
545
|
-
* escalated (ba14b antagonism) — but a temperature-fixed model still drops it, so the EFFECTIVE temp recorded
|
|
546
|
-
* above is `null`, not `temperatures[0]`.
|
|
547
|
-
* @property {string|null} model
|
|
548
|
-
* @property {string|null} [retrieval] - (§10 step 7) the retrieval mode this node ran (`scan`/`search`/`exact`),
|
|
549
|
-
* or null/absent for a plain reasoning node.
|
|
550
|
-
* @property {string} [retrievalUpgraded] - set when the completeness guard upgraded the mode (e.g.
|
|
551
|
-
* `'search→scan (completeness)'`) — the audit trail for RC-9-applied-to-retrieval.
|
|
552
|
-
* @property {{window: number, passes: number, scanned: number, matched: number}} [scan] - (scan) the scan
|
|
553
|
-
* shape: window/passes used, slices scanned, ids matched (CODE-counted).
|
|
554
|
-
* @property {{size: number, workerBudget: number, floor: number, dataWidth: number, width: number, matched?: number}} [partition]
|
|
555
|
-
* - (`mode:'partition'`) the data-driven width audit: corpus size, the budget knob, the count floor, the
|
|
556
|
-
* data-derived width `⌈size/budget⌉`, the chosen `width = max(floor, dataWidth)`, and matched count.
|
|
557
|
-
*/
|
|
558
|
-
/**
|
|
559
|
-
* @typedef {object} RecurseResult
|
|
560
|
-
* @property {any} [result] - The synthesized answer (on convergence).
|
|
561
|
-
* @property {Verdict|null} [verdict] - The verifier's gap report (null when verification did not run).
|
|
562
|
-
* @property {boolean} [incomplete] - true on guard exhaustion / a dead worker / an incomplete child (RC-9) —
|
|
563
|
-
* never a faked pass.
|
|
564
|
-
* @property {any} [best] - The best partial answer when `incomplete` (RC-9).
|
|
565
|
-
* @property {string[]} [missingSlices] - When `incomplete` because a child failed: the sub-task(s) that came
|
|
566
|
-
* back incomplete (§9 scenario 1) — the anti-survivor-sum signal, not a quiet undercount.
|
|
567
|
-
* @property {string} [blocker] - Present when `incomplete` for a specific, actionable reason. `'governance-deny'`
|
|
568
|
-
* (BA-11): the worker's Loop short-circuited after N consecutive policy denials rather than burn to the
|
|
569
|
-
* budget cap — the caller can widen scope / re-gate / escalate instead of reading it as a model failure.
|
|
570
|
-
* `'broken-sensor'` (BA-15): the caller's `refineLeaf.sensor` threw or returned a malformed verdict — the
|
|
571
|
-
* ARBITER is faulty, not the model; fix the sensor and re-run (`receipts.blockerDetail` says what it did).
|
|
572
|
-
* `'broken-verifier'` (BA-15): same fault class at the verify slot — the caller's `opts.evaluate` threw
|
|
573
|
-
* (non-Halt) or returned a malformed verdict; the default Evaluator path is never labeled (its failures are
|
|
574
|
-
* provider-class faults). For both `broken-*` blockers `best` preserves the model's last non-empty output
|
|
575
|
-
* (BA-5) — the arbiter broke, so treat it as best-effort work rather than a graded pass.
|
|
576
|
-
* @property {string} [blockerDetail] - (BA-15) with a `broken-*` blocker: what the arbiter did — the
|
|
577
|
-
* ACTIONABLE half of the label, surfaced on the result (not only in `receipts`) so a caller branching on
|
|
578
|
-
* `blocker` can report the cause without walking the receipts tree.
|
|
579
|
-
* @property {string} [blockerTask] - (BA-15) when the blocker was INHERITED from a descendant in a nested run:
|
|
580
|
-
* which sub-task actually broke. Without it a nested failure reports "a sensor broke" with no way to find
|
|
581
|
-
* which one.
|
|
582
|
-
* @property {RecurseNode} receipts - The audit node for this call (RC-10).
|
|
583
|
-
*/
|
|
584
211
|
/**
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
* ⚠️ RESOURCE BOUNDS ARE bareguard's, not recurse()'s — OPEN BY DESIGN (§6, "no second guard layer"), and the
|
|
589
|
-
* one thing to know before running it. `recurse()` adds NO intrinsic total-work cap. The **Family-A default**
|
|
590
|
-
* (model-driven `spawn_child`) lets a node spawn UP TO each Loop's `HARD_ROUND_LIMIT` (100) children PER LEVEL,
|
|
591
|
-
* each recursing to `opts.maxDepth` (default 3) — so node count, and therefore TOKEN + $ SPEND, compounds
|
|
592
|
-
* multiplicatively and is **not capped by recurse itself**. (The forced paths — `mode:'fanout'`/`'partition'` —
|
|
593
|
-
* ARE bounded: a deterministic `count` + a `concurrency` cap. The uncapped path is the model-driven default.)
|
|
594
|
-
* This is real, not theoretical: a live POC (`poc/rlm-defer2-history-overflow.mjs`) showed a weak model
|
|
595
|
-
* over-decomposing into 40–117 calls on a single run. **So: running WITHOUT bareguard — or without ANY
|
|
596
|
-
* token/cost cap — CAN BURN TOKENS / $ unboundedly (up to ~100×depth nodes).** **WIRE bareguard**
|
|
597
|
-
* (`ctx.policy` via `wireGate`) for any non-trivial or untrusted run — it enforces depth/budget/call caps and
|
|
598
|
-
* the pre-wave fan-out checkpoint, turning a runaway into a clean `{incomplete}`. With no gate available, the
|
|
599
|
-
* only local brakes are `opts.maxDepth: 1` (flat — no nesting) and the provider/key's own usage limits.
|
|
600
|
-
*
|
|
212
|
+
* Answer a task over an input held in an environment, with fixed tools, structural brakes and one honest tail.
|
|
213
|
+
* Input is never pasted into the prompt; the answer is a var of the declared `kind` (count derived by CODE).
|
|
601
214
|
* @param {string} task - The goal.
|
|
602
|
-
* @param {RecurseCtx} [ctx] -
|
|
603
|
-
* @param {RecurseOptions} [opts] - The
|
|
604
|
-
* @returns {Promise<RecurseResult>} `{
|
|
605
|
-
*
|
|
606
|
-
* @
|
|
607
|
-
* @
|
|
608
|
-
* @fails returns `{incomplete, best}` on guard exhaustion or a dead worker (never a faked pass); a gate HaltError exits clean. Cost is open by design — run under a budget gate.
|
|
215
|
+
* @param {RecurseCtx} [ctx] - Runtime wiring (provider, policy, onLlmResult, stream, depth).
|
|
216
|
+
* @param {RecurseOptions} [opts] - The knobs (`input`, `kind`, `limits`, ...).
|
|
217
|
+
* @returns {Promise<RecurseResult>} `{result, verdict, receipts, metrics}` or `{incomplete, best, blocker, receipts, metrics}`.
|
|
218
|
+
* @throws {Error} no task/provider; a removed v1 option; a bad `kind`/`limits`.
|
|
219
|
+
* @when a task is about data too big for one prompt (counts, needles, per-chunk questions) and you want it answered from an environment with hard call limits
|
|
220
|
+
* @fails returns `{incomplete, best, blocker}` on a brake, gate halt, dead slot, failed verify, wrong or missing final (never a faked pass); a v1 option throws.
|
|
609
221
|
* @example
|
|
610
|
-
* const
|
|
611
|
-
*
|
|
612
|
-
* if (incomplete) retryOrEscalate(result);
|
|
222
|
+
* const { result, incomplete } = await recurse('how many are about sports?', { provider }, { input: items, kind: 'count' });
|
|
223
|
+
* if (!incomplete) console.log(result.count);
|
|
613
224
|
*/
|
|
614
225
|
export function recurse(task: string, ctx?: RecurseCtx, opts?: RecurseOptions): Promise<RecurseResult>;
|