@animalabs/agent-framework 0.26.2 → 0.28.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 (371) hide show
  1. package/README.md +99 -8
  2. package/dist/src/agent.d.ts +291 -23
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +596 -61
  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 +5 -4
  8. package/dist/src/api/server.js.map +1 -1
  9. package/dist/src/auto-continue.d.ts +34 -0
  10. package/dist/src/auto-continue.d.ts.map +1 -0
  11. package/dist/src/auto-continue.js +36 -0
  12. package/dist/src/auto-continue.js.map +1 -0
  13. package/dist/src/code-execution/isolate/scripts.d.ts +11 -0
  14. package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
  15. package/dist/src/code-execution/isolate/scripts.js +5 -1
  16. package/dist/src/code-execution/isolate/scripts.js.map +1 -1
  17. package/dist/src/cut-off-round.d.ts +24 -0
  18. package/dist/src/cut-off-round.d.ts.map +1 -0
  19. package/dist/src/cut-off-round.js +87 -0
  20. package/dist/src/cut-off-round.js.map +1 -0
  21. package/dist/src/framework.d.ts +1038 -193
  22. package/dist/src/framework.d.ts.map +1 -1
  23. package/dist/src/framework.js +5967 -1514
  24. package/dist/src/framework.js.map +1 -1
  25. package/dist/src/gate/event-gate.d.ts +405 -46
  26. package/dist/src/gate/event-gate.d.ts.map +1 -1
  27. package/dist/src/gate/event-gate.js +2646 -399
  28. package/dist/src/gate/event-gate.js.map +1 -1
  29. package/dist/src/gate/index.d.ts +3 -2
  30. package/dist/src/gate/index.d.ts.map +1 -1
  31. package/dist/src/gate/index.js +2 -1
  32. package/dist/src/gate/index.js.map +1 -1
  33. package/dist/src/gate/recipe-reconcile.d.ts +103 -0
  34. package/dist/src/gate/recipe-reconcile.d.ts.map +1 -0
  35. package/dist/src/gate/recipe-reconcile.js +325 -0
  36. package/dist/src/gate/recipe-reconcile.js.map +1 -0
  37. package/dist/src/gate/reply-judge.d.ts +116 -0
  38. package/dist/src/gate/reply-judge.d.ts.map +1 -0
  39. package/dist/src/gate/reply-judge.js +467 -0
  40. package/dist/src/gate/reply-judge.js.map +1 -0
  41. package/dist/src/gate/types.d.ts +229 -8
  42. package/dist/src/gate/types.d.ts.map +1 -1
  43. package/dist/src/heartbeat/heartbeat.d.ts +184 -0
  44. package/dist/src/heartbeat/heartbeat.d.ts.map +1 -0
  45. package/dist/src/heartbeat/heartbeat.js +752 -0
  46. package/dist/src/heartbeat/heartbeat.js.map +1 -0
  47. package/dist/src/heartbeat/reminder-time.d.ts +5 -0
  48. package/dist/src/heartbeat/reminder-time.d.ts.map +1 -0
  49. package/dist/src/heartbeat/reminder-time.js +107 -0
  50. package/dist/src/heartbeat/reminder-time.js.map +1 -0
  51. package/dist/src/index.d.ts +10 -4
  52. package/dist/src/index.d.ts.map +1 -1
  53. package/dist/src/index.js +7 -2
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/src/mcpl/capability-mask.d.ts.map +1 -1
  56. package/dist/src/mcpl/capability-mask.js +3 -2
  57. package/dist/src/mcpl/capability-mask.js.map +1 -1
  58. package/dist/src/mcpl/channel-registry.d.ts +433 -113
  59. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  60. package/dist/src/mcpl/channel-registry.js +1154 -435
  61. package/dist/src/mcpl/channel-registry.js.map +1 -1
  62. package/dist/src/mcpl/conversation-router.d.ts +16 -8
  63. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  64. package/dist/src/mcpl/conversation-router.js +29 -15
  65. package/dist/src/mcpl/conversation-router.js.map +1 -1
  66. package/dist/src/mcpl/convert-block.d.ts.map +1 -1
  67. package/dist/src/mcpl/convert-block.js +14 -2
  68. package/dist/src/mcpl/convert-block.js.map +1 -1
  69. package/dist/src/mcpl/hook-orchestrator.d.ts +7 -1
  70. package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
  71. package/dist/src/mcpl/hook-orchestrator.js +32 -7
  72. package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
  73. package/dist/src/mcpl/inbound-source.d.ts +26 -10
  74. package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
  75. package/dist/src/mcpl/inbound-source.js +40 -69
  76. package/dist/src/mcpl/inbound-source.js.map +1 -1
  77. package/dist/src/mcpl/index.d.ts +5 -1
  78. package/dist/src/mcpl/index.d.ts.map +1 -1
  79. package/dist/src/mcpl/index.js +4 -0
  80. package/dist/src/mcpl/index.js.map +1 -1
  81. package/dist/src/mcpl/inference-router.d.ts +14 -2
  82. package/dist/src/mcpl/inference-router.d.ts.map +1 -1
  83. package/dist/src/mcpl/inference-router.js +73 -28
  84. package/dist/src/mcpl/inference-router.js.map +1 -1
  85. package/dist/src/mcpl/prose-grammar.d.ts +4 -0
  86. package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
  87. package/dist/src/mcpl/prose-grammar.js +6 -0
  88. package/dist/src/mcpl/prose-grammar.js.map +1 -1
  89. package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
  90. package/dist/src/mcpl/protocol-family.js +3 -0
  91. package/dist/src/mcpl/protocol-family.js.map +1 -1
  92. package/dist/src/mcpl/push-coalescer.d.ts +20 -2
  93. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  94. package/dist/src/mcpl/push-coalescer.js +33 -11
  95. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  96. package/dist/src/mcpl/reference-fetcher.d.ts +63 -42
  97. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  98. package/dist/src/mcpl/reference-fetcher.js +177 -145
  99. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  100. package/dist/src/mcpl/references.d.ts +380 -46
  101. package/dist/src/mcpl/references.d.ts.map +1 -1
  102. package/dist/src/mcpl/references.js +736 -77
  103. package/dist/src/mcpl/references.js.map +1 -1
  104. package/dist/src/mcpl/server-connection.d.ts +93 -4
  105. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  106. package/dist/src/mcpl/server-connection.js +176 -11
  107. package/dist/src/mcpl/server-connection.js.map +1 -1
  108. package/dist/src/mcpl/tags.d.ts +9 -2
  109. package/dist/src/mcpl/tags.d.ts.map +1 -1
  110. package/dist/src/mcpl/tags.js +12 -2
  111. package/dist/src/mcpl/tags.js.map +1 -1
  112. package/dist/src/mcpl/tool-lifecycle.d.ts +11 -0
  113. package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
  114. package/dist/src/mcpl/tool-lifecycle.js +21 -0
  115. package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
  116. package/dist/src/mcpl/tool-presence.d.ts +311 -0
  117. package/dist/src/mcpl/tool-presence.d.ts.map +1 -0
  118. package/dist/src/mcpl/tool-presence.js +697 -0
  119. package/dist/src/mcpl/tool-presence.js.map +1 -0
  120. package/dist/src/mcpl/tool-result-normalize.d.ts +9 -3
  121. package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
  122. package/dist/src/mcpl/tool-result-normalize.js +14 -6
  123. package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
  124. package/dist/src/mcpl/tool-signature.d.ts +46 -0
  125. package/dist/src/mcpl/tool-signature.d.ts.map +1 -0
  126. package/dist/src/mcpl/tool-signature.js +321 -0
  127. package/dist/src/mcpl/tool-signature.js.map +1 -0
  128. package/dist/src/mcpl/toolset-host.d.ts +251 -0
  129. package/dist/src/mcpl/toolset-host.d.ts.map +1 -0
  130. package/dist/src/mcpl/toolset-host.js +720 -0
  131. package/dist/src/mcpl/toolset-host.js.map +1 -0
  132. package/dist/src/mcpl/toolsets-module.d.ts +83 -0
  133. package/dist/src/mcpl/toolsets-module.d.ts.map +1 -0
  134. package/dist/src/mcpl/toolsets-module.js +523 -0
  135. package/dist/src/mcpl/toolsets-module.js.map +1 -0
  136. package/dist/src/mcpl/transport.d.ts +2 -2
  137. package/dist/src/mcpl/transport.d.ts.map +1 -1
  138. package/dist/src/mcpl/transport.js +3 -2
  139. package/dist/src/mcpl/transport.js.map +1 -1
  140. package/dist/src/mcpl/types.d.ts +24 -2
  141. package/dist/src/mcpl/types.d.ts.map +1 -1
  142. package/dist/src/mcpl/types.js.map +1 -1
  143. package/dist/src/mcpl/visible-content.d.ts +7 -9
  144. package/dist/src/mcpl/visible-content.d.ts.map +1 -1
  145. package/dist/src/mcpl/visible-content.js +21 -9
  146. package/dist/src/mcpl/visible-content.js.map +1 -1
  147. package/dist/src/module-registry.d.ts +27 -9
  148. package/dist/src/module-registry.d.ts.map +1 -1
  149. package/dist/src/module-registry.js +77 -17
  150. package/dist/src/module-registry.js.map +1 -1
  151. package/dist/src/modules/discord/index.js +1 -1
  152. package/dist/src/modules/discord/index.js.map +1 -1
  153. package/dist/src/modules/history/index.d.ts +2 -1
  154. package/dist/src/modules/history/index.d.ts.map +1 -1
  155. package/dist/src/modules/history/index.js +73 -28
  156. package/dist/src/modules/history/index.js.map +1 -1
  157. package/dist/src/modules/history/semantic.d.ts +108 -6
  158. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  159. package/dist/src/modules/history/semantic.js +273 -57
  160. package/dist/src/modules/history/semantic.js.map +1 -1
  161. package/dist/src/modules/workspace/answers.d.ts +22 -0
  162. package/dist/src/modules/workspace/answers.d.ts.map +1 -0
  163. package/dist/src/modules/workspace/answers.js +123 -0
  164. package/dist/src/modules/workspace/answers.js.map +1 -0
  165. package/dist/src/modules/workspace/branch-intent.d.ts +5 -3
  166. package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
  167. package/dist/src/modules/workspace/branch-intent.js +6 -2
  168. package/dist/src/modules/workspace/branch-intent.js.map +1 -1
  169. package/dist/src/modules/workspace/direct-write.d.ts +184 -0
  170. package/dist/src/modules/workspace/direct-write.d.ts.map +1 -0
  171. package/dist/src/modules/workspace/direct-write.js +417 -0
  172. package/dist/src/modules/workspace/direct-write.js.map +1 -0
  173. package/dist/src/modules/workspace/disk-agreement.d.ts +33 -11
  174. package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -1
  175. package/dist/src/modules/workspace/disk-agreement.js +48 -17
  176. package/dist/src/modules/workspace/disk-agreement.js.map +1 -1
  177. package/dist/src/modules/workspace/edit-text.d.ts +27 -12
  178. package/dist/src/modules/workspace/edit-text.d.ts.map +1 -1
  179. package/dist/src/modules/workspace/edit-text.js +61 -29
  180. package/dist/src/modules/workspace/edit-text.js.map +1 -1
  181. package/dist/src/modules/workspace/effects.d.ts +10 -0
  182. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  183. package/dist/src/modules/workspace/effects.js +21 -14
  184. package/dist/src/modules/workspace/effects.js.map +1 -1
  185. package/dist/src/modules/workspace/index.d.ts +308 -78
  186. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  187. package/dist/src/modules/workspace/index.js +2103 -720
  188. package/dist/src/modules/workspace/index.js.map +1 -1
  189. package/dist/src/modules/workspace/observe.d.ts +75 -63
  190. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  191. package/dist/src/modules/workspace/observe.js +366 -180
  192. package/dist/src/modules/workspace/observe.js.map +1 -1
  193. package/dist/src/modules/workspace/read-page.d.ts +41 -0
  194. package/dist/src/modules/workspace/read-page.d.ts.map +1 -0
  195. package/dist/src/modules/workspace/read-page.js +219 -0
  196. package/dist/src/modules/workspace/read-page.js.map +1 -0
  197. package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
  198. package/dist/src/modules/workspace/reconcile.js +26 -16
  199. package/dist/src/modules/workspace/reconcile.js.map +1 -1
  200. package/dist/src/modules/workspace/result-text.d.ts +68 -0
  201. package/dist/src/modules/workspace/result-text.d.ts.map +1 -0
  202. package/dist/src/modules/workspace/result-text.js +94 -0
  203. package/dist/src/modules/workspace/result-text.js.map +1 -0
  204. package/dist/src/modules/workspace/sync.d.ts +9 -0
  205. package/dist/src/modules/workspace/sync.d.ts.map +1 -1
  206. package/dist/src/modules/workspace/sync.js +14 -0
  207. package/dist/src/modules/workspace/sync.js.map +1 -1
  208. package/dist/src/modules/workspace/text.d.ts +29 -12
  209. package/dist/src/modules/workspace/text.d.ts.map +1 -1
  210. package/dist/src/modules/workspace/text.js +35 -33
  211. package/dist/src/modules/workspace/text.js.map +1 -1
  212. package/dist/src/modules/workspace/types.d.ts +137 -60
  213. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  214. package/dist/src/modules/workspace/types.js.map +1 -1
  215. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  216. package/dist/src/modules/workspace/watcher.js +8 -3
  217. package/dist/src/modules/workspace/watcher.js.map +1 -1
  218. package/dist/src/prose-drafts.d.ts +4 -3
  219. package/dist/src/prose-drafts.d.ts.map +1 -1
  220. package/dist/src/prose-drafts.js +3 -2
  221. package/dist/src/prose-drafts.js.map +1 -1
  222. package/dist/src/reasoning-loss-notice.d.ts +23 -0
  223. package/dist/src/reasoning-loss-notice.d.ts.map +1 -0
  224. package/dist/src/reasoning-loss-notice.js +50 -0
  225. package/dist/src/reasoning-loss-notice.js.map +1 -0
  226. package/dist/src/reasoning-loss.d.ts +24 -0
  227. package/dist/src/reasoning-loss.d.ts.map +1 -0
  228. package/dist/src/reasoning-loss.js +102 -0
  229. package/dist/src/reasoning-loss.js.map +1 -0
  230. package/dist/src/send-tools.d.ts +3 -2
  231. package/dist/src/send-tools.d.ts.map +1 -1
  232. package/dist/src/send-tools.js +3 -2
  233. package/dist/src/send-tools.js.map +1 -1
  234. package/dist/src/sent-rows.d.ts +59 -0
  235. package/dist/src/sent-rows.d.ts.map +1 -0
  236. package/dist/src/sent-rows.js +145 -0
  237. package/dist/src/sent-rows.js.map +1 -0
  238. package/dist/src/silent-heartbeat.d.ts +17 -10
  239. package/dist/src/silent-heartbeat.d.ts.map +1 -1
  240. package/dist/src/silent-heartbeat.js.map +1 -1
  241. package/dist/src/stable-hash.d.ts +3 -0
  242. package/dist/src/stable-hash.d.ts.map +1 -0
  243. package/dist/src/stable-hash.js +15 -0
  244. package/dist/src/stable-hash.js.map +1 -0
  245. package/dist/src/stored-injections.d.ts +99 -0
  246. package/dist/src/stored-injections.d.ts.map +1 -0
  247. package/dist/src/stored-injections.js +106 -0
  248. package/dist/src/stored-injections.js.map +1 -0
  249. package/dist/src/text-as-stored.d.ts +4 -3
  250. package/dist/src/text-as-stored.d.ts.map +1 -1
  251. package/dist/src/text-as-stored.js +4 -3
  252. package/dist/src/text-as-stored.js.map +1 -1
  253. package/dist/src/thinking-drops.d.ts +74 -0
  254. package/dist/src/thinking-drops.d.ts.map +1 -0
  255. package/dist/src/thinking-drops.js +96 -0
  256. package/dist/src/thinking-drops.js.map +1 -0
  257. package/dist/src/tool-args.d.ts +12 -0
  258. package/dist/src/tool-args.d.ts.map +1 -1
  259. package/dist/src/tool-args.js +35 -1
  260. package/dist/src/tool-args.js.map +1 -1
  261. package/dist/src/tool-image-ledger.d.ts +9 -8
  262. package/dist/src/tool-image-ledger.d.ts.map +1 -1
  263. package/dist/src/tool-image-ledger.js +9 -8
  264. package/dist/src/tool-image-ledger.js.map +1 -1
  265. package/dist/src/tool-presentation.d.ts.map +1 -1
  266. package/dist/src/tool-presentation.js +3 -1
  267. package/dist/src/tool-presentation.js.map +1 -1
  268. package/dist/src/tool-result-guard.d.ts +12 -6
  269. package/dist/src/tool-result-guard.d.ts.map +1 -1
  270. package/dist/src/tool-result-guard.js +44 -17
  271. package/dist/src/tool-result-guard.js.map +1 -1
  272. package/dist/src/tool-result-history.d.ts +176 -24
  273. package/dist/src/tool-result-history.d.ts.map +1 -1
  274. package/dist/src/tool-result-history.js +411 -91
  275. package/dist/src/tool-result-history.js.map +1 -1
  276. package/dist/src/tune-out/coordinator.d.ts +17 -9
  277. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  278. package/dist/src/tune-out/coordinator.js +84 -37
  279. package/dist/src/tune-out/coordinator.js.map +1 -1
  280. package/dist/src/tune-out/tools.d.ts +4 -1
  281. package/dist/src/tune-out/tools.d.ts.map +1 -1
  282. package/dist/src/types/agent.d.ts +217 -7
  283. package/dist/src/types/agent.d.ts.map +1 -1
  284. package/dist/src/types/events.d.ts +33 -9
  285. package/dist/src/types/events.d.ts.map +1 -1
  286. package/dist/src/types/framework.d.ts +39 -3
  287. package/dist/src/types/framework.d.ts.map +1 -1
  288. package/dist/src/types/module.d.ts +95 -9
  289. package/dist/src/types/module.d.ts.map +1 -1
  290. package/dist/src/types/trace.d.ts +91 -3
  291. package/dist/src/types/trace.d.ts.map +1 -1
  292. package/package.json +5 -4
  293. package/src/agent.ts +661 -67
  294. package/src/api/server.ts +5 -4
  295. package/src/auto-continue.ts +43 -0
  296. package/src/code-execution/isolate/scripts.ts +11 -3
  297. package/src/cut-off-round.ts +98 -0
  298. package/src/framework.ts +6168 -1540
  299. package/src/gate/event-gate.ts +2895 -405
  300. package/src/gate/index.ts +10 -1
  301. package/src/gate/recipe-reconcile.ts +355 -0
  302. package/src/gate/reply-judge.ts +512 -0
  303. package/src/gate/types.ts +234 -9
  304. package/src/heartbeat/heartbeat.ts +804 -0
  305. package/src/heartbeat/reminder-time.ts +107 -0
  306. package/src/index.ts +11 -4
  307. package/src/mcpl/capability-mask.ts +3 -2
  308. package/src/mcpl/channel-registry.ts +1222 -468
  309. package/src/mcpl/conversation-router.ts +34 -16
  310. package/src/mcpl/convert-block.ts +14 -1
  311. package/src/mcpl/hook-orchestrator.ts +33 -6
  312. package/src/mcpl/inbound-source.ts +42 -69
  313. package/src/mcpl/index.ts +6 -1
  314. package/src/mcpl/inference-router.ts +79 -34
  315. package/src/mcpl/prose-grammar.ts +7 -0
  316. package/src/mcpl/protocol-family.ts +2 -0
  317. package/src/mcpl/push-coalescer.ts +51 -13
  318. package/src/mcpl/reference-fetcher.ts +201 -162
  319. package/src/mcpl/references.ts +851 -77
  320. package/src/mcpl/server-connection.ts +189 -11
  321. package/src/mcpl/tags.ts +13 -2
  322. package/src/mcpl/tool-lifecycle.ts +21 -0
  323. package/src/mcpl/tool-presence.ts +716 -0
  324. package/src/mcpl/tool-result-normalize.ts +18 -6
  325. package/src/mcpl/tool-signature.ts +316 -0
  326. package/src/mcpl/toolset-host.ts +727 -0
  327. package/src/mcpl/toolsets-module.ts +545 -0
  328. package/src/mcpl/transport.ts +3 -2
  329. package/src/mcpl/types.ts +25 -2
  330. package/src/mcpl/visible-content.ts +22 -9
  331. package/src/module-registry.ts +85 -26
  332. package/src/modules/discord/index.ts +1 -1
  333. package/src/modules/history/index.ts +70 -30
  334. package/src/modules/history/semantic.ts +308 -54
  335. package/src/modules/workspace/answers.ts +133 -0
  336. package/src/modules/workspace/branch-intent.ts +10 -5
  337. package/src/modules/workspace/direct-write.ts +460 -0
  338. package/src/modules/workspace/disk-agreement.ts +52 -21
  339. package/src/modules/workspace/edit-text.ts +84 -35
  340. package/src/modules/workspace/effects.ts +22 -13
  341. package/src/modules/workspace/index.ts +2142 -723
  342. package/src/modules/workspace/observe.ts +381 -177
  343. package/src/modules/workspace/read-page.ts +228 -0
  344. package/src/modules/workspace/reconcile.ts +27 -15
  345. package/src/modules/workspace/result-text.ts +121 -0
  346. package/src/modules/workspace/sync.ts +16 -0
  347. package/src/modules/workspace/text.ts +58 -32
  348. package/src/modules/workspace/types.ts +137 -60
  349. package/src/modules/workspace/watcher.ts +8 -3
  350. package/src/prose-drafts.ts +4 -3
  351. package/src/reasoning-loss-notice.ts +62 -0
  352. package/src/reasoning-loss.ts +120 -0
  353. package/src/send-tools.ts +3 -2
  354. package/src/sent-rows.ts +162 -0
  355. package/src/silent-heartbeat.ts +17 -10
  356. package/src/stable-hash.ts +14 -0
  357. package/src/stored-injections.ts +131 -0
  358. package/src/text-as-stored.ts +4 -3
  359. package/src/thinking-drops.ts +135 -0
  360. package/src/tool-args.ts +34 -1
  361. package/src/tool-image-ledger.ts +9 -8
  362. package/src/tool-presentation.ts +3 -1
  363. package/src/tool-result-guard.ts +45 -17
  364. package/src/tool-result-history.ts +471 -90
  365. package/src/tune-out/coordinator.ts +80 -37
  366. package/src/tune-out/tools.ts +4 -1
  367. package/src/types/agent.ts +220 -7
  368. package/src/types/events.ts +33 -9
  369. package/src/types/framework.ts +36 -3
  370. package/src/types/module.ts +91 -9
  371. package/src/types/trace.ts +94 -3
