@hailer/mcp 0.0.1

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 (163) hide show
  1. package/.claude/commands/tool-builder.md +37 -0
  2. package/.claude/commands/ws-pull.md +44 -0
  3. package/.claude/settings.json +8 -0
  4. package/.claude/settings.local.json +49 -0
  5. package/.claude/skills/activity-api/SKILL.md +96 -0
  6. package/.claude/skills/activity-api/references/activity-endpoints.md +845 -0
  7. package/.claude/skills/add-app-member-skill/SKILL.md +977 -0
  8. package/.claude/skills/agent-building/SKILL.md +243 -0
  9. package/.claude/skills/agent-building/references/architecture-patterns.md +446 -0
  10. package/.claude/skills/agent-building/references/code-examples.md +587 -0
  11. package/.claude/skills/agent-building/references/implementation-guide.md +619 -0
  12. package/.claude/skills/app-api/SKILL.md +219 -0
  13. package/.claude/skills/app-api/references/app-endpoints.md +759 -0
  14. package/.claude/skills/building-hailer-apps-skill/SKILL.md +548 -0
  15. package/.claude/skills/create-app-skill/SKILL.md +1101 -0
  16. package/.claude/skills/create-insight-skill/SKILL.md +1317 -0
  17. package/.claude/skills/get-insight-data-skill/SKILL.md +1053 -0
  18. package/.claude/skills/hailer-api/SKILL.md +283 -0
  19. package/.claude/skills/hailer-api/references/activities.md +620 -0
  20. package/.claude/skills/hailer-api/references/authentication.md +216 -0
  21. package/.claude/skills/hailer-api/references/datasets.md +437 -0
  22. package/.claude/skills/hailer-api/references/files.md +301 -0
  23. package/.claude/skills/hailer-api/references/insights.md +469 -0
  24. package/.claude/skills/hailer-api/references/workflows.md +720 -0
  25. package/.claude/skills/hailer-api/references/workspaces-users.md +445 -0
  26. package/.claude/skills/insight-api/SKILL.md +185 -0
  27. package/.claude/skills/insight-api/references/insight-endpoints.md +514 -0
  28. package/.claude/skills/install-workflow-skill/SKILL.md +1056 -0
  29. package/.claude/skills/list-apps-skill/SKILL.md +1010 -0
  30. package/.claude/skills/list-workflows-minimal-skill/SKILL.md +992 -0
  31. package/.claude/skills/local-first-skill/SKILL.md +570 -0
  32. package/.claude/skills/mcp-tools/SKILL.md +419 -0
  33. package/.claude/skills/mcp-tools/references/api-endpoints.md +499 -0
  34. package/.claude/skills/mcp-tools/references/data-structures.md +554 -0
  35. package/.claude/skills/mcp-tools/references/implementation-patterns.md +717 -0
  36. package/.claude/skills/preview-insight-skill/SKILL.md +1290 -0
  37. package/.claude/skills/publish-hailer-app-skill/SKILL.md +453 -0
  38. package/.claude/skills/remove-app-member-skill/SKILL.md +671 -0
  39. package/.claude/skills/remove-app-skill/SKILL.md +985 -0
  40. package/.claude/skills/remove-insight-skill/SKILL.md +1011 -0
  41. package/.claude/skills/remove-workflow-skill/SKILL.md +920 -0
  42. package/.claude/skills/scaffold-hailer-app-skill/SKILL.md +1034 -0
  43. package/.claude/skills/skill-testing/README.md +137 -0
  44. package/.claude/skills/skill-testing/SKILL.md +348 -0
  45. package/.claude/skills/skill-testing/references/test-patterns.md +705 -0
  46. package/.claude/skills/skill-testing/references/testing-guide.md +603 -0
  47. package/.claude/skills/skill-testing/references/validation-checklist.md +537 -0
  48. package/.claude/skills/tool-builder/SKILL.md +328 -0
  49. package/.claude/skills/update-app-skill/SKILL.md +970 -0
  50. package/.claude/skills/update-workflow-field-skill/SKILL.md +1098 -0
  51. package/.env.example +81 -0
  52. package/.mcp.json +13 -0
  53. package/README.md +297 -0
  54. package/dist/app.d.ts +4 -0
  55. package/dist/app.js +74 -0
  56. package/dist/cli.d.ts +3 -0
  57. package/dist/cli.js +5 -0
  58. package/dist/client/adaptive-documentation-bot.d.ts +108 -0
  59. package/dist/client/adaptive-documentation-bot.js +475 -0
  60. package/dist/client/adaptive-documentation-types.d.ts +66 -0
  61. package/dist/client/adaptive-documentation-types.js +9 -0
  62. package/dist/client/agent-activity-bot.d.ts +51 -0
  63. package/dist/client/agent-activity-bot.js +166 -0
  64. package/dist/client/agent-tracker.d.ts +499 -0
  65. package/dist/client/agent-tracker.js +659 -0
  66. package/dist/client/description-updater.d.ts +56 -0
  67. package/dist/client/description-updater.js +259 -0
  68. package/dist/client/log-parser.d.ts +72 -0
  69. package/dist/client/log-parser.js +387 -0
  70. package/dist/client/mcp-client.d.ts +50 -0
  71. package/dist/client/mcp-client.js +532 -0
  72. package/dist/client/message-processor.d.ts +35 -0
  73. package/dist/client/message-processor.js +352 -0
  74. package/dist/client/multi-bot-manager.d.ts +24 -0
  75. package/dist/client/multi-bot-manager.js +74 -0
  76. package/dist/client/providers/anthropic-provider.d.ts +19 -0
  77. package/dist/client/providers/anthropic-provider.js +631 -0
  78. package/dist/client/providers/llm-provider.d.ts +47 -0
  79. package/dist/client/providers/llm-provider.js +367 -0
  80. package/dist/client/providers/openai-provider.d.ts +23 -0
  81. package/dist/client/providers/openai-provider.js +621 -0
  82. package/dist/client/simple-llm-caller.d.ts +19 -0
  83. package/dist/client/simple-llm-caller.js +100 -0
  84. package/dist/client/skill-generator.d.ts +81 -0
  85. package/dist/client/skill-generator.js +386 -0
  86. package/dist/client/test-adaptive-bot.d.ts +9 -0
  87. package/dist/client/test-adaptive-bot.js +82 -0
  88. package/dist/client/token-pricing.d.ts +38 -0
  89. package/dist/client/token-pricing.js +127 -0
  90. package/dist/client/token-tracker.d.ts +232 -0
  91. package/dist/client/token-tracker.js +457 -0
  92. package/dist/client/token-usage-bot.d.ts +53 -0
  93. package/dist/client/token-usage-bot.js +153 -0
  94. package/dist/client/tool-executor.d.ts +69 -0
  95. package/dist/client/tool-executor.js +159 -0
  96. package/dist/client/tool-schema-loader.d.ts +60 -0
  97. package/dist/client/tool-schema-loader.js +178 -0
  98. package/dist/client/types.d.ts +69 -0
  99. package/dist/client/types.js +7 -0
  100. package/dist/config.d.ts +162 -0
  101. package/dist/config.js +296 -0
  102. package/dist/core.d.ts +26 -0
  103. package/dist/core.js +147 -0
  104. package/dist/lib/context-manager.d.ts +111 -0
  105. package/dist/lib/context-manager.js +431 -0
  106. package/dist/lib/logger.d.ts +74 -0
  107. package/dist/lib/logger.js +277 -0
  108. package/dist/lib/materialize.d.ts +3 -0
  109. package/dist/lib/materialize.js +101 -0
  110. package/dist/lib/normalizedName.d.ts +7 -0
  111. package/dist/lib/normalizedName.js +48 -0
  112. package/dist/lib/prompt-length-manager.d.ts +81 -0
  113. package/dist/lib/prompt-length-manager.js +457 -0
  114. package/dist/lib/terminal-prompt.d.ts +9 -0
  115. package/dist/lib/terminal-prompt.js +108 -0
  116. package/dist/mcp/UserContextCache.d.ts +56 -0
  117. package/dist/mcp/UserContextCache.js +163 -0
  118. package/dist/mcp/auth.d.ts +2 -0
  119. package/dist/mcp/auth.js +29 -0
  120. package/dist/mcp/hailer-clients.d.ts +42 -0
  121. package/dist/mcp/hailer-clients.js +246 -0
  122. package/dist/mcp/signal-handler.d.ts +45 -0
  123. package/dist/mcp/signal-handler.js +317 -0
  124. package/dist/mcp/tool-registry.d.ts +100 -0
  125. package/dist/mcp/tool-registry.js +306 -0
  126. package/dist/mcp/tools/activity.d.ts +15 -0
  127. package/dist/mcp/tools/activity.js +955 -0
  128. package/dist/mcp/tools/app.d.ts +20 -0
  129. package/dist/mcp/tools/app.js +1488 -0
  130. package/dist/mcp/tools/discussion.d.ts +19 -0
  131. package/dist/mcp/tools/discussion.js +950 -0
  132. package/dist/mcp/tools/file.d.ts +15 -0
  133. package/dist/mcp/tools/file.js +119 -0
  134. package/dist/mcp/tools/insight.d.ts +17 -0
  135. package/dist/mcp/tools/insight.js +806 -0
  136. package/dist/mcp/tools/skill.d.ts +10 -0
  137. package/dist/mcp/tools/skill.js +279 -0
  138. package/dist/mcp/tools/user.d.ts +10 -0
  139. package/dist/mcp/tools/user.js +108 -0
  140. package/dist/mcp/tools/workflow-template.d.ts +19 -0
  141. package/dist/mcp/tools/workflow-template.js +822 -0
  142. package/dist/mcp/tools/workflow.d.ts +18 -0
  143. package/dist/mcp/tools/workflow.js +1362 -0
  144. package/dist/mcp/utils/api-errors.d.ts +45 -0
  145. package/dist/mcp/utils/api-errors.js +160 -0
  146. package/dist/mcp/utils/data-transformers.d.ts +102 -0
  147. package/dist/mcp/utils/data-transformers.js +194 -0
  148. package/dist/mcp/utils/file-upload.d.ts +33 -0
  149. package/dist/mcp/utils/file-upload.js +148 -0
  150. package/dist/mcp/utils/hailer-api-client.d.ts +120 -0
  151. package/dist/mcp/utils/hailer-api-client.js +323 -0
  152. package/dist/mcp/utils/index.d.ts +13 -0
  153. package/dist/mcp/utils/index.js +39 -0
  154. package/dist/mcp/utils/logger.d.ts +42 -0
  155. package/dist/mcp/utils/logger.js +103 -0
  156. package/dist/mcp/utils/types.d.ts +286 -0
  157. package/dist/mcp/utils/types.js +7 -0
  158. package/dist/mcp/workspace-cache.d.ts +42 -0
  159. package/dist/mcp/workspace-cache.js +97 -0
  160. package/dist/mcp-server.d.ts +42 -0
  161. package/dist/mcp-server.js +280 -0
  162. package/package.json +56 -0
  163. package/tsconfig.json +23 -0
