swarm_memory 2.1.5 → 2.1.6

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 (182) hide show
  1. checksums.yaml +4 -4
  2. data/lib/swarm_memory/version.rb +1 -1
  3. metadata +5 -184
  4. data/lib/claude_swarm/base_executor.rb +0 -133
  5. data/lib/claude_swarm/claude_code_executor.rb +0 -349
  6. data/lib/claude_swarm/claude_mcp_server.rb +0 -78
  7. data/lib/claude_swarm/cli.rb +0 -697
  8. data/lib/claude_swarm/commands/ps.rb +0 -215
  9. data/lib/claude_swarm/commands/show.rb +0 -139
  10. data/lib/claude_swarm/configuration.rb +0 -373
  11. data/lib/claude_swarm/hooks/session_start_hook.rb +0 -42
  12. data/lib/claude_swarm/json_handler.rb +0 -91
  13. data/lib/claude_swarm/mcp_generator.rb +0 -230
  14. data/lib/claude_swarm/openai/chat_completion.rb +0 -256
  15. data/lib/claude_swarm/openai/executor.rb +0 -256
  16. data/lib/claude_swarm/openai/responses.rb +0 -319
  17. data/lib/claude_swarm/orchestrator.rb +0 -878
  18. data/lib/claude_swarm/process_tracker.rb +0 -78
  19. data/lib/claude_swarm/session_cost_calculator.rb +0 -209
  20. data/lib/claude_swarm/session_path.rb +0 -42
  21. data/lib/claude_swarm/settings_generator.rb +0 -77
  22. data/lib/claude_swarm/system_utils.rb +0 -46
  23. data/lib/claude_swarm/templates/generation_prompt.md.erb +0 -230
  24. data/lib/claude_swarm/tools/reset_session_tool.rb +0 -24
  25. data/lib/claude_swarm/tools/session_info_tool.rb +0 -24
  26. data/lib/claude_swarm/tools/task_tool.rb +0 -63
  27. data/lib/claude_swarm/version.rb +0 -5
  28. data/lib/claude_swarm/worktree_manager.rb +0 -475
  29. data/lib/claude_swarm/yaml_loader.rb +0 -22
  30. data/lib/claude_swarm.rb +0 -67
  31. data/lib/swarm_cli/cli.rb +0 -201
  32. data/lib/swarm_cli/command_registry.rb +0 -61
  33. data/lib/swarm_cli/commands/mcp_serve.rb +0 -130
  34. data/lib/swarm_cli/commands/mcp_tools.rb +0 -148
  35. data/lib/swarm_cli/commands/migrate.rb +0 -55
  36. data/lib/swarm_cli/commands/run.rb +0 -173
  37. data/lib/swarm_cli/config_loader.rb +0 -98
  38. data/lib/swarm_cli/formatters/human_formatter.rb +0 -781
  39. data/lib/swarm_cli/formatters/json_formatter.rb +0 -51
  40. data/lib/swarm_cli/interactive_repl.rb +0 -924
  41. data/lib/swarm_cli/mcp_serve_options.rb +0 -44
  42. data/lib/swarm_cli/mcp_tools_options.rb +0 -59
  43. data/lib/swarm_cli/migrate_options.rb +0 -54
  44. data/lib/swarm_cli/migrator.rb +0 -132
  45. data/lib/swarm_cli/options.rb +0 -151
  46. data/lib/swarm_cli/ui/components/agent_badge.rb +0 -33
  47. data/lib/swarm_cli/ui/components/content_block.rb +0 -120
  48. data/lib/swarm_cli/ui/components/divider.rb +0 -57
  49. data/lib/swarm_cli/ui/components/panel.rb +0 -62
  50. data/lib/swarm_cli/ui/components/usage_stats.rb +0 -70
  51. data/lib/swarm_cli/ui/formatters/cost.rb +0 -49
  52. data/lib/swarm_cli/ui/formatters/number.rb +0 -58
  53. data/lib/swarm_cli/ui/formatters/text.rb +0 -77
  54. data/lib/swarm_cli/ui/formatters/time.rb +0 -73
  55. data/lib/swarm_cli/ui/icons.rb +0 -36
  56. data/lib/swarm_cli/ui/renderers/event_renderer.rb +0 -188
  57. data/lib/swarm_cli/ui/state/agent_color_cache.rb +0 -45
  58. data/lib/swarm_cli/ui/state/depth_tracker.rb +0 -40
  59. data/lib/swarm_cli/ui/state/spinner_manager.rb +0 -170
  60. data/lib/swarm_cli/ui/state/usage_tracker.rb +0 -62
  61. data/lib/swarm_cli/version.rb +0 -5
  62. data/lib/swarm_cli.rb +0 -46
  63. data/lib/swarm_sdk/agent/RETRY_LOGIC.md +0 -127
  64. data/lib/swarm_sdk/agent/builder.rb +0 -552
  65. data/lib/swarm_sdk/agent/chat.rb +0 -774
  66. data/lib/swarm_sdk/agent/chat_helpers/context_tracker.rb +0 -268
  67. data/lib/swarm_sdk/agent/chat_helpers/event_emitter.rb +0 -204
  68. data/lib/swarm_sdk/agent/chat_helpers/hook_integration.rb +0 -480
  69. data/lib/swarm_sdk/agent/chat_helpers/instrumentation.rb +0 -78
  70. data/lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb +0 -233
  71. data/lib/swarm_sdk/agent/chat_helpers/logging_helpers.rb +0 -116
  72. data/lib/swarm_sdk/agent/chat_helpers/serialization.rb +0 -83
  73. data/lib/swarm_sdk/agent/chat_helpers/system_reminder_injector.rb +0 -136
  74. data/lib/swarm_sdk/agent/chat_helpers/system_reminders.rb +0 -79
  75. data/lib/swarm_sdk/agent/chat_helpers/token_tracking.rb +0 -98
  76. data/lib/swarm_sdk/agent/context.rb +0 -116
  77. data/lib/swarm_sdk/agent/context_manager.rb +0 -315
  78. data/lib/swarm_sdk/agent/definition.rb +0 -477
  79. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +0 -182
  80. data/lib/swarm_sdk/agent/system_prompt_builder.rb +0 -161
  81. data/lib/swarm_sdk/builders/base_builder.rb +0 -409
  82. data/lib/swarm_sdk/claude_code_agent_adapter.rb +0 -205
  83. data/lib/swarm_sdk/concerns/cleanupable.rb +0 -39
  84. data/lib/swarm_sdk/concerns/snapshotable.rb +0 -67
  85. data/lib/swarm_sdk/concerns/validatable.rb +0 -55
  86. data/lib/swarm_sdk/configuration/parser.rb +0 -353
  87. data/lib/swarm_sdk/configuration/translator.rb +0 -255
  88. data/lib/swarm_sdk/configuration.rb +0 -135
  89. data/lib/swarm_sdk/context_compactor/metrics.rb +0 -147
  90. data/lib/swarm_sdk/context_compactor/token_counter.rb +0 -106
  91. data/lib/swarm_sdk/context_compactor.rb +0 -335
  92. data/lib/swarm_sdk/context_management/builder.rb +0 -128
  93. data/lib/swarm_sdk/context_management/context.rb +0 -328
  94. data/lib/swarm_sdk/defaults.rb +0 -196
  95. data/lib/swarm_sdk/events_to_messages.rb +0 -199
  96. data/lib/swarm_sdk/hooks/adapter.rb +0 -359
  97. data/lib/swarm_sdk/hooks/context.rb +0 -197
  98. data/lib/swarm_sdk/hooks/definition.rb +0 -80
  99. data/lib/swarm_sdk/hooks/error.rb +0 -29
  100. data/lib/swarm_sdk/hooks/executor.rb +0 -146
  101. data/lib/swarm_sdk/hooks/registry.rb +0 -147
  102. data/lib/swarm_sdk/hooks/result.rb +0 -150
  103. data/lib/swarm_sdk/hooks/shell_executor.rb +0 -255
  104. data/lib/swarm_sdk/hooks/tool_call.rb +0 -35
  105. data/lib/swarm_sdk/hooks/tool_result.rb +0 -62
  106. data/lib/swarm_sdk/log_collector.rb +0 -227
  107. data/lib/swarm_sdk/log_stream.rb +0 -127
  108. data/lib/swarm_sdk/markdown_parser.rb +0 -75
  109. data/lib/swarm_sdk/model_aliases.json +0 -8
  110. data/lib/swarm_sdk/models.json +0 -1
  111. data/lib/swarm_sdk/models.rb +0 -120
  112. data/lib/swarm_sdk/node_context.rb +0 -245
  113. data/lib/swarm_sdk/observer/builder.rb +0 -81
  114. data/lib/swarm_sdk/observer/config.rb +0 -45
  115. data/lib/swarm_sdk/observer/manager.rb +0 -236
  116. data/lib/swarm_sdk/patterns/agent_observer.rb +0 -160
  117. data/lib/swarm_sdk/permissions/config.rb +0 -239
  118. data/lib/swarm_sdk/permissions/error_formatter.rb +0 -121
  119. data/lib/swarm_sdk/permissions/path_matcher.rb +0 -35
  120. data/lib/swarm_sdk/permissions/validator.rb +0 -173
  121. data/lib/swarm_sdk/permissions_builder.rb +0 -122
  122. data/lib/swarm_sdk/plugin.rb +0 -309
  123. data/lib/swarm_sdk/plugin_registry.rb +0 -101
  124. data/lib/swarm_sdk/proc_helpers.rb +0 -53
  125. data/lib/swarm_sdk/prompts/base_system_prompt.md.erb +0 -117
  126. data/lib/swarm_sdk/restore_result.rb +0 -65
  127. data/lib/swarm_sdk/result.rb +0 -123
  128. data/lib/swarm_sdk/snapshot.rb +0 -156
  129. data/lib/swarm_sdk/snapshot_from_events.rb +0 -397
  130. data/lib/swarm_sdk/state_restorer.rb +0 -476
  131. data/lib/swarm_sdk/state_snapshot.rb +0 -334
  132. data/lib/swarm_sdk/swarm/agent_initializer.rb +0 -683
  133. data/lib/swarm_sdk/swarm/all_agents_builder.rb +0 -167
  134. data/lib/swarm_sdk/swarm/builder.rb +0 -249
  135. data/lib/swarm_sdk/swarm/executor.rb +0 -213
  136. data/lib/swarm_sdk/swarm/hook_triggers.rb +0 -150
  137. data/lib/swarm_sdk/swarm/logging_callbacks.rb +0 -340
  138. data/lib/swarm_sdk/swarm/mcp_configurator.rb +0 -154
  139. data/lib/swarm_sdk/swarm/swarm_registry_builder.rb +0 -67
  140. data/lib/swarm_sdk/swarm/tool_configurator.rb +0 -358
  141. data/lib/swarm_sdk/swarm.rb +0 -717
  142. data/lib/swarm_sdk/swarm_loader.rb +0 -145
  143. data/lib/swarm_sdk/swarm_registry.rb +0 -136
  144. data/lib/swarm_sdk/tools/bash.rb +0 -282
  145. data/lib/swarm_sdk/tools/clock.rb +0 -44
  146. data/lib/swarm_sdk/tools/delegate.rb +0 -267
  147. data/lib/swarm_sdk/tools/document_converters/base_converter.rb +0 -83
  148. data/lib/swarm_sdk/tools/document_converters/docx_converter.rb +0 -99
  149. data/lib/swarm_sdk/tools/document_converters/html_converter.rb +0 -101
  150. data/lib/swarm_sdk/tools/document_converters/pdf_converter.rb +0 -78
  151. data/lib/swarm_sdk/tools/document_converters/xlsx_converter.rb +0 -194
  152. data/lib/swarm_sdk/tools/edit.rb +0 -145
  153. data/lib/swarm_sdk/tools/glob.rb +0 -166
  154. data/lib/swarm_sdk/tools/grep.rb +0 -235
  155. data/lib/swarm_sdk/tools/image_extractors/docx_image_extractor.rb +0 -43
  156. data/lib/swarm_sdk/tools/image_extractors/pdf_image_extractor.rb +0 -163
  157. data/lib/swarm_sdk/tools/image_formats/tiff_builder.rb +0 -65
  158. data/lib/swarm_sdk/tools/multi_edit.rb +0 -236
  159. data/lib/swarm_sdk/tools/path_resolver.rb +0 -92
  160. data/lib/swarm_sdk/tools/read.rb +0 -261
  161. data/lib/swarm_sdk/tools/registry.rb +0 -205
  162. data/lib/swarm_sdk/tools/scratchpad/scratchpad_list.rb +0 -117
  163. data/lib/swarm_sdk/tools/scratchpad/scratchpad_read.rb +0 -97
  164. data/lib/swarm_sdk/tools/scratchpad/scratchpad_write.rb +0 -108
  165. data/lib/swarm_sdk/tools/stores/read_tracker.rb +0 -96
  166. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +0 -272
  167. data/lib/swarm_sdk/tools/stores/storage.rb +0 -142
  168. data/lib/swarm_sdk/tools/stores/todo_manager.rb +0 -65
  169. data/lib/swarm_sdk/tools/think.rb +0 -98
  170. data/lib/swarm_sdk/tools/todo_write.rb +0 -235
  171. data/lib/swarm_sdk/tools/web_fetch.rb +0 -262
  172. data/lib/swarm_sdk/tools/write.rb +0 -112
  173. data/lib/swarm_sdk/utils.rb +0 -68
  174. data/lib/swarm_sdk/validation_result.rb +0 -33
  175. data/lib/swarm_sdk/version.rb +0 -5
  176. data/lib/swarm_sdk/workflow/agent_config.rb +0 -79
  177. data/lib/swarm_sdk/workflow/builder.rb +0 -143
  178. data/lib/swarm_sdk/workflow/executor.rb +0 -497
  179. data/lib/swarm_sdk/workflow/node_builder.rb +0 -555
  180. data/lib/swarm_sdk/workflow/transformer_executor.rb +0 -249
  181. data/lib/swarm_sdk/workflow.rb +0 -554
  182. data/lib/swarm_sdk.rb +0 -524
