@stigmer/runner 3.14.0 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (331) hide show
  1. package/dist/.build-fingerprint +1 -1
  2. package/dist/__test-utils__/execution-record-fixture.d.ts +47 -0
  3. package/dist/__test-utils__/execution-record-fixture.js +68 -0
  4. package/dist/__test-utils__/execution-record-fixture.js.map +1 -0
  5. package/dist/__test-utils__/harness-contract/types.d.ts +166 -0
  6. package/dist/__test-utils__/harness-contract/types.js +49 -0
  7. package/dist/__test-utils__/harness-contract/types.js.map +1 -0
  8. package/dist/__test-utils__/hermetic-activity.d.ts +268 -0
  9. package/dist/__test-utils__/hermetic-activity.js +385 -0
  10. package/dist/__test-utils__/hermetic-activity.js.map +1 -0
  11. package/dist/__test-utils__/mock-client.d.ts +13 -0
  12. package/dist/__test-utils__/mock-client.js +45 -0
  13. package/dist/__test-utils__/mock-client.js.map +1 -0
  14. package/dist/__test-utils__/mock-workspace.d.ts +15 -0
  15. package/dist/__test-utils__/mock-workspace.js +21 -0
  16. package/dist/__test-utils__/mock-workspace.js.map +1 -0
  17. package/dist/__test-utils__/model-registry-fixture.d.ts +56 -0
  18. package/dist/__test-utils__/model-registry-fixture.js +66 -0
  19. package/dist/__test-utils__/model-registry-fixture.js.map +1 -0
  20. package/dist/__test-utils__/turn-input-fixture.d.ts +60 -0
  21. package/dist/__test-utils__/turn-input-fixture.js +118 -0
  22. package/dist/__test-utils__/turn-input-fixture.js.map +1 -0
  23. package/dist/activities/execute-cursor/__test-utils__/contract-subject.d.ts +107 -0
  24. package/dist/activities/execute-cursor/__test-utils__/contract-subject.js +344 -0
  25. package/dist/activities/execute-cursor/__test-utils__/contract-subject.js.map +1 -0
  26. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.d.ts +20 -0
  27. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js +58 -0
  28. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js.map +1 -1
  29. package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js +2 -32
  30. package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js.map +1 -1
  31. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.d.ts +148 -0
  32. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js +257 -0
  33. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js.map +1 -0
  34. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.d.ts +183 -0
  35. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js +262 -0
  36. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js.map +1 -0
  37. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.d.ts +138 -0
  38. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js +191 -0
  39. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js.map +1 -0
  40. package/dist/activities/execute-cursor/adapter.d.ts +55 -0
  41. package/dist/activities/execute-cursor/adapter.js +119 -0
  42. package/dist/activities/execute-cursor/adapter.js.map +1 -0
  43. package/dist/activities/execute-cursor/approval-state.d.ts +2 -2
  44. package/dist/activities/execute-cursor/approval-state.js.map +1 -1
  45. package/dist/activities/execute-cursor/capture-flow.d.ts +15 -30
  46. package/dist/activities/execute-cursor/capture-flow.js +17 -26
  47. package/dist/activities/execute-cursor/capture-flow.js.map +1 -1
  48. package/dist/activities/execute-cursor/cursor-capabilities.d.ts +23 -0
  49. package/dist/activities/execute-cursor/cursor-capabilities.js +33 -0
  50. package/dist/activities/execute-cursor/cursor-capabilities.js.map +1 -0
  51. package/dist/activities/execute-cursor/cursor-mcp-config.d.ts +2 -2
  52. package/dist/activities/execute-cursor/cursor-mcp-config.js.map +1 -1
  53. package/dist/activities/execute-cursor/fetch-interceptor.d.ts +15 -25
  54. package/dist/activities/execute-cursor/fetch-interceptor.js +39 -33
  55. package/dist/activities/execute-cursor/fetch-interceptor.js.map +1 -1
  56. package/dist/activities/execute-cursor/http2-interceptor.d.ts +21 -17
  57. package/dist/activities/execute-cursor/http2-interceptor.js +38 -31
  58. package/dist/activities/execute-cursor/http2-interceptor.js.map +1 -1
  59. package/dist/activities/execute-cursor/message-translator.d.ts +28 -19
  60. package/dist/activities/execute-cursor/message-translator.js +76 -27
  61. package/dist/activities/execute-cursor/message-translator.js.map +1 -1
  62. package/dist/activities/execute-cursor/prompt-builder.d.ts +180 -11
  63. package/dist/activities/execute-cursor/prompt-builder.js +171 -0
  64. package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
  65. package/dist/activities/execute-cursor/rejection-capture.d.ts +3 -6
  66. package/dist/activities/execute-cursor/rejection-capture.js +5 -7
  67. package/dist/activities/execute-cursor/rejection-capture.js.map +1 -1
  68. package/dist/activities/execute-cursor/session-lifecycle.d.ts +1 -4
  69. package/dist/activities/execute-cursor/session-lifecycle.js.map +1 -1
  70. package/dist/activities/execute-cursor/turn-boundary.d.ts +1 -1
  71. package/dist/activities/execute-cursor/turn-settle.d.ts +49 -0
  72. package/dist/activities/execute-cursor/turn-settle.js +507 -0
  73. package/dist/activities/execute-cursor/turn-settle.js.map +1 -0
  74. package/dist/activities/execute-cursor/turn-setup.d.ts +173 -0
  75. package/dist/activities/execute-cursor/turn-setup.js +496 -0
  76. package/dist/activities/execute-cursor/turn-setup.js.map +1 -0
  77. package/dist/activities/execute-cursor/turn-stream.d.ts +41 -71
  78. package/dist/activities/execute-cursor/turn-stream.js +70 -135
  79. package/dist/activities/execute-cursor/turn-stream.js.map +1 -1
  80. package/dist/activities/execute-cursor/turn.d.ts +43 -0
  81. package/dist/activities/execute-cursor/turn.js +222 -0
  82. package/dist/activities/execute-cursor/turn.js.map +1 -0
  83. package/dist/activities/execute-cursor/usage-pricing.d.ts +38 -0
  84. package/dist/activities/execute-cursor/usage-pricing.js +50 -0
  85. package/dist/activities/execute-cursor/usage-pricing.js.map +1 -0
  86. package/dist/activities/execute-deep-agent/approval-file-change.d.ts +1 -1
  87. package/dist/activities/execute-deep-agent/approval-file-change.js +1 -1
  88. package/dist/activities/execute-deep-agent/environment.js +1 -1
  89. package/dist/activities/execute-deep-agent/environment.js.map +1 -1
  90. package/dist/activities/execute-deep-agent/setup.js +3 -2
  91. package/dist/activities/execute-deep-agent/setup.js.map +1 -1
  92. package/dist/activities/hydrate-workflow-execution.js +1 -1
  93. package/dist/activities/hydrate-workflow-execution.js.map +1 -1
  94. package/dist/config.d.ts +15 -0
  95. package/dist/config.js.map +1 -1
  96. package/dist/harness/capabilities.d.ts +87 -0
  97. package/dist/harness/capabilities.js +37 -0
  98. package/dist/harness/capabilities.js.map +1 -0
  99. package/dist/harness/persist-chokepoint.d.ts +74 -0
  100. package/dist/harness/persist-chokepoint.js +88 -0
  101. package/dist/harness/persist-chokepoint.js.map +1 -0
  102. package/dist/harness/registry.d.ts +106 -0
  103. package/dist/harness/registry.js +168 -0
  104. package/dist/harness/registry.js.map +1 -0
  105. package/dist/harness/run-turn.d.ts +53 -0
  106. package/dist/harness/run-turn.js +528 -0
  107. package/dist/harness/run-turn.js.map +1 -0
  108. package/dist/harness/stop-controller.d.ts +50 -0
  109. package/dist/harness/stop-controller.js +62 -0
  110. package/dist/harness/stop-controller.js.map +1 -0
  111. package/dist/harness/terminal-table.d.ts +141 -0
  112. package/dist/harness/terminal-table.js +239 -0
  113. package/dist/harness/terminal-table.js.map +1 -0
  114. package/dist/harness/turn-context.d.ts +523 -0
  115. package/dist/harness/turn-context.js +739 -0
  116. package/dist/harness/turn-context.js.map +1 -0
  117. package/dist/harness/types.d.ts +448 -0
  118. package/dist/harness/types.js +64 -0
  119. package/dist/harness/types.js.map +1 -0
  120. package/dist/harness/usage-accumulator.d.ts +68 -0
  121. package/dist/harness/usage-accumulator.js +101 -0
  122. package/dist/harness/usage-accumulator.js.map +1 -0
  123. package/dist/harness-adapters.d.ts +27 -0
  124. package/dist/harness-adapters.js +28 -0
  125. package/dist/harness-adapters.js.map +1 -0
  126. package/dist/main.js.map +1 -1
  127. package/dist/runner-manager.js +64 -48
  128. package/dist/runner-manager.js.map +1 -1
  129. package/dist/runner.d.ts +5 -4
  130. package/dist/runner.js +65 -64
  131. package/dist/runner.js.map +1 -1
  132. package/dist/shared/approval-policy.d.ts +1 -1
  133. package/dist/shared/approval-policy.js.map +1 -1
  134. package/dist/{activities/execute-cursor → shared}/attachment-resolver.d.ts +2 -2
  135. package/dist/{activities/execute-cursor → shared}/attachment-resolver.js +5 -5
  136. package/dist/shared/attachment-resolver.js.map +1 -0
  137. package/dist/{activities/execute-cursor → shared}/blueprint-resolver.d.ts +7 -5
  138. package/dist/{activities/execute-cursor → shared}/blueprint-resolver.js +3 -63
  139. package/dist/shared/blueprint-resolver.js.map +1 -0
  140. package/dist/shared/channel-attachment.d.ts +1 -1
  141. package/dist/shared/channel-attachment.js.map +1 -1
  142. package/dist/{activities/execute-cursor → shared}/cost-guard.d.ts +5 -1
  143. package/dist/{activities/execute-cursor → shared}/cost-guard.js +5 -1
  144. package/dist/shared/cost-guard.js.map +1 -0
  145. package/dist/{activities/execute-cursor → shared}/env-resolver.d.ts +1 -1
  146. package/dist/shared/env-resolver.js.map +1 -0
  147. package/dist/{activities/execute-cursor → shared}/exact-apply.d.ts +1 -1
  148. package/dist/{activities/execute-cursor → shared}/exact-apply.js +6 -6
  149. package/dist/shared/exact-apply.js.map +1 -0
  150. package/dist/shared/execution-context.d.ts +35 -0
  151. package/dist/shared/execution-context.js +38 -0
  152. package/dist/shared/execution-context.js.map +1 -0
  153. package/dist/{activities/execute-cursor → shared}/extract-structured-output.d.ts +5 -2
  154. package/dist/{activities/execute-cursor → shared}/extract-structured-output.js +9 -6
  155. package/dist/shared/extract-structured-output.js.map +1 -0
  156. package/dist/shared/filereview/capture.d.ts +1 -1
  157. package/dist/shared/filereview/capture.js +1 -1
  158. package/dist/shared/heartbeat.d.ts +13 -11
  159. package/dist/shared/heartbeat.js +14 -29
  160. package/dist/shared/heartbeat.js.map +1 -1
  161. package/dist/{activities/execute-cursor → shared}/persist-decision.d.ts +5 -2
  162. package/dist/{activities/execute-cursor → shared}/persist-decision.js +4 -1
  163. package/dist/shared/persist-decision.js.map +1 -0
  164. package/dist/{activities/execute-cursor → shared}/skill-resolver.d.ts +16 -3
  165. package/dist/{activities/execute-cursor → shared}/skill-resolver.js +12 -4
  166. package/dist/shared/skill-resolver.js.map +1 -0
  167. package/dist/shared/subagent-rows.d.ts +21 -0
  168. package/dist/shared/subagent-rows.js +34 -0
  169. package/dist/shared/subagent-rows.js.map +1 -0
  170. package/dist/shared/worker-shutdown.d.ts +43 -16
  171. package/dist/shared/worker-shutdown.js +28 -13
  172. package/dist/shared/worker-shutdown.js.map +1 -1
  173. package/dist/shared/workspace/platform-dir.d.ts +1 -1
  174. package/dist/shared/workspace/platform-dir.js +1 -1
  175. package/dist/shared/workspace/session-provision.d.ts +54 -0
  176. package/dist/{activities/execute-cursor/workspace-provision.js → shared/workspace/session-provision.js} +15 -12
  177. package/dist/shared/workspace/session-provision.js.map +1 -0
  178. package/package.json +4 -4
  179. package/src/__test-utils__/__tests__/harness-contract-self-check.test.ts +325 -0
  180. package/src/__test-utils__/config-fixture.ts +63 -0
  181. package/src/__test-utils__/execution-record-fixture.ts +104 -0
  182. package/src/__test-utils__/harness-boot-order-child.ts +58 -0
  183. package/src/__test-utils__/harness-contract/contract.ts +581 -0
  184. package/src/__test-utils__/harness-contract/recording-sink.ts +107 -0
  185. package/src/__test-utils__/harness-contract/runtime-contract.ts +666 -0
  186. package/src/__test-utils__/harness-contract/scripted-adapter.ts +349 -0
  187. package/src/__test-utils__/harness-contract/types.ts +176 -0
  188. package/src/__test-utils__/hermetic-activity.ts +502 -0
  189. package/src/__test-utils__/model-registry-fixture.ts +72 -0
  190. package/src/__test-utils__/module-specifiers.ts +82 -0
  191. package/src/__test-utils__/proto-helpers.ts +25 -0
  192. package/src/__test-utils__/turn-input-fixture.ts +155 -0
  193. package/src/__tests__/harness-boot-order.test.ts +77 -0
  194. package/src/__tests__/harness-contract.test.ts +27 -0
  195. package/src/__tests__/runner-manager.test.ts +18 -0
  196. package/src/activities/execute-cursor/__test-utils__/__tests__/scripted-double.test.ts +102 -0
  197. package/src/activities/execute-cursor/__test-utils__/contract-subject.ts +396 -0
  198. package/src/activities/execute-cursor/__test-utils__/cursor-hook-harness.ts +66 -0
  199. package/src/activities/execute-cursor/__test-utils__/gateway-substrate.ts +2 -43
  200. package/src/activities/execute-cursor/__test-utils__/hermetic-cursor.ts +342 -0
  201. package/src/activities/execute-cursor/__test-utils__/scripted-agent.ts +368 -0
  202. package/src/activities/execute-cursor/__test-utils__/scripted-sdk.ts +254 -0
  203. package/src/activities/execute-cursor/__tests__/adapter-is-temporal-free.test.ts +45 -0
  204. package/src/activities/execute-cursor/__tests__/approval-decisions-agree.test.ts +90 -0
  205. package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +7 -8
  206. package/src/activities/execute-cursor/__tests__/capture-flow.test.ts +28 -1
  207. package/src/activities/execute-cursor/__tests__/deny-gate-exact-apply.test.ts +1 -1
  208. package/src/activities/execute-cursor/__tests__/fetch-interceptor.test.ts +64 -6
  209. package/src/activities/execute-cursor/__tests__/hermetic/deny-and-retry.test.ts +228 -0
  210. package/src/activities/execute-cursor/__tests__/hermetic/file-review-capture.test.ts +180 -0
  211. package/src/activities/execute-cursor/__tests__/hermetic/goldens/cost-cap.status.json +53 -0
  212. package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn1.status.json +55 -0
  213. package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn2.status.json +77 -0
  214. package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-capture.status.json +126 -0
  215. package/src/activities/execute-cursor/__tests__/hermetic/goldens/pause.status.json +40 -0
  216. package/src/activities/execute-cursor/__tests__/hermetic/goldens/plain-turn.status.json +48 -0
  217. package/src/activities/execute-cursor/__tests__/hermetic/goldens/platform-stop.status.json +56 -0
  218. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-fresh-agent.status.json +53 -0
  219. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-transport-timeout.status.json +48 -0
  220. package/src/activities/execute-cursor/__tests__/hermetic/goldens/resolution-error.status.json +18 -0
  221. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-cancelled.status.json +36 -0
  222. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-error-non-retryable.status.json +37 -0
  223. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-error-at-create.status.json +38 -0
  224. package/src/activities/execute-cursor/__tests__/hermetic/goldens/stall.status.json +59 -0
  225. package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-call.status.json +68 -0
  226. package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattributed-hook-block.status.json +79 -0
  227. package/src/activities/execute-cursor/__tests__/hermetic/goldens/worker-shutdown.status.json +42 -0
  228. package/src/activities/execute-cursor/__tests__/hermetic/harness-contract.test.ts +170 -0
  229. package/src/activities/execute-cursor/__tests__/hermetic/pause-vs-shutdown.test.ts +205 -0
  230. package/src/activities/execute-cursor/__tests__/hermetic/plain-turn.test.ts +171 -0
  231. package/src/activities/execute-cursor/__tests__/hermetic/recovery-fresh-agent.test.ts +156 -0
  232. package/src/activities/execute-cursor/__tests__/hermetic/run-wait-arms.test.ts +286 -0
  233. package/src/activities/execute-cursor/__tests__/hermetic/stream-self-stop-arms.test.ts +332 -0
  234. package/src/activities/execute-cursor/__tests__/hermetic/thrown-error-arms.test.ts +193 -0
  235. package/src/activities/execute-cursor/__tests__/hermetic/tool-call.test.ts +137 -0
  236. package/src/activities/execute-cursor/__tests__/hermetic/unattributed-hook-block.test.ts +185 -0
  237. package/src/activities/execute-cursor/__tests__/hermetic/workspace-lock-timeout.test.ts +151 -0
  238. package/src/activities/execute-cursor/__tests__/http2-interceptor.test.ts +65 -35
  239. package/src/activities/execute-cursor/__tests__/message-translator.test.ts +0 -40
  240. package/src/activities/execute-cursor/__tests__/same-identity-reproposal.test.ts +171 -0
  241. package/src/activities/execute-cursor/__tests__/turn-stream.test.ts +118 -243
  242. package/src/activities/execute-cursor/__tests__/usage-pricing.test.ts +84 -0
  243. package/src/activities/execute-cursor/adapter.ts +138 -0
  244. package/src/activities/execute-cursor/approval-state.ts +2 -2
  245. package/src/activities/execute-cursor/capture-flow.ts +18 -41
  246. package/src/activities/execute-cursor/cursor-capabilities.ts +35 -0
  247. package/src/activities/execute-cursor/cursor-mcp-config.ts +2 -2
  248. package/src/activities/execute-cursor/fetch-interceptor.ts +48 -45
  249. package/src/activities/execute-cursor/http2-interceptor.ts +47 -34
  250. package/src/activities/execute-cursor/message-translator.ts +90 -45
  251. package/src/activities/execute-cursor/prompt-builder.ts +327 -12
  252. package/src/activities/execute-cursor/rejection-capture.ts +5 -12
  253. package/src/activities/execute-cursor/session-lifecycle.ts +1 -5
  254. package/src/activities/execute-cursor/turn-boundary.ts +1 -1
  255. package/src/activities/execute-cursor/turn-settle.ts +601 -0
  256. package/src/activities/execute-cursor/turn-setup.ts +645 -0
  257. package/src/activities/execute-cursor/turn-stream.ts +84 -210
  258. package/src/activities/execute-cursor/turn.ts +240 -0
  259. package/src/activities/execute-cursor/usage-pricing.ts +67 -0
  260. package/src/activities/execute-deep-agent/approval-file-change.ts +1 -1
  261. package/src/activities/execute-deep-agent/environment.ts +1 -1
  262. package/src/activities/execute-deep-agent/setup.ts +3 -2
  263. package/src/activities/hydrate-workflow-execution.ts +1 -1
  264. package/src/config.ts +13 -0
  265. package/src/harness/__tests__/import-direction.test.ts +168 -0
  266. package/src/harness/__tests__/persist-chokepoint.test.ts +146 -0
  267. package/src/harness/__tests__/registry.test.ts +168 -0
  268. package/src/harness/__tests__/run-turn.test.ts +165 -0
  269. package/src/harness/__tests__/stop-controller.test.ts +49 -0
  270. package/src/harness/__tests__/turn-context.test.ts +178 -0
  271. package/src/harness/__tests__/usage-accumulator.test.ts +83 -0
  272. package/src/harness/capabilities.ts +92 -0
  273. package/src/harness/persist-chokepoint.ts +112 -0
  274. package/src/harness/registry.ts +197 -0
  275. package/src/harness/run-turn.ts +618 -0
  276. package/src/harness/stop-controller.ts +83 -0
  277. package/src/harness/terminal-table.ts +276 -0
  278. package/src/harness/turn-context.ts +1028 -0
  279. package/src/harness/types.ts +473 -0
  280. package/src/harness/usage-accumulator.ts +122 -0
  281. package/src/harness-adapters.ts +30 -0
  282. package/src/main.ts +1 -1
  283. package/src/runner-manager.ts +68 -61
  284. package/src/runner.ts +67 -78
  285. package/src/shared/__tests__/attachment-naming.test.ts +1 -1
  286. package/src/{activities/execute-cursor → shared}/__tests__/attachment-resolver.test.ts +6 -4
  287. package/src/{activities/execute-cursor → shared}/__tests__/cost-guard.test.ts +2 -1
  288. package/src/{activities/execute-cursor → shared}/__tests__/exact-apply.test.ts +3 -3
  289. package/src/{activities/execute-cursor → shared}/__tests__/extract-structured-output.test.ts +8 -8
  290. package/src/{activities/execute-cursor → shared}/__tests__/persist-decision.test.ts +4 -2
  291. package/src/{activities/execute-cursor → shared}/__tests__/skill-resolver.test.ts +1 -1
  292. package/src/shared/__tests__/subagent-rows.test.ts +34 -0
  293. package/src/shared/__tests__/worker-shutdown.test.ts +44 -39
  294. package/src/shared/approval-policy.ts +1 -1
  295. package/src/{activities/execute-cursor → shared}/attachment-resolver.ts +6 -6
  296. package/src/{activities/execute-cursor → shared}/blueprint-resolver.ts +7 -78
  297. package/src/shared/channel-attachment.ts +1 -1
  298. package/src/{activities/execute-cursor → shared}/cost-guard.ts +5 -1
  299. package/src/{activities/execute-cursor → shared}/env-resolver.ts +1 -1
  300. package/src/{activities/execute-cursor → shared}/exact-apply.ts +7 -7
  301. package/src/shared/execution-context.ts +45 -0
  302. package/src/{activities/execute-cursor → shared}/extract-structured-output.ts +10 -7
  303. package/src/shared/filereview/capture.ts +1 -1
  304. package/src/shared/heartbeat.ts +13 -33
  305. package/src/{activities/execute-cursor → shared}/persist-decision.ts +5 -2
  306. package/src/{activities/execute-cursor → shared}/skill-resolver.ts +20 -6
  307. package/src/shared/subagent-rows.ts +39 -0
  308. package/src/shared/worker-shutdown.ts +55 -25
  309. package/src/{activities/execute-cursor/__tests__/workspace-provision.test.ts → shared/workspace/__tests__/session-provision.test.ts} +25 -28
  310. package/src/shared/workspace/platform-dir.ts +1 -1
  311. package/src/{activities/execute-cursor/workspace-provision.ts → shared/workspace/session-provision.ts} +29 -16
  312. package/dist/activities/execute-cursor/attachment-resolver.js.map +0 -1
  313. package/dist/activities/execute-cursor/blueprint-resolver.js.map +0 -1
  314. package/dist/activities/execute-cursor/cost-guard.js.map +0 -1
  315. package/dist/activities/execute-cursor/env-resolver.js.map +0 -1
  316. package/dist/activities/execute-cursor/exact-apply.js.map +0 -1
  317. package/dist/activities/execute-cursor/extract-structured-output.js.map +0 -1
  318. package/dist/activities/execute-cursor/index.d.ts +0 -209
  319. package/dist/activities/execute-cursor/index.js +0 -2345
  320. package/dist/activities/execute-cursor/index.js.map +0 -1
  321. package/dist/activities/execute-cursor/persist-decision.js.map +0 -1
  322. package/dist/activities/execute-cursor/skill-resolver.js.map +0 -1
  323. package/dist/activities/execute-cursor/usage-accumulator.d.ts +0 -89
  324. package/dist/activities/execute-cursor/usage-accumulator.js +0 -121
  325. package/dist/activities/execute-cursor/usage-accumulator.js.map +0 -1
  326. package/dist/activities/execute-cursor/workspace-provision.d.ts +0 -42
  327. package/dist/activities/execute-cursor/workspace-provision.js.map +0 -1
  328. package/src/activities/execute-cursor/__tests__/usage-accumulator.test.ts +0 -164
  329. package/src/activities/execute-cursor/index.ts +0 -2876
  330. package/src/activities/execute-cursor/usage-accumulator.ts +0 -169
  331. /package/dist/{activities/execute-cursor → shared}/env-resolver.js +0 -0
