claude-flow 1.0.9 ā 1.0.11
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/bin/claude-flow +70 -9
- package/package.json +3 -3
- package/scripts/install.js +57 -0
- package/src/cli/cli-core.ts +1 -1
- package/src/cli/commands/index.ts +126 -0
- package/src/cli/main.ts +1 -1
- package/bin/claude-flow-node.js +0 -709
- package/src/cli/commands/swarm.ts +0 -227
package/bin/claude-flow
CHANGED
|
@@ -2,15 +2,76 @@
|
|
|
2
2
|
|
|
3
3
|
const { spawn } = require('child_process');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
5
6
|
|
|
6
|
-
//
|
|
7
|
-
|
|
7
|
+
// Special handling for init command
|
|
8
|
+
if (process.argv[2] === 'init') {
|
|
9
|
+
// Use the Node.js init script that handles Deno installation
|
|
10
|
+
const initScript = path.join(__dirname, '..', 'scripts', 'init.js');
|
|
11
|
+
const child = spawn('node', [initScript, ...process.argv.slice(3)], {
|
|
12
|
+
stdio: 'inherit',
|
|
13
|
+
env: process.env
|
|
14
|
+
});
|
|
15
|
+
child.on('exit', (code) => process.exit(code || 0));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
8
18
|
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
// Check if compiled binary exists
|
|
20
|
+
const binaryPath = __filename + '-binary';
|
|
21
|
+
if (fs.existsSync(binaryPath)) {
|
|
22
|
+
// Use compiled binary
|
|
23
|
+
const child = spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
24
|
+
child.on('exit', (code) => process.exit(code));
|
|
25
|
+
} else {
|
|
26
|
+
// Fallback to Deno execution
|
|
27
|
+
const mainPath = path.join(__dirname, '..', 'src', 'cli', 'main.ts');
|
|
28
|
+
|
|
29
|
+
// Try to find deno in common locations
|
|
30
|
+
let denoPath = 'deno';
|
|
31
|
+
const os = require('os');
|
|
32
|
+
const possiblePaths = [
|
|
33
|
+
path.join(os.homedir(), '.deno', 'bin', 'deno'),
|
|
34
|
+
'/usr/local/bin/deno',
|
|
35
|
+
'/usr/bin/deno',
|
|
36
|
+
'deno' // Try PATH as last resort
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
let denoFound = false;
|
|
40
|
+
for (const p of possiblePaths) {
|
|
41
|
+
try {
|
|
42
|
+
if (p === 'deno' || fs.existsSync(p)) {
|
|
43
|
+
denoPath = p;
|
|
44
|
+
// Test if it works
|
|
45
|
+
const testChild = spawn(p, ['--version'], { stdio: 'pipe' });
|
|
46
|
+
testChild.on('close', (code) => {
|
|
47
|
+
if (code === 0) denoFound = true;
|
|
48
|
+
});
|
|
49
|
+
if (p !== 'deno') {
|
|
50
|
+
denoFound = true;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
// Continue to next path
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const child = spawn(denoPath, ['run', '--allow-all', mainPath, ...process.argv.slice(2)], {
|
|
60
|
+
stdio: 'inherit',
|
|
61
|
+
env: { ...process.env }
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
child.on('error', (err) => {
|
|
65
|
+
if (err.code === 'ENOENT') {
|
|
66
|
+
console.error('Error: Deno is not installed. Please install Deno first:');
|
|
67
|
+
console.error('Visit https://deno.land/ for installation instructions.');
|
|
68
|
+
console.error('Or run: curl -fsSL https://deno.land/x/install/install.sh | sh');
|
|
69
|
+
process.exit(1);
|
|
70
|
+
} else {
|
|
71
|
+
console.error('Error executing claude-flow:', err.message);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
child.on('exit', (code) => process.exit(code || 0));
|
|
16
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-flow",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Advanced AI agent orchestration system for Claude Code",
|
|
5
5
|
"main": "src/cli/main.ts",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"postinstall": "node scripts/install.js",
|
|
11
|
-
"build": "PATH=\"/home/codespace/.deno/bin:$PATH\" deno compile --allow-all --no-check --output=bin/claude-flow src/cli/main.ts",
|
|
11
|
+
"build": "PATH=\"/home/codespace/.deno/bin:$PATH\" deno compile --allow-all --no-check --output=bin/claude-flow-binary src/cli/main.ts",
|
|
12
12
|
"build:simple": "PATH=\"/home/codespace/.deno/bin:$PATH\" deno compile --allow-all --no-check --output=bin/claude-flow-simple src/cli/simple-cli.ts",
|
|
13
13
|
"test": "deno task test"
|
|
14
14
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"node": ">=16.0.0"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
|
-
"bin/",
|
|
38
|
+
"bin/claude-flow",
|
|
39
39
|
"src/",
|
|
40
40
|
"scripts/install.js",
|
|
41
41
|
"README.md",
|
package/scripts/install.js
CHANGED
|
@@ -50,6 +50,55 @@ async function installDeno() {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// Build the binary
|
|
54
|
+
async function buildBinary() {
|
|
55
|
+
console.log('Building Claude-Flow binary...');
|
|
56
|
+
|
|
57
|
+
// Create bin directory if it doesn't exist
|
|
58
|
+
const binDir = path.join(__dirname, '..', 'bin');
|
|
59
|
+
if (!fs.existsSync(binDir)) {
|
|
60
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Try to find deno in common locations
|
|
64
|
+
let denoPath = 'deno';
|
|
65
|
+
const possiblePaths = [
|
|
66
|
+
path.join(os.homedir(), '.deno', 'bin', 'deno'),
|
|
67
|
+
'/usr/local/bin/deno',
|
|
68
|
+
'/usr/bin/deno'
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
for (const p of possiblePaths) {
|
|
72
|
+
if (fs.existsSync(p)) {
|
|
73
|
+
denoPath = p;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const build = spawn(denoPath, [
|
|
80
|
+
'compile',
|
|
81
|
+
'--allow-all',
|
|
82
|
+
'--no-check',
|
|
83
|
+
'--output=' + path.join(binDir, 'claude-flow-binary'),
|
|
84
|
+
path.join(__dirname, '..', 'src', 'cli', 'main.ts')
|
|
85
|
+
], { stdio: 'inherit' });
|
|
86
|
+
|
|
87
|
+
build.on('close', (code) => {
|
|
88
|
+
if (code === 0) {
|
|
89
|
+
console.log('Binary built successfully!');
|
|
90
|
+
resolve();
|
|
91
|
+
} else {
|
|
92
|
+
reject(new Error('Failed to build binary'));
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
build.on('error', (err) => {
|
|
97
|
+
reject(err);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
53
102
|
// Main installation process
|
|
54
103
|
async function main() {
|
|
55
104
|
try {
|
|
@@ -59,6 +108,14 @@ async function main() {
|
|
|
59
108
|
await installDeno();
|
|
60
109
|
}
|
|
61
110
|
|
|
111
|
+
// Try to build the binary
|
|
112
|
+
try {
|
|
113
|
+
await buildBinary();
|
|
114
|
+
} catch (buildError) {
|
|
115
|
+
console.warn('Failed to build binary:', buildError.message);
|
|
116
|
+
console.log('Falling back to runtime execution mode.');
|
|
117
|
+
}
|
|
118
|
+
|
|
62
119
|
console.log('Claude-Flow installation completed!');
|
|
63
120
|
console.log('You can now use: npx claude-flow or claude-flow (if installed globally)');
|
|
64
121
|
|
package/src/cli/cli-core.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { red, green, yellow, blue, bold, cyan } from "https://deno.land/std@0.22
|
|
|
8
8
|
import { ensureDir } from "https://deno.land/std@0.224.0/fs/mod.ts";
|
|
9
9
|
import { join } from "https://deno.land/std@0.224.0/path/mod.ts";
|
|
10
10
|
|
|
11
|
-
export const VERSION = "1.0.
|
|
11
|
+
export const VERSION = "1.0.11";
|
|
12
12
|
|
|
13
13
|
interface CommandContext {
|
|
14
14
|
args: string[];
|
|
@@ -12,6 +12,129 @@ let orchestrator: Orchestrator | null = null;
|
|
|
12
12
|
let configManager: ConfigManager | null = null;
|
|
13
13
|
let persistence: JsonPersistenceManager | null = null;
|
|
14
14
|
|
|
15
|
+
async function checkAndInstallDeno(): Promise<boolean> {
|
|
16
|
+
try {
|
|
17
|
+
// Check if Deno is already available
|
|
18
|
+
const checkCommand = new Deno.Command("deno", {
|
|
19
|
+
args: ["--version"],
|
|
20
|
+
stdout: "null",
|
|
21
|
+
stderr: "null",
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const result = await checkCommand.output();
|
|
26
|
+
if (result.success) {
|
|
27
|
+
info("ā Deno is already installed");
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
// Deno not found, continue to installation
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
warning("Deno not found. Installing Deno automatically...");
|
|
35
|
+
|
|
36
|
+
// Determine OS and install Deno
|
|
37
|
+
const os = Deno.build.os;
|
|
38
|
+
const homeDir = Deno.env.get("HOME") || Deno.env.get("USERPROFILE") || "";
|
|
39
|
+
const denoDir = `${homeDir}/.deno`;
|
|
40
|
+
|
|
41
|
+
if (os === "windows") {
|
|
42
|
+
error("Please install Deno manually on Windows from https://deno.land/");
|
|
43
|
+
console.log("Run: irm https://deno.land/install.ps1 | iex");
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Download and install Deno for Unix-like systems
|
|
48
|
+
info("Downloading Deno installer...");
|
|
49
|
+
|
|
50
|
+
const installScript = await fetch("https://deno.land/x/install/install.sh");
|
|
51
|
+
if (!installScript.ok) {
|
|
52
|
+
throw new Error("Failed to download Deno installer");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const scriptContent = await installScript.text();
|
|
56
|
+
const tempFile = await Deno.makeTempFile({ suffix: ".sh" });
|
|
57
|
+
await Deno.writeTextFile(tempFile, scriptContent);
|
|
58
|
+
|
|
59
|
+
// Make script executable
|
|
60
|
+
await Deno.chmod(tempFile, 0o755);
|
|
61
|
+
|
|
62
|
+
// Run the installer
|
|
63
|
+
const installCommand = new Deno.Command("sh", {
|
|
64
|
+
args: [tempFile],
|
|
65
|
+
env: {
|
|
66
|
+
...Deno.env.toObject(),
|
|
67
|
+
DENO_INSTALL: denoDir,
|
|
68
|
+
},
|
|
69
|
+
stdout: "inherit",
|
|
70
|
+
stderr: "inherit",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const installResult = await installCommand.output();
|
|
74
|
+
|
|
75
|
+
// Clean up temp file
|
|
76
|
+
await Deno.remove(tempFile);
|
|
77
|
+
|
|
78
|
+
if (!installResult.success) {
|
|
79
|
+
throw new Error("Failed to install Deno");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
success("ā Deno installed successfully!");
|
|
83
|
+
|
|
84
|
+
// Export path instructions
|
|
85
|
+
const denoBinPath = `${denoDir}/bin`;
|
|
86
|
+
const shellConfig = os === "darwin" ? "~/.zshrc" : "~/.bashrc";
|
|
87
|
+
|
|
88
|
+
info("\nTo use Deno, add it to your PATH:");
|
|
89
|
+
console.log(` export DENO_INSTALL="${denoDir}"`);
|
|
90
|
+
console.log(` export PATH="$DENO_INSTALL/bin:$PATH"`);
|
|
91
|
+
console.log(`\nAdd these lines to your ${shellConfig} file to make it permanent.`);
|
|
92
|
+
|
|
93
|
+
// Try to add to current session PATH
|
|
94
|
+
const currentPath = Deno.env.get("PATH") || "";
|
|
95
|
+
if (!currentPath.includes(denoBinPath)) {
|
|
96
|
+
Deno.env.set("PATH", `${denoBinPath}:${currentPath}`);
|
|
97
|
+
info(`\nā Temporarily added Deno to PATH for this session`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Create a shell script to help users
|
|
101
|
+
const setupScript = `#!/bin/bash
|
|
102
|
+
# Claude-Flow Deno Setup Script
|
|
103
|
+
# This script sets up Deno in your environment
|
|
104
|
+
|
|
105
|
+
export DENO_INSTALL="${denoDir}"
|
|
106
|
+
export PATH="$DENO_INSTALL/bin:$PATH"
|
|
107
|
+
|
|
108
|
+
# Check if Deno is accessible
|
|
109
|
+
if command -v deno &> /dev/null; then
|
|
110
|
+
echo "ā Deno is now available in your PATH"
|
|
111
|
+
deno --version
|
|
112
|
+
else
|
|
113
|
+
echo "ā Failed to add Deno to PATH"
|
|
114
|
+
echo "Please manually add the following to your ${shellConfig}:"
|
|
115
|
+
echo ' export DENO_INSTALL="${denoDir}"'
|
|
116
|
+
echo ' export PATH="$DENO_INSTALL/bin:$PATH"'
|
|
117
|
+
fi
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
await Deno.writeTextFile("setup-deno.sh", setupScript);
|
|
121
|
+
await Deno.chmod("setup-deno.sh", 0o755);
|
|
122
|
+
|
|
123
|
+
info("\nā Created setup-deno.sh script");
|
|
124
|
+
console.log(" Run: source ./setup-deno.sh");
|
|
125
|
+
console.log(" to set up Deno in your current shell\n");
|
|
126
|
+
|
|
127
|
+
return true;
|
|
128
|
+
|
|
129
|
+
} catch (err) {
|
|
130
|
+
error(`Failed to install Deno: ${(err as Error).message}`);
|
|
131
|
+
console.log("\nPlease install Deno manually:");
|
|
132
|
+
console.log(" curl -fsSL https://deno.land/x/install/install.sh | sh");
|
|
133
|
+
console.log(" or visit: https://deno.land/");
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
15
138
|
async function getPersistence(): Promise<JsonPersistenceManager> {
|
|
16
139
|
if (!persistence) {
|
|
17
140
|
persistence = new JsonPersistenceManager();
|
|
@@ -61,6 +184,9 @@ export function setupCommands(cli: CLI): void {
|
|
|
61
184
|
try {
|
|
62
185
|
success("Initializing Claude Code integration files...");
|
|
63
186
|
|
|
187
|
+
// Check and install Deno first
|
|
188
|
+
const denoInstalled = await checkAndInstallDeno();
|
|
189
|
+
|
|
64
190
|
const force = ctx.flags.force as boolean || ctx.flags.f as boolean;
|
|
65
191
|
const minimal = ctx.flags.minimal as boolean || ctx.flags.m as boolean;
|
|
66
192
|
|
package/src/cli/main.ts
CHANGED
package/bin/claude-flow-node.js
DELETED
|
@@ -1,709 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Pure Node.js CLI for Claude-Flow
|
|
4
|
-
* This version works without Deno dependency
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs').promises;
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const { spawn } = require('child_process');
|
|
10
|
-
const os = require('os');
|
|
11
|
-
|
|
12
|
-
const VERSION = '1.0.0';
|
|
13
|
-
|
|
14
|
-
// ANSI color codes
|
|
15
|
-
const colors = {
|
|
16
|
-
reset: '\x1b[0m',
|
|
17
|
-
bright: '\x1b[1m',
|
|
18
|
-
red: '\x1b[31m',
|
|
19
|
-
green: '\x1b[32m',
|
|
20
|
-
yellow: '\x1b[33m',
|
|
21
|
-
blue: '\x1b[34m',
|
|
22
|
-
cyan: '\x1b[36m',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
function success(msg) {
|
|
26
|
-
console.log(`${colors.green}ā
${msg}${colors.reset}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function error(msg) {
|
|
30
|
-
console.log(`${colors.red}ā ${msg}${colors.reset}`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function warning(msg) {
|
|
34
|
-
console.log(`${colors.yellow}ā ļø ${msg}${colors.reset}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function info(msg) {
|
|
38
|
-
console.log(`${colors.blue}ā¹ļø ${msg}${colors.reset}`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Check if Deno is available
|
|
42
|
-
function checkDeno() {
|
|
43
|
-
return new Promise((resolve) => {
|
|
44
|
-
const deno = spawn('deno', ['--version'], { stdio: 'pipe' });
|
|
45
|
-
deno.on('close', (code) => {
|
|
46
|
-
resolve(code === 0);
|
|
47
|
-
});
|
|
48
|
-
deno.on('error', () => {
|
|
49
|
-
resolve(false);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Install Deno if not available
|
|
55
|
-
async function installDeno() {
|
|
56
|
-
console.log('Deno not found. Installing Deno...');
|
|
57
|
-
|
|
58
|
-
const platform = os.platform();
|
|
59
|
-
|
|
60
|
-
if (platform === 'win32') {
|
|
61
|
-
console.log('Please install Deno manually from https://deno.land/');
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
const installScript = spawn('curl', ['-fsSL', 'https://deno.land/x/install/install.sh'], { stdio: 'pipe' });
|
|
67
|
-
const sh = spawn('sh', [], { stdio: ['pipe', 'inherit', 'inherit'] });
|
|
68
|
-
|
|
69
|
-
installScript.stdout.pipe(sh.stdin);
|
|
70
|
-
|
|
71
|
-
sh.on('close', (code) => {
|
|
72
|
-
if (code === 0) {
|
|
73
|
-
success('Deno installed successfully!');
|
|
74
|
-
console.log('Please restart your terminal or run: export PATH="$HOME/.deno/bin:$PATH"');
|
|
75
|
-
resolve();
|
|
76
|
-
} else {
|
|
77
|
-
reject(new Error('Failed to install Deno'));
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Handle commands that require Deno
|
|
84
|
-
async function handleDenoCommand(command, args) {
|
|
85
|
-
try {
|
|
86
|
-
const denoAvailable = await checkDeno();
|
|
87
|
-
|
|
88
|
-
if (!denoAvailable) {
|
|
89
|
-
const readline = require('readline');
|
|
90
|
-
const rl = readline.createInterface({
|
|
91
|
-
input: process.stdin,
|
|
92
|
-
output: process.stdout
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
warning(`The '${command}' command requires Deno to be installed.`);
|
|
96
|
-
console.log('Would you like to install Deno automatically? (y/n)');
|
|
97
|
-
|
|
98
|
-
const answer = await new Promise((resolve) => {
|
|
99
|
-
rl.question('', (answer) => {
|
|
100
|
-
rl.close();
|
|
101
|
-
resolve(answer.toLowerCase());
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
if (answer === 'y' || answer === 'yes') {
|
|
106
|
-
await installDeno();
|
|
107
|
-
console.log('\nNow you can run the command again after restarting your terminal or running:');
|
|
108
|
-
console.log('export PATH="$HOME/.deno/bin:$PATH"');
|
|
109
|
-
console.log(`\nThen: npx claude-flow ${command} ${args.join(' ')}`);
|
|
110
|
-
} else {
|
|
111
|
-
console.log('Please install Deno manually from https://deno.land/ and run:');
|
|
112
|
-
console.log(` deno run --allow-all src/cli/index.ts ${command} ${args.join(' ')}`);
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
console.log(`Running: deno run --allow-all src/cli/index.ts ${command} ${args.join(' ')}`);
|
|
116
|
-
console.log('Note: Make sure you\'re in the claude-flow project directory');
|
|
117
|
-
}
|
|
118
|
-
} catch (error) {
|
|
119
|
-
error(`Failed to handle Deno command: ${error.message}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function printHelp() {
|
|
124
|
-
console.log(`
|
|
125
|
-
${colors.blue}š§ Claude-Flow v${VERSION}${colors.reset} - Advanced AI Agent Orchestration System
|
|
126
|
-
|
|
127
|
-
USAGE:
|
|
128
|
-
claude-flow [COMMAND] [OPTIONS]
|
|
129
|
-
|
|
130
|
-
COMMANDS:
|
|
131
|
-
${colors.cyan}init${colors.reset} Initialize Claude Code integration files (includes Deno check)
|
|
132
|
-
${colors.cyan}start${colors.reset} Start the orchestration system
|
|
133
|
-
${colors.cyan}agent${colors.reset} Manage agents (spawn, list, terminate, info)
|
|
134
|
-
${colors.cyan}task${colors.reset} Manage tasks (create, list, status, cancel, workflow)
|
|
135
|
-
${colors.cyan}memory${colors.reset} Manage memory (query, export, import, stats, cleanup)
|
|
136
|
-
${colors.cyan}config${colors.reset} Manage configuration (show, get, set, init, validate)
|
|
137
|
-
${colors.cyan}status${colors.reset} Show system status
|
|
138
|
-
${colors.cyan}monitor${colors.reset} Monitor system in real-time
|
|
139
|
-
${colors.cyan}mcp${colors.reset} MCP server management (status, tools, config, logs)
|
|
140
|
-
${colors.cyan}claude${colors.reset} Spawn Claude instances with specific configurations
|
|
141
|
-
${colors.cyan}session${colors.reset} Manage terminal sessions
|
|
142
|
-
${colors.cyan}workflow${colors.reset} Execute workflow files
|
|
143
|
-
${colors.cyan}version${colors.reset} Show version information
|
|
144
|
-
${colors.cyan}help${colors.reset} Show this help message
|
|
145
|
-
|
|
146
|
-
GLOBAL OPTIONS:
|
|
147
|
-
-c, --config <path> Path to configuration file
|
|
148
|
-
-v, --verbose Enable verbose logging
|
|
149
|
-
--log-level <level> Set log level (debug, info, warn, error)
|
|
150
|
-
--help Show help for specific command
|
|
151
|
-
|
|
152
|
-
EXAMPLES:
|
|
153
|
-
claude-flow init # Initialize project (checks/installs Deno)
|
|
154
|
-
claude-flow init --skip-deno # Initialize without Deno check
|
|
155
|
-
claude-flow start # Start orchestrator (auto-installs Deno)
|
|
156
|
-
claude-flow agent spawn researcher --name "Bot" # Spawn research agent
|
|
157
|
-
claude-flow task create research "Analyze data" # Create task
|
|
158
|
-
claude-flow status # Show system status
|
|
159
|
-
|
|
160
|
-
NOTE: Commands requiring Deno will offer automatic installation
|
|
161
|
-
|
|
162
|
-
Documentation: https://github.com/ruvnet/claude-code-flow
|
|
163
|
-
`);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async function executeInit(args) {
|
|
167
|
-
const force = args.includes('-f') || args.includes('--force');
|
|
168
|
-
const minimal = args.includes('-m') || args.includes('--minimal');
|
|
169
|
-
const skipDeno = args.includes('--skip-deno');
|
|
170
|
-
|
|
171
|
-
success('Initializing Claude Code integration files...');
|
|
172
|
-
|
|
173
|
-
// Check and optionally install Deno first
|
|
174
|
-
if (!skipDeno) {
|
|
175
|
-
try {
|
|
176
|
-
const denoAvailable = await checkDeno();
|
|
177
|
-
|
|
178
|
-
if (!denoAvailable) {
|
|
179
|
-
const readline = require('readline');
|
|
180
|
-
const rl = readline.createInterface({
|
|
181
|
-
input: process.stdin,
|
|
182
|
-
output: process.stdout
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
warning('Deno is not installed. Claude-Flow requires Deno for full functionality.');
|
|
186
|
-
console.log('Would you like to install Deno now? (y/n)');
|
|
187
|
-
|
|
188
|
-
const answer = await new Promise((resolve) => {
|
|
189
|
-
rl.question('', (answer) => {
|
|
190
|
-
rl.close();
|
|
191
|
-
resolve(answer.toLowerCase());
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
if (answer === 'y' || answer === 'yes') {
|
|
196
|
-
await installDeno();
|
|
197
|
-
console.log('');
|
|
198
|
-
} else {
|
|
199
|
-
info('You can install Deno later from https://deno.land/');
|
|
200
|
-
console.log('');
|
|
201
|
-
}
|
|
202
|
-
} else {
|
|
203
|
-
success('Deno is already installed ā');
|
|
204
|
-
}
|
|
205
|
-
} catch (error) {
|
|
206
|
-
warning(`Could not check Deno installation: ${error.message}`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
// Check if files already exist
|
|
212
|
-
const files = ['CLAUDE.md', 'memory-bank.md', 'coordination.md'];
|
|
213
|
-
const existingFiles = [];
|
|
214
|
-
|
|
215
|
-
for (const file of files) {
|
|
216
|
-
try {
|
|
217
|
-
await fs.access(file);
|
|
218
|
-
existingFiles.push(file);
|
|
219
|
-
} catch {
|
|
220
|
-
// File doesn't exist, which is fine
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (existingFiles.length > 0 && !force) {
|
|
225
|
-
warning(`The following files already exist: ${existingFiles.join(', ')}`);
|
|
226
|
-
console.log('Use --force to overwrite existing files');
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Create CLAUDE.md
|
|
231
|
-
const claudeMd = minimal ? createMinimalClaudeMd() : createFullClaudeMd();
|
|
232
|
-
await fs.writeFile('CLAUDE.md', claudeMd);
|
|
233
|
-
console.log(' ā Created CLAUDE.md');
|
|
234
|
-
|
|
235
|
-
// Create memory-bank.md
|
|
236
|
-
const memoryBankMd = minimal ? createMinimalMemoryBankMd() : createFullMemoryBankMd();
|
|
237
|
-
await fs.writeFile('memory-bank.md', memoryBankMd);
|
|
238
|
-
console.log(' ā Created memory-bank.md');
|
|
239
|
-
|
|
240
|
-
// Create coordination.md
|
|
241
|
-
const coordinationMd = minimal ? createMinimalCoordinationMd() : createFullCoordinationMd();
|
|
242
|
-
await fs.writeFile('coordination.md', coordinationMd);
|
|
243
|
-
console.log(' ā Created coordination.md');
|
|
244
|
-
|
|
245
|
-
// Create directory structure
|
|
246
|
-
const directories = [
|
|
247
|
-
'memory',
|
|
248
|
-
'memory/agents',
|
|
249
|
-
'memory/sessions',
|
|
250
|
-
'coordination',
|
|
251
|
-
'coordination/memory_bank',
|
|
252
|
-
'coordination/subtasks',
|
|
253
|
-
'coordination/orchestration'
|
|
254
|
-
];
|
|
255
|
-
|
|
256
|
-
for (const dir of directories) {
|
|
257
|
-
try {
|
|
258
|
-
await fs.mkdir(dir, { recursive: true });
|
|
259
|
-
console.log(` ā Created ${dir}/ directory`);
|
|
260
|
-
} catch (err) {
|
|
261
|
-
if (err.code !== 'EEXIST') {
|
|
262
|
-
throw err;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Create placeholder files
|
|
268
|
-
const agentsReadme = createAgentsReadme();
|
|
269
|
-
await fs.writeFile('memory/agents/README.md', agentsReadme);
|
|
270
|
-
console.log(' ā Created memory/agents/README.md');
|
|
271
|
-
|
|
272
|
-
const sessionsReadme = createSessionsReadme();
|
|
273
|
-
await fs.writeFile('memory/sessions/README.md', sessionsReadme);
|
|
274
|
-
console.log(' ā Created memory/sessions/README.md');
|
|
275
|
-
|
|
276
|
-
// Initialize persistence database
|
|
277
|
-
const initialData = {
|
|
278
|
-
agents: [],
|
|
279
|
-
tasks: [],
|
|
280
|
-
lastUpdated: Date.now()
|
|
281
|
-
};
|
|
282
|
-
await fs.writeFile('memory/claude-flow-data.json', JSON.stringify(initialData, null, 2));
|
|
283
|
-
console.log(' ā Created memory/claude-flow-data.json (persistence database)');
|
|
284
|
-
|
|
285
|
-
success('Claude Code integration files initialized successfully!');
|
|
286
|
-
console.log('\nNext steps:');
|
|
287
|
-
console.log('1. Review and customize the generated files for your project');
|
|
288
|
-
console.log('2. Run \'npx claude-flow start\' to begin the orchestration system');
|
|
289
|
-
console.log('3. Use \'claude --dangerously-skip-permissions\' for unattended operation');
|
|
290
|
-
|
|
291
|
-
} catch (err) {
|
|
292
|
-
error(`Failed to initialize files: ${err.message}`);
|
|
293
|
-
process.exit(1);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
async function executeStatus() {
|
|
298
|
-
try {
|
|
299
|
-
// Check if persistence file exists
|
|
300
|
-
let data;
|
|
301
|
-
try {
|
|
302
|
-
const content = await fs.readFile('memory/claude-flow-data.json', 'utf8');
|
|
303
|
-
data = JSON.parse(content);
|
|
304
|
-
} catch {
|
|
305
|
-
data = { agents: [], tasks: [] };
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Check if orchestrator is running (simplified check)
|
|
309
|
-
let isRunning = false;
|
|
310
|
-
try {
|
|
311
|
-
await fs.access('orchestrator.log');
|
|
312
|
-
isRunning = true;
|
|
313
|
-
} catch {
|
|
314
|
-
// Log file doesn't exist, orchestrator not running
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const activeAgents = data.agents.filter(a => a.status === 'active').length;
|
|
318
|
-
const totalAgents = data.agents.length;
|
|
319
|
-
const pendingTasks = data.tasks.filter(t => t.status === 'pending' || t.status === 'assigned').length;
|
|
320
|
-
const totalTasks = data.tasks.length;
|
|
321
|
-
const completedTasks = data.tasks.filter(t => t.status === 'completed').length;
|
|
322
|
-
|
|
323
|
-
success('Claude-Flow System Status:');
|
|
324
|
-
console.log(`š¢ Status: ${isRunning ? 'Running' : 'Stopped'}`);
|
|
325
|
-
console.log(`š¤ Agents: ${activeAgents} active (${totalAgents} total)`);
|
|
326
|
-
console.log(`š Tasks: ${pendingTasks} in queue (${totalTasks} total)`);
|
|
327
|
-
console.log(`ā
Completed: ${completedTasks} tasks`);
|
|
328
|
-
console.log(`š¾ Memory: Ready`);
|
|
329
|
-
console.log(`š„ļø Terminal Pool: Ready`);
|
|
330
|
-
console.log(`š MCP Server: ${isRunning ? 'Running' : 'Stopped'}`);
|
|
331
|
-
|
|
332
|
-
} catch (err) {
|
|
333
|
-
error(`Failed to get status: ${err.message}`);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Template functions
|
|
338
|
-
function createMinimalClaudeMd() {
|
|
339
|
-
return `# Claude Code Configuration
|
|
340
|
-
|
|
341
|
-
## Build Commands
|
|
342
|
-
- \`npm run build\`: Build the project
|
|
343
|
-
- \`npm run test\`: Run tests
|
|
344
|
-
- \`npm run lint\`: Run linter
|
|
345
|
-
|
|
346
|
-
## Code Style
|
|
347
|
-
- Use TypeScript/ES modules
|
|
348
|
-
- Follow project conventions
|
|
349
|
-
- Run typecheck before committing
|
|
350
|
-
|
|
351
|
-
## Project Info
|
|
352
|
-
This is a Claude-Flow AI agent orchestration system.
|
|
353
|
-
`;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function createFullClaudeMd() {
|
|
357
|
-
return `# Claude Code Configuration
|
|
358
|
-
|
|
359
|
-
## Build Commands
|
|
360
|
-
- \`npm run build\`: Build the project using Deno compile
|
|
361
|
-
- \`npm run test\`: Run the full test suite
|
|
362
|
-
- \`npm run lint\`: Run ESLint and format checks
|
|
363
|
-
- \`npm run typecheck\`: Run TypeScript type checking
|
|
364
|
-
- \`npx claude-flow start\`: Start the orchestration system
|
|
365
|
-
- \`npx claude-flow --help\`: Show all available commands
|
|
366
|
-
|
|
367
|
-
## Code Style Preferences
|
|
368
|
-
- Use ES modules (import/export) syntax, not CommonJS (require)
|
|
369
|
-
- Destructure imports when possible (e.g., \`import { foo } from 'bar'\`)
|
|
370
|
-
- Use TypeScript for all new code
|
|
371
|
-
- Follow existing naming conventions (camelCase for variables, PascalCase for classes)
|
|
372
|
-
- Add JSDoc comments for public APIs
|
|
373
|
-
- Use async/await instead of Promise chains
|
|
374
|
-
- Prefer const/let over var
|
|
375
|
-
|
|
376
|
-
## Workflow Guidelines
|
|
377
|
-
- Always run typecheck after making code changes
|
|
378
|
-
- Run tests before committing changes
|
|
379
|
-
- Use meaningful commit messages following conventional commits
|
|
380
|
-
- Create feature branches for new functionality
|
|
381
|
-
- Ensure all tests pass before merging
|
|
382
|
-
|
|
383
|
-
## Project Architecture
|
|
384
|
-
This is a Claude-Flow AI agent orchestration system with the following components:
|
|
385
|
-
- **CLI Interface**: Command-line tools for managing the system
|
|
386
|
-
- **Orchestrator**: Core engine for coordinating agents and tasks
|
|
387
|
-
- **Memory System**: Persistent storage and retrieval of information
|
|
388
|
-
- **Terminal Management**: Automated terminal session handling
|
|
389
|
-
- **MCP Integration**: Model Context Protocol server for Claude integration
|
|
390
|
-
- **Agent Coordination**: Multi-agent task distribution and management
|
|
391
|
-
|
|
392
|
-
## Important Notes
|
|
393
|
-
- Use \`claude --dangerously-skip-permissions\` for unattended operation
|
|
394
|
-
- The system supports both daemon and interactive modes
|
|
395
|
-
- Memory persistence is handled automatically
|
|
396
|
-
- All components are event-driven for scalability
|
|
397
|
-
|
|
398
|
-
## Debugging
|
|
399
|
-
- Check logs in \`./claude-flow.log\`
|
|
400
|
-
- Use \`npx claude-flow status\` to check system health
|
|
401
|
-
- Monitor with \`npx claude-flow monitor\` for real-time updates
|
|
402
|
-
- Verbose output available with \`--verbose\` flag on most commands
|
|
403
|
-
`;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
function createMinimalMemoryBankMd() {
|
|
407
|
-
return `# Memory Bank
|
|
408
|
-
|
|
409
|
-
## Quick Reference
|
|
410
|
-
- Project uses JSON for memory persistence
|
|
411
|
-
- Memory is organized by namespaces
|
|
412
|
-
- Query with \`npx claude-flow memory query <search>\`
|
|
413
|
-
|
|
414
|
-
## Storage Location
|
|
415
|
-
- Database: \`./memory/claude-flow-data.json\`
|
|
416
|
-
- Sessions: \`./memory/sessions/\`
|
|
417
|
-
`;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
function createFullMemoryBankMd() {
|
|
421
|
-
return `# Memory Bank Configuration
|
|
422
|
-
|
|
423
|
-
## Overview
|
|
424
|
-
The Claude-Flow memory system provides persistent storage and intelligent retrieval of information across agent sessions. It uses a hybrid approach combining JSON databases with semantic search capabilities.
|
|
425
|
-
|
|
426
|
-
## Storage Backends
|
|
427
|
-
- **Primary**: JSON database (\`./memory/claude-flow-data.json\`)
|
|
428
|
-
- **Sessions**: File-based storage in \`./memory/sessions/\`
|
|
429
|
-
- **Cache**: In-memory cache for frequently accessed data
|
|
430
|
-
|
|
431
|
-
## Memory Organization
|
|
432
|
-
- **Namespaces**: Logical groupings of related information
|
|
433
|
-
- **Sessions**: Time-bound conversation contexts
|
|
434
|
-
- **Indexing**: Automatic content indexing for fast retrieval
|
|
435
|
-
- **Replication**: Optional distributed storage support
|
|
436
|
-
|
|
437
|
-
## Commands
|
|
438
|
-
- \`npx claude-flow memory query <search>\`: Search stored information
|
|
439
|
-
- \`npx claude-flow memory stats\`: Show memory usage statistics
|
|
440
|
-
- \`npx claude-flow memory export <file>\`: Export memory to file
|
|
441
|
-
- \`npx claude-flow memory import <file>\`: Import memory from file
|
|
442
|
-
|
|
443
|
-
## Configuration
|
|
444
|
-
Memory settings are configured in \`claude-flow.config.json\`:
|
|
445
|
-
\`\`\`json
|
|
446
|
-
{
|
|
447
|
-
"memory": {
|
|
448
|
-
"backend": "json",
|
|
449
|
-
"path": "./memory/claude-flow-data.json",
|
|
450
|
-
"cacheSize": 1000,
|
|
451
|
-
"indexing": true,
|
|
452
|
-
"namespaces": ["default", "agents", "tasks", "sessions"],
|
|
453
|
-
"retentionPolicy": {
|
|
454
|
-
"sessions": "30d",
|
|
455
|
-
"tasks": "90d",
|
|
456
|
-
"agents": "permanent"
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
\`\`\`
|
|
461
|
-
|
|
462
|
-
## Best Practices
|
|
463
|
-
- Use descriptive namespaces for different data types
|
|
464
|
-
- Regular memory exports for backup purposes
|
|
465
|
-
- Monitor memory usage with stats command
|
|
466
|
-
- Clean up old sessions periodically
|
|
467
|
-
|
|
468
|
-
## Memory Types
|
|
469
|
-
- **Episodic**: Conversation and interaction history
|
|
470
|
-
- **Semantic**: Factual knowledge and relationships
|
|
471
|
-
- **Procedural**: Task patterns and workflows
|
|
472
|
-
- **Meta**: System configuration and preferences
|
|
473
|
-
|
|
474
|
-
## Integration Notes
|
|
475
|
-
- Memory is automatically synchronized across agents
|
|
476
|
-
- Search supports both exact match and semantic similarity
|
|
477
|
-
- Memory contents are private to your local instance
|
|
478
|
-
- No data is sent to external services without explicit commands
|
|
479
|
-
`;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
function createMinimalCoordinationMd() {
|
|
483
|
-
return `# Agent Coordination
|
|
484
|
-
|
|
485
|
-
## Quick Commands
|
|
486
|
-
- \`npx claude-flow agent spawn <type>\`: Create new agent
|
|
487
|
-
- \`npx claude-flow agent list\`: Show active agents
|
|
488
|
-
- \`npx claude-flow task create <type> <description>\`: Create task
|
|
489
|
-
|
|
490
|
-
## Agent Types
|
|
491
|
-
- researcher, coder, analyst, coordinator, general
|
|
492
|
-
`;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function createFullCoordinationMd() {
|
|
496
|
-
return `# Agent Coordination System
|
|
497
|
-
|
|
498
|
-
## Overview
|
|
499
|
-
The Claude-Flow coordination system manages multiple AI agents working together on complex tasks. It provides intelligent task distribution, resource management, and inter-agent communication.
|
|
500
|
-
|
|
501
|
-
## Agent Types and Capabilities
|
|
502
|
-
- **Researcher**: Web search, information gathering, knowledge synthesis
|
|
503
|
-
- **Coder**: Code analysis, development, debugging, testing
|
|
504
|
-
- **Analyst**: Data processing, pattern recognition, insights generation
|
|
505
|
-
- **Coordinator**: Task planning, resource allocation, workflow management
|
|
506
|
-
- **General**: Multi-purpose agent with balanced capabilities
|
|
507
|
-
|
|
508
|
-
## Task Management
|
|
509
|
-
- **Priority Levels**: 1 (lowest) to 10 (highest)
|
|
510
|
-
- **Dependencies**: Tasks can depend on completion of other tasks
|
|
511
|
-
- **Parallel Execution**: Independent tasks run concurrently
|
|
512
|
-
- **Load Balancing**: Automatic distribution based on agent capacity
|
|
513
|
-
|
|
514
|
-
## Coordination Commands
|
|
515
|
-
\`\`\`bash
|
|
516
|
-
# Agent Management
|
|
517
|
-
npx claude-flow agent spawn <type> --name <name> --priority <1-10>
|
|
518
|
-
npx claude-flow agent list
|
|
519
|
-
npx claude-flow agent info <agent-id>
|
|
520
|
-
npx claude-flow agent terminate <agent-id>
|
|
521
|
-
|
|
522
|
-
# Task Management
|
|
523
|
-
npx claude-flow task create <type> <description> --priority <1-10> --deps <task-ids>
|
|
524
|
-
npx claude-flow task list --verbose
|
|
525
|
-
npx claude-flow task status <task-id>
|
|
526
|
-
npx claude-flow task cancel <task-id>
|
|
527
|
-
|
|
528
|
-
# System Monitoring
|
|
529
|
-
npx claude-flow status --verbose
|
|
530
|
-
npx claude-flow monitor --interval 5000
|
|
531
|
-
\`\`\`
|
|
532
|
-
|
|
533
|
-
## Workflow Execution
|
|
534
|
-
Workflows are defined in JSON format and can orchestrate complex multi-agent operations:
|
|
535
|
-
\`\`\`bash
|
|
536
|
-
npx claude-flow workflow examples/research-workflow.json
|
|
537
|
-
npx claude-flow workflow examples/development-config.json --async
|
|
538
|
-
\`\`\`
|
|
539
|
-
|
|
540
|
-
## Advanced Features
|
|
541
|
-
- **Circuit Breakers**: Automatic failure handling and recovery
|
|
542
|
-
- **Work Stealing**: Dynamic load redistribution for efficiency
|
|
543
|
-
- **Resource Limits**: Memory and CPU usage constraints
|
|
544
|
-
- **Metrics Collection**: Performance monitoring and optimization
|
|
545
|
-
|
|
546
|
-
## Configuration
|
|
547
|
-
Coordination settings in \`claude-flow.config.json\`:
|
|
548
|
-
\`\`\`json
|
|
549
|
-
{
|
|
550
|
-
"orchestrator": {
|
|
551
|
-
"maxConcurrentTasks": 10,
|
|
552
|
-
"taskTimeout": 300000,
|
|
553
|
-
"defaultPriority": 5
|
|
554
|
-
},
|
|
555
|
-
"agents": {
|
|
556
|
-
"maxAgents": 20,
|
|
557
|
-
"defaultCapabilities": ["research", "code", "terminal"],
|
|
558
|
-
"resourceLimits": {
|
|
559
|
-
"memory": "1GB",
|
|
560
|
-
"cpu": "50%"
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
\`\`\`
|
|
565
|
-
|
|
566
|
-
## Communication Patterns
|
|
567
|
-
- **Direct Messaging**: Agent-to-agent communication
|
|
568
|
-
- **Event Broadcasting**: System-wide notifications
|
|
569
|
-
- **Shared Memory**: Common information access
|
|
570
|
-
- **Task Handoff**: Seamless work transfer between agents
|
|
571
|
-
|
|
572
|
-
## Best Practices
|
|
573
|
-
- Start with general agents and specialize as needed
|
|
574
|
-
- Use descriptive task names and clear requirements
|
|
575
|
-
- Monitor system resources during heavy workloads
|
|
576
|
-
- Implement proper error handling in workflows
|
|
577
|
-
- Regular cleanup of completed tasks and inactive agents
|
|
578
|
-
|
|
579
|
-
## Troubleshooting
|
|
580
|
-
- Check agent health with \`npx claude-flow status\`
|
|
581
|
-
- View detailed logs with \`npx claude-flow monitor\`
|
|
582
|
-
- Restart stuck agents with terminate/spawn cycle
|
|
583
|
-
- Use \`--verbose\` flags for detailed diagnostic information
|
|
584
|
-
`;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function createAgentsReadme() {
|
|
588
|
-
return `# Agent Memory Storage
|
|
589
|
-
|
|
590
|
-
## Purpose
|
|
591
|
-
This directory stores agent-specific memory data, configurations, and persistent state information for individual Claude agents in the orchestration system.
|
|
592
|
-
|
|
593
|
-
## Structure
|
|
594
|
-
Each agent gets its own subdirectory for isolated memory storage:
|
|
595
|
-
|
|
596
|
-
\`\`\`
|
|
597
|
-
memory/agents/
|
|
598
|
-
āāā agent_001/
|
|
599
|
-
ā āāā state.json # Agent state and configuration
|
|
600
|
-
ā āāā knowledge.md # Agent-specific knowledge base
|
|
601
|
-
ā āāā tasks.json # Completed and active tasks
|
|
602
|
-
ā āāā calibration.json # Agent-specific calibrations
|
|
603
|
-
āāā agent_002/
|
|
604
|
-
ā āāā ...
|
|
605
|
-
āāā shared/
|
|
606
|
-
āāā common_knowledge.md # Shared knowledge across agents
|
|
607
|
-
āāā global_config.json # Global agent configurations
|
|
608
|
-
\`\`\`
|
|
609
|
-
|
|
610
|
-
## Usage Guidelines
|
|
611
|
-
1. **Agent Isolation**: Each agent should only read/write to its own directory
|
|
612
|
-
2. **Shared Resources**: Use the \`shared/\` directory for cross-agent information
|
|
613
|
-
3. **State Persistence**: Update state.json whenever agent status changes
|
|
614
|
-
4. **Knowledge Sharing**: Document discoveries in knowledge.md files
|
|
615
|
-
5. **Cleanup**: Remove directories for terminated agents periodically
|
|
616
|
-
|
|
617
|
-
## Last Updated
|
|
618
|
-
${new Date().toISOString()}
|
|
619
|
-
`;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
function createSessionsReadme() {
|
|
623
|
-
return `# Session Memory Storage
|
|
624
|
-
|
|
625
|
-
## Purpose
|
|
626
|
-
This directory stores session-based memory data, conversation history, and contextual information for development sessions using the Claude-Flow orchestration system.
|
|
627
|
-
|
|
628
|
-
## Structure
|
|
629
|
-
Sessions are organized by date and session ID for easy retrieval:
|
|
630
|
-
|
|
631
|
-
\`\`\`
|
|
632
|
-
memory/sessions/
|
|
633
|
-
āāā 2024-01-10/
|
|
634
|
-
ā āāā session_001/
|
|
635
|
-
ā ā āāā metadata.json # Session metadata and configuration
|
|
636
|
-
ā ā āāā conversation.md # Full conversation history
|
|
637
|
-
ā ā āāā decisions.md # Key decisions and rationale
|
|
638
|
-
ā ā āāā artifacts/ # Generated files and outputs
|
|
639
|
-
ā ā āāā coordination_state/ # Coordination system snapshots
|
|
640
|
-
ā āāā ...
|
|
641
|
-
āāā shared/
|
|
642
|
-
āāā patterns.md # Common session patterns
|
|
643
|
-
āāā templates/ # Session template files
|
|
644
|
-
\`\`\`
|
|
645
|
-
|
|
646
|
-
## Usage Guidelines
|
|
647
|
-
1. **Session Isolation**: Each session gets its own directory
|
|
648
|
-
2. **Metadata Completeness**: Always fill out session metadata
|
|
649
|
-
3. **Conversation Logging**: Document all significant interactions
|
|
650
|
-
4. **Artifact Organization**: Structure generated files clearly
|
|
651
|
-
5. **State Preservation**: Snapshot coordination state regularly
|
|
652
|
-
|
|
653
|
-
## Last Updated
|
|
654
|
-
${new Date().toISOString()}
|
|
655
|
-
`;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
// Main CLI handler
|
|
659
|
-
async function main() {
|
|
660
|
-
const args = process.argv.slice(2);
|
|
661
|
-
const command = args[0];
|
|
662
|
-
|
|
663
|
-
if (!command || command === 'help' || command === '--help') {
|
|
664
|
-
printHelp();
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
if (command === 'version' || command === '--version') {
|
|
669
|
-
console.log(`Claude-Flow v${VERSION}`);
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
switch (command) {
|
|
674
|
-
case 'init':
|
|
675
|
-
await executeInit(args.slice(1));
|
|
676
|
-
break;
|
|
677
|
-
|
|
678
|
-
case 'status':
|
|
679
|
-
await executeStatus();
|
|
680
|
-
break;
|
|
681
|
-
|
|
682
|
-
case 'start':
|
|
683
|
-
await handleDenoCommand('start', args.slice(1));
|
|
684
|
-
break;
|
|
685
|
-
|
|
686
|
-
case 'agent':
|
|
687
|
-
case 'task':
|
|
688
|
-
case 'memory':
|
|
689
|
-
case 'config':
|
|
690
|
-
case 'monitor':
|
|
691
|
-
case 'mcp':
|
|
692
|
-
case 'claude':
|
|
693
|
-
case 'session':
|
|
694
|
-
case 'workflow':
|
|
695
|
-
await handleDenoCommand(command, args.slice(1));
|
|
696
|
-
break;
|
|
697
|
-
|
|
698
|
-
default:
|
|
699
|
-
error(`Unknown command: ${command}`);
|
|
700
|
-
console.log('Run \'claude-flow help\' for usage information.');
|
|
701
|
-
process.exit(1);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
// Run the CLI
|
|
706
|
-
main().catch(err => {
|
|
707
|
-
error(`Fatal error: ${err.message}`);
|
|
708
|
-
process.exit(1);
|
|
709
|
-
});
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Swarm Mode - Self-orchestrating agent swarms
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Command } from '@cliffy/command';
|
|
6
|
-
import { colors } from '@cliffy/ansi/colors';
|
|
7
|
-
import { generateId } from '../../utils/helpers.ts';
|
|
8
|
-
|
|
9
|
-
export const swarmCommand = new Command()
|
|
10
|
-
.description('Create self-orchestrating Claude agent swarms')
|
|
11
|
-
.arguments('<objective:string>')
|
|
12
|
-
.option('-s, --strategy <strategy:string>', 'Orchestration strategy (auto, research, development, analysis)', {
|
|
13
|
-
default: 'auto'
|
|
14
|
-
})
|
|
15
|
-
.option('--max-agents <count:number>', 'Maximum number of agents to spawn', { default: 5 })
|
|
16
|
-
.option('--max-depth <depth:number>', 'Maximum delegation depth', { default: 3 })
|
|
17
|
-
.option('--research', 'Enable research capabilities for all agents')
|
|
18
|
-
.option('--parallel', 'Enable parallel execution')
|
|
19
|
-
.option('--memory-namespace <ns:string>', 'Shared memory namespace', { default: 'swarm' })
|
|
20
|
-
.option('--timeout <minutes:number>', 'Swarm timeout in minutes', { default: 60 })
|
|
21
|
-
.option('--review', 'Enable peer review between agents')
|
|
22
|
-
.option('--coordinator', 'Spawn dedicated coordinator agent')
|
|
23
|
-
.option('-c, --config <file:string>', 'MCP config file')
|
|
24
|
-
.option('-v, --verbose', 'Enable verbose output')
|
|
25
|
-
.option('-d, --dry-run', 'Preview swarm configuration')
|
|
26
|
-
.action(async (objective: string, options: any) => {
|
|
27
|
-
const swarmId = generateId('swarm');
|
|
28
|
-
|
|
29
|
-
if (options.dryRun) {
|
|
30
|
-
console.log(colors.yellow('DRY RUN - Swarm Configuration:'));
|
|
31
|
-
console.log(`Swarm ID: ${swarmId}`);
|
|
32
|
-
console.log(`Objective: ${objective}`);
|
|
33
|
-
console.log(`Strategy: ${options.strategy}`);
|
|
34
|
-
console.log(`Max Agents: ${options.maxAgents}`);
|
|
35
|
-
console.log(`Max Depth: ${options.maxDepth}`);
|
|
36
|
-
console.log(`Research: ${options.research}`);
|
|
37
|
-
console.log(`Parallel: ${options.parallel}`);
|
|
38
|
-
console.log(`Review Mode: ${options.review}`);
|
|
39
|
-
console.log(`Coordinator: ${options.coordinator}`);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
console.log(colors.green(`š Initializing Claude Swarm: ${swarmId}`));
|
|
44
|
-
console.log(colors.cyan(`š Objective: ${objective}`));
|
|
45
|
-
|
|
46
|
-
// Build the orchestration prompt
|
|
47
|
-
const orchestrationPrompt = buildOrchestrationPrompt(objective, options);
|
|
48
|
-
|
|
49
|
-
// Spawn the master orchestrator
|
|
50
|
-
console.log(colors.blue('šÆ Spawning Master Orchestrator...'));
|
|
51
|
-
|
|
52
|
-
const orchestratorTask = {
|
|
53
|
-
id: `${swarmId}-orchestrator`,
|
|
54
|
-
description: orchestrationPrompt,
|
|
55
|
-
tools: buildOrchestratorTools(options),
|
|
56
|
-
config: options.config,
|
|
57
|
-
environment: {
|
|
58
|
-
CLAUDE_SWARM_ID: swarmId,
|
|
59
|
-
CLAUDE_SWARM_MODE: 'orchestrator',
|
|
60
|
-
CLAUDE_SWARM_OBJECTIVE: objective,
|
|
61
|
-
CLAUDE_SWARM_STRATEGY: options.strategy,
|
|
62
|
-
CLAUDE_SWARM_MAX_AGENTS: options.maxAgents.toString(),
|
|
63
|
-
CLAUDE_SWARM_MAX_DEPTH: options.maxDepth.toString(),
|
|
64
|
-
CLAUDE_SWARM_MEMORY_NS: options.memoryNamespace,
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
if (options.verbose) {
|
|
69
|
-
console.log(colors.gray('Orchestrator configuration:'));
|
|
70
|
-
console.log(JSON.stringify(orchestratorTask, null, 2));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Spawn the master orchestrator using Deno.Command
|
|
74
|
-
try {
|
|
75
|
-
// Build Claude command arguments
|
|
76
|
-
const claudeArgs = [orchestrationPrompt];
|
|
77
|
-
claudeArgs.push('--allowedTools', orchestratorTask.tools);
|
|
78
|
-
|
|
79
|
-
if (orchestratorTask.config) {
|
|
80
|
-
claudeArgs.push('--mcp-config', orchestratorTask.config);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (options.verbose) {
|
|
84
|
-
claudeArgs.push('--verbose');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Show progress
|
|
88
|
-
console.log(colors.gray('Launching orchestrator with Claude...'));
|
|
89
|
-
|
|
90
|
-
// Create the command
|
|
91
|
-
const command = new Deno.Command('claude', {
|
|
92
|
-
args: claudeArgs,
|
|
93
|
-
stdin: 'piped',
|
|
94
|
-
stdout: 'inherit',
|
|
95
|
-
stderr: 'inherit',
|
|
96
|
-
env: {
|
|
97
|
-
...Deno.env.toObject(),
|
|
98
|
-
...orchestratorTask.environment,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Spawn the process
|
|
103
|
-
const process = command.spawn();
|
|
104
|
-
|
|
105
|
-
console.log(colors.green('ā
Master Orchestrator spawned successfully'));
|
|
106
|
-
console.log(colors.blue('š Swarm is now active and self-orchestrating...'));
|
|
107
|
-
|
|
108
|
-
// Wait for the orchestrator to complete
|
|
109
|
-
const status = await process.status;
|
|
110
|
-
|
|
111
|
-
if (status.success) {
|
|
112
|
-
console.log(colors.green(`\nā
Swarm ${swarmId} completed successfully`));
|
|
113
|
-
} else {
|
|
114
|
-
console.log(colors.red(`\nā Swarm ${swarmId} exited with code ${status.code}`));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
} catch (error) {
|
|
118
|
-
console.error(colors.red('ā Failed to spawn orchestrator:'), (error as Error).message);
|
|
119
|
-
console.error(colors.yellow('Make sure Claude CLI is installed and available in your PATH'));
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
function buildOrchestrationPrompt(objective: string, options: any): string {
|
|
124
|
-
const strategies = {
|
|
125
|
-
auto: 'Automatically determine the best approach',
|
|
126
|
-
research: 'Focus on research and information gathering',
|
|
127
|
-
development: 'Focus on implementation and coding',
|
|
128
|
-
analysis: 'Focus on analysis and insights'
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
return `
|
|
132
|
-
# Claude Swarm Orchestration Task
|
|
133
|
-
|
|
134
|
-
You are the Master Orchestrator for a Claude agent swarm. Your objective is to coordinate multiple specialized agents to achieve the following goal:
|
|
135
|
-
|
|
136
|
-
**OBJECTIVE**: ${objective}
|
|
137
|
-
|
|
138
|
-
## Orchestration Parameters:
|
|
139
|
-
- Strategy: ${strategies[options.strategy as keyof typeof strategies] || strategies.auto}
|
|
140
|
-
- Maximum Agents: ${options.maxAgents}
|
|
141
|
-
- Maximum Delegation Depth: ${options.maxDepth}
|
|
142
|
-
- Parallel Execution: ${options.parallel ? 'Enabled' : 'Disabled'}
|
|
143
|
-
- Peer Review: ${options.review ? 'Enabled' : 'Disabled'}
|
|
144
|
-
- Research Capabilities: ${options.research ? 'Enabled' : 'Disabled'}
|
|
145
|
-
|
|
146
|
-
## Your Responsibilities:
|
|
147
|
-
|
|
148
|
-
1. **Task Decomposition**: Break down the objective into subtasks
|
|
149
|
-
2. **Agent Spawning**: Create specialized agents for each subtask
|
|
150
|
-
3. **Resource Allocation**: Assign appropriate tools and permissions
|
|
151
|
-
4. **Coordination**: Manage dependencies and communication
|
|
152
|
-
5. **Quality Control**: ${options.review ? 'Implement peer review processes' : 'Monitor task quality'}
|
|
153
|
-
6. **Progress Tracking**: Monitor and report on swarm progress
|
|
154
|
-
|
|
155
|
-
## Available Agent Types:
|
|
156
|
-
- **Researcher**: Information gathering, web research, analysis
|
|
157
|
-
- **Developer**: Code implementation, testing, debugging
|
|
158
|
-
- **Analyst**: Data analysis, pattern recognition, insights
|
|
159
|
-
- **Reviewer**: Code review, quality assurance, validation
|
|
160
|
-
- **Coordinator**: Sub-task coordination, dependency management
|
|
161
|
-
|
|
162
|
-
## Swarm Execution Process:
|
|
163
|
-
|
|
164
|
-
1. Analyze the objective and create a detailed execution plan
|
|
165
|
-
2. Identify required agent types and their responsibilities
|
|
166
|
-
3. Spawn agents with appropriate configurations using:
|
|
167
|
-
\`\`\`
|
|
168
|
-
claude-flow agent spawn <type> --name "<name>" --task "<specific task>"
|
|
169
|
-
\`\`\`
|
|
170
|
-
4. Create tasks and assign them to agents:
|
|
171
|
-
\`\`\`
|
|
172
|
-
claude-flow task create <type> "<description>" --assign-to <agent-id>
|
|
173
|
-
\`\`\`
|
|
174
|
-
5. Monitor progress and adjust as needed
|
|
175
|
-
6. ${options.review ? 'Implement peer review cycles between agents' : 'Validate outputs'}
|
|
176
|
-
7. Synthesize results and report completion
|
|
177
|
-
|
|
178
|
-
## Memory Coordination:
|
|
179
|
-
All agents share the memory namespace: "${options.memoryNamespace}"
|
|
180
|
-
Use this for:
|
|
181
|
-
- Sharing discoveries and insights
|
|
182
|
-
- Avoiding duplicate work
|
|
183
|
-
- Building on each other's findings
|
|
184
|
-
- Maintaining context across the swarm
|
|
185
|
-
|
|
186
|
-
## Special Instructions:
|
|
187
|
-
${options.coordinator ? '- Spawn a dedicated coordinator agent for complex subtasks' : ''}
|
|
188
|
-
${options.research ? '- All agents should have research capabilities enabled' : ''}
|
|
189
|
-
${options.parallel ? '- Maximize parallel execution where dependencies allow' : ''}
|
|
190
|
-
${options.maxDepth > 1 ? `- Agents can delegate to sub-agents up to depth ${options.maxDepth}` : ''}
|
|
191
|
-
|
|
192
|
-
## Output Format:
|
|
193
|
-
Provide regular status updates in this format:
|
|
194
|
-
\`\`\`
|
|
195
|
-
[SWARM STATUS]
|
|
196
|
-
- Active Agents: X/Y
|
|
197
|
-
- Tasks Completed: X/Y
|
|
198
|
-
- Current Phase: <phase>
|
|
199
|
-
- Next Actions: <list>
|
|
200
|
-
\`\`\`
|
|
201
|
-
|
|
202
|
-
Begin by analyzing the objective and presenting your execution plan.
|
|
203
|
-
`;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function buildOrchestratorTools(options: any): string {
|
|
207
|
-
const tools = [
|
|
208
|
-
'View',
|
|
209
|
-
'Edit',
|
|
210
|
-
'Replace',
|
|
211
|
-
'GlobTool',
|
|
212
|
-
'GrepTool',
|
|
213
|
-
'LS',
|
|
214
|
-
'Bash',
|
|
215
|
-
'dispatch_agent'
|
|
216
|
-
];
|
|
217
|
-
|
|
218
|
-
if (options.research) {
|
|
219
|
-
tools.push('WebFetchTool');
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (options.parallel) {
|
|
223
|
-
tools.push('BatchTool');
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return tools.join(',');
|
|
227
|
-
}
|