@hailer/mcp 0.1.17 → 0.2.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 (200) hide show
  1. package/dist/app.js +24 -20
  2. package/dist/core.d.ts +33 -9
  3. package/dist/core.js +279 -147
  4. package/dist/mcp/UserContextCache.js +18 -0
  5. package/dist/mcp/hailer-clients.d.ts +9 -1
  6. package/dist/mcp/hailer-clients.js +13 -3
  7. package/dist/mcp/signal-handler.js +1 -1
  8. package/dist/mcp/tool-registry.d.ts +3 -1
  9. package/dist/mcp/tool-registry.js +4 -1
  10. package/dist/mcp/tools/activity.js +43 -34
  11. package/dist/mcp/tools/bot-config/constants.d.ts +23 -0
  12. package/dist/mcp/tools/bot-config/constants.js +94 -0
  13. package/dist/mcp/tools/{bot-config.d.ts → bot-config/core.d.ts} +6 -6
  14. package/dist/mcp/tools/{bot-config.js → bot-config/core.js} +15 -15
  15. package/dist/mcp/tools/bot-config/index.d.ts +10 -0
  16. package/dist/mcp/tools/bot-config/index.js +59 -0
  17. package/dist/mcp/tools/bot-config/tools.d.ts +7 -0
  18. package/dist/mcp/tools/bot-config/tools.js +15 -0
  19. package/dist/mcp/tools/bot-config/types.d.ts +50 -0
  20. package/dist/mcp/tools/bot-config/types.js +6 -0
  21. package/dist/mcp/tools/bug-fixer-tools.d.ts +21 -0
  22. package/dist/mcp/tools/{giuseppe-tools.js → bug-fixer-tools.js} +61 -61
  23. package/dist/mcp/tools/user.js +10 -29
  24. package/dist/mcp/tools/workflow.js +36 -2
  25. package/dist/mcp/utils/data-transformers.d.ts +0 -8
  26. package/dist/mcp/utils/data-transformers.js +0 -28
  27. package/dist/mcp/utils/index.d.ts +4 -1
  28. package/dist/mcp/utils/index.js +17 -3
  29. package/dist/mcp/utils/pagination.d.ts +40 -0
  30. package/dist/mcp/utils/pagination.js +55 -0
  31. package/dist/mcp/utils/response-builder.d.ts +53 -0
  32. package/dist/mcp/utils/response-builder.js +110 -0
  33. package/dist/mcp/utils/tool-helpers.d.ts +0 -8
  34. package/dist/mcp/utils/tool-helpers.js +0 -24
  35. package/dist/mcp/utils/types.d.ts +1 -33
  36. package/dist/mcp-server.d.ts +2 -2
  37. package/dist/mcp-server.js +161 -139
  38. package/package.json +1 -1
  39. package/REFACTOR_STATUS.md +0 -127
  40. package/dist/agents/bot-manager.d.ts +0 -48
  41. package/dist/agents/bot-manager.js +0 -254
  42. package/dist/agents/factory.d.ts +0 -150
  43. package/dist/agents/factory.js +0 -650
  44. package/dist/agents/giuseppe/ai.d.ts +0 -83
  45. package/dist/agents/giuseppe/ai.js +0 -466
  46. package/dist/agents/giuseppe/bot.d.ts +0 -110
  47. package/dist/agents/giuseppe/bot.js +0 -780
  48. package/dist/agents/giuseppe/config.d.ts +0 -25
  49. package/dist/agents/giuseppe/config.js +0 -227
  50. package/dist/agents/giuseppe/files.d.ts +0 -52
  51. package/dist/agents/giuseppe/files.js +0 -338
  52. package/dist/agents/giuseppe/git.d.ts +0 -48
  53. package/dist/agents/giuseppe/git.js +0 -298
  54. package/dist/agents/giuseppe/index.d.ts +0 -97
  55. package/dist/agents/giuseppe/index.js +0 -258
  56. package/dist/agents/giuseppe/lsp.d.ts +0 -113
  57. package/dist/agents/giuseppe/lsp.js +0 -485
  58. package/dist/agents/giuseppe/monitor.d.ts +0 -118
  59. package/dist/agents/giuseppe/monitor.js +0 -621
  60. package/dist/agents/giuseppe/prompt.d.ts +0 -5
  61. package/dist/agents/giuseppe/prompt.js +0 -94
  62. package/dist/agents/giuseppe/registries/pending-classification.d.ts +0 -28
  63. package/dist/agents/giuseppe/registries/pending-classification.js +0 -50
  64. package/dist/agents/giuseppe/registries/pending-fix.d.ts +0 -30
  65. package/dist/agents/giuseppe/registries/pending-fix.js +0 -42
  66. package/dist/agents/giuseppe/registries/pending.d.ts +0 -27
  67. package/dist/agents/giuseppe/registries/pending.js +0 -49
  68. package/dist/agents/giuseppe/specialist.d.ts +0 -47
  69. package/dist/agents/giuseppe/specialist.js +0 -237
  70. package/dist/agents/giuseppe/types.d.ts +0 -123
  71. package/dist/agents/giuseppe/types.js +0 -9
  72. package/dist/agents/hailer-expert/index.d.ts +0 -8
  73. package/dist/agents/hailer-expert/index.js +0 -14
  74. package/dist/agents/hal/daemon.d.ts +0 -142
  75. package/dist/agents/hal/daemon.js +0 -1103
  76. package/dist/agents/hal/definitions.d.ts +0 -55
  77. package/dist/agents/hal/definitions.js +0 -263
  78. package/dist/agents/hal/index.d.ts +0 -3
  79. package/dist/agents/hal/index.js +0 -8
  80. package/dist/agents/index.d.ts +0 -18
  81. package/dist/agents/index.js +0 -48
  82. package/dist/agents/shared/base.d.ts +0 -216
  83. package/dist/agents/shared/base.js +0 -846
  84. package/dist/agents/shared/services/agent-registry.d.ts +0 -107
  85. package/dist/agents/shared/services/agent-registry.js +0 -629
  86. package/dist/agents/shared/services/conversation-manager.d.ts +0 -50
  87. package/dist/agents/shared/services/conversation-manager.js +0 -136
  88. package/dist/agents/shared/services/mcp-client.d.ts +0 -56
  89. package/dist/agents/shared/services/mcp-client.js +0 -124
  90. package/dist/agents/shared/services/message-classifier.d.ts +0 -37
  91. package/dist/agents/shared/services/message-classifier.js +0 -187
  92. package/dist/agents/shared/services/message-formatter.d.ts +0 -89
  93. package/dist/agents/shared/services/message-formatter.js +0 -371
  94. package/dist/agents/shared/services/session-logger.d.ts +0 -106
  95. package/dist/agents/shared/services/session-logger.js +0 -446
  96. package/dist/agents/shared/services/tool-executor.d.ts +0 -41
  97. package/dist/agents/shared/services/tool-executor.js +0 -169
  98. package/dist/agents/shared/services/workspace-schema-cache.d.ts +0 -125
  99. package/dist/agents/shared/services/workspace-schema-cache.js +0 -578
  100. package/dist/agents/shared/specialist.d.ts +0 -91
  101. package/dist/agents/shared/specialist.js +0 -399
  102. package/dist/agents/shared/tool-schema-loader.d.ts +0 -62
  103. package/dist/agents/shared/tool-schema-loader.js +0 -232
  104. package/dist/agents/shared/types.d.ts +0 -327
  105. package/dist/agents/shared/types.js +0 -121
  106. package/dist/client/agents/base.d.ts +0 -207
  107. package/dist/client/agents/base.js +0 -744
  108. package/dist/client/agents/definitions.d.ts +0 -53
  109. package/dist/client/agents/definitions.js +0 -263
  110. package/dist/client/agents/orchestrator.d.ts +0 -141
  111. package/dist/client/agents/orchestrator.js +0 -1062
  112. package/dist/client/agents/specialist.d.ts +0 -86
  113. package/dist/client/agents/specialist.js +0 -340
  114. package/dist/client/bot-entrypoint.d.ts +0 -7
  115. package/dist/client/bot-entrypoint.js +0 -103
  116. package/dist/client/bot-manager.d.ts +0 -44
  117. package/dist/client/bot-manager.js +0 -173
  118. package/dist/client/bot-runner.d.ts +0 -35
  119. package/dist/client/bot-runner.js +0 -188
  120. package/dist/client/chat-agent-daemon.d.ts +0 -464
  121. package/dist/client/chat-agent-daemon.js +0 -1774
  122. package/dist/client/daemon-factory.d.ts +0 -106
  123. package/dist/client/daemon-factory.js +0 -301
  124. package/dist/client/factory.d.ts +0 -111
  125. package/dist/client/factory.js +0 -314
  126. package/dist/client/index.d.ts +0 -17
  127. package/dist/client/index.js +0 -38
  128. package/dist/client/multi-bot-manager.d.ts +0 -42
  129. package/dist/client/multi-bot-manager.js +0 -161
  130. package/dist/client/orchestrator-daemon.d.ts +0 -87
  131. package/dist/client/orchestrator-daemon.js +0 -444
  132. package/dist/client/server.d.ts +0 -8
  133. package/dist/client/server.js +0 -251
  134. package/dist/client/services/agent-registry.d.ts +0 -108
  135. package/dist/client/services/agent-registry.js +0 -630
  136. package/dist/client/services/conversation-manager.d.ts +0 -50
  137. package/dist/client/services/conversation-manager.js +0 -136
  138. package/dist/client/services/mcp-client.d.ts +0 -48
  139. package/dist/client/services/mcp-client.js +0 -105
  140. package/dist/client/services/message-classifier.d.ts +0 -37
  141. package/dist/client/services/message-classifier.js +0 -187
  142. package/dist/client/services/message-formatter.d.ts +0 -84
  143. package/dist/client/services/message-formatter.js +0 -353
  144. package/dist/client/services/session-logger.d.ts +0 -106
  145. package/dist/client/services/session-logger.js +0 -446
  146. package/dist/client/services/tool-executor.d.ts +0 -41
  147. package/dist/client/services/tool-executor.js +0 -169
  148. package/dist/client/services/workspace-schema-cache.d.ts +0 -149
  149. package/dist/client/services/workspace-schema-cache.js +0 -732
  150. package/dist/client/specialist-daemon.d.ts +0 -77
  151. package/dist/client/specialist-daemon.js +0 -197
  152. package/dist/client/specialists.d.ts +0 -53
  153. package/dist/client/specialists.js +0 -178
  154. package/dist/client/tool-schema-loader.d.ts +0 -62
  155. package/dist/client/tool-schema-loader.js +0 -232
  156. package/dist/client/types.d.ts +0 -327
  157. package/dist/client/types.js +0 -121
  158. package/dist/commands/seed-config.d.ts +0 -9
  159. package/dist/commands/seed-config.js +0 -372
  160. package/dist/lib/context-manager.d.ts +0 -111
  161. package/dist/lib/context-manager.js +0 -431
  162. package/dist/lib/prompt-length-manager.d.ts +0 -81
  163. package/dist/lib/prompt-length-manager.js +0 -457
  164. package/dist/mcp/tools/giuseppe-tools.d.ts +0 -21
  165. package/dist/modules/bug-reports/bug-config.d.ts +0 -25
  166. package/dist/modules/bug-reports/bug-config.js +0 -187
  167. package/dist/modules/bug-reports/bug-monitor.d.ts +0 -108
  168. package/dist/modules/bug-reports/bug-monitor.js +0 -510
  169. package/dist/modules/bug-reports/giuseppe-agent.d.ts +0 -58
  170. package/dist/modules/bug-reports/giuseppe-agent.js +0 -467
  171. package/dist/modules/bug-reports/giuseppe-ai.d.ts +0 -83
  172. package/dist/modules/bug-reports/giuseppe-ai.js +0 -466
  173. package/dist/modules/bug-reports/giuseppe-bot.d.ts +0 -110
  174. package/dist/modules/bug-reports/giuseppe-bot.js +0 -804
  175. package/dist/modules/bug-reports/giuseppe-daemon.d.ts +0 -80
  176. package/dist/modules/bug-reports/giuseppe-daemon.js +0 -617
  177. package/dist/modules/bug-reports/giuseppe-files.d.ts +0 -64
  178. package/dist/modules/bug-reports/giuseppe-files.js +0 -375
  179. package/dist/modules/bug-reports/giuseppe-git.d.ts +0 -48
  180. package/dist/modules/bug-reports/giuseppe-git.js +0 -298
  181. package/dist/modules/bug-reports/giuseppe-lsp.d.ts +0 -113
  182. package/dist/modules/bug-reports/giuseppe-lsp.js +0 -485
  183. package/dist/modules/bug-reports/giuseppe-prompt.d.ts +0 -5
  184. package/dist/modules/bug-reports/giuseppe-prompt.js +0 -94
  185. package/dist/modules/bug-reports/index.d.ts +0 -77
  186. package/dist/modules/bug-reports/index.js +0 -215
  187. package/dist/modules/bug-reports/pending-classification-registry.d.ts +0 -28
  188. package/dist/modules/bug-reports/pending-classification-registry.js +0 -50
  189. package/dist/modules/bug-reports/pending-fix-registry.d.ts +0 -30
  190. package/dist/modules/bug-reports/pending-fix-registry.js +0 -42
  191. package/dist/modules/bug-reports/pending-registry.d.ts +0 -27
  192. package/dist/modules/bug-reports/pending-registry.js +0 -49
  193. package/dist/modules/bug-reports/types.d.ts +0 -123
  194. package/dist/modules/bug-reports/types.js +0 -9
  195. package/dist/routes/agents.d.ts +0 -44
  196. package/dist/routes/agents.js +0 -311
  197. package/dist/services/agent-credential-store.d.ts +0 -73
  198. package/dist/services/agent-credential-store.js +0 -212
  199. package/dist/services/bug-monitor.d.ts +0 -23
  200. package/dist/services/bug-monitor.js +0 -275