@@ -1,35 +1,42 @@
1
1
  /**
2
2
  * The Cursor harness's stream phase — the single per-event consumption loop that
3
3
  * turns a live Cursor SDK run into the streamed transcript, mid-run progress, and
4
- * the flags that decide how the turn ends.
4
+ * the one flag that decides how the turn goes on (the first-denial stop).
5
5
  *
6
- * Extracted from the activity entry point (index.ts) so that BOTH the primary
7
- * turn and the two recovery retries (poisoned-handle / transport-timeout) drive
8
- * the exact same code. The retries previously re-implemented a stripped "bare"
6
+ * Extracted from the activity entry point so that BOTH the primary turn and
7
+ * the two recovery retries (poisoned-handle / transport-timeout) drive the
8
+ * exact same code. The retries previously re-implemented a stripped "bare"
9
9
  * loop that dropped live persist, DD-32/DD-33 mid-run progress, sub-agent
10
- * tracking, the first-denial early stop, and correct pause/stall handling — so a
10
+ * tracking, the first-denial early stop, and correct pause handling — so a
11
11
  * retry froze the UI and mis-handled a mid-retry pause. One loop removes that
12
12
  * drift by construction.
13
13
  *
14
- * This mirrors the deep-agent harness's `streamExecution` seam
15
- * (execute-deep-agent/streaming.ts): injected `heartbeat`/`isCancelled` so it
16
- * runs without Temporal, a structural `StreamableRun` so it runs without the live
17
- * SDK, and a result (the terminal reason) instead of internal terminal mapping.
18
- * The one deliberate difference: this consumer REPORTS why the stream ended and
19
- * leaves the terminal MAPPING to the activity, because Cursor's mapping is
20
- * entangled with worker-shutdown-vs-pause disambiguation, the turn boundary,
21
- * structured output, and recovery retries all of which must stay in index.ts.
14
+ * What the loop asks of the runtime, through the sink (`harness/types.ts`):
15
+ * `recordActivity()` per event (with the tool name) and per delta, so the
16
+ * runtime's stall watchdog measures the engine; `reportUsage()` per
17
+ * `turn-ended` delta, priced here at the requested variant's rates
18
+ * (`usage-pricing.ts`), so the runtime accounts and enforces the cost cap;
19
+ * `requestPersist()` where a discrete change or the streaming cadence says
20
+ * so (`shared/persist-decision.ts` over this loop's own dirty flags), AWAITED,
21
+ * so a platform STOP the runtime reads from that write aborts the signal
22
+ * before the next event is pulled; and `stopSignal`, checked at every event
23
+ * boundary and listened to inside the pull, where an abort cancels the SDK
24
+ * run — the one way a wedged stream is unblocked, and the same act for every
25
+ * cause of stopping (the runtime knows why; this loop never does).
26
+ *
27
+ * Until S2 M3 this loop armed its own stall watchdog, enforced the cost cap,
28
+ * read STOP from its own persist, and told a pause from the activity's
29
+ * cancellation signal; every one of those is the runtime's now, and the loop
30
+ * reports only `completed`, `first-denial` or `interrupted`.
22
31
  */