@@ -0,0 +1,1011 @@
1
+ ---
2
+ name: Removing Hailer Insights
3
+ description: Complete guide for safely removing Hailer insights - use when deleting reports or cleaning up insights
4
+ ---
5
+
6
+ # Removing Hailer Insights - Complete Guide
7
+
8
+ Complete reference for safely removing Hailer insights using the `remove_insight` MCP tool.
9
+
10
+ ## Table of Contents
11
+ 1. [Quick Reference](#quick-reference)
12
+ 2. [Overview](#overview)
13
+ 3. [What Gets Deleted](#what-gets-deleted)
14
+ 4. [Prerequisites](#prerequisites)
15
+ 5. [Basic Usage](#basic-usage)
16
+ 6. [Safety Checklist](#safety-checklist)
17
+ 7. [Common Scenarios](#common-scenarios)
18
+ 8. [Before Removing](#before-removing)
19
+ 9. [After Removing](#after-removing)
20
+ 10. [Best Practices](#best-practices)
21
+ 11. [Troubleshooting](#troubleshooting)
22
+
23
+ ## Quick Reference
24
+
25
+ **⚠️ WARNING: This operation is PERMANENT and CANNOT be undone!**
26
+
27
+ **Basic Removal:**
28
+
29
+ ```javascript
30
+ remove_insight({
31
+ insightId: 'insight-id'
32
+ })
33
+ ```
34
+
35
+ **Response:**
36
+ ```
37
+ ✅ Insight Removed Successfully
38
+
39
+ Insight ID: insight-id
40
+
41
+ ⚠️ The insight has been permanently deleted.
42
+
43
+ What was deleted:
44
+ - Insight definition (SQL query and sources)
45
+ - Saved query results
46
+ - Insight permissions
47
+ - Associated discussion
48
+ ```
49
+
50
+ **Key Requirements:**
51
+ - Must be insight owner OR workspace administrator
52
+ - Insight ID must be valid
53
+ - Cannot be undone - all data permanently deleted
54
+ - Discussion associated with insight also deleted
55
+
56
+ ## Overview
57
+
58
+ The `remove_insight` tool permanently deletes an insight from your Hailer workspace. This is a **destructive operation** that removes both the insight definition and all associated data.
59
+
60
+ **Think of it as:**
61
+ - Dropping a database view
62
+ - Deleting a saved report
63
+ - Removing a SQL query definition
64
+ - Permanent deletion
65
+
66
+ **When to use:**
67
+ - Cleaning up test/development insights
68
+ - Removing obsolete or unused reports
69
+ - Deleting insights with incorrect queries
70
+ - Workspace reorganization
71
+ - Archiving completed analysis
72
+
73
+ **When NOT to use:**
74
+ - If you might need the query definition later (export first)
75
+ - If other users depend on the insight
76
+ - If you're unsure about usage
77
+ - For temporary deactivation (no such option exists)
78
+
79
+ ## What Gets Deleted
80
+
81
+ ### 1. Insight Definition
82
+ - Insight name and description
83
+ - SQL query text
84
+ - Source definitions (workflow mappings, field mappings)
85
+ - Insight configuration (public/private setting)
86
+ - Metadata (creator, creation date)
87
+
88
+ ### 2. Saved Query Results
89
+ - Cached result data (columns and rows)
90
+ - Last calculation timestamp
91
+ - Result statistics
92
+
93
+ ### 3. Insight Permissions
94
+ - Access control list
95
+ - Sharing settings
96
+ - Public access settings
97
+
98
+ ### 4. Associated Discussion
99
+ - Discussion thread linked to insight
100
+ - All messages in the discussion
101
+ - Message attachments
102
+ - Discussion participants list
103
+ - Read receipts and notifications
104
+
105
+ ### What Does NOT Get Deleted
106
+ - Source workflows (workflows remain intact)
107
+ - Activities in source workflows (data not affected)
108
+ - Users who accessed the insight
109
+ - External references to insight (links will break)
110
+ - Insights that reference same workflows (other insights unaffected)
111
+
112
+ ## Prerequisites
113
+
114
+ ### Required Permissions
115
+
116
+ **You can remove an insight if:**
117
+ - You are the insight creator/owner, OR
118
+ - You are a workspace administrator
119
+
120
+ **You CANNOT remove an insight if:**
121
+ - You are not the owner and not an admin
122
+ - You only have read access to the insight
123
+ - Insight was shared with you but you don't own it
124
+
125
+ **Check permissions:**
126
+ ```javascript
127
+ // List insights to see which you own
128
+ const insights = list_insights()
129
+ insights.forEach(i => {
130
+ console.log(`${i.name}: Owner=${i.owner}, You=${i.isOwner ? 'Owner' : 'Viewer'}`)
131
+ })
132
+ ```
133
+
134
+ ### Required Information
135
+
136
+ **1. Insight ID**
137
+
138
+ Get from `list_insights`:
139
+ ```javascript
140
+ const insights = list_insights()
141
+ insights.forEach(i => {
142
+ console.log(`${i.name}: ${i._id}`)
143
+ })
144
+ ```
145
+
146
+ **2. Verify Ownership**
147
+
148
+ Confirm you have permission:
149
+ ```javascript
150
+ const insights = list_insights()
151
+ const target = insights.find(i => i._id === 'target-id')
152
+
153
+ if (target.isOwner || target.isAdmin) {
154
+ console.log('✅ Can remove')
155
+ } else {
156
+ console.log('❌ Cannot remove - not owner or admin')
157
+ }
158
+ ```
159
+
160
+ ## Basic Usage
161
+
162
+ ### Example 1: Remove Simple Insight
163
+
164
+ ```javascript
165
+ // 1. Find the insight
166
+ const insights = list_insights()
167
+ const testInsight = insights.find(i => i.name === 'Test Report')
168
+ console.log('Found insight:', testInsight._id)
169
+
170
+ // 2. Remove it
171
+ remove_insight({
172
+ insightId: testInsight._id
173
+ })
174
+
175
+ // Output:
176
+ // ✅ Insight Removed Successfully
177
+ // Insight ID: 68446dc05b30685f67c6fcd4
178
+ // ⚠️ The insight has been permanently deleted.
179
+ ```
180
+
181
+ ### Example 2: Remove with Verification
182
+
183
+ ```javascript
184
+ // 1. List insights
185
+ const insights = list_insights()
186
+
187
+ // 2. Find target insight
188
+ const target = insights.find(i => i.name === 'Old Report')
189
+
190
+ // 3. Verify it's the right one
191
+ console.log('About to remove:')
192
+ console.log('- Name:', target.name)
193
+ console.log('- ID:', target._id)
194
+ console.log('- Created:', target.created)
195
+ console.log('- Public:', target.public)
196
+
197
+ // 4. Get one last look at data
198
+ const data = get_insight_data({
199
+ insightId: target._id
200
+ })
201
+ console.log('- Result rows:', data.rows.length)
202
+
203
+ // 5. Confirm and remove
204
+ const confirmed = true // Your confirmation logic
205
+ if (confirmed) {
206
+ remove_insight({
207
+ insightId: target._id
208
+ })
209
+ }
210
+ ```
211
+
212
+ ### Example 3: Batch Removal
213
+
214
+ ```javascript
215
+ // Remove multiple test insights
216
+
217
+ const insights = list_insights()
218
+
219
+ // Find all test insights
220
+ const testInsights = insights.filter(i =>
221
+ i.name.toLowerCase().includes('test') ||
222
+ i.name.toLowerCase().includes('demo')
223
+ )
224
+
225
+ console.log(`Found ${testInsights.length} test insights`)
226
+
227
+ // Remove each one
228
+ testInsights.forEach(insight => {
229
+ console.log(`Removing: ${insight.name}`)
230
+ remove_insight({
231
+ insightId: insight._id
232
+ })
233
+ })
234
+
235
+ console.log('✅ All test insights removed')
236
+ ```
237
+
238
+ ## ⚠️ MANDATORY: Comprehensive Confirmation Protocol
239
+
240
+ **BEFORE calling `remove_insight`, you MUST gather complete context and show it to the user:**
241
+
242
+ ### Required Context to Gather
243
+
244
+ 1. **Workspace Information:**
245
+ - Workspace ID: Get from API init or insight data
246
+ - Workspace name: Get from API init
247
+
248
+ 2. **Insight Information:**
249
+ - Insight ID (provided by user)
250
+ - Insight name: Get from `list_insights`
251
+ - SQL query: Get from `list_insights`
252
+ - Source workflows: Get from `list_insights` (sources array)
253
+ - Number of sources being queried
254
+
255
+ 3. **What Will Be Deleted:**
256
+ - Insight definition (sources, query, name)
257
+ - Saved query results
258
+ - Insight permissions
259
+ - Associated discussion
260
+
261
+ ### Required Confirmation Message Format
262
+
263
+ **You MUST display this information to the user BEFORE calling the tool:**
264
+
265
+ ```
266
+ ⚠️ WARNING: This action is irreversible!
267
+
268
+ You are about to permanently delete the following:
269
+
270
+ **Workspace**:
271
+ - Workspace ID: `<workspace-id>`
272
+ - Workspace name: <workspace-name>
273
+
274
+ **Insight to Delete**:
275
+ - Name: <insight-name>
276
+ - ID: `<insight-id>`
277
+
278
+ **What Will Be Deleted**:
279
+ - ❌ Insight definition (sources, query, name)
280
+ - ❌ Saved query results
281
+ - ❌ Insight permissions
282
+ - ❌ Associated discussion
283
+
284
+ **Sources Being Queried**:
285
+ - Workflow: <workflow-name-1>
286
+ - Workflow: <workflow-name-2>
287
+ (These workflows won't be affected, only this insight will be deleted)
288
+
289
+ **This operation cannot be undone. All data will be permanently lost.**
290
+
291
+ Do you want to proceed with permanently deleting this insight?
292
+ ```
293
+
294
+ ### Example: Complete Safe Removal Flow
295
+
296
+ ```javascript
297
+ // Step 1: Gather complete context
298
+ const insights = list_insights()
299
+ const targetInsight = insights.find(i => i._id === "target-id")
300
+ const workspaceName = "My Workspace" // From init or context
301
+
302
+ // Step 2: Get workflow names for sources
303
+ const sourceWorkflowNames = targetInsight.sources.map(s => s.name || s.workflowId)
304
+
305
+ // Step 3: Show comprehensive confirmation message to user
306
+ console.log(`
307
+ ⚠️ WARNING: This action is irreversible!
308
+
309
+ **Workspace**:
310
+ - Workspace ID: \`${workspaceId}\`
311
+ - Workspace name: ${workspaceName}
312
+
313
+ **Insight to Delete**:
314
+ - Name: ${targetInsight.name}
315
+ - ID: \`${targetInsight._id}\`
316
+
317
+ **What Will Be Deleted**:
318
+ - ❌ Insight definition (sources, query, name)
319
+ - ❌ Saved query results
320
+ - ❌ Insight permissions
321
+ - ❌ Associated discussion
322
+
323
+ **Sources Being Queried**:
324
+ ${sourceWorkflowNames.map(name => `- Workflow: ${name}`).join('\n')}
325
+
326
+ This operation cannot be undone.
327
+ `)
328
+
329
+ // Step 4: Wait for explicit user confirmation
330
+
331
+ // Step 5: Only after confirmation, call the tool
332
+ remove_insight({ insightId: targetInsight._id })
333
+ ```
334
+
335
+ ### **FAILURE TO GATHER AND SHOW THIS CONTEXT IS AN ERROR**
336
+
337
+ If you call `remove_insight` without first gathering and displaying all this information to the user, you are violating safety protocols.
338
+
339
+ ## Safety Checklist
340
+
341
+ **Before removing ANY insight, complete this checklist:**
342
+
343
+ ### Step 1: Identify the Insight
344
+ - [ ] Confirmed insight name with `list_insights`
345
+ - [ ] Verified insight ID is correct
346
+ - [ ] Reviewed insight query and sources
347
+ - [ ] Checked insight description/purpose
348
+
349
+ ### Step 2: Check Usage
350
+ - [ ] Verified no active users depend on this insight
351
+ - [ ] Checked if insight is embedded in apps
352
+ - [ ] Searched for references in documentation
353
+ - [ ] Confirmed insight not used in dashboards
354
+ - [ ] Asked team if insight is still needed
355
+
356
+ ### Step 3: Export Data (If Needed)
357
+ - [ ] Saved insight query definition
358
+ - [ ] Exported current data with `get_insight_data`
359
+ - [ ] Documented source workflows and field mappings
360
+ - [ ] Archived any important discussion messages
361
+
362
+ ### Step 4: Verify Permissions
363
+ - [ ] Confirmed you are owner or admin
364
+ - [ ] Checked insight ownership
365
+ - [ ] Verified no organizational policies prevent removal
366
+
367
+ ### Step 5: Consider Alternatives
368
+ - [ ] Considered duplicating before removing
369
+ - [ ] Evaluated updating query instead
370
+ - [ ] Checked if making private is better option
371
+ - [ ] Reviewed if insight can be archived differently
372
+
373
+ ### Step 6: Final Confirmation
374
+ - [ ] Double-checked insight ID one more time
375
+ - [ ] Confirmed this is the intended insight
376
+ - [ ] Accepted that this cannot be undone
377
+ - [ ] Ready to proceed with deletion
378
+
379
+ ## Common Scenarios
380
+
381
+ ### Scenario 1: Clean Up Test Insights
382
+
383
+ **Situation:** Created test insights during development.
384
+
385
+ ```javascript
386
+ // 1. List all insights
387
+ const insights = list_insights()
388
+
389
+ // 2. Identify test insights
390
+ const testInsights = insights.filter(i =>
391
+ i.name.startsWith('Test -') ||
392
+ i.name.includes('[TEST]') ||
393
+ i.name.includes('Demo')
394
+ )
395
+
396
+ console.log(`Found ${testInsights.length} test insights:`)
397
+ testInsights.forEach(i => console.log(`- ${i.name}`))
398
+
399
+ // 3. Remove each test insight
400
+ testInsights.forEach(insight => {
401
+ remove_insight({ insightId: insight._id })
402
+ console.log(`✅ Removed: ${insight.name}`)
403
+ })
404
+ ```
405
+
406
+ ### Scenario 2: Replace Insight with Improved Version
407
+
408
+ **Situation:** Created new insight to replace old one.
409
+
410
+ ```javascript
411
+ // 1. Create new insight
412
+ const newInsight = create_insight({
413
+ name: 'Tasks Report v2',
414
+ sources: [...], // Improved query
415
+ query: '...'
416
+ })
417
+
418
+ // 2. Verify new insight works
419
+ const data = get_insight_data({
420
+ insightId: newInsight.insightId,
421
+ update: true
422
+ })
423
+ console.log(`✅ New insight works: ${data.rows.length} rows`)
424
+
425
+ // 3. Find old insight
426
+ const insights = list_insights()
427
+ const oldInsight = insights.find(i => i.name === 'Tasks Report v1')
428
+
429
+ // 4. Remove old version
430
+ remove_insight({
431
+ insightId: oldInsight._id
432
+ })
433
+ ```
434
+
435
+ ### Scenario 3: Remove Broken Insight
436
+
437
+ **Situation:** Insight has SQL errors or references deleted workflows.
438
+
439
+ ```javascript
440
+ // 1. Try to get data (will fail)
441
+ try {
442
+ get_insight_data({ insightId: 'broken-insight-id' })
443
+ } catch (error) {
444
+ console.log('❌ Insight is broken:', error.message)
445
+ }
446
+
447
+ // 2. Try to preview (check if fixable)
448
+ try {
449
+ preview_insight({
450
+ sources: brokenInsight.sources,
451
+ query: brokenInsight.query
452
+ })
453
+ } catch (error) {
454
+ console.log('❌ Query cannot be fixed:', error.message)
455
+ }
456
+
457
+ // 3. Remove broken insight
458
+ remove_insight({
459
+ insightId: 'broken-insight-id'
460
+ })
461
+ console.log('✅ Removed broken insight')
462
+ ```
463
+
464
+ ### Scenario 4: Remove Unused Insights
465
+
466
+ **Situation:** Insights exist but no longer used.
467
+
468
+ ```javascript
469
+ // 1. List all insights
470
+ const insights = list_insights()
471
+
472
+ // 2. Check each insight's last update
473
+ insights.forEach(insight => {
474
+ const lastUpdate = new Date(insight.lastCalculated)
475
+ const daysSinceUpdate = (Date.now() - lastUpdate) / 1000 / 60 / 60 / 24
476
+
477
+ console.log(`${insight.name}: ${daysSinceUpdate.toFixed(0)} days old`)
478
+
479
+ // 3. Remove if very old (e.g., > 90 days)
480
+ if (daysSinceUpdate > 90) {
481
+ console.log(` ⚠️ Very old, consider removing`)
482
+ }
483
+ })
484
+
485
+ // 4. Remove confirmed unused insights
486
+ const unusedInsights = ['id1', 'id2', 'id3']
487
+ unusedInsights.forEach(id => {
488
+ remove_insight({ insightId: id })
489
+ })
490
+ ```
491
+
492
+ ### Scenario 5: Remove After Workflow Deletion
493
+
494
+ **Situation:** Source workflow deleted, insight no longer works.
495
+
496
+ ```javascript
497
+ // Workflow was deleted, insights referencing it are now broken
498
+
499
+ // 1. Find insights referencing deleted workflow
500
+ const insights = list_insights()
501
+ const brokenInsights = insights.filter(i =>
502
+ i.sources.some(s => s.workflowId === 'deleted-workflow-id')
503
+ )
504
+
505
+ console.log(`Found ${brokenInsights.length} broken insights`)
506
+
507
+ // 2. Remove broken insights
508
+ brokenInsights.forEach(insight => {
509
+ console.log(`Removing broken insight: ${insight.name}`)
510
+ remove_insight({ insightId: insight._id })
511
+ })
512
+ ```
513
+
514
+ ## Before Removing
515
+
516
+ ### Export Insight Definition
517
+
518
+ **Save query and sources:**
519
+ ```javascript
520
+ const insights = list_insights()
521
+ const target = insights.find(i => i._id === 'target-id')
522
+
523
+ // Save insight definition
524
+ const backup = {
525
+ name: target.name,
526
+ description: target.description,
527
+ public: target.public,
528
+ sources: target.sources,
529
+ query: target.query,
530
+ exportDate: new Date().toISOString()
531
+ }
532
+
533
+ console.log('Insight backup:')
534
+ console.log(JSON.stringify(backup, null, 2))
535
+
536
+ // Save to file or external storage
537
+ // saveToFile('insight-backup.json', JSON.stringify(backup, null, 2))
538
+ ```
539
+
540
+ ### Export Current Data
541
+
542
+ **Save insight results:**
543
+ ```javascript
544
+ const data = get_insight_data({
545
+ insightId: 'target-id',
546
+ update: true // Get fresh data
547
+ })
548
+
549
+ // Convert to objects
550
+ const records = data.rows.map(row => {
551
+ const obj = {}
552
+ data.columns.forEach((col, i) => {
553
+ obj[col] = row[i]
554
+ })
555
+ return obj
556
+ })
557
+
558
+ // Save data
559
+ console.log(JSON.stringify(records, null, 2))
560
+ // saveToFile('insight-data.json', JSON.stringify(records, null, 2))
561
+ ```
562
+
563
+ ### Check Dependencies
564
+
565
+ **Find if insight is used elsewhere:**
566
+ ```javascript
567
+ // 1. Check if insight is public (might be shared)
568
+ const insights = list_insights()
569
+ const target = insights.find(i => i._id === 'target-id')
570
+
571
+ if (target.public) {
572
+ console.warn('⚠️ This insight is PUBLIC - may have external users')
573
+ }
574
+
575
+ // 2. Check if insight has discussion
576
+ if (target.discussion) {
577
+ console.warn('⚠️ Insight has discussion thread - will be deleted')
578
+ }
579
+
580
+ // 3. Document usage
581
+ console.log('Insight usage check:')
582
+ console.log('- Public:', target.public)
583
+ console.log('- Created:', target.created)
584
+ console.log('- Last calculated:', target.lastCalculated)
585
+ ```
586
+
587
+ ## After Removing
588
+
589
+ ### Verify Removal
590
+
591
+ ```javascript
592
+ // 1. Remove insight
593
+ remove_insight({ insightId: 'removed-id' })
594
+
595
+ // 2. Verify it's gone
596
+ const insights = list_insights()
597
+ const stillExists = insights.find(i => i._id === 'removed-id')
598
+
599
+ if (stillExists) {
600
+ console.error('❌ Insight still exists!')
601
+ } else {
602
+ console.log('✅ Insight successfully removed')
603
+ }
604
+
605
+ // 3. Try to access (should fail)
606
+ try {
607
+ get_insight_data({ insightId: 'removed-id' })
608
+ console.error('❌ Can still access insight!')
609
+ } catch (error) {
610
+ console.log('✅ Insight not accessible (expected)')
611
+ }
612
+ ```
613
+
614
+ ### Update Documentation
615
+
616
+ After removing insights:
617
+ - Update workspace documentation
618
+ - Remove insight references from guides
619
+ - Update team training materials
620
+ - Archive insight specifications
621
+ - Document removal reason and date
622
+
623
+ ### Clean Up Related Resources
624
+
625
+ **Remove references:**
626
+ ```javascript
627
+ // Update apps that referenced the insight
628
+ // Remove dashboard widgets showing the insight
629
+ // Update scheduled reports
630
+ // Notify users who used the insight
631
+ ```
632
+
633
+ ## Best Practices
634
+
635
+ ### 1. Always Verify Before Removing
636
+
637
+ **Bad:**
638
+ ```javascript
639
+ // Removed without checking
640
+ remove_insight({ insightId: 'some-id' })
641
+ ```
642
+
643
+ **Good:**
644
+ ```javascript
645
+ // 1. Verify insight exists and ownership
646
+ const insights = list_insights()
647
+ const target = insights.find(i => i._id === 'some-id')
648
+
649
+ if (!target) {
650
+ console.error('Insight not found')
651
+ return
652
+ }
653
+
654
+ console.log('About to remove:', target.name)
655
+ console.log('Owner:', target.isOwner ? 'You' : 'Someone else')
656
+
657
+ // 2. Confirm and remove
658
+ if (target.isOwner) {
659
+ remove_insight({ insightId: target._id })
660
+ } else {
661
+ console.error('Cannot remove - not owner')
662
+ }
663
+ ```
664
+
665
+ ### 2. Export Before Removing
666
+
667
+ **Always backup important insights:**
668
+ ```javascript
669
+ // 1. Export definition
670
+ const insights = list_insights()
671
+ const target = insights.find(i => i._id === 'target-id')
672
+ const definition = {
673
+ name: target.name,
674
+ sources: target.sources,
675
+ query: target.query
676
+ }
677
+ console.log('Backup:', JSON.stringify(definition, null, 2))
678
+
679
+ // 2. Export data
680
+ const data = get_insight_data({ insightId: target._id })
681
+ console.log(`Backing up ${data.rows.length} rows`)
682
+
683
+ // 3. Then remove
684
+ remove_insight({ insightId: target._id })
685
+ ```
686
+
687
+ ### 3. Use Descriptive Insight Names
688
+
689
+ Makes identification easier:
690
+ - ✅ "High Priority Tasks - Dec 2024"
691
+ - ✅ "Test - Can Delete - Daily Report"
692
+ - ✅ "DEPRECATED - Old Budget Report"
693
+ - ❌ "Report 1"
694
+ - ❌ "Query"
695
+
696
+ ### 4. Remove Test Insights Promptly
697
+
698
+ Don't let test insights accumulate:
699
+ ```javascript
700
+ // Regular cleanup schedule
701
+ function cleanupTestInsights() {
702
+ const insights = list_insights()
703
+ const testInsights = insights.filter(i =>
704
+ i.name.toLowerCase().includes('test') ||
705
+ i.name.toLowerCase().includes('demo') ||
706
+ i.name.startsWith('TMP -')
707
+ )
708
+
709
+ testInsights.forEach(i => {
710
+ remove_insight({ insightId: i._id })
711
+ console.log(`Removed test insight: ${i.name}`)
712
+ })
713
+ }
714
+ ```
715
+
716
+ ### 5. Communicate Before Removing
717
+
718
+ **Notify team before removing shared insights:**
719
+ - Send message in workspace discussion
720
+ - Post in relevant channels
721
+ - Update documentation
722
+ - Provide migration path if replacing insight
723
+
724
+ ### 6. Consider Duplicating First
725
+
726
+ **If unsure, duplicate before removing:**
727
+ ```javascript
728
+ // 1. Get insight definition
729
+ const insights = list_insights()
730
+ const original = insights.find(i => i._id === 'original-id')
731
+
732
+ // 2. Create copy with different name
733
+ create_insight({
734
+ name: original.name + ' - Archive',
735
+ sources: original.sources,
736
+ query: original.query,
737
+ public: false // Make archive private
738
+ })
739
+
740
+ // 3. Later remove original if archive works
741
+ // remove_insight({ insightId: 'original-id' })
742
+ ```
743
+
744
+ ### 7. Document Removal
745
+
746
+ Keep audit trail:
747
+ ```javascript
748
+ console.log({
749
+ action: 'remove_insight',
750
+ insightId: 'insight-id',
751
+ insightName: 'Report Name',
752
+ reason: 'Replaced by v2',
753
+ date: new Date().toISOString(),
754
+ removedBy: 'user-id'
755
+ })
756
+ ```
757
+
758
+ ### 8. Handle Broken Insights
759
+
760
+ **Remove insights that reference deleted workflows:**
761
+ ```javascript
762
+ // After deleting workflow, clean up insights
763
+ const deletedWorkflowId = 'deleted-workflow-id'
764
+
765
+ const insights = list_insights()
766
+ const brokenInsights = insights.filter(i =>
767
+ i.sources.some(s => s.workflowId === deletedWorkflowId)
768
+ )
769
+
770
+ console.log(`Found ${brokenInsights.length} broken insights`)
771
+ brokenInsights.forEach(i => {
772
+ console.log(`Removing: ${i.name}`)
773
+ remove_insight({ insightId: i._id })
774
+ })
775
+ ```
776
+
777
+ ## Troubleshooting
778
+
779
+ ### Error: "Insight Not Found"
780
+
781
+ **Cause:** Invalid insight ID or insight already deleted.
782
+
783
+ **Solution:**
784
+
785
+ ```javascript
786
+ // 1. List insights to verify
787
+ const insights = list_insights()
788
+ console.log('Available insights:')
789
+ insights.forEach(i => {
790
+ console.log(`- ${i.name}: ${i._id}`)
791
+ })
792
+
793
+ // 2. Use correct ID
794
+ remove_insight({ insightId: 'correct-id' })
795
+ ```
796
+
797
+ ### Error: "Permission Denied"
798
+
799
+ **Cause:** Not insight owner or workspace admin.
800
+
801
+ **Solutions:**
802
+
803
+ 1. **Check ownership:**
804
+ ```javascript
805
+ const insights = list_insights()
806
+ const target = insights.find(i => i._id === 'target-id')
807
+
808
+ console.log('Owner:', target.owner)
809
+ console.log('You are owner:', target.isOwner)
810
+ console.log('You are admin:', target.isAdmin)
811
+ ```
812
+
813
+ 2. **Request removal from owner/admin**
814
+ 3. **Contact workspace administrator**
815
+
816
+ ### Insight Removed But Still Appears
817
+
818
+ **Cause:** Cache not updated.
819
+
820
+ **Solution:**
821
+
822
+ ```javascript
823
+ // Refresh insight list
824
+ const insights = list_insights()
825
+
826
+ // Verify removal
827
+ const stillExists = insights.find(i => i._id === 'removed-id')
828
+ console.log('Still exists:', !!stillExists)
829
+ ```
830
+
831
+ ### Accidentally Removed Wrong Insight
832
+
833
+ **Reality Check:** **Cannot be undone.**
834
+
835
+ **Mitigation:**
836
+
837
+ 1. **If you have backup:**
838
+ ```javascript
839
+ // Recreate from backup
840
+ create_insight({
841
+ name: backup.name,
842
+ sources: backup.sources,
843
+ query: backup.query
844
+ })
845
+ // Note: Will have different ID
846
+ ```
847
+
848
+ 2. **If no backup:**
849
+ - Data is permanently lost
850
+ - Contact Hailer support (may have database backups)
851
+ - Implement backup procedures for future
852
+
853
+ 3. **Prevention:**
854
+ - Always verify insight ID before removing
855
+ - Use descriptive insight names
856
+ - Export definitions before removal
857
+ - Test in development workspace first
858
+
859
+ ### Can't Find Insight to Remove
860
+
861
+ **Cause:** Insight in different workspace or already removed.
862
+
863
+ **Solution:**
864
+
865
+ ```javascript
866
+ // 1. Check current workspace
867
+ const workspace = get_current_workspace()
868
+ console.log('Current workspace:', workspace.name)
869
+
870
+ // 2. List insights in this workspace
871
+ const insights = list_insights()
872
+ console.log(`Found ${insights.length} insights`)
873
+
874
+ // 3. Search by name
875
+ const target = insights.find(i =>
876
+ i.name.toLowerCase().includes('search term')
877
+ )
878
+
879
+ if (target) {
880
+ console.log('Found:', target._id)
881
+ } else {
882
+ console.log('Not found in current workspace')
883
+ }
884
+ ```
885
+
886
+ ## Integration with Other Tools
887
+
888
+ ### With create_insight
889
+
890
+ Replace pattern:
891
+
892
+ ```javascript
893
+ // 1. Create new version
894
+ const newInsight = create_insight({
895
+ name: 'Report v2',
896
+ sources: [...],
897
+ query: '...'
898
+ })
899
+
900
+ // 2. Verify it works
901
+ const data = get_insight_data({
902
+ insightId: newInsight.insightId
903
+ })
904
+ console.log(`✅ New insight: ${data.rows.length} rows`)
905
+
906
+ // 3. Remove old version
907
+ remove_insight({ insightId: 'old-version-id' })
908
+ ```
909
+
910
+ ### With list_insights
911
+
912
+ Find and remove:
913
+
914
+ ```javascript
915
+ // 1. List insights
916
+ const insights = list_insights()
917
+
918
+ // 2. Find by name
919
+ const target = insights.find(i => i.name === 'Old Report')
920
+
921
+ // 3. Remove
922
+ if (target) {
923
+ remove_insight({ insightId: target._id })
924
+ } else {
925
+ console.log('Insight not found')
926
+ }
927
+ ```
928
+
929
+ ### With get_insight_data
930
+
931
+ Backup before removal:
932
+
933
+ ```javascript
934
+ // 1. Get data
935
+ const data = get_insight_data({
936
+ insightId: 'target-id',
937
+ update: true
938
+ })
939
+
940
+ // 2. Save data
941
+ console.log(`Backing up ${data.rows.length} rows`)
942
+ const backup = JSON.stringify(data, null, 2)
943
+
944
+ // 3. Remove insight
945
+ remove_insight({ insightId: 'target-id' })
946
+ ```
947
+
948
+ ### With preview_insight
949
+
950
+ Test before recreating:
951
+
952
+ ```javascript
953
+ // 1. Get insight definition before removal
954
+ const insights = list_insights()
955
+ const target = insights.find(i => i._id === 'target-id')
956
+
957
+ // 2. Export definition
958
+ const definition = {
959
+ sources: target.sources,
960
+ query: target.query
961
+ }
962
+
963
+ // 3. Remove insight
964
+ remove_insight({ insightId: target._id })
965
+
966
+ // 4. Later, test if you want to recreate
967
+ preview_insight({
968
+ sources: definition.sources,
969
+ query: definition.query
970
+ })
971
+
972
+ // 5. Recreate if test succeeds
973
+ create_insight({
974
+ name: 'Recreated Report',
975
+ sources: definition.sources,
976
+ query: definition.query
977
+ })
978
+ ```
979
+
980
+ ## Summary
981
+
982
+ **Key Takeaways:**
983
+ 1. ⚠️ **Permanent deletion** - Cannot be undone
984
+ 2. 🔒 **Owner or admin only** - Permission required
985
+ 3. 🗑️ **Complete removal** - Definition, data, discussion deleted
986
+ 4. 💾 **Export first** - Backup important insights
987
+ 5. ✅ **Verify twice** - Double-check insight ID
988
+ 6. 📢 **Communicate** - Inform users before removing shared insights
989
+ 7. 🔄 **Consider alternatives** - Duplicate or update instead of remove
990
+
991
+ **Quick Decision Tree:**
992
+
993
+ ```
994
+ Need to remove insight?
995
+
996
+ ├─ Contains important data? → Export first, then remove
997
+ ├─ Used by others? → Notify team first, then remove
998
+ ├─ Might need later? → Duplicate before removing
999
+ ├─ Test/demo insight? → Remove immediately
1000
+ ├─ Broken/outdated? → Remove after documenting reason
1001
+ └─ Sure about removal? → Verify ID and remove
1002
+ ```
1003
+
1004
+ ## Additional Resources
1005
+
1006
+ - See `create-insight-skill` for creating insights
1007
+ - See `preview-insight-skill` for testing queries
1008
+ - See `get-insight-data-skill` for executing insights
1009
+ - See `insight-api` skill for comprehensive Insight API documentation
1010
+ - Use `list_insights` to view all insights
1011
+ - Use `get_insight_data` to backup data before removal