@stigmer/runner 3.14.1 → 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 (320) 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 +28 -5
  9. package/dist/__test-utils__/hermetic-activity.js +23 -7
  10. package/dist/__test-utils__/hermetic-activity.js.map +1 -1
  11. package/dist/__test-utils__/mock-workspace.d.ts +15 -0
  12. package/dist/__test-utils__/mock-workspace.js +21 -0
  13. package/dist/__test-utils__/mock-workspace.js.map +1 -0
  14. package/dist/__test-utils__/model-registry-fixture.d.ts +56 -0
  15. package/dist/__test-utils__/model-registry-fixture.js +66 -0
  16. package/dist/__test-utils__/model-registry-fixture.js.map +1 -0
  17. package/dist/__test-utils__/turn-input-fixture.d.ts +60 -0
  18. package/dist/__test-utils__/turn-input-fixture.js +118 -0
  19. package/dist/__test-utils__/turn-input-fixture.js.map +1 -0
  20. package/dist/activities/execute-cursor/__test-utils__/contract-subject.d.ts +107 -0
  21. package/dist/activities/execute-cursor/__test-utils__/contract-subject.js +344 -0
  22. package/dist/activities/execute-cursor/__test-utils__/contract-subject.js.map +1 -0
  23. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.d.ts +20 -0
  24. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js +58 -0
  25. package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js.map +1 -1
  26. package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js +2 -32
  27. package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js.map +1 -1
  28. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.d.ts +38 -62
  29. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js +47 -121
  30. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js.map +1 -1
  31. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.d.ts +17 -1
  32. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js +27 -4
  33. package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js.map +1 -1
  34. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.d.ts +52 -11
  35. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js +66 -7
  36. package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js.map +1 -1
  37. package/dist/activities/execute-cursor/adapter.d.ts +55 -0
  38. package/dist/activities/execute-cursor/adapter.js +119 -0
  39. package/dist/activities/execute-cursor/adapter.js.map +1 -0
  40. package/dist/activities/execute-cursor/approval-state.d.ts +2 -2
  41. package/dist/activities/execute-cursor/approval-state.js.map +1 -1
  42. package/dist/activities/execute-cursor/capture-flow.d.ts +15 -30
  43. package/dist/activities/execute-cursor/capture-flow.js +17 -26
  44. package/dist/activities/execute-cursor/capture-flow.js.map +1 -1
  45. package/dist/activities/execute-cursor/cursor-capabilities.d.ts +23 -0
  46. package/dist/activities/execute-cursor/cursor-capabilities.js +33 -0
  47. package/dist/activities/execute-cursor/cursor-capabilities.js.map +1 -0
  48. package/dist/activities/execute-cursor/cursor-mcp-config.d.ts +2 -2
  49. package/dist/activities/execute-cursor/cursor-mcp-config.js.map +1 -1
  50. package/dist/activities/execute-cursor/fetch-interceptor.d.ts +15 -25
  51. package/dist/activities/execute-cursor/fetch-interceptor.js +39 -33
  52. package/dist/activities/execute-cursor/fetch-interceptor.js.map +1 -1
  53. package/dist/activities/execute-cursor/http2-interceptor.d.ts +21 -17
  54. package/dist/activities/execute-cursor/http2-interceptor.js +38 -31
  55. package/dist/activities/execute-cursor/http2-interceptor.js.map +1 -1
  56. package/dist/activities/execute-cursor/message-translator.d.ts +28 -19
  57. package/dist/activities/execute-cursor/message-translator.js +76 -27
  58. package/dist/activities/execute-cursor/message-translator.js.map +1 -1
  59. package/dist/activities/execute-cursor/prompt-builder.d.ts +180 -11
  60. package/dist/activities/execute-cursor/prompt-builder.js +171 -0
  61. package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
  62. package/dist/activities/execute-cursor/rejection-capture.d.ts +3 -6
  63. package/dist/activities/execute-cursor/rejection-capture.js +5 -7
  64. package/dist/activities/execute-cursor/rejection-capture.js.map +1 -1
  65. package/dist/activities/execute-cursor/session-lifecycle.d.ts +1 -4
  66. package/dist/activities/execute-cursor/session-lifecycle.js.map +1 -1
  67. package/dist/activities/execute-cursor/turn-boundary.d.ts +1 -1
  68. package/dist/activities/execute-cursor/turn-settle.d.ts +49 -0
  69. package/dist/activities/execute-cursor/turn-settle.js +507 -0
  70. package/dist/activities/execute-cursor/turn-settle.js.map +1 -0
  71. package/dist/activities/execute-cursor/turn-setup.d.ts +173 -0
  72. package/dist/activities/execute-cursor/turn-setup.js +496 -0
  73. package/dist/activities/execute-cursor/turn-setup.js.map +1 -0
  74. package/dist/activities/execute-cursor/turn-stream.d.ts +41 -71
  75. package/dist/activities/execute-cursor/turn-stream.js +70 -135
  76. package/dist/activities/execute-cursor/turn-stream.js.map +1 -1
  77. package/dist/activities/execute-cursor/turn.d.ts +43 -0
  78. package/dist/activities/execute-cursor/turn.js +222 -0
  79. package/dist/activities/execute-cursor/turn.js.map +1 -0
  80. package/dist/activities/execute-cursor/usage-pricing.d.ts +38 -0
  81. package/dist/activities/execute-cursor/usage-pricing.js +50 -0
  82. package/dist/activities/execute-cursor/usage-pricing.js.map +1 -0
  83. package/dist/activities/execute-deep-agent/approval-file-change.d.ts +1 -1
  84. package/dist/activities/execute-deep-agent/approval-file-change.js +1 -1
  85. package/dist/activities/execute-deep-agent/environment.js +1 -1
  86. package/dist/activities/execute-deep-agent/environment.js.map +1 -1
  87. package/dist/activities/execute-deep-agent/setup.js +3 -2
  88. package/dist/activities/execute-deep-agent/setup.js.map +1 -1
  89. package/dist/activities/hydrate-workflow-execution.js +1 -1
  90. package/dist/activities/hydrate-workflow-execution.js.map +1 -1
  91. package/dist/config.d.ts +15 -0
  92. package/dist/config.js.map +1 -1
  93. package/dist/harness/capabilities.d.ts +16 -0
  94. package/dist/harness/capabilities.js +1 -0
  95. package/dist/harness/capabilities.js.map +1 -1
  96. package/dist/harness/persist-chokepoint.d.ts +74 -0
  97. package/dist/harness/persist-chokepoint.js +88 -0
  98. package/dist/harness/persist-chokepoint.js.map +1 -0
  99. package/dist/harness/registry.d.ts +44 -5
  100. package/dist/harness/registry.js +61 -5
  101. package/dist/harness/registry.js.map +1 -1
  102. package/dist/harness/run-turn.d.ts +53 -0
  103. package/dist/harness/run-turn.js +528 -0
  104. package/dist/harness/run-turn.js.map +1 -0
  105. package/dist/harness/stop-controller.d.ts +50 -0
  106. package/dist/harness/stop-controller.js +62 -0
  107. package/dist/harness/stop-controller.js.map +1 -0
  108. package/dist/harness/terminal-table.d.ts +141 -0
  109. package/dist/harness/terminal-table.js +239 -0
  110. package/dist/harness/terminal-table.js.map +1 -0
  111. package/dist/harness/turn-context.d.ts +523 -0
  112. package/dist/harness/turn-context.js +739 -0
  113. package/dist/harness/turn-context.js.map +1 -0
  114. package/dist/harness/types.d.ts +232 -52
  115. package/dist/harness/types.js +17 -8
  116. package/dist/harness/types.js.map +1 -1
  117. package/dist/harness/usage-accumulator.d.ts +68 -0
  118. package/dist/harness/usage-accumulator.js +101 -0
  119. package/dist/harness/usage-accumulator.js.map +1 -0
  120. package/dist/harness-adapters.d.ts +27 -0
  121. package/dist/harness-adapters.js +28 -0
  122. package/dist/harness-adapters.js.map +1 -0
  123. package/dist/main.js.map +1 -1
  124. package/dist/runner-manager.js +64 -48
  125. package/dist/runner-manager.js.map +1 -1
  126. package/dist/runner.d.ts +5 -4
  127. package/dist/runner.js +65 -64
  128. package/dist/runner.js.map +1 -1
  129. package/dist/shared/approval-policy.d.ts +1 -1
  130. package/dist/shared/approval-policy.js.map +1 -1
  131. package/dist/{activities/execute-cursor → shared}/attachment-resolver.d.ts +2 -2
  132. package/dist/{activities/execute-cursor → shared}/attachment-resolver.js +5 -5
  133. package/dist/shared/attachment-resolver.js.map +1 -0
  134. package/dist/{activities/execute-cursor → shared}/blueprint-resolver.d.ts +7 -5
  135. package/dist/{activities/execute-cursor → shared}/blueprint-resolver.js +3 -63
  136. package/dist/shared/blueprint-resolver.js.map +1 -0
  137. package/dist/shared/channel-attachment.d.ts +1 -1
  138. package/dist/shared/channel-attachment.js.map +1 -1
  139. package/dist/{activities/execute-cursor → shared}/cost-guard.d.ts +5 -1
  140. package/dist/{activities/execute-cursor → shared}/cost-guard.js +5 -1
  141. package/dist/shared/cost-guard.js.map +1 -0
  142. package/dist/{activities/execute-cursor → shared}/env-resolver.d.ts +1 -1
  143. package/dist/shared/env-resolver.js.map +1 -0
  144. package/dist/{activities/execute-cursor → shared}/exact-apply.d.ts +1 -1
  145. package/dist/{activities/execute-cursor → shared}/exact-apply.js +6 -6
  146. package/dist/shared/exact-apply.js.map +1 -0
  147. package/dist/shared/execution-context.d.ts +35 -0
  148. package/dist/shared/execution-context.js +38 -0
  149. package/dist/shared/execution-context.js.map +1 -0
  150. package/dist/{activities/execute-cursor → shared}/extract-structured-output.d.ts +5 -2
  151. package/dist/{activities/execute-cursor → shared}/extract-structured-output.js +9 -6
  152. package/dist/shared/extract-structured-output.js.map +1 -0
  153. package/dist/shared/filereview/capture.d.ts +1 -1
  154. package/dist/shared/filereview/capture.js +1 -1
  155. package/dist/shared/heartbeat.d.ts +13 -11
  156. package/dist/shared/heartbeat.js +14 -29
  157. package/dist/shared/heartbeat.js.map +1 -1
  158. package/dist/{activities/execute-cursor → shared}/persist-decision.d.ts +5 -2
  159. package/dist/{activities/execute-cursor → shared}/persist-decision.js +4 -1
  160. package/dist/shared/persist-decision.js.map +1 -0
  161. package/dist/{activities/execute-cursor → shared}/skill-resolver.d.ts +16 -3
  162. package/dist/{activities/execute-cursor → shared}/skill-resolver.js +12 -4
  163. package/dist/shared/skill-resolver.js.map +1 -0
  164. package/dist/shared/subagent-rows.d.ts +21 -0
  165. package/dist/shared/subagent-rows.js +34 -0
  166. package/dist/shared/subagent-rows.js.map +1 -0
  167. package/dist/shared/worker-shutdown.d.ts +43 -16
  168. package/dist/shared/worker-shutdown.js +28 -13
  169. package/dist/shared/worker-shutdown.js.map +1 -1
  170. package/dist/shared/workspace/platform-dir.d.ts +1 -1
  171. package/dist/shared/workspace/platform-dir.js +1 -1
  172. package/dist/shared/workspace/session-provision.d.ts +54 -0
  173. package/dist/{activities/execute-cursor/workspace-provision.js → shared/workspace/session-provision.js} +15 -12
  174. package/dist/shared/workspace/session-provision.js.map +1 -0
  175. package/package.json +4 -4
  176. package/src/__test-utils__/__tests__/harness-contract-self-check.test.ts +110 -14
  177. package/src/__test-utils__/execution-record-fixture.ts +104 -0
  178. package/src/__test-utils__/harness-boot-order-child.ts +58 -0
  179. package/src/__test-utils__/harness-contract/contract.ts +128 -83
  180. package/src/__test-utils__/harness-contract/recording-sink.ts +15 -4
  181. package/src/__test-utils__/harness-contract/runtime-contract.ts +666 -0
  182. package/src/__test-utils__/harness-contract/scripted-adapter.ts +92 -32
  183. package/src/__test-utils__/harness-contract/types.ts +85 -9
  184. package/src/__test-utils__/hermetic-activity.ts +33 -8
  185. package/src/__test-utils__/model-registry-fixture.ts +72 -0
  186. package/src/__test-utils__/module-specifiers.ts +82 -0
  187. package/src/__test-utils__/turn-input-fixture.ts +155 -0
  188. package/src/__tests__/harness-boot-order.test.ts +77 -0
  189. package/src/__tests__/harness-contract.test.ts +7 -5
  190. package/src/__tests__/runner-manager.test.ts +18 -0
  191. package/src/activities/execute-cursor/__test-utils__/__tests__/scripted-double.test.ts +102 -0
  192. package/src/activities/execute-cursor/__test-utils__/contract-subject.ts +396 -0
  193. package/src/activities/execute-cursor/__test-utils__/cursor-hook-harness.ts +66 -0
  194. package/src/activities/execute-cursor/__test-utils__/gateway-substrate.ts +2 -43
  195. package/src/activities/execute-cursor/__test-utils__/hermetic-cursor.ts +65 -145
  196. package/src/activities/execute-cursor/__test-utils__/scripted-agent.ts +30 -4
  197. package/src/activities/execute-cursor/__test-utils__/scripted-sdk.ts +96 -8
  198. package/src/activities/execute-cursor/__tests__/adapter-is-temporal-free.test.ts +45 -0
  199. package/src/activities/execute-cursor/__tests__/approval-decisions-agree.test.ts +90 -0
  200. package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +7 -8
  201. package/src/activities/execute-cursor/__tests__/capture-flow.test.ts +28 -1
  202. package/src/activities/execute-cursor/__tests__/deny-gate-exact-apply.test.ts +1 -1
  203. package/src/activities/execute-cursor/__tests__/fetch-interceptor.test.ts +64 -6
  204. package/src/activities/execute-cursor/__tests__/hermetic/deny-and-retry.test.ts +1 -1
  205. package/src/activities/execute-cursor/__tests__/hermetic/file-review-capture.test.ts +1 -1
  206. package/src/activities/execute-cursor/__tests__/hermetic/goldens/cost-cap.status.json +53 -0
  207. package/src/activities/execute-cursor/__tests__/hermetic/goldens/pause.status.json +1 -6
  208. package/src/activities/execute-cursor/__tests__/hermetic/goldens/platform-stop.status.json +56 -0
  209. package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-transport-timeout.status.json +48 -0
  210. package/src/activities/execute-cursor/__tests__/hermetic/goldens/resolution-error.status.json +18 -0
  211. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-cancelled.status.json +36 -0
  212. package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-error-non-retryable.status.json +37 -0
  213. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-error-at-create.status.json +38 -0
  214. package/src/activities/execute-cursor/__tests__/hermetic/goldens/stall.status.json +59 -0
  215. package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattributed-hook-block.status.json +79 -0
  216. package/src/activities/execute-cursor/__tests__/hermetic/goldens/worker-shutdown.status.json +2 -7
  217. package/src/activities/execute-cursor/__tests__/hermetic/harness-contract.test.ts +170 -0
  218. package/src/activities/execute-cursor/__tests__/hermetic/pause-vs-shutdown.test.ts +22 -18
  219. package/src/activities/execute-cursor/__tests__/hermetic/plain-turn.test.ts +1 -1
  220. package/src/activities/execute-cursor/__tests__/hermetic/recovery-fresh-agent.test.ts +1 -1
  221. package/src/activities/execute-cursor/__tests__/hermetic/run-wait-arms.test.ts +286 -0
  222. package/src/activities/execute-cursor/__tests__/hermetic/stream-self-stop-arms.test.ts +332 -0
  223. package/src/activities/execute-cursor/__tests__/hermetic/thrown-error-arms.test.ts +193 -0
  224. package/src/activities/execute-cursor/__tests__/hermetic/tool-call.test.ts +1 -1
  225. package/src/activities/execute-cursor/__tests__/hermetic/unattributed-hook-block.test.ts +185 -0
  226. package/src/activities/execute-cursor/__tests__/hermetic/workspace-lock-timeout.test.ts +151 -0
  227. package/src/activities/execute-cursor/__tests__/http2-interceptor.test.ts +65 -35
  228. package/src/activities/execute-cursor/__tests__/message-translator.test.ts +0 -40
  229. package/src/activities/execute-cursor/__tests__/same-identity-reproposal.test.ts +171 -0
  230. package/src/activities/execute-cursor/__tests__/turn-stream.test.ts +118 -243
  231. package/src/activities/execute-cursor/__tests__/usage-pricing.test.ts +84 -0
  232. package/src/activities/execute-cursor/adapter.ts +138 -0
  233. package/src/activities/execute-cursor/approval-state.ts +2 -2
  234. package/src/activities/execute-cursor/capture-flow.ts +18 -41
  235. package/src/activities/execute-cursor/cursor-capabilities.ts +35 -0
  236. package/src/activities/execute-cursor/cursor-mcp-config.ts +2 -2
  237. package/src/activities/execute-cursor/fetch-interceptor.ts +48 -45
  238. package/src/activities/execute-cursor/http2-interceptor.ts +47 -34
  239. package/src/activities/execute-cursor/message-translator.ts +90 -45
  240. package/src/activities/execute-cursor/prompt-builder.ts +327 -12
  241. package/src/activities/execute-cursor/rejection-capture.ts +5 -12
  242. package/src/activities/execute-cursor/session-lifecycle.ts +1 -5
  243. package/src/activities/execute-cursor/turn-boundary.ts +1 -1
  244. package/src/activities/execute-cursor/turn-settle.ts +601 -0
  245. package/src/activities/execute-cursor/turn-setup.ts +645 -0
  246. package/src/activities/execute-cursor/turn-stream.ts +84 -210
  247. package/src/activities/execute-cursor/turn.ts +240 -0
  248. package/src/activities/execute-cursor/usage-pricing.ts +67 -0
  249. package/src/activities/execute-deep-agent/approval-file-change.ts +1 -1
  250. package/src/activities/execute-deep-agent/environment.ts +1 -1
  251. package/src/activities/execute-deep-agent/setup.ts +3 -2
  252. package/src/activities/hydrate-workflow-execution.ts +1 -1
  253. package/src/config.ts +13 -0
  254. package/src/harness/__tests__/import-direction.test.ts +168 -0
  255. package/src/harness/__tests__/persist-chokepoint.test.ts +146 -0
  256. package/src/harness/__tests__/registry.test.ts +1 -0
  257. package/src/harness/__tests__/run-turn.test.ts +165 -0
  258. package/src/harness/__tests__/stop-controller.test.ts +49 -0
  259. package/src/harness/__tests__/turn-context.test.ts +178 -0
  260. package/src/harness/__tests__/usage-accumulator.test.ts +83 -0
  261. package/src/harness/capabilities.ts +17 -0
  262. package/src/harness/persist-chokepoint.ts +112 -0
  263. package/src/harness/registry.ts +79 -5
  264. package/src/harness/run-turn.ts +618 -0
  265. package/src/harness/stop-controller.ts +83 -0
  266. package/src/harness/terminal-table.ts +276 -0
  267. package/src/harness/turn-context.ts +1028 -0
  268. package/src/harness/types.ts +248 -53
  269. package/src/harness/usage-accumulator.ts +122 -0
  270. package/src/harness-adapters.ts +30 -0
  271. package/src/main.ts +1 -1
  272. package/src/runner-manager.ts +68 -61
  273. package/src/runner.ts +67 -78
  274. package/src/shared/__tests__/attachment-naming.test.ts +1 -1
  275. package/src/{activities/execute-cursor → shared}/__tests__/attachment-resolver.test.ts +6 -4
  276. package/src/{activities/execute-cursor → shared}/__tests__/cost-guard.test.ts +2 -1
  277. package/src/{activities/execute-cursor → shared}/__tests__/exact-apply.test.ts +3 -3
  278. package/src/{activities/execute-cursor → shared}/__tests__/extract-structured-output.test.ts +8 -8
  279. package/src/{activities/execute-cursor → shared}/__tests__/persist-decision.test.ts +4 -2
  280. package/src/{activities/execute-cursor → shared}/__tests__/skill-resolver.test.ts +1 -1
  281. package/src/shared/__tests__/subagent-rows.test.ts +34 -0
  282. package/src/shared/__tests__/worker-shutdown.test.ts +44 -39
  283. package/src/shared/approval-policy.ts +1 -1
  284. package/src/{activities/execute-cursor → shared}/attachment-resolver.ts +6 -6
  285. package/src/{activities/execute-cursor → shared}/blueprint-resolver.ts +7 -78
  286. package/src/shared/channel-attachment.ts +1 -1
  287. package/src/{activities/execute-cursor → shared}/cost-guard.ts +5 -1
  288. package/src/{activities/execute-cursor → shared}/env-resolver.ts +1 -1
  289. package/src/{activities/execute-cursor → shared}/exact-apply.ts +7 -7
  290. package/src/shared/execution-context.ts +45 -0
  291. package/src/{activities/execute-cursor → shared}/extract-structured-output.ts +10 -7
  292. package/src/shared/filereview/capture.ts +1 -1
  293. package/src/shared/heartbeat.ts +13 -33
  294. package/src/{activities/execute-cursor → shared}/persist-decision.ts +5 -2
  295. package/src/{activities/execute-cursor → shared}/skill-resolver.ts +20 -6
  296. package/src/shared/subagent-rows.ts +39 -0
  297. package/src/shared/worker-shutdown.ts +55 -25
  298. package/src/{activities/execute-cursor/__tests__/workspace-provision.test.ts → shared/workspace/__tests__/session-provision.test.ts} +25 -28
  299. package/src/shared/workspace/platform-dir.ts +1 -1
  300. package/src/{activities/execute-cursor/workspace-provision.ts → shared/workspace/session-provision.ts} +29 -16
  301. package/dist/activities/execute-cursor/attachment-resolver.js.map +0 -1
  302. package/dist/activities/execute-cursor/blueprint-resolver.js.map +0 -1
  303. package/dist/activities/execute-cursor/cost-guard.js.map +0 -1
  304. package/dist/activities/execute-cursor/env-resolver.js.map +0 -1
  305. package/dist/activities/execute-cursor/exact-apply.js.map +0 -1
  306. package/dist/activities/execute-cursor/extract-structured-output.js.map +0 -1
  307. package/dist/activities/execute-cursor/index.d.ts +0 -209
  308. package/dist/activities/execute-cursor/index.js +0 -2345
  309. package/dist/activities/execute-cursor/index.js.map +0 -1
  310. package/dist/activities/execute-cursor/persist-decision.js.map +0 -1
  311. package/dist/activities/execute-cursor/skill-resolver.js.map +0 -1
  312. package/dist/activities/execute-cursor/usage-accumulator.d.ts +0 -89
  313. package/dist/activities/execute-cursor/usage-accumulator.js +0 -121
  314. package/dist/activities/execute-cursor/usage-accumulator.js.map +0 -1
  315. package/dist/activities/execute-cursor/workspace-provision.d.ts +0 -42
  316. package/dist/activities/execute-cursor/workspace-provision.js.map +0 -1
  317. package/src/activities/execute-cursor/__tests__/usage-accumulator.test.ts +0 -164
  318. package/src/activities/execute-cursor/index.ts +0 -2876
  319. package/src/activities/execute-cursor/usage-accumulator.ts +0 -169
  320. /package/dist/{activities/execute-cursor → shared}/env-resolver.js +0 -0
