@hailer/mcp 1.2.1 → 1.3.10

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 (774) hide show
  1. package/.claude/agents/agent-hailer-helper.md +118 -0
  2. package/.claude/commands/debug-squad.md +13 -290
  3. package/.claude/commands/publish.md +2 -2
  4. package/.claude/commands/review-squad.md +17 -139
  5. package/.claude/skills/create-and-publish-app/SKILL.md +133 -143
  6. package/.claude/skills/hailer-app-builder/SKILL.md +29 -2
  7. package/.claude/skills/hailer-ui-guide/SKILL.md +265 -0
  8. package/.env.example +50 -1
  9. package/CLAUDE.md +141 -10
  10. package/dist/app-prep.d.ts +27 -0
  11. package/dist/app-prep.d.ts.map +1 -0
  12. package/dist/app-prep.js +94 -0
  13. package/dist/app-prep.js.map +1 -0
  14. package/dist/app.d.ts.map +1 -1
  15. package/dist/app.js +3 -0
  16. package/dist/app.js.map +1 -1
  17. package/dist/bot/bot-manager.d.ts +9 -6
  18. package/dist/bot/bot-manager.d.ts.map +1 -1
  19. package/dist/bot/bot-manager.js +142 -31
  20. package/dist/bot/bot-manager.js.map +1 -1
  21. package/dist/bot/bot.d.ts +61 -16
  22. package/dist/bot/bot.d.ts.map +1 -1
  23. package/dist/bot/bot.js +927 -151
  24. package/dist/bot/bot.js.map +1 -1
  25. package/dist/bot/operation-logger.d.ts.map +1 -1
  26. package/dist/bot/operation-logger.js +24 -12
  27. package/dist/bot/operation-logger.js.map +1 -1
  28. package/dist/bot/services/bot-permissions.d.ts +37 -5
  29. package/dist/bot/services/bot-permissions.d.ts.map +1 -1
  30. package/dist/bot/services/bot-permissions.js +159 -35
  31. package/dist/bot/services/bot-permissions.js.map +1 -1
  32. package/dist/bot/services/conversation-manager.d.ts +23 -23
  33. package/dist/bot/services/conversation-manager.d.ts.map +1 -1
  34. package/dist/bot/services/conversation-manager.js +52 -49
  35. package/dist/bot/services/conversation-manager.js.map +1 -1
  36. package/dist/bot/services/helper-prompt.d.ts +8 -0
  37. package/dist/bot/services/helper-prompt.d.ts.map +1 -0
  38. package/dist/bot/services/helper-prompt.js +177 -0
  39. package/dist/bot/services/helper-prompt.js.map +1 -0
  40. package/dist/bot/services/message-classifier.d.ts +16 -16
  41. package/dist/bot/services/message-classifier.d.ts.map +1 -1
  42. package/dist/bot/services/message-classifier.js +55 -49
  43. package/dist/bot/services/message-classifier.js.map +1 -1
  44. package/dist/bot/services/message-formatter.d.ts +47 -38
  45. package/dist/bot/services/message-formatter.d.ts.map +1 -1
  46. package/dist/bot/services/message-formatter.js +99 -80
  47. package/dist/bot/services/message-formatter.js.map +1 -1
  48. package/dist/bot/services/permission-guard.d.ts.map +1 -1
  49. package/dist/bot/services/permission-guard.js +20 -10
  50. package/dist/bot/services/permission-guard.js.map +1 -1
  51. package/dist/bot/services/signal-router.d.ts.map +1 -1
  52. package/dist/bot/services/signal-router.js +11 -6
  53. package/dist/bot/services/signal-router.js.map +1 -1
  54. package/dist/bot/services/system-prompt.d.ts +14 -0
  55. package/dist/bot/services/system-prompt.d.ts.map +1 -1
  56. package/dist/bot/services/system-prompt.js +181 -4
  57. package/dist/bot/services/system-prompt.js.map +1 -1
  58. package/dist/bot/services/token-billing.d.ts +23 -23
  59. package/dist/bot/services/token-billing.d.ts.map +1 -1
  60. package/dist/bot/services/token-billing.js +51 -36
  61. package/dist/bot/services/token-billing.js.map +1 -1
  62. package/dist/bot/services/types.d.ts +3 -1
  63. package/dist/bot/services/types.d.ts.map +1 -1
  64. package/dist/bot/services/typing-indicator.d.ts +8 -8
  65. package/dist/bot/services/typing-indicator.d.ts.map +1 -1
  66. package/dist/bot/services/typing-indicator.js +12 -10
  67. package/dist/bot/services/typing-indicator.js.map +1 -1
  68. package/dist/bot/services/workspace-refresh.d.ts +3 -3
  69. package/dist/bot/services/workspace-refresh.d.ts.map +1 -1
  70. package/dist/bot/services/workspace-refresh.js +23 -13
  71. package/dist/bot/services/workspace-refresh.js.map +1 -1
  72. package/dist/bot/tool-executor.d.ts +10 -6
  73. package/dist/bot/tool-executor.d.ts.map +1 -1
  74. package/dist/bot/tool-executor.js +12 -6
  75. package/dist/bot/tool-executor.js.map +1 -1
  76. package/dist/bot/workspace-overview.d.ts.map +1 -1
  77. package/dist/bot/workspace-overview.js +6 -3
  78. package/dist/bot/workspace-overview.js.map +1 -1
  79. package/dist/bot-config/activity-error.d.ts +47 -0
  80. package/dist/bot-config/activity-error.d.ts.map +1 -0
  81. package/dist/bot-config/activity-error.js +67 -0
  82. package/dist/bot-config/activity-error.js.map +1 -0
  83. package/dist/bot-config/context.d.ts +4 -4
  84. package/dist/bot-config/context.d.ts.map +1 -1
  85. package/dist/bot-config/context.js +18 -14
  86. package/dist/bot-config/context.js.map +1 -1
  87. package/dist/bot-config/events.d.ts +45 -0
  88. package/dist/bot-config/events.d.ts.map +1 -0
  89. package/dist/bot-config/events.js +51 -0
  90. package/dist/bot-config/events.js.map +1 -0
  91. package/dist/bot-config/index.d.ts +3 -0
  92. package/dist/bot-config/index.d.ts.map +1 -1
  93. package/dist/bot-config/index.js +8 -1
  94. package/dist/bot-config/index.js.map +1 -1
  95. package/dist/bot-config/loader.d.ts +3 -0
  96. package/dist/bot-config/loader.d.ts.map +1 -1
  97. package/dist/bot-config/loader.js +45 -20
  98. package/dist/bot-config/loader.js.map +1 -1
  99. package/dist/bot-config/persistence.js.map +1 -1
  100. package/dist/bot-config/reconciler.d.ts +11 -0
  101. package/dist/bot-config/reconciler.d.ts.map +1 -0
  102. package/dist/bot-config/reconciler.js +121 -0
  103. package/dist/bot-config/reconciler.js.map +1 -0
  104. package/dist/bot-config/state.d.ts.map +1 -1
  105. package/dist/bot-config/state.js.map +1 -1
  106. package/dist/bot-config/types.d.ts +32 -0
  107. package/dist/bot-config/types.d.ts.map +1 -1
  108. package/dist/bot-config/webhooks.d.ts.map +1 -1
  109. package/dist/bot-config/webhooks.js.map +1 -1
  110. package/dist/bot-config/workflow-installer.d.ts +37 -0
  111. package/dist/bot-config/workflow-installer.d.ts.map +1 -0
  112. package/dist/bot-config/workflow-installer.js +346 -0
  113. package/dist/bot-config/workflow-installer.js.map +1 -0
  114. package/dist/cli.d.ts +4 -1
  115. package/dist/cli.d.ts.map +1 -1
  116. package/dist/cli.js +92 -11
  117. package/dist/cli.js.map +1 -1
  118. package/dist/config.d.ts +23 -19
  119. package/dist/config.d.ts.map +1 -1
  120. package/dist/config.js +65 -27
  121. package/dist/config.js.map +1 -1
  122. package/dist/core.d.ts +6 -4
  123. package/dist/core.d.ts.map +1 -1
  124. package/dist/core.js +11 -16
  125. package/dist/core.js.map +1 -1
  126. package/dist/lib/logger.d.ts.map +1 -1
  127. package/dist/lib/logger.js +7 -4
  128. package/dist/lib/logger.js.map +1 -1
  129. package/dist/lib/request-logger.d.ts +19 -19
  130. package/dist/lib/request-logger.d.ts.map +1 -1
  131. package/dist/lib/request-logger.js +19 -19
  132. package/dist/lib/request-logger.js.map +1 -1
  133. package/dist/mcp/UserContextCache.d.ts +28 -22
  134. package/dist/mcp/UserContextCache.d.ts.map +1 -1
  135. package/dist/mcp/UserContextCache.js +23 -23
  136. package/dist/mcp/UserContextCache.js.map +1 -1
  137. package/dist/mcp/auth.js.map +1 -1
  138. package/dist/mcp/hailer-clients.d.ts +5 -4
  139. package/dist/mcp/hailer-clients.d.ts.map +1 -1
  140. package/dist/mcp/hailer-clients.js +83 -34
  141. package/dist/mcp/hailer-clients.js.map +1 -1
  142. package/dist/mcp/hailer-rpc.d.ts +40 -0
  143. package/dist/mcp/hailer-rpc.d.ts.map +1 -0
  144. package/dist/mcp/hailer-rpc.js +43 -0
  145. package/dist/mcp/hailer-rpc.js.map +1 -0
  146. package/dist/mcp/publish-auth-injector.d.ts +22 -0
  147. package/dist/mcp/publish-auth-injector.d.ts.map +1 -0
  148. package/dist/mcp/publish-auth-injector.js +100 -0
  149. package/dist/mcp/publish-auth-injector.js.map +1 -0
  150. package/dist/mcp/session-store.d.ts +16 -16
  151. package/dist/mcp/session-store.d.ts.map +1 -1
  152. package/dist/mcp/session-store.js +16 -16
  153. package/dist/mcp/session-store.js.map +1 -1
  154. package/dist/mcp/tool-profiles.d.ts +69 -0
  155. package/dist/mcp/tool-profiles.d.ts.map +1 -0
  156. package/dist/mcp/tool-profiles.js +184 -0
  157. package/dist/mcp/tool-profiles.js.map +1 -0
  158. package/dist/mcp/tool-registry.d.ts +16 -0
  159. package/dist/mcp/tool-registry.d.ts.map +1 -1
  160. package/dist/mcp/tool-registry.js +91 -39
  161. package/dist/mcp/tool-registry.js.map +1 -1
  162. package/dist/mcp/tools/activity.d.ts +2 -0
  163. package/dist/mcp/tools/activity.d.ts.map +1 -1
  164. package/dist/mcp/tools/activity.js +575 -218
  165. package/dist/mcp/tools/activity.js.map +1 -1
  166. package/dist/mcp/tools/aliases.d.ts +11 -0
  167. package/dist/mcp/tools/aliases.d.ts.map +1 -0
  168. package/dist/mcp/tools/aliases.js +182 -0
  169. package/dist/mcp/tools/aliases.js.map +1 -0
  170. package/dist/mcp/tools/app-core.d.ts +6 -8
  171. package/dist/mcp/tools/app-core.d.ts.map +1 -1
  172. package/dist/mcp/tools/app-core.js +355 -254
  173. package/dist/mcp/tools/app-core.js.map +1 -1
  174. package/dist/mcp/tools/app-marketplace.d.ts +12 -16
  175. package/dist/mcp/tools/app-marketplace.d.ts.map +1 -1
  176. package/dist/mcp/tools/app-marketplace.js +748 -856
  177. package/dist/mcp/tools/app-marketplace.js.map +1 -1
  178. package/dist/mcp/tools/app.d.ts +4 -7
  179. package/dist/mcp/tools/app.d.ts.map +1 -1
  180. package/dist/mcp/tools/app.js +4 -7
  181. package/dist/mcp/tools/app.js.map +1 -1
  182. package/dist/mcp/tools/bot-self.d.ts +21 -0
  183. package/dist/mcp/tools/bot-self.d.ts.map +1 -0
  184. package/dist/mcp/tools/bot-self.js +174 -0
  185. package/dist/mcp/tools/bot-self.js.map +1 -0
  186. package/dist/mcp/tools/calendar.d.ts +21 -0
  187. package/dist/mcp/tools/calendar.d.ts.map +1 -0
  188. package/dist/mcp/tools/calendar.js +741 -0
  189. package/dist/mcp/tools/calendar.js.map +1 -0
  190. package/dist/mcp/tools/company.d.ts.map +1 -1
  191. package/dist/mcp/tools/company.js +2 -1
  192. package/dist/mcp/tools/company.js.map +1 -1
  193. package/dist/mcp/tools/date.js.map +1 -1
  194. package/dist/mcp/tools/discussion.d.ts +29 -3
  195. package/dist/mcp/tools/discussion.d.ts.map +1 -1
  196. package/dist/mcp/tools/discussion.js +419 -534
  197. package/dist/mcp/tools/discussion.js.map +1 -1
  198. package/dist/mcp/tools/file.d.ts.map +1 -1
  199. package/dist/mcp/tools/file.js +18 -16
  200. package/dist/mcp/tools/file.js.map +1 -1
  201. package/dist/mcp/tools/index.js +4 -4
  202. package/dist/mcp/tools/index.js.map +1 -1
  203. package/dist/mcp/tools/insight.d.ts +24 -5
  204. package/dist/mcp/tools/insight.d.ts.map +1 -1
  205. package/dist/mcp/tools/insight.js +513 -480
  206. package/dist/mcp/tools/insight.js.map +1 -1
  207. package/dist/mcp/tools/user.d.ts.map +1 -1
  208. package/dist/mcp/tools/user.js +15 -13
  209. package/dist/mcp/tools/user.js.map +1 -1
  210. package/dist/mcp/tools/workflow-permissions.d.ts +2 -4
  211. package/dist/mcp/tools/workflow-permissions.d.ts.map +1 -1
  212. package/dist/mcp/tools/workflow-permissions.js +88 -97
  213. package/dist/mcp/tools/workflow-permissions.js.map +1 -1
  214. package/dist/mcp/tools/workflow.d.ts +9 -7
  215. package/dist/mcp/tools/workflow.d.ts.map +1 -1
  216. package/dist/mcp/tools/workflow.js +852 -860
  217. package/dist/mcp/tools/workflow.js.map +1 -1
  218. package/dist/mcp/utils/api-errors.d.ts.map +1 -1
  219. package/dist/mcp/utils/api-errors.js +2 -2
  220. package/dist/mcp/utils/api-errors.js.map +1 -1
  221. package/dist/mcp/utils/data-transformers.d.ts +0 -3
  222. package/dist/mcp/utils/data-transformers.d.ts.map +1 -1
  223. package/dist/mcp/utils/data-transformers.js +32 -5
  224. package/dist/mcp/utils/data-transformers.js.map +1 -1
  225. package/dist/mcp/utils/file-upload.d.ts.map +1 -1
  226. package/dist/mcp/utils/file-upload.js +1 -1
  227. package/dist/mcp/utils/file-upload.js.map +1 -1
  228. package/dist/mcp/utils/hailer-api-client.d.ts +81 -81
  229. package/dist/mcp/utils/hailer-api-client.d.ts.map +1 -1
  230. package/dist/mcp/utils/hailer-api-client.js +113 -103
  231. package/dist/mcp/utils/hailer-api-client.js.map +1 -1
  232. package/dist/mcp/utils/index.d.ts.map +1 -1
  233. package/dist/mcp/utils/index.js.map +1 -1
  234. package/dist/mcp/utils/logger.d.ts.map +1 -1
  235. package/dist/mcp/utils/logger.js.map +1 -1
  236. package/dist/mcp/utils/response-builder.d.ts.map +1 -1
  237. package/dist/mcp/utils/response-builder.js +8 -4
  238. package/dist/mcp/utils/response-builder.js.map +1 -1
  239. package/dist/mcp/utils/role-utils.d.ts.map +1 -1
  240. package/dist/mcp/utils/role-utils.js +6 -3
  241. package/dist/mcp/utils/role-utils.js.map +1 -1
  242. package/dist/mcp/utils/tool-helpers.d.ts.map +1 -1
  243. package/dist/mcp/utils/tool-helpers.js +2 -2
  244. package/dist/mcp/utils/tool-helpers.js.map +1 -1
  245. package/dist/mcp/utils/types.d.ts +2 -1
  246. package/dist/mcp/utils/types.d.ts.map +1 -1
  247. package/dist/mcp/utils/types.js.map +1 -1
  248. package/dist/mcp/webhook-handler.d.ts +43 -8
  249. package/dist/mcp/webhook-handler.d.ts.map +1 -1
  250. package/dist/mcp/webhook-handler.js +861 -116
  251. package/dist/mcp/webhook-handler.js.map +1 -1
  252. package/dist/mcp/workspace-admin-store.d.ts +49 -0
  253. package/dist/mcp/workspace-admin-store.d.ts.map +1 -0
  254. package/dist/mcp/workspace-admin-store.js +168 -0
  255. package/dist/mcp/workspace-admin-store.js.map +1 -0
  256. package/dist/mcp/workspace-cache.d.ts +2 -2
  257. package/dist/mcp/workspace-cache.d.ts.map +1 -1
  258. package/dist/mcp/workspace-cache.js +9 -5
  259. package/dist/mcp/workspace-cache.js.map +1 -1
  260. package/dist/mcp-server.d.ts +26 -11
  261. package/dist/mcp-server.d.ts.map +1 -1
  262. package/dist/mcp-server.js +367 -48
  263. package/dist/mcp-server.js.map +1 -1
  264. package/dist/plugins/vipunen/client.d.ts +41 -41
  265. package/dist/plugins/vipunen/client.d.ts.map +1 -1
  266. package/dist/plugins/vipunen/client.js +53 -48
  267. package/dist/plugins/vipunen/client.js.map +1 -1
  268. package/dist/plugins/vipunen/index.js.map +1 -1
  269. package/dist/plugins/vipunen/tools.d.ts.map +1 -1
  270. package/dist/plugins/vipunen/tools.js +6 -3
  271. package/dist/plugins/vipunen/tools.js.map +1 -1
  272. package/dist/public-chat/graduate.d.ts +29 -0
  273. package/dist/public-chat/graduate.d.ts.map +1 -0
  274. package/dist/public-chat/graduate.js +593 -0
  275. package/dist/public-chat/graduate.js.map +1 -0
  276. package/dist/public-chat/handler.d.ts +12 -0
  277. package/dist/public-chat/handler.d.ts.map +1 -0
  278. package/dist/public-chat/handler.js +183 -0
  279. package/dist/public-chat/handler.js.map +1 -0
  280. package/dist/public-chat/index.d.ts +16 -0
  281. package/dist/public-chat/index.d.ts.map +1 -0
  282. package/dist/public-chat/index.js +74 -0
  283. package/dist/public-chat/index.js.map +1 -0
  284. package/dist/public-chat/knowledge.d.ts +3 -0
  285. package/dist/public-chat/knowledge.d.ts.map +1 -0
  286. package/dist/public-chat/knowledge.js +1340 -0
  287. package/dist/public-chat/knowledge.js.map +1 -0
  288. package/dist/public-chat/rate-limit.d.ts +16 -0
  289. package/dist/public-chat/rate-limit.d.ts.map +1 -0
  290. package/dist/public-chat/rate-limit.js +51 -0
  291. package/dist/public-chat/rate-limit.js.map +1 -0
  292. package/dist/public-chat/session-store.d.ts +41 -0
  293. package/dist/public-chat/session-store.d.ts.map +1 -0
  294. package/dist/public-chat/session-store.js +95 -0
  295. package/dist/public-chat/session-store.js.map +1 -0
  296. package/dist/public-chat/studio-prewarm.d.ts +61 -0
  297. package/dist/public-chat/studio-prewarm.d.ts.map +1 -0
  298. package/dist/public-chat/studio-prewarm.js +162 -0
  299. package/dist/public-chat/studio-prewarm.js.map +1 -0
  300. package/dist/public-chat/system-prompt.d.ts +22 -0
  301. package/dist/public-chat/system-prompt.d.ts.map +1 -0
  302. package/dist/public-chat/system-prompt.js +435 -0
  303. package/dist/public-chat/system-prompt.js.map +1 -0
  304. package/package.json +13 -7
  305. package/scripts/build-public-chat-knowledge.py +101 -0
  306. package/scripts/smoke-public-chat-live.ts +148 -0
  307. package/scripts/smoke-public-chat.ts +110 -0
  308. package/.claude/CLAUDE.md +0 -126
  309. package/.claude/commands/app-squad.md +0 -131
  310. package/.claude/commands/audit-squad.md +0 -158
  311. package/.claude/commands/cleanup-squad.md +0 -98
  312. package/.claude/commands/config-squad.md +0 -106
  313. package/.claude/commands/crud-squad.md +0 -87
  314. package/.claude/commands/data-squad.md +0 -97
  315. package/.claude/commands/doc-squad.md +0 -65
  316. package/.claude/commands/help.md +0 -29
  317. package/.claude/commands/help:agents.md +0 -182
  318. package/.claude/commands/help:commands.md +0 -78
  319. package/.claude/commands/help:faq.md +0 -79
  320. package/.claude/commands/help:plugins.md +0 -50
  321. package/.claude/commands/help:skills.md +0 -87
  322. package/.claude/commands/help:tools.md +0 -75
  323. package/.claude/commands/hotfix-squad.md +0 -112
  324. package/.claude/commands/integration-squad.md +0 -82
  325. package/.claude/commands/janitor-squad.md +0 -167
  326. package/.claude/commands/onboard-squad.md +0 -130
  327. package/.claude/commands/swarm.md +0 -210
  328. package/.claude/commands/tool-builder.md +0 -39
  329. package/.claude/skills/publish-hailer-app/SKILL.md +0 -280
  330. package/dist/CLAUDE.md +0 -370
  331. package/dist/agents/bot-manager.d.ts +0 -48
  332. package/dist/agents/bot-manager.d.ts.map +0 -1
  333. package/dist/agents/bot-manager.js +0 -254
  334. package/dist/agents/bot-manager.js.map +0 -1
  335. package/dist/agents/bug-fixer/ai.d.ts +0 -80
  336. package/dist/agents/bug-fixer/ai.d.ts.map +0 -1
  337. package/dist/agents/bug-fixer/ai.js +0 -466
  338. package/dist/agents/bug-fixer/ai.js.map +0 -1
  339. package/dist/agents/bug-fixer/bot.d.ts +0 -92
  340. package/dist/agents/bug-fixer/bot.d.ts.map +0 -1
  341. package/dist/agents/bug-fixer/bot.js +0 -687
  342. package/dist/agents/bug-fixer/bot.js.map +0 -1
  343. package/dist/agents/bug-fixer/config.d.ts +0 -21
  344. package/dist/agents/bug-fixer/config.d.ts.map +0 -1
  345. package/dist/agents/bug-fixer/config.js +0 -218
  346. package/dist/agents/bug-fixer/config.js.map +0 -1
  347. package/dist/agents/bug-fixer/files.d.ts +0 -67
  348. package/dist/agents/bug-fixer/files.d.ts.map +0 -1
  349. package/dist/agents/bug-fixer/files.js +0 -386
  350. package/dist/agents/bug-fixer/files.js.map +0 -1
  351. package/dist/agents/bug-fixer/git.d.ts +0 -48
  352. package/dist/agents/bug-fixer/git.d.ts.map +0 -1
  353. package/dist/agents/bug-fixer/git.js +0 -298
  354. package/dist/agents/bug-fixer/git.js.map +0 -1
  355. package/dist/agents/bug-fixer/index.d.ts +0 -103
  356. package/dist/agents/bug-fixer/index.d.ts.map +0 -1
  357. package/dist/agents/bug-fixer/index.js +0 -262
  358. package/dist/agents/bug-fixer/index.js.map +0 -1
  359. package/dist/agents/bug-fixer/lsp.d.ts +0 -113
  360. package/dist/agents/bug-fixer/lsp.d.ts.map +0 -1
  361. package/dist/agents/bug-fixer/lsp.js +0 -485
  362. package/dist/agents/bug-fixer/lsp.js.map +0 -1
  363. package/dist/agents/bug-fixer/monitor.d.ts +0 -123
  364. package/dist/agents/bug-fixer/monitor.d.ts.map +0 -1
  365. package/dist/agents/bug-fixer/monitor.js +0 -629
  366. package/dist/agents/bug-fixer/monitor.js.map +0 -1
  367. package/dist/agents/bug-fixer/prompt.d.ts +0 -5
  368. package/dist/agents/bug-fixer/prompt.d.ts.map +0 -1
  369. package/dist/agents/bug-fixer/prompt.js +0 -94
  370. package/dist/agents/bug-fixer/prompt.js.map +0 -1
  371. package/dist/agents/bug-fixer/registries/pending-classification.d.ts +0 -28
  372. package/dist/agents/bug-fixer/registries/pending-classification.d.ts.map +0 -1
  373. package/dist/agents/bug-fixer/registries/pending-classification.js +0 -50
  374. package/dist/agents/bug-fixer/registries/pending-classification.js.map +0 -1
  375. package/dist/agents/bug-fixer/registries/pending-fix.d.ts +0 -33
  376. package/dist/agents/bug-fixer/registries/pending-fix.d.ts.map +0 -1
  377. package/dist/agents/bug-fixer/registries/pending-fix.js +0 -64
  378. package/dist/agents/bug-fixer/registries/pending-fix.js.map +0 -1
  379. package/dist/agents/bug-fixer/registries/pending.d.ts +0 -27
  380. package/dist/agents/bug-fixer/registries/pending.d.ts.map +0 -1
  381. package/dist/agents/bug-fixer/registries/pending.js +0 -49
  382. package/dist/agents/bug-fixer/registries/pending.js.map +0 -1
  383. package/dist/agents/bug-fixer/specialist-daemon.d.ts +0 -88
  384. package/dist/agents/bug-fixer/specialist-daemon.d.ts.map +0 -1
  385. package/dist/agents/bug-fixer/specialist-daemon.js +0 -431
  386. package/dist/agents/bug-fixer/specialist-daemon.js.map +0 -1
  387. package/dist/agents/bug-fixer/specialist.d.ts +0 -47
  388. package/dist/agents/bug-fixer/specialist.d.ts.map +0 -1
  389. package/dist/agents/bug-fixer/specialist.js +0 -327
  390. package/dist/agents/bug-fixer/specialist.js.map +0 -1
  391. package/dist/agents/bug-fixer/types.d.ts +0 -123
  392. package/dist/agents/bug-fixer/types.d.ts.map +0 -1
  393. package/dist/agents/bug-fixer/types.js +0 -9
  394. package/dist/agents/bug-fixer/types.js.map +0 -1
  395. package/dist/agents/factory.d.ts +0 -172
  396. package/dist/agents/factory.d.ts.map +0 -1
  397. package/dist/agents/factory.js +0 -706
  398. package/dist/agents/factory.js.map +0 -1
  399. package/dist/agents/hailer-expert/index.d.ts +0 -8
  400. package/dist/agents/hailer-expert/index.d.ts.map +0 -1
  401. package/dist/agents/hailer-expert/index.js +0 -14
  402. package/dist/agents/hailer-expert/index.js.map +0 -1
  403. package/dist/agents/hal/daemon.d.ts +0 -174
  404. package/dist/agents/hal/daemon.d.ts.map +0 -1
  405. package/dist/agents/hal/daemon.js +0 -1385
  406. package/dist/agents/hal/daemon.js.map +0 -1
  407. package/dist/agents/hal/definitions.d.ts +0 -42
  408. package/dist/agents/hal/definitions.d.ts.map +0 -1
  409. package/dist/agents/hal/definitions.js +0 -300
  410. package/dist/agents/hal/definitions.js.map +0 -1
  411. package/dist/agents/hal/index.d.ts +0 -3
  412. package/dist/agents/hal/index.d.ts.map +0 -1
  413. package/dist/agents/hal/index.js +0 -8
  414. package/dist/agents/hal/index.js.map +0 -1
  415. package/dist/agents/index.d.ts +0 -18
  416. package/dist/agents/index.d.ts.map +0 -1
  417. package/dist/agents/index.js +0 -48
  418. package/dist/agents/index.js.map +0 -1
  419. package/dist/agents/shared/base.d.ts +0 -253
  420. package/dist/agents/shared/base.d.ts.map +0 -1
  421. package/dist/agents/shared/base.js +0 -1122
  422. package/dist/agents/shared/base.js.map +0 -1
  423. package/dist/agents/shared/schemas/action-schema.d.ts +0 -62
  424. package/dist/agents/shared/schemas/action-schema.d.ts.map +0 -1
  425. package/dist/agents/shared/schemas/action-schema.js +0 -483
  426. package/dist/agents/shared/schemas/action-schema.js.map +0 -1
  427. package/dist/agents/shared/services/agent-registry.d.ts +0 -108
  428. package/dist/agents/shared/services/agent-registry.d.ts.map +0 -1
  429. package/dist/agents/shared/services/agent-registry.js +0 -469
  430. package/dist/agents/shared/services/agent-registry.js.map +0 -1
  431. package/dist/agents/shared/services/conversation-manager.d.ts +0 -57
  432. package/dist/agents/shared/services/conversation-manager.d.ts.map +0 -1
  433. package/dist/agents/shared/services/conversation-manager.js +0 -168
  434. package/dist/agents/shared/services/conversation-manager.js.map +0 -1
  435. package/dist/agents/shared/services/mcp-client.d.ts +0 -56
  436. package/dist/agents/shared/services/mcp-client.d.ts.map +0 -1
  437. package/dist/agents/shared/services/mcp-client.js +0 -124
  438. package/dist/agents/shared/services/mcp-client.js.map +0 -1
  439. package/dist/agents/shared/services/message-classifier.d.ts +0 -37
  440. package/dist/agents/shared/services/message-classifier.d.ts.map +0 -1
  441. package/dist/agents/shared/services/message-classifier.js +0 -203
  442. package/dist/agents/shared/services/message-classifier.js.map +0 -1
  443. package/dist/agents/shared/services/message-formatter.d.ts +0 -89
  444. package/dist/agents/shared/services/message-formatter.d.ts.map +0 -1
  445. package/dist/agents/shared/services/message-formatter.js +0 -390
  446. package/dist/agents/shared/services/message-formatter.js.map +0 -1
  447. package/dist/agents/shared/services/session-logger.d.ts +0 -162
  448. package/dist/agents/shared/services/session-logger.d.ts.map +0 -1
  449. package/dist/agents/shared/services/session-logger.js +0 -724
  450. package/dist/agents/shared/services/session-logger.js.map +0 -1
  451. package/dist/agents/shared/services/structured-output-executor.d.ts +0 -88
  452. package/dist/agents/shared/services/structured-output-executor.d.ts.map +0 -1
  453. package/dist/agents/shared/services/structured-output-executor.js +0 -296
  454. package/dist/agents/shared/services/structured-output-executor.js.map +0 -1
  455. package/dist/agents/shared/services/token-billing.d.ts +0 -72
  456. package/dist/agents/shared/services/token-billing.d.ts.map +0 -1
  457. package/dist/agents/shared/services/token-billing.js +0 -198
  458. package/dist/agents/shared/services/token-billing.js.map +0 -1
  459. package/dist/agents/shared/services/tool-executor.d.ts +0 -43
  460. package/dist/agents/shared/services/tool-executor.d.ts.map +0 -1
  461. package/dist/agents/shared/services/tool-executor.js +0 -175
  462. package/dist/agents/shared/services/tool-executor.js.map +0 -1
  463. package/dist/agents/shared/services/typing-indicator.d.ts +0 -24
  464. package/dist/agents/shared/services/typing-indicator.d.ts.map +0 -1
  465. package/dist/agents/shared/services/typing-indicator.js +0 -54
  466. package/dist/agents/shared/services/typing-indicator.js.map +0 -1
  467. package/dist/agents/shared/services/workspace-schema-cache.d.ts +0 -122
  468. package/dist/agents/shared/services/workspace-schema-cache.d.ts.map +0 -1
  469. package/dist/agents/shared/services/workspace-schema-cache.js +0 -507
  470. package/dist/agents/shared/services/workspace-schema-cache.js.map +0 -1
  471. package/dist/agents/shared/specialist.d.ts +0 -91
  472. package/dist/agents/shared/specialist.d.ts.map +0 -1
  473. package/dist/agents/shared/specialist.js +0 -399
  474. package/dist/agents/shared/specialist.js.map +0 -1
  475. package/dist/agents/shared/tool-schema-loader.d.ts +0 -65
  476. package/dist/agents/shared/tool-schema-loader.d.ts.map +0 -1
  477. package/dist/agents/shared/tool-schema-loader.js +0 -238
  478. package/dist/agents/shared/tool-schema-loader.js.map +0 -1
  479. package/dist/agents/shared/types.d.ts +0 -190
  480. package/dist/agents/shared/types.d.ts.map +0 -1
  481. package/dist/agents/shared/types.js +0 -13
  482. package/dist/agents/shared/types.js.map +0 -1
  483. package/dist/bot/bot-config.d.ts +0 -37
  484. package/dist/bot/bot-config.d.ts.map +0 -1
  485. package/dist/bot/bot-config.js +0 -219
  486. package/dist/bot/bot-config.js.map +0 -1
  487. package/dist/bot/services/__tests__/permission-guard.test.d.ts +0 -2
  488. package/dist/bot/services/__tests__/permission-guard.test.d.ts.map +0 -1
  489. package/dist/bot/services/__tests__/permission-guard.test.js +0 -357
  490. package/dist/bot/services/__tests__/permission-guard.test.js.map +0 -1
  491. package/dist/bot/services/session-logger.d.ts +0 -162
  492. package/dist/bot/services/session-logger.d.ts.map +0 -1
  493. package/dist/bot/services/session-logger.js +0 -724
  494. package/dist/bot/services/session-logger.js.map +0 -1
  495. package/dist/bot/services/workspace-schema-cache.d.ts +0 -122
  496. package/dist/bot/services/workspace-schema-cache.d.ts.map +0 -1
  497. package/dist/bot/services/workspace-schema-cache.js +0 -506
  498. package/dist/bot/services/workspace-schema-cache.js.map +0 -1
  499. package/dist/bot-config/tools.d.ts +0 -28
  500. package/dist/bot-config/tools.d.ts.map +0 -1
  501. package/dist/bot-config/tools.js +0 -279
  502. package/dist/bot-config/tools.js.map +0 -1
  503. package/dist/client/agents/base.d.ts +0 -207
  504. package/dist/client/agents/base.d.ts.map +0 -1
  505. package/dist/client/agents/base.js +0 -744
  506. package/dist/client/agents/base.js.map +0 -1
  507. package/dist/client/agents/definitions.d.ts +0 -53
  508. package/dist/client/agents/definitions.d.ts.map +0 -1
  509. package/dist/client/agents/definitions.js +0 -263
  510. package/dist/client/agents/definitions.js.map +0 -1
  511. package/dist/client/agents/orchestrator.d.ts +0 -141
  512. package/dist/client/agents/orchestrator.d.ts.map +0 -1
  513. package/dist/client/agents/orchestrator.js +0 -1062
  514. package/dist/client/agents/orchestrator.js.map +0 -1
  515. package/dist/client/agents/specialist.d.ts +0 -86
  516. package/dist/client/agents/specialist.d.ts.map +0 -1
  517. package/dist/client/agents/specialist.js +0 -340
  518. package/dist/client/agents/specialist.js.map +0 -1
  519. package/dist/client/bot-entrypoint.d.ts +0 -7
  520. package/dist/client/bot-entrypoint.d.ts.map +0 -1
  521. package/dist/client/bot-entrypoint.js +0 -103
  522. package/dist/client/bot-entrypoint.js.map +0 -1
  523. package/dist/client/bot-manager.d.ts +0 -44
  524. package/dist/client/bot-manager.d.ts.map +0 -1
  525. package/dist/client/bot-manager.js +0 -173
  526. package/dist/client/bot-manager.js.map +0 -1
  527. package/dist/client/bot-runner.d.ts +0 -35
  528. package/dist/client/bot-runner.d.ts.map +0 -1
  529. package/dist/client/bot-runner.js +0 -188
  530. package/dist/client/bot-runner.js.map +0 -1
  531. package/dist/client/chat-agent-daemon.d.ts +0 -464
  532. package/dist/client/chat-agent-daemon.d.ts.map +0 -1
  533. package/dist/client/chat-agent-daemon.js +0 -1774
  534. package/dist/client/chat-agent-daemon.js.map +0 -1
  535. package/dist/client/daemon-factory.d.ts +0 -106
  536. package/dist/client/daemon-factory.d.ts.map +0 -1
  537. package/dist/client/daemon-factory.js +0 -301
  538. package/dist/client/daemon-factory.js.map +0 -1
  539. package/dist/client/factory.d.ts +0 -111
  540. package/dist/client/factory.d.ts.map +0 -1
  541. package/dist/client/factory.js +0 -314
  542. package/dist/client/factory.js.map +0 -1
  543. package/dist/client/index.d.ts +0 -17
  544. package/dist/client/index.d.ts.map +0 -1
  545. package/dist/client/index.js +0 -38
  546. package/dist/client/index.js.map +0 -1
  547. package/dist/client/multi-bot-manager.d.ts +0 -42
  548. package/dist/client/multi-bot-manager.d.ts.map +0 -1
  549. package/dist/client/multi-bot-manager.js +0 -161
  550. package/dist/client/multi-bot-manager.js.map +0 -1
  551. package/dist/client/orchestrator-daemon.d.ts +0 -87
  552. package/dist/client/orchestrator-daemon.d.ts.map +0 -1
  553. package/dist/client/orchestrator-daemon.js +0 -444
  554. package/dist/client/orchestrator-daemon.js.map +0 -1
  555. package/dist/client/server.d.ts +0 -8
  556. package/dist/client/server.d.ts.map +0 -1
  557. package/dist/client/server.js +0 -251
  558. package/dist/client/server.js.map +0 -1
  559. package/dist/client/services/agent-registry.d.ts +0 -108
  560. package/dist/client/services/agent-registry.d.ts.map +0 -1
  561. package/dist/client/services/agent-registry.js +0 -630
  562. package/dist/client/services/agent-registry.js.map +0 -1
  563. package/dist/client/services/conversation-manager.d.ts +0 -50
  564. package/dist/client/services/conversation-manager.d.ts.map +0 -1
  565. package/dist/client/services/conversation-manager.js +0 -136
  566. package/dist/client/services/conversation-manager.js.map +0 -1
  567. package/dist/client/services/mcp-client.d.ts +0 -48
  568. package/dist/client/services/mcp-client.d.ts.map +0 -1
  569. package/dist/client/services/mcp-client.js +0 -105
  570. package/dist/client/services/mcp-client.js.map +0 -1
  571. package/dist/client/services/message-classifier.d.ts +0 -37
  572. package/dist/client/services/message-classifier.d.ts.map +0 -1
  573. package/dist/client/services/message-classifier.js +0 -187
  574. package/dist/client/services/message-classifier.js.map +0 -1
  575. package/dist/client/services/message-formatter.d.ts +0 -84
  576. package/dist/client/services/message-formatter.d.ts.map +0 -1
  577. package/dist/client/services/message-formatter.js +0 -353
  578. package/dist/client/services/message-formatter.js.map +0 -1
  579. package/dist/client/services/session-logger.d.ts +0 -106
  580. package/dist/client/services/session-logger.d.ts.map +0 -1
  581. package/dist/client/services/session-logger.js +0 -446
  582. package/dist/client/services/session-logger.js.map +0 -1
  583. package/dist/client/services/tool-executor.d.ts +0 -41
  584. package/dist/client/services/tool-executor.d.ts.map +0 -1
  585. package/dist/client/services/tool-executor.js +0 -169
  586. package/dist/client/services/tool-executor.js.map +0 -1
  587. package/dist/client/services/workspace-schema-cache.d.ts +0 -149
  588. package/dist/client/services/workspace-schema-cache.d.ts.map +0 -1
  589. package/dist/client/services/workspace-schema-cache.js +0 -732
  590. package/dist/client/services/workspace-schema-cache.js.map +0 -1
  591. package/dist/client/specialist-daemon.d.ts +0 -77
  592. package/dist/client/specialist-daemon.d.ts.map +0 -1
  593. package/dist/client/specialist-daemon.js +0 -197
  594. package/dist/client/specialist-daemon.js.map +0 -1
  595. package/dist/client/specialists.d.ts +0 -53
  596. package/dist/client/specialists.d.ts.map +0 -1
  597. package/dist/client/specialists.js +0 -178
  598. package/dist/client/specialists.js.map +0 -1
  599. package/dist/client/tool-schema-loader.d.ts +0 -62
  600. package/dist/client/tool-schema-loader.d.ts.map +0 -1
  601. package/dist/client/tool-schema-loader.js +0 -232
  602. package/dist/client/tool-schema-loader.js.map +0 -1
  603. package/dist/client/types.d.ts +0 -327
  604. package/dist/client/types.d.ts.map +0 -1
  605. package/dist/client/types.js +0 -121
  606. package/dist/client/types.js.map +0 -1
  607. package/dist/commands/seed-config.d.ts +0 -9
  608. package/dist/commands/seed-config.d.ts.map +0 -1
  609. package/dist/commands/seed-config.js +0 -377
  610. package/dist/commands/seed-config.js.map +0 -1
  611. package/dist/commands/setup.d.ts +0 -11
  612. package/dist/commands/setup.d.ts.map +0 -1
  613. package/dist/commands/setup.js +0 -320
  614. package/dist/commands/setup.js.map +0 -1
  615. package/dist/lib/discussion-lock.d.ts +0 -42
  616. package/dist/lib/discussion-lock.d.ts.map +0 -1
  617. package/dist/lib/discussion-lock.js +0 -110
  618. package/dist/lib/discussion-lock.js.map +0 -1
  619. package/dist/mcp/signal-handler.d.ts +0 -82
  620. package/dist/mcp/signal-handler.d.ts.map +0 -1
  621. package/dist/mcp/signal-handler.js +0 -406
  622. package/dist/mcp/signal-handler.js.map +0 -1
  623. package/dist/mcp/tools/__tests__/discussion-forward.test.d.ts +0 -2
  624. package/dist/mcp/tools/__tests__/discussion-forward.test.d.ts.map +0 -1
  625. package/dist/mcp/tools/__tests__/discussion-forward.test.js +0 -218
  626. package/dist/mcp/tools/__tests__/discussion-forward.test.js.map +0 -1
  627. package/dist/mcp/tools/app-member.d.ts +0 -14
  628. package/dist/mcp/tools/app-member.d.ts.map +0 -1
  629. package/dist/mcp/tools/app-member.js +0 -195
  630. package/dist/mcp/tools/app-member.js.map +0 -1
  631. package/dist/mcp/tools/app-scaffold.d.ts +0 -14
  632. package/dist/mcp/tools/app-scaffold.d.ts.map +0 -1
  633. package/dist/mcp/tools/app-scaffold.js +0 -581
  634. package/dist/mcp/tools/app-scaffold.js.map +0 -1
  635. package/dist/mcp/tools/bot-config/constants.d.ts +0 -23
  636. package/dist/mcp/tools/bot-config/constants.d.ts.map +0 -1
  637. package/dist/mcp/tools/bot-config/constants.js +0 -94
  638. package/dist/mcp/tools/bot-config/constants.js.map +0 -1
  639. package/dist/mcp/tools/bot-config/core.d.ts +0 -253
  640. package/dist/mcp/tools/bot-config/core.d.ts.map +0 -1
  641. package/dist/mcp/tools/bot-config/core.js +0 -2456
  642. package/dist/mcp/tools/bot-config/core.js.map +0 -1
  643. package/dist/mcp/tools/bot-config/index.d.ts +0 -10
  644. package/dist/mcp/tools/bot-config/index.d.ts.map +0 -1
  645. package/dist/mcp/tools/bot-config/index.js +0 -59
  646. package/dist/mcp/tools/bot-config/index.js.map +0 -1
  647. package/dist/mcp/tools/bot-config/tools.d.ts +0 -7
  648. package/dist/mcp/tools/bot-config/tools.d.ts.map +0 -1
  649. package/dist/mcp/tools/bot-config/tools.js +0 -15
  650. package/dist/mcp/tools/bot-config/tools.js.map +0 -1
  651. package/dist/mcp/tools/bot-config/types.d.ts +0 -50
  652. package/dist/mcp/tools/bot-config/types.d.ts.map +0 -1
  653. package/dist/mcp/tools/bot-config/types.js +0 -6
  654. package/dist/mcp/tools/bot-config/types.js.map +0 -1
  655. package/dist/mcp/tools/bug-fixer-tools.d.ts +0 -45
  656. package/dist/mcp/tools/bug-fixer-tools.d.ts.map +0 -1
  657. package/dist/mcp/tools/bug-fixer-tools.js +0 -1096
  658. package/dist/mcp/tools/bug-fixer-tools.js.map +0 -1
  659. package/dist/mcp/tools/document.d.ts +0 -11
  660. package/dist/mcp/tools/document.d.ts.map +0 -1
  661. package/dist/mcp/tools/document.js +0 -741
  662. package/dist/mcp/tools/document.js.map +0 -1
  663. package/dist/mcp/tools/investigate.d.ts +0 -9
  664. package/dist/mcp/tools/investigate.d.ts.map +0 -1
  665. package/dist/mcp/tools/investigate.js +0 -254
  666. package/dist/mcp/tools/investigate.js.map +0 -1
  667. package/dist/mcp/utils/pagination.d.ts +0 -40
  668. package/dist/mcp/utils/pagination.d.ts.map +0 -1
  669. package/dist/mcp/utils/pagination.js +0 -55
  670. package/dist/mcp/utils/pagination.js.map +0 -1
  671. package/dist/modules/bug-reports/bug-config.d.ts +0 -25
  672. package/dist/modules/bug-reports/bug-config.d.ts.map +0 -1
  673. package/dist/modules/bug-reports/bug-config.js +0 -187
  674. package/dist/modules/bug-reports/bug-config.js.map +0 -1
  675. package/dist/modules/bug-reports/bug-monitor.d.ts +0 -108
  676. package/dist/modules/bug-reports/bug-monitor.d.ts.map +0 -1
  677. package/dist/modules/bug-reports/bug-monitor.js +0 -510
  678. package/dist/modules/bug-reports/bug-monitor.js.map +0 -1
  679. package/dist/modules/bug-reports/giuseppe-agent.d.ts +0 -58
  680. package/dist/modules/bug-reports/giuseppe-agent.d.ts.map +0 -1
  681. package/dist/modules/bug-reports/giuseppe-agent.js +0 -467
  682. package/dist/modules/bug-reports/giuseppe-agent.js.map +0 -1
  683. package/dist/modules/bug-reports/giuseppe-ai.d.ts +0 -83
  684. package/dist/modules/bug-reports/giuseppe-ai.d.ts.map +0 -1
  685. package/dist/modules/bug-reports/giuseppe-ai.js +0 -466
  686. package/dist/modules/bug-reports/giuseppe-ai.js.map +0 -1
  687. package/dist/modules/bug-reports/giuseppe-bot.d.ts +0 -110
  688. package/dist/modules/bug-reports/giuseppe-bot.d.ts.map +0 -1
  689. package/dist/modules/bug-reports/giuseppe-bot.js +0 -804
  690. package/dist/modules/bug-reports/giuseppe-bot.js.map +0 -1
  691. package/dist/modules/bug-reports/giuseppe-daemon.d.ts +0 -80
  692. package/dist/modules/bug-reports/giuseppe-daemon.d.ts.map +0 -1
  693. package/dist/modules/bug-reports/giuseppe-daemon.js +0 -617
  694. package/dist/modules/bug-reports/giuseppe-daemon.js.map +0 -1
  695. package/dist/modules/bug-reports/giuseppe-files.d.ts +0 -64
  696. package/dist/modules/bug-reports/giuseppe-files.d.ts.map +0 -1
  697. package/dist/modules/bug-reports/giuseppe-files.js +0 -375
  698. package/dist/modules/bug-reports/giuseppe-files.js.map +0 -1
  699. package/dist/modules/bug-reports/giuseppe-git.d.ts +0 -48
  700. package/dist/modules/bug-reports/giuseppe-git.d.ts.map +0 -1
  701. package/dist/modules/bug-reports/giuseppe-git.js +0 -298
  702. package/dist/modules/bug-reports/giuseppe-git.js.map +0 -1
  703. package/dist/modules/bug-reports/giuseppe-lsp.d.ts +0 -113
  704. package/dist/modules/bug-reports/giuseppe-lsp.d.ts.map +0 -1
  705. package/dist/modules/bug-reports/giuseppe-lsp.js +0 -485
  706. package/dist/modules/bug-reports/giuseppe-lsp.js.map +0 -1
  707. package/dist/modules/bug-reports/giuseppe-prompt.d.ts +0 -5
  708. package/dist/modules/bug-reports/giuseppe-prompt.d.ts.map +0 -1
  709. package/dist/modules/bug-reports/giuseppe-prompt.js +0 -94
  710. package/dist/modules/bug-reports/giuseppe-prompt.js.map +0 -1
  711. package/dist/modules/bug-reports/index.d.ts +0 -77
  712. package/dist/modules/bug-reports/index.d.ts.map +0 -1
  713. package/dist/modules/bug-reports/index.js +0 -215
  714. package/dist/modules/bug-reports/index.js.map +0 -1
  715. package/dist/modules/bug-reports/pending-classification-registry.d.ts +0 -28
  716. package/dist/modules/bug-reports/pending-classification-registry.d.ts.map +0 -1
  717. package/dist/modules/bug-reports/pending-classification-registry.js +0 -50
  718. package/dist/modules/bug-reports/pending-classification-registry.js.map +0 -1
  719. package/dist/modules/bug-reports/pending-fix-registry.d.ts +0 -30
  720. package/dist/modules/bug-reports/pending-fix-registry.d.ts.map +0 -1
  721. package/dist/modules/bug-reports/pending-fix-registry.js +0 -42
  722. package/dist/modules/bug-reports/pending-fix-registry.js.map +0 -1
  723. package/dist/modules/bug-reports/pending-registry.d.ts +0 -27
  724. package/dist/modules/bug-reports/pending-registry.d.ts.map +0 -1
  725. package/dist/modules/bug-reports/pending-registry.js +0 -49
  726. package/dist/modules/bug-reports/pending-registry.js.map +0 -1
  727. package/dist/modules/bug-reports/types.d.ts +0 -123
  728. package/dist/modules/bug-reports/types.d.ts.map +0 -1
  729. package/dist/modules/bug-reports/types.js +0 -9
  730. package/dist/modules/bug-reports/types.js.map +0 -1
  731. package/dist/plugins/bug-fixer/index.d.ts +0 -2
  732. package/dist/plugins/bug-fixer/index.d.ts.map +0 -1
  733. package/dist/plugins/bug-fixer/index.js +0 -18
  734. package/dist/plugins/bug-fixer/index.js.map +0 -1
  735. package/dist/plugins/bug-fixer/tools.d.ts +0 -45
  736. package/dist/plugins/bug-fixer/tools.d.ts.map +0 -1
  737. package/dist/plugins/bug-fixer/tools.js +0 -1096
  738. package/dist/plugins/bug-fixer/tools.js.map +0 -1
  739. package/dist/plugins/vipunen/__tests__/tools.test.d.ts +0 -10
  740. package/dist/plugins/vipunen/__tests__/tools.test.d.ts.map +0 -1
  741. package/dist/plugins/vipunen/__tests__/tools.test.js +0 -646
  742. package/dist/plugins/vipunen/__tests__/tools.test.js.map +0 -1
  743. package/dist/routes/agents.d.ts +0 -44
  744. package/dist/routes/agents.d.ts.map +0 -1
  745. package/dist/routes/agents.js +0 -311
  746. package/dist/routes/agents.js.map +0 -1
  747. package/dist/services/agent-credential-store.d.ts +0 -73
  748. package/dist/services/agent-credential-store.d.ts.map +0 -1
  749. package/dist/services/agent-credential-store.js +0 -212
  750. package/dist/services/agent-credential-store.js.map +0 -1
  751. package/dist/stdio-server.d.ts +0 -14
  752. package/dist/stdio-server.d.ts.map +0 -1
  753. package/dist/stdio-server.js +0 -101
  754. package/dist/stdio-server.js.map +0 -1
  755. package/dist/workspace/context.d.ts +0 -148
  756. package/dist/workspace/context.d.ts.map +0 -1
  757. package/dist/workspace/context.js +0 -339
  758. package/dist/workspace/context.js.map +0 -1
  759. package/dist/workspace/credentials.d.ts +0 -55
  760. package/dist/workspace/credentials.d.ts.map +0 -1
  761. package/dist/workspace/credentials.js +0 -239
  762. package/dist/workspace/credentials.js.map +0 -1
  763. package/dist/workspace/index.d.ts +0 -21
  764. package/dist/workspace/index.d.ts.map +0 -1
  765. package/dist/workspace/index.js +0 -45
  766. package/dist/workspace/index.js.map +0 -1
  767. package/dist/workspace/loader.d.ts +0 -27
  768. package/dist/workspace/loader.d.ts.map +0 -1
  769. package/dist/workspace/loader.js +0 -222
  770. package/dist/workspace/loader.js.map +0 -1
  771. package/dist/workspace/schema.d.ts +0 -37
  772. package/dist/workspace/schema.d.ts.map +0 -1
  773. package/dist/workspace/schema.js +0 -192
  774. package/dist/workspace/schema.js.map +0 -1
