stigmergy 1.0.68 → 1.0.70

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 (102) hide show
  1. package/README.en.md +306 -300
  2. package/README.md +469 -301
  3. package/package.json +97 -81
  4. package/scripts/publish.js +268 -0
  5. package/scripts/simple-publish.js +59 -0
  6. package/src/index.js +12 -0
  7. package/test/enhanced-main-alignment.test.js +298 -0
  8. package/test/hook-system-integration-test.js +307 -0
  9. package/test/natural-language-skills-test.js +320 -0
  10. package/test/nl-integration-test.js +179 -0
  11. package/test/parameter-parsing-test.js +143 -0
  12. package/test/real-test.js +435 -0
  13. package/test/system-compatibility-test.js +447 -0
  14. package/test/tdd-fixes-test.js +211 -0
  15. package/test/third-party-skills-test.js +321 -0
  16. package/test/tool-selection-integration-test.js +157 -0
  17. package/test/unit/cli-scanner.test.js +291 -0
  18. package/test/unit/cross-cli-executor.test.js +399 -0
  19. package/src/adapters/claude/__init__.py +0 -13
  20. package/src/adapters/claude/claude_skills_integration.py +0 -609
  21. package/src/adapters/claude/hook_adapter.py +0 -663
  22. package/src/adapters/claude/install_claude_integration.py +0 -265
  23. package/src/adapters/claude/skills_hook_adapter.py +0 -841
  24. package/src/adapters/claude/standalone_claude_adapter.py +0 -384
  25. package/src/adapters/cline/__init__.py +0 -20
  26. package/src/adapters/cline/config.py +0 -108
  27. package/src/adapters/cline/install_cline_integration.py +0 -617
  28. package/src/adapters/cline/mcp_server.py +0 -713
  29. package/src/adapters/cline/standalone_cline_adapter.py +0 -459
  30. package/src/adapters/codebuddy/__init__.py +0 -13
  31. package/src/adapters/codebuddy/buddy_adapter.py +0 -1125
  32. package/src/adapters/codebuddy/install_codebuddy_integration.py +0 -279
  33. package/src/adapters/codebuddy/skills_hook_adapter.py +0 -672
  34. package/src/adapters/codebuddy/skills_integration.py +0 -395
  35. package/src/adapters/codebuddy/standalone_codebuddy_adapter.py +0 -403
  36. package/src/adapters/codex/__init__.py +0 -11
  37. package/src/adapters/codex/base.py +0 -46
  38. package/src/adapters/codex/install_codex_integration.py +0 -311
  39. package/src/adapters/codex/mcp_server.py +0 -493
  40. package/src/adapters/codex/natural_language_parser.py +0 -82
  41. package/src/adapters/codex/slash_command_adapter.py +0 -326
  42. package/src/adapters/codex/standalone_codex_adapter.py +0 -362
  43. package/src/adapters/copilot/__init__.py +0 -13
  44. package/src/adapters/copilot/install_copilot_integration.py +0 -564
  45. package/src/adapters/copilot/mcp_adapter.py +0 -772
  46. package/src/adapters/copilot/mcp_server.py +0 -168
  47. package/src/adapters/copilot/standalone_copilot_adapter.py +0 -114
  48. package/src/adapters/gemini/__init__.py +0 -13
  49. package/src/adapters/gemini/extension_adapter.py +0 -690
  50. package/src/adapters/gemini/install_gemini_integration.py +0 -257
  51. package/src/adapters/gemini/standalone_gemini_adapter.py +0 -366
  52. package/src/adapters/iflow/__init__.py +0 -7
  53. package/src/adapters/iflow/hook_adapter.py +0 -1038
  54. package/src/adapters/iflow/hook_installer.py +0 -536
  55. package/src/adapters/iflow/install_iflow_integration.py +0 -271
  56. package/src/adapters/iflow/official_hook_adapter.py +0 -1272
  57. package/src/adapters/iflow/standalone_iflow_adapter.py +0 -48
  58. package/src/adapters/iflow/workflow_adapter.py +0 -793
  59. package/src/adapters/qoder/hook_installer.py +0 -732
  60. package/src/adapters/qoder/install_qoder_integration.py +0 -265
  61. package/src/adapters/qoder/notification_hook_adapter.py +0 -863
  62. package/src/adapters/qoder/standalone_qoder_adapter.py +0 -48
  63. package/src/adapters/qwen/__init__.py +0 -17
  64. package/src/adapters/qwencode/__init__.py +0 -13
  65. package/src/adapters/qwencode/inheritance_adapter.py +0 -818
  66. package/src/adapters/qwencode/install_qwencode_integration.py +0 -276
  67. package/src/adapters/qwencode/standalone_qwencode_adapter.py +0 -399
  68. package/src/atomic_collaboration_handler.py +0 -461
  69. package/src/cli_collaboration_agent.py +0 -697
  70. package/src/collaboration/hooks.py +0 -315
  71. package/src/core/__init__.py +0 -21
  72. package/src/core/ai_environment_scanner.py +0 -331
  73. package/src/core/base_adapter.py +0 -220
  74. package/src/core/cli_hook_integration.py +0 -406
  75. package/src/core/cross_cli_executor.py +0 -713
  76. package/src/core/cross_cli_mapping.py +0 -1165
  77. package/src/core/cross_platform_encoding.py +0 -365
  78. package/src/core/cross_platform_safe_cli.py +0 -894
  79. package/src/core/direct_cli_executor.py +0 -805
  80. package/src/core/direct_cli_hook_system.py +0 -958
  81. package/src/core/enhanced_init_processor.py +0 -467
  82. package/src/core/graceful_cli_executor.py +0 -912
  83. package/src/core/md_enhancer.py +0 -342
  84. package/src/core/md_generator.py +0 -619
  85. package/src/core/models.py +0 -218
  86. package/src/core/parser.py +0 -108
  87. package/src/core/real_cli_hook_system.py +0 -852
  88. package/src/core/real_cross_cli_system.py +0 -925
  89. package/src/core/verified_cross_cli_system.py +0 -961
  90. package/src/deploy.js +0 -737
  91. package/src/enhanced-main.js +0 -626
  92. package/src/enhanced_deploy.js +0 -303
  93. package/src/enhanced_universal_cli_setup.py +0 -930
  94. package/src/kimi_wrapper.py +0 -104
  95. package/src/main.js +0 -1309
  96. package/src/shell_integration.py +0 -398
  97. package/src/simple-main.js +0 -315
  98. package/src/smart_router_creator.py +0 -323
  99. package/src/universal_cli_setup.py +0 -1289
  100. package/src/utils/__init__.py +0 -12
  101. package/src/utils/cli_detector.py +0 -445
  102. package/src/utils/file_utils.py +0 -246
