@hailer/mcp 0.1.14 → 0.1.16

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 (112) hide show
  1. package/.claude/agents/agent-giuseppe-app-builder.md +7 -6
  2. package/.claude/agents/agent-lars-code-inspector.md +26 -14
  3. package/dist/agents/bot-manager.d.ts +48 -0
  4. package/dist/agents/bot-manager.js +254 -0
  5. package/dist/agents/factory.d.ts +150 -0
  6. package/dist/agents/factory.js +650 -0
  7. package/dist/agents/giuseppe/ai.d.ts +83 -0
  8. package/dist/agents/giuseppe/ai.js +466 -0
  9. package/dist/agents/giuseppe/bot.d.ts +110 -0
  10. package/dist/agents/giuseppe/bot.js +780 -0
  11. package/dist/agents/giuseppe/config.d.ts +25 -0
  12. package/dist/agents/giuseppe/config.js +227 -0
  13. package/dist/agents/giuseppe/files.d.ts +52 -0
  14. package/dist/agents/giuseppe/files.js +338 -0
  15. package/dist/agents/giuseppe/git.d.ts +48 -0
  16. package/dist/agents/giuseppe/git.js +298 -0
  17. package/dist/agents/giuseppe/index.d.ts +97 -0
  18. package/dist/agents/giuseppe/index.js +258 -0
  19. package/dist/agents/giuseppe/lsp.d.ts +113 -0
  20. package/dist/agents/giuseppe/lsp.js +485 -0
  21. package/dist/agents/giuseppe/monitor.d.ts +118 -0
  22. package/dist/agents/giuseppe/monitor.js +621 -0
  23. package/dist/agents/giuseppe/prompt.d.ts +5 -0
  24. package/dist/agents/giuseppe/prompt.js +94 -0
  25. package/dist/agents/giuseppe/registries/pending-classification.d.ts +28 -0
  26. package/dist/agents/giuseppe/registries/pending-classification.js +50 -0
  27. package/dist/agents/giuseppe/registries/pending-fix.d.ts +30 -0
  28. package/dist/agents/giuseppe/registries/pending-fix.js +42 -0
  29. package/dist/agents/giuseppe/registries/pending.d.ts +27 -0
  30. package/dist/agents/giuseppe/registries/pending.js +49 -0
  31. package/dist/agents/giuseppe/specialist.d.ts +47 -0
  32. package/dist/agents/giuseppe/specialist.js +237 -0
  33. package/dist/agents/giuseppe/types.d.ts +123 -0
  34. package/dist/agents/giuseppe/types.js +9 -0
  35. package/dist/agents/hailer-expert/index.d.ts +8 -0
  36. package/dist/agents/hailer-expert/index.js +14 -0
  37. package/dist/agents/hal/daemon.d.ts +142 -0
  38. package/dist/agents/hal/daemon.js +1103 -0
  39. package/dist/agents/hal/definitions.d.ts +55 -0
  40. package/dist/agents/hal/definitions.js +263 -0
  41. package/dist/agents/hal/index.d.ts +3 -0
  42. package/dist/agents/hal/index.js +8 -0
  43. package/dist/agents/index.d.ts +18 -0
  44. package/dist/agents/index.js +48 -0
  45. package/dist/agents/shared/base.d.ts +216 -0
  46. package/dist/agents/shared/base.js +846 -0
  47. package/dist/agents/shared/services/agent-registry.d.ts +107 -0
  48. package/dist/agents/shared/services/agent-registry.js +629 -0
  49. package/dist/agents/shared/services/conversation-manager.d.ts +50 -0
  50. package/dist/agents/shared/services/conversation-manager.js +136 -0
  51. package/dist/agents/shared/services/mcp-client.d.ts +56 -0
  52. package/dist/agents/shared/services/mcp-client.js +124 -0
  53. package/dist/agents/shared/services/message-classifier.d.ts +37 -0
  54. package/dist/agents/shared/services/message-classifier.js +187 -0
  55. package/dist/agents/shared/services/message-formatter.d.ts +89 -0
  56. package/dist/agents/shared/services/message-formatter.js +371 -0
  57. package/dist/agents/shared/services/session-logger.d.ts +106 -0
  58. package/dist/agents/shared/services/session-logger.js +446 -0
  59. package/dist/agents/shared/services/tool-executor.d.ts +41 -0
  60. package/dist/agents/shared/services/tool-executor.js +169 -0
  61. package/dist/agents/shared/services/workspace-schema-cache.d.ts +125 -0
  62. package/dist/agents/shared/services/workspace-schema-cache.js +578 -0
  63. package/dist/agents/shared/specialist.d.ts +91 -0
  64. package/dist/agents/shared/specialist.js +399 -0
  65. package/dist/agents/shared/tool-schema-loader.d.ts +62 -0
  66. package/dist/agents/shared/tool-schema-loader.js +232 -0
  67. package/dist/agents/shared/types.d.ts +327 -0
  68. package/dist/agents/shared/types.js +121 -0
  69. package/dist/app.js +21 -4
  70. package/dist/cli.js +0 -0
  71. package/dist/client/agents/orchestrator.d.ts +1 -0
  72. package/dist/client/agents/orchestrator.js +12 -1
  73. package/dist/commands/seed-config.d.ts +9 -0
  74. package/dist/commands/seed-config.js +372 -0
  75. package/dist/config.d.ts +10 -0
  76. package/dist/config.js +61 -1
  77. package/dist/core.d.ts +8 -0
  78. package/dist/core.js +137 -6
  79. package/dist/lib/discussion-lock.d.ts +42 -0
  80. package/dist/lib/discussion-lock.js +110 -0
  81. package/dist/mcp/UserContextCache.js +2 -2
  82. package/dist/mcp/hailer-clients.d.ts +15 -0
  83. package/dist/mcp/hailer-clients.js +100 -6
  84. package/dist/mcp/signal-handler.d.ts +16 -5
  85. package/dist/mcp/signal-handler.js +173 -122
  86. package/dist/mcp/tools/activity.js +9 -1
  87. package/dist/mcp/tools/bot-config.d.ts +184 -9
  88. package/dist/mcp/tools/bot-config.js +2177 -163
  89. package/dist/mcp/tools/giuseppe-tools.d.ts +21 -0
  90. package/dist/mcp/tools/giuseppe-tools.js +525 -0
  91. package/dist/mcp/utils/hailer-api-client.d.ts +42 -1
  92. package/dist/mcp/utils/hailer-api-client.js +128 -2
  93. package/dist/mcp/webhook-handler.d.ts +87 -0
  94. package/dist/mcp/webhook-handler.js +343 -0
  95. package/dist/mcp/workspace-cache.d.ts +5 -0
  96. package/dist/mcp/workspace-cache.js +11 -0
  97. package/dist/mcp-server.js +55 -5
  98. package/dist/modules/bug-reports/giuseppe-agent.d.ts +58 -0
  99. package/dist/modules/bug-reports/giuseppe-agent.js +467 -0
  100. package/dist/modules/bug-reports/giuseppe-ai.d.ts +25 -1
  101. package/dist/modules/bug-reports/giuseppe-ai.js +133 -2
  102. package/dist/modules/bug-reports/giuseppe-bot.d.ts +3 -2
  103. package/dist/modules/bug-reports/giuseppe-bot.js +75 -36
  104. package/dist/modules/bug-reports/giuseppe-daemon.d.ts +80 -0
  105. package/dist/modules/bug-reports/giuseppe-daemon.js +617 -0
  106. package/dist/modules/bug-reports/giuseppe-files.d.ts +12 -0
  107. package/dist/modules/bug-reports/giuseppe-files.js +37 -0
  108. package/dist/modules/bug-reports/giuseppe-lsp.d.ts +113 -0
  109. package/dist/modules/bug-reports/giuseppe-lsp.js +485 -0
  110. package/dist/modules/bug-reports/index.d.ts +1 -0
  111. package/dist/modules/bug-reports/index.js +31 -29
  112. package/package.json +5 -4
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Specialist Bot Configuration
3
+ *
4
+ * Defines specialist bots that can be invited by the orchestrator (HAL)
5
+ * when tasks are too complex for general handling.
6
+ *
7
+ * Each specialist has:
8
+ * - Trigger patterns: When HAL should consider inviting them
9
+ * - Expertise areas: What they're good at
10
+ * - System prompt: How they behave when invited
11
+ */
12
+ export interface Specialist {
13
+ /** Definition name (e.g., "Hailer Expert") - used internally */
14
+ name: string;
15
+ /** Actual Hailer user display name (e.g., "Claude Terminal") - used for @mentions */
16
+ displayName?: string;
17
+ /** Hailer user ID of this bot (set at runtime from config) */
18
+ botUserId?: string;
19
+ /** Email of this bot (for matching with config) */
20
+ botEmail: string;
21
+ /** What this specialist is good at */
22
+ expertise: string[];
23
+ /** Regex patterns that trigger consideration of this specialist */
24
+ triggerPatterns: RegExp[];
25
+ /** Keywords that suggest this specialist (less strict than patterns) */
26
+ triggerKeywords: string[];
27
+ /** System prompt for this specialist when active */
28
+ systemPrompt: string;
29
+ /** Model to use (defaults to parent config) */
30
+ model?: string;
31
+ }
32
+ /**
33
+ * Registry of available specialists
34
+ * Key is the specialist identifier used internally
35
+ */
36
+ export declare const SPECIALISTS: Record<string, Specialist>;
37
+ /**
38
+ * Find a specialist that matches the given message content
39
+ * Returns the specialist if patterns match, null otherwise
40
+ */
41
+ export declare function findMatchingSpecialist(content: string): Specialist | null;
42
+ /**
43
+ * Check if content contains keywords suggesting a specialist might help
44
+ * Less strict than pattern matching - used for secondary consideration
45
+ */
46
+ export declare function hasSpecialistKeywords(content: string, specialist: Specialist): boolean;
47
+ /**
48
+ * Get specialist by key
49
+ */
50
+ export declare function getSpecialist(key: string): Specialist | undefined;
51
+ /**
52
+ * Get all specialist keys
53
+ */
54
+ export declare function getSpecialistKeys(): string[];
55
+ //# sourceMappingURL=definitions.d.ts.map
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ /**
3
+ * Specialist Bot Configuration
4
+ *
5
+ * Defines specialist bots that can be invited by the orchestrator (HAL)
6
+ * when tasks are too complex for general handling.
7
+ *
8
+ * Each specialist has:
9
+ * - Trigger patterns: When HAL should consider inviting them
10
+ * - Expertise areas: What they're good at
11
+ * - System prompt: How they behave when invited
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.SPECIALISTS = void 0;
15
+ exports.findMatchingSpecialist = findMatchingSpecialist;
16
+ exports.hasSpecialistKeywords = hasSpecialistKeywords;
17
+ exports.getSpecialist = getSpecialist;
18
+ exports.getSpecialistKeys = getSpecialistKeys;
19
+ /**
20
+ * Registry of available specialists
21
+ * Key is the specialist identifier used internally
22
+ */
23
+ exports.SPECIALISTS = {
24
+ giuseppe: {
25
+ name: "Giuseppe",
26
+ botEmail: "", // Set from config at runtime (uses same bot as orchestrator for now)
27
+ expertise: [
28
+ "bug fixing",
29
+ "app debugging",
30
+ "React/TypeScript fixes",
31
+ "Hailer app development",
32
+ "automated code repair",
33
+ ],
34
+ triggerPatterns: [
35
+ // Bug reports
36
+ /bug\s+(report|in|with|found)/i,
37
+ /report\s+(a\s+)?bug/i,
38
+ /found\s+(a\s+)?bug/i,
39
+ /there('s|\s+is)\s+(a\s+)?bug/i,
40
+ // Fix requests
41
+ /fix\s+(the|this|my)\s+(bug|issue|problem|app)/i,
42
+ /can\s+you\s+fix/i,
43
+ /please\s+fix/i,
44
+ // App issues
45
+ /app\s+(is\s+)?(broken|not\s+working|crashing|laggy)/i,
46
+ /(broken|crashing|laggy)\s+app/i,
47
+ // Giuseppe mentions
48
+ /giuseppe/i,
49
+ /auto.?fix/i,
50
+ ],
51
+ triggerKeywords: [
52
+ "bug",
53
+ "fix",
54
+ "broken",
55
+ "issue",
56
+ "error",
57
+ "crash",
58
+ "laggy",
59
+ "not working",
60
+ "giuseppe",
61
+ ],
62
+ systemPrompt: `<identity>
63
+ You are Giuseppe - the autonomous bug fixing specialist.
64
+ You were designed to automatically detect, analyze, and fix bugs in Hailer apps.
65
+ </identity>
66
+
67
+ <capabilities>
68
+ **Automatic Bug Detection:**
69
+ - I monitor the "Bug Reports" workflow for new bugs
70
+ - When a bug is detected, I automatically:
71
+ 1. Find the app project
72
+ 2. Analyze the code
73
+ 3. Generate a fix using Claude
74
+ 4. Apply and test the fix
75
+ 5. Ask for approval before publishing
76
+
77
+ **Bug Report Workflow:**
78
+ - Users create bug reports in the "Bug Reports" workflow
79
+ - I pick them up automatically and start fixing
80
+ - After the fix is ready, I ask the user to test
81
+ - User replies "approved" → I publish to production
82
+ - User replies "denied" → I ask what's wrong and retry
83
+
84
+ **What I Can Fix:**
85
+ - React/TypeScript compilation errors
86
+ - Hailer app SDK issues
87
+ - UI bugs and layout problems
88
+ - State management issues
89
+ - API integration bugs
90
+ </capabilities>
91
+
92
+ <how_to_use>
93
+ To report a bug for me to fix:
94
+ 1. Create a new activity in the "Bug Reports" workflow
95
+ 2. Set the title to include the app name (e.g., "Bug Report - My App")
96
+ 3. Describe the bug in detail
97
+ 4. I'll automatically pick it up and start working on it!
98
+
99
+ Or just tell HAL about a bug and ask to create a bug report.
100
+ </how_to_use>
101
+
102
+ <response_format>
103
+ When asked about bugs or my capabilities:
104
+ - Explain what I can do
105
+ - Offer to create a bug report if they describe a bug
106
+ - Tell them to check the Bug Reports workflow for status
107
+ </response_format>`,
108
+ },
109
+ hailerExpert: {
110
+ name: "Hailer Expert",
111
+ botEmail: "", // Set from config at runtime
112
+ expertise: [
113
+ "workflow creation and management",
114
+ "activity bulk operations",
115
+ "insights and SQL reports",
116
+ "complex data queries",
117
+ "workflow configuration",
118
+ ],
119
+ triggerPatterns: [
120
+ // Workflow creation
121
+ /create\s+(a\s+)?(new\s+)?(workflow|pipeline|process|tracker)/i,
122
+ /set\s+up\s+(a\s+)?(new\s+)?(workflow|pipeline|process)/i,
123
+ /build\s+(me\s+)?(a\s+)?(workflow|pipeline|crm|tracker)/i,
124
+ // Insight/report creation
125
+ /create\s+(a\s+)?(new\s+)?(report|insight|dashboard)/i,
126
+ /set\s+up\s+(a\s+)?(report|insight|analytics)/i,
127
+ /build\s+(a\s+)?(report|dashboard)\s+(showing|for)/i,
128
+ // Bulk operations
129
+ /create\s+(\d{2,}|multiple|several|many)\s+(activities|tasks|records)/i,
130
+ /bulk\s+(create|update|import)/i,
131
+ /import\s+(\d+|these|the)\s+(activities|tasks|records|items)/i,
132
+ // Complex queries
133
+ /complex\s+(query|filter|search)/i,
134
+ /advanced\s+(search|filter)/i,
135
+ // Multi-step operations
136
+ /(and|then|also)\s+(create|set up|add)\s+(a\s+)?(report|insight|workflow)/i,
137
+ ],
138
+ triggerKeywords: [
139
+ "workflow",
140
+ "pipeline",
141
+ "insight",
142
+ "report",
143
+ "dashboard",
144
+ "bulk",
145
+ "import",
146
+ "phases",
147
+ "stages",
148
+ ],
149
+ systemPrompt: `<identity>
150
+ You are the Hailer Expert - a specialized assistant for Hailer workspace operations.
151
+ You were invited to this discussion by HAL to help with a specific task.
152
+ </identity>
153
+
154
+ <capabilities>
155
+ You have access to these MCP tools:
156
+
157
+ **Workflow Management:**
158
+ - list_workflows, list_workflows_minimal - See available workflows
159
+ - list_workflow_phases - See phases in a workflow
160
+ - get_workflow_schema - See fields and structure
161
+ - install_workflow(workflowTemplates: [{name, fields: {_1000: {label, type, key}}, phases: {_2000: {name, isInitial}}}]) - CREATE workflows from scratch (NOT marketplace)
162
+ - update_workflow_field - Modify workflow fields
163
+ - update_workflow_phase - Modify phases
164
+
165
+ **Activity Operations:**
166
+ - list_activities(workflowId, phaseId, filters?, fields?, search?, limit?) - Query activities
167
+ - show_activity_by_id(activityId) - Get activity details
168
+ - create_activity(workflowId, name, fields?) OR create_activity(workflowId, activities[{name, fields}]) - Create single/bulk
169
+ - update_activity(activityId, name?, fields?, phaseId?) - Update SINGLE activity
170
+ - update_activity(activities: [{_id, name?, fields?, phaseId?}]) - Update BULK (3+ activities)
171
+ - count_activities(workflowId, phaseId?) - Count activities
172
+
173
+ **CRITICAL for update_activity:**
174
+ - SINGLE: use "activityId" parameter (NOT "_id")
175
+ - BULK: use "activities" array, each object MUST have "_id" (the activity ID)
176
+
177
+ **Insights (SQL Reports):**
178
+ - list_insights - See existing insights
179
+ - create_insight - Create SQL-like reports
180
+ - preview_insight - Test SQL queries
181
+ - get_insight_data - Execute and get results
182
+
183
+ **Other:**
184
+ - search_workspace_users - Find users
185
+ - Discussion tools for chat
186
+ </capabilities>
187
+
188
+ <protocol>
189
+ 1. Read HAL's handoff message carefully - it contains the task context
190
+ 2. Plan the operations needed
191
+ 3. Execute using MCP tools - NEVER fabricate data
192
+ 4. Report back with:
193
+ - What you did
194
+ - Results with clickable links (#activityId format)
195
+ - Any follow-up suggestions
196
+ </protocol>
197
+
198
+ <response_format>
199
+ When completing a task:
200
+ <respond discussion="DISCUSSION_ID">
201
+ [Brief status emoji + summary]
202
+
203
+ **What I did:**
204
+ - Step 1: ...
205
+ - Step 2: ...
206
+
207
+ **Results:**
208
+ [Data, links, or confirmation]
209
+
210
+ **Next steps (optional):**
211
+ [Suggestions for follow-up]
212
+ </respond>
213
+ </response_format>
214
+
215
+ <rules>
216
+ - Only respond when @mentioned - you were invited for a specific task
217
+ - Always use tools - never make up data or IDs
218
+ - Use #activityId format for activity links (auto-resolves to names)
219
+ - Be concise and technical
220
+ - If a tool call fails, DO NOT retry with the same parameters - explain the error to the user
221
+ - If you get "activityId is required" error, you forgot to pass the activity ID - fix your parameters
222
+ - Maximum 5 tool calls per task - if you need more, ask the user to break it down
223
+ </rules>`,
224
+ },
225
+ };
226
+ /**
227
+ * Find a specialist that matches the given message content
228
+ * Returns the specialist if patterns match, null otherwise
229
+ */
230
+ function findMatchingSpecialist(content) {
231
+ for (const specialist of Object.values(exports.SPECIALISTS)) {
232
+ // Check trigger patterns (strict match)
233
+ for (const pattern of specialist.triggerPatterns) {
234
+ if (pattern.test(content)) {
235
+ return specialist;
236
+ }
237
+ }
238
+ }
239
+ return null;
240
+ }
241
+ /**
242
+ * Check if content contains keywords suggesting a specialist might help
243
+ * Less strict than pattern matching - used for secondary consideration
244
+ */
245
+ function hasSpecialistKeywords(content, specialist) {
246
+ const contentLower = content.toLowerCase();
247
+ const keywordCount = specialist.triggerKeywords.filter((kw) => contentLower.includes(kw.toLowerCase())).length;
248
+ // Require at least 2 keywords for a soft match
249
+ return keywordCount >= 2;
250
+ }
251
+ /**
252
+ * Get specialist by key
253
+ */
254
+ function getSpecialist(key) {
255
+ return exports.SPECIALISTS[key];
256
+ }
257
+ /**
258
+ * Get all specialist keys
259
+ */
260
+ function getSpecialistKeys() {
261
+ return Object.keys(exports.SPECIALISTS);
262
+ }
263
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1,3 @@
1
+ export { OrchestratorDaemon, OrchestratorDaemonConfig } from './daemon';
2
+ export { SPECIALISTS, Specialist } from './definitions';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SPECIALISTS = exports.OrchestratorDaemon = void 0;
4
+ var daemon_1 = require("./daemon");
5
+ Object.defineProperty(exports, "OrchestratorDaemon", { enumerable: true, get: function () { return daemon_1.OrchestratorDaemon; } });
6
+ var definitions_1 = require("./definitions");
7
+ Object.defineProperty(exports, "SPECIALISTS", { enumerable: true, get: function () { return definitions_1.SPECIALISTS; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Hailer MCP Agents
3
+ *
4
+ * Each agent has its own folder with related code:
5
+ * - hal/ - HAL orchestrator (coordinates specialists)
6
+ * - giuseppe/ - Giuseppe bug fixer (autonomous code repair)
7
+ * - hailer-expert/ - Hailer workspace specialist
8
+ * - shared/ - Base classes and services used by all agents
9
+ */
10
+ export { ChatAgentDaemon, ChatAgentDaemonConfig } from './shared/base';
11
+ export { SpecialistDaemon, SpecialistDaemonConfig } from './shared/specialist';
12
+ export * from './shared/types';
13
+ export { OrchestratorDaemon, OrchestratorDaemonConfig } from './hal';
14
+ export { SPECIALISTS, Specialist } from './hal';
15
+ export { GiuseppeModule } from './giuseppe';
16
+ export { DaemonManager, DaemonManagerOptions, createDaemonManager, CreateDaemonManagerOptions, startDaemonMode } from './factory';
17
+ export { MultiBotManager, BotClient } from './bot-manager';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Hailer MCP Agents
4
+ *
5
+ * Each agent has its own folder with related code:
6
+ * - hal/ - HAL orchestrator (coordinates specialists)
7
+ * - giuseppe/ - Giuseppe bug fixer (autonomous code repair)
8
+ * - hailer-expert/ - Hailer workspace specialist
9
+ * - shared/ - Base classes and services used by all agents
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
23
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.MultiBotManager = exports.startDaemonMode = exports.createDaemonManager = exports.DaemonManager = exports.GiuseppeModule = exports.SPECIALISTS = exports.OrchestratorDaemon = exports.SpecialistDaemon = exports.ChatAgentDaemon = void 0;
27
+ // Shared
28
+ var base_1 = require("./shared/base");
29
+ Object.defineProperty(exports, "ChatAgentDaemon", { enumerable: true, get: function () { return base_1.ChatAgentDaemon; } });
30
+ var specialist_1 = require("./shared/specialist");
31
+ Object.defineProperty(exports, "SpecialistDaemon", { enumerable: true, get: function () { return specialist_1.SpecialistDaemon; } });
32
+ __exportStar(require("./shared/types"), exports);
33
+ // HAL (Orchestrator)
34
+ var hal_1 = require("./hal");
35
+ Object.defineProperty(exports, "OrchestratorDaemon", { enumerable: true, get: function () { return hal_1.OrchestratorDaemon; } });
36
+ var hal_2 = require("./hal");
37
+ Object.defineProperty(exports, "SPECIALISTS", { enumerable: true, get: function () { return hal_2.SPECIALISTS; } });
38
+ // Giuseppe (Bug Fixer)
39
+ var giuseppe_1 = require("./giuseppe");
40
+ Object.defineProperty(exports, "GiuseppeModule", { enumerable: true, get: function () { return giuseppe_1.GiuseppeModule; } });
41
+ // Factory
42
+ var factory_1 = require("./factory");
43
+ Object.defineProperty(exports, "DaemonManager", { enumerable: true, get: function () { return factory_1.DaemonManager; } });
44
+ Object.defineProperty(exports, "createDaemonManager", { enumerable: true, get: function () { return factory_1.createDaemonManager; } });
45
+ Object.defineProperty(exports, "startDaemonMode", { enumerable: true, get: function () { return factory_1.startDaemonMode; } });
46
+ var bot_manager_1 = require("./bot-manager");
47
+ Object.defineProperty(exports, "MultiBotManager", { enumerable: true, get: function () { return bot_manager_1.MultiBotManager; } });
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Chat Agent Daemon
3
+ *
4
+ * A persistent LLM conversation that monitors all workspace chats.
5
+ * The LLM maintains context across messages and decides what to respond to.
6
+ *
7
+ * Architecture:
8
+ * - One daemon per bot client
9
+ * - Subscribes to ALL messenger.new signals (not filtered)
10
+ * - LLM sees every message with priority markers
11
+ * - LLM decides: RESPOND / IGNORE / ACTION
12
+ */
13
+ import Anthropic from "@anthropic-ai/sdk";
14
+ import { BotClient } from "../bot-manager";
15
+ import { HailerSignal } from "../../mcp/signal-handler";
16
+ import { Logger } from "../../lib/logger";
17
+ import { ToolSchemaLoader, ToolIndexEntry } from "./tool-schema-loader";
18
+ import { ToolInput, McpToolResult } from "./types";
19
+ import { AgentRegistryService } from "./services/agent-registry";
20
+ import { ConversationManager, ConversationMessage } from "./services/conversation-manager";
21
+ import { McpClientService } from "./services/mcp-client";
22
+ import { MessageFormatterService } from "./services/message-formatter";
23
+ import { MessageClassifier } from "./services/message-classifier";
24
+ import { SessionLoggerService } from "./services/session-logger";
25
+ import { ToolExecutor } from "./services/tool-executor";
26
+ import { WorkspaceSchemaCacheService } from "./services/workspace-schema-cache";
27
+ import { SessionMetrics, ActivitySession, MessagePriority, IncomingMessage, ConversationState } from "./types";
28
+ export type { IncomingMessage, MessagePriority, SessionMetrics, ActivitySession };
29
+ export interface ChatAgentDaemonConfig {
30
+ botClient: BotClient;
31
+ mcpServerUrl: string;
32
+ anthropicApiKey: string;
33
+ model?: string;
34
+ maxContextMessages?: number;
35
+ }
36
+ export declare class ChatAgentDaemon {
37
+ protected logger: Logger;
38
+ protected client: Anthropic;
39
+ protected botClient: BotClient;
40
+ protected config: ChatAgentDaemonConfig;
41
+ protected toolSchemaLoader: ToolSchemaLoader;
42
+ protected isProcessing: boolean;
43
+ protected messageQueue: IncomingMessage[];
44
+ protected processedMessageIds: Set<string>;
45
+ private typingInterval;
46
+ private typingDiscussionId;
47
+ private static TYPING_REFRESH_MS;
48
+ protected toolIndex: ToolIndexEntry[];
49
+ protected minimalTools: Anthropic.Tool[];
50
+ /** Message classifier - handles message extraction and priority classification */
51
+ protected messageClassifier: MessageClassifier | null;
52
+ /** Conversation manager - handles per-discussion context and LRU cache */
53
+ protected conversationManager: ConversationManager | null;
54
+ /** MCP client service - handles tool schema loading and execution */
55
+ protected mcpClient: McpClientService | null;
56
+ /** Tool executor - handles tool execution and write tracking */
57
+ protected toolExecutor: ToolExecutor | null;
58
+ /** Agent registration service - handles Agent Directory, Position, Team, etc. */
59
+ protected registryService: AgentRegistryService | null;
60
+ /** Message formatting service - handles tag resolution and formatting */
61
+ protected messageFormatter: MessageFormatterService | null;
62
+ /** Session logging service - handles activity session tracking */
63
+ protected sessionLogger: SessionLoggerService | null;
64
+ /** Workspace schema cache - dynamic workflow/field ID lookup */
65
+ protected schemaCache: WorkspaceSchemaCacheService | null;
66
+ /** Current discussion context for tracking */
67
+ protected currentDiscussionId: string | null;
68
+ protected currentLinkedActivityId: string | null;
69
+ /** Unsubscribe function for messenger.new signals */
70
+ private messengerUnsubscribe;
71
+ /** Original API key for cleanup - stored at init because botClient.config may change */
72
+ private originalApiKey;
73
+ constructor(config: ChatAgentDaemonConfig);
74
+ /**
75
+ * Initialize the daemon - load tools and subscribe to signals
76
+ */
77
+ initialize(): Promise<void>;
78
+ /**
79
+ * Load existing discussions the bot is already a member of
80
+ * This ensures the bot can respond to messages in discussions it was added to before startup
81
+ */
82
+ private loadExistingDiscussions;
83
+ /**
84
+ * Extract and classify incoming message from signal
85
+ * Can be overridden in subclasses to customize filtering
86
+ */
87
+ protected extractIncomingMessage(signal: HailerSignal): Promise<IncomingMessage | null>;
88
+ /**
89
+ * Handle incoming signal from Hailer
90
+ */
91
+ private handleSignal;
92
+ /**
93
+ * Process queued messages through the LLM
94
+ * Note: Uses flag-first pattern to prevent race conditions
95
+ */
96
+ private processQueue;
97
+ /**
98
+ * Process a single message through the persistent LLM conversation
99
+ */
100
+ private processMessage;
101
+ /**
102
+ * Format incoming message for LLM consumption
103
+ */
104
+ private formatIncomingMessage;
105
+ /**
106
+ * Load and inject memory for an activity into conversation context
107
+ * Called when entering a new discussion that's linked to an activity
108
+ */
109
+ private injectMemoryForActivity;
110
+ /**
111
+ * Execute tool calls and continue the conversation
112
+ * Simple passthrough - just execute tools and return results to LLM
113
+ */
114
+ protected executeToolsAndContinue(toolUseBlocks: Anthropic.ToolUseBlock[], originalMessage: IncomingMessage): Promise<void>;
115
+ /**
116
+ * Handle LLM response
117
+ * Override in subclasses to customize response handling
118
+ */
119
+ protected handleLlmResponse(response: Anthropic.Message, originalMessage: IncomingMessage): Promise<void>;
120
+ /**
121
+ * Start typing indicator with auto-refresh interval
122
+ * Keeps refreshing every 3 seconds until stopTypingIndicator is called
123
+ */
124
+ protected startTypingIndicator(discussionId: string): void;
125
+ /**
126
+ * Stop typing indicator and clear refresh interval
127
+ */
128
+ protected stopTypingIndicator(): void;
129
+ /**
130
+ * Send typing signal to Hailer API
131
+ * API: messenger.set_discussion_typing_state(discussionId, typingState)
132
+ */
133
+ private sendTypingSignal;
134
+ /**
135
+ * Post a response to a discussion
136
+ * Automatically converts @mentions and #activity tags to Hailer tags
137
+ * Includes links metadata required for tags to work
138
+ */
139
+ protected postResponse(discussionId: string, content: string): Promise<void>;
140
+ /**
141
+ * Get the system prompt for the daemon
142
+ * MUST be overridden in subclasses
143
+ */
144
+ protected getSystemPrompt(): string;
145
+ /**
146
+ * Get tools for LLM calls
147
+ * Override in subclass to add custom tools (like trigger_giuseppe_retry)
148
+ */
149
+ protected getTools(): Anthropic.Tool[];
150
+ /**
151
+ * Get tool whitelist for this agent
152
+ * Override in subclass to limit which tools are available
153
+ * Return null for all tools, or array of tool names
154
+ */
155
+ protected getToolWhitelist(): string[] | null;
156
+ /**
157
+ * Preprocess tool input before execution
158
+ * Override in subclass to inject context (e.g., sourceActivityId)
159
+ * @param toolName - Name of the tool being called
160
+ * @param input - Original tool input from LLM
161
+ * @returns Processed input (may be modified)
162
+ */
163
+ protected preprocessToolInput(toolName: string, input: ToolInput): ToolInput;
164
+ /**
165
+ * Call MCP tool (delegates to McpClientService)
166
+ * Protected for subclass access
167
+ */
168
+ protected callMcpTool(name: string, args: ToolInput): Promise<McpToolResult>;
169
+ /**
170
+ * Stop the daemon
171
+ * Flushes all pending activity sessions before stopping
172
+ */
173
+ stop(): Promise<void>;
174
+ /**
175
+ * Get current conversation state (for debugging)
176
+ */
177
+ getConversationState(): ConversationState;
178
+ /**
179
+ * Get full conversation for a specific discussion (for debugging)
180
+ */
181
+ getFullConversation(discussionId?: string): ConversationMessage[];
182
+ /**
183
+ * Get agent's display name (override in subclass for custom names)
184
+ * Default implementation uses the actual Hailer user name from BotClient
185
+ */
186
+ protected getAgentName(): {
187
+ firstName: string;
188
+ lastName: string;
189
+ };
190
+ /**
191
+ * Get agent's description/system prompt (override in subclass)
192
+ */
193
+ protected getAgentDescription(): string;
194
+ /**
195
+ * Get default team ID from workspace cache
196
+ * Returns the first available team, or undefined if no teams exist
197
+ *
198
+ * Teams structure in init is: { teams: { workspaceId: { teamId: teamData, ... } } }
199
+ */
200
+ protected getDefaultTeamId(): string | undefined;
201
+ /**
202
+ * Get agent's Position details (override in subclass for custom positions)
203
+ */
204
+ protected getPositionDetails(): {
205
+ name: string;
206
+ purpose: string;
207
+ personaTone: string;
208
+ coreCapabilities: string;
209
+ boundaries: string;
210
+ };
211
+ /**
212
+ * Get agent directory ID
213
+ */
214
+ getAgentDirectoryId(): string | null;
215
+ }
216
+ //# sourceMappingURL=base.d.ts.map