@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,1419 @@
1
+ /**
2
+ * The Cursor harness's boundary rows — the post-stream settlements that turn
3
+ * the deny-and-retry primitive's evidence into transcript rows the runtime's
4
+ * review surfaces read: the denial overlay (a hook-denied call becomes the
5
+ * turn's one WAITING_APPROVAL gate), the same-identity twin collapse, the
6
+ * one-gate-per-turn collapse of non-anchor denials, the provisional-narration
7
+ * redaction, the #205 foreign-hook-block detector, the #965 unresolved-row
8
+ * settle, and the unattended-mode SKIPPED stamp.
9
+ *
10
+ * Moved verbatim from the boundary half of `message-translator.ts` in #1097,
11
+ * so that module's folding half — the Cursor accumulator, the
12
+ * second copy of the transcript folding rule — could be deleted whole at the
13
+ * swap and replaced by `translator.ts` over the shared
14
+ * `TranscriptBuilder`. Nothing here folds engine events: every function
15
+ * AMENDS rows the stream already created, by identity (the token the hook and
16
+ * the runner share); the one row this module ever needs CREATED — the gate for
17
+ * a denial no streamed call matched — and the one it REOPENS — the streamed
18
+ * call the hook denied — go through the shared `TranscriptBuilder` as
19
+ * `approval_proposed`, the one post-stream fact both harnesses produce
20
+ * (#1097). `isTerminalToolStatus` below is the twin
21
+ * collapse's own settled set (`shared/tool-row.ts` explains why INTERRUPTED is
22
+ * not in it).
23
+ *
24
+ * The identity this module correlates on lives in `approval-state.ts`
25
+ * (`toolCallIdentityToken` beside `toolIdentity`/`primaryToken`, the same
26
+ * space the hook records denials in); the row predicates it shares with the
27
+ * runtime (`isAdjudicatedRow`, `isDeclinedRow`) in `shared/tool-row.ts`.
28
+ * The pipeline that calls these, and its ordering rationale, is
29
+ * `turn-boundary.ts`.
30
+ */
31
+
32
+ import type { TranscriptBuilder } from "../../harness/transcript/builder.js";
33
+ import type { McpApprovalDefault } from "./approval-policy.js";
34
+ import { resolveApprovalMessage, resolveBuiltInApprovalMessage } from "./approval-policy.js";
35
+ import { CURSOR_SDK_TOOL_COVERS } from "@stigmer/tool-vocabulary";
36
+ import { normalizeSubAgentType } from "../../shared/tool-lists.js";
37
+ import { AGENT_SCOPE_KEY, READ_SCOPE_KEY, SCOPE_KEY_PREFIX, scopeKey } from "./hook-scope.js";
38
+ import {
39
+ DESTRUCTIVE_MCP_APPROVAL_MESSAGE,
40
+ mcpToolKey,
41
+ UNLISTED_MCP_APPROVAL_MESSAGE,
42
+ POLICY_ENGINE_VERSION,
43
+ resolveApprovalProvenance,
44
+ unattendedSkipMessage,
45
+ } from "../../shared/approval-policy.js";
46
+ import {
47
+ approvalDenials,
48
+ decodeIdentityToken,
49
+ denialKindOf,
50
+ DISABLED_DENIAL_KIND,
51
+ grantToken,
52
+ HOOK_DENIAL_KIND,
53
+ hookAskDigest,
54
+ toolCallArgs,
55
+ toolCallIdentityToken,
56
+ toolIdentity,
57
+ type DeniedLedgerEntry,
58
+ } from "./approval-state.js";
59
+ import { utcTimestamp } from "../../shared/status.js";
60
+ import { hideToolCallRow, isAdjudicatedRow, isToolCallRowHidden } from "../../shared/tool-row.js";
61
+ import { toolApprovalCategory, type ToolApprovalCategory } from "../../shared/tool-kind.js";
62
+ import { resolveWorkspacePath } from "../../shared/file-change.js";
63
+ import { contentDigest, extractFilePath } from "../../shared/file-tools.js";
64
+ import { isSecretLikePath } from "../../shared/filereview/secret-paths.js";
65
+ import type { WorkspaceBackend } from "../../shared/workspace/types.js";
66
+ import type { AgentMessage, ToolCall, SubAgentRun } from "../../gen/turn/ai/stigmer/runner/turn/v1/rows_pb.js";
67
+ import { ApprovalPolicySource, MessageType, ToolCallStatus } from "../../gen/turn/ai/stigmer/runner/turn/v1/enum_pb.js";
68
+
69
+ /** No row settled from a refusal: the twin collapse's default keep-set. */
70
+ const NO_REFUSED_ROWS: ReadonlySet<string> = new Set();
71
+
72
+ /** Shared empty set so a synthesized gate's provenance read allocates nothing. */
73
+ const NO_LEASED_CATEGORIES: ReadonlySet<ToolApprovalCategory> = new Set();
74
+
75
+ /**
76
+ * Terminal for the twin collapse's "prefer a settled representative" pick —
77
+ * the same set the merge guard used (`isSettled` in the shared builder):
78
+ * INTERRUPTED is deliberately NOT here; see `shared/tool-row.ts`.
79
+ */
80
+ function isTerminalToolStatus(status: ToolCallStatus): boolean {
81
+ return (
82
+ status === ToolCallStatus.TOOL_CALL_COMPLETED ||
83
+ status === ToolCallStatus.TOOL_CALL_FAILED ||
84
+ status === ToolCallStatus.TOOL_CALL_SKIPPED
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Reconcile the denial ledger written by the preToolUse hook against the tool
90
+ * calls accumulated from the stream, marking each denied call as
91
+ * WAITING_APPROVAL.
92
+ *
93
+ * This is the cursor analog of the native harness synthesizing WAITING_APPROVAL
94
+ * tool calls from LangGraph interrupts (execute-deep-agent/turn-settle.ts). The hook
95
+ * ledger — not the SDK-reported tool status — is the authoritative record of
96
+ * what was gated, because the hook is the only component that makes the per-call
97
+ * allow/deny decision. The backend then projects pending_approvals from these
98
+ * WAITING_APPROVAL tool calls (PendingApprovalComputer), so the approval surface
99
+ * is driven entirely by tool-call status, exactly like the native harness.
100
+ *
101
+ * Correlation is by tool identity token (the same space as approvedGrantTokens),
102
+ * not by call id: a denied tool's identity is stable, and a single resource
103
+ * approved once should produce one approval regardless of how many times the
104
+ * agent re-attempted it within the turn.
105
+ *
106
+ * ONE GATE PER TURN (deny-only clean pause). The Cursor harness can only gate by
107
+ * the hook returning `deny`, which Cursor surfaces to the model as a tool
108
+ * *failure* — so a blocked model frequently improvises a workaround (the
109
+ * canonical case: a denied `edit notes.md` followed ~2.5s later by a
110
+ * `shell: cat > notes.md`, in the SAME assistant message with no narration
111
+ * between them — observed in production, exec aex_01kw4p0cqgk0j8vvxbs5t8gv59).
112
+ * The first-denial stop (index.ts) tries to cancel the turn at that first
113
+ * denial, but `run.cancel()` is async and races the SDK's auto-execution, so the
114
+ * workaround can still stream and land a SECOND denial in the ledger. Two
115
+ * denials of distinct identity would otherwise surface two approval cards for
116
+ * one logical intent. Their identities differ (`write\nnotes.md` vs
117
+ * `shell\ncat > notes.md`), so no same-identity twin collapse can join them, and
118
+ * they share one message, so no positional rule can separate them; the only
119
+ * honest signal that the second is a reaction is CAUSALITY — it was emitted
120
+ * after the model saw the first denial. We therefore ANCHOR on the FIRST ledger
121
+ * denial of the turn (the ledger is reset per turn and appended in denial order,
122
+ * so ledger[0] is the original intent) and surface ONLY that identity. Every
123
+ * other denied identity in the turn — a post-denial workaround, or a genuine
124
+ * co-pending sibling the deny-only harness defers — is blanked in place to a
125
+ * hidden SKIPPED row ({@link collapseNonAnchorDenials}). A deferred sibling is
126
+ * not lost: on resume it re-attempts and gates again next turn (sequential
127
+ * gating). The native (LangGraph) harness pauses BEFORE the model can react, so
128
+ * it keeps full in-turn co-pending and is untouched by this rule. This is the
129
+ * near-term, invariant-preserving stepping stone to the Tool Execution Gateway,
130
+ * where an un-leased workaround is refused by construction.
131
+ *
132
+ * Correlation runs in two passes. The first matches the streamed token to a
133
+ * ledger token byte-for-byte (the common case). The hook, however, records its
134
+ * token from the RAW path Cursor hands it — a bash script cannot normalize a
135
+ * path against the workspace root — so an ABSOLUTE hook `file_path` against a
136
+ * RELATIVE stream `path` (or vice versa) yields two different raw tokens for one
137
+ * edit and the exact pass misses. The runner CAN normalize, so a second pass
138
+ * matches any still-unmatched FILE denial to a streamed call by (category,
139
+ * workspace-normalized path) and overlays the REAL streamed call, never appending
140
+ * a content-less placeholder beside it. This is the difference between one honest
141
+ * gate and two cards, one of which reads "No preview available". It reuses the
142
+ * single tool-identity definition + `resolveWorkspacePath`; it introduces no
143
+ * parallel identity.
144
+ *
145
+ * Only after BOTH passes miss is a placeholder WAITING_APPROVAL tool call
146
+ * synthesized (rare — Cursor normally emits a tool_call event for every
147
+ * attempt), so the gate still surfaces and never renders as a silent success.
148
+ * Critically, every match overlays a call IN PLACE (the committed id is
149
+ * preserved): the backend's append-only-at-identity transcript guard rejects a
150
+ * finalize that drops a previously-committed tool-call id, so reconciliation may
151
+ * only reconcile entries in place, never remove them.
152
+ *
153
+ * Every matched/synthesized call is enriched with the hook-captured authoritative
154
+ * input (`ledger.input`) via {@link applyGateInput}: the full proposed args, a
155
+ * compact `args_preview`, and the content digest — so the approval card renders
156
+ * the proposed write/edit content from `args` and a resume re-gates a diverging
157
+ * sibling edit. A missing capture (the hook's grep fallback) degrades to the
158
+ * prior behavior.
159
+ *
160
+ * Every gate this function opens goes through the transcript builder as an
161
+ * `approval_proposed` (since #1097): a known row REOPENS
162
+ * (WAITING, the outcome the stream wrote cleared, the hook's captured input as
163
+ * its args and preview), an unknown one gets a WAITING row on the message
164
+ * whose text proposed it. The builder is the one writer of a WAITING row on
165
+ * both harnesses; this module supplies the fact and reads the row back.
166
+ *
167
+ * Two handles, one object: `messages` is the root transcript's own array
168
+ * (`status.messages`, the rows this function reads and matches against) and
169
+ * `transcript` is the builder that creates rows INTO that same array — it
170
+ * pushes and never replaces, so a row proposed through the builder is found
171
+ * in `messages` on the next line. Rows to read, a builder to create through:
172
+ * the sink's ownership rule, stated in the signature.
173
+ *
174
+ * Returns the tool calls now marked WAITING_APPROVAL — the single anchor gate
175
+ * for the turn (overlaid or, rarely, synthesized).
176
+ */
177
+ export async function reconcileDeniedToolCalls(
178
+ messages: AgentMessage[],
179
+ transcript: TranscriptBuilder,
180
+ ledger: DeniedLedgerEntry[],
181
+ mcpDefault?: McpApprovalDefault,
182
+ workspaceBackend?: WorkspaceBackend,
183
+ ): Promise<ToolCall[]> {
184
+ // Defense-in-depth: only APPROVAL-kind denials may become approval gates.
185
+ // The turn boundary already passes the filtered subset; re-filtering here
186
+ // makes it structurally impossible for a secret/capture-error/fail-closed
187
+ // entry to manufacture a pause the user cannot meaningfully grant, no matter
188
+ // what a future caller passes (an absent kind is the pre-kind format and
189
+ // counts as approval).
190
+ ledger = approvalDenials(ledger);
191
+ if (ledger.length === 0) return [];
192
+
193
+ // The workspace the gated files live in; its rootDir normalizes paths for the
194
+ // abs-vs-rel correlation fallback (normalizedFileSalient).
195
+ const workspaceRoot = workspaceBackend?.rootDir;
196
+
197
+ // One gate per turn: anchor on the FIRST ledger denial. The ledger is reset
198
+ // per turn and appended in denial order, so ledger[0] is the model's original
199
+ // intent; any later denial of a DIFFERENT identity is a post-denial workaround
200
+ // or a deferred co-pending sibling (see the doc comment). We surface ONLY the
201
+ // anchor identity below and blank every other denied identity to a hidden
202
+ // SKIPPED row. `deniedTokens` still carries every denied identity — it is the
203
+ // scope for that collapse, never an additional gate.
204
+ const anchorToken = ledger[0].token;
205
+ const deniedTokens = new Set(ledger.map((e) => e.token));
206
+ // The authoritative pre-execution args the hook captured for the anchor. A
207
+ // resource re-attempted within the turn shares a token; last write wins (the
208
+ // attempts carry the same proposed change).
209
+ let anchorInput: Record<string, unknown> | undefined;
210
+ for (const e of ledger) {
211
+ if (e.token === anchorToken && e.input) anchorInput = e.input;
212
+ }
213
+ // A hook asked for the anchor: the card names the hook and says why.
214
+ const anchorAsk = askedByHook(ledger[0]);
215
+ const matchedCalls = new Set<ToolCall>();
216
+ const result: ToolCall[] = [];
217
+ let anchorMatched = false;
218
+
219
+ // 1. Exact overlay: a streamed call whose token equals the anchor denial token
220
+ // byte-for-byte (the path form agreed on both sides). The anchor resource
221
+ // re-attempted within the turn shares one token and collapses to a single
222
+ // approval (the first match is the keeper; same-identity twins are blanked
223
+ // by collapseRedundantToolCallTwins below). A row an earlier invocation's
224
+ // gate already settled is never the home of THIS turn's denial
225
+ // (isAdjudicatedRow) — the search moves past it to this turn's attempt.
226
+ for (const msg of messages) {
227
+ if (anchorMatched) break;
228
+ for (const tc of msg.toolCalls) {
229
+ if (isAdjudicatedRow(tc)) continue;
230
+ if (toolCallIdentityToken(tc) !== anchorToken) continue;
231
+ proposeOnStreamedRow(transcript, tc, anchorInput, mcpDefault, anchorAsk);
232
+ matchedCalls.add(tc);
233
+ result.push(tc);
234
+ anchorMatched = true;
235
+ break;
236
+ }
237
+ }
238
+
239
+ // 2. Normalized-path fallback (the abs-vs-rel drift fix): if the anchor is a
240
+ // FILE denial the exact pass missed, match a streamed call by (category,
241
+ // workspace-normalized path) and overlay the REAL call — never a content-
242
+ // less placeholder beside it. Requires the workspace root to normalize;
243
+ // shell/MCP denials (no path) and resumes without a root fall through to
244
+ // synthesis.
245
+ if (!anchorMatched && workspaceRoot) {
246
+ const decoded = decodeIdentityToken(anchorToken);
247
+ const wanted = decoded
248
+ ? normalizedFileSalient(decoded.key, decoded.salient, workspaceRoot)
249
+ : undefined;
250
+ if (wanted) {
251
+ const tc = findUnmatchedStreamCallByNormalizedSalient(
252
+ messages, matchedCalls, wanted, workspaceRoot,
253
+ );
254
+ if (tc) {
255
+ proposeOnStreamedRow(transcript, tc, anchorInput, mcpDefault, anchorAsk);
256
+ matchedCalls.add(tc);
257
+ result.push(tc);
258
+ anchorMatched = true;
259
+ }
260
+ }
261
+ }
262
+
263
+ // 2a. One gate per turn: blank every denied identity OTHER than the anchor to a
264
+ // hidden SKIPPED row (the workaround shell, or a deferred co-pending
265
+ // sibling). Runs BEFORE the WAITING_FOR_APPROVAL persist so a reaction is
266
+ // never persisted as WAITING_APPROVAL — the backend authors an approval
267
+ // REQUESTED event only from a WAITING_APPROVAL tool call, so collapsing
268
+ // here keeps the append-only approval-event stream free of an orphan
269
+ // REQUESTED that would need retraction.
270
+ const nonAnchorCollapsed = collapseNonAnchorDenials(messages, deniedTokens, anchorToken);
271
+ if (nonAnchorCollapsed > 0) {
272
+ console.log(
273
+ `ExecuteCursor reconcile collapsed ${nonAnchorCollapsed} non-anchor denied ` +
274
+ `tool call(s) to hidden SKIPPED (one gate per turn; anchor is the first ` +
275
+ `denial of the turn)`,
276
+ );
277
+ }
278
+
279
+ // 2b. Collapse same-turn duplicate edits. When the model emitted the SAME
280
+ // resource twice in one turn (two call ids, one identity token), only the
281
+ // FIRST same-token stream call was overlaid into the gate above; any OTHER
282
+ // same-token call stays a committed row (RUNNING zombie, or a
283
+ // denied-reported-as-success COMPLETED) that would render as a second,
284
+ // content-less card beside the gate (the reported "No preview available"
285
+ // duplicate). The overlaid gate is now WAITING_APPROVAL, so the shared
286
+ // routine recognizes it as the keeper and blanks the twins IN PLACE to
287
+ // hidden SKIPPED rows — we cannot drop them, since the backend's
288
+ // append-only-at-identity guard rejects removing a previously-committed
289
+ // tool-call id, but the id is preserved so the finalize stays append-only.
290
+ const collapsed = collapseRedundantToolCallTwins(messages);
291
+ if (collapsed > 0) {
292
+ console.log(
293
+ `ExecuteCursor reconcile collapsed ${collapsed} redundant tool-call twin(s) ` +
294
+ `superseded by the approval gate (kept in place as hidden SKIPPED rows)`,
295
+ );
296
+ }
297
+
298
+ // 2c. Finalize interrupted rows. The first-denial stop cancelled the run, so
299
+ // a tool call still PENDING/RUNNING here can never complete — no event
300
+ // will ever deliver its result, and left alone it persists as a spinner
301
+ // forever. The canonical victim is a post-denial workaround whose own
302
+ // hook denial raced (or never reached) the final ledger read, so the
303
+ // token-scoped collapse in 2a could not see it (production case
304
+ // aex_01kwj07f7g23c3wp9sn8496z5g: a python-write shell reaction persisted
305
+ // as RUNNING with requiresApproval=true). Whatever the cause, a
306
+ // non-terminal row on a turn that is pausing is an interrupted attempt
307
+ // with no output: collapse it to the same hidden SKIPPED shape as every
308
+ // other superseded row (in place — the append-only-at-identity guard
309
+ // forbids dropping a committed id). Runs AFTER the anchor overlay, so the
310
+ // gate itself (now WAITING_APPROVAL) is never touched.
311
+ const interrupted = finalizeInterruptedToolCalls(messages);
312
+ if (interrupted > 0) {
313
+ console.log(
314
+ `ExecuteCursor reconcile collapsed ${interrupted} interrupted non-terminal ` +
315
+ `tool call(s) that can never complete (run cancelled at first denial)`,
316
+ );
317
+ }
318
+
319
+ // 3. Synthesize the anchor gate if it matched NO streamed call in either pass
320
+ // (rare — Cursor emits a tool_call event for every attempt), so the gate
321
+ // still surfaces rather than rendering as a silent success. After the
322
+ // normalized fallback this should be ~0; the caller logs a divergence when
323
+ // it is not (a synthesized id is prefixed `approval:`). Only the anchor is
324
+ // ever synthesized: non-anchor denials are deliberately collapsed, never
325
+ // surfaced (one gate per turn).
326
+ if (!anchorMatched) {
327
+ const anchorEntry = ledger.find((e) => e.token === anchorToken) ?? ledger[0];
328
+ const decoded = decodeIdentityToken(anchorToken);
329
+ // Display the hook's raw tool name; carry the decoded salient so the grant
330
+ // rebuilt from this tool call on reinvocation keys on the same resource.
331
+ const displayName = anchorEntry.toolName || decoded?.key || "tool";
332
+ const salient = decoded?.salient ?? "";
333
+ const tc = proposeSynthesizedGate(messages, transcript, {
334
+ displayName,
335
+ salient,
336
+ digest: decoded?.digest ?? "",
337
+ token: anchorToken,
338
+ input: anchorInput ?? anchorEntry.input,
339
+ mcpDefault,
340
+ asked: anchorAsk,
341
+ });
342
+ result.push(tc);
343
+ }
344
+
345
+ return result;
346
+ }
347
+
348
+ /**
349
+ * Propose the gate ON a streamed tool call the hook denied: the row REOPENS
350
+ * WAITING through the builder and keeps its committed id, so the backend's
351
+ * append-only-at-identity transcript guard accepts the finalize (an in-place
352
+ * status change is a reconcile, not a drop). The single routine for both the
353
+ * exact and the normalized correlation passes, so the gate can never diverge
354
+ * between them. The message is the one the stream already stamped when the
355
+ * policy gated the call, else resolved now; the hook-captured `input` (when
356
+ * present) is the authoritative, complete proposed args — the stream may have
357
+ * carried only partial args before the first-denial cancel — and supplies the
358
+ * args, the preview and the content digest (see {@link proposalArgs}).
359
+ */
360
+ function proposeOnStreamedRow(
361
+ transcript: TranscriptBuilder,
362
+ tc: ToolCall,
363
+ input: Record<string, unknown> | undefined,
364
+ mcpDefault: McpApprovalDefault | undefined,
365
+ asked: HookAsk | undefined,
366
+ ): void {
367
+ const args = proposalArgs(input);
368
+ const digest = approvalDigest(tc.mcpServerSlug, args ? contentDigest(args) : "", input, asked !== undefined);
369
+ transcript.apply({
370
+ kind: "approval_proposed",
371
+ callId: tc.id,
372
+ name: tc.name,
373
+ mcpServerSlug: tc.mcpServerSlug,
374
+ message: asked?.message || tc.approvalMessage || resolveDeniedApprovalMessage(tc.name, tc.mcpServerSlug, toolCallArgs(tc), mcpDefault),
375
+ ...(asked !== undefined ? { provenance: "hook" as const, policyHook: asked.hook } : {}),
376
+ ...(args !== undefined ? { args } : {}),
377
+ ...(digest ? { contentDigest: digest } : {}),
378
+ });
379
+ }
380
+
381
+ /**
382
+ * The digest an approval is granted under: a built-in's file content when it
383
+ * has some; for a call a hook asked on and that has none, or any MCP call a
384
+ * hook asked on, the hook's whole input ({@link hookAskDigest}), so the grant
385
+ * lets through that call and no other, as the native engine asks for each.
386
+ */
387
+ export function approvalDigest(
388
+ mcpServerSlug: string,
389
+ content: string,
390
+ input: Record<string, unknown> | undefined,
391
+ askedByHook: boolean,
392
+ ): string {
393
+ if (!askedByHook || input === undefined) return content;
394
+ return content && !mcpServerSlug ? content : hookAskDigest(input);
395
+ }
396
+
397
+ /** A hook's ask, as the card shows it. */
398
+ interface HookAsk {
399
+ readonly hook: string;
400
+ readonly message: string;
401
+ }
402
+
403
+ /** The hook that asked for a ledger entry's approval, when one did. */
404
+ function askedByHook(entry: DeniedLedgerEntry | undefined): HookAsk | undefined {
405
+ if (entry?.hook === undefined) return undefined;
406
+ return { hook: entry.hook, message: entry.message ?? "" };
407
+ }
408
+
409
+ /**
410
+ * Propose the gate for a denial that matched NO streamed call: a WAITING row
411
+ * with a synthesized id (`approval:<token>`) on the message whose text proposed
412
+ * it. It displays the hook's raw tool name and carries the decoded salient as
413
+ * its args (so the grant rebuilt from it on reinvocation keys on the same
414
+ * resource) and the anchor's content digest (so its identity equals the
415
+ * anchor's content token); the hook-captured input, when present, upgrades
416
+ * both to the full proposed change. A synthesized call is a ledger denial — it
417
+ * was gated, so it has a governing layer, and a denied call never occurs under
418
+ * a global bypass or a matching lease, so empty leases + no bypass attribute
419
+ * it faithfully (a built-in resolves to builtin_category; an MCP placeholder
420
+ * lacks a reconstructed slug and stays UNSPECIFIED rather than be mislabeled).
421
+ * The row is read back from `messages`, the array the builder appended into.
422
+ */
423
+ function proposeSynthesizedGate(
424
+ messages: readonly AgentMessage[],
425
+ transcript: TranscriptBuilder,
426
+ gate: {
427
+ displayName: string;
428
+ salient: string;
429
+ digest: string;
430
+ token: string;
431
+ input: Record<string, unknown> | undefined;
432
+ mcpDefault: McpApprovalDefault | undefined;
433
+ asked: HookAsk | undefined;
434
+ },
435
+ ): ToolCall {
436
+ const { displayName, salient, digest, token, input, mcpDefault, asked } = gate;
437
+ const callId = `approval:${token}`;
438
+ const captured = proposalArgs(input);
439
+ const args = captured ?? (salient ? { path: salient } : undefined);
440
+ const provenance = asked !== undefined
441
+ ? "hook" as const
442
+ : mcpDefault
443
+ ? resolveApprovalProvenance(displayName, "", mcpDefault, NO_LEASED_CATEGORIES, false)
444
+ : undefined;
445
+ transcript.apply({
446
+ kind: "approval_proposed",
447
+ callId,
448
+ name: displayName,
449
+ mcpServerSlug: "",
450
+ message: asked?.message || (salient
451
+ ? `Tool requires approval: ${displayName} (${salient})`
452
+ : resolveDeniedApprovalMessage(displayName, "", {}, mcpDefault)),
453
+ ...(args !== undefined ? { args } : {}),
454
+ ...(provenance !== undefined ? { provenance } : {}),
455
+ ...(asked !== undefined ? { policyHook: asked.hook } : {}),
456
+ contentDigest: approvalDigest("", captured ? contentDigest(captured) : digest, input, asked !== undefined),
457
+ });
458
+ const row = findToolCallById(messages, callId);
459
+ if (!row) throw new Error(`reconcileDeniedToolCalls: the builder did not create the proposed row ${callId}`);
460
+ return row;
461
+ }
462
+
463
+ /** The last row with this id in the root transcript (the builder appends; a synthesized gate is always the newest). */
464
+ function findToolCallById(messages: readonly AgentMessage[], id: string): ToolCall | undefined {
465
+ for (let i = messages.length - 1; i >= 0; i--) {
466
+ const found = messages[i].toolCalls.find((tc) => tc.id === id);
467
+ if (found) return found;
468
+ }
469
+ return undefined;
470
+ }
471
+
472
+ /**
473
+ * Collapse every tool call still in a non-terminal state (PENDING / RUNNING)
474
+ * to the hidden SKIPPED row shape, returning how many were collapsed.
475
+ *
476
+ * Called only on the pause-for-approval path, after the anchor gate has been
477
+ * overlaid to WAITING_APPROVAL: the run was cancelled, so nothing will ever
478
+ * complete these calls, and a permanently-RUNNING row would render as an
479
+ * eternal spinner beside the approval card. This is the causality sibling of
480
+ * {@link collapseNonAnchorDenials}: that collapse is token-scoped (it needs the
481
+ * denial in the ledger), while this one catches the attempt whose hook denial
482
+ * raced the final ledger read or whose execution the cancel interrupted
483
+ * outright — either way an attempt with no output that the turn's end orphaned.
484
+ */
485
+ function finalizeInterruptedToolCalls(messages: AgentMessage[]): number {
486
+ let finalized = 0;
487
+ for (const msg of messages) {
488
+ for (const tc of msg.toolCalls) {
489
+ if (
490
+ tc.status !== ToolCallStatus.TOOL_CALL_PENDING &&
491
+ tc.status !== ToolCallStatus.TOOL_CALL_RUNNING
492
+ ) {
493
+ continue;
494
+ }
495
+ hideToolCallRow(tc);
496
+ finalized++;
497
+ }
498
+ }
499
+ return finalized;
500
+ }
501
+
502
+ /**
503
+ * Recognizes a tool call already blanked to a hidden collapsed row, so a second
504
+ * pass never re-collapses it (and never miscounts). Mirrors the SDK's
505
+ * `isCollapsedToolCall` shape without importing across the runner/SDK seam.
506
+ */
507
+ function isAlreadyCollapsed(tc: ToolCall): boolean {
508
+ return (
509
+ tc.status === ToolCallStatus.TOOL_CALL_SKIPPED &&
510
+ !tc.requiresApproval &&
511
+ !tc.result &&
512
+ !tc.error &&
513
+ !tc.argsPreview
514
+ );
515
+ }
516
+
517
+ /**
518
+ * Whether a tool call carries a change/output of its own — the signal that it is
519
+ * authoritative for its resource rather than a redundant denial/cancel twin.
520
+ *
521
+ * The notion of "change" is category-aware on purpose:
522
+ * - A file mutation (`write`/`delete`) never carries an authoritative change on
523
+ * the tool-call ROW: under apply-then-review its review lives in the
524
+ * `FileChangeSet` ledger (capture mode), and under the no-storage deny-gate it
525
+ * is the WAITING_APPROVAL gate itself (kept explicitly by the caller). So a
526
+ * file row is authoritative only as that gate, never on its own — hence
527
+ * `false` here. (This once read `file_changes.length > 0`;
528
+ * that field is gone, and the row was never the review surface.)
529
+ * - Every other gated tool (shell, MCP) has no ledger; its "change" is its
530
+ * execution output, so a genuine run carries a non-empty `result` while a
531
+ * denied/cancelled attempt that never executed does not. This keeps two
532
+ * distinct shell runs (each with output) both visible while still collapsing a
533
+ * same-command denial twin.
534
+ */
535
+ function carriesOwnChange(tc: ToolCall): boolean {
536
+ const category = toolApprovalCategory(tc.name);
537
+ if (category === "write" || category === "delete") {
538
+ return false;
539
+ }
540
+ return !!tc.result;
541
+ }
542
+
543
+ /**
544
+ * Whether this turn's boundary may still rewrite a row: the fact the
545
+ * session event emitter reads (`harness/events/emitter.ts`, through this
546
+ * harness's `boundaryRewritesRow` capability) so it never writes into the
547
+ * log a row the boundary will reopen, hide or settle differently. Such a
548
+ * row, and everything after it in its thread, is written once the turn's
549
+ * terminal write proves the boundary ran.
550
+ *
551
+ * The rows each pass of the boundary can still touch, and no others:
552
+ * - a call still PENDING or RUNNING: the interrupted-attempt finalize hides
553
+ * it, the unresolved settle marks it, the refusal stamps settle it;
554
+ * - a call FAILED by a hook block (`isHookBlockError`): the denial overlay
555
+ * reopens it as the turn's gate, the one-gate collapse hides it, the
556
+ * refusal and unattended stamps settle it;
557
+ * - a gated call (a file write or delete, a shell, an MCP tool) that
558
+ * carries no change of its own (`carriesOwnChange`): the twin collapse
559
+ * hides it when a same-identity sibling turns up later in the turn.
560
+ *
561
+ * A row a person already decided is a keeper of every pass, so never
562
+ * rewritten; a read-only built-in that settled, or a shell or MCP call that
563
+ * returned output, is final the moment it settles.
564
+ */
565
+ export function boundaryMayStillRewrite(tc: ToolCall): boolean {
566
+ if (isAdjudicatedRow(tc)) return false;
567
+ if (tc.status === ToolCallStatus.TOOL_CALL_PENDING || tc.status === ToolCallStatus.TOOL_CALL_RUNNING) return true;
568
+ if (tc.status === ToolCallStatus.TOOL_CALL_FAILED && isHookBlockError(tc.error)) return true;
569
+ const key = toolIdentity(tc.name, tc.mcpServerSlug, toolCallArgs(tc)).key;
570
+ const gated = tc.mcpServerSlug ? true : key === "write" || key === "delete" || key === "shell";
571
+ return gated && !carriesOwnChange(tc);
572
+ }
573
+
574
+ /**
575
+ * Collapse redundant same-identity tool-call twins to a single visible row.
576
+ *
577
+ * The model frequently emits the SAME gated action twice in one turn (two
578
+ * tool-call ids, one identity). When the first attempt is gated and the run is
579
+ * cancelled mid-flight, the extra attempt never receives a terminal event and
580
+ * persists as a stuck `RUNNING` row ("No preview available"); other variants are
581
+ * a denied-reported-as-success `COMPLETED` with an empty result, two no-change
582
+ * `COMPLETED` attempts where neither carries a change, or — on the denial path —
583
+ * a `FAILED` twin beside the overlaid gate. All render as a duplicate card beside
584
+ * the real action (or the approval gate). This is the recurring duplicate-card
585
+ * defect, most visible for file edits but shared by every gated tool family.
586
+ *
587
+ * The routine is harness-agnostic and a pure function of `messages`:
588
+ *
589
+ * 1. Scope to GATED identities — file mutations (`write`/`delete`) and shell key
590
+ * on their cross-taxonomy category; MCP tools are recognized by their server
591
+ * slug. A same-turn duplicate of a gated tool is a denial/cancel artifact, not
592
+ * meaningful repetition. The category is name-derived (via {@link toolIdentity}
593
+ * -> approvalCategory), so a twin cancelled before classification (empty
594
+ * `toolKind`) is still scoped via its name (`edit` -> `write`). Ungated
595
+ * read-only tools are left untouched.
596
+ * 2. Group those calls by `toolCallIdentityToken` — the SAME `toolIdentity` used
597
+ * for denial correlation and resume grants, so scope and grouping cannot drift.
598
+ * 3. In each group the keepers carry authoritative state — a change/output of
599
+ * their own (see {@link carriesOwnChange}), a row named in `refusedRowIds`
600
+ * (the ids {@link stampHookRefusedToolCalls} settled: each the record of a
601
+ * refusal, carried by id because its shape matches a hook-block twin's) or
602
+ * the approval gate itself (`WAITING_APPROVAL`). For a file mutation the gate is the sole authoritative
603
+ * row: the row carries no diff (review lives in the `FileChangeSet` ledger, or
604
+ * is the no-storage deny-gate itself), so a denied write's same-identity
605
+ * siblings — a denied/zombie row or a stale snapshot from a second attempt —
606
+ * collapse onto the gate. A shell/MCP twin keeps every distinct run with
607
+ * output. If NO member qualifies (every attempt produced no change), keep
608
+ * exactly ONE representative — preferring a terminal attempt over a stuck
609
+ * `RUNNING` zombie — so the resource still shows a single card. Every
610
+ * non-keeper is blanked in place to a hidden `SKIPPED` row (see
611
+ * {@link collapseDenialTwin}).
612
+ *
613
+ * It is deliberately subtractive — it only ever HIDES a row, never invents a
614
+ * terminal state. The committed `id` is preserved on every collapse, so the
615
+ * finalize stays append-only by construction and the backend's
616
+ * append-only-at-identity guard accepts it. Returns the number collapsed, for
617
+ * observability.
618
+ */
619
+ export function collapseRedundantToolCallTwins(
620
+ messages: AgentMessage[],
621
+ refusedRowIds: ReadonlySet<string> = NO_REFUSED_ROWS,
622
+ ): number {
623
+ const groups = new Map<string, ToolCall[]>();
624
+ for (const msg of messages) {
625
+ for (const tc of msg.toolCalls) {
626
+ const id = toolIdentity(tc.name, tc.mcpServerSlug, toolCallArgs(tc));
627
+ const gated = tc.mcpServerSlug
628
+ ? true
629
+ : id.key === "write" || id.key === "delete" || id.key === "shell";
630
+ if (!gated) continue;
631
+ const token = grantToken(id.key, id.salient);
632
+ const bucket = groups.get(token);
633
+ if (bucket) bucket.push(tc);
634
+ else groups.set(token, [tc]);
635
+ }
636
+ }
637
+
638
+ let collapsed = 0;
639
+ for (const group of groups.values()) {
640
+ if (group.length < 2) continue; // a lone call is never a twin
641
+
642
+ // Keepers carry authoritative state: a change/output of their own
643
+ // (carriesOwnChange), the approval gate itself, or a gate an earlier
644
+ // invocation already settled (isAdjudicatedRow — the transcript's record of
645
+ // what the user decided and what ran; a same-identity act in a later turn
646
+ // is a new act, never this row's twin), or a row the boundary settled from
647
+ // a refusal in the ledger (`refusedRowIds`: one row per refusal, so two
648
+ // refusals of one command in a turn are two acts, #1967). For a file
649
+ // mutation the gate is the sole authoritative row (the row carries no diff — review lives in
650
+ // the ledger, or the row IS the no-storage deny-gate), so a denied write's
651
+ // same-identity siblings collapse onto it; a shell/MCP twin keeps every
652
+ // distinct run with output.
653
+ const keepers = new Set<ToolCall>(
654
+ group.filter(
655
+ (tc) =>
656
+ carriesOwnChange(tc) ||
657
+ isAdjudicatedRow(tc) ||
658
+ refusedRowIds.has(tc.id) ||
659
+ tc.status === ToolCallStatus.TOOL_CALL_WAITING_APPROVAL,
660
+ ),
661
+ );
662
+ // All attempts produced no change (e.g. denied-reported-as-success): keep one
663
+ // representative, preferring a settled outcome over a stuck RUNNING zombie.
664
+ if (keepers.size === 0) {
665
+ const terminal = [...group].reverse().find((tc) => isTerminalToolStatus(tc.status));
666
+ keepers.add(terminal ?? group[0]);
667
+ }
668
+
669
+ for (const tc of group) {
670
+ if (keepers.has(tc)) continue;
671
+ if (isAlreadyCollapsed(tc)) continue;
672
+ collapseDenialTwin(tc);
673
+ collapsed++;
674
+ }
675
+ }
676
+ return collapsed;
677
+ }
678
+
679
+ /**
680
+ * One gate per turn: blank every DENIED tool call whose identity differs from
681
+ * the anchor (the first denial of the turn) to a hidden SKIPPED row.
682
+ *
683
+ * This is the cross-identity complement of {@link collapseRedundantToolCallTwins}
684
+ * (which only joins SAME-identity duplicates). The canonical target is the
685
+ * deny-only workaround — a denied `edit notes.md` followed by a `shell:
686
+ * cat > notes.md` whose identity (`shell\n…`) differs from the edit's
687
+ * (`write\nnotes.md`), so no twin collapse can join them and (since they share
688
+ * one assistant message) no positional rule can separate them. The honest signal
689
+ * that the shell is redundant is that it is a DIFFERENT denied identity in the
690
+ * same turn as the anchor; under the one-gate-per-turn contract every such
691
+ * identity is either a post-denial reaction or a co-pending sibling the harness
692
+ * defers to the next turn, so it is hidden, not surfaced.
693
+ *
694
+ * Scoped strictly to identities present in `deniedTokens`: a non-denied tool
695
+ * (an earlier read/glob, or an already-granted call that ran) is never touched.
696
+ * Subtractive and id-preserving (via {@link collapseDenialTwin}), so the finalize
697
+ * stays append-only. Returns the number collapsed, for observability.
698
+ */
699
+ function collapseNonAnchorDenials(
700
+ messages: AgentMessage[],
701
+ deniedTokens: ReadonlySet<string>,
702
+ anchorToken: string,
703
+ ): number {
704
+ let collapsed = 0;
705
+ for (const msg of messages) {
706
+ for (const tc of msg.toolCalls) {
707
+ if (isAdjudicatedRow(tc)) continue;
708
+ const token = toolCallIdentityToken(tc);
709
+ if (token === anchorToken) continue;
710
+ if (!deniedTokens.has(token)) continue;
711
+ if (isAlreadyCollapsed(tc)) continue;
712
+ collapseDenialTwin(tc);
713
+ collapsed++;
714
+ }
715
+ }
716
+ return collapsed;
717
+ }
718
+
719
+ /**
720
+ * Blank a superseded denial twin in place to a hidden SKIPPED row. Keeps the
721
+ * committed `id` (append-only), `name`, and `toolKind`; clears every renderable
722
+ * surface and the approval flags so the SDK's `isCollapsedToolCall` predicate
723
+ * recognizes it and renders nothing. The structured `args` are left as the honest
724
+ * stored record of the redundant attempt (never rendered, since the row is
725
+ * hidden; the gate carries the authoritative proposed change).
726
+ */
727
+ function collapseDenialTwin(tc: ToolCall): void {
728
+ hideToolCallRow(tc);
729
+ }
730
+
731
+ // `hideToolCallRow` (the "hidden row" shape, shared by the denial-twin collapse
732
+ // and the capture flow) lives in shared/tool-row.ts so both harnesses collapse
733
+ // rows identically; imported at the top of this module.
734
+
735
+ /**
736
+ * The hook-captured authoritative tool input as a proposal's args, so the
737
+ * approval card can show the proposed change before the user approves.
738
+ *
739
+ * When present it becomes the single source for the preview: the full
740
+ * structured `args` (the approval card renders the proposed write/edit content
741
+ * from these), the compact-but-always-valid `args_preview` the builder derives
742
+ * from them (the field a resumed turn parses to rebuild the grant salient — so
743
+ * salient fields are never elided), and the content digest the caller stamps
744
+ * beside them. The digest is the resume identity: it binds the grant to
745
+ * (category, path, content) so a sibling edit to the same file re-gates rather
746
+ * than riding an earlier approval through. It is also the identity the Cursor
747
+ * deny-gate's exact-apply reads on resume — together with the whole-file bytes
748
+ * in `args` — to write exactly what was approved (see exact-apply.ts). There is
749
+ * no separate captured `file_changes` mirror; `args` is the single source for
750
+ * both the preview and the applied bytes.
751
+ *
752
+ * Defense-in-depth: a secret-like write's content never reaches the
753
+ * persisted approval preview. Normally unreachable — the hook hard-blocks a
754
+ * secret write and records no ledger input — but if a hook classify failure
755
+ * fell one through, its content must still never reach args/args_preview; the
756
+ * Invariant-A backstop is the final net, this closes the path at the source.
757
+ * With no input (the hook's grep fallback) there is nothing authoritative and
758
+ * the row keeps its existing args.
759
+ */
760
+ function proposalArgs(input: Record<string, unknown> | undefined): Record<string, unknown> | undefined {
761
+ if (!input) return undefined;
762
+ const gatePath = extractFilePath(input);
763
+ if (gatePath !== null && isSecretLikePath(gatePath)) return undefined;
764
+ return input;
765
+ }
766
+
767
+ /** The identity keys whose salient is a path: the file categories, and the read, search, listing and lint read a hook may ask on. */
768
+ const PATH_KEYS: ReadonlySet<string> = new Set(["write", "delete", "Read", "Grep", "List", "ReadLints"]);
769
+
770
+ /**
771
+ * The workspace-normalized identity of a FILE approval category's salient, or
772
+ * undefined for a non-file category (shell, whose salient is a command, not a
773
+ * path) or an empty salient. Both the hook-decoded denial salient and a streamed
774
+ * call's salient pass through this, so an absolute-vs-relative path difference
775
+ * collapses to one comparable key (`category + "\n" + relPath`). Restricting to
776
+ * write/delete keeps a shell command from being mangled by path normalization.
777
+ */
778
+ function normalizedFileSalient(
779
+ category: string,
780
+ salient: string,
781
+ workspaceRoot: string,
782
+ ): string | undefined {
783
+ if (!PATH_KEYS.has(category) || !salient) return undefined;
784
+ const { path } = resolveWorkspacePath(salient, workspaceRoot, /* virtualRoot */ false);
785
+ return `${category}\n${path}`;
786
+ }
787
+
788
+ /**
789
+ * Find the first not-yet-overlaid streamed tool call whose workspace-normalized
790
+ * (category, path) equals `wanted`. Skips calls already claimed by an earlier
791
+ * denial so several concurrent file denials each overlay a distinct stream call.
792
+ */
793
+ function findUnmatchedStreamCallByNormalizedSalient(
794
+ messages: AgentMessage[],
795
+ matchedCalls: ReadonlySet<ToolCall>,
796
+ wanted: string,
797
+ workspaceRoot: string,
798
+ ): ToolCall | undefined {
799
+ for (const msg of messages) {
800
+ for (const tc of msg.toolCalls) {
801
+ if (matchedCalls.has(tc) || isAdjudicatedRow(tc)) continue;
802
+ const id = toolIdentity(tc.name, tc.mcpServerSlug, toolCallArgs(tc));
803
+ if (normalizedFileSalient(id.key, id.salient, workspaceRoot) === wanted) {
804
+ return tc;
805
+ }
806
+ }
807
+ }
808
+ return undefined;
809
+ }
810
+
811
+ /**
812
+ * Redact provisional post-denial narration when a Cursor turn pauses for approval.
813
+ *
814
+ * THE PROBLEM. Unlike the native harness — which gates with a LangGraph
815
+ * `interrupt()` *before* the tool runs, so the model never sees a denial — the
816
+ * Cursor harness can only gate via the file-based `beforeMCPExecution`/
817
+ * `preToolUse` hook returning `deny`. Cursor surfaces that deny to the model as
818
+ * a tool *failure* (often its own generic "blocked by a hook" text; see the
819
+ * ground-truth capture in cursor_hitl_test.go), and there is no
820
+ * non-leaky SDK approval primitive to use instead (the `request` event is
821
+ * opaque and carries no responder). So a well-behaved model frequently reacts by
822
+ * narrating defeat — "I couldn't do this; enable the hook in your Cursor
823
+ * settings" — which would otherwise be persisted as the assistant's verdict and
824
+ * rendered right next to the approval card that is, in fact, asking the user to
825
+ * approve. Contradictory and alarming.
826
+ *
827
+ * THE GUARANTEE. The runner's job is to simplify this data, not mirror its
828
+ * complexity: a turn that pauses for approval must read the SAME shape the
829
+ * native harness produces — `[pre-tool text][tool calls WAITING_APPROVAL]`, with
830
+ * no post-denial verdict. We therefore BLANK (clear the `content` of, and mark
831
+ * non-streaming) the trailing assistant/thinking messages that (a) appear
832
+ * positionally AFTER the last message bearing a WAITING_APPROVAL tool call and
833
+ * (b) carry no tool calls of their own. The approval card (projected from the
834
+ * WAITING_APPROVAL tool-call status) becomes the single, unambiguous source of
835
+ * truth. The blanked messages are already invisible on every surface via the
836
+ * existing empty-message handling (`buildThreadItems` skips empty `MESSAGE_AI`;
837
+ * `MessageEntry` renders nothing for empty `MESSAGE_THINKING`), so the shared
838
+ * `@stigmer/react-sdk`/Ink components stay harness-agnostic with zero per-harness UI
839
+ * special-casing — the cleanliness lives in the data, not in each consumer.
840
+ *
841
+ * WHY BLANK INSTEAD OF REMOVE. Removing the messages would make the persisted
842
+ * WAITING_FOR_APPROVAL transcript SHORTER than the in-progress transcript the
843
+ * runner already streamed. The backend's append-only message guard rejects a
844
+ * shrink for a non-terminal execution (it protects against regressed/partial
845
+ * writes). Blanking keeps the message COUNT identical, so the finalize is
846
+ * append-only BY CONSTRUCTION and the guard accepts it with no special case —
847
+ * which is why this phase deletes the backend's former `isApprovalFinalize`
848
+ * shrink exception in both editions. The transcript is the authoritative *raw*
849
+ * record; the verbatim narration text remains recoverable from the runner logs
850
+ * and the recorded cursor-event stream.
851
+ *
852
+ * WHY THIS IS DETERMINISTIC. `attachToolCallToLastAi` calls
853
+ * `finalizeStreaming(run_id)` before attaching a tool call, so any assistant
854
+ * text the model emits *after* the denied tool call always starts a NEW message
855
+ * — post-denial narration is never merged into the message that holds the gated
856
+ * call. We stop at the first non-narration message — one bearing a VISIBLE tool
857
+ * call — so legitimately-executed tools after the gate and any text around them
858
+ * are never touched; only the contiguous trailing reaction block is blanked. A
859
+ * message whose every tool call was collapsed to the hidden SKIPPED row (a
860
+ * post-denial workaround or an interrupted attempt — see
861
+ * collapseNonAnchorDenials / finalizeInterruptedToolCalls, which run first) IS
862
+ * trailing narration: its rows render as absent, so only its text remains, and
863
+ * that text is precisely the reaction this redaction exists to blank. Treating
864
+ * it as a stop would strand every reaction message behind it (the production
865
+ * shape in aex_01kwj07f7g23c3wp9sn8496z5g: [gate][thinking][narration+workaround
866
+ * row] — the old walk stopped at the workaround message and redacted nothing).
867
+ * The first-denial stop in index.ts is the primary mechanism that keeps this
868
+ * block small (it ends the turn before the model produces inter-tool
869
+ * narration); this redaction is the backstop for any token that streamed before
870
+ * the cancel landed.
871
+ *
872
+ * Returns the blanked messages (for diagnostics); mutates `messages` in place.
873
+ */
874
+ export function clearProvisionalPostDenialNarration(
875
+ messages: AgentMessage[],
876
+ deniedToolCalls: ToolCall[],
877
+ ): AgentMessage[] {
878
+ if (deniedToolCalls.length === 0) return [];
879
+
880
+ // reconcileDeniedToolCalls returns the very ToolCall protos held inside
881
+ // messages[].toolCalls (overlaid) or appended to the last AI message
882
+ // (synthesized), so object identity is a stable, exact match.
883
+ const denied = new Set(deniedToolCalls);
884
+
885
+ let lastGatedIdx = -1;
886
+ for (let i = 0; i < messages.length; i++) {
887
+ if (messages[i].toolCalls.some((tc) => denied.has(tc))) {
888
+ lastGatedIdx = i;
889
+ }
890
+ }
891
+ if (lastGatedIdx < 0) return [];
892
+
893
+ const redacted: AgentMessage[] = [];
894
+ for (let i = messages.length - 1; i > lastGatedIdx; i--) {
895
+ const msg = messages[i];
896
+ const isProvisionalNarration =
897
+ (msg.type === MessageType.MESSAGE_AI || msg.type === MessageType.MESSAGE_THINKING) &&
898
+ msg.toolCalls.every((tc) => isToolCallRowHidden(tc));
899
+ // Stop at the first message that is NOT trailing narration: a message
900
+ // bearing a visible (non-collapsed) tool call marks real activity we must
901
+ // preserve, and anything before it is no longer "trailing".
902
+ if (!isProvisionalNarration) break;
903
+ // Blank in place — keep the message so the transcript count never shrinks,
904
+ // but drop its provisional content so no consumer renders the defeatist
905
+ // verdict. Empty AI/THINKING messages are hidden by the SDK already; hidden
906
+ // SKIPPED rows already render as absent.
907
+ msg.content = "";
908
+ msg.isStreaming = false;
909
+ redacted.unshift(msg);
910
+ }
911
+ return redacted;
912
+ }
913
+
914
+ /**
915
+ * Substrings of the error text Cursor stamps onto a tool call blocked by a
916
+ * `preToolUse`/`beforeMCPExecution` hook (its generic replacement for the
917
+ * hook's own agent_message — confirmed by the ground-truth capture in
918
+ * cursor_hitl_test.go). The SDK has NO structured "denied by hook" signal, so
919
+ * this marker family is the only stream-side trace of a hook block and is
920
+ * single-sourced here for every consumer (the issue #205 attribution detector
921
+ * below; tests). Matched case-insensitively against the FAILED call's error.
922
+ */
923
+ export const HOOK_BLOCK_ERROR_MARKERS: readonly string[] = ["blocked by a hook"];
924
+
925
+ /** True when a tool call's error text reads as a hook block. */
926
+ function isHookBlockError(errorText: string): boolean {
927
+ if (!errorText) return false;
928
+ const lowered = errorText.toLowerCase();
929
+ return HOOK_BLOCK_ERROR_MARKERS.some((marker) => lowered.includes(marker));
930
+ }
931
+
932
+ /** One hook-blocked tool call that no ledger entry accounts for (issue #205). */
933
+ export interface UnattributedHookBlock {
934
+ toolCallId: string;
935
+ toolName: string;
936
+ /** The hook-block error text Cursor stamped on the call. */
937
+ error: string;
938
+ }
939
+
940
+ /**
941
+ * Detect tool calls blocked by a hook that STIGMER'S OWN hook did not deny —
942
+ * the issue #205 invariant check "a blocked tool must never silently complete".
943
+ *
944
+ * Cursor runs EVERY hook it loads, and a deny from any of them blocks the
945
+ * tool. The gate sets a workspace's own hook files aside for the turn
946
+ * (`workspace-hook-files.ts`), and our hook records every deny it issues to
947
+ * the denial ledger (all kinds — see {@link DeniedLedgerEntry}), so a FAILED
948
+ * tool call carrying Cursor's hook-block error text with NO matching ledger
949
+ * entry was blocked by a FOREIGN hook the set-aside missed (one loaded from
950
+ * a file the turn does not rewrite, or written during the turn) — or,
951
+ * equally fatally, by our own hook whose best-effort ledger append failed.
952
+ * Either way the runner cannot pause for approval (an approval grants a
953
+ * token only OUR hook reads; the foreign hook would deny the re-attempt
954
+ * forever), so the caller surfaces an explicit failure instead of
955
+ * completing with the work silently undone.
956
+ *
957
+ * Attribution, in order:
958
+ * 1. Any `fail-closed` ledger entry → the gate itself was broken this turn and
959
+ * denied EVERYTHING it saw; per-call correlation is meaningless, so every
960
+ * hook block is attributed to our own (broken) gate. Nothing is reported.
961
+ * 2. Exact identity: the call's {@link toolCallIdentityToken} appears in the
962
+ * ledger (any kind — approval gates were overlaid to WAITING_APPROVAL or
963
+ * collapsed by the reconcile that runs first, so a still-FAILED row here is
964
+ * typically a secret/capture-error deny, correctly attributed as ours).
965
+ * 3. Normalized-path fallback: the same abs-vs-rel drift the reconcile's
966
+ * second pass handles — a FILE call matches a ledger entry by (category,
967
+ * workspace-normalized path) even when the raw tokens differ.
968
+ * 4. Tool-list refusal: a call the hook refused as out of scope
969
+ * ({@link scopeRefusalOf}: the tool, and for a tool the lists exclude only
970
+ * in part, the call it names). {@link stampScopeRefusedToolCalls}
971
+ * normally rewrote such rows already; this keeps a refusal recorded
972
+ * without its text attributable too.
973
+ *
974
+ * Scoped to THIS turn's messages (from `turnStartMessageIndex`): seeded
975
+ * prior-turn rows were already adjudicated and must never re-trigger.
976
+ * Deliberately conservative: an ordinary tool failure (no hook-block text)
977
+ * is never reported, and a foreign hook denying with fully custom text evades
978
+ * the marker match (the documented residual).
979
+ */
980
+ export function detectUnattributedHookBlocks(
981
+ messages: readonly AgentMessage[],
982
+ turnStartMessageIndex: number,
983
+ ledger: readonly DeniedLedgerEntry[],
984
+ workspaceRoot?: string,
985
+ ): UnattributedHookBlock[] {
986
+ if (ledger.some((e) => denialKindOf(e) === "fail-closed")) return [];
987
+
988
+ const ledgerTokens = new Set(ledger.map((e) => e.token));
989
+ const ledgerNormalizedSalients = new Set<string>();
990
+ if (workspaceRoot) {
991
+ for (const entry of ledger) {
992
+ const decoded = decodeIdentityToken(entry.token);
993
+ if (!decoded) continue;
994
+ const normalized = normalizedFileSalient(decoded.key, decoded.salient, workspaceRoot);
995
+ if (normalized) ledgerNormalizedSalients.add(normalized);
996
+ }
997
+ }
998
+ const refusals = scopeRefusalsIn(ledger);
999
+
1000
+ const blocks: UnattributedHookBlock[] = [];
1001
+ for (const msg of messages.slice(Math.max(0, turnStartMessageIndex))) {
1002
+ for (const tc of msg.toolCalls) {
1003
+ if (tc.status !== ToolCallStatus.TOOL_CALL_FAILED) continue;
1004
+ if (!isHookBlockError(tc.error)) continue;
1005
+ if (ledgerTokens.has(toolCallIdentityToken(tc))) continue;
1006
+ if (scopeRefusalOf(tc, refusals, workspaceRoot) !== undefined) continue;
1007
+ if (workspaceRoot) {
1008
+ const id = toolIdentity(tc.name, tc.mcpServerSlug, toolCallArgs(tc));
1009
+ const normalized = normalizedFileSalient(id.key, id.salient, workspaceRoot);
1010
+ if (normalized && ledgerNormalizedSalients.has(normalized)) continue;
1011
+ }
1012
+ blocks.push({ toolCallId: tc.id, toolName: tc.name, error: tc.error });
1013
+ }
1014
+ }
1015
+ return blocks;
1016
+ }
1017
+
1018
+ /**
1019
+ * The honest terminal error stamped on a tool call that never resolved (issue
1020
+ * #965). Deliberately states all three negatives — not executed, not approved,
1021
+ * not denied — because the incident's harm was the model claiming an approval
1022
+ * was pending: this text is what the transcript shows INSTEAD of a spinner or
1023
+ * a silent after-the-fact interruption, and it must leave no room for an
1024
+ * approval-is-coming reading.
1025
+ */
1026
+ export const UNRESOLVED_TOOL_CALL_ERROR =
1027
+ "The tool did not return a result before the turn ended. It was never " +
1028
+ "executed, approved, or denied — no approval is pending for it.";
1029
+
1030
+ /** One never-resolved tool call the turn boundary settled (issue #965). */
1031
+ export interface UnresolvedToolCall {
1032
+ toolCallId: string;
1033
+ toolName: string;
1034
+ }
1035
+
1036
+ /**
1037
+ * Settle this-turn tool calls that are still NON-TERMINAL when a turn
1038
+ * completes without pausing — the issue #965 invariant, the sibling of
1039
+ * {@link detectUnattributedHookBlocks}' #205 invariant ("a blocked tool must
1040
+ * never silently complete" → "an unresolved tool must never silently
1041
+ * complete").
1042
+ *
1043
+ * THE SHAPE THIS CATCHES. A tool that hangs INSIDE the Cursor agent runtime —
1044
+ * the production case is `generateImage`, which rides the SDK's
1045
+ * interaction-query channel rather than the ordinary tool path — streams a
1046
+ * tool_call start, never streams a result, and is invisible to every Stigmer
1047
+ * seam: the hook never denied it (no ledger entry), so the reconcile never
1048
+ * gated it, and the turn completes with the row still PENDING/RUNNING. Before
1049
+ * this sweep, the server's terminal settle (issue #207) stamped such rows
1050
+ * TOOL_CALL_INTERRUPTED silently AFTER the runner reported completion — the
1051
+ * transcript's last word stayed whatever the model claimed, which in
1052
+ * aex_01m1a6ww3nmp4952ar5v0g4g85 was a promise that an approval was pending
1053
+ * when none existed.
1054
+ *
1055
+ * Settling here instead makes the runner the author of the honest record: the
1056
+ * row gets TOOL_CALL_INTERRUPTED with {@link UNRESOLVED_TOOL_CALL_ERROR}, and
1057
+ * the caller (turn-boundary.ts) appends a system disclosure naming what never
1058
+ * ran.
1059
+ *
1060
+ * WHY INTERRUPTED AND NEVER FAILED. TOOL_CALL_INTERRUPTED is deliberately the
1061
+ * one settled status the monotonic merge guard lets live execution evidence
1062
+ * supersede (see the guard's note in this file, ~line 331): if this FAILED
1063
+ * execution is later RECOVERED, the harness checkpoint may re-execute the call
1064
+ * under its original id, and the replayed events must be able to advance the
1065
+ * row to its true outcome. A boundary-stamped FAILED would freeze it forever.
1066
+ *
1067
+ * WHY IT NEVER FAILS THE RUN (unlike #205). A foreign hook block is provably
1068
+ * adversarial — approval semantics are permanently broken, so completing would
1069
+ * always be a lie. An unresolved row can also be benign stream event-loss
1070
+ * where the tool actually ran; failing the run would convert those into
1071
+ * regressions. Disclosure restores honesty at zero regression risk.
1072
+ *
1073
+ * Scope and exclusions, in order:
1074
+ * - THIS turn's parent-transcript rows only (from `turnStartMessageIndex`):
1075
+ * seeded prior-turn rows were adjudicated by their own execution's settle,
1076
+ * and sub-agent inner rows are the server settle's concern — the parent row
1077
+ * (e.g. the Task call) is what the user sees. Mirrors #205's scoping.
1078
+ * - Only PENDING/RUNNING rows: every terminal row was adjudicated, and
1079
+ * WAITING_APPROVAL rows belong to the pause machinery (the caller only runs
1080
+ * this sweep on a NON-pausing turn, so none should exist here anyway).
1081
+ * - Only rows with NO denial-ledger entry of ANY kind (exact token, then the
1082
+ * normalized-path fallback — the same two identities every sweep in this
1083
+ * file uses): a ledger-attributed row is the unattended/secret/fail-closed
1084
+ * machinery's to settle, not ours.
1085
+ *
1086
+ * Returns the settled calls so the boundary can disclose and log them.
1087
+ */
1088
+ export function settleUnresolvedToolCalls(
1089
+ messages: readonly AgentMessage[],
1090
+ turnStartMessageIndex: number,
1091
+ ledger: readonly DeniedLedgerEntry[],
1092
+ workspaceRoot?: string,
1093
+ ): UnresolvedToolCall[] {
1094
+ const ledgerTokens = new Set(ledger.map((e) => e.token));
1095
+ const ledgerNormalizedSalients = new Set<string>();
1096
+ if (workspaceRoot) {
1097
+ for (const entry of ledger) {
1098
+ const decoded = decodeIdentityToken(entry.token);
1099
+ if (!decoded) continue;
1100
+ const normalized = normalizedFileSalient(decoded.key, decoded.salient, workspaceRoot);
1101
+ if (normalized) ledgerNormalizedSalients.add(normalized);
1102
+ }
1103
+ }
1104
+
1105
+ const matchesLedger = (tc: ToolCall): boolean => {
1106
+ if (ledgerTokens.has(toolCallIdentityToken(tc))) return true;
1107
+ if (!workspaceRoot) return false;
1108
+ const id = toolIdentity(tc.name, tc.mcpServerSlug, toolCallArgs(tc));
1109
+ const normalized = normalizedFileSalient(id.key, id.salient, workspaceRoot);
1110
+ return !!normalized && ledgerNormalizedSalients.has(normalized);
1111
+ };
1112
+
1113
+ const settled: UnresolvedToolCall[] = [];
1114
+ for (const msg of messages.slice(Math.max(0, turnStartMessageIndex))) {
1115
+ for (const tc of msg.toolCalls) {
1116
+ if (
1117
+ tc.status !== ToolCallStatus.TOOL_CALL_PENDING &&
1118
+ tc.status !== ToolCallStatus.TOOL_CALL_RUNNING
1119
+ ) {
1120
+ continue;
1121
+ }
1122
+ if (matchesLedger(tc)) continue;
1123
+ tc.status = ToolCallStatus.TOOL_CALL_INTERRUPTED;
1124
+ tc.error = UNRESOLVED_TOOL_CALL_ERROR;
1125
+ tc.isStreaming = false;
1126
+ if (!tc.completedAt) tc.completedAt = utcTimestamp();
1127
+ settled.push({ toolCallId: tc.id, toolName: tc.name });
1128
+ }
1129
+ }
1130
+ return settled;
1131
+ }
1132
+
1133
+ /**
1134
+ * Stamp the tool calls the hook denied under UNATTENDED approval mode
1135
+ * as terminal TOOL_CALL_SKIPPED rows with UNATTENDED_SKIP
1136
+ * provenance — the Cursor twin of the native harness's
1137
+ * `reconcileUnattendedSkips`, so both harnesses persist the same honest
1138
+ * shape for a platform-resolved skip.
1139
+ *
1140
+ * An unattended denial never pauses the run (its ledger kind is excluded
1141
+ * from {@link approvalDenials}), so the stream leaves the denied call as a
1142
+ * FAILED row carrying Cursor's generic hook-block error — dishonest ("the
1143
+ * tool broke") and alarming in a transcript an org admin reviews. This pass
1144
+ * correlates the unattended ledger entries to their streamed calls with the
1145
+ * SAME two identities the rest of the file uses — exact token, then
1146
+ * (category, workspace-normalized path) for the abs-vs-rel drift — and
1147
+ * settles each match to SKIPPED with a result explaining the skip.
1148
+ *
1149
+ * Scope: hook-blocked FAILED rows and still-non-terminal (PENDING/RUNNING)
1150
+ * rows only — a COMPLETED row is a real execution and is never rewritten
1151
+ * (an unattended deny cannot produce one). `approval_action`/`approved_by`
1152
+ * stay untouched: they record a person's decision only (the runtime's seed
1153
+ * copies the answer from the session's log).
1154
+ * Unmatched ledger entries need no synthesis — there is no pause to
1155
+ * surface; the model already saw the deny and adapted in-turn.
1156
+ *
1157
+ * Returns how many tool calls were stamped.
1158
+ */
1159
+ export function stampUnattendedSkippedToolCalls(
1160
+ messages: readonly AgentMessage[],
1161
+ subAgentExecutions: readonly SubAgentRun[],
1162
+ unattendedLedger: readonly DeniedLedgerEntry[],
1163
+ workspaceRoot?: string,
1164
+ ): number {
1165
+ if (unattendedLedger.length === 0) return 0;
1166
+
1167
+ const ledgerTokens = new Set(unattendedLedger.map((e) => e.token));
1168
+ // The hook that asked, by the call's token: the skipped row names it.
1169
+ const askingHooks = new Map(unattendedLedger.flatMap((e) => (e.hook !== undefined ? [[e.token, e.hook] as const] : [])));
1170
+ const ledgerNormalizedSalients = new Set<string>();
1171
+ if (workspaceRoot) {
1172
+ for (const entry of unattendedLedger) {
1173
+ const decoded = decodeIdentityToken(entry.token);
1174
+ if (!decoded) continue;
1175
+ const normalized = normalizedFileSalient(decoded.key, decoded.salient, workspaceRoot);
1176
+ if (normalized) ledgerNormalizedSalients.add(normalized);
1177
+ }
1178
+ }
1179
+
1180
+ const matchesLedger = (tc: ToolCall): boolean => {
1181
+ if (ledgerTokens.has(toolCallIdentityToken(tc))) return true;
1182
+ if (!workspaceRoot) return false;
1183
+ const id = toolIdentity(tc.name, tc.mcpServerSlug, toolCallArgs(tc));
1184
+ const normalized = normalizedFileSalient(id.key, id.salient, workspaceRoot);
1185
+ return !!normalized && ledgerNormalizedSalients.has(normalized);
1186
+ };
1187
+
1188
+ let stamped = 0;
1189
+ const apply = (msgs: readonly AgentMessage[]): void => {
1190
+ for (const msg of msgs) {
1191
+ for (const tc of msg.toolCalls) {
1192
+ const deniedShape =
1193
+ (tc.status === ToolCallStatus.TOOL_CALL_FAILED && isHookBlockError(tc.error)) ||
1194
+ tc.status === ToolCallStatus.TOOL_CALL_PENDING ||
1195
+ tc.status === ToolCallStatus.TOOL_CALL_RUNNING;
1196
+ if (!deniedShape || !matchesLedger(tc)) continue;
1197
+ tc.status = ToolCallStatus.TOOL_CALL_SKIPPED;
1198
+ tc.approvalPolicySource = ApprovalPolicySource.UNATTENDED_SKIP;
1199
+ tc.approvalPolicyHook = askingHooks.get(toolCallIdentityToken(tc)) ?? "";
1200
+ tc.policyEngineVersion = POLICY_ENGINE_VERSION;
1201
+ tc.error = "";
1202
+ tc.result = unattendedSkipMessage(tc.name);
1203
+ tc.isStreaming = false;
1204
+ if (!tc.completedAt) tc.completedAt = utcTimestamp();
1205
+ stamped++;
1206
+ }
1207
+ }
1208
+ };
1209
+
1210
+ apply(messages);
1211
+ for (const subAgent of subAgentExecutions) {
1212
+ apply(subAgent.messages);
1213
+ }
1214
+ return stamped;
1215
+ }
1216
+
1217
+ /** One tool-list refusal the hook recorded (ledger kind `disabled`). */
1218
+ interface ScopeRefusal {
1219
+ /** The tool's scope key (`scopeKey`, or `server/tool` for an MCP call). */
1220
+ readonly key: string;
1221
+ /** The call's discriminator for a tool excluded only in part; "" names the whole tool. */
1222
+ readonly discriminator: string;
1223
+ /** The refusal the model read; "" when the entry carries none. */
1224
+ readonly message: string;
1225
+ }
1226
+
1227
+ /** The tool-list refusals in a ledger, decoded from their scope tokens (`scopeRefusalToken`). */
1228
+ function scopeRefusalsIn(ledger: readonly DeniedLedgerEntry[]): ScopeRefusal[] {
1229
+ const refusals: ScopeRefusal[] = [];
1230
+ for (const entry of ledger) {
1231
+ if (denialKindOf(entry) !== DISABLED_DENIAL_KIND) continue;
1232
+ const decoded = decodeIdentityToken(entry.token);
1233
+ if (!decoded || !decoded.key.startsWith(SCOPE_KEY_PREFIX)) continue;
1234
+ refusals.push({ key: decoded.key.slice(SCOPE_KEY_PREFIX.length), discriminator: decoded.salient, message: entry.message ?? "" });
1235
+ }
1236
+ return refusals;
1237
+ }
1238
+
1239
+ /**
1240
+ * The refusal this streamed call is, if any. The tool must match: its
1241
+ * `server/tool` for an MCP call, else the stream name's `scopeKey` in the
1242
+ * SDK's taxonomy (every engine extra shares one); the hook computes the same
1243
+ * key from its own names (`hook-script.ts` `buildScopeEvalScript`). A refusal
1244
+ * naming the whole tool then matches every call of it. One carrying a
1245
+ * discriminator (a tool the lists exclude only in part) matches only the
1246
+ * call it names: a `task` by its normalized sub-agent type, a `read` by its
1247
+ * path, as given or normalized against the workspace (the hook and the
1248
+ * stream may spell one path absolutely and relatively). An allowed call of
1249
+ * the same tool, a `.stigmer/` read or a permitted sub-agent type, is never
1250
+ * matched.
1251
+ */
1252
+ function scopeRefusalOf(tc: ToolCall, refusals: readonly ScopeRefusal[], workspaceRoot: string | undefined): ScopeRefusal | undefined {
1253
+ const key = tc.mcpServerSlug ? mcpToolKey(tc.mcpServerSlug, tc.name) : scopeKey(tc.name, CURSOR_SDK_TOOL_COVERS);
1254
+ const args = toolCallArgs(tc);
1255
+ const callDiscriminator = (): string => {
1256
+ if (key !== AGENT_SCOPE_KEY) return toolIdentity(tc.name, tc.mcpServerSlug, args).salient;
1257
+ return typeof args.subagentType === "string" ? normalizeSubAgentType(args.subagentType) : "";
1258
+ };
1259
+ return refusals.find((r) => {
1260
+ if (r.key !== key) return false;
1261
+ if (r.discriminator === "") return true;
1262
+ const own = callDiscriminator();
1263
+ if (own === r.discriminator) return true;
1264
+ if (key !== READ_SCOPE_KEY || own === "" || workspaceRoot === undefined) return false;
1265
+ return resolveWorkspacePath(own, workspaceRoot, false).path === resolveWorkspacePath(r.discriminator, workspaceRoot, false).path;
1266
+ });
1267
+ }
1268
+
1269
+ /**
1270
+ * Settle the streamed rows of calls the hook refused under the agent's tool
1271
+ * lists (ledger kind `disabled`) into the shape the native harness persists
1272
+ * for the same refusal: TOOL_CALL_FAILED, the error the very text the model
1273
+ * read (`outOfScopeMessage`, carried on the ledger entry), no approval and no
1274
+ * provenance. Cursor stamps such a row with its generic hook-block text, and
1275
+ * the translator stamped the provenance its approval default would have
1276
+ * had at tool start, before anyone knew the call would be refused.
1277
+ *
1278
+ * Which rows: THIS turn's (from `turnStartMessageIndex`) and those of the
1279
+ * sub-agents this turn's `task` calls started, hook-blocked FAILED or still
1280
+ * PENDING/RUNNING (the unattended stamp's shape), that a refusal names
1281
+ * ({@link scopeRefusalOf}): an earlier turn's rows were settled then, and an
1282
+ * allowed call of a tool the lists exclude only in part is never one. A row
1283
+ * that failed for another reason carries no hook-block text and is left
1284
+ * alone.
1285
+ *
1286
+ * Runs before the #205 attribution pass, which then never sees these rows as
1287
+ * hook blocks. Returns how many rows were stamped.
1288
+ */
1289
+ export function stampScopeRefusedToolCalls(
1290
+ messages: readonly AgentMessage[],
1291
+ subAgentExecutions: readonly SubAgentRun[],
1292
+ ledger: readonly DeniedLedgerEntry[],
1293
+ turnStartMessageIndex: number,
1294
+ workspaceRoot?: string,
1295
+ ): number {
1296
+ const refusals = scopeRefusalsIn(ledger).filter((r) => r.message !== "");
1297
+ if (refusals.length === 0) return 0;
1298
+
1299
+ const turnMessages = messages.slice(Math.max(0, turnStartMessageIndex));
1300
+ const turnCallIds = new Set(turnMessages.flatMap((m) => m.toolCalls.map((tc) => tc.id)));
1301
+ let stamped = 0;
1302
+ const apply = (msgs: readonly AgentMessage[]): void => {
1303
+ for (const msg of msgs) {
1304
+ for (const tc of msg.toolCalls) {
1305
+ const deniedShape =
1306
+ (tc.status === ToolCallStatus.TOOL_CALL_FAILED && isHookBlockError(tc.error)) ||
1307
+ tc.status === ToolCallStatus.TOOL_CALL_PENDING ||
1308
+ tc.status === ToolCallStatus.TOOL_CALL_RUNNING;
1309
+ if (!deniedShape) continue;
1310
+ const refusal = scopeRefusalOf(tc, refusals, workspaceRoot);
1311
+ if (refusal === undefined) continue;
1312
+ tc.status = ToolCallStatus.TOOL_CALL_FAILED;
1313
+ tc.error = refusal.message;
1314
+ tc.requiresApproval = false;
1315
+ tc.approvalPolicySource = ApprovalPolicySource.UNSPECIFIED;
1316
+ tc.policyEngineVersion = "";
1317
+ tc.isStreaming = false;
1318
+ if (!tc.completedAt) tc.completedAt = utcTimestamp();
1319
+ stamped++;
1320
+ }
1321
+ }
1322
+ };
1323
+ apply(turnMessages);
1324
+ for (const subAgent of subAgentExecutions) {
1325
+ if (turnCallIds.has(subAgent.id)) apply(subAgent.messages);
1326
+ }
1327
+ return stamped;
1328
+ }
1329
+
1330
+ /**
1331
+ * Settle the streamed rows of calls the hook layer refused before they ran
1332
+ * (ledger kind `hook`) into the shape the native engine persists for the
1333
+ * same refusal: TOOL_CALL_FAILED, the error the very text the model read,
1334
+ * no approval, and HOOK provenance naming the hook that refused, or no
1335
+ * provenance when it was a person's earlier refusal standing over a hook's
1336
+ * allow. Cursor stamps such a row with its generic hook-block text.
1337
+ *
1338
+ * Which rows: THIS turn's (from `turnStartMessageIndex`) and those of the
1339
+ * sub-agents this turn's `task` calls started, hook-blocked FAILED or still
1340
+ * PENDING/RUNNING, each entry settling the first row of its call: the exact
1341
+ * identity token, its coarse (key, salient), then the workspace-normalized
1342
+ * path for the abs-vs-rel drift. Runs before the #205 attribution pass,
1343
+ * which then never sees these rows as hook blocks. Returns the ids of the
1344
+ * rows it stamped, which the terminal twin collapse keeps (#1967).
1345
+ */
1346
+ export function stampHookRefusedToolCalls(
1347
+ messages: readonly AgentMessage[],
1348
+ subAgentExecutions: readonly SubAgentRun[],
1349
+ ledger: readonly DeniedLedgerEntry[],
1350
+ turnStartMessageIndex: number,
1351
+ workspaceRoot?: string,
1352
+ ): string[] {
1353
+ const refusals = ledger.filter((e) => denialKindOf(e) === HOOK_DENIAL_KIND && e.message);
1354
+ if (refusals.length === 0) return [];
1355
+
1356
+ const turnMessages = messages.slice(Math.max(0, turnStartMessageIndex));
1357
+ const turnCallIds = new Set(turnMessages.flatMap((m) => m.toolCalls.map((tc) => tc.id)));
1358
+ const rows: ToolCall[] = [
1359
+ ...turnMessages.flatMap((m) => m.toolCalls),
1360
+ ...subAgentExecutions.filter((sa) => turnCallIds.has(sa.id)).flatMap((sa) => sa.messages.flatMap((m) => m.toolCalls)),
1361
+ ].filter(
1362
+ (tc) =>
1363
+ (tc.status === ToolCallStatus.TOOL_CALL_FAILED && isHookBlockError(tc.error)) ||
1364
+ tc.status === ToolCallStatus.TOOL_CALL_PENDING ||
1365
+ tc.status === ToolCallStatus.TOOL_CALL_RUNNING,
1366
+ );
1367
+
1368
+ const stamped: string[] = [];
1369
+ const settled = new Set<ToolCall>();
1370
+ for (const entry of refusals) {
1371
+ const decoded = decodeIdentityToken(entry.token);
1372
+ const coarse = decoded ? grantToken(decoded.key, decoded.salient) : undefined;
1373
+ const normalized = decoded && workspaceRoot ? normalizedFileSalient(decoded.key, decoded.salient, workspaceRoot) : undefined;
1374
+ const matches = (tc: ToolCall): boolean => {
1375
+ if (toolCallIdentityToken(tc) === entry.token) return true;
1376
+ const id = toolIdentity(tc.name, tc.mcpServerSlug, toolCallArgs(tc));
1377
+ if (coarse !== undefined && grantToken(id.key, id.salient) === coarse) return true;
1378
+ return normalized !== undefined && workspaceRoot !== undefined && normalizedFileSalient(id.key, id.salient, workspaceRoot) === normalized;
1379
+ };
1380
+ const tc = rows.find((row) => !settled.has(row) && matches(row));
1381
+ if (tc === undefined) continue;
1382
+ settled.add(tc);
1383
+ tc.status = ToolCallStatus.TOOL_CALL_FAILED;
1384
+ tc.error = entry.message ?? "";
1385
+ tc.requiresApproval = false;
1386
+ tc.approvalPolicySource = entry.hook !== undefined ? ApprovalPolicySource.HOOK : ApprovalPolicySource.UNSPECIFIED;
1387
+ tc.approvalPolicyHook = entry.hook ?? "";
1388
+ tc.policyEngineVersion = entry.hook !== undefined ? POLICY_ENGINE_VERSION : "";
1389
+ tc.isStreaming = false;
1390
+ if (!tc.completedAt) tc.completedAt = utcTimestamp();
1391
+ stamped.push(tc.id);
1392
+ }
1393
+ return stamped;
1394
+ }
1395
+
1396
+ /**
1397
+ * Resolve a human-readable approval message for a denied tool, preferring the
1398
+ * destructive-MCP template, then the unlisted-server one (a server whose
1399
+ * tools could not be listed this turn, so every tool of it asks), then the
1400
+ * built-in template, then a generic fallback.
1401
+ */
1402
+ function resolveDeniedApprovalMessage(
1403
+ name: string,
1404
+ mcpServerSlug: string,
1405
+ args: Record<string, unknown>,
1406
+ mcpDefault?: McpApprovalDefault,
1407
+ ): string {
1408
+ if (mcpDefault && mcpServerSlug && mcpDefault.destructive.has(mcpToolKey(mcpServerSlug, name))) {
1409
+ return resolveApprovalMessage(DESTRUCTIVE_MCP_APPROVAL_MESSAGE, name, args);
1410
+ }
1411
+ if (mcpDefault && mcpServerSlug && mcpDefault.unlisted.has(mcpServerSlug)) {
1412
+ return resolveApprovalMessage(UNLISTED_MCP_APPROVAL_MESSAGE, name, args);
1413
+ }
1414
+ if (!mcpServerSlug) {
1415
+ const message = resolveBuiltInApprovalMessage(name, args);
1416
+ if (message !== undefined) return message;
1417
+ }
1418
+ return `Tool requires approval: ${name}`;
1419
+ }