@namzu/sdk 3.0.0 → 3.2.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 (307) hide show
  1. package/CHANGELOG.md +223 -0
  2. package/dist/advisory/__tests__/consultation-context.test.d.ts +2 -0
  3. package/dist/advisory/__tests__/consultation-context.test.d.ts.map +1 -0
  4. package/dist/advisory/__tests__/consultation-context.test.js +124 -0
  5. package/dist/advisory/__tests__/consultation-context.test.js.map +1 -0
  6. package/dist/advisory/context.d.ts +25 -0
  7. package/dist/advisory/context.d.ts.map +1 -1
  8. package/dist/advisory/context.js +18 -0
  9. package/dist/advisory/context.js.map +1 -1
  10. package/dist/advisory/executor.d.ts.map +1 -1
  11. package/dist/advisory/executor.js +25 -3
  12. package/dist/advisory/executor.js.map +1 -1
  13. package/dist/compaction/__tests__/context-reducer.test.d.ts +2 -0
  14. package/dist/compaction/__tests__/context-reducer.test.d.ts.map +1 -0
  15. package/dist/compaction/__tests__/context-reducer.test.js +197 -0
  16. package/dist/compaction/__tests__/context-reducer.test.js.map +1 -0
  17. package/dist/compaction/factory.d.ts +7 -0
  18. package/dist/compaction/factory.d.ts.map +1 -1
  19. package/dist/compaction/factory.js +7 -0
  20. package/dist/compaction/factory.js.map +1 -1
  21. package/dist/compaction/index.d.ts +2 -0
  22. package/dist/compaction/index.d.ts.map +1 -1
  23. package/dist/compaction/index.js +1 -0
  24. package/dist/compaction/index.js.map +1 -1
  25. package/dist/compaction/interface.d.ts +13 -0
  26. package/dist/compaction/interface.d.ts.map +1 -1
  27. package/dist/compaction/managers/null.d.ts +3 -0
  28. package/dist/compaction/managers/null.d.ts.map +1 -1
  29. package/dist/compaction/managers/null.js +3 -0
  30. package/dist/compaction/managers/null.js.map +1 -1
  31. package/dist/compaction/managers/slidingWindow.d.ts +6 -0
  32. package/dist/compaction/managers/slidingWindow.d.ts.map +1 -1
  33. package/dist/compaction/managers/slidingWindow.js +6 -0
  34. package/dist/compaction/managers/slidingWindow.js.map +1 -1
  35. package/dist/compaction/managers/structured.d.ts +10 -0
  36. package/dist/compaction/managers/structured.d.ts.map +1 -1
  37. package/dist/compaction/managers/structured.js +10 -0
  38. package/dist/compaction/managers/structured.js.map +1 -1
  39. package/dist/compaction/reducer.d.ts +86 -0
  40. package/dist/compaction/reducer.d.ts.map +1 -0
  41. package/dist/compaction/reducer.js +77 -0
  42. package/dist/compaction/reducer.js.map +1 -0
  43. package/dist/connector/builtins/__tests__/oauth2-auth.test.d.ts +2 -0
  44. package/dist/connector/builtins/__tests__/oauth2-auth.test.d.ts.map +1 -0
  45. package/dist/connector/builtins/__tests__/oauth2-auth.test.js +54 -0
  46. package/dist/connector/builtins/__tests__/oauth2-auth.test.js.map +1 -0
  47. package/dist/connector/builtins/http.d.ts.map +1 -1
  48. package/dist/connector/builtins/http.js +24 -2
  49. package/dist/connector/builtins/http.js.map +1 -1
  50. package/dist/connector/builtins/http.test.js +18 -2
  51. package/dist/connector/builtins/http.test.js.map +1 -1
  52. package/dist/connector/index.d.ts +2 -2
  53. package/dist/connector/index.d.ts.map +1 -1
  54. package/dist/connector/index.js +1 -1
  55. package/dist/connector/index.js.map +1 -1
  56. package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.d.ts +2 -0
  57. package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.d.ts.map +1 -0
  58. package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.js +214 -0
  59. package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.js.map +1 -0
  60. package/dist/connector/mcp/client.d.ts +52 -1
  61. package/dist/connector/mcp/client.d.ts.map +1 -1
  62. package/dist/connector/mcp/client.js +86 -0
  63. package/dist/connector/mcp/client.js.map +1 -1
  64. package/dist/connector/mcp/discovery.d.ts +12 -1
  65. package/dist/connector/mcp/discovery.d.ts.map +1 -1
  66. package/dist/connector/mcp/discovery.js +19 -4
  67. package/dist/connector/mcp/discovery.js.map +1 -1
  68. package/dist/connector/mcp/index.d.ts +2 -2
  69. package/dist/connector/mcp/index.d.ts.map +1 -1
  70. package/dist/connector/mcp/index.js +1 -1
  71. package/dist/connector/mcp/index.js.map +1 -1
  72. package/dist/connector/mcp/server.d.ts +42 -1
  73. package/dist/connector/mcp/server.d.ts.map +1 -1
  74. package/dist/connector/mcp/server.js +77 -4
  75. package/dist/connector/mcp/server.js.map +1 -1
  76. package/dist/manager/agent/__tests__/depth-limit-authority.test.d.ts +2 -0
  77. package/dist/manager/agent/__tests__/depth-limit-authority.test.d.ts.map +1 -0
  78. package/dist/manager/agent/__tests__/depth-limit-authority.test.js +58 -0
  79. package/dist/manager/agent/__tests__/depth-limit-authority.test.js.map +1 -0
  80. package/dist/plugin/__tests__/discovery-scopes.test.d.ts +2 -0
  81. package/dist/plugin/__tests__/discovery-scopes.test.d.ts.map +1 -0
  82. package/dist/plugin/__tests__/discovery-scopes.test.js +97 -0
  83. package/dist/plugin/__tests__/discovery-scopes.test.js.map +1 -0
  84. package/dist/plugin/__tests__/enable-contributions.test.js +5 -1
  85. package/dist/plugin/__tests__/enable-contributions.test.js.map +1 -1
  86. package/dist/plugin/__tests__/mcp-admission.test.d.ts +2 -0
  87. package/dist/plugin/__tests__/mcp-admission.test.d.ts.map +1 -0
  88. package/dist/plugin/__tests__/mcp-admission.test.js +192 -0
  89. package/dist/plugin/__tests__/mcp-admission.test.js.map +1 -0
  90. package/dist/plugin/lifecycle.d.ts +41 -0
  91. package/dist/plugin/lifecycle.d.ts.map +1 -1
  92. package/dist/plugin/lifecycle.js +29 -1
  93. package/dist/plugin/lifecycle.js.map +1 -1
  94. package/dist/plugin/loader.d.ts +39 -3
  95. package/dist/plugin/loader.d.ts.map +1 -1
  96. package/dist/plugin/loader.js +37 -4
  97. package/dist/plugin/loader.js.map +1 -1
  98. package/dist/public-runtime.d.ts +5 -3
  99. package/dist/public-runtime.d.ts.map +1 -1
  100. package/dist/public-runtime.js +11 -3
  101. package/dist/public-runtime.js.map +1 -1
  102. package/dist/public-types.d.ts +2 -2
  103. package/dist/public-types.d.ts.map +1 -1
  104. package/dist/rag/__tests__/namespace-isolation.test.d.ts +2 -0
  105. package/dist/rag/__tests__/namespace-isolation.test.d.ts.map +1 -0
  106. package/dist/rag/__tests__/namespace-isolation.test.js +80 -0
  107. package/dist/rag/__tests__/namespace-isolation.test.js.map +1 -0
  108. package/dist/rag/ingestion.d.ts.map +1 -1
  109. package/dist/rag/ingestion.js +1 -0
  110. package/dist/rag/ingestion.js.map +1 -1
  111. package/dist/rag/retriever.d.ts.map +1 -1
  112. package/dist/rag/retriever.js +2 -0
  113. package/dist/rag/retriever.js.map +1 -1
  114. package/dist/rag/vector-store.d.ts.map +1 -1
  115. package/dist/rag/vector-store.js +6 -0
  116. package/dist/rag/vector-store.js.map +1 -1
  117. package/dist/registry/tool/execute.d.ts.map +1 -1
  118. package/dist/registry/tool/execute.js +113 -109
  119. package/dist/registry/tool/execute.js.map +1 -1
  120. package/dist/runtime/query/__tests__/capability-negotiation.test.js +59 -0
  121. package/dist/runtime/query/__tests__/capability-negotiation.test.js.map +1 -1
  122. package/dist/runtime/query/__tests__/per-step-skills.test.d.ts +10 -0
  123. package/dist/runtime/query/__tests__/per-step-skills.test.d.ts.map +1 -0
  124. package/dist/runtime/query/__tests__/per-step-skills.test.js +122 -0
  125. package/dist/runtime/query/__tests__/per-step-skills.test.js.map +1 -0
  126. package/dist/runtime/query/__tests__/per-step-tool-choice.test.d.ts +2 -0
  127. package/dist/runtime/query/__tests__/per-step-tool-choice.test.d.ts.map +1 -0
  128. package/dist/runtime/query/__tests__/per-step-tool-choice.test.js +153 -0
  129. package/dist/runtime/query/__tests__/per-step-tool-choice.test.js.map +1 -0
  130. package/dist/runtime/query/__tests__/resume-run.test.d.ts +2 -0
  131. package/dist/runtime/query/__tests__/resume-run.test.d.ts.map +1 -0
  132. package/dist/runtime/query/__tests__/resume-run.test.js +211 -0
  133. package/dist/runtime/query/__tests__/resume-run.test.js.map +1 -0
  134. package/dist/runtime/query/executor.d.ts +1 -0
  135. package/dist/runtime/query/executor.d.ts.map +1 -1
  136. package/dist/runtime/query/executor.js +10 -1
  137. package/dist/runtime/query/executor.js.map +1 -1
  138. package/dist/runtime/query/index.d.ts +10 -0
  139. package/dist/runtime/query/index.d.ts.map +1 -1
  140. package/dist/runtime/query/index.js +26 -0
  141. package/dist/runtime/query/index.js.map +1 -1
  142. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  143. package/dist/runtime/query/iteration/index.js +118 -34
  144. package/dist/runtime/query/iteration/index.js.map +1 -1
  145. package/dist/runtime/query/iteration/phases/compaction-model-routing.test.d.ts +2 -0
  146. package/dist/runtime/query/iteration/phases/compaction-model-routing.test.d.ts.map +1 -0
  147. package/dist/runtime/query/iteration/phases/compaction-model-routing.test.js +96 -0
  148. package/dist/runtime/query/iteration/phases/compaction-model-routing.test.js.map +1 -0
  149. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  150. package/dist/runtime/query/iteration/phases/compaction.js +95 -5
  151. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  152. package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.d.ts +2 -0
  153. package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.d.ts.map +1 -0
  154. package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.js +180 -0
  155. package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.js.map +1 -0
  156. package/dist/runtime/query/iteration/phases/context.d.ts +9 -0
  157. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  158. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  159. package/dist/runtime/query/resume-run.d.ts +70 -0
  160. package/dist/runtime/query/resume-run.d.ts.map +1 -0
  161. package/dist/runtime/query/resume-run.js +46 -0
  162. package/dist/runtime/query/resume-run.js.map +1 -0
  163. package/dist/telemetry/__tests__/model-call-span.test.d.ts +2 -0
  164. package/dist/telemetry/__tests__/model-call-span.test.d.ts.map +1 -0
  165. package/dist/telemetry/__tests__/model-call-span.test.js +147 -0
  166. package/dist/telemetry/__tests__/model-call-span.test.js.map +1 -0
  167. package/dist/telemetry/__tests__/span-closure.test.d.ts +2 -0
  168. package/dist/telemetry/__tests__/span-closure.test.d.ts.map +1 -0
  169. package/dist/telemetry/__tests__/span-closure.test.js +124 -0
  170. package/dist/telemetry/__tests__/span-closure.test.js.map +1 -0
  171. package/dist/tools/advisory/index.js +1 -1
  172. package/dist/tools/advisory/index.js.map +1 -1
  173. package/dist/tools/builtins/__tests__/edit-commits-atomically.test.d.ts +2 -0
  174. package/dist/tools/builtins/__tests__/edit-commits-atomically.test.d.ts.map +1 -0
  175. package/dist/tools/builtins/__tests__/edit-commits-atomically.test.js +78 -0
  176. package/dist/tools/builtins/__tests__/edit-commits-atomically.test.js.map +1 -0
  177. package/dist/tools/builtins/__tests__/edit.test.js +242 -1
  178. package/dist/tools/builtins/__tests__/edit.test.js.map +1 -1
  179. package/dist/tools/builtins/__tests__/stale-file-refusal.test.d.ts +2 -0
  180. package/dist/tools/builtins/__tests__/stale-file-refusal.test.d.ts.map +1 -0
  181. package/dist/tools/builtins/__tests__/stale-file-refusal.test.js +187 -0
  182. package/dist/tools/builtins/__tests__/stale-file-refusal.test.js.map +1 -0
  183. package/dist/tools/builtins/atomic-write-file.d.ts +1 -1
  184. package/dist/tools/builtins/atomic-write-file.d.ts.map +1 -1
  185. package/dist/tools/builtins/atomic-write-file.js +31 -2
  186. package/dist/tools/builtins/atomic-write-file.js.map +1 -1
  187. package/dist/tools/builtins/content-fingerprint.d.ts +23 -0
  188. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -0
  189. package/dist/tools/builtins/content-fingerprint.js +30 -0
  190. package/dist/tools/builtins/content-fingerprint.js.map +1 -0
  191. package/dist/tools/builtins/edit.d.ts.map +1 -1
  192. package/dist/tools/builtins/edit.js +172 -31
  193. package/dist/tools/builtins/edit.js.map +1 -1
  194. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  195. package/dist/tools/builtins/read-file.js +5 -2
  196. package/dist/tools/builtins/read-file.js.map +1 -1
  197. package/dist/tools/builtins/write-file.d.ts.map +1 -1
  198. package/dist/tools/builtins/write-file.js +75 -27
  199. package/dist/tools/builtins/write-file.js.map +1 -1
  200. package/dist/tools/coordinator/__tests__/ask-user-question.test.js +55 -0
  201. package/dist/tools/coordinator/__tests__/ask-user-question.test.js.map +1 -1
  202. package/dist/tools/coordinator/__tests__/plan-dependencies.test.d.ts +2 -0
  203. package/dist/tools/coordinator/__tests__/plan-dependencies.test.d.ts.map +1 -0
  204. package/dist/tools/coordinator/__tests__/plan-dependencies.test.js +126 -0
  205. package/dist/tools/coordinator/__tests__/plan-dependencies.test.js.map +1 -0
  206. package/dist/tools/coordinator/index.d.ts.map +1 -1
  207. package/dist/tools/coordinator/index.js +75 -5
  208. package/dist/tools/coordinator/index.js.map +1 -1
  209. package/dist/tools/coordinator/plan-dependencies.d.ts +43 -0
  210. package/dist/tools/coordinator/plan-dependencies.d.ts.map +1 -0
  211. package/dist/tools/coordinator/plan-dependencies.js +148 -0
  212. package/dist/tools/coordinator/plan-dependencies.js.map +1 -0
  213. package/dist/types/agent/supervisor.d.ts +15 -0
  214. package/dist/types/agent/supervisor.d.ts.map +1 -1
  215. package/dist/types/connector/core.d.ts +34 -0
  216. package/dist/types/connector/core.d.ts.map +1 -1
  217. package/dist/types/connector/definition.d.ts +10 -0
  218. package/dist/types/connector/definition.d.ts.map +1 -1
  219. package/dist/types/connector/mcp.d.ts +13 -0
  220. package/dist/types/connector/mcp.d.ts.map +1 -1
  221. package/dist/types/rag/retrieval.d.ts +16 -0
  222. package/dist/types/rag/retrieval.d.ts.map +1 -1
  223. package/dist/types/rag/storage.d.ts +9 -0
  224. package/dist/types/rag/storage.d.ts.map +1 -1
  225. package/dist/types/rag/vector.d.ts +11 -0
  226. package/dist/types/rag/vector.d.ts.map +1 -1
  227. package/dist/types/router/task-router.d.ts +19 -0
  228. package/dist/types/router/task-router.d.ts.map +1 -1
  229. package/dist/types/run/prepare-step.d.ts +56 -3
  230. package/dist/types/run/prepare-step.d.ts.map +1 -1
  231. package/dist/types/tool/index.d.ts +17 -1
  232. package/dist/types/tool/index.d.ts.map +1 -1
  233. package/dist/types/tool/index.js.map +1 -1
  234. package/dist/types/toolset/index.d.ts +22 -0
  235. package/dist/types/toolset/index.d.ts.map +1 -1
  236. package/package.json +1 -1
  237. package/src/advisory/__tests__/consultation-context.test.ts +191 -0
  238. package/src/advisory/context.ts +32 -0
  239. package/src/advisory/executor.ts +30 -3
  240. package/src/compaction/__tests__/context-reducer.test.ts +239 -0
  241. package/src/compaction/factory.ts +7 -0
  242. package/src/compaction/index.ts +8 -0
  243. package/src/compaction/interface.ts +13 -0
  244. package/src/compaction/managers/null.ts +3 -0
  245. package/src/compaction/managers/slidingWindow.ts +6 -0
  246. package/src/compaction/managers/structured.ts +10 -0
  247. package/src/compaction/reducer.ts +154 -0
  248. package/src/connector/builtins/__tests__/oauth2-auth.test.ts +73 -0
  249. package/src/connector/builtins/http.test.ts +28 -2
  250. package/src/connector/builtins/http.ts +26 -2
  251. package/src/connector/index.ts +6 -2
  252. package/src/connector/mcp/__tests__/prompts-and-lifecycle.test.ts +286 -0
  253. package/src/connector/mcp/client.ts +95 -0
  254. package/src/connector/mcp/discovery.ts +19 -4
  255. package/src/connector/mcp/index.ts +6 -2
  256. package/src/connector/mcp/server.ts +101 -3
  257. package/src/manager/agent/__tests__/depth-limit-authority.test.ts +74 -0
  258. package/src/plugin/__tests__/discovery-scopes.test.ts +133 -0
  259. package/src/plugin/__tests__/enable-contributions.test.ts +5 -1
  260. package/src/plugin/__tests__/mcp-admission.test.ts +242 -0
  261. package/src/plugin/lifecycle.ts +57 -1
  262. package/src/plugin/loader.ts +57 -3
  263. package/src/public-runtime.ts +16 -1
  264. package/src/public-types.ts +5 -0
  265. package/src/rag/__tests__/namespace-isolation.test.ts +109 -0
  266. package/src/rag/ingestion.ts +1 -0
  267. package/src/rag/retriever.ts +2 -0
  268. package/src/rag/vector-store.ts +5 -0
  269. package/src/registry/tool/execute.ts +123 -119
  270. package/src/runtime/query/__tests__/capability-negotiation.test.ts +69 -0
  271. package/src/runtime/query/__tests__/per-step-skills.test.ts +154 -0
  272. package/src/runtime/query/__tests__/per-step-tool-choice.test.ts +180 -0
  273. package/src/runtime/query/__tests__/resume-run.test.ts +262 -0
  274. package/src/runtime/query/executor.ts +9 -1
  275. package/src/runtime/query/index.ts +39 -0
  276. package/src/runtime/query/iteration/index.ts +130 -34
  277. package/src/runtime/query/iteration/phases/compaction-model-routing.test.ts +125 -0
  278. package/src/runtime/query/iteration/phases/compaction.ts +106 -5
  279. package/src/runtime/query/iteration/phases/context-reducer-dispatch.test.ts +238 -0
  280. package/src/runtime/query/iteration/phases/context.ts +11 -0
  281. package/src/runtime/query/resume-run.ts +93 -0
  282. package/src/telemetry/__tests__/model-call-span.test.ts +189 -0
  283. package/src/telemetry/__tests__/span-closure.test.ts +153 -0
  284. package/src/tools/advisory/index.ts +1 -1
  285. package/src/tools/builtins/__tests__/edit-commits-atomically.test.ts +103 -0
  286. package/src/tools/builtins/__tests__/edit.test.ts +324 -1
  287. package/src/tools/builtins/__tests__/stale-file-refusal.test.ts +258 -0
  288. package/src/tools/builtins/atomic-write-file.ts +30 -2
  289. package/src/tools/builtins/content-fingerprint.ts +33 -0
  290. package/src/tools/builtins/edit.ts +188 -36
  291. package/src/tools/builtins/read-file.ts +5 -2
  292. package/src/tools/builtins/write-file.ts +79 -28
  293. package/src/tools/coordinator/__tests__/ask-user-question.test.ts +68 -0
  294. package/src/tools/coordinator/__tests__/plan-dependencies.test.ts +186 -0
  295. package/src/tools/coordinator/index.ts +116 -42
  296. package/src/tools/coordinator/plan-dependencies.ts +175 -0
  297. package/src/types/agent/supervisor.ts +15 -0
  298. package/src/types/connector/core.ts +34 -0
  299. package/src/types/connector/definition.ts +10 -0
  300. package/src/types/connector/mcp.ts +14 -0
  301. package/src/types/rag/retrieval.ts +16 -0
  302. package/src/types/rag/storage.ts +9 -0
  303. package/src/types/rag/vector.ts +11 -0
  304. package/src/types/router/task-router.ts +19 -0
  305. package/src/types/run/prepare-step.ts +58 -3
  306. package/src/types/tool/index.ts +17 -1
  307. package/src/types/toolset/index.ts +22 -0
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Turn the dependencies a model described into the step ids a plan uses.
3
+ *
4
+ * The model is shown `depends_on: string[]` on every plan step, described to
5
+ * it as "Step descriptions this depends on" — descriptions, because that is
6
+ * the only handle it has. Step ids are minted at execute time (`step_1`,
7
+ * `step_2`, ...), so the model cannot name one and should not be asked to.
8
+ *
9
+ * The translation between the two was never written. `approve_plan` passed
10
+ * `dependsOn: []` for every step, so whatever ordering the model declared
11
+ * was dropped at the one place it entered the system. The visible cost is
12
+ * not scheduling — `PlanManager.getNextPendingStep` holds the dependency
13
+ * gate and currently has no callers — it is the APPROVAL: `dependsOn` is
14
+ * serialized into the `plan_approval` payload a human reads before saying
15
+ * yes, so a reviewer was shown a plan whose steps all looked independent
16
+ * however carefully the model had ordered them.
17
+ */
18
+
19
+ /** What the model said, before ids exist. */
20
+ export interface DescribedStep {
21
+ readonly description: string
22
+ readonly depends_on?: readonly string[]
23
+ }
24
+
25
+ export type ResolvedDependencies =
26
+ | { readonly ok: true; readonly dependsOn: readonly (readonly string[])[] }
27
+ | { readonly ok: false; readonly error: string }
28
+
29
+ /**
30
+ * Resolve every step's declared dependencies to step ids, or refuse.
31
+ *
32
+ * Returns one id array per input step, positionally.
33
+ *
34
+ * **Refusing beats dropping.** Every failure here means the model expressed
35
+ * an ordering it cannot have and the plan does not mean what it says; the
36
+ * old behaviour — discard silently — is what put an empty dependency list in
37
+ * front of a human approver. The error text names the offending description
38
+ * so the model can correct it and call again, which is the same shape every
39
+ * other recoverable tool failure in this kernel uses.
40
+ */
41
+ export function resolvePlanDependencies(
42
+ steps: readonly DescribedStep[],
43
+ idOf: (index: number) => string,
44
+ ): ResolvedDependencies {
45
+ const byDescription = new Map<string, number[]>()
46
+ for (let i = 0; i < steps.length; i++) {
47
+ const description = steps[i]?.description
48
+ if (description === undefined) continue
49
+ const key = normalize(description)
50
+ const at = byDescription.get(key)
51
+ if (at) at.push(i)
52
+ else byDescription.set(key, [i])
53
+ }
54
+
55
+ const resolved: string[][] = []
56
+
57
+ for (let i = 0; i < steps.length; i++) {
58
+ const step = steps[i]
59
+ const declared = step?.depends_on
60
+ if (!step || !declared || declared.length === 0) {
61
+ resolved.push([])
62
+ continue
63
+ }
64
+
65
+ const ids: string[] = []
66
+ const seen = new Set<number>()
67
+
68
+ for (const wanted of declared) {
69
+ const matches = byDescription.get(normalize(wanted))
70
+
71
+ if (!matches) {
72
+ return {
73
+ ok: false,
74
+ error: `Step ${i + 1} depends on "${wanted}", which is not the description of any step in this plan. A dependency has to name another step exactly. Fix the description or drop the dependency, then call approve_plan again.`,
75
+ }
76
+ }
77
+
78
+ // Two steps sharing a description make "depends on that one"
79
+ // unanswerable. Picking either is a coin flip whose result a human
80
+ // then approves as if it were the model's intent.
81
+ if (matches.length > 1) {
82
+ return {
83
+ ok: false,
84
+ error: `Step ${i + 1} depends on "${wanted}", but ${matches.length} steps share that description, so it does not identify one. Make the descriptions distinct, then call approve_plan again.`,
85
+ }
86
+ }
87
+
88
+ const target = matches[0] as number
89
+
90
+ if (target === i) {
91
+ return {
92
+ ok: false,
93
+ error: `Step ${i + 1} depends on itself. A step cannot wait for its own completion; remove the dependency and call approve_plan again.`,
94
+ }
95
+ }
96
+
97
+ // Duplicates in one step's list are harmless — same edge twice.
98
+ if (seen.has(target)) continue
99
+ seen.add(target)
100
+ ids.push(idOf(target))
101
+ }
102
+
103
+ resolved.push(ids)
104
+ }
105
+
106
+ // A cycle is the failure worth catching hardest. Every step in one waits
107
+ // for another that is waiting for it, so the dependency gate never
108
+ // releases any of them and a plan that reads as fine simply stops. There
109
+ // is no error to observe at that point — the run just makes no progress.
110
+ const cycle = findCycle(resolved, (index) => idOf(index))
111
+ if (cycle) {
112
+ return {
113
+ ok: false,
114
+ error: `These steps depend on each other in a loop: ${cycle.map((i) => `step ${i + 1} ("${steps[i]?.description ?? ''}")`).join(' -> ')}. No step in a loop can ever start, because each waits for another that is waiting for it. Break the loop and call approve_plan again.`,
115
+ }
116
+ }
117
+
118
+ return { ok: true, dependsOn: resolved }
119
+ }
120
+
121
+ /**
122
+ * Descriptions come from a model, so they carry incidental whitespace and
123
+ * casing differences between the step and the reference to it. Matching on
124
+ * the exact string would reject "Run the tests" against "run the tests " —
125
+ * a refusal the model cannot learn anything from, for a plan that was right.
126
+ */
127
+ function normalize(description: string): string {
128
+ return description.trim().replace(/\s+/g, ' ').toLowerCase()
129
+ }
130
+
131
+ /** Indices forming a dependency cycle, in order, or undefined. */
132
+ function findCycle(
133
+ dependsOn: readonly (readonly string[])[],
134
+ idOf: (index: number) => string,
135
+ ): number[] | undefined {
136
+ const indexOfId = new Map<string, number>()
137
+ for (let i = 0; i < dependsOn.length; i++) indexOfId.set(idOf(i), i)
138
+
139
+ const UNVISITED = 0
140
+ const ON_STACK = 1
141
+ const DONE = 2
142
+ const state = new Array<number>(dependsOn.length).fill(UNVISITED)
143
+ const stack: number[] = []
144
+
145
+ const walk = (node: number): number[] | undefined => {
146
+ state[node] = ON_STACK
147
+ stack.push(node)
148
+
149
+ for (const depId of dependsOn[node] ?? []) {
150
+ const next = indexOfId.get(depId)
151
+ if (next === undefined) continue
152
+ if (state[next] === ON_STACK) {
153
+ // Report the loop itself, not the path that reached it.
154
+ const from = stack.indexOf(next)
155
+ return [...stack.slice(from), next]
156
+ }
157
+ if (state[next] === UNVISITED) {
158
+ const found = walk(next)
159
+ if (found) return found
160
+ }
161
+ }
162
+
163
+ stack.pop()
164
+ state[node] = DONE
165
+ return undefined
166
+ }
167
+
168
+ for (let i = 0; i < dependsOn.length; i++) {
169
+ if (state[i] !== UNVISITED) continue
170
+ const found = walk(i)
171
+ if (found) return found
172
+ }
173
+
174
+ return undefined
175
+ }
@@ -26,6 +26,21 @@ export interface SupervisorAgentConfig extends BaseAgentConfig {
26
26
 
27
27
  skills?: Skill[]
28
28
 
29
+ /**
30
+ * **Not consulted. The limit lives on `AgentManagerConfig.maxDepth`.**
31
+ *
32
+ * A supervisor does not own the recursion bound: it is enforced in
33
+ * `AgentManager.sendMessage`, against the manager's own config, and a
34
+ * supervisor receives a manager rather than building one. So a host that
35
+ * set this got the manager's value regardless — which for a safety limit
36
+ * is the worst way to be wrong, because the number in front of the
37
+ * reviewer is not the number in force.
38
+ *
39
+ * Stated rather than removed: it is reachable from the published
40
+ * typings, so it goes in the next major. Set the bound where it is read.
41
+ *
42
+ * @deprecated Set `maxDepth` on the `AgentManagerConfig` instead.
43
+ */
29
44
  maxDepth?: number
30
45
 
31
46
  taskRouter?: TaskRouterConfig
@@ -28,9 +28,43 @@ export interface ConnectorMethod<TInput = unknown, TOutput = unknown> {
28
28
  name: string
29
29
  description: string
30
30
  inputSchema: z.ZodType<TInput, z.ZodTypeDef, unknown>
31
+ /**
32
+ * **Not consulted.** Neither in-tree connector declares one, and nothing
33
+ * validates a result against it or shows it to a model.
34
+ *
35
+ * The tool layer solved the same problem already: a remote tool's output
36
+ * schema is appended to its description by `describeWithOutput`, because
37
+ * no provider's tool wire format has a slot for one. A connector method
38
+ * that reaches a model through that bridge should take the same route
39
+ * rather than growing a second mechanism.
40
+ */
31
41
  outputSchema?: z.ZodType<TOutput, z.ZodTypeDef, unknown>
32
42
  }
33
43
 
44
+ /**
45
+ * **Declared, not implemented.** Nothing reads a trigger and nothing emits
46
+ * a {@link ConnectorEvent}; no inbound event starts a run today.
47
+ *
48
+ * Said here rather than left to be discovered, because a connector author
49
+ * who declares triggers gets no error and no events — the worst combination
50
+ * to debug. The shape is kept because it is right: a trigger names an
51
+ * upstream event and the config a subscription needs.
52
+ *
53
+ * What is missing is not the type but the delivery half, and it is a larger
54
+ * piece than it looks. An inbound event has to be de-duplicated across
55
+ * processes, since the same webhook is retried and the same poll can
56
+ * overlap; that needs a compare-and-set claim, and the only durable write
57
+ * primitive here is an atomic file REPLACE, which is last-writer-wins and
58
+ * cannot express one. It also needs a release path for an event claimed by
59
+ * a process that then dies, or the first crash silently drops that event
60
+ * forever.
61
+ *
62
+ * Two of those parts already exist and should be reused rather than
63
+ * rebuilt when this is built: `AbstractAgent.underIdempotencyKey` is the
64
+ * in-process dedupe seam and names the cross-process half as its known
65
+ * gap, and `EditOwnershipTracker.claim` is the claim/refuse shape with
66
+ * same-owner idempotency already worked out.
67
+ */
34
68
  export interface ConnectorTrigger {
35
69
  name: string
36
70
  description: string
@@ -17,9 +17,19 @@ export interface ConnectorDefinition<TConfig = unknown> {
17
17
  version?: string
18
18
  category?: ConnectorCategory
19
19
  connectionType: ConnectionType
20
+ /**
21
+ * **Not consulted.** A connector declaring this is not checked against
22
+ * the auth an instance is actually configured with, so a mismatch
23
+ * surfaces as a 401 from the upstream rather than as a refusal here.
24
+ *
25
+ * Worth wiring where instances are created, not at request time: the
26
+ * point of declaring supported schemes is to reject a misconfiguration
27
+ * before anything is sent.
28
+ */
20
29
  supportedAuth?: AuthType[]
21
30
  configSchema: z.ZodType<TConfig, z.ZodTypeDef, unknown>
22
31
  methods: ConnectorMethod[]
32
+ /** Declared, not implemented — see {@link ConnectorTrigger}. */
23
33
  triggers?: ConnectorTrigger[]
24
34
  }
25
35
 
@@ -145,6 +145,20 @@ export interface MCPPromptDefinition {
145
145
  arguments?: MCPPromptArgument[]
146
146
  }
147
147
 
148
+ /**
149
+ * One message of a prompt the server composed.
150
+ *
151
+ * Deliberately its own shape rather than the kernel's `Message`: this is
152
+ * what a remote server said, before anything decides whether to believe it.
153
+ * Converting at the boundary is what keeps a server's `role` from becoming
154
+ * a role in this agent's history by accident — a server that returns an
155
+ * `assistant` message is claiming the agent already said something.
156
+ */
157
+ export interface MCPPromptMessage {
158
+ role: 'user' | 'assistant'
159
+ content: MCPContentBlock
160
+ }
161
+
148
162
  export interface MCPClientCapabilities {
149
163
  roots?: { listChanged?: boolean }
150
164
  sampling?: Record<string, never>
@@ -14,6 +14,22 @@ export interface RetrievalConfig {
14
14
 
15
15
  export interface RetrievalQuery {
16
16
  text: string
17
+ /**
18
+ * **Not consulted.** No chunk carries a project, so there is nothing to
19
+ * match it against: ingestion stamps a tenant and a namespace, and
20
+ * `KnowledgeBaseConfig` has no project field to stamp a third from.
21
+ *
22
+ * Left declared and said out loud rather than quietly filtering on it.
23
+ * Wiring one end of an isolation dimension is worse than wiring
24
+ * neither — a query that filters against a value nothing writes returns
25
+ * zero rows, and "no results" reads as "nothing matched" rather than
26
+ * "this scope does not exist". Partition with
27
+ * {@link TenantScope.namespace}, which is stamped at ingest and matched
28
+ * at search.
29
+ *
30
+ * @deprecated Use `TenantScope.namespace` until a project reaches
31
+ * ingestion.
32
+ */
17
33
  projectId?: ProjectId
18
34
  recentMessages?: string[]
19
35
  config?: Partial<RetrievalConfig>
@@ -16,6 +16,15 @@ export interface Chunk {
16
16
  documentId: DocumentId
17
17
  knowledgeBaseId: KnowledgeBaseId
18
18
  tenantId: TenantId
19
+ /**
20
+ * The partition this chunk was ingested into, from `TenantScope`.
21
+ *
22
+ * `TenantScope.namespace` and `KnowledgeBaseConfig.namespace` were both
23
+ * declared from the start and neither reached storage: ingestion copied
24
+ * `scope.tenantId` onto every chunk and dropped the namespace, so a
25
+ * partition a host had asked for did not exist at all.
26
+ */
27
+ namespace?: string
19
28
  content: string
20
29
  index: number
21
30
  tokenCount: number
@@ -11,6 +11,17 @@ export interface VectorStoreQuery {
11
11
  topK: number
12
12
  tenantId: TenantId
13
13
  knowledgeBaseId?: KnowledgeBaseId
14
+ /**
15
+ * The partition to search. Matched by equality, INCLUDING absence.
16
+ *
17
+ * An omitted namespace means "the default partition", not "no filter".
18
+ * Reading it as "no filter" is how an isolation boundary leaks: a caller
19
+ * who never asked for a namespace would see every namespaced chunk in
20
+ * the tenant, which is the opposite of what partitioning is for. A
21
+ * caller who genuinely wants everything asks the store for each
22
+ * namespace it holds.
23
+ */
24
+ namespace?: string
14
25
  filter?: Record<string, unknown>
15
26
  minScore?: number
16
27
  }
@@ -8,6 +8,25 @@ export type TaskType =
8
8
  | 'advisory'
9
9
  | 'default'
10
10
 
11
+ /**
12
+ * Send a particular kind of work to a particular model.
13
+ *
14
+ * **Which keys the runtime consults today: `compaction`, and `default` as its
15
+ * fallback.** That is stated because the rest are silently inert, and an
16
+ * inert key is worse than an absent one — a host who sets `coding` reads it
17
+ * as taking effect. The compaction summary is the call worth routing first
18
+ * regardless: it is the only model call a run makes that nobody asked for,
19
+ * it reads a transcript and writes a summary, and it fires on exactly the
20
+ * long runs where the primary model costs the most.
21
+ *
22
+ * The remaining keys describe sub-agent routing. `SupervisorAgent` already
23
+ * threads this config down to the agent factory, but nothing classifies a
24
+ * spawned task as exploration or coding, and guessing a classifier here
25
+ * would put a wrong model behind a right-looking config.
26
+ *
27
+ * `advisory` is deliberately not consulted: an advisor carries its own
28
+ * `model`, so routing would override an explicit choice with a general one.
29
+ */
11
30
  export interface TaskRouterConfig {
12
31
  readonly compaction?: string | null
13
32
  readonly summarization?: string | null
@@ -1,5 +1,7 @@
1
1
  import type { RunId } from '../ids/index.js'
2
2
  import type { Message } from '../message/index.js'
3
+ import type { ToolChoice } from '../provider/chat.js'
4
+ import type { Skill } from '../skills/index.js'
3
5
  import type { StepResult } from './step.js'
4
6
 
5
7
  /**
@@ -51,12 +53,65 @@ export interface PrepareStepResult {
51
53
  * it is worth doing when a phase boundary genuinely changes what the
52
54
  * agent should reach for — and not worth doing every step.
53
55
  *
54
- * Note it does NOT touch `tool_choice`. Not every provider has an `allowed_tools`
55
- * parameter, and moving `tool_choice` invalidates cached MESSAGE blocks
56
- * as well — a strictly worse trade for the same effect.
56
+ * Note it does NOT imply a `tool_choice`. Not every provider has an
57
+ * `allowed_tools` parameter, and moving `tool_choice` invalidates cached
58
+ * MESSAGE blocks as well — a strictly worse trade for the same effect.
59
+ * When a step genuinely needs the model FORCED rather than narrowed, ask
60
+ * for it explicitly through {@link PrepareStepResult.toolChoice} and pay
61
+ * that cost knowingly.
57
62
  */
58
63
  readonly activeTools?: readonly string[]
59
64
 
65
+ /**
66
+ * Force this step's tool use: `'required'` to make the model call
67
+ * something, `'none'` to forbid it, or a named function to demand that
68
+ * one. Absent leaves the provider's default.
69
+ *
70
+ * **It applies to this step only, by construction.** That is the whole
71
+ * reason it lives here rather than on the run config. A forced choice
72
+ * that persists makes the model call a tool, see the result, and be
73
+ * forced again — an agent that cannot stop. The one peer SDK that puts
74
+ * `tool_choice` on persistent model settings has to undo it with a
75
+ * tool-use tracker, an opt-out flag and a reset applied at two call
76
+ * sites; the flag defaults to on precisely because turning it off hangs
77
+ * the agent. Here there is nothing to reset and no flag to get wrong:
78
+ * the next step is prepared fresh, so the force cannot outlive the step
79
+ * that asked for it.
80
+ *
81
+ * **It costs more cache than `activeTools`.** Narrowing tools
82
+ * invalidates the tool prefix; moving `tool_choice` invalidates cached
83
+ * message blocks too. Worth it at a real phase boundary — "this step
84
+ * must produce the structured answer" — and not worth it as a habit.
85
+ */
86
+ readonly toolChoice?: ToolChoice
87
+
88
+ /**
89
+ * Put these skills in front of the model for this step only.
90
+ *
91
+ * A run's skills are fixed at `query()` time and rendered into the cached
92
+ * system prefix, so every skill a run might ever need is paid for on
93
+ * every single turn. A phased agent rarely needs them all at once —
94
+ * research wants the search skill, writing wants the style guide, and
95
+ * neither benefits from carrying the other.
96
+ *
97
+ * Rendered into the same ephemeral trailing system message `system`
98
+ * uses, and for the same reason: appending leaves the cached prefix
99
+ * intact, where rewriting the run's prompt would invalidate it every
100
+ * iteration for what is usually one phase's worth of guidance.
101
+ *
102
+ * ADDITIVE to the run's skills, not a replacement. A skill the run
103
+ * always carries is not something a step should be able to take away by
104
+ * naming a different one — that would make every step's list a complete
105
+ * restatement, and a phase that forgot one would silently lose it.
106
+ *
107
+ * Sub-agents are deliberately NOT per-step. Which agents `create_task`
108
+ * can reach is baked into that tool's input schema, so varying it would
109
+ * rebuild the tool catalogue every step — a worse prompt-cache trade
110
+ * than moving tools, for a narrowing a step can already express by
111
+ * withholding `create_task` through {@link PrepareStepResult.activeTools}.
112
+ */
113
+ readonly skills?: readonly Skill[]
114
+
60
115
  /** Use a different model for this step. */
61
116
  readonly model?: string
62
117
 
@@ -19,8 +19,24 @@ export interface ToolRegistryRef {
19
19
  * is active, absolute (`workingDirectory`-resolved) otherwise.
20
20
  */
21
21
  export interface FileReadTracker {
22
- recordRead(key: string): void
22
+ /**
23
+ * `content` lets the tracker fingerprint what was read, which is what
24
+ * makes drift detectable later. Optional so a host that only needs the
25
+ * read-before-overwrite guard can keep its existing implementation.
26
+ */
27
+ recordRead(key: string, content?: string): void
23
28
  hasRead(key: string): boolean
29
+ /**
30
+ * Fingerprint of the body captured at the last read, when one was.
31
+ *
32
+ * A file mutation is computed against what the agent READ, and between
33
+ * that read and the write the file may have moved under it — a person
34
+ * editing in an editor, another process, a second agent. The in-process
35
+ * lock cannot see any of those. Comparing this against the body actually
36
+ * on disk at mutation time is what turns a silent lost update into a
37
+ * refusal the agent can act on by re-reading.
38
+ */
39
+ fingerprint?(key: string): string | undefined
24
40
  }
25
41
 
26
42
  export interface ToolPauseOption {
@@ -1,5 +1,21 @@
1
1
  import type { LLMToolSchema, ToolDefinition, ToolPermission } from '../tool/index.js'
2
2
 
3
+ /**
4
+ * @deprecated Slated for removal in the next major. Nothing produces or
5
+ * reads it — no code constructs any member, and `ToolsetPolicy.surfaces`,
6
+ * the only field that carries it, is never consulted.
7
+ *
8
+ * It is also the wrong axis. Which tools a run may use is already
9
+ * expressible four ways, all of them per-run and dynamic where this is
10
+ * fixed at definition: `allowedTools` on the query, `ToolAvailability`
11
+ * (`active` / `deferred` / `suspended`) with mid-run activation,
12
+ * `runtimeToolOverrides`, and capability negotiation stripping tools a
13
+ * driver cannot carry. Prefer `allowedTools`.
14
+ *
15
+ * The member names encode deployment shapes this kernel does not own,
16
+ * which is the deeper reason not to keep them: a host's surfaces are the
17
+ * host's to name.
18
+ */
3
19
  export type ToolCatalogSurface = 'chat' | 'supervised' | 'managed-agent' | 'worker' | 'code'
4
20
 
5
21
  export type ToolSourceKind =
@@ -41,6 +57,12 @@ export interface ToolsetPolicy {
41
57
  readonly enabled?: boolean
42
58
  readonly loading?: ToolLoadingMode
43
59
  readonly preferred?: boolean
60
+ /**
61
+ * @deprecated Slated for removal in the next major. Never read by
62
+ * anything — setting it has no effect today. Use `allowedTools` on the
63
+ * query to bound which tools a run may use; it says the same thing per
64
+ * run instead of per definition. See {@link ToolCatalogSurface}.
65
+ */
44
66
  readonly surfaces?: readonly ToolCatalogSurface[]
45
67
  readonly providerConfig?: Record<string, unknown>
46
68
  }