@@ -1,457 +0,0 @@
1
- "use strict";
2
- /**
3
- * Prompt Length Manager
4
- * Handles prompt length validation, truncation, and debugging
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.promptLengthManager = exports.PromptLengthManager = exports.DEFAULT_TRUNCATION_CONFIG = void 0;
8
- const logger_1 = require("./logger");
9
- exports.DEFAULT_TRUNCATION_CONFIG = {
10
- // Claude 4 optimized limits (leaving room for response)
11
- maxTotalTokens: 150_000, // 150k tokens for Claude 4
12
- maxUserMessagesTokens: 20_000, // 20k tokens for user messages
13
- // Character limits (fallback: 1 token ≈ 4 characters)
14
- maxTotalCharacters: 600_000, // ~150k tokens
15
- maxUserMessagesCharacters: 80_000, // ~20k tokens
16
- // Provider context windows (in tokens)
17
- anthropicContextWindow: 200_000, // Claude Sonnet 4
18
- openaiContextWindow: 128_000, // GPT-4 Turbo
19
- // New smart truncation strategy
20
- preserveSystemPrompt: true, // Never truncate system prompts
21
- preserveUserMessages: true, // Preserve up to 20k tokens
22
- preserveAssistantResponses: true, // Preserve when possible
23
- truncateToolResponsesFirst: true, // Tool responses are most expendable
24
- };
25
- class PromptLengthManager {
26
- logger;
27
- config;
28
- constructor(config = {}) {
29
- this.config = { ...exports.DEFAULT_TRUNCATION_CONFIG, ...config };
30
- this.logger = (0, logger_1.createLogger)({ component: "PromptLengthManager" });
31
- }
32
- /**
33
- * Estimate token count from character count
34
- * Rough approximation: 1 token ≈ 4 characters for English text
35
- */
36
- estimateTokens(text) {
37
- return Math.ceil(text.length / 4);
38
- }
39
- /**
40
- * Count exact characters and estimate tokens for a text
41
- */
42
- analyzeText(text) {
43
- const characters = text.length;
44
- const estimatedTokens = this.estimateTokens(text);
45
- return { characters, estimatedTokens };
46
- }
47
- /**
48
- * Truncate text intelligently, preserving structure when possible
49
- */
50
- truncateText(text, maxLength, source) {
51
- if (text.length <= maxLength) {
52
- return { text, truncated: false };
53
- }
54
- // Try to truncate at natural boundaries (paragraphs, sentences)
55
- const truncated = text.substring(0, maxLength);
56
- // Find last complete sentence or paragraph
57
- const lastParagraph = truncated.lastIndexOf('\n\n');
58
- const lastSentence = truncated.lastIndexOf('. ');
59
- let cutPoint = maxLength;
60
- let truncationMethod = 'hard_cutoff';
61
- if (lastParagraph > maxLength * 0.7) {
62
- cutPoint = lastParagraph;
63
- truncationMethod = 'paragraph_boundary';
64
- }
65
- else if (lastSentence > maxLength * 0.8) {
66
- cutPoint = lastSentence + 1;
67
- truncationMethod = 'sentence_boundary';
68
- }
69
- const finalText = text.substring(0, cutPoint) + '\n\n[... Content truncated ...]';
70
- const removedContent = text.substring(cutPoint);
71
- this.logger.warn(`Truncated ${source}`, {
72
- originalLength: text.length,
73
- truncatedLength: finalText.length,
74
- truncatedAt: cutPoint,
75
- truncationMethod,
76
- removedCharacters: removedContent.length,
77
- reductionPercent: Math.round((1 - finalText.length / text.length) * 100),
78
- source,
79
- removedContentPreview: removedContent.substring(0, 200) + (removedContent.length > 200 ? '...' : ''),
80
- originalContentPreview: text.substring(0, 200) + (text.length > 200 ? '...' : '')
81
- });
82
- return {
83
- text: finalText,
84
- truncated: true,
85
- truncatedAt: cutPoint,
86
- truncationMethod,
87
- originalContent: text
88
- };
89
- }
90
- /**
91
- * Analyze prompt components and build analysis
92
- */
93
- analyzePrompt(components) {
94
- let totalCharacters = 0;
95
- let totalTokens = 0;
96
- const warnings = [];
97
- const processedComponents = [];
98
- for (const component of components) {
99
- const analysis = this.analyzeText(component.content);
100
- totalCharacters += analysis.characters;
101
- totalTokens += analysis.estimatedTokens;
102
- processedComponents.push({
103
- ...component,
104
- originalLength: analysis.characters,
105
- });
106
- // TRUNCATION WARNINGS TEMPORARILY DISABLED FOR TESTING
107
- /* COMMENTED OUT - RE-ENABLE BY UNCOMMENTING THIS BLOCK
108
- // Check component token limits under new system
109
- const componentTokens = this.estimateTokens(component.content);
110
-
111
- if (component.type === 'user' && componentTokens > this.config.maxUserMessagesTokens) {
112
- warnings.push(`User message (${componentTokens} tokens) exceeds user message limit (${this.config.maxUserMessagesTokens} tokens)`);
113
- }
114
-
115
- // Note: No individual limits for system prompts or tool responses under new logic
116
- */ // END OF COMMENTED OUT WARNING LOGIC
117
- }
118
- // TOTAL TOKEN LIMIT WARNINGS TEMPORARILY DISABLED FOR TESTING
119
- /* COMMENTED OUT - RE-ENABLE BY UNCOMMENTING THIS BLOCK
120
- // Check total token limits (primary check under new system)
121
- if (totalTokens > this.config.maxTotalTokens) {
122
- warnings.push(`Total prompt (${totalTokens} tokens) exceeds Claude 4 limit (${this.config.maxTotalTokens} tokens)`);
123
- }
124
- */ // END OF COMMENTED OUT WARNING LOGIC
125
- return {
126
- totalCharacters,
127
- estimatedTokens: totalTokens,
128
- components: processedComponents,
129
- truncationApplied: false,
130
- warnings,
131
- };
132
- }
133
- /**
134
- * No longer truncate individual tool responses - only when total prompt exceeds limits
135
- * This method now just passes through content unchanged and logs for monitoring
136
- * TEMPORARILY DISABLED - Even monitoring/logging is disabled
137
- */
138
- truncateToolResponse(content, toolName) {
139
- // TRUNCATION AND MONITORING TEMPORARILY DISABLED FOR TESTING
140
- return content; // Pass through unchanged with no logging
141
- /* COMMENTED OUT - RE-ENABLE BY UNCOMMENTING THIS BLOCK
142
- this.logger.debug(`Tool response processed (no individual limits)`, {
143
- toolName,
144
- length: content.length,
145
- estimatedTokens: this.estimateTokens(content),
146
- note: "Individual tool limits removed - truncation only happens at total prompt level"
147
- });
148
-
149
- return content; // Pass through unchanged
150
- */ // END OF COMMENTED OUT MONITORING LOGIC
151
- }
152
- /**
153
- * Apply smart token-based truncation optimized for Claude 4
154
- * TEMPORARILY DISABLED - All truncation logic commented out for testing
155
- */
156
- truncatePrompt(analysis) {
157
- // TRUNCATION TEMPORARILY DISABLED FOR TESTING
158
- this.logger.info("Truncation is temporarily disabled - returning prompt unchanged", {
159
- originalTokens: analysis.estimatedTokens,
160
- originalChars: analysis.totalCharacters,
161
- tokenLimit: this.config.maxTotalTokens,
162
- status: "DISABLED"
163
- });
164
- return analysis;
165
- /* COMMENTED OUT - RE-ENABLE BY UNCOMMENTING THIS BLOCK
166
- if (analysis.estimatedTokens <= this.config.maxTotalTokens) {
167
- return analysis; // No truncation needed
168
- }
169
-
170
- const targetTokenReduction = analysis.estimatedTokens - this.config.maxTotalTokens;
171
-
172
- this.logger.warn("Applying Claude 4 optimized prompt truncation", {
173
- originalTokens: analysis.estimatedTokens,
174
- originalChars: analysis.totalCharacters,
175
- tokenLimit: this.config.maxTotalTokens,
176
- targetTokenReduction,
177
- truncationStrategy: "claude_4_smart_preservation"
178
- });
179
-
180
- // Track unknown component types for debugging
181
- const knownTypes = new Set(['system', 'user', 'assistant', 'tool_result', 'tool_call']);
182
- const unknownComponents = analysis.components.filter(c => !knownTypes.has(c.type));
183
- if (unknownComponents.length > 0) {
184
- this.logger.info("Unknown prompt component types detected", {
185
- unknownTypes: unknownComponents.map(c => ({ type: c.type, source: c.source, length: c.content.length })),
186
- count: unknownComponents.length
187
- });
188
- }
189
-
190
- // Separate components by type for smart preservation
191
- const systemComponents = analysis.components.filter(c => c.type === 'system');
192
- const userComponents = analysis.components.filter(c => c.type === 'user');
193
- const assistantComponents = analysis.components.filter(c => c.type === 'assistant' || c.type === 'tool_call');
194
- const toolComponents = analysis.components.filter(c => c.type === 'tool_result');
195
- const otherComponents = analysis.components.filter(c => !knownTypes.has(c.type));
196
-
197
- // Calculate current token usage by component type
198
- const systemTokens = systemComponents.reduce((sum, c) => sum + this.estimateTokens(c.content), 0);
199
- const userTokens = userComponents.reduce((sum, c) => sum + this.estimateTokens(c.content), 0);
200
- const assistantTokens = assistantComponents.reduce((sum, c) => sum + this.estimateTokens(c.content), 0);
201
- const toolTokens = toolComponents.reduce((sum, c) => sum + this.estimateTokens(c.content), 0);
202
- const otherTokens = otherComponents.reduce((sum, c) => sum + this.estimateTokens(c.content), 0);
203
-
204
- this.logger.info("Component token breakdown", {
205
- system: `${systemTokens} tokens (${systemComponents.length} components) - PRESERVED`,
206
- user: `${userTokens} tokens (${userComponents.length} components) - PRESERVE UP TO 20k`,
207
- assistant: `${assistantTokens} tokens (${assistantComponents.length} components) - PRESERVE WHEN POSSIBLE`,
208
- tool_result: `${toolTokens} tokens (${toolComponents.length} components) - TRUNCATE FIRST`,
209
- other: `${otherTokens} tokens (${otherComponents.length} components) - UNKNOWN TYPE`
210
- });
211
-
212
- const truncatedComponents: PromptComponent[] = [];
213
- let tokensUsed = 0;
214
- let tokensReduced = 0;
215
-
216
- // Step 1: Always preserve system prompts (100%)
217
- systemComponents.forEach(component => {
218
- truncatedComponents.push({ ...component });
219
- tokensUsed += this.estimateTokens(component.content);
220
- });
221
-
222
- // Step 2: Preserve user messages up to 20k tokens
223
- let userTokensUsed = 0;
224
- userComponents.forEach(component => {
225
- const componentTokens = this.estimateTokens(component.content);
226
- if (userTokensUsed + componentTokens <= this.config.maxUserMessagesTokens) {
227
- // Keep this user message fully
228
- truncatedComponents.push({ ...component });
229
- tokensUsed += componentTokens;
230
- userTokensUsed += componentTokens;
231
- } else if (userTokensUsed < this.config.maxUserMessagesTokens) {
232
- // Partial truncation to fit within user message limit
233
- const allowedTokens = this.config.maxUserMessagesTokens - userTokensUsed;
234
- const allowedChars = Math.floor(allowedTokens * 4); // Approximate conversion
235
-
236
- const result = this.truncateText(component.content, allowedChars, component.source || 'user_message');
237
- truncatedComponents.push({
238
- ...component,
239
- content: result.text,
240
- truncated: result.truncated,
241
- originalContent: result.originalContent,
242
- truncatedAt: result.truncatedAt,
243
- truncationReason: `User message truncated to fit within ${this.config.maxUserMessagesTokens} token limit for user messages`
244
- });
245
-
246
- const actualTokens = this.estimateTokens(result.text);
247
- tokensUsed += actualTokens;
248
- userTokensUsed += actualTokens;
249
- tokensReduced += componentTokens - actualTokens;
250
-
251
- if (result.truncated) {
252
- this.logger.warn("User message truncated to fit limit", {
253
- componentSource: component.source,
254
- originalTokens: componentTokens,
255
- truncatedTokens: actualTokens,
256
- userTokenLimit: this.config.maxUserMessagesTokens
257
- });
258
- }
259
- }
260
- // Skip user messages that don't fit in the 20k limit
261
- });
262
-
263
- // Step 3: Add assistant responses if we have room
264
- assistantComponents.forEach(component => {
265
- const componentTokens = this.estimateTokens(component.content);
266
- if (tokensUsed + componentTokens <= this.config.maxTotalTokens - targetTokenReduction) {
267
- truncatedComponents.push({ ...component });
268
- tokensUsed += componentTokens;
269
- }
270
- // Skip assistant messages if no room
271
- });
272
-
273
- // Step 4: Add tool responses with truncation if needed
274
- const remainingTokenBudget = this.config.maxTotalTokens - tokensUsed;
275
- let toolBudgetUsed = 0;
276
-
277
- toolComponents.forEach(component => {
278
- const componentTokens = this.estimateTokens(component.content);
279
-
280
- if (toolBudgetUsed + componentTokens <= remainingTokenBudget) {
281
- // Tool response fits fully
282
- truncatedComponents.push({ ...component });
283
- tokensUsed += componentTokens;
284
- toolBudgetUsed += componentTokens;
285
- } else if (toolBudgetUsed < remainingTokenBudget) {
286
- // Partial truncation of tool response
287
- const allowedTokens = remainingTokenBudget - toolBudgetUsed;
288
- const allowedChars = Math.floor(allowedTokens * 4);
289
-
290
- const result = this.truncateText(component.content, allowedChars, component.source || 'tool_result');
291
- truncatedComponents.push({
292
- ...component,
293
- content: result.text,
294
- truncated: result.truncated,
295
- originalContent: result.originalContent,
296
- truncatedAt: result.truncatedAt,
297
- truncationReason: `Tool response truncated to fit within ${this.config.maxTotalTokens} token total limit`
298
- });
299
-
300
- const actualTokens = this.estimateTokens(result.text);
301
- tokensUsed += actualTokens;
302
- toolBudgetUsed += actualTokens;
303
- tokensReduced += componentTokens - actualTokens;
304
-
305
- if (result.truncated) {
306
- this.logger.warn("Tool response truncated", {
307
- toolSource: component.source,
308
- originalTokens: componentTokens,
309
- truncatedTokens: actualTokens,
310
- originalLength: component.content.length,
311
- truncatedLength: result.text.length,
312
- truncationMethod: result.truncationMethod,
313
- truncatedAt: result.truncatedAt
314
- });
315
- }
316
- }
317
- // Skip tool responses that don't fit
318
- });
319
-
320
- // Step 5: Handle unknown component types
321
- otherComponents.forEach(component => {
322
- this.logger.warn("Unknown component type in prompt", {
323
- type: component.type,
324
- source: component.source,
325
- length: component.content.length,
326
- tokens: this.estimateTokens(component.content),
327
- note: "Added to debug page for analysis"
328
- });
329
-
330
- // Add to debug but don't include in prompt for now
331
- truncatedComponents.push({
332
- ...component,
333
- truncationReason: `Unknown component type '${component.type}' - review on debug page`
334
- });
335
- });
336
-
337
- const finalTokens = this.estimateTokens(truncatedComponents.map(c => c.content).join(''));
338
-
339
- return {
340
- totalCharacters: truncatedComponents.reduce((sum, c) => sum + c.content.length, 0),
341
- estimatedTokens: finalTokens,
342
- components: truncatedComponents,
343
- truncationApplied: tokensReduced > 0,
344
- warnings: [
345
- ...analysis.warnings,
346
- `Applied Claude 4 smart truncation: reduced by ${tokensReduced} tokens (${Math.round(tokensReduced / analysis.estimatedTokens * 100)}%)`,
347
- `Preservation strategy: System (100%) → User (up to 20k tokens) → Assistant → Tools`,
348
- `Final prompt: ${finalTokens.toLocaleString()} tokens (limit: ${this.config.maxTotalTokens.toLocaleString()})`
349
- ],
350
- };
351
- */ // END OF COMMENTED OUT TRUNCATION LOGIC
352
- }
353
- /**
354
- * Check if a provider-specific error indicates prompt too long
355
- */
356
- isPromptTooLongError(error, provider) {
357
- const errorMessage = error.message.toLowerCase();
358
- if (provider === 'anthropic') {
359
- return errorMessage.includes('prompt too long') ||
360
- errorMessage.includes('maximum context length') ||
361
- errorMessage.includes('context_length_exceeded') ||
362
- errorMessage.includes('token limit exceeded');
363
- }
364
- if (provider === 'openai') {
365
- return errorMessage.includes('maximum context length') ||
366
- errorMessage.includes('context_length_exceeded') ||
367
- errorMessage.includes('token limit exceeded') ||
368
- errorMessage.includes('reduce the length');
369
- }
370
- return false;
371
- }
372
- /**
373
- * Log comprehensive debug information about prompt structure
374
- */
375
- logPromptDebugInfo(analysis, provider, botId) {
376
- const debugData = {
377
- provider,
378
- botId,
379
- summary: {
380
- totalCharacters: analysis.totalCharacters,
381
- estimatedTokens: analysis.estimatedTokens,
382
- componentCount: analysis.components.length,
383
- truncationApplied: analysis.truncationApplied,
384
- warningCount: analysis.warnings.length,
385
- },
386
- breakdown: analysis.components.map(comp => ({
387
- type: comp.type,
388
- source: comp.source,
389
- currentLength: comp.content.length,
390
- originalLength: comp.originalLength || comp.content.length,
391
- truncated: comp.truncated,
392
- reductionPercent: comp.originalLength ?
393
- Math.round((1 - comp.content.length / comp.originalLength) * 100) : 0,
394
- estimatedTokens: this.estimateTokens(comp.content),
395
- // First 100 chars as preview (for debugging)
396
- preview: comp.content.substring(0, 100) + (comp.content.length > 100 ? '...' : ''),
397
- })),
398
- warnings: analysis.warnings,
399
- };
400
- this.logger.info("Prompt debug analysis", debugData);
401
- // Enhanced truncation logging
402
- const truncatedComponents = analysis.components.filter(c => c.truncated);
403
- if (truncatedComponents.length > 0) {
404
- this.logger.warn("Component truncation summary", {
405
- truncatedCount: truncatedComponents.length,
406
- totalComponents: analysis.components.length,
407
- truncations: truncatedComponents.map(comp => ({
408
- type: comp.type,
409
- source: comp.source,
410
- originalChars: comp.originalLength,
411
- truncatedChars: comp.content.length,
412
- savedChars: (comp.originalLength || comp.content.length) - comp.content.length,
413
- reductionPercent: comp.originalLength ?
414
- Math.round((1 - comp.content.length / comp.originalLength) * 100) : 0,
415
- }))
416
- });
417
- }
418
- // Log full prompt to separate file if it was truncated or has warnings
419
- if (analysis.truncationApplied || analysis.warnings.length > 0) {
420
- this.logger.warn("Prompt required attention", {
421
- reason: analysis.truncationApplied ? 'truncation' : 'warnings',
422
- fullPrompt: analysis.components.map(c => `=== ${c.type.toUpperCase()} (${c.source || 'unknown'}) ===\n${c.content}`).join('\n\n'),
423
- });
424
- }
425
- }
426
- /**
427
- * Generate a quick truncation summary for debugging
428
- */
429
- generateTruncationSummary(analysis) {
430
- const totalOriginal = analysis.components.reduce((sum, comp) => sum + (comp.originalLength || comp.content.length), 0);
431
- const totalCurrent = analysis.totalCharacters;
432
- const totalSaved = totalOriginal - totalCurrent;
433
- const overallReduction = totalOriginal > 0 ? Math.round((totalSaved / totalOriginal) * 100) : 0;
434
- const truncatedComponents = analysis.components.filter(c => c.truncated);
435
- let summary = `Prompt Summary: ${totalCurrent.toLocaleString()} chars (${analysis.estimatedTokens.toLocaleString()} tokens)`;
436
- if (totalSaved > 0) {
437
- summary += `\nTruncation Applied: Saved ${totalSaved.toLocaleString()} chars (${overallReduction}% reduction)`;
438
- summary += `\nTruncated Components: ${truncatedComponents.length}/${analysis.components.length}`;
439
- if (truncatedComponents.length > 0) {
440
- summary += `\nBreakdown:`;
441
- truncatedComponents.forEach(comp => {
442
- const saved = (comp.originalLength || comp.content.length) - comp.content.length;
443
- const percent = comp.originalLength ? Math.round((saved / comp.originalLength) * 100) : 0;
444
- summary += `\n - ${comp.type} (${comp.source}): ${saved.toLocaleString()} chars saved (${percent}%)`;
445
- });
446
- }
447
- }
448
- else {
449
- summary += `\nNo truncation applied`;
450
- }
451
- return summary;
452
- }
453
- }
454
- exports.PromptLengthManager = PromptLengthManager;
455
- // Export a default instance
456
- exports.promptLengthManager = new PromptLengthManager();
457
- //# sourceMappingURL=prompt-length-manager.js.map
@@ -1,21 +0,0 @@
1
- /**
2
- * Giuseppe MCP Tools
3
- *
4
- * Bug-fixing tools for Giuseppe specialist daemon.
5
- * These tools handle file operations, git, and build commands.
6
- */
7
- import { Tool } from "../tool-registry";
8
- export declare const giuseppeFindAppTool: Tool;
9
- export declare const giuseppeListFilesTool: Tool;
10
- export declare const giuseppeReadFileTool: Tool;
11
- export declare const giuseppeWriteFileTool: Tool;
12
- export declare const giuseppeApplyFixTool: Tool;
13
- export declare const giuseppeRunBuildTool: Tool;
14
- export declare const giuseppeGitStatusTool: Tool;
15
- export declare const giuseppeGitPullTool: Tool;
16
- export declare const giuseppeGitCommitTool: Tool;
17
- export declare const giuseppeGitPushTool: Tool;
18
- export declare const giuseppeGitRevertTool: Tool;
19
- export declare const giuseppePublishAppTool: Tool;
20
- export declare const giuseppeTools: Tool[];
21
- //# sourceMappingURL=giuseppe-tools.d.ts.map
@@ -1,25 +0,0 @@
1
- /**
2
- * Bug Reports Module - Configuration Discovery
3
- *
4
- * Discovers Bug Reports workflow by name pattern.
5
- * No hardcoded IDs - works in any workspace.
6
- */
7
- import type { UserContext } from '../../mcp/UserContextCache';
8
- import type { BugReportsConfig, WorkflowDiscoveryResult } from './types';
9
- /**
10
- * Discover Bug Reports workflow in a workspace
11
- */
12
- export declare function discoverWorkflow(userContext: UserContext, config: BugReportsConfig): Promise<WorkflowDiscoveryResult | null>;
13
- /**
14
- * Load config from MCP Config workflow or environment
15
- */
16
- export declare function loadConfig(userContext: UserContext): Promise<BugReportsConfig>;
17
- /**
18
- * Get default configuration
19
- */
20
- export declare function getDefaultConfig(): BugReportsConfig;
21
- /**
22
- * Save config back to Hailer (creates/updates config activity)
23
- */
24
- export declare function saveConfig(userContext: UserContext, config: BugReportsConfig): Promise<boolean>;
25
- //# sourceMappingURL=bug-config.d.ts.map