@spinabot/brigade 0.1.1 → 1.0.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 (1931) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +746 -93
  3. package/brigade.mjs +150 -73
  4. package/dist/agents/a2a-policy-canonicalize.d.ts +60 -0
  5. package/dist/agents/a2a-policy-canonicalize.d.ts.map +1 -0
  6. package/dist/agents/a2a-policy-canonicalize.js +103 -0
  7. package/dist/agents/a2a-policy-canonicalize.js.map +1 -0
  8. package/dist/agents/agent-event-bus.d.ts +221 -0
  9. package/dist/agents/agent-event-bus.d.ts.map +1 -0
  10. package/dist/agents/agent-event-bus.js +88 -0
  11. package/dist/agents/agent-event-bus.js.map +1 -0
  12. package/dist/agents/agent-events.d.ts +84 -0
  13. package/dist/agents/agent-events.d.ts.map +1 -0
  14. package/dist/agents/agent-events.js +309 -0
  15. package/dist/agents/agent-events.js.map +1 -0
  16. package/dist/agents/agent-events.types.d.ts +139 -0
  17. package/dist/agents/agent-events.types.d.ts.map +1 -0
  18. package/dist/agents/agent-events.types.js +27 -0
  19. package/dist/agents/agent-events.types.js.map +1 -0
  20. package/dist/agents/agent-loop.d.ts +145 -0
  21. package/dist/agents/agent-loop.d.ts.map +1 -0
  22. package/dist/agents/agent-loop.js +1938 -0
  23. package/dist/agents/agent-loop.js.map +1 -0
  24. package/dist/agents/agent-scope.d.ts +28 -0
  25. package/dist/agents/agent-scope.d.ts.map +1 -0
  26. package/dist/agents/agent-scope.js +39 -0
  27. package/dist/agents/agent-scope.js.map +1 -0
  28. package/dist/agents/approval-bridge.d.ts +139 -0
  29. package/dist/agents/approval-bridge.d.ts.map +1 -0
  30. package/dist/agents/approval-bridge.js +178 -0
  31. package/dist/agents/approval-bridge.js.map +1 -0
  32. package/dist/agents/carrow.d.ts +49 -0
  33. package/dist/agents/carrow.d.ts.map +1 -0
  34. package/dist/agents/carrow.js +57 -0
  35. package/dist/agents/carrow.js.map +1 -0
  36. package/dist/agents/channels/abort-triggers.d.ts +17 -0
  37. package/dist/agents/channels/abort-triggers.d.ts.map +1 -0
  38. package/dist/agents/channels/abort-triggers.js +52 -0
  39. package/dist/agents/channels/abort-triggers.js.map +1 -0
  40. package/dist/agents/channels/access-control/index.d.ts +5 -0
  41. package/dist/agents/channels/access-control/index.d.ts.map +1 -0
  42. package/dist/agents/channels/access-control/index.js +4 -0
  43. package/dist/agents/channels/access-control/index.js.map +1 -0
  44. package/dist/agents/channels/access-control/policy.d.ts +69 -0
  45. package/dist/agents/channels/access-control/policy.d.ts.map +1 -0
  46. package/dist/agents/channels/access-control/policy.js +123 -0
  47. package/dist/agents/channels/access-control/policy.js.map +1 -0
  48. package/dist/agents/channels/access-control/store.d.ts +86 -0
  49. package/dist/agents/channels/access-control/store.d.ts.map +1 -0
  50. package/dist/agents/channels/access-control/store.js +482 -0
  51. package/dist/agents/channels/access-control/store.js.map +1 -0
  52. package/dist/agents/channels/access-control/types.d.ts +52 -0
  53. package/dist/agents/channels/access-control/types.d.ts.map +1 -0
  54. package/dist/agents/channels/access-control/types.js +20 -0
  55. package/dist/agents/channels/access-control/types.js.map +1 -0
  56. package/dist/agents/channels/active-manager.d.ts +31 -0
  57. package/dist/agents/channels/active-manager.d.ts.map +1 -0
  58. package/dist/agents/channels/active-manager.js +41 -0
  59. package/dist/agents/channels/active-manager.js.map +1 -0
  60. package/dist/agents/channels/agent-switch-command.d.ts +53 -0
  61. package/dist/agents/channels/agent-switch-command.d.ts.map +1 -0
  62. package/dist/agents/channels/agent-switch-command.js +349 -0
  63. package/dist/agents/channels/agent-switch-command.js.map +1 -0
  64. package/dist/agents/channels/approval-router.d.ts +158 -0
  65. package/dist/agents/channels/approval-router.d.ts.map +1 -0
  66. package/dist/agents/channels/approval-router.js +446 -0
  67. package/dist/agents/channels/approval-router.js.map +1 -0
  68. package/dist/agents/channels/channel-entry-contract.d.ts +70 -0
  69. package/dist/agents/channels/channel-entry-contract.d.ts.map +1 -0
  70. package/dist/agents/channels/channel-entry-contract.js +48 -0
  71. package/dist/agents/channels/channel-entry-contract.js.map +1 -0
  72. package/dist/agents/channels/channel-plugin-manager.d.ts +86 -0
  73. package/dist/agents/channels/channel-plugin-manager.d.ts.map +1 -0
  74. package/dist/agents/channels/channel-plugin-manager.js +345 -0
  75. package/dist/agents/channels/channel-plugin-manager.js.map +1 -0
  76. package/dist/agents/channels/chat-type.d.ts +27 -0
  77. package/dist/agents/channels/chat-type.d.ts.map +1 -0
  78. package/dist/agents/channels/chat-type.js +33 -0
  79. package/dist/agents/channels/chat-type.js.map +1 -0
  80. package/dist/agents/channels/dedupe.d.ts +44 -0
  81. package/dist/agents/channels/dedupe.d.ts.map +1 -0
  82. package/dist/agents/channels/dedupe.js +80 -0
  83. package/dist/agents/channels/dedupe.js.map +1 -0
  84. package/dist/agents/channels/inbound-pipeline.d.ts +90 -0
  85. package/dist/agents/channels/inbound-pipeline.d.ts.map +1 -0
  86. package/dist/agents/channels/inbound-pipeline.js +721 -0
  87. package/dist/agents/channels/inbound-pipeline.js.map +1 -0
  88. package/dist/agents/channels/last-channel.d.ts +56 -0
  89. package/dist/agents/channels/last-channel.d.ts.map +1 -0
  90. package/dist/agents/channels/last-channel.js +65 -0
  91. package/dist/agents/channels/last-channel.js.map +1 -0
  92. package/dist/agents/channels/manager.d.ts +76 -0
  93. package/dist/agents/channels/manager.d.ts.map +1 -0
  94. package/dist/agents/channels/manager.js +132 -0
  95. package/dist/agents/channels/manager.js.map +1 -0
  96. package/dist/agents/channels/media-capture.d.ts +23 -0
  97. package/dist/agents/channels/media-capture.d.ts.map +1 -0
  98. package/dist/agents/channels/media-capture.js +40 -0
  99. package/dist/agents/channels/media-capture.js.map +1 -0
  100. package/dist/agents/channels/plugin-channel-manager-facade.d.ts +18 -0
  101. package/dist/agents/channels/plugin-channel-manager-facade.d.ts.map +1 -0
  102. package/dist/agents/channels/plugin-channel-manager-facade.js +52 -0
  103. package/dist/agents/channels/plugin-channel-manager-facade.js.map +1 -0
  104. package/dist/agents/channels/reply-sanitizer.d.ts +38 -0
  105. package/dist/agents/channels/reply-sanitizer.d.ts.map +1 -0
  106. package/dist/agents/channels/reply-sanitizer.js +94 -0
  107. package/dist/agents/channels/reply-sanitizer.js.map +1 -0
  108. package/dist/agents/channels/retryable-inbound.d.ts +31 -0
  109. package/dist/agents/channels/retryable-inbound.d.ts.map +1 -0
  110. package/dist/agents/channels/retryable-inbound.js +37 -0
  111. package/dist/agents/channels/retryable-inbound.js.map +1 -0
  112. package/dist/agents/channels/types.adapters.d.ts +399 -0
  113. package/dist/agents/channels/types.adapters.d.ts.map +1 -0
  114. package/dist/agents/channels/types.adapters.js +33 -0
  115. package/dist/agents/channels/types.adapters.js.map +1 -0
  116. package/dist/agents/channels/types.core.d.ts +134 -0
  117. package/dist/agents/channels/types.core.d.ts.map +1 -0
  118. package/dist/agents/channels/types.core.js +32 -0
  119. package/dist/agents/channels/types.core.js.map +1 -0
  120. package/dist/agents/channels/types.plugin.d.ts +78 -0
  121. package/dist/agents/channels/types.plugin.d.ts.map +1 -0
  122. package/dist/agents/channels/types.plugin.js +30 -0
  123. package/dist/agents/channels/types.plugin.js.map +1 -0
  124. package/dist/agents/channels/whatsapp/account-config.d.ts +50 -0
  125. package/dist/agents/channels/whatsapp/account-config.d.ts.map +1 -0
  126. package/dist/agents/channels/whatsapp/account-config.js +105 -0
  127. package/dist/agents/channels/whatsapp/account-config.js.map +1 -0
  128. package/dist/agents/channels/whatsapp/adapter.d.ts +22 -0
  129. package/dist/agents/channels/whatsapp/adapter.d.ts.map +1 -0
  130. package/dist/agents/channels/whatsapp/adapter.js +270 -0
  131. package/dist/agents/channels/whatsapp/adapter.js.map +1 -0
  132. package/dist/agents/channels/whatsapp/chunk.d.ts +26 -0
  133. package/dist/agents/channels/whatsapp/chunk.d.ts.map +1 -0
  134. package/dist/agents/channels/whatsapp/chunk.js +123 -0
  135. package/dist/agents/channels/whatsapp/chunk.js.map +1 -0
  136. package/dist/agents/channels/whatsapp/connection.d.ts +249 -0
  137. package/dist/agents/channels/whatsapp/connection.d.ts.map +1 -0
  138. package/dist/agents/channels/whatsapp/connection.js +1628 -0
  139. package/dist/agents/channels/whatsapp/connection.js.map +1 -0
  140. package/dist/agents/channels/whatsapp/convex-auth-state.d.ts +34 -0
  141. package/dist/agents/channels/whatsapp/convex-auth-state.d.ts.map +1 -0
  142. package/dist/agents/channels/whatsapp/convex-auth-state.js +168 -0
  143. package/dist/agents/channels/whatsapp/convex-auth-state.js.map +1 -0
  144. package/dist/agents/channels/whatsapp/format.d.ts +15 -0
  145. package/dist/agents/channels/whatsapp/format.d.ts.map +1 -0
  146. package/dist/agents/channels/whatsapp/format.js +66 -0
  147. package/dist/agents/channels/whatsapp/format.js.map +1 -0
  148. package/dist/agents/channels/whatsapp/inbound-extras.d.ts +30 -0
  149. package/dist/agents/channels/whatsapp/inbound-extras.d.ts.map +1 -0
  150. package/dist/agents/channels/whatsapp/inbound-extras.js +146 -0
  151. package/dist/agents/channels/whatsapp/inbound-extras.js.map +1 -0
  152. package/dist/agents/channels/whatsapp/index.d.ts +7 -0
  153. package/dist/agents/channels/whatsapp/index.d.ts.map +1 -0
  154. package/dist/agents/channels/whatsapp/index.js +7 -0
  155. package/dist/agents/channels/whatsapp/index.js.map +1 -0
  156. package/dist/agents/channels/whatsapp/media.d.ts +47 -0
  157. package/dist/agents/channels/whatsapp/media.d.ts.map +1 -0
  158. package/dist/agents/channels/whatsapp/media.js +192 -0
  159. package/dist/agents/channels/whatsapp/media.js.map +1 -0
  160. package/dist/agents/channels/whatsapp/module.d.ts +10 -0
  161. package/dist/agents/channels/whatsapp/module.d.ts.map +1 -0
  162. package/dist/agents/channels/whatsapp/module.js +17 -0
  163. package/dist/agents/channels/whatsapp/module.js.map +1 -0
  164. package/dist/agents/channels/whatsapp/plugin.d.ts +60 -0
  165. package/dist/agents/channels/whatsapp/plugin.d.ts.map +1 -0
  166. package/dist/agents/channels/whatsapp/plugin.js +238 -0
  167. package/dist/agents/channels/whatsapp/plugin.js.map +1 -0
  168. package/dist/agents/cmd-ism-guard.d.ts +47 -0
  169. package/dist/agents/cmd-ism-guard.d.ts.map +1 -0
  170. package/dist/agents/cmd-ism-guard.js +100 -0
  171. package/dist/agents/cmd-ism-guard.js.map +1 -0
  172. package/dist/agents/config-write-guard.d.ts +25 -0
  173. package/dist/agents/config-write-guard.d.ts.map +1 -0
  174. package/dist/agents/config-write-guard.js +95 -0
  175. package/dist/agents/config-write-guard.js.map +1 -0
  176. package/dist/agents/content-quality-retry.d.ts +66 -0
  177. package/dist/agents/content-quality-retry.d.ts.map +1 -0
  178. package/dist/agents/content-quality-retry.js +140 -0
  179. package/dist/agents/content-quality-retry.js.map +1 -0
  180. package/dist/agents/error-classifier.d.ts +89 -0
  181. package/dist/agents/error-classifier.d.ts.map +1 -0
  182. package/dist/agents/error-classifier.js +630 -0
  183. package/dist/agents/error-classifier.js.map +1 -0
  184. package/dist/agents/exec-gate.d.ts +113 -0
  185. package/dist/agents/exec-gate.d.ts.map +1 -0
  186. package/dist/agents/exec-gate.js +335 -0
  187. package/dist/agents/exec-gate.js.map +1 -0
  188. package/dist/agents/exec-session-allow.d.ts +30 -0
  189. package/dist/agents/exec-session-allow.d.ts.map +1 -0
  190. package/dist/agents/exec-session-allow.js +50 -0
  191. package/dist/agents/exec-session-allow.js.map +1 -0
  192. package/dist/agents/extensions/active-registry.d.ts +4 -0
  193. package/dist/agents/extensions/active-registry.d.ts.map +1 -0
  194. package/dist/agents/extensions/active-registry.js +18 -0
  195. package/dist/agents/extensions/active-registry.js.map +1 -0
  196. package/dist/agents/extensions/discovery.d.ts +84 -0
  197. package/dist/agents/extensions/discovery.d.ts.map +1 -0
  198. package/dist/agents/extensions/discovery.js +249 -0
  199. package/dist/agents/extensions/discovery.js.map +1 -0
  200. package/dist/agents/extensions/hook-runner.d.ts +67 -0
  201. package/dist/agents/extensions/hook-runner.d.ts.map +1 -0
  202. package/dist/agents/extensions/hook-runner.js +155 -0
  203. package/dist/agents/extensions/hook-runner.js.map +1 -0
  204. package/dist/agents/extensions/index.d.ts +15 -0
  205. package/dist/agents/extensions/index.d.ts.map +1 -0
  206. package/dist/agents/extensions/index.js +14 -0
  207. package/dist/agents/extensions/index.js.map +1 -0
  208. package/dist/agents/extensions/loader.d.ts +38 -0
  209. package/dist/agents/extensions/loader.d.ts.map +1 -0
  210. package/dist/agents/extensions/loader.js +142 -0
  211. package/dist/agents/extensions/loader.js.map +1 -0
  212. package/dist/agents/extensions/modules/arxiv.d.ts +28 -0
  213. package/dist/agents/extensions/modules/arxiv.d.ts.map +1 -0
  214. package/dist/agents/extensions/modules/arxiv.js +145 -0
  215. package/dist/agents/extensions/modules/arxiv.js.map +1 -0
  216. package/dist/agents/extensions/modules/brave.d.ts +28 -0
  217. package/dist/agents/extensions/modules/brave.d.ts.map +1 -0
  218. package/dist/agents/extensions/modules/brave.js +489 -0
  219. package/dist/agents/extensions/modules/brave.js.map +1 -0
  220. package/dist/agents/extensions/modules/duckduckgo.d.ts +27 -0
  221. package/dist/agents/extensions/modules/duckduckgo.d.ts.map +1 -0
  222. package/dist/agents/extensions/modules/duckduckgo.js +263 -0
  223. package/dist/agents/extensions/modules/duckduckgo.js.map +1 -0
  224. package/dist/agents/extensions/modules/exa.d.ts +19 -0
  225. package/dist/agents/extensions/modules/exa.d.ts.map +1 -0
  226. package/dist/agents/extensions/modules/exa.js +208 -0
  227. package/dist/agents/extensions/modules/exa.js.map +1 -0
  228. package/dist/agents/extensions/modules/firecrawl.d.ts +51 -0
  229. package/dist/agents/extensions/modules/firecrawl.d.ts.map +1 -0
  230. package/dist/agents/extensions/modules/firecrawl.js +280 -0
  231. package/dist/agents/extensions/modules/firecrawl.js.map +1 -0
  232. package/dist/agents/extensions/modules/github-search.d.ts +29 -0
  233. package/dist/agents/extensions/modules/github-search.d.ts.map +1 -0
  234. package/dist/agents/extensions/modules/github-search.js +197 -0
  235. package/dist/agents/extensions/modules/github-search.js.map +1 -0
  236. package/dist/agents/extensions/modules/hackernews.d.ts +17 -0
  237. package/dist/agents/extensions/modules/hackernews.d.ts.map +1 -0
  238. package/dist/agents/extensions/modules/hackernews.js +144 -0
  239. package/dist/agents/extensions/modules/hackernews.js.map +1 -0
  240. package/dist/agents/extensions/modules/index.d.ts +11 -0
  241. package/dist/agents/extensions/modules/index.d.ts.map +1 -0
  242. package/dist/agents/extensions/modules/index.js +64 -0
  243. package/dist/agents/extensions/modules/index.js.map +1 -0
  244. package/dist/agents/extensions/modules/npm-search.d.ts +15 -0
  245. package/dist/agents/extensions/modules/npm-search.d.ts.map +1 -0
  246. package/dist/agents/extensions/modules/npm-search.js +126 -0
  247. package/dist/agents/extensions/modules/npm-search.js.map +1 -0
  248. package/dist/agents/extensions/modules/ollama-search.d.ts +30 -0
  249. package/dist/agents/extensions/modules/ollama-search.d.ts.map +1 -0
  250. package/dist/agents/extensions/modules/ollama-search.js +171 -0
  251. package/dist/agents/extensions/modules/ollama-search.js.map +1 -0
  252. package/dist/agents/extensions/modules/perplexity.d.ts +19 -0
  253. package/dist/agents/extensions/modules/perplexity.d.ts.map +1 -0
  254. package/dist/agents/extensions/modules/perplexity.js +358 -0
  255. package/dist/agents/extensions/modules/perplexity.js.map +1 -0
  256. package/dist/agents/extensions/modules/searxng.d.ts +43 -0
  257. package/dist/agents/extensions/modules/searxng.d.ts.map +1 -0
  258. package/dist/agents/extensions/modules/searxng.js +191 -0
  259. package/dist/agents/extensions/modules/searxng.js.map +1 -0
  260. package/dist/agents/extensions/modules/tavily.d.ts +71 -0
  261. package/dist/agents/extensions/modules/tavily.d.ts.map +1 -0
  262. package/dist/agents/extensions/modules/tavily.js +330 -0
  263. package/dist/agents/extensions/modules/tavily.js.map +1 -0
  264. package/dist/agents/extensions/modules/web-provider-helpers.d.ts +89 -0
  265. package/dist/agents/extensions/modules/web-provider-helpers.d.ts.map +1 -0
  266. package/dist/agents/extensions/modules/web-provider-helpers.js +146 -0
  267. package/dist/agents/extensions/modules/web-provider-helpers.js.map +1 -0
  268. package/dist/agents/extensions/modules/web-search-filters.d.ts +62 -0
  269. package/dist/agents/extensions/modules/web-search-filters.d.ts.map +1 -0
  270. package/dist/agents/extensions/modules/web-search-filters.js +179 -0
  271. package/dist/agents/extensions/modules/web-search-filters.js.map +1 -0
  272. package/dist/agents/extensions/modules/wikipedia.d.ts +16 -0
  273. package/dist/agents/extensions/modules/wikipedia.d.ts.map +1 -0
  274. package/dist/agents/extensions/modules/wikipedia.js +138 -0
  275. package/dist/agents/extensions/modules/wikipedia.js.map +1 -0
  276. package/dist/agents/extensions/registry-cache.d.ts +74 -0
  277. package/dist/agents/extensions/registry-cache.d.ts.map +1 -0
  278. package/dist/agents/extensions/registry-cache.js +117 -0
  279. package/dist/agents/extensions/registry-cache.js.map +1 -0
  280. package/dist/agents/extensions/registry.d.ts +184 -0
  281. package/dist/agents/extensions/registry.d.ts.map +1 -0
  282. package/dist/agents/extensions/registry.js +512 -0
  283. package/dist/agents/extensions/registry.js.map +1 -0
  284. package/dist/agents/extensions/types.d.ts +1195 -0
  285. package/dist/agents/extensions/types.d.ts.map +1 -0
  286. package/dist/agents/extensions/types.js +28 -0
  287. package/dist/agents/extensions/types.js.map +1 -0
  288. package/dist/agents/gateway-call.d.ts +171 -0
  289. package/dist/agents/gateway-call.d.ts.map +1 -0
  290. package/dist/agents/gateway-call.js +74 -0
  291. package/dist/agents/gateway-call.js.map +1 -0
  292. package/dist/agents/heartbeat-runner.d.ts +100 -0
  293. package/dist/agents/heartbeat-runner.d.ts.map +1 -0
  294. package/dist/agents/heartbeat-runner.js +268 -0
  295. package/dist/agents/heartbeat-runner.js.map +1 -0
  296. package/dist/agents/heartbeat-scheduler.d.ts +56 -0
  297. package/dist/agents/heartbeat-scheduler.d.ts.map +1 -0
  298. package/dist/agents/heartbeat-scheduler.js +366 -0
  299. package/dist/agents/heartbeat-scheduler.js.map +1 -0
  300. package/dist/agents/heartbeat-wake.d.ts +99 -0
  301. package/dist/agents/heartbeat-wake.d.ts.map +1 -0
  302. package/dist/agents/heartbeat-wake.js +304 -0
  303. package/dist/agents/heartbeat-wake.js.map +1 -0
  304. package/dist/agents/identity-file.d.ts +26 -0
  305. package/dist/agents/identity-file.d.ts.map +1 -0
  306. package/dist/agents/identity-file.js +86 -0
  307. package/dist/agents/identity-file.js.map +1 -0
  308. package/dist/agents/identity-links.d.ts +44 -0
  309. package/dist/agents/identity-links.d.ts.map +1 -0
  310. package/dist/agents/identity-links.js +51 -0
  311. package/dist/agents/identity-links.js.map +1 -0
  312. package/dist/agents/loop/autonomous-agent.d.ts +55 -0
  313. package/dist/agents/loop/autonomous-agent.d.ts.map +1 -0
  314. package/dist/agents/loop/autonomous-agent.js +91 -0
  315. package/dist/agents/loop/autonomous-agent.js.map +1 -0
  316. package/dist/agents/loop/loop-guards.d.ts +95 -0
  317. package/dist/agents/loop/loop-guards.d.ts.map +1 -0
  318. package/dist/agents/loop/loop-guards.js +169 -0
  319. package/dist/agents/loop/loop-guards.js.map +1 -0
  320. package/dist/agents/loop/loop-runner.d.ts +72 -0
  321. package/dist/agents/loop/loop-runner.d.ts.map +1 -0
  322. package/dist/agents/loop/loop-runner.js +114 -0
  323. package/dist/agents/loop/loop-runner.js.map +1 -0
  324. package/dist/agents/memory/auto-recall.d.ts +69 -0
  325. package/dist/agents/memory/auto-recall.d.ts.map +1 -0
  326. package/dist/agents/memory/auto-recall.js +147 -0
  327. package/dist/agents/memory/auto-recall.js.map +1 -0
  328. package/dist/agents/memory/behavior-review.d.ts +68 -0
  329. package/dist/agents/memory/behavior-review.d.ts.map +1 -0
  330. package/dist/agents/memory/behavior-review.js +131 -0
  331. package/dist/agents/memory/behavior-review.js.map +1 -0
  332. package/dist/agents/memory/consolidate.d.ts +62 -0
  333. package/dist/agents/memory/consolidate.d.ts.map +1 -0
  334. package/dist/agents/memory/consolidate.js +275 -0
  335. package/dist/agents/memory/consolidate.js.map +1 -0
  336. package/dist/agents/memory/contradiction.d.ts +44 -0
  337. package/dist/agents/memory/contradiction.d.ts.map +1 -0
  338. package/dist/agents/memory/contradiction.js +86 -0
  339. package/dist/agents/memory/contradiction.js.map +1 -0
  340. package/dist/agents/memory/curator.d.ts +22 -0
  341. package/dist/agents/memory/curator.d.ts.map +1 -0
  342. package/dist/agents/memory/curator.js +52 -0
  343. package/dist/agents/memory/curator.js.map +1 -0
  344. package/dist/agents/memory/decay.d.ts +32 -0
  345. package/dist/agents/memory/decay.d.ts.map +1 -0
  346. package/dist/agents/memory/decay.js +86 -0
  347. package/dist/agents/memory/decay.js.map +1 -0
  348. package/dist/agents/memory/dream.d.ts +52 -0
  349. package/dist/agents/memory/dream.d.ts.map +1 -0
  350. package/dist/agents/memory/dream.js +192 -0
  351. package/dist/agents/memory/dream.js.map +1 -0
  352. package/dist/agents/memory/embedder-providers.d.ts +114 -0
  353. package/dist/agents/memory/embedder-providers.d.ts.map +1 -0
  354. package/dist/agents/memory/embedder-providers.js +213 -0
  355. package/dist/agents/memory/embedder-providers.js.map +1 -0
  356. package/dist/agents/memory/embedder.d.ts +84 -0
  357. package/dist/agents/memory/embedder.d.ts.map +1 -0
  358. package/dist/agents/memory/embedder.js +218 -0
  359. package/dist/agents/memory/embedder.js.map +1 -0
  360. package/dist/agents/memory/eval/asr-bench.d.ts +33 -0
  361. package/dist/agents/memory/eval/asr-bench.d.ts.map +1 -0
  362. package/dist/agents/memory/eval/asr-bench.js +129 -0
  363. package/dist/agents/memory/eval/asr-bench.js.map +1 -0
  364. package/dist/agents/memory/eval/capabilities.d.ts +97 -0
  365. package/dist/agents/memory/eval/capabilities.d.ts.map +1 -0
  366. package/dist/agents/memory/eval/capabilities.js +210 -0
  367. package/dist/agents/memory/eval/capabilities.js.map +1 -0
  368. package/dist/agents/memory/eval/gold-export.d.ts +44 -0
  369. package/dist/agents/memory/eval/gold-export.d.ts.map +1 -0
  370. package/dist/agents/memory/eval/gold-export.js +85 -0
  371. package/dist/agents/memory/eval/gold-export.js.map +1 -0
  372. package/dist/agents/memory/eval/gold-hard.d.ts +35 -0
  373. package/dist/agents/memory/eval/gold-hard.d.ts.map +1 -0
  374. package/dist/agents/memory/eval/gold-hard.js +113 -0
  375. package/dist/agents/memory/eval/gold-hard.js.map +1 -0
  376. package/dist/agents/memory/eval/gold-rich.d.ts +33 -0
  377. package/dist/agents/memory/eval/gold-rich.d.ts.map +1 -0
  378. package/dist/agents/memory/eval/gold-rich.js +82 -0
  379. package/dist/agents/memory/eval/gold-rich.js.map +1 -0
  380. package/dist/agents/memory/eval/gold-synthetic.d.ts +19 -0
  381. package/dist/agents/memory/eval/gold-synthetic.d.ts.map +1 -0
  382. package/dist/agents/memory/eval/gold-synthetic.js +65 -0
  383. package/dist/agents/memory/eval/gold-synthetic.js.map +1 -0
  384. package/dist/agents/memory/eval/gold.d.ts +73 -0
  385. package/dist/agents/memory/eval/gold.d.ts.map +1 -0
  386. package/dist/agents/memory/eval/gold.js +174 -0
  387. package/dist/agents/memory/eval/gold.js.map +1 -0
  388. package/dist/agents/memory/eval/harness.d.ts +110 -0
  389. package/dist/agents/memory/eval/harness.d.ts.map +1 -0
  390. package/dist/agents/memory/eval/harness.js +123 -0
  391. package/dist/agents/memory/eval/harness.js.map +1 -0
  392. package/dist/agents/memory/eval/metrics.d.ts +71 -0
  393. package/dist/agents/memory/eval/metrics.d.ts.map +1 -0
  394. package/dist/agents/memory/eval/metrics.js +169 -0
  395. package/dist/agents/memory/eval/metrics.js.map +1 -0
  396. package/dist/agents/memory/event-log.d.ts +52 -0
  397. package/dist/agents/memory/event-log.d.ts.map +1 -0
  398. package/dist/agents/memory/event-log.js +65 -0
  399. package/dist/agents/memory/event-log.js.map +1 -0
  400. package/dist/agents/memory/extract.d.ts +155 -0
  401. package/dist/agents/memory/extract.d.ts.map +1 -0
  402. package/dist/agents/memory/extract.js +571 -0
  403. package/dist/agents/memory/extract.js.map +1 -0
  404. package/dist/agents/memory/governance.d.ts +45 -0
  405. package/dist/agents/memory/governance.d.ts.map +1 -0
  406. package/dist/agents/memory/governance.js +113 -0
  407. package/dist/agents/memory/governance.js.map +1 -0
  408. package/dist/agents/memory/graph-export.d.ts +59 -0
  409. package/dist/agents/memory/graph-export.d.ts.map +1 -0
  410. package/dist/agents/memory/graph-export.js +181 -0
  411. package/dist/agents/memory/graph-export.js.map +1 -0
  412. package/dist/agents/memory/graph-recall.d.ts +42 -0
  413. package/dist/agents/memory/graph-recall.d.ts.map +1 -0
  414. package/dist/agents/memory/graph-recall.js +165 -0
  415. package/dist/agents/memory/graph-recall.js.map +1 -0
  416. package/dist/agents/memory/graph.d.ts +92 -0
  417. package/dist/agents/memory/graph.d.ts.map +1 -0
  418. package/dist/agents/memory/graph.js +266 -0
  419. package/dist/agents/memory/graph.js.map +1 -0
  420. package/dist/agents/memory/host-ports.d.ts +27 -0
  421. package/dist/agents/memory/host-ports.d.ts.map +1 -0
  422. package/dist/agents/memory/host-ports.js +31 -0
  423. package/dist/agents/memory/host-ports.js.map +1 -0
  424. package/dist/agents/memory/hybrid.d.ts +46 -0
  425. package/dist/agents/memory/hybrid.d.ts.map +1 -0
  426. package/dist/agents/memory/hybrid.js +184 -0
  427. package/dist/agents/memory/hybrid.js.map +1 -0
  428. package/dist/agents/memory/index.d.ts +13 -0
  429. package/dist/agents/memory/index.d.ts.map +1 -0
  430. package/dist/agents/memory/index.js +13 -0
  431. package/dist/agents/memory/index.js.map +1 -0
  432. package/dist/agents/memory/json-scan.d.ts +14 -0
  433. package/dist/agents/memory/json-scan.d.ts.map +1 -0
  434. package/dist/agents/memory/json-scan.js +47 -0
  435. package/dist/agents/memory/json-scan.js.map +1 -0
  436. package/dist/agents/memory/links.d.ts +92 -0
  437. package/dist/agents/memory/links.d.ts.map +1 -0
  438. package/dist/agents/memory/links.js +140 -0
  439. package/dist/agents/memory/links.js.map +1 -0
  440. package/dist/agents/memory/maintenance.d.ts +18 -0
  441. package/dist/agents/memory/maintenance.d.ts.map +1 -0
  442. package/dist/agents/memory/maintenance.js +66 -0
  443. package/dist/agents/memory/maintenance.js.map +1 -0
  444. package/dist/agents/memory/memory-mcp-server.d.ts +39 -0
  445. package/dist/agents/memory/memory-mcp-server.d.ts.map +1 -0
  446. package/dist/agents/memory/memory-mcp-server.js +122 -0
  447. package/dist/agents/memory/memory-mcp-server.js.map +1 -0
  448. package/dist/agents/memory/memory-mcp.d.ts +34 -0
  449. package/dist/agents/memory/memory-mcp.d.ts.map +1 -0
  450. package/dist/agents/memory/memory-mcp.js +130 -0
  451. package/dist/agents/memory/memory-mcp.js.map +1 -0
  452. package/dist/agents/memory/plugin-runtime.d.ts +133 -0
  453. package/dist/agents/memory/plugin-runtime.d.ts.map +1 -0
  454. package/dist/agents/memory/plugin-runtime.js +149 -0
  455. package/dist/agents/memory/plugin-runtime.js.map +1 -0
  456. package/dist/agents/memory/query.d.ts +50 -0
  457. package/dist/agents/memory/query.d.ts.map +1 -0
  458. package/dist/agents/memory/query.js +94 -0
  459. package/dist/agents/memory/query.js.map +1 -0
  460. package/dist/agents/memory/records.d.ts +617 -0
  461. package/dist/agents/memory/records.d.ts.map +1 -0
  462. package/dist/agents/memory/records.js +1327 -0
  463. package/dist/agents/memory/records.js.map +1 -0
  464. package/dist/agents/memory/reembed.d.ts +42 -0
  465. package/dist/agents/memory/reembed.d.ts.map +1 -0
  466. package/dist/agents/memory/reembed.js +60 -0
  467. package/dist/agents/memory/reembed.js.map +1 -0
  468. package/dist/agents/memory/relationship-extract.d.ts +259 -0
  469. package/dist/agents/memory/relationship-extract.d.ts.map +1 -0
  470. package/dist/agents/memory/relationship-extract.js +454 -0
  471. package/dist/agents/memory/relationship-extract.js.map +1 -0
  472. package/dist/agents/memory/rerank.d.ts +37 -0
  473. package/dist/agents/memory/rerank.d.ts.map +1 -0
  474. package/dist/agents/memory/rerank.js +43 -0
  475. package/dist/agents/memory/rerank.js.map +1 -0
  476. package/dist/agents/memory/scoring.d.ts +85 -0
  477. package/dist/agents/memory/scoring.d.ts.map +1 -0
  478. package/dist/agents/memory/scoring.js +139 -0
  479. package/dist/agents/memory/scoring.js.map +1 -0
  480. package/dist/agents/memory/self-improve.d.ts +56 -0
  481. package/dist/agents/memory/self-improve.d.ts.map +1 -0
  482. package/dist/agents/memory/self-improve.js +98 -0
  483. package/dist/agents/memory/self-improve.js.map +1 -0
  484. package/dist/agents/memory/self-review.d.ts +68 -0
  485. package/dist/agents/memory/self-review.d.ts.map +1 -0
  486. package/dist/agents/memory/self-review.js +109 -0
  487. package/dist/agents/memory/self-review.js.map +1 -0
  488. package/dist/agents/memory/storage.d.ts +156 -0
  489. package/dist/agents/memory/storage.d.ts.map +1 -0
  490. package/dist/agents/memory/storage.js +359 -0
  491. package/dist/agents/memory/storage.js.map +1 -0
  492. package/dist/agents/memory/tideline.d.ts +203 -0
  493. package/dist/agents/memory/tideline.d.ts.map +1 -0
  494. package/dist/agents/memory/tideline.js +189 -0
  495. package/dist/agents/memory/tideline.js.map +1 -0
  496. package/dist/agents/memory/vault.d.ts +142 -0
  497. package/dist/agents/memory/vault.d.ts.map +1 -0
  498. package/dist/agents/memory/vault.js +787 -0
  499. package/dist/agents/memory/vault.js.map +1 -0
  500. package/dist/agents/memory/write-gate.d.ts +76 -0
  501. package/dist/agents/memory/write-gate.d.ts.map +1 -0
  502. package/dist/agents/memory/write-gate.js +140 -0
  503. package/dist/agents/memory/write-gate.js.map +1 -0
  504. package/dist/agents/mid-turn-switch.d.ts +25 -0
  505. package/dist/agents/mid-turn-switch.d.ts.map +1 -0
  506. package/dist/agents/mid-turn-switch.js +103 -0
  507. package/dist/agents/mid-turn-switch.js.map +1 -0
  508. package/dist/agents/model-fallback.d.ts +50 -0
  509. package/dist/agents/model-fallback.d.ts.map +1 -0
  510. package/dist/agents/model-fallback.js +226 -0
  511. package/dist/agents/model-fallback.js.map +1 -0
  512. package/dist/agents/model-resolution.d.ts +38 -0
  513. package/dist/agents/model-resolution.d.ts.map +1 -0
  514. package/dist/agents/model-resolution.js +155 -0
  515. package/dist/agents/model-resolution.js.map +1 -0
  516. package/dist/agents/org/a2a-adapter.d.ts +49 -0
  517. package/dist/agents/org/a2a-adapter.d.ts.map +1 -0
  518. package/dist/agents/org/a2a-adapter.js +92 -0
  519. package/dist/agents/org/a2a-adapter.js.map +1 -0
  520. package/dist/agents/org/assets/mascots/README.md +34 -0
  521. package/dist/agents/org/assets/mascots/Untitled-1.png +0 -0
  522. package/dist/agents/org/assets/mascots/brigade_biceps.png +0 -0
  523. package/dist/agents/org/audit-log.d.ts +22 -0
  524. package/dist/agents/org/audit-log.d.ts.map +1 -0
  525. package/dist/agents/org/audit-log.js +37 -0
  526. package/dist/agents/org/audit-log.js.map +1 -0
  527. package/dist/agents/org/auto-derive.d.ts +22 -0
  528. package/dist/agents/org/auto-derive.d.ts.map +1 -0
  529. package/dist/agents/org/auto-derive.js +66 -0
  530. package/dist/agents/org/auto-derive.js.map +1 -0
  531. package/dist/agents/org/delivery-kind.d.ts +89 -0
  532. package/dist/agents/org/delivery-kind.d.ts.map +1 -0
  533. package/dist/agents/org/delivery-kind.js +149 -0
  534. package/dist/agents/org/delivery-kind.js.map +1 -0
  535. package/dist/agents/org/derive-graph.d.ts +34 -0
  536. package/dist/agents/org/derive-graph.d.ts.map +1 -0
  537. package/dist/agents/org/derive-graph.js +266 -0
  538. package/dist/agents/org/derive-graph.js.map +1 -0
  539. package/dist/agents/org/lints.d.ts +21 -0
  540. package/dist/agents/org/lints.d.ts.map +1 -0
  541. package/dist/agents/org/lints.js +133 -0
  542. package/dist/agents/org/lints.js.map +1 -0
  543. package/dist/agents/org/pride-html.d.ts +61 -0
  544. package/dist/agents/org/pride-html.d.ts.map +1 -0
  545. package/dist/agents/org/pride-html.js +565 -0
  546. package/dist/agents/org/pride-html.js.map +1 -0
  547. package/dist/agents/org/pride-image.d.ts +101 -0
  548. package/dist/agents/org/pride-image.d.ts.map +1 -0
  549. package/dist/agents/org/pride-image.js +210 -0
  550. package/dist/agents/org/pride-image.js.map +1 -0
  551. package/dist/agents/org/pride-taunts.d.ts +47 -0
  552. package/dist/agents/org/pride-taunts.d.ts.map +1 -0
  553. package/dist/agents/org/pride-taunts.js +411 -0
  554. package/dist/agents/org/pride-taunts.js.map +1 -0
  555. package/dist/agents/org/pride-template.d.ts +272 -0
  556. package/dist/agents/org/pride-template.d.ts.map +1 -0
  557. package/dist/agents/org/pride-template.js +892 -0
  558. package/dist/agents/org/pride-template.js.map +1 -0
  559. package/dist/agents/org/pride-themes.d.ts +80 -0
  560. package/dist/agents/org/pride-themes.d.ts.map +1 -0
  561. package/dist/agents/org/pride-themes.js +7596 -0
  562. package/dist/agents/org/pride-themes.js.map +1 -0
  563. package/dist/agents/org/structured-errors.d.ts +47 -0
  564. package/dist/agents/org/structured-errors.d.ts.map +1 -0
  565. package/dist/agents/org/structured-errors.js +97 -0
  566. package/dist/agents/org/structured-errors.js.map +1 -0
  567. package/dist/agents/org/types.d.ts +139 -0
  568. package/dist/agents/org/types.d.ts.map +1 -0
  569. package/dist/agents/org/types.js +43 -0
  570. package/dist/agents/org/types.js.map +1 -0
  571. package/dist/agents/org/validate.d.ts +36 -0
  572. package/dist/agents/org/validate.d.ts.map +1 -0
  573. package/dist/agents/org/validate.js +135 -0
  574. package/dist/agents/org/validate.js.map +1 -0
  575. package/dist/agents/path-write-guard.d.ts +82 -0
  576. package/dist/agents/path-write-guard.d.ts.map +1 -0
  577. package/dist/agents/path-write-guard.js +722 -0
  578. package/dist/agents/path-write-guard.js.map +1 -0
  579. package/dist/agents/payload-mutators.d.ts +175 -0
  580. package/dist/agents/payload-mutators.d.ts.map +1 -0
  581. package/dist/agents/payload-mutators.js +994 -0
  582. package/dist/agents/payload-mutators.js.map +1 -0
  583. package/dist/agents/pending-system-events.d.ts +76 -0
  584. package/dist/agents/pending-system-events.d.ts.map +1 -0
  585. package/dist/agents/pending-system-events.js +115 -0
  586. package/dist/agents/pending-system-events.js.map +1 -0
  587. package/dist/agents/provider-attribution.d.ts +19 -0
  588. package/dist/agents/provider-attribution.d.ts.map +1 -0
  589. package/dist/agents/provider-attribution.js +62 -0
  590. package/dist/agents/provider-attribution.js.map +1 -0
  591. package/dist/agents/quality/slop-detector.d.ts +40 -0
  592. package/dist/agents/quality/slop-detector.d.ts.map +1 -0
  593. package/dist/agents/quality/slop-detector.js +108 -0
  594. package/dist/agents/quality/slop-detector.js.map +1 -0
  595. package/dist/agents/quality/slop-index.d.ts +27 -0
  596. package/dist/agents/quality/slop-index.d.ts.map +1 -0
  597. package/dist/agents/quality/slop-index.js +124 -0
  598. package/dist/agents/quality/slop-index.js.map +1 -0
  599. package/dist/agents/retry-policy.d.ts +38 -0
  600. package/dist/agents/retry-policy.d.ts.map +1 -0
  601. package/dist/agents/retry-policy.js +276 -0
  602. package/dist/agents/retry-policy.js.map +1 -0
  603. package/dist/agents/routing/account-id.d.ts +43 -0
  604. package/dist/agents/routing/account-id.d.ts.map +1 -0
  605. package/dist/agents/routing/account-id.js +103 -0
  606. package/dist/agents/routing/account-id.js.map +1 -0
  607. package/dist/agents/routing/bindings.d.ts +20 -0
  608. package/dist/agents/routing/bindings.d.ts.map +1 -0
  609. package/dist/agents/routing/bindings.js +22 -0
  610. package/dist/agents/routing/bindings.js.map +1 -0
  611. package/dist/agents/routing/dm-scope-warning.d.ts +37 -0
  612. package/dist/agents/routing/dm-scope-warning.d.ts.map +1 -0
  613. package/dist/agents/routing/dm-scope-warning.js +110 -0
  614. package/dist/agents/routing/dm-scope-warning.js.map +1 -0
  615. package/dist/agents/routing/identity-links.d.ts +45 -0
  616. package/dist/agents/routing/identity-links.d.ts.map +1 -0
  617. package/dist/agents/routing/identity-links.js +85 -0
  618. package/dist/agents/routing/identity-links.js.map +1 -0
  619. package/dist/agents/routing/resolve-route.d.ts +91 -0
  620. package/dist/agents/routing/resolve-route.d.ts.map +1 -0
  621. package/dist/agents/routing/resolve-route.js +653 -0
  622. package/dist/agents/routing/resolve-route.js.map +1 -0
  623. package/dist/agents/routing/session-key.d.ts +168 -0
  624. package/dist/agents/routing/session-key.d.ts.map +1 -0
  625. package/dist/agents/routing/session-key.js +268 -0
  626. package/dist/agents/routing/session-key.js.map +1 -0
  627. package/dist/agents/sanitize-surrogates.d.ts +30 -0
  628. package/dist/agents/sanitize-surrogates.d.ts.map +1 -0
  629. package/dist/agents/sanitize-surrogates.js +56 -0
  630. package/dist/agents/sanitize-surrogates.js.map +1 -0
  631. package/dist/agents/session-context.d.ts +80 -0
  632. package/dist/agents/session-context.d.ts.map +1 -0
  633. package/dist/agents/session-context.js +76 -0
  634. package/dist/agents/session-context.js.map +1 -0
  635. package/dist/agents/session-event-prompt.d.ts +124 -0
  636. package/dist/agents/session-event-prompt.d.ts.map +1 -0
  637. package/dist/agents/session-event-prompt.js +179 -0
  638. package/dist/agents/session-event-prompt.js.map +1 -0
  639. package/dist/agents/session-inbox.d.ts +129 -0
  640. package/dist/agents/session-inbox.d.ts.map +1 -0
  641. package/dist/agents/session-inbox.js +492 -0
  642. package/dist/agents/session-inbox.js.map +1 -0
  643. package/dist/agents/session-registry.d.ts +148 -0
  644. package/dist/agents/session-registry.d.ts.map +1 -0
  645. package/dist/agents/session-registry.js +405 -0
  646. package/dist/agents/session-registry.js.map +1 -0
  647. package/dist/agents/session-wiring.d.ts +214 -0
  648. package/dist/agents/session-wiring.d.ts.map +1 -0
  649. package/dist/agents/session-wiring.js +278 -0
  650. package/dist/agents/session-wiring.js.map +1 -0
  651. package/dist/agents/session-write-lock.d.ts +15 -0
  652. package/dist/agents/session-write-lock.d.ts.map +1 -0
  653. package/dist/agents/session-write-lock.js +15 -0
  654. package/dist/agents/session-write-lock.js.map +1 -0
  655. package/dist/agents/skills/agent-filter.d.ts +43 -0
  656. package/dist/agents/skills/agent-filter.d.ts.map +1 -0
  657. package/dist/agents/skills/agent-filter.js +89 -0
  658. package/dist/agents/skills/agent-filter.js.map +1 -0
  659. package/dist/agents/skills/discovery.d.ts +97 -0
  660. package/dist/agents/skills/discovery.d.ts.map +1 -0
  661. package/dist/agents/skills/discovery.js +136 -0
  662. package/dist/agents/skills/discovery.js.map +1 -0
  663. package/dist/agents/skills/eligibility.d.ts +118 -0
  664. package/dist/agents/skills/eligibility.d.ts.map +1 -0
  665. package/dist/agents/skills/eligibility.js +280 -0
  666. package/dist/agents/skills/eligibility.js.map +1 -0
  667. package/dist/agents/skills/grant.d.ts +70 -0
  668. package/dist/agents/skills/grant.d.ts.map +1 -0
  669. package/dist/agents/skills/grant.js +106 -0
  670. package/dist/agents/skills/grant.js.map +1 -0
  671. package/dist/agents/skills/index.d.ts +35 -0
  672. package/dist/agents/skills/index.d.ts.map +1 -0
  673. package/dist/agents/skills/index.js +88 -0
  674. package/dist/agents/skills/index.js.map +1 -0
  675. package/dist/agents/skills/install-spec.d.ts +51 -0
  676. package/dist/agents/skills/install-spec.d.ts.map +1 -0
  677. package/dist/agents/skills/install-spec.js +21 -0
  678. package/dist/agents/skills/install-spec.js.map +1 -0
  679. package/dist/agents/skills/install.d.ts +68 -0
  680. package/dist/agents/skills/install.d.ts.map +1 -0
  681. package/dist/agents/skills/install.js +206 -0
  682. package/dist/agents/skills/install.js.map +1 -0
  683. package/dist/agents/skills/org-access.d.ts +27 -0
  684. package/dist/agents/skills/org-access.d.ts.map +1 -0
  685. package/dist/agents/skills/org-access.js +87 -0
  686. package/dist/agents/skills/org-access.js.map +1 -0
  687. package/dist/agents/skills/skill-consolidate.d.ts +76 -0
  688. package/dist/agents/skills/skill-consolidate.d.ts.map +1 -0
  689. package/dist/agents/skills/skill-consolidate.js +264 -0
  690. package/dist/agents/skills/skill-consolidate.js.map +1 -0
  691. package/dist/agents/skills/skill-curator.d.ts +91 -0
  692. package/dist/agents/skills/skill-curator.d.ts.map +1 -0
  693. package/dist/agents/skills/skill-curator.js +239 -0
  694. package/dist/agents/skills/skill-curator.js.map +1 -0
  695. package/dist/agents/skills/skill-manifest.d.ts +35 -0
  696. package/dist/agents/skills/skill-manifest.d.ts.map +1 -0
  697. package/dist/agents/skills/skill-manifest.js +82 -0
  698. package/dist/agents/skills/skill-manifest.js.map +1 -0
  699. package/dist/agents/skills/skill-review.d.ts +91 -0
  700. package/dist/agents/skills/skill-review.d.ts.map +1 -0
  701. package/dist/agents/skills/skill-review.js +271 -0
  702. package/dist/agents/skills/skill-review.js.map +1 -0
  703. package/dist/agents/skills/skill-usage.d.ts +81 -0
  704. package/dist/agents/skills/skill-usage.d.ts.map +1 -0
  705. package/dist/agents/skills/skill-usage.js +208 -0
  706. package/dist/agents/skills/skill-usage.js.map +1 -0
  707. package/dist/agents/skills/status.d.ts +68 -0
  708. package/dist/agents/skills/status.d.ts.map +1 -0
  709. package/dist/agents/skills/status.js +147 -0
  710. package/dist/agents/skills/status.js.map +1 -0
  711. package/dist/agents/skills/update-config.d.ts +32 -0
  712. package/dist/agents/skills/update-config.d.ts.map +1 -0
  713. package/dist/agents/skills/update-config.js +53 -0
  714. package/dist/agents/skills/update-config.js.map +1 -0
  715. package/dist/agents/slash-commands.d.ts +25 -0
  716. package/dist/agents/slash-commands.d.ts.map +1 -0
  717. package/dist/agents/slash-commands.js +151 -0
  718. package/dist/agents/slash-commands.js.map +1 -0
  719. package/dist/agents/smart-compaction.d.ts +105 -0
  720. package/dist/agents/smart-compaction.d.ts.map +1 -0
  721. package/dist/agents/smart-compaction.js +355 -0
  722. package/dist/agents/smart-compaction.js.map +1 -0
  723. package/dist/agents/stream-wrappers.d.ts +20 -0
  724. package/dist/agents/stream-wrappers.d.ts.map +1 -0
  725. package/dist/agents/stream-wrappers.js +307 -0
  726. package/dist/agents/stream-wrappers.js.map +1 -0
  727. package/dist/agents/subagent-abort-cascade.d.ts +31 -0
  728. package/dist/agents/subagent-abort-cascade.d.ts.map +1 -0
  729. package/dist/agents/subagent-abort-cascade.js +124 -0
  730. package/dist/agents/subagent-abort-cascade.js.map +1 -0
  731. package/dist/agents/subagent-announce-delivery.d.ts +83 -0
  732. package/dist/agents/subagent-announce-delivery.d.ts.map +1 -0
  733. package/dist/agents/subagent-announce-delivery.js +159 -0
  734. package/dist/agents/subagent-announce-delivery.js.map +1 -0
  735. package/dist/agents/subagent-budget.d.ts +36 -0
  736. package/dist/agents/subagent-budget.d.ts.map +1 -0
  737. package/dist/agents/subagent-budget.js +93 -0
  738. package/dist/agents/subagent-budget.js.map +1 -0
  739. package/dist/agents/subagent-completion-bridge.d.ts +42 -0
  740. package/dist/agents/subagent-completion-bridge.d.ts.map +1 -0
  741. package/dist/agents/subagent-completion-bridge.js +338 -0
  742. package/dist/agents/subagent-completion-bridge.js.map +1 -0
  743. package/dist/agents/subagent-lifecycle-events.d.ts +31 -0
  744. package/dist/agents/subagent-lifecycle-events.d.ts.map +1 -0
  745. package/dist/agents/subagent-lifecycle-events.js +21 -0
  746. package/dist/agents/subagent-lifecycle-events.js.map +1 -0
  747. package/dist/agents/subagent-policy.d.ts +206 -0
  748. package/dist/agents/subagent-policy.d.ts.map +1 -0
  749. package/dist/agents/subagent-policy.js +295 -0
  750. package/dist/agents/subagent-policy.js.map +1 -0
  751. package/dist/agents/subagent-registry-completion.d.ts +69 -0
  752. package/dist/agents/subagent-registry-completion.d.ts.map +1 -0
  753. package/dist/agents/subagent-registry-completion.js +128 -0
  754. package/dist/agents/subagent-registry-completion.js.map +1 -0
  755. package/dist/agents/subagent-registry.d.ts +85 -0
  756. package/dist/agents/subagent-registry.d.ts.map +1 -0
  757. package/dist/agents/subagent-registry.js +215 -0
  758. package/dist/agents/subagent-registry.js.map +1 -0
  759. package/dist/agents/subagent-registry.types.d.ts +94 -0
  760. package/dist/agents/subagent-registry.types.d.ts.map +1 -0
  761. package/dist/agents/subagent-registry.types.js +19 -0
  762. package/dist/agents/subagent-registry.types.js.map +1 -0
  763. package/dist/agents/subagent-runner.d.ts +75 -0
  764. package/dist/agents/subagent-runner.d.ts.map +1 -0
  765. package/dist/agents/subagent-runner.js +358 -0
  766. package/dist/agents/subagent-runner.js.map +1 -0
  767. package/dist/agents/subagent-spawn-abort-marker.d.ts +46 -0
  768. package/dist/agents/subagent-spawn-abort-marker.d.ts.map +1 -0
  769. package/dist/agents/subagent-spawn-abort-marker.js +81 -0
  770. package/dist/agents/subagent-spawn-abort-marker.js.map +1 -0
  771. package/dist/agents/subagent-spawn.d.ts +104 -0
  772. package/dist/agents/subagent-spawn.d.ts.map +1 -0
  773. package/dist/agents/subagent-spawn.js +358 -0
  774. package/dist/agents/subagent-spawn.js.map +1 -0
  775. package/dist/agents/thinking-fallback.d.ts +49 -0
  776. package/dist/agents/thinking-fallback.d.ts.map +1 -0
  777. package/dist/agents/thinking-fallback.js +97 -0
  778. package/dist/agents/thinking-fallback.js.map +1 -0
  779. package/dist/agents/tool-guard.d.ts +71 -0
  780. package/dist/agents/tool-guard.d.ts.map +1 -0
  781. package/dist/agents/tool-guard.js +154 -0
  782. package/dist/agents/tool-guard.js.map +1 -0
  783. package/dist/agents/tool-loop-detector.d.ts +115 -0
  784. package/dist/agents/tool-loop-detector.d.ts.map +1 -0
  785. package/dist/agents/tool-loop-detector.js +0 -0
  786. package/dist/agents/tool-loop-detector.js.map +1 -0
  787. package/dist/agents/tool-summaries.d.ts +3 -0
  788. package/dist/agents/tool-summaries.d.ts.map +1 -0
  789. package/dist/agents/tool-summaries.js +78 -0
  790. package/dist/agents/tool-summaries.js.map +1 -0
  791. package/dist/agents/tools/agents-list-tool.d.ts +51 -0
  792. package/dist/agents/tools/agents-list-tool.d.ts.map +1 -0
  793. package/dist/agents/tools/agents-list-tool.js +167 -0
  794. package/dist/agents/tools/agents-list-tool.js.map +1 -0
  795. package/dist/agents/tools/browser.d.ts +144 -0
  796. package/dist/agents/tools/browser.d.ts.map +1 -0
  797. package/dist/agents/tools/browser.js +1538 -0
  798. package/dist/agents/tools/browser.js.map +1 -0
  799. package/dist/agents/tools/common.d.ts +208 -0
  800. package/dist/agents/tools/common.d.ts.map +1 -0
  801. package/dist/agents/tools/common.js +405 -0
  802. package/dist/agents/tools/common.js.map +1 -0
  803. package/dist/agents/tools/composio-tool.d.ts +179 -0
  804. package/dist/agents/tools/composio-tool.d.ts.map +1 -0
  805. package/dist/agents/tools/composio-tool.js +474 -0
  806. package/dist/agents/tools/composio-tool.js.map +1 -0
  807. package/dist/agents/tools/cron-tool.d.ts +187 -0
  808. package/dist/agents/tools/cron-tool.d.ts.map +1 -0
  809. package/dist/agents/tools/cron-tool.js +985 -0
  810. package/dist/agents/tools/cron-tool.js.map +1 -0
  811. package/dist/agents/tools/find-tool.d.ts +55 -0
  812. package/dist/agents/tools/find-tool.d.ts.map +1 -0
  813. package/dist/agents/tools/find-tool.js +163 -0
  814. package/dist/agents/tools/find-tool.js.map +1 -0
  815. package/dist/agents/tools/generate-image-tool.d.ts +77 -0
  816. package/dist/agents/tools/generate-image-tool.d.ts.map +1 -0
  817. package/dist/agents/tools/generate-image-tool.js +421 -0
  818. package/dist/agents/tools/generate-image-tool.js.map +1 -0
  819. package/dist/agents/tools/index.d.ts +14 -0
  820. package/dist/agents/tools/index.d.ts.map +1 -0
  821. package/dist/agents/tools/index.js +12 -0
  822. package/dist/agents/tools/index.js.map +1 -0
  823. package/dist/agents/tools/manage-access-tool.d.ts +64 -0
  824. package/dist/agents/tools/manage-access-tool.d.ts.map +1 -0
  825. package/dist/agents/tools/manage-access-tool.js +188 -0
  826. package/dist/agents/tools/manage-access-tool.js.map +1 -0
  827. package/dist/agents/tools/manage-agent-tool.d.ts +50 -0
  828. package/dist/agents/tools/manage-agent-tool.d.ts.map +1 -0
  829. package/dist/agents/tools/manage-agent-tool.js +232 -0
  830. package/dist/agents/tools/manage-agent-tool.js.map +1 -0
  831. package/dist/agents/tools/manage-channel-access-tool.d.ts +44 -0
  832. package/dist/agents/tools/manage-channel-access-tool.d.ts.map +1 -0
  833. package/dist/agents/tools/manage-channel-access-tool.js +144 -0
  834. package/dist/agents/tools/manage-channel-access-tool.js.map +1 -0
  835. package/dist/agents/tools/manage-memory-tool.d.ts +30 -0
  836. package/dist/agents/tools/manage-memory-tool.d.ts.map +1 -0
  837. package/dist/agents/tools/manage-memory-tool.js +309 -0
  838. package/dist/agents/tools/manage-memory-tool.js.map +1 -0
  839. package/dist/agents/tools/manage-provider-tool.d.ts +65 -0
  840. package/dist/agents/tools/manage-provider-tool.d.ts.map +1 -0
  841. package/dist/agents/tools/manage-provider-tool.js +249 -0
  842. package/dist/agents/tools/manage-provider-tool.js.map +1 -0
  843. package/dist/agents/tools/manage-skill-tool.d.ts +121 -0
  844. package/dist/agents/tools/manage-skill-tool.d.ts.map +1 -0
  845. package/dist/agents/tools/manage-skill-tool.js +722 -0
  846. package/dist/agents/tools/manage-skill-tool.js.map +1 -0
  847. package/dist/agents/tools/memory-tools.d.ts +172 -0
  848. package/dist/agents/tools/memory-tools.d.ts.map +1 -0
  849. package/dist/agents/tools/memory-tools.js +561 -0
  850. package/dist/agents/tools/memory-tools.js.map +1 -0
  851. package/dist/agents/tools/oauth-authorize-tool.d.ts +94 -0
  852. package/dist/agents/tools/oauth-authorize-tool.d.ts.map +1 -0
  853. package/dist/agents/tools/oauth-authorize-tool.js +670 -0
  854. package/dist/agents/tools/oauth-authorize-tool.js.map +1 -0
  855. package/dist/agents/tools/org-tool.d.ts +208 -0
  856. package/dist/agents/tools/org-tool.d.ts.map +1 -0
  857. package/dist/agents/tools/org-tool.js +790 -0
  858. package/dist/agents/tools/org-tool.js.map +1 -0
  859. package/dist/agents/tools/registry.d.ts +146 -0
  860. package/dist/agents/tools/registry.d.ts.map +1 -0
  861. package/dist/agents/tools/registry.js +396 -0
  862. package/dist/agents/tools/registry.js.map +1 -0
  863. package/dist/agents/tools/send-media-tool.d.ts +92 -0
  864. package/dist/agents/tools/send-media-tool.d.ts.map +1 -0
  865. package/dist/agents/tools/send-media-tool.js +512 -0
  866. package/dist/agents/tools/send-media-tool.js.map +1 -0
  867. package/dist/agents/tools/send-message-tool.d.ts +84 -0
  868. package/dist/agents/tools/send-message-tool.d.ts.map +1 -0
  869. package/dist/agents/tools/send-message-tool.js +226 -0
  870. package/dist/agents/tools/send-message-tool.js.map +1 -0
  871. package/dist/agents/tools/sessions/history.d.ts +53 -0
  872. package/dist/agents/tools/sessions/history.d.ts.map +1 -0
  873. package/dist/agents/tools/sessions/history.js +138 -0
  874. package/dist/agents/tools/sessions/history.js.map +1 -0
  875. package/dist/agents/tools/sessions/index.d.ts +92 -0
  876. package/dist/agents/tools/sessions/index.d.ts.map +1 -0
  877. package/dist/agents/tools/sessions/index.js +125 -0
  878. package/dist/agents/tools/sessions/index.js.map +1 -0
  879. package/dist/agents/tools/sessions/list.d.ts +53 -0
  880. package/dist/agents/tools/sessions/list.d.ts.map +1 -0
  881. package/dist/agents/tools/sessions/list.js +134 -0
  882. package/dist/agents/tools/sessions/list.js.map +1 -0
  883. package/dist/agents/tools/sessions/resolve-access.d.ts +34 -0
  884. package/dist/agents/tools/sessions/resolve-access.d.ts.map +1 -0
  885. package/dist/agents/tools/sessions/resolve-access.js +67 -0
  886. package/dist/agents/tools/sessions/resolve-access.js.map +1 -0
  887. package/dist/agents/tools/sessions/send.d.ts +68 -0
  888. package/dist/agents/tools/sessions/send.d.ts.map +1 -0
  889. package/dist/agents/tools/sessions/send.js +556 -0
  890. package/dist/agents/tools/sessions/send.js.map +1 -0
  891. package/dist/agents/tools/sessions/shared.d.ts +145 -0
  892. package/dist/agents/tools/sessions/shared.d.ts.map +1 -0
  893. package/dist/agents/tools/sessions/shared.js +352 -0
  894. package/dist/agents/tools/sessions/shared.js.map +1 -0
  895. package/dist/agents/tools/sessions/spawn.d.ts +71 -0
  896. package/dist/agents/tools/sessions/spawn.d.ts.map +1 -0
  897. package/dist/agents/tools/sessions/spawn.js +132 -0
  898. package/dist/agents/tools/sessions/spawn.js.map +1 -0
  899. package/dist/agents/tools/spawn-agent-tool.d.ts +87 -0
  900. package/dist/agents/tools/spawn-agent-tool.d.ts.map +1 -0
  901. package/dist/agents/tools/spawn-agent-tool.js +189 -0
  902. package/dist/agents/tools/spawn-agent-tool.js.map +1 -0
  903. package/dist/agents/tools/spawn-agents-tool.d.ts +75 -0
  904. package/dist/agents/tools/spawn-agents-tool.d.ts.map +1 -0
  905. package/dist/agents/tools/spawn-agents-tool.js +267 -0
  906. package/dist/agents/tools/spawn-agents-tool.js.map +1 -0
  907. package/dist/agents/tools/types.d.ts +55 -0
  908. package/dist/agents/tools/types.d.ts.map +1 -0
  909. package/dist/agents/tools/types.js +28 -0
  910. package/dist/agents/tools/types.js.map +1 -0
  911. package/dist/agents/tools/web-fetch-utils.d.ts +114 -0
  912. package/dist/agents/tools/web-fetch-utils.d.ts.map +1 -0
  913. package/dist/agents/tools/web-fetch-utils.js +560 -0
  914. package/dist/agents/tools/web-fetch-utils.js.map +1 -0
  915. package/dist/agents/tools/web-fetch.d.ts +97 -0
  916. package/dist/agents/tools/web-fetch.d.ts.map +1 -0
  917. package/dist/agents/tools/web-fetch.js +369 -0
  918. package/dist/agents/tools/web-fetch.js.map +1 -0
  919. package/dist/agents/tools/web-retry.d.ts +55 -0
  920. package/dist/agents/tools/web-retry.d.ts.map +1 -0
  921. package/dist/agents/tools/web-retry.js +172 -0
  922. package/dist/agents/tools/web-retry.js.map +1 -0
  923. package/dist/agents/tools/web-search.d.ts +96 -0
  924. package/dist/agents/tools/web-search.d.ts.map +1 -0
  925. package/dist/agents/tools/web-search.js +459 -0
  926. package/dist/agents/tools/web-search.js.map +1 -0
  927. package/dist/agents/tools/web-shared.d.ts +123 -0
  928. package/dist/agents/tools/web-shared.d.ts.map +1 -0
  929. package/dist/agents/tools/web-shared.js +207 -0
  930. package/dist/agents/tools/web-shared.js.map +1 -0
  931. package/dist/assets/brigade-favicon.png +0 -0
  932. package/dist/auth/profile-cooldown.d.ts +105 -0
  933. package/dist/auth/profile-cooldown.d.ts.map +1 -0
  934. package/dist/auth/profile-cooldown.js +466 -0
  935. package/dist/auth/profile-cooldown.js.map +1 -0
  936. package/dist/auth/profiles.d.ts +93 -0
  937. package/dist/auth/profiles.d.ts.map +1 -0
  938. package/dist/auth/profiles.js +321 -0
  939. package/dist/auth/profiles.js.map +1 -0
  940. package/dist/buildstamp.json +1 -0
  941. package/dist/cli/argv.d.ts +20 -0
  942. package/dist/cli/argv.d.ts.map +1 -0
  943. package/dist/cli/argv.js +47 -0
  944. package/dist/cli/argv.js.map +1 -0
  945. package/dist/cli/commands/agent.d.ts +19 -0
  946. package/dist/cli/commands/agent.d.ts.map +1 -0
  947. package/dist/cli/commands/agent.js +297 -0
  948. package/dist/cli/commands/agent.js.map +1 -0
  949. package/dist/cli/commands/agents-bindings.d.ts +80 -0
  950. package/dist/cli/commands/agents-bindings.d.ts.map +1 -0
  951. package/dist/cli/commands/agents-bindings.js +252 -0
  952. package/dist/cli/commands/agents-bindings.js.map +1 -0
  953. package/dist/cli/commands/agents-cmd.d.ts +160 -0
  954. package/dist/cli/commands/agents-cmd.d.ts.map +1 -0
  955. package/dist/cli/commands/agents-cmd.js +1199 -0
  956. package/dist/cli/commands/agents-cmd.js.map +1 -0
  957. package/dist/cli/commands/agents-config.d.ts +102 -0
  958. package/dist/cli/commands/agents-config.d.ts.map +1 -0
  959. package/dist/cli/commands/agents-config.js +294 -0
  960. package/dist/cli/commands/agents-config.js.map +1 -0
  961. package/dist/cli/commands/agents-shared.d.ts +57 -0
  962. package/dist/cli/commands/agents-shared.d.ts.map +1 -0
  963. package/dist/cli/commands/agents-shared.js +83 -0
  964. package/dist/cli/commands/agents-shared.js.map +1 -0
  965. package/dist/cli/commands/backup.d.ts +36 -0
  966. package/dist/cli/commands/backup.d.ts.map +1 -0
  967. package/dist/cli/commands/backup.js +244 -0
  968. package/dist/cli/commands/backup.js.map +1 -0
  969. package/dist/cli/commands/channels.d.ts +106 -0
  970. package/dist/cli/commands/channels.d.ts.map +1 -0
  971. package/dist/cli/commands/channels.js +830 -0
  972. package/dist/cli/commands/channels.js.map +1 -0
  973. package/dist/cli/commands/chat.d.ts +43 -0
  974. package/dist/cli/commands/chat.d.ts.map +1 -0
  975. package/dist/cli/commands/chat.js +84 -0
  976. package/dist/cli/commands/chat.js.map +1 -0
  977. package/dist/cli/commands/config-cmd.d.ts +62 -0
  978. package/dist/cli/commands/config-cmd.d.ts.map +1 -0
  979. package/dist/cli/commands/config-cmd.js +404 -0
  980. package/dist/cli/commands/config-cmd.js.map +1 -0
  981. package/dist/cli/commands/connect.d.ts +73 -0
  982. package/dist/cli/commands/connect.d.ts.map +1 -0
  983. package/dist/cli/commands/connect.js +1952 -0
  984. package/dist/cli/commands/connect.js.map +1 -0
  985. package/dist/cli/commands/cron.d.ts +58 -0
  986. package/dist/cli/commands/cron.d.ts.map +1 -0
  987. package/dist/cli/commands/cron.js +250 -0
  988. package/dist/cli/commands/cron.js.map +1 -0
  989. package/dist/cli/commands/doctor.d.ts +25 -0
  990. package/dist/cli/commands/doctor.d.ts.map +1 -0
  991. package/dist/cli/commands/doctor.js +618 -0
  992. package/dist/cli/commands/doctor.js.map +1 -0
  993. package/dist/cli/commands/encrypt-cmd.d.ts +12 -0
  994. package/dist/cli/commands/encrypt-cmd.d.ts.map +1 -0
  995. package/dist/cli/commands/encrypt-cmd.js +119 -0
  996. package/dist/cli/commands/encrypt-cmd.js.map +1 -0
  997. package/dist/cli/commands/exec-cmd.d.ts +55 -0
  998. package/dist/cli/commands/exec-cmd.d.ts.map +1 -0
  999. package/dist/cli/commands/exec-cmd.js +253 -0
  1000. package/dist/cli/commands/exec-cmd.js.map +1 -0
  1001. package/dist/cli/commands/gateway-install.d.ts +21 -0
  1002. package/dist/cli/commands/gateway-install.d.ts.map +1 -0
  1003. package/dist/cli/commands/gateway-install.js +71 -0
  1004. package/dist/cli/commands/gateway-install.js.map +1 -0
  1005. package/dist/cli/commands/gateway-supervise.d.ts +102 -0
  1006. package/dist/cli/commands/gateway-supervise.d.ts.map +1 -0
  1007. package/dist/cli/commands/gateway-supervise.js +194 -0
  1008. package/dist/cli/commands/gateway-supervise.js.map +1 -0
  1009. package/dist/cli/commands/gateway.d.ts +58 -0
  1010. package/dist/cli/commands/gateway.d.ts.map +1 -0
  1011. package/dist/cli/commands/gateway.js +497 -0
  1012. package/dist/cli/commands/gateway.js.map +1 -0
  1013. package/dist/cli/commands/logs.d.ts +14 -0
  1014. package/dist/cli/commands/logs.d.ts.map +1 -0
  1015. package/dist/cli/commands/logs.js +93 -0
  1016. package/dist/cli/commands/logs.js.map +1 -0
  1017. package/dist/cli/commands/mcp-cmd.d.ts +4 -0
  1018. package/dist/cli/commands/mcp-cmd.d.ts.map +1 -0
  1019. package/dist/cli/commands/mcp-cmd.js +30 -0
  1020. package/dist/cli/commands/mcp-cmd.js.map +1 -0
  1021. package/dist/cli/commands/onboard-config.d.ts +23 -0
  1022. package/dist/cli/commands/onboard-config.d.ts.map +1 -0
  1023. package/dist/cli/commands/onboard-config.js +33 -0
  1024. package/dist/cli/commands/onboard-config.js.map +1 -0
  1025. package/dist/cli/commands/onboard.d.ts +48 -0
  1026. package/dist/cli/commands/onboard.d.ts.map +1 -0
  1027. package/dist/cli/commands/onboard.js +397 -0
  1028. package/dist/cli/commands/onboard.js.map +1 -0
  1029. package/dist/cli/commands/org-cmd.d.ts +87 -0
  1030. package/dist/cli/commands/org-cmd.d.ts.map +1 -0
  1031. package/dist/cli/commands/org-cmd.js +394 -0
  1032. package/dist/cli/commands/org-cmd.js.map +1 -0
  1033. package/dist/cli/commands/org-cmd.templates.d.ts +66 -0
  1034. package/dist/cli/commands/org-cmd.templates.d.ts.map +1 -0
  1035. package/dist/cli/commands/org-cmd.templates.js +145 -0
  1036. package/dist/cli/commands/org-cmd.templates.js.map +1 -0
  1037. package/dist/cli/commands/org-slash.d.ts +107 -0
  1038. package/dist/cli/commands/org-slash.d.ts.map +1 -0
  1039. package/dist/cli/commands/org-slash.js +263 -0
  1040. package/dist/cli/commands/org-slash.js.map +1 -0
  1041. package/dist/cli/commands/pairing.d.ts +33 -0
  1042. package/dist/cli/commands/pairing.d.ts.map +1 -0
  1043. package/dist/cli/commands/pairing.js +155 -0
  1044. package/dist/cli/commands/pairing.js.map +1 -0
  1045. package/dist/cli/commands/secrets-audit.d.ts +17 -0
  1046. package/dist/cli/commands/secrets-audit.d.ts.map +1 -0
  1047. package/dist/cli/commands/secrets-audit.js +109 -0
  1048. package/dist/cli/commands/secrets-audit.js.map +1 -0
  1049. package/dist/cli/commands/sessions.d.ts +22 -0
  1050. package/dist/cli/commands/sessions.d.ts.map +1 -0
  1051. package/dist/cli/commands/sessions.js +99 -0
  1052. package/dist/cli/commands/sessions.js.map +1 -0
  1053. package/dist/cli/commands/skills.d.ts +17 -0
  1054. package/dist/cli/commands/skills.d.ts.map +1 -0
  1055. package/dist/cli/commands/skills.js +100 -0
  1056. package/dist/cli/commands/skills.js.map +1 -0
  1057. package/dist/cli/commands/status.d.ts +26 -0
  1058. package/dist/cli/commands/status.d.ts.map +1 -0
  1059. package/dist/cli/commands/status.js +252 -0
  1060. package/dist/cli/commands/status.js.map +1 -0
  1061. package/dist/cli/commands/store-cmd.d.ts +36 -0
  1062. package/dist/cli/commands/store-cmd.d.ts.map +1 -0
  1063. package/dist/cli/commands/store-cmd.js +405 -0
  1064. package/dist/cli/commands/store-cmd.js.map +1 -0
  1065. package/dist/cli/flows/web-setup.d.ts +47 -0
  1066. package/dist/cli/flows/web-setup.d.ts.map +1 -0
  1067. package/dist/cli/flows/web-setup.js +324 -0
  1068. package/dist/cli/flows/web-setup.js.map +1 -0
  1069. package/dist/cli/program/build-program.d.ts +3 -0
  1070. package/dist/cli/program/build-program.d.ts.map +1 -0
  1071. package/dist/cli/program/build-program.js +1326 -0
  1072. package/dist/cli/program/build-program.js.map +1 -0
  1073. package/dist/cli/run-main.d.ts +2 -0
  1074. package/dist/cli/run-main.d.ts.map +1 -0
  1075. package/dist/cli/run-main.js +63 -0
  1076. package/dist/cli/run-main.js.map +1 -0
  1077. package/dist/config/agent-limits.d.ts +22 -0
  1078. package/dist/config/agent-limits.d.ts.map +1 -0
  1079. package/dist/config/agent-limits.js +34 -0
  1080. package/dist/config/agent-limits.js.map +1 -0
  1081. package/dist/config/io.d.ts +378 -0
  1082. package/dist/config/io.d.ts.map +1 -0
  1083. package/dist/config/io.js +602 -0
  1084. package/dist/config/io.js.map +1 -0
  1085. package/dist/config/paths.d.ts +80 -0
  1086. package/dist/config/paths.d.ts.map +1 -0
  1087. package/dist/config/paths.js +342 -0
  1088. package/dist/config/paths.js.map +1 -0
  1089. package/dist/config/types.d.ts +12 -0
  1090. package/dist/config/types.d.ts.map +1 -0
  1091. package/dist/config/types.js +12 -0
  1092. package/dist/config/types.js.map +1 -0
  1093. package/dist/core/agent-dispatcher.d.ts +91 -0
  1094. package/dist/core/agent-dispatcher.d.ts.map +1 -0
  1095. package/dist/core/agent-dispatcher.js +251 -0
  1096. package/dist/core/agent-dispatcher.js.map +1 -0
  1097. package/dist/core/agent-events-stream.d.ts +76 -0
  1098. package/dist/core/agent-events-stream.d.ts.map +1 -0
  1099. package/dist/core/agent-events-stream.js +185 -0
  1100. package/dist/core/agent-events-stream.js.map +1 -0
  1101. package/dist/core/agent-runtime-persist.d.ts +53 -0
  1102. package/dist/core/agent-runtime-persist.d.ts.map +1 -0
  1103. package/dist/core/agent-runtime-persist.js +114 -0
  1104. package/dist/core/agent-runtime-persist.js.map +1 -0
  1105. package/dist/core/auth-bridge.d.ts +8 -0
  1106. package/dist/core/auth-bridge.d.ts.map +1 -0
  1107. package/dist/core/auth-bridge.js +102 -0
  1108. package/dist/core/auth-bridge.js.map +1 -0
  1109. package/dist/core/auth-error.d.ts +49 -0
  1110. package/dist/core/auth-error.d.ts.map +1 -0
  1111. package/dist/core/auth-error.js.map +1 -0
  1112. package/dist/core/brigade-config.d.ts +205 -0
  1113. package/dist/core/brigade-config.d.ts.map +1 -0
  1114. package/dist/core/brigade-config.js +58 -6
  1115. package/dist/core/brigade-config.js.map +1 -0
  1116. package/dist/core/config.d.ts +17 -0
  1117. package/dist/core/config.d.ts.map +1 -0
  1118. package/dist/core/config.js +92 -246
  1119. package/dist/core/config.js.map +1 -0
  1120. package/dist/core/console-stream.d.ts +52 -0
  1121. package/dist/core/console-stream.d.ts.map +1 -0
  1122. package/dist/core/console-stream.js +49 -3
  1123. package/dist/core/console-stream.js.map +1 -0
  1124. package/dist/core/daemon/launchd.d.ts +19 -0
  1125. package/dist/core/daemon/launchd.d.ts.map +1 -0
  1126. package/dist/core/daemon/launchd.js +117 -0
  1127. package/dist/core/daemon/launchd.js.map +1 -0
  1128. package/dist/core/daemon/schtasks.d.ts +23 -0
  1129. package/dist/core/daemon/schtasks.d.ts.map +1 -0
  1130. package/dist/core/daemon/schtasks.js +139 -0
  1131. package/dist/core/daemon/schtasks.js.map +1 -0
  1132. package/dist/core/daemon/service.d.ts +56 -0
  1133. package/dist/core/daemon/service.d.ts.map +1 -0
  1134. package/dist/core/daemon/service.js +54 -0
  1135. package/dist/core/daemon/service.js.map +1 -0
  1136. package/dist/core/daemon/systemd.d.ts +19 -0
  1137. package/dist/core/daemon/systemd.d.ts.map +1 -0
  1138. package/dist/core/daemon/systemd.js +117 -0
  1139. package/dist/core/daemon/systemd.js.map +1 -0
  1140. package/dist/core/event-logger.d.ts +74 -0
  1141. package/dist/core/event-logger.d.ts.map +1 -0
  1142. package/dist/core/event-logger.js +299 -6
  1143. package/dist/core/event-logger.js.map +1 -0
  1144. package/dist/core/exec-approvals.d.ts +178 -0
  1145. package/dist/core/exec-approvals.d.ts.map +1 -0
  1146. package/dist/core/exec-approvals.js +591 -266
  1147. package/dist/core/exec-approvals.js.map +1 -0
  1148. package/dist/core/extension-lifecycle.d.ts +27 -0
  1149. package/dist/core/extension-lifecycle.d.ts.map +1 -0
  1150. package/dist/core/extension-lifecycle.js +45 -0
  1151. package/dist/core/extension-lifecycle.js.map +1 -0
  1152. package/dist/core/gateway-caller-impl.d.ts +42 -0
  1153. package/dist/core/gateway-caller-impl.d.ts.map +1 -0
  1154. package/dist/core/gateway-caller-impl.js +95 -0
  1155. package/dist/core/gateway-caller-impl.js.map +1 -0
  1156. package/dist/core/gateway-lock.d.ts +88 -0
  1157. package/dist/core/gateway-lock.d.ts.map +1 -0
  1158. package/dist/core/gateway-lock.js +204 -0
  1159. package/dist/core/gateway-lock.js.map +1 -0
  1160. package/dist/core/gateway-probe.d.ts +148 -0
  1161. package/dist/core/gateway-probe.d.ts.map +1 -0
  1162. package/dist/core/gateway-probe.js +319 -0
  1163. package/dist/core/gateway-probe.js.map +1 -0
  1164. package/dist/core/gateway-spawn.d.ts +40 -0
  1165. package/dist/core/gateway-spawn.d.ts.map +1 -0
  1166. package/dist/core/gateway-spawn.js +156 -0
  1167. package/dist/core/gateway-spawn.js.map +1 -0
  1168. package/dist/core/model-caps.d.ts +85 -0
  1169. package/dist/core/model-caps.d.ts.map +1 -0
  1170. package/dist/core/model-caps.js +88 -2
  1171. package/dist/core/model-caps.js.map +1 -0
  1172. package/dist/core/port-inspect.d.ts +37 -0
  1173. package/dist/core/port-inspect.d.ts.map +1 -0
  1174. package/dist/core/port-inspect.js +165 -0
  1175. package/dist/core/port-inspect.js.map +1 -0
  1176. package/dist/core/server-lanes.d.ts +25 -0
  1177. package/dist/core/server-lanes.d.ts.map +1 -0
  1178. package/dist/core/server-lanes.js +31 -0
  1179. package/dist/core/server-lanes.js.map +1 -0
  1180. package/dist/core/server-methods/cron.d.ts +104 -0
  1181. package/dist/core/server-methods/cron.d.ts.map +1 -0
  1182. package/dist/core/server-methods/cron.js +183 -0
  1183. package/dist/core/server-methods/cron.js.map +1 -0
  1184. package/dist/core/server-methods/health.d.ts +36 -0
  1185. package/dist/core/server-methods/health.d.ts.map +1 -0
  1186. package/dist/core/server-methods/health.js +51 -0
  1187. package/dist/core/server-methods/health.js.map +1 -0
  1188. package/dist/core/server-methods/org.d.ts +93 -0
  1189. package/dist/core/server-methods/org.d.ts.map +1 -0
  1190. package/dist/core/server-methods/org.js +95 -0
  1191. package/dist/core/server-methods/org.js.map +1 -0
  1192. package/dist/core/server-methods/sessions.d.ts +133 -0
  1193. package/dist/core/server-methods/sessions.d.ts.map +1 -0
  1194. package/dist/core/server-methods/sessions.js +209 -0
  1195. package/dist/core/server-methods/sessions.js.map +1 -0
  1196. package/dist/core/server.d.ts +46 -0
  1197. package/dist/core/server.d.ts.map +1 -0
  1198. package/dist/core/server.js +4716 -249
  1199. package/dist/core/server.js.map +1 -0
  1200. package/dist/core/system-prompt.d.ts +92 -0
  1201. package/dist/core/system-prompt.d.ts.map +1 -0
  1202. package/dist/core/system-prompt.js +180 -1584
  1203. package/dist/core/system-prompt.js.map +1 -0
  1204. package/dist/core/version.d.ts +4 -0
  1205. package/dist/core/version.d.ts.map +1 -0
  1206. package/dist/core/version.js +8 -13
  1207. package/dist/core/version.js.map +1 -0
  1208. package/dist/core/webhook-guards.d.ts +131 -0
  1209. package/dist/core/webhook-guards.d.ts.map +1 -0
  1210. package/dist/core/webhook-guards.js +283 -0
  1211. package/dist/core/webhook-guards.js.map +1 -0
  1212. package/dist/core/ws-subscription-filter.d.ts +9 -0
  1213. package/dist/core/ws-subscription-filter.d.ts.map +1 -0
  1214. package/dist/core/ws-subscription-filter.js +39 -0
  1215. package/dist/core/ws-subscription-filter.js.map +1 -0
  1216. package/dist/cron/active-service.d.ts +30 -0
  1217. package/dist/cron/active-service.d.ts.map +1 -0
  1218. package/dist/cron/active-service.js +48 -0
  1219. package/dist/cron/active-service.js.map +1 -0
  1220. package/dist/cron/isolated-agent/run-executor.d.ts +49 -0
  1221. package/dist/cron/isolated-agent/run-executor.d.ts.map +1 -0
  1222. package/dist/cron/isolated-agent/run-executor.js +343 -0
  1223. package/dist/cron/isolated-agent/run-executor.js.map +1 -0
  1224. package/dist/cron/isolated-agent/run.d.ts +27 -0
  1225. package/dist/cron/isolated-agent/run.d.ts.map +1 -0
  1226. package/dist/cron/isolated-agent/run.js +29 -0
  1227. package/dist/cron/isolated-agent/run.js.map +1 -0
  1228. package/dist/cron/normalize.d.ts +103 -0
  1229. package/dist/cron/normalize.d.ts.map +1 -0
  1230. package/dist/cron/normalize.js +376 -0
  1231. package/dist/cron/normalize.js.map +1 -0
  1232. package/dist/cron/parse.d.ts +27 -0
  1233. package/dist/cron/parse.d.ts.map +1 -0
  1234. package/dist/cron/parse.js +55 -0
  1235. package/dist/cron/parse.js.map +1 -0
  1236. package/dist/cron/reminder-context.d.ts +78 -0
  1237. package/dist/cron/reminder-context.d.ts.map +1 -0
  1238. package/dist/cron/reminder-context.js +167 -0
  1239. package/dist/cron/reminder-context.js.map +1 -0
  1240. package/dist/cron/run-log.d.ts +48 -0
  1241. package/dist/cron/run-log.d.ts.map +1 -0
  1242. package/dist/cron/run-log.js +225 -0
  1243. package/dist/cron/run-log.js.map +1 -0
  1244. package/dist/cron/schedule.d.ts +46 -0
  1245. package/dist/cron/schedule.d.ts.map +1 -0
  1246. package/dist/cron/schedule.js +144 -0
  1247. package/dist/cron/schedule.js.map +1 -0
  1248. package/dist/cron/service/jobs.d.ts +138 -0
  1249. package/dist/cron/service/jobs.d.ts.map +1 -0
  1250. package/dist/cron/service/jobs.js +370 -0
  1251. package/dist/cron/service/jobs.js.map +1 -0
  1252. package/dist/cron/service/locked.d.ts +46 -0
  1253. package/dist/cron/service/locked.d.ts.map +1 -0
  1254. package/dist/cron/service/locked.js +54 -0
  1255. package/dist/cron/service/locked.js.map +1 -0
  1256. package/dist/cron/service/ops.d.ts +124 -0
  1257. package/dist/cron/service/ops.d.ts.map +1 -0
  1258. package/dist/cron/service/ops.js +415 -0
  1259. package/dist/cron/service/ops.js.map +1 -0
  1260. package/dist/cron/service/state.d.ts +254 -0
  1261. package/dist/cron/service/state.d.ts.map +1 -0
  1262. package/dist/cron/service/state.js +50 -0
  1263. package/dist/cron/service/state.js.map +1 -0
  1264. package/dist/cron/service/store.d.ts +65 -0
  1265. package/dist/cron/service/store.d.ts.map +1 -0
  1266. package/dist/cron/service/store.js +350 -0
  1267. package/dist/cron/service/store.js.map +1 -0
  1268. package/dist/cron/service/timer.d.ts +113 -0
  1269. package/dist/cron/service/timer.d.ts.map +1 -0
  1270. package/dist/cron/service/timer.js +1081 -0
  1271. package/dist/cron/service/timer.js.map +1 -0
  1272. package/dist/cron/session-reaper.d.ts +62 -0
  1273. package/dist/cron/session-reaper.d.ts.map +1 -0
  1274. package/dist/cron/session-reaper.js +152 -0
  1275. package/dist/cron/session-reaper.js.map +1 -0
  1276. package/dist/cron/session-target.d.ts +56 -0
  1277. package/dist/cron/session-target.d.ts.map +1 -0
  1278. package/dist/cron/session-target.js +96 -0
  1279. package/dist/cron/session-target.js.map +1 -0
  1280. package/dist/cron/stagger.d.ts +34 -0
  1281. package/dist/cron/stagger.d.ts.map +1 -0
  1282. package/dist/cron/stagger.js +69 -0
  1283. package/dist/cron/stagger.js.map +1 -0
  1284. package/dist/cron/types.d.ts +287 -0
  1285. package/dist/cron/types.d.ts.map +1 -0
  1286. package/dist/cron/types.js +22 -0
  1287. package/dist/cron/types.js.map +1 -0
  1288. package/dist/cron/validate-timestamp.d.ts +33 -0
  1289. package/dist/cron/validate-timestamp.d.ts.map +1 -0
  1290. package/dist/cron/validate-timestamp.js +54 -0
  1291. package/dist/cron/validate-timestamp.js.map +1 -0
  1292. package/dist/entry.d.ts +2 -0
  1293. package/dist/entry.d.ts.map +1 -0
  1294. package/dist/entry.js +57 -0
  1295. package/dist/entry.js.map +1 -0
  1296. package/dist/extension-sdk.d.ts +28 -0
  1297. package/dist/extension-sdk.d.ts.map +1 -0
  1298. package/dist/extension-sdk.js +26 -0
  1299. package/dist/extension-sdk.js.map +1 -0
  1300. package/dist/identity/device.d.ts +19 -0
  1301. package/dist/identity/device.d.ts.map +1 -0
  1302. package/dist/identity/device.js +88 -0
  1303. package/dist/identity/device.js.map +1 -0
  1304. package/dist/infra/backoff.d.ts +24 -0
  1305. package/dist/infra/backoff.d.ts.map +1 -0
  1306. package/dist/infra/backoff.js +48 -0
  1307. package/dist/infra/backoff.js.map +1 -0
  1308. package/dist/infra/errors.d.ts +35 -0
  1309. package/dist/infra/errors.d.ts.map +1 -0
  1310. package/dist/infra/errors.js +54 -0
  1311. package/dist/infra/errors.js.map +1 -0
  1312. package/dist/infra/fs/atomic-rename.d.ts +31 -0
  1313. package/dist/infra/fs/atomic-rename.d.ts.map +1 -0
  1314. package/dist/infra/fs/atomic-rename.js +75 -0
  1315. package/dist/infra/fs/atomic-rename.js.map +1 -0
  1316. package/dist/infra/json-file.d.ts +25 -0
  1317. package/dist/infra/json-file.d.ts.map +1 -0
  1318. package/dist/infra/json-file.js +49 -0
  1319. package/dist/infra/json-file.js.map +1 -0
  1320. package/dist/infra/json-utf8-bytes.d.ts +14 -0
  1321. package/dist/infra/json-utf8-bytes.d.ts.map +1 -0
  1322. package/dist/infra/json-utf8-bytes.js +20 -0
  1323. package/dist/infra/json-utf8-bytes.js.map +1 -0
  1324. package/dist/infra/net/dns-pinning.d.ts +66 -0
  1325. package/dist/infra/net/dns-pinning.d.ts.map +1 -0
  1326. package/dist/infra/net/dns-pinning.js +128 -0
  1327. package/dist/infra/net/dns-pinning.js.map +1 -0
  1328. package/dist/infra/net/fetch-guard.d.ts +85 -0
  1329. package/dist/infra/net/fetch-guard.d.ts.map +1 -0
  1330. package/dist/infra/net/fetch-guard.js +439 -0
  1331. package/dist/infra/net/fetch-guard.js.map +1 -0
  1332. package/dist/infra/prototype-keys.d.ts +19 -0
  1333. package/dist/infra/prototype-keys.d.ts.map +1 -0
  1334. package/dist/infra/prototype-keys.js +22 -0
  1335. package/dist/infra/prototype-keys.js.map +1 -0
  1336. package/dist/integrations/ollama.d.ts +67 -0
  1337. package/dist/integrations/ollama.d.ts.map +1 -0
  1338. package/dist/integrations/ollama.js +53 -0
  1339. package/dist/integrations/ollama.js.map +1 -0
  1340. package/dist/integrations/provider-discovery.d.ts +66 -0
  1341. package/dist/integrations/provider-discovery.d.ts.map +1 -0
  1342. package/dist/integrations/provider-discovery.js +166 -0
  1343. package/dist/integrations/provider-discovery.js.map +1 -0
  1344. package/dist/logging/redact.d.ts +28 -0
  1345. package/dist/logging/redact.d.ts.map +1 -0
  1346. package/dist/logging/redact.js +51 -0
  1347. package/dist/logging/redact.js.map +1 -0
  1348. package/dist/logging/subsystem-logger.d.ts +77 -0
  1349. package/dist/logging/subsystem-logger.d.ts.map +1 -0
  1350. package/dist/logging/subsystem-logger.js +577 -0
  1351. package/dist/logging/subsystem-logger.js.map +1 -0
  1352. package/dist/logging/subsystem.d.ts +13 -0
  1353. package/dist/logging/subsystem.d.ts.map +1 -0
  1354. package/dist/logging/subsystem.js +12 -0
  1355. package/dist/logging/subsystem.js.map +1 -0
  1356. package/dist/process/command-queue.d.ts +152 -0
  1357. package/dist/process/command-queue.d.ts.map +1 -0
  1358. package/dist/process/command-queue.js +420 -0
  1359. package/dist/process/command-queue.js.map +1 -0
  1360. package/dist/process/lanes.d.ts +102 -0
  1361. package/dist/process/lanes.d.ts.map +1 -0
  1362. package/dist/process/lanes.js +117 -0
  1363. package/dist/process/lanes.js.map +1 -0
  1364. package/dist/process/session-lane.d.ts +31 -0
  1365. package/dist/process/session-lane.d.ts.map +1 -0
  1366. package/dist/process/session-lane.js +45 -0
  1367. package/dist/process/session-lane.js.map +1 -0
  1368. package/dist/protocol/errors.d.ts +35 -0
  1369. package/dist/protocol/errors.d.ts.map +1 -0
  1370. package/dist/protocol/errors.js +36 -0
  1371. package/dist/protocol/errors.js.map +1 -0
  1372. package/dist/protocol/handshake.d.ts +101 -0
  1373. package/dist/protocol/handshake.d.ts.map +1 -0
  1374. package/dist/protocol/handshake.js +49 -0
  1375. package/dist/protocol/handshake.js.map +1 -0
  1376. package/dist/protocol/messages.d.ts +68 -0
  1377. package/dist/protocol/messages.d.ts.map +1 -0
  1378. package/dist/protocol/messages.js +20 -0
  1379. package/dist/protocol/messages.js.map +1 -0
  1380. package/dist/protocol/methods.d.ts +312 -0
  1381. package/dist/protocol/methods.d.ts.map +1 -0
  1382. package/dist/protocol/methods.js +16 -0
  1383. package/dist/protocol/methods.js.map +1 -0
  1384. package/dist/protocol.d.ts +598 -0
  1385. package/dist/protocol.d.ts.map +1 -0
  1386. package/dist/protocol.js +12 -0
  1387. package/dist/protocol.js.map +1 -0
  1388. package/dist/providers/auth-methods.d.ts +82 -0
  1389. package/dist/providers/auth-methods.d.ts.map +1 -0
  1390. package/dist/providers/auth-methods.js +180 -0
  1391. package/dist/providers/auth-methods.js.map +1 -0
  1392. package/dist/providers/catalog.d.ts +85 -0
  1393. package/dist/providers/catalog.d.ts.map +1 -0
  1394. package/dist/providers/catalog.js +41 -0
  1395. package/dist/providers/catalog.js.map +1 -0
  1396. package/dist/providers/validate-key.d.ts +42 -0
  1397. package/dist/providers/validate-key.d.ts.map +1 -0
  1398. package/dist/providers/validate-key.js.map +1 -0
  1399. package/dist/security/external-content.d.ts +67 -0
  1400. package/dist/security/external-content.d.ts.map +1 -0
  1401. package/dist/security/external-content.js +80 -0
  1402. package/dist/security/external-content.js.map +1 -0
  1403. package/dist/security/injection-patterns.d.ts +33 -0
  1404. package/dist/security/injection-patterns.d.ts.map +1 -0
  1405. package/dist/security/injection-patterns.js +97 -0
  1406. package/dist/security/injection-patterns.js.map +1 -0
  1407. package/dist/security/media-path-guard.d.ts +25 -0
  1408. package/dist/security/media-path-guard.d.ts.map +1 -0
  1409. package/dist/security/media-path-guard.js +98 -0
  1410. package/dist/security/media-path-guard.js.map +1 -0
  1411. package/dist/security/terminal-input-sanitizer.d.ts +30 -0
  1412. package/dist/security/terminal-input-sanitizer.d.ts.map +1 -0
  1413. package/dist/security/terminal-input-sanitizer.js +70 -0
  1414. package/dist/security/terminal-input-sanitizer.js.map +1 -0
  1415. package/dist/sessions/bootstrap-marker.d.ts +5 -0
  1416. package/dist/sessions/bootstrap-marker.d.ts.map +1 -0
  1417. package/dist/sessions/bootstrap-marker.js +120 -0
  1418. package/dist/sessions/bootstrap-marker.js.map +1 -0
  1419. package/dist/sessions/session-file-repair.d.ts +12 -0
  1420. package/dist/sessions/session-file-repair.d.ts.map +1 -0
  1421. package/dist/sessions/session-file-repair.js +155 -0
  1422. package/dist/sessions/session-file-repair.js.map +1 -0
  1423. package/dist/sessions/session-key-utils.d.ts +54 -0
  1424. package/dist/sessions/session-key-utils.d.ts.map +1 -0
  1425. package/dist/sessions/session-key-utils.js +133 -0
  1426. package/dist/sessions/session-key-utils.js.map +1 -0
  1427. package/dist/sessions/session-manager-factory.d.ts +21 -0
  1428. package/dist/sessions/session-manager-factory.d.ts.map +1 -0
  1429. package/dist/sessions/session-manager-factory.js +142 -0
  1430. package/dist/sessions/session-manager-factory.js.map +1 -0
  1431. package/dist/sessions/session-store.d.ts +154 -0
  1432. package/dist/sessions/session-store.d.ts.map +1 -0
  1433. package/dist/sessions/session-store.js +498 -0
  1434. package/dist/sessions/session-store.js.map +1 -0
  1435. package/dist/sessions/session-write-lock.d.ts +10 -0
  1436. package/dist/sessions/session-write-lock.d.ts.map +1 -0
  1437. package/dist/sessions/session-write-lock.js +167 -0
  1438. package/dist/sessions/session-write-lock.js.map +1 -0
  1439. package/dist/sessions/transcript-reader.d.ts +37 -0
  1440. package/dist/sessions/transcript-reader.d.ts.map +1 -0
  1441. package/dist/sessions/transcript-reader.js +136 -0
  1442. package/dist/sessions/transcript-reader.js.map +1 -0
  1443. package/dist/sessions/transcript-repair.d.ts +16 -0
  1444. package/dist/sessions/transcript-repair.d.ts.map +1 -0
  1445. package/dist/sessions/transcript-repair.js +214 -0
  1446. package/dist/sessions/transcript-repair.js.map +1 -0
  1447. package/dist/shared/global-singleton.d.ts +27 -0
  1448. package/dist/shared/global-singleton.d.ts.map +1 -0
  1449. package/dist/shared/global-singleton.js +35 -0
  1450. package/dist/shared/global-singleton.js.map +1 -0
  1451. package/dist/shared/string-coerce.d.ts +12 -0
  1452. package/dist/shared/string-coerce.d.ts.map +1 -0
  1453. package/dist/shared/string-coerce.js +12 -0
  1454. package/dist/shared/string-coerce.js.map +1 -0
  1455. package/dist/storage/boot.d.ts +28 -0
  1456. package/dist/storage/boot.d.ts.map +1 -0
  1457. package/dist/storage/boot.js +588 -0
  1458. package/dist/storage/boot.js.map +1 -0
  1459. package/dist/storage/config-cache.d.ts +23 -0
  1460. package/dist/storage/config-cache.d.ts.map +1 -0
  1461. package/dist/storage/config-cache.js +58 -0
  1462. package/dist/storage/config-cache.js.map +1 -0
  1463. package/dist/storage/convex/auth-store.d.ts +52 -0
  1464. package/dist/storage/convex/auth-store.d.ts.map +1 -0
  1465. package/dist/storage/convex/auth-store.js +282 -0
  1466. package/dist/storage/convex/auth-store.js.map +1 -0
  1467. package/dist/storage/convex/blob-store.d.ts +20 -0
  1468. package/dist/storage/convex/blob-store.d.ts.map +1 -0
  1469. package/dist/storage/convex/blob-store.js +74 -0
  1470. package/dist/storage/convex/blob-store.js.map +1 -0
  1471. package/dist/storage/convex/channel-store.d.ts +112 -0
  1472. package/dist/storage/convex/channel-store.d.ts.map +1 -0
  1473. package/dist/storage/convex/channel-store.js +267 -0
  1474. package/dist/storage/convex/channel-store.js.map +1 -0
  1475. package/dist/storage/convex/client.d.ts +53 -0
  1476. package/dist/storage/convex/client.d.ts.map +1 -0
  1477. package/dist/storage/convex/client.js +121 -0
  1478. package/dist/storage/convex/client.js.map +1 -0
  1479. package/dist/storage/convex/config-store.d.ts +29 -0
  1480. package/dist/storage/convex/config-store.d.ts.map +1 -0
  1481. package/dist/storage/convex/config-store.js +205 -0
  1482. package/dist/storage/convex/config-store.js.map +1 -0
  1483. package/dist/storage/convex/cron-store.d.ts +86 -0
  1484. package/dist/storage/convex/cron-store.d.ts.map +1 -0
  1485. package/dist/storage/convex/cron-store.js +428 -0
  1486. package/dist/storage/convex/cron-store.js.map +1 -0
  1487. package/dist/storage/convex/exec-approval-store.d.ts +38 -0
  1488. package/dist/storage/convex/exec-approval-store.d.ts.map +1 -0
  1489. package/dist/storage/convex/exec-approval-store.js +147 -0
  1490. package/dist/storage/convex/exec-approval-store.js.map +1 -0
  1491. package/dist/storage/convex/extension-store.d.ts +28 -0
  1492. package/dist/storage/convex/extension-store.d.ts.map +1 -0
  1493. package/dist/storage/convex/extension-store.js +39 -0
  1494. package/dist/storage/convex/extension-store.js.map +1 -0
  1495. package/dist/storage/convex/index.d.ts +35 -0
  1496. package/dist/storage/convex/index.d.ts.map +1 -0
  1497. package/dist/storage/convex/index.js +141 -0
  1498. package/dist/storage/convex/index.js.map +1 -0
  1499. package/dist/storage/convex/instance-store.d.ts +37 -0
  1500. package/dist/storage/convex/instance-store.d.ts.map +1 -0
  1501. package/dist/storage/convex/instance-store.js +88 -0
  1502. package/dist/storage/convex/instance-store.js.map +1 -0
  1503. package/dist/storage/convex/log-store.d.ts +36 -0
  1504. package/dist/storage/convex/log-store.d.ts.map +1 -0
  1505. package/dist/storage/convex/log-store.js +213 -0
  1506. package/dist/storage/convex/log-store.js.map +1 -0
  1507. package/dist/storage/convex/memory-store.d.ts +50 -0
  1508. package/dist/storage/convex/memory-store.d.ts.map +1 -0
  1509. package/dist/storage/convex/memory-store.js +537 -0
  1510. package/dist/storage/convex/memory-store.js.map +1 -0
  1511. package/dist/storage/convex/message-store.d.ts +32 -0
  1512. package/dist/storage/convex/message-store.d.ts.map +1 -0
  1513. package/dist/storage/convex/message-store.js +272 -0
  1514. package/dist/storage/convex/message-store.js.map +1 -0
  1515. package/dist/storage/convex/org-store.d.ts +46 -0
  1516. package/dist/storage/convex/org-store.d.ts.map +1 -0
  1517. package/dist/storage/convex/org-store.js +101 -0
  1518. package/dist/storage/convex/org-store.js.map +1 -0
  1519. package/dist/storage/convex/session-store.d.ts +44 -0
  1520. package/dist/storage/convex/session-store.d.ts.map +1 -0
  1521. package/dist/storage/convex/session-store.js +257 -0
  1522. package/dist/storage/convex/session-store.js.map +1 -0
  1523. package/dist/storage/convex/skill-store.d.ts +49 -0
  1524. package/dist/storage/convex/skill-store.d.ts.map +1 -0
  1525. package/dist/storage/convex/skill-store.js +84 -0
  1526. package/dist/storage/convex/skill-store.js.map +1 -0
  1527. package/dist/storage/convex/subagent-store.d.ts +28 -0
  1528. package/dist/storage/convex/subagent-store.d.ts.map +1 -0
  1529. package/dist/storage/convex/subagent-store.js +83 -0
  1530. package/dist/storage/convex/subagent-store.js.map +1 -0
  1531. package/dist/storage/convex/workspace-store.d.ts +25 -0
  1532. package/dist/storage/convex/workspace-store.d.ts.map +1 -0
  1533. package/dist/storage/convex/workspace-store.js +127 -0
  1534. package/dist/storage/convex/workspace-store.js.map +1 -0
  1535. package/dist/storage/cron-cache.d.ts +17 -0
  1536. package/dist/storage/cron-cache.d.ts.map +1 -0
  1537. package/dist/storage/cron-cache.js +67 -0
  1538. package/dist/storage/cron-cache.js.map +1 -0
  1539. package/dist/storage/encryption.d.ts +69 -0
  1540. package/dist/storage/encryption.d.ts.map +1 -0
  1541. package/dist/storage/encryption.js +389 -0
  1542. package/dist/storage/encryption.js.map +1 -0
  1543. package/dist/storage/factory-reset.d.ts +7 -0
  1544. package/dist/storage/factory-reset.d.ts.map +1 -0
  1545. package/dist/storage/factory-reset.js +34 -0
  1546. package/dist/storage/factory-reset.js.map +1 -0
  1547. package/dist/storage/facts-cache.d.ts +24 -0
  1548. package/dist/storage/facts-cache.d.ts.map +1 -0
  1549. package/dist/storage/facts-cache.js +110 -0
  1550. package/dist/storage/facts-cache.js.map +1 -0
  1551. package/dist/storage/flush.d.ts +4 -0
  1552. package/dist/storage/flush.d.ts.map +1 -0
  1553. package/dist/storage/flush.js +128 -0
  1554. package/dist/storage/flush.js.map +1 -0
  1555. package/dist/storage/instance-admin.d.ts +52 -0
  1556. package/dist/storage/instance-admin.d.ts.map +1 -0
  1557. package/dist/storage/instance-admin.js +90 -0
  1558. package/dist/storage/instance-admin.js.map +1 -0
  1559. package/dist/storage/local/auth-store.d.ts +44 -0
  1560. package/dist/storage/local/auth-store.d.ts.map +1 -0
  1561. package/dist/storage/local/auth-store.js +252 -0
  1562. package/dist/storage/local/auth-store.js.map +1 -0
  1563. package/dist/storage/local/blob-store.d.ts +14 -0
  1564. package/dist/storage/local/blob-store.d.ts.map +1 -0
  1565. package/dist/storage/local/blob-store.js +87 -0
  1566. package/dist/storage/local/blob-store.js.map +1 -0
  1567. package/dist/storage/local/channel-store.d.ts +107 -0
  1568. package/dist/storage/local/channel-store.d.ts.map +1 -0
  1569. package/dist/storage/local/channel-store.js +147 -0
  1570. package/dist/storage/local/channel-store.js.map +1 -0
  1571. package/dist/storage/local/config-store.d.ts +23 -0
  1572. package/dist/storage/local/config-store.d.ts.map +1 -0
  1573. package/dist/storage/local/config-store.js +98 -0
  1574. package/dist/storage/local/config-store.js.map +1 -0
  1575. package/dist/storage/local/cron-store.d.ts +30 -0
  1576. package/dist/storage/local/cron-store.d.ts.map +1 -0
  1577. package/dist/storage/local/cron-store.js +186 -0
  1578. package/dist/storage/local/cron-store.js.map +1 -0
  1579. package/dist/storage/local/exec-approval-store.d.ts +41 -0
  1580. package/dist/storage/local/exec-approval-store.d.ts.map +1 -0
  1581. package/dist/storage/local/exec-approval-store.js +78 -0
  1582. package/dist/storage/local/exec-approval-store.js.map +1 -0
  1583. package/dist/storage/local/extension-store.d.ts +13 -0
  1584. package/dist/storage/local/extension-store.d.ts.map +1 -0
  1585. package/dist/storage/local/extension-store.js +36 -0
  1586. package/dist/storage/local/extension-store.js.map +1 -0
  1587. package/dist/storage/local/file-watcher.d.ts +24 -0
  1588. package/dist/storage/local/file-watcher.d.ts.map +1 -0
  1589. package/dist/storage/local/file-watcher.js +141 -0
  1590. package/dist/storage/local/file-watcher.js.map +1 -0
  1591. package/dist/storage/local/index.d.ts +33 -0
  1592. package/dist/storage/local/index.d.ts.map +1 -0
  1593. package/dist/storage/local/index.js +143 -0
  1594. package/dist/storage/local/index.js.map +1 -0
  1595. package/dist/storage/local/instance-store.d.ts +30 -0
  1596. package/dist/storage/local/instance-store.d.ts.map +1 -0
  1597. package/dist/storage/local/instance-store.js +83 -0
  1598. package/dist/storage/local/instance-store.js.map +1 -0
  1599. package/dist/storage/local/log-store.d.ts +27 -0
  1600. package/dist/storage/local/log-store.d.ts.map +1 -0
  1601. package/dist/storage/local/log-store.js +185 -0
  1602. package/dist/storage/local/log-store.js.map +1 -0
  1603. package/dist/storage/local/memory-store.d.ts +39 -0
  1604. package/dist/storage/local/memory-store.d.ts.map +1 -0
  1605. package/dist/storage/local/memory-store.js +258 -0
  1606. package/dist/storage/local/memory-store.js.map +1 -0
  1607. package/dist/storage/local/message-store.d.ts +27 -0
  1608. package/dist/storage/local/message-store.d.ts.map +1 -0
  1609. package/dist/storage/local/message-store.js +253 -0
  1610. package/dist/storage/local/message-store.js.map +1 -0
  1611. package/dist/storage/local/org-store.d.ts +39 -0
  1612. package/dist/storage/local/org-store.d.ts.map +1 -0
  1613. package/dist/storage/local/org-store.js +155 -0
  1614. package/dist/storage/local/org-store.js.map +1 -0
  1615. package/dist/storage/local/session-store.d.ts +30 -0
  1616. package/dist/storage/local/session-store.d.ts.map +1 -0
  1617. package/dist/storage/local/session-store.js +82 -0
  1618. package/dist/storage/local/session-store.js.map +1 -0
  1619. package/dist/storage/local/skill-store.d.ts +40 -0
  1620. package/dist/storage/local/skill-store.d.ts.map +1 -0
  1621. package/dist/storage/local/skill-store.js +121 -0
  1622. package/dist/storage/local/skill-store.js.map +1 -0
  1623. package/dist/storage/local/subagent-store.d.ts +20 -0
  1624. package/dist/storage/local/subagent-store.d.ts.map +1 -0
  1625. package/dist/storage/local/subagent-store.js +71 -0
  1626. package/dist/storage/local/subagent-store.js.map +1 -0
  1627. package/dist/storage/local/workspace-store.d.ts +22 -0
  1628. package/dist/storage/local/workspace-store.d.ts.map +1 -0
  1629. package/dist/storage/local/workspace-store.js +190 -0
  1630. package/dist/storage/local/workspace-store.js.map +1 -0
  1631. package/dist/storage/migrate.d.ts +64 -0
  1632. package/dist/storage/migrate.d.ts.map +1 -0
  1633. package/dist/storage/migrate.js +581 -0
  1634. package/dist/storage/migrate.js.map +1 -0
  1635. package/dist/storage/runtime-context.d.ts +35 -0
  1636. package/dist/storage/runtime-context.d.ts.map +1 -0
  1637. package/dist/storage/runtime-context.js +145 -0
  1638. package/dist/storage/runtime-context.js.map +1 -0
  1639. package/dist/storage/sentinel.d.ts +28 -0
  1640. package/dist/storage/sentinel.d.ts.map +1 -0
  1641. package/dist/storage/sentinel.js +98 -0
  1642. package/dist/storage/sentinel.js.map +1 -0
  1643. package/dist/storage/session-cache.d.ts +15 -0
  1644. package/dist/storage/session-cache.d.ts.map +1 -0
  1645. package/dist/storage/session-cache.js +81 -0
  1646. package/dist/storage/session-cache.js.map +1 -0
  1647. package/dist/storage/store.d.ts +745 -0
  1648. package/dist/storage/store.d.ts.map +1 -0
  1649. package/dist/storage/store.js +36 -0
  1650. package/dist/storage/store.js.map +1 -0
  1651. package/dist/storage/strict-guard.d.ts +17 -0
  1652. package/dist/storage/strict-guard.d.ts.map +1 -0
  1653. package/dist/storage/strict-guard.js +200 -0
  1654. package/dist/storage/strict-guard.js.map +1 -0
  1655. package/dist/storage/workspace-live-mirror.d.ts +33 -0
  1656. package/dist/storage/workspace-live-mirror.d.ts.map +1 -0
  1657. package/dist/storage/workspace-live-mirror.js +207 -0
  1658. package/dist/storage/workspace-live-mirror.js.map +1 -0
  1659. package/dist/system-prompt/assembler.d.ts +113 -0
  1660. package/dist/system-prompt/assembler.d.ts.map +1 -0
  1661. package/dist/system-prompt/assembler.js +649 -0
  1662. package/dist/system-prompt/assembler.js.map +1 -0
  1663. package/dist/system-prompt/bootstrap-budget.d.ts +22 -0
  1664. package/dist/system-prompt/bootstrap-budget.d.ts.map +1 -0
  1665. package/dist/system-prompt/bootstrap-budget.js +83 -0
  1666. package/dist/system-prompt/bootstrap-budget.js.map +1 -0
  1667. package/dist/system-prompt/cache-boundary.d.ts +13 -0
  1668. package/dist/system-prompt/cache-boundary.d.ts.map +1 -0
  1669. package/dist/system-prompt/cache-boundary.js +56 -0
  1670. package/dist/system-prompt/cache-boundary.js.map +1 -0
  1671. package/dist/system-prompt/cache-stability.d.ts +3 -0
  1672. package/dist/system-prompt/cache-stability.d.ts.map +1 -0
  1673. package/dist/system-prompt/cache-stability.js +18 -0
  1674. package/dist/system-prompt/cache-stability.js.map +1 -0
  1675. package/dist/system-prompt/guidance.d.ts +147 -0
  1676. package/dist/system-prompt/guidance.d.ts.map +1 -0
  1677. package/dist/system-prompt/guidance.js +352 -0
  1678. package/dist/system-prompt/guidance.js.map +1 -0
  1679. package/dist/system-prompt/identity-defaults.d.ts +50 -0
  1680. package/dist/system-prompt/identity-defaults.d.ts.map +1 -0
  1681. package/dist/system-prompt/identity-defaults.js +119 -0
  1682. package/dist/system-prompt/identity-defaults.js.map +1 -0
  1683. package/dist/system-prompt/org/escalation-inbox.d.ts +53 -0
  1684. package/dist/system-prompt/org/escalation-inbox.d.ts.map +1 -0
  1685. package/dist/system-prompt/org/escalation-inbox.js +71 -0
  1686. package/dist/system-prompt/org/escalation-inbox.js.map +1 -0
  1687. package/dist/system-prompt/org/receiver-hint.d.ts +72 -0
  1688. package/dist/system-prompt/org/receiver-hint.d.ts.map +1 -0
  1689. package/dist/system-prompt/org/receiver-hint.js +116 -0
  1690. package/dist/system-prompt/org/receiver-hint.js.map +1 -0
  1691. package/dist/system-prompt/org/render-org-block.d.ts +42 -0
  1692. package/dist/system-prompt/org/render-org-block.d.ts.map +1 -0
  1693. package/dist/system-prompt/org/render-org-block.js +57 -0
  1694. package/dist/system-prompt/org/render-org-block.js.map +1 -0
  1695. package/dist/system-prompt/org/sub-agent-anchor.d.ts +30 -0
  1696. package/dist/system-prompt/org/sub-agent-anchor.d.ts.map +1 -0
  1697. package/dist/system-prompt/org/sub-agent-anchor.js +36 -0
  1698. package/dist/system-prompt/org/sub-agent-anchor.js.map +1 -0
  1699. package/dist/system-prompt/override.d.ts +7 -0
  1700. package/dist/system-prompt/override.d.ts.map +1 -0
  1701. package/dist/system-prompt/override.js +13 -0
  1702. package/dist/system-prompt/override.js.map +1 -0
  1703. package/dist/system-prompt/pi-injection.d.ts +5 -0
  1704. package/dist/system-prompt/pi-injection.d.ts.map +1 -0
  1705. package/dist/system-prompt/pi-injection.js +33 -0
  1706. package/dist/system-prompt/pi-injection.js.map +1 -0
  1707. package/dist/system-prompt/runtime-params.d.ts +34 -0
  1708. package/dist/system-prompt/runtime-params.d.ts.map +1 -0
  1709. package/dist/system-prompt/runtime-params.js +108 -0
  1710. package/dist/system-prompt/runtime-params.js.map +1 -0
  1711. package/dist/system-prompt/sanitize.d.ts +7 -0
  1712. package/dist/system-prompt/sanitize.d.ts.map +1 -0
  1713. package/dist/system-prompt/sanitize.js +31 -0
  1714. package/dist/system-prompt/sanitize.js.map +1 -0
  1715. package/dist/system-prompt/types.d.ts +7 -0
  1716. package/dist/system-prompt/types.d.ts.map +1 -0
  1717. package/dist/system-prompt/types.js +3 -0
  1718. package/dist/system-prompt/types.js.map +1 -0
  1719. package/dist/system-prompt/workspace-loader.d.ts +12 -0
  1720. package/dist/system-prompt/workspace-loader.d.ts.map +1 -0
  1721. package/dist/system-prompt/workspace-loader.js +115 -0
  1722. package/dist/system-prompt/workspace-loader.js.map +1 -0
  1723. package/dist/tideline/advanced.d.ts +25 -0
  1724. package/dist/tideline/advanced.d.ts.map +1 -0
  1725. package/dist/tideline/advanced.js +34 -0
  1726. package/dist/tideline/advanced.js.map +1 -0
  1727. package/dist/tideline/eval.d.ts +19 -0
  1728. package/dist/tideline/eval.d.ts.map +1 -0
  1729. package/dist/tideline/eval.js +24 -0
  1730. package/dist/tideline/eval.js.map +1 -0
  1731. package/dist/tideline/host-ports.standalone.d.ts +49 -0
  1732. package/dist/tideline/host-ports.standalone.d.ts.map +1 -0
  1733. package/dist/tideline/host-ports.standalone.js +61 -0
  1734. package/dist/tideline/host-ports.standalone.js.map +1 -0
  1735. package/dist/tideline/index.d.ts +34 -0
  1736. package/dist/tideline/index.d.ts.map +1 -0
  1737. package/dist/tideline/index.js +42 -0
  1738. package/dist/tideline/index.js.map +1 -0
  1739. package/dist/tui/approval-prompt.d.ts +73 -0
  1740. package/dist/tui/approval-prompt.d.ts.map +1 -0
  1741. package/dist/tui/approval-prompt.js +272 -0
  1742. package/dist/tui/approval-prompt.js.map +1 -0
  1743. package/dist/tui/client.d.ts +89 -0
  1744. package/dist/tui/client.d.ts.map +1 -0
  1745. package/dist/tui/client.js.map +1 -0
  1746. package/dist/ui/brand-frames-cli.d.ts +19 -0
  1747. package/dist/ui/brand-frames-cli.d.ts.map +1 -0
  1748. package/dist/ui/brand-frames-cli.js +8 -13
  1749. package/dist/ui/brand-frames-cli.js.map +1 -0
  1750. package/dist/ui/brand.d.ts +41 -0
  1751. package/dist/ui/brand.d.ts.map +1 -0
  1752. package/dist/ui/brand.js +28 -6
  1753. package/dist/ui/brand.js.map +1 -0
  1754. package/dist/ui/editor.d.ts +30 -0
  1755. package/dist/ui/editor.d.ts.map +1 -0
  1756. package/dist/ui/editor.js +73 -0
  1757. package/dist/ui/editor.js.map +1 -0
  1758. package/dist/ui/format-session.d.ts +68 -0
  1759. package/dist/ui/format-session.d.ts.map +1 -0
  1760. package/dist/ui/format-session.js +181 -0
  1761. package/dist/ui/format-session.js.map +1 -0
  1762. package/dist/ui/markdown.d.ts +48 -0
  1763. package/dist/ui/markdown.d.ts.map +1 -0
  1764. package/dist/ui/markdown.js +60 -0
  1765. package/dist/ui/markdown.js.map +1 -0
  1766. package/dist/ui/onboard-storage-mode.d.ts +17 -0
  1767. package/dist/ui/onboard-storage-mode.d.ts.map +1 -0
  1768. package/dist/ui/onboard-storage-mode.js +638 -0
  1769. package/dist/ui/onboard-storage-mode.js.map +1 -0
  1770. package/dist/ui/onboarding.d.ts +97 -0
  1771. package/dist/ui/onboarding.d.ts.map +1 -0
  1772. package/dist/ui/onboarding.js +259 -111
  1773. package/dist/ui/onboarding.js.map +1 -0
  1774. package/dist/ui/searchable-select.d.ts +48 -0
  1775. package/dist/ui/searchable-select.d.ts.map +1 -0
  1776. package/dist/ui/searchable-select.js +108 -0
  1777. package/dist/ui/searchable-select.js.map +1 -0
  1778. package/dist/ui/syntax-theme.d.ts +30 -0
  1779. package/dist/ui/syntax-theme.d.ts.map +1 -0
  1780. package/dist/ui/syntax-theme.js +72 -0
  1781. package/dist/ui/syntax-theme.js.map +1 -0
  1782. package/dist/ui/terminal-cleanup.d.ts +46 -0
  1783. package/dist/ui/terminal-cleanup.d.ts.map +1 -0
  1784. package/dist/ui/terminal-cleanup.js +17 -5
  1785. package/dist/ui/terminal-cleanup.js.map +1 -0
  1786. package/dist/ui/theme.d.ts +21 -0
  1787. package/dist/ui/theme.d.ts.map +1 -0
  1788. package/dist/ui/theme.js +66 -2
  1789. package/dist/ui/theme.js.map +1 -0
  1790. package/dist/ui/tool-result.d.ts +47 -0
  1791. package/dist/ui/tool-result.d.ts.map +1 -0
  1792. package/dist/ui/tool-result.js +100 -0
  1793. package/dist/ui/tool-result.js.map +1 -0
  1794. package/dist/utils/delivery-context.d.ts +50 -0
  1795. package/dist/utils/delivery-context.d.ts.map +1 -0
  1796. package/dist/utils/delivery-context.js +82 -0
  1797. package/dist/utils/delivery-context.js.map +1 -0
  1798. package/dist/utils/message-channel.d.ts +60 -0
  1799. package/dist/utils/message-channel.d.ts.map +1 -0
  1800. package/dist/utils/message-channel.js +103 -0
  1801. package/dist/utils/message-channel.js.map +1 -0
  1802. package/dist/utils/string-coerce.d.ts +50 -0
  1803. package/dist/utils/string-coerce.d.ts.map +1 -0
  1804. package/dist/utils/string-coerce.js +101 -0
  1805. package/dist/utils/string-coerce.js.map +1 -0
  1806. package/dist/version.d.ts +20 -0
  1807. package/dist/version.d.ts.map +1 -0
  1808. package/dist/version.js +54 -0
  1809. package/dist/version.js.map +1 -0
  1810. package/dist/workspace/bootstrap.d.ts +12 -0
  1811. package/dist/workspace/bootstrap.d.ts.map +1 -0
  1812. package/dist/workspace/bootstrap.js +123 -0
  1813. package/dist/workspace/bootstrap.js.map +1 -0
  1814. package/dist/workspace/fs-utils.d.ts +2 -0
  1815. package/dist/workspace/fs-utils.d.ts.map +1 -0
  1816. package/dist/workspace/fs-utils.js +14 -0
  1817. package/dist/workspace/fs-utils.js.map +1 -0
  1818. package/dist/workspace/git-init.d.ts +5 -0
  1819. package/dist/workspace/git-init.d.ts.map +1 -0
  1820. package/dist/workspace/git-init.js +71 -0
  1821. package/dist/workspace/git-init.js.map +1 -0
  1822. package/dist/workspace/state.d.ts +13 -0
  1823. package/dist/workspace/state.d.ts.map +1 -0
  1824. package/dist/workspace/state.js +128 -0
  1825. package/dist/workspace/state.js.map +1 -0
  1826. package/dist/workspace/template-loader.d.ts +15 -0
  1827. package/dist/workspace/template-loader.d.ts.map +1 -0
  1828. package/dist/workspace/template-loader.js +214 -0
  1829. package/dist/workspace/template-loader.js.map +1 -0
  1830. package/package.json +173 -68
  1831. package/scripts/build-done.mjs +125 -0
  1832. package/scripts/run-brigade.mjs +208 -0
  1833. package/skills/1password/SKILL.md +70 -0
  1834. package/skills/1password/references/cli-examples.md +29 -0
  1835. package/skills/1password/references/get-started.md +17 -0
  1836. package/skills/apple-notes/SKILL.md +77 -0
  1837. package/skills/apple-reminders/SKILL.md +118 -0
  1838. package/skills/bear-notes/SKILL.md +107 -0
  1839. package/skills/blogwatcher/SKILL.md +69 -0
  1840. package/skills/blucli/SKILL.md +47 -0
  1841. package/skills/bluebubbles/SKILL.md +136 -0
  1842. package/skills/camsnap/SKILL.md +45 -0
  1843. package/skills/canvas/SKILL.md +204 -0
  1844. package/skills/coding-agent/SKILL.md +316 -0
  1845. package/skills/discord/SKILL.md +197 -0
  1846. package/skills/eightctl/SKILL.md +50 -0
  1847. package/skills/gemini/SKILL.md +43 -0
  1848. package/skills/gh-issues/SKILL.md +885 -0
  1849. package/skills/gifgrep/SKILL.md +79 -0
  1850. package/skills/git-commit/SKILL.md +40 -0
  1851. package/skills/github/SKILL.md +163 -0
  1852. package/skills/gog/SKILL.md +116 -0
  1853. package/skills/goplaces/SKILL.md +52 -0
  1854. package/skills/healthcheck/SKILL.md +245 -0
  1855. package/skills/himalaya/SKILL.md +257 -0
  1856. package/skills/himalaya/references/configuration.md +184 -0
  1857. package/skills/himalaya/references/message-composition.md +199 -0
  1858. package/skills/imsg/SKILL.md +122 -0
  1859. package/skills/lead-scout/SKILL.md +46 -0
  1860. package/skills/mcporter/SKILL.md +61 -0
  1861. package/skills/model-usage/SKILL.md +69 -0
  1862. package/skills/nano-pdf/SKILL.md +38 -0
  1863. package/skills/node-connect/SKILL.md +142 -0
  1864. package/skills/notion/SKILL.md +174 -0
  1865. package/skills/oauth-setup/SKILL.md +55 -0
  1866. package/skills/obsidian/SKILL.md +81 -0
  1867. package/skills/openai-whisper/SKILL.md +38 -0
  1868. package/skills/openai-whisper-api/SKILL.md +62 -0
  1869. package/skills/openai-whisper-api/scripts/transcribe.sh +88 -0
  1870. package/skills/openhue/SKILL.md +112 -0
  1871. package/skills/oracle/SKILL.md +125 -0
  1872. package/skills/ordercli/SKILL.md +78 -0
  1873. package/skills/peekaboo/SKILL.md +190 -0
  1874. package/skills/sag/SKILL.md +87 -0
  1875. package/skills/session-logs/SKILL.md +151 -0
  1876. package/skills/share-skills/SKILL.md +72 -0
  1877. package/skills/sherpa-onnx-tts/SKILL.md +109 -0
  1878. package/skills/sherpa-onnx-tts/bin/sherpa-onnx-tts +178 -0
  1879. package/skills/skill-creator/SKILL.md +372 -0
  1880. package/skills/skill-creator/license.txt +202 -0
  1881. package/skills/skill-creator/scripts/init_skill.py +378 -0
  1882. package/skills/skill-creator/scripts/package_skill.py +139 -0
  1883. package/skills/skill-creator/scripts/quick_validate.py +159 -0
  1884. package/skills/skill-creator/scripts/test_package_skill.py +160 -0
  1885. package/skills/skill-creator/scripts/test_quick_validate.py +72 -0
  1886. package/skills/slack/SKILL.md +144 -0
  1887. package/skills/songsee/SKILL.md +49 -0
  1888. package/skills/sonoscli/SKILL.md +65 -0
  1889. package/skills/spotify-player/SKILL.md +64 -0
  1890. package/skills/summarize/SKILL.md +87 -0
  1891. package/skills/taskflow/SKILL.md +149 -0
  1892. package/skills/taskflow-inbox-triage/SKILL.md +119 -0
  1893. package/skills/things-mac/SKILL.md +86 -0
  1894. package/skills/tmux/SKILL.md +170 -0
  1895. package/skills/tmux/scripts/find-sessions.sh +112 -0
  1896. package/skills/tmux/scripts/wait-for-text.sh +83 -0
  1897. package/skills/trello/SKILL.md +108 -0
  1898. package/skills/video-frames/SKILL.md +46 -0
  1899. package/skills/video-frames/scripts/frame.sh +81 -0
  1900. package/skills/voice-call/SKILL.md +45 -0
  1901. package/skills/wacli/SKILL.md +72 -0
  1902. package/skills/weather/SKILL.md +129 -0
  1903. package/skills/xurl/SKILL.md +461 -0
  1904. package/templates/workspace/AGENTS.md +223 -0
  1905. package/templates/workspace/BOOTSTRAP.md +64 -0
  1906. package/templates/workspace/HEARTBEAT.md +15 -0
  1907. package/templates/workspace/IDENTITY.md +31 -0
  1908. package/templates/workspace/SOUL.md +47 -0
  1909. package/templates/workspace/TOOLS.md +48 -0
  1910. package/templates/workspace/USER.md +25 -0
  1911. package/CHANGELOG.md +0 -41
  1912. package/SECURITY.md +0 -208
  1913. package/assets/brigade-wordmark.png +0 -0
  1914. package/dist/cli/chat-cmd.js +0 -191
  1915. package/dist/cli/config-cmd.js +0 -171
  1916. package/dist/cli/connect-cmd.js +0 -487
  1917. package/dist/cli/doctor-cmd.js +0 -387
  1918. package/dist/cli/gateway-cmd.js +0 -155
  1919. package/dist/cli.js +0 -328
  1920. package/dist/core/agent.js +0 -1123
  1921. package/dist/core/auth-label.js +0 -147
  1922. package/dist/core/cli-error.js +0 -94
  1923. package/dist/core/error-classifier.js +0 -354
  1924. package/dist/core/provider-payload-mutators.js +0 -517
  1925. package/dist/core/provider-quirks.js +0 -285
  1926. package/dist/core/smart-compaction.js +0 -209
  1927. package/dist/core/system-prompt-defaults.js +0 -264
  1928. package/dist/core/system-prompt-guidance.js +0 -271
  1929. package/dist/index.js +0 -32
  1930. package/dist/ui/brand-frames.js +0 -36
  1931. package/dist/ui/chat.js +0 -1008