@@ -16,6 +16,13 @@ export type { TraceEvent, TraceEventListener } from './trace.js';
16
16
  export interface ModuleProcessResponse {
17
17
  moduleName: string;
18
18
  response: EventResponse;
19
+ /**
20
+ * Set when applying the response threw: the operation it threw at, such
21
+ * as `the edit of <id>`, and the error's message. What the response asked
22
+ * for before that was applied, that operation may have taken effect in
23
+ * part or whole, and the rest of it wasn't (EventResponse).
24
+ */
25
+ threw?: { at: string; error: string };
19
26
  }
20
27
 
21
28
  /**
@@ -241,8 +248,9 @@ export interface FrameworkConfig {
241
248
  * workspace file under `tool-results/` (deterministic `<date>-<callId>.txt`
242
249
  * name, overwritten on collision, retained until the workspace owner
243
250
  * deletes it — never auto-GC'd) and replaced inline by a bounded preview
244
- * plus the file reference; with no writable mount without an include, the
245
- * fallback is explicit plain truncation. Default 24000 (house-safe; issue #89). Must be
251
+ * plus the file reference; with no writable mount without an include that
252
+ * keeps its files in the store (not configured direct), the fallback is
253
+ * explicit plain truncation. Default 24000 (house-safe; issue #89). Must be
246
254
  * >= 1000. A resident's own agent_settings value
247
255
  * `tool_result_inline_max_chars` (durable, persisted in framework state)
248
256
  * takes precedence over this for that agent; the EFFECTIVE cap for every
@@ -276,11 +284,36 @@ export interface FrameworkConfig {
276
284
  */
