claude_swarm 0.1.19 → 0.1.20
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/.rubocop.yml +3 -0
- data/CHANGELOG.md +17 -0
- data/CLAUDE.md +3 -2
- data/README.md +18 -13
- data/examples/monitoring-demo.yml +4 -4
- data/lib/claude_swarm/claude_code_executor.rb +0 -1
- data/lib/claude_swarm/claude_mcp_server.rb +0 -5
- data/lib/claude_swarm/cli.rb +99 -108
- data/lib/claude_swarm/mcp_generator.rb +0 -1
- data/lib/claude_swarm/orchestrator.rb +16 -6
- data/lib/claude_swarm/system_utils.rb +18 -0
- data/lib/claude_swarm/templates/generation_prompt.md.erb +230 -0
- data/lib/claude_swarm/version.rb +1 -1
- data/lib/claude_swarm/worktree_manager.rb +136 -32
- data/lib/claude_swarm.rb +21 -12
- data/llms.txt +2 -2
- data/team.yml +344 -0
- metadata +18 -1
@@ -0,0 +1,230 @@
|
|
1
|
+
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.
|
2
|
+
|
3
|
+
## Claude Swarm Overview
|
4
|
+
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).
|
5
|
+
|
6
|
+
Key capabilities:
|
7
|
+
- Define multiple AI instances with different roles and specializations
|
8
|
+
- Set up connections between instances for collaboration
|
9
|
+
- Restrict tools based on each instance's responsibilities
|
10
|
+
- Run instances in different directories or Git worktrees
|
11
|
+
- Support for custom system prompts per instance
|
12
|
+
- Choose appropriate models (opus for complex tasks, sonnet for simpler ones)
|
13
|
+
|
14
|
+
## Your Task
|
15
|
+
1. Start by asking about the user's project structure and development needs
|
16
|
+
2. Understand what kind of team they need (roles, specializations)
|
17
|
+
3. Suggest an appropriate swarm topology based on their needs
|
18
|
+
4. Help them refine and customize the configuration
|
19
|
+
5. Generate the final claude-swarm.yml content
|
20
|
+
6. When the configuration is complete, save it to: <%= output_file || "a descriptive filename based on the swarm's function" %>
|
21
|
+
|
22
|
+
## File Naming Convention
|
23
|
+
<% if output_file %>
|
24
|
+
The user has specified the output file: <%= output_file %>
|
25
|
+
<% else %>
|
26
|
+
Since no output file was specified, name the file based on the swarm's function. Examples:
|
27
|
+
- web-dev-swarm.yml for full-stack web development teams
|
28
|
+
- data-pipeline-swarm.yml for data processing teams
|
29
|
+
- microservices-swarm.yml for microservice architectures
|
30
|
+
- mobile-app-swarm.yml for mobile development teams
|
31
|
+
- ml-research-swarm.yml for machine learning teams
|
32
|
+
- devops-swarm.yml for infrastructure and deployment teams
|
33
|
+
Use descriptive names that clearly indicate the swarm's purpose.
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
## Configuration Structure
|
37
|
+
```yaml
|
38
|
+
version: 1
|
39
|
+
swarm:
|
40
|
+
name: "Descriptive Swarm Name"
|
41
|
+
main: main_instance_name
|
42
|
+
instances:
|
43
|
+
instance_name:
|
44
|
+
description: "Clear description of role and responsibilities"
|
45
|
+
directory: ./path/to/directory
|
46
|
+
model: sonnet # or opus for complex tasks
|
47
|
+
allowed_tools: [Read, Edit, Write, Bash]
|
48
|
+
connections: [other_instance_names] # Optional
|
49
|
+
prompt: |
|
50
|
+
Custom system prompt for specialization
|
51
|
+
|
52
|
+
```
|
53
|
+
|
54
|
+
## Best Practices to Follow
|
55
|
+
- Use descriptive, role-based instance names (e.g., frontend_dev, api_architect)
|
56
|
+
- Write prompts using multi-line strings to make them more readable.
|
57
|
+
- Write clear descriptions explaining each instance's responsibilities
|
58
|
+
- Choose opus model for complex architectural or algorithmic tasks and routine development.
|
59
|
+
- Choose sonnet model for simpler tasks
|
60
|
+
- Set up logical connections (e.g., lead → team members, architect → implementers), but avoid circular dependencies.
|
61
|
+
- 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.`
|
62
|
+
- Select tools based on each instance's actual needs:
|
63
|
+
- Read: For code review and analysis roles
|
64
|
+
- Edit: For active development roles
|
65
|
+
- Write: For creating new files
|
66
|
+
- Bash: For running commands, tests, builds
|
67
|
+
- MultiEdit: For editing multiple files at once
|
68
|
+
- WebFetch: For fetching information from the web
|
69
|
+
- WebSearch: For searching the web
|
70
|
+
- Use custom prompts to specialize each instance's expertise
|
71
|
+
- Organize directories to match project structure
|
72
|
+
|
73
|
+
## Interactive Questions to Ask
|
74
|
+
- What type of project are you working on?
|
75
|
+
- What's your project's directory structure?
|
76
|
+
- What are the main technologies/frameworks you're using?
|
77
|
+
- What development tasks do you need help with?
|
78
|
+
- Do you need specialized roles (testing, DevOps, documentation)?
|
79
|
+
- Are there specific areas that need focused attention?
|
80
|
+
- Do you have multiple repositories or services to coordinate?
|
81
|
+
|
82
|
+
<full_readme>
|
83
|
+
<%= readme_content %>
|
84
|
+
</full_readme>
|
85
|
+
|
86
|
+
<prompt_best_practices>
|
87
|
+
# Claude 4 prompt engineering best practices
|
88
|
+
|
89
|
+
This guide provides specific prompt engineering techniques for Claude 4 models (Opus 4 and Sonnet 4) to help you achieve optimal results in your applications. These models have been trained for more precise instruction following than previous generations of Claude models.
|
90
|
+
|
91
|
+
## General principles
|
92
|
+
|
93
|
+
### Be explicit with your instructions
|
94
|
+
|
95
|
+
Claude 4 models respond well to clear, explicit instructions. Being specific about your desired output can help enhance results. Customers who desire the "above and beyond" behavior from previous Claude models might need to more explicitly request these behaviors with Claude 4.
|
96
|
+
|
97
|
+
**Less effective:**
|
98
|
+
|
99
|
+
```text
|
100
|
+
Create an analytics dashboard
|
101
|
+
```
|
102
|
+
|
103
|
+
**More effective:**
|
104
|
+
|
105
|
+
```text
|
106
|
+
Create an analytics dashboard. Include as many relevant features and interactions as possible. Go beyond the basics to create a fully-featured implementation.
|
107
|
+
```
|
108
|
+
|
109
|
+
### Add context to improve performance
|
110
|
+
|
111
|
+
Providing context or motivation behind your instructions, such as explaining to Claude why such behavior is important, can help Claude 4 better understand your goals and deliver more targeted responses.
|
112
|
+
|
113
|
+
**Less effective:**
|
114
|
+
|
115
|
+
```text
|
116
|
+
NEVER use ellipses
|
117
|
+
```
|
118
|
+
|
119
|
+
**More effective:**
|
120
|
+
|
121
|
+
```text
|
122
|
+
Your response will be read aloud by a text-to-speech engine, so never use ellipses since the text-to-speech engine will not know how to pronounce them.
|
123
|
+
```
|
124
|
+
|
125
|
+
Claude is smart enough to generalize from the explanation.
|
126
|
+
|
127
|
+
### Be vigilant with examples & details
|
128
|
+
|
129
|
+
Claude 4 models pay attention to details and examples as part of instruction following. Ensure that your examples align with the behaviors you want to encourage and minimize behaviors you want to avoid.
|
130
|
+
|
131
|
+
## Guidance for specific situations
|
132
|
+
|
133
|
+
### Control the format of responses
|
134
|
+
|
135
|
+
There are a few ways that we have found to be particularly effective in seering output formatting in Claude 4 models:
|
136
|
+
|
137
|
+
1. **Tell Claude what to do instead of what not to do**
|
138
|
+
|
139
|
+
* Instead of: "Do not use markdown in your response"
|
140
|
+
* Try: "Your response should be composed of smoothly flowing prose paragraphs."
|
141
|
+
|
142
|
+
2. **Use XML format indicators**
|
143
|
+
|
144
|
+
* Try: "Write the prose sections of your response in <smoothly_flowing_prose_paragraphs> tags."
|
145
|
+
|
146
|
+
3. **Match your prompt style to the desired output**
|
147
|
+
|
148
|
+
The formatting style used in your prompt may influence Claude's response style. If you are still experiencing steerability issues with output formatting, we recommend as best as you can matching your prompt style to your desired output style. For exmaple, removing markdown from your prompt can reduce the volume of markdown in the output.
|
149
|
+
|
150
|
+
### Leverage thinking & interleaved thinking capabilities
|
151
|
+
|
152
|
+
Claude 4 offers thinking capabilities that can be especially helpful for tasks involving reflection after tool use or complex multi-step reasoning. You can guide its initial or interleaved thinking for better results.
|
153
|
+
|
154
|
+
```text Example prompt
|
155
|
+
After receiving tool results, carefully reflect on their quality and determine optimal next steps before proceeding. Use your thinking to plan and iterate based on this new information, and then take the best next action.
|
156
|
+
```
|
157
|
+
|
158
|
+
### Optimize parallel tool calling
|
159
|
+
|
160
|
+
Claude 4 models excel at parallel tool execution. They have a high success rate in using parallel tool calling without any prompting to do so, but some minor prompting can boost this behavior to ~100% parallel tool use success rate. We have found this prompt to be most effective:
|
161
|
+
|
162
|
+
```text Sample prompt for agents
|
163
|
+
For maximum efficiency, whenever you need to perform multiple independent operations, invoke all relevant tools simultaneously rather than sequentially.
|
164
|
+
```
|
165
|
+
|
166
|
+
### Reduce file creation in agentic coding
|
167
|
+
|
168
|
+
Claude 4 models may sometimes create new files for testing and iteration purposes, particularly when working with code. This approach allows Claude to use files, especially python scripts, as a 'temporary scratchpad' before saving its final output. Using temporary files can improve outcomes particularly for agentic coding use cases.
|
169
|
+
|
170
|
+
If you'd prefer to minimize net new file creation, you can instruct Claude to clean up after itself:
|
171
|
+
|
172
|
+
```text Sample prompt
|
173
|
+
If you create any temporary new files, scripts, or helper files for iteration, clean up these files by removing them at the end of the task.
|
174
|
+
```
|
175
|
+
|
176
|
+
### Enhance visual and frontend code generation
|
177
|
+
|
178
|
+
For frontend code generation, you can steer Claude 4 models to create complex, detailed, and interactive designs by providing explicit encouragement:
|
179
|
+
|
180
|
+
```text Sample prompt
|
181
|
+
Don't hold back. Give it your all.
|
182
|
+
```
|
183
|
+
|
184
|
+
You can also improve Claude's frontend performance in specific areas by providing additional modifiers and details on what to focus on:
|
185
|
+
|
186
|
+
* "Include as many relevant features and interactions as possible"
|
187
|
+
* "Add thoughtful details like hover states, transitions, and micro-interactions"
|
188
|
+
* "Create an impressive demonstration showcasing web development capabilities"
|
189
|
+
* "Apply design principles: hierarchy, contrast, balance, and movement"
|
190
|
+
|
191
|
+
### Avoid focusing on passing tests and hard-coding
|
192
|
+
|
193
|
+
Frontier language models can sometimes focus too heavily on making tests pass at the expense of more general solutions. To prevent this behavior and ensure robust, generalizable solutions:
|
194
|
+
|
195
|
+
```text
|
196
|
+
Please write a high quality, general purpose solution. Implement a solution that works correctly for all valid inputs, not just the test cases. Do not hard-code values or create solutions that only work for specific test inputs. Instead, implement the actual logic that solves the problem generally.
|
197
|
+
|
198
|
+
Focus on understanding the problem requirements and implementing the correct algorithm. Tests are there to verify correctness, not to define the solution. Provide a principled implementation that follows best practices and software design principles.
|
199
|
+
|
200
|
+
If the task is unreasonable or infeasible, or if any of the tests are incorrect, please tell me. The solution should be robust, maintainable, and extendable.
|
201
|
+
```
|
202
|
+
|
203
|
+
1. **Be specific about desired behavior**: Consider describing exactly what you'd like to see in the output.
|
204
|
+
|
205
|
+
2. **Frame your instructions with modifiers**: Adding modifiers that encourage Claude to increase the quality and detail of its output can help better shape Claude's performance. For example, instead of "Create an analytics dashboard", use "Create an analytics dashboard. Include as many relevant features and interactions as possible. Go beyond the basics to create a fully-featured implementation."
|
206
|
+
|
207
|
+
3. **Request specific features explicitly**: Animations and interactive elements should be requested explicitly when desired.
|
208
|
+
|
209
|
+
|
210
|
+
# Be clear, direct, and detailed
|
211
|
+
|
212
|
+
When interacting with Claude, think of it as a brilliant but very new employee (with amnesia) who needs explicit instructions. Like any new employee, Claude does not have context on your norms, styles, guidelines, or preferred ways of working.
|
213
|
+
The more precisely you explain what you want, the better Claude's response will be.
|
214
|
+
|
215
|
+
**The golden rule of clear prompting:** Show your prompt to a colleague, ideally someone who has minimal context on the task, and ask them to follow the instructions. If they're confused, Claude will likely be too.
|
216
|
+
|
217
|
+
## How to be clear, contextual, and specific
|
218
|
+
|
219
|
+
* **Give Claude contextual information:** Just like you might be able to better perform on a task if you knew more context, Claude will perform better if it has more contextual information. Some examples of contextual information:
|
220
|
+
* What the task results will be used for
|
221
|
+
* What audience the output is meant for
|
222
|
+
* What workflow the task is a part of, and where this task belongs in that workflow
|
223
|
+
* The end goal of the task, or what a successful task completion looks like
|
224
|
+
* **Be specific about what you want Claude to do:** For example, if you want Claude to output only code and nothing else, say so.
|
225
|
+
* **Provide instructions as sequential steps:** Use numbered lists or bullet points to better ensure that Claude carries out the task the exact way you want it to.
|
226
|
+
|
227
|
+
</prompt_best_practices>
|
228
|
+
|
229
|
+
Start the conversation by greeting the user and asking: "What kind of project would you like to create a Claude Swarm for?"
|
230
|
+
Say: I am ready to start
|
data/lib/claude_swarm/version.rb
CHANGED
@@ -5,9 +5,11 @@ require "fileutils"
|
|
5
5
|
require "json"
|
6
6
|
require "pathname"
|
7
7
|
require "securerandom"
|
8
|
+
require "digest"
|
8
9
|
|
9
10
|
module ClaudeSwarm
|
10
11
|
class WorktreeManager
|
12
|
+
include SystemUtils
|
11
13
|
attr_reader :shared_worktree_name, :created_worktrees
|
12
14
|
|
13
15
|
def initialize(cli_worktree_option = nil, session_id: nil)
|
@@ -121,7 +123,9 @@ module ClaudeSwarm
|
|
121
123
|
end
|
122
124
|
|
123
125
|
# Check for unpushed commits
|
124
|
-
|
126
|
+
has_unpushed = has_unpushed_commits?(worktree_path)
|
127
|
+
|
128
|
+
if has_unpushed
|
125
129
|
puts "⚠️ Warning: Worktree has unpushed commits, skipping cleanup: #{worktree_path}" unless ENV["CLAUDE_SWARM_PROMPT"]
|
126
130
|
next
|
127
131
|
end
|
@@ -137,10 +141,37 @@ module ClaudeSwarm
|
|
137
141
|
output, status = Open3.capture2e("git", "-C", repo_root, "worktree", "remove", "--force", worktree_path)
|
138
142
|
puts "Force remove result: #{output}" unless status.success?
|
139
143
|
end
|
144
|
+
|
145
|
+
# Clean up external worktree directories
|
146
|
+
cleanup_external_directories
|
140
147
|
rescue StandardError => e
|
141
148
|
puts "Error during worktree cleanup: #{e.message}"
|
142
149
|
end
|
143
150
|
|
151
|
+
def cleanup_external_directories
|
152
|
+
# Remove session-specific worktree directory if it exists and is empty
|
153
|
+
return unless @session_id
|
154
|
+
|
155
|
+
session_worktree_dir = File.join(File.expand_path("~/.claude-swarm/worktrees"), @session_id)
|
156
|
+
return unless File.exist?(session_worktree_dir)
|
157
|
+
|
158
|
+
# Try to remove the directory tree
|
159
|
+
begin
|
160
|
+
# Remove all empty directories recursively
|
161
|
+
Dir.glob(File.join(session_worktree_dir, "**/*"), File::FNM_DOTMATCH).reverse_each do |path|
|
162
|
+
next if path.end_with?("/.", "/..")
|
163
|
+
|
164
|
+
FileUtils.rmdir(path) if File.directory?(path) && Dir.empty?(path)
|
165
|
+
end
|
166
|
+
# Finally try to remove the session directory itself
|
167
|
+
FileUtils.rmdir(session_worktree_dir) if Dir.empty?(session_worktree_dir)
|
168
|
+
rescue Errno::ENOTEMPTY
|
169
|
+
puts "Note: Session worktree directory not empty, leaving in place: #{session_worktree_dir}" unless ENV["CLAUDE_SWARM_PROMPT"]
|
170
|
+
rescue StandardError => e
|
171
|
+
puts "Warning: Error cleaning up worktree directories: #{e.message}" unless ENV["CLAUDE_SWARM_PROMPT"]
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
144
175
|
def session_metadata
|
145
176
|
{
|
146
177
|
enabled: true,
|
@@ -157,6 +188,35 @@ module ClaudeSwarm
|
|
157
188
|
|
158
189
|
private
|
159
190
|
|
191
|
+
def external_worktree_path(repo_root, worktree_name)
|
192
|
+
# Get repository name from path
|
193
|
+
repo_name = sanitize_repo_name(File.basename(repo_root))
|
194
|
+
|
195
|
+
# Add a short hash of the full path to handle multiple repos with same name
|
196
|
+
path_hash = Digest::SHA256.hexdigest(repo_root)[0..7]
|
197
|
+
unique_repo_name = "#{repo_name}-#{path_hash}"
|
198
|
+
|
199
|
+
# Build external path: ~/.claude-swarm/worktrees/[session_id]/[repo_name-hash]/[worktree_name]
|
200
|
+
base_dir = File.expand_path("~/.claude-swarm/worktrees")
|
201
|
+
|
202
|
+
# Validate base directory is accessible
|
203
|
+
begin
|
204
|
+
FileUtils.mkdir_p(base_dir)
|
205
|
+
rescue Errno::EACCES
|
206
|
+
# Fall back to temp directory if home is not writable
|
207
|
+
base_dir = File.join(Dir.tmpdir, ".claude-swarm", "worktrees")
|
208
|
+
FileUtils.mkdir_p(base_dir)
|
209
|
+
end
|
210
|
+
|
211
|
+
session_dir = @session_id || "default"
|
212
|
+
File.join(base_dir, session_dir, unique_repo_name, worktree_name)
|
213
|
+
end
|
214
|
+
|
215
|
+
def sanitize_repo_name(name)
|
216
|
+
# Replace problematic characters with underscores
|
217
|
+
name.gsub(/[^a-zA-Z0-9._-]/, "_")
|
218
|
+
end
|
219
|
+
|
160
220
|
def generate_worktree_name
|
161
221
|
# Use session ID if available, otherwise generate a random suffix
|
162
222
|
if @session_id
|
@@ -240,9 +300,8 @@ module ClaudeSwarm
|
|
240
300
|
|
241
301
|
def create_worktree(repo_root, worktree_name)
|
242
302
|
worktree_key = "#{repo_root}:#{worktree_name}"
|
243
|
-
# Create worktrees
|
244
|
-
|
245
|
-
worktree_path = File.join(worktree_base_dir, worktree_name)
|
303
|
+
# Create worktrees in external directory
|
304
|
+
worktree_path = external_worktree_path(repo_root, worktree_name)
|
246
305
|
|
247
306
|
# Check if worktree already exists
|
248
307
|
if File.exist?(worktree_path)
|
@@ -251,12 +310,16 @@ module ClaudeSwarm
|
|
251
310
|
return
|
252
311
|
end
|
253
312
|
|
254
|
-
# Ensure
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
313
|
+
# Ensure parent directory exists with proper error handling
|
314
|
+
begin
|
315
|
+
FileUtils.mkdir_p(File.dirname(worktree_path))
|
316
|
+
rescue Errno::EACCES => e
|
317
|
+
raise Error, "Permission denied creating worktree directory: #{e.message}"
|
318
|
+
rescue Errno::ENOSPC => e
|
319
|
+
raise Error, "Not enough disk space for worktree: #{e.message}"
|
320
|
+
rescue StandardError => e
|
321
|
+
raise Error, "Failed to create worktree directory: #{e.message}"
|
322
|
+
end
|
260
323
|
|
261
324
|
# Get current branch
|
262
325
|
output, status = Open3.capture2e("git", "-C", repo_root, "rev-parse", "--abbrev-ref", "HEAD")
|
@@ -277,6 +340,26 @@ module ClaudeSwarm
|
|
277
340
|
output, status = Open3.capture2e("git", "-C", repo_root, "worktree", "add", worktree_path, branch_name)
|
278
341
|
end
|
279
342
|
|
343
|
+
# If worktree path is already in use, it might be from a previous run
|
344
|
+
if !status.success? && output.include?("is already used by worktree")
|
345
|
+
puts "Worktree path already in use, checking if it's valid" unless ENV["CLAUDE_SWARM_PROMPT"]
|
346
|
+
# Check if the worktree actually exists at that path
|
347
|
+
if File.exist?(File.join(worktree_path, ".git"))
|
348
|
+
puts "Using existing worktree: #{worktree_path}" unless ENV["CLAUDE_SWARM_PROMPT"]
|
349
|
+
@created_worktrees[worktree_key] = worktree_path
|
350
|
+
return
|
351
|
+
else
|
352
|
+
# The worktree is registered but the directory doesn't exist, prune and retry
|
353
|
+
puts "Pruning stale worktree references" unless ENV["CLAUDE_SWARM_PROMPT"]
|
354
|
+
begin
|
355
|
+
system!("git", "-C", repo_root, "worktree", "prune")
|
356
|
+
rescue Error
|
357
|
+
# Ignore errors when pruning
|
358
|
+
end
|
359
|
+
output, status = Open3.capture2e("git", "-C", repo_root, "worktree", "add", worktree_path, branch_name)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
280
363
|
raise Error, "Failed to create worktree: #{output}" unless status.success?
|
281
364
|
|
282
365
|
@created_worktrees[worktree_key] = worktree_path
|
@@ -301,35 +384,56 @@ module ClaudeSwarm
|
|
301
384
|
# Check if the branch has an upstream
|
302
385
|
_, upstream_status = Open3.capture2e("git", "-C", worktree_path, "rev-parse", "--abbrev-ref", "#{current_branch}@{upstream}")
|
303
386
|
|
304
|
-
# If
|
305
|
-
|
306
|
-
#
|
307
|
-
|
387
|
+
# If branch has upstream, check against it
|
388
|
+
if upstream_status.success?
|
389
|
+
# Check for unpushed commits against upstream
|
390
|
+
unpushed_output, unpushed_status = Open3.capture2e("git", "-C", worktree_path, "rev-list", "HEAD", "^#{current_branch}@{upstream}")
|
391
|
+
return false unless unpushed_status.success?
|
392
|
+
|
393
|
+
# If output is not empty, there are unpushed commits
|
394
|
+
return !unpushed_output.strip.empty?
|
395
|
+
end
|
308
396
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
return false unless commits_status.success?
|
397
|
+
# No upstream - this is likely a new branch created by the worktree
|
398
|
+
# The key insight: when git worktree add -b creates a branch, it creates it in BOTH
|
399
|
+
# the worktree AND the main repository. So we need to check the reflog in the worktree
|
400
|
+
# to see if any NEW commits were made after the worktree was created.
|
314
401
|
|
315
|
-
|
316
|
-
|
317
|
-
end
|
402
|
+
# Use reflog to check if any commits were made in this worktree
|
403
|
+
reflog_output, reflog_status = Open3.capture2e("git", "-C", worktree_path, "reflog", "--format=%H %gs", current_branch)
|
318
404
|
|
319
|
-
|
320
|
-
|
321
|
-
return false unless commits_status.success?
|
405
|
+
if reflog_status.success? && !reflog_output.strip.empty?
|
406
|
+
reflog_lines = reflog_output.strip.split("\n")
|
322
407
|
|
323
|
-
#
|
324
|
-
|
408
|
+
# Look for commit entries (not branch creation)
|
409
|
+
commit_entries = reflog_lines.select { |line| line.include?(" commit:") || line.include?(" commit (amend):") }
|
410
|
+
|
411
|
+
# If there are commit entries in the reflog, there are unpushed commits
|
412
|
+
return !commit_entries.empty?
|
325
413
|
end
|
326
414
|
|
327
|
-
#
|
328
|
-
|
329
|
-
|
415
|
+
# As a fallback, assume no unpushed commits
|
416
|
+
false
|
417
|
+
end
|
418
|
+
|
419
|
+
def find_original_repo_for_worktree(worktree_path)
|
420
|
+
# Get the git directory for this worktree
|
421
|
+
_, git_dir_status = Open3.capture2e("git", "-C", worktree_path, "rev-parse", "--git-dir")
|
422
|
+
return nil unless git_dir_status.success?
|
423
|
+
|
424
|
+
# Read the gitdir file to find the main repository
|
425
|
+
# Worktree .git files contain: gitdir: /path/to/main/repo/.git/worktrees/worktree-name
|
426
|
+
if File.file?(File.join(worktree_path, ".git"))
|
427
|
+
gitdir_content = File.read(File.join(worktree_path, ".git")).strip
|
428
|
+
if gitdir_content =~ /^gitdir: (.+)$/
|
429
|
+
git_path = $1
|
430
|
+
# Extract the main repo path from the worktree git path
|
431
|
+
# Format: /path/to/repo/.git/worktrees/worktree-name
|
432
|
+
return $1 if git_path =~ %r{^(.+)/\.git/worktrees/[^/]+$}
|
433
|
+
end
|
434
|
+
end
|
330
435
|
|
331
|
-
|
332
|
-
!unpushed_output.strip.empty?
|
436
|
+
nil
|
333
437
|
end
|
334
438
|
|
335
439
|
def find_base_branch(repo_path)
|
data/lib/claude_swarm.rb
CHANGED
@@ -1,17 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
# External dependencies
|
4
|
+
require "time"
|
5
|
+
require "thor"
|
6
|
+
require "yaml"
|
7
|
+
require "json"
|
8
|
+
require "fileutils"
|
9
|
+
require "erb"
|
10
|
+
require "tmpdir"
|
11
|
+
require "open3"
|
12
|
+
require "timeout"
|
13
|
+
require "pty"
|
14
|
+
require "io/console"
|
15
|
+
|
16
|
+
# Zeitwerk setup
|
17
|
+
require "zeitwerk"
|
18
|
+
loader = Zeitwerk::Loader.for_gem
|
19
|
+
loader.ignore("#{__dir__}/claude_swarm/templates")
|
20
|
+
loader.inflector.inflect(
|
21
|
+
"cli" => "CLI"
|
22
|
+
)
|
23
|
+
loader.setup
|
15
24
|
|
16
25
|
module ClaudeSwarm
|
17
26
|
class Error < StandardError; end
|
data/llms.txt
CHANGED
@@ -57,7 +57,7 @@ A collection of Claude instances (agents) working together. One instance is desi
|
|
57
57
|
An individual Claude Code agent with:
|
58
58
|
- **description** (required): Role and responsibilities
|
59
59
|
- **directory**: Working directory context
|
60
|
-
- **model**: Claude model (opus/sonnet
|
60
|
+
- **model**: Claude model (opus/sonnet)
|
61
61
|
- **connections**: Other instances it can delegate to
|
62
62
|
- **allowed_tools**: Tools this instance can use
|
63
63
|
- **disallowed_tools**: Explicitly denied tools (override allowed)
|
@@ -79,7 +79,7 @@ swarm:
|
|
79
79
|
instance_name:
|
80
80
|
description: "Agent role description" # REQUIRED
|
81
81
|
directory: ~/path/to/dir # Working directory
|
82
|
-
model: opus # opus/sonnet
|
82
|
+
model: opus # opus/sonnet
|
83
83
|
connections: [other1, other2] # Connected instances
|
84
84
|
prompt: "Custom system prompt" # Additional instructions
|
85
85
|
vibe: false # Skip permissions (default: false)
|