data/lib/swarm_sdk.rb DELETED
@@ -1,524 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler"
4
- require "digest"
5
- require "English"
6
- require "erb"
7
- require "fileutils"
8
- require "json"
9
- require "logger"
10
- require "pathname"
11
- require "securerandom"
12
- require "set"
13
- require "yaml"
14
-
15
- require "async"
16
- require "async/semaphore"
17
- require "ruby_llm"
18
- require "ruby_llm/mcp"
19
-
20
- # Patch ruby_llm-mcp's Zeitwerk loader to ignore railtie.rb when Rails is not present
21
- # This prevents NameError when eager loading outside of Rails applications
22
- # Can be removed once https://github.com/parruda/ruby_llm-mcp/issues/XXX is fixed
23
- unless defined?(Rails)
24
- require "zeitwerk"
25
- mcp_loader = nil
26
- Zeitwerk::Registry.loaders.each { |l| mcp_loader = l if l.tag == "RubyLLM-mcp" }
27
- if mcp_loader
28
- mcp_gem_dir = Gem.loaded_specs["ruby_llm-mcp"]&.gem_dir
29
- if mcp_gem_dir
30
- railtie_path = File.join(mcp_gem_dir, "lib", "ruby_llm", "mcp", "railtie.rb")
31
- mcp_loader.ignore(railtie_path)
32
- end
33
- end
34
- end
35
-
36
- # Configure Faraday to use async-http adapter by default
37
- # This ensures HTTP requests are fiber-aware and don't block the Async scheduler
38
- # when SwarmSDK executes LLM requests within Async/Sync blocks
39
- require "async/http/faraday/default"
40
-
41
- require_relative "swarm_sdk/version"
42
-
43
- require "zeitwerk"
44
- loader = Zeitwerk::Loader.new
45
- loader.tag = File.basename(__FILE__, ".rb")
46
- loader.push_dir("#{__dir__}/swarm_sdk", namespace: SwarmSDK)
47
- loader.inflector = Zeitwerk::GemInflector.new(__FILE__)
48
- loader.inflector.inflect(
49
- "cli" => "CLI",
50
- "llm_instrumentation_middleware" => "LLMInstrumentationMiddleware",
51
- "mcp" => "MCP",
52
- "openai_with_responses" => "OpenAIWithResponses",
53
- )
54
- loader.setup
55
-
56
- module SwarmSDK
57
- class Error < StandardError; end
58
- class ConfigurationError < Error; end
59
- class AgentNotFoundError < Error; end
60
- class CircularDependencyError < Error; end
61
- class ToolExecutionError < Error; end
62
- class LLMError < Error; end
63
- class StateError < Error; end
64
-
65
- class << self
66
- # Settings for SwarmSDK (global configuration)
67
- attr_accessor :settings
68
-
69
- # Main entry point for DSL - builds simple multi-agent swarms
70
- #
71
- # @return [Swarm] Always returns a Swarm instance
72
- def build(allow_filesystem_tools: nil, &block)
73
- Swarm::Builder.build(allow_filesystem_tools: allow_filesystem_tools, &block)
74
- end
75
-
76
- # Entry point for building multi-stage workflows
77
- #
78
- # @return [Workflow] Always returns a Workflow instance
79
- def workflow(allow_filesystem_tools: nil, &block)
80
- Workflow::Builder.build(allow_filesystem_tools: allow_filesystem_tools, &block)
81
- end
82
-
83
- # Validate YAML configuration without creating a swarm
84
- #
85
- # Performs comprehensive validation of YAML configuration including:
86
- # - YAML syntax
87
- # - Required fields (version, swarm name, lead, agents)
88
- # - Agent configurations (description, directory existence)
89
- # - Circular dependencies
90
- # - File references (agent_file paths)
91
- # - Hook configurations
92
- #
93
- # @param yaml_content [String] YAML configuration content
94
- # @param base_dir [String, Pathname] Base directory for resolving agent file paths (default: Dir.pwd)
95
- # @return [Array<Hash>] Array of error hashes (empty if valid)
96
- #
97
- # @example Validate YAML string
98
- # errors = SwarmSDK.validate(yaml_content)
99
- # if errors.empty?
100
- # puts "Configuration is valid!"
101
- # else
102
- # errors.each do |error|
103
- # puts "#{error[:field]}: #{error[:message]}"
104
- # end
105
- # end
106
- #
107
- # @example Error hash structure
108
- # {
109
- # type: :missing_field, # Error type
110
- # field: "swarm.agents.backend.description", # JSON-style path to field
111
- # message: "Agent 'backend' missing required 'description' field",
112
- # agent: "backend" # Optional, present if error is agent-specific
113
- # }
114
- def validate(yaml_content, base_dir: Dir.pwd)
115
- errors = []
116
-
117
- begin
118
- config = Configuration.new(yaml_content, base_dir: base_dir)
119
- config.load_and_validate
120
-
121
- # Build swarm to trigger DSL validation
122
- # This catches errors from Agent::Definition, Builder, etc.
123
- config.to_swarm
124
- rescue ConfigurationError, CircularDependencyError => e
125
- errors << parse_configuration_error(e)
126
- rescue StandardError => e
127
- errors << {
128
- type: :unknown_error,
129
- field: nil,
130
- message: e.message,
131
- }
132
- end
133
-
134
- errors
135
- end
136
-
137
- # Validate YAML configuration file
138
- #
139
- # Convenience method that reads the file and validates the content.
140
- #
141
- # @param path [String, Pathname] Path to YAML configuration file
142
- # @return [Array<Hash>] Array of error hashes (empty if valid)
143
- #
144
- # @example
145
- # errors = SwarmSDK.validate_file("config.yml")
146
- # if errors.empty?
147
- # puts "Valid configuration!"
148
- # swarm = SwarmSDK.load_file("config.yml")
149
- # else
150
- # errors.each { |e| puts "Error: #{e[:message]}" }
151
- # end
152
- def validate_file(path)
153
- path = Pathname.new(path).expand_path
154
-
155
- unless path.exist?
156
- return [{
157
- type: :file_not_found,
158
- field: nil,
159
- message: "Configuration file not found: #{path}",
160
- }]
161
- end
162
-
163
- yaml_content = File.read(path)
164
- base_dir = path.dirname
165
-
166
- validate(yaml_content, base_dir: base_dir)
167
- rescue StandardError => e
168
- [{
169
- type: :file_read_error,
170
- field: nil,
171
- message: "Error reading file: #{e.message}",
172
- }]
173
- end
174
-
175
- # Load swarm from YAML string
176
- #
177
- # This is the primary programmatic API for loading YAML configurations.
178
- # For file-based loading, use SwarmSDK.load_file for convenience.
179
- #
180
- # @param yaml_content [String] YAML configuration content
181
- # @param base_dir [String, Pathname] Base directory for resolving agent file paths (default: Dir.pwd)
182
- # @return [Swarm, Workflow] Configured swarm or workflow instance
183
- # @raise [ConfigurationError] If YAML is invalid or configuration is incorrect
184
- #
185
- # @example Load from YAML string
186
- # yaml = <<~YAML
187
- # version: 2
188
- # swarm:
189
- # name: "Dev Team"
190
- # lead: backend
191
- # agents:
192
- # backend:
193
- # description: "Backend developer"
194
- # model: "gpt-4"
195
- # agent_file: "agents/backend.md" # Resolved relative to base_dir
196
- # YAML
197
- #
198
- # swarm = SwarmSDK.load(yaml, base_dir: "/path/to/project")
199
- # result = swarm.execute("Build authentication")
200
- #
201
- # @example Load with default base_dir (Dir.pwd)
202
- # yaml = File.read("config.yml")
203
- # swarm = SwarmSDK.load(yaml) # base_dir defaults to Dir.pwd
204
- def load(yaml_content, base_dir: Dir.pwd, allow_filesystem_tools: nil)
205
- config = Configuration.new(yaml_content, base_dir: base_dir)
206
- config.load_and_validate
207
- swarm = config.to_swarm(allow_filesystem_tools: allow_filesystem_tools)
208
-
209
- # Apply hooks if any are configured (YAML-only feature)
210
- if hooks_configured?(config)
211
- Hooks::Adapter.apply_hooks(swarm, config)
212
- end
213
-
214
- # Store config reference for agent hooks (applied during initialize_agents)
215
- swarm.config_for_hooks = config
216
-
217
- swarm
218
- end
219
-
220
- # Load swarm from YAML file (convenience method)
221
- #
222
- # Reads the YAML file and uses the file's directory as the base directory
223
- # for resolving agent file paths. This is the recommended method for
224
- # loading swarms from configuration files.
225
- #
226
- # @param path [String, Pathname] Path to YAML configuration file
227
- # @return [Swarm, Workflow] Configured swarm or workflow instance
228
- # @raise [ConfigurationError] If file not found or configuration invalid
229
- #
230
- # @example
231
- # swarm = SwarmSDK.load_file("config.yml")
232
- # result = swarm.execute("Build authentication")
233
- #
234
- # @example With absolute path
235
- # swarm = SwarmSDK.load_file("/absolute/path/config.yml")
236
- def load_file(path, allow_filesystem_tools: nil)
237
- config = Configuration.load_file(path)
238
- swarm = config.to_swarm(allow_filesystem_tools: allow_filesystem_tools)
239
-
240
- # Apply hooks if any are configured (YAML-only feature)
241
- if hooks_configured?(config)
242
- Hooks::Adapter.apply_hooks(swarm, config)
243
- end
244
-
245
- # Store config reference for agent hooks (applied during initialize_agents)
246
- swarm.config_for_hooks = config
247
-
248
- swarm
249
- end
250
-
251
- # Configure SwarmSDK global settings
252
- def configure
253
- self.settings ||= Settings.new
254
- yield(settings)
255
- end
256
-
257
- # Reset settings to defaults
258
- def reset_settings!
259
- self.settings = Settings.new
260
- end
261
-
262
- # Alias for backward compatibility
263
- alias_method :configuration, :settings
264
- alias_method :reset_configuration!, :reset_settings!
265
-
266
- private
267
-
268
- # Check if hooks are configured in the configuration
269
- #
270
- # @param config [Configuration] Configuration instance
271
- # @return [Boolean] true if any hooks are configured
272
- def hooks_configured?(config)
273
- config.swarm_hooks.any? ||
274
- config.all_agents_hooks.any? ||
275
- config.agents.any? { |_, agent_config| agent_config[:hooks]&.any? }
276
- end
277
-
278
- # Parse configuration error and extract structured information
279
- #
280
- # Attempts to extract field path and agent name from error messages.
281
- # Returns a structured error hash with type, field, message, and optional agent.
282
- #
283
- # @param error [StandardError] The caught error
284
- # @return [Hash] Structured error hash
285
- def parse_configuration_error(error)
286
- message = error.message
287
- error_hash = { message: message }
288
-
289
- # Detect error type and extract field information
290
- case message
291
- # YAML syntax errors
292
- when /Invalid YAML syntax/i
293
- error_hash.merge!(
294
- type: :syntax_error,
295
- field: nil,
296
- )
297
-
298
- # Missing version field
299
- when /Missing 'version' field/i
300
- error_hash.merge!(
301
- type: :missing_field,
302
- field: "version",
303
- )
304
-
305
- # Invalid version
306
- when /SwarmSDK requires version: (\d+)/i
307
- error_hash.merge!(
308
- type: :invalid_value,
309
- field: "version",
310
- )
311
-
312
- # Missing swarm fields
313
- when /Missing '(\w+)' field in swarm configuration/i
314
- field_name = Regexp.last_match(1)
315
- error_hash.merge!(
316
- type: :missing_field,
317
- field: "swarm.#{field_name}",
318
- )
319
-
320
- # Agent missing required field
321
- when /Agent '([^']+)' missing required '([^']+)' field/i
322
- agent_name = Regexp.last_match(1)
323
- field_name = Regexp.last_match(2)
324
- error_hash.merge!(
325
- type: :missing_field,
326
- field: "swarm.agents.#{agent_name}.#{field_name}",
327
- agent: agent_name,
328
- )
329
-
330
- # Directory does not exist
331
- when /Directory '([^']+)' for agent '([^']+)' does not exist/i
332
- agent_name = Regexp.last_match(2)
333
- error_hash.merge!(
334
- type: :directory_not_found,
335
- field: "swarm.agents.#{agent_name}.directory",
336
- agent: agent_name,
337
- )
338
-
339
- # Error loading agent from file (must come before "Agent file not found")
340
- when /Error loading agent '([^']+)' from file/i
341
- agent_name = Regexp.last_match(1)
342
- error_hash.merge!(
343
- type: :file_load_error,
344
- field: "swarm.agents.#{agent_name}.agent_file",
345
- agent: agent_name,
346
- )
347
-
348
- # Agent file not found
349
- when /Agent file not found: (.+)/i
350
- # Try to extract agent name from the error context if available
351
- error_hash.merge!(
352
- type: :file_not_found,
353
- field: nil, # We don't know which agent without more context
354
- )
355
-
356
- # Lead agent not found
357
- when /Lead agent '([^']+)' not found in agents/i
358
- error_hash.merge!(
359
- type: :invalid_reference,
360
- field: "swarm.lead",
361
- )
362
-
363
- # Unknown agent in connections (old format)
364
- when /Agent '([^']+)' has connection to unknown agent '([^']+)'/i
365
- agent_name = Regexp.last_match(1)
366
- error_hash.merge!(
367
- type: :invalid_reference,
368
- field: "swarm.agents.#{agent_name}.delegates_to",
369
- agent: agent_name,
370
- )
371
-
372
- # Unknown agent in connections (new format with composable swarms)
373
- when /Agent '([^']+)' delegates to unknown target '([^']+)'/i
374
- agent_name = Regexp.last_match(1)
375
- error_hash.merge!(
376
- type: :invalid_reference,
377
- field: "swarm.agents.#{agent_name}.delegates_to",
378
- agent: agent_name,
379
- )
380
-
381
- # Circular dependency
382
- when /Circular dependency detected/i
383
- error_hash.merge!(
384
- type: :circular_dependency,
385
- field: nil,
386
- )
387
-
388
- # Configuration file not found
389
- when /Configuration file not found/i
390
- error_hash.merge!(
391
- type: :file_not_found,
392
- field: nil,
393
- )
394
-
395
- # Invalid hook event
396
- when /Invalid hook event '([^']+)' for agent '([^']+)'/i
397
- agent_name = Regexp.last_match(2)
398
- error_hash.merge!(
399
- type: :invalid_value,
400
- field: "swarm.agents.#{agent_name}.hooks",
401
- agent: agent_name,
402
- )
403
-
404
- # api_version validation error
405
- when /Agent '([^']+)' has api_version set, but provider is/i
406
- agent_name = Regexp.last_match(1)
407
- error_hash.merge!(
408
- type: :invalid_value,
409
- field: "swarm.agents.#{agent_name}.api_version",
410
- agent: agent_name,
411
- )
412
-
413
- # api_version invalid value
414
- when /Agent '([^']+)' has invalid api_version/i
415
- agent_name = Regexp.last_match(1)
416
- error_hash.merge!(
417
- type: :invalid_value,
418
- field: "swarm.agents.#{agent_name}.api_version",
419
- agent: agent_name,
420
- )
421
-
422
- # No agents defined
423
- when /No agents defined/i
424
- error_hash.merge!(
425
- type: :missing_field,
426
- field: "swarm.agents",
427
- )
428
-
429
- # Default: unknown error
430
- else
431
- error_hash.merge!(
432
- type: :validation_error,
433
- field: nil,
434
- )
435
- end
436
-
437
- error_hash.compact
438
- end
439
- end
440
-
441
- # Settings class for SwarmSDK global settings (not to be confused with Configuration for YAML loading)
442
- class Settings
443
- # WebFetch tool LLM processing configuration
444
- attr_accessor :webfetch_provider, :webfetch_model, :webfetch_base_url, :webfetch_max_tokens
445
-
446
- # Filesystem tools control
447
- attr_accessor :allow_filesystem_tools
448
-
449
- def initialize
450
- @webfetch_provider = nil
451
- @webfetch_model = nil
452
- @webfetch_base_url = nil
453
- @webfetch_max_tokens = 4096
454
- @allow_filesystem_tools = parse_env_bool("SWARM_SDK_ALLOW_FILESYSTEM_TOOLS", default: true)
455
- end
456
-
457
- # Check if WebFetch LLM processing is enabled
458
- def webfetch_llm_enabled?
459
- !@webfetch_provider.nil? && !@webfetch_model.nil?
460
- end
461
-
462
- private
463
-
464
- def parse_env_bool(key, default:)
465
- return default unless ENV.key?(key)
466
-
467
- value = ENV[key].to_s.downcase
468
- return true if ["true", "yes", "1", "on", "enabled"].include?(value)
469
- return false if ["false", "no", "0", "off", "disabled"].include?(value)
470
-
471
- default
472
- end
473
- end
474
-
475
- # Initialize default settings
476
- self.settings = Settings.new
477
- end
478
-
479
- # Automatically configure RubyLLM from environment variables
480
- # This makes SwarmSDK "just work" when users set standard ENV variables
481
- RubyLLM.configure do |config|
482
- # Only set if config not already set (||= handles nil ENV values gracefully)
483
-
484
- # OpenAI
485
- config.openai_api_key ||= ENV["OPENAI_API_KEY"]
486
- config.openai_api_base ||= ENV["OPENAI_API_BASE"]
487
- config.openai_organization_id ||= ENV["OPENAI_ORG_ID"]
488
- config.openai_project_id ||= ENV["OPENAI_PROJECT_ID"]
489
-
490
- # Anthropic
491
- config.anthropic_api_key ||= ENV["ANTHROPIC_API_KEY"]
492
-
493
- # Google Gemini
494
- config.gemini_api_key ||= ENV["GEMINI_API_KEY"]
495
-
496
- # Google Vertex AI (note: vertexai, not vertex_ai)
497
- config.vertexai_project_id ||= ENV["GOOGLE_CLOUD_PROJECT"] || ENV["VERTEXAI_PROJECT_ID"]
498
- config.vertexai_location ||= ENV["GOOGLE_CLOUD_LOCATION"] || ENV["VERTEXAI_LOCATION"]
499
-
500
- # DeepSeek
501
- config.deepseek_api_key ||= ENV["DEEPSEEK_API_KEY"]
502
-
503
- # Mistral
504
- config.mistral_api_key ||= ENV["MISTRAL_API_KEY"]
505
-
506
- # Perplexity
507
- config.perplexity_api_key ||= ENV["PERPLEXITY_API_KEY"]
508
-
509
- # OpenRouter
510
- config.openrouter_api_key ||= ENV["OPENROUTER_API_KEY"]
511
-
512
- # AWS Bedrock
513
- config.bedrock_api_key ||= ENV["AWS_ACCESS_KEY_ID"]
514
- config.bedrock_secret_key ||= ENV["AWS_SECRET_ACCESS_KEY"]
515
- config.bedrock_region ||= ENV["AWS_REGION"]
516
- config.bedrock_session_token ||= ENV["AWS_SESSION_TOKEN"]
517
-
518
- # Ollama (local)
519
- config.ollama_api_base ||= ENV["OLLAMA_API_BASE"]
520
-
521
- # GPUStack (local)
522
- config.gpustack_api_base ||= ENV["GPUSTACK_API_BASE"]
523
- config.gpustack_api_key ||= ENV["GPUSTACK_API_KEY"]
524
- end