@animalabs/agent-framework 0.23.1 → 0.24.0

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 (338) hide show
  1. package/README.md +212 -42
  2. package/dist/src/agent.d.ts +60 -9
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +92 -12
  5. package/dist/src/agent.js.map +1 -1
  6. package/dist/src/api/server.d.ts.map +1 -1
  7. package/dist/src/api/server.js +14 -12
  8. package/dist/src/api/server.js.map +1 -1
  9. package/dist/src/code-execution/engine.d.ts +177 -0
  10. package/dist/src/code-execution/engine.d.ts.map +1 -0
  11. package/dist/src/code-execution/engine.js +494 -0
  12. package/dist/src/code-execution/engine.js.map +1 -0
  13. package/dist/src/code-execution/index.d.ts +5 -10
  14. package/dist/src/code-execution/index.d.ts.map +1 -1
  15. package/dist/src/code-execution/index.js +5 -9
  16. package/dist/src/code-execution/index.js.map +1 -1
  17. package/dist/src/code-execution/isolate/calls.d.ts +114 -0
  18. package/dist/src/code-execution/isolate/calls.d.ts.map +1 -0
  19. package/dist/src/code-execution/isolate/calls.js +145 -0
  20. package/dist/src/code-execution/isolate/calls.js.map +1 -0
  21. package/dist/src/code-execution/isolate/child-entry.d.ts +2 -0
  22. package/dist/src/code-execution/isolate/child-entry.d.ts.map +1 -0
  23. package/dist/src/code-execution/isolate/child-entry.js +5 -0
  24. package/dist/src/code-execution/isolate/child-entry.js.map +1 -0
  25. package/dist/src/code-execution/isolate/child-main.d.ts +26 -0
  26. package/dist/src/code-execution/isolate/child-main.d.ts.map +1 -0
  27. package/dist/src/code-execution/isolate/child-main.js +132 -0
  28. package/dist/src/code-execution/isolate/child-main.js.map +1 -0
  29. package/dist/src/code-execution/isolate/child.d.ts +44 -0
  30. package/dist/src/code-execution/isolate/child.d.ts.map +1 -0
  31. package/dist/src/code-execution/isolate/child.js +315 -0
  32. package/dist/src/code-execution/isolate/child.js.map +1 -0
  33. package/dist/src/code-execution/isolate/frames.d.ts +80 -0
  34. package/dist/src/code-execution/isolate/frames.d.ts.map +1 -0
  35. package/dist/src/code-execution/isolate/frames.js +210 -0
  36. package/dist/src/code-execution/isolate/frames.js.map +1 -0
  37. package/dist/src/code-execution/isolate/output.d.ts +68 -0
  38. package/dist/src/code-execution/isolate/output.d.ts.map +1 -0
  39. package/dist/src/code-execution/isolate/output.js +143 -0
  40. package/dist/src/code-execution/isolate/output.js.map +1 -0
  41. package/dist/src/code-execution/isolate/prelude.d.ts +109 -0
  42. package/dist/src/code-execution/isolate/prelude.d.ts.map +1 -0
  43. package/dist/src/code-execution/isolate/prelude.js +401 -0
  44. package/dist/src/code-execution/isolate/prelude.js.map +1 -0
  45. package/dist/src/code-execution/isolate/protocol.d.ts +151 -0
  46. package/dist/src/code-execution/isolate/protocol.d.ts.map +1 -0
  47. package/dist/src/code-execution/isolate/protocol.js +150 -0
  48. package/dist/src/code-execution/isolate/protocol.js.map +1 -0
  49. package/dist/src/code-execution/isolate/render.d.ts +57 -0
  50. package/dist/src/code-execution/isolate/render.d.ts.map +1 -0
  51. package/dist/src/code-execution/isolate/render.js +214 -0
  52. package/dist/src/code-execution/isolate/render.js.map +1 -0
  53. package/dist/src/code-execution/isolate/runner.d.ts +250 -0
  54. package/dist/src/code-execution/isolate/runner.d.ts.map +1 -0
  55. package/dist/src/code-execution/isolate/runner.js +854 -0
  56. package/dist/src/code-execution/isolate/runner.js.map +1 -0
  57. package/dist/src/code-execution/isolate/scripts.d.ts +175 -0
  58. package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -0
  59. package/dist/src/code-execution/isolate/scripts.js +357 -0
  60. package/dist/src/code-execution/isolate/scripts.js.map +1 -0
  61. package/dist/src/code-execution/quickjs.wasm +0 -0
  62. package/dist/src/code-execution/tool-definition.d.ts +93 -43
  63. package/dist/src/code-execution/tool-definition.d.ts.map +1 -1
  64. package/dist/src/code-execution/tool-definition.js +176 -142
  65. package/dist/src/code-execution/tool-definition.js.map +1 -1
  66. package/dist/src/deadline-timer.d.ts +3 -0
  67. package/dist/src/deadline-timer.d.ts.map +1 -1
  68. package/dist/src/deadline-timer.js +1 -1
  69. package/dist/src/deadline-timer.js.map +1 -1
  70. package/dist/src/framework.d.ts +1036 -440
  71. package/dist/src/framework.d.ts.map +1 -1
  72. package/dist/src/framework.js +4131 -2228
  73. package/dist/src/framework.js.map +1 -1
  74. package/dist/src/gate/event-gate.d.ts +28 -1
  75. package/dist/src/gate/event-gate.d.ts.map +1 -1
  76. package/dist/src/gate/event-gate.js +88 -10
  77. package/dist/src/gate/event-gate.js.map +1 -1
  78. package/dist/src/held-writes.d.ts +16 -3
  79. package/dist/src/held-writes.d.ts.map +1 -1
  80. package/dist/src/held-writes.js +16 -3
  81. package/dist/src/held-writes.js.map +1 -1
  82. package/dist/src/index.d.ts +6 -6
  83. package/dist/src/index.d.ts.map +1 -1
  84. package/dist/src/index.js +9 -8
  85. package/dist/src/index.js.map +1 -1
  86. package/dist/src/mcpl/channel-registry.d.ts +471 -75
  87. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  88. package/dist/src/mcpl/channel-registry.js +1673 -337
  89. package/dist/src/mcpl/channel-registry.js.map +1 -1
  90. package/dist/src/mcpl/conversation-router.d.ts +12 -7
  91. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  92. package/dist/src/mcpl/conversation-router.js +12 -7
  93. package/dist/src/mcpl/conversation-router.js.map +1 -1
  94. package/dist/src/mcpl/convert-block.d.ts.map +1 -1
  95. package/dist/src/mcpl/convert-block.js +9 -5
  96. package/dist/src/mcpl/convert-block.js.map +1 -1
  97. package/dist/src/mcpl/inbound-source.d.ts +50 -0
  98. package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
  99. package/dist/src/mcpl/inbound-source.js +130 -0
  100. package/dist/src/mcpl/inbound-source.js.map +1 -1
  101. package/dist/src/mcpl/index.d.ts +2 -1
  102. package/dist/src/mcpl/index.d.ts.map +1 -1
  103. package/dist/src/mcpl/index.js +3 -2
  104. package/dist/src/mcpl/index.js.map +1 -1
  105. package/dist/src/mcpl/log-value.d.ts +6 -0
  106. package/dist/src/mcpl/log-value.d.ts.map +1 -1
  107. package/dist/src/mcpl/log-value.js +8 -0
  108. package/dist/src/mcpl/log-value.js.map +1 -1
  109. package/dist/src/mcpl/modern-connection.d.ts +15 -6
  110. package/dist/src/mcpl/modern-connection.d.ts.map +1 -1
  111. package/dist/src/mcpl/modern-connection.js +168 -53
  112. package/dist/src/mcpl/modern-connection.js.map +1 -1
  113. package/dist/src/mcpl/prose-grammar.d.ts +4 -5
  114. package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
  115. package/dist/src/mcpl/prose-grammar.js +4 -5
  116. package/dist/src/mcpl/prose-grammar.js.map +1 -1
  117. package/dist/src/mcpl/protocol-family.d.ts +97 -10
  118. package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
  119. package/dist/src/mcpl/protocol-family.js +173 -16
  120. package/dist/src/mcpl/protocol-family.js.map +1 -1
  121. package/dist/src/mcpl/push-coalescer.d.ts +132 -14
  122. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  123. package/dist/src/mcpl/push-coalescer.js +227 -50
  124. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  125. package/dist/src/mcpl/push-handler.d.ts +6 -1
  126. package/dist/src/mcpl/push-handler.d.ts.map +1 -1
  127. package/dist/src/mcpl/push-handler.js +4 -1
  128. package/dist/src/mcpl/push-handler.js.map +1 -1
  129. package/dist/src/mcpl/reference-fetcher.d.ts +2 -2
  130. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  131. package/dist/src/mcpl/reference-fetcher.js +4 -4
  132. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  133. package/dist/src/mcpl/server-connection.d.ts +50 -21
  134. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  135. package/dist/src/mcpl/server-connection.js +158 -74
  136. package/dist/src/mcpl/server-connection.js.map +1 -1
  137. package/dist/src/mcpl/tags.d.ts +24 -0
  138. package/dist/src/mcpl/tags.d.ts.map +1 -1
  139. package/dist/src/mcpl/tags.js +33 -0
  140. package/dist/src/mcpl/tags.js.map +1 -1
  141. package/dist/src/mcpl/tool-result-normalize.d.ts +2 -1
  142. package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
  143. package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
  144. package/dist/src/mcpl/transport.d.ts +55 -7
  145. package/dist/src/mcpl/transport.d.ts.map +1 -1
  146. package/dist/src/mcpl/transport.js +163 -34
  147. package/dist/src/mcpl/transport.js.map +1 -1
  148. package/dist/src/mcpl/types.d.ts +22 -6
  149. package/dist/src/mcpl/types.d.ts.map +1 -1
  150. package/dist/src/mcpl/types.js.map +1 -1
  151. package/dist/src/module-registry.d.ts +4 -2
  152. package/dist/src/module-registry.d.ts.map +1 -1
  153. package/dist/src/module-registry.js +100 -13
  154. package/dist/src/module-registry.js.map +1 -1
  155. package/dist/src/modules/discord/index.d.ts.map +1 -1
  156. package/dist/src/modules/discord/index.js +8 -13
  157. package/dist/src/modules/discord/index.js.map +1 -1
  158. package/dist/src/modules/history/index.d.ts.map +1 -1
  159. package/dist/src/modules/history/index.js +27 -4
  160. package/dist/src/modules/history/index.js.map +1 -1
  161. package/dist/src/modules/history/semantic.d.ts +15 -3
  162. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  163. package/dist/src/modules/history/semantic.js +27 -5
  164. package/dist/src/modules/history/semantic.js.map +1 -1
  165. package/dist/src/modules/index.d.ts +1 -1
  166. package/dist/src/modules/index.d.ts.map +1 -1
  167. package/dist/src/modules/index.js.map +1 -1
  168. package/dist/src/modules/unknown-tool.d.ts +4 -1
  169. package/dist/src/modules/unknown-tool.d.ts.map +1 -1
  170. package/dist/src/modules/unknown-tool.js +4 -1
  171. package/dist/src/modules/unknown-tool.js.map +1 -1
  172. package/dist/src/modules/workspace/branch-intent.d.ts +3 -1
  173. package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
  174. package/dist/src/modules/workspace/branch-intent.js +3 -1
  175. package/dist/src/modules/workspace/branch-intent.js.map +1 -1
  176. package/dist/src/modules/workspace/edit-plan.d.ts +265 -0
  177. package/dist/src/modules/workspace/edit-plan.d.ts.map +1 -0
  178. package/dist/src/modules/workspace/edit-plan.js +794 -0
  179. package/dist/src/modules/workspace/edit-plan.js.map +1 -0
  180. package/dist/src/modules/workspace/edit-text.d.ts +117 -0
  181. package/dist/src/modules/workspace/edit-text.d.ts.map +1 -0
  182. package/dist/src/modules/workspace/edit-text.js +584 -0
  183. package/dist/src/modules/workspace/edit-text.js.map +1 -0
  184. package/dist/src/modules/workspace/effects.d.ts +5 -4
  185. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  186. package/dist/src/modules/workspace/effects.js +78 -25
  187. package/dist/src/modules/workspace/effects.js.map +1 -1
  188. package/dist/src/modules/workspace/index.d.ts +484 -61
  189. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  190. package/dist/src/modules/workspace/index.js +2173 -645
  191. package/dist/src/modules/workspace/index.js.map +1 -1
  192. package/dist/src/modules/workspace/observe.d.ts +213 -38
  193. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  194. package/dist/src/modules/workspace/observe.js +416 -36
  195. package/dist/src/modules/workspace/observe.js.map +1 -1
  196. package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
  197. package/dist/src/modules/workspace/reconcile.js +15 -8
  198. package/dist/src/modules/workspace/reconcile.js.map +1 -1
  199. package/dist/src/modules/workspace/text.d.ts +32 -0
  200. package/dist/src/modules/workspace/text.d.ts.map +1 -0
  201. package/dist/src/modules/workspace/text.js +67 -0
  202. package/dist/src/modules/workspace/text.js.map +1 -0
  203. package/dist/src/modules/workspace/types.d.ts +210 -6
  204. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  205. package/dist/src/modules/workspace/types.js.map +1 -1
  206. package/dist/src/modules/workspace/watcher.d.ts +3 -2
  207. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  208. package/dist/src/modules/workspace/watcher.js.map +1 -1
  209. package/dist/src/operator-log.d.ts +52 -24
  210. package/dist/src/operator-log.d.ts.map +1 -1
  211. package/dist/src/operator-log.js.map +1 -1
  212. package/dist/src/recovery/discord-awareness-outbox.d.ts +496 -72
  213. package/dist/src/recovery/discord-awareness-outbox.d.ts.map +1 -1
  214. package/dist/src/recovery/discord-awareness-outbox.js +1196 -289
  215. package/dist/src/recovery/discord-awareness-outbox.js.map +1 -1
  216. package/dist/src/recovery/offline-branch.d.ts +26 -1
  217. package/dist/src/recovery/offline-branch.d.ts.map +1 -1
  218. package/dist/src/recovery/offline-branch.js +164 -39
  219. package/dist/src/recovery/offline-branch.js.map +1 -1
  220. package/dist/src/recovery/recover-cli.js +23 -4
  221. package/dist/src/recovery/recover-cli.js.map +1 -1
  222. package/dist/src/send-tools.d.ts +11 -0
  223. package/dist/src/send-tools.d.ts.map +1 -0
  224. package/dist/src/send-tools.js +11 -0
  225. package/dist/src/send-tools.js.map +1 -0
  226. package/dist/src/tool-result-guard.d.ts +4 -3
  227. package/dist/src/tool-result-guard.d.ts.map +1 -1
  228. package/dist/src/tool-result-guard.js +5 -4
  229. package/dist/src/tool-result-guard.js.map +1 -1
  230. package/dist/src/tool-result-history.d.ts +1 -1
  231. package/dist/src/tool-result-history.js +1 -1
  232. package/dist/src/tune-out/coordinator.d.ts +21 -0
  233. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  234. package/dist/src/tune-out/coordinator.js +139 -37
  235. package/dist/src/tune-out/coordinator.js.map +1 -1
  236. package/dist/src/types/agent.d.ts +4 -0
  237. package/dist/src/types/agent.d.ts.map +1 -1
  238. package/dist/src/types/events.d.ts +62 -9
  239. package/dist/src/types/events.d.ts.map +1 -1
  240. package/dist/src/types/framework.d.ts +62 -58
  241. package/dist/src/types/framework.d.ts.map +1 -1
  242. package/dist/src/types/module.d.ts +40 -8
  243. package/dist/src/types/module.d.ts.map +1 -1
  244. package/dist/src/types/trace.d.ts +111 -10
  245. package/dist/src/types/trace.d.ts.map +1 -1
  246. package/dist/src/usage/types.d.ts +16 -0
  247. package/dist/src/usage/types.d.ts.map +1 -1
  248. package/dist/src/usage/usage-tracker.d.ts +14 -1
  249. package/dist/src/usage/usage-tracker.d.ts.map +1 -1
  250. package/dist/src/usage/usage-tracker.js +81 -41
  251. package/dist/src/usage/usage-tracker.js.map +1 -1
  252. package/package.json +6 -5
  253. package/src/agent.ts +93 -12
  254. package/src/api/server.ts +14 -12
  255. package/src/code-execution/engine.ts +595 -0
  256. package/src/code-execution/index.ts +5 -17
  257. package/src/code-execution/isolate/calls.ts +199 -0
  258. package/src/code-execution/isolate/child-entry.ts +5 -0
  259. package/src/code-execution/isolate/child-main.ts +132 -0
  260. package/src/code-execution/isolate/child.ts +327 -0
  261. package/src/code-execution/isolate/frames.ts +209 -0
  262. package/src/code-execution/isolate/output.ts +161 -0
  263. package/src/code-execution/isolate/prelude.ts +409 -0
  264. package/src/code-execution/isolate/protocol.ts +240 -0
  265. package/src/code-execution/isolate/render.ts +230 -0
  266. package/src/code-execution/isolate/runner.ts +911 -0
  267. package/src/code-execution/isolate/scripts.ts +479 -0
  268. package/src/code-execution/quickjs.wasm +0 -0
  269. package/src/code-execution/quickjs.wasm.LICENSES +149 -0
  270. package/src/code-execution/tool-definition.ts +236 -167
  271. package/src/deadline-timer.ts +1 -1
  272. package/src/framework.ts +4507 -2406
  273. package/src/gate/event-gate.ts +78 -11
  274. package/src/held-writes.ts +17 -3
  275. package/src/index.ts +30 -22
  276. package/src/mcpl/channel-registry.ts +1825 -368
  277. package/src/mcpl/conversation-router.ts +12 -7
  278. package/src/mcpl/convert-block.ts +9 -5
  279. package/src/mcpl/inbound-source.ts +131 -0
  280. package/src/mcpl/index.ts +4 -2
  281. package/src/mcpl/log-value.ts +9 -0
  282. package/src/mcpl/modern-connection.ts +162 -53
  283. package/src/mcpl/prose-grammar.ts +4 -5
  284. package/src/mcpl/protocol-family.ts +199 -21
  285. package/src/mcpl/push-coalescer.ts +306 -62
  286. package/src/mcpl/push-handler.ts +10 -2
  287. package/src/mcpl/reference-fetcher.ts +4 -4
  288. package/src/mcpl/server-connection.ts +180 -79
  289. package/src/mcpl/tags.ts +36 -0
  290. package/src/mcpl/tool-result-normalize.ts +2 -1
  291. package/src/mcpl/transport.ts +162 -33
  292. package/src/mcpl/types.ts +23 -6
  293. package/src/module-registry.ts +92 -13
  294. package/src/modules/discord/index.ts +8 -13
  295. package/src/modules/history/index.ts +25 -3
  296. package/src/modules/history/semantic.ts +29 -6
  297. package/src/modules/index.ts +1 -0
  298. package/src/modules/unknown-tool.ts +4 -1
  299. package/src/modules/workspace/branch-intent.ts +3 -1
  300. package/src/modules/workspace/edit-plan.ts +954 -0
  301. package/src/modules/workspace/edit-text.ts +618 -0
  302. package/src/modules/workspace/effects.ts +70 -19
  303. package/src/modules/workspace/index.ts +2247 -642
  304. package/src/modules/workspace/observe.ts +465 -56
  305. package/src/modules/workspace/reconcile.ts +14 -7
  306. package/src/modules/workspace/text.ts +68 -0
  307. package/src/modules/workspace/types.ts +211 -6
  308. package/src/modules/workspace/watcher.ts +3 -2
  309. package/src/operator-log.ts +47 -19
  310. package/src/recovery/discord-awareness-outbox.ts +1500 -356
  311. package/src/recovery/offline-branch.ts +189 -55
  312. package/src/recovery/recover-cli.ts +25 -4
  313. package/src/send-tools.ts +11 -0
  314. package/src/tool-result-guard.ts +6 -5
  315. package/src/tool-result-history.ts +1 -1
  316. package/src/tune-out/coordinator.ts +163 -42
  317. package/src/types/agent.ts +4 -0
  318. package/src/types/events.ts +62 -9
  319. package/src/types/framework.ts +62 -58
  320. package/src/types/module.ts +40 -8
  321. package/src/types/trace.ts +121 -15
  322. package/src/usage/types.ts +16 -0
  323. package/src/usage/usage-tracker.ts +86 -43
  324. package/dist/src/code-execution/py-runner.d.ts +0 -191
  325. package/dist/src/code-execution/py-runner.d.ts.map +0 -1
  326. package/dist/src/code-execution/py-runner.js +0 -655
  327. package/dist/src/code-execution/py-runner.js.map +0 -1
  328. package/dist/src/code-execution/runtime-py.d.ts +0 -50
  329. package/dist/src/code-execution/runtime-py.d.ts.map +0 -1
  330. package/dist/src/code-execution/runtime-py.js +0 -677
  331. package/dist/src/code-execution/runtime-py.js.map +0 -1
  332. package/dist/src/mcpl/prose-stream-router.d.ts +0 -88
  333. package/dist/src/mcpl/prose-stream-router.d.ts.map +0 -1
  334. package/dist/src/mcpl/prose-stream-router.js +0 -291
  335. package/dist/src/mcpl/prose-stream-router.js.map +0 -1
  336. package/src/code-execution/py-runner.ts +0 -791
  337. package/src/code-execution/runtime-py.ts +0 -677
  338. package/src/mcpl/prose-stream-router.ts +0 -268