277
285
  hostToolClasses?: Record<string, string[]>;
278
286
 
279
- /** Inference routing policy for server-initiated inference (optional). */
287
+ /**
288
+ * Inference routing policy for server-initiated inference (optional): the
289
+ * model an MCPL server's inference/request runs on. Without one, each such
290
+ * request is refused with -32603 and a message naming this setting; the
291
+ * framework doesn't choose a model for a server. A server's effective
292
+ * grant can still list `inferenceRequest` then, since the grant comes from
293
+ * what the server advertises and `enabledCapabilities`, not from this
294
+ * policy. A policy that names no model for a request's feature set (no
295
+ * override, byFeature or wildcards entry that names one, and an empty
296
+ * `default`) refuses that request the same way, naming the feature set.
297
+ */
280
298
  inferenceRouting?: InferenceRoutingPolicy;
281
299
 
282
300
  /** EventGate config. If omitted, all events trigger inference (unchanged default). */
283
301
  gate?: GateOptions;
302
+ /**
303
+ * The heartbeat: the agent's own periodic check-in and reminders, kept by
304
+ * the framework (src/heartbeat/heartbeat.ts), with the tools
305
+ * `heartbeat--heartbeat_status`, `heartbeat--heartbeat_configure`,
306
+ * `heartbeat--heartbeat_trigger`, `heartbeat--reminder_add`,
307
+ * `heartbeat--reminder_list` and `heartbeat--reminder_cancel`. `true` turns it
308
+ * on with its defaults; `false`, null or leaving it out leaves it off. Its
309
+ * wakes go to the gate as heartbeat-mcpl's pushes did, from the server id
310
+ * `heartbeat`, so the agent's rules decide them and a sleep lets them
311
+ * through. It replaces the heartbeat-mcpl server, which is refused beside it
312
+ * (by its id, a heartbeat tool prefix, or its command), at create and at a
313
+ * runtime connect: both would wake the agent. `importFrom` brings that
314
+ * server's schedule and reminders along.
315
+ */
316
+ heartbeat?: boolean | null | import('../heartbeat/heartbeat.js').HeartbeatOptions;
284
317
 
