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
@@ -1,328 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SwarmSDK
4
- module ContextManagement
5
- # Rich context wrapper for context management handlers
6
- #
7
- # Provides a clean, developer-friendly API for manipulating the conversation
8
- # context when warning thresholds are triggered. Wraps the lower-level
9
- # Hooks::Context with message manipulation helpers.
10
- #
11
- # @example Basic usage in handler
12
- # on :warning_60 do |ctx|
13
- # ctx.compress_tool_results(keep_recent: 10)
14
- # end
15
- #
16
- # @example Advanced usage with metrics
17
- # on :warning_80 do |ctx|
18
- # if ctx.usage_percentage > 85
19
- # ctx.prune_old_messages(keep_recent: 10)
20
- # ctx.log_action("aggressive_pruning", remaining: ctx.tokens_remaining)
21
- # else
22
- # ctx.compress_tool_results(keep_recent: 5, truncate_to: 100)
23
- # end
24
- # end
25
- class Context
26
- # Create a new context wrapper
27
- #
28
- # @param hooks_context [Hooks::Context] Lower-level hook context with metadata
29
- def initialize(hooks_context)
30
- @hooks_context = hooks_context
31
- @chat = hooks_context.metadata[:chat]
32
- end
33
-
34
- # --- Context Metrics ---
35
-
36
- # Current context usage percentage
37
- #
38
- # @return [Float] Usage percentage (0.0 to 100.0)
39
- #
40
- # @example
41
- # if ctx.usage_percentage > 85
42
- # ctx.prune_old_messages(keep_recent: 10)
43
- # end
44
- def usage_percentage
45
- @hooks_context.metadata[:percentage]
46
- end
47
-
48
- # Threshold that triggered this handler
49
- #
50
- # @return [Integer] Threshold (60, 80, or 90)
51
- #
52
- # @example
53
- # ctx.log_action("threshold_hit", threshold: ctx.threshold)
54
- def threshold
55
- @hooks_context.metadata[:threshold]
56
- end
57
-
58
- # Total tokens used so far
59
- #
60
- # @return [Integer] Token count
61
- #
62
- # @example
63
- # ctx.log_action("usage", tokens: ctx.tokens_used)
64
- def tokens_used
65
- @hooks_context.metadata[:tokens_used]
66
- end
67
-
68
- # Tokens remaining in context window
69
- #
70
- # @return [Integer] Token count
71
- #
72
- # @example
73
- # if ctx.tokens_remaining < 10000
74
- # ctx.prune_old_messages(keep_recent: 5)
75
- # end
76
- def tokens_remaining
77
- @hooks_context.metadata[:tokens_remaining]
78
- end
79
-
80
- # Total context window size
81
- #
82
- # @return [Integer] Token count
83
- #
84
- # @example
85
- # buffer = ctx.context_limit * 0.1 # 10% buffer
86
- def context_limit
87
- @hooks_context.metadata[:context_limit]
88
- end
89
-
90
- # Agent name
91
- #
92
- # @return [Symbol] Agent identifier
93
- #
94
- # @example
95
- # ctx.log_action("agent_context", agent: ctx.agent_name)
96
- def agent_name
97
- @hooks_context.agent_name
98
- end
99
-
100
- # --- Message Access ---
101
-
102
- # Get all messages (copy for manipulation)
103
- #
104
- # @return [Array<RubyLLM::Message>] Message array
105
- #
106
- # @example
107
- # ctx.messages.each do |msg|
108
- # puts "#{msg.role}: #{msg.content.length} chars"
109
- # end
110
- def messages
111
- @chat.messages
112
- end
113
-
114
- # Number of messages
115
- #
116
- # @return [Integer] Message count
117
- #
118
- # @example
119
- # if ctx.message_count > 100
120
- # ctx.prune_old_messages(keep_recent: 50)
121
- # end
122
- def message_count
123
- @chat.message_count
124
- end
125
-
126
- # --- Message Manipulation ---
127
-
128
- # Replace all messages with new array
129
- #
130
- # @param new_messages [Array<RubyLLM::Message>] New message array
131
- # @return [void]
132
- #
133
- # @example
134
- # new_msgs = ctx.messages.reject { |m| m.role == :tool }
135
- # ctx.replace_messages(new_msgs)
136
- def replace_messages(new_messages)
137
- @chat.replace_messages(new_messages)
138
- end
139
-
140
- # Compress tool result messages to save context space
141
- #
142
- # Creates NEW message objects with truncated content (follows RubyLLM patterns).
143
- # Truncates old tool results while keeping recent ones intact.
144
- # Automatically marks compression as applied to prevent double compression.
145
- #
146
- # @param keep_recent [Integer] Number of recent tool results to preserve (default: 10)
147
- # @param truncate_to [Integer] Max characters for truncated results (default: 200)
148
- # @return [Integer] Number of messages compressed
149
- #
150
- # @example Light compression at 60%
151
- # ctx.compress_tool_results(keep_recent: 15, truncate_to: 500)
152
- #
153
- # @example Aggressive compression at 80%
154
- # ctx.compress_tool_results(keep_recent: 5, truncate_to: 100)
155
- def compress_tool_results(keep_recent: 10, truncate_to: 200)
156
- msgs = messages.dup
157
- compressed_count = 0
158
-
159
- # Find tool result messages (skip recent ones)
160
- tool_indices = []
161
- msgs.each_with_index do |msg, idx|
162
- tool_indices << idx if msg.role == :tool
163
- end
164
-
165
- # Keep recent tool results, compress older ones
166
- indices_to_compress = tool_indices[0...-keep_recent] || []
167
-
168
- indices_to_compress.each do |idx|
169
- msg = msgs[idx]
170
- content = msg.content.to_s
171
- next if content.length <= truncate_to
172
-
173
- # Create NEW message with truncated content (NO instance_variable_set!)
174
- truncated_content = "#{content[0...truncate_to]}... [truncated for context management]"
175
-
176
- # Create new message object following RubyLLM patterns
177
- msgs[idx] = RubyLLM::Message.new(
178
- role: :tool,
179
- content: truncated_content,
180
- tool_call_id: msg.tool_call_id,
181
- )
182
- compressed_count += 1
183
- end
184
-
185
- replace_messages(msgs)
186
-
187
- # Mark compression as applied to coordinate with ContextManager
188
- mark_compression_applied
189
-
190
- compressed_count
191
- end
192
-
193
- # Mark compression as applied in ContextManager
194
- #
195
- # Call this when your handler performs compression to prevent
196
- # double compression from auto-compression logic.
197
- #
198
- # @return [void]
199
- #
200
- # @example Custom compression
201
- # msgs = ctx.messages.map { |m| ... } # custom logic
202
- # ctx.replace_messages(msgs)
203
- # ctx.mark_compression_applied
204
- def mark_compression_applied
205
- return unless @chat.respond_to?(:context_manager)
206
-
207
- @chat.context_manager.compression_applied = true
208
- end
209
-
210
- # Check if compression has already been applied
211
- #
212
- # @return [Boolean] True if compression was already applied
213
- #
214
- # @example Conditional compression
215
- # unless ctx.compression_applied?
216
- # ctx.compress_tool_results(keep_recent: 10)
217
- # end
218
- def compression_applied?
219
- return false unless @chat.respond_to?(:context_manager)
220
-
221
- !!@chat.context_manager.compression_applied
222
- end
223
-
224
- # Remove old messages from history
225
- #
226
- # Keeps system message (if any) and recent exchanges.
227
- # This is more aggressive than compression and loses context.
228
- #
229
- # @param keep_recent [Integer] Number of recent messages to keep (default: 20)
230
- # @return [Integer] Number of messages removed
231
- #
232
- # @example Prune at 80% threshold
233
- # ctx.prune_old_messages(keep_recent: 30)
234
- #
235
- # @example Emergency pruning at 90%
236
- # ctx.prune_old_messages(keep_recent: 10)
237
- def prune_old_messages(keep_recent: 20)
238
- msgs = messages.dup
239
- original_count = msgs.size
240
-
241
- # Always keep system message if present
242
- system_msg = msgs.first if msgs.first&.role == :system
243
- non_system = system_msg ? msgs[1..] : msgs
244
-
245
- # Keep only recent messages
246
- if non_system.size > keep_recent
247
- kept = non_system.last(keep_recent)
248
- new_msgs = system_msg ? [system_msg] + kept : kept
249
- replace_messages(new_msgs)
250
- original_count - new_msgs.size
251
- else
252
- 0
253
- end
254
- end
255
-
256
- # Summarize old message exchanges
257
- #
258
- # Groups old user/assistant pairs and replaces with summary.
259
- # This is a placeholder - actual implementation would use LLM.
260
- #
261
- # @param older_than [Integer] Messages older than this index get summarized
262
- # @return [Integer] Number of exchanges summarized
263
- #
264
- # @example
265
- # ctx.summarize_old_exchanges(older_than: 10)
266
- def summarize_old_exchanges(older_than: 10)
267
- # For now, this is a marker - full implementation would call LLM
268
- # to summarize exchanges. We provide the API for developers to
269
- # implement their own summarization logic.
270
- 0
271
- end
272
-
273
- # Custom message transformation
274
- #
275
- # Apply a block to transform messages. This gives full control
276
- # over message manipulation for custom strategies.
277
- #
278
- # @yield [Array<RubyLLM::Message>] Current messages
279
- # @yieldreturn [Array<RubyLLM::Message>] Transformed messages
280
- # @return [void]
281
- #
282
- # @example Remove specific tool results
283
- # ctx.transform_messages do |msgs|
284
- # msgs.reject { |m| m.role == :tool && m.content.include?("verbose output") }
285
- # end
286
- #
287
- # @example Custom compression logic
288
- # ctx.transform_messages do |msgs|
289
- # msgs.map do |m|
290
- # if m.role == :tool && m.content.length > 1000
291
- # RubyLLM::Message.new(role: :tool, content: m.content[0..500], tool_call_id: m.tool_call_id)
292
- # else
293
- # m
294
- # end
295
- # end
296
- # end
297
- def transform_messages
298
- new_msgs = yield(messages.dup)
299
- replace_messages(new_msgs)
300
- end
301
-
302
- # Log a context management action
303
- #
304
- # Emits a log event for tracking what actions were taken.
305
- # Useful for debugging and monitoring context management strategies.
306
- #
307
- # @param action [String] Description of action taken
308
- # @param details [Hash] Additional details
309
- # @return [void]
310
- #
311
- # @example Log compression action
312
- # ctx.log_action("compressed_tool_results", count: 5)
313
- #
314
- # @example Log emergency action
315
- # ctx.log_action("emergency_pruning", remaining: ctx.tokens_remaining)
316
- def log_action(action, details = {})
317
- LogStream.emit(
318
- type: "context_management_action",
319
- agent: agent_name,
320
- threshold: threshold,
321
- action: action,
322
- usage_percentage: usage_percentage,
323
- **details,
324
- )
325
- end
326
- end
327
- end
328
- end
@@ -1,196 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SwarmSDK
4
- # Centralized configuration defaults for SwarmSDK
5
- #
6
- # This module provides well-documented default values for all configurable
7
- # aspects of the SDK. Values are organized by category and include explanations
8
- # for their purpose and rationale.
9
- #
10
- # @example Accessing defaults
11
- # SwarmSDK::Defaults::Timeouts::AGENT_REQUEST_SECONDS
12
- # SwarmSDK::Defaults::Concurrency::GLOBAL_LIMIT
13
- # SwarmSDK::Defaults::Limits::OUTPUT_CHARACTERS
14
- module Defaults
15
- # Concurrency limits for parallel execution
16
- #
17
- # These limits prevent overwhelming external services and ensure
18
- # fair resource usage across the system.
19
- module Concurrency
20
- # Maximum concurrent API calls across entire swarm
21
- #
22
- # This limits total parallel LLM API requests to prevent rate limiting
23
- # and excessive resource consumption. 50 is a balanced value that allows
24
- # good parallelism while respecting API rate limits.
25
- GLOBAL_LIMIT = 50
26
-
27
- # Maximum parallel tool executions per agent
28
- #
29
- # Limits concurrent tool calls within a single agent. 10 allows
30
- # meaningful parallelism (e.g., reading multiple files) without
31
- # overwhelming the system.
32
- LOCAL_LIMIT = 10
33
- end
34
-
35
- # Timeout values for various operations
36
- #
37
- # All timeouts are in seconds unless explicitly marked as milliseconds.
38
- # Timeouts balance responsiveness with allowing enough time for operations
39
- # to complete successfully.
40
- module Timeouts
41
- # LLM API request timeout (seconds)
42
- #
43
- # Default timeout for Claude/GPT API calls. 5 minutes accommodates
44
- # reasoning models (o1, Claude with extended thinking) which can take
45
- # longer to process complex queries.
46
- AGENT_REQUEST_SECONDS = 300
47
-
48
- # Bash command execution timeout (milliseconds)
49
- #
50
- # Default timeout for shell commands. 2 minutes balances allowing
51
- # build/test commands while preventing runaway processes.
52
- BASH_COMMAND_MS = 120_000
53
-
54
- # Maximum Bash command timeout (milliseconds)
55
- #
56
- # Hard upper limit for bash commands. 10 minutes prevents indefinitely
57
- # running commands while allowing long builds/tests.
58
- BASH_COMMAND_MAX_MS = 600_000
59
-
60
- # Web fetch timeout (seconds)
61
- #
62
- # Timeout for HTTP requests in WebFetch tool. 30 seconds is standard
63
- # for web requests, allowing slow servers while timing out unresponsive ones.
64
- WEB_FETCH_SECONDS = 30
65
-
66
- # Shell hook executor timeout (seconds)
67
- #
68
- # Default timeout for hook shell commands. 60 seconds allows complex
69
- # pre/post hooks while preventing indefinite blocking.
70
- HOOK_SHELL_SECONDS = 60
71
-
72
- # Workflow transformer command timeout (seconds)
73
- #
74
- # Timeout for input/output transformer bash commands. 60 seconds allows
75
- # data transformation operations while preventing stalls.
76
- TRANSFORMER_COMMAND_SECONDS = 60
77
-
78
- # OpenAI responses API ID TTL (seconds)
79
- #
80
- # Time-to-live for cached response IDs. 5 minutes allows conversation
81
- # continuity while preventing stale cache issues.
82
- RESPONSES_API_TTL_SECONDS = 300
83
- end
84
-
85
- # Output and content size limits
86
- #
87
- # These limits prevent overwhelming context windows and ensure
88
- # reasonable memory usage.
89
- module Limits
90
- # Maximum Bash output characters
91
- #
92
- # Truncates command output to prevent overwhelming agent context.
93
- # 30,000 characters balances useful information with context constraints.
94
- OUTPUT_CHARACTERS = 30_000
95
-
96
- # Default lines to read from files
97
- #
98
- # When no explicit limit is set, Read tool returns first 2000 lines.
99
- # This provides substantial file content while preventing huge files
100
- # from overwhelming context.
101
- READ_LINES = 2000
102
-
103
- # Maximum characters per line in Read output
104
- #
105
- # Truncates very long lines to prevent single lines from consuming
106
- # excessive context. 2000 characters per line is generous while
107
- # protecting against minified files.
108
- LINE_CHARACTERS = 2000
109
-
110
- # Maximum WebFetch content length
111
- #
112
- # Limits web content fetched from URLs. 100,000 characters provides
113
- # substantial page content while preventing huge pages from overwhelming context.
114
- WEB_FETCH_CHARACTERS = 100_000
115
-
116
- # Maximum Glob search results
117
- #
118
- # Limits number of file paths returned by Glob tool. 1000 results
119
- # provides comprehensive search while preventing overwhelming output.
120
- GLOB_RESULTS = 1000
121
- end
122
-
123
- # Storage limits for persistent data
124
- module Storage
125
- # Maximum size for single scratchpad entry (bytes)
126
- #
127
- # 3MB per entry prevents individual entries from consuming excessive storage
128
- # while allowing substantial content (code, large texts).
129
- ENTRY_SIZE_BYTES = 3_000_000
130
-
131
- # Maximum total scratchpad storage (bytes)
132
- #
133
- # 100GB total storage provides ample room for extensive projects
134
- # while preventing unbounded growth.
135
- TOTAL_SIZE_BYTES = 100_000_000_000
136
- end
137
-
138
- # Context management settings
139
- module Context
140
- # Context usage percentage triggering compression warning
141
- #
142
- # When context usage reaches 60%, agents should consider compaction.
143
- # This threshold provides buffer before hitting limits.
144
- COMPRESSION_THRESHOLD_PERCENT = 60
145
-
146
- # Message count between TodoWrite reminders
147
- #
148
- # After 8 messages without using TodoWrite, a gentle reminder is injected.
149
- # Balances helpfulness without being annoying.
150
- TODOWRITE_REMINDER_INTERVAL = 8
151
- end
152
-
153
- # Token estimation factors
154
- #
155
- # Used for approximate token counting when precise counts aren't available.
156
- module TokenEstimation
157
- # Characters per token for prose text
158
- #
159
- # Average of ~4 characters per token for natural language text.
160
- # Based on empirical analysis of tokenization patterns.
161
- CHARS_PER_TOKEN_PROSE = 4.0
162
-
163
- # Characters per token for code
164
- #
165
- # Code tends to have shorter tokens due to symbols and operators.
166
- # ~3.5 characters per token accounts for this density.
167
- CHARS_PER_TOKEN_CODE = 3.5
168
- end
169
-
170
- # Logging configuration
171
- module Logging
172
- # Default MCP client log level
173
- #
174
- # WARN level suppresses verbose MCP client logs while still
175
- # reporting important issues.
176
- MCP_LOG_LEVEL = Logger::WARN
177
- end
178
-
179
- # Agent configuration defaults
180
- #
181
- # Default values for agent configuration when not explicitly specified.
182
- module Agent
183
- # Default LLM model identifier
184
- #
185
- # OpenAI's GPT-5 is used as the default model. This can be overridden
186
- # per-agent or globally via all_agents configuration.
187
- MODEL = "gpt-5"
188
-
189
- # Default LLM provider
190
- #
191
- # OpenAI is the default provider. Supported providers include:
192
- # openai, anthropic, gemini, deepseek, openrouter, bedrock, etc.
193
- PROVIDER = "openai"
194
- end
195
- end
196
- end