@tangle-network/agent-runtime 0.337.2 → 0.339.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.
Files changed (155) hide show
  1. package/dist/{activation-DRHM55Oo.d.ts → activation-CJIIl_Ey.d.ts} +90 -22
  2. package/dist/activation-CVSFxis9.js +876 -0
  3. package/dist/activation-CVSFxis9.js.map +1 -0
  4. package/dist/agent.d.ts +4 -4
  5. package/dist/agent.js +4 -7
  6. package/dist/agent.js.map +1 -1
  7. package/dist/{bundle-BPGjESee.js → bundle-DVOhBTic.js} +2 -2
  8. package/dist/{bundle-BPGjESee.js.map → bundle-DVOhBTic.js.map} +1 -1
  9. package/dist/candidate-execution/index.d.ts +4 -63
  10. package/dist/candidate-execution/index.js +6 -146
  11. package/dist/candidate-execution/index.js.map +1 -1
  12. package/dist/content-digest-sBTLujlK.js +9 -0
  13. package/dist/content-digest-sBTLujlK.js.map +1 -0
  14. package/dist/{delegate-B-T_ZB50.js → delegate-CCWE_AkU.js} +2 -2
  15. package/dist/{delegate-B-T_ZB50.js.map → delegate-CCWE_AkU.js.map} +1 -1
  16. package/dist/{coordination-driver-BHkFVqIq.js → driver-control-acknowledgers-C53ggdJ6.js} +4520 -4442
  17. package/dist/driver-control-acknowledgers-C53ggdJ6.js.map +1 -0
  18. package/dist/{durable-file-B_eJr6Mb.js → durable-file-gNI9ILAn.js} +1 -3
  19. package/dist/durable-file-gNI9ILAn.js.map +1 -0
  20. package/dist/durable.d.ts +3 -35
  21. package/dist/durable.js +225 -229
  22. package/dist/durable.js.map +1 -1
  23. package/dist/{graph-C4RFlWAJ.js → graph-CI9JXKqO.js} +65 -18
  24. package/dist/graph-CI9JXKqO.js.map +1 -0
  25. package/dist/{graph-registry-DAI6KNXB.js → graph-registry-BnO64cn8.js} +18 -17
  26. package/dist/graph-registry-BnO64cn8.js.map +1 -0
  27. package/dist/{improvement-cycle-D1I4hQvf.js → improve-BOXTLWJ3.js} +76 -1248
  28. package/dist/improve-BOXTLWJ3.js.map +1 -0
  29. package/dist/{improvement-adapter-D5gwwoXQ.d.ts → improvement-adapter-HUt_-cWA.d.ts} +2 -20
  30. package/dist/index.d.ts +10 -207
  31. package/dist/index.js +91 -305
  32. package/dist/index.js.map +1 -1
  33. package/dist/intelligence.d.ts +10 -229
  34. package/dist/intelligence.js +506 -88
  35. package/dist/intelligence.js.map +1 -1
  36. package/dist/{jsonl-file-DBv31uPi.js → jsonl-file-C9Kde_0Z.js} +2 -2
  37. package/dist/{jsonl-file-DBv31uPi.js.map → jsonl-file-C9Kde_0Z.js.map} +1 -1
  38. package/dist/kernel.d.ts +4 -3
  39. package/dist/kernel.js +12 -13
  40. package/dist/loop-runner-CWzG1bH4.d.ts +32 -0
  41. package/dist/loop-runner-bin.d.ts +32 -2
  42. package/dist/loop-runner-bin.js +93 -1
  43. package/dist/loop-runner-bin.js.map +1 -0
  44. package/dist/loop-runner-pmPIHFVY.js +59 -0
  45. package/dist/loop-runner-pmPIHFVY.js.map +1 -0
  46. package/dist/mcp/bin.js +3 -3
  47. package/dist/mcp/bin.js.map +1 -1
  48. package/dist/mcp/index.d.ts +101 -416
  49. package/dist/mcp/index.js +122 -206
  50. package/dist/mcp/index.js.map +1 -1
  51. package/dist/mcp/memory-bin.js +231 -1
  52. package/dist/mcp/memory-bin.js.map +1 -1
  53. package/dist/model-policy-CyCUwHed.js.map +1 -1
  54. package/dist/placement.d.ts +2 -9
  55. package/dist/placement.js +1 -1
  56. package/dist/placement.js.map +1 -1
  57. package/dist/platform.d.ts +194 -2
  58. package/dist/platform.js +145 -9
  59. package/dist/platform.js.map +1 -1
  60. package/dist/{prepare-CER-ZkPp.js → prepare-bXkvPMJA.js} +1213 -710
  61. package/dist/prepare-bXkvPMJA.js.map +1 -0
  62. package/dist/{profile-gNUsHNIJ.js → profile-Dpei_Sq0.js} +89 -3
  63. package/dist/profile-Dpei_Sq0.js.map +1 -0
  64. package/dist/{profile-materialization-BnoEf1co.d.ts → profile-materialization-B1wm2SPT.d.ts} +3 -5
  65. package/dist/profiles.d.ts +2 -2
  66. package/dist/profiles.js +4 -43
  67. package/dist/profiles.js.map +1 -1
  68. package/dist/{protected-model-port-BhpQRTw-.d.ts → protected-model-port-BGgpy2r9.d.ts} +4 -30
  69. package/dist/protected-redaction-DFCeo4vg.js.map +1 -1
  70. package/dist/{provision-supervisor-DGegCUH4.js → provision-supervisor-CJ6Zz6dz.js} +13 -10
  71. package/dist/provision-supervisor-CJ6Zz6dz.js.map +1 -0
  72. package/dist/record-value-B6bwJxLa.js +12 -0
  73. package/dist/record-value-B6bwJxLa.js.map +1 -0
  74. package/dist/{run-layout-Cu8H7aeh.js → run-cancellation-C9oL62sW.js} +175 -100
  75. package/dist/run-cancellation-C9oL62sW.js.map +1 -0
  76. package/dist/{runtime-BOGpotnH.js → runtime-B2fjL9Oi.js} +2639 -3187
  77. package/dist/runtime-B2fjL9Oi.js.map +1 -0
  78. package/dist/{runtime-hooks-Bj6wJHlH.d.ts → runtime-hooks-nsqxSUFL.d.ts} +2 -6
  79. package/dist/{sandbox-profile-compat-QTkLe1Z6.js → sandbox-profile-compat-BzVBFqrz.js} +690 -699
  80. package/dist/sandbox-profile-compat-BzVBFqrz.js.map +1 -0
  81. package/dist/search-executor-zMumiak_.js +1916 -0
  82. package/dist/search-executor-zMumiak_.js.map +1 -0
  83. package/dist/{server-hZWM-G8w.js → server-_4voDNrl.js} +362 -67
  84. package/dist/server-_4voDNrl.js.map +1 -0
  85. package/dist/{search-executor-Cm1WZmL-.js → structural-rollout-DpLCXzaL.js} +1680 -3403
  86. package/dist/structural-rollout-DpLCXzaL.js.map +1 -0
  87. package/dist/{substrate-B0TYNrXn.js → substrate-CGDFTSRh.js} +2 -9
  88. package/dist/substrate-CGDFTSRh.js.map +1 -0
  89. package/dist/{supervise-CvAKVfue.js → supervise-qAwXmPtD.js} +7768 -5360
  90. package/dist/supervise-qAwXmPtD.js.map +1 -0
  91. package/dist/{supervisor-Rz8AGpYb.js → supervisor-DHrUJhEZ.js} +26301 -26964
  92. package/dist/supervisor-DHrUJhEZ.js.map +1 -0
  93. package/dist/testing.d.ts +227 -2
  94. package/dist/testing.js +13 -14
  95. package/dist/testing.js.map +1 -1
  96. package/dist/tool-loop.d.ts +1 -1
  97. package/dist/{tool-server-Dqer2M4_.js → tool-server-XV4aJwoQ.js} +2 -2
  98. package/dist/tool-server-XV4aJwoQ.js.map +1 -0
  99. package/dist/top-snapshot-CbZE1JsU.js +502 -0
  100. package/dist/top-snapshot-CbZE1JsU.js.map +1 -0
  101. package/dist/tui/bin.js +711 -1
  102. package/dist/tui/bin.js.map +1 -1
  103. package/dist/tui/index.d.ts +5 -71
  104. package/dist/tui/index.js +3 -3
  105. package/dist/{types-Dl5L4r8Z.d.ts → types-CaOXqRTq.d.ts} +16230 -17376
  106. package/dist/workspace-store/index.d.ts +2 -27
  107. package/dist/workspace-store/index.js +2 -2
  108. package/dist/workspace-store/index.js.map +1 -1
  109. package/dist/{workspace-streams-JLjh5DC6.d.ts → workspace-streams-BiS4ABah.d.ts} +19 -32
  110. package/package.json +2 -2
  111. package/skills/agent-graphs/SKILL.md +10 -3
  112. package/skills/agent-graphs/references/authoring.md +18 -0
  113. package/skills/profile-authoring/SKILL.md +3 -3
  114. package/skills/supervise/SKILL.md +2 -2
  115. package/dist/activation-BDP6Eivv.js +0 -234
  116. package/dist/activation-BDP6Eivv.js.map +0 -1
  117. package/dist/coder-yhVWbdWc.js +0 -40
  118. package/dist/coder-yhVWbdWc.js.map +0 -1
  119. package/dist/coordination-driver-BHkFVqIq.js.map +0 -1
  120. package/dist/delegation-status-CF4D0NZ_.js +0 -358
  121. package/dist/delegation-status-CF4D0NZ_.js.map +0 -1
  122. package/dist/durable-file-B_eJr6Mb.js.map +0 -1
  123. package/dist/graph-C4RFlWAJ.js.map +0 -1
  124. package/dist/graph-registry-DAI6KNXB.js.map +0 -1
  125. package/dist/improvement-cycle-D1I4hQvf.js.map +0 -1
  126. package/dist/integrations-DopfCC2a.d.ts +0 -190
  127. package/dist/integrations-dFi-ALk7.js +0 -132
  128. package/dist/integrations-dFi-ALk7.js.map +0 -1
  129. package/dist/kb-gate-C8z2juK8.d.ts +0 -80
  130. package/dist/kb-gate-DpaSwXVx.js +0 -80
  131. package/dist/kb-gate-DpaSwXVx.js.map +0 -1
  132. package/dist/loop-runner-bin-DOuBIJ2O.d.ts +0 -164
  133. package/dist/loop-runner-bin-Dv5QvYDH.js +0 -246
  134. package/dist/loop-runner-bin-Dv5QvYDH.js.map +0 -1
  135. package/dist/memory-server-DXQ8IxGR.js +0 -234
  136. package/dist/memory-server-DXQ8IxGR.js.map +0 -1
  137. package/dist/openai-tools-DoQ32vpe.js +0 -44
  138. package/dist/openai-tools-DoQ32vpe.js.map +0 -1
  139. package/dist/openai-tools-Oxk4KQrY.d.ts +0 -24
  140. package/dist/prepare-CER-ZkPp.js.map +0 -1
  141. package/dist/profile-gNUsHNIJ.js.map +0 -1
  142. package/dist/protected-model-port-BuRsviSL.js +0 -766
  143. package/dist/protected-model-port-BuRsviSL.js.map +0 -1
  144. package/dist/provision-supervisor-DGegCUH4.js.map +0 -1
  145. package/dist/run-layout-Cu8H7aeh.js.map +0 -1
  146. package/dist/runtime-BOGpotnH.js.map +0 -1
  147. package/dist/sandbox-profile-compat-QTkLe1Z6.js.map +0 -1
  148. package/dist/search-executor-Cm1WZmL-.js.map +0 -1
  149. package/dist/server-hZWM-G8w.js.map +0 -1
  150. package/dist/substrate-B0TYNrXn.js.map +0 -1
  151. package/dist/supervise-CvAKVfue.js.map +0 -1
  152. package/dist/supervisor-Rz8AGpYb.js.map +0 -1
  153. package/dist/tool-server-Dqer2M4_.js.map +0 -1
  154. package/dist/top-app-BaMw1W2z.js +0 -1212
  155. package/dist/top-app-BaMw1W2z.js.map +0 -1
