claude_swarm 1.0.8 → 1.0.10

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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/CLAUDE.md +347 -191
  4. data/docs/v1/README.md +10 -0
  5. data/docs/v2/CHANGELOG.swarm_cli.md +8 -0
  6. data/docs/v2/CHANGELOG.swarm_memory.md +7 -1
  7. data/docs/v2/CHANGELOG.swarm_sdk.md +184 -9
  8. data/docs/v2/README.md +6 -1
  9. data/docs/v2/guides/complete-tutorial.md +2 -2
  10. data/docs/v2/guides/getting-started.md +7 -7
  11. data/docs/v2/guides/migrating-to-2.3.md +541 -0
  12. data/docs/v2/guides/snapshots.md +14 -14
  13. data/docs/v2/reference/architecture-flow.md +3 -3
  14. data/docs/v2/reference/event_payload_structures.md +1 -1
  15. data/docs/v2/reference/ruby-dsl.md +157 -14
  16. data/docs/v2/reference/yaml.md +170 -52
  17. data/examples/snapshot_demo.rb +2 -2
  18. data/lib/claude_swarm/claude_mcp_server.rb +1 -0
  19. data/lib/claude_swarm/cli.rb +5 -0
  20. data/lib/claude_swarm/configuration.rb +2 -1
  21. data/lib/claude_swarm/mcp_generator.rb +8 -20
  22. data/lib/claude_swarm/openai/chat_completion.rb +2 -1
  23. data/lib/claude_swarm/openai/executor.rb +3 -1
  24. data/lib/claude_swarm/openai/responses.rb +11 -21
  25. data/lib/claude_swarm/version.rb +1 -1
  26. data/lib/swarm_cli/commands/run.rb +2 -2
  27. data/lib/swarm_cli/config_loader.rb +11 -11
  28. data/lib/swarm_cli/formatters/human_formatter.rb +0 -33
  29. data/lib/swarm_cli/interactive_repl.rb +2 -2
  30. data/lib/swarm_cli/ui/icons.rb +0 -23
  31. data/lib/swarm_cli/version.rb +1 -1
  32. data/lib/swarm_memory/adapters/filesystem_adapter.rb +11 -34
  33. data/lib/swarm_memory/integration/sdk_plugin.rb +87 -7
  34. data/lib/swarm_memory/version.rb +1 -1
  35. data/lib/swarm_memory.rb +1 -1
  36. data/lib/swarm_sdk/agent/builder.rb +58 -0
  37. data/lib/swarm_sdk/agent/chat.rb +527 -1061
  38. data/lib/swarm_sdk/agent/{chat → chat_helpers}/context_tracker.rb +9 -88
  39. data/lib/swarm_sdk/agent/chat_helpers/event_emitter.rb +204 -0
  40. data/lib/swarm_sdk/agent/{chat → chat_helpers}/hook_integration.rb +108 -46
  41. data/lib/swarm_sdk/agent/chat_helpers/instrumentation.rb +78 -0
  42. data/lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb +233 -0
  43. data/lib/swarm_sdk/agent/{chat → chat_helpers}/logging_helpers.rb +1 -1
  44. data/lib/swarm_sdk/agent/chat_helpers/serialization.rb +83 -0
  45. data/lib/swarm_sdk/agent/{chat → chat_helpers}/system_reminder_injector.rb +12 -12
  46. data/lib/swarm_sdk/agent/chat_helpers/system_reminders.rb +79 -0
  47. data/lib/swarm_sdk/agent/chat_helpers/token_tracking.rb +98 -0
  48. data/lib/swarm_sdk/agent/context.rb +2 -2
  49. data/lib/swarm_sdk/agent/definition.rb +66 -154
  50. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +4 -2
  51. data/lib/swarm_sdk/agent/system_prompt_builder.rb +161 -0
  52. data/lib/swarm_sdk/builders/base_builder.rb +409 -0
  53. data/lib/swarm_sdk/concerns/cleanupable.rb +39 -0
  54. data/lib/swarm_sdk/concerns/snapshotable.rb +67 -0
  55. data/lib/swarm_sdk/concerns/validatable.rb +55 -0
  56. data/lib/swarm_sdk/configuration/parser.rb +353 -0
  57. data/lib/swarm_sdk/configuration/translator.rb +255 -0
  58. data/lib/swarm_sdk/configuration.rb +65 -543
  59. data/lib/swarm_sdk/context_compactor/token_counter.rb +3 -3
  60. data/lib/swarm_sdk/context_compactor.rb +6 -11
  61. data/lib/swarm_sdk/context_management/builder.rb +128 -0
  62. data/lib/swarm_sdk/context_management/context.rb +328 -0
  63. data/lib/swarm_sdk/defaults.rb +196 -0
  64. data/lib/swarm_sdk/events_to_messages.rb +18 -0
  65. data/lib/swarm_sdk/hooks/shell_executor.rb +2 -1
  66. data/lib/swarm_sdk/log_collector.rb +179 -29
  67. data/lib/swarm_sdk/log_stream.rb +29 -0
  68. data/lib/swarm_sdk/node_context.rb +1 -1
  69. data/lib/swarm_sdk/observer/builder.rb +81 -0
  70. data/lib/swarm_sdk/observer/config.rb +45 -0
  71. data/lib/swarm_sdk/observer/manager.rb +236 -0
  72. data/lib/swarm_sdk/patterns/agent_observer.rb +160 -0
  73. data/lib/swarm_sdk/plugin.rb +93 -3
  74. data/lib/swarm_sdk/snapshot.rb +6 -6
  75. data/lib/swarm_sdk/snapshot_from_events.rb +13 -2
  76. data/lib/swarm_sdk/state_restorer.rb +136 -151
  77. data/lib/swarm_sdk/state_snapshot.rb +65 -100
  78. data/lib/swarm_sdk/swarm/agent_initializer.rb +180 -136
  79. data/lib/swarm_sdk/swarm/builder.rb +44 -578
  80. data/lib/swarm_sdk/swarm/executor.rb +213 -0
  81. data/lib/swarm_sdk/swarm/hook_triggers.rb +150 -0
  82. data/lib/swarm_sdk/swarm/logging_callbacks.rb +340 -0
  83. data/lib/swarm_sdk/swarm/mcp_configurator.rb +7 -4
  84. data/lib/swarm_sdk/swarm/tool_configurator.rb +42 -138
  85. data/lib/swarm_sdk/swarm.rb +137 -680
  86. data/lib/swarm_sdk/tools/bash.rb +11 -3
  87. data/lib/swarm_sdk/tools/delegate.rb +61 -43
  88. data/lib/swarm_sdk/tools/edit.rb +8 -13
  89. data/lib/swarm_sdk/tools/glob.rb +9 -1
  90. data/lib/swarm_sdk/tools/grep.rb +7 -0
  91. data/lib/swarm_sdk/tools/multi_edit.rb +15 -11
  92. data/lib/swarm_sdk/tools/path_resolver.rb +51 -2
  93. data/lib/swarm_sdk/tools/read.rb +11 -13
  94. data/lib/swarm_sdk/tools/registry.rb +122 -10
  95. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +8 -5
  96. data/lib/swarm_sdk/tools/stores/storage.rb +0 -6
  97. data/lib/swarm_sdk/tools/todo_write.rb +7 -0
  98. data/lib/swarm_sdk/tools/web_fetch.rb +3 -2
  99. data/lib/swarm_sdk/tools/write.rb +8 -13
  100. data/lib/swarm_sdk/version.rb +1 -1
  101. data/lib/swarm_sdk/{node → workflow}/agent_config.rb +1 -1
  102. data/lib/swarm_sdk/workflow/builder.rb +143 -0
  103. data/lib/swarm_sdk/workflow/executor.rb +497 -0
  104. data/lib/swarm_sdk/{node/builder.rb → workflow/node_builder.rb} +3 -3
  105. data/lib/swarm_sdk/{node → workflow}/transformer_executor.rb +3 -2
  106. data/lib/swarm_sdk/{node_orchestrator.rb → workflow.rb} +152 -456
  107. data/lib/swarm_sdk.rb +33 -3
  108. data/rubocop/cop/security/no_reflection_methods.rb +1 -1
  109. data/swarm_memory.gemspec +1 -1
  110. data/swarm_sdk.gemspec +4 -2
  111. data/team_full.yml +24 -24
  112. metadata +35 -11
  113. data/lib/swarm_memory/chat_extension.rb +0 -34
  114. data/lib/swarm_sdk/providers/openai_with_responses.rb +0 -589
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb4d46c1724d7488d304465b03250af098e1db3c2f73005cdb48c1092920628f
4
- data.tar.gz: '031668b2d8abfcddf0fae98e14364259c7a8d66bbb201a67eba7a58063203a7a'
3
+ metadata.gz: 7137a9b3f3fd37de3a81a9b3f4b1b6fe5b3173248284f4c6ce0af628f2f140cd
4
+ data.tar.gz: 447a2c03a49e23e2ba1750d05922b84e95df7bebfd5dbeacc3331cefa6882b8e
5
5
  SHA512:
