claude_swarm 1.0.9 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/CLAUDE.md +347 -191
- data/docs/v2/CHANGELOG.swarm_cli.md +8 -0
- data/docs/v2/CHANGELOG.swarm_memory.md +7 -1
- data/docs/v2/CHANGELOG.swarm_sdk.md +184 -9
- data/docs/v2/README.md +6 -1
- data/docs/v2/guides/complete-tutorial.md +2 -2
- data/docs/v2/guides/getting-started.md +7 -7
- data/docs/v2/guides/migrating-to-2.3.md +541 -0
- data/docs/v2/guides/snapshots.md +14 -14
- data/docs/v2/reference/architecture-flow.md +3 -3
- data/docs/v2/reference/event_payload_structures.md +1 -1
- data/docs/v2/reference/ruby-dsl.md +157 -14
- data/docs/v2/reference/yaml.md +170 -52
- data/examples/snapshot_demo.rb +2 -2
- data/lib/claude_swarm/mcp_generator.rb +7 -20
- data/lib/claude_swarm/version.rb +1 -1
- data/lib/swarm_cli/commands/run.rb +2 -2
- data/lib/swarm_cli/config_loader.rb +11 -11
- data/lib/swarm_cli/formatters/human_formatter.rb +0 -33
- data/lib/swarm_cli/interactive_repl.rb +2 -2
- data/lib/swarm_cli/ui/icons.rb +0 -23
- data/lib/swarm_cli/version.rb +1 -1
- data/lib/swarm_memory/adapters/filesystem_adapter.rb +11 -34
- data/lib/swarm_memory/integration/sdk_plugin.rb +87 -7
- data/lib/swarm_memory/version.rb +1 -1
- data/lib/swarm_memory.rb +1 -1
- data/lib/swarm_sdk/agent/builder.rb +58 -0
- data/lib/swarm_sdk/agent/chat.rb +527 -1061
- data/lib/swarm_sdk/agent/{chat → chat_helpers}/context_tracker.rb +9 -88
- data/lib/swarm_sdk/agent/chat_helpers/event_emitter.rb +204 -0
- data/lib/swarm_sdk/agent/{chat → chat_helpers}/hook_integration.rb +108 -46
- data/lib/swarm_sdk/agent/chat_helpers/instrumentation.rb +78 -0
- data/lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb +233 -0
- data/lib/swarm_sdk/agent/{chat → chat_helpers}/logging_helpers.rb +1 -1
- data/lib/swarm_sdk/agent/chat_helpers/serialization.rb +83 -0
- data/lib/swarm_sdk/agent/{chat → chat_helpers}/system_reminder_injector.rb +12 -12
- data/lib/swarm_sdk/agent/chat_helpers/system_reminders.rb +79 -0
- data/lib/swarm_sdk/agent/chat_helpers/token_tracking.rb +98 -0
- data/lib/swarm_sdk/agent/context.rb +2 -2
- data/lib/swarm_sdk/agent/definition.rb +66 -154
- data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +4 -2
- data/lib/swarm_sdk/agent/system_prompt_builder.rb +161 -0
- data/lib/swarm_sdk/builders/base_builder.rb +409 -0
- data/lib/swarm_sdk/concerns/cleanupable.rb +39 -0
- data/lib/swarm_sdk/concerns/snapshotable.rb +67 -0
- data/lib/swarm_sdk/concerns/validatable.rb +55 -0
- data/lib/swarm_sdk/configuration/parser.rb +353 -0
- data/lib/swarm_sdk/configuration/translator.rb +255 -0
- data/lib/swarm_sdk/configuration.rb +65 -543
- data/lib/swarm_sdk/context_compactor/token_counter.rb +3 -3
- data/lib/swarm_sdk/context_compactor.rb +6 -11
- data/lib/swarm_sdk/context_management/builder.rb +128 -0
- data/lib/swarm_sdk/context_management/context.rb +328 -0
- data/lib/swarm_sdk/defaults.rb +196 -0
- data/lib/swarm_sdk/events_to_messages.rb +18 -0
- data/lib/swarm_sdk/hooks/shell_executor.rb +2 -1
- data/lib/swarm_sdk/log_collector.rb +179 -29
- data/lib/swarm_sdk/log_stream.rb +29 -0
- data/lib/swarm_sdk/node_context.rb +1 -1
- data/lib/swarm_sdk/observer/builder.rb +81 -0
- data/lib/swarm_sdk/observer/config.rb +45 -0
- data/lib/swarm_sdk/observer/manager.rb +236 -0
- data/lib/swarm_sdk/patterns/agent_observer.rb +160 -0
- data/lib/swarm_sdk/plugin.rb +93 -3
- data/lib/swarm_sdk/snapshot.rb +6 -6
- data/lib/swarm_sdk/snapshot_from_events.rb +13 -2
- data/lib/swarm_sdk/state_restorer.rb +136 -151
- data/lib/swarm_sdk/state_snapshot.rb +65 -100
- data/lib/swarm_sdk/swarm/agent_initializer.rb +180 -136
- data/lib/swarm_sdk/swarm/builder.rb +44 -578
- data/lib/swarm_sdk/swarm/executor.rb +213 -0
- data/lib/swarm_sdk/swarm/hook_triggers.rb +150 -0
- data/lib/swarm_sdk/swarm/logging_callbacks.rb +340 -0
- data/lib/swarm_sdk/swarm/mcp_configurator.rb +7 -4
- data/lib/swarm_sdk/swarm/tool_configurator.rb +42 -138
- data/lib/swarm_sdk/swarm.rb +137 -680
- data/lib/swarm_sdk/tools/bash.rb +11 -3
- data/lib/swarm_sdk/tools/delegate.rb +61 -43
- data/lib/swarm_sdk/tools/edit.rb +8 -13
- data/lib/swarm_sdk/tools/glob.rb +9 -1
- data/lib/swarm_sdk/tools/grep.rb +7 -0
- data/lib/swarm_sdk/tools/multi_edit.rb +15 -11
- data/lib/swarm_sdk/tools/path_resolver.rb +51 -2
- data/lib/swarm_sdk/tools/read.rb +11 -13
- data/lib/swarm_sdk/tools/registry.rb +122 -10
- data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +8 -5
- data/lib/swarm_sdk/tools/stores/storage.rb +0 -6
- data/lib/swarm_sdk/tools/todo_write.rb +7 -0
- data/lib/swarm_sdk/tools/web_fetch.rb +3 -2
- data/lib/swarm_sdk/tools/write.rb +8 -13
- data/lib/swarm_sdk/version.rb +1 -1
- data/lib/swarm_sdk/{node → workflow}/agent_config.rb +1 -1
- data/lib/swarm_sdk/workflow/builder.rb +143 -0
- data/lib/swarm_sdk/workflow/executor.rb +497 -0
- data/lib/swarm_sdk/{node/builder.rb → workflow/node_builder.rb} +3 -3
- data/lib/swarm_sdk/{node → workflow}/transformer_executor.rb +3 -2
- data/lib/swarm_sdk/{node_orchestrator.rb → workflow.rb} +152 -456
- data/lib/swarm_sdk.rb +33 -3
- data/rubocop/cop/security/no_reflection_methods.rb +1 -1
- data/swarm_memory.gemspec +1 -1
- data/swarm_sdk.gemspec +4 -2
- data/team_full.yml +24 -24
- metadata +35 -11
- data/lib/swarm_memory/chat_extension.rb +0 -34
- 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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7137a9b3f3fd37de3a81a9b3f4b1b6fe5b3173248284f4c6ce0af628f2f140cd
|
|
4
|
+
data.tar.gz: 447a2c03a49e23e2ba1750d05922b84e95df7bebfd5dbeacc3331cefa6882b8e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8bd44b19b45e5482d141520c84589a08b646bfa2691b48d233e2c844745d1084081e16e23971a71f71bda796c85c3e6a599be33bbf839b2bc2d8d626b8a3cf1
|
|
7
|
+
data.tar.gz: 2600e70853d9d590075c3c172e3bea65a75795d0a667ab4dffa8361c6bc3a4d829643ac64eac42f2fb260639759326ab5af00d36cda2538634f4d0656ca94628
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## [1.0.9]
|
|
2
9
|
|
|
3
10
|
### 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
|
-
|
|
7
|
+
This repository contains three integrated Ruby gems that work together to create collaborative AI agent systems:
|
|
8
8
|
|
|
9
|
-
SwarmSDK
|
|
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
|
-
|
|
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
|
-
|
|
41
|
-
```bash
|
|
42
|
-
bin/console # Start IRB session with gem loaded
|
|
43
|
-
```
|
|
85
|
+
## Architecture
|
|
44
86
|
|
|
45
|
-
###
|
|
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
|
-
|
|
52
|
-
```bash
|
|
53
|
-
rake # Runs both tests and RuboCop
|
|
54
|
-
```
|
|
89
|
+
**Core Components:**
|
|
55
90
|
|
|
56
|
-
|
|
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
|
-
|
|
99
|
+
**Key Subsystems:**
|
|
59
100
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
66
|
-
claude-swarm --worktree
|
|
107
|
+
**User-Facing APIs:**
|
|
67
108
|
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
136
|
+
**Core Components:**
|
|
99
137
|
|
|
100
|
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
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
|
-
|
|
144
|
+
**Memory Tools:**
|
|
107
145
|
|
|
108
|
-
|
|
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
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
170
|
+
### SwarmCLI Architecture (`lib/swarm_cli/`)
|
|
210
171
|
|
|
211
|
-
|
|
172
|
+
**Core Components:**
|
|
212
173
|
|
|
213
|
-
|
|
214
|
-
-
|
|
215
|
-
-
|
|
216
|
-
-
|
|
217
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
225
|
-
|
|
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
|
|
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
|
|
236
|
-
-
|
|
237
|
-
-
|
|
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
|
|
240
|
-
- Dependencies loaded in
|
|
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/
|
|
247
|
-
|
|
248
|
-
require "
|
|
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.
|
|
265
|
+
loader = Zeitwerk::Loader.new
|
|
261
266
|
loader.setup
|
|
262
267
|
|
|
263
|
-
# ❌ INCORRECT - lib/
|
|
264
|
-
require "
|
|
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 "
|
|
271
|
+
require "swarm_sdk/configuration" # Don't do this!
|
|
267
272
|
```
|
|
268
273
|
|
|
269
|
-
|
|
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.
|
|
@@ -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
|
|
@@ -5,7 +5,13 @@ All notable changes to SwarmMemory 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
|
-
## [
|
|
8
|
+
## [2.1.4]
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Updated documentation to reference `Workflow` instead of `NodeOrchestrator`
|
|
13
|
+
- Memory configuration preserved when agents are cloned in `Workflow` (formerly `NodeOrchestrator`)
|
|
14
|
+
- No functional changes - fully compatible with SwarmSDK refactoring
|
|
9
15
|
|
|
10
16
|
## [2.1.3] - 2025-11-06
|
|
11
17
|
|