@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
@@ -0,0 +1,325 @@
1
+ /**
2
+ * What a start does to an existing gate.json, given the recipe's gate config.
3
+ *
4
+ * The gate keeps the recipe it last applied in a file of its own beside
5
+ * gate.json (`gate.recipe.json` for `gate.json`), written by the gate. A start
6
+ * merges the recipe into gate.json three ways, rule by rule, against it:
7
+ * - a rule as the last recipe left it follows the new recipe: it takes the
8
+ * new definition, or goes when the new recipe no longer declares it, so a
9
+ * renamed rule goes under its old name and comes in under its new one;
10
+ * - a rule edited since the last recipe keeps its definition, unless it now
11
+ * agrees with the recipe's;
12
+ * - a rule both recipes declare, removed from gate.json since, comes back;
13
+ * - a rule no recipe declared (added at run time, or by hand) stays, and if
14
+ * the recipe now declares it as it stands, it's the recipe's from then on;
15
+ * - a rule new in the recipe comes in.
16
+ *
17
+ * Order is an edit of its own, apart from a rule's definition. When gate.json
18
+ * holds the rules both recipes declare in the last recipe's order, the recipe's
19
+ * rules take the new recipe's order, in the places gate.json gives them, and
20
+ * every other rule keeps its place. When one of them was moved since
21
+ * (wake_add_rule's position moves one), gate.json's order stays. Either way, a
22
+ * recipe rule new to gate.json goes before the recipe rule that follows it
23
+ * there, or after the one before it when none follows.
24
+ * `default` follows the same rule as a definition.
25
+ *
26
+ * Without a last recipe, as at the first start after this change, nothing is
27
+ * removed or redefined: the rules that match the recipe by name and definition
28
+ * take its order, every other rule stays, and the line names those that differ
29
+ * from the recipe or aren't in it. A rule that differs can be removed, and the
30
+ * next start restores it from the recipe.
31
+ *
32
+ * Rules are compared by what they mean and kept as written. Two rules agree
33
+ * when the gate reads them the same, so a rule `wake_add_rule` wrote as the
34
+ * gate reads it agrees with the recipe's rule as written, and a change to a
35
+ * field the gate doesn't read alone isn't an edit; the caller gives the
36
+ * meaning (`meaningOf`). A rule the gate leaves out has no reading, so it is
37
+ * compared as written, a change to any of its fields an edit. A rule that agrees with the recipe stays as gate.json
38
+ * holds it, and one that follows the recipe takes the recipe's rule as
39
+ * written. A rule with no name stays where gate.json holds it, and a recipe's
40
+ * rule with no name is never merged: the merge keys rules by name.
41
+ */
42
+ /** The file beside gate.json that holds the recipe the gate last applied. */
43
+ export function lastRecipePath(configPath) {
44
+ return `${configPath.replace(/\.json$/, '')}.recipe.json`;
45
+ }
46
+ function sortKeys(value) {
47
+ if (Array.isArray(value))
48
+ return value.map(sortKeys);
49
+ if (value && typeof value === 'object') {
50
+ // No prototype, so a key such as "__proto__", which JSON.parse gives as an
51
+ // own field, is copied as one rather than setting the prototype.
52
+ const out = Object.create(null);
53
+ for (const key of Object.keys(value).sort()) {
54
+ out[key] = sortKeys(value[key]);
55
+ }
56
+ return out;
57
+ }
58
+ return value;
59
+ }
60
+ /** A config or policy as text that doesn't depend on its keys' order. */
61
+ export function canonical(value) {
62
+ return JSON.stringify(sortKeys(value));
63
+ }
64
+ const same = (a, b) => canonical(a) === canonical(b);
65
+ /** Changes with nothing in them, for a start to fill. */
66
+ export function noChanges() {
67
+ return {
68
+ added: [], removed: [], updated: [], restored: [], moved: [],
69
+ keptEdited: [], differsFromRecipe: [], outsideRecipe: [], orderKept: false,
70
+ };
71
+ }
72
+ /** A rule's name as written, when it has a usable one. */
73
+ export function ruleName(rule) {
74
+ if (!rule || typeof rule !== 'object' || Array.isArray(rule))
75
+ return undefined;
76
+ const name = rule.name;
77
+ return typeof name === 'string' && name ? name : undefined;
78
+ }
79
+ /** A rule name the list gives more than once, if any: the merge keys rules by name. */
80
+ export function duplicateName(rules) {
81
+ const seen = new Set();
82
+ for (const rule of rules) {
83
+ const name = ruleName(rule);
84
+ if (name === undefined)
85
+ continue;
86
+ if (seen.has(name))
87
+ return name;
88
+ seen.add(name);
89
+ }
90
+ return undefined;
91
+ }
92
+ /** A `default` as the gate reads one: left out, null or "" is "always". */
93
+ function behaviorOf(value) {
94
+ return value === undefined || value === null || value === '' ? 'always' : value;
95
+ }
96
+ /** The names in one longest sequence that `a` and `b` share in order. */
97
+ function longestShared(a, b) {
98
+ const rows = a.length + 1;
99
+ const cols = b.length + 1;
100
+ const table = Array.from({ length: rows }, () => new Array(cols).fill(0));
101
+ for (let i = a.length - 1; i >= 0; i--) {
102
+ for (let j = b.length - 1; j >= 0; j--) {
103
+ table[i][j] = a[i] === b[j] ? table[i + 1][j + 1] + 1 : Math.max(table[i + 1][j], table[i][j + 1]);
104
+ }
105
+ }
106
+ const shared = new Set();
107
+ let i = 0;
108
+ let j = 0;
109
+ while (i < a.length && j < b.length) {
110
+ if (a[i] === b[j]) {
111
+ shared.add(a[i]);
112
+ i++;
113
+ j++;
114
+ }
115
+ else if (table[i + 1][j] > table[i][j + 1]) {
116
+ i++;
117
+ }
118
+ else {
119
+ // On a tie, the result's rule is the one named as moved: the rule a
120
+ // swap brought earlier, such as one the old appending left behind a
121
+ // catch-all.
122
+ j++;
123
+ }
124
+ }
125
+ return shared;
126
+ }
127
+ /**
128
+ * Merge `recipe` into `live` against `last`, the recipe last applied (null
129
+ * when there is none), each as written. Pure: the caller reads and writes the
130
+ * files, and gives `meaningOf`, a rule's meaning as a string two rules share
131
+ * when they mean the same (as written, unless given). Returns the rule list
132
+ * and `default` to write, each as written, and whether `default` changed.
133
+ * Throws when `live` or `recipe` names a rule twice, since the merge keys
134
+ * rules by name.
135
+ */
136
+ export function reconcileWithRecipe(live, recipe, last, meaningOf = canonical) {
137
+ const agree = (a, b) => meaningOf(a) === meaningOf(b);
138
+ const liveDuplicate = duplicateName(live.rules);
139
+ if (liveDuplicate !== undefined) {
140
+ throw new Error(`gate.json names the rule "${liveDuplicate}" twice`);
141
+ }
142
+ const recipeDuplicate = duplicateName(recipe.rules);
143
+ if (recipeDuplicate !== undefined) {
144
+ throw new Error(`the recipe names the rule "${recipeDuplicate}" twice`);
145
+ }
146
+ const changes = noChanges();
147
+ // Each rule by its name; a rule with no name by a key no name can be, so
148
+ // it keeps its place and matches nothing.
149
+ const keyOf = (rule, index) => ruleName(rule) ?? `\u0000nameless ${index}`;
150
+ const byName = (rules) => new Map(rules.flatMap((rule) => {
151
+ const name = ruleName(rule);
152
+ return name === undefined ? [] : [[name, rule]];
153
+ }));
154
+ const inLive = new Map(live.rules.map((rule, index) => [keyOf(rule, index), rule]));
155
+ const inRecipe = byName(recipe.rules);
156
+ const inLast = last ? byName(last.rules) : null;
157
+ // Each rule gate.json keeps, with its definition, and which of them take
158
+ // the recipe's order (`ordered`); the rest keep their places.
159
+ const definitions = new Map();
160
+ const ordered = new Set();
161
+ live.rules.forEach((rule, index) => {
162
+ const name = keyOf(rule, index);
163
+ const declared = inRecipe.get(name);
164
+ const before = inLast?.get(name);
165
+ if (declared !== undefined && agree(rule, declared)) {
166
+ // As the recipe has it: kept as written, whatever the record says, and
167
+ // nothing to change or name.
168
+ definitions.set(name, rule);
169
+ ordered.add(name);
170
+ }
171
+ else if (ruleName(rule) === undefined) {
172
+ definitions.set(name, rule);
173
+ }
174
+ else if (!inLast) {
175
+ definitions.set(name, rule);
176
+ (declared !== undefined ? changes.differsFromRecipe : changes.outsideRecipe).push(name);
177
+ }
178
+ else if (before !== undefined) {
179
+ const edited = !agree(rule, before);
180
+ if (declared === undefined) {
181
+ if (edited) {
182
+ definitions.set(name, rule);
183
+ changes.keptEdited.push(name);
184
+ }
185
+ else {
186
+ changes.removed.push(name);
187
+ }
188
+ }
189
+ else {
190
+ // Both recipes declare it: it's a recipe rule, so it takes the recipe's order.
191
+ ordered.add(name);
192
+ if (edited) {
193
+ definitions.set(name, rule);
194
+ if (!agree(declared, before))
195
+ changes.keptEdited.push(name);
196
+ }
197
+ else {
198
+ definitions.set(name, declared);
199
+ changes.updated.push(name);
200
+ }
201
+ }
202
+ }
203
+ else {
204
+ // No recipe declared it as it stands: a run-time rule, or one the recipe
205
+ // now declares otherwise.
206
+ definitions.set(name, rule);
207
+ if (declared !== undefined)
208
+ changes.differsFromRecipe.push(name);
209
+ }
210
+ });
211
+ const liveOrder = live.rules.map(keyOf);
212
+ const recipeOrder = recipe.rules.flatMap((rule) => {
213
+ const name = ruleName(rule);
214
+ return name === undefined ? [] : [name];
215
+ });
216
+ const staying = liveOrder.filter((name) => definitions.has(name));
217
+ // Whether gate.json holds the rules both recipes declare in the last recipe's order.
218
+ const shared = (order) => order.filter((name) => inLast?.has(name) && inRecipe.has(name) && inLive.has(name));
219
+ const lastOrder = last ? last.rules.flatMap((rule) => {
220
+ const name = ruleName(rule);
221
+ return name === undefined ? [] : [name];
222
+ }) : [];
223
+ const followsLast = canonical(shared(liveOrder)) === canonical(shared(lastOrder));
224
+ let order;
225
+ if (followsLast) {
226
+ // The recipe's rules fill the places its rules hold, in the recipe's order.
227
+ const recipeRules = recipeOrder.filter((name) => ordered.has(name));
228
+ let next = 0;
229
+ order = staying.map((name) => (ordered.has(name) ? recipeRules[next++] : name));
230
+ }
231
+ else {
232
+ order = staying;
233
+ // Named only when it holds something back: the recipe reordered these
234
+ // rules, and gate.json doesn't already hold the recipe's order.
235
+ changes.orderKept = canonical(shared(recipeOrder)) !== canonical(shared(lastOrder))
236
+ && canonical(shared(liveOrder)) !== canonical(shared(recipeOrder));
237
+ }
238
+ // A recipe rule new to gate.json goes before the recipe rule that follows it
239
+ // there, or after the one before it when none follows.
240
+ recipeOrder.forEach((name, index) => {
241
+ if (inLive.has(name))
242
+ return;
243
+ definitions.set(name, inRecipe.get(name));
244
+ (inLast?.has(name) ? changes.restored : changes.added).push(name);
245
+ const following = recipeOrder.slice(index + 1).find((later) => order.includes(later));
246
+ if (following !== undefined) {
247
+ order.splice(order.indexOf(following), 0, name);
248
+ return;
249
+ }
250
+ const preceding = recipeOrder.slice(0, index).reverse().find((earlier) => order.includes(earlier));
251
+ if (preceding !== undefined)
252
+ order.splice(order.indexOf(preceding) + 1, 0, name);
253
+ else
254
+ order.push(name);
255
+ });
256
+ // Only the recipe's rules move; every other rule keeps its place.
257
+ const stayedInOrder = longestShared(staying.filter((name) => ordered.has(name)), order.filter((name) => ordered.has(name)));
258
+ changes.moved = order.filter((name) => ordered.has(name) && !stayedInOrder.has(name));
259
+ // `default` as the gate reads it, compared as written once read.
260
+ const liveDefault = behaviorOf(live.default);
261
+ const recipeDefault = behaviorOf(recipe.default);
262
+ let defaultBehavior = live.default;
263
+ let defaultChanged = false;
264
+ const shownBehavior = (value) => (typeof value === 'string' ? value : JSON.stringify(value));
265
+ if (!last) {
266
+ if (!same(liveDefault, recipeDefault))
267
+ changes.defaultDiffers = { kept: shownBehavior(liveDefault), recipe: shownBehavior(recipeDefault) };
268
+ }
269
+ else {
270
+ const lastDefault = behaviorOf(last.default);
271
+ if (same(liveDefault, lastDefault) || same(liveDefault, recipeDefault)) {
272
+ if (!same(recipeDefault, liveDefault)) {
273
+ defaultBehavior = recipe.default;
274
+ defaultChanged = true;
275
+ changes.defaultChange = { from: shownBehavior(liveDefault), to: shownBehavior(recipeDefault) };
276
+ }
277
+ }
278
+ else if (!same(recipeDefault, lastDefault)) {
279
+ changes.defaultKept = shownBehavior(liveDefault);
280
+ }
281
+ }
282
+ return {
283
+ rules: order.map((name) => definitions.get(name)),
284
+ default: defaultBehavior,
285
+ defaultChanged,
286
+ changes,
287
+ };
288
+ }
289
+ /** The log line a start gives its changes, or null when it changed nothing worth saying. */
290
+ export function reconcileLine(changes) {
291
+ const parts = [];
292
+ if (changes.recordUnreadable !== undefined) {
293
+ parts.push(`the recorded recipe couldn't be read (${changes.recordUnreadable}), so this start removed and redefined nothing`);
294
+ }
295
+ const list = (label, names) => {
296
+ if (names.length > 0)
297
+ parts.push(`${label} ${names.join(', ')}`);
298
+ };
299
+ list('added', changes.added);
300
+ list('removed', changes.removed);
301
+ list('updated', changes.updated);
302
+ list('restored', changes.restored);
303
+ list('moved', changes.moved);
304
+ list('kept as edited, though the recipe changed or dropped it:', changes.keptEdited);
305
+ if (changes.differsFromRecipe.length > 0) {
306
+ parts.push(`kept, though the recipe defines it otherwise: ${changes.differsFromRecipe.join(', ')} `
307
+ + '(remove such a rule, and the next start restores it from the recipe)');
308
+ }
309
+ if (changes.outsideRecipe.length > 0) {
310
+ parts.push(`kept, not in the recipe: ${changes.outsideRecipe.join(', ')} `
311
+ + "(a stale one can be removed, and no start brings it back)");
312
+ }
313
+ if (changes.defaultChange)
314
+ parts.push(`default ${changes.defaultChange.from} → ${changes.defaultChange.to}`);
315
+ if (changes.defaultKept)
316
+ parts.push(`default kept as edited (${changes.defaultKept}), though the recipe changed it`);
317
+ if (changes.defaultDiffers) {
318
+ parts.push(`default kept as gate.json has it (${changes.defaultDiffers.kept}), though the recipe's is ${changes.defaultDiffers.recipe} `
319
+ + "(set it to the recipe's, and later starts follow the recipe)");
320
+ }
321
+ if (changes.orderKept)
322
+ parts.push("gate.json's order kept, though the recipe reordered its rules, since a recipe rule was moved in it");
323
+ return parts.length > 0 ? `[gate] the recipe was applied to gate.json: ${parts.join('; ')}` : null;
324
+ }
325
+ //# sourceMappingURL=recipe-reconcile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recipe-reconcile.js","sourceRoot":"","sources":["../../../src/gate/recipe-reconcile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AA0BH,6EAA6E;AAC7E,MAAM,UAAU,cAAc,CAAC,UAAkB;IAC/C,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,cAAc,CAAC;AAC5D,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,2EAA2E;QAC3E,iEAAiE;QACjE,MAAM,GAAG,GAA4B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAgC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C,cAAc,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CACR,qCAAqC,OAAO,CAAC,cAAc,CAAC,IAAI,6BAA6B,OAAO,CAAC,cAAc,CAAC,MAAM,GAAG;cACzH,8DAA8D,CACnE,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,oGAAoG,CAAC,CAAC;IACxI,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,+CAA+C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACrG,CAAC"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * ReplyJudge — the small model a `judge` wake rule asks whether now is a good
3
+ * time for the agent to reply (JudgeConfig).
4
+ *
5
+ * Per batch it takes the request the agent WOULD send if woken now (the
6
+ * framework's previewActivation, a dry run that commits nothing), renders it
7
+ * as one plain-text document (the agent's system prompt, abridged, then its
8
+ * conversation, oldest first), keeps the newest part of that document that
9
+ * fits the judge's input budget, and asks the model, with the agent's own
10
+ * instructions and the batch, for one line: `REPLY: <reason>` or
11
+ * `WAIT: <reason>`.
12
+ *
13
+ * Cost and latency. The budget (`maxInputTokens`, default 90,000) keeps every
14
+ * request under the 100,000-token line past which Claude Haiku 5.5 costs five
15
+ * times as much. Tokens are estimated from characters, at a ratio the judge
16
+ * corrects from every response's reported input, so the estimate tracks the
17
+ * model's tokenizer and the context's mix of prose and code. The document is
18
+ * sent as a run of chunks that start at an anchor, the first message shown,
19
+ * which stays put while the window grows into its budget: the chunks before
20
+ * the newest stay byte-identical from one request to the next, and a cache
21
+ * breakpoint after the last full one lets every later request read them from
22
+ * the prompt cache. Only when the window outgrows its budget does the anchor
23
+ * move, to leave the window a share of the budget to grow into again.
24
+ *
25
+ * The judge reads; it never writes into the agent's context and never speaks.
26
+ */
27
+ import type { DetailedUsage, Membrane, NormalizedMessage, NormalizedRequest } from '@animalabs/membrane';
28
+ import type { JudgeFn, JudgeRequest, ReplyJudgeOptions, UpcomingWake } from './types.js';
29
+ /** The judge's model when the host names none. */
30
+ export declare const DEFAULT_JUDGE_MODEL = "claude-haiku-5-5";
31
+ /** The judge's input budget when the host names none: under Haiku 5.5's 100K price line, with margin. */
32
+ export declare const DEFAULT_JUDGE_MAX_INPUT_TOKENS = 90000;
33
+ /** The smallest input budget the judge takes: its instructions, the batch and a little context. A
34
+ * host that wants only the newest few messages read (a short tail, cheaper and quicker, with less
35
+ * of the room's history to weigh) sets a budget near it. */
36
+ export declare const MIN_JUDGE_INPUT_TOKENS = 4000;
37
+ /** What the framework gives the judge. */
38
+ export interface ReplyJudgeDeps {
39
+ /** The membrane the judge calls for an agent. The framework's binds the
40
+ * judge as it binds compression, refusing a call rather than waiting under
41
+ * a hold, and never waits on the agent's turn. */
42
+ membraneFor: (agentName: string) => Membrane;
43
+ options?: ReplyJudgeOptions;
44
+ /** Which of the batch's agents the judge reads the context of. */
45
+ chooseAgent: (agentNames: string[]) => string | undefined;
46
+ /** The request the agent would send if woken now, as a dry run (previewActivation). */
47
+ preview: (agentName: string) => Promise<NormalizedRequest>;
48
+ /** Count a judge request's usage as the agent's, where its turns' usage is counted. */
49
+ recordUsage?: (agentName: string, usage: DetailedUsage) => void;
50
+ /** What else will wake the agent with no new event, beyond the gate's own
51
+ * timers the request carries: wakes the framework has queued or holds. A
52
+ * provider that throws counts as knowing of none. */
53
+ upcomingWakes?: (agentName: string) => UpcomingWake[] | Promise<UpcomingWake[]>;
54
+ }
55
+ /** A message as the document shows it: its participant, and each block as text. Thinking is the agent's own, and isn't shown. */
56
+ export declare function renderMessage(message: NormalizedMessage): string;
57
+ /** Text no longer than `max` characters: a longer one keeps its head and tail, the middle named as cut. */
58
+ export declare function cut(text: string, max: number): string;
59
+ /**
60
+ * What waiting would leave the agent with: what wakes it anyway, soonest
61
+ * first, or that nothing the host knows of is scheduled. A server's own
62
+ * timers (a heartbeat, a reminder) are listed only where the host was told
63
+ * of them, so the empty case says so.
64
+ */
65
+ export declare function ifYouWait(wakes: readonly UpcomingWake[], agentName: string, now: number): string;
66
+ /**
67
+ * The verdict in a response's text: its last line that starts with REPLY or
68
+ * WAIT in capitals followed by a colon or a dash, as the judge is asked to
69
+ * write it. A capital word without one, or a lower-case "reply" or "wait" in
70
+ * the judge's reasoning ("Wait, they did ask"), isn't a verdict.
71
+ */
72
+ export declare function parseVerdict(text: string): {
73
+ reply: boolean;
74
+ reason: string;
75
+ } | undefined;
76
+ /** The judge's own system prompt: stable per agent, so it caches. */
77
+ export declare function judgeSystemPrompt(agentName: string): string;
78
+ /** The closing message: the batch, the agent's instructions, the question. */
79
+ export declare function judgeQuestion(request: Pick<JudgeRequest, 'events' | 'instructions' | 'upcomingWakes'>, agentName: string, now: number, maxEventChars?: number): string;
80
+ export declare class ReplyJudge {
81
+ private readonly membraneFor;
82
+ private readonly cacheTtl;
83
+ private readonly model;
84
+ private readonly maxInputTokens;
85
+ private readonly effort;
86
+ private readonly chooseAgent;
87
+ private readonly preview;
88
+ private readonly recordUsage;
89
+ private readonly extraWakes;
90
+ /** Characters per token, corrected from each response's reported input. */
91
+ private charsPerToken;
92
+ private readonly anchors;
93
+ constructor(deps: ReplyJudgeDeps);
94
+ /** The gate's judge function. */
95
+ readonly judge: JudgeFn;
96
+ /** The ratio the judge estimates tokens by now (for tests and status). */
97
+ estimateRatio(): number;
98
+ private tokens;
99
+ /** Build the judge's request for one batch: the system prompt, the document in chunks, the question. */
100
+ buildRequest(request: JudgeRequest, now?: number): Promise<{
101
+ request: NormalizedRequest;
102
+ agentName: string;
103
+ chars: number;
104
+ }>;
105
+ /**
106
+ * Where the window starts: at last request's anchor, while the window from
107
+ * there fits; otherwise where the newest messages fill FRESH_WINDOW_SHARE
108
+ * of the budget, leaving room to grow before it moves again.
109
+ */
110
+ private windowStart;
111
+ private findAnchor;
112
+ /** Learn the tokenizer's ratio from one response, leaning conservative after an overshoot. */
113
+ private calibrate;
114
+ private decide;
115
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