6
- metadata.gz: b1187c0f7a3f73d65832e83236a4c17967835bd70764fd782111e4b80fe20ad61c9dd0ab7c4c3bec755df387e1221597695302a05c3044dca427b08c40da7a1a
7
- data.tar.gz: b5242fd046e72ced817feab59b628d8013c8b674ddee698b99f32a87936acc5a470d007a16dcdbea0a75656a238099380aa261022fa5e75be08b8c0b51e9d5a2
6
+ metadata.gz: d8bd44b19b45e5482d141520c84589a08b646bfa2691b48d233e2c844745d1084081e16e23971a71f71bda796c85c3e6a599be33bbf839b2bc2d8d626b8a3cf1
7
+ data.tar.gz: 2600e70853d9d590075c3c172e3bea65a75795d0a667ab4dffa8361c6bc3a4d829643ac64eac42f2fb260639759326ab5af00d36cda2538634f4d0656ca94628
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## [1.0.10]
2
+
3
+ ### Changed
4
+ - **Simplified Claude MCP server configuration for non Anthropic models**: Removed environment variable filtering from `claude mcp serve` configuration
5
+ - Previously filtered out Ruby/Bundler environment variables to prevent contamination
6
+ - Now uses a clean, minimal configuration that relies on the Claude CLI's default environment handling
7
+
8
+ ## [1.0.9]
9
+
10
+ ### Added
11
+ - **Zero Data Retention (ZDR) support for OpenAI Responses API**: Added ZDR mode to disable conversation continuity for privacy-focused use cases
12
+ - New `zdr` configuration parameter (boolean) that can be set in YAML configuration files
13
+ - When enabled, sets `previous_response_id` to nil, ensuring each API call is independent
14
+ - Supported in Configuration, CLI (`--zdr` flag), and MCP generator
15
+
1
16
  ## [1.0.8]
