claude_swarm 0.1.17 → 0.1.19
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -0
- data/CLAUDE.md +48 -0
- data/README.md +143 -2
- data/claude-swarm.yml +54 -16
- data/examples/with-before-commands.yml +30 -0
- data/lib/claude_swarm/cli.rb +131 -3
- data/lib/claude_swarm/commands/ps.rb +53 -1
- data/lib/claude_swarm/configuration.rb +14 -1
- data/lib/claude_swarm/orchestrator.rb +165 -2
- data/lib/claude_swarm/version.rb +1 -1
- data/lib/claude_swarm/worktree_manager.rb +353 -0
- data/llms.txt +2 -2
- data/single.yml +92 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecbec0c31b9252f826e28978e871cdc0003644d691a541906a8c36ae60c717f6
|
4
|
+
data.tar.gz: 9d88ab7118d614108adcd2995b270f3c223e08a0a7ccd8768136f362f9f002d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66783c2bc619846d7ce78b33e290d34b414946a5e66714f0528ef312a1e641cc9c6950e30d492e1f428374da391f39e11556bffaa68ced4b4cda726987ea4a8c
|
7
|
+
data.tar.gz: f04e7f694fb8f151c5ccfa4bd145a2184cb7674b78a1c3af414704664b6efadd5887d9f78e3ad8da4d7f41a25bdfb8e23d355eb79c4bb7675aebb79424995a59
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,53 @@
|
|
1
|
+
## [0.1.19]
|
2
|
+
|
3
|
+
### Added
|
4
|
+
- **Interactive configuration generator**: New `claude-swarm generate` command launches Claude to help create swarm configurations
|
5
|
+
- Runs Claude in interactive mode with an initial prompt to guide configuration creation
|
6
|
+
- Customizable output file with `-o/--output` option
|
7
|
+
- When no output file is specified, Claude names the file based on the swarm's function (e.g., web-dev-swarm.yml, data-pipeline-swarm.yml)
|
8
|
+
- Model selection with `-m/--model` option (default: sonnet)
|
9
|
+
- Checks for Claude CLI installation and provides helpful error message if not found
|
10
|
+
- Includes comprehensive initial prompt with Claude Swarm overview, best practices, and common patterns
|
11
|
+
- Full README content is included in the prompt within `<full_readme>` tags for complete context
|
12
|
+
- Examples:
|
13
|
+
- `claude-swarm generate` - Claude names file based on swarm function
|
14
|
+
- `claude-swarm generate -o my-team.yml --model opus` - Custom file and model
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- **ps command path display**: The `claude-swarm ps` command now shows expanded absolute paths instead of raw YAML values
|
18
|
+
- Relative paths like `.` are expanded to their full absolute paths (e.g., `/Users/paulo/project`)
|
19
|
+
- Multiple directories are properly expanded and displayed as comma-separated values
|
20
|
+
- Worktree directories are correctly shown when sessions use worktrees (e.g., `/path/to/repo/.worktrees/feature-branch`)
|
21
|
+
- Path resolution uses the start_directory from session metadata for accurate expansion
|
22
|
+
|
23
|
+
## [0.1.18]
|
24
|
+
|
25
|
+
### Added
|
26
|
+
- **Before commands**: Execute setup commands before launching the swarm
|
27
|
+
- New `before` field in swarm configuration accepts an array of commands
|
28
|
+
- Commands are executed in sequence before any Claude instances are launched
|
29
|
+
- All commands must succeed (exit code 0) for the swarm to launch
|
30
|
+
- Commands are only executed on initial launch, not when restoring sessions
|
31
|
+
- Output is logged to the session log file
|
32
|
+
- Useful for installing dependencies, starting services, or running setup scripts
|
33
|
+
- Example: `before: ["npm install", "docker-compose up -d"]`
|
34
|
+
|
35
|
+
- **Git worktree support**: Run instances in isolated Git worktrees
|
36
|
+
- New `--worktree [NAME]` CLI option creates worktrees for all instances
|
37
|
+
- Worktrees are created inside each repository at `.worktrees/NAME`
|
38
|
+
- Each worktree gets its own branch (not detached HEAD) for proper Git operations
|
39
|
+
- Auto-generated names use session ID: `worktree-SESSION_ID`
|
40
|
+
- Per-instance worktree configuration in YAML:
|
41
|
+
- `worktree: true` - Use shared worktree name
|
42
|
+
- `worktree: false` - Disable worktree for this instance
|
43
|
+
- `worktree: "branch-name"` - Use custom worktree name
|
44
|
+
- Session restoration automatically restores worktrees
|
45
|
+
- Cleanup preserves worktrees with uncommitted changes or unpushed commits
|
46
|
+
- Warnings displayed when worktrees are preserved: "⚠️ Warning: Worktree has uncommitted changes"
|
47
|
+
- Multiple directories per instance work seamlessly with worktrees
|
48
|
+
- `.gitignore` automatically created in `.worktrees/` directory
|
49
|
+
- Example: `claude-swarm --worktree feature-branch`
|
50
|
+
|
1
51
|
## [0.1.17]
|
2
52
|
|
3
53
|
### Added
|
data/CLAUDE.md
CHANGED
@@ -39,6 +39,47 @@ bundle exec rake release # Release gem to RubyGems.org
|
|
39
39
|
rake # Runs both tests and RuboCop
|
40
40
|
```
|
41
41
|
|
42
|
+
## Git Worktree Support
|
43
|
+
|
44
|
+
Claude Swarm supports launching instances in Git worktrees to isolate changes:
|
45
|
+
|
46
|
+
### CLI Usage
|
47
|
+
```bash
|
48
|
+
# Create worktrees with custom name
|
49
|
+
claude-swarm --worktree feature-branch
|
50
|
+
|
51
|
+
# Create worktrees with auto-generated name (worktree-SESSION_ID)
|
52
|
+
claude-swarm --worktree
|
53
|
+
|
54
|
+
# Short form
|
55
|
+
claude-swarm -w feature-x
|
56
|
+
```
|
57
|
+
|
58
|
+
### Per-Instance Configuration
|
59
|
+
Instances can have individual worktree settings that override CLI behavior:
|
60
|
+
|
61
|
+
```yaml
|
62
|
+
instances:
|
63
|
+
main:
|
64
|
+
worktree: true # Use shared worktree name (from CLI or auto-generated)
|
65
|
+
testing:
|
66
|
+
worktree: false # Don't use worktree for this instance
|
67
|
+
feature:
|
68
|
+
worktree: "feature-x" # Use specific worktree name
|
69
|
+
default:
|
70
|
+
# No worktree field - follows CLI behavior
|
71
|
+
```
|
72
|
+
|
73
|
+
### Worktree Behavior
|
74
|
+
- Worktrees are created inside each repository in a `.worktrees/` directory
|
75
|
+
- A `.gitignore` file is automatically created inside `.worktrees/` to ignore all contents
|
76
|
+
- Each unique Git repository gets its own worktree with the same name
|
77
|
+
- All instance directories are mapped to their worktree equivalents
|
78
|
+
- Worktrees are automatically cleaned up when the swarm exits
|
79
|
+
- Session metadata tracks worktree information for restoration
|
80
|
+
- Non-Git directories are used as-is without creating worktrees
|
81
|
+
- Existing worktrees with the same name are reused
|
82
|
+
|
42
83
|
## Architecture
|
43
84
|
|
44
85
|
The gem is fully implemented with the following components:
|
@@ -49,6 +90,7 @@ The gem is fully implemented with the following components:
|
|
49
90
|
- **ClaudeSwarm::Configuration** (`lib/claude_swarm/configuration.rb`): YAML parser and validator for swarm configurations
|
50
91
|
- **ClaudeSwarm::McpGenerator** (`lib/claude_swarm/mcp_generator.rb`): Generates MCP JSON configurations for each instance
|
51
92
|
- **ClaudeSwarm::Orchestrator** (`lib/claude_swarm/orchestrator.rb`): Launches the main Claude instance with proper configuration
|
93
|
+
- **ClaudeSwarm::WorktreeManager** (`lib/claude_swarm/worktree_manager.rb`): Manages Git worktrees for isolated development
|
52
94
|
|
53
95
|
### Key Features
|
54
96
|
|
@@ -58,6 +100,7 @@ The gem is fully implemented with the following components:
|
|
58
100
|
4. **Multiple MCP Types**: Supports both stdio and SSE MCP server types
|
59
101
|
5. **Automatic MCP Generation**: Creates `.claude-swarm/` directory with MCP configs
|
60
102
|
6. **Custom System Prompts**: Each instance can have a custom prompt via `--append-system-prompt`
|
103
|
+
7. **Git Worktree Support**: Run instances in isolated Git worktrees with per-instance configuration
|
61
104
|
|
62
105
|
### How It Works
|
63
106
|
|
@@ -77,16 +120,20 @@ swarm:
|
|
77
120
|
main: lead
|
78
121
|
instances:
|
79
122
|
lead:
|
123
|
+
description: "Lead developer coordinating the team"
|
80
124
|
directory: .
|
81
125
|
model: opus
|
82
126
|
connections: [frontend, backend]
|
83
127
|
prompt: "You are the lead developer coordinating the team"
|
84
128
|
tools: [Read, Edit, Bash]
|
129
|
+
worktree: true # Optional: use worktree for this instance
|
85
130
|
frontend:
|
131
|
+
description: "Frontend developer specializing in React"
|
86
132
|
directory: ./frontend
|
87
133
|
model: sonnet
|
88
134
|
prompt: "You specialize in frontend development with React"
|
89
135
|
tools: [Edit, Write, Bash]
|
136
|
+
worktree: false # Optional: disable worktree for this instance
|
90
137
|
```
|
91
138
|
|
92
139
|
## Testing
|
@@ -98,6 +145,7 @@ The gem includes comprehensive tests covering:
|
|
98
145
|
- CLI command functionality
|
99
146
|
- Session restoration
|
100
147
|
- Vibe mode behavior
|
148
|
+
- Worktree management and per-instance configuration
|
101
149
|
|
102
150
|
## Dependencies
|
103
151
|
|
data/README.md
CHANGED
@@ -1,10 +1,30 @@
|
|
1
1
|
# Claude Swarm
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/claude_swarm)
|
4
4
|
[](https://github.com/parruda/claude-swarm/actions/workflows/ci.yml)
|
5
5
|
|
6
6
|
Claude Swarm orchestrates multiple Claude Code instances as a collaborative AI development team. It enables running AI agents with specialized roles, tools, and directory contexts, communicating via MCP (Model Context Protocol) in a tree-like hierarchy. Define your swarm topology in simple YAML and let Claude instances delegate tasks through connected instances. Perfect for complex projects requiring specialized AI agents for frontend, backend, testing, DevOps, or research tasks.
|
7
7
|
|
8
|
+
## Table of Contents
|
9
|
+
|
10
|
+
- [Installation](#installation)
|
11
|
+
- [Prerequisites](#prerequisites)
|
12
|
+
- [Usage](#usage)
|
13
|
+
- [Quick Start](#quick-start)
|
14
|
+
- [Configuration Format](#configuration-format)
|
15
|
+
- [MCP Server Types](#mcp-server-types)
|
16
|
+
- [Tools](#tools)
|
17
|
+
- [Examples](#examples)
|
18
|
+
- [Command Line Options](#command-line-options)
|
19
|
+
- [Session Monitoring](#session-monitoring)
|
20
|
+
- [Session Management and Restoration](#session-management-and-restoration-experimental)
|
21
|
+
- [How It Works](#how-it-works)
|
22
|
+
- [Troubleshooting](#troubleshooting)
|
23
|
+
- [Architecture](#architecture)
|
24
|
+
- [Development](#development)
|
25
|
+
- [Contributing](#contributing)
|
26
|
+
- [License](#license)
|
27
|
+
|
8
28
|
## Installation
|
9
29
|
|
10
30
|
Install the gem by executing:
|
@@ -35,7 +55,7 @@ bundle install
|
|
35
55
|
|
36
56
|
### Quick Start
|
37
57
|
|
38
|
-
1. Run `claude-swarm init` or create a `claude-swarm.yml` file in your project:
|
58
|
+
1. Run `claude-swarm init` to create a basic template, or use `claude-swarm generate` for an interactive configuration experience with Claude's help. You can also manually create a `claude-swarm.yml` file in your project:
|
39
59
|
|
40
60
|
```yaml
|
41
61
|
version: 1
|
@@ -191,6 +211,10 @@ version: 1 # Required, currently only version 1 is supported
|
|
191
211
|
swarm:
|
192
212
|
name: "Swarm Name" # Display name for your swarm
|
193
213
|
main: instance_key # Which instance to launch as the main interface
|
214
|
+
before: # Optional: commands to run before launching the swarm
|
215
|
+
- "echo 'Setting up environment...'"
|
216
|
+
- "npm install"
|
217
|
+
- "docker-compose up -d"
|
194
218
|
instances:
|
195
219
|
# Instance definitions...
|
196
220
|
```
|
@@ -211,6 +235,7 @@ Each instance can have:
|
|
211
235
|
- **mcps**: Array of additional MCP servers to connect
|
212
236
|
- **prompt**: Custom system prompt to append to the instance
|
213
237
|
- **vibe**: Enable vibe mode (--dangerously-skip-permissions) for this instance (default: false)
|
238
|
+
- **worktree**: Configure Git worktree usage for this instance (true/false/string)
|
214
239
|
|
215
240
|
```yaml
|
216
241
|
instance_name:
|
@@ -428,6 +453,42 @@ When using multiple directories:
|
|
428
453
|
- Additional directories are accessible via the `--add-dir` flag in Claude
|
429
454
|
- All directories must exist or the configuration will fail validation
|
430
455
|
|
456
|
+
#### Before Commands
|
457
|
+
|
458
|
+
You can specify commands to run before launching the swarm using the `before` field:
|
459
|
+
|
460
|
+
```yaml
|
461
|
+
version: 1
|
462
|
+
swarm:
|
463
|
+
name: "Development Environment"
|
464
|
+
main: lead_developer
|
465
|
+
before:
|
466
|
+
- "echo '🚀 Setting up development environment...'"
|
467
|
+
- "npm install"
|
468
|
+
- "docker-compose up -d"
|
469
|
+
- "bundle install"
|
470
|
+
instances:
|
471
|
+
lead_developer:
|
472
|
+
description: "Lead developer coordinating the team"
|
473
|
+
directory: .
|
474
|
+
model: opus
|
475
|
+
allowed_tools: [Read, Edit, Write, Bash]
|
476
|
+
```
|
477
|
+
|
478
|
+
The `before` commands:
|
479
|
+
- Are executed in sequence before launching any Claude instances
|
480
|
+
- Must all succeed for the swarm to launch (exit code 0)
|
481
|
+
- Are only executed on initial swarm launch, not when restoring sessions
|
482
|
+
- Have their output logged to the session log file
|
483
|
+
- Will abort the swarm launch if any command fails
|
484
|
+
|
485
|
+
This is useful for:
|
486
|
+
- Installing dependencies
|
487
|
+
- Starting required services (databases, Docker containers, etc.)
|
488
|
+
- Setting up the development environment
|
489
|
+
- Running any prerequisite setup scripts
|
490
|
+
|
491
|
+
|
431
492
|
#### Mixed Permission Modes
|
432
493
|
|
433
494
|
You can have different permission modes for different instances:
|
@@ -459,6 +520,72 @@ swarm:
|
|
459
520
|
allowed_tools: [] # Tools list ignored when vibe: true
|
460
521
|
```
|
461
522
|
|
523
|
+
#### Git Worktrees
|
524
|
+
|
525
|
+
Claude Swarm supports running instances in Git worktrees, allowing isolated work without affecting your main repository state. Worktrees are created inside each repository in a `.worktrees/` directory following Git best practices.
|
526
|
+
|
527
|
+
**Example Structure:**
|
528
|
+
```
|
529
|
+
my-repo/
|
530
|
+
├── .git/
|
531
|
+
├── .worktrees/ (created by Claude Swarm)
|
532
|
+
│ ├── .gitignore (auto-created, contains "*")
|
533
|
+
│ └── feature-x/ (worktree for feature-x branch)
|
534
|
+
├── src/
|
535
|
+
└── tests/
|
536
|
+
```
|
537
|
+
|
538
|
+
**CLI Option:**
|
539
|
+
```bash
|
540
|
+
# Create worktrees with auto-generated name (worktree-SESSION_ID)
|
541
|
+
claude-swarm --worktree
|
542
|
+
|
543
|
+
# Create worktrees with custom name
|
544
|
+
claude-swarm --worktree feature-branch
|
545
|
+
|
546
|
+
# Short form
|
547
|
+
claude-swarm -w
|
548
|
+
```
|
549
|
+
|
550
|
+
**Per-Instance Configuration:**
|
551
|
+
```yaml
|
552
|
+
version: 1
|
553
|
+
swarm:
|
554
|
+
name: "Worktree Example"
|
555
|
+
main: lead
|
556
|
+
instances:
|
557
|
+
lead:
|
558
|
+
description: "Lead developer"
|
559
|
+
directory: .
|
560
|
+
worktree: true # Use shared worktree name from CLI (or auto-generate)
|
561
|
+
|
562
|
+
testing:
|
563
|
+
description: "Test developer"
|
564
|
+
directory: ./tests
|
565
|
+
worktree: false # Don't use worktree for this instance
|
566
|
+
|
567
|
+
feature_dev:
|
568
|
+
description: "Feature developer"
|
569
|
+
directory: ./features
|
570
|
+
worktree: "feature-x" # Use specific worktree name
|
571
|
+
```
|
572
|
+
|
573
|
+
**Worktree Behavior:**
|
574
|
+
- `worktree: true` - Uses the shared worktree name (from CLI or auto-generated)
|
575
|
+
- `worktree: false` - Disables worktree for this instance
|
576
|
+
- `worktree: "name"` - Uses a specific worktree name
|
577
|
+
- Omitted - Follows CLI behavior (use worktree if `--worktree` is specified)
|
578
|
+
|
579
|
+
**Notes:**
|
580
|
+
- Worktrees are created inside each repository in a `.worktrees/` directory
|
581
|
+
- Auto-generated worktree names use the session ID (e.g., `worktree-20241206_143022`)
|
582
|
+
- This makes it easy to correlate worktrees with their Claude Swarm sessions
|
583
|
+
- A `.gitignore` file is automatically created inside `.worktrees/` to ignore all worktree contents
|
584
|
+
- All worktrees are automatically cleaned up when the swarm exits
|
585
|
+
- Worktrees with the same name across different repositories share that name
|
586
|
+
- Non-Git directories are unaffected by worktree settings
|
587
|
+
- Existing worktrees with the same name are reused
|
588
|
+
|
462
589
|
### Command Line Options
|
463
590
|
|
464
591
|
```bash
|
@@ -480,6 +607,20 @@ claude-swarm --prompt "Fix the bug in the payment module"
|
|
480
607
|
claude-swarm --session-id 20241206_143022
|
481
608
|
claude-swarm --session-id ~/path/to/session
|
482
609
|
|
610
|
+
# Run all instances in Git worktrees
|
611
|
+
claude-swarm --worktree # Auto-generated name (worktree-SESSION_ID)
|
612
|
+
claude-swarm --worktree feature-branch # Custom worktree name
|
613
|
+
claude-swarm -w # Short form
|
614
|
+
|
615
|
+
# Initialize a new configuration file
|
616
|
+
claude-swarm init
|
617
|
+
claude-swarm init --force # Overwrite existing file
|
618
|
+
|
619
|
+
# Generate configuration interactively with Claude's help
|
620
|
+
claude-swarm generate # Claude names file based on swarm function
|
621
|
+
claude-swarm generate -o my-swarm.yml # Custom output file
|
622
|
+
claude-swarm generate --model opus # Use a specific model
|
623
|
+
|
483
624
|
# Show version
|
484
625
|
claude-swarm version
|
485
626
|
|
data/claude-swarm.yml
CHANGED
@@ -1,26 +1,64 @@
|
|
1
1
|
version: 1
|
2
2
|
swarm:
|
3
|
-
name: "
|
4
|
-
main:
|
3
|
+
name: "Codex CLI Integration Team"
|
4
|
+
main: claude_swarm_developer
|
5
5
|
instances:
|
6
|
-
|
7
|
-
description: "
|
8
|
-
directory:
|
9
|
-
- .
|
10
|
-
- /Users/paulo/src/github.com/shopify-playground/claudeception
|
6
|
+
claude_swarm_developer:
|
7
|
+
description: "Claude Swarm developer implementing Codex CLI integration to enable OpenAI model support"
|
8
|
+
directory: .
|
11
9
|
model: opus
|
12
|
-
prompt: "You are an expert in Claude swarm architecture"
|
13
10
|
vibe: true
|
14
|
-
connections: [
|
11
|
+
connections: [codex_cli_expert]
|
12
|
+
prompt: |
|
13
|
+
You are an expert Claude Swarm developer responsible for integrating Codex CLI functionality into Claude Swarm to enable the use of OpenAI models alongside Claude models.
|
15
14
|
|
16
|
-
|
15
|
+
Your primary objectives:
|
16
|
+
1. Work closely with the codex_cli_expert to understand how Codex CLI works
|
17
|
+
2. Design and implement the integration of Codex CLI into Claude Swarm
|
18
|
+
3. Ensure seamless interoperability between Claude and OpenAI models in swarm configurations
|
19
|
+
4. Extend the YAML configuration format to support OpenAI model specifications
|
20
|
+
5. Implement the necessary Ruby code to launch and manage Codex CLI instances
|
21
|
+
6. Ensure proper session management and MCP communication for Codex instances
|
22
|
+
7. Update documentation and examples to showcase the new capabilities
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
-
|
22
|
-
-
|
24
|
+
When working on this integration:
|
25
|
+
- First, consult with the codex_cli_expert to understand Codex CLI's architecture, API, and usage patterns
|
26
|
+
- Identify the key integration points and design patterns needed
|
27
|
+
- Implement the changes incrementally, testing as you go
|
28
|
+
- Consider backward compatibility with existing Claude Swarm configurations
|
29
|
+
- Think about how users will specify OpenAI models in their swarm configurations
|
30
|
+
|
31
|
+
For maximum efficiency, whenever you need to perform multiple independent operations, invoke all relevant tools simultaneously rather than sequentially.
|
32
|
+
|
33
|
+
Start by asking the codex_cli_expert for a comprehensive overview of how Codex CLI works, its command-line interface, configuration format, and any relevant APIs or extension points.
|
34
|
+
|
35
|
+
codex_cli_expert:
|
36
|
+
description: "Codex CLI expert providing detailed information about Codex CLI architecture and integration points"
|
37
|
+
directory: /Users/paulo/src/github.com/openai/codex
|
23
38
|
model: opus
|
24
|
-
prompt: "You are an expert in Claudeception architecture"
|
25
39
|
vibe: true
|
40
|
+
prompt: |
|
41
|
+
You are an expert on the Codex CLI codebase with deep knowledge of its architecture, implementation, and usage patterns. Your role is to help understand how Codex CLI works so they can integrate it into Claude Swarm.
|
42
|
+
|
43
|
+
Your responsibilities:
|
44
|
+
1. Analyze and explain the Codex CLI codebase structure and architecture
|
45
|
+
2. Document the command-line interface, flags, and configuration options
|
46
|
+
3. Identify key APIs, interfaces, and extension points that could be used for integration
|
47
|
+
4. Explain how Codex CLI manages sessions, contexts, and model interactions
|
48
|
+
5. Provide code examples and usage patterns
|
49
|
+
6. Suggest integration strategies based on your understanding of both systems
|
50
|
+
7. Answer any technical questions about Codex CLI implementation details
|
51
|
+
|
52
|
+
When analyzing the codebase:
|
53
|
+
- Start with a high-level overview of the project structure
|
54
|
+
- Examine the main entry points and command processing logic
|
55
|
+
- Look for configuration file formats and parsing logic
|
56
|
+
- Understand how Codex CLI communicates with OpenAI models
|
57
|
+
- Identify any MCP or similar protocol support
|
58
|
+
- Look for session management and state persistence features
|
59
|
+
- Look for logging output, log streams, log to a file, JSON logs, verbose mode, etc.
|
60
|
+
- Check for any existing integration or extension mechanisms
|
61
|
+
|
62
|
+
For maximum efficiency, whenever you need to perform multiple independent operations, invoke all relevant tools simultaneously rather than sequentially.
|
26
63
|
|
64
|
+
Be proactive in providing comprehensive information. Don't wait to be asked for every detail - anticipate what the claude_swarm_developer will need to know for a successful integration.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
version: 1
|
2
|
+
swarm:
|
3
|
+
name: "Development Environment"
|
4
|
+
main: lead_developer
|
5
|
+
before:
|
6
|
+
- "echo '🚀 Setting up development environment...'"
|
7
|
+
- "echo '📦 Installing dependencies...'"
|
8
|
+
- "echo '🐳 Starting Docker containers...'"
|
9
|
+
instances:
|
10
|
+
lead_developer:
|
11
|
+
description: "Lead developer who coordinates the team"
|
12
|
+
directory: .
|
13
|
+
model: sonnet
|
14
|
+
prompt: "You are the lead developer coordinating the team"
|
15
|
+
allowed_tools: [Read, Edit, Bash, Write]
|
16
|
+
connections: [frontend_dev, backend_dev]
|
17
|
+
|
18
|
+
frontend_dev:
|
19
|
+
description: "Frontend developer specializing in React"
|
20
|
+
directory: ./frontend
|
21
|
+
model: sonnet
|
22
|
+
prompt: "You specialize in frontend development with React"
|
23
|
+
allowed_tools: [Read, Edit, Write]
|
24
|
+
|
25
|
+
backend_dev:
|
26
|
+
description: "Backend developer focusing on APIs"
|
27
|
+
directory: ./backend
|
28
|
+
model: sonnet
|
29
|
+
prompt: "You specialize in backend development and APIs"
|
30
|
+
allowed_tools: [Read, Edit, Write, Bash]
|
data/lib/claude_swarm/cli.rb
CHANGED
@@ -26,6 +26,9 @@ module ClaudeSwarm
|
|
26
26
|
desc: "Enable debug output"
|
27
27
|
method_option :session_id, type: :string,
|
28
28
|
desc: "Resume a previous session by ID or path"
|
29
|
+
method_option :worktree, type: :string, aliases: "-w",
|
30
|
+
desc: "Create instances in Git worktrees with the given name (auto-generated if true)",
|
31
|
+
banner: "[NAME]"
|
29
32
|
def start(config_file = nil)
|
30
33
|
# Handle session restoration
|
31
34
|
if options[:session_id]
|
@@ -54,7 +57,8 @@ module ClaudeSwarm
|
|
54
57
|
vibe: options[:vibe],
|
55
58
|
prompt: options[:prompt],
|
56
59
|
stream_logs: options[:stream_logs],
|
57
|
-
debug: options[:debug]
|
60
|
+
debug: options[:debug],
|
61
|
+
worktree: options[:worktree])
|
58
62
|
orchestrator.start
|
59
63
|
rescue Error => e
|
60
64
|
error e.message
|
@@ -147,6 +151,10 @@ module ClaudeSwarm
|
|
147
151
|
swarm:
|
148
152
|
name: "Swarm Name"
|
149
153
|
main: lead_developer
|
154
|
+
# before: # Optional: commands to run before launching swarm (executed in sequence)
|
155
|
+
# - "echo 'Setting up environment...'"
|
156
|
+
# - "npm install"
|
157
|
+
# - "docker-compose up -d"
|
150
158
|
instances:
|
151
159
|
lead_developer:
|
152
160
|
description: "Lead developer who coordinates the team and makes architectural decisions"
|
@@ -192,6 +200,37 @@ module ClaudeSwarm
|
|
192
200
|
say "Edit this file to configure your swarm, then run 'claude-swarm' to start"
|
193
201
|
end
|
194
202
|
|
203
|
+
desc "generate", "Launch Claude to help generate a swarm configuration interactively"
|
204
|
+
method_option :output, aliases: "-o", type: :string,
|
205
|
+
desc: "Output file path for the generated configuration"
|
206
|
+
method_option :model, aliases: "-m", type: :string, default: "sonnet",
|
207
|
+
desc: "Claude model to use for generation"
|
208
|
+
def generate
|
209
|
+
# Check if claude command exists
|
210
|
+
unless system("which claude > /dev/null 2>&1")
|
211
|
+
error "Claude CLI is not installed or not in PATH"
|
212
|
+
say "To install Claude CLI, visit: https://docs.anthropic.com/en/docs/claude-code"
|
213
|
+
exit 1
|
214
|
+
end
|
215
|
+
|
216
|
+
# Read README for context about claude-swarm capabilities
|
217
|
+
readme_path = File.join(__dir__, "../../README.md")
|
218
|
+
readme_content = File.exist?(readme_path) ? File.read(readme_path) : ""
|
219
|
+
|
220
|
+
# Build the pre-prompt
|
221
|
+
preprompt = build_generation_prompt(readme_content, options[:output])
|
222
|
+
|
223
|
+
# Launch Claude in interactive mode with the initial prompt
|
224
|
+
cmd = [
|
225
|
+
"claude",
|
226
|
+
"--model", options[:model],
|
227
|
+
preprompt
|
228
|
+
]
|
229
|
+
|
230
|
+
# Execute and let the user take over
|
231
|
+
exec(*cmd)
|
232
|
+
end
|
233
|
+
|
195
234
|
desc "version", "Show Claude Swarm version"
|
196
235
|
def version
|
197
236
|
say "Claude Swarm #{VERSION}"
|
@@ -241,7 +280,7 @@ module ClaudeSwarm
|
|
241
280
|
end
|
242
281
|
end
|
243
282
|
|
244
|
-
say "Cleaned #{cleaned} stale session#{cleaned == 1
|
283
|
+
say "Cleaned #{cleaned} stale session#{"s" unless cleaned == 1}", :green
|
245
284
|
end
|
246
285
|
|
247
286
|
desc "watch SESSION_ID", "Watch session logs"
|
@@ -395,6 +434,17 @@ module ClaudeSwarm
|
|
395
434
|
|
396
435
|
config = Configuration.new(config_file, base_dir: Dir.pwd)
|
397
436
|
|
437
|
+
# Load session metadata if it exists to check for worktree info
|
438
|
+
session_metadata_file = File.join(session_path, "session_metadata.json")
|
439
|
+
worktree_name = nil
|
440
|
+
if File.exist?(session_metadata_file)
|
441
|
+
metadata = JSON.parse(File.read(session_metadata_file))
|
442
|
+
if metadata["worktree"] && metadata["worktree"]["enabled"]
|
443
|
+
worktree_name = metadata["worktree"]["name"]
|
444
|
+
say "Restoring with worktree: #{worktree_name}", :green unless options[:prompt]
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
398
448
|
# Create orchestrator with restoration mode
|
399
449
|
generator = McpGenerator.new(config, vibe: options[:vibe], restore_session_path: session_path)
|
400
450
|
orchestrator = Orchestrator.new(config, generator,
|
@@ -402,7 +452,8 @@ module ClaudeSwarm
|
|
402
452
|
prompt: options[:prompt],
|
403
453
|
stream_logs: options[:stream_logs],
|
404
454
|
debug: options[:debug],
|
405
|
-
restore_session_path: session_path
|
455
|
+
restore_session_path: session_path,
|
456
|
+
worktree: worktree_name)
|
406
457
|
orchestrator.start
|
407
458
|
rescue StandardError => e
|
408
459
|
error "Failed to restore session: #{e.message}"
|
@@ -425,5 +476,82 @@ module ClaudeSwarm
|
|
425
476
|
|
426
477
|
nil
|
427
478
|
end
|
479
|
+
|
480
|
+
def build_generation_prompt(readme_content, output_file)
|
481
|
+
<<~PROMPT
|
482
|
+
You are a Claude Swarm configuration generator assistant. Your role is to help the user create a well-structured claude-swarm.yml file through an interactive conversation.
|
483
|
+
|
484
|
+
## Claude Swarm Overview
|
485
|
+
Claude Swarm is a Ruby gem that orchestrates multiple Claude Code instances as a collaborative AI development team. It enables running AI agents with specialized roles, tools, and directory contexts, communicating via MCP (Model Context Protocol).
|
486
|
+
|
487
|
+
Key capabilities:
|
488
|
+
- Define multiple AI instances with different roles and specializations
|
489
|
+
- Set up connections between instances for collaboration
|
490
|
+
- Restrict tools based on each instance's responsibilities
|
491
|
+
- Run instances in different directories or Git worktrees
|
492
|
+
- Support for custom system prompts per instance
|
493
|
+
- Choose appropriate models (opus for complex tasks, sonnet for simpler ones)
|
494
|
+
|
495
|
+
## Your Task
|
496
|
+
1. Start by asking about the user's project structure and development needs
|
497
|
+
2. Understand what kind of team they need (roles, specializations)
|
498
|
+
3. Suggest an appropriate swarm topology based on their needs
|
499
|
+
4. Help them refine and customize the configuration
|
500
|
+
5. Generate the final claude-swarm.yml content
|
501
|
+
6. When the configuration is complete, save it to: #{output_file || "a descriptive filename based on the swarm's function"}
|
502
|
+
|
503
|
+
## File Naming Convention
|
504
|
+
#{output_file ? "The user has specified the output file: #{output_file}" : "Since no output file was specified, name the file based on the swarm's function. Examples:\n - web-dev-swarm.yml for full-stack web development teams\n - data-pipeline-swarm.yml for data processing teams\n - microservices-swarm.yml for microservice architectures\n - mobile-app-swarm.yml for mobile development teams\n - ml-research-swarm.yml for machine learning teams\n - devops-swarm.yml for infrastructure and deployment teams\n Use descriptive names that clearly indicate the swarm's purpose."}
|
505
|
+
|
506
|
+
## Configuration Structure
|
507
|
+
```yaml
|
508
|
+
version: 1
|
509
|
+
swarm:
|
510
|
+
name: "Descriptive Swarm Name"
|
511
|
+
main: main_instance_name
|
512
|
+
instances:
|
513
|
+
instance_name:
|
514
|
+
description: "Clear description of role and responsibilities"
|
515
|
+
directory: ./path/to/directory
|
516
|
+
model: sonnet # or opus for complex tasks
|
517
|
+
prompt: "Custom system prompt for specialization"
|
518
|
+
allowed_tools: [Read, Edit, Write, Bash]
|
519
|
+
connections: [other_instance_names] # Optional
|
520
|
+
```
|
521
|
+
|
522
|
+
## Best Practices to Follow
|
523
|
+
- Use descriptive, role-based instance names (e.g., frontend_dev, api_architect)
|
524
|
+
- Write clear descriptions explaining each instance's responsibilities
|
525
|
+
- Choose opus model for complex architectural or algorithmic tasks and routine development.
|
526
|
+
- Choose sonnet model for simpler tasks
|
527
|
+
- Set up logical connections (e.g., lead → team members, architect → implementers), but avoid circular dependencies.
|
528
|
+
- Always add this to the end of every prompt: `For maximum efficiency, whenever you need to perform multiple independent operations, invoke all relevant tools simultaneously rather than sequentially.`
|
529
|
+
- Select tools based on each instance's actual needs:
|
530
|
+
- Read: For code review and analysis roles
|
531
|
+
- Edit: For active development roles
|
532
|
+
- Write: For creating new files
|
533
|
+
- Bash: For running commands, tests, builds
|
534
|
+
- MultiEdit: For editing multiple files at once
|
535
|
+
- WebFetch: For fetching information from the web
|
536
|
+
- WebSearch: For searching the web
|
537
|
+
- Use custom prompts to specialize each instance's expertise
|
538
|
+
- Organize directories to match project structure
|
539
|
+
|
540
|
+
## Interactive Questions to Ask
|
541
|
+
- What type of project are you working on?
|
542
|
+
- What's your project's directory structure?
|
543
|
+
- What are the main technologies/frameworks you're using?
|
544
|
+
- What development tasks do you need help with?
|
545
|
+
- Do you need specialized roles (testing, DevOps, documentation)?
|
546
|
+
- Are there specific areas that need focused attention?
|
547
|
+
- Do you have multiple repositories or services to coordinate?
|
548
|
+
|
549
|
+
<full_readme>
|
550
|
+
#{readme_content}
|
551
|
+
</full_readme>
|
552
|
+
|
553
|
+
Start the conversation by greeting the user and asking: "What kind of project would you like to create a Claude Swarm for?"
|
554
|
+
PROMPT
|
555
|
+
end
|
428
556
|
end
|
429
557
|
end
|