285
318
  /**
286
319
  * Liveness watchdog: fail hard (and let the supervisor restart) if the main
@@ -25,6 +25,29 @@ export interface MessageQuery {
25
25
  metadata?: Record<string, unknown>;
26
26
  }
27
27
 
28
+ /**
29
+ * A context injection a module gathers (Module.gatherContext).
30
+ *
31
+ * An `afterUser` one is stored in the agent's window, as the message
32
+ * `compile()` would have placed after the last user message, where it then
33
+ * stays: so the replies after it keep their thinking, and the cache keeps the
34
+ * turns before it. The same source's unchanged content isn't stored again
35
+ * while the copy the agent will read as current has it whole: the one its
36
+ * last request held, or a newer one a start stored whose compile then
37
+ * didn't record. Once a fold has summarized it or a strategy's window has
38
+ * scrolled past it, it's stored again, as one more row. (See
39
+ * stored-injections.ts.)
40
+ *
41
+ * `placedEachCompile: true` opts out: `compile()` places the injection after
42
+ * the last user message at each start, near the end, as before it was
43
+ * stored. That's for context meant to stay near the end, such as
44
+ * instructions moved off `system`. Its cost: it moves, and on a model that
45
+ * binds a reply's thinking to everything before it, every reply after its old
46
+ * place loses its thinking. It has no effect on a `system` or `beforeUser`
47
+ * injection, which `compile()` always places.
48
+ */
49
+ export type ModuleContextInjection = ContextInjection & { placedEachCompile?: true };
50
+
28
51
  /**
29
52
  * A message as a module context's reads answer it: a stored row, or a row
30
53
  * for a write the framework holds (`held`). Either is marked
@@ -159,9 +182,16 @@ export interface Module {
159
182
  * Called before each inference to collect data (e.g., HUD overlays, game state)
160
183
  * that should be injected into the compiled context.
161
184
  * Complementary to MCPL push-based hooks — modules pull via gatherContext.
185
+ * An `afterUser` injection is appended to the agent's window, where it
186
+ * then stays, unless the copy the agent will read as current has the same
187
+ * content, every part of it (the one its last request held, or a newer
188
+ * one a start stored whose compile then didn't record), or it opts out
189
+ * (ModuleContextInjection.placedEachCompile). At a
190
+ * turn's start or a restart after tool results, that's where `compile()`
191
+ * would have placed it.
162
192
  * Adapted from Anarchid/agent-framework@mcpl-module-proto.
163
193
  */
