@hailer/mcp 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/.claude/agents/ada.md +127 -0
  2. package/.claude/agents/agent-builder.md +151 -0
  3. package/.claude/agents/alejandro.md +66 -0
  4. package/.claude/agents/bjorn.md +305 -0
  5. package/.claude/agents/dmitri.md +61 -0
  6. package/.claude/agents/giuseppe.md +66 -0
  7. package/.claude/agents/gunther.md +355 -0
  8. package/.claude/agents/helga.md +68 -0
  9. package/.claude/agents/kenji.md +58 -0
  10. package/.claude/agents/svetlana.md +394 -0
  11. package/.claude/agents/viktor.md +63 -0
  12. package/.claude/agents/yevgeni.md +60 -0
  13. package/.claude/hooks/agent-failure-detector.cjs +286 -0
  14. package/.claude/hooks/app-edit-guard.cjs +462 -0
  15. package/.claude/hooks/interactive-mode.cjs +59 -0
  16. package/.claude/hooks/mcp-server-guard.cjs +92 -0
  17. package/.claude/hooks/post-scaffold-hook.cjs +31 -0
  18. package/.claude/hooks/src-edit-guard.cjs +208 -0
  19. package/.claude/settings.json +47 -2
  20. package/.claude/skills/insight-join-patterns/SKILL.md +209 -0
  21. package/.env.example +13 -1
  22. package/CLAUDE.md +134 -0
  23. package/dist/app.js +4 -3
  24. package/dist/cli.js +0 -0
  25. package/dist/client/adaptive-documentation-bot.d.ts +0 -2
  26. package/dist/client/adaptive-documentation-bot.js +5 -16
  27. package/dist/client/message-processor.js +5 -0
  28. package/dist/client/providers/anthropic-provider.js +21 -7
  29. package/dist/mcp/UserContextCache.d.ts +14 -0
  30. package/dist/mcp/UserContextCache.js +49 -24
  31. package/dist/mcp/auth.d.ts +7 -0
  32. package/dist/mcp/auth.js +13 -5
  33. package/dist/mcp/hailer-clients.d.ts +5 -2
  34. package/dist/mcp/signal-handler.d.ts +28 -2
  35. package/dist/mcp/signal-handler.js +4 -2
  36. package/dist/mcp/tool-registry.d.ts +55 -2
  37. package/dist/mcp/tool-registry.js +197 -2
  38. package/dist/mcp/tools/app-core.d.ts +15 -0
  39. package/dist/mcp/tools/app-core.js +609 -0
  40. package/dist/mcp/tools/app-marketplace.d.ts +21 -0
  41. package/dist/mcp/tools/app-marketplace.js +1284 -0
  42. package/dist/mcp/tools/app-member.d.ts +11 -0
  43. package/dist/mcp/tools/app-member.js +258 -0
  44. package/dist/mcp/tools/app-scaffold.d.ts +11 -0
  45. package/dist/mcp/tools/app-scaffold.js +743 -0
  46. package/dist/mcp/tools/app.d.ts +13 -22
  47. package/dist/mcp/tools/app.js +17 -2466
  48. package/dist/mcp/tools/file.js +6 -6
  49. package/dist/mcp/tools/insight.d.ts +1 -0
  50. package/dist/mcp/tools/insight.js +203 -64
  51. package/dist/mcp/tools/user.js +3 -9
  52. package/dist/mcp/tools/workflow.js +49 -38
  53. package/dist/mcp/utils/hailer-api-client.js +4 -13
  54. package/dist/mcp/utils/tool-helpers.d.ts +102 -0
  55. package/dist/mcp/utils/tool-helpers.js +179 -0
  56. package/dist/mcp/utils/types.d.ts +6 -0
  57. package/dist/mcp/workspace-cache.d.ts +5 -5
  58. package/dist/mcp/workspace-cache.js +4 -3
  59. package/package.json +1 -1
  60. package/.claude/hooks/PreToolUse.sh +0 -52
  61. package/.claude/hooks/prompt-skill-loader.cjs +0 -553
  62. package/.claude/hooks/skill-loader.cjs +0 -142
  63. package/.claude/settings.local.json +0 -49
  64. package/.claude/skills/MCP-add-app-member-skill/SKILL.md +0 -977
  65. package/.claude/skills/MCP-build-data-app-skill/SKILL.md +0 -372
  66. package/.claude/skills/MCP-create-app-skill/SKILL.md +0 -1101
  67. package/.claude/skills/MCP-create-insight-skill/SKILL.md +0 -1317
  68. package/.claude/skills/MCP-get-insight-data-skill/SKILL.md +0 -1053
  69. package/.claude/skills/MCP-insight-api/SKILL.md +0 -185
  70. package/.claude/skills/MCP-insight-api/references/insight-endpoints.md +0 -514
  71. package/.claude/skills/MCP-install-workflow-skill/SKILL.md +0 -1056
  72. package/.claude/skills/MCP-list-apps-skill/SKILL.md +0 -1010
  73. package/.claude/skills/MCP-list-workflows-minimal-skill/SKILL.md +0 -992
  74. package/.claude/skills/MCP-local-first-skill/SKILL.md +0 -570
  75. package/.claude/skills/MCP-populate-workflow-data-skill/SKILL.md +0 -395
  76. package/.claude/skills/MCP-preview-insight-skill/SKILL.md +0 -1290
  77. package/.claude/skills/MCP-publish-hailer-app-skill/SKILL.md +0 -453
  78. package/.claude/skills/MCP-publish-template-skill/SKILL.md +0 -278
  79. package/.claude/skills/MCP-remove-app-member-skill/SKILL.md +0 -671
  80. package/.claude/skills/MCP-remove-app-skill/SKILL.md +0 -985
  81. package/.claude/skills/MCP-remove-insight-skill/SKILL.md +0 -1011
  82. package/.claude/skills/MCP-remove-workflow-skill/SKILL.md +0 -920
  83. package/.claude/skills/MCP-scaffold-hailer-app-skill/SKILL.md +0 -1237
  84. package/.claude/skills/MCP-update-app-skill/SKILL.md +0 -970
  85. package/.claude/skills/MCP-update-workflow-field-skill/SKILL.md +0 -1098
  86. package/.claude/skills/SDK-create-function-field-skill/SKILL.md +0 -313
  87. package/.claude/skills/SDK-generate-skill/SKILL.md +0 -223
  88. package/.claude/skills/SDK-init-skill/SKILL.md +0 -177
  89. package/.claude/skills/SDK-workspace-setup-skill/SKILL.md +0 -605
  90. package/.claude/skills/SDK-ws-config-skill/SKILL.md +0 -435
  91. package/.claude/skills/activity-api/SKILL.md +0 -96
  92. package/.claude/skills/activity-api/references/activity-endpoints.md +0 -845
  93. package/.claude/skills/agent-building/SKILL.md +0 -243
  94. package/.claude/skills/agent-building/references/architecture-patterns.md +0 -446
  95. package/.claude/skills/agent-building/references/code-examples.md +0 -587
  96. package/.claude/skills/agent-building/references/implementation-guide.md +0 -619
  97. package/.claude/skills/app-api/SKILL.md +0 -219
  98. package/.claude/skills/app-api/references/app-endpoints.md +0 -759
  99. package/.claude/skills/building-hailer-apps-skill/SKILL.md +0 -813
  100. package/.claude/skills/hailer-api/SKILL.md +0 -283
  101. package/.claude/skills/hailer-api/references/activities.md +0 -620
  102. package/.claude/skills/hailer-api/references/authentication.md +0 -216
  103. package/.claude/skills/hailer-api/references/datasets.md +0 -437
  104. package/.claude/skills/hailer-api/references/files.md +0 -301
  105. package/.claude/skills/hailer-api/references/insights.md +0 -469
  106. package/.claude/skills/hailer-api/references/workflows.md +0 -720
  107. package/.claude/skills/hailer-api/references/workspaces-users.md +0 -445
  108. package/.claude/skills/hailer-app-builder/SKILL.md +0 -340
  109. package/.claude/skills/mcp-tools/SKILL.md +0 -419
  110. package/.claude/skills/mcp-tools/references/api-endpoints.md +0 -499
  111. package/.claude/skills/mcp-tools/references/data-structures.md +0 -554
  112. package/.claude/skills/mcp-tools/references/implementation-patterns.md +0 -717
  113. package/.claude/skills/skill-testing/README.md +0 -137
  114. package/.claude/skills/skill-testing/SKILL.md +0 -348
  115. package/.claude/skills/skill-testing/references/test-patterns.md +0 -705
  116. package/.claude/skills/skill-testing/references/testing-guide.md +0 -603
  117. package/.claude/skills/skill-testing/references/validation-checklist.md +0 -537
  118. package/.claude/skills/spawn-app-builder/SKILL.md +0 -366
  119. package/.claude/skills/tool-builder/SKILL.md +0 -328
  120. package/tsconfig.json +0 -23
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Agent Failure Detector Hook
4
+ *
5
+ * PostToolUse hook for Task tool - detects agent failures, categorizes them,
6
+ * and suggests appropriate fixes (skill creation vs agent update).
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const os = require('os');
12
+
13
+ const TRACKER_FILE = path.join(os.tmpdir(), '.claude-agent-failures.json');
14
+ const FAILURE_THRESHOLD = 2;
15
+
16
+ let input = '';
17
+ process.stdin.setEncoding('utf8');
18
+ process.stdin.on('data', chunk => input += chunk);
19
+ process.stdin.on('end', () => {
20
+ try {
21
+ const data = JSON.parse(input);
22
+ processHook(data);
23
+ } catch {
24
+ process.exit(0);
25
+ }
26
+ });
27
+
28
+ function loadTracker() {
29
+ try {
30
+ if (fs.existsSync(TRACKER_FILE)) {
31
+ return JSON.parse(fs.readFileSync(TRACKER_FILE, 'utf8'));
32
+ }
33
+ } catch {}
34
+ return { failures: {}, prompted: {}, errorTypes: {} };
35
+ }
36
+
37
+ function saveTracker(tracker) {
38
+ fs.writeFileSync(TRACKER_FILE, JSON.stringify(tracker, null, 2));
39
+ }
40
+
41
+ // Error categorization - determines fix type
42
+ const ERROR_CATEGORIES = {
43
+ // API/Schema errors -> Create skill (reusable knowledge)
44
+ skill: {
45
+ patterns: [
46
+ 'validation error',
47
+ 'invalid field',
48
+ 'schema',
49
+ 'required parameter',
50
+ 'type mismatch',
51
+ 'format error',
52
+ 'join syntax',
53
+ 'sql error',
54
+ 'query error',
55
+ 'activitylink',
56
+ 'workflow.*not found',
57
+ 'phase.*not found',
58
+ 'field.*not found'
59
+ ],
60
+ suggestion: 'Create a skill documenting the correct pattern',
61
+ action: 'create_skill'
62
+ },
63
+ // Agent behavior errors -> Update agent
64
+ agent: {
65
+ patterns: [
66
+ 'wrong approach',
67
+ 'misunderstood',
68
+ 'incorrect assumption',
69
+ 'should have',
70
+ 'forgot to',
71
+ 'didn\'t check',
72
+ 'missing context',
73
+ 'needs to first',
74
+ 'order of operations'
75
+ ],
76
+ suggestion: 'Update agent definition with better instructions',
77
+ action: 'update_agent'
78
+ },
79
+ // Permission/Auth errors -> Neither (user issue)
80
+ user_issue: {
81
+ patterns: [
82
+ 'permission denied',
83
+ 'unauthorized',
84
+ 'access denied',
85
+ 'not allowed',
86
+ 'admin required'
87
+ ],
88
+ suggestion: 'User permission issue - not an agent problem',
89
+ action: 'ignore'
90
+ },
91
+ // Connection/Transient errors -> Neither (retry)
92
+ transient: {
93
+ patterns: [
94
+ 'timeout',
95
+ 'connection',
96
+ 'network',
97
+ 'unavailable',
98
+ 'try again',
99
+ 'rate limit'
100
+ ],
101
+ suggestion: 'Transient error - retry may work',
102
+ action: 'ignore'
103
+ }
104
+ };
105
+
106
+ function categorizeError(responseText) {
107
+ const lower = responseText.toLowerCase();
108
+
109
+ for (const [category, config] of Object.entries(ERROR_CATEGORIES)) {
110
+ for (const pattern of config.patterns) {
111
+ const regex = new RegExp(pattern, 'i');
112
+ if (regex.test(lower)) {
113
+ return {
114
+ category,
115
+ ...config,
116
+ matchedPattern: pattern
117
+ };
118
+ }
119
+ }
120
+ }
121
+
122
+ // Default: likely needs skill (documentation)
123
+ return {
124
+ category: 'unknown',
125
+ suggestion: 'Analyze error to determine fix type',
126
+ action: 'analyze'
127
+ };
128
+ }
129
+
130
+ function detectFailure(responseText) {
131
+ const lower = responseText.toLowerCase();
132
+ const failurePatterns = [
133
+ '"status":"error"',
134
+ '"status": "error"',
135
+ 'failed to',
136
+ 'error:',
137
+ 'could not',
138
+ 'unable to',
139
+ 'invalid',
140
+ 'not found',
141
+ 'exception'
142
+ ];
143
+
144
+ for (const pattern of failurePatterns) {
145
+ if (lower.includes(pattern)) {
146
+ return true;
147
+ }
148
+ }
149
+ return false;
150
+ }
151
+
152
+ function extractErrorMessage(responseText) {
153
+ // Try to extract meaningful error message
154
+ const patterns = [
155
+ /"error":\s*"([^"]+)"/i,
156
+ /"message":\s*"([^"]+)"/i,
157
+ /Error:\s*([^\n]+)/i,
158
+ /failed to ([^\n.]+)/i
159
+ ];
160
+
161
+ for (const pattern of patterns) {
162
+ const match = responseText.match(pattern);
163
+ if (match) {
164
+ return match[1].substring(0, 100); // Limit length
165
+ }
166
+ }
167
+
168
+ return 'Unknown error';
169
+ }
170
+
171
+ function processHook(data) {
172
+ const { tool_name, tool_input, tool_response } = data;
173
+
174
+ if (tool_name !== 'Task') {
175
+ process.exit(0);
176
+ }
177
+
178
+ const agentName = tool_input?.subagent_type;
179
+ if (!agentName || agentName === 'ada') {
180
+ process.exit(0);
181
+ }
182
+
183
+ const responseText = typeof tool_response === 'string'
184
+ ? tool_response
185
+ : JSON.stringify(tool_response || '');
186
+
187
+ if (!detectFailure(responseText)) {
188
+ process.exit(0);
189
+ }
190
+
191
+ // Categorize the error
192
+ const errorInfo = categorizeError(responseText);
193
+ const errorMessage = extractErrorMessage(responseText);
194
+
195
+ // Skip if it's a user issue or transient
196
+ if (errorInfo.action === 'ignore') {
197
+ process.exit(0);
198
+ }
199
+
200
+ // Track the failure with category
201
+ const tracker = loadTracker();
202
+ const key = `${agentName}:${errorInfo.category}`;
203
+ tracker.failures[key] = (tracker.failures[key] || 0) + 1;
204
+ tracker.errorTypes[key] = errorInfo;
205
+ saveTracker(tracker);
206
+
207
+ const failureCount = tracker.failures[key];
208
+
209
+ if (failureCount >= FAILURE_THRESHOLD && !tracker.prompted[key]) {
210
+ tracker.prompted[key] = true;
211
+ saveTracker(tracker);
212
+
213
+ // Build suggestion based on category
214
+ let fixOptions;
215
+ let recommendation;
216
+
217
+ if (errorInfo.action === 'create_skill') {
218
+ recommendation = `📚 RECOMMENDED: Create a skill to document this pattern`;
219
+ fixOptions = [
220
+ { label: 'Create skill', description: `Ada creates docs/skills/ entry for ${errorInfo.matchedPattern || 'this pattern'}` },
221
+ { label: 'Update agent instead', description: `Add knowledge directly to ${agentName}'s definition` },
222
+ { label: 'Ignore', description: 'Continue without changes' }
223
+ ];
224
+ } else if (errorInfo.action === 'update_agent') {
225
+ recommendation = `🤖 RECOMMENDED: Update ${agentName}'s agent definition`;
226
+ fixOptions = [
227
+ { label: 'Update agent', description: `Ada adds better instructions to ${agentName}.md` },
228
+ { label: 'Create skill instead', description: 'Document as reusable skill for all agents' },
229
+ { label: 'Ignore', description: 'Continue without changes' }
230
+ ];
231
+ } else {
232
+ recommendation = `🔍 ANALYZE: Let Ada determine the best fix`;
233
+ fixOptions = [
234
+ { label: 'Let Ada analyze', description: 'Ada will determine if skill or agent update is better' },
235
+ { label: 'Ignore', description: 'Continue without changes' }
236
+ ];
237
+ }
238
+
239
+ const output = `
240
+ ${'='.repeat(60)}
241
+ 🔧 AGENT IMPROVEMENT SUGGESTION
242
+ ${'='.repeat(60)}
243
+
244
+ Agent "${agentName}" has failed ${failureCount} times with similar errors.
245
+
246
+ **Error type:** ${errorInfo.category}
247
+ **Error:** ${errorMessage}
248
+ **Pattern:** ${errorInfo.matchedPattern || 'general failure'}
249
+
250
+ ${recommendation}
251
+
252
+ USE THIS AskUserQuestion CALL:
253
+
254
+ \`\`\`json
255
+ {
256
+ "questions": [{
257
+ "question": "${agentName} failed ${failureCount}x (${errorInfo.category}). How should Ada fix this?",
258
+ "header": "Fix type",
259
+ "options": ${JSON.stringify(fixOptions)},
260
+ "multiSelect": false
261
+ }]
262
+ }
263
+ \`\`\`
264
+
265
+ After user responds, invoke Ada with context:
266
+ \`\`\`
267
+ Task(subagent_type="ada", prompt=\`{
268
+ "task": "${errorInfo.action === 'create_skill' ? 'create_skill' : 'update_agent'}",
269
+ "context": {
270
+ "agent": "${agentName}",
271
+ "error_type": "${errorInfo.category}",
272
+ "error_message": "${errorMessage.replace(/"/g, '\\"')}",
273
+ "failure_count": ${failureCount}
274
+ },
275
+ "output": ["action_taken", "file_path"]
276
+ }\`)
277
+ \`\`\`
278
+
279
+ ${'='.repeat(60)}
280
+ `;
281
+
282
+ console.error(output);
283
+ }
284
+
285
+ process.exit(0);
286
+ }