2
17
 
3
18
  ### Changed
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,166 @@ 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
+ - **MemoryMultiEdit** - Batch edit multiple entries
150
+ - **MemoryDelete** - Remove memory entries
151
+ - **MemoryGrep** - Search memory content with regex
152
+ - **MemoryGlob** - Find memory entries by pattern
153
+ - **MemoryDefrag** - Optimize storage and rebuild indices
109
154
 
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
- ```
155
+ **Integration:**
164
156
 
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"
157
+ ```ruby
158
+ # Enable memory for an agent
159
+ SwarmSDK.build do
160
+ agent :researcher do
161
+ model "claude-sonnet-4"
162
+ memory do
163
+ directory("tmp/memory/corpus")
164
+ mode(:researcher)
165
+ end
166
+ end
167
+ end
207
168
  ```
208
169
 
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.
170
+ ### SwarmCLI Architecture (`lib/swarm_cli/`)
210
171
 
211
- ## Testing
172
+ **Core Components:**
212
173
 
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
174
+ - **Commands::Run** - Main command for executing swarms
175
+ - **InteractiveREPL** - Interactive mode with Reline
176
+ - **UI::EventRenderer** - Event formatting and display
177
+ - **UI::Formatters** - TTY-based output formatting
178
+ - **ConfigLoader** - YAML configuration parsing
221
179
 
222
- ## Dependencies
180
+ **Key Features:**
181
+
182
+ - **Non-Interactive Mode**: JSON structured logs for automation
183
+ - **Interactive Mode**: Rich terminal UI with colors, spinners, trees
184
+ - **Event Streaming**: Real-time display of agent actions
185
+ - **Configuration**: YAML-based swarm definitions
186
+ - **Reline Integration**: Advanced input editing with history
187
+
188
+ ## Code Separation
189
+
190
+ **CRITICAL**: The three components are completely separate:
191
+
192
+ - **SwarmSDK**: Core SDK functionality in `lib/swarm_sdk/` and `lib/swarm_sdk.rb`
193
+ - **SwarmMemory**: Memory system in `lib/swarm_memory/` and `lib/swarm_memory.rb`
194
+ - **SwarmCLI**: CLI interface in `lib/swarm_cli/` and `lib/swarm_cli.rb`
195
+
196
+ **NEVER mix SDK, Memory, and CLI code** - they are separate gems with distinct concerns:
197
+ - SDK provides the programmatic API
198
+ - Memory provides persistent storage with semantic search
199
+ - CLI provides the command-line interface
223
200
 
224
- - **thor** (~> 1.3): Command-line interface framework
225
- - **yaml**: Built-in Ruby YAML parser (no explicit dependency needed)
201
+ ## Testing Guidelines
202
+
203
+ ### Component-Specific Tests
204
+
205
+ - **SwarmSDK**: `test/swarm_sdk/**/*_test.rb`
206
+ - **SwarmMemory**: `test/swarm_memory/**/*_test.rb`
207
+ - **SwarmCLI**: `test/swarm_cli/**/*_test.rb`
208
+
209
+ ### Best Practices
210
+
211
+ 1. **Isolation**: Each component's tests should not depend on others
212
+ 2. **Mocking**: Mock external dependencies (LLM API calls, file system, etc.)
213
+ 3. **Cleanup**: Always clean up test artifacts (temp files, directories)
214
+ 4. **No Output**: Tests should be silent (capture stdout/stderr)
215
+ 5. **Fast**: Unit tests should be fast; integration tests can be slower
216
+
217
+ ### Example Test Structure
218
+
219
+ ```ruby
220
+ require "test_helper"
221
+
222
+ class SwarmSDK::MyFeatureTest < Minitest::Test
223
+ def setup
224
+ @swarm = SwarmSDK::Swarm.new(name: "Test Swarm")
225
+ end
226
+
227
+ def teardown
228
+ @swarm.cleanup if @swarm
229
+ end
230
+
231
+ def test_feature_works
232
+ # Suppress output
233
+ _out, _err = capture_io do
234
+ result = @swarm.execute("test prompt")
235
+ assert result.success?
236
+ end
237
+ end
238
+ end
239
+ ```
226
240
 
227
241
  ## Zeitwerk Autoloading
228
242
 
@@ -230,40 +244,182 @@ This project uses Zeitwerk for automatic class loading. Important guidelines:
230
244
 
231
245
  ### Require Statement Rules
232
246
 
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.
247
+ 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
248
 
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)
249
+ 2. **All dependencies must be consolidated in the main file**:
250
+ - `lib/swarm_sdk.rb` - SDK dependencies
251
+ - `lib/swarm_memory.rb` - Memory dependencies
252
+ - `lib/swarm_cli.rb` - CLI dependencies
238
253
 
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`
254
+ 3. **No requires in other lib files**: Individual files should not have any require statements. They rely on:
255
+ - Dependencies loaded in the main file
241
256
  - Other classes autoloaded by Zeitwerk