164
- gatherContext?(agentName: string): Promise<ContextInjection[]>;
194
+ gatherContext?(agentName: string): Promise<ModuleContextInjection[]>;
165
195
 
166
196
  /**
167
197
  * Called once an agent's tool batch has completed — when the round's last
@@ -202,13 +232,16 @@ export interface AgentSettingsExtension {
202
232
  properties: Record<string, unknown>;
203
233
  /** The setting keys this extension owns (must match `properties` keys). */
204
234
  keys: string[];
205
- /** Current values for the extension's keys. */
235
+ /** Current values for the extension's keys. A refused agent_settings call
236
+ * names what changed by comparing every field this returns, before the
237
+ * call and at its refusal. */
206
238
  get(agentName: string): Record<string, unknown>;
207
239
  /** Apply a partial update (only this extension's keys present) and return
208
240
  * the new values. Throw to surface a validation error to the agent. */
209
241
  update(agentName: string, patch: Record<string, unknown>): Record<string, unknown>;
210
242
  /** Restore the listed keys (or all when omitted) to defaults and return the
211
- * new values. Optional — extensions without reset semantics are skipped. */
243
+ * new values. Optional: without it, a reset of every setting skips the
244
+ * extension, and a reset that names one of its keys is refused. */
212
245
  reset?(agentName: string, keys?: string[]): Record<string, unknown>;
