claude_swarm 1.0.6 → 1.0.7

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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +14 -0
  4. data/README.md +336 -1037
  5. data/docs/V1_TO_V2_MIGRATION_GUIDE.md +1120 -0
  6. data/docs/v1/README.md +1195 -0
  7. data/docs/v2/CHANGELOG.swarm_cli.md +22 -0
  8. data/docs/v2/CHANGELOG.swarm_memory.md +20 -0
  9. data/docs/v2/CHANGELOG.swarm_sdk.md +287 -10
  10. data/docs/v2/README.md +32 -6
  11. data/docs/v2/guides/complete-tutorial.md +133 -37
  12. data/docs/v2/guides/composable-swarms.md +1178 -0
  13. data/docs/v2/guides/getting-started.md +42 -1
  14. data/docs/v2/guides/snapshots.md +1498 -0
  15. data/docs/v2/reference/architecture-flow.md +5 -3
  16. data/docs/v2/reference/event_payload_structures.md +249 -12
  17. data/docs/v2/reference/execution-flow.md +1 -1
  18. data/docs/v2/reference/ruby-dsl.md +368 -22
  19. data/docs/v2/reference/yaml.md +314 -63
  20. data/examples/snapshot_demo.rb +119 -0
  21. data/examples/v2/dsl/01_basic.rb +0 -2
  22. data/examples/v2/dsl/02_core_parameters.rb +0 -2
  23. data/examples/v2/dsl/03_capabilities.rb +0 -2
  24. data/examples/v2/dsl/04_llm_parameters.rb +0 -2
  25. data/examples/v2/dsl/05_advanced_flags.rb +0 -3
  26. data/examples/v2/dsl/06_permissions.rb +0 -4
  27. data/examples/v2/dsl/07_mcp_server.rb +0 -2
  28. data/examples/v2/dsl/08_swarm_hooks.rb +0 -2
  29. data/examples/v2/dsl/09_agent_hooks.rb +0 -2
  30. data/examples/v2/dsl/10_all_agents_hooks.rb +0 -3
  31. data/examples/v2/dsl/11_delegation.rb +0 -2
  32. data/examples/v2/dsl/12_complete_integration.rb +2 -6
  33. data/examples/v2/node_context_demo.rb +1 -1
  34. data/examples/v2/node_workflow.rb +2 -4
  35. data/examples/v2/plan_and_execute.rb +157 -0
  36. data/lib/claude_swarm/configuration.rb +28 -4
  37. data/lib/claude_swarm/version.rb +1 -1
  38. data/lib/swarm_cli/formatters/human_formatter.rb +103 -0
  39. data/lib/swarm_cli/interactive_repl.rb +9 -3
  40. data/lib/swarm_cli/version.rb +1 -1
  41. data/lib/swarm_memory/core/storage_read_tracker.rb +51 -14
  42. data/lib/swarm_memory/integration/cli_registration.rb +3 -2
  43. data/lib/swarm_memory/integration/sdk_plugin.rb +11 -5
  44. data/lib/swarm_memory/tools/memory_edit.rb +2 -2
  45. data/lib/swarm_memory/tools/memory_multi_edit.rb +2 -2
  46. data/lib/swarm_memory/tools/memory_read.rb +3 -3
  47. data/lib/swarm_memory/version.rb +1 -1
  48. data/lib/swarm_memory.rb +5 -0
  49. data/lib/swarm_sdk/agent/builder.rb +33 -0
  50. data/lib/swarm_sdk/agent/chat/context_tracker.rb +33 -0
  51. data/lib/swarm_sdk/agent/chat/hook_integration.rb +49 -3
  52. data/lib/swarm_sdk/agent/chat/system_reminder_injector.rb +11 -27
  53. data/lib/swarm_sdk/agent/chat.rb +200 -51
  54. data/lib/swarm_sdk/agent/context.rb +6 -2
  55. data/lib/swarm_sdk/agent/context_manager.rb +6 -0
  56. data/lib/swarm_sdk/agent/definition.rb +14 -2
  57. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +180 -0
  58. data/lib/swarm_sdk/configuration.rb +387 -94
  59. data/lib/swarm_sdk/events_to_messages.rb +181 -0
  60. data/lib/swarm_sdk/log_collector.rb +31 -5
  61. data/lib/swarm_sdk/log_stream.rb +37 -8
  62. data/lib/swarm_sdk/model_aliases.json +4 -1
  63. data/lib/swarm_sdk/node/agent_config.rb +33 -8
  64. data/lib/swarm_sdk/node/builder.rb +39 -18
  65. data/lib/swarm_sdk/node_orchestrator.rb +293 -26
  66. data/lib/swarm_sdk/proc_helpers.rb +53 -0
  67. data/lib/swarm_sdk/providers/openai_with_responses.rb +22 -15
  68. data/lib/swarm_sdk/restore_result.rb +65 -0
  69. data/lib/swarm_sdk/snapshot.rb +156 -0
  70. data/lib/swarm_sdk/snapshot_from_events.rb +386 -0
  71. data/lib/swarm_sdk/state_restorer.rb +491 -0
  72. data/lib/swarm_sdk/state_snapshot.rb +369 -0
  73. data/lib/swarm_sdk/swarm/agent_initializer.rb +360 -55
  74. data/lib/swarm_sdk/swarm/all_agents_builder.rb +28 -1
  75. data/lib/swarm_sdk/swarm/builder.rb +208 -12
  76. data/lib/swarm_sdk/swarm/swarm_registry_builder.rb +67 -0
  77. data/lib/swarm_sdk/swarm/tool_configurator.rb +46 -11
  78. data/lib/swarm_sdk/swarm.rb +338 -42
  79. data/lib/swarm_sdk/swarm_loader.rb +145 -0
  80. data/lib/swarm_sdk/swarm_registry.rb +136 -0
  81. data/lib/swarm_sdk/tools/delegate.rb +92 -7
  82. data/lib/swarm_sdk/tools/read.rb +17 -5
  83. data/lib/swarm_sdk/tools/stores/read_tracker.rb +47 -12
  84. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +45 -0
  85. data/lib/swarm_sdk/utils.rb +18 -0
  86. data/lib/swarm_sdk/validation_result.rb +33 -0
  87. data/lib/swarm_sdk/version.rb +1 -1
  88. data/lib/swarm_sdk.rb +40 -8
  89. data/swarm_cli.gemspec +1 -1
  90. data/swarm_memory.gemspec +2 -2
  91. data/swarm_sdk.gemspec +2 -2
  92. metadata +21 -13
  93. data/examples/learning-assistant/assistant.md +0 -7
  94. data/examples/learning-assistant/example-memories/concept-example.md +0 -90
  95. data/examples/learning-assistant/example-memories/experience-example.md +0 -66
  96. data/examples/learning-assistant/example-memories/fact-example.md +0 -76
  97. data/examples/learning-assistant/example-memories/memory-index.md +0 -78
  98. data/examples/learning-assistant/example-memories/skill-example.md +0 -168
  99. data/examples/learning-assistant/learning_assistant.rb +0 -34
  100. data/examples/learning-assistant/learning_assistant.yml +0 -20
  101. data/lib/swarm_sdk/mcp.rb +0 -16
  102. data/llm.v2.txt +0 -13407
  103. /data/docs/v2/guides/{MEMORY_DEFRAG_GUIDE.md → memory-defrag-guide.md} +0 -0
  104. /data/{llms.txt → llms.claude-swarm.txt} +0 -0
