claude-agent-sdk 0.16.2 → 0.16.4
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/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/lib/claude_agent_sdk/fiber_boundary.rb +4 -0
- data/lib/claude_agent_sdk/subprocess_cli_transport.rb +15 -10
- data/lib/claude_agent_sdk/version.rb +1 -1
- data/lib/claude_agent_sdk.rb +12 -9
- 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: 98b00605830d86d1dc5e632ef9887574b255d2ace8fdc815451a53983ca0ea2e
|
|
4
|
+
data.tar.gz: d28cb3256fa5944f966e21afa753d082559a6d537d527dfc2abb5aaa962a450b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 807595177836563a86f0dc72a3a70b297860d07f76d19c90d70f97dafae7a1bdd69a52583a8c005172148f6742b59fbd80e78f79a3d10c47ad33ba24d7ade89c
|
|
7
|
+
data.tar.gz: af94cf3bbd037da6b1a7998a41438f10227d731657c2050e4a0f1d57551e682d4dd9dcfef9d98c67f6ead150472804468093cc226622392b8b3ecdb25cae4d18
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.16.4] - 2026-04-23
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- `Client#receive_response` no longer hangs in interactive Client mode. The 0.16.1 flag-based fix relied on the loop draining via the transport's `:end` sentinel, which only arrives when the CLI subprocess exits — true for one-shot `query()` but never for a `Client` whose CLI stays alive between turns. `receive_response` now drives `QueryHandler#receive_messages` directly so its `break` runs on the same fiber as the underlying `Async::Queue#dequeue` loop and unwinds it. The 0.16.1 regression spec passed only because its stub iterated a finite array; replaced with a real `Async::Queue` driven from a sibling task so a hang now fails the test.
|
|
14
|
+
|
|
15
|
+
### Internal
|
|
16
|
+
- `FiberBoundary` doc-comment now warns that `break`/`return`/`next` cannot cross the thread hop, so SDK-internal loops yielding user callbacks must keep loop control on the outer side of the boundary.
|
|
17
|
+
|
|
18
|
+
## [0.16.3] - 2026-04-23
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- Internal: extracted `SubprocessCLITransport#record_bounded_stderr` helper to deduplicate the recent-stderr ring-buffer append/trim logic shared by `handle_stderr` and `drain_stderr_with_accumulation`, and replaced the inlined `20` cap with a named `RECENT_STDERR_LINES_LIMIT` constant. No public behavior change.
|
|
22
|
+
|
|
10
23
|
## [0.16.2] - 2026-04-23
|
|
11
24
|
|
|
12
25
|
### Changed
|
data/README.md
CHANGED
|
@@ -108,7 +108,7 @@ Add this line to your application's Gemfile:
|
|
|
108
108
|
gem 'claude-agent-sdk', github: 'ya-luotao/claude-agent-sdk-ruby'
|
|
109
109
|
|
|
110
110
|
# Or use a stable version from RubyGems
|
|
111
|
-
gem 'claude-agent-sdk', '~> 0.16.
|
|
111
|
+
gem 'claude-agent-sdk', '~> 0.16.4'
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
And then execute:
|
|
@@ -23,6 +23,10 @@ module ClaudeAgentSDK
|
|
|
23
23
|
# user's app makes.
|
|
24
24
|
#
|
|
25
25
|
# No-op when no scheduler is active, so it's cheap to use unconditionally.
|
|
26
|
+
#
|
|
27
|
+
# The thread hop severs `break`/`return`/`next` from the surrounding method,
|
|
28
|
+
# so SDK loops yielding user callbacks must keep loop control outside the
|
|
29
|
+
# invoked block (see `Client#receive_response`).
|
|
26
30
|
module FiberBoundary
|
|
27
31
|
module_function
|
|
28
32
|
|
|
@@ -13,6 +13,7 @@ module ClaudeAgentSDK
|
|
|
13
13
|
class SubprocessCLITransport < Transport
|
|
14
14
|
DEFAULT_MAX_BUFFER_SIZE = 1024 * 1024 # 1MB buffer limit
|
|
15
15
|
MINIMUM_CLAUDE_CODE_VERSION = '2.0.0'
|
|
16
|
+
RECENT_STDERR_LINES_LIMIT = 20
|
|
16
17
|
|
|
17
18
|
def initialize(options_or_prompt = nil, options = nil)
|
|
18
19
|
# Support both new single-arg form and legacy two-arg form
|
|
@@ -145,11 +146,7 @@ module ClaudeAgentSDK
|
|
|
145
146
|
line_str = line.chomp
|
|
146
147
|
next if line_str.empty?
|
|
147
148
|
|
|
148
|
-
|
|
149
|
-
@recent_stderr_mutex.synchronize do
|
|
150
|
-
@recent_stderr << line_str
|
|
151
|
-
@recent_stderr.shift if @recent_stderr.size > 20
|
|
152
|
-
end
|
|
149
|
+
record_bounded_stderr(line_str)
|
|
153
150
|
|
|
154
151
|
# Call stderr callback if provided
|
|
155
152
|
@options.stderr&.call(line_str)
|
|
@@ -174,10 +171,7 @@ module ClaudeAgentSDK
|
|
|
174
171
|
line_str = line.chomp
|
|
175
172
|
next if line_str.empty?
|
|
176
173
|
|
|
177
|
-
|
|
178
|
-
@recent_stderr << line_str
|
|
179
|
-
@recent_stderr.shift if @recent_stderr.size > 20
|
|
180
|
-
end
|
|
174
|
+
record_bounded_stderr(line_str)
|
|
181
175
|
end
|
|
182
176
|
end
|
|
183
177
|
|
|
@@ -282,7 +276,6 @@ module ClaudeAgentSDK
|
|
|
282
276
|
def write(data)
|
|
283
277
|
raise CLIConnectionError, 'ProcessTransport is not ready for writing' unless @ready && @stdin
|
|
284
278
|
raise CLIConnectionError, "Cannot write to terminated process" if @process && !@process.alive?
|
|
285
|
-
|
|
286
279
|
raise CLIConnectionError, "Cannot write to process that exited with error: #{@exit_error}" if @exit_error
|
|
287
280
|
|
|
288
281
|
begin
|
|
@@ -395,5 +388,17 @@ module ClaudeAgentSDK
|
|
|
395
388
|
def ready?
|
|
396
389
|
@ready
|
|
397
390
|
end
|
|
391
|
+
|
|
392
|
+
private
|
|
393
|
+
|
|
394
|
+
# Append a stderr line to the recent-stderr ring, dropping the oldest
|
|
395
|
+
# entry once the buffer exceeds RECENT_STDERR_LINES_LIMIT. Used to surface the
|
|
396
|
+
# last few lines in ProcessError when the CLI exits non-zero.
|
|
397
|
+
def record_bounded_stderr(line)
|
|
398
|
+
@recent_stderr_mutex.synchronize do
|
|
399
|
+
@recent_stderr << line
|
|
400
|
+
@recent_stderr.shift if @recent_stderr.size > RECENT_STDERR_LINES_LIMIT
|
|
401
|
+
end
|
|
402
|
+
end
|
|
398
403
|
end
|
|
399
404
|
end
|
data/lib/claude_agent_sdk.rb
CHANGED
|
@@ -418,15 +418,18 @@ module ClaudeAgentSDK
|
|
|
418
418
|
def receive_response(&block)
|
|
419
419
|
return enum_for(:receive_response) unless block
|
|
420
420
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
#
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
421
|
+
raise CLIConnectionError, 'Not connected. Call connect() first' unless @connected
|
|
422
|
+
|
|
423
|
+
# Keep `break` on the same fiber as the underlying dequeue. Going through
|
|
424
|
+
# Client#receive_messages would put the FiberBoundary hop above the break
|
|
425
|
+
# and hang in Client mode — the CLI keeps stdin open and never emits `:end`.
|
|
426
|
+
@query_handler.receive_messages do |data|
|
|
427
|
+
message = MessageParser.parse(data)
|
|
428
|
+
next unless message
|
|
429
|
+
|
|
430
|
+
ClaudeAgentSDK.notify_observers(@resolved_observers, :on_message, message)
|
|
431
|
+
FiberBoundary.invoke { block.call(message) }
|
|
432
|
+
break if message.is_a?(ResultMessage)
|
|
430
433
|
end
|
|
431
434
|
end
|
|
432
435
|
|