@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/dist/src/agent.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { isAbortedResponse } from '@animalabs/membrane';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { ToolResultGuard } from './tool-result-guard.js';
4
+ import { assertBooleanSetting, holdsSettings } from './config-checks.js';
4
5
  import { indexSilentTickRows, separateSilentHeartbeatTicks, silentHeartbeatSeparatorTurn, } from './silent-heartbeat.js';
5
6
  import { nonErrorResultText, truncateForHistory, DEFAULT_TOOL_RESULT_INLINE_MAX_CHARS, } from './tool-result-history.js';
6
7
  function stableHash(value) {
@@ -18,6 +19,32 @@ function stableHash(value) {
18
19
  const DEFAULT_CONTEXT_BUDGET_TOKENS = 100_000;
19
20
  const DEFAULT_TRANSITION_PACE_TOKENS = 16_000;
20
21
  const DEFAULT_SAME_ROUND_THINK_TEXT_POLICY = 'public';
22
+ /**
23
+ * Refuse an agent config whose `promptCaching`, `toolResultGuard`,
24
+ * `toolWrapperProseGuard`, `thinking.enabled` or `refusalHandling.autoRewind`
25
+ * holds anything but true or false (assertBooleanSetting), or whose `thinking`
26
+ * or `refusalHandling` is anything but an object, null or false
27
+ * (holdsSettings). The constructor runs it first, so the rule holds wherever
28
+ * an Agent is built. `create()` also runs it for each of its agents before
29
+ * anything opens, and `createEphemeralAgent` before it reserves the name, so a
30
+ * refusal there leaves nothing behind. Membrane reads `thinking.enabled`, and
31
+ * the refusal is here because the setting is AgentConfig's.
32
+ */
33
+ export function assertAgentSwitches(config) {
34
+ const agent = `Agent "${config.name}"`;
35
+ assertBooleanSetting(`${agent} promptCaching`, config.promptCaching, 'true or leaving it out marks requests for prompt caching, and false leaves the markers off, for transports that refuse them');
36
+ if (holdsSettings(`${agent} thinking`, config.thinking, '{ enabled: true }')) {
37
+ assertBooleanSetting(`${agent} thinking.enabled`, config.thinking.enabled, 'true asks the provider for extended thinking, and false or leaving it out doesn\'t');
38
+ }
39
+ if (holdsSettings(`${agent} refusalHandling`, config.refusalHandling, '{ autoRewind: true }')) {
40
+ assertBooleanSetting(`${agent} refusalHandling.autoRewind`, config.refusalHandling.autoRewind, 'true redacts the turn that tripped a refusal and runs again, up to maxRewinds times, ' +
41
+ 'and false or leaving it out doesn\'t');
42
+ }
43
+ assertBooleanSetting(`${agent} toolResultGuard`, config.toolResultGuard, 'true turns on tool-output admission, with one guarded retry after a provider refusal, ' +
44
+ 'and false or leaving it out doesn\'t');
45
+ assertBooleanSetting(`${agent} toolWrapperProseGuard`, config.toolWrapperProseGuard, 'true keeps a response whose whole prose is a tool-call-shaped wrapper from running or entering the agent\'s history, ' +
46
+ 'and false or leaving it out doesn\'t');
47
+ }
21
48
  /**
22
49
  * An agent wraps a context manager and manages inference state.
23
50
  */
@@ -65,15 +92,38 @@ export class Agent {
65
92
  * closure) so the next activation can close whatever its predecessor left
66
93
  * open — see failOpenKvSubmissions. */
67
94
  kvOpenQueue = null;
95
+ /** The current stream's fresh input so far, as membrane's usage event
96
+ * reports it (cumulative across the tool loop): what the maxStreamTokens
97
+ * budget checks. */
68
98
  lastStreamInputTokens = 0;
69
- /** Real prefix size of the last usage event: fresh + cache creation +
70
- * cache read. THE window-shaped number — `lastStreamInputTokens` alone
71
- * omits cached tokens, which are most of a warm stream's window. */
99
+ /** Real prompt size of the stream's latest provider call that reported a
100
+ * prompt, which is what the provider billed it: fresh + cache creation +
101
+ * cache read. A call that reports none leaves it as it was (see
102
+ * lastStreamUnreportedTokens). Membrane's usage events are cumulative, so
103
+ * this is the call's share of its event (cumulativeDelta): the whole event
104
+ * for a stream's first call, and the event's own value where a counter
105
+ * went back. THE window-shaped number — `lastStreamInputTokens` alone
106
+ * omits cached tokens, which are most of a warm stream's window. 0 until a
107
+ * call on this stream reports a prompt, and the physical-window
108
+ * projection runs only once one has. */
72
109
  lastStreamRealInputTokens = 0;
73
- /** Output tokens of the last usage event — the prior round's generated
74
- * thinking/text/tool_use, which becomes part of the NEXT round's input
75
- * and so belongs in the physical-window projection. */
110
+ /** Output tokens of the same call as lastStreamRealInputTokens, or
111
+ * maxTokens, the bound on them, when it reported none (a call that ends at
112
+ * a tool boundary wrote a tool_use, so a 0 is a count left unreported) —
113
+ * the prior round's generated thinking/text/tool_use, which becomes part
114
+ * of the NEXT round's input and so belongs in the physical-window
115
+ * projection. */
76
116
  lastStreamOutputTokens = 0;
117
+ /** What the stream has grown by since the call lastStreamRealInputTokens
118
+ * describes, for the physical-window projection: the blocks appended at
119
+ * each boundary the stream continued past (counted only for an agent with
120
+ * physicalWindowTokens, whose projection is this field's one reader), and
121
+ * the output of each call that reported no prompt (its reported output,
122
+ * or maxTokens, the bound on it, when it reported none either). After
123
+ * calls that report no prompt, the next request holds the prompt and
124
+ * output of the call lastStreamRealInputTokens describes, plus this. 0 at
125
+ * stream start and whenever a call reports a prompt. */
126
+ lastStreamUnreportedTokens = 0;
77
127
  maxStreamTokens;
78
128
  /** Provider hard context cap (see AgentConfig.physicalWindowTokens). */
79
129
  physicalWindowTokens;
@@ -87,9 +137,55 @@ export class Agent {
87
137
  configuredSameRoundThinkTextPolicy;
88
138
  contextBudgetTargetTokens;
89
139
  runtimeSettingsOverrides = {};
140
+ /**
141
+ * Counts changes of the live budget (an update, a reset, a restore, a
142
+ * settle). A compile speaks for the budget it planned at only if the live
143
+ * budget didn't change while it ran, and what it showed stands only until
144
+ * the next change.
145
+ */
146
+ liveBudgetEpoch = 0;
147
+ /**
148
+ * Counts changes of the descent (each arm of one, the same target included,
149
+ * a reset, a cancel, a settle). A settle proves its target only to a
150
+ * compile that began under that same descent.
151
+ */
152
+ descentEpoch = 0;
153
+ /** The live budget the last compile planned at, whether it fit, and the live budget's epoch then. */
154
+ lastCompiledBudget;
155
+ /** Counts compiles at the live budget as they start. */
156
+ compilesStarted = 0;
157
+ /** The start numbers of the compiles at the live budget still running. */
158
+ compilesRunning = new Set();
159
+ /**
160
+ * For each budget, the start of the latest-started compile that has ended
161
+ * there with a fit or a refusal, whether or not what it showed was
162
+ * credited. Of two compiles at one budget, the later-started one planned
163
+ * at the newer store, so an earlier-started one that ends after it is
164
+ * ignored. That rests on the context manager selecting at the start of
165
+ * `compile`, before anything it awaits, so start order is selection order;
166
+ * a context manager that awaits before its select breaks it. (Injections
167
+ * are added after the select, so compiles with and without them plan
168
+ * alike.) An entry is
169
+ * kept only while a compile that started before it is still running, the
170
+ * only kind it can turn away, so the map is empty whenever no compile
171
+ * runs.
172
+ */
173
+ latestEndedStart = new Map();
174
+ /** The last outcome the listener recorded; a failed record is told again, and so is any after a change. */
175
+ recordedCompiledBudget;
176
+ /**
177
+ * A boot restore applied a proven budget below the live one at once. Until
178
+ * the budget is next written (an update that carries one, or a reset of
179
+ * it) or a compile at it fits, a refusal of a compile at it restores it
180
+ * paced instead.
181
+ */
182
+ restoredAtOnce = false;
183
+ /** Told when that changes (the framework records it beside the persisted budget). */
184
+ compiledBudgetListener;
90
185
  contextManager;
91
186
  membrane;
92
187
  constructor(config, contextManager, membrane) {
188
+ assertAgentSwitches(config);
93
189
  this.name = config.name;
94
190
  this.model = config.model;
95
191
  this.systemPrompt = config.systemPrompt;
@@ -99,11 +195,11 @@ export class Agent {
99
195
  this.temperature = config.temperature;
100
196
  this.thinking = config.thinking;
101
197
  this.refusalHandling = config.refusalHandling;
102
- this.toolResultGuard = new ToolResultGuard(config.name, contextManager, config.toolResultGuard);
198
+ this.toolResultGuard = new ToolResultGuard(config.name, contextManager, config.toolResultGuard === true);
103
199
  this.proseRouting = config.proseRouting ?? 'locus';
104
- this.toolWrapperProseGuard = config.toolWrapperProseGuard ?? false;
200
+ this.toolWrapperProseGuard = config.toolWrapperProseGuard === true;
105
201
  this.cacheTtl = config.cacheTtl ?? '1h';
106
- this.promptCaching = config.promptCaching ?? true;
202
+ this.promptCaching = config.promptCaching !== false;
107
203
  this.prefillUserMessage = config.prefillUserMessage;
108
204
  this.providerParams = config.providerParams;
109
205
  this.sameRoundThinkTextPolicy = config.sameRoundThinkTextPolicy;
@@ -208,9 +304,15 @@ export class Agent {
208
304
  getRuntimeSettings() {
209
305
  const hot = this.getHotContextSettings();
210
306
  return {
211
- contextBudgetTokens: this.contextBudgetTargetTokens ??
307
+ // The budget it's set to: the override, where there is one. That is
308
+ // the target of a descent toward it, or else the live budget, except
309
+ // while it's kept unapplied: at boot (keepRuntimeSettings), or after a
310
+ // refused at-once budget couldn't be restored paced (compileAtLiveBudget).
311
+ contextBudgetTokens: this.runtimeSettingsOverrides.contextBudgetTokens ??
312
+ this.contextBudgetTargetTokens ??
212
313
  this.contextBudgetTokens ??
213
314
  DEFAULT_CONTEXT_BUDGET_TOKENS,
315
+ effectiveContextBudgetTokens: this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS,
214
316
  ...(hot ? { tailTokens: hot.tailTokens } : {}),
215
317
  ...(hot?.transitionPaceTokens !== undefined
216
318
  ? { transitionPaceTokens: hot.transitionPaceTokens }
@@ -232,6 +334,179 @@ export class Agent {
232
334
  getRuntimeSettingsOverrides() {
233
335
  return { ...this.runtimeSettingsOverrides };
234
336
  }
337
+ /**
338
+ * Set (or clear) the one listener told when a compile at the live budget
339
+ * comes out differently from the last: it fit at a budget the last one
340
+ * didn't plan at (after a settle, the target), or the context manager
341
+ * refused a budget the last one fit at.
342
+ */
343
+ onContextBudgetCompiled(listener) {
344
+ this.compiledBudgetListener = listener;
345
+ }
346
+ /**
347
+ * The live budget the last compile planned at and fit, if it fit and the
348
+ * live budget hasn't changed since.
349
+ */
350
+ getProvenContextBudgetTokens() {
351
+ const last = this.lastCompiledBudget;
352
+ return last?.fit && last.epoch === this.liveBudgetEpoch ? last.budget : undefined;
353
+ }
354
+ /**
355
+ * Set the live budget and the descent target, counting a change of each.
356
+ * `armed` counts a descent armed here as a change even when its target is
357
+ * the one already set: a compile that began under the earlier arm isn't
358
+ * credited with this one's settle.
359
+ */
360
+ setContextBudget(budget, target, armed = false) {
361
+ if (budget !== this.contextBudgetTokens)
362
+ this.liveBudgetEpoch++;
363
+ if (armed || target !== this.contextBudgetTargetTokens)
364
+ this.descentEpoch++;
365
+ this.contextBudgetTokens = budget;
366
+ this.contextBudgetTargetTokens = target;
367
+ }
368
+ /**
369
+ * Claim the place of the latest compile to end at `budget` for the one that
370
+ * started as the `started`th, and say whether it got it: a compile that
371
+ * started before one that has already ended there is ignored, whichever
372
+ * finishes last.
373
+ */
374
+ claimLatestAt(budget, started) {
375
+ if (started < (this.latestEndedStart.get(budget) ?? 0))
376
+ return false;
377
+ this.latestEndedStart.set(budget, started);
378
+ return true;
379
+ }
380
+ /**
381
+ * Note what a compile at `budget`, planned at the live budget's `epoch`,
382
+ * showed. It speaks for the live budget only if that hasn't changed since;
383
+ * the listener is told either way, so a refusal withdraws the record's
384
+ * marker for the budget it planned at whatever changed meanwhile.
385
+ */
386
+ noteCompiledBudget(budget, fit, epoch) {
387
+ if (epoch === this.liveBudgetEpoch)
388
+ this.lastCompiledBudget = { budget, fit, epoch };
389
+ const recorded = this.recordedCompiledBudget;
390
+ if (recorded?.budget === budget && recorded.fit === fit && recorded.epoch === epoch)
391
+ return;
392
+ // A listener that couldn't record it returns false: nothing is assumed
393
+ // recorded then, so the next compile tells it again whatever it shows.
394
+ this.recordedCompiledBudget = this.compiledBudgetListener?.(budget, fit) !== false ? { budget, fit, epoch } : undefined;
395
+ }
396
+ /** Compile at the live budget (no explicit one), noting whether it fit. */
397
+ async compileAtLiveBudget(compile) {
398
+ const started = ++this.compilesStarted;
399
+ this.compilesRunning.add(started);
400
+ try {
401
+ return await this.compileAtLiveBudgetNoting(compile, started);
402
+ }
403
+ finally {
404
+ this.compilesRunning.delete(started);
405
+ const earliest = Math.min(...this.compilesRunning);
406
+ for (const [budget, start] of this.latestEndedStart) {
407
+ if (start < earliest)
408
+ this.latestEndedStart.delete(budget);
409
+ }
410
+ }
411
+ }
412
+ /** The compile at the live budget that started as the `started`th, and what it showed. */
413
+ async compileAtLiveBudgetNoting(compile, started) {
414
+ // The budget this compile plans at, and the descent under way when it
415
+ // started: a change of either while it runs is no part of what it shows.
416
+ const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
417
+ const epoch = this.liveBudgetEpoch;
418
+ const descent = this.descentEpoch;
419
+ let result;
420
+ try {
421
+ result = await compile();
422
+ }
423
+ catch (error) {
424
+ if (error?.name !== 'OverBudgetError')
425
+ throw error;
426
+ // A refusal shows the budget it planned at doesn't fit, whatever
427
+ // changed while it ran: the record's marker for it is withdrawn, and
428
+ // nothing is credited, unless a compile that started later has already
429
+ // ended at that budget.
430
+ if (this.claimLatestAt(live, started))
431
+ this.noteCompiledBudget(live, false, epoch);
432
+ // A budget a boot restore applied at once, refused at its first test,
433
+ // before anything wrote the budget: restore it paced instead, as the
434
+ // boot would have without its proof, and compile again from the
435
+ // recipe's budget. (While restoredAtOnce holds, the live budget is the
436
+ // one the boot applied: every write of the budget clears it, and no
437
+ // compile runs before the boot's restore.)
438
+ if (!this.restoredAtOnce)
439
+ throw error;
440
+ this.restoredAtOnce = false;
441
+ // The persisted budget stays in the overrides, so if it can't be
442
+ // restored paced, no later write erases it.
443
+ this.setContextBudget(this.configuredContextBudgetTokens, undefined);
444
+ let outcome;
445
+ try {
446
+ this.updateRuntimeSettings({ contextBudgetTokens: live });
447
+ outcome = 'restored it as a paced descent from the recipe\'s budget';
448
+ }
449
+ catch (fallback) {
450
+ outcome = `couldn't restore it paced (${fallback instanceof Error ? fallback.message : String(fallback)}), ` +
451
+ `so it compiles at the recipe's budget, with contextBudgetTokens=${live} kept set`;
452
+ }
453
+ console.error(`[agent-settings] ${this.name}: the context manager refused contextBudgetTokens=${live}, which the boot ` +
454
+ `applied at once; ${outcome}`);
455
+ return this.compileAtLiveBudget(compile);
456
+ }
457
+ this.restoredAtOnce = false;
458
+ // A settle, here, of the descent this compile began under proves its
459
+ // target: the frontier fits the window prepared for it. Without a settle,
460
+ // the compile proves the budget it planned at. Either only if the live
461
+ // budget didn't change while it ran; a settle of a descent armed while it
462
+ // ran proves nothing (the next compile at the target does).
463
+ // A compile that ends here with a fit takes its place in the start order
464
+ // at the budget it planned at, credited or not; a settle credits its
465
+ // target only from the latest compile to end there.
466
+ const latest = this.claimLatestAt(live, started);
467
+ const sameLive = this.liveBudgetEpoch === epoch;
468
+ const sameDescent = this.descentEpoch === descent;
469
+ const settled = this.settleRuntimeSettingsTransition();
470
+ if (latest && sameLive && settled && sameDescent && this.claimLatestAt(this.contextBudgetTokens, started)) {
471
+ this.noteCompiledBudget(this.contextBudgetTokens, true, this.liveBudgetEpoch);
472
+ }
473
+ else if (latest && sameLive && !settled)
474
+ this.noteCompiledBudget(live, true, epoch);
475
+ return result;
476
+ }
477
+ /**
478
+ * The budget compiles plan at, the path a patch's budget takes from it, and
479
+ * whether a descent is in flight, from the agent's own state alone: what a
480
+ * runtime-settings preview can still say while the context manager refuses
481
+ * its queries.
482
+ * @internal For the framework's runtime-settings preview; not a host API.
483
+ */
484
+ runtimeBudgetPath(patch) {
485
+ const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
486
+ const budget = patch?.contextBudgetTokens;
487
+ return {
488
+ liveBudgetTokens: live,
489
+ path: budget === undefined ? 'none' : budget >= live || patch?.immediate ? 'immediate' : 'paced',
490
+ transition: this.contextBudgetTargetTokens === undefined ? 'stable' : 'converging',
491
+ };
492
+ }
493
+ /**
494
+ * Whether the context manager answers its queries, as its readiness says.
495
+ * It refuses them while its strategy's initialization is pending or has
496
+ * failed, until a switchBranch or setStrategy succeeds, and a strategy can
497
+ * refuse its readiness on its own, as the autobiographical one does for a
498
+ * branch it hasn't reloaded.
499
+ * @internal For the framework's runtime-settings preview; not a host API.
500
+ */
501
+ contextManagerAnswers() {
502
+ try {
503
+ this.contextManager.isReady();
504
+ return true;
505
+ }
506
+ catch {
507
+ return false;
508
+ }
509
+ }
235
510
  /**
236
511
  * Read-only mirror of `updateRuntimeSettings`' budget semantics: derive what
237
512
  * the next compile would actually plan at if `patch` were applied, WITHOUT
@@ -248,41 +523,48 @@ export class Agent {
248
523
  * - `path: 'none'` — patch absent or budget untouched.
249
524
  *
250
525
  * `overrides` uses strategy-config names (`recentWindowTokens`,
251
- * `kvStableReachTokens`) suitable for `previewContext`. `preparedWindowTokens`
252
- * is deliberately never mapped: it is strategy instance state, not config,
253
- * and cannot be simulated by a preview. A `kvStableReachTokens` override is
254
- * omitted while a prepared window is in flight — the live runtime pace
255
- * shadows the config value there, so the override would not be observed.
526
+ * `kvStableReachTokens`) suitable for `previewContext`. The reach is the one
527
+ * the next compile plans at (context-manager's kv-stable picker): a
528
+ * descent's pace while a window is prepared for it, one this patch arms (a
529
+ * paced decrease) or one in flight that it leaves alone (a patch without a
530
+ * budget), and the configured reach otherwise. Config is a preview's only
531
+ * lever: `preparedWindowTokens` and the live runtime pace are strategy
532
+ * instance state, which a preview can't set. So a preview taken during a
533
+ * descent plans under that descent's prepared window, and at its live pace
534
+ * whenever the strategy carries one, which the picker reads before the
535
+ * configured reach. A boot restore's preflight never meets this: a new
536
+ * strategy has no window.
256
537
  */
257
538
  planRuntimeSettings(patch) {
258
539
  if (patch && Object.keys(patch).length > 0) {
259
540
  this.validateRuntimeSettingsPatch(patch);
260
541
  }
261
542
  const hot = this.getHotContextSettings();
262
- const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
543
+ const { liveBudgetTokens: live, path } = this.runtimeBudgetPath(patch);
544
+ const budget = patch?.contextBudgetTokens;
263
545
  const overrides = {};
264
546
  if (patch?.tailTokens !== undefined) {
265
547
  overrides.recentWindowTokens = patch.tailTokens;
266
548
  }
267
- if (patch?.transitionPaceTokens !== undefined &&
268
- hot?.preparedWindowTokens === undefined) {
269
- overrides.kvStableReachTokens = patch.transitionPaceTokens;
549
+ // A window is prepared at the next compile when this patch arms a
550
+ // descent, or leaves one in flight alone; an immediate change clears it.
551
+ const prepared = hot !== null && (path === 'paced' || (path === 'none' && hot.preparedWindowTokens !== undefined));
552
+ const reach = prepared
553
+ ? patch?.transitionPaceTokens ?? hot.transitionPaceTokens ?? DEFAULT_TRANSITION_PACE_TOKENS
554
+ : this.configuredTransitionPaceTokens;
555
+ if (reach !== undefined && reach !== this.configuredTransitionPaceTokens) {
556
+ overrides.kvStableReachTokens = reach;
270
557
  }
271
- if (patch?.contextBudgetTokens === undefined) {
558
+ if (budget === undefined) {
272
559
  return { effectiveBudgetTokens: live, liveBudgetTokens: live, path: 'none', overrides };
273
560
  }
274
- if (patch.contextBudgetTokens >= live || patch.immediate) {
275
- return {
276
- effectiveBudgetTokens: patch.contextBudgetTokens,
277
- liveBudgetTokens: live,
278
- path: 'immediate',
279
- overrides,
280
- };
561
+ if (path === 'immediate') {
562
+ return { effectiveBudgetTokens: budget, liveBudgetTokens: live, path, overrides };
281
563
  }
282
564
  return {
283
565
  effectiveBudgetTokens: live,
284
566
  liveBudgetTokens: live,
285
- advisoryTargetTokens: patch.contextBudgetTokens,
567
+ advisoryTargetTokens: budget,
286
568
  path: 'paced',
287
569
  overrides,
288
570
  };
@@ -306,6 +588,8 @@ export class Agent {
306
588
  let nextContextBudget = this.contextBudgetTokens;
307
589
  let nextContextTarget = this.contextBudgetTargetTokens;
308
590
  let appliedDefaultPace = false;
591
+ // A paced decrease arms a descent, even to the target already set.
592
+ let armed = false;
309
593
  const hotPatch = {};
310
594
  if (patch.tailTokens !== undefined)
311
595
  hotPatch.tailTokens = patch.tailTokens;
@@ -335,23 +619,25 @@ export class Agent {
335
619
  }
336
620
  hotPatch.preparedWindowTokens = patch.contextBudgetTokens - this.maxTokens;
337
621
  nextContextTarget = patch.contextBudgetTokens;
622
+ armed = true;
338
623
  }
339
624
  }
340
625
  if (Object.keys(hotPatch).length > 0) {
341
626
  this.updateHotContextSettings(hotPatch);
342
627
  }
343
- this.contextBudgetTokens = nextContextBudget;
344
- this.contextBudgetTargetTokens = nextContextTarget;
628
+ this.setContextBudget(nextContextBudget, nextContextTarget, armed);
629
+ // A budget written here is a decision about it, whatever its value: the
630
+ // boot's at-once fallback (restoredAtOnce) no longer speaks for it.
631
+ if (patch.contextBudgetTokens !== undefined)
632
+ this.restoredAtOnce = false;
345
633
  if (appliedDefaultPace) {
346
634
  this.runtimeSettingsOverrides.transitionPaceTokens = DEFAULT_TRANSITION_PACE_TOKENS;
347
635
  }
348
- for (const [key, value] of Object.entries(patch)) {
349
- if (key === 'sameRoundThinkTextPolicy')
350
- continue;
351
- if (key === 'immediate')
352
- continue; // a mode for this apply, never a persisted setting
353
- if (value !== undefined)
354
- this.runtimeSettingsOverrides[key] = value;
636
+ // Only settings reach the override map: `immediate` is a mode for this
637
+ // apply, and nothing else a caller passes is a setting.
638
+ for (const key of ['contextBudgetTokens', 'tailTokens', 'transitionPaceTokens']) {
639
+ if (patch[key] !== undefined)
640
+ this.runtimeSettingsOverrides[key] = patch[key];
355
641
  }
356
642
  if (patch.sameRoundThinkTextPolicy !== undefined) {
357
643
  this.runtimeSettingsOverrides.sameRoundThinkTextPolicy = patch.sameRoundThinkTextPolicy;
@@ -362,6 +648,8 @@ export class Agent {
362
648
  const reset = new Set(keys ?? ['contextBudgetTokens', 'tailTokens', 'transitionPaceTokens', 'sameRoundThinkTextPolicy']);
363
649
  let nextContextBudget = this.contextBudgetTokens;
364
650
  let nextContextTarget = this.contextBudgetTargetTokens;
651
+ // A reset to a recipe budget below the live one arms a descent to it.
652
+ let armed = false;
365
653
  const hotPatch = {};
366
654
  if (reset.has('contextBudgetTokens')) {
367
655
  const configured = this.configuredContextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
@@ -375,6 +663,7 @@ export class Agent {
375
663
  hotPatch.transitionPaceTokens = DEFAULT_TRANSITION_PACE_TOKENS;
376
664
  }
377
665
  nextContextTarget = configured;
666
+ armed = true;
378
667
  }
379
668
  else {
380
669
  nextContextBudget = this.configuredContextBudgetTokens;
@@ -395,10 +684,11 @@ export class Agent {
395
684
  }
396
685
  if (Object.keys(hotPatch).length > 0)
397
686
  this.updateHotContextSettings(hotPatch);
398
- this.contextBudgetTokens = nextContextBudget;
399
- this.contextBudgetTargetTokens = nextContextTarget;
400
- if (reset.has('contextBudgetTokens'))
687
+ this.setContextBudget(nextContextBudget, nextContextTarget, armed);
688
+ if (reset.has('contextBudgetTokens')) {
401
689
  delete this.runtimeSettingsOverrides.contextBudgetTokens;
690
+ this.restoredAtOnce = false;
691
+ }
402
692
  if (reset.has('tailTokens'))
403
693
  delete this.runtimeSettingsOverrides.tailTokens;
404
694
  if (reset.has('transitionPaceTokens')) {
@@ -412,7 +702,7 @@ export class Agent {
412
702
  cancelRuntimeSettingsTransition() {
413
703
  if (this.contextBudgetTargetTokens !== undefined) {
414
704
  this.updateHotContextSettings({ preparedWindowTokens: null });
415
- this.contextBudgetTargetTokens = undefined;
705
+ this.setContextBudget(this.contextBudgetTokens, undefined);
416
706
  const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
417
707
  if (live === (this.configuredContextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS)) {
418
708
  delete this.runtimeSettingsOverrides.contextBudgetTokens;
@@ -423,10 +713,52 @@ export class Agent {
423
713
  }
424
714
  return this.getRuntimeSettings();
425
715
  }
426
- restoreRuntimeSettings(overrides) {
427
- return this.updateRuntimeSettings(overrides);
716
+ /**
717
+ * Apply persisted settings at construction. `provenBudget` is a budget the
718
+ * caller has shown fits (the framework, from the record and a preflight),
719
+ * applied at once: it stands as the last compile's until a compile here
720
+ * says otherwise. When it's below the live budget, where the proof is what
721
+ * took the restore off the paced path, a refusal of a compile at it
722
+ * restores it paced instead, until the budget is next written or a compile
723
+ * at it fits. At or above the live budget, the restore is at once either
724
+ * way, and a refusal has nothing to fall back to.
725
+ */
726
+ restoreRuntimeSettings(settings, opts) {
727
+ if (Object.keys(settings).length === 0)
728
+ return this.getRuntimeSettings();
729
+ const live = this.contextBudgetTokens ?? DEFAULT_CONTEXT_BUDGET_TOKENS;
730
+ const snapshot = this.updateRuntimeSettings(settings);
731
+ if (opts?.provenBudget !== undefined) {
732
+ this.lastCompiledBudget = { budget: opts.provenBudget, fit: true, epoch: this.liveBudgetEpoch };
733
+ this.restoredAtOnce = opts.provenBudget < live;
734
+ }
735
+ return snapshot;
736
+ }
737
+ /**
738
+ * Keep a persisted budget, tail or pace that couldn't be applied at
739
+ * construction: it stays in the override map, unapplied, so a later
740
+ * persisting write keeps it in the record. A budget is reported as the one
741
+ * set (`contextBudgetTokens`) beside the one compiles plan at
742
+ * (`effectiveContextBudgetTokens`); a tail or pace stays the strategy's.
743
+ */
744
+ keepRuntimeSettings(settings) {
745
+ for (const key of ['contextBudgetTokens', 'tailTokens', 'transitionPaceTokens']) {
746
+ if (settings[key] !== undefined)
747
+ this.runtimeSettingsOverrides[key] = settings[key];
748
+ }
428
749
  }
429
750
  validateRuntimeSettingsPatch(patch) {
751
+ this.checkRuntimeSettingsPatch(patch);
752
+ if ((patch.tailTokens !== undefined || patch.transitionPaceTokens !== undefined) &&
753
+ !this.getHotContextSettings()) {
754
+ throw new Error('The active context strategy does not support live tail/transition settings');
755
+ }
756
+ }
757
+ /**
758
+ * The checks of a runtime-settings patch that need nothing from the context manager.
759
+ * @internal For the framework's runtime-settings preview; not a host API.
760
+ */
761
+ checkRuntimeSettingsPatch(patch) {
430
762
  if (Object.keys(patch).length === 0)
431
763
  throw new Error('At least one setting is required');
432
764
  if (patch.contextBudgetTokens !== undefined) {
@@ -447,35 +779,54 @@ export class Agent {
447
779
  patch.sameRoundThinkTextPolicy !== 'private') {
448
780
  throw new Error("sameRoundThinkTextPolicy must be 'public' or 'private'");
449
781
  }
450
- if ((patch.tailTokens !== undefined || patch.transitionPaceTokens !== undefined) &&
451
- !this.getHotContextSettings()) {
452
- throw new Error('The active context strategy does not support live tail/transition settings');
453
- }
454
782
  }
783
+ /** Settle a converging budget once the window is prepared; true if it settled. */
455
784
  settleRuntimeSettingsTransition() {
456
785
  if (this.contextBudgetTargetTokens === undefined)
457
- return;
786
+ return false;
458
787
  const hot = this.getHotContextSettings();
459
788
  if (!hot?.prepared)
460
- return;
461
- this.contextBudgetTokens = this.contextBudgetTargetTokens;
462
- this.contextBudgetTargetTokens = undefined;
789
+ return false;
790
+ this.setContextBudget(this.contextBudgetTargetTokens, undefined);
463
791
  this.updateHotContextSettings({ preparedWindowTokens: null });
792
+ return true;
464
793
  }
465
794
  /**
466
795
  * RFC-006 consumed watermark: the newest stored message at the last compile
467
- * of a model request, per branch. Everything above it has never been in a
796
+ * of a model request, or at the last tool boundary that injected messages
797
+ * into a live one, per branch. Everything above it has never been in a
468
798
  * request and may still be replaced or withdrawn in place by its sender.
469
799
  */
470
800
  consumedWatermark = null;
801
+ /** Counts marks: a compile writes its watermark back only if no mark was
802
+ * made while it ran (a tool boundary's, or another compile's). */
803
+ watermarkMarks = 0;
471
804
  getConsumedWatermark() {
472
805
  return this.consumedWatermark;
473
806
  }
474
- /** Mark everything currently stored as consumed (boot, branch switch). */
807
+ /** Mark everything currently stored as consumed (the agent's creation, at
808
+ * boot or later, and a tool boundary that injected messages into the live
809
+ * stream). */
475
810
  markContextConsumed() {
476
811
  // Tolerates partial context-manager doubles (tests build Agents over
477
812
  // stubs): without a watermark nothing is ever treated as unread.
478
813
  this.consumedWatermark = this.pendingWatermark();
814
+ this.watermarkMarks++;
815
+ }
816
+ /**
817
+ * A finished compile's watermark, taken before it awaited. Within a branch
818
+ * the watermark only advances: if a mark was made while the compile ran,
819
+ * the compile's (older) one is applied only where it is later on that
820
+ * mark's branch, so a boundary's mark is never rolled back by a compile
821
+ * that started before it (a preview during a live turn).
822
+ */
823
+ applyCompileWatermark(watermark, marksBefore) {
824
+ const current = this.consumedWatermark;
825
+ if (this.watermarkMarks !== marksBefore && current
826
+ && (current.branch !== watermark.branch || current.sequence >= watermark.sequence))
827
+ return;
828
+ this.consumedWatermark = watermark;
829
+ this.watermarkMarks++;
479
830
  }
480
831
  /** The watermark a successful compile will establish (taken before, applied after). */
481
832
  pendingWatermark() {
@@ -498,29 +849,58 @@ export class Agent {
498
849
  return null;
499
850
  }
500
851
  }
852
+ /** A committing compile, as for a request that is sent: the context
853
+ * manager commits what it commits for one, the consumed watermark moves,
854
+ * and a prepared budget change settles. To inspect what the agent would
855
+ * see, use the framework's `previewActivation`, which compiles as a dry
856
+ * run. */
501
857
  async compileContext(budget) {
502
858
  // RFC-006 §3.3: consumption is determined at assembly — a compile that
503
859
  // fails assembled nothing, so the watermark moves only on success.
504
860
  const watermark = this.pendingWatermark();
505
- const result = await this.contextManager.compile(this.compileBudget(budget));
861
+ const marksBefore = this.watermarkMarks;
862
+ const compile = () => this.contextManager.compile(this.compileBudget(budget));
863
+ const result = budget ? await compile() : await this.compileAtLiveBudget(compile);
506
864
  if (watermark)
507
- this.consumedWatermark = watermark;
508
- if (!budget)
509
- this.settleRuntimeSettingsTransition();
865
+ this.applyCompileWatermark(watermark, marksBefore);
510
866
  return result;
511
867
  }
512
868
  /**
513
- * Compile the context with injections.
514
- * Same as compileContext but forwards injections (e.g. from MCPL servers)
515
- * to the context manager so they are merged into the compiled messages.
869
+ * Compile the context with injections (e.g. from MCPL servers), which the
870
+ * context manager merges into the compiled messages. Without
871
+ * `opts.dryRun` it commits as `compileContext` does: the consumed
872
+ * watermark moves, and a compile at the live window settles a prepared
873
+ * budget change. With `opts.dryRun`, for a compile that will never be
874
+ * sent, it does neither (see below).
516
875
  */
517
876
  async compileWithInjections(budget, injections, opts) {
518
- const watermark = this.pendingWatermark();
519
- const result = await this.contextManager.compile(this.compileBudget(budget), injections, opts);
877
+ // A dry run is a compile that will never be sent. The context manager
878
+ // persists no fold resolutions for it and queues none of the compression
879
+ // or merge work its fold plan calls for. Its thinking binding
880
+ // (context-manager#160, not yet released) will commit stamps and add a
881
+ // compile awaiting acceptance for a committing compile only. Here nothing
882
+ // moves either: the agent never read what a dry run assembled, so the
883
+ // consumed watermark stays. A dry run proves nothing about the budget
884
+ // either, so it goes straight to the compile, around
885
+ // compileAtLiveBudget: it settles no descent (a prepared budget change
886
+ // waits for the compile that is sent), notes no compiled budget, and
887
+ // restores nothing the boot applied at once, whether it fits or is
888
+ // refused.
889
+ //
890
+ // Context-manager 0.14 leaves what a select leaves behind as the last
891
+ // committing compile left it, on every path out of a dry run, throws
892
+ // included: no chunk record and no compression queued for a chunk the
893
+ // dry run closes, no calibration, and none of the bookkeeping the next
894
+ // compile or an observer reads (its `SelectOptions.dryRun` gives the
895
+ // contract). The one thing a dry run can still leave is the release of a
896
+ // compression hold whose deadline has passed, which `compile` does for
897
+ // any compile before it selects.
898
+ const watermark = opts?.dryRun ? null : this.pendingWatermark();
899
+ const marksBefore = this.watermarkMarks;
900
+ const compile = () => this.contextManager.compile(this.compileBudget(budget), injections, opts);
901
+ const result = budget || opts?.dryRun ? await compile() : await this.compileAtLiveBudget(compile);
520
902
  if (watermark)
521
- this.consumedWatermark = watermark;
522
- if (!budget)
523
- this.settleRuntimeSettingsTransition();
903
+ this.applyCompileWatermark(watermark, marksBefore);
524
904
  return result;
525
905
  }
526
906
  // ==========================================================================
@@ -577,15 +957,8 @@ export class Agent {
577
957
  return {
578
958
  messages: this.toolResultGuard.prepareRequest(messages, true),
579
959
  system: this.buildSystemPrompt(systemInjections),
580
- config: {
581
- model: this.model,
582
- maxTokens: this.maxTokens,
583
- ...(this.temperature !== undefined && { temperature: this.temperature }),
584
- ...(this.thinking !== undefined && { thinking: this.thinking }),
585
- },
586
960
  tools: tools.length > 0 ? tools : undefined,
587
- ...(this.providerParams && { providerParams: this.providerParams }),
588
- assistantParticipant: this.name,
961
+ ...this.requestSettings(),
589
962
  };
590
963
  };
591
964
  const request = await assemble();
@@ -657,7 +1030,12 @@ export class Agent {
657
1030
  this._state.completed.push(completed);
658
1031
  // If all tools done, transition to ready
659
1032
  if (this._state.pending.size === 0) {
660
- this._state = { status: 'ready', toolResults: this._state.completed, stream: this._state.stream };
1033
+ this._state = {
1034
+ status: 'ready',
1035
+ toolResults: this._state.completed,
1036
+ stream: this._state.stream,
1037
+ supportsInjectedMessages: this._state.supportsInjectedMessages,
1038
+ };
661
1039
  }
662
1040
  }
663
1041
  /**
@@ -671,12 +1049,18 @@ export class Agent {
671
1049
  * Build the membrane-normalized request that WOULD be emitted for this
672
1050
  * agent's next activation, given the supplied tools and injections.
673
1051
  *
674
- * This is the single source of truth for request assembly, shared by the
675
- * real activation path (`startStreamWithInjections`) and debug/preview
676
- * tooling (`Framework.previewActivation`). It is pure and non-mutating:
677
- * it does not touch agent state and does not call the membrane, and
678
- * `ContextManager.compile` is itself side-effect-free (compression runs in
679
- * the background). Safe to call regardless of the agent's current status.
1052
+ * This is the single source of truth for a framework turn's request,
1053
+ * shared by the real activation path (`startStreamWithInjections`) and
1054
+ * debug/preview tooling (`Framework.previewActivation`). It does not call
1055
+ * the membrane. The direct API (`runInferenceWithInjections`) assembles its
1056
+ * own messages, system prompt and tools, and both take the agent's
1057
+ * settings from `requestSettings()`.
1058
+ * A compile that is sent commits what the context manager commits for it
1059
+ * (fold resolutions, the compression its fold plan calls for, the consumed
1060
+ * watermark); a preview passes `options.dryRun`, so its compile commits
1061
+ * none of that (see `compileWithInjections` for what a dry run still
1062
+ * leaves). Either way the context manager is handed the compression tool
1063
+ * definitions. Safe to call regardless of the agent's current status.
680
1064
  * It doesn't wait for the tool-result guard's annotations, so a preview
681
1065
  * never waits on a workspace write (rollback, undo and redo report one), and
682
1066
  * may show a withheld stub before its place is added; the activation waits
@@ -704,7 +1088,12 @@ export class Agent {
704
1088
  system: this.buildSystemPrompt(prospectiveSystemInjections),
705
1089
  })
706
1090
  : undefined;
707
- let { messages, systemInjections } = await this.compileWithInjections(budget, injections, immutablePrefixHash ? { kvUnifiedImmutablePrefixHash: immutablePrefixHash } : undefined);
1091
+ let { messages, systemInjections } = await this.compileWithInjections(budget, injections, immutablePrefixHash || options.dryRun
1092
+ ? {
1093
+ ...(immutablePrefixHash ? { kvUnifiedImmutablePrefixHash: immutablePrefixHash } : {}),
1094
+ ...(options.dryRun ? { dryRun: true } : {}),
1095
+ }
1096
+ : undefined);
708
1097
  // Sanitize: strip empty/whitespace text blocks and drop messages left with
709
1098
  // no content. The Anthropic API rejects empty text blocks with 400
710
1099
  // "messages: text content blocks must be non-empty"; when such a block
@@ -751,15 +1140,28 @@ export class Agent {
751
1140
  return {
752
1141
  messages: this.toolResultGuard.prepareRequest(messages),
753
1142
  system: this.buildSystemPrompt(systemInjections),
1143
+ tools: availableTools.length > 0 ? availableTools : undefined,
1144
+ ...this.requestSettings(),
1145
+ ...(kvUnified ? { cacheMarkers: 'cm-owned' } : {}),
1146
+ };
1147
+ }
1148
+ /**
1149
+ * The request fields that come from this agent's own settings: its model
1150
+ * config, prompt caching and cache TTL, prefill message, provider
1151
+ * parameters and participant name. Every request the agent sends takes
1152
+ * them from here, a framework turn's (buildActivationRequest) and the
1153
+ * direct API's (runInferenceWithInjections), so a setting reaches both or
1154
+ * neither.
1155
+ */
1156
+ requestSettings() {
1157
+ return {
754
1158
  config: {
755
1159
  model: this.model,
756
1160
  maxTokens: this.maxTokens,
757
1161
  ...(this.temperature !== undefined && { temperature: this.temperature }),
758
1162
  ...(this.thinking !== undefined && { thinking: this.thinking }),
759
1163
  },
760
- tools: availableTools.length > 0 ? availableTools : undefined,
761
1164
  promptCaching: this.promptCaching,
762
- ...(kvUnified ? { cacheMarkers: 'cm-owned' } : {}),
763
1165
  cacheTtl: this.cacheTtl,
764
1166
  ...(this.prefillUserMessage && { prefillUserMessage: this.prefillUserMessage }),
765
1167
  ...(this.providerParams && { providerParams: this.providerParams }),
@@ -811,16 +1213,28 @@ export class Agent {
811
1213
  // flight" (devops agent, 2026-09-16 07:33Z, no provider error logged).
812
1214
  this.failOpenKvSubmissions();
813
1215
  this._streamId++;
1216
+ // A pending cancel belongs to the stream that was live when cancelStream()
1217
+ // ran. The stream driver collects it on that stream's terminal event, or
1218
+ // at the loop's end when the iterator closed without one, while the
1219
+ // stream still owns the agent. This clear is for the records no driver
1220
+ // collects: a dropped turn's, whose stream no driver iterates; one whose
1221
+ // stream's terminal came after another stream took the agent; or a
1222
+ // cancel after the stream's complete event. A fresh stream must not
1223
+ // inherit one and read its own later error as a deliberate stop.
1224
+ this._pendingCancel = undefined;
814
1225
  this._inferenceStartedAt = Date.now();
815
1226
  this.lastStreamInputTokens = 0;
816
1227
  // Reset the cache-inclusive counters too: a new stream must not inherit
817
1228
  // the prior stream's window size — on the physical-window restart path
818
1229
  // that inherited value IS the oversized number that caused the restart,
819
1230
  // and projecting on it before this stream's first usage event would
820
- // restart again (loop). The `> 0` guard downstream means "no usage
821
- // observed on THIS stream yet" only because of this reset.
1231
+ // restart again (loop). The `> 0` guard downstream means "no call on
1232
+ // THIS stream has reported a prompt yet" only because of this reset (a
1233
+ // call that reports none leaves these as they were, and adds to
1234
+ // lastStreamUnreportedTokens instead).
822
1235
  this.lastStreamRealInputTokens = 0;
823
1236
  this.lastStreamOutputTokens = 0;
1237
+ this.lastStreamUnreportedTokens = 0;
824
1238
  // Compiled only once each withheld stub's annotation has finished,
825
1239
  // including one that began during the compile, and after a stub edit that
826
1240
  // failed has been retried (see afterAnnotations).
@@ -898,9 +1312,10 @@ export class Agent {
898
1312
  }
899
1313
  /**
900
1314
  * Transition to waiting_for_tools when stream yields tool calls.
901
- * Called by framework's driveStream.
1315
+ * Called by framework's driveStream, with what the stream declared about
1316
+ * carrying injected messages with this round's results (see AgentState).
902
1317
  */
903
- enterWaitingForTools(calls, stream) {
1318
+ enterWaitingForTools(calls, stream, supportsInjectedMessages) {
904
1319
  const pending = new Map();
905
1320
  for (const call of calls) {
906
1321
  pending.set(call.id, {
@@ -910,7 +1325,7 @@ export class Agent {
910
1325
  startedAt: Date.now(),
911
1326
  });
912
1327
  }
913
- this._state = { status: 'waiting_for_tools', pending, completed: [], stream };
1328
+ this._state = { status: 'waiting_for_tools', pending, completed: [], stream, supportsInjectedMessages };
914
1329
  }
915
1330
  /**
916
1331
  * Add an assistant response to context.
@@ -946,18 +1361,39 @@ export class Agent {
946
1361
  setStreaming(stream) {
947
1362
  this._state = { status: 'streaming', stream };
948
1363
  }
1364
+ /** The most recent cancelStream() of a live stream, until the stream
1365
+ * driver collects it on that stream's terminal event. Its presence is
1366
+ * the signal (a reasonless Stop is still a deliberate stop); its reason
1367
+ * is the caller's own word. Membrane reports every cancel() as reason
1368
+ * 'user' — the call, not the actor — and a stream implementation may
1369
+ * report the cancel as `error` with no reason at all, so this record is
1370
+ * the only provenance a host-side cancel has. */
1371
+ _pendingCancel;
949
1372
  /**
950
- * Cancel any active stream and reset to idle.
1373
+ * Cancel the stream this agent's state holds (streaming, waiting on its
1374
+ * tools, or ready at a tool boundary with every result in), and reset to
1375
+ * idle. `reason` is provenance for the framework's inference:aborted trace
1376
+ * and marker metadata (e.g. 'zombie_reclaim', 'subagent_cancel'); it never
1377
+ * reaches the provider.
951
1378
  */
952
- cancelStream() {
953
- if (this._state.status === 'streaming') {
954
- this._state.stream.cancel();
955
- }
956
- else if (this._state.status === 'waiting_for_tools' && this._state.stream) {
1379
+ cancelStream(reason) {
1380
+ if ('stream' in this._state && this._state.stream) {
1381
+ this._pendingCancel = { reason };
957
1382
  this._state.stream.cancel();
958
1383
  }
959
1384
  this._state = { status: 'idle' };
960
1385
  }
1386
+ /** Collect (and clear) the cancel that ended the current stream, if this
1387
+ * side issued one. The stream driver calls it once, while the stream
1388
+ * still owns the agent, at the stream's terminal event (`aborted`
1389
+ * normally, `error` for implementations that report cancel() that way)
1390
+ * or at the loop's end when the stream closed without one. A record no
1391
+ * driver collects is cleared when the agent's next stream starts. */
1392
+ takeCancel() {
1393
+ const c = this._pendingCancel;
1394
+ this._pendingCancel = undefined;
1395
+ return c;
1396
+ }
961
1397
  /**
962
1398
  * Check if agent has pending tool calls.
963
1399
  */
@@ -986,18 +1422,18 @@ export class Agent {
986
1422
  return this.contextManager;
987
1423
  }
988
1424
  /**
989
- * Build the effective system prompt, appending any system-position injections.
1425
+ * Build the effective system prompt, appending any system-position
1426
+ * injections, their blocks joined by line breaks. The system prompt is
1427
+ * text, so a block of another type, such as an image a server or module
1428
+ * injected there, can't go in it: a line in its place says so. The hook
1429
+ * orchestrator tells a server's operator once per server and namespace,
1430
+ * and the module registry tells a module's once per module and namespace.
990
1431
  */
991
1432
  buildSystemPrompt(systemInjections) {
992
1433
  if (systemInjections.length === 0) {
993
1434
  return this.systemPrompt;
994
1435
  }
995
- const injectedText = systemInjections
996
- .filter((block) => block.type === 'text')
997
- .map((block) => block.text);
998
- if (injectedText.length === 0) {
999
- return this.systemPrompt;
1000
- }
1436
+ const injectedText = systemInjections.map((block) => block.type === 'text' ? block.text : `[${block.type} block not shown: the system prompt carries text only.]`);
1001
1437
  return this.systemPrompt + '\n' + injectedText.join('\n');
1002
1438
  }
1003
1439
  abortInference(reason) {
@@ -1006,10 +1442,9 @@ export class Agent {
1006
1442
  this._state.abortController.abort(reason);
1007
1443
  return { aborted: true, durationMs };
1008
1444
  }
1009
- if (this._state.status === 'streaming' ||
1010
- (this._state.status === 'waiting_for_tools' && this._state.stream)) {
1445
+ if ('stream' in this._state && this._state.stream) {
1011
1446
  const durationMs = Date.now() - this._inferenceStartedAt;
1012
- this.cancelStream();
1447
+ this.cancelStream(reason);
1013
1448
  return { aborted: true, durationMs };
1014
1449
  }
1015
1450
  return false;