@@ -5,6 +5,28 @@ 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.3]
9
+
10
+ ### Fixed
11
+
12
+ - **Interactive REPL spinner cleanup** - Fixed spinners not stopping properly
13
+ - Bug: Spinners continued animating after swarm execution completed or on errors
14
+ - Bug: REPL prompt would overlap with spinner animation, causing terminal corruption
15
+ - Fix: Added `spinner_manager.stop_all()` after `execute_with_cancellation()` in all paths
16
+ - Fix: Added defensive cleanup in `on_success()`, `on_error()`, and `run()` ensure block
17
+ - Fix: Ensures spinners stop before displaying results, errors, or REPL prompt
18
+ - Impact: Fixes 100% of interactive mode sessions
19
+
20
+ ### Added
21
+
22
+ - **LLM API Error and Retry Event Handlers** - CLI now shows LLM API errors and retries
23
+ - Added handler for `llm_retry_attempt` - Shows warning panel during retry attempts
24
+ - Added handler for `llm_retry_exhausted` - Shows error panel when retries are exhausted
25
+ - Added handler for `response_parse_error` - Shows error panel when response parsing fails
26
+ - Displays attempt numbers (e.g., "attempt 2/3"), retry delays, error messages
27
+ - Properly manages spinners during error display (stops "thinking" spinner, restarts "retrying" spinner)
28
+ - Provides clear visibility into API rate limits, timeouts, and parsing errors
29
+
8
30
  ## [2.1.2]
9
31
 
10
32
  ### Changed
@@ -5,6 +5,26 @@ 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
+ ## [Unreleased]
9
+
10
+ ## [2.1.3] - 2025-11-06
11
+
12
+ ### Added
13
+
14
+ - **Memory Read Tracking in Events**: MemoryRead tool now includes digest in tool_result events
15
+ - **`metadata.read_digest`** - SHA256 digest of entry content added to tool_result events
16
+ - **`metadata.read_path`** - Entry path added to tool_result events
17
+ - **Enables snapshot reconstruction** - Complete memory_read_tracking state recoverable from events
18
+ - **Event sourcing support** - Memory state can be reconstructed from event logs
19
+ - **Cross-gem coordination** - Works seamlessly with SwarmSDK's SnapshotFromEvents
20
+
21
+ ### Changed
22
+
23
+ - **StorageReadTracker returns digest**: `register_read` now returns SHA256 digest string
24
+ - **Enables**: Digest extraction after MemoryRead execution for event metadata
25
+ - **Backward compatible**: Return value wasn't previously used
26
+ - **Integration**: Used by SwarmSDK to populate tool_result event metadata
27
+
8
28
  ## [2.1.2]
9
29
 
10
30
  ### Changed
