@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
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The one way a turn is told to stop, and the runtime's record of why.
3
+ *
4
+ * The adapter contract gives an engine ONE signal (`TurnSink.stopSignal`) for
5
+ * every cause of stopping and forbids it to branch on the cause; the runtime
6
+ * keeps the cause here, as evidence its terminal table reads after the
7
+ * adapter settles `interrupted`. Four producers abort the signal: the stall
8
+ * watchdog, the usage accumulator's cost cap, the persist chokepoint's
9
+ * platform STOP, and Temporal's own cancellation (a pause, a worker
10
+ * shutdown, a heartbeat timeout — told apart later from the signal's reason,
11
+ * `shared/worker-shutdown.ts`). The first cause wins the abort; every cause
12
+ * is recorded, because the table's precedence (stall over cost cap over
13
+ * cancellation over platform stop) is decided at settlement, not at abort.
14
+ *
15
+ * Nothing here is engine-specific and nothing here persists; the Cursor
16
+ * orchestrator kept the same facts as flags on its stream state
17
+ * (`turn-stream.ts` `TurnStreamState`, before S2 M3 moved them out).
18
+ */
19
+
20
+ import type { StallTimeoutError } from "../shared/stall-watchdog.js";
21
+
22
+ /** Why the runtime stopped the turn. */
23
+ export type StopCause =
24
+ | { readonly kind: "stall"; readonly error: StallTimeoutError }
25
+ | { readonly kind: "cost-cap" }
26
+ | { readonly kind: "platform-stop" }
27
+ | { readonly kind: "cancellation" };
28
+
29
+ /** What the terminal table reads. Each field is set by the first cause of its kind and never cleared. */
30
+ export interface StopEvidence {
31
+ readonly stall: StallTimeoutError | undefined;
32
+ readonly costCapExceeded: boolean;
33
+ readonly platformStop: boolean;
34
+ /** Temporal delivered a cancellation; its reason is on the cancellation signal itself. */
35
+ readonly cancellation: boolean;
36
+ }
37
+
38
+ export class StopController {
39
+ private readonly controller = new AbortController();
40
+ private stall: StallTimeoutError | undefined;
41
+ private costCapExceeded = false;
42
+ private platformStop = false;
43
+ private cancellation = false;
44
+
45
+ /** The adapter's `stopSignal`. Its `reason` is the first cause's kind, a diagnostic only. */
46
+ get signal(): AbortSignal {
47
+ return this.controller.signal;
48
+ }
49
+
50
+ get evidence(): StopEvidence {
51
+ return {
52
+ stall: this.stall,
53
+ costCapExceeded: this.costCapExceeded,
54
+ platformStop: this.platformStop,
55
+ cancellation: this.cancellation,
56
+ };
57
+ }
58
+
59
+ /** Record a cause and abort the signal (idempotent per cause; the signal aborts once). */
60
+ stop(cause: StopCause): void {
61
+ switch (cause.kind) {
62
+ case "stall":
63
+ this.stall ??= cause.error;
64
+ break;
65
+ case "cost-cap":
66
+ this.costCapExceeded = true;
67
+ break;
68
+ case "platform-stop":
69
+ this.platformStop = true;
70
+ break;
71
+ case "cancellation":
72
+ this.cancellation = true;
73
+ break;
74
+ default: {
75
+ const exhaustive: never = cause;
76
+ throw new Error(`StopController: unknown stop cause ${JSON.stringify(exhaustive)}`);
77
+ }
78
+ }
79
+ if (!this.controller.signal.aborted) {
80
+ this.controller.abort(cause.kind);
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,276 @@
1
+ /**
2
+ * The terminal table: every way a turn ends, as data — the phase it writes,
3
+ * the `error` it sets, the system rows it appends, whether it stamps
4
+ * `completedAt`, and whether the activity RETURNS the slim status or THROWS
5
+ * a `CancelledFailure` — with one function that applies an arm to a status.
6
+ *
7
+ * Why data and not one function per arm: the copy is the user-facing
8
+ * contract of the runner (the hermetic goldens pin every string below byte
9
+ * for byte, `activities/execute-cursor/__tests__/hermetic/`), and a table a
10
+ * reader can scan is how that contract stays reviewable. The native
11
+ * harness's `execute-deep-agent/streaming-terminal.ts` keeps one function
12
+ * per arm; S3 aligns the two (P-1's copy alignment) with both in view.
13
+ *
14
+ * The throw-vs-return rule, unchanged from the orchestrator it replaces:
15
+ * - RETURN when a Temporal retry would only repeat the outcome — a stall
16
+ * would wedge again, an exhausted budget would burn again, a platform
17
+ * stop is the platform's decision, a failed engine would fail the same
18
+ * prompt the same way, a completed turn is complete.
19
+ * - THROW `CancelledFailure` when the workflow must see the activity as
20
+ * cancelled — the orchestrator's pause, the runner's own drain, and an
21
+ * infrastructure cancel it delivered — with the message the control
22
+ * planes recognise.
23
+ *
24
+ * An arm's rows are appended exactly once, by `applyTerminalArm`, and an arm
25
+ * is persisted exactly once, by `run-turn.ts`'s `settleWith` — the one
26
+ * writer of a terminal. The orchestrator this table replaced appended the
27
+ * three THROW arms' rows twice (its throw fell into its own catch, which
28
+ * wrote the copy again); S2 reproduced that on purpose so the goldens could
29
+ * pin the wire byte for byte, and the PR after S2 removed it with a reviewed
30
+ * golden regeneration (stigmer#1054, Q-S2-4).
31
+ */
32
+
33
+ import { create } from "@bufbuild/protobuf";
34
+ import type { AgentExecutionStatus } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
35
+ import { AgentMessageSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
36
+ import { ExecutionPhase, MessageType } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
37
+
38
+ import { COST_LIMIT_USER_COPY, formatCostLimitError } from "../shared/cost-guard.js";
39
+ import { formatStallFailure, type StallTimeoutError } from "../shared/stall-watchdog.js";
40
+ import { utcTimestamp } from "../shared/status.js";
41
+ import type { WorkspaceLockTimeoutError } from "../shared/workspace/workspace-lock.js";
42
+ import type { FailureSurface } from "./types.js";
43
+
44
+ /** How the activity ends after the arm is written and persisted. */
45
+ export type TerminalDisposition = { readonly kind: "return" } | { readonly kind: "throw"; readonly message: string };
46
+
47
+ /** One arm of the table: what to write, and how to end. */
48
+ export interface TerminalArm {
49
+ readonly phase: ExecutionPhase;
50
+ /** `status.error`; absent leaves it as it is (a pause is not an error). */
51
+ readonly error?: string;
52
+ /** System rows appended in order, each exactly once. */
53
+ readonly rows: readonly string[];
54
+ /** Stamp `completedAt`; a paused turn is not complete. */
55
+ readonly completes: boolean;
56
+ readonly disposition: TerminalDisposition;
57
+ }
58
+
59
+ const RETURN: TerminalDisposition = { kind: "return" };
60
+
61
+ /** The fixed strings of the table, in one place. Every one is pinned by a golden or a hermetic assertion. */
62
+ export const TERMINAL_COPY = {
63
+ pause: {
64
+ row: "Execution paused by user. Use resume to continue.",
65
+ throwMessage: "Activity paused by orchestrator",
66
+ throwMessageAfterError: "Activity paused by orchestrator (error during pause)",
67
+ },
68
+ workerShutdown: {
69
+ error: "Execution interrupted: runner worker was shut down. Retry or resume.",
70
+ row: "Execution interrupted: the runner worker was shut down while the agent was still running. You can retry or resume.",
71
+ throwMessage: "Activity cancelled (worker shutdown, not user pause)",
72
+ },
73
+ infrastructureCancel: {
74
+ error: "Execution interrupted: agent was unresponsive (heartbeat timeout). Retry or resume.",
75
+ row: "Execution interrupted: the agent was unresponsive for too long. You can retry or resume.",
76
+ throwMessage: "Activity cancelled (heartbeat timeout, not user pause)",
77
+ throwMessageAfterError: "Activity cancelled (infrastructure, not user pause)",
78
+ },
79
+ platformStop: {
80
+ row: "Execution stopped by the platform.",
81
+ },
82
+ rejectedByUser: {
83
+ error: "Execution rejected by user",
84
+ row: "Execution was rejected by the user during tool approval.",
85
+ },
86
+ fileReview: {
87
+ applyFailedPrefix: "Some approved file changes could not be applied because the file changed after review: ",
88
+ discardedPrefix: "Some proposed file changes were discarded by the user and were not applied: ",
89
+ },
90
+ internalFailure: {
91
+ row: "Internal system error occurred. Please contact support if this issue persists.",
92
+ },
93
+ } as const;
94
+
95
+ // ── The arms ────────────────────────────────────────────────────────────────
96
+
97
+ /** The watchdog cancelled a turn that made no progress. RETURN: an identical prompt would wedge again. */
98
+ export function stallArm(error: StallTimeoutError): TerminalArm {
99
+ return {
100
+ phase: ExecutionPhase.EXECUTION_FAILED,
101
+ error: formatStallFailure(error),
102
+ rows: [
103
+ `Execution failed: the agent made no progress for too long and was stopped (${error.message}). You can retry or resume.`,
104
+ ],
105
+ completes: true,
106
+ disposition: RETURN,
107
+ };
108
+ }
109
+
110
+ /**
111
+ * The cost cap stopped the turn. TERMINATED, not FAILED: the platform
112
+ * deliberately stopped the run, work is checkpointed, and the conversation
113
+ * continues on the next message (the recursion-limit precedent in
114
+ * `execute-deep-agent/streaming-terminal.ts`). RETURN: a retry would burn
115
+ * the same budget again.
116
+ */
117
+ export function costCapArm(maxCostUsd: number, estimatedCostUsd: number): TerminalArm {
118
+ return {
119
+ phase: ExecutionPhase.EXECUTION_TERMINATED,
120
+ error: formatCostLimitError(maxCostUsd, estimatedCostUsd),
121
+ rows: [COST_LIMIT_USER_COPY],
122
+ completes: true,
123
+ disposition: RETURN,
124
+ };
125
+ }
126
+
127
+ /** The runner is draining. Not a user pause: FAILED with the shutdown copy, thrown as cancelled. */
128
+ export function workerShutdownArm(): TerminalArm {
129
+ return {
130
+ phase: ExecutionPhase.EXECUTION_FAILED,
131
+ error: TERMINAL_COPY.workerShutdown.error,
132
+ rows: [TERMINAL_COPY.workerShutdown.row],
133
+ completes: true,
134
+ disposition: { kind: "throw", message: TERMINAL_COPY.workerShutdown.throwMessage },
135
+ };
136
+ }
137
+
138
+ /** The orchestrator paused the execution. Not an error, not complete; thrown as cancelled. */
139
+ export function pauseArm(): TerminalArm {
140
+ return {
141
+ phase: ExecutionPhase.EXECUTION_PAUSED,
142
+ rows: [TERMINAL_COPY.pause.row],
143
+ completes: false,
144
+ disposition: { kind: "throw", message: TERMINAL_COPY.pause.throwMessage },
145
+ };
146
+ }
147
+
148
+ /** Temporal cancelled for its own reason (a heartbeat timeout). FAILED with the unresponsive copy, thrown as cancelled. */
149
+ export function infrastructureCancelArm(): TerminalArm {
150
+ return {
151
+ phase: ExecutionPhase.EXECUTION_FAILED,
152
+ error: TERMINAL_COPY.infrastructureCancel.error,
153
+ rows: [TERMINAL_COPY.infrastructureCancel.row],
154
+ completes: true,
155
+ disposition: { kind: "throw", message: TERMINAL_COPY.infrastructureCancel.throwMessage },
156
+ };
157
+ }
158
+
159
+ /** The control plane answered STOP. A clean COMPLETED early exit. */
160
+ export function platformStopArm(): TerminalArm {
161
+ return {
162
+ phase: ExecutionPhase.EXECUTION_COMPLETED,
163
+ rows: [TERMINAL_COPY.platformStop.row],
164
+ completes: true,
165
+ disposition: RETURN,
166
+ };
167
+ }
168
+
169
+ /** Another turn held the primary tree past the lock timeout. RETURN: a retry would queue behind the same holder. */
170
+ export function workspaceLockTimeoutArm(error: WorkspaceLockTimeoutError): TerminalArm {
171
+ return {
172
+ phase: ExecutionPhase.EXECUTION_FAILED,
173
+ error: error.message,
174
+ rows: [`Execution failed: ${error.message}`],
175
+ completes: true,
176
+ disposition: RETURN,
177
+ };
178
+ }
179
+
180
+ /** An adjudicated irreversible action (shell / MCP) was REJECTed. */
181
+ export function rejectedByUserArm(): TerminalArm {
182
+ return {
183
+ phase: ExecutionPhase.EXECUTION_FAILED,
184
+ error: TERMINAL_COPY.rejectedByUser.error,
185
+ rows: [TERMINAL_COPY.rejectedByUser.row],
186
+ completes: true,
187
+ disposition: RETURN,
188
+ };
189
+ }
190
+
191
+ /**
192
+ * A pure file-review resume: the agent already finished its turn during
193
+ * capture, so keeping or discarding a change never re-prompts it
194
+ * (Cursor-like); the reconcile is the whole act and the execution is
195
+ * complete. A failed reconcile (what-you-approve-is-what-applies could not
196
+ * be honored) tells the human; a discard tells the human which files were
197
+ * reverted — the agent's native context still believes those edits stuck,
198
+ * and any edit it makes from that belief is re-surfaced next turn (the
199
+ * structural safety net; design-decisions/capture-reject-next-turn-resync-not-built.md).
200
+ */
201
+ export function fileReviewResolvedArm(settlement: {
202
+ readonly failed: boolean;
203
+ readonly failureDetail: string;
204
+ readonly discardedPaths: readonly string[];
205
+ }): TerminalArm {
206
+ const rows: string[] = [];
207
+ if (settlement.failed) {
208
+ rows.push(`${TERMINAL_COPY.fileReview.applyFailedPrefix}${settlement.failureDetail}.`);
209
+ } else if (settlement.discardedPaths.length > 0) {
210
+ rows.push(`${TERMINAL_COPY.fileReview.discardedPrefix}${settlement.discardedPaths.join(", ")}.`);
211
+ }
212
+ return { phase: ExecutionPhase.EXECUTION_COMPLETED, rows, completes: true, disposition: RETURN };
213
+ }
214
+
215
+ /**
216
+ * The adapter settled `failed`. The surface picks the copy (the three shapes
217
+ * the Cursor orchestrator wrote, `types.ts` `FailureSurface`); `message` is
218
+ * the adapter's user-facing sentence and becomes `status.error` whole.
219
+ */
220
+ export function failedArm(message: string, surface: FailureSurface): TerminalArm {
221
+ const rows = ((): readonly string[] => {
222
+ switch (surface) {
223
+ case "engine":
224
+ return [];
225
+ case "actionable":
226
+ return [`Execution failed: ${message}`];
227
+ case "internal":
228
+ return [TERMINAL_COPY.internalFailure.row, `Error details: ${message}`];
229
+ default: {
230
+ const exhaustive: never = surface;
231
+ throw new Error(`terminal table: unknown failure surface ${String(exhaustive)}`);
232
+ }
233
+ }
234
+ })();
235
+ return { phase: ExecutionPhase.EXECUTION_FAILED, error: message, rows, completes: true, disposition: RETURN };
236
+ }
237
+
238
+ /**
239
+ * An error the runtime caught itself, outside any adapter (a resolution
240
+ * phase, the epilogue): the boilerplate row and the described error as the
241
+ * details, with `status.error` carrying the `Execution failed:` prefix the
242
+ * orchestrator's generic arm always wrote (`describeExecutionError` supplies
243
+ * the two parts). The one arm whose `error` and details row differ, kept as
244
+ * it was because the resolution-error golden pins both.
245
+ */
246
+ export function unexpectedErrorArm(errorType: string, errorMessage: string): TerminalArm {
247
+ const described = `[${errorType}] ${errorMessage}`;
248
+ return {
249
+ phase: ExecutionPhase.EXECUTION_FAILED,
250
+ error: `Execution failed: ${described}`,
251
+ rows: [TERMINAL_COPY.internalFailure.row, `Error details: ${described}`],
252
+ completes: true,
253
+ disposition: RETURN,
254
+ };
255
+ }
256
+
257
+ // ── Applying an arm ─────────────────────────────────────────────────────────
258
+
259
+ /**
260
+ * Append system rows, each with its own timestamp, in order. Module-private
261
+ * on purpose: rows reach a status only through `applyTerminalArm`, so no
262
+ * caller can append an arm's copy a second time (the shape of stigmer#1054).
263
+ */
264
+ function appendSystemRows(status: AgentExecutionStatus, rows: readonly string[]): void {
265
+ for (const content of rows) {
266
+ status.messages.push(create(AgentMessageSchema, { type: MessageType.MESSAGE_SYSTEM, content, timestamp: utcTimestamp() }));
267
+ }
268
+ }
269
+
270
+ /** Write an arm onto the status: phase, error, completion stamp, rows. The caller persists and disposes. */
271
+ export function applyTerminalArm(status: AgentExecutionStatus, arm: TerminalArm): void {
272
+ status.phase = arm.phase;
273
+ if (arm.error !== undefined) status.error = arm.error;
274
+ if (arm.completes) status.completedAt = utcTimestamp();
275
+ appendSystemRows(status, arm.rows);
276
+ }