@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
package/dist/mcp/index.js CHANGED
@@ -1,19 +1,128 @@
1
- import { Br as localHarnessExecutable, En as assertBoxlessPromptOptions, Fr as removeWorktree, G as environmentReader, Hr as CodexExecutionDiagnosticError, Ir as DEFAULT_LOCAL_HARNESS, K as hostDirectoryReader, Lr as LOCAL_HARNESSES, Mr as runWorktreeHarness, Nr as captureWorktreeDiff, Pr as createWorktree, Vr as parseCodexTokenUsage, W as SPAWN_RESOURCE_PATH_MAX_BYTES, dr as createPropagatingTraceEmitter, fr as mergeTraceEnv, mr as traceContextToEnv, pr as readTraceContextFromEnv, q as resolveSpawnResourcePaths, vn as createSandboxForSpec, xn as runAgentRounds, zr as harnessSupportsReasoningEffort } from "../supervisor-Rz8AGpYb.js";
1
+ import { Tr as LOCAL_HARNESSES, _t as runAgentRounds, bt as createSandboxForSpec, nn as readTraceContextFromEnv, tn as createPropagatingTraceEmitter, vt as assertBoxlessPromptOptions, wr as runWorktreeHarness } from "../supervisor-DHrUJhEZ.js";
2
2
  import { i as ConfigError, m as ValidationError } from "../errors-DodWX-cb.js";
3
- import { J as deleteBoxSafe, at as sleep, ct as throwIfAborted, st as throwAbort } from "../sandbox-profile-compat-QTkLe1Z6.js";
3
+ import { t as isRecord } from "../record-value-B6bwJxLa.js";
4
+ import { X as deleteBoxSafe, st as sleep, ut as throwIfAborted } from "../sandbox-profile-compat-BzVBFqrz.js";
4
5
  import { t as assertExecutableAgentProfile } from "../model-policy-CyCUwHed.js";
5
- import { R as runCoderChecks, gt as selectValidWinner } from "../runtime-BOGpotnH.js";
6
- import { A as ANALYST_DEFINITION_BOUNDS, I as downMessageRefusalReasons, P as createCoordinationTools, R as parseAuthoredAnalystDefinition, j as analystToolGroupNames, z as questionEscalationTargets } from "../coordination-driver-BHkFVqIq.js";
7
- import { n as SUPPORTED_PROTOCOL_VERSIONS, r as createStdioToolServer } from "../tool-server-Dqer2M4_.js";
8
- import { t as createKbGate } from "../kb-gate-DpaSwXVx.js";
9
- import { _ as InMemoryFeedbackStore, a as validateDelegationStatusArgs, c as DELEGATION_HISTORY_TOOL_NAME, d as delegationProfiles, f as DELEGATE_FEEDBACK_DESCRIPTION, g as validateDelegateFeedbackArgs, 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, u as validateDelegationHistoryArgs, v as eventToSnapshot } from "../delegation-status-CF4D0NZ_.js";
10
- import { n as mcpToolsForRuntimeMcpSubset, t as mcpToolsForRuntimeMcp } from "../openai-tools-DoQ32vpe.js";
11
- import { t as coderTaskToPrompt } from "../coder-yhVWbdWc.js";
12
- import { n as PlatformHubError } from "../integrations-dFi-ALk7.js";
13
- import { C as composeLoopTraceEmitters, S as capDelegationTrace, _ as FileDelegationStore, a as DELEGATE_UI_AUDIT_TOOL_NAME, b as DELEGATION_TRACE_MAX_SPANS, c as DELEGATE_DESCRIPTION, d as createDelegateHandler, f as validateDelegateArgs, g as DelegationStateCorruptError, h as DelegationPersistenceError, i as DELEGATE_UI_AUDIT_INPUT_SCHEMA, l as DELEGATE_INPUT_SCHEMA, m as hashIdempotencyInput, n as createMcpServer, o as createDelegateUiAuditHandler, p as DelegationTaskQueue, r as DELEGATE_UI_AUDIT_DESCRIPTION, s as validateDelegateUiAuditArgs, t as createInProcessTransport, u as DELEGATE_TOOL_NAME, v as InMemoryDelegationStore, w as createDelegationTraceCollector, x as buildDelegationTraceSpans, y as DELEGATION_TRACE_MAX_BYTES } from "../server-hZWM-G8w.js";
14
- import { a as createMemoryToolServer, c as resolveMemoryFromEnv, i as MEMORY_NAME_ENV, n as MEMORY_ITEMS_ENV, o as parseMemoryItems, r as MEMORY_LOG_ENV, s as readMemoryItemsFile, t as MEMORY_FILE_ENV } from "../memory-server-DXQ8IxGR.js";
6
+ import { _ as environmentReader, r as createCoordinationTools, v as resolveSpawnResourcePaths } from "../driver-control-acknowledgers-C53ggdJ6.js";
7
+ import { n as createStdioToolServer } from "../tool-server-XV4aJwoQ.js";
8
+ import { ct as selectValidWinner, h as runCoderChecks } from "../runtime-B2fjL9Oi.js";
9
+ import { a as composeLoopTraceEmitters, i as FileDelegationStore, n as createDelegateHandler, r as DelegationTaskQueue, t as createMcpServer } from "../server-_4voDNrl.js";
15
10
  import { agentProfileSchema } from "@tangle-network/agent-interface";