@@ -5,7 +5,283 @@ All notable changes to SwarmSDK 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.2]
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ - **User Prompt Source Tracking**: `user_prompt` events now include source information to distinguish user interactions from delegations
13
+ - **`source` field**: Indicates origin of prompt - `"user"` (direct user interaction) or `"delegation"` (from delegation tool)
14
+ - **Event filtering**: Enables filtering user prompts by source in logs and analytics
15
+ - **Delegation tracking**: Identify which prompts originated from agent delegations vs direct user input
16
+ - **Hook context**: Source information available in user_prompt hooks via `context.metadata[:source]`
17
+ - **Implementation**: Source passed through `ask()` method options, extracted in `trigger_user_prompt()`
18
+ - **Default behavior**: All prompts default to `source: "user"` for backward compatibility
19
+ - **Files**: `lib/swarm_sdk/agent/chat/hook_integration.rb`, `lib/swarm_sdk/tools/delegate.rb`, `lib/swarm_sdk/swarm.rb`
20
+ - **Example**: `{ type: "user_prompt", agent: "backend", source: "delegation", ... }`
21
+
22
+ - **Safe Return Statements in Node Transformers**: Input and output transformers now support `return` statements for natural control flow
23
+ - **Automatic lambda conversion**: Blocks passed to `input {}` and `output {}` are automatically converted to lambdas via `ProcHelpers.to_lambda`
24
+ - **Safe early exits**: Use `return` for early exits without risking program termination
25
+ - **Natural control flow**: Write intuitive conditional logic with standard Ruby `return` keyword
26
+ - **Examples**: `return ctx.skip_execution(content: "cached") if cached?`, `return ctx.halt_workflow(content: "error") if invalid?`
27
+ - **Implementation**: Converts Proc to UnboundMethod via `define_method`, then wraps in lambda where `return` only exits the method
28
+ - **Backward compatible**: Existing code without `return` statements continues to work unchanged
29
+ - **Files**: `lib/swarm_sdk/proc_helpers.rb`, `lib/swarm_sdk/node/builder.rb`
30
+ - **Tests**: 8 comprehensive tests in `test/swarm_sdk/proc_helpers_test.rb` covering closures, keyword args, block args, and multiple return paths
31
+
32
+ - **Per-Node Tool Overrides**: Agents can now have different tool sets in different nodes
33
+ - **Node-specific tools**: Override agent's global tool configuration on a per-node basis
34
+ - **Fluent syntax**: Chain with delegation: `agent(:backend).delegates_to(:tester).tools(:Read, :Edit, :Write)`
35
+ - **Use case**: Restrict tools for specific workflow stages (e.g., planning node with thinking tools only, execution node with file tools)
36
+ - **Example**: `agent(:planner).tools(:Think, :Read)` in planning node, `agent(:planner).tools(:Write, :Edit, :Bash)` in implementation node
37
+ - **Implementation**: New `tools(*tool_names)` method on `AgentConfig`, stored in node configuration as tool override
38
+ - **Backward compatible**: Omit `.tools()` to use agent's global tool configuration
39
+ - **Files**: `lib/swarm_sdk/node/agent_config.rb`, `lib/swarm_sdk/node/builder.rb`, `lib/swarm_sdk/node_orchestrator.rb`
40
+
41
+ ## [2.2.0] - 2025-11-06
42
+
43
+ ### Fixed
44
+
45
+ - **Snapshot Restoration Critical Bugs**: Fixed two critical bugs preventing proper state restoration
46
+ - **Bug 1 - Delegation Instance Validation**: Delegation instances incorrectly rejected during restoration
47
+ - **Issue**: `bob@jarvis` delegation failed validation even when both agents existed
48
+ - **Root cause**: Validation checked if base agent (`bob`) existed as primary agent in snapshot, but bob only appeared as delegation
49
+ - **Fix**: Changed validation to check if base agent exists in **current configuration** instead of snapshot
50
+ - **Impact**: Delegation instances can now be restored correctly from snapshots and events
51
+ - **Bug 2 - System Prompt Ordering**: System prompts applied then immediately removed
52
+ - **Issue**: `with_instructions()` adds system message, but `messages.clear` was called after, removing it
53
+ - **Root cause**: Wrong order of operations - system prompt added before clearing messages
54
+ - **Fix**: Clear messages first, then add system prompt, then restore conversation
55
+ - **Impact**: System prompts now correctly preserved during restoration for all agents
56
+ - **Result**: Event sourcing fully functional, delegation workflows restore correctly
57
+ - **Files**: `lib/swarm_sdk/state_restorer.rb` - Lines 140-141, 210-225, 340-356
58
+
59
+ - **Event Timestamp Precision**: Microsecond-precision timestamps for correct event ordering
60
+ - **Issue**: Events emitted rapidly within same second had identical timestamps, causing arbitrary sort order
61
+ - **Impact**: Message reconstruction from events produced incorrect conversation order (tool results before tool calls)
62
+ - **Root cause**: `Time.now.utc.iso8601` defaults to second precision, events within same second indistinguishable
63
+ - **Fix**: Use `Time.now.utc.iso8601(6)` for microsecond precision (e.g., `2025-11-05T19:10:58.123456Z`)
64
+ - **Files**: `log_stream.rb:54`, `log_collector.rb:65`
65
+ - **Result**: Events now sort correctly even when emitted microseconds apart
66
+ - **Critical for**: Snapshot reconstruction, delegation conversations, rapid tool executions
67
+
68
+ - **Rails/Puma Event Loss in Multi-Threaded Environments**: Complete fix for event streaming in production
69
+ - **Issue**: Events lost on subsequent requests when using `restore()` before `execute()` in Rails/Puma
70
+ - **Root cause 1**: Callbacks stored in class instance variables didn't propagate to child fibers
71
+ - **Root cause 2**: `restore()` triggered agent initialization before logging setup, skipping callback registration
72
+ - **Root cause 3**: Callbacks passed stale `@agent_context.swarm_id` that overrode Fiber-local storage
73
+ - **Fix 1**: LogCollector uses Fiber-local storage (`Fiber[:log_callbacks]`) for thread-safe callback propagation
74
+ - **Fix 2**: Retroactive callback registration via `setup_logging_for_all_agents` when agents initialized early
75
+ - **Fix 3**: Removed explicit `swarm_id`/`parent_swarm_id` from LogStream.emit calls in callbacks
76
+ - **Fix 4**: Scheduler leak prevention - force cleanup of lingering Async schedulers between requests
77
+ - **Fix 5**: Fresh callback array per execution to prevent accumulation
78
+ - **Result**: All events (agent_step, tool_call, delegation, etc.) now work correctly in Puma/Sidekiq
79
+ - **Rails integration**: Works seamlessly without service code changes
80
+
81
+ ### Added
82
+
83
+ - **Configurable System Prompt Restoration**: Control whether system prompts come from current config or historical snapshot
84
+ - **`preserve_system_prompts`** parameter in `swarm.restore()` and `orchestrator.restore()` (default: `false`)
85
+ - **Default behavior (`false`)**: System prompts from current agent definitions (YAML + SDK defaults + plugin injections)
86
+ - Enables system prompt iteration without creating new sessions
87
+ - Configuration is source of truth for agent behavior
88
+ - External session management with prompt updates works seamlessly
89
+ - **Historical mode (`true`)**: System prompts from snapshot (exact historical state)
90
+ - For debugging: "What instructions was agent following when bug occurred?"
91
+ - For auditing: "What exact prompts were active at that time?"
92
+ - For reproducibility: "Replay with exact historical context"
93
+ - **Applies to all agents**: Primary agents and delegation instances
94
+ - **Includes all injections**: YAML config, SDK defaults, SwarmMemory instructions, plugin additions
95
+ - **Non-breaking**: Backward compatible, all existing code works unchanged
96
+ - **Documentation**: Complete guide in `docs/v2/guides/snapshots.md` with examples and comparisons
97
+
98
+ - **System-Wide Filesystem Tools Control**: Global security setting to disable filesystem tools across all agents
99
+ - **`SwarmSDK.settings.allow_filesystem_tools`** - Global setting to enable/disable filesystem tools (default: true)
100
+ - **Environment variable**: `SWARM_SDK_ALLOW_FILESYSTEM_TOOLS` - Set via environment for production deployments
101
+ - **Parameter override**: `allow_filesystem_tools:` parameter in `SwarmSDK.build`, `load`, and `load_file`
102
+ - **Filesystem tools**: Read, Write, Edit, MultiEdit, Grep, Glob, Bash
103
+ - **Validation**: Build-time validation catches forbidden tools early with clear error messages
104
+ - **Non-breaking**: Defaults to `true` for backward compatibility
105
+ - **Security boundary**: External to swarm configuration - cannot be overridden by YAML/DSL
106
+ - **Tools still allowed**: Think, TodoWrite, Clock, WebFetch, ScratchpadRead/Write/List, Memory tools
107
+ - **Use cases**: Multi-tenant platforms, sandboxed execution, containerized environments, compliance requirements
108
+ - **Priority resolution**: Explicit parameter > Global setting > Environment variable > Default (true)
109
+ - **26 comprehensive tests** covering all configuration and validation scenarios
110
+ - **Documentation**: Complete implementation guide in `FILESYSTEM_TOOLS_CONTROL_PLAN.md`
111
+
112
+ - **Snapshot Reconstruction from Events**: Complete StateSnapshot reconstruction from event logs
113
+ - **`SwarmSDK::SnapshotFromEvents`** class reconstructs full swarm state from event stream
114
+ - **100% state reconstruction** - All components recoverable: conversations, context state, scratchpad, read tracking, delegation instances
115
+ - **Event sourcing ready** - Events are single source of truth, snapshots derived on-demand
116
+ - **Time travel debugging** - Reconstruct state at any point in time by filtering events
117
+ - **Session persistence** - Store only events in database, reconstruct snapshots when needed
118
+ - **`SwarmSDK::EventsToMessages`** helper class for message reconstruction with chronological ordering
119
+ - **Database/Redis patterns** - Complete examples for event-based session storage
120
+ - **Hybrid optimization** - Periodic snapshots + delta events for performance
121
+ - **Performance**: 1,000 events in ~10-20ms, 10,000 events in ~100-200ms
122
+ - **29 comprehensive tests** verifying event data capture and reconstruction accuracy
123
+ - **Documentation**: Complete guide in `docs/v2/guides/snapshots.md` with patterns and examples
124
+
125
+ - **Event Timestamp Guarantee**: All events now guaranteed to have timestamps
126
+ - **Automatic timestamp injection** in `LogCollector.emit` if missing
127
+ - **Format**: ISO 8601 UTC (`YYYY-MM-DDTHH:MM:SSZ`)
128
+ - **Preserves existing timestamps** - Won't overwrite if already present
129
+ - **Dual injection points** - LogStream and LogCollector both ensure timestamps
130
+ - **Chronological ordering** - Enables proper event sequencing for reconstruction
131
+ - **Updated test**: Verifies timestamp presence and preservation
132
+
133
+ - **Context Threshold Tracking**: New event for tracking which warning thresholds were hit
134
+ - **`context_threshold_hit`** event emitted when threshold crossed for first time
135
+ - **Contains**: `threshold` (integer: 60, 80, 90, 95), `current_usage_percentage`
136
+ - **Enables reconstruction** of `context_state.warning_thresholds_hit` from events
137
+ - **Separate from context_limit_warning** - Hit tracking vs informational warning
138
+
139
+ - **Read Tracking Digest in Events**: File read digests now included in tool_result metadata
140
+ - **`metadata.read_digest`** - SHA256 digest of read file content
141
+ - **`metadata.read_path`** - Absolute path to file
142
+ - **Added via `extract_tool_tracking_digest`** method after tool execution
143
+ - **Queries ReadTracker** after read completes to get calculated digest
144
+ - **Enables reconstruction** of complete read_tracking state from events
145
+ - **Works for all file types** - Text files, binary files, documents
146
+
147
+ - **Memory Read Tracking Digest in Events**: Memory read digests included in tool_result metadata
148
+ - **`metadata.read_digest`** - SHA256 digest of memory entry content
149
+ - **`metadata.read_path`** - Memory entry path
150
+ - **Unified handling** with file read tracking via same extraction method
151
+ - **Enables reconstruction** of complete memory_read_tracking state from events
152
+ - **Cross-gem coordination** - SwarmMemory and SwarmSDK work together seamlessly
153
+
154
+ - **Execution ID and Complete Swarm ID Tracking**: All log events now include comprehensive execution tracking fields
155
+ - **`execution_id`**: Uniquely identifies a single `swarm.execute()` or `orchestrator.execute()` call
156
+ - Format: `exec_{swarm_id}_{random_hex}` for swarms (e.g., `exec_main_a3f2b1c8`)
157
+ - Format: `exec_workflow_{random_hex}` for workflows (e.g., `exec_workflow_abc123`)
158
+ - Enables calculating total cost/tokens for a single execution
159
+ - Allows building complete execution traces across all agents and tools
160
+ - **`swarm_id`**: Identifies which swarm/node emitted the event
161
+ - Hierarchical format for NodeOrchestrator nodes (e.g., `workflow/node:planning`)
162
+ - Tracks execution flow through nested swarms and workflow stages
163
+ - **`parent_swarm_id`**: Identifies the parent swarm for nested execution contexts
164
+ - **Fiber-local storage implementation**: Uses Ruby 3.2+ Fiber storage for automatic propagation
165
+ - IDs automatically inherit to child fibers (tools, delegations, nested executions)
166
+ - Mini-swarms in workflows inherit orchestrator's execution_id while maintaining node-specific swarm_ids
167
+ - Zero manual propagation needed - all handled by `LogStream.emit()` auto-injection
168
+ - **Smart cleanup pattern**: Uses `block_given?` to determine cleanup responsibility
169
+ - Standalone swarms clear Fiber storage after execution
170
+ - Mini-swarms preserve parent's execution context for workflow continuity
171
+ - **Comprehensive coverage**: 30 out of 31 event types now have complete tracking
172
+ - All events except optional `claude_code_conversion_warning` (backward compatibility)
173
+ - **Production-ready**: Minimal code changes (3 files, ~28 lines), zero performance impact
174
+ - **Fully tested**: 10 comprehensive test cases covering uniqueness, inheritance, isolation, and cleanup
175
+
176
+ - **Composable Swarms**: Build reusable swarm components that can be composed together
177
+ - **New `id()` DSL method**: Set unique swarm identifier (required when using composable swarms)
178
+ - **New `swarms {}` DSL block**: Register external swarms for delegation
179
+ - **New `register()` method**: Three registration methods:
180
+ - `register "name", file: "./swarm.rb"` - Load from file
181
+ - `register "name", yaml: yaml_string` - Load from YAML string
182
+ - `register "name" { ... }` - Define inline with DSL block
183
+ - **`keep_context` parameter**: Control conversation persistence per swarm (default: true)
184
+ - **Hierarchical swarm IDs**: Parent/child tracking (e.g., `main/code_review/security`)
185
+ - **Transparent delegation**: Use swarms in `delegates_to` like regular agents
186
+ - **Lazy loading & caching**: Sub-swarms loaded on first access and cached
187
+ - **Circular dependency detection**: Runtime prevention of infinite delegation loops
188
+ - **Event tracking**: All events include `swarm_id` and `parent_swarm_id` fields
189
+ - **SwarmRegistry class**: Manages sub-swarm lifecycle and cleanup
190
+ - **SwarmLoader class**: Multi-source loader (files, YAML strings, blocks)
191
+ - **Deep nesting support**: Unlimited levels of swarm composition
192
+ - **Cleanup cascade**: Proper resource cleanup through hierarchy
193
+ - **YAML support**: `id:` and `swarms:` sections with file/inline definitions
194
+ - **Comprehensive tests**: 36 new tests, 100% pass rate
195
+
196
+ - **Per-Delegation Agent Instances**: Dual-mode delegation support with isolated and shared modes
197
+ - **New `shared_across_delegations` configuration** (default: `false`)
198
+ - `false` (default): Each delegator gets its own isolated instance with separate conversation history
199
+ - `true`: All delegators share the same primary agent instance (legacy behavior)
200
+ - **Prevents context mixing**: Multiple agents delegating to the same target no longer share conversation history by default
201
+ - **Instance naming**: Delegation instances follow `"delegate@delegator"` pattern (e.g., `"tester@frontend"`)
202
+ - **Memory sharing**: Plugin storage (SwarmMemory) shared by base name across all instances
203
+ - **Tool state isolation**: TodoWrite, ReadTracker, and other stateful tools isolated per instance
204
+ - **Nested delegation support**: Works correctly with multi-level delegation chains
205
+ - **Fiber-safe concurrency**: Added `Async::Semaphore` to `Chat.ask()` to prevent message corruption when multiple delegation instances call shared agents in parallel
206
+ - **Atomic caching**: NodeOrchestrator caches delegation instances together with primary agents for context preservation
207
+ - **Agent name validation**: Agent names cannot contain '@' character (reserved for delegation instances)
208
+ - **Automatic deduplication**: Duplicate entries in `delegates_to` are automatically removed
209
+ - **Comprehensive test coverage**: 17 new tests covering isolated mode, shared mode, nested delegation, cleanup, and more
210
+
211
+ - **YAML-to-DSL Internal Refactor**: Configuration class now uses DSL internally for swarm construction
212
+ - **New `Configuration.to_swarm` implementation**: Translates YAML to Ruby DSL calls instead of direct API
213
+ - **Better separation of concerns**: YAML parsing separated from swarm building logic
214
+ - **Node workflow support in YAML**: Full support for multi-stage node-based workflows
215
+ - **Improved translation methods**: `translate_agents`, `translate_all_agents`, `translate_nodes`, `translate_swarm_hooks`
216
+ - **Stricter validation**: Agent descriptions now required in YAML (caught earlier with better error messages)
217
+ - **Test coverage**: Added `yaml_node_support_test.rb` with comprehensive node workflow tests
218
+
219
+ - **YAML Hooks & Permissions**: Fixed and improved YAML configuration for hooks and permissions
220
+ - **Hooks now work correctly**: Fixed translation from YAML to DSL
221
+ - **Permissions properly translated**: Complex permission configurations now work in YAML
222
+ - **Documentation improvements**: Updated YAML reference with correct examples
223
+ - **Cleaner agent builder**: Removed redundant hook/permission handling code
224
+
225
+ ### Fixed
226
+
227
+ - **StateSnapshot tool_calls serialization**: Fixed bug where tool_calls couldn't be serialized
228
+ - **Issue**: `msg.tool_calls.map(&:to_h)` failed because tool_calls is a Hash, not Array
229
+ - **Fix**: Changed to `msg.tool_calls.values.map(&:to_h)` to properly serialize
230
+ - **Impact**: Snapshots with tool calls now serialize correctly
231
+ - **Location**: `lib/swarm_sdk/state_snapshot.rb:154`
232
+
233
+ - **ReadTracker and StorageReadTracker return digest**: Both trackers now return calculated digest
234
+ - **Changed**: `register_read` methods now return SHA256 digest string
235
+ - **Enables**: Digest extraction after tool execution for event metadata
236
+ - **Backward compatible**: Return value wasn't previously used
237
+
238
+ ### Changed
239
+
240
+ - **Breaking: Default tools reduced to essential file operations only**
241
+ - **Old default tools**: Read, Grep, Glob, WebFetch, TodoWrite, Clock, Think
242
+ - **New default tools**: Read, Grep, Glob
243
+ - **Removed from defaults**: WebFetch, TodoWrite, Clock, Think
244
+ - **Rationale**: Follows principle of least privilege - users have complete control over agent capabilities
245
+ - **Migration**: Explicitly add removed tools if needed: `tools :Read, :Grep, :Glob, :WebFetch, :TodoWrite, :Clock, :Think`
246
+ - **Impact**: Agents will no longer have WebFetch, TodoWrite, Clock, or Think unless explicitly added
247
+ - **Documentation updated**: All guides and references now show correct default tools
248
+
249
+ - **Breaking: Default delegation behavior changed**
250
+ - **Old behavior**: Multiple agents delegating to same target shared conversation history
251
+ - **New behavior**: Each delegator gets isolated instance with separate history (prevents context mixing)
252
+ - **Migration**: Add `shared_across_delegations: true` to agents that need the old shared behavior
253
+ - **Impact**: Existing swarms will see different behavior - agents no longer share delegation contexts by default
254
+
255
+ - **Ruby version upgraded**: 3.4.2 → 3.4.5
256
+ - Updated `.ruby-version` file
257
+ - All dependencies compatible with Ruby 3.4.5
258
+
259
+ - **RubyLLM upgraded**: 1.8.2 → 1.9.0
260
+ - Updated to latest RubyLLM gem version
261
+ - Updated ruby_llm-mcp integration
262
+ - Disabled MCP lazy loading for better compatibility
263
+ - See RubyLLM changelog for full details
264
+
265
+ - **YAML Configuration Loading**: Improved YAML parsing and validation
266
+ - **Stricter validation**: Required fields now validated earlier with better error messages
267
+ - **Better error context**: Error messages include field paths and agent names
268
+ - **Node workflow validation**: Full validation for node dependencies and transformers
269
+
270
+ - **TodoWrite system reminders**: Only injected when TodoWrite tool is available
271
+ - Fixed bug where TodoWrite reminders appeared even when tool was disabled
272
+ - System reminders now conditional based on agent's actual toolset
273
+ - Cleaner agent output when TodoWrite is not needed
274
+
275
+ ### Fixed
276
+
277
+ - **Node context preservation bug**: Fixed issue where `inject_cached_agents` would be overwritten by fresh initialization
278
+ - Added forced initialization before injection to ensure cached instances are preserved
279
+ - **Nested delegation race condition**: Added per-instance semaphore to prevent concurrent `ask()` calls from corrupting shared agent message history
280
+ - **Hash iteration bug**: Fixed "can't add key during iteration" error in nested delegation by using `.to_a`
281
+ - **YAML hooks translation**: Fixed hooks not being properly translated from YAML to DSL
282
+ - **YAML permissions handling**: Fixed permissions configurations not working correctly in YAML
283
+
284
+ ## [2.1.3]
9
285
 
