claude-agent-sdk 0.6.2 → 0.6.3
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ee66bd44d402ecac03c5928cc485360342b64510985de4966a627b5ada3919f
|
|
4
|
+
data.tar.gz: d69ea31b3f6dd26679aeb9c8857616d757861a54a9f9803ce7b0575043348bef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e381c777261d67d8e95638874455cd13cda055b7524ff20459dc5e53ca2d8e70c4580637f3da34d83e22090becae0b4a9bcdd15ffb9613db3c03133fe3c4255
|
|
7
|
+
data.tar.gz: 2400f7ccb58c48b8c12d4fc3843781b5545d2ff80c030daa32be4529ae0c2b4f59e3114138e6b21f7c3923c4e3ccca9594fbf6e6722c8d540b729c18e47767f3
|
|
@@ -23,6 +23,8 @@ module ClaudeAgentSDK
|
|
|
23
23
|
parse_result_message(data)
|
|
24
24
|
when 'stream_event'
|
|
25
25
|
parse_stream_event(data)
|
|
26
|
+
when 'rate_limit_event'
|
|
27
|
+
parse_rate_limit_event(data)
|
|
26
28
|
else
|
|
27
29
|
raise MessageParseError.new("Unknown message type: #{message_type}", data: data)
|
|
28
30
|
end
|
|
@@ -91,6 +93,10 @@ module ClaudeAgentSDK
|
|
|
91
93
|
)
|
|
92
94
|
end
|
|
93
95
|
|
|
96
|
+
def self.parse_rate_limit_event(data)
|
|
97
|
+
RateLimitEvent.new(data: data)
|
|
98
|
+
end
|
|
99
|
+
|
|
94
100
|
def self.parse_content_block(block)
|
|
95
101
|
case block[:type]
|
|
96
102
|
when 'text'
|
|
@@ -32,6 +32,8 @@ module ClaudeAgentSDK
|
|
|
32
32
|
@exit_error = nil
|
|
33
33
|
@max_buffer_size = options.max_buffer_size || DEFAULT_MAX_BUFFER_SIZE
|
|
34
34
|
@stderr_task = nil
|
|
35
|
+
@recent_stderr = []
|
|
36
|
+
@recent_stderr_mutex = Mutex.new
|
|
35
37
|
@pipe_prompt_via_stdin = false
|
|
36
38
|
end
|
|
37
39
|
|
|
@@ -273,9 +275,11 @@ module ClaudeAgentSDK
|
|
|
273
275
|
# Build environment
|
|
274
276
|
# Convert symbol keys to strings for spawn compatibility
|
|
275
277
|
custom_env = @options.env.transform_keys { |k| k.to_s }
|
|
276
|
-
#
|
|
277
|
-
# launches Claude Code from within an existing Claude Code terminal
|
|
278
|
-
|
|
278
|
+
# Explicitly unset CLAUDECODE to prevent "nested session" detection when the SDK
|
|
279
|
+
# launches Claude Code from within an existing Claude Code terminal.
|
|
280
|
+
# NOTE: Must set to nil (not just omit the key) — Ruby's spawn only overlays
|
|
281
|
+
# the env hash on top of the parent environment; a nil value actively unsets.
|
|
282
|
+
process_env = ENV.to_h.merge('CLAUDECODE' => nil, 'CLAUDE_AGENT_SDK_VERSION' => VERSION).merge(custom_env)
|
|
279
283
|
process_env['CLAUDE_CODE_ENTRYPOINT'] ||= 'sdk-rb'
|
|
280
284
|
process_env['PWD'] = @cwd.to_s if @cwd
|
|
281
285
|
|
|
@@ -292,16 +296,17 @@ module ClaudeAgentSDK
|
|
|
292
296
|
# Without this, --verbose output fills the OS pipe buffer (~64KB),
|
|
293
297
|
# the subprocess blocks on write, and all pipes stall → EPIPE.
|
|
294
298
|
if @stderr
|
|
295
|
-
if should_pipe_stderr
|
|
299
|
+
if should_pipe_stderr # rubocop:disable Style/ConditionalAssignment
|
|
296
300
|
@stderr_task = Thread.new do
|
|
297
301
|
handle_stderr
|
|
298
302
|
rescue StandardError
|
|
299
303
|
# Ignore errors during stderr reading
|
|
300
304
|
end
|
|
301
305
|
else
|
|
302
|
-
# Silently drain stderr so the subprocess never blocks
|
|
306
|
+
# Silently drain stderr so the subprocess never blocks,
|
|
307
|
+
# but still accumulate recent lines for error reporting.
|
|
303
308
|
@stderr_task = Thread.new do
|
|
304
|
-
|
|
309
|
+
drain_stderr_with_accumulation
|
|
305
310
|
rescue StandardError
|
|
306
311
|
# Ignore — process may have already exited
|
|
307
312
|
end
|
|
@@ -343,6 +348,12 @@ module ClaudeAgentSDK
|
|
|
343
348
|
line_str = line.chomp
|
|
344
349
|
next if line_str.empty?
|
|
345
350
|
|
|
351
|
+
# Accumulate recent lines for inclusion in ProcessError
|
|
352
|
+
@recent_stderr_mutex.synchronize do
|
|
353
|
+
@recent_stderr << line_str
|
|
354
|
+
@recent_stderr.shift if @recent_stderr.size > 20
|
|
355
|
+
end
|
|
356
|
+
|
|
346
357
|
# Call stderr callback if provided
|
|
347
358
|
@options.stderr&.call(line_str)
|
|
348
359
|
|
|
@@ -359,6 +370,20 @@ module ClaudeAgentSDK
|
|
|
359
370
|
# Ignore errors during stderr reading
|
|
360
371
|
end
|
|
361
372
|
|
|
373
|
+
def drain_stderr_with_accumulation
|
|
374
|
+
return unless @stderr
|
|
375
|
+
|
|
376
|
+
@stderr.each_line do |line|
|
|
377
|
+
line_str = line.chomp
|
|
378
|
+
next if line_str.empty?
|
|
379
|
+
|
|
380
|
+
@recent_stderr_mutex.synchronize do
|
|
381
|
+
@recent_stderr << line_str
|
|
382
|
+
@recent_stderr.shift if @recent_stderr.size > 20
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
|
|
362
387
|
def close
|
|
363
388
|
@ready = false
|
|
364
389
|
return unless @process
|
|
@@ -511,10 +536,16 @@ module ClaudeAgentSDK
|
|
|
511
536
|
returncode = status.exitstatus
|
|
512
537
|
|
|
513
538
|
if returncode && returncode != 0
|
|
539
|
+
# Wait briefly for stderr thread to finish draining
|
|
540
|
+
@stderr_task&.join(1)
|
|
541
|
+
|
|
542
|
+
stderr_text = @recent_stderr_mutex.synchronize { @recent_stderr.last(10).join("\n") }
|
|
543
|
+
stderr_text = 'No stderr output captured' if stderr_text.empty?
|
|
544
|
+
|
|
514
545
|
@exit_error = ProcessError.new(
|
|
515
546
|
"Command failed with exit code #{returncode}",
|
|
516
547
|
exit_code: returncode,
|
|
517
|
-
stderr:
|
|
548
|
+
stderr: stderr_text
|
|
518
549
|
)
|
|
519
550
|
raise @exit_error
|
|
520
551
|
end
|
|
@@ -144,6 +144,15 @@ module ClaudeAgentSDK
|
|
|
144
144
|
end
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
+
# Rate limit event emitted by Claude Code CLI when API rate limits are hit
|
|
148
|
+
class RateLimitEvent
|
|
149
|
+
attr_accessor :data
|
|
150
|
+
|
|
151
|
+
def initialize(data:)
|
|
152
|
+
@data = data
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
147
156
|
# Agent definition configuration
|
|
148
157
|
class AgentDefinition
|
|
149
158
|
attr_accessor :description, :prompt, :tools, :model
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: claude-agent-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Community Contributors
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-02-
|
|
10
|
+
date: 2026-02-18 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: async
|