16
11
  import { randomUUID } from "node:crypto";
12
+ //#region src/mcp/kb-gate.ts
13
+ const norm = (s) => s.toLowerCase().replace(/\s+/g, " ").trim();
14
+ /** Does `value` appear in the (normalized) passage — literally, comma-grouped,
15
+ * or in billion/million shorthand (the forms a source actually writes). */
16
+ function valueAppears(value, passageNorm) {
17
+ if (passageNorm.includes(norm(String(value)))) return true;
18
+ if (typeof value !== "number" || !Number.isFinite(value)) return false;
19
+ const forms = [value.toLocaleString("en-US")];
20
+ if (Math.abs(value) >= 1e9) forms.push(`${trimZero(value / 1e9)} billion`);
21
+ if (Math.abs(value) >= 1e6) forms.push(`${trimZero(value / 1e6)} million`);
22
+ return forms.some((f) => passageNorm.includes(norm(f)));
23
+ }
24
+ function trimZero(n) {
25
+ return Number.isInteger(n) ? String(n) : String(Number(n.toFixed(2)));
26
+ }
27
+ /** The always-on floor judges. Order matters: cheapest / most-fundamental first. */
28
+ function builtinJudges(minPassageChars, selfArtifactKinds) {
29
+ const kinds = selfArtifactKinds.map((k) => k.toLowerCase());
30
+ return [
31
+ {
32
+ name: "passage-non-empty",
33
+ judge: (c) => c.verbatimPassage.trim().length >= minPassageChars ? { accept: true } : {
34
+ accept: false,
35
+ reason: `passage shorter than ${minPassageChars} chars`
36
+ }
37
+ },
38
+ {
39
+ name: "passage-present",
40
+ judge: (c) => norm(c.sourceText).includes(norm(c.verbatimPassage)) ? { accept: true } : {
41
+ accept: false,
42
+ reason: "verbatim passage not found in source (unbacked fact)"
43
+ }
44
+ },
45
+ {
46
+ name: "value-in-passage",
47
+ judge: (c) => c.value === void 0 || valueAppears(c.value, norm(c.verbatimPassage)) ? { accept: true } : {
48
+ accept: false,
49
+ reason: `value ${JSON.stringify(c.value)} not present in passage`
50
+ }
51
+ },
52
+ {
53
+ name: "no-circular-citation",
54
+ judge: (c) => {
55
+ if (!c.citation || kinds.length === 0) return { accept: true };
56
+ const cite = c.citation.toLowerCase();
57
+ const hit = kinds.find((k) => cite.includes(k));
58
+ return hit ? {
59
+ accept: false,
60
+ reason: `circular citation to self-generated artifact "${hit}"`
61
+ } : { accept: true };
62
+ }
63
+ }
64
+ ];
65
+ }
66
+ /**
67
+ *
68
+ * Build a fail-closed KB gate. The returned function runs the built-in floor
69
+ * (passage-non-empty → passage-present → value-in-passage → no-circular-citation)
70
+ * then any consumer judges, returning on the first veto.
71
+ *
72
+ * @experimental
73
+ */
74
+ function createKbGate(options = {}) {
75
+ const judges = [...builtinJudges(options.minPassageChars ?? 12, options.selfArtifactKinds ?? []), ...options.judges ?? []];
76
+ return async (candidate) => {
77
+ for (const j of judges) {
78
+ const verdict = await j.judge(candidate);
79
+ if (!verdict.accept) return {
80
+ accepted: false,
81
+ vetoedBy: j.name,
82
+ reason: verdict.reason
83
+ };
84
+ }
85
+ return { accepted: true };
86
+ };
87
+ }
88
+ //#endregion
89
+ //#region src/profiles/coder.ts
90
+ /**
91
+ *
92
+ * `CoderTask` + `coderTaskToPrompt` — the per-task DATA + pure formatter for code-modification tasks
93
+ * (§1.5: the system authors profiles; there is no hardcoded coder profile constant). A domain
94
+ * customizes the worker by authoring its own `AgentProfile` and handing it to a leaf executor
95
+ * (`createWorktreeCliExecutor`) or a fanout (`worktreeFanout`); "is it delivered" is a
96
+ * `DeliverableSpec` (`patchDelivered`), not a bundled validator. This formatter renders a `CoderTask`
97
+ * into the per-task instruction that profile receives.
98
+ *
99
+ * @experimental
100
+ */
101
+ const DEFAULT_MAX_DIFF_LINES$1 = 400;
102
+ /** Render a `CoderTask` into the per-task instruction handed to the coder profile. @experimental */
103
+ function coderTaskToPrompt(task) {
104
+ const base = task.baseBranch ?? "main";
105
+ const testCmd = task.testCmd ?? "pnpm test --run";
106
+ const typecheckCmd = task.typecheckCmd ?? "pnpm typecheck";
107
+ const maxDiff = task.maxDiffLines ?? DEFAULT_MAX_DIFF_LINES$1;
108
+ const forbidden = task.forbiddenPaths?.length ? task.forbiddenPaths.join(", ") : "(none)";
109
+ const context = task.contextFiles?.length ? task.contextFiles.map((f) => ` - ${f}`).join("\n") : " (none)";
110
+ return [
111
+ `Goal: ${task.goal}`,
112
+ `Repo: ${task.repoRoot}`,
113
+ `Base branch: ${base}`,
114
+ `Run tests with: ${testCmd}`,
115
+ `Run typecheck with: ${typecheckCmd}`,
116
+ `Forbidden paths: ${forbidden}`,
117
+ `Max diff lines: ${maxDiff}`,
118
+ "Context files:",
119
+ context,
120
+ "",
121
+ "Produce a minimal patch on a fresh branch. Run tests and typecheck before",
122
+ "returning. Emit the final JSON result block exactly as instructed."
123
+ ].join("\n");
124
+ }
125
+ //#endregion
17
126
  //#region src/mcp/detached-coder.ts
