claude_swarm 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.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/{CHANGELOG.md → CHANGELOG.claude-swarm.md} +10 -0
  3. data/CLAUDE.md +346 -191
  4. data/decisions/2025-11-22-001-global-agent-registry.md +172 -0
  5. data/docs/v2/CHANGELOG.swarm_cli.md +20 -0
  6. data/docs/v2/CHANGELOG.swarm_memory.md +146 -1
  7. data/docs/v2/CHANGELOG.swarm_sdk.md +433 -10
  8. data/docs/v2/README.md +20 -5
  9. data/docs/v2/guides/complete-tutorial.md +95 -9
  10. data/docs/v2/guides/getting-started.md +10 -8
  11. data/docs/v2/guides/memory-adapters.md +41 -0
  12. data/docs/v2/guides/migrating-to-2.x.md +746 -0
  13. data/docs/v2/guides/plugins.md +52 -5
  14. data/docs/v2/guides/rails-integration.md +6 -0
  15. data/docs/v2/guides/snapshots.md +14 -14
  16. data/docs/v2/guides/swarm-memory.md +2 -13
  17. data/docs/v2/reference/architecture-flow.md +3 -3
  18. data/docs/v2/reference/cli.md +0 -1
  19. data/docs/v2/reference/configuration_reference.md +300 -0
  20. data/docs/v2/reference/event_payload_structures.md +27 -5
  21. data/docs/v2/reference/ruby-dsl.md +614 -18
  22. data/docs/v2/reference/swarm_memory_technical_details.md +7 -29
  23. data/docs/v2/reference/yaml.md +172 -54
  24. data/examples/snapshot_demo.rb +2 -2
  25. data/lib/claude_swarm/mcp_generator.rb +8 -21
  26. data/lib/claude_swarm/orchestrator.rb +8 -1
  27. data/lib/claude_swarm/version.rb +1 -1
  28. data/lib/swarm_cli/commands/run.rb +2 -2
  29. data/lib/swarm_cli/config_loader.rb +11 -11
  30. data/lib/swarm_cli/formatters/human_formatter.rb +0 -33
  31. data/lib/swarm_cli/interactive_repl.rb +2 -2
  32. data/lib/swarm_cli/ui/icons.rb +0 -23
  33. data/lib/swarm_cli/version.rb +1 -1
  34. data/lib/swarm_memory/adapters/filesystem_adapter.rb +11 -34
  35. data/lib/swarm_memory/core/semantic_index.rb +10 -2
  36. data/lib/swarm_memory/core/storage.rb +7 -2
  37. data/lib/swarm_memory/dsl/memory_config.rb +37 -0
  38. data/lib/swarm_memory/integration/sdk_plugin.rb +201 -28
  39. data/lib/swarm_memory/optimization/defragmenter.rb +1 -1
  40. data/lib/swarm_memory/prompts/memory_researcher.md.erb +0 -1
  41. data/lib/swarm_memory/tools/load_skill.rb +0 -1
  42. data/lib/swarm_memory/tools/memory_edit.rb +2 -1
  43. data/lib/swarm_memory/tools/memory_read.rb +1 -1
  44. data/lib/swarm_memory/version.rb +1 -1
  45. data/lib/swarm_memory.rb +8 -6
  46. data/lib/swarm_sdk/agent/builder.rb +58 -0
  47. data/lib/swarm_sdk/agent/chat.rb +527 -1061
  48. data/lib/swarm_sdk/agent/{chat → chat_helpers}/context_tracker.rb +13 -88
  49. data/lib/swarm_sdk/agent/chat_helpers/event_emitter.rb +204 -0
  50. data/lib/swarm_sdk/agent/{chat → chat_helpers}/hook_integration.rb +108 -46
  51. data/lib/swarm_sdk/agent/chat_helpers/instrumentation.rb +78 -0
  52. data/lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb +267 -0
  53. data/lib/swarm_sdk/agent/{chat → chat_helpers}/logging_helpers.rb +3 -3
  54. data/lib/swarm_sdk/agent/chat_helpers/serialization.rb +83 -0
  55. data/lib/swarm_sdk/agent/{chat → chat_helpers}/system_reminder_injector.rb +11 -13
  56. data/lib/swarm_sdk/agent/chat_helpers/system_reminders.rb +79 -0
  57. data/lib/swarm_sdk/agent/chat_helpers/token_tracking.rb +146 -0
  58. data/lib/swarm_sdk/agent/context.rb +1 -2
  59. data/lib/swarm_sdk/agent/definition.rb +66 -154
  60. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +4 -2
  61. data/lib/swarm_sdk/agent/system_prompt_builder.rb +161 -0
  62. data/lib/swarm_sdk/agent_registry.rb +146 -0
  63. data/lib/swarm_sdk/builders/base_builder.rb +488 -0
  64. data/lib/swarm_sdk/concerns/cleanupable.rb +39 -0
  65. data/lib/swarm_sdk/concerns/snapshotable.rb +67 -0
  66. data/lib/swarm_sdk/concerns/validatable.rb +55 -0
  67. data/lib/swarm_sdk/config.rb +302 -0
  68. data/lib/swarm_sdk/configuration/parser.rb +373 -0
  69. data/lib/swarm_sdk/configuration/translator.rb +255 -0
  70. data/lib/swarm_sdk/configuration.rb +77 -546
  71. data/lib/swarm_sdk/context_compactor/token_counter.rb +2 -6
  72. data/lib/swarm_sdk/context_compactor.rb +6 -11
  73. data/lib/swarm_sdk/context_management/builder.rb +128 -0
  74. data/lib/swarm_sdk/context_management/context.rb +328 -0
  75. data/lib/swarm_sdk/custom_tool_registry.rb +226 -0
  76. data/lib/swarm_sdk/defaults.rb +196 -0
  77. data/lib/swarm_sdk/events_to_messages.rb +18 -0
  78. data/lib/swarm_sdk/hooks/adapter.rb +3 -3
  79. data/lib/swarm_sdk/hooks/shell_executor.rb +4 -2
  80. data/lib/swarm_sdk/log_collector.rb +179 -29
  81. data/lib/swarm_sdk/log_stream.rb +29 -0
  82. data/lib/swarm_sdk/models.json +4333 -1
  83. data/lib/swarm_sdk/models.rb +43 -2
  84. data/lib/swarm_sdk/node_context.rb +1 -1
  85. data/lib/swarm_sdk/observer/builder.rb +81 -0
  86. data/lib/swarm_sdk/observer/config.rb +45 -0
  87. data/lib/swarm_sdk/observer/manager.rb +236 -0
  88. data/lib/swarm_sdk/patterns/agent_observer.rb +160 -0
  89. data/lib/swarm_sdk/plugin.rb +95 -5
  90. data/lib/swarm_sdk/result.rb +52 -0
  91. data/lib/swarm_sdk/snapshot.rb +6 -6
  92. data/lib/swarm_sdk/snapshot_from_events.rb +13 -2
  93. data/lib/swarm_sdk/state_restorer.rb +136 -151
  94. data/lib/swarm_sdk/state_snapshot.rb +65 -100
  95. data/lib/swarm_sdk/swarm/agent_initializer.rb +181 -137
  96. data/lib/swarm_sdk/swarm/builder.rb +44 -578
  97. data/lib/swarm_sdk/swarm/executor.rb +213 -0
  98. data/lib/swarm_sdk/swarm/hook_triggers.rb +151 -0
  99. data/lib/swarm_sdk/swarm/logging_callbacks.rb +341 -0
  100. data/lib/swarm_sdk/swarm/mcp_configurator.rb +7 -4
  101. data/lib/swarm_sdk/swarm/tool_configurator.rb +58 -140
  102. data/lib/swarm_sdk/swarm.rb +203 -683
  103. data/lib/swarm_sdk/tools/bash.rb +14 -8
  104. data/lib/swarm_sdk/tools/delegate.rb +61 -43
  105. data/lib/swarm_sdk/tools/edit.rb +8 -13
  106. data/lib/swarm_sdk/tools/glob.rb +12 -4
  107. data/lib/swarm_sdk/tools/grep.rb +7 -0
  108. data/lib/swarm_sdk/tools/multi_edit.rb +15 -11
  109. data/lib/swarm_sdk/tools/path_resolver.rb +51 -2
  110. data/lib/swarm_sdk/tools/read.rb +16 -18
  111. data/lib/swarm_sdk/tools/registry.rb +122 -10
  112. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +9 -5
  113. data/lib/swarm_sdk/tools/stores/storage.rb +0 -6
  114. data/lib/swarm_sdk/tools/todo_write.rb +7 -0
  115. data/lib/swarm_sdk/tools/web_fetch.rb +20 -17
  116. data/lib/swarm_sdk/tools/write.rb +8 -13
  117. data/lib/swarm_sdk/version.rb +1 -1
  118. data/lib/swarm_sdk/{node → workflow}/agent_config.rb +1 -1
  119. data/lib/swarm_sdk/workflow/builder.rb +192 -0
  120. data/lib/swarm_sdk/workflow/executor.rb +497 -0
  121. data/lib/swarm_sdk/{node/builder.rb → workflow/node_builder.rb} +7 -5
  122. data/lib/swarm_sdk/{node → workflow}/transformer_executor.rb +5 -3
  123. data/lib/swarm_sdk/{node_orchestrator.rb → workflow.rb} +152 -456
  124. data/lib/swarm_sdk.rb +294 -108
  125. data/rubocop/cop/security/no_reflection_methods.rb +1 -1
  126. data/swarm_cli.gemspec +1 -1
  127. data/swarm_memory.gemspec +8 -3
  128. data/swarm_sdk.gemspec +6 -4
  129. data/team_full.yml +124 -320
  130. metadata +42 -14
  131. data/lib/swarm_memory/chat_extension.rb +0 -34
  132. data/lib/swarm_memory/tools/memory_multi_edit.rb +0 -281
  133. data/lib/swarm_sdk/providers/openai_with_responses.rb +0 -589
  134. /data/lib/swarm_memory/{errors.rb → error.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b5d5d686096a33cf7a16511f728091f92e2bb33d9c5eeacdf430718a1a8548e
4
- data.tar.gz: 63e3445e6279abc98b4202b582cfc48a4e17b610339241ba0872532a61174697
3
+ metadata.gz: f29b35b5b6dadfd9638907704a3bc204ebd35ba3c7e95c4bfafb0ff7ed1f44ed
4
+ data.tar.gz: e6e005f4dc472961daaa02f094c8d044a76018628a0e7d07ea6ed55ab0d830b6
5
5
  SHA512:
6
- metadata.gz: 8521d7386607e3391915dfeb68f82ca9df8361566832724fe8e59357444137530a4b825e9c665f328a6157a0ee6a7202ad536409e59253d4f7fdb909482bc178
7
- data.tar.gz: c34358c386fac205277cab662b3041330b5006878520f8c8ae265a316bc239e71d396e5ed4ea77c897bc7bf5b465eddf810cb227be13ba189cc27169496e6d78
6
+ metadata.gz: 0bd8988be66a9514cc80732a5d66b52fc737f44f67b1949271230fbb083e3a8fcc95a515b1bc5fd2688b51449cc04e5e162c70f66de14531075f4f6606bd2002
7
+ data.tar.gz: 5aa8a44f9dc5bd935b380ab59654e2e382726a977ea404ebe8c20401df29536425f50619857ae87a6b3ee4674377b83fa3a211b73fc232bc2ff1ce7af61df128
@@ -1,3 +1,13 @@
1
+ ## [1.0.11]
2
+ - Fix: load prompt_file for main instance in orchestrator: https://github.com/parruda/swarm/pull/183
3
+
4
+ ## [1.0.10]
5
+
6
+ ### Changed
7
+ - **Simplified Claude MCP server configuration for non Anthropic models**: Removed environment variable filtering from `claude mcp serve` configuration
8
+ - Previously filtered out Ruby/Bundler environment variables to prevent contamination
9
+ - Now uses a clean, minimal configuration that relies on the Claude CLI's default environment handling
10
+
1
11
  ## [1.0.9]
2
12
 
3
13
  ### Added
data/CLAUDE.md CHANGED
@@ -4,15 +4,59 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4
4
 
5
5
  ## Overview
6
6
 
7
- 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).
7
+ This repository contains three integrated Ruby gems that work together to create collaborative AI agent systems:
8
8
 