@@ -1,13 +1,12 @@
1
- import { gr as buildLoopSpanNodes } from "./supervisor-Rz8AGpYb.js";
2
- import { m as ValidationError, t as AgentEvalError } from "./errors-DodWX-cb.js";
3
- import { X as fnv1a32Hex, Y as errorMessage } from "./sandbox-profile-compat-QTkLe1Z6.js";
4
- import { r as createStdioToolServer } from "./tool-server-Dqer2M4_.js";
5
- import { n as delegate } from "./delegate-B-T_ZB50.js";
6
- import { _ as InMemoryFeedbackStore, c as DELEGATION_HISTORY_TOOL_NAME, f as DELEGATE_FEEDBACK_DESCRIPTION, h as createDelegateFeedbackHandler, i as createDelegationStatusHandler, l as createDelegationHistoryHandler, m as DELEGATE_FEEDBACK_TOOL_NAME, n as DELEGATION_STATUS_INPUT_SCHEMA, o as DELEGATION_HISTORY_DESCRIPTION, p as DELEGATE_FEEDBACK_INPUT_SCHEMA, r as DELEGATION_STATUS_TOOL_NAME, s as DELEGATION_HISTORY_INPUT_SCHEMA, t as DELEGATION_STATUS_DESCRIPTION } from "./delegation-status-CF4D0NZ_.js";
7
- import { n as UI_LENSES } from "./substrate-B0TYNrXn.js";
1
+ import { in as buildLoopSpanNodes } from "./supervisor-DHrUJhEZ.js";
2
+ import { m as ValidationError, o as NotFoundError, t as AgentEvalError } from "./errors-DodWX-cb.js";
3
+ import { Q as fnv1a32Hex, Z as errorMessage } from "./sandbox-profile-compat-BzVBFqrz.js";
4
+ import { n as createStdioToolServer } from "./tool-server-XV4aJwoQ.js";
5
+ import { n as delegate } from "./delegate-CCWE_AkU.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 { Readable, Writable } from "node:stream";
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 ?? 512;
64
- const maxBytes = caps?.maxBytes ?? 262144;
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/server.ts
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
- * Stdio JSON-RPC MCP server exposing the delegation tools to sandbox
1179
- * coding-harness agents (claude-code, codex, opencode, ...): the generic
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
- * @experimental
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 C, capDelegationTrace as S, FileDelegationStore as _, DELEGATE_UI_AUDIT_TOOL_NAME as a, DELEGATION_TRACE_MAX_SPANS as b, DELEGATE_DESCRIPTION as c, createDelegateHandler as d, validateDelegateArgs as f, DelegationStateCorruptError as g, DelegationPersistenceError as h, DELEGATE_UI_AUDIT_INPUT_SCHEMA as i, DELEGATE_INPUT_SCHEMA as l, hashIdempotencyInput as m, createMcpServer as n, createDelegateUiAuditHandler as o, DelegationTaskQueue as p, DELEGATE_UI_AUDIT_DESCRIPTION as r, validateDelegateUiAuditArgs as s, createInProcessTransport as t, DELEGATE_TOOL_NAME as u, InMemoryDelegationStore as v, createDelegationTraceCollector as w, buildDelegationTraceSpans as x, DELEGATION_TRACE_MAX_BYTES as y };
1597
+ export { composeLoopTraceEmitters as a, FileDelegationStore as i, createDelegateHandler as n, DelegationTaskQueue as r, createMcpServer as t };
1303
1598
 
1304
- //# sourceMappingURL=server-hZWM-G8w.js.map
1599
+ //# sourceMappingURL=server-_4voDNrl.js.map