23
- import type { AgentExecutionStatus } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
24
- import { ExecutionControlSignal } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
25
32
  import type { SDKMessage, InteractionUpdate } from "@cursor/sdk";
26
- import { StallTimeoutError, type StallWatchdog } from "../../shared/stall-watchdog.js";
33
+ import type { TurnSink } from "../../harness/types.js";
27
34
  import { type ProgressCaptureState, type ProgressSubstrate } from "../../shared/filereview/progress.js";
28
35
  import type { MessageAccumulator } from "./message-translator.js";
29
36
  import type { DeltaEnricher } from "./delta-enricher.js";
30
37
  import type { TodoTracker } from "./todo-tracker.js";
31
38
  import type { StreamingUpdateScheduler } from "../../shared/streaming-scheduler.js";
32
- import type { UsageAccumulator } from "./usage-accumulator.js";
39
+ import type { CursorUsagePricer } from "./usage-pricing.js";
33
40
  import type { createCursorEventRecorder } from "./cursor-event-recorder.js";
34
41
  /**
35
42
  * The subset of the Cursor SDK `Run` the stream phase consumes. Kept structural
@@ -42,75 +49,47 @@ export interface StreamableRun {
42
49
  }
43
50
  export type CursorTurnEventRecorder = ReturnType<typeof createCursorEventRecorder>;
44
51
  /**
45
- * Why the turn's stream ended. The activity maps each reason to a terminal
46
- * outcome (see resolvePreBoundaryTerminal in index.ts): `completed` and
47
- * `first-denial` proceed to the turn boundary; the rest are pre-boundary
48
- * terminals that return or throw.
52
+ * Why the turn's stream ended. `completed` and `first-denial` proceed to the
53
+ * turn boundary; `interrupted` is the runtime's stop, and the adapter settles
54
+ * `interrupted` (the runtime classifies the cause from its own evidence).
49
55
  */