9
- SwarmSDK is a complete reimagining of Claude Swarm that decouples from Claude Code and runs everything in a single process using RubyLLM for all LLM interactions. It is being developed in `lib/swarm_sdk`, and using the gemspec swarm-sdk.gemspec.
9
+ - **SwarmSDK** (`lib/swarm_sdk/`) - Core SDK for building multi-agent AI systems using RubyLLM
10
+ - **SwarmMemory** (`lib/swarm_memory/`) - Persistent memory system with semantic search for agents
11
+ - **SwarmCLI** (`lib/swarm_cli/`) - Modern command-line interface using TTY toolkit components
12
+
13
+ ### SwarmSDK
14
+
15
+ SwarmSDK is a single-process, lightweight framework for building collaborative AI agent systems. Key features:
16
+
17
+ - **Single Process**: All agents run in the same Ruby process using RubyLLM
18
+ - **Agent Delegation**: Agents can delegate tasks to specialized agents
19
+ - **Tool System**: Rich set of built-in tools (Read, Write, Edit, Bash, etc.)
20
+ - **Ruby DSL**: Clean, intuitive API for defining agent swarms
21
+ - **Event System**: Comprehensive event emission for monitoring and debugging
22
+ - **State Management**: Snapshot/restore for session persistence
23
+ - **Async Support**: Built on Async gem for efficient concurrent execution
24
+ - **MCP Integration**: Connect to external MCP servers via RubyLLM::MCP
25
+
26
+ ### SwarmMemory
27
+
28
+ SwarmMemory provides hierarchical persistent memory with semantic search capabilities:
29
+
30
+ - **Semantic Search**: Fast ONNX-based embeddings using Informers gem
31
+ - **Memory Tools**: MemoryWrite, MemoryRead, MemoryEdit, MemoryDelete, MemoryGrep, MemoryGlob
32
+ - **SDK Integration**: Seamlessly integrates with SwarmSDK through plugin system
33
+ - **Frontmatter Support**: Extract metadata from memory entries
34
+ - **Storage Abstraction**: Pluggable storage backends
35
+ - **Defragmentation**: Optimize memory storage over time
36
+
37
+ ### SwarmCLI
38
+
39
+ SwarmCLI provides a modern, user-friendly command-line interface:
40
+
41
+ - **Dual-Mode Support**: Interactive REPL and non-interactive automation
42
+ - **TTY Toolkit**: Rich terminal UI with Pastel styling, TTY::Spinner, TTY::Markdown
43
+ - **JSON Logging**: Structured logs for automation and scripting
44
+ - **Reline Integration**: Advanced line editing with history and completion
45
+ - **Configuration Management**: YAML-based swarm definitions
46
+ - **Memory Commands**: Full memory system integration (if swarm_memory installed)
10
47
 
