claude-agent-sdk 0.4.2 → 0.5.0
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 +11 -0
- data/README.md +1 -1
- data/lib/claude_agent_sdk/configuration.rb +74 -0
- data/lib/claude_agent_sdk/types.rb +50 -75
- data/lib/claude_agent_sdk/version.rb +1 -1
- data/lib/claude_agent_sdk.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: acfb2780cc551ed4ff8cd1d96286636dd2d8d24b1ca3d34b93eadf15d1bbf49c
|
|
4
|
+
data.tar.gz: b3857039975c72fbf730e261831783db37efd00706bf30b2863b2feeceb58b3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa211da2013526662038143ed0cc7e04639a1821e5de8fdd7a6cc305f4d30fe495dd7b827796fd6e85e98612c61df2335120cbd2938a74736b1d31840719cf0f
|
|
7
|
+
data.tar.gz: 1bf84df24c779a99dbeeea776e00e53dc131bb2aca21a3bb2658ea7c3a972222bbfb0abef7d0ef48ec402490bd992074b82d7f806b8c3a98eb616f9d76421d20
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.5.0] - 2026-02-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Default configuration:** `ClaudeAgentSDK.configure` block for setting default options that merge with every `ClaudeAgentOptions` instance, ideal for Rails initializers (PR #8)
|
|
12
|
+
- `ClaudeAgentSDK.reset_configuration` for resetting defaults (useful in tests)
|
|
13
|
+
- Deep merge for `env` and `mcp_servers` hashes; provided values override configured defaults
|
|
14
|
+
- `OPTION_DEFAULTS` constant on `ClaudeAgentOptions` for introspectable non-nil defaults
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- `ClaudeAgentOptions#initialize` now uses `**kwargs` internally to correctly distinguish caller-provided values from method signature defaults
|
|
18
|
+
|
|
8
19
|
## [0.4.2] - 2026-02-07
|
|
9
20
|
|
|
10
21
|
### Fixed
|
data/README.md
CHANGED
|
@@ -38,7 +38,7 @@ Add this line to your application's Gemfile:
|
|
|
38
38
|
gem 'claude-agent-sdk', github: 'ya-luotao/claude-agent-sdk-ruby'
|
|
39
39
|
|
|
40
40
|
# Or use a stable version from RubyGems
|
|
41
|
-
gem 'claude-agent-sdk', '~> 0.
|
|
41
|
+
gem 'claude-agent-sdk', '~> 0.5.0'
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
And then execute:
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ClaudeAgentSDK
|
|
4
|
+
# Configuration class for setting default options
|
|
5
|
+
#
|
|
6
|
+
# Use this to set default options that will be merged with every request.
|
|
7
|
+
# This is especially useful in Rails applications where you want to
|
|
8
|
+
# configure defaults once during initialization.
|
|
9
|
+
#
|
|
10
|
+
# @example In a Rails initializer (config/initializers/claude_agent_sdk.rb)
|
|
11
|
+
# ClaudeAgentSDK.configure do |config|
|
|
12
|
+
# config.default_options = {
|
|
13
|
+
# env: {
|
|
14
|
+
# 'ANTHROPIC_API_KEY' => ENV['ANTHROPIC_API_KEY'],
|
|
15
|
+
# 'CUSTOM_VAR' => 'value'
|
|
16
|
+
# },
|
|
17
|
+
# permission_mode: 'bypassPermissions',
|
|
18
|
+
# model: 'sonnet'
|
|
19
|
+
# }
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# @example Then use ClaudeAgentSDK without repeating options
|
|
23
|
+
# # env and other defaults will be automatically applied
|
|
24
|
+
# ClaudeAgentSDK.query(prompt: "Hello!")
|
|
25
|
+
#
|
|
26
|
+
# # You can still override defaults when needed
|
|
27
|
+
# ClaudeAgentSDK.query(
|
|
28
|
+
# prompt: "Hello!",
|
|
29
|
+
# options: ClaudeAgentOptions.new(model: 'opus') # overrides default
|
|
30
|
+
# )
|
|
31
|
+
class Configuration
|
|
32
|
+
attr_accessor :default_options
|
|
33
|
+
|
|
34
|
+
def initialize
|
|
35
|
+
@default_options = {}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class << self
|
|
40
|
+
# Configure the SDK with default options
|
|
41
|
+
#
|
|
42
|
+
# @yield [Configuration] The configuration object
|
|
43
|
+
#
|
|
44
|
+
# @example Set default env and other options
|
|
45
|
+
# ClaudeAgentSDK.configure do |config|
|
|
46
|
+
# config.default_options = {
|
|
47
|
+
# env: { 'API_KEY' => 'xxx' },
|
|
48
|
+
# permission_mode: 'bypassPermissions'
|
|
49
|
+
# }
|
|
50
|
+
# end
|
|
51
|
+
def configure
|
|
52
|
+
yield(configuration)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Get the configuration object
|
|
56
|
+
#
|
|
57
|
+
# @return [Configuration] The current configuration
|
|
58
|
+
def configuration
|
|
59
|
+
@configuration ||= Configuration.new
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Reset configuration to defaults (useful for testing)
|
|
63
|
+
def reset_configuration
|
|
64
|
+
@configuration = Configuration.new
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Get merged default options for use with ClaudeAgentOptions
|
|
68
|
+
#
|
|
69
|
+
# @return [Hash] Default options hash
|
|
70
|
+
def default_options
|
|
71
|
+
configuration.default_options || {}
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -784,87 +784,62 @@ module ClaudeAgentSDK
|
|
|
784
784
|
:fallback_model, :plugins, :debug_stderr,
|
|
785
785
|
:betas, :tools, :sandbox, :enable_file_checkpointing, :append_allowed_tools
|
|
786
786
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
continue_conversation: false,
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
fork_session: false,
|
|
811
|
-
agents: nil,
|
|
812
|
-
setting_sources: nil,
|
|
813
|
-
output_format: nil,
|
|
814
|
-
max_budget_usd: nil,
|
|
815
|
-
max_thinking_tokens: nil,
|
|
816
|
-
fallback_model: nil,
|
|
817
|
-
plugins: nil,
|
|
818
|
-
debug_stderr: nil,
|
|
819
|
-
betas: nil,
|
|
820
|
-
tools: nil,
|
|
821
|
-
sandbox: nil,
|
|
822
|
-
enable_file_checkpointing: false,
|
|
823
|
-
append_allowed_tools: nil
|
|
824
|
-
)
|
|
825
|
-
@allowed_tools = allowed_tools
|
|
826
|
-
@system_prompt = system_prompt
|
|
827
|
-
@mcp_servers = mcp_servers
|
|
828
|
-
@permission_mode = permission_mode
|
|
829
|
-
@continue_conversation = continue_conversation
|
|
830
|
-
@resume = resume
|
|
831
|
-
@max_turns = max_turns
|
|
832
|
-
@disallowed_tools = disallowed_tools
|
|
833
|
-
@model = model
|
|
834
|
-
@permission_prompt_tool_name = permission_prompt_tool_name
|
|
835
|
-
@cwd = cwd
|
|
836
|
-
@cli_path = cli_path
|
|
837
|
-
@settings = settings
|
|
838
|
-
@add_dirs = add_dirs
|
|
839
|
-
@env = env
|
|
840
|
-
@extra_args = extra_args
|
|
841
|
-
@max_buffer_size = max_buffer_size
|
|
842
|
-
@stderr = stderr
|
|
843
|
-
@can_use_tool = can_use_tool
|
|
844
|
-
@hooks = hooks
|
|
845
|
-
@user = user
|
|
846
|
-
@include_partial_messages = include_partial_messages
|
|
847
|
-
@fork_session = fork_session
|
|
848
|
-
@agents = agents
|
|
849
|
-
@setting_sources = setting_sources
|
|
850
|
-
@output_format = output_format # JSON schema for structured output
|
|
851
|
-
@max_budget_usd = max_budget_usd # Spending cap in dollars
|
|
852
|
-
@max_thinking_tokens = max_thinking_tokens # Extended thinking token budget
|
|
853
|
-
@fallback_model = fallback_model # Backup model if primary unavailable
|
|
854
|
-
@plugins = plugins # Array of SdkPluginConfig
|
|
855
|
-
@debug_stderr = debug_stderr # Debug output file object/path
|
|
856
|
-
@betas = betas # Array of beta feature strings (e.g., ["context-1m-2025-08-07"])
|
|
857
|
-
@tools = tools # Base tools selection: Array, empty array [], or ToolsPreset
|
|
858
|
-
@sandbox = sandbox # SandboxSettings instance for isolated command execution
|
|
859
|
-
@enable_file_checkpointing = enable_file_checkpointing # Enable file checkpointing for rewind support
|
|
860
|
-
@append_allowed_tools = append_allowed_tools # Array of tools to append to allowed_tools
|
|
787
|
+
# Non-nil defaults for options that need them.
|
|
788
|
+
# Keys absent from here default to nil.
|
|
789
|
+
OPTION_DEFAULTS = {
|
|
790
|
+
allowed_tools: [], disallowed_tools: [], add_dirs: [],
|
|
791
|
+
mcp_servers: {}, env: {}, extra_args: {},
|
|
792
|
+
continue_conversation: false, include_partial_messages: false,
|
|
793
|
+
fork_session: false, enable_file_checkpointing: false
|
|
794
|
+
}.freeze
|
|
795
|
+
|
|
796
|
+
# Valid option names derived from attr_accessor declarations.
|
|
797
|
+
VALID_OPTIONS = instance_methods.grep(/=\z/).map { |m| m.to_s.chomp('=').to_sym }.freeze
|
|
798
|
+
|
|
799
|
+
# Using **kwargs lets us distinguish "caller passed allowed_tools: []"
|
|
800
|
+
# from "caller omitted allowed_tools" — critical for correct merge with
|
|
801
|
+
# configured defaults.
|
|
802
|
+
def initialize(**kwargs)
|
|
803
|
+
unknown = kwargs.keys - VALID_OPTIONS
|
|
804
|
+
raise ArgumentError, "unknown keyword#{'s' if unknown.size > 1}: #{unknown.join(', ')}" if unknown.any?
|
|
805
|
+
|
|
806
|
+
merged = merge_with_defaults(kwargs)
|
|
807
|
+
OPTION_DEFAULTS.merge(merged).each do |key, value|
|
|
808
|
+
instance_variable_set(:"@#{key}", value)
|
|
809
|
+
end
|
|
861
810
|
end
|
|
862
811
|
|
|
863
812
|
def dup_with(**changes)
|
|
864
813
|
new_options = self.dup
|
|
865
|
-
changes.each { |key, value| new_options.send("#{key}=", value) }
|
|
814
|
+
changes.each { |key, value| new_options.send(:"#{key}=", value) }
|
|
866
815
|
new_options
|
|
867
816
|
end
|
|
817
|
+
|
|
818
|
+
private
|
|
819
|
+
|
|
820
|
+
# Merge caller-provided kwargs with configured defaults.
|
|
821
|
+
# Only keys the caller explicitly passed are treated as overrides;
|
|
822
|
+
# method-signature defaults ([], {}, false) are NOT in kwargs unless the caller wrote them.
|
|
823
|
+
def merge_with_defaults(kwargs)
|
|
824
|
+
return OPTION_DEFAULTS.merge(kwargs) unless defined?(ClaudeAgentSDK) && ClaudeAgentSDK.respond_to?(:default_options)
|
|
825
|
+
|
|
826
|
+
defaults = ClaudeAgentSDK.default_options
|
|
827
|
+
return OPTION_DEFAULTS.merge(kwargs) unless defaults.any?
|
|
828
|
+
|
|
829
|
+
# Start from configured defaults (deep dup hashes to prevent mutation)
|
|
830
|
+
result = defaults.transform_values { |v| v.is_a?(Hash) ? v.dup : v }
|
|
831
|
+
kwargs.each do |key, value|
|
|
832
|
+
default_val = result[key]
|
|
833
|
+
result[key] = if value.nil?
|
|
834
|
+
default_val # nil means "no preference" — keep the configured default
|
|
835
|
+
elsif default_val.is_a?(Hash) && value.is_a?(Hash)
|
|
836
|
+
default_val.merge(value)
|
|
837
|
+
else
|
|
838
|
+
value
|
|
839
|
+
end
|
|
840
|
+
end
|
|
841
|
+
OPTION_DEFAULTS.merge(result)
|
|
842
|
+
end
|
|
868
843
|
end
|
|
869
844
|
|
|
870
845
|
# SDK MCP Tool definition
|
data/lib/claude_agent_sdk.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'claude_agent_sdk/version'
|
|
4
4
|
require_relative 'claude_agent_sdk/errors'
|
|
5
|
+
require_relative 'claude_agent_sdk/configuration'
|
|
5
6
|
require_relative 'claude_agent_sdk/types'
|
|
6
7
|
require_relative 'claude_agent_sdk/transport'
|
|
7
8
|
require_relative 'claude_agent_sdk/subprocess_cli_transport'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: claude-agent-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Community Contributors
|
|
@@ -104,6 +104,7 @@ files:
|
|
|
104
104
|
- LICENSE
|
|
105
105
|
- README.md
|
|
106
106
|
- lib/claude_agent_sdk.rb
|
|
107
|
+
- lib/claude_agent_sdk/configuration.rb
|
|
107
108
|
- lib/claude_agent_sdk/errors.rb
|
|
108
109
|
- lib/claude_agent_sdk/message_parser.rb
|
|
109
110
|
- lib/claude_agent_sdk/query.rb
|