10
286
  ### Added
11
287
 
@@ -85,9 +361,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
85
361
  - Enables clean separation between core SDK and plugin features (memory, skills, etc.)
86
362
  - Plugins can preserve their configuration when agents are cloned in NodeOrchestrator
87
363
 
88
- - **NodeOrchestrator**: Passes scratchpad configuration to mini-swarms
89
- - Bug fix: `scratchpad_enabled` now correctly propagated to node-level swarms
90
- - Ensures `use_scratchpad false` works properly in node workflows
364
+ - **NodeOrchestrator**: Configurable scratchpad sharing modes
365
+ - `scratchpad: :enabled` - Share scratchpad across all nodes
366
+ - `scratchpad: :per_node` - Isolated scratchpad per node
367
+ - `scratchpad: :disabled` - No scratchpad tools (default)
91
368
 
92
369
  - **CLI ConfigLoader**: Accepts both Swarm and NodeOrchestrator instances
93
370
  - Bug fix: CLI now correctly handles NodeOrchestrator execution
@@ -282,17 +559,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
282
559
  directory: .swarm/assistant-memory
283
560
  ```
284
561
 
285
- - **Scratchpad Configuration DSL** - Enable/disable at swarm level
562
+ - **Scratchpad Configuration DSL** - Configure mode at swarm/workflow level
286
563
  ```ruby
