@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,1204 @@
1
+ /**
2
+ * Template for the approval hook script that Cursor spawns.
3
+ *
4
+ * This module doesn't execute as a hook itself — it generates the shell script
5
+ * written to the HITL dir as stigmer-approval.sh. Cursor invokes that ONE script
6
+ * for THREE events (registered in .cursor/hooks.json by workspace-setup.ts):
7
+ * - `preToolUse` — fires for built-in tools (Write/Shell/Delete/…), and
8
+ * for MCP calls as `MCP:<tool>`, which it leaves to:
9
+ * - `beforeMCPExecution` — the only event Cursor enforces for MCP tool calls,
10
+ * and the one whose payload names the server
11
+ * (`mcp_server_name`). MCP is therefore gated in
12
+ * exactly ONE place, so a denial is never
13
+ * double-recorded.
14
+ * - `subagentStart` — documented to fire before a sub-agent starts,
15
+ * with its `subagent_type`; only the scope arm
16
+ * answers it. The 1.0.31 local runtime does not
17
+ * fire it for a `task` call (live probe,
18
+ * 2026-10-05), so it is a second line for a
19
+ * runtime that does, never the guard: an
20
+ * `Agent(type, …)` type list is refused at setup
21
+ * (`turn-setup.ts` `checkToolScope`).
22
+ * - `postToolUse` — hands the model what the agent's hooks say after
23
+ * a call. Registered for every turn, as the others
24
+ * are (the SDK keeps the first registration it
25
+ * reads); a turn with no hooks answers it with
26
+ * nothing, at once.
27
+ * The script branches on the payload's `hook_event_name`. An agent's own
28
+ * hooks run inside the runner, which serves them to this script on a local
29
+ * socket (`hook-server.ts`).
30
+ *
31
+ * The hook script:
32
+ * 1. Reads the tool call JSON from stdin
33
+ * 2. Reads the approval state JSON file written by the cursor-runner
34
+ * 3. Evaluates, in order: the agent's tool lists (any event), then
35
+ * auto-approve, approved grants (reinvocation) and — by event — gated
36
+ * built-in tools (preToolUse) or destructive MCP tools (beforeMCPExecution)
37
+ * 4. On a deny, appends the call's identity token to the denial ledger
38
+ * (denials.jsonl) — EVERY deny path records, each tagged with a `kind`
39
+ * (see below), so the ledger is the complete, authoritative record of what
40
+ * this hook blocked this turn. The runner marks approval-kind denials as
41
+ * WAITING_APPROVAL; the full ledger is its attribution set for
42
+ * distinguishing our denials from a FOREIGN hook's (issue #205): a
43
+ * hook-blocked tool with NO ledger entry of any kind was not blocked by us.
44
+ * 5. Returns { "permission": "allow" } or { "permission": "deny" } on stdout
45
+ *
46
+ * Denial kinds (the attribution taxonomy, mirrored in approval-state.ts):
47
+ * - "approval" — the normal gate: pauses the run for user approval.
48
+ * - "secret" — secret hard-block: the agent continues, no pause.
49
+ * - "capture-error" — CAS staging failed, write kept on the deny-gate.
50
+ * - "fail-closed" — approval state file missing, everything gated denies.
51
+ * - "disabled" — the agent's tool lists exclude the tool (or the
52
+ * sub-agent type): the agent continues, no pause,
53
+ * permanent for the run.
54
+ * - "hook" — an agent's hook refused the call, or a person's
55
+ * earlier refusal stood over a hook's allow: the agent
56
+ * continues, no pause; carries the refusal and the
57
+ * hook. An approval a hook asked for carries the hook
58
+ * and its message too.
59
+ * - "hook-unavailable" — the runner's hook server did not answer, so the
60
+ * agent's hooks could not be asked: the call is
61
+ * refused, no pause; unlike "fail-closed" the gate
62
+ * itself worked.
63
+ * Only approval-kind records carry the captured tool_input: a secret write's
64
+ * content must never be persisted, a capture-error's content is
65
+ * UNCLASSIFIED (the staging error means secret classification may never have
66
+ * run), and fail-closed has no state to classify against.
67
+ *
68
+ * Identity extraction runs on the SAME Node.js binary as the runner (its
69
+ * absolute path — process.execPath — is baked into the script at generation
70
+ * time), because the identity token must be byte-identical to the one the
71
+ * runner computes from the parsed stream event. The original grep/cut
72
+ * extraction is kept only as a best-effort fallback if that binary cannot run:
73
+ * grep's `"command":"[^"]*"` truncates at the first JSON-escaped quote, so for
74
+ * a shell command like `printf '%s' "x" > file` the fallback token will NOT
75
+ * match the runner's — the call is still denied (the gate holds) but the
76
+ * denial cannot be overlaid onto the real streamed tool call and a grant for
77
+ * it will not match on reinvocation. All policy decisions are pre-computed by
78
+ * the runner into the state file (and into this generated script); the hook
79
+ * only performs mechanical field extraction and string lookups — the policy
80
+ * itself is authored once in TypeScript (approval-policy.ts /
81
+ * approval-state.ts).
82
+ *
83
+ * Cross-taxonomy identity (the crux):
84
+ * The preToolUse hook and the SDK event stream name the same operation
85
+ * differently — the hook receives PascalCase `tool_name` (`Write` for any file
86
+ * create/edit, `Shell`, `Delete`) while the stream emits lowercase `event.name`
87
+ * (`edit`, `shell`, `delete`). They also name the salient argument differently
88
+ * (`file_path` in the hook input vs `path` in the stream). So the hook and the
89
+ * runner cannot correlate on the raw name. Instead both reduce a tool call to a
90
+ * canonical identity — `base64(category \n salient)` — where `category` is the
91
+ * approval category (`write`/`delete`/`shell`, baked into the case statement
92
+ * below from approval-policy.ts) and `salient` is the resource VALUE (the file
93
+ * path or shell command), which is identical on both sides. The runner mirrors
94
+ * this exactly in approval-state.ts (toolIdentity + grantToken), so a denial
95
+ * recorded here correlates to the streamed tool call, and an approval grant
96
+ * matches the agent's re-attempt on reinvocation.
97
+ *
98
+ * Content-exact identity (the sibling-hole fix): for a file edit the coarse
99
+ * (category, salient) is not enough — approving one edit to a file must not let
100
+ * a DIFFERENT edit to the SAME file ride through. So the hook ALSO computes a
101
+ * CONTENT token `base64(category \n salient \n contentDigest)`, where
102
+ * contentDigest is a sha256 over the edit content (mirror of file-tools.ts
103
+ * contentDigest; see buildContentDigestScript). It allows a built-in when EITHER
104
+ * the content token (a file edit approved with this exact content) OR the coarse
105
+ * token (shell/delete, or a content-less degrade) is granted, and records the
106
+ * content token as the denial identity. The runner grants the content token when
107
+ * it has the approved content (the persisted approval_content_digest), so a
108
+ * sibling edit re-gates; it degrades to the coarse grant only when the content is
109
+ * unrecoverable.
110
+ *
111
+ * Policy evaluation order (first match wins). The approval half is "gate the
112
+ * dangerous set, allow the rest", matching the native harness:
113
+ * 0. Scope guard: not the runner's own agent → allow (never touch the ledger)
114
+ * 1. Missing state file → deny (fail-closed)
115
+ * 1a. Tool lists (the state's `toolScope`, compiled by hook-scope.ts): a tool,
116
+ * MCP server tool or sub-agent type the agent's lists exclude → record
117
+ * kind "disabled", deny with the lists' refusal. Deliberately BEFORE the
118
+ * capture arms, autoApproveAll and every grant: a list says what the agent
119
+ * may call at all, so no approval posture may resurrect an excluded tool
120
+ * and no human is ever offered "approve" on one. The Node snippet only
121
+ * looks names up in the runner's tables; if it cannot run while the agent
122
+ * has lists, the call is denied (fail-closed).
123
+ * 0b. postToolUse event → the hook server's answer (the agent's hooks'
124
+ * context); on a turn with no hook server, nothing, before the pointer
125
+ * is even parsed
126
+ * 1b. subagentStart event that survived 1a → allow (no approval arm applies)
127
+ * 1h. The agent's hooks, when it has any (the hook server answers once per
128
+ * call; an MCP call on beforeMCPExecution): deny → record kind "hook",
129
+ * deny; ask → allow under autoApproveAll or an approved grant, record
130
+ * "unattended" under the unattended mode, else record "approval" (the
131
+ * hook's card); allow → the capture arms still run, then 1i; no decision
132
+ * → every arm below as without hooks; no answer → record
133
+ * "hook-unavailable", deny
134
+ * 1i. After the capture arms, a hook's allow → allow, with its context and
135
+ * any rewrite it made
136
+ * 1c. autoApproveAll (the pre-armed spec.auto_approve_all global bypass) →
137
+ * allow
138
+ * 2. beforeMCPExecution event → the server's tool listed in mcpDestructiveTools,
139
+ * or any tool of a server listed in mcpUnlistedServers:
140
+ * a. name token in approvedGrantTokens → allow (reinvocation grant)
141
+ * b. otherwise → record denial, deny
142
+ * (every other MCP tool falls through → allow; a server lease leaves its
143
+ * server out of both, so its tools fall through)
144
+ * 3. preToolUse event → gated built-in (category non-empty):
145
+ * 0. a git-tracked write or delete in capture mode, or with file review
146
+ * off → allow; a secret-like write left → record kind "secret", deny;
147
+ * any other write or delete with file review off → allow
148
+ * a. identity token in approvedGrantTokens → allow (reinvocation grant)
149
+ * b. category in leasedCategories → allow (run-lifetime scoped lease)
150
+ * c. otherwise → record denial, deny
151
+ * (read-only / ungated built-ins fall through → allow)
152
+ */
153
+ import { SALIENT_ARG_FIELDS, getBuiltInGatedCategories } from "./approval-policy.js";
154
+ import { SKILL_CONTENT_PATTERN } from "../../shared/skill-mount.js";
155
+ import { normalizeSubAgentType } from "../../shared/tool-lists.js";
156
+ import { CURSOR_HOOK_MCP_PREFIX, ENGINE_EXTRA_SCOPE_KEY, AGENT_SCOPE_KEY, READ_SCOPE_KEY, SCOPE_KEY_PREFIX, TOOL_NAME_PLACEHOLDER, } from "./hook-scope.js";
157
+ import { EDIT_OLD_FIELDS, EDIT_NEW_FIELDS, WRITE_CONTENT_FIELDS, } from "../../shared/file-tools.js";
158
+ import { buildObservationStagingScript, buildSecretClassifyScript, CAS_OBSERVATIONS_DIRNAME } from "./cas-observations.js";
159
+ import { HOOK_ASK_DIGEST_PREFIX } from "./approval-state.js";
160
+ import { UNLISTED_MCP_APPROVAL_MESSAGE } from "../../shared/approval-policy.js";
161
+ // Shown to the model when the gate denies a tool call. It must NOT teach the
162
+ // model to ask for permission in prose or to "stop and wait" — that framing
163
+ // makes the model narrate approval requests instead of invoking tools (the
164
+ // platform's approval surface is driven by tool invocation; see
165
+ // formatToolApprovalProtocol in prompt-builder.ts). Instead it tells the model
166
+ // the approval is automatic and that it should not retry or work around THIS
167
+ // action. Embedded verbatim into the generated hook script inside a
168
+ // single-quoted bash echo of a JSON object, so the text must contain no double
169
+ // quotes, apostrophes, or backslashes.
170
+ export const APPROVAL_REQUIRED_AGENT_MESSAGE = "This action has been submitted to the user for approval automatically; you " +
171
+ "do not need to ask for permission. This is the platform approval gate working " +
172
+ "as intended — it is not an error and not a Cursor misconfiguration, so never " +
173
+ "tell the user to change Cursor settings or enable hooks. Do not retry it or " +
174
+ "attempt a workaround for this action. The platform will resume you " +
175
+ "automatically after the user responds — continue with the rest of the task.";
176
+ // Shown to the model when the gate denies a tool call under UNATTENDED
177
+ // approval mode: the lane the run came through (a Slack or WhatsApp
178
+ // channel, a chat link's guest) has no approver, so — unlike APPROVAL_REQUIRED_AGENT_MESSAGE — this
179
+ // must NOT promise a resume: the deny is final for this turn and the model
180
+ // must adapt. It also enforces the anti-leak posture: the end user hears a
181
+ // plain-language explanation, never tool/approval vocabulary. Same embedding
182
+ // constraint (single-quoted bash echo of a JSON object): no double quotes,
183
+ // apostrophes, or backslashes. Mirrors the native gate skip message
184
+ // (middleware/approval-gate.ts unattendedSkipMessage) in intent.
185
+ export const UNATTENDED_SKIP_AGENT_MESSAGE = "This action was skipped automatically because it requires an approval that " +
186
+ "is not available in this conversation. This is the platform approval gate " +
187
+ "working as intended — it is not an error and not a Cursor misconfiguration. " +
188
+ "Do not retry it or attempt a workaround; it will not be resumed. Adapt your " +
189
+ "plan, and explain to the user in plain language what you could not do and " +
190
+ "what they can do instead — never mention tools, approvals, or platform " +
191
+ "mechanics.";
192
+ // Shown to the model when a secret-like gitignored write is hard-blocked.
193
+ // Unlike APPROVAL_REQUIRED_AGENT_MESSAGE, this must NOT promise a resume:
194
+ // the write is discarded and never captured for review, so the model must move on
195
+ // rather than wait or retry. Same embedding constraint (single-quoted bash echo
196
+ // of a JSON object): no double quotes, apostrophes, or backslashes.
197
+ export const SECRET_BLOCKED_AGENT_MESSAGE = "This file was blocked for security because its path matches a secret-like " +
198
+ "pattern Stigmer will not capture for review. Nothing was written. This is the " +
199
+ "platform safety gate working as intended — it is not an error and not a Cursor " +
200
+ "misconfiguration, so never tell the user to change Cursor settings or enable " +
201
+ "hooks. Do not retry this write or attempt a workaround; the write will not be " +
202
+ "applied. Continue with the rest of the task.";
203
+ // Shown to the model when the agent has tool lists but the hook could not
204
+ // evaluate them (the runner's Node binary would not run, or the state would
205
+ // not parse): the call is refused, since a list the hook cannot read must not
206
+ // widen to "every tool". Same embedding constraint (single-quoted bash echo of
207
+ // a JSON object): no double quotes, apostrophes, or backslashes.
208
+ const SCOPE_UNAVAILABLE_AGENT_MESSAGE = "This tool call was refused because the platform could not check it against " +
209
+ "this agent tool lists. Do not retry it; continue without it and tell the " +
210
+ "user plainly what you could not do.";
211
+ // Shown to the model when the agent has hooks but the gate could not reach
212
+ // them (the runner's hook server did not answer): a hook that cannot be
213
+ // asked must not be skipped, so the call is refused. Same embedding
214
+ // constraint (single-quoted bash echo of a JSON object): no double quotes,
215
+ // apostrophes, or backslashes.
216
+ const HOOKS_UNAVAILABLE_AGENT_MESSAGE = "This tool call was refused because the platform could not run this agent hooks " +
217
+ "for it. Do not retry it; continue without it and tell the user plainly what you " +
218
+ "could not do.";
219
+ /**
220
+ * Build the inline client that asks the runner's hook server about a call
221
+ * (`hook-server.ts`), run on the runner's own Node like the identity
222
+ * extractor. It reads the hook payload on stdin and takes the socket, the
223
+ * turn's token, the mode (`pre` or `post`), and the call's identity and
224
+ * coarse tokens as arguments. For `pre` it prints seven lines: the decision
225
+ * (`allow`, `deny`, `ask`, `refused`, `none`, or `error` when the server did
226
+ * not answer), the deciding plugin's slug in base64 (`=` for the agent's own
227
+ * block, empty when no hook decided), then base64 of the allow, deny,
228
+ * approval and unattended answers and of the message the ledger records.
229
+ * For `post` it prints the answer itself, `{}` when the server did not
230
+ * answer (a hook after the call can no longer stop it). No timeout of its
231
+ * own: Cursor's timeout on the hook entry bounds the wait. Authored as part
232
+ * of a single-quoted bash string, so it contains no single quotes.
233
+ */
234
+ export function buildHookClientScript() {
235
+ return [
236
+ `const net=require("net");`,
237
+ `const [sock,tok,mode,id,coarse,exact]=process.argv.slice(1);`,
238
+ `let input="";process.stdin.setEncoding("utf8");process.stdin.on("data",(c)=>{input+=c;});`,
239
+ `process.stdin.on("end",()=>{`,
240
+ `let payload=null;try{payload=JSON.parse(input);}catch(e){}`,
241
+ `let buf="",done=false;`,
242
+ `const fail=()=>{if(done)return;done=true;process.stdout.write(mode==="post"?"{}":"error");process.exit(0);};`,
243
+ `const b=(x)=>Buffer.from(String(x===undefined||x===null?"":x),"utf8").toString("base64");`,
244
+ `const c=net.createConnection(sock);`,
245
+ `c.setEncoding("utf8");`,
246
+ `c.on("error",fail);`,
247
+ `c.on("connect",()=>{c.write(JSON.stringify({token:tok,mode:mode,payload:payload,identity:id,coarse:coarse,exact:exact})+"\\n");});`,
248
+ `c.on("data",(d)=>{buf+=d;const i=buf.indexOf("\\n");if(i<0)return;`,
249
+ `let r=null;try{r=JSON.parse(buf.slice(0,i));}catch(e){return fail();}`,
250
+ `if(!r||typeof r!=="object"||r.error!==undefined)return fail();`,
251
+ `done=true;c.end();`,
252
+ `if(mode==="post"){process.stdout.write(typeof r.response==="string"?r.response:"{}");process.exit(0);}`,
253
+ `const h=typeof r.hook==="string"?(r.hook===""?"=":b(r.hook)):"";`,
254
+ `process.stdout.write([String(r.decision||"error"),h,b(r.allow),b(r.deny),b(r.approval),b(r.unattended),b(r.message)].join("\\n"));process.exit(0);});`,
255
+ `c.on("end",fail);`,
256
+ `});`,
257
+ ].join("");
258
+ }
259
+ /**
260
+ * Build the bash `case` arms that map an incoming hook `tool_name` to its
261
+ * canonical approval category. Generated from approval-policy.ts so the hook and
262
+ * the runner never disagree on which built-ins are gated or how they categorize.
263
+ */
264
+ function buildCategoryCaseArms() {
265
+ const byCategory = new Map();
266
+ for (const [name, category] of getBuiltInGatedCategories()) {
267
+ const names = byCategory.get(category) ?? [];
268
+ names.push(name);
269
+ byCategory.set(category, names);
270
+ }
271
+ const arms = [];
272
+ for (const [category, names] of byCategory) {
273
+ const pattern = names.map((n) => `"${n}"`).join("|");
274
+ arms.push(` ${pattern}) CATEGORY="${category}" ;;`);
275
+ }
276
+ return arms.join("\n");
277
+ }
278
+ /**
279
+ * Build the inline content-digest extractor — a BYTE-IDENTICAL MIRROR of
280
+ * {@link file://../../shared/file-tools.ts} `contentDigest()`.
281
+ *
282
+ * Computes the same `sha256(JSON.stringify(["w", content]))` /
283
+ * `sha256(JSON.stringify(["e", old, new]))` from the parsed tool_input `a`,
284
+ * using the SAME union field lists injected from file-tools.ts (so the
285
+ * file_path/path & content/contents cross-layer name divergence is normalized
286
+ * identically) and the SAME Node binary as the runner — so the hook-side and
287
+ * runner-side digests agree. Any change to the format here or in
288
+ * file-tools.ts MUST be mirrored in the other. Empty (`dig===""`) for a tool
289
+ * with no edit content (shell/delete/read/MCP).
290
+ *
291
+ * Authored as part of a single-quoted bash string, so the JS must not contain
292
+ * single quotes (JSON.stringify emits double quotes).
293
+ */
294
+ function buildContentDigestScript() {
295
+ const wc = JSON.stringify(WRITE_CONTENT_FIELDS);
296
+ const eo = JSON.stringify(EDIT_OLD_FIELDS);
297
+ const en = JSON.stringify(EDIT_NEW_FIELDS);
298
+ return [
299
+ `const pick=(fl)=>{for(const f of fl){const v=a[f];if(typeof v==="string")return v;}return null;};`,
300
+ `const sha=(x)=>require("crypto").createHash("sha256").update(x,"utf8").digest("hex");`,
301
+ `let dig="";`,
302
+ `const _wc=pick(${wc});`,
303
+ `if(_wc!==null){dig=sha(JSON.stringify(["w",_wc]));}`,
304
+ `else{const _o=pick(${eo}),_n=pick(${en});if(_o!==null||_n!==null){dig=sha(JSON.stringify(["e",_o===null?"":_o,_n===null?"":_n]));}}`,
305
+ ].join("");
306
+ }
307
+ /**
308
+ * Build the inline tool-lists evaluator (policy arm 1a), part of the identity
309
+ * extractor below. It reads the turn's state file (`process.argv[1]`), decodes
310
+ * `toolScope` (`encodeHookToolScope`) and looks the call up in the tables `hook-scope.ts` compiled from
311
+ * the runner's `ToolScope`: it decides nothing those tables do not already
312
+ * say, so the list rules stay in `shared/tool-lists.ts` alone. Sets:
313
+ * - `sv`: "" (in scope, or no lists), "E" (could not evaluate), else
314
+ * base64(JSON) of the deny response, the refusal naming the tool;
315
+ * - `stk`: the ledger token a refusal is recorded under, the scope token
316
+ * (`approval-state.ts` `scopeRefusalToken`): keyed by the built-in's
317
+ * `scopeKey` (every engine extra shares one), by `server/tool` for an MCP
318
+ * call (the `mcpToolKey` form), by the `Task` key for a sub-agent start;
319
+ * and, for a tool the lists may exclude only in part (`READ_SCOPE_KEY`,
320
+ * `AGENT_SCOPE_KEY`), discriminated by the call: the path as given, the
321
+ * normalized sub-agent type;
322
+ * - `smsg`: base64 of the refusal text, which the ledger carries so the turn
323
+ * boundary can write the very words the model read onto the refused row.
324
+ * An excluded `Read` is let through only when the file's REAL path lies
325
+ * inside `readRoot` (the platform dir's real path, "" on a turn with no
326
+ * platform link), the path resolved against the payload's `cwd`, else the
327
+ * baked workspace root (`process.argv[2]`); a missing file is refused. Under
328
+ * lists that deny `Skill`, a `Read` whose real path, relative to `skillRoot`
329
+ * (the platform dir's real path), matches `SKILL_CONTENT_PATTERN` (its
330
+ * source and flags embedded) is refused whether or not `Read` is in scope;
331
+ * the real path is the filesystem's own spelling (`realpathSync.native`),
332
+ * since a case-insensitive filesystem opens `skills/` under spellings that
333
+ * lower case does not fold (U+017F, the Kelvin sign), and both paths are
334
+ * then compared in lower case, since the pattern holds a case-insensitive
335
+ * filesystem's view of the same file. A
336
+ * `Task` call naming its `subagent_type` is held to `Agent(type, …)` here as
337
+ * well as at `subagentStart`, refused under the same discriminator. Both are a
338
+ * second line for a runtime that fires them, never the guard: the 1.0.31
339
+ * local runtime fires neither for a `task` call (live probe, 2026-10-05), so
340
+ * an `Agent(type, …)` type list is refused at setup (`turn-setup.ts`). A
341
+ * sub-agent type is normalized by the source of `normalizeSubAgentType`
342
+ * itself, embedded, so the hook and the resolver share one rule. Expects `t`, `name`, `a`, `s`, `b`, `ev`
343
+ * and `srv` in scope.
344
+ */
345
+ function buildScopeEvalScript() {
346
+ const placeholder = JSON.stringify(TOOL_NAME_PLACEHOLDER);
347
+ const mcpPrefix = JSON.stringify(CURSOR_HOOK_MCP_PREFIX);
348
+ const keyPrefix = JSON.stringify(SCOPE_KEY_PREFIX);
349
+ const extraKey = JSON.stringify(ENGINE_EXTRA_SCOPE_KEY);
350
+ const readKey = JSON.stringify(READ_SCOPE_KEY);
351
+ const agentKey = JSON.stringify(AGENT_SCOPE_KEY);
352
+ const skillPattern = JSON.stringify(SKILL_CONTENT_PATTERN.source);
353
+ const skillFlags = JSON.stringify(SKILL_CONTENT_PATTERN.flags);
354
+ return [
355
+ `let sv="",stk="",smsg="",disc="";`,
356
+ `try{`,
357
+ `const st=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"));`,
358
+ `const sc=st.toolListsRestricted===true?JSON.parse(Buffer.from(String(st.toolScope),"base64").toString("utf8")):null;`,
359
+ `if(sc&&sc.restricted===true){`,
360
+ `const own=(o,k)=>o!==null&&typeof o==="object"&&Object.prototype.hasOwnProperty.call(o,k);`,
361
+ `let ok=true,label=name,key=name;`,
362
+ `const nt=(${normalizeSubAgentType.toString()});`,
363
+ `const typeOk=(lt)=>own(sc.subAgentTypes.types,lt)?sc.subAgentTypes.types[lt]===true:sc.subAgentTypes.otherTypes===true;`,
364
+ `if(ev==="subagentStart"){`,
365
+ `const ty=typeof t.subagent_type==="string"?t.subagent_type:"";`,
366
+ `const lt=nt(ty);`,
367
+ `ok=typeOk(lt);`,
368
+ `label="Agent("+ty+")";`,
369
+ `disc=lt;`,
370
+ `key=own(sc.builtins,"Task")?sc.builtins.Task.key:"Task";`,
371
+ `}else if(ev==="beforeMCPExecution"){`,
372
+ `const sm=own(sc.mcp.servers,srv)?sc.mcp.servers[srv]:null;`,
373
+ `ok=sm?(own(sm.tools,name)?sm.tools[name]===true:sm.otherTools===true):sc.mcp.otherServers===true;`,
374
+ `key=srv+"/"+name;`,
375
+ `}else if(!name.startsWith(${mcpPrefix})){`,
376
+ `const e=own(sc.builtins,name)?sc.builtins[name]:null;`,
377
+ `ok=e?e.allowed===true:sc.otherBuiltins===true;`,
378
+ `key=e?e.key:${extraKey};`,
379
+ `if(key===${readKey})disc=s;`,
380
+ `if(ok&&key===${agentKey}&&typeof a.subagent_type==="string"&&a.subagent_type!==""){`,
381
+ `const lt=nt(a.subagent_type);`,
382
+ `if(!typeOk(lt)){ok=false;label="Agent("+a.subagent_type+")";disc=lt;}`,
383
+ `}`,
384
+ `if(!ok&&key===${readKey}&&s&&typeof sc.readRoot==="string"&&sc.readRoot!==""){`,
385
+ `const pth=require("path");`,
386
+ `const base=typeof t.cwd==="string"&&t.cwd?t.cwd:(process.argv[2]||"/");`,
387
+ `try{ok=require("fs").realpathSync(pth.resolve(base,s)).startsWith(sc.readRoot+pth.sep);}catch(e){ok=false;}`,
388
+ `}`,
389
+ `if(ok&&key===${readKey}&&s&&typeof sc.skillRoot==="string"&&sc.skillRoot!==""){`,
390
+ `const pth=require("path");`,
391
+ `const base=typeof t.cwd==="string"&&t.cwd?t.cwd:(process.argv[2]||"/");`,
392
+ `try{const rel=pth.relative(sc.skillRoot.toLowerCase(),require("fs").realpathSync.native(pth.resolve(base,s)).toLowerCase()).split(pth.sep).join("/");`,
393
+ `if(!rel.startsWith("../")&&rel!==".."&&!pth.isAbsolute(rel)&&new RegExp(${skillPattern},${skillFlags}).test(rel))ok=false;}catch(e){}`,
394
+ `}`,
395
+ `}`,
396
+ `if(!ok){`,
397
+ `const msg=String(sc.refusal).split(${placeholder}).join(label);`,
398
+ `sv=b(JSON.stringify(ev==="subagentStart"?{permission:"deny",user_message:msg}:{permission:"deny",agent_message:msg,user_message:msg}));`,
399
+ `stk=b(${keyPrefix}+key+"\\n"+disc);`,
400
+ `smsg=b(msg);`,
401
+ `}`,
402
+ `}`,
403
+ `}catch(e){sv="E";stk="";smsg="";}`,
404
+ ].join("");
405
+ }
406
+ /**
407
+ * Build the inline Node.js identity extractor embedded in the hook script.
408
+ *
409
+ * Parses the hook's stdin JSON properly (the bash fallback's grep truncates
410
+ * string values at the first escaped quote) and emits TWELVE lines: tool_name,
411
+ * canonical category, coarse identity token, MCP name-token, hook_event_name
412
+ * (the event discriminator: `preToolUse` for built-ins, `beforeMCPExecution`
413
+ * for MCP), base64(JSON(tool_input)) — the authoritative pre-execution args the
414
+ * runner overlays onto the gated tool call for the approval preview — the
415
+ * CONTENT token (base64(category \n salient \n contentDigest), empty when the
416
+ * tool has no edit content), base64(salient), and mcp_server_name (the MCP
417
+ * server slug the beforeMCPExecution payload carries; empty for built-ins),
418
+ * then the tool-lists verdict, its ledger token and its refusal text
419
+ * ({@link buildScopeEvalScript}).
420
+ * It runs with two arguments: the turn's state file and the baked workspace
421
+ * root. The token encodings must stay byte-identical to
422
+ * grantToken()/contentToken()/scopeRefusalToken() in approval-state.ts.
423
+ *
424
+ * Authored as a single-quoted bash string, so the JS must not contain single
425
+ * quotes. The category map, salient field list, and edit/content field lists are
426
+ * baked from approval-policy.ts / file-tools.ts — the same source the runner
427
+ * uses — so the two sides can never disagree.
428
+ */
429
+ function buildNodeIdentityScript() {
430
+ const categoryMap = {};
431
+ for (const [name, category] of getBuiltInGatedCategories()) {
432
+ categoryMap[name] = category;
433
+ }
434
+ const categories = JSON.stringify(categoryMap);
435
+ const fields = JSON.stringify(SALIENT_ARG_FIELDS);
436
+ return [
437
+ `const t=JSON.parse(require("fs").readFileSync(0,"utf8"));`,
438
+ `const name=typeof t.tool_name==="string"?t.tool_name:"";`,
439
+ `const cat=(${categories})[name]||"";`,
440
+ // tool_input is an object for built-ins (preToolUse) but a JSON STRING for
441
+ // MCP tools (beforeMCPExecution). Parse the string form so the captured
442
+ // input is the same object shape on both paths.
443
+ `let a={};`,
444
+ `if(t.tool_input&&typeof t.tool_input==="object"){a=t.tool_input;}`,
445
+ `else if(typeof t.tool_input==="string"){try{const p=JSON.parse(t.tool_input);if(p&&typeof p==="object")a=p;}catch(e){}}`,
446
+ `let s="";`,
447
+ `for(const f of ${fields}){const v=a[f];if(typeof v==="string"&&v){s=v;break;}}`,
448
+ `const b=(x)=>Buffer.from(x,"utf8").toString("base64");`,
449
+ // Content digest of the edit (mirror of file-tools.ts contentDigest); `dig`
450
+ // is "" for a non-edit tool, in which case the content token (line 7) is "".
451
+ buildContentDigestScript(),
452
+ `const ev=typeof t.hook_event_name==="string"?t.hook_event_name:"";`,
453
+ `const srv=typeof t.mcp_server_name==="string"?t.mcp_server_name:"";`,
454
+ buildScopeEvalScript(),
455
+ // Line 6 is base64(JSON(tool_input)): the AUTHORITATIVE pre-execution args
456
+ // the runner overlays onto the gated tool call so the approval card can show
457
+ // the proposed change before the user approves. Base64 keeps the bash side
458
+ // free of quoting/escaping concerns even for large multi-line file content.
459
+ // Line 7 is the CONTENT token (empty when no digest) — the exact-identity
460
+ // grant the runner authorizes for a file edit. Line 8 is base64(salient) —
461
+ // the raw resource value (file path / command) capture mode needs to run
462
+ // `git check-ignore` on a file path; base64 keeps newlines/quotes out of the
463
+ // line-oriented bash parse. Line 9 is mcp_server_name — the server half of
464
+ // the destructive-tool key (a bare slug, never quoted/escaped, so it rides
465
+ // as a plain line).
466
+ // Lines 10 to 12 are the tool-lists verdict, its ledger token and its
467
+ // refusal text (buildScopeEvalScript), each a single base64 line or a
468
+ // sentinel.
469
+ // A call's key is its approval category, else the hook's name for the
470
+ // tool (a hook may ask on any tool); an MCP call's is `server/tool`.
471
+ // Line 13 is the token an approval of a hook's ask is granted under when
472
+ // the call has no file content: its identity and the digest of its whole
473
+ // input (mirror of approval-state.ts hookAskDigest).
474
+ `const key=cat||name;`,
475
+ `const hk=ev==="beforeMCPExecution"?srv+"/"+name:key;`,
476
+ `const hs=ev==="beforeMCPExecution"?"":s;`,
477
+ `const hd="${HOOK_ASK_DIGEST_PREFIX}"+require("crypto").createHash("sha256").update(JSON.stringify(a),"utf8").digest("hex");`,
478
+ `process.stdout.write(name+"\\n"+cat+"\\n"+b(key+"\\n"+s)+"\\n"+b(srv+"/"+name+"\\n")+"\\n"+ev+"\\n"+b(JSON.stringify(a))+"\\n"+(dig?b(key+"\\n"+s+"\\n"+dig):"")+"\\n"+b(s)+"\\n"+srv+"\\n"+sv+"\\n"+stk+"\\n"+smsg+"\\n"+b(hk+"\\n"+hs+"\\n"+hd));`,
479
+ ].join("");
480
+ }
481
+ /**
482
+ * Generates the STABLE bash hook script content.
483
+ *
484
+ * The script is STABLE across executions in a runner process — its only inputs
485
+ * are the absolute path of the active-turn pointer (and the runner's Node
486
+ * binary), both constant for a given workspace. This is deliberate and
487
+ * load-bearing: the Cursor SDK loads `<workspace>/.cursor/hooks.json` (the hook
488
+ * script PATH) ONCE per runner process and caches it, ignoring later
489
+ * per-execution rewrites. A per-session script with per-session baked paths
490
+ * therefore gets cached at the FIRST execution and reused for every later one,
491
+ * recording their denials into the FIRST session's ledger while each later runner
492
+ * reads its own (empty) ledger and silently completes — the no-approval-button /
493
+ * "execution completed" regression. Keeping the script stable and resolving the
494
+ * CURRENT turn's artifacts from the pointer (which bash re-reads every
495
+ * invocation; see {@link ActiveTurnPointer}/writeActiveTurnPointer) makes a
496
+ * long-lived multi-session runner correct.
497
+ *
498
+ * From the pointer the script reads the current turn's approval-state file (the
499
+ * single source of truth for the dynamic inputs: autoApproveAll, leasedCategories,
500
+ * mcpDestructiveTools, toolScope, approvedGrantTokens), denial ledger, and
501
+ * runner PID. The
502
+ * static policy (which built-ins are gated, their categories, the salient arg
503
+ * fields) is baked at generation time from approval-policy.ts.
504
+ *
505
+ * The identity token encoding (`base64(key \n salient)`) must stay byte-identical
506
+ * to grantToken() in approval-state.ts.
507
+ *
508
+ * Scope guard (the crux of issue #173): the Cursor SDK loads project hooks from
509
+ * `<workspace>/.cursor/hooks.json`, the SAME per-repo surface every Cursor client
510
+ * reads. When a session runs against the user's real repo, the user's own
511
+ * interactive Cursor IDE would otherwise load and run this hook too — gating the
512
+ * IDE, polluting the denial ledger, and (in multi-root windows) failing closed.
513
+ * We make the gate apply ONLY to the runner's own agent by checking, on every
514
+ * invocation, whether the runner PID (FROM THE POINTER) is an ancestor of the
515
+ * hook process. The SDK runs hooks in-process via child_process, so the runner's
516
+ * own agent (and its delegated sub-agents) spawn the hook as a descendant of the
517
+ * runner; any other Cursor client spawns it under a different process tree. A
518
+ * non-descendant invocation is allowed immediately and never touches the ledger.
519
+ * Combined with pointer teardown, a leftover hooks.json is self-neutralizing:
520
+ * once the turn ends (pointer removed) or the runner exits (PID dead), no
521
+ * invocation gates, so the gate is inert.
522
+ */
523
+ /**
524
+ * The question for a tool of a server whose tools could not be listed, as a
525
+ * bash double-quoted string body with the tool's name spliced in at
526
+ * `{{tool_name}}`. The message holds no double quote, backslash, `$` or
527
+ * backtick, so it is embedded as it is.
528
+ */
529
+ function unlistedMessage(toolNameExpression) {
530
+ return UNLISTED_MCP_APPROVAL_MESSAGE.replace("{{tool_name}}", toolNameExpression);
531
+ }
532
+ export function generateHookScript(activePointerPath, workspaceRoot = "") {
533
+ const salientFields = SALIENT_ARG_FIELDS.join(" ");
534
+ const categoryCaseArms = buildCategoryCaseArms();
535
+ const nodeIdentityScript = buildNodeIdentityScript();
536
+ const observationStagingScript = buildObservationStagingScript();
537
+ const secretClassifyScript = buildSecretClassifyScript();
538
+ const hookClientScript = buildHookClientScript();
539
+ const nodeBin = process.execPath;
540
+ return `#!/bin/bash
541
+ # Stigmer HITL approval hook for Cursor (preToolUse + beforeMCPExecution).
542
+ # Generated by cursor-runner — do not edit manually.
543
+ #
544
+ # Reads a tool call from stdin (JSON), checks the approval state file, returns a
545
+ # permission decision on stdout (JSON). Branches on hook_event_name: MCP tools
546
+ # are gated on beforeMCPExecution, built-ins on preToolUse (preToolUse does not
547
+ # enforce MCP), sub-agent types on subagentStart. On a deny, appends the call's
548
+ # canonical identity token to the denial ledger so the runner can mark the
549
+ # gated tool call as WAITING_APPROVAL.
550
+ # See hook-script.ts for the cross-taxonomy identity design.
551
+
552
+ set -euo pipefail
553
+
554
+ INPUT=$(cat)
555
+
556
+ NODE_BIN="${nodeBin}"
557
+ ACTIVE_FILE="${activePointerPath}"
558
+
559
+ # --- 0b, at once: after a call on a turn with no hooks ----------------------
560
+ # postToolUse is registered for every turn; a turn whose pointer names no hook
561
+ # server has nothing to add, so it answers before any Node or scope walk.
562
+ case "$INPUT" in
563
+ *'"hook_event_name":"postToolUse"'*)
564
+ if [ ! -f "$ACTIVE_FILE" ] || ! grep -q '"hookSocket":"[^"]' "$ACTIVE_FILE" 2>/dev/null; then
565
+ echo '{}'
566
+ exit 0
567
+ fi
568
+ ;;
569
+ esac
570
+ # Baked workspace root for capture-mode's gitignore check (empty in unit tests
571
+ # that don't exercise capture mode; the check then falls back to the path's dir).
572
+ GIT_ROOT="${workspaceRoot}"
573
+
574
+ # --- Resolve the CURRENT turn from the runner-written pointer ----------------
575
+ # The Cursor SDK caches .cursor/hooks.json (the hook script PATH) for the runner
576
+ # process, so THIS script is stable across executions and the per-turn pointer
577
+ # (active.json) — which bash re-reads on every invocation — is the only thing
578
+ # that changes. It names the CURRENT turn's approval-state, denial ledger, and
579
+ # runner PID. This indirection is what makes a long-lived runner correct: a
580
+ # per-session script baked with per-session paths would be cached at the FIRST
581
+ # execution and reused for every later one, recording their denials to the FIRST
582
+ # session's ledger while each later runner reads its own empty ledger and
583
+ # silently completes (the no-approval-button / "completed" regression).
584
+ #
585
+ # A missing/garbled pointer means no active Stigmer turn (between turns, after
586
+ # teardown, or a dead runner) -> allow (inert), matching the
587
+ # leftover-hooks.json-is-inert invariant (issue #173).
588
+ if [ ! -f "$ACTIVE_FILE" ]; then
589
+ echo '{"permission":"allow"}'
590
+ exit 0
591
+ fi
592
+ PTR=$(ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e 'const p=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"));process.stdout.write((p.stateFile||"")+"\\n"+(p.ledgerFile||"")+"\\n"+((p.runnerPid==null)?"":String(p.runnerPid))+"\\n"+(p.hookSocket||"")+"\\n"+(p.hookToken||""))' "$ACTIVE_FILE" 2>/dev/null || true)
593
+ if [ -n "$PTR" ]; then
594
+ STATE_FILE=$(printf '%s\\n' "$PTR" | sed -n 1p)
595
+ LEDGER_FILE=$(printf '%s\\n' "$PTR" | sed -n 2p)
596
+ RUNNER_PID=$(printf '%s\\n' "$PTR" | sed -n 3p)
597
+ HOOK_SOCKET=$(printf '%s\\n' "$PTR" | sed -n 4p)
598
+ HOOK_TOKEN=$(printf '%s\\n' "$PTR" | sed -n 5p)
599
+ else
600
+ # Node unavailable: the pointer holds plain ~/.stigmer paths, an integer
601
+ # and a hex token (no JSON-escaped quotes), so grep/cut is reliable here.
602
+ STATE_FILE=$(grep -o '"stateFile":"[^"]*"' "$ACTIVE_FILE" | head -1 | cut -d'"' -f4 || true)
603
+ LEDGER_FILE=$(grep -o '"ledgerFile":"[^"]*"' "$ACTIVE_FILE" | head -1 | cut -d'"' -f4 || true)
604
+ RUNNER_PID=$(grep -o '"runnerPid":[0-9]*' "$ACTIVE_FILE" | head -1 | cut -d: -f2 || true)
605
+ HOOK_SOCKET=$(grep -o '"hookSocket":"[^"]*"' "$ACTIVE_FILE" | head -1 | cut -d'"' -f4 || true)
606
+ HOOK_TOKEN=$(grep -o '"hookToken":"[^"]*"' "$ACTIVE_FILE" | head -1 | cut -d'"' -f4 || true)
607
+ fi
608
+ if [ -z "$RUNNER_PID" ]; then
609
+ # Pointer unreadable -> no scope owner to gate for; stay inert.
610
+ echo '{"permission":"allow"}'
611
+ exit 0
612
+ fi
613
+
614
+ # --- Scope guard: gate ONLY the runner's own agent (issue #173) -------------
615
+ # The Cursor SDK runs hooks in-process, so the runner's own agent invocations
616
+ # spawn this script as a DESCENDANT of the runner process (RUNNER_PID); the
617
+ # user's interactive IDE — sharing the same repo .cursor/hooks.json — spawns it
618
+ # under a different process tree. Walk the parent-PID chain: if the runner is an
619
+ # ancestor, apply the gate; otherwise allow immediately and DO NOT write the
620
+ # ledger (so foreign tool calls never appear as phantom approvals). Pure bash so
621
+ # it works even when the Node identity binary below is unavailable.
622
+ __stigmer_ppid() {
623
+ _p="$1"
624
+ if [ -r "/proc/$_p/status" ]; then
625
+ awk '/^PPid:/{print $2; exit}' "/proc/$_p/status" 2>/dev/null || true
626
+ else
627
+ ps -o ppid= -p "$_p" 2>/dev/null | tr -d ' ' || true
628
+ fi
629
+ }
630
+ __stigmer_is_own_agent() {
631
+ _cur="$$"
632
+ _i=0
633
+ while [ "$_i" -lt 64 ]; do
634
+ if [ -z "$_cur" ]; then return 1; fi
635
+ if [ "$_cur" = "$RUNNER_PID" ]; then return 0; fi
636
+ if [ "$_cur" = "1" ] || [ "$_cur" = "0" ]; then return 1; fi
637
+ _cur="$(__stigmer_ppid "$_cur")"
638
+ _i=$((_i + 1))
639
+ done
640
+ return 1
641
+ }
642
+ if ! __stigmer_is_own_agent; then
643
+ echo '{"permission":"allow"}'
644
+ exit 0
645
+ fi
646
+
647
+ # --- Capture-mode helper: is a path gitignored? -----------------------------
648
+ # In capture mode the runner snapshots the working tree with git and reconciles
649
+ # it to the user's per-file decisions on resume, but a gitignored path (e.g.
650
+ # .env, build output) is invisible to that snapshot — so it can be neither
651
+ # captured for review nor reverted on reject. Such writes/deletes therefore stay
652
+ # on the deny-gate. Returns 0 (true) when the path is ignored. A non-git context
653
+ # or a missing path returns non-zero (treated as not-ignored -> allow).
654
+ __stigmer_is_gitignored() {
655
+ _p="$1"
656
+ [ -z "$_p" ] && return 1
657
+ if [ -n "$GIT_ROOT" ]; then
658
+ git -C "$GIT_ROOT" check-ignore -q -- "$_p" 2>/dev/null
659
+ else
660
+ git -C "$(dirname "$_p")" check-ignore -q -- "$_p" 2>/dev/null
661
+ fi
662
+ }
663
+
664
+ # --- Canonical identity: tool_name / category / identity token / MCP token ---
665
+ # Computed by the same Node.js binary that runs the cursor-runner (absolute path
666
+ # baked at generation time) so JSON string values — file paths and especially
667
+ # shell commands containing quotes, newlines, or unicode escapes — decode to the
668
+ # exact bytes the runner sees in the stream event. ELECTRON_RUN_AS_NODE makes
669
+ # the invocation safe when the runner is embedded in an Electron app (where
670
+ # process.execPath is the Electron binary). NODE_BIN is defined once near the top
671
+ # (it also parses the active-turn pointer).
672
+ IDENTITY=$(printf '%s' "$INPUT" | ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e '${nodeIdentityScript}' "$STATE_FILE" "$GIT_ROOT" 2>/dev/null || true)
673
+ if [ -n "$IDENTITY" ]; then
674
+ TOOL_NAME=$(printf '%s\\n' "$IDENTITY" | sed -n 1p)
675
+ CATEGORY=$(printf '%s\\n' "$IDENTITY" | sed -n 2p)
676
+ TOKEN=$(printf '%s\\n' "$IDENTITY" | sed -n 3p)
677
+ MCP_TOKEN=$(printf '%s\\n' "$IDENTITY" | sed -n 4p)
678
+ HOOK_EVENT=$(printf '%s\\n' "$IDENTITY" | sed -n 5p)
679
+ # base64(JSON(tool_input)) — the authoritative args the runner overlays onto
680
+ # the gated tool call. A single unwrapped base64 line (Node does not wrap), so
681
+ # sed reads it whole even for large file content.
682
+ INPUT_B64=$(printf '%s\\n' "$IDENTITY" | sed -n 6p)
683
+ # Content token (base64 of category\\nsalient\\ndigest), empty for a non-edit
684
+ # tool. The exact-identity grant the runner authorizes for a file edit.
685
+ CONTENT_TOKEN=$(printf '%s\\n' "$IDENTITY" | sed -n 7p)
686
+ # Raw salient (base64) — the file path / command. Capture mode decodes it to
687
+ # run git check-ignore on a file path.
688
+ SALIENT=$(printf '%s\\n' "$IDENTITY" | sed -n 8p | base64 -d 2>/dev/null || true)
689
+ # MCP server slug (beforeMCPExecution payloads only; empty for built-ins).
690
+ MCP_SERVER=$(printf '%s\\n' "$IDENTITY" | sed -n 9p)
691
+ # Tool-lists verdict: empty (in scope), E (could not evaluate), or the
692
+ # base64 deny response; and the ledger token a refusal is recorded under.
693
+ SCOPE_VERDICT=$(printf '%s\\n' "$IDENTITY" | sed -n 10p)
694
+ SCOPE_TOKEN=$(printf '%s\\n' "$IDENTITY" | sed -n 11p)
695
+ SCOPE_MESSAGE=$(printf '%s\\n' "$IDENTITY" | sed -n 12p)
696
+ HOOK_ARGS_TOKEN=$(printf '%s\\n' "$IDENTITY" | sed -n 13p)
697
+ else
698
+ # Fallback when the Node binary cannot run: grep/cut extraction. Best-effort
699
+ # only — '"field":"[^"]*"' truncates at the first JSON-escaped quote, so the
700
+ # token may not match the runner's for values containing escapes. Gating still
701
+ # holds (deny goes out); only denial correlation and grant precision degrade.
702
+ # Every extraction ends with '|| true': under 'set -e' a non-matching grep
703
+ # would otherwise abort the script and emit no decision.
704
+ TOOL_NAME=$(echo "$INPUT" | grep -o '"tool_name":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
705
+ HOOK_EVENT=$(echo "$INPUT" | grep -o '"hook_event_name":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
706
+ # Server slugs are plain identifiers (no JSON-escaped quotes), so the grep
707
+ # fallback extracts mcp_server_name reliably.
708
+ MCP_SERVER=$(echo "$INPUT" | grep -o '"mcp_server_name":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
709
+ SALIENT=""
710
+ for field in ${salientFields}; do
711
+ v=$(echo "$INPUT" | grep -o "\\"$field\\":\\"[^\\"]*\\"" | head -1 | cut -d'"' -f4 || true)
712
+ if [ -n "$v" ]; then SALIENT="$v"; break; fi
713
+ done
714
+ CATEGORY=""
715
+ case "$TOOL_NAME" in
716
+ ${categoryCaseArms}
717
+ *) CATEGORY="" ;;
718
+ esac
719
+ TOKEN=$(printf '%s\\n%s' "$CATEGORY" "$SALIENT" | base64 | tr -d '\\n')
720
+ MCP_TOKEN=$(printf '%s/%s\\n' "$MCP_SERVER" "$TOOL_NAME" | base64 | tr -d '\\n')
721
+ # The grep fallback cannot reliably capture full multi-line tool_input, so the
722
+ # gated call degrades to today's stream-recovered args (no authoritative input)
723
+ # and cannot compute a content digest — the coarse token is the only identity.
724
+ INPUT_B64=""
725
+ CONTENT_TOKEN=""
726
+ # Without Node the tool lists cannot be evaluated; the scope arm refuses
727
+ # every call when the agent has lists (fail-closed).
728
+ SCOPE_VERDICT="E"
729
+ SCOPE_TOKEN=""
730
+ SCOPE_MESSAGE=""
731
+ HOOK_ARGS_TOKEN=""
732
+ fi
733
+ # The single identity a deny is recorded under: content-exact when the input
734
+ # carried edit content, else coarse — the same PRIMARY-token choice the runner
735
+ # grants on approval (approval-state.ts primaryToken).
736
+ if [ -n "$CONTENT_TOKEN" ]; then
737
+ PRIMARY_TOKEN="$CONTENT_TOKEN"
738
+ else
739
+ PRIMARY_TOKEN="$TOKEN"
740
+ fi
741
+
742
+ # --- 0b. After a call: what the agent's hooks hand back (postToolUse) ---
743
+ # Registered only for an agent with hooks that run after a call. The runner's
744
+ # hook server (hook-server.ts) runs them and answers with the context they
745
+ # hand the model. A call that already ran cannot be stopped, so a server that
746
+ # does not answer adds nothing.
747
+ if [ "$HOOK_EVENT" = "postToolUse" ]; then
748
+ if [ -n "$HOOK_SOCKET" ]; then
749
+ printf '%s' "$INPUT" | ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e '${hookClientScript}' "$HOOK_SOCKET" "$HOOK_TOKEN" post "" "" 2>/dev/null || printf '{}'
750
+ echo
751
+ else
752
+ echo '{}'
753
+ fi
754
+ exit 0
755
+ fi
756
+
757
+ # Append a denial record to the ledger: $1 = identity token, $2 = kind (the
758
+ # attribution taxonomy — see the module doc in hook-script.ts). EVERY deny arm
759
+ # below records, so the ledger is the complete record of what THIS hook blocked
760
+ # and the runner can tell its own denials from a foreign hook's (issue #205).
761
+ # Best-effort: a ledger write failure must never abort the decision (the deny
762
+ # still goes out on stdout). ONLY approval-kind records carry the captured
763
+ # tool_input (secret or unclassified content must never be persisted);
764
+ # input is base64(JSON(tool_input)) — the authoritative pre-execution args the
765
+ # runner overlays for the approval preview (empty on the grep fallback path).
766
+ # A tool-list refusal passes $3, base64 of the refusal text the model read,
767
+ # which the turn boundary writes onto the refused row. Written with printf (a builtin, so no ARG_MAX limit) because the input can be
768
+ # a large multi-MB file body. Defined BEFORE the first deny arm: bash resolves
769
+ # function calls at execution time, and under 'set -euo pipefail' with our
770
+ # failClosed hooks.json registration a call-before-define would abort with no
771
+ # decision and block EVERY tool.
772
+ record_denial() {
773
+ _extra=""
774
+ if [ -n "\${3:-}" ]; then _extra="$_extra"',"message":"'"$3"'"'; fi
775
+ if [ -n "\${4:-}" ]; then _extra="$_extra"',"hook":"'"$4"'"'; fi
776
+ if [ "$2" = "approval" ]; then
777
+ printf '{"toolName":"%s","token":"%s","kind":"%s","input":"%s"%s}\\n' "$TOOL_NAME" "$1" "$2" "$INPUT_B64" "$_extra" >> "$LEDGER_FILE" 2>/dev/null || true
778
+ else
779
+ printf '{"toolName":"%s","token":"%s","kind":"%s"%s}\\n' "$TOOL_NAME" "$1" "$2" "$_extra" >> "$LEDGER_FILE" 2>/dev/null || true
780
+ fi
781
+ }
782
+
783
+ # --- Failsafe: missing state file → deny (fail-closed) ---
784
+ # Recorded as kind "fail-closed" so the runner attributes the blocked call to
785
+ # its own (broken) gate instead of misdiagnosing a foreign hook. The ledger
786
+ # path comes from the POINTER, not the state file, so it is recordable here.
787
+ if [ ! -f "$STATE_FILE" ]; then
788
+ if [ "$HOOK_EVENT" = "beforeMCPExecution" ]; then
789
+ record_denial "$MCP_TOKEN" "fail-closed"
790
+ else
791
+ record_denial "$PRIMARY_TOKEN" "fail-closed"
792
+ fi
793
+ echo '{"permission":"deny","agent_message":"${APPROVAL_REQUIRED_AGENT_MESSAGE}","user_message":"Tool requires approval: '"$TOOL_NAME"'"}'
794
+ exit 0
795
+ fi
796
+
797
+ STATE=$(cat "$STATE_FILE")
798
+ # The approved grants alone, so a token elsewhere in the state (a refused
799
+ # call's, a tool-list key) never reads as a grant. Base64 holds no ']'.
800
+ GRANTS=$(echo "$STATE" | grep -o '"approvedGrantTokens":\\[[^]]*\\]' | head -1 || true)
801
+ # Whether an approved grant covers this call: the content-exact token (a file
802
+ # edit approved with this exact content) or the coarse one for a built-in;
803
+ # the server/tool token for an MCP tool.
804
+ # The approval of a hook's ask: a built-in's file content when it has some,
805
+ # else the call's whole input (HOOK_ARGS_TOKEN), never the tool alone, so an
806
+ # approved call lets through that call and no other.
807
+ __stigmer_hook_granted() {
808
+ if [ "$HOOK_EVENT" != "beforeMCPExecution" ] && [ -n "$CONTENT_TOKEN" ]; then
809
+ echo "$GRANTS" | grep -qF "\\"$CONTENT_TOKEN\\""
810
+ return
811
+ fi
812
+ [ -n "$HOOK_ARGS_TOKEN" ] && echo "$GRANTS" | grep -qF "\\"$HOOK_ARGS_TOKEN\\""
813
+ }
814
+
815
+ __stigmer_granted() {
816
+ if [ "$HOOK_EVENT" = "beforeMCPExecution" ]; then
817
+ echo "$GRANTS" | grep -qF "\\"$MCP_TOKEN\\""
818
+ return
819
+ fi
820
+ { [ -n "$CONTENT_TOKEN" ] && echo "$GRANTS" | grep -qF "\\"$CONTENT_TOKEN\\""; } || echo "$GRANTS" | grep -qF "\\"$TOKEN\\""
821
+ }
822
+
823
+ # Capture mode (git workspaces): file mutations flow during the turn and are
824
+ # captured/gated per-file by the runner at the turn boundary (see
825
+ # shared/filereview/git-substrate.ts). Read once; consulted only in the
826
+ # gated-built-in arm below.
827
+ CAPTURE_MODE=false
828
+ if echo "$STATE" | grep -q '"captureMode":true'; then
829
+ CAPTURE_MODE=true
830
+ fi
831
+ # File review off: a built-in write or delete flows unreviewed (no capture, no
832
+ # ask); the secret-like write block still applies, keyed on the substrate (a
833
+ # git-tracked path flows, a gitignored or non-git one is refused). Default on
834
+ # when the key is absent, which keeps review's rules (capture or the
835
+ # deny-gate). Consulted in the hook-allow arm (1i) and the gated-built-in arm.
836
+ FILE_REVIEW=true
837
+ if echo "$STATE" | grep -q '"fileReview":false'; then
838
+ FILE_REVIEW=false
839
+ fi
840
+ # CAS capture of gitignored writes (the deep-agent parity switch). Set only when
841
+ # capture mode is on AND an artifact storage is configured (to persist blobs). It
842
+ # governs whether a non-secret gitignored write is staged+flowed for review vs.
843
+ # kept on the deny-gate. Read here; consulted only in the gitignored-capture arm
844
+ # below, which runs BEFORE auto-approve-all (capture is a turn property).
845
+ CAPTURE_IGNORED=false
846
+ if echo "$STATE" | grep -q '"captureIgnored":true'; then
847
+ CAPTURE_IGNORED=true
848
+ fi
849
+ # gitWorkspace selects the capture substrate. Default true when the
850
+ # key is absent (older state files). When false the workspace is NOT a git tree:
851
+ # there is no git snapshot, so EVERY file write/delete is CAS-staged below (not
852
+ # only gitignored ones) and the git-tracked flow arm is skipped.
853
+ GIT_WORKSPACE=true
854
+ if echo "$STATE" | grep -q '"gitWorkspace":false'; then
855
+ GIT_WORKSPACE=false
856
+ fi
857
+ # Unattended approval mode: the surface has no approver. Same gate,
858
+ # different RESOLUTION — the approval-deny arms below record kind "unattended"
859
+ # (non-pausing) with an adapt-and-explain message instead of kind "approval"
860
+ # (pausing). Secret/fail-closed/capture-error arms are mode-independent.
861
+ UNATTENDED_SKIP=false
862
+ if echo "$STATE" | grep -q '"unattendedSkip":true'; then
863
+ UNATTENDED_SKIP=true
864
+ fi
865
+
866
+ # --- 1a. Tool lists: what this agent may call at all ------------------------
867
+ # Runs BEFORE the capture arms, the auto-approve-all shortcut and every grant:
868
+ # a list is not an approval gate, so no bypass may resurrect an excluded tool
869
+ # and no human may be offered approval on one. The Node snippet looked the call
870
+ # up in the runner's compiled scope (toolScope, hook-scope.ts) and handed back
871
+ # the deny response; this arm only records and replies. Kind "disabled":
872
+ # attributable, non-pausing (the model adapts), permanent for the run.
873
+ if [ "$SCOPE_VERDICT" = "E" ]; then
874
+ if echo "$STATE" | grep -q '"toolListsRestricted":true'; then
875
+ record_denial "$PRIMARY_TOKEN" "fail-closed"
876
+ echo '{"permission":"deny","agent_message":"${SCOPE_UNAVAILABLE_AGENT_MESSAGE}","user_message":"Refused: the tool lists could not be checked"}'
877
+ exit 0
878
+ fi
879
+ elif [ -n "$SCOPE_VERDICT" ]; then
880
+ record_denial "$SCOPE_TOKEN" "disabled" "$SCOPE_MESSAGE"
881
+ printf '%s' "$SCOPE_VERDICT" | base64 -d
882
+ echo
883
+ exit 0
884
+ fi
885
+
886
+ # --- 1b. A sub-agent start the lists allow ----------------------------------
887
+ # subagentStart reaches this script only for the scope arm above; no approval
888
+ # arm below applies to it.
889
+ if [ "$HOOK_EVENT" = "subagentStart" ]; then
890
+ echo '{"permission":"allow"}'
891
+ exit 0
892
+ fi
893
+
894
+ # --- 1h. The agent's hooks -----------------------------------------------
895
+ # Present only when the agent has hooks: the runner serves them on a local
896
+ # socket the pointer names (hook-server.ts), and every hook, in either
897
+ # format, answers there, once per call. An MCP call is asked on
898
+ # beforeMCPExecution, the event that names its server; its preToolUse
899
+ # (MCP:<tool>) firing passes on. After the tool lists (1a), so an excluded
900
+ # call never reaches a hook.
901
+ # - deny, or a call a person refused earlier this run that a hook would let
902
+ # through (refused): record kind "hook" with the refusal, deny. The agent
903
+ # continues; nothing pauses.
904
+ # - ask: under the pre-armed bypass or an approved grant, as an allow;
905
+ # skipped under the unattended mode; otherwise recorded kind "approval"
906
+ # with the hook and its message, which pauses the turn on the hook's card.
907
+ # - allow: the capture arms below still review the call, and nothing after
908
+ # them may ask (1i).
909
+ # - none: no hook decided; every arm below runs as it would without hooks.
910
+ # - anything else: the server did not answer; a hook that cannot be asked
911
+ # is not skipped, so the call is refused (fail-closed).
912
+ # A secret-like write the hook asks on is blocked rather than shown on a
913
+ # card, and one it allows meets the same block the deny-gate applies (1i).
914
+ HOOK_ALLOW=false
915
+ HOOK_ALLOW_RESPONSE=""
916
+ # An allowed call's answer: a hook's (its context and any rewrite) once one
917
+ # allowed it, else the plain allow.
918
+ __stigmer_allow() {
919
+ if [ -n "$HOOK_ALLOW_RESPONSE" ]; then
920
+ printf '%s\\n' "$HOOK_ALLOW_RESPONSE"
921
+ else
922
+ echo '{"permission":"allow"}'
923
+ fi
924
+ }
925
+ # Whether this call is a secret-like write, outside the pre-armed bypass.
926
+ __stigmer_secret_write() {
927
+ [ "$CATEGORY" = "write" ] && [ -n "$SALIENT" ] || return 1
928
+ ! echo "$STATE" | grep -q '"autoApproveAll":true' || return 1
929
+ [ "$(printf '%s' "$SALIENT" | ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e '${secretClassifyScript}' 2>/dev/null || echo ok)" = "secret" ]
930
+ }
931
+ if [ -n "$HOOK_SOCKET" ] && { [ "$HOOK_EVENT" = "beforeMCPExecution" ] || { [ "$HOOK_EVENT" = "preToolUse" ] && [ "\${TOOL_NAME#MCP:}" = "$TOOL_NAME" ]; }; }; then
932
+ if [ "$HOOK_EVENT" = "beforeMCPExecution" ]; then
933
+ HOOK_ID="$MCP_TOKEN"
934
+ HOOK_COARSE="$MCP_TOKEN"
935
+ else
936
+ HOOK_ID="$PRIMARY_TOKEN"
937
+ HOOK_COARSE="$TOKEN"
938
+ fi
939
+ HOOK_REPLY=$(printf '%s' "$INPUT" | ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e '${hookClientScript}' "$HOOK_SOCKET" "$HOOK_TOKEN" pre "$HOOK_ID" "$HOOK_COARSE" "$HOOK_ARGS_TOKEN" 2>/dev/null || echo error)
940
+ HOOK_DECISION=$(printf '%s\\n' "$HOOK_REPLY" | sed -n 1p)
941
+ HOOK_SLUG=$(printf '%s\\n' "$HOOK_REPLY" | sed -n 2p)
942
+ HOOK_MESSAGE=$(printf '%s\\n' "$HOOK_REPLY" | sed -n 7p)
943
+ case "$HOOK_DECISION" in
944
+ deny|refused)
945
+ record_denial "$HOOK_ID" "hook" "$HOOK_MESSAGE" "$HOOK_SLUG"
946
+ printf '%s\\n' "$HOOK_REPLY" | sed -n 4p | base64 -d
947
+ echo
948
+ exit 0
949
+ ;;
950
+ ask)
951
+ if echo "$STATE" | grep -q '"autoApproveAll":true' || __stigmer_hook_granted; then
952
+ # Satisfied: an allow, so the capture arms below still review it.
953
+ HOOK_ALLOW=true
954
+ HOOK_ALLOW_RESPONSE=$(printf '%s\\n' "$HOOK_REPLY" | sed -n 3p | base64 -d)
955
+ elif [ "$UNATTENDED_SKIP" = "true" ]; then
956
+ record_denial "$HOOK_ID" "unattended" "" "$HOOK_SLUG"
957
+ printf '%s\\n' "$HOOK_REPLY" | sed -n 6p | base64 -d
958
+ echo
959
+ exit 0
960
+ elif __stigmer_secret_write; then
961
+ # Never shown on a card: its content is a secret's.
962
+ record_denial "$PRIMARY_TOKEN" "secret"
963
+ echo '{"permission":"deny","agent_message":"${SECRET_BLOCKED_AGENT_MESSAGE}","user_message":"Blocked for security: this file matches a secret-like path and was not written."}'
964
+ exit 0
965
+ else
966
+ record_denial "$HOOK_ID" "approval" "$HOOK_MESSAGE" "$HOOK_SLUG"
967
+ printf '%s\\n' "$HOOK_REPLY" | sed -n 5p | base64 -d
968
+ echo
969
+ exit 0
970
+ fi
971
+ ;;
972
+ allow)
973
+ HOOK_ALLOW=true
974
+ HOOK_ALLOW_RESPONSE=$(printf '%s\\n' "$HOOK_REPLY" | sed -n 3p | base64 -d)
975
+ ;;
976
+ none)
977
+ ;;
978
+ *)
979
+ record_denial "$HOOK_ID" "hook-unavailable"
980
+ echo '{"permission":"deny","agent_message":"${HOOKS_UNAVAILABLE_AGENT_MESSAGE}","user_message":"Refused: the agent hooks could not be run"}'
981
+ exit 0
982
+ ;;
983
+ esac
984
+ fi
985
+
986
+ # --- Capture mode: observe CAS-owned writes for review ----------------------
987
+ # Runs BEFORE the auto-approve-all shortcut and the grant/lease checks because
988
+ # capture is a property of the TURN, not authorization: a non-secret CAS-owned
989
+ # write must be staged and reviewed even under the global bypass, and a
990
+ # secret-like one must be hard-blocked in every mode. WHICH writes are CAS-owned
991
+ # depends on the substrate: in a git tree it is only the GITIGNORED writes (git
992
+ # captures the tracked ones); in a NON-GIT workspace it is EVERY write (there is
993
+ # no git snapshot). Only a built-in write/edit (category "write") takes THIS arm;
994
+ # deletes take their own staging arm just below (issue #303), shell/MCP stay on
995
+ # the deny-gate (parity with the deep-agent approval gate). The staging runs on
996
+ # the runner's own Node binary (the
997
+ # disk-backed mirror of CasCaptureFilesystemBackend.recordBefore): the salient
998
+ # path rides stdin (no argv escaping), the workspace root and the per-turn
999
+ # cas-observations dir ride argv. "captured" -> allow (apply-then-review);
1000
+ # "secret" -> hard-block; "error"/Node-unavailable -> fail closed (deny, since a
1001
+ # write we cannot capture cannot be reviewed).
1002
+ if [ "$CAPTURE_IGNORED" = "true" ] && [ "$CATEGORY" = "write" ] && [ -n "$SALIENT" ] && { [ "$GIT_WORKSPACE" = "false" ] || __stigmer_is_gitignored "$SALIENT"; }; then
1003
+ OBS_DIR="$(dirname "$STATE_FILE")/${CAS_OBSERVATIONS_DIRNAME}"
1004
+ OBS_RESULT=$(printf '%s' "$SALIENT" | ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e '${observationStagingScript}' "$GIT_ROOT" "$OBS_DIR" 2>/dev/null || echo error)
1005
+ if [ "$OBS_RESULT" = "captured" ]; then
1006
+ __stigmer_allow
1007
+ exit 0
1008
+ elif [ "$OBS_RESULT" = "secret" ]; then
1009
+ # Kind "secret": attributable but deliberately non-pausing (the agent moves
1010
+ # on) and content-free (the token is the only identity recorded).
1011
+ record_denial "$PRIMARY_TOKEN" "secret"
1012
+ echo '{"permission":"deny","agent_message":"${SECRET_BLOCKED_AGENT_MESSAGE}","user_message":"Blocked for security: this file matches a secret-like path and was not written or captured for review."}'
1013
+ exit 0
1014
+ else
1015
+ # Node unavailable or a staging error: fail closed. A gitignored write we
1016
+ # cannot stage cannot be captured for review, so keep gating it (today's
1017
+ # behavior) rather than letting unreviewable bytes flow. Kind
1018
+ # "capture-error" and content-free: the staging error means secret
1019
+ # classification may never have run, so the content is UNCLASSIFIED.
1020
+ record_denial "$PRIMARY_TOKEN" "capture-error"
1021
+ echo '{"permission":"deny","agent_message":"${APPROVAL_REQUIRED_AGENT_MESSAGE}","user_message":"Tool requires approval: '"$TOOL_NAME"'"}'
1022
+ exit 0
1023
+ fi
1024
+ fi
1025
+
1026
+ # --- Capture mode: observe CAS-owned deletes for review (issue #303) --------
1027
+ # The delete twin of the write arm above — a non-secret CAS-owned delete stages
1028
+ # its before-bytes (the one moment they still exist on disk) and flows; the
1029
+ # turn boundary then reads after=null and authors a reviewable, restorable
1030
+ # DELETE entry. One deliberate difference from the write arm: the path is
1031
+ # classified for secret-likeness BEFORE any staging touches the sidecar. A
1032
+ # secret-like delete must stay on the deny-gate below where a human may still
1033
+ # approve it (its args expose no secret content, unlike a write) — staging it
1034
+ # would both persist the secret before-bytes and mark the sidecar "secret",
1035
+ # making the boundary author a blocking DIFF_UNREVIEWABLE for a merely-gated
1036
+ # delete. Every failure mode (secret, classify error, staging error) falls
1037
+ # through to the deny-gate rather than denying here, so grants and leases keep
1038
+ # applying to a gated delete exactly as before this arm existed; the eventual
1039
+ # resolution records its own ledger kind.
1040
+ if [ "$CAPTURE_IGNORED" = "true" ] && [ "$CATEGORY" = "delete" ] && [ -n "$SALIENT" ] && { [ "$GIT_WORKSPACE" = "false" ] || __stigmer_is_gitignored "$SALIENT"; }; then
1041
+ DELETE_SECRET_RESULT=$(printf '%s' "$SALIENT" | ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e '${secretClassifyScript}' 2>/dev/null || echo error)
1042
+ if [ "$DELETE_SECRET_RESULT" = "ok" ]; then
1043
+ OBS_DIR="$(dirname "$STATE_FILE")/${CAS_OBSERVATIONS_DIRNAME}"
1044
+ OBS_RESULT=$(printf '%s' "$SALIENT" | ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e '${observationStagingScript}' "$GIT_ROOT" "$OBS_DIR" 2>/dev/null || echo error)
1045
+ if [ "$OBS_RESULT" = "captured" ]; then
1046
+ __stigmer_allow
1047
+ exit 0
1048
+ fi
1049
+ fi
1050
+ fi
1051
+
1052
+ # --- 1i. A hook's allow ---
1053
+ # Capture (above) has reviewed what it reviews; nothing below may ask. A
1054
+ # write takes the deny-gate's own rule (3): a git-tracked one flows (to the
1055
+ # turn's review in capture mode, unreviewed with review off), and any other
1056
+ # secret-like one is blocked.
1057
+ if [ "$HOOK_ALLOW" = "true" ]; then
1058
+ if ! { { [ "$CAPTURE_MODE" = "true" ] || [ "$FILE_REVIEW" = "false" ]; } && [ "$GIT_WORKSPACE" = "true" ] && [ "$CATEGORY" = "write" ] && ! __stigmer_is_gitignored "$SALIENT"; } && __stigmer_secret_write; then
1059
+ record_denial "$PRIMARY_TOKEN" "secret"
1060
+ echo '{"permission":"deny","agent_message":"${SECRET_BLOCKED_AGENT_MESSAGE}","user_message":"Blocked for security: this file matches a secret-like path and was not written."}'
1061
+ exit 0
1062
+ fi
1063
+ __stigmer_allow
1064
+ exit 0
1065
+ fi
1066
+
1067
+ # --- 1c. Auto-approve all ---
1068
+ if echo "$STATE" | grep -q '"autoApproveAll":true'; then
1069
+ echo '{"permission":"allow"}'
1070
+ exit 0
1071
+ fi
1072
+
1073
+ # --- 2. MCP tools (beforeMCPExecution event) ---
1074
+ # preToolUse does NOT enforce gating for MCP calls — beforeMCPExecution does — so
1075
+ # MCP is gated here and ONLY here (never double-recorded). mcpDestructiveTools
1076
+ # holds only the tools that ask, keyed "server/tool" from the payload's
1077
+ # mcp_server_name, so presence means "deny" and an equal tool name on another
1078
+ # server is never caught; mcpUnlistedServers names the servers whose every tool
1079
+ # asks, because their tools could not be listed at turn start. MCP tool and
1080
+ # server names are consistent across the hook and the stream, so the identity
1081
+ # token is base64("server/tool\\n").
1082
+ if [ "$HOOK_EVENT" = "beforeMCPExecution" ]; then
1083
+ if [ -n "$MCP_SERVER" ] && [ -n "$TOOL_NAME" ]; then
1084
+ MSG=""
1085
+ TOOL_POLICY=$(echo "$STATE" | grep -o "\\"$MCP_SERVER/$TOOL_NAME\\":{[^}]*}" | head -1 || true)
1086
+ if [ -n "$TOOL_POLICY" ]; then
1087
+ MSG=$(echo "$TOOL_POLICY" | grep -o '"message":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
1088
+ if [ -z "$MSG" ]; then
1089
+ MSG="Tool requires approval: $TOOL_NAME"
1090
+ fi
1091
+ elif echo "$STATE" | grep -o '"mcpUnlistedServers":\\[[^]]*\\]' | grep -qF "\\"$MCP_SERVER\\""; then
1092
+ MSG="${unlistedMessage("$TOOL_NAME")}"
1093
+ fi
1094
+ if [ -n "$MSG" ]; then
1095
+ # Reinvocation grant: this tool was approved earlier → allow.
1096
+ if __stigmer_granted; then
1097
+ echo '{"permission":"allow"}'
1098
+ exit 0
1099
+ fi
1100
+ if [ "$UNATTENDED_SKIP" = "true" ]; then
1101
+ # Unattended resolution: non-pausing kind, final for this
1102
+ # turn — the model adapts and the turn boundary stamps SKIPPED.
1103
+ record_denial "$MCP_TOKEN" "unattended"
1104
+ echo '{"permission":"deny","agent_message":"${UNATTENDED_SKIP_AGENT_MESSAGE}","user_message":"Skipped (approval not available on this surface): '"$TOOL_NAME"'"}'
1105
+ exit 0
1106
+ fi
1107
+ record_denial "$MCP_TOKEN" "approval"
1108
+ echo '{"permission":"deny","agent_message":"${APPROVAL_REQUIRED_AGENT_MESSAGE}","user_message":"'"$MSG"'"}'
1109
+ exit 0
1110
+ fi
1111
+ fi
1112
+ # Auto-approved or unmarked MCP tool → allow.
1113
+ echo '{"permission":"allow"}'
1114
+ exit 0
1115
+ fi
1116
+
1117
+ # --- 3. Gated built-in tools (preToolUse event, category non-empty) ---
1118
+ if [ -n "$CATEGORY" ]; then
1119
+ # Capture mode (GIT tree only): a git-tracked file mutation (write/edit/delete)
1120
+ # flows freely — the runner captures the whole change set with git at the turn
1121
+ # boundary and gates it per-file for review. A gitignored path is invisible to
1122
+ # that git snapshot: a non-secret gitignored WRITE or DELETE was already
1123
+ # handled above (staged + allowed, hard-blocked, or left to fall through) when
1124
+ # captureIgnored is on; here it only reaches the deny-gate when captureIgnored
1125
+ # is off (no artifact storage), or it is a secret-like DELETE (approvable, but
1126
+ # never staged — issue #303). shell (category "shell") never takes this branch
1127
+ # and stays gated as always. In a NON-GIT workspace this arm is skipped
1128
+ # entirely (there is no git diff): writes and deletes were CAS-staged above.
1129
+ # With file review off the same git-tracked mutation flows unreviewed: the
1130
+ # secret rule is keyed on the git substrate, not on review, so a committed
1131
+ # .env.example flows as before.
1132
+ if { [ "$CAPTURE_MODE" = "true" ] || [ "$FILE_REVIEW" = "false" ]; } && [ "$GIT_WORKSPACE" = "true" ] && { [ "$CATEGORY" = "write" ] || [ "$CATEGORY" = "delete" ]; }; then
1133
+ if ! __stigmer_is_gitignored "$SALIENT"; then
1134
+ echo '{"permission":"allow"}'
1135
+ exit 0
1136
+ fi
1137
+ fi
1138
+ # Deny-gate secret hard-block: a secret-like WRITE that reaches the
1139
+ # deny-gate (no capture substrate for it — capture off, or captureIgnored off in
1140
+ # a git-no-storage workspace) must not surface its content for approval. Classify
1141
+ # byte-identically to isSecretLikePath (no staging) and, on a match, hard-block
1142
+ # with the security message: the agent continues, nothing is written, and NO
1143
+ # content is recorded to the ledger. Placed before the grant/lease checks so a
1144
+ # write-category lease can never bypass it; only writes are content-bearing
1145
+ # (deletes stay gated). Fail-open on a classify error — the write falls to the
1146
+ # normal deny-gate and the runner-side backstop still withholds any secret
1147
+ # content before persist.
1148
+ if [ "$CATEGORY" = "write" ] && [ -n "$SALIENT" ]; then
1149
+ SECRET_RESULT=$(printf '%s' "$SALIENT" | ELECTRON_RUN_AS_NODE=1 "$NODE_BIN" -e '${secretClassifyScript}' 2>/dev/null || echo ok)
1150
+ if [ "$SECRET_RESULT" = "secret" ]; then
1151
+ # Kind "secret": attributable but non-pausing and content-free (only
1152
+ # the identity token is recorded, never the proposed content).
1153
+ record_denial "$PRIMARY_TOKEN" "secret"
1154
+ echo '{"permission":"deny","agent_message":"${SECRET_BLOCKED_AGENT_MESSAGE}","user_message":"Blocked for security: this file matches a secret-like path and was not written."}'
1155
+ exit 0
1156
+ fi
1157
+ fi
1158
+ # File review off: any other built-in write or delete flows unreviewed
1159
+ # (stigmer#1471). The secret-like write block above has already refused a
1160
+ # gitignored or non-git secret-like path; shell (category "shell") never
1161
+ # takes this branch and stays gated.
1162
+ if [ "$FILE_REVIEW" = "false" ] && { [ "$CATEGORY" = "write" ] || [ "$CATEGORY" = "delete" ]; }; then
1163
+ echo '{"permission":"allow"}'
1164
+ exit 0
1165
+ fi
1166
+ # Reinvocation grant: allow when the CONTENT-exact token (a file edit approved
1167
+ # earlier with this exact content) OR the COARSE token (a shell/delete, or the
1168
+ # content-less degrade) is in approvedGrantTokens. A sibling edit to the same
1169
+ # file has a different content token and no coarse grant, so it re-gates.
1170
+ if __stigmer_granted; then
1171
+ echo '{"permission":"allow"}'
1172
+ exit 0
1173
+ fi
1174
+ # Run-lifetime category lease: the user chose "approve all <category>" earlier
1175
+ # in this run (the scoped successor to autoApproveAll), so every built-in of
1176
+ # this category is allowed for the rest of the run. Matched within the extracted
1177
+ # leasedCategories array so a category word elsewhere in the state can't grant.
1178
+ LEASED_CATEGORIES=$(echo "$STATE" | grep -o '"leasedCategories":\\[[^]]*\\]' | head -1 || true)
1179
+ if [ -n "$LEASED_CATEGORIES" ] && echo "$LEASED_CATEGORIES" | grep -q "\\"$CATEGORY\\""; then
1180
+ echo '{"permission":"allow"}'
1181
+ exit 0
1182
+ fi
1183
+ # Record the PRIMARY token (content-exact when available, else coarse) so the
1184
+ # runner's denial correlation keys on the SAME identity it grants on approval.
1185
+ if [ "$UNATTENDED_SKIP" = "true" ]; then
1186
+ # Unattended resolution: non-pausing kind, final for this turn —
1187
+ # the model adapts and the turn boundary stamps SKIPPED.
1188
+ record_denial "$PRIMARY_TOKEN" "unattended"
1189
+ echo '{"permission":"deny","agent_message":"${UNATTENDED_SKIP_AGENT_MESSAGE}","user_message":"Skipped (approval not available on this surface): '"$TOOL_NAME"'"}'
1190
+ exit 0
1191
+ fi
1192
+ record_denial "$PRIMARY_TOKEN" "approval"
1193
+ echo '{"permission":"deny","agent_message":"${APPROVAL_REQUIRED_AGENT_MESSAGE}","user_message":"Tool requires approval: '"$TOOL_NAME"'"}'
1194
+ exit 0
1195
+ fi
1196
+
1197
+ # --- 4. Everything else → allow ---
1198
+ # Read-only built-ins and anything not explicitly gated. Fail-open mirrors the
1199
+ # native harness (gate the dangerous set, allow the rest).
1200
+ echo '{"permission":"allow"}'
1201
+ exit 0
1202
+ `;
1203
+ }
1204
+ //# sourceMappingURL=hook-script.js.map