claude-flow-novice 1.5.6 → 1.5.8
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/.claude-flow-novice/dist/src/cli/simple-commands/init/index.js +2 -18
- package/.claude-flow-novice/dist/src/cli/simple-commands/mcp.js +420 -0
- package/.claude-flow-novice/dist/src/mcp/mcp-config-manager.js +1362 -0
- package/.claude-flow-novice/dist/src/mcp/mcp-server-novice-simplified.js +583 -0
- package/.claude-flow-novice/dist/src/mcp/mcp-server-novice.js +723 -0
- package/.claude-flow-novice/dist/src/mcp/mcp-server-sdk.js +649 -0
- package/.claude-flow-novice/dist/src/mcp/mcp-server.js +2256 -0
- package/.claude-flow-novice/dist/src/mcp/ruv-swarm-wrapper.js +254 -0
- package/package.json +2 -2
- package/src/cli/simple-commands/init/index.js +2 -18
- package/src/cli/simple-commands/init/template-copier.js +18 -81
- package/examples/sdk-swarm-demo.js +0 -194
- package/src/cli/simple-commands/init/templates/claude-md.js +0 -982
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrapper for ruv-swarm MCP server to handle logger issues
|
|
3
|
+
* This wrapper ensures compatibility and handles known issues in ruv-swarm
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { spawn } from 'child_process';
|
|
7
|
+
import { createInterface } from 'readline';
|
|
8
|
+
|
|
9
|
+
export class RuvSwarmWrapper {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.options = {
|
|
12
|
+
silent: options.silent || false,
|
|
13
|
+
autoRestart: options.autoRestart !== false,
|
|
14
|
+
maxRestarts: options.maxRestarts || 3,
|
|
15
|
+
restartDelay: options.restartDelay || 1000,
|
|
16
|
+
...options,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
this.process = null;
|
|
20
|
+
this.restartCount = 0;
|
|
21
|
+
this.isShuttingDown = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async start() {
|
|
25
|
+
if (this.process) {
|
|
26
|
+
throw new Error('RuvSwarm MCP server is already running');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
try {
|
|
31
|
+
// Spawn ruv-swarm MCP server
|
|
32
|
+
this.process = spawn('npx', ['ruv-swarm', 'mcp', 'start'], {
|
|
33
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
34
|
+
env: {
|
|
35
|
+
...process.env,
|
|
36
|
+
// Ensure stdio mode for MCP
|
|
37
|
+
MCP_MODE: 'stdio',
|
|
38
|
+
// Set log level to reduce noise
|
|
39
|
+
LOG_LEVEL: 'WARN',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
let initialized = false;
|
|
44
|
+
let initTimeout;
|
|
45
|
+
|
|
46
|
+
// Handle stdout (JSON-RPC messages)
|
|
47
|
+
const rlOut = createInterface({
|
|
48
|
+
input: this.process.stdout,
|
|
49
|
+
crlfDelay: Infinity,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
rlOut.on('line', (line) => {
|
|
53
|
+
try {
|
|
54
|
+
const message = JSON.parse(line);
|
|
55
|
+
|
|
56
|
+
// Check for initialization
|
|
57
|
+
if (message.method === 'server.initialized' && !initialized) {
|
|
58
|
+
initialized = true;
|
|
59
|
+
clearTimeout(initTimeout);
|
|
60
|
+
resolve({
|
|
61
|
+
process: this.process,
|
|
62
|
+
stdout: this.process.stdout,
|
|
63
|
+
stdin: this.process.stdin,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Forward JSON-RPC messages
|
|
68
|
+
process.stdout.write(line + '\n');
|
|
69
|
+
} catch (err) {
|
|
70
|
+
// Not JSON, ignore
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Handle stderr (logs and errors)
|
|
75
|
+
const rlErr = createInterface({
|
|
76
|
+
input: this.process.stderr,
|
|
77
|
+
crlfDelay: Infinity,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
rlErr.on('line', (line) => {
|
|
81
|
+
// Parse structured error messages if available
|
|
82
|
+
try {
|
|
83
|
+
const errorData = JSON.parse(line);
|
|
84
|
+
if (errorData.error && errorData.error.code) {
|
|
85
|
+
// Handle specific error codes
|
|
86
|
+
switch (errorData.error.code) {
|
|
87
|
+
case 'LOGGER_METHOD_MISSING':
|
|
88
|
+
case 'ERR_LOGGER_MEMORY_USAGE':
|
|
89
|
+
// Known issue with logger.logMemoryUsage in ruv-swarm
|
|
90
|
+
if (!this.options.silent) {
|
|
91
|
+
console.error(
|
|
92
|
+
'⚠️ Known ruv-swarm logger issue detected (continuing normally)',
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
case 'ERR_INITIALIZATION':
|
|
97
|
+
console.error('❌ RuvSwarm initialization error:', errorData.error.message);
|
|
98
|
+
return;
|
|
99
|
+
default:
|
|
100
|
+
// Unknown error code, log it
|
|
101
|
+
if (!this.options.silent) {
|
|
102
|
+
console.error(
|
|
103
|
+
`RuvSwarm error [${errorData.error.code}]:`,
|
|
104
|
+
errorData.error.message,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
} catch (e) {
|
|
111
|
+
// Not JSON, check for known text patterns as fallback
|
|
112
|
+
const knownErrorPatterns = [
|
|
113
|
+
{
|
|
114
|
+
pattern: /logger\.logMemoryUsage is not a function/,
|
|
115
|
+
code: 'LOGGER_METHOD_MISSING',
|
|
116
|
+
message: 'Known ruv-swarm logger issue detected (continuing normally)',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
pattern: /Cannot find module/,
|
|
120
|
+
code: 'MODULE_NOT_FOUND',
|
|
121
|
+
message: 'Module not found error',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
pattern: /ECONNREFUSED/,
|
|
125
|
+
code: 'CONNECTION_REFUSED',
|
|
126
|
+
message: 'Connection refused error',
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
for (const errorPattern of knownErrorPatterns) {
|
|
131
|
+
if (errorPattern.pattern.test(line)) {
|
|
132
|
+
if (!this.options.silent || errorPattern.code !== 'LOGGER_METHOD_MISSING') {
|
|
133
|
+
console.error(`⚠️ ${errorPattern.message}`);
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Filter out initialization messages if silent
|
|
141
|
+
if (this.options.silent) {
|
|
142
|
+
if (line.includes('✅') || line.includes('🧠') || line.includes('📊')) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Forward other stderr output
|
|
148
|
+
if (!this.options.silent) {
|
|
149
|
+
process.stderr.write(line + '\n');
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Handle process errors
|
|
154
|
+
this.process.on('error', (error) => {
|
|
155
|
+
if (!initialized) {
|
|
156
|
+
clearTimeout(initTimeout);
|
|
157
|
+
reject(new Error(`Failed to start ruv-swarm: ${error.message}`));
|
|
158
|
+
} else {
|
|
159
|
+
console.error('RuvSwarm process error:', error);
|
|
160
|
+
this.handleProcessExit(error.code || 1);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Handle process exit
|
|
165
|
+
this.process.on('exit', (code, signal) => {
|
|
166
|
+
if (!initialized) {
|
|
167
|
+
clearTimeout(initTimeout);
|
|
168
|
+
reject(
|
|
169
|
+
new Error(`RuvSwarm exited before initialization: code ${code}, signal ${signal}`),
|
|
170
|
+
);
|
|
171
|
+
} else {
|
|
172
|
+
this.handleProcessExit(code || 0);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Set initialization timeout
|
|
177
|
+
initTimeout = setTimeout(() => {
|
|
178
|
+
if (!initialized) {
|
|
179
|
+
this.stop();
|
|
180
|
+
reject(new Error('RuvSwarm initialization timeout'));
|
|
181
|
+
}
|
|
182
|
+
}, 30000); // 30 second timeout
|
|
183
|
+
} catch (error) {
|
|
184
|
+
reject(error);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
handleProcessExit(code) {
|
|
190
|
+
this.process = null;
|
|
191
|
+
|
|
192
|
+
if (this.isShuttingDown) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
console.error(`RuvSwarm MCP server exited with code ${code}`);
|
|
197
|
+
|
|
198
|
+
// Auto-restart if enabled and under limit
|
|
199
|
+
if (this.options.autoRestart && this.restartCount < this.options.maxRestarts) {
|
|
200
|
+
this.restartCount++;
|
|
201
|
+
console.log(
|
|
202
|
+
`Attempting to restart RuvSwarm (attempt ${this.restartCount}/${this.options.maxRestarts})...`,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
this.start().catch((err) => {
|
|
207
|
+
console.error('Failed to restart RuvSwarm:', err);
|
|
208
|
+
});
|
|
209
|
+
}, this.options.restartDelay);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async stop() {
|
|
214
|
+
this.isShuttingDown = true;
|
|
215
|
+
|
|
216
|
+
if (!this.process) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return new Promise((resolve) => {
|
|
221
|
+
const killTimeout = setTimeout(() => {
|
|
222
|
+
console.warn('RuvSwarm did not exit gracefully, forcing kill...');
|
|
223
|
+
this.process.kill('SIGKILL');
|
|
224
|
+
}, 5000);
|
|
225
|
+
|
|
226
|
+
this.process.on('exit', () => {
|
|
227
|
+
clearTimeout(killTimeout);
|
|
228
|
+
this.process = null;
|
|
229
|
+
resolve();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Send graceful shutdown signal
|
|
233
|
+
this.process.kill('SIGTERM');
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
isRunning() {
|
|
238
|
+
return this.process !== null && !this.process.killed;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Export a function to start ruv-swarm with error handling
|
|
243
|
+
export async function startRuvSwarmMCP(options = {}) {
|
|
244
|
+
const wrapper = new RuvSwarmWrapper(options);
|
|
245
|
+
|
|
246
|
+
try {
|
|
247
|
+
const result = await wrapper.start();
|
|
248
|
+
console.log('✅ RuvSwarm MCP server started successfully');
|
|
249
|
+
return { wrapper, ...result };
|
|
250
|
+
} catch (error) {
|
|
251
|
+
console.error('❌ Failed to start RuvSwarm MCP server:', error.message);
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-flow-novice",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"description": "Standalone Claude Flow for beginners - AI agent orchestration made easy with enhanced TDD testing pipeline. Enhanced init command creates complete agent system, MCP configuration with 30 essential tools, and automated hooks with single-file testing, real-time coverage analysis, and advanced validation. Fully standalone with zero external dependencies, complete project setup in one command.",
|
|
5
5
|
"mcpName": "io.github.ruvnet/claude-flow",
|
|
6
6
|
"main": ".claude-flow-novice/dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"optimize:validate:hardware": "node scripts/optimization/config-validator.js validate hardware",
|
|
40
40
|
"optimize:validate:monitoring": "node scripts/optimization/config-validator.js validate monitoring",
|
|
41
41
|
"build": "scripts/build/unified-builder.sh safe",
|
|
42
|
-
"build:swc": "swc src -d .claude-flow-novice/dist --only='**/*.ts' --config-file .swcrc && cp -r src/slash-commands .claude-flow-novice/dist/src/ && cp -r src/cli/simple-commands/hooks .claude-flow-novice/dist/src/cli/simple-commands/ && cp -r src/cli/simple-commands/init/templates .claude-flow-novice/dist/src/cli/simple-commands/init/ && cp src/cli/simple-commands/init/index.js .claude-flow-novice/dist/src/cli/simple-commands/init/ && cp src/cli/simple-commands/init.js .claude-flow-novice/dist/src/cli/simple-commands/ && cp -r .claude/agents .claude-flow-novice/.claude/",
|
|
42
|
+
"build:swc": "swc src -d .claude-flow-novice/dist --only='**/*.ts' --config-file .swcrc && cp -r src/slash-commands .claude-flow-novice/dist/src/ && cp -r src/cli/simple-commands/hooks .claude-flow-novice/dist/src/cli/simple-commands/ && cp -r src/cli/simple-commands/init/templates .claude-flow-novice/dist/src/cli/simple-commands/init/ && cp src/cli/simple-commands/init/index.js .claude-flow-novice/dist/src/cli/simple-commands/init/ && cp src/cli/simple-commands/init.js .claude-flow-novice/dist/src/cli/simple-commands/ && cp src/cli/simple-commands/mcp.js .claude-flow-novice/dist/src/cli/simple-commands/ && cp src/mcp/*.js .claude-flow-novice/dist/src/mcp/ && cp -r .claude/agents .claude-flow-novice/.claude/",
|
|
43
43
|
"build:types": "tsc --project config/typescript/tsconfig.json --emitDeclarationOnly --outDir .claude-flow-novice/dist --skipLibCheck",
|
|
44
44
|
"build:watch": "swc src -d .claude-flow-novice/dist --watch --config-file .swcrc && cp -r src/slash-commands .claude-flow-novice/dist/src/ && cp -r src/cli/simple-commands/hooks .claude-flow-novice/dist/src/cli/simple-commands/ && cp -r src/cli/simple-commands/init/templates .claude-flow-novice/dist/src/cli/simple-commands/init/ && npm run copy:agents",
|
|
45
45
|
"build:legacy": "scripts/build/unified-builder.sh migration",
|
|
@@ -64,14 +64,8 @@ import {
|
|
|
64
64
|
createHelperScript,
|
|
65
65
|
COMMAND_STRUCTURE,
|
|
66
66
|
} from './templates/enhanced-templates.js';
|
|
67
|
-
import { createOptimizedSparcClaudeMd } from './templates/claude-md.js';
|
|
68
67
|
import { getIsolatedNpxEnv } from '../../../utils/npx-isolated-cache.js';
|
|
69
68
|
import { updateGitignore, needsGitignoreUpdate } from './gitignore-updater.js';
|
|
70
|
-
import {
|
|
71
|
-
createFullClaudeMd,
|
|
72
|
-
createSparcClaudeMd,
|
|
73
|
-
createMinimalClaudeMd,
|
|
74
|
-
} from './templates/claude-md.js';
|
|
75
69
|
import {
|
|
76
70
|
createVerificationClaudeMd,
|
|
77
71
|
createVerificationSettingsJson,
|
|
@@ -271,13 +265,6 @@ export async function initCommand(subArgs, flags) {
|
|
|
271
265
|
return handleBatchInit(subArgs, flags);
|
|
272
266
|
}
|
|
273
267
|
|
|
274
|
-
// For novice package, always use enhanced initialization with agent system
|
|
275
|
-
const useEnhanced = true; // Always enhanced for novice users
|
|
276
|
-
|
|
277
|
-
if (useEnhanced) {
|
|
278
|
-
return enhancedInitCommand(subArgs, flags);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
268
|
// Parse init options
|
|
282
269
|
const initForce = subArgs.includes('--force') || subArgs.includes('-f') || flags.force;
|
|
283
270
|
const initMinimal = subArgs.includes('--minimal') || subArgs.includes('-m') || flags.minimal;
|
|
@@ -1047,11 +1034,8 @@ async function performInitializationWithCheckpoints(
|
|
|
1047
1034
|
// Helper functions for atomic initialization
|
|
1048
1035
|
async function createInitialFiles(options, workingDir, dryRun = false) {
|
|
1049
1036
|
if (!dryRun) {
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
: options.minimal
|
|
1053
|
-
? createMinimalClaudeMd()
|
|
1054
|
-
: createFullClaudeMd();
|
|
1037
|
+
// Use template file instead of generation
|
|
1038
|
+
const claudeMd = await readClaudeMdTemplate();
|
|
1055
1039
|
await fs.writeFile(`${workingDir}/CLAUDE.md`, claudeMd, 'utf8');
|
|
1056
1040
|
|
|
1057
1041
|
const memoryBankMd = options.minimal ? createMinimalMemoryBankMd() : createFullMemoryBankMd();
|
|
@@ -498,98 +498,35 @@ async function createMemoryReadmeFiles(targetDir, options, results) {
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
/**
|
|
501
|
-
* Get template content
|
|
501
|
+
* Get template content from template file only (NO GENERATION)
|
|
502
502
|
*/
|
|
503
503
|
async function getTemplateContent(templatePath) {
|
|
504
504
|
const filename = templatePath.split('/').pop();
|
|
505
505
|
|
|
506
|
-
//
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
const { createFullClaudeMd } = await import('./templates/claude-md.js');
|
|
510
|
-
return createFullClaudeMd();
|
|
511
|
-
},
|
|
512
|
-
'CLAUDE.md.sparc': async () => {
|
|
513
|
-
const { createSparcClaudeMd } = await import('./templates/claude-md.js');
|
|
514
|
-
return createSparcClaudeMd();
|
|
515
|
-
},
|
|
516
|
-
'CLAUDE.md.minimal': async () => {
|
|
517
|
-
const { createMinimalClaudeMd } = await import('./templates/claude-md.js');
|
|
518
|
-
return createMinimalClaudeMd();
|
|
519
|
-
},
|
|
520
|
-
'CLAUDE.md.optimized': async () => {
|
|
521
|
-
const { createOptimizedSparcClaudeMd } = await import('./templates/claude-md.js');
|
|
522
|
-
return createOptimizedSparcClaudeMd();
|
|
523
|
-
},
|
|
524
|
-
'CLAUDE.md.enhanced': async () => {
|
|
525
|
-
const { createEnhancedClaudeMd } = await import('./templates/enhanced-templates.js');
|
|
526
|
-
return createEnhancedClaudeMd();
|
|
527
|
-
},
|
|
528
|
-
'CLAUDE.md.verification': async () => {
|
|
529
|
-
const { createVerificationClaudeMd } = await import('./templates/verification-claude-md.js');
|
|
530
|
-
return createVerificationClaudeMd();
|
|
531
|
-
},
|
|
532
|
-
'memory-bank.md': async () => {
|
|
533
|
-
const { createFullMemoryBankMd } = await import('./templates/memory-bank-md.js');
|
|
534
|
-
return createFullMemoryBankMd();
|
|
535
|
-
},
|
|
536
|
-
'memory-bank.md.minimal': async () => {
|
|
537
|
-
const { createMinimalMemoryBankMd } = await import('./templates/memory-bank-md.js');
|
|
538
|
-
return createMinimalMemoryBankMd();
|
|
539
|
-
},
|
|
540
|
-
'memory-bank.md.optimized': async () => {
|
|
541
|
-
const { createOptimizedMemoryBankMd } = await import('./templates/memory-bank-md.js');
|
|
542
|
-
return createOptimizedMemoryBankMd();
|
|
543
|
-
},
|
|
544
|
-
'coordination.md': async () => {
|
|
545
|
-
const { createFullCoordinationMd } = await import('./templates/coordination-md.js');
|
|
546
|
-
return createFullCoordinationMd();
|
|
547
|
-
},
|
|
548
|
-
'coordination.md.minimal': async () => {
|
|
549
|
-
const { createMinimalCoordinationMd } = await import('./templates/coordination-md.js');
|
|
550
|
-
return createMinimalCoordinationMd();
|
|
551
|
-
},
|
|
552
|
-
'coordination.md.optimized': async () => {
|
|
553
|
-
const { createOptimizedCoordinationMd } = await import('./templates/coordination-md.js');
|
|
554
|
-
return createOptimizedCoordinationMd();
|
|
555
|
-
},
|
|
556
|
-
'settings.json': async () => {
|
|
557
|
-
return await fs.readFile(join(__dirname, 'templates', 'settings.json'), 'utf8');
|
|
558
|
-
},
|
|
559
|
-
'settings.json.enhanced': async () => {
|
|
560
|
-
const { createEnhancedSettingsJson } = await import('./templates/enhanced-templates.js');
|
|
561
|
-
return createEnhancedSettingsJson();
|
|
562
|
-
},
|
|
563
|
-
'settings.json.verification': async () => {
|
|
564
|
-
const { createVerificationSettingsJson } = await import(
|
|
565
|
-
'./templates/verification-claude-md.js'
|
|
566
|
-
);
|
|
567
|
-
return createVerificationSettingsJson();
|
|
568
|
-
},
|
|
569
|
-
'claude-flow-universal': async () => {
|
|
570
|
-
return await fs.readFile(join(__dirname, 'templates', 'claude-flow-universal'), 'utf8');
|
|
571
|
-
},
|
|
572
|
-
'claude-flow.bat': async () => {
|
|
573
|
-
return await fs.readFile(join(__dirname, 'templates', 'claude-flow.bat'), 'utf8');
|
|
574
|
-
},
|
|
575
|
-
'claude-flow.ps1': async () => {
|
|
576
|
-
return await fs.readFile(join(__dirname, 'templates', 'claude-flow.ps1'), 'utf8');
|
|
577
|
-
},
|
|
578
|
-
};
|
|
506
|
+
// Try to read from the actual template file ONLY
|
|
507
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
508
|
+
const __dirname = dirname(__filename);
|
|
579
509
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
510
|
+
// Try multiple possible template locations
|
|
511
|
+
const templatePaths = [
|
|
512
|
+
join(__dirname, 'templates', filename), // Source location: src/cli/simple-commands/init/templates/
|
|
513
|
+
join(__dirname, filename), // Dist location: dist/src/cli/simple-commands/init/ (files copied directly)
|
|
514
|
+
];
|
|
583
515
|
|
|
584
|
-
|
|
516
|
+
for (const actualTemplatePath of templatePaths) {
|
|
585
517
|
try {
|
|
586
|
-
|
|
518
|
+
const content = await fs.readFile(actualTemplatePath, 'utf8');
|
|
519
|
+
console.log(` ✓ Using template from ${actualTemplatePath}`);
|
|
520
|
+
return content;
|
|
587
521
|
} catch (err) {
|
|
588
|
-
|
|
589
|
-
|
|
522
|
+
// Try next path
|
|
523
|
+
continue;
|
|
590
524
|
}
|
|
591
525
|
}
|
|
592
526
|
|
|
527
|
+
// NO FALLBACK TO GENERATION - Template file must exist
|
|
528
|
+
console.log(` ⚠️ Template file not found for ${filename}`);
|
|
529
|
+
console.log(` 💡 Template files must be present in src/cli/simple-commands/init/templates/`);
|
|
593
530
|
return null;
|
|
594
531
|
}
|
|
595
532
|
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* SDK Swarm Integration Demo
|
|
5
|
-
*
|
|
6
|
-
* Demonstrates how to use the SDK Swarm Orchestrator for parallel agent execution
|
|
7
|
-
* with self-validation and Byzantine consensus.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* node examples/sdk-swarm-demo.js
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { SDKSwarmOrchestrator } from '../src/sdk/swarm-integration.js';
|
|
14
|
-
|
|
15
|
-
async function main() {
|
|
16
|
-
console.log('🚀 SDK Swarm Integration Demo\n');
|
|
17
|
-
|
|
18
|
-
// Step 1: Create and initialize orchestrator
|
|
19
|
-
console.log('Step 1: Creating SDK Swarm Orchestrator...');
|
|
20
|
-
const orchestrator = new SDKSwarmOrchestrator({
|
|
21
|
-
swarmId: 'demo-swarm',
|
|
22
|
-
maxAgents: 10,
|
|
23
|
-
maxConcurrent: 3,
|
|
24
|
-
consensusProtocol: 'pbft',
|
|
25
|
-
consensusQuorumSize: 2,
|
|
26
|
-
consensusTimeout: 5000,
|
|
27
|
-
parallelExecution: true,
|
|
28
|
-
filterFailedValidations: true,
|
|
29
|
-
minimumValidAgents: 1,
|
|
30
|
-
enableLearning: true,
|
|
31
|
-
enableMetrics: true
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
await orchestrator.initialize();
|
|
35
|
-
console.log('✅ Orchestrator initialized\n');
|
|
36
|
-
|
|
37
|
-
// Step 2: Define task with agent configuration
|
|
38
|
-
console.log('Step 2: Defining task with multiple agents...');
|
|
39
|
-
const task = {
|
|
40
|
-
description: 'Implement user authentication feature',
|
|
41
|
-
operation: 'implement',
|
|
42
|
-
file: 'src/auth/user-auth.js',
|
|
43
|
-
content: 'User authentication logic',
|
|
44
|
-
agents: [
|
|
45
|
-
{
|
|
46
|
-
agentId: 'coder-1',
|
|
47
|
-
agentType: 'coder',
|
|
48
|
-
confidenceThreshold: 0.75,
|
|
49
|
-
maxRetries: 3,
|
|
50
|
-
minimumCoverage: 80
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
agentId: 'coder-2',
|
|
54
|
-
agentType: 'coder',
|
|
55
|
-
confidenceThreshold: 0.80,
|
|
56
|
-
maxRetries: 3,
|
|
57
|
-
minimumCoverage: 85
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
agentId: 'tester-1',
|
|
61
|
-
agentType: 'tester',
|
|
62
|
-
confidenceThreshold: 0.80,
|
|
63
|
-
maxRetries: 3,
|
|
64
|
-
minimumCoverage: 90
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
agentId: 'reviewer-1',
|
|
68
|
-
agentType: 'reviewer',
|
|
69
|
-
confidenceThreshold: 0.75,
|
|
70
|
-
maxRetries: 2,
|
|
71
|
-
minimumCoverage: 75
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
};
|
|
75
|
-
console.log('✅ Task defined with 4 agents\n');
|
|
76
|
-
|
|
77
|
-
// Step 3: Execute with consensus
|
|
78
|
-
console.log('Step 3: Executing task with parallel agents and consensus...');
|
|
79
|
-
console.log('─'.repeat(80));
|
|
80
|
-
|
|
81
|
-
const result = await orchestrator.executeWithConsensus(task);
|
|
82
|
-
|
|
83
|
-
console.log('─'.repeat(80));
|
|
84
|
-
console.log('\n✅ Execution completed!\n');
|
|
85
|
-
|
|
86
|
-
// Step 4: Display results
|
|
87
|
-
console.log('📊 Execution Results:');
|
|
88
|
-
console.log('═'.repeat(80));
|
|
89
|
-
console.log(`Status: ${result.status}`);
|
|
90
|
-
console.log(`Reason: ${result.reason}`);
|
|
91
|
-
console.log(`Execution ID: ${result.executionId}`);
|
|
92
|
-
console.log(`Timestamp: ${new Date(result.timestamp).toISOString()}`);
|
|
93
|
-
|
|
94
|
-
console.log('\n📈 Statistics:');
|
|
95
|
-
console.log('─'.repeat(80));
|
|
96
|
-
console.log(`Agents Spawned: ${result.stats.agentsSpawned}`);
|
|
97
|
-
console.log(`Validations Passed: ${result.stats.validationPassed}`);
|
|
98
|
-
console.log(`Validations Failed: ${result.stats.validationFailed}`);
|
|
99
|
-
console.log(`Validation Rate: ${result.stats.validationRate}`);
|
|
100
|
-
console.log(`Avg Confidence: ${result.stats.avgConfidence}`);
|
|
101
|
-
console.log(`Avg Attempts: ${result.stats.avgAttempts}`);
|
|
102
|
-
console.log(`Total Duration: ${result.stats.totalDuration}`);
|
|
103
|
-
console.log(`Avg Agent Duration: ${result.stats.avgAgentDuration}`);
|
|
104
|
-
|
|
105
|
-
if (result.stats.consensus) {
|
|
106
|
-
console.log('\n🤝 Consensus Results:');
|
|
107
|
-
console.log('─'.repeat(80));
|
|
108
|
-
console.log(`Decision: ${result.stats.consensus.decision}`);
|
|
109
|
-
console.log(`Consensus Time: ${result.stats.consensus.consensusTime}`);
|
|
110
|
-
console.log(`Participation Rate: ${result.stats.consensus.participationRate}`);
|
|
111
|
-
console.log(`Total Votes: ${result.stats.consensus.votes.total}`);
|
|
112
|
-
console.log(`Approved: ${result.stats.consensus.votes.approved}`);
|
|
113
|
-
console.log(`Rejected: ${result.stats.consensus.votes.rejected}`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
console.log('\n🎯 Quality Metrics:');
|
|
117
|
-
console.log('─'.repeat(80));
|
|
118
|
-
console.log(`Total Coverage: ${result.stats.metrics.totalCoverage}%`);
|
|
119
|
-
console.log(`Tests Passed: ${result.stats.metrics.totalTestsPassed}`);
|
|
120
|
-
console.log(`Tests Failed: ${result.stats.metrics.totalTestsFailed}`);
|
|
121
|
-
|
|
122
|
-
// Step 5: Display individual agent results
|
|
123
|
-
console.log('\n🤖 Individual Agent Results:');
|
|
124
|
-
console.log('═'.repeat(80));
|
|
125
|
-
|
|
126
|
-
result.results.forEach((agentResult, index) => {
|
|
127
|
-
console.log(`\nAgent ${index + 1}: ${agentResult.agentId} (${agentResult.agentType})`);
|
|
128
|
-
console.log('─'.repeat(80));
|
|
129
|
-
console.log(`Status: ${agentResult.isValid() ? '✅ VALID' : '❌ INVALID'}`);
|
|
130
|
-
console.log(`Confidence: ${(agentResult.getConfidence() * 100).toFixed(1)}%`);
|
|
131
|
-
console.log(`Attempts: ${agentResult.attempts}`);
|
|
132
|
-
console.log(`Duration: ${agentResult.duration.toFixed(2)}ms`);
|
|
133
|
-
|
|
134
|
-
if (agentResult.validation?.metrics) {
|
|
135
|
-
console.log(`Coverage: ${agentResult.validation.metrics.coverage}%`);
|
|
136
|
-
console.log(`Tests Passed: ${agentResult.validation.metrics.testsPassed}`);
|
|
137
|
-
console.log(`Tests Failed: ${agentResult.validation.metrics.testsFailed}`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (agentResult.error) {
|
|
141
|
-
console.log(`Error: ${agentResult.error}`);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// Step 6: Get orchestrator metrics
|
|
146
|
-
console.log('\n\n📊 Orchestrator Metrics:');
|
|
147
|
-
console.log('═'.repeat(80));
|
|
148
|
-
|
|
149
|
-
const metrics = orchestrator.getMetrics();
|
|
150
|
-
|
|
151
|
-
console.log('\nSwarm:');
|
|
152
|
-
console.log(` Swarm ID: ${metrics.swarm.swarmId}`);
|
|
153
|
-
console.log(` Agents Registered: ${metrics.swarm.agentsRegistered}`);
|
|
154
|
-
console.log(` Active Executions: ${metrics.swarm.activeExecutions}`);
|
|
155
|
-
console.log(` Parallel Execution: ${metrics.swarm.parallelExecution}`);
|
|
156
|
-
|
|
157
|
-
console.log('\nTasks:');
|
|
158
|
-
console.log(` Total: ${metrics.tasks.total}`);
|
|
159
|
-
console.log(` Successful: ${metrics.tasks.successful}`);
|
|
160
|
-
console.log(` Failed: ${metrics.tasks.failed}`);
|
|
161
|
-
console.log(` Success Rate: ${metrics.tasks.successRate}`);
|
|
162
|
-
|
|
163
|
-
console.log('\nValidation:');
|
|
164
|
-
console.log(` Passed: ${metrics.validation.passed}`);
|
|
165
|
-
console.log(` Failed: ${metrics.validation.failed}`);
|
|
166
|
-
console.log(` Pass Rate: ${metrics.validation.passRate}`);
|
|
167
|
-
console.log(` Avg Duration: ${metrics.validation.avgDuration}`);
|
|
168
|
-
|
|
169
|
-
console.log('\nConsensus:');
|
|
170
|
-
console.log(` Reached: ${metrics.consensus.reached}`);
|
|
171
|
-
console.log(` Failed: ${metrics.consensus.failed}`);
|
|
172
|
-
console.log(` Success Rate: ${metrics.consensus.successRate}`);
|
|
173
|
-
console.log(` Avg Duration: ${metrics.consensus.avgDuration}`);
|
|
174
|
-
console.log(` Protocol: ${metrics.consensus.protocol}`);
|
|
175
|
-
console.log(` Quorum Size: ${metrics.consensus.quorumSize}`);
|
|
176
|
-
|
|
177
|
-
console.log('\nPerformance:');
|
|
178
|
-
console.log(` Avg Task Duration: ${metrics.performance.avgTaskDuration}`);
|
|
179
|
-
console.log(` Tasks Completed: ${metrics.performance.tasksCompleted}`);
|
|
180
|
-
console.log(` Agents Spawned: ${metrics.performance.agentsSpawned}`);
|
|
181
|
-
|
|
182
|
-
// Step 7: Cleanup
|
|
183
|
-
console.log('\n\n🧹 Cleaning up...');
|
|
184
|
-
await orchestrator.shutdown();
|
|
185
|
-
console.log('✅ Orchestrator shut down cleanly');
|
|
186
|
-
|
|
187
|
-
console.log('\n🎉 Demo completed successfully!\n');
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Run demo
|
|
191
|
-
main().catch(error => {
|
|
192
|
-
console.error('\n❌ Demo failed:', error);
|
|
193
|
-
process.exit(1);
|
|
194
|
-
});
|