50
- export type TurnStreamReason = "completed" | "paused" | "stalled" | "first-denial" | "platform-stop" | "cost-cap";
56
+ export type TurnStreamReason = "completed" | "first-denial" | "interrupted";
51
57
  /**
52
- * Single owner for every flag the turn's stream produces. Before this, these
53
- * eleven fields lived as scattered `let`s co-written by FOUR concurrent
54
- * producers the SDK `onDelta`, the fs denial-watcher, the stall-watchdog, and
55
- * the loop the classic "who writes this field?" hazard. Consolidating them into
56
- * one object (created once per turn, shared by every producer, the epilogue, and
57
- * the outer catch/finally) makes ownership explicit and lets the primary turn and
58
- * both recovery retries drive the identical stream code.
59
- *
60
- * Field ownership is annotated per field: exactly one primary writer, plus any
61
- * documented producer/consumer handshakes.
58
+ * The flags the turn's stream produces that outlive the loop: created once per
59
+ * turn and shared by the primary stream, both recovery retries, the boundary
60
+ * and the settle, so every reader sees ONE source of truth. Field ownership
61
+ * is annotated per field: exactly one primary writer.
62
62
  */
63
63
  export interface TurnStreamState {
64
- /** Written by: onDelta (heartbeat cancel) + the loop's cancellation check. Read by: the loop, epilogue, outer catch. */
65
- pauseDetected: boolean;
66
- /** Written by: the stall-watchdog callback. Read by: the loop + epilogue. */
67
- stallDetected: boolean;
68
- stallError: StallTimeoutError | undefined;
69
- /** Written by: the loop (on the first ledger entry). Read by: the loop, epilogue, settleRetryTurn. */
64
+ /** Written by: the loop (on the first ledger entry). Read by: the loop, the boundary, settleRetryTurn. */
70
65
  firstDenialDetected: boolean;
71
66
  /** Written by: the fs denial-watcher (→ true) + the loop (→ false after a read). Read by: the loop. */
72
67
  denialLedgerDirty: boolean;
73
68
  /** Written by: the loop (the first-denial run.cancel()). Read by: the turn boundary. */
74
69
  denialCancelSettled: Promise<void> | undefined;
75
- /** Written by: the loop (a platform STOP signal from persist). Read by: the loop + epilogue. */
76
- platformStopSignaled: boolean;
77
- /** Written by: onDelta (a turn-ended usage delta pushed the estimate past max_cost_usd). Read by: the loop (cancel + break) + epilogue. */
78
- costCapExceeded: boolean;
79
70
  /** Written by: the loop (a stream ERROR status event) + the retry setup (reset). Read by: error classification. */
80
71
  streamErrorMessage: string | undefined;
81
- /** Written by: the loop (each tool_call). Read by: the stall-watchdog (message enrichment). */
82
- lastToolName: string | undefined;
83
72
  /** Written by: the loop. Read by: the event recorder, the persist cadence, and logs. */
84
73
  eventCount: number;
85
74
  /** Written + read by: onDelta (log the first turn's context attribution exactly once). */
86
75
  firstTurnAttributionLogged: boolean;
87
- /** The stall watchdog for the CURRENT stream, armed by consumeCursorTurnStream; held so onDelta can reset it and the activity's finally can stop it. */
88
- stallWatchdog: StallWatchdog | undefined;
89
76
  }