@@ -7,10 +7,16 @@
7
7
  * - Activities = Rows
8
8
  * - Fields = Columns
9
9
  *
10
- * All 4 insight management tools in one file for cohesion.
10
+ * All 4 insight tools in one file for cohesion (v2 surface):
11
+ * - run_insight (saved execution + ad-hoc preview)
12
+ * - save_insight (create + update upsert)
13
+ * - list_insights
14
+ * - remove_insight
11
15
  */
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.insightTools = exports.listInsightsTool = exports.removeInsightTool = exports.updateInsightTool = exports.getInsightDataTool = exports.previewInsightTool = exports.createInsightTool = void 0;
17
+ exports.insightTools = exports.listInsightsTool = exports.removeInsightTool = exports.saveInsightTool = exports.runInsightTool = void 0;
18
+ exports.formatResultData = formatResultData;
19
+ exports.findExistingInsight = findExistingInsight;
14
20
  const zod_1 = require("zod");
15
21
  const tool_registry_1 = require("../tool-registry");
16
22
  const logger_1 = require("../../lib/logger");
@@ -25,10 +31,10 @@ const logger = (0, logger_1.createLogger)({ component: 'insight-tools' });
25
31
  * Accepts both 'id' and 'fieldId' for flexibility (LLMs often use 'id')
