@animalabs/agent-framework 0.22.1 → 0.22.2

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 (359) hide show
  1. package/README.md +1 -1
  2. package/dist/src/agent.d.ts +192 -19
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +404 -65
  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 +50 -26
  17. package/dist/src/api/server.js.map +1 -1
  18. package/dist/src/api/types.d.ts +9 -1
  19. package/dist/src/api/types.d.ts.map +1 -1
  20. package/dist/src/code-execution/py-runner.d.ts.map +1 -1
  21. package/dist/src/code-execution/py-runner.js.map +1 -1
  22. package/dist/src/framework.d.ts +393 -113
  23. package/dist/src/framework.d.ts.map +1 -1
  24. package/dist/src/framework.js +1748 -582
  25. package/dist/src/framework.js.map +1 -1
  26. package/dist/src/gate/event-gate.d.ts.map +1 -1
  27. package/dist/src/gate/gate-script.d.ts.map +1 -1
  28. package/dist/src/gate/gate-script.js.map +1 -1
  29. package/dist/src/index.d.ts +2 -2
  30. package/dist/src/index.d.ts.map +1 -1
  31. package/dist/src/index.js +2 -2
  32. package/dist/src/index.js.map +1 -1
  33. package/dist/src/mcpl/capability-grant.d.ts.map +1 -1
  34. package/dist/src/mcpl/channel-registry.d.ts +26 -7
  35. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  36. package/dist/src/mcpl/channel-registry.js +102 -22
  37. package/dist/src/mcpl/channel-registry.js.map +1 -1
  38. package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -1
  39. package/dist/src/mcpl/checkpoint-manager.js.map +1 -1
  40. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  41. package/dist/src/mcpl/errors.js.map +1 -1
  42. package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
  43. package/dist/src/mcpl/feature-set-manager.js +4 -3
  44. package/dist/src/mcpl/feature-set-manager.js.map +1 -1
  45. package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
  46. package/dist/src/mcpl/inference-router.d.ts.map +1 -1
  47. package/dist/src/mcpl/log-value.d.ts +54 -0
  48. package/dist/src/mcpl/log-value.d.ts.map +1 -0
  49. package/dist/src/mcpl/log-value.js +109 -0
  50. package/dist/src/mcpl/log-value.js.map +1 -0
  51. package/dist/src/mcpl/prose-stream-router.d.ts +6 -6
  52. package/dist/src/mcpl/prose-stream-router.d.ts.map +1 -1
  53. package/dist/src/mcpl/prose-stream-router.js +4 -4
  54. package/dist/src/mcpl/prose-stream-router.js.map +1 -1
  55. package/dist/src/mcpl/push-coalescer.d.ts +38 -3
  56. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  57. package/dist/src/mcpl/push-coalescer.js +81 -16
  58. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  59. package/dist/src/mcpl/push-handler.d.ts +26 -3
  60. package/dist/src/mcpl/push-handler.d.ts.map +1 -1
  61. package/dist/src/mcpl/push-handler.js +87 -23
  62. package/dist/src/mcpl/push-handler.js.map +1 -1
  63. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  64. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  65. package/dist/src/mcpl/references.d.ts +2 -2
  66. package/dist/src/mcpl/references.d.ts.map +1 -1
  67. package/dist/src/mcpl/references.js.map +1 -1
  68. package/dist/src/mcpl/refusal-lines.d.ts +37 -0
  69. package/dist/src/mcpl/refusal-lines.d.ts.map +1 -0
  70. package/dist/src/mcpl/refusal-lines.js +61 -0
  71. package/dist/src/mcpl/refusal-lines.js.map +1 -0
  72. package/dist/src/mcpl/scope-manager.d.ts.map +1 -1
  73. package/dist/src/mcpl/server-connection.d.ts +18 -2
  74. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  75. package/dist/src/mcpl/server-connection.js +66 -11
  76. package/dist/src/mcpl/server-connection.js.map +1 -1
  77. package/dist/src/mcpl/server-registry.d.ts.map +1 -1
  78. package/dist/src/mcpl/tool-classes.d.ts +1 -1
  79. package/dist/src/mcpl/tool-classes.d.ts.map +1 -1
  80. package/dist/src/mcpl/tool-classes.js +3 -2
  81. package/dist/src/mcpl/tool-classes.js.map +1 -1
  82. package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
  83. package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
  84. package/dist/src/mcpl/transport.d.ts +23 -5
  85. package/dist/src/mcpl/transport.d.ts.map +1 -1
  86. package/dist/src/mcpl/transport.js +103 -10
  87. package/dist/src/mcpl/transport.js.map +1 -1
  88. package/dist/src/mcpl/types.d.ts +30 -26
  89. package/dist/src/mcpl/types.d.ts.map +1 -1
  90. package/dist/src/mcpl/types.js.map +1 -1
  91. package/dist/src/module-registry.d.ts.map +1 -1
  92. package/dist/src/module-registry.js.map +1 -1
  93. package/dist/src/modules/api/index.d.ts.map +1 -1
  94. package/dist/src/modules/discord/discord-js-client.d.ts.map +1 -1
  95. package/dist/src/modules/discord/discord-js-client.js.map +1 -1
  96. package/dist/src/modules/discord/index.d.ts.map +1 -1
  97. package/dist/src/modules/discord/index.js +4 -2
  98. package/dist/src/modules/discord/index.js.map +1 -1
  99. package/dist/src/modules/health/index.d.ts.map +1 -1
  100. package/dist/src/modules/health/index.js.map +1 -1
  101. package/dist/src/modules/history/index.d.ts.map +1 -1
  102. package/dist/src/modules/history/index.js.map +1 -1
  103. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  104. package/dist/src/modules/history/semantic.js.map +1 -1
  105. package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
  106. package/dist/src/modules/workspace/branch-intent.js.map +1 -1
  107. package/dist/src/modules/workspace/disk-agreement.d.ts +22 -4
  108. package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -1
  109. package/dist/src/modules/workspace/disk-agreement.js +63 -25
  110. package/dist/src/modules/workspace/disk-agreement.js.map +1 -1
  111. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  112. package/dist/src/modules/workspace/index.d.ts +8 -4
  113. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  114. package/dist/src/modules/workspace/index.js +39 -12
  115. package/dist/src/modules/workspace/index.js.map +1 -1
  116. package/dist/src/modules/workspace/observe.d.ts +43 -8
  117. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  118. package/dist/src/modules/workspace/observe.js +264 -39
  119. package/dist/src/modules/workspace/observe.js.map +1 -1
  120. package/dist/src/modules/workspace/reconcile.d.ts +17 -1
  121. package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
  122. package/dist/src/modules/workspace/reconcile.js +57 -14
  123. package/dist/src/modules/workspace/reconcile.js.map +1 -1
  124. package/dist/src/modules/workspace/types.d.ts +27 -2
  125. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  126. package/dist/src/modules/workspace/types.js.map +1 -1
  127. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  128. package/dist/src/modules/workspace/watcher.js.map +1 -1
  129. package/dist/src/operator-log.d.ts.map +1 -1
  130. package/dist/src/operator-log.js.map +1 -1
  131. package/dist/src/provider-waits.d.ts.map +1 -1
  132. package/dist/src/provider-waits.js.map +1 -1
  133. package/dist/src/queue.d.ts.map +1 -1
  134. package/dist/src/record-journal.d.ts.map +1 -1
  135. package/dist/src/record-journal.js.map +1 -1
  136. package/dist/src/recovery/discord-awareness-outbox.d.ts.map +1 -1
  137. package/dist/src/recovery/discord-awareness-outbox.js.map +1 -1
  138. package/dist/src/recovery/offline-branch.d.ts.map +1 -1
  139. package/dist/src/recovery/offline-branch.js +29 -24
  140. package/dist/src/recovery/offline-branch.js.map +1 -1
  141. package/dist/src/recovery/recover-cli.js.map +1 -1
  142. package/dist/src/runtime/liveness-watchdog.d.ts.map +1 -1
  143. package/dist/src/runtime/liveness-watchdog.js.map +1 -1
  144. package/dist/src/shutdown.d.ts.map +1 -1
  145. package/dist/src/shutdown.js.map +1 -1
  146. package/dist/src/stored-removal.d.ts +73 -0
  147. package/dist/src/stored-removal.d.ts.map +1 -0
  148. package/dist/src/stored-removal.js +100 -0
  149. package/dist/src/stored-removal.js.map +1 -0
  150. package/dist/src/thinking-token-stamp.js.map +1 -1
  151. package/dist/src/tool-image-ledger.d.ts.map +1 -1
  152. package/dist/src/tool-image-ledger.js.map +1 -1
  153. package/dist/src/tool-presentation.d.ts.map +1 -1
  154. package/dist/src/tool-presentation.js.map +1 -1
  155. package/dist/src/tool-result-guard.d.ts.map +1 -1
  156. package/dist/src/tool-result-guard.js.map +1 -1
  157. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  158. package/dist/src/tune-out/coordinator.js.map +1 -1
  159. package/dist/src/tune-out/tools.d.ts +1 -1
  160. package/dist/src/tune-out/tools.d.ts.map +1 -1
  161. package/dist/src/types/agent.d.ts +42 -6
  162. package/dist/src/types/agent.d.ts.map +1 -1
  163. package/dist/src/types/framework.d.ts +10 -0
  164. package/dist/src/types/framework.d.ts.map +1 -1
  165. package/dist/src/types/module.d.ts +8 -4
  166. package/dist/src/types/module.d.ts.map +1 -1
  167. package/dist/src/types/trace.d.ts +61 -10
  168. package/dist/src/types/trace.d.ts.map +1 -1
  169. package/dist/src/usage/usage-tracker.d.ts.map +1 -1
  170. package/dist/test/agent-runtime-settings.test.js +1139 -3
  171. package/dist/test/agent-runtime-settings.test.js.map +1 -1
  172. package/dist/test/batched-wake-locus.test.js.map +1 -1
  173. package/dist/test/channel-label-history.test.js.map +1 -1
  174. package/dist/test/code-execution.test.js.map +1 -1
  175. package/dist/test/conversation-fork-injection-scoping.test.js.map +1 -1
  176. package/dist/test/conversation-router.test.js.map +1 -1
  177. package/dist/test/conversation-routing.test.js +240 -6
  178. package/dist/test/conversation-routing.test.js.map +1 -1
  179. package/dist/test/discord-awareness-outbox.test.js +104 -0
  180. package/dist/test/discord-awareness-outbox.test.js.map +1 -1
  181. package/dist/test/discord-typing-keepalive.test.d.ts +2 -0
  182. package/dist/test/discord-typing-keepalive.test.d.ts.map +1 -0
  183. package/dist/test/discord-typing-keepalive.test.js +77 -0
  184. package/dist/test/discord-typing-keepalive.test.js.map +1 -0
  185. package/dist/test/ephemeral-settle.test.js.map +1 -1
  186. package/dist/test/event-gate-passthrough.test.js.map +1 -1
  187. package/dist/test/event-gate-policy-mutation.test.js.map +1 -1
  188. package/dist/test/event-gate-rate-limit.test.js.map +1 -1
  189. package/dist/test/event-gate-script.test.js.map +1 -1
  190. package/dist/test/event-gate-selfwake.test.js.map +1 -1
  191. package/dist/test/event-gate-tags.test.js.map +1 -1
  192. package/dist/test/event-gate.test.js.map +1 -1
  193. package/dist/test/explicit-prose-routing.test.js +363 -42
  194. package/dist/test/explicit-prose-routing.test.js.map +1 -1
  195. package/dist/test/framework.test.js.map +1 -1
  196. package/dist/test/helpers/coalescing-fixture.d.ts +2 -0
  197. package/dist/test/helpers/coalescing-fixture.d.ts.map +1 -1
  198. package/dist/test/helpers/coalescing-fixture.js +8 -2
  199. package/dist/test/helpers/coalescing-fixture.js.map +1 -1
  200. package/dist/test/helpers/mock-membrane.d.ts.map +1 -1
  201. package/dist/test/helpers/mock-membrane.js.map +1 -1
  202. package/dist/test/hide-then-turn.test.d.ts +2 -0
  203. package/dist/test/hide-then-turn.test.d.ts.map +1 -0
  204. package/dist/test/hide-then-turn.test.js +101 -0
  205. package/dist/test/hide-then-turn.test.js.map +1 -0
  206. package/dist/test/history-module-overview.test.js.map +1 -1
  207. package/dist/test/history-module-semantic.test.js.map +1 -1
  208. package/dist/test/history-module.test.js.map +1 -1
  209. package/dist/test/history-semantic-review-findings.test.js.map +1 -1
  210. package/dist/test/host-quiesce.test.js +125 -0
  211. package/dist/test/host-quiesce.test.js.map +1 -1
  212. package/dist/test/inference-exhaustion-rewind.test.js +81 -3
  213. package/dist/test/inference-exhaustion-rewind.test.js.map +1 -1
  214. package/dist/test/inference-failure-bounds.test.js +1 -0
  215. package/dist/test/inference-failure-bounds.test.js.map +1 -1
  216. package/dist/test/kv-unified-open-flight-retry.test.js.map +1 -1
  217. package/dist/test/liveness-watchdog.test.js.map +1 -1
  218. package/dist/test/maintenance-timer.test.js +1564 -2
  219. package/dist/test/maintenance-timer.test.js.map +1 -1
  220. package/dist/test/mcp-server-bin.test.d.ts +2 -0
  221. package/dist/test/mcp-server-bin.test.d.ts.map +1 -0
  222. package/dist/test/mcp-server-bin.test.js +142 -0
  223. package/dist/test/mcp-server-bin.test.js.map +1 -0
  224. package/dist/test/mcpl-awareness-barrier.test.js.map +1 -1
  225. package/dist/test/mcpl-child-env.test.js +1 -1
  226. package/dist/test/mcpl-child-env.test.js.map +1 -1
  227. package/dist/test/mcpl-coalesced-content-parity.test.d.ts +2 -0
  228. package/dist/test/mcpl-coalesced-content-parity.test.d.ts.map +1 -0
  229. package/dist/test/mcpl-coalesced-content-parity.test.js +532 -0
  230. package/dist/test/mcpl-coalesced-content-parity.test.js.map +1 -0
  231. package/dist/test/mcpl-coalescing.test.js.map +1 -1
  232. package/dist/test/mcpl-config-diagnostics.test.js.map +1 -1
  233. package/dist/test/mcpl-gate-roundtrip.test.js.map +1 -1
  234. package/dist/test/mcpl-manifest-changed.test.js.map +1 -1
  235. package/dist/test/mcpl-reconnect-events.test.js.map +1 -1
  236. package/dist/test/mcpl-reconnect-reregistration.test.js +2 -0
  237. package/dist/test/mcpl-reconnect-reregistration.test.js.map +1 -1
  238. package/dist/test/mcpl-reference-fetcher.test.js.map +1 -1
  239. package/dist/test/mcpl-reference-fields.test.js.map +1 -1
  240. package/dist/test/mcpl-rejection-log-lines.test.d.ts +2 -0
  241. package/dist/test/mcpl-rejection-log-lines.test.d.ts.map +1 -0
  242. package/dist/test/mcpl-rejection-log-lines.test.js +349 -0
  243. package/dist/test/mcpl-rejection-log-lines.test.js.map +1 -0
  244. package/dist/test/mcpl-stderr-tail.test.d.ts +2 -0
  245. package/dist/test/mcpl-stderr-tail.test.d.ts.map +1 -0
  246. package/dist/test/mcpl-stderr-tail.test.js +210 -0
  247. package/dist/test/mcpl-stderr-tail.test.js.map +1 -0
  248. package/dist/test/mcpl-tool-lifecycle-e2e.test.js.map +1 -1
  249. package/dist/test/mcpl-tool-lifecycle-emitter.test.js.map +1 -1
  250. package/dist/test/mcpl-tool-lifecycle-script.test.js.map +1 -1
  251. package/dist/test/mcpl-tool-lifecycle.test.js.map +1 -1
  252. package/dist/test/mcpl-transport-close.test.d.ts +2 -0
  253. package/dist/test/mcpl-transport-close.test.d.ts.map +1 -0
  254. package/dist/test/mcpl-transport-close.test.js +373 -0
  255. package/dist/test/mcpl-transport-close.test.js.map +1 -0
  256. package/dist/test/mcpl-transport-spawn.test.d.ts +2 -0
  257. package/dist/test/mcpl-transport-spawn.test.d.ts.map +1 -0
  258. package/dist/test/mcpl-transport-spawn.test.js +58 -0
  259. package/dist/test/mcpl-transport-spawn.test.js.map +1 -0
  260. package/dist/test/mcpl-ws-transport.test.js +1 -0
  261. package/dist/test/mcpl-ws-transport.test.js.map +1 -1
  262. package/dist/test/offline-recovery-branch.test.js +344 -0
  263. package/dist/test/offline-recovery-branch.test.js.map +1 -1
  264. package/dist/test/operator-surgery.test.js +197 -0
  265. package/dist/test/operator-surgery.test.js.map +1 -1
  266. package/dist/test/overbudget-drain-breaker.test.js +1 -0
  267. package/dist/test/overbudget-drain-breaker.test.js.map +1 -1
  268. package/dist/test/pack-installs-alone.test.d.ts +2 -0
  269. package/dist/test/pack-installs-alone.test.d.ts.map +1 -0
  270. package/dist/test/pack-installs-alone.test.js +284 -0
  271. package/dist/test/pack-installs-alone.test.js.map +1 -0
  272. package/dist/test/physical-window-restart.test.d.ts +6 -4
  273. package/dist/test/physical-window-restart.test.d.ts.map +1 -1
  274. package/dist/test/physical-window-restart.test.js +275 -10
  275. package/dist/test/physical-window-restart.test.js.map +1 -1
  276. package/dist/test/placed-reaction-baseline.test.js.map +1 -1
  277. package/dist/test/present-while-acting.test.js +949 -6
  278. package/dist/test/present-while-acting.test.js.map +1 -1
  279. package/dist/test/provider-acceleration-cooldown.test.js.map +1 -1
  280. package/dist/test/provider-waits.test.js +67 -4
  281. package/dist/test/provider-waits.test.js.map +1 -1
  282. package/dist/test/puppet-tool-call.test.js +2 -0
  283. package/dist/test/puppet-tool-call.test.js.map +1 -1
  284. package/dist/test/reaction-baseline-platform.test.js.map +1 -1
  285. package/dist/test/record-journal.test.js.map +1 -1
  286. package/dist/test/refusal-rewind.test.js +9 -0
  287. package/dist/test/refusal-rewind.test.js.map +1 -1
  288. package/dist/test/refusal-single-call.test.js.map +1 -1
  289. package/dist/test/release-bump.test.d.ts +2 -0
  290. package/dist/test/release-bump.test.d.ts.map +1 -0
  291. package/dist/test/release-bump.test.js +248 -0
  292. package/dist/test/release-bump.test.js.map +1 -0
  293. package/dist/test/release-changelog.test.js.map +1 -1
  294. package/dist/test/release-holds.test.d.ts +2 -0
  295. package/dist/test/release-holds.test.d.ts.map +1 -0
  296. package/dist/test/release-holds.test.js +456 -0
  297. package/dist/test/release-holds.test.js.map +1 -0
  298. package/dist/test/same-round-think-policy.test.js.map +1 -1
  299. package/dist/test/shutdown-errors.test.js.map +1 -1
  300. package/dist/test/silent-heartbeat-rows.test.js.map +1 -1
  301. package/dist/test/stop-with-host-operations.test.d.ts +20 -0
  302. package/dist/test/stop-with-host-operations.test.d.ts.map +1 -0
  303. package/dist/test/stop-with-host-operations.test.js +1174 -0
  304. package/dist/test/stop-with-host-operations.test.js.map +1 -0
  305. package/dist/test/stop-with-work-in-flight.test.js +162 -50
  306. package/dist/test/stop-with-work-in-flight.test.js.map +1 -1
  307. package/dist/test/surgery-marks-receipt.test.js.map +1 -1
  308. package/dist/test/tool-batch-hook.test.js.map +1 -1
  309. package/dist/test/tool-result-guard.test.js +131 -9
  310. package/dist/test/tool-result-guard.test.js.map +1 -1
  311. package/dist/test/tool-result-spill.test.js.map +1 -1
  312. package/dist/test/tool-wrapper-prose-guard-integration.test.js.map +1 -1
  313. package/dist/test/trunk-channel-routing.test.js +330 -7
  314. package/dist/test/trunk-channel-routing.test.js.map +1 -1
  315. package/dist/test/tune-out-e2e.test.js.map +1 -1
  316. package/dist/test/unconvertible-tool-result.test.js.map +1 -1
  317. package/dist/test/unsent-compiles.test.d.ts +2 -0
  318. package/dist/test/unsent-compiles.test.d.ts.map +1 -0
  319. package/dist/test/unsent-compiles.test.js +139 -0
  320. package/dist/test/unsent-compiles.test.js.map +1 -0
  321. package/dist/test/workspace-branch-continuation.test.js.map +1 -1
  322. package/dist/test/workspace-materialize-freshness.test.js.map +1 -1
  323. package/dist/test/workspace-read-text.test.js.map +1 -1
  324. package/dist/test/workspace-three-way.test.js +907 -7
  325. package/dist/test/workspace-three-way.test.js.map +1 -1
  326. package/dist/test/workspace-watcher.test.js.map +1 -1
  327. package/dist/test/xml-round-persist.test.js.map +1 -1
  328. package/dist/tsconfig.tsbuildinfo +1 -1
  329. package/package.json +8 -6
  330. package/src/agent.ts +411 -66
  331. package/src/api/mcp-server-core.ts +681 -0
  332. package/src/api/mcp-server.ts +16 -685
  333. package/src/api/server.ts +51 -29
  334. package/src/api/types.ts +9 -1
  335. package/src/framework.ts +1899 -641
  336. package/src/index.ts +2 -2
  337. package/src/mcpl/channel-registry.ts +126 -31
  338. package/src/mcpl/feature-set-manager.ts +4 -3
  339. package/src/mcpl/log-value.ts +116 -0
  340. package/src/mcpl/prose-stream-router.ts +6 -6
  341. package/src/mcpl/push-coalescer.ts +76 -12
  342. package/src/mcpl/push-handler.ts +95 -23
  343. package/src/mcpl/refusal-lines.ts +59 -0
  344. package/src/mcpl/server-connection.ts +70 -11
  345. package/src/mcpl/tool-classes.ts +3 -2
  346. package/src/mcpl/transport.ts +105 -14
  347. package/src/mcpl/types.ts +5 -1
  348. package/src/modules/discord/index.ts +4 -2
  349. package/src/modules/workspace/disk-agreement.ts +74 -18
  350. package/src/modules/workspace/index.ts +41 -11
  351. package/src/modules/workspace/observe.ts +265 -39
  352. package/src/modules/workspace/reconcile.ts +71 -14
  353. package/src/modules/workspace/types.ts +26 -1
  354. package/src/recovery/offline-branch.ts +32 -28
  355. package/src/stored-removal.ts +126 -0
  356. package/src/types/agent.ts +42 -6
  357. package/src/types/framework.ts +10 -0
  358. package/src/types/module.ts +8 -4
  359. package/src/types/trace.ts +62 -11
