bare-agent 0.58.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 +32 -61
- package/index.d.ts +2 -5
- package/index.js +2 -5
- package/package.json +5 -1
- package/primitives.json +23 -14
- package/src/bareguard-adapter.js +2 -0
- 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/tools/shell.d.ts +31 -3
- package/tools/shell.js +142 -5
- package/src/recurse-synthesize.d.ts +0 -53
- package/src/recurse-synthesize.js +0 -106
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
export type Provider = import("../types").Provider;
|
|
2
|
+
export type ToolDef = import("../types").ToolDef;
|
|
3
|
+
export type Verdict = import("./evaluator").Verdict;
|
|
4
|
+
export type RecurseCtx = import("./recurse").RecurseCtx;
|
|
5
|
+
export type RecurseOptions = import("./recurse").RecurseOptions;
|
|
6
|
+
export type RecurseNode = import("./recurse").RecurseNode;
|
|
7
|
+
export type RecurseResult = import("./recurse").RecurseResult;
|
|
8
|
+
/**
|
|
9
|
+
* Run ONE worker as a bounded refine loop: each attempt is a fresh Loop at an escalating temperature, a
|
|
10
|
+
* deterministic caller `sensor` judges it, the GAP is fed forward, and a rejected-attempt buffer engages on a
|
|
11
|
+
* temperature-fixed model. Does exactly what `recurse(task, ctx, {maxDepth:0, refineLeaf, ...})` does and returns
|
|
12
|
+
* the SAME shape (`{result, verdict, receipts}` or `{incomplete, best, blocker?, receipts}`), incl.
|
|
13
|
+
* `receipts.refineLeaf`. Takes the same `opts` as `recurse` (`refineLeaf`, `persona`, `context`, `tools`,
|
|
14
|
+
* `contract`, `evaluate`; `maxDepth` is REJECTED with a ValidationError — a worker is always a leaf). Governance is the caller's gate (`ctx.policy`/`onLlmResult`).
|
|
15
|
+
* `opts.evaluate` (optional `(result, {contract, task}) => Verdict`) is supported: when set (as with a `contract` or
|
|
16
|
+
* a critical task) it runs AFTER the sensor loop and its verdict is the TOP verdict — it overrides the sensor's
|
|
17
|
+
* (a failing sensor verdict is replaced by the evaluate verdict; a throwing/garbage evaluate is `blocker:'broken-verifier'`).
|
|
18
|
+
* @when you want a model to produce an artifact that a deterministic check (test/compile/lint) must pass, retried with fed-back gaps — one worker, no decomposition
|
|
19
|
+
* @fails returns `{incomplete, best}` on non-recovery, halt, deny-spin (`blocker:'governance-deny'`) or a broken sensor (`blocker:'broken-sensor'`); throws on a missing task, provider or sensor
|
|
20
|
+
* @param {string} task
|
|
21
|
+
* @param {RecurseCtx} [ctx]
|
|
22
|
+
* @param {RecurseOptions} [opts]
|
|
23
|
+
* @returns {Promise<RecurseResult>}
|
|
24
|
+
* @example
|
|
25
|
+
* const out = await refineWorker('write add(a,b)', { provider }, { tools: [editTool], refineLeaf: { sensor } });
|
|
26
|
+
* if (out.incomplete) console.log(out.blocker, out.best);
|
|
27
|
+
*/
|
|
28
|
+
export function refineWorker(task: string, ctx?: RecurseCtx, opts?: RecurseOptions): Promise<RecurseResult>;
|
|
29
|
+
/** Internal opts key: `recurse` hands its already-resolved state (provider/system/tools/depth/node) to `refineWorker`. Not public. */
|
|
30
|
+
export const PRE: unique symbol;
|
|
31
|
+
/**
|
|
32
|
+
* The audit node every recurse/refineWorker call returns as `receipts` (RC-10). One factory so the two entry
|
|
33
|
+
* points cannot drift. `retrieval` stays null here; `recurse` assigns it once its routing resolves.
|
|
34
|
+
* @param {string} task
|
|
35
|
+
* @param {number} depth
|
|
36
|
+
* @param {{level: string, score: number}} assessment
|
|
37
|
+
* @param {boolean} critical
|
|
38
|
+
* @returns {RecurseNode}
|
|
39
|
+
*/
|
|
40
|
+
export function newNode(task: string, depth: number, assessment: {
|
|
41
|
+
level: string;
|
|
42
|
+
score: number;
|
|
43
|
+
}, critical: boolean): RecurseNode;
|
|
44
|
+
/**
|
|
45
|
+
* BA-9 (relayfact F19): prepend the caller's read-only working-context blob to a worker's task message, so a
|
|
46
|
+
* sliced child can LOCATE its artifact (absolute paths / cwd) — the concrete context the Planner otherwise
|
|
47
|
+
* strips when it paraphrases the parent goal into child subtasks. Distinct from `persona`: persona is a STANCE
|
|
48
|
+
* on the SYSTEM prompt (a privileged seam); context is neutral run-state FACTS on the USER message (the form
|
|
49
|
+
* the live POC `poc/ba9-context-thread.mjs` validated: no-context 0/3 → context 3/3 on a weak model). Absent/
|
|
50
|
+
* blank ⇒ the task message is byte-identical to pre-BA-9 (backward-compatible). Carries down the tree via
|
|
51
|
+
* `forChild` (a child of a worker rooted at `/proj` is still rooted at `/proj`), like `persona`.
|
|
52
|
+
* @param {string} task
|
|
53
|
+
* @param {unknown} context
|
|
54
|
+
* @returns {string}
|
|
55
|
+
*/
|
|
56
|
+
export function withContext(task: string, context: unknown): string;
|
|
57
|
+
/**
|
|
58
|
+
* The ctx handed to a worker `Loop.run({ ctx })` or to a direct `ctx.policy(...)` checkpoint — i.e. the ctx
|
|
59
|
+
* that a wired gate records VERBATIM into the audit as `action._ctx` (see `defaultActionTranslator` in
|
|
60
|
+
* src/bareguard-adapter.js). It STRIPS the live `provider` instance, because that object carries the API key
|
|
61
|
+
* (`provider.apiKey`) and bareguard serializes `_ctx` to disk — so an un-stripped ctx writes the raw
|
|
62
|
+
* `sk-…` key into the plaintext audit log (F16/BA-1, confirmed by relayfact probe-03).
|
|
63
|
+
*
|
|
64
|
+
* Only the AUDITED copy is cleaned: the provider still rides in the recurse-internal ctx that is threaded into
|
|
65
|
+
* each child `recurse()` self-call (children need `ctx.provider` to run), and the worker Loop already receives
|
|
66
|
+
* the provider as a constructor option — `Loop.run` never reads `ctx.provider`. The provider's IDENTITY is not
|
|
67
|
+
* lost from the audit either: the meter records the provider NAME on the `{type:'llm'}` action's args.
|
|
68
|
+
*
|
|
69
|
+
* NB: this strips the provider only — the leak that was grounded. A caller that threads its OWN secret-bearing
|
|
70
|
+
* fields onto ctx is backstopped by bareguard-side redaction (BG-1), the defense-in-depth pair to this fix.
|
|
71
|
+
* @param {RecurseCtx} ctx
|
|
72
|
+
* @param {object} [overrides] - extra fields to set on the audited copy (e.g. `{ depth }`).
|
|
73
|
+
* @returns {object}
|
|
74
|
+
*/
|
|
75
|
+
export function auditSafeCtx(ctx: RecurseCtx, overrides?: object): object;
|
|
76
|
+
/**
|
|
77
|
+
* The persona prefix for a worker system prompt (Gap 3 / 0.21.0). A caller-supplied `opts.persona` AUGMENTS the
|
|
78
|
+
* decomposition policy + scrub (never replaces them — that text drives the spawn mechanics). Returns '' when
|
|
79
|
+
* absent/blank, so the default worker prompt is byte-identical to pre-0.21 (backward-compatible). Validated live
|
|
80
|
+
* by `poc/rlm-persona-seam.mjs` (the worker still decomposes, adopts the persona, and carries it to children).
|
|
81
|
+
* @param {unknown} persona
|
|
82
|
+
* @returns {string}
|
|
83
|
+
*/
|
|
84
|
+
export function workerPersonaPrefix(persona: unknown): string;
|
|
85
|
+
/**
|
|
86
|
+
* BA-15 — run a caller arbiter (the `refineLeaf.sensor` or the `opts.evaluate` verifier) and NAME a broken one
|
|
87
|
+
* rather than let it launder. A non-`HaltError` throw or a malformed return (per {@link verdictShapeFault}) is
|
|
88
|
+
* re-thrown as a typed {@link BrokenArbiterError} the call sites classify by `instanceof` + `.tag` (NEVER by
|
|
89
|
+
* re-parsing the message text); a `HaltError` passes straight through (clean
|
|
90
|
+
* governance exit, BA-2). One helper so the sensor and verifier seams stay byte-identical (same guidance
|
|
91
|
+
* string, same fault taxonomy) — a divergence between them was the copy-paste risk this replaces.
|
|
92
|
+
* A verdict that carries a valid `status` but no boolean `pass` is NORMALIZED to add `pass = status ===
|
|
93
|
+
* 'satisfied'` (the same derivation as `evaluator.js`): the advertised `{status}` contract must actually
|
|
94
|
+
* WORK — `refine.js` stops the leaf on `verdict.pass`, so a bare `{status:'satisfied'}` would otherwise never
|
|
95
|
+
* satisfy, burn every iteration, and report `passed:false` (a satisfied close mislabeled as non-recovery).
|
|
96
|
+
* @template {{pass?: boolean, status?: string}} T
|
|
97
|
+
* @param {'broken-sensor'|'broken-verifier'} tag - the fault channel, carried on the thrown error's `.tag`.
|
|
98
|
+
* @param {() => (T | Promise<T>)} call - invokes the arbiter (already bound to its result/ctx args).
|
|
99
|
+
* @returns {Promise<T>} the arbiter's well-formed verdict (with `pass` derived from `status` when absent).
|
|
100
|
+
*/
|
|
101
|
+
export function runArbiter<T extends {
|
|
102
|
+
pass?: boolean;
|
|
103
|
+
status?: string;
|
|
104
|
+
}>(tag: "broken-sensor" | "broken-verifier", call: () => (T | Promise<T>)): Promise<T>;
|
|
105
|
+
/**
|
|
106
|
+
* BA-15 (verifier seam) — run the verify slot, converting a `BrokenArbiterError` into a LABELED
|
|
107
|
+
* `{ incomplete, blocker:'broken-verifier' }` return with `best` preserving the result the arbiter failed to
|
|
108
|
+
* judge (BA-5: the work exists — best-effort, not a graded pass). One helper so all five dispatch paths (worker /
|
|
109
|
+
* refineLeaf / scan / partition / fanout) get identical semantics. Anything else (HaltError, a default-
|
|
110
|
+
* Evaluator provider fault) rethrows to the caller's own catch, exactly as before.
|
|
111
|
+
*
|
|
112
|
+
* MUST be called as `return await verifyOrBlock(...)` from inside each caller's `try` — a bare
|
|
113
|
+
* `return verifyOrBlock(...)` returns the promise and exits the `try` before it settles, so a verifier
|
|
114
|
+
* `HaltError` would escape the caller's own catch instead of landing as a clean `{ incomplete, halted }`
|
|
115
|
+
* (proven by `poc/ba15-broken-sensor.mjs` [E4]).
|
|
116
|
+
* @param {string} task
|
|
117
|
+
* @param {any} result
|
|
118
|
+
* @param {RecurseCtx} ctx
|
|
119
|
+
* @param {RecurseOptions} opts
|
|
120
|
+
* @param {RecurseNode} node
|
|
121
|
+
* @returns {Promise<RecurseResult>}
|
|
122
|
+
*/
|
|
123
|
+
export function verifyOrBlock(task: string, result: any, ctx: RecurseCtx, opts: RecurseOptions, node: RecurseNode): Promise<RecurseResult>;
|
|
124
|
+
/**
|
|
125
|
+
* The verify slot (§7.1) — the Evaluator fills it by default. `opts.evaluate` overrides. The default path
|
|
126
|
+
* runs an isolated adversarial rubric grader (separate context window): when a `contract` is present it
|
|
127
|
+
* grades against THAT (A3); otherwise it grades full-and-correct against the goal — which is exactly the
|
|
128
|
+
* `critical → force verify` rail (a critical task with no contract still gets an independent grader).
|
|
129
|
+
* @param {string} task
|
|
130
|
+
* @param {any} result
|
|
131
|
+
* @param {RecurseCtx} ctx
|
|
132
|
+
* @param {RecurseOptions} opts
|
|
133
|
+
* @returns {Promise<Verdict>}
|
|
134
|
+
*/
|
|
135
|
+
export function verify(task: string, result: any, ctx: RecurseCtx, opts: RecurseOptions): Promise<Verdict>;
|
|
136
|
+
/**
|
|
137
|
+
* BA-15 — a TYPED signal that a caller arbiter (the `refineLeaf.sensor` or the `opts.evaluate` verifier)
|
|
138
|
+
* broke (threw non-Halt, or returned a malformed verdict). Classified by `instanceof` + `.tag`, NOT by
|
|
139
|
+
* re-parsing an `Error.message` prefix — so an intermediate layer that rewords the message (the exact class
|
|
140
|
+
* of the prior loop.js HaltError-wrapping bug) or a Loop/provider error whose text happens to begin
|
|
141
|
+
* `broken-sensor: ` can never be mis-labeled. Module-local: it is always thrown AND caught inside recurse.js
|
|
142
|
+
* (never propagates to a caller), so it needs no `errors.js` entry or public export.
|
|
143
|
+
*/
|
|
144
|
+
export class BrokenArbiterError extends Error {
|
|
145
|
+
/**
|
|
146
|
+
* @param {'broken-sensor'|'broken-verifier'} tag - which seam broke.
|
|
147
|
+
* @param {string} detail - what the arbiter did (surfaced as `receipts.blockerDetail`).
|
|
148
|
+
* @param {{cause?: any}} [options] - `cause` preserves the original error (stack/type) for debugging.
|
|
149
|
+
*/
|
|
150
|
+
constructor(tag: "broken-sensor" | "broken-verifier", detail: string, options?: {
|
|
151
|
+
cause?: any;
|
|
152
|
+
});
|
|
153
|
+
tag: "broken-sensor" | "broken-verifier";
|
|
154
|
+
detail: string;
|
|
155
|
+
}
|