26
32
  */
27
33
  const fieldSchema = zod_1.z.object({
28
- name: zod_1.z.string().describe("Column name in SQL query"),
34
+ name: zod_1.z.string().describe('Column name in SQL query'),
29
35
  // Accept both 'id' and 'fieldId' - will be normalized to 'fieldId'
30
- id: zod_1.z.string().optional().describe("Field ID (alias for fieldId)"),
31
- fieldId: zod_1.z.string().optional().describe("Custom field ID from workflow"),
36
+ id: zod_1.z.string().optional().describe('Field ID (alias for fieldId)'),
37
+ fieldId: zod_1.z.string().optional().describe('Custom field ID from workflow'),
32
38
  meta: zod_1.z.enum([
33
39
  '_id',
34
40
  'uid',
@@ -43,7 +49,7 @@ const fieldSchema = zod_1.z.object({
43
49
  'workflowId',
44
50
  'workflowName',
45
51
  'priority'
46
- ]).optional().describe("Built-in activity property (alternative to fieldId)"),
52
+ ]).optional().describe('Built-in activity property (alternative to fieldId)'),
47
53
  }).refine((data) => data.meta || data.fieldId || data.id, { message: "Field must have either 'meta', 'fieldId', or 'id'" });
48
54
  /**
49
55
  * Sanitize field name to be SQL-identifier safe (no spaces, special chars)
@@ -53,8 +59,9 @@ function sanitizeFieldName(name) {
53
59
  return name
54
60
  .split(/\s+/)
55
61
  .map((word, index) => {
56
- if (index === 0)
62
+ if (index === 0) {
57
63
  return word.charAt(0).toLowerCase() + word.slice(1);
64
+ }
58
65
  return word.charAt(0).toUpperCase() + word.slice(1);
59
66
  })
60
67
  .join('')
@@ -67,7 +74,7 @@ function normalizeFields(sources) {
67
74
  return sources.map(source => ({
68
75
  ...source,
69
76
  fields: source.fields.map(field => {
70
- let normalized = { ...field };
77
+ const normalized = { ...field };
71
78
  // Sanitize field name (remove spaces, make SQL-safe)
72
79
  if (normalized.name) {
73
80
  normalized.name = sanitizeFieldName(normalized.name);
@@ -85,546 +92,572 @@ function normalizeFields(sources) {
85
92
  * Source definition schema - workflow as SQL table
86
93
  */