90
77
  export declare function newTurnStreamState(): TurnStreamState;
91
78
  /**
92
79
  * The subset of collaborators the shared onDelta needs. Broken out from
93
80
  * CursorTurnStreamDeps because the primary send happens BEFORE the accumulator
94
- * exists — onDelta only touches usage, the enricher, the heartbeat, and state.
81
+ * exists — onDelta only touches the sink, the pricer, the enricher, and state.
95
82
  */
96
83
  export interface TurnOnDeltaDeps {
97
- readonly usageAccumulator: UsageAccumulator;
84
+ readonly sink: TurnSink;
85
+ /** This harness's pricing of a `turn-ended` delta at the requested variant's rates. */
86
+ readonly usagePricer: CursorUsagePricer;
98
87
  readonly deltaEnricher: DeltaEnricher;
99
- /** Temporal heartbeat. Injected so the callback is testable without Temporal. */
100
- readonly heartbeat: () => void;
101
88
  readonly promptEstimatedTokens: number;
102
89
  readonly executionId: string;
103
90
  readonly state: TurnStreamState;
104
- /**
105
- * ExecutionConfig.max_cost_usd — 0/unset disables the cap. Checked by
106
- * onDelta after each turn-ended usage delta lands (the only point the
107
- * running estimate advances); the loop performs the actual run.cancel().
108
- * See cost-guard.ts for the semantics.
109
- */
110
- readonly maxCostUsd: number;
111
91
  }
