@sema-ai/core 1.275.1

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 (962) hide show
  1. package/CHANGELOG.md +5433 -0
  2. package/LICENSE +27 -0
  3. package/NOTICE.md +30 -0
  4. package/README.md +1040 -0
  5. package/dist/agents/agent-definition.d.ts +10 -0
  6. package/dist/agents/agent-definition.d.ts.map +1 -0
  7. package/dist/agents/agent-definition.js +18 -0
  8. package/dist/agents/agent-definition.js.map +1 -0
  9. package/dist/agents/builtin-agents.d.ts +69 -0
  10. package/dist/agents/builtin-agents.d.ts.map +1 -0
  11. package/dist/agents/builtin-agents.js +177 -0
  12. package/dist/agents/builtin-agents.js.map +1 -0
  13. package/dist/agents/cascade.d.ts +101 -0
  14. package/dist/agents/cascade.d.ts.map +1 -0
  15. package/dist/agents/cascade.js +189 -0
  16. package/dist/agents/cascade.js.map +1 -0
  17. package/dist/agents/observer.d.ts +209 -0
  18. package/dist/agents/observer.d.ts.map +1 -0
  19. package/dist/agents/observer.js +495 -0
  20. package/dist/agents/observer.js.map +1 -0
  21. package/dist/agents/repair-loop.d.ts +236 -0
  22. package/dist/agents/repair-loop.d.ts.map +1 -0
  23. package/dist/agents/repair-loop.js +293 -0
  24. package/dist/agents/repair-loop.js.map +1 -0
  25. package/dist/agents/session-util.d.ts +8 -0
  26. package/dist/agents/session-util.d.ts.map +1 -0
  27. package/dist/agents/session-util.js +9 -0
  28. package/dist/agents/session-util.js.map +1 -0
  29. package/dist/agents/subagent-steps.d.ts +93 -0
  30. package/dist/agents/subagent-steps.d.ts.map +1 -0
  31. package/dist/agents/subagent-steps.js +206 -0
  32. package/dist/agents/subagent-steps.js.map +1 -0
  33. package/dist/agents/subagent.d.ts +441 -0
  34. package/dist/agents/subagent.d.ts.map +1 -0
  35. package/dist/agents/subagent.js +2492 -0
  36. package/dist/agents/subagent.js.map +1 -0
  37. package/dist/agents/suspend-guard.d.ts +35 -0
  38. package/dist/agents/suspend-guard.d.ts.map +1 -0
  39. package/dist/agents/suspend-guard.js +48 -0
  40. package/dist/agents/suspend-guard.js.map +1 -0
  41. package/dist/agents/teacher.d.ts +137 -0
  42. package/dist/agents/teacher.d.ts.map +1 -0
  43. package/dist/agents/teacher.js +575 -0
  44. package/dist/agents/teacher.js.map +1 -0
  45. package/dist/agents/team.d.ts +211 -0
  46. package/dist/agents/team.d.ts.map +1 -0
  47. package/dist/agents/team.js +293 -0
  48. package/dist/agents/team.js.map +1 -0
  49. package/dist/agents/tool-filter.d.ts +29 -0
  50. package/dist/agents/tool-filter.d.ts.map +1 -0
  51. package/dist/agents/tool-filter.js +50 -0
  52. package/dist/agents/tool-filter.js.map +1 -0
  53. package/dist/agents/verify.d.ts +177 -0
  54. package/dist/agents/verify.d.ts.map +1 -0
  55. package/dist/agents/verify.js +305 -0
  56. package/dist/agents/verify.js.map +1 -0
  57. package/dist/bench/metrics.d.ts +714 -0
  58. package/dist/bench/metrics.d.ts.map +1 -0
  59. package/dist/bench/metrics.js +618 -0
  60. package/dist/bench/metrics.js.map +1 -0
  61. package/dist/bin/sema-tb.d.ts +3 -0
  62. package/dist/bin/sema-tb.d.ts.map +1 -0
  63. package/dist/bin/sema-tb.js +516 -0
  64. package/dist/bin/sema-tb.js.map +1 -0
  65. package/dist/bin/tb-env.d.ts +13 -0
  66. package/dist/bin/tb-env.d.ts.map +1 -0
  67. package/dist/bin/tb-env.js +26 -0
  68. package/dist/bin/tb-env.js.map +1 -0
  69. package/dist/brain/anthropic.d.ts +46 -0
  70. package/dist/brain/anthropic.d.ts.map +1 -0
  71. package/dist/brain/anthropic.js +830 -0
  72. package/dist/brain/anthropic.js.map +1 -0
  73. package/dist/brain/circuit-breaker.d.ts +46 -0
  74. package/dist/brain/circuit-breaker.d.ts.map +1 -0
  75. package/dist/brain/circuit-breaker.js +173 -0
  76. package/dist/brain/circuit-breaker.js.map +1 -0
  77. package/dist/brain/degrading.d.ts +98 -0
  78. package/dist/brain/degrading.d.ts.map +1 -0
  79. package/dist/brain/degrading.js +249 -0
  80. package/dist/brain/degrading.js.map +1 -0
  81. package/dist/brain/errors.d.ts +31 -0
  82. package/dist/brain/errors.d.ts.map +1 -0
  83. package/dist/brain/errors.js +58 -0
  84. package/dist/brain/errors.js.map +1 -0
  85. package/dist/brain/failover.d.ts +18 -0
  86. package/dist/brain/failover.d.ts.map +1 -0
  87. package/dist/brain/failover.js +118 -0
  88. package/dist/brain/failover.js.map +1 -0
  89. package/dist/brain/model-presets.d.ts +36 -0
  90. package/dist/brain/model-presets.d.ts.map +1 -0
  91. package/dist/brain/model-presets.js +54 -0
  92. package/dist/brain/model-presets.js.map +1 -0
  93. package/dist/brain/openai.d.ts +43 -0
  94. package/dist/brain/openai.d.ts.map +1 -0
  95. package/dist/brain/openai.js +784 -0
  96. package/dist/brain/openai.js.map +1 -0
  97. package/dist/brain/reasoning.d.ts +138 -0
  98. package/dist/brain/reasoning.d.ts.map +1 -0
  99. package/dist/brain/reasoning.js +146 -0
  100. package/dist/brain/reasoning.js.map +1 -0
  101. package/dist/brain/repetition.d.ts +60 -0
  102. package/dist/brain/repetition.d.ts.map +1 -0
  103. package/dist/brain/repetition.js +121 -0
  104. package/dist/brain/repetition.js.map +1 -0
  105. package/dist/brain/request-params.d.ts +29 -0
  106. package/dist/brain/request-params.d.ts.map +1 -0
  107. package/dist/brain/request-params.js +78 -0
  108. package/dist/brain/request-params.js.map +1 -0
  109. package/dist/brain/retry.d.ts +18 -0
  110. package/dist/brain/retry.d.ts.map +1 -0
  111. package/dist/brain/retry.js +42 -0
  112. package/dist/brain/retry.js.map +1 -0
  113. package/dist/brain/routing.d.ts +19 -0
  114. package/dist/brain/routing.d.ts.map +1 -0
  115. package/dist/brain/routing.js +44 -0
  116. package/dist/brain/routing.js.map +1 -0
  117. package/dist/brain/status-sink.d.ts +46 -0
  118. package/dist/brain/status-sink.d.ts.map +1 -0
  119. package/dist/brain/status-sink.js +36 -0
  120. package/dist/brain/status-sink.js.map +1 -0
  121. package/dist/brain/stream-engine.d.ts +85 -0
  122. package/dist/brain/stream-engine.d.ts.map +1 -0
  123. package/dist/brain/stream-engine.js +391 -0
  124. package/dist/brain/stream-engine.js.map +1 -0
  125. package/dist/brain/timeout.d.ts +44 -0
  126. package/dist/brain/timeout.d.ts.map +1 -0
  127. package/dist/brain/timeout.js +41 -0
  128. package/dist/brain/timeout.js.map +1 -0
  129. package/dist/brain/tool-call-repair.d.ts +15 -0
  130. package/dist/brain/tool-call-repair.d.ts.map +1 -0
  131. package/dist/brain/tool-call-repair.js +67 -0
  132. package/dist/brain/tool-call-repair.js.map +1 -0
  133. package/dist/brain/walltime.d.ts +14 -0
  134. package/dist/brain/walltime.d.ts.map +1 -0
  135. package/dist/brain/walltime.js +14 -0
  136. package/dist/brain/walltime.js.map +1 -0
  137. package/dist/core/arg-summary.d.ts +19 -0
  138. package/dist/core/arg-summary.d.ts.map +1 -0
  139. package/dist/core/arg-summary.js +96 -0
  140. package/dist/core/arg-summary.js.map +1 -0
  141. package/dist/core/ask-question.d.ts +113 -0
  142. package/dist/core/ask-question.d.ts.map +1 -0
  143. package/dist/core/ask-question.js +246 -0
  144. package/dist/core/ask-question.js.map +1 -0
  145. package/dist/core/auto-compaction.d.ts +341 -0
  146. package/dist/core/auto-compaction.d.ts.map +1 -0
  147. package/dist/core/auto-compaction.js +495 -0
  148. package/dist/core/auto-compaction.js.map +1 -0
  149. package/dist/core/auto-promote.d.ts +126 -0
  150. package/dist/core/auto-promote.d.ts.map +1 -0
  151. package/dist/core/auto-promote.js +171 -0
  152. package/dist/core/auto-promote.js.map +1 -0
  153. package/dist/core/background-shell.d.ts +128 -0
  154. package/dist/core/background-shell.d.ts.map +1 -0
  155. package/dist/core/background-shell.js +42 -0
  156. package/dist/core/background-shell.js.map +1 -0
  157. package/dist/core/cache-break-detector.d.ts +63 -0
  158. package/dist/core/cache-break-detector.d.ts.map +1 -0
  159. package/dist/core/cache-break-detector.js +0 -0
  160. package/dist/core/cache-break-detector.js.map +1 -0
  161. package/dist/core/canonical-json.d.ts +45 -0
  162. package/dist/core/canonical-json.d.ts.map +1 -0
  163. package/dist/core/canonical-json.js +132 -0
  164. package/dist/core/canonical-json.js.map +1 -0
  165. package/dist/core/checkpoint-store.d.ts +1101 -0
  166. package/dist/core/checkpoint-store.d.ts.map +1 -0
  167. package/dist/core/checkpoint-store.js +514 -0
  168. package/dist/core/checkpoint-store.js.map +1 -0
  169. package/dist/core/consolidate-scope.d.ts +94 -0
  170. package/dist/core/consolidate-scope.d.ts.map +1 -0
  171. package/dist/core/consolidate-scope.js +158 -0
  172. package/dist/core/consolidate-scope.js.map +1 -0
  173. package/dist/core/context-edit.d.ts +82 -0
  174. package/dist/core/context-edit.d.ts.map +1 -0
  175. package/dist/core/context-edit.js +149 -0
  176. package/dist/core/context-edit.js.map +1 -0
  177. package/dist/core/context-guard.d.ts +43 -0
  178. package/dist/core/context-guard.d.ts.map +1 -0
  179. package/dist/core/context-guard.js +171 -0
  180. package/dist/core/context-guard.js.map +1 -0
  181. package/dist/core/dynamic-recall.d.ts +100 -0
  182. package/dist/core/dynamic-recall.d.ts.map +1 -0
  183. package/dist/core/dynamic-recall.js +108 -0
  184. package/dist/core/dynamic-recall.js.map +1 -0
  185. package/dist/core/exec-gate.d.ts +74 -0
  186. package/dist/core/exec-gate.d.ts.map +1 -0
  187. package/dist/core/exec-gate.js +143 -0
  188. package/dist/core/exec-gate.js.map +1 -0
  189. package/dist/core/exec-output-tail.d.ts +37 -0
  190. package/dist/core/exec-output-tail.d.ts.map +1 -0
  191. package/dist/core/exec-output-tail.js +63 -0
  192. package/dist/core/exec-output-tail.js.map +1 -0
  193. package/dist/core/file-snapshot-store.d.ts +137 -0
  194. package/dist/core/file-snapshot-store.d.ts.map +1 -0
  195. package/dist/core/file-snapshot-store.js +319 -0
  196. package/dist/core/file-snapshot-store.js.map +1 -0
  197. package/dist/core/git-worktree-env.d.ts +41 -0
  198. package/dist/core/git-worktree-env.d.ts.map +1 -0
  199. package/dist/core/git-worktree-env.js +64 -0
  200. package/dist/core/git-worktree-env.js.map +1 -0
  201. package/dist/core/hooks.d.ts +372 -0
  202. package/dist/core/hooks.d.ts.map +1 -0
  203. package/dist/core/hooks.js +269 -0
  204. package/dist/core/hooks.js.map +1 -0
  205. package/dist/core/lsp-diagnostics.d.ts +74 -0
  206. package/dist/core/lsp-diagnostics.d.ts.map +1 -0
  207. package/dist/core/lsp-diagnostics.js +125 -0
  208. package/dist/core/lsp-diagnostics.js.map +1 -0
  209. package/dist/core/lsp-protocol.d.ts +28 -0
  210. package/dist/core/lsp-protocol.d.ts.map +1 -0
  211. package/dist/core/lsp-protocol.js +179 -0
  212. package/dist/core/lsp-protocol.js.map +1 -0
  213. package/dist/core/lsp-session.d.ts +56 -0
  214. package/dist/core/lsp-session.d.ts.map +1 -0
  215. package/dist/core/lsp-session.js +185 -0
  216. package/dist/core/lsp-session.js.map +1 -0
  217. package/dist/core/lsp.d.ts +132 -0
  218. package/dist/core/lsp.d.ts.map +1 -0
  219. package/dist/core/lsp.js +147 -0
  220. package/dist/core/lsp.js.map +1 -0
  221. package/dist/core/mcp.d.ts +294 -0
  222. package/dist/core/mcp.d.ts.map +1 -0
  223. package/dist/core/mcp.js +992 -0
  224. package/dist/core/mcp.js.map +1 -0
  225. package/dist/core/media-byte-cap.d.ts +34 -0
  226. package/dist/core/media-byte-cap.d.ts.map +1 -0
  227. package/dist/core/media-byte-cap.js +76 -0
  228. package/dist/core/media-byte-cap.js.map +1 -0
  229. package/dist/core/memory-engine/data-plane.d.ts +103 -0
  230. package/dist/core/memory-engine/data-plane.d.ts.map +1 -0
  231. package/dist/core/memory-engine/data-plane.js +272 -0
  232. package/dist/core/memory-engine/data-plane.js.map +1 -0
  233. package/dist/core/memory-engine/dual-root.d.ts +40 -0
  234. package/dist/core/memory-engine/dual-root.d.ts.map +1 -0
  235. package/dist/core/memory-engine/dual-root.js +95 -0
  236. package/dist/core/memory-engine/dual-root.js.map +1 -0
  237. package/dist/core/memory-engine/engine.d.ts +161 -0
  238. package/dist/core/memory-engine/engine.d.ts.map +1 -0
  239. package/dist/core/memory-engine/engine.js +1110 -0
  240. package/dist/core/memory-engine/engine.js.map +1 -0
  241. package/dist/core/memory-engine/file-backend.d.ts +162 -0
  242. package/dist/core/memory-engine/file-backend.d.ts.map +1 -0
  243. package/dist/core/memory-engine/file-backend.js +948 -0
  244. package/dist/core/memory-engine/file-backend.js.map +1 -0
  245. package/dist/core/memory-engine/frontmatter.d.ts +24 -0
  246. package/dist/core/memory-engine/frontmatter.d.ts.map +1 -0
  247. package/dist/core/memory-engine/frontmatter.js +135 -0
  248. package/dist/core/memory-engine/frontmatter.js.map +1 -0
  249. package/dist/core/memory-engine/index.d.ts +13 -0
  250. package/dist/core/memory-engine/index.d.ts.map +1 -0
  251. package/dist/core/memory-engine/index.js +28 -0
  252. package/dist/core/memory-engine/index.js.map +1 -0
  253. package/dist/core/memory-engine/layout.d.ts +123 -0
  254. package/dist/core/memory-engine/layout.d.ts.map +1 -0
  255. package/dist/core/memory-engine/layout.js +643 -0
  256. package/dist/core/memory-engine/layout.js.map +1 -0
  257. package/dist/core/memory-engine/memory-backend-contract.d.ts +22 -0
  258. package/dist/core/memory-engine/memory-backend-contract.d.ts.map +1 -0
  259. package/dist/core/memory-engine/memory-backend-contract.js +271 -0
  260. package/dist/core/memory-engine/memory-backend-contract.js.map +1 -0
  261. package/dist/core/memory-engine/migrate.d.ts +17 -0
  262. package/dist/core/memory-engine/migrate.d.ts.map +1 -0
  263. package/dist/core/memory-engine/migrate.js +35 -0
  264. package/dist/core/memory-engine/migrate.js.map +1 -0
  265. package/dist/core/memory-engine/scan.d.ts +20 -0
  266. package/dist/core/memory-engine/scan.d.ts.map +1 -0
  267. package/dist/core/memory-engine/scan.js +84 -0
  268. package/dist/core/memory-engine/scan.js.map +1 -0
  269. package/dist/core/memory-engine/scope-contract.d.ts +104 -0
  270. package/dist/core/memory-engine/scope-contract.d.ts.map +1 -0
  271. package/dist/core/memory-engine/scope-contract.js +288 -0
  272. package/dist/core/memory-engine/scope-contract.js.map +1 -0
  273. package/dist/core/memory-engine/sync-client.d.ts +100 -0
  274. package/dist/core/memory-engine/sync-client.d.ts.map +1 -0
  275. package/dist/core/memory-engine/sync-client.js +328 -0
  276. package/dist/core/memory-engine/sync-client.js.map +1 -0
  277. package/dist/core/memory-engine/sync.d.ts +97 -0
  278. package/dist/core/memory-engine/sync.d.ts.map +1 -0
  279. package/dist/core/memory-engine/sync.js +91 -0
  280. package/dist/core/memory-engine/sync.js.map +1 -0
  281. package/dist/core/memory-engine/types.d.ts +279 -0
  282. package/dist/core/memory-engine/types.d.ts.map +1 -0
  283. package/dist/core/memory-engine/types.js +9 -0
  284. package/dist/core/memory-engine/types.js.map +1 -0
  285. package/dist/core/memory-recall.d.ts +261 -0
  286. package/dist/core/memory-recall.d.ts.map +1 -0
  287. package/dist/core/memory-recall.js +600 -0
  288. package/dist/core/memory-recall.js.map +1 -0
  289. package/dist/core/memory-vector.d.ts +24 -0
  290. package/dist/core/memory-vector.d.ts.map +1 -0
  291. package/dist/core/memory-vector.js +51 -0
  292. package/dist/core/memory-vector.js.map +1 -0
  293. package/dist/core/memory.d.ts +502 -0
  294. package/dist/core/memory.d.ts.map +1 -0
  295. package/dist/core/memory.js +881 -0
  296. package/dist/core/memory.js.map +1 -0
  297. package/dist/core/message-utils.d.ts +7 -0
  298. package/dist/core/message-utils.d.ts.map +1 -0
  299. package/dist/core/message-utils.js +10 -0
  300. package/dist/core/message-utils.js.map +1 -0
  301. package/dist/core/oracle-isolation.d.ts +85 -0
  302. package/dist/core/oracle-isolation.d.ts.map +1 -0
  303. package/dist/core/oracle-isolation.js +121 -0
  304. package/dist/core/oracle-isolation.js.map +1 -0
  305. package/dist/core/permission-rules.d.ts +102 -0
  306. package/dist/core/permission-rules.d.ts.map +1 -0
  307. package/dist/core/permission-rules.js +357 -0
  308. package/dist/core/permission-rules.js.map +1 -0
  309. package/dist/core/present-plan-tool.d.ts +28 -0
  310. package/dist/core/present-plan-tool.d.ts.map +1 -0
  311. package/dist/core/present-plan-tool.js +119 -0
  312. package/dist/core/present-plan-tool.js.map +1 -0
  313. package/dist/core/pricing.d.ts +48 -0
  314. package/dist/core/pricing.d.ts.map +1 -0
  315. package/dist/core/pricing.js +46 -0
  316. package/dist/core/pricing.js.map +1 -0
  317. package/dist/core/property-harness.d.ts +126 -0
  318. package/dist/core/property-harness.d.ts.map +1 -0
  319. package/dist/core/property-harness.js +192 -0
  320. package/dist/core/property-harness.js.map +1 -0
  321. package/dist/core/push-queue.d.ts +10 -0
  322. package/dist/core/push-queue.d.ts.map +1 -0
  323. package/dist/core/push-queue.js +42 -0
  324. package/dist/core/push-queue.js.map +1 -0
  325. package/dist/core/remote-env.d.ts +432 -0
  326. package/dist/core/remote-env.d.ts.map +1 -0
  327. package/dist/core/remote-env.js +77 -0
  328. package/dist/core/remote-env.js.map +1 -0
  329. package/dist/core/roles.d.ts +74 -0
  330. package/dist/core/roles.d.ts.map +1 -0
  331. package/dist/core/roles.js +272 -0
  332. package/dist/core/roles.js.map +1 -0
  333. package/dist/core/runner/active-skill-scope.d.ts +64 -0
  334. package/dist/core/runner/active-skill-scope.d.ts.map +1 -0
  335. package/dist/core/runner/active-skill-scope.js +197 -0
  336. package/dist/core/runner/active-skill-scope.js.map +1 -0
  337. package/dist/core/runner/assemble-result.d.ts +191 -0
  338. package/dist/core/runner/assemble-result.d.ts.map +1 -0
  339. package/dist/core/runner/assemble-result.js +250 -0
  340. package/dist/core/runner/assemble-result.js.map +1 -0
  341. package/dist/core/runner/call-cap.d.ts +130 -0
  342. package/dist/core/runner/call-cap.d.ts.map +1 -0
  343. package/dist/core/runner/call-cap.js +151 -0
  344. package/dist/core/runner/call-cap.js.map +1 -0
  345. package/dist/core/runner/grounding-signal.d.ts +12 -0
  346. package/dist/core/runner/grounding-signal.d.ts.map +1 -0
  347. package/dist/core/runner/grounding-signal.js +94 -0
  348. package/dist/core/runner/grounding-signal.js.map +1 -0
  349. package/dist/core/runner/image.d.ts +23 -0
  350. package/dist/core/runner/image.d.ts.map +1 -0
  351. package/dist/core/runner/image.js +151 -0
  352. package/dist/core/runner/image.js.map +1 -0
  353. package/dist/core/runner/memory-consolidation.d.ts +112 -0
  354. package/dist/core/runner/memory-consolidation.d.ts.map +1 -0
  355. package/dist/core/runner/memory-consolidation.js +372 -0
  356. package/dist/core/runner/memory-consolidation.js.map +1 -0
  357. package/dist/core/runner/prepare-task.d.ts +583 -0
  358. package/dist/core/runner/prepare-task.d.ts.map +1 -0
  359. package/dist/core/runner/prepare-task.js +3612 -0
  360. package/dist/core/runner/prepare-task.js.map +1 -0
  361. package/dist/core/runner/prompt-suggestions.d.ts +33 -0
  362. package/dist/core/runner/prompt-suggestions.d.ts.map +1 -0
  363. package/dist/core/runner/prompt-suggestions.js +116 -0
  364. package/dist/core/runner/prompt-suggestions.js.map +1 -0
  365. package/dist/core/runner/runtask.d.ts +274 -0
  366. package/dist/core/runner/runtask.d.ts.map +1 -0
  367. package/dist/core/runner/runtask.js +4606 -0
  368. package/dist/core/runner/runtask.js.map +1 -0
  369. package/dist/core/runner/session-rule-policy.d.ts +28 -0
  370. package/dist/core/runner/session-rule-policy.d.ts.map +1 -0
  371. package/dist/core/runner/session-rule-policy.js +110 -0
  372. package/dist/core/runner/session-rule-policy.js.map +1 -0
  373. package/dist/core/runner/strict-output-schema.d.ts +36 -0
  374. package/dist/core/runner/strict-output-schema.d.ts.map +1 -0
  375. package/dist/core/runner/strict-output-schema.js +365 -0
  376. package/dist/core/runner/strict-output-schema.js.map +1 -0
  377. package/dist/core/runner/synthetic-tools.d.ts +72 -0
  378. package/dist/core/runner/synthetic-tools.d.ts.map +1 -0
  379. package/dist/core/runner/synthetic-tools.js +203 -0
  380. package/dist/core/runner/synthetic-tools.js.map +1 -0
  381. package/dist/core/runner/tool-disclosure.d.ts +117 -0
  382. package/dist/core/runner/tool-disclosure.d.ts.map +1 -0
  383. package/dist/core/runner/tool-disclosure.js +0 -0
  384. package/dist/core/runner/tool-disclosure.js.map +1 -0
  385. package/dist/core/runner/turn-attachments.d.ts +381 -0
  386. package/dist/core/runner/turn-attachments.d.ts.map +1 -0
  387. package/dist/core/runner/turn-attachments.js +596 -0
  388. package/dist/core/runner/turn-attachments.js.map +1 -0
  389. package/dist/core/runner/usage-accounting.d.ts +35 -0
  390. package/dist/core/runner/usage-accounting.d.ts.map +1 -0
  391. package/dist/core/runner/usage-accounting.js +45 -0
  392. package/dist/core/runner/usage-accounting.js.map +1 -0
  393. package/dist/core/runtime.d.ts +9 -0
  394. package/dist/core/runtime.d.ts.map +1 -0
  395. package/dist/core/runtime.js +17 -0
  396. package/dist/core/runtime.js.map +1 -0
  397. package/dist/core/safety-axis-vocab.d.ts +33 -0
  398. package/dist/core/safety-axis-vocab.d.ts.map +1 -0
  399. package/dist/core/safety-axis-vocab.js +35 -0
  400. package/dist/core/safety-axis-vocab.js.map +1 -0
  401. package/dist/core/safety-merge-corpus.d.ts +48 -0
  402. package/dist/core/safety-merge-corpus.d.ts.map +1 -0
  403. package/dist/core/safety-merge-corpus.js +203 -0
  404. package/dist/core/safety-merge-corpus.js.map +1 -0
  405. package/dist/core/scheduler.d.ts +126 -0
  406. package/dist/core/scheduler.d.ts.map +1 -0
  407. package/dist/core/scheduler.js +54 -0
  408. package/dist/core/scheduler.js.map +1 -0
  409. package/dist/core/secret-env.d.ts +23 -0
  410. package/dist/core/secret-env.d.ts.map +1 -0
  411. package/dist/core/secret-env.js +35 -0
  412. package/dist/core/secret-env.js.map +1 -0
  413. package/dist/core/select-model.d.ts +26 -0
  414. package/dist/core/select-model.d.ts.map +1 -0
  415. package/dist/core/select-model.js +58 -0
  416. package/dist/core/select-model.js.map +1 -0
  417. package/dist/core/sensitive-path-policy.d.ts +24 -0
  418. package/dist/core/sensitive-path-policy.d.ts.map +1 -0
  419. package/dist/core/sensitive-path-policy.js +96 -0
  420. package/dist/core/sensitive-path-policy.js.map +1 -0
  421. package/dist/core/session-policy-store.d.ts +102 -0
  422. package/dist/core/session-policy-store.d.ts.map +1 -0
  423. package/dist/core/session-policy-store.js +177 -0
  424. package/dist/core/session-policy-store.js.map +1 -0
  425. package/dist/core/session-reconcile.d.ts +63 -0
  426. package/dist/core/session-reconcile.d.ts.map +1 -0
  427. package/dist/core/session-reconcile.js +71 -0
  428. package/dist/core/session-reconcile.js.map +1 -0
  429. package/dist/core/session-store.d.ts +99 -0
  430. package/dist/core/session-store.d.ts.map +1 -0
  431. package/dist/core/session-store.js +298 -0
  432. package/dist/core/session-store.js.map +1 -0
  433. package/dist/core/session.d.ts +144 -0
  434. package/dist/core/session.d.ts.map +1 -0
  435. package/dist/core/session.js +56 -0
  436. package/dist/core/session.js.map +1 -0
  437. package/dist/core/spec-contract.d.ts +147 -0
  438. package/dist/core/spec-contract.d.ts.map +1 -0
  439. package/dist/core/spec-contract.js +340 -0
  440. package/dist/core/spec-contract.js.map +1 -0
  441. package/dist/core/strategy-store.d.ts +50 -0
  442. package/dist/core/strategy-store.d.ts.map +1 -0
  443. package/dist/core/strategy-store.js +100 -0
  444. package/dist/core/strategy-store.js.map +1 -0
  445. package/dist/core/stub-env.d.ts +35 -0
  446. package/dist/core/stub-env.d.ts.map +1 -0
  447. package/dist/core/stub-env.js +69 -0
  448. package/dist/core/stub-env.js.map +1 -0
  449. package/dist/core/task-notification.d.ts +115 -0
  450. package/dist/core/task-notification.d.ts.map +1 -0
  451. package/dist/core/task-notification.js +247 -0
  452. package/dist/core/task-notification.js.map +1 -0
  453. package/dist/core/task-outcome.d.ts +80 -0
  454. package/dist/core/task-outcome.d.ts.map +1 -0
  455. package/dist/core/task-outcome.js +40 -0
  456. package/dist/core/task-outcome.js.map +1 -0
  457. package/dist/core/task-registry.d.ts +349 -0
  458. package/dist/core/task-registry.d.ts.map +1 -0
  459. package/dist/core/task-registry.js +1751 -0
  460. package/dist/core/task-registry.js.map +1 -0
  461. package/dist/core/tighten-task-spec.d.ts +27 -0
  462. package/dist/core/tighten-task-spec.d.ts.map +1 -0
  463. package/dist/core/tighten-task-spec.js +95 -0
  464. package/dist/core/tighten-task-spec.js.map +1 -0
  465. package/dist/core/tool-detach.d.ts +31 -0
  466. package/dist/core/tool-detach.d.ts.map +1 -0
  467. package/dist/core/tool-detach.js +62 -0
  468. package/dist/core/tool-detach.js.map +1 -0
  469. package/dist/core/tool-errors.d.ts +72 -0
  470. package/dist/core/tool-errors.d.ts.map +1 -0
  471. package/dist/core/tool-errors.js +194 -0
  472. package/dist/core/tool-errors.js.map +1 -0
  473. package/dist/core/tool-name-aliases.d.ts +5 -0
  474. package/dist/core/tool-name-aliases.d.ts.map +1 -0
  475. package/dist/core/tool-name-aliases.js +130 -0
  476. package/dist/core/tool-name-aliases.js.map +1 -0
  477. package/dist/core/tool-policy.d.ts +295 -0
  478. package/dist/core/tool-policy.d.ts.map +1 -0
  479. package/dist/core/tool-policy.js +567 -0
  480. package/dist/core/tool-policy.js.map +1 -0
  481. package/dist/core/tool-result-budget.d.ts +44 -0
  482. package/dist/core/tool-result-budget.d.ts.map +1 -0
  483. package/dist/core/tool-result-budget.js +140 -0
  484. package/dist/core/tool-result-budget.js.map +1 -0
  485. package/dist/core/tool-result-store.d.ts +136 -0
  486. package/dist/core/tool-result-store.d.ts.map +1 -0
  487. package/dist/core/tool-result-store.js +219 -0
  488. package/dist/core/tool-result-store.js.map +1 -0
  489. package/dist/core/tools.d.ts +14 -0
  490. package/dist/core/tools.d.ts.map +1 -0
  491. package/dist/core/tools.js +98 -0
  492. package/dist/core/tools.js.map +1 -0
  493. package/dist/core/trace.d.ts +340 -0
  494. package/dist/core/trace.d.ts.map +1 -0
  495. package/dist/core/trace.js +12 -0
  496. package/dist/core/trace.js.map +1 -0
  497. package/dist/core/types.d.ts +2828 -0
  498. package/dist/core/types.d.ts.map +1 -0
  499. package/dist/core/types.js +2 -0
  500. package/dist/core/types.js.map +1 -0
  501. package/dist/core/untrusted-egress.d.ts +32 -0
  502. package/dist/core/untrusted-egress.d.ts.map +1 -0
  503. package/dist/core/untrusted-egress.js +49 -0
  504. package/dist/core/untrusted-egress.js.map +1 -0
  505. package/dist/core/untrusted-text.d.ts +64 -0
  506. package/dist/core/untrusted-text.d.ts.map +1 -0
  507. package/dist/core/untrusted-text.js +119 -0
  508. package/dist/core/untrusted-text.js.map +1 -0
  509. package/dist/core/warm-resume.d.ts +23 -0
  510. package/dist/core/warm-resume.d.ts.map +1 -0
  511. package/dist/core/warm-resume.js +28 -0
  512. package/dist/core/warm-resume.js.map +1 -0
  513. package/dist/core/with-retry.d.ts +43 -0
  514. package/dist/core/with-retry.d.ts.map +1 -0
  515. package/dist/core/with-retry.js +59 -0
  516. package/dist/core/with-retry.js.map +1 -0
  517. package/dist/core/workflow-journal-store.d.ts +44 -0
  518. package/dist/core/workflow-journal-store.d.ts.map +1 -0
  519. package/dist/core/workflow-journal-store.js +47 -0
  520. package/dist/core/workflow-journal-store.js.map +1 -0
  521. package/dist/core/workflow-run-store-contract.d.ts +31 -0
  522. package/dist/core/workflow-run-store-contract.d.ts.map +1 -0
  523. package/dist/core/workflow-run-store-contract.js +191 -0
  524. package/dist/core/workflow-run-store-contract.js.map +1 -0
  525. package/dist/core/workflow-run-store.d.ts +149 -0
  526. package/dist/core/workflow-run-store.d.ts.map +1 -0
  527. package/dist/core/workflow-run-store.js +110 -0
  528. package/dist/core/workflow-run-store.js.map +1 -0
  529. package/dist/engine/compaction/compaction.d.ts +139 -0
  530. package/dist/engine/compaction/compaction.d.ts.map +1 -0
  531. package/dist/engine/compaction/compaction.js +1030 -0
  532. package/dist/engine/compaction/compaction.js.map +1 -0
  533. package/dist/engine/compaction/utils.d.ts +45 -0
  534. package/dist/engine/compaction/utils.d.ts.map +1 -0
  535. package/dist/engine/compaction/utils.js +203 -0
  536. package/dist/engine/compaction/utils.js.map +1 -0
  537. package/dist/engine/execution-env/kill-tree.d.ts +20 -0
  538. package/dist/engine/execution-env/kill-tree.d.ts.map +1 -0
  539. package/dist/engine/execution-env/kill-tree.js +183 -0
  540. package/dist/engine/execution-env/kill-tree.js.map +1 -0
  541. package/dist/engine/execution-env/node-execution-env.d.ts +133 -0
  542. package/dist/engine/execution-env/node-execution-env.d.ts.map +1 -0
  543. package/dist/engine/execution-env/node-execution-env.js +1031 -0
  544. package/dist/engine/execution-env/node-execution-env.js.map +1 -0
  545. package/dist/engine/harness/agent-harness.d.ts +174 -0
  546. package/dist/engine/harness/agent-harness.d.ts.map +1 -0
  547. package/dist/engine/harness/agent-harness.js +1053 -0
  548. package/dist/engine/harness/agent-harness.js.map +1 -0
  549. package/dist/engine/harness/messages.d.ts +17 -0
  550. package/dist/engine/harness/messages.d.ts.map +1 -0
  551. package/dist/engine/harness/messages.js +122 -0
  552. package/dist/engine/harness/messages.js.map +1 -0
  553. package/dist/engine/harness/types.d.ts +713 -0
  554. package/dist/engine/harness/types.d.ts.map +1 -0
  555. package/dist/engine/harness/types.js +100 -0
  556. package/dist/engine/harness/types.js.map +1 -0
  557. package/dist/engine/llm/diagnostics.d.ts +23 -0
  558. package/dist/engine/llm/diagnostics.d.ts.map +1 -0
  559. package/dist/engine/llm/diagnostics.js +32 -0
  560. package/dist/engine/llm/diagnostics.js.map +1 -0
  561. package/dist/engine/llm/event-stream.d.ts +25 -0
  562. package/dist/engine/llm/event-stream.d.ts.map +1 -0
  563. package/dist/engine/llm/event-stream.js +103 -0
  564. package/dist/engine/llm/event-stream.js.map +1 -0
  565. package/dist/engine/llm/index.d.ts +12 -0
  566. package/dist/engine/llm/index.d.ts.map +1 -0
  567. package/dist/engine/llm/index.js +12 -0
  568. package/dist/engine/llm/index.js.map +1 -0
  569. package/dist/engine/llm/types.d.ts +753 -0
  570. package/dist/engine/llm/types.d.ts.map +1 -0
  571. package/dist/engine/llm/types.js +2 -0
  572. package/dist/engine/llm/types.js.map +1 -0
  573. package/dist/engine/llm/validation.d.ts +8 -0
  574. package/dist/engine/llm/validation.d.ts.map +1 -0
  575. package/dist/engine/llm/validation.js +318 -0
  576. package/dist/engine/llm/validation.js.map +1 -0
  577. package/dist/engine/loop/agent-loop.d.ts +74 -0
  578. package/dist/engine/loop/agent-loop.d.ts.map +1 -0
  579. package/dist/engine/loop/agent-loop.js +1490 -0
  580. package/dist/engine/loop/agent-loop.js.map +1 -0
  581. package/dist/engine/loop/runtime-deps.d.ts +17 -0
  582. package/dist/engine/loop/runtime-deps.d.ts.map +1 -0
  583. package/dist/engine/loop/runtime-deps.js +21 -0
  584. package/dist/engine/loop/runtime-deps.js.map +1 -0
  585. package/dist/engine/loop/types.d.ts +609 -0
  586. package/dist/engine/loop/types.d.ts.map +1 -0
  587. package/dist/engine/loop/types.js +2 -0
  588. package/dist/engine/loop/types.js.map +1 -0
  589. package/dist/engine/lsp/frame-decoder.d.ts +16 -0
  590. package/dist/engine/lsp/frame-decoder.d.ts.map +1 -0
  591. package/dist/engine/lsp/frame-decoder.js +53 -0
  592. package/dist/engine/lsp/frame-decoder.js.map +1 -0
  593. package/dist/engine/lsp/node-lsp-manager.d.ts +105 -0
  594. package/dist/engine/lsp/node-lsp-manager.d.ts.map +1 -0
  595. package/dist/engine/lsp/node-lsp-manager.js +343 -0
  596. package/dist/engine/lsp/node-lsp-manager.js.map +1 -0
  597. package/dist/engine/lsp/stdio-lsp-transport.d.ts +37 -0
  598. package/dist/engine/lsp/stdio-lsp-transport.d.ts.map +1 -0
  599. package/dist/engine/lsp/stdio-lsp-transport.js +185 -0
  600. package/dist/engine/lsp/stdio-lsp-transport.js.map +1 -0
  601. package/dist/engine/session/import-validate.d.ts +44 -0
  602. package/dist/engine/session/import-validate.d.ts.map +1 -0
  603. package/dist/engine/session/import-validate.js +92 -0
  604. package/dist/engine/session/import-validate.js.map +1 -0
  605. package/dist/engine/session/memory-repo.d.ts +25 -0
  606. package/dist/engine/session/memory-repo.d.ts.map +1 -0
  607. package/dist/engine/session/memory-repo.js +59 -0
  608. package/dist/engine/session/memory-repo.js.map +1 -0
  609. package/dist/engine/session/memory-storage.d.ts +14 -0
  610. package/dist/engine/session/memory-storage.d.ts.map +1 -0
  611. package/dist/engine/session/memory-storage.js +17 -0
  612. package/dist/engine/session/memory-storage.js.map +1 -0
  613. package/dist/engine/session/repo-utils.d.ts +11 -0
  614. package/dist/engine/session/repo-utils.d.ts.map +1 -0
  615. package/dist/engine/session/repo-utils.js +40 -0
  616. package/dist/engine/session/repo-utils.js.map +1 -0
  617. package/dist/engine/session/session.d.ts +34 -0
  618. package/dist/engine/session/session.d.ts.map +1 -0
  619. package/dist/engine/session/session.js +227 -0
  620. package/dist/engine/session/session.js.map +1 -0
  621. package/dist/engine/session/storage-base.d.ts +38 -0
  622. package/dist/engine/session/storage-base.d.ts.map +1 -0
  623. package/dist/engine/session/storage-base.js +157 -0
  624. package/dist/engine/session/storage-base.js.map +1 -0
  625. package/dist/engine/session/timestamps.d.ts +3 -0
  626. package/dist/engine/session/timestamps.d.ts.map +1 -0
  627. package/dist/engine/session/timestamps.js +15 -0
  628. package/dist/engine/session/timestamps.js.map +1 -0
  629. package/dist/engine/session/uuid.d.ts +2 -0
  630. package/dist/engine/session/uuid.d.ts.map +1 -0
  631. package/dist/engine/session/uuid.js +50 -0
  632. package/dist/engine/session/uuid.js.map +1 -0
  633. package/dist/index.d.ts +160 -0
  634. package/dist/index.d.ts.map +1 -0
  635. package/dist/index.js +374 -0
  636. package/dist/index.js.map +1 -0
  637. package/dist/internal/harness.d.ts +26 -0
  638. package/dist/internal/harness.d.ts.map +1 -0
  639. package/dist/internal/harness.js +24 -0
  640. package/dist/internal/harness.js.map +1 -0
  641. package/dist/internal/llm.d.ts +9 -0
  642. package/dist/internal/llm.d.ts.map +1 -0
  643. package/dist/internal/llm.js +8 -0
  644. package/dist/internal/llm.js.map +1 -0
  645. package/dist/orchestration/builtin-workflows.d.ts +44 -0
  646. package/dist/orchestration/builtin-workflows.d.ts.map +1 -0
  647. package/dist/orchestration/builtin-workflows.js +165 -0
  648. package/dist/orchestration/builtin-workflows.js.map +1 -0
  649. package/dist/orchestration/dev-vm-script-runner.d.ts +24 -0
  650. package/dist/orchestration/dev-vm-script-runner.d.ts.map +1 -0
  651. package/dist/orchestration/dev-vm-script-runner.js +106 -0
  652. package/dist/orchestration/dev-vm-script-runner.js.map +1 -0
  653. package/dist/orchestration/goal.d.ts +97 -0
  654. package/dist/orchestration/goal.d.ts.map +1 -0
  655. package/dist/orchestration/goal.js +248 -0
  656. package/dist/orchestration/goal.js.map +1 -0
  657. package/dist/orchestration/run-spec.d.ts +63 -0
  658. package/dist/orchestration/run-spec.d.ts.map +1 -0
  659. package/dist/orchestration/run-spec.js +274 -0
  660. package/dist/orchestration/run-spec.js.map +1 -0
  661. package/dist/orchestration/run-workflow-tool.d.ts +187 -0
  662. package/dist/orchestration/run-workflow-tool.d.ts.map +1 -0
  663. package/dist/orchestration/run-workflow-tool.js +612 -0
  664. package/dist/orchestration/run-workflow-tool.js.map +1 -0
  665. package/dist/orchestration/workflow-governance.d.ts +70 -0
  666. package/dist/orchestration/workflow-governance.d.ts.map +1 -0
  667. package/dist/orchestration/workflow-governance.js +176 -0
  668. package/dist/orchestration/workflow-governance.js.map +1 -0
  669. package/dist/orchestration/workflow-meta.d.ts +41 -0
  670. package/dist/orchestration/workflow-meta.d.ts.map +1 -0
  671. package/dist/orchestration/workflow-meta.js +426 -0
  672. package/dist/orchestration/workflow-meta.js.map +1 -0
  673. package/dist/orchestration/workflow-observe.d.ts +77 -0
  674. package/dist/orchestration/workflow-observe.d.ts.map +1 -0
  675. package/dist/orchestration/workflow-observe.js +177 -0
  676. package/dist/orchestration/workflow-observe.js.map +1 -0
  677. package/dist/orchestration/workflow-primitives.d.ts +31 -0
  678. package/dist/orchestration/workflow-primitives.d.ts.map +1 -0
  679. package/dist/orchestration/workflow-primitives.js +104 -0
  680. package/dist/orchestration/workflow-primitives.js.map +1 -0
  681. package/dist/orchestration/workflow-sandbox-conformance.d.ts +34 -0
  682. package/dist/orchestration/workflow-sandbox-conformance.d.ts.map +1 -0
  683. package/dist/orchestration/workflow-sandbox-conformance.js +301 -0
  684. package/dist/orchestration/workflow-sandbox-conformance.js.map +1 -0
  685. package/dist/orchestration/workflow-script-runner.d.ts +127 -0
  686. package/dist/orchestration/workflow-script-runner.d.ts.map +1 -0
  687. package/dist/orchestration/workflow-script-runner.js +48 -0
  688. package/dist/orchestration/workflow-script-runner.js.map +1 -0
  689. package/dist/orchestration/workflow-script-store.d.ts +99 -0
  690. package/dist/orchestration/workflow-script-store.d.ts.map +1 -0
  691. package/dist/orchestration/workflow-script-store.js +133 -0
  692. package/dist/orchestration/workflow-script-store.js.map +1 -0
  693. package/dist/orchestration/workflow-size-guideline.d.ts +50 -0
  694. package/dist/orchestration/workflow-size-guideline.d.ts.map +1 -0
  695. package/dist/orchestration/workflow-size-guideline.js +78 -0
  696. package/dist/orchestration/workflow-size-guideline.js.map +1 -0
  697. package/dist/orchestration/workflow.d.ts +624 -0
  698. package/dist/orchestration/workflow.d.ts.map +1 -0
  699. package/dist/orchestration/workflow.js +1596 -0
  700. package/dist/orchestration/workflow.js.map +1 -0
  701. package/dist/prompts/default.d.ts +474 -0
  702. package/dist/prompts/default.d.ts.map +1 -0
  703. package/dist/prompts/default.js +676 -0
  704. package/dist/prompts/default.js.map +1 -0
  705. package/dist/prompts/supervisor.d.ts +60 -0
  706. package/dist/prompts/supervisor.d.ts.map +1 -0
  707. package/dist/prompts/supervisor.js +162 -0
  708. package/dist/prompts/supervisor.js.map +1 -0
  709. package/dist/scenarios/env.d.ts +41 -0
  710. package/dist/scenarios/env.d.ts.map +1 -0
  711. package/dist/scenarios/env.js +65 -0
  712. package/dist/scenarios/env.js.map +1 -0
  713. package/dist/scenarios/full-body.d.ts +47 -0
  714. package/dist/scenarios/full-body.d.ts.map +1 -0
  715. package/dist/scenarios/full-body.js +36 -0
  716. package/dist/scenarios/full-body.js.map +1 -0
  717. package/dist/scenarios/scenario-registry.d.ts +107 -0
  718. package/dist/scenarios/scenario-registry.d.ts.map +1 -0
  719. package/dist/scenarios/scenario-registry.js +192 -0
  720. package/dist/scenarios/scenario-registry.js.map +1 -0
  721. package/dist/scenarios/teacher-quickstart.d.ts +41 -0
  722. package/dist/scenarios/teacher-quickstart.d.ts.map +1 -0
  723. package/dist/scenarios/teacher-quickstart.js +32 -0
  724. package/dist/scenarios/teacher-quickstart.js.map +1 -0
  725. package/dist/server/http.d.ts +36 -0
  726. package/dist/server/http.d.ts.map +1 -0
  727. package/dist/server/http.js +144 -0
  728. package/dist/server/http.js.map +1 -0
  729. package/dist/stores/file/checkpoint-store.d.ts +62 -0
  730. package/dist/stores/file/checkpoint-store.d.ts.map +1 -0
  731. package/dist/stores/file/checkpoint-store.js +250 -0
  732. package/dist/stores/file/checkpoint-store.js.map +1 -0
  733. package/dist/stores/file/file-snapshot-store.d.ts +43 -0
  734. package/dist/stores/file/file-snapshot-store.d.ts.map +1 -0
  735. package/dist/stores/file/file-snapshot-store.js +374 -0
  736. package/dist/stores/file/file-snapshot-store.js.map +1 -0
  737. package/dist/stores/file/fs-atomic.d.ts +95 -0
  738. package/dist/stores/file/fs-atomic.d.ts.map +1 -0
  739. package/dist/stores/file/fs-atomic.js +415 -0
  740. package/dist/stores/file/fs-atomic.js.map +1 -0
  741. package/dist/stores/file/index.d.ts +98 -0
  742. package/dist/stores/file/index.d.ts.map +1 -0
  743. package/dist/stores/file/index.js +109 -0
  744. package/dist/stores/file/index.js.map +1 -0
  745. package/dist/stores/file/memory-store.d.ts +95 -0
  746. package/dist/stores/file/memory-store.d.ts.map +1 -0
  747. package/dist/stores/file/memory-store.js +393 -0
  748. package/dist/stores/file/memory-store.js.map +1 -0
  749. package/dist/stores/file/session-policy-store.d.ts +24 -0
  750. package/dist/stores/file/session-policy-store.d.ts.map +1 -0
  751. package/dist/stores/file/session-policy-store.js +123 -0
  752. package/dist/stores/file/session-policy-store.js.map +1 -0
  753. package/dist/stores/file/session-store.d.ts +34 -0
  754. package/dist/stores/file/session-store.d.ts.map +1 -0
  755. package/dist/stores/file/session-store.js +175 -0
  756. package/dist/stores/file/session-store.js.map +1 -0
  757. package/dist/stores/file/tool-result-store.d.ts +23 -0
  758. package/dist/stores/file/tool-result-store.d.ts.map +1 -0
  759. package/dist/stores/file/tool-result-store.js +61 -0
  760. package/dist/stores/file/tool-result-store.js.map +1 -0
  761. package/dist/stores/file/workflow-journal-store.d.ts +36 -0
  762. package/dist/stores/file/workflow-journal-store.d.ts.map +1 -0
  763. package/dist/stores/file/workflow-journal-store.js +157 -0
  764. package/dist/stores/file/workflow-journal-store.js.map +1 -0
  765. package/dist/stores/file/workflow-run-store.d.ts +58 -0
  766. package/dist/stores/file/workflow-run-store.d.ts.map +1 -0
  767. package/dist/stores/file/workflow-run-store.js +178 -0
  768. package/dist/stores/file/workflow-run-store.js.map +1 -0
  769. package/dist/stores/pg.d.ts +210 -0
  770. package/dist/stores/pg.d.ts.map +1 -0
  771. package/dist/stores/pg.js +652 -0
  772. package/dist/stores/pg.js.map +1 -0
  773. package/dist/tools/fs/encoding.d.ts +51 -0
  774. package/dist/tools/fs/encoding.d.ts.map +1 -0
  775. package/dist/tools/fs/encoding.js +74 -0
  776. package/dist/tools/fs/encoding.js.map +1 -0
  777. package/dist/tools/fs/gh-rate-limit.d.ts +19 -0
  778. package/dist/tools/fs/gh-rate-limit.d.ts.map +1 -0
  779. package/dist/tools/fs/gh-rate-limit.js +35 -0
  780. package/dist/tools/fs/gh-rate-limit.js.map +1 -0
  781. package/dist/tools/fs/index.d.ts +246 -0
  782. package/dist/tools/fs/index.d.ts.map +1 -0
  783. package/dist/tools/fs/index.js +2130 -0
  784. package/dist/tools/fs/index.js.map +1 -0
  785. package/dist/tools/fs/pdf.d.ts +106 -0
  786. package/dist/tools/fs/pdf.d.ts.map +1 -0
  787. package/dist/tools/fs/pdf.js +178 -0
  788. package/dist/tools/fs/pdf.js.map +1 -0
  789. package/dist/tools/fs/repo-map.d.ts +15 -0
  790. package/dist/tools/fs/repo-map.d.ts.map +1 -0
  791. package/dist/tools/fs/repo-map.js +251 -0
  792. package/dist/tools/fs/repo-map.js.map +1 -0
  793. package/dist/tools/fs/safety.d.ts +168 -0
  794. package/dist/tools/fs/safety.d.ts.map +1 -0
  795. package/dist/tools/fs/safety.js +479 -0
  796. package/dist/tools/fs/safety.js.map +1 -0
  797. package/dist/tools/fs/search.d.ts +118 -0
  798. package/dist/tools/fs/search.d.ts.map +1 -0
  799. package/dist/tools/fs/search.js +650 -0
  800. package/dist/tools/fs/search.js.map +1 -0
  801. package/dist/tools/gitea-issue.d.ts +39 -0
  802. package/dist/tools/gitea-issue.d.ts.map +1 -0
  803. package/dist/tools/gitea-issue.js +91 -0
  804. package/dist/tools/gitea-issue.js.map +1 -0
  805. package/dist/tools/monitor.d.ts +64 -0
  806. package/dist/tools/monitor.d.ts.map +1 -0
  807. package/dist/tools/monitor.js +135 -0
  808. package/dist/tools/monitor.js.map +1 -0
  809. package/dist/tools/scheduler-tools.d.ts +48 -0
  810. package/dist/tools/scheduler-tools.d.ts.map +1 -0
  811. package/dist/tools/scheduler-tools.js +449 -0
  812. package/dist/tools/scheduler-tools.js.map +1 -0
  813. package/dist/tools/sql-adapters.d.ts +32 -0
  814. package/dist/tools/sql-adapters.d.ts.map +1 -0
  815. package/dist/tools/sql-adapters.js +31 -0
  816. package/dist/tools/sql-adapters.js.map +1 -0
  817. package/dist/tools/sql.d.ts +36 -0
  818. package/dist/tools/sql.d.ts.map +1 -0
  819. package/dist/tools/sql.js +131 -0
  820. package/dist/tools/sql.js.map +1 -0
  821. package/dist/tools/task-list.d.ts +26 -0
  822. package/dist/tools/task-list.d.ts.map +1 -0
  823. package/dist/tools/task-list.js +352 -0
  824. package/dist/tools/task-list.js.map +1 -0
  825. package/dist/tools/todo.d.ts +11 -0
  826. package/dist/tools/todo.d.ts.map +1 -0
  827. package/dist/tools/todo.js +126 -0
  828. package/dist/tools/todo.js.map +1 -0
  829. package/dist/tools/web.d.ts +59 -0
  830. package/dist/tools/web.d.ts.map +1 -0
  831. package/dist/tools/web.js +607 -0
  832. package/dist/tools/web.js.map +1 -0
  833. package/dist/tools/worktree.d.ts +88 -0
  834. package/dist/tools/worktree.d.ts.map +1 -0
  835. package/dist/tools/worktree.js +434 -0
  836. package/dist/tools/worktree.js.map +1 -0
  837. package/docs/A1-ATTRIBUTION-ROUND1-2026-07-09.md +181 -0
  838. package/docs/AB-ORACLE-GATE-VERDICT-2026-07-10.md +100 -0
  839. package/docs/ANCHOR-GAP-INVENTORY-2026-07-09.md +143 -0
  840. package/docs/ARCHITECTURE.md +125 -0
  841. package/docs/BUGHUNT-2026-07-05-NIGHT.md +98 -0
  842. package/docs/BUILD.md +63 -0
  843. package/docs/CANCEL-ASYNC-ATTRIBUTION-2026-07-09.md +98 -0
  844. package/docs/CC-198-VS-201-DRIFT-2026-07-09.md +70 -0
  845. package/docs/CC-BASELINE-FAKE-ZERO-AUDIT-2026-07-09.md +51 -0
  846. package/docs/CC-DRIFT-198-206-AGENT-TYPES-2026-07-10.md +82 -0
  847. package/docs/CC-DRIFT-198-206-CHANGELOG-2026-07-10.md +82 -0
  848. package/docs/CC-DRIFT-198-206-REMINDERS-2026-07-10.md +96 -0
  849. package/docs/CC-DRIFT-198-206-ROADMAP-2026-07-10.md +110 -0
  850. package/docs/CC-DRIFT-198-206-TOOL-INVENTORY-2026-07-10.md +53 -0
  851. package/docs/CC-DRIFT-198-206-USAGE-CONSTANTS-2026-07-10.md +64 -0
  852. package/docs/CC-DRIFT-198-206-WORKFLOW-2026-07-10.md +83 -0
  853. package/docs/CC-PARITY-CHECKLIST.md +220 -0
  854. package/docs/CC-PARITY-DEEP-SWEEP-2026-07-07.md +149 -0
  855. package/docs/CC-SUBAGENT-PROMPT-STUDY-2026-07-09.md +219 -0
  856. package/docs/CC-TASK-REMINDER-CADENCE-STUDY-2026-07-09.md +396 -0
  857. package/docs/CC-TOOL-PARITY-SWEEP-2026-07.md +56 -0
  858. package/docs/CC-TOOL-PROMPT-DEEP-DIFF-2026-07-08.md +274 -0
  859. package/docs/CC-TOOLSURFACE-DEEP-DIVE-2026-07-07.md +197 -0
  860. package/docs/CC206-OBSERVER-ANCHORS-2026-07-11.md +463 -0
  861. package/docs/CC207-CORE-SWEEP-BACKLOG-2026-07-12.md +155 -0
  862. package/docs/CENTER-CONTROL-PLANE-SEAM.md +86 -0
  863. package/docs/CLEANUP-CONTRACT-ANCHOR-2026-07-09.md +83 -0
  864. package/docs/COLD-START-RSI-2026-07-09.md +72 -0
  865. package/docs/COMPACTION-LIVE-AUDIT-2026-07-09.md +114 -0
  866. package/docs/CONTEXT-lifecycle-extension-points-and-stop-attribution.md +71 -0
  867. package/docs/COREWARS-POLYGLOT-TRIAGE-2026-07-09.md +85 -0
  868. package/docs/DEADTARGET-OVERFULL-HBOX-2026-07-10.md +92 -0
  869. package/docs/DEADTARGET-PATH-TRACING-REVERSE-2026-07-10.md +87 -0
  870. package/docs/DEADTARGET-WINNING-AVG-COREWARS-2026-07-10.md +96 -0
  871. package/docs/DEEPSEEK-API-LIMITS-PROBE-2026-07-09.md +118 -0
  872. package/docs/DESIGN-140-MOCK-VERIFY-2026-07-11.md +79 -0
  873. package/docs/DESIGN-140-VERIFICATION-2026-07-11.md +43 -0
  874. package/docs/DESIGN-DRAFT-workflow-collab-2026-07-11.md +56 -0
  875. package/docs/DESIGN-ORACLE-GROUNDING-GATE-2026-07-10.md +167 -0
  876. package/docs/DESIGN-TFRAG-RECONCILE-SCAFFOLD-2026-07-09.md +102 -0
  877. package/docs/EXP-PA2-PE-DESIGN-2026-07-11.md +220 -0
  878. package/docs/EXT-DOGFOOD-2026-07-12.md +50 -0
  879. package/docs/FINAL-VERIFY-SURFACE-AUDIT-2026-07-09.md +44 -0
  880. package/docs/FRAG-RECON-INVESTIGATION-2026-07-09.md +183 -0
  881. package/docs/HANDOFF.md +121 -0
  882. package/docs/KNOWN-ISSUES.md +96 -0
  883. package/docs/LEGW-WINDOW-TAX-2026-07-10.md +82 -0
  884. package/docs/LIVE-PROBE-BATCH-2026-07-11.md +207 -0
  885. package/docs/M2-CERT-ATTRIBUTION-2026-07-10.md +61 -0
  886. package/docs/M25-LEG-VARIANCE-ATTRIBUTION-2026-07-10.md +81 -0
  887. package/docs/MAILMAN-TIMEOUT-ATTRIBUTION-2026-07-10.md +88 -0
  888. package/docs/MEMORY-BACKEND-DIALECT-NOTES.md +69 -0
  889. package/docs/MTEB-ESCAPE-HATCH-ATTRIBUTION-2026-07-09.md +57 -0
  890. package/docs/MTEB-LEADERBOARD-ATTRIBUTION-2026-07-10.md +134 -0
  891. package/docs/ORACLE-GATE-NEGATIVE-SAMPLE-2026-07-11.md +28 -0
  892. package/docs/PARITY-CONTEXT-TRANSACTIONS-2026-07-10.md +67 -0
  893. package/docs/PARITY-PROGRESS-MATRIX-2026-07-10.md +37 -0
  894. package/docs/PARITY-SPOT-AGENT-TYPES-2026-07-10.md +70 -0
  895. package/docs/PARITY-SPOT-REMINDERS-2026-07-10.md +144 -0
  896. package/docs/PARITY-SPOT-TOOL-INVENTORY-2026-07-10.md +61 -0
  897. package/docs/PARITY-SPOT-USAGE-CONSTANTS-2026-07-10.md +95 -0
  898. package/docs/PARITY-SPOT-WORKFLOW-2026-07-10.md +93 -0
  899. package/docs/PASSWORD-RECOVERY-PANEL-VERDICT-2026-07-10.md +62 -0
  900. package/docs/R8-R9-FINALIZE-COORDINATION-2026-07-09.md +124 -0
  901. package/docs/REPL-CODE-MODE-EVALUATION-2026-07-10.md +187 -0
  902. package/docs/REPORT-1249-TARGETED.md +48 -0
  903. package/docs/RESEARCH-3P-MEMORY-SWAP-2026-07-12.md +273 -0
  904. package/docs/ROADMAP.md +111 -0
  905. package/docs/RSI-CLOUD-DEPLOY-2026-07-06.md +289 -0
  906. package/docs/RSI-PROCESS-AI-COLDSTART-2026-07-11.md +68 -0
  907. package/docs/S18-THOROUGHNESS-AUDIT-2026-07-09.md +113 -0
  908. package/docs/SERVICE-INTEGRATION-GUIDE.md +298 -0
  909. package/docs/SUBAGENT-STREAM-RESILIENCE-PARITY-2026-07-10.md +118 -0
  910. package/docs/SWEBENCH-PRO-RECON-2026-07-11.md +31 -0
  911. package/docs/TB-EFFICIENCY-TELEMETRY-2026-07-08.md +114 -0
  912. package/docs/TB-FAILURE-AUTOPSY-2026-07-05-RERUN.md +67 -0
  913. package/docs/TB-FAIRNESS-AUDIT-2026-07-08.md +141 -0
  914. package/docs/TB-FULL-1257-2026-07-08.md +77 -0
  915. package/docs/TB-LEG-GAP-ATTRIBUTION-1261-1263-2026-07-11.md +154 -0
  916. package/docs/TB-REGRESSION-DAEMON-KILL-2026-07-08.md +58 -0
  917. package/docs/TB-RSI-CROSSCHECK-2026-07-06.md +68 -0
  918. package/docs/TB-RSI-LEDGER.md +30 -0
  919. package/docs/TB-STABLE-SET-2026-07-08.md +127 -0
  920. package/docs/TB21-RECON-2026-07-11.md +28 -0
  921. package/docs/TEST-DESIGN-BATCH-1-2-3.md +97 -0
  922. package/docs/THIRD-PARTY-INTEGRATION.md +45 -0
  923. package/docs/TOKEN-ESTIMATE-CALIBRATION-LIVE-2026-07-09.md +102 -0
  924. package/docs/audit-2026-06-10-/347/254/254/344/272/214/350/275/256-/347/251/272/347/231/275/345/214/272/344/270/216/345/277/230/346/216/245/347/272/277.md +147 -0
  925. package/docs/audit-2026-06-10-/350/256/241/347/256/227bug/346/211/253/346/217/217.md +163 -0
  926. package/docs/audit-2026-06-11-/344/277/256/345/244/215/345/244/215/345/256/241/344/270/216/345/233/236/345/275/222/344/270/223/346/211/253.md +95 -0
  927. package/docs/audit-2026-06-12-design71-P1/346/275/234/344/274/217/351/235/242/350/243/201/345/206/263/344/270/216/345/220/236/351/224/231/345/256/241/350/256/241.md +45 -0
  928. package/docs/audit-2026-06-12-/345/205/254/345/274/200/346/227/213/351/222/256/346/264/273/346/200/247/344/270/216vendored/346/255/273/350/267/257.md +63 -0
  929. package/docs/audit-2026-06-15/ADDENDUM-second-pass.md +88 -0
  930. package/docs/audit-2026-06-15/ARCHITECTURE-AND-ROADMAP.md +187 -0
  931. package/docs/audit-2026-06-15/DOC-CORRECTIONS.md +105 -0
  932. package/docs/audit-2026-06-15/INDEX.md +49 -0
  933. package/docs/audit-2026-06-15/ORCHESTRATION-STATUS.md +98 -0
  934. package/docs/audit-2026-06-15/PRODUCTION-ISSUES.md +189 -0
  935. package/docs/audit-2026-06-15/REFERENCES-literature.md +139 -0
  936. package/docs/audit-2026-06-15/VENDOR-REFACTOR-PLAN.md +96 -0
  937. package/docs/cc-probe-198/README.md +72 -0
  938. package/docs/cc-probe-198/STABILITY-AUDIT.md +118 -0
  939. package/docs/cc-probe-198/live-schema-monitor-worktree-2026-07-09.json +56 -0
  940. package/docs/cc-probe-198/mount-variants.json +536 -0
  941. package/docs/cc-probe-198/plan-mode-run.json +1 -0
  942. package/docs/cc-probe-198/probe-bash-bg.json +224 -0
  943. package/docs/cc-probe-198/probe-edit-mismatch.json +120 -0
  944. package/docs/cc-probe-198/probe-read-missing.json +62 -0
  945. package/docs/cc-probe-198/probe-search-empty.json +127 -0
  946. package/docs/cc-probe-198/probe-task-family.json +227 -0
  947. package/docs/cc-probe-198/probes.status +6 -0
  948. package/docs/cc-probe-198/raw-capture-interactive.json +948 -0
  949. package/docs/cc-probe-198/raw-capture-print.json +787 -0
  950. package/docs/cc-probe-198/raw-capture2-interactive.json +948 -0
  951. package/docs/cc-probe-198/raw-capture2-print.json +787 -0
  952. package/docs/cc-probe-198/system-prompt.txt +135 -0
  953. package/docs/cc-probe-198/tools-array.json +962 -0
  954. package/docs/durability-boundary.md +63 -0
  955. package/docs/fix-2026-06-10-/350/256/241/347/256/227bug/344/277/256/345/244/215-search/346/211/271.md +75 -0
  956. package/docs/fix-2026-06-11-/347/254/254/344/272/214/350/275/256-/344/277/256/345/244/215-search/346/211/271.md +62 -0
  957. package/docs/parity-sweep/REPORT-DYNAMIC.md +97 -0
  958. package/docs/parity-sweep/REPORT-STATIC-GGB.md +127 -0
  959. package/docs/parity-sweep/REPORT-STATIC-RWE.md +133 -0
  960. package/docs/vendor-history.md +385 -0
  961. package/docs/vendored-upstream-diff-2026-07.md +83 -0
  962. package/package.json +70 -0