213
246
  }
214
247
 
@@ -304,11 +337,43 @@ export interface ModuleContext {
304
337
  * (ModuleMessage.held). The writes a process held, and keeps across a
305
338
  * restart, show to the next process's modules once create() has restored
306
339
  * them, which is after every module's start().
340
+ *
341
+ * With `opts.forAgent`, it's added to the named agent's window instead: a
342
+ * conversation fork's or a running sub-agent's own store, or, for an
343
+ * ordinary resident, the residents' shared slot. It's held while that
344
+ * agent's turn is alive, as a write for the primary is while the
345
+ * primary's is. A name that isn't a registered agent when the write is
346
+ * made, or the empty name, throws, naming the registered ones, so a write
347
+ * for a launcher that has gone is heard. For an ephemeral run (a
348
+ * sub-agent's run) or a conversation fork, whose window nothing reads
349
+ * after it's released, a write it never read goes to the primary at its
350
+ * release, as the write itself, through the primary's own delivery. It's
351
+ * read as the framework reads a notice: once it's below the target's
352
+ * consumed watermark, which a compile built to send moves when it
353
+ * commits (a row that compile's strategy left out counts as read too),
354
+ * and a tool round moves when it injects messages into a stream that
355
+ * declares it carries them. So one that waited for its target's end (a
356
+ * run's end, or a fork's last turn), one stored while it was idle and
357
+ * never sent, one stored at a tool round that ended the turn, and one
358
+ * injected into a stream that didn't declare it carries injections go to
359
+ * the primary. The framework's own
360
+ * writes for a run or a fork are unchanged: they stay in its store,
361
+ * unless they're notices the primary already takes in their place (a
362
+ * failed reply, or a channel notice its reader could act on). getMessage,
363
+ * editMessage and removeMessage read the delivery agent's window (the
364
+ * primary's, or the first agent's when none is primary): they don't take
365
+ * an id or handle for a row in a fork's or a sub-agent's window, and don't
366
+ * find it (read it with queryMessages and the same forAgent). The
367
+ * residents' shared slot is the primary's window too, for a primary
368
+ * that's an ordinary resident, so there they do.
369
+ * `metadata.external` with a target throws: its id map is read in the
370
+ * primary's window.
307
371
  */
308
372
  addMessage(
309
373
  participant: string,
310
374
  content: ContentBlock[],
311
- metadata?: MessageMetadata & { external?: ExternalIdRef }
375
+ metadata?: MessageMetadata & { external?: ExternalIdRef },
376
+ opts?: { forAgent?: string },
312
377
  ): MessageId;
313
378
 
314
379
  /**
@@ -354,8 +419,17 @@ export interface ModuleContext {
354
419
  * restored them, after every module's start() (addMessage). A message a
355
420
  * tune-out holds from the residents is among the rows, marked
356
421
  * `heldFromResidents` (ModuleMessage).
422
+ *
423
+ * It reads the primary's window (the first registered agent's when none
424
+ * is primary), or with `opts.forAgent`, the named agent's: a conversation
425
+ * fork's or a running sub-agent's own store, or, for an ordinary resident,
426
+ * the residents' shared slot. For the subconscious, it's the
427
+ * subconscious's own store, not the residents' slot its compile merges
428
+ * in. A name that isn't a registered agent, or the empty name, throws,
429
+ * naming the registered ones, so a typo is heard rather than read as an
430
+ * empty window.
357
431
  */
