@animalabs/agent-framework 0.22.1 → 0.22.3

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 (946) hide show
  1. package/README.md +4 -2
  2. package/dist/src/agent.d.ts +266 -28
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +539 -104
  5. package/dist/src/agent.js.map +1 -1
  6. package/dist/src/api/mcp-server-core.d.ts +41 -0
  7. package/dist/src/api/mcp-server-core.d.ts.map +1 -0
  8. package/dist/src/api/mcp-server-core.js +593 -0
  9. package/dist/src/api/mcp-server-core.js.map +1 -0
  10. package/dist/src/api/mcp-server.d.ts +2 -36
  11. package/dist/src/api/mcp-server.d.ts.map +1 -1
  12. package/dist/src/api/mcp-server.js +15 -595
  13. package/dist/src/api/mcp-server.js.map +1 -1
  14. package/dist/src/api/server.d.ts +9 -1
  15. package/dist/src/api/server.d.ts.map +1 -1
  16. package/dist/src/api/server.js +55 -27
  17. package/dist/src/api/server.js.map +1 -1
  18. package/dist/src/api/types.d.ts +10 -2
  19. package/dist/src/api/types.d.ts.map +1 -1
  20. package/dist/src/branch-names.d.ts +14 -0
  21. package/dist/src/branch-names.d.ts.map +1 -0
  22. package/dist/src/branch-names.js +22 -0
  23. package/dist/src/branch-names.js.map +1 -0
  24. package/dist/src/closest-names.d.ts +28 -0
  25. package/dist/src/closest-names.d.ts.map +1 -0
  26. package/dist/src/closest-names.js +98 -0
  27. package/dist/src/closest-names.js.map +1 -0
  28. package/dist/src/code-execution/py-runner.d.ts +16 -5
  29. package/dist/src/code-execution/py-runner.d.ts.map +1 -1
  30. package/dist/src/code-execution/py-runner.js +186 -74
  31. package/dist/src/code-execution/py-runner.js.map +1 -1
  32. package/dist/src/code-execution/runtime-py.d.ts.map +1 -1
  33. package/dist/src/code-execution/runtime-py.js +49 -3
  34. package/dist/src/code-execution/runtime-py.js.map +1 -1
  35. package/dist/src/code-execution/tool-definition.d.ts +12 -1
  36. package/dist/src/code-execution/tool-definition.d.ts.map +1 -1
  37. package/dist/src/code-execution/tool-definition.js +21 -3
  38. package/dist/src/code-execution/tool-definition.js.map +1 -1
  39. package/dist/src/config-checks.d.ts +28 -0
  40. package/dist/src/config-checks.d.ts.map +1 -0
  41. package/dist/src/config-checks.js +52 -0
  42. package/dist/src/config-checks.js.map +1 -0
  43. package/dist/src/deadline-timer.d.ts +21 -0
  44. package/dist/src/deadline-timer.d.ts.map +1 -0
  45. package/dist/src/deadline-timer.js +43 -0
  46. package/dist/src/deadline-timer.js.map +1 -0
  47. package/dist/src/error-message.d.ts +30 -0
  48. package/dist/src/error-message.d.ts.map +1 -0
  49. package/dist/src/error-message.js +50 -0
  50. package/dist/src/error-message.js.map +1 -0
  51. package/dist/src/framework.d.ts +1212 -192
  52. package/dist/src/framework.d.ts.map +1 -1
  53. package/dist/src/framework.js +6686 -1835
  54. package/dist/src/framework.js.map +1 -1
  55. package/dist/src/gate/event-gate.d.ts +8 -0
  56. package/dist/src/gate/event-gate.d.ts.map +1 -1
  57. package/dist/src/gate/event-gate.js +27 -3
  58. package/dist/src/gate/event-gate.js.map +1 -1
  59. package/dist/src/gate/gate-script.d.ts.map +1 -1
  60. package/dist/src/gate/gate-script.js.map +1 -1
  61. package/dist/src/index.d.ts +5 -3
  62. package/dist/src/index.d.ts.map +1 -1
  63. package/dist/src/index.js +5 -3
  64. package/dist/src/index.js.map +1 -1
  65. package/dist/src/mcpl/capability-grant.d.ts.map +1 -1
  66. package/dist/src/mcpl/channel-registry.d.ts +170 -13
  67. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  68. package/dist/src/mcpl/channel-registry.js +499 -258
  69. package/dist/src/mcpl/channel-registry.js.map +1 -1
  70. package/dist/src/mcpl/checkpoint-manager.d.ts +21 -1
  71. package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -1
  72. package/dist/src/mcpl/checkpoint-manager.js +91 -30
  73. package/dist/src/mcpl/checkpoint-manager.js.map +1 -1
  74. package/dist/src/mcpl/conversation-router.d.ts +19 -3
  75. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  76. package/dist/src/mcpl/conversation-router.js +23 -8
  77. package/dist/src/mcpl/conversation-router.js.map +1 -1
  78. package/dist/src/mcpl/convert-block.d.ts +20 -0
  79. package/dist/src/mcpl/convert-block.d.ts.map +1 -0
  80. package/dist/src/mcpl/convert-block.js +89 -0
  81. package/dist/src/mcpl/convert-block.js.map +1 -0
  82. package/dist/src/mcpl/errors.d.ts +13 -0
  83. package/dist/src/mcpl/errors.d.ts.map +1 -1
  84. package/dist/src/mcpl/errors.js +28 -0
  85. package/dist/src/mcpl/errors.js.map +1 -1
  86. package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
  87. package/dist/src/mcpl/feature-set-manager.js +4 -3
  88. package/dist/src/mcpl/feature-set-manager.js.map +1 -1
  89. package/dist/src/mcpl/hook-orchestrator.d.ts +23 -0
  90. package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
  91. package/dist/src/mcpl/hook-orchestrator.js +83 -72
  92. package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
  93. package/dist/src/mcpl/inbound-source.d.ts +114 -0
  94. package/dist/src/mcpl/inbound-source.d.ts.map +1 -0
  95. package/dist/src/mcpl/inbound-source.js +83 -0
  96. package/dist/src/mcpl/inbound-source.js.map +1 -0
  97. package/dist/src/mcpl/index.d.ts +3 -1
  98. package/dist/src/mcpl/index.d.ts.map +1 -1
  99. package/dist/src/mcpl/index.js +3 -1
  100. package/dist/src/mcpl/index.js.map +1 -1
  101. package/dist/src/mcpl/inference-router.d.ts +15 -11
  102. package/dist/src/mcpl/inference-router.d.ts.map +1 -1
  103. package/dist/src/mcpl/inference-router.js +153 -84
  104. package/dist/src/mcpl/inference-router.js.map +1 -1
  105. package/dist/src/mcpl/log-value.d.ts +54 -0
  106. package/dist/src/mcpl/log-value.d.ts.map +1 -0
  107. package/dist/src/mcpl/log-value.js +109 -0
  108. package/dist/src/mcpl/log-value.js.map +1 -0
  109. package/dist/src/mcpl/prose-stream-router.d.ts +6 -6
  110. package/dist/src/mcpl/prose-stream-router.d.ts.map +1 -1
  111. package/dist/src/mcpl/prose-stream-router.js +4 -4
  112. package/dist/src/mcpl/prose-stream-router.js.map +1 -1
  113. package/dist/src/mcpl/push-coalescer.d.ts +64 -7
  114. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  115. package/dist/src/mcpl/push-coalescer.js +121 -24
  116. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  117. package/dist/src/mcpl/push-handler.d.ts +38 -8
  118. package/dist/src/mcpl/push-handler.d.ts.map +1 -1
  119. package/dist/src/mcpl/push-handler.js +77 -78
  120. package/dist/src/mcpl/push-handler.js.map +1 -1
  121. package/dist/src/mcpl/reference-fetcher.d.ts +14 -2
  122. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  123. package/dist/src/mcpl/reference-fetcher.js +72 -30
  124. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  125. package/dist/src/mcpl/references.d.ts +49 -14
  126. package/dist/src/mcpl/references.d.ts.map +1 -1
  127. package/dist/src/mcpl/references.js +74 -21
  128. package/dist/src/mcpl/references.js.map +1 -1
  129. package/dist/src/mcpl/refusal-lines.d.ts +37 -0
  130. package/dist/src/mcpl/refusal-lines.d.ts.map +1 -0
  131. package/dist/src/mcpl/refusal-lines.js +61 -0
  132. package/dist/src/mcpl/refusal-lines.js.map +1 -0
  133. package/dist/src/mcpl/scope-manager.d.ts.map +1 -1
  134. package/dist/src/mcpl/server-connection.d.ts +107 -12
  135. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  136. package/dist/src/mcpl/server-connection.js +470 -139
  137. package/dist/src/mcpl/server-connection.js.map +1 -1
  138. package/dist/src/mcpl/server-registry.d.ts +10 -1
  139. package/dist/src/mcpl/server-registry.d.ts.map +1 -1
  140. package/dist/src/mcpl/server-registry.js +14 -3
  141. package/dist/src/mcpl/server-registry.js.map +1 -1
  142. package/dist/src/mcpl/skip-reply-wake.d.ts +36 -0
  143. package/dist/src/mcpl/skip-reply-wake.d.ts.map +1 -0
  144. package/dist/src/mcpl/skip-reply-wake.js +55 -0
  145. package/dist/src/mcpl/skip-reply-wake.js.map +1 -0
  146. package/dist/src/mcpl/tool-classes.d.ts +1 -1
  147. package/dist/src/mcpl/tool-classes.d.ts.map +1 -1
  148. package/dist/src/mcpl/tool-classes.js +3 -2
  149. package/dist/src/mcpl/tool-classes.js.map +1 -1
  150. package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
  151. package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
  152. package/dist/src/mcpl/transport.d.ts +74 -7
  153. package/dist/src/mcpl/transport.d.ts.map +1 -1
  154. package/dist/src/mcpl/transport.js +209 -22
  155. package/dist/src/mcpl/transport.js.map +1 -1
  156. package/dist/src/mcpl/types.d.ts +43 -28
  157. package/dist/src/mcpl/types.d.ts.map +1 -1
  158. package/dist/src/mcpl/types.js.map +1 -1
  159. package/dist/src/mcpl/visible-content.d.ts +15 -0
  160. package/dist/src/mcpl/visible-content.d.ts.map +1 -1
  161. package/dist/src/mcpl/visible-content.js +25 -0
  162. package/dist/src/mcpl/visible-content.js.map +1 -1
  163. package/dist/src/module-registry.d.ts +19 -1
  164. package/dist/src/module-registry.d.ts.map +1 -1
  165. package/dist/src/module-registry.js +54 -25
  166. package/dist/src/module-registry.js.map +1 -1
  167. package/dist/src/modules/api/index.d.ts.map +1 -1
  168. package/dist/src/modules/api/index.js +1 -1
  169. package/dist/src/modules/api/index.js.map +1 -1
  170. package/dist/src/modules/discord/discord-js-client.d.ts +1 -0
  171. package/dist/src/modules/discord/discord-js-client.d.ts.map +1 -1
  172. package/dist/src/modules/discord/discord-js-client.js +25 -9
  173. package/dist/src/modules/discord/discord-js-client.js.map +1 -1
  174. package/dist/src/modules/discord/index.d.ts +29 -3
  175. package/dist/src/modules/discord/index.d.ts.map +1 -1
  176. package/dist/src/modules/discord/index.js +383 -145
  177. package/dist/src/modules/discord/index.js.map +1 -1
  178. package/dist/src/modules/discord/types.d.ts +14 -1
  179. package/dist/src/modules/discord/types.d.ts.map +1 -1
  180. package/dist/src/modules/health/index.d.ts.map +1 -1
  181. package/dist/src/modules/health/index.js +2 -1
  182. package/dist/src/modules/health/index.js.map +1 -1
  183. package/dist/src/modules/history/index.d.ts +3 -1
  184. package/dist/src/modules/history/index.d.ts.map +1 -1
  185. package/dist/src/modules/history/index.js +359 -127
  186. package/dist/src/modules/history/index.js.map +1 -1
  187. package/dist/src/modules/history/semantic.d.ts +28 -1
  188. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  189. package/dist/src/modules/history/semantic.js +177 -32
  190. package/dist/src/modules/history/semantic.js.map +1 -1
  191. package/dist/src/modules/unknown-tool.d.ts +10 -0
  192. package/dist/src/modules/unknown-tool.d.ts.map +1 -0
  193. package/dist/src/modules/unknown-tool.js +17 -0
  194. package/dist/src/modules/unknown-tool.js.map +1 -0
  195. package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
  196. package/dist/src/modules/workspace/branch-intent.js.map +1 -1
  197. package/dist/src/modules/workspace/disk-agreement.d.ts +54 -6
  198. package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -1
  199. package/dist/src/modules/workspace/disk-agreement.js +93 -27
  200. package/dist/src/modules/workspace/disk-agreement.js.map +1 -1
  201. package/dist/src/modules/workspace/effects.d.ts +64 -6
  202. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  203. package/dist/src/modules/workspace/effects.js +291 -44
  204. package/dist/src/modules/workspace/effects.js.map +1 -1
  205. package/dist/src/modules/workspace/index.d.ts +127 -27
  206. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  207. package/dist/src/modules/workspace/index.js +821 -248
  208. package/dist/src/modules/workspace/index.js.map +1 -1
  209. package/dist/src/modules/workspace/observe.d.ts +117 -15
  210. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  211. package/dist/src/modules/workspace/observe.js +436 -51
  212. package/dist/src/modules/workspace/observe.js.map +1 -1
  213. package/dist/src/modules/workspace/reconcile.d.ts +75 -8
  214. package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
  215. package/dist/src/modules/workspace/reconcile.js +576 -68
  216. package/dist/src/modules/workspace/reconcile.js.map +1 -1
  217. package/dist/src/modules/workspace/types.d.ts +42 -3
  218. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  219. package/dist/src/modules/workspace/types.js.map +1 -1
  220. package/dist/src/modules/workspace/watcher.d.ts +7 -2
  221. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  222. package/dist/src/modules/workspace/watcher.js +28 -4
  223. package/dist/src/modules/workspace/watcher.js.map +1 -1
  224. package/dist/src/operator-log.d.ts.map +1 -1
  225. package/dist/src/operator-log.js.map +1 -1
  226. package/dist/src/prose-drafts.d.ts +240 -0
  227. package/dist/src/prose-drafts.d.ts.map +1 -0
  228. package/dist/src/prose-drafts.js +362 -0
  229. package/dist/src/prose-drafts.js.map +1 -0
  230. package/dist/src/prose-segments.d.ts +21 -2
  231. package/dist/src/prose-segments.d.ts.map +1 -1
  232. package/dist/src/prose-segments.js +46 -9
  233. package/dist/src/prose-segments.js.map +1 -1
  234. package/dist/src/provider-waits.d.ts.map +1 -1
  235. package/dist/src/provider-waits.js.map +1 -1
  236. package/dist/src/queue.d.ts.map +1 -1
  237. package/dist/src/record-journal.d.ts.map +1 -1
  238. package/dist/src/record-journal.js.map +1 -1
  239. package/dist/src/recovery/discord-awareness-outbox.d.ts.map +1 -1
  240. package/dist/src/recovery/discord-awareness-outbox.js.map +1 -1
  241. package/dist/src/recovery/offline-branch.d.ts +1 -0
  242. package/dist/src/recovery/offline-branch.d.ts.map +1 -1
  243. package/dist/src/recovery/offline-branch.js +32 -25
  244. package/dist/src/recovery/offline-branch.js.map +1 -1
  245. package/dist/src/recovery/recover-cli.js.map +1 -1
  246. package/dist/src/runtime/liveness-watchdog.d.ts.map +1 -1
  247. package/dist/src/runtime/liveness-watchdog.js.map +1 -1
  248. package/dist/src/safe-slice.d.ts +5 -1
  249. package/dist/src/safe-slice.d.ts.map +1 -1
  250. package/dist/src/safe-slice.js +9 -1
  251. package/dist/src/safe-slice.js.map +1 -1
  252. package/dist/src/shutdown.d.ts.map +1 -1
  253. package/dist/src/shutdown.js.map +1 -1
  254. package/dist/src/stored-removal.d.ts +73 -0
  255. package/dist/src/stored-removal.d.ts.map +1 -0
  256. package/dist/src/stored-removal.js +100 -0
  257. package/dist/src/stored-removal.js.map +1 -0
  258. package/dist/src/thinking-token-stamp.js.map +1 -1
  259. package/dist/src/tool-image-ledger.d.ts +87 -19
  260. package/dist/src/tool-image-ledger.d.ts.map +1 -1
  261. package/dist/src/tool-image-ledger.js +135 -32
  262. package/dist/src/tool-image-ledger.js.map +1 -1
  263. package/dist/src/tool-presentation.d.ts +9 -0
  264. package/dist/src/tool-presentation.d.ts.map +1 -1
  265. package/dist/src/tool-presentation.js +257 -60
  266. package/dist/src/tool-presentation.js.map +1 -1
  267. package/dist/src/tool-result-guard.d.ts.map +1 -1
  268. package/dist/src/tool-result-guard.js +7 -10
  269. package/dist/src/tool-result-guard.js.map +1 -1
  270. package/dist/src/tool-result-history.d.ts +32 -3
  271. package/dist/src/tool-result-history.d.ts.map +1 -1
  272. package/dist/src/tool-result-history.js +106 -19
  273. package/dist/src/tool-result-history.js.map +1 -1
  274. package/dist/src/tune-out/coordinator.d.ts +25 -1
  275. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  276. package/dist/src/tune-out/coordinator.js +260 -65
  277. package/dist/src/tune-out/coordinator.js.map +1 -1
  278. package/dist/src/tune-out/tools.d.ts +1 -1
  279. package/dist/src/tune-out/tools.d.ts.map +1 -1
  280. package/dist/src/types/agent.d.ts +59 -11
  281. package/dist/src/types/agent.d.ts.map +1 -1
  282. package/dist/src/types/events.d.ts +17 -0
  283. package/dist/src/types/events.d.ts.map +1 -1
  284. package/dist/src/types/framework.d.ts +31 -5
  285. package/dist/src/types/framework.d.ts.map +1 -1
  286. package/dist/src/types/inference-log.d.ts +1 -1
  287. package/dist/src/types/inference-log.d.ts.map +1 -1
  288. package/dist/src/types/module.d.ts +30 -7
  289. package/dist/src/types/module.d.ts.map +1 -1
  290. package/dist/src/types/trace.d.ts +151 -11
  291. package/dist/src/types/trace.d.ts.map +1 -1
  292. package/dist/src/usage/usage-tracker.d.ts +5 -0
  293. package/dist/src/usage/usage-tracker.d.ts.map +1 -1
  294. package/dist/src/usage/usage-tracker.js +35 -8
  295. package/dist/src/usage/usage-tracker.js.map +1 -1
  296. package/package.json +10 -9
  297. package/src/agent.ts +572 -105
  298. package/src/api/mcp-server-core.ts +681 -0
  299. package/src/api/mcp-server.ts +16 -685
  300. package/src/api/server.ts +55 -30
  301. package/src/api/types.ts +10 -2
  302. package/src/branch-names.ts +19 -0
  303. package/src/closest-names.ts +94 -0
  304. package/src/code-execution/py-runner.ts +200 -76
  305. package/src/code-execution/runtime-py.ts +49 -3
  306. package/src/code-execution/tool-definition.ts +28 -4
  307. package/src/config-checks.ts +48 -0
  308. package/src/deadline-timer.ts +44 -0
  309. package/src/error-message.ts +48 -0
  310. package/src/framework.ts +7158 -1936
  311. package/src/gate/event-gate.ts +28 -3
  312. package/src/index.ts +12 -3
  313. package/src/mcpl/channel-registry.ts +615 -289
  314. package/src/mcpl/checkpoint-manager.ts +104 -29
  315. package/src/mcpl/conversation-router.ts +28 -8
  316. package/src/mcpl/convert-block.ts +97 -0
  317. package/src/mcpl/errors.ts +28 -0
  318. package/src/mcpl/feature-set-manager.ts +4 -3
  319. package/src/mcpl/hook-orchestrator.ts +84 -77
  320. package/src/mcpl/inbound-source.ts +156 -0
  321. package/src/mcpl/index.ts +10 -1
  322. package/src/mcpl/inference-router.ts +174 -99
  323. package/src/mcpl/log-value.ts +116 -0
  324. package/src/mcpl/prose-stream-router.ts +6 -6
  325. package/src/mcpl/push-coalescer.ts +124 -24
  326. package/src/mcpl/push-handler.ts +86 -84
  327. package/src/mcpl/reference-fetcher.ts +71 -26
  328. package/src/mcpl/references.ts +81 -22
  329. package/src/mcpl/refusal-lines.ts +59 -0
  330. package/src/mcpl/server-connection.ts +496 -142
  331. package/src/mcpl/server-registry.ts +15 -4
  332. package/src/mcpl/skip-reply-wake.ts +73 -0
  333. package/src/mcpl/tool-classes.ts +3 -2
  334. package/src/mcpl/transport.ts +219 -26
  335. package/src/mcpl/types.ts +18 -3
  336. package/src/mcpl/visible-content.ts +27 -0
  337. package/src/module-registry.ts +58 -23
  338. package/src/modules/api/index.ts +1 -1
  339. package/src/modules/discord/discord-js-client.ts +26 -10
  340. package/src/modules/discord/index.ts +395 -160
  341. package/src/modules/discord/types.ts +15 -2
  342. package/src/modules/health/index.ts +2 -1
  343. package/src/modules/history/index.ts +410 -120
  344. package/src/modules/history/semantic.ts +189 -32
  345. package/src/modules/unknown-tool.ts +16 -0
  346. package/src/modules/workspace/disk-agreement.ts +125 -21
  347. package/src/modules/workspace/effects.ts +279 -35
  348. package/src/modules/workspace/index.ts +841 -261
  349. package/src/modules/workspace/observe.ts +456 -56
  350. package/src/modules/workspace/reconcile.ts +688 -76
  351. package/src/modules/workspace/types.ts +41 -2
  352. package/src/modules/workspace/watcher.ts +27 -4
  353. package/src/prose-drafts.ts +481 -0
  354. package/src/prose-segments.ts +51 -8
  355. package/src/recovery/offline-branch.ts +36 -29
  356. package/src/safe-slice.ts +9 -1
  357. package/src/stored-removal.ts +126 -0
  358. package/src/tool-image-ledger.ts +153 -34
  359. package/src/tool-presentation.ts +224 -40
  360. package/src/tool-result-guard.ts +7 -8
  361. package/src/tool-result-history.ts +124 -20
  362. package/src/tune-out/coordinator.ts +259 -65
  363. package/src/types/agent.ts +59 -13
  364. package/src/types/events.ts +17 -0
  365. package/src/types/framework.ts +31 -5
  366. package/src/types/inference-log.ts +1 -1
  367. package/src/types/module.ts +31 -7
  368. package/src/types/trace.ts +158 -12
  369. package/src/usage/usage-tracker.ts +32 -8
  370. package/dist/test/activation-request-sanitize.test.d.ts +0 -2
  371. package/dist/test/activation-request-sanitize.test.d.ts.map +0 -1
  372. package/dist/test/activation-request-sanitize.test.js +0 -89
  373. package/dist/test/activation-request-sanitize.test.js.map +0 -1
  374. package/dist/test/agent-cache-ttl.test.d.ts +0 -2
  375. package/dist/test/agent-cache-ttl.test.d.ts.map +0 -1
  376. package/dist/test/agent-cache-ttl.test.js +0 -41
  377. package/dist/test/agent-cache-ttl.test.js.map +0 -1
  378. package/dist/test/agent-runtime-settings.test.d.ts +0 -2
  379. package/dist/test/agent-runtime-settings.test.d.ts.map +0 -1
  380. package/dist/test/agent-runtime-settings.test.js +0 -462
  381. package/dist/test/agent-runtime-settings.test.js.map +0 -1
  382. package/dist/test/api-admin-gate.test.d.ts +0 -2
  383. package/dist/test/api-admin-gate.test.d.ts.map +0 -1
  384. package/dist/test/api-admin-gate.test.js +0 -116
  385. package/dist/test/api-admin-gate.test.js.map +0 -1
  386. package/dist/test/assistant-persist-refusal.test.d.ts +0 -2
  387. package/dist/test/assistant-persist-refusal.test.d.ts.map +0 -1
  388. package/dist/test/assistant-persist-refusal.test.js +0 -63
  389. package/dist/test/assistant-persist-refusal.test.js.map +0 -1
  390. package/dist/test/batched-wake-locus.test.d.ts +0 -2
  391. package/dist/test/batched-wake-locus.test.d.ts.map +0 -1
  392. package/dist/test/batched-wake-locus.test.js +0 -166
  393. package/dist/test/batched-wake-locus.test.js.map +0 -1
  394. package/dist/test/busy-agent-scheduler.test.d.ts +0 -2
  395. package/dist/test/busy-agent-scheduler.test.d.ts.map +0 -1
  396. package/dist/test/busy-agent-scheduler.test.js +0 -92
  397. package/dist/test/busy-agent-scheduler.test.js.map +0 -1
  398. package/dist/test/channel-incoming-targeting.test.d.ts +0 -2
  399. package/dist/test/channel-incoming-targeting.test.d.ts.map +0 -1
  400. package/dist/test/channel-incoming-targeting.test.js +0 -81
  401. package/dist/test/channel-incoming-targeting.test.js.map +0 -1
  402. package/dist/test/channel-label-history.test.d.ts +0 -2
  403. package/dist/test/channel-label-history.test.d.ts.map +0 -1
  404. package/dist/test/channel-label-history.test.js +0 -424
  405. package/dist/test/channel-label-history.test.js.map +0 -1
  406. package/dist/test/channel-lifecycle-provenance.test.d.ts +0 -2
  407. package/dist/test/channel-lifecycle-provenance.test.d.ts.map +0 -1
  408. package/dist/test/channel-lifecycle-provenance.test.js +0 -47
  409. package/dist/test/channel-lifecycle-provenance.test.js.map +0 -1
  410. package/dist/test/channel-registry-routing.test.d.ts +0 -2
  411. package/dist/test/channel-registry-routing.test.d.ts.map +0 -1
  412. package/dist/test/channel-registry-routing.test.js +0 -446
  413. package/dist/test/channel-registry-routing.test.js.map +0 -1
  414. package/dist/test/channel-registry-typing.test.d.ts +0 -2
  415. package/dist/test/channel-registry-typing.test.d.ts.map +0 -1
  416. package/dist/test/channel-registry-typing.test.js +0 -91
  417. package/dist/test/channel-registry-typing.test.js.map +0 -1
  418. package/dist/test/channels-changed-respond-first.test.d.ts +0 -2
  419. package/dist/test/channels-changed-respond-first.test.d.ts.map +0 -1
  420. package/dist/test/channels-changed-respond-first.test.js +0 -74
  421. package/dist/test/channels-changed-respond-first.test.js.map +0 -1
  422. package/dist/test/checkpoint-attribution.test.d.ts +0 -2
  423. package/dist/test/checkpoint-attribution.test.d.ts.map +0 -1
  424. package/dist/test/checkpoint-attribution.test.js +0 -200
  425. package/dist/test/checkpoint-attribution.test.js.map +0 -1
  426. package/dist/test/code-execution.test.d.ts +0 -11
  427. package/dist/test/code-execution.test.d.ts.map +0 -1
  428. package/dist/test/code-execution.test.js +0 -1272
  429. package/dist/test/code-execution.test.js.map +0 -1
  430. package/dist/test/component-defaults.test.d.ts +0 -2
  431. package/dist/test/component-defaults.test.d.ts.map +0 -1
  432. package/dist/test/component-defaults.test.js +0 -54
  433. package/dist/test/component-defaults.test.js.map +0 -1
  434. package/dist/test/conversation-fork-injection-scoping.test.d.ts +0 -2
  435. package/dist/test/conversation-fork-injection-scoping.test.d.ts.map +0 -1
  436. package/dist/test/conversation-fork-injection-scoping.test.js +0 -200
  437. package/dist/test/conversation-fork-injection-scoping.test.js.map +0 -1
  438. package/dist/test/conversation-router.test.d.ts +0 -2
  439. package/dist/test/conversation-router.test.d.ts.map +0 -1
  440. package/dist/test/conversation-router.test.js +0 -174
  441. package/dist/test/conversation-router.test.js.map +0 -1
  442. package/dist/test/conversation-routing.test.d.ts +0 -7
  443. package/dist/test/conversation-routing.test.d.ts.map +0 -1
  444. package/dist/test/conversation-routing.test.js +0 -387
  445. package/dist/test/conversation-routing.test.js.map +0 -1
  446. package/dist/test/deferred-wake-integrity.test.d.ts +0 -29
  447. package/dist/test/deferred-wake-integrity.test.d.ts.map +0 -1
  448. package/dist/test/deferred-wake-integrity.test.js +0 -320
  449. package/dist/test/deferred-wake-integrity.test.js.map +0 -1
  450. package/dist/test/discord-awareness-outbox.test.d.ts +0 -2
  451. package/dist/test/discord-awareness-outbox.test.d.ts.map +0 -1
  452. package/dist/test/discord-awareness-outbox.test.js +0 -267
  453. package/dist/test/discord-awareness-outbox.test.js.map +0 -1
  454. package/dist/test/discord-history-delete-window.test.d.ts +0 -2
  455. package/dist/test/discord-history-delete-window.test.d.ts.map +0 -1
  456. package/dist/test/discord-history-delete-window.test.js +0 -81
  457. package/dist/test/discord-history-delete-window.test.js.map +0 -1
  458. package/dist/test/discord-history-sync.test.d.ts +0 -2
  459. package/dist/test/discord-history-sync.test.d.ts.map +0 -1
  460. package/dist/test/discord-history-sync.test.js +0 -56
  461. package/dist/test/discord-history-sync.test.js.map +0 -1
  462. package/dist/test/ephemeral-settle.test.d.ts +0 -2
  463. package/dist/test/ephemeral-settle.test.d.ts.map +0 -1
  464. package/dist/test/ephemeral-settle.test.js +0 -354
  465. package/dist/test/ephemeral-settle.test.js.map +0 -1
  466. package/dist/test/event-gate-passthrough.test.d.ts +0 -15
  467. package/dist/test/event-gate-passthrough.test.d.ts.map +0 -1
  468. package/dist/test/event-gate-passthrough.test.js +0 -289
  469. package/dist/test/event-gate-passthrough.test.js.map +0 -1
  470. package/dist/test/event-gate-policy-mutation.test.d.ts +0 -2
  471. package/dist/test/event-gate-policy-mutation.test.d.ts.map +0 -1
  472. package/dist/test/event-gate-policy-mutation.test.js +0 -137
  473. package/dist/test/event-gate-policy-mutation.test.js.map +0 -1
  474. package/dist/test/event-gate-rate-limit.test.d.ts +0 -2
  475. package/dist/test/event-gate-rate-limit.test.d.ts.map +0 -1
  476. package/dist/test/event-gate-rate-limit.test.js +0 -627
  477. package/dist/test/event-gate-rate-limit.test.js.map +0 -1
  478. package/dist/test/event-gate-script.test.d.ts +0 -2
  479. package/dist/test/event-gate-script.test.d.ts.map +0 -1
  480. package/dist/test/event-gate-script.test.js +0 -95
  481. package/dist/test/event-gate-script.test.js.map +0 -1
  482. package/dist/test/event-gate-selfwake.test.d.ts +0 -15
  483. package/dist/test/event-gate-selfwake.test.d.ts.map +0 -1
  484. package/dist/test/event-gate-selfwake.test.js +0 -125
  485. package/dist/test/event-gate-selfwake.test.js.map +0 -1
  486. package/dist/test/event-gate-tags.test.d.ts +0 -2
  487. package/dist/test/event-gate-tags.test.d.ts.map +0 -1
  488. package/dist/test/event-gate-tags.test.js +0 -76
  489. package/dist/test/event-gate-tags.test.js.map +0 -1
  490. package/dist/test/event-gate.test.d.ts +0 -2
  491. package/dist/test/event-gate.test.d.ts.map +0 -1
  492. package/dist/test/event-gate.test.js +0 -919
  493. package/dist/test/event-gate.test.js.map +0 -1
  494. package/dist/test/explicit-prose-routing.test.d.ts +0 -11
  495. package/dist/test/explicit-prose-routing.test.d.ts.map +0 -1
  496. package/dist/test/explicit-prose-routing.test.js +0 -1394
  497. package/dist/test/explicit-prose-routing.test.js.map +0 -1
  498. package/dist/test/framework.test.d.ts +0 -5
  499. package/dist/test/framework.test.d.ts.map +0 -1
  500. package/dist/test/framework.test.js +0 -1048
  501. package/dist/test/framework.test.js.map +0 -1
  502. package/dist/test/gather-context-timeout.test.d.ts +0 -2
  503. package/dist/test/gather-context-timeout.test.d.ts.map +0 -1
  504. package/dist/test/gather-context-timeout.test.js +0 -120
  505. package/dist/test/gather-context-timeout.test.js.map +0 -1
  506. package/dist/test/health-snapshot.test.d.ts +0 -2
  507. package/dist/test/health-snapshot.test.d.ts.map +0 -1
  508. package/dist/test/health-snapshot.test.js +0 -74
  509. package/dist/test/health-snapshot.test.js.map +0 -1
  510. package/dist/test/helpers/coalescing-fixture.d.ts +0 -72
  511. package/dist/test/helpers/coalescing-fixture.d.ts.map +0 -1
  512. package/dist/test/helpers/coalescing-fixture.js +0 -146
  513. package/dist/test/helpers/coalescing-fixture.js.map +0 -1
  514. package/dist/test/helpers/coalescing-kill-child.d.ts +0 -2
  515. package/dist/test/helpers/coalescing-kill-child.d.ts.map +0 -1
  516. package/dist/test/helpers/coalescing-kill-child.js +0 -24
  517. package/dist/test/helpers/coalescing-kill-child.js.map +0 -1
  518. package/dist/test/helpers/mock-membrane.d.ts +0 -53
  519. package/dist/test/helpers/mock-membrane.d.ts.map +0 -1
  520. package/dist/test/helpers/mock-membrane.js +0 -168
  521. package/dist/test/helpers/mock-membrane.js.map +0 -1
  522. package/dist/test/helpers/pytc-stop-rows.d.ts +0 -11
  523. package/dist/test/helpers/pytc-stop-rows.d.ts.map +0 -1
  524. package/dist/test/helpers/pytc-stop-rows.js +0 -143
  525. package/dist/test/helpers/pytc-stop-rows.js.map +0 -1
  526. package/dist/test/helpers/quiesce-crash-child.d.ts +0 -2
  527. package/dist/test/helpers/quiesce-crash-child.d.ts.map +0 -1
  528. package/dist/test/helpers/quiesce-crash-child.js +0 -156
  529. package/dist/test/helpers/quiesce-crash-child.js.map +0 -1
  530. package/dist/test/history-module-overview.test.d.ts +0 -2
  531. package/dist/test/history-module-overview.test.d.ts.map +0 -1
  532. package/dist/test/history-module-overview.test.js +0 -711
  533. package/dist/test/history-module-overview.test.js.map +0 -1
  534. package/dist/test/history-module-realstore.test.d.ts +0 -2
  535. package/dist/test/history-module-realstore.test.d.ts.map +0 -1
  536. package/dist/test/history-module-realstore.test.js +0 -363
  537. package/dist/test/history-module-realstore.test.js.map +0 -1
  538. package/dist/test/history-module-semantic.test.d.ts +0 -2
  539. package/dist/test/history-module-semantic.test.d.ts.map +0 -1
  540. package/dist/test/history-module-semantic.test.js +0 -213
  541. package/dist/test/history-module-semantic.test.js.map +0 -1
  542. package/dist/test/history-module-ux.test.d.ts +0 -2
  543. package/dist/test/history-module-ux.test.d.ts.map +0 -1
  544. package/dist/test/history-module-ux.test.js +0 -304
  545. package/dist/test/history-module-ux.test.js.map +0 -1
  546. package/dist/test/history-module.test.d.ts +0 -2
  547. package/dist/test/history-module.test.d.ts.map +0 -1
  548. package/dist/test/history-module.test.js +0 -619
  549. package/dist/test/history-module.test.js.map +0 -1
  550. package/dist/test/history-semantic-review-findings.test.d.ts +0 -2
  551. package/dist/test/history-semantic-review-findings.test.d.ts.map +0 -1
  552. package/dist/test/history-semantic-review-findings.test.js +0 -338
  553. package/dist/test/history-semantic-review-findings.test.js.map +0 -1
  554. package/dist/test/history-semantic-sync-converges.test.d.ts +0 -2
  555. package/dist/test/history-semantic-sync-converges.test.d.ts.map +0 -1
  556. package/dist/test/history-semantic-sync-converges.test.js +0 -109
  557. package/dist/test/history-semantic-sync-converges.test.js.map +0 -1
  558. package/dist/test/host-quiesce.test.d.ts +0 -2
  559. package/dist/test/host-quiesce.test.d.ts.map +0 -1
  560. package/dist/test/host-quiesce.test.js +0 -863
  561. package/dist/test/host-quiesce.test.js.map +0 -1
  562. package/dist/test/inference-exhaustion-rewind.test.d.ts +0 -2
  563. package/dist/test/inference-exhaustion-rewind.test.d.ts.map +0 -1
  564. package/dist/test/inference-exhaustion-rewind.test.js +0 -309
  565. package/dist/test/inference-exhaustion-rewind.test.js.map +0 -1
  566. package/dist/test/inference-failure-bounds.test.d.ts +0 -2
  567. package/dist/test/inference-failure-bounds.test.d.ts.map +0 -1
  568. package/dist/test/inference-failure-bounds.test.js +0 -1201
  569. package/dist/test/inference-failure-bounds.test.js.map +0 -1
  570. package/dist/test/inference-failure-observability.test.d.ts +0 -2
  571. package/dist/test/inference-failure-observability.test.d.ts.map +0 -1
  572. package/dist/test/inference-failure-observability.test.js +0 -84
  573. package/dist/test/inference-failure-observability.test.js.map +0 -1
  574. package/dist/test/journal-tool.test.d.ts +0 -2
  575. package/dist/test/journal-tool.test.d.ts.map +0 -1
  576. package/dist/test/journal-tool.test.js +0 -33
  577. package/dist/test/journal-tool.test.js.map +0 -1
  578. package/dist/test/kv-unified-open-flight-retry.test.d.ts +0 -2
  579. package/dist/test/kv-unified-open-flight-retry.test.d.ts.map +0 -1
  580. package/dist/test/kv-unified-open-flight-retry.test.js +0 -189
  581. package/dist/test/kv-unified-open-flight-retry.test.js.map +0 -1
  582. package/dist/test/kv-unified-wiring.test.d.ts +0 -2
  583. package/dist/test/kv-unified-wiring.test.d.ts.map +0 -1
  584. package/dist/test/kv-unified-wiring.test.js +0 -95
  585. package/dist/test/kv-unified-wiring.test.js.map +0 -1
  586. package/dist/test/late-events-after-stop.test.d.ts +0 -2
  587. package/dist/test/late-events-after-stop.test.d.ts.map +0 -1
  588. package/dist/test/late-events-after-stop.test.js +0 -122
  589. package/dist/test/late-events-after-stop.test.js.map +0 -1
  590. package/dist/test/liveness-watchdog.test.d.ts +0 -2
  591. package/dist/test/liveness-watchdog.test.d.ts.map +0 -1
  592. package/dist/test/liveness-watchdog.test.js +0 -94
  593. package/dist/test/liveness-watchdog.test.js.map +0 -1
  594. package/dist/test/machine-close-provenance.test.d.ts +0 -2
  595. package/dist/test/machine-close-provenance.test.d.ts.map +0 -1
  596. package/dist/test/machine-close-provenance.test.js +0 -116
  597. package/dist/test/machine-close-provenance.test.js.map +0 -1
  598. package/dist/test/maintenance-timer.test.d.ts +0 -2
  599. package/dist/test/maintenance-timer.test.d.ts.map +0 -1
  600. package/dist/test/maintenance-timer.test.js +0 -265
  601. package/dist/test/maintenance-timer.test.js.map +0 -1
  602. package/dist/test/mcpl-access-provider.test.d.ts +0 -2
  603. package/dist/test/mcpl-access-provider.test.d.ts.map +0 -1
  604. package/dist/test/mcpl-access-provider.test.js +0 -20
  605. package/dist/test/mcpl-access-provider.test.js.map +0 -1
  606. package/dist/test/mcpl-awareness-barrier.test.d.ts +0 -2
  607. package/dist/test/mcpl-awareness-barrier.test.d.ts.map +0 -1
  608. package/dist/test/mcpl-awareness-barrier.test.js +0 -769
  609. package/dist/test/mcpl-awareness-barrier.test.js.map +0 -1
  610. package/dist/test/mcpl-capability-grant.test.d.ts +0 -10
  611. package/dist/test/mcpl-capability-grant.test.d.ts.map +0 -1
  612. package/dist/test/mcpl-capability-grant.test.js +0 -111
  613. package/dist/test/mcpl-capability-grant.test.js.map +0 -1
  614. package/dist/test/mcpl-capability-scoping.test.d.ts +0 -2
  615. package/dist/test/mcpl-capability-scoping.test.d.ts.map +0 -1
  616. package/dist/test/mcpl-capability-scoping.test.js +0 -266
  617. package/dist/test/mcpl-capability-scoping.test.js.map +0 -1
  618. package/dist/test/mcpl-child-env.test.d.ts +0 -2
  619. package/dist/test/mcpl-child-env.test.d.ts.map +0 -1
  620. package/dist/test/mcpl-child-env.test.js +0 -158
  621. package/dist/test/mcpl-child-env.test.js.map +0 -1
  622. package/dist/test/mcpl-coalescing.test.d.ts +0 -2
  623. package/dist/test/mcpl-coalescing.test.d.ts.map +0 -1
  624. package/dist/test/mcpl-coalescing.test.js +0 -1125
  625. package/dist/test/mcpl-coalescing.test.js.map +0 -1
  626. package/dist/test/mcpl-config-diagnostics.test.d.ts +0 -2
  627. package/dist/test/mcpl-config-diagnostics.test.d.ts.map +0 -1
  628. package/dist/test/mcpl-config-diagnostics.test.js +0 -452
  629. package/dist/test/mcpl-config-diagnostics.test.js.map +0 -1
  630. package/dist/test/mcpl-empty-content.test.d.ts +0 -2
  631. package/dist/test/mcpl-empty-content.test.d.ts.map +0 -1
  632. package/dist/test/mcpl-empty-content.test.js +0 -368
  633. package/dist/test/mcpl-empty-content.test.js.map +0 -1
  634. package/dist/test/mcpl-gate-roundtrip.test.d.ts +0 -2
  635. package/dist/test/mcpl-gate-roundtrip.test.d.ts.map +0 -1
  636. package/dist/test/mcpl-gate-roundtrip.test.js +0 -285
  637. package/dist/test/mcpl-gate-roundtrip.test.js.map +0 -1
  638. package/dist/test/mcpl-list-status.test.d.ts +0 -2
  639. package/dist/test/mcpl-list-status.test.d.ts.map +0 -1
  640. package/dist/test/mcpl-list-status.test.js +0 -82
  641. package/dist/test/mcpl-list-status.test.js.map +0 -1
  642. package/dist/test/mcpl-manifest-changed.test.d.ts +0 -2
  643. package/dist/test/mcpl-manifest-changed.test.d.ts.map +0 -1
  644. package/dist/test/mcpl-manifest-changed.test.js +0 -178
  645. package/dist/test/mcpl-manifest-changed.test.js.map +0 -1
  646. package/dist/test/mcpl-push-convert.test.d.ts +0 -2
  647. package/dist/test/mcpl-push-convert.test.d.ts.map +0 -1
  648. package/dist/test/mcpl-push-convert.test.js +0 -42
  649. package/dist/test/mcpl-push-convert.test.js.map +0 -1
  650. package/dist/test/mcpl-reconnect-events.test.d.ts +0 -2
  651. package/dist/test/mcpl-reconnect-events.test.d.ts.map +0 -1
  652. package/dist/test/mcpl-reconnect-events.test.js +0 -144
  653. package/dist/test/mcpl-reconnect-events.test.js.map +0 -1
  654. package/dist/test/mcpl-reconnect-reregistration.test.d.ts +0 -2
  655. package/dist/test/mcpl-reconnect-reregistration.test.d.ts.map +0 -1
  656. package/dist/test/mcpl-reconnect-reregistration.test.js +0 -236
  657. package/dist/test/mcpl-reconnect-reregistration.test.js.map +0 -1
  658. package/dist/test/mcpl-reference-fetcher.test.d.ts +0 -2
  659. package/dist/test/mcpl-reference-fetcher.test.d.ts.map +0 -1
  660. package/dist/test/mcpl-reference-fetcher.test.js +0 -427
  661. package/dist/test/mcpl-reference-fetcher.test.js.map +0 -1
  662. package/dist/test/mcpl-reference-fields.test.d.ts +0 -2
  663. package/dist/test/mcpl-reference-fields.test.d.ts.map +0 -1
  664. package/dist/test/mcpl-reference-fields.test.js +0 -149
  665. package/dist/test/mcpl-reference-fields.test.js.map +0 -1
  666. package/dist/test/mcpl-request-timeout.test.d.ts +0 -2
  667. package/dist/test/mcpl-request-timeout.test.d.ts.map +0 -1
  668. package/dist/test/mcpl-request-timeout.test.js +0 -138
  669. package/dist/test/mcpl-request-timeout.test.js.map +0 -1
  670. package/dist/test/mcpl-runtime-lifecycle.test.d.ts +0 -7
  671. package/dist/test/mcpl-runtime-lifecycle.test.d.ts.map +0 -1
  672. package/dist/test/mcpl-runtime-lifecycle.test.js +0 -142
  673. package/dist/test/mcpl-runtime-lifecycle.test.js.map +0 -1
  674. package/dist/test/mcpl-tool-class-listing.test.d.ts +0 -2
  675. package/dist/test/mcpl-tool-class-listing.test.d.ts.map +0 -1
  676. package/dist/test/mcpl-tool-class-listing.test.js +0 -147
  677. package/dist/test/mcpl-tool-class-listing.test.js.map +0 -1
  678. package/dist/test/mcpl-tool-classes.test.d.ts +0 -7
  679. package/dist/test/mcpl-tool-classes.test.d.ts.map +0 -1
  680. package/dist/test/mcpl-tool-classes.test.js +0 -80
  681. package/dist/test/mcpl-tool-classes.test.js.map +0 -1
  682. package/dist/test/mcpl-tool-lifecycle-e2e.test.d.ts +0 -2
  683. package/dist/test/mcpl-tool-lifecycle-e2e.test.d.ts.map +0 -1
  684. package/dist/test/mcpl-tool-lifecycle-e2e.test.js +0 -237
  685. package/dist/test/mcpl-tool-lifecycle-e2e.test.js.map +0 -1
  686. package/dist/test/mcpl-tool-lifecycle-emitter.test.d.ts +0 -11
  687. package/dist/test/mcpl-tool-lifecycle-emitter.test.d.ts.map +0 -1
  688. package/dist/test/mcpl-tool-lifecycle-emitter.test.js +0 -412
  689. package/dist/test/mcpl-tool-lifecycle-emitter.test.js.map +0 -1
  690. package/dist/test/mcpl-tool-lifecycle-script.test.d.ts +0 -2
  691. package/dist/test/mcpl-tool-lifecycle-script.test.d.ts.map +0 -1
  692. package/dist/test/mcpl-tool-lifecycle-script.test.js +0 -288
  693. package/dist/test/mcpl-tool-lifecycle-script.test.js.map +0 -1
  694. package/dist/test/mcpl-tool-lifecycle.test.d.ts +0 -11
  695. package/dist/test/mcpl-tool-lifecycle.test.d.ts.map +0 -1
  696. package/dist/test/mcpl-tool-lifecycle.test.js +0 -270
  697. package/dist/test/mcpl-tool-lifecycle.test.js.map +0 -1
  698. package/dist/test/mcpl-ws-transport.test.d.ts +0 -2
  699. package/dist/test/mcpl-ws-transport.test.d.ts.map +0 -1
  700. package/dist/test/mcpl-ws-transport.test.js +0 -258
  701. package/dist/test/mcpl-ws-transport.test.js.map +0 -1
  702. package/dist/test/module-context-integration.test.d.ts +0 -18
  703. package/dist/test/module-context-integration.test.d.ts.map +0 -1
  704. package/dist/test/module-context-integration.test.js +0 -181
  705. package/dist/test/module-context-integration.test.js.map +0 -1
  706. package/dist/test/offline-recovery-branch.test.d.ts +0 -2
  707. package/dist/test/offline-recovery-branch.test.d.ts.map +0 -1
  708. package/dist/test/offline-recovery-branch.test.js +0 -226
  709. package/dist/test/offline-recovery-branch.test.js.map +0 -1
  710. package/dist/test/operator-surgery.test.d.ts +0 -2
  711. package/dist/test/operator-surgery.test.d.ts.map +0 -1
  712. package/dist/test/operator-surgery.test.js +0 -398
  713. package/dist/test/operator-surgery.test.js.map +0 -1
  714. package/dist/test/ops-alert.test.d.ts +0 -2
  715. package/dist/test/ops-alert.test.d.ts.map +0 -1
  716. package/dist/test/ops-alert.test.js +0 -153
  717. package/dist/test/ops-alert.test.js.map +0 -1
  718. package/dist/test/overbudget-drain-breaker.test.d.ts +0 -2
  719. package/dist/test/overbudget-drain-breaker.test.d.ts.map +0 -1
  720. package/dist/test/overbudget-drain-breaker.test.js +0 -197
  721. package/dist/test/overbudget-drain-breaker.test.js.map +0 -1
  722. package/dist/test/per-agent-delivery.test.d.ts +0 -2
  723. package/dist/test/per-agent-delivery.test.d.ts.map +0 -1
  724. package/dist/test/per-agent-delivery.test.js +0 -108
  725. package/dist/test/per-agent-delivery.test.js.map +0 -1
  726. package/dist/test/physical-window-restart.test.d.ts +0 -14
  727. package/dist/test/physical-window-restart.test.d.ts.map +0 -1
  728. package/dist/test/physical-window-restart.test.js +0 -222
  729. package/dist/test/physical-window-restart.test.js.map +0 -1
  730. package/dist/test/placed-reaction-baseline.test.d.ts +0 -2
  731. package/dist/test/placed-reaction-baseline.test.d.ts.map +0 -1
  732. package/dist/test/placed-reaction-baseline.test.js +0 -312
  733. package/dist/test/placed-reaction-baseline.test.js.map +0 -1
  734. package/dist/test/present-while-acting.test.d.ts +0 -19
  735. package/dist/test/present-while-acting.test.d.ts.map +0 -1
  736. package/dist/test/present-while-acting.test.js +0 -706
  737. package/dist/test/present-while-acting.test.js.map +0 -1
  738. package/dist/test/prose-segments.test.d.ts +0 -2
  739. package/dist/test/prose-segments.test.d.ts.map +0 -1
  740. package/dist/test/prose-segments.test.js +0 -52
  741. package/dist/test/prose-segments.test.js.map +0 -1
  742. package/dist/test/prose-stream-router.test.d.ts +0 -2
  743. package/dist/test/prose-stream-router.test.d.ts.map +0 -1
  744. package/dist/test/prose-stream-router.test.js +0 -171
  745. package/dist/test/prose-stream-router.test.js.map +0 -1
  746. package/dist/test/provider-acceleration-cooldown.test.d.ts +0 -2
  747. package/dist/test/provider-acceleration-cooldown.test.d.ts.map +0 -1
  748. package/dist/test/provider-acceleration-cooldown.test.js +0 -435
  749. package/dist/test/provider-acceleration-cooldown.test.js.map +0 -1
  750. package/dist/test/provider-waits.test.d.ts +0 -2
  751. package/dist/test/provider-waits.test.d.ts.map +0 -1
  752. package/dist/test/provider-waits.test.js +0 -2196
  753. package/dist/test/provider-waits.test.js.map +0 -1
  754. package/dist/test/puppet-tool-call.test.d.ts +0 -2
  755. package/dist/test/puppet-tool-call.test.d.ts.map +0 -1
  756. package/dist/test/puppet-tool-call.test.js +0 -224
  757. package/dist/test/puppet-tool-call.test.js.map +0 -1
  758. package/dist/test/puppet-turn-reservation.test.d.ts +0 -2
  759. package/dist/test/puppet-turn-reservation.test.d.ts.map +0 -1
  760. package/dist/test/puppet-turn-reservation.test.js +0 -139
  761. package/dist/test/puppet-turn-reservation.test.js.map +0 -1
  762. package/dist/test/reaction-baseline-platform.test.d.ts +0 -2
  763. package/dist/test/reaction-baseline-platform.test.d.ts.map +0 -1
  764. package/dist/test/reaction-baseline-platform.test.js +0 -124
  765. package/dist/test/reaction-baseline-platform.test.js.map +0 -1
  766. package/dist/test/record-journal.test.d.ts +0 -6
  767. package/dist/test/record-journal.test.d.ts.map +0 -1
  768. package/dist/test/record-journal.test.js +0 -269
  769. package/dist/test/record-journal.test.js.map +0 -1
  770. package/dist/test/refusal-reaction-baseline.test.d.ts +0 -2
  771. package/dist/test/refusal-reaction-baseline.test.d.ts.map +0 -1
  772. package/dist/test/refusal-reaction-baseline.test.js +0 -81
  773. package/dist/test/refusal-reaction-baseline.test.js.map +0 -1
  774. package/dist/test/refusal-rewind.test.d.ts +0 -2
  775. package/dist/test/refusal-rewind.test.d.ts.map +0 -1
  776. package/dist/test/refusal-rewind.test.js +0 -108
  777. package/dist/test/refusal-rewind.test.js.map +0 -1
  778. package/dist/test/refusal-single-call.test.d.ts +0 -2
  779. package/dist/test/refusal-single-call.test.d.ts.map +0 -1
  780. package/dist/test/refusal-single-call.test.js +0 -177
  781. package/dist/test/refusal-single-call.test.js.map +0 -1
  782. package/dist/test/release-changelog.test.d.ts +0 -2
  783. package/dist/test/release-changelog.test.d.ts.map +0 -1
  784. package/dist/test/release-changelog.test.js +0 -159
  785. package/dist/test/release-changelog.test.js.map +0 -1
  786. package/dist/test/same-round-think-policy.test.d.ts +0 -2
  787. package/dist/test/same-round-think-policy.test.d.ts.map +0 -1
  788. package/dist/test/same-round-think-policy.test.js +0 -853
  789. package/dist/test/same-round-think-policy.test.js.map +0 -1
  790. package/dist/test/save-recent-image.test.d.ts +0 -26
  791. package/dist/test/save-recent-image.test.d.ts.map +0 -1
  792. package/dist/test/save-recent-image.test.js +0 -974
  793. package/dist/test/save-recent-image.test.js.map +0 -1
  794. package/dist/test/shutdown-errors.test.d.ts +0 -2
  795. package/dist/test/shutdown-errors.test.d.ts.map +0 -1
  796. package/dist/test/shutdown-errors.test.js +0 -662
  797. package/dist/test/shutdown-errors.test.js.map +0 -1
  798. package/dist/test/silent-heartbeat-rows.test.d.ts +0 -2
  799. package/dist/test/silent-heartbeat-rows.test.d.ts.map +0 -1
  800. package/dist/test/silent-heartbeat-rows.test.js +0 -451
  801. package/dist/test/silent-heartbeat-rows.test.js.map +0 -1
  802. package/dist/test/silent-heartbeat.test.d.ts +0 -2
  803. package/dist/test/silent-heartbeat.test.d.ts.map +0 -1
  804. package/dist/test/silent-heartbeat.test.js +0 -165
  805. package/dist/test/silent-heartbeat.test.js.map +0 -1
  806. package/dist/test/state-scaling-e2e.test.d.ts +0 -22
  807. package/dist/test/state-scaling-e2e.test.d.ts.map +0 -1
  808. package/dist/test/state-scaling-e2e.test.js +0 -206
  809. package/dist/test/state-scaling-e2e.test.js.map +0 -1
  810. package/dist/test/state-scaling.test.d.ts +0 -12
  811. package/dist/test/state-scaling.test.d.ts.map +0 -1
  812. package/dist/test/state-scaling.test.js +0 -251
  813. package/dist/test/state-scaling.test.js.map +0 -1
  814. package/dist/test/stop-with-work-in-flight.test.d.ts +0 -23
  815. package/dist/test/stop-with-work-in-flight.test.d.ts.map +0 -1
  816. package/dist/test/stop-with-work-in-flight.test.js +0 -672
  817. package/dist/test/stop-with-work-in-flight.test.js.map +0 -1
  818. package/dist/test/surgery-marks-receipt.test.d.ts +0 -2
  819. package/dist/test/surgery-marks-receipt.test.d.ts.map +0 -1
  820. package/dist/test/surgery-marks-receipt.test.js +0 -540
  821. package/dist/test/surgery-marks-receipt.test.js.map +0 -1
  822. package/dist/test/thinking-token-stamp.test.d.ts +0 -12
  823. package/dist/test/thinking-token-stamp.test.d.ts.map +0 -1
  824. package/dist/test/thinking-token-stamp.test.js +0 -129
  825. package/dist/test/thinking-token-stamp.test.js.map +0 -1
  826. package/dist/test/timezone.test.d.ts +0 -2
  827. package/dist/test/timezone.test.d.ts.map +0 -1
  828. package/dist/test/timezone.test.js +0 -18
  829. package/dist/test/timezone.test.js.map +0 -1
  830. package/dist/test/tool-batch-hook.test.d.ts +0 -8
  831. package/dist/test/tool-batch-hook.test.d.ts.map +0 -1
  832. package/dist/test/tool-batch-hook.test.js +0 -275
  833. package/dist/test/tool-batch-hook.test.js.map +0 -1
  834. package/dist/test/tool-policy.test.d.ts +0 -2
  835. package/dist/test/tool-policy.test.d.ts.map +0 -1
  836. package/dist/test/tool-policy.test.js +0 -51
  837. package/dist/test/tool-policy.test.js.map +0 -1
  838. package/dist/test/tool-presentation.test.d.ts +0 -2
  839. package/dist/test/tool-presentation.test.d.ts.map +0 -1
  840. package/dist/test/tool-presentation.test.js +0 -268
  841. package/dist/test/tool-presentation.test.js.map +0 -1
  842. package/dist/test/tool-result-content.test.d.ts +0 -2
  843. package/dist/test/tool-result-content.test.d.ts.map +0 -1
  844. package/dist/test/tool-result-content.test.js +0 -37
  845. package/dist/test/tool-result-content.test.js.map +0 -1
  846. package/dist/test/tool-result-guard.test.d.ts +0 -2
  847. package/dist/test/tool-result-guard.test.d.ts.map +0 -1
  848. package/dist/test/tool-result-guard.test.js +0 -3607
  849. package/dist/test/tool-result-guard.test.js.map +0 -1
  850. package/dist/test/tool-result-history.test.d.ts +0 -7
  851. package/dist/test/tool-result-history.test.d.ts.map +0 -1
  852. package/dist/test/tool-result-history.test.js +0 -156
  853. package/dist/test/tool-result-history.test.js.map +0 -1
  854. package/dist/test/tool-result-spill.test.d.ts +0 -13
  855. package/dist/test/tool-result-spill.test.d.ts.map +0 -1
  856. package/dist/test/tool-result-spill.test.js +0 -586
  857. package/dist/test/tool-result-spill.test.js.map +0 -1
  858. package/dist/test/tool-wrapper-prose-guard-integration.test.d.ts +0 -2
  859. package/dist/test/tool-wrapper-prose-guard-integration.test.d.ts.map +0 -1
  860. package/dist/test/tool-wrapper-prose-guard-integration.test.js +0 -485
  861. package/dist/test/tool-wrapper-prose-guard-integration.test.js.map +0 -1
  862. package/dist/test/tool-wrapper-prose-guard.test.d.ts +0 -2
  863. package/dist/test/tool-wrapper-prose-guard.test.d.ts.map +0 -1
  864. package/dist/test/tool-wrapper-prose-guard.test.js +0 -34
  865. package/dist/test/tool-wrapper-prose-guard.test.js.map +0 -1
  866. package/dist/test/tools-observe-parser-conformance.test.d.ts +0 -2
  867. package/dist/test/tools-observe-parser-conformance.test.d.ts.map +0 -1
  868. package/dist/test/tools-observe-parser-conformance.test.js +0 -129
  869. package/dist/test/tools-observe-parser-conformance.test.js.map +0 -1
  870. package/dist/test/trunk-channel-routing.test.d.ts +0 -19
  871. package/dist/test/trunk-channel-routing.test.d.ts.map +0 -1
  872. package/dist/test/trunk-channel-routing.test.js +0 -329
  873. package/dist/test/trunk-channel-routing.test.js.map +0 -1
  874. package/dist/test/tune-out-e2e.test.d.ts +0 -2
  875. package/dist/test/tune-out-e2e.test.d.ts.map +0 -1
  876. package/dist/test/tune-out-e2e.test.js +0 -142
  877. package/dist/test/tune-out-e2e.test.js.map +0 -1
  878. package/dist/test/tune-out-gate-composition.test.d.ts +0 -2
  879. package/dist/test/tune-out-gate-composition.test.d.ts.map +0 -1
  880. package/dist/test/tune-out-gate-composition.test.js +0 -221
  881. package/dist/test/tune-out-gate-composition.test.js.map +0 -1
  882. package/dist/test/tune-out-lifecycle.test.d.ts +0 -2
  883. package/dist/test/tune-out-lifecycle.test.d.ts.map +0 -1
  884. package/dist/test/tune-out-lifecycle.test.js +0 -121
  885. package/dist/test/tune-out-lifecycle.test.js.map +0 -1
  886. package/dist/test/turn-trigger-provenance.test.d.ts +0 -2
  887. package/dist/test/turn-trigger-provenance.test.d.ts.map +0 -1
  888. package/dist/test/turn-trigger-provenance.test.js +0 -137
  889. package/dist/test/turn-trigger-provenance.test.js.map +0 -1
  890. package/dist/test/unconvertible-tool-result.test.d.ts +0 -2
  891. package/dist/test/unconvertible-tool-result.test.d.ts.map +0 -1
  892. package/dist/test/unconvertible-tool-result.test.js +0 -358
  893. package/dist/test/unconvertible-tool-result.test.js.map +0 -1
  894. package/dist/test/usage-accounting.test.d.ts +0 -2
  895. package/dist/test/usage-accounting.test.d.ts.map +0 -1
  896. package/dist/test/usage-accounting.test.js +0 -13
  897. package/dist/test/usage-accounting.test.js.map +0 -1
  898. package/dist/test/usage-tracker.test.d.ts +0 -2
  899. package/dist/test/usage-tracker.test.d.ts.map +0 -1
  900. package/dist/test/usage-tracker.test.js +0 -129
  901. package/dist/test/usage-tracker.test.js.map +0 -1
  902. package/dist/test/utils-surface.test.d.ts +0 -2
  903. package/dist/test/utils-surface.test.d.ts.map +0 -1
  904. package/dist/test/utils-surface.test.js +0 -145
  905. package/dist/test/utils-surface.test.js.map +0 -1
  906. package/dist/test/workspace-branch-continuation.test.d.ts +0 -15
  907. package/dist/test/workspace-branch-continuation.test.d.ts.map +0 -1
  908. package/dist/test/workspace-branch-continuation.test.js +0 -183
  909. package/dist/test/workspace-branch-continuation.test.js.map +0 -1
  910. package/dist/test/workspace-materialize-freshness.test.d.ts +0 -16
  911. package/dist/test/workspace-materialize-freshness.test.d.ts.map +0 -1
  912. package/dist/test/workspace-materialize-freshness.test.js +0 -252
  913. package/dist/test/workspace-materialize-freshness.test.js.map +0 -1
  914. package/dist/test/workspace-path-containment.test.d.ts +0 -19
  915. package/dist/test/workspace-path-containment.test.d.ts.map +0 -1
  916. package/dist/test/workspace-path-containment.test.js +0 -91
  917. package/dist/test/workspace-path-containment.test.js.map +0 -1
  918. package/dist/test/workspace-read-file-from-disk.test.d.ts +0 -17
  919. package/dist/test/workspace-read-file-from-disk.test.d.ts.map +0 -1
  920. package/dist/test/workspace-read-file-from-disk.test.js +0 -174
  921. package/dist/test/workspace-read-file-from-disk.test.js.map +0 -1
  922. package/dist/test/workspace-read-image.test.d.ts +0 -2
  923. package/dist/test/workspace-read-image.test.d.ts.map +0 -1
  924. package/dist/test/workspace-read-image.test.js +0 -597
  925. package/dist/test/workspace-read-image.test.js.map +0 -1
  926. package/dist/test/workspace-read-text.test.d.ts +0 -2
  927. package/dist/test/workspace-read-text.test.d.ts.map +0 -1
  928. package/dist/test/workspace-read-text.test.js +0 -101
  929. package/dist/test/workspace-read-text.test.js.map +0 -1
  930. package/dist/test/workspace-restore-order.test.d.ts +0 -16
  931. package/dist/test/workspace-restore-order.test.d.ts.map +0 -1
  932. package/dist/test/workspace-restore-order.test.js +0 -140
  933. package/dist/test/workspace-restore-order.test.js.map +0 -1
  934. package/dist/test/workspace-three-way.test.d.ts +0 -12
  935. package/dist/test/workspace-three-way.test.d.ts.map +0 -1
  936. package/dist/test/workspace-three-way.test.js +0 -3194
  937. package/dist/test/workspace-three-way.test.js.map +0 -1
  938. package/dist/test/workspace-watcher.test.d.ts +0 -2
  939. package/dist/test/workspace-watcher.test.d.ts.map +0 -1
  940. package/dist/test/workspace-watcher.test.js +0 -281
  941. package/dist/test/workspace-watcher.test.js.map +0 -1
  942. package/dist/test/xml-round-persist.test.d.ts +0 -19
  943. package/dist/test/xml-round-persist.test.d.ts.map +0 -1
  944. package/dist/test/xml-round-persist.test.js +0 -235
  945. package/dist/test/xml-round-persist.test.js.map +0 -1
  946. package/dist/tsconfig.tsbuildinfo +0 -1
