@jungjaehoon/mama-os 0.28.6 → 0.29.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 (448) hide show
  1. package/dist/agent/agent-loop.d.ts +0 -4
  2. package/dist/agent/agent-loop.d.ts.map +1 -1
  3. package/dist/agent/agent-loop.js +33 -10
  4. package/dist/agent/agent-loop.js.map +1 -1
  5. package/dist/agent/code-act/host-bridge.d.ts.map +1 -1
  6. package/dist/agent/code-act/host-bridge.js +53 -3
  7. package/dist/agent/code-act/host-bridge.js.map +1 -1
  8. package/dist/agent/code-act/tool-policy.d.ts.map +1 -1
  9. package/dist/agent/code-act/tool-policy.js +5 -0
  10. package/dist/agent/code-act/tool-policy.js.map +1 -1
  11. package/dist/agent/codex-auth.d.ts +0 -1
  12. package/dist/agent/codex-auth.d.ts.map +1 -1
  13. package/dist/agent/codex-auth.js +0 -4
  14. package/dist/agent/codex-auth.js.map +1 -1
  15. package/dist/agent/codex-home.d.ts +0 -2
  16. package/dist/agent/codex-home.d.ts.map +1 -1
  17. package/dist/agent/codex-home.js +0 -66
  18. package/dist/agent/codex-home.js.map +1 -1
  19. package/dist/agent/context-compile-service.d.ts +9 -0
  20. package/dist/agent/context-compile-service.d.ts.map +1 -1
  21. package/dist/agent/context-compile-service.js +6 -0
  22. package/dist/agent/context-compile-service.js.map +1 -1
  23. package/dist/agent/context-prompt-builder.d.ts +0 -6
  24. package/dist/agent/context-prompt-builder.d.ts.map +1 -1
  25. package/dist/agent/context-prompt-builder.js +0 -131
  26. package/dist/agent/context-prompt-builder.js.map +1 -1
  27. package/dist/agent/contract-extractor.d.ts +0 -4
  28. package/dist/agent/contract-extractor.d.ts.map +1 -1
  29. package/dist/agent/contract-extractor.js +0 -68
  30. package/dist/agent/contract-extractor.js.map +1 -1
  31. package/dist/agent/gateway-tool-executor.d.ts +20 -15
  32. package/dist/agent/gateway-tool-executor.d.ts.map +1 -1
  33. package/dist/agent/gateway-tool-executor.js +236 -90
  34. package/dist/agent/gateway-tool-executor.js.map +1 -1
  35. package/dist/agent/gateway-tools.md +7 -4
  36. package/dist/agent/skill-loader.d.ts +0 -7
  37. package/dist/agent/skill-loader.d.ts.map +1 -1
  38. package/dist/agent/skill-loader.js +0 -86
  39. package/dist/agent/skill-loader.js.map +1 -1
  40. package/dist/agent/token-estimator.d.ts +0 -8
  41. package/dist/agent/token-estimator.d.ts.map +1 -1
  42. package/dist/agent/token-estimator.js +0 -14
  43. package/dist/agent/token-estimator.js.map +1 -1
  44. package/dist/agent/tool-registry.d.ts.map +1 -1
  45. package/dist/agent/tool-registry.js +23 -5
  46. package/dist/agent/tool-registry.js.map +1 -1
  47. package/dist/agent/types.d.ts +27 -1
  48. package/dist/agent/types.d.ts.map +1 -1
  49. package/dist/agent/types.js.map +1 -1
  50. package/dist/api/agent-graph-handler.d.ts +9 -0
  51. package/dist/api/agent-graph-handler.d.ts.map +1 -1
  52. package/dist/api/agent-graph-handler.js +27 -1
  53. package/dist/api/agent-graph-handler.js.map +1 -1
  54. package/dist/api/entity-audit-handler.d.ts +1 -2
  55. package/dist/api/entity-audit-handler.d.ts.map +1 -1
  56. package/dist/api/entity-audit-handler.js +0 -5
  57. package/dist/api/entity-audit-handler.js.map +1 -1
  58. package/dist/api/index.d.ts +1 -9
  59. package/dist/api/index.d.ts.map +1 -1
  60. package/dist/api/index.js +4 -17
  61. package/dist/api/index.js.map +1 -1
  62. package/dist/api/intelligence-handler.d.ts +0 -5
  63. package/dist/api/intelligence-handler.d.ts.map +1 -1
  64. package/dist/api/intelligence-handler.js +0 -15
  65. package/dist/api/intelligence-handler.js.map +1 -1
  66. package/dist/api/types.d.ts +1 -5
  67. package/dist/api/types.d.ts.map +1 -1
  68. package/dist/api/types.js +0 -14
  69. package/dist/api/types.js.map +1 -1
  70. package/dist/cli/commands/start.d.ts +117 -3
  71. package/dist/cli/commands/start.d.ts.map +1 -1
  72. package/dist/cli/commands/start.js +223 -62
  73. package/dist/cli/commands/start.js.map +1 -1
  74. package/dist/cli/config/config-manager.d.ts +0 -5
  75. package/dist/cli/config/config-manager.d.ts.map +1 -1
  76. package/dist/cli/config/config-manager.js +0 -29
  77. package/dist/cli/config/config-manager.js.map +1 -1
  78. package/dist/cli/config/types.d.ts.map +1 -1
  79. package/dist/cli/config/types.js +3 -0
  80. package/dist/cli/config/types.js.map +1 -1
  81. package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
  82. package/dist/cli/runtime/api-routes-init.js +32 -5
  83. package/dist/cli/runtime/api-routes-init.js.map +1 -1
  84. package/dist/cli/runtime/api-server-init.d.ts.map +1 -1
  85. package/dist/cli/runtime/api-server-init.js +2 -0
  86. package/dist/cli/runtime/api-server-init.js.map +1 -1
  87. package/dist/cli/runtime/gateway-init.d.ts +1 -1
  88. package/dist/cli/runtime/gateway-init.d.ts.map +1 -1
  89. package/dist/cli/runtime/gateway-init.js +11 -38
  90. package/dist/cli/runtime/gateway-init.js.map +1 -1
  91. package/dist/cli/runtime/gateway-wiring.d.ts.map +1 -1
  92. package/dist/cli/runtime/gateway-wiring.js +6 -120
  93. package/dist/cli/runtime/gateway-wiring.js.map +1 -1
  94. package/dist/cli/utils/pid-manager.d.ts +0 -10
  95. package/dist/cli/utils/pid-manager.d.ts.map +1 -1
  96. package/dist/cli/utils/pid-manager.js +0 -26
  97. package/dist/cli/utils/pid-manager.js.map +1 -1
  98. package/dist/connectors/framework/polling-scheduler.d.ts +33 -1
  99. package/dist/connectors/framework/polling-scheduler.d.ts.map +1 -1
  100. package/dist/connectors/framework/polling-scheduler.js +46 -40
  101. package/dist/connectors/framework/polling-scheduler.js.map +1 -1
  102. package/dist/connectors/trello/query-tools.d.ts +32 -5
  103. package/dist/connectors/trello/query-tools.d.ts.map +1 -1
  104. package/dist/connectors/trello/query-tools.js +56 -17
  105. package/dist/connectors/trello/query-tools.js.map +1 -1
  106. package/dist/db/agent-store.d.ts +0 -4
  107. package/dist/db/agent-store.d.ts.map +1 -1
  108. package/dist/db/agent-store.js +0 -65
  109. package/dist/db/agent-store.js.map +1 -1
  110. package/dist/envelope/enforcer.d.ts.map +1 -1
  111. package/dist/envelope/enforcer.js +10 -1
  112. package/dist/envelope/enforcer.js.map +1 -1
  113. package/dist/envelope/index.d.ts +0 -1
  114. package/dist/envelope/index.d.ts.map +1 -1
  115. package/dist/envelope/index.js +0 -1
  116. package/dist/envelope/index.js.map +1 -1
  117. package/dist/envelope/signature.d.ts +0 -1
  118. package/dist/envelope/signature.d.ts.map +1 -1
  119. package/dist/envelope/signature.js +0 -7
  120. package/dist/envelope/signature.js.map +1 -1
  121. package/dist/envelope/tool-connector-scope.d.ts +35 -0
  122. package/dist/envelope/tool-connector-scope.d.ts.map +1 -0
  123. package/dist/envelope/tool-connector-scope.js +57 -0
  124. package/dist/envelope/tool-connector-scope.js.map +1 -0
  125. package/dist/evidence/effects.d.ts +107 -0
  126. package/dist/evidence/effects.d.ts.map +1 -0
  127. package/dist/evidence/effects.js +281 -0
  128. package/dist/evidence/effects.js.map +1 -0
  129. package/dist/evidence/read.d.ts +75 -0
  130. package/dist/evidence/read.d.ts.map +1 -0
  131. package/dist/evidence/read.js +105 -0
  132. package/dist/evidence/read.js.map +1 -0
  133. package/dist/gateways/base-gateway.d.ts +23 -3
  134. package/dist/gateways/base-gateway.d.ts.map +1 -1
  135. package/dist/gateways/base-gateway.js +15 -2
  136. package/dist/gateways/base-gateway.js.map +1 -1
  137. package/dist/gateways/discord.d.ts +4 -16
  138. package/dist/gateways/discord.d.ts.map +1 -1
  139. package/dist/gateways/discord.js +22 -189
  140. package/dist/gateways/discord.js.map +1 -1
  141. package/dist/gateways/index.d.ts +2 -1
  142. package/dist/gateways/index.d.ts.map +1 -1
  143. package/dist/gateways/message-router.d.ts +13 -20
  144. package/dist/gateways/message-router.d.ts.map +1 -1
  145. package/dist/gateways/message-router.js +32 -3
  146. package/dist/gateways/message-router.js.map +1 -1
  147. package/dist/gateways/slack.d.ts +2 -12
  148. package/dist/gateways/slack.d.ts.map +1 -1
  149. package/dist/gateways/slack.js +6 -220
  150. package/dist/gateways/slack.js.map +1 -1
  151. package/dist/gateways/telegram.d.ts +2 -2
  152. package/dist/gateways/telegram.d.ts.map +1 -1
  153. package/dist/gateways/telegram.js +3 -2
  154. package/dist/gateways/telegram.js.map +1 -1
  155. package/dist/gateways/turn-contract.d.ts +104 -0
  156. package/dist/gateways/turn-contract.d.ts.map +1 -0
  157. package/dist/{memory/consult-contract.js → gateways/turn-contract.js} +1 -1
  158. package/dist/gateways/turn-contract.js.map +1 -0
  159. package/dist/memory/provenance-live.d.ts +111 -0
  160. package/dist/memory/provenance-live.d.ts.map +1 -0
  161. package/dist/memory/provenance-live.js +381 -0
  162. package/dist/memory/provenance-live.js.map +1 -0
  163. package/dist/memory/provenance-resolver.d.ts +184 -0
  164. package/dist/memory/provenance-resolver.d.ts.map +1 -0
  165. package/dist/memory/provenance-resolver.js +152 -0
  166. package/dist/memory/provenance-resolver.js.map +1 -0
  167. package/dist/multi-agent/agent-event-bus.d.ts +1 -0
  168. package/dist/multi-agent/agent-event-bus.d.ts.map +1 -1
  169. package/dist/multi-agent/bmad-templates.d.ts +0 -18
  170. package/dist/multi-agent/bmad-templates.d.ts.map +1 -1
  171. package/dist/multi-agent/bmad-templates.js +0 -127
  172. package/dist/multi-agent/bmad-templates.js.map +1 -1
  173. package/dist/multi-agent/dashboard-agent-persona.js +3 -3
  174. package/dist/operator/board-reconcile.d.ts +2 -3
  175. package/dist/operator/board-reconcile.d.ts.map +1 -1
  176. package/dist/operator/board-reconcile.js +18 -32
  177. package/dist/operator/board-reconcile.js.map +1 -1
  178. package/dist/operator/changes-projection.d.ts +70 -0
  179. package/dist/operator/changes-projection.d.ts.map +1 -0
  180. package/dist/operator/changes-projection.js +109 -0
  181. package/dist/operator/changes-projection.js.map +1 -0
  182. package/dist/operator/external-correlation.d.ts +94 -0
  183. package/dist/operator/external-correlation.d.ts.map +1 -0
  184. package/dist/operator/external-correlation.js +177 -0
  185. package/dist/operator/external-correlation.js.map +1 -0
  186. package/dist/operator/operator-trigger-loop.d.ts +9 -1
  187. package/dist/operator/operator-trigger-loop.d.ts.map +1 -1
  188. package/dist/operator/operator-trigger-loop.js +8 -4
  189. package/dist/operator/operator-trigger-loop.js.map +1 -1
  190. package/dist/operator/provenance-lookup.d.ts +18 -0
  191. package/dist/operator/provenance-lookup.d.ts.map +1 -0
  192. package/dist/operator/provenance-lookup.js +54 -0
  193. package/dist/operator/provenance-lookup.js.map +1 -0
  194. package/dist/operator/report-carry.d.ts +18 -1
  195. package/dist/operator/report-carry.d.ts.map +1 -1
  196. package/dist/operator/report-carry.js +22 -3
  197. package/dist/operator/report-carry.js.map +1 -1
  198. package/dist/operator/report-run.d.ts +31 -0
  199. package/dist/operator/report-run.d.ts.map +1 -1
  200. package/dist/operator/report-run.js +140 -22
  201. package/dist/operator/report-run.js.map +1 -1
  202. package/dist/operator/task-ledger.d.ts +84 -2
  203. package/dist/operator/task-ledger.d.ts.map +1 -1
  204. package/dist/operator/task-ledger.js +274 -31
  205. package/dist/operator/task-ledger.js.map +1 -1
  206. package/dist/operator/worker-run.js +1 -1
  207. package/dist/operator/worker-run.js.map +1 -1
  208. package/dist/operator/workorder-hooks.d.ts +79 -4
  209. package/dist/operator/workorder-hooks.d.ts.map +1 -1
  210. package/dist/operator/workorder-hooks.js +152 -20
  211. package/dist/operator/workorder-hooks.js.map +1 -1
  212. package/dist/operator/workorder-publishers.d.ts +2 -0
  213. package/dist/operator/workorder-publishers.d.ts.map +1 -1
  214. package/dist/operator/workorder-publishers.js +8 -1
  215. package/dist/operator/workorder-publishers.js.map +1 -1
  216. package/dist/utils/untrusted-content.d.ts +11 -0
  217. package/dist/utils/untrusted-content.d.ts.map +1 -1
  218. package/dist/utils/untrusted-content.js +20 -0
  219. package/dist/utils/untrusted-content.js.map +1 -1
  220. package/package.json +4 -3
  221. package/scripts/backfill-channel-keys.ts +451 -0
  222. package/dist/agent/auto-recall.d.ts +0 -48
  223. package/dist/agent/auto-recall.d.ts.map +0 -1
  224. package/dist/agent/auto-recall.js +0 -192
  225. package/dist/agent/auto-recall.js.map +0 -1
  226. package/dist/agent/claude-client.d.ts +0 -50
  227. package/dist/agent/claude-client.d.ts.map +0 -1
  228. package/dist/agent/claude-client.js +0 -219
  229. package/dist/agent/claude-client.js.map +0 -1
  230. package/dist/agent/delegation-executor.d.ts +0 -49
  231. package/dist/agent/delegation-executor.d.ts.map +0 -1
  232. package/dist/agent/delegation-executor.js +0 -692
  233. package/dist/agent/delegation-executor.js.map +0 -1
  234. package/dist/agent/mcp-executor.d.ts +0 -60
  235. package/dist/agent/mcp-executor.d.ts.map +0 -1
  236. package/dist/agent/mcp-executor.js +0 -190
  237. package/dist/agent/mcp-executor.js.map +0 -1
  238. package/dist/agent/process-tree.d.ts +0 -6
  239. package/dist/agent/process-tree.d.ts.map +0 -1
  240. package/dist/agent/process-tree.js +0 -21
  241. package/dist/agent/process-tree.js.map +0 -1
  242. package/dist/agent/streaming-callback-manager.d.ts +0 -85
  243. package/dist/agent/streaming-callback-manager.d.ts.map +0 -1
  244. package/dist/agent/streaming-callback-manager.js +0 -103
  245. package/dist/agent/streaming-callback-manager.js.map +0 -1
  246. package/dist/agent/token-budget.d.ts +0 -49
  247. package/dist/agent/token-budget.d.ts.map +0 -1
  248. package/dist/agent/token-budget.js +0 -92
  249. package/dist/agent/token-budget.js.map +0 -1
  250. package/dist/connectors/kagemusha/history-compiler.d.ts +0 -18
  251. package/dist/connectors/kagemusha/history-compiler.d.ts.map +0 -1
  252. package/dist/connectors/kagemusha/history-compiler.js +0 -35
  253. package/dist/connectors/kagemusha/history-compiler.js.map +0 -1
  254. package/dist/db/migrations/wiki-artifacts.d.ts +0 -3
  255. package/dist/db/migrations/wiki-artifacts.d.ts.map +0 -1
  256. package/dist/db/migrations/wiki-artifacts.js +0 -24
  257. package/dist/db/migrations/wiki-artifacts.js.map +0 -1
  258. package/dist/envelope/subset.d.ts +0 -9
  259. package/dist/envelope/subset.d.ts.map +0 -1
  260. package/dist/envelope/subset.js +0 -67
  261. package/dist/envelope/subset.js.map +0 -1
  262. package/dist/memory/consult-contract.d.ts +0 -8
  263. package/dist/memory/consult-contract.d.ts.map +0 -1
  264. package/dist/memory/consult-contract.js.map +0 -1
  265. package/dist/multi-agent/agent-message-queue.d.ts +0 -104
  266. package/dist/multi-agent/agent-message-queue.d.ts.map +0 -1
  267. package/dist/multi-agent/agent-message-queue.js +0 -227
  268. package/dist/multi-agent/agent-message-queue.js.map +0 -1
  269. package/dist/multi-agent/background-task-manager.d.ts +0 -248
  270. package/dist/multi-agent/background-task-manager.d.ts.map +0 -1
  271. package/dist/multi-agent/background-task-manager.js +0 -415
  272. package/dist/multi-agent/background-task-manager.js.map +0 -1
  273. package/dist/multi-agent/category-router.d.ts +0 -56
  274. package/dist/multi-agent/category-router.d.ts.map +0 -1
  275. package/dist/multi-agent/category-router.js +0 -99
  276. package/dist/multi-agent/category-router.js.map +0 -1
  277. package/dist/multi-agent/council-engine.d.ts +0 -60
  278. package/dist/multi-agent/council-engine.d.ts.map +0 -1
  279. package/dist/multi-agent/council-engine.js +0 -284
  280. package/dist/multi-agent/council-engine.js.map +0 -1
  281. package/dist/multi-agent/delegation-format-validator.d.ts +0 -22
  282. package/dist/multi-agent/delegation-format-validator.d.ts.map +0 -1
  283. package/dist/multi-agent/delegation-format-validator.js +0 -31
  284. package/dist/multi-agent/delegation-format-validator.js.map +0 -1
  285. package/dist/multi-agent/delegation-manager.d.ts +0 -128
  286. package/dist/multi-agent/delegation-manager.d.ts.map +0 -1
  287. package/dist/multi-agent/delegation-manager.js +0 -276
  288. package/dist/multi-agent/delegation-manager.js.map +0 -1
  289. package/dist/multi-agent/i18n-messages.d.ts +0 -35
  290. package/dist/multi-agent/i18n-messages.d.ts.map +0 -1
  291. package/dist/multi-agent/i18n-messages.js +0 -54
  292. package/dist/multi-agent/i18n-messages.js.map +0 -1
  293. package/dist/multi-agent/index.d.ts +0 -31
  294. package/dist/multi-agent/index.d.ts.map +0 -1
  295. package/dist/multi-agent/index.js +0 -46
  296. package/dist/multi-agent/index.js.map +0 -1
  297. package/dist/multi-agent/multi-agent-base.d.ts +0 -223
  298. package/dist/multi-agent/multi-agent-base.d.ts.map +0 -1
  299. package/dist/multi-agent/multi-agent-base.js +0 -592
  300. package/dist/multi-agent/multi-agent-base.js.map +0 -1
  301. package/dist/multi-agent/multi-agent-discord.d.ts +0 -142
  302. package/dist/multi-agent/multi-agent-discord.d.ts.map +0 -1
  303. package/dist/multi-agent/multi-agent-discord.js +0 -1235
  304. package/dist/multi-agent/multi-agent-discord.js.map +0 -1
  305. package/dist/multi-agent/multi-agent-slack.d.ts +0 -146
  306. package/dist/multi-agent/multi-agent-slack.d.ts.map +0 -1
  307. package/dist/multi-agent/multi-agent-slack.js +0 -953
  308. package/dist/multi-agent/multi-agent-slack.js.map +0 -1
  309. package/dist/multi-agent/multi-bot-manager.d.ts +0 -119
  310. package/dist/multi-agent/multi-bot-manager.d.ts.map +0 -1
  311. package/dist/multi-agent/multi-bot-manager.js +0 -449
  312. package/dist/multi-agent/multi-bot-manager.js.map +0 -1
  313. package/dist/multi-agent/orchestrator.d.ts +0 -110
  314. package/dist/multi-agent/orchestrator.d.ts.map +0 -1
  315. package/dist/multi-agent/orchestrator.js +0 -436
  316. package/dist/multi-agent/orchestrator.js.map +0 -1
  317. package/dist/multi-agent/rate-limiter.d.ts +0 -76
  318. package/dist/multi-agent/rate-limiter.d.ts.map +0 -1
  319. package/dist/multi-agent/rate-limiter.js +0 -128
  320. package/dist/multi-agent/rate-limiter.js.map +0 -1
  321. package/dist/multi-agent/shared-context.d.ts +0 -127
  322. package/dist/multi-agent/shared-context.d.ts.map +0 -1
  323. package/dist/multi-agent/shared-context.js +0 -239
  324. package/dist/multi-agent/shared-context.js.map +0 -1
  325. package/dist/multi-agent/slack-config-validator.d.ts +0 -42
  326. package/dist/multi-agent/slack-config-validator.d.ts.map +0 -1
  327. package/dist/multi-agent/slack-config-validator.js +0 -194
  328. package/dist/multi-agent/slack-config-validator.js.map +0 -1
  329. package/dist/multi-agent/slack-multi-bot-manager.d.ts +0 -143
  330. package/dist/multi-agent/slack-multi-bot-manager.d.ts.map +0 -1
  331. package/dist/multi-agent/slack-multi-bot-manager.js +0 -413
  332. package/dist/multi-agent/slack-multi-bot-manager.js.map +0 -1
  333. package/dist/multi-agent/swarm/swarm-anti-pattern-detector.d.ts +0 -98
  334. package/dist/multi-agent/swarm/swarm-anti-pattern-detector.d.ts.map +0 -1
  335. package/dist/multi-agent/swarm/swarm-anti-pattern-detector.js +0 -225
  336. package/dist/multi-agent/swarm/swarm-anti-pattern-detector.js.map +0 -1
  337. package/dist/multi-agent/swarm/swarm-db.d.ts +0 -175
  338. package/dist/multi-agent/swarm/swarm-db.d.ts.map +0 -1
  339. package/dist/multi-agent/swarm/swarm-db.js +0 -313
  340. package/dist/multi-agent/swarm/swarm-db.js.map +0 -1
  341. package/dist/multi-agent/swarm/swarm-event-reporter.d.ts +0 -116
  342. package/dist/multi-agent/swarm/swarm-event-reporter.d.ts.map +0 -1
  343. package/dist/multi-agent/swarm/swarm-event-reporter.js +0 -243
  344. package/dist/multi-agent/swarm/swarm-event-reporter.js.map +0 -1
  345. package/dist/multi-agent/swarm/swarm-mama-adapter.d.ts +0 -57
  346. package/dist/multi-agent/swarm/swarm-mama-adapter.d.ts.map +0 -1
  347. package/dist/multi-agent/swarm/swarm-mama-adapter.js +0 -87
  348. package/dist/multi-agent/swarm/swarm-mama-adapter.js.map +0 -1
  349. package/dist/multi-agent/swarm/swarm-manager.d.ts +0 -122
  350. package/dist/multi-agent/swarm/swarm-manager.d.ts.map +0 -1
  351. package/dist/multi-agent/swarm/swarm-manager.js +0 -199
  352. package/dist/multi-agent/swarm/swarm-manager.js.map +0 -1
  353. package/dist/multi-agent/swarm/swarm-task-learner.d.ts +0 -104
  354. package/dist/multi-agent/swarm/swarm-task-learner.d.ts.map +0 -1
  355. package/dist/multi-agent/swarm/swarm-task-learner.js +0 -211
  356. package/dist/multi-agent/swarm/swarm-task-learner.js.map +0 -1
  357. package/dist/multi-agent/swarm/swarm-task-runner.d.ts +0 -155
  358. package/dist/multi-agent/swarm/swarm-task-runner.d.ts.map +0 -1
  359. package/dist/multi-agent/swarm/swarm-task-runner.js +0 -615
  360. package/dist/multi-agent/swarm/swarm-task-runner.js.map +0 -1
  361. package/dist/multi-agent/swarm/wave-engine.d.ts +0 -96
  362. package/dist/multi-agent/swarm/wave-engine.d.ts.map +0 -1
  363. package/dist/multi-agent/swarm/wave-engine.js +0 -123
  364. package/dist/multi-agent/swarm/wave-engine.js.map +0 -1
  365. package/dist/multi-agent/system-reminder.d.ts +0 -206
  366. package/dist/multi-agent/system-reminder.d.ts.map +0 -1
  367. package/dist/multi-agent/system-reminder.js +0 -455
  368. package/dist/multi-agent/system-reminder.js.map +0 -1
  369. package/dist/multi-agent/task-continuation.d.ts +0 -74
  370. package/dist/multi-agent/task-continuation.d.ts.map +0 -1
  371. package/dist/multi-agent/task-continuation.js +0 -172
  372. package/dist/multi-agent/task-continuation.js.map +0 -1
  373. package/dist/multi-agent/ultrawork-state.d.ts +0 -57
  374. package/dist/multi-agent/ultrawork-state.d.ts.map +0 -1
  375. package/dist/multi-agent/ultrawork-state.js +0 -191
  376. package/dist/multi-agent/ultrawork-state.js.map +0 -1
  377. package/dist/multi-agent/ultrawork.d.ts +0 -152
  378. package/dist/multi-agent/ultrawork.d.ts.map +0 -1
  379. package/dist/multi-agent/ultrawork.js +0 -879
  380. package/dist/multi-agent/ultrawork.js.map +0 -1
  381. package/dist/multi-agent/work-tracker.d.ts +0 -22
  382. package/dist/multi-agent/work-tracker.d.ts.map +0 -1
  383. package/dist/multi-agent/work-tracker.js +0 -45
  384. package/dist/multi-agent/work-tracker.js.map +0 -1
  385. package/dist/multi-agent/workflow-engine.d.ts +0 -87
  386. package/dist/multi-agent/workflow-engine.d.ts.map +0 -1
  387. package/dist/multi-agent/workflow-engine.js +0 -604
  388. package/dist/multi-agent/workflow-engine.js.map +0 -1
  389. package/dist/onboarding/all-tools.d.ts +0 -18
  390. package/dist/onboarding/all-tools.d.ts.map +0 -1
  391. package/dist/onboarding/all-tools.js +0 -149
  392. package/dist/onboarding/all-tools.js.map +0 -1
  393. package/dist/onboarding/autonomous-discovery-tools.d.ts +0 -23
  394. package/dist/onboarding/autonomous-discovery-tools.d.ts.map +0 -1
  395. package/dist/onboarding/autonomous-discovery-tools.js +0 -268
  396. package/dist/onboarding/autonomous-discovery-tools.js.map +0 -1
  397. package/dist/onboarding/onboarding-state.d.ts +0 -70
  398. package/dist/onboarding/onboarding-state.d.ts.map +0 -1
  399. package/dist/onboarding/onboarding-state.js +0 -183
  400. package/dist/onboarding/onboarding-state.js.map +0 -1
  401. package/dist/onboarding/personality-quiz.d.ts +0 -35
  402. package/dist/onboarding/personality-quiz.d.ts.map +0 -1
  403. package/dist/onboarding/personality-quiz.js +0 -219
  404. package/dist/onboarding/personality-quiz.js.map +0 -1
  405. package/dist/onboarding/phase-5-summary.d.ts +0 -26
  406. package/dist/onboarding/phase-5-summary.d.ts.map +0 -1
  407. package/dist/onboarding/phase-5-summary.js +0 -153
  408. package/dist/onboarding/phase-5-summary.js.map +0 -1
  409. package/dist/onboarding/phase-6-security.d.ts +0 -33
  410. package/dist/onboarding/phase-6-security.d.ts.map +0 -1
  411. package/dist/onboarding/phase-6-security.js +0 -473
  412. package/dist/onboarding/phase-6-security.js.map +0 -1
  413. package/dist/onboarding/phase-7-integrations.d.ts +0 -91
  414. package/dist/onboarding/phase-7-integrations.d.ts.map +0 -1
  415. package/dist/onboarding/phase-7-integrations.js +0 -725
  416. package/dist/onboarding/phase-7-integrations.js.map +0 -1
  417. package/dist/onboarding/phase-8-demo.d.ts +0 -43
  418. package/dist/onboarding/phase-8-demo.d.ts.map +0 -1
  419. package/dist/onboarding/phase-8-demo.js +0 -346
  420. package/dist/onboarding/phase-8-demo.js.map +0 -1
  421. package/dist/onboarding/phase-9-finalization.d.ts +0 -27
  422. package/dist/onboarding/phase-9-finalization.d.ts.map +0 -1
  423. package/dist/onboarding/phase-9-finalization.js +0 -417
  424. package/dist/onboarding/phase-9-finalization.js.map +0 -1
  425. package/dist/onboarding/ritual-prompt.d.ts +0 -2
  426. package/dist/onboarding/ritual-prompt.d.ts.map +0 -1
  427. package/dist/onboarding/ritual-prompt.js +0 -285
  428. package/dist/onboarding/ritual-prompt.js.map +0 -1
  429. package/dist/onboarding/ritual-tools.d.ts +0 -17
  430. package/dist/onboarding/ritual-tools.d.ts.map +0 -1
  431. package/dist/onboarding/ritual-tools.js +0 -93
  432. package/dist/onboarding/ritual-tools.js.map +0 -1
  433. package/dist/setup/setup-tools.d.ts +0 -13
  434. package/dist/setup/setup-tools.d.ts.map +0 -1
  435. package/dist/setup/setup-tools.js +0 -106
  436. package/dist/setup/setup-tools.js.map +0 -1
  437. package/dist/utils/slack-input-validator.d.ts +0 -74
  438. package/dist/utils/slack-input-validator.d.ts.map +0 -1
  439. package/dist/utils/slack-input-validator.js +0 -275
  440. package/dist/utils/slack-input-validator.js.map +0 -1
  441. package/dist/utils/slack-rate-limiter.d.ts +0 -139
  442. package/dist/utils/slack-rate-limiter.d.ts.map +0 -1
  443. package/dist/utils/slack-rate-limiter.js +0 -324
  444. package/dist/utils/slack-rate-limiter.js.map +0 -1
  445. package/dist/wiki/wiki-compiler.d.ts +0 -13
  446. package/dist/wiki/wiki-compiler.d.ts.map +0 -1
  447. package/dist/wiki/wiki-compiler.js +0 -82
  448. package/dist/wiki/wiki-compiler.js.map +0 -1
