@stigmer/runner 0.1.0-dev.20261017020314.g644422724c27

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 (2029) hide show
  1. package/LICENSE +194 -0
  2. package/README.md +310 -0
  3. package/dist/.build-fingerprint +1 -0
  4. package/dist/__test-utils__/approval-contract/hook-commands.d.ts +25 -0
  5. package/dist/__test-utils__/approval-contract/hook-commands.js +87 -0
  6. package/dist/__test-utils__/approval-contract/hook-commands.js.map +1 -0
  7. package/dist/__test-utils__/approval-contract/types.d.ts +326 -0
  8. package/dist/__test-utils__/approval-contract/types.js +24 -0
  9. package/dist/__test-utils__/approval-contract/types.js.map +1 -0
  10. package/dist/__test-utils__/approval-log.d.ts +34 -0
  11. package/dist/__test-utils__/approval-log.js +126 -0
  12. package/dist/__test-utils__/approval-log.js.map +1 -0
  13. package/dist/__test-utils__/execution-record-fixture.d.ts +121 -0
  14. package/dist/__test-utils__/execution-record-fixture.js +134 -0
  15. package/dist/__test-utils__/execution-record-fixture.js.map +1 -0
  16. package/dist/__test-utils__/file-review-projection.d.ts +45 -0
  17. package/dist/__test-utils__/file-review-projection.js +61 -0
  18. package/dist/__test-utils__/file-review-projection.js.map +1 -0
  19. package/dist/__test-utils__/harness-contract/types.d.ts +188 -0
  20. package/dist/__test-utils__/harness-contract/types.js +64 -0
  21. package/dist/__test-utils__/harness-contract/types.js.map +1 -0
  22. package/dist/__test-utils__/hermetic-activity.d.ts +450 -0
  23. package/dist/__test-utils__/hermetic-activity.js +883 -0
  24. package/dist/__test-utils__/hermetic-activity.js.map +1 -0
  25. package/dist/__test-utils__/loopback-host.d.ts +23 -0
  26. package/dist/__test-utils__/loopback-host.js +45 -0
  27. package/dist/__test-utils__/loopback-host.js.map +1 -0
  28. package/dist/__test-utils__/mock-client.d.ts +13 -0
  29. package/dist/__test-utils__/mock-client.js +46 -0
  30. package/dist/__test-utils__/mock-client.js.map +1 -0
  31. package/dist/__test-utils__/mock-workspace.d.ts +15 -0
  32. package/dist/__test-utils__/mock-workspace.js +21 -0
  33. package/dist/__test-utils__/mock-workspace.js.map +1 -0
  34. package/dist/__test-utils__/model-registry-fixture.d.ts +111 -0
  35. package/dist/__test-utils__/model-registry-fixture.js +109 -0
  36. package/dist/__test-utils__/model-registry-fixture.js.map +1 -0
  37. package/dist/__test-utils__/turn-input-fixture.d.ts +60 -0
  38. package/dist/__test-utils__/turn-input-fixture.js +129 -0
  39. package/dist/__test-utils__/turn-input-fixture.js.map +1 -0
  40. package/dist/activities/attach-session.d.ts +34 -0
  41. package/dist/activities/attach-session.js +94 -0
  42. package/dist/activities/attach-session.js.map +1 -0
  43. package/dist/activities/ensure-thread.d.ts +24 -0
  44. package/dist/activities/ensure-thread.js +44 -0
  45. package/dist/activities/ensure-thread.js.map +1 -0
  46. package/dist/activities/execute-cursor/__test-utils__/contract-subject.d.ts +107 -0
  47. package/dist/activities/execute-cursor/__test-utils__/contract-subject.js +392 -0
  48. package/dist/activities/execute-cursor/__test-utils__/contract-subject.js.map +1 -0
  49. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.d.ts +251 -0
  50. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js +254 -0
  51. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js.map +1 -0
  52. package/dist/activities/execute-cursor/__test-utils__/fold.d.ts +62 -0
  53. package/dist/activities/execute-cursor/__test-utils__/fold.js +94 -0
  54. package/dist/activities/execute-cursor/__test-utils__/fold.js.map +1 -0
  55. package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.d.ts +34 -0
  56. package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js +287 -0
  57. package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js.map +1 -0
  58. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.d.ts +202 -0
  59. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js +306 -0
  60. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js.map +1 -0
  61. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.d.ts +176 -0
  62. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js +278 -0
  63. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js.map +1 -0
  64. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.d.ts +182 -0
  65. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js +241 -0
  66. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js.map +1 -0
  67. package/dist/activities/execute-cursor/adapter.d.ts +63 -0
  68. package/dist/activities/execute-cursor/adapter.js +141 -0
  69. package/dist/activities/execute-cursor/adapter.js.map +1 -0
  70. package/dist/activities/execute-cursor/agent-session-cache.d.ts +72 -0
  71. package/dist/activities/execute-cursor/agent-session-cache.js +186 -0
  72. package/dist/activities/execute-cursor/agent-session-cache.js.map +1 -0
  73. package/dist/activities/execute-cursor/approval-policy.d.ts +67 -0
  74. package/dist/activities/execute-cursor/approval-policy.js +101 -0
  75. package/dist/activities/execute-cursor/approval-policy.js.map +1 -0
  76. package/dist/activities/execute-cursor/approval-state.d.ts +657 -0
  77. package/dist/activities/execute-cursor/approval-state.js +682 -0
  78. package/dist/activities/execute-cursor/approval-state.js.map +1 -0
  79. package/dist/activities/execute-cursor/boundary-rows.d.ts +455 -0
  80. package/dist/activities/execute-cursor/boundary-rows.js +1268 -0
  81. package/dist/activities/execute-cursor/boundary-rows.js.map +1 -0
  82. package/dist/activities/execute-cursor/cas-observations.d.ts +126 -0
  83. package/dist/activities/execute-cursor/cas-observations.js +240 -0
  84. package/dist/activities/execute-cursor/cas-observations.js.map +1 -0
  85. package/dist/activities/execute-cursor/cursor-capabilities.d.ts +37 -0
  86. package/dist/activities/execute-cursor/cursor-capabilities.js +74 -0
  87. package/dist/activities/execute-cursor/cursor-capabilities.js.map +1 -0
  88. package/dist/activities/execute-cursor/cursor-event-recorder.d.ts +43 -0
  89. package/dist/activities/execute-cursor/cursor-event-recorder.js +88 -0
  90. package/dist/activities/execute-cursor/cursor-event-recorder.js.map +1 -0
  91. package/dist/activities/execute-cursor/cursor-mcp-config.d.ts +58 -0
  92. package/dist/activities/execute-cursor/cursor-mcp-config.js +86 -0
  93. package/dist/activities/execute-cursor/cursor-mcp-config.js.map +1 -0
  94. package/dist/activities/execute-cursor/cursor-mode.d.ts +32 -0
  95. package/dist/activities/execute-cursor/cursor-mode.js +36 -0
  96. package/dist/activities/execute-cursor/cursor-mode.js.map +1 -0
  97. package/dist/activities/execute-cursor/error-classifier.d.ts +138 -0
  98. package/dist/activities/execute-cursor/error-classifier.js +330 -0
  99. package/dist/activities/execute-cursor/error-classifier.js.map +1 -0
  100. package/dist/activities/execute-cursor/fetch-interceptor.d.ts +56 -0
  101. package/dist/activities/execute-cursor/fetch-interceptor.js +378 -0
  102. package/dist/activities/execute-cursor/fetch-interceptor.js.map +1 -0
  103. package/dist/activities/execute-cursor/hook-scope.d.ts +143 -0
  104. package/dist/activities/execute-cursor/hook-scope.js +149 -0
  105. package/dist/activities/execute-cursor/hook-scope.js.map +1 -0
  106. package/dist/activities/execute-cursor/hook-script.d.ts +172 -0
  107. package/dist/activities/execute-cursor/hook-script.js +1204 -0
  108. package/dist/activities/execute-cursor/hook-script.js.map +1 -0
  109. package/dist/activities/execute-cursor/hook-server.d.ts +152 -0
  110. package/dist/activities/execute-cursor/hook-server.js +422 -0
  111. package/dist/activities/execute-cursor/hook-server.js.map +1 -0
  112. package/dist/activities/execute-cursor/hook-tool-hiding.d.ts +37 -0
  113. package/dist/activities/execute-cursor/hook-tool-hiding.js +58 -0
  114. package/dist/activities/execute-cursor/hook-tool-hiding.js.map +1 -0
  115. package/dist/activities/execute-cursor/hook-views.d.ts +74 -0
  116. package/dist/activities/execute-cursor/hook-views.js +180 -0
  117. package/dist/activities/execute-cursor/hook-views.js.map +1 -0
  118. package/dist/activities/execute-cursor/http2-interceptor.d.ts +98 -0
  119. package/dist/activities/execute-cursor/http2-interceptor.js +218 -0
  120. package/dist/activities/execute-cursor/http2-interceptor.js.map +1 -0
  121. package/dist/activities/execute-cursor/model-pricing-data.d.ts +39 -0
  122. package/dist/activities/execute-cursor/model-pricing-data.js +109 -0
  123. package/dist/activities/execute-cursor/model-pricing-data.js.map +1 -0
  124. package/dist/activities/execute-cursor/model-pricing.d.ts +51 -0
  125. package/dist/activities/execute-cursor/model-pricing.js +160 -0
  126. package/dist/activities/execute-cursor/model-pricing.js.map +1 -0
  127. package/dist/activities/execute-cursor/prompt-builder.d.ts +437 -0
  128. package/dist/activities/execute-cursor/prompt-builder.js +719 -0
  129. package/dist/activities/execute-cursor/prompt-builder.js.map +1 -0
  130. package/dist/activities/execute-cursor/rejection-capture.d.ts +27 -0
  131. package/dist/activities/execute-cursor/rejection-capture.js +78 -0
  132. package/dist/activities/execute-cursor/rejection-capture.js.map +1 -0
  133. package/dist/activities/execute-cursor/run-telemetry.d.ts +61 -0
  134. package/dist/activities/execute-cursor/run-telemetry.js +149 -0
  135. package/dist/activities/execute-cursor/run-telemetry.js.map +1 -0
  136. package/dist/activities/execute-cursor/sdk-warmup.d.ts +53 -0
  137. package/dist/activities/execute-cursor/sdk-warmup.js +70 -0
  138. package/dist/activities/execute-cursor/sdk-warmup.js.map +1 -0
  139. package/dist/activities/execute-cursor/service-tier.d.ts +68 -0
  140. package/dist/activities/execute-cursor/service-tier.js +200 -0
  141. package/dist/activities/execute-cursor/service-tier.js.map +1 -0
  142. package/dist/activities/execute-cursor/session-lifecycle.d.ts +247 -0
  143. package/dist/activities/execute-cursor/session-lifecycle.js +330 -0
  144. package/dist/activities/execute-cursor/session-lifecycle.js.map +1 -0
  145. package/dist/activities/execute-cursor/session-store.d.ts +99 -0
  146. package/dist/activities/execute-cursor/session-store.js +156 -0
  147. package/dist/activities/execute-cursor/session-store.js.map +1 -0
  148. package/dist/activities/execute-cursor/sub-agent-steps.d.ts +79 -0
  149. package/dist/activities/execute-cursor/sub-agent-steps.js +180 -0
  150. package/dist/activities/execute-cursor/sub-agent-steps.js.map +1 -0
  151. package/dist/activities/execute-cursor/subagent-config.d.ts +61 -0
  152. package/dist/activities/execute-cursor/subagent-config.js +102 -0
  153. package/dist/activities/execute-cursor/subagent-config.js.map +1 -0
  154. package/dist/activities/execute-cursor/tool-result.d.ts +49 -0
  155. package/dist/activities/execute-cursor/tool-result.js +130 -0
  156. package/dist/activities/execute-cursor/tool-result.js.map +1 -0
  157. package/dist/activities/execute-cursor/translator.d.ts +183 -0
  158. package/dist/activities/execute-cursor/translator.js +485 -0
  159. package/dist/activities/execute-cursor/translator.js.map +1 -0
  160. package/dist/activities/execute-cursor/turn-boundary.d.ts +124 -0
  161. package/dist/activities/execute-cursor/turn-boundary.js +210 -0
  162. package/dist/activities/execute-cursor/turn-boundary.js.map +1 -0
  163. package/dist/activities/execute-cursor/turn-recovery.d.ts +62 -0
  164. package/dist/activities/execute-cursor/turn-recovery.js +208 -0
  165. package/dist/activities/execute-cursor/turn-recovery.js.map +1 -0
  166. package/dist/activities/execute-cursor/turn-settle.d.ts +59 -0
  167. package/dist/activities/execute-cursor/turn-settle.js +512 -0
  168. package/dist/activities/execute-cursor/turn-settle.js.map +1 -0
  169. package/dist/activities/execute-cursor/turn-setup.d.ts +281 -0
  170. package/dist/activities/execute-cursor/turn-setup.js +739 -0
  171. package/dist/activities/execute-cursor/turn-setup.js.map +1 -0
  172. package/dist/activities/execute-cursor/turn-stream.d.ts +133 -0
  173. package/dist/activities/execute-cursor/turn-stream.js +239 -0
  174. package/dist/activities/execute-cursor/turn-stream.js.map +1 -0
  175. package/dist/activities/execute-cursor/turn.d.ts +46 -0
  176. package/dist/activities/execute-cursor/turn.js +247 -0
  177. package/dist/activities/execute-cursor/turn.js.map +1 -0
  178. package/dist/activities/execute-cursor/usage-pricing.d.ts +38 -0
  179. package/dist/activities/execute-cursor/usage-pricing.js +50 -0
  180. package/dist/activities/execute-cursor/usage-pricing.js.map +1 -0
  181. package/dist/activities/execute-cursor/workspace-hook-files.d.ts +116 -0
  182. package/dist/activities/execute-cursor/workspace-hook-files.js +390 -0
  183. package/dist/activities/execute-cursor/workspace-hook-files.js.map +1 -0
  184. package/dist/activities/execute-cursor/workspace-setup.d.ts +148 -0
  185. package/dist/activities/execute-cursor/workspace-setup.js +444 -0
  186. package/dist/activities/execute-cursor/workspace-setup.js.map +1 -0
  187. package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.d.ts +102 -0
  188. package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.js +361 -0
  189. package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.js.map +1 -0
  190. package/dist/activities/execute-deep-agent/__test-utils__/gateway-substrate.d.ts +33 -0
  191. package/dist/activities/execute-deep-agent/__test-utils__/gateway-substrate.js +423 -0
  192. package/dist/activities/execute-deep-agent/__test-utils__/gateway-substrate.js.map +1 -0
  193. package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.d.ts +224 -0
  194. package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.js +307 -0
  195. package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.js.map +1 -0
  196. package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.d.ts +24 -0
  197. package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.js +41 -0
  198. package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.js.map +1 -0
  199. package/dist/activities/execute-deep-agent/__test-utils__/paused-session-fixture.d.ts +76 -0
  200. package/dist/activities/execute-deep-agent/__test-utils__/paused-session-fixture.js +112 -0
  201. package/dist/activities/execute-deep-agent/__test-utils__/paused-session-fixture.js.map +1 -0
  202. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.d.ts +53 -0
  203. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.js +71 -0
  204. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.js.map +1 -0
  205. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.d.ts +305 -0
  206. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.js +368 -0
  207. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.js.map +1 -0
  208. package/dist/activities/execute-deep-agent/__test-utils__/think-bound-session.d.ts +17 -0
  209. package/dist/activities/execute-deep-agent/__test-utils__/think-bound-session.js +23 -0
  210. package/dist/activities/execute-deep-agent/__test-utils__/think-bound-session.js.map +1 -0
  211. package/dist/activities/execute-deep-agent/__test-utils__/v3-event-fixtures.d.ts +80 -0
  212. package/dist/activities/execute-deep-agent/__test-utils__/v3-event-fixtures.js +195 -0
  213. package/dist/activities/execute-deep-agent/__test-utils__/v3-event-fixtures.js.map +1 -0
  214. package/dist/activities/execute-deep-agent/adapter.d.ts +41 -0
  215. package/dist/activities/execute-deep-agent/adapter.js +79 -0
  216. package/dist/activities/execute-deep-agent/adapter.js.map +1 -0
  217. package/dist/activities/execute-deep-agent/approval-file-change.d.ts +54 -0
  218. package/dist/activities/execute-deep-agent/approval-file-change.js +68 -0
  219. package/dist/activities/execute-deep-agent/approval-file-change.js.map +1 -0
  220. package/dist/activities/execute-deep-agent/auto-publish.d.ts +17 -0
  221. package/dist/activities/execute-deep-agent/auto-publish.js +71 -0
  222. package/dist/activities/execute-deep-agent/auto-publish.js.map +1 -0
  223. package/dist/activities/execute-deep-agent/cas-capture-backend.d.ts +84 -0
  224. package/dist/activities/execute-deep-agent/cas-capture-backend.js +106 -0
  225. package/dist/activities/execute-deep-agent/cas-capture-backend.js.map +1 -0
  226. package/dist/activities/execute-deep-agent/cas-capture-observer.d.ts +83 -0
  227. package/dist/activities/execute-deep-agent/cas-capture-observer.js +117 -0
  228. package/dist/activities/execute-deep-agent/cas-capture-observer.js.map +1 -0
  229. package/dist/activities/execute-deep-agent/deep-agent-capabilities.d.ts +32 -0
  230. package/dist/activities/execute-deep-agent/deep-agent-capabilities.js +45 -0
  231. package/dist/activities/execute-deep-agent/deep-agent-capabilities.js.map +1 -0
  232. package/dist/activities/execute-deep-agent/deepagents-profiles.d.ts +30 -0
  233. package/dist/activities/execute-deep-agent/deepagents-profiles.js +46 -0
  234. package/dist/activities/execute-deep-agent/deepagents-profiles.js.map +1 -0
  235. package/dist/activities/execute-deep-agent/engine-tools.d.ts +32 -0
  236. package/dist/activities/execute-deep-agent/engine-tools.js +32 -0
  237. package/dist/activities/execute-deep-agent/engine-tools.js.map +1 -0
  238. package/dist/activities/execute-deep-agent/hitl.d.ts +126 -0
  239. package/dist/activities/execute-deep-agent/hitl.js +194 -0
  240. package/dist/activities/execute-deep-agent/hitl.js.map +1 -0
  241. package/dist/activities/execute-deep-agent/hooks-setup.d.ts +25 -0
  242. package/dist/activities/execute-deep-agent/hooks-setup.js +59 -0
  243. package/dist/activities/execute-deep-agent/hooks-setup.js.map +1 -0
  244. package/dist/activities/execute-deep-agent/inline-publisher.d.ts +83 -0
  245. package/dist/activities/execute-deep-agent/inline-publisher.js +152 -0
  246. package/dist/activities/execute-deep-agent/inline-publisher.js.map +1 -0
  247. package/dist/activities/execute-deep-agent/platform-route.d.ts +145 -0
  248. package/dist/activities/execute-deep-agent/platform-route.js +237 -0
  249. package/dist/activities/execute-deep-agent/platform-route.js.map +1 -0
  250. package/dist/activities/execute-deep-agent/prompt-builder.d.ts +189 -0
  251. package/dist/activities/execute-deep-agent/prompt-builder.js +369 -0
  252. package/dist/activities/execute-deep-agent/prompt-builder.js.map +1 -0
  253. package/dist/activities/execute-deep-agent/resumed-history.d.ts +25 -0
  254. package/dist/activities/execute-deep-agent/resumed-history.js +47 -0
  255. package/dist/activities/execute-deep-agent/resumed-history.js.map +1 -0
  256. package/dist/activities/execute-deep-agent/streaming-side-effects.d.ts +49 -0
  257. package/dist/activities/execute-deep-agent/streaming-side-effects.js +73 -0
  258. package/dist/activities/execute-deep-agent/streaming-side-effects.js.map +1 -0
  259. package/dist/activities/execute-deep-agent/subagent-transformer.d.ts +253 -0
  260. package/dist/activities/execute-deep-agent/subagent-transformer.js +474 -0
  261. package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -0
  262. package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +99 -0
  263. package/dist/activities/execute-deep-agent/subagent-wiring.js +119 -0
  264. package/dist/activities/execute-deep-agent/subagent-wiring.js.map +1 -0
  265. package/dist/activities/execute-deep-agent/todo-list.d.ts +40 -0
  266. package/dist/activities/execute-deep-agent/todo-list.js +51 -0
  267. package/dist/activities/execute-deep-agent/todo-list.js.map +1 -0
  268. package/dist/activities/execute-deep-agent/translator.d.ts +167 -0
  269. package/dist/activities/execute-deep-agent/translator.js +521 -0
  270. package/dist/activities/execute-deep-agent/translator.js.map +1 -0
  271. package/dist/activities/execute-deep-agent/turn-settle.d.ts +48 -0
  272. package/dist/activities/execute-deep-agent/turn-settle.js +141 -0
  273. package/dist/activities/execute-deep-agent/turn-settle.js.map +1 -0
  274. package/dist/activities/execute-deep-agent/turn-setup.d.ts +281 -0
  275. package/dist/activities/execute-deep-agent/turn-setup.js +687 -0
  276. package/dist/activities/execute-deep-agent/turn-setup.js.map +1 -0
  277. package/dist/activities/execute-deep-agent/turn-stream.d.ts +105 -0
  278. package/dist/activities/execute-deep-agent/turn-stream.js +236 -0
  279. package/dist/activities/execute-deep-agent/turn-stream.js.map +1 -0
  280. package/dist/activities/execute-deep-agent/turn.d.ts +48 -0
  281. package/dist/activities/execute-deep-agent/turn.js +136 -0
  282. package/dist/activities/execute-deep-agent/turn.js.map +1 -0
  283. package/dist/activities/execute-deep-agent/v3-event-recorder.d.ts +32 -0
  284. package/dist/activities/execute-deep-agent/v3-event-recorder.js +72 -0
  285. package/dist/activities/execute-deep-agent/v3-event-recorder.js.map +1 -0
  286. package/dist/activities/generate-session-subject.d.ts +93 -0
  287. package/dist/activities/generate-session-subject.js +285 -0
  288. package/dist/activities/generate-session-subject.js.map +1 -0
  289. package/dist/activities/list-plugin-tools.d.ts +76 -0
  290. package/dist/activities/list-plugin-tools.js +170 -0
  291. package/dist/activities/list-plugin-tools.js.map +1 -0
  292. package/dist/agent-host/channel.d.ts +93 -0
  293. package/dist/agent-host/channel.js +332 -0
  294. package/dist/agent-host/channel.js.map +1 -0
  295. package/dist/agent-host/codec.d.ts +290 -0
  296. package/dist/agent-host/codec.js +437 -0
  297. package/dist/agent-host/codec.js.map +1 -0
  298. package/dist/agent-host/entry.d.ts +56 -0
  299. package/dist/agent-host/entry.js +137 -0
  300. package/dist/agent-host/entry.js.map +1 -0
  301. package/dist/agent-host/environment.d.ts +36 -0
  302. package/dist/agent-host/environment.js +72 -0
  303. package/dist/agent-host/environment.js.map +1 -0
  304. package/dist/agent-host/failed-boot.d.ts +15 -0
  305. package/dist/agent-host/failed-boot.js +26 -0
  306. package/dist/agent-host/failed-boot.js.map +1 -0
  307. package/dist/agent-host/fs-service.d.ts +18 -0
  308. package/dist/agent-host/fs-service.js +133 -0
  309. package/dist/agent-host/fs-service.js.map +1 -0
  310. package/dist/agent-host/host-sink.d.ts +63 -0
  311. package/dist/agent-host/host-sink.js +136 -0
  312. package/dist/agent-host/host-sink.js.map +1 -0
  313. package/dist/agent-host/host.d.ts +48 -0
  314. package/dist/agent-host/host.js +191 -0
  315. package/dist/agent-host/host.js.map +1 -0
  316. package/dist/agent-host/hosting.d.ts +80 -0
  317. package/dist/agent-host/hosting.js +126 -0
  318. package/dist/agent-host/hosting.js.map +1 -0
  319. package/dist/agent-host/protocol.d.ts +478 -0
  320. package/dist/agent-host/protocol.js +77 -0
  321. package/dist/agent-host/protocol.js.map +1 -0
  322. package/dist/agent-host/remote-adapter.d.ts +64 -0
  323. package/dist/agent-host/remote-adapter.js +283 -0
  324. package/dist/agent-host/remote-adapter.js.map +1 -0
  325. package/dist/agent-host/remote-fs.d.ts +19 -0
  326. package/dist/agent-host/remote-fs.js +120 -0
  327. package/dist/agent-host/remote-fs.js.map +1 -0
  328. package/dist/agent-host/supervisor.d.ts +149 -0
  329. package/dist/agent-host/supervisor.js +311 -0
  330. package/dist/agent-host/supervisor.js.map +1 -0
  331. package/dist/agent-proxy/cursor-lane.d.ts +124 -0
  332. package/dist/agent-proxy/cursor-lane.js +507 -0
  333. package/dist/agent-proxy/cursor-lane.js.map +1 -0
  334. package/dist/agent-proxy/lanes.d.ts +63 -0
  335. package/dist/agent-proxy/lanes.js +255 -0
  336. package/dist/agent-proxy/lanes.js.map +1 -0
  337. package/dist/agent-proxy/loopback-certificate.d.ts +27 -0
  338. package/dist/agent-proxy/loopback-certificate.js +115 -0
  339. package/dist/agent-proxy/loopback-certificate.js.map +1 -0
  340. package/dist/agent-proxy/otlp-forward.d.ts +67 -0
  341. package/dist/agent-proxy/otlp-forward.js +170 -0
  342. package/dist/agent-proxy/otlp-forward.js.map +1 -0
  343. package/dist/agent-proxy/relay.d.ts +67 -0
  344. package/dist/agent-proxy/relay.js +164 -0
  345. package/dist/agent-proxy/relay.js.map +1 -0
  346. package/dist/agent-proxy/server.d.ts +84 -0
  347. package/dist/agent-proxy/server.js +258 -0
  348. package/dist/agent-proxy/server.js.map +1 -0
  349. package/dist/attach/entry.d.ts +36 -0
  350. package/dist/attach/entry.js +69 -0
  351. package/dist/attach/entry.js.map +1 -0
  352. package/dist/attach/main.d.ts +14 -0
  353. package/dist/attach/main.js +25 -0
  354. package/dist/attach/main.js.map +1 -0
  355. package/dist/attach/push.d.ts +71 -0
  356. package/dist/attach/push.js +123 -0
  357. package/dist/attach/push.js.map +1 -0
  358. package/dist/attach/waiter.d.ts +108 -0
  359. package/dist/attach/waiter.js +323 -0
  360. package/dist/attach/waiter.js.map +1 -0
  361. package/dist/bootstrap.d.ts +80 -0
  362. package/dist/bootstrap.js +119 -0
  363. package/dist/bootstrap.js.map +1 -0
  364. package/dist/client/server-contracts.d.ts +51 -0
  365. package/dist/client/server-contracts.js +70 -0
  366. package/dist/client/server-contracts.js.map +1 -0
  367. package/dist/client/stigmer-client.d.ts +328 -0
  368. package/dist/client/stigmer-client.js +478 -0
  369. package/dist/client/stigmer-client.js.map +1 -0
  370. package/dist/client/token-claims.d.ts +40 -0
  371. package/dist/client/token-claims.js +88 -0
  372. package/dist/client/token-claims.js.map +1 -0
  373. package/dist/config.d.ts +216 -0
  374. package/dist/config.js +200 -0
  375. package/dist/config.js.map +1 -0
  376. package/dist/exit-backstop.d.ts +64 -0
  377. package/dist/exit-backstop.js +79 -0
  378. package/dist/exit-backstop.js.map +1 -0
  379. package/dist/gen/turn/ai/stigmer/runner/turn/v1/enum_pb.d.ts +1016 -0
  380. package/dist/gen/turn/ai/stigmer/runner/turn/v1/enum_pb.js +1035 -0
  381. package/dist/gen/turn/ai/stigmer/runner/turn/v1/enum_pb.js.map +1 -0
  382. package/dist/gen/turn/ai/stigmer/runner/turn/v1/ledger_pb.d.ts +402 -0
  383. package/dist/gen/turn/ai/stigmer/runner/turn/v1/ledger_pb.js +47 -0
  384. package/dist/gen/turn/ai/stigmer/runner/turn/v1/ledger_pb.js.map +1 -0
  385. package/dist/gen/turn/ai/stigmer/runner/turn/v1/rows_pb.d.ts +826 -0
  386. package/dist/gen/turn/ai/stigmer/runner/turn/v1/rows_pb.js +48 -0
  387. package/dist/gen/turn/ai/stigmer/runner/turn/v1/rows_pb.js.map +1 -0
  388. package/dist/gen-ai-conventions.d.ts +95 -0
  389. package/dist/gen-ai-conventions.js +102 -0
  390. package/dist/gen-ai-conventions.js.map +1 -0
  391. package/dist/harness/approval-answers.d.ts +104 -0
  392. package/dist/harness/approval-answers.js +136 -0
  393. package/dist/harness/approval-answers.js.map +1 -0
  394. package/dist/harness/approval-decisions.d.ts +50 -0
  395. package/dist/harness/approval-decisions.js +80 -0
  396. package/dist/harness/approval-decisions.js.map +1 -0
  397. package/dist/harness/capabilities.d.ts +149 -0
  398. package/dist/harness/capabilities.js +48 -0
  399. package/dist/harness/capabilities.js.map +1 -0
  400. package/dist/harness/capture.d.ts +154 -0
  401. package/dist/harness/capture.js +248 -0
  402. package/dist/harness/capture.js.map +1 -0
  403. package/dist/harness/cost-cap-watch.d.ts +31 -0
  404. package/dist/harness/cost-cap-watch.js +44 -0
  405. package/dist/harness/cost-cap-watch.js.map +1 -0
  406. package/dist/harness/events/emitter.d.ts +220 -0
  407. package/dist/harness/events/emitter.js +726 -0
  408. package/dist/harness/events/emitter.js.map +1 -0
  409. package/dist/harness/events/ids.d.ts +88 -0
  410. package/dist/harness/events/ids.js +136 -0
  411. package/dist/harness/events/ids.js.map +1 -0
  412. package/dist/harness/loaded-versions.d.ts +20 -0
  413. package/dist/harness/loaded-versions.js +70 -0
  414. package/dist/harness/loaded-versions.js.map +1 -0
  415. package/dist/harness/owed-undos.d.ts +119 -0
  416. package/dist/harness/owed-undos.js +200 -0
  417. package/dist/harness/owed-undos.js.map +1 -0
  418. package/dist/harness/persist-chokepoint.d.ts +113 -0
  419. package/dist/harness/persist-chokepoint.js +126 -0
  420. package/dist/harness/persist-chokepoint.js.map +1 -0
  421. package/dist/harness/registry.d.ts +108 -0
  422. package/dist/harness/registry.js +174 -0
  423. package/dist/harness/registry.js.map +1 -0
  424. package/dist/harness/run-span.d.ts +78 -0
  425. package/dist/harness/run-span.js +139 -0
  426. package/dist/harness/run-span.js.map +1 -0
  427. package/dist/harness/run-turn.d.ts +59 -0
  428. package/dist/harness/run-turn.js +749 -0
  429. package/dist/harness/run-turn.js.map +1 -0
  430. package/dist/harness/stop-controller.d.ts +65 -0
  431. package/dist/harness/stop-controller.js +70 -0
  432. package/dist/harness/stop-controller.js.map +1 -0
  433. package/dist/harness/terminal-table.d.ts +212 -0
  434. package/dist/harness/terminal-table.js +329 -0
  435. package/dist/harness/terminal-table.js.map +1 -0
  436. package/dist/harness/transcript/builder.d.ts +269 -0
  437. package/dist/harness/transcript/builder.js +842 -0
  438. package/dist/harness/transcript/builder.js.map +1 -0
  439. package/dist/harness/transcript/events.d.ts +236 -0
  440. package/dist/harness/transcript/events.js +55 -0
  441. package/dist/harness/transcript/events.js.map +1 -0
  442. package/dist/harness/transcript/resume-seed.d.ts +67 -0
  443. package/dist/harness/transcript/resume-seed.js +228 -0
  444. package/dist/harness/transcript/resume-seed.js.map +1 -0
  445. package/dist/harness/transcript/state.d.ts +111 -0
  446. package/dist/harness/transcript/state.js +147 -0
  447. package/dist/harness/transcript/state.js.map +1 -0
  448. package/dist/harness/turn-context.d.ts +923 -0
  449. package/dist/harness/turn-context.js +1448 -0
  450. package/dist/harness/turn-context.js.map +1 -0
  451. package/dist/harness/turn-timeline.d.ts +132 -0
  452. package/dist/harness/turn-timeline.js +213 -0
  453. package/dist/harness/turn-timeline.js.map +1 -0
  454. package/dist/harness/types.d.ts +700 -0
  455. package/dist/harness/types.js +72 -0
  456. package/dist/harness/types.js.map +1 -0
  457. package/dist/harness/usage-accumulator.d.ts +76 -0
  458. package/dist/harness/usage-accumulator.js +112 -0
  459. package/dist/harness/usage-accumulator.js.map +1 -0
  460. package/dist/harness-adapters.d.ts +40 -0
  461. package/dist/harness-adapters.js +45 -0
  462. package/dist/harness-adapters.js.map +1 -0
  463. package/dist/idle-watchdog.d.ts +11 -0
  464. package/dist/idle-watchdog.js +24 -0
  465. package/dist/idle-watchdog.js.map +1 -0
  466. package/dist/in-flight.d.ts +35 -0
  467. package/dist/in-flight.js +61 -0
  468. package/dist/in-flight.js.map +1 -0
  469. package/dist/index.d.ts +43 -0
  470. package/dist/index.js +42 -0
  471. package/dist/index.js.map +1 -0
  472. package/dist/interceptors/run-credential-activity.d.ts +24 -0
  473. package/dist/interceptors/run-credential-activity.js +36 -0
  474. package/dist/interceptors/run-credential-activity.js.map +1 -0
  475. package/dist/ipc-protocol-fixtures.d.ts +28 -0
  476. package/dist/ipc-protocol-fixtures.js +50 -0
  477. package/dist/ipc-protocol-fixtures.js.map +1 -0
  478. package/dist/ipc-protocol.d.ts +43 -0
  479. package/dist/ipc-protocol.js +20 -0
  480. package/dist/ipc-protocol.js.map +1 -0
  481. package/dist/main.d.ts +26 -0
  482. package/dist/main.js +451 -0
  483. package/dist/main.js.map +1 -0
  484. package/dist/middleware/advisory-message.d.ts +52 -0
  485. package/dist/middleware/advisory-message.js +58 -0
  486. package/dist/middleware/advisory-message.js.map +1 -0
  487. package/dist/middleware/approval-gate.d.ts +255 -0
  488. package/dist/middleware/approval-gate.js +502 -0
  489. package/dist/middleware/approval-gate.js.map +1 -0
  490. package/dist/middleware/cost-advisory.d.ts +65 -0
  491. package/dist/middleware/cost-advisory.js +185 -0
  492. package/dist/middleware/cost-advisory.js.map +1 -0
  493. package/dist/middleware/error-hints.d.ts +27 -0
  494. package/dist/middleware/error-hints.js +116 -0
  495. package/dist/middleware/error-hints.js.map +1 -0
  496. package/dist/middleware/execution-budget.d.ts +38 -0
  497. package/dist/middleware/execution-budget.js +168 -0
  498. package/dist/middleware/execution-budget.js.map +1 -0
  499. package/dist/middleware/index.d.ts +55 -0
  500. package/dist/middleware/index.js +80 -0
  501. package/dist/middleware/index.js.map +1 -0
  502. package/dist/middleware/loop-detection.d.ts +22 -0
  503. package/dist/middleware/loop-detection.js +161 -0
  504. package/dist/middleware/loop-detection.js.map +1 -0
  505. package/dist/middleware/otel-spans.d.ts +43 -0
  506. package/dist/middleware/otel-spans.js +281 -0
  507. package/dist/middleware/otel-spans.js.map +1 -0
  508. package/dist/middleware/path-normalization.d.ts +84 -0
  509. package/dist/middleware/path-normalization.js +161 -0
  510. package/dist/middleware/path-normalization.js.map +1 -0
  511. package/dist/middleware/tool-intent.d.ts +57 -0
  512. package/dist/middleware/tool-intent.js +152 -0
  513. package/dist/middleware/tool-intent.js.map +1 -0
  514. package/dist/middleware/tool-scope.d.ts +119 -0
  515. package/dist/middleware/tool-scope.js +159 -0
  516. package/dist/middleware/tool-scope.js.map +1 -0
  517. package/dist/middleware/tool-truncation.d.ts +16 -0
  518. package/dist/middleware/tool-truncation.js +67 -0
  519. package/dist/middleware/tool-truncation.js.map +1 -0
  520. package/dist/middleware/types.d.ts +119 -0
  521. package/dist/middleware/types.js +10 -0
  522. package/dist/middleware/types.js.map +1 -0
  523. package/dist/otel-export.d.ts +142 -0
  524. package/dist/otel-export.js +269 -0
  525. package/dist/otel-export.js.map +1 -0
  526. package/dist/otel-metrics.d.ts +22 -0
  527. package/dist/otel-metrics.js +47 -0
  528. package/dist/otel-metrics.js.map +1 -0
  529. package/dist/otel.d.ts +49 -0
  530. package/dist/otel.js +125 -0
  531. package/dist/otel.js.map +1 -0
  532. package/dist/payload-codecs.d.ts +17 -0
  533. package/dist/payload-codecs.js +45 -0
  534. package/dist/payload-codecs.js.map +1 -0
  535. package/dist/pipe-safety.d.ts +55 -0
  536. package/dist/pipe-safety.js +103 -0
  537. package/dist/pipe-safety.js.map +1 -0
  538. package/dist/pool-member.d.ts +61 -0
  539. package/dist/pool-member.js +51 -0
  540. package/dist/pool-member.js.map +1 -0
  541. package/dist/preflight.d.ts +77 -0
  542. package/dist/preflight.js +98 -0
  543. package/dist/preflight.js.map +1 -0
  544. package/dist/run-trace-id.d.ts +34 -0
  545. package/dist/run-trace-id.js +44 -0
  546. package/dist/run-trace-id.js.map +1 -0
  547. package/dist/runner-entry.d.ts +15 -0
  548. package/dist/runner-entry.js +17 -0
  549. package/dist/runner-entry.js.map +1 -0
  550. package/dist/runner-manager.d.ts +160 -0
  551. package/dist/runner-manager.js +590 -0
  552. package/dist/runner-manager.js.map +1 -0
  553. package/dist/runner-token-coordinator.d.ts +61 -0
  554. package/dist/runner-token-coordinator.js +89 -0
  555. package/dist/runner-token-coordinator.js.map +1 -0
  556. package/dist/runner.d.ts +155 -0
  557. package/dist/runner.js +392 -0
  558. package/dist/runner.js.map +1 -0
  559. package/dist/sandbox-token-renewal.d.ts +64 -0
  560. package/dist/sandbox-token-renewal.js +168 -0
  561. package/dist/sandbox-token-renewal.js.map +1 -0
  562. package/dist/shared/activity-input.d.ts +52 -0
  563. package/dist/shared/activity-input.js +34 -0
  564. package/dist/shared/activity-input.js.map +1 -0
  565. package/dist/shared/agent-fs.d.ts +144 -0
  566. package/dist/shared/agent-fs.js +171 -0
  567. package/dist/shared/agent-fs.js.map +1 -0
  568. package/dist/shared/agent-handover.d.ts +42 -0
  569. package/dist/shared/agent-handover.js +156 -0
  570. package/dist/shared/agent-handover.js.map +1 -0
  571. package/dist/shared/agent-identity.d.ts +96 -0
  572. package/dist/shared/agent-identity.js +153 -0
  573. package/dist/shared/agent-identity.js.map +1 -0
  574. package/dist/shared/agent-servers.d.ts +4 -0
  575. package/dist/shared/agent-servers.js +46 -0
  576. package/dist/shared/agent-servers.js.map +1 -0
  577. package/dist/shared/approval-canonicalize.d.ts +19 -0
  578. package/dist/shared/approval-canonicalize.js +119 -0
  579. package/dist/shared/approval-canonicalize.js.map +1 -0
  580. package/dist/shared/approval-fingerprint.d.ts +103 -0
  581. package/dist/shared/approval-fingerprint.js +110 -0
  582. package/dist/shared/approval-fingerprint.js.map +1 -0
  583. package/dist/shared/approval-policy.d.ts +323 -0
  584. package/dist/shared/approval-policy.js +375 -0
  585. package/dist/shared/approval-policy.js.map +1 -0
  586. package/dist/shared/archive-mount.d.ts +68 -0
  587. package/dist/shared/archive-mount.js +108 -0
  588. package/dist/shared/archive-mount.js.map +1 -0
  589. package/dist/shared/args-preview.d.ts +90 -0
  590. package/dist/shared/args-preview.js +121 -0
  591. package/dist/shared/args-preview.js.map +1 -0
  592. package/dist/shared/artifact-storage.d.ts +155 -0
  593. package/dist/shared/artifact-storage.js +373 -0
  594. package/dist/shared/artifact-storage.js.map +1 -0
  595. package/dist/shared/attachment-download-urls.d.ts +53 -0
  596. package/dist/shared/attachment-download-urls.js +68 -0
  597. package/dist/shared/attachment-download-urls.js.map +1 -0
  598. package/dist/shared/attachment-naming.d.ts +53 -0
  599. package/dist/shared/attachment-naming.js +59 -0
  600. package/dist/shared/attachment-naming.js.map +1 -0
  601. package/dist/shared/attachment-resolver.d.ts +124 -0
  602. package/dist/shared/attachment-resolver.js +322 -0
  603. package/dist/shared/attachment-resolver.js.map +1 -0
  604. package/dist/shared/attachment-vision.d.ts +245 -0
  605. package/dist/shared/attachment-vision.js +339 -0
  606. package/dist/shared/attachment-vision.js.map +1 -0
  607. package/dist/shared/attachment-zip.d.ts +85 -0
  608. package/dist/shared/attachment-zip.js +185 -0
  609. package/dist/shared/attachment-zip.js.map +1 -0
  610. package/dist/shared/blueprint-resolver.d.ts +175 -0
  611. package/dist/shared/blueprint-resolver.js +305 -0
  612. package/dist/shared/blueprint-resolver.js.map +1 -0
  613. package/dist/shared/builtin-assistant-prompt.d.ts +30 -0
  614. package/dist/shared/builtin-assistant-prompt.js +36 -0
  615. package/dist/shared/builtin-assistant-prompt.js.map +1 -0
  616. package/dist/shared/builtin-judge.d.ts +9 -0
  617. package/dist/shared/builtin-judge.js +53 -0
  618. package/dist/shared/builtin-judge.js.map +1 -0
  619. package/dist/shared/caller-identity.d.ts +112 -0
  620. package/dist/shared/caller-identity.js +150 -0
  621. package/dist/shared/caller-identity.js.map +1 -0
  622. package/dist/shared/channel-attachment.d.ts +90 -0
  623. package/dist/shared/channel-attachment.js +209 -0
  624. package/dist/shared/channel-attachment.js.map +1 -0
  625. package/dist/shared/checkpointer/factory.d.ts +32 -0
  626. package/dist/shared/checkpointer/factory.js +72 -0
  627. package/dist/shared/checkpointer/factory.js.map +1 -0
  628. package/dist/shared/checkpointer/http-saver.d.ts +70 -0
  629. package/dist/shared/checkpointer/http-saver.js +335 -0
  630. package/dist/shared/checkpointer/http-saver.js.map +1 -0
  631. package/dist/shared/checkpointer/sqlite-saver.d.ts +54 -0
  632. package/dist/shared/checkpointer/sqlite-saver.js +272 -0
  633. package/dist/shared/checkpointer/sqlite-saver.js.map +1 -0
  634. package/dist/shared/checkpointer/types.d.ts +25 -0
  635. package/dist/shared/checkpointer/types.js +18 -0
  636. package/dist/shared/checkpointer/types.js.map +1 -0
  637. package/dist/shared/cold-start-timing.d.ts +124 -0
  638. package/dist/shared/cold-start-timing.js +220 -0
  639. package/dist/shared/cold-start-timing.js.map +1 -0
  640. package/dist/shared/context-bridge.d.ts +30 -0
  641. package/dist/shared/context-bridge.js +45 -0
  642. package/dist/shared/context-bridge.js.map +1 -0
  643. package/dist/shared/conversation-attachment.d.ts +103 -0
  644. package/dist/shared/conversation-attachment.js +128 -0
  645. package/dist/shared/conversation-attachment.js.map +1 -0
  646. package/dist/shared/conversation-catchup.d.ts +40 -0
  647. package/dist/shared/conversation-catchup.js +86 -0
  648. package/dist/shared/conversation-catchup.js.map +1 -0
  649. package/dist/shared/cost-guard.d.ts +51 -0
  650. package/dist/shared/cost-guard.js +58 -0
  651. package/dist/shared/cost-guard.js.map +1 -0
  652. package/dist/shared/declared-preferences.d.ts +47 -0
  653. package/dist/shared/declared-preferences.js +64 -0
  654. package/dist/shared/declared-preferences.js.map +1 -0
  655. package/dist/shared/eval-case/agent-mock.d.ts +61 -0
  656. package/dist/shared/eval-case/agent-mock.js +88 -0
  657. package/dist/shared/eval-case/agent-mock.js.map +1 -0
  658. package/dist/shared/eval-case/case-archive.d.ts +51 -0
  659. package/dist/shared/eval-case/case-archive.js +119 -0
  660. package/dist/shared/eval-case/case-archive.js.map +1 -0
  661. package/dist/shared/eval-case/mock-endpoint.d.ts +68 -0
  662. package/dist/shared/eval-case/mock-endpoint.js +209 -0
  663. package/dist/shared/eval-case/mock-endpoint.js.map +1 -0
  664. package/dist/shared/eval-case/prepare-case.d.ts +78 -0
  665. package/dist/shared/eval-case/prepare-case.js +193 -0
  666. package/dist/shared/eval-case/prepare-case.js.map +1 -0
  667. package/dist/shared/eval-case/read-files.d.ts +26 -0
  668. package/dist/shared/eval-case/read-files.js +88 -0
  669. package/dist/shared/eval-case/read-files.js.map +1 -0
  670. package/dist/shared/exact-apply.d.ts +109 -0
  671. package/dist/shared/exact-apply.js +205 -0
  672. package/dist/shared/exact-apply.js.map +1 -0
  673. package/dist/shared/execution-context.d.ts +47 -0
  674. package/dist/shared/execution-context.js +51 -0
  675. package/dist/shared/execution-context.js.map +1 -0
  676. package/dist/shared/execution-target.d.ts +13 -0
  677. package/dist/shared/execution-target.js +15 -0
  678. package/dist/shared/execution-target.js.map +1 -0
  679. package/dist/shared/extract-json.d.ts +26 -0
  680. package/dist/shared/extract-json.js +140 -0
  681. package/dist/shared/extract-json.js.map +1 -0
  682. package/dist/shared/extract-structured-output.d.ts +38 -0
  683. package/dist/shared/extract-structured-output.js +68 -0
  684. package/dist/shared/extract-structured-output.js.map +1 -0
  685. package/dist/shared/file-change.d.ts +42 -0
  686. package/dist/shared/file-change.js +55 -0
  687. package/dist/shared/file-change.js.map +1 -0
  688. package/dist/shared/file-tools.d.ts +105 -0
  689. package/dist/shared/file-tools.js +166 -0
  690. package/dist/shared/file-tools.js.map +1 -0
  691. package/dist/shared/filereview/capture.d.ts +238 -0
  692. package/dist/shared/filereview/capture.js +559 -0
  693. package/dist/shared/filereview/capture.js.map +1 -0
  694. package/dist/shared/filereview/cas-progress.d.ts +45 -0
  695. package/dist/shared/filereview/cas-progress.js +131 -0
  696. package/dist/shared/filereview/cas-progress.js.map +1 -0
  697. package/dist/shared/filereview/cas-substrate.d.ts +226 -0
  698. package/dist/shared/filereview/cas-substrate.js +315 -0
  699. package/dist/shared/filereview/cas-substrate.js.map +1 -0
  700. package/dist/shared/filereview/cas-touched.d.ts +56 -0
  701. package/dist/shared/filereview/cas-touched.js +63 -0
  702. package/dist/shared/filereview/cas-touched.js.map +1 -0
  703. package/dist/shared/filereview/command-provenance.d.ts +95 -0
  704. package/dist/shared/filereview/command-provenance.js +134 -0
  705. package/dist/shared/filereview/command-provenance.js.map +1 -0
  706. package/dist/shared/filereview/digest.d.ts +40 -0
  707. package/dist/shared/filereview/digest.js +66 -0
  708. package/dist/shared/filereview/digest.js.map +1 -0
  709. package/dist/shared/filereview/events.d.ts +199 -0
  710. package/dist/shared/filereview/events.js +348 -0
  711. package/dist/shared/filereview/events.js.map +1 -0
  712. package/dist/shared/filereview/git-substrate.d.ts +233 -0
  713. package/dist/shared/filereview/git-substrate.js +528 -0
  714. package/dist/shared/filereview/git-substrate.js.map +1 -0
  715. package/dist/shared/filereview/index.d.ts +15 -0
  716. package/dist/shared/filereview/index.js +16 -0
  717. package/dist/shared/filereview/index.js.map +1 -0
  718. package/dist/shared/filereview/line-counts.d.ts +48 -0
  719. package/dist/shared/filereview/line-counts.js +72 -0
  720. package/dist/shared/filereview/line-counts.js.map +1 -0
  721. package/dist/shared/filereview/progress.d.ts +200 -0
  722. package/dist/shared/filereview/progress.js +245 -0
  723. package/dist/shared/filereview/progress.js.map +1 -0
  724. package/dist/shared/filereview/record.d.ts +53 -0
  725. package/dist/shared/filereview/record.js +104 -0
  726. package/dist/shared/filereview/record.js.map +1 -0
  727. package/dist/shared/filereview/secret-paths.d.ts +61 -0
  728. package/dist/shared/filereview/secret-paths.js +103 -0
  729. package/dist/shared/filereview/secret-paths.js.map +1 -0
  730. package/dist/shared/fingerprint-secret.d.ts +35 -0
  731. package/dist/shared/fingerprint-secret.js +68 -0
  732. package/dist/shared/fingerprint-secret.js.map +1 -0
  733. package/dist/shared/grpc-retry.d.ts +28 -0
  734. package/dist/shared/grpc-retry.js +39 -0
  735. package/dist/shared/grpc-retry.js.map +1 -0
  736. package/dist/shared/heartbeat.d.ts +24 -0
  737. package/dist/shared/heartbeat.js +40 -0
  738. package/dist/shared/heartbeat.js.map +1 -0
  739. package/dist/shared/hooks/answer.d.ts +49 -0
  740. package/dist/shared/hooks/answer.js +152 -0
  741. package/dist/shared/hooks/answer.js.map +1 -0
  742. package/dist/shared/hooks/condition.d.ts +71 -0
  743. package/dist/shared/hooks/condition.js +341 -0
  744. package/dist/shared/hooks/condition.js.map +1 -0
  745. package/dist/shared/hooks/evaluate.d.ts +125 -0
  746. package/dist/shared/hooks/evaluate.js +253 -0
  747. package/dist/shared/hooks/evaluate.js.map +1 -0
  748. package/dist/shared/hooks/formats/claude-code.d.ts +43 -0
  749. package/dist/shared/hooks/formats/claude-code.js +90 -0
  750. package/dist/shared/hooks/formats/claude-code.js.map +1 -0
  751. package/dist/shared/hooks/formats/common.d.ts +30 -0
  752. package/dist/shared/hooks/formats/common.js +7 -0
  753. package/dist/shared/hooks/formats/common.js.map +1 -0
  754. package/dist/shared/hooks/formats/cursor.d.ts +72 -0
  755. package/dist/shared/hooks/formats/cursor.js +238 -0
  756. package/dist/shared/hooks/formats/cursor.js.map +1 -0
  757. package/dist/shared/hooks/hook-set.d.ts +84 -0
  758. package/dist/shared/hooks/hook-set.js +80 -0
  759. package/dist/shared/hooks/hook-set.js.map +1 -0
  760. package/dist/shared/hooks/matcher.d.ts +14 -0
  761. package/dist/shared/hooks/matcher.js +32 -0
  762. package/dist/shared/hooks/matcher.js.map +1 -0
  763. package/dist/shared/hooks/messages.d.ts +19 -0
  764. package/dist/shared/hooks/messages.js +34 -0
  765. package/dist/shared/hooks/messages.js.map +1 -0
  766. package/dist/shared/hooks/run.d.ts +89 -0
  767. package/dist/shared/hooks/run.js +146 -0
  768. package/dist/shared/hooks/run.js.map +1 -0
  769. package/dist/shared/hooks/setup.d.ts +73 -0
  770. package/dist/shared/hooks/setup.js +166 -0
  771. package/dist/shared/hooks/setup.js.map +1 -0
  772. package/dist/shared/hooks/shell-commands.d.ts +39 -0
  773. package/dist/shared/hooks/shell-commands.js +326 -0
  774. package/dist/shared/hooks/shell-commands.js.map +1 -0
  775. package/dist/shared/hooks/tool-view.d.ts +164 -0
  776. package/dist/shared/hooks/tool-view.js +310 -0
  777. package/dist/shared/hooks/tool-view.js.map +1 -0
  778. package/dist/shared/http-retry.d.ts +85 -0
  779. package/dist/shared/http-retry.js +101 -0
  780. package/dist/shared/http-retry.js.map +1 -0
  781. package/dist/shared/implement-plan-prompt.d.ts +44 -0
  782. package/dist/shared/implement-plan-prompt.js +98 -0
  783. package/dist/shared/implement-plan-prompt.js.map +1 -0
  784. package/dist/shared/json-schema-to-zod.d.ts +13 -0
  785. package/dist/shared/json-schema-to-zod.js +49 -0
  786. package/dist/shared/json-schema-to-zod.js.map +1 -0
  787. package/dist/shared/llm-backend.d.ts +303 -0
  788. package/dist/shared/llm-backend.js +491 -0
  789. package/dist/shared/llm-backend.js.map +1 -0
  790. package/dist/shared/llm-proxy.d.ts +64 -0
  791. package/dist/shared/llm-proxy.js +131 -0
  792. package/dist/shared/llm-proxy.js.map +1 -0
  793. package/dist/shared/mcp-manager.d.ts +61 -0
  794. package/dist/shared/mcp-manager.js +131 -0
  795. package/dist/shared/mcp-manager.js.map +1 -0
  796. package/dist/shared/mcp-oauth-detect.d.ts +23 -0
  797. package/dist/shared/mcp-oauth-detect.js +72 -0
  798. package/dist/shared/mcp-oauth-detect.js.map +1 -0
  799. package/dist/shared/mcp-resolver.d.ts +145 -0
  800. package/dist/shared/mcp-resolver.js +238 -0
  801. package/dist/shared/mcp-resolver.js.map +1 -0
  802. package/dist/shared/mcp-schema-sanitizer.d.ts +68 -0
  803. package/dist/shared/mcp-schema-sanitizer.js +195 -0
  804. package/dist/shared/mcp-schema-sanitizer.js.map +1 -0
  805. package/dist/shared/mcp-tool-listing.d.ts +80 -0
  806. package/dist/shared/mcp-tool-listing.js +166 -0
  807. package/dist/shared/mcp-tool-listing.js.map +1 -0
  808. package/dist/shared/mcp-transport-guard.d.ts +53 -0
  809. package/dist/shared/mcp-transport-guard.js +70 -0
  810. package/dist/shared/mcp-transport-guard.js.map +1 -0
  811. package/dist/shared/memory-attachment.d.ts +103 -0
  812. package/dist/shared/memory-attachment.js +142 -0
  813. package/dist/shared/memory-attachment.js.map +1 -0
  814. package/dist/shared/memory-retrieval.d.ts +126 -0
  815. package/dist/shared/memory-retrieval.js +293 -0
  816. package/dist/shared/memory-retrieval.js.map +1 -0
  817. package/dist/shared/model-client.d.ts +111 -0
  818. package/dist/shared/model-client.js +328 -0
  819. package/dist/shared/model-client.js.map +1 -0
  820. package/dist/shared/model-error.d.ts +94 -0
  821. package/dist/shared/model-error.js +475 -0
  822. package/dist/shared/model-error.js.map +1 -0
  823. package/dist/shared/model-facts.d.ts +21 -0
  824. package/dist/shared/model-facts.js +22 -0
  825. package/dist/shared/model-facts.js.map +1 -0
  826. package/dist/shared/model-lanes.d.ts +48 -0
  827. package/dist/shared/model-lanes.js +52 -0
  828. package/dist/shared/model-lanes.js.map +1 -0
  829. package/dist/shared/model-pricing-data.d.ts +20 -0
  830. package/dist/shared/model-pricing-data.js +82 -0
  831. package/dist/shared/model-pricing-data.js.map +1 -0
  832. package/dist/shared/model-pricing.d.ts +16 -0
  833. package/dist/shared/model-pricing.js +46 -0
  834. package/dist/shared/model-pricing.js.map +1 -0
  835. package/dist/shared/model-registry.d.ts +113 -0
  836. package/dist/shared/model-registry.js +250 -0
  837. package/dist/shared/model-registry.js.map +1 -0
  838. package/dist/shared/persist-decision.d.ts +38 -0
  839. package/dist/shared/persist-decision.js +40 -0
  840. package/dist/shared/persist-decision.js.map +1 -0
  841. package/dist/shared/placeholder-resolver.d.ts +39 -0
  842. package/dist/shared/placeholder-resolver.js +86 -0
  843. package/dist/shared/placeholder-resolver.js.map +1 -0
  844. package/dist/shared/plan-artifact.d.ts +105 -0
  845. package/dist/shared/plan-artifact.js +225 -0
  846. package/dist/shared/plan-artifact.js.map +1 -0
  847. package/dist/shared/plan-mode-permissions.d.ts +49 -0
  848. package/dist/shared/plan-mode-permissions.js +51 -0
  849. package/dist/shared/plan-mode-permissions.js.map +1 -0
  850. package/dist/shared/plan-mode-prompt.d.ts +41 -0
  851. package/dist/shared/plan-mode-prompt.js +74 -0
  852. package/dist/shared/plan-mode-prompt.js.map +1 -0
  853. package/dist/shared/platform-server-address.d.ts +72 -0
  854. package/dist/shared/platform-server-address.js +103 -0
  855. package/dist/shared/platform-server-address.js.map +1 -0
  856. package/dist/shared/plugin-mount.d.ts +165 -0
  857. package/dist/shared/plugin-mount.js +428 -0
  858. package/dist/shared/plugin-mount.js.map +1 -0
  859. package/dist/shared/plugin-servers.d.ts +16 -0
  860. package/dist/shared/plugin-servers.js +22 -0
  861. package/dist/shared/plugin-servers.js.map +1 -0
  862. package/dist/shared/prompt-sections.d.ts +140 -0
  863. package/dist/shared/prompt-sections.js +135 -0
  864. package/dist/shared/prompt-sections.js.map +1 -0
  865. package/dist/shared/recalled-memories.d.ts +55 -0
  866. package/dist/shared/recalled-memories.js +70 -0
  867. package/dist/shared/recalled-memories.js.map +1 -0
  868. package/dist/shared/registry-endpoint.d.ts +60 -0
  869. package/dist/shared/registry-endpoint.js +99 -0
  870. package/dist/shared/registry-endpoint.js.map +1 -0
  871. package/dist/shared/run-credential-store.d.ts +32 -0
  872. package/dist/shared/run-credential-store.js +39 -0
  873. package/dist/shared/run-credential-store.js.map +1 -0
  874. package/dist/shared/run-credential.d.ts +40 -0
  875. package/dist/shared/run-credential.js +47 -0
  876. package/dist/shared/run-credential.js.map +1 -0
  877. package/dist/shared/run-values.d.ts +88 -0
  878. package/dist/shared/run-values.js +101 -0
  879. package/dist/shared/run-values.js.map +1 -0
  880. package/dist/shared/runner-credential-keys.d.ts +20 -0
  881. package/dist/shared/runner-credential-keys.js +101 -0
  882. package/dist/shared/runner-credential-keys.js.map +1 -0
  883. package/dist/shared/runner-credential-store.d.ts +77 -0
  884. package/dist/shared/runner-credential-store.js +111 -0
  885. package/dist/shared/runner-credential-store.js.map +1 -0
  886. package/dist/shared/sender-identity.d.ts +50 -0
  887. package/dist/shared/sender-identity.js +69 -0
  888. package/dist/shared/sender-identity.js.map +1 -0
  889. package/dist/shared/service-tier.d.ts +55 -0
  890. package/dist/shared/service-tier.js +67 -0
  891. package/dist/shared/service-tier.js.map +1 -0
  892. package/dist/shared/session-context.d.ts +35 -0
  893. package/dist/shared/session-context.js +52 -0
  894. package/dist/shared/session-context.js.map +1 -0
  895. package/dist/shared/shell-env.d.ts +42 -0
  896. package/dist/shared/shell-env.js +65 -0
  897. package/dist/shared/shell-env.js.map +1 -0
  898. package/dist/shared/skill-mount.d.ts +135 -0
  899. package/dist/shared/skill-mount.js +178 -0
  900. package/dist/shared/skill-mount.js.map +1 -0
  901. package/dist/shared/skill-resolver.d.ts +57 -0
  902. package/dist/shared/skill-resolver.js +113 -0
  903. package/dist/shared/skill-resolver.js.map +1 -0
  904. package/dist/shared/stall-watchdog.d.ts +68 -0
  905. package/dist/shared/stall-watchdog.js +102 -0
  906. package/dist/shared/stall-watchdog.js.map +1 -0
  907. package/dist/shared/status-offload.d.ts +196 -0
  908. package/dist/shared/status-offload.js +655 -0
  909. package/dist/shared/status-offload.js.map +1 -0
  910. package/dist/shared/status.d.ts +100 -0
  911. package/dist/shared/status.js +191 -0
  912. package/dist/shared/status.js.map +1 -0
  913. package/dist/shared/streaming-scheduler.d.ts +59 -0
  914. package/dist/shared/streaming-scheduler.js +110 -0
  915. package/dist/shared/streaming-scheduler.js.map +1 -0
  916. package/dist/shared/subagent-gate.d.ts +47 -0
  917. package/dist/shared/subagent-gate.js +98 -0
  918. package/dist/shared/subagent-gate.js.map +1 -0
  919. package/dist/shared/subagent-rows.d.ts +21 -0
  920. package/dist/shared/subagent-rows.js +34 -0
  921. package/dist/shared/subagent-rows.js.map +1 -0
  922. package/dist/shared/subagents.d.ts +49 -0
  923. package/dist/shared/subagents.js +51 -0
  924. package/dist/shared/subagents.js.map +1 -0
  925. package/dist/shared/synthesized-attachment.d.ts +73 -0
  926. package/dist/shared/synthesized-attachment.js +59 -0
  927. package/dist/shared/synthesized-attachment.js.map +1 -0
  928. package/dist/shared/telemetry-content.d.ts +132 -0
  929. package/dist/shared/telemetry-content.js +239 -0
  930. package/dist/shared/telemetry-content.js.map +1 -0
  931. package/dist/shared/thinking-mode.d.ts +82 -0
  932. package/dist/shared/thinking-mode.js +105 -0
  933. package/dist/shared/thinking-mode.js.map +1 -0
  934. package/dist/shared/todos.d.ts +30 -0
  935. package/dist/shared/todos.js +58 -0
  936. package/dist/shared/todos.js.map +1 -0
  937. package/dist/shared/tool-kind.d.ts +41 -0
  938. package/dist/shared/tool-kind.js +107 -0
  939. package/dist/shared/tool-kind.js.map +1 -0
  940. package/dist/shared/tool-lists.d.ts +283 -0
  941. package/dist/shared/tool-lists.js +518 -0
  942. package/dist/shared/tool-lists.js.map +1 -0
  943. package/dist/shared/tool-rounds.d.ts +91 -0
  944. package/dist/shared/tool-rounds.js +136 -0
  945. package/dist/shared/tool-rounds.js.map +1 -0
  946. package/dist/shared/tool-row.d.ts +195 -0
  947. package/dist/shared/tool-row.js +320 -0
  948. package/dist/shared/tool-row.js.map +1 -0
  949. package/dist/shared/trace-context.d.ts +20 -0
  950. package/dist/shared/trace-context.js +36 -0
  951. package/dist/shared/trace-context.js.map +1 -0
  952. package/dist/shared/with-timeout.d.ts +27 -0
  953. package/dist/shared/with-timeout.js +47 -0
  954. package/dist/shared/with-timeout.js.map +1 -0
  955. package/dist/shared/worker-shutdown.d.ts +99 -0
  956. package/dist/shared/worker-shutdown.js +94 -0
  957. package/dist/shared/worker-shutdown.js.map +1 -0
  958. package/dist/shared/workspace/file-tree.d.ts +13 -0
  959. package/dist/shared/workspace/file-tree.js +101 -0
  960. package/dist/shared/workspace/file-tree.js.map +1 -0
  961. package/dist/shared/workspace/git-credential.d.ts +91 -0
  962. package/dist/shared/workspace/git-credential.js +222 -0
  963. package/dist/shared/workspace/git-credential.js.map +1 -0
  964. package/dist/shared/workspace/git-identity.d.ts +36 -0
  965. package/dist/shared/workspace/git-identity.js +39 -0
  966. package/dist/shared/workspace/git-identity.js.map +1 -0
  967. package/dist/shared/workspace/local-backend.d.ts +44 -0
  968. package/dist/shared/workspace/local-backend.js +110 -0
  969. package/dist/shared/workspace/local-backend.js.map +1 -0
  970. package/dist/shared/workspace/platform-dir.d.ts +106 -0
  971. package/dist/shared/workspace/platform-dir.js +151 -0
  972. package/dist/shared/workspace/platform-dir.js.map +1 -0
  973. package/dist/shared/workspace/platform-mount.d.ts +95 -0
  974. package/dist/shared/workspace/platform-mount.js +157 -0
  975. package/dist/shared/workspace/platform-mount.js.map +1 -0
  976. package/dist/shared/workspace/provisioner.d.ts +52 -0
  977. package/dist/shared/workspace/provisioner.js +70 -0
  978. package/dist/shared/workspace/provisioner.js.map +1 -0
  979. package/dist/shared/workspace/session-provision.d.ts +56 -0
  980. package/dist/shared/workspace/session-provision.js +54 -0
  981. package/dist/shared/workspace/session-provision.js.map +1 -0
  982. package/dist/shared/workspace/session-root.d.ts +35 -0
  983. package/dist/shared/workspace/session-root.js +53 -0
  984. package/dist/shared/workspace/session-root.js.map +1 -0
  985. package/dist/shared/workspace/sources/empty.d.ts +8 -0
  986. package/dist/shared/workspace/sources/empty.js +16 -0
  987. package/dist/shared/workspace/sources/empty.js.map +1 -0
  988. package/dist/shared/workspace/sources/git.d.ts +30 -0
  989. package/dist/shared/workspace/sources/git.js +224 -0
  990. package/dist/shared/workspace/sources/git.js.map +1 -0
  991. package/dist/shared/workspace/sources/local-path.d.ts +17 -0
  992. package/dist/shared/workspace/sources/local-path.js +61 -0
  993. package/dist/shared/workspace/sources/local-path.js.map +1 -0
  994. package/dist/shared/workspace/stigmer-link.d.ts +73 -0
  995. package/dist/shared/workspace/stigmer-link.js +173 -0
  996. package/dist/shared/workspace/stigmer-link.js.map +1 -0
  997. package/dist/shared/workspace/types.d.ts +71 -0
  998. package/dist/shared/workspace/types.js +19 -0
  999. package/dist/shared/workspace/types.js.map +1 -0
  1000. package/dist/shared/workspace/workspace-lock.d.ts +86 -0
  1001. package/dist/shared/workspace/workspace-lock.js +190 -0
  1002. package/dist/shared/workspace/workspace-lock.js.map +1 -0
  1003. package/dist/shared/workspace/writeback-coordinator.d.ts +119 -0
  1004. package/dist/shared/workspace/writeback-coordinator.js +361 -0
  1005. package/dist/shared/workspace/writeback-coordinator.js.map +1 -0
  1006. package/dist/shared/zip-extract.d.ts +55 -0
  1007. package/dist/shared/zip-extract.js +98 -0
  1008. package/dist/shared/zip-extract.js.map +1 -0
  1009. package/dist/tools/index.d.ts +26 -0
  1010. package/dist/tools/index.js +26 -0
  1011. package/dist/tools/index.js.map +1 -0
  1012. package/dist/tools/url-guard.d.ts +77 -0
  1013. package/dist/tools/url-guard.js +119 -0
  1014. package/dist/tools/url-guard.js.map +1 -0
  1015. package/dist/tools/web-fetch-tool.d.ts +55 -0
  1016. package/dist/tools/web-fetch-tool.js +218 -0
  1017. package/dist/tools/web-fetch-tool.js.map +1 -0
  1018. package/dist/worker.d.ts +35 -0
  1019. package/dist/worker.js +71 -0
  1020. package/dist/worker.js.map +1 -0
  1021. package/dist/workflow-source.d.ts +38 -0
  1022. package/dist/workflow-source.js +53 -0
  1023. package/dist/workflow-source.js.map +1 -0
  1024. package/dist/workflows/index.d.ts +32 -0
  1025. package/dist/workflows/index.js +33 -0
  1026. package/dist/workflows/index.js.map +1 -0
  1027. package/dist/workflows/list-plugin-tools.d.ts +23 -0
  1028. package/dist/workflows/list-plugin-tools.js +56 -0
  1029. package/dist/workflows/list-plugin-tools.js.map +1 -0
  1030. package/dist/workflows/types.d.ts +43 -0
  1031. package/dist/workflows/types.js +18 -0
  1032. package/dist/workflows/types.js.map +1 -0
  1033. package/package.json +161 -0
  1034. package/src/__test-utils__/__tests__/execution-record-barrier.test.ts +75 -0
  1035. package/src/__test-utils__/__tests__/harness-contract-self-check.test.ts +361 -0
  1036. package/src/__test-utils__/__tests__/live-gate.test.ts +100 -0
  1037. package/src/__test-utils__/__tests__/real-model-registry.test.ts +53 -0
  1038. package/src/__test-utils__/__tests__/vitest-global-setup.test.ts +37 -0
  1039. package/src/__test-utils__/agent-host-probe-child.ts +77 -0
  1040. package/src/__test-utils__/approval-contract/contract.ts +613 -0
  1041. package/src/__test-utils__/approval-contract/hook-commands.ts +100 -0
  1042. package/src/__test-utils__/approval-contract/types.ts +323 -0
  1043. package/src/__test-utils__/approval-log.ts +142 -0
  1044. package/src/__test-utils__/config-fixture.ts +65 -0
  1045. package/src/__test-utils__/cursor-sdk-wire-child.ts +47 -0
  1046. package/src/__test-utils__/execution-record-fixture.ts +229 -0
  1047. package/src/__test-utils__/fake-artifact-storage.ts +83 -0
  1048. package/src/__test-utils__/fake-upstream.ts +67 -0
  1049. package/src/__test-utils__/file-review-projection.ts +77 -0
  1050. package/src/__test-utils__/git-workspace-fixture.ts +58 -0
  1051. package/src/__test-utils__/harness-boot-order-child.ts +78 -0
  1052. package/src/__test-utils__/harness-contract/contract.ts +652 -0
  1053. package/src/__test-utils__/harness-contract/recording-sink.ts +138 -0
  1054. package/src/__test-utils__/harness-contract/runtime-contract.ts +1136 -0
  1055. package/src/__test-utils__/harness-contract/scripted-adapter.ts +404 -0
  1056. package/src/__test-utils__/harness-contract/types.ts +200 -0
  1057. package/src/__test-utils__/hermetic-activity.ts +1061 -0
  1058. package/src/__test-utils__/import-http2-first.ts +11 -0
  1059. package/src/__test-utils__/live-gate.ts +106 -0
  1060. package/src/__test-utils__/loopback-host.ts +48 -0
  1061. package/src/__test-utils__/mock-client.ts +52 -0
  1062. package/src/__test-utils__/mock-workspace.ts +28 -0
  1063. package/src/__test-utils__/model-registry-fixture.ts +133 -0
  1064. package/src/__test-utils__/module-specifiers.ts +177 -0
  1065. package/src/__test-utils__/proto-helpers.ts +70 -0
  1066. package/src/__test-utils__/real-model-registry.ts +85 -0
  1067. package/src/__test-utils__/refuse-engine-sdks.ts +18 -0
  1068. package/src/__test-utils__/timing-lines.ts +43 -0
  1069. package/src/__test-utils__/turn-input-fixture.ts +166 -0
  1070. package/src/__test-utils__/vitest-global-setup.ts +50 -0
  1071. package/src/__tests__/agent-separation.container.test.ts +157 -0
  1072. package/src/__tests__/approval-gateway-contract.test.ts +29 -0
  1073. package/src/__tests__/bootstrap.test.ts +264 -0
  1074. package/src/__tests__/config-boundary.test.ts +135 -0
  1075. package/src/__tests__/config.test.ts +165 -0
  1076. package/src/__tests__/exit-backstop.test.ts +91 -0
  1077. package/src/__tests__/harness-boot-order.test.ts +87 -0
  1078. package/src/__tests__/harness-contract.test.ts +27 -0
  1079. package/src/__tests__/in-flight.test.ts +84 -0
  1080. package/src/__tests__/ipc-protocol-fixtures.test.ts +61 -0
  1081. package/src/__tests__/ipc-protocol.test.ts +33 -0
  1082. package/src/__tests__/otel-export.test.ts +266 -0
  1083. package/src/__tests__/otel-init.test.ts +111 -0
  1084. package/src/__tests__/otel-metrics.test.ts +37 -0
  1085. package/src/__tests__/pipe-safety.test.ts +119 -0
  1086. package/src/__tests__/pool-member.test.ts +77 -0
  1087. package/src/__tests__/preflight.test.ts +104 -0
  1088. package/src/__tests__/readme-environment.test.ts +678 -0
  1089. package/src/__tests__/run-credential-registration.test.ts +53 -0
  1090. package/src/__tests__/run-trace-id.test.ts +53 -0
  1091. package/src/__tests__/runner-hosting.test.ts +134 -0
  1092. package/src/__tests__/runner-manager-interceptors.test.ts +67 -0
  1093. package/src/__tests__/runner-manager-shutdown.test.ts +199 -0
  1094. package/src/__tests__/runner-manager.test.ts +95 -0
  1095. package/src/__tests__/runner-token-coordinator.test.ts +166 -0
  1096. package/src/__tests__/runner.test.ts +284 -0
  1097. package/src/__tests__/sandbox-token-renewal.test.ts +175 -0
  1098. package/src/__tests__/worker.test.ts +107 -0
  1099. package/src/activities/__tests__/attach-session.test.ts +133 -0
  1100. package/src/activities/__tests__/ensure-thread.test.ts +96 -0
  1101. package/src/activities/__tests__/error-classifier.test.ts +464 -0
  1102. package/src/activities/__tests__/generate-session-subject-wire.test.ts +119 -0
  1103. package/src/activities/__tests__/generate-session-subject.test.ts +356 -0
  1104. package/src/activities/__tests__/list-plugin-tools.test.ts +392 -0
  1105. package/src/activities/attach-session.ts +111 -0
  1106. package/src/activities/ensure-thread.ts +45 -0
  1107. package/src/activities/execute-cursor/__test-utils__/__tests__/scripted-double.test.ts +126 -0
  1108. package/src/activities/execute-cursor/__test-utils__/contract-subject.ts +445 -0
  1109. package/src/activities/execute-cursor/__test-utils__/cursor-hook-harness.ts +407 -0
  1110. package/src/activities/execute-cursor/__test-utils__/fold.ts +118 -0
  1111. package/src/activities/execute-cursor/__test-utils__/gateway-substrate.ts +316 -0
  1112. package/src/activities/execute-cursor/__test-utils__/hermetic-cursor.ts +428 -0
  1113. package/src/activities/execute-cursor/__test-utils__/scripted-agent.ts +374 -0
  1114. package/src/activities/execute-cursor/__test-utils__/scripted-sdk.ts +310 -0
  1115. package/src/activities/execute-cursor/__tests__/adapter-is-temporal-free.test.ts +45 -0
  1116. package/src/activities/execute-cursor/__tests__/agent-session-cache.test.ts +220 -0
  1117. package/src/activities/execute-cursor/__tests__/approval-decisions-agree.test.ts +141 -0
  1118. package/src/activities/execute-cursor/__tests__/approval-gate.test.ts +335 -0
  1119. package/src/activities/execute-cursor/__tests__/approval-state.test.ts +288 -0
  1120. package/src/activities/execute-cursor/__tests__/boundary-seal.test.ts +125 -0
  1121. package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +1045 -0
  1122. package/src/activities/execute-cursor/__tests__/cas-observations.test.ts +267 -0
  1123. package/src/activities/execute-cursor/__tests__/check-tool-scope.test.ts +290 -0
  1124. package/src/activities/execute-cursor/__tests__/coarse-fingerprint.test.ts +98 -0
  1125. package/src/activities/execute-cursor/__tests__/cursor-baseurl-routing.live.test.ts +94 -0
  1126. package/src/activities/execute-cursor/__tests__/cursor-event-recorder.test.ts +142 -0
  1127. package/src/activities/execute-cursor/__tests__/cursor-fetch-interceptor-bypass.live.test.ts +76 -0
  1128. package/src/activities/execute-cursor/__tests__/cursor-generate-image.live.test.ts +154 -0
  1129. package/src/activities/execute-cursor/__tests__/cursor-hook-protocol.live.test.ts +479 -0
  1130. package/src/activities/execute-cursor/__tests__/cursor-hooks-gate.live.test.ts +295 -0
  1131. package/src/activities/execute-cursor/__tests__/cursor-mcp-config.test.ts +128 -0
  1132. package/src/activities/execute-cursor/__tests__/cursor-mode.test.ts +95 -0
  1133. package/src/activities/execute-cursor/__tests__/cursor-sdk-auth.live.test.ts +97 -0
  1134. package/src/activities/execute-cursor/__tests__/cursor-transcript.live.test.ts +289 -0
  1135. package/src/activities/execute-cursor/__tests__/deny-gate-exact-apply.test.ts +200 -0
  1136. package/src/activities/execute-cursor/__tests__/error-classifier-billing.test.ts +178 -0
  1137. package/src/activities/execute-cursor/__tests__/error-classifier-extraction.test.ts +208 -0
  1138. package/src/activities/execute-cursor/__tests__/error-classifier-introspection.test.ts +156 -0
  1139. package/src/activities/execute-cursor/__tests__/fetch-interceptor.test.ts +389 -0
  1140. package/src/activities/execute-cursor/__tests__/goldens/prompt.enhanced.append.prompt.md +147 -0
  1141. package/src/activities/execute-cursor/__tests__/goldens/prompt.enhanced.everything.prompt.md +164 -0
  1142. package/src/activities/execute-cursor/__tests__/goldens/prompt.enhanced.no-instructions.prompt.md +142 -0
  1143. package/src/activities/execute-cursor/__tests__/goldens/prompt.enhanced.plan-mode.prompt.md +184 -0
  1144. package/src/activities/execute-cursor/__tests__/goldens/prompt.hitl.recovery.prompt.md +189 -0
  1145. package/src/activities/execute-cursor/__tests__/goldens/prompt.hitl.reinvocation.prompt.md +13 -0
  1146. package/src/activities/execute-cursor/__tests__/goldens/prompt.resumed.prefixed.prompt.md +32 -0
  1147. package/src/activities/execute-cursor/__tests__/goldens/prompt.resumed.raw.append.prompt.md +5 -0
  1148. package/src/activities/execute-cursor/__tests__/goldens/prompt.resumed.raw.prompt.md +1 -0
  1149. package/src/activities/execute-cursor/__tests__/hermetic/answers.test.ts +279 -0
  1150. package/src/activities/execute-cursor/__tests__/hermetic/built-in-assistant.test.ts +127 -0
  1151. package/src/activities/execute-cursor/__tests__/hermetic/bypassed-tool-call.test.ts +120 -0
  1152. package/src/activities/execute-cursor/__tests__/hermetic/deny-and-retry.test.ts +233 -0
  1153. package/src/activities/execute-cursor/__tests__/hermetic/file-review-capture.test.ts +262 -0
  1154. package/src/activities/execute-cursor/__tests__/hermetic/goldens/approve-all.turn2.events.json +94 -0
  1155. package/src/activities/execute-cursor/__tests__/hermetic/goldens/approve-all.turn2.rows.json +47 -0
  1156. package/src/activities/execute-cursor/__tests__/hermetic/goldens/approve-all.turn2.status.json +17 -0
  1157. package/src/activities/execute-cursor/__tests__/hermetic/goldens/cost-cap.events.json +14 -0
  1158. package/src/activities/execute-cursor/__tests__/hermetic/goldens/cost-cap.rows.json +14 -0
  1159. package/src/activities/execute-cursor/__tests__/hermetic/goldens/cost-cap.status.json +18 -0
  1160. package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn1.events.json +37 -0
  1161. package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn1.rows.json +29 -0
  1162. package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn1.status.json +4 -0
  1163. package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn2.events.json +71 -0
  1164. package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn2.rows.json +32 -0
  1165. package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn2.status.json +17 -0
  1166. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-capture.events.json +68 -0
  1167. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-capture.rows.json +96 -0
  1168. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-capture.status.json +74 -0
  1169. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-off.events.json +50 -0
  1170. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-off.rows.json +32 -0
  1171. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-off.status.json +17 -0
  1172. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-reconcile.events.json +91 -0
  1173. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-reconcile.rows.json +9 -0
  1174. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-reconcile.status.json +6 -0
  1175. package/src/activities/execute-cursor/__tests__/hermetic/goldens/hooks.turn1.events.json +110 -0
  1176. package/src/activities/execute-cursor/__tests__/hermetic/goldens/hooks.turn1.rows.json +77 -0
  1177. package/src/activities/execute-cursor/__tests__/hermetic/goldens/hooks.turn1.status.json +14 -0
  1178. package/src/activities/execute-cursor/__tests__/hermetic/goldens/hooks.turn2.events.json +144 -0
  1179. package/src/activities/execute-cursor/__tests__/hermetic/goldens/hooks.turn2.rows.json +34 -0
  1180. package/src/activities/execute-cursor/__tests__/hermetic/goldens/hooks.turn2.status.json +27 -0
  1181. package/src/activities/execute-cursor/__tests__/hermetic/goldens/mcp-tool-call.events.json +50 -0
  1182. package/src/activities/execute-cursor/__tests__/hermetic/goldens/mcp-tool-call.rows.json +30 -0
  1183. package/src/activities/execute-cursor/__tests__/hermetic/goldens/mcp-tool-call.status.json +17 -0
  1184. package/src/activities/execute-cursor/__tests__/hermetic/goldens/pause.events.json +14 -0
  1185. package/src/activities/execute-cursor/__tests__/hermetic/goldens/pause.rows.json +9 -0
  1186. package/src/activities/execute-cursor/__tests__/hermetic/goldens/pause.status.json +4 -0
  1187. package/src/activities/execute-cursor/__tests__/hermetic/goldens/plain-turn.events.json +14 -0
  1188. package/src/activities/execute-cursor/__tests__/hermetic/goldens/plain-turn.rows.json +9 -0
  1189. package/src/activities/execute-cursor/__tests__/hermetic/goldens/plain-turn.status.json +17 -0
  1190. package/src/activities/execute-cursor/__tests__/hermetic/goldens/platform-stop.events.json +37 -0
  1191. package/src/activities/execute-cursor/__tests__/hermetic/goldens/platform-stop.rows.json +29 -0
  1192. package/src/activities/execute-cursor/__tests__/hermetic/goldens/platform-stop.status.json +6 -0
  1193. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-fresh-agent.events.json +26 -0
  1194. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-fresh-agent.rows.json +14 -0
  1195. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-fresh-agent.status.json +17 -0
  1196. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-transport-timeout.events.json +14 -0
  1197. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-transport-timeout.rows.json +9 -0
  1198. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-transport-timeout.status.json +17 -0
  1199. package/src/activities/execute-cursor/__tests__/hermetic/goldens/reject.turn2.events.json +61 -0
  1200. package/src/activities/execute-cursor/__tests__/hermetic/goldens/reject.turn2.rows.json +31 -0
  1201. package/src/activities/execute-cursor/__tests__/hermetic/goldens/reject.turn2.status.json +17 -0
  1202. package/src/activities/execute-cursor/__tests__/hermetic/goldens/resolution-error.events.json +1 -0
  1203. package/src/activities/execute-cursor/__tests__/hermetic/goldens/resolution-error.rows.json +14 -0
  1204. package/src/activities/execute-cursor/__tests__/hermetic/goldens/resolution-error.status.json +7 -0
  1205. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-cancelled.events.json +14 -0
  1206. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-cancelled.rows.json +9 -0
  1207. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-cancelled.status.json +5 -0
  1208. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-error-non-retryable.events.json +14 -0
  1209. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-error-non-retryable.rows.json +9 -0
  1210. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-error-non-retryable.status.json +7 -0
  1211. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-error-at-create.events.json +1 -0
  1212. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-error-at-create.rows.json +14 -0
  1213. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-error-at-create.status.json +7 -0
  1214. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-task-note.events.json +56 -0
  1215. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-task-note.rows.json +34 -0
  1216. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-task-note.status.json +17 -0
  1217. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.error-delta.events.json +64 -0
  1218. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.error-delta.rows.json +36 -0
  1219. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.error-delta.status.json +17 -0
  1220. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.events.json +49 -0
  1221. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.output-first.events.json +49 -0
  1222. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.output-first.rows.json +31 -0
  1223. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.output-first.status.json +17 -0
  1224. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.rows.json +31 -0
  1225. package/src/activities/execute-cursor/__tests__/hermetic/goldens/shell-output-delta.status.json +17 -0
  1226. package/src/activities/execute-cursor/__tests__/hermetic/goldens/stall.events.json +24 -0
  1227. package/src/activities/execute-cursor/__tests__/hermetic/goldens/stall.rows.json +29 -0
  1228. package/src/activities/execute-cursor/__tests__/hermetic/goldens/stall.status.json +7 -0
  1229. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sub-agent-delegation.events.json +158 -0
  1230. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sub-agent-delegation.rows.json +70 -0
  1231. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sub-agent-delegation.status.json +17 -0
  1232. package/src/activities/execute-cursor/__tests__/hermetic/goldens/thinking-turn.events.json +77 -0
  1233. package/src/activities/execute-cursor/__tests__/hermetic/goldens/thinking-turn.rows.json +39 -0
  1234. package/src/activities/execute-cursor/__tests__/hermetic/goldens/thinking-turn.status.json +17 -0
  1235. package/src/activities/execute-cursor/__tests__/hermetic/goldens/todo-write.events.json +99 -0
  1236. package/src/activities/execute-cursor/__tests__/hermetic/goldens/todo-write.rows.json +80 -0
  1237. package/src/activities/execute-cursor/__tests__/hermetic/goldens/todo-write.status.json +17 -0
  1238. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-call.events.json +49 -0
  1239. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-call.rows.json +29 -0
  1240. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-call.status.json +17 -0
  1241. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-error.events.json +50 -0
  1242. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-error.rows.json +29 -0
  1243. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-error.status.json +17 -0
  1244. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-only-step.events.json +37 -0
  1245. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-only-step.rows.json +28 -0
  1246. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-only-step.status.json +17 -0
  1247. package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattended-skip.events.json +51 -0
  1248. package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattended-skip.rows.json +31 -0
  1249. package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattended-skip.status.json +17 -0
  1250. package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattributed-hook-block.events.json +50 -0
  1251. package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattributed-hook-block.rows.json +36 -0
  1252. package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattributed-hook-block.status.json +19 -0
  1253. package/src/activities/execute-cursor/__tests__/hermetic/goldens/worker-shutdown.events.json +14 -0
  1254. package/src/activities/execute-cursor/__tests__/hermetic/goldens/worker-shutdown.rows.json +14 -0
  1255. package/src/activities/execute-cursor/__tests__/hermetic/goldens/worker-shutdown.status.json +7 -0
  1256. package/src/activities/execute-cursor/__tests__/hermetic/harness-contract.test.ts +198 -0
  1257. package/src/activities/execute-cursor/__tests__/hermetic/hooks.test.ts +569 -0
  1258. package/src/activities/execute-cursor/__tests__/hermetic/mcp-tool-call.test.ts +149 -0
  1259. package/src/activities/execute-cursor/__tests__/hermetic/pause-vs-shutdown.test.ts +222 -0
  1260. package/src/activities/execute-cursor/__tests__/hermetic/plain-turn.test.ts +178 -0
  1261. package/src/activities/execute-cursor/__tests__/hermetic/recovery-fresh-agent.test.ts +162 -0
  1262. package/src/activities/execute-cursor/__tests__/hermetic/run-wait-arms.test.ts +296 -0
  1263. package/src/activities/execute-cursor/__tests__/hermetic/sdk-task-note.test.ts +125 -0
  1264. package/src/activities/execute-cursor/__tests__/hermetic/shell-output-delta.test.ts +283 -0
  1265. package/src/activities/execute-cursor/__tests__/hermetic/stream-self-stop-arms.test.ts +342 -0
  1266. package/src/activities/execute-cursor/__tests__/hermetic/sub-agent-delegation.test.ts +197 -0
  1267. package/src/activities/execute-cursor/__tests__/hermetic/thinking-turn.test.ts +149 -0
  1268. package/src/activities/execute-cursor/__tests__/hermetic/thrown-error-arms.test.ts +214 -0
  1269. package/src/activities/execute-cursor/__tests__/hermetic/todo-write.test.ts +169 -0
  1270. package/src/activities/execute-cursor/__tests__/hermetic/tool-call.test.ts +143 -0
  1271. package/src/activities/execute-cursor/__tests__/hermetic/tool-error.test.ts +141 -0
  1272. package/src/activities/execute-cursor/__tests__/hermetic/tool-lists.test.ts +391 -0
  1273. package/src/activities/execute-cursor/__tests__/hermetic/tool-only-step.test.ts +134 -0
  1274. package/src/activities/execute-cursor/__tests__/hermetic/turn-phases.test.ts +136 -0
  1275. package/src/activities/execute-cursor/__tests__/hermetic/unattended-skip.test.ts +157 -0
  1276. package/src/activities/execute-cursor/__tests__/hermetic/unattributed-hook-block.test.ts +200 -0
  1277. package/src/activities/execute-cursor/__tests__/hermetic/workspace-lock-timeout.test.ts +156 -0
  1278. package/src/activities/execute-cursor/__tests__/hitl-ledger.test.ts +2109 -0
  1279. package/src/activities/execute-cursor/__tests__/hitl-resume-history.test.ts +431 -0
  1280. package/src/activities/execute-cursor/__tests__/hook-refusal-rows.test.ts +95 -0
  1281. package/src/activities/execute-cursor/__tests__/hook-scope.test.ts +175 -0
  1282. package/src/activities/execute-cursor/__tests__/hook-script.test.ts +1408 -0
  1283. package/src/activities/execute-cursor/__tests__/hook-server.test.ts +465 -0
  1284. package/src/activities/execute-cursor/__tests__/hook-views.test.ts +171 -0
  1285. package/src/activities/execute-cursor/__tests__/http2-interceptor.test.ts +408 -0
  1286. package/src/activities/execute-cursor/__tests__/model-pricing.test.ts +173 -0
  1287. package/src/activities/execute-cursor/__tests__/prepare-hooks.test.ts +97 -0
  1288. package/src/activities/execute-cursor/__tests__/prompt-builder-delegation.test.ts +85 -0
  1289. package/src/activities/execute-cursor/__tests__/prompt-goldens.test.ts +270 -0
  1290. package/src/activities/execute-cursor/__tests__/resolve-timeout-message.test.ts +24 -0
  1291. package/src/activities/execute-cursor/__tests__/run-telemetry.test.ts +177 -0
  1292. package/src/activities/execute-cursor/__tests__/runner-error-regressions.test.ts +103 -0
  1293. package/src/activities/execute-cursor/__tests__/same-identity-reproposal.test.ts +174 -0
  1294. package/src/activities/execute-cursor/__tests__/scope-refusal-rows.test.ts +269 -0
  1295. package/src/activities/execute-cursor/__tests__/sdk-warmup.test.ts +45 -0
  1296. package/src/activities/execute-cursor/__tests__/sequential-gate-resume.test.ts +182 -0
  1297. package/src/activities/execute-cursor/__tests__/service-tier.test.ts +230 -0
  1298. package/src/activities/execute-cursor/__tests__/session-lifecycle.test.ts +336 -0
  1299. package/src/activities/execute-cursor/__tests__/session-store.test.ts +220 -0
  1300. package/src/activities/execute-cursor/__tests__/subagent-config.test.ts +181 -0
  1301. package/src/activities/execute-cursor/__tests__/tool-result-image.test.ts +250 -0
  1302. package/src/activities/execute-cursor/__tests__/translator.test.ts +651 -0
  1303. package/src/activities/execute-cursor/__tests__/turn-boundary.test.ts +415 -0
  1304. package/src/activities/execute-cursor/__tests__/turn-recovery.test.ts +186 -0
  1305. package/src/activities/execute-cursor/__tests__/turn-stream.test.ts +354 -0
  1306. package/src/activities/execute-cursor/__tests__/usage-pricing.test.ts +84 -0
  1307. package/src/activities/execute-cursor/__tests__/workspace-setup.test.ts +814 -0
  1308. package/src/activities/execute-cursor/adapter.ts +161 -0
  1309. package/src/activities/execute-cursor/agent-session-cache.ts +229 -0
  1310. package/src/activities/execute-cursor/approval-policy.ts +129 -0
  1311. package/src/activities/execute-cursor/approval-state.ts +1097 -0
  1312. package/src/activities/execute-cursor/boundary-rows.ts +1419 -0
  1313. package/src/activities/execute-cursor/cas-observations.ts +263 -0
  1314. package/src/activities/execute-cursor/cursor-capabilities.ts +80 -0
  1315. package/src/activities/execute-cursor/cursor-event-recorder.ts +112 -0
  1316. package/src/activities/execute-cursor/cursor-mcp-config.ts +124 -0
  1317. package/src/activities/execute-cursor/cursor-mode.ts +42 -0
  1318. package/src/activities/execute-cursor/error-classifier.ts +416 -0
  1319. package/src/activities/execute-cursor/fetch-interceptor.ts +454 -0
  1320. package/src/activities/execute-cursor/hook-scope.ts +216 -0
  1321. package/src/activities/execute-cursor/hook-script.ts +1232 -0
  1322. package/src/activities/execute-cursor/hook-server.ts +473 -0
  1323. package/src/activities/execute-cursor/hook-tool-hiding.ts +76 -0
  1324. package/src/activities/execute-cursor/hook-views.ts +195 -0
  1325. package/src/activities/execute-cursor/http2-interceptor.ts +267 -0
  1326. package/src/activities/execute-cursor/model-pricing-data.ts +170 -0
  1327. package/src/activities/execute-cursor/model-pricing.ts +190 -0
  1328. package/src/activities/execute-cursor/prompt-builder.ts +1081 -0
  1329. package/src/activities/execute-cursor/rejection-capture.ts +93 -0
  1330. package/src/activities/execute-cursor/run-telemetry.ts +189 -0
  1331. package/src/activities/execute-cursor/sdk-warmup.ts +77 -0
  1332. package/src/activities/execute-cursor/service-tier.ts +251 -0
  1333. package/src/activities/execute-cursor/session-lifecycle.ts +543 -0
  1334. package/src/activities/execute-cursor/session-store.ts +186 -0
  1335. package/src/activities/execute-cursor/sub-agent-steps.ts +188 -0
  1336. package/src/activities/execute-cursor/subagent-config.ts +124 -0
  1337. package/src/activities/execute-cursor/tool-result.ts +128 -0
  1338. package/src/activities/execute-cursor/translator.ts +544 -0
  1339. package/src/activities/execute-cursor/turn-boundary.ts +373 -0
  1340. package/src/activities/execute-cursor/turn-recovery.ts +223 -0
  1341. package/src/activities/execute-cursor/turn-settle.ts +605 -0
  1342. package/src/activities/execute-cursor/turn-setup.ts +964 -0
  1343. package/src/activities/execute-cursor/turn-stream.ts +354 -0
  1344. package/src/activities/execute-cursor/turn.ts +271 -0
  1345. package/src/activities/execute-cursor/usage-pricing.ts +67 -0
  1346. package/src/activities/execute-cursor/workspace-hook-files.ts +424 -0
  1347. package/src/activities/execute-cursor/workspace-setup.ts +549 -0
  1348. package/src/activities/execute-deep-agent/__test-utils__/contract-subject.ts +404 -0
  1349. package/src/activities/execute-deep-agent/__test-utils__/gateway-substrate.ts +519 -0
  1350. package/src/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.ts +430 -0
  1351. package/src/activities/execute-deep-agent/__test-utils__/hitl-script.ts +48 -0
  1352. package/src/activities/execute-deep-agent/__test-utils__/paused-session-fixture.ts +172 -0
  1353. package/src/activities/execute-deep-agent/__test-utils__/scripted-model-module.ts +84 -0
  1354. package/src/activities/execute-deep-agent/__test-utils__/scripted-model.ts +585 -0
  1355. package/src/activities/execute-deep-agent/__test-utils__/think-bound-session.ts +29 -0
  1356. package/src/activities/execute-deep-agent/__test-utils__/v3-event-fixtures.ts +295 -0
  1357. package/src/activities/execute-deep-agent/__tests__/adapter-graph-is-sdk-free.test.ts +76 -0
  1358. package/src/activities/execute-deep-agent/__tests__/adapter-is-temporal-free.test.ts +47 -0
  1359. package/src/activities/execute-deep-agent/__tests__/adapter.test.ts +83 -0
  1360. package/src/activities/execute-deep-agent/__tests__/approval-file-change.test.ts +88 -0
  1361. package/src/activities/execute-deep-agent/__tests__/auto-publish.test.ts +144 -0
  1362. package/src/activities/execute-deep-agent/__tests__/builtin-tool-surface.test.ts +108 -0
  1363. package/src/activities/execute-deep-agent/__tests__/cas-capture-backend.test.ts +286 -0
  1364. package/src/activities/execute-deep-agent/__tests__/cas-capture-observer.test.ts +163 -0
  1365. package/src/activities/execute-deep-agent/__tests__/engine-tools.test.ts +97 -0
  1366. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.build-from-plan.prompt.md +133 -0
  1367. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.everything.prompt.md +151 -0
  1368. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.judge.prompt.md +26 -0
  1369. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.minimal.append.prompt.md +28 -0
  1370. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.minimal.prompt.md +25 -0
  1371. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.plan-mode.prompt.md +140 -0
  1372. package/src/activities/execute-deep-agent/__tests__/goldens/user-message.everything.md +36 -0
  1373. package/src/activities/execute-deep-agent/__tests__/hermetic/answers.test.ts +114 -0
  1374. package/src/activities/execute-deep-agent/__tests__/hermetic/built-in-assistant.test.ts +103 -0
  1375. package/src/activities/execute-deep-agent/__tests__/hermetic/cost-advisory.test.ts +239 -0
  1376. package/src/activities/execute-deep-agent/__tests__/hermetic/file-review-capture.test.ts +306 -0
  1377. package/src/activities/execute-deep-agent/__tests__/hermetic/fixtures/paused-session.deepagents-1.10.2.json +592 -0
  1378. package/src/activities/execute-deep-agent/__tests__/hermetic/fixtures/paused-session.think-bound.json +498 -0
  1379. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn1.events.json +49 -0
  1380. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn1.rows.json +32 -0
  1381. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn1.status.json +15 -0
  1382. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn2.events.json +118 -0
  1383. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn2.rows.json +45 -0
  1384. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn2.status.json +16 -0
  1385. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve.turn2.events.json +69 -0
  1386. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve.turn2.rows.json +30 -0
  1387. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve.turn2.status.json +16 -0
  1388. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-capture.events.json +69 -0
  1389. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-capture.rows.json +97 -0
  1390. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-capture.status.json +84 -0
  1391. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-off.events.json +51 -0
  1392. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-off.rows.json +33 -0
  1393. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-off.status.json +27 -0
  1394. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-reconcile.events.json +92 -0
  1395. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-reconcile.rows.json +9 -0
  1396. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-reconcile.status.json +6 -0
  1397. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/gate.turn1.events.json +35 -0
  1398. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/gate.turn1.rows.json +27 -0
  1399. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/gate.turn1.status.json +15 -0
  1400. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/hooks.turn1.events.json +107 -0
  1401. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/hooks.turn1.rows.json +74 -0
  1402. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/hooks.turn1.status.json +25 -0
  1403. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/hooks.turn2.events.json +141 -0
  1404. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/hooks.turn2.rows.json +31 -0
  1405. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/hooks.turn2.status.json +26 -0
  1406. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn1.events.json +71 -0
  1407. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn1.rows.json +50 -0
  1408. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn1.status.json +26 -0
  1409. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn2.events.json +105 -0
  1410. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn2.rows.json +30 -0
  1411. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn2.status.json +27 -0
  1412. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.after-tool.events.json +37 -0
  1413. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.after-tool.rows.json +24 -0
  1414. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.after-tool.status.json +15 -0
  1415. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.mid-tool.events.json +24 -0
  1416. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.mid-tool.rows.json +22 -0
  1417. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.mid-tool.status.json +15 -0
  1418. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/plain-turn.events.json +14 -0
  1419. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/plain-turn.rows.json +9 -0
  1420. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/plain-turn.status.json +16 -0
  1421. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/platform-stop.events.json +24 -0
  1422. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/platform-stop.rows.json +27 -0
  1423. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/platform-stop.status.json +17 -0
  1424. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/recursion-limit.persisted.events.json +352 -0
  1425. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/recursion-limit.persisted.rows.json +209 -0
  1426. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/recursion-limit.persisted.status.json +18 -0
  1427. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/reject.turn2.events.json +71 -0
  1428. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/reject.turn2.rows.json +29 -0
  1429. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/reject.turn2.status.json +16 -0
  1430. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/resolution-error.events.json +1 -0
  1431. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/resolution-error.rows.json +14 -0
  1432. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/resolution-error.status.json +7 -0
  1433. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn2.events.json +90 -0
  1434. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn2.rows.json +48 -0
  1435. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn2.status.json +15 -0
  1436. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn3.events.json +124 -0
  1437. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn3.rows.json +30 -0
  1438. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn3.status.json +16 -0
  1439. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/skip.turn2.events.json +70 -0
  1440. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/skip.turn2.rows.json +29 -0
  1441. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/skip.turn2.status.json +16 -0
  1442. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.text-fallback.events.json +24 -0
  1443. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.text-fallback.rows.json +13 -0
  1444. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.text-fallback.status.json +16 -0
  1445. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tier2.events.json +24 -0
  1446. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tier2.rows.json +13 -0
  1447. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tier2.status.json +16 -0
  1448. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tool-strategy.events.json +36 -0
  1449. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tool-strategy.rows.json +18 -0
  1450. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tool-strategy.status.json +16 -0
  1451. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sub-agent-delegation.events.json +118 -0
  1452. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sub-agent-delegation.rows.json +49 -0
  1453. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sub-agent-delegation.status.json +16 -0
  1454. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/tool-call.events.json +49 -0
  1455. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/tool-call.rows.json +29 -0
  1456. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/tool-call.status.json +16 -0
  1457. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/unattended-skip.events.json +51 -0
  1458. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/unattended-skip.rows.json +31 -0
  1459. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/unattended-skip.status.json +16 -0
  1460. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/worker-shutdown.events.json +37 -0
  1461. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/worker-shutdown.rows.json +29 -0
  1462. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/worker-shutdown.status.json +18 -0
  1463. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/write-todos.events.json +58 -0
  1464. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/write-todos.rows.json +54 -0
  1465. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/write-todos.status.json +16 -0
  1466. package/src/activities/execute-deep-agent/__tests__/hermetic/harness-contract.test.ts +144 -0
  1467. package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-approve-all-lease.test.ts +194 -0
  1468. package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-parallel-gates.test.ts +131 -0
  1469. package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-round-trips.test.ts +224 -0
  1470. package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-sequential-gates.test.ts +180 -0
  1471. package/src/activities/execute-deep-agent/__tests__/hermetic/hooks.test.ts +556 -0
  1472. package/src/activities/execute-deep-agent/__tests__/hermetic/inline-artifact-across-gate.test.ts +188 -0
  1473. package/src/activities/execute-deep-agent/__tests__/hermetic/pause-vs-shutdown.test.ts +217 -0
  1474. package/src/activities/execute-deep-agent/__tests__/hermetic/plain-turn.test.ts +162 -0
  1475. package/src/activities/execute-deep-agent/__tests__/hermetic/platform-stop.test.ts +130 -0
  1476. package/src/activities/execute-deep-agent/__tests__/hermetic/recorded-agent-version.test.ts +148 -0
  1477. package/src/activities/execute-deep-agent/__tests__/hermetic/recursion-limit.test.ts +212 -0
  1478. package/src/activities/execute-deep-agent/__tests__/hermetic/resolution-error.test.ts +130 -0
  1479. package/src/activities/execute-deep-agent/__tests__/hermetic/resume-across-engine-upgrade.test.ts +268 -0
  1480. package/src/activities/execute-deep-agent/__tests__/hermetic/resume-across-think-retirement.test.ts +181 -0
  1481. package/src/activities/execute-deep-agent/__tests__/hermetic/run-finished-while-waiting.test.ts +110 -0
  1482. package/src/activities/execute-deep-agent/__tests__/hermetic/run-values-refused.test.ts +106 -0
  1483. package/src/activities/execute-deep-agent/__tests__/hermetic/structured-output.test.ts +242 -0
  1484. package/src/activities/execute-deep-agent/__tests__/hermetic/sub-agent-concurrent-invocations.test.ts +312 -0
  1485. package/src/activities/execute-deep-agent/__tests__/hermetic/sub-agent-delegation.test.ts +211 -0
  1486. package/src/activities/execute-deep-agent/__tests__/hermetic/sub-agent-own-context.test.ts +192 -0
  1487. package/src/activities/execute-deep-agent/__tests__/hermetic/thrown-turn-drains-publishes.test.ts +154 -0
  1488. package/src/activities/execute-deep-agent/__tests__/hermetic/tool-call.test.ts +167 -0
  1489. package/src/activities/execute-deep-agent/__tests__/hermetic/tool-lists.test.ts +291 -0
  1490. package/src/activities/execute-deep-agent/__tests__/hermetic/turn-phases.test.ts +118 -0
  1491. package/src/activities/execute-deep-agent/__tests__/hermetic/unattended-skip.test.ts +130 -0
  1492. package/src/activities/execute-deep-agent/__tests__/hermetic/workspace-lock-timeout.test.ts +154 -0
  1493. package/src/activities/execute-deep-agent/__tests__/hermetic/write-todos.test.ts +160 -0
  1494. package/src/activities/execute-deep-agent/__tests__/hitl.test.ts +355 -0
  1495. package/src/activities/execute-deep-agent/__tests__/hooks-setup.test.ts +333 -0
  1496. package/src/activities/execute-deep-agent/__tests__/inline-publisher.test.ts +350 -0
  1497. package/src/activities/execute-deep-agent/__tests__/loaded-tool-marks.test.ts +95 -0
  1498. package/src/activities/execute-deep-agent/__tests__/plain-turn.live.test.ts +103 -0
  1499. package/src/activities/execute-deep-agent/__tests__/plan-mode-path-normalization.test.ts +404 -0
  1500. package/src/activities/execute-deep-agent/__tests__/platform-route.test.ts +185 -0
  1501. package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +577 -0
  1502. package/src/activities/execute-deep-agent/__tests__/prompt-goldens.test.ts +293 -0
  1503. package/src/activities/execute-deep-agent/__tests__/resume-across-think-retirement.live.test.ts +98 -0
  1504. package/src/activities/execute-deep-agent/__tests__/resumed-history.test.ts +48 -0
  1505. package/src/activities/execute-deep-agent/__tests__/scripted-model.test.ts +408 -0
  1506. package/src/activities/execute-deep-agent/__tests__/shell-execute-gate.test.ts +293 -0
  1507. package/src/activities/execute-deep-agent/__tests__/streaming-side-effects.test.ts +120 -0
  1508. package/src/activities/execute-deep-agent/__tests__/subagent-approval-propagation.test.ts +160 -0
  1509. package/src/activities/execute-deep-agent/__tests__/subagent-gitignored-capture.test.ts +214 -0
  1510. package/src/activities/execute-deep-agent/__tests__/subagent-plan-mode-permissions.test.ts +213 -0
  1511. package/src/activities/execute-deep-agent/__tests__/subagent-spans.test.ts +110 -0
  1512. package/src/activities/execute-deep-agent/__tests__/subagent-transformer.test.ts +662 -0
  1513. package/src/activities/execute-deep-agent/__tests__/subagent-wiring.test.ts +197 -0
  1514. package/src/activities/execute-deep-agent/__tests__/summarization-verification.test.ts +330 -0
  1515. package/src/activities/execute-deep-agent/__tests__/tool-call.live.test.ts +80 -0
  1516. package/src/activities/execute-deep-agent/__tests__/tool-scope.test.ts +519 -0
  1517. package/src/activities/execute-deep-agent/__tests__/translator-subagents.test.ts +519 -0
  1518. package/src/activities/execute-deep-agent/__tests__/translator-through-builder.test.ts +830 -0
  1519. package/src/activities/execute-deep-agent/__tests__/translator.test.ts +641 -0
  1520. package/src/activities/execute-deep-agent/__tests__/turn-setup-connect.test.ts +89 -0
  1521. package/src/activities/execute-deep-agent/__tests__/turn-setup-tool-lists.test.ts +192 -0
  1522. package/src/activities/execute-deep-agent/__tests__/turn-stream.test.ts +381 -0
  1523. package/src/activities/execute-deep-agent/__tests__/v3-event-recorder.test.ts +186 -0
  1524. package/src/activities/execute-deep-agent/__tests__/vision-input.test.ts +152 -0
  1525. package/src/activities/execute-deep-agent/adapter.ts +95 -0
  1526. package/src/activities/execute-deep-agent/approval-file-change.ts +86 -0
  1527. package/src/activities/execute-deep-agent/auto-publish.ts +80 -0
  1528. package/src/activities/execute-deep-agent/cas-capture-backend.ts +154 -0
  1529. package/src/activities/execute-deep-agent/cas-capture-observer.ts +132 -0
  1530. package/src/activities/execute-deep-agent/deep-agent-capabilities.ts +49 -0
  1531. package/src/activities/execute-deep-agent/deepagents-profiles.ts +51 -0
  1532. package/src/activities/execute-deep-agent/engine-tools.ts +33 -0
  1533. package/src/activities/execute-deep-agent/hitl.ts +274 -0
  1534. package/src/activities/execute-deep-agent/hooks-setup.ts +75 -0
  1535. package/src/activities/execute-deep-agent/inline-publisher.ts +208 -0
  1536. package/src/activities/execute-deep-agent/platform-route.ts +284 -0
  1537. package/src/activities/execute-deep-agent/prompt-builder.ts +547 -0
  1538. package/src/activities/execute-deep-agent/resumed-history.ts +52 -0
  1539. package/src/activities/execute-deep-agent/streaming-side-effects.ts +83 -0
  1540. package/src/activities/execute-deep-agent/subagent-transformer.ts +732 -0
  1541. package/src/activities/execute-deep-agent/subagent-wiring.ts +180 -0
  1542. package/src/activities/execute-deep-agent/todo-list.ts +56 -0
  1543. package/src/activities/execute-deep-agent/translator.ts +564 -0
  1544. package/src/activities/execute-deep-agent/turn-settle.ts +162 -0
  1545. package/src/activities/execute-deep-agent/turn-setup.ts +842 -0
  1546. package/src/activities/execute-deep-agent/turn-stream.ts +309 -0
  1547. package/src/activities/execute-deep-agent/turn.ts +151 -0
  1548. package/src/activities/execute-deep-agent/v3-event-recorder.ts +112 -0
  1549. package/src/activities/generate-session-subject.ts +376 -0
  1550. package/src/activities/list-plugin-tools.ts +251 -0
  1551. package/src/agent-host/__tests__/channel.test.ts +271 -0
  1552. package/src/agent-host/__tests__/codec.test.ts +435 -0
  1553. package/src/agent-host/__tests__/entry-telemetry.test.ts +159 -0
  1554. package/src/agent-host/__tests__/entry.test.ts +223 -0
  1555. package/src/agent-host/__tests__/environment.test.ts +73 -0
  1556. package/src/agent-host/__tests__/failed-boot.test.ts +58 -0
  1557. package/src/agent-host/__tests__/host-sink.test.ts +118 -0
  1558. package/src/agent-host/__tests__/host.test.ts +162 -0
  1559. package/src/agent-host/__tests__/hostile-host.test.ts +440 -0
  1560. package/src/agent-host/__tests__/offload-through-host.test.ts +124 -0
  1561. package/src/agent-host/__tests__/remote-fs.test.ts +177 -0
  1562. package/src/agent-host/__tests__/spawned-host.test.ts +174 -0
  1563. package/src/agent-host/__tests__/supervisor.test.ts +488 -0
  1564. package/src/agent-host/channel.ts +334 -0
  1565. package/src/agent-host/codec.ts +631 -0
  1566. package/src/agent-host/entry.ts +153 -0
  1567. package/src/agent-host/environment.ts +76 -0
  1568. package/src/agent-host/failed-boot.ts +29 -0
  1569. package/src/agent-host/fs-service.ts +133 -0
  1570. package/src/agent-host/host-sink.ts +153 -0
  1571. package/src/agent-host/host.ts +228 -0
  1572. package/src/agent-host/hosting.ts +162 -0
  1573. package/src/agent-host/protocol.ts +380 -0
  1574. package/src/agent-host/remote-adapter.ts +320 -0
  1575. package/src/agent-host/remote-fs.ts +128 -0
  1576. package/src/agent-host/supervisor.ts +382 -0
  1577. package/src/agent-proxy/__tests__/cursor-lane.test.ts +635 -0
  1578. package/src/agent-proxy/__tests__/cursor-sdk-key-required.test.ts +119 -0
  1579. package/src/agent-proxy/__tests__/cursor-sdk-wire.test.ts +175 -0
  1580. package/src/agent-proxy/__tests__/lanes.test.ts +258 -0
  1581. package/src/agent-proxy/__tests__/loopback-certificate.test.ts +100 -0
  1582. package/src/agent-proxy/__tests__/otlp-forward-rebuild.test.ts +66 -0
  1583. package/src/agent-proxy/__tests__/otlp-forward.test.ts +295 -0
  1584. package/src/agent-proxy/__tests__/relay.test.ts +115 -0
  1585. package/src/agent-proxy/__tests__/server.test.ts +436 -0
  1586. package/src/agent-proxy/cursor-lane.ts +528 -0
  1587. package/src/agent-proxy/lanes.ts +285 -0
  1588. package/src/agent-proxy/loopback-certificate.ts +143 -0
  1589. package/src/agent-proxy/otlp-forward.ts +190 -0
  1590. package/src/agent-proxy/relay.ts +188 -0
  1591. package/src/agent-proxy/server.ts +266 -0
  1592. package/src/attach/__tests__/entry.test.ts +123 -0
  1593. package/src/attach/__tests__/import-graph.test.ts +66 -0
  1594. package/src/attach/__tests__/push.test.ts +162 -0
  1595. package/src/attach/__tests__/waiter.test.ts +416 -0
  1596. package/src/attach/entry.ts +92 -0
  1597. package/src/attach/main.ts +26 -0
  1598. package/src/attach/push.ts +165 -0
  1599. package/src/attach/waiter.ts +370 -0
  1600. package/src/bootstrap.ts +178 -0
  1601. package/src/client/__tests__/agent-version-read.test.ts +39 -0
  1602. package/src/client/__tests__/eval-read.test.ts +43 -0
  1603. package/src/client/__tests__/plugin-read.test.ts +57 -0
  1604. package/src/client/__tests__/run-calls.test.ts +65 -0
  1605. package/src/client/__tests__/server-contracts.test.ts +157 -0
  1606. package/src/client/__tests__/session-events-calls.test.ts +139 -0
  1607. package/src/client/__tests__/stigmer-client.test.ts +577 -0
  1608. package/src/client/__tests__/token-claims.test.ts +102 -0
  1609. package/src/client/server-contracts.ts +124 -0
  1610. package/src/client/stigmer-client.ts +686 -0
  1611. package/src/client/token-claims.ts +103 -0
  1612. package/src/config.ts +378 -0
  1613. package/src/exit-backstop.ts +97 -0
  1614. package/src/gen/turn/ai/stigmer/runner/turn/v1/enum_pb.ts +1142 -0
  1615. package/src/gen/turn/ai/stigmer/runner/turn/v1/ledger_pb.ts +458 -0
  1616. package/src/gen/turn/ai/stigmer/runner/turn/v1/rows_pb.ts +920 -0
  1617. package/src/gen-ai-conventions.ts +121 -0
  1618. package/src/harness/README.md +372 -0
  1619. package/src/harness/__tests__/approval-answers.test.ts +202 -0
  1620. package/src/harness/__tests__/approval-decisions.test.ts +114 -0
  1621. package/src/harness/__tests__/attachment-credential.test.ts +115 -0
  1622. package/src/harness/__tests__/capture.test.ts +285 -0
  1623. package/src/harness/__tests__/import-direction.test.ts +169 -0
  1624. package/src/harness/__tests__/loaded-versions.test.ts +76 -0
  1625. package/src/harness/__tests__/mount-skills.test.ts +305 -0
  1626. package/src/harness/__tests__/owed-undos.test.ts +305 -0
  1627. package/src/harness/__tests__/persist-chokepoint.test.ts +344 -0
  1628. package/src/harness/__tests__/readme-index.test.ts +339 -0
  1629. package/src/harness/__tests__/reconcile-turn.test.ts +111 -0
  1630. package/src/harness/__tests__/registry.test.ts +178 -0
  1631. package/src/harness/__tests__/reinvocation-carry.test.ts +65 -0
  1632. package/src/harness/__tests__/resolve-hooks.test.ts +241 -0
  1633. package/src/harness/__tests__/resolve-subagents.test.ts +477 -0
  1634. package/src/harness/__tests__/run-span.test.ts +255 -0
  1635. package/src/harness/__tests__/run-turn-deterministic.test.ts +94 -0
  1636. package/src/harness/__tests__/run-turn-eval-case.test.ts +211 -0
  1637. package/src/harness/__tests__/run-turn.test.ts +435 -0
  1638. package/src/harness/__tests__/runtime-touches-no-agent-path.test.ts +109 -0
  1639. package/src/harness/__tests__/stop-controller.test.ts +93 -0
  1640. package/src/harness/__tests__/terminal-table.test.ts +81 -0
  1641. package/src/harness/__tests__/transcript-is-engine-free.test.ts +83 -0
  1642. package/src/harness/__tests__/transcript-writers.test.ts +193 -0
  1643. package/src/harness/__tests__/turn-attachments-vision.test.ts +105 -0
  1644. package/src/harness/__tests__/turn-context.test.ts +213 -0
  1645. package/src/harness/__tests__/turn-mcp.test.ts +554 -0
  1646. package/src/harness/__tests__/turn-timeline.test.ts +290 -0
  1647. package/src/harness/__tests__/usage-accumulator.test.ts +106 -0
  1648. package/src/harness/approval-answers.ts +174 -0
  1649. package/src/harness/approval-decisions.ts +82 -0
  1650. package/src/harness/capabilities.ts +155 -0
  1651. package/src/harness/capture.ts +337 -0
  1652. package/src/harness/cost-cap-watch.ts +52 -0
  1653. package/src/harness/events/__tests__/emitter.test.ts +715 -0
  1654. package/src/harness/events/__tests__/ids-corpus.test.ts +86 -0
  1655. package/src/harness/events/emitter.ts +805 -0
  1656. package/src/harness/events/ids.ts +156 -0
  1657. package/src/harness/loaded-versions.ts +78 -0
  1658. package/src/harness/owed-undos.ts +258 -0
  1659. package/src/harness/persist-chokepoint.ts +163 -0
  1660. package/src/harness/registry.ts +203 -0
  1661. package/src/harness/run-span.ts +184 -0
  1662. package/src/harness/run-turn.ts +862 -0
  1663. package/src/harness/stop-controller.ts +101 -0
  1664. package/src/harness/terminal-table.ts +390 -0
  1665. package/src/harness/transcript/__tests__/builder.test.ts +1246 -0
  1666. package/src/harness/transcript/__tests__/resume-seed.test.ts +148 -0
  1667. package/src/harness/transcript/__tests__/state.test.ts +144 -0
  1668. package/src/harness/transcript/builder.ts +925 -0
  1669. package/src/harness/transcript/events.ts +281 -0
  1670. package/src/harness/transcript/resume-seed.ts +280 -0
  1671. package/src/harness/transcript/state.ts +167 -0
  1672. package/src/harness/turn-context.ts +1982 -0
  1673. package/src/harness/turn-timeline.ts +248 -0
  1674. package/src/harness/types.ts +725 -0
  1675. package/src/harness/usage-accumulator.ts +134 -0
  1676. package/src/harness-adapters.ts +48 -0
  1677. package/src/idle-watchdog.ts +28 -0
  1678. package/src/in-flight.ts +71 -0
  1679. package/src/index.ts +48 -0
  1680. package/src/interceptors/__tests__/run-credential-activity.test.ts +86 -0
  1681. package/src/interceptors/run-credential-activity.ts +40 -0
  1682. package/src/ipc-protocol-fixtures.ts +90 -0
  1683. package/src/ipc-protocol.ts +89 -0
  1684. package/src/main.ts +506 -0
  1685. package/src/middleware/__tests__/advisory-message.test.ts +59 -0
  1686. package/src/middleware/__tests__/approval-gate-hooks.test.ts +269 -0
  1687. package/src/middleware/__tests__/approval-gate.test.ts +1072 -0
  1688. package/src/middleware/__tests__/cost-advisory.test.ts +272 -0
  1689. package/src/middleware/__tests__/error-hints.test.ts +90 -0
  1690. package/src/middleware/__tests__/execution-budget.test.ts +239 -0
  1691. package/src/middleware/__tests__/loop-detection.test.ts +194 -0
  1692. package/src/middleware/__tests__/otel-spans.test.ts +460 -0
  1693. package/src/middleware/__tests__/path-normalization.test.ts +198 -0
  1694. package/src/middleware/__tests__/tool-intent.test.ts +266 -0
  1695. package/src/middleware/__tests__/tool-truncation.test.ts +112 -0
  1696. package/src/middleware/advisory-message.ts +62 -0
  1697. package/src/middleware/approval-gate.ts +741 -0
  1698. package/src/middleware/cost-advisory.ts +224 -0
  1699. package/src/middleware/error-hints.ts +136 -0
  1700. package/src/middleware/execution-budget.ts +197 -0
  1701. package/src/middleware/index.ts +100 -0
  1702. package/src/middleware/loop-detection.ts +197 -0
  1703. package/src/middleware/otel-spans.ts +345 -0
  1704. package/src/middleware/path-normalization.ts +178 -0
  1705. package/src/middleware/tool-intent.ts +174 -0
  1706. package/src/middleware/tool-scope.ts +201 -0
  1707. package/src/middleware/tool-truncation.ts +94 -0
  1708. package/src/middleware/types.ts +141 -0
  1709. package/src/otel-export.ts +325 -0
  1710. package/src/otel-metrics.ts +61 -0
  1711. package/src/otel.ts +173 -0
  1712. package/src/payload-codecs.ts +66 -0
  1713. package/src/pipe-safety.ts +117 -0
  1714. package/src/pool-member.ts +99 -0
  1715. package/src/preflight.ts +104 -0
  1716. package/src/run-trace-id.ts +50 -0
  1717. package/src/runner-entry.ts +18 -0
  1718. package/src/runner-manager.ts +882 -0
  1719. package/src/runner-token-coordinator.ts +140 -0
  1720. package/src/runner.ts +588 -0
  1721. package/src/sandbox-token-renewal.ts +211 -0
  1722. package/src/shared/__tests__/activity-input.test.ts +78 -0
  1723. package/src/shared/__tests__/advisory-anthropic-payload.test.ts +194 -0
  1724. package/src/shared/__tests__/agent-handover.test.ts +186 -0
  1725. package/src/shared/__tests__/agent-identity.test.ts +144 -0
  1726. package/src/shared/__tests__/agent-servers.test.ts +55 -0
  1727. package/src/shared/__tests__/approval-canonicalize.test.ts +106 -0
  1728. package/src/shared/__tests__/approval-fingerprint.test.ts +115 -0
  1729. package/src/shared/__tests__/approval-policy.test.ts +466 -0
  1730. package/src/shared/__tests__/args-preview.test.ts +147 -0
  1731. package/src/shared/__tests__/artifact-storage-extended.test.ts +243 -0
  1732. package/src/shared/__tests__/artifact-storage.test.ts +844 -0
  1733. package/src/shared/__tests__/attachment-download-urls.test.ts +72 -0
  1734. package/src/shared/__tests__/attachment-naming.test.ts +146 -0
  1735. package/src/shared/__tests__/attachment-resolver.test.ts +644 -0
  1736. package/src/shared/__tests__/attachment-vision.test.ts +424 -0
  1737. package/src/shared/__tests__/attachment-zip.test.ts +236 -0
  1738. package/src/shared/__tests__/bedrock-adapter.test.ts +213 -0
  1739. package/src/shared/__tests__/bedrock-seam.test.ts +390 -0
  1740. package/src/shared/__tests__/blueprint-resolver.test.ts +629 -0
  1741. package/src/shared/__tests__/builtin-judge.test.ts +57 -0
  1742. package/src/shared/__tests__/caller-identity.test.ts +172 -0
  1743. package/src/shared/__tests__/channel-attachment.test.ts +285 -0
  1744. package/src/shared/__tests__/cold-start-timing.test.ts +333 -0
  1745. package/src/shared/__tests__/context-bridge.test.ts +51 -0
  1746. package/src/shared/__tests__/conversation-attachment.test.ts +152 -0
  1747. package/src/shared/__tests__/conversation-catchup.test.ts +94 -0
  1748. package/src/shared/__tests__/cost-guard.test.ts +68 -0
  1749. package/src/shared/__tests__/declared-preferences.test.ts +109 -0
  1750. package/src/shared/__tests__/default-model-agrees-with-server.test.ts +74 -0
  1751. package/src/shared/__tests__/exact-apply.test.ts +370 -0
  1752. package/src/shared/__tests__/execution-target.test.ts +33 -0
  1753. package/src/shared/__tests__/extract-json.test.ts +153 -0
  1754. package/src/shared/__tests__/extract-structured-output.test.ts +149 -0
  1755. package/src/shared/__tests__/file-change.test.ts +85 -0
  1756. package/src/shared/__tests__/file-tools.test.ts +90 -0
  1757. package/src/shared/__tests__/fingerprint-secret.test.ts +51 -0
  1758. package/src/shared/__tests__/foundry-adapter.test.ts +276 -0
  1759. package/src/shared/__tests__/foundry-seam.test.ts +482 -0
  1760. package/src/shared/__tests__/grpc-retry-extended.test.ts +38 -0
  1761. package/src/shared/__tests__/grpc-retry.test.ts +43 -0
  1762. package/src/shared/__tests__/http-retry.test.ts +68 -0
  1763. package/src/shared/__tests__/implement-plan-prompt.test.ts +86 -0
  1764. package/src/shared/__tests__/json-schema-to-zod.test.ts +227 -0
  1765. package/src/shared/__tests__/lease-scope-corpus.test.ts +78 -0
  1766. package/src/shared/__tests__/llm-backend.test.ts +676 -0
  1767. package/src/shared/__tests__/llm-proxy.test.ts +179 -0
  1768. package/src/shared/__tests__/mcp-manager.test.ts +272 -0
  1769. package/src/shared/__tests__/mcp-oauth-detect.test.ts +167 -0
  1770. package/src/shared/__tests__/mcp-resolver.test.ts +454 -0
  1771. package/src/shared/__tests__/mcp-schema-sanitizer.test.ts +267 -0
  1772. package/src/shared/__tests__/mcp-tool-listing.hang.test.ts +82 -0
  1773. package/src/shared/__tests__/mcp-tool-listing.test.ts +257 -0
  1774. package/src/shared/__tests__/mcp-transport-guard.test.ts +71 -0
  1775. package/src/shared/__tests__/memory-attachment.test.ts +183 -0
  1776. package/src/shared/__tests__/memory-retrieval.test.ts +310 -0
  1777. package/src/shared/__tests__/model-client-sampling.test.ts +110 -0
  1778. package/src/shared/__tests__/model-client.test.ts +623 -0
  1779. package/src/shared/__tests__/model-error.test.ts +579 -0
  1780. package/src/shared/__tests__/model-lanes.test.ts +225 -0
  1781. package/src/shared/__tests__/model-pricing.test.ts +131 -0
  1782. package/src/shared/__tests__/model-registry-at-provider.live.test.ts +63 -0
  1783. package/src/shared/__tests__/model-registry.test.ts +460 -0
  1784. package/src/shared/__tests__/persist-decision.test.ts +87 -0
  1785. package/src/shared/__tests__/placeholder-resolver.test.ts +210 -0
  1786. package/src/shared/__tests__/plan-artifact.test.ts +260 -0
  1787. package/src/shared/__tests__/plan-mode-permissions.test.ts +29 -0
  1788. package/src/shared/__tests__/platform-server-address.test.ts +125 -0
  1789. package/src/shared/__tests__/plugin-mount-faults.test.ts +71 -0
  1790. package/src/shared/__tests__/plugin-mount.test.ts +407 -0
  1791. package/src/shared/__tests__/plugin-servers.test.ts +53 -0
  1792. package/src/shared/__tests__/policy-source-corpus.test.ts +69 -0
  1793. package/src/shared/__tests__/prompt-sections.test.ts +113 -0
  1794. package/src/shared/__tests__/recalled-memories.test.ts +88 -0
  1795. package/src/shared/__tests__/registry-endpoint.test.ts +96 -0
  1796. package/src/shared/__tests__/run-credential.test.ts +109 -0
  1797. package/src/shared/__tests__/run-values.test.ts +125 -0
  1798. package/src/shared/__tests__/runner-credential-store.test.ts +175 -0
  1799. package/src/shared/__tests__/secret-leak-scan.test.ts +100 -0
  1800. package/src/shared/__tests__/sender-identity.test.ts +92 -0
  1801. package/src/shared/__tests__/session-context.test.ts +67 -0
  1802. package/src/shared/__tests__/shell-env.test.ts +118 -0
  1803. package/src/shared/__tests__/skill-mount.test.ts +353 -0
  1804. package/src/shared/__tests__/skill-resolver.test.ts +401 -0
  1805. package/src/shared/__tests__/stall-watchdog.test.ts +193 -0
  1806. package/src/shared/__tests__/stamp-flowed-rows.test.ts +142 -0
  1807. package/src/shared/__tests__/status-offload.test.ts +778 -0
  1808. package/src/shared/__tests__/status.test.ts +350 -0
  1809. package/src/shared/__tests__/streaming-scheduler.test.ts +198 -0
  1810. package/src/shared/__tests__/subagent-gate.test.ts +112 -0
  1811. package/src/shared/__tests__/subagent-rows.test.ts +34 -0
  1812. package/src/shared/__tests__/subagents.test.ts +135 -0
  1813. package/src/shared/__tests__/synthesized-attachment.test.ts +96 -0
  1814. package/src/shared/__tests__/telemetry-content.test.ts +220 -0
  1815. package/src/shared/__tests__/thinking-mode.test.ts +69 -0
  1816. package/src/shared/__tests__/todos.test.ts +216 -0
  1817. package/src/shared/__tests__/tool-kind.test.ts +81 -0
  1818. package/src/shared/__tests__/tool-lists.test.ts +463 -0
  1819. package/src/shared/__tests__/tool-rounds.test.ts +107 -0
  1820. package/src/shared/__tests__/tool-row.test.ts +390 -0
  1821. package/src/shared/__tests__/trace-context.test.ts +68 -0
  1822. package/src/shared/__tests__/vertex-adapter.test.ts +196 -0
  1823. package/src/shared/__tests__/vertex-seam.test.ts +296 -0
  1824. package/src/shared/__tests__/with-timeout.test.ts +60 -0
  1825. package/src/shared/__tests__/worker-shutdown.test.ts +106 -0
  1826. package/src/shared/__tests__/zip-extract.test.ts +256 -0
  1827. package/src/shared/activity-input.ts +78 -0
  1828. package/src/shared/agent-fs.ts +264 -0
  1829. package/src/shared/agent-handover.ts +171 -0
  1830. package/src/shared/agent-identity.ts +185 -0
  1831. package/src/shared/agent-servers.ts +51 -0
  1832. package/src/shared/approval-canonicalize.ts +159 -0
  1833. package/src/shared/approval-fingerprint.ts +145 -0
  1834. package/src/shared/approval-policy.ts +536 -0
  1835. package/src/shared/archive-mount.ts +140 -0
  1836. package/src/shared/args-preview.ts +128 -0
  1837. package/src/shared/artifact-storage.ts +496 -0
  1838. package/src/shared/attachment-download-urls.ts +76 -0
  1839. package/src/shared/attachment-naming.ts +78 -0
  1840. package/src/shared/attachment-resolver.ts +468 -0
  1841. package/src/shared/attachment-vision.ts +466 -0
  1842. package/src/shared/attachment-zip.ts +281 -0
  1843. package/src/shared/blueprint-resolver.ts +420 -0
  1844. package/src/shared/builtin-assistant-prompt.ts +38 -0
  1845. package/src/shared/builtin-judge.ts +62 -0
  1846. package/src/shared/caller-identity.ts +186 -0
  1847. package/src/shared/channel-attachment.ts +246 -0
  1848. package/src/shared/checkpointer/__tests__/factory.test.ts +88 -0
  1849. package/src/shared/checkpointer/__tests__/http-saver.test.ts +393 -0
  1850. package/src/shared/checkpointer/__tests__/sqlite-saver.test.ts +212 -0
  1851. package/src/shared/checkpointer/factory.ts +94 -0
  1852. package/src/shared/checkpointer/http-saver.ts +429 -0
  1853. package/src/shared/checkpointer/sqlite-saver.ts +384 -0
  1854. package/src/shared/checkpointer/types.ts +27 -0
  1855. package/src/shared/cold-start-timing.ts +260 -0
  1856. package/src/shared/context-bridge.ts +51 -0
  1857. package/src/shared/conversation-attachment.ts +141 -0
  1858. package/src/shared/conversation-catchup.ts +93 -0
  1859. package/src/shared/cost-guard.ts +63 -0
  1860. package/src/shared/declared-preferences.ts +84 -0
  1861. package/src/shared/eval-case/__tests__/agent-mock.test.ts +126 -0
  1862. package/src/shared/eval-case/__tests__/case-archive.test.ts +159 -0
  1863. package/src/shared/eval-case/__tests__/mock-endpoint-failure.test.ts +65 -0
  1864. package/src/shared/eval-case/__tests__/mock-endpoint.test.ts +269 -0
  1865. package/src/shared/eval-case/__tests__/prepare-case.test.ts +228 -0
  1866. package/src/shared/eval-case/__tests__/read-files.test.ts +90 -0
  1867. package/src/shared/eval-case/agent-mock.ts +131 -0
  1868. package/src/shared/eval-case/case-archive.ts +135 -0
  1869. package/src/shared/eval-case/mock-endpoint.ts +282 -0
  1870. package/src/shared/eval-case/prepare-case.ts +227 -0
  1871. package/src/shared/eval-case/read-files.ts +94 -0
  1872. package/src/shared/exact-apply.ts +247 -0
  1873. package/src/shared/execution-context.ts +62 -0
  1874. package/src/shared/execution-target.ts +17 -0
  1875. package/src/shared/extract-json.ts +153 -0
  1876. package/src/shared/extract-structured-output.ts +83 -0
  1877. package/src/shared/file-change.ts +62 -0
  1878. package/src/shared/file-tools.ts +167 -0
  1879. package/src/shared/filereview/__tests__/capture.test.ts +1178 -0
  1880. package/src/shared/filereview/__tests__/cas-progress.test.ts +229 -0
  1881. package/src/shared/filereview/__tests__/cas-substrate.test.ts +504 -0
  1882. package/src/shared/filereview/__tests__/command-provenance.test.ts +249 -0
  1883. package/src/shared/filereview/__tests__/digest.test.ts +100 -0
  1884. package/src/shared/filereview/__tests__/events.test.ts +350 -0
  1885. package/src/shared/filereview/__tests__/git-substrate.test.ts +365 -0
  1886. package/src/shared/filereview/__tests__/line-counts.test.ts +73 -0
  1887. package/src/shared/filereview/__tests__/progress.test.ts +480 -0
  1888. package/src/shared/filereview/__tests__/proxy-reconcile.test.ts +265 -0
  1889. package/src/shared/filereview/__tests__/record.test.ts +126 -0
  1890. package/src/shared/filereview/__tests__/secret-paths.test.ts +121 -0
  1891. package/src/shared/filereview/capture.ts +783 -0
  1892. package/src/shared/filereview/cas-progress.ts +155 -0
  1893. package/src/shared/filereview/cas-substrate.ts +460 -0
  1894. package/src/shared/filereview/cas-touched.ts +89 -0
  1895. package/src/shared/filereview/command-provenance.ts +182 -0
  1896. package/src/shared/filereview/digest.ts +83 -0
  1897. package/src/shared/filereview/events.ts +515 -0
  1898. package/src/shared/filereview/git-substrate.ts +680 -0
  1899. package/src/shared/filereview/index.ts +99 -0
  1900. package/src/shared/filereview/line-counts.ts +83 -0
  1901. package/src/shared/filereview/progress.ts +361 -0
  1902. package/src/shared/filereview/record.ts +107 -0
  1903. package/src/shared/filereview/secret-paths.ts +119 -0
  1904. package/src/shared/fingerprint-secret.ts +77 -0
  1905. package/src/shared/grpc-retry.ts +54 -0
  1906. package/src/shared/heartbeat.ts +50 -0
  1907. package/src/shared/hooks/__tests__/answer.test.ts +179 -0
  1908. package/src/shared/hooks/__tests__/condition.test.ts +389 -0
  1909. package/src/shared/hooks/__tests__/cursor-format.test.ts +209 -0
  1910. package/src/shared/hooks/__tests__/evaluate.test.ts +473 -0
  1911. package/src/shared/hooks/__tests__/run.test.ts +159 -0
  1912. package/src/shared/hooks/__tests__/stall.test.ts +75 -0
  1913. package/src/shared/hooks/__tests__/tool-view.test.ts +235 -0
  1914. package/src/shared/hooks/answer.ts +180 -0
  1915. package/src/shared/hooks/condition.ts +341 -0
  1916. package/src/shared/hooks/evaluate.ts +381 -0
  1917. package/src/shared/hooks/formats/claude-code.ts +106 -0
  1918. package/src/shared/hooks/formats/common.ts +31 -0
  1919. package/src/shared/hooks/formats/cursor.ts +261 -0
  1920. package/src/shared/hooks/hook-set.ts +134 -0
  1921. package/src/shared/hooks/matcher.ts +31 -0
  1922. package/src/shared/hooks/messages.ts +38 -0
  1923. package/src/shared/hooks/run.ts +190 -0
  1924. package/src/shared/hooks/setup.ts +209 -0
  1925. package/src/shared/hooks/shell-commands.ts +326 -0
  1926. package/src/shared/hooks/tool-view.ts +406 -0
  1927. package/src/shared/http-retry.ts +139 -0
  1928. package/src/shared/implement-plan-prompt.ts +104 -0
  1929. package/src/shared/json-schema-to-zod.ts +53 -0
  1930. package/src/shared/llm-backend.ts +623 -0
  1931. package/src/shared/llm-proxy.ts +154 -0
  1932. package/src/shared/mcp-manager.ts +161 -0
  1933. package/src/shared/mcp-oauth-detect.ts +80 -0
  1934. package/src/shared/mcp-resolver.ts +338 -0
  1935. package/src/shared/mcp-schema-sanitizer.ts +222 -0
  1936. package/src/shared/mcp-tool-listing.ts +203 -0
  1937. package/src/shared/mcp-transport-guard.ts +81 -0
  1938. package/src/shared/memory-attachment.ts +177 -0
  1939. package/src/shared/memory-retrieval.ts +380 -0
  1940. package/src/shared/model-client.ts +465 -0
  1941. package/src/shared/model-error.ts +551 -0
  1942. package/src/shared/model-facts.ts +30 -0
  1943. package/src/shared/model-lanes.ts +66 -0
  1944. package/src/shared/model-pricing-data.ts +123 -0
  1945. package/src/shared/model-pricing.ts +64 -0
  1946. package/src/shared/model-registry.ts +352 -0
  1947. package/src/shared/persist-decision.ts +47 -0
  1948. package/src/shared/placeholder-resolver.ts +113 -0
  1949. package/src/shared/plan-artifact.ts +255 -0
  1950. package/src/shared/plan-mode-permissions.ts +53 -0
  1951. package/src/shared/plan-mode-prompt.ts +74 -0
  1952. package/src/shared/platform-server-address.ts +124 -0
  1953. package/src/shared/plugin-mount.ts +495 -0
  1954. package/src/shared/plugin-servers.ts +23 -0
  1955. package/src/shared/prompt-sections.ts +205 -0
  1956. package/src/shared/recalled-memories.ts +90 -0
  1957. package/src/shared/registry-endpoint.ts +108 -0
  1958. package/src/shared/run-credential-store.ts +45 -0
  1959. package/src/shared/run-credential.ts +48 -0
  1960. package/src/shared/run-values.ts +154 -0
  1961. package/src/shared/runner-credential-keys.ts +106 -0
  1962. package/src/shared/runner-credential-store.ts +115 -0
  1963. package/src/shared/sender-identity.ts +85 -0
  1964. package/src/shared/service-tier.ts +78 -0
  1965. package/src/shared/session-context.ts +58 -0
  1966. package/src/shared/shell-env.ts +75 -0
  1967. package/src/shared/skill-mount.ts +214 -0
  1968. package/src/shared/skill-resolver.ts +167 -0
  1969. package/src/shared/stall-watchdog.ts +122 -0
  1970. package/src/shared/status-offload.ts +742 -0
  1971. package/src/shared/status.ts +268 -0
  1972. package/src/shared/streaming-scheduler.ts +158 -0
  1973. package/src/shared/subagent-gate.ts +122 -0
  1974. package/src/shared/subagent-rows.ts +39 -0
  1975. package/src/shared/subagents.ts +75 -0
  1976. package/src/shared/synthesized-attachment.ts +100 -0
  1977. package/src/shared/telemetry-content.ts +301 -0
  1978. package/src/shared/thinking-mode.ts +125 -0
  1979. package/src/shared/todos.ts +68 -0
  1980. package/src/shared/tool-kind.ts +140 -0
  1981. package/src/shared/tool-lists.ts +617 -0
  1982. package/src/shared/tool-rounds.ts +151 -0
  1983. package/src/shared/tool-row.ts +346 -0
  1984. package/src/shared/trace-context.ts +35 -0
  1985. package/src/shared/with-timeout.ts +53 -0
  1986. package/src/shared/worker-shutdown.ts +134 -0
  1987. package/src/shared/workspace/__tests__/file-tree.test.ts +210 -0
  1988. package/src/shared/workspace/__tests__/git-credential.test.ts +470 -0
  1989. package/src/shared/workspace/__tests__/git-identity.test.ts +124 -0
  1990. package/src/shared/workspace/__tests__/git-source.test.ts +476 -0
  1991. package/src/shared/workspace/__tests__/local-backend-platform.test.ts +259 -0
  1992. package/src/shared/workspace/__tests__/local-backend.test.ts +160 -0
  1993. package/src/shared/workspace/__tests__/platform-mount.test.ts +378 -0
  1994. package/src/shared/workspace/__tests__/provisioner.test.ts +194 -0
  1995. package/src/shared/workspace/__tests__/session-provision.test.ts +322 -0
  1996. package/src/shared/workspace/__tests__/session-root.test.ts +42 -0
  1997. package/src/shared/workspace/__tests__/stigmer-link.test.ts +278 -0
  1998. package/src/shared/workspace/__tests__/workspace-lock.test.ts +207 -0
  1999. package/src/shared/workspace/__tests__/writeback-coordinator-git.test.ts +244 -0
  2000. package/src/shared/workspace/__tests__/writeback-coordinator.test.ts +495 -0
  2001. package/src/shared/workspace/file-tree.ts +116 -0
  2002. package/src/shared/workspace/git-credential.ts +247 -0
  2003. package/src/shared/workspace/git-identity.ts +41 -0
  2004. package/src/shared/workspace/local-backend.ts +132 -0
  2005. package/src/shared/workspace/platform-dir.ts +163 -0
  2006. package/src/shared/workspace/platform-mount.ts +190 -0
  2007. package/src/shared/workspace/provisioner.ts +119 -0
  2008. package/src/shared/workspace/session-provision.ts +104 -0
  2009. package/src/shared/workspace/session-root.ts +60 -0
  2010. package/src/shared/workspace/sources/empty.ts +19 -0
  2011. package/src/shared/workspace/sources/git.ts +292 -0
  2012. package/src/shared/workspace/sources/local-path.ts +92 -0
  2013. package/src/shared/workspace/stigmer-link.ts +185 -0
  2014. package/src/shared/workspace/types.ts +85 -0
  2015. package/src/shared/workspace/workspace-lock.ts +245 -0
  2016. package/src/shared/workspace/writeback-coordinator.ts +522 -0
  2017. package/src/shared/zip-extract.ts +118 -0
  2018. package/src/tools/__tests__/url-guard.test.ts +155 -0
  2019. package/src/tools/__tests__/web-fetch-tool.test.ts +193 -0
  2020. package/src/tools/index.ts +27 -0
  2021. package/src/tools/url-guard.ts +140 -0
  2022. package/src/tools/web-fetch-tool.ts +278 -0
  2023. package/src/worker.ts +112 -0
  2024. package/src/workflow-source.ts +72 -0
  2025. package/src/workflows/__tests__/barrel.test.ts +21 -0
  2026. package/src/workflows/__tests__/list-plugin-tools.test.ts +82 -0
  2027. package/src/workflows/index.ts +36 -0
  2028. package/src/workflows/list-plugin-tools.ts +70 -0
  2029. package/src/workflows/types.ts +46 -0