@@ -0,0 +1,435 @@
1
+ /**
2
+ * Real Test Runner - TDD Implementation Validation
3
+ * 真实测试,无Mock,ANSI编码,Node.js优先
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+
9
+ // 导入我们的实现
10
+ const CLIScanner = require('../src/core/cli-scanner');
11
+ const CrossCLIExecutor = require('../src/core/cross-cli-executor');
12
+
13
+ // ANSI安全输出
14
+ function safeLog(message) {
15
+ process.stdout.write(`${message}\n`);
16
+ }
17
+
18
+ // 简单的测试框架
19
+ class RealTestRunner {
20
+ constructor() {
21
+ this.results = {
22
+ passed: 0,
23
+ failed: 0,
24
+ skipped: 0,
25
+ errors: 0
26
+ };
27
+ }
28
+
29
+ async test(name, testFn) {
30
+ try {
31
+ safeLog(`Testing: ${name}`);
32
+ await testFn();
33
+ this.results.passed++;
34
+ safeLog(`[PASS] ${name}`);
35
+ } catch (error) {
36
+ this.results.failed++;
37
+ safeLog(`[FAIL] ${name}`);
38
+ safeLog(` Error: ${error.message}`);
39
+ }
40
+ }
41
+
42
+ skip(name, reason) {
43
+ this.results.skipped++;
44
+ safeLog(`[SKIP] ${name} - ${reason}`);
45
+ }
46
+
47
+ error(name, error) {
48
+ this.results.errors++;
49
+ safeLog(`[ERROR] ${name}`);
50
+ safeLog(` ${error.message}`);
51
+ }
52
+
53
+ printSummary() {
54
+ const total = this.results.passed + this.results.failed + this.results.skipped + this.results.errors;
55
+ safeLog(`\n=== Test Summary ===`);
56
+ safeLog(`Total: ${total}`);
57
+ safeLog(`Passed: ${this.results.passed}`);
58
+ safeLog(`Failed: ${this.results.failed}`);
59
+ safeLog(`Skipped: ${this.results.skipped}`);
60
+ safeLog(`Errors: ${this.results.errors}`);
61
+ safeLog(`Success Rate: ${((this.results.passed / total) * 100).toFixed(1)}%`);
62
+ }
63
+ }
64
+
65
+ // 测试套件
66
+ async function runRealTests() {
67
+ safeLog('Starting Real TDD Tests - No Mocks, ANSI Encoding Only');
68
+ safeLog('='.repeat(60));
69
+
70
+ const runner = new RealTestRunner();
71
+
72
+ // 1. CLI扫描器测试
73
+ safeLog('\n--- CLI Scanner Tests ---');
74
+
75
+ await runner.test('Scanner initialization', () => {
76
+ const scanner = new CLIScanner();
77
+ if (!scanner) {
78
+ throw new Error('Scanner failed to initialize');
79
+ }
80
+ });
81
+
82
+ await runner.test('Detect Node.js CLI', async () => {
83
+ const scanner = new CLIScanner();
84
+ const result = await scanner.scanForCLI('node', { timeout: 5000 });
85
+
86
+ if (!result.available) {
87
+ throw new Error('Node.js should be available');
88
+ }
89
+ if (!result.version) {
90
+ throw new Error('Node.js version should be detected');
91
+ }
92
+ if (!result.path) {
93
+ throw new Error('Node.js path should be detected');
94
+ }
95
+ });
96
+
97
+ await runner.test('Detect NPM CLI', async () => {
98
+ const scanner = new CLIScanner();
99
+ const result = await scanner.scanForCLI('npm', { timeout: 5000 });
100
+
101
+ if (!result.available) {
102
+ throw new Error('NPM should be available');
103
+ }
104
+ if (!result.version) {
105
+ throw new Error('NPM version should be detected');
106
+ }
107
+ });
108
+
109
+ await runner.test('Handle non-existent CLI', async () => {
110
+ const scanner = new CLIScanner();
111
+ const result = await scanner.scanForCLI('non-existent-cli-12345', { timeout: 3000 });
112
+
113
+ if (result.available) {
114
+ throw new Error('Non-existent CLI should not be available');
115
+ }
116
+ if (!result.error) {
117
+ throw new Error('Should include error message');
118
+ }
119
+ });
120
+
121
+ await runner.test('Batch CLI detection', async () => {
122
+ const scanner = new CLIScanner();
123
+ const results = await scanner.detectInstalledCLIs(['node', 'npm', 'non-existent-cli'], { timeout: 5000 });
124
+
125
+ if (results.size !== 3) {
126
+ throw new Error('Should return results for all 3 CLIs');
127
+ }
128
+ if (!results.get('node').available) {
129
+ throw new Error('Node should be available');
130
+ }
131
+ if (!results.get('npm').available) {
132
+ throw new Error('NPM should be available');
133
+ }
134
+ if (results.get('non-existent-cli').available) {
135
+ throw new Error('Non-existent CLI should not be available');
136
+ }
137
+ });
138
+
139
+ await runner.test('CLI validation', () => {
140
+ const scanner = new CLIScanner();
141
+
142
+ if (!scanner.validateCLIExecutable('node')) {
143
+ throw new Error('Node should be valid executable');
144
+ }
145
+ if (scanner.validateCLIExecutable('')) {
146
+ throw new Error('Empty string should not be valid');
147
+ }
148
+ if (scanner.validateCLIExecutable('non-existent-command-12345')) {
149
+ throw new Error('Random string should not be valid executable');
150
+ }
151
+ });
152
+
153
+ // 2. 跨CLI执行器测试
154
+ safeLog('\n--- Cross-CLI Executor Tests ---');
155
+
156
+ await runner.test('Executor initialization', () => {
157
+ const executor = new CrossCLIExecutor();
158
+ if (!executor) {
159
+ throw new Error('Executor failed to initialize');
160
+ }
161
+ });
162
+
163
+ await runner.test('Execute Node.js command', async () => {
164
+ const executor = new CrossCLIExecutor();
165
+ const result = await executor.executeCommand('node', ['--version'], { timeout: 5000 });
166
+
167
+ if (!result.success) {
168
+ throw new Error('Node version command should succeed');
169
+ }
170
+ if (!result.stdout) {
171
+ throw new Error('Should have stdout output');
172
+ }
173
+ if (result.exitCode !== 0) {
174
+ throw new Error('Exit code should be 0');
175
+ }
176
+ });
177
+
178
+ await runner.test('Execute NPM command', async () => {
179
+ const executor = new CrossCLIExecutor();
180
+ const result = await executor.executeCommand('npm', ['--version'], { timeout: 5000 });
181
+
182
+ if (!result.success) {
183
+ throw new Error('NPM version command should succeed');
184
+ }
185
+ if (!result.stdout) {
186
+ throw new Error('Should have stdout output');
187
+ }
188
+ });
189
+
190
+ await runner.test('Handle command timeout', async () => {
191
+ const executor = new CrossCLIExecutor();
192
+ const startTime = Date.now();
193
+
194
+ try {
195
+ await executor.executeCommand('node', ['-e', 'setTimeout(() => {}, 5000)'], { timeout: 2000 });
196
+ throw new Error('Should have thrown timeout error');
197
+ } catch (error) {
198
+ const elapsed = Date.now() - startTime;
199
+ if (elapsed > 10000) { // 10秒安全边界
200
+ throw new Error('Timeout should have occurred quickly');
201
+ }
202
+ }
203
+ });
204
+
205
+ await runner.test('Handle non-existent command', async () => {
206
+ const executor = new CrossCLIExecutor();
207
+ const result = await executor.executeCommand('non-existent-command-12345', [], { timeout: 3000 });
208
+
209
+ if (result.success) {
210
+ throw new Error('Non-existent command should fail');
211
+ }
212
+ if (!result.error) {
213
+ throw new Error('Should include error message');
214
+ }
215
+ });
216
+
217
+ await runner.test('Parameter validation', () => {
218
+ const executor = new CrossCLIExecutor();
219
+
220
+ // 有效参数
221
+ const validResult = executor.validateExecutionParams('claude', 'gemini', 'test task');
222
+ if (!validResult.valid) {
223
+ throw new Error('Valid parameters should pass');
224
+ }
225
+
226
+ // 无效参数
227
+ const invalidResult1 = executor.validateExecutionParams('', 'gemini', 'test task');
228
+ if (invalidResult1.valid) {
229
+ throw new Error('Empty source CLI should be invalid');
230
+ }
231
+
232
+ const invalidResult2 = executor.validateExecutionParams('claude', '', 'test task');
233
+ if (invalidResult2.valid) {
234
+ throw new Error('Empty target CLI should be invalid');
235
+ }
236
+
237
+ const invalidResult3 = executor.validateExecutionParams('claude', 'gemini', '');
238
+ if (invalidResult3.valid) {
239
+ throw new Error('Empty task should be invalid');
240
+ }
241
+
242
+ const invalidResult4 = executor.validateExecutionParams('claude', 'claude', 'test task');
243
+ if (invalidResult4.valid) {
244
+ throw new Error('Same source and target should be invalid');
245
+ }
246
+ });
247
+
248
+ // 3. 跨CLI协作测试
249
+ safeLog('\n--- Cross-CLI Collaboration Tests ---');
250
+
251
+ await runner.test('Dry run cross-CLI execution', async () => {
252
+ const executor = new CrossCLIExecutor();
253
+ const result = await executor.executeCrossCLI('claude', 'gemini', 'translate "hello world"', {
254
+ dryRun: true,
255
+ timeout: 5000
256
+ });
257
+
258
+ if (!result.success) {
259
+ throw new Error('Dry run should succeed');
260
+ }
261
+ if (!result.sourceCLI || result.sourceCLI !== 'claude') {
262
+ throw new Error('Should preserve source CLI');
263
+ }
264
+ if (!result.targetCLI || result.targetCLI !== 'gemini') {
265
+ throw new Error('Should preserve target CLI');
266
+ }
267
+ if (!result.executionId) {
268
+ throw new Error('Should generate execution ID');
269
+ }
270
+ });
271
+
272
+ // 4. 性能和内存测试
273
+ safeLog('\n--- Performance Tests ---');
274
+
275
+ await runner.test('Concurrent command execution', async () => {
276
+ const executor = new CrossCLIExecutor();
277
+ const startTime = Date.now();
278
+
279
+ const commands = [
280
+ executor.executeCommand('node', ['--version']),
281
+ executor.executeCommand('npm', ['--version']),
282
+ executor.executeCommand('node', ['-e', 'console.log("test")'])
283
+ ];
284
+
285
+ const results = await Promise.all(commands);
286
+ const elapsed = Date.now() - startTime;
287
+
288
+ if (results.length !== 3) {
289
+ throw new Error('Should execute all 3 commands');
290
+ }
291
+ if (!results.every(r => r.success)) {
292
+ throw new Error('All commands should succeed');
293
+ }
294
+ if (elapsed > 15000) { // 15秒安全边界
295
+ throw new Error('Should complete within reasonable time');
296
+ }
297
+ });
298
+
299
+ await runner.test('Memory usage', async () => {
300
+ const initialMemory = process.memoryUsage().heapUsed;
301
+ const executor = new CrossCLIExecutor();
302
+
303
+ // 执行多个命令测试内存泄漏
304
+ for (let i = 0; i < 20; i++) {
305
+ await executor.executeCommand('node', ['--version']);
306
+ }
307
+
308
+ // 强制垃圾回收(如果可用)
309
+ if (global.gc) {
310
+ global.gc();
311
+ }
312
+
313
+ const finalMemory = process.memoryUsage().heapUsed;
314
+ const memoryIncrease = finalMemory - initialMemory;
315
+
316
+ // 内存增长应该控制在合理范围内
317
+ const maxAcceptableIncrease = 50 * 1024 * 1024; // 50MB
318
+ if (memoryIncrease > maxAcceptableIncrease) {
319
+ throw new Error(`Memory increased too much: ${Math.round(memoryIncrease / 1024 / 1024)}MB`);
320
+ }
321
+ });
322
+
323
+ // 5. 平台特定测试
324
+ safeLog('\n--- Platform-Specific Tests ---');
325
+
326
+ if (process.platform === 'win32') {
327
+ await runner.test('Windows command execution', async () => {
328
+ const executor = new CrossCLIExecutor();
329
+ const result = await executor.executeCommand('cmd', ['/c', 'echo test'], { timeout: 5000 });
330
+
331
+ if (!result.success) {
332
+ throw new Error('Windows cmd should succeed');
333
+ }
334
+ });
335
+ } else {
336
+ await runner.test('Unix command execution', async () => {
337
+ const executor = new CrossCLIExecutor();
338
+ const result = await executor.executeCommand('echo', ['test'], { timeout: 5000 });
339
+
340
+ if (!result.success) {
341
+ throw new Error('Unix echo should succeed');
342
+ }
343
+ });
344
+ }
345
+
346
+ // 6. 错误处理和边界条件测试
347
+ safeLog('\n--- Error Handling Tests ---');
348
+
349
+ await runner.test('Invalid input handling', async () => {
350
+ const executor = new CrossCLIExecutor();
351
+
352
+ // 测试无效命令
353
+ try {
354
+ await executor.executeCommand('', []);
355
+ throw new Error('Empty command should throw error');
356
+ } catch (error) {
357
+ if (!error.message.includes('Invalid command')) {
358
+ throw new Error('Should have specific error message');
359
+ }
360
+ }
361
+ });
362
+
363
+ await runner.test('Statistics tracking', async () => {
364
+ const executor = new CrossCLIExecutor();
365
+ const initialStats = executor.getStats();
366
+
367
+ // 执行一些命令
368
+ await executor.executeCommand('node', ['--version']);
369
+ await executor.executeCommand('non-existent-command', []);
370
+
371
+ const finalStats = executor.getStats();
372
+ if (finalStats.totalExecutions <= initialStats.totalExecutions) {
373
+ throw new Error('Statistics should track executions');
374
+ }
375
+ });
376
+
377
+ // 打印总结
378
+ runner.printSummary();
379
+
380
+ // 7. 集成测试
381
+ safeLog('\n--- Integration Tests ---');
382
+
383
+ await runner.test('End-to-end scanner and executor integration', async () => {
384
+ const scanner = new CLIScanner();
385
+ const executor = new CrossCLIExecutor();
386
+
387
+ // 扫描可用的CLI
388
+ const scanResults = await scanner.detectInstalledCLIs(['node', 'npm']);
389
+
390
+ if (scanResults.size === 0) {
391
+ throw new Error('Should detect at least some CLI tools');
392
+ }
393
+
394
+ // 使用检测到的CLI执行命令
395
+ for (const [cliName, cliInfo] of scanResults) {
396
+ if (cliInfo.available) {
397
+ const result = await executor.executeCommand(cliName, ['--version']);
398
+ if (!result.success) {
399
+ safeLog(`Warning: ${cliName} detected but failed to execute`);
400
+ }
401
+ }
402
+ }
403
+ });
404
+
405
+ safeLog('\n=== All Real Tests Completed ===');
406
+ runner.printSummary();
407
+
408
+ return runner.results;
409
+ }
410
+
411
+ // 主执行函数
412
+ async function main() {
413
+ try {
414
+ const results = await runRealTests();
415
+
416
+ // 设置退出码
417
+ if (results.failed > 0 || results.errors > 0) {
418
+ process.exit(1);
419
+ } else {
420
+ process.exit(0);
421
+ }
422
+
423
+ } catch (error) {
424
+ safeLog(`Fatal error during test execution: ${error.message}`);
425
+ safeLog(`Stack trace: ${error.stack}`);
426
+ process.exit(1);
427
+ }
428
+ }
429
+
430
+ // 如果直接运行此文件
431
+ if (require.main === module) {
432
+ main();
433
+ }
434
+
435
+ module.exports = { RealTestRunner, runRealTests };