@tangle-network/agent-runtime 0.57.0 → 0.59.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-RLDUT4JL.js → chunk-45D64J7B.js} +263 -103
- package/dist/chunk-45D64J7B.js.map +1 -0
- package/dist/{chunk-WFEQCRQP.js → chunk-4FEUFYOY.js} +2 -2
- package/dist/{chunk-6BOIKGSU.js → chunk-IN7WHMGZ.js} +2 -2
- package/dist/{chunk-TVBXDW7C.js → chunk-MMDIORZY.js} +3 -3
- package/dist/{chunk-NJST5D2G.js → chunk-ZWGEA722.js} +2 -2
- package/dist/{coordination-BydGBQCZ.d.ts → coordination-Biw19JzN.d.ts} +3 -2
- package/dist/index.js +4 -4
- package/dist/loop-runner-bin.js +3 -3
- package/dist/loops.d.ts +2 -2
- package/dist/loops.js +23 -5
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +4 -4
- package/dist/runtime.d.ts +138 -53
- package/dist/runtime.js +23 -5
- package/dist/workflow.js +1 -1
- package/package.json +3 -1
- package/dist/chunk-RLDUT4JL.js.map +0 -1
- /package/dist/{chunk-WFEQCRQP.js.map → chunk-4FEUFYOY.js.map} +0 -0
- /package/dist/{chunk-6BOIKGSU.js.map → chunk-IN7WHMGZ.js.map} +0 -0
- /package/dist/{chunk-TVBXDW7C.js.map → chunk-MMDIORZY.js.map} +0 -0
- /package/dist/{chunk-NJST5D2G.js.map → chunk-ZWGEA722.js.map} +0 -0
package/dist/agent.js
CHANGED
|
@@ -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");
|
|
@@ -3516,9 +3516,14 @@ async function createWorktree(options) {
|
|
|
3516
3516
|
}
|
|
3517
3517
|
async function captureWorktreeDiff(options) {
|
|
3518
3518
|
const baseRef = options.baseRef ?? options.worktree.baseSha;
|
|
3519
|
-
|
|
3519
|
+
await runGitAsync(["add", "-A"], options.worktree.path, options.runGit);
|
|
3520
|
+
const patch = await runGitAsync(
|
|
3521
|
+
["diff", "--cached", baseRef],
|
|
3522
|
+
options.worktree.path,
|
|
3523
|
+
options.runGit
|
|
3524
|
+
);
|
|
3520
3525
|
const shortstat = await runGitAsync(
|
|
3521
|
-
["diff", "--shortstat", baseRef],
|
|
3526
|
+
["diff", "--cached", "--shortstat", baseRef],
|
|
3522
3527
|
options.worktree.path,
|
|
3523
3528
|
options.runGit
|
|
3524
3529
|
);
|
|
@@ -3750,15 +3755,15 @@ var cliSeamKey = "cli";
|
|
|
3750
3755
|
var bridgeSeamKey = "bridge";
|
|
3751
3756
|
var cliWorktreeSeamKey = "cli-worktree";
|
|
3752
3757
|
function contentRef(prefix, value) {
|
|
3753
|
-
let
|
|
3758
|
+
let str2;
|
|
3754
3759
|
try {
|
|
3755
|
-
|
|
3760
|
+
str2 = JSON.stringify(value) ?? String(value);
|
|
3756
3761
|
} catch {
|
|
3757
|
-
|
|
3762
|
+
str2 = String(value);
|
|
3758
3763
|
}
|
|
3759
3764
|
let h = 2166136261;
|
|
3760
|
-
for (let i = 0; i <
|
|
3761
|
-
h ^=
|
|
3765
|
+
for (let i = 0; i < str2.length; i += 1) {
|
|
3766
|
+
h ^= str2.charCodeAt(i);
|
|
3762
3767
|
h = Math.imul(h, 16777619);
|
|
3763
3768
|
}
|
|
3764
3769
|
return `${prefix}:${(h >>> 0).toString(16).padStart(8, "0")}`;
|
|
@@ -4338,9 +4343,9 @@ function readSeam(ctx, key, who) {
|
|
|
4338
4343
|
function taskToPrompt(task) {
|
|
4339
4344
|
if (typeof task === "string") return task;
|
|
4340
4345
|
if (task && typeof task === "object") {
|
|
4341
|
-
const
|
|
4346
|
+
const obj2 = task;
|
|
4342
4347
|
for (const k of ["prompt", "content", "task", "message"]) {
|
|
4343
|
-
if (typeof
|
|
4348
|
+
if (typeof obj2[k] === "string") return obj2[k];
|
|
4344
4349
|
}
|
|
4345
4350
|
}
|
|
4346
4351
|
return JSON.stringify(task);
|
|
@@ -7038,12 +7043,12 @@ function createCoordinationTools(opts) {
|
|
|
7038
7043
|
bus.subscribe((rec) => cb(rec.event));
|
|
7039
7044
|
}
|
|
7040
7045
|
const urgencyPriority = (u) => u === "blocks-run" ? 20 : u === "blocks-step" ? 10 : 0;
|
|
7041
|
-
const
|
|
7046
|
+
const str2 = (v, field) => {
|
|
7042
7047
|
if (typeof v !== "string" || v.length === 0)
|
|
7043
7048
|
throw new Error(`coordination tools: "${field}" must be a non-empty string`);
|
|
7044
7049
|
return v;
|
|
7045
7050
|
};
|
|
7046
|
-
const
|
|
7051
|
+
const obj2 = (raw) => {
|
|
7047
7052
|
if (!raw || typeof raw !== "object")
|
|
7048
7053
|
throw new Error("coordination tools: arguments must be an object");
|
|
7049
7054
|
return raw;
|
|
@@ -7085,7 +7090,7 @@ function createCoordinationTools(opts) {
|
|
|
7085
7090
|
};
|
|
7086
7091
|
async function sendDown(type, down, questionId) {
|
|
7087
7092
|
await bus.publish(
|
|
7088
|
-
type === "answer" ? { type, down, questionId:
|
|
7093
|
+
type === "answer" ? { type, down, questionId: str2(questionId, "questionId") } : { type, down },
|
|
7089
7094
|
{ queue: false }
|
|
7090
7095
|
);
|
|
7091
7096
|
}
|
|
@@ -7108,13 +7113,13 @@ function createCoordinationTools(opts) {
|
|
|
7108
7113
|
};
|
|
7109
7114
|
const nextQuestionId = (from) => `${from}:q${questionSeq++}`;
|
|
7110
7115
|
const normalizeQuestion = (q, fallbackFrom) => {
|
|
7111
|
-
const from =
|
|
7116
|
+
const from = str2(q.from ?? fallbackFrom, "from");
|
|
7112
7117
|
return {
|
|
7113
7118
|
id: typeof q.id === "string" && q.id.length > 0 ? q.id : nextQuestionId(from),
|
|
7114
7119
|
from,
|
|
7115
7120
|
level: level(q.level),
|
|
7116
|
-
question:
|
|
7117
|
-
reason:
|
|
7121
|
+
question: str2(q.question, "question"),
|
|
7122
|
+
reason: str2(q.reason, "reason"),
|
|
7118
7123
|
...q.options ? { options: q.options } : {},
|
|
7119
7124
|
urgency: urgency(q.urgency)
|
|
7120
7125
|
};
|
|
@@ -7178,7 +7183,7 @@ function createCoordinationTools(opts) {
|
|
|
7178
7183
|
required: ["profile", "task"]
|
|
7179
7184
|
},
|
|
7180
7185
|
handler: (raw) => {
|
|
7181
|
-
const a =
|
|
7186
|
+
const a = obj2(raw);
|
|
7182
7187
|
const agent = opts.makeWorkerAgent(a.profile);
|
|
7183
7188
|
const res = opts.scope.spawn(agent, a.task, {
|
|
7184
7189
|
budget: opts.perWorker,
|
|
@@ -7192,7 +7197,7 @@ function createCoordinationTools(opts) {
|
|
|
7192
7197
|
description: "Inspect a worker status, spend, and settled output artifact when available.",
|
|
7193
7198
|
inputSchema: { type: "object", properties: { workerId: idArg }, required: ["workerId"] },
|
|
7194
7199
|
handler: async (raw) => {
|
|
7195
|
-
const id =
|
|
7200
|
+
const id = str2(obj2(raw).workerId, "workerId");
|
|
7196
7201
|
const node = opts.scope.view.nodes.find((n) => n.id === id);
|
|
7197
7202
|
if (!node) return { error: `unknown workerId ${JSON.stringify(id)}` };
|
|
7198
7203
|
const output = node.outRef ? await opts.blobs.get(node.outRef) : void 0;
|
|
@@ -7220,9 +7225,9 @@ function createCoordinationTools(opts) {
|
|
|
7220
7225
|
required: ["workerId", "instruction"]
|
|
7221
7226
|
},
|
|
7222
7227
|
handler: async (raw) => {
|
|
7223
|
-
const a =
|
|
7224
|
-
const workerId =
|
|
7225
|
-
const instruction =
|
|
7228
|
+
const a = obj2(raw);
|
|
7229
|
+
const workerId = str2(a.workerId, "workerId");
|
|
7230
|
+
const instruction = str2(a.instruction, "instruction");
|
|
7226
7231
|
const interrupt = a.interrupt === true;
|
|
7227
7232
|
const delivered = opts.scope.send(workerId, { steer: instruction, interrupt });
|
|
7228
7233
|
await sendDown("steer", { toWorker: workerId, instruction, delivered });
|
|
@@ -7243,7 +7248,7 @@ function createCoordinationTools(opts) {
|
|
|
7243
7248
|
}
|
|
7244
7249
|
},
|
|
7245
7250
|
handler: async (raw) => {
|
|
7246
|
-
const k =
|
|
7251
|
+
const k = obj2(raw).kinds;
|
|
7247
7252
|
const kinds = Array.isArray(k) ? k.filter((x) => x === "settled" || x === "question" || x === "finding") : void 0;
|
|
7248
7253
|
let ev = bus.pull(kinds);
|
|
7249
7254
|
if (!ev) {
|
|
@@ -7276,8 +7281,8 @@ function createCoordinationTools(opts) {
|
|
|
7276
7281
|
required: ["questionId"]
|
|
7277
7282
|
},
|
|
7278
7283
|
handler: async (raw) => {
|
|
7279
|
-
const a =
|
|
7280
|
-
const questionId =
|
|
7284
|
+
const a = obj2(raw);
|
|
7285
|
+
const questionId = str2(a.questionId, "questionId");
|
|
7281
7286
|
if (typeof a.answer === "string" && a.answer.length > 0) {
|
|
7282
7287
|
const answer = a.answer;
|
|
7283
7288
|
const question = decideQuestion(questionId, {
|
|
@@ -7330,15 +7335,15 @@ function createCoordinationTools(opts) {
|
|
|
7330
7335
|
required: ["from", "level", "question", "reason", "urgency"]
|
|
7331
7336
|
},
|
|
7332
7337
|
handler: async (raw) => {
|
|
7333
|
-
const a =
|
|
7334
|
-
const from =
|
|
7338
|
+
const a = obj2(raw);
|
|
7339
|
+
const from = str2(a.from, "from");
|
|
7335
7340
|
const q = await emitNewQuestion(
|
|
7336
7341
|
addQuestion(
|
|
7337
7342
|
{
|
|
7338
7343
|
from,
|
|
7339
7344
|
level: level(a.level),
|
|
7340
|
-
question:
|
|
7341
|
-
reason:
|
|
7345
|
+
question: str2(a.question, "question"),
|
|
7346
|
+
reason: str2(a.reason, "reason"),
|
|
7342
7347
|
urgency: urgency(a.urgency)
|
|
7343
7348
|
},
|
|
7344
7349
|
from,
|
|
@@ -7365,7 +7370,7 @@ function createCoordinationTools(opts) {
|
|
|
7365
7370
|
});
|
|
7366
7371
|
}
|
|
7367
7372
|
stopped = true;
|
|
7368
|
-
const r =
|
|
7373
|
+
const r = obj2(raw).reason;
|
|
7369
7374
|
reason = typeof r === "string" ? r : void 0;
|
|
7370
7375
|
return Promise.resolve({ stopped: true });
|
|
7371
7376
|
}
|
|
@@ -7390,14 +7395,14 @@ function createCoordinationTools(opts) {
|
|
|
7390
7395
|
required: ["kind", "workerId"]
|
|
7391
7396
|
},
|
|
7392
7397
|
handler: async (raw) => {
|
|
7393
|
-
const a =
|
|
7394
|
-
const id =
|
|
7398
|
+
const a = obj2(raw);
|
|
7399
|
+
const id = str2(a.workerId, "workerId");
|
|
7395
7400
|
const node = opts.scope.view.nodes.find((n) => n.id === id);
|
|
7396
7401
|
if (!node) return { error: `unknown workerId ${JSON.stringify(id)}` };
|
|
7397
7402
|
if (!node.outRef)
|
|
7398
7403
|
return { error: `worker ${JSON.stringify(id)} has not settled \u2014 no trace to analyze yet` };
|
|
7399
7404
|
const trace = await opts.blobs.get(node.outRef);
|
|
7400
|
-
return { findings: await opts.analysts?.run(
|
|
7405
|
+
return { findings: await opts.analysts?.run(str2(a.kind, "kind"), trace) };
|
|
7401
7406
|
}
|
|
7402
7407
|
});
|
|
7403
7408
|
}
|
|
@@ -8256,15 +8261,15 @@ function randomTaskId() {
|
|
|
8256
8261
|
return `dlg-${t}-${r}`;
|
|
8257
8262
|
}
|
|
8258
8263
|
function hashIdempotencyInput(value) {
|
|
8259
|
-
let
|
|
8264
|
+
let str2;
|
|
8260
8265
|
try {
|
|
8261
|
-
|
|
8266
|
+
str2 = JSON.stringify(canonicalize(value));
|
|
8262
8267
|
} catch {
|
|
8263
|
-
|
|
8268
|
+
str2 = String(value);
|
|
8264
8269
|
}
|
|
8265
8270
|
let h = 2166136261;
|
|
8266
|
-
for (let i = 0; i <
|
|
8267
|
-
h ^=
|
|
8271
|
+
for (let i = 0; i < str2.length; i += 1) {
|
|
8272
|
+
h ^= str2.charCodeAt(i);
|
|
8268
8273
|
h = Math.imul(h, 16777619);
|
|
8269
8274
|
}
|
|
8270
8275
|
return (h >>> 0).toString(16).padStart(8, "0");
|
|
@@ -9711,29 +9716,22 @@ import {
|
|
|
9711
9716
|
function defaultToolDetectors() {
|
|
9712
9717
|
return [repeatedActionDetector({ maxRepeated: 3 }), errorStreakDetector({ maxErrors: 3 })];
|
|
9713
9718
|
}
|
|
9714
|
-
function
|
|
9719
|
+
function watchTrace(source, opts = {}) {
|
|
9715
9720
|
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();
|
|
9721
|
+
return source.onSpan((span) => {
|
|
9722
|
+
let fingerprint;
|
|
9723
|
+
try {
|
|
9724
|
+
fingerprint = `${span.toolName}|${argHash(span.args)}`;
|
|
9725
|
+
} catch {
|
|
9726
|
+
fingerprint = `${span.toolName}|<unhashable>`;
|
|
9735
9727
|
}
|
|
9736
|
-
|
|
9728
|
+
const signals = observeAll(detectors, {
|
|
9729
|
+
actionFingerprint: fingerprint,
|
|
9730
|
+
...span.status ? { status: span.status } : {},
|
|
9731
|
+
label: span.toolName
|
|
9732
|
+
});
|
|
9733
|
+
for (const s of signals) void opts.onSignal?.(s, span);
|
|
9734
|
+
});
|
|
9737
9735
|
}
|
|
9738
9736
|
|
|
9739
9737
|
// src/runtime/supervise/router-driver-chat.ts
|
|
@@ -9790,46 +9788,199 @@ function safeParse(s) {
|
|
|
9790
9788
|
}
|
|
9791
9789
|
}
|
|
9792
9790
|
|
|
9793
|
-
// src/runtime/supervise/
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
|
|
9797
|
-
|
|
9791
|
+
// src/runtime/supervise/trace-source.ts
|
|
9792
|
+
function toToolSpan(input, runId, seq, at) {
|
|
9793
|
+
return {
|
|
9794
|
+
spanId: `${runId}-t${seq}`,
|
|
9795
|
+
runId,
|
|
9796
|
+
kind: "tool",
|
|
9797
|
+
name: input.toolName,
|
|
9798
|
+
toolName: input.toolName,
|
|
9799
|
+
args: input.args,
|
|
9800
|
+
status: input.status ?? "ok",
|
|
9801
|
+
startedAt: at,
|
|
9802
|
+
endedAt: at,
|
|
9803
|
+
...input.result !== void 0 ? { result: input.result } : {}
|
|
9804
|
+
};
|
|
9805
|
+
}
|
|
9806
|
+
var obj = (v) => v && typeof v === "object" ? v : void 0;
|
|
9807
|
+
var str = (v) => typeof v === "string" && v ? v : void 0;
|
|
9808
|
+
var decodeOpencodePart = (raw) => {
|
|
9809
|
+
if (str(raw.type)?.toLowerCase() !== "tool" || !str(raw.tool)) return void 0;
|
|
9810
|
+
const part = raw;
|
|
9811
|
+
const state = obj(part.state);
|
|
9812
|
+
const status = state?.status;
|
|
9813
|
+
if (!status || status === "pending" || status === "running") return void 0;
|
|
9814
|
+
return {
|
|
9815
|
+
toolName: part.tool,
|
|
9816
|
+
args: state?.input ?? {},
|
|
9817
|
+
// ToolStateError carries 'error' OR 'failed' — the reverse-engineered decoder missed 'failed'.
|
|
9818
|
+
status: status === "error" || status === "failed" ? "error" : "ok",
|
|
9819
|
+
...str(part.callID) ? { callId: part.callID } : {}
|
|
9820
|
+
};
|
|
9821
|
+
};
|
|
9822
|
+
var decodeAnthropicPart = (p) => {
|
|
9823
|
+
if (str(p.type)?.toLowerCase() !== "tool_use") return void 0;
|
|
9824
|
+
const name = str(p.name) ?? str(p.tool);
|
|
9825
|
+
if (!name) return void 0;
|
|
9826
|
+
const id = str(p.id) ?? str(p.tool_use_id);
|
|
9827
|
+
return {
|
|
9828
|
+
toolName: name,
|
|
9829
|
+
args: p.input ?? {},
|
|
9830
|
+
...id ? { callId: id } : {}
|
|
9831
|
+
};
|
|
9832
|
+
};
|
|
9833
|
+
var decodeOpenAiPart = (p) => {
|
|
9834
|
+
const type = str(p.type)?.toLowerCase();
|
|
9835
|
+
const fn = obj(p.function);
|
|
9836
|
+
if (type !== "function" && type !== "tool_call") return void 0;
|
|
9837
|
+
const name = str(fn?.name) ?? str(p.name);
|
|
9838
|
+
if (!name) return void 0;
|
|
9839
|
+
const rawArgs = fn?.arguments ?? p.arguments;
|
|
9840
|
+
return {
|
|
9841
|
+
toolName: name,
|
|
9842
|
+
args: typeof rawArgs === "string" ? safeParse2(rawArgs) : rawArgs ?? {},
|
|
9843
|
+
...str(p.id) ? { callId: p.id } : str(fn?.id) ? { callId: fn?.id } : {}
|
|
9844
|
+
};
|
|
9845
|
+
};
|
|
9846
|
+
var toolPartDecoders = {
|
|
9847
|
+
opencode: decodeOpencodePart,
|
|
9848
|
+
"claude-code": decodeAnthropicPart,
|
|
9849
|
+
anthropic: decodeAnthropicPart,
|
|
9850
|
+
codex: decodeOpenAiPart,
|
|
9851
|
+
openai: decodeOpenAiPart,
|
|
9852
|
+
router: decodeOpenAiPart,
|
|
9853
|
+
kimi: decodeOpenAiPart
|
|
9854
|
+
};
|
|
9855
|
+
function decodeToolPart(part, harness) {
|
|
9856
|
+
const p = obj(part);
|
|
9857
|
+
if (!p) return void 0;
|
|
9858
|
+
const specific = harness ? toolPartDecoders[harness] : void 0;
|
|
9859
|
+
if (specific) return specific(p);
|
|
9860
|
+
for (const decode of new Set(Object.values(toolPartDecoders))) {
|
|
9861
|
+
const step = decode(p);
|
|
9862
|
+
if (step) return step;
|
|
9863
|
+
}
|
|
9864
|
+
return void 0;
|
|
9865
|
+
}
|
|
9866
|
+
function safeParse2(s) {
|
|
9867
|
+
try {
|
|
9868
|
+
return JSON.parse(s);
|
|
9869
|
+
} catch {
|
|
9870
|
+
return s;
|
|
9871
|
+
}
|
|
9872
|
+
}
|
|
9873
|
+
var runSeq = 0;
|
|
9874
|
+
function createPushTraceSource(opts = {}) {
|
|
9875
|
+
const runId = opts.runId ?? `push-${runSeq++}`;
|
|
9876
|
+
const now = opts.now ?? Date.now;
|
|
9877
|
+
const spans = [];
|
|
9878
|
+
const subs = /* @__PURE__ */ new Set();
|
|
9798
9879
|
return {
|
|
9799
|
-
|
|
9800
|
-
|
|
9880
|
+
record(input) {
|
|
9881
|
+
const span = toToolSpan(input, runId, spans.length, now());
|
|
9882
|
+
spans.push(span);
|
|
9883
|
+
for (const fn of subs) {
|
|
9884
|
+
try {
|
|
9885
|
+
fn(span);
|
|
9886
|
+
} catch {
|
|
9887
|
+
}
|
|
9888
|
+
}
|
|
9889
|
+
return span;
|
|
9801
9890
|
},
|
|
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
|
-
|
|
9891
|
+
source: {
|
|
9892
|
+
onSpan(handler) {
|
|
9893
|
+
subs.add(handler);
|
|
9894
|
+
return () => subs.delete(handler);
|
|
9895
|
+
},
|
|
9896
|
+
collect: () => Promise.resolve([...spans])
|
|
9897
|
+
}
|
|
9898
|
+
};
|
|
9899
|
+
}
|
|
9900
|
+
function createPartsTraceSource(opts) {
|
|
9901
|
+
const runId = opts.runId ?? `parts-${runSeq++}`;
|
|
9902
|
+
const now = opts.now ?? Date.now;
|
|
9903
|
+
const subs = /* @__PURE__ */ new Set();
|
|
9904
|
+
const seenLive = /* @__PURE__ */ new Set();
|
|
9905
|
+
let liveSeq = 0;
|
|
9906
|
+
let unsub;
|
|
9907
|
+
const startLive = () => {
|
|
9908
|
+
if (unsub || !opts.subscribeParts) return;
|
|
9909
|
+
unsub = opts.subscribeParts((part) => {
|
|
9910
|
+
const step = decodeToolPart(part, opts.harness);
|
|
9911
|
+
if (!step) return;
|
|
9912
|
+
if (step.callId) {
|
|
9913
|
+
if (seenLive.has(step.callId)) return;
|
|
9914
|
+
seenLive.add(step.callId);
|
|
9915
|
+
}
|
|
9916
|
+
const span = toToolSpan(step, runId, liveSeq++, now());
|
|
9917
|
+
for (const fn of subs) {
|
|
9918
|
+
try {
|
|
9919
|
+
fn(span);
|
|
9920
|
+
} catch {
|
|
9921
|
+
}
|
|
9922
|
+
}
|
|
9923
|
+
});
|
|
9924
|
+
};
|
|
9925
|
+
return {
|
|
9926
|
+
onSpan(handler) {
|
|
9927
|
+
subs.add(handler);
|
|
9928
|
+
startLive();
|
|
9929
|
+
return () => {
|
|
9930
|
+
subs.delete(handler);
|
|
9931
|
+
if (subs.size === 0 && unsub) {
|
|
9932
|
+
unsub();
|
|
9933
|
+
unsub = void 0;
|
|
9934
|
+
}
|
|
9935
|
+
};
|
|
9827
9936
|
},
|
|
9828
|
-
|
|
9829
|
-
|
|
9937
|
+
async collect() {
|
|
9938
|
+
const parts = await opts.collectParts();
|
|
9939
|
+
const spans = [];
|
|
9940
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9941
|
+
for (const part of parts) {
|
|
9942
|
+
const step = decodeToolPart(part, opts.harness);
|
|
9943
|
+
if (!step) continue;
|
|
9944
|
+
if (step.callId) {
|
|
9945
|
+
if (seen.has(step.callId)) continue;
|
|
9946
|
+
seen.add(step.callId);
|
|
9947
|
+
}
|
|
9948
|
+
spans.push(toToolSpan(step, runId, spans.length, now()));
|
|
9949
|
+
}
|
|
9950
|
+
return spans;
|
|
9830
9951
|
}
|
|
9831
9952
|
};
|
|
9832
9953
|
}
|
|
9954
|
+
function sandboxSessionTraceSource(box, sessionId, opts = {}) {
|
|
9955
|
+
return createPartsTraceSource({
|
|
9956
|
+
collectParts: async () => {
|
|
9957
|
+
const msgs = await box.messages({ sessionId });
|
|
9958
|
+
return msgs.flatMap((m) => m.parts ? [...m.parts] : []);
|
|
9959
|
+
},
|
|
9960
|
+
...opts.harness ? { harness: opts.harness } : {},
|
|
9961
|
+
...opts.subscribeParts ? { subscribeParts: opts.subscribeParts } : {},
|
|
9962
|
+
runId: opts.runId ?? `box-${sessionId}`,
|
|
9963
|
+
...opts.now ? { now: opts.now } : {}
|
|
9964
|
+
});
|
|
9965
|
+
}
|
|
9966
|
+
|
|
9967
|
+
// src/runtime/supervise/trajectory-recorder.ts
|
|
9968
|
+
import { buildTrajectory, InMemoryTraceStore } from "@tangle-network/agent-eval";
|
|
9969
|
+
import { stuckLoopView, toolWasteView } from "@tangle-network/agent-eval/pipelines";
|
|
9970
|
+
async function analyzeTrace(source, runId = "worker") {
|
|
9971
|
+
const spans = await source.collect();
|
|
9972
|
+
const store = new InMemoryTraceStore();
|
|
9973
|
+
for (let i = 0; i < spans.length; i += 1) {
|
|
9974
|
+
const s = spans[i];
|
|
9975
|
+
if (s) await store.appendSpan({ ...s, runId, spanId: `${runId}-t${i}` });
|
|
9976
|
+
}
|
|
9977
|
+
const [trajectory, stuckLoop, toolWaste] = await Promise.all([
|
|
9978
|
+
buildTrajectory(store, runId),
|
|
9979
|
+
stuckLoopView(store, { runId }),
|
|
9980
|
+
toolWasteView(store, { runId })
|
|
9981
|
+
]);
|
|
9982
|
+
return { trajectory, stuckLoop, toolWaste };
|
|
9983
|
+
}
|
|
9833
9984
|
|
|
9834
9985
|
// src/runtime/verifier-environment.ts
|
|
9835
9986
|
var submitTool = {
|
|
@@ -10279,9 +10430,18 @@ export {
|
|
|
10279
10430
|
createInProcessTransport,
|
|
10280
10431
|
serveCoordinationMcp,
|
|
10281
10432
|
defaultToolDetectors,
|
|
10282
|
-
|
|
10433
|
+
watchTrace,
|
|
10283
10434
|
routerDriverChat,
|
|
10284
|
-
|
|
10435
|
+
toToolSpan,
|
|
10436
|
+
decodeOpencodePart,
|
|
10437
|
+
decodeAnthropicPart,
|
|
10438
|
+
decodeOpenAiPart,
|
|
10439
|
+
toolPartDecoders,
|
|
10440
|
+
decodeToolPart,
|
|
10441
|
+
createPushTraceSource,
|
|
10442
|
+
createPartsTraceSource,
|
|
10443
|
+
sandboxSessionTraceSource,
|
|
10444
|
+
analyzeTrace,
|
|
10285
10445
|
createVerifierEnvironment,
|
|
10286
10446
|
createWaterfallCollector,
|
|
10287
10447
|
localShell,
|
|
@@ -10289,4 +10449,4 @@ export {
|
|
|
10289
10449
|
jjWorkspace,
|
|
10290
10450
|
runInWorkspace
|
|
10291
10451
|
};
|
|
10292
|
-
//# sourceMappingURL=chunk-
|
|
10452
|
+
//# sourceMappingURL=chunk-45D64J7B.js.map
|