242
257
 
243
258
  ### Example
244
259
 
245
260
  ```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
261
+ # ✅ CORRECT - lib/swarm_sdk.rb
262
+ require "async"
263
+ require "ruby_llm"
259
264
  require "zeitwerk"
260
- loader = Zeitwerk::Loader.for_gem
265
+ loader = Zeitwerk::Loader.new
261
266
  loader.setup
262
267
 
263
- # ❌ INCORRECT - lib/claude_swarm/some_class.rb
264
- require "json" # Don't do this!
268
+ # ❌ INCORRECT - lib/swarm_sdk/some_class.rb
269
+ require "async" # Don't do this!
265
270
  require_relative "other_class" # Don't do this!
266
- require "claude_swarm/configuration" # Don't do this!
271
+ require "swarm_sdk/configuration" # Don't do this!
267
272
  ```
268
273
 
269
- This approach ensures clean dependency management and leverages Ruby's modern autoloading capabilities.
274
+ ## Development Guidelines
275
+
276
+ **Code Quality:**
277
+ - Write PROFESSIONAL, CLEAN, MAINTAINABLE, TESTABLE code
278
+ - NEVER mix SDK, Memory, and CLI code
279
+ - NEVER call private methods from outside a class
280
+ - NEVER use `send`, `instance_variable_get`, or `instance_variable_set`
281
+ - DO NOT create methods only for testing - write production testable code
282
+
283
+ **Architecture:**
284
+ - Keep concerns separated (SDK = API, Memory = Storage, CLI = Interface)
285
+ - Use dependency injection for testability
286
+ - Follow Ruby idioms and conventions
287
+ - Document public APIs with YARD comments
288
+
289
+ **Testing:**
290
+ - Write tests for new features
291
+ - Maintain test coverage
292
+ - Tests should be fast and isolated
293
+ - No stdout/stderr output in tests
294
+
295
+ ## Ruby Documentation Standards
296
+
297
+ ### YARD Documentation Requirements
298
+
299
+ All Ruby code MUST include comprehensive YARD documentation. Follow these rules:
300
+
301
+ #### Required for ALL Public Methods:
302
+ - `@param` for each parameter with type annotation
303
+ - `@return` with type annotation (use multiple if different return types possible)
304
+ - `@raise` for any exceptions that may be raised
305
+ - At least one `@example` showing typical usage
306
+ - `@note` for important behavioral details or side effects
307
+
308
+ #### Required for Complex Methods:
309
+ - `@option` for each hash option parameter
310
+ - Multiple `@example` blocks showing different use cases
311
+ - `@see` links to related methods
312
+ - Performance considerations if relevant
313
+
314
+ #### Method Documentation Template:
315
+ ```ruby
316
+ # Brief one-line description
317
+ #
318
+ # Optional longer description explaining the method's purpose,
319
+ # important details, or context.
320
+ #
321
+ # @param name [Type] description
322
+ # @param options [Hash] optional parameters
323
+ # @option options [Type] :key description
324
+ #
325
+ # @return [Type] description of return value
326
+ # @raise [ExceptionType] when this exception occurs
327
+ #
328
+ # @example Basic usage
329
+ # code_example
330
+ #
331
+ # @example Advanced usage
332
+ # code_example
333
+ #
334
+ # @note Important behavioral detail
335
+ # @see #related_method
336
+ def method_name(name, options = {})
337
+ end
338
+ ```
339
+
340
+ ## Key Concepts
341
+
342
+ ### SwarmSDK Concepts
343
+
344
+ **Agents**: AI agents with specific roles, tools, and capabilities
345
+ **Delegation**: Agents can delegate tasks to other specialized agents
346
+ **Tools**: Built-in and custom tools for agent capabilities
347
+ **Events**: Comprehensive logging and monitoring system
348
+ **Hooks**: Lifecycle hooks for pre/post tool execution
349
+ **State**: Snapshot/restore for session persistence
350
+
351
+ ### SwarmMemory Concepts
352
+
353
+ **Memory Entries**: Markdown files with frontmatter metadata
354
+ **Semantic Search**: ONNX-based embeddings for similarity search
355
+ **Storage**: Hierarchical file-based storage
356
+ **Index**: FAISS index for fast nearest-neighbor search
357
+ **Tools**: Memory manipulation tools integrated with SDK
358
+
359
+ ### SwarmCLI Concepts
360
+
361
+ **Interactive Mode**: REPL with rich terminal UI
362
+ **Non-Interactive Mode**: Automation-friendly JSON output
363
+ **Configuration**: YAML-based swarm definitions
364
+ **Event Rendering**: Real-time display of agent actions
365
+
366
+ ## Dependencies
367
+
368
+ ### SwarmSDK
369
+ - `async` (~> 2.0) - Concurrent execution
370
+ - `ruby_llm` (~> 1.9) - LLM interactions
371
+ - `ruby_llm-mcp` (~> 0.7) - MCP client support
372
+ - `zeitwerk` (~> 2.6) - Autoloading
373
+
374
+ ### SwarmMemory
375
+ - `async` (~> 2.0) - Concurrent execution
376
+ - `informers` (~> 1.2.1) - ONNX embeddings for semantic search
377
+ - `rice` (~> 4.6.0) - Ruby C extension binding (for FAISS)
378
+ - `ruby_llm` (~> 1.9) - LLM interactions
379
+ - `swarm_sdk` (~> 2.2) - Core SDK integration
380
+ - `zeitwerk` (~> 2.6) - Autoloading
381
+
382
+ ### SwarmCLI
383
+ - `fast-mcp` (~> 1.6) - MCP server support for CLI
384
+ - `pastel` - Terminal text styling and colors
385
+ - `swarm_sdk` (~> 2.2) - Core SDK
386
+ - `tty-box` - Drawing boxes and frames
387
+ - `tty-cursor` - Terminal cursor control
388
+ - `tty-link` - Hyperlink support
389
+ - `tty-markdown` - Markdown rendering
390
+ - `tty-option` - Command-line option parsing
391
+ - `tty-spinner` - Progress indicators
392
+ - `tty-tree` - Tree structure rendering
393
+ - `zeitwerk` - Autoloading
394
+ - `reline` - Line editing (Ruby stdlib, no gem dependency)
395
+
396
+ **Document parsing tools (for Read tool):**
397
+ - `csv` - CSV file parsing
398
+ - `docx` (~> 0.10) - Word document parsing
399
+ - `pdf-reader` (~> 2.15) - PDF parsing
400
+ - `reverse_markdown` (~> 3.0.0) - HTML to Markdown conversion
401
+ - `roo` (~> 3.0.0) - Spreadsheet parsing (xlsx, xlsm, ods)
402
+
403
+ ## Additional Resources
404
+
405
+ - **SwarmSDK Documentation**: See `docs/v2/` for comprehensive guides
406
+ - **SwarmMemory Documentation**: See `docs/memory/` for memory system details
407
+ - **SwarmCLI Documentation**: See `docs/cli/` for CLI usage and configuration
408
+ - **RubyLLM Documentation**: ~/src/github.com/crmne/ruby_llm
409
+ - **Async Documentation**: ~/src/github.com/socketry/async
410
+
411
+ ## Notes for Claude Code
412
+
413
+ When working with this codebase:
414
+
415
+ 1. **Always check which component** you're working with (SDK, Memory, or CLI)
416
+ 2. **Never cross boundaries** between components unless through public APIs
417
+ 3. **Run component-specific tests** after making changes
418
+ 4. **Follow Zeitwerk rules** - no require statements in lib files
419
+ 5. **Maintain code quality** - professional, clean, testable code
420
+ 6. **Suppress test output** - use capture_io for silent tests
421
+ 7. **Document public APIs** - use YARD comments for public methods
422
+
423
+ This is an open-source project - code should be exemplary and well-documented.
424
+
425
+ When making plans, do not include time-based effort estimates.
data/docs/v1/README.md CHANGED
@@ -372,6 +372,7 @@ When using `provider: openai`, the following additional fields are available:
372
372
  - **openai_token_env**: Environment variable name for OpenAI API key (default: "OPENAI_API_KEY")
