@tangle-network/agent-runtime 0.57.0 → 0.58.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/dist/agent.js +1 -1
- package/dist/{chunk-TVBXDW7C.js → chunk-E2L6PG5F.js} +3 -3
- package/dist/{chunk-WFEQCRQP.js → chunk-ISVIQDIX.js} +2 -2
- package/dist/{chunk-RLDUT4JL.js → chunk-MDFZSPHA.js} +254 -101
- package/dist/chunk-MDFZSPHA.js.map +1 -0
- package/dist/{chunk-NJST5D2G.js → chunk-VAGARXI5.js} +2 -2
- package/dist/{chunk-6BOIKGSU.js → chunk-ZGPQY6Z3.js} +2 -2
- package/dist/index.js +4 -4
- package/dist/loop-runner-bin.js +3 -3
- package/dist/loops.d.ts +1 -1
- package/dist/loops.js +23 -5
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.js +4 -4
- package/dist/runtime.d.ts +132 -51
- package/dist/runtime.js +23 -5
- package/dist/workflow.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-RLDUT4JL.js.map +0 -1
- /package/dist/{chunk-TVBXDW7C.js.map → chunk-E2L6PG5F.js.map} +0 -0
- /package/dist/{chunk-WFEQCRQP.js.map → chunk-ISVIQDIX.js.map} +0 -0
- /package/dist/{chunk-NJST5D2G.js.map → chunk-VAGARXI5.js.map} +0 -0
- /package/dist/{chunk-6BOIKGSU.js.map → chunk-ZGPQY6Z3.js.map} +0 -0
package/dist/agent.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createFleetWorkspaceExecutor,
|
|
3
3
|
createSiblingSandboxExecutor
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ISVIQDIX.js";
|
|
5
5
|
import {
|
|
6
6
|
runWorktreeHarness
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-MDFZSPHA.js";
|
|
8
8
|
import {
|
|
9
9
|
buildLoopOtelSpans,
|
|
10
10
|
createOtelExporter
|
|
@@ -294,4 +294,4 @@ export {
|
|
|
294
294
|
createPropagatingTraceEmitter,
|
|
295
295
|
traceContextToEnv
|
|
296
296
|
};
|
|
297
|
-
//# sourceMappingURL=chunk-
|
|
297
|
+
//# sourceMappingURL=chunk-E2L6PG5F.js.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
parseDetachedSessionRef,
|
|
6
6
|
runDetachedTurn,
|
|
7
7
|
runLoop
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-MDFZSPHA.js";
|
|
9
9
|
import {
|
|
10
10
|
coderProfile,
|
|
11
11
|
multiHarnessCoderFanout
|
|
@@ -279,4 +279,4 @@ export {
|
|
|
279
279
|
coderTaskFromArgs,
|
|
280
280
|
settleDetachedCoderTurn
|
|
281
281
|
};
|
|
282
|
-
//# sourceMappingURL=chunk-
|
|
282
|
+
//# sourceMappingURL=chunk-ISVIQDIX.js.map
|
|
@@ -809,14 +809,14 @@ ${traceSummary}`
|
|
|
809
809
|
return { findings, learned, report: renderReport(findings) };
|
|
810
810
|
}
|
|
811
811
|
function parseFindings(content) {
|
|
812
|
-
let
|
|
812
|
+
let obj2;
|
|
813
813
|
try {
|
|
814
|
-
|
|
814
|
+
obj2 = JSON.parse(content);
|
|
815
815
|
} catch {
|
|
816
816
|
const m = content.match(/\{[\s\S]*\}/);
|
|
817
|
-
|
|
817
|
+
obj2 = m ? JSON.parse(m[0]) : { findings: [] };
|
|
818
818
|
}
|
|
819
|
-
const arr =
|
|
819
|
+
const arr = obj2.findings;
|
|
820
820
|
return Array.isArray(arr) ? arr : [];
|
|
821
821
|
}
|
|
822
822
|
function renderReport(findings) {
|
|
@@ -1888,15 +1888,15 @@ async function emitTrace(emitter, event) {
|
|
|
1888
1888
|
await emitter.emit(event);
|
|
1889
1889
|
}
|
|
1890
1890
|
function hashJson(value) {
|
|
1891
|
-
let
|
|
1891
|
+
let str2;
|
|
1892
1892
|
try {
|
|
1893
|
-
|
|
1893
|
+
str2 = JSON.stringify(value) ?? String(value);
|
|
1894
1894
|
} catch {
|
|
1895
|
-
|
|
1895
|
+
str2 = String(value);
|
|
1896
1896
|
}
|
|
1897
1897
|
let h = 2166136261;
|
|
1898
|
-
for (let i = 0; i <
|
|
1899
|
-
h ^=
|
|
1898
|
+
for (let i = 0; i < str2.length; i += 1) {
|
|
1899
|
+
h ^= str2.charCodeAt(i);
|
|
1900
1900
|
h = Math.imul(h, 16777619);
|
|
1901
1901
|
}
|
|
1902
1902
|
return (h >>> 0).toString(16).padStart(8, "0");
|
|
@@ -3750,15 +3750,15 @@ var cliSeamKey = "cli";
|
|
|
3750
3750
|
var bridgeSeamKey = "bridge";
|
|
3751
3751
|
var cliWorktreeSeamKey = "cli-worktree";
|
|
3752
3752
|
function contentRef(prefix, value) {
|
|
3753
|
-
let
|
|
3753
|
+
let str2;
|
|
3754
3754
|
try {
|
|
3755
|
-
|
|
3755
|
+
str2 = JSON.stringify(value) ?? String(value);
|
|
3756
3756
|
} catch {
|
|
3757
|
-
|
|
3757
|
+
str2 = String(value);
|
|
3758
3758
|
}
|
|
3759
3759
|
let h = 2166136261;
|
|
3760
|
-
for (let i = 0; i <
|
|
3761
|
-
h ^=
|
|
3760
|
+
for (let i = 0; i < str2.length; i += 1) {
|
|
3761
|
+
h ^= str2.charCodeAt(i);
|
|
3762
3762
|
h = Math.imul(h, 16777619);
|
|
3763
3763
|
}
|
|
3764
3764
|
return `${prefix}:${(h >>> 0).toString(16).padStart(8, "0")}`;
|
|
@@ -4338,9 +4338,9 @@ function readSeam(ctx, key, who) {
|
|
|
4338
4338
|
function taskToPrompt(task) {
|
|
4339
4339
|
if (typeof task === "string") return task;
|
|
4340
4340
|
if (task && typeof task === "object") {
|
|
4341
|
-
const
|
|
4341
|
+
const obj2 = task;
|
|
4342
4342
|
for (const k of ["prompt", "content", "task", "message"]) {
|
|
4343
|
-
if (typeof
|
|
4343
|
+
if (typeof obj2[k] === "string") return obj2[k];
|
|
4344
4344
|
}
|
|
4345
4345
|
}
|
|
4346
4346
|
return JSON.stringify(task);
|
|
@@ -7038,12 +7038,12 @@ function createCoordinationTools(opts) {
|
|
|
7038
7038
|
bus.subscribe((rec) => cb(rec.event));
|
|
7039
7039
|
}
|
|
7040
7040
|
const urgencyPriority = (u) => u === "blocks-run" ? 20 : u === "blocks-step" ? 10 : 0;
|
|
7041
|
-
const
|
|
7041
|
+
const str2 = (v, field) => {
|
|
7042
7042
|
if (typeof v !== "string" || v.length === 0)
|
|
7043
7043
|
throw new Error(`coordination tools: "${field}" must be a non-empty string`);
|
|
7044
7044
|
return v;
|
|
7045
7045
|
};
|
|
7046
|
-
const
|
|
7046
|
+
const obj2 = (raw) => {
|
|
7047
7047
|
if (!raw || typeof raw !== "object")
|
|
7048
7048
|
throw new Error("coordination tools: arguments must be an object");
|
|
7049
7049
|
return raw;
|
|
@@ -7085,7 +7085,7 @@ function createCoordinationTools(opts) {
|
|
|
7085
7085
|
};
|
|
7086
7086
|
async function sendDown(type, down, questionId) {
|
|
7087
7087
|
await bus.publish(
|
|
7088
|
-
type === "answer" ? { type, down, questionId:
|
|
7088
|
+
type === "answer" ? { type, down, questionId: str2(questionId, "questionId") } : { type, down },
|
|
7089
7089
|
{ queue: false }
|
|
7090
7090
|
);
|
|
7091
7091
|
}
|
|
@@ -7108,13 +7108,13 @@ function createCoordinationTools(opts) {
|
|
|
7108
7108
|
};
|
|
7109
7109
|
const nextQuestionId = (from) => `${from}:q${questionSeq++}`;
|
|
7110
7110
|
const normalizeQuestion = (q, fallbackFrom) => {
|
|
7111
|
-
const from =
|
|
7111
|
+
const from = str2(q.from ?? fallbackFrom, "from");
|
|
7112
7112
|
return {
|
|
7113
7113
|
id: typeof q.id === "string" && q.id.length > 0 ? q.id : nextQuestionId(from),
|
|
7114
7114
|
from,
|
|
7115
7115
|
level: level(q.level),
|
|
7116
|
-
question:
|
|
7117
|
-
reason:
|
|
7116
|
+
question: str2(q.question, "question"),
|
|
7117
|
+
reason: str2(q.reason, "reason"),
|
|
7118
7118
|
...q.options ? { options: q.options } : {},
|
|
7119
7119
|
urgency: urgency(q.urgency)
|
|
7120
7120
|
};
|
|
@@ -7178,7 +7178,7 @@ function createCoordinationTools(opts) {
|
|
|
7178
7178
|
required: ["profile", "task"]
|
|
7179
7179
|
},
|
|
7180
7180
|
handler: (raw) => {
|
|
7181
|
-
const a =
|
|
7181
|
+
const a = obj2(raw);
|
|
7182
7182
|
const agent = opts.makeWorkerAgent(a.profile);
|
|
7183
7183
|
const res = opts.scope.spawn(agent, a.task, {
|
|
7184
7184
|
budget: opts.perWorker,
|
|
@@ -7192,7 +7192,7 @@ function createCoordinationTools(opts) {
|
|
|
7192
7192
|
description: "Inspect a worker status, spend, and settled output artifact when available.",
|
|
7193
7193
|
inputSchema: { type: "object", properties: { workerId: idArg }, required: ["workerId"] },
|
|
7194
7194
|
handler: async (raw) => {
|
|
7195
|
-
const id =
|
|
7195
|
+
const id = str2(obj2(raw).workerId, "workerId");
|
|
7196
7196
|
const node = opts.scope.view.nodes.find((n) => n.id === id);
|
|
7197
7197
|
if (!node) return { error: `unknown workerId ${JSON.stringify(id)}` };
|
|
7198
7198
|
const output = node.outRef ? await opts.blobs.get(node.outRef) : void 0;
|
|
@@ -7220,9 +7220,9 @@ function createCoordinationTools(opts) {
|
|
|
7220
7220
|
required: ["workerId", "instruction"]
|
|
7221
7221
|
},
|
|
7222
7222
|
handler: async (raw) => {
|
|
7223
|
-
const a =
|
|
7224
|
-
const workerId =
|
|
7225
|
-
const instruction =
|
|
7223
|
+
const a = obj2(raw);
|
|
7224
|
+
const workerId = str2(a.workerId, "workerId");
|
|
7225
|
+
const instruction = str2(a.instruction, "instruction");
|
|
7226
7226
|
const interrupt = a.interrupt === true;
|
|
7227
7227
|
const delivered = opts.scope.send(workerId, { steer: instruction, interrupt });
|
|
7228
7228
|
await sendDown("steer", { toWorker: workerId, instruction, delivered });
|
|
@@ -7243,7 +7243,7 @@ function createCoordinationTools(opts) {
|
|
|
7243
7243
|
}
|
|
7244
7244
|
},
|
|
7245
7245
|
handler: async (raw) => {
|
|
7246
|
-
const k =
|
|
7246
|
+
const k = obj2(raw).kinds;
|
|
7247
7247
|
const kinds = Array.isArray(k) ? k.filter((x) => x === "settled" || x === "question" || x === "finding") : void 0;
|
|
7248
7248
|
let ev = bus.pull(kinds);
|
|
7249
7249
|
if (!ev) {
|
|
@@ -7276,8 +7276,8 @@ function createCoordinationTools(opts) {
|
|
|
7276
7276
|
required: ["questionId"]
|
|
7277
7277
|
},
|
|
7278
7278
|
handler: async (raw) => {
|
|
7279
|
-
const a =
|
|
7280
|
-
const questionId =
|
|
7279
|
+
const a = obj2(raw);
|
|
7280
|
+
const questionId = str2(a.questionId, "questionId");
|
|
7281
7281
|
if (typeof a.answer === "string" && a.answer.length > 0) {
|
|
7282
7282
|
const answer = a.answer;
|
|
7283
7283
|
const question = decideQuestion(questionId, {
|
|
@@ -7330,15 +7330,15 @@ function createCoordinationTools(opts) {
|
|
|
7330
7330
|
required: ["from", "level", "question", "reason", "urgency"]
|
|
7331
7331
|
},
|
|
7332
7332
|
handler: async (raw) => {
|
|
7333
|
-
const a =
|
|
7334
|
-
const from =
|
|
7333
|
+
const a = obj2(raw);
|
|
7334
|
+
const from = str2(a.from, "from");
|
|
7335
7335
|
const q = await emitNewQuestion(
|
|
7336
7336
|
addQuestion(
|
|
7337
7337
|
{
|
|
7338
7338
|
from,
|
|
7339
7339
|
level: level(a.level),
|
|
7340
|
-
question:
|
|
7341
|
-
reason:
|
|
7340
|
+
question: str2(a.question, "question"),
|
|
7341
|
+
reason: str2(a.reason, "reason"),
|
|
7342
7342
|
urgency: urgency(a.urgency)
|
|
7343
7343
|
},
|
|
7344
7344
|
from,
|
|
@@ -7365,7 +7365,7 @@ function createCoordinationTools(opts) {
|
|
|
7365
7365
|
});
|
|
7366
7366
|
}
|
|
7367
7367
|
stopped = true;
|
|
7368
|
-
const r =
|
|
7368
|
+
const r = obj2(raw).reason;
|
|
7369
7369
|
reason = typeof r === "string" ? r : void 0;
|
|
7370
7370
|
return Promise.resolve({ stopped: true });
|
|
7371
7371
|
}
|
|
@@ -7390,14 +7390,14 @@ function createCoordinationTools(opts) {
|
|
|
7390
7390
|
required: ["kind", "workerId"]
|
|
7391
7391
|
},
|
|
7392
7392
|
handler: async (raw) => {
|
|
7393
|
-
const a =
|
|
7394
|
-
const id =
|
|
7393
|
+
const a = obj2(raw);
|
|
7394
|
+
const id = str2(a.workerId, "workerId");
|
|
7395
7395
|
const node = opts.scope.view.nodes.find((n) => n.id === id);
|
|
7396
7396
|
if (!node) return { error: `unknown workerId ${JSON.stringify(id)}` };
|
|
7397
7397
|
if (!node.outRef)
|
|
7398
7398
|
return { error: `worker ${JSON.stringify(id)} has not settled \u2014 no trace to analyze yet` };
|
|
7399
7399
|
const trace = await opts.blobs.get(node.outRef);
|
|
7400
|
-
return { findings: await opts.analysts?.run(
|
|
7400
|
+
return { findings: await opts.analysts?.run(str2(a.kind, "kind"), trace) };
|
|
7401
7401
|
}
|
|
7402
7402
|
});
|
|
7403
7403
|
}
|
|
@@ -8256,15 +8256,15 @@ function randomTaskId() {
|
|
|
8256
8256
|
return `dlg-${t}-${r}`;
|
|
8257
8257
|
}
|
|
8258
8258
|
function hashIdempotencyInput(value) {
|
|
8259
|
-
let
|
|
8259
|
+
let str2;
|
|
8260
8260
|
try {
|
|
8261
|
-
|
|
8261
|
+
str2 = JSON.stringify(canonicalize(value));
|
|
8262
8262
|
} catch {
|
|
8263
|
-
|
|
8263
|
+
str2 = String(value);
|
|
8264
8264
|
}
|
|
8265
8265
|
let h = 2166136261;
|
|
8266
|
-
for (let i = 0; i <
|
|
8267
|
-
h ^=
|
|
8266
|
+
for (let i = 0; i < str2.length; i += 1) {
|
|
8267
|
+
h ^= str2.charCodeAt(i);
|
|
8268
8268
|
h = Math.imul(h, 16777619);
|
|
8269
8269
|
}
|
|
8270
8270
|
return (h >>> 0).toString(16).padStart(8, "0");
|
|
@@ -9711,29 +9711,22 @@ import {
|
|
|
9711
9711
|
function defaultToolDetectors() {
|
|
9712
9712
|
return [repeatedActionDetector({ maxRepeated: 3 }), errorStreakDetector({ maxErrors: 3 })];
|
|
9713
9713
|
}
|
|
9714
|
-
function
|
|
9714
|
+
function watchTrace(source, opts = {}) {
|
|
9715
9715
|
const detectors = opts.detectors ?? defaultToolDetectors();
|
|
9716
|
-
return {
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
fingerprint = `${step.toolName}|<unhashable>`;
|
|
9723
|
-
}
|
|
9724
|
-
const signals = observeAll(detectors, {
|
|
9725
|
-
// Same fingerprint scheme as agent-eval's batch stuck-loop view: tool name + hashed args.
|
|
9726
|
-
actionFingerprint: fingerprint,
|
|
9727
|
-
...step.status ? { status: step.status } : {},
|
|
9728
|
-
label: step.toolName
|
|
9729
|
-
});
|
|
9730
|
-
for (const s of signals) void opts.onSignal?.(s);
|
|
9731
|
-
return signals;
|
|
9732
|
-
},
|
|
9733
|
-
reset() {
|
|
9734
|
-
for (const d of detectors) d.reset();
|
|
9716
|
+
return source.onSpan((span) => {
|
|
9717
|
+
let fingerprint;
|
|
9718
|
+
try {
|
|
9719
|
+
fingerprint = `${span.toolName}|${argHash(span.args)}`;
|
|
9720
|
+
} catch {
|
|
9721
|
+
fingerprint = `${span.toolName}|<unhashable>`;
|
|
9735
9722
|
}
|
|
9736
|
-
|
|
9723
|
+
const signals = observeAll(detectors, {
|
|
9724
|
+
actionFingerprint: fingerprint,
|
|
9725
|
+
...span.status ? { status: span.status } : {},
|
|
9726
|
+
label: span.toolName
|
|
9727
|
+
});
|
|
9728
|
+
for (const s of signals) void opts.onSignal?.(s, span);
|
|
9729
|
+
});
|
|
9737
9730
|
}
|
|
9738
9731
|
|
|
9739
9732
|
// src/runtime/supervise/router-driver-chat.ts
|
|
@@ -9790,46 +9783,197 @@ function safeParse(s) {
|
|
|
9790
9783
|
}
|
|
9791
9784
|
}
|
|
9792
9785
|
|
|
9793
|
-
// src/runtime/supervise/
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
|
|
9797
|
-
|
|
9786
|
+
// src/runtime/supervise/trace-source.ts
|
|
9787
|
+
function toToolSpan(input, runId, seq, at) {
|
|
9788
|
+
return {
|
|
9789
|
+
spanId: `${runId}-t${seq}`,
|
|
9790
|
+
runId,
|
|
9791
|
+
kind: "tool",
|
|
9792
|
+
name: input.toolName,
|
|
9793
|
+
toolName: input.toolName,
|
|
9794
|
+
args: input.args,
|
|
9795
|
+
status: input.status ?? "ok",
|
|
9796
|
+
startedAt: at,
|
|
9797
|
+
endedAt: at,
|
|
9798
|
+
...input.result !== void 0 ? { result: input.result } : {}
|
|
9799
|
+
};
|
|
9800
|
+
}
|
|
9801
|
+
var obj = (v) => v && typeof v === "object" ? v : void 0;
|
|
9802
|
+
var str = (v) => typeof v === "string" && v ? v : void 0;
|
|
9803
|
+
var decodeOpencodePart = (p) => {
|
|
9804
|
+
if (str(p.type)?.toLowerCase() !== "tool" || !str(p.tool)) return void 0;
|
|
9805
|
+
const state = obj(p.state);
|
|
9806
|
+
const status = str(state?.status) ?? "";
|
|
9807
|
+
if (status === "pending" || status === "running") return void 0;
|
|
9798
9808
|
return {
|
|
9799
|
-
|
|
9800
|
-
|
|
9809
|
+
toolName: p.tool,
|
|
9810
|
+
args: state?.input ?? {},
|
|
9811
|
+
...status === "error" ? { status: "error" } : status ? { status: "ok" } : {},
|
|
9812
|
+
...str(p.callID) ? { callId: p.callID } : {}
|
|
9813
|
+
};
|
|
9814
|
+
};
|
|
9815
|
+
var decodeAnthropicPart = (p) => {
|
|
9816
|
+
if (str(p.type)?.toLowerCase() !== "tool_use") return void 0;
|
|
9817
|
+
const name = str(p.name) ?? str(p.tool);
|
|
9818
|
+
if (!name) return void 0;
|
|
9819
|
+
const id = str(p.id) ?? str(p.tool_use_id);
|
|
9820
|
+
return {
|
|
9821
|
+
toolName: name,
|
|
9822
|
+
args: p.input ?? {},
|
|
9823
|
+
...id ? { callId: id } : {}
|
|
9824
|
+
};
|
|
9825
|
+
};
|
|
9826
|
+
var decodeOpenAiPart = (p) => {
|
|
9827
|
+
const type = str(p.type)?.toLowerCase();
|
|
9828
|
+
const fn = obj(p.function);
|
|
9829
|
+
if (type !== "function" && type !== "tool_call") return void 0;
|
|
9830
|
+
const name = str(fn?.name) ?? str(p.name);
|
|
9831
|
+
if (!name) return void 0;
|
|
9832
|
+
const rawArgs = fn?.arguments ?? p.arguments;
|
|
9833
|
+
return {
|
|
9834
|
+
toolName: name,
|
|
9835
|
+
args: typeof rawArgs === "string" ? safeParse2(rawArgs) : rawArgs ?? {},
|
|
9836
|
+
...str(p.id) ? { callId: p.id } : str(fn?.id) ? { callId: fn?.id } : {}
|
|
9837
|
+
};
|
|
9838
|
+
};
|
|
9839
|
+
var toolPartDecoders = {
|
|
9840
|
+
opencode: decodeOpencodePart,
|
|
9841
|
+
"claude-code": decodeAnthropicPart,
|
|
9842
|
+
anthropic: decodeAnthropicPart,
|
|
9843
|
+
codex: decodeOpenAiPart,
|
|
9844
|
+
openai: decodeOpenAiPart,
|
|
9845
|
+
router: decodeOpenAiPart,
|
|
9846
|
+
kimi: decodeOpenAiPart
|
|
9847
|
+
};
|
|
9848
|
+
function decodeToolPart(part, harness) {
|
|
9849
|
+
const p = obj(part);
|
|
9850
|
+
if (!p) return void 0;
|
|
9851
|
+
const specific = harness ? toolPartDecoders[harness] : void 0;
|
|
9852
|
+
if (specific) return specific(p);
|
|
9853
|
+
for (const decode of new Set(Object.values(toolPartDecoders))) {
|
|
9854
|
+
const step = decode(p);
|
|
9855
|
+
if (step) return step;
|
|
9856
|
+
}
|
|
9857
|
+
return void 0;
|
|
9858
|
+
}
|
|
9859
|
+
function safeParse2(s) {
|
|
9860
|
+
try {
|
|
9861
|
+
return JSON.parse(s);
|
|
9862
|
+
} catch {
|
|
9863
|
+
return s;
|
|
9864
|
+
}
|
|
9865
|
+
}
|
|
9866
|
+
var runSeq = 0;
|
|
9867
|
+
function createPushTraceSource(opts = {}) {
|
|
9868
|
+
const runId = opts.runId ?? `push-${runSeq++}`;
|
|
9869
|
+
const now = opts.now ?? Date.now;
|
|
9870
|
+
const spans = [];
|
|
9871
|
+
const subs = /* @__PURE__ */ new Set();
|
|
9872
|
+
return {
|
|
9873
|
+
record(input) {
|
|
9874
|
+
const span = toToolSpan(input, runId, spans.length, now());
|
|
9875
|
+
spans.push(span);
|
|
9876
|
+
for (const fn of subs) {
|
|
9877
|
+
try {
|
|
9878
|
+
fn(span);
|
|
9879
|
+
} catch {
|
|
9880
|
+
}
|
|
9881
|
+
}
|
|
9882
|
+
return span;
|
|
9801
9883
|
},
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
const
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
9826
|
-
|
|
9884
|
+
source: {
|
|
9885
|
+
onSpan(handler) {
|
|
9886
|
+
subs.add(handler);
|
|
9887
|
+
return () => subs.delete(handler);
|
|
9888
|
+
},
|
|
9889
|
+
collect: () => Promise.resolve([...spans])
|
|
9890
|
+
}
|
|
9891
|
+
};
|
|
9892
|
+
}
|
|
9893
|
+
function createPartsTraceSource(opts) {
|
|
9894
|
+
const runId = opts.runId ?? `parts-${runSeq++}`;
|
|
9895
|
+
const now = opts.now ?? Date.now;
|
|
9896
|
+
const subs = /* @__PURE__ */ new Set();
|
|
9897
|
+
const seenLive = /* @__PURE__ */ new Set();
|
|
9898
|
+
let liveSeq = 0;
|
|
9899
|
+
let unsub;
|
|
9900
|
+
const startLive = () => {
|
|
9901
|
+
if (unsub || !opts.subscribeParts) return;
|
|
9902
|
+
unsub = opts.subscribeParts((part) => {
|
|
9903
|
+
const step = decodeToolPart(part, opts.harness);
|
|
9904
|
+
if (!step) return;
|
|
9905
|
+
if (step.callId) {
|
|
9906
|
+
if (seenLive.has(step.callId)) return;
|
|
9907
|
+
seenLive.add(step.callId);
|
|
9908
|
+
}
|
|
9909
|
+
const span = toToolSpan(step, runId, liveSeq++, now());
|
|
9910
|
+
for (const fn of subs) {
|
|
9911
|
+
try {
|
|
9912
|
+
fn(span);
|
|
9913
|
+
} catch {
|
|
9914
|
+
}
|
|
9915
|
+
}
|
|
9916
|
+
});
|
|
9917
|
+
};
|
|
9918
|
+
return {
|
|
9919
|
+
onSpan(handler) {
|
|
9920
|
+
subs.add(handler);
|
|
9921
|
+
startLive();
|
|
9922
|
+
return () => {
|
|
9923
|
+
subs.delete(handler);
|
|
9924
|
+
if (subs.size === 0 && unsub) {
|
|
9925
|
+
unsub();
|
|
9926
|
+
unsub = void 0;
|
|
9927
|
+
}
|
|
9928
|
+
};
|
|
9827
9929
|
},
|
|
9828
|
-
|
|
9829
|
-
|
|
9930
|
+
async collect() {
|
|
9931
|
+
const parts = await opts.collectParts();
|
|
9932
|
+
const spans = [];
|
|
9933
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9934
|
+
for (const part of parts) {
|
|
9935
|
+
const step = decodeToolPart(part, opts.harness);
|
|
9936
|
+
if (!step) continue;
|
|
9937
|
+
if (step.callId) {
|
|
9938
|
+
if (seen.has(step.callId)) continue;
|
|
9939
|
+
seen.add(step.callId);
|
|
9940
|
+
}
|
|
9941
|
+
spans.push(toToolSpan(step, runId, spans.length, now()));
|
|
9942
|
+
}
|
|
9943
|
+
return spans;
|
|
9830
9944
|
}
|
|
9831
9945
|
};
|
|
9832
9946
|
}
|
|
9947
|
+
function sandboxSessionTraceSource(box, sessionId, opts = {}) {
|
|
9948
|
+
return createPartsTraceSource({
|
|
9949
|
+
collectParts: async () => {
|
|
9950
|
+
const msgs = await box.messages({ sessionId });
|
|
9951
|
+
return msgs.flatMap((m) => m.parts ? [...m.parts] : []);
|
|
9952
|
+
},
|
|
9953
|
+
...opts.harness ? { harness: opts.harness } : {},
|
|
9954
|
+
...opts.subscribeParts ? { subscribeParts: opts.subscribeParts } : {},
|
|
9955
|
+
runId: opts.runId ?? `box-${sessionId}`,
|
|
9956
|
+
...opts.now ? { now: opts.now } : {}
|
|
9957
|
+
});
|
|
9958
|
+
}
|
|
9959
|
+
|
|
9960
|
+
// src/runtime/supervise/trajectory-recorder.ts
|
|
9961
|
+
import { buildTrajectory, InMemoryTraceStore } from "@tangle-network/agent-eval";
|
|
9962
|
+
import { stuckLoopView, toolWasteView } from "@tangle-network/agent-eval/pipelines";
|
|
9963
|
+
async function analyzeTrace(source, runId = "worker") {
|
|
9964
|
+
const spans = await source.collect();
|
|
9965
|
+
const store = new InMemoryTraceStore();
|
|
9966
|
+
for (let i = 0; i < spans.length; i += 1) {
|
|
9967
|
+
const s = spans[i];
|
|
9968
|
+
if (s) await store.appendSpan({ ...s, runId, spanId: `${runId}-t${i}` });
|
|
9969
|
+
}
|
|
9970
|
+
const [trajectory, stuckLoop, toolWaste] = await Promise.all([
|
|
9971
|
+
buildTrajectory(store, runId),
|
|
9972
|
+
stuckLoopView(store, { runId }),
|
|
9973
|
+
toolWasteView(store, { runId })
|
|
9974
|
+
]);
|
|
9975
|
+
return { trajectory, stuckLoop, toolWaste };
|
|
9976
|
+
}
|
|
9833
9977
|
|
|
9834
9978
|
// src/runtime/verifier-environment.ts
|
|
9835
9979
|
var submitTool = {
|
|
@@ -10279,9 +10423,18 @@ export {
|
|
|
10279
10423
|
createInProcessTransport,
|
|
10280
10424
|
serveCoordinationMcp,
|
|
10281
10425
|
defaultToolDetectors,
|
|
10282
|
-
|
|
10426
|
+
watchTrace,
|
|
10283
10427
|
routerDriverChat,
|
|
10284
|
-
|
|
10428
|
+
toToolSpan,
|
|
10429
|
+
decodeOpencodePart,
|
|
10430
|
+
decodeAnthropicPart,
|
|
10431
|
+
decodeOpenAiPart,
|
|
10432
|
+
toolPartDecoders,
|
|
10433
|
+
decodeToolPart,
|
|
10434
|
+
createPushTraceSource,
|
|
10435
|
+
createPartsTraceSource,
|
|
10436
|
+
sandboxSessionTraceSource,
|
|
10437
|
+
analyzeTrace,
|
|
10285
10438
|
createVerifierEnvironment,
|
|
10286
10439
|
createWaterfallCollector,
|
|
10287
10440
|
localShell,
|
|
@@ -10289,4 +10442,4 @@ export {
|
|
|
10289
10442
|
jjWorkspace,
|
|
10290
10443
|
runInWorkspace
|
|
10291
10444
|
};
|
|
10292
|
-
//# sourceMappingURL=chunk-
|
|
10445
|
+
//# sourceMappingURL=chunk-MDFZSPHA.js.map
|