11
48
  ## Development Commands
12
49
 
13
50
  ### Testing
51
+ NEVER RUN ALL TESTS WITH `bundle exec rake test`. Run tests for each component separately.
52
+
53
+ Each component has its own test suite:
54
+
14
55
  ```bash
15
- bundle exec rake test # Run the Minitest test suite
56
+ # Run specific component tests
57
+ bundle exec rake swarm_sdk:test # SwarmSDK tests
58
+ bundle exec rake swarm_memory:test # SwarmMemory tests
59
+ bundle exec rake swarm_cli:test # SwarmCLI tests
16
60
  ```
17
61
 
18
62
  **Important**: Tests should not generate any output to stdout or stderr. When writing tests:
@@ -33,196 +77,165 @@ end
33
77
  ```
34
78
 
35
79
  ### Linting
80
+
36
81
  ```bash
37
82
  bundle exec rubocop -A # Run RuboCop linter to auto fix problems
38
83
  ```
39
84
 
40
- ### Development Console
41
- ```bash
42
- bin/console # Start IRB session with gem loaded
43
- ```
85
+ ## Architecture
44
86
 
45
- ### Build & Release
46
- ```bash
47
- bundle exec rake install # Install gem locally
48
- bundle exec rake release # Release gem to RubyGems.org
49
- ```
87
+ ### SwarmSDK Architecture (`lib/swarm_sdk/`)
50
88
 
51
- ### Default Task
52
- ```bash
53
- rake # Runs both tests and RuboCop
54
- ```
89
+ **Core Components:**
55
90
 
56
- ## Git Worktree Support
91
+ - **Swarm** - Main orchestrator managing multiple agents with shared rate limiting
92
+ - **Agent::Definition** - Agent configuration and validation
93
+ - **Agent::Chat** - RubyLLM chat wrapper with tool execution and delegation
94
+ - **AgentInitializer** - Complex 5-pass agent setup with tool and MCP configuration
95
+ - **ToolConfigurator** - Tool creation, permissions, and delegation tool generation
96
+ - **McpConfigurator** - MCP client management and configuration
97
+ - **NodeOrchestrator** - Multi-node workflow execution with dependencies
57
98
 
58
- Claude Swarm supports launching instances in Git worktrees to isolate changes:
99
+ **Key Subsystems:**
59
100
 
60
- ### CLI Usage
61
- ```bash
62
- # Create worktrees with custom name
63
- claude-swarm --worktree feature-branch
101
+ - **Events**: LogStream + LogCollector for comprehensive event emission
102
+ - **Hooks**: Pre/post tool execution, swarm lifecycle hooks
103
+ - **State**: Snapshot/restore for session persistence
104
+ - **Tools**: 25+ built-in tools (Read, Write, Edit, Bash, Grep, Glob, etc.)
105
+ - **Plugins**: Extensible plugin system (SwarmMemory integrates via plugins)
64
106
 