@@ -0,0 +1,451 @@
1
+ /**
2
+ * Re-key indexed connector events from display names to configured channel keys.
3
+ *
4
+ * WHY THIS EXISTS. Six of seven connectors wrote `item.channel` as a human display name
5
+ * while the config declares the same channel under the upstream's stable id. Binding
6
+ * absorbed the difference with a name fallback, so nothing ever looked broken, and every
7
+ * reader downstream compared a display name against a config key and matched nothing.
8
+ * `canonicalChannelKey` fixes this at the write boundary - for newly polled events only.
9
+ * The rows already indexed stay unreadable until they are moved, and on the live index
10
+ * that is 15,279 events belonging to channels the owner did configure.
11
+ *
12
+ * WHY IT IS NOT JUST ONE UPDATE. The channel value is a join key in several places, and
13
+ * the one that matters is not a table. A seam review found this version carefully merging
14
+ * cursors in three tables that have no reader or writer anywhere in the repo, while
15
+ * missing the live one: ConnectorDeltaRepo keys its partitions `connector\0channel` in
16
+ * ~/.mama/operator/trigger-loop-cursors.json, and `drainNew` starts from 0 when a key is
17
+ * absent. All 22 re-keyed partitions have a live cursor there. Applying the earlier
18
+ * version would have redelivered 15,279 months-old events as new and composed owner
19
+ * reports out of them - precisely the failure this comment claimed to prevent.
20
+ *
21
+ * Those three tables are now gone from this script entirely: they have no reader and no
22
+ * writer anywhere in the repository. Carefully merging cursors nothing consults was work
23
+ * that looked like rigour and was decoration.
24
+ *
25
+ * `memory_scope_id` is the sixth carrier: on all 11,277 channel-scoped rows it is exactly
26
+ * equal to `channel`. Moving one without the other leaves a row holding two names for its
27
+ * own channel, which the pre-grant readers (/api/agent/raw among them) still consult.
28
+ *
29
+ * WHAT IT REFUSES TO DO:
30
+ * - Guess. A display name that maps to two configured channels is reported and skipped;
31
+ * an identity that has to be inferred is not an identity.
32
+ * - Invent. A channel that appears in no config entry is left exactly as it is. Those
33
+ * rows are correctly invisible: the owner never asked this system to look there.
34
+ * - Run by accident. Dry run is the default and --apply is required.
35
+ * - Run while the daemon is up. The deployed build's upsert overwrites `channel` from
36
+ * the poller on every re-fetch of an existing source_id (42% of slack rows have been
37
+ * re-upserted at least once), so a repair applied under a live daemon erodes silently,
38
+ * row by row, with no error.
39
+ * - Run against a schema whose per-partition sequence would collide. `operator_ingest_seq`
40
+ * is unique per (connector, channel), so merging two partitions merges two independent
41
+ * 1..N sequences; the moved rows are renumbered above the target's high-water mark
42
+ * rather than left to abort the transaction on the unique index.
43
+ */
44
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
45
+ import { homedir } from 'node:os';
46
+ import { join } from 'node:path';
47
+ import Database from 'better-sqlite3';
48
+ import { loadConnectorConfig } from '../src/connectors/config-loader.js';
49
+
50
+ interface Rekey {
51
+ connector: string;
52
+ from: string;
53
+ to: string;
54
+ events: number;
55
+ }
56
+
57
+ interface Plan {
58
+ rekeys: Rekey[];
59
+ ambiguous: Array<{ connector: string; name: string; candidates: number }>;
60
+ alreadyCanonical: number;
61
+ /** Events of a connector the config does not declare at all. */
62
+ unknownConnector: number;
63
+ /**
64
+ * Events of a DECLARED connector whose channel matches no configured key or name.
65
+ *
66
+ * Reported apart from unknownConnector because the two mean different things and the
67
+ * earlier version printed both as "channels this system was never given". 860 of the
68
+ * 1,312 belong to declared connectors - a channel that was removed from config, or
69
+ * renamed after the rows were written. Those stay permanently invisible, and calling
70
+ * them never-configured hides the one class an owner could actually act on.
71
+ */
72
+ unmatchedChannel: number;
73
+ }
74
+
75
+ /** Tables whose channel column is the same join key, and must move with the index. */
76
+ const CHANNEL_TABLES: Array<{ table: string; connectorColumn: string; channelColumn: string }> = [
77
+ { table: 'connector_event_index', connectorColumn: 'source_connector', channelColumn: 'channel' },
78
+ {
79
+ table: 'connector_event_index_operator_seq_cursors',
80
+ connectorColumn: 'source_connector',
81
+ channelColumn: 'channel',
82
+ },
83
+ ];
84
+
85
+ type Db = InstanceType<typeof Database>;
86
+
87
+ export function buildPlan(db: Db, config: Record<string, unknown>): Plan {
88
+ const canonical = new Map<string, Set<string>>();
89
+ const byName = new Map<string, Map<string, string[]>>();
90
+
91
+ for (const [connector, raw] of Object.entries(config)) {
92
+ if (raw === null || typeof raw !== 'object') continue;
93
+ const entry = raw as { enabled?: unknown; channels?: unknown };
94
+ if (entry.enabled === false) continue;
95
+ if (entry.channels === null || typeof entry.channels !== 'object') continue;
96
+ const channels = entry.channels as Record<string, { name?: unknown }>;
97
+ canonical.set(connector, new Set(Object.keys(channels)));
98
+ const names = new Map<string, string[]>();
99
+ for (const [key, value] of Object.entries(channels)) {
100
+ const name = value?.name;
101
+ if (typeof name !== 'string' || name.trim().length === 0) continue;
102
+ names.set(name, [...(names.get(name) ?? []), key]);
103
+ }
104
+ byName.set(connector, names);
105
+ }
106
+
107
+ const rows = db
108
+ .prepare(
109
+ `SELECT source_connector AS connector, channel, COUNT(*) AS n
110
+ FROM connector_event_index GROUP BY 1, 2`
111
+ )
112
+ .all() as Array<{ connector: string; channel: string | null; n: number }>;
113
+
114
+ const plan: Plan = {
115
+ rekeys: [],
116
+ ambiguous: [],
117
+ alreadyCanonical: 0,
118
+ unknownConnector: 0,
119
+ unmatchedChannel: 0,
120
+ };
121
+ for (const row of rows) {
122
+ const channel = row.channel ?? '';
123
+ const keys = canonical.get(row.connector);
124
+ if (!keys) {
125
+ plan.unknownConnector += row.n;
126
+ continue;
127
+ }
128
+ if (keys.has(channel)) {
129
+ plan.alreadyCanonical += row.n;
130
+ continue;
131
+ }
132
+ const candidates = byName.get(row.connector)?.get(channel) ?? [];
133
+ if (candidates.length === 1) {
134
+ plan.rekeys.push({
135
+ connector: row.connector,
136
+ from: channel,
137
+ to: candidates[0],
138
+ events: row.n,
139
+ });
140
+ } else {
141
+ if (candidates.length > 1) {
142
+ plan.ambiguous.push({
143
+ connector: row.connector,
144
+ name: channel,
145
+ candidates: candidates.length,
146
+ });
147
+ }
148
+ plan.unmatchedChannel += row.n;
149
+ }
150
+ }
151
+ return plan;
152
+ }
153
+
154
+ /**
155
+ * Apply one re-key across every table that carries the value.
156
+ *
157
+ * Cursor tables are keyed by (connector, channel), so a re-key can collide with a row that
158
+ * already exists under the canonical key. Deleting the loser would rewind a consumer;
159
+ * keeping the further-along cursor is the only merge that cannot cause redelivery.
160
+ */
161
+ export function applyRekey(db: Db, rekey: Rekey): Record<string, number> {
162
+ const moved: Record<string, number> = {};
163
+ renumberOperatorSeq(db, rekey);
164
+ for (const { table, connectorColumn, channelColumn } of CHANNEL_TABLES) {
165
+ if (!tableExists(db, table)) continue;
166
+ if (table === 'connector_event_index_operator_seq_cursors') {
167
+ moved[table] = mergeSeqCursor(db, rekey);
168
+ continue;
169
+ }
170
+ const result = db
171
+ .prepare(
172
+ `UPDATE "${table}" SET "${channelColumn}" = ?
173
+ WHERE "${connectorColumn}" = ? AND "${channelColumn}" = ?`
174
+ )
175
+ .run(rekey.to, rekey.connector, rekey.from);
176
+ moved[table] = result.changes;
177
+ if (table === 'connector_event_index') {
178
+ // The sixth carrier. Equal to `channel` on every channel-scoped row, so leaving it
179
+ // behind gives the row two names for itself and makes the pre-grant readers
180
+ // disagree with the grant path about the same event.
181
+ moved['memory_scope_id'] = db
182
+ .prepare(
183
+ `UPDATE connector_event_index SET memory_scope_id = ?
184
+ WHERE source_connector = ? AND memory_scope_kind = 'channel' AND memory_scope_id = ?`
185
+ )
186
+ .run(rekey.to, rekey.connector, rekey.from).changes;
187
+ }
188
+ }
189
+ return moved;
190
+ }
191
+
192
+ /**
193
+ * Give the moving rows sequence numbers above the target partition's high-water mark.
194
+ *
195
+ * `operator_ingest_seq` is numbered per (connector, channel) and a unique index enforces
196
+ * it, so merging two partitions merges two independent 1..N sequences. Merging the CURSOR
197
+ * to the higher watermark - which is what the first version did - only governs what is
198
+ * assigned next; it does nothing about the rows already numbered. With one event already
199
+ * polled into the target partition, the whole repair aborted on the unique index, after
200
+ * the backup message had printed.
201
+ *
202
+ * Relative order within the moving set is preserved; interleaving with the target's
203
+ * existing rows is not recoverable, because the two streams were never ordered against
204
+ * each other in the first place.
205
+ */
206
+ function renumberOperatorSeq(db: Db, rekey: Rekey): void {
207
+ if (!tableExists(db, 'connector_event_index')) return;
208
+ const high = db
209
+ .prepare(
210
+ `SELECT COALESCE(MAX(operator_ingest_seq), 0) AS high FROM connector_event_index
211
+ WHERE source_connector = ? AND COALESCE(channel, '') = ?`
212
+ )
213
+ .get(rekey.connector, rekey.to) as { high?: number } | undefined;
214
+ const base = Number(high?.high ?? 0);
215
+ if (base === 0) return; // Target partition is empty: the move cannot collide.
216
+
217
+ const moving = db
218
+ .prepare(
219
+ `SELECT event_index_id FROM connector_event_index
220
+ WHERE source_connector = ? AND COALESCE(channel, '') = ?
221
+ AND operator_ingest_seq IS NOT NULL
222
+ ORDER BY operator_ingest_seq ASC`
223
+ )
224
+ .all(rekey.connector, rekey.from) as Array<{ event_index_id: string }>;
225
+
226
+ const update = db.prepare(
227
+ `UPDATE connector_event_index SET operator_ingest_seq = ? WHERE event_index_id = ?`
228
+ );
229
+ // Two passes through a disjoint high range: assigning directly into base+1.. can collide
230
+ // with a not-yet-moved row of the same partition when the ranges overlap.
231
+ const staging = base + 1_000_000;
232
+ moving.forEach((row, index) => update.run(staging + index, row.event_index_id));
233
+ moving.forEach((row, index) => update.run(base + 1 + index, row.event_index_id));
234
+ }
235
+
236
+ function mergeSeqCursor(db: Db, rekey: Rekey): number {
237
+ const target = db
238
+ .prepare(
239
+ `SELECT next_seq FROM connector_event_index_operator_seq_cursors
240
+ WHERE source_connector = ? AND channel = ?`
241
+ )
242
+ .get(rekey.connector, rekey.to) as { next_seq?: number } | undefined;
243
+ const source = db
244
+ .prepare(
245
+ `SELECT next_seq FROM connector_event_index_operator_seq_cursors
246
+ WHERE source_connector = ? AND channel = ?`
247
+ )
248
+ .get(rekey.connector, rekey.from) as { next_seq?: number } | undefined;
249
+ if (!source) return 0;
250
+
251
+ if (target === undefined) {
252
+ return db
253
+ .prepare(
254
+ `UPDATE connector_event_index_operator_seq_cursors SET channel = ?
255
+ WHERE source_connector = ? AND channel = ?`
256
+ )
257
+ .run(rekey.to, rekey.connector, rekey.from).changes;
258
+ }
259
+ // Both exist: the merged stream must not hand out a sequence number twice.
260
+ db.prepare(
261
+ `UPDATE connector_event_index_operator_seq_cursors SET next_seq = ?
262
+ WHERE source_connector = ? AND channel = ?`
263
+ ).run(Math.max(target.next_seq ?? 1, source.next_seq ?? 1), rekey.connector, rekey.to);
264
+ db.prepare(
265
+ `DELETE FROM connector_event_index_operator_seq_cursors
266
+ WHERE source_connector = ? AND channel = ?`
267
+ ).run(rekey.connector, rekey.from);
268
+ return 1;
269
+ }
270
+
271
+ /**
272
+ * Carry the live delta cursors, which are a JSON file rather than a table.
273
+ *
274
+ * ConnectorDeltaRepo keys partitions `connector\0channel` and `drainNew` falls back to 0
275
+ * for an absent key, so an orphaned cursor does not error - it silently redelivers every
276
+ * event in the partition. On the live file all 22 re-keyed partitions have a cursor, and
277
+ * behind them sit 15,279 events that would have been drained as new and turned into owner
278
+ * reports about months-old messages.
279
+ *
280
+ * THIS is the cursor that matters. The three cursor TABLES this script used to merge have
281
+ * no reader and no writer anywhere in the repository; they were deleted, and this was very
282
+ * nearly deleted with them.
283
+ *
284
+ * Where both keys exist the LATER cursor wins, for the same reason as any merge here:
285
+ * moving a consumer backwards is redelivery by another route.
286
+ */
287
+ export function carryDeltaCursors(
288
+ cursors: Record<string, number>,
289
+ rekeys: readonly Rekey[]
290
+ ): { cursors: Record<string, number>; carried: number } {
291
+ const next = { ...cursors };
292
+ let carried = 0;
293
+ for (const rekey of rekeys) {
294
+ const from = `${rekey.connector}\u0000${rekey.from}`;
295
+ const to = `${rekey.connector}\u0000${rekey.to}`;
296
+ if (!(from in next)) continue;
297
+ const fromValue = next[from];
298
+ const toValue = next[to];
299
+ next[to] = toValue === undefined ? fromValue : Math.max(toValue, fromValue);
300
+ delete next[from];
301
+ carried += 1;
302
+ }
303
+ return { cursors: next, carried };
304
+ }
305
+
306
+ function tableExists(db: Db, table: string): boolean {
307
+ return Boolean(
308
+ db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name = ?`).get(table)
309
+ );
310
+ }
311
+
312
+ function readCursorFile(path: string): Record<string, number> {
313
+ if (!existsSync(path)) return {};
314
+ try {
315
+ const parsed = JSON.parse(readFileSync(path, 'utf8')) as unknown;
316
+ return parsed !== null && typeof parsed === 'object' ? (parsed as Record<string, number>) : {};
317
+ } catch {
318
+ return {};
319
+ }
320
+ }
321
+
322
+ /**
323
+ * The daemon's pid if it is up. A stale pid file is not a running daemon.
324
+ *
325
+ * The pid file is JSON - `{"pid":59974,"startedAt":...}`, written by pid-manager and by the
326
+ * watchdog. Reading it as a bare integer yields NaN, which made this return null on EVERY
327
+ * call: the "refuse to --apply under a live daemon" rail that the module docstring calls
328
+ * mandatory never fired once. Found in review, verified against the live file.
329
+ *
330
+ * The legacy bare-integer form is still accepted, because an old pid file outliving an
331
+ * upgrade must not silently disable the rail a second time.
332
+ */
333
+ export function runningDaemonPid(): number | null {
334
+ const pidPath = join(homedir(), '.mama', 'mama.pid');
335
+ if (!existsSync(pidPath)) return null;
336
+ const raw = readFileSync(pidPath, 'utf8').trim();
337
+ let pid = Number.NaN;
338
+ try {
339
+ const parsed: unknown = JSON.parse(raw);
340
+ if (typeof parsed === 'number') {
341
+ // A bare integer is valid JSON, so it lands here rather than in the catch.
342
+ pid = parsed;
343
+ } else if (parsed !== null && typeof parsed === 'object') {
344
+ const value = (parsed as { pid?: unknown }).pid;
345
+ if (typeof value === 'number') pid = value;
346
+ }
347
+ } catch {
348
+ pid = Number(raw);
349
+ }
350
+ if (!Number.isInteger(pid) || pid <= 0) return null;
351
+ try {
352
+ process.kill(pid, 0);
353
+ return pid;
354
+ } catch {
355
+ return null;
356
+ }
357
+ }
358
+
359
+ function main(): void {
360
+ const apply = process.argv.includes('--apply');
361
+ const dbPath = process.env.MAMA_DB_PATH ?? join(homedir(), '.mama', 'mama-memory.db');
362
+ if (!existsSync(dbPath)) {
363
+ console.error(`No index at ${dbPath}`);
364
+ process.exit(1);
365
+ }
366
+ const loaded = loadConnectorConfig();
367
+ if (!loaded.ok) {
368
+ console.error('Connector config is unreadable; refusing to plan a re-key against a guess.');
369
+ process.exit(1);
370
+ }
371
+
372
+ const db = new Database(dbPath);
373
+ const plan = buildPlan(db, loaded.config as unknown as Record<string, unknown>);
374
+ const total = plan.rekeys.reduce((sum, rekey) => sum + rekey.events, 0);
375
+
376
+ console.log(`already canonical : ${plan.alreadyCanonical}`);
377
+ console.log(`to re-key : ${total} events across ${plan.rekeys.length} channels`);
378
+ console.log(
379
+ `unknown connector : ${plan.unknownConnector} (the config does not declare it at all)`
380
+ );
381
+ console.log(
382
+ `unmatched channel : ${plan.unmatchedChannel} (declared connector, channel matches no ` +
383
+ 'configured key or name - removed or renamed since the rows were written, and ' +
384
+ 'permanently invisible until the config names them again)'
385
+ );
386
+ if (plan.ambiguous.length > 0) {
387
+ console.log(
388
+ `AMBIGUOUS (skipped): ${plan.ambiguous.length} display names map to more than one channel`
389
+ );
390
+ }
391
+
392
+ const cursorPath = join(homedir(), '.mama', 'operator', 'trigger-loop-cursors.json');
393
+ const cursors = readCursorFile(cursorPath);
394
+ const carriedPreview = carryDeltaCursors(cursors, plan.rekeys).carried;
395
+ console.log(`delta cursors : ${carriedPreview} of ${plan.rekeys.length} partitions carry`);
396
+
397
+ if (!apply) {
398
+ console.log('\nDry run. Nothing was written. Pass --apply to perform the re-key.');
399
+ db.close();
400
+ return;
401
+ }
402
+
403
+ // A live daemon re-upserts polled events and its build overwrites `channel` from the
404
+ // poller, so a repair applied underneath it erodes silently, row by row, with no error.
405
+ const daemonPid = runningDaemonPid();
406
+ if (daemonPid !== null) {
407
+ console.error(
408
+ `Refusing to apply while the daemon is running (pid ${daemonPid}).\n` +
409
+ 'Its build rewrites channel on every re-poll of an existing event, so the repair ' +
410
+ 'would be undone one row at a time with nothing reporting it. Run `mama stop` first.'
411
+ );
412
+ db.close();
413
+ process.exit(1);
414
+ }
415
+
416
+ // VACUUM INTO, not copyFileSync: the live database is in WAL mode and a plain file copy
417
+ // omits committed-but-uncheckpointed transactions, so the "backup" would be missing the
418
+ // most recent writes precisely when it is needed.
419
+ const backup = `${dbPath}.before-channel-rekey-${new Date().toISOString().replace(/[:.]/g, '')}`;
420
+ db.prepare('VACUUM INTO ?').run(backup);
421
+ console.log(`\nbackup: ${backup}`);
422
+
423
+ const moved: Record<string, number> = {};
424
+ const run = db.transaction(() => {
425
+ for (const rekey of plan.rekeys) {
426
+ for (const [table, count] of Object.entries(applyRekey(db, rekey))) {
427
+ moved[table] = (moved[table] ?? 0) + count;
428
+ }
429
+ }
430
+ });
431
+ run();
432
+
433
+ for (const [table, count] of Object.entries(moved)) {
434
+ console.log(` ${table}: ${count}`);
435
+ }
436
+
437
+ const carried = carryDeltaCursors(cursors, plan.rekeys);
438
+ if (carried.carried > 0) {
439
+ writeFileSync(`${cursorPath}.before-channel-rekey`, JSON.stringify(cursors, null, 2));
440
+ writeFileSync(cursorPath, JSON.stringify(carried.cursors, null, 2));
441
+ console.log(` delta cursors carried: ${carried.carried}`);
442
+ }
443
+ db.close();
444
+ }
445
+
446
+ // Only run when invoked directly, so the planning and merge logic stay testable.
447
+ // Matches the compiled .js too: gating on the .ts name alone made a built copy exit
448
+ // silently having done nothing.
449
+ if (/backfill-channel-keys\.(ts|js)$/.test(process.argv[1] ?? '')) {
450
+ main();
451
+ }
@@ -1,48 +0,0 @@
1
- /**
2
- * Auto-Recall Module for MAMA Standalone
3
- *
4
- * Ported from OpenClaw plugin's auto-recall logic to standalone.
5
- * Automatically searches related memories before agent start and injects into context.
6
- *
7
- * Features:
8
- * - Prompt-based semantic search
9
- * - Recent checkpoint loading
10
- * - Related decision context injection
11
- */
12
- /**
13
- * Auto-recall result type
14
- */
15
- export interface AutoRecallResult {
16
- /** Context string to inject */
17
- context: string;
18
- /** Number of semantic search results */
19
- semanticMatches: number;
20
- /** Number of recent decisions */
21
- recentDecisions: number;
22
- /** Whether a checkpoint exists */
23
- hasCheckpoint: boolean;
24
- }
25
- /**
26
- * Execute prompt-based auto-recall
27
- *
28
- * Ported from OpenClaw's before_agent_start hook logic to standalone.
29
- *
30
- * @param userPrompt - User prompt (used as semantic search query)
31
- * @param options - Options
32
- * @returns AutoRecallResult or null (no memories found)
33
- */
34
- export declare function autoRecall(userPrompt: string, options?: {
35
- dbPath?: string;
36
- semanticLimit?: number;
37
- recentLimit?: number;
38
- threshold?: number;
39
- }): Promise<AutoRecallResult | null>;
40
- /**
41
- * Direct MAMA API access (advanced usage)
42
- */
43
- export declare function getMAMAApi(): any;
44
- /**
45
- * Check initialization status
46
- */
47
- export declare function isInitialized(): boolean;
48
- //# sourceMappingURL=auto-recall.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auto-recall.d.ts","sourceRoot":"","sources":["../../src/agent/auto-recall.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAsFH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,eAAe,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,kCAAkC;IAClC,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC9B,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACf,GACL,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA6GlC;AAED;;GAEG;AAEH,wBAAgB,UAAU,IAAI,GAAG,CAEhC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC"}
@@ -1,192 +0,0 @@
1
- "use strict";
2
- /**
3
- * Auto-Recall Module for MAMA Standalone
4
- *
5
- * Ported from OpenClaw plugin's auto-recall logic to standalone.
6
- * Automatically searches related memories before agent start and injects into context.
7
- *
8
- * Features:
9
- * - Prompt-based semantic search
10
- * - Recent checkpoint loading
11
- * - Related decision context injection
12
- */
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.autoRecall = autoRecall;
18
- exports.getMAMAApi = getMAMAApi;
19
- exports.isInitialized = isInitialized;
20
- const node_path_1 = __importDefault(require("node:path"));
21
- const node_os_1 = __importDefault(require("node:os"));
22
- // Singleton state
23
- let initialized = false;
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- let mamaApi = null;
26
- /**
27
- * Format reasoning with link extraction (reused from OpenClaw logic)
28
- */
29
- function formatReasoning(reasoning, maxLen = 80) {
30
- if (!reasoning)
31
- return '';
32
- // Extract link patterns
33
- const linkMatch = reasoning.match(/(builds_on|debates|synthesizes):\s*[\w[\],\s_-]+/i);
34
- // Truncate main reasoning
35
- const truncated = reasoning.length > maxLen ? reasoning.substring(0, maxLen) + '...' : reasoning;
36
- // Add link info if found and not already in truncated part
37
- if (linkMatch && !truncated.includes(linkMatch[0])) {
38
- return `${truncated}\n 🔗 ${linkMatch[0]}`;
39
- }
40
- return truncated;
41
- }
42
- /**
43
- * Initialize MAMA API (lazy, singleton)
44
- */
45
- async function initMAMA(dbPath) {
46
- if (initialized && mamaApi) {
47
- return;
48
- }
49
- const finalDbPath = dbPath || process.env.MAMA_DB_PATH || node_path_1.default.join(node_os_1.default.homedir(), '.claude/mama-memory.db');
50
- process.env.MAMA_DB_PATH = finalDbPath;
51
- try {
52
- // Dynamic import of mama-core modules
53
- // eslint-disable-next-line @typescript-eslint/no-require-imports
54
- mamaApi = require('@jungjaehoon/mama-core/mama-api');
55
- // Initialize database
56
- // eslint-disable-next-line @typescript-eslint/no-require-imports
57
- const dbManager = require('@jungjaehoon/mama-core/db-manager');
58
- await dbManager.initDB();
59
- initialized = true;
60
- console.log(`[AutoRecall] MAMA initialized (db: ${finalDbPath})`);
61
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
- }
63
- catch (err) {
64
- console.error('[AutoRecall] MAMA init failed:', err.message);
65
- // Don't throw - auto-recall should be optional
66
- }
67
- }
68
- /**
69
- * Execute prompt-based auto-recall
70
- *
71
- * Ported from OpenClaw's before_agent_start hook logic to standalone.
72
- *
73
- * @param userPrompt - User prompt (used as semantic search query)
74
- * @param options - Options
75
- * @returns AutoRecallResult or null (no memories found)
76
- */
77
- async function autoRecall(userPrompt, options = {}) {
78
- try {
79
- await initMAMA(options.dbPath);
80
- if (!mamaApi) {
81
- return null;
82
- }
83
- const semanticLimit = options.semanticLimit ?? 3;
84
- const recentLimit = options.recentLimit ?? 3;
85
- const threshold = options.threshold ?? 0.5;
86
- // 1. Semantic search (only when prompt is long enough)
87
- let semanticResults = [];
88
- if (userPrompt && userPrompt.length >= 5) {
89
- try {
90
- const searchResult = await mamaApi.suggest(userPrompt, {
91
- limit: semanticLimit,
92
- threshold,
93
- });
94
- semanticResults = searchResult?.results || [];
95
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- }
97
- catch (err) {
98
- console.error('[AutoRecall] Semantic search error:', err.message);
99
- }
100
- }
101
- // 2. Load checkpoint
102
- let checkpoint = null;
103
- try {
104
- checkpoint = await mamaApi.loadCheckpoint();
105
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
- }
107
- catch (err) {
108
- console.error('[AutoRecall] Checkpoint load error:', err.message);
109
- }
110
- // 3. Load recent decisions (only when no semantic results)
111
- let recentDecisions = [];
112
- if (semanticResults.length === 0) {
113
- try {
114
- recentDecisions = await mamaApi.listDecisions({ limit: recentLimit });
115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- }
117
- catch (err) {
118
- console.error('[AutoRecall] Recent decisions error:', err.message);
119
- }
120
- }
121
- // 4. Return null if no context found
122
- if (!checkpoint && semanticResults.length === 0 && recentDecisions.length === 0) {
123
- return null;
124
- }
125
- // 5. Build context string
126
- let content = '<relevant-memories>\n';
127
- content += '# MAMA Memory Context\n\n';
128
- if (semanticResults.length > 0) {
129
- content += '## Related Decisions (Semantic Match)\n\n';
130
- semanticResults.forEach((r) => {
131
- const pct = Math.round((r.similarity || 0) * 100);
132
- content += `- **${r.topic}** [${pct}%]: ${r.decision}`;
133
- if (r.outcome)
134
- content += ` (${r.outcome})`;
135
- content += `\n _${formatReasoning(r.reasoning, 100)}_\n`;
136
- content += ` ID: \`${r.id}\`\n`;
137
- });
138
- content += '\n';
139
- }
140
- if (checkpoint) {
141
- let ts;
142
- try {
143
- ts = new Date(checkpoint.timestamp).toISOString();
144
- }
145
- catch {
146
- ts = String(checkpoint.timestamp);
147
- }
148
- content += `## Last Checkpoint (${ts})\n\n`;
149
- content += `**Summary:** ${checkpoint.summary}\n\n`;
150
- if (checkpoint.next_steps) {
151
- content += `**Next Steps:** ${checkpoint.next_steps}\n\n`;
152
- }
153
- }
154
- if (recentDecisions.length > 0) {
155
- content += '## Recent Decisions\n\n';
156
- recentDecisions.forEach((d) => {
157
- content += `- **${d.topic}**: ${d.decision}`;
158
- if (d.outcome)
159
- content += ` (${d.outcome})`;
160
- content += '\n';
161
- });
162
- content += '\n';
163
- }
164
- content += '</relevant-memories>';
165
- console.log(`[AutoRecall] Found: ${semanticResults.length} semantic, ${recentDecisions.length} recent, checkpoint: ${!!checkpoint}`);
166
- return {
167
- context: content,
168
- semanticMatches: semanticResults.length,
169
- recentDecisions: recentDecisions.length,
170
- hasCheckpoint: !!checkpoint,
171
- };
172
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
173
- }
174
- catch (err) {
175
- console.error('[AutoRecall] Error:', err.message);
176
- return null;
177
- }
178
- }
179
- /**
180
- * Direct MAMA API access (advanced usage)
181
- */
182
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
- function getMAMAApi() {
184
- return mamaApi;
185
- }
186
- /**
187
- * Check initialization status
188
- */
189
- function isInitialized() {
190
- return initialized;
191
- }
192
- //# sourceMappingURL=auto-recall.js.map