87
94
  const sourceSchema = zod_1.z.object({
88
- name: zod_1.z.string().describe("Table alias for SQL query"),
89
- workflowId: zod_1.z.string().describe("Workflow ID to query"),
90
- fields: zod_1.z.array(fieldSchema).min(1).describe("Field mappings for SQL columns"),
95
+ name: zod_1.z.string().describe('Table alias for SQL query'),
96
+ workflowId: zod_1.z.string().describe('Workflow ID to query'),
97
+ fields: zod_1.z.array(fieldSchema).min(1).describe('Field mappings for SQL columns'),
91
98
  });
92
- // ============================================================================
93
- // CREATE INSIGHT TOOL
94
- // ============================================================================
95
99
  const INSIGHT_SQL_GUIDE = `**How sources map to SQL:**
96
100
  - sources[].name → TABLE NAME in SQL
97
101
  - sources[].fields[].name → COLUMN NAME in SQL
98
- - sources[].fields[].fieldId → custom field ID (hex string from get_workflow_schema)
99
- - sources[].fields[].meta → built-in property (use INSTEAD of fieldId): phaseName, name, created, updated, uid, team, priority
102
+ - sources[].fields[].fieldId → custom field ID (hex string from describe_workflows include:["schema"])
103
+ - sources[].fields[].meta → built-in property (use INSTEAD of fieldId): _id, phaseName, name, created, updated, uid, team, priority (use meta: "_id" to get activity IDs for update_activity bulk calls)
100
104
 
101
105
  **Example — count by phase:**
102
106
  sources: [{ name: "T", workflowId: "...", fields: [{ name: "phase", meta: "phaseName" }] }]
103
107
  query: "SELECT phase, COUNT(*) as count FROM T GROUP BY phase"
104
108
 
105
109
  **NEVER use fieldId or workflowId in the SQL — only field name values.**`;
