swarm_cli 2.1.12 → 2.1.13
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_cli/interactive_repl.rb +15 -44
- data/lib/swarm_cli/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af3e0c037fa25f545dd90fe21908da554c7cb3242d752c58eabec95b7453c840
|
|
4
|
+
data.tar.gz: 52aee53c8a31b17a0035d95e814f756ae01ca7b895aa94216e77a8a03af14b89
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 444bfa6029186f64b6d6fea74c1bf6c7dd1976971a6ea383ac1c49bf128d1c515f074d53266a35414a1cd32f58cdfd2d83b8ecd3a934293d01e691a7b4df8d68
|
|
7
|
+
data.tar.gz: 05e3f8f1e937f19c916f72fd78f74591df2b2862ad34885010b8b63dd4958e178f7112e1e9227192ef480da2efa53ce6f4d7563be3fba85893ddb086de828b09
|
|
@@ -6,7 +6,6 @@ require "tty-markdown"
|
|
|
6
6
|
require "tty-box"
|
|
7
7
|
require "pastel"
|
|
8
8
|
require "async"
|
|
9
|
-
require "async/condition"
|
|
10
9
|
|
|
11
10
|
module SwarmCLI
|
|
12
11
|
# InteractiveREPL provides a professional, interactive terminal interface
|
|
@@ -91,54 +90,26 @@ module SwarmCLI
|
|
|
91
90
|
# Execute a message with Ctrl+C cancellation support
|
|
92
91
|
# Public for testing
|
|
93
92
|
#
|
|
93
|
+
# Uses swarm.stop for thread-safe cancellation via IO.pipe signaling.
|
|
94
|
+
# The INT trap handler calls swarm.stop which writes to the pipe,
|
|
95
|
+
# waking the Async scheduler's stop listener to cancel all tasks.
|
|
96
|
+
#
|
|
94
97
|
# @param input [String] User input to execute
|
|
95
98
|
# @return [SwarmSDK::Result, nil] Result or nil if cancelled
|
|
96
99
|
def execute_with_cancellation(input, &log_callback)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# Use Async::Condition for trap-safe cancellation
|
|
103
|
-
# (Condition#signal uses Thread::Queue which is safe from trap context)
|
|
104
|
-
cancel_condition = Async::Condition.new
|
|
105
|
-
|
|
106
|
-
# Install trap ONLY during execution
|
|
107
|
-
# When Ctrl+C is pressed, signal the condition instead of calling task.stop
|
|
108
|
-
old_trap = trap("INT") do
|
|
109
|
-
cancel_condition.signal(:cancel)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
begin
|
|
113
|
-
# Execute swarm in async task
|
|
114
|
-
llm_task = task.async do
|
|
115
|
-
@swarm.execute(input, &log_callback)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# Monitor task - watches for cancellation signal
|
|
119
|
-
# Must be created AFTER llm_task so it can reference it
|
|
120
|
-
monitor_task = task.async do
|
|
121
|
-
if cancel_condition.wait == :cancel
|
|
122
|
-
cancelled = true
|
|
123
|
-
llm_task.stop
|
|
124
|
-
end
|
|
125
|
-
end
|
|
100
|
+
# Install trap ONLY during execution
|
|
101
|
+
# swarm.stop is safe to call from trap context (IO.pipe write)
|
|
102
|
+
old_trap = trap("INT") do
|
|
103
|
+
@swarm.stop
|
|
104
|
+
end
|
|
126
105
|
|
|
127
|
-
|
|
128
|
-
rescue Async::Stop
|
|
129
|
-
# Task was stopped by Ctrl+C
|
|
130
|
-
cancelled = true
|
|
131
|
-
ensure
|
|
132
|
-
# Clean up monitor task
|
|
133
|
-
monitor_task&.stop if monitor_task&.alive?
|
|
134
|
-
|
|
135
|
-
# CRITICAL: Restore old trap when done
|
|
136
|
-
# This ensures Ctrl+C at the prompt still exits the REPL
|
|
137
|
-
trap("INT", old_trap)
|
|
138
|
-
end
|
|
139
|
-
end.wait
|
|
106
|
+
result = @swarm.execute(input, &log_callback)
|
|
140
107
|
|
|
141
|
-
|
|
108
|
+
result&.interrupted? ? nil : result
|
|
109
|
+
ensure
|
|
110
|
+
# CRITICAL: Restore old trap when done
|
|
111
|
+
# This ensures Ctrl+C at the prompt still exits the REPL
|
|
112
|
+
trap("INT", old_trap)
|
|
142
113
|
end
|
|
143
114
|
|
|
144
115
|
# Handle slash commands
|
data/lib/swarm_cli/version.rb
CHANGED