18
127
  /**
19
128
  *
@@ -175,9 +284,6 @@ function projectWorktreeArtifact(value) {
175
284
  ...exitCode !== 0 ? { reviewerNotes: `harness ${harnessName} exited ${exitCode}${timedOut ? " (timed out)" : ""}` } : {}
176
285
  };
177
286
  }
178
- function isRecord(value) {
179
- return value !== null && typeof value === "object" && !Array.isArray(value);
180
- }
181
287
  /** Keep the last `max` chars of a diagnostic string — harness stdout can be large; the gate reads
182
288
  * `passed`, not this text, so only the tail is retained for traces/logs. */
183
289
  function tail(text, max) {
@@ -480,74 +586,6 @@ function createDetachedTurnTrace(options) {
480
586
  function detachedRunningPhase(elapsedMs) {
481
587
  return elapsedMs === void 0 ? "detached-running" : `detached-running ${Math.round(elapsedMs / 1e3)}s`;
482
588
  }
483
- /**
484
- * Build the `driveTurn`-backed {@link DelegationResumeDriver}. Each `tick()`
485
- * is one settle/poll/dispatch pass:
486
- *
487
- * - ref without a sandbox binding → `failed` (`DetachedSessionUnboundError`):
488
- * the previous process died before a box existed; there is nothing to resume.
489
- * - `driveTurn` `completed` → `settleOutput` → `completed` tick.
490
- * - `running` → progress via `ctx.report`, `running` tick (queue re-ticks
491
- * after `intervalMs`).
492
- * - `failed` → `failed` tick (`DetachedTurnFailedError`) — terminal per the
493
- * SDK's deterministic-failure contract.
494
- *
495
- * Abort: the queue stops ticking once `cancel()` flips the record, so remote
496
- * cancellation is hooked onto `ctx.signal` (once per task) and fires
497
- * `_sessionCancel` when the SDK surface exposes it. The driver never deletes
498
- * boxes — it cannot know whether `sandboxId` is a disposable sibling or a
499
- * fleet machine, and destroying a fleet machine would be unrecoverable.
500
- *
501
- * @experimental
502
- */
503
- function createDetachedTurnResumeDriver(options) {
504
- const cancelHooked = /* @__PURE__ */ new Set();
505
- return {
506
- intervalMs: options.intervalMs ?? DEFAULT_TICK_INTERVAL_MS,
507
- async tick({ record, detachedSessionRef }, ctx) {
508
- const ref = parseDetachedSessionRef(detachedSessionRef);
509
- if (ref.sandboxId === void 0) return {
510
- state: "failed",
511
- error: {
512
- message: `detached session "${ref.sessionId}" was never bound to a sandbox — the previous process died before the box was acquired, so the turn was never dispatched and cannot be resumed`,
513
- kind: "DetachedSessionUnboundError"
514
- }
515
- };
516
- const box = await options.resolveSandbox(ref.sandboxId);
517
- if (!cancelHooked.has(record.taskId)) {
518
- cancelHooked.add(record.taskId);
519
- ctx.signal.addEventListener("abort", () => {
520
- box._sessionCancel?.(ref.sessionId).catch(() => {});
521
- }, { once: true });
522
- }
523
- if (ctx.signal.aborted) throwAbort();
524
- const tick = await box.driveTurn(options.buildMessage(record), {
525
- sessionId: ref.sessionId,
526
- turnId: ref.sessionId,
527
- ...options.wallCapMs !== void 0 ? { wallCapMs: options.wallCapMs } : {}
528
- });
529
- if (tick.state === "completed") return {
530
- state: "completed",
531
- output: await options.settleOutput({
532
- text: tick.text,
533
- result: tick.result
534
- }, record, { signal: ctx.signal })
535
- };
536
- if (tick.state === "failed") return {
537
- state: "failed",
538
- error: {
539
- message: `detached turn ${ref.sessionId} failed: ${tick.error}`,
540
- kind: "DetachedTurnFailedError"
541
- }
542
- };
543
- ctx.report({
544
- iteration: 0,
545
- phase: detachedRunningPhase(tick.elapsedMs)
546
- });
547
- return { state: "running" };
548
- }
549
- };
550
- }
551
589
  //#endregion
552
590
  //#region src/mcp/executor.ts
553
591
  /**
@@ -936,128 +974,6 @@ function collidesWithHarnessNativeTool(name) {
936
974
  return sourcedHarnesses.filter((harness) => harnessNativeTools[harness].some((native) => native.toLowerCase() === wanted));
937
975
  }
938
976
  //#endregion
939
- //#region src/mcp/hub-server.ts
940
- /**
941
- * Hub integration MCP server — the user's connected databases and vector
942
- * stores as agent tools, mid-turn.
943
- *
944
- * The Tangle Platform Hub (`PlatformHubClient`, platform/integrations.ts)
945
- * already turns a provider credential into a per-user, per-action-policy'd,
946
- * approved, audited access surface: the user connects Pinecone/Qdrant/
947
- * Weaviate/Neon/Supabase/… once, and every later call goes through
948
- * `POST /v1/hub/exec`. This module is the thin bridge from that surface to
949
- * the agent's tool loop: for every ACTIVE connection to a data provider it
950
- * serves ONE router tool (`hub_<provider>`) whose `action` + `input`
951
- * arguments are dispatched to the provider's Hub adapter.
952
- *
953
- * Why one router tool per connection instead of one tool per adapter action:
954
- * the Hub catalog publishes capability counts, not capability schemas, so a
955
- * per-action tool surface would have to bundle the whole adapter registry.
956
- * The router tool keeps the layer thin — the Hub adapter IS the tool, the
957
- * Hub exec endpoint IS the invocation, and the Hub policy IS the permission.
958
- * Every call is policy-gated server-side; a denial surfaces to the agent as
959
- * the Hub's own error message. When the platform grows a capabilities
960
- * endpoint, per-action tools can be generated from it without changing this
961
- * module's contract.
962
- *
963
- * Tool lists are resolved at construction (session-scoped, like the memory
964
- * server): connections the user adds later appear after the server restarts.
965
- *
966
- * @experimental
967
- */
968
- /** The substrate data providers whose Hub adapters become agent tools. */
969
- const HUB_DATA_PROVIDER_KINDS = [
970
- "pinecone",
971
- "qdrant",
972
- "weaviate",
973
- "neon",
974
- "supabase",
975
- "mongodb",
976
- "postgres",
977
- "mysql",
978
- "redis"
979
- ];
980
- /** An action name: dot-separated identifiers — `vectors.query`, `branches.list`. */
981
- const ACTION_NAME_PATTERN = /^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)+$/;
982
- const MCP_TOOL_NAME_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
983
- function toolNameFor(providerId, connectionId, taken) {
984
- const base = `hub_${providerId}`.replace(/[^A-Za-z0-9_-]/g, "-");
985
- const candidates = [base, `${base}-${connectionId.replace(/[^A-Za-z0-9_-]/g, "-").slice(0, 64 - base.length - 1)}`];
986
- for (const candidate of candidates) if (MCP_TOOL_NAME_PATTERN.test(candidate) && !taken.has(candidate)) {
987
- taken.add(candidate);
988
- return candidate;
989
- }
990
- throw new ValidationError(`hubIntegrationTools: cannot derive a unique tool name for connection '${connectionId}' of provider '${providerId}'`);
991
- }
992
- function connectionLabel(connection) {
993
- const account = connection.accountDisplay ? ` (${connection.accountDisplay})` : "";
994
- return `${connection.displayName || connection.providerId}${account}`;
995
- }
996
- /**
997
- * One router tool per active Hub connection to a data provider. The tool
998
- * handler never holds provider credentials — it execs through the Hub, which
999
- * enforces the per-user action policy and writes the audit record.
1000
- */
1001
- async function hubIntegrationTools(options) {
1002
- const providers = new Set(options.providers ?? HUB_DATA_PROVIDER_KINDS);
1003
- const eligible = (await options.client.listConnections()).filter((connection) => providers.has(connection.providerId) && connection.status === "active" && (options.includeUnhealthy === true || connection.health !== "unhealthy"));
1004
- const taken = /* @__PURE__ */ new Set();
1005
- return eligible.map((connection) => {
1006
- const providerId = connection.providerId;
1007
- const name = toolNameFor(providerId, connection.id, taken);
1008
- return {
1009
- name,
1010
- description: `Execute a ${providerId} action on the user's Hub connection '${connectionLabel(connection)}' (connection ${connection.id}). Pass action (e.g. "vectors.query", "branches.list", "collections.list") and its input object. Every call is policy-gated and audited by the Tangle Hub; a denied action returns the Hub's error message. Read actions list data; mutations may require prior approval.`,
1011
- inputSchema: {
1012
- type: "object",
1013
- properties: {
1014
- action: {
1015
- type: "string",
1016
- description: `The ${providerId} adapter action name, e.g. "vectors.query".`
1017
- },
1018
- input: {
1019
- type: "object",
1020
- description: "Arguments object for the action.",
1021
- additionalProperties: true
1022
- }
1023
- },
1024
- required: ["action"],
1025
- additionalProperties: false
1026
- },
1027
- handler: async (raw) => {
1028
- const args = raw ?? {};
1029
- if (typeof args.action !== "string" || !ACTION_NAME_PATTERN.test(args.action)) throw new TypeError(`${name}: action must be a provider action name like "vectors.query" (dot-separated, no path or spaces)`);
1030
- if (args.input !== void 0 && (typeof args.input !== "object" || args.input === null || Array.isArray(args.input))) throw new TypeError(`${name}: input must be an object of action arguments`);
1031
- const path = `${providerId}.${args.action}`;
1032
- try {
1033
- return await options.client.exec({
1034
- path,
1035
- input: args.input ?? {},
1036
- connectionId: connection.id
1037
- });
1038
- } catch (error) {
1039
- if (error instanceof PlatformHubError) throw new Error(`${name}: hub exec '${path}' failed (${error.status}${error.code ? ` ${error.code}` : ""}): ${error.message}`);
1040
- throw error;
1041
- }
1042
- }
1043
- };
1044
- });
1045
- }
1046
- /**
1047
- * Build the hub integration MCP server on the shared stdio JSON-RPC core —
1048
- * the same wire protocol every in-repo MCP server speaks. Serves zero tools
1049
- * when the caller has no active data-provider connections (a session without
1050
- * connections simply gets no database tools, mirroring the memory server's
1051
- * "no artifact, no server" discipline).
1052
- */
1053
- async function createHubIntegrationToolServer(options) {
1054
- return createStdioToolServer({
1055
- serverName: options.serverName ?? "agent-hub-integrations",
1056
- serverVersion: options.serverVersion ?? "0",
1057
- tools: await hubIntegrationTools(options)
1058
- });
1059
- }
1060
- //#endregion
1061
977
  //#region src/mcp/in-process-executor.ts
1062
978
  /**
1063
979
  *
@@ -1239,6 +1155,6 @@ async function defaultRunPostCheck(cmd, cwd, signal) {
1239
1155
  });
1240
1156
  }
1241
1157
  //#endregion
1242
- export { ANALYST_DEFINITION_BOUNDS, CodexExecutionDiagnosticError, DEFAULT_LOCAL_HARNESS, DELEGATE_DESCRIPTION, DELEGATE_FEEDBACK_DESCRIPTION, DELEGATE_FEEDBACK_INPUT_SCHEMA, DELEGATE_FEEDBACK_TOOL_NAME, DELEGATE_INPUT_SCHEMA, DELEGATE_TOOL_NAME, DELEGATE_UI_AUDIT_DESCRIPTION, DELEGATE_UI_AUDIT_INPUT_SCHEMA, DELEGATE_UI_AUDIT_TOOL_NAME, DELEGATION_HISTORY_DESCRIPTION, DELEGATION_HISTORY_INPUT_SCHEMA, DELEGATION_HISTORY_TOOL_NAME, DELEGATION_STATUS_DESCRIPTION, DELEGATION_STATUS_INPUT_SCHEMA, DELEGATION_STATUS_TOOL_NAME, DELEGATION_TRACE_MAX_BYTES, DELEGATION_TRACE_MAX_SPANS, DelegationPersistenceError, DelegationStateCorruptError, DelegationTaskQueue, FileDelegationStore, HUB_DATA_PROVIDER_KINDS, InMemoryDelegationStore, InMemoryFeedbackStore, LOCAL_HARNESSES, MEMORY_FILE_ENV, MEMORY_ITEMS_ENV, MEMORY_LOG_ENV, MEMORY_NAME_ENV, SPAWN_RESOURCE_PATH_MAX_BYTES, SUPPORTED_PROTOCOL_VERSIONS, analystToolGroupNames, buildDelegationTraceSpans, capDelegationTrace, captureWorktreeDiff, coderTaskFromArgs, collidesWithHarnessNativeTool, composeLoopTraceEmitters, createCoordinationTools, createDelegateFeedbackHandler, createDelegateHandler, createDelegateUiAuditHandler, createDelegationHistoryHandler, createDelegationStatusHandler, createDelegationTraceCollector, createDetachedTurnResumeDriver, createFleetWorkspaceExecutor, createHubIntegrationToolServer, createInProcessExecutor, createInProcessTransport, createKbGate, createMcpServer, createMemoryToolServer, createPropagatingTraceEmitter, createSiblingSandboxExecutor, createStdioToolServer, createWorktree, delegationProfiles, detachedSessionDelegate, detachedTurnEvents, downMessageRefusalReasons, environmentReader, eventToSnapshot, formatDetachedSessionRef, harnessNativeToolNames, harnessNativeTools, harnessSupportsReasoningEffort, hashIdempotencyInput, hostDirectoryReader, hubIntegrationTools, localHarnessExecutable, mcpToolsForRuntimeMcp, mcpToolsForRuntimeMcpSubset, mergeTraceEnv, parseAuthoredAnalystDefinition, parseCodexTokenUsage, parseDetachedSessionRef, parseMemoryItems, questionEscalationTargets, readMemoryItemsFile, readTraceContextFromEnv, removeWorktree, resolveMemoryFromEnv, resolveSpawnResourcePaths, runDetachedTurn, settleDetachedCoderTurn, sourcedHarnesses, traceContextToEnv, validateDelegateArgs, validateDelegateFeedbackArgs, validateDelegateUiAuditArgs, validateDelegationHistoryArgs, validateDelegationStatusArgs };
1158
+ export { DelegationTaskQueue, FileDelegationStore, LOCAL_HARNESSES, collidesWithHarnessNativeTool, composeLoopTraceEmitters, createCoordinationTools, createDelegateHandler, createFleetWorkspaceExecutor, createInProcessExecutor, createKbGate, createMcpServer, createPropagatingTraceEmitter, createSiblingSandboxExecutor, createStdioToolServer, detachedSessionDelegate, environmentReader, harnessNativeToolNames, readTraceContextFromEnv, resolveSpawnResourcePaths, runDetachedTurn };
1243
1159
 
1244
1160
  //# sourceMappingURL=index.js.map