106
- const createInsightDescription = `Create SQL insight over workflow data.
110
+ /**
111
+ * Result byte budget — keeps insight responses under MCP client caps while
112
+ * returning the actual data. (The old formatter showed a 10-row sample and
113
+ * discarded the rest, which made run_insight useless for data retrieval.)
114
+ */
115
+ const MAX_INSIGHT_RESPONSE_CHARS = 200000;
116
+ /**
117
+ * Format a headers/rows result set as compact JSON, windowed by offset/maxRows
118
+ * and trimmed to the byte budget on whole-row boundaries. The full result set
119
+ * is already in memory here — slicing costs nothing and lets the model page.
120
+ */
121
+ function formatResultData(headers, rows, offset, maxRows) {
122
+ if (!headers || !rows) {
123
+ return '⚠️ No data returned\n';
124
+ }
125
+ if (rows.length === 0) {
126
+ return `**Columns:** ${headers.join(', ')}\n\n⚠️ **No rows matched** - Check your query filters\n`;
127
+ }
128
+ const totalRows = rows.length;
129
+ const windowed = rows.slice(offset, offset + maxRows);
130
+ const included = [];
131
+ let used = JSON.stringify(headers).length + 32;
132
+ for (const row of windowed) {
133
+ const rowLength = JSON.stringify(row).length + 1;
134
+ if (used + rowLength > MAX_INSIGHT_RESPONSE_CHARS) {
135
+ break;
136
+ }
137
+ included.push(row);
138
+ used += rowLength;
139
+ }
140
+ if (included.length === 0 && windowed.length > 0) {
141
+ // A pagination hint here would point at the SAME offset forever.
142
+ return `⚠️ **Row too large**: the single row at offset ${offset} exceeds the response size cap. ` +
143
+ `Select fewer or shorter columns in the SQL, or skip it with offset=${offset + 1}.\n`;
144
+ }
145
+ let text = `**Rows ${Math.min(offset + 1, totalRows)}-${offset + included.length} of ${totalRows}**\n`;
146
+ text += '```json\n';
147
+ text += JSON.stringify({ headers, rows: included });
148
+ text += '\n```\n';
149
+ const nextOffset = offset + included.length;
150
+ if (nextOffset < totalRows) {
151
+ text += `\n➡️ **More rows available**: call run_insight again with the same query/insightId and offset=${nextOffset}\n`;
152
+ }
153
+ return text;
154
+ }
155
+ // ============================================================================
156
+ // RUN INSIGHT TOOL (saved execution + ad-hoc preview)
157
+ // ============================================================================
158
+ const runInsightDescription = `Execute an insight query and return rows. PREFER THIS over paginating list_activities for: aggregations (COUNT/SUM/GROUP BY), selecting a few columns across many activities, cross-workflow JOINs, and collecting activity _ids for bulk updates (\`SELECT _id ...\` with meta: "_id").
159
+
160
+ Two modes (mutually exclusive):
161
+ - Saved: pass insightId to run a stored insight over the FULL dataset (no sampling). Results may be served from a server cache up to ~15 min old; a newly saved insight computes fresh on first run. Check list_insights first — an existing insight may already answer the question; reuse before creating new ones.
162
+ - Ad-hoc: pass sources + query to test SQL without saving. ⚠️ Ad-hoc runs on a SAMPLE (the newest ~200 activities per source) — good for validating SQL and small workflows, NOT for full-dataset counts/sums. Save the insight and run it by insightId for exact numbers.
163
+
164
+ Results return as compact JSON (headers + rows) up to a size cap — page with offset/maxRows.
107
165
 
108
166
  ${INSIGHT_SQL_GUIDE}`;