@@ -0,0 +1,1628 @@
1
+ /**
2
+ * WhatsApp Web connection (Baileys).
3
+ *
4
+ * A multi-file auth store on disk, QR-on-first-link, auto-reconnect with
5
+ * backoff, and a normalized text-message callback. Baileys is a heavy
6
+ * dependency, so it is lazy-imported here — the gateway only pays for it when a
7
+ * WhatsApp channel actually starts. Types are imported `type`-only (erased at
8
+ * build) so the static import never pulls the runtime in.
9
+ *
10
+ * Reconnect discipline: on a transient drop the live socket is fully torn down
11
+ * (listeners removed + ended) BEFORE a replacement is built, and the rebuild is
12
+ * scheduled on a backoff timer rather than synchronously inside the close
13
+ * handler — so a flapping link can never fork into parallel reconnect chains or
14
+ * leak listeners. A logged-out close stops reconnection entirely (creds are
15
+ * dead). `close()` cancels any pending reconnect and tears the socket down.
16
+ *
17
+ * Scope (this phase): text in / text out. Media, reactions, groups-as-rooms,
18
+ * and presence are deliberately out of scope and slot in later behind the same
19
+ * ChannelAdapter contract.
20
+ */
21
+ import { existsSync, readFileSync } from "node:fs";
22
+ import { access, chmod, copyFile, readFile, rename, unlink, writeFile } from "node:fs/promises";
23
+ import { join as joinPath } from "node:path";
24
+ import { tryGetRuntimeContext } from "../../../storage/runtime-context.js";
25
+ import { validateOutboundMediaPath } from "../../../security/media-path-guard.js";
26
+ import { createDedupeCache } from "../dedupe.js";
27
+ import { chunkText } from "./chunk.js";
28
+ import { lookupLidReverseSync, useConvexAuthState } from "./convex-auth-state.js";
29
+ import { markdownToWhatsApp } from "./format.js";
30
+ import { extractMentions, extractReplyContext } from "./inbound-extras.js";
31
+ import { downloadInboundMedia, hasInboundMedia } from "./media.js";
32
+ /**
33
+ * Extract the canonical phone-number id (digits-only E.164) from a regular
34
+ * WhatsApp jid like `15551234567@s.whatsapp.net`, a participant jid with a
35
+ * device suffix like `15551234567:1@s.whatsapp.net`, or a raw E.164 string.
36
+ * Returns `""` when no digits are present.
37
+ *
38
+ * ⚠ DO NOT use this on LID-suffixed jids (`@lid` / `@hosted.lid`). LIDs are
39
+ * privacy aliases — the leading digits are an opaque WhatsApp-internal id, NOT
40
+ * a phone number. Use {@link resolveJidToE164} (async) which calls Baileys'
41
+ * `signalRepository.lidMapping.getPNForLID` to map the alias to a real phone.
42
+ */
43
+ export function canonicalWhatsAppId(raw) {
44
+ if (!raw)
45
+ return "";
46
+ // Strip everything except digits — drops `+`, `-`, spaces, jid suffix, and
47
+ // the device-id `:N` segment that follows the number in participant ids.
48
+ const at = raw.indexOf("@");
49
+ const head = at === -1 ? raw : raw.slice(0, at);
50
+ const beforeColon = head.split(":")[0] ?? head;
51
+ return beforeColon.replace(/\D/g, "");
52
+ }
53
+ /**
54
+ * Coerce ANY operator-shaped target into a sendable WhatsApp JID. Accepts:
55
+ *
56
+ * - `"+1 555 010 0001"` / `"+15550100001"` / `"15550100001"` → strips
57
+ * formatting, treats as a personal phone number, returns
58
+ * `"15550100001@s.whatsapp.net"`.
59
+ * - `"15550100001@s.whatsapp.net"` → returned unchanged (already canonical).
60
+ * - `"123-456-789@g.us"` → returned unchanged (group jid).
61
+ * - `"260451430568126@lid"` → returned unchanged (LID alias — Baileys handles
62
+ * the lookup internally during send).
63
+ *
64
+ * Returns `""` when the input has no recoverable digits AND no `@`.
65
+ *
66
+ * The Baileys `sendMessage` API parses the recipient via `jidDecode` and
67
+ * crashes with `"Cannot destructure property 'user' of 'jidDecode(...)' as
68
+ * it is undefined"` when the input is a bare `"+phonenumber"` — `jidDecode`
69
+ * returns undefined because there's no `@`. Normalising at the adapter
70
+ * boundary means the operator (and the model) can address peers by phone
71
+ * number in the natural shape and never has to know about JID syntax.
72
+ */
73
+ export function toWhatsAppJid(raw) {
74
+ if (!raw)
75
+ return "";
76
+ const trimmed = raw.trim();
77
+ if (!trimmed)
78
+ return "";
79
+ // Already a jid → pass through unchanged. Covers @s.whatsapp.net (personal),
80
+ // @g.us (group), @lid / @hosted.lid (LID alias), @broadcast (status).
81
+ if (trimmed.includes("@"))
82
+ return trimmed;
83
+ // Bare phone — strip formatting (`+`, spaces, hyphens, parens) and append
84
+ // the personal-jid suffix. We DO NOT validate the number's country-code
85
+ // shape; Baileys will reject with a clear error if the number is invalid.
86
+ const digits = trimmed.replace(/\D/g, "");
87
+ if (!digits)
88
+ return "";
89
+ return `${digits}@s.whatsapp.net`;
90
+ }
91
+ // Regular phone-number jid (with optional device suffix). The capture is the
92
+ // raw E.164 digits — no leading `+`, callers add it when displaying.
93
+ const WA_PHONE_JID_RE = /^(\d+)(?::\d+)?@(s\.whatsapp\.net|hosted)$/;
94
+ // Privacy-alias (LID) jid. The leading digits look like a phone number but
95
+ // are NOT — they're an opaque alias the user opted into to hide their real
96
+ // number. The only way to map LID → phone is `signalRepository.lidMapping`.
97
+ const WA_LID_JID_RE = /^(\d+)(?::\d+)?@(lid|hosted\.lid)$/;
98
+ /**
99
+ * Read the on-disk LID-reverse mapping file Baileys writes alongside its
100
+ * multi-file auth store. When `signalRepository.lidMapping.getPNForLID` hasn't
101
+ * cached a mapping yet (typical right after a fresh link), the cached reverse
102
+ * file is the only place to find the LID → phone translation. Path shape:
103
+ * `<authDir>/lid-mapping-<lid>_reverse.json` → JSON containing the phone
104
+ * number (string or number) the LID is aliased to.
105
+ *
106
+ * Sync (single small JSON file, microseconds); the caller's outer resolver is
107
+ * async because the runtime lookup is async. Returns null when the file is
108
+ * absent, unreadable, or carries a null/empty value.
109
+ */
110
+ function readLidReverseMappingSync(authDir, lidDigits, accountId = "default") {
111
+ if (!lidDigits)
112
+ return null;
113
+ // Convex mode — the lid-mapping keys live in the keystore; the
114
+ // auth-state module mirrors reverse entries for exactly this sync read.
115
+ // The mirror is keyed by accountId, so the lookup MUST use the same
116
+ // accountId the auth-state was loaded with (not a hardcoded "default",
117
+ // which silently misses for any non-default WhatsApp account → inbound
118
+ // LID-form senders get dropped).
119
+ if (tryGetRuntimeContext()?.mode === "convex") {
120
+ return lookupLidReverseSync(accountId, lidDigits);
121
+ }
122
+ if (!authDir)
123
+ return null;
124
+ // Best-effort filesystem read — gated by a quick exists check so the
125
+ // happy-path "no mapping yet" branch doesn't spam the disk.
126
+ try {
127
+ const mappingPath = joinPath(authDir, `lid-mapping-${lidDigits}_reverse.json`);
128
+ if (!existsSync(mappingPath))
129
+ return null;
130
+ const raw = readFileSync(mappingPath, "utf8");
131
+ const parsed = JSON.parse(raw);
132
+ if (parsed === null || parsed === undefined)
133
+ return null;
134
+ const digits = String(parsed).replace(/\D/g, "");
135
+ return digits.length >= 7 ? digits : null;
136
+ }
137
+ catch {
138
+ // Missing / malformed / racing-with-write — degrade silently to the
139
+ // runtime-lookup path so a transient read error doesn't drop the msg.
140
+ return null;
141
+ }
142
+ }
143
+ /**
144
+ * Resolve a WhatsApp jid to a canonical phone number (digits-only E.164),
145
+ * including LID-aliased jids that need a runtime lookup. Resolution order
146
+ * for LID jids:
147
+ * 1. On-disk reverse mapping at `<authDir>/lid-mapping-<lid>_reverse.json`
148
+ * (Baileys persists these across reconnects — survives the cold-start
149
+ * window where `signalRepository.lidMapping` is empty).
150
+ * 2. `signalRepository.lidMapping.getPNForLID()` — the live in-memory cache.
151
+ *
152
+ * Returns `null` when:
153
+ * - `jid` is empty/missing
154
+ * - the jid is in LID form AND neither resolution path yields a phone
155
+ * - the resolved value isn't a recognized phone-jid shape
156
+ *
157
+ * Callers MUST drop messages with a `null` resolution rather than inventing a
158
+ * fake sender id from raw LID digits — those digits aren't a phone number, and
159
+ * downstream pairing/allow-list code keys on E.164.
160
+ *
161
+ * `authDir` is optional so tests can call without an on-disk store; when
162
+ * omitted only the runtime lookup is consulted.
163
+ */
164
+ export async function resolveJidToE164(sock, jid, authDir, accountId) {
165
+ if (!jid)
166
+ return null;
167
+ const direct = jid.match(WA_PHONE_JID_RE);
168
+ if (direct)
169
+ return direct[1] ?? null;
170
+ const lidMatch = jid.match(WA_LID_JID_RE);
171
+ if (!lidMatch)
172
+ return null;
173
+ const lidDigits = lidMatch[1] ?? "";
174
+ // First: on-disk reverse mapping. Baileys' multi-file auth store writes
175
+ // these the moment it sees a LID's phone translation, so right after a
176
+ // fresh link they're available even while the in-memory `lidMapping` is
177
+ // still warming up.
178
+ const fromDisk = readLidReverseMappingSync(authDir, lidDigits, accountId);
179
+ if (fromDisk)
180
+ return fromDisk;
181
+ // Then: runtime lookup. Some Baileys builds expose
182
+ // `signalRepository.lidMapping`; older / partially-initialized sockets
183
+ // don't. Treat a missing lookup as "unresolvable" — we already tried disk.
184
+ const lookup = sock?.signalRepository
185
+ ?.lidMapping;
186
+ if (!lookup?.getPNForLID)
187
+ return null;
188
+ try {
189
+ const pnJid = await lookup.getPNForLID(jid);
190
+ if (!pnJid)
191
+ return null;
192
+ const m = pnJid.match(WA_PHONE_JID_RE);
193
+ return m ? (m[1] ?? null) : null;
194
+ }
195
+ catch {
196
+ // Lookup failure (e.g. mapping not cached yet) → fall through.
197
+ return null;
198
+ }
199
+ }
200
+ /** Strip a device-id suffix (`:NN`) from a jid, leaving the bare user jid. */
201
+ export function normalizeDeviceScopedJid(jid) {
202
+ return jid ? jid.replace(/:\d+/, "") : null;
203
+ }
204
+ /**
205
+ * Resolve an inbound sender jid to a STABLE channel identity that NEVER drops a
206
+ * usable sender. Mirrors the reference codebase's identity model
207
+ * (`getPrimaryIdentityId`: e164 || jid || lid): try the phone number first, and
208
+ * when it can't be resolved — e.g. an unmapped `@lid` privacy alias, the common
209
+ * case for group participants — fall back to the canonical LID jid so the
210
+ * message still reaches the access-control gate instead of being silently
211
+ * dropped at the socket layer. The LID is a perfectly stable "same person"
212
+ * handle: routing, allow-lists, and per-sender sessions all key off the
213
+ * returned `id` exactly the way they key off a phone number.
214
+ *
215
+ * Returns:
216
+ * { id: "<e164 digits>", e164: "<e164 digits>" } — phone resolved
217
+ * { id: "<digits>@lid", lid: "<digits>@lid" } — LID alias, unmapped
218
+ * { id: "<normalized jid>" } — other jid shape
219
+ * null — empty / unusable input
220
+ */
221
+ export async function resolveSenderIdentity(sock, jid, authDir, accountId) {
222
+ if (!jid)
223
+ return null;
224
+ // Capture the LID alias whenever the sender came in via one — even when it
225
+ // DID map to a phone number — so the access-control gate can match on either
226
+ // the number or the LID (mirrors the reference codebase's identity overlap).
227
+ const lid = WA_LID_JID_RE.test(jid) ? (normalizeDeviceScopedJid(jid) ?? undefined) : undefined;
228
+ const e164 = await resolveJidToE164(sock, jid, authDir, accountId);
229
+ if (e164)
230
+ return { id: e164, e164, ...(lid ? { lid } : {}) };
231
+ const normalized = normalizeDeviceScopedJid(jid) ?? jid;
232
+ if (!normalized)
233
+ return null;
234
+ // Unmapped LID privacy alias — keep it verbatim as the stable identity.
235
+ if (lid || /@(lid|hosted\.lid)$/i.test(normalized)) {
236
+ return { id: normalized, lid: lid ?? normalized };
237
+ }
238
+ // Some other jid shape we couldn't map — keep it rather than dropping.
239
+ return { id: normalized };
240
+ }
241
+ // Reconnect backoff: 2s → 30s, ×1.8 with ±25% jitter, capped attempts so a
242
+ // permanently-broken link stops hammering WhatsApp instead of looping forever.
243
+ const RECONNECT_INITIAL_MS = 2_000;
244
+ const RECONNECT_MAX_MS = 30_000;
245
+ const RECONNECT_FACTOR = 1.8;
246
+ const RECONNECT_JITTER = 0.25;
247
+ const RECONNECT_MAX_ATTEMPTS = 12;
248
+ function backoffDelay(attempt) {
249
+ const base = Math.min(RECONNECT_MAX_MS, RECONNECT_INITIAL_MS * RECONNECT_FACTOR ** attempt);
250
+ const jitter = base * RECONNECT_JITTER * (Math.random() * 2 - 1);
251
+ return Math.max(0, Math.round(base + jitter));
252
+ }
253
+ // How often to send an outbound "available" presence ping while the link is
254
+ // otherwise idle. WhatsApp's servers can silently mark a long-idle linked
255
+ // device offline (queueing inbound until the next reconnect) — a periodic
256
+ // nudge keeps the link warm. Defaults to 5 minutes; tune with the env var
257
+ // when debugging suspicious overnight stalls.
258
+ const PRESENCE_PING_MS_DEFAULT = 5 * 60 * 1_000;
259
+ function presencePingMs() {
260
+ const raw = process.env.BRIGADE_WHATSAPP_PRESENCE_PING_MS;
261
+ const parsed = raw ? Number(raw) : NaN;
262
+ return Number.isFinite(parsed) && parsed >= 30_000 ? parsed : PRESENCE_PING_MS_DEFAULT;
263
+ }
264
+ /**
265
+ * Cold-start presence nudges. After EVERY `connection: "open"` event we
266
+ * fire `sendPresenceUpdate("available")` once immediately, then again at
267
+ * these offsets. WhatsApp's server has a "is the device really ready"
268
+ * debounce — one presence ping is often not enough to convince it to
269
+ * flush a queued message backlog, leaving the operator staring at a
270
+ * silent chat for ~60s on first connect. Three quick re-pings during
271
+ * the cold-start window pull that floor down to ~5-15 s. Cheap (one
272
+ * outbound stanza each) and cancelled the moment a real inbound flows.
273
+ *
274
+ * Tuning rationale: 5s catches the case where the first presence beat
275
+ * the server's "device-ready" decision; 15s catches the case where the
276
+ * server held the queue waiting for a steady-state signal; 30s is the
277
+ * outer envelope before the regular 5-min ping cadence takes over.
278
+ */
279
+ const COLD_START_NUDGES_MS = [5_000, 15_000, 30_000];
280
+ // Long-lived sessions accumulate Signal-protocol state drift; a clean recycle
281
+ // every N hours costs one reconnect and avoids a midnight stall against a
282
+ // session the server has quietly invalidated. 6h default — long enough to
283
+ // avoid churn during a normal workday, short enough to recover before the
284
+ // next morning.
285
+ const MAX_SESSION_AGE_MS_DEFAULT = 6 * 60 * 60 * 1_000;
286
+ function maxSessionAgeMs() {
287
+ const raw = process.env.BRIGADE_WHATSAPP_MAX_SESSION_AGE_MS;
288
+ const parsed = raw ? Number(raw) : NaN;
289
+ // Minimum 10 min so a misconfigured "0" doesn't reconnect-storm.
290
+ return Number.isFinite(parsed) && parsed >= 10 * 60_000 ? parsed : MAX_SESSION_AGE_MS_DEFAULT;
291
+ }
292
+ // Baileys DisconnectReason value emitted when a NEW WhatsApp Web session opens
293
+ // against the same number — another linked Brigade or a manual Web login. Two
294
+ // sessions reconnecting on the same number get into a 440-conflict ping-pong
295
+ // loop, so this code is treated as terminal (same as logged-out) instead of
296
+ // retried.
297
+ const MULTI_DEVICE_CONFLICT_CODE = 440;
298
+ /**
299
+ * Detect Signal-protocol crypto errors that bubble up from Baileys as
300
+ * unhandled promise rejections instead of through the `connection.update`
301
+ * event (the protocol library throws inside its own async ratchet). When a
302
+ * pre-key rotation goes wrong or a session entry desyncs we'd otherwise wait
303
+ * for the watchdog to time out; trapping the rejection lets us force-reconnect
304
+ * immediately and recover the link in seconds.
305
+ *
306
+ * The attribution-keyword list is deliberately narrow: only stack-frame
307
+ * markers unique to Baileys' WhatsApp transport. Broader markers (e.g. the
308
+ * generic "signal" token, which can appear in unrelated libsignal builds,
309
+ * crypto-library stacks, or even our own log lines) would cause false
310
+ * positives that force-reconnect a healthy socket on unrelated rejections.
311
+ */
312
+ export function isWaCryptoError(reason) {
313
+ const message = String(reason?.message ?? reason ?? "").toLowerCase();
314
+ const cryptoHit = message.includes("unsupported state or unable to authenticate data") ||
315
+ message.includes("bad mac");
316
+ if (!cryptoHit)
317
+ return false;
318
+ return (message.includes("baileys") ||
319
+ message.includes("noise-handler") ||
320
+ message.includes("aesdecryptgcm") ||
321
+ message.includes("@whiskeysockets"));
322
+ }
323
+ /**
324
+ * Extract plain text from a Baileys message, unwrapping the common envelopes
325
+ * (`ephemeralMessage`, `viewOnceMessage*`, `documentWithCaptionMessage`) and
326
+ * surfacing placeholder text for content kinds without a natural body —
327
+ * shared contacts, location pins, polls — so the LLM at least sees that the
328
+ * user sent SOMETHING and can acknowledge it instead of silently dropping
329
+ * the inbound.
330
+ */
331
+ function extractText(message, normalize) {
332
+ // `normalize` is Baileys' own envelope-flattener; we still wrap it in our
333
+ // wrapper-chain walk in case `normalize` itself leaves a wrapper in place
334
+ // for shapes it doesn't recognize (newer Baileys variants).
335
+ const flattened = (normalize(message) ?? {});
336
+ let content = flattened;
337
+ const fromWrappers = unwrapWrapperEnvelopes(flattened);
338
+ if (fromWrappers)
339
+ content = fromWrappers;
340
+ if (typeof content.conversation === "string")
341
+ return content.conversation;
342
+ const ext = content.extendedTextMessage;
343
+ if (ext && typeof ext.text === "string")
344
+ return ext.text;
345
+ // Image/video/document with a caption — treat the caption as the text.
346
+ const img = content.imageMessage;
347
+ if (img && typeof img.caption === "string")
348
+ return img.caption;
349
+ const vid = content.videoMessage;
350
+ if (vid && typeof vid.caption === "string")
351
+ return vid.caption;
352
+ const doc = content.documentMessage;
353
+ if (doc && typeof doc.caption === "string")
354
+ return doc.caption;
355
+ // Contact card — placeholder so the LLM knows a contact was shared.
356
+ const contact = content.contactMessage;
357
+ if (contact && typeof contact.displayName === "string" && contact.displayName.length > 0) {
358
+ return `[contact shared: ${contact.displayName}]`;
359
+ }
360
+ const contactsArray = content.contactsArrayMessage;
361
+ if (contactsArray?.contacts && contactsArray.contacts.length > 0) {
362
+ const names = contactsArray.contacts
363
+ .map((c) => (typeof c?.displayName === "string" ? c.displayName : ""))
364
+ .filter(Boolean);
365
+ if (names.length > 0)
366
+ return `[contacts shared: ${names.join(", ")}]`;
367
+ }
368
+ // Location pin — placeholder with lat/lon when present.
369
+ const loc = content.locationMessage;
370
+ if (loc && (typeof loc.degreesLatitude === "number" || typeof loc.name === "string")) {
371
+ const named = typeof loc.name === "string" && loc.name ? `"${loc.name}"` : "";
372
+ const coords = typeof loc.degreesLatitude === "number" && typeof loc.degreesLongitude === "number"
373
+ ? `(${loc.degreesLatitude.toFixed(6)}, ${loc.degreesLongitude.toFixed(6)})`
374
+ : "";
375
+ return `[location shared ${named}${named && coords ? " " : ""}${coords}]`.trim();
376
+ }
377
+ // Live-location update — placeholder so a stream of these doesn't drop silently.
378
+ if (content.liveLocationMessage)
379
+ return "[live location update]";
380
+ return "";
381
+ }
382
+ /**
383
+ * Wrapper envelopes Baileys' own `normalizeMessageContent` may not unwrap
384
+ * (newer message kinds, hosted-LID variants). Walks the chain in lock-step
385
+ * with `inbound-extras.ts:unwrapMessage` so caller behavior is consistent.
386
+ */
387
+ const WRAPPER_KEYS = [
388
+ "ephemeralMessage",
389
+ "viewOnceMessage",
390
+ "viewOnceMessageV2",
391
+ "viewOnceMessageV2Extension",
392
+ "documentWithCaptionMessage",
393
+ "botInvokeMessage",
394
+ "groupMentionedMessage",
395
+ ];
396
+ function unwrapWrapperEnvelopes(message) {
397
+ let current = message;
398
+ for (let depth = 0; depth < 8 && current; depth += 1) {
399
+ const obj = current;
400
+ let inner;
401
+ for (const key of WRAPPER_KEYS) {
402
+ const wrapper = obj[key];
403
+ if (wrapper?.message) {
404
+ inner = wrapper.message;
405
+ break;
406
+ }
407
+ }
408
+ if (!inner)
409
+ return current;
410
+ current = inner;
411
+ }
412
+ return current;
413
+ }
414
+ /**
415
+ * Establish a WhatsApp Web connection with auto-reconnect. Resolves once the
416
+ * first socket is constructed (NOT once connected — QR/open events arrive via
417
+ * the callbacks). The returned handle owns the reconnect loop.
418
+ */
419
+ /**
420
+ * Patch `console.info` ONCE per process so the libsignal protocol library
421
+ * (Baileys' Signal implementation) stops dumping massive `Closing session:
422
+ * SessionEntry { … }` objects into the gateway log on every key-ratchet step.
423
+ * That's a debug print inside `libsignal/src/session_record.js` we can't reach
424
+ * to remove; filtering at the console layer keeps the gateway log readable
425
+ * without losing real `console.info` calls.
426
+ *
427
+ * Idempotent — the patch checks for its own marker so a second `connectWhatsApp`
428
+ * call doesn't double-wrap.
429
+ */
430
+ const LIBSIGNAL_FILTER_MARKER = Symbol.for("brigade.libsignal.console.filter");
431
+ function installLibsignalConsoleFilter() {
432
+ const flag = console;
433
+ if (flag[LIBSIGNAL_FILTER_MARKER])
434
+ return;
435
+ const original = console.info.bind(console);
436
+ console.info = ((...callArgs) => {
437
+ const first = callArgs[0];
438
+ if (typeof first === "string" && first.startsWith("Closing session:"))
439
+ return;
440
+ original(...callArgs);
441
+ });
442
+ flag[LIBSIGNAL_FILTER_MARKER] = true;
443
+ }
444
+ // Filesystem-mode creds durability. Baileys' useMultiFileAuthState persists
445
+ // creds.json with a single non-atomic fs.writeFile and keeps no backup, so a
446
+ // crash mid-save can truncate the file; on the next boot the parse fails,
447
+ // Baileys falls back to a fresh unlinked identity, and the operator is forced
448
+ // to re-scan the QR. The WhatsApp link surviving a restart is a stated Brigade
449
+ // priority (see the final creds flush in close()), so the filesystem branch
450
+ // wraps creds persistence to be crash-safe: a parseable on-disk copy is mirrored
451
+ // to a sibling backup before each write, and the new state is written to a temp
452
+ // file then atomically renamed into place. Convex mode is unaffected — it rides
453
+ // useConvexAuthState with its own write-behind store.
454
+ const FS_CREDS_FILE_NAME = "creds.json";
455
+ const FS_CREDS_BACKUP_FILE_NAME = "creds.json.bak";
456
+ /** True iff `path` exists and its contents parse as JSON. Best-effort. */
457
+ async function fileParsesAsJson(path) {
458
+ try {
459
+ const raw = await readFile(path, "utf8");
460
+ JSON.parse(raw);
461
+ return true;
462
+ }
463
+ catch {
464
+ return false;
465
+ }
466
+ }
467
+ /**
468
+ * Before the first socket is built, recover from a half-written creds.json:
469
+ * when the live creds file is missing/empty/unparseable but the sibling backup
470
+ * parses cleanly, copy the backup over creds.json so Baileys loads the last
471
+ * good identity instead of minting a fresh one (which would force a re-pair).
472
+ * Best-effort — any failure degrades to Baileys' own fresh-creds path.
473
+ */
474
+ async function restoreFsCredsFromBackupIfNeeded(authDir, log) {
475
+ try {
476
+ const credsPath = joinPath(authDir, FS_CREDS_FILE_NAME);
477
+ const backupPath = joinPath(authDir, FS_CREDS_BACKUP_FILE_NAME);
478
+ // Live file already good — nothing to do.
479
+ if (await fileParsesAsJson(credsPath))
480
+ return;
481
+ // No usable backup — leave Baileys to mint fresh creds.
482
+ if (!(await fileParsesAsJson(backupPath)))
483
+ return;
484
+ await copyFile(backupPath, credsPath);
485
+ try {
486
+ await chmod(credsPath, 0o600);
487
+ }
488
+ catch {
489
+ // chmod is a no-op / unsupported on some filesystems — ignore.
490
+ }
491
+ log("restored WhatsApp creds from backup after a corrupt/missing creds file");
492
+ }
493
+ catch (err) {
494
+ // Restore is opportunistic — never let it block a connect.
495
+ log("WhatsApp creds backup-restore skipped", {
496
+ error: err instanceof Error ? err.message : String(err),
497
+ });
498
+ }
499
+ }
500
+ /**
501
+ * Build a crash-safe replacement for Baileys' raw saveCreds (filesystem branch
502
+ * only). Baileys' saveCreds writes only creds.json, so fully owning that one
503
+ * write is sufficient. Each save: (1) mirror a currently-parseable creds.json to
504
+ * creds.json.bak — skipped when the live file is missing/corrupt so a known-good
505
+ * backup is never clobbered; (2) serialize the live creds with Baileys'
506
+ * BufferJSON.replacer to a unique temp file, then fs.rename it onto creds.json
507
+ * (atomic on the same filesystem). The temp file is cleaned up on error.
508
+ * `liveCreds` is the same object Baileys mutates in state.creds, so it always
509
+ * reflects the latest credentials at write time.
510
+ */
511
+ function makeFsCrashSafeCredsSaver(authDir, liveCreds, bufferJsonReplacer, log) {
512
+ const credsPath = joinPath(authDir, FS_CREDS_FILE_NAME);
513
+ const backupPath = joinPath(authDir, FS_CREDS_BACKUP_FILE_NAME);
514
+ return async () => {
515
+ // 1. Back up the live file only when it currently parses — never
516
+ // overwrite a good backup with a truncated one.
517
+ try {
518
+ if (await fileParsesAsJson(credsPath)) {
519
+ await copyFile(credsPath, backupPath);
520
+ try {
521
+ await chmod(backupPath, 0o600);
522
+ }
523
+ catch {
524
+ // chmod unsupported here — ignore.
525
+ }
526
+ }
527
+ }
528
+ catch (err) {
529
+ // A failed backup must not block the actual save.
530
+ log("WhatsApp creds backup skipped", {
531
+ error: err instanceof Error ? err.message : String(err),
532
+ });
533
+ }
534
+ // 2. Atomic write: temp file + rename.
535
+ const tmpPath = joinPath(authDir, `.creds.${process.pid}.${Date.now()}.tmp`);
536
+ try {
537
+ await writeFile(tmpPath, JSON.stringify(liveCreds, bufferJsonReplacer));
538
+ try {
539
+ await chmod(tmpPath, 0o600);
540
+ }
541
+ catch {
542
+ // chmod unsupported here — ignore.
543
+ }
544
+ await rename(tmpPath, credsPath);
545
+ }
546
+ catch (err) {
547
+ // Best-effort temp cleanup so a failed write doesn't litter authDir.
548
+ try {
549
+ await access(tmpPath);
550
+ await unlink(tmpPath);
551
+ }
552
+ catch {
553
+ // Temp file never created or already gone — nothing to clean.
554
+ }
555
+ throw err instanceof Error ? err : new Error(String(err));
556
+ }
557
+ };
558
+ }
559
+ export async function connectWhatsApp(args) {
560
+ installLibsignalConsoleFilter();
561
+ const baileys = await import("@whiskeysockets/baileys");
562
+ const makeWASocket = (baileys.default ?? baileys.makeWASocket);
563
+ const { DisconnectReason, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, normalizeMessageContent, useMultiFileAuthState } = baileys;
564
+ const loggedOutCode = DisconnectReason?.loggedOut ?? 401;
565
+ const restartRequiredCode = DisconnectReason?.restartRequired ?? 515;
566
+ // Silent pino-shaped logger unless verbose — Baileys logs prolifically.
567
+ const level = args.verbose ? "info" : "silent";
568
+ const noop = () => { };
569
+ const baileysLogger = {
570
+ level,
571
+ trace: noop,
572
+ debug: noop,
573
+ info: noop,
574
+ warn: noop,
575
+ error: noop,
576
+ fatal: noop,
577
+ child: () => baileysLogger,
578
+ };
579
+ // Auth state — mode dispatch. Filesystem: Baileys' own multi-file dir
580
+ // (~900 small files under the channel state dir). Convex: the
581
+ // whatsappAuthCreds/whatsappAuthKeys tables via useConvexAuthState — no
582
+ // auth files on disk; key material is sealed before it leaves the
583
+ // process; pre-hydrated in one query so Signal-path key reads never pay
584
+ // a network round-trip.
585
+ const rctxForAuth = tryGetRuntimeContext();
586
+ // One accountId for the whole connection: the auth-state load, the
587
+ // LID-reverse mirror lookups, and (convex) the close() flush all key off
588
+ // it. Hardcoding "default" downstream silently breaks any non-default
589
+ // WhatsApp account.
590
+ const connectionAccountId = args.accountId ?? "default";
591
+ let state;
592
+ let saveCreds;
593
+ // Convex-mode: the auth-state queues key writes write-behind. Capture its
594
+ // flush so close() can drain it — otherwise a fresh pair's keys can be
595
+ // lost when the link command exits right after a successful connect.
596
+ let convexAuthFlush;
597
+ if (rctxForAuth?.mode === "convex") {
598
+ const convexAuth = await useConvexAuthState(rctxForAuth.store, connectionAccountId, {
599
+ initAuthCreds: baileys.initAuthCreds,
600
+ BufferJSON: baileys.BufferJSON,
601
+ proto: baileys.proto,
602
+ });
603
+ state = convexAuth.state;
604
+ saveCreds = convexAuth.saveCreds;
605
+ convexAuthFlush = convexAuth.flush;
606
+ }
607
+ else {
608
+ // Recover a half-written creds.json from its backup BEFORE Baileys loads
609
+ // the auth state — otherwise a truncated file parses as null and Baileys
610
+ // mints a fresh identity, forcing a QR re-pair.
611
+ await restoreFsCredsFromBackupIfNeeded(args.authDir, args.log);
612
+ const multiFile = await useMultiFileAuthState(args.authDir);
613
+ state = multiFile.state;
614
+ // Replace Baileys' raw (non-atomic, no-backup) saveCreds with a crash-safe
615
+ // wrapper. Baileys' saveCreds writes only creds.json, so owning that one
616
+ // write fully closes the durability gap. state.creds is the live object
617
+ // Baileys mutates, so the wrapper always serializes the current creds.
618
+ saveCreds = makeFsCrashSafeCredsSaver(args.authDir, state.creds, baileys.BufferJSON.replacer, args.log);
619
+ }
620
+ const { version } = await fetchLatestBaileysVersion();
621
+ let sock = null;
622
+ let closed = false;
623
+ let reconnectAttempts = 0;
624
+ let reconnectTimer = null;
625
+ // Inbound dedupe: WhatsApp re-delivers the same msg.key.id after a
626
+ // reconnect; without this, the agent runs the LLM (and bills) twice and
627
+ // posts the reply twice. Per-connection lifetime.
628
+ const inboundDedupe = createDedupeCache({ maxEntries: 5_000, ttlMs: 60 * 60 * 1_000 });
629
+ // Outbound id tracking — every successful send records `result.key.id` so
630
+ // the inbound `fromMe` echo (WhatsApp mirrors our own sends back through
631
+ // `messages.upsert`) can be distinguished from a genuine self-chat. Without
632
+ // this we'd have to blanket-drop `fromMe`, which silences the operator
633
+ // DMing themselves (selfChat). 20-min TTL — long enough to survive a
634
+ // slow reconnect, short enough to bound memory on a chatty account.
635
+ const outboundDedupe = createDedupeCache({ maxEntries: 5_000, ttlMs: 20 * 60 * 1_000 });
636
+ /**
637
+ * Compose the outbound-dedupe key from the destination jid + the WhatsApp
638
+ * `msg.key.id`. WAMIDs are statistically unique, but defence-in-depth: if
639
+ * a future Baileys build ever reuses short ids across chats, an id-only
640
+ * key would collide and Brigade would mis-classify a real inbound from
641
+ * one chat as an echo of an outbound from another. Conversation-scoped
642
+ * keys close that window with no real cost.
643
+ */
644
+ const outboundKey = (conversationId, messageId) => `${conversationId}:${messageId}`;
645
+ const recordOutboundId = (conversationId, id) => {
646
+ if (id)
647
+ outboundDedupe.remember(outboundKey(conversationId, id));
648
+ };
649
+ // Track the last QR we surfaced so a Baileys QR refresh (same string) doesn't
650
+ // flood the operator's terminal with duplicate prints. Only NEW QRs reach
651
+ // `args.onQr`.
652
+ let lastQr = null;
653
+ // Pending creds writes are tracked so a reconnect (notably the 515 that
654
+ // follows first-link) can wait for them to flush before rebuilding.
655
+ let pendingCredsSave = Promise.resolve();
656
+ // Epoch ms of the most recent `connection: "open"` event. Inbound messages
657
+ // older than `connectedAtMs - PAIRING_GRACE_MS` are treated as queued-since-
658
+ // last-restart history — the access-control gate uses this to suppress
659
+ // pairing-challenge replies to historical DMs (otherwise every stranger
660
+ // who messaged Brigade since the last shutdown gets a code in a burst
661
+ // the moment the gateway reconnects).
662
+ let connectedAtMs = null;
663
+ // How long a "healthy" session must run before its next disconnect is
664
+ // treated as a fresh flap rather than another retry inside an existing
665
+ // failure sequence. Without this guard a link that ran fine for 2 hours
666
+ // then blipped would consume all 12 reconnect attempts in a few minutes;
667
+ // every flap mid-cycle would count as one more retry against a budget
668
+ // that should have been considered fresh.
669
+ const LONG_SESSION_RESET_MS = 60_000;
670
+ // Watchdog state. Two clocks:
671
+ // `lastInboundAt` — bumped on ANY notify frame (incl. status@broadcast).
672
+ // Coarse "transport seeing traffic" signal; kept for telemetry + back-
673
+ // compat with consumers that may already read it.
674
+ // `lastActivityAt` — bumped ONLY after per-message filtering rejects the
675
+ // broadcast / dedupe / LID-unresolvable cases, so the watchdog wakes
676
+ // up when REAL DM/group inbound stops flowing — not when story updates
677
+ // happen to keep the socket warm.
678
+ // The watchdog reads `lastActivityAt`. Disabled in linkMode (one-shot).
679
+ let lastInboundAt = Date.now();
680
+ let lastActivityAt = Date.now();
681
+ let watchdogTimer = null;
682
+ // Periodic outbound presence ping — keeps WhatsApp's server convinced the
683
+ // device is online even during long idle windows. Armed when the link
684
+ // opens, cleared on teardown.
685
+ let presencePingTimer = null;
686
+ // Cold-start presence nudge timers — extra presence-updates fired in the
687
+ // first ~30s after each `connection.open` to convince WhatsApp's server
688
+ // the device is genuinely ready and trigger immediate queue flush.
689
+ // Cleared on teardown AND cancelled the moment real conversational
690
+ // traffic starts flowing (no need to keep nagging once we know the
691
+ // queue is open).
692
+ let coldStartNudgeTimers = [];
693
+ const clearColdStartNudges = () => {
694
+ for (const t of coldStartNudgeTimers)
695
+ clearTimeout(t);
696
+ coldStartNudgeTimers = [];
697
+ };
698
+ // Max-session-age guard — preventively recycles the socket every N hours
699
+ // so accumulated Signal-state drift can't silently kill inbound delivery.
700
+ let sessionAgeTimer = null;
701
+ const WATCHDOG_CHECK_MS = 60_000;
702
+ const WATCHDOG_STALE_MS = 10 * 60 * 1_000;
703
+ // Connect-time liveness probe. As soon as the link opens we want proof that
704
+ // inbound is actually flowing — not just a socket that *says* "ready" while
705
+ // the server silently holds the queue (the "turn it on after a week and
706
+ // nothing arrives" failure). WhatsApp emits `receivedPendingNotifications:
707
+ // true` on `connection.update` once it has flushed everything that arrived
708
+ // while the device was away; a real inbound also counts as proof. If NEITHER
709
+ // happens within COLD_START_HEALTH_MS of connect, the socket is wedged, so we
710
+ // force ONE immediate clean reconnect to wake it — instead of waiting out the
711
+ // 10-minute watchdog. Bounded to MAX_COLD_START_KICKS per attempt so a
712
+ // legitimately slow flush of a huge backlog can't become a reconnect-storm.
713
+ const COLD_START_HEALTH_MS = 90_000;
714
+ const MAX_COLD_START_KICKS = 2;
715
+ let coldStartHealthTimer = null;
716
+ let pendingNotificationsSeen = false;
717
+ let coldStartKicks = 0;
718
+ const clearColdStartHealth = () => {
719
+ if (coldStartHealthTimer) {
720
+ clearTimeout(coldStartHealthTimer);
721
+ coldStartHealthTimer = null;
722
+ }
723
+ };
724
+ // Signal-protocol crypto errors don't reach `connection.update` — they
725
+ // surface as unhandled rejections from inside Baileys' async ratchet.
726
+ // Trap them per-connection and force a fast reconnect; the handler is
727
+ // idempotent (the `closed` + `linkMode` guards keep multi-account
728
+ // processes safe) and is removed on `close()`. The actual `process.on`
729
+ // registration happens at the bottom of `connectWhatsApp` once
730
+ // `teardownSocket` and `scheduleReconnect` have been declared.
731
+ const onUnhandledRejection = (reason) => {
732
+ if (closed || args.linkMode)
733
+ return;
734
+ if (!isWaCryptoError(reason))
735
+ return;
736
+ args.log("WhatsApp Signal-crypto error — force-reconnecting", {
737
+ error: String(reason?.message ?? reason ?? ""),
738
+ });
739
+ const dying = sock;
740
+ sock = null;
741
+ teardownSocket(dying);
742
+ reconnectAttempts = 0;
743
+ scheduleReconnect({ immediate: true });
744
+ };
745
+ /** Detach every listener from a socket and end it — no zombie emits. */
746
+ // Per-socket detach callbacks. Every listener attached inside `buildSocket`
747
+ // pushes its `() => emitter.off(event, handler)` here so `teardownSocket`
748
+ // can detach each one explicitly before falling back to the coarse
749
+ // `removeAllListeners()`. Explicit detach is the principled path —
750
+ // `removeAllListeners` would also drop any listener a future Brigade
751
+ // subsystem (a doctor probe, a sub-agent, an extension) might have
752
+ // attached to the same emitter.
753
+ const socketDetach = new Map();
754
+ const registerDetach = (s, off) => {
755
+ let list = socketDetach.get(s);
756
+ if (!list) {
757
+ list = [];
758
+ socketDetach.set(s, list);
759
+ }
760
+ list.push(off);
761
+ };
762
+ const teardownSocket = (s) => {
763
+ // Per-socket timers go down with the socket — a fresh `buildSocket`
764
+ // re-arms them in the next open handler. Clearing here keeps a
765
+ // reconnect from leaving zombie pings firing against a dead socket.
766
+ if (presencePingTimer) {
767
+ clearInterval(presencePingTimer);
768
+ presencePingTimer = null;
769
+ }
770
+ if (sessionAgeTimer) {
771
+ clearTimeout(sessionAgeTimer);
772
+ sessionAgeTimer = null;
773
+ }
774
+ clearColdStartNudges();
775
+ clearColdStartHealth();
776
+ if (!s)
777
+ return;
778
+ // Detach our own listeners explicitly first so we never drop
779
+ // listeners owned by callers (defense against a future cross-cutting
780
+ // subsystem subscribing to the same emitter).
781
+ const detaches = socketDetach.get(s);
782
+ if (detaches) {
783
+ for (const off of detaches) {
784
+ try {
785
+ off();
786
+ }
787
+ catch {
788
+ /* best-effort — keep going on the next detach */
789
+ }
790
+ }
791
+ socketDetach.delete(s);
792
+ }
793
+ // Belt-and-braces fallback: in case a Baileys-internal listener slipped
794
+ // past our register helper, the coarse removeAllListeners catches it.
795
+ try {
796
+ s.ev.removeAllListeners?.();
797
+ }
798
+ catch {
799
+ /* best-effort */
800
+ }
801
+ try {
802
+ const ws = s.ws;
803
+ ws?.removeAllListeners?.();
804
+ }
805
+ catch {
806
+ /* best-effort */
807
+ }
808
+ try {
809
+ s.end?.(undefined);
810
+ }
811
+ catch {
812
+ /* already torn down */
813
+ }
814
+ };
815
+ const scheduleReconnect = (opts = {}) => {
816
+ if (closed || reconnectTimer)
817
+ return;
818
+ if (reconnectAttempts >= RECONNECT_MAX_ATTEMPTS) {
819
+ args.log("WhatsApp reconnect attempts exhausted — giving up until restart", {
820
+ attempts: reconnectAttempts,
821
+ });
822
+ return;
823
+ }
824
+ // `immediate: true` is set by the 515 first-link recovery path — we know
825
+ // the creds just landed and there's no rate-limit risk reconnecting at
826
+ // once. Skipping the 2s backoff turns a 7-second pair into a 2-second
827
+ // pair and avoids a window where neither socket nor timer is anchoring
828
+ // the Node event loop. For drop recoveries we keep the jittered backoff.
829
+ const delay = opts.immediate ? 0 : backoffDelay(reconnectAttempts);
830
+ reconnectAttempts += 1;
831
+ // During linkMode the CLI is rendering a polished status; the technical
832
+ // "reconnecting attempt=N delayMs=…" line would clutter the link UX.
833
+ // Gateway mode keeps the structured log — operators want that detail.
834
+ if (!args.linkMode) {
835
+ args.log("WhatsApp reconnecting", { attempt: reconnectAttempts, delayMs: delay });
836
+ }
837
+ reconnectTimer = setTimeout(() => {
838
+ reconnectTimer = null;
839
+ if (closed)
840
+ return;
841
+ // Flush any pending creds write first (covers the 515 first-link race),
842
+ // then build a fresh socket on the same creds.
843
+ void pendingCredsSave
844
+ .catch(() => { })
845
+ .then(() => {
846
+ if (closed)
847
+ return;
848
+ sock = buildSocket();
849
+ });
850
+ }, delay);
851
+ // In gateway mode we `.unref()` so a permanently-broken link can't keep
852
+ // the daemon alive across shutdown. In linkMode we MUST NOT unref — the
853
+ // CLI's outer `await done` is the only thing holding the event loop
854
+ // open across the brief gap between socket teardown and rebuild; an
855
+ // unref'd timer plus a torn-down socket = nothing anchoring the loop,
856
+ // which surfaces as "Detected unsettled top-level await" and an early
857
+ // exit BEFORE the new socket reaches `open`.
858
+ if (!args.linkMode)
859
+ reconnectTimer.unref?.();
860
+ };
861
+ const buildSocket = () => {
862
+ const s = makeWASocket({
863
+ version,
864
+ // biome-ignore lint/suspicious/noExplicitAny: pino-shaped stub logger
865
+ logger: baileysLogger,
866
+ printQRInTerminal: false,
867
+ browser: ["Brigade", "Chrome", "1.0.0"],
868
+ syncFullHistory: false,
869
+ markOnlineOnConnect: false,
870
+ // Explicit timeouts + keepalive. Baileys' defaults work in
871
+ // well-connected environments but leave the door open to slow
872
+ // silent failures over flaky networks: keepalive at 25s sits
873
+ // under WhatsApp's typical 30s server-side idle threshold so
874
+ // the link gets nudged before the server marks it offline; the
875
+ // 60s connect/query timeouts give Baileys enough headroom on
876
+ // the initial handshake without dragging shutdown.
877
+ keepAliveIntervalMs: 25_000,
878
+ connectTimeoutMs: 60_000,
879
+ defaultQueryTimeoutMs: 60_000,
880
+ retryRequestDelayMs: 250,
881
+ qrTimeout: 60_000,
882
+ auth: {
883
+ creds: state.creds,
884
+ // biome-ignore lint/suspicious/noExplicitAny: pino-shaped stub logger
885
+ keys: makeCacheableSignalKeyStore(state.keys, baileysLogger),
886
+ },
887
+ });
888
+ const credsUpdateHandler = () => {
889
+ pendingCredsSave = Promise.resolve(saveCreds()).catch((err) => {
890
+ args.log("failed saving WhatsApp creds", { error: err instanceof Error ? err.message : String(err) });
891
+ });
892
+ };
893
+ s.ev.on("creds.update", credsUpdateHandler);
894
+ registerDetach(s, () => {
895
+ s.ev.off?.("creds.update", credsUpdateHandler);
896
+ });
897
+ const connectionUpdateHandler = (update) => {
898
+ // Wrap the whole handler — a throw inside a Baileys event emit would
899
+ // otherwise surface as an unhandled rejection and could crash the daemon.
900
+ try {
901
+ const { connection, lastDisconnect, qr } = update;
902
+ // Offline-queue flush signal — WhatsApp sets
903
+ // `receivedPendingNotifications: true` on `connection.update` once it
904
+ // has delivered everything that arrived while the device was away.
905
+ // That's positive proof inbound is flowing (not a connected-but-deaf
906
+ // socket), so we disarm the connect-time liveness probe and announce
907
+ // the catch-up — the operator sees "turned it on → immediately caught
908
+ // up", even after a week away.
909
+ if (update.receivedPendingNotifications) {
910
+ if (!pendingNotificationsSeen) {
911
+ pendingNotificationsSeen = true;
912
+ coldStartKicks = 0;
913
+ clearColdStartHealth();
914
+ if (!args.linkMode)
915
+ args.log("WhatsApp caught up — offline message queue flushed");
916
+ }
917
+ }
918
+ // Dedupe QR refreshes — Baileys re-emits the same string on its own
919
+ // polling cadence; only forward when the QR actually changed so the
920
+ // operator's terminal doesn't fill with identical QR codes.
921
+ if (qr && qr !== lastQr) {
922
+ lastQr = qr;
923
+ args.onQr?.(qr);
924
+ }
925
+ if (connection === "open") {
926
+ reconnectAttempts = 0; // healthy link — reset backoff
927
+ lastQr = null; // any future QR is genuinely a re-pair
928
+ const now = Date.now();
929
+ lastInboundAt = now; // coarse "frames flowing" reset on fresh link
930
+ lastActivityAt = now; // watchdog clock reset on fresh link
931
+ connectedAtMs = now; // anchor the pairing-grace window
932
+ pendingNotificationsSeen = false; // re-arm the connect-time liveness probe
933
+ clearColdStartHealth();
934
+ // Gateway mode: always log the structured event.
935
+ // Link mode: the CLI renders the polished success card itself,
936
+ // so suppress the duplicate "connected" log here.
937
+ if (!args.linkMode)
938
+ args.log("connected to WhatsApp");
939
+ args.onConnected?.();
940
+ // Tell WhatsApp's server we're online and ready for queued
941
+ // messages. Without this nudge the server can sit on queued
942
+ // inbound for hours (boot connection silent until a later
943
+ // reconnect happens to push the queue) — exactly the overnight
944
+ // "connected but no messages" failure mode. Fires on EVERY
945
+ // fresh `open`, not just the first connect, so watchdog-
946
+ // triggered reconnects also reannounce presence. `queueMicrotask`
947
+ // so `onConnected` callers see the connection before any
948
+ // outbound traffic.
949
+ if (!args.linkMode) {
950
+ queueMicrotask(() => {
951
+ const live = sock;
952
+ if (!live)
953
+ return;
954
+ void Promise.resolve()
955
+ .then(() => live.sendPresenceUpdate?.("available"))
956
+ .catch((err) => {
957
+ args.log("WhatsApp presence-update on open failed", {
958
+ error: err instanceof Error ? err.message : String(err),
959
+ });
960
+ });
961
+ });
962
+ // Cold-start nudges. The single presence-update above is
963
+ // often not enough to convince WhatsApp's server the device
964
+ // is "really" ready — there's a server-side debounce that
965
+ // otherwise holds the queue for ~60s before flushing. Three
966
+ // quick re-pings during the cold window pull that floor
967
+ // down to ~5-15s. Self-cancel as soon as real inbound
968
+ // flows (see the per-message loop). New nudges replace any
969
+ // stale ones from a prior `open` event in the same lifetime.
970
+ clearColdStartNudges();
971
+ for (const offset of COLD_START_NUDGES_MS) {
972
+ const timer = setTimeout(() => {
973
+ if (closed)
974
+ return;
975
+ const live = sock;
976
+ if (!live)
977
+ return;
978
+ void Promise.resolve()
979
+ .then(() => live.sendPresenceUpdate?.("available"))
980
+ .catch((err) => {
981
+ args.log("WhatsApp cold-start presence-nudge failed", {
982
+ offsetMs: offset,
983
+ error: err instanceof Error ? err.message : String(err),
984
+ });
985
+ });
986
+ }, offset);
987
+ timer.unref?.();
988
+ coldStartNudgeTimers.push(timer);
989
+ }
990
+ // Arm the periodic presence ping (idle keepalive nudge).
991
+ // Cleared by `teardownSocket` on the next reconnect / close.
992
+ if (presencePingTimer)
993
+ clearInterval(presencePingTimer);
994
+ const pingInterval = presencePingMs();
995
+ presencePingTimer = setInterval(() => {
996
+ if (closed)
997
+ return;
998
+ const live = sock;
999
+ if (!live)
1000
+ return;
1001
+ void Promise.resolve()
1002
+ .then(() => live.sendPresenceUpdate?.("available"))
1003
+ .catch((err) => {
1004
+ args.log("WhatsApp presence-ping failed", {
1005
+ error: err instanceof Error ? err.message : String(err),
1006
+ });
1007
+ });
1008
+ }, pingInterval);
1009
+ presencePingTimer.unref?.();
1010
+ // Arm the max-session-age recycle. After N hours we force a
1011
+ // clean reconnect regardless of how healthy the link looks —
1012
+ // preventive defense against accumulated Signal state drift.
1013
+ if (sessionAgeTimer)
1014
+ clearTimeout(sessionAgeTimer);
1015
+ const sessionAge = maxSessionAgeMs();
1016
+ sessionAgeTimer = setTimeout(() => {
1017
+ if (closed)
1018
+ return;
1019
+ args.log("WhatsApp forced reconnect after max session age", {
1020
+ maxAgeMs: sessionAge,
1021
+ });
1022
+ const dying = sock;
1023
+ sock = null;
1024
+ teardownSocket(dying);
1025
+ reconnectAttempts = 0; // preventive recycle isn't a failure
1026
+ scheduleReconnect();
1027
+ }, sessionAge);
1028
+ sessionAgeTimer.unref?.();
1029
+ // Arm the connect-time liveness probe (one-shot per open). If
1030
+ // the offline-queue flush (`receivedPendingNotifications`)
1031
+ // hasn't arrived AND no real inbound has flowed within
1032
+ // COLD_START_HEALTH_MS, the socket is connected-but-deaf — force
1033
+ // ONE immediate clean reconnect so a wedged link wakes up in
1034
+ // ~90s instead of waiting out the 10-minute watchdog. Bounded by
1035
+ // MAX_COLD_START_KICKS so a legitimately slow flush of a huge
1036
+ // backlog can't become a reconnect-storm; after that we leave it
1037
+ // to the steady-state watchdog.
1038
+ clearColdStartHealth();
1039
+ coldStartHealthTimer = setTimeout(() => {
1040
+ if (closed || !sock)
1041
+ return;
1042
+ if (pendingNotificationsSeen)
1043
+ return; // queue flushed / inbound flowed — healthy
1044
+ if (Date.now() - lastActivityAt < COLD_START_HEALTH_MS)
1045
+ return; // real inbound recently
1046
+ if (coldStartKicks >= MAX_COLD_START_KICKS) {
1047
+ args.log("WhatsApp liveness probe — still no inbound after retries; leaving it to the watchdog", {
1048
+ kicks: coldStartKicks,
1049
+ });
1050
+ return;
1051
+ }
1052
+ coldStartKicks += 1;
1053
+ args.log("WhatsApp liveness probe — no inbound flow after connect, forcing reconnect to wake the link", {
1054
+ waitedMs: COLD_START_HEALTH_MS,
1055
+ kick: coldStartKicks,
1056
+ });
1057
+ const dying = sock;
1058
+ sock = null;
1059
+ teardownSocket(dying);
1060
+ reconnectAttempts = 0; // liveness kick isn't a failure sequence
1061
+ scheduleReconnect({ immediate: true });
1062
+ }, COLD_START_HEALTH_MS);
1063
+ coldStartHealthTimer.unref?.();
1064
+ }
1065
+ }
1066
+ if (connection === "close") {
1067
+ const status = lastDisconnect?.error?.output
1068
+ ?.statusCode;
1069
+ // Tear the dead socket down BEFORE doing anything else so its
1070
+ // listeners can't fire again (no leak, no duplicate inbound).
1071
+ teardownSocket(s);
1072
+ if (sock === s)
1073
+ sock = null;
1074
+ // If this socket lived for more than LONG_SESSION_RESET_MS, the
1075
+ // close is a fresh flap — not the continuation of a failing
1076
+ // reconnect sequence. Reset the attempt counter so the new
1077
+ // flap gets the full 12-retry budget instead of inheriting a
1078
+ // burned-down one from earlier in the day. Without this guard,
1079
+ // a single transient blip after a healthy 2-hour session can
1080
+ // exhaust the budget within minutes.
1081
+ if (connectedAtMs !== null &&
1082
+ Date.now() - connectedAtMs >= LONG_SESSION_RESET_MS &&
1083
+ reconnectAttempts > 0) {
1084
+ reconnectAttempts = 0;
1085
+ }
1086
+ if (status === loggedOutCode) {
1087
+ args.log("WhatsApp session logged out — re-link required");
1088
+ args.onLoggedOut?.();
1089
+ return; // dead creds — never reconnect
1090
+ }
1091
+ if (status === MULTI_DEVICE_CONFLICT_CODE) {
1092
+ // A new WhatsApp Web session opened against the same number
1093
+ // (another linked Brigade, a manual Web login, or the
1094
+ // operator scanning the QR somewhere else). Reconnecting
1095
+ // here would put us into a 440-conflict ping-pong with the
1096
+ // other session — both reconnect, both see 440, both
1097
+ // reconnect, forever. Treat as terminal; the operator must
1098
+ // resolve which session keeps the link.
1099
+ args.log("WhatsApp multi-device conflict — another linked Web session took over; not reconnecting");
1100
+ args.onLoggedOut?.();
1101
+ return;
1102
+ }
1103
+ if (status === restartRequiredCode) {
1104
+ // Expected immediately after first-link; reconnect promptly
1105
+ // without consuming the backoff budget. This single hop is
1106
+ // honored even in linkMode — it's part of the pair handshake.
1107
+ // During linkMode we emit a single polished progress string
1108
+ // instead of the technical "restart required" log; the CLI
1109
+ // renders it as "Finalising link…" — much friendlier than
1110
+ // "restart required → reconnecting" which sounds like an error.
1111
+ if (args.linkMode) {
1112
+ args.onLinkProgress?.("Finalising link…");
1113
+ }
1114
+ else {
1115
+ args.log("WhatsApp restart required (post-link) — reconnecting");
1116
+ }
1117
+ reconnectAttempts = 0;
1118
+ // Immediate reconnect — the creds-flush promise still gates
1119
+ // the rebuild, but there's no jittered 2s delay. Halves the
1120
+ // total link time and closes the unref'd-timer race window.
1121
+ scheduleReconnect({ immediate: true });
1122
+ return;
1123
+ }
1124
+ // In one-shot link mode, treat any non-515 close as a hard failure
1125
+ // so the link command's outer timeout / failure path can act on it.
1126
+ // The gateway path keeps the auto-reconnect (its job IS to stay up).
1127
+ if (args.linkMode) {
1128
+ args.log("WhatsApp connection dropped during link — aborting (linkMode)", { status });
1129
+ return;
1130
+ }
1131
+ scheduleReconnect();
1132
+ }
1133
+ }
1134
+ catch (err) {
1135
+ args.log("WhatsApp connection.update handler error", {
1136
+ error: err instanceof Error ? err.message : String(err),
1137
+ });
1138
+ }
1139
+ };
1140
+ s.ev.on("connection.update", connectionUpdateHandler);
1141
+ registerDetach(s, () => {
1142
+ s.ev.off?.("connection.update", connectionUpdateHandler);
1143
+ });
1144
+ const messagesUpsertHandler = (payload) => {
1145
+ // `notify` = live messages. `append` = the offline/history catch-up
1146
+ // batch WhatsApp delivers on (re)connect — the messages that arrived
1147
+ // while the device was away. We accept BOTH (mirrors the reference
1148
+ // codebase) so a gateway turned on after a long offline window
1149
+ // immediately surfaces what it missed; the per-message handler gates
1150
+ // `append` to RECENT entries (within APPEND_RECENT_GRACE_MS of connect)
1151
+ // so we catch genuinely-missed live messages without replaying the
1152
+ // whole backlog of old chats.
1153
+ if (payload.type !== "notify" && payload.type !== "append")
1154
+ return;
1155
+ const upsertType = payload.type;
1156
+ // Coarse "frames are flowing" clock — bumped on ANY notify, including
1157
+ // status broadcasts and other passthrough traffic. This proves the
1158
+ // transport is alive but says nothing about real inbound delivery,
1159
+ // so the watchdog does NOT read it. Telemetry / back-compat only.
1160
+ lastInboundAt = Date.now();
1161
+ // Process each message in its own async task so media download (a
1162
+ // network round-trip) doesn't block the next message's dedupe claim.
1163
+ for (const m of payload.messages) {
1164
+ void (async () => {
1165
+ try {
1166
+ const jid = m.key.remoteJid;
1167
+ if (!jid)
1168
+ return;
1169
+ // Status/broadcast feeds — both legacy (`status@broadcast`) and
1170
+ // the suffix variants (`…@status`, `…@broadcast`) — are story
1171
+ // updates, never DMs to react to. They must NOT bump the
1172
+ // watchdog clock: if a contact posts a story every few
1173
+ // minutes, those notifies would otherwise keep the watchdog
1174
+ // satisfied while real DMs were silently queued server-side.
1175
+ if (jid === "status@broadcast" || jid.endsWith("@status") || jid.endsWith("@broadcast"))
1176
+ return;
1177
+ // Real DM/group inbound — bump the watchdog clock. From this
1178
+ // point on we know we've got actual conversational traffic.
1179
+ lastActivityAt = Date.now();
1180
+ // Cancel any pending cold-start nudges — the queue is open
1181
+ // and flowing, no need to keep nagging the server.
1182
+ if (coldStartNudgeTimers.length > 0)
1183
+ clearColdStartNudges();
1184
+ // Real inbound (live OR offline catch-up) proves delivery is
1185
+ // flowing — disarm the connect-time liveness probe.
1186
+ pendingNotificationsSeen = true;
1187
+ clearColdStartHealth();
1188
+ // History/offline catch-up (`append`) — process only RECENT
1189
+ // entries so a reconnect after a long offline window surfaces
1190
+ // genuinely-missed live messages without replaying the whole
1191
+ // backlog of old chats. Mirrors the reference codebase's
1192
+ // APPEND_RECENT_GRACE_MS gate. `notify` messages are always
1193
+ // live and skip this check.
1194
+ if (upsertType === "append") {
1195
+ const APPEND_RECENT_GRACE_MS = 60_000;
1196
+ const tsRaw = m.messageTimestamp;
1197
+ const tsSec = typeof tsRaw === "number"
1198
+ ? tsRaw
1199
+ : tsRaw && typeof tsRaw.toNumber === "function"
1200
+ ? tsRaw.toNumber()
1201
+ : 0;
1202
+ const tsMs = tsSec > 0 ? tsSec * 1000 : 0;
1203
+ if (connectedAtMs !== null && tsMs < connectedAtMs - APPEND_RECENT_GRACE_MS)
1204
+ return;
1205
+ }
1206
+ const isGroup = jid.endsWith("@g.us");
1207
+ const msgId = m.key.id;
1208
+ // `fromMe` handling. WhatsApp surfaces TWO distinct flavours of
1209
+ // `fromMe: true` messages through the same `messages.upsert`
1210
+ // event, and they must be handled completely differently:
1211
+ //
1212
+ // (a) ECHO of an outbound Brigade just sent — `msgId` is in
1213
+ // `outboundDedupe` (we remembered it on send). Always
1214
+ // drop; it's not user input.
1215
+ //
1216
+ // (b) OPERATOR TYPED ON A LINKED DEVICE (their phone, web,
1217
+ // another linked Brigade) — `msgId` is fresh. This branches:
1218
+ //
1219
+ // (b1) DM to a CONTACT (chat jid ≠ operator's own phone):
1220
+ // the operator messaging Mom from their phone. Brigade
1221
+ // MUST NOT engage with this — otherwise we'd send
1222
+ // Mom a pairing-challenge card from the operator's
1223
+ // own account. Drop silently. Matches the upstream
1224
+ // reference's access-control.ts:136-144 "Skipping outbound DM".
1225
+ //
1226
+ // (b2) SELF-CHAT (chat jid == operator's own phone): the
1227
+ // "notes-to-self" use case. Flow through as normal
1228
+ // inbound; the bot responds.
1229
+ //
1230
+ // (b3) GROUP: fall through so policy.ts can apply the
1231
+ // standard group rules. The operator is NOT auto-
1232
+ // allowed in groups — a group the operator hasn't
1233
+ // opted in (via `groupAllowJids`, or by being on the
1234
+ // group allow-from list) is dropped with reason
1235
+ // `group:not-allowlisted`, even for the operator's
1236
+ // own messages and self-tags.
1237
+ if (m.key.fromMe) {
1238
+ // (a) — known echo of our own outbound.
1239
+ if (!msgId || outboundDedupe.peek(outboundKey(jid, msgId)))
1240
+ return;
1241
+ // (b1) — operator messaged a contact from a linked device.
1242
+ // Detect by comparing the chat jid's canonical phone to the
1243
+ // linked self id. Resolution gates on having BOTH — without
1244
+ // either, we conservatively drop (better to miss a self-
1245
+ // chat than to spam a contact with a pairing card).
1246
+ if (!isGroup) {
1247
+ const selfPhone = canonicalWhatsAppId(sock?.user?.id);
1248
+ const chatPhone = await resolveJidToE164(sock, jid, args.authDir, connectionAccountId);
1249
+ const isSelfChat = !!(selfPhone && chatPhone && selfPhone === chatPhone);
1250
+ if (!isSelfChat) {
1251
+ args.log("dropped operator outbound DM (fromMe, not self-chat)", {
1252
+ jid,
1253
+ msgId,
1254
+ });
1255
+ return;
1256
+ }
1257
+ }
1258
+ // (b2) self-chat, or (b3) group: fall through.
1259
+ }
1260
+ // Drop duplicates of the same message — WhatsApp re-delivers the
1261
+ // same `msg.key.id` after a reconnect; without this guard the agent
1262
+ // would run twice (and bill twice) per real message.
1263
+ if (msgId && !inboundDedupe.claim(`${jid}:${msgId}`)) {
1264
+ args.log("dropped duplicate inbound (already processed)", { jid, msgId });
1265
+ return;
1266
+ }
1267
+ const normalized = normalizeMessageContent(m.message);
1268
+ const text = extractText(m.message, normalizeMessageContent).trim();
1269
+ // Media download is DEFERRED. Only a cheap envelope probe runs
1270
+ // here; the actual download (bytes from WhatsApp + seal +
1271
+ // backend archive) happens via `resolveMedia` AFTER the
1272
+ // pipeline's access-control gate admits the sender. Eager
1273
+ // download meant any stranger in any group could push videos
1274
+ // into the operator's storage even though the message itself
1275
+ // was dropped by policy.
1276
+ const hasMedia = !!(normalized && msgId) && hasInboundMedia(normalized);
1277
+ const resolveMedia = hasMedia && normalized && msgId
1278
+ ? () => downloadInboundMedia({
1279
+ content: normalized,
1280
+ msgId,
1281
+ downloadMediaMessage: baileys.downloadMediaMessage,
1282
+ rawMessage: m,
1283
+ log: args.log,
1284
+ })
1285
+ : undefined;
1286
+ // Drop the message entirely only if there's no text AND no media.
1287
+ if (!text && !hasMedia)
1288
+ return;
1289
+ // Sender resolution. For DMs the chat jid itself is the sender;
1290
+ // for groups the per-message `participant` carries the speaker.
1291
+ // We resolve to a STABLE identity that NEVER drops a usable
1292
+ // sender (mirrors the reference codebase): the phone number when
1293
+ // the LID can be mapped, otherwise the canonical `@lid` alias
1294
+ // itself — so a group message from a privacy-aliased member
1295
+ // still reaches the access-control gate instead of vanishing at
1296
+ // the socket layer. Only a genuinely empty/unusable jid drops.
1297
+ const rawParticipant = m.key.participant?.trim();
1298
+ const senderJid = isGroup && rawParticipant && rawParticipant.length > 0 ? rawParticipant : jid;
1299
+ const senderIdentity = await resolveSenderIdentity(sock, senderJid, args.authDir, connectionAccountId);
1300
+ if (!senderIdentity) {
1301
+ args.log("inbound dropped — empty/unusable sender jid", {
1302
+ jid,
1303
+ participant: rawParticipant,
1304
+ });
1305
+ return;
1306
+ }
1307
+ const fromCanonical = senderIdentity.id;
1308
+ const senderLid = senderIdentity.lid;
1309
+ // Mentions + quoted-reply context come from the normalized message;
1310
+ // pulled here so the manager can gate group activation cleanly and
1311
+ // the LLM gets the "user replied to X" context for free. Async
1312
+ // because LID mentions need the same resolver above.
1313
+ const mentions = normalized
1314
+ ? await extractMentions(normalized, sock, args.authDir, connectionAccountId)
1315
+ : [];
1316
+ const replyTo = normalized
1317
+ ? await extractReplyContext(normalized, sock, args.authDir, connectionAccountId)
1318
+ : undefined;
1319
+ // Baileys' `messageTimestamp` is in seconds (Long or number).
1320
+ // Normalize to epoch ms; the manager uses this to decide
1321
+ // whether a stranger's DM is "live" or "since-restart
1322
+ // history" for the pairing-grace window.
1323
+ const tsRaw = m.messageTimestamp;
1324
+ const tsSec = typeof tsRaw === "number"
1325
+ ? tsRaw
1326
+ : tsRaw && typeof tsRaw.toNumber === "function"
1327
+ ? tsRaw.toNumber()
1328
+ : undefined;
1329
+ args.onMessage({
1330
+ conversationId: jid,
1331
+ messageId: msgId ?? undefined,
1332
+ participantId: isGroup ? rawParticipant : undefined,
1333
+ messageTimestampMs: typeof tsSec === "number" && tsSec > 0 ? tsSec * 1000 : undefined,
1334
+ from: fromCanonical,
1335
+ senderLid,
1336
+ fromName: m.pushName ?? undefined,
1337
+ text,
1338
+ chatType: isGroup ? "group" : "direct",
1339
+ mentions: mentions.length > 0 ? mentions : undefined,
1340
+ replyTo,
1341
+ ...(resolveMedia ? { resolveMedia } : {}),
1342
+ raw: m,
1343
+ });
1344
+ }
1345
+ catch (err) {
1346
+ args.log("failed to process inbound message", {
1347
+ error: err instanceof Error ? err.message : String(err),
1348
+ });
1349
+ }
1350
+ })();
1351
+ }
1352
+ };
1353
+ s.ev.on("messages.upsert", messagesUpsertHandler);
1354
+ registerDetach(s, () => {
1355
+ s.ev.off?.("messages.upsert", messagesUpsertHandler);
1356
+ });
1357
+ // Surface socket-level WS errors instead of crashing the process.
1358
+ const ws = s.ws;
1359
+ const wsErrorHandler = (err) => args.log("WhatsApp socket error", { error: String(err) });
1360
+ ws?.on?.("error", wsErrorHandler);
1361
+ registerDetach(s, () => {
1362
+ ws?.off?.("error", wsErrorHandler);
1363
+ });
1364
+ return s;
1365
+ };
1366
+ sock = buildSocket();
1367
+ // Watchdog — once-a-minute check that WhatsApp is still delivering REAL
1368
+ // inbound. Reads `lastActivityAt` (post-filter) so a stream of story-
1369
+ // broadcast notifies on an otherwise-silent link can't keep us asleep.
1370
+ // If we go past the stale threshold, force a reconnect so the operator
1371
+ // doesn't sit there wondering why nothing arrives. Disabled in linkMode
1372
+ // (one-shot pair, no daemon).
1373
+ if (!args.linkMode) {
1374
+ watchdogTimer = setInterval(() => {
1375
+ if (closed || !sock)
1376
+ return;
1377
+ const elapsed = Date.now() - lastActivityAt;
1378
+ if (elapsed < WATCHDOG_STALE_MS)
1379
+ return;
1380
+ args.log("WhatsApp watchdog — no inbound activity, forcing reconnect", {
1381
+ elapsedMs: elapsed,
1382
+ staleThresholdMs: WATCHDOG_STALE_MS,
1383
+ });
1384
+ const dying = sock;
1385
+ sock = null;
1386
+ teardownSocket(dying);
1387
+ scheduleReconnect();
1388
+ // Reset the clock so a flapping link doesn't trigger another forced
1389
+ // reconnect before the new socket has a chance to open.
1390
+ lastActivityAt = Date.now();
1391
+ lastInboundAt = Date.now();
1392
+ }, WATCHDOG_CHECK_MS);
1393
+ watchdogTimer.unref?.();
1394
+ }
1395
+ // Trap Signal-protocol crypto rejections (declared earlier in this
1396
+ // function; see `onUnhandledRejection`). Registered here, AFTER
1397
+ // `teardownSocket` and `scheduleReconnect` are in scope, and removed in
1398
+ // `close()` so a torn-down connection's handler doesn't survive past
1399
+ // the lifecycle that armed it.
1400
+ if (!args.linkMode) {
1401
+ process.on("unhandledRejection", onUnhandledRejection);
1402
+ }
1403
+ const delay = (ms) => new Promise((r) => setTimeout(r, ms).unref?.());
1404
+ /**
1405
+ * Send one chunk with retry on transient send failures. A WebSocket flap
1406
+ * during a reply would otherwise drop the message silently — Baileys throws
1407
+ * "Connection Closed" / "WS not open" until the auto-reconnect lands a
1408
+ * fresh socket. We back off and retry against the LIVE `sock` reference (so
1409
+ * a reconnect-replaced socket is used on the next attempt). Permanent
1410
+ * errors (e.g. "jid not registered") propagate after the first try.
1411
+ */
1412
+ const TRANSIENT_SEND_ERROR = /closed|reset|timed?\s*out|disconnect|not\s*open|stream\s*error|ws/i;
1413
+ const SEND_MAX_ATTEMPTS = 3;
1414
+ /**
1415
+ * Run an outbound send against the LIVE `sock` reference with retry on
1416
+ * transient WS / disconnect errors. Used by text / media / reaction /
1417
+ * presence paths so a single reconnect mid-flight doesn't silently drop
1418
+ * the send. Permanent errors (e.g. "jid not registered") propagate after
1419
+ * the first try. `kind` is just a log tag — every line for one send shares
1420
+ * a correlation id so operators can grep for it.
1421
+ */
1422
+ async function sendWithRetry(kind, send, log, extra) {
1423
+ const correlationId = `wa-${Date.now().toString(36)}-${Math.floor(Math.random() * 1e6).toString(36)}`;
1424
+ const startedAt = Date.now();
1425
+ let lastErr;
1426
+ for (let attempt = 1; attempt <= SEND_MAX_ATTEMPTS; attempt++) {
1427
+ const live = sock;
1428
+ if (live) {
1429
+ try {
1430
+ const result = await send(live);
1431
+ log(`WhatsApp ${kind} ok`, {
1432
+ correlationId,
1433
+ attempt,
1434
+ durationMs: Date.now() - startedAt,
1435
+ ...extra,
1436
+ });
1437
+ return result;
1438
+ }
1439
+ catch (err) {
1440
+ lastErr = err;
1441
+ const message = err instanceof Error ? err.message : String(err);
1442
+ if (!TRANSIENT_SEND_ERROR.test(message)) {
1443
+ log(`WhatsApp ${kind} permanent error`, { correlationId, attempt, error: message });
1444
+ throw err;
1445
+ }
1446
+ log(`WhatsApp ${kind} transient — retrying`, { correlationId, attempt, error: message });
1447
+ }
1448
+ }
1449
+ else {
1450
+ lastErr = new Error("WhatsApp socket not connected");
1451
+ log(`WhatsApp ${kind} paused — socket reconnecting`, { correlationId, attempt });
1452
+ }
1453
+ if (attempt < SEND_MAX_ATTEMPTS)
1454
+ await delay(500 * attempt);
1455
+ }
1456
+ log(`WhatsApp ${kind} failed after retries`, {
1457
+ correlationId,
1458
+ attempts: SEND_MAX_ATTEMPTS,
1459
+ durationMs: Date.now() - startedAt,
1460
+ error: lastErr instanceof Error ? lastErr.message : String(lastErr),
1461
+ });
1462
+ throw lastErr ?? new Error(`WhatsApp ${kind} failed after retries`);
1463
+ }
1464
+ /** Send a single text chunk with retry. Records the outbound id for echo-dedupe. */
1465
+ async function sendOneChunkWithRetry(conversationId, chunk, log) {
1466
+ const result = await sendWithRetry("send", async (live) => (await live.sendMessage(conversationId, { text: chunk })), log, { chunkBytes: chunk.length });
1467
+ // Remember the outbound message id so the inbound `fromMe` echo
1468
+ // can be distinguished from a genuine self-chat message (see
1469
+ // outboundDedupe in the upsert handler).
1470
+ recordOutboundId(conversationId, result?.key?.id);
1471
+ }
1472
+ return {
1473
+ current: () => sock,
1474
+ selfId: () => canonicalWhatsAppId(sock?.user?.id) || null,
1475
+ connectedAt: () => connectedAtMs,
1476
+ lastInboundAt: () => lastInboundAt,
1477
+ lastActivityAt: () => lastActivityAt,
1478
+ async sendText(conversationId, text) {
1479
+ // Convert agent-style markdown (**bold**, headings, tables, [links])
1480
+ // into WhatsApp's sparse formatting (*bold*, • bullets, "label (url)")
1481
+ // before splitting. Otherwise raw `**` / `|` / `###` leak into chat.
1482
+ const wa = markdownToWhatsApp(text);
1483
+ // Split long replies into WhatsApp-sized chunks (~4000 chars, fence-
1484
+ // aware). Each chunk goes through its own retry loop so a transient
1485
+ // reconnect mid-reply doesn't lose the rest of the message.
1486
+ const chunks = chunkText(wa);
1487
+ // Show "composing…" once at the start of a multi-chunk reply so the
1488
+ // recipient sees "typing…" while the LLM was thinking AND while we're
1489
+ // sending. Best-effort — failure here never breaks the send.
1490
+ try {
1491
+ await sock?.sendPresenceUpdate?.("composing", conversationId);
1492
+ }
1493
+ catch {
1494
+ /* presence is cosmetic */
1495
+ }
1496
+ for (let i = 0; i < chunks.length; i++) {
1497
+ await sendOneChunkWithRetry(conversationId, chunks[i], args.log);
1498
+ if (i < chunks.length - 1)
1499
+ await delay(150);
1500
+ }
1501
+ // Reset presence so the bot doesn't show as "typing forever".
1502
+ try {
1503
+ await sock?.sendPresenceUpdate?.("paused", conversationId);
1504
+ }
1505
+ catch {
1506
+ /* ignore */
1507
+ }
1508
+ },
1509
+ async sendMedia(conversationId, media) {
1510
+ // Map Brigade's media kind onto Baileys' payload shape. Caption rides
1511
+ // the media (a single message) so the agent doesn't have to issue two
1512
+ // sends; voice = audio + ptt=true with opus mime.
1513
+ const url = media.path; // Baileys accepts an absolute path for `url`.
1514
+ // SECURITY — refuse to upload a local secret/system file. media.path can be
1515
+ // agent/tool-supplied, so a prompt-injected "send ~/.ssh/id_rsa" (or
1516
+ // Brigade's own sealed auth) would otherwise exfiltrate it to the chat.
1517
+ const mediaGuard = validateOutboundMediaPath(url);
1518
+ if (!mediaGuard.ok) {
1519
+ args.log?.(`sendMedia blocked: ${mediaGuard.reason}`);
1520
+ throw new Error(`Refusing to send this file — ${mediaGuard.reason}.`);
1521
+ }
1522
+ const captionWa = media.caption ? markdownToWhatsApp(media.caption) : undefined;
1523
+ let payload;
1524
+ switch (media.kind) {
1525
+ case "image":
1526
+ payload = { image: { url }, mimetype: media.mimeType ?? "image/jpeg", caption: captionWa };
1527
+ break;
1528
+ case "video":
1529
+ payload = { video: { url }, mimetype: media.mimeType ?? "video/mp4", caption: captionWa };
1530
+ break;
1531
+ case "audio":
1532
+ payload = { audio: { url }, mimetype: media.mimeType ?? "audio/mpeg", ptt: false };
1533
+ break;
1534
+ case "voice":
1535
+ payload = { audio: { url }, mimetype: media.mimeType ?? "audio/ogg; codecs=opus", ptt: true };
1536
+ break;
1537
+ case "document":
1538
+ payload = {
1539
+ document: { url },
1540
+ mimetype: media.mimeType ?? "application/octet-stream",
1541
+ fileName: media.fileName,
1542
+ caption: captionWa,
1543
+ };
1544
+ break;
1545
+ case "sticker":
1546
+ payload = { sticker: { url }, mimetype: media.mimeType ?? "image/webp" };
1547
+ break;
1548
+ }
1549
+ // Same transient-retry shape as text — a reconnect mid-upload
1550
+ // otherwise drops the media silently. The actual Baileys upload
1551
+ // happens inside `live.sendMessage`; if it fails transiently we
1552
+ // retry against whatever socket the reconnect loop hands us next.
1553
+ const mediaResult = await sendWithRetry(`sendMedia(${media.kind})`, async (live) => (await live.sendMessage(conversationId, payload)), args.log);
1554
+ recordOutboundId(conversationId, mediaResult?.key?.id);
1555
+ },
1556
+ async react(conversationId, messageId, emoji, fromMe) {
1557
+ // Reactions need the original message's key (jid + id + fromMe). When
1558
+ // the caller only has the inbound's id (the common case), pass
1559
+ // fromMe=false; for clearing our own reaction, pass fromMe=true.
1560
+ // Wrapped in sendWithRetry so a transient reconnect mid-reaction
1561
+ // doesn't silently drop it (reactions are cheap; better to retry
1562
+ // than to leave a half-acknowledged inbound).
1563
+ const reactResult = await sendWithRetry("react", async (live) => (await live.sendMessage(conversationId, {
1564
+ react: {
1565
+ text: emoji, // "" clears any prior reaction
1566
+ key: { remoteJid: conversationId, id: messageId, fromMe: fromMe ?? false },
1567
+ },
1568
+ })), args.log);
1569
+ recordOutboundId(conversationId, reactResult?.key?.id);
1570
+ },
1571
+ async markRead(conversationId, messageId, participant) {
1572
+ // Read receipts are cosmetic — drop silently when the socket is
1573
+ // reconnecting or the platform refuses (e.g. account hasn't opted
1574
+ // into read receipts globally).
1575
+ try {
1576
+ await sock?.readMessages?.([
1577
+ {
1578
+ remoteJid: conversationId,
1579
+ id: messageId,
1580
+ ...(participant ? { participant } : {}),
1581
+ },
1582
+ ]);
1583
+ }
1584
+ catch {
1585
+ /* cosmetic */
1586
+ }
1587
+ },
1588
+ async setComposing(conversationId, state) {
1589
+ try {
1590
+ await sock?.sendPresenceUpdate?.(state, conversationId);
1591
+ }
1592
+ catch {
1593
+ /* cosmetic */
1594
+ }
1595
+ },
1596
+ async close() {
1597
+ closed = true;
1598
+ if (reconnectTimer) {
1599
+ clearTimeout(reconnectTimer);
1600
+ reconnectTimer = null;
1601
+ }
1602
+ if (watchdogTimer) {
1603
+ clearInterval(watchdogTimer);
1604
+ watchdogTimer = null;
1605
+ }
1606
+ clearColdStartHealth();
1607
+ // Remove the process-level crypto-rejection trap — otherwise a
1608
+ // torn-down connection's handler survives and could touch a `sock`
1609
+ // that's been nulled out (the `closed` guard catches that, but it's
1610
+ // cleaner to deregister).
1611
+ process.off("unhandledRejection", onUnhandledRejection);
1612
+ // `logout()` would invalidate creds; we want a clean disconnect that
1613
+ // keeps the link, so just tear the socket down. (presencePingTimer
1614
+ // + sessionAgeTimer are cleared inside teardownSocket.)
1615
+ teardownSocket(sock);
1616
+ sock = null;
1617
+ // Let a final creds write flush so the link survives a restart.
1618
+ await pendingCredsSave.catch(() => { });
1619
+ // Convex mode: drain the auth-state's write-behind key queue so a
1620
+ // just-completed pair (or any keys written right before close) lands
1621
+ // in the backend. Without this, a `brigade channels link` that exits
1622
+ // immediately after connect can lose the freshly-negotiated keys.
1623
+ if (convexAuthFlush)
1624
+ await convexAuthFlush().catch(() => { });
1625
+ },
1626
+ };
1627
+ }
1628
+ //# sourceMappingURL=connection.js.map