tachibot-mcp 2.0.2

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 (214) hide show
  1. package/.env.example +260 -0
  2. package/CHANGELOG.md +54 -0
  3. package/CODE_OF_CONDUCT.md +56 -0
  4. package/CONTRIBUTING.md +54 -0
  5. package/Dockerfile +36 -0
  6. package/LICENSE +644 -0
  7. package/README.md +201 -0
  8. package/SECURITY.md +95 -0
  9. package/dist/personality/komaai-expressions.js +12 -0
  10. package/dist/profiles/balanced.json +33 -0
  11. package/dist/profiles/code_focus.json +33 -0
  12. package/dist/profiles/full.json +33 -0
  13. package/dist/profiles/minimal.json +33 -0
  14. package/dist/profiles/research_power.json +33 -0
  15. package/dist/scripts/build-profiles.js +46 -0
  16. package/dist/src/application/services/focus/FocusModeRegistry.js +46 -0
  17. package/dist/src/application/services/focus/FocusTool.service.js +109 -0
  18. package/dist/src/application/services/focus/ModeRegistry.js +46 -0
  19. package/dist/src/application/services/focus/modes/focus-deep.mode.js +27 -0
  20. package/dist/src/application/services/focus/modes/status.mode.js +50 -0
  21. package/dist/src/application/services/focus/modes/tachibot-status.mode.js +50 -0
  22. package/dist/src/collaborative-orchestrator.js +391 -0
  23. package/dist/src/config/model-constants.js +188 -0
  24. package/dist/src/config/model-defaults.js +57 -0
  25. package/dist/src/config/model-preferences.js +382 -0
  26. package/dist/src/config/timeout-config.js +130 -0
  27. package/dist/src/config.js +173 -0
  28. package/dist/src/domain/interfaces/IFocusMode.js +5 -0
  29. package/dist/src/domain/interfaces/IProvider.js +6 -0
  30. package/dist/src/domain/interfaces/ITool.js +5 -0
  31. package/dist/src/focus-deep.js +245 -0
  32. package/dist/src/infrastructure/ascii/art/robots.ascii.js +16 -0
  33. package/dist/src/mcp-client.js +90 -0
  34. package/dist/src/memory/index.js +17 -0
  35. package/dist/src/memory/memory-config.js +135 -0
  36. package/dist/src/memory/memory-interface.js +174 -0
  37. package/dist/src/memory/memory-manager.js +383 -0
  38. package/dist/src/memory/providers/devlog-provider.js +385 -0
  39. package/dist/src/memory/providers/hybrid-provider.js +399 -0
  40. package/dist/src/memory/providers/local-provider.js +388 -0
  41. package/dist/src/memory/providers/mem0-provider.js +337 -0
  42. package/dist/src/modes/architect.js +477 -0
  43. package/dist/src/modes/auditor.js +362 -0
  44. package/dist/src/modes/challenger.js +841 -0
  45. package/dist/src/modes/code-reviewer.js +382 -0
  46. package/dist/src/modes/commit-guardian.js +424 -0
  47. package/dist/src/modes/documentation-writer.js +572 -0
  48. package/dist/src/modes/scout.js +587 -0
  49. package/dist/src/modes/shared/helpers/challenger-helpers.js +454 -0
  50. package/dist/src/modes/shared/helpers/index.js +17 -0
  51. package/dist/src/modes/shared/helpers/scout-helpers.js +270 -0
  52. package/dist/src/modes/shared/helpers/verifier-helpers.js +332 -0
  53. package/dist/src/modes/test-architect.js +767 -0
  54. package/dist/src/modes/verifier.js +378 -0
  55. package/dist/src/monitoring/performance-monitor.js +435 -0
  56. package/dist/src/optimization/batch-executor.js +121 -0
  57. package/dist/src/optimization/context-pruner.js +196 -0
  58. package/dist/src/optimization/cost-monitor.js +338 -0
  59. package/dist/src/optimization/index.js +65 -0
  60. package/dist/src/optimization/model-router.js +264 -0
  61. package/dist/src/optimization/result-cache.js +114 -0
  62. package/dist/src/optimization/token-optimizer.js +257 -0
  63. package/dist/src/optimization/token-tracker.js +118 -0
  64. package/dist/src/orchestrator-instructions.js +128 -0
  65. package/dist/src/orchestrator-lite.js +139 -0
  66. package/dist/src/orchestrator.js +191 -0
  67. package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionEngine.js +1 -0
  68. package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionStrategy.js +5 -0
  69. package/dist/src/orchestrators/collaborative/interfaces/IVisualizationRenderer.js +1 -0
  70. package/dist/src/orchestrators/collaborative/registries/ModelProviderRegistry.js +95 -0
  71. package/dist/src/orchestrators/collaborative/registries/ToolAdapterRegistry.js +64 -0
  72. package/dist/src/orchestrators/collaborative/services/tool-execution/ToolExecutionService.js +502 -0
  73. package/dist/src/orchestrators/collaborative/services/visualization/VisualizationService.js +206 -0
  74. package/dist/src/orchestrators/collaborative/types/session-types.js +5 -0
  75. package/dist/src/profiles/balanced.js +37 -0
  76. package/dist/src/profiles/code_focus.js +37 -0
  77. package/dist/src/profiles/debug_intensive.js +59 -0
  78. package/dist/src/profiles/full.js +37 -0
  79. package/dist/src/profiles/minimal.js +37 -0
  80. package/dist/src/profiles/research_code.js +59 -0
  81. package/dist/src/profiles/research_power.js +37 -0
  82. package/dist/src/profiles/types.js +5 -0
  83. package/dist/src/profiles/workflow_builder.js +53 -0
  84. package/dist/src/prompt-engineer-lite.js +78 -0
  85. package/dist/src/prompt-engineer.js +399 -0
  86. package/dist/src/reasoning-chain.js +508 -0
  87. package/dist/src/sequential-thinking.js +291 -0
  88. package/dist/src/server-diagnostic.js +74 -0
  89. package/dist/src/server-raw.js +158 -0
  90. package/dist/src/server-simple.js +58 -0
  91. package/dist/src/server.js +514 -0
  92. package/dist/src/session/session-logger.js +617 -0
  93. package/dist/src/session/session-manager.js +571 -0
  94. package/dist/src/session/session-tools.js +400 -0
  95. package/dist/src/tools/advanced-modes.js +200 -0
  96. package/dist/src/tools/claude-integration.js +356 -0
  97. package/dist/src/tools/consolidated/ai-router.js +174 -0
  98. package/dist/src/tools/consolidated/ai-tool.js +48 -0
  99. package/dist/src/tools/consolidated/brainstorm-tool.js +87 -0
  100. package/dist/src/tools/consolidated/environment-detector.js +80 -0
  101. package/dist/src/tools/consolidated/index.js +50 -0
  102. package/dist/src/tools/consolidated/search-tool.js +110 -0
  103. package/dist/src/tools/consolidated/workflow-tool.js +238 -0
  104. package/dist/src/tools/gemini-tools.js +329 -0
  105. package/dist/src/tools/grok-enhanced.js +376 -0
  106. package/dist/src/tools/grok-tools.js +299 -0
  107. package/dist/src/tools/lmstudio-tools.js +223 -0
  108. package/dist/src/tools/openai-tools.js +498 -0
  109. package/dist/src/tools/openrouter-tools.js +317 -0
  110. package/dist/src/tools/optimized-wrapper.js +204 -0
  111. package/dist/src/tools/perplexity-tools.js +294 -0
  112. package/dist/src/tools/pingpong-tool.js +343 -0
  113. package/dist/src/tools/qwen-wrapper.js +74 -0
  114. package/dist/src/tools/tool-router.js +444 -0
  115. package/dist/src/tools/unified-ai-provider.js +260 -0
  116. package/dist/src/tools/workflow-runner.js +425 -0
  117. package/dist/src/tools/workflow-validator-tool.js +107 -0
  118. package/dist/src/types.js +23 -0
  119. package/dist/src/utils/input-validator.js +130 -0
  120. package/dist/src/utils/model-router.js +91 -0
  121. package/dist/src/utils/progress-stream.js +255 -0
  122. package/dist/src/utils/provider-router.js +88 -0
  123. package/dist/src/utils/smart-api-client.js +146 -0
  124. package/dist/src/utils/table-builder.js +218 -0
  125. package/dist/src/utils/timestamp-formatter.js +134 -0
  126. package/dist/src/utils/tool-compressor.js +257 -0
  127. package/dist/src/utils/tool-config.js +201 -0
  128. package/dist/src/validators/dependency-graph-validator.js +147 -0
  129. package/dist/src/validators/interpolation-validator.js +222 -0
  130. package/dist/src/validators/output-usage-validator.js +151 -0
  131. package/dist/src/validators/syntax-validator.js +102 -0
  132. package/dist/src/validators/tool-registry-validator.js +123 -0
  133. package/dist/src/validators/tool-types.js +97 -0
  134. package/dist/src/validators/types.js +8 -0
  135. package/dist/src/validators/workflow-validator.js +134 -0
  136. package/dist/src/visualizer-lite.js +42 -0
  137. package/dist/src/visualizer.js +179 -0
  138. package/dist/src/workflows/circuit-breaker.js +199 -0
  139. package/dist/src/workflows/custom-workflows.js +451 -0
  140. package/dist/src/workflows/engine/AutoSynthesizer.js +97 -0
  141. package/dist/src/workflows/engine/StepParameterResolver.js +74 -0
  142. package/dist/src/workflows/engine/VariableInterpolator.js +123 -0
  143. package/dist/src/workflows/engine/WorkflowDiscovery.js +125 -0
  144. package/dist/src/workflows/engine/WorkflowExecutionEngine.js +485 -0
  145. package/dist/src/workflows/engine/WorkflowExecutor.js +113 -0
  146. package/dist/src/workflows/engine/WorkflowFileManager.js +244 -0
  147. package/dist/src/workflows/engine/WorkflowHelpers.js +114 -0
  148. package/dist/src/workflows/engine/WorkflowOutputFormatter.js +83 -0
  149. package/dist/src/workflows/engine/events/WorkflowEventBus.js +132 -0
  150. package/dist/src/workflows/engine/events/interfaces/IEventBus.js +5 -0
  151. package/dist/src/workflows/engine/handlers/ErrorRecoveryHandler.js +162 -0
  152. package/dist/src/workflows/engine/handlers/PromptEnhancementHandler.js +115 -0
  153. package/dist/src/workflows/engine/handlers/SessionPersistenceHandler.js +167 -0
  154. package/dist/src/workflows/engine/handlers/StepExecutionHandler.js +231 -0
  155. package/dist/src/workflows/engine/handlers/ToolInvocationHandler.js +46 -0
  156. package/dist/src/workflows/engine/interfaces/IAutoSynthesizer.js +5 -0
  157. package/dist/src/workflows/engine/interfaces/IStepParameterResolver.js +5 -0
  158. package/dist/src/workflows/engine/interfaces/IVariableInterpolator.js +5 -0
  159. package/dist/src/workflows/engine/interfaces/IWorkflowDiscovery.js +4 -0
  160. package/dist/src/workflows/engine/interfaces/IWorkflowFileManager.js +5 -0
  161. package/dist/src/workflows/engine/interfaces/IWorkflowOutputFormatter.js +5 -0
  162. package/dist/src/workflows/engine/state/WorkflowStateMachine.js +194 -0
  163. package/dist/src/workflows/engine/state/interfaces/IStateMachine.js +17 -0
  164. package/dist/src/workflows/fallback-strategies.js +373 -0
  165. package/dist/src/workflows/message-queue.js +455 -0
  166. package/dist/src/workflows/model-router.js +189 -0
  167. package/dist/src/workflows/orchestrator-examples.js +174 -0
  168. package/dist/src/workflows/orchestrator-integration.js +200 -0
  169. package/dist/src/workflows/self-healing.js +524 -0
  170. package/dist/src/workflows/tool-mapper.js +407 -0
  171. package/dist/src/workflows/tool-orchestrator.js +796 -0
  172. package/dist/src/workflows/workflow-engine.js +573 -0
  173. package/dist/src/workflows/workflow-parser.js +283 -0
  174. package/dist/src/workflows/workflow-types.js +95 -0
  175. package/dist/src/workflows.js +568 -0
  176. package/dist/test-workflow-file-output.js +93 -0
  177. package/docs/API_KEYS.md +570 -0
  178. package/docs/CLAUDE_CODE_SETUP.md +181 -0
  179. package/docs/CLAUDE_DESKTOP_MANUAL.md +127 -0
  180. package/docs/CONFIGURATION.md +745 -0
  181. package/docs/FOCUS_MODES.md +240 -0
  182. package/docs/INSTALLATION_BOTH.md +145 -0
  183. package/docs/TERMS.md +352 -0
  184. package/docs/TOOLS_REFERENCE.md +1622 -0
  185. package/docs/TOOL_PARAMETERS.md +496 -0
  186. package/docs/TOOL_PROFILES.md +236 -0
  187. package/docs/WORKFLOWS.md +987 -0
  188. package/docs/WORKFLOW_OUTPUT.md +198 -0
  189. package/docs/WORKFLOW_PROGRESS_TRACKING.md +305 -0
  190. package/docs/workflows/design-brainstorm.md +335 -0
  191. package/package.json +97 -0
  192. package/profiles/balanced.json +37 -0
  193. package/profiles/code_focus.json +37 -0
  194. package/profiles/debug_intensive.json +34 -0
  195. package/profiles/full.json +37 -0
  196. package/profiles/minimal.json +37 -0
  197. package/profiles/research_power.json +37 -0
  198. package/profiles/workflow_builder.json +37 -0
  199. package/smithery.yaml +66 -0
  200. package/start.sh +8 -0
  201. package/tools.config.json +81 -0
  202. package/tsconfig.json +18 -0
  203. package/workflows/accessibility-code-audit.yaml +92 -0
  204. package/workflows/code-architecture-review.yaml +202 -0
  205. package/workflows/code-review.yaml +142 -0
  206. package/workflows/core/iterative-problem-solver.yaml +283 -0
  207. package/workflows/creative-brainstorm-yaml.yaml +215 -0
  208. package/workflows/pingpong.yaml +141 -0
  209. package/workflows/system/README.md +412 -0
  210. package/workflows/system/challenger.yaml +175 -0
  211. package/workflows/system/scout.yaml +164 -0
  212. package/workflows/system/verifier.yaml +133 -0
  213. package/workflows/ultra-creative-brainstorm.yaml +318 -0
  214. package/workflows/ux-research-flow.yaml +92 -0
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Registry for tool execution strategies
3
+ * Simple pattern: register strategies, find by model name
4
+ */
5
+ export class ToolAdapterRegistry {
6
+ constructor() {
7
+ this.strategies = new Map();
8
+ this.fallbackStrategy = null;
9
+ }
10
+ /**
11
+ * Register a tool execution strategy
12
+ */
13
+ register(strategy) {
14
+ this.strategies.set(strategy.name, strategy);
15
+ }
16
+ /**
17
+ * Register multiple strategies at once
18
+ */
19
+ registerMany(strategies) {
20
+ strategies.forEach(s => this.register(s));
21
+ }
22
+ /**
23
+ * Set a fallback strategy for when no specific strategy is found
24
+ */
25
+ setFallback(strategy) {
26
+ this.fallbackStrategy = strategy;
27
+ }
28
+ /**
29
+ * Find the best strategy for a given model
30
+ * Returns null if no strategy can handle the model
31
+ */
32
+ findStrategy(model) {
33
+ // First, try exact match by strategy name
34
+ const exactMatch = this.strategies.get(model);
35
+ if (exactMatch && exactMatch.canExecute(model)) {
36
+ return exactMatch;
37
+ }
38
+ // Then, try all strategies to see if any can execute this model
39
+ for (const strategy of Array.from(this.strategies.values())) {
40
+ if (strategy.canExecute(model)) {
41
+ return strategy;
42
+ }
43
+ }
44
+ // Finally, use fallback if available
45
+ if (this.fallbackStrategy && this.fallbackStrategy.canExecute(model)) {
46
+ return this.fallbackStrategy;
47
+ }
48
+ return null;
49
+ }
50
+ /**
51
+ * Get all registered strategy names
52
+ */
53
+ getRegisteredStrategies() {
54
+ return Array.from(this.strategies.keys());
55
+ }
56
+ /**
57
+ * Check if a strategy is registered for a model
58
+ */
59
+ hasStrategy(model) {
60
+ return this.findStrategy(model) !== null;
61
+ }
62
+ }
63
+ // Singleton instance for global use
64
+ export const toolAdapterRegistry = new ToolAdapterRegistry();
@@ -0,0 +1,502 @@
1
+ import { ReasoningMode } from "../../../../reasoning-chain.js";
2
+ import { ToolRouter, ToolCategory } from "../../../../tools/tool-router.js";
3
+ import { modelProviderRegistry } from "../../registries/ModelProviderRegistry.js";
4
+ /**
5
+ * Tool Execution Service
6
+ * Handles execution of AI model tools with parameter building and error handling
7
+ * Extracted from CollaborativeOrchestrator (482 lines!)
8
+ */
9
+ export class ToolExecutionService {
10
+ constructor(options) {
11
+ this.verbose = false;
12
+ this.memoryManager = null;
13
+ this.enableMemory = false;
14
+ this.toolRouter = options?.toolRouter || new ToolRouter({
15
+ verboseLogging: false,
16
+ qualityPriority: true,
17
+ fallbackEnabled: true
18
+ });
19
+ this.memoryManager = options?.memoryManager || null;
20
+ this.enableMemory = options?.enableMemory || false;
21
+ this.verbose = options?.verbose || false;
22
+ }
23
+ setVerbose(verbose) {
24
+ this.verbose = verbose;
25
+ }
26
+ /**
27
+ * Execute real tool based on model and reasoning mode
28
+ */
29
+ async executeRealTool(model, prompt, mode, context) {
30
+ const startTime = Date.now();
31
+ // Map model names to actual tool names
32
+ const toolName = this.getToolNameForModel(model, mode);
33
+ if (!toolName) {
34
+ console.error(`āŒ No tool mapping found for model: ${model}, mode: ${mode}`);
35
+ return `[No tool available for ${model}: ${prompt.substring(0, 50)}...]`;
36
+ }
37
+ try {
38
+ // Log tool execution start
39
+ if (this.verbose) {
40
+ console.error(`\nšŸ”§ Executing tool: ${toolName} for model: ${model}`);
41
+ console.error(`šŸ“ Prompt preview: ${prompt.substring(0, 100)}...`);
42
+ }
43
+ // Get the tool parameters based on the specific tool
44
+ let toolParams = this.buildToolParameters(toolName, prompt, mode, context);
45
+ // Enrich with memory context if enabled
46
+ if (this.enableMemory && this.memoryManager) {
47
+ toolParams = await this.enrichWithMemoryContext(toolParams, prompt);
48
+ }
49
+ // Execute the tool via MCP server or direct execution
50
+ const result = await this.executeMCPTool(toolName, toolParams);
51
+ // Store result in memory if enabled
52
+ if (this.enableMemory && this.memoryManager && result) {
53
+ await this.storeInMemory(result, toolName, model);
54
+ }
55
+ // Log success
56
+ const duration = Date.now() - startTime;
57
+ if (this.verbose) {
58
+ console.error(`āœ… Tool ${toolName} completed in ${duration}ms`);
59
+ console.error(`šŸ“Š Response length: ${result.length} characters`);
60
+ }
61
+ // Validate result
62
+ if (!result || result.trim() === '') {
63
+ console.warn(`āš ļø Tool ${toolName} returned empty response`);
64
+ return `[${model} returned empty response for: ${prompt.substring(0, 50)}...]`;
65
+ }
66
+ return result;
67
+ }
68
+ catch (error) {
69
+ const errorMsg = error instanceof Error ? error.message : String(error);
70
+ console.error(`āŒ Error executing ${toolName}:`, errorMsg);
71
+ // Log full error stack in verbose mode
72
+ if (this.verbose && error instanceof Error) {
73
+ console.error(`Stack trace:`, error.stack);
74
+ }
75
+ // Return a more informative error message
76
+ return `[Error with ${toolName} (${model}): ${errorMsg}. Prompt: ${prompt.substring(0, 50)}...]`;
77
+ }
78
+ }
79
+ /**
80
+ * Map model names to actual MCP tool names
81
+ */
82
+ getToolNameForModel(model, mode) {
83
+ // Try registry first
84
+ const toolName = modelProviderRegistry.getToolName(model);
85
+ if (toolName) {
86
+ return toolName;
87
+ }
88
+ // Mode-based fallback using tool router
89
+ const category = this.reasoningModeToToolCategory(mode);
90
+ const tool = this.toolRouter.getBestTool(category);
91
+ return tool?.name || "think"; // fallback to think tool
92
+ }
93
+ /**
94
+ * Map reasoning modes to tool categories
95
+ */
96
+ reasoningModeToToolCategory(mode) {
97
+ switch (mode) {
98
+ case ReasoningMode.BRAINSTORM:
99
+ return ToolCategory.BRAINSTORM;
100
+ case ReasoningMode.CRITIQUE:
101
+ case ReasoningMode.VALIDATE:
102
+ return ToolCategory.ANALYSIS;
103
+ case ReasoningMode.ENHANCE:
104
+ case ReasoningMode.DEEP_REASONING:
105
+ case ReasoningMode.CONSENSUS:
106
+ case ReasoningMode.DEBATE:
107
+ case ReasoningMode.SYNTHESIZE:
108
+ case ReasoningMode.PINGPONG:
109
+ return ToolCategory.REASONING;
110
+ default:
111
+ return ToolCategory.REASONING;
112
+ }
113
+ }
114
+ /**
115
+ * Build parameters for specific tools
116
+ */
117
+ buildToolParameters(toolName, prompt, mode, context) {
118
+ switch (toolName) {
119
+ case "qwen_coder":
120
+ return {
121
+ task: "generate",
122
+ requirements: prompt,
123
+ language: "typescript"
124
+ };
125
+ case "qwq_reason":
126
+ return {
127
+ problem: prompt,
128
+ approach: "step-by-step"
129
+ };
130
+ case "kimi_thinking":
131
+ return {
132
+ problem: prompt,
133
+ approach: "step-by-step",
134
+ maxSteps: 10
135
+ };
136
+ case "grok_reason":
137
+ return {
138
+ problem: prompt,
139
+ approach: "first-principles"
140
+ };
141
+ case "grok_brainstorm":
142
+ return {
143
+ topic: prompt,
144
+ numIdeas: 5
145
+ };
146
+ case "gemini_query":
147
+ case "gemini_brainstorm":
148
+ return {
149
+ prompt: prompt
150
+ };
151
+ case "perplexity_ask":
152
+ return {
153
+ query: prompt
154
+ };
155
+ case "perplexity_reason":
156
+ return {
157
+ problem: prompt,
158
+ approach: "analytical"
159
+ };
160
+ case "gpt5_analyze":
161
+ return {
162
+ query: prompt,
163
+ analysisType: "strategy"
164
+ };
165
+ case "gpt5_reason":
166
+ case "gpt5_mini_reason":
167
+ return {
168
+ query: prompt,
169
+ mode: "analytical"
170
+ };
171
+ case "think":
172
+ return {
173
+ thought: prompt
174
+ };
175
+ default:
176
+ return { prompt: prompt };
177
+ }
178
+ }
179
+ /**
180
+ * Execute MCP tool via direct tool imports
181
+ */
182
+ async executeMCPTool(toolName, params) {
183
+ // Fallback responses for when API keys are missing
184
+ const fallbackResponses = {
185
+ "grok_reason": (p) => `### Grok Analysis (First Principles)
186
+ **Problem**: ${p.problem || p.prompt || 'No input'}
187
+
188
+ Using first principles thinking:
189
+ 1. **Core Components**: Breaking down the problem into fundamental elements
190
+ 2. **Root Cause**: Identifying the underlying constraints and requirements
191
+ 3. **Unconventional Approach**: Consider solutions that challenge assumptions
192
+ 4. **Scalability**: How this scales from first principles
193
+
194
+ **Recommendation**: Focus on the simplest solution that addresses the core need.`,
195
+ "gemini_query": (p) => `### Gemini Synthesis
196
+ **Query**: ${p.prompt || 'No input'}
197
+
198
+ Creative connections:
199
+ - **Pattern Recognition**: Identifying similar patterns in different domains
200
+ - **Innovation Opportunity**: Novel combinations of existing solutions
201
+ - **Cross-Domain Insights**: Applying concepts from unrelated fields
202
+
203
+ **Synthesis**: Multiple perspectives converge on a balanced approach.`,
204
+ "perplexity_ask": (p) => `### Perplexity Research
205
+ **Query**: ${p.query || 'No input'}
206
+
207
+ Based on research patterns:
208
+ - **Industry Standards**: Common approaches used in production systems
209
+ - **Best Practices**: Validated patterns from successful implementations
210
+ - **Data Points**: Key metrics to consider for evaluation
211
+
212
+ **Evidence**: Real-world implementations support this approach.`,
213
+ "gpt5_analyze": (p) => `### GPT-5 Strategic Analysis
214
+ **Content**: ${p.content || p.prompt || 'No input'}
215
+
216
+ Strategic considerations:
217
+ - **Business Impact**: ROI and resource requirements
218
+ - **Technical Feasibility**: Implementation complexity and timeline
219
+ - **Risk Assessment**: Potential pitfalls and mitigation strategies
220
+
221
+ **Analysis**: Balanced evaluation suggests a phased approach.`,
222
+ "think": (p) => `### Claude Code Reasoning
223
+ **Thought**: ${p.thought || p.prompt || 'No input'}
224
+
225
+ Systematic analysis:
226
+ 1. **Architecture**: Structural considerations for maintainability
227
+ 2. **Implementation**: Practical steps for execution
228
+ 3. **Edge Cases**: Handling exceptional scenarios
229
+ 4. **Testing Strategy**: Validation and quality assurance
230
+
231
+ **Conclusion**: Structured implementation with iterative refinement.`,
232
+ "kimi_thinking": (p) => `### Kimi K2 Agentic Reasoning
233
+ **Problem**: ${p.problem || p.prompt || 'No input'}
234
+
235
+ Step-by-step reasoning:
236
+ 1. **Problem Analysis**: Breaking down the core question and context
237
+ 2. **Approach Selection**: Choosing the most effective reasoning strategy
238
+ 3. **Multi-Step Exploration**: Working through the solution systematically
239
+ 4. **Validation**: Checking assumptions and logical consistency
240
+
241
+ **Conclusion**: Methodical approach leads to reliable solutions.`
242
+ };
243
+ try {
244
+ // Import and execute tools directly
245
+ switch (toolName) {
246
+ case "grok_reason":
247
+ const { grokReasonTool } = await import("../../../../tools/grok-tools.js");
248
+ const grokResult = await grokReasonTool.execute(params, {
249
+ log: {
250
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
251
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
252
+ }
253
+ });
254
+ return typeof grokResult === 'string' ? grokResult : JSON.stringify(grokResult);
255
+ case "grok_brainstorm":
256
+ const { grokBrainstormTool } = await import("../../../../tools/grok-tools.js");
257
+ const grokBrainstormResult = await grokBrainstormTool.execute(params, {
258
+ log: {
259
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
260
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
261
+ }
262
+ });
263
+ return typeof grokBrainstormResult === 'string' ? grokBrainstormResult : JSON.stringify(grokBrainstormResult);
264
+ case "gemini_query":
265
+ const { geminiQueryTool } = await import("../../../../tools/gemini-tools.js");
266
+ const geminiResult = await geminiQueryTool.execute(params, {
267
+ log: {
268
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
269
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
270
+ }
271
+ });
272
+ return typeof geminiResult === 'string' ? geminiResult : JSON.stringify(geminiResult);
273
+ case "perplexity_ask":
274
+ const { perplexityAskTool } = await import("../../../../tools/perplexity-tools.js");
275
+ const perplexityResult = await perplexityAskTool.execute(params, {
276
+ log: {
277
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
278
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
279
+ }
280
+ });
281
+ return typeof perplexityResult === 'string' ? perplexityResult : JSON.stringify(perplexityResult);
282
+ case "gpt5_analyze":
283
+ const { openAIBrainstormTool: analyzeTool } = await import("../../../../tools/openai-tools.js");
284
+ const analyzeResult = await analyzeTool.execute({
285
+ ...params,
286
+ model: "gpt-5-mini",
287
+ max_tokens: 2000
288
+ }, {
289
+ log: {
290
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
291
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
292
+ }
293
+ });
294
+ return typeof analyzeResult === 'string' ? analyzeResult : JSON.stringify(analyzeResult);
295
+ case "qwen_coder":
296
+ const { qwenCoderTool } = await import("../../../../tools/openrouter-tools.js");
297
+ const qwenResult = await qwenCoderTool.execute(params, {
298
+ log: {
299
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
300
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
301
+ }
302
+ });
303
+ return typeof qwenResult === 'string' ? qwenResult : JSON.stringify(qwenResult);
304
+ case "qwq_reason":
305
+ const { qwqReasoningTool } = await import("../../../../tools/openrouter-tools.js");
306
+ const qwqResult = await qwqReasoningTool.execute(params, {
307
+ log: {
308
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
309
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
310
+ }
311
+ });
312
+ return typeof qwqResult === 'string' ? qwqResult : JSON.stringify(qwqResult);
313
+ case "kimi_thinking":
314
+ const { kimiThinkingTool } = await import("../../../../tools/openrouter-tools.js");
315
+ const kimiResult = await kimiThinkingTool.execute(params, {
316
+ log: {
317
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
318
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
319
+ }
320
+ });
321
+ return typeof kimiResult === 'string' ? kimiResult : JSON.stringify(kimiResult);
322
+ case "perplexity_reason":
323
+ const { perplexityReasonTool } = await import("../../../../tools/perplexity-tools.js");
324
+ const perplexityReasonResult = await perplexityReasonTool.execute(params, {
325
+ log: {
326
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
327
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
328
+ }
329
+ });
330
+ return typeof perplexityReasonResult === 'string' ? perplexityReasonResult : JSON.stringify(perplexityReasonResult);
331
+ case "gpt5_reason":
332
+ const { gpt5ReasonTool } = await import("../../../../tools/openai-tools.js");
333
+ const gpt5Result = await gpt5ReasonTool.execute(params, {
334
+ log: {
335
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
336
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
337
+ }
338
+ });
339
+ return typeof gpt5Result === 'string' ? gpt5Result : JSON.stringify(gpt5Result);
340
+ case "gpt5_mini_reason":
341
+ const { gpt5MiniReasonTool } = await import("../../../../tools/openai-tools.js");
342
+ const gpt5MiniResult = await gpt5MiniReasonTool.execute(params, {
343
+ log: {
344
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
345
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
346
+ }
347
+ });
348
+ return typeof gpt5MiniResult === 'string' ? gpt5MiniResult : JSON.stringify(gpt5MiniResult);
349
+ case "openai_brainstorm":
350
+ const { openAIBrainstormTool } = await import("../../../../tools/openai-tools.js");
351
+ const openaiBrainstormResult = await openAIBrainstormTool.execute(params, {
352
+ log: {
353
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
354
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
355
+ }
356
+ });
357
+ return typeof openaiBrainstormResult === 'string' ? openaiBrainstormResult : JSON.stringify(openaiBrainstormResult);
358
+ case "gemini_brainstorm":
359
+ const { geminiBrainstormTool } = await import("../../../../tools/gemini-tools.js");
360
+ const geminiBrainstormResult = await geminiBrainstormTool.execute(params, {
361
+ log: {
362
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
363
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
364
+ }
365
+ });
366
+ return typeof geminiBrainstormResult === 'string' ? geminiBrainstormResult : JSON.stringify(geminiBrainstormResult);
367
+ case "grok_code":
368
+ const { grokCodeTool } = await import("../../../../tools/grok-tools.js");
369
+ const grokCodeResult = await grokCodeTool.execute(params, {
370
+ log: {
371
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
372
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
373
+ }
374
+ });
375
+ return typeof grokCodeResult === 'string' ? grokCodeResult : JSON.stringify(grokCodeResult);
376
+ case "grok_debug":
377
+ const { grokDebugTool } = await import("../../../../tools/grok-tools.js");
378
+ const grokDebugResult = await grokDebugTool.execute(params, {
379
+ log: {
380
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
381
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
382
+ }
383
+ });
384
+ return typeof grokDebugResult === 'string' ? grokDebugResult : JSON.stringify(grokDebugResult);
385
+ case "grok_architect":
386
+ const { grokArchitectTool } = await import("../../../../tools/grok-tools.js");
387
+ const grokArchitectResult = await grokArchitectTool.execute(params, {
388
+ log: {
389
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
390
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
391
+ }
392
+ });
393
+ return typeof grokArchitectResult === 'string' ? grokArchitectResult : JSON.stringify(grokArchitectResult);
394
+ case "qwen_general":
395
+ const { qwenGeneralTool } = await import("../../../../tools/openrouter-tools.js");
396
+ const qwenGeneralResult = await qwenGeneralTool.execute(params, {
397
+ log: {
398
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
399
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
400
+ }
401
+ });
402
+ return typeof qwenGeneralResult === 'string' ? qwenGeneralResult : JSON.stringify(qwenGeneralResult);
403
+ case "qwen_competitive":
404
+ const { qwenCompetitiveTool } = await import("../../../../tools/openrouter-tools.js");
405
+ const qwenCompetitiveResult = await qwenCompetitiveTool.execute(params, {
406
+ log: {
407
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
408
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
409
+ }
410
+ });
411
+ return typeof qwenCompetitiveResult === 'string' ? qwenCompetitiveResult : JSON.stringify(qwenCompetitiveResult);
412
+ case "think":
413
+ const { claudeIntegrationTool } = await import("../../../../tools/claude-integration.js");
414
+ const claudeResult = await claudeIntegrationTool.execute(params, {
415
+ log: {
416
+ info: (msg, data) => console.error(`[${toolName}] ${msg}`, data),
417
+ error: (msg, data) => console.error(`[${toolName}] ERROR: ${msg}`, data)
418
+ }
419
+ });
420
+ return typeof claudeResult === 'string' ? claudeResult : JSON.stringify(claudeResult);
421
+ default:
422
+ console.error(`Warning: Tool '${toolName}' not implemented, using fallback`);
423
+ return `[Tool ${toolName} not available - using fallback for: ${params.prompt || params.query || params.problem || 'no prompt'}]`;
424
+ }
425
+ }
426
+ catch (error) {
427
+ const errorMsg = error instanceof Error ? error.message : String(error);
428
+ console.error(`āŒ Failed to execute ${toolName}:`, errorMsg);
429
+ // Use fallback response if available
430
+ if (fallbackResponses[toolName]) {
431
+ console.error(`ā„¹ļø Using fallback response for ${toolName}`);
432
+ return fallbackResponses[toolName](params);
433
+ }
434
+ // Default fallback
435
+ return `[Tool ${toolName} not available - API key missing or service error. Using fallback for: ${params.prompt || params.query || params.problem || 'no prompt'}]`;
436
+ }
437
+ }
438
+ /**
439
+ * Enrich tool parameters with memory context
440
+ */
441
+ async enrichWithMemoryContext(params, prompt) {
442
+ if (!this.memoryManager)
443
+ return params;
444
+ try {
445
+ // Get relevant memory context
446
+ const context = await this.memoryManager.getContext(prompt, 1000);
447
+ if (context.items.length > 0) {
448
+ // Add memory context to parameters
449
+ const memoryContext = `\n\nšŸ“š Memory Context:\n${context.synthesis}`;
450
+ // Different parameter names for different tools
451
+ if ('prompt' in params) {
452
+ params.prompt = params.prompt + memoryContext;
453
+ }
454
+ else if ('query' in params) {
455
+ params.query = params.query + memoryContext;
456
+ }
457
+ else if ('problem' in params) {
458
+ params.problem = params.problem + memoryContext;
459
+ }
460
+ else if ('content' in params) {
461
+ params.content = params.content + memoryContext;
462
+ }
463
+ if (this.verbose) {
464
+ console.error(`🧠 Added ${context.items.length} memory items to context`);
465
+ }
466
+ }
467
+ }
468
+ catch (error) {
469
+ console.error('Failed to enrich with memory context:', error);
470
+ }
471
+ return params;
472
+ }
473
+ /**
474
+ * Store result in memory
475
+ */
476
+ async storeInMemory(result, toolName, model) {
477
+ if (!this.memoryManager)
478
+ return;
479
+ try {
480
+ // Determine tier based on content
481
+ let tier = 'session';
482
+ if (result.length > 1000)
483
+ tier = 'working';
484
+ if (toolName.includes('architect') || toolName.includes('design'))
485
+ tier = 'project';
486
+ // Store in memory
487
+ await this.memoryManager.store(result, tier, {
488
+ toolName,
489
+ model,
490
+ timestamp: new Date().toISOString()
491
+ });
492
+ if (this.verbose) {
493
+ console.error(`šŸ’¾ Stored result in ${tier} memory`);
494
+ }
495
+ }
496
+ catch (error) {
497
+ console.error('Failed to store in memory:', error);
498
+ }
499
+ }
500
+ }
501
+ // Singleton instance
502
+ export const toolExecutionService = new ToolExecutionService();