358
- queryMessages(filter: MessageQuery): MessageQueryResult;
432
+ queryMessages(filter: MessageQuery, opts?: { forAgent?: string }): MessageQueryResult;
359
433
 
360
434
  /**
361
435
  * Get info about all agents.
@@ -512,7 +586,15 @@ export interface AgentInfo {
512
586
  export type AgentStatus = 'idle' | 'inferring' | 'streaming' | 'waiting_for_tools' | 'ready';
513
587
 
514
588
  /**
515
- * Response from a module's event handler.
589
+ * Response from a module's event handler. The framework applies it in this
590
+ * order: its messages added, edited and removed, then its stateUpdate, then
591
+ * its inference request. When one of these throws, such as an edit of a
592
+ * message the store doesn't hold, what came before it stays applied, the
593
+ * operation that threw may have taken effect in part or whole (a store can
594
+ * throw after it wrote), the rest of the response isn't, and a line names
595
+ * the module and where it threw; the event's other responses, a tool call's dispatch and its trace
596
+ * go on. Content the framework finds malformed refuses the whole response
597
+ * before any of it applies.
516
598
  */
517
599
  export interface EventResponse {
518
600
  /**
@@ -546,9 +628,9 @@ export interface EventResponse {
546
628
  toolsChanged?: boolean;
547
629
 
548
630
  /**
549
- * Module state update. Applied atomically with message operations.
550
- * The framework will call setState() with this value after applying
551
- * message changes, ensuring consistent state.
631
+ * Module state update. The framework calls setState() with this value
632
+ * after applying the response's message changes, and not when one of
633
+ * them threw.
552
634
  */
553
635
  stateUpdate?: unknown;
554
636
  }
@@ -1,3 +1,4 @@
1
+ import type { ThinkingBindingEntry } from '@animalabs/membrane';
1
2
  import type { ProcessEvent } from './events.js';
2
3
  import type { ModuleProcessResponse } from './framework.js';
3
4
  import type { SessionUsage } from '../usage/types.js';
@@ -66,6 +67,14 @@ export type TraceEvent =
66
67
  * without re-deriving routing.
67
68
  */
68
69
  channelId?: string;
70
+ /**
71
+ * The server that registers `channelId`, given with it. Two MCPL
72
+ * servers may register one channel id, so a tap that posts back to the
73
+ * turn's channel, such as a host telling it the turn failed, passes this
74
+ * server with the id. The streaming traces, `inference:tokens` and
75
+ * `inference:content_block`, carry the id alone.
76
+ */
77
+ serverId?: string;
69
78
  /** True for a control-plane wake that must not surface typing/prose. */
70
79
  silent?: boolean;
71
80
  })
@@ -105,6 +114,23 @@ export type TraceEvent =
105
114
  /** Bounded like `error`. */
106
115
  stack?: string;
107
116
  })
117
+ | (TraceEventBase & {
118
+ /**
119
+ * A turn waiting out its error policy's delay before a retry says so:
120
+ * as the wait begins, with when it is due to end, and again every 60
121
+ * seconds while it lasts, while its agent is the one registered under
122
+ * its name, and never after the wait ends (its time coming, a stop, or
123
+ * an abort). The failure being retried is the `inference:failed` just
124
+ * before it. A host watching for agents gone quiet can tell a waiting
125
+ * one from a stuck one by it.
126
+ */
127
+ type: 'inference:waiting';
128
+ agentName: string;
129
+ /** When the wait is due to end (epoch ms): it counts down by its
130
+ * timers, so a stalled event loop can end it later. Absent for a wait
131
+ * too long for a date. */
132
+ until?: number;
133
+ })
108
134
  | (TraceEventBase & {
109
135
  type: 'inference:exhausted';
110
136
  agentName: string;
@@ -146,7 +172,9 @@ export type TraceEvent =
146
172
  * content in it or its retry after a refusal, and a tool result the
147
173
  * boundary reports carries the channel of the round it answers. In
148
174
  * hybrid mode a `>>>` envelope can send the text itself elsewhere.
149
- * Explicit mode: the channel the start's wake came from. */
175
+ * Explicit mode: the channel its typing shows, where the start's wake
176
+ * came from, or, at a start whose wake names none, such as a budget
177
+ * restart, the one the turn already shows. */
150
178
  channelId?: string;
151
179
  })
152
180
  | (TraceEventBase & {
@@ -169,7 +197,9 @@ export type TraceEvent =
169
197
  * content in it or its retry after a refusal, and a tool result the
170
198
  * boundary reports carries the channel of the round it answers. In
171
199
  * hybrid mode a `>>>` envelope can send the text itself elsewhere.
172
- * Explicit mode: the channel the start's wake came from. */
200
+ * Explicit mode: the channel its typing shows, where the start's wake
201
+ * came from, or, at a start whose wake names none, such as a budget
202
+ * restart, the one the turn already shows. */
173
203
  channelId?: string;
174
204
  })
175
205
  | (TraceEventBase & {
@@ -181,6 +211,20 @@ export type TraceEvent =
181
211
  type: 'inference:usage';
182
212
  agentName: string;
183
213
  tokenUsage: { input: number; output: number; cacheCreation?: number; cacheRead?: number };
214
+ /**
215
+ * The provider's report on the signed thinking of the call this event
216
+ * closes (membrane's `RoundReport.thinking`): blocks it dropped before
217
+ * the model saw them, and blocks it showed the model anyway because the
218
+ * check isn't enforced. `tokenUsage` beside it is the stream's running
219
+ * total, not this call's. The provider reports them for a request that
220
+ * carried the binding control, whoever asked for it:
221
+ * `thinkingBinding.dropBlock`, or a thinking config the host sends
222
+ * itself. Present only when the report names any block.
223
+ */
224
+ thinking?: {
225
+ dropped: ThinkingBindingEntry[];
226
+ mismatchAllowed: ThinkingBindingEntry[];
227
+ };
184
228
  })
