claude-flow 1.0.21 → 1.0.23
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/README.md +58 -12
- package/bin/claude-flow +14 -1
- package/bin/claude-flow-swarm +19 -0
- package/bin/claude-flow-swarm-monitor +18 -0
- package/bin/claude-flow-swarm-ui +40 -0
- package/package.json +18 -4
- package/src/cli/cli-core.ts +2 -2
- package/src/cli/commands/index.ts +329 -7
- package/src/cli/commands/swarm-spawn.ts +79 -0
- package/src/cli/commands/swarm.ts +431 -0
- package/src/cli/create-enhanced-task.js +181 -0
- package/src/cli/main.ts +1 -1
- package/src/cli/simple-cli.js +195 -5
- package/src/cli/simple-cli.ts +9 -9
- package/src/coordination/swarm-monitor.ts +473 -0
- package/src/mcp/swarm-tools.ts +166 -0
- package/src/utils/helpers.ts +44 -1
|
@@ -7,6 +7,7 @@ import { MemoryManager } from "../../memory/manager.ts";
|
|
|
7
7
|
import { EventBus } from "../../core/event-bus.ts";
|
|
8
8
|
import { Logger } from "../../core/logger.ts";
|
|
9
9
|
import { JsonPersistenceManager } from "../../core/json-persistence.ts";
|
|
10
|
+
import { swarmAction } from "./swarm.ts";
|
|
10
11
|
|
|
11
12
|
let orchestrator: Orchestrator | null = null;
|
|
12
13
|
let configManager: ConfigManager | null = null;
|
|
@@ -705,8 +706,96 @@ export function setupCommands(cli: CLI): void {
|
|
|
705
706
|
tools += ",WebFetchTool";
|
|
706
707
|
}
|
|
707
708
|
|
|
708
|
-
|
|
709
|
-
|
|
709
|
+
const instanceId = `claude-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
710
|
+
|
|
711
|
+
// Build enhanced task with Claude-Flow guidance
|
|
712
|
+
let enhancedTask = `# Claude-Flow Enhanced Task
|
|
713
|
+
|
|
714
|
+
## Your Task
|
|
715
|
+
${task}
|
|
716
|
+
|
|
717
|
+
## Claude-Flow System Context
|
|
718
|
+
|
|
719
|
+
You are running within the Claude-Flow orchestration system, which provides powerful features for complex task management:
|
|
720
|
+
|
|
721
|
+
### Available Features
|
|
722
|
+
|
|
723
|
+
1. **Memory Bank** (Always Available)
|
|
724
|
+
- Store data: \`npx claude-flow memory store <key> <value>\` - Save important data, findings, or progress
|
|
725
|
+
- Retrieve data: \`npx claude-flow memory query <key>\` - Access previously stored information
|
|
726
|
+
- Check status: \`npx claude-flow status\` - View current system/task status
|
|
727
|
+
- List agents: \`npx claude-flow agent list\` - See active agents
|
|
728
|
+
- Memory persists across Claude instances in the same namespace
|
|
729
|
+
|
|
730
|
+
2. **Tool Access**
|
|
731
|
+
- You have access to these tools: ${tools}`;
|
|
732
|
+
|
|
733
|
+
if (ctx.flags.parallel) {
|
|
734
|
+
enhancedTask += `
|
|
735
|
+
- **Parallel Execution Enabled**: Use \`npx claude-flow agent spawn <type> --name <name>\` to spawn sub-agents
|
|
736
|
+
- Create tasks: \`npx claude-flow task create <type> "<description>"\`
|
|
737
|
+
- Assign tasks: \`npx claude-flow task assign <task-id> <agent-id>\`
|
|
738
|
+
- Break down complex tasks and delegate to specialized agents`;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (ctx.flags.research) {
|
|
742
|
+
enhancedTask += `
|
|
743
|
+
- **Research Mode**: Use \`WebFetchTool\` for web research and information gathering`;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
enhancedTask += `
|
|
747
|
+
|
|
748
|
+
### Workflow Guidelines
|
|
749
|
+
|
|
750
|
+
1. **Before Starting**:
|
|
751
|
+
- Check memory: \`npx claude-flow memory query previous_work\`
|
|
752
|
+
- Check system status: \`npx claude-flow status\`
|
|
753
|
+
- List active agents: \`npx claude-flow agent list\`
|
|
754
|
+
- List active tasks: \`npx claude-flow task list\`
|
|
755
|
+
|
|
756
|
+
2. **During Execution**:
|
|
757
|
+
- Store findings: \`npx claude-flow memory store findings "your data here"\`
|
|
758
|
+
- Save checkpoints: \`npx claude-flow memory store progress_${task.replace(/\s+/g, '_')} "current status"\`
|
|
759
|
+
${ctx.flags.parallel ? '- Spawn agents: `npx claude-flow agent spawn researcher --name "research-agent"`' : ''}
|
|
760
|
+
${ctx.flags.parallel ? '- Create tasks: `npx claude-flow task create implementation "implement feature X"`' : ''}
|
|
761
|
+
|
|
762
|
+
3. **Best Practices**:
|
|
763
|
+
- Use the Bash tool to run \`npx claude-flow\` commands
|
|
764
|
+
- Store data as JSON strings for complex structures
|
|
765
|
+
- Query memory before starting to check for existing work
|
|
766
|
+
- Use descriptive keys for memory storage
|
|
767
|
+
${ctx.flags.parallel ? '- Coordinate with other agents through shared memory' : ''}
|
|
768
|
+
${ctx.flags.research ? '- Store research findings: `npx claude-flow memory store research_findings "data"`' : ''}
|
|
769
|
+
|
|
770
|
+
## Configuration
|
|
771
|
+
- Instance ID: ${instanceId}
|
|
772
|
+
- Mode: ${ctx.flags.mode || 'full'}
|
|
773
|
+
- Coverage Target: ${ctx.flags.coverage || 80}%
|
|
774
|
+
- Commit Strategy: ${ctx.flags.commit || 'phase'}
|
|
775
|
+
|
|
776
|
+
## Example Commands
|
|
777
|
+
|
|
778
|
+
To interact with Claude-Flow, use the Bash tool:
|
|
779
|
+
|
|
780
|
+
\`\`\`bash
|
|
781
|
+
# Check for previous work
|
|
782
|
+
Bash("npx claude-flow memory query previous_work")
|
|
783
|
+
|
|
784
|
+
# Store your findings
|
|
785
|
+
Bash("npx claude-flow memory store analysis_results 'Found 3 critical issues...'")
|
|
786
|
+
|
|
787
|
+
# Check system status
|
|
788
|
+
Bash("npx claude-flow status")
|
|
789
|
+
|
|
790
|
+
# Create and assign tasks (when --parallel is enabled)
|
|
791
|
+
Bash("npx claude-flow task create research 'Research authentication methods'")
|
|
792
|
+
Bash("npx claude-flow agent spawn researcher --name auth-researcher")
|
|
793
|
+
\`\`\`
|
|
794
|
+
|
|
795
|
+
Now, please proceed with the task: ${task}`;
|
|
796
|
+
|
|
797
|
+
// Build Claude command with enhanced task
|
|
798
|
+
const claudeCmd = ["claude", enhancedTask];
|
|
710
799
|
claudeCmd.push("--allowedTools", tools);
|
|
711
800
|
|
|
712
801
|
if (ctx.flags.noPermissions || ctx.flags["skip-permissions"]) {
|
|
@@ -721,22 +810,35 @@ export function setupCommands(cli: CLI): void {
|
|
|
721
810
|
claudeCmd.push("--verbose");
|
|
722
811
|
}
|
|
723
812
|
|
|
724
|
-
const instanceId = `claude-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
725
|
-
|
|
726
813
|
if (ctx.flags.dryRun || ctx.flags["dry-run"] || ctx.flags.d) {
|
|
727
814
|
warning("DRY RUN - Would execute:");
|
|
728
|
-
console.log(`Command:
|
|
815
|
+
console.log(`Command: claude "<enhanced task with guidance>" --allowedTools ${tools}`);
|
|
729
816
|
console.log(`Instance ID: ${instanceId}`);
|
|
730
|
-
console.log(`Task: ${task}`);
|
|
817
|
+
console.log(`Original Task: ${task}`);
|
|
731
818
|
console.log(`Tools: ${tools}`);
|
|
732
819
|
console.log(`Mode: ${ctx.flags.mode || "full"}`);
|
|
820
|
+
console.log(`Coverage: ${ctx.flags.coverage || 80}%`);
|
|
821
|
+
console.log(`Commit: ${ctx.flags.commit || "phase"}`);
|
|
822
|
+
console.log(`\nEnhanced Features:`);
|
|
823
|
+
console.log(` - Memory Bank enabled via: npx claude-flow memory commands`);
|
|
824
|
+
console.log(` - Coordination ${ctx.flags.parallel ? 'enabled' : 'disabled'}`);
|
|
825
|
+
console.log(` - Access Claude-Flow features through Bash tool`);
|
|
733
826
|
return;
|
|
734
827
|
}
|
|
735
828
|
|
|
736
829
|
success(`Spawning Claude instance: ${instanceId}`);
|
|
737
|
-
console.log(`📝 Task: ${task}`);
|
|
830
|
+
console.log(`📝 Original Task: ${task}`);
|
|
738
831
|
console.log(`🔧 Tools: ${tools}`);
|
|
739
832
|
console.log(`⚙️ Mode: ${ctx.flags.mode || "full"}`);
|
|
833
|
+
console.log(`📊 Coverage: ${ctx.flags.coverage || 80}%`);
|
|
834
|
+
console.log(`💾 Commit: ${ctx.flags.commit || "phase"}`);
|
|
835
|
+
console.log(`✨ Enhanced with Claude-Flow guidance for memory and coordination`);
|
|
836
|
+
console.log('');
|
|
837
|
+
console.log('📋 Task will be enhanced with:');
|
|
838
|
+
console.log(' - Memory Bank instructions (store/retrieve)');
|
|
839
|
+
console.log(' - Coordination capabilities (swarm management)');
|
|
840
|
+
console.log(' - Best practices for multi-agent workflows');
|
|
841
|
+
console.log('');
|
|
740
842
|
|
|
741
843
|
// Execute Claude command
|
|
742
844
|
const command = new Deno.Command("claude", {
|
|
@@ -747,6 +849,11 @@ export function setupCommands(cli: CLI): void {
|
|
|
747
849
|
CLAUDE_FLOW_MODE: ctx.flags.mode as string || "full",
|
|
748
850
|
CLAUDE_FLOW_COVERAGE: (ctx.flags.coverage || 80).toString(),
|
|
749
851
|
CLAUDE_FLOW_COMMIT: ctx.flags.commit as string || "phase",
|
|
852
|
+
// Add Claude-Flow specific features
|
|
853
|
+
CLAUDE_FLOW_MEMORY_ENABLED: 'true',
|
|
854
|
+
CLAUDE_FLOW_MEMORY_NAMESPACE: 'default',
|
|
855
|
+
CLAUDE_FLOW_COORDINATION_ENABLED: ctx.flags.parallel ? 'true' : 'false',
|
|
856
|
+
CLAUDE_FLOW_FEATURES: 'memory,coordination,swarm',
|
|
750
857
|
},
|
|
751
858
|
stdin: "inherit",
|
|
752
859
|
stdout: "inherit",
|
|
@@ -993,6 +1100,181 @@ export function setupCommands(cli: CLI): void {
|
|
|
993
1100
|
},
|
|
994
1101
|
});
|
|
995
1102
|
|
|
1103
|
+
// Swarm command
|
|
1104
|
+
cli.command({
|
|
1105
|
+
name: "swarm",
|
|
1106
|
+
description: "Create self-orchestrating Claude agent swarms",
|
|
1107
|
+
options: [
|
|
1108
|
+
{
|
|
1109
|
+
name: "strategy",
|
|
1110
|
+
short: "s",
|
|
1111
|
+
description: "Orchestration strategy (auto, research, development, analysis)",
|
|
1112
|
+
type: "string",
|
|
1113
|
+
default: "auto",
|
|
1114
|
+
},
|
|
1115
|
+
{
|
|
1116
|
+
name: "max-agents",
|
|
1117
|
+
description: "Maximum number of agents to spawn",
|
|
1118
|
+
type: "number",
|
|
1119
|
+
default: 5,
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
name: "max-depth",
|
|
1123
|
+
description: "Maximum delegation depth",
|
|
1124
|
+
type: "number",
|
|
1125
|
+
default: 3,
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
name: "research",
|
|
1129
|
+
description: "Enable research capabilities for all agents",
|
|
1130
|
+
type: "boolean",
|
|
1131
|
+
},
|
|
1132
|
+
{
|
|
1133
|
+
name: "parallel",
|
|
1134
|
+
description: "Enable parallel execution",
|
|
1135
|
+
type: "boolean",
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
name: "memory-namespace",
|
|
1139
|
+
description: "Shared memory namespace",
|
|
1140
|
+
type: "string",
|
|
1141
|
+
default: "swarm",
|
|
1142
|
+
},
|
|
1143
|
+
{
|
|
1144
|
+
name: "timeout",
|
|
1145
|
+
description: "Swarm timeout in minutes",
|
|
1146
|
+
type: "number",
|
|
1147
|
+
default: 60,
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
name: "review",
|
|
1151
|
+
description: "Enable peer review between agents",
|
|
1152
|
+
type: "boolean",
|
|
1153
|
+
},
|
|
1154
|
+
{
|
|
1155
|
+
name: "coordinator",
|
|
1156
|
+
description: "Spawn dedicated coordinator agent",
|
|
1157
|
+
type: "boolean",
|
|
1158
|
+
},
|
|
1159
|
+
{
|
|
1160
|
+
name: "config",
|
|
1161
|
+
short: "c",
|
|
1162
|
+
description: "MCP config file",
|
|
1163
|
+
type: "string",
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
name: "verbose",
|
|
1167
|
+
short: "v",
|
|
1168
|
+
description: "Enable verbose output",
|
|
1169
|
+
type: "boolean",
|
|
1170
|
+
},
|
|
1171
|
+
{
|
|
1172
|
+
name: "dry-run",
|
|
1173
|
+
short: "d",
|
|
1174
|
+
description: "Preview swarm configuration",
|
|
1175
|
+
type: "boolean",
|
|
1176
|
+
},
|
|
1177
|
+
{
|
|
1178
|
+
name: "vscode",
|
|
1179
|
+
description: "Use VS Code terminal integration",
|
|
1180
|
+
type: "boolean",
|
|
1181
|
+
},
|
|
1182
|
+
{
|
|
1183
|
+
name: "monitor",
|
|
1184
|
+
description: "Enable real-time monitoring",
|
|
1185
|
+
type: "boolean",
|
|
1186
|
+
},
|
|
1187
|
+
{
|
|
1188
|
+
name: "ui",
|
|
1189
|
+
description: "Use blessed terminal UI (avoids TTY issues)",
|
|
1190
|
+
type: "boolean",
|
|
1191
|
+
},
|
|
1192
|
+
],
|
|
1193
|
+
action: swarmAction,
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
// Swarm UI command (convenience wrapper)
|
|
1197
|
+
cli.command({
|
|
1198
|
+
name: "swarm-ui",
|
|
1199
|
+
description: "Create self-orchestrating Claude agent swarms with blessed UI",
|
|
1200
|
+
options: [
|
|
1201
|
+
{
|
|
1202
|
+
name: "strategy",
|
|
1203
|
+
short: "s",
|
|
1204
|
+
description: "Orchestration strategy (auto, research, development, analysis)",
|
|
1205
|
+
type: "string",
|
|
1206
|
+
default: "auto",
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
name: "max-agents",
|
|
1210
|
+
description: "Maximum number of agents to spawn",
|
|
1211
|
+
type: "number",
|
|
1212
|
+
default: 5,
|
|
1213
|
+
},
|
|
1214
|
+
{
|
|
1215
|
+
name: "max-depth",
|
|
1216
|
+
description: "Maximum delegation depth",
|
|
1217
|
+
type: "number",
|
|
1218
|
+
default: 3,
|
|
1219
|
+
},
|
|
1220
|
+
{
|
|
1221
|
+
name: "research",
|
|
1222
|
+
description: "Enable research capabilities for all agents",
|
|
1223
|
+
type: "boolean",
|
|
1224
|
+
},
|
|
1225
|
+
{
|
|
1226
|
+
name: "parallel",
|
|
1227
|
+
description: "Enable parallel execution",
|
|
1228
|
+
type: "boolean",
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
name: "memory-namespace",
|
|
1232
|
+
description: "Shared memory namespace",
|
|
1233
|
+
type: "string",
|
|
1234
|
+
default: "swarm",
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
name: "timeout",
|
|
1238
|
+
description: "Swarm timeout in minutes",
|
|
1239
|
+
type: "number",
|
|
1240
|
+
default: 60,
|
|
1241
|
+
},
|
|
1242
|
+
{
|
|
1243
|
+
name: "review",
|
|
1244
|
+
description: "Enable peer review between agents",
|
|
1245
|
+
type: "boolean",
|
|
1246
|
+
},
|
|
1247
|
+
{
|
|
1248
|
+
name: "coordinator",
|
|
1249
|
+
description: "Spawn dedicated coordinator agent",
|
|
1250
|
+
type: "boolean",
|
|
1251
|
+
},
|
|
1252
|
+
{
|
|
1253
|
+
name: "config",
|
|
1254
|
+
short: "c",
|
|
1255
|
+
description: "MCP config file",
|
|
1256
|
+
type: "string",
|
|
1257
|
+
},
|
|
1258
|
+
{
|
|
1259
|
+
name: "verbose",
|
|
1260
|
+
short: "v",
|
|
1261
|
+
description: "Enable verbose output",
|
|
1262
|
+
type: "boolean",
|
|
1263
|
+
},
|
|
1264
|
+
{
|
|
1265
|
+
name: "dry-run",
|
|
1266
|
+
short: "d",
|
|
1267
|
+
description: "Preview swarm configuration",
|
|
1268
|
+
type: "boolean",
|
|
1269
|
+
},
|
|
1270
|
+
],
|
|
1271
|
+
action: async (ctx: CommandContext) => {
|
|
1272
|
+
// Force UI mode
|
|
1273
|
+
ctx.flags.ui = true;
|
|
1274
|
+
await swarmAction(ctx);
|
|
1275
|
+
},
|
|
1276
|
+
});
|
|
1277
|
+
|
|
996
1278
|
// Help command
|
|
997
1279
|
cli.command({
|
|
998
1280
|
name: "help",
|
|
@@ -1027,6 +1309,46 @@ export function setupCommands(cli: CLI): void {
|
|
|
1027
1309
|
console.log(` ${blue("claude-flow claude batch")} workflow.json --dry-run`);
|
|
1028
1310
|
console.log();
|
|
1029
1311
|
console.log("For more information, see: https://github.com/ruvnet/claude-code-flow/docs/11-claude-spawning.md");
|
|
1312
|
+
} else if (command === "swarm" || command === "swarm-ui") {
|
|
1313
|
+
console.log(bold(blue("Claude Swarm Mode")));
|
|
1314
|
+
console.log();
|
|
1315
|
+
console.log("Create self-orchestrating Claude agent swarms to tackle complex objectives.");
|
|
1316
|
+
console.log();
|
|
1317
|
+
console.log(bold("Usage:"));
|
|
1318
|
+
console.log(" claude-flow swarm <objective> [options]");
|
|
1319
|
+
console.log(" claude-flow swarm-ui <objective> [options] # Uses blessed UI (avoids TTY issues)");
|
|
1320
|
+
console.log();
|
|
1321
|
+
console.log(bold("Options:"));
|
|
1322
|
+
console.log(" -s, --strategy <s> Orchestration strategy (auto, research, development, analysis)");
|
|
1323
|
+
console.log(" --max-agents <n> Maximum number of agents (default: 5)");
|
|
1324
|
+
console.log(" --max-depth <n> Maximum delegation depth (default: 3)");
|
|
1325
|
+
console.log(" --research Enable research capabilities for all agents");
|
|
1326
|
+
console.log(" --parallel Enable parallel execution");
|
|
1327
|
+
console.log(" --memory-namespace <ns> Shared memory namespace (default: swarm)");
|
|
1328
|
+
console.log(" --timeout <minutes> Swarm timeout in minutes (default: 60)");
|
|
1329
|
+
console.log(" --review Enable peer review between agents");
|
|
1330
|
+
console.log(" --coordinator Spawn dedicated coordinator agent");
|
|
1331
|
+
console.log(" -c, --config <file> MCP config file");
|
|
1332
|
+
console.log(" -v, --verbose Enable verbose output");
|
|
1333
|
+
console.log(" -d, --dry-run Preview swarm configuration");
|
|
1334
|
+
console.log(" --vscode Use VS Code terminal integration");
|
|
1335
|
+
console.log(" --monitor Enable real-time monitoring");
|
|
1336
|
+
console.log(" --ui Use blessed terminal UI (avoids TTY issues)");
|
|
1337
|
+
console.log();
|
|
1338
|
+
console.log(bold("Examples:"));
|
|
1339
|
+
console.log(` ${blue("claude-flow swarm")} "Build a REST API"`);
|
|
1340
|
+
console.log(` ${blue("claude-flow swarm-ui")} "Build a REST API" # Avoids TTY issues`);
|
|
1341
|
+
console.log(` ${blue("claude-flow swarm")} "Research cloud architecture" --strategy research --research`);
|
|
1342
|
+
console.log(` ${blue("claude-flow swarm")} "Migrate app to microservices" --coordinator --review --ui`);
|
|
1343
|
+
console.log();
|
|
1344
|
+
console.log(bold("TTY Issues?"));
|
|
1345
|
+
console.log("If you encounter 'Raw mode is not supported' errors, use:");
|
|
1346
|
+
console.log(` - ${blue("claude-flow swarm-ui")} <objective> # Recommended`);
|
|
1347
|
+
console.log(` - ${blue("claude-flow swarm")} <objective> --ui`);
|
|
1348
|
+
console.log();
|
|
1349
|
+
console.log("For more information, see:");
|
|
1350
|
+
console.log(" - https://github.com/ruvnet/claude-code-flow/docs/12-swarm.md");
|
|
1351
|
+
console.log(" - https://github.com/ruvnet/claude-code-flow/SWARM_TTY_SOLUTION.md");
|
|
1030
1352
|
} else {
|
|
1031
1353
|
// Show general help
|
|
1032
1354
|
cli.showHelp();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swarm spawning utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
interface Agent {
|
|
6
|
+
id: string;
|
|
7
|
+
type: string;
|
|
8
|
+
status: string;
|
|
9
|
+
name: string;
|
|
10
|
+
task: string;
|
|
11
|
+
parentId?: string;
|
|
12
|
+
terminalId?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface SwarmState {
|
|
16
|
+
swarmId: string;
|
|
17
|
+
objective: string;
|
|
18
|
+
agents: Map<string, Agent>;
|
|
19
|
+
startTime: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const swarmStates = new Map<string, SwarmState>();
|
|
23
|
+
|
|
24
|
+
export function initializeSwarm(swarmId: string, objective: string): void {
|
|
25
|
+
swarmStates.set(swarmId, {
|
|
26
|
+
swarmId: swarmId,
|
|
27
|
+
objective,
|
|
28
|
+
agents: new Map<string, Agent>(),
|
|
29
|
+
startTime: Date.now(),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function spawnSwarmAgent(swarmId: string, agentType: string, task: string): Promise<string> {
|
|
34
|
+
const swarm = swarmStates.get(swarmId);
|
|
35
|
+
if (!swarm) {
|
|
36
|
+
throw new Error(`Swarm ${swarmId} not found`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const agentId = `${swarmId}-agent-${Date.now()}`;
|
|
40
|
+
swarm.agents.push({
|
|
41
|
+
id: agentId,
|
|
42
|
+
type: agentType,
|
|
43
|
+
status: 'active',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// In a real implementation, this would spawn actual Claude instances
|
|
47
|
+
console.log(`[SWARM] Spawned ${agentType} agent: ${agentId}`);
|
|
48
|
+
console.log(`[SWARM] Task: ${task}`);
|
|
49
|
+
|
|
50
|
+
return agentId;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function monitorSwarm(swarmId: string): Promise<void> {
|
|
54
|
+
const swarm = swarmStates.get(swarmId);
|
|
55
|
+
if (!swarm) {
|
|
56
|
+
throw new Error(`Swarm ${swarmId} not found`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Simple monitoring loop
|
|
60
|
+
let running = true;
|
|
61
|
+
const interval = setInterval(() => {
|
|
62
|
+
if (!running) {
|
|
63
|
+
clearInterval(interval);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(`[MONITOR] Swarm ${swarmId} - Agents: ${swarm.agents.length}`);
|
|
68
|
+
console.log(`[MONITOR] Active: ${swarm.agents.filter(a => a.status === 'active').length}`);
|
|
69
|
+
}, 5000);
|
|
70
|
+
|
|
71
|
+
// Stop monitoring after timeout
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
running = false;
|
|
74
|
+
}, 60 * 60 * 1000); // 1 hour
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getSwarmState(swarmId: string): SwarmState | undefined {
|
|
78
|
+
return swarmStates.get(swarmId);
|
|
79
|
+
}
|