@tangle-network/agent-runtime 0.114.0 → 0.115.1
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/dist/{activation-DlKl7-1o.js → activation-Bt_XVkjK.js} +2 -2
- package/dist/{activation-DlKl7-1o.js.map → activation-Bt_XVkjK.js.map} +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -2
- package/dist/{improvement-cycle-vLye8pYb.js → improvement-cycle-tEswzEPr.js} +3 -3
- package/dist/{improvement-cycle-vLye8pYb.js.map → improvement-cycle-tEswzEPr.js.map} +1 -1
- package/dist/{index-D-lNUfea.d.ts → index-BUWd8QJq.d.ts} +108 -2
- package/dist/{index-YpvLKzIX.d.ts → index-DZukewLl.d.ts} +2 -2
- package/dist/{index-BLf-SZ2b.d.ts → index-K7nucOmw.d.ts} +4 -4
- package/dist/index.d.ts +5 -5
- package/dist/index.js +9 -9
- package/dist/intelligence.js +3 -3
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +5 -5
- package/dist/{knowledge-BTsA9n6L.js → knowledge-CUXQE8Sq.js} +3 -3
- package/dist/{knowledge-BTsA9n6L.js.map → knowledge-CUXQE8Sq.js.map} +1 -1
- package/dist/knowledge.d.ts +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/{loop-runner-bin-Cg_8UKZR.d.ts → loop-runner-bin-BZl5vp7t.d.ts} +2 -2
- package/dist/{loop-runner-bin-CuBMmlMJ.js → loop-runner-bin-DzJz48Fb.js} +3 -3
- package/dist/{loop-runner-bin-CuBMmlMJ.js.map → loop-runner-bin-DzJz48Fb.js.map} +1 -1
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +2 -2
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +5 -5
- package/dist/{openai-tools-VAbzps5G.js → openai-tools-CynwZMZd.js} +2 -2
- package/dist/{openai-tools-VAbzps5G.js.map → openai-tools-CynwZMZd.js.map} +1 -1
- package/dist/{otel-export-D34IQW1C.js → otel-export-CPZTSADj.js} +16 -7
- package/dist/otel-export-CPZTSADj.js.map +1 -0
- package/dist/primeintellect/index.d.ts +1 -1
- package/dist/{runtime-DQ5seHEu.js → runtime-BatQajPB.js} +4 -4
- package/dist/{runtime-DQ5seHEu.js.map → runtime-BatQajPB.js.map} +1 -1
- package/dist/{structural-rollout-C7vF83fV.js → structural-rollout-DEf37yQy.js} +2 -2
- package/dist/{structural-rollout-C7vF83fV.js.map → structural-rollout-DEf37yQy.js.map} +1 -1
- package/dist/{supervise-tdxMJYem.js → supervise-B7TIJR3D.js} +336 -9
- package/dist/supervise-B7TIJR3D.js.map +1 -0
- package/dist/{supervisor-DKqolBGI.js → supervisor-DzQu5Ydu.js} +36 -9
- package/dist/supervisor-DzQu5Ydu.js.map +1 -0
- package/dist/testing.js +8 -8
- package/dist/{trace-propagation-CJJC7SVB.js → trace-propagation-B-pL7xn_.js} +2 -2
- package/dist/{trace-propagation-CJJC7SVB.js.map → trace-propagation-B-pL7xn_.js.map} +1 -1
- package/package.json +1 -1
- package/dist/otel-export-D34IQW1C.js.map +0 -1
- package/dist/supervise-tdxMJYem.js.map +0 -1
- package/dist/supervisor-DKqolBGI.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { c as RuntimeRunStateError, i as ConfigError, o as NotFoundError, t as AgentEvalError$1, u as ValidationError } from "./errors-DEAvWQPy.js";
|
|
2
2
|
import { a as mapWithConcurrency, c as sleep, d as throwIfAborted, f as withTimeout, l as stringifySafe, n as addTokenUsage, o as randomSuffix, p as zeroTokenUsage, r as deleteBoxSafe, s as randomUuid, t as abortError, u as throwAbort } from "./util-Cc9g9Y-o.js";
|
|
3
3
|
import { a as contentAddress, i as InMemorySpawnJournal, n as FileSpawnJournal, r as InMemoryResultBlobStore, t as FileResultBlobStore } from "./spawn-journal-DCPbicXB.js";
|
|
4
|
-
import { A as captureWorktreeDiff, C as routerChatWithUsage, E as runBrainLoop, M as removeWorktree, O as runWorktreeChecks, a as runFinalizer, i as pickBestDelivered, j as createWorktree, k as runWorktreeHarness, l as withDriverExecutor, n as bestDelivered, o as runTree, t as createSupervisor, x as routerBrain, y as createActivityLog } from "./supervisor-
|
|
5
|
-
import { i as notifyRuntimeHookEvent } from "./runtime-hooks-C7iJOWm3.js";
|
|
4
|
+
import { A as captureWorktreeDiff, C as routerChatWithUsage, E as runBrainLoop, M as removeWorktree, O as runWorktreeChecks, a as runFinalizer, i as pickBestDelivered, j as createWorktree, k as runWorktreeHarness, l as withDriverExecutor, n as bestDelivered, o as runTree, t as createSupervisor, x as routerBrain, y as createActivityLog } from "./supervisor-DzQu5Ydu.js";
|
|
5
|
+
import { i as notifyRuntimeHookEvent, t as composeRuntimeHooks } from "./runtime-hooks-C7iJOWm3.js";
|
|
6
6
|
import { a as notifySandboxEventObserver, n as extractLlmCallEvent } from "./sandbox-events-DeI5xX8P.js";
|
|
7
|
+
import { a as createOtelExporter, c as generateSpanId, r as buildLoopSpanNodes, u as toOtelAttributes } from "./otel-export-CPZTSADj.js";
|
|
7
8
|
import { i as resolveAgentEnvironmentProvider, n as providerAsExecutor, s as buildBackendOptions } from "./environment-provider-CCaEhA-l.js";
|
|
8
|
-
import { r as buildLoopSpanNodes } from "./otel-export-D34IQW1C.js";
|
|
9
9
|
import { t as createStdioToolServer } from "./tool-server-RcWgLIsL.js";
|
|
10
10
|
import { n as UI_LENSES } from "./substrate-B0TYNrXn.js";
|
|
11
11
|
import { argHash, computeFindingId, errorStreakDetector, estimateCost, isModelPriced, makeFinding, observeAll, repeatedActionDetector } from "@tangle-network/agent-eval";
|
|
@@ -94,6 +94,308 @@ function assertModelAllowed(model, allowed) {
|
|
|
94
94
|
if (!allowed.includes(model)) throw new ConfigError(`model ${JSON.stringify(model)} is not in the allowed set ${JSON.stringify([...allowed])}`);
|
|
95
95
|
}
|
|
96
96
|
//#endregion
|
|
97
|
+
//#region src/runtime/supervise/otel-spans.ts
|
|
98
|
+
/**
|
|
99
|
+
* Supervisor tree → OTLP spans. OPT-IN, off by default.
|
|
100
|
+
*
|
|
101
|
+
* WHY. A supervised tree is legible today only by parsing this package's own spawn journal, so
|
|
102
|
+
* every other multi-agent shape on the machine (a coding-CLI's subagents, a pi fanout, ad-hoc tool
|
|
103
|
+
* parallelism) needs its own bespoke reader. A span carrying `parent_span_id` IS a tree, and any
|
|
104
|
+
* system can emit one — so emitting spans makes the supervisor readable by the same viewer as
|
|
105
|
+
* everything else, with no per-system reader.
|
|
106
|
+
*
|
|
107
|
+
* WHAT IT IS NOT. This is telemetry, never the record of truth. The spawn journal remains the sole
|
|
108
|
+
* durable ledger for replay/resume and for cost; nothing here is read back, and a run whose export
|
|
109
|
+
* fails is unaffected in every observable way. The two data models are deliberately separate.
|
|
110
|
+
*
|
|
111
|
+
* HOW IT ATTACHES. This is a pure `RuntimeHooks` observer over the lifecycle events `Scope` ALREADY
|
|
112
|
+
* emits — `agent.spawn` (a node opened), `agent.child` (a node settled), `agent.turn` (a driver
|
|
113
|
+
* inference turn was metered). It adds no event, mutates no journal, and changes no result. Because
|
|
114
|
+
* `Scope` re-seeds the same hooks into every nested scope (`makeNestedScopeSeam`), one observer sees
|
|
115
|
+
* the WHOLE recursion at arbitrary depth.
|
|
116
|
+
*
|
|
117
|
+
* SPAN SHAPE. One span per supervised node, opened at spawn and closed at settle, parented to its
|
|
118
|
+
* parent node's span; the run root is the trace. Driver inference rides as an `LLM` child span under
|
|
119
|
+
* the node that metered it. Attributes reuse the vocabulary the rest of the stack already reads
|
|
120
|
+
* (`openinference.span.kind`, `agent.name`, `llm.token_count.*`, `llm.cost_usd`, `tangle.cost.usd`)
|
|
121
|
+
* — see `@tangle-network/agent-eval`'s `src/trace/attribute-vocabulary.ts`, which is the consumer.
|
|
122
|
+
*
|
|
123
|
+
* UNKNOWN IS NEVER ZERO. `Spend.tokensKnown === false` / `usdKnown === false` mark work that
|
|
124
|
+
* HAPPENED with an unreported count. Those spans OMIT the token/cost attribute entirely and set
|
|
125
|
+
* `tangle.supervise.tokens_known` / `tangle.supervise.cost_known` to `false`, so a reader can never
|
|
126
|
+
* mistake an unmeasured turn for a free one.
|
|
127
|
+
*/
|
|
128
|
+
/** OTEL status codes (`UNSET` / `OK` / `ERROR`) — the numeric wire values `OtelSpan.status` carries. */
|
|
129
|
+
const STATUS_UNSET = 0;
|
|
130
|
+
const STATUS_OK = 1;
|
|
131
|
+
const STATUS_ERROR = 2;
|
|
132
|
+
/** Longest string attribute value written from free-form detail, so an oversized turn payload
|
|
133
|
+
* cannot inflate a span. Identity/label attributes we control are never truncated. */
|
|
134
|
+
const MAX_DETAIL_CHARS = 256;
|
|
135
|
+
/**
|
|
136
|
+
* Build the span recorder for one supervised run, or `undefined` when no exporter resolves — the
|
|
137
|
+
* off-by-default path. A run that passes no `exporter` and no `exportConfig` never reaches this
|
|
138
|
+
* function at all; one that passes an `exportConfig` with no endpoint (and no env endpoint) gets
|
|
139
|
+
* `undefined` here, so "configured but unreachable" also costs nothing.
|
|
140
|
+
*/
|
|
141
|
+
function createSupervisorSpanRecorder(opts) {
|
|
142
|
+
const exporter = opts.exporter ?? createOtelExporter(opts.exportConfig);
|
|
143
|
+
if (!exporter) return void 0;
|
|
144
|
+
const ownsExporter = opts.exporter === void 0;
|
|
145
|
+
const now = opts.now ?? Date.now;
|
|
146
|
+
const traceId = normalizeTraceId(opts.traceId, opts.runId);
|
|
147
|
+
const rootSpanId = generateSpanId();
|
|
148
|
+
const rootStartMs = now();
|
|
149
|
+
const base = {
|
|
150
|
+
"tangle.run.id": opts.runId,
|
|
151
|
+
"tangle.sessionId": opts.runId,
|
|
152
|
+
...opts.attributes ?? {}
|
|
153
|
+
};
|
|
154
|
+
/** Node id → its open span. Seeded with the run id ⇒ the root span, because a depth-0 spawn's
|
|
155
|
+
* `parentId` is the run id itself and every deeper spawn's is a real node id. */
|
|
156
|
+
const open = /* @__PURE__ */ new Map();
|
|
157
|
+
const spanIdOf = /* @__PURE__ */ new Map([[opts.runId, rootSpanId]]);
|
|
158
|
+
let finished = false;
|
|
159
|
+
/** Every export is best-effort: a throwing exporter must never reach the run. */
|
|
160
|
+
const emit = (span) => {
|
|
161
|
+
try {
|
|
162
|
+
exporter.exportSpan(span);
|
|
163
|
+
} catch {}
|
|
164
|
+
};
|
|
165
|
+
const span = (spanId, parentSpanId, name, startMs, endMs, attrs, status, message) => ({
|
|
166
|
+
traceId,
|
|
167
|
+
spanId,
|
|
168
|
+
...parentSpanId ? { parentSpanId } : {},
|
|
169
|
+
name,
|
|
170
|
+
kind: 1,
|
|
171
|
+
startTimeUnixNano: msToNano(startMs),
|
|
172
|
+
endTimeUnixNano: msToNano(Math.max(startMs, endMs)),
|
|
173
|
+
attributes: toOtelAttributes(attrs),
|
|
174
|
+
status: {
|
|
175
|
+
code: status,
|
|
176
|
+
...message ? { message } : {}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
function onSpawn(event) {
|
|
180
|
+
const p = record(event.payload);
|
|
181
|
+
const childId = str$1(p.childId);
|
|
182
|
+
if (!childId) return;
|
|
183
|
+
const label = str$1(p.label) ?? "node";
|
|
184
|
+
const runtime = str$1(p.runtime);
|
|
185
|
+
const isWait = runtime === "wait";
|
|
186
|
+
const attrs = {
|
|
187
|
+
...base,
|
|
188
|
+
"openinference.span.kind": isWait ? "CHAIN" : "AGENT",
|
|
189
|
+
"agent.name": label,
|
|
190
|
+
"tangle.supervise.node.id": childId,
|
|
191
|
+
"tangle.supervise.node.label": label,
|
|
192
|
+
"tangle.supervise.node.kind": isWait ? "wait" : "agent",
|
|
193
|
+
"tangle.supervise.tree.root": event.runId
|
|
194
|
+
};
|
|
195
|
+
if (event.parentId) attrs["tangle.supervise.node.parent_id"] = event.parentId;
|
|
196
|
+
if (runtime) attrs["tangle.supervise.node.runtime"] = runtime;
|
|
197
|
+
if (typeof p.depth === "number") attrs["tangle.supervise.node.depth"] = p.depth;
|
|
198
|
+
if (typeof event.stepIndex === "number") attrs["tangle.supervise.node.ordinal"] = event.stepIndex;
|
|
199
|
+
if (p.resumed === true) attrs["tangle.supervise.node.resumed"] = true;
|
|
200
|
+
assignBudget(attrs, p.budget);
|
|
201
|
+
const spanId = generateSpanId();
|
|
202
|
+
spanIdOf.set(childId, spanId);
|
|
203
|
+
open.set(childId, {
|
|
204
|
+
spanId,
|
|
205
|
+
parentSpanId: event.parentId && spanIdOf.get(event.parentId) || rootSpanId,
|
|
206
|
+
name: label,
|
|
207
|
+
startMs: event.timestamp,
|
|
208
|
+
attrs
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function onSettled(event) {
|
|
212
|
+
const p = record(event.payload);
|
|
213
|
+
const childId = str$1(p.childId);
|
|
214
|
+
if (!childId) return;
|
|
215
|
+
const node = open.get(childId);
|
|
216
|
+
if (!node) return;
|
|
217
|
+
open.delete(childId);
|
|
218
|
+
const status = str$1(p.status);
|
|
219
|
+
const down = status === "down";
|
|
220
|
+
const attrs = {
|
|
221
|
+
...node.attrs,
|
|
222
|
+
"tangle.supervise.node.status": status ?? "done"
|
|
223
|
+
};
|
|
224
|
+
if (typeof event.stepIndex === "number") attrs["tangle.supervise.node.seq"] = event.stepIndex;
|
|
225
|
+
if (typeof p.outRef === "string") attrs["tangle.supervise.node.out_ref"] = p.outRef;
|
|
226
|
+
if (typeof p.valid === "boolean") attrs["tangle.supervise.verdict.valid"] = p.valid;
|
|
227
|
+
if (typeof p.score === "number") attrs["tangle.supervise.verdict.score"] = p.score;
|
|
228
|
+
if (down) {
|
|
229
|
+
attrs["error.type"] = p.infra === true ? "infra" : "child-down";
|
|
230
|
+
const reason = str$1(p.reason);
|
|
231
|
+
if (reason) attrs["error.message"] = truncate(reason);
|
|
232
|
+
if (typeof p.infra === "boolean") attrs["tangle.supervise.node.infra"] = p.infra;
|
|
233
|
+
}
|
|
234
|
+
const wokeBy = str$1(record(p.wait).settled);
|
|
235
|
+
if (wokeBy) attrs["tangle.supervise.wait.settled"] = wokeBy;
|
|
236
|
+
assignSpend(attrs, p.spent);
|
|
237
|
+
emit(span(node.spanId, node.parentSpanId, node.name, node.startMs, event.timestamp, attrs, down ? STATUS_ERROR : STATUS_OK, down ? str$1(p.reason) ?? "child down" : void 0));
|
|
238
|
+
}
|
|
239
|
+
function onTurn(event) {
|
|
240
|
+
const p = record(event.payload);
|
|
241
|
+
const parentId = event.parentId;
|
|
242
|
+
const parentSpanId = parentId && spanIdOf.get(parentId) || rootSpanId;
|
|
243
|
+
const attrs = {
|
|
244
|
+
...base,
|
|
245
|
+
"openinference.span.kind": "LLM",
|
|
246
|
+
"inference.observation_kind": "LLM",
|
|
247
|
+
"tangle.supervise.node.kind": "inference"
|
|
248
|
+
};
|
|
249
|
+
if (parentId) attrs["tangle.supervise.node.id"] = parentId;
|
|
250
|
+
for (const [key, value] of Object.entries(p)) {
|
|
251
|
+
if (key === "spend") continue;
|
|
252
|
+
if (key === "driver" && typeof value === "string") {
|
|
253
|
+
attrs["agent.name"] = value;
|
|
254
|
+
attrs["inference.agent_name"] = value;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (key === "model" && typeof value === "string") {
|
|
258
|
+
attrs["llm.model_name"] = value;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (Array.isArray(value)) {
|
|
262
|
+
const scalars = value.filter((v) => typeof v === "string" || typeof v === "number");
|
|
263
|
+
if (scalars.length > 0) attrs[`tangle.supervise.turn.${key}`] = truncate(scalars.join(","));
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (typeof value === "string") attrs[`tangle.supervise.turn.${key}`] = truncate(value);
|
|
267
|
+
else if (typeof value === "number" || typeof value === "boolean") attrs[`tangle.supervise.turn.${key}`] = value;
|
|
268
|
+
}
|
|
269
|
+
const spend = assignSpend(attrs, p.spend);
|
|
270
|
+
const endMs = event.timestamp + (spend?.ms ?? 0);
|
|
271
|
+
emit(span(generateSpanId(), parentSpanId, "gen_ai.client.inference", event.timestamp, endMs, attrs, STATUS_OK));
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
hooks: { onEvent(event) {
|
|
275
|
+
if (finished) return;
|
|
276
|
+
try {
|
|
277
|
+
if (event.phase !== "after") return;
|
|
278
|
+
if (event.target === "agent.spawn") onSpawn(event);
|
|
279
|
+
else if (event.target === "agent.child") onSettled(event);
|
|
280
|
+
else if (event.target === "agent.turn") onTurn(event);
|
|
281
|
+
} catch {}
|
|
282
|
+
} },
|
|
283
|
+
traceId,
|
|
284
|
+
rootSpanId,
|
|
285
|
+
async finish(outcome) {
|
|
286
|
+
if (finished) return;
|
|
287
|
+
finished = true;
|
|
288
|
+
const endMs = now();
|
|
289
|
+
try {
|
|
290
|
+
for (const [nodeId, node] of open) emit(span(node.spanId, node.parentSpanId, node.name, node.startMs, endMs, {
|
|
291
|
+
...node.attrs,
|
|
292
|
+
"tangle.supervise.node.status": "unsettled",
|
|
293
|
+
"tangle.supervise.node.settled": false,
|
|
294
|
+
"tangle.supervise.node.id": nodeId
|
|
295
|
+
}, STATUS_UNSET));
|
|
296
|
+
open.clear();
|
|
297
|
+
emit(span(rootSpanId, opts.parentSpanId, "supervisor.run", rootStartMs, endMs, rootAttrs(base, opts.agentName ?? "supervisor", outcome), rootStatus(outcome), rootMessage(outcome)));
|
|
298
|
+
await exporter.flush();
|
|
299
|
+
if (ownsExporter) await exporter.shutdown();
|
|
300
|
+
} catch {}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function rootAttrs(base, agentName, outcome) {
|
|
305
|
+
const attrs = {
|
|
306
|
+
...base,
|
|
307
|
+
"openinference.span.kind": "AGENT",
|
|
308
|
+
"inference.observation_kind": "AGENT",
|
|
309
|
+
"agent.name": agentName,
|
|
310
|
+
"inference.agent_name": agentName,
|
|
311
|
+
"tangle.supervise.node.kind": "root"
|
|
312
|
+
};
|
|
313
|
+
const result = outcome?.result;
|
|
314
|
+
if (result) {
|
|
315
|
+
attrs["tangle.supervise.result"] = result.kind;
|
|
316
|
+
if (result.kind === "no-winner") {
|
|
317
|
+
attrs["tangle.supervise.reason"] = result.reason;
|
|
318
|
+
attrs["tangle.supervise.down_count"] = result.downCount;
|
|
319
|
+
if (result.reason === "driver-failed") {
|
|
320
|
+
attrs["error.type"] = result.error.name;
|
|
321
|
+
attrs["error.message"] = truncate(result.error.message);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
assignSpend(attrs, result.spentTotal);
|
|
325
|
+
}
|
|
326
|
+
if (outcome?.error !== void 0) {
|
|
327
|
+
attrs["tangle.supervise.result"] = "error";
|
|
328
|
+
const err = outcome.error;
|
|
329
|
+
attrs["error.type"] = err instanceof Error ? err.name : typeof err;
|
|
330
|
+
attrs["error.message"] = truncate(err instanceof Error ? err.message : String(err));
|
|
331
|
+
}
|
|
332
|
+
return attrs;
|
|
333
|
+
}
|
|
334
|
+
function rootStatus(outcome) {
|
|
335
|
+
if (outcome?.error !== void 0) return STATUS_ERROR;
|
|
336
|
+
if (!outcome?.result) return STATUS_UNSET;
|
|
337
|
+
return outcome.result.kind === "winner" ? STATUS_OK : STATUS_ERROR;
|
|
338
|
+
}
|
|
339
|
+
function rootMessage(outcome) {
|
|
340
|
+
if (outcome?.error !== void 0) return truncate(outcome.error instanceof Error ? outcome.error.message : String(outcome.error));
|
|
341
|
+
const result = outcome?.result;
|
|
342
|
+
return result && result.kind === "no-winner" ? result.reason : void 0;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Write a `Spend` onto a span, honouring the "a missing measurement is never zero" invariant: a
|
|
346
|
+
* channel marked NOT known contributes no number at all and instead flags itself, so nothing
|
|
347
|
+
* downstream can sum an unmeasured turn as free. Returns the spend it read (for the duration).
|
|
348
|
+
*/
|
|
349
|
+
function assignSpend(attrs, value) {
|
|
350
|
+
if (!isRecord(value)) return void 0;
|
|
351
|
+
const spend = value;
|
|
352
|
+
const tokens = isRecord(spend.tokens) ? spend.tokens : void 0;
|
|
353
|
+
if (spend.tokensKnown === false) attrs["tangle.supervise.tokens_known"] = false;
|
|
354
|
+
else if (tokens) {
|
|
355
|
+
if (typeof tokens.input === "number") attrs["llm.token_count.prompt"] = tokens.input;
|
|
356
|
+
if (typeof tokens.output === "number") attrs["llm.token_count.completion"] = tokens.output;
|
|
357
|
+
}
|
|
358
|
+
if (spend.usdKnown === false) attrs["tangle.supervise.cost_known"] = false;
|
|
359
|
+
else if (typeof spend.usd === "number" && Number.isFinite(spend.usd)) {
|
|
360
|
+
attrs["llm.cost_usd"] = spend.usd;
|
|
361
|
+
attrs["tangle.cost.usd"] = spend.usd;
|
|
362
|
+
}
|
|
363
|
+
if (typeof spend.iterations === "number") attrs["tangle.supervise.iterations"] = spend.iterations;
|
|
364
|
+
if (typeof spend.ms === "number" && spend.ms > 0) attrs["tangle.supervise.duration_ms"] = spend.ms;
|
|
365
|
+
return spend;
|
|
366
|
+
}
|
|
367
|
+
function assignBudget(attrs, value) {
|
|
368
|
+
if (!isRecord(value)) return;
|
|
369
|
+
const budget = value;
|
|
370
|
+
if (typeof budget.maxTokens === "number") attrs["tangle.supervise.budget.max_tokens"] = budget.maxTokens;
|
|
371
|
+
if (typeof budget.maxIterations === "number") attrs["tangle.supervise.budget.max_iterations"] = budget.maxIterations;
|
|
372
|
+
if (typeof budget.maxUsd === "number") attrs["tangle.supervise.budget.max_usd"] = budget.maxUsd;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* A trace id must be 32 hex characters. A caller-supplied one is used verbatim when it already is;
|
|
376
|
+
* anything else (and the default) is DERIVED from the run id by content address — deterministic, so
|
|
377
|
+
* a resumed run rejoins the trace its first process opened rather than forking a new one.
|
|
378
|
+
*/
|
|
379
|
+
function normalizeTraceId(traceId, runId) {
|
|
380
|
+
if (traceId && /^[0-9a-f]{32}$/i.test(traceId)) return traceId.toLowerCase();
|
|
381
|
+
return contentAddress(traceId ?? runId).slice(7, 39);
|
|
382
|
+
}
|
|
383
|
+
function msToNano(ms) {
|
|
384
|
+
return (BigInt(Number.isFinite(ms) ? Math.floor(ms) : 0) * 1000000n).toString();
|
|
385
|
+
}
|
|
386
|
+
function isRecord(value) {
|
|
387
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
388
|
+
}
|
|
389
|
+
function record(value) {
|
|
390
|
+
return isRecord(value) ? value : {};
|
|
391
|
+
}
|
|
392
|
+
function str$1(value) {
|
|
393
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
394
|
+
}
|
|
395
|
+
function truncate(value) {
|
|
396
|
+
return value.length > MAX_DETAIL_CHARS ? `${value.slice(0, MAX_DETAIL_CHARS)}…` : value;
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
97
399
|
//#region src/runtime/supervise/coordination-log.ts
|
|
98
400
|
/** Should this bus event be persisted? Questions and findings ARE the prior context a resumed
|
|
99
401
|
* driver needs; answers fold their status; everything else has a better ledger or none. */
|
|
@@ -1405,6 +1707,13 @@ function publicConfigString(value, where) {
|
|
|
1405
1707
|
/**
|
|
1406
1708
|
* Build the canonical `{ mcpServers }` body the adapter reads, from `AgentProfile.mcp`.
|
|
1407
1709
|
*
|
|
1710
|
+
* Every server is written with `directTools: true` (`pi-mcp-adapter` types.ts:351), which
|
|
1711
|
+
* registers its tools as NATIVE pi tools instead of hiding them behind the generic `mcp` tool.
|
|
1712
|
+
* Without it an agent must discover its own verbs before it can use them — connect to the server,
|
|
1713
|
+
* then describe each tool — and a measured run spent 58 turns and 639,632 input tokens doing that
|
|
1714
|
+
* before it could delegate once. A profile that declares an MCP server is asking for its tools,
|
|
1715
|
+
* not for a directory it has to browse.
|
|
1716
|
+
*
|
|
1408
1717
|
* This is cli-bridge's `buildCanonicalMcpServers`
|
|
1409
1718
|
* (`/home/drew/code/cli-bridge/src/backends/profile-support.ts:253`) reproduced field for field and
|
|
1410
1719
|
* in the same key order — same drop of `enabled:false`, same stdio-versus-remote decision
|
|
@@ -1450,7 +1759,8 @@ function buildPiMcpServers(mcp) {
|
|
|
1450
1759
|
command,
|
|
1451
1760
|
...args.length > 0 ? { args } : {},
|
|
1452
1761
|
...Object.keys(env).length > 0 ? { env } : {},
|
|
1453
|
-
...typeof raw.cwd === "string" && raw.cwd.length > 0 ? { cwd: raw.cwd } : {}
|
|
1762
|
+
...typeof raw.cwd === "string" && raw.cwd.length > 0 ? { cwd: raw.cwd } : {},
|
|
1763
|
+
directTools: true
|
|
1454
1764
|
};
|
|
1455
1765
|
continue;
|
|
1456
1766
|
}
|
|
@@ -1459,7 +1769,8 @@ function buildPiMcpServers(mcp) {
|
|
|
1459
1769
|
out[name] = {
|
|
1460
1770
|
type: transport === "sse" ? "sse" : "http",
|
|
1461
1771
|
url,
|
|
1462
|
-
...Object.keys(headers).length > 0 ? { headers } : {}
|
|
1772
|
+
...Object.keys(headers).length > 0 ? { headers } : {},
|
|
1773
|
+
directTools: true
|
|
1463
1774
|
};
|
|
1464
1775
|
}
|
|
1465
1776
|
}
|
|
@@ -8357,7 +8668,13 @@ function supervise(profile, task, opts) {
|
|
|
8357
8668
|
...opts.maxTurns !== void 0 ? { maxTurns: opts.maxTurns } : {},
|
|
8358
8669
|
...opts.compaction ? { compaction: opts.compaction } : {}
|
|
8359
8670
|
});
|
|
8360
|
-
|
|
8671
|
+
const spans = opts.otel ? createSupervisorSpanRecorder({
|
|
8672
|
+
runId,
|
|
8673
|
+
...opts.otel,
|
|
8674
|
+
now
|
|
8675
|
+
}) : void 0;
|
|
8676
|
+
const hooks = spans ? composeRuntimeHooks(opts.hooks, spans.hooks) : opts.hooks;
|
|
8677
|
+
const run = createSupervisor().run(agent, task, {
|
|
8361
8678
|
budget: opts.budget,
|
|
8362
8679
|
runId,
|
|
8363
8680
|
journal: opts.journal ?? ctx.journal,
|
|
@@ -8366,12 +8683,22 @@ function supervise(profile, task, opts) {
|
|
|
8366
8683
|
maxDepth: opts.maxDepth ?? 8,
|
|
8367
8684
|
...probes ? { probes } : {},
|
|
8368
8685
|
...ctx.resume === true ? { resume: true } : {},
|
|
8369
|
-
...opts.now ? { now: opts.now } : {}
|
|
8686
|
+
...opts.now ? { now: opts.now } : {},
|
|
8687
|
+
...hooks ? { hooks } : {}
|
|
8370
8688
|
});
|
|
8689
|
+
if (!spans) return run;
|
|
8690
|
+
try {
|
|
8691
|
+
const result = await run;
|
|
8692
|
+
await spans.finish({ result });
|
|
8693
|
+
return result;
|
|
8694
|
+
} catch (error) {
|
|
8695
|
+
await spans.finish({ error });
|
|
8696
|
+
throw error;
|
|
8697
|
+
}
|
|
8371
8698
|
};
|
|
8372
8699
|
return start();
|
|
8373
8700
|
}
|
|
8374
8701
|
//#endregion
|
|
8375
|
-
export { InMemoryDelegationStore as $, FileCoordinationLog as $t, DELEGATE_INPUT_SCHEMA as A, createWorktreeCliExecutor as At, profileRichnessFinding as B, PI_MCP_ADAPTER_ENV as Bt, validateDelegateUiAuditArgs as C, defaultToolDetectors as Ct, createDelegateFeedbackHandler as D, cliWorktreeExecutor as Dt, DELEGATE_FEEDBACK_TOOL_NAME as E, createInMemoryRunContext as Et, delegate as F, piSeamKey as Ft, DELEGATION_TRACE_MAX_SPANS as G, createInbox as Gt, DelegationTaskQueue as H, buildPiMcpServers as Ht, asAuthoredProfile as I, createPushTraceSource as It, composeLoopTraceEmitters as J, runAgentRounds as Jt, buildDelegationTraceSpans as K, createSandboxForSpec as Kt, assessAuthoredProfile as L, decodeToolPart as Lt, createDelegateHandler as M, createSteerableSandboxSession as Mt, validateDelegateArgs as N, PI_RUNTIME as Nt, validateDelegateFeedbackArgs as O, createExecutor as Ot, defaultDelegateBudget as P, piExecutor as Pt, FileDelegationStore as Q, acquireSandbox as Qt, authoredWorker as R, sandboxSessionTraceSource as Rt, createDelegateUiAuditHandler as S, rollingDispatch as St, DELEGATE_FEEDBACK_INPUT_SCHEMA as T, createFileRunContext as Tt, hashIdempotencyInput as U, piMcpAdapterAvailable as Ut, supervisorInstructions as V, PI_MCP_CONFIG_FLAG as Vt, DELEGATION_TRACE_MAX_BYTES as W, preparePiMcp as Wt, DelegationPersistenceError as X, createSandboxLineage as Xt, createDelegationTraceCollector as Y, runLoop as Yt, DelegationStateCorruptError as Z, probeSandboxCapabilities as Zt, createDelegationHistoryHandler as _, createCoordinationTools as _t, supervisorAgent as a, allWorkersStalled as at, DELEGATE_UI_AUDIT_INPUT_SCHEMA as b, freeSlots as bt, createMcpServer as c, noProgressFor as ct, DELEGATION_STATUS_TOOL_NAME as d, anytimeReport as dt,
|
|
8702
|
+
export { InMemoryDelegationStore as $, FileCoordinationLog as $t, DELEGATE_INPUT_SCHEMA as A, createWorktreeCliExecutor as At, profileRichnessFinding as B, PI_MCP_ADAPTER_ENV as Bt, validateDelegateUiAuditArgs as C, defaultToolDetectors as Ct, createDelegateFeedbackHandler as D, cliWorktreeExecutor as Dt, DELEGATE_FEEDBACK_TOOL_NAME as E, createInMemoryRunContext as Et, delegate as F, piSeamKey as Ft, DELEGATION_TRACE_MAX_SPANS as G, createInbox as Gt, DelegationTaskQueue as H, buildPiMcpServers as Ht, asAuthoredProfile as I, createPushTraceSource as It, composeLoopTraceEmitters as J, runAgentRounds as Jt, buildDelegationTraceSpans as K, createSandboxForSpec as Kt, assessAuthoredProfile as L, decodeToolPart as Lt, createDelegateHandler as M, createSteerableSandboxSession as Mt, validateDelegateArgs as N, PI_RUNTIME as Nt, validateDelegateFeedbackArgs as O, createExecutor as Ot, defaultDelegateBudget as P, piExecutor as Pt, FileDelegationStore as Q, acquireSandbox as Qt, authoredWorker as R, sandboxSessionTraceSource as Rt, createDelegateUiAuditHandler as S, rollingDispatch as St, DELEGATE_FEEDBACK_INPUT_SCHEMA as T, createFileRunContext as Tt, hashIdempotencyInput as U, piMcpAdapterAvailable as Ut, supervisorInstructions as V, PI_MCP_CONFIG_FLAG as Vt, DELEGATION_TRACE_MAX_BYTES as W, preparePiMcp as Wt, DelegationPersistenceError as X, createSandboxLineage as Xt, createDelegationTraceCollector as Y, runLoop as Yt, DelegationStateCorruptError as Z, probeSandboxCapabilities as Zt, createDelegationHistoryHandler as _, createCoordinationTools as _t, supervisorAgent as a, allWorkersStalled as at, DELEGATE_UI_AUDIT_INPUT_SCHEMA as b, freeSlots as bt, createMcpServer as c, noProgressFor as ct, DELEGATION_STATUS_TOOL_NAME as d, anytimeReport as dt, createSupervisorSpanRecorder as en, InMemoryFeedbackStore as et, createDelegationStatusHandler as f, areaUnderCurve as ft, DELEGATION_HISTORY_TOOL_NAME as g, DEFAULT_AWAIT_EVENT_TIMEOUT_MS as gt, DELEGATION_HISTORY_INPUT_SCHEMA as h, renderAnytimeTable as ht, resolveSupervisorProfile as i, allOf as it, DELEGATE_TOOL_NAME as j, DEFAULT_SANDBOX_STEERING_MAX_TURNS as jt, DELEGATE_DESCRIPTION as k, createExecutorRegistry as kt, DELEGATION_STATUS_DESCRIPTION as l, plateau as lt, DELEGATION_HISTORY_DESCRIPTION as m, plateauLength as mt, workerFromBackend as n, gateOnDeliverable as nn, driverAgent as nt, serveCoordinationMcp as o, anyOf as ot, validateDelegationStatusArgs as p, bestSoFar as pt, capDelegationTrace as q, defaultSelectWinner as qt, assertCoordinationBinding as r, finalizeBestDelivered as rt, createInProcessTransport as s, createProgressTracker as st, supervise as t, assertModelAllowed as tn, eventToSnapshot as tt, DELEGATION_STATUS_INPUT_SCHEMA as u, sampleFromSettled as ut, validateDelegationHistoryArgs as v, createEventBus as vt, DELEGATE_FEEDBACK_DESCRIPTION as w, watchTrace as wt, DELEGATE_UI_AUDIT_TOOL_NAME as x, queueOf as xt, DELEGATE_UI_AUDIT_DESCRIPTION as y, effectiveConcurrency as yt, defaultProfileRichnessThresholds as z, PI_MCP_ADAPTER as zt };
|
|
8376
8703
|
|
|
8377
|
-
//# sourceMappingURL=supervise-
|
|
8704
|
+
//# sourceMappingURL=supervise-B7TIJR3D.js.map
|