@@ -0,0 +1,1053 @@
1
+ import { runAgentLoop } from "../loop/agent-loop.js";
2
+ import { resolveAgentCoreStreamFn } from "../loop/runtime-deps.js";
3
+ import { convertToLlm } from "./messages.js";
4
+ import { AgentHarnessError, CompactionError, SessionError, toError, } from "./types.js";
5
+ function createUserMessage(text, images) {
6
+ const content = [{ type: "text", text }];
7
+ if (images) {
8
+ content.push(...images);
9
+ }
10
+ return { role: "user", content, timestamp: Date.now() };
11
+ }
12
+ function createFailureMessage(model, error, aborted) {
13
+ return {
14
+ role: "assistant",
15
+ content: [{ type: "text", text: "" }],
16
+ api: model.api,
17
+ provider: model.provider,
18
+ model: model.id,
19
+ stopReason: aborted ? "aborted" : "error",
20
+ errorMessage: error instanceof Error ? error.message : String(error),
21
+ timestamp: Date.now(),
22
+ usage: {
23
+ input: 0,
24
+ output: 0,
25
+ cacheRead: 0,
26
+ cacheWrite: 0,
27
+ totalTokens: 0,
28
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
29
+ },
30
+ };
31
+ }
32
+ function cloneStreamOptions(streamOptions) {
33
+ return {
34
+ ...streamOptions,
35
+ headers: streamOptions?.headers ? { ...streamOptions.headers } : undefined,
36
+ metadata: streamOptions?.metadata ? { ...streamOptions.metadata } : undefined,
37
+ };
38
+ }
39
+ function mergeHeaders(...headers) {
40
+ const merged = {};
41
+ let hasHeaders = false;
42
+ for (const entry of headers) {
43
+ if (!entry) {
44
+ continue;
45
+ }
46
+ Object.assign(merged, entry);
47
+ hasHeaders = true;
48
+ }
49
+ return hasHeaders ? merged : undefined;
50
+ }
51
+ function applyStreamOptionsPatch(base, patch) {
52
+ const result = cloneStreamOptions(base);
53
+ if (!patch) {
54
+ return result;
55
+ }
56
+ if (Object.hasOwn(patch, "transport")) {
57
+ result.transport = patch.transport;
58
+ }
59
+ if (Object.hasOwn(patch, "timeoutMs")) {
60
+ result.timeoutMs = patch.timeoutMs;
61
+ }
62
+ if (Object.hasOwn(patch, "maxRetries")) {
63
+ result.maxRetries = patch.maxRetries;
64
+ }
65
+ if (Object.hasOwn(patch, "maxRetryDelayMs")) {
66
+ result.maxRetryDelayMs = patch.maxRetryDelayMs;
67
+ }
68
+ if (Object.hasOwn(patch, "cacheRetention")) {
69
+ result.cacheRetention = patch.cacheRetention;
70
+ }
71
+ if (Object.hasOwn(patch, "headers")) {
72
+ if (patch.headers === undefined) {
73
+ result.headers = undefined;
74
+ }
75
+ else {
76
+ const headers = { ...result.headers };
77
+ for (const [key, value] of Object.entries(patch.headers)) {
78
+ if (value === undefined) {
79
+ delete headers[key];
80
+ }
81
+ else {
82
+ headers[key] = value;
83
+ }
84
+ }
85
+ result.headers = Object.keys(headers).length > 0 ? headers : undefined;
86
+ }
87
+ }
88
+ if (Object.hasOwn(patch, "metadata")) {
89
+ if (patch.metadata === undefined) {
90
+ result.metadata = undefined;
91
+ }
92
+ else {
93
+ const metadata = { ...result.metadata };
94
+ for (const [key, value] of Object.entries(patch.metadata)) {
95
+ if (value === undefined) {
96
+ delete metadata[key];
97
+ }
98
+ else {
99
+ metadata[key] = value;
100
+ }
101
+ }
102
+ result.metadata = Object.keys(metadata).length > 0 ? metadata : undefined;
103
+ }
104
+ }
105
+ return result;
106
+ }
107
+ const SUBSCRIBER_EVENT_TYPE = "*";
108
+ function normalizeHarnessError(error, fallbackCode) {
109
+ if (error instanceof AgentHarnessError) {
110
+ return error;
111
+ }
112
+ const cause = toError(error);
113
+ if (cause instanceof SessionError) {
114
+ return new AgentHarnessError("session", cause.message, cause);
115
+ }
116
+ if (cause instanceof CompactionError) {
117
+ return new AgentHarnessError("compaction", cause.message, cause);
118
+ }
119
+ return new AgentHarnessError(fallbackCode, cause.message, cause);
120
+ }
121
+ function normalizeHookError(error) {
122
+ return normalizeHarnessError(error, "hook");
123
+ }
124
+ export class AgentHarness {
125
+ env;
126
+ session;
127
+ phase = "idle";
128
+ /** design/74 R3-A: a one-way soft-stop flag. When set, `shouldStopAfterTurn` returns true at the next turn
129
+ * boundary so the loop exits CLEANLY (emit `agent_end` + return) WITHOUT an abort/interrupt — the path a
130
+ * resource-slice suspend needs (an abort would trip the orphan-[INTERRUPTED] reconcile = corrupt resume). */
131
+ _stopAfterTurn = false;
132
+ runAbortController;
133
+ runPromise;
134
+ pendingSessionWrites = [];
135
+ model;
136
+ thinkingLevel;
137
+ systemPrompt;
138
+ streamOptions;
139
+ getApiKeyAndHeaders;
140
+ runtime;
141
+ resources;
142
+ tools = new Map();
143
+ activeToolNames;
144
+ steerQueue = [];
145
+ steeringQueueMode;
146
+ maxOutputTokens;
147
+ maxOutputTokensPerCall;
148
+ callDeadlineMsPerCall; // design/130 P2b
149
+ loopTrace; // service [398] C2
150
+ resilience; // design/131
151
+ maxToolConcurrency;
152
+ streamingToolExecution;
153
+ followUpQueue = [];
154
+ followUpQueueMode;
155
+ nextTurnQueue = [];
156
+ loopRecovery;
157
+ /** roadmap #5 (CC Stop hook): the runner-wired stop gate — see {@link setStopGate}. */
158
+ stopGate;
159
+ handlers = new Map();
160
+ constructor(options) {
161
+ this.env = options.env;
162
+ this.session = options.session;
163
+ this.resources = options.resources ?? {};
164
+ this.streamOptions = cloneStreamOptions(options.streamOptions);
165
+ this.systemPrompt = options.systemPrompt;
166
+ this.getApiKeyAndHeaders = options.getApiKeyAndHeaders;
167
+ this.runtime = options.runtime;
168
+ for (const tool of options.tools ?? []) {
169
+ this.tools.set(tool.name, tool);
170
+ }
171
+ this.model = options.model;
172
+ this.thinkingLevel = options.thinkingLevel ?? "off";
173
+ this.activeToolNames =
174
+ options.activeToolNames ?? (options.tools ?? []).map((tool) => tool.name);
175
+ this.steeringQueueMode = options.steeringMode ?? "one-at-a-time";
176
+ this.maxOutputTokens = options.maxOutputTokens;
177
+ this.maxOutputTokensPerCall = options.maxOutputTokensPerCall;
178
+ this.callDeadlineMsPerCall = options.callDeadlineMsPerCall; // design/130 P2b
179
+ this.loopTrace = options.loopTrace; // service [398] C2
180
+ this.resilience = options.resilience; // design/131
181
+ this.maxToolConcurrency = options.maxToolConcurrency;
182
+ this.streamingToolExecution = options.streamingToolExecution;
183
+ this.followUpQueueMode = options.followUpMode ?? "one-at-a-time";
184
+ }
185
+ getHandlers(type) {
186
+ return this.handlers.get(type);
187
+ }
188
+ async emitOwn(event, signal) {
189
+ for (const listener of this.getHandlers(SUBSCRIBER_EVENT_TYPE) ?? []) {
190
+ try {
191
+ await listener(event, signal);
192
+ }
193
+ catch (error) {
194
+ throw normalizeHookError(error);
195
+ }
196
+ }
197
+ }
198
+ async emitAny(event, signal) {
199
+ for (const listener of this.getHandlers(SUBSCRIBER_EVENT_TYPE) ?? []) {
200
+ try {
201
+ await listener(event, signal);
202
+ }
203
+ catch (error) {
204
+ throw normalizeHookError(error);
205
+ }
206
+ }
207
+ }
208
+ /**
209
+ * Emit a hook event to its registered handlers and return a single result.
210
+ *
211
+ * **Last-write-wins:** handlers run in registration order; each non-`undefined` result overwrites
212
+ * the previous one, and the LAST non-`undefined` result is returned (`undefined` = abstain, keeps
213
+ * the prior winner). Handlers do NOT compose — registering two handlers that both return a result
214
+ * for the same event silently drops all but the last. A handler that throws aborts the whole emit
215
+ * (errors are not swallowed). Callers that need ordered, composable semantics for one event (e.g.
216
+ * the design/37 two-phase tool gate: collect arg rewrites, then adjudicate policy) must funnel that
217
+ * logic through a SINGLE handler rather than relying on multiple handlers + this fold.
218
+ */
219
+ async emitHook(event) {
220
+ const handlers = this.getHandlers(event.type);
221
+ if (!handlers || handlers.size === 0) {
222
+ return undefined;
223
+ }
224
+ let lastResult;
225
+ for (const handler of handlers) {
226
+ try {
227
+ const result = (await handler(event));
228
+ if (result !== undefined) {
229
+ lastResult = result;
230
+ }
231
+ }
232
+ catch (error) {
233
+ throw normalizeHookError(error);
234
+ }
235
+ }
236
+ return lastResult;
237
+ }
238
+ async emitBeforeProviderRequest(model, sessionId, streamOptions) {
239
+ const handlers = this.getHandlers("before_provider_request");
240
+ let current = cloneStreamOptions(streamOptions);
241
+ if (!handlers || handlers.size === 0) {
242
+ return current;
243
+ }
244
+ for (const handler of handlers) {
245
+ try {
246
+ const result = (await handler({
247
+ type: "before_provider_request",
248
+ model,
249
+ sessionId,
250
+ streamOptions: cloneStreamOptions(current),
251
+ }));
252
+ if (result?.streamOptions) {
253
+ current = applyStreamOptionsPatch(current, result.streamOptions);
254
+ }
255
+ }
256
+ catch (error) {
257
+ throw normalizeHookError(error);
258
+ }
259
+ }
260
+ return current;
261
+ }
262
+ async emitBeforeProviderPayload(model, payload) {
263
+ const handlers = this.getHandlers("before_provider_payload");
264
+ let current = payload;
265
+ if (!handlers || handlers.size === 0) {
266
+ return current;
267
+ }
268
+ for (const handler of handlers) {
269
+ try {
270
+ const result = (await handler({
271
+ type: "before_provider_payload",
272
+ model,
273
+ payload: current,
274
+ }));
275
+ if (result !== undefined) {
276
+ current = result.payload;
277
+ }
278
+ }
279
+ catch (error) {
280
+ throw normalizeHookError(error);
281
+ }
282
+ }
283
+ return current;
284
+ }
285
+ async emitQueueUpdate() {
286
+ await this.emitOwn({
287
+ type: "queue_update",
288
+ steer: [...this.steerQueue],
289
+ followUp: [...this.followUpQueue],
290
+ nextTurn: [...this.nextTurnQueue],
291
+ });
292
+ }
293
+ startRunPromise() {
294
+ let finish = () => { };
295
+ this.runPromise = new Promise((resolve) => {
296
+ finish = resolve;
297
+ });
298
+ return () => {
299
+ this.runPromise = undefined;
300
+ finish();
301
+ };
302
+ }
303
+ async createTurnState() {
304
+ const context = await this.session.buildContext();
305
+ const resources = this.getResources();
306
+ const sessionMetadata = await this.session.getMetadata();
307
+ const tools = [...this.tools.values()];
308
+ const activeTools = this.activeToolNames
309
+ .map((name) => this.tools.get(name))
310
+ .filter((tool) => tool !== undefined);
311
+ let systemPrompt = "You are a helpful assistant.";
312
+ if (typeof this.systemPrompt === "string") {
313
+ systemPrompt = this.systemPrompt;
314
+ }
315
+ else if (this.systemPrompt) {
316
+ systemPrompt = await this.systemPrompt({
317
+ env: this.env,
318
+ session: this.session,
319
+ model: this.model,
320
+ thinkingLevel: this.thinkingLevel,
321
+ activeTools,
322
+ resources,
323
+ });
324
+ }
325
+ return {
326
+ messages: context.messages,
327
+ resources,
328
+ streamOptions: cloneStreamOptions(this.streamOptions),
329
+ sessionId: sessionMetadata.id,
330
+ systemPrompt,
331
+ model: this.model,
332
+ thinkingLevel: this.thinkingLevel,
333
+ tools,
334
+ activeTools,
335
+ };
336
+ }
337
+ createContext(turnState, systemPrompt) {
338
+ return {
339
+ systemPrompt: systemPrompt ?? turnState.systemPrompt,
340
+ messages: turnState.messages.slice(),
341
+ tools: turnState.activeTools.slice(),
342
+ };
343
+ }
344
+ createStreamFn(getTurnState) {
345
+ return async (model, context, streamOptions) => {
346
+ const turnState = getTurnState();
347
+ const auth = await this.getApiKeyAndHeaders?.(model);
348
+ const snapshotOptions = {
349
+ ...turnState.streamOptions,
350
+ headers: mergeHeaders(turnState.streamOptions.headers, auth?.headers),
351
+ };
352
+ const requestOptions = await this.emitBeforeProviderRequest(model, turnState.sessionId, snapshotOptions);
353
+ return resolveAgentCoreStreamFn(this.runtime)(model, context, {
354
+ cacheRetention: requestOptions.cacheRetention,
355
+ headers: requestOptions.headers,
356
+ maxRetries: requestOptions.maxRetries,
357
+ maxRetryDelayMs: requestOptions.maxRetryDelayMs,
358
+ metadata: requestOptions.metadata,
359
+ onPayload: async (payload) => await this.emitBeforeProviderPayload(model, payload),
360
+ onResponse: async (response) => {
361
+ const headers = { ...response.headers };
362
+ await this.emitOwn({ type: "after_provider_response", status: response.status, headers }, streamOptions?.signal);
363
+ },
364
+ reasoning: streamOptions?.reasoning,
365
+ // design/119 #2: forward the loop-config per-request output cap (the curated snapshot below
366
+ // deliberately excludes provider knobs, but maxTokens is loop-owned — dropping it here was
367
+ // the silent break in the spec.limits.maxOutputTokens chain).
368
+ maxTokens: streamOptions?.maxTokens,
369
+ // design/130 P2b (codex BLOCKER): same class as the maxTokens line above — the curated
370
+ // snapshot must forward every LOOP-OWNED per-call field, or the soft call deadline silently
371
+ // dies at this seam on the production runner→harness→provider path.
372
+ callDeadlineMs: streamOptions?.callDeadlineMs,
373
+ // service [405]: the dynamic-cap marker rides with maxTokens (recoverable-length contract).
374
+ maxTokensDynamic: streamOptions?.maxTokensDynamic,
375
+ // [477]: the static reasoning-cut downgrade grant is loop-owned per-call state — same
376
+ // forwarding class as maxTokensDynamic (locked by test/stream-options-forwarding.test.ts).
377
+ staticReasoningCutDowngrade: streamOptions?.staticReasoningCutDowngrade,
378
+ // design/131: third loop-owned per-call field through this whitelist (the forwarding contract
379
+ // is now LOCKED by test/stream-options-forwarding.test.ts — the class that bit twice).
380
+ resilience: streamOptions?.resilience,
381
+ signal: streamOptions?.signal,
382
+ sessionId: turnState.sessionId,
383
+ timeoutMs: requestOptions.timeoutMs,
384
+ transport: requestOptions.transport,
385
+ apiKey: auth?.apiKey,
386
+ });
387
+ };
388
+ }
389
+ async drainQueuedMessages(queue, mode) {
390
+ const messages = mode === "all" ? queue.splice(0) : queue.splice(0, 1);
391
+ if (messages.length === 0) {
392
+ return messages;
393
+ }
394
+ try {
395
+ await this.emitQueueUpdate();
396
+ return messages;
397
+ }
398
+ catch (error) {
399
+ queue.unshift(...messages);
400
+ throw normalizeHookError(error);
401
+ }
402
+ }
403
+ createLoopConfig(getTurnState, setTurnState) {
404
+ const turnState = getTurnState();
405
+ // eslint-disable-next-line @typescript-eslint/no-this-alias -- the recovery getters below close over the instance
406
+ const self = this;
407
+ return {
408
+ model: turnState.model,
409
+ reasoning: turnState.thinkingLevel === "off" ? undefined : turnState.thinkingLevel,
410
+ // design/119 #2: per-request output cap — config extends SimpleStreamOptions, so the loop's
411
+ // {...config} spread carries it into every provider call as options.maxTokens.
412
+ ...(this.maxOutputTokens !== undefined ? { maxTokens: this.maxOutputTokens } : {}),
413
+ // design/130 P1: per-call dynamic cap seam — evaluated by the loop before each provider call.
414
+ ...(this.maxOutputTokensPerCall !== undefined ? { maxTokensPerCall: this.maxOutputTokensPerCall } : {}),
415
+ // design/130 P2b: per-call soft wall-clock deadline seam (brain-side stream cutoff).
416
+ ...(this.callDeadlineMsPerCall !== undefined ? { callDeadlineMsPerCall: this.callDeadlineMsPerCall } : {}),
417
+ // design/131: per-task resilience intent — rides the loop-config spread into every provider call.
418
+ ...(this.resilience !== undefined ? { resilience: this.resilience } : {}),
419
+ ...(this.maxToolConcurrency !== undefined ? { maxToolConcurrency: this.maxToolConcurrency } : {}),
420
+ // design/120 P2: in-stream execution reaches the loop ONLY when the host opted in AND no
421
+ // tool_call gate handler exists at run start (createLoopConfig runs once per prompt()). A
422
+ // registered tool_call handler could durably suspend (mint checkpoint + abort), which has no
423
+ // stable leaf mid-stream, so its presence forces the batch path for the whole run.
424
+ ...(this.streamingToolExecution === true && (this.getHandlers("tool_call")?.size ?? 0) === 0
425
+ ? { streamingToolExecution: true }
426
+ : {}),
427
+ convertToLlm,
428
+ // VENDORED EDIT (design/74 R3-A, VENDOR.md mod #16): wire the loop's EXISTING clean-exit callback to a
429
+ // one-way harness flag. The runner's `turn_boundary` subscriber sets it (via `requestStopAfterTurn`)
430
+ // once a resource slice limit is hit + the suspend is committed; the loop then exits cleanly at the
431
+ // boundary (agent_end + return) instead of via abort — no orphan-[INTERRUPTED] reconcile, clean resume.
432
+ shouldStopAfterTurn: () => this._stopAfterTurn,
433
+ transformContext: async (messages) => {
434
+ const result = await this.emitHook({ type: "context", messages: [...messages] });
435
+ return result?.messages ?? messages;
436
+ },
437
+ beforeToolCall: async ({ toolCall, args }) => {
438
+ const result = await this.emitHook({
439
+ type: "tool_call",
440
+ toolCallId: toolCall.id,
441
+ toolName: toolCall.name,
442
+ input: args,
443
+ });
444
+ // Return the hook result verbatim: cherry-picking `{ block, reason }` here structurally
445
+ // dropped any future field (e.g. `updatedInput`, design/37) before it reached the loop, with
446
+ // no TS error since BeforeToolCallResult only requires block?/reason?. `ToolCallResult` is
447
+ // kept in sync with `BeforeToolCallResult`, so the shapes match.
448
+ return result;
449
+ },
450
+ afterToolCall: async ({ toolCall, args, result, isError }) => {
451
+ const patch = await this.emitHook({
452
+ type: "tool_result",
453
+ toolCallId: toolCall.id,
454
+ toolName: toolCall.name,
455
+ input: args,
456
+ content: result.content,
457
+ details: result.details,
458
+ isError,
459
+ });
460
+ return patch
461
+ ? {
462
+ content: patch.content,
463
+ details: patch.details,
464
+ isError: patch.isError,
465
+ terminate: patch.terminate,
466
+ }
467
+ : undefined;
468
+ },
469
+ prepareNextTurn: async () => {
470
+ await this.flushPendingSessionWrites();
471
+ // VENDORED EDIT (design/64 §25 (A), within-task compaction): between-turn boundary seam. The
472
+ // session is fully flushed here and `createTurnState()` below rebuilds the context FROM the
473
+ // session, so a handler that persists a mutation (e.g. compaction via `session.appendCompaction`)
474
+ // is picked up by the very next request — the CC query-path autocompact position equivalent.
475
+ // Policy lives entirely in the subscriber (core runtask); the harness only supplies the timing.
476
+ // `this.model` (always set — required in AgentHarnessOptions) is what `createTurnState()` will
477
+ // stamp on the NEXT turn: a mid-task `setModel` (e.g. budget degrade) lands there first, so the
478
+ // handler's window math follows the model that actually runs the next request (council #1).
479
+ await this.emitHook({ type: "turn_boundary", model: this.model });
480
+ const nextTurnState = await this.createTurnState();
481
+ setTurnState(nextTurnState);
482
+ return {
483
+ context: this.createContext(nextTurnState),
484
+ model: nextTurnState.model,
485
+ thinkingLevel: nextTurnState.thinkingLevel,
486
+ };
487
+ },
488
+ getSteeringMessages: async () => this.drainQueuedMessages(this.steerQueue, this.steeringQueueMode),
489
+ getFollowUpMessages: async () => {
490
+ const queued = await this.drainQueuedMessages(this.followUpQueue, this.followUpQueueMode);
491
+ if (queued.length > 0)
492
+ return queued;
493
+ // roadmap #5 (CC Stop hook): the queue is dry and the agent would otherwise END — consult
494
+ // the stop gate (wired by the runner from Hooks.stop). Returned messages continue the run
495
+ // through the SAME pending-message path as real follow-ups; [] lets the run end normally.
496
+ return this.stopGate ? await this.stopGate() : queued;
497
+ },
498
+ // design/118 ④b/⑤: recovery chains. Read LIVE (not snapshotted) so setLoopRecovery() before
499
+ // prompt() — the runner's wiring point — always lands.
500
+ recovery: {
501
+ get truncatedOutput() {
502
+ return self.loopRecovery?.truncatedOutput;
503
+ },
504
+ get malformedToolUse() {
505
+ return self.loopRecovery?.malformedToolUse;
506
+ },
507
+ get thinkingOnly() {
508
+ return self.loopRecovery?.thinkingOnly;
509
+ },
510
+ get degenerateOutput() {
511
+ return self.loopRecovery?.degenerateOutput;
512
+ },
513
+ get walltimeCutoff() {
514
+ return self.loopRecovery?.walltimeCutoff; // design/130 P2b
515
+ },
516
+ get promptTooLong() {
517
+ const ptl = self.loopRecovery?.promptTooLong;
518
+ if (!ptl)
519
+ return undefined;
520
+ return {
521
+ detect: ptl.detect,
522
+ maxRetries: ptl.maxRetries,
523
+ withholdErrorEvents: ptl.withholdErrorEvents, // M1: relay the CC-withhold switch
524
+ recover: async (_messages, attempt) => {
525
+ let shrank = false;
526
+ try {
527
+ shrank = await ptl.recover(attempt);
528
+ }
529
+ catch {
530
+ shrank = false; // contract belt: a throwing policy = recovery declined, never a new failure
531
+ }
532
+ if (!shrank)
533
+ return undefined;
534
+ // Rebuild the transcript FROM the session (where recover() persisted the reduction),
535
+ // and adopt the rebuilt turn state so subsequent hooks see the same view.
536
+ const nextTurnState = await self.createTurnState();
537
+ setTurnState(nextTurnState);
538
+ return self.createContext(nextTurnState).messages;
539
+ },
540
+ };
541
+ },
542
+ },
543
+ };
544
+ }
545
+ /**
546
+ * design/118 ④b/⑤: wire (or clear) the loop's recovery chains. The runner calls this after
547
+ * construction — truncated-output auto-continue and the prompt-too-long recover policy are
548
+ * PROFILE decisions (the harness only relays them to the loop).
549
+ */
550
+ setLoopRecovery(recovery) {
551
+ this.loopRecovery = recovery;
552
+ }
553
+ /**
554
+ * roadmap #5 (CC Stop hook): wire (or clear) the stop gate — consulted ONLY when the run would
555
+ * otherwise end (no tool calls, steer + followUp queues dry). Non-empty return = the run
556
+ * continues with those messages injected; empty = the run ends. Policy (the Hooks.stop call,
557
+ * consecutive-block cap, reason formatting) lives in the runner; the harness only supplies the
558
+ * drain-point timing.
559
+ */
560
+ setStopGate(gate) {
561
+ this.stopGate = gate;
562
+ }
563
+ validateToolNames(toolNames, tools = this.tools) {
564
+ const missing = toolNames.filter((name) => !tools.has(name));
565
+ if (missing.length > 0) {
566
+ throw new AgentHarnessError("invalid_argument", `Unknown tool(s): ${missing.join(", ")}`);
567
+ }
568
+ }
569
+ async flushPendingSessionWrites() {
570
+ // VENDOR.md mod #5 (fixed at de-vendoring, design/118 ⑤ — central guard): once THIS run's abort
571
+ // has fired, the session may hold an open tool_call batch whose synthetic tool_results are
572
+ // appended later by the caller's interrupt reconcile. Flushing caller-queued writes now (from
573
+ // ANY teardown path: prepareNextTurn, turn_end, agent_end, executeTurn's finally) would land
574
+ // them inside that open batch — an API-invalid sequence on strict providers. Hold the queue;
575
+ // it drains via flushQueuedSessionWrites() after the reconcile (runtask wires this) or at the
576
+ // next prompt() start. (Caveats, documented: ① a durable-suspend abort that never reconciles in
577
+ // this process holds these writes until the harness dies — the resume leg rebuilds from the
578
+ // checkpointed session, so a held write is lost, not corrupting; ② a same-tick turn-boundary
579
+ // setModel racing a hard abort CAN be held — the runtask reconcile-then-drain wiring flushes it
580
+ // right after the transcript is legal again, so the ordering stays correct either way.)
581
+ if (this.runAbortController?.signal.aborted) {
582
+ return;
583
+ }
584
+ while (this.pendingSessionWrites.length > 0) {
585
+ const write = this.pendingSessionWrites[0];
586
+ if (write.type === "message") {
587
+ await this.session.appendMessage(write.message);
588
+ }
589
+ else if (write.type === "model_change") {
590
+ await this.session.appendModelChange(write.provider, write.modelId);
591
+ }
592
+ else if (write.type === "thinking_level_change") {
593
+ await this.session.appendThinkingLevelChange(write.thinkingLevel);
594
+ }
595
+ else if (write.type === "custom") {
596
+ await this.session.appendCustomEntry(write.customType, write.data);
597
+ }
598
+ else if (write.type === "custom_message") {
599
+ await this.session.appendCustomMessageEntry(write.customType, write.content, write.display, write.details);
600
+ }
601
+ else if (write.type === "label") {
602
+ await this.session.appendLabel(write.targetId, write.label);
603
+ }
604
+ else if (write.type === "session_info") {
605
+ await this.session.appendSessionName(write.name ?? "");
606
+ }
607
+ else if (write.type === "leaf") {
608
+ await this.session.getStorage().setLeafId(write.targetId);
609
+ }
610
+ this.pendingSessionWrites.shift();
611
+ }
612
+ }
613
+ async handleAgentEvent(event, signal) {
614
+ if (event.type === "message_end") {
615
+ // VENDORED EDIT (audit A-1 layer ③, design/64 §28.3): a synthetic EMPTY failure assistant
616
+ // (stopReason aborted/error, no text/thinking/toolCall content — e.g. the loop-failure message
617
+ // for a stream that died on an aborted signal or a provider 500 with no output) is NOT model
618
+ // output and must not be persisted: parked between an interrupted tool batch and its reconcile
619
+ // tool_results it makes the session permanently invalid for strict providers. It still flows to
620
+ // live subscribers (emitAny below) and into the prompt() result — only the session skips it. An
621
+ // aborted message WITH partial content is real output and persists as before.
622
+ // VENDORED EDIT (message-identity Phase 1, VENDOR.md mod #23): keep the entry id `appendMessage` RETURNS
623
+ // (synchronous at the append — no `getLeafId` after-the-fact race) and thread it onto the emitted event via
624
+ // a fresh `{ ...event, entryId }` (never mutate `event`). A consumer maps this just-committed message → its
625
+ // persisted SessionTreeEntry id (the `message_committed` wire event). Undefined when the skip above appends
626
+ // nothing (empty-failure assistant) — then the event is emitted as-is and no commit event is published.
627
+ let entryId;
628
+ if (!isEmptyFailureAssistant(event.message)) {
629
+ entryId = await this.session.appendMessage(event.message);
630
+ }
631
+ await this.emitAny(entryId !== undefined ? { ...event, entryId } : event, signal);
632
+ return;
633
+ }
634
+ if (event.type === "turn_end") {
635
+ let eventError;
636
+ try {
637
+ await this.emitAny(event, signal);
638
+ }
639
+ catch (error) {
640
+ eventError = error;
641
+ }
642
+ const queued = this.pendingSessionWrites.length > 0;
643
+ await this.flushPendingSessionWrites(); // mod #5: no-op while this run's abort has fired
644
+ // Honest save_point semantics under the mod #5 hold: `hadPendingMutations` means "this save
645
+ // point PERSISTED queued mutations" — when the abort hold kept the queue, report false (the
646
+ // late drain after reconcile is not a save point).
647
+ const hadPendingMutations = queued && this.pendingSessionWrites.length === 0;
648
+ if (eventError) {
649
+ throw toLintErrorObject(eventError, "Non-Error thrown");
650
+ }
651
+ await this.emitOwn({ type: "save_point", hadPendingMutations });
652
+ return;
653
+ }
654
+ if (event.type === "agent_end") {
655
+ await this.flushPendingSessionWrites(); // mod #5: no-op while this run's abort has fired
656
+ this.phase = "idle";
657
+ await this.emitAny(event, signal);
658
+ await this.emitOwn({ type: "settled", nextTurnCount: this.nextTurnQueue.length }, signal);
659
+ return;
660
+ }
661
+ await this.emitAny(event, signal);
662
+ }
663
+ async emitRunFailure(model, error, aborted, signal) {
664
+ const failureMessage = createFailureMessage(model, error, aborted);
665
+ await this.handleAgentEvent({ type: "message_start", message: failureMessage }, signal);
666
+ await this.handleAgentEvent({ type: "message_end", message: failureMessage }, signal);
667
+ await this.handleAgentEvent({ type: "turn_end", message: failureMessage, toolResults: [] }, signal);
668
+ await this.handleAgentEvent({ type: "agent_end", messages: [failureMessage] }, signal);
669
+ return [failureMessage];
670
+ }
671
+ async executeTurn(turnState, text, options) {
672
+ let activeTurnState = turnState;
673
+ let messages = [createUserMessage(text, options?.images)];
674
+ if (this.nextTurnQueue.length > 0) {
675
+ const queuedMessages = this.nextTurnQueue.splice(0);
676
+ try {
677
+ await this.emitQueueUpdate();
678
+ }
679
+ catch (error) {
680
+ this.nextTurnQueue.unshift(...queuedMessages);
681
+ throw normalizeHookError(error);
682
+ }
683
+ messages = [...queuedMessages, messages[0]];
684
+ }
685
+ const beforeResult = await this.emitHook({
686
+ type: "before_agent_start",
687
+ prompt: text,
688
+ images: options?.images,
689
+ systemPrompt: turnState.systemPrompt,
690
+ resources: turnState.resources,
691
+ });
692
+ if (beforeResult?.messages) {
693
+ messages = [...messages, ...beforeResult.messages];
694
+ }
695
+ const abortController = new AbortController();
696
+ const getTurnState = () => activeTurnState;
697
+ const setTurnState = (nextTurnState) => {
698
+ activeTurnState = nextTurnState;
699
+ };
700
+ this.runAbortController = abortController;
701
+ const runResultPromise = (async () => {
702
+ try {
703
+ return await runAgentLoop(messages, this.createContext(turnState, beforeResult?.systemPrompt), this.createLoopConfig(getTurnState, setTurnState), (event) => this.handleAgentEvent(event, abortController.signal), abortController.signal, this.createStreamFn(getTurnState), undefined,
704
+ // service [398] C2: the loop's recovery trace was test-only (the 8th arg was never passed in
705
+ // production) — wire the host's sink so self-heal recoveries stop being invisible.
706
+ this.loopTrace);
707
+ }
708
+ catch (error) {
709
+ try {
710
+ return await this.emitRunFailure(activeTurnState.model, error, abortController.signal.aborted, abortController.signal);
711
+ }
712
+ catch (failureError) {
713
+ const cause = new AggregateError([toError(error), toError(failureError)], "Agent run failed and failure reporting failed");
714
+ throw new AgentHarnessError("unknown", cause.message, cause);
715
+ }
716
+ }
717
+ })();
718
+ try {
719
+ const newMessages = await runResultPromise;
720
+ for (let i = newMessages.length - 1; i >= 0; i--) {
721
+ const message = newMessages[i];
722
+ if (message.role === "assistant") {
723
+ // design/118 ④b: a truncated-output auto-continue splits ONE answer across several
724
+ // assistant messages (…length-stop → nudge → continuation…). The prompt() result is "the
725
+ // answer", so merge the trailing chain's text — otherwise the caller's result string
726
+ // silently loses every segment but the last (the session/events keep the real messages).
727
+ return mergeTruncatedOutputChain(newMessages, i);
728
+ }
729
+ }
730
+ throw new AgentHarnessError("invalid_state", "AgentHarness prompt completed without an assistant message");
731
+ }
732
+ finally {
733
+ try {
734
+ await this.flushPendingSessionWrites(); // mod #5: no-op while this run's abort has fired
735
+ }
736
+ finally {
737
+ this.runAbortController = undefined;
738
+ }
739
+ }
740
+ }
741
+ async prompt(text, options) {
742
+ if (this.phase !== "idle") {
743
+ throw new AgentHarnessError("busy", "AgentHarness is busy");
744
+ }
745
+ // VENDORED EDIT (design/74 council #1, VENDOR.md mod #16): the resource-suspend stop latch is ONE-SHOT
746
+ // per prompt. `requestStopAfterTurn()` sets it to cleanly stop THIS run's loop after the current turn;
747
+ // clear it at the start of every prompt so a re-prompt/reuse of the harness can't inherit a stale stop
748
+ // (which would silently end the next run after a single turn).
749
+ this._stopAfterTurn = false;
750
+ this.phase = "turn";
751
+ const finishRunPromise = this.startRunPromise();
752
+ try {
753
+ // mod #5 belt: writes held from a previous ABORTED run (whose caller never called
754
+ // flushQueuedSessionWrites) drain here — before createTurnState builds the new context —
755
+ // so they are never lost and always land AFTER any reconcile the caller did run.
756
+ await this.flushPendingSessionWrites();
757
+ const turnState = await this.createTurnState();
758
+ return await this.executeTurn(turnState, text, options);
759
+ }
760
+ catch (error) {
761
+ this.phase = "idle";
762
+ throw normalizeHarnessError(error, "unknown");
763
+ }
764
+ finally {
765
+ finishRunPromise();
766
+ }
767
+ }
768
+ // VENDORED EDIT (design/71 P1, 2026-06-12): skill() DELETED along with harness/skills.ts +
769
+ // file-loader-utils.ts (and the ignore/yaml deps they alone pulled). Upstream's explicit
770
+ // skill-invocation entry; zero callers here, and the system-prompt half of the feature
771
+ // (formatSkillsForSystemPrompt) was already dead-deleted in P0 — the model never saw skill
772
+ // listings in this repo. resources.skills is now a fully inert field (see TaskSpec.skills note
773
+ // in src/core/types.ts; the Skill TYPE stays in types.ts and is still used by core's toSkill).
774
+ // VENDORED EDIT (design/71 P1, 2026-06-12): promptFromTemplate() DELETED along with
775
+ // harness/prompt-templates.ts + prompt-template-arguments.ts. Upstream's interactive
776
+ // slash-command feature; resources.promptTemplates was never fed by this repo and the method had
777
+ // zero callers (src/ + test/). The PromptTemplate type stays in types.ts (type-level surface only).
778
+ async steer(text, options) {
779
+ if (this.phase === "idle") {
780
+ throw new AgentHarnessError("invalid_state", "Cannot steer while idle");
781
+ }
782
+ this.steerQueue.push(createUserMessage(text, options?.images));
783
+ await this.emitQueueUpdate();
784
+ }
785
+ async followUp(text, options) {
786
+ if (this.phase === "idle") {
787
+ throw new AgentHarnessError("invalid_state", "Cannot follow up while idle");
788
+ }
789
+ this.followUpQueue.push(createUserMessage(text, options?.images));
790
+ await this.emitQueueUpdate();
791
+ }
792
+ async nextTurn(text, options) {
793
+ this.nextTurnQueue.push(createUserMessage(text, options?.images));
794
+ await this.emitQueueUpdate();
795
+ }
796
+ async appendMessage(message) {
797
+ try {
798
+ if (this.phase === "idle") {
799
+ await this.session.appendMessage(message);
800
+ }
801
+ else {
802
+ this.pendingSessionWrites.push({ type: "message", message });
803
+ }
804
+ }
805
+ catch (error) {
806
+ throw normalizeHarnessError(error, "session");
807
+ }
808
+ }
809
+ // VENDORED EDIT (bug-hunt #10, 2026-06-25): the public `compact()` method was DELETED (with its 3
810
+ // first-party imports: compact / prepareCompaction / DEFAULT_COMPACTION_SETTINGS). It was an unreachable
811
+ // DIVERGENCE landmine: ZERO callers (src/ + test/ — within-task compaction goes through the first-party
812
+ // `maybeCompact` turn-end seam, NOT this method), `AgentHarness` is not exported from src/index.ts, AND it
813
+ // skipped the first-party `<analysis>`-strip + empty-summary guard that `auto-compaction.ts` applies — so if
814
+ // anyone HAD wired it, it would persist un-stripped scratch as the summary. Same precedent as navigateTree
815
+ // below (design/71 delete-the-unreachable-divergence). Deleting it also removed a vendored→first-party import.
816
+ // VENDORED EDIT (design/71 P0, 2026-06-12): navigateTree() DELETED along with
817
+ // harness/compaction/branch-summarization.ts. It was upstream's interactive branch-navigation
818
+ // feature (move leaf + summarize the abandoned branch); zero callers in this repo (src/ + test/),
819
+ // unreachable from Runner -> harness.prompt. The whole branch_summary chain (entry type, render,
820
+ // replay, moveTo, BranchSummaryError) was removed in the design/71 清尾 pass — zero producers ever
821
+ // shipped from this repo, so no stored session can contain such an entry.
822
+ getModel() {
823
+ return this.model;
824
+ }
825
+ getThinkingLevel() {
826
+ return this.thinkingLevel;
827
+ }
828
+ async setModel(model) {
829
+ try {
830
+ const previousModel = this.model;
831
+ if (this.phase === "idle") {
832
+ await this.session.appendModelChange(model.provider, model.id);
833
+ }
834
+ else {
835
+ this.pendingSessionWrites.push({
836
+ type: "model_change",
837
+ provider: model.provider,
838
+ modelId: model.id,
839
+ });
840
+ }
841
+ this.model = model;
842
+ await this.emitOwn({ type: "model_select", model, previousModel, source: "set" });
843
+ }
844
+ catch (error) {
845
+ throw normalizeHarnessError(error, "session");
846
+ }
847
+ }
848
+ async setThinkingLevel(level) {
849
+ try {
850
+ const previousLevel = this.thinkingLevel;
851
+ if (this.phase === "idle") {
852
+ await this.session.appendThinkingLevelChange(level);
853
+ }
854
+ else {
855
+ this.pendingSessionWrites.push({ type: "thinking_level_change", thinkingLevel: level });
856
+ }
857
+ this.thinkingLevel = level;
858
+ await this.emitOwn({ type: "thinking_level_select", level, previousLevel });
859
+ }
860
+ catch (error) {
861
+ throw normalizeHarnessError(error, "session");
862
+ }
863
+ }
864
+ async setActiveTools(toolNames) {
865
+ try {
866
+ this.validateToolNames(toolNames);
867
+ this.activeToolNames = [...toolNames];
868
+ }
869
+ catch (error) {
870
+ throw normalizeHarnessError(error, "invalid_argument");
871
+ }
872
+ }
873
+ getSteeringMode() {
874
+ return this.steeringQueueMode;
875
+ }
876
+ async setSteeringMode(mode) {
877
+ this.steeringQueueMode = mode;
878
+ }
879
+ getFollowUpMode() {
880
+ return this.followUpQueueMode;
881
+ }
882
+ async setFollowUpMode(mode) {
883
+ this.followUpQueueMode = mode;
884
+ }
885
+ getResources() {
886
+ return {
887
+ skills: this.resources.skills?.slice(),
888
+ promptTemplates: this.resources.promptTemplates?.slice(),
889
+ };
890
+ }
891
+ async setResources(resources) {
892
+ const previousResources = this.getResources();
893
+ this.resources = {
894
+ skills: resources.skills?.slice(),
895
+ promptTemplates: resources.promptTemplates?.slice(),
896
+ };
897
+ await this.emitOwn({
898
+ type: "resources_update",
899
+ resources: this.getResources(),
900
+ previousResources,
901
+ });
902
+ }
903
+ getStreamOptions() {
904
+ return cloneStreamOptions(this.streamOptions);
905
+ }
906
+ async setStreamOptions(streamOptions) {
907
+ this.streamOptions = cloneStreamOptions(streamOptions);
908
+ }
909
+ async setTools(tools, activeToolNames) {
910
+ try {
911
+ const nextTools = new Map(tools.map((tool) => [tool.name, tool]));
912
+ const nextActiveToolNames = activeToolNames ? [...activeToolNames] : this.activeToolNames;
913
+ this.validateToolNames(nextActiveToolNames, nextTools);
914
+ this.tools = nextTools;
915
+ this.activeToolNames = [...nextActiveToolNames];
916
+ }
917
+ catch (error) {
918
+ throw normalizeHarnessError(error, "invalid_argument");
919
+ }
920
+ }
921
+ /**
922
+ * design/74 R3-A: request a CLEAN stop at the next turn boundary. Unlike {@link abort} (a hard
923
+ * AbortController cancel that — with no `suspendRef` — drives the orphan-[INTERRUPTED] session reconcile),
924
+ * this sets a one-way flag the loop reads via its `shouldStopAfterTurn` callback: the current turn finishes
925
+ * its tool calls, the loop emits `agent_end`, and returns. The runner uses it for a resource-slice suspend
926
+ * so the suspended session is left clean (resumable), never reconciled as interrupted. Idempotent.
927
+ */
928
+ requestStopAfterTurn() {
929
+ this._stopAfterTurn = true;
930
+ }
931
+ /**
932
+ * VENDOR.md mod #5 (fixed at de-vendoring, design/118 ⑤): drain session writes queued during an
933
+ * ABORTED run. The harness intentionally does NOT flush on the abort path — the caller's interrupt
934
+ * reconcile must append its synthetic tool_results first (closing the open tool_call batch), then
935
+ * call this, so queued writes always land on a legal transcript. Safe to call anytime; no-op when
936
+ * the queue is empty.
937
+ */
938
+ async flushQueuedSessionWrites() {
939
+ try {
940
+ await this.flushPendingSessionWrites();
941
+ }
942
+ catch (error) {
943
+ throw normalizeHarnessError(error, "session");
944
+ }
945
+ }
946
+ async abort() {
947
+ const clearedSteer = [...this.steerQueue];
948
+ const clearedFollowUp = [...this.followUpQueue];
949
+ this.steerQueue = [];
950
+ this.followUpQueue = [];
951
+ this.runAbortController?.abort();
952
+ const errors = [];
953
+ try {
954
+ await this.emitQueueUpdate();
955
+ }
956
+ catch (error) {
957
+ errors.push(toError(error));
958
+ }
959
+ try {
960
+ await this.waitForIdle();
961
+ }
962
+ catch (error) {
963
+ errors.push(toError(error));
964
+ }
965
+ try {
966
+ await this.emitOwn({ type: "abort", clearedSteer, clearedFollowUp });
967
+ }
968
+ catch (error) {
969
+ errors.push(toError(error));
970
+ }
971
+ if (errors.length > 0) {
972
+ const cause = errors.length === 1 ? errors[0] : new AggregateError(errors, "Abort completed with errors");
973
+ throw normalizeHarnessError(cause, "hook");
974
+ }
975
+ return { clearedSteer, clearedFollowUp };
976
+ }
977
+ async waitForIdle() {
978
+ await this.runPromise;
979
+ }
980
+ subscribe(listener) {
981
+ let handlers = this.handlers.get(SUBSCRIBER_EVENT_TYPE);
982
+ if (!handlers) {
983
+ handlers = new Set();
984
+ this.handlers.set(SUBSCRIBER_EVENT_TYPE, handlers);
985
+ }
986
+ handlers.add(listener);
987
+ return () => handlers.delete(listener);
988
+ }
989
+ on(type, handler) {
990
+ let handlers = this.handlers.get(type);
991
+ if (!handlers) {
992
+ handlers = new Set();
993
+ this.handlers.set(type, handlers);
994
+ }
995
+ handlers.add(handler);
996
+ return () => handlers.delete(handler);
997
+ }
998
+ }
999
+ // VENDORED EDIT (audit A-1 layer ③): a failure assistant carrying NO content — no tool calls, no
1000
+ // non-whitespace text/thinking. Only such messages are skipped from session persistence; an aborted
1001
+ // message with partial output is real transcript and persists.
1002
+ function isEmptyFailureAssistant(message) {
1003
+ if (message.role !== "assistant")
1004
+ return false;
1005
+ const m = message;
1006
+ if (m.stopReason !== "aborted" && m.stopReason !== "error")
1007
+ return false;
1008
+ return m.content.every((c) => c.type === "text" ? c.text.trim() === "" : c.type === "thinking" ? c.thinking.trim() === "" : false);
1009
+ }
1010
+ /**
1011
+ * design/118 ④b: walk backward across the trailing `length`-stop chain
1012
+ * (assistant[length] → continue-nudge custom → assistant …) and return the FINAL assistant with the
1013
+ * chain's text concatenated in order. Non-chain shapes return the final assistant unchanged.
1014
+ */
1015
+ function mergeTruncatedOutputChain(messages, lastAssistantIndex) {
1016
+ const last = messages[lastAssistantIndex];
1017
+ const parts = [];
1018
+ let i = lastAssistantIndex;
1019
+ while (i - 2 >= 0 &&
1020
+ messages[i - 1].role === "custom" &&
1021
+ messages[i - 1].customType === "loop:truncated-output-continue" &&
1022
+ messages[i - 2].role === "assistant" &&
1023
+ messages[i - 2].stopReason === "length") {
1024
+ const head = messages[i - 2];
1025
+ parts.unshift(head.content.map((c) => (c.type === "text" ? c.text : "")).join(""));
1026
+ i -= 2;
1027
+ }
1028
+ if (parts.length === 0) {
1029
+ return last;
1030
+ }
1031
+ const lastText = last.content.map((c) => (c.type === "text" ? c.text : "")).join("");
1032
+ return {
1033
+ ...last,
1034
+ content: [
1035
+ { type: "text", text: parts.join("") + lastText },
1036
+ ...last.content.filter((c) => c.type !== "text"),
1037
+ ],
1038
+ };
1039
+ }
1040
+ function toLintErrorObject(value, fallbackMessage) {
1041
+ if (value instanceof Error) {
1042
+ return value;
1043
+ }
1044
+ if (typeof value === "string") {
1045
+ return new Error(value);
1046
+ }
1047
+ const error = new Error(fallbackMessage, { cause: value });
1048
+ if ((typeof value === "object" && value !== null) || typeof value === "function") {
1049
+ Object.assign(error, value);
1050
+ }
1051
+ return error;
1052
+ }
1053
+ //# sourceMappingURL=agent-harness.js.map