65
- # Create worktrees with auto-generated name (worktree-SESSION_ID)
66
- claude-swarm --worktree
107
+ **User-Facing APIs:**
67
108
 
68
- # Short form
69
- claude-swarm -w feature-x
70
- ```
109
+ ```ruby
110
+ # Ruby DSL (Recommended)
111
+ swarm = SwarmSDK.build do
112
+ name "Development Team"
113
+ lead :backend
114
+
115
+ agent :backend do
116
+ model "claude-sonnet-4"
117
+ description "Backend developer"
118
+ prompt "You build APIs and databases"
119
+ tools :Read, :Edit, :Bash
120
+ delegates_to :database
121
+ end
122
+ end
71
123
 
72
- ### Per-Instance Configuration
73
- Instances can have individual worktree settings that override CLI behavior:
74
-
75
- ```yaml
76
- instances:
77
- main:
78
- worktree: true # Use shared worktree name (from CLI or auto-generated)
79
- testing:
80
- worktree: false # Don't use worktree for this instance
81
- feature:
82
- worktree: "feature-x" # Use specific worktree name
83
- default:
84
- # No worktree field - follows CLI behavior
124
+ result = swarm.execute("Build authentication system")
125
+
126
+ # YAML String API
127
+ yaml = File.read("swarm.yml")
128
+ swarm = SwarmSDK.load(yaml, base_dir: "/path/to/project")
129
+
130
+ # YAML File API (Convenience)
131
+ swarm = SwarmSDK.load_file("swarm.yml")
85
132
  ```
86
133
 
87
- ### Worktree Behavior
88
- - Worktrees are created in external directory: `~/.claude-swarm/worktrees/[session_id]/[repo_name-hash]/[worktree_name]`
89
- - This ensures proper isolation from the main repository and avoids conflicts with bundler and other tools
90
- - Each unique Git repository gets its own worktree with the same name
91
- - All instance directories are mapped to their worktree equivalents
92
- - Worktrees are automatically cleaned up when the swarm exits
93
- - Session metadata tracks worktree information for restoration
94
- - Non-Git directories are used as-is without creating worktrees
95
- - Existing worktrees with the same name are reused
96
- - The `claude-swarm clean` command removes orphaned worktrees
134
+ ### SwarmMemory Architecture (`lib/swarm_memory/`)
97
135
 
