stigmergy 1.2.0 → 1.2.6

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 (125) hide show
  1. package/LICENSE +18 -18
  2. package/README.md +28 -223
  3. package/STIGMERGY.md +61 -61
  4. package/docs/PROJECT_CONSTITUTION.md +433 -433
  5. package/docs/PROJECT_STRUCTURE_CURRENT.md +80 -80
  6. package/examples/calculator-example.js +72 -72
  7. package/examples/cline_usage_examples.md +364 -364
  8. package/examples/encryption-example.js +67 -67
  9. package/examples/json-parser-example.js +120 -120
  10. package/examples/json-validation-example.js +64 -64
  11. package/examples/rest-client-example.js +52 -52
  12. package/examples/rest_client_example.js +54 -54
  13. package/package.json +36 -15
  14. package/scripts/build.js +74 -74
  15. package/scripts/post-deployment-config.js +296 -296
  16. package/scripts/preinstall-check.js +173 -173
  17. package/scripts/publish.js +58 -268
  18. package/scripts/run-layered-tests.js +247 -0
  19. package/scripts/safe-install.js +139 -139
  20. package/scripts/simple-publish.js +57 -59
  21. package/src/adapters/claude/install_claude_integration.js +292 -0
  22. package/src/adapters/codebuddy/install_codebuddy_integration.js +349 -0
  23. package/src/adapters/codex/install_codex_integration.js +395 -0
  24. package/src/adapters/copilot/install_copilot_integration.js +716 -0
  25. package/src/adapters/gemini/install_gemini_integration.js +304 -0
  26. package/src/adapters/iflow/install_iflow_integration.js +304 -0
  27. package/src/adapters/qoder/install_qoder_integration.js +1090 -0
  28. package/src/adapters/qwen/install_qwen_integration.js +285 -0
  29. package/src/auth.js +173 -173
  30. package/src/auth_command.js +208 -208
  31. package/src/calculator.js +313 -313
  32. package/src/cli/router.js +417 -38
  33. package/src/core/cache_cleaner.js +767 -744
  34. package/src/core/cli_help_analyzer.js +680 -674
  35. package/src/core/cli_parameter_handler.js +132 -127
  36. package/src/core/cli_tools.js +89 -89
  37. package/src/core/coordination/index.js +16 -16
  38. package/src/core/coordination/nodejs/AdapterManager.js +102 -89
  39. package/src/core/coordination/nodejs/CLCommunication.js +132 -124
  40. package/src/core/coordination/nodejs/CLIIntegrationManager.js +272 -236
  41. package/src/core/coordination/nodejs/HealthChecker.js +76 -77
  42. package/src/core/coordination/nodejs/HookDeploymentManager.js +263 -190
  43. package/src/core/coordination/nodejs/StatisticsCollector.js +71 -71
  44. package/src/core/coordination/nodejs/index.js +90 -72
  45. package/src/core/coordination/nodejs/utils/Logger.js +29 -29
  46. package/src/core/enhanced_installer.js +479 -456
  47. package/src/core/enhanced_uninstaller.js +638 -618
  48. package/src/core/error_handler.js +406 -406
  49. package/src/core/installer.js +815 -294
  50. package/src/core/memory_manager.js +83 -83
  51. package/src/core/rest_client.js +160 -160
  52. package/src/core/smart_router.js +249 -146
  53. package/src/core/upgrade_manager.js +76 -59
  54. package/src/data_encryption.js +143 -143
  55. package/src/data_structures.js +440 -440
  56. package/src/deploy.js +55 -55
  57. package/src/index.js +30 -30
  58. package/src/test/cli-availability-checker.js +194 -0
  59. package/src/test/test-environment.js +289 -0
  60. package/src/utils/helpers.js +35 -35
  61. package/src/utils.js +921 -915
  62. package/src/weatherProcessor.js +228 -228
  63. package/test/cache-cleaner-implemented.test.js +0 -328
  64. package/test/cache-cleaner.test.js +0 -390
  65. package/test/calculator.test.js +0 -215
  66. package/test/collision-test.js +0 -26
  67. package/test/comprehensive-enhanced-features.test.js +0 -252
  68. package/test/comprehensive-execution-test.js +0 -428
  69. package/test/conflict-prevention-test.js +0 -95
  70. package/test/cross-cli-detection-test.js +0 -33
  71. package/test/csv-processing-test.js +0 -36
  72. package/test/deploy-hooks-test.js +0 -250
  73. package/test/e2e/claude-cli-test.js +0 -128
  74. package/test/e2e/collaboration-test.js +0 -75
  75. package/test/e2e/comprehensive-test.js +0 -431
  76. package/test/e2e/error-handling-test.js +0 -90
  77. package/test/e2e/individual-tool-test.js +0 -143
  78. package/test/e2e/other-cli-test.js +0 -130
  79. package/test/e2e/qoder-cli-test.js +0 -128
  80. package/test/e2e/run-e2e-tests.js +0 -73
  81. package/test/e2e/test-data.js +0 -88
  82. package/test/e2e/test-utils.js +0 -222
  83. package/test/encryption-simple-test.js +0 -110
  84. package/test/encryption.test.js +0 -129
  85. package/test/enhanced-main-alignment.test.js +0 -298
  86. package/test/enhanced-uninstaller-implemented.test.js +0 -271
  87. package/test/enhanced-uninstaller.test.js +0 -284
  88. package/test/error-handling-test.js +0 -341
  89. package/test/fibonacci.test.js +0 -178
  90. package/test/final-deploy-test.js +0 -221
  91. package/test/final-install-test.js +0 -226
  92. package/test/hash-table-demo.js +0 -33
  93. package/test/hash-table-test.js +0 -26
  94. package/test/hash_table_test.js +0 -114
  95. package/test/hook-system-integration-test.js +0 -307
  96. package/test/iflow-integration-test.js +0 -292
  97. package/test/improved-install-test.js +0 -362
  98. package/test/install-command-test.js +0 -370
  99. package/test/json-parser-test.js +0 -161
  100. package/test/json-validation-test.js +0 -164
  101. package/test/natural-language-skills-test.js +0 -320
  102. package/test/nl-integration-test.js +0 -179
  103. package/test/parameter-parsing-test.js +0 -143
  104. package/test/plugin-deployment-test.js +0 -316
  105. package/test/postinstall-test.js +0 -269
  106. package/test/python-plugins-test.js +0 -259
  107. package/test/real-test.js +0 -435
  108. package/test/remaining-adapters-test.js +0 -256
  109. package/test/rest-client-test.js +0 -56
  110. package/test/rest_client.test.js +0 -85
  111. package/test/safe-installation-cleaner.test.js +0 -343
  112. package/test/simple-iflow-hook-test.js +0 -137
  113. package/test/stigmergy-upgrade-test.js +0 -243
  114. package/test/system-compatibility-test.js +0 -467
  115. package/test/tdd-deploy-fix-test.js +0 -324
  116. package/test/tdd-fixes-test.js +0 -211
  117. package/test/third-party-skills-test.js +0 -321
  118. package/test/tool-selection-integration-test.js +0 -158
  119. package/test/unit/calculator-full.test.js +0 -191
  120. package/test/unit/calculator-simple.test.js +0 -96
  121. package/test/unit/calculator.test.js +0 -97
  122. package/test/unit/cli-scanner.test.js +0 -291
  123. package/test/unit/cli_parameter_handler.test.js +0 -116
  124. package/test/unit/cross-cli-executor.test.js +0 -399
  125. package/test/weather-processor.test.js +0 -104