373
373
  - **base_url**: Custom base URL for OpenAI API (optional)
374
374
  - **reasoning_effort**: Reasoning effort for O-series models only - "low", "medium", or "high"
375
+ - **zdr**: Zero Data Retention mode (boolean) - when set to `true`, disables conversation continuity by setting `previous_response_id` to nil (responses API only)
375
376
 
376
377
  **Important Notes:**
377
378
 
@@ -428,6 +429,15 @@ reasoning_instance:
428
429
  reasoning_effort: medium # Only for O-series models
429
430
  api_version: responses # Can use either API version
430
431
  prompt: "You are a reasoning assistant for complex problem solving"
432
+
433
+ # Instance with Zero Data Retention mode
434
+ zdr_instance:
435
+ description: "Privacy-focused assistant with no conversation memory"
436
+ provider: openai
437
+ model: gpt-4o
438
+ api_version: responses # ZDR only works with responses API
439
+ zdr: true # Disables conversation continuity
440
+ prompt: "You are a privacy-focused assistant that handles sensitive data"
431
441
  ```
432
442
 
433
443
  ### MCP Server Types
@@ -5,6 +5,14 @@ All notable changes to SwarmCLI will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.1.4]
9
+
10
+ ### Changed
11
+
12
+ - `ConfigLoader` now accepts both `SwarmSDK::Swarm` and `SwarmSDK::Workflow` instances from Ruby DSL files
13
+ - Updated error messages to reference `Workflow` instead of `NodeOrchestrator`
14
+ - Both swarms and workflows work seamlessly with CLI commands
15
+
8
16
  ## [2.1.3]
9
17
 
10
18
  ### Fixed