stigmergy 1.2.13 → 1.3.2-beta.0

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 (48) hide show
  1. package/README.md +39 -3
  2. package/STIGMERGY.md +3 -0
  3. package/config/enhanced-cli-config.json +438 -0
  4. package/docs/CLI_TOOLS_AGENT_SKILL_ANALYSIS.md +463 -0
  5. package/docs/ENHANCED_CLI_AGENT_SKILL_CONFIG.md +285 -0
  6. package/docs/INSTALLER_ARCHITECTURE.md +257 -0
  7. package/docs/SUDO_PROBLEM_AND_SOLUTION.md +529 -0
  8. package/package.json +14 -5
  9. package/scripts/analyze-router.js +168 -0
  10. package/scripts/test-runner.js +344 -0
  11. package/src/cli/commands/autoinstall.js +158 -0
  12. package/src/cli/commands/errors.js +190 -0
  13. package/src/cli/commands/install.js +142 -0
  14. package/src/cli/commands/permissions.js +108 -0
  15. package/src/cli/commands/project.js +449 -0
  16. package/src/cli/commands/resume.js +136 -0
  17. package/src/cli/commands/scan.js +97 -0
  18. package/src/cli/commands/skills.js +158 -0
  19. package/src/cli/commands/status.js +106 -0
  20. package/src/cli/commands/system.js +301 -0
  21. package/src/cli/router-beta.js +477 -0
  22. package/src/cli/utils/environment.js +75 -0
  23. package/src/cli/utils/formatters.js +47 -0
  24. package/src/cli/utils/skills_cache.js +92 -0
  25. package/src/core/cache_cleaner.js +1 -0
  26. package/src/core/cli_adapters.js +345 -0
  27. package/src/core/cli_help_analyzer.js +473 -1
  28. package/src/core/cli_path_detector.js +2 -1
  29. package/src/core/cli_tools.js +107 -0
  30. package/src/core/coordination/nodejs/HookDeploymentManager.js +185 -422
  31. package/src/core/coordination/nodejs/HookDeploymentManager.refactored.js +323 -0
  32. package/src/core/coordination/nodejs/generators/CLIAdapterGenerator.js +363 -0
  33. package/src/core/coordination/nodejs/generators/ResumeSessionGenerator.js +701 -0
  34. package/src/core/coordination/nodejs/generators/SkillsIntegrationGenerator.js +1210 -0
  35. package/src/core/coordination/nodejs/generators/index.js +12 -0
  36. package/src/core/enhanced_cli_installer.js +220 -30
  37. package/src/core/enhanced_cli_parameter_handler.js +395 -0
  38. package/src/core/execution_mode_detector.js +222 -0
  39. package/src/core/installer.js +51 -70
  40. package/src/core/local_skill_scanner.js +732 -0
  41. package/src/core/multilingual/language-pattern-manager.js +1 -1
  42. package/src/core/skills/StigmergySkillManager.js +26 -8
  43. package/src/core/smart_router.js +279 -2
  44. package/src/index.js +10 -4
  45. package/test/cli-integration.test.js +304 -0
  46. package/test/enhanced-cli-agent-skill-test.js +485 -0
  47. package/test/specific-cli-agent-skill-analysis.js +385 -0
  48. package/src/cli/router.js +0 -1783
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Error Reporting Commands
3
+ * Modular implementation for error reporting and system troubleshooting
4
+ */
5
+
6
+ const chalk = require('chalk');
7
+ const { errorHandler } = require('../../core/error_handler');
8
+ const fs = require('fs').promises;
9
+ const path = require('path');
10
+ const os = require('os');
11
+
12
+ /**
13
+ * Handle errors command - Generate comprehensive error report
14
+ * @param {Object} options - Command options
15
+ */
16
+ async function handleErrorsCommand(options = {}) {
17
+ try {
18
+ console.log(chalk.cyan('[ERRORS] Generating Stigmergy CLI error report...\n'));
19
+
20
+ const report = {
21
+ timestamp: new Date().toISOString(),
22
+ system: {},
23
+ environment: {},
24
+ errors: [],
25
+ diagnostics: {}
26
+ };
27
+
28
+ // System information
29
+ console.log(chalk.blue('šŸ–„ļø System Information:'));
30
+ report.system = {
31
+ platform: os.platform(),
32
+ arch: os.arch(),
33
+ nodeVersion: process.version,
34
+ memory: Math.round(os.totalmem() / 1024 / 1024) + ' MB',
35
+ freeMemory: Math.round(os.freemem() / 1024 / 1024) + ' MB'
36
+ };
37
+
38
+ Object.entries(report.system).forEach(([key, value]) => {
39
+ console.log(` ${key}: ${chalk.green(value)}`);
40
+ });
41
+
42
+ // Environment information
43
+ console.log(chalk.blue('\nšŸŒ Environment Information:'));
44
+ report.environment = {
45
+ pwd: process.cwd(),
46
+ home: os.homedir(),
47
+ shell: process.env.SHELL || process.env.COMSPEC || 'unknown',
48
+ path: process.env.PATH ? process.env.PATH.split(path.delimiter).slice(0, 3).join(path.delimiter) + '...' : 'unknown',
49
+ nodeEnv: process.env.NODE_ENV || 'undefined',
50
+ debugMode: process.env.DEBUG === 'true'
51
+ };
52
+
53
+ Object.entries(report.environment).forEach(([key, value]) => {
54
+ console.log(` ${key}: ${chalk.green(value)}`);
55
+ });
56
+
57
+ // Error handler report (if available)
58
+ console.log(chalk.blue('\nšŸ“‹ Error Handler Report:'));
59
+ try {
60
+ if (errorHandler && typeof errorHandler.printErrorReport === 'function') {
61
+ await errorHandler.printErrorReport();
62
+ console.log(chalk.green(' āœ… Error handler report generated'));
63
+ } else {
64
+ console.log(chalk.yellow(' āš ļø Error handler not available'));
65
+ }
66
+ } catch (error) {
67
+ console.log(chalk.red(` āŒ Error handler failed: ${error.message}`));
68
+ report.errors.push({
69
+ type: 'error_handler',
70
+ message: error.message,
71
+ timestamp: new Date().toISOString()
72
+ });
73
+ }
74
+
75
+ // Check for common issues
76
+ console.log(chalk.blue('\nšŸ” Common Issues Check:'));
77
+
78
+ const checks = [
79
+ {
80
+ name: 'Current directory writable',
81
+ check: async () => {
82
+ try {
83
+ await fs.access(process.cwd(), fs.constants.W_OK);
84
+ return true;
85
+ } catch {
86
+ return false;
87
+ }
88
+ }
89
+ },
90
+ {
91
+ name: 'Home directory accessible',
92
+ check: async () => {
93
+ try {
94
+ await fs.access(os.homedir(), fs.constants.R_OK);
95
+ return true;
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
100
+ },
101
+ {
102
+ name: 'Node modules accessible',
103
+ check: async () => {
104
+ try {
105
+ await fs.access(path.join(process.cwd(), 'node_modules'), fs.constants.R_OK);
106
+ return true;
107
+ } catch {
108
+ return false;
109
+ }
110
+ }
111
+ },
112
+ {
113
+ name: 'Package.json exists',
114
+ check: async () => {
115
+ try {
116
+ await fs.access(path.join(process.cwd(), 'package.json'), fs.constants.R_OK);
117
+ return true;
118
+ } catch {
119
+ return false;
120
+ }
121
+ }
122
+ }
123
+ ];
124
+
125
+ for (const check of checks) {
126
+ try {
127
+ const passed = await check.check();
128
+ const icon = passed ? chalk.green('āœ…') : chalk.red('āŒ');
129
+ console.log(` ${icon} ${check.name}`);
130
+
131
+ if (!passed) {
132
+ report.errors.push({
133
+ type: 'common_issue',
134
+ message: `${check.name} failed`,
135
+ timestamp: new Date().toISOString()
136
+ });
137
+ }
138
+ } catch (error) {
139
+ console.log(` ${chalk.yellow('āš ļø')} ${check.name} - Check failed`);
140
+ }
141
+ }
142
+
143
+ // Log files check
144
+ console.log(chalk.blue('\nšŸ“„ Log Files:'));
145
+ const logLocations = [
146
+ path.join(os.homedir(), '.stigmergy', 'logs'),
147
+ path.join(process.cwd(), 'logs'),
148
+ path.join(os.tmpdir(), 'stigmergy-logs')
149
+ ];
150
+
151
+ for (const logLocation of logLocations) {
152
+ try {
153
+ const stats = await fs.stat(logLocation);
154
+ console.log(` ${chalk.green('āœ…')} ${logLocation} (${stats.size} bytes)`);
155
+ } catch {
156
+ console.log(` ${chalk.gray('⚪')} ${logLocation} (not found)`);
157
+ }
158
+ }
159
+
160
+ // Summary
161
+ console.log(chalk.blue('\nšŸ“Š Error Report Summary:'));
162
+ const errorCount = report.errors.length;
163
+ const warningCount = report.environment.debugMode ? 1 : 0;
164
+
165
+ console.log(` Errors: ${chalk.red(errorCount)}`);
166
+ console.log(` Warnings: ${chalk.yellow(warningCount)}`);
167
+
168
+ if (errorCount === 0) {
169
+ console.log(chalk.green('\nāœ… No critical errors detected!'));
170
+ } else {
171
+ console.log(chalk.red(`\nāŒ ${errorCount} issue(s) found - see details above`));
172
+ }
173
+
174
+ // Save report to file if requested
175
+ if (options.save) {
176
+ const reportPath = path.join(process.cwd(), `stigmergy-error-report-${Date.now()}.json`);
177
+ await fs.writeFile(reportPath, JSON.stringify(report, null, 2));
178
+ console.log(chalk.blue(`\nšŸ’¾ Report saved to: ${reportPath}`));
179
+ }
180
+
181
+ return { success: true, report };
182
+ } catch (error) {
183
+ console.error(chalk.red('[ERROR] Failed to generate error report:'), error.message);
184
+ return { success: false, error: error.message };
185
+ }
186
+ }
187
+
188
+ module.exports = {
189
+ handleErrorsCommand
190
+ };
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Install Command Module
3
+ * Handles CLI tool installation commands
4
+ */
5
+
6
+ const StigmergyInstaller = require('../../core/installer');
7
+ const chalk = require('chalk');
8
+ const { ensureSkillsCache } = require('../utils/skills_cache');
9
+
10
+ /**
11
+ * Handle install command
12
+ * @param {Object} options - Command options
13
+ * @param {string} options.cli - Specific CLI to install
14
+ * @param {boolean} options.verbose - Verbose output
15
+ * @param {boolean} options.force - Force installation
16
+ */
17
+ async function handleInstallCommand(options = {}) {
18
+ const installer = new StigmergyInstaller();
19
+
20
+ try {
21
+ // Initialize or update skills/agents cache
22
+ await ensureSkillsCache({ verbose: options.verbose || process.env.DEBUG === 'true' });
23
+
24
+ console.log(chalk.blue('šŸš€ Starting CLI tools installation...'));
25
+
26
+ // Handle auto-install mode (non-interactive)
27
+ if (options.nonInteractive) {
28
+ console.log(chalk.blue('[AUTO-INSTALL] Running in non-interactive mode'));
29
+
30
+ // Scan for available and missing tools
31
+ const { missing: missingTools, available: availableTools } = await installer.scanCLI();
32
+
33
+ if (Object.keys(missingTools).length === 0) {
34
+ console.log(chalk.green('āœ… All AI CLI tools are already installed!'));
35
+ return {
36
+ success: true,
37
+ installed: [],
38
+ existing: Object.keys(availableTools)
39
+ };
40
+ }
41
+
42
+ // Install all missing tools in auto mode
43
+ const selectedTools = Object.keys(missingTools);
44
+ console.log(chalk.blue(`[AUTO-INSTALL] Installing ${selectedTools.length} tools: ${selectedTools.join(', ')}`));
45
+
46
+ const installResult = await installer.installTools(selectedTools, missingTools);
47
+
48
+ if (installResult.success) {
49
+ console.log(chalk.green('āœ… Auto-install completed successfully!'));
50
+ return {
51
+ success: true,
52
+ installed: installResult.installed || [],
53
+ failed: installResult.failed || [],
54
+ existing: Object.keys(availableTools)
55
+ };
56
+ } else {
57
+ console.log(chalk.yellow('āš ļø Some tools may not have installed successfully'));
58
+ return {
59
+ success: false,
60
+ installed: installResult.installed || [],
61
+ failed: installResult.failed || [],
62
+ existing: Object.keys(availableTools),
63
+ error: 'Some installations failed'
64
+ };
65
+ }
66
+ }
67
+
68
+ // Interactive install mode
69
+ const { missing: missingTools, available: availableTools } = await installer.scanCLI();
70
+
71
+ if (Object.keys(missingTools).length === 0) {
72
+ console.log(chalk.green('āœ… All AI CLI tools are already installed!'));
73
+
74
+ if (Object.keys(availableTools).length > 0) {
75
+ console.log(chalk.cyan('\nšŸ“¦ Available tools:'));
76
+ Object.keys(availableTools).forEach(tool => {
77
+ console.log(` āœ… ${tool}`);
78
+ });
79
+ }
80
+
81
+ return {
82
+ success: true,
83
+ installed: [],
84
+ existing: Object.keys(availableTools)
85
+ };
86
+ }
87
+
88
+ console.log(chalk.yellow(`\nāš ļø Found ${Object.keys(missingTools).length} missing tools:`));
89
+ Object.entries(missingTools).forEach(([toolName, toolInfo]) => {
90
+ console.log(` - ${toolInfo.name}: ${toolInfo.install}`);
91
+ });
92
+
93
+ // For now, install all missing tools
94
+ const selectedTools = Object.keys(missingTools);
95
+ const installResult = await installer.installTools(selectedTools, missingTools);
96
+
97
+ if (installResult.success) {
98
+ console.log(chalk.green('āœ… Installation completed successfully!'));
99
+
100
+ if (installResult.installed && installResult.installed.length > 0) {
101
+ console.log(chalk.cyan('\nšŸ“¦ Installed tools:'));
102
+ installResult.installed.forEach(tool => {
103
+ console.log(` āœ… ${tool}`);
104
+ });
105
+ }
106
+
107
+ if (installResult.failed && installResult.failed.length > 0) {
108
+ console.log(chalk.red('\nāŒ Failed tools:'));
109
+ installResult.failed.forEach(tool => {
110
+ console.log(` āŒ ${tool}`);
111
+ });
112
+ }
113
+
114
+ return {
115
+ success: true,
116
+ installed: installResult.installed || [],
117
+ failed: installResult.failed || [],
118
+ existing: Object.keys(availableTools)
119
+ };
120
+ } else {
121
+ console.log(chalk.red('āŒ Installation failed!'));
122
+ return {
123
+ success: false,
124
+ installed: installResult.installed || [],
125
+ failed: installResult.failed || [],
126
+ existing: Object.keys(availableTools),
127
+ error: 'Installation failed'
128
+ };
129
+ }
130
+ } catch (error) {
131
+ console.log(chalk.red(`āŒ Installation error: ${error.message}`));
132
+ return {
133
+ success: false,
134
+ error: error.message,
135
+ installed: []
136
+ };
137
+ }
138
+ }
139
+
140
+ module.exports = {
141
+ handleInstallCommand
142
+ };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Permission Management Commands
3
+ * Modular implementation for fix-perms and perm-check commands
4
+ */
5
+
6
+ const chalk = require('chalk');
7
+ const DirectoryPermissionManager = require('../../core/directory_permission_manager');
8
+
9
+ /**
10
+ * Handle permission check command
11
+ * @param {Object} options - Command options
12
+ */
13
+ async function handlePermCheckCommand(options = {}) {
14
+ try {
15
+ console.log(chalk.cyan('[PERM-CHECK] Checking current directory permissions...\n'));
16
+
17
+ const permissionManager = new DirectoryPermissionManager({
18
+ verbose: options.verbose || process.env.DEBUG === 'true'
19
+ });
20
+
21
+ const hasWritePermission = await permissionManager.checkWritePermission();
22
+
23
+ console.log(`šŸ“ Current directory: ${process.cwd()}`);
24
+ console.log(`šŸ”§ Write permission: ${hasWritePermission ? chalk.green('āœ… Yes') : chalk.red('āŒ No')}`);
25
+
26
+ if (!hasWritePermission) {
27
+ console.log('\nšŸ’” Suggestions:');
28
+ console.log('1. Run: stigmergy fix-perms # Fix permissions automatically');
29
+ console.log('2. Change to user directory: cd ~');
30
+ console.log('3. Create project directory: mkdir ~/stigmergy && cd ~/stigmergy');
31
+
32
+ console.log('\nšŸ” System Info:');
33
+ const sysInfo = permissionManager.getSystemInfo();
34
+ console.log(` Platform: ${sysInfo.platform}`);
35
+ console.log(` Shell: ${sysInfo.shell}`);
36
+ console.log(` Home: ${sysInfo.homeDir}`);
37
+ } else {
38
+ console.log(chalk.green('\nāœ… Directory permissions are OK!'));
39
+ }
40
+
41
+ return { success: true, hasWritePermission };
42
+ } catch (error) {
43
+ console.error(chalk.red('[ERROR] Permission check failed:'), error.message);
44
+ return { success: false, error: error.message };
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Handle fix permissions command
50
+ * @param {Object} options - Command options
51
+ */
52
+ async function handleFixPermsCommand(options = {}) {
53
+ try {
54
+ console.log(chalk.cyan('[FIX-PERMS] Setting up working directory with proper permissions...\n'));
55
+
56
+ // Using DirectoryPermissionManager for permission handling
57
+ // This provides the core permission management functionality
58
+ const permissionManager = new DirectoryPermissionManager({
59
+ verbose: options.verbose || process.env.DEBUG === 'true',
60
+ createStigmergyDir: true
61
+ });
62
+
63
+ const hasWritePermission = await permissionManager.checkWritePermission();
64
+
65
+ if (hasWritePermission) {
66
+ console.log(chalk.green('āœ… Current directory already has proper permissions!'));
67
+ return { success: true, alreadyFixed: true };
68
+ }
69
+
70
+ console.log(chalk.yellow('šŸ”§ Attempting to fix permissions...'));
71
+
72
+ // Try to create a .stigmergy directory in user home as fallback
73
+ const fs = require('fs').promises;
74
+ const path = require('path');
75
+ const os = require('os');
76
+
77
+ const stigmergyDir = path.join(os.homedir(), '.stigmergy');
78
+
79
+ try {
80
+ await fs.mkdir(stigmergyDir, { recursive: true });
81
+ console.log(chalk.green(`āœ… Created Stigmergy directory: ${stigmergyDir}`));
82
+ console.log(chalk.yellow('šŸ’” Consider changing to this directory for your projects'));
83
+
84
+ return { success: true, createdDirectory: stigmergyDir };
85
+ } catch (mkdirError) {
86
+ console.log(chalk.red('āŒ Could not create directory or fix permissions'));
87
+ console.log(chalk.red(`Error: ${mkdirError.message}`));
88
+
89
+ console.log('\nšŸ”§ Manual fix required:');
90
+ console.log('1. Run in a directory where you have write permissions');
91
+ console.log('2. Try: cd ~ && mkdir stigmergy-workspace && cd stigmergy-workspace');
92
+
93
+ return { success: false, error: mkdirError.message };
94
+ }
95
+
96
+ } catch (error) {
97
+ console.error(chalk.red('[ERROR] Permission setup failed:'), error.message);
98
+ if (options.verbose) {
99
+ console.error(error.stack);
100
+ }
101
+ return { success: false, error: error.message };
102
+ }
103
+ }
104
+
105
+ module.exports = {
106
+ handlePermCheckCommand,
107
+ handleFixPermsCommand
108
+ };