@stigmer/runner 3.15.1 → 3.15.2-dev.20260913223433

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 (518) hide show
  1. package/README.md +2 -4
  2. package/dist/.build-fingerprint +1 -1
  3. package/dist/__test-utils__/execution-record-fixture.d.ts +14 -0
  4. package/dist/__test-utils__/execution-record-fixture.js +4 -0
  5. package/dist/__test-utils__/execution-record-fixture.js.map +1 -1
  6. package/dist/__test-utils__/file-review-projection.d.ts +40 -0
  7. package/dist/__test-utils__/file-review-projection.js +136 -0
  8. package/dist/__test-utils__/file-review-projection.js.map +1 -0
  9. package/dist/__test-utils__/harness-contract/types.d.ts +23 -1
  10. package/dist/__test-utils__/harness-contract/types.js +15 -0
  11. package/dist/__test-utils__/harness-contract/types.js.map +1 -1
  12. package/dist/__test-utils__/hermetic-activity.d.ts +44 -12
  13. package/dist/__test-utils__/hermetic-activity.js +52 -14
  14. package/dist/__test-utils__/hermetic-activity.js.map +1 -1
  15. package/dist/__test-utils__/model-registry-fixture.d.ts +32 -7
  16. package/dist/__test-utils__/model-registry-fixture.js +31 -7
  17. package/dist/__test-utils__/model-registry-fixture.js.map +1 -1
  18. package/dist/__test-utils__/turn-input-fixture.d.ts +1 -1
  19. package/dist/__test-utils__/turn-input-fixture.js +1 -1
  20. package/dist/__test-utils__/turn-input-fixture.js.map +1 -1
  21. package/dist/activities/call-agent.js +2 -2
  22. package/dist/activities/call-agent.js.map +1 -1
  23. package/dist/activities/execute-cursor/__test-utils__/contract-subject.js +45 -3
  24. package/dist/activities/execute-cursor/__test-utils__/contract-subject.js.map +1 -1
  25. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.d.ts +0 -9
  26. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js +2 -41
  27. package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js.map +1 -1
  28. package/dist/activities/execute-cursor/adapter.d.ts +7 -5
  29. package/dist/activities/execute-cursor/adapter.js +7 -5
  30. package/dist/activities/execute-cursor/adapter.js.map +1 -1
  31. package/dist/activities/execute-cursor/approval-policy.d.ts +5 -2
  32. package/dist/activities/execute-cursor/approval-policy.js +5 -2
  33. package/dist/activities/execute-cursor/approval-policy.js.map +1 -1
  34. package/dist/activities/execute-cursor/approval-state.d.ts +16 -8
  35. package/dist/activities/execute-cursor/approval-state.js +6 -3
  36. package/dist/activities/execute-cursor/approval-state.js.map +1 -1
  37. package/dist/activities/execute-cursor/cas-observations.d.ts +14 -2
  38. package/dist/activities/execute-cursor/cas-observations.js +19 -2
  39. package/dist/activities/execute-cursor/cas-observations.js.map +1 -1
  40. package/dist/activities/execute-cursor/cursor-capabilities.d.ts +8 -4
  41. package/dist/activities/execute-cursor/cursor-capabilities.js +21 -4
  42. package/dist/activities/execute-cursor/cursor-capabilities.js.map +1 -1
  43. package/dist/activities/execute-cursor/message-translator.d.ts +12 -20
  44. package/dist/activities/execute-cursor/message-translator.js +19 -32
  45. package/dist/activities/execute-cursor/message-translator.js.map +1 -1
  46. package/dist/activities/execute-cursor/prompt-builder.d.ts +48 -58
  47. package/dist/activities/execute-cursor/prompt-builder.js +76 -95
  48. package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
  49. package/dist/activities/execute-cursor/turn-boundary.d.ts +27 -55
  50. package/dist/activities/execute-cursor/turn-boundary.js +30 -90
  51. package/dist/activities/execute-cursor/turn-boundary.js.map +1 -1
  52. package/dist/activities/execute-cursor/turn-settle.d.ts +11 -7
  53. package/dist/activities/execute-cursor/turn-settle.js +37 -49
  54. package/dist/activities/execute-cursor/turn-settle.js.map +1 -1
  55. package/dist/activities/execute-cursor/turn-setup.d.ts +16 -24
  56. package/dist/activities/execute-cursor/turn-setup.js +29 -59
  57. package/dist/activities/execute-cursor/turn-setup.js.map +1 -1
  58. package/dist/activities/execute-cursor/turn-stream.d.ts +3 -8
  59. package/dist/activities/execute-cursor/turn-stream.js +9 -22
  60. package/dist/activities/execute-cursor/turn-stream.js.map +1 -1
  61. package/dist/activities/execute-cursor/turn.js +5 -1
  62. package/dist/activities/execute-cursor/turn.js.map +1 -1
  63. package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.d.ts +93 -0
  64. package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.js +348 -0
  65. package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.js.map +1 -0
  66. package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.d.ts +170 -0
  67. package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.js +225 -0
  68. package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.js.map +1 -0
  69. package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.d.ts +24 -0
  70. package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.js +41 -0
  71. package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.js.map +1 -0
  72. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.d.ts +54 -0
  73. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.js +72 -0
  74. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.js.map +1 -0
  75. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.d.ts +187 -23
  76. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.js +238 -27
  77. package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.js.map +1 -1
  78. package/dist/activities/execute-deep-agent/adapter.d.ts +41 -0
  79. package/dist/activities/execute-deep-agent/adapter.js +78 -0
  80. package/dist/activities/execute-deep-agent/adapter.js.map +1 -0
  81. package/dist/activities/execute-deep-agent/cas-capture-observer.d.ts +8 -0
  82. package/dist/activities/execute-deep-agent/cas-capture-observer.js +9 -0
  83. package/dist/activities/execute-deep-agent/cas-capture-observer.js.map +1 -1
  84. package/dist/activities/execute-deep-agent/deep-agent-capabilities.d.ts +31 -0
  85. package/dist/activities/execute-deep-agent/deep-agent-capabilities.js +40 -0
  86. package/dist/activities/execute-deep-agent/deep-agent-capabilities.js.map +1 -0
  87. package/dist/activities/execute-deep-agent/execution-state.d.ts +4 -11
  88. package/dist/activities/execute-deep-agent/execution-state.js +4 -12
  89. package/dist/activities/execute-deep-agent/execution-state.js.map +1 -1
  90. package/dist/activities/execute-deep-agent/hitl.d.ts +49 -47
  91. package/dist/activities/execute-deep-agent/hitl.js +77 -103
  92. package/dist/activities/execute-deep-agent/hitl.js.map +1 -1
  93. package/dist/activities/execute-deep-agent/prompt-builder.d.ts +51 -23
  94. package/dist/activities/execute-deep-agent/prompt-builder.js +115 -76
  95. package/dist/activities/execute-deep-agent/prompt-builder.js.map +1 -1
  96. package/dist/activities/execute-deep-agent/status-builder-shared.d.ts +18 -32
  97. package/dist/activities/execute-deep-agent/status-builder-shared.js +10 -65
  98. package/dist/activities/execute-deep-agent/status-builder-shared.js.map +1 -1
  99. package/dist/activities/execute-deep-agent/streaming-side-effects.d.ts +10 -8
  100. package/dist/activities/execute-deep-agent/streaming-side-effects.js +12 -14
  101. package/dist/activities/execute-deep-agent/streaming-side-effects.js.map +1 -1
  102. package/dist/activities/execute-deep-agent/subagent-tracker.d.ts +36 -13
  103. package/dist/activities/execute-deep-agent/subagent-tracker.js +76 -39
  104. package/dist/activities/execute-deep-agent/subagent-tracker.js.map +1 -1
  105. package/dist/activities/execute-deep-agent/subagent-transformer.d.ts +25 -28
  106. package/dist/activities/execute-deep-agent/subagent-transformer.js +29 -82
  107. package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -1
  108. package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +3 -2
  109. package/dist/activities/execute-deep-agent/subagent-wiring.js +2 -2
  110. package/dist/activities/execute-deep-agent/subagent-wiring.js.map +1 -1
  111. package/dist/activities/execute-deep-agent/turn-settle.d.ts +42 -0
  112. package/dist/activities/execute-deep-agent/turn-settle.js +146 -0
  113. package/dist/activities/execute-deep-agent/turn-settle.js.map +1 -0
  114. package/dist/activities/execute-deep-agent/turn-setup.d.ts +212 -0
  115. package/dist/activities/execute-deep-agent/turn-setup.js +430 -0
  116. package/dist/activities/execute-deep-agent/turn-setup.js.map +1 -0
  117. package/dist/activities/execute-deep-agent/turn-stream.d.ts +97 -0
  118. package/dist/activities/execute-deep-agent/turn-stream.js +242 -0
  119. package/dist/activities/execute-deep-agent/turn-stream.js.map +1 -0
  120. package/dist/activities/execute-deep-agent/turn.d.ts +42 -0
  121. package/dist/activities/execute-deep-agent/turn.js +116 -0
  122. package/dist/activities/execute-deep-agent/turn.js.map +1 -0
  123. package/dist/activities/execute-deep-agent/v3-event-recorder.d.ts +6 -5
  124. package/dist/activities/execute-deep-agent/v3-event-recorder.js +6 -5
  125. package/dist/activities/execute-deep-agent/v3-event-recorder.js.map +1 -1
  126. package/dist/activities/execute-deep-agent/v3-events.d.ts +1 -1
  127. package/dist/activities/execute-deep-agent/v3-events.js +1 -1
  128. package/dist/activities/execute-deep-agent/v3-status-builder.d.ts +60 -17
  129. package/dist/activities/execute-deep-agent/v3-status-builder.js +72 -57
  130. package/dist/activities/execute-deep-agent/v3-status-builder.js.map +1 -1
  131. package/dist/harness/approval-decisions.d.ts +61 -0
  132. package/dist/harness/approval-decisions.js +102 -0
  133. package/dist/harness/approval-decisions.js.map +1 -0
  134. package/dist/harness/capabilities.d.ts +16 -5
  135. package/dist/harness/capabilities.js +9 -0
  136. package/dist/harness/capabilities.js.map +1 -1
  137. package/dist/harness/capture.d.ts +144 -0
  138. package/dist/harness/capture.js +219 -0
  139. package/dist/harness/capture.js.map +1 -0
  140. package/dist/harness/persist-chokepoint.d.ts +19 -4
  141. package/dist/harness/persist-chokepoint.js +17 -4
  142. package/dist/harness/persist-chokepoint.js.map +1 -1
  143. package/dist/harness/run-turn.js +115 -29
  144. package/dist/harness/run-turn.js.map +1 -1
  145. package/dist/harness/terminal-table.d.ts +40 -11
  146. package/dist/harness/terminal-table.js +58 -19
  147. package/dist/harness/terminal-table.js.map +1 -1
  148. package/dist/harness/turn-context.d.ts +141 -76
  149. package/dist/harness/turn-context.js +194 -99
  150. package/dist/harness/turn-context.js.map +1 -1
  151. package/dist/harness/types.d.ts +65 -12
  152. package/dist/harness/types.js +8 -2
  153. package/dist/harness/types.js.map +1 -1
  154. package/dist/harness-adapters.d.ts +12 -8
  155. package/dist/harness-adapters.js +17 -9
  156. package/dist/harness-adapters.js.map +1 -1
  157. package/dist/middleware/approval-gate.d.ts +1 -1
  158. package/dist/middleware/approval-gate.js +1 -1
  159. package/dist/middleware/approval-gate.js.map +1 -1
  160. package/dist/middleware/cost-advisory.d.ts +39 -0
  161. package/dist/middleware/{cost-cap.js → cost-advisory.js} +37 -55
  162. package/dist/middleware/cost-advisory.js.map +1 -0
  163. package/dist/middleware/index.d.ts +23 -12
  164. package/dist/middleware/index.js +26 -18
  165. package/dist/middleware/index.js.map +1 -1
  166. package/dist/middleware/types.d.ts +3 -2
  167. package/dist/runner-manager.js +1 -5
  168. package/dist/runner-manager.js.map +1 -1
  169. package/dist/runner.js +1 -5
  170. package/dist/runner.js.map +1 -1
  171. package/dist/shared/attachment-resolver.d.ts +41 -18
  172. package/dist/shared/attachment-resolver.js +178 -46
  173. package/dist/shared/attachment-resolver.js.map +1 -1
  174. package/dist/shared/attachment-zip.d.ts +85 -0
  175. package/dist/shared/attachment-zip.js +185 -0
  176. package/dist/shared/attachment-zip.js.map +1 -0
  177. package/dist/shared/connect-backfill.js +5 -4
  178. package/dist/shared/connect-backfill.js.map +1 -1
  179. package/dist/shared/cost-guard.d.ts +3 -3
  180. package/dist/shared/cost-guard.js +3 -3
  181. package/dist/shared/execution-status-writer.d.ts +5 -5
  182. package/dist/shared/execution-status-writer.js +5 -5
  183. package/dist/shared/extract-structured-output.d.ts +8 -7
  184. package/dist/shared/extract-structured-output.js +8 -7
  185. package/dist/shared/extract-structured-output.js.map +1 -1
  186. package/dist/shared/filereview/cas-progress.d.ts +1 -18
  187. package/dist/shared/filereview/cas-progress.js +4 -0
  188. package/dist/shared/filereview/cas-progress.js.map +1 -1
  189. package/dist/shared/filereview/cas-touched.d.ts +56 -0
  190. package/dist/shared/filereview/cas-touched.js +63 -0
  191. package/dist/shared/filereview/cas-touched.js.map +1 -0
  192. package/dist/shared/filereview/index.d.ts +2 -1
  193. package/dist/shared/filereview/index.js +2 -1
  194. package/dist/shared/filereview/index.js.map +1 -1
  195. package/dist/shared/mcp-resolver.d.ts +4 -5
  196. package/dist/shared/mcp-resolver.js +4 -5
  197. package/dist/shared/mcp-resolver.js.map +1 -1
  198. package/dist/shared/persist-decision.d.ts +3 -4
  199. package/dist/shared/persist-decision.js +3 -4
  200. package/dist/shared/persist-decision.js.map +1 -1
  201. package/dist/shared/plan-mode-permissions.d.ts +2 -2
  202. package/dist/shared/plan-mode-permissions.js +2 -2
  203. package/dist/shared/plan-mode-prompt.d.ts +1 -1
  204. package/dist/shared/plan-mode-prompt.js +1 -1
  205. package/dist/shared/prompt-sections.d.ts +163 -0
  206. package/dist/shared/prompt-sections.js +164 -0
  207. package/dist/shared/prompt-sections.js.map +1 -0
  208. package/dist/shared/skill-resolver.d.ts +4 -2
  209. package/dist/shared/skill-resolver.js +4 -2
  210. package/dist/shared/skill-resolver.js.map +1 -1
  211. package/dist/shared/tool-rounds.d.ts +32 -0
  212. package/dist/shared/tool-rounds.js +43 -0
  213. package/dist/shared/tool-rounds.js.map +1 -1
  214. package/dist/shared/tool-row.d.ts +34 -0
  215. package/dist/shared/tool-row.js +52 -0
  216. package/dist/shared/tool-row.js.map +1 -1
  217. package/dist/shared/workspace/session-provision.d.ts +3 -3
  218. package/dist/shared/workspace/session-provision.js +3 -3
  219. package/dist/shared/workspace/stigmer-link.d.ts +3 -3
  220. package/dist/shared/workspace/stigmer-link.js +3 -3
  221. package/dist/shared/workspace/writeback-coordinator.d.ts +15 -22
  222. package/dist/shared/workspace/writeback-coordinator.js +16 -53
  223. package/dist/shared/workspace/writeback-coordinator.js.map +1 -1
  224. package/dist/tools/index.d.ts +1 -1
  225. package/dist/tools/index.js +1 -1
  226. package/package.json +4 -4
  227. package/src/__test-utils__/__tests__/harness-contract-self-check.test.ts +1 -0
  228. package/src/__test-utils__/execution-record-fixture.ts +18 -2
  229. package/src/__test-utils__/file-review-projection.ts +156 -0
  230. package/src/__test-utils__/git-workspace-fixture.ts +58 -0
  231. package/src/__test-utils__/harness-boot-order-child.ts +7 -2
  232. package/src/__test-utils__/harness-contract/contract.ts +33 -20
  233. package/src/__test-utils__/harness-contract/recording-sink.ts +11 -1
  234. package/src/__test-utils__/harness-contract/runtime-contract.ts +328 -10
  235. package/src/__test-utils__/harness-contract/scripted-adapter.ts +38 -6
  236. package/src/__test-utils__/harness-contract/types.ts +27 -3
  237. package/src/__test-utils__/hermetic-activity.ts +52 -14
  238. package/src/__test-utils__/model-registry-fixture.ts +32 -7
  239. package/src/__test-utils__/module-specifiers.ts +24 -0
  240. package/src/__test-utils__/turn-input-fixture.ts +2 -2
  241. package/src/__tests__/harness-boot-order.test.ts +9 -2
  242. package/src/activities/call-agent.ts +2 -2
  243. package/src/activities/execute-cursor/__test-utils__/contract-subject.ts +47 -3
  244. package/src/activities/execute-cursor/__test-utils__/hermetic-cursor.ts +2 -48
  245. package/src/activities/execute-cursor/__tests__/approval-decisions-agree.test.ts +1 -1
  246. package/src/activities/execute-cursor/__tests__/approval-gate.test.ts +6 -1
  247. package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +52 -27
  248. package/src/activities/execute-cursor/__tests__/cas-observations.test.ts +25 -0
  249. package/src/activities/execute-cursor/__tests__/goldens/prompt.enhanced.everything.prompt.md +166 -0
  250. package/src/activities/execute-cursor/__tests__/goldens/prompt.enhanced.plan-mode.prompt.md +186 -0
  251. package/src/activities/execute-cursor/__tests__/goldens/prompt.hitl.recovery.prompt.md +191 -0
  252. package/src/activities/execute-cursor/__tests__/goldens/prompt.hitl.reinvocation.prompt.md +13 -0
  253. package/src/activities/execute-cursor/__tests__/goldens/prompt.resumed.prefixed.prompt.md +32 -0
  254. package/src/activities/execute-cursor/__tests__/goldens/prompt.resumed.raw.prompt.md +1 -0
  255. package/src/activities/execute-cursor/__tests__/hermetic/file-review-capture.test.ts +1 -2
  256. package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-error-at-create.status.json +4 -0
  257. package/src/activities/execute-cursor/__tests__/hermetic/harness-contract.test.ts +24 -4
  258. package/src/activities/execute-cursor/__tests__/hermetic/stream-self-stop-arms.test.ts +6 -5
  259. package/src/activities/execute-cursor/__tests__/hermetic/thrown-error-arms.test.ts +9 -0
  260. package/src/activities/execute-cursor/__tests__/hitl-resume-history.test.ts +11 -8
  261. package/src/activities/execute-cursor/__tests__/prompt-goldens.test.ts +229 -0
  262. package/src/activities/execute-cursor/__tests__/same-identity-reproposal.test.ts +3 -3
  263. package/src/activities/execute-cursor/__tests__/sequential-gate-resume.test.ts +2 -2
  264. package/src/activities/execute-cursor/__tests__/turn-boundary.test.ts +78 -234
  265. package/src/activities/execute-cursor/__tests__/turn-stream.test.ts +1 -26
  266. package/src/activities/execute-cursor/adapter.ts +7 -5
  267. package/src/activities/execute-cursor/approval-policy.ts +5 -2
  268. package/src/activities/execute-cursor/approval-state.ts +16 -8
  269. package/src/activities/execute-cursor/cas-observations.ts +20 -2
  270. package/src/activities/execute-cursor/cursor-capabilities.ts +24 -5
  271. package/src/activities/execute-cursor/message-translator.ts +29 -41
  272. package/src/activities/execute-cursor/prompt-builder.ts +99 -157
  273. package/src/activities/execute-cursor/turn-boundary.ts +34 -140
  274. package/src/activities/execute-cursor/turn-settle.ts +37 -51
  275. package/src/activities/execute-cursor/turn-setup.ts +30 -70
  276. package/src/activities/execute-cursor/turn-stream.ts +8 -31
  277. package/src/activities/execute-cursor/turn.ts +5 -1
  278. package/src/activities/execute-deep-agent/__test-utils__/contract-subject.ts +391 -0
  279. package/src/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.ts +313 -0
  280. package/src/activities/execute-deep-agent/__test-utils__/hitl-script.ts +48 -0
  281. package/src/activities/execute-deep-agent/__test-utils__/scripted-model-module.ts +85 -0
  282. package/src/activities/execute-deep-agent/__test-utils__/scripted-model.ts +383 -36
  283. package/src/activities/execute-deep-agent/__tests__/adapter-graph-is-sdk-free.test.ts +76 -0
  284. package/src/activities/execute-deep-agent/__tests__/adapter-is-temporal-free.test.ts +47 -0
  285. package/src/activities/execute-deep-agent/__tests__/adapter.test.ts +80 -0
  286. package/src/activities/execute-deep-agent/__tests__/cas-capture-backend.test.ts +1 -1
  287. package/src/activities/execute-deep-agent/__tests__/execution-state-extended.test.ts +0 -2
  288. package/src/activities/execute-deep-agent/__tests__/execution-state.test.ts +0 -3
  289. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.build-from-plan.prompt.md +172 -0
  290. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.everything.prompt.md +167 -0
  291. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.minimal.prompt.md +36 -0
  292. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.plan-mode.prompt.md +178 -0
  293. package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.skills-below-threshold.prompt.md +158 -0
  294. package/src/activities/execute-deep-agent/__tests__/hermetic/file-review-capture.test.ts +210 -0
  295. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn1.status.json +74 -0
  296. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn2.status.json +104 -0
  297. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve.turn2.status.json +78 -0
  298. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-capture.status.json +138 -0
  299. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/gate.turn1.status.json +68 -0
  300. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn1.status.json +154 -0
  301. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn2.status.json +116 -0
  302. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.after-tool.status.json +69 -0
  303. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.mid-tool.status.json +67 -0
  304. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/plain-turn.status.json +47 -0
  305. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/platform-stop.status.json +68 -0
  306. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/recursion-limit.persisted.status.json +280 -0
  307. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/reject.turn2.status.json +77 -0
  308. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/resolution-error.status.json +18 -0
  309. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn2.status.json +99 -0
  310. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn3.status.json +109 -0
  311. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/skip.turn2.status.json +76 -0
  312. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.text-fallback.status.json +51 -0
  313. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tier2.status.json +51 -0
  314. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tool-strategy.status.json +56 -0
  315. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sub-agent-delegation.status.json +90 -0
  316. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/tool-call.status.json +70 -0
  317. package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/worker-shutdown.status.json +71 -0
  318. package/src/activities/execute-deep-agent/__tests__/hermetic/harness-contract.test.ts +144 -0
  319. package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-approve-all-lease.test.ts +184 -0
  320. package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-round-trips.test.ts +203 -0
  321. package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-sequential-gates.test.ts +170 -0
  322. package/src/activities/execute-deep-agent/__tests__/hermetic/inline-artifact-across-gate.test.ts +175 -0
  323. package/src/activities/execute-deep-agent/__tests__/hermetic/pause-vs-shutdown.test.ts +206 -0
  324. package/src/activities/execute-deep-agent/__tests__/hermetic/plain-turn.test.ts +142 -0
  325. package/src/activities/execute-deep-agent/__tests__/hermetic/platform-stop.test.ts +126 -0
  326. package/src/activities/execute-deep-agent/__tests__/hermetic/recursion-limit.test.ts +139 -0
  327. package/src/activities/execute-deep-agent/__tests__/hermetic/resolution-error.test.ts +122 -0
  328. package/src/activities/execute-deep-agent/__tests__/hermetic/structured-output.test.ts +236 -0
  329. package/src/activities/execute-deep-agent/__tests__/hermetic/sub-agent-delegation.test.ts +161 -0
  330. package/src/activities/execute-deep-agent/__tests__/hermetic/tool-call.test.ts +157 -0
  331. package/src/activities/execute-deep-agent/__tests__/hermetic/workspace-lock-timeout.test.ts +152 -0
  332. package/src/activities/execute-deep-agent/__tests__/hitl.test.ts +50 -122
  333. package/src/activities/execute-deep-agent/__tests__/inline-publisher.test.ts +8 -6
  334. package/src/activities/execute-deep-agent/__tests__/plan-mode-path-normalization.test.ts +2 -2
  335. package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +35 -35
  336. package/src/activities/execute-deep-agent/__tests__/prompt-goldens.test.ts +247 -0
  337. package/src/activities/execute-deep-agent/__tests__/scripted-model.test.ts +329 -0
  338. package/src/activities/execute-deep-agent/__tests__/status-builder-shared.test.ts +1 -20
  339. package/src/activities/execute-deep-agent/__tests__/streaming-side-effects.test.ts +78 -0
  340. package/src/activities/execute-deep-agent/__tests__/subagent-gitignored-capture.test.ts +1 -1
  341. package/src/activities/execute-deep-agent/__tests__/subagent-plan-mode-permissions.test.ts +2 -2
  342. package/src/activities/execute-deep-agent/__tests__/subagent-tracker.test.ts +57 -31
  343. package/src/activities/execute-deep-agent/__tests__/subagent-transformer.test.ts +19 -79
  344. package/src/activities/execute-deep-agent/__tests__/subagent-wiring.test.ts +15 -15
  345. package/src/activities/execute-deep-agent/__tests__/summarization-verification.test.ts +1 -1
  346. package/src/activities/execute-deep-agent/__tests__/turn-stream.test.ts +391 -0
  347. package/src/activities/execute-deep-agent/__tests__/v3-status-builder.test.ts +343 -38
  348. package/src/activities/execute-deep-agent/__tests__/vision-input.test.ts +5 -5
  349. package/src/activities/execute-deep-agent/adapter.ts +94 -0
  350. package/src/activities/execute-deep-agent/cas-capture-observer.ts +11 -0
  351. package/src/activities/execute-deep-agent/deep-agent-capabilities.ts +43 -0
  352. package/src/activities/execute-deep-agent/execution-state.ts +4 -13
  353. package/src/activities/execute-deep-agent/hitl.ts +100 -123
  354. package/src/activities/execute-deep-agent/prompt-builder.ts +141 -115
  355. package/src/activities/execute-deep-agent/status-builder-shared.ts +21 -84
  356. package/src/activities/execute-deep-agent/streaming-side-effects.ts +13 -19
  357. package/src/activities/execute-deep-agent/subagent-tracker.ts +77 -42
  358. package/src/activities/execute-deep-agent/subagent-transformer.ts +46 -105
  359. package/src/activities/execute-deep-agent/subagent-wiring.ts +5 -4
  360. package/src/activities/execute-deep-agent/turn-settle.ts +164 -0
  361. package/src/activities/execute-deep-agent/turn-setup.ts +541 -0
  362. package/src/activities/execute-deep-agent/turn-stream.ts +313 -0
  363. package/src/activities/execute-deep-agent/turn.ts +131 -0
  364. package/src/activities/execute-deep-agent/v3-event-recorder.ts +6 -5
  365. package/src/activities/execute-deep-agent/v3-events.ts +1 -1
  366. package/src/activities/execute-deep-agent/v3-status-builder.ts +84 -63
  367. package/src/harness/__tests__/approval-decisions.test.ts +116 -0
  368. package/src/harness/__tests__/capture.test.ts +268 -0
  369. package/src/harness/__tests__/mount-skills.test.ts +169 -0
  370. package/src/harness/__tests__/persist-chokepoint.test.ts +38 -2
  371. package/src/harness/__tests__/run-turn-deterministic.test.ts +94 -0
  372. package/src/harness/__tests__/run-turn.test.ts +39 -23
  373. package/src/harness/__tests__/turn-attachments-vision.test.ts +80 -0
  374. package/src/harness/__tests__/turn-context.test.ts +73 -26
  375. package/src/harness/approval-decisions.ts +104 -0
  376. package/src/harness/capabilities.ts +16 -5
  377. package/src/harness/capture.ts +301 -0
  378. package/src/harness/persist-chokepoint.ts +24 -4
  379. package/src/harness/run-turn.ts +120 -29
  380. package/src/harness/terminal-table.ts +61 -20
  381. package/src/harness/turn-context.ts +208 -111
  382. package/src/harness/types.ts +66 -12
  383. package/src/harness-adapters.ts +17 -9
  384. package/src/middleware/__tests__/approval-gate.test.ts +1 -1
  385. package/src/middleware/__tests__/cost-advisory.test.ts +113 -0
  386. package/src/middleware/approval-gate.ts +2 -2
  387. package/src/middleware/{cost-cap.ts → cost-advisory.ts} +40 -70
  388. package/src/middleware/index.ts +29 -29
  389. package/src/middleware/types.ts +3 -2
  390. package/src/runner-manager.ts +0 -8
  391. package/src/runner.ts +0 -8
  392. package/src/shared/__tests__/attachment-naming.test.ts +6 -19
  393. package/src/shared/__tests__/attachment-resolver.test.ts +158 -8
  394. package/src/shared/__tests__/attachment-zip.test.ts +236 -0
  395. package/src/shared/__tests__/bedrock-adapter.test.ts +1 -1
  396. package/src/shared/__tests__/blueprint-resolver.test.ts +43 -0
  397. package/src/shared/__tests__/cost-guard.test.ts +3 -3
  398. package/src/shared/__tests__/prompt-sections.test.ts +167 -0
  399. package/src/shared/__tests__/secret-leak-scan.test.ts +2 -2
  400. package/src/{activities/execute-deep-agent → shared}/__tests__/stamp-flowed-rows.test.ts +33 -10
  401. package/src/shared/__tests__/vertex-adapter.test.ts +1 -1
  402. package/src/shared/attachment-resolver.ts +218 -55
  403. package/src/shared/attachment-zip.ts +281 -0
  404. package/src/shared/connect-backfill.ts +9 -11
  405. package/src/shared/cost-guard.ts +3 -3
  406. package/src/shared/execution-status-writer.ts +5 -5
  407. package/src/shared/extract-structured-output.ts +8 -7
  408. package/src/shared/filereview/__tests__/capture.test.ts +86 -4
  409. package/src/shared/filereview/__tests__/cas-progress.test.ts +2 -1
  410. package/src/shared/filereview/cas-progress.ts +5 -19
  411. package/src/shared/filereview/cas-touched.ts +89 -0
  412. package/src/shared/filereview/index.ts +4 -2
  413. package/src/shared/mcp-resolver.ts +4 -5
  414. package/src/shared/persist-decision.ts +3 -4
  415. package/src/shared/plan-mode-permissions.ts +2 -2
  416. package/src/shared/plan-mode-prompt.ts +1 -1
  417. package/src/shared/prompt-sections.ts +256 -0
  418. package/src/shared/skill-resolver.ts +4 -2
  419. package/src/shared/tool-rounds.ts +48 -0
  420. package/src/shared/tool-row.ts +61 -0
  421. package/src/shared/workspace/__tests__/stigmer-link.test.ts +7 -22
  422. package/src/shared/workspace/__tests__/writeback-coordinator.test.ts +20 -61
  423. package/src/shared/workspace/session-provision.ts +3 -3
  424. package/src/shared/workspace/stigmer-link.ts +3 -3
  425. package/src/shared/workspace/writeback-coordinator.ts +16 -64
  426. package/src/tools/index.ts +1 -1
  427. package/dist/activities/execute-cursor/capture-flow.d.ts +0 -142
  428. package/dist/activities/execute-cursor/capture-flow.js +0 -285
  429. package/dist/activities/execute-cursor/capture-flow.js.map +0 -1
  430. package/dist/activities/execute-cursor/command-provenance.d.ts +0 -48
  431. package/dist/activities/execute-cursor/command-provenance.js +0 -38
  432. package/dist/activities/execute-cursor/command-provenance.js.map +0 -1
  433. package/dist/activities/execute-deep-agent/attachment-injector.d.ts +0 -134
  434. package/dist/activities/execute-deep-agent/attachment-injector.js +0 -386
  435. package/dist/activities/execute-deep-agent/attachment-injector.js.map +0 -1
  436. package/dist/activities/execute-deep-agent/command-provenance.d.ts +0 -61
  437. package/dist/activities/execute-deep-agent/command-provenance.js +0 -72
  438. package/dist/activities/execute-deep-agent/command-provenance.js.map +0 -1
  439. package/dist/activities/execute-deep-agent/environment.d.ts +0 -24
  440. package/dist/activities/execute-deep-agent/environment.js +0 -58
  441. package/dist/activities/execute-deep-agent/environment.js.map +0 -1
  442. package/dist/activities/execute-deep-agent/event-recorder.d.ts +0 -21
  443. package/dist/activities/execute-deep-agent/event-recorder.js +0 -67
  444. package/dist/activities/execute-deep-agent/event-recorder.js.map +0 -1
  445. package/dist/activities/execute-deep-agent/index.d.ts +0 -15
  446. package/dist/activities/execute-deep-agent/index.js +0 -918
  447. package/dist/activities/execute-deep-agent/index.js.map +0 -1
  448. package/dist/activities/execute-deep-agent/mcp-gate.d.ts +0 -28
  449. package/dist/activities/execute-deep-agent/mcp-gate.js +0 -22
  450. package/dist/activities/execute-deep-agent/mcp-gate.js.map +0 -1
  451. package/dist/activities/execute-deep-agent/post-stream.d.ts +0 -23
  452. package/dist/activities/execute-deep-agent/post-stream.js +0 -71
  453. package/dist/activities/execute-deep-agent/post-stream.js.map +0 -1
  454. package/dist/activities/execute-deep-agent/setup.d.ts +0 -136
  455. package/dist/activities/execute-deep-agent/setup.js +0 -767
  456. package/dist/activities/execute-deep-agent/setup.js.map +0 -1
  457. package/dist/activities/execute-deep-agent/stamp-flowed-rows.d.ts +0 -36
  458. package/dist/activities/execute-deep-agent/stamp-flowed-rows.js +0 -56
  459. package/dist/activities/execute-deep-agent/stamp-flowed-rows.js.map +0 -1
  460. package/dist/activities/execute-deep-agent/status-builder.d.ts +0 -93
  461. package/dist/activities/execute-deep-agent/status-builder.js +0 -365
  462. package/dist/activities/execute-deep-agent/status-builder.js.map +0 -1
  463. package/dist/activities/execute-deep-agent/streaming-terminal.d.ts +0 -21
  464. package/dist/activities/execute-deep-agent/streaming-terminal.js +0 -80
  465. package/dist/activities/execute-deep-agent/streaming-terminal.js.map +0 -1
  466. package/dist/activities/execute-deep-agent/streaming-v3.d.ts +0 -13
  467. package/dist/activities/execute-deep-agent/streaming-v3.js +0 -174
  468. package/dist/activities/execute-deep-agent/streaming-v3.js.map +0 -1
  469. package/dist/activities/execute-deep-agent/streaming.d.ts +0 -81
  470. package/dist/activities/execute-deep-agent/streaming.js +0 -160
  471. package/dist/activities/execute-deep-agent/streaming.js.map +0 -1
  472. package/dist/middleware/cost-cap.d.ts +0 -22
  473. package/dist/middleware/cost-cap.js.map +0 -1
  474. package/dist/middleware/graceful-stop.d.ts +0 -17
  475. package/dist/middleware/graceful-stop.js +0 -63
  476. package/dist/middleware/graceful-stop.js.map +0 -1
  477. package/dist/shared/skill-writer.d.ts +0 -75
  478. package/dist/shared/skill-writer.js +0 -207
  479. package/dist/shared/skill-writer.js.map +0 -1
  480. package/src/activities/execute-cursor/__tests__/capture-flow.test.ts +0 -1032
  481. package/src/activities/execute-cursor/__tests__/command-provenance.test.ts +0 -240
  482. package/src/activities/execute-cursor/__tests__/progress-substrate.test.ts +0 -169
  483. package/src/activities/execute-cursor/capture-flow.ts +0 -379
  484. package/src/activities/execute-cursor/command-provenance.ts +0 -73
  485. package/src/activities/execute-deep-agent/__tests__/attachment-injector.test.ts +0 -1161
  486. package/src/activities/execute-deep-agent/__tests__/command-provenance.test.ts +0 -252
  487. package/src/activities/execute-deep-agent/__tests__/environment.test.ts +0 -108
  488. package/src/activities/execute-deep-agent/__tests__/event-recorder.test.ts +0 -150
  489. package/src/activities/execute-deep-agent/__tests__/hitl-integration.test.ts +0 -226
  490. package/src/activities/execute-deep-agent/__tests__/hitl-reject.test.ts +0 -318
  491. package/src/activities/execute-deep-agent/__tests__/hitl-resume-approve-all.test.ts +0 -351
  492. package/src/activities/execute-deep-agent/__tests__/hitl-resume-history.test.ts +0 -293
  493. package/src/activities/execute-deep-agent/__tests__/index.test.ts +0 -99
  494. package/src/activities/execute-deep-agent/__tests__/mcp-gate.test.ts +0 -44
  495. package/src/activities/execute-deep-agent/__tests__/post-stream.test.ts +0 -112
  496. package/src/activities/execute-deep-agent/__tests__/sequential-gate-resume.test.ts +0 -358
  497. package/src/activities/execute-deep-agent/__tests__/status-builder.test.ts +0 -1933
  498. package/src/activities/execute-deep-agent/__tests__/streaming-terminal.test.ts +0 -40
  499. package/src/activities/execute-deep-agent/__tests__/streaming-v3.test.ts +0 -597
  500. package/src/activities/execute-deep-agent/__tests__/streaming.test.ts +0 -508
  501. package/src/activities/execute-deep-agent/attachment-injector.ts +0 -627
  502. package/src/activities/execute-deep-agent/command-provenance.ts +0 -102
  503. package/src/activities/execute-deep-agent/environment.ts +0 -76
  504. package/src/activities/execute-deep-agent/event-recorder.ts +0 -95
  505. package/src/activities/execute-deep-agent/index.ts +0 -1072
  506. package/src/activities/execute-deep-agent/mcp-gate.ts +0 -37
  507. package/src/activities/execute-deep-agent/post-stream.ts +0 -109
  508. package/src/activities/execute-deep-agent/setup.ts +0 -1081
  509. package/src/activities/execute-deep-agent/stamp-flowed-rows.ts +0 -64
  510. package/src/activities/execute-deep-agent/status-builder.ts +0 -481
  511. package/src/activities/execute-deep-agent/streaming-terminal.ts +0 -106
  512. package/src/activities/execute-deep-agent/streaming-v3.ts +0 -277
  513. package/src/activities/execute-deep-agent/streaming.ts +0 -313
  514. package/src/middleware/__tests__/cost-cap.test.ts +0 -192
  515. package/src/middleware/__tests__/graceful-stop.test.ts +0 -105
  516. package/src/middleware/graceful-stop.ts +0 -86
  517. package/src/shared/__tests__/skill-writer.test.ts +0 -372
  518. package/src/shared/skill-writer.ts +0 -266
