@tangle-network/agent-runtime 0.338.0 → 0.340.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/{activation-kbkAuSmY.js → activation-D2PVljaw.js} +5 -18
- package/dist/{activation-kbkAuSmY.js.map → activation-D2PVljaw.js.map} +1 -1
- package/dist/{activation-CsbNax2X.d.ts → activation-DGDl4wwI.d.ts} +4 -24
- package/dist/agent.d.ts +4 -18
- package/dist/agent.js +3 -21
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +2 -2
- package/dist/{bundle-DM60AI2B.js → bundle-DNUq-OPW.js} +2 -2
- package/dist/{bundle-DM60AI2B.js.map → bundle-DNUq-OPW.js.map} +1 -1
- package/dist/candidate-execution/index.d.ts +4 -101
- package/dist/candidate-execution/index.js +10 -395
- package/dist/candidate-execution/index.js.map +1 -1
- package/dist/{delegate-Se1YZKMb.js → delegate-CtJIS-tp.js} +2 -2
- package/dist/{delegate-Se1YZKMb.js.map → delegate-CtJIS-tp.js.map} +1 -1
- package/dist/{driver-control-acknowledgers-T2a1Ouay.js → driver-control-acknowledgers-MTrs8HAF.js} +15 -11
- package/dist/driver-control-acknowledgers-MTrs8HAF.js.map +1 -0
- package/dist/{durable-file-B_eJr6Mb.js → durable-file-gNI9ILAn.js} +1 -3
- package/dist/durable-file-gNI9ILAn.js.map +1 -0
- package/dist/durable.d.ts +3 -35
- package/dist/durable.js +10 -10
- package/dist/durable.js.map +1 -1
- package/dist/{graph-CY0wH838.js → graph-DfWqp_1e.js} +4 -4
- package/dist/graph-DfWqp_1e.js.map +1 -0
- package/dist/{graph-registry-By0tUj4S.js → graph-registry-BnO64cn8.js} +3 -3
- package/dist/{graph-registry-By0tUj4S.js.map → graph-registry-BnO64cn8.js.map} +1 -1
- package/dist/{improve-CWGBT13K.js → improve-CKRVQqzt.js} +8 -35
- package/dist/improve-CKRVQqzt.js.map +1 -0
- package/dist/{improvement-adapter-D5gwwoXQ.d.ts → improvement-adapter-sIthWkcN.d.ts} +3 -21
- package/dist/index.d.ts +10 -215
- package/dist/index.js +91 -302
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +11 -143
- package/dist/intelligence.js +7 -81
- package/dist/intelligence.js.map +1 -1
- package/dist/{jsonl-file-DBv31uPi.js → jsonl-file-C9Kde_0Z.js} +2 -2
- package/dist/{jsonl-file-DBv31uPi.js.map → jsonl-file-C9Kde_0Z.js.map} +1 -1
- package/dist/kernel.d.ts +4 -3
- package/dist/kernel.js +12 -14
- package/dist/loop-runner-C4EWEcXf.d.ts +32 -0
- package/dist/loop-runner-DNWbTcVm.js +59 -0
- package/dist/loop-runner-DNWbTcVm.js.map +1 -0
- package/dist/loop-runner-bin.d.ts +32 -2
- package/dist/loop-runner-bin.js +93 -1
- package/dist/loop-runner-bin.js.map +1 -0
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +99 -418
- package/dist/mcp/index.js +121 -203
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/memory-bin.js +231 -1
- package/dist/mcp/memory-bin.js.map +1 -1
- package/dist/model-policy-CyCUwHed.js.map +1 -1
- package/dist/placement.d.ts +2 -33
- package/dist/placement.js +1 -35
- package/dist/placement.js.map +1 -1
- package/dist/platform.d.ts +188 -1
- package/dist/platform.js +129 -1
- package/dist/platform.js.map +1 -1
- package/dist/{prepare-Bt0IouPq.js → prepare-FzJoS68l.js} +8 -160
- package/dist/prepare-FzJoS68l.js.map +1 -0
- package/dist/{profile-Do-5xO_D.js → profile-DToH0XEs.js} +2 -2
- package/dist/profile-DToH0XEs.js.map +1 -0
- package/dist/profile-materialization-bPm0gGLO.d.ts +49 -0
- package/dist/profiles.d.ts +2 -2
- package/dist/profiles.js +3 -40
- package/dist/profiles.js.map +1 -1
- package/dist/{protected-model-port-DGxQ8_YM.d.ts → protected-model-port-DVVh-hEk.d.ts} +3 -33
- package/dist/protected-redaction-DFCeo4vg.js.map +1 -1
- package/dist/{provision-supervisor-0jMufp4h.js → provision-supervisor-DqvWXmAE.js} +6 -6
- package/dist/{provision-supervisor-0jMufp4h.js.map → provision-supervisor-DqvWXmAE.js.map} +1 -1
- package/dist/{run-cancellation-BoW5Sg9Y.js → run-cancellation-C9oL62sW.js} +3 -7
- package/dist/{run-cancellation-BoW5Sg9Y.js.map → run-cancellation-C9oL62sW.js.map} +1 -1
- package/dist/{runtime-D37zRSs7.js → runtime-C55Zgo1R.js} +2531 -2889
- package/dist/runtime-C55Zgo1R.js.map +1 -0
- package/dist/{runtime-hooks-Bj6wJHlH.d.ts → runtime-hooks-nsqxSUFL.d.ts} +2 -6
- package/dist/{sandbox-profile-compat-xSoVtdWw.js → sandbox-profile-compat-DRr3JwDx.js} +2 -4
- package/dist/sandbox-profile-compat-DRr3JwDx.js.map +1 -0
- package/dist/{search-executor-DmgUm5p7.js → search-executor-ChOlRBgg.js} +3 -3
- package/dist/search-executor-ChOlRBgg.js.map +1 -0
- package/dist/{server-DQHJszfk.js → server-DkVBSN_S.js} +362 -67
- package/dist/server-DkVBSN_S.js.map +1 -0
- package/dist/{structural-rollout-DAvIE8mw.js → structural-rollout-C1LEk_zq.js} +80 -80
- package/dist/structural-rollout-C1LEk_zq.js.map +1 -0
- package/dist/{substrate-B0TYNrXn.js → substrate-CGDFTSRh.js} +2 -9
- package/dist/substrate-CGDFTSRh.js.map +1 -0
- package/dist/{supervise-WuPAwfPh.js → supervise-CaUAxZZP.js} +92 -75
- package/dist/supervise-CaUAxZZP.js.map +1 -0
- package/dist/{supervisor-CPG1I9UN.js → supervisor-VXuN2OHT.js} +205 -319
- package/dist/supervisor-VXuN2OHT.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +13 -13
- package/dist/testing.js.map +1 -1
- package/dist/tool-loop.d.ts +1 -1
- package/dist/{tool-server-Dqer2M4_.js → tool-server-XV4aJwoQ.js} +2 -2
- package/dist/tool-server-XV4aJwoQ.js.map +1 -0
- package/dist/top-snapshot-CbZE1JsU.js +502 -0
- package/dist/top-snapshot-CbZE1JsU.js.map +1 -0
- package/dist/tui/bin.js +711 -1
- package/dist/tui/bin.js.map +1 -1
- package/dist/tui/index.d.ts +2 -70
- package/dist/tui/index.js +3 -3
- package/dist/{types-zWfqDjeL.d.ts → types-Cwrea-bU.d.ts} +2 -17
- package/dist/{types-CrNWif8-.d.ts → types-DZ6L0Bv3.d.ts} +765 -2152
- package/dist/workspace-store/index.d.ts +1 -107
- package/dist/workspace-store/index.js +1 -415
- package/dist/workspace-store/index.js.map +1 -1
- package/dist/{workspace-streams-BZZds1Fw.d.ts → workspace-streams-BiS4ABah.d.ts} +3 -18
- package/package.json +1 -1
- package/skills/agent-graphs/references/authoring.md +3 -2
- package/dist/coder-yhVWbdWc.js +0 -40
- package/dist/coder-yhVWbdWc.js.map +0 -1
- package/dist/delegation-status-CF4D0NZ_.js +0 -358
- package/dist/delegation-status-CF4D0NZ_.js.map +0 -1
- package/dist/driver-control-acknowledgers-T2a1Ouay.js.map +0 -1
- package/dist/durable-file-B_eJr6Mb.js.map +0 -1
- package/dist/graph-CY0wH838.js.map +0 -1
- package/dist/improve-CWGBT13K.js.map +0 -1
- package/dist/integrations-6xttbPi9.d.ts +0 -190
- package/dist/integrations-dFi-ALk7.js +0 -132
- package/dist/integrations-dFi-ALk7.js.map +0 -1
- package/dist/kb-gate-C8z2juK8.d.ts +0 -80
- package/dist/kb-gate-DpaSwXVx.js +0 -80
- package/dist/kb-gate-DpaSwXVx.js.map +0 -1
- package/dist/loop-runner-bin-CFnrAHpl.d.ts +0 -164
- package/dist/loop-runner-bin-CdPlhy9g.js +0 -246
- package/dist/loop-runner-bin-CdPlhy9g.js.map +0 -1
- package/dist/memory-server-DXQ8IxGR.js +0 -234
- package/dist/memory-server-DXQ8IxGR.js.map +0 -1
- package/dist/openai-tools-DoQ32vpe.js +0 -44
- package/dist/openai-tools-DoQ32vpe.js.map +0 -1
- package/dist/openai-tools-zh2I_uD7.d.ts +0 -24
- package/dist/prepare-Bt0IouPq.js.map +0 -1
- package/dist/profile-Do-5xO_D.js.map +0 -1
- package/dist/profile-materialization-BnoEf1co.d.ts +0 -96
- package/dist/runtime-D37zRSs7.js.map +0 -1
- package/dist/sandbox-profile-compat-xSoVtdWw.js.map +0 -1
- package/dist/search-executor-DmgUm5p7.js.map +0 -1
- package/dist/server-DQHJszfk.js.map +0 -1
- package/dist/structural-rollout-DAvIE8mw.js.map +0 -1
- package/dist/substrate-B0TYNrXn.js.map +0 -1
- package/dist/supervise-WuPAwfPh.js.map +0 -1
- package/dist/supervisor-CPG1I9UN.js.map +0 -1
- package/dist/tool-server-Dqer2M4_.js.map +0 -1
- package/dist/top-app-C55Wa7uy.js +0 -1214
- package/dist/top-app-C55Wa7uy.js.map +0 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { m as ValidationError, t as AgentEvalError } from "./errors-DodWX-cb.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { n as delegate } from "./delegate-
|
|
6
|
-
import {
|
|
7
|
-
import { n as UI_LENSES } from "./substrate-B0TYNrXn.js";
|
|
1
|
+
import { an as buildLoopSpanNodes } from "./supervisor-VXuN2OHT.js";
|
|
2
|
+
import { m as ValidationError, o as NotFoundError, t as AgentEvalError } from "./errors-DodWX-cb.js";
|
|
3
|
+
import { X as errorMessage, Z as fnv1a32Hex } from "./sandbox-profile-compat-DRr3JwDx.js";
|
|
4
|
+
import { n as createStdioToolServer } from "./tool-server-XV4aJwoQ.js";
|
|
5
|
+
import { n as delegate } from "./delegate-CtJIS-tp.js";
|
|
6
|
+
import { t as UI_LENSES } from "./substrate-CGDFTSRh.js";
|
|
8
7
|
import path, { dirname } from "node:path";
|
|
9
8
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
10
|
-
import
|
|
9
|
+
import "node:stream";
|
|
11
10
|
//#region src/mcp/delegation-trace.ts
|
|
12
11
|
/**
|
|
13
12
|
*
|
|
@@ -60,8 +59,8 @@ function buildDelegationTraceSpans(events) {
|
|
|
60
59
|
* @experimental
|
|
61
60
|
*/
|
|
62
61
|
function capDelegationTrace(spans, caps) {
|
|
63
|
-
const maxSpans = caps?.maxSpans ??
|
|
64
|
-
const maxBytes = caps?.maxBytes ??
|
|
62
|
+
const maxSpans = caps?.maxSpans ?? DELEGATION_TRACE_MAX_SPANS;
|
|
63
|
+
const maxBytes = caps?.maxBytes ?? DELEGATION_TRACE_MAX_BYTES;
|
|
65
64
|
let start = Math.max(0, spans.length - maxSpans);
|
|
66
65
|
const sizes = spans.map((span) => JSON.stringify(span).length + 1);
|
|
67
66
|
let total = 0;
|
|
@@ -306,6 +305,38 @@ function cloneRecord(record) {
|
|
|
306
305
|
return structuredClone(record);
|
|
307
306
|
}
|
|
308
307
|
//#endregion
|
|
308
|
+
//#region src/mcp/feedback-store.ts
|
|
309
|
+
/** In-memory `FeedbackStore` — suitable for single-process use and tests. @stable */
|
|
310
|
+
var InMemoryFeedbackStore = class {
|
|
311
|
+
events = [];
|
|
312
|
+
async put(event) {
|
|
313
|
+
this.events.push({ ...event });
|
|
314
|
+
}
|
|
315
|
+
async list(filter = {}) {
|
|
316
|
+
let out = this.events;
|
|
317
|
+
if (filter.namespace !== void 0) out = out.filter((event) => event.namespace === filter.namespace);
|
|
318
|
+
if (filter.refersToRef !== void 0) out = out.filter((event) => event.refersTo.ref === filter.refersToRef);
|
|
319
|
+
return out.map((event) => ({ ...event }));
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Project a `FeedbackEvent` down to the snapshot shape carried on
|
|
324
|
+
* `delegation_history` entries.
|
|
325
|
+
*
|
|
326
|
+
* @stable
|
|
327
|
+
*/
|
|
328
|
+
function eventToSnapshot(event) {
|
|
329
|
+
const snap = {
|
|
330
|
+
id: event.id,
|
|
331
|
+
score: event.rating.score,
|
|
332
|
+
by: event.by,
|
|
333
|
+
notes: event.rating.notes,
|
|
334
|
+
capturedAt: event.capturedAt
|
|
335
|
+
};
|
|
336
|
+
if (event.rating.label) snap.label = event.rating.label;
|
|
337
|
+
return snap;
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
309
340
|
//#region src/mcp/task-queue.ts
|
|
310
341
|
/**
|
|
311
342
|
*
|
|
@@ -917,6 +948,169 @@ function createDelegateHandler(options) {
|
|
|
917
948
|
};
|
|
918
949
|
}
|
|
919
950
|
//#endregion
|
|
951
|
+
//#region src/mcp/tools/delegate-feedback.ts
|
|
952
|
+
/** MCP tool name for the `delegate_feedback` feedback-recording tool. @stable */
|
|
953
|
+
const DELEGATE_FEEDBACK_TOOL_NAME = "delegate_feedback";
|
|
954
|
+
/** Human-readable description of the `delegate_feedback` MCP tool, injected into the tool manifest. @stable */
|
|
955
|
+
const DELEGATE_FEEDBACK_DESCRIPTION = [
|
|
956
|
+
"Record feedback on a delegation, artifact, or outcome. Synchronous — the",
|
|
957
|
+
"event is durably stored when this call returns.",
|
|
958
|
+
"",
|
|
959
|
+
"Use when: you (the agent), the user, or a downstream judge has formed an",
|
|
960
|
+
"opinion about a piece of work and want it persisted for calibration,",
|
|
961
|
+
"pricing, or future routing. Every call is a new event — multiple ratings",
|
|
962
|
+
"on the same target are expected and never deduped.",
|
|
963
|
+
"",
|
|
964
|
+
"`refersTo.kind`:",
|
|
965
|
+
" - \"delegation\": ref is a taskId returned by delegate_ui_audit",
|
|
966
|
+
" - \"artifact\": ref is a URI/path/git-sha — anything you can dereference",
|
|
967
|
+
" - \"outcome\": ref is a free-form description of a downstream result",
|
|
968
|
+
"",
|
|
969
|
+
"`by`:",
|
|
970
|
+
" - \"agent\": the agent itself rated the work",
|
|
971
|
+
" - \"user\": the human user rated it",
|
|
972
|
+
" - \"downstream-judge\": an automated evaluator emitted the rating",
|
|
973
|
+
"",
|
|
974
|
+
"When ref names a known taskId, the rating is also attached to the",
|
|
975
|
+
"delegation record so delegation_history surfaces it inline."
|
|
976
|
+
].join("\n");
|
|
977
|
+
/** JSON Schema for `delegate_feedback` tool arguments (`refersTo`, `rating`, `by`, optional fields). @stable */
|
|
978
|
+
const DELEGATE_FEEDBACK_INPUT_SCHEMA = {
|
|
979
|
+
type: "object",
|
|
980
|
+
properties: {
|
|
981
|
+
refersTo: {
|
|
982
|
+
type: "object",
|
|
983
|
+
properties: {
|
|
984
|
+
kind: {
|
|
985
|
+
type: "string",
|
|
986
|
+
enum: [
|
|
987
|
+
"delegation",
|
|
988
|
+
"artifact",
|
|
989
|
+
"outcome"
|
|
990
|
+
]
|
|
991
|
+
},
|
|
992
|
+
ref: { type: "string" }
|
|
993
|
+
},
|
|
994
|
+
required: ["kind", "ref"],
|
|
995
|
+
additionalProperties: false
|
|
996
|
+
},
|
|
997
|
+
rating: {
|
|
998
|
+
type: "object",
|
|
999
|
+
properties: {
|
|
1000
|
+
score: {
|
|
1001
|
+
type: "number",
|
|
1002
|
+
minimum: 0,
|
|
1003
|
+
maximum: 1
|
|
1004
|
+
},
|
|
1005
|
+
label: {
|
|
1006
|
+
type: "string",
|
|
1007
|
+
enum: [
|
|
1008
|
+
"good",
|
|
1009
|
+
"bad",
|
|
1010
|
+
"neutral",
|
|
1011
|
+
"mixed"
|
|
1012
|
+
]
|
|
1013
|
+
},
|
|
1014
|
+
notes: { type: "string" }
|
|
1015
|
+
},
|
|
1016
|
+
required: ["score", "notes"],
|
|
1017
|
+
additionalProperties: false
|
|
1018
|
+
},
|
|
1019
|
+
by: {
|
|
1020
|
+
type: "string",
|
|
1021
|
+
enum: [
|
|
1022
|
+
"agent",
|
|
1023
|
+
"user",
|
|
1024
|
+
"downstream-judge"
|
|
1025
|
+
]
|
|
1026
|
+
},
|
|
1027
|
+
capturedAt: { type: "string" },
|
|
1028
|
+
namespace: { type: "string" }
|
|
1029
|
+
},
|
|
1030
|
+
required: [
|
|
1031
|
+
"refersTo",
|
|
1032
|
+
"rating",
|
|
1033
|
+
"by"
|
|
1034
|
+
],
|
|
1035
|
+
additionalProperties: false
|
|
1036
|
+
};
|
|
1037
|
+
/** Parse and validate raw MCP tool input into typed `DelegateFeedbackArgs`; throws `TypeError` on bad input. @stable */
|
|
1038
|
+
function validateDelegateFeedbackArgs(raw) {
|
|
1039
|
+
if (raw === null || typeof raw !== "object") throw new TypeError("delegate_feedback: arguments must be an object");
|
|
1040
|
+
const value = raw;
|
|
1041
|
+
const refersTo = validateRefersTo(value.refersTo);
|
|
1042
|
+
const rating = validateRating(value.rating);
|
|
1043
|
+
const by = value.by;
|
|
1044
|
+
if (by !== "agent" && by !== "user" && by !== "downstream-judge") throw new TypeError("delegate_feedback: `by` must be one of \"agent\" | \"user\" | \"downstream-judge\"");
|
|
1045
|
+
const args = {
|
|
1046
|
+
refersTo,
|
|
1047
|
+
rating,
|
|
1048
|
+
by
|
|
1049
|
+
};
|
|
1050
|
+
if (value.capturedAt !== void 0) {
|
|
1051
|
+
if (typeof value.capturedAt !== "string" || Number.isNaN(Date.parse(value.capturedAt))) throw new TypeError("delegate_feedback: `capturedAt` must be an ISO datetime");
|
|
1052
|
+
args.capturedAt = value.capturedAt;
|
|
1053
|
+
}
|
|
1054
|
+
if (typeof value.namespace === "string") args.namespace = value.namespace;
|
|
1055
|
+
return args;
|
|
1056
|
+
}
|
|
1057
|
+
function validateRefersTo(raw) {
|
|
1058
|
+
if (raw === null || typeof raw !== "object") throw new TypeError("delegate_feedback: `refersTo` must be an object");
|
|
1059
|
+
const value = raw;
|
|
1060
|
+
const kind = value.kind;
|
|
1061
|
+
if (kind !== "delegation" && kind !== "artifact" && kind !== "outcome") throw new TypeError("delegate_feedback: `refersTo.kind` must be one of \"delegation\" | \"artifact\" | \"outcome\"");
|
|
1062
|
+
const ref = value.ref;
|
|
1063
|
+
if (typeof ref !== "string" || ref.trim().length === 0) throw new TypeError("delegate_feedback: `refersTo.ref` must be a non-empty string");
|
|
1064
|
+
return {
|
|
1065
|
+
kind,
|
|
1066
|
+
ref: ref.trim()
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
function validateRating(raw) {
|
|
1070
|
+
if (raw === null || typeof raw !== "object") throw new TypeError("delegate_feedback: `rating` must be an object");
|
|
1071
|
+
const value = raw;
|
|
1072
|
+
const score = Number(value.score);
|
|
1073
|
+
if (!Number.isFinite(score) || score < 0 || score > 1) throw new RangeError("delegate_feedback: `rating.score` must be a number in [0, 1]");
|
|
1074
|
+
const notes = value.notes;
|
|
1075
|
+
if (typeof notes !== "string") throw new TypeError("delegate_feedback: `rating.notes` must be a string");
|
|
1076
|
+
const rating = {
|
|
1077
|
+
score,
|
|
1078
|
+
notes
|
|
1079
|
+
};
|
|
1080
|
+
const label = value.label;
|
|
1081
|
+
if (label !== void 0) {
|
|
1082
|
+
if (label !== "good" && label !== "bad" && label !== "neutral" && label !== "mixed") throw new TypeError("delegate_feedback: `rating.label` must be one of \"good\" | \"bad\" | \"neutral\" | \"mixed\"");
|
|
1083
|
+
rating.label = label;
|
|
1084
|
+
}
|
|
1085
|
+
return rating;
|
|
1086
|
+
}
|
|
1087
|
+
/** Build the MCP tool handler that persists feedback events and attaches them to delegation records. @stable */
|
|
1088
|
+
function createDelegateFeedbackHandler(options) {
|
|
1089
|
+
const generateId = options.generateId ?? randomFeedbackId;
|
|
1090
|
+
const now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
1091
|
+
return async (raw) => {
|
|
1092
|
+
const args = validateDelegateFeedbackArgs(raw);
|
|
1093
|
+
const id = generateId();
|
|
1094
|
+
const event = {
|
|
1095
|
+
id,
|
|
1096
|
+
refersTo: args.refersTo,
|
|
1097
|
+
rating: args.rating,
|
|
1098
|
+
by: args.by,
|
|
1099
|
+
capturedAt: args.capturedAt ?? now(),
|
|
1100
|
+
namespace: args.namespace
|
|
1101
|
+
};
|
|
1102
|
+
await options.store.put(event);
|
|
1103
|
+
if (args.refersTo.kind === "delegation") options.queue.attachFeedback(args.refersTo.ref, eventToSnapshot(event));
|
|
1104
|
+
return {
|
|
1105
|
+
recorded: true,
|
|
1106
|
+
id
|
|
1107
|
+
};
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function randomFeedbackId() {
|
|
1111
|
+
return `fbk-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
1112
|
+
}
|
|
1113
|
+
//#endregion
|
|
920
1114
|
//#region src/mcp/tools/delegate-ui-audit.ts
|
|
921
1115
|
/**
|
|
922
1116
|
*
|
|
@@ -1172,28 +1366,166 @@ function defaultEstimate(args) {
|
|
|
1172
1366
|
return PER_LENS_PER_ROUTE_ESTIMATE_MS * lenses * routes;
|
|
1173
1367
|
}
|
|
1174
1368
|
//#endregion
|
|
1175
|
-
//#region src/mcp/
|
|
1369
|
+
//#region src/mcp/types.ts
|
|
1370
|
+
/**
|
|
1371
|
+
* Every delegation profile a queued record can carry. One owner: the tool schemas and validators
|
|
1372
|
+
* that filter on a profile read this list, so a profile added here cannot be one a tool refuses.
|
|
1373
|
+
* @experimental
|
|
1374
|
+
*/
|
|
1375
|
+
const delegationProfiles = [
|
|
1376
|
+
"coder",
|
|
1377
|
+
"researcher",
|
|
1378
|
+
"ui-auditor"
|
|
1379
|
+
];
|
|
1380
|
+
//#endregion
|
|
1381
|
+
//#region src/mcp/tools/delegation-history.ts
|
|
1382
|
+
/** MCP tool name for the `delegation_history` read-past-delegations tool. @stable */
|
|
1383
|
+
const DELEGATION_HISTORY_TOOL_NAME = "delegation_history";
|
|
1384
|
+
/** Human-readable description of the `delegation_history` MCP tool, injected into the tool manifest. @stable */
|
|
1385
|
+
const DELEGATION_HISTORY_DESCRIPTION = [
|
|
1386
|
+
"Read past delegations newest-first. Each entry carries the original",
|
|
1387
|
+
"arguments, current status, cost, and any feedback attached via",
|
|
1388
|
+
"delegate_feedback.",
|
|
1389
|
+
"",
|
|
1390
|
+
"Use when: you want to introspect prior decisions — \"have I asked this",
|
|
1391
|
+
"question before?",
|
|
1392
|
+
"did the last patch land?",
|
|
1393
|
+
"what's the historical",
|
|
1394
|
+
"success rate of coder delegations on this repo?\". Feed the results back",
|
|
1395
|
+
"into your own routing and calibration.",
|
|
1396
|
+
"",
|
|
1397
|
+
"Each entry carries `hasTrace` — when true, the full loop-trace span tree",
|
|
1398
|
+
"is retrievable via delegation_status { taskId, includeTrace: true }.",
|
|
1399
|
+
"",
|
|
1400
|
+
`Filters: \`namespace\` (multi-tenant scope), \`profile\` (${delegationProfiles.map((profile) => `"${profile}"`).join(" | ")}),`,
|
|
1401
|
+
"`since` (ISO date — only delegations started at-or-after). `limit` defaults",
|
|
1402
|
+
"to 50, capped at 500."
|
|
1403
|
+
].join("\n");
|
|
1404
|
+
/** JSON Schema for `delegation_history` tool arguments (optional `namespace`, `profile`, `since`, `limit`). @stable */
|
|
1405
|
+
const DELEGATION_HISTORY_INPUT_SCHEMA = {
|
|
1406
|
+
type: "object",
|
|
1407
|
+
properties: {
|
|
1408
|
+
namespace: { type: "string" },
|
|
1409
|
+
profile: {
|
|
1410
|
+
type: "string",
|
|
1411
|
+
enum: delegationProfiles
|
|
1412
|
+
},
|
|
1413
|
+
since: {
|
|
1414
|
+
type: "string",
|
|
1415
|
+
description: "ISO datetime — earliest startedAt to include."
|
|
1416
|
+
},
|
|
1417
|
+
limit: {
|
|
1418
|
+
type: "integer",
|
|
1419
|
+
minimum: 1,
|
|
1420
|
+
maximum: 500
|
|
1421
|
+
}
|
|
1422
|
+
},
|
|
1423
|
+
additionalProperties: false
|
|
1424
|
+
};
|
|
1425
|
+
/** Parse and validate raw MCP tool input into typed `DelegationHistoryArgs`; throws `TypeError` on bad input. @stable */
|
|
1426
|
+
function validateDelegationHistoryArgs(raw) {
|
|
1427
|
+
if (raw === void 0 || raw === null) return {};
|
|
1428
|
+
if (typeof raw !== "object") throw new TypeError("delegation_history: arguments must be an object");
|
|
1429
|
+
const value = raw;
|
|
1430
|
+
const out = {};
|
|
1431
|
+
if (value.namespace !== void 0) {
|
|
1432
|
+
if (typeof value.namespace !== "string") throw new TypeError("delegation_history: `namespace` must be a string");
|
|
1433
|
+
out.namespace = value.namespace;
|
|
1434
|
+
}
|
|
1435
|
+
if (value.profile !== void 0) {
|
|
1436
|
+
if (!delegationProfiles.includes(value.profile)) throw new TypeError(`delegation_history: \`profile\` must be one of ${delegationProfiles.join(", ")}`);
|
|
1437
|
+
out.profile = value.profile;
|
|
1438
|
+
}
|
|
1439
|
+
if (value.since !== void 0) {
|
|
1440
|
+
if (typeof value.since !== "string" || Number.isNaN(Date.parse(value.since))) throw new TypeError("delegation_history: `since` must be an ISO datetime");
|
|
1441
|
+
out.since = value.since;
|
|
1442
|
+
}
|
|
1443
|
+
if (value.limit !== void 0) {
|
|
1444
|
+
const n = Number(value.limit);
|
|
1445
|
+
if (!Number.isFinite(n) || n < 1 || n > 500) throw new RangeError("delegation_history: `limit` must be an integer in [1, 500]");
|
|
1446
|
+
out.limit = Math.trunc(n);
|
|
1447
|
+
}
|
|
1448
|
+
return out;
|
|
1449
|
+
}
|
|
1450
|
+
/** Build the MCP tool handler that reads filtered past delegations from a `DelegationTaskQueue`. @stable */
|
|
1451
|
+
function createDelegationHistoryHandler(options) {
|
|
1452
|
+
return async (raw) => {
|
|
1453
|
+
const args = validateDelegationHistoryArgs(raw);
|
|
1454
|
+
return { delegations: options.queue.history(args) };
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
//#endregion
|
|
1458
|
+
//#region src/mcp/tools/delegation-status.ts
|
|
1176
1459
|
/**
|
|
1177
1460
|
*
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
* `delegate` verb plus the queue-bound `delegate_feedback`,
|
|
1181
|
-
* `delegation_status`, and `delegation_history`. `delegate_ui_audit` is served
|
|
1182
|
-
* when a `uiAuditorDelegate` is wired.
|
|
1183
|
-
*
|
|
1184
|
-
* The server is transport-bound but topology-free: tool execution is
|
|
1185
|
-
* delegated to handler functions composed from a queue, a feedback
|
|
1186
|
-
* store, and the wired run delegates. Consumers wire those at
|
|
1187
|
-
* construction time. The `agent-runtime-mcp` bin serves the generic
|
|
1188
|
-
* `delegate` verb over a real sandbox client when `MCP_ENABLE_DELEGATE=1`.
|
|
1189
|
-
*
|
|
1190
|
-
* Wire protocol: line-delimited JSON-RPC 2.0 over stdio. Each line is
|
|
1191
|
-
* one request; each response is one line. `tools/list` and `tools/call`
|
|
1192
|
-
* mirror the MCP 2024-11-05 spec. The production server does not depend on
|
|
1193
|
-
* `@modelcontextprotocol/sdk`; integration tests validate this wire with the official client.
|
|
1461
|
+
* `delegation_status` MCP tool — synchronous poll. Returns the current
|
|
1462
|
+
* state machine + optional progress + final result (when terminal).
|
|
1194
1463
|
*
|
|
1195
|
-
* @
|
|
1464
|
+
* @stable
|
|
1196
1465
|
*/
|
|
1466
|
+
/** MCP tool name for the `delegation_status` synchronous-poll tool. @stable */
|
|
1467
|
+
const DELEGATION_STATUS_TOOL_NAME = "delegation_status";
|
|
1468
|
+
/** Human-readable description of the `delegation_status` MCP tool, injected into the tool manifest. @stable */
|
|
1469
|
+
const DELEGATION_STATUS_DESCRIPTION = [
|
|
1470
|
+
"Poll the status of an async delegation. Returns the current state",
|
|
1471
|
+
"(pending | running | completed | failed | cancelled), optional progress,",
|
|
1472
|
+
"and the final result when status === \"completed\".",
|
|
1473
|
+
"",
|
|
1474
|
+
"Use when: you previously kicked off an async delegation (delegate_ui_audit)",
|
|
1475
|
+
"and need to know whether the work is done. The agent's right rhythm is to",
|
|
1476
|
+
"call this every minute or two while waiting; do not busy-poll.",
|
|
1477
|
+
"",
|
|
1478
|
+
"For a completed delegate_ui_audit run, `result.output` is the array of UI",
|
|
1479
|
+
"findings — one self-contained Markdown finding per issue, each with an",
|
|
1480
|
+
"embedded screenshot and a suggested fix.",
|
|
1481
|
+
"",
|
|
1482
|
+
"Pass includeTrace: true to also receive the journaled loop-trace span",
|
|
1483
|
+
"tree (loop → round → iteration, with placement/cost/verdict metadata).",
|
|
1484
|
+
"Default false — keep routine polls light.",
|
|
1485
|
+
"",
|
|
1486
|
+
"Throws NotFoundError when taskId is unknown — never silently returns",
|
|
1487
|
+
"`pending` for a typo."
|
|
1488
|
+
].join("\n");
|
|
1489
|
+
/** JSON Schema for `delegation_status` tool arguments (`taskId` + optional `includeTrace`). @stable */
|
|
1490
|
+
const DELEGATION_STATUS_INPUT_SCHEMA = {
|
|
1491
|
+
type: "object",
|
|
1492
|
+
properties: {
|
|
1493
|
+
taskId: {
|
|
1494
|
+
type: "string",
|
|
1495
|
+
description: "Returned by delegate_ui_audit."
|
|
1496
|
+
},
|
|
1497
|
+
includeTrace: {
|
|
1498
|
+
type: "boolean",
|
|
1499
|
+
description: "Also return the journaled loop-trace span tree for this delegation. Default false."
|
|
1500
|
+
}
|
|
1501
|
+
},
|
|
1502
|
+
required: ["taskId"],
|
|
1503
|
+
additionalProperties: false
|
|
1504
|
+
};
|
|
1505
|
+
/** Parse and validate raw MCP tool input into typed `DelegationStatusArgs`; throws `TypeError` on bad input. @stable */
|
|
1506
|
+
function validateDelegationStatusArgs(raw) {
|
|
1507
|
+
if (raw === null || typeof raw !== "object") throw new TypeError("delegation_status: arguments must be an object");
|
|
1508
|
+
const value = raw;
|
|
1509
|
+
const taskId = value.taskId;
|
|
1510
|
+
if (typeof taskId !== "string" || taskId.trim().length === 0) throw new TypeError("delegation_status: `taskId` must be a non-empty string");
|
|
1511
|
+
const out = { taskId: taskId.trim() };
|
|
1512
|
+
if (value.includeTrace !== void 0) {
|
|
1513
|
+
if (typeof value.includeTrace !== "boolean") throw new TypeError("delegation_status: `includeTrace` must be a boolean");
|
|
1514
|
+
out.includeTrace = value.includeTrace;
|
|
1515
|
+
}
|
|
1516
|
+
return out;
|
|
1517
|
+
}
|
|
1518
|
+
/** Build the MCP tool handler that polls a `DelegationTaskQueue` for task status. @stable */
|
|
1519
|
+
function createDelegationStatusHandler(options) {
|
|
1520
|
+
return async (raw) => {
|
|
1521
|
+
const args = validateDelegationStatusArgs(raw);
|
|
1522
|
+
const status = options.queue.status(args.taskId, args.includeTrace !== void 0 ? { includeTrace: args.includeTrace } : void 0);
|
|
1523
|
+
if (!status) throw new NotFoundError(`delegation_status: unknown taskId "${args.taskId}"`);
|
|
1524
|
+
return status;
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
//#endregion
|
|
1528
|
+
//#region src/mcp/server.ts
|
|
1197
1529
|
const DEFAULT_SERVER_NAME = "agent-runtime-mcp";
|
|
1198
1530
|
const DEFAULT_SERVER_VERSION = "0.22.0";
|
|
1199
1531
|
/**
|
|
@@ -1261,44 +1593,7 @@ function createMcpServer(options = {}) {
|
|
|
1261
1593
|
stop: stdio.stop
|
|
1262
1594
|
};
|
|
1263
1595
|
}
|
|
1264
|
-
/**
|
|
1265
|
-
* In-process pair of `Readable` + `Writable` streams suitable for driving
|
|
1266
|
-
* `server.serve(...)` from a test. Returns the agent-side stream (the
|
|
1267
|
-
* client writes to it) and the server-side stream (the test reads from it).
|
|
1268
|
-
*
|
|
1269
|
-
* @experimental
|
|
1270
|
-
*/
|
|
1271
|
-
function createInProcessTransport() {
|
|
1272
|
-
const responses = [];
|
|
1273
|
-
const input = new Readable({ read() {} });
|
|
1274
|
-
return {
|
|
1275
|
-
transport: {
|
|
1276
|
-
input,
|
|
1277
|
-
output: new Writable({ write(chunk, _enc, cb) {
|
|
1278
|
-
const text = chunk.toString("utf8");
|
|
1279
|
-
for (const line of text.split("\n")) {
|
|
1280
|
-
const trimmed = line.trim();
|
|
1281
|
-
if (!trimmed) continue;
|
|
1282
|
-
try {
|
|
1283
|
-
responses.push(JSON.parse(trimmed));
|
|
1284
|
-
} catch {}
|
|
1285
|
-
}
|
|
1286
|
-
cb();
|
|
1287
|
-
} })
|
|
1288
|
-
},
|
|
1289
|
-
clientWrite(line) {
|
|
1290
|
-
input.push(`${line}\n`);
|
|
1291
|
-
},
|
|
1292
|
-
clientClose() {
|
|
1293
|
-
input.push(null);
|
|
1294
|
-
},
|
|
1295
|
-
async readServer() {
|
|
1296
|
-
for (let i = 0; i < 5; i += 1) await new Promise((r) => setImmediate(r));
|
|
1297
|
-
return [...responses];
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
1596
|
//#endregion
|
|
1302
|
-
export { composeLoopTraceEmitters as
|
|
1597
|
+
export { composeLoopTraceEmitters as a, FileDelegationStore as i, createDelegateHandler as n, DelegationTaskQueue as r, createMcpServer as t };
|
|
1303
1598
|
|
|
1304
|
-
//# sourceMappingURL=server-
|
|
1599
|
+
//# sourceMappingURL=server-DkVBSN_S.js.map
|