@@ -48,10 +48,10 @@
48
48
  */
49
49
  import { isAbsolute, relative, resolve } from "node:path";
50
50
  import { ApprovalAction, ToolCallStatus, } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
51
- import { ELISION_MARKER } from "../../shared/status-offload.js";
52
- import { extractFilePath, extractWriteContent } from "../../shared/file-tools.js";
53
- import { resolveWorkspacePath } from "../../shared/file-change.js";
54
- import { utcTimestamp } from "../../shared/status.js";
51
+ import { ELISION_MARKER } from "./status-offload.js";
52
+ import { extractFilePath, extractWriteContent } from "./file-tools.js";
53
+ import { resolveWorkspacePath } from "./file-change.js";
54
+ import { utcTimestamp } from "./status.js";
55
55
  /**
56
56
  * Apply every APPROVED whole-file write in `messages` to disk with its EXACT
57
57
  * approved bytes, marking each applied tool call COMPLETED in place.
@@ -113,7 +113,7 @@ export async function applyApprovedWholeFileWrites(opts) {
113
113
  tc.completedAt = utcTimestamp();
114
114
  tc.error = "";
115
115
  applied.add(tc.id);
116
- console.log(`ExecuteCursor exact-apply: wrote approved bytes to ${target} ` +
116
+ console.log(`[exact-apply] wrote approved bytes to ${target} ` +
117
117
  `(tool=${tc.id}); no resource grant issued, so a further change ` +
118
118
  `re-gates. execution=${opts.executionId}`);
119
119
  }
@@ -198,7 +198,7 @@ function isWithinWorkspace(absTarget, workspaceDirs) {
198
198
  });
199
199
  }
200
200
  function logSkip(executionId, tc, reason) {
201
- console.log(`ExecuteCursor exact-apply skipped (falling back to grant+reinvocation): ` +
201
+ console.log(`[exact-apply] skipped (falling back to grant+reinvocation): ` +
202
202
  `tool=${tc.id} reason="${reason}" execution=${executionId}`);
203
203
  }
204
204
  //# sourceMappingURL=exact-apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exact-apply.js","sourceRoot":"","sources":["../../src/shared/exact-apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EACL,cAAc,EACd,cAAc,GACf,MAAM,8DAA8D,CAAC;AAMtE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAc3C;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,IAAuB;IAEvB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAElC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChC,KAAK,MAAM,EAAE,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC;gBAAE,SAAS;YAE5C,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;YAC5B,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,C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I,CAAC;AACtD,CAAC;AAED,mFAAmF;AACnF,SAAS,UAAU,CAAC,EAAY;IAC9B,OAAO,EAAE,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC,IAAI,KAAK,QAAQ;QAC3C,CAAC,CAAE,EAAE,CAAC,IAAgC;QACtC,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,iFAAiF;AACjF,SAAS,iBAAiB,CACxB,SAAiB,EACjB,aAAgC;IAEhC,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAClC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QAChC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QACjC,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnC,OAAO,GAAG,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,WAAmB,EAAE,EAAY,EAAE,MAAc;IAChE,OAAO,CAAC,GAAG,CACT,8DAA8D;QAC5D,QAAQ,EAAE,CAAC,EAAE,YAAY,MAAM,eAAe,WAAW,EAAE,CAC9D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The execution-scoped context — "this async work belongs to execution X" —
3
+ * as an `AsyncLocalStorage` the turn runtime enters once around the WHOLE
4
+ * activity, and the transport layer reads per request.
5
+ *
6
+ * Why it is the runtime's and not a harness's: every proxy-bound request the
7
+ * runner makes carries `x-stigmer-execution-id` from this store (the Cursor
8
+ * fetch and HTTP/2 interceptors stamp it; `rejection-capture.ts` correlates
9
+ * unhandled rejections by it), and a large share of those requests are made
10
+ * OUTSIDE any engine stretch — attachment downloads and status offload
11
+ * through the artifact proxy, the memory selection, the structured-output
12
+ * extraction and the plan-artifact publish in the epilogue, and in a cloud
13
+ * sandbox the control-plane writes themselves. Under `maxConcurrentActivities
14
+ * > 1` the fallback (a module-level id, `fetch-interceptor.ts`
15
+ * `setInterceptorExecutionId`) is whichever turn set it last; this store is
16
+ * what makes concurrent turns not overwrite each other's headers.
17
+ *
18
+ * Moved from `activities/execute-cursor/fetch-interceptor.ts` (S2 M3,
19
+ * Q-M3-12) so `harness/run-turn.ts` can enter it without importing the
20
+ * adapter; the interceptors import it from here. No harness enters it: the
21
+ * contract lists it among the things deliberately NOT on `TurnSink`.
22
+ */
23
+ import { AsyncLocalStorage } from "node:async_hooks";
24
+ export interface ExecutionContextStore {
25
+ readonly executionId: string;
26
+ }
27
+ /** The store, for readers that stamp or correlate by execution id. */
28
+ export declare function getExecutionContext(): AsyncLocalStorage<ExecutionContextStore>;
29
+ /**
30
+ * Run an async function with execution-scoped context. The executionId is
31
+ * propagated through the async call chain via AsyncLocalStorage, ensuring
32
+ * concurrent activities on the same runner process don't overwrite each
33
+ * other's proxy headers.
34
+ */
35
+ export declare function runWithExecutionContext<T>(executionId: string, fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The execution-scoped context — "this async work belongs to execution X" —
3
+ * as an `AsyncLocalStorage` the turn runtime enters once around the WHOLE
4
+ * activity, and the transport layer reads per request.
5
+ *
6
+ * Why it is the runtime's and not a harness's: every proxy-bound request the
7
+ * runner makes carries `x-stigmer-execution-id` from this store (the Cursor
8
+ * fetch and HTTP/2 interceptors stamp it; `rejection-capture.ts` correlates
9
+ * unhandled rejections by it), and a large share of those requests are made
10
+ * OUTSIDE any engine stretch — attachment downloads and status offload
11
+ * through the artifact proxy, the memory selection, the structured-output
12
+ * extraction and the plan-artifact publish in the epilogue, and in a cloud
13
+ * sandbox the control-plane writes themselves. Under `maxConcurrentActivities
14
+ * > 1` the fallback (a module-level id, `fetch-interceptor.ts`
15
+ * `setInterceptorExecutionId`) is whichever turn set it last; this store is
16
+ * what makes concurrent turns not overwrite each other's headers.
17
+ *
18
+ * Moved from `activities/execute-cursor/fetch-interceptor.ts` (S2 M3,
19
+ * Q-M3-12) so `harness/run-turn.ts` can enter it without importing the
20
+ * adapter; the interceptors import it from here. No harness enters it: the
21
+ * contract lists it among the things deliberately NOT on `TurnSink`.
22
+ */
23
+ import { AsyncLocalStorage } from "node:async_hooks";
24
+ const executionContext = new AsyncLocalStorage();
25
+ /** The store, for readers that stamp or correlate by execution id. */
26
+ export function getExecutionContext() {
27
+ return executionContext;
28
+ }
29
+ /**
30
+ * Run an async function with execution-scoped context. The executionId is
31
+ * propagated through the async call chain via AsyncLocalStorage, ensuring
32
+ * concurrent activities on the same runner process don't overwrite each
33
+ * other's proxy headers.
34
+ */
35
+ export function runWithExecutionContext(executionId, fn) {
36
+ return executionContext.run({ executionId }, fn);
37
+ }
38
+ //# sourceMappingURL=execution-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-context.js","sourceRoot":"","sources":["../../src/shared/execution-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAMrD,MAAM,gBAAgB,GAAG,IAAI,iBAAiB,EAAyB,CAAC;AAExE,sEAAsE;AACtE,MAAM,UAAU,mBAAmB;IACjC,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAI,WAAmB,EAAE,EAAoB;IAClF,OAAO,gBAAgB,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC"}
@@ -1,5 +1,8 @@
1
1
  /**
2
- * Tier-2 structured-output extraction for the Cursor harness.
2
+ * Tier-2 structured-output extraction for a harness turn.
3
+ *
4
+ * Harness-agnostic: the Cursor activity is today's only caller and the turn
5
+ * runtime takes it over in S2 M3 (the native harness has no tier 2 today).
3
6
  *
4
7
  * When tier-1 text extraction (shared/extract-json.ts) cannot find JSON in
5
8
  * the agent's free-text response, this tier asks an economy-tier LLM to
@@ -12,7 +15,7 @@
12
15
  * lazily at the call site, mirroring its tier-1 import, which is what
13
16
  * bundle-slim's deferred evaluation preserves.
14
17
  */
15
- import type { Config } from "../../config.js";
18
+ import type { Config } from "../config.js";
16
19
  /**
17
20
  * Extract structured data from an agent's free-text response using an
18
21
  * economy-tier LLM with withStructuredOutput (function-calling).
@@ -1,5 +1,8 @@
1
1
  /**
2
- * Tier-2 structured-output extraction for the Cursor harness.
2
+ * Tier-2 structured-output extraction for a harness turn.
3
+ *
4
+ * Harness-agnostic: the Cursor activity is today's only caller and the turn
5
+ * runtime takes it over in S2 M3 (the native harness has no tier 2 today).
3
6
  *
4
7
  * When tier-1 text extraction (shared/extract-json.ts) cannot find JSON in
5
8
  * the agent's free-text response, this tier asks an economy-tier LLM to
@@ -12,11 +15,11 @@
12
15
  * lazily at the call site, mirroring its tier-1 import, which is what
13
16
  * bundle-slim's deferred evaluation preserves.
14
17
  */
15
- import { getEconomyModel } from "../../shared/model-registry.js";
16
- import { buildChatModel } from "../../shared/model-client.js";
17
- import { checkDirectCredentials } from "../../shared/llm-backend.js";
18
- import { tryInferProvider } from "../../shared/llm-proxy.js";
19
- import { jsonSchemaToZod } from "../../shared/json-schema-to-zod.js";
18
+ import { getEconomyModel } from "./model-registry.js";
19
+ import { buildChatModel } from "./model-client.js";
20
+ import { checkDirectCredentials } from "./llm-backend.js";
21
+ import { tryInferProvider } from "./llm-proxy.js";
22
+ import { jsonSchemaToZod } from "./json-schema-to-zod.js";
20
23
  /**
21
24
  * Extract structured data from an agent's free-text response using an
22
25
  * economy-tier LLM with withStructuredOutput (function-calling).
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-structured-output.js","sourceRoot":"","sources":["../../src/shared/extract-structured-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;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MAAM,UAAU,CAAC,MAAM,CAAC;QACrC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,sGAAsG,EAAE;QACnI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE;KACzC,CAAC,CAAC;IAEH,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC"}
@@ -40,7 +40,7 @@ import { type BlobReader, type CasPathCapture } from "./cas-substrate.js";
40
40
  * no capture substrate and falls back to the deny-gate: the agent still runs, but
41
41
  * file writes gate pre-execution instead of flowing. In the Cursor harness that
42
42
  * fallback is also the ONLY branch that arms the resume-time exact-apply guarantee
43
- * (see execute-cursor/exact-apply.ts); the deep-agent harness re-applies an
43
+ * (see shared/exact-apply.ts); the deep-agent harness re-applies an
44
44
  * approved write via LangGraph checkpoint replay and needs no exact-apply. Keeping
45
45
  * this the single, named, truth-table-tested decision pins exactly when the
46
46
  * no-storage deny-gate engages in either harness.
@@ -42,7 +42,7 @@ import { isSecretLikePath } from "./secret-paths.js";
42
42
  * no capture substrate and falls back to the deny-gate: the agent still runs, but
43
43
  * file writes gate pre-execution instead of flowing. In the Cursor harness that
44
44
  * fallback is also the ONLY branch that arms the resume-time exact-apply guarantee
45
- * (see execute-cursor/exact-apply.ts); the deep-agent harness re-applies an
45
+ * (see shared/exact-apply.ts); the deep-agent harness re-applies an
46
46
  * approved write via LangGraph checkpoint replay and needs no exact-apply. Keeping
47
47
  * this the single, named, truth-table-tested decision pins exactly when the
48
48
  * no-storage deny-gate engages in either harness.
@@ -3,20 +3,22 @@
3
3
  *
4
4
  * Provides a periodic heartbeat loop that activities can start for
5
5
  * long-running operations. The loop sends heartbeat details at a
6
- * configurable interval and stops when cancelled or when the
7
- * returned abort function is called.
6
+ * configurable interval and stops when the returned handle is stopped.
8
7
  *
9
- * Heartbeats serve two purposes:
10
- * 1. Prevent Temporal from timing out the activity (heartbeatTimeout)
11
- * 2. Detect parent workflow cancellation (CancelledFailure from heartbeat)
8
+ * Heartbeats keep Temporal from timing the activity out
9
+ * (`heartbeatTimeout`) and are how an activity RECEIVES cancellation: the
10
+ * server piggybacks a cancel request on a heartbeat response, and the SDK
11
+ * then aborts `Context.current().cancellationSignal`. `Context.heartbeat()`
12
+ * itself never throws for cancellation (it enqueues to the worker's
13
+ * heartbeat subject — `@temporalio/activity/lib/index.js`
14
+ * `Context.heartbeat`, `@temporalio/worker/lib/worker.js` the heartbeat
15
+ * callback; the SDK's own doc: "Cancellation is not propagated from this
16
+ * function"). Until S2 M3 this handle carried two flags for a throw that
17
+ * cannot happen; a turn reads its interruption from the signal's reason
18
+ * instead (`worker-shutdown.ts` `classifyTurnInterruption`).
12
19
  */
13
20
  export interface HeartbeatHandle {
14
21
  stop(): void;
15
- readonly cancelled: boolean;
16
- readonly workerShutdown: boolean;
17
22
  }
18
- export interface HeartbeatOptions {
19
- shutdownSignal?: AbortSignal;
20
- }
21
- export declare function startHeartbeat(intervalMs: number, getDetails?: () => Record<string, unknown>, options?: HeartbeatOptions): HeartbeatHandle;
23
+ export declare function startHeartbeat(intervalMs: number, getDetails?: () => Record<string, unknown>): HeartbeatHandle;
22
24
  export declare function checkCancellation(): void;
@@ -3,48 +3,33 @@
3
3
  *
4
4
  * Provides a periodic heartbeat loop that activities can start for
5
5
  * long-running operations. The loop sends heartbeat details at a
6
- * configurable interval and stops when cancelled or when the
7
- * returned abort function is called.
6
+ * configurable interval and stops when the returned handle is stopped.
8
7
  *
9
- * Heartbeats serve two purposes:
10
- * 1. Prevent Temporal from timing out the activity (heartbeatTimeout)
11
- * 2. Detect parent workflow cancellation (CancelledFailure from heartbeat)
8
+ * Heartbeats keep Temporal from timing the activity out
9
+ * (`heartbeatTimeout`) and are how an activity RECEIVES cancellation: the
10
+ * server piggybacks a cancel request on a heartbeat response, and the SDK
11
+ * then aborts `Context.current().cancellationSignal`. `Context.heartbeat()`
12
+ * itself never throws for cancellation (it enqueues to the worker's
13
+ * heartbeat subject — `@temporalio/activity/lib/index.js`
14
+ * `Context.heartbeat`, `@temporalio/worker/lib/worker.js` the heartbeat
15
+ * callback; the SDK's own doc: "Cancellation is not propagated from this
16
+ * function"). Until S2 M3 this handle carried two flags for a throw that
17
+ * cannot happen; a turn reads its interruption from the signal's reason
18
+ * instead (`worker-shutdown.ts` `classifyTurnInterruption`).
12
19
  */
13
20
  import { Context, CancelledFailure } from "@temporalio/activity";
14
- export function startHeartbeat(intervalMs, getDetails, options) {
21
+ export function startHeartbeat(intervalMs, getDetails) {
15
22
  let stopped = false;
16
- let wasCancelled = false;
17
- let wasWorkerShutdown = false;
18
23
  const timer = setInterval(() => {
19
24
  if (stopped)
20
25
  return;
21
- try {
22
- Context.current().heartbeat(getDetails?.());
23
- }
24
- catch (err) {
25
- if (err instanceof CancelledFailure) {
26
- if (options?.shutdownSignal?.aborted) {
27
- wasWorkerShutdown = true;
28
- }
29
- else {
30
- wasCancelled = true;
31
- }
32
- stopped = true;
33
- clearInterval(timer);
34
- }
35
- }
26
+ Context.current().heartbeat(getDetails?.());
36
27
  }, intervalMs);
37
28
  return {
38
29
  stop() {
39
30
  stopped = true;
40
31
  clearInterval(timer);
41
32
  },
42
- get cancelled() {
43
- return wasCancelled;
44
- },
45
- get workerShutdown() {
46
- return wasWorkerShutdown;
47
- },
48
33
  };
49
34
  }
50
35
  export function checkCancellation() {
@@ -1 +1 @@
1
- {"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../../src/shared/heartbeat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAYjE,MAAM,UAAU,cAAc,CAC5B,UAAkB,EAClB,UAA0C,EAC1C,OAA0B;IAE1B,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,YAAY,GAAG,KAAK,CAAC;IACzB,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAE9B,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC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AAO;YAAE,OAAO;QACpB,OAAO,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC9C,CAAC,EAAE,UAAU,CAAC,CAAC;IAEf,OAAO;QACL,IAAI;YACF,OAAO,GAAG,IAAI,CAAC;YACf,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;QACjD,MAAM,IAAI,gBAAgB,CAAC,gCAAgC,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC"}
@@ -1,5 +1,8 @@
1
1
  /**
2
- * Streaming persist decision for the Cursor harness.
2
+ * Streaming persist decision for a harness turn.
3
+ *
4
+ * Harness-agnostic: the Cursor stream loop is today's only caller, the turn
5
+ * runtime takes it over in S2 M3, and S3 retires the native twin below.
3
6
  *
4
7
  * Mirrors the native deep-agent harness (execute-deep-agent/streaming.ts):
5
8
  * `shouldPersist = forceFlush || scheduler.shouldSendUpdate(eventCount)`.
@@ -9,7 +12,7 @@
9
12
  * Extracted as a single pure function so the stream loop and its unit tests
10
13
  * exercise the same implementation and cannot drift.
11
14
  */
12
- import type { StreamingUpdateScheduler } from "../../shared/streaming-scheduler.js";
15
+ import type { StreamingUpdateScheduler } from "./streaming-scheduler.js";
13
16
  /**
14
17
  * Force-flush signals — discrete, user-visible state changes that must reach the
15
18
  * live stream immediately, independent of the scheduler's time cadence.
@@ -1,5 +1,8 @@
1
1
  /**
2
- * Streaming persist decision for the Cursor harness.
2
+ * Streaming persist decision for a harness turn.
3
+ *
4
+ * Harness-agnostic: the Cursor stream loop is today's only caller, the turn
5
+ * runtime takes it over in S2 M3, and S3 retires the native twin below.
3
6
  *
4
7
  * Mirrors the native deep-agent harness (execute-deep-agent/streaming.ts):
5
8
  * `shouldPersist = forceFlush || scheduler.shouldSendUpdate(eventCount)`.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist-decision.js","sourceRoot":"","sources":["../../src/shared/persist-decision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAoBH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,4BAA4B,CAC1C,OAA0B,EAC1B,SAAmC,EACnC,UAAkB,EAClB,KAAc;IAEd,MAAM,UAAU,GACd,OAAO,CAAC,kBAAkB,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC;IAC3E,OAAO,UAAU,IAAI,SAAS,CAAC,gBAAgB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACrE,CAAC"}
@@ -5,9 +5,17 @@
5
5
  * - Mounts each skill via the shared skill-mount mechanics (SKILL.md +
6
6
  * extracted artifact, hash-keyed cache — see shared/skill-mount.ts)
7
7
  * - Uses a platform-managed directory outside the workspace
8
- * - Ensures the workspace `.stigmer` symlink (see stigmer-link.ts)
8
+ * - Ensures the workspace `.stigmer` symlink (see workspace/stigmer-link.ts)
9
9
  * - Returns metadata for prompt injection
10
10
  *
11
+ * A turn-runtime phase (`harness/turn-context.ts` `mountSkills`): it reads
12
+ * the control plane, which only the runtime holds, and writes under the
13
+ * platform dir the runtime owns; the harness renders the returned metadata
14
+ * into its prompt in its own placement. Moved from
15
+ * `activities/execute-cursor/` at S2 M3b; the native harness's twin
16
+ * (`skill-writer.ts` `fetchSkillsByRefs` + `mountSkills`) is what S3
17
+ * reconciles it with.
18
+ *
11
19
  * The mount is cached by the skill's content-addressed version hash
12
20
  * (stigmer/stigmer#672): metadata is fetched on every execution (that keeps
13
21
  * latest-version freshness), but the artifact download and file rewrite are
@@ -16,9 +24,14 @@
16
24
  * message after the first pays a metadata read instead of a full artifact
17
25
  * transfer.
18
26
  */
19
- import type { StigmerClient } from "../../client/stigmer-client.js";
27
+ import type { StigmerClient } from "../client/stigmer-client.js";
20
28
  import type { ApiResourceReference } from "@stigmer/protos/ai/stigmer/commons/apiresource/io_pb";
21
- import type { SkillMetadata } from "./prompt-builder.js";
29
+ /** One mounted skill as a prompt renders it: its name, its description, and the workspace-relative path of its SKILL.md. */
30
+ export interface SkillMetadata {
31
+ name: string;
32
+ description: string;
33
+ path: string;
34
+ }
22
35
  export interface SkillResolverOptions {
23
36
  sessionId: string;
24
37
  primaryWorkspaceDir: string;
@@ -5,9 +5,17 @@
5
5
  * - Mounts each skill via the shared skill-mount mechanics (SKILL.md +
6
6
  * extracted artifact, hash-keyed cache — see shared/skill-mount.ts)
7
7
  * - Uses a platform-managed directory outside the workspace
8
- * - Ensures the workspace `.stigmer` symlink (see stigmer-link.ts)
8
+ * - Ensures the workspace `.stigmer` symlink (see workspace/stigmer-link.ts)
9
9
  * - Returns metadata for prompt injection
10
10
  *
11
+ * A turn-runtime phase (`harness/turn-context.ts` `mountSkills`): it reads
12
+ * the control plane, which only the runtime holds, and writes under the
13
+ * platform dir the runtime owns; the harness renders the returned metadata
14
+ * into its prompt in its own placement. Moved from
15
+ * `activities/execute-cursor/` at S2 M3b; the native harness's twin
16
+ * (`skill-writer.ts` `fetchSkillsByRefs` + `mountSkills`) is what S3
17
+ * reconciles it with.
18
+ *
11
19
  * The mount is cached by the skill's content-addressed version hash
12
20
  * (stigmer/stigmer#672): metadata is fetched on every execution (that keeps
13
21
  * latest-version freshness), but the artifact download and file rewrite are
@@ -18,9 +26,9 @@
18
26
  */
19
27
  import { mkdir } from "node:fs/promises";
20
28
  import { join } from "node:path";
21
- import { getPlatformDir } from "../../shared/workspace/platform-dir.js";
22
- import { SKILLS_SUBDIR, mountIsFresh, downloadArtifact, writeSkillMount, } from "../../shared/skill-mount.js";
23
- import { ensureStigmerSymlink, STIGMER_LOCAL_STATE_DIR } from "../../shared/workspace/stigmer-link.js";
29
+ import { getPlatformDir } from "./workspace/platform-dir.js";
30
+ import { SKILLS_SUBDIR, mountIsFresh, downloadArtifact, writeSkillMount, } from "./skill-mount.js";
31
+ import { ensureStigmerSymlink, STIGMER_LOCAL_STATE_DIR } from "./workspace/stigmer-link.js";
24
32
  /**
25
33
  * Resolve skill references into written SKILL.md files and prompt metadata.
26
34
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-resolver.js","sourceRoot":"","sources":["../../src/shared/skill-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAc5F;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAqB,EACrB,SAAiC,EACjC,OAA6B;IAE7B,OAAO,CAAC,GAAG,CACT,6BAA6B,OAAO,CAAC,SAAS,IAAI;QAClD,uBAAuB,OAAO,CAAC,mBAAmB,IAAI,aAAa,IAAI;QACvE,iBAAiB,SAAS,CAAC,MAAM,IAAI;QACrC,SAAS,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,WAAW,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC/E,CAAC;IAEF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEtC,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACnD,MAAM,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE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AO,CAAC,MAAM,IAAI,SAAS,CAAC,MAAM,kBAAkB,CACnF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Terminal transitions on the sub-agent rows of an execution status,
3
+ * operating on the proto array itself.
4
+ *
5
+ * One function today: marking every non-terminal sub-agent CANCELLED when a
6
+ * turn ends without them (a pause, a shutdown, a stall, a cost cap, an
7
+ * infrastructure cancel), so the final snapshot has no permanent IN_PROGRESS
8
+ * "zombie" delegation. Harness-agnostic (a `SubAgentExecution` is the
9
+ * platform's row, not an engine's), read by the turn runtime's terminal
10
+ * table and the Cursor accumulator's own finalize alike.
11
+ *
12
+ * Moved from `activities/execute-cursor/message-translator.ts` at S2 M3 so
13
+ * the runtime's catch can reach it; the body is unchanged.
14
+ */
15
+ import type { SubAgentExecution } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/subagent_pb";
16
+ /**
17
+ * Transition any non-terminal sub-agent (IN_PROGRESS or PENDING) in the given
18
+ * proto array to CANCELLED with a completion timestamp, in place. Returns
19
+ * true if any sub-agent changed.
20
+ */
21
+ export declare function cancelInProgressSubAgentProtos(subAgents: SubAgentExecution[]): boolean;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Terminal transitions on the sub-agent rows of an execution status,
3
+ * operating on the proto array itself.
4
+ *
5
+ * One function today: marking every non-terminal sub-agent CANCELLED when a
6
+ * turn ends without them (a pause, a shutdown, a stall, a cost cap, an
7
+ * infrastructure cancel), so the final snapshot has no permanent IN_PROGRESS
8
+ * "zombie" delegation. Harness-agnostic (a `SubAgentExecution` is the
9
+ * platform's row, not an engine's), read by the turn runtime's terminal
10
+ * table and the Cursor accumulator's own finalize alike.
11
+ *
12
+ * Moved from `activities/execute-cursor/message-translator.ts` at S2 M3 so
13
+ * the runtime's catch can reach it; the body is unchanged.
14
+ */
15
+ import { SubAgentStatus } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
16
+ import { utcTimestamp } from "./status.js";
17
+ /**
18
+ * Transition any non-terminal sub-agent (IN_PROGRESS or PENDING) in the given
19
+ * proto array to CANCELLED with a completion timestamp, in place. Returns
20
+ * true if any sub-agent changed.
21
+ */
22
+ export function cancelInProgressSubAgentProtos(subAgents) {
23
+ let changed = false;
24
+ for (const sub of subAgents) {
25
+ if (sub.status === SubAgentStatus.SUB_AGENT_IN_PROGRESS ||
26
+ sub.status === SubAgentStatus.SUB_AGENT_PENDING) {
27
+ sub.status = SubAgentStatus.SUB_AGENT_CANCELLED;
28
+ sub.completedAt = utcTimestamp();
29
+ changed = true;
30
+ }
31
+ }
32
+ return changed;
33
+ }
34
+ //# sourceMappingURL=subagent-rows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subagent-rows.js","sourceRoot":"","sources":["../../src/shared/subagent-rows.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,8DAA8D,CAAC;AAE9F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAAC,SAA8B;IAC3E,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC5B,IACE,GAAG,CAAC,MAAM,KAAK,cAAc,CAAC,qBAAqB;YACnD,GAAG,CAAC,MAAM,KAAK,cAAc,CAAC,iBAAiB,EAC/C,CAAC;YACD,GAAG,CAAC,MAAM,GAAG,cAAc,CAAC,mBAAmB,CAAC;YAChD,GAAG,CAAC,WAAW,GAAG,YAAY,EAAE,CAAC;YACjC,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -40,28 +40,55 @@ export declare function getShutdownSignalForQueue(taskQueue: string): AbortSigna
40
40
  export declare function signalWorkerShutdown(taskQueue: string): void;
41
41
  /** Drop the registration once the queue's worker is fully torn down. */
42
42
  export declare function unregisterWorkerShutdownSignal(taskQueue: string): void;
43
- /** The evidence a turn's post-stream classification weighs (see below). */
43
+ /**
44
+ * Why Temporal cancelled the activity, as the SDK states it: the message of
45
+ * the `CancelledFailure` it aborted `Context.current().cancellationSignal`
46
+ * with (`@temporalio/activity`'s module header lists them — `CANCELLED` for a
47
+ * workflow-requested cancel, `TIMED_OUT` when a heartbeat or other timeout
48
+ * fired server-side, `NOT_FOUND` when the run closed, `WORKER_SHUTDOWN`,
49
+ * `HEARTBEAT_DETAILS_CONVERSION_FAILED`, `PAUSED`). `undefined` when no
50
+ * cancellation was delivered.
51
+ */
52
+ export type CancellationReason = string | undefined;
53
+ /** The reason a cancellation signal carries, or `undefined` when it has not aborted. */
54
+ export declare function cancellationReasonOf(signal: AbortSignal): CancellationReason;
55
+ /** The evidence a turn's interruption classification weighs (see below). */
44
56
  export interface TurnInterruptionEvidence {
45
- /** The periodic heartbeat threw CancelledFailure with no shutdown signal. */
46
- heartbeatCancelled: boolean;
47
- /** The periodic heartbeat threw CancelledFailure with the signal aborted. */
48
- heartbeatWorkerShutdown: boolean;
49
- /** Temporal delivered cancellation to the activity. */
50
- cancellationSignalAborted: boolean;
57
+ /** The delivered cancellation's reason; `undefined` when none was delivered. */
58
+ readonly cancellationReason: CancellationReason;
51
59
  /** This queue's worker-shutdown signal is aborted. */
52
- shutdownSignalAborted: boolean;
60
+ readonly shutdownSignalAborted: boolean;
53
61
  }
54
62
  /**
55
- * Classify how (whether) a turn's stream was interrupted, from the evidence
56
- * available after the stream ends. Pure so the decision table is directly
57
- * testable the activities feed it their heartbeat flags and signals.
63
+ * How Temporal's cancellation reads to the turn:
64
+ * - `worker-shutdown`: the runner is draining (the queue's signal, or the
65
+ * SDK's own `WORKER_SHUTDOWN`); FAILED with the shutdown copy, thrown.
66
+ * - `pause`: the workflow asked (`CANCELLED`, the Pause RPC's path);
67
+ * PAUSED, thrown.
68
+ * - `infrastructure`: the platform cancelled for its own reason (a heartbeat
69
+ * timeout, a closed run); FAILED with the unresponsive copy, thrown.
70
+ * - `none`: nothing was delivered.
71
+ */
72
+ export type TurnInterruption = "worker-shutdown" | "pause" | "infrastructure" | "none";
73
+ /**
74
+ * Classify how (whether) Temporal interrupted the turn, from the two live
75
+ * facts: the reason on the cancellation signal and the queue's shutdown
76
+ * signal. Pure so the decision table is directly testable.
58
77
  *
59
78
  * The load-bearing rule is the grace-window guard (#776): an aborted
60
79
  * shutdown signal ALONE is "none", because a run that completes normally
61
80
  * inside the drain grace window reaches the classification with the signal
62
- * already aborted and nothing actually interrupted. Shutdown requires
63
- * interruption evidence (a heartbeat CancelledFailure or a delivered
64
- * cancellation) alongside the signal; a heartbeat cancellation with no
65
- * shutdown signal is the orchestrator's pause.
81
+ * already aborted and nothing actually interrupted. Shutdown requires a
82
+ * delivered cancellation alongside the signal.
83
+ *
84
+ * Until S2 M3 the evidence also carried two flags from the periodic
85
+ * heartbeat ("it threw `CancelledFailure`"), and a delivered cancellation
86
+ * without them read as "none". `Context.heartbeat()` never throws in the
87
+ * Temporal TypeScript SDK (it enqueues to the worker's heartbeat subject;
88
+ * `@temporalio/activity/lib/index.js` `Context.heartbeat`,
89
+ * `@temporalio/worker/lib/worker.js` the heartbeat callback), so the flags
90
+ * were never set and a pause was in fact recognised by the stream loop's
91
+ * own cancellation check. The reason the SDK puts on the signal is the
92
+ * direct identity that inference stood in for.
66
93
  */
67
- export declare function classifyTurnInterruption(evidence: TurnInterruptionEvidence): "worker-shutdown" | "pause" | "none";
94
+ export declare function classifyTurnInterruption(evidence: TurnInterruptionEvidence): TurnInterruption;
@@ -51,29 +51,44 @@ export function signalWorkerShutdown(taskQueue) {
51
51
  export function unregisterWorkerShutdownSignal(taskQueue) {
52
52
  registry.delete(taskQueue);
53
53
  }
54
+ /** The reason a cancellation signal carries, or `undefined` when it has not aborted. */
55
+ export function cancellationReasonOf(signal) {
56
+ if (!signal.aborted)
57
+ return undefined;
58
+ const reason = signal.reason;
59
+ if (reason instanceof Error)
60
+ return reason.message;
61
+ return typeof reason === "string" ? reason : "CANCELLED";
62
+ }
54
63
  /**
55
- * Classify how (whether) a turn's stream was interrupted, from the evidence
56
- * available after the stream ends. Pure so the decision table is directly
57
- * testable the activities feed it their heartbeat flags and signals.
64
+ * Classify how (whether) Temporal interrupted the turn, from the two live
65
+ * facts: the reason on the cancellation signal and the queue's shutdown
66
+ * signal. Pure so the decision table is directly testable.
58
67
  *
59
68
  * The load-bearing rule is the grace-window guard (#776): an aborted
60
69
  * shutdown signal ALONE is "none", because a run that completes normally
61
70
  * inside the drain grace window reaches the classification with the signal
62
- * already aborted and nothing actually interrupted. Shutdown requires
63
- * interruption evidence (a heartbeat CancelledFailure or a delivered
64
- * cancellation) alongside the signal; a heartbeat cancellation with no
65
- * shutdown signal is the orchestrator's pause.
71
+ * already aborted and nothing actually interrupted. Shutdown requires a
72
+ * delivered cancellation alongside the signal.
73
+ *
74
+ * Until S2 M3 the evidence also carried two flags from the periodic
75
+ * heartbeat ("it threw `CancelledFailure`"), and a delivered cancellation
76
+ * without them read as "none". `Context.heartbeat()` never throws in the
77
+ * Temporal TypeScript SDK (it enqueues to the worker's heartbeat subject;
78
+ * `@temporalio/activity/lib/index.js` `Context.heartbeat`,
79
+ * `@temporalio/worker/lib/worker.js` the heartbeat callback), so the flags
80
+ * were never set and a pause was in fact recognised by the stream loop's
81
+ * own cancellation check. The reason the SDK puts on the signal is the
82
+ * direct identity that inference stood in for.
66
83
  */
67
84
  export function classifyTurnInterruption(evidence) {
68
- const interrupted = evidence.heartbeatCancelled ||
69
- evidence.heartbeatWorkerShutdown ||
70
- evidence.cancellationSignalAborted;
71
- if (!interrupted) {
85
+ const { cancellationReason, shutdownSignalAborted } = evidence;
86
+ if (cancellationReason === undefined) {
72
87
  return "none";
73
88
  }
74
- if (evidence.heartbeatWorkerShutdown || evidence.shutdownSignalAborted) {
89
+ if (shutdownSignalAborted || cancellationReason === "WORKER_SHUTDOWN") {
75
90
  return "worker-shutdown";
76
91
  }
77
- return evidence.heartbeatCancelled ? "pause" : "none";
92
+ return cancellationReason === "CANCELLED" ? "pause" : "infrastructure";
78
93
  }
79
94
  //# sourceMappingURL=worker-shutdown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-shutdown.js","sourceRoot":"","sources":["../../src/shared/worker-shutdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAAC,SAAiB;IAC5D,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACpC,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,yBAAyB,CAAC,SAAiB;IACzD,OAAO,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC;AACnC,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,8BAA8B,CAAC,SAAiB;IAC9D,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC7B,CAAC;AAcD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAkC;IAElC,MAAM,WAAW,GACf,QAAQ,CAAC,kBAAkB;QAC3B,QAAQ,CAAC,uBAAuB;QAChC,QAAQ,CAAC,yBAAyB,CAAC;IACrC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,QAAQ,CAAC,uBAAuB,IAAI,QAAQ,CAAC,qBAAqB,EAAE,CAAC;QACvE,OAAO,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