@@ -1,208 +1,208 @@
1
- /**
2
- * Authentication command handler for the Stigmergy CLI.
3
- * Provides CLI commands for user registration, login, and session management.
4
- */
5
-
6
- const fs = require('fs');
7
- const path = require('path');
8
- const { UserAuthenticator, authenticateAndGetToken } = require('./auth');
9
-
10
- /**
11
- * Get the path to the authentication data file.
12
- * @returns {string} Path to the auth data file
13
- */
14
- function getAuthDataPath() {
15
- const homeDir = process.env.HOME || process.env.USERPROFILE;
16
- const configDir = path.join(homeDir, '.stigmergy');
17
-
18
- // Create config directory if it doesn't exist
19
- if (!fs.existsSync(configDir)) {
20
- fs.mkdirSync(configDir, { recursive: true });
21
- }
22
-
23
- return path.join(configDir, 'auth.json');
24
- }
25
-
26
- /**
27
- * Load authentication data from file.
28
- * @param {UserAuthenticator} authenticator - The authenticator instance
29
- */
30
- function loadAuthData(authenticator) {
31
- try {
32
- const authFile = getAuthDataPath();
33
- if (fs.existsSync(authFile)) {
34
- const data = JSON.parse(fs.readFileSync(authFile, 'utf8'));
35
-
36
- // Load users
37
- if (data.users) {
38
- for (const [username, userData] of Object.entries(data.users)) {
39
- authenticator._users.set(username, userData);
40
- }
41
- }
42
-
43
- // Load sessions
44
- if (data.sessions) {
45
- for (const [token, sessionData] of Object.entries(data.sessions)) {
46
- authenticator._sessions.set(token, sessionData);
47
- }
48
- }
49
- }
50
- } catch (error) {
51
- console.warn('[WARN] Could not load authentication data:', error.message);
52
- }
53
- }
54
-
55
- /**
56
- * Save authentication data to file.
57
- * @param {UserAuthenticator} authenticator - The authenticator instance
58
- */
59
- function saveAuthData(authenticator) {
60
- try {
61
- const authFile = getAuthDataPath();
62
-
63
- // Convert Maps to objects for JSON serialization
64
- const users = {};
65
- for (const [username, userData] of authenticator._users.entries()) {
66
- users[username] = userData;
67
- }
68
-
69
- const sessions = {};
70
- for (const [token, sessionData] of authenticator._sessions.entries()) {
71
- sessions[token] = sessionData;
72
- }
73
-
74
- const data = {
75
- users,
76
- sessions,
77
- };
78
-
79
- fs.writeFileSync(authFile, JSON.stringify(data, null, 2));
80
- } catch (error) {
81
- console.warn('[WARN] Could not save authentication data:', error.message);
82
- }
83
- }
84
-
85
- /**
86
- * Handle user registration.
87
- * @param {string} username - The username to register
88
- * @param {string} password - The password for the user
89
- */
90
- function handleRegister(username, password) {
91
- const authenticator = new UserAuthenticator();
92
- loadAuthData(authenticator);
93
-
94
- try {
95
- const success = authenticator.registerUser(username, password);
96
- if (success) {
97
- saveAuthData(authenticator);
98
- console.log(`[SUCCESS] User '${username}' registered successfully`);
99
- } else {
100
- console.log(`[ERROR] Username '${username}' already exists`);
101
- process.exit(1);
102
- }
103
- } catch (error) {
104
- console.log(`[ERROR] Registration failed: ${error.message}`);
105
- process.exit(1);
106
- }
107
- }
108
-
109
- /**
110
- * Handle user login.
111
- * @param {string} username - The username to login
112
- * @param {string} password - The password for the user
113
- */
114
- function handleLogin(username, password) {
115
- const authenticator = new UserAuthenticator();
116
- loadAuthData(authenticator);
117
-
118
- const [success, result] = authenticateAndGetToken(
119
- authenticator,
120
- username,
121
- password,
122
- );
123
-
124
- if (success) {
125
- const token = result;
126
- saveAuthData(authenticator);
127
-
128
- // Also save the token to a session file for easy access
129
- const sessionFile = path.join(
130
- path.dirname(getAuthDataPath()),
131
- 'session.token',
132
- );
133
- fs.writeFileSync(sessionFile, token);
134
-
135
- console.log('[SUCCESS] Login successful');
136
- console.log(`Session token: ${token}`);
137
- } else {
138
- console.log(`[ERROR] Login failed: ${result}`);
139
- process.exit(1);
140
- }
141
- }
142
-
143
- /**
144
- * Handle user logout.
145
- */
146
- function handleLogout() {
147
- const authenticator = new UserAuthenticator();
148
- loadAuthData(authenticator);
149
-
150
- // Read the current session token
151
- const sessionFile = path.join(
152
- path.dirname(getAuthDataPath()),
153
- 'session.token',
154
- );
155
-
156
- if (!fs.existsSync(sessionFile)) {
157
- console.log('[ERROR] No active session found');
158
- process.exit(1);
159
- }
160
-
161
- const token = fs.readFileSync(sessionFile, 'utf8').trim();
162
-
163
- const success = authenticator.logout(token);
164
- if (success) {
165
- saveAuthData(authenticator);
166
- fs.unlinkSync(sessionFile); // Remove the session file
167
- console.log('[SUCCESS] Logged out successfully');
168
- } else {
169
- console.log('[ERROR] Logout failed: Invalid session');
170
- process.exit(1);
171
- }
172
- }
173
-
174
- /**
175
- * Check if user is authenticated.
176
- */
177
- function handleStatus() {
178
- const authenticator = new UserAuthenticator();
179
- loadAuthData(authenticator);
180
-
181
- // Read the current session token
182
- const sessionFile = path.join(
183
- path.dirname(getAuthDataPath()),
184
- 'session.token',
185
- );
186
-
187
- if (!fs.existsSync(sessionFile)) {
188
- console.log('[INFO] No active session');
189
- return;
190
- }
191
-
192
- const token = fs.readFileSync(sessionFile, 'utf8').trim();
193
- const username = authenticator.validateSession(token);
194
-
195
- if (username) {
196
- console.log(`[INFO] Authenticated as: ${username}`);
197
- } else {
198
- console.log('[INFO] Session expired or invalid');
199
- fs.unlinkSync(sessionFile); // Remove the invalid session file
200
- }
201
- }
202
-
203
- module.exports = {
204
- handleRegister,
205
- handleLogin,
206
- handleLogout,
207
- handleStatus,
208
- };
1
+ /**
2
+ * Authentication command handler for the Stigmergy CLI.
3
+ * Provides CLI commands for user registration, login, and session management.
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { UserAuthenticator, authenticateAndGetToken } = require('./auth');
9
+
10
+ /**
11
+ * Get the path to the authentication data file.
12
+ * @returns {string} Path to the auth data file
13
+ */
14
+ function getAuthDataPath() {
15
+ const homeDir = process.env.HOME || process.env.USERPROFILE;
16
+ const configDir = path.join(homeDir, '.stigmergy');
17
+
18
+ // Create config directory if it doesn't exist
19
+ if (!fs.existsSync(configDir)) {
20
+ fs.mkdirSync(configDir, { recursive: true });
21
+ }
22
+
23
+ return path.join(configDir, 'auth.json');
24
+ }
25
+
26
+ /**
27
+ * Load authentication data from file.
28
+ * @param {UserAuthenticator} authenticator - The authenticator instance
29
+ */
30
+ function loadAuthData(authenticator) {
31
+ try {
32
+ const authFile = getAuthDataPath();
33
+ if (fs.existsSync(authFile)) {
34
+ const data = JSON.parse(fs.readFileSync(authFile, 'utf8'));
35
+
36
+ // Load users
37
+ if (data.users) {
38
+ for (const [username, userData] of Object.entries(data.users)) {
39
+ authenticator._users.set(username, userData);
40
+ }
41
+ }
42
+
43
+ // Load sessions
44
+ if (data.sessions) {
45
+ for (const [token, sessionData] of Object.entries(data.sessions)) {
46
+ authenticator._sessions.set(token, sessionData);
47
+ }
48
+ }
49
+ }
50
+ } catch (error) {
51
+ console.warn('[WARN] Could not load authentication data:', error.message);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Save authentication data to file.
57
+ * @param {UserAuthenticator} authenticator - The authenticator instance
58
+ */
59
+ function saveAuthData(authenticator) {
60
+ try {
61
+ const authFile = getAuthDataPath();
62
+
63
+ // Convert Maps to objects for JSON serialization
64
+ const users = {};
65
+ for (const [username, userData] of authenticator._users.entries()) {
66
+ users[username] = userData;
67
+ }
68
+
69
+ const sessions = {};
70
+ for (const [token, sessionData] of authenticator._sessions.entries()) {
71
+ sessions[token] = sessionData;
72
+ }
73
+
74
+ const data = {
75
+ users,
76
+ sessions,
77
+ };
78
+
79
+ fs.writeFileSync(authFile, JSON.stringify(data, null, 2));
80
+ } catch (error) {
81
+ console.warn('[WARN] Could not save authentication data:', error.message);
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Handle user registration.
87
+ * @param {string} username - The username to register
88
+ * @param {string} password - The password for the user
89
+ */
90
+ function handleRegister(username, password) {
91
+ const authenticator = new UserAuthenticator();
92
+ loadAuthData(authenticator);
93
+
94
+ try {
95
+ const success = authenticator.registerUser(username, password);
96
+ if (success) {
97
+ saveAuthData(authenticator);
98
+ console.log(`[SUCCESS] User '${username}' registered successfully`);
99
+ } else {
100
+ console.log(`[ERROR] Username '${username}' already exists`);
101
+ process.exit(1);
102
+ }
103
+ } catch (error) {
104
+ console.log(`[ERROR] Registration failed: ${error.message}`);
105
+ process.exit(1);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Handle user login.
111
+ * @param {string} username - The username to login
112
+ * @param {string} password - The password for the user
113
+ */
114
+ function handleLogin(username, password) {
115
+ const authenticator = new UserAuthenticator();
116
+ loadAuthData(authenticator);
117
+
118
+ const [success, result] = authenticateAndGetToken(
119
+ authenticator,
120
+ username,
121
+ password,
122
+ );
123
+
124
+ if (success) {
125
+ const token = result;
126
+ saveAuthData(authenticator);
127
+
128
+ // Also save the token to a session file for easy access
129
+ const sessionFile = path.join(
130
+ path.dirname(getAuthDataPath()),
131
+ 'session.token',
132
+ );
133
+ fs.writeFileSync(sessionFile, token);
134
+
135
+ console.log('[SUCCESS] Login successful');
136
+ console.log(`Session token: ${token}`);
137
+ } else {
138
+ console.log(`[ERROR] Login failed: ${result}`);
139
+ process.exit(1);
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Handle user logout.
145
+ */
146
+ function handleLogout() {
147
+ const authenticator = new UserAuthenticator();
148
+ loadAuthData(authenticator);
149
+
150
+ // Read the current session token
151
+ const sessionFile = path.join(
152
+ path.dirname(getAuthDataPath()),
153
+ 'session.token',
154
+ );
155
+
156
+ if (!fs.existsSync(sessionFile)) {
157
+ console.log('[ERROR] No active session found');
158
+ process.exit(1);
159
+ }
160
+
161
+ const token = fs.readFileSync(sessionFile, 'utf8').trim();
162
+
163
+ const success = authenticator.logout(token);
164
+ if (success) {
165
+ saveAuthData(authenticator);
166
+ fs.unlinkSync(sessionFile); // Remove the session file
167
+ console.log('[SUCCESS] Logged out successfully');
168
+ } else {
169
+ console.log('[ERROR] Logout failed: Invalid session');
170
+ process.exit(1);
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Check if user is authenticated.
176
+ */
177
+ function handleStatus() {
178
+ const authenticator = new UserAuthenticator();
179
+ loadAuthData(authenticator);
180
+
181
+ // Read the current session token
182
+ const sessionFile = path.join(
183
+ path.dirname(getAuthDataPath()),
184
+ 'session.token',
185
+ );
186
+
187
+ if (!fs.existsSync(sessionFile)) {
188
+ console.log('[INFO] No active session');
189
+ return;
190
+ }
191
+
192
+ const token = fs.readFileSync(sessionFile, 'utf8').trim();
193
+ const username = authenticator.validateSession(token);
194
+
195
+ if (username) {
196
+ console.log(`[INFO] Authenticated as: ${username}`);
197
+ } else {
198
+ console.log('[INFO] Session expired or invalid');
199
+ fs.unlinkSync(sessionFile); // Remove the invalid session file
200
+ }
201
+ }
202
+
203
+ module.exports = {
204
+ handleRegister,
205
+ handleLogin,
206
+ handleLogout,
207
+ handleStatus,
208
+ };