stigmergy 1.0.95 → 1.0.97
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/README.md +20 -0
- package/bin/stigmergy +11 -0
- package/docs/http-request-handler.md +289 -0
- package/docs/json-parser.md +102 -0
- package/docs/rest_client.md +144 -0
- package/examples/encryption-example.js +67 -0
- package/examples/json-parser-example.js +120 -0
- package/examples/rest_client_example.js +54 -0
- package/package.json +6 -5
- package/src/auth.js +28 -26
- package/src/auth_command.js +51 -38
- package/src/calculator.js +102 -9
- package/src/core/cli_help_analyzer.js +621 -573
- package/src/core/cli_parameter_handler.js +110 -104
- package/src/core/cli_tools.js +76 -76
- package/src/core/error_handler.js +154 -55
- package/src/core/memory_manager.js +70 -63
- package/src/core/rest_client.js +160 -0
- package/src/core/smart_router.js +130 -117
- package/src/data_encryption.js +143 -0
- package/src/data_structures.js +440 -0
- package/src/deploy.js +38 -32
- package/src/index.js +9 -9
- package/src/main.js +889 -752
- package/src/main_english.js +1292 -887
- package/src/main_fixed.js +1039 -902
- package/src/utils.js +462 -75
- package/src/weatherProcessor.js +78 -55
- package/test/encryption-simple-test.js +110 -0
- package/test/encryption.test.js +129 -0
- package/test/hash_table_test.js +114 -0
- package/test/json-parser-test.js +161 -0
- package/test/rest_client.test.js +85 -0
|
@@ -1,121 +1,127 @@
|
|
|
1
1
|
// Unified CLI Parameter Handler
|
|
2
|
-
const { spawn } = require(
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
3
|
|
|
4
4
|
class CLIParameterHandler {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Generate appropriate arguments for CLI execution based on tool patterns
|
|
7
|
+
* @param {string} toolName - Name of the CLI tool
|
|
8
|
+
* @param {string} prompt - User prompt
|
|
9
|
+
* @param {Object} cliPattern - CLI pattern information from analyzer
|
|
10
|
+
* @returns {Array} Arguments array for spawn
|
|
11
|
+
*/
|
|
12
|
+
static generateArguments(toolName, prompt, cliPattern) {
|
|
13
|
+
// Default arguments
|
|
14
|
+
let toolArgs = [];
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
// Special handling for Codex CLI which always needs 'exec' subcommand
|
|
17
|
+
if (toolName === "codex") {
|
|
18
|
+
return ["exec", "-p", `"${prompt}"`];
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Handle based on command structure and patterns from help analyzer
|
|
27
|
-
if (commandStructure.nonInteractiveSupport) {
|
|
28
|
-
// Use flag-based approach if available
|
|
29
|
-
if (commandStructure.promptFlag) {
|
|
30
|
-
toolArgs = [commandStructure.promptFlag, `"${prompt}"`];
|
|
31
|
-
} else if (commandStructure.nonInteractiveFlag) {
|
|
32
|
-
toolArgs = [commandStructure.nonInteractiveFlag, `"${prompt}"`];
|
|
33
|
-
} else {
|
|
34
|
-
// Fallback to standard -p flag
|
|
35
|
-
toolArgs = ['-p', `"${prompt}"`];
|
|
36
|
-
}
|
|
37
|
-
} else if (commandStructure.executionPattern === 'flag-based') {
|
|
38
|
-
// Explicitly flag-based tools
|
|
39
|
-
if (commandStructure.promptFlag) {
|
|
40
|
-
toolArgs = [commandStructure.promptFlag, `"${prompt}"`];
|
|
41
|
-
} else {
|
|
42
|
-
toolArgs = ['-p', `"${prompt}"`];
|
|
43
|
-
}
|
|
44
|
-
} else if (commandStructure.executionPattern === 'argument-based') {
|
|
45
|
-
// Argument-based tools
|
|
46
|
-
toolArgs = [`"${prompt}"`];
|
|
47
|
-
} else if (commandStructure.executionPattern === 'subcommand-based') {
|
|
48
|
-
// Subcommand-based tools
|
|
49
|
-
toolArgs = ['-p', `"${prompt}"`];
|
|
50
|
-
} else {
|
|
51
|
-
// Fallback to tool-specific handling
|
|
52
|
-
toolArgs = this.getToolSpecificArguments(toolName, prompt);
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
// Fallback to tool-specific handling if no pattern information
|
|
56
|
-
toolArgs = this.getToolSpecificArguments(toolName, prompt);
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
// Final fallback to tool-specific handling
|
|
60
|
-
toolArgs = this.getToolSpecificArguments(toolName, prompt);
|
|
61
|
-
}
|
|
21
|
+
try {
|
|
22
|
+
// Check if we have pattern information from CLI help analyzer
|
|
23
|
+
if (cliPattern && cliPattern.commandStructure) {
|
|
24
|
+
const commandStructure = cliPattern.commandStructure;
|
|
62
25
|
|
|
63
|
-
|
|
26
|
+
// Handle based on command structure and patterns from help analyzer
|
|
27
|
+
if (commandStructure.nonInteractiveSupport) {
|
|
28
|
+
// Use flag-based approach if available
|
|
29
|
+
if (commandStructure.promptFlag) {
|
|
30
|
+
toolArgs = [commandStructure.promptFlag, `"${prompt}"`];
|
|
31
|
+
} else if (commandStructure.nonInteractiveFlag) {
|
|
32
|
+
toolArgs = [commandStructure.nonInteractiveFlag, `"${prompt}"`];
|
|
33
|
+
} else {
|
|
34
|
+
// Fallback to standard -p flag
|
|
35
|
+
toolArgs = ["-p", `"${prompt}"`];
|
|
36
|
+
}
|
|
37
|
+
} else if (commandStructure.executionPattern === "flag-based") {
|
|
38
|
+
// Explicitly flag-based tools
|
|
39
|
+
if (commandStructure.promptFlag) {
|
|
40
|
+
toolArgs = [commandStructure.promptFlag, `"${prompt}"`];
|
|
41
|
+
} else {
|
|
42
|
+
toolArgs = ["-p", `"${prompt}"`];
|
|
43
|
+
}
|
|
44
|
+
} else if (commandStructure.executionPattern === "argument-based") {
|
|
45
|
+
// Argument-based tools
|
|
46
|
+
toolArgs = [`"${prompt}"`];
|
|
47
|
+
} else if (commandStructure.executionPattern === "subcommand-based") {
|
|
48
|
+
// Subcommand-based tools
|
|
49
|
+
toolArgs = ["-p", `"${prompt}"`];
|
|
50
|
+
} else {
|
|
51
|
+
// Fallback to tool-specific handling
|
|
52
|
+
toolArgs = this.getToolSpecificArguments(toolName, prompt);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
// Fallback to tool-specific handling if no pattern information
|
|
56
|
+
toolArgs = this.getToolSpecificArguments(toolName, prompt);
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
// Final fallback to tool-specific handling
|
|
60
|
+
toolArgs = this.getToolSpecificArguments(toolName, prompt);
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* @param {string} toolName - Name of the CLI tool
|
|
69
|
-
* @param {string} prompt - User prompt
|
|
70
|
-
* @returns {Array} Arguments array for spawn
|
|
71
|
-
*/
|
|
72
|
-
static getToolSpecificArguments(toolName, prompt) {
|
|
73
|
-
// Tool-specific argument handling
|
|
74
|
-
const toolSpecificArgs = {
|
|
75
|
-
'claude': ['-p', `"${prompt}"`],
|
|
76
|
-
'qodercli': ['-p', `"${prompt}"`],
|
|
77
|
-
'iflow': ['-p', `"${prompt}"`],
|
|
78
|
-
'codebuddy': ['-p', `"${prompt}"`],
|
|
79
|
-
'copilot': ['-p', `"${prompt}"`],
|
|
80
|
-
'codex': ['exec', '-p', `"${prompt}"`] // Codex needs 'exec' subcommand
|
|
81
|
-
};
|
|
63
|
+
return toolArgs;
|
|
64
|
+
}
|
|
82
65
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Get tool-specific arguments based on known patterns
|
|
68
|
+
* @param {string} toolName - Name of the CLI tool
|
|
69
|
+
* @param {string} prompt - User prompt
|
|
70
|
+
* @returns {Array} Arguments array for spawn
|
|
71
|
+
*/
|
|
72
|
+
static getToolSpecificArguments(toolName, prompt) {
|
|
73
|
+
// Tool-specific argument handling
|
|
74
|
+
const toolSpecificArgs = {
|
|
75
|
+
claude: ["-p", `"${prompt}"`],
|
|
76
|
+
qodercli: ["-p", `"${prompt}"`],
|
|
77
|
+
iflow: ["-p", `"${prompt}"`],
|
|
78
|
+
codebuddy: ["-p", `"${prompt}"`],
|
|
79
|
+
copilot: ["-p", `"${prompt}"`],
|
|
80
|
+
codex: ["exec", "-p", `"${prompt}"`], // Codex needs 'exec' subcommand
|
|
81
|
+
};
|
|
87
82
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return ['-p', `"${prompt}"`];
|
|
93
|
-
}
|
|
83
|
+
// Return tool-specific arguments if available
|
|
84
|
+
if (toolSpecificArgs[toolName]) {
|
|
85
|
+
return toolSpecificArgs[toolName];
|
|
86
|
+
}
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
// Default handling for other tools
|
|
89
|
+
// Check if the tool commonly uses -p flag
|
|
90
|
+
const toolsWithPFlag = [
|
|
91
|
+
"claude",
|
|
92
|
+
"qodercli",
|
|
93
|
+
"iflow",
|
|
94
|
+
"codebuddy",
|
|
95
|
+
"copilot",
|
|
96
|
+
];
|
|
97
|
+
if (toolsWithPFlag.includes(toolName)) {
|
|
98
|
+
return ["-p", `"${prompt}"`];
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
* @param {string} toolName - Name of the CLI tool
|
|
103
|
-
* @param {string} prompt - User prompt
|
|
104
|
-
* @param {Object} cliPattern - CLI pattern information from analyzer
|
|
105
|
-
* @returns {Object} Child process object
|
|
106
|
-
*/
|
|
107
|
-
static executeCLI(toolPath, toolName, prompt, cliPattern) {
|
|
108
|
-
// Generate appropriate arguments
|
|
109
|
-
const toolArgs = this.generateArguments(toolName, prompt, cliPattern);
|
|
101
|
+
// Default to argument-based approach
|
|
102
|
+
return [`"${prompt}"`];
|
|
103
|
+
}
|
|
110
104
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Execute CLI tool with appropriate arguments
|
|
107
|
+
* @param {string} toolPath - Path to the CLI tool
|
|
108
|
+
* @param {string} toolName - Name of the CLI tool
|
|
109
|
+
* @param {string} prompt - User prompt
|
|
110
|
+
* @param {Object} cliPattern - CLI pattern information from analyzer
|
|
111
|
+
* @returns {Object} Child process object
|
|
112
|
+
*/
|
|
113
|
+
static executeCLI(toolPath, toolName, prompt, cliPattern) {
|
|
114
|
+
// Generate appropriate arguments
|
|
115
|
+
const toolArgs = this.generateArguments(toolName, prompt, cliPattern);
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
// Execute the tool
|
|
118
|
+
const child = spawn(toolPath, toolArgs, {
|
|
119
|
+
stdio: "inherit",
|
|
120
|
+
shell: true,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return child;
|
|
124
|
+
}
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
module.exports = CLIParameterHandler;
|
|
127
|
+
module.exports = CLIParameterHandler;
|
package/src/core/cli_tools.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
const path = require(
|
|
2
|
-
const os = require(
|
|
3
|
-
const { errorHandler, ERROR_TYPES } = require(
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const os = require("os");
|
|
3
|
+
const { errorHandler, ERROR_TYPES } = require("./error_handler");
|
|
4
4
|
|
|
5
5
|
// AI CLI Tools Configuration
|
|
6
6
|
const CLI_TOOLS = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
7
|
+
claude: {
|
|
8
|
+
name: "Claude CLI",
|
|
9
|
+
version: "claude --version",
|
|
10
|
+
install: "npm install -g @anthropic-ai/claude-cli",
|
|
11
|
+
hooksDir: path.join(os.homedir(), ".claude", "hooks"),
|
|
12
|
+
config: path.join(os.homedir(), ".claude", "config.json"),
|
|
13
|
+
},
|
|
14
|
+
gemini: {
|
|
15
|
+
name: "Gemini CLI",
|
|
16
|
+
version: "gemini --version",
|
|
17
|
+
install: "npm install -g @google/generative-ai-cli",
|
|
18
|
+
hooksDir: path.join(os.homedir(), ".gemini", "extensions"),
|
|
19
|
+
config: path.join(os.homedir(), ".gemini", "config.json"),
|
|
20
|
+
},
|
|
21
|
+
qwen: {
|
|
22
|
+
name: "Qwen CLI",
|
|
23
|
+
version: "qwen --version",
|
|
24
|
+
install: "npm install -g @alibaba/qwen-cli",
|
|
25
|
+
hooksDir: path.join(os.homedir(), ".qwen", "hooks"),
|
|
26
|
+
config: path.join(os.homedir(), ".qwen", "config.json"),
|
|
27
|
+
},
|
|
28
|
+
iflow: {
|
|
29
|
+
name: "iFlow CLI",
|
|
30
|
+
version: "iflow --version",
|
|
31
|
+
install: "npm install -g iflow-cli",
|
|
32
|
+
hooksDir: path.join(os.homedir(), ".iflow", "hooks"),
|
|
33
|
+
config: path.join(os.homedir(), ".iflow", "config.json"),
|
|
34
|
+
},
|
|
35
|
+
qodercli: {
|
|
36
|
+
name: "Qoder CLI",
|
|
37
|
+
version: "qodercli --version",
|
|
38
|
+
install: "npm install -g @qoder-ai/qodercli",
|
|
39
|
+
hooksDir: path.join(os.homedir(), ".qoder", "hooks"),
|
|
40
|
+
config: path.join(os.homedir(), ".qoder", "config.json"),
|
|
41
|
+
},
|
|
42
|
+
codebuddy: {
|
|
43
|
+
name: "CodeBuddy CLI",
|
|
44
|
+
version: "codebuddy --version",
|
|
45
|
+
install: "npm install -g codebuddy-cli",
|
|
46
|
+
hooksDir: path.join(os.homedir(), ".codebuddy", "hooks"),
|
|
47
|
+
config: path.join(os.homedir(), ".codebuddy", "config.json"),
|
|
48
|
+
},
|
|
49
|
+
copilot: {
|
|
50
|
+
name: "GitHub Copilot CLI",
|
|
51
|
+
version: "copilot --version",
|
|
52
|
+
install: "npm install -g @github/copilot-cli",
|
|
53
|
+
hooksDir: path.join(os.homedir(), ".copilot", "mcp"),
|
|
54
|
+
config: path.join(os.homedir(), ".copilot", "config.json"),
|
|
55
|
+
},
|
|
56
|
+
codex: {
|
|
57
|
+
name: "OpenAI Codex CLI",
|
|
58
|
+
version: "codex --version",
|
|
59
|
+
install: "npm install -g openai-codex-cli",
|
|
60
|
+
hooksDir: path.join(os.homedir(), ".config", "codex", "slash_commands"),
|
|
61
|
+
config: path.join(os.homedir(), ".codex", "config.json"),
|
|
62
|
+
},
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
/**
|
|
@@ -68,22 +68,22 @@ const CLI_TOOLS = {
|
|
|
68
68
|
* @throws {StigmergyError} If validation fails
|
|
69
69
|
*/
|
|
70
70
|
function validateCLITool(toolName) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
if (!CLI_TOOLS[toolName]) {
|
|
72
|
+
throw errorHandler.createError(
|
|
73
|
+
`CLI tool '${toolName}' is not configured`,
|
|
74
|
+
ERROR_TYPES.CONFIGURATION,
|
|
75
|
+
"INVALID_CLI_TOOL",
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const tool = CLI_TOOLS[toolName];
|
|
80
|
+
if (!tool.name || !tool.version || !tool.install) {
|
|
81
|
+
throw errorHandler.createError(
|
|
82
|
+
`CLI tool '${toolName}' has invalid configuration`,
|
|
83
|
+
ERROR_TYPES.CONFIGURATION,
|
|
84
|
+
"INCOMPLETE_CLI_CONFIG",
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
module.exports = { CLI_TOOLS, validateCLITool };
|
|
89
|
+
module.exports = { CLI_TOOLS, validateCLITool };
|