98
- ## Claude Code SDK Integration
136
+ **Core Components:**
99
137
 
100
- Claude Swarm uses the Claude Code SDK (`claude-code-sdk-ruby`) for all Claude instances. This provides:
101
- - Better performance and reliability
102
- - Structured message handling
103
- - Improved error recovery
104
- - Direct MCP server configuration support (stdio, sse, http)
138
+ - **Core::Storage** - Hierarchical file-based storage with frontmatter
139
+ - **Core::Index** - FAISS-based semantic search index
140
+ - **Core::Embedder** - ONNX embeddings via Informers gem
141
+ - **Tools::Memory*** - Memory manipulation tools (Write, Read, Edit, Delete, etc.)
142
+ - **Integration::SDKPlugin** - SwarmSDK plugin for seamless integration
105
143
 
106
- The SDK executor handles all three MCP server types and properly converts MCP JSON configurations to SDK format.
144
+ **Memory Tools:**
107
145
 
108
- ## Architecture
146
+ - **MemoryWrite** - Create/update memory entries with semantic indexing
147
+ - **MemoryRead** - Retrieve memory entries with optional semantic search
148
+ - **MemoryEdit** - Edit specific memory entries
149
+ - **MemoryDelete** - Remove memory entries
150
+ - **MemoryGrep** - Search memory content with regex
151
+ - **MemoryGlob** - Find memory entries by pattern
152
+ - **MemoryDefrag** - Optimize storage and rebuild indices
109
153
 
110
- The gem is fully implemented with the following components:
111
-
112
- ### Core Classes
113
-
114
- - **ClaudeSwarm::CLI** (`lib/claude_swarm/cli.rb`): Thor-based CLI that handles command parsing and orchestration
115
- - **ClaudeSwarm::Configuration** (`lib/claude_swarm/configuration.rb`): YAML parser and validator for swarm configurations
116
- - **ClaudeSwarm::McpGenerator** (`lib/claude_swarm/mcp_generator.rb`): Generates MCP JSON configurations for each instance
117
- - **ClaudeSwarm::Orchestrator** (`lib/claude_swarm/orchestrator.rb`): Launches the main Claude instance with proper configuration
118
- - **ClaudeSwarm::WorktreeManager** (`lib/claude_swarm/worktree_manager.rb`): Manages Git worktrees for isolated development
119
-
120
- ### Key Features
121
-
122
- 1. **YAML Configuration**: Define swarms with instances, connections, tools, and MCP servers
123
- 2. **Inter-Instance Communication**: Instances connect via MCP using `claude mcp serve` with `-p` flag
124
- 3. **Tool Restrictions**: Support for tool restrictions using Claude's native pattern (connections are available as `mcp__instance_name`)
125
- 4. **Multiple MCP Types**: Supports both stdio and SSE MCP server types
126
- 5. **Automatic MCP Generation**: Creates `.claude-swarm/` directory with MCP configs
127
- 6. **Custom System Prompts**: Each instance can have a custom prompt via `--append-system-prompt`
128
- 7. **Git Worktree Support**: Run instances in isolated Git worktrees with per-instance configuration
129
-
130
- ### How It Works
131
-
132
- 1. User creates a `claude-swarm.yml` file defining the swarm topology
133
- 2. Running `claude-swarm` parses the configuration and validates it
134
- 3. MCP configuration files are generated for each instance in a session directory
135
- 4. Settings files (with hooks) are generated for each instance if hooks are configured
136
- 5. The main instance is launched with `exec`, replacing the current process
137
- 6. Connected instances are available as MCP servers to the main instance
138
- 7. When an instance has connections, those connections are automatically added to its allowed tools as `mcp__<connection_name>`
139
-
140
- ### Configuration Example
141
-
142
- ```yaml
143
- version: 1
144
- swarm:
145
- name: "Dev Team"
146
- main: lead
147
- instances:
148
- lead:
149
- description: "Lead developer coordinating the team"
150
- directory: .
151
- model: opus
152
- connections: [frontend, backend]
153
- prompt: "You are the lead developer coordinating the team"
154
- tools: [Read, Edit, Bash]
155
- worktree: true # Optional: use worktree for this instance
156
- frontend:
157
- description: "Frontend developer specializing in React"
158
- directory: ./frontend
159
- model: sonnet
160
- prompt: "You specialize in frontend development with React"
161
- tools: [Edit, Write, Bash]
162
- worktree: false # Optional: disable worktree for this instance
163
- ```
154
+ **Integration:**
164
155
 