185
229
  | (TraceEventBase & {
186
230
  type: 'inference:stream_resumed';
@@ -445,6 +489,38 @@ export type TraceEvent =
445
489
  policyName: string;
446
490
  eventCount: number;
447
491
  })
492
+ | (TraceEventBase & {
493
+ /** The reply judge's verdict on a `judge` rule's batch. `verdict`:
494
+ * `reply` or `wait` as the judge answered, `error` when it failed,
495
+ * timed out or answered nothing usable; `woke` is whether the batch
496
+ * then woke the agent (an error does by the host's onError).
497
+ * The judge's reason is in the agent's gate_status, not here: it's
498
+ * written from the agent's context. */
499
+ type: 'gate:judge-verdict';
500
+ policyName: string;
501
+ verdict: 'reply' | 'wait' | 'error';
502
+ woke: boolean;
503
+ eventCount: number;
504
+ durationMs: number;
505
+ model?: string;
506
+ inputTokens?: number;
507
+ cacheReadTokens?: number;
508
+ outputTokens?: number;
509
+ })
510
+ | (TraceEventBase & {
511
+ /** A batched wake's turn started without its `[Gate: …]` line (the
512
+ * gate hands the line to the wake when its message is the newest at
513
+ * the fire, EventGate isNewestEntry, and the turn's start decides).
514
+ * `reason`: `newest`, on the delivery agent's start the message was
515
+ * still the newest entry in the window; `held`, the host was quiesced
516
+ * or another reader of the residents' shared slot had a turn alive,
517
+ * so no line could be written then. */
518
+ type: 'gate:wake-line-omitted';
519
+ reason: 'newest' | 'held';
520
+ policyNames: string[];
521
+ eventType: string;
522
+ channelId?: string;
523
+ })
448
524
  | (TraceEventBase & {
449
525
  type: 'gate:config-reloaded';
450
526
  configPath: string;
@@ -508,6 +584,8 @@ export type TraceEvent =
508
584
  | (TraceEventBase & {
509
585
  type: 'mcpl:conversation-spawned';
510
586
  channelId: string;
587
+ /** The channel's server: a channel id is unique only within one server. */
588
+ serverId: string;
511
589
  agentName: string;
512
590
  generation: number;
513
591
  template: string;
@@ -515,22 +593,30 @@ export type TraceEvent =
515
593
  | (TraceEventBase & {
516
594
  type: 'mcpl:conversation-spawn-failed';
517
595
  channelId: string;
596
+ /** The channel's server: a channel id is unique only within one server. */
597
+ serverId: string;
518
598
  agentName: string;
519
599
  error: string;
520
600
  })
521
601
  | (TraceEventBase & {
522
602
  type: 'mcpl:conversation-unrouted';
523
603
  channelId: string;
604
+ /** The channel's server: a channel id is unique only within one server. */
605
+ serverId: string;
524
606
  messageId: string;
525
607
  })
526
608
  | (TraceEventBase & {
527
609
  type: 'mcpl:conversation-binding-orphaned';
528
610
  channelId: string;
611
+ /** The channel's server: a channel id is unique only within one server. */
612
+ serverId: string;
529
613
  agentName: string;
530
614
  })
531
615
  | (TraceEventBase & {
532
616
  type: 'mcpl:conversation-closed';
533
617
  channelId: string;
618
+ /** The channel's server: a channel id is unique only within one server. */
619
+ serverId: string;
534
620
  agentName: string;
535
621
  reason: 'idle-ttl';
536
622
  })
@@ -538,6 +624,8 @@ export type TraceEvent =
538
624
  type: 'mcpl:conversation-disposed';
539
625
  agentName: string;
540
626
  channelId?: string;
627
+ /** The home channel's server, beside its channelId. */
628
+ serverId?: string;
541
629
  })
542
630
 
543
631
  // Host-owned speech routing (ChannelRegistry.routeSpeech). One trace per
@@ -569,6 +657,9 @@ export type TraceEvent =
569
657
  type: 'mcpl:speech-route-failed';
570
658
  /** Agent / conversation whose speech failed to route. */
571
659
  conversationId: string;
660
+ /** The channel's server, where the destination, or the caller, named
661
+ * one: a channel id is unique only within one server. */
662
+ serverId?: string;
572
663
  /** Empty string when the failure was "no locus at all". */
573
664
  channelId: string;
574
665
  reason: string;
@@ -780,7 +871,7 @@ export type TraceEvent =
780
871
  parkedAdmissions?: number;
781
872
  /** True when undrained turns were force-cancelled (abandon). */
782
873
  abandoned?: boolean;
783
- /** Agents whose turn the abandon had not ended when its grace ran out: a token held with no stream and no check ahead (a puppet tool turn, a store surgery's reservation, a turn finishing its last delivery), or a turn that hadn't reached its next check, the tool-result guard's wait for its speech included. A turn whose stream the abandon cancelled while it was still streaming isn't listed, even one still running when the grace ran out. */
874
+ /** Agents whose turn the abandon had not ended when its grace ran out: a token held with no stream and no check ahead (a puppet tool turn, a store surgery's reservation, a turn finishing its last delivery), or a turn that hadn't reached its next check, the tool-result guard's wait for its speech included, or a turn whose stream's cancel threw with no check ahead, so that its stream goes on. A turn whose stream the abandon cancelled while it was still streaming isn't listed, even one still running when the grace ran out. */
784
875
  unabandonable?: string[];
785
876
  })
786
877
  | (TraceEventBase & {