package/README.md CHANGED
@@ -181,15 +181,24 @@ agent-framework-recover \
181
181
 
182
182
  The specified Discord message is the last message the agent will still see;
183
183
  everything after it is left on the old branch. The command scans in bounded
184
- windows, never compiles message content, activates
185
- the new Chronicle branch, and writes only Discord `{serverId, channelId,
186
- messageId}` metadata to
187
- `<store>/recovery/discord-awareness-outbox.json`. When the host and that
188
- agent's `discord-mcpl` bot reconnect, each addressable discarded message is
189
- marked with 💤. Delivery state is recorded per message: retryable failures
190
- remain queued, permanent deleted/inaccessible-message failures remain in the
191
- audit ledger without blocking later markers. Portal and other non-Discord
192
- records are ignored.
184
+ windows, never compiles message content, and activates the new Chronicle
185
+ branch. By default the recovery is local to the resident: nothing is posted to
186
+ Discord. To let the people involved see that the agent no longer has their
187
+ messages, choose awareness marks explicitly with `--marks addressed` (removed
188
+ messages that mentioned or replied to the bot, and DMs) or `--marks all`
189
+ (every removed Discord message). The output counts what will be marked and
190
+ what stays unmarked, and `--dry-run` shows exactly which addresses each choice
191
+ covers. Only `{serverId, channelId, messageId}` metadata is written, to the
192
+ awareness ledger, `<store>/recovery/discord-awareness-outbox.json`, and the
193
+ marks are delivered when the host and that agent's `discord-mcpl` bot next
194
+ connect (see
195
+ [Live surgery and Discord awareness marks](#live-surgery-and-discord-awareness-marks)).
196
+ If the branch is made but the marks can't be recorded, the output's `markers`
197
+ says so and the branch stands. The live controls described below list, cancel
198
+ and retract marks; with the host stopped there are none, so a chosen batch is
199
+ stopped by starting the host and cancelling it, and a few of its marks may go
200
+ out first.
201
+ Portal and other non-Discord records are ignored.
193
202
 
194
203
  When the safe point is an assistant/tool-side record rather than a Discord
195
204
  message, use its exact ContextManager message ID:
@@ -222,7 +231,7 @@ agent-framework-recover \
222
231
  `--suppress-range <first>..<last>` suppresses the inclusive context interval
223
232
  between two Discord messages, including intervening agent/tool entries. These
224
233
  removals exist only on the recovery branch; the source branch remains intact.
225
- Suppressed Discord messages are queued for the same 💤 awareness marker.
234
+ Suppressed Discord messages follow the same `--marks` choice.
226
235
  Selections that split a sharded body group or a tool-use/tool-result exchange
227
236
  are rejected. The suppression plan is journaled before the branch switch; if
228
237
  the recovery process is interrupted between interval removals, framework
@@ -232,22 +241,7 @@ For old stores whose messages lack `metadata.serverId`, supply
232
241
  normal agent host must be stopped while this command has the Chronicle store
233
242
  open.
234
243
 
235
- The marker sidecar is a retained operation ledger, not a delete-on-success
236
- queue. Switching back to the source branch queues removal of the bot's marker;
237
- returning to the recovery branch queues it again. Initial MCPL events remain
238
- buffered until the ledger has been reconciled. Startup, reconnect, runtime
239
- list-change, and online undo use one framework-global generation: every MCPL
240
- data plane waits while the control planes remain live for registration and
241
- marker service. A connection whose policy exchange is in flight, after a
242
- connect or a reconnect, keeps both planes closed until the exchange settles,
243
- since its traffic is admitted against the grant the exchange establishes.
244
- Awareness marker calls also have a mandatory deadline that is
245
- independent of `requestTimeoutMs` (including when that value is `0`); configure
246
- it with `discordAwarenessDeadlineMs` (default 10000ms, clamped to 50..60000ms).
247
- Configure the online marker with `discordAwarenessEmoji`; the offline CLI
248
- accepts `--emoji`.
249
-
250
- For stdio MCPL children, the framework defaults `DISCORD_SUPPRESSED_REACTIONS_BASELINE` to the reactions it places: its refusal markers, the Discord adapter's default awareness marker, the configured awareness marker, and every retained outbox emoji. This covers later removals and replays after a configuration change. Suppression is by emoji, so members' own reactions with those emoji stop reaching the agent too. The default is derived at each spawn of a child (its first connect, each automatic reconnect, a restart), so the next child spawned gets the markers retained since the last spawn. When the awareness ledger exists but can't be read, a runtime connect reads it first and refuses before anything is registered or spawned (a startup connect, whose routing is staged beforehand, before anything spawns), and a restart refuses before it stops the running child. An automatic reconnect of a child that takes the default fails and retries rather than spawn it without the default. A value with tokens in the server's env (case-insensitive on Windows), or one intentionally inherited with `inheritEnv: true`, takes precedence, and the framework logs that it replaces the default. A value with no tokens, as discord-mcpl's parser reads them, counts as unset, since the adapter would read it as suppression off. The parser splits on commas and keeps a token only when its normalizer leaves something of it, after stripping U+FE0F, trimming, and stripping one leading and one trailing colon: so a blank value, commas alone, `:`, `::` or a lone U+FE0F (say from `${A},${B}` or `:${NAME}:` with the variables empty) has no tokens. The adapter's filters file and legacy operator env still take precedence over this variable, and they are where an operator turns suppression off.
244
+ For stdio MCPL children, the framework defaults `DISCORD_SUPPRESSED_REACTIONS_BASELINE` to the reactions it places: its refusal markers, the Discord adapter's default awareness marker, the configured awareness marker, and every retained outbox emoji. This covers later removals and replays after a configuration change. Suppression is by emoji, so members' own reactions with those emoji stop reaching the agent too. The default is derived at each spawn of a child (its first connect, each automatic reconnect, a restart), so the next child spawned gets the markers retained since the last spawn. The ledger is read once and held, and read from its file again only after a write to it failed. When it can't be read, a runtime connect of a child that takes the default refuses before anything is registered or spawned (a startup connect, whose routing is staged beforehand, before anything spawns), and a restart of one refuses before it stops the running child; a child with a baseline of its own, and a WebSocket server, connect and restart whatever the ledger's state. An automatic reconnect of a child that takes the default fails and retries rather than spawn it without the default. A value with tokens in the server's env (case-insensitive on Windows), or one intentionally inherited with `inheritEnv: true`, takes precedence, and the framework logs that it replaces the default. A value with no tokens, as discord-mcpl's parser reads them, counts as unset, since the adapter would read it as suppression off. The parser splits on commas and keeps a token only when its normalizer leaves something of it, after stripping U+FE0F, trimming, and stripping one leading and one trailing colon: so a blank value, commas alone, `:`, `::` or a lone U+FE0F (say from `${A},${B}` or `:${NAME}:` with the variables empty) has no tokens. The adapter's filters file and legacy operator env still take precedence over this variable, and they are where an operator turns suppression off.
251
245
 
252
246
  `framework.getPlacedReactionBaseline()` returns a fresh snapshot of that default for other embeddings, including separately managed WebSocket adapters. It returns suppression tokens, with a custom emoji as its bare ID, not marker payloads for adding, removing or replaying a reaction. An unreadable awareness ledger throws instead of producing a partial snapshot. Hosts that previously supplied a refusal-only default must stop supplying it to adopt this framework-derived default; an explicit operator choice should remain intact.
253
247
 
@@ -312,7 +306,7 @@ configuration chooses the family, and nothing is probed:
312
306
 
313
307
  | Configuration | Family | Transport |
314
308
  |---|---|---|
315
- | `url: 'ws://…'` / `'wss://…'` | MCPL (MCP `2024-11-05`) | WebSocket |
309
+ | `url: 'ws://…'` / `'wss://…'` | MCPL (MCP `2024-11-05`) | WebSocket (`token` / `accessProvider` as `?token=`, or as bearer with `tokenTransport: 'header'`) |
316
310
  | `url: 'http://…'` / `'https://…'` | modern MCP | Streamable HTTP (`token` / `accessProvider` as bearer) |
317
311
  | `command` | MCPL | stdio |
318
312
  | `command` + `protocol: 'modern'` | modern MCP | stdio |
@@ -329,6 +323,21 @@ configuration chooses the family, and nothing is probed:
329
323
  A configuration with both `command` and `url` needs `transport` to say which
330
324
  one is used; without it, it is refused rather than silently ignoring one.
331
325
 
326
+ A WebSocket server's credential, its `token` or what its `accessProvider`
327
+ returns for a dial, goes as a `token` query parameter by default
328
+ (`tokenTransport: 'query'`). With `tokenTransport: 'header'` it goes as an
329
+ `Authorization: Bearer` header on the upgrade instead, with no query
330
+ parameter, so it stays out of the url and of the access logs that record it;
331
+ the provider still runs at every dial and reconnect. Switch a server to
332
+ `'header'` once it reads the header. A header carries a credential as
333
+ configured only if it is printable ASCII with no space at either end, so
334
+ header mode refuses any other, without quoting it: a static `token` when the
335
+ server is added, and an access provider's at the dial. `tokenTransport` is
336
+ refused on an http(s):// server, which always sends the header, and on a
337
+ stdio server; `'header'` is refused with a url that carries a `token`
338
+ parameter or userinfo of its own, since whenever the Bearer header carries a
339
+ credential it replaces the userinfo's Basic one.
340
+
332
341
  A modern server's tools get the same prefix, `enabledTools`/`disabledTools`,
333
342
  class overrides and dispatch as an MCPL server's, and `listMcplServers()`
334
343
  shows its `family`, `protocolVersion` and `transport`. Its config differs in
@@ -368,7 +377,7 @@ revisions the server says it supports ("none listed" for an empty list), or its
368
377
  and when the list includes `2026-07-28` it says to configure the server with
369
378
  `protocol: 'modern'` (stdio) or reach it over http(s).
370
379
 
371
- Server and transport text the framework records has the server's configured credentials replaced, in both engines. That covers connection traces, console lines, stderr traces, ops alerts, and a tool call's failure as its caller, the model and the `tool:failed` trace get it. The credentials are those the configuration holds and those its dials sent: from the url as each dial sends it (a WebSocket dial sets the token in the query, which writes the whole query again, form-encoded, and an access provider's token can be in it), credential-like path segments and query names, credential-shaped or credential-named query values, and a WebSocket url's userinfo, in their encoded and decoded forms, replaced wherever they occur; every non-empty query parameter as its whole `name=value`, where no letter or digit adjoins it; the static `token`, and each token an access provider handed a dial, the newest sixteen, raw and url-encoded; and a stdio server's `env` values whose names have a part ending in a credential word, such as `GITHUB_TOKEN`, `PGPASSWORD` or `SESSION_COOKIE`, raw and url-encoded. A stdio server's command-line arguments aren't derived. Standalone strings shorter than eight characters stay unchanged because they may be ordinary words; short query values are still removed with their parameter names. Treat a submitted configuration as immutable while the server uses it: apply changes with `restartMcplServer(id, newConfig)`. Secrets neither the configuration holds nor a dial sent remain outside this filtering. JSON-RPC tool answers, and the error a host's own connect raises, pass through as sent.
380
+ Server and transport text the framework records has the server's configured credentials replaced, in both engines. That covers connection traces, console lines, stderr traces, ops alerts, and a tool call's failure as its caller, the model and the `tool:failed` trace get it. The credentials are those the configuration holds and those its dials sent: from the url as each dial sends it (a WebSocket dial sets the token in the query, which writes the whole query again, form-encoded, and an access provider's token can be in it; with `tokenTransport: 'header'` it sets none), credential-like path segments and query names, credential-shaped or credential-named query values, and a WebSocket url's userinfo, in their encoded and decoded forms, replaced wherever they occur; every non-empty query parameter as its whole `name=value`, where no letter or digit adjoins it; the static `token`, and each token an access provider handed a dial, the newest sixteen, raw and url-encoded; and a stdio server's `env` values whose names have a part ending in a credential word, such as `GITHUB_TOKEN`, `PGPASSWORD` or `SESSION_COOKIE`, raw and url-encoded. A stdio server's command and arguments aren't derived. Standalone strings shorter than eight characters stay unchanged because they may be ordinary words; short query values are still removed with their parameter names. Treat a submitted configuration as immutable while the server uses it: apply changes with `restartMcplServer(id, newConfig)`. Secrets neither the configuration holds nor a dial sent remain outside this filtering. A JSON-RPC tool answer's result passes through as sent. No error a host's own call gets, whether thrown, rejected with or in an error answer's data, carries a credential this filtering replaces, whoever wrote its words: a server's words are redacted, then bounded, where an error is built from them, the strings in an error answer's data are redacted, and an error a library raised, such as a failed modern connect's, is handed on as its name and its redacted words alone. A stdio child that couldn't be started is refused with Node's words redacted, stopping before Node's quote of a value it refused at once, and a cause that keeps Node's error's name, those words and its `code`. With a configuration that can't be read, the server's words and data are withheld. A failed handshake's `stderrTail` is the end of the server's stderr, with every credential of up to 14,336 characters that reaches into it replaced whole. A number in an error answer's data is matched as JavaScript reads it, so one with more significant digits than a double holds has lost its last digits before it's matched. A close's or a cleanup's failure carries the transports' own words, a child's pid, its server's id and the wait it was given. A connection's events are inputs to the framework's records, which redact them.
372
381
 
373
382
  #### Feature sets
374
383
 
@@ -393,22 +402,31 @@ The host advertises `eventCoalescing` (both lanes, deferred rendering,
393
402
  channel-scoped pushes, a one-hour retry window). A server may add
394
403
  `coalesce: { key }` to a `push/event` or a `channels/incoming` message so that a
395
404
  later occurrence of the same subject **replaces** the earlier one while it is
396
- still unread, and **appends** once a model has seen it; `retract: true`
397
- withdraws unread content and appends the supplied deletion notice only when
398
- some version was read (or history is unknown). `initial: true` on a create lets
399
- the host know the subject's history is complete, so a create → edit → delete
400
- that nobody read leaves no trace. `deferred: true` (push only) holds a batch of
401
- notices outside context and asks the server for the content with `push/render`
402
- when a turn is assembled.
405
+ still unread, and **appends** once it has been read (both defined below);
406
+ `retract: true` withdraws unread content and appends the supplied deletion
407
+ notice only when some version was read (or history is unknown). `initial: true`
408
+ on a create lets the host know the subject's history is complete, so a create →
409
+ edit → delete that nobody read leaves no trace. `deferred: true` (push only)
410
+ holds a batch of notices outside context and asks the server for the content
411
+ with `push/render` when a turn is assembled. Each render describes what changed
412
+ since the one before it, so neither a later render nor a notice replaces an
413
+ earlier render the model hasn't read: the newer render lands after it, and a
414
+ retraction or a later plain occurrence withdraws the unread renders, newest
415
+ first.
403
416
 
404
417
  Plain content stays in context and is delivered on arrival through the ordinary
405
418
  channel/push path; the host only remembers where it landed. "Unread" means:
406
- above the agent's consumed watermark (advanced at every compile of a model
407
- request), on the current branch, not a sharded message, and not folded into a
408
- summary by compression. On any doubt — restart, branch switch, eviction — the
409
- host appends, as it does today. There is no per-subject cap: a busy channel's
410
- unread backlog is simply its unread backlog. Receipts and subject history are
411
- kept in the `mcpl/coalescing` state (retry window 1 h); audit lines are
419
+ above the agent's consumed watermark (set when the agent is created, and
420
+ advanced at every compile of a request it sends, which a preview isn't, and at
421
+ a tool boundary that injects messages into a stream declaring it carries them,
422
+ as membrane's native path does from 0.6.0), on the current branch, not a
423
+ sharded message, and not folded into a summary by compression. A message
424
+ injected at a tool boundary whose stream doesn't say whether it carries
425
+ injections, as no membrane 0.5.x stream does, stays unread though the model
426
+ may have seen it. On any doubt — restart, branch switch, eviction — the host
427
+ appends, as it does today. There is no per-subject cap: a busy channel's unread
428
+ backlog is simply its unread backlog. Receipts and subject history are kept in
429
+ the `mcpl/coalescing` state (retry window 1 h); audit lines are
412
430
  `mcpl:coalescing` trace events.
413
431
 
414
432
  #### Per-channel conversation routing (deprecated)
@@ -474,6 +492,158 @@ stated wait with `release-provider-wait` (`agentName`, optional `model`), as
474
492
  optional shared secret (`ApiServerConfig.adminToken`, sent as `x-admin-token`)
475
493
  for deployments that front the port with a proxy.
476
494
 
495
+ ### Live surgery and Discord awareness marks
496
+
497
+ `rollbackToMessage(agent, { messageId })` forks the agent's context at a
498
+ message and switches to the fork; `suppressMessages(agent, { messageIds })`
499
+ forks at the head and removes the chosen messages on the fork. The source
500
+ branch stays intact either way. Removing Discord messages from an agent's
501
+ context is local to that agent unless the operator also chooses to mark them:
502
+
503
+ ```typescript
504
+ const preview = framework.previewSurgeryMarks('cairn', { rollbackTo: messageId });
505
+ // preview.scopes.addressed / .all: count, per-channel counts and refs
506
+ const result = await framework.rollbackToMessage('cairn', {
507
+ messageId,
508
+ marks: { scope: 'addressed', refs: preview.scopes.addressed.refs },
509
+ });
510
+ // result.markers: { status: 'none' | 'queued' | 'not-scheduled', ... }
511
+ ```
512
+
513
+ - **`marks`** is `'none'` (the default), or `{ scope: 'addressed' | 'all', refs? }`.
514
+ `addressed` covers messages tagged `chat:addressed` (mentions, replies to
515
+ the bot, DMs). Passing a preview's `refs` binds the choice to exactly that
516
+ set: messages that arrive before the surgery applies are removed locally but
517
+ never marked. Any other value is refused (`invalid`), never guessed. The
518
+ choice is recorded in the operator log.
519
+ - **The surgery returns once marks are scheduled**, never after Discord has
520
+ accepted them. `result.markers` says whether they were scheduled (`queued`
521
+ with a count and batch id), not chosen or not in scope (`none`), or not to
522
+ be delivered because recording the batch as active failed after the body
523
+ change (`not-scheduled`, whose `error` says why, and whether the batch was
524
+ retired or stays prepared for a start to retire). Every receipt also counts the removed messages left
525
+ unmarked. Marker bookkeeping never fails or undoes an applied rollback or
526
+ suppression; a batch that can't be recorded before the body change stops
527
+ the surgery before anything changes (`failed`).
528
+ - **Delivery runs in the background** and never holds MCPL traffic or turns.
529
+ MCPL's own hold stays: a connection whose policy exchange is in flight,
530
+ after a connect or a reconnect, keeps both planes closed until the
531
+ exchange settles, since its traffic is admitted against the grant the
532
+ exchange establishes. A route that is not connected keeps its work queued
533
+ until it connects.
534
+ Each reaction call has a mandatory deadline independent of
535
+ `requestTimeoutMs` (including `0`): `discordAwarenessDeadlineMs` (default
536
+ 10000ms, clamped to 50..60000ms). The emoji is `discordAwarenessEmoji`
537
+ (offline: `--emoji`). Nothing more is sent for a mark after three
538
+ unconfirmed attempts at it (Discord refused it, or no answer came and so
539
+ it may have landed, one left on the wire when the host stopped included;
540
+ an attempt refused before it left the host doesn't count), or after a
541
+ refusal no retry can change (the message, channel or emoji is gone, access
542
+ is missing, or the message takes no more reactions); a pass that gives up
543
+ on marks raises one `discord-awareness-delivery` ops alert, and so does a
544
+ start whose reconciliation gives up on any. A JSON-RPC error answer, which
545
+ may come after the server acted, counts as unanswered, unless it is such a
546
+ refusal. A mark whose request failed in a way a retry could change is sent
547
+ again by the next delivery pass: after a surgery, a retract, a start, a
548
+ connect or reconnect of its route, a tools-list change, or an operator's
549
+ sync, and a trigger that meets a pass already running has that pass try
550
+ it once more before it ends.
551
+ - **Marks are one-shot.** Switching branches, a turn undo, a redo and
552
+ restarts never request a mark or a removal of their own: what goes out is what a surgery
553
+ (the marks chosen for it) or a retract recorded, and a start's delivery
554
+ sends what of that hasn't gone out. The ledger is a table with one entry
555
+ per reaction (route, channel, message and emoji): what the acts that still
556
+ stand want of it, whether Discord is owed a request for that, and what
557
+ Discord last answered. It is a JSON file outside Chronicle,
558
+ `<store>/recovery/discord-awareness-outbox.json` (or
559
+ `discordAwarenessOutboxPath`), so it survives rollbacks, branch deletion
560
+ and a killed process. Each request is written ahead before it leaves, and
561
+ the next one is chosen from the ledger as it is then, so a cancel takes
562
+ effect even while an earlier request is on the wire. A request written and
563
+ never answered is kept as one that may land, whatever Discord answers
564
+ later. Between opposite wishes for one reaction, the later act wins: a
565
+ surgery's marks carry the moment of its choice, even when activation comes
566
+ later, so a retract made in between prevails, and cancelling it revives
567
+ nothing. A write goes to a temporary file renamed over the ledger, synced
568
+ with its directory and that directory's parent, as the framework's own
569
+ recovery files are: one that fails leaves the ledger as it was, and a
570
+ directory that can't be synced after the rename raises the `recovery-sync`
571
+ ops alert while the write stands. A write that activates, completes or
572
+ retires a batch syncs the store first, so it never outlives the change it
573
+ certifies. A ledger that can't be read, or holds a version this build
574
+ doesn't read, stops a start. A running host holds the ledger in memory and
575
+ reads the file again only after a write failed; while it then can't be
576
+ read, nothing is sent, the delivery alert says so, and the controls
577
+ refuse.
578
+ - **A start never activates a surgery's marks.** A batch an interrupted
579
+ surgery left prepared is retired at the next start, none of its marks
580
+ sent. One that had marks to apply raises a `discord-awareness-not-scheduled` ops alert that names the
581
+ surgery, its agent and its branches, and the redo that applies the marks:
582
+ run the surgery again from the source onto a new branch name, choosing
583
+ marks again, if the source still has every message the surgery removed (a
584
+ `hide` there, or the source's deletion, changes that). A batch doesn't say
585
+ which surgery made it, so the alert names an offline recovery beside a
586
+ rollback or a suppression. One with none to apply (none chosen, or its marks cancelled) is
587
+ only logged. An interrupted suppression's removals are still finished, at
588
+ the first start on its branch, and its batch is retired then. Until then
589
+ a start on any branch with that name would apply those removals there.
590
+ - **Operator controls,** each that changes the ledger recorded in the
591
+ operator log (a list or a preview records nothing); once `stop()`
592
+ has begun, cancel and retract refuse, like every operator entry
593
+ point:
594
+ - `listDiscordAwareness()` lists batches and retract requests, each with
595
+ its reactions counted by state (`queued`, `sending`, `present`,
596
+ `absent`, `unknown`, `failed` or `untouched`) and how many may still land;
597
+ - `cancelDiscordAwareness(batch | retractRequest)` stops a batch's marks or
598
+ a retract's removals from being sent or sent again, and never removes or
599
+ undoes anything. Its receipt counts what it stopped before any request
600
+ went out (`cancelled`), what Discord last confirmed as the act wanted
601
+ (`confirmed`), and the act's reactions with a request on the wire or one
602
+ never answered, any of which may still land (`mayStillLand`);
603
+ - `retractDiscordAwareness(batch | 'all')` queues removal of this bot's
604
+ reaction, through each address's configured MCPL route, for every message
605
+ of the batch (or of every batch that isn't retired, whether prepared or
606
+ active, and every reaction the ledger holds), whatever was answered
607
+ before: removing an absent reaction does nothing. As the latest act on
608
+ those reactions, it replaces the adds owed there and any an earlier
609
+ choice would owe later (a prepared batch's activation); cancelling it
610
+ never revives them. Its receipt counts the reactions on which an add may
611
+ still land, on the wire or never answered (an unanswered removal can't
612
+ bring a mark back).
613
+
614
+ Both are async. A request the ledger won't carry out (an unknown batch or
615
+ retract request) is refused as `invalid`; a failure to read or write the
616
+ ledger is `failed`. A framework with neither `storePath` nor
617
+ `discordAwarenessOutboxPath` has no ledger: it refuses a marks choice as
618
+ `invalid`, and so do its controls.
619
+ - **Over `host/command`** (servers granted `allowHostCommands`): an `undo` by
620
+ messages takes `marks: 'none' | 'addressed' | 'all'` (default `none`; any
621
+ other value is refused) and returns `markers`. It holds the store like
622
+ every surgery, so it is refused while any agent sharing the store is
623
+ mid-turn. `hide` and an `undo` by turns place no marks, and refuse a
624
+ `marks` choice other than `none`. The `marks` verb takes `action: 'list'
625
+ | 'cancel' | 'retract'` with a `target` (a batch id; for cancel also a
626
+ retract request id; for retract also `all`).
627
+
628
+ The ledger is version 3. A version 2 ledger, agent-framework 0.22.x's at the
629
+ same path, is rewritten as version 3 in place by its first write: at a start,
630
+ or an offline recovery. Each of its batches keeps how many of its messages
631
+ 0.22.x's last attempt saw a mark added to (`legacyAdded` in the list), never
632
+ as a claim about what is on Discord. The work 0.22.x had still to do is never
633
+ sent, since nobody chose it: a batch it never activated is retired (a
634
+ suppression whose body may be pending, once a start on its branch finishes
635
+ the body), and pending adds and removals are dropped. A batch it activated
636
+ stays active, its body taken as finished, as 0.22.x took it. The rewrite names
637
+ each batch that had such work, with how many adds and removals, on stderr
638
+ wherever it runs, and in a `discord-awareness-import-unsent` ops alert at the
639
+ host's start that made it. A batch 0.22.x never activated placed no marks; a
640
+ retract of a batch takes off the mark of its emoji from each of its messages,
641
+ whichever batch placed it. 0.22.x reads only versions 1 and 2, and its start
642
+ stops on a version 3 file: to go back to 0.22.x, move the file aside first,
643
+ and 0.22.x then starts with no marks history. A version 1 ledger, which only
644
+ an unreleased commit wrote, is refused until it is moved away, and its error
645
+ says what that gives up.
646
+
477
647
  ## Observability
478
648
 
479
649
  Subscribe to trace events for logging, UI updates, or debugging:
@@ -517,4 +687,4 @@ npm test # Run tests
517
687
  npm run typecheck # Type-check without emitting
518
688
  ```
519
689
 
520
- Requires Node.js >= 20. Chronicle requires a Rust toolchain for native module compilation (`npm run build` in the chronicle directory).
690
+ Requires Node.js >= 22.12. Chronicle requires a Rust toolchain for native module compilation (`npm run build` in the chronicle directory).
@@ -351,29 +351,80 @@ export declare class Agent {
351
351
  /** Settle a converging budget once the window is prepared; true if it settled. */
352
352
  private settleRuntimeSettingsTransition;
353
353
  /**
354
- * RFC-006 consumed watermark: the newest stored message at the last compile
355
- * of a model request, or at the last tool boundary that injected messages
356
- * into a live one, per branch. Everything above it has never been in a
357
- * request and may still be replaced or withdrawn in place by its sender.
354
+ * RFC-006 consumed watermark, per branch: the newest stored message as of
355
+ * the latest of the agent's creation, a committing compile that returns,
356
+ * and a tool boundary that injected messages into a live stream declaring
357
+ * it carries them (`supportsInjectedMessages` true: membrane's native
358
+ * path, from membrane 0.6.0). A compile counts from when it takes its
359
+ * value, before it awaits, so one that began before a boundary's mark
360
+ * doesn't roll the mark back (applyCompileWatermark), and a dry run, such
361
+ * as previewActivation's, doesn't move it. Each move takes the store's
362
+ * head, a scalar, so it also covers stored messages the agent wasn't
363
+ * given, such as another slot's.
364
+ *
365
+ * A message above it may still be replaced or withdrawn in place by its
366
+ * sender, though it may already have been in one of the agent's requests.
367
+ * A live stream carries each round's own content and results, which it
368
+ * stores at its tool boundaries, into its next request. It can also carry
369
+ * the messages injected at a boundary whose stream didn't say whether it
370
+ * carries injections, as no membrane 0.5.x stream does: its native path
371
+ * carries them and its XML path drops them, and either way they stay
372
+ * above it.
358
373
  */
359
374
  private consumedWatermark;
360
- /** Counts marks: a compile writes its watermark back only if no mark was
361
- * made while it ran (a tool boundary's, or another compile's). */
375
+ /** Counts marks (markContextConsumed's and applyCompileWatermark's), so a
376
+ * compile that finishes can tell whether one was made while it ran. */
362
377
  private watermarkMarks;
378
+ /**
379
+ * The newest stored message a compile or a tool boundary may have put in
380
+ * front of the agent, per branch. It moves where the consumed watermark
381
+ * does, and sooner: when a committing compile takes its value, before it
382
+ * awaits, and at every tool boundary that injects, whether or not the
383
+ * stream says it carries injected messages. A message above it may still
384
+ * have been shown, though: for one, a live stream carries each round's own
385
+ * content and results, stored at a boundary that injected nothing, into its
386
+ * next request. A compile that throws assembled nothing, and gives its move
387
+ * back where it can (unshowFailedCompile). A scalar counts a prefix, so a
388
+ * message stored below it without having been shown counts as shown, which
389
+ * errs toward a marker.
390
+ */
391
+ private shownWatermark;
363
392
  getConsumedWatermark(): {
364
393
  branch: string;
365
394
  sequence: number;
366
395
  } | null;
396
+ getShownWatermark(): {
397
+ branch: string;
398
+ sequence: number;
399
+ } | null;
367
400
  /** Mark everything currently stored as consumed (the agent's creation, at
368
- * boot or later, and a tool boundary that injected messages into the live
369
- * stream). */
401
+ * boot or later, and a tool boundary that injected messages into a live
402
+ * stream declaring it carries them; see consumedWatermark). */
370
403
  markContextConsumed(): void;
404
+ /** Mark everything currently stored as possibly shown (a tool boundary
405
+ * that injected messages, whatever its stream says it carries). Without
406
+ * a watermark the coalescer counts a message as shown, as it counts one
407
+ * read without a consumed watermark. */
408
+ markContextShown(): void;
409
+ /** A committing compile that threw assembled nothing, so its own move of
410
+ * the shown watermark goes back, unless a boundary or another compile has
411
+ * moved the watermark since. It goes back to the watermark as the compile
412
+ * found it, which can be another compile's claim that has failed as well.
413
+ * Of two overlapping committing compiles, if the first to start throws
414
+ * first, it gives nothing back (the second's claim is current), and if
415
+ * the second then throws, it restores the first's failed claim. Messages
416
+ * up to that claim then count as shown, although no request held those
417
+ * above the watermark the first compile found, which errs toward a marker
418
+ * until the next compile or boundary moves the watermark. */
419
+ private unshowFailedCompile;
371
420
  /**
372
421
  * A finished compile's watermark, taken before it awaited. Within a branch
373
422
  * the watermark only advances: if a mark was made while the compile ran,
374
423
  * the compile's (older) one is applied only where it is later on that
375
424
  * mark's branch, so a boundary's mark is never rolled back by a compile
376
- * that started before it (a preview during a live turn).
425
+ * that started before it (a committing compile, such as compileContext's,
426
+ * run during a live turn; a dry run, such as previewActivation's, never
427
+ * reaches here).
377
428
  */
378
429
  private applyCompileWatermark;
379
430
  /** The watermark a successful compile will establish (taken before, applied after). */
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAqB,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGxH,OAAO,KAAK,EAAE,gBAAgB,EAAyB,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,OAAO,EAQL,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EAEzB,MAAM,uBAAuB,CAAC;AAQ/B,MAAM,WAAW,wBAAwB;IACvC,8DAA8D;IAC9D,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC;wEACoE;IACpE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,iBAAiB,CAAC;IAC3B;;;;;iCAK6B;IAC7B,cAAc,CAAC,EAAE,iBAAiB,CAAC;IACnC,gBAAgB,CAAC,EAAE,MAAM;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,gBAAgB,CAAA;KAAE,GAAG,SAAS,CAAC;IAC7F,oBAAoB,CAAC,EAAE,MAAM,MAAM,EAAE,CAAC;CACvC;AACD,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,aAAa,EAGb,eAAe,EAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,wBAAwB,EACxB,8BAA8B,EAG9B,UAAU,EACV,QAAQ,EACR,UAAU,EACV,cAAc,EACd,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,6BAA6B,EAC9B,MAAM,kBAAkB,CAAC;AAkB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
  /**
797
- * RFC-006 consumed watermark: the newest stored message at the last compile
798
- * of a model request, or at the last tool boundary that injected messages
799
- * into a live one, per branch. Everything above it has never been in a
800
- * request and may still be replaced or withdrawn in place by its sender.
797
+ * RFC-006 consumed watermark, per branch: the newest stored message as of
798
+ * the latest of the agent's creation, a committing compile that returns,
799
+ * and a tool boundary that injected messages into a live stream declaring
800
+ * it carries them (`supportsInjectedMessages` true: membrane's native
801
+ * path, from membrane 0.6.0). A compile counts from when it takes its
802
+ * value, before it awaits, so one that began before a boundary's mark
803
+ * doesn't roll the mark back (applyCompileWatermark), and a dry run, such
804
+ * as previewActivation's, doesn't move it. Each move takes the store's
805
+ * head, a scalar, so it also covers stored messages the agent wasn't
806
+ * given, such as another slot's.
807
+ *
808
+ * A message above it may still be replaced or withdrawn in place by its
809
+ * sender, though it may already have been in one of the agent's requests.
810
+ * A live stream carries each round's own content and results, which it
811
+ * stores at its tool boundaries, into its next request. It can also carry
812
+ * the messages injected at a boundary whose stream didn't say whether it
813
+ * carries injections, as no membrane 0.5.x stream does: its native path
814
+ * carries them and its XML path drops them, and either way they stay
815
+ * above it.
801
816
  */
802
817
  consumedWatermark = null;
803
- /** Counts marks: a compile writes its watermark back only if no mark was
804
- * made while it ran (a tool boundary's, or another compile's). */
818
+ /** Counts marks (markContextConsumed's and applyCompileWatermark's), so a
819
+ * compile that finishes can tell whether one was made while it ran. */
805
820
  watermarkMarks = 0;
821
+ /**
822
+ * The newest stored message a compile or a tool boundary may have put in
823
+ * front of the agent, per branch. It moves where the consumed watermark
824
+ * does, and sooner: when a committing compile takes its value, before it
825
+ * awaits, and at every tool boundary that injects, whether or not the
826
+ * stream says it carries injected messages. A message above it may still
827
+ * have been shown, though: for one, a live stream carries each round's own
828
+ * content and results, stored at a boundary that injected nothing, into its
829
+ * next request. A compile that throws assembled nothing, and gives its move
830
+ * back where it can (unshowFailedCompile). A scalar counts a prefix, so a
831
+ * message stored below it without having been shown counts as shown, which
832
+ * errs toward a marker.
833
+ */
834
+ shownWatermark = null;
806
835
  getConsumedWatermark() {
807
836
  return this.consumedWatermark;
808
837
  }
838
+ getShownWatermark() {
839
+ return this.shownWatermark;
840
+ }
809
841
  /** Mark everything currently stored as consumed (the agent's creation, at
810
- * boot or later, and a tool boundary that injected messages into the live
811
- * stream). */
842
+ * boot or later, and a tool boundary that injected messages into a live
843
+ * stream declaring it carries them; see consumedWatermark). */
812
844
  markContextConsumed() {
813
845
  // Tolerates partial context-manager doubles (tests build Agents over
814
- // stubs): without a watermark nothing is ever treated as unread.
846
+ // stubs). Without a watermark, a reader that looks for one takes its own
847
+ // side: the coalescer counts the message as read, and the framework's
848
+ // deferredWriteReadOrGone and unreadNoticesForPrimary count it as unread.
815
849
  this.consumedWatermark = this.pendingWatermark();
816
850
  this.watermarkMarks++;
851
+ this.shownWatermark = this.consumedWatermark;
852
+ }
853
+ /** Mark everything currently stored as possibly shown (a tool boundary
854
+ * that injected messages, whatever its stream says it carries). Without
855
+ * a watermark the coalescer counts a message as shown, as it counts one
856
+ * read without a consumed watermark. */
857
+ markContextShown() {
858
+ this.shownWatermark = this.pendingWatermark();
859
+ }
860
+ /** A committing compile that threw assembled nothing, so its own move of
861
+ * the shown watermark goes back, unless a boundary or another compile has
862
+ * moved the watermark since. It goes back to the watermark as the compile
863
+ * found it, which can be another compile's claim that has failed as well.
864
+ * Of two overlapping committing compiles, if the first to start throws
865
+ * first, it gives nothing back (the second's claim is current), and if
866
+ * the second then throws, it restores the first's failed claim. Messages
867
+ * up to that claim then count as shown, although no request held those
868
+ * above the watermark the first compile found, which errs toward a marker
869
+ * until the next compile or boundary moves the watermark. */
870
+ unshowFailedCompile(watermark, before) {
871
+ if (watermark && this.shownWatermark === watermark)
872
+ this.shownWatermark = before;
817
873
  }
818
874
  /**
819
875
  * A finished compile's watermark, taken before it awaited. Within a branch
820
876
  * the watermark only advances: if a mark was made while the compile ran,
821
877
  * the compile's (older) one is applied only where it is later on that
822
878
  * mark's branch, so a boundary's mark is never rolled back by a compile
823
- * that started before it (a preview during a live turn).
879
+ * that started before it (a committing compile, such as compileContext's,
880
+ * run during a live turn; a dry run, such as previewActivation's, never
881
+ * reaches here).
824
882
  */
825
883
  applyCompileWatermark(watermark, marksBefore) {
826
884
  const current = this.consumedWatermark;
@@ -861,8 +919,18 @@ export class Agent {
861
919
  // fails assembled nothing, so the watermark moves only on success.
862
920
  const watermark = this.pendingWatermark();
863
921
  const marksBefore = this.watermarkMarks;
922
+ const shownBefore = this.shownWatermark;
923
+ if (watermark)
924
+ this.shownWatermark = watermark;
864
925
  const compile = () => this.contextManager.compile(this.compileBudget(budget));
865
- const result = budget ? await compile() : await this.compileAtLiveBudget(compile);
926
+ let result;
927
+ try {
928
+ result = budget ? await compile() : await this.compileAtLiveBudget(compile);
929
+ }
930
+ catch (error) {
931
+ this.unshowFailedCompile(watermark, shownBefore);
932
+ throw error;
933
+ }
866
934
  if (watermark)
867
935
  this.applyCompileWatermark(watermark, marksBefore);
868
936
  return result;
@@ -899,8 +967,20 @@ export class Agent {
899
967
  // any compile before it selects.
900
968
  const watermark = opts?.dryRun ? null : this.pendingWatermark();
901
969
  const marksBefore = this.watermarkMarks;
970
+ // Shown from the compile's start: what it assembles is in front of the
971
+ // agent before the consumed watermark moves, once it returns.
972
+ const shownBefore = this.shownWatermark;
973
+ if (watermark)
974
+ this.shownWatermark = watermark;
902
975
  const compile = () => this.contextManager.compile(this.compileBudget(budget), injections, opts);
903
- const result = budget || opts?.dryRun ? await compile() : await this.compileAtLiveBudget(compile);
976
+ let result;
977
+ try {
978
+ result = budget || opts?.dryRun ? await compile() : await this.compileAtLiveBudget(compile);
979
+ }
980
+ catch (error) {
981
+ this.unshowFailedCompile(watermark, shownBefore);
982
+ throw error;
983
+ }
904
984
  if (watermark)
905
985
  this.applyCompileWatermark(watermark, marksBefore);
906
986
  return result;