112
92
  export interface CursorTurnStreamDeps extends TurnOnDeltaDeps {
113
- readonly status: AgentExecutionStatus;
114
93
  readonly accumulator: MessageAccumulator;
115
94
  readonly todoTracker: TodoTracker;
116
95
  readonly eventRecorder: CursorTurnEventRecorder | undefined;
@@ -120,19 +99,12 @@ export interface CursorTurnStreamDeps extends TurnOnDeltaDeps {
120
99
  readonly changeSetId: string;
121
100
  /** Session HITL dir holding the denial ledger; undefined → no gate installed → no first-denial stop. */
122
101
  readonly hitlDir: string | undefined;
123
- readonly stallTimeoutMs: number;
124
- /** The single size-bounded persist chokepoint. Returns the platform control signal. */
125
- readonly persist: (status: AgentExecutionStatus) => Promise<ExecutionControlSignal>;
126
- /** Temporal cancellation check. Injected so the loop is testable without Temporal. */
127
- readonly isCancelled: () => boolean;
128
102
  }
129
103
  /**
130
104
  * Build the shared onDelta callback. The Cursor SDK's fine-grained delta channel
131
105
  * carries token usage, live shell output, and precise tool-call timings; it also
132
- * fires far more often than discrete stream events, so it is where the stall
133
- * timer is reset during a long model generation. A heartbeat CancelledFailure
134
- * here flags the pause so the loop and epilogue treat it as a user pause (the
135
- * bare retry loops swallowed this — the cause of the mid-retry mislabel).
106
+ * fires far more often than discrete stream events, so it is where the runtime's
107
+ * stall timer is reset during a long model generation.
136
108
  */
137
109
  export declare function makeCursorTurnOnDelta(deps: TurnOnDeltaDeps): (event: {
138
110
  update: InteractionUpdate;
@@ -142,9 +114,7 @@ export declare function makeCursorTurnOnDelta(deps: TurnOnDeltaDeps): (event: {
142
114
  * transcript, todos, sub-agent tracking, live persist, and DD-32/DD-33 mid-run
143
115
  * progress, and reporting WHY the stream ended.
144
116
  *
145
- * Arms + stops its own stall watchdog (stored on `state.stallWatchdog` so the
146
- * shared onDelta can reset it and the activity's finally can stop it as a
147
- * backstop). Mutates `deps.status` + `deps.state` in place. The caller owns the
148
- * post-stream finalize and the terminal mapping.
117
+ * Mutates `deps.sink.status` + `deps.state` in place. The caller owns the
118
+ * post-stream finalize and the settle.
149
119
  */
150
120
  export declare function consumeCursorTurnStream(run: StreamableRun, deps: CursorTurnStreamDeps): Promise<TurnStreamReason>;
@@ -1,78 +1,64 @@
1
1
  /**
2
2
  * The Cursor harness's stream phase — the single per-event consumption loop that
3
3
  * turns a live Cursor SDK run into the streamed transcript, mid-run progress, and
4
- * the flags that decide how the turn ends.
4
+ * the one flag that decides how the turn goes on (the first-denial stop).
5
5
  *
6
- * Extracted from the activity entry point (index.ts) so that BOTH the primary
7
- * turn and the two recovery retries (poisoned-handle / transport-timeout) drive
8
- * the exact same code. The retries previously re-implemented a stripped "bare"
6
+ * Extracted from the activity entry point so that BOTH the primary turn and
7
+ * the two recovery retries (poisoned-handle / transport-timeout) drive the
8
+ * exact same code. The retries previously re-implemented a stripped "bare"
9
9
  * loop that dropped live persist, DD-32/DD-33 mid-run progress, sub-agent
10
- * tracking, the first-denial early stop, and correct pause/stall handling — so a
10
+ * tracking, the first-denial early stop, and correct pause handling — so a
11
11
  * retry froze the UI and mis-handled a mid-retry pause. One loop removes that
12
12
  * drift by construction.
13
13
  *
14
- * This mirrors the deep-agent harness's `streamExecution` seam
15
- * (execute-deep-agent/streaming.ts): injected `heartbeat`/`isCancelled` so it
16
- * runs without Temporal, a structural `StreamableRun` so it runs without the live
17
- * SDK, and a result (the terminal reason) instead of internal terminal mapping.
18
- * The one deliberate difference: this consumer REPORTS why the stream ended and
19
- * leaves the terminal MAPPING to the activity, because Cursor's mapping is
20
- * entangled with worker-shutdown-vs-pause disambiguation, the turn boundary,
21
- * structured output, and recovery retries all of which must stay in index.ts.
14
+ * What the loop asks of the runtime, through the sink (`harness/types.ts`):
15
+ * `recordActivity()` per event (with the tool name) and per delta, so the
16
+ * runtime's stall watchdog measures the engine; `reportUsage()` per
17
+ * `turn-ended` delta, priced here at the requested variant's rates
18
+ * (`usage-pricing.ts`), so the runtime accounts and enforces the cost cap;
19
+ * `requestPersist()` where a discrete change or the streaming cadence says
20
+ * so (`shared/persist-decision.ts` over this loop's own dirty flags), AWAITED,
21
+ * so a platform STOP the runtime reads from that write aborts the signal
22
+ * before the next event is pulled; and `stopSignal`, checked at every event
23
+ * boundary and listened to inside the pull, where an abort cancels the SDK
24
+ * run — the one way a wedged stream is unblocked, and the same act for every
25
+ * cause of stopping (the runtime knows why; this loop never does).
26
+ *
27
+ * Until S2 M3 this loop armed its own stall watchdog, enforced the cost cap,
28
+ * read STOP from its own persist, and told a pause from the activity's
29
+ * cancellation signal; every one of those is the runtime's now, and the loop
30
+ * reports only `completed`, `first-denial` or `interrupted`.
22
31
  */
23
- import { create } from "@bufbuild/protobuf";
24
- import { CancelledFailure } from "@temporalio/activity";
25
- import { ExecutionControlSignal } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
26
- import { StreamingUsageSummarySchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/usage_pb";
27
- import { startStallWatchdog, StallTimeoutError, } from "../../shared/stall-watchdog.js";
28
- import { shouldPersistStreamingStatus } from "./persist-decision.js";
32
+ import { shouldPersistStreamingStatus } from "../../shared/persist-decision.js";
29
33
  import { approvalDenials, readDenialLedger } from "./approval-state.js";
30
34
  import { captureFileChangeProgress, } from "../../shared/filereview/progress.js";
31
- import { costCapExceeded } from "./cost-guard.js";
32
35
  export function newTurnStreamState() {
33
36
  return {
34
- pauseDetected: false,
35
- stallDetected: false,
36
- stallError: undefined,
37
37
  firstDenialDetected: false,
38
38
  denialLedgerDirty: false,
39
39
  denialCancelSettled: undefined,
40
- platformStopSignaled: false,
41
- costCapExceeded: false,
42
40
  streamErrorMessage: undefined,
43
- lastToolName: undefined,
44
41
  eventCount: 0,
45
42
  firstTurnAttributionLogged: false,
46
- stallWatchdog: undefined,
47
43
  };
48
44
  }
49
45
  /**
50
46
  * Build the shared onDelta callback. The Cursor SDK's fine-grained delta channel
51
47
  * carries token usage, live shell output, and precise tool-call timings; it also
52
- * fires far more often than discrete stream events, so it is where the stall
53
- * timer is reset during a long model generation. A heartbeat CancelledFailure
54
- * here flags the pause so the loop and epilogue treat it as a user pause (the
55
- * bare retry loops swallowed this — the cause of the mid-retry mislabel).
48
+ * fires far more often than discrete stream events, so it is where the runtime's
49
+ * stall timer is reset during a long model generation.
56
50
  */
57
51
  export function makeCursorTurnOnDelta(deps) {
58
- const { usageAccumulator, deltaEnricher, heartbeat, promptEstimatedTokens, executionId, state, maxCostUsd } = deps;
52
+ const { sink, usagePricer, deltaEnricher, promptEstimatedTokens, executionId, state } = deps;
59
53
  return ({ update }) => {
60
- // Reset the stall timer on the delta channel too: a long model generation
61
- // emits token deltas but few discrete stream events, so resetting only in the
62
- // stream loop would false-positive a stall.
63
- state.stallWatchdog?.recordActivity();
54
+ // Progress on the delta channel too: a long model generation emits token
55
+ // deltas but few discrete stream events, and resetting only in the stream
56
+ // loop would false-positive a stall.
57
+ sink.recordActivity();
64
58
  if (update.type === "turn-ended" && update.usage) {
65
- usageAccumulator.addTurn(update.usage);
66
- // max_cost_usd enforcement (cost-guard.ts): the running estimate only
67
- // advances here, so this is the single check point. onDelta cannot reach
68
- // the run — the loop reads the flag and performs the clean cancel.
69
- if (!state.costCapExceeded
70
- && costCapExceeded(maxCostUsd, usageAccumulator.snapshot().estimatedCostUsd)) {
71
- state.costCapExceeded = true;
72
- console.warn(`ExecuteCursor cost cap exceeded: execution=${executionId}, ` +
73
- `estimatedCostUsd=${usageAccumulator.snapshot().estimatedCostUsd.toFixed(4)}, ` +
74
- `maxCostUsd=${maxCostUsd.toFixed(2)}`);
75
- }
59
+ // The running estimate advances only here; the runtime enforces the cap
60
+ // and aborts the signal, which the loop reads at the next boundary.
61
+ sink.reportUsage(usagePricer.price(update.usage));
76
62
  if (!state.firstTurnAttributionLogged) {
77
63
  state.firstTurnAttributionLogged = true;
78
64
  const sdkInputTokens = update.usage.inputTokens ?? 0;
@@ -83,16 +69,6 @@ export function makeCursorTurnOnDelta(deps) {
83
69
  }
84
70
  }
85
71
  deltaEnricher.processDelta(update);
86
- try {
87
- heartbeat();
88
- }
89
- catch (hbErr) {
90
- if (hbErr instanceof CancelledFailure) {
91
- state.pauseDetected = true;
92
- return;
93
- }
94
- throw hbErr;
95
- }
96
72
  };
97
73
  }
98
74
  /**
@@ -100,59 +76,38 @@ export function makeCursorTurnOnDelta(deps) {
100
76
  * transcript, todos, sub-agent tracking, live persist, and DD-32/DD-33 mid-run
101
77
  * progress, and reporting WHY the stream ended.
102
78
  *
103
- * Arms + stops its own stall watchdog (stored on `state.stallWatchdog` so the
104
- * shared onDelta can reset it and the activity's finally can stop it as a
105
- * backstop). Mutates `deps.status` + `deps.state` in place. The caller owns the
106
- * post-stream finalize and the terminal mapping.
79
+ * Mutates `deps.sink.status` + `deps.state` in place. The caller owns the
80
+ * post-stream finalize and the settle.
107
81
  */
108
82
  export async function consumeCursorTurnStream(run, deps) {
109
- const { status, accumulator, todoTracker, deltaEnricher, eventRecorder, scheduler, usageAccumulator, progressSubstrate, progressState, changeSetId, hitlDir, executionId, stallTimeoutMs, persist, heartbeat, isCancelled, state, } = deps;
110
- // Arm the stall watchdog now that the run exists. The activity's periodic
111
- // heartbeat proves the process is alive, not that the agent is progressing: if
112
- // the stream wedges (a tool call or model connection that never returns), no
113
- // event/delta arrives and the turn would hang forever. On stall we end the run
114
- // cleanly via the SDK's run.cancel() (guarded by supports("cancel")), which
115
- // unblocks the for-await; the caller then reports EXECUTION_FAILED with a
116
- // recognizable, actionable message.
117
- state.stallWatchdog = startStallWatchdog(stallTimeoutMs, (idleMs) => {
118
- state.stallDetected = true;
119
- state.stallError = new StallTimeoutError(idleMs, state.lastToolName ? `last tool: ${state.lastToolName}` : undefined);
120
- console.warn(`ExecuteCursor stall detected: execution=${executionId}, idleMs=${idleMs}, lastTool=${state.lastToolName ?? "none"}`);
83
+ const { sink, accumulator, todoTracker, deltaEnricher, eventRecorder, scheduler, progressSubstrate, progressState, changeSetId, hitlDir, executionId, state, } = deps;
84
+ const { status, stopSignal } = sink;
85
+ // The runtime's stop, whatever its cause, ends the run through the SDK's
86
+ // own cancel: that is what unblocks a wedged `for await` (a stall), and it
87
+ // stops the engine's tools and deltas from outliving the turn on every
88
+ // other cause too. Guarded by supports("cancel") as the loop's own cancels
89
+ // are; the teardown rejection it can cause is swallowed below.
90
+ const cancelOnStop = () => {
91
+ console.log(`ExecuteCursor stopping stream on the runtime's stop signal: execution=${executionId}`);
121
92
  if (run.supports?.("cancel")) {
122
93
  void run.cancel().catch((cancelErr) => {
123
- console.warn(`ExecuteCursor run.cancel() after stall failed (non-fatal): execution=${executionId}, ` +
94
+ console.warn(`ExecuteCursor run.cancel() after stop failed (non-fatal): execution=${executionId}, ` +
124
95
  `error=${cancelErr instanceof Error ? cancelErr.message : cancelErr}`);
125
96
  });
126
97
  }
127
- });
98
+ };
99
+ if (stopSignal.aborted) {
100
+ cancelOnStop();
101
+ return "interrupted";
102
+ }
103
+ stopSignal.addEventListener("abort", cancelOnStop, { once: true });
128
104
  try {
129
105
  for await (const event of run.stream()) {
130
- if (state.pauseDetected || isCancelled()) {
131
- state.pauseDetected = true;
132
- break;
133
- }
134
- if (state.stallDetected)
106
+ if (stopSignal.aborted)
135
107
  break;
136
- // Cost cap (cost-guard.ts): onDelta flagged the overrun on a turn-ended
137
- // usage delta; end the run through the same clean-cancel pattern as the
138
- // stall watchdog and the first-denial stop. Fire-and-forget is correct
139
- // here — nothing downstream waits on this turn's agent (unlike the
140
- // first-denial stop, whose ledger read needs a stopped agent).
141
- if (state.costCapExceeded) {
142
- console.log(`ExecuteCursor stopping stream at cost cap: execution=${executionId}`);
143
- if (run.supports?.("cancel")) {
144
- void run.cancel().catch((cancelErr) => {
145
- console.warn(`ExecuteCursor run.cancel() after cost cap failed (non-fatal): execution=${executionId}, ` +
146
- `error=${cancelErr instanceof Error ? cancelErr.message : cancelErr}`);
147
- });
148
- }
149
- break;
150
- }
151
- // Progress: reset the stall timer on every stream event.
152
- state.stallWatchdog.recordActivity();
153
- if (event.type === "tool_call" && typeof event.name === "string") {
154
- state.lastToolName = event.name;
155
- }
108
+ // Progress: reset the runtime's stall timer on every stream event,
109
+ // naming the tool so a stall's copy can say `last tool: shell`.
110
+ sink.recordActivity(event.type === "tool_call" && typeof event.name === "string" ? event.name : undefined);
156
111
  eventRecorder?.record(event, state.eventCount);
157
112
  accumulator.processEvent(event);
158
113
  todoTracker.processEvent(event);
@@ -216,9 +171,6 @@ export async function consumeCursorTurnStream(run, deps) {
216
171
  todosDirty: todoTracker.isDirty,
217
172
  contentDirty: accumulator.isDirty,
218
173
  }, scheduler, state.eventCount);
219
- if (usageAccumulator.hasTurns) {
220
- status.streamingUsage = create(StreamingUsageSummarySchema, usageAccumulator.snapshot());
221
- }
222
174
  if (shouldPersist) {
223
175
  // Sync sub-agent executions into status before every persist so the live
224
176
  // UI reflects delegation (including the IN_PROGRESS state) while the
@@ -236,54 +188,37 @@ export async function consumeCursorTurnStream(run, deps) {
236
188
  state: progressState,
237
189
  });
238
190
  }
239
- const signal = await persist(status);
191
+ // Awaited: the runtime reads the control plane's answer to this write,
192
+ // and a STOP must be seen at the next event boundary, not one event late.
193
+ await sink.requestPersist();
240
194
  deltaEnricher.markPersisted();
241
195
  todoTracker.markPersisted();
242
196
  accumulator.markPersisted();
243
197
  scheduler.markUpdateSent(state.eventCount);
244
- heartbeat();
245
- if (signal === ExecutionControlSignal.STOP) {
246
- state.platformStopSignaled = true;
247
- console.warn(`ExecuteCursor platform stop signal received: execution=${executionId}`);
248
- }
249
- }
250
- if (state.platformStopSignaled) {
251
- console.log(`ExecuteCursor stopping stream due to platform stop signal: execution=${executionId}`);
252
- break;
253
198
  }
254
199
  }
255
200
  }
256
201
  catch (streamErr) {
257
- // run.cancel() — from the stall watchdog, the first-denial stop, or the
258
- // cost-cap stop — can make the stream iterator reject as it tears down;
259
- // that is the expected teardown for all three, so swallow it and fall
260
- // through. Anything else is a genuine stream failure — rethrow it to the
261
- // activity's error handler.
262
- if (!state.stallDetected && !state.firstDenialDetected && !state.costCapExceeded) {
202
+ // run.cancel() — from the runtime's stop or the first-denial stop can
203
+ // make the stream iterator reject as it tears down; that is the expected
204
+ // teardown for both, so swallow it and fall through. Anything else is a
205
+ // genuine stream failure — rethrow it to the adapter's error handler.
206
+ if (!stopSignal.aborted && !state.firstDenialDetected) {
263
207
  throw streamErr;
264
208
  }
265
209
  console.warn(`ExecuteCursor stream ended via cancel: execution=${executionId}, ` +
266
- `stall=${state.stallDetected}, firstDenial=${state.firstDenialDetected}, ` +
267
- `costCap=${state.costCapExceeded}`);
210
+ `stopped=${stopSignal.aborted}, firstDenial=${state.firstDenialDetected}`);
268
211
  }
269
212
  finally {
270
- state.stallWatchdog.stop();
213
+ stopSignal.removeEventListener("abort", cancelOnStop);
271
214
  }
272
- // Report why the stream ended, in the same precedence the activity's epilogue
273
- // applies: a stall (an EXECUTION_FAILED terminal) outranks everything; a
274
- // platform stop, a cost-cap stop, and a first denial are distinct
275
- // return/proceed outcomes; a pause is the fallback for a cancellation with
276
- // no other cause.
277
- if (state.stallDetected)
278
- return "stalled";
279
- if (state.platformStopSignaled)
280
- return "platform-stop";
281
- if (state.costCapExceeded)
282
- return "cost-cap";
215
+ // Report why the stream ended: the runtime's stop outranks a first denial
216
+ // (there is no review to open on a stopped turn), a first denial outranks a
217
+ // natural end.
218
+ if (stopSignal.aborted)
219
+ return "interrupted";
283
220
  if (state.firstDenialDetected)
284
221
  return "first-denial";
285
- if (state.pauseDetected || isCancelled())
286
- return "paused";
287
222
  return "completed";
288
223
  }
289
224
  //# sourceMappingURL=turn-stream.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"turn-stream.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/turn-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,8DAA8D,CAAC;AACtG,OAAO,EAAE,2BAA2B,EAAE,MAAM,+DAA+D,CAAC;AAE5G,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAElB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EACL,yBAAyB,GAG1B,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAoElD,MAAM,UAAU,kBAAkB;IAChC,OAAO;QAC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E;QACxE,yEAAyE;QACzE,wEAAwE;QACxE,sEAAsE;QACtE,IAAI,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC;YACtD,MAAM,SAAS,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,IAAI,CACV,oDAAoD,WAAW,IAAI;YACjE,WAAW,UAAU,CAAC,OAAO,iBAAiB,KAAK,CAAC,mBAAmB,EAAE,CAC5E,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACxD,CAAC;IAED,0EAA0E;IAC1E,4EAA4E;IAC5E,eAAe;IACf,IAAI,UAAU,CAAC,OAAO;QAAE,OAAO,aAAa,CAAC;IAC7C,IAAI,KAAK,CAAC,mBAAmB;QAAE,OAAO,cAAc,CAAC;IACrD,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * One Cursor engine turn — the SDK slice of the Cursor harness, behind the
3
+ * turn runtime's contract (`harness/types.ts`).
4
+ *
5
+ * `runCursorTurn` is what `adapter.ts`'s `runTurn` delegates to: the HITL
6
+ * gate, the agent (parked, created or resumed), the prompt, the stream, the
7
+ * turn boundary, `run.wait()` and its recovery spines, and its own teardown
8
+ * (the denial watcher, the gate, the OTel span, and what becomes of the agent
9
+ * handle). Everything else about a turn is the runtime's
10
+ * (`harness/run-turn.ts`): the resolution phases, the persist chokepoint, the
11
+ * watchdog, the cost cap, the interruption table, the completion epilogue,
12
+ * the lock.
13
+ *
14
+ * This module is where `@cursor/sdk` enters the adapter's graph (through
15
+ * `turn-setup.ts` and its siblings), which is WHY it is a separate module
16
+ * from `adapter.ts` and is loaded there with a dynamic import inside `boot`:
17
+ * the adapter's HTTP/2 interceptor must patch `node:http2` before the SDK
18
+ * (and, through it, `@connectrpc/connect-node`) is first imported, and the
19
+ * composition roots import `adapter.ts` before they boot it. Nothing outside
20
+ * `adapter.ts` imports this module.
21
+ *
22
+ * Never throws out of `runCursorTurn` (an SDK failure is `failed` with the
23
+ * classifier's sentence; an unexpected exception is `failed` on the
24
+ * `internal` surface; a `CancelledFailure` never exists here), never branches
25
+ * on why `stopSignal` aborted, never writes a phase or a terminal copy, never
26
+ * imports `@temporalio/*` (`__tests__/adapter-is-temporal-free.test.ts`).
27
+ *
28
+ * Engine disposition, one rule per outcome (Q-S2-6): the agent is PARKED
29
+ * for the session's next turn on every exit but a failure — `completed`,
30
+ * `cancelled`, `awaiting_approval` and `interrupted` alike (a wedged handle
31
+ * after a stall is caught by the poisoned-handle recovery on the next turn;
32
+ * before S2 a pause, a shutdown and a stall dropped the handle, leaking the
33
+ * executor lease). A `failed` turn keeps the orchestrator's three
34
+ * dispositions: an engine-reported failure parks (a bad key is not a bad
35
+ * handle), a user-actionable failure closes, an internal failure drops.
36
+ *
37
+ * Extracted from `index.ts` `executeCursorInner` at S2 M3b and moved out of
38
+ * `adapter.ts` at S2 M5; the seventeen hermetic goldens under `__tests__/hermetic/`
39
+ * pin the result byte for byte.
40
+ */
41
+ import type { TurnInput, TurnOutcome, TurnSink } from "../../harness/types.js";
42
+ import { type CursorAdapterConfig } from "./turn-setup.js";
43
+ export declare function runCursorTurn(input: TurnInput, sink: TurnSink, config: CursorAdapterConfig): Promise<TurnOutcome>;