@@ -0,0 +1,1982 @@
1
+ /**
2
+ * The turn context — everything the runtime resolves for one agent turn
3
+ * before any harness runs, as small named phases producing one typed record.
4
+ *
5
+ * A turn begins with a dozen reads and provisions that have nothing to do
6
+ * with the engine that will run it: the execution and its session, the
7
+ * agent blueprint, the run's values, the workspace and its lock, the undos
8
+ * still owed to earlier turns, what the previous turn left waiting for
9
+ * approval, the MCP servers with the
10
+ * approval default and the agent's tool scope, the attachments, the standing context. Until #1070
11
+ * that sequence lived inline in the Cursor orchestrator
12
+ * (`activities/execute-cursor/index.ts` `executeCursorInner`, phases 1 to
13
+ * 9c); the native orchestrator carried a second copy in its `performSetup`.
14
+ * This module is the one copy. Each phase is a function that reads its
15
+ * inputs, reports its progress label, heartbeats once on entry, and returns
16
+ * a typed slice of the contract's `TurnInput`; {@link resolveTurnContext}
17
+ * sequences them, and the adapter runs its own harness-specific steps after
18
+ * the whole record exists.
19
+ *
20
+ * Shape, chosen against the native orchestrator's `setup.ts` (deleted in
21
+ * #1096): a typed record built from small functions (the `SetupResult` mold),
22
+ * never one 775-line `performSetup`. The record is the adapter contract's `TurnInput`
23
+ * (`types.ts`): every phase returns a named slice of it, and
24
+ * {@link resolveTurnContext} composes the whole. There is no wider
25
+ * "runtime-private" record beside it — the lock release and the write-back
26
+ * coordinator a phase produces are the caller's `TurnFrame` resources, set
27
+ * the instant they exist so a `finally` sees them on every path (a first cut
28
+ * had a `TurnContext extends TurnInput` for them; once the groups lifted,
29
+ * nothing read the extension after composition, so #1070 shipped without it).
30
+ *
31
+ * Three rules every phase obeys:
32
+ *
33
+ * - It never persists and never returns a slim status. A phase that can end
34
+ * the turn (the lock, the reconcile turn's undo) returns a
35
+ * {@link TurnSettlement} naming WHAT was decided; the caller writes the
36
+ * status, persists once and returns. The lock golden pins that persist as
37
+ * the turn's one and only, which is why the rule is structural.
38
+ * - It imports nothing from `src/activities/` (pinned by
39
+ * `__tests__/import-direction.test.ts`). A fact only the harness knows
40
+ * (its file-review identity, its vision profile) arrives through
41
+ * `HarnessCapabilities`.
42
+ * - Its heartbeat pulse and its cold-start timing marks are its own: the
43
+ * step name it enters under is the mark name it emits, one vocabulary for
44
+ * "where in setup are we" in Temporal heartbeat details and the
45
+ * `execution_setup` log.
46
+ *
47
+ * What is deliberately NOT here, and where it is instead:
48
+ *
49
+ * - Cursor's catalog validation of the requested model (`resolveModelId`),
50
+ * the pricing preload and the MCP env pre-flight warning stay in the
51
+ * Cursor adapter: each reads a module that is the adapter's own, and the
52
+ * runtime carries the REQUESTED model name so every harness validates
53
+ * against its own catalog. The skill mount was in that list until #1070
54
+ * found it reads the control plane, which only the runtime holds; it is
55
+ * {@link mountSkills}.
56
+ * - The approval grants, the HITL gate, the capture baseline pin and the
57
+ * Cursor agent itself (phases 5c, 7, 8a, 9) are the adapter's.
58
+ * - The memory selection is a memoized thunk, not a value: whether a prompt
59
+ * carries standing context depends on how the ENGINE resolved (a resumed
60
+ * agent already holds it), which the runtime learns only after the
61
+ * adapter runs. The runtime prepares the selection once; the adapter
62
+ * pulls it when its prompt needs it.
63
+ */
64
+
65
+ import { CancelledFailure } from "@temporalio/activity";
66
+ import { clone } from "@bufbuild/protobuf";
67
+ import { RunStatusSchema, type Run, type RunStatus } from "@stigmer/apis/ai/stigmer/agentic/run/v1/api_pb";
68
+ import { RunPhase } from "@stigmer/apis/ai/stigmer/agentic/run/v1/enum_pb";
69
+ import type { RunSpec } from "@stigmer/apis/ai/stigmer/agentic/run/v1/spec_pb";
70
+ import type { RunConfig } from "@stigmer/apis/ai/stigmer/agentic/run/v1/invocation_pb";
71
+ import type { Session } from "@stigmer/apis/ai/stigmer/agentic/session/v1/api_pb";
72
+ import type { SessionEvent } from "@stigmer/apis/ai/stigmer/agentic/session/v1/event_pb";
73
+
74
+ import type { Config } from "../config.js";
75
+ import type { StigmerClient } from "../client/stigmer-client.js";
76
+ import { scopedRunnerCredential } from "../client/token-claims.js";
77
+ import type { NormalizedActivityInput } from "../shared/activity-input.js";
78
+ import { APPROVAL_ANSWER_EVENT_TYPES, approvalAnswersOf, copyAnswersOntoRows, type ApprovalAsk } from "./approval-answers.js";
79
+ import { RESUME_SEED_EVENT_TYPES, resumeSeedOf } from "./transcript/resume-seed.js";
80
+ import type { ArtifactStorage } from "../shared/artifact-storage.js";
81
+ import type { TimingRecorder } from "../shared/cold-start-timing.js";
82
+ import { resolveBlueprint, type ResolvedBlueprint } from "../shared/blueprint-resolver.js";
83
+ import { fetchTurnValues, RunValuesRefusedError, type RepositoryToken, type RunValues } from "../shared/run-values.js";
84
+ import { provisionSessionWorkspace } from "../shared/workspace/session-provision.js";
85
+ import { WriteBackCoordinator } from "../shared/workspace/writeback-coordinator.js";
86
+ import { isGitWorkTree } from "../shared/filereview/git-substrate.js";
87
+ import { type CaseArchive, fetchCaseArchive } from "../shared/eval-case/case-archive.js";
88
+ import { prepareEvalCase, type PreparedEvalCase } from "../shared/eval-case/prepare-case.js";
89
+ import { chatAgentMockModel } from "../shared/eval-case/agent-mock.js";
90
+ import type { MockEndpoint } from "../shared/eval-case/mock-endpoint.js";
91
+ import { formatTryStop } from "@stigmer/eval-runtime";
92
+ import { deriveCaptureMode, deriveCaptureSubstrate, type UndoOutcome } from "../shared/filereview/capture.js";
93
+ import {
94
+ acquireWorkspaceLock,
95
+ WorkspaceLockCancelledError,
96
+ WorkspaceLockTimeoutError,
97
+ type ReleaseWorkspaceLock,
98
+ } from "../shared/workspace/workspace-lock.js";
99
+ import { LocalWorkspaceBackend } from "../shared/workspace/local-backend.js";
100
+ import {
101
+ describeServerHome,
102
+ DuplicateServerNameError,
103
+ platformServerSlugsOf,
104
+ resolveTurnServers,
105
+ sameServerHome,
106
+ } from "../shared/mcp-resolver.js";
107
+ import { resolveMcpTransportPosture } from "../shared/mcp-transport-guard.js";
108
+ import { callerIdentityValues, resolveCallerIdentity } from "../shared/caller-identity.js";
109
+ import { discoverChannelMessaging, synthesizeChannelAttachment } from "../shared/channel-attachment.js";
110
+ import { readChannelConversationId, synthesizeConversationAttachment } from "../shared/conversation-attachment.js";
111
+ import { synthesizeMemoryAttachment } from "../shared/memory-attachment.js";
112
+ import { injectSynthesizedAttachment } from "../shared/synthesized-attachment.js";
113
+ import { buildMcpApprovalDefault, deriveActiveLeases, NOTHING_LISTED, type LeaseGrant } from "../shared/approval-policy.js";
114
+ import { listTurnTools, type McpToolListing } from "../shared/mcp-tool-listing.js";
115
+ import { ToolScope } from "../shared/tool-lists.js";
116
+ import { resolveAttachments } from "../shared/attachment-resolver.js";
117
+ import { resolveSkills, type SkillMetadata } from "../shared/skill-resolver.js";
118
+ import type { ApiResourceReference } from "@stigmer/apis/ai/stigmer/commons/apiresource/io_pb";
119
+ import { loadedVersionsOf } from "./loaded-versions.js";
120
+ import { mountPlugin, PluginMountError } from "../shared/plugin-mount.js";
121
+ import { isTerminalError } from "../shared/grpc-retry.js";
122
+ import { hookServerNamesOf } from "../shared/hooks/tool-view.js";
123
+ import { getPlatformDir } from "../shared/workspace/platform-dir.js";
124
+ import { HookFormat } from "@stigmer/apis/ai/stigmer/agentic/plugin/v1/hooks_pb";
125
+ import type { HookSource } from "@stigmer/apis/ai/stigmer/agentic/agent/v1/spec_pb";
126
+ import type { HookFormatName } from "../shared/hooks/hook-set.js";
127
+ import type { Plugin } from "@stigmer/apis/ai/stigmer/agentic/plugin/v1/api_pb";
128
+ import { join } from "node:path";
129
+ import { PLUGINS_SUBDIR } from "../shared/plugin-mount.js";
130
+ import { ensureStigmerSymlink, STIGMER_LOCAL_STATE_DIR } from "../shared/workspace/stigmer-link.js";
131
+ import { pluginAgentName } from "../shared/blueprint-resolver.js";
132
+ import type { ResolvedMcpServer } from "../shared/mcp-resolver.js";
133
+ import { VisionBudget, type NotViewableEntry, type VisionProfile } from "../shared/attachment-vision.js";
134
+ import { getDefaultModel, getModelVisionCapability } from "../shared/model-registry.js";
135
+ import { pluginSubagentScope, savedSubagentScope, subagentModel } from "../shared/subagents.js";
136
+ import { applyApprovedWholeFileWrites } from "../shared/exact-apply.js";
137
+ import { resolveEffectiveServiceTier } from "../shared/service-tier.js";
138
+ import { resolveEffectiveThinkingMode } from "../shared/thinking-mode.js";
139
+ import { readContextBridge } from "../shared/context-bridge.js";
140
+ import { readSenderIdentity } from "../shared/sender-identity.js";
141
+ import { readSessionContext } from "../shared/session-context.js";
142
+ import { readDeclaredPreferences } from "../shared/declared-preferences.js";
143
+ import { sessionIdOf } from "../shared/execution-target.js";
144
+ import { readConversationCatchup } from "../shared/conversation-catchup.js";
145
+ import { selectRecalledFacts } from "../shared/memory-retrieval.js";
146
+ import type { RecalledMemoriesContent } from "../shared/recalled-memories.js";
147
+ import type { HarnessCapabilities, PausePrimitive, StateIdSource } from "./capabilities.js";
148
+ import { reconcileOwedUndos, type ReconciledUndo } from "./owed-undos.js";
149
+ import type { RunFacts } from "./run-span.js";
150
+ import type { TranscriptBuilder } from "./transcript/builder.js";
151
+ import type {
152
+ TurnAttachments,
153
+ TurnHookSource,
154
+ TurnHooks,
155
+ TurnInput,
156
+ TurnMcp,
157
+ TurnModelPreferences,
158
+ TurnSkills,
159
+ TurnStandingContext,
160
+ TurnSubagent,
161
+ TurnWorkspace,
162
+ } from "./types.js";
163
+ import type { ApprovalAction } from "../gen/turn/ai/stigmer/runner/turn/v1/enum_pb.js";
164
+ import type { RecalledMemoriesReport, TurnRows } from "../gen/turn/ai/stigmer/runner/turn/v1/rows_pb.js";
165
+
166
+ // ---------------------------------------------------------------------------
167
+ // What the phases take
168
+ // ---------------------------------------------------------------------------
169
+
170
+ /**
171
+ * What every phase reads from its caller. The activity's identity and the
172
+ * runtime's own seams; nothing harness-specific. The four function members
173
+ * are the caller's, injected so the phase bodies are the same code under
174
+ * the Cursor orchestrator it left and under `run-turn.ts` (only the
175
+ * binding changes), and so a test can drive a phase without a Temporal
176
+ * activity context.
177
+ */
178
+ export interface ResolutionDeps {
179
+ /** The activity's own identity: execution id, engine state id, HITL cycle index. */
180
+ readonly input: NormalizedActivityInput;
181
+ readonly client: StigmerClient;
182
+ /**
183
+ * The whole runner config. The runtime is its rightful reader; a shared
184
+ * helper that needs two fields is handed a narrowed view of it
185
+ * (`SessionProvisionConfig`), never the other way round.
186
+ */
187
+ readonly config: Config;
188
+ /**
189
+ * The one execution status this turn writes. Phases write the runtime's
190
+ * OWN fields here (the loaded versions, the status outputs a reinvocation
191
+ * carries over); nothing else does.
192
+ */
193
+ readonly status: RunStatus;
194
+ /**
195
+ * The turn's rows, which the builder folds into and the session's log is
196
+ * written from. Phases write only the runtime's own fields here (the
197
+ * memory-selection report); rows arrive through the builder.
198
+ */
199
+ readonly rows: TurnRows;
200
+ /**
201
+ * The one transcript builder over `rows`, the caller's, born with them.
202
+ * Two phases hand it on: the seed appends a reinvocation's asks through
203
+ * it (so they are indexed as they land), and the workspace phase gives it
204
+ * to the write-back coordinator as the place a write-back record is
205
+ * registered. One phase folds a single event of its own: the MCP phase's
206
+ * system note when the platform's tools are off for the turn
207
+ * (`resolveMcpServersAndPolicies`). No engine has run yet.
208
+ */
209
+ readonly transcript: TranscriptBuilder;
210
+ /** Resolved once by the caller before any phase; absent when no substrate works. */
211
+ readonly artifactStorage: ArtifactStorage | undefined;
212
+ /** The cold-start timeline; each phase marks its own segment(s) exactly as before. */
213
+ readonly timing: TimingRecorder;
214
+ /** Cancellation for the one wait a phase can block on (the workspace lock). */
215
+ readonly signal: AbortSignal;
216
+ /** The Temporal heartbeat, handed to helpers that pulse mid-call (the lock wait). */
217
+ readonly heartbeat: () => void;
218
+ /**
219
+ * "Resolution is now at this step": labels the caller's periodic heartbeat
220
+ * and pulses once. Every phase calls it first with its own step name.
221
+ */
222
+ readonly enterPhase: (step: string) => void;
223
+ /** The user-visible setup label (`setupProgress`); the six strings are unchanged from the orchestrator. */
224
+ readonly reportProgress: (label: string) => Promise<void>;
225
+ /**
226
+ * The run and its session are known: the turn's trace span takes its
227
+ * name and facts from them (`run-span.ts`). Called once, right after the
228
+ * blueprint resolves, so a turn that settles during resolution is named
229
+ * too.
230
+ */
231
+ readonly identifyRun: (facts: RunFacts) => void;
232
+ /**
233
+ * Writes what the turn's start put back for earlier turns into the
234
+ * session's log at once (`events/emitter.ts` `writeReconciled`), before the
235
+ * workspace lock is released (`owed-undos.ts`).
236
+ */
237
+ readonly recordReconciled: (answers: readonly ReconciledUndo[]) => Promise<void>;
238
+ }
239
+
240
+ // ---------------------------------------------------------------------------
241
+ // What the reinvocation phase answers
242
+ // ---------------------------------------------------------------------------
243
+
244
+ /**
245
+ * What the previous invocation left for this one (phase 3). Not part of
246
+ * `TurnInput`: `isReinvocation` is the adapter's own derivation from
247
+ * `threadId` (the contract carries no flag by design, `types.ts` header) and
248
+ * the runtime reads it only inside {@link resolveTurnContext}; the decisions
249
+ * and the asks ARE on the input. The seeded asks are on `sink.rows`
250
+ * (`transcript/resume-seed.ts`), each carrying the log's answer to its call; an
251
+ * adapter wraps them by reference.
252
+ */
253
+ export interface TurnReinvocation {
254
+ /** The engine already holds state for this execution (derived per {@link isReinvocation}). */
255
+ readonly isReinvocation: boolean;
256
+ /**
257
+ * The log holds what an earlier invocation of this run's engine did
258
+ * ({@link runWroteEngineEvents}): the emitter's `resumed`, which reads
259
+ * back what the run already wrote before writing on.
260
+ */
261
+ readonly runWroteEvents: boolean;
262
+ /** The answered WAITING rows, keyed by tool-call id; empty when nothing was answered. */
263
+ readonly approvalDecisions: ReadonlyMap<string, ApprovalAction>;
264
+ /** The reason a person gave with each deny that carries one, by tool-call id. */
265
+ readonly approvalDenyMessages: ReadonlyMap<string, string>;
266
+ /** What each of the run's asked calls was asked under, by tool use id (`approval-answers.ts`). */
267
+ readonly approvalAsks: ReadonlyMap<string, ApprovalAsk>;
268
+ /** The run's grants, by the tool use id each was given on: the leases phase 4b arms. */
269
+ readonly grants: ReadonlyMap<string, LeaseGrant>;
270
+ /** The run's newest root `agent.message` an earlier invocation wrote: the run's answer when this one writes none. */
271
+ readonly answerText: string | undefined;
272
+ /** The memory selection an earlier invocation recorded (`stigmer.memory.recalled`): replayed, never re-selected. */
273
+ readonly recalledMemoriesReport: RecalledMemoriesReport | undefined;
274
+ }
275
+
276
+ // ---------------------------------------------------------------------------
277
+ // Settlements
278
+ // ---------------------------------------------------------------------------
279
+
280
+ /**
281
+ * A turn that ended during resolution, before any harness ran. Each arm
282
+ * names what was decided and carries only the facts the caller's status
283
+ * writes need; the copy, the phase flip, the persist and the slim return are
284
+ * the caller's (the runtime's terminal table).
285
+ *
286
+ * - `workspace-lock-timeout`: another turn held the primary tree past
287
+ * `Config.workspaceLockTimeoutMs`. FAILED, returned (a Temporal retry
288
+ * would queue behind the same holder).
289
+ * - `values-refused`: the run's value fetch was refused for a reason its
290
+ * person fixes (an entry gone from its vault, a vault the run may no
291
+ * longer use, a tool moved to another address, a sign-in that cannot be
292
+ * renewed). FAILED with the server's message, returned: a retry would
293
+ * read the same vaults.
294
+ * - `file-review-resolved`: a reconcile turn (`RunSpec.reconcile_file_review`),
295
+ * the run a person's Undo on an ended turn starts: putting back the undos
296
+ * still owed is the whole act, and no engine runs. COMPLETED, returned,
297
+ * with the write-back finalized first when every undo held.
298
+ * - `eval-scaffold-failed`: a eval-run try's scaffold exited non-zero or
299
+ * ran past its limit. TERMINATED with the try stop's sentence, returned:
300
+ * the eval scores the try 0, and a retry would run the same script.
301
+ * - `run-finished`: the run finished while this invocation waited for its
302
+ * workspace ({@link runFinishedWhileWaiting}). Returned with the phase
303
+ * the server holds, and nothing written: the server takes no more status
304
+ * and no more events of a finished run.
305
+ *
306
+ * A REJECTed tool is not a settlement: the run continues without it
307
+ * (`approval-decisions.ts`).
308
+ */
309
+ export type TurnSettlement =
310
+ | { readonly kind: "workspace-lock-timeout"; readonly error: WorkspaceLockTimeoutError }
311
+ | {
312
+ readonly kind: "file-review-resolved";
313
+ readonly failed: boolean;
314
+ readonly failureDetail: string;
315
+ readonly discardedPaths: readonly string[];
316
+ }
317
+ | {
318
+ /** The agent's hooks cannot run as written; `message` names what and why, for the person who owns the agent. */
319
+ readonly kind: "hooks-refused";
320
+ readonly message: string;
321
+ }
322
+ | {
323
+ /** The run's values could not be fetched; `message` is the server's, naming the key, its declarer and the vault. */
324
+ readonly kind: "values-refused";
325
+ readonly message: string;
326
+ }
327
+ | {
328
+ /** A eval-run try's scaffold failed; `message` is the try stop's sentence (`@stigmer/eval-runtime` `formatTryStop`). */
329
+ readonly kind: "eval-scaffold-failed";
330
+ readonly message: string;
331
+ }
332
+ | {
333
+ /** The run finished while the turn waited for its workspace; `status` is the run's as the server holds it. */
334
+ readonly kind: "run-finished";
335
+ readonly status: RunStatus;
336
+ };
337
+
338
+ /** The values phase's answer: the run's values, or the settlement a refused fetch produces. */
339
+ export type ValuesOutcome =
340
+ | { readonly kind: "ready"; readonly values: RunValues }
341
+ | { readonly kind: "settled"; readonly settlement: Extract<TurnSettlement, { kind: "values-refused" }> };
342
+
343
+ /**
344
+ * The lock phase's answer: the release handle (absent when there is no
345
+ * primary tree) and whether another turn held the tree first, or the one
346
+ * settlement a lock can produce.
347
+ */
348
+ export type WorkspaceLockOutcome =
349
+ | { readonly kind: "acquired"; readonly release: ReleaseWorkspaceLock | undefined; readonly waited: boolean }
350
+ | { readonly kind: "settled"; readonly settlement: Extract<TurnSettlement, { kind: "workspace-lock-timeout" }> };
351
+
352
+ // ---------------------------------------------------------------------------
353
+ // Pure helpers (exported for their tests and for the adapter kit)
354
+ // ---------------------------------------------------------------------------
355
+
356
+ /**
357
+ * Whether the engine already holds state for this execution, so this
358
+ * invocation resumes rather than begins. One function keyed on how the
359
+ * harness mints its state id:
360
+ *
361
+ * - `engine-minted` (Cursor: the agent id): the runtime knows nothing until
362
+ * the adapter binds an id, so a non-empty `threadId` IS the evidence.
363
+ * Correct today because a pure-reconcile turn does not advance `turnSeq`
364
+ * and the legacy positional wire shape yields 0, so `turnSeq` cannot be
365
+ * the signal.
366
+ * - `deterministic` (native: the runtime-minted thread id): the id exists
367
+ * on the FIRST turn too, so the evidence is the session's log: whether it
368
+ * holds an event the runner wrote from this run's engine
369
+ * ({@link runWroteEngineEvents}). Whether the execution already has
370
+ * committed history is the ONE signal that behaves identically across
371
+ * the engine's checkpointer backends: a durable saver (sqlite locally,
372
+ * http in cloud) keeps the checkpoint and resumes from it, while the
373
+ * test-only memory saver recreates it empty and replays from scratch —
374
+ * so the live checkpoint cannot be the signal (native's
375
+ * `shouldSeedFromPersistedTranscript`, retired with its orchestrator).
376
+ * Any event of the run cannot be it either: the server writes the run's
377
+ * `user.message` when it creates the run. A first run's engine has
378
+ * written nothing and starts from empty, as it always did.
379
+ *
380
+ * This is the runtime's own reading, for its phases (the seed, the
381
+ * exact-apply). An adapter that needs create-vs-resume for its ENGINE
382
+ * reads `input.threadId` itself — for an engine-minted harness that is the
383
+ * same bit, for a deterministic one the engine's checkpoint is the adapter's
384
+ * to consult — so the contract carries no flag with two meanings.
385
+ */
386
+ export function isReinvocation(
387
+ stateIdSource: StateIdSource,
388
+ input: NormalizedActivityInput,
389
+ runWroteEvents: boolean,
390
+ ): boolean {
391
+ switch (stateIdSource) {
392
+ case "engine-minted":
393
+ return input.threadId !== "";
394
+ case "deterministic":
395
+ return runWroteEvents;
396
+ default: {
397
+ const exhaustive: never = stateIdSource;
398
+ throw new Error(`isReinvocation: unknown state id source ${String(exhaustive)}`);
399
+ }
400
+ }
401
+ }
402
+
403
+ /**
404
+ * The event types the runner writes from the rows its engine produced
405
+ * (`events/emitter.ts` `writeMessage`, `writeToolUse`): a message, a
406
+ * thinking, a tool use, a harness note. The other types a runner may write
407
+ * say nothing about the engine: `stigmer.memory.recalled` is written at the
408
+ * turn's first write whatever the engine did, and
409
+ * `stigmer.file_review.reconciled` at the turn's start, before any engine;
410
+ * the rest follow one of these.
411
+ */
412
+ export const ENGINE_EVENT_TYPES = [
413
+ "agent.message",
414
+ "agent.thinking",
415
+ "agent.tool_use",
416
+ "agent.mcp_tool_use",
417
+ "stigmer.harness.note",
418
+ ] as const;
419
+
420
+ /**
421
+ * Whether the session's log holds an event an earlier invocation of this
422
+ * run wrote from its engine ({@link ENGINE_EVENT_TYPES}): one read of at
423
+ * most one event. Throws when the log cannot be read, as the turn's other
424
+ * control-plane reads do.
425
+ */
426
+ export async function runWroteEngineEvents(
427
+ client: Pick<StigmerClient, "hasRunSessionEvent">,
428
+ sessionId: string,
429
+ runId: string,
430
+ ): Promise<boolean> {
431
+ return client.hasRunSessionEvent(sessionId, runId, ENGINE_EVENT_TYPES);
432
+ }
433
+
434
+ /**
435
+ * The run's events, read from the session's log each time it is called
436
+ * (`TurnInput.readRunEvents`): what an adapter tells the turn's story from.
437
+ */
438
+ export function runEventsReader(
439
+ client: Pick<StigmerClient, "listRunSessionEvents">,
440
+ sessionId: string,
441
+ runId: string,
442
+ ): () => Promise<readonly SessionEvent[]> {
443
+ return () => client.listRunSessionEvents(sessionId, runId);
444
+ }
445
+
446
+ /**
447
+ * Carry the status's own outputs over on a resume (HITL approval,
448
+ * pause/resume, transient recovery): the artifacts and write-backs earlier
449
+ * invocations registered, and the streaming usage so far. They are the run's
450
+ * file outputs and cost, not its transcript, and the server takes each list
451
+ * a write carries as the whole list, so a resumed turn that publishes one
452
+ * artifact sends every earlier one too. The persisted protos are cloned so
453
+ * the input execution stays immutable. Nothing of the transcript is carried:
454
+ * the asks a resumed engine resumes onto come from the session's log
455
+ * (`transcript/resume-seed.ts`), and every other row is the invocation's own.
456
+ */
457
+ export function seedStatusOutputs(status: RunStatus, execution: Run): void {
458
+ const persisted = execution.status;
459
+ if (!persisted) return;
460
+ const seed = clone(RunStatusSchema, persisted);
461
+ status.artifacts.push(...seed.artifacts);
462
+ status.workspaceWriteBacks.push(...seed.workspaceWriteBacks);
463
+ if (seed.streamingUsage !== undefined) status.streamingUsage = seed.streamingUsage;
464
+ }
465
+
466
+ /** The log types a reinvocation reads, once: the seed's and the answers'. */
467
+ export const REINVOCATION_EVENT_TYPES: readonly string[] = [...new Set<string>([...RESUME_SEED_EVENT_TYPES, ...APPROVAL_ANSWER_EVENT_TYPES])];
468
+
469
+ // ---------------------------------------------------------------------------
470
+ // The phases, in the order the turn runs them
471
+ // ---------------------------------------------------------------------------
472
+
473
+ /** Phase 1: hydrate the execution from the control plane. */
474
+ export async function fetchExecution(deps: ResolutionDeps): Promise<{
475
+ readonly execution: Run;
476
+ /** `execution.spec`, asserted once here: the control plane never dispatches an execution without one. */
477
+ readonly spec: RunSpec;
478
+ readonly sessionId: string;
479
+ }> {
480
+ deps.enterPhase("fetch_execution");
481
+ await deps.reportProgress("Fetching execution");
482
+ const execution = await deps.client.getExecution(deps.input.executionId);
483
+ const spec = execution.spec!;
484
+ deps.timing.mark("fetch_execution");
485
+ return { execution, spec, sessionId: sessionIdOf(spec) };
486
+ }
487
+
488
+ /**
489
+ * Phase 2: load the session and resolve the full agent blueprint: the agent
490
+ * and version the execution recorded at create, merged with the session's
491
+ * own tools.
492
+ */
493
+ export async function resolveAgentBlueprint(
494
+ deps: ResolutionDeps,
495
+ execution: Run,
496
+ sessionId: string,
497
+ ): Promise<{ readonly session: Session; readonly blueprint: ResolvedBlueprint }> {
498
+ deps.enterPhase("resolve_blueprint");
499
+ await deps.reportProgress("Resolving agent blueprint");
500
+ const session = await deps.client.getSession(sessionId);
501
+ const blueprint = await resolveBlueprint(
502
+ deps.client,
503
+ session,
504
+ execution.status,
505
+ execution.metadata?.labels ?? {},
506
+ execution.spec?.excludedPluginIds,
507
+ );
508
+ deps.timing.mark("resolve_blueprint");
509
+ return { session, blueprint };
510
+ }
511
+
512
+ /**
513
+ * Phase 2b: the run's values, fetched from their vaults now and grouped by
514
+ * declarer (`shared/run-values.ts`). A fetch refused for a reason the
515
+ * person fixes settles the turn with the server's message.
516
+ */
517
+ export async function fetchValues(deps: ResolutionDeps): Promise<ValuesOutcome> {
518
+ deps.enterPhase("fetch_values");
519
+ await deps.reportProgress("Fetching values from vaults");
520
+ let values: RunValues;
521
+ try {
522
+ values = await fetchTurnValues(deps.client, deps.input.executionId);
523
+ } catch (err) {
524
+ if (err instanceof RunValuesRefusedError) {
525
+ return { kind: "settled", settlement: { kind: "values-refused", message: err.message } };
526
+ }
527
+ throw err;
528
+ }
529
+ deps.timing.mark("fetch_values");
530
+ return { kind: "ready", values };
531
+ }
532
+
533
+ /**
534
+ * Phase 2c, first half: provision the workspace (clone
535
+ * git repos / mount local paths) so the LOCAL agent operates on the actual
536
+ * repo, wire the git write-back coordinator, and decide the capture posture.
537
+ *
538
+ * Git provisioning is idempotent across multi-turn and HITL reinvocations.
539
+ * The write-back coordinator pushes the session's tree to the session branch
540
+ * (stigmer/<session-id>) and keeps one PR open; finalize runs at exactly two
541
+ * seams (a reconcile turn, after it put undone files back, and terminal
542
+ * completion), never mid-turn. Non-eligible workspaces (local paths, no
543
+ * credentials) make it a no-op coordinator, here `null`.
544
+ *
545
+ * File review is opt-in (`review`: the session's `file_review`, or a
546
+ * eval-run try). With it on, apply-then-review is the model: a git work
547
+ * tree captures per-file from the git diff at the turn boundary; a NON-git
548
+ * workspace captures every write via the path-scoped CAS substrate, which
549
+ * needs artifact storage to persist blobs, and falls back to the classic
550
+ * deny-gate without it. With it off, file edits flow and nothing is
551
+ * captured. `gitWorkspace` selects the substrate, `captureSubstrate` says
552
+ * whether one exists (the secret-path rule's input), `captureMode` whether
553
+ * capture runs.
554
+ *
555
+ * The change-set id is minted from the workflow-threaded turn index so it is
556
+ * stable across a Temporal retry (idempotent ledger authoring) and unique per
557
+ * turn; a "wasted" id on a turn that captures nothing is harmless.
558
+ */
559
+ export async function provisionWorkspace(
560
+ deps: ResolutionDeps,
561
+ args: {
562
+ readonly session: Session;
563
+ readonly sessionId: string;
564
+ readonly repositories: readonly RepositoryToken[];
565
+ /** Whether this turn's edits are offered for review ({@link fileReviewOn}). */
566
+ readonly review: boolean;
567
+ },
568
+ ): Promise<{ readonly workspace: TurnWorkspace; readonly writeback: WriteBackCoordinator | null }> {
569
+ deps.enterPhase("provision_workspace");
570
+ await deps.reportProgress("Provisioning workspace");
571
+ const provision = await provisionSessionWorkspace(deps.config, args.session, args.repositories, args.sessionId);
572
+ deps.timing.mark("provision_workspace");
573
+
574
+ const writeback = provision.provisionResults.length > 0
575
+ ? new WriteBackCoordinator({
576
+ writeBacks: deps.transcript,
577
+ executionId: deps.input.executionId,
578
+ sessionId: args.sessionId,
579
+ repositories: args.repositories,
580
+ provisionResults: provision.provisionResults,
581
+ workspaceEntries: args.session.spec?.workspaceEntries ?? [],
582
+ workspaceBackend: provision.workspaceBackend,
583
+ })
584
+ : null;
585
+
586
+ const primaryDir = provision.workspaceDirs[0];
587
+ const gitWorkspace = primaryDir ? await isGitWorkTree(primaryDir) : false;
588
+ const captureSubstrate = deriveCaptureSubstrate(primaryDir, gitWorkspace, !!deps.artifactStorage);
589
+ const captureMode = deriveCaptureMode(primaryDir, gitWorkspace, !!deps.artifactStorage, args.review);
590
+ const changeSetId = `${deps.input.executionId}:${deps.input.turnSeq}`;
591
+
592
+ return {
593
+ workspace: {
594
+ dirs: provision.workspaceDirs,
595
+ primaryDir,
596
+ gitWorkspace,
597
+ captureSubstrate,
598
+ fileReview: args.review,
599
+ captureMode,
600
+ changeSetId,
601
+ provision,
602
+ },
603
+ writeback,
604
+ };
605
+ }
606
+
607
+ /**
608
+ * Whether a turn's file edits are offered for review: the session asked
609
+ * (`SessionSpec.file_review`, off unless set), or the run is an eval
610
+ * run's try, whose file graders read the captured sets whatever the switch says.
611
+ */
612
+ export function fileReviewOn(session: Session, spec: RunSpec): boolean {
613
+ return (session.spec?.fileReview ?? false) || spec.evalCase !== undefined;
614
+ }
615
+
616
+ /**
617
+ * Phase 2c, second half: serialize this turn against
618
+ * every other execution sharing the primary working tree. Sessions declaring
619
+ * the same localPath (or the shared runner root) resolve to ONE directory,
620
+ * and an unserialized concurrent write lands inside this turn's
621
+ * baseline→candidate window, misattributing another session's file to this
622
+ * turn's review. Acquired before ANY tree mutation (the owed undos, gate
623
+ * install, agent writes, capture); while another turn holds the lock this
624
+ * surfaces a visible waiting state and heartbeats; a cancel aborts the wait
625
+ * at once.
626
+ *
627
+ * Its own phase so the release handle reaches the caller the instant the
628
+ * lock exists: nothing runs between acquisition and hand-over, so nothing
629
+ * can throw and leave a held lock the caller's `finally` never sees.
630
+ */
631
+ export async function acquireWorkspaceTurnLock(
632
+ deps: ResolutionDeps,
633
+ primaryDir: string,
634
+ ): Promise<WorkspaceLockOutcome> {
635
+ deps.enterPhase("acquire_workspace_lock");
636
+ let release: ReleaseWorkspaceLock | undefined;
637
+ let waited = false;
638
+ if (primaryDir) {
639
+ try {
640
+ release = await acquireWorkspaceLock(primaryDir, {
641
+ onWaiting: () => {
642
+ waited = true;
643
+ return deps.reportProgress("Waiting for workspace — in use by another session");
644
+ },
645
+ heartbeat: deps.heartbeat,
646
+ signal: deps.signal,
647
+ timeoutMs: deps.config.workspaceLockTimeoutMs,
648
+ });
649
+ } catch (lockErr) {
650
+ if (lockErr instanceof WorkspaceLockCancelledError) {
651
+ throw new CancelledFailure("Activity cancelled while waiting for the workspace lock");
652
+ }
653
+ if (lockErr instanceof WorkspaceLockTimeoutError) {
654
+ return { kind: "settled", settlement: { kind: "workspace-lock-timeout", error: lockErr } };
655
+ }
656
+ throw lockErr;
657
+ }
658
+ }
659
+ deps.timing.mark("acquire_workspace_lock");
660
+ return { kind: "acquired", release, waited };
661
+ }
662
+
663
+ /** The phases the server holds as finished: it takes no more status and no more events of such a run. */
664
+ const FINISHED_PHASES: ReadonlySet<RunPhase> = new Set([
665
+ RunPhase.RUN_COMPLETED,
666
+ RunPhase.RUN_FAILED,
667
+ RunPhase.RUN_CANCELLED,
668
+ RunPhase.RUN_TERMINATED,
669
+ ]);
670
+
671
+ /**
672
+ * Phase 2c, after the lock: a turn that waited for its workspace reads its
673
+ * run again, and ends with the run when it finished meanwhile.
674
+ *
675
+ * The turn holding the workspace can be an earlier invocation of the same
676
+ * run. A pause cancels the running activity, but the cancellation reaches
677
+ * the runner only at its next heartbeat, so the paused invocation can
678
+ * finish its turn, persist the run finished and only then let the resumed
679
+ * one have the tree. The server takes nothing more of a finished run (no
680
+ * status, no event), so an invocation that ran on would spend a model call
681
+ * whose answer the log refuses, and leave the engine's checkpoint holding a
682
+ * reply the session never shows. A turn that did not wait read its run
683
+ * moments ago (phase 1), so only a wait costs the second read.
684
+ */
685
+ export async function runFinishedWhileWaiting(
686
+ deps: ResolutionDeps,
687
+ waited: boolean,
688
+ ): Promise<Extract<TurnSettlement, { kind: "run-finished" }> | undefined> {
689
+ if (!waited) return undefined;
690
+ const status = (await deps.client.getExecution(deps.input.executionId)).status;
691
+ if (status === undefined || !FINISHED_PHASES.has(status.phase)) return undefined;
692
+ return { kind: "run-finished", status };
693
+ }
694
+
695
+ /** The eval phase's answer: nothing to do, the prepared case, or the settlement a failed scaffold produces. */
696
+ export type EvalCaseOutcome =
697
+ | {
698
+ readonly kind: "ready";
699
+ /** Absent on every run that is not a eval-run try. */
700
+ readonly prepared:
701
+ | {
702
+ readonly case: PreparedEvalCase;
703
+ /** The workspace with its capture substrate re-derived after the scaffold. */
704
+ readonly workspace: TurnWorkspace;
705
+ /** The run's values with the case's `EVAL_*` variables over the agent's. */
706
+ readonly values: RunValues;
707
+ /** The plugin's archive at the eval's version, which the mocks answer from. */
708
+ readonly archive: CaseArchive;
709
+ }
710
+ | undefined;
711
+ }
712
+ | { readonly kind: "settled"; readonly settlement: Extract<TurnSettlement, { kind: "eval-scaffold-failed" }> };
713
+
714
+ /**
715
+ * Phase 2d: a eval-run try's own setup (`shared/eval-case/
716
+ * prepare-case.ts`), after the workspace lock because the scaffold mutates
717
+ * the tree. The scaffold may make the workspace a git repository, so the
718
+ * capture substrate is derived again; the capture baseline is pinned after
719
+ * every phase (`run-turn.ts`), so what the scaffold made is baseline, never
720
+ * the try's change. The case's variables join the agent's run values, the
721
+ * one path to the native shell and the plugin's hooks.
722
+ */
723
+ export async function prepareEvalCasePhase(
724
+ deps: ResolutionDeps,
725
+ args: {
726
+ readonly spec: RunSpec;
727
+ readonly sessionId: string;
728
+ readonly workspace: TurnWorkspace;
729
+ readonly values: RunValues;
730
+ },
731
+ ): Promise<EvalCaseOutcome> {
732
+ const context = args.spec.evalCase;
733
+ if (context === undefined) return { kind: "ready", prepared: undefined };
734
+ deps.enterPhase("prepare_eval_case");
735
+ await deps.reportProgress("Preparing the eval case");
736
+ const archive = await fetchCaseArchive(deps.client, context);
737
+ const outcome = await prepareEvalCase({ context, archive, sessionId: args.sessionId, primaryDir: args.workspace.primaryDir });
738
+ deps.timing.mark("prepare_eval_case");
739
+ if (outcome.kind === "scaffold-failed") {
740
+ return {
741
+ kind: "settled",
742
+ settlement: { kind: "eval-scaffold-failed", message: formatTryStop({ kind: "scaffold-failed", detail: outcome.detail }) },
743
+ };
744
+ }
745
+ const { primaryDir, fileReview } = args.workspace;
746
+ const gitWorkspace = primaryDir ? await isGitWorkTree(primaryDir) : false;
747
+ const hasStorage = !!deps.artifactStorage;
748
+ return {
749
+ kind: "ready",
750
+ prepared: {
751
+ case: outcome.prepared,
752
+ workspace: {
753
+ ...args.workspace,
754
+ gitWorkspace,
755
+ captureSubstrate: deriveCaptureSubstrate(primaryDir, gitWorkspace, hasStorage),
756
+ captureMode: deriveCaptureMode(primaryDir, gitWorkspace, hasStorage, fileReview),
757
+ },
758
+ values: { ...args.values, agent: { ...args.values.agent, ...outcome.prepared.env } },
759
+ archive,
760
+ },
761
+ };
762
+ }
763
+
764
+ /**
765
+ * Phase 4c: a eval-run try's MCP stand-ins (`shared/eval-case/
766
+ * mock-endpoint.ts`). Each replaces the plugin's own server of the same
767
+ * name in the turn's list, so the real one is never started; a stand-in
768
+ * the turn's lists exclude whole is left out like any server (#2106). The
769
+ * endpoint goes on the frame at once, so the turn's `finally` closes it
770
+ * whatever happens next. Loaded only for a try with mocks: the MCP SDK's
771
+ * HTTP server imports `node:http2`, which must stay out of the pre-boot
772
+ * module graph (`src/__tests__/harness-boot-order.test.ts`).
773
+ */
774
+ export async function startEvalMocks(
775
+ deps: ResolutionDeps,
776
+ args: {
777
+ readonly spec: RunSpec;
778
+ readonly archive: CaseArchive;
779
+ readonly mcp: TurnMcp;
780
+ readonly frame: TurnFrame;
781
+ },
782
+ ): Promise<TurnMcp> {
783
+ const context = args.spec.evalCase;
784
+ if (context === undefined || context.mocks.length === 0) return args.mcp;
785
+ deps.enterPhase("start_eval_mocks");
786
+ const { startMockEndpoint } = await import("../shared/eval-case/mock-endpoint.js");
787
+ const endpoint = await startMockEndpoint({
788
+ context,
789
+ archive: args.archive,
790
+ agentModel: chatAgentMockModel({ modelName: context.agentMockModel, config: deps.config, executionId: deps.input.executionId }),
791
+ });
792
+ if (endpoint === undefined) return args.mcp;
793
+ args.frame.evalMocks = endpoint;
794
+ const standIns = callableServers(endpoint.servers, args.mcp.toolScope, args.mcp.platformServerSlugs);
795
+ const replaced = new Set(endpoint.servers.map((server) => server.slug));
796
+ const kept = new Set(standIns.map((server) => server.slug));
797
+ // An engine that does not read its tools' marks scopes a server's tools
798
+ // by the listing: a stand-in lists its mocked tools, none destructive.
799
+ const { listing } = args.mcp;
800
+ return {
801
+ ...args.mcp,
802
+ servers: [...args.mcp.servers.filter((server) => !replaced.has(server.slug)), ...standIns],
803
+ listing:
804
+ listing === undefined
805
+ ? undefined
806
+ : {
807
+ listed: [
808
+ ...listing.listed.filter(({ server }) => !replaced.has(server)),
809
+ ...endpoint.listed.filter(({ server }) => kept.has(server)),
810
+ ],
811
+ destructive: listing.destructive.filter(({ server }) => !replaced.has(server)),
812
+ unlisted: listing.unlisted.filter((server) => !replaced.has(server)),
813
+ },
814
+ };
815
+ }
816
+
817
+ /**
818
+ * Phase 3: what the previous invocation left.
819
+ *
820
+ * Whether this invocation resumes is read first ({@link isReinvocation},
821
+ * with the log's {@link runWroteEngineEvents}). On a reinvocation the run's
822
+ * events are read once ({@link REINVOCATION_EVENT_TYPES}) and the asks the
823
+ * engine resumes onto are seeded through the builder (`transcript/resume-seed.ts`),
824
+ * before any harness runs; the status's own outputs are carried over
825
+ * ({@link seedStatusOutputs}). Tool approvals (shell / MCP / a gated write)
826
+ * resolve from the answers the server appended to the session's log, read
827
+ * through the one door, `approval-answers.ts` `approvalAnswersOf`, and the
828
+ * seed then copies each call's answer from the log onto its row
829
+ * (`copyAnswersOntoRows`): every later reader of a row's `approval_action`
830
+ * reads the log's answer.
831
+ *
832
+ * Any answer runs the agent: an
833
+ * allowed call proceeds; a denied one is refused with the reason given, and
834
+ * the run continues without it (the row is settled SKIPPED after the turn,
835
+ * `approval-decisions.ts`). Until #1096 a REJECT failed the turn here with
836
+ * its own FAILED arm, Cursor's legacy; the proto (`APPROVAL_ACTION_REJECT`:
837
+ * "does NOT fail the run"), the conformance suite and the native harness
838
+ * said otherwise since stigmer#197, and the runtime agrees.
839
+ *
840
+ * File review is not here: a turn never waits on it, and the undos a person
841
+ * made after a turn are done at every turn's start, under the lock
842
+ * (`owed-undos.ts`). The step name is the wire's and stays.
843
+ */
844
+ export async function reconcileReinvocation(
845
+ deps: ResolutionDeps,
846
+ args: {
847
+ readonly stateIdSource: StateIdSource;
848
+ readonly execution: Run;
849
+ readonly sessionId: string;
850
+ },
851
+ ): Promise<TurnReinvocation> {
852
+ deps.enterPhase("reconcile_reinvocation");
853
+ const runId = deps.input.executionId;
854
+ const runWroteEvents = await runWroteEngineEvents(deps.client, args.sessionId, runId);
855
+ const reinvoked = isReinvocation(args.stateIdSource, deps.input, runWroteEvents);
856
+ if (!reinvoked) {
857
+ return {
858
+ isReinvocation: false,
859
+ runWroteEvents,
860
+ approvalDecisions: new Map(),
861
+ approvalDenyMessages: new Map(),
862
+ approvalAsks: new Map(),
863
+ grants: new Map(),
864
+ answerText: undefined,
865
+ recalledMemoriesReport: undefined,
866
+ };
867
+ }
868
+ seedStatusOutputs(deps.status, args.execution);
869
+ const events = await deps.client.listRunSessionEvents(args.sessionId, runId, REINVOCATION_EVENT_TYPES);
870
+ const seed = resumeSeedOf(runId, events);
871
+ deps.transcript.seed(seed.rows);
872
+ const answers = approvalAnswersOf(runId, deps.rows, events);
873
+ copyAnswersOntoRows(runId, deps.rows, answers);
874
+ return {
875
+ isReinvocation: true,
876
+ runWroteEvents,
877
+ approvalDecisions: answers.decisions,
878
+ approvalDenyMessages: answers.denyMessages,
879
+ approvalAsks: answers.asks,
880
+ grants: answers.grants,
881
+ answerText: seed.answerText,
882
+ recalledMemoriesReport: seed.recalledMemoriesReport,
883
+ };
884
+ }
885
+
886
+ /**
887
+ * Phase 2c, third half: the undos still owed to earlier turns, done under
888
+ * the lock before anything else touches the tree (`owed-undos.ts`), on every
889
+ * turn: a message turn, a reinvocation, a reconcile turn.
890
+ */
891
+ export async function reconcileOwedUndosPhase(
892
+ deps: ResolutionDeps,
893
+ args: { readonly sessionId: string; readonly workspace: TurnWorkspace; readonly reconcileTurn: boolean },
894
+ ): Promise<readonly UndoOutcome[]> {
895
+ deps.enterPhase("reconcile_owed_undos");
896
+ const outcomes = await reconcileOwedUndos({
897
+ client: deps.client,
898
+ runId: deps.input.executionId,
899
+ sessionId: args.sessionId,
900
+ workspace: args.workspace,
901
+ artifactStorage: deps.artifactStorage,
902
+ reconcileTurn: args.reconcileTurn,
903
+ recordReconciled: deps.recordReconciled,
904
+ });
905
+ deps.timing.mark("reconcile_owed_undos");
906
+ return outcomes;
907
+ }
908
+
909
+ /** A reconcile turn's settlement from what its start put back: COMPLETED, its rows naming what was undone or what failed. */
910
+ export function reconcileTurnSettlement(
911
+ outcomes: readonly UndoOutcome[],
912
+ ): Extract<TurnSettlement, { kind: "file-review-resolved" }> {
913
+ const failures = outcomes.filter((outcome) => outcome.failure !== "");
914
+ return {
915
+ kind: "file-review-resolved",
916
+ failed: failures.length > 0,
917
+ failureDetail: failures.map((outcome) => outcome.failureDetail).join("; "),
918
+ discardedPaths: outcomes.flatMap((outcome) => outcome.undonePaths),
919
+ };
920
+ }
921
+
922
+ /** The transcript row a turn without the platform's own MCP servers carries (#2062). */
923
+ export const PLATFORM_TOOLS_OFF_NOTICE =
924
+ "The platform's own tools (memory, channel messaging and the conversation tools) are off for this turn: no credential scoped to this run could be had.";
925
+
926
+ /**
927
+ * Phases 4 to 4b: the tool surface.
928
+ *
929
+ * The MCP-bound env map (and ONLY it, never the agent process env) carries
930
+ * the reserved caller-identity keys, so a server that declares them in
931
+ * spec.env can template the platform-verified caller into its headers;
932
+ * filterEnvToDeclaredKeys keeps every other server blind. Every server is a
933
+ * plugin's (the turn's plugins, shared/mcp-resolver.ts), named as Claude
934
+ * Code names it. Resolution fills a missing STIGMER_SERVER_ADDRESS per
935
+ * server from `config`'s endpoints (shared/platform-server-address.ts). The
936
+ * resolved list then gains three synthesized attachments, deliberately
937
+ * AFTER resolve: an attachment is the platform's own server, never listed,
938
+ * and its tools never ask:
939
+ *
940
+ * - channel messaging: the discovery read IS the attachment
941
+ * decision, and every failure mode degrades to honest absence;
942
+ * - conversation participation: the
943
+ * channel-id session label IS the decision, a free local read;
944
+ * - memory capture: the recall snapshot's enabled bit IS the
945
+ * decision, server-stamped at execution create.
946
+ *
947
+ * Their credential story: the exchanged scoped runner token authenticates
948
+ * the discovery reads per call and goes into the attachments. The runner's
949
+ * own key never does (#2062): without a scoped token, a credential already
950
+ * scoped below the runner (a cloud sandbox's session token) is used, a
951
+ * runner holding none runs them without one, and otherwise the turn runs
952
+ * without the platform's own servers and says so (\`PLATFORM_TOOLS_OFF_NOTICE\`).
953
+ * The exchange is opportunistic, so a failed one never kills the run,
954
+ * unlike the env read, where secrets are load-bearing.
955
+ *
956
+ * The approval default's MCP half is built last (which tools their servers
957
+ * mark destructive, read live), with two bypasses shared with the native
958
+ * harness (`shared/approval-policy.ts` `ActiveLeases`): the pre-armed
959
+ * spec.auto_approve_all is the one whole-run global bypass; an interactive
960
+ * APPROVE_ALL grants a run-lifetime lease scoped to that action's class,
961
+ * read from the run's `stigmer.permission.grant` events (`grants`, the
962
+ * reinvocation phase's read; none on a fresh turn). An
963
+ * engine that loads the tools itself reads their marks from what it loaded
964
+ * (`capabilities.readsToolMarks`), so the default carries only the leases
965
+ * here and the engine completes it; for any other engine each plugin server
966
+ * is listed now, in parallel (shared/mcp-tool-listing.ts), and a server
967
+ * whose listing fails asks before every one of its tools. The
968
+ * agent's tool scope is resolved here too, from its two lists, so both
969
+ * harnesses enforce one reading of them. The harness projects its SDK config
970
+ * from `servers` after this returns, exactly once, so every mutation is
971
+ * visible by construction.
972
+ */
973
+ export async function resolveMcpServersAndPolicies(
974
+ deps: ResolutionDeps,
975
+ args: {
976
+ readonly execution: Run;
977
+ readonly session: Session;
978
+ readonly sessionId: string;
979
+ readonly blueprint: ResolvedBlueprint;
980
+ readonly values: RunValues;
981
+ readonly readsToolMarks: boolean;
982
+ /** The run's grants, from the reinvocation phase: the interactive leases. */
983
+ readonly grants: ReadonlyMap<string, LeaseGrant>;
984
+ },
985
+ ): Promise<TurnMcp> {
986
+ const { client, config } = deps;
987
+ const { executionId } = deps.input;
988
+ const { execution, session, sessionId, blueprint, values } = args;
989
+
990
+ deps.enterPhase("resolve_mcp_servers");
991
+ await deps.reportProgress("Resolving MCP servers");
992
+ const transportPosture = resolveMcpTransportPosture(config.mode);
993
+ const platformValues = turnPlatformValues(blueprint, session, sessionId);
994
+ let servers = resolveTurnServers({
995
+ agent: blueprint.agent === undefined
996
+ ? undefined
997
+ : { agentId: blueprint.agent.id, subagent: null, servers: blueprint.agent.spec.mcpServers },
998
+ plugins: blueprint.plugins,
999
+ tools: values.tools,
1000
+ platformValues,
1001
+ transportPosture,
1002
+ platformEndpoints: config,
1003
+ }).resolvedServers;
1004
+ deps.timing.mark("resolve_mcp_servers");
1005
+
1006
+ // The turn's tool scope (the agent's lists, then this turn's over them,
1007
+ // which can only narrow), and the servers it leaves standing, before
1008
+ // anything connects, the tool listing included: a server the lists
1009
+ // exclude whole is never started or dialled, since no tool of it could be
1010
+ // called (#2106). A eval-run try's mocked servers are left out too:
1011
+ // their stand-ins take their names (`startEvalMocks`), and the real ones
1012
+ // must never start. The platform's own servers, added below, are always
1013
+ // kept.
1014
+ const toolScope = mainToolScope(blueprint, execution.spec);
1015
+ const standIns = new Set((execution.spec?.evalCase?.mocks ?? []).map((mock) => mock.segment));
1016
+ const resolved = servers;
1017
+ servers = callableServers(resolved, toolScope, new Set()).filter((server) => !standIns.has(server.slug));
1018
+ if (servers.length < resolved.length) {
1019
+ const left = resolved.filter((server) => !servers.includes(server)).map((server) => server.slug);
1020
+ console.log(`[turn-context] execution=${executionId}: not connecting ${left.join(", ")}: excluded whole by the turn's tool lists, or answered by a stand-in`);
1021
+ }
1022
+
1023
+ // Phase 4a: the plugin servers' tools, listed now for an engine that does
1024
+ // not load them itself.
1025
+ let listing: McpToolListing | undefined;
1026
+ if (!args.readsToolMarks && servers.length > 0) {
1027
+ await deps.reportProgress("Listing MCP tools");
1028
+ listing = await listTurnTools(servers);
1029
+ deps.timing.mark("list_mcp_tools");
1030
+ }
1031
+
1032
+ let exchangedRunnerToken: string | undefined;
1033
+ try {
1034
+ exchangedRunnerToken =
1035
+ await client.acquireScopedRunnerToken({ agentExecutionId: executionId });
1036
+ } catch (err) {
1037
+ console.warn(
1038
+ "[turn-context] Scoped-token exchange failed for attachment/discovery " +
1039
+ `reads; the platform's own MCP servers use a credential scoped below the runner, or are off for this turn: ${err instanceof Error ? err.message : err}`,
1040
+ );
1041
+ }
1042
+ // The platform's own servers run on the agent's side of the turn, so they
1043
+ // never carry the runner's own key (#2062): a credential scoped to this
1044
+ // run when there is one; else an ambient credential already scoped below
1045
+ // the runner, a cloud sandbox's session token, until the cloud mints run
1046
+ // credentials (#2080); a runner holding no credential (a trusted-local
1047
+ // server) gives them none, as before; and a runner whose own key could
1048
+ // not be exchanged runs the turn without them, and says so.
1049
+ const attachmentCredential =
1050
+ exchangedRunnerToken ??
1051
+ scopedRunnerCredential(config.stigmerRunnerTokenRef?.current ?? config.stigmerTokenRef.current) ??
1052
+ (config.stigmerTokenRef.current ? undefined : null);
1053
+ if (attachmentCredential === undefined) {
1054
+ console.warn(`[turn-context] execution=${executionId}: no credential scoped to this run; the platform's own MCP servers are off for this turn`);
1055
+ deps.transcript.apply({ kind: "system_note", text: PLATFORM_TOOLS_OFF_NOTICE });
1056
+ }
1057
+ const attachmentEndpoints = {
1058
+ bridgeEndpoint: config.mcpBridgeEndpoint,
1059
+ credential: attachmentCredential ?? null,
1060
+ backendEndpoint: config.stigmerBackendEndpoint,
1061
+ };
1062
+ const attachmentsOn = attachmentCredential !== undefined;
1063
+
1064
+ // Phase 4a2: the channel messaging attachment.
1065
+ const channelMessaging = await discoverChannelMessaging(client, exchangedRunnerToken);
1066
+ if (attachmentsOn && channelMessaging.length > 0) {
1067
+ const attachment = synthesizeChannelAttachment(channelMessaging, attachmentEndpoints);
1068
+ if (attachment) {
1069
+ servers = injectSynthesizedAttachment(servers, attachment, "channel messaging");
1070
+ }
1071
+ }
1072
+
1073
+ // Phase 4a4: the conversation participation attachment. HTTP-only:
1074
+ // synthesize answers undefined with no bridge endpoint by design.
1075
+ const conversationAttachment = attachmentsOn
1076
+ ? synthesizeConversationAttachment(readChannelConversationId(session.metadata?.labels), attachmentEndpoints)
1077
+ : undefined;
1078
+ if (conversationAttachment) {
1079
+ servers = injectSynthesizedAttachment(servers, conversationAttachment, "conversation participation");
1080
+ }
1081
+
1082
+ // Phase 4a5: the memory capture attachment. The capture context is
1083
+ // attribution the server verifies or trusts per edition; the subject is
1084
+ // never threaded, it derives from the credential.
1085
+ const memoryAttachment = attachmentsOn && synthesizeMemoryAttachment(
1086
+ execution.status?.recalledMemories,
1087
+ {
1088
+ org: session.metadata?.org ?? "",
1089
+ // Provenance, not scope: empty for the built-in assistant, and the
1090
+ // carrier omits an empty field (memory-attachment.ts).
1091
+ agentId: blueprint.agent?.id ?? "",
1092
+ sessionId,
1093
+ agentExecutionId: executionId,
1094
+ },
1095
+ attachmentEndpoints,
1096
+ );
1097
+ if (memoryAttachment) {
1098
+ servers = injectSynthesizedAttachment(servers, memoryAttachment, "memory capture");
1099
+ }
1100
+
1101
+ // Phase 4b: the approval default's MCP half, over the servers the turn
1102
+ // connects.
1103
+ const leases = deriveActiveLeases(args.grants.values(), execution.spec?.autoApproveAll ?? false);
1104
+ const mcpDefault = buildMcpApprovalDefault(listing ?? NOTHING_LISTED, leases);
1105
+
1106
+
1107
+ // The platform's own servers, read from the homes the attachments carry
1108
+ // once every one is injected: one truth for hiding them from hooks,
1109
+ // keeping them outside the tool lists and marking their tools.
1110
+ const platformServerSlugs = platformServerSlugsOf(servers);
1111
+
1112
+ return { servers, channelMessaging, leases, mcpDefault, listing, platformServerSlugs, toolScope };
1113
+ }
1114
+
1115
+ /** The caller-identity keys every plugin server of the turn may template (the main agent's and each subagent's). */
1116
+ function turnPlatformValues(blueprint: ResolvedBlueprint, session: Session, sessionId: string): ReturnType<typeof callerIdentityValues> {
1117
+ return callerIdentityValues(
1118
+ resolveCallerIdentity(blueprint.sessionSpec.metadata, session.status?.audit?.specAudit?.createdBy),
1119
+ sessionId,
1120
+ );
1121
+ }
1122
+
1123
+ /**
1124
+ * The servers a turn connects: every one whose tools the scope can reach at
1125
+ * all (`ToolScope.allowsMcpFamily`), and the platform's own. A server
1126
+ * excluded tool by tool still connects, since its other tools may remain.
1127
+ */
1128
+ export function callableServers(
1129
+ servers: readonly ResolvedMcpServer[],
1130
+ toolScope: ToolScope,
1131
+ platformServerSlugs: ReadonlySet<string>,
1132
+ ): readonly ResolvedMcpServer[] {
1133
+ return servers.filter((server) => platformServerSlugs.has(server.slug) || toolScope.allowsMcpFamily(server.slug));
1134
+ }
1135
+
1136
+ /**
1137
+ * The main agent's tool scope for one turn: the agent's two lists, then the
1138
+ * turn's own (`RunSpec.tools`, `RunSpec.disallowed_tools`) as one more layer,
1139
+ * so a turn narrows its agent's tools (or the built-in assistant's, which has
1140
+ * no lists) and never widens them (`shared/tool-lists.ts`). Unrestricted
1141
+ * when neither carries a list.
1142
+ */
1143
+ export function mainToolScope(blueprint: ResolvedBlueprint, spec: RunSpec | undefined): ToolScope {
1144
+ const agentSpec = blueprint.agent?.spec;
1145
+ return ToolScope.ofMain([
1146
+ ...(agentSpec ? [{ owner: "The agent", lists: { tools: agentSpec.tools, disallowedTools: agentSpec.disallowedTools } }] : []),
1147
+ { owner: "The turn", lists: { tools: spec?.tools ?? [], disallowedTools: spec?.disallowedTools ?? [] } },
1148
+ ]);
1149
+ }
1150
+
1151
+ /**
1152
+ * Phase 5 (between the tool surface and the attachments): mount the skills
1153
+ * under the session's platform dir, reachable from the workspace through its
1154
+ * `.stigmer` link, and return what a prompt renders, per owner
1155
+ * (`shared/skill-resolver.ts`).
1156
+ * Reads the control plane, which is why it is the runtime's and not a
1157
+ * harness's; each harness places the returned metadata in its own prompt
1158
+ * shapes — the root's in its system prompt, a sub-agent's in that
1159
+ * sub-agent's, client-free.
1160
+ *
1161
+ * Each plugin of the turn is mounted once (shared/plugin-mount.ts, its
1162
+ * verified archive), and its skills are rendered from the mounted tree as
1163
+ * `<plugin>:<skill>`, never copied: the root gets every plugin's skills,
1164
+ * and a plugin's agent (`<plugin>:<agent>`) the ones its `skills:` names. A
1165
+ * plugin that cannot be mounted contributes no skills, warned, as a failed
1166
+ * skill does.
1167
+ *
1168
+ * The root's refs are the blueprint's merged set (agent plus session). A
1169
+ * ref that fails resolves to nothing, warned and never thrown, as the
1170
+ * root's always did. A plugin subagent's skills are mapped only for a
1171
+ * harness whose `capabilities.subAgents` is true: the blueprint's plugin
1172
+ * subagents are that harness's to compile, so their skills are its to
1173
+ * render. A saved subagent's skills are its own context's
1174
+ * ({@link resolveSubagents}). One progress label for the whole phase, as
1175
+ * before.
1176
+ *
1177
+ * A scope that denies `Skill` hides skills (`ToolScope.hidesSkills`): the
1178
+ * root's when the main scope denies it, a plugin subagent's when its own
1179
+ * lists narrowed from the main scope do. A hidden owner's skills are
1180
+ * neither fetched nor mounted, so no prompt lists them; the harness's
1181
+ * confined read refuses the skill files an earlier turn mounted.
1182
+ *
1183
+ * The `.stigmer` link this and the attachment phase create is removed in
1184
+ * the runtime's finally, after the harness's own teardown. Until #1096 the
1185
+ * native orchestrator fetched and mounted sub-agent skills itself
1186
+ * (`subagent-transformer.ts` with a client); this phase is where that read
1187
+ * lives now.
1188
+ *
1189
+ * Beside the skills it returns `loaded`: the root's mounted skills by id at
1190
+ * their version hash, for the run's record of what it loaded
1191
+ * (`loaded-versions.ts`). A plugin's skills are not listed; the plugin's
1192
+ * digest names them.
1193
+ */
1194
+ export async function mountSkills(
1195
+ deps: ResolutionDeps,
1196
+ args: {
1197
+ readonly blueprint: ResolvedBlueprint;
1198
+ readonly sessionId: string;
1199
+ readonly primaryDir: string;
1200
+ readonly subAgents: boolean;
1201
+ /** The main scope ({@link mainToolScope}), which decides whether skills are hidden. */
1202
+ readonly toolScope: ToolScope;
1203
+ },
1204
+ ): Promise<{ readonly skills: TurnSkills; readonly loaded: readonly ApiResourceReference[] }> {
1205
+ deps.enterPhase("resolve_skills");
1206
+ await deps.reportProgress("Resolving skills");
1207
+ const options = { sessionId: args.sessionId, primaryWorkspaceDir: args.primaryDir };
1208
+ const { toolScope } = args;
1209
+ if (toolScope.hidesSkills) {
1210
+ console.log(`[resolveSkills] execution=${deps.input.executionId}: the tool lists deny Skill; no skills this turn`);
1211
+ }
1212
+ const resolved = toolScope.hidesSkills ? [] : await resolveSkills(deps.client, args.blueprint.mergedSkillRefs, options);
1213
+ const root = resolved.map((skill) => skill.metadata);
1214
+ const bySubAgent = new Map<string, readonly SkillMetadata[]>();
1215
+ for (const plugin of args.blueprint.plugins) {
1216
+ // The same rule for a plugin's skills: the root lists them unless the
1217
+ // main scope hides skills, and a plugin agent its own unless its lists,
1218
+ // narrowed from the main scope, do.
1219
+ const pluginName = plugin.metadata?.name ?? "";
1220
+ const agents = args.subAgents
1221
+ ? (plugin.status?.agents ?? []).filter(
1222
+ (agent) =>
1223
+ agent.skills.length > 0 &&
1224
+ !pluginSubagentScope(toolScope, { name: pluginAgentName(pluginName, agent.name), tools: agent.tools, disallowedTools: agent.disallowedTools }).hidesSkills,
1225
+ )
1226
+ : [];
1227
+ if (toolScope.hidesSkills && agents.length === 0) continue;
1228
+ const skills = await mountPluginSkills(deps, plugin, args.sessionId, args.primaryDir);
1229
+ if (!toolScope.hidesSkills) root.push(...skills.values());
1230
+ for (const agent of agents) {
1231
+ const own = agent.skills.flatMap((name) => skills.get(name) ?? []);
1232
+ if (own.length > 0) bySubAgent.set(pluginAgentName(pluginName, agent.name), own);
1233
+ }
1234
+ }
1235
+ deps.timing.mark("resolve_skills");
1236
+ return { skills: { root, bySubAgent }, loaded: resolved.map((skill) => skill.loaded) };
1237
+ }
1238
+
1239
+ /**
1240
+ * A plugin's skills by their name in the plugin, as a prompt renders them:
1241
+ * `<plugin>:<skill>`, with the path of the skill's SKILL.md inside the
1242
+ * plugin's mounted tree, reached from the workspace through `.stigmer`. A
1243
+ * plugin that cannot be mounted contributes none, warned.
1244
+ */
1245
+ async function mountPluginSkills(
1246
+ deps: ResolutionDeps,
1247
+ plugin: Plugin,
1248
+ sessionId: string,
1249
+ primaryDir: string,
1250
+ ): Promise<ReadonlyMap<string, SkillMetadata>> {
1251
+ const skills = plugin.status?.skills ?? [];
1252
+ if (skills.length === 0) return new Map();
1253
+ const pluginName = plugin.metadata?.name ?? "";
1254
+ try {
1255
+ const platformDir = getPlatformDir(sessionId);
1256
+ await ensureStigmerSymlink(primaryDir, platformDir);
1257
+ await mountPlugin(deps.client, plugin, platformDir);
1258
+ } catch (err) {
1259
+ console.warn(
1260
+ `[turn-context] the skills of plugin '${pluginName}' are missing this turn: its archive could not be mounted: ${errorText(err)}`,
1261
+ );
1262
+ return new Map();
1263
+ }
1264
+ const digest = plugin.status?.digest ?? "";
1265
+ return new Map(
1266
+ skills.map((skill): [string, SkillMetadata] => [
1267
+ skill.name,
1268
+ {
1269
+ name: `${pluginName}:${skill.name}`,
1270
+ description: skill.description || `Skill: ${skill.name}`,
1271
+ path: join(STIGMER_LOCAL_STATE_DIR, PLUGINS_SUBDIR, digest, skill.path, "SKILL.md"),
1272
+ },
1273
+ ]),
1274
+ );
1275
+ }
1276
+
1277
+ /** No hooks: the record of a turn whose plugins carry none and whose agent writes none. */
1278
+ const NO_HOOKS: TurnHooks = { sources: [], serverNames: new Map() };
1279
+
1280
+ /** The plugins among `plugins` that carry hooks. */
1281
+ function pluginsWithHooks(plugins: readonly Plugin[]): Plugin[] {
1282
+ return plugins.filter((plugin) => (plugin.status?.hooks?.groups.length ?? 0) > 0);
1283
+ }
1284
+
1285
+ /**
1286
+ * Phase 2b: refuse a turn whose agent or any of its subagents has hooks
1287
+ * when the harness does not run them, right after the blueprint and before
1288
+ * anything else is fetched or provisioned. Run without them, the hooks would be policies that
1289
+ * silently vanished; the refusal names them and says what to do. Both built
1290
+ * harnesses run hooks, so this refuses nothing today; it stays for the
1291
+ * next harness that does not.
1292
+ */
1293
+ export function refuseUnrunnableHooks(
1294
+ blueprint: ResolvedBlueprint,
1295
+ capabilities: Pick<HarnessCapabilities, "runsHooks">,
1296
+ ): Extract<TurnSettlement, { kind: "hooks-refused" }> | undefined {
1297
+ const described = [
1298
+ ...pluginsWithHooks(blueprint.plugins).map((plugin) => `the plugin '${plugin.metadata?.name ?? ""}'`),
1299
+ ...(blueprint.agent?.spec?.hooks ?? []).map(() => "the agent's own hooks block"),
1300
+ ...blueprint.subagents.flatMap((subagent) => [
1301
+ ...pluginsWithHooks(subagent.plugins).map((plugin) => `the plugin '${plugin.metadata?.name ?? ""}' of the subagent '${subagent.name}'`),
1302
+ ...subagent.spec.hooks.map(() => `the subagent '${subagent.name}''s own hooks block`),
1303
+ ]),
1304
+ ];
1305
+ if (described.length === 0 || capabilities.runsHooks) return undefined;
1306
+ return {
1307
+ kind: "hooks-refused",
1308
+ message:
1309
+ `This conversation has hooks (${described.join(", ")}), and this engine does not run hooks yet. ` +
1310
+ "Run it on Stigmer's native engine, or remove the hooks.",
1311
+ };
1312
+ }
1313
+
1314
+ /**
1315
+ * Phase 5a: resolve the turn's hooks for a harness that runs them.
1316
+ *
1317
+ * The sources, in order: each of the turn's plugins that records hooks (its
1318
+ * agent's plugins, then the conversation's, as the blueprint merged them),
1319
+ * mounted from its verified archive (`shared/plugin-mount.ts`), then the
1320
+ * agent's own block, taken as written. A chat with the built-in assistant
1321
+ * gets its plugins' hooks too. Each source keeps the format it is written
1322
+ * in, Claude Code's or Cursor's; both run on every engine that runs hooks.
1323
+ * Every server is named to a hook as Claude Code names it: a plugin's as
1324
+ * `plugin:<plugin>:<server>`, so a plugin's matchers find its tools, and
1325
+ * one the agent writes itself by its own name, with `source: "agent"`.
1326
+ *
1327
+ * A plugin whose archive cannot be fetched or verified refuses the turn
1328
+ * (`hooks-refused`), naming it: a hook that does not run as written is a
1329
+ * policy that vanished, so this is deliberately stricter than a skill, whose
1330
+ * failed download degrades.
1331
+ */
1332
+ export async function resolveHooks(
1333
+ deps: ResolutionDeps,
1334
+ args: {
1335
+ readonly blueprint: ResolvedBlueprint;
1336
+ readonly sessionId: string;
1337
+ readonly servers: readonly ResolvedMcpServer[];
1338
+ },
1339
+ ): Promise<{ readonly kind: "ready"; readonly hooks: TurnHooks } | { readonly kind: "settled"; readonly settlement: TurnSettlement }> {
1340
+ const plugins = pluginsWithHooks(args.blueprint.plugins);
1341
+ const inline = args.blueprint.agent?.spec?.hooks ?? [];
1342
+ if (plugins.length === 0 && inline.length === 0) return { kind: "ready", hooks: NO_HOOKS };
1343
+ deps.enterPhase("resolve_hooks");
1344
+ await deps.reportProgress("Resolving hooks");
1345
+
1346
+ const resolved = await hookSources(deps, plugins, inline, args.sessionId);
1347
+ if (resolved.kind === "settled") return resolved;
1348
+
1349
+ deps.timing.mark("resolve_hooks");
1350
+ return { kind: "ready", hooks: { sources: resolved.sources, serverNames: hookServerNamesOf(args.servers) } };
1351
+ }
1352
+
1353
+ /**
1354
+ * The hook sources of one agent: each plugin that records hooks, mounted
1355
+ * from its verified archive, then its own inline block, taken as written.
1356
+ * A plugin that cannot be mounted for a reason its owner fixes settles the
1357
+ * turn naming it (`hooks-refused`); a transient fault is thrown.
1358
+ */
1359
+ async function hookSources(
1360
+ deps: ResolutionDeps,
1361
+ plugins: readonly Plugin[],
1362
+ inline: readonly HookSource[],
1363
+ sessionId: string,
1364
+ ): Promise<
1365
+ | { readonly kind: "ready"; readonly sources: TurnHookSource[] }
1366
+ | { readonly kind: "settled"; readonly settlement: TurnSettlement }
1367
+ > {
1368
+ const platformDir = getPlatformDir(sessionId);
1369
+ const sources: TurnHookSource[] = [];
1370
+ for (const plugin of plugins) {
1371
+ const hooks = plugin.status!.hooks!;
1372
+ try {
1373
+ sources.push({ plugin: await mountPlugin(deps.client, plugin, platformDir), format: formatOf(hooks.format), groups: hooks.groups });
1374
+ } catch (err) {
1375
+ if (!ownersToFix(err)) throw err;
1376
+ return {
1377
+ kind: "settled",
1378
+ settlement: { kind: "hooks-refused", message: `The hooks of plugin '${plugin.metadata?.name ?? ""}' could not be prepared: ${errorText(err)}` },
1379
+ };
1380
+ }
1381
+ }
1382
+ for (const source of inline) {
1383
+ if (source.source.case !== "inline") continue;
1384
+ sources.push({ plugin: null, format: formatOf(source.source.value.format), groups: source.source.value.groups });
1385
+ }
1386
+ return { kind: "ready", sources };
1387
+ }
1388
+
1389
+ /** Refuses a subagent's server that takes the name of a server already named, from another home. */
1390
+ function refuseSharedServerNames(
1391
+ mainServers: readonly ResolvedMcpServer[],
1392
+ servers: readonly ResolvedMcpServer[],
1393
+ ): void {
1394
+ for (const server of servers) {
1395
+ const main = mainServers.find((candidate) => candidate.slug === server.slug);
1396
+ if (main !== undefined && !sameServerHome(main.home, server.home)) {
1397
+ throw new DuplicateServerNameError(
1398
+ server.slug,
1399
+ describeServerHome(main.home, main.slug),
1400
+ describeServerHome(server.home, server.slug),
1401
+ );
1402
+ }
1403
+ }
1404
+ }
1405
+
1406
+ /**
1407
+ * Phase 5c: each saved agent the turn's agent lists, as an agent of its
1408
+ * own ({@link TurnSubagent}), for a harness whose `capabilities.subAgents`
1409
+ * is true. The phases the main agent's context came from, run again over
1410
+ * the subagent's own definition, with shared caches: a plugin mounts once
1411
+ * by digest (`shared/plugin-mount.ts`), a skill once by version hash, and
1412
+ * a server the main agent also has resolves to the same slug, which the
1413
+ * engine connects once.
1414
+ *
1415
+ * - Its servers: the ones it writes itself, then its plugins'
1416
+ * (`shared/mcp-resolver.ts`), with the run's tool values and the caller
1417
+ * identity the main agent's get. None of the
1418
+ * platform's own servers: a subagent reports to the main agent, which
1419
+ * alone speaks to the person or the channel.
1420
+ * - Its skills: its own refs and its plugins', unless its scope hides them.
1421
+ * - Its hooks: its plugins', then its own block; the engine runs the
1422
+ * conversation's hooks first on its calls.
1423
+ * - Its model ({@link subagentModel}) and its values, by its name.
1424
+ *
1425
+ * A plugin of a subagent whose hooks cannot be prepared settles the turn
1426
+ * naming it, as the main agent's do. A subagent's server that would take
1427
+ * the name of a server the main agent or an earlier subagent has, from
1428
+ * another plugin or agent, refuses the turn
1429
+ * (`DuplicateServerNameError`): the engine connects one server per name,
1430
+ * so one would run with the other's values. Run planning refuses two
1431
+ * plugins of one name first; this is the backstop for a plugin that
1432
+ * appeared or changed since.
1433
+ *
1434
+ * Ready, it also returns `loadedSkills`: every subagent's own mounted
1435
+ * skills by id at their version hash, in subagent order, for the run's
1436
+ * record of what it loaded (`loaded-versions.ts`).
1437
+ */
1438
+ export async function resolveSubagents(
1439
+ deps: ResolutionDeps,
1440
+ args: {
1441
+ readonly execution: Run;
1442
+ readonly session: Session;
1443
+ readonly sessionId: string;
1444
+ readonly blueprint: ResolvedBlueprint;
1445
+ readonly values: RunValues;
1446
+ readonly primaryDir: string;
1447
+ readonly capabilities: Pick<HarnessCapabilities, "harness" | "subAgents">;
1448
+ /** The main agent's resolved servers: a subagent's server of the same name must be the same plugin's. */
1449
+ readonly mainServers: readonly ResolvedMcpServer[];
1450
+ },
1451
+ ): Promise<
1452
+ | { readonly kind: "ready"; readonly subagents: readonly TurnSubagent[]; readonly loadedSkills: readonly ApiResourceReference[] }
1453
+ | { readonly kind: "settled"; readonly settlement: TurnSettlement }
1454
+ > {
1455
+ const { blueprint, values, sessionId } = args;
1456
+ if (blueprint.subagents.length === 0 || !args.capabilities.subAgents) return { kind: "ready", subagents: [], loadedSkills: [] };
1457
+ deps.enterPhase("resolve_subagents");
1458
+ await deps.reportProgress("Resolving subagents");
1459
+ const transportPosture = resolveMcpTransportPosture(deps.config.mode);
1460
+ const platformValues = turnPlatformValues(blueprint, args.session, sessionId);
1461
+ const options = { sessionId, primaryWorkspaceDir: args.primaryDir };
1462
+ const subagents: TurnSubagent[] = [];
1463
+ const loadedSkills: ApiResourceReference[] = [];
1464
+ // Every server named so far: the main agent's, then each subagent's.
1465
+ const named: ResolvedMcpServer[] = [...args.mainServers];
1466
+ for (const subagent of blueprint.subagents) {
1467
+ const { spec } = subagent;
1468
+ const toolScope = savedSubagentScope(subagent.name, spec, args.execution.spec);
1469
+ const servers = resolveTurnServers({
1470
+ agent: { agentId: subagent.agentId, subagent: subagent.name, servers: spec.mcpServers },
1471
+ plugins: subagent.plugins,
1472
+ tools: values.tools,
1473
+ platformValues,
1474
+ transportPosture,
1475
+ platformEndpoints: deps.config,
1476
+ }).resolvedServers;
1477
+ refuseSharedServerNames(named, servers);
1478
+ named.push(...servers);
1479
+ const skills: SkillMetadata[] = [];
1480
+ if (!toolScope.hidesSkills) {
1481
+ const own = await resolveSkills(deps.client, spec.skillRefs, options);
1482
+ skills.push(...own.map((skill) => skill.metadata));
1483
+ loadedSkills.push(...own.map((skill) => skill.loaded));
1484
+ for (const plugin of subagent.plugins) {
1485
+ skills.push(...(await mountPluginSkills(deps, plugin, sessionId, args.primaryDir)).values());
1486
+ }
1487
+ }
1488
+ const hooks = await hookSources(deps, pluginsWithHooks(subagent.plugins), spec.hooks, sessionId);
1489
+ if (hooks.kind === "settled") return hooks;
1490
+ subagents.push({
1491
+ name: subagent.name,
1492
+ description: spec.description,
1493
+ instructions: spec.instructions,
1494
+ model: await subagentModel(spec.runConfig?.modelName ?? "", args.capabilities.harness, spec.harness),
1495
+ toolScope,
1496
+ servers,
1497
+ skills,
1498
+ hooks: hooks.sources,
1499
+ values: values.subagents.get(subagent.name) ?? {},
1500
+ bringsOwn: {
1501
+ plugins: spec.plugins.length > 0,
1502
+ hooks: spec.hooks.length > 0,
1503
+ lists: spec.tools.length > 0 || spec.disallowedTools.length > 0,
1504
+ mcpServers: spec.mcpServers.length > 0,
1505
+ },
1506
+ });
1507
+ }
1508
+ deps.timing.mark("resolve_subagents");
1509
+ return { kind: "ready", subagents, loadedSkills };
1510
+ }
1511
+
1512
+ /** A recorded hook format as the evaluator names it; an unset format is Claude Code's, as apply fills it. */
1513
+ function formatOf(format: HookFormat): HookFormatName {
1514
+ return format === HookFormat.CURSOR ? "cursor" : "claude-code";
1515
+ }
1516
+
1517
+ /**
1518
+ * Whether a failure reading or mounting a hook's plugin is the agent owner's
1519
+ * to fix (the plugin is gone, not theirs to read, or its archive does not
1520
+ * verify), and so refuses the turn with a sentence naming it. A transient
1521
+ * fault (the server unreachable, a download that failed in transit) is the
1522
+ * infrastructure's: it is thrown and settles as any other failure there.
1523
+ */
1524
+ function ownersToFix(err: unknown): boolean {
1525
+ if (err instanceof PluginMountError) return err.cause === undefined || isTerminalError(err.cause);
1526
+ return isTerminalError(err);
1527
+ }
1528
+
1529
+ function errorText(err: unknown): string {
1530
+ return err instanceof Error ? err.message : String(err);
1531
+ }
1532
+
1533
+ /**
1534
+ * Phase 5b: resolve the turn's attachments, fail-hard
1535
+ * (they are explicit user inputs; see `shared/attachment-resolver.ts`).
1536
+ * Downloads by storage key through the same artifact storage resolved for
1537
+ * status offload. The vision budget rides along so image attachments are
1538
+ * selected for inline delivery while their bytes are already in hand
1539
+ * (`shared/attachment-vision.ts` owns all policy); it carries the vision
1540
+ * capability of the model the turn will run on: the one the turn's resolved
1541
+ * settings name (`status.run_config`, which the control plane resolved once
1542
+ * at create), or the registry's default when they name none — the model the native
1543
+ * harness builds in that case, so the budget asks about the model that will
1544
+ * actually see the image. Full model validation is not needed for this. The
1545
+ * Cursor harness with no model named builds its own catalog default instead
1546
+ * (`resolveModelId("default")`), so for it this is an approximation: today
1547
+ * both answers read as sighted, and the exact per-harness default is not yet
1548
+ * declared. The vision profile is the harness's
1549
+ * (each engine accepts different image shapes), so it arrives as an
1550
+ * argument.
1551
+ */
1552
+ export async function resolveTurnAttachments(
1553
+ deps: ResolutionDeps,
1554
+ args: {
1555
+ readonly spec: RunSpec;
1556
+ /** The settings the turn runs with (`execution.status.run_config`); never the request's. */
1557
+ readonly runConfig: RunConfig | undefined;
1558
+ readonly sessionId: string;
1559
+ readonly primaryDir: string;
1560
+ readonly visionProfile: VisionProfile;
1561
+ },
1562
+ ): Promise<TurnAttachments> {
1563
+ deps.enterPhase("resolve_attachments");
1564
+ const modelName = args.runConfig?.modelName || (await getDefaultModel());
1565
+ const visionBudget = new VisionBudget(args.visionProfile, {
1566
+ modelVision: await getModelVisionCapability(modelName),
1567
+ });
1568
+ const results = await resolveAttachments(args.spec.attachments, {
1569
+ sessionId: args.sessionId,
1570
+ primaryWorkspaceDir: args.primaryDir,
1571
+ mode: deps.config.mode,
1572
+ storage: deps.artifactStorage,
1573
+ visionBudget,
1574
+ });
1575
+ // Vision facts, derived once from the single resolution result: the
1576
+ // images the model will see inline (in attachment order) and the ones
1577
+ // that degraded to path-only, disclosed in the prompt.
1578
+ const visionImages = results.flatMap((a) => (a.vision ? [a.vision] : []));
1579
+ const visionNotViewable: NotViewableEntry[] = results.flatMap((a) =>
1580
+ a.visionDegraded ? [{ path: a.relativePath, reason: a.visionDegraded }] : [],
1581
+ );
1582
+ if (visionImages.length > 0 || visionNotViewable.length > 0) {
1583
+ console.log(
1584
+ `[attachment-vision] execution=${deps.input.executionId} inline=${visionImages.length} ` +
1585
+ `(${visionImages.reduce((n, v) => n + v.byteSize, 0)} bytes) ` +
1586
+ `degraded=${JSON.stringify(visionNotViewable.map((d) => `${d.path}:${d.reason}`))}`,
1587
+ );
1588
+ }
1589
+ deps.timing.mark("resolve_attachments");
1590
+ return { results, visionImages, visionNotViewable };
1591
+ }
1592
+
1593
+ /**
1594
+ * Whether a harness performs an approved call by RE-RUNNING the model, so
1595
+ * the bytes an approved whole-file write lands can differ from the bytes the
1596
+ * user approved unless the runner pins them itself
1597
+ * ({@link applyApprovedWrites}). Keyed on the pause primitive
1598
+ * (`capabilities.ts`): `deny-and-retry` denies the call and re-prompts the
1599
+ * model with grants; `callback` answers "deny, stop" and the resumed session
1600
+ * re-attempts the call — both regenerate. An `interrupt` engine checkpoints
1601
+ * AT the call and applies its exact args on `approve`, so a runner-side
1602
+ * write would land the same bytes twice and pre-empt a row the engine is
1603
+ * about to execute; `none` gates nothing. Until #1096 the phase ran for
1604
+ * every harness — a deny-and-retry mechanism the native harness would have
1605
+ * met on its first deny-gated file approval.
1606
+ */
1607
+ export function regeneratesApprovedWrites(pausePrimitive: PausePrimitive): boolean {
1608
+ switch (pausePrimitive) {
1609
+ case "deny-and-retry":
1610
+ case "callback":
1611
+ return true;
1612
+ case "interrupt":
1613
+ case "none":
1614
+ return false;
1615
+ default: {
1616
+ const exhaustive: never = pausePrimitive;
1617
+ throw new Error(`regeneratesApprovedWrites: unknown pause primitive ${String(exhaustive)}`);
1618
+ }
1619
+ }
1620
+ }
1621
+
1622
+ /**
1623
+ * Phase 5b3: exact-apply approved whole-file writes
1624
+ * (HITL "what you approve is what gets applied"). A deny-only harness
1625
+ * reinvokes the model, which regenerates content, so a resource grant alone
1626
+ * cannot guarantee the bytes that land match the bytes the user approved.
1627
+ * The runner therefore writes the EXACT approved whole-file content itself
1628
+ * and marks those tool calls COMPLETED; the harness then issues NO grant for
1629
+ * them, so any FURTHER change the model makes to those files is re-gated.
1630
+ * Hunk edits / shell / MCP stay on the grant + reinvocation path, and every
1631
+ * uncertain case degrades to that path, so this can never corrupt a file
1632
+ * (see `shared/exact-apply.ts`).
1633
+ *
1634
+ * Scoped to the harnesses that regenerate ({@link regeneratesApprovedWrites})
1635
+ * and OUT of capture mode, where a file edit flows and is never asked for.
1636
+ *
1637
+ * The caller persists when the returned set is non-empty (the applied state
1638
+ * must be durable before the continuation runs, and the UI reflects it at
1639
+ * once); this phase, like every phase, never persists.
1640
+ */
1641
+ export async function applyApprovedWrites(
1642
+ deps: ResolutionDeps,
1643
+ args: {
1644
+ readonly pausePrimitive: PausePrimitive;
1645
+ readonly workspace: TurnWorkspace;
1646
+ readonly reinvocation: TurnReinvocation;
1647
+ },
1648
+ ): Promise<ReadonlySet<string>> {
1649
+ const { pausePrimitive, workspace, reinvocation } = args;
1650
+ if (
1651
+ !regeneratesApprovedWrites(pausePrimitive) ||
1652
+ workspace.captureMode ||
1653
+ !reinvocation.isReinvocation ||
1654
+ reinvocation.approvalDecisions.size === 0
1655
+ ) {
1656
+ return new Set();
1657
+ }
1658
+ deps.enterPhase("apply_approved_writes");
1659
+ return applyApprovedWholeFileWrites({
1660
+ messages: deps.rows.messages,
1661
+ workspaceBackend: new LocalWorkspaceBackend(workspace.primaryDir),
1662
+ workspaceDirs: workspace.dirs,
1663
+ executionId: deps.input.executionId,
1664
+ });
1665
+ }
1666
+
1667
+ /**
1668
+ * Phase 6, the harness-agnostic half: the model name the turn runs with, and
1669
+ * the effective service tier and thinking mode. All three come from
1670
+ * `execution.status.run_config`, the settings the control plane resolved
1671
+ * once at create from the message, the agent's defaults and the lane's
1672
+ * operator profile; the request's own `spec.run_config` is one input to that
1673
+ * resolution and is never read here, so a request can never bypass a cap or
1674
+ * a default the resolution applied. UNSPECIFIED → STANDARD (#357) and
1675
+ * UNSPECIFIED → DISABLED (#772) resolve here and nowhere else: the resolved
1676
+ * settings keep "no layer set it" as UNSPECIFIED. Validating the NAME against
1677
+ * a catalog is the harness's (Cursor's `resolveModelId`), so it is not here.
1678
+ */
1679
+ export function resolveModelPreferences(runConfig: RunConfig | undefined): TurnModelPreferences {
1680
+ return {
1681
+ requested: runConfig?.modelName || "default",
1682
+ serviceTier: resolveEffectiveServiceTier(runConfig?.serviceTier),
1683
+ thinkingMode: resolveEffectiveThinkingMode(runConfig?.thinkingMode),
1684
+ };
1685
+ }
1686
+
1687
+ /** Phase 9b: the structured-output schema this message asks for, if any (a per-message intent on the spec). */
1688
+ export function structuredOutputSchemaOf(spec: RunSpec): Record<string, unknown> | undefined {
1689
+ return spec.structuredOutputSchema;
1690
+ }
1691
+
1692
+ /**
1693
+ * Phase 9c:
1694
+ * the standing context, read once, and the memory selection prepared once.
1695
+ *
1696
+ * Selection runs against the frozen first message's semantics: above the
1697
+ * activation threshold it picks top-k for spec.message, otherwise (and on
1698
+ * any failure) it injects the full candidate set. The outcome report is
1699
+ * stamped on the turn's rows ONCE, written to the log by the next persist
1700
+ * as `stigmer.memory.recalled`; a re-invocation replays the report an
1701
+ * earlier invocation wrote there (`TurnReinvocation.recalledMemoriesReport`)
1702
+ * rather than re-selecting (the written-once rule). Memoized because a
1703
+ * resumed-agent primary send carries no memories, but a mid-send
1704
+ * poisoned-handle failure rebuilds on a FRESH agent whose recovery prompt
1705
+ * does, so every memory-carrying build site awaits this lazily.
1706
+ */
1707
+ export function resolveStandingContext(
1708
+ deps: ResolutionDeps,
1709
+ args: {
1710
+ readonly execution: Run;
1711
+ readonly spec: RunSpec;
1712
+ readonly blueprint: ResolvedBlueprint;
1713
+ readonly priorReport: RecalledMemoriesReport | undefined;
1714
+ },
1715
+ ): TurnStandingContext {
1716
+ const { execution, spec, blueprint, priorReport } = args;
1717
+ let memorySelection: Promise<RecalledMemoriesContent | undefined> | undefined;
1718
+ const selectRecalledMemories = (): Promise<RecalledMemoriesContent | undefined> => {
1719
+ memorySelection ??= selectRecalledFacts(execution.status?.recalledMemories, spec.message, {
1720
+ proxyEndpoint: deps.config.proxyEndpoint,
1721
+ stigmerToken: deps.config.stigmerTokenRef.current,
1722
+ executionId: deps.input.executionId,
1723
+ priorReport,
1724
+ }).then((selection) => {
1725
+ if (selection.report !== undefined) {
1726
+ deps.rows.recalledMemoriesReport = selection.report;
1727
+ }
1728
+ return selection.content;
1729
+ });
1730
+ return memorySelection;
1731
+ };
1732
+ return {
1733
+ contextBridge: readContextBridge(blueprint.sessionSpec.metadata),
1734
+ senderIdentity: readSenderIdentity(blueprint.sessionSpec.metadata),
1735
+ sessionContext: readSessionContext(blueprint.sessionSpec.metadata),
1736
+ declaredPreferences: readDeclaredPreferences(execution.status?.declaredPreferences),
1737
+ conversationCatchup: readConversationCatchup(spec.conversationCatchup),
1738
+ selectRecalledMemories,
1739
+ };
1740
+ }
1741
+
1742
+ // ---------------------------------------------------------------------------
1743
+ // The composer
1744
+ // ---------------------------------------------------------------------------
1745
+
1746
+ /**
1747
+ * The resources a turn holds that outlive the phase that produced them and
1748
+ * must be released or finalized by the caller's `finally` and terminal
1749
+ * writes — set on this frame the instant they exist, so no throw between
1750
+ * acquisition and hand-over can leave a held lock the caller never sees.
1751
+ * Not part of `TurnInput`: an adapter never releases the lock or finalizes
1752
+ * the write-back.
1753
+ */
1754
+ export interface TurnFrame {
1755
+ /** The primary tree once provisioned: the `.stigmer` link the skill and attachment phases create under it is removed at turn end. */
1756
+ primaryDir: string | undefined;
1757
+ /** Exclusive turn lock on the primary tree; released LAST, after the adapter's own teardown. */
1758
+ releaseWorkspaceLock: ReleaseWorkspaceLock | undefined;
1759
+ /** Finalizes at exactly two seams: a reconcile turn and terminal completion. `null` when nothing is eligible. */
1760
+ writeback: WriteBackCoordinator | null;
1761
+ /** A eval-run try's mock endpoint, bound when the engine's turn starts and closed when the turn ends. */
1762
+ evalMocks: MockEndpoint | undefined;
1763
+ /** The files a eval-run try's graders read, returned on the run as the turn leaves them (`read-files.ts`); set once its case is prepared. */
1764
+ evalReadFiles: readonly string[] | undefined;
1765
+ /**
1766
+ * The log holds what an earlier invocation of this run's engine did
1767
+ * (`TurnReinvocation.runWroteEvents`), set by the reinvocation phase: the
1768
+ * session event emitter's `resumed`.
1769
+ */
1770
+ runWroteEvents: boolean;
1771
+ /**
1772
+ * The run's answer as an earlier invocation wrote it
1773
+ * (`TurnReinvocation.answerText`), set by the reinvocation phase: what the
1774
+ * turn reports when this invocation writes no message.
1775
+ */
1776
+ priorAnswer: string | undefined;
1777
+ }
1778
+
1779
+ /** What the composer answers: the whole record, or a settlement the caller writes and returns. */
1780
+ export type TurnResolution =
1781
+ | { readonly kind: "ready"; readonly input: TurnInput }
1782
+ | { readonly kind: "settled"; readonly settlement: TurnSettlement };
1783
+
1784
+ /**
1785
+ * Run the phases in order and compose the turn's `TurnInput`, or stop at
1786
+ * the first settlement.
1787
+ *
1788
+ * A reconcile turn (`RunSpec.reconcile_file_review`, no message) takes
1789
+ * {@link resolveReconcileTurn} instead, right after the execution is read:
1790
+ * it never reaches a phase that prepares an engine.
1791
+ *
1792
+ * The order is the orchestrator's, with its harness-specific steps gone
1793
+ * (they run inside `adapter.runTurn`, after this returns): the tool surface,
1794
+ * the skills, the attachments, the exact-apply, then the reads that need no
1795
+ * network.
1796
+ *
1797
+ * The one persist a phase requires — the applied writes must be durable
1798
+ * before the continuation runs — goes through the caller's chokepoint
1799
+ * (`persist`), so the rule that phases never persist holds here too.
1800
+ */
1801
+ export async function resolveTurnContext(
1802
+ deps: ResolutionDeps,
1803
+ capabilities: HarnessCapabilities,
1804
+ frame: TurnFrame,
1805
+ persist: () => Promise<void>,
1806
+ ): Promise<TurnResolution> {
1807
+ const { execution, spec, sessionId } = await fetchExecution(deps);
1808
+ if (spec.reconcileFileReview) return resolveReconcileTurn(deps, frame, sessionId);
1809
+ const { session, blueprint } = await resolveAgentBlueprint(deps, execution, sessionId);
1810
+ deps.identifyRun({ execution, session, sessionId, blueprint });
1811
+ const unrunnable = refuseUnrunnableHooks(blueprint, capabilities);
1812
+ if (unrunnable !== undefined) return { kind: "settled", settlement: unrunnable };
1813
+ const fetched = await fetchValues(deps);
1814
+ if (fetched.kind === "settled") return { kind: "settled", settlement: fetched.settlement };
1815
+ let { values } = fetched;
1816
+ const provisioned = await provisionWorkspace(deps, {
1817
+ session,
1818
+ sessionId,
1819
+ repositories: values.repositories,
1820
+ review: fileReviewOn(session, spec),
1821
+ });
1822
+ let { workspace } = provisioned;
1823
+ const { writeback } = provisioned;
1824
+ frame.primaryDir = workspace.primaryDir;
1825
+ frame.writeback = writeback;
1826
+
1827
+ const lock = await acquireWorkspaceTurnLock(deps, workspace.primaryDir);
1828
+ if (lock.kind === "settled") return { kind: "settled", settlement: lock.settlement };
1829
+ frame.releaseWorkspaceLock = lock.release;
1830
+ const finished = await runFinishedWhileWaiting(deps, lock.waited);
1831
+ if (finished !== undefined) return { kind: "settled", settlement: finished };
1832
+ await reconcileOwedUndosPhase(deps, { sessionId, workspace, reconcileTurn: false });
1833
+
1834
+ const evalCase = await prepareEvalCasePhase(deps, { spec, sessionId, workspace, values });
1835
+ if (evalCase.kind === "settled") return { kind: "settled", settlement: evalCase.settlement };
1836
+ const prepared = evalCase.prepared;
1837
+ if (prepared !== undefined) {
1838
+ workspace = prepared.workspace;
1839
+ values = prepared.values;
1840
+ frame.evalReadFiles = spec.evalCase?.readFiles;
1841
+ }
1842
+
1843
+ const reinvocation = await reconcileReinvocation(deps, {
1844
+ stateIdSource: capabilities.stateIdSource,
1845
+ execution,
1846
+ sessionId,
1847
+ });
1848
+ frame.runWroteEvents = reinvocation.runWroteEvents;
1849
+ frame.priorAnswer = reinvocation.answerText;
1850
+
1851
+ const resolvedMcp = await resolveMcpServersAndPolicies(deps, {
1852
+ execution,
1853
+ session,
1854
+ sessionId,
1855
+ blueprint,
1856
+ values,
1857
+ readsToolMarks: capabilities.readsToolMarks,
1858
+ grants: reinvocation.grants,
1859
+ });
1860
+ const mcp =
1861
+ prepared === undefined ? resolvedMcp : await startEvalMocks(deps, { spec, archive: prepared.archive, mcp: resolvedMcp, frame });
1862
+ const mounted = await mountSkills(deps, {
1863
+ blueprint,
1864
+ sessionId,
1865
+ primaryDir: workspace.primaryDir,
1866
+ subAgents: capabilities.subAgents,
1867
+ toolScope: mcp.toolScope,
1868
+ });
1869
+ const hookResolution = await resolveHooks(deps, { blueprint, sessionId, servers: mcp.servers });
1870
+ if (hookResolution.kind === "settled") return hookResolution;
1871
+ const subagentResolution = await resolveSubagents(deps, {
1872
+ execution,
1873
+ session,
1874
+ sessionId,
1875
+ blueprint,
1876
+ values,
1877
+ primaryDir: workspace.primaryDir,
1878
+ capabilities,
1879
+ mainServers: mcp.servers,
1880
+ });
1881
+ if (subagentResolution.kind === "settled") return subagentResolution;
1882
+ const resolvedAttachments = await resolveTurnAttachments(deps, {
1883
+ spec,
1884
+ runConfig: execution.status?.runConfig,
1885
+ sessionId,
1886
+ primaryDir: workspace.primaryDir,
1887
+ visionProfile: capabilities.visionProfile,
1888
+ });
1889
+ const attachments: TurnAttachments =
1890
+ prepared === undefined || prepared.case.referenceInputs.length === 0
1891
+ ? resolvedAttachments
1892
+ : { ...resolvedAttachments, results: [...resolvedAttachments.results, ...prepared.case.referenceInputs] };
1893
+ const appliedToolCallIds = await applyApprovedWrites(deps, {
1894
+ pausePrimitive: capabilities.pausePrimitive,
1895
+ workspace,
1896
+ reinvocation,
1897
+ });
1898
+ if (appliedToolCallIds.size > 0) {
1899
+ // Persist the applied writes (tool calls now COMPLETED with the approved
1900
+ // diff) before reinvocation, so the applied state is durable even if the
1901
+ // continuation fails, and the UI reflects it immediately.
1902
+ await persist();
1903
+ }
1904
+
1905
+ // What this turn loaded, recorded once it is ready to run; the
1906
+ // adapter's first persist carries it.
1907
+ const loadedVersions = loadedVersionsOf(
1908
+ [...mounted.loaded, ...subagentResolution.loadedSkills],
1909
+ blueprint,
1910
+ capabilities.subAgents,
1911
+ );
1912
+ if (loadedVersions !== undefined) deps.status.loadedVersions = loadedVersions;
1913
+
1914
+ return {
1915
+ kind: "ready",
1916
+ input: {
1917
+ executionId: deps.input.executionId,
1918
+ threadId: deps.input.threadId,
1919
+ turnSeq: deps.input.turnSeq,
1920
+ sessionId,
1921
+ approvalDecisions: reinvocation.approvalDecisions,
1922
+ approvalDenyMessages: reinvocation.approvalDenyMessages,
1923
+ approvalAsks: reinvocation.approvalAsks,
1924
+ execution,
1925
+ session,
1926
+ blueprint,
1927
+ values,
1928
+ workspace,
1929
+ mcp,
1930
+ skills: mounted.skills,
1931
+ hooks: hookResolution.hooks,
1932
+ subagents: subagentResolution.subagents,
1933
+ attachments,
1934
+ appliedToolCallIds,
1935
+ model: resolveModelPreferences(execution.status?.runConfig),
1936
+ structuredOutputSchema: structuredOutputSchemaOf(spec),
1937
+ appendSystemPrompt: spec.appendSystemPrompt,
1938
+ standing: resolveStandingContext(deps, { execution, spec, blueprint, priorReport: reinvocation.recalledMemoriesReport }),
1939
+ artifactStorage: deps.artifactStorage,
1940
+ readRunEvents: runEventsReader(deps.client, sessionId, deps.input.executionId),
1941
+ ...(prepared?.case.history !== undefined && { resumedHistory: prepared.case.history }),
1942
+ },
1943
+ };
1944
+ }
1945
+
1946
+ /**
1947
+ * A reconcile turn's whole resolution: the run a person's Undo on an ended
1948
+ * turn starts, with no message and nothing for an engine to do. Only what
1949
+ * putting the files back needs: the session (its workspace entries; no
1950
+ * blueprint is resolved), the run's values (the repository tokens the
1951
+ * write-back pushes with), the workspace and its lock, then the undos owed
1952
+ * (`owed-undos.ts`). No hook, eval case, MCP server, skill, attachment or
1953
+ * engine is touched on any harness, and the session event emitter never
1954
+ * begins; the outcome is written as `stigmer.file_review.reconciled` and the
1955
+ * turn settles `file-review-resolved`, whose settle finalizes the write-back
1956
+ * and completes with stop cause `review_resolved`.
1957
+ */
1958
+ export async function resolveReconcileTurn(
1959
+ deps: ResolutionDeps,
1960
+ frame: TurnFrame,
1961
+ sessionId: string,
1962
+ ): Promise<TurnResolution> {
1963
+ deps.enterPhase("load_session");
1964
+ const session = await deps.client.getSession(sessionId);
1965
+ deps.timing.mark("load_session");
1966
+ const fetched = await fetchValues(deps);
1967
+ if (fetched.kind === "settled") return { kind: "settled", settlement: fetched.settlement };
1968
+ const { workspace, writeback } = await provisionWorkspace(deps, {
1969
+ session,
1970
+ sessionId,
1971
+ repositories: fetched.values.repositories,
1972
+ review: false,
1973
+ });
1974
+ frame.primaryDir = workspace.primaryDir;
1975
+ frame.writeback = writeback;
1976
+
1977
+ const lock = await acquireWorkspaceTurnLock(deps, workspace.primaryDir);
1978
+ if (lock.kind === "settled") return { kind: "settled", settlement: lock.settlement };
1979
+ frame.releaseWorkspaceLock = lock.release;
1980
+ const outcomes = await reconcileOwedUndosPhase(deps, { sessionId, workspace, reconcileTurn: true });
1981
+ return { kind: "settled", settlement: reconcileTurnSettlement(outcomes) };
1982
+ }