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.
@@ -1,121 +1,127 @@
1
1
  // Unified CLI Parameter Handler
2
- const { spawn } = require('child_process');
2
+ const { spawn } = require("child_process");
3
3
 
4
4
  class CLIParameterHandler {
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 = [];
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
- // Special handling for Codex CLI which always needs 'exec' subcommand
17
- if (toolName === 'codex') {
18
- return ['exec', '-p', `"${prompt}"`];
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
- try {
22
- // Check if we have pattern information from CLI help analyzer
23
- if (cliPattern && cliPattern.commandStructure) {
24
- const commandStructure = cliPattern.commandStructure;
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
- return toolArgs;
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
- * 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
- };
63
+ return toolArgs;
64
+ }
82
65
 
83
- // Return tool-specific arguments if available
84
- if (toolSpecificArgs[toolName]) {
85
- return toolSpecificArgs[toolName];
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
- // Default handling for other tools
89
- // Check if the tool commonly uses -p flag
90
- const toolsWithPFlag = ['claude', 'qodercli', 'iflow', 'codebuddy', 'copilot'];
91
- if (toolsWithPFlag.includes(toolName)) {
92
- return ['-p', `"${prompt}"`];
93
- }
83
+ // Return tool-specific arguments if available
84
+ if (toolSpecificArgs[toolName]) {
85
+ return toolSpecificArgs[toolName];
86
+ }
94
87
 
95
- // Default to argument-based approach
96
- return [`"${prompt}"`];
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
- * Execute CLI tool with appropriate arguments
101
- * @param {string} toolPath - Path to the CLI tool
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
- // Execute the tool
112
- const child = spawn(toolPath, toolArgs, {
113
- stdio: 'inherit',
114
- shell: true
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
- return child;
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;
@@ -1,65 +1,65 @@
1
- const path = require('path');
2
- const os = require('os');
3
- const { errorHandler, ERROR_TYPES } = require('./error_handler');
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
- 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
- }
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
- 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
- }
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 };