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.
- checksums.yaml +4 -4
- data/lib/swarm_memory/version.rb +1 -1
- metadata +5 -184
- data/lib/claude_swarm/base_executor.rb +0 -133
- data/lib/claude_swarm/claude_code_executor.rb +0 -349
- data/lib/claude_swarm/claude_mcp_server.rb +0 -78
- data/lib/claude_swarm/cli.rb +0 -697
- data/lib/claude_swarm/commands/ps.rb +0 -215
- data/lib/claude_swarm/commands/show.rb +0 -139
- data/lib/claude_swarm/configuration.rb +0 -373
- data/lib/claude_swarm/hooks/session_start_hook.rb +0 -42
- data/lib/claude_swarm/json_handler.rb +0 -91
- data/lib/claude_swarm/mcp_generator.rb +0 -230
- data/lib/claude_swarm/openai/chat_completion.rb +0 -256
- data/lib/claude_swarm/openai/executor.rb +0 -256
- data/lib/claude_swarm/openai/responses.rb +0 -319
- data/lib/claude_swarm/orchestrator.rb +0 -878
- data/lib/claude_swarm/process_tracker.rb +0 -78
- data/lib/claude_swarm/session_cost_calculator.rb +0 -209
- data/lib/claude_swarm/session_path.rb +0 -42
- data/lib/claude_swarm/settings_generator.rb +0 -77
- data/lib/claude_swarm/system_utils.rb +0 -46
- data/lib/claude_swarm/templates/generation_prompt.md.erb +0 -230
- data/lib/claude_swarm/tools/reset_session_tool.rb +0 -24
- data/lib/claude_swarm/tools/session_info_tool.rb +0 -24
- data/lib/claude_swarm/tools/task_tool.rb +0 -63
- data/lib/claude_swarm/version.rb +0 -5
- data/lib/claude_swarm/worktree_manager.rb +0 -475
- data/lib/claude_swarm/yaml_loader.rb +0 -22
- data/lib/claude_swarm.rb +0 -67
- data/lib/swarm_cli/cli.rb +0 -201
- data/lib/swarm_cli/command_registry.rb +0 -61
- data/lib/swarm_cli/commands/mcp_serve.rb +0 -130
- data/lib/swarm_cli/commands/mcp_tools.rb +0 -148
- data/lib/swarm_cli/commands/migrate.rb +0 -55
- data/lib/swarm_cli/commands/run.rb +0 -173
- data/lib/swarm_cli/config_loader.rb +0 -98
- data/lib/swarm_cli/formatters/human_formatter.rb +0 -781
- data/lib/swarm_cli/formatters/json_formatter.rb +0 -51
- data/lib/swarm_cli/interactive_repl.rb +0 -924
- data/lib/swarm_cli/mcp_serve_options.rb +0 -44
- data/lib/swarm_cli/mcp_tools_options.rb +0 -59
- data/lib/swarm_cli/migrate_options.rb +0 -54
- data/lib/swarm_cli/migrator.rb +0 -132
- data/lib/swarm_cli/options.rb +0 -151
- data/lib/swarm_cli/ui/components/agent_badge.rb +0 -33
- data/lib/swarm_cli/ui/components/content_block.rb +0 -120
- data/lib/swarm_cli/ui/components/divider.rb +0 -57
- data/lib/swarm_cli/ui/components/panel.rb +0 -62
- data/lib/swarm_cli/ui/components/usage_stats.rb +0 -70
- data/lib/swarm_cli/ui/formatters/cost.rb +0 -49
- data/lib/swarm_cli/ui/formatters/number.rb +0 -58
- data/lib/swarm_cli/ui/formatters/text.rb +0 -77
- data/lib/swarm_cli/ui/formatters/time.rb +0 -73
- data/lib/swarm_cli/ui/icons.rb +0 -36
- data/lib/swarm_cli/ui/renderers/event_renderer.rb +0 -188
- data/lib/swarm_cli/ui/state/agent_color_cache.rb +0 -45
- data/lib/swarm_cli/ui/state/depth_tracker.rb +0 -40
- data/lib/swarm_cli/ui/state/spinner_manager.rb +0 -170
- data/lib/swarm_cli/ui/state/usage_tracker.rb +0 -62
- data/lib/swarm_cli/version.rb +0 -5
- data/lib/swarm_cli.rb +0 -46
- data/lib/swarm_sdk/agent/RETRY_LOGIC.md +0 -127
- data/lib/swarm_sdk/agent/builder.rb +0 -552
- data/lib/swarm_sdk/agent/chat.rb +0 -774
- data/lib/swarm_sdk/agent/chat_helpers/context_tracker.rb +0 -268
- data/lib/swarm_sdk/agent/chat_helpers/event_emitter.rb +0 -204
- data/lib/swarm_sdk/agent/chat_helpers/hook_integration.rb +0 -480
- data/lib/swarm_sdk/agent/chat_helpers/instrumentation.rb +0 -78
- data/lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb +0 -233
- data/lib/swarm_sdk/agent/chat_helpers/logging_helpers.rb +0 -116
- data/lib/swarm_sdk/agent/chat_helpers/serialization.rb +0 -83
- data/lib/swarm_sdk/agent/chat_helpers/system_reminder_injector.rb +0 -136
- data/lib/swarm_sdk/agent/chat_helpers/system_reminders.rb +0 -79
- data/lib/swarm_sdk/agent/chat_helpers/token_tracking.rb +0 -98
- data/lib/swarm_sdk/agent/context.rb +0 -116
- data/lib/swarm_sdk/agent/context_manager.rb +0 -315
- data/lib/swarm_sdk/agent/definition.rb +0 -477
- data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +0 -182
- data/lib/swarm_sdk/agent/system_prompt_builder.rb +0 -161
- data/lib/swarm_sdk/builders/base_builder.rb +0 -409
- data/lib/swarm_sdk/claude_code_agent_adapter.rb +0 -205
- data/lib/swarm_sdk/concerns/cleanupable.rb +0 -39
- data/lib/swarm_sdk/concerns/snapshotable.rb +0 -67
- data/lib/swarm_sdk/concerns/validatable.rb +0 -55
- data/lib/swarm_sdk/configuration/parser.rb +0 -353
- data/lib/swarm_sdk/configuration/translator.rb +0 -255
- data/lib/swarm_sdk/configuration.rb +0 -135
- data/lib/swarm_sdk/context_compactor/metrics.rb +0 -147
- data/lib/swarm_sdk/context_compactor/token_counter.rb +0 -106
- data/lib/swarm_sdk/context_compactor.rb +0 -335
- data/lib/swarm_sdk/context_management/builder.rb +0 -128
- data/lib/swarm_sdk/context_management/context.rb +0 -328
- data/lib/swarm_sdk/defaults.rb +0 -196
- data/lib/swarm_sdk/events_to_messages.rb +0 -199
- data/lib/swarm_sdk/hooks/adapter.rb +0 -359
- data/lib/swarm_sdk/hooks/context.rb +0 -197
- data/lib/swarm_sdk/hooks/definition.rb +0 -80
- data/lib/swarm_sdk/hooks/error.rb +0 -29
- data/lib/swarm_sdk/hooks/executor.rb +0 -146
- data/lib/swarm_sdk/hooks/registry.rb +0 -147
- data/lib/swarm_sdk/hooks/result.rb +0 -150
- data/lib/swarm_sdk/hooks/shell_executor.rb +0 -255
- data/lib/swarm_sdk/hooks/tool_call.rb +0 -35
- data/lib/swarm_sdk/hooks/tool_result.rb +0 -62
- data/lib/swarm_sdk/log_collector.rb +0 -227
- data/lib/swarm_sdk/log_stream.rb +0 -127
- data/lib/swarm_sdk/markdown_parser.rb +0 -75
- data/lib/swarm_sdk/model_aliases.json +0 -8
- data/lib/swarm_sdk/models.json +0 -1
- data/lib/swarm_sdk/models.rb +0 -120
- data/lib/swarm_sdk/node_context.rb +0 -245
- data/lib/swarm_sdk/observer/builder.rb +0 -81
- data/lib/swarm_sdk/observer/config.rb +0 -45
- data/lib/swarm_sdk/observer/manager.rb +0 -236
- data/lib/swarm_sdk/patterns/agent_observer.rb +0 -160
- data/lib/swarm_sdk/permissions/config.rb +0 -239
- data/lib/swarm_sdk/permissions/error_formatter.rb +0 -121
- data/lib/swarm_sdk/permissions/path_matcher.rb +0 -35
- data/lib/swarm_sdk/permissions/validator.rb +0 -173
- data/lib/swarm_sdk/permissions_builder.rb +0 -122
- data/lib/swarm_sdk/plugin.rb +0 -309
- data/lib/swarm_sdk/plugin_registry.rb +0 -101
- data/lib/swarm_sdk/proc_helpers.rb +0 -53
- data/lib/swarm_sdk/prompts/base_system_prompt.md.erb +0 -117
- data/lib/swarm_sdk/restore_result.rb +0 -65
- data/lib/swarm_sdk/result.rb +0 -123
- data/lib/swarm_sdk/snapshot.rb +0 -156
- data/lib/swarm_sdk/snapshot_from_events.rb +0 -397
- data/lib/swarm_sdk/state_restorer.rb +0 -476
- data/lib/swarm_sdk/state_snapshot.rb +0 -334
- data/lib/swarm_sdk/swarm/agent_initializer.rb +0 -683
- data/lib/swarm_sdk/swarm/all_agents_builder.rb +0 -167
- data/lib/swarm_sdk/swarm/builder.rb +0 -249
- data/lib/swarm_sdk/swarm/executor.rb +0 -213
- data/lib/swarm_sdk/swarm/hook_triggers.rb +0 -150
- data/lib/swarm_sdk/swarm/logging_callbacks.rb +0 -340
- data/lib/swarm_sdk/swarm/mcp_configurator.rb +0 -154
- data/lib/swarm_sdk/swarm/swarm_registry_builder.rb +0 -67
- data/lib/swarm_sdk/swarm/tool_configurator.rb +0 -358
- data/lib/swarm_sdk/swarm.rb +0 -717
- data/lib/swarm_sdk/swarm_loader.rb +0 -145
- data/lib/swarm_sdk/swarm_registry.rb +0 -136
- data/lib/swarm_sdk/tools/bash.rb +0 -282
- data/lib/swarm_sdk/tools/clock.rb +0 -44
- data/lib/swarm_sdk/tools/delegate.rb +0 -267
- data/lib/swarm_sdk/tools/document_converters/base_converter.rb +0 -83
- data/lib/swarm_sdk/tools/document_converters/docx_converter.rb +0 -99
- data/lib/swarm_sdk/tools/document_converters/html_converter.rb +0 -101
- data/lib/swarm_sdk/tools/document_converters/pdf_converter.rb +0 -78
- data/lib/swarm_sdk/tools/document_converters/xlsx_converter.rb +0 -194
- data/lib/swarm_sdk/tools/edit.rb +0 -145
- data/lib/swarm_sdk/tools/glob.rb +0 -166
- data/lib/swarm_sdk/tools/grep.rb +0 -235
- data/lib/swarm_sdk/tools/image_extractors/docx_image_extractor.rb +0 -43
- data/lib/swarm_sdk/tools/image_extractors/pdf_image_extractor.rb +0 -163
- data/lib/swarm_sdk/tools/image_formats/tiff_builder.rb +0 -65
- data/lib/swarm_sdk/tools/multi_edit.rb +0 -236
- data/lib/swarm_sdk/tools/path_resolver.rb +0 -92
- data/lib/swarm_sdk/tools/read.rb +0 -261
- data/lib/swarm_sdk/tools/registry.rb +0 -205
- data/lib/swarm_sdk/tools/scratchpad/scratchpad_list.rb +0 -117
- data/lib/swarm_sdk/tools/scratchpad/scratchpad_read.rb +0 -97
- data/lib/swarm_sdk/tools/scratchpad/scratchpad_write.rb +0 -108
- data/lib/swarm_sdk/tools/stores/read_tracker.rb +0 -96
- data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +0 -272
- data/lib/swarm_sdk/tools/stores/storage.rb +0 -142
- data/lib/swarm_sdk/tools/stores/todo_manager.rb +0 -65
- data/lib/swarm_sdk/tools/think.rb +0 -98
- data/lib/swarm_sdk/tools/todo_write.rb +0 -235
- data/lib/swarm_sdk/tools/web_fetch.rb +0 -262
- data/lib/swarm_sdk/tools/write.rb +0 -112
- data/lib/swarm_sdk/utils.rb +0 -68
- data/lib/swarm_sdk/validation_result.rb +0 -33
- data/lib/swarm_sdk/version.rb +0 -5
- data/lib/swarm_sdk/workflow/agent_config.rb +0 -79
- data/lib/swarm_sdk/workflow/builder.rb +0 -143
- data/lib/swarm_sdk/workflow/executor.rb +0 -497
- data/lib/swarm_sdk/workflow/node_builder.rb +0 -555
- data/lib/swarm_sdk/workflow/transformer_executor.rb +0 -249
- data/lib/swarm_sdk/workflow.rb +0 -554
- data/lib/swarm_sdk.rb +0 -524
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module SwarmSDK
|
|
4
|
-
# Creates snapshots of swarm/workflow conversation state
|
|
5
|
-
#
|
|
6
|
-
# Unified implementation that works for both Swarm and Workflow.
|
|
7
|
-
# Captures conversation history, context state, scratchpad contents, and
|
|
8
|
-
# read tracking information.
|
|
9
|
-
#
|
|
10
|
-
# The snapshot is a plain Ruby hash that can be serialized to JSON or any
|
|
11
|
-
# other format. Configuration (agent definitions, tools, prompts) stays in
|
|
12
|
-
# your YAML/DSL and is not included in snapshots.
|
|
13
|
-
#
|
|
14
|
-
# @example Snapshot a swarm
|
|
15
|
-
# swarm = SwarmSDK.build { ... }
|
|
16
|
-
# swarm.execute("Build authentication")
|
|
17
|
-
# snapshot = swarm.snapshot
|
|
18
|
-
# snapshot.write_to_file("session.json")
|
|
19
|
-
#
|
|
20
|
-
# @example Snapshot a workflow
|
|
21
|
-
# workflow = SwarmSDK.workflow { ... }
|
|
22
|
-
# workflow.execute("Build feature")
|
|
23
|
-
# snapshot = workflow.snapshot
|
|
24
|
-
# snapshot.write_to_file("workflow_session.json")
|
|
25
|
-
class StateSnapshot
|
|
26
|
-
# Initialize snapshot creator
|
|
27
|
-
#
|
|
28
|
-
# @param orchestration [Swarm, Workflow] Swarm or workflow to snapshot
|
|
29
|
-
def initialize(orchestration)
|
|
30
|
-
@orchestration = orchestration
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Create snapshot of current state
|
|
34
|
-
#
|
|
35
|
-
# Returns a Snapshot object that encapsulates the snapshot data with
|
|
36
|
-
# convenient methods for serialization and file I/O.
|
|
37
|
-
#
|
|
38
|
-
# @return [Snapshot] Snapshot object
|
|
39
|
-
def snapshot
|
|
40
|
-
data = {
|
|
41
|
-
version: "2.1.0", # Bumped for plugin state abstraction
|
|
42
|
-
type: type_name,
|
|
43
|
-
snapshot_at: Time.now.utc.iso8601,
|
|
44
|
-
swarm_sdk_version: SwarmSDK::VERSION,
|
|
45
|
-
metadata: snapshot_metadata,
|
|
46
|
-
agents: snapshot_agents,
|
|
47
|
-
delegation_instances: snapshot_delegation_instances,
|
|
48
|
-
scratchpad: snapshot_scratchpad,
|
|
49
|
-
read_tracking: snapshot_read_tracking,
|
|
50
|
-
plugin_states: snapshot_plugin_states,
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
# Wrap in Snapshot object
|
|
54
|
-
SwarmSDK::Snapshot.new(data)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
# Get type name for snapshot
|
|
60
|
-
#
|
|
61
|
-
# @return [String] "swarm" or "workflow"
|
|
62
|
-
def type_name
|
|
63
|
-
@orchestration.class.name.split("::").last.downcase
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Snapshot common metadata
|
|
67
|
-
#
|
|
68
|
-
# @return [Hash] Metadata
|
|
69
|
-
def snapshot_metadata
|
|
70
|
-
{
|
|
71
|
-
id: @orchestration.swarm_id,
|
|
72
|
-
parent_id: @orchestration.parent_swarm_id,
|
|
73
|
-
name: @orchestration.name,
|
|
74
|
-
# Swarm-specific: first_message_sent (Workflow returns false)
|
|
75
|
-
first_message_sent: @orchestration.first_message_sent?,
|
|
76
|
-
}
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Snapshot all agent conversations and context state
|
|
80
|
-
#
|
|
81
|
-
# Uses interface method: primary_agents (no type checking!)
|
|
82
|
-
#
|
|
83
|
-
# @return [Hash] { agent_name => { conversation:, context_state:, system_prompt: } }
|
|
84
|
-
def snapshot_agents
|
|
85
|
-
result = {}
|
|
86
|
-
|
|
87
|
-
# Use interface method - works for both Swarm and Workflow!
|
|
88
|
-
@orchestration.primary_agents.each do |agent_name, agent_chat|
|
|
89
|
-
agent_definition = @orchestration.agent_definitions[agent_name]
|
|
90
|
-
system_prompt = agent_definition&.system_prompt
|
|
91
|
-
|
|
92
|
-
result[agent_name.to_s] = {
|
|
93
|
-
conversation: snapshot_conversation(agent_chat),
|
|
94
|
-
context_state: snapshot_context_state(agent_chat),
|
|
95
|
-
system_prompt: system_prompt,
|
|
96
|
-
}
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
result
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# Snapshot conversation messages for an agent
|
|
103
|
-
#
|
|
104
|
-
# @param agent_chat [Agent::Chat] Agent chat instance
|
|
105
|
-
# @return [Array<Hash>] Serialized messages
|
|
106
|
-
def snapshot_conversation(agent_chat)
|
|
107
|
-
agent_chat.messages.map { |msg| serialize_message(msg) }
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# Serialize a single message
|
|
111
|
-
#
|
|
112
|
-
# @param msg [RubyLLM::Message] Message to serialize
|
|
113
|
-
# @return [Hash] Serialized message
|
|
114
|
-
def serialize_message(msg)
|
|
115
|
-
hash = { role: msg.role }
|
|
116
|
-
|
|
117
|
-
# Handle content - check msg.content directly
|
|
118
|
-
hash[:content] = if msg.content.is_a?(RubyLLM::Content)
|
|
119
|
-
msg.content.to_h
|
|
120
|
-
else
|
|
121
|
-
msg.content
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# Handle tool calls
|
|
125
|
-
if msg.tool_calls && !msg.tool_calls.empty?
|
|
126
|
-
hash[:tool_calls] = msg.tool_calls.values.map do |tc|
|
|
127
|
-
{
|
|
128
|
-
id: tc.id,
|
|
129
|
-
name: tc.name,
|
|
130
|
-
arguments: tc.arguments,
|
|
131
|
-
}
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
# Handle other fields
|
|
136
|
-
hash[:tool_call_id] = msg.tool_call_id if msg.tool_call_id
|
|
137
|
-
hash[:input_tokens] = msg.input_tokens if msg.input_tokens
|
|
138
|
-
hash[:output_tokens] = msg.output_tokens if msg.output_tokens
|
|
139
|
-
hash[:model_id] = msg.model_id if msg.model_id
|
|
140
|
-
|
|
141
|
-
hash
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
# Snapshot context state for an agent
|
|
145
|
-
#
|
|
146
|
-
# @param agent_chat [Agent::Chat] Agent chat instance
|
|
147
|
-
# @return [Hash] Context state
|
|
148
|
-
def snapshot_context_state(agent_chat)
|
|
149
|
-
context_manager = agent_chat.context_manager
|
|
150
|
-
agent_context = agent_chat.agent_context
|
|
151
|
-
|
|
152
|
-
{
|
|
153
|
-
warning_thresholds_hit: agent_context.warning_thresholds_hit.to_a,
|
|
154
|
-
compression_applied: context_manager.compression_applied,
|
|
155
|
-
last_todowrite_message_index: agent_chat.last_todowrite_message_index,
|
|
156
|
-
active_skill_path: agent_chat.active_skill_path,
|
|
157
|
-
}
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# Snapshot delegation instance conversations
|
|
161
|
-
#
|
|
162
|
-
# Uses interface method: delegation_instances_hash (no type checking!)
|
|
163
|
-
#
|
|
164
|
-
# @return [Hash] { "delegate@delegator" => { conversation:, context_state:, system_prompt: } }
|
|
165
|
-
def snapshot_delegation_instances
|
|
166
|
-
result = {}
|
|
167
|
-
|
|
168
|
-
# Use interface method - works for both Swarm and Workflow!
|
|
169
|
-
@orchestration.delegation_instances_hash.each do |instance_name, delegation_chat|
|
|
170
|
-
# Extract base agent name from instance name
|
|
171
|
-
base_name = instance_name.to_s.split("@").first.to_sym
|
|
172
|
-
|
|
173
|
-
# Get system prompt from base agent definition
|
|
174
|
-
agent_definition = @orchestration.agent_definitions[base_name]
|
|
175
|
-
system_prompt = agent_definition&.system_prompt
|
|
176
|
-
|
|
177
|
-
result[instance_name] = {
|
|
178
|
-
conversation: snapshot_conversation(delegation_chat),
|
|
179
|
-
context_state: snapshot_context_state(delegation_chat),
|
|
180
|
-
system_prompt: system_prompt,
|
|
181
|
-
}
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
result
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
# Snapshot scratchpad contents
|
|
188
|
-
#
|
|
189
|
-
# Detects type and calls appropriate method.
|
|
190
|
-
#
|
|
191
|
-
# @return [Hash] Scratchpad snapshot data
|
|
192
|
-
def snapshot_scratchpad
|
|
193
|
-
if @orchestration.is_a?(Workflow)
|
|
194
|
-
snapshot_workflow_scratchpad
|
|
195
|
-
else
|
|
196
|
-
snapshot_swarm_scratchpad
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
# Snapshot scratchpad for Workflow
|
|
201
|
-
#
|
|
202
|
-
# @return [Hash] Structured scratchpad data with mode metadata
|
|
203
|
-
def snapshot_workflow_scratchpad
|
|
204
|
-
all_scratchpads = @orchestration.all_scratchpads
|
|
205
|
-
return {} unless all_scratchpads&.any?
|
|
206
|
-
|
|
207
|
-
if @orchestration.shared_scratchpad?
|
|
208
|
-
# Enabled mode: single shared scratchpad
|
|
209
|
-
shared_scratchpad = all_scratchpads[:shared]
|
|
210
|
-
return {} unless shared_scratchpad
|
|
211
|
-
|
|
212
|
-
entries = serialize_scratchpad_entries(shared_scratchpad.all_entries)
|
|
213
|
-
return {} if entries.empty?
|
|
214
|
-
|
|
215
|
-
{
|
|
216
|
-
shared: true,
|
|
217
|
-
data: entries,
|
|
218
|
-
}
|
|
219
|
-
else
|
|
220
|
-
# Per-node mode: separate scratchpads per node
|
|
221
|
-
node_data = {}
|
|
222
|
-
all_scratchpads.each do |node_name, scratchpad|
|
|
223
|
-
next unless scratchpad
|
|
224
|
-
|
|
225
|
-
entries = serialize_scratchpad_entries(scratchpad.all_entries)
|
|
226
|
-
node_data[node_name.to_s] = entries unless entries.empty?
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
return {} if node_data.empty?
|
|
230
|
-
|
|
231
|
-
{
|
|
232
|
-
shared: false,
|
|
233
|
-
data: node_data,
|
|
234
|
-
}
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
# Snapshot scratchpad for Swarm
|
|
239
|
-
#
|
|
240
|
-
# @return [Hash] Flat scratchpad entries
|
|
241
|
-
def snapshot_swarm_scratchpad
|
|
242
|
-
scratchpad = @orchestration.scratchpad_storage
|
|
243
|
-
return {} unless scratchpad
|
|
244
|
-
|
|
245
|
-
entries_hash = scratchpad.all_entries
|
|
246
|
-
return {} unless entries_hash&.any?
|
|
247
|
-
|
|
248
|
-
serialize_scratchpad_entries(entries_hash)
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
# Serialize scratchpad entries to snapshot format
|
|
252
|
-
#
|
|
253
|
-
# @param entries_hash [Hash] { path => Entry }
|
|
254
|
-
# @return [Hash] { path => { content:, title:, updated_at:, size: } }
|
|
255
|
-
def serialize_scratchpad_entries(entries_hash)
|
|
256
|
-
return {} unless entries_hash
|
|
257
|
-
|
|
258
|
-
result = {}
|
|
259
|
-
entries_hash.each do |path, entry|
|
|
260
|
-
result[path] = {
|
|
261
|
-
content: entry.content,
|
|
262
|
-
title: entry.title,
|
|
263
|
-
updated_at: entry.updated_at.iso8601,
|
|
264
|
-
size: entry.size,
|
|
265
|
-
}
|
|
266
|
-
end
|
|
267
|
-
result
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
# Snapshot read tracking state
|
|
271
|
-
#
|
|
272
|
-
# @return [Hash] { agent_name => { file_path => digest } }
|
|
273
|
-
def snapshot_read_tracking
|
|
274
|
-
result = {}
|
|
275
|
-
|
|
276
|
-
# Get all agents (primary + delegations)
|
|
277
|
-
agent_names = all_agent_names
|
|
278
|
-
|
|
279
|
-
agent_names.each do |agent_name|
|
|
280
|
-
files_with_digests = Tools::Stores::ReadTracker.get_read_files(agent_name)
|
|
281
|
-
next if files_with_digests.empty?
|
|
282
|
-
|
|
283
|
-
result[agent_name.to_s] = files_with_digests
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
result
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
# Snapshot plugin-specific state for all plugins
|
|
290
|
-
#
|
|
291
|
-
# Iterates over all registered plugins and collects their agent-specific state.
|
|
292
|
-
# This decouples the SDK from plugin-specific implementations.
|
|
293
|
-
#
|
|
294
|
-
# @return [Hash] { plugin_name => { agent_name => plugin_state } }
|
|
295
|
-
def snapshot_plugin_states
|
|
296
|
-
result = {}
|
|
297
|
-
|
|
298
|
-
# Get all agents (primary + delegations)
|
|
299
|
-
agent_names = all_agent_names
|
|
300
|
-
|
|
301
|
-
# Iterate over all registered plugins
|
|
302
|
-
PluginRegistry.all.each do |plugin|
|
|
303
|
-
plugin_state = {}
|
|
304
|
-
|
|
305
|
-
agent_names.each do |agent_name|
|
|
306
|
-
agent_state = plugin.snapshot_agent_state(agent_name)
|
|
307
|
-
next if agent_state.empty?
|
|
308
|
-
|
|
309
|
-
plugin_state[agent_name.to_s] = agent_state
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
# Only include plugin if it has state for at least one agent
|
|
313
|
-
result[plugin.name.to_s] = plugin_state unless plugin_state.empty?
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
result
|
|
317
|
-
end
|
|
318
|
-
|
|
319
|
-
# All agent names (primary + delegations)
|
|
320
|
-
#
|
|
321
|
-
# Uses interface methods - no type checking!
|
|
322
|
-
#
|
|
323
|
-
# @return [Array<Symbol>] All agent names
|
|
324
|
-
def all_agent_names
|
|
325
|
-
# Get primary agent names
|
|
326
|
-
agents_hash = @orchestration.agent_definitions.keys
|
|
327
|
-
|
|
328
|
-
# Add delegation instance names
|
|
329
|
-
delegations_hash = @orchestration.delegation_instances_hash.keys
|
|
330
|
-
|
|
331
|
-
agents_hash + delegations_hash.map(&:to_sym)
|
|
332
|
-
end
|
|
333
|
-
end
|
|
334
|
-
end
|