claude-agent-sdk 0.35.0 → 0.37.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 +74 -0
- data/README.md +17 -8
- data/docs/cli-installer.md +16 -2
- data/docs/client.md +44 -4
- data/docs/errors.md +15 -1
- data/docs/hooks-and-permissions.md +27 -3
- data/docs/mcp-servers.md +36 -7
- data/docs/rails.md +3 -4
- data/docs/sessions.md +149 -34
- data/docs/types.md +106 -4
- data/lib/claude_agent_sdk/cancellation_signal.rb +2 -1
- data/lib/claude_agent_sdk/cli_installer.rb +68 -11
- data/lib/claude_agent_sdk/command_builder.rb +109 -98
- data/lib/claude_agent_sdk/deprecation.rb +90 -0
- data/lib/claude_agent_sdk/errors.rb +8 -0
- data/lib/claude_agent_sdk/fiber_boundary.rb +113 -2
- data/lib/claude_agent_sdk/instrumentation/otel.rb +15 -7
- data/lib/claude_agent_sdk/message_parser.rb +23 -9
- data/lib/claude_agent_sdk/observer.rb +2 -1
- data/lib/claude_agent_sdk/option_warnings.rb +2 -2
- data/lib/claude_agent_sdk/query.rb +99 -51
- data/lib/claude_agent_sdk/railtie.rb +14 -3
- data/lib/claude_agent_sdk/sdk_mcp_server.rb +58 -38
- data/lib/claude_agent_sdk/session_mutations.rb +28 -16
- data/lib/claude_agent_sdk/session_resume.rb +39 -35
- data/lib/claude_agent_sdk/session_store.rb +35 -21
- data/lib/claude_agent_sdk/session_summary.rb +12 -5
- data/lib/claude_agent_sdk/sessions.rb +112 -24
- data/lib/claude_agent_sdk/streaming.rb +1 -1
- data/lib/claude_agent_sdk/subprocess_cli_transport.rb +75 -52
- data/lib/claude_agent_sdk/tasks/claude_agent_sdk.rake +12 -5
- data/lib/claude_agent_sdk/testing/session_store_conformance.rb +15 -11
- data/lib/claude_agent_sdk/transcript_mirror_batcher.rb +19 -1
- data/lib/claude_agent_sdk/types/attributes.rb +271 -0
- data/lib/claude_agent_sdk/types/base.rb +320 -0
- data/lib/claude_agent_sdk/types/content_blocks.rb +57 -0
- data/lib/claude_agent_sdk/types/hooks.rb +640 -0
- data/lib/claude_agent_sdk/types/mcp.rb +232 -0
- data/lib/claude_agent_sdk/types/messages.rb +614 -0
- data/lib/claude_agent_sdk/types/option_values.rb +302 -0
- data/lib/claude_agent_sdk/types/options.rb +352 -0
- data/lib/claude_agent_sdk/types/permissions.rb +107 -0
- data/lib/claude_agent_sdk/types/sessions.rb +10 -0
- data/lib/claude_agent_sdk/types.rb +13 -2534
- data/lib/claude_agent_sdk/version.rb +1 -1
- data/lib/claude_agent_sdk.rb +308 -73
- data/lib/generators/claude_agent_sdk/install/templates/claude_agent_sdk.rb.tt +3 -3
- metadata +12 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base'
|
|
4
|
+
|
|
5
|
+
module ClaudeAgentSDK
|
|
6
|
+
# Type constants for permission modes
|
|
7
|
+
PERMISSION_MODES = %w[default acceptEdits plan bypassPermissions dontAsk auto].freeze
|
|
8
|
+
|
|
9
|
+
# Type constants for permission update destinations
|
|
10
|
+
PERMISSION_UPDATE_DESTINATIONS = %w[userSettings projectSettings localSettings session].freeze
|
|
11
|
+
|
|
12
|
+
# Type constants for permission behaviors
|
|
13
|
+
PERMISSION_BEHAVIORS = %w[allow deny ask].freeze
|
|
14
|
+
|
|
15
|
+
# Permission rule value
|
|
16
|
+
class PermissionRuleValue < Type
|
|
17
|
+
strict_attributes
|
|
18
|
+
|
|
19
|
+
attr_accessor :tool_name, :rule_content
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Permission update configuration
|
|
23
|
+
class PermissionUpdate < Type
|
|
24
|
+
strict_attributes
|
|
25
|
+
|
|
26
|
+
attr_accessor :type, :behavior, :mode, :directories, :destination
|
|
27
|
+
attr_reader :rules
|
|
28
|
+
|
|
29
|
+
# Wire-format parity with Python PermissionUpdate.from_dict (#920): the CLI
|
|
30
|
+
# sends rules as camelCase hashes ({toolName:, ruleContent:}); hydrate them
|
|
31
|
+
# into PermissionRuleValue (Type#assign_attribute normalizes the camelCase
|
|
32
|
+
# keys). Already-typed PermissionRuleValue entries pass through unchanged.
|
|
33
|
+
def rules=(value)
|
|
34
|
+
@rules = value&.map { |rule| rule.is_a?(Hash) ? PermissionRuleValue.new(rule) : rule }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def to_h
|
|
38
|
+
result = { type: @type }
|
|
39
|
+
result[:destination] = @destination if @destination
|
|
40
|
+
|
|
41
|
+
case @type
|
|
42
|
+
when 'addRules', 'replaceRules', 'removeRules'
|
|
43
|
+
if @rules
|
|
44
|
+
result[:rules] = @rules.map do |rule|
|
|
45
|
+
{
|
|
46
|
+
toolName: rule.tool_name,
|
|
47
|
+
ruleContent: rule.rule_content
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
result[:behavior] = @behavior if @behavior
|
|
52
|
+
when 'setMode'
|
|
53
|
+
result[:mode] = @mode if @mode
|
|
54
|
+
when 'addDirectories', 'removeDirectories'
|
|
55
|
+
result[:directories] = @directories if @directories
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
result
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Tool permission context delivered to `can_use_tool` callbacks.
|
|
63
|
+
# CLI 2.1.110+ began populating the four pre-formatted display fields
|
|
64
|
+
# (`title`, `display_name`, `description`, `blocked_path`,
|
|
65
|
+
# `decision_reason`) so the SDK consumer can render the same prompt UI
|
|
66
|
+
# the CLI would have shown. Older fields (`signal`, `suggestions`,
|
|
67
|
+
# `tool_use_id`, `agent_id`) remain unchanged.
|
|
68
|
+
# `signal` is a CancellationSignal on dispatched callbacks; `request_id`
|
|
69
|
+
# identifies this permission request (distinct from the tool invocation).
|
|
70
|
+
class ToolPermissionContext < Type
|
|
71
|
+
attr_accessor :signal, :request_id, :suggestions, :tool_use_id, :agent_id,
|
|
72
|
+
:title, :display_name, :description,
|
|
73
|
+
:blocked_path, :decision_reason
|
|
74
|
+
|
|
75
|
+
def initialize(attributes = {})
|
|
76
|
+
super
|
|
77
|
+
@suggestions ||= []
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Permission results
|
|
82
|
+
class PermissionResultAllow < Type
|
|
83
|
+
strict_attributes
|
|
84
|
+
|
|
85
|
+
attr_accessor :updated_input, :updated_permissions
|
|
86
|
+
attr_reader :behavior
|
|
87
|
+
|
|
88
|
+
def initialize(attributes = {})
|
|
89
|
+
super
|
|
90
|
+
@behavior = 'allow'
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
class PermissionResultDeny < Type
|
|
95
|
+
strict_attributes
|
|
96
|
+
|
|
97
|
+
attr_accessor :message, :interrupt
|
|
98
|
+
attr_reader :behavior
|
|
99
|
+
|
|
100
|
+
def initialize(attributes = {})
|
|
101
|
+
super
|
|
102
|
+
@behavior = 'deny'
|
|
103
|
+
@message ||= ''
|
|
104
|
+
@interrupt = false if @interrupt.nil?
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|