stigmergy 1.0.94 → 1.0.95
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.
- package/bin/stigmergy +26 -12
- package/docs/HASH_TABLE.md +83 -0
- package/docs/WEATHER_PROCESSOR_API.md +230 -0
- package/docs/best_practices.md +135 -0
- package/docs/development_guidelines.md +392 -0
- package/docs/requirements_specification.md +148 -0
- package/docs/system_design.md +314 -0
- package/docs/tdd_implementation_plan.md +384 -0
- package/docs/test_report.md +49 -0
- package/examples/calculator-example.js +72 -0
- package/examples/json-validation-example.js +64 -0
- package/examples/rest-client-example.js +52 -0
- package/package.json +21 -17
- package/scripts/post-deployment-config.js +9 -2
- package/src/auth.js +171 -0
- package/src/auth_command.js +195 -0
- package/src/calculator.js +220 -0
- package/src/core/cli_help_analyzer.js +625 -562
- package/src/core/cli_parameter_handler.js +121 -0
- package/src/core/cli_tools.js +89 -0
- package/src/core/error_handler.js +307 -0
- package/src/core/memory_manager.js +76 -0
- package/src/core/smart_router.js +133 -0
- package/src/deploy.js +50 -0
- package/src/main_english.js +642 -719
- package/src/main_fixed.js +1035 -0
- package/src/utils.js +529 -0
- package/src/weatherProcessor.js +205 -0
- package/test/calculator.test.js +215 -0
- package/test/collision-test.js +26 -0
- package/test/csv-processing-test.js +36 -0
- package/test/e2e/claude-cli-test.js +128 -0
- package/test/e2e/collaboration-test.js +75 -0
- package/test/e2e/comprehensive-test.js +431 -0
- package/test/e2e/error-handling-test.js +90 -0
- package/test/e2e/individual-tool-test.js +143 -0
- package/test/e2e/other-cli-test.js +130 -0
- package/test/e2e/qoder-cli-test.js +128 -0
- package/test/e2e/run-e2e-tests.js +73 -0
- package/test/e2e/test-data.js +88 -0
- package/test/e2e/test-utils.js +222 -0
- package/test/hash-table-demo.js +33 -0
- package/test/hash-table-test.js +26 -0
- package/test/json-validation-test.js +164 -0
- package/test/rest-client-test.js +56 -0
- package/test/unit/calculator-full.test.js +191 -0
- package/test/unit/calculator-simple.test.js +96 -0
- package/test/unit/calculator.test.js +97 -0
- package/test/unit/cli_parameter_handler.test.js +116 -0
- package/test/weather-processor.test.js +104 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const CLIHelpAnalyzer = require('./cli_help_analyzer');
|
|
2
|
+
const { CLI_TOOLS, validateCLITool } = require('./cli_tools');
|
|
3
|
+
const { errorHandler, ERROR_TYPES } = require('./error_handler');
|
|
4
|
+
|
|
5
|
+
class SmartRouter {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.tools = CLI_TOOLS;
|
|
8
|
+
try {
|
|
9
|
+
this.analyzer = new CLIHelpAnalyzer();
|
|
10
|
+
this.analyzer.setCLITools(this.tools);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
errorHandler.logError(error, 'ERROR', 'SmartRouter.constructor');
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
this.routeKeywords = ['use', 'help', 'please', 'write', 'generate', 'explain', 'analyze', 'translate', 'code', 'article'];
|
|
16
|
+
this.defaultTool = 'claude';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Initialize the smart router
|
|
21
|
+
*/
|
|
22
|
+
async initialize() {
|
|
23
|
+
await this.analyzer.initialize();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if input should be routed to a specific CLI tool
|
|
28
|
+
*/
|
|
29
|
+
shouldRoute(userInput) {
|
|
30
|
+
return this.routeKeywords.some(keyword =>
|
|
31
|
+
userInput.toLowerCase().includes(keyword.toLowerCase())
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Perform smart routing based on user input and CLI patterns
|
|
37
|
+
*/
|
|
38
|
+
async smartRoute(userInput) {
|
|
39
|
+
const input = userInput.trim();
|
|
40
|
+
|
|
41
|
+
// First try to detect tool-specific keywords
|
|
42
|
+
for (const [toolName, toolInfo] of Object.entries(this.tools)) {
|
|
43
|
+
try {
|
|
44
|
+
// Validate tool configuration
|
|
45
|
+
validateCLITool(toolName);
|
|
46
|
+
|
|
47
|
+
// Get CLI pattern for this tool
|
|
48
|
+
let cliPattern = await this.analyzer.getCLIPattern(toolName);
|
|
49
|
+
|
|
50
|
+
// If we don't have a pattern, try to analyze the CLI
|
|
51
|
+
if (!cliPattern) {
|
|
52
|
+
try {
|
|
53
|
+
cliPattern = await this.analyzer.analyzeCLI(toolName);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.warn(`Failed to analyze ${toolName}:`, error.message);
|
|
56
|
+
// Continue with next tool
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Check if input contains any of the tool's keywords or subcommands
|
|
62
|
+
const keywords = this.extractKeywords(toolName, cliPattern);
|
|
63
|
+
for (const keyword of keywords) {
|
|
64
|
+
if (input.toLowerCase().includes(keyword.toLowerCase())) {
|
|
65
|
+
// Extract clean parameters
|
|
66
|
+
const cleanInput = input
|
|
67
|
+
.replace(new RegExp(`.*${keyword}\\s*`, 'gi'), '')
|
|
68
|
+
.replace(/^(use|please|help|using|with)\s*/i, '')
|
|
69
|
+
.trim();
|
|
70
|
+
return { tool: toolName, prompt: cleanInput };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
await errorHandler.logError(
|
|
75
|
+
error,
|
|
76
|
+
'WARN',
|
|
77
|
+
`SmartRouter.smartRoute.${toolName}`
|
|
78
|
+
);
|
|
79
|
+
// Continue with next tool
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Default routing
|
|
85
|
+
const cleanInput = input.replace(/^(use|please|help|using|with)\s*/i, '').trim();
|
|
86
|
+
return { tool: this.defaultTool, prompt: cleanInput };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Extract keywords for a tool from its CLI patterns
|
|
91
|
+
*/
|
|
92
|
+
extractKeywords(toolName, cliPattern) {
|
|
93
|
+
const keywords = [toolName];
|
|
94
|
+
|
|
95
|
+
// Add tool-specific keywords
|
|
96
|
+
const toolSpecificKeywords = {
|
|
97
|
+
claude: ['claude', 'anthropic'],
|
|
98
|
+
gemini: ['gemini', 'google'],
|
|
99
|
+
qwen: ['qwen', 'alibaba', 'tongyi'],
|
|
100
|
+
iflow: ['iflow', 'workflow', 'intelligent'],
|
|
101
|
+
qodercli: ['qoder', 'code'],
|
|
102
|
+
codebuddy: ['codebuddy', 'buddy', 'assistant'],
|
|
103
|
+
copilot: ['copilot', 'github', 'gh'],
|
|
104
|
+
codex: ['codex', 'openai', 'gpt']
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
if (toolSpecificKeywords[toolName]) {
|
|
108
|
+
keywords.push(...toolSpecificKeywords[toolName]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Add subcommands from CLI pattern if available
|
|
112
|
+
if (cliPattern && cliPattern.patterns && cliPattern.patterns.subcommands) {
|
|
113
|
+
cliPattern.patterns.subcommands.forEach(subcommand => {
|
|
114
|
+
if (subcommand.name) {
|
|
115
|
+
keywords.push(subcommand.name);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Add commands from CLI pattern if available
|
|
121
|
+
if (cliPattern && cliPattern.patterns && cliPattern.patterns.commands) {
|
|
122
|
+
cliPattern.patterns.commands.forEach(command => {
|
|
123
|
+
if (command.name && command.name !== toolName) {
|
|
124
|
+
keywords.push(command.name);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return [...new Set(keywords)]; // Remove duplicates
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = SmartRouter;
|
package/src/deploy.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stigmergy Deployment Script
|
|
5
|
+
* This script deploys hooks and integrations for all available CLI tools
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs').promises;
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
|
|
12
|
+
// Import the main Stigmergy installer
|
|
13
|
+
const { StigmergyInstaller } = require('./main_english.js');
|
|
14
|
+
|
|
15
|
+
async function deploy() {
|
|
16
|
+
console.log('Stigmergy Deployment Script');
|
|
17
|
+
console.log('==========================');
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
// Create installer instance
|
|
21
|
+
const installer = new StigmergyInstaller();
|
|
22
|
+
|
|
23
|
+
// Scan for available tools
|
|
24
|
+
console.log('[SCAN] Scanning for available CLI tools...');
|
|
25
|
+
const scanResult = await installer.scanCLI();
|
|
26
|
+
const available = scanResult.available;
|
|
27
|
+
|
|
28
|
+
// Deploy hooks for all available tools
|
|
29
|
+
console.log('[DEPLOY] Deploying hooks for all available tools...');
|
|
30
|
+
await installer.deployHooks(available);
|
|
31
|
+
|
|
32
|
+
console.log('\n[SUCCESS] Deployment completed successfully!');
|
|
33
|
+
return true;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('[ERROR] Deployment failed:', error.message);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Run deployment if called directly
|
|
41
|
+
if (require.main === module) {
|
|
42
|
+
deploy().then(success => {
|
|
43
|
+
process.exit(success ? 0 : 1);
|
|
44
|
+
}).catch(error => {
|
|
45
|
+
console.error('[FATAL ERROR]:', error.message);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = { deploy };
|