@animalabs/agent-framework 0.22.0 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) hide show
  1. package/README.md +12 -5
  2. package/dist/src/agent.d.ts +192 -19
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +407 -66
  5. package/dist/src/agent.js.map +1 -1
  6. package/dist/src/api/mcp-server-core.d.ts +41 -0
  7. package/dist/src/api/mcp-server-core.d.ts.map +1 -0
  8. package/dist/src/api/mcp-server-core.js +593 -0
  9. package/dist/src/api/mcp-server-core.js.map +1 -0
  10. package/dist/src/api/mcp-server.d.ts +2 -36
  11. package/dist/src/api/mcp-server.d.ts.map +1 -1
  12. package/dist/src/api/mcp-server.js +15 -595
  13. package/dist/src/api/mcp-server.js.map +1 -1
  14. package/dist/src/api/server.d.ts +9 -1
  15. package/dist/src/api/server.d.ts.map +1 -1
  16. package/dist/src/api/server.js +84 -23
  17. package/dist/src/api/server.js.map +1 -1
  18. package/dist/src/api/types.d.ts +9 -1
  19. package/dist/src/api/types.d.ts.map +1 -1
  20. package/dist/src/code-execution/py-runner.d.ts.map +1 -1
  21. package/dist/src/code-execution/py-runner.js.map +1 -1
  22. package/dist/src/framework.d.ts +682 -103
  23. package/dist/src/framework.d.ts.map +1 -1
  24. package/dist/src/framework.js +3202 -718
  25. package/dist/src/framework.js.map +1 -1
  26. package/dist/src/gate/event-gate.d.ts.map +1 -1
  27. package/dist/src/gate/gate-script.d.ts.map +1 -1
  28. package/dist/src/gate/gate-script.js.map +1 -1
  29. package/dist/src/index.d.ts +4 -4
  30. package/dist/src/index.d.ts.map +1 -1
  31. package/dist/src/index.js +2 -2
  32. package/dist/src/index.js.map +1 -1
  33. package/dist/src/mcpl/capability-grant.d.ts.map +1 -1
  34. package/dist/src/mcpl/channel-registry.d.ts +26 -7
  35. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  36. package/dist/src/mcpl/channel-registry.js +102 -22
  37. package/dist/src/mcpl/channel-registry.js.map +1 -1
  38. package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -1
  39. package/dist/src/mcpl/checkpoint-manager.js.map +1 -1
  40. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  41. package/dist/src/mcpl/errors.js.map +1 -1
  42. package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
  43. package/dist/src/mcpl/feature-set-manager.js +4 -3
  44. package/dist/src/mcpl/feature-set-manager.js.map +1 -1
  45. package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
  46. package/dist/src/mcpl/index.d.ts +2 -0
  47. package/dist/src/mcpl/index.d.ts.map +1 -1
  48. package/dist/src/mcpl/index.js.map +1 -1
  49. package/dist/src/mcpl/inference-router.d.ts.map +1 -1
  50. package/dist/src/mcpl/log-value.d.ts +54 -0
  51. package/dist/src/mcpl/log-value.d.ts.map +1 -0
  52. package/dist/src/mcpl/log-value.js +109 -0
  53. package/dist/src/mcpl/log-value.js.map +1 -0
  54. package/dist/src/mcpl/prose-stream-router.d.ts +6 -6
  55. package/dist/src/mcpl/prose-stream-router.d.ts.map +1 -1
  56. package/dist/src/mcpl/prose-stream-router.js +4 -4
  57. package/dist/src/mcpl/prose-stream-router.js.map +1 -1
  58. package/dist/src/mcpl/push-coalescer.d.ts +38 -3
  59. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  60. package/dist/src/mcpl/push-coalescer.js +81 -16
  61. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  62. package/dist/src/mcpl/push-handler.d.ts +26 -3
  63. package/dist/src/mcpl/push-handler.d.ts.map +1 -1
  64. package/dist/src/mcpl/push-handler.js +87 -23
  65. package/dist/src/mcpl/push-handler.js.map +1 -1
  66. package/dist/src/mcpl/reference-fetcher.d.ts +2 -1
  67. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  68. package/dist/src/mcpl/reference-fetcher.js +20 -9
  69. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  70. package/dist/src/mcpl/references.d.ts +29 -6
  71. package/dist/src/mcpl/references.d.ts.map +1 -1
  72. package/dist/src/mcpl/references.js +57 -16
  73. package/dist/src/mcpl/references.js.map +1 -1
  74. package/dist/src/mcpl/refusal-lines.d.ts +37 -0
  75. package/dist/src/mcpl/refusal-lines.d.ts.map +1 -0
  76. package/dist/src/mcpl/refusal-lines.js +61 -0
  77. package/dist/src/mcpl/refusal-lines.js.map +1 -0
  78. package/dist/src/mcpl/scope-manager.d.ts.map +1 -1
  79. package/dist/src/mcpl/server-connection.d.ts +46 -3
  80. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  81. package/dist/src/mcpl/server-connection.js +98 -15
  82. package/dist/src/mcpl/server-connection.js.map +1 -1
  83. package/dist/src/mcpl/server-registry.d.ts.map +1 -1
  84. package/dist/src/mcpl/tool-classes.d.ts +1 -1
  85. package/dist/src/mcpl/tool-classes.d.ts.map +1 -1
  86. package/dist/src/mcpl/tool-classes.js +3 -2
  87. package/dist/src/mcpl/tool-classes.js.map +1 -1
  88. package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
  89. package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
  90. package/dist/src/mcpl/transport.d.ts +23 -5
  91. package/dist/src/mcpl/transport.d.ts.map +1 -1
  92. package/dist/src/mcpl/transport.js +103 -10
  93. package/dist/src/mcpl/transport.js.map +1 -1
  94. package/dist/src/mcpl/types.d.ts +30 -26
  95. package/dist/src/mcpl/types.d.ts.map +1 -1
  96. package/dist/src/mcpl/types.js.map +1 -1
  97. package/dist/src/module-registry.d.ts +9 -3
  98. package/dist/src/module-registry.d.ts.map +1 -1
  99. package/dist/src/module-registry.js +3 -2
  100. package/dist/src/module-registry.js.map +1 -1
  101. package/dist/src/modules/api/index.d.ts.map +1 -1
  102. package/dist/src/modules/discord/discord-js-client.d.ts.map +1 -1
  103. package/dist/src/modules/discord/discord-js-client.js.map +1 -1
  104. package/dist/src/modules/discord/index.d.ts.map +1 -1
  105. package/dist/src/modules/discord/index.js +4 -2
  106. package/dist/src/modules/discord/index.js.map +1 -1
  107. package/dist/src/modules/health/index.d.ts.map +1 -1
  108. package/dist/src/modules/health/index.js.map +1 -1
  109. package/dist/src/modules/history/index.d.ts.map +1 -1
  110. package/dist/src/modules/history/index.js.map +1 -1
  111. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  112. package/dist/src/modules/history/semantic.js.map +1 -1
  113. package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
  114. package/dist/src/modules/workspace/branch-intent.js.map +1 -1
  115. package/dist/src/modules/workspace/disk-agreement.d.ts +22 -4
  116. package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -1
  117. package/dist/src/modules/workspace/disk-agreement.js +63 -25
  118. package/dist/src/modules/workspace/disk-agreement.js.map +1 -1
  119. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  120. package/dist/src/modules/workspace/index.d.ts +8 -4
  121. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  122. package/dist/src/modules/workspace/index.js +85 -16
  123. package/dist/src/modules/workspace/index.js.map +1 -1
  124. package/dist/src/modules/workspace/observe.d.ts +56 -11
  125. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  126. package/dist/src/modules/workspace/observe.js +288 -43
  127. package/dist/src/modules/workspace/observe.js.map +1 -1
  128. package/dist/src/modules/workspace/reconcile.d.ts +31 -1
  129. package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
  130. package/dist/src/modules/workspace/reconcile.js +63 -12
  131. package/dist/src/modules/workspace/reconcile.js.map +1 -1
  132. package/dist/src/modules/workspace/types.d.ts +27 -2
  133. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  134. package/dist/src/modules/workspace/types.js.map +1 -1
  135. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  136. package/dist/src/modules/workspace/watcher.js.map +1 -1
  137. package/dist/src/operator-log.d.ts +41 -0
  138. package/dist/src/operator-log.d.ts.map +1 -1
  139. package/dist/src/operator-log.js.map +1 -1
  140. package/dist/src/provider-waits.d.ts +216 -0
  141. package/dist/src/provider-waits.d.ts.map +1 -0
  142. package/dist/src/provider-waits.js +482 -0
  143. package/dist/src/provider-waits.js.map +1 -0
  144. package/dist/src/queue.d.ts.map +1 -1
  145. package/dist/src/record-journal.d.ts.map +1 -1
  146. package/dist/src/record-journal.js.map +1 -1
  147. package/dist/src/recovery/discord-awareness-outbox.d.ts.map +1 -1
  148. package/dist/src/recovery/discord-awareness-outbox.js.map +1 -1
  149. package/dist/src/recovery/offline-branch.d.ts.map +1 -1
  150. package/dist/src/recovery/offline-branch.js +29 -24
  151. package/dist/src/recovery/offline-branch.js.map +1 -1
  152. package/dist/src/recovery/recover-cli.js.map +1 -1
  153. package/dist/src/refusal-reactions.d.ts +14 -12
  154. package/dist/src/refusal-reactions.d.ts.map +1 -1
  155. package/dist/src/refusal-reactions.js +14 -12
  156. package/dist/src/refusal-reactions.js.map +1 -1
  157. package/dist/src/runtime/liveness-watchdog.d.ts.map +1 -1
  158. package/dist/src/runtime/liveness-watchdog.js.map +1 -1
  159. package/dist/src/shutdown.d.ts.map +1 -1
  160. package/dist/src/shutdown.js.map +1 -1
  161. package/dist/src/stored-removal.d.ts +73 -0
  162. package/dist/src/stored-removal.d.ts.map +1 -0
  163. package/dist/src/stored-removal.js +100 -0
  164. package/dist/src/stored-removal.js.map +1 -0
  165. package/dist/src/thinking-token-stamp.js.map +1 -1
  166. package/dist/src/tool-image-ledger.d.ts.map +1 -1
  167. package/dist/src/tool-image-ledger.js.map +1 -1
  168. package/dist/src/tool-presentation.d.ts.map +1 -1
  169. package/dist/src/tool-presentation.js.map +1 -1
  170. package/dist/src/tool-result-guard.d.ts +30 -13
  171. package/dist/src/tool-result-guard.d.ts.map +1 -1
  172. package/dist/src/tool-result-guard.js +71 -25
  173. package/dist/src/tool-result-guard.js.map +1 -1
  174. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  175. package/dist/src/tune-out/coordinator.js.map +1 -1
  176. package/dist/src/tune-out/tools.d.ts +1 -1
  177. package/dist/src/tune-out/tools.d.ts.map +1 -1
  178. package/dist/src/types/agent.d.ts +42 -6
  179. package/dist/src/types/agent.d.ts.map +1 -1
  180. package/dist/src/types/events.d.ts +12 -0
  181. package/dist/src/types/events.d.ts.map +1 -1
  182. package/dist/src/types/framework.d.ts +10 -0
  183. package/dist/src/types/framework.d.ts.map +1 -1
  184. package/dist/src/types/module.d.ts +20 -8
  185. package/dist/src/types/module.d.ts.map +1 -1
  186. package/dist/src/types/trace.d.ts +75 -13
  187. package/dist/src/types/trace.d.ts.map +1 -1
  188. package/dist/src/usage/usage-tracker.d.ts.map +1 -1
  189. package/dist/test/agent-runtime-settings.test.js +1139 -3
  190. package/dist/test/agent-runtime-settings.test.js.map +1 -1
  191. package/dist/test/batched-wake-locus.test.js.map +1 -1
  192. package/dist/test/channel-label-history.test.js.map +1 -1
  193. package/dist/test/code-execution.test.js.map +1 -1
  194. package/dist/test/conversation-fork-injection-scoping.test.js.map +1 -1
  195. package/dist/test/conversation-router.test.js.map +1 -1
  196. package/dist/test/conversation-routing.test.js +240 -6
  197. package/dist/test/conversation-routing.test.js.map +1 -1
  198. package/dist/test/discord-awareness-outbox.test.js +107 -0
  199. package/dist/test/discord-awareness-outbox.test.js.map +1 -1
  200. package/dist/test/discord-typing-keepalive.test.d.ts +2 -0
  201. package/dist/test/discord-typing-keepalive.test.d.ts.map +1 -0
  202. package/dist/test/discord-typing-keepalive.test.js +77 -0
  203. package/dist/test/discord-typing-keepalive.test.js.map +1 -0
  204. package/dist/test/ephemeral-settle.test.js.map +1 -1
  205. package/dist/test/event-gate-passthrough.test.js.map +1 -1
  206. package/dist/test/event-gate-policy-mutation.test.js.map +1 -1
  207. package/dist/test/event-gate-rate-limit.test.js.map +1 -1
  208. package/dist/test/event-gate-script.test.js.map +1 -1
  209. package/dist/test/event-gate-selfwake.test.js.map +1 -1
  210. package/dist/test/event-gate-tags.test.js.map +1 -1
  211. package/dist/test/event-gate.test.js.map +1 -1
  212. package/dist/test/explicit-prose-routing.test.js +363 -44
  213. package/dist/test/explicit-prose-routing.test.js.map +1 -1
  214. package/dist/test/framework.test.js +160 -1
  215. package/dist/test/framework.test.js.map +1 -1
  216. package/dist/test/helpers/coalescing-fixture.d.ts +2 -0
  217. package/dist/test/helpers/coalescing-fixture.d.ts.map +1 -1
  218. package/dist/test/helpers/coalescing-fixture.js +11 -4
  219. package/dist/test/helpers/coalescing-fixture.js.map +1 -1
  220. package/dist/test/helpers/mock-membrane.d.ts.map +1 -1
  221. package/dist/test/helpers/mock-membrane.js.map +1 -1
  222. package/dist/test/hide-then-turn.test.d.ts +2 -0
  223. package/dist/test/hide-then-turn.test.d.ts.map +1 -0
  224. package/dist/test/hide-then-turn.test.js +101 -0
  225. package/dist/test/hide-then-turn.test.js.map +1 -0
  226. package/dist/test/history-module-overview.test.js.map +1 -1
  227. package/dist/test/history-module-semantic.test.js.map +1 -1
  228. package/dist/test/history-module.test.js.map +1 -1
  229. package/dist/test/history-semantic-review-findings.test.js.map +1 -1
  230. package/dist/test/host-quiesce.test.js +125 -0
  231. package/dist/test/host-quiesce.test.js.map +1 -1
  232. package/dist/test/inference-exhaustion-rewind.test.js +220 -14
  233. package/dist/test/inference-exhaustion-rewind.test.js.map +1 -1
  234. package/dist/test/inference-failure-bounds.test.d.ts +2 -0
  235. package/dist/test/inference-failure-bounds.test.d.ts.map +1 -0
  236. package/dist/test/inference-failure-bounds.test.js +1202 -0
  237. package/dist/test/inference-failure-bounds.test.js.map +1 -0
  238. package/dist/test/kv-unified-open-flight-retry.test.js.map +1 -1
  239. package/dist/test/late-events-after-stop.test.d.ts +2 -0
  240. package/dist/test/late-events-after-stop.test.d.ts.map +1 -0
  241. package/dist/test/late-events-after-stop.test.js +122 -0
  242. package/dist/test/late-events-after-stop.test.js.map +1 -0
  243. package/dist/test/liveness-watchdog.test.js.map +1 -1
  244. package/dist/test/maintenance-timer.test.js +1564 -2
  245. package/dist/test/maintenance-timer.test.js.map +1 -1
  246. package/dist/test/mcp-server-bin.test.d.ts +2 -0
  247. package/dist/test/mcp-server-bin.test.d.ts.map +1 -0
  248. package/dist/test/mcp-server-bin.test.js +142 -0
  249. package/dist/test/mcp-server-bin.test.js.map +1 -0
  250. package/dist/test/mcpl-awareness-barrier.test.js +141 -0
  251. package/dist/test/mcpl-awareness-barrier.test.js.map +1 -1
  252. package/dist/test/mcpl-child-env.test.js +1 -1
  253. package/dist/test/mcpl-child-env.test.js.map +1 -1
  254. package/dist/test/mcpl-coalesced-content-parity.test.d.ts +2 -0
  255. package/dist/test/mcpl-coalesced-content-parity.test.d.ts.map +1 -0
  256. package/dist/test/mcpl-coalesced-content-parity.test.js +532 -0
  257. package/dist/test/mcpl-coalesced-content-parity.test.js.map +1 -0
  258. package/dist/test/mcpl-coalescing.test.js +78 -16
  259. package/dist/test/mcpl-coalescing.test.js.map +1 -1
  260. package/dist/test/mcpl-config-diagnostics.test.js +6 -3
  261. package/dist/test/mcpl-config-diagnostics.test.js.map +1 -1
  262. package/dist/test/mcpl-gate-roundtrip.test.js.map +1 -1
  263. package/dist/test/mcpl-manifest-changed.test.js +2 -1
  264. package/dist/test/mcpl-manifest-changed.test.js.map +1 -1
  265. package/dist/test/mcpl-reconnect-events.test.js.map +1 -1
  266. package/dist/test/mcpl-reconnect-reregistration.test.js +2 -0
  267. package/dist/test/mcpl-reconnect-reregistration.test.js.map +1 -1
  268. package/dist/test/mcpl-reference-fetcher.test.js +232 -4
  269. package/dist/test/mcpl-reference-fetcher.test.js.map +1 -1
  270. package/dist/test/mcpl-reference-fields.test.js +69 -2
  271. package/dist/test/mcpl-reference-fields.test.js.map +1 -1
  272. package/dist/test/mcpl-rejection-log-lines.test.d.ts +2 -0
  273. package/dist/test/mcpl-rejection-log-lines.test.d.ts.map +1 -0
  274. package/dist/test/mcpl-rejection-log-lines.test.js +349 -0
  275. package/dist/test/mcpl-rejection-log-lines.test.js.map +1 -0
  276. package/dist/test/mcpl-stderr-tail.test.d.ts +2 -0
  277. package/dist/test/mcpl-stderr-tail.test.d.ts.map +1 -0
  278. package/dist/test/mcpl-stderr-tail.test.js +210 -0
  279. package/dist/test/mcpl-stderr-tail.test.js.map +1 -0
  280. package/dist/test/mcpl-tool-lifecycle-e2e.test.js.map +1 -1
  281. package/dist/test/mcpl-tool-lifecycle-emitter.test.js.map +1 -1
  282. package/dist/test/mcpl-tool-lifecycle-script.test.js.map +1 -1
  283. package/dist/test/mcpl-tool-lifecycle.test.js.map +1 -1
  284. package/dist/test/mcpl-transport-close.test.d.ts +2 -0
  285. package/dist/test/mcpl-transport-close.test.d.ts.map +1 -0
  286. package/dist/test/mcpl-transport-close.test.js +373 -0
  287. package/dist/test/mcpl-transport-close.test.js.map +1 -0
  288. package/dist/test/mcpl-transport-spawn.test.d.ts +2 -0
  289. package/dist/test/mcpl-transport-spawn.test.d.ts.map +1 -0
  290. package/dist/test/mcpl-transport-spawn.test.js +58 -0
  291. package/dist/test/mcpl-transport-spawn.test.js.map +1 -0
  292. package/dist/test/mcpl-ws-transport.test.js +104 -0
  293. package/dist/test/mcpl-ws-transport.test.js.map +1 -1
  294. package/dist/test/offline-recovery-branch.test.js +344 -0
  295. package/dist/test/offline-recovery-branch.test.js.map +1 -1
  296. package/dist/test/operator-surgery.test.js +197 -0
  297. package/dist/test/operator-surgery.test.js.map +1 -1
  298. package/dist/test/ops-alert.test.js +2 -1
  299. package/dist/test/ops-alert.test.js.map +1 -1
  300. package/dist/test/overbudget-drain-breaker.test.js +1 -0
  301. package/dist/test/overbudget-drain-breaker.test.js.map +1 -1
  302. package/dist/test/pack-installs-alone.test.d.ts +2 -0
  303. package/dist/test/pack-installs-alone.test.d.ts.map +1 -0
  304. package/dist/test/pack-installs-alone.test.js +284 -0
  305. package/dist/test/pack-installs-alone.test.js.map +1 -0
  306. package/dist/test/physical-window-restart.test.d.ts +6 -4
  307. package/dist/test/physical-window-restart.test.d.ts.map +1 -1
  308. package/dist/test/physical-window-restart.test.js +275 -10
  309. package/dist/test/physical-window-restart.test.js.map +1 -1
  310. package/dist/test/placed-reaction-baseline.test.d.ts +2 -0
  311. package/dist/test/placed-reaction-baseline.test.d.ts.map +1 -0
  312. package/dist/test/placed-reaction-baseline.test.js +312 -0
  313. package/dist/test/placed-reaction-baseline.test.js.map +1 -0
  314. package/dist/test/present-while-acting.test.js +949 -6
  315. package/dist/test/present-while-acting.test.js.map +1 -1
  316. package/dist/test/provider-acceleration-cooldown.test.js +5 -1
  317. package/dist/test/provider-acceleration-cooldown.test.js.map +1 -1
  318. package/dist/test/provider-waits.test.d.ts +2 -0
  319. package/dist/test/provider-waits.test.d.ts.map +1 -0
  320. package/dist/test/provider-waits.test.js +2259 -0
  321. package/dist/test/provider-waits.test.js.map +1 -0
  322. package/dist/test/puppet-tool-call.test.js +2 -0
  323. package/dist/test/puppet-tool-call.test.js.map +1 -1
  324. package/dist/test/reaction-baseline-platform.test.d.ts +2 -0
  325. package/dist/test/reaction-baseline-platform.test.d.ts.map +1 -0
  326. package/dist/test/reaction-baseline-platform.test.js +124 -0
  327. package/dist/test/reaction-baseline-platform.test.js.map +1 -0
  328. package/dist/test/record-journal.test.js.map +1 -1
  329. package/dist/test/refusal-reaction-baseline.test.js +10 -3
  330. package/dist/test/refusal-reaction-baseline.test.js.map +1 -1
  331. package/dist/test/refusal-rewind.test.js +9 -0
  332. package/dist/test/refusal-rewind.test.js.map +1 -1
  333. package/dist/test/refusal-single-call.test.js.map +1 -1
  334. package/dist/test/release-bump.test.d.ts +2 -0
  335. package/dist/test/release-bump.test.d.ts.map +1 -0
  336. package/dist/test/release-bump.test.js +248 -0
  337. package/dist/test/release-bump.test.js.map +1 -0
  338. package/dist/test/release-changelog.test.js.map +1 -1
  339. package/dist/test/release-holds.test.d.ts +2 -0
  340. package/dist/test/release-holds.test.d.ts.map +1 -0
  341. package/dist/test/release-holds.test.js +456 -0
  342. package/dist/test/release-holds.test.js.map +1 -0
  343. package/dist/test/same-round-think-policy.test.js.map +1 -1
  344. package/dist/test/save-recent-image.test.js +138 -2
  345. package/dist/test/save-recent-image.test.js.map +1 -1
  346. package/dist/test/shutdown-errors.test.js.map +1 -1
  347. package/dist/test/silent-heartbeat-rows.test.js.map +1 -1
  348. package/dist/test/stop-with-host-operations.test.d.ts +20 -0
  349. package/dist/test/stop-with-host-operations.test.d.ts.map +1 -0
  350. package/dist/test/stop-with-host-operations.test.js +1174 -0
  351. package/dist/test/stop-with-host-operations.test.js.map +1 -0
  352. package/dist/test/stop-with-work-in-flight.test.js +162 -50
  353. package/dist/test/stop-with-work-in-flight.test.js.map +1 -1
  354. package/dist/test/surgery-marks-receipt.test.d.ts +2 -0
  355. package/dist/test/surgery-marks-receipt.test.d.ts.map +1 -0
  356. package/dist/test/surgery-marks-receipt.test.js +540 -0
  357. package/dist/test/surgery-marks-receipt.test.js.map +1 -0
  358. package/dist/test/tool-batch-hook.test.js.map +1 -1
  359. package/dist/test/tool-result-guard.test.js +352 -16
  360. package/dist/test/tool-result-guard.test.js.map +1 -1
  361. package/dist/test/tool-result-spill.test.js.map +1 -1
  362. package/dist/test/tool-wrapper-prose-guard-integration.test.js.map +1 -1
  363. package/dist/test/trunk-channel-routing.test.js +330 -7
  364. package/dist/test/trunk-channel-routing.test.js.map +1 -1
  365. package/dist/test/tune-out-e2e.test.js.map +1 -1
  366. package/dist/test/unconvertible-tool-result.test.js.map +1 -1
  367. package/dist/test/unsent-compiles.test.d.ts +2 -0
  368. package/dist/test/unsent-compiles.test.d.ts.map +1 -0
  369. package/dist/test/unsent-compiles.test.js +139 -0
  370. package/dist/test/unsent-compiles.test.js.map +1 -0
  371. package/dist/test/workspace-branch-continuation.test.js.map +1 -1
  372. package/dist/test/workspace-materialize-freshness.test.js.map +1 -1
  373. package/dist/test/workspace-read-text.test.js.map +1 -1
  374. package/dist/test/workspace-three-way.test.js +1022 -7
  375. package/dist/test/workspace-three-way.test.js.map +1 -1
  376. package/dist/test/workspace-watcher.test.js.map +1 -1
  377. package/dist/test/xml-round-persist.test.js.map +1 -1
  378. package/dist/tsconfig.tsbuildinfo +1 -1
  379. package/package.json +8 -6
  380. package/src/agent.ts +415 -67
  381. package/src/api/mcp-server-core.ts +681 -0
  382. package/src/api/mcp-server.ts +16 -685
  383. package/src/api/server.ts +87 -26
  384. package/src/api/types.ts +9 -1
  385. package/src/framework.ts +3389 -782
  386. package/src/index.ts +9 -4
  387. package/src/mcpl/channel-registry.ts +126 -31
  388. package/src/mcpl/feature-set-manager.ts +4 -3
  389. package/src/mcpl/index.ts +2 -0
  390. package/src/mcpl/log-value.ts +116 -0
  391. package/src/mcpl/prose-stream-router.ts +6 -6
  392. package/src/mcpl/push-coalescer.ts +76 -12
  393. package/src/mcpl/push-handler.ts +95 -23
  394. package/src/mcpl/reference-fetcher.ts +18 -8
  395. package/src/mcpl/references.ts +57 -13
  396. package/src/mcpl/refusal-lines.ts +59 -0
  397. package/src/mcpl/server-connection.ts +125 -15
  398. package/src/mcpl/tool-classes.ts +3 -2
  399. package/src/mcpl/transport.ts +105 -14
  400. package/src/mcpl/types.ts +5 -1
  401. package/src/module-registry.ts +17 -9
  402. package/src/modules/discord/index.ts +4 -2
  403. package/src/modules/workspace/disk-agreement.ts +74 -18
  404. package/src/modules/workspace/index.ts +85 -15
  405. package/src/modules/workspace/observe.ts +295 -43
  406. package/src/modules/workspace/reconcile.ts +90 -12
  407. package/src/modules/workspace/types.ts +26 -1
  408. package/src/operator-log.ts +30 -0
  409. package/src/provider-waits.ts +523 -0
  410. package/src/recovery/offline-branch.ts +32 -28
  411. package/src/refusal-reactions.ts +14 -12
  412. package/src/stored-removal.ts +126 -0
  413. package/src/tool-result-guard.ts +72 -24
  414. package/src/types/agent.ts +42 -6
  415. package/src/types/events.ts +12 -0
  416. package/src/types/framework.ts +10 -0
  417. package/src/types/module.ts +20 -8
  418. package/src/types/trace.ts +76 -14