@@ -104,6 +104,22 @@ export declare class ResumeBlockedError extends Error {
104
104
  preview: RuntimeSettingsPreview;
105
105
  }>);
106
106
  }
107
+ /**
108
+ * How `runEphemeralToCompletion` rejects when a retryable provider failure
109
+ * states a wait the run won't sleep: one longer than an ephemeral run sleeps
110
+ * in its turn (600 s), an infinite one, or one that is `NaN`. The run ends at
111
+ * once, without retrying inside the wait, and every other ending of the run
112
+ * rejects with a plain `Error`. `retryAfterMs` is the wait as the provider
113
+ * stated it, in milliseconds, so `Infinity` or `NaN` in those two cases: a
114
+ * host that schedules a rerun from it handles a value that isn't finite, and
115
+ * one past the 2,147,483,647 ms a timer can hold. The message says the same
116
+ * in words. A host can test `instanceof` or the `name`, which also holds for
117
+ * an error from another copy of this package.
118
+ */
119
+ export declare class ProviderWaitNotSleptError extends Error {
120
+ readonly retryAfterMs: number;
121
+ constructor(message: string, retryAfterMs: number);
122
+ }
107
123
  interface InferenceToolSnapshot {
108
124
  sameRoundThinkTextPolicy: SameRoundThinkTextPolicy;
109
125
  }
