@tangle-network/agent-runtime 0.102.1 → 0.103.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 +73 -10
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +5 -5
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/candidate-execution/index.d.ts +5 -41
- package/dist/candidate-execution/index.js +8 -6
- package/dist/{chunk-KPHTCHQ4.js → chunk-3LJF5XSE.js} +79 -334
- package/dist/chunk-3LJF5XSE.js.map +1 -0
- package/dist/{chunk-3DW5DEKQ.js → chunk-5AITUUHO.js} +3 -3
- package/dist/{chunk-SQ3ZJH3Y.js → chunk-6WZZXQV5.js} +467 -23
- package/dist/chunk-6WZZXQV5.js.map +1 -0
- package/dist/{chunk-RTB3TC73.js → chunk-AAN2MB2X.js} +3 -3
- package/dist/{chunk-KSM6GFHP.js → chunk-B7K7V22Y.js} +2 -2
- package/dist/{chunk-6MR4IJRW.js → chunk-EAQ5YRRY.js} +1383 -63
- package/dist/chunk-EAQ5YRRY.js.map +1 -0
- package/dist/chunk-ISPWRSEC.js +408 -0
- package/dist/chunk-ISPWRSEC.js.map +1 -0
- package/dist/{chunk-7FJJUC73.js → chunk-LFM4JBRW.js} +29 -6
- package/dist/{chunk-7FJJUC73.js.map → chunk-LFM4JBRW.js.map} +1 -1
- package/dist/{chunk-ROILMKDL.js → chunk-QYCKIV6C.js} +3 -3
- package/dist/{chunk-LJLG734E.js → chunk-SBTWKPVR.js} +10 -11
- package/dist/{chunk-LJLG734E.js.map → chunk-SBTWKPVR.js.map} +1 -1
- package/dist/{chunk-CK76OZPM.js → chunk-SNSMRT6H.js} +56 -386
- package/dist/chunk-SNSMRT6H.js.map +1 -0
- package/dist/{chunk-KJ2Q4T7F.js → chunk-TUSOOIDV.js} +2 -2
- package/dist/{chunk-CI7WS6S2.js → chunk-ZOYN3JR5.js} +5 -5
- package/dist/{chunk-377GOJHJ.js → chunk-ZXICDSAK.js} +333 -4
- package/dist/chunk-ZXICDSAK.js.map +1 -0
- package/dist/{completion-gate-C6dhVN-N.d.ts → completion-gate-DLINnrkM.d.ts} +1 -1
- package/dist/{coordination-D9l_YmwW.d.ts → coordination-DTehA977.d.ts} +250 -8
- package/dist/environment-provider.d.ts +2 -2
- package/dist/index.d.ts +12 -12
- package/dist/index.js +17 -15
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +26 -8
- package/dist/intelligence.js +24 -7
- package/dist/intelligence.js.map +1 -1
- package/dist/knowledge.d.ts +6 -6
- package/dist/knowledge.js +9 -9
- package/dist/{loop-runner-bin-PnWslIw4.d.ts → loop-runner-bin-DhIXsLAd.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +5 -5
- package/dist/loop-runner-bin.js +6 -6
- package/dist/loops.d.ts +305 -148
- package/dist/loops.js +82 -14
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +6 -6
- package/dist/mcp/index.js +6 -6
- package/dist/profiles.d.ts +1 -1
- package/dist/{profile-DbfaMTdk.d.ts → protected-model-port-DzkUY3HQ.d.ts} +41 -3
- package/dist/{structural-rollout-D7xik9XR.d.ts → structural-rollout-BFPIy3iw.d.ts} +3 -3
- package/dist/supervise-Cp8bNcJi.d.ts +379 -0
- package/dist/testing.js +10 -10
- package/dist/testing.js.map +1 -1
- package/dist/{types-CWqfCO8s.d.ts → types-Cbp72qyu.d.ts} +1 -1
- package/dist/{types-CLat4bT9.d.ts → types-DK11_O4L.d.ts} +1 -1
- package/dist/types-lZTE_LBd.d.ts +957 -0
- package/dist/{worktree-fanout-DsIR4d6w.d.ts → worktree-fanout-DiiJWjJO.d.ts} +17 -5
- package/package.json +3 -2
- package/skills/build-with-agent-runtime/SKILL.md +7 -5
- package/skills/generate-eval/SKILL.md +45 -52
- package/skills/loop-writer/SKILL.md +79 -147
- package/skills/supervise/SKILL.md +33 -14
- package/dist/chunk-377GOJHJ.js.map +0 -1
- package/dist/chunk-6MR4IJRW.js.map +0 -1
- package/dist/chunk-CK76OZPM.js.map +0 -1
- package/dist/chunk-IMSNJSXH.js +0 -73
- package/dist/chunk-IMSNJSXH.js.map +0 -1
- package/dist/chunk-KPHTCHQ4.js.map +0 -1
- package/dist/chunk-SQ3ZJH3Y.js.map +0 -1
- package/dist/supervise-BQdNAXtK.d.ts +0 -131
- package/dist/types-D870JlH0.d.ts +0 -500
- /package/dist/{chunk-3DW5DEKQ.js.map → chunk-5AITUUHO.js.map} +0 -0
- /package/dist/{chunk-RTB3TC73.js.map → chunk-AAN2MB2X.js.map} +0 -0
- /package/dist/{chunk-KSM6GFHP.js.map → chunk-B7K7V22Y.js.map} +0 -0
- /package/dist/{chunk-ROILMKDL.js.map → chunk-QYCKIV6C.js.map} +0 -0
- /package/dist/{chunk-KJ2Q4T7F.js.map → chunk-TUSOOIDV.js.map} +0 -0
- /package/dist/{chunk-CI7WS6S2.js.map → chunk-ZOYN3JR5.js.map} +0 -0
|
@@ -11,9 +11,10 @@ import {
|
|
|
11
11
|
defaultSelectWinner,
|
|
12
12
|
gateOnDeliverable,
|
|
13
13
|
probeSandboxCapabilities,
|
|
14
|
+
rollingDispatch,
|
|
14
15
|
runLoop,
|
|
15
16
|
supervise
|
|
16
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-EAQ5YRRY.js";
|
|
17
18
|
import {
|
|
18
19
|
observe,
|
|
19
20
|
refine,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
sample,
|
|
22
23
|
sampleThenRefine,
|
|
23
24
|
strategyAuthorMethod
|
|
24
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-QYCKIV6C.js";
|
|
25
26
|
import {
|
|
26
27
|
redactProtectedReason,
|
|
27
28
|
redactProtectedValue
|
|
@@ -33,11 +34,11 @@ import {
|
|
|
33
34
|
runBrainLoop,
|
|
34
35
|
settledToIteration,
|
|
35
36
|
withDriverExecutor
|
|
36
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-6WZZXQV5.js";
|
|
37
38
|
import {
|
|
38
39
|
InMemoryResultBlobStore,
|
|
39
40
|
InMemorySpawnJournal
|
|
40
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-ISPWRSEC.js";
|
|
41
42
|
import {
|
|
42
43
|
addTokenUsage,
|
|
43
44
|
isAbortError,
|
|
@@ -61,103 +62,6 @@ import {
|
|
|
61
62
|
// src/runtime/index.ts
|
|
62
63
|
import { computeFindingId, makeFinding } from "@tangle-network/agent-eval";
|
|
63
64
|
|
|
64
|
-
// src/runtime/anytime.ts
|
|
65
|
-
var median = (xs) => {
|
|
66
|
-
if (xs.length === 0) return null;
|
|
67
|
-
const s = [...xs].sort((a, b) => a - b);
|
|
68
|
-
const mid = Math.floor(s.length / 2);
|
|
69
|
-
return s.length % 2 === 1 ? s[mid] : (s[mid - 1] + s[mid]) / 2;
|
|
70
|
-
};
|
|
71
|
-
function anytimeReport(spans, opts) {
|
|
72
|
-
const targets = opts?.targets ?? [1];
|
|
73
|
-
const byRun = /* @__PURE__ */ new Map();
|
|
74
|
-
for (const s of spans) {
|
|
75
|
-
if (!s.label.startsWith("shot:")) continue;
|
|
76
|
-
const list = byRun.get(s.runId) ?? [];
|
|
77
|
-
list.push(s);
|
|
78
|
-
byRun.set(s.runId, list);
|
|
79
|
-
}
|
|
80
|
-
const perTask = [];
|
|
81
|
-
for (const [runId, shots] of byRun) {
|
|
82
|
-
const m = runId.match(/^agentic:(.+):(.+)$/);
|
|
83
|
-
const strategy = m?.[1] ?? runId;
|
|
84
|
-
const taskId = m?.[2] ?? runId;
|
|
85
|
-
const ordered = [...shots].sort((a, b) => (a.endMs ?? a.startMs) - (b.endMs ?? b.startMs));
|
|
86
|
-
const t0 = Math.min(...ordered.map((s) => s.startMs));
|
|
87
|
-
const taskTargets = opts?.targetFor ? [opts.targetFor(taskId)] : targets;
|
|
88
|
-
let best = 0;
|
|
89
|
-
let cumUsd = 0;
|
|
90
|
-
const points = [];
|
|
91
|
-
const hits = {};
|
|
92
|
-
for (const t of taskTargets) hits[String(t)] = null;
|
|
93
|
-
for (const s of ordered) {
|
|
94
|
-
cumUsd += s.usd;
|
|
95
|
-
if (typeof s.score === "number" && s.score > best) best = s.score;
|
|
96
|
-
const elapsedMs = (s.endMs ?? s.startMs) - t0;
|
|
97
|
-
points.push({ elapsedMs, cumUsd, best });
|
|
98
|
-
for (const t of taskTargets) {
|
|
99
|
-
if (hits[String(t)] === null && best >= t) {
|
|
100
|
-
hits[String(t)] = { ms: elapsedMs, shots: points.length, usd: cumUsd };
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
perTask.push({ taskId, strategy, points, hits });
|
|
105
|
-
}
|
|
106
|
-
const byStrategy = /* @__PURE__ */ new Map();
|
|
107
|
-
for (const t of perTask) {
|
|
108
|
-
const list = byStrategy.get(t.strategy) ?? [];
|
|
109
|
-
list.push(t);
|
|
110
|
-
byStrategy.set(t.strategy, list);
|
|
111
|
-
}
|
|
112
|
-
const perStrategy = [];
|
|
113
|
-
for (const [strategy, tasks] of byStrategy) {
|
|
114
|
-
const totalMs = tasks.reduce((s, t) => s + (t.points[t.points.length - 1]?.elapsedMs ?? 0), 0);
|
|
115
|
-
const totalUsd = tasks.reduce((s, t) => s + (t.points[t.points.length - 1]?.cumUsd ?? 0), 0);
|
|
116
|
-
const maxShots = Math.max(0, ...tasks.map((t) => t.points.length));
|
|
117
|
-
const curveByShot = [];
|
|
118
|
-
for (let i = 0; i < maxShots; i += 1) {
|
|
119
|
-
const vals = tasks.map(
|
|
120
|
-
(t) => t.points[Math.min(i, t.points.length - 1)].best
|
|
121
|
-
);
|
|
122
|
-
curveByShot.push(vals.reduce((s, v) => s + v, 0) / vals.length);
|
|
123
|
-
}
|
|
124
|
-
const auc = curveByShot.length > 0 ? curveByShot.reduce((s, v) => s + v, 0) / curveByShot.length : 0;
|
|
125
|
-
const summaryTargets = opts?.targetFor ? [Number.NaN] : targets;
|
|
126
|
-
for (const t of summaryTargets) {
|
|
127
|
-
const key = (taskCurve) => opts?.targetFor ? Object.values(taskCurve.hits)[0] ?? null : taskCurve.hits[String(t)] ?? null;
|
|
128
|
-
const reached = tasks.filter((x) => key(x) !== null);
|
|
129
|
-
perStrategy.push({
|
|
130
|
-
strategy,
|
|
131
|
-
target: t,
|
|
132
|
-
tasks: tasks.length,
|
|
133
|
-
reachedTarget: reached.length,
|
|
134
|
-
medianTttMs: median(reached.map((x) => key(x).ms)),
|
|
135
|
-
medianShotsToTarget: median(reached.map((x) => key(x).shots)),
|
|
136
|
-
ertMs: reached.length > 0 ? totalMs / reached.length : null,
|
|
137
|
-
erUsd: reached.length > 0 ? totalUsd / reached.length : null,
|
|
138
|
-
curveByShot,
|
|
139
|
-
auc
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
perStrategy.sort((a, b) => a.strategy.localeCompare(b.strategy) || a.target - b.target);
|
|
144
|
-
return { targets, perTask, perStrategy };
|
|
145
|
-
}
|
|
146
|
-
function renderAnytimeTable(report) {
|
|
147
|
-
const lines = [
|
|
148
|
-
`anytime metrics \xB7 satisficing targets [${report.targets.join(", ")}] \xB7 ERT = \u03A3 all wall-time / #successes (COCO)`,
|
|
149
|
-
"strategy \u2265tgt reach med-TTT med-shots ERT(all-in) $/success AUC curve"
|
|
150
|
-
];
|
|
151
|
-
for (const s of report.perStrategy) {
|
|
152
|
-
const curve = s.curveByShot.map((v) => "\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588"[Math.min(7, Math.floor(v * 8))]).join("");
|
|
153
|
-
const tgt = Number.isNaN(s.target) ? "task" : s.target.toFixed(2);
|
|
154
|
-
lines.push(
|
|
155
|
-
`${s.strategy.padEnd(19)} ${tgt.padStart(4)} ${String(s.reachedTarget).padStart(4)}/${String(s.tasks).padEnd(3)} ${s.medianTttMs === null ? " \u2014" : `${(s.medianTttMs / 1e3).toFixed(1).padStart(6)}s`} ${s.medianShotsToTarget === null ? " \u2014" : String(s.medianShotsToTarget).padStart(5)} ${s.ertMs === null ? " \u2014" : `${(s.ertMs / 1e3).toFixed(1).padStart(9)}s`} ${s.erUsd === null ? " \u2014" : `$${s.erUsd.toFixed(4)}`} ${s.auc.toFixed(2)} ${curve}`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
return lines.join("\n");
|
|
159
|
-
}
|
|
160
|
-
|
|
161
65
|
// src/runtime/audit-intent.ts
|
|
162
66
|
var defaultAuditorInstruction = "You audit whether an AI agent is on the RIGHT ROUTE \u2014 not whether it works hard, but whether its actions serve the stated intents. Infer the REVEALED intent from the action pattern (what the trajectory is actually optimizing). Compare against the declared task intent, the user intent when given, and the meta-intent when given. Flawless execution down the wrong route is DIVERGED. Busy-work that neither advances nor harms is DRIFTING. Judge only from the trajectory \u2014 be specific about which actions ground your verdict. Recommend abort only when continuing cannot serve the intent.";
|
|
163
67
|
function summarize(trace, maxLines) {
|
|
@@ -1940,24 +1844,50 @@ function fanout(items, opts) {
|
|
|
1940
1844
|
name: `${ctx.persona.name}/fanout`,
|
|
1941
1845
|
async act(_task, scope) {
|
|
1942
1846
|
const rejected = [];
|
|
1943
|
-
|
|
1944
|
-
|
|
1847
|
+
const unitAt = (i) => {
|
|
1848
|
+
const item = items[i];
|
|
1849
|
+
if (item === void 0) return void 0;
|
|
1945
1850
|
const label = opts.label ? opts.label(item, i) : `item:${i}`;
|
|
1946
1851
|
const spec = opts.itemSpec ? opts.itemSpec(item, i, ctx) : ctx.persona.root;
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
label
|
|
1852
|
+
return {
|
|
1853
|
+
agent: ctx.spawnChild(label, spec),
|
|
1854
|
+
task: opts.itemTask(item, i, ctx),
|
|
1855
|
+
opts: { budget: ctx.budget.perChild, label }
|
|
1856
|
+
};
|
|
1857
|
+
};
|
|
1858
|
+
let opened = 0;
|
|
1859
|
+
let drained;
|
|
1860
|
+
if (opts.width !== void 0) {
|
|
1861
|
+
let next = 0;
|
|
1862
|
+
const report = await rollingDispatch(scope, {
|
|
1863
|
+
width: opts.width,
|
|
1864
|
+
nextUnit: () => {
|
|
1865
|
+
const unit = unitAt(next);
|
|
1866
|
+
next += 1;
|
|
1867
|
+
return unit;
|
|
1868
|
+
}
|
|
1951
1869
|
});
|
|
1952
|
-
|
|
1953
|
-
|
|
1870
|
+
opened = report.admitted;
|
|
1871
|
+
for (const r of report.rejected) {
|
|
1872
|
+
const [label, reason] = splitOnce(r, ": ");
|
|
1873
|
+
rejected.push(`${label}: not admitted (${reason})`);
|
|
1874
|
+
}
|
|
1875
|
+
drained = projectDrain(report.settled);
|
|
1876
|
+
} else {
|
|
1877
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
1878
|
+
const unit = unitAt(i);
|
|
1879
|
+
if (unit === void 0) continue;
|
|
1880
|
+
const res = scope.spawn(unit.agent, unit.task, unit.opts);
|
|
1881
|
+
if (res.ok) opened += 1;
|
|
1882
|
+
else rejected.push(`${unit.opts.label}: not admitted (${res.reason})`);
|
|
1883
|
+
}
|
|
1884
|
+
drained = opened === 0 ? emptyRound() : await drain(scope);
|
|
1954
1885
|
}
|
|
1955
1886
|
if (opened === 0) {
|
|
1956
1887
|
return blocked(
|
|
1957
1888
|
rejected.length > 0 ? rejected : ["fanout: budget admitted no item (fanout fully rejected)"]
|
|
1958
1889
|
);
|
|
1959
1890
|
}
|
|
1960
|
-
const drained = await drain(scope);
|
|
1961
1891
|
if (drained.done.length === 0) {
|
|
1962
1892
|
return blocked(
|
|
1963
1893
|
orderedBlockers(
|
|
@@ -2164,6 +2094,26 @@ function flatWidenGate() {
|
|
|
2164
2094
|
}
|
|
2165
2095
|
};
|
|
2166
2096
|
}
|
|
2097
|
+
function emptyRound() {
|
|
2098
|
+
return { iterations: [], done: [], blockers: [] };
|
|
2099
|
+
}
|
|
2100
|
+
function projectDrain(settled) {
|
|
2101
|
+
const round = emptyRound();
|
|
2102
|
+
for (const s of settled) {
|
|
2103
|
+
if (s.kind === "down") {
|
|
2104
|
+
round.blockers.push(blockerFromDown(s));
|
|
2105
|
+
continue;
|
|
2106
|
+
}
|
|
2107
|
+
round.iterations.push(settledToIteration(s));
|
|
2108
|
+
round.done.push(s);
|
|
2109
|
+
}
|
|
2110
|
+
return round;
|
|
2111
|
+
}
|
|
2112
|
+
function splitOnce(text, sep) {
|
|
2113
|
+
const at = text.indexOf(sep);
|
|
2114
|
+
if (at < 0) return [text, ""];
|
|
2115
|
+
return [text.slice(0, at), text.slice(at + sep.length)];
|
|
2116
|
+
}
|
|
2167
2117
|
async function drain(scope) {
|
|
2168
2118
|
const iterations = [];
|
|
2169
2119
|
const done = [];
|
|
@@ -2587,16 +2537,18 @@ async function trajectoryReport(journal, blobs, root, options = {}) {
|
|
|
2587
2537
|
if (events === void 0) {
|
|
2588
2538
|
throw new Error(`trajectoryReport: no journaled tree for root '${root}'`);
|
|
2589
2539
|
}
|
|
2590
|
-
const spawns = events.filter(
|
|
2591
|
-
const closes = events.filter((ev) => ev.kind !== "spawned" && ev.kind !== "metered").sort(bySeq);
|
|
2540
|
+
const spawns = events.filter(isNodeCreation).sort(bySeq);
|
|
2541
|
+
const closes = events.filter((ev) => ev.kind !== "spawned" && ev.kind !== "waiting" && ev.kind !== "metered").sort(bySeq);
|
|
2592
2542
|
const nodes = /* @__PURE__ */ new Map();
|
|
2593
2543
|
for (const ev of spawns) {
|
|
2594
2544
|
nodes.set(ev.id, {
|
|
2595
2545
|
id: ev.id,
|
|
2596
2546
|
parent: ev.parent,
|
|
2597
2547
|
label: ev.label,
|
|
2598
|
-
runtime
|
|
2599
|
-
|
|
2548
|
+
// A wait-state has no executor, so it has no runtime in the executor sense — it is tagged
|
|
2549
|
+
// `'wait'` so a reader can separate zero-cost waiting from paid work in the trajectory.
|
|
2550
|
+
runtime: ev.kind === "waiting" ? "wait" : ev.runtime,
|
|
2551
|
+
status: ev.kind === "waiting" ? "waiting" : "pending",
|
|
2600
2552
|
ownSpend: zeroSpend(),
|
|
2601
2553
|
children: []
|
|
2602
2554
|
});
|
|
@@ -2607,6 +2559,11 @@ async function trajectoryReport(journal, blobs, root, options = {}) {
|
|
|
2607
2559
|
node.status = "cancelled";
|
|
2608
2560
|
continue;
|
|
2609
2561
|
}
|
|
2562
|
+
if (ev.kind === "woken") {
|
|
2563
|
+
node.status = ev.by === "cancelled" ? "cancelled" : "done";
|
|
2564
|
+
node.outRef = ev.outRef;
|
|
2565
|
+
continue;
|
|
2566
|
+
}
|
|
2610
2567
|
node.status = ev.status === "done" ? "done" : "failed";
|
|
2611
2568
|
node.ownSpend = ev.spent;
|
|
2612
2569
|
node.verdict = ev.verdict;
|
|
@@ -2716,7 +2673,8 @@ function countStatuses(reported) {
|
|
|
2716
2673
|
done: 0,
|
|
2717
2674
|
failed: 0,
|
|
2718
2675
|
cancelled: 0,
|
|
2719
|
-
pending: 0
|
|
2676
|
+
pending: 0,
|
|
2677
|
+
waiting: 0
|
|
2720
2678
|
};
|
|
2721
2679
|
for (const node of reported) counts[node.status] += 1;
|
|
2722
2680
|
return counts;
|
|
@@ -2756,13 +2714,13 @@ function spreadOf(values) {
|
|
|
2756
2714
|
function fractionalSpread(values) {
|
|
2757
2715
|
const spread = spreadOf(values);
|
|
2758
2716
|
if (spread === 0) return 0;
|
|
2759
|
-
const
|
|
2760
|
-
if (
|
|
2717
|
+
const median = medianOf(values);
|
|
2718
|
+
if (median === 0) {
|
|
2761
2719
|
throw new Error(
|
|
2762
2720
|
"equalKOnCost: arms have a non-zero cost spread on a zero-median channel; cannot express it as a fraction"
|
|
2763
2721
|
);
|
|
2764
2722
|
}
|
|
2765
|
-
return spread /
|
|
2723
|
+
return spread / median;
|
|
2766
2724
|
}
|
|
2767
2725
|
function medianOf(values) {
|
|
2768
2726
|
if (values.length === 0) {
|
|
@@ -2775,8 +2733,8 @@ function medianOf(values) {
|
|
|
2775
2733
|
const lo = sorted[mid - 1];
|
|
2776
2734
|
return (lo + hi) / 2;
|
|
2777
2735
|
}
|
|
2778
|
-
function
|
|
2779
|
-
return ev.kind === "spawned";
|
|
2736
|
+
function isNodeCreation(ev) {
|
|
2737
|
+
return ev.kind === "spawned" || ev.kind === "waiting";
|
|
2780
2738
|
}
|
|
2781
2739
|
function isNode(node) {
|
|
2782
2740
|
return node !== void 0;
|
|
@@ -4052,34 +4010,6 @@ function deriveTurnSignal(callerSignal, timeoutMs) {
|
|
|
4052
4010
|
};
|
|
4053
4011
|
}
|
|
4054
4012
|
|
|
4055
|
-
// src/runtime/supervise/detector-monitor.ts
|
|
4056
|
-
import {
|
|
4057
|
-
argHash,
|
|
4058
|
-
errorStreakDetector,
|
|
4059
|
-
observeAll,
|
|
4060
|
-
repeatedActionDetector
|
|
4061
|
-
} from "@tangle-network/agent-eval";
|
|
4062
|
-
function defaultToolDetectors() {
|
|
4063
|
-
return [repeatedActionDetector({ maxRepeated: 3 }), errorStreakDetector({ maxErrors: 3 })];
|
|
4064
|
-
}
|
|
4065
|
-
function watchTrace(source, opts = {}) {
|
|
4066
|
-
const detectors = opts.detectors ?? defaultToolDetectors();
|
|
4067
|
-
return source.onSpan((span) => {
|
|
4068
|
-
let fingerprint;
|
|
4069
|
-
try {
|
|
4070
|
-
fingerprint = `${span.toolName}|${argHash(span.args)}`;
|
|
4071
|
-
} catch {
|
|
4072
|
-
fingerprint = `${span.toolName}|<unhashable>`;
|
|
4073
|
-
}
|
|
4074
|
-
const signals = observeAll(detectors, {
|
|
4075
|
-
actionFingerprint: fingerprint,
|
|
4076
|
-
...span.status ? { status: span.status } : {},
|
|
4077
|
-
label: span.toolName
|
|
4078
|
-
});
|
|
4079
|
-
for (const s of signals) void opts.onSignal?.(s, span);
|
|
4080
|
-
});
|
|
4081
|
-
}
|
|
4082
|
-
|
|
4083
4013
|
// src/runtime/supervise/patch-checks.ts
|
|
4084
4014
|
var DEFAULT_MAX_DIFF_LINES = 400;
|
|
4085
4015
|
var secretPathPattern = /(^|\/)(\.env(\.|$)|.*\.(pem|key|p12|pfx|keystore|wallet)|id_rsa|id_ed25519|secrets?\.json|credentials?\.json)$/i;
|
|
@@ -4190,184 +4120,6 @@ function signalPass(value, required) {
|
|
|
4190
4120
|
return !required;
|
|
4191
4121
|
}
|
|
4192
4122
|
|
|
4193
|
-
// src/runtime/supervise/trace-source.ts
|
|
4194
|
-
function toToolSpan(input, runId, seq, at) {
|
|
4195
|
-
const startedAt = typeof input.startedAt === "number" ? input.startedAt : at;
|
|
4196
|
-
const endedAt = typeof input.endedAt === "number" ? input.endedAt : startedAt;
|
|
4197
|
-
return {
|
|
4198
|
-
spanId: `${runId}-t${seq}`,
|
|
4199
|
-
runId,
|
|
4200
|
-
kind: "tool",
|
|
4201
|
-
name: input.toolName,
|
|
4202
|
-
toolName: input.toolName,
|
|
4203
|
-
args: input.args,
|
|
4204
|
-
status: input.status ?? "ok",
|
|
4205
|
-
startedAt,
|
|
4206
|
-
endedAt,
|
|
4207
|
-
...input.result !== void 0 ? { result: input.result } : {}
|
|
4208
|
-
};
|
|
4209
|
-
}
|
|
4210
|
-
var obj = (v) => v && typeof v === "object" ? v : void 0;
|
|
4211
|
-
var str = (v) => typeof v === "string" && v ? v : void 0;
|
|
4212
|
-
var decodeOpencodePart = (raw) => {
|
|
4213
|
-
if (str(raw.type)?.toLowerCase() !== "tool" || !str(raw.tool)) return void 0;
|
|
4214
|
-
const part = raw;
|
|
4215
|
-
const state = obj(part.state);
|
|
4216
|
-
const status = state?.status;
|
|
4217
|
-
if (!status || status === "pending" || status === "running") return void 0;
|
|
4218
|
-
return {
|
|
4219
|
-
toolName: part.tool,
|
|
4220
|
-
args: state?.input ?? {},
|
|
4221
|
-
// ToolStateError carries 'error' OR 'failed' — the reverse-engineered decoder missed 'failed'.
|
|
4222
|
-
status: status === "error" || status === "failed" ? "error" : "ok",
|
|
4223
|
-
...str(part.callID) ? { callId: part.callID } : {}
|
|
4224
|
-
};
|
|
4225
|
-
};
|
|
4226
|
-
var decodeAnthropicPart = (p) => {
|
|
4227
|
-
if (str(p.type)?.toLowerCase() !== "tool_use") return void 0;
|
|
4228
|
-
const name = str(p.name) ?? str(p.tool);
|
|
4229
|
-
if (!name) return void 0;
|
|
4230
|
-
const id = str(p.id) ?? str(p.tool_use_id);
|
|
4231
|
-
return {
|
|
4232
|
-
toolName: name,
|
|
4233
|
-
args: p.input ?? {},
|
|
4234
|
-
...id ? { callId: id } : {}
|
|
4235
|
-
};
|
|
4236
|
-
};
|
|
4237
|
-
var decodeOpenAiPart = (p) => {
|
|
4238
|
-
const type = str(p.type)?.toLowerCase();
|
|
4239
|
-
const fn = obj(p.function);
|
|
4240
|
-
if (type !== "function" && type !== "tool_call") return void 0;
|
|
4241
|
-
const name = str(fn?.name) ?? str(p.name);
|
|
4242
|
-
if (!name) return void 0;
|
|
4243
|
-
const rawArgs = fn?.arguments ?? p.arguments;
|
|
4244
|
-
return {
|
|
4245
|
-
toolName: name,
|
|
4246
|
-
args: typeof rawArgs === "string" ? safeParse(rawArgs) : rawArgs ?? {},
|
|
4247
|
-
...str(p.id) ? { callId: p.id } : str(fn?.id) ? { callId: fn?.id } : {}
|
|
4248
|
-
};
|
|
4249
|
-
};
|
|
4250
|
-
var toolPartDecoders = {
|
|
4251
|
-
opencode: decodeOpencodePart,
|
|
4252
|
-
"claude-code": decodeAnthropicPart,
|
|
4253
|
-
anthropic: decodeAnthropicPart,
|
|
4254
|
-
codex: decodeOpenAiPart,
|
|
4255
|
-
openai: decodeOpenAiPart,
|
|
4256
|
-
router: decodeOpenAiPart,
|
|
4257
|
-
kimi: decodeOpenAiPart
|
|
4258
|
-
};
|
|
4259
|
-
function decodeToolPart(part, harness) {
|
|
4260
|
-
const p = obj(part);
|
|
4261
|
-
if (!p) return void 0;
|
|
4262
|
-
const specific = harness ? toolPartDecoders[harness] : void 0;
|
|
4263
|
-
if (specific) return specific(p);
|
|
4264
|
-
for (const decode of new Set(Object.values(toolPartDecoders))) {
|
|
4265
|
-
const step = decode(p);
|
|
4266
|
-
if (step) return step;
|
|
4267
|
-
}
|
|
4268
|
-
return void 0;
|
|
4269
|
-
}
|
|
4270
|
-
function safeParse(s) {
|
|
4271
|
-
try {
|
|
4272
|
-
return JSON.parse(s);
|
|
4273
|
-
} catch {
|
|
4274
|
-
return s;
|
|
4275
|
-
}
|
|
4276
|
-
}
|
|
4277
|
-
var runSeq = 0;
|
|
4278
|
-
function createPushTraceSource(opts = {}) {
|
|
4279
|
-
const runId = opts.runId ?? `push-${runSeq++}`;
|
|
4280
|
-
const now = opts.now ?? Date.now;
|
|
4281
|
-
const spans = [];
|
|
4282
|
-
const subs = /* @__PURE__ */ new Set();
|
|
4283
|
-
return {
|
|
4284
|
-
record(input) {
|
|
4285
|
-
const span = toToolSpan(input, runId, spans.length, now());
|
|
4286
|
-
spans.push(span);
|
|
4287
|
-
for (const fn of subs) {
|
|
4288
|
-
try {
|
|
4289
|
-
fn(span);
|
|
4290
|
-
} catch {
|
|
4291
|
-
}
|
|
4292
|
-
}
|
|
4293
|
-
return span;
|
|
4294
|
-
},
|
|
4295
|
-
source: {
|
|
4296
|
-
onSpan(handler) {
|
|
4297
|
-
subs.add(handler);
|
|
4298
|
-
return () => subs.delete(handler);
|
|
4299
|
-
},
|
|
4300
|
-
collect: () => Promise.resolve([...spans])
|
|
4301
|
-
}
|
|
4302
|
-
};
|
|
4303
|
-
}
|
|
4304
|
-
function createPartsTraceSource(opts) {
|
|
4305
|
-
const runId = opts.runId ?? `parts-${runSeq++}`;
|
|
4306
|
-
const now = opts.now ?? Date.now;
|
|
4307
|
-
const subs = /* @__PURE__ */ new Set();
|
|
4308
|
-
const seenLive = /* @__PURE__ */ new Set();
|
|
4309
|
-
let liveSeq = 0;
|
|
4310
|
-
let unsub;
|
|
4311
|
-
const startLive = () => {
|
|
4312
|
-
if (unsub || !opts.subscribeParts) return;
|
|
4313
|
-
unsub = opts.subscribeParts((part) => {
|
|
4314
|
-
const step = decodeToolPart(part, opts.harness);
|
|
4315
|
-
if (!step) return;
|
|
4316
|
-
if (step.callId) {
|
|
4317
|
-
if (seenLive.has(step.callId)) return;
|
|
4318
|
-
seenLive.add(step.callId);
|
|
4319
|
-
}
|
|
4320
|
-
const span = toToolSpan(step, runId, liveSeq++, now());
|
|
4321
|
-
for (const fn of subs) {
|
|
4322
|
-
try {
|
|
4323
|
-
fn(span);
|
|
4324
|
-
} catch {
|
|
4325
|
-
}
|
|
4326
|
-
}
|
|
4327
|
-
});
|
|
4328
|
-
};
|
|
4329
|
-
return {
|
|
4330
|
-
onSpan(handler) {
|
|
4331
|
-
subs.add(handler);
|
|
4332
|
-
startLive();
|
|
4333
|
-
return () => {
|
|
4334
|
-
subs.delete(handler);
|
|
4335
|
-
if (subs.size === 0 && unsub) {
|
|
4336
|
-
unsub();
|
|
4337
|
-
unsub = void 0;
|
|
4338
|
-
}
|
|
4339
|
-
};
|
|
4340
|
-
},
|
|
4341
|
-
async collect() {
|
|
4342
|
-
const parts = await opts.collectParts();
|
|
4343
|
-
const spans = [];
|
|
4344
|
-
const seen = /* @__PURE__ */ new Set();
|
|
4345
|
-
for (const part of parts) {
|
|
4346
|
-
const step = decodeToolPart(part, opts.harness);
|
|
4347
|
-
if (!step) continue;
|
|
4348
|
-
if (step.callId) {
|
|
4349
|
-
if (seen.has(step.callId)) continue;
|
|
4350
|
-
seen.add(step.callId);
|
|
4351
|
-
}
|
|
4352
|
-
spans.push(toToolSpan(step, runId, spans.length, now()));
|
|
4353
|
-
}
|
|
4354
|
-
return spans;
|
|
4355
|
-
}
|
|
4356
|
-
};
|
|
4357
|
-
}
|
|
4358
|
-
function sandboxSessionTraceSource(box, sessionId, opts = {}) {
|
|
4359
|
-
return createPartsTraceSource({
|
|
4360
|
-
collectParts: async () => {
|
|
4361
|
-
const msgs = await box.messages({ sessionId });
|
|
4362
|
-
return msgs.flatMap((m) => m.parts ? [...m.parts] : []);
|
|
4363
|
-
},
|
|
4364
|
-
...opts.harness ? { harness: opts.harness } : {},
|
|
4365
|
-
...opts.subscribeParts ? { subscribeParts: opts.subscribeParts } : {},
|
|
4366
|
-
runId: opts.runId ?? `box-${sessionId}`,
|
|
4367
|
-
...opts.now ? { now: opts.now } : {}
|
|
4368
|
-
});
|
|
4369
|
-
}
|
|
4370
|
-
|
|
4371
4123
|
// src/runtime/supervise/trajectory-recorder.ts
|
|
4372
4124
|
import { buildTrajectory, InMemoryTraceStore } from "@tangle-network/agent-eval";
|
|
4373
4125
|
import { stuckLoopView, toolWasteView } from "@tangle-network/agent-eval/pipelines";
|
|
@@ -4899,8 +4651,6 @@ export {
|
|
|
4899
4651
|
McpSpawnFault,
|
|
4900
4652
|
connectStdioMcp,
|
|
4901
4653
|
materializeLocalMcp,
|
|
4902
|
-
anytimeReport,
|
|
4903
|
-
renderAnytimeTable,
|
|
4904
4654
|
defaultAuditorInstruction,
|
|
4905
4655
|
auditIntent,
|
|
4906
4656
|
leaderboard,
|
|
@@ -4960,13 +4710,8 @@ export {
|
|
|
4960
4710
|
runStrategyEvolution,
|
|
4961
4711
|
streamAgentTurn,
|
|
4962
4712
|
collectAgentTurn,
|
|
4963
|
-
defaultToolDetectors,
|
|
4964
|
-
watchTrace,
|
|
4965
4713
|
runCoderChecks,
|
|
4966
4714
|
patchDelivered,
|
|
4967
|
-
decodeToolPart,
|
|
4968
|
-
createPushTraceSource,
|
|
4969
|
-
sandboxSessionTraceSource,
|
|
4970
4715
|
analyzeTrace,
|
|
4971
4716
|
worktreeFanout,
|
|
4972
4717
|
failuresAnalyst,
|
|
@@ -4980,4 +4725,4 @@ export {
|
|
|
4980
4725
|
computeFindingId,
|
|
4981
4726
|
makeFinding
|
|
4982
4727
|
};
|
|
4983
|
-
//# sourceMappingURL=chunk-
|
|
4728
|
+
//# sourceMappingURL=chunk-3LJF5XSE.js.map
|