@@ -0,0 +1,242 @@
1
+ /**
2
+ * The native deep-agent harness's stream phase — the single per-event
3
+ * consumption loop that turns a live LangGraph v3 event stream into the
4
+ * streamed transcript and the one fact that decides how
5
+ * the turn goes on (the graph paused at a gate).
6
+ *
7
+ * What the loop asks of the runtime, through the sink (`harness/types.ts`):
8
+ * `recordActivity()` per event (with the tool name on a tool start), so the
9
+ * runtime's stall watchdog measures the engine; `reportUsage()` per parent
10
+ * `message_finish`, priced here at the registry's rates for the model the
11
+ * turn runs on (`shared/model-pricing.ts`), so the runtime accounts and
12
+ * enforces the cost cap and writes `streamingUsage` (Q-M2a-2); `requestPersist()`
13
+ * where a discrete change or the streaming cadence says so
14
+ * (`shared/persist-decision.ts` over the builder's one dirty flag), AWAITED,
15
+ * so a platform STOP the runtime reads from that write aborts the signal
16
+ * before the next event is pulled; and `stopSignal`, checked at every event
17
+ * boundary and listened to inside the pull, where a stop cancels the graph
18
+ * run — the same act for every cause of stopping (the runtime knows why;
19
+ * this loop never does). An error the aborted run throws is the abort itself
20
+ * and settles `interrupted`, never `failed`.
21
+ *
22
+ * WHEN the run is aborted (S3 M2a, F-M2a-18): on the arrival of the next
23
+ * event — the graph's own step boundary — or after {@link STOP_GRACE_MS} if
24
+ * no event arrives. A LangGraph run aborted while a step is in flight leaves
25
+ * `@langchain/core` with an orphaned rejection (`AsyncGeneratorWithSetup`
26
+ * races its first pull against the signal eagerly, and an abort mid-step
27
+ * rejects a promise nothing awaits), which surfaces as a process-level
28
+ * `unhandledRejection` — logged by `main.ts`, but noise the runner must not
29
+ * produce on every pause. Aborting as an event arrives is clean, and it is
30
+ * exactly when the orchestrator's loop aborted; so the loop never aborts
31
+ * right after a persist, even one that answered STOP — it lets the next
32
+ * event arrive and stops there. A live engine yields an event well inside
33
+ * the grace; a wedged engine (the runtime's stall watchdog is the caller
34
+ * here) is forced, and that one orphan is the price of unblocking it — the
35
+ * contract's bound on settling `interrupted` is what wins.
36
+ *
37
+ * Until S3 M2a this loop (`streaming-v3.ts`) armed its own 120 s stall
38
+ * check, pulsed the Temporal heartbeat every 2 s, read STOP from its own
39
+ * persist and activated a graceful-stop middleware on it, told a pause from
40
+ * the activity's cancellation signal, and wrote PAUSED, COMPLETED and
41
+ * TERMINATED itself; every one of those is the runtime's now, and the loop
42
+ * reports only `completed`, `awaiting_approval` or `interrupted`. The
43
+ * graph's recursion limit propagates as its own error for `turn.ts` to
44
+ * classify (`tool_call_limit`), and an empty stream is an error the same
45
+ * way (`failed` on the `internal` surface).
46
+ */
47
+ import { shouldPersistStreamingStatus } from "../../shared/persist-decision.js";
48
+ import { StreamingUpdateScheduler, loadStreamingConfig } from "../../shared/streaming-scheduler.js";
49
+ import { computeTurnCost } from "../../shared/model-pricing.js";
50
+ import { TimeoutError, withTimeout } from "../../shared/with-timeout.js";
51
+ import { InlinePublisher } from "./inline-publisher.js";
52
+ import { StreamingSideEffects } from "./streaming-side-effects.js";
53
+ import { createV3EventRecorder } from "./v3-event-recorder.js";
54
+ import { normalize } from "./v3-protocol-normalizer.js";
55
+ import { V3StatusBuilder } from "./v3-status-builder.js";
56
+ /**
57
+ * How long the loop waits for `run.output` after the stream ended before
58
+ * proceeding without the final state (the structured response rides it).
59
+ */
60
+ const RUN_OUTPUT_TIMEOUT_MS = 30_000;
61
+ /**
62
+ * How long a stop waits for the next event before the run is aborted
63
+ * mid-step (see the header). Well inside the contract kit's settle bound and
64
+ * far above any token cadence a live model has.
65
+ */
66
+ const STOP_GRACE_MS = 1_000;
67
+ export function createDeepAgentTranscript(input, sink, engine, workspace) {
68
+ const builder = new V3StatusBuilder(input.executionId, sink.status, {
69
+ onUsage: (usage) => {
70
+ // LangChain's `input_tokens` already INCLUDES the cache buckets (the
71
+ // Anthropic adapter folds them in; the cost advisory reads them the
72
+ // same way), so the counts are reported as delivered and the price
73
+ // is computed over the disjoint buckets.
74
+ const inputTokens = usage.input_tokens ?? 0;
75
+ const outputTokens = usage.output_tokens ?? 0;
76
+ const cacheReadTokens = usage.input_token_details?.cache_read ?? 0;
77
+ const cacheWriteTokens = usage.input_token_details?.cache_creation ?? 0;
78
+ const uncachedInput = Math.max(inputTokens - cacheReadTokens - cacheWriteTokens, 0);
79
+ sink.reportUsage({
80
+ inputTokens,
81
+ outputTokens,
82
+ cacheReadTokens,
83
+ cacheWriteTokens,
84
+ estimatedCostUsd: computeTurnCost(engine.pricing, uncachedInput, outputTokens, cacheWriteTokens, cacheReadTokens),
85
+ model: engine.modelName,
86
+ });
87
+ },
88
+ });
89
+ builder.setApprovalProvider({
90
+ policies: engine.gate.policies,
91
+ toolServerMap: engine.gate.toolServerMap,
92
+ leasedCategories: engine.gate.leasedCategories,
93
+ globalBypass: engine.gate.globalBypass,
94
+ unattended: engine.gate.unattended,
95
+ });
96
+ const publisher = new InlinePublisher({
97
+ workspaceBackend: workspace.backend,
98
+ artifactStorage: input.artifactStorage,
99
+ statusWriter: builder,
100
+ executionId: input.executionId,
101
+ });
102
+ return { builder, publisher };
103
+ }
104
+ /**
105
+ * Start the graph run and consume it to the end, folding every event into
106
+ * the transcript. Returns why it ended; throws only what `turn.ts`
107
+ * classifies (the recursion limit, an empty stream, an engine error).
108
+ */
109
+ export async function consumeDeepAgentStream(deps) {
110
+ const { input, sink, engine, graphInput, transcript } = deps;
111
+ const { executionId } = input;
112
+ const { builder, publisher } = transcript;
113
+ const scheduler = new StreamingUpdateScheduler(loadStreamingConfig());
114
+ const recorder = createV3EventRecorder(executionId, process.env.V3_EVENT_RECORD_DIR);
115
+ const sideEffects = new StreamingSideEffects({ inlinePublisher: publisher });
116
+ const abortController = new AbortController();
117
+ let forceAbort;
118
+ const abortRun = () => {
119
+ if (forceAbort !== undefined)
120
+ clearTimeout(forceAbort);
121
+ forceAbort = undefined;
122
+ abortController.abort("stopped by the runtime");
123
+ };
124
+ const onStop = () => {
125
+ forceAbort = setTimeout(abortRun, STOP_GRACE_MS);
126
+ };
127
+ sink.stopSignal.addEventListener("abort", onStop, { once: true });
128
+ let eventsProcessed = 0;
129
+ /** The stop, taken at a boundary: abort the run now and settle. */
130
+ const interrupted = () => {
131
+ abortRun();
132
+ return {
133
+ reason: "interrupted",
134
+ eventsProcessed,
135
+ runOutput: undefined,
136
+ pendingPublishPromises: sideEffects.pendingPublishPromises,
137
+ };
138
+ };
139
+ try {
140
+ if (sink.stopSignal.aborted)
141
+ return interrupted();
142
+ const run = (await engine.graph.streamEvents(graphInput.kind === "resume" ? graphInput.command : graphInput.input, { ...engine.langgraphConfig, version: "v3", signal: abortController.signal }));
143
+ sink.recordActivity();
144
+ // An aborted run rejects `run.output` with the abort error; an
145
+ // interrupted turn never awaits it (there is no final state to read), so
146
+ // the rejection is claimed here or it surfaces as unhandled. A completed
147
+ // turn still awaits the same promise below and reads its value.
148
+ run.output.catch(() => undefined);
149
+ try {
150
+ for await (const event of run) {
151
+ if (sink.stopSignal.aborted)
152
+ return interrupted();
153
+ recorder?.record(event, eventsProcessed);
154
+ let detail;
155
+ for (const normalized of normalize(event)) {
156
+ builder.processEvent(normalized);
157
+ if (normalized.kind === "tool_started")
158
+ detail = normalized.name;
159
+ }
160
+ sideEffects.onProtocolEvent(event);
161
+ eventsProcessed++;
162
+ sink.recordActivity(detail);
163
+ const persist = shouldPersistStreamingStatus({ deltaEnricherDirty: false, todosDirty: false, contentDirty: builder.forceNextUpdate }, scheduler, eventsProcessed);
164
+ if (!persist)
165
+ continue;
166
+ builder.clearForceFlag();
167
+ // The runtime attaches the mid-run file-change progress on this write
168
+ // (the chokepoint's step 2), as it does on every write. Awaited so a platform STOP the runtime reads from this write has
169
+ // aborted the signal by the time the next event arrives — where the
170
+ // stop is taken (see the header on why not here).
171
+ await sink.requestPersist();
172
+ scheduler.markUpdateSent(eventsProcessed);
173
+ }
174
+ }
175
+ catch (err) {
176
+ // The aborted run throws its own abort out of the pull; that is the
177
+ // stop the runtime asked for, not a failure.
178
+ if (sink.stopSignal.aborted)
179
+ return interrupted();
180
+ throw err;
181
+ }
182
+ if (eventsProcessed === 0) {
183
+ throw new Error("Stream completed without processing any events. " +
184
+ "This may indicate a configuration error or v3 API incompatibility.");
185
+ }
186
+ if (builder.awaitingApproval) {
187
+ console.log(`[turn-stream] execution=${executionId} stream ended at a gate; awaiting approval`);
188
+ return {
189
+ reason: "awaiting_approval",
190
+ eventsProcessed,
191
+ runOutput: undefined,
192
+ pendingPublishPromises: sideEffects.pendingPublishPromises,
193
+ };
194
+ }
195
+ console.log(`[turn-stream] execution=${executionId} stream finished — processed ${eventsProcessed} events`);
196
+ const runOutput = await extractRunOutput(run, executionId);
197
+ sink.recordActivity();
198
+ return { reason: "completed", eventsProcessed, runOutput, pendingPublishPromises: sideEffects.pendingPublishPromises };
199
+ }
200
+ finally {
201
+ sink.stopSignal.removeEventListener("abort", onStop);
202
+ if (forceAbort !== undefined)
203
+ clearTimeout(forceAbort);
204
+ await recorder?.flush();
205
+ }
206
+ }
207
+ /**
208
+ * The graph's final state, bounded: `run.output` normally resolves the
209
+ * moment the stream ends, but a state that never settles must not hold the
210
+ * turn (the structured response is recoverable from the final text; the
211
+ * runtime's epilogue does that).
212
+ *
213
+ * Bounded through the shared `withTimeout`, never a hand-rolled
214
+ * `Promise.race` against a bare `setTimeout`: a race leaves its losing timer
215
+ * armed, and a referenced timer holds the Node event loop open. The
216
+ * orchestrator's copy of this wait left a 30 s timer behind every completed
217
+ * execution, so a runner asked to exit right after one idled for the full
218
+ * Kubernetes termination grace (stigmer#1008, fixed on the orchestrator in
219
+ * stigmer#1092 while this adapter was on its branch; this copy had cleared
220
+ * its timer in a `finally` from the start, and took the shared shape at the
221
+ * merge so there is one way to bound a wait). `withTimeout` clears the timer
222
+ * on whichever side settles first; `turn-stream.test.ts` pins that nothing
223
+ * stays armed on either side.
224
+ */
225
+ async function extractRunOutput(run, executionId) {
226
+ try {
227
+ const finalState = await withTimeout(RUN_OUTPUT_TIMEOUT_MS, `run.output did not resolve within ${RUN_OUTPUT_TIMEOUT_MS}ms`, () => run.output);
228
+ const output = finalState;
229
+ console.log(`[turn-stream] execution=${executionId} — run.output resolved. ` +
230
+ `Keys: [${Object.keys(output ?? {}).join(", ")}]. hasStructuredResponse=${output?.structuredResponse !== undefined}`);
231
+ return output;
232
+ }
233
+ catch (err) {
234
+ if (err instanceof TimeoutError) {
235
+ console.warn(`[turn-stream] execution=${executionId} — ${err.message}. Proceeding without final state.`);
236
+ return undefined;
237
+ }
238
+ console.warn(`[turn-stream] execution=${executionId} — run.output rejected: ${err}`);
239
+ return undefined;
240
+ }
241
+ }
242
+ //# sourceMappingURL=turn-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-stream.js","sourceRoot":"","sources":["../../../src/activities/execute-deep-agent/turn-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAGH,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC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,IAAI,CAAC,IAAI,CAAC,4BAA4B,MAAM,EAAE,kBAAkB,KAAK,SAAS,EAAE,CACrH,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,YAAY,EAAE,CAAC;YAChC,OAAO,CAAC,IAAI,CAAC,2BAA2B,WAAW,MAAM,GAAG,CAAC,OAAO,mCAAmC,CAAC,CAAC;YACzG,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,2BAA2B,WAAW,2BAA2B,GAAG,EAAE,CAAC,CAAC;QACrF,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * One native deep-agent engine turn — the LangGraph slice of the harness,
3
+ * behind the turn runtime's contract (`harness/types.ts`).
4
+ *
5
+ * `runDeepAgentTurn` is what `adapter.ts`'s `runTurn` delegates to: the
6
+ * setup over the runtime's record (`turn-setup.ts`), the stream over the
7
+ * sink (`turn-stream.ts`), the settle (`turn-settle.ts`), and its own
8
+ * teardown — the MCP connection and the checkpoint saver. Everything else
9
+ * about a turn is the runtime's (`harness/run-turn.ts`): the resolution
10
+ * phases, the workspace lock and the `.stigmer` link, the persist
11
+ * chokepoint, the watchdog, the heartbeat, the cost cap, the interruption
12
+ * table, the completion epilogue, the SKIP/REJECT settlement.
13
+ *
14
+ * This module is where `deepagents` and `@langchain/*` enter the adapter's
15
+ * graph (through `turn-setup.ts` and its siblings), which is WHY it is a
16
+ * separate module from `adapter.ts` and is loaded there with a dynamic
17
+ * import inside `boot`: the harness table's static graph must stay SDK-free
18
+ * so a worker that does not serve this harness never pays for LangChain
19
+ * (`harness-adapters.ts`). Nothing outside `adapter.ts` imports this module.
20
+ *
21
+ * Never throws out of `runDeepAgentTurn`: the graph exhausting its recursion
22
+ * limit is the `tool_call_limit` outcome (the platform's budget, not a
23
+ * failure; the runtime writes TERMINATED with the cross-repo prefix); any
24
+ * other exception — a provider error unwrapped from LangChain's middleware
25
+ * wrapper, an MCP connect failure, an empty stream — is `failed` on the
26
+ * `internal` surface with `describeExecutionError`'s sentence as
27
+ * `status.error` whole (Q-M2a-9). Never branches on why `stopSignal`
28
+ * aborted, never writes a phase or a terminal copy, never imports
29
+ * `@temporalio/*` (`__tests__/adapter-is-temporal-free.test.ts`).
30
+ *
31
+ * Engine disposition: nothing is parked between turns. The sqlite saver is
32
+ * opened and closed per turn (it holds an OS handle); the MCP subprocesses
33
+ * are connected and closed per turn. Both are closed on EVERY exit path in
34
+ * the `finally`, before the runtime removes the link and releases the lock.
35
+ *
36
+ * Extracted from `index.ts` `createDeepAgentActivities` at S3 M2a; the
37
+ * hermetic goldens under `__tests__/hermetic/` pin the result byte for
38
+ * byte, with the ruled alignments quoted in their headers.
39
+ */
40
+ import type { TurnInput, TurnOutcome, TurnSink } from "../../harness/types.js";
41
+ import { type DeepAgentAdapterConfig } from "./turn-setup.js";
42
+ export declare function runDeepAgentTurn(input: TurnInput, sink: TurnSink, config: DeepAgentAdapterConfig): Promise<TurnOutcome>;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * One native deep-agent engine turn — the LangGraph slice of the harness,
3
+ * behind the turn runtime's contract (`harness/types.ts`).
4
+ *
5
+ * `runDeepAgentTurn` is what `adapter.ts`'s `runTurn` delegates to: the
6
+ * setup over the runtime's record (`turn-setup.ts`), the stream over the
7
+ * sink (`turn-stream.ts`), the settle (`turn-settle.ts`), and its own
8
+ * teardown — the MCP connection and the checkpoint saver. Everything else
9
+ * about a turn is the runtime's (`harness/run-turn.ts`): the resolution
10
+ * phases, the workspace lock and the `.stigmer` link, the persist
11
+ * chokepoint, the watchdog, the heartbeat, the cost cap, the interruption
12
+ * table, the completion epilogue, the SKIP/REJECT settlement.
13
+ *
14
+ * This module is where `deepagents` and `@langchain/*` enter the adapter's
15
+ * graph (through `turn-setup.ts` and its siblings), which is WHY it is a
16
+ * separate module from `adapter.ts` and is loaded there with a dynamic
17
+ * import inside `boot`: the harness table's static graph must stay SDK-free
18
+ * so a worker that does not serve this harness never pays for LangChain
19
+ * (`harness-adapters.ts`). Nothing outside `adapter.ts` imports this module.
20
+ *
21
+ * Never throws out of `runDeepAgentTurn`: the graph exhausting its recursion
22
+ * limit is the `tool_call_limit` outcome (the platform's budget, not a
23
+ * failure; the runtime writes TERMINATED with the cross-repo prefix); any
24
+ * other exception — a provider error unwrapped from LangChain's middleware
25
+ * wrapper, an MCP connect failure, an empty stream — is `failed` on the
26
+ * `internal` surface with `describeExecutionError`'s sentence as
27
+ * `status.error` whole (Q-M2a-9). Never branches on why `stopSignal`
28
+ * aborted, never writes a phase or a terminal copy, never imports
29
+ * `@temporalio/*` (`__tests__/adapter-is-temporal-free.test.ts`).
30
+ *
31
+ * Engine disposition: nothing is parked between turns. The sqlite saver is
32
+ * opened and closed per turn (it holds an OS handle); the MCP subprocesses
33
+ * are connected and closed per turn. Both are closed on EVERY exit path in
34
+ * the `finally`, before the runtime removes the link and releases the lock.
35
+ *
36
+ * Extracted from `index.ts` `createDeepAgentActivities` at S3 M2a; the
37
+ * hermetic goldens under `__tests__/hermetic/` pin the result byte for
38
+ * byte, with the ruled alignments quoted in their headers.
39
+ */
40
+ import { tryInferProvider } from "../../shared/llm-proxy.js";
41
+ import { describeExecutionError } from "../../shared/model-error.js";
42
+ import { isGraphRecursionError } from "../../shared/tool-rounds.js";
43
+ import { buildDeepAgentWorkspace, buildEngine, composeGraphInput, connectTools, openCheckpointer, readGateState, resolveModelName, } from "./turn-setup.js";
44
+ import { consumeDeepAgentStream, createDeepAgentTranscript } from "./turn-stream.js";
45
+ import { settleDeepAgentTurn } from "./turn-settle.js";
46
+ export async function runDeepAgentTurn(input, sink, config) {
47
+ if (sink.stopSignal.aborted)
48
+ return { kind: "interrupted" };
49
+ let checkpointer;
50
+ let connection;
51
+ let modelName;
52
+ try {
53
+ modelName = await resolveModelName(input);
54
+ checkpointer = await openCheckpointer(input, sink, config);
55
+ const workspace = buildDeepAgentWorkspace(input);
56
+ // What this engine observes touching CAS-owned paths — the one capture
57
+ // fact the runtime cannot read from the tree (`harness/capture.ts`).
58
+ sink.bindCasObservations(() => workspace.casObserver.snapshot());
59
+ const tools = await connectTools(input, sink);
60
+ connection = tools.connection;
61
+ if (sink.stopSignal.aborted)
62
+ return { kind: "interrupted" };
63
+ const gate = readGateState(input, tools);
64
+ const engine = await buildEngine(input, sink, config, { modelName, checkpointer, workspace, tools, gate });
65
+ if (sink.stopSignal.aborted)
66
+ return { kind: "interrupted" };
67
+ const graphInput = await composeGraphInput(input, engine);
68
+ sink.recordActivity();
69
+ const transcript = createDeepAgentTranscript(input, sink, engine, workspace);
70
+ const stream = await consumeDeepAgentStream({ input, sink, engine, graphInput, transcript });
71
+ return await settleDeepAgentTurn({ input, sink, engine, transcript, stream });
72
+ }
73
+ catch (err) {
74
+ return classifyThrown(err, input, config, modelName);
75
+ }
76
+ finally {
77
+ await closeQuietly(input.executionId, "MCP connection", () => connection?.client.close());
78
+ // Only the durable sqlite saver holds an OS handle (an open DB file);
79
+ // memory/http savers have no close(), so this is duck-typed.
80
+ const closable = checkpointer;
81
+ await closeQuietly(input.executionId, "checkpointer", () => closable?.close?.());
82
+ }
83
+ }
84
+ /**
85
+ * An exception that escaped the turn, classified. The graph's recursion
86
+ * limit is the budget's own signal (`shared/tool-rounds.ts`), not an error:
87
+ * the work is checkpointed and the conversation continues on the next
88
+ * message. Anything else is described by `describeExecutionError` (a model
89
+ * error arrives MiddlewareError-wrapped with raw provider prose and is
90
+ * unwrapped to its stable platform code; non-model errors keep the root
91
+ * error's identity) on the `internal` surface: the runner or its transport
92
+ * broke.
93
+ */
94
+ function classifyThrown(err, input, config, modelName) {
95
+ if (isGraphRecursionError(err)) {
96
+ console.log(`ExecuteDeepAgent reached the tool-call limit: execution=${input.executionId}`);
97
+ return { kind: "tool_call_limit" };
98
+ }
99
+ const { errorType, errorMessage } = describeExecutionError(err, {
100
+ proxyMode: !!config.proxyEndpoint,
101
+ modelId: modelName,
102
+ provider: modelName ? (tryInferProvider(modelName) ?? undefined) : undefined,
103
+ });
104
+ console.error(`ExecuteDeepAgent failed: execution=${input.executionId}, [${errorType}] ${errorMessage}`);
105
+ return { kind: "failed", surface: "internal", message: `[${errorType}] ${errorMessage}`, cause: err };
106
+ }
107
+ /** Best-effort teardown: a failed close is logged and never masks the turn's outcome. */
108
+ async function closeQuietly(executionId, what, close) {
109
+ try {
110
+ await close();
111
+ }
112
+ catch (err) {
113
+ console.warn(`ExecuteDeepAgent ${what} cleanup failed (non-fatal): execution=${executionId}, error=${err}`);
114
+ }
115
+ }
116
+ //# sourceMappingURL=turn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn.js","sourceRoot":"","sources":["../../../src/activities/execute-deep-agent/turn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAMH,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EACL,uBAAuB,EACvB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,gBAAgB,GAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAgB,EAAE,IAAc,EAAE,MAA8B;IACrG,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO;QAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IAE5D,IAAI,YAA6C,CAAC;IAClD,IAAI,UAA2C,CAAC;IAChD,IAAI,SAA6B,CAAC;IAElC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IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,SAAS,KAAK,YAAY,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACxG,CAAC;AAED,yFAAyF;AACzF,KAAK,UAAU,YAAY,CAAC,WAAmB,EAAE,IAAY,EAAE,KAA6C;IAC1G,IAAI,CAAC;QACH,MAAM,KAAK,EAAE,CAAC;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,oBAAoB,IAAI,0CAA0C,WAAW,WAAW,GAAG,EAAE,CAAC,CAAC;IAC9G,CAAC;AACH,CAAC"}
@@ -2,12 +2,13 @@
2
2
  * V3 event recorder for capturing raw LangGraph v3 ProtocolEvents.