287
564
  SwarmSDK.build do
288
- use_scratchpad true # or false (default: true)
565
+ scratchpad :enabled # or :per_node (nodes only), :disabled (default: :disabled)
289
566
  end
290
567
  ```
291
568
 
292
569
  - **Scratchpad Configuration YAML**
293
570
  ```yaml
294
571
  swarm:
295
- use_scratchpad: true # or false
572
+ scratchpad: enabled # or per_node (nodes only), disabled
296
573
  ```
297
574
 
298
575
  - **Agent Start Events** - New log event after agent initialization
@@ -330,8 +607,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
330
607
  - Future-ready for SQLite and FAISS adapters
331
608
 
332
609
  - **Default tools** - Conditional inclusion
333
- - Core defaults: Read, Grep, Glob, TodoWrite, Think, WebFetch
334
- - Scratchpad tools: Added if `use_scratchpad true` (default)
610
+ - Core defaults: Read, Grep, Glob
611
+ - Scratchpad tools: Added if `scratchpad: :enabled` (default)
335
612
  - Memory tools: Added if agent has `memory` configured
336
613
  - Enables fine-grained control over tool availability
337
614
 
@@ -371,7 +648,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
371
648
  - **Migration**: Old persisted scratchpad.json files will not load
372
649
 
373
650
  4. **Default tools behavior changed**: Memory and Scratchpad are conditional
374
- - Scratchpad: Enabled by default via `use_scratchpad true`
651
+ - Scratchpad: Enabled by default via `scratchpad: :enabled`
375
652
  - Memory: Opt-in via `memory` configuration
376
653
  - **Migration**: Explicitly configure if needed
377
654
 
data/docs/v2/README.md CHANGED
@@ -18,6 +18,10 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
18
18
  - **[Getting Started with SwarmCLI](guides/quick-start-cli.md)** ⭐ START HERE
19
19
  Command-line interface: interactive REPL and automation modes
20
20
 
21
+ ### For Advanced Features
22
+ - **[Composable Swarms Guide](guides/composable-swarms.md)** ⭐ NEW
23
+ Build reusable swarm components: file/YAML/inline registration, hierarchical composition, keep_context control
24
+
21
25
  ---
22
26
 
23
27
  ## 📖 Comprehensive Tutorial
@@ -61,7 +65,7 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
61
65
 
62
66
  ### YAML Configuration
63
67
  - **[YAML Configuration Reference](reference/yaml.md)**
64
- Complete YAML structure: agents, tools, permissions, hooks, MCP servers
68
+ Complete YAML structure: agents, tools, permissions, hooks, nodes, MCP servers
65
69
 
66
70
  ### SwarmMemory
67
71
  - **[SwarmMemory Technical Details](reference/swarm_memory_technical_details.md)**
@@ -69,7 +73,17 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
69
73
 
70
74
  ---
71
75
 
72
- ## 🛠️ Integration Guides
76
+ ## 🛠️ Feature Guides
77
+
78
+ ### Composable Swarms
79
+ - **[Composable Swarms Guide](guides/composable-swarms.md)** ⭐ NEW
80
+ Build reusable swarm components that can be composed together:
81
+ - Three registration methods (file, YAML string, inline block)
82
+ - Hierarchical composition and deep nesting
83
+ - Context control (keep_context: true/false)
84
+ - Circular dependency detection
85
+ - Event tracking with swarm_id hierarchy
86
+ - Use cases: specialized teams, dynamic loading, gems, testing
73
87
 
74
88
  ### SwarmMemory
75
89
  - **[SwarmMemory Guide](guides/swarm-memory.md)** ⭐ NEW
@@ -128,6 +142,7 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
128
142
  - **Agents**: [Getting Started](guides/getting-started.md#core-concepts) | [Tutorial Part 1](guides/complete-tutorial.md#part-1-fundamentals)
129
143
  - **Tools**: [Tutorial Part 2](guides/complete-tutorial.md#part-2-tools-and-permissions)
130
144
  - **Delegation**: [Tutorial Part 3](guides/complete-tutorial.md#part-3-agent-collaboration)
145
+ - **Composable Swarms**: [Ruby DSL Ref](reference/ruby-dsl.md#swarms) | [YAML Ref](reference/yaml.md#swarms) ⭐ NEW
131
146
  - **Hooks**: [Tutorial Part 4](guides/complete-tutorial.md#part-4-hooks-system)
132
147
  - **Node Workflows**: [Tutorial Part 5](guides/complete-tutorial.md#part-5-node-workflows)
133
148
 
@@ -145,6 +160,7 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
145
160
  - **Rate Limiting**: [Tutorial Part 6](guides/complete-tutorial.md#rate-limiting)
146
161
 
147
162
  ### Production
163
+ - **Security**: [Filesystem Tools Control](reference/ruby-dsl.md#swarmsdk.configure) | [Tutorial Part 8](guides/complete-tutorial.md#security-considerations)
148
164
  - **Logging**: [Tutorial Part 7](guides/complete-tutorial.md#structured-logging)
149
165
  - **Error Handling**: [Tutorial Part 7](guides/complete-tutorial.md#error-handling-and-recovery)
150
166
  - **Testing**: [Tutorial Part 8](guides/complete-tutorial.md#testing-strategies) | [Rails Guide](guides/rails-integration.md#testing-strategies)
@@ -180,12 +196,18 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
180
196
  **Add persistent memory to agents**
181
197
  → [SwarmMemory Guide](guides/swarm-memory.md)
182
198
 
199
+ **Build composable/reusable swarm teams** ⭐ NEW
200
+ → [Composable Swarms Guide](guides/composable-swarms.md)
201
+
183
202
  **Build a SwarmSDK plugin**
184
203
  → [Plugin System Guide](guides/plugins.md)
185
204
 
186
205
  **Build a custom storage adapter**
187
206
  → [Memory Adapter Guide](guides/memory-adapters.md)
188
207
 
208
+ **Secure swarms for production** ⭐ NEW
209
+ → [Filesystem Tools Control](reference/ruby-dsl.md#swarmsdk.configure) | [Security Considerations](guides/complete-tutorial.md#security-considerations)
210
+
189
211
  **Understand the system architecture**
190
212
  → [Architecture Flow Diagram](reference/architecture-flow.md)
191
213
 
@@ -204,6 +226,7 @@ docs/v2/
204
226
  │ ├── getting-started.md # SDK quick start (YAML + Ruby DSL)
205
227
  │ ├── quick-start-cli.md # CLI quick start
206
228
  │ ├── complete-tutorial.md # 100% feature coverage tutorial
229
+ │ ├── composable-swarms.md # Composable swarms guide ⭐ NEW
207
230
  │ ├── swarm-memory.md # SwarmMemory guide ⭐
208
231
  │ ├── plugins.md # Plugin system guide ⭐
209
232
  │ ├── memory-adapters.md # Adapter development ⭐
@@ -236,8 +259,9 @@ docs/v2/
236
259
 
237
260
  ### Path 2: Intermediate → Advanced
238
261
  1. [Complete Tutorial Parts 4-6](guides/complete-tutorial.md) - Hooks, workflows, advanced config
239
- 2. [Rails Integration](guides/rails-integration.md) - Production integration patterns
240
- 3. [Complete Tutorial Parts 7-8](guides/complete-tutorial.md) - Production features and best practices
262
+ 2. [Composable Swarms Guide](guides/composable-swarms.md) ⭐ NEW - Build reusable swarm teams
263
+ 3. [Rails Integration](guides/rails-integration.md) - Production integration patterns
264
+ 4. [Complete Tutorial Parts 7-8](guides/complete-tutorial.md) - Production features and best practices
241
265
 
242
266
  ### Path 3: SwarmMemory Deep Dive
243
267
  1. [SwarmMemory Guide](guides/swarm-memory.md) - Installation, memory tools, usage patterns
@@ -260,7 +284,8 @@ docs/v2/
260
284
  A Ruby framework for orchestrating multiple AI agents that work together as a team. Each agent has:
261
285
  - **Role**: Specialized expertise (backend developer, code reviewer, etc.)
262
286
  - **Tools**: Capabilities (Read files, Write files, Run bash commands, etc.)
263
- - **Delegation**: Ability to delegate subtasks to other agents
287
+ - **Delegation**: Ability to delegate subtasks to other agents or swarms
288
+ - **Composable Swarms**: Build hierarchies by delegating to reusable swarm components ⭐ NEW
264
289
  - **Hooks**: Custom logic that runs at key points in execution
265
290
 
266
291
  ### SwarmCLI
@@ -295,8 +320,9 @@ A persistent memory system for agents with semantic search capabilities:
295
320
  | **Tools** | [Tutorial Part 2](guides/complete-tutorial.md#part-2-tools-and-permissions) | [YAML Ref](reference/yaml.md#tools) |
296
321
  | **Permissions** | [Tutorial Part 2](guides/complete-tutorial.md#permissions-system) | [YAML Ref](reference/yaml.md#permissions-configuration) |
297
322
  | **Delegation** | [Tutorial Part 3](guides/complete-tutorial.md#part-3-agent-collaboration) | [Ruby DSL Ref](reference/ruby-dsl.md#delegates_to) |
323
+ | **Composable Swarms** ⭐ | [Composable Swarms Guide](guides/composable-swarms.md) | [Ruby DSL Ref](reference/ruby-dsl.md#swarms) · [YAML Ref](reference/yaml.md#swarms) |
298
324
  | **Hooks** | [Tutorial Part 4](guides/complete-tutorial.md#part-4-hooks-system) | [YAML Ref](reference/yaml.md#hooks-configuration) |
299
- | **Workflows** | [Tutorial Part 5](guides/complete-tutorial.md#part-5-node-workflows) | [Ruby DSL Ref](reference/ruby-dsl.md#node-builder-dsl) |
325
+ | **Workflows** | [Tutorial Part 5](guides/complete-tutorial.md#part-5-node-workflows) | [YAML Ref](reference/yaml.md#nodes) · [Ruby DSL Ref](reference/ruby-dsl.md#node-builder-dsl) |
300
326
  | **MCP Servers** | [Tutorial Part 6](guides/complete-tutorial.md#mcp-server-integration) | [YAML Ref](reference/yaml.md#mcp_servers) |
301
327
  | **Memory** | [SwarmMemory Guide](guides/swarm-memory.md) | [Technical Details](reference/swarm_memory_technical_details.md) |
302
328
  | **Memory Adapters** | [Adapter Guide](guides/memory-adapters.md) | [Technical Details](reference/swarm_memory_technical_details.md) |