package/src/agent.ts CHANGED
@@ -3,6 +3,7 @@ import { isAbortedResponse } from '@animalabs/membrane';
3
3
  import { createHash } from 'node:crypto';
4
4
  import type { CacheWireReceipt, KvUnifiedRequestHooks } from './kv-unified-wire.js';
5
5
  import { ToolResultGuard } from './tool-result-guard.js';
6
+ import { assertBooleanSetting, holdsSettings } from './config-checks.js';
6
7
  import {
7
8
  indexSilentTickRows,
8
9
  separateSilentHeartbeatTicks,
@@ -20,6 +21,9 @@ import {
20
21
  export interface ActivationRequestOptions {
21
22
  /** The silent heartbeat tick this request answers, if any. */
22
23
  silentHeartbeat?: SilentHeartbeatTick;
24
+ /** A request that will never be sent (a preview): compile it as a dry
25
+ * run (see `compileWithInjections` for what that leaves alone). */
26
+ dryRun?: boolean;
23
27
  }
24
28
 
25
29
  export interface StartStreamResult {
@@ -72,6 +76,53 @@ const DEFAULT_CONTEXT_BUDGET_TOKENS = 100_000;
72
76
  const DEFAULT_TRANSITION_PACE_TOKENS = 16_000;
73
77
  const DEFAULT_SAME_ROUND_THINK_TEXT_POLICY: SameRoundThinkTextPolicy = 'public';
74
78
 
79
+ /**
80
+ * Refuse an agent config whose `promptCaching`, `toolResultGuard`,
81
+ * `toolWrapperProseGuard`, `thinking.enabled` or `refusalHandling.autoRewind`
82
+ * holds anything but true or false (assertBooleanSetting), or whose `thinking`
83
+ * or `refusalHandling` is anything but an object, null or false
84
+ * (holdsSettings). The constructor runs it first, so the rule holds wherever
85
+ * an Agent is built. `create()` also runs it for each of its agents before
86
+ * anything opens, and `createEphemeralAgent` before it reserves the name, so a
87
+ * refusal there leaves nothing behind. Membrane reads `thinking.enabled`, and
88
+ * the refusal is here because the setting is AgentConfig's.
89
+ */
90
+ export function assertAgentSwitches(config: AgentConfig): void {
91
+ const agent = `Agent "${config.name}"`;
92
+ assertBooleanSetting(
93
+ `${agent} promptCaching`,
94
+ config.promptCaching,
95
+ 'true or leaving it out marks requests for prompt caching, and false leaves the markers off, for transports that refuse them',
96
+ );
97
+ if (holdsSettings(`${agent} thinking`, config.thinking, '{ enabled: true }')) {
98
+ assertBooleanSetting(
99
+ `${agent} thinking.enabled`,
100
+ config.thinking.enabled,
101
+ 'true asks the provider for extended thinking, and false or leaving it out doesn\'t',
102
+ );
103
+ }
104
+ if (holdsSettings(`${agent} refusalHandling`, config.refusalHandling, '{ autoRewind: true }')) {
105
+ assertBooleanSetting(
106
+ `${agent} refusalHandling.autoRewind`,
107
+ config.refusalHandling.autoRewind,
108
+ 'true redacts the turn that tripped a refusal and runs again, up to maxRewinds times, ' +
109
+ 'and false or leaving it out doesn\'t',
110
+ );
111
+ }
112
+ assertBooleanSetting(
113
+ `${agent} toolResultGuard`,
114
+ config.toolResultGuard,
115
+ 'true turns on tool-output admission, with one guarded retry after a provider refusal, ' +
116
+ 'and false or leaving it out doesn\'t',
117
+ );
118
+ assertBooleanSetting(
119
+ `${agent} toolWrapperProseGuard`,
120
+ config.toolWrapperProseGuard,
121
+ 'true keeps a response whose whole prose is a tool-call-shaped wrapper from running or entering the agent\'s history, ' +
122
+ 'and false or leaving it out doesn\'t',
123
+ );
124
+ }
125
+
75
126
  /**
76
127
  * An agent wraps a context manager and manages inference state.
77
128
  */
@@ -120,15 +171,38 @@ export class Agent {
120
171
  * closure) so the next activation can close whatever its predecessor left
121
172
  * open — see failOpenKvSubmissions. */
122
173
  private kvOpenQueue: Array<{ submissionId: string; wireReceipt: CacheWireReceipt }> | null = null;
174
+ /** The current stream's fresh input so far, as membrane's usage event
175
+ * reports it (cumulative across the tool loop): what the maxStreamTokens
176
+ * budget checks. */
123
177
  lastStreamInputTokens = 0;
124
- /** Real prefix size of the last usage event: fresh + cache creation +
125
- * cache read. THE window-shaped number — `lastStreamInputTokens` alone
126
- * omits cached tokens, which are most of a warm stream's window. */
178
+ /** Real prompt size of the stream's latest provider call that reported a
179
+ * prompt, which is what the provider billed it: fresh + cache creation +
180
+ * cache read. A call that reports none leaves it as it was (see
181
+ * lastStreamUnreportedTokens). Membrane's usage events are cumulative, so
182
+ * this is the call's share of its event (cumulativeDelta): the whole event
183
+ * for a stream's first call, and the event's own value where a counter
184
+ * went back. THE window-shaped number — `lastStreamInputTokens` alone
185
+ * omits cached tokens, which are most of a warm stream's window. 0 until a
186
+ * call on this stream reports a prompt, and the physical-window
187
+ * projection runs only once one has. */
127
188
  lastStreamRealInputTokens = 0;
128
- /** Output tokens of the last usage event — the prior round's generated
129
- * thinking/text/tool_use, which becomes part of the NEXT round's input
130
- * and so belongs in the physical-window projection. */
189
+ /** Output tokens of the same call as lastStreamRealInputTokens, or
190
+ * maxTokens, the bound on them, when it reported none (a call that ends at
191
+ * a tool boundary wrote a tool_use, so a 0 is a count left unreported) —
192
+ * the prior round's generated thinking/text/tool_use, which becomes part
193
+ * of the NEXT round's input and so belongs in the physical-window
194
+ * projection. */
131
195
  lastStreamOutputTokens = 0;
196
+ /** What the stream has grown by since the call lastStreamRealInputTokens
197
+ * describes, for the physical-window projection: the blocks appended at
198
+ * each boundary the stream continued past (counted only for an agent with
199
+ * physicalWindowTokens, whose projection is this field's one reader), and
200
+ * the output of each call that reported no prompt (its reported output,
201
+ * or maxTokens, the bound on it, when it reported none either). After
202
+ * calls that report no prompt, the next request holds the prompt and
203
+ * output of the call lastStreamRealInputTokens describes, plus this. 0 at
204
+ * stream start and whenever a call reports a prompt. */
205
+ lastStreamUnreportedTokens = 0;
132
206
  maxStreamTokens: number;
133
207
  /** Provider hard context cap (see AgentConfig.physicalWindowTokens). */
134
208
  readonly physicalWindowTokens?: number;
@@ -141,7 +215,52 @@ export class Agent {
141
215
  private readonly configuredTransitionPaceTokens?: number;
142
216
  private readonly configuredSameRoundThinkTextPolicy?: SameRoundThinkTextPolicy;
143
217
  private contextBudgetTargetTokens?: number;
144
- private runtimeSettingsOverrides: AgentRuntimeSettingsOverrides = {};
218
+ private runtimeSettingsOverrides: AgentRuntimeSettingsPatch = {};
219
+ /**
220
+ * Counts changes of the live budget (an update, a reset, a restore, a
221
+ * settle). A compile speaks for the budget it planned at only if the live
222
+ * budget didn't change while it ran, and what it showed stands only until
223
+ * the next change.
224
+ */
225
+ private liveBudgetEpoch = 0;
226
+ /**
227
+ * Counts changes of the descent (each arm of one, the same target included,
228
+ * a reset, a cancel, a settle). A settle proves its target only to a
229
+ * compile that began under that same descent.
230
+ */
231
+ private descentEpoch = 0;
232
+ /** The live budget the last compile planned at, whether it fit, and the live budget's epoch then. */
233
+ private lastCompiledBudget?: { budget: number; fit: boolean; epoch: number };
234
+ /** Counts compiles at the live budget as they start. */
235
+ private compilesStarted = 0;
236
+ /** The start numbers of the compiles at the live budget still running. */
237
+ private readonly compilesRunning = new Set<number>();
238
+ /**
239
+ * For each budget, the start of the latest-started compile that has ended
240
+ * there with a fit or a refusal, whether or not what it showed was
241
+ * credited. Of two compiles at one budget, the later-started one planned
242
+ * at the newer store, so an earlier-started one that ends after it is
243
+ * ignored. That rests on the context manager selecting at the start of
244
+ * `compile`, before anything it awaits, so start order is selection order;
245
+ * a context manager that awaits before its select breaks it. (Injections
246
+ * are added after the select, so compiles with and without them plan
247
+ * alike.) An entry is
248
+ * kept only while a compile that started before it is still running, the
249
+ * only kind it can turn away, so the map is empty whenever no compile
250
+ * runs.
251
+ */
252
+ private readonly latestEndedStart = new Map<number, number>();
253
+ /** The last outcome the listener recorded; a failed record is told again, and so is any after a change. */
254
+ private recordedCompiledBudget?: { budget: number; fit: boolean; epoch: number };
255
+ /**
256
+ * A boot restore applied a proven budget below the live one at once. Until
257
+ * the budget is next written (an update that carries one, or a reset of
258
+ * it) or a compile at it fits, a refusal of a compile at it restores it
259
+ * paced instead.
260
+ */
261
+ private restoredAtOnce = false;
262
+ /** Told when that changes (the framework records it beside the persisted budget). */
263
+ private compiledBudgetListener?: (budget: number, fit: boolean) => boolean;
145
264
  private contextManager: ContextManager;
146
265
  private membrane: Membrane;
147
266
 
@@ -150,6 +269,7 @@ export class Agent {
150
269
  contextManager: ContextManager,
151
270
  membrane: Membrane
152
271
  ) {
272
+ assertAgentSwitches(config);
153
273
  this.name = config.name;
154
274
  this.model = config.model;
155
275
  this.systemPrompt = config.systemPrompt;
@@ -159,11 +279,11 @@ export class Agent {
159
279
  this.temperature = config.temperature;
160
280
  this.thinking = config.thinking;
161
281
  this.refusalHandling = config.refusalHandling;
162
- this.toolResultGuard = new ToolResultGuard(config.name, contextManager, config.toolResultGuard);
282
+ this.toolResultGuard = new ToolResultGuard(config.name, contextManager, config.toolResultGuard === true);
163
283
  this.proseRouting = config.proseRouting ?? 'locus';
164
- this.toolWrapperProseGuard = config.toolWrapperProseGuard ?? false;
284
+ this.toolWrapperProseGuard = config.toolWrapperProseGuard === true;
165
285
  this.cacheTtl = config.cacheTtl ?? '1h';
166
- this.promptCaching = config.promptCaching ?? true;
286
+ this.promptCaching = config.promptCaching !== false;
167
287
  this.prefillUserMessage = config.prefillUserMessage;
168
288
  this.providerParams = config.providerParams;
169
289
  this.sameRoundThinkTextPolicy = config.sameRoundThinkTextPolicy;
@@ -280,10 +400,16 @@ export class Agent {
280
400
  getRuntimeSettings(): AgentRuntimeSettingsSnapshot {
281
401
  const hot = this.getHotContextSettings();
282
402
  return {
403
+ // The budget it's set to: the override, where there is one. That is
404
+ // the target of a descent toward it, or else the live budget, except
405
+ // while it's kept unapplied: at boot (keepRuntimeSettings), or after a
406
+ // refused at-once budget couldn't be restored paced (compileAtLiveBudget).
283
407
  contextBudgetTokens:
408
+ this.runtimeSettingsOverrides.contextBudgetTokens ??
284
409
  this.contextBudgetTargetTokens ??
285
410
  this.contextBudgetTokens ??
286
411
  DEFAULT_CONTEXT_BUDGET_TOKENS,
412
+ effectiveContextBudgetTokens: this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS,
287
413
  ...(hot ? { tailTokens: hot.tailTokens } : {}),
288
414
  ...(hot?.transitionPaceTokens !== undefined
289
415
  ? { transitionPaceTokens: hot.transitionPaceTokens }
@@ -307,6 +433,179 @@ export class Agent {
307
433
  return { ...this.runtimeSettingsOverrides };
308
434
  }
309
435
 
436
+ /**
437
+ * Set (or clear) the one listener told when a compile at the live budget
438
+ * comes out differently from the last: it fit at a budget the last one
439
+ * didn't plan at (after a settle, the target), or the context manager
440
+ * refused a budget the last one fit at.
441
+ */
442
+ onContextBudgetCompiled(listener: ((budget: number, fit: boolean) => boolean) | undefined): void {
443
+ this.compiledBudgetListener = listener;
444
+ }
445
+
446
+ /**
447
+ * The live budget the last compile planned at and fit, if it fit and the
448
+ * live budget hasn't changed since.
449
+ */
450
+ getProvenContextBudgetTokens(): number | undefined {
451
+ const last = this.lastCompiledBudget;
452
+ return last?.fit && last.epoch === this.liveBudgetEpoch ? last.budget : undefined;
453
+ }
454
+
455
+ /**
456
+ * Set the live budget and the descent target, counting a change of each.
457
+ * `armed` counts a descent armed here as a change even when its target is
458
+ * the one already set: a compile that began under the earlier arm isn't
459
+ * credited with this one's settle.
460
+ */
461
+ private setContextBudget(budget: number | undefined, target: number | undefined, armed = false): void {
462
+ if (budget !== this.contextBudgetTokens) this.liveBudgetEpoch++;
463
+ if (armed || target !== this.contextBudgetTargetTokens) this.descentEpoch++;
464
+ this.contextBudgetTokens = budget;
465
+ this.contextBudgetTargetTokens = target;
466
+ }
467
+
468
+ /**
469
+ * Claim the place of the latest compile to end at `budget` for the one that
470
+ * started as the `started`th, and say whether it got it: a compile that
471
+ * started before one that has already ended there is ignored, whichever
472
+ * finishes last.
473
+ */
474
+ private claimLatestAt(budget: number, started: number): boolean {
475
+ if (started < (this.latestEndedStart.get(budget) ?? 0)) return false;
476
+ this.latestEndedStart.set(budget, started);
477
+ return true;
478
+ }
479
+
480
+ /**
481
+ * Note what a compile at `budget`, planned at the live budget's `epoch`,
482
+ * showed. It speaks for the live budget only if that hasn't changed since;
483
+ * the listener is told either way, so a refusal withdraws the record's
484
+ * marker for the budget it planned at whatever changed meanwhile.
485
+ */
486
+ private noteCompiledBudget(budget: number, fit: boolean, epoch: number): void {
487
+ if (epoch === this.liveBudgetEpoch) this.lastCompiledBudget = { budget, fit, epoch };
488
+ const recorded = this.recordedCompiledBudget;
489
+ if (recorded?.budget === budget && recorded.fit === fit && recorded.epoch === epoch) return;
490
+ // A listener that couldn't record it returns false: nothing is assumed
491
+ // recorded then, so the next compile tells it again whatever it shows.
492
+ this.recordedCompiledBudget = this.compiledBudgetListener?.(budget, fit) !== false ? { budget, fit, epoch } : undefined;
493
+ }
494
+
495
+ /** Compile at the live budget (no explicit one), noting whether it fit. */
496
+ private async compileAtLiveBudget(compile: () => Promise<CompileResult>): Promise<CompileResult> {
497
+ const started = ++this.compilesStarted;
498
+ this.compilesRunning.add(started);
499
+ try {
500
+ return await this.compileAtLiveBudgetNoting(compile, started);
501
+ } finally {
502
+ this.compilesRunning.delete(started);
503
+ const earliest = Math.min(...this.compilesRunning);
504
+ for (const [budget, start] of this.latestEndedStart) {
505
+ if (start < earliest) this.latestEndedStart.delete(budget);
506
+ }
507
+ }
508
+ }
509
+
510
+ /** The compile at the live budget that started as the `started`th, and what it showed. */
511
+ private async compileAtLiveBudgetNoting(compile: () => Promise<CompileResult>, started: number): Promise<CompileResult> {
512
+ // The budget this compile plans at, and the descent under way when it
513
+ // started: a change of either while it runs is no part of what it shows.
514
+ const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
515
+ const epoch = this.liveBudgetEpoch;
516
+ const descent = this.descentEpoch;
517
+ let result: CompileResult;
518
+ try {
519
+ result = await compile();
520
+ } catch (error) {
521
+ if ((error as { name?: unknown } | null)?.name !== 'OverBudgetError') throw error;
522
+ // A refusal shows the budget it planned at doesn't fit, whatever
523
+ // changed while it ran: the record's marker for it is withdrawn, and
524
+ // nothing is credited, unless a compile that started later has already
525
+ // ended at that budget.
526
+ if (this.claimLatestAt(live, started)) this.noteCompiledBudget(live, false, epoch);
527
+ // A budget a boot restore applied at once, refused at its first test,
528
+ // before anything wrote the budget: restore it paced instead, as the
529
+ // boot would have without its proof, and compile again from the
530
+ // recipe's budget. (While restoredAtOnce holds, the live budget is the
531
+ // one the boot applied: every write of the budget clears it, and no
532
+ // compile runs before the boot's restore.)
533
+ if (!this.restoredAtOnce) throw error;
534
+ this.restoredAtOnce = false;
535
+ // The persisted budget stays in the overrides, so if it can't be
536
+ // restored paced, no later write erases it.
537
+ this.setContextBudget(this.configuredContextBudgetTokens, undefined);
538
+ let outcome: string;
539
+ try {
540
+ this.updateRuntimeSettings({ contextBudgetTokens: live });
541
+ outcome = 'restored it as a paced descent from the recipe\'s budget';
542
+ } catch (fallback) {
543
+ outcome = `couldn't restore it paced (${fallback instanceof Error ? fallback.message : String(fallback)}), ` +
544
+ `so it compiles at the recipe's budget, with contextBudgetTokens=${live} kept set`;
545
+ }
546
+ console.error(
547
+ `[agent-settings] ${this.name}: the context manager refused contextBudgetTokens=${live}, which the boot ` +
548
+ `applied at once; ${outcome}`,
549
+ );
550
+ return this.compileAtLiveBudget(compile);
551
+ }
552
+ this.restoredAtOnce = false;
553
+ // A settle, here, of the descent this compile began under proves its
554
+ // target: the frontier fits the window prepared for it. Without a settle,
555
+ // the compile proves the budget it planned at. Either only if the live
556
+ // budget didn't change while it ran; a settle of a descent armed while it
557
+ // ran proves nothing (the next compile at the target does).
558
+ // A compile that ends here with a fit takes its place in the start order
559
+ // at the budget it planned at, credited or not; a settle credits its
560
+ // target only from the latest compile to end there.
561
+ const latest = this.claimLatestAt(live, started);
562
+ const sameLive = this.liveBudgetEpoch === epoch;
563
+ const sameDescent = this.descentEpoch === descent;
564
+ const settled = this.settleRuntimeSettingsTransition();
565
+ if (latest && sameLive && settled && sameDescent && this.claimLatestAt(this.contextBudgetTokens!, started)) {
566
+ this.noteCompiledBudget(this.contextBudgetTokens!, true, this.liveBudgetEpoch);
567
+ } else if (latest && sameLive && !settled) this.noteCompiledBudget(live, true, epoch);
568
+ return result;
569
+ }
570
+
571
+ /**
572
+ * The budget compiles plan at, the path a patch's budget takes from it, and
573
+ * whether a descent is in flight, from the agent's own state alone: what a
574
+ * runtime-settings preview can still say while the context manager refuses
575
+ * its queries.
576
+ * @internal For the framework's runtime-settings preview; not a host API.
577
+ */
578
+ runtimeBudgetPath(patch?: AgentRuntimeSettingsPatch): {
579
+ liveBudgetTokens: number;
580
+ path: 'immediate' | 'paced' | 'none';
581
+ transition: 'stable' | 'converging';
582
+ } {
583
+ const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
584
+ const budget = patch?.contextBudgetTokens;
585
+ return {
586
+ liveBudgetTokens: live,
587
+ path: budget === undefined ? 'none' : budget >= live || patch?.immediate ? 'immediate' : 'paced',
588
+ transition: this.contextBudgetTargetTokens === undefined ? 'stable' : 'converging',
589
+ };
590
+ }
591
+
592
+ /**
593
+ * Whether the context manager answers its queries, as its readiness says.
594
+ * It refuses them while its strategy's initialization is pending or has
595
+ * failed, until a switchBranch or setStrategy succeeds, and a strategy can
596
+ * refuse its readiness on its own, as the autobiographical one does for a
597
+ * branch it hasn't reloaded.
598
+ * @internal For the framework's runtime-settings preview; not a host API.
599
+ */
600
+ contextManagerAnswers(): boolean {
601
+ try {
602
+ this.contextManager.isReady();
603
+ return true;
604
+ } catch {
605
+ return false;
606
+ }
607
+ }
608
+
310
609
  /**
311
610
  * Read-only mirror of `updateRuntimeSettings`' budget semantics: derive what
312
611
  * the next compile would actually plan at if `patch` were applied, WITHOUT
@@ -323,11 +622,17 @@ export class Agent {
323
622
  * - `path: 'none'` — patch absent or budget untouched.
324
623
  *
325
624
  * `overrides` uses strategy-config names (`recentWindowTokens`,
326
- * `kvStableReachTokens`) suitable for `previewContext`. `preparedWindowTokens`
327
- * is deliberately never mapped: it is strategy instance state, not config,
328
- * and cannot be simulated by a preview. A `kvStableReachTokens` override is
329
- * omitted while a prepared window is in flight — the live runtime pace
330
- * shadows the config value there, so the override would not be observed.
625
+ * `kvStableReachTokens`) suitable for `previewContext`. The reach is the one
626
+ * the next compile plans at (context-manager's kv-stable picker): a
627
+ * descent's pace while a window is prepared for it, one this patch arms (a
628
+ * paced decrease) or one in flight that it leaves alone (a patch without a
629
+ * budget), and the configured reach otherwise. Config is a preview's only
630
+ * lever: `preparedWindowTokens` and the live runtime pace are strategy
631
+ * instance state, which a preview can't set. So a preview taken during a
632
+ * descent plans under that descent's prepared window, and at its live pace
633
+ * whenever the strategy carries one, which the picker reads before the
634
+ * configured reach. A boot restore's preflight never meets this: a new
635
+ * strategy has no window.
331
636
  */
332
637
  planRuntimeSettings(patch?: AgentRuntimeSettingsPatch): {
333
638
  effectiveBudgetTokens: number;
@@ -343,34 +648,33 @@ export class Agent {
343
648
  this.validateRuntimeSettingsPatch(patch);
344
649
  }
345
650
  const hot = this.getHotContextSettings();
346
- const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
651
+ const { liveBudgetTokens: live, path } = this.runtimeBudgetPath(patch);
652
+ const budget = patch?.contextBudgetTokens;
347
653
 
348
654
  const overrides: Record<string, unknown> = {};
349
655
  if (patch?.tailTokens !== undefined) {
350
656
  overrides.recentWindowTokens = patch.tailTokens;
351
657
  }
352
- if (
353
- patch?.transitionPaceTokens !== undefined &&
354
- hot?.preparedWindowTokens === undefined
355
- ) {
356
- overrides.kvStableReachTokens = patch.transitionPaceTokens;
658
+ // A window is prepared at the next compile when this patch arms a
659
+ // descent, or leaves one in flight alone; an immediate change clears it.
660
+ const prepared = hot !== null && (path === 'paced' || (path === 'none' && hot.preparedWindowTokens !== undefined));
661
+ const reach = prepared
662
+ ? patch?.transitionPaceTokens ?? hot.transitionPaceTokens ?? DEFAULT_TRANSITION_PACE_TOKENS
663
+ : this.configuredTransitionPaceTokens;
664
+ if (reach !== undefined && reach !== this.configuredTransitionPaceTokens) {
665
+ overrides.kvStableReachTokens = reach;
357
666
  }
358
667
 
359
- if (patch?.contextBudgetTokens === undefined) {
668
+ if (budget === undefined) {
360
669
  return { effectiveBudgetTokens: live, liveBudgetTokens: live, path: 'none', overrides };
361
670
  }
362
- if (patch.contextBudgetTokens >= live || patch.immediate) {
363
- return {
364
- effectiveBudgetTokens: patch.contextBudgetTokens,
365
- liveBudgetTokens: live,
366
- path: 'immediate',
367
- overrides,
368
- };
671
+ if (path === 'immediate') {
672
+ return { effectiveBudgetTokens: budget, liveBudgetTokens: live, path, overrides };
369
673
  }
370
674
  return {
371
675
  effectiveBudgetTokens: live,
372
676
  liveBudgetTokens: live,
373
- advisoryTargetTokens: patch.contextBudgetTokens,
677
+ advisoryTargetTokens: budget,
374
678
  path: 'paced',
375
679
  overrides,
376
680
  };
@@ -397,6 +701,8 @@ export class Agent {
397
701
  let nextContextBudget = this.contextBudgetTokens;
398
702
  let nextContextTarget = this.contextBudgetTargetTokens;
399
703
  let appliedDefaultPace = false;
704
+ // A paced decrease arms a descent, even to the target already set.
705
+ let armed = false;
400
706
  const hotPatch: {
401
707
  tailTokens?: number;
402
708
  transitionPaceTokens?: number | null;
@@ -428,21 +734,24 @@ export class Agent {
428
734
  }
429
735
  hotPatch.preparedWindowTokens = patch.contextBudgetTokens - this.maxTokens;
430
736
  nextContextTarget = patch.contextBudgetTokens;
737
+ armed = true;
431
738
  }
432
739
  }
433
740
 
434
741
  if (Object.keys(hotPatch).length > 0) {
435
742
  this.updateHotContextSettings(hotPatch);
436
743
  }
437
- this.contextBudgetTokens = nextContextBudget;
438
- this.contextBudgetTargetTokens = nextContextTarget;
744
+ this.setContextBudget(nextContextBudget, nextContextTarget, armed);
745
+ // A budget written here is a decision about it, whatever its value: the
746
+ // boot's at-once fallback (restoredAtOnce) no longer speaks for it.
747
+ if (patch.contextBudgetTokens !== undefined) this.restoredAtOnce = false;
439
748
  if (appliedDefaultPace) {
440
749
  this.runtimeSettingsOverrides.transitionPaceTokens = DEFAULT_TRANSITION_PACE_TOKENS;
441
750
  }
442
- for (const [key, value] of Object.entries(patch)) {
443
- if (key === 'sameRoundThinkTextPolicy') continue;
444
- if (key === 'immediate') continue; // a mode for this apply, never a persisted setting
445
- if (value !== undefined) (this.runtimeSettingsOverrides as Record<string, unknown>)[key] = value;
751
+ // Only settings reach the override map: `immediate` is a mode for this
752
+ // apply, and nothing else a caller passes is a setting.
753
+ for (const key of ['contextBudgetTokens', 'tailTokens', 'transitionPaceTokens'] as const) {
754
+ if (patch[key] !== undefined) this.runtimeSettingsOverrides[key] = patch[key];
446
755
  }
447
756
  if (patch.sameRoundThinkTextPolicy !== undefined) {
448
757
  this.runtimeSettingsOverrides.sameRoundThinkTextPolicy = patch.sameRoundThinkTextPolicy;
@@ -454,6 +763,8 @@ export class Agent {
454
763
  const reset = new Set(keys ?? ['contextBudgetTokens', 'tailTokens', 'transitionPaceTokens', 'sameRoundThinkTextPolicy']);
455
764
  let nextContextBudget = this.contextBudgetTokens;
456
765
  let nextContextTarget = this.contextBudgetTargetTokens;
766
+ // A reset to a recipe budget below the live one arms a descent to it.
767
+ let armed = false;
457
768
  const hotPatch: {
458
769
  tailTokens?: number;
459
770
  transitionPaceTokens?: number | null;
@@ -471,6 +782,7 @@ export class Agent {
471
782
  hotPatch.transitionPaceTokens = DEFAULT_TRANSITION_PACE_TOKENS;
472
783
  }
473
784
  nextContextTarget = configured;
785
+ armed = true;
474
786
  } else {
475
787
  nextContextBudget = this.configuredContextBudgetTokens;
476
788
  nextContextTarget = undefined;
@@ -487,9 +799,11 @@ export class Agent {
487
799
  : this.configuredTransitionPaceTokens ?? null;
488
800
  }
489
801
  if (Object.keys(hotPatch).length > 0) this.updateHotContextSettings(hotPatch);
490
- this.contextBudgetTokens = nextContextBudget;
491
- this.contextBudgetTargetTokens = nextContextTarget;
492
- if (reset.has('contextBudgetTokens')) delete this.runtimeSettingsOverrides.contextBudgetTokens;
802
+ this.setContextBudget(nextContextBudget, nextContextTarget, armed);
803
+ if (reset.has('contextBudgetTokens')) {
804
+ delete this.runtimeSettingsOverrides.contextBudgetTokens;
805
+ this.restoredAtOnce = false;
806
+ }
493
807
  if (reset.has('tailTokens')) delete this.runtimeSettingsOverrides.tailTokens;
494
808
  if (reset.has('transitionPaceTokens')) {
495
809
  delete this.runtimeSettingsOverrides.transitionPaceTokens;
@@ -503,7 +817,7 @@ export class Agent {
503
817
  cancelRuntimeSettingsTransition(): AgentRuntimeSettingsSnapshot {
504
818
  if (this.contextBudgetTargetTokens !== undefined) {
505
819
  this.updateHotContextSettings({ preparedWindowTokens: null });
506
- this.contextBudgetTargetTokens = undefined;
820
+ this.setContextBudget(this.contextBudgetTokens, undefined);
507
821
  const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
508
822
  if (live === (this.configuredContextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS)) {
509
823
  delete this.runtimeSettingsOverrides.contextBudgetTokens;
@@ -514,11 +828,56 @@ export class Agent {
514
828
  return this.getRuntimeSettings();
515
829
  }
516
830
 
517
- restoreRuntimeSettings(overrides: AgentRuntimeSettingsOverrides): AgentRuntimeSettingsSnapshot {
518
- return this.updateRuntimeSettings(overrides);
831
+ /**
832
+ * Apply persisted settings at construction. `provenBudget` is a budget the
833
+ * caller has shown fits (the framework, from the record and a preflight),
834
+ * applied at once: it stands as the last compile's until a compile here
835
+ * says otherwise. When it's below the live budget, where the proof is what
836
+ * took the restore off the paced path, a refusal of a compile at it
837
+ * restores it paced instead, until the budget is next written or a compile
838
+ * at it fits. At or above the live budget, the restore is at once either
839
+ * way, and a refusal has nothing to fall back to.
840
+ */
841
+ restoreRuntimeSettings(
842
+ settings: AgentRuntimeSettingsPatch,
843
+ opts?: { provenBudget?: number },
844
+ ): AgentRuntimeSettingsSnapshot {
845
+ if (Object.keys(settings).length === 0) return this.getRuntimeSettings();
846
+ const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
847
+ const snapshot = this.updateRuntimeSettings(settings);
848
+ if (opts?.provenBudget !== undefined) {
849
+ this.lastCompiledBudget = { budget: opts.provenBudget, fit: true, epoch: this.liveBudgetEpoch };
850
+ this.restoredAtOnce = opts.provenBudget < live;
851
+ }
852
+ return snapshot;
853
+ }
854
+
855
+ /**
856
+ * Keep a persisted budget, tail or pace that couldn't be applied at
857
+ * construction: it stays in the override map, unapplied, so a later
858
+ * persisting write keeps it in the record. A budget is reported as the one
859
+ * set (`contextBudgetTokens`) beside the one compiles plan at
860
+ * (`effectiveContextBudgetTokens`); a tail or pace stays the strategy's.
861
+ */
862
+ keepRuntimeSettings(settings: Pick<AgentRuntimeSettingsPatch, 'contextBudgetTokens' | 'tailTokens' | 'transitionPaceTokens'>): void {
863
+ for (const key of ['contextBudgetTokens', 'tailTokens', 'transitionPaceTokens'] as const) {
864
+ if (settings[key] !== undefined) this.runtimeSettingsOverrides[key] = settings[key];
865
+ }
519
866
  }
520
867
 
521
868
  private validateRuntimeSettingsPatch(patch: AgentRuntimeSettingsPatch): void {
869
+ this.checkRuntimeSettingsPatch(patch);
870
+ if ((patch.tailTokens !== undefined || patch.transitionPaceTokens !== undefined) &&
871
+ !this.getHotContextSettings()) {
872
+ throw new Error('The active context strategy does not support live tail/transition settings');
873
+ }
874
+ }
875
+
876
+ /**
877
+ * The checks of a runtime-settings patch that need nothing from the context manager.
878
+ * @internal For the framework's runtime-settings preview; not a host API.
879
+ */
880
+ checkRuntimeSettingsPatch(patch: AgentRuntimeSettingsPatch): void {
522
881
  if (Object.keys(patch).length === 0) throw new Error('At least one setting is required');
523
882
  if (patch.contextBudgetTokens !== undefined) {
524
883
  if (!Number.isSafeInteger(patch.contextBudgetTokens) || patch.contextBudgetTokens <= this.maxTokens) {
@@ -538,37 +897,56 @@ export class Agent {
538
897
  patch.sameRoundThinkTextPolicy !== 'private') {
539
898
  throw new Error("sameRoundThinkTextPolicy must be 'public' or 'private'");
540
899
  }
541
- if ((patch.tailTokens !== undefined || patch.transitionPaceTokens !== undefined) &&
542
- !this.getHotContextSettings()) {
543
- throw new Error('The active context strategy does not support live tail/transition settings');
544
- }
545
900
  }
546
901
 
547
- private settleRuntimeSettingsTransition(): void {
548
- if (this.contextBudgetTargetTokens === undefined) return;
902
+ /** Settle a converging budget once the window is prepared; true if it settled. */
903
+ private settleRuntimeSettingsTransition(): boolean {
904
+ if (this.contextBudgetTargetTokens === undefined) return false;
549
905
  const hot = this.getHotContextSettings();
550
- if (!hot?.prepared) return;
551
- this.contextBudgetTokens = this.contextBudgetTargetTokens;
552
- this.contextBudgetTargetTokens = undefined;
906
+ if (!hot?.prepared) return false;
907
+ this.setContextBudget(this.contextBudgetTargetTokens, undefined);
553
908
  this.updateHotContextSettings({ preparedWindowTokens: null });
909
+ return true;
554
910
  }
555
911
 
556
912
  /**
557
913
  * RFC-006 consumed watermark: the newest stored message at the last compile
558
- * of a model request, per branch. Everything above it has never been in a
914
+ * of a model request, or at the last tool boundary that injected messages
915
+ * into a live one, per branch. Everything above it has never been in a
559
916
  * request and may still be replaced or withdrawn in place by its sender.
560
917
  */
561
918
  private consumedWatermark: { branch: string; sequence: number } | null = null;
919
+ /** Counts marks: a compile writes its watermark back only if no mark was
920
+ * made while it ran (a tool boundary's, or another compile's). */
921
+ private watermarkMarks = 0;
562
922
 
563
923
  getConsumedWatermark(): { branch: string; sequence: number } | null {
564
924
  return this.consumedWatermark;
565
925
  }
566
926
 
567
- /** Mark everything currently stored as consumed (boot, branch switch). */
927
+ /** Mark everything currently stored as consumed (the agent's creation, at
928
+ * boot or later, and a tool boundary that injected messages into the live
929
+ * stream). */
568
930
  markContextConsumed(): void {
569
931
  // Tolerates partial context-manager doubles (tests build Agents over
570
932
  // stubs): without a watermark nothing is ever treated as unread.
571
933
  this.consumedWatermark = this.pendingWatermark();
934
+ this.watermarkMarks++;
935
+ }
936
+
937
+ /**
938
+ * A finished compile's watermark, taken before it awaited. Within a branch
939
+ * the watermark only advances: if a mark was made while the compile ran,
940
+ * the compile's (older) one is applied only where it is later on that
941
+ * mark's branch, so a boundary's mark is never rolled back by a compile
942
+ * that started before it (a preview during a live turn).
943
+ */
944
+ private applyCompileWatermark(watermark: { branch: string; sequence: number }, marksBefore: number): void {
945
+ const current = this.consumedWatermark;
946
+ if (this.watermarkMarks !== marksBefore && current
947
+ && (current.branch !== watermark.branch || current.sequence >= watermark.sequence)) return;
948
+ this.consumedWatermark = watermark;
949
+ this.watermarkMarks++;
572
950
  }
573
951
 
574
952
  /** The watermark a successful compile will establish (taken before, applied after). */
@@ -591,32 +969,61 @@ export class Agent {
591
969
  }
592
970
  }
593
971
 
972
+ /** A committing compile, as for a request that is sent: the context
973
+ * manager commits what it commits for one, the consumed watermark moves,
974
+ * and a prepared budget change settles. To inspect what the agent would
975
+ * see, use the framework's `previewActivation`, which compiles as a dry
976
+ * run. */
594
977
  async compileContext(budget?: TokenBudget): Promise<CompileResult> {
595
978
  // RFC-006 §3.3: consumption is determined at assembly — a compile that
596
979
  // fails assembled nothing, so the watermark moves only on success.
597
980
  const watermark = this.pendingWatermark();
598
- const result = await this.contextManager.compile(this.compileBudget(budget));
599
- if (watermark) this.consumedWatermark = watermark;
600
- if (!budget) this.settleRuntimeSettingsTransition();
981
+ const marksBefore = this.watermarkMarks;
982
+ const compile = () => this.contextManager.compile(this.compileBudget(budget));
983
+ const result = budget ? await compile() : await this.compileAtLiveBudget(compile);
984
+ if (watermark) this.applyCompileWatermark(watermark, marksBefore);
601
985
  return result;
602
986
  }
603
987
 
604
988
  /**
605
- * Compile the context with injections.
606
- * Same as compileContext but forwards injections (e.g. from MCPL servers)
607
- * to the context manager so they are merged into the compiled messages.
989
+ * Compile the context with injections (e.g. from MCPL servers), which the
990
+ * context manager merges into the compiled messages. Without
991
+ * `opts.dryRun` it commits as `compileContext` does: the consumed
992
+ * watermark moves, and a compile at the live window settles a prepared
993
+ * budget change. With `opts.dryRun`, for a compile that will never be
994
+ * sent, it does neither (see below).
608
995
  */
609
996
  async compileWithInjections(
610
997
  budget?: TokenBudget,
611
998
  injections?: ContextInjection[],
612
- opts?: { kvUnifiedImmutablePrefixHash?: string },
999
+ opts?: { kvUnifiedImmutablePrefixHash?: string; dryRun?: boolean },
613
1000
  ): Promise<CompileResult> {
614
- const watermark = this.pendingWatermark();
615
- const result = await this.contextManager.compile(
616
- this.compileBudget(budget), injections, opts as never,
617
- );
618
- if (watermark) this.consumedWatermark = watermark;
619
- if (!budget) this.settleRuntimeSettingsTransition();
1001
+ // A dry run is a compile that will never be sent. The context manager
1002
+ // persists no fold resolutions for it and queues none of the compression
1003
+ // or merge work its fold plan calls for. Its thinking binding
1004
+ // (context-manager#160, not yet released) will commit stamps and add a
1005
+ // compile awaiting acceptance for a committing compile only. Here nothing
1006
+ // moves either: the agent never read what a dry run assembled, so the
1007
+ // consumed watermark stays. A dry run proves nothing about the budget
1008
+ // either, so it goes straight to the compile, around
1009
+ // compileAtLiveBudget: it settles no descent (a prepared budget change
1010
+ // waits for the compile that is sent), notes no compiled budget, and
1011
+ // restores nothing the boot applied at once, whether it fits or is
1012
+ // refused.
1013
+ //
1014
+ // Context-manager 0.14 leaves what a select leaves behind as the last
1015
+ // committing compile left it, on every path out of a dry run, throws
1016
+ // included: no chunk record and no compression queued for a chunk the
1017
+ // dry run closes, no calibration, and none of the bookkeeping the next
1018
+ // compile or an observer reads (its `SelectOptions.dryRun` gives the
1019
+ // contract). The one thing a dry run can still leave is the release of a
1020
+ // compression hold whose deadline has passed, which `compile` does for
1021
+ // any compile before it selects.
1022
+ const watermark = opts?.dryRun ? null : this.pendingWatermark();
1023
+ const marksBefore = this.watermarkMarks;
1024
+ const compile = () => this.contextManager.compile(this.compileBudget(budget), injections, opts as never);
1025
+ const result = budget || opts?.dryRun ? await compile() : await this.compileAtLiveBudget(compile);
1026
+ if (watermark) this.applyCompileWatermark(watermark, marksBefore);
620
1027
  return result;
621
1028
  }
622
1029
 
@@ -692,15 +1099,8 @@ export class Agent {
692
1099
  return {
693
1100
  messages: this.toolResultGuard.prepareRequest(messages, true),
694
1101
  system: this.buildSystemPrompt(systemInjections),
695
- config: {
696
- model: this.model,
697
- maxTokens: this.maxTokens,
698
- ...(this.temperature !== undefined && { temperature: this.temperature }),
699
- ...(this.thinking !== undefined && { thinking: this.thinking }),
700
- },
701
1102
  tools: tools.length > 0 ? tools : undefined,
702
- ...(this.providerParams && { providerParams: this.providerParams }),
703
- assistantParticipant: this.name,
1103
+ ...this.requestSettings(),
704
1104
  };
705
1105
  };
706
1106
  const request = await assemble();
@@ -780,7 +1180,12 @@ export class Agent {
780
1180
 
781
1181
  // If all tools done, transition to ready
782
1182
  if (this._state.pending.size === 0) {
783
- this._state = { status: 'ready', toolResults: this._state.completed, stream: this._state.stream };
1183
+ this._state = {
1184
+ status: 'ready',
1185
+ toolResults: this._state.completed,
1186
+ stream: this._state.stream,
1187
+ supportsInjectedMessages: this._state.supportsInjectedMessages,
1188
+ };
784
1189
  }
785
1190
  }
786
1191
 
@@ -799,12 +1204,18 @@ export class Agent {
799
1204
  * Build the membrane-normalized request that WOULD be emitted for this
800
1205
  * agent's next activation, given the supplied tools and injections.
801
1206
  *
802
- * This is the single source of truth for request assembly, shared by the
803
- * real activation path (`startStreamWithInjections`) and debug/preview
804
- * tooling (`Framework.previewActivation`). It is pure and non-mutating:
805
- * it does not touch agent state and does not call the membrane, and
806
- * `ContextManager.compile` is itself side-effect-free (compression runs in
807
- * the background). Safe to call regardless of the agent's current status.
1207
+ * This is the single source of truth for a framework turn's request,
1208
+ * shared by the real activation path (`startStreamWithInjections`) and
1209
+ * debug/preview tooling (`Framework.previewActivation`). It does not call
1210
+ * the membrane. The direct API (`runInferenceWithInjections`) assembles its
1211
+ * own messages, system prompt and tools, and both take the agent's
1212
+ * settings from `requestSettings()`.
1213
+ * A compile that is sent commits what the context manager commits for it
1214
+ * (fold resolutions, the compression its fold plan calls for, the consumed
1215
+ * watermark); a preview passes `options.dryRun`, so its compile commits
1216
+ * none of that (see `compileWithInjections` for what a dry run still
1217
+ * leaves). Either way the context manager is handed the compression tool
1218
+ * definitions. Safe to call regardless of the agent's current status.
808
1219
  * It doesn't wait for the tool-result guard's annotations, so a preview
809
1220
  * never waits on a workspace write (rollback, undo and redo report one), and
810
1221
  * may show a withheld stub before its place is added; the activation waits
@@ -845,7 +1256,12 @@ export class Agent {
845
1256
  let { messages, systemInjections } = await this.compileWithInjections(
846
1257
  budget,
847
1258
  injections,
848
- immutablePrefixHash ? { kvUnifiedImmutablePrefixHash: immutablePrefixHash } : undefined,
1259
+ immutablePrefixHash || options.dryRun
1260
+ ? {
1261
+ ...(immutablePrefixHash ? { kvUnifiedImmutablePrefixHash: immutablePrefixHash } : {}),
1262
+ ...(options.dryRun ? { dryRun: true } : {}),
1263
+ }
1264
+ : undefined,
849
1265
  );
850
1266
 
851
1267
  // Sanitize: strip empty/whitespace text blocks and drop messages left with
@@ -897,15 +1313,30 @@ export class Agent {
897
1313
  return {
898
1314
  messages: this.toolResultGuard.prepareRequest(messages),
899
1315
  system: this.buildSystemPrompt(systemInjections),
1316
+ tools: availableTools.length > 0 ? availableTools : undefined,
1317
+ ...this.requestSettings(),
1318
+ ...(kvUnified ? { cacheMarkers: 'cm-owned' as const } : {}),
1319
+ };
1320
+ }
1321
+
1322
+ /**
1323
+ * The request fields that come from this agent's own settings: its model
1324
+ * config, prompt caching and cache TTL, prefill message, provider
1325
+ * parameters and participant name. Every request the agent sends takes
1326
+ * them from here, a framework turn's (buildActivationRequest) and the
1327
+ * direct API's (runInferenceWithInjections), so a setting reaches both or
1328
+ * neither.
1329
+ */
1330
+ private requestSettings(): Pick<NormalizedRequest,
1331
+ 'config' | 'promptCaching' | 'cacheTtl' | 'prefillUserMessage' | 'providerParams' | 'assistantParticipant'> {
1332
+ return {
900
1333
  config: {
901
1334
  model: this.model,
902
1335
  maxTokens: this.maxTokens,
903
1336
  ...(this.temperature !== undefined && { temperature: this.temperature }),
904
1337
  ...(this.thinking !== undefined && { thinking: this.thinking }),
905
1338
  },
906
- tools: availableTools.length > 0 ? availableTools : undefined,
907
1339
  promptCaching: this.promptCaching,
908
- ...(kvUnified ? { cacheMarkers: 'cm-owned' as const } : {}),
909
1340
  cacheTtl: this.cacheTtl,
910
1341
  ...(this.prefillUserMessage && { prefillUserMessage: this.prefillUserMessage }),
911
1342
  ...(this.providerParams && { providerParams: this.providerParams }),
@@ -966,16 +1397,28 @@ export class Agent {
966
1397
  this.failOpenKvSubmissions();
967
1398
 
968
1399
  this._streamId++;
1400
+ // A pending cancel belongs to the stream that was live when cancelStream()
1401
+ // ran. The stream driver collects it on that stream's terminal event, or
1402
+ // at the loop's end when the iterator closed without one, while the
1403
+ // stream still owns the agent. This clear is for the records no driver
1404
+ // collects: a dropped turn's, whose stream no driver iterates; one whose
1405
+ // stream's terminal came after another stream took the agent; or a
1406
+ // cancel after the stream's complete event. A fresh stream must not
1407
+ // inherit one and read its own later error as a deliberate stop.
1408
+ this._pendingCancel = undefined;
969
1409
  this._inferenceStartedAt = Date.now();
970
1410
  this.lastStreamInputTokens = 0;
971
1411
  // Reset the cache-inclusive counters too: a new stream must not inherit
972
1412
  // the prior stream's window size — on the physical-window restart path
973
1413
  // that inherited value IS the oversized number that caused the restart,
974
1414
  // and projecting on it before this stream's first usage event would
975
- // restart again (loop). The `> 0` guard downstream means "no usage
976
- // observed on THIS stream yet" only because of this reset.
1415
+ // restart again (loop). The `> 0` guard downstream means "no call on
1416
+ // THIS stream has reported a prompt yet" only because of this reset (a
1417
+ // call that reports none leaves these as they were, and adds to
1418
+ // lastStreamUnreportedTokens instead).
977
1419
  this.lastStreamRealInputTokens = 0;
978
1420
  this.lastStreamOutputTokens = 0;
1421
+ this.lastStreamUnreportedTokens = 0;
979
1422
 
980
1423
  // Compiled only once each withheld stub's annotation has finished,
981
1424
  // including one that began during the compile, and after a stub edit that
@@ -1063,9 +1506,10 @@ export class Agent {
1063
1506
 
1064
1507
  /**
1065
1508
  * Transition to waiting_for_tools when stream yields tool calls.
1066
- * Called by framework's driveStream.
1509
+ * Called by framework's driveStream, with what the stream declared about
1510
+ * carrying injected messages with this round's results (see AgentState).
1067
1511
  */
1068
- enterWaitingForTools(calls: ToolCall[], stream: YieldingStream): void {
1512
+ enterWaitingForTools(calls: ToolCall[], stream: YieldingStream, supportsInjectedMessages?: boolean): void {
1069
1513
  const pending = new Map<ToolCallId, PendingToolCall>();
1070
1514
  for (const call of calls) {
1071
1515
  pending.set(call.id, {
@@ -1075,7 +1519,7 @@ export class Agent {
1075
1519
  startedAt: Date.now(),
1076
1520
  });
1077
1521
  }
1078
- this._state = { status: 'waiting_for_tools', pending, completed: [], stream };
1522
+ this._state = { status: 'waiting_for_tools', pending, completed: [], stream, supportsInjectedMessages };
1079
1523
  }
1080
1524
 
1081
1525
  /**
@@ -1118,18 +1562,42 @@ export class Agent {
1118
1562
  this._state = { status: 'streaming', stream };
1119
1563
  }
1120
1564
 
1565
+ /** The most recent cancelStream() of a live stream, until the stream
1566
+ * driver collects it on that stream's terminal event. Its presence is
1567
+ * the signal (a reasonless Stop is still a deliberate stop); its reason
1568
+ * is the caller's own word. Membrane reports every cancel() as reason
1569
+ * 'user' — the call, not the actor — and a stream implementation may
1570
+ * report the cancel as `error` with no reason at all, so this record is
1571
+ * the only provenance a host-side cancel has. */
1572
+ private _pendingCancel: { reason?: string } | undefined;
1573
+
1121
1574
  /**
1122
- * Cancel any active stream and reset to idle.
1575
+ * Cancel the stream this agent's state holds (streaming, waiting on its
1576
+ * tools, or ready at a tool boundary with every result in), and reset to
1577
+ * idle. `reason` is provenance for the framework's inference:aborted trace
1578
+ * and marker metadata (e.g. 'zombie_reclaim', 'subagent_cancel'); it never
1579
+ * reaches the provider.
1123
1580
  */
1124
- cancelStream(): void {
1125
- if (this._state.status === 'streaming') {
1126
- this._state.stream.cancel();
1127
- } else if (this._state.status === 'waiting_for_tools' && this._state.stream) {
1581
+ cancelStream(reason?: string): void {
1582
+ if ('stream' in this._state && this._state.stream) {
1583
+ this._pendingCancel = { reason };
1128
1584
  this._state.stream.cancel();
1129
1585
  }
1130
1586
  this._state = { status: 'idle' };
1131
1587
  }
1132
1588
 
1589
+ /** Collect (and clear) the cancel that ended the current stream, if this
1590
+ * side issued one. The stream driver calls it once, while the stream
1591
+ * still owns the agent, at the stream's terminal event (`aborted`
1592
+ * normally, `error` for implementations that report cancel() that way)
1593
+ * or at the loop's end when the stream closed without one. A record no
1594
+ * driver collects is cleared when the agent's next stream starts. */
1595
+ takeCancel(): { reason?: string } | undefined {
1596
+ const c = this._pendingCancel;
1597
+ this._pendingCancel = undefined;
1598
+ return c;
1599
+ }
1600
+
1133
1601
  /**
1134
1602
  * Check if agent has pending tool calls.
1135
1603
  */
@@ -1162,20 +1630,20 @@ export class Agent {
1162
1630
  }
1163
1631
 
1164
1632
  /**
1165
- * Build the effective system prompt, appending any system-position injections.
1633
+ * Build the effective system prompt, appending any system-position
1634
+ * injections, their blocks joined by line breaks. The system prompt is
1635
+ * text, so a block of another type, such as an image a server or module
1636
+ * injected there, can't go in it: a line in its place says so. The hook
1637
+ * orchestrator tells a server's operator once per server and namespace,
1638
+ * and the module registry tells a module's once per module and namespace.
1166
1639
  */
1167
1640
  private buildSystemPrompt(systemInjections: ContentBlock[]): string {
1168
1641
  if (systemInjections.length === 0) {
1169
1642
  return this.systemPrompt;
1170
1643
  }
1171
1644
 
1172
- const injectedText = systemInjections
1173
- .filter((block): block is ContentBlock & { type: 'text' } => block.type === 'text')
1174
- .map((block) => block.text);
1175
-
1176
- if (injectedText.length === 0) {
1177
- return this.systemPrompt;
1178
- }
1645
+ const injectedText = systemInjections.map((block) =>
1646
+ block.type === 'text' ? block.text : `[${block.type} block not shown: the system prompt carries text only.]`);
1179
1647
 
1180
1648
  return this.systemPrompt + '\n' + injectedText.join('\n');
1181
1649
  }
@@ -1187,10 +1655,9 @@ export class Agent {
1187
1655
  return { aborted: true, durationMs };
1188
1656
  }
1189
1657
 
1190
- if (this._state.status === 'streaming' ||
1191
- (this._state.status === 'waiting_for_tools' && this._state.stream)) {
1658
+ if ('stream' in this._state && this._state.stream) {
1192
1659
  const durationMs = Date.now() - this._inferenceStartedAt;
1193
- this.cancelStream();
1660
+ this.cancelStream(reason);
1194
1661
  return { aborted: true, durationMs };
1195
1662
  }
1196
1663