109
- exports.createInsightTool = {
110
- name: 'create_insight',
167
+ /** Saved-insight path: v3.insight.data */
168
+ async function runSavedInsight(insightId, context, offset, maxRows) {
169
+ try {
170
+ logger.debug('Calling v3.insight.data', { insightId });
171
+ // Always update: false — forcing recalculation rebuilds the whole
172
+ // in-memory SQLite dataset server-side (queued, max 2 concurrent) and
173
+ // is never needed: an uncached insight computes on first run anyway.
174
+ const result = await context.hailer.request('v3.insight.data', [insightId, { update: false }]);
175
+ logger.debug('Insight data retrieved', {
176
+ headers: result.headers?.length,
177
+ rows: result.rows?.length,
178
+ fullResult: JSON.stringify(result).substring(0, 500)
179
+ });
180
+ let responseText = `✅ **Insight Data Retrieved** (${result.rows?.length || 0} rows)\n\n`;
181
+ responseText += formatResultData(result.headers, result.rows, offset, maxRows);
182
+ if (!result.headers || !result.rows) {
183
+ responseText += `**Debug:** Response keys: ${Object.keys(result).join(', ')}\n`;
184
+ responseText += `**Full response (truncated):** \`${JSON.stringify(result).substring(0, 300)}\`\n`;
185
+ }
186
+ return {
187
+ content: [{
188
+ type: 'text',
189
+ text: responseText,
190
+ }],
191
+ };
192
+ }
193
+ catch (error) {
194
+ if (!request_logger_1.RequestLogger.getCurrent()) {
195
+ logger.error('Error getting insight data', error);
196
+ }
197
+ const errorMessage = (0, tool_helpers_1.extractErrorMessage)(error);
198
+ return {
199
+ content: [{
200
+ type: 'text',
201
+ text: `❌ **Error getting insight data**\n\n**Error:** ${errorMessage}\n\n**Common Issues:**\n- Insight ID not found\n- Permission denied\n- Insight query has errors\n- Use \`list_insights\` to verify insight ID`,
202
+ }],
203
+ };
204
+ }
205
+ }
206
+ /** Ad-hoc path: v3.insight.preview */
207
+ async function runAdHocInsight(sources, query, context, offset, maxRows) {
208
+ try {
209
+ // Resolve workspace ID (returns undefined if cache unavailable)
210
+ const workspaceId = (0, tool_helpers_1.getResolvedWorkspaceId)({}, context);
211
+ if (!workspaceId) {
212
+ return (0, tool_helpers_1.missingWorkspaceCacheResponse)();
213
+ }
214
+ logger.debug('Calling v3.insight.preview', {
215
+ workspaceId,
216
+ sourcesCount: sources.length,
217
+ });
218
+ // Normalize sources (convert 'id' to 'fieldId' if needed)
219
+ const normalizedSources = normalizeFields(sources);
220
+ const previewData = {
221
+ sources: normalizedSources,
222
+ query,
223
+ };
224
+ // Call v3.insight.preview endpoint
225
+ const result = await context.hailer.request('v3.insight.preview', [workspaceId, previewData]);
226
+ logger.debug('Preview successful', {
227
+ headers: result.headers?.length,
228
+ rows: result.rows?.length
229
+ });
230
+ let responseText = `✅ **Preview Results** (~${result.rows?.length || 0} rows)\n\n`;
231
+ responseText += `⚠️ Ad-hoc preview computes over a SAMPLE (newest ~200 activities per source). For full-dataset numbers, save with \`save_insight\` and run by insightId.\n\n`;
232
+ responseText += formatResultData(result.headers, result.rows, offset, maxRows);
233
+ responseText += '\n✅ **Query is valid!** Ready to save with `save_insight`.';
234
+ return {
235
+ content: [{
236
+ type: 'text',
237
+ text: responseText,
238
+ }],
239
+ };
240
+ }
241
+ catch (error) {
242
+ if (!request_logger_1.RequestLogger.getCurrent()) {
243
+ logger.error('Error previewing insight', error);
244
+ }
245
+ const errorMessage = (0, tool_helpers_1.extractErrorMessage)(error);
246
+ return {
247
+ content: [{
248
+ type: 'text',
249
+ text: `❌ **Preview Failed**\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Check SQL syntax\n- Verify field names match source definitions\n- Ensure workflow IDs are correct\n- Check table aliases match source names`,
250
+ }],
251
+ };
252
+ }
253
+ }
254
+ exports.runInsightTool = {
255
+ name: 'run_insight',
111
256
  group: tool_registry_1.ToolGroup.PLAYGROUND,
112
- description: createInsightDescription,
257
+ description: runInsightDescription,
113
258
  schema: zod_1.z.object({
114
- workspaceId: zod_1.z
115
- .string()
116
- .optional()
117
- .describe("Optional workspace ID or name - defaults to current workspace"),
118
- name: zod_1.z
259
+ insightId: zod_1.z
119
260
  .string()
120
- .min(1)
121
- .describe("Insight name"),
122
- public: zod_1.z
123
- .boolean()
124
261
  .optional()
125
- .default(false)
126
- .describe("Whether insight is publicly accessible (default: false)"),
262
+ .describe('Saved insight ID to execute. Mutually exclusive with sources/query.'),
127
263
  sources: zod_1.z
128
264
  .array(sourceSchema)
129
265
  .min(1)
130
- .describe("Workflow sources. source.name = SQL table name, field.name = SQL column name. Never use IDs in the query."),
266
+ .optional()
267
+ .describe('Ad-hoc mode: workflow sources. source.name = SQL table name, field.name = SQL column name.'),
131
268
  query: zod_1.z
132
269
  .string()
133
270
  .min(1)
134
- .describe("SQL query (SELECT, JOIN, WHERE, GROUP BY, ORDER BY, etc.)"),
271
+ .optional()
272
+ .describe('Ad-hoc mode: SQL query to test'),
273
+ offset: zod_1.z.coerce
274
+ .number()
275
+ .int()
276
+ .min(0)
277
+ .optional()
278
+ .default(0)
279
+ .describe('Skip this many result rows (0-based) — for paging through large results'),
280
+ maxRows: zod_1.z.coerce
281
+ .number()
282
+ .int()
283
+ .min(1)
284
+ .max(2000)
285
+ .optional()
286
+ .default(500)
287
+ .describe('Maximum rows to return (default 500). A response size cap may return fewer; the response says how to continue'),
135
288
  }),
136
289
  async execute(args, context) {
137
- logger.debug('Creating insight', {
138
- name: args.name,
139
- workspaceId: args.workspaceId,
140
- sourcesCount: args.sources.length,
290
+ logger.debug('Running insight', {
291
+ insightId: args.insightId,
292
+ sourcesCount: args.sources?.length,
293
+ hasQuery: !!args.query,
141
294
  apiKey: context.apiKey.substring(0, 8) + '...'
142
295
  });
143
- try {
144
- // Resolve workspace ID (returns undefined if cache unavailable)
145
- const workspaceId = (0, tool_helpers_1.getResolvedWorkspaceId)(args, context);
146
- if (!workspaceId) {
147
- return (0, tool_helpers_1.missingWorkspaceCacheResponse)();
148
- }
149
- logger.debug('Calling v3.insight.create', {
150
- workspaceId,
151
- name: args.name,
152
- sourcesCount: args.sources.length
153
- });
154
- // Normalize sources (convert 'id' to 'fieldId' if needed)
155
- const normalizedSources = normalizeFields(args.sources);
156
- // Build insight payload
157
- const insightData = {
158
- name: args.name,
159
- public: args.public || false,
160
- sources: normalizedSources,
161
- query: args.query,
296
+ const hasAdHocArgs = !!args.sources || !!args.query;
297
+ if (args.insightId && hasAdHocArgs) {
298
+ return {
299
+ content: [{
300
+ type: 'text',
301
+ text: '❌ **Conflicting modes**\n\nPass EITHER `insightId` (run a saved insight) OR `sources` + `query` (ad-hoc test) — not both.',
302
+ }],
162
303
  };
163
- // Call v3.insight.create endpoint
164
- const result = await context.hailer.request('v3.insight.create', [workspaceId, insightData]);
165
- logger.debug('Insight creation successful', {
166
- insightId: result.insightId || result._id,
167
- result: JSON.stringify(result)
168
- });
169
- const insightId = result.insightId || result._id;
170
- const discussionId = result.discussionId || result.discussion;
171
- // Automatically join the insight's discussion
172
- if (discussionId) {
173
- try {
174
- logger.debug('Automatically joining insight discussion', { discussionId });
175
- await context.hailer.joinDiscussion(discussionId);
176
- logger.debug('Successfully joined insight discussion', { discussionId });
177
- }
178
- catch (joinError) {
179
- logger.warn('Failed to join insight discussion (non-fatal)', {
180
- discussionId,
181
- error: joinError instanceof Error ? joinError.message : String(joinError)
182
- });
183
- }
184
- }
185
- else {
186
- logger.debug('No discussion ID in response, skipping auto-join');
187
- }
188
- // Build success response
189
- let responseText = `✅ **Insight Created Successfully**\n\n`;
190
- responseText += `**Insight Name:** ${args.name}\n`;
191
- responseText += `**Insight ID:** \`${insightId}\`\n`;
192
- responseText += `**Workspace:** ${workspaceId}\n`;
193
- responseText += `**Public:** ${args.public ? 'Yes' : 'No'}\n`;
194
- responseText += `**Sources:** ${args.sources.length} workflow(s)\n`;
195
- if (discussionId) {
196
- responseText += `**Discussion:** Automatically joined ✓\n`;
197
- }
198
- responseText += `\n`;
199
- // Show sources
200
- responseText += `**Query Sources:**\n`;
201
- args.sources.forEach((source) => {
202
- responseText += `- \`${source.name}\` → Workflow: \`${source.workflowId}\` (${source.fields.length} fields)\n`;
203
- });
204
- responseText += `\n**SQL Query:**\n\`\`\`sql\n${args.query}\n\`\`\`\n\n`;
205
- responseText += `💡 **Next Steps:**\n`;
206
- responseText += `- Use \`get_insight_data\` to execute the query and see results\n`;
207
- responseText += `- Use \`list_insights\` to see all insights in workspace\n`;
208
- responseText += `- Use \`update_insight\` to modify the insight\n`;
209
- responseText += `- Use \`preview_insight\` to test query changes before saving\n\n`;
210
- if (args.public) {
211
- responseText += `🌐 **Public Insight:** This insight can be accessed without authentication.\n`;
212
- }
304
+ }
305
+ if (args.insightId) {
306
+ return runSavedInsight(args.insightId, context, args.offset ?? 0, args.maxRows ?? 500);
307
+ }
308
+ if (!hasAdHocArgs) {
213
309
  return {
214
310
  content: [{
215
- type: "text",
216
- text: responseText,
311
+ type: 'text',
312
+ text: '❌ **Missing parameters**\n\nPass `insightId` to run a saved insight, or `sources` + `query` to test an ad-hoc SQL query.\n\nUse `list_insights` to find saved insight IDs.',
217
313
  }],
218
314
  };
219
315
  }
220
- catch (error) {
221
- if (!request_logger_1.RequestLogger.getCurrent())
222
- logger.error("Error creating insight", error);
223
- let errorMessage = 'Unknown error occurred';
224
- let errorDetails = '';
225
- if (error instanceof Error) {
226
- errorMessage = error.message;
227
- if (error.stack) {
228
- errorDetails = `\n\n**Stack trace:**\n\`\`\`\n${error.stack}\n\`\`\``;
229
- }
230
- }
231
- else if (typeof error === 'object' && error !== null) {
232
- try {
233
- errorMessage = JSON.stringify(error, null, 2);
234
- }
235
- catch {
236
- errorMessage = String(error);
237
- }
238
- }
239
- else {
240
- errorMessage = String(error);
241
- }
242
- // Handle SQL syntax errors
243
- if (errorMessage.toLowerCase().includes('sql') || errorMessage.toLowerCase().includes('syntax')) {
244
- return {
245
- content: [{
246
- type: "text",
247
- text: `❌ **SQL Query Error**\n\nThere's a problem with your SQL query.\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Check column names match field names in sources\n- Check table names match source names\n- Use \`preview_insight\` to test queries before creating\n- Make sure field IDs are correct (use \`get_workflow_schema\`)`,
248
- }],
249
- };
250
- }
251
- // Handle permission errors
252
- if (errorMessage.includes('permission') || errorMessage.includes('PermissionDenied')) {
253
- return {
254
- content: [{
255
- type: "text",
256
- text: `❌ **Permission Denied**\n\nYou may not have permission to create insights or access the specified workflows.\n\n**Error:** ${errorMessage}`,
257
- }],
258
- };
259
- }
316
+ if (!args.sources || !args.query) {
260
317
  return {
261
318
  content: [{
262
- type: "text",
263
- text: `❌ **Error creating insight**\n\n**Error:** ${errorMessage}${errorDetails}\n\n**Common Issues:**\n- SQL query syntax errors\n- Invalid field IDs or workflow IDs\n- Workflow fields don't exist\n- Permission issues\n- Check field IDs with \`get_workflow_schema\`\n- Test query with \`preview_insight\` first`,
319
+ type: 'text',
320
+ text: '❌ **Incomplete ad-hoc query**\n\nAd-hoc mode requires BOTH `sources` and `query`.',
264
321
  }],
265
322
  };
266
323
  }
324
+ return runAdHocInsight(args.sources, args.query, context, args.offset ?? 0, args.maxRows ?? 500);
267
325
  }
268
326
  };
269
327
  // ============================================================================
270
- // PREVIEW INSIGHT TOOL
328
+ // SAVE INSIGHT TOOL (create + update upsert)
271
329
  // ============================================================================
272
- const previewInsightDescription = `Test SQL query before creating insight. One call replaces multiple list_activities calls. Always preview before create_insight.
330
+ const saveInsightDescription = `Create or update a SQL insight over workflow data (upsert).
331
+ - BEFORE creating: call list_insights — an existing insight may already cover the question (run it by insightId) or be close enough to update. Creating with a name or query that already exists returns the existing insight instead of making a duplicate.
332
+ - Create: omit insightId — name, sources, and query are required.
333
+ - Update: pass insightId — only the provided fields (name, public, sources, query) are changed.
273
334
 
274
335
  ${INSIGHT_SQL_GUIDE}`;
275
- exports.previewInsightTool = {
276
- name: 'preview_insight',
277
- group: tool_registry_1.ToolGroup.PLAYGROUND,
278
- description: previewInsightDescription,
279
- schema: zod_1.z.object({
280
- workspaceId: zod_1.z
281
- .string()
282
- .optional()
283
- .describe("Optional workspace ID or name - defaults to current workspace"),
284
- sources: zod_1.z
285
- .array(sourceSchema)
286
- .min(1)
287
- .describe("Workflow sources. Use source.name as table, field.name as column in SQL."),
288
- query: zod_1.z
289
- .string()
290
- .min(1)
291
- .describe("SQL query to test"),
292
- insightId: zod_1.z
293
- .string()
294
- .optional()
295
- .describe("Optional insight ID if previewing changes to existing insight"),
296
- }),
297
- async execute(args, context) {
298
- logger.debug('Previewing insight', {
299
- workspaceId: args.workspaceId,
300
- sourcesCount: args.sources.length,
301
- insightId: args.insightId,
302
- apiKey: context.apiKey.substring(0, 8) + '...'
303
- });
304
- try {
305
- // Resolve workspace ID (returns undefined if cache unavailable)
306
- const workspaceId = (0, tool_helpers_1.getResolvedWorkspaceId)(args, context);
307
- if (!workspaceId) {
308
- return (0, tool_helpers_1.missingWorkspaceCacheResponse)();
336
+ /** Normalized-query comparison: whitespace collapsed, case-insensitive. */
337
+ function normalizeQuery(query) {
338
+ return query.replace(/\s+/g, ' ').trim().toLowerCase();
339
+ }
340
+ /**
341
+ * Looks up an existing insight with the same name (case-insensitive) or an
342
+ * identical query, so create calls reuse instead of piling up duplicates.
343
+ * Returns undefined when the list call fails — creation proceeds normally.
344
+ */
345
+ async function findExistingInsight(workspaceId, name, query, context) {
346
+ try {
347
+ const result = await context.hailer.request('v3.insight.list', [workspaceId]);
348
+ const insights = Array.isArray(result)
349
+ ? result
350
+ : (result.details || result.insights || []);
351
+ const wantedName = name.trim().toLowerCase();
352
+ const wantedQuery = normalizeQuery(query);
353
+ for (const insight of insights) {
354
+ if (insight.name?.trim().toLowerCase() === wantedName) {
355
+ return { _id: insight._id, name: insight.name, matchedBy: 'name' };
356
+ }
357
+ if (insight.query && normalizeQuery(insight.query) === wantedQuery) {
358
+ return { _id: insight._id, name: insight.name || '(unnamed)', matchedBy: 'query' };
309
359
  }
310
- logger.debug('Calling v3.insight.preview', {
311
- workspaceId,
312
- sourcesCount: args.sources.length,
313
- insightId: args.insightId
314
- });
315
- // Normalize sources (convert 'id' to 'fieldId' if needed)
316
- const normalizedSources = normalizeFields(args.sources);
317
- // Build preview payload (insightId not accepted by v3.insight.preview)
318
- const previewData = {
319
- sources: normalizedSources,
320
- query: args.query,
360
+ }
361
+ return undefined;
362
+ }
363
+ catch (error) {
364
+ logger.warn('Insight reuse check failed (non-fatal) - proceeding with create', {
365
+ error: (0, tool_helpers_1.extractErrorMessage)(error),
366
+ });
367
+ return undefined;
368
+ }
369
+ }
370
+ /** Create path: v3.insight.create (auto-joins the insight's discussion) */
371
+ async function createNewInsight(args, context) {
372
+ const { name, sources, query } = args;
373
+ if (!name || !sources || !query) {
374
+ return {
375
+ content: [{
376
+ type: 'text',
377
+ text: '❌ **Missing required fields**\n\nCreating a new insight (no `insightId`) requires `name`, `sources`, and `query`.\n\nTo update an existing insight instead, pass its `insightId`.',
378
+ }],
379
+ };
380
+ }
381
+ try {
382
+ // Resolve workspace ID (returns undefined if cache unavailable)
383
+ const workspaceId = (0, tool_helpers_1.getResolvedWorkspaceId)(args, context);
384
+ if (!workspaceId) {
385
+ return (0, tool_helpers_1.missingWorkspaceCacheResponse)();
386
+ }
387
+ // Reuse guard: models tend to create a fresh insight per question,
388
+ // piling up near-duplicates in the workspace.
389
+ const existing = await findExistingInsight(workspaceId, name, query, context);
390
+ if (existing) {
391
+ const matchReason = existing.matchedBy === 'query' ? 'already has this exact query' : 'already uses this name';
392
+ return {
393
+ content: [{
394
+ type: 'text',
395
+ text: `♻️ **Existing insight reused — no duplicate created**\n\n` +
396
+ `**${existing.name}** (ID: \`${existing._id}\`) ${matchReason}.\n\n` +
397
+ `- Run it: \`run_insight({ insightId: "${existing._id}" })\`\n` +
398
+ `- Modify it: \`save_insight({ insightId: "${existing._id}", ... })\`\n` +
399
+ `- Genuinely need a separate insight? Call save_insight again with a different name and query.`,
400
+ }],
321
401
  };
322
- // Call v3.insight.preview endpoint
323
- const result = await context.hailer.request('v3.insight.preview', [workspaceId, previewData]);
324
- logger.debug('Preview successful', {
325
- headers: result.headers?.length,
326
- rows: result.rows?.length
327
- });
328
- // Format results
329
- let responseText = `✅ **Preview Results** (~${result.rows?.length || 0} rows)\n\n`;
330
- if (!result.headers || !result.rows) {
331
- responseText += `⚠️ No data returned from preview\n`;
332
- }
333
- else if (result.rows.length === 0) {
334
- responseText += `**Columns:** ${result.headers.join(', ')}\n\n`;
335
- responseText += `⚠️ **No rows matched** - Check your query filters\n`;
336
- }
337
- else {
338
- responseText += `**Columns:** ${result.headers.join(', ')}\n\n`;
339
- responseText += `**Sample Data:**\n\`\`\`\n`;
340
- // Show column headers
341
- responseText += result.headers.join(' | ') + '\n';
342
- responseText += result.headers.map(() => '---').join(' | ') + '\n';
343
- // Show first 10 rows
344
- const rowsToShow = Math.min(result.rows.length, 10);
345
- for (let i = 0; i < rowsToShow; i++) {
346
- responseText += result.rows[i].map(v => String(v || '')).join(' | ') + '\n';
347
- }
348
- if (result.rows.length > 10) {
349
- responseText += `\n... and ${result.rows.length - 10} more rows\n`;
350
- }
351
- responseText += `\`\`\`\n\n`;
402
+ }
403
+ logger.debug('Calling v3.insight.create', {
404
+ workspaceId,
405
+ name,
406
+ sourcesCount: sources.length
407
+ });
408
+ // Normalize sources (convert 'id' to 'fieldId' if needed)
409
+ const normalizedSources = normalizeFields(sources);
410
+ // Build insight payload
411
+ const insightData = {
412
+ name,
413
+ public: args.public || false,
414
+ sources: normalizedSources,
415
+ query,
416
+ };
417
+ // Call v3.insight.create endpoint
418
+ const result = await context.hailer.request('v3.insight.create', [workspaceId, insightData]);
419
+ logger.debug('Insight creation successful', {
420
+ insightId: result.insightId || result._id,
421
+ result: JSON.stringify(result)
422
+ });
423
+ const insightId = result.insightId || result._id;
424
+ const discussionId = result.discussionId || result.discussion;
425
+ // Automatically join the insight's discussion
426
+ if (discussionId) {
427
+ try {
428
+ logger.debug('Automatically joining insight discussion', { discussionId });
429
+ await context.hailer.joinDiscussion(discussionId);
430
+ logger.debug('Successfully joined insight discussion', { discussionId });
431
+ }
432
+ catch (joinError) {
433
+ logger.warn('Failed to join insight discussion (non-fatal)', {
434
+ discussionId,
435
+ error: joinError instanceof Error ? joinError.message : String(joinError)
436
+ });
352
437
  }
353
- responseText += `\n✅ **Query is valid!** Ready to use in \`create_insight\` or \`update_insight\`.`;
438
+ }
439
+ if (!discussionId) {
440
+ logger.debug('No discussion ID in response, skipping auto-join');
441
+ }
442
+ // Build success response
443
+ let responseText = '✅ **Insight Created Successfully**\n\n';
444
+ responseText += `**Insight Name:** ${name}\n`;
445
+ responseText += `**Insight ID:** \`${insightId}\`\n`;
446
+ responseText += `**Workspace:** ${workspaceId}\n`;
447
+ responseText += `**Public:** ${args.public ? 'Yes' : 'No'}\n`;
448
+ responseText += `**Sources:** ${sources.length} workflow(s)\n`;
449
+ if (discussionId) {
450
+ responseText += '**Discussion:** Automatically joined ✓\n';
451
+ }
452
+ responseText += '\n';
453
+ // Show sources
454
+ responseText += '**Query Sources:**\n';
455
+ sources.forEach((source) => {
456
+ responseText += `- \`${source.name}\` → Workflow: \`${source.workflowId}\` (${source.fields.length} fields)\n`;
457
+ });
458
+ responseText += `\n**SQL Query:**\n\`\`\`sql\n${query}\n\`\`\`\n\n`;
459
+ responseText += '💡 **Next Steps:**\n';
460
+ responseText += '- Use `run_insight` with this insightId to execute the query and see results\n';
461
+ responseText += '- Use `list_insights` to see all insights in workspace\n';
462
+ responseText += '- Use `save_insight` with this insightId to modify the insight\n\n';
463
+ if (args.public) {
464
+ responseText += '🌐 **Public Insight:** This insight can be accessed without authentication.\n';
465
+ }
466
+ return {
467
+ content: [{
468
+ type: 'text',
469
+ text: responseText,
470
+ }],
471
+ };
472
+ }
473
+ catch (error) {
474
+ if (!request_logger_1.RequestLogger.getCurrent()) {
475
+ logger.error('Error creating insight', error);
476
+ }
477
+ const errorMessage = (0, tool_helpers_1.extractErrorMessage)(error);
478
+ const errorDetails = error instanceof Error && error.stack
479
+ ? `\n\n**Stack trace:**\n\`\`\`\n${error.stack}\n\`\`\``
480
+ : '';
481
+ // Handle SQL syntax errors
482
+ if (errorMessage.toLowerCase().includes('sql') || errorMessage.toLowerCase().includes('syntax')) {
354
483
  return {
355
484
  content: [{
356
- type: "text",
357
- text: responseText,
485
+ type: 'text',
486
+ text: `❌ **SQL Query Error**\n\nThere's a problem with your SQL query.\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Check column names match field names in sources\n- Check table names match source names\n- Use \`run_insight\` (sources + query) to test queries before saving\n- Make sure field IDs are correct (use \`describe_workflows\` with include:["schema"])`,
358
487
  }],
359
488
  };
360
489
  }
361
- catch (error) {
362
- if (!request_logger_1.RequestLogger.getCurrent())
363
- logger.error("Error previewing insight", error);
364
- let errorMessage = 'Unknown error occurred';
365
- if (error instanceof Error) {
366
- errorMessage = error.message;
367
- }
368
- else if (typeof error === 'object' && error !== null) {
369
- try {
370
- errorMessage = JSON.stringify(error, null, 2);
371
- }
372
- catch {
373
- errorMessage = String(error);
374
- }
375
- }
376
- else {
377
- errorMessage = String(error);
378
- }
490
+ // Handle permission errors
491
+ if (errorMessage.includes('permission') || errorMessage.includes('PermissionDenied')) {
379
492
  return {
380
493
  content: [{
381
- type: "text",
382
- text: `❌ **Preview Failed**\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Check SQL syntax\n- Verify field names match source definitions\n- Ensure workflow IDs are correct\n- Check table aliases match source names`,
494
+ type: 'text',
495
+ text: `❌ **Permission Denied**\n\nYou may not have permission to create insights or access the specified workflows.\n\n**Error:** ${errorMessage}`,
383
496
  }],
384
497
  };
385
498
  }
499
+ return {
500
+ content: [{
501
+ type: 'text',
502
+ text: `❌ **Error creating insight**\n\n**Error:** ${errorMessage}${errorDetails}\n\n**Common Issues:**\n- SQL query syntax errors\n- Invalid field IDs or workflow IDs\n- Workflow fields don't exist\n- Permission issues\n- Check field IDs with \`describe_workflows\` include:["schema"]\n- Test query with \`run_insight\` (sources + query) first`,
503
+ }],
504
+ };
386
505
  }
387
- };
388
- // ============================================================================
389
- // GET INSIGHT DATA TOOL
390
- // ============================================================================
391
- const getInsightDataDescription = `Execute insight and get results`;
392
- exports.getInsightDataTool = {
393
- name: 'get_insight_data',
394
- group: tool_registry_1.ToolGroup.PLAYGROUND,
395
- description: getInsightDataDescription,
396
- schema: zod_1.z.object({
397
- insightId: zod_1.z
398
- .string()
399
- .describe("Insight ID to execute"),
400
- update: zod_1.z
401
- .boolean()
402
- .optional()
403
- .default(false)
404
- .describe("Whether to recalculate data (true) or use cached results (false, default)"),
405
- }),
406
- async execute(args, context) {
407
- logger.debug('Getting insight data', {
408
- insightId: args.insightId,
409
- update: args.update,
410
- apiKey: context.apiKey.substring(0, 8) + '...'
506
+ }
507
+ /** Update path: v3.insight.update (partial-field semantics) */
508
+ async function updateExistingInsight(insightId, args, context) {
509
+ try {
510
+ // Build update payload - only include provided fields
511
+ const updateData = {};
512
+ if (args.name) {
513
+ updateData.name = args.name;
514
+ }
515
+ if (typeof args.public === 'boolean') {
516
+ updateData.public = args.public;
517
+ }
518
+ if (args.sources) {
519
+ updateData.sources = normalizeFields(args.sources);
520
+ }
521
+ if (args.query) {
522
+ updateData.query = args.query;
523
+ }
524
+ // Validate at least one field is being updated
525
+ if (Object.keys(updateData).length === 0) {
526
+ return {
527
+ content: [{
528
+ type: 'text',
529
+ text: `❌ **No updates provided**\n\nYou must provide at least one field to update:\n- name\n- public\n- sources\n- query\n\nExample:\n\`\`\`javascript\nsave_insight({\n insightId: "${insightId}",\n name: "New Name"\n})\n\`\`\``,
530
+ }],
531
+ };
532
+ }
533
+ logger.debug('Calling v3.insight.update', {
534
+ insightId,
535
+ updateFields: Object.keys(updateData)
411
536
  });
412
- try {
413
- logger.debug('Calling v3.insight.data', {
414
- insightId: args.insightId,
415
- update: args.update
416
- });
417
- // Call v3.insight.data endpoint
418
- const result = await context.hailer.request('v3.insight.data', [args.insightId, { update: args.update || false }]);
419
- logger.debug('Insight data retrieved', {
420
- headers: result.headers?.length,
421
- rows: result.rows?.length,
422
- fullResult: JSON.stringify(result).substring(0, 500)
423
- });
424
- // Format results
425
- let responseText = `✅ **Insight Data Retrieved** (${result.rows?.length || 0} rows)\n\n`;
426
- if (!result.headers || !result.rows) {
427
- responseText += `⚠️ No data returned\n`;
428
- responseText += `**Debug:** Response keys: ${Object.keys(result).join(', ')}\n`;
429
- responseText += `**Full response (truncated):** \`${JSON.stringify(result).substring(0, 300)}\`\n`;
430
- }
431
- else if (result.rows.length === 0) {
432
- responseText += `**Columns:** ${result.headers.join(', ')}\n\n`;
433
- responseText += `⚠️ **No rows matched**\n`;
434
- }
435
- else {
436
- responseText += `**Columns:** ${result.headers.join(', ')}\n\n`;
437
- responseText += `**Sample Data (first 10 rows):**\n\`\`\`\n`;
438
- // Show column headers
439
- responseText += result.headers.join(' | ') + '\n';
440
- responseText += result.headers.map(() => '---').join(' | ') + '\n';
441
- // Show first 10 rows
442
- const rowsToShow = Math.min(result.rows.length, 10);
443
- for (let i = 0; i < rowsToShow; i++) {
444
- responseText += result.rows[i].map(v => String(v || '')).join(' | ') + '\n';
445
- }
446
- if (result.rows.length > 10) {
447
- responseText += `\n... and ${result.rows.length - 10} more rows\n`;
448
- }
449
- responseText += `\`\`\`\n`;
450
- }
537
+ // Call v3.insight.update endpoint
538
+ // API expects: [insightId, updateData]
539
+ const result = await context.hailer.request('v3.insight.update', [
540
+ insightId,
541
+ updateData
542
+ ]);
543
+ logger.debug('Insight update successful', {
544
+ insightId,
545
+ result: JSON.stringify(result)
546
+ });
547
+ // Build success response
548
+ let responseText = '✅ **Insight Updated Successfully**\n\n';
549
+ responseText += `**Insight ID:** \`${insightId}\`\n`;
550
+ responseText += '**Updated Fields:**\n';
551
+ if (args.name) {
552
+ responseText += `- Name: ${args.name}\n`;
553
+ }
554
+ if (typeof args.public === 'boolean') {
555
+ responseText += `- Public: ${args.public ? 'Yes' : 'No'}\n`;
556
+ }
557
+ if (args.sources) {
558
+ responseText += `- Sources: ${args.sources.length} workflow(s)\n`;
559
+ }
560
+ if (args.query) {
561
+ responseText += '- Query: Updated\n';
562
+ }
563
+ if (args.query) {
564
+ responseText += `\n**New SQL Query:**\n\`\`\`sql\n${args.query}\n\`\`\`\n`;
565
+ }
566
+ responseText += '\n💡 **Next Steps:**\n';
567
+ responseText += '- Use `run_insight` with the insightId to see results\n';
568
+ responseText += '- Use `run_insight` (sources + query) to test if you made query changes\n';
569
+ responseText += '- Use `list_insights` to see all insights\n';
570
+ return {
571
+ content: [{
572
+ type: 'text',
573
+ text: responseText,
574
+ }],
575
+ };
576
+ }
577
+ catch (error) {
578
+ if (!request_logger_1.RequestLogger.getCurrent()) {
579
+ logger.error('Error updating insight', error);
580
+ }
581
+ const errorMessage = (0, tool_helpers_1.extractErrorMessage)(error);
582
+ // Handle SQL syntax errors
583
+ if (errorMessage.toLowerCase().includes('sql') || errorMessage.toLowerCase().includes('syntax')) {
451
584
  return {
452
585
  content: [{
453
- type: "text",
454
- text: responseText,
586
+ type: 'text',
587
+ text: `❌ **SQL Query Error**\n\nThere's a problem with your SQL query.\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Check column names match field names in sources\n- Check table names match source names\n- Use \`run_insight\` (sources + query) to test queries before updating\n- Make sure field IDs are correct (use \`describe_workflows\` with include:["schema"])`,
455
588
  }],
456
589
  };
457
590
  }
458
- catch (error) {
459
- if (!request_logger_1.RequestLogger.getCurrent())
460
- logger.error("Error getting insight data", error);
461
- let errorMessage = 'Unknown error occurred';
462
- if (error instanceof Error) {
463
- errorMessage = error.message;
464
- }
465
- else if (typeof error === 'object' && error !== null) {
466
- try {
467
- errorMessage = JSON.stringify(error, null, 2);
468
- }
469
- catch {
470
- errorMessage = String(error);
471
- }
472
- }
473
- else {
474
- errorMessage = String(error);
475
- }
591
+ // Handle permission errors
592
+ if (errorMessage.includes('permission') || errorMessage.includes('PermissionDenied')) {
476
593
  return {
477
594
  content: [{
478
- type: "text",
479
- text: `❌ **Error getting insight data**\n\n**Error:** ${errorMessage}\n\n**Common Issues:**\n- Insight ID not found\n- Permission denied\n- Insight query has errors\n- Use \`list_insights\` to verify insight ID`,
595
+ type: 'text',
596
+ text: `❌ **Permission Denied**\n\nYou may not have permission to update this insight.\n\n**Error:** ${errorMessage}`,
480
597
  }],
481
598
  };
482
599
  }
600
+ // Handle not found errors
601
+ if (errorMessage.includes('not found') || errorMessage.includes('NotFound')) {
602
+ return {
603
+ content: [{
604
+ type: 'text',
605
+ text: `❌ **Insight Not Found**\n\nInsight ID \`${insightId}\` does not exist.\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Use \`list_insights\` to find valid insight IDs\n- Check for typos in the insight ID`,
606
+ }],
607
+ };
608
+ }
609
+ return {
610
+ content: [{
611
+ type: 'text',
612
+ text: `❌ **Error updating insight**\n\n**Error:** ${errorMessage}\n\n**Common Issues:**\n- Insight ID not found\n- SQL query syntax errors\n- Invalid field IDs or workflow IDs\n- Permission issues\n- Use \`list_insights\` to verify insight ID\n- Use \`run_insight\` (sources + query) to test query changes first`,
613
+ }],
614
+ };
483
615
  }
484
- };
485
- // ============================================================================
486
- // UPDATE INSIGHT TOOL
487
- // ============================================================================
488
- const updateInsightDescription = `Update existing insight (name, query, sources, or visibility)`;
489
- exports.updateInsightTool = {
490
- name: 'update_insight',
616
+ }
617
+ exports.saveInsightTool = {
618
+ name: 'save_insight',
491
619
  group: tool_registry_1.ToolGroup.PLAYGROUND,
492
- description: updateInsightDescription,
620
+ description: saveInsightDescription,
493
621
  schema: zod_1.z.object({
622
+ workspaceId: zod_1.z
623
+ .string()
624
+ .optional()
625
+ .describe('Optional workspace ID or name - defaults to current workspace (create mode only)'),
494
626
  insightId: zod_1.z
495
627
  .string()
496
- .describe("Insight ID to update (24 characters)"),
628
+ .optional()
629
+ .describe('Existing insight ID to update (24 characters). Omit to create a new insight.'),
497
630
  name: zod_1.z
498
631
  .string()
632
+ .min(1)
499
633
  .optional()
500
- .describe("New insight name"),
634
+ .describe('Insight name (required when creating)'),
501
635
  public: zod_1.z
502
636
  .coerce.boolean()
503
637
  .optional()
504
- .describe("Whether insight is publicly accessible"),
638
+ .describe('Whether insight is publicly accessible (default: false on create)'),
505
639
  sources: zod_1.z
506
- .preprocess((val) => typeof val === 'string' ? JSON.parse(val) : val, zod_1.z.array(sourceSchema).optional())
507
- .describe("Updated workflow sources (like SQL table references)"),
640
+ .preprocess((val) => typeof val === 'string' ? JSON.parse(val) : val, zod_1.z.array(sourceSchema).min(1).optional())
641
+ .describe('Workflow sources (required when creating). source.name = SQL table name, field.name = SQL column name. Never use IDs in the query.'),
508
642
  query: zod_1.z
509
643
  .string()
644
+ .min(1)
510
645
  .optional()
511
- .describe("Updated SQL query"),
646
+ .describe('SQL query (SELECT, JOIN, WHERE, GROUP BY, ORDER BY, etc.) - required when creating'),
512
647
  }),
513
648
  async execute(args, context) {
514
- logger.debug('Updating insight', {
649
+ logger.debug('Saving insight', {
515
650
  insightId: args.insightId,
516
651
  hasName: !!args.name,
517
652
  hasQuery: !!args.query,
518
653
  hasSources: !!args.sources,
519
- hasPublic: args.public !== undefined,
654
+ hasPublic: typeof args.public === 'boolean',
520
655
  apiKey: context.apiKey.substring(0, 8) + '...'
521
656
  });
522
- try {
523
- // Build update payload - only include provided fields
524
- const updateData = {};
525
- if (args.name !== undefined) {
526
- updateData.name = args.name;
527
- }
528
- if (args.public !== undefined) {
529
- updateData.public = args.public;
530
- }
531
- if (args.sources !== undefined) {
532
- updateData.sources = normalizeFields(args.sources);
533
- }
534
- if (args.query !== undefined) {
535
- updateData.query = args.query;
536
- }
537
- // Validate at least one field is being updated
538
- if (Object.keys(updateData).length === 0) {
539
- return {
540
- content: [{
541
- type: "text",
542
- text: `❌ **No updates provided**\n\nYou must provide at least one field to update:\n- name\n- public\n- sources\n- query\n\nExample:\n\`\`\`javascript\nupdate_insight({\n insightId: "${args.insightId}",\n name: "New Name"\n})\n\`\`\``,
543
- }],
544
- };
545
- }
546
- logger.debug('Calling v3.insight.update', {
547
- insightId: args.insightId,
548
- updateFields: Object.keys(updateData)
549
- });
550
- // Call v3.insight.update endpoint
551
- // API expects: [insightId, updateData]
552
- const result = await context.hailer.request('v3.insight.update', [
553
- args.insightId,
554
- updateData
555
- ]);
556
- logger.debug('Insight update successful', {
557
- insightId: args.insightId,
558
- result: JSON.stringify(result)
559
- });
560
- // Build success response
561
- let responseText = `✅ **Insight Updated Successfully**\n\n`;
562
- responseText += `**Insight ID:** \`${args.insightId}\`\n`;
563
- responseText += `**Updated Fields:**\n`;
564
- if (args.name !== undefined) {
565
- responseText += `- Name: ${args.name}\n`;
566
- }
567
- if (args.public !== undefined) {
568
- responseText += `- Public: ${args.public ? 'Yes' : 'No'}\n`;
569
- }
570
- if (args.sources !== undefined) {
571
- responseText += `- Sources: ${args.sources.length} workflow(s)\n`;
572
- }
573
- if (args.query !== undefined) {
574
- responseText += `- Query: Updated\n`;
575
- }
576
- if (args.query) {
577
- responseText += `\n**New SQL Query:**\n\`\`\`sql\n${args.query}\n\`\`\`\n`;
578
- }
579
- responseText += `\n💡 **Next Steps:**\n`;
580
- responseText += `- Use \`get_insight_data\` with \`update: true\` to see fresh results\n`;
581
- responseText += `- Use \`preview_insight\` to test if you made query changes\n`;
582
- responseText += `- Use \`list_insights\` to see all insights\n`;
583
- return {
584
- content: [{
585
- type: "text",
586
- text: responseText,
587
- }],
588
- };
589
- }
590
- catch (error) {
591
- if (!request_logger_1.RequestLogger.getCurrent())
592
- logger.error("Error updating insight", error);
593
- const errorMessage = (0, tool_helpers_1.extractErrorMessage)(error);
594
- // Handle SQL syntax errors
595
- if (errorMessage.toLowerCase().includes('sql') || errorMessage.toLowerCase().includes('syntax')) {
596
- return {
597
- content: [{
598
- type: "text",
599
- text: `❌ **SQL Query Error**\n\nThere's a problem with your SQL query.\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Check column names match field names in sources\n- Check table names match source names\n- Use \`preview_insight\` to test queries before updating\n- Make sure field IDs are correct (use \`get_workflow_schema\`)`,
600
- }],
601
- };
602
- }
603
- // Handle permission errors
604
- if (errorMessage.includes('permission') || errorMessage.includes('PermissionDenied')) {
605
- return {
606
- content: [{
607
- type: "text",
608
- text: `❌ **Permission Denied**\n\nYou may not have permission to update this insight.\n\n**Error:** ${errorMessage}`,
609
- }],
610
- };
611
- }
612
- // Handle not found errors
613
- if (errorMessage.includes('not found') || errorMessage.includes('NotFound')) {
614
- return {
615
- content: [{
616
- type: "text",
617
- text: `❌ **Insight Not Found**\n\nInsight ID \`${args.insightId}\` does not exist.\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Use \`list_insights\` to find valid insight IDs\n- Check for typos in the insight ID`,
618
- }],
619
- };
620
- }
621
- return {
622
- content: [{
623
- type: "text",
624
- text: `❌ **Error updating insight**\n\n**Error:** ${errorMessage}\n\n**Common Issues:**\n- Insight ID not found\n- SQL query syntax errors\n- Invalid field IDs or workflow IDs\n- Permission issues\n- Use \`list_insights\` to verify insight ID\n- Use \`preview_insight\` to test query changes first`,
625
- }],
626
- };
657
+ if (args.insightId) {
658
+ return updateExistingInsight(args.insightId, args, context);
627
659
  }
660
+ return createNewInsight(args, context);
628
661
  }
629
662
  };
630
663
  // ============================================================================
@@ -638,15 +671,15 @@ exports.removeInsightTool = {
638
671
  schema: zod_1.z.object({
639
672
  insightId: zod_1.z
640
673
  .string()
641
- .describe("Insight ID to remove (get from list_insights or create_insight)"),
674
+ .describe('Insight ID to remove (get from list_insights or save_insight)'),
642
675
  confirmed: zod_1.z
643
676
  .boolean()
644
677
  .optional()
645
- .describe("First confirmation - must be true to proceed"),
678
+ .describe('First confirmation - must be true to proceed'),
646
679
  secondConfirmed: zod_1.z
647
680
  .boolean()
648
681
  .optional()
649
- .describe("Second confirmation - must be true to proceed (required for double-check safety)"),
682
+ .describe('Second confirmation - must be true to proceed (required for double-check safety)'),
650
683
  }),
651
684
  async execute(args, context) {
652
685
  logger.debug('Removing insight', {
@@ -664,7 +697,7 @@ exports.removeInsightTool = {
664
697
  // Fetch insight info and workspace info
665
698
  const [insightListResult, initData] = await Promise.all([
666
699
  context.hailer.request('v3.insight.list', [workspaceId]),
667
- context.hailer.request('v2.core.init', [["network"]])
700
+ context.hailer.request('v2.core.init', [['network']])
668
701
  ]);
669
702
  const insights = Array.isArray(insightListResult) ? insightListResult : (insightListResult.details || insightListResult.insights || []);
670
703
  const insight = insights.find((i) => i._id === args.insightId);
@@ -695,11 +728,11 @@ exports.removeInsightTool = {
695
728
  warningText += `\`\`\`\n\n`;
696
729
  warningText += `💡 **Before proceeding:**\n`;
697
730
  warningText += `- Load \`remove-insight-skill\` to review safety checklist\n`;
698
- warningText += `- Use \`get_insight_data\` to verify before deleting\n`;
731
+ warningText += `- Use \`run_insight\` to verify before deleting\n`;
699
732
  warningText += `- Verify with user that this is intentional`;
700
733
  return {
701
734
  content: [{
702
- type: "text",
735
+ type: 'text',
703
736
  text: warningText,
704
737
  }],
705
738
  };
@@ -724,14 +757,15 @@ exports.removeInsightTool = {
724
757
  responseText += `💡 Use \`list_insights\` to see remaining insights.`;
725
758
  return {
726
759
  content: [{
727
- type: "text",
760
+ type: 'text',
728
761
  text: responseText,
729
762
  }],
730
763
  };
731
764
  }
732
765
  catch (error) {
733
- if (!request_logger_1.RequestLogger.getCurrent())
734
- logger.error("Error removing insight", error);
766
+ if (!request_logger_1.RequestLogger.getCurrent()) {
767
+ logger.error('Error removing insight', error);
768
+ }
735
769
  let errorMessage = 'Unknown error occurred';
736
770
  if (error instanceof Error) {
737
771
  errorMessage = error.message;
@@ -749,14 +783,14 @@ exports.removeInsightTool = {
749
783
  }
750
784
  return {
751
785
  content: [{
752
- type: "text",
786
+ type: 'text',
753
787
  text: `❌ **Error removing insight**\n\n**Error:** ${errorMessage}\n\n**Common Issues:**\n- Insight ID not found\n- Permission denied\n- Insight already deleted\n- Use \`list_insights\` to verify insight ID`,
754
788
  }],
755
789
  };
756
790
  }
757
791
  }
758
792
  };
759
- const listInsightsDescription = `List all insights in workspace`;
793
+ const listInsightsDescription = `List all insights in the workspace (name, ID, table names, query). Check here BEFORE save_insight — reuse or update an existing insight instead of creating near-duplicates.`;
760
794
  exports.listInsightsTool = {
761
795
  name: 'list_insights',
762
796
  group: tool_registry_1.ToolGroup.PLAYGROUND,
@@ -765,7 +799,7 @@ exports.listInsightsTool = {
765
799
  workspaceId: zod_1.z
766
800
  .string()
767
801
  .optional()
768
- .describe("Optional workspace ID or name - defaults to current workspace"),
802
+ .describe('Optional workspace ID or name - defaults to current workspace'),
769
803
  }),
770
804
  async execute(args, context) {
771
805
  logger.debug('Listing insights', {
@@ -792,7 +826,7 @@ exports.listInsightsTool = {
792
826
  let responseText = `📊 **Insights Found** (${insights.length || 0} total)\n\n`;
793
827
  if (!insights || insights.length === 0) {
794
828
  responseText += `No insights found in this workspace.\n\n`;
795
- responseText += `💡 Use \`create_insight\` to create a new SQL-like report.`;
829
+ responseText += `💡 Use \`save_insight\` to create a new SQL-like report.`;
796
830
  }
797
831
  else {
798
832
  insights.forEach((insight, index) => {
@@ -807,20 +841,21 @@ exports.listInsightsTool = {
807
841
  responseText += ` - Query: \`${insight.query?.substring(0, 80)}${(insight.query?.length || 0) > 80 ? '...' : ''}\`\n\n`;
808
842
  });
809
843
  responseText += `💡 **Next Steps:**\n`;
810
- responseText += `- Use \`get_insight_data\` to execute an insight\n`;
811
- responseText += `- Use \`preview_insight\` to test query changes\n`;
844
+ responseText += `- Use \`run_insight\` with an insightId to execute an insight\n`;
845
+ responseText += `- Use \`run_insight\` with sources + query to test changes\n`;
812
846
  responseText += `- Use \`remove_insight\` to delete an insight\n`;
813
847
  }
814
848
  return {
815
849
  content: [{
816
- type: "text",
850
+ type: 'text',
817
851
  text: responseText,
818
852
  }],
819
853
  };
820
854
  }
821
855
  catch (error) {
822
- if (!request_logger_1.RequestLogger.getCurrent())
823
- logger.error("Error listing insights", error);
856
+ if (!request_logger_1.RequestLogger.getCurrent()) {
857
+ logger.error('Error listing insights', error);
858
+ }
824
859
  let errorMessage = 'Unknown error occurred';
825
860
  if (error instanceof Error) {
826
861
  errorMessage = error.message;
@@ -838,7 +873,7 @@ exports.listInsightsTool = {
838
873
  }
839
874
  return {
840
875
  content: [{
841
- type: "text",
876
+ type: 'text',
842
877
  text: `❌ **Error listing insights**\n\n**Error:** ${errorMessage}\n\n**Tips:**\n- Check workspace ID is valid\n- Verify you have permission to list insights`,
843
878
  }],
844
879
  };
@@ -847,11 +882,9 @@ exports.listInsightsTool = {
847
882
  };
848
883
  /** All insight tools */
849
884
  exports.insightTools = [
850
- exports.createInsightTool,
851
- exports.previewInsightTool,
852
- exports.getInsightDataTool,
853
- exports.updateInsightTool,
854
- exports.removeInsightTool,
855
885
  exports.listInsightsTool,
886
+ exports.runInsightTool,
887
+ exports.saveInsightTool,
888
+ exports.removeInsightTool,
856
889
  ];
857
890
  //# sourceMappingURL=insight.js.map