3
3
  *
4
4
  * Activated by the V3_EVENT_RECORD_DIR environment variable. When set,
5
- * the v3 streaming loop records every raw protocol event and flushes
6
- * them atomically to a JSON file after the stream completes.
5
+ * the adapter's stream loop (`turn-stream.ts`) records every raw protocol
6
+ * event and flushes them atomically to a JSON file after the stream
7
+ * completes — the native twin of `execute-cursor/cursor-event-recorder.ts`.
7
8
  *
8
- * This is test/development infrastructure for the v3 streaming migration.
9
- * The captured events serve as ground-truth for building the
10
- * V3StatusBuilder and validating v3 event shape assumptions.
9
+ * Development infrastructure: the captured events are the ground truth the
10
+ * v3 fixtures (`__test-utils__/v3-event-fixtures.ts`) and the builder's
11
+ * tests were shaped from, and the way a new provider's event shape is read.
11
12
  */
12
13
  export interface V3EventRecorder {
13
14
  record(event: V3ProtocolEvent, seq: number): void;
@@ -2,12 +2,13 @@
2
2
  * V3 event recorder for capturing raw LangGraph v3 ProtocolEvents.
3
3
  *
4
4
  * Activated by the V3_EVENT_RECORD_DIR environment variable. When set,
5
- * the v3 streaming loop records every raw protocol event and flushes
6
- * them atomically to a JSON file after the stream completes.
5
+ * the adapter's stream loop (`turn-stream.ts`) records every raw protocol
6
+ * event and flushes them atomically to a JSON file after the stream
7
+ * completes — the native twin of `execute-cursor/cursor-event-recorder.ts`.
7
8
  *
8
- * This is test/development infrastructure for the v3 streaming migration.
9
- * The captured events serve as ground-truth for building the
10
- * V3StatusBuilder and validating v3 event shape assumptions.
9
+ * Development infrastructure: the captured events are the ground truth the
10
+ * v3 fixtures (`__test-utils__/v3-event-fixtures.ts`) and the builder's
11
+ * tests were shaped from, and the way a new provider's event shape is read.
11
12
  */
12
13
  import { writeFile, mkdir } from "node:fs/promises";
13
14
  import { join } from "node:path";
@@ -1 +1 @@
1
- {"version":3,"file":"v3-event-recorder.js","sourceRoot":"","sources":["../../../src/activities/execute-deep-agent/v3-event-recorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AA8BjC;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,SAA6B;IAE7B,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IACjC,OAAO,IAAI,mBAAmB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,mBAAmB;IAIJ;IACA;IAJF,MAAM,GAAsB,EAAE,CAAC;IAEhD,YACmB,WAAmB,EACnB,SAAiB;QADjB,gBAAW,GAAX,WAAW,CAAQ;QACnB,cAAS,GAAT,SAAS,CAAQ;IACjC,CAAC;IAEJ,MAAM,CAAC,KAAsB,EAAE,GAAW;QACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACf,GAAG;YACH,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACpC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;YACjC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;YACj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OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9D,CAAC"}
1
+ {"version":3,"file":"v3-event-recorder.js","sourceRoot":"","sources":["../../../src/activities/execute-deep-agent/v3-event-recorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AA8BjC;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,SAA6B;IAE7B,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IACjC,OAAO,IAAI,mBAAmB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,mBAAmB;IAIJ;IACA;IAJF,MAAM,GAAsB,EAAE,CAAC;IAEhD,YACmB,WAAmB,EACnB,SAAiB;QADjB,gBAAW,GAAX,WAAW,CAAQ;QACnB,cAAS,GAAT,SAAS,CAAQ;IACjC,CAAC;IAEJ,MAAM,CAAC,KAAsB,EAAE,GAAW;QACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACf,GAAG;YACH,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACpC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;YACjC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;YACjC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI;YACvB,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;SACnC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,MAAM,CAAC,MAA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posed to
9
- * clients). It isolates the StatusBuilder from LangGraph protocol
9
+ * clients). It isolates the V3StatusBuilder from LangGraph protocol
10
10
  * instability (field naming, delta shapes, channel semantics).
11
11
  *
12
12
  * ID conventions:
@@ -6,7 +6,7 @@
6
6
  * AgentExecutionStatus proto.
7
7
  *
8
8
  * This is a runner-internal contract (not persisted, not exposed to
9
- * clients). It isolates the StatusBuilder from LangGraph protocol
9
+ * clients). It isolates the V3StatusBuilder from LangGraph protocol
10
10
  * instability (field naming, delta shapes, channel semantics).
11
11
  *
12
12
  * ID conventions:
@@ -1,32 +1,77 @@
1
1
  /**
2
2
  * V3StatusBuilder — consumes StigmerRunEvents from the V3ProtocolNormalizer
3
- * and progressively builds the AgentExecutionStatus proto.
3
+ * and progressively builds the transcript half of the AgentExecutionStatus
4
+ * proto it is handed: messages, tool-call rows and their approval status,
5
+ * sub-agent rows, todos, artifacts, write-backs.
4
6
  *
5
- * Implements the same behavioral contract as the v2 StatusBuilder for all
6
- * 8 golden scenarios, using v3 event semantics (tool_call_id keying,
7
- * content-block-level deltas, explicit tool lifecycle).
7
+ * The one transcript builder of the native harness since S3 M2b: v3 event
8
+ * semantics (tool_call_id keying, content-block-level deltas, explicit tool
9
+ * lifecycle). Its predecessor, the v2 `StatusBuilder` over LangChain's
10
+ * `streamEvents` v2, was retired with the v2 stream (Q-S3-1); the eight
11
+ * golden sequences both once had to agree on are this builder's test's.
8
12
  *
9
- * Usage is accumulated on message_finish only (standalone usage events are
13
+ * What this builder deliberately does NOT write, and who does (the adapter
14
+ * contract's field ownership, `harness/types.ts` `TurnSink`): the phase,
15
+ * `startedAt` and `streamingUsage` are the turn runtime's. A gated tool
16
+ * start is reported as the {@link awaitingApproval} fact and the caller
17
+ * (`turn-stream.ts`) decides what that means for the turn; usage is reported
18
+ * raw through {@link V3StatusBuilderOptions.onUsage} and the caller prices
19
+ * it into the sink (until S3 M2a this builder flipped WAITING_FOR_APPROVAL
20
+ * itself and summed usage into `streamingUsage` — a second writer of each
21
+ * field beside the runtime's).
22
+ *
23
+ * Usage is reported on message_finish only (standalone usage events are
10
24
  * no-ops) to prevent double-counting — v3 emits both for the same turn.
25
+ * EVERY graph's usage is reported, the sub-agents' included (S3 M2b,
26
+ * Q-M2b-1): a sub-agent's `message_finish` fires the same hook before it is
27
+ * routed to the tracker, so the execution's usage — and the cost cap the
28
+ * runtime enforces over it — is the whole execution's spend. Until M2b the
29
+ * sub-agents' turns were discarded (S3 M2a finding F-M2a-12); the cost cap
30
+ * then lived inside the graph, where a middleware saw every model call.
11
31
  */
12
32
  import type { AgentExecutionStatus } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
13
33
  import type { ExecutionArtifact } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/artifact_pb";
14
34
  import type { WorkspaceWriteBack } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/writeback_pb";
15
35
  import type { ExecutionStatusWriter } from "../../shared/execution-status-writer.js";
16
- import type { ApprovalPolicyProvider } from "./status-builder.js";
17
- import type { StigmerRunEvent } from "./v3-events.js";
36
+ import type { StigmerRunEvent, V3UsagePayload } from "./v3-events.js";
37
+ import { type ApprovalPolicyProvider } from "./status-builder-shared.js";
38
+ export interface V3StatusBuilderOptions {
39
+ /**
40
+ * Fired once per `message_finish` that carries usage — the parent graph's
41
+ * and every sub-agent's — with the payload exactly as the protocol
42
+ * delivered it. The builder never sums or prices: the caller accounts (the
43
+ * turn runtime through `TurnSink.reportUsage`, priced at the turn's model;
44
+ * a sub-agent on its own model is priced at the parent's rate, as the
45
+ * in-graph cost cap always did — per-sub-agent pricing is an S5 item).
46
+ */
47
+ readonly onUsage?: (usage: V3UsagePayload) => void;
48
+ }
18
49
  export declare class V3StatusBuilder implements ExecutionStatusWriter {
19
50
  readonly executionId: string;
20
51
  private readonly state;
21
52
  private _forceNextUpdate;
53
+ private _awaitingApproval;
22
54
  private approvalProvider;
23
- private readonly usageAccumulator;
55
+ private readonly onUsage;
24
56
  private readonly subAgentTracker;
25
57
  /** Progressive tool call arg accumulation keyed by callId. */
26
58
  private readonly toolArgBuffers;
27
- constructor(executionId: string, initialStatus: AgentExecutionStatus);
59
+ /**
60
+ * Builds INTO `status`, by reference: its `messages` and
61
+ * `subAgentExecutions` arrays are the ones indexed and pushed into, never
62
+ * replaced, so a caller that wraps the same status (the write-back
63
+ * coordinator's writer, the runtime's chokepoint) keeps seeing every row.
64
+ */
65
+ constructor(executionId: string, status: AgentExecutionStatus, options?: V3StatusBuilderOptions);
28
66
  setApprovalProvider(provider: ApprovalPolicyProvider): void;
29
67
  get currentStatus(): AgentExecutionStatus;
68
+ /**
69
+ * True once a tool call this turn was gated and left WAITING_APPROVAL: the
70
+ * engine has interrupted (or will, at this step's end) and the turn should
71
+ * end awaiting a decision. A fact about the transcript, not a phase — the
72
+ * caller owns the phase.
73
+ */
74
+ get awaitingApproval(): boolean;
30
75
  get forceNextUpdate(): boolean;
31
76
  clearForceFlag(): void;
32
77
  processEvent(event: StigmerRunEvent): void;
@@ -50,19 +95,17 @@ export declare class V3StatusBuilder implements ExecutionStatusWriter {
50
95
  private checkApprovalRequirement;
51
96
  private ensureAiMessage;
52
97
  private ensureAiMessageForToolCall;
53
- private accumulateV3Usage;
54
98
  /**
55
99
  * Check if a tool_call_id belongs to a tracked "task" tool invocation.
56
100
  * Used to route tool_finished/tool_error events to both parent and tracker.
57
101
  */
58
102
  private isTrackedTaskTool;
59
103
  /**
60
- * Sync sub-agent executions into the proto for persistence.
61
- * Called by the streaming orchestrator before each persist.
62
- */
63
- syncSubAgentExecutions(): void;
64
- /**
65
- * Cancel all in-progress sub-agents (called on parent cancellation).
104
+ * Clear the streaming flag on every sub-agent message still marked as
105
+ * streaming what a turn that stopped mid-delegation owes the transcript
106
+ * beside the CANCELLED status the caller stamps on the row itself
107
+ * (`shared/subagent-rows.ts` `cancelInProgressSubAgentProtos`, the one
108
+ * home of that transition for every harness).
66
109
  */
67
- cancelSubAgents(): void;
110
+ finalizeSubAgentStreaming(): void;
68
111
  }