165
- ### Hooks Support
166
-
167
- Claude Swarm supports configuring [Claude Code hooks](https://docs.anthropic.com/en/docs/claude-code/hooks) for each instance. This allows you to run custom scripts before/after tools, on prompt submission, and more.
168
-
169
- #### Configuration Example with Hooks
170
-
171
- ```yaml
172
- version: 1
173
- swarm:
174
- name: "Dev Team"
175
- main: lead
176
- instances:
177
- lead:
178
- description: "Lead developer"
179
- directory: .
180
- model: opus
181
- # Hooks configuration follows Claude Code's format exactly
182
- hooks:
183
- PreToolUse:
184
- - matcher: "Write|Edit"
185
- hooks:
186
- - type: "command"
187
- command: "$CLAUDE_PROJECT_DIR/.claude/hooks/validate-code.py"
188
- timeout: 10
189
- PostToolUse:
190
- - matcher: "Bash"
191
- hooks:
192
- - type: "command"
193
- command: "echo 'Command executed by lead' >> /tmp/lead.log"
194
- UserPromptSubmit:
195
- - hooks:
196
- - type: "command"
197
- command: "$CLAUDE_PROJECT_DIR/.claude/hooks/add-context.py"
198
- frontend:
199
- description: "Frontend developer"
200
- directory: ./frontend
201
- hooks:
202
- PreToolUse:
203
- - matcher: "Write"
204
- hooks:
205
- - type: "command"
206
- command: "npm run lint"
156
+ ```ruby
157
+ # Enable memory for an agent
158
+ SwarmSDK.build do
159
+ agent :researcher do
160
+ model "claude-sonnet-4"
161
+ memory do
162
+ directory("tmp/memory/corpus")
163
+ mode(:researcher)
164
+ end
165
+ end
166
+ end
207
167
  ```
208
168
 
209
- The hooks configuration is passed directly to Claude Code via a generated settings.json file in the session directory. Each instance gets its own settings file with its specific hooks.
169
+ ### SwarmCLI Architecture (`lib/swarm_cli/`)
210
170
 
211
- ## Testing
171
+ **Core Components:**
212
172
 
213
- The gem includes comprehensive tests covering:
214
- - Configuration parsing and validation
215
- - MCP generation logic with connections
216
- - Error handling scenarios
217
- - CLI command functionality
218
- - Session restoration
219
- - Vibe mode behavior
220
- - Worktree management and per-instance configuration
173
+ - **Commands::Run** - Main command for executing swarms
174
+ - **InteractiveREPL** - Interactive mode with Reline
175
+ - **UI::EventRenderer** - Event formatting and display
176
+ - **UI::Formatters** - TTY-based output formatting
177
+ - **ConfigLoader** - YAML configuration parsing
221
178
 
222
- ## Dependencies
179
+ **Key Features:**
180
+
181
+ - **Non-Interactive Mode**: JSON structured logs for automation
182
+ - **Interactive Mode**: Rich terminal UI with colors, spinners, trees
183
+ - **Event Streaming**: Real-time display of agent actions
184
+ - **Configuration**: YAML-based swarm definitions
185
+ - **Reline Integration**: Advanced input editing with history
186
+
187
+ ## Code Separation
188
+
189
+ **CRITICAL**: The three components are completely separate:
190
+
191
+ - **SwarmSDK**: Core SDK functionality in `lib/swarm_sdk/` and `lib/swarm_sdk.rb`
192
+ - **SwarmMemory**: Memory system in `lib/swarm_memory/` and `lib/swarm_memory.rb`
193
+ - **SwarmCLI**: CLI interface in `lib/swarm_cli/` and `lib/swarm_cli.rb`
194
+
195
+ **NEVER mix SDK, Memory, and CLI code** - they are separate gems with distinct concerns:
196
+ - SDK provides the programmatic API
197
+ - Memory provides persistent storage with semantic search
198
+ - CLI provides the command-line interface
223
199
 
224
- - **thor** (~> 1.3): Command-line interface framework
225
- - **yaml**: Built-in Ruby YAML parser (no explicit dependency needed)
200
+ ## Testing Guidelines
201
+
202
+ ### Component-Specific Tests
203
+
204
+ - **SwarmSDK**: `test/swarm_sdk/**/*_test.rb`
205
+ - **SwarmMemory**: `test/swarm_memory/**/*_test.rb`
206
+ - **SwarmCLI**: `test/swarm_cli/**/*_test.rb`
207
+
208
+ ### Best Practices
209
+
210
+ 1. **Isolation**: Each component's tests should not depend on others
211
+ 2. **Mocking**: Mock external dependencies (LLM API calls, file system, etc.)
212
+ 3. **Cleanup**: Always clean up test artifacts (temp files, directories)
213
+ 4. **No Output**: Tests should be silent (capture stdout/stderr)
214
+ 5. **Fast**: Unit tests should be fast; integration tests can be slower
215
+
216
+ ### Example Test Structure
217
+
218
+ ```ruby
219
+ require "test_helper"
220
+
221
+ class SwarmSDK::MyFeatureTest < Minitest::Test
222
+ def setup
223
+ @swarm = SwarmSDK::Swarm.new(name: "Test Swarm")
224
+ end
225
+
226
+ def teardown
227
+ @swarm.cleanup if @swarm
228
+ end
229
+
230
+ def test_feature_works
231
+ # Suppress output
232
+ _out, _err = capture_io do
233
+ result = @swarm.execute("test prompt")
234
+ assert result.success?
235
+ end
236
+ end
237
+ end
238
+ ```
226
239
 
227
240
  ## Zeitwerk Autoloading
228
241
 
@@ -230,40 +243,182 @@ This project uses Zeitwerk for automatic class loading. Important guidelines:
230
243
 
231
244
  ### Require Statement Rules
232
245
 
233
- 1. **DO NOT include any require statements for lib files**: Zeitwerk automatically loads all classes under `lib/claude_swarm/`. Never use `require`, `require_relative`, or `require "claude_swarm/..."` for internal project files.
246
+ 1. **DO NOT include any require statements for lib files**: Zeitwerk automatically loads all classes. Never use `require`, `require_relative`, or `require "swarm_sdk/..."` for internal project files.
234
247
 
235
- 2. **All dependencies must be consolidated in lib/claude_swarm.rb**: Both standard library and external gem dependencies are required at the top of `lib/claude_swarm.rb`. This includes:
236
- - Standard library dependencies (json, yaml, fileutils, etc.)
237
- - External gem dependencies (thor, openai, mcp_client, fast_mcp_annotations)
248
+ 2. **All dependencies must be consolidated in the main file**:
249
+ - `lib/swarm_sdk.rb` - SDK dependencies
250
+ - `lib/swarm_memory.rb` - Memory dependencies
251
+ - `lib/swarm_cli.rb` - CLI dependencies
238
252
 
239
- 3. **No requires in other lib files**: Individual files in `lib/claude_swarm/` should not have any require statements. They rely on:
240
- - Dependencies loaded in `lib/claude_swarm.rb`
253
+ 3. **No requires in other lib files**: Individual files should not have any require statements. They rely on:
254
+ - Dependencies loaded in the main file
241
255
  - Other classes autoloaded by Zeitwerk
242
256
 
243
257
  ### Example
244
258
 
245
259
  ```ruby
246
- # ✅ CORRECT - lib/claude_swarm.rb
247
- # Standard library dependencies
248
- require "json"
249
- require "yaml"
250
- require "fileutils"
251
- # ... other standard libraries
252
-
253
- # External dependencies
254
- require "thor"
255
- require "openai"
256
- # ... other gems
257
-
258
- # Zeitwerk setup
260
+ # ✅ CORRECT - lib/swarm_sdk.rb
261
+ require "async"
262
+ require "ruby_llm"
259
263
  require "zeitwerk"
260
- loader = Zeitwerk::Loader.for_gem
264
+ loader = Zeitwerk::Loader.new
261
265
  loader.setup
262
266
 
263
- # ❌ INCORRECT - lib/claude_swarm/some_class.rb
264
- require "json" # Don't do this!
267
+ # ❌ INCORRECT - lib/swarm_sdk/some_class.rb
268
+ require "async" # Don't do this!
265
269
  require_relative "other_class" # Don't do this!
266
- require "claude_swarm/configuration" # Don't do this!
270
+ require "swarm_sdk/configuration" # Don't do this!
267
271
  ```
268
272
 
269
- This approach ensures clean dependency management and leverages Ruby's modern autoloading capabilities.
273
+ ## Development Guidelines
274
+
275
+ **Code Quality:**
276
+ - Write PROFESSIONAL, CLEAN, MAINTAINABLE, TESTABLE code
277
+ - NEVER mix SDK, Memory, and CLI code
278
+ - NEVER call private methods from outside a class
279
+ - NEVER use `send`, `instance_variable_get`, or `instance_variable_set`
280
+ - DO NOT create methods only for testing - write production testable code
281
+
282
+ **Architecture:**
283
+ - Keep concerns separated (SDK = API, Memory = Storage, CLI = Interface)
284
+ - Use dependency injection for testability
285
+ - Follow Ruby idioms and conventions
286
+ - Document public APIs with YARD comments
287
+
288
+ **Testing:**
289
+ - Write tests for new features
290
+ - Maintain test coverage
291
+ - Tests should be fast and isolated
292
+ - No stdout/stderr output in tests
293
+
294
+ ## Ruby Documentation Standards
295
+
296
+ ### YARD Documentation Requirements
297
+
298
+ All Ruby code MUST include comprehensive YARD documentation. Follow these rules:
299
+
300
+ #### Required for ALL Public Methods:
301
+ - `@param` for each parameter with type annotation
302
+ - `@return` with type annotation (use multiple if different return types possible)
303
+ - `@raise` for any exceptions that may be raised
304
+ - At least one `@example` showing typical usage
305
+ - `@note` for important behavioral details or side effects
306
+
307
+ #### Required for Complex Methods:
308
+ - `@option` for each hash option parameter
309
+ - Multiple `@example` blocks showing different use cases
310
+ - `@see` links to related methods
311
+ - Performance considerations if relevant
312
+
313
+ #### Method Documentation Template:
314
+ ```ruby
315
+ # Brief one-line description
316
+ #
317
+ # Optional longer description explaining the method's purpose,
318
+ # important details, or context.
319
+ #
320
+ # @param name [Type] description
321
+ # @param options [Hash] optional parameters
322
+ # @option options [Type] :key description
323
+ #
324
+ # @return [Type] description of return value
325
+ # @raise [ExceptionType] when this exception occurs
326
+ #
327
+ # @example Basic usage
328
+ # code_example
329
+ #
330
+ # @example Advanced usage
331
+ # code_example
332
+ #
333
+ # @note Important behavioral detail
334
+ # @see #related_method
335
+ def method_name(name, options = {})
336
+ end
337
+ ```
338
+
339
+ ## Key Concepts
340
+
341
+ ### SwarmSDK Concepts
342
+
343
+ **Agents**: AI agents with specific roles, tools, and capabilities
344
+ **Delegation**: Agents can delegate tasks to other specialized agents
345
+ **Tools**: Built-in and custom tools for agent capabilities
346
+ **Events**: Comprehensive logging and monitoring system
347
+ **Hooks**: Lifecycle hooks for pre/post tool execution
348
+ **State**: Snapshot/restore for session persistence
349
+
350
+ ### SwarmMemory Concepts
351
+
352
+ **Memory Entries**: Markdown files with frontmatter metadata
353
+ **Semantic Search**: ONNX-based embeddings for similarity search
354
+ **Storage**: Hierarchical file-based storage
355
+ **Index**: FAISS index for fast nearest-neighbor search
356
+ **Tools**: Memory manipulation tools integrated with SDK
357
+
358
+ ### SwarmCLI Concepts
359
+
360
+ **Interactive Mode**: REPL with rich terminal UI
361
+ **Non-Interactive Mode**: Automation-friendly JSON output
362
+ **Configuration**: YAML-based swarm definitions
363
+ **Event Rendering**: Real-time display of agent actions
364
+
365
+ ## Dependencies
366
+
367
+ ### SwarmSDK
368
+ - `async` (~> 2.0) - Concurrent execution
369
+ - `ruby_llm` (~> 1.9) - LLM interactions
370
+ - `ruby_llm-mcp` (~> 0.7) - MCP client support
371
+ - `zeitwerk` (~> 2.6) - Autoloading
372
+
373
+ ### SwarmMemory
374
+ - `async` (~> 2.0) - Concurrent execution
375
+ - `informers` (~> 1.2.1) - ONNX embeddings for semantic search
376
+ - `rice` (~> 4.6.0) - Ruby C extension binding (for FAISS)
377
+ - `ruby_llm` (~> 1.9) - LLM interactions
378
+ - `swarm_sdk` (~> 2.2) - Core SDK integration
379
+ - `zeitwerk` (~> 2.6) - Autoloading
380
+
381
+ ### SwarmCLI
382
+ - `fast-mcp` (~> 1.6) - MCP server support for CLI
383
+ - `pastel` - Terminal text styling and colors
384
+ - `swarm_sdk` (~> 2.2) - Core SDK
385
+ - `tty-box` - Drawing boxes and frames
386
+ - `tty-cursor` - Terminal cursor control
387
+ - `tty-link` - Hyperlink support
388
+ - `tty-markdown` - Markdown rendering
389
+ - `tty-option` - Command-line option parsing
390
+ - `tty-spinner` - Progress indicators
391
+ - `tty-tree` - Tree structure rendering
392
+ - `zeitwerk` - Autoloading
393
+ - `reline` - Line editing (Ruby stdlib, no gem dependency)
394
+
395
+ **Document parsing tools (for Read tool):**
396
+ - `csv` - CSV file parsing
397
+ - `docx` (~> 0.10) - Word document parsing
398
+ - `pdf-reader` (~> 2.15) - PDF parsing
399
+ - `reverse_markdown` (~> 3.0.0) - HTML to Markdown conversion
400
+ - `roo` (~> 3.0.0) - Spreadsheet parsing (xlsx, xlsm, ods)
401
+
402
+ ## Additional Resources
403
+
404
+ - **SwarmSDK Documentation**: See `docs/v2/` for comprehensive guides
405
+ - **SwarmMemory Documentation**: See `docs/memory/` for memory system details
406
+ - **SwarmCLI Documentation**: See `docs/cli/` for CLI usage and configuration
407
+ - **RubyLLM Documentation**: ~/src/github.com/crmne/ruby_llm
408
+ - **Async Documentation**: ~/src/github.com/socketry/async
409
+
410
+ ## Notes for Claude Code
411
+
412
+ When working with this codebase:
413
+
414
+ 1. **Always check which component** you're working with (SDK, Memory, or CLI)
415
+ 2. **Never cross boundaries** between components unless through public APIs
416
+ 3. **Run component-specific tests** after making changes
417
+ 4. **Follow Zeitwerk rules** - no require statements in lib files
418
+ 5. **Maintain code quality** - professional, clean, testable code
419
+ 6. **Suppress test output** - use capture_io for silent tests
420
+ 7. **Document public APIs** - use YARD comments for public methods
421
+
422
+ This is an open-source project - code should be exemplary and well-documented.
423
+
424
+ When making plans, do not include time-based effort estimates.