@@ -115,18 +131,19 @@ interface InferenceToolSnapshot {
115
131
  *
116
132
  * 400 and 422 are how a provider answers a request that fails its
117
133
  * validation, as a history it can't accept does, but other refusals come
118
- * back the same way, such as Anthropic's 400 for a credit balance that's too
119
- * low. A 413 is the request's size. When the newest exchange made it too
120
- * large, as an oversized attachment does, shedding that exchange may bring
121
- * the request back under the limit, and nothing else in the framework
122
- * recovers a 413; when the history as a whole is too large, the shed doesn't
123
- * help, and the breaker stops at its rewind cap. The 413 arm takes both
124
- * labels a 413 arrives under, invalid_request and context_length, because
125
- * membrane's label for a 413 differs by version and adapter. Other statuses
126
- * keep the history, since shed history can't be got back and the status
127
- * gives no sign that a shed would help: a 404 is a model or an endpoint that
128
- * doesn't exist, and 405, 409, 410 and 415 are about the HTTP request or the
129
- * resource, as a rule, rather than the conversation.
134
+ * back the same way, such as a refusal of the account that membrane doesn't
135
+ * recognize by its text. A 413 is the request's size. When the newest
136
+ * exchange made it too large, as an oversized attachment does, shedding that
137
+ * exchange may bring the request back under the limit, and nothing else in
138
+ * the framework recovers a 413; when the history as a whole is too large,
139
+ * the shed doesn't help, and the breaker stops at its rewind cap. The 413 arm
140
+ * takes both labels membranes have given a 413, invalid_request and
141
+ * context_length (see the notes below). Other statuses keep the history,
142
+ * since a shed takes the exchange out of the agent's context, which only an
143
+ * operator's undo brings back, and the status gives no sign that a shed
144
+ * would help: a 404 is a model or an endpoint that doesn't exist, and 405,
145
+ * 409, 410 and 415 are about the HTTP request or the resource, as a rule,
146
+ * rather than the conversation.
130
147
  *
131
148
  * The table test in test/inference-exhaustion-rewind.test.ts is this
132
149
  * predicate's contract. The notes below on which membrane version gives which
@@ -141,13 +158,24 @@ interface InferenceToolSnapshot {
141
158
  * adapter files every status it doesn't list (404, 405, 409, 410, 413,
142
159
  * 415, 422 …) as invalid_request, so it alone produces an invalid_request
143
160
  * at 413 or 422, and no 0.5.86 adapter produces a context_length at 413.
144
- * - From membrane #56 (merged, not yet in a release), one table serves every
145
- * adapter. Auth codes and context overflow are checked on a 400 or 422
146
- * first, a 404 is invalid_request, a 413 is context_length, and other 4xx
147
- * are invalid_request. So a 413 still sheds, an Anthropic one included,
148
- * while a context_length at 400 or 422, a token overflow, keeps the
149
- * history. The 422 arm then also covers an OpenAI-compatible server, such
150
- * as a FastAPI one, that answers a validation failure with 422.
161
+ * - From membrane 0.5.87 (membrane #56 and #107), this package's floor, every
162
+ * adapter sends an HTTP failure through one status table
163
+ * (errorFromProviderStatus). On a 400 or 422, auth codes and reasons and
164
+ * the two account refusals it recognizes by their text (a balance too low,
165
+ * usage limits reached) are auth, and a context overflow, by its code or
166
+ * text, is context_length. A 401, 402 or 403 is auth, a 408 timeout, a 429
167
+ * rate_limit, a 404 invalid_request and a 413 context_length; other 4xx
168
+ * are invalid_request. So a 413 the table types sheds, an Anthropic one
169
+ * included, while a context_length at 400 or 422, a token overflow, keeps
170
+ * the history, and so does an account refusal, which is auth. An adapter
171
+ * can type a failure before the table does, as Anthropic's does for a
172
+ * gateway's aggregate error (server). A failure with no HTTP status takes
173
+ * the status its provider code implies when the table knows the code, as
174
+ * for Anthropic's mid-stream errors, and is otherwise typed from its
175
+ * message, with no status. The 422 arm also covers an
176
+ * OpenAI-compatible server, such as a FastAPI one, that answers a
177
+ * validation failure with 422. The test of provider answers through the
178
+ * table, beside the table test, pins how the two meet at the floor.
151
179
  *
152
180
  * An error with no status, from a membrane that reports none, keeps the rule
153
181
  * the breaker had before: the type alone.
@@ -162,6 +190,10 @@ export declare class AgentFramework {
162
190
  private stopPromise;
163
191
  private stopCompleted;
164
192
  private ownedStoreClosed;
193
+ /** An operator's operations in flight, and the config materializations they
194
+ * start. stop() waits until this set is empty before it tears down, unless
195
+ * its wait budget runs out. */
196
+ private readonly operatorOperations;
165
197
  private membrane;
166
198
  private queue;
167
199
  private agents;
@@ -169,16 +201,6 @@ export declare class AgentFramework {
169
201
  private inferencePolicy;
170
202
  private errorPolicy;
171
203
  private pendingRequests;
172
- /**
173
- * Per-agent channel that triggered the agent's CURRENT inference turn, if any
174
- * (item-3 redux). Read by the ChannelRegistry's `activeChannelResolver` to
175
- * route a single-trunk agent's plain-text speech back to the channel it is
176
- * answering, instead of the process-global most-recent-inbound locus that a
177
- * concurrent message elsewhere can hijack. Set at turn start (or cleared for a
178
- * heartbeat / no-trigger turn) in startAgentStream; overwritten by the next
179
- * turn. Never read between turns (a given agent runs one turn at a time).
180
- */
181
- private activeTriggerChannels;
182
204
  private running;
183
205
  private loopPromise;
184
206
  /** Quiesce/maintenance mode (issue #122). DELIBERATELY separate from
@@ -201,6 +223,14 @@ export declare class AgentFramework {
201
223
  private maintenanceRunId;
202
224
  private currentMaintenanceRun;
203
225
  private maintenanceHistory;
226
+ /** Each agent's last reported maintenance failure, its whole text and when
227
+ * it was alerted, until its maintenance goes without one
228
+ * (reportMaintenanceFailure). */
229
+ private maintenanceFailureReported;
230
+ /** Run records whose failure repeated one already reported, and whose report was suppressed. */
231
+ private maintenanceRepeats;
232
+ /** An operator's maintain (maintenanceTick) asked for the pass running or about to run: the run it records is kept in the history whatever it met. A pass with nothing to run records none. */
233
+ private maintenancePassRequested;
204
234
  private providerGates;
205
235
  private providerAccelerationCooldowns;
206
236
  private providerAccelerationRecoveries;
@@ -222,32 +252,6 @@ export declare class AgentFramework {
222
252
  private processLoggingPersist;
223
253
  private processLoggingBroadcast;
224
254
  private activeStreams;
225
- /** Per-agent output locus FROZEN for the CURRENT logical turn. Resolved
226
- * eagerly in startAgentStream (home → addressed trigger → global default)
227
- * and never moved until the next turn: mid-turn injected messages — ambient
228
- * chatter, reactions, system markers — must not hijack where the agent's
229
- * plain prose lands (2026-07-21 Cairn lounge misroute). Lives here — not in
230
- * driveStream locals — so the pin survives a context-budget stream restart,
231
- * which continues the same logical turn in a fresh driveStream. Cleared or
232
- * re-set at the start of every non-restart turn. Since 2026-07-31 the pin
233
- * is no longer fully frozen: an ADDRESSED conversational injection — or a
234
- * conversational follow-up in a channel the agent itself explicitly sent
235
- * into this turn (turnEngagedChannels) — re-pins it at the boundary (see
236
- * the addressed re-pin block in the tool-result handler). Ambient chatter
237
- * elsewhere, reactions, and system markers still cannot move it. */
238
- private turnLocusPins;
239
- /** Channels the agent EXPLICITLY sent into during the CURRENT turn
240
- * (SEND_ENGAGEMENT_TOOLS, successful calls), per agent. Second re-pin
241
- * signal: a conversational reply in a channel the agent just engaged is
242
- * addressed by context even without a mention (2026-07-31 n=7: q's
243
- * #portables follow-up — no @mention — was answered in trailing prose
244
- * that followed the stale pin into repligate's DM). No author-kind
245
- * filter: agent-residents are full participants, and the bot flag
246
- * tracks nothing that matters (antra). Reactions/system markers are
247
- * excluded by isConversationalInjection; the engaged-this-turn scope
248
- * keeps unrelated channels from moving the pin. Cleared at every fresh
249
- * turn's start; budget restarts keep it. */
250
- private turnEngagedChannels;
251
255
  /** A tool boundary injected fresh CONVERSATIONAL input (a real message —
252
256
  * not a reaction or a system marker) into the live stream. Tells
253
257
  * driveStream to clear sticky explicit-send suppression before handling
@@ -261,12 +265,13 @@ export declare class AgentFramework {
261
265
  /** Latest bounced (undelivered) prose per agent — the `{{unsent}}` source. */
262
266
  private proseClipboards;
263
267
  /**
264
- * Each agent's routing state for its current turn (TurnRouting): the
265
- * sticky destination, the turn's destination for a resumed stream,
266
- * hybrid's hold, a `!` continuation and receipt tallies. A fresh turn starts a new object
267
- * instead of clearing the old one, and a stream that resumes the turn
268
- * (resumesLogicalTurn) keeps it. A queued delivery holds the object of the
269
- * turn that queued it, so prose a turn leaves queued when it ends (a
268
+ * Each agent's routing state for its current logical turn (TurnRouting):
269
+ * its trigger channel, locus and engaged channels, the sticky destination,
270
+ * the turn's destination, hybrid's hold, a ` !` continuation and receipt
271
+ * tallies. The start that opens a turn makes a
272
+ * new object instead of clearing the old one, and every later stream of
273
+ * the turn shares it (openLogical). A queued delivery holds the object of
274
+ * the turn that queued it, so prose a turn leaves queued when it ends (a
270
275
  * skip_reply ends it before its posts have run) still follows that turn's
271
276
  * destination, and its late writes can't reach the next turn.
272
277
  */
@@ -278,23 +283,25 @@ export declare class AgentFramework {
278
283
  */
279
284
  private proseSpeechChains;
280
285
  /**
281
- * Each agent's open logical turn (LogicalTurn). It stays open from the
282
- * fresh start that opens it until the turn settles (settleAgent: it
283
- * completes, a tool ends it, or it fails or is abandoned), and every fresh
284
- * start that routes prose while it is open continues it: a framework
285
- * retry, the start that consumes tool results the non-streaming fallback
286
- * left (whichever wake the scheduler starts it with), the later compile a
287
- * provider-capacity hold defers a turn to. A silent start neither
288
- * continues nor opens one. A stream that ends without settling needs to do
289
- * nothing to carry its turn. Settling only detaches the turn from future
290
- * starts: the settling stream keeps its own object, which its remaining
291
- * deliveries, its receipt and its ` !` check go on using (a completion
292
- * settles before it awaits its chain and writes its receipt). So every
293
- * logical end must close inheritance once, before the next fresh start:
294
- * a turn left open would hand its object, late writes and all, to an
295
- * unrelated turn. A tool-ended turn settles before the next turn can
296
- * start. Only the stream that holds the open turn closes it; disposal
297
- * drops it, and stop() clears every agent's.
286
+ * Each agent's open logical turn: its routing state and receipt tallies
287
+ * (TurnRouting). It stays open from the start that opens it until the
288
+ * turn settles (settleAgent: it completes, a tool ends it, or it fails or
289
+ * is abandoned), and every start that routes prose while it is open
290
+ * continues it with that object: a framework retry, the start that
291
+ * consumes tool results the non-streaming fallback left (whichever wake
292
+ * the scheduler starts it with), the later compile a provider-capacity
293
+ * hold defers a turn to. A silent start neither continues nor opens one,
294
+ * and leaves the open turn's object untouched (its own is the live routing
295
+ * while it runs: turnRouting). A stream that ends without
296
+ * settling needs to do nothing to carry its turn. Settling only detaches
297
+ * the turn from future starts: the settling stream keeps its own object,
298
+ * which its remaining deliveries, its receipt and its ` !` check go on
299
+ * using (a completion settles before it awaits its chain and writes its
300
+ * receipt). So every logical end must close inheritance once, before the
301
+ * next fresh start: a turn left open would hand its object, late writes
302
+ * and all, to an unrelated turn. A tool-ended turn settles before the
303
+ * next turn can start. Only the stream that holds the open turn closes
304
+ * it; disposal drops it, and stop() clears every agent's.
298
305
  */
299
306
  private openLogical;
300
307
  /** Consecutive bounce-wakes per agent; capped so an agent that keeps
@@ -357,6 +364,8 @@ export declare class AgentFramework {
357
364
  * tick counts in the success log stop meaning anything. One kick per agent
358
365
  * at a time; cleared when the kick settles (success or failure). */
359
366
  private overBudgetDrainInFlight;
367
+ /** The over-budget drain kicks running, which a branch move waits for as it waits for a maintenance pass. */
368
+ private overBudgetDrains;
360
369
  /** Per-agent current rewind episode: the single consolidated marker's id and
361
370
  * how many turns have been shed so far. One marker per episode, updated in
362
371
  * place (see updateRewindMarker); cleared when the episode ends. */
@@ -570,14 +579,35 @@ export declare class AgentFramework {
570
579
  */
571
580
  start(): void;
572
581
  /**
573
- * Stop the event loop. Failed module/MCPL cleanup can be retried with its
574
- * original context; storage stays open until that cleanup succeeds.
575
- * @param teardownTimeoutMs Optional module/MCPL wait budget. Omit to wait
576
- * until cleanup settles, as required by existing module/child contracts. This
577
- * does not bound earlier stream or event-loop quiescence, or cancel cleanup.
582
+ * Stop the event loop. After a failed or timed-out wait on operator, module
583
+ * or MCPL cleanup, storage stays open and stop() can be called again. A
584
+ * timed-out wait lets teardown go on while that work may still act on what
585
+ * is being torn down.
586
+ * @param teardownTimeoutMs Optional budget for each wait on cleanup: an
587
+ * operator's operations already running, then modules and MCPL together.
588
+ * Omit to wait until cleanup settles, as required by existing module/child
589
+ * contracts. This does not bound earlier stream, event-loop or maintenance
590
+ * quiescence (a maintenance pass or over-budget drain kick in flight), or
591
+ * cancel cleanup.
578
592
  */
579
593
  stop(teardownTimeoutMs?: number | undefined): Promise<void>;
580
594
  private resetCompletedStop;
595
+ /** Register before invoking the body, so the set holds the operation for
596
+ * its whole life: its synchronous trace callbacks can reenter stop(), and
597
+ * that stop() must find it. Invocation stays in this stack, preserving
598
+ * immediate mode changes; the returned promise carries its result to the
599
+ * caller. */
600
+ private trackOperatorOperation;
601
+ /** Whether stop() has begun: an attempt in flight (stopPromise is set before
602
+ * its body runs, which emits traces before the queue closes) or a closed
603
+ * queue (after a failed or completed stop()). The admission rule for every
604
+ * operator entry point, the host/command listener included. */
605
+ private stopHasBegun;
606
+ private refuseOperatorAfterStop;
607
+ /** Wait in rounds until the set is empty: admitted work can still start work
608
+ * of its own. All rounds share the caller's deadline rather than renewing
609
+ * its budget. */
610
+ private waitForOperatorOperations;
581
611
  private stopOwned;
582
612
  /**
583
613
  * Advance queued ContextManager work without requiring a new message.
@@ -597,6 +627,20 @@ export declare class AgentFramework {
597
627
  private flushAuxiliaryAdmission;
598
628
  private waitForAuxiliaryIdle;
599
629
  private withAuxiliaryAdmission;
630
+ /**
631
+ * Maintenance makes no provider call while a surgery holds the store. The
632
+ * surgery waits for the maintenance work that is running before it moves
633
+ * the branch, so a call that parked at the gate would make it wait on
634
+ * whatever reopens the gate: the end of a cooldown, or the retry turn a
635
+ * cooldown queues, which the hold itself keeps from starting.
636
+ */
637
+ private withdrawMaintenanceUnderSurgery;
638
+ /**
639
+ * Nor once stop() has closed provider admission: a stop that catches a
640
+ * tick is the framework stopping on purpose, so the call is withdrawn, as
641
+ * under a surgery's hold, and no failure is reported for it.
642
+ */
643
+ private withdrawMaintenanceWhenStopping;
600
644
  private auxiliaryMembraneFor;
601
645
  /**
602
646
  * A conversation agent's auxiliary calls (its context manager's
@@ -606,7 +650,11 @@ export declare class AgentFramework {
606
650
  * as a resident's are, so they bind its auxiliary calls too: a held model
607
651
  * is refused without a call, and an auxiliary call's own stated wait is
608
652
  * recorded for it. (An ephemeral run records nothing, its name being
609
- * single-use, so its context manager keeps the plain membrane.)
653
+ * single-use, so its context manager keeps the plain membrane.) Its
654
+ * compression is the background work a resident's is, whether a
655
+ * maintenance tick or a drain after a message starts it, so it is withdrawn
656
+ * as a resident's is: a call made while a surgery holds the store, or once
657
+ * stop() has closed provider admission, is withdrawn without being sent.
610
658
  */
611
659
  private conversationAuxiliaryMembraneFor;
612
660
  /** The framework's membrane, with each complete() call passed through
@@ -645,7 +693,8 @@ export declare class AgentFramework {
645
693
  */
646
694
  private nonOwningProviderWait;
647
695
  /** Why an ephemeral run ended instead of sleeping a provider's stated wait,
648
- * for its caller. */
696
+ * for its caller: the text, and the wait itself, which its rejection
697
+ * carries (ProviderWaitNotSleptError). */
649
698
  private statedWaitNotSlept;
650
699
  /** When a hold's timer next fires: at its deadline, stepped past what one
651
700
  * timer can hold. A hold with no deadline (a wait held until released, or
@@ -710,7 +759,36 @@ export declare class AgentFramework {
710
759
  private recordProviderAccelerationRecovery;
711
760
  private cancelProviderAdmission;
712
761
  private startQueuedMaintenance;
762
+ /** resume()'s refusal while a surgery holds the store. */
763
+ private refuseResumeUnderSurgery;
764
+ /** Whether maintenance work is running: a pass, or an over-budget drain kick. */
765
+ private maintenanceRunning;
766
+ /** Wait for the maintenance work that is running, whatever its outcome. */
767
+ private settleMaintenancePass;
713
768
  private runQueuedMaintenance;
769
+ /**
770
+ * One agent's maintenance failure: recorded on its run, bounded as every
771
+ * failure sink is (`record.error`), and logged and alerted for that agent
772
+ * with the whole text. A failure that lasts, such as a manager whose
773
+ * strategy failed to initialize, meets every pass, a few seconds apart. It
774
+ * is logged and alerted again only when its whole text changes, once
775
+ * opsAlert's cooldown for it has passed since the webhook last posted it
776
+ * (so the webhook, which posts a kind at most once per cooldown, hears a
777
+ * failure that lasts), or after a pass in which that agent's maintenance
778
+ * went without a failure (maintenanceFailureReported). A record whose
779
+ * failure isn't reported again is marked as a repeat, and a pass whose
780
+ * every record is a repeat that took no tick stays out of the history.
781
+ */
782
+ private reportMaintenanceFailure;
783
+ /**
784
+ * An agent's context readiness, or the error that reading it threw. The
785
+ * context manager refuses while its strategy's initialization is pending
786
+ * or has failed (context-manager 0.14), and a strategy can refuse on its
787
+ * own, as the autobiographical one does after a store-level branch switch
788
+ * it hasn't reloaded for. Every such throw is that agent's failure.
789
+ */
790
+ private contextReadiness;
791
+ /** The strategy's progress snapshot, for diagnostics: one it can't give reads as none. */
714
792
  private contextProgress;
715
793
  /**
716
794
  * A server's request or notification the host couldn't handle, answered
@@ -950,6 +1028,7 @@ export declare class AgentFramework {
950
1028
  timeoutMs?: number;
951
1029
  abandon?: boolean;
952
1030
  }): Promise<HostModeStatus>;
1031
+ private runQuiesce;
953
1032
  /** Cancel every turn-alive stream via the quiesce_abandoned kind and give
954
1033
  * teardown a bounded grace to settle. Shared by the drain-timeout path and
955
1034
  * the already-quiesced escalation path. */
@@ -965,6 +1044,7 @@ export declare class AgentFramework {
965
1044
  resume(opts?: {
966
1045
  force?: boolean;
967
1046
  }): Promise<HostModeStatus>;
1047
+ private runResume;
968
1048
  /**
969
1049
  * Land every deferred write whose target has no turn alive, one at a time,
970
1050
  * acknowledging each durably as it lands (the persisted queue is rewritten
@@ -1035,13 +1115,28 @@ export declare class AgentFramework {
1035
1115
  * were activated right now — WITHOUT running inference, opening a stream, or
1036
1116
  * mutating agent state. Intended for debug/preview tooling.
1037
1117
  *
1038
- * Transparency contract (default): the preview is side-effect-free and
1039
- * leaves no trace on the system. It does only read-only work —
1040
- * `ContextManager.compile` (which never triggers compression itself;
1041
- * compression runs in the background out-of-band), tool filtering, and
1042
- * system-prompt assembly — then delegates to `Agent.buildActivationRequest`.
1043
- * No tokens are spent, nothing is written to Chronicle, and no external
1044
- * MCPL server is contacted.
1118
+ * What a preview commits (default): nothing of its own. It compiles as a
1119
+ * dry run (`dryRun`), filters tools and assembles the system prompt, then
1120
+ * delegates to `Agent.buildActivationRequest`. No tokens are spent, no
1121
+ * external MCPL server is contacted, no fold resolution is persisted and
1122
+ * none of the compression its fold plan calls for is queued; the consumed
1123
+ * watermark and any prepared budget change are left alone; and once
1124
+ * context-manager's thinking binding (context-manager#160, not yet
1125
+ * released) ships, no stamps are committed and no compile awaits
1126
+ * acceptance. In context-manager 0.14 its dry run leaves nothing else
1127
+ * behind but the release of an expired compression hold, as any compile
1128
+ * does (see `Agent.compileWithInjections`). The preview keeps in-memory
1129
+ * bookkeeping of its own, such as handing the context manager the
1130
+ * compression tool definitions, as every activation request does.
1131
+ * Under the autobiographical strategy, a budget the context can't fit
1132
+ * still throws, as for a committing compile: a dry run skips only
1133
+ * context-manager's post-pick check, and an adaptive fold plan that
1134
+ * doesn't fit then overruns at the middle's emission, with a refusal that
1135
+ * names the tokens and the limit. Windowed passthrough's newest message
1136
+ * alone is the one window that comes back larger than the budget. For a
1137
+ * verdict instead of the refusal, `previewContextSettings` returns
1138
+ * context-manager's own at a budget, with the agent's `maxTokens` reserved
1139
+ * for the response.
1045
1140
  *
1046
1141
  * The trade-off is fidelity: the dynamically-gathered ContextInjection[]
1047
1142
  * (module `gatherContext` + MCPL `beforeInference` hooks) are NOT included
@@ -1066,15 +1161,18 @@ export declare class AgentFramework {
1066
1161
  *
1067
1162
  * Unlike `previewActivation` (which renders a request), this returns the
1068
1163
  * picker's plan: resulting tokens, whether it fits, how many summaries would
1069
- * have to be produced first, and the per-chunk fold levels. Commits nothing:
1070
- * no resolution persistence, no compression enqueue, no transition
1071
- * bookkeeping — see `AutobiographicalStrategy.previewContext`.
1164
+ * have to be produced first, and the per-chunk fold levels. It commits
1165
+ * nothing: its select is a dry run, which in context-manager 0.14 leaves
1166
+ * what a select leaves behind as the last committing compile left it —
1167
+ * see `AutobiographicalStrategy.previewContext` and
1168
+ * `Agent.compileWithInjections`.
1072
1169
  *
1073
1170
  * Returns null when the agent's strategy has no fold plan (non-adaptive).
1074
1171
  */
1075
1172
  previewContextSettings(agentName: string, budgetTokens: number, overrides?: Record<string, unknown>, opts?: {
1076
1173
  render?: boolean;
1077
1174
  }): unknown;
1175
+ private previewContextFor;
1078
1176
  /**
1079
1177
  * Feasibility preview for a runtime-settings patch — or, with no patch, for
1080
1178
  * the agent's CURRENT settings (the resume-gate case: quiesce maintenance
@@ -1089,11 +1187,18 @@ export declare class AgentFramework {
1089
1187
  * the compile budget and rejected safe-by-construction paced descents.
1090
1188
  *
1091
1189
  * Never throws for preview-layer reasons: strategy without previewContext,
1092
- * preview overlap, stale branch generation, and the hierarchical (non-
1093
- * adaptive) path all come back as `{available: false, reason}`. Unknown
1094
- * agent still throws, matching the sibling accessors.
1190
+ * preview overlap, stale branch generation, the hierarchical (non-
1191
+ * adaptive) path, and a context manager that refuses its queries (its
1192
+ * strategy's initialization pending or failed) all come back as
1193
+ * `{available: false, reason}`. Unknown agent still throws, matching the
1194
+ * sibling accessors, and so does a patch whose values the agent refuses,
1195
+ * whatever its context manager's state. Whether the strategy takes live
1196
+ * tail and pace settings is the manager's to say, so while it refuses, a
1197
+ * patch that sets them gets no verdict either.
1095
1198
  */
1096
1199
  previewAgentRuntimeSettings(agentName: string, patch?: AgentRuntimeSettingsPatch): RuntimeSettingsPreview;
1200
+ /** previewAgentRuntimeSettings for an agent in hand: boot restore previews one not yet registered. */
1201
+ private previewRuntimeSettingsFor;
1097
1202
  /**
1098
1203
  * Check if process logging is enabled.
1099
1204
  */
@@ -1138,6 +1243,7 @@ export declare class AgentFramework {
1138
1243
  getSessionUsage(): SessionUsageSnapshot;
1139
1244
  private restoreUsageState;
1140
1245
  private persistUsageState;
1246
+ /** An agent's persisted record, or null when it has none; throws when the store can't be read. */
1141
1247
  private readAgentRuntimeSettings;
1142
1248
  private validatePersistedAgentRuntimeSettings;
1143
1249
  /** Load resident-set inline caps from framework state, dropping (loudly)
@@ -1145,6 +1251,57 @@ export declare class AgentFramework {
1145
1251
  private readPersistedToolResultInlineCaps;
1146
1252
  /** Write (cap) or clear (null) one agent's resident-set inline cap. */
1147
1253
  private persistToolResultInlineCap;
1254
+ /**
1255
+ * Apply an agent's persisted settings at boot, each on its own, the budget
1256
+ * last. A persisted setting never stops the agent booting, except a
1257
+ * think-text policy, which fails closed: an invalid one is refused before
1258
+ * this (validatePersistedAgentRuntimeSettings), and a valid one always
1259
+ * applies. A tail, pace or budget that can't be applied now (a tail or pace
1260
+ * on a strategy without live settings, a budget no longer above maxTokens,
1261
+ * a lower one restored paced on a strategy that can't prepare a smaller
1262
+ * window) is kept set but unapplied (Agent.keepRuntimeSettings), so a later
1263
+ * persisting write keeps it in the record.
1264
+ *
1265
+ * A budget below the recipe's restores as a paced descent from it, unless
1266
+ * the record carries its marker (`contextBudgetReachedTokens`, written when
1267
+ * a compile fit at it) and the preflight says it fits now: then it is
1268
+ * applied at once. The preflight plans the stored context as the context
1269
+ * manager will, with the restored tail and pace, so it sees what a restart
1270
+ * can change there: a new maxTokens (the response reserve) or strategy
1271
+ * configuration. It also sees a context that grew while the agent ran at
1272
+ * another budget after the record was written, through a persist: false
1273
+ * change. The system prompt, tools and injections are outside the context
1274
+ * manager's budget, so they don't enter it (context-manager #162). If a
1275
+ * compile at a budget applied at once this way is refused, the agent
1276
+ * restores it paced then (armed by Agent.restoreRuntimeSettings, run in
1277
+ * Agent.compileAtLiveBudgetNoting). A budget at or above the recipe's is
1278
+ * applied at once with or without the marker, as an increase always is.
1279
+ *
1280
+ * When a marked budget isn't applied at once or a setting can't be
1281
+ * applied, one line says why, what couldn't be applied, and the budget set
1282
+ * beside the one compiles plan at.
1283
+ */
1284
+ private restorePersistedRuntimeSettings;
1285
+ /**
1286
+ * What persists for an agent: its overrides, and `contextBudgetReachedTokens`
1287
+ * when the agent's proof stands for the overridden budget: a compile fit at
1288
+ * it, or the boot applied it at once on the record's proof, and the live
1289
+ * budget hasn't changed since (context-manager #162). A
1290
+ * change of budget, immediate or not, carries none until a compile at it
1291
+ * fits; arming or cancelling a descent leaves the proof as it was.
1292
+ */
1293
+ private persistedRuntimeSettingsOf;
1294
+ /**
1295
+ * A compile at the agent's live budget came out differently from the last
1296
+ * (Agent.onContextBudgetCompiled). Keep the persisted record's
1297
+ * `contextBudgetReachedTokens` true to it: written when a compile fits at
1298
+ * the record's own budget, withdrawn when the context manager refuses that
1299
+ * budget. Nothing else in the record changes, and a budget other than the
1300
+ * record's (one applied with `persist: false`, or a descent's starting
1301
+ * budget) writes nothing. A record that can't be read, or written, is
1302
+ * logged, and the next compile at that budget tells it again.
1303
+ */
1304
+ private recordCompiledContextBudget;
1148
1305
  private persistAgentRuntimeSettings;
1149
1306
  /** Persist (or clear, with null) the host quiesce mode. First process-global
1150
1307
  * key in the framework/state slot: quiesce survives a restart BY DESIGN — a
@@ -1179,6 +1336,17 @@ export declare class AgentFramework {
1179
1336
  * events after an ephemeral/conversation agent has been disposed. */
1180
1337
  private recordLogicalTurnToolCalls;
1181
1338
  private recordEphemeralToolCalls;
1339
+ /**
1340
+ * A start dropped before its stream sends anything (its agent was replaced,
1341
+ * or stop() closed admission or ended the lifecycle the start began in)
1342
+ * ends the logical turn it was running. stop() ends every open turn
1343
+ * (openLogical), but a fresh start that awaited its batches' assembly
1344
+ * across a stop() reaches its routing after it and opens its turn. That
1345
+ * turn would then stay open, and the agent's first start after a restart
1346
+ * would continue the dropped turn's routing. The identity check leaves any
1347
+ * other turn open.
1348
+ */
1349
+ private endDroppedTurn;
1182
1350
  /** A logical turn's end, for every agent: it closes the agent's open
1183
1351
  * logical turn when it is the settling stream's own (openLogical), and
1184
1352
  * settles an active ephemeral run. The run's tool-call count comes from
@@ -1191,6 +1359,9 @@ export declare class AgentFramework {
1191
1359
  * The agent is temporarily registered, inference is triggered, and the
1192
1360
  * framework drives the stream (emitting traces, logging, dispatching tools).
1193
1361
  * Returns the agent's speech output when it finishes (no more tool calls).
1362
+ * Rejects with ProviderWaitNotSleptError when the run ends rather than sleep
1363
+ * a retryable failure's stated wait, and with a plain Error for any other
1364
+ * ending.
1194
1365
  *
1195
1366
  * The caller provides a pre-created agent + contextManager (from createEphemeralAgent).
1196
1367
  * The task message should already be in the context manager.
@@ -1340,6 +1511,8 @@ export declare class AgentFramework {
1340
1511
  * explicit, recorded operator override.
1341
1512
  */
1342
1513
  private handleHostCommand;
1514
+ /** handleHostCommand's work, run where stop() can wait for it. */
1515
+ private runHostCommand;
1343
1516
  /**
1344
1517
  * The last message the agent would see in its context right now, via the
1345
1518
  * transparent `previewActivation` render (no inference, no Chronicle
@@ -1370,6 +1543,22 @@ export declare class AgentFramework {
1370
1543
  * Get the most recent process logs (tail).
1371
1544
  */
1372
1545
  tailProcessLogs(count?: number, eventType?: string): ProcessLogEntryWithId[];
1546
+ /**
1547
+ * Switch the store to an existing branch, start the delivery of the
1548
+ * Discord awareness marks the move changes (startDiscordAwarenessDelivery),
1549
+ * and re-materialize the config mount from it. Resolves once the mount has
1550
+ * run; if it fails, it rejects with the store already moved. The marks'
1551
+ * delivery isn't awaited, and its failure doesn't fail the switch. The
1552
+ * store has moved by the time the call returns, before its promise
1553
+ * settles, and a refusal moves nothing. An operator's operation: refused
1554
+ * once stop() has begun, and waited for by stop() while it runs.
1555
+ *
1556
+ * The branch moves under every agent sharing the store, so the switch
1557
+ * reserves the store as a surgery does: every agent must be idle, or it is
1558
+ * refused (OperatorActionError 'agent-busy'), and no turn starts until the
1559
+ * switch is done.
1560
+ */
1561
+ switchBranch(name: string): Promise<void>;
1373
1562
  /**
1374
1563
  * Undo the last inference turn for an agent.
1375
1564
  *
@@ -1386,6 +1575,9 @@ export declare class AgentFramework {
1386
1575
  fromBranch?: string;
1387
1576
  toBranch?: string;
1388
1577
  };
1578
+ /** undoLastTurn's work, for a host/command undo already admitted: a stop()
1579
+ * begun by a trace of one of its turns doesn't refuse the next. */
1580
+ private runUndoLastTurn;
1389
1581
  /**
1390
1582
  * Redo a previously undone turn for an agent.
1391
1583
  *
@@ -1543,9 +1735,9 @@ export declare class AgentFramework {
1543
1735
  * undo or redo) without the caller awaiting it. No operator response waits
1544
1736
  * for Discord to accept marks: the MCPL data-plane gate alone holds channel
1545
1737
  * traffic that arrives after it until they are attempted.
1546
- * `syncDiscordAwarenessMarkers` installs that gate synchronously, before
1547
- * its first await, so calling this while a surgery still holds the store
1548
- * puts the gate up before the store is released. With no drain running, the
1738
+ * The sync's body installs that gate synchronously, before its first
1739
+ * await, so calling this while a surgery still holds the store puts the
1740
+ * gate up before the store is released. With no drain running, the
1549
1741
  * drain starts in the same synchronous run (the first reaction request can
1550
1742
  * be written before this returns); with one running, this generation's pass
1551
1743
  * follows it (drainForGeneration). Either way delivery continues
@@ -1556,10 +1748,20 @@ export declare class AgentFramework {
1556
1748
  * (queued when a surgery began, or arriving during its switch or fork): the
1557
1749
  * surgery's store reservation, which used to hold such a turn through the
1558
1750
  * drain, now ends once the gate is up. A failure is accounted by the gate
1559
- * itself: the current generation's failure recycles the connections, and a
1560
- * superseded one leaves that to the newer generation, whose own pass meets
1561
- * the same ledger. Here it is logged and raised as an ops alert, and the
1562
- * next sync, reconnect or start delivers what is still pending.
1751
+ * itself: the current generation's failure recycles the connections (or,
1752
+ * once the host is stopping, releases the gate instead), and a superseded
1753
+ * one leaves that to the newer generation, whose own pass meets the same
1754
+ * ledger. Here it is logged and raised as an ops alert, and the next sync,
1755
+ * reconnect or start delivers what is still pending.
1756
+ *
1757
+ * Like a server's drain, the delivery runs apart from the operation that
1758
+ * started it: it isn't an operator's operation, so stop() doesn't wait for
1759
+ * it. A drain already running when stop() begins runs on while the
1760
+ * connections close, and what it can't deliver stays pending in the
1761
+ * durable outbox. Once stop() has begun, none is started, since there's
1762
+ * no point opening a drain that the teardown is about to cut off: the
1763
+ * marks stay pending, and the next start's barrier reconciles the outbox
1764
+ * with the branch and delivers them.
1563
1765
  *
1564
1766
  * @param after What moved the branch, for the log and the alert
1565
1767
  * ("rollback", "branch switch", "undo" …).
@@ -1567,8 +1769,8 @@ export declare class AgentFramework {
1567
1769
  * branch switch that names none.
1568
1770
  */
1569
1771
  startDiscordAwarenessDelivery(after: string, agentName?: string): void;
1570
- /** Re-materialize config files from the (new) active branch — fire and
1571
- * forget; the gate picks changes up via mtime. Mirrors undoLastTurn. */
1772
+ /** Start config file IO without holding the caller or a surgery's store
1773
+ * reservation. The gate picks it up by mtime; stop() still waits for it. */
1572
1774
  private materializeConfigMountAfterBranchSwitch;
1573
1775
  /**
1574
1776
  * Check if undo/redo is available for an agent.
@@ -1651,9 +1853,10 @@ export declare class AgentFramework {
1651
1853
  /**
1652
1854
  * Spawn a persistent per-channel conversation agent ("fork") from the
1653
1855
  * template agent: own ContextManager under `conversations/{name}`, seeded
1654
- * with a copy of the template's compiled context (the SubagentModule
1655
- * wholesale-copy pattern), registered in the event loop like any agent —
1656
- * but never primary.
1856
+ * with the template's compiled context without its thinking or its unpaired
1857
+ * tool blocks (the SubagentModule wholesale-copy pattern; see the seeding
1858
+ * comment below), registered in the event loop like any agent — but never
1859
+ * primary.
1657
1860
  */
1658
1861
  private createConversationAgent;
1659
1862
  /** Persist the router's generation counters (see hydration in create()). */
@@ -1822,6 +2025,59 @@ export declare class AgentFramework {
1822
2025
  * inference; never locus-eligible itself (system + no channel metadata).
1823
2026
  */
1824
2027
  private announceLocusIfChanged;
2028
+ /**
2029
+ * The channel a message moves its turn's locus to, by the addressed
2030
+ * re-pin rule (2026-07-31, n=6 and n=7): a conversational message (not a
2031
+ * reaction or a system marker) that addressed the agent, or that follows
2032
+ * up in a channel the turn sent into (TurnRouting.engaged). Undefined for
2033
+ * any other message. A tool boundary weighs the messages it injects by it,
2034
+ * and noteArrival the ones no boundary of the turn weighs.
2035
+ */
2036
+ private repinChannel;
2037
+ /**
2038
+ * Weigh a message that no tool boundary of the agent's open logical turn
2039
+ * will weigh: one that would re-pin the locus becomes one of the turn's
2040
+ * arrivals (TurnRouting.arrivals). A message tune-out diverted
2041
+ * (metadata.tuneOut) never enters a resident's compiled view, so the agent
2042
+ * won't see it, and it moves nothing.
2043
+ */
2044
+ private noteArrival;
2045
+ /**
2046
+ * Whether `agent`'s store is the residents' one message slot, which every
2047
+ * ordinary resident reads (sharedSlotAgents). The subconscious reads that
2048
+ * slot through a merged view, but its own store is isolated, as a fork's
2049
+ * or an ephemeral agent's is.
2050
+ */
2051
+ private isOrdinaryResident;
2052
+ /**
2053
+ * Weigh a message just stored in an ordinary resident's store for every
2054
+ * other ordinary resident's open turn, running or not: residents read one
2055
+ * message slot, and a tool boundary weighs only the messages drained for
2056
+ * its own agent, so no boundary of another resident's turn weighs it.
2057
+ */
2058
+ private noteForOtherResidents;
2059
+ /**
2060
+ * The channel of the turn's newest arrival whose message is still in the
2061
+ * agent's store (TurnRouting.arrivals). A message removed since it was
2062
+ * stored, such as an unread coalesced message its server retracted, moves
2063
+ * nothing, and an earlier one that remains still does. Compression keeps a
2064
+ * message in the store; the last compile can't be the test, since an
2065
+ * arrival between the turn's streams isn't in it yet.
2066
+ */
2067
+ private remainingArrival;
2068
+ /**
2069
+ * Move a turn's locus to the channel its conversation moved to: an
2070
+ * addressed message, or a follow-up in a channel the turn engaged (the
2071
+ * addressed re-pin, repinChannel). Ambient chatter never moves it. Leaves
2072
+ * a durable `[routing]` notice in the window and updates
2073
+ * lastAnnouncedLocus once it's stored, so the next turn's announce-on-change
2074
+ * diffs against what the agent was last told. Returns the notice as stored, for a live
2075
+ * stream to inject with its boundary's other messages. Returns undefined
2076
+ * when the locus is already there, and when the notice couldn't be
2077
+ * stored. The locus has moved then too, but the announce baseline hasn't,
2078
+ * so the agent's next turn announces where its speech lands.
2079
+ */
2080
+ private repinTurnLocus;
1825
2081
  /**
1826
2082
  * Durable window notice for a channel the agent did not ask to open —
1827
2083
  * subscription-policy admission, or an open forced by the agent's own
@@ -1881,6 +2137,18 @@ export declare class AgentFramework {
1881
2137
  */
1882
2138
  private maybePrimeProseMode;
1883
2139
  private startAgentStream;
2140
+ /**
2141
+ * End a turn that beginAgentTurn drops before it sends anything. The turn
2142
+ * emitted inference:started, and listeners that bracket a turn, such as a
2143
+ * typing loop or an activity indicator, end it on a terminal event, so it
2144
+ * gets inference:aborted with `reason`, and lastInference records its end
2145
+ * as driveStream's would, when the record is still this turn's. Nothing of
2146
+ * the kind when another turn of this agent's name holds the turn token (one
2147
+ * begun after a stop and start, or by a replacement agent object): the
2148
+ * event and the record carry only the name, so this frame's would end that
2149
+ * newer turn instead.
2150
+ */
2151
+ private abortDroppedTurn;
1884
2152
  /**
1885
2153
  * Body of startAgentStream, split out so the caller's try/finally owns the
1886
2154
  * turn token unconditionally. Returns true iff the token was handed off to
@@ -1942,6 +2210,8 @@ export declare class AgentFramework {
1942
2210
  toolUseId: string;
1943
2211
  result: ToolResult;
1944
2212
  }>;
2213
+ /** puppetToolCall's work, run where stop() can wait for it. */
2214
+ private runPuppetToolCall;
1945
2215
  private executeToolCallFrom;
1946
2216
  private executeMcplToolCall;
1947
2217
  /** Event-pushing wrapper for the model-driven dispatch path. */
@@ -2252,9 +2522,16 @@ export declare class AgentFramework {
2252
2522
  /**
2253
2523
  * Reconcile the durable ledger with Chronicle, then deliver every server's
2254
2524
  * work. A drain still running is waited for and then followed by a fresh
2255
- * pass (drainForGeneration).
2256
- */
2257
- syncDiscordAwarenessMarkers(_onlyServerId?: string): Promise<void>;
2525
+ * pass (drainForGeneration). Like the other operator entry points, it's
2526
+ * refused once stop() has begun, and stop() waits for one already running.
2527
+ * The framework's own branch moves start their delivery without awaiting
2528
+ * it (startDiscordAwarenessDelivery).
2529
+ */
2530
+ syncDiscordAwarenessMarkers(onlyServerId?: string): Promise<void>;
2531
+ /** The sync's work. It installs the MCPL data-plane gate before its first
2532
+ * await, so a caller that starts it while holding the store puts the gate
2533
+ * up before releasing the store. */
2534
+ private runDiscordAwarenessSync;
2258
2535
  private resumePreparedDiscordSuppressions;
2259
2536
  /**
2260
2537
  * Deliver every due ref independently. Permanent Discord failures are kept
@@ -2385,6 +2662,7 @@ export declare class AgentFramework {
2385
2662
  * connection/handshake fails.
2386
2663
  */
2387
2664
  connectMcplServer(config: import('./mcpl/types.js').McplServerConfig): Promise<void>;
2665
+ private runConnectMcplServer;
2388
2666
  /**
2389
2667
  * Disconnect an MCPL server at runtime: close the connection, destroy its
2390
2668
  * feature-set and checkpoint state (permanent removal — unlike a transient
@@ -2393,6 +2671,7 @@ export declare class AgentFramework {
2393
2671
  * No-op-ish if the server is not connected (still clears routing state).
2394
2672
  */
2395
2673
  disconnectMcplServer(id: string): Promise<void>;
2674
+ private runDisconnectMcplServer;
2396
2675
  /**
2397
2676
  * Restart an MCPL server at runtime: disconnect, then reconnect with the
2398
2677
  * same (or an updated) config. This actually respawns a stdio child —
@@ -2400,6 +2679,7 @@ export declare class AgentFramework {
2400
2679
  * failures. Throws if the server has no stored config and none is given.
2401
2680
  */
2402
2681
  restartMcplServer(id: string, newConfig?: import('./mcpl/types.js').McplServerConfig): Promise<void>;
2682
+ private runRestartMcplServer;
2403
2683
  /**
2404
2684
  * List configured MCPL servers with live connection status and the number
2405
2685
  * of tools each currently contributes.