@@ -1,687 +1,18 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
- * MCP Server for Claude Code integration
3
- *
4
- * Exposes agent framework capabilities as MCP tools that can be called
5
- * from Claude Code or other MCP clients.
6
- *
7
- * Communicates with the WebSocket API server to perform operations.
3
+ * The `agent-framework-mcp` command: an MCP server over stdio for Claude Code
4
+ * and other MCP clients, as a client of the framework's WebSocket API at
5
+ * AGENT_FRAMEWORK_WS_URL (default ws://localhost:8765/ws). It always starts:
6
+ * the server itself is McpServer, in ./mcp-server-core.ts, which the package
7
+ * root exports, so importing the package never runs this file. The package's
8
+ * `exports` names only its root, so nothing outside it can import this path
9
+ * by the package's name.
8
10
  */
9
-
10
- import WebSocket from 'ws';
11
- import { createInterface } from 'node:readline';
12
- import type { ApiRequest, ApiResponse, ApiEvent } from './types.js';
13
-
14
- // ============================================================================
15
- // MCP Protocol Types
16
- // ============================================================================
17
-
18
- interface JsonRpcRequest {
19
- jsonrpc: '2.0';
20
- id: string | number;
21
- method: string;
22
- params?: unknown;
23
- }
24
-
25
- interface JsonRpcResponse {
26
- jsonrpc: '2.0';
27
- id: string | number | null;
28
- result?: unknown;
29
- error?: {
30
- code: number;
31
- message: string;
32
- data?: unknown;
33
- };
34
- }
35
-
36
- interface JsonRpcNotification {
37
- jsonrpc: '2.0';
38
- method: string;
39
- params?: unknown;
40
- }
41
-
42
- interface McpTool {
43
- name: string;
44
- description: string;
45
- inputSchema: {
46
- type: 'object';
47
- properties: Record<string, unknown>;
48
- required?: string[];
49
- };
50
- }
51
-
52
- interface McpToolCall {
53
- name: string;
54
- arguments: Record<string, unknown>;
55
- }
56
-
57
- // ============================================================================
58
- // MCP Server Implementation
59
- // ============================================================================
60
-
61
- export class McpServer {
62
- private ws: WebSocket | null = null;
63
- private wsUrl: string;
64
- private requestId = 0;
65
- private pendingRequests = new Map<
66
- string,
67
- { resolve: (value: unknown) => void; reject: (error: Error) => void }
68
- >();
69
- private connected = false;
70
- private reconnecting = false;
71
- private reconnectInterval = 2000; // Retry every 2s
72
- private closing = false;
73
-
74
- constructor(wsUrl: string = 'ws://localhost:8765/ws') {
75
- this.wsUrl = wsUrl;
76
- }
77
-
78
- /**
79
- * Start the MCP server (stdio mode).
80
- */
81
- async start(): Promise<void> {
82
- // Connect to WebSocket API
83
- await this.connectWs();
84
-
85
- // Set up stdio interface
86
- const rl = createInterface({
87
- input: process.stdin,
88
- output: process.stdout,
89
- terminal: false,
90
- });
91
-
92
- rl.on('line', (line) => {
93
- this.handleInput(line);
94
- });
95
-
96
- rl.on('close', () => {
97
- this.close();
98
- process.exit(0);
99
- });
100
-
101
- // Handle SIGINT gracefully
102
- process.on('SIGINT', () => {
103
- this.close();
104
- process.exit(0);
105
- });
106
- }
107
-
108
- private async connectWs(): Promise<void> {
109
- return new Promise((resolve, reject) => {
110
- this.ws = new WebSocket(this.wsUrl);
111
-
112
- this.ws.on('open', () => {
113
- this.connected = true;
114
- this.reconnecting = false;
115
- resolve();
116
- });
117
-
118
- this.ws.on('message', (data) => {
119
- this.handleWsMessage(data.toString());
120
- });
121
-
122
- this.ws.on('close', () => {
123
- this.connected = false;
124
- if (!this.closing) {
125
- this.scheduleReconnect();
126
- }
127
- });
128
-
129
- this.ws.on('error', (error) => {
130
- if (!this.connected) {
131
- // Connection failed - reject so we can retry
132
- reject(error);
133
- } else {
134
- // Connected but got an error - just log it
135
- this.sendNotification('notifications/message', {
136
- level: 'error',
137
- logger: 'agent-framework',
138
- data: `WebSocket error: ${error.message}`,
139
- });
140
- }
141
- });
142
- });
143
- }
144
-
145
- private scheduleReconnect(): void {
146
- if (this.reconnecting || this.closing) return;
147
- this.reconnecting = true;
148
-
149
- setTimeout(() => {
150
- if (this.closing) return;
151
- this.connectWs().catch(() => {
152
- this.reconnecting = false;
153
- this.scheduleReconnect();
154
- });
155
- }, this.reconnectInterval);
156
- }
157
-
158
- private handleWsMessage(data: string): void {
159
- try {
160
- const message = JSON.parse(data) as ApiResponse | ApiEvent;
161
-
162
- if (message.type === 'response' && 'id' in message && message.id) {
163
- // Handle response to our request
164
- const pending = this.pendingRequests.get(message.id);
165
- if (pending) {
166
- this.pendingRequests.delete(message.id);
167
- if (message.success) {
168
- pending.resolve(message.data);
169
- } else {
170
- pending.reject(new Error(message.error ?? 'Unknown error'));
171
- }
172
- }
173
- } else if (message.type === 'event') {
174
- // Forward events as MCP notifications
175
- this.sendNotification('notifications/message', {
176
- level: 'info',
177
- logger: 'agent-framework',
178
- data: `Event: ${message.event} - ${JSON.stringify(message.data)}`,
179
- });
180
- }
181
- } catch {
182
- // Ignore parse errors
183
- }
184
- }
185
-
186
- private handleInput(line: string): void {
187
- try {
188
- const message = JSON.parse(line);
189
-
190
- // Check if this is a notification (no id) or a request (has id)
191
- if (!('id' in message) || message.id === undefined) {
192
- // This is a notification - handle silently without response
193
- // Common notifications: notifications/initialized, notifications/cancelled
194
- return;
195
- }
196
-
197
- // This is a request - process and respond
198
- this.handleRequest(message as JsonRpcRequest);
199
- } catch {
200
- this.sendError(null, -32700, 'Parse error');
201
- }
202
- }
203
-
204
- private async handleRequest(request: JsonRpcRequest): Promise<void> {
205
- try {
206
- switch (request.method) {
207
- case 'initialize':
208
- this.sendResult(request.id, {
209
- protocolVersion: '2024-11-05',
210
- capabilities: {
211
- tools: {},
212
- },
213
- serverInfo: {
214
- name: 'agent-framework',
215
- version: '0.1.0',
216
- },
217
- });
218
- break;
219
-
220
- case 'initialized':
221
- // Client acknowledgment, no response needed
222
- break;
223
-
224
- case 'tools/list':
225
- this.sendResult(request.id, { tools: this.getTools() });
226
- break;
227
-
228
- case 'tools/call':
229
- await this.handleToolCall(request);
230
- break;
231
-
232
- case 'ping':
233
- this.sendResult(request.id, {});
234
- break;
235
-
236
- default:
237
- this.sendError(request.id, -32601, `Method not found: ${request.method}`);
238
- }
239
- } catch (error) {
240
- this.sendError(
241
- request.id,
242
- -32603,
243
- error instanceof Error ? error.message : String(error)
244
- );
245
- }
246
- }
247
-
248
- private getTools(): McpTool[] {
249
- return [
250
- {
251
- name: 'agent_send_message',
252
- description:
253
- 'Send a message to the agent framework. This will add the message to the conversation and optionally trigger inference.',
254
- inputSchema: {
255
- type: 'object',
256
- properties: {
257
- participant: {
258
- type: 'string',
259
- description: 'Name of the participant sending the message (e.g., "user")',
260
- },
261
- content: {
262
- type: 'string',
263
- description: 'The message content',
264
- },
265
- triggerInference: {
266
- type: 'boolean',
267
- description: 'Whether to trigger agent inference after sending (default: true)',
268
- },
269
- targetAgents: {
270
- type: 'array',
271
- items: { type: 'string' },
272
- description: 'Specific agents to trigger (optional, defaults to all)',
273
- },
274
- },
275
- required: ['participant', 'content'],
276
- },
277
- },
278
- {
279
- name: 'agent_list_messages',
280
- description: 'List recent messages in the conversation',
281
- inputSchema: {
282
- type: 'object',
283
- properties: {
284
- limit: {
285
- type: 'number',
286
- description: 'Maximum number of messages to return (default: 50)',
287
- },
288
- offset: {
289
- type: 'number',
290
- description: 'Offset from the most recent message (default: 0)',
291
- },
292
- },
293
- },
294
- },
295
- {
296
- name: 'agent_request_inference',
297
- description: 'Request the agent to run inference and generate a response',
298
- inputSchema: {
299
- type: 'object',
300
- properties: {
301
- agentName: {
302
- type: 'string',
303
- description: 'Specific agent to run (optional, defaults to all)',
304
- },
305
- reason: {
306
- type: 'string',
307
- description: 'Reason for the inference request',
308
- },
309
- },
310
- },
311
- },
312
- {
313
- name: 'branch_list',
314
- description: 'List all branches in the agent framework',
315
- inputSchema: {
316
- type: 'object',
317
- properties: {},
318
- },
319
- },
320
- {
321
- name: 'branch_create',
322
- description: 'Create a new branch from the current state',
323
- inputSchema: {
324
- type: 'object',
325
- properties: {
326
- name: {
327
- type: 'string',
328
- description: 'Name for the new branch',
329
- },
330
- switchTo: {
331
- type: 'boolean',
332
- description: 'Whether to switch to the new branch after creation (default: false)',
333
- },
334
- },
335
- required: ['name'],
336
- },
337
- },
338
- {
339
- name: 'branch_switch',
340
- description: 'Switch to a different branch',
341
- inputSchema: {
342
- type: 'object',
343
- properties: {
344
- name: {
345
- type: 'string',
346
- description: 'Name of the branch to switch to',
347
- },
348
- },
349
- required: ['name'],
350
- },
351
- },
352
- {
353
- name: 'branch_current',
354
- description: 'Get the name of the current branch',
355
- inputSchema: {
356
- type: 'object',
357
- properties: {},
358
- },
359
- },
360
- {
361
- name: 'branch_delete',
362
- description: 'Delete a branch (cannot delete current or main branch)',
363
- inputSchema: {
364
- type: 'object',
365
- properties: {
366
- name: {
367
- type: 'string',
368
- description: 'Name of the branch to delete',
369
- },
370
- },
371
- required: ['name'],
372
- },
373
- },
374
- {
375
- name: 'agent_list',
376
- description: 'List all agents in the framework',
377
- inputSchema: {
378
- type: 'object',
379
- properties: {},
380
- },
381
- },
382
- {
383
- name: 'agent_context',
384
- description: "Get an agent's current context (compiled messages)",
385
- inputSchema: {
386
- type: 'object',
387
- properties: {
388
- agentName: {
389
- type: 'string',
390
- description: 'Name of the agent',
391
- },
392
- maxTokens: {
393
- type: 'number',
394
- description: 'Maximum tokens to include (optional)',
395
- },
396
- },
397
- required: ['agentName'],
398
- },
399
- },
400
- {
401
- name: 'module_list',
402
- description: 'List all modules registered with the framework',
403
- inputSchema: {
404
- type: 'object',
405
- properties: {},
406
- },
407
- },
408
- {
409
- name: 'module_state',
410
- description: "Get a module's current state",
411
- inputSchema: {
412
- type: 'object',
413
- properties: {
414
- moduleName: {
415
- type: 'string',
416
- description: 'Name of the module',
417
- },
418
- },
419
- required: ['moduleName'],
420
- },
421
- },
422
- {
423
- name: 'store_states',
424
- description: 'List all states in the store',
425
- inputSchema: {
426
- type: 'object',
427
- properties: {
428
- namespace: {
429
- type: 'string',
430
- description: "Filter by namespace prefix (e.g., 'agents/', 'modules/')",
431
- },
432
- limit: {
433
- type: 'number',
434
- description: 'Maximum number of states to return (default: 50)',
435
- },
436
- },
437
- },
438
- },
439
- {
440
- name: 'store_search',
441
- description: 'Search through store states by namespace and/or content pattern',
442
- inputSchema: {
443
- type: 'object',
444
- properties: {
445
- namespace: {
446
- type: 'string',
447
- description: 'Filter by namespace prefix',
448
- },
449
- contentPattern: {
450
- type: 'string',
451
- description: 'Regex pattern to match against state content (JSON stringified)',
452
- },
453
- limit: {
454
- type: 'number',
455
- description: 'Maximum number of results (default: 20)',
456
- },
457
- offset: {
458
- type: 'number',
459
- description: 'Skip first N results for pagination (default: 0)',
460
- },
461
- previewLength: {
462
- type: 'number',
463
- description: 'Preview length in characters (default: 300)',
464
- },
465
- },
466
- },
467
- },
468
- {
469
- name: 'store_inspect',
470
- description: 'Inspect a specific state in the store',
471
- inputSchema: {
472
- type: 'object',
473
- properties: {
474
- stateId: {
475
- type: 'string',
476
- description: 'ID of the state to inspect',
477
- },
478
- },
479
- required: ['stateId'],
480
- },
481
- },
482
- // Inference logging tools
483
- {
484
- name: 'inference_tail',
485
- description: 'Get the most recent inference log entries. Shows raw LLM requests and responses for debugging.',
486
- inputSchema: {
487
- type: 'object',
488
- properties: {
489
- count: {
490
- type: 'number',
491
- description: 'Number of recent entries to return (default: 10)',
492
- },
493
- agentName: {
494
- type: 'string',
495
- description: 'Filter by agent name (optional)',
496
- },
497
- },
498
- },
499
- },
500
- {
501
- name: 'inference_inspect',
502
- description: 'Inspect a specific inference log entry by sequence number. Returns full raw request and response.',
503
- inputSchema: {
504
- type: 'object',
505
- properties: {
506
- sequence: {
507
- type: 'number',
508
- description: 'Sequence number of the log entry to inspect',
509
- },
510
- },
511
- required: ['sequence'],
512
- },
513
- },
514
- {
515
- name: 'inference_search',
516
- description: 'Search through inference logs by agent, pattern, or error status. Useful for debugging specific issues.',
517
- inputSchema: {
518
- type: 'object',
519
- properties: {
520
- agentName: {
521
- type: 'string',
522
- description: 'Filter by agent name',
523
- },
524
- pattern: {
525
- type: 'string',
526
- description: 'Regex pattern to search in log content',
527
- },
528
- errorsOnly: {
529
- type: 'boolean',
530
- description: 'Only show failed inferences',
531
- },
532
- limit: {
533
- type: 'number',
534
- description: 'Maximum number of results (default: 20)',
535
- },
536
- offset: {
537
- type: 'number',
538
- description: 'Skip first N results for pagination (default: 0)',
539
- },
540
- },
541
- },
542
- },
543
- ];
544
- }
545
-
546
- private async handleToolCall(request: JsonRpcRequest): Promise<void> {
547
- const params = request.params as { name: string; arguments: Record<string, unknown> };
548
- const { name, arguments: args } = params;
549
-
550
- // Map MCP tool names to API commands
551
- const toolToCommand: Record<string, string> = {
552
- agent_send_message: 'message.send',
553
- agent_list_messages: 'message.list',
554
- agent_request_inference: 'inference.request',
555
- branch_list: 'branch.list',
556
- branch_create: 'branch.create',
557
- branch_switch: 'branch.switch',
558
- branch_current: 'branch.current',
559
- branch_delete: 'branch.delete',
560
- agent_list: 'agent.list',
561
- agent_context: 'agent.context',
562
- module_list: 'module.list',
563
- module_state: 'module.state',
564
- store_states: 'store.states',
565
- store_search: 'store.search',
566
- store_inspect: 'store.inspect',
567
- inference_tail: 'inference.tail',
568
- inference_inspect: 'inference.inspect',
569
- inference_search: 'inference.search',
570
- };
571
-
572
- const command = toolToCommand[name];
573
- if (!command) {
574
- this.sendError(request.id, -32602, `Unknown tool: ${name}`);
575
- return;
576
- }
577
-
578
- try {
579
- const result = await this.sendApiRequest(command, args);
580
- this.sendResult(request.id, {
581
- content: [
582
- {
583
- type: 'text',
584
- text: JSON.stringify(result, null, 2),
585
- },
586
- ],
587
- });
588
- } catch (error) {
589
- this.sendResult(request.id, {
590
- content: [
591
- {
592
- type: 'text',
593
- text: `Error: ${error instanceof Error ? error.message : String(error)}`,
594
- },
595
- ],
596
- isError: true,
597
- });
598
- }
599
- }
600
-
601
- private sendApiRequest(
602
- command: string,
603
- params: Record<string, unknown>
604
- ): Promise<unknown> {
605
- return new Promise((resolve, reject) => {
606
- if (!this.ws || !this.connected) {
607
- reject(new Error('Not connected to API server'));
608
- return;
609
- }
610
-
611
- const id = `mcp-${++this.requestId}`;
612
- this.pendingRequests.set(id, { resolve, reject });
613
-
614
- const request: ApiRequest = {
615
- type: 'request',
616
- id,
617
- command,
618
- params,
619
- };
620
-
621
- this.ws.send(JSON.stringify(request));
622
-
623
- // Timeout after 30 seconds
624
- setTimeout(() => {
625
- if (this.pendingRequests.has(id)) {
626
- this.pendingRequests.delete(id);
627
- reject(new Error('Request timeout'));
628
- }
629
- }, 30000);
630
- });
631
- }
632
-
633
- private sendResult(id: string | number, result: unknown): void {
634
- const response: JsonRpcResponse = {
635
- jsonrpc: '2.0',
636
- id,
637
- result,
638
- };
639
- this.send(response);
640
- }
641
-
642
- private sendError(id: string | number | null, code: number, message: string): void {
643
- const response: JsonRpcResponse = {
644
- jsonrpc: '2.0',
645
- id,
646
- error: { code, message },
647
- };
648
- this.send(response);
649
- }
650
-
651
- private sendNotification(method: string, params: unknown): void {
652
- const notification: JsonRpcNotification = {
653
- jsonrpc: '2.0',
654
- method,
655
- params,
656
- };
657
- this.send(notification);
658
- }
659
-
660
- private send(message: JsonRpcResponse | JsonRpcNotification): void {
661
- process.stdout.write(JSON.stringify(message) + '\n');
662
- }
663
-
664
- close(): void {
665
- this.closing = true;
666
- if (this.ws) {
667
- this.ws.close();
668
- this.ws = null;
669
- }
670
- this.connected = false;
671
- }
672
- }
673
-
674
- // ============================================================================
675
- // CLI Entry Point
676
- // ============================================================================
677
-
678
- // Run if executed directly
679
- const isMain = process.argv[1]?.endsWith('mcp-server.js');
680
- if (isMain) {
681
- const wsUrl = process.env.AGENT_FRAMEWORK_WS_URL ?? 'ws://localhost:8765/ws';
682
- const server = new McpServer(wsUrl);
683
- server.start().catch((error) => {
684
- console.error('Failed to start MCP server:', error);
685
- process.exit(1);
686
- });
687
- }
11
+ import { McpServer } from './mcp-server-core.js';
12
+
13
+ const wsUrl = process.env.AGENT_FRAMEWORK_WS_URL ?? 'ws://localhost:8765/ws';
14
+ const server = new McpServer(wsUrl);
15
+ server.start().catch((error) => {
16
+ console.error('Failed to start MCP server:', error);
17
+ process.exit(1);
18
+ });