claude_agent 0.1.0 → 0.2.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 +10 -0
- data/SPEC.md +14 -11
- data/lib/claude_agent/options.rb +3 -1
- data/lib/claude_agent/permissions.rb +18 -10
- data/lib/claude_agent/session.rb +207 -0
- data/lib/claude_agent/types.rb +5 -3
- data/lib/claude_agent/version.rb +1 -1
- data/lib/claude_agent.rb +1 -0
- data/sig/claude_agent.rbs +43 -4
- 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: 791bfc30df3cce213645d97676501c53e0acd5cbcedeacadbd61b810469c2be5
|
|
4
|
+
data.tar.gz: 5cdf1984dd821ce465165e6887dcb430989669692924d747e4a23d49f7aae0ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6824f825982dc3066a6512f9d2d8a84253f6b861916b76917792ab9bf5a7f52a026105de09ab357e0a99a9cd289a77f6f7574c3e71569d1f8d2bcfa6fb31997d
|
|
7
|
+
data.tar.gz: df13b541959f5962c385b5295508b89f03471c2617e0b787747e130cddae9d2d74b512d3c2a63a9d959290d10c2d3f676241dec9f4ffc4a51caea12717e7eacf
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0] - 2026-01-11
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- V2 Session API for multi-turn conversations (`unstable_v2_create_session`, `unstable_v2_resume_session`, `unstable_v2_prompt`)
|
|
14
|
+
- `Session` class for stateful conversation management
|
|
15
|
+
- `SessionOptions` data type for V2 API configuration
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- `Options#initialize` now correctly handles nil values without overriding defaults
|
|
19
|
+
|
|
10
20
|
## [0.1.0] - 2026-01-10
|
|
11
21
|
|
|
12
22
|
### Added
|
data/SPEC.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
This document provides a comprehensive specification of the Claude Agent SDK, comparing feature parity across the official TypeScript and Python SDKs with this Ruby implementation.
|
|
4
4
|
|
|
5
5
|
**Reference Versions:**
|
|
6
|
-
- TypeScript SDK: v0.2.
|
|
7
|
-
- Python SDK: Latest from GitHub (commit
|
|
6
|
+
- TypeScript SDK: v0.2.5 (npm package)
|
|
7
|
+
- Python SDK: Latest from GitHub (commit 3b7e3ba)
|
|
8
8
|
- Ruby SDK: This repository
|
|
9
9
|
|
|
10
10
|
---
|
|
@@ -64,12 +64,12 @@ Configuration options for SDK queries and clients.
|
|
|
64
64
|
| `sandbox` | ✅ | ✅ | ✅ | Sandbox settings |
|
|
65
65
|
| `settingSources` | ✅ | ✅ | ✅ | Which settings to load |
|
|
66
66
|
| `plugins` | ✅ | ✅ | ✅ | Plugin configurations |
|
|
67
|
-
| `betas` | ✅ | ✅ | ✅ | Beta features (e.g., context-1m)
|
|
67
|
+
| `betas` | ✅ | ✅ | ✅ | Beta features (e.g., context-1m-2025-08-07) |
|
|
68
68
|
| `abortController` | ✅ | ❌ | ✅ | Cancellation controller |
|
|
69
69
|
| `stderr` | ✅ | ✅ | ✅ | Stderr callback |
|
|
70
70
|
| `spawnClaudeCodeProcess` | ✅ | ❌ | ✅ | Custom spawn function |
|
|
71
71
|
| `pathToClaudeCodeExecutable` | ✅ | ✅ | ✅ | Custom CLI path |
|
|
72
|
-
| `executable` | ✅ | ❌ | ❌ | JS runtime (bun/deno
|
|
72
|
+
| `executable` | ✅ | ❌ | ❌ | JS runtime (node/bun/deno) |
|
|
73
73
|
| `executableArgs` | ✅ | ❌ | ❌ | JS runtime args |
|
|
74
74
|
| `extraArgs` | ✅ | ✅ | ✅ | Extra CLI arguments |
|
|
75
75
|
| `user` | ❌ | ✅ | ✅ | User identifier |
|
|
@@ -289,7 +289,7 @@ Permission handling and updates.
|
|
|
289
289
|
| `updatedPermissions` | ✅ | ✅ | ✅ |
|
|
290
290
|
| `message` (deny) | ✅ | ✅ | ✅ |
|
|
291
291
|
| `interrupt` (deny) | ✅ | ✅ | ✅ |
|
|
292
|
-
| `toolUseID` | ✅ | ❌ |
|
|
292
|
+
| `toolUseID` | ✅ | ❌ | ✅ |
|
|
293
293
|
|
|
294
294
|
### Permission Update Types
|
|
295
295
|
|
|
@@ -316,7 +316,7 @@ Permission handling and updates.
|
|
|
316
316
|
|
|
317
317
|
| Field | TypeScript | Python | Ruby | Notes |
|
|
318
318
|
|------------------|:----------:|:------:|:----:|---------------------------|
|
|
319
|
-
| `signal` | ✅ | ✅ |
|
|
319
|
+
| `signal` | ✅ | ✅ | ✅ | Abort signal |
|
|
320
320
|
| `suggestions` | ✅ | ✅ | ✅ | Permission suggestions |
|
|
321
321
|
| `blockedPath` | ✅ | ✅ | ✅ | Blocked file path |
|
|
322
322
|
| `decisionReason` | ✅ | ❌ | ✅ | Why permission triggered |
|
|
@@ -392,10 +392,10 @@ Session management and resumption.
|
|
|
392
392
|
|
|
393
393
|
| Feature | TypeScript | Python | Ruby | Notes |
|
|
394
394
|
|-----------------------------|:----------:|:------:|:----:|---------------------------|
|
|
395
|
-
| `SDKSession` interface | ✅ | ❌ |
|
|
396
|
-
| `unstable_v2_createSession` | ✅ | ❌ |
|
|
397
|
-
| `unstable_v2_resumeSession` | ✅ | ❌ |
|
|
398
|
-
| `unstable_v2_prompt` | ✅ | ❌ |
|
|
395
|
+
| `SDKSession` interface | ✅ | ❌ | ✅ | Multi-turn session object |
|
|
396
|
+
| `unstable_v2_createSession` | ✅ | ❌ | ✅ | Create new session |
|
|
397
|
+
| `unstable_v2_resumeSession` | ✅ | ❌ | ✅ | Resume existing session |
|
|
398
|
+
| `unstable_v2_prompt` | ✅ | ❌ | ✅ | One-shot prompt |
|
|
399
399
|
|
|
400
400
|
---
|
|
401
401
|
|
|
@@ -541,7 +541,9 @@ Public API surface for SDK clients.
|
|
|
541
541
|
- Primary reference for API surface (most comprehensive)
|
|
542
542
|
- Source is bundled/minified, but `sdk.d.ts` provides complete type definitions
|
|
543
543
|
- Includes unstable V2 session API
|
|
544
|
-
- Version 0.2.
|
|
544
|
+
- Version 0.2.5 includes `maxOutputTokens` field in `ModelUsage`
|
|
545
|
+
- Adds `deno` as supported executable option
|
|
546
|
+
- Includes experimental `criticalSystemReminder_EXPERIMENTAL` for agent definitions
|
|
545
547
|
|
|
546
548
|
### Python SDK
|
|
547
549
|
- Full source available
|
|
@@ -556,3 +558,4 @@ Public API surface for SDK clients.
|
|
|
556
558
|
- Complete control protocol support
|
|
557
559
|
- Dedicated Client class for multi-turn conversations
|
|
558
560
|
- Full hook event support including all 12 events
|
|
561
|
+
- Full V2 Session API support (unstable)
|
data/lib/claude_agent/options.rb
CHANGED
|
@@ -60,7 +60,9 @@ module ClaudeAgent
|
|
|
60
60
|
attr_accessor(*ATTRIBUTES)
|
|
61
61
|
|
|
62
62
|
def initialize(**kwargs)
|
|
63
|
-
|
|
63
|
+
# Remove nil values so they don't override defaults
|
|
64
|
+
filtered = kwargs.compact
|
|
65
|
+
merged = DEFAULTS.merge(filtered)
|
|
64
66
|
ATTRIBUTES.each do |attr|
|
|
65
67
|
instance_variable_set(:"@#{attr}", merged[attr])
|
|
66
68
|
end
|
|
@@ -5,11 +5,12 @@ module ClaudeAgent
|
|
|
5
5
|
#
|
|
6
6
|
# @example Allow with modified input
|
|
7
7
|
# PermissionResultAllow.new(
|
|
8
|
-
# updated_input: input.merge("safe" => true)
|
|
8
|
+
# updated_input: input.merge("safe" => true),
|
|
9
|
+
# tool_use_id: "tool_123"
|
|
9
10
|
# )
|
|
10
11
|
#
|
|
11
|
-
PermissionResultAllow = Data.define(:updated_input, :updated_permissions) do
|
|
12
|
-
def initialize(updated_input: nil, updated_permissions: nil)
|
|
12
|
+
PermissionResultAllow = Data.define(:updated_input, :updated_permissions, :tool_use_id) do
|
|
13
|
+
def initialize(updated_input: nil, updated_permissions: nil, tool_use_id: nil)
|
|
13
14
|
super
|
|
14
15
|
end
|
|
15
16
|
|
|
@@ -21,6 +22,7 @@ module ClaudeAgent
|
|
|
21
22
|
h = { behavior: "allow" }
|
|
22
23
|
h[:updatedInput] = updated_input if updated_input
|
|
23
24
|
h[:updatedPermissions] = updated_permissions&.map { |p| p.respond_to?(:to_h) ? p.to_h : p } if updated_permissions
|
|
25
|
+
h[:toolUseID] = tool_use_id if tool_use_id
|
|
24
26
|
h
|
|
25
27
|
end
|
|
26
28
|
end
|
|
@@ -30,11 +32,12 @@ module ClaudeAgent
|
|
|
30
32
|
# @example Deny with message
|
|
31
33
|
# PermissionResultDeny.new(
|
|
32
34
|
# message: "Operation not allowed",
|
|
33
|
-
# interrupt: true
|
|
35
|
+
# interrupt: true,
|
|
36
|
+
# tool_use_id: "tool_123"
|
|
34
37
|
# )
|
|
35
38
|
#
|
|
36
|
-
PermissionResultDeny = Data.define(:message, :interrupt) do
|
|
37
|
-
def initialize(message: "", interrupt: false)
|
|
39
|
+
PermissionResultDeny = Data.define(:message, :interrupt, :tool_use_id) do
|
|
40
|
+
def initialize(message: "", interrupt: false, tool_use_id: nil)
|
|
38
41
|
super
|
|
39
42
|
end
|
|
40
43
|
|
|
@@ -43,7 +46,9 @@ module ClaudeAgent
|
|
|
43
46
|
end
|
|
44
47
|
|
|
45
48
|
def to_h
|
|
46
|
-
{ behavior: "deny", message: message, interrupt: interrupt }
|
|
49
|
+
h = { behavior: "deny", message: message, interrupt: interrupt }
|
|
50
|
+
h[:toolUseID] = tool_use_id if tool_use_id
|
|
51
|
+
h
|
|
47
52
|
end
|
|
48
53
|
end
|
|
49
54
|
|
|
@@ -141,7 +146,8 @@ module ClaudeAgent
|
|
|
141
146
|
# blocked_path: "/etc/passwd",
|
|
142
147
|
# decision_reason: "Path outside allowed directories",
|
|
143
148
|
# tool_use_id: "tool_123",
|
|
144
|
-
# agent_id: "agent_456"
|
|
149
|
+
# agent_id: "agent_456",
|
|
150
|
+
# signal: abort_signal
|
|
145
151
|
# )
|
|
146
152
|
#
|
|
147
153
|
ToolPermissionContext = Data.define(
|
|
@@ -149,14 +155,16 @@ module ClaudeAgent
|
|
|
149
155
|
:blocked_path,
|
|
150
156
|
:decision_reason,
|
|
151
157
|
:tool_use_id,
|
|
152
|
-
:agent_id
|
|
158
|
+
:agent_id,
|
|
159
|
+
:signal
|
|
153
160
|
) do
|
|
154
161
|
def initialize(
|
|
155
162
|
permission_suggestions: nil,
|
|
156
163
|
blocked_path: nil,
|
|
157
164
|
decision_reason: nil,
|
|
158
165
|
tool_use_id: nil,
|
|
159
|
-
agent_id: nil
|
|
166
|
+
agent_id: nil,
|
|
167
|
+
signal: nil
|
|
160
168
|
)
|
|
161
169
|
super
|
|
162
170
|
end
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ClaudeAgent
|
|
4
|
+
# V2 Session options (subset of full Options)
|
|
5
|
+
# V2 API - UNSTABLE
|
|
6
|
+
# @alpha
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# options = SessionOptions.new(
|
|
10
|
+
# model: "claude-sonnet-4-5-20250929",
|
|
11
|
+
# permission_mode: "acceptEdits"
|
|
12
|
+
# )
|
|
13
|
+
#
|
|
14
|
+
SessionOptions = Data.define(
|
|
15
|
+
:model,
|
|
16
|
+
:path_to_claude_code_executable,
|
|
17
|
+
:env,
|
|
18
|
+
:allowed_tools,
|
|
19
|
+
:disallowed_tools,
|
|
20
|
+
:can_use_tool,
|
|
21
|
+
:hooks,
|
|
22
|
+
:permission_mode
|
|
23
|
+
) do
|
|
24
|
+
def initialize(
|
|
25
|
+
model:,
|
|
26
|
+
path_to_claude_code_executable: nil,
|
|
27
|
+
env: nil,
|
|
28
|
+
allowed_tools: nil,
|
|
29
|
+
disallowed_tools: nil,
|
|
30
|
+
can_use_tool: nil,
|
|
31
|
+
hooks: nil,
|
|
32
|
+
permission_mode: nil
|
|
33
|
+
)
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# V2 API - UNSTABLE
|
|
39
|
+
# Multi-turn session interface for persistent conversations.
|
|
40
|
+
#
|
|
41
|
+
# This provides a simpler interface than the full Client class,
|
|
42
|
+
# matching the TypeScript SDK's SDKSession interface.
|
|
43
|
+
#
|
|
44
|
+
# @alpha
|
|
45
|
+
#
|
|
46
|
+
# @example Create a session and send messages
|
|
47
|
+
# session = ClaudeAgent.unstable_v2_create_session(model: "claude-sonnet-4-5-20250929")
|
|
48
|
+
# session.send("Hello!")
|
|
49
|
+
# session.stream.each { |msg| puts msg.inspect }
|
|
50
|
+
# session.close
|
|
51
|
+
#
|
|
52
|
+
class Session
|
|
53
|
+
attr_reader :session_id, :options
|
|
54
|
+
|
|
55
|
+
def initialize(options)
|
|
56
|
+
@options = options.is_a?(SessionOptions) ? options : SessionOptions.new(**options)
|
|
57
|
+
@client = nil
|
|
58
|
+
@session_id = nil
|
|
59
|
+
@closed = false
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Send a message to the agent
|
|
63
|
+
#
|
|
64
|
+
# @param message [String, UserMessage] The message to send
|
|
65
|
+
# @return [void]
|
|
66
|
+
def send(message)
|
|
67
|
+
ensure_connected!
|
|
68
|
+
content = message.is_a?(String) ? message : message
|
|
69
|
+
@client.send_message(content)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Stream messages from the agent
|
|
73
|
+
#
|
|
74
|
+
# @return [Enumerator<message>] An enumerator of messages
|
|
75
|
+
# @yield [message] Each message received from the agent
|
|
76
|
+
def stream(&block)
|
|
77
|
+
ensure_connected!
|
|
78
|
+
if block_given?
|
|
79
|
+
@client.receive_response(&block)
|
|
80
|
+
else
|
|
81
|
+
@client.receive_response
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Close the session
|
|
86
|
+
#
|
|
87
|
+
# @return [void]
|
|
88
|
+
def close
|
|
89
|
+
return if @closed
|
|
90
|
+
@client&.disconnect
|
|
91
|
+
@closed = true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Check if session is closed
|
|
95
|
+
#
|
|
96
|
+
# @return [Boolean]
|
|
97
|
+
def closed?
|
|
98
|
+
@closed
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
def ensure_connected!
|
|
104
|
+
raise AbortError, "Session is closed" if @closed
|
|
105
|
+
return if @client&.connected?
|
|
106
|
+
|
|
107
|
+
@client = Client.new(options: build_client_options)
|
|
108
|
+
@client.connect
|
|
109
|
+
update_session_id
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def build_client_options
|
|
113
|
+
Options.new(
|
|
114
|
+
model: @options.model,
|
|
115
|
+
cli_path: @options.path_to_claude_code_executable,
|
|
116
|
+
env: @options.env,
|
|
117
|
+
allowed_tools: @options.allowed_tools,
|
|
118
|
+
disallowed_tools: @options.disallowed_tools,
|
|
119
|
+
can_use_tool: @options.can_use_tool,
|
|
120
|
+
hooks: @options.hooks,
|
|
121
|
+
permission_mode: @options.permission_mode
|
|
122
|
+
)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def update_session_id
|
|
126
|
+
# Session ID is typically extracted from the first system message
|
|
127
|
+
# but since we don't have it immediately, we leave it nil until available
|
|
128
|
+
@session_id = @client.server_info&.dig("session_id")
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
class << self
|
|
133
|
+
# V2 API - UNSTABLE
|
|
134
|
+
# Create a persistent session for multi-turn conversations.
|
|
135
|
+
#
|
|
136
|
+
# @param options [Hash, SessionOptions] Session configuration
|
|
137
|
+
# @return [Session] A new session instance
|
|
138
|
+
# @alpha
|
|
139
|
+
#
|
|
140
|
+
# @example
|
|
141
|
+
# session = ClaudeAgent.unstable_v2_create_session(model: "claude-sonnet-4-5-20250929")
|
|
142
|
+
#
|
|
143
|
+
def unstable_v2_create_session(options)
|
|
144
|
+
Session.new(options)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# V2 API - UNSTABLE
|
|
148
|
+
# Resume an existing session by ID.
|
|
149
|
+
#
|
|
150
|
+
# @param session_id [String] The session ID to resume
|
|
151
|
+
# @param options [Hash, SessionOptions] Session configuration
|
|
152
|
+
# @return [Session] A session configured to resume the specified session
|
|
153
|
+
# @alpha
|
|
154
|
+
#
|
|
155
|
+
# @example
|
|
156
|
+
# session = ClaudeAgent.unstable_v2_resume_session("session-abc123", model: "claude-sonnet-4-5-20250929")
|
|
157
|
+
#
|
|
158
|
+
def unstable_v2_resume_session(session_id, options)
|
|
159
|
+
# For resumption, we need to pass the resume option through
|
|
160
|
+
# Since SessionOptions doesn't have resume, we handle it in the Client options
|
|
161
|
+
session = Session.new(options)
|
|
162
|
+
session.instance_variable_set(:@resume_session_id, session_id)
|
|
163
|
+
|
|
164
|
+
# Override build_client_options to include resume
|
|
165
|
+
session.define_singleton_method(:build_client_options) do
|
|
166
|
+
Options.new(
|
|
167
|
+
model: @options.model,
|
|
168
|
+
cli_path: @options.path_to_claude_code_executable,
|
|
169
|
+
env: @options.env,
|
|
170
|
+
allowed_tools: @options.allowed_tools,
|
|
171
|
+
disallowed_tools: @options.disallowed_tools,
|
|
172
|
+
can_use_tool: @options.can_use_tool,
|
|
173
|
+
hooks: @options.hooks,
|
|
174
|
+
permission_mode: @options.permission_mode,
|
|
175
|
+
resume: @resume_session_id
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
session
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# V2 API - UNSTABLE
|
|
183
|
+
# One-shot convenience function for single prompts.
|
|
184
|
+
#
|
|
185
|
+
# @param message [String] The prompt message
|
|
186
|
+
# @param options [Hash, SessionOptions] Session configuration
|
|
187
|
+
# @return [ResultMessage] The result of the query
|
|
188
|
+
# @alpha
|
|
189
|
+
#
|
|
190
|
+
# @example
|
|
191
|
+
# result = ClaudeAgent.unstable_v2_prompt("What files are here?", model: "claude-sonnet-4-5-20250929")
|
|
192
|
+
#
|
|
193
|
+
def unstable_v2_prompt(message, options)
|
|
194
|
+
session = unstable_v2_create_session(options)
|
|
195
|
+
begin
|
|
196
|
+
session.send(message)
|
|
197
|
+
result = nil
|
|
198
|
+
session.stream.each do |msg|
|
|
199
|
+
result = msg if msg.is_a?(ResultMessage)
|
|
200
|
+
end
|
|
201
|
+
result
|
|
202
|
+
ensure
|
|
203
|
+
session.close
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
data/lib/claude_agent/types.rb
CHANGED
|
@@ -83,7 +83,7 @@ module ClaudeAgent
|
|
|
83
83
|
# Per-model usage statistics returned in result messages (TypeScript SDK parity)
|
|
84
84
|
#
|
|
85
85
|
# @example
|
|
86
|
-
# usage = ModelUsage.new(input_tokens: 100, output_tokens: 50, cost_usd: 0.01)
|
|
86
|
+
# usage = ModelUsage.new(input_tokens: 100, output_tokens: 50, cost_usd: 0.01, max_output_tokens: 4096)
|
|
87
87
|
#
|
|
88
88
|
ModelUsage = Data.define(
|
|
89
89
|
:input_tokens,
|
|
@@ -92,7 +92,8 @@ module ClaudeAgent
|
|
|
92
92
|
:cache_creation_input_tokens,
|
|
93
93
|
:web_search_requests,
|
|
94
94
|
:cost_usd,
|
|
95
|
-
:context_window
|
|
95
|
+
:context_window,
|
|
96
|
+
:max_output_tokens
|
|
96
97
|
) do
|
|
97
98
|
def initialize(
|
|
98
99
|
input_tokens: 0,
|
|
@@ -101,7 +102,8 @@ module ClaudeAgent
|
|
|
101
102
|
cache_creation_input_tokens: 0,
|
|
102
103
|
web_search_requests: 0,
|
|
103
104
|
cost_usd: 0.0,
|
|
104
|
-
context_window: nil
|
|
105
|
+
context_window: nil,
|
|
106
|
+
max_output_tokens: nil
|
|
105
107
|
)
|
|
106
108
|
super
|
|
107
109
|
end
|
data/lib/claude_agent/version.rb
CHANGED
data/lib/claude_agent.rb
CHANGED
|
@@ -22,6 +22,7 @@ require_relative "claude_agent/mcp/tool"
|
|
|
22
22
|
require_relative "claude_agent/mcp/server"
|
|
23
23
|
require_relative "claude_agent/query"
|
|
24
24
|
require_relative "claude_agent/client"
|
|
25
|
+
require_relative "claude_agent/session" # V2 Session API (unstable)
|
|
25
26
|
|
|
26
27
|
module ClaudeAgent
|
|
27
28
|
# Re-export key classes at module level for convenience
|
data/sig/claude_agent.rbs
CHANGED
|
@@ -122,8 +122,9 @@ module ClaudeAgent
|
|
|
122
122
|
attr_reader web_search_requests: Integer
|
|
123
123
|
attr_reader cost_usd: Float
|
|
124
124
|
attr_reader context_window: Integer?
|
|
125
|
+
attr_reader max_output_tokens: Integer?
|
|
125
126
|
|
|
126
|
-
def initialize: (?input_tokens: Integer, ?output_tokens: Integer, ?cache_read_input_tokens: Integer, ?cache_creation_input_tokens: Integer, ?web_search_requests: Integer, ?cost_usd: Float, ?context_window: Integer?) -> void
|
|
127
|
+
def initialize: (?input_tokens: Integer, ?output_tokens: Integer, ?cache_read_input_tokens: Integer, ?cache_creation_input_tokens: Integer, ?web_search_requests: Integer, ?cost_usd: Float, ?context_window: Integer?, ?max_output_tokens: Integer?) -> void
|
|
127
128
|
end
|
|
128
129
|
|
|
129
130
|
class SDKPermissionDenial
|
|
@@ -687,8 +688,9 @@ module ClaudeAgent
|
|
|
687
688
|
class PermissionResultAllow
|
|
688
689
|
attr_reader updated_input: Hash[String, untyped]?
|
|
689
690
|
attr_reader updated_permissions: Array[PermissionUpdate]?
|
|
691
|
+
attr_reader tool_use_id: String?
|
|
690
692
|
|
|
691
|
-
def initialize: (?updated_input: Hash[String, untyped]?, ?updated_permissions: Array[PermissionUpdate]?) -> void
|
|
693
|
+
def initialize: (?updated_input: Hash[String, untyped]?, ?updated_permissions: Array[PermissionUpdate]?, ?tool_use_id: String?) -> void
|
|
692
694
|
def behavior: () -> "allow"
|
|
693
695
|
def to_h: () -> Hash[Symbol, untyped]
|
|
694
696
|
end
|
|
@@ -696,8 +698,9 @@ module ClaudeAgent
|
|
|
696
698
|
class PermissionResultDeny
|
|
697
699
|
attr_reader message: String
|
|
698
700
|
attr_reader interrupt: bool
|
|
701
|
+
attr_reader tool_use_id: String?
|
|
699
702
|
|
|
700
|
-
def initialize: (?message: String, ?interrupt: bool) -> void
|
|
703
|
+
def initialize: (?message: String, ?interrupt: bool, ?tool_use_id: String?) -> void
|
|
701
704
|
def behavior: () -> "deny"
|
|
702
705
|
def to_h: () -> Hash[Symbol, untyped]
|
|
703
706
|
end
|
|
@@ -728,8 +731,9 @@ module ClaudeAgent
|
|
|
728
731
|
attr_reader decision_reason: String?
|
|
729
732
|
attr_reader tool_use_id: String?
|
|
730
733
|
attr_reader agent_id: String?
|
|
734
|
+
attr_reader signal: AbortSignal?
|
|
731
735
|
|
|
732
|
-
def initialize: (?permission_suggestions: untyped, ?blocked_path: String?, ?decision_reason: String?, ?tool_use_id: String?, ?agent_id: String?) -> void
|
|
736
|
+
def initialize: (?permission_suggestions: untyped, ?blocked_path: String?, ?decision_reason: String?, ?tool_use_id: String?, ?agent_id: String?, ?signal: AbortSignal?) -> void
|
|
733
737
|
end
|
|
734
738
|
|
|
735
739
|
# Client
|
|
@@ -909,4 +913,39 @@ module ClaudeAgent
|
|
|
909
913
|
def to_config: () -> Hash[Symbol, untyped]
|
|
910
914
|
end
|
|
911
915
|
end
|
|
916
|
+
|
|
917
|
+
# V2 Session API - UNSTABLE
|
|
918
|
+
# @alpha
|
|
919
|
+
|
|
920
|
+
# V2 Session options (subset of full Options)
|
|
921
|
+
class SessionOptions
|
|
922
|
+
attr_reader model: String
|
|
923
|
+
attr_reader path_to_claude_code_executable: String?
|
|
924
|
+
attr_reader env: Hash[String, String]?
|
|
925
|
+
attr_reader allowed_tools: Array[String]?
|
|
926
|
+
attr_reader disallowed_tools: Array[String]?
|
|
927
|
+
attr_reader can_use_tool: (^(String, Hash[String, untyped], untyped) -> permission_result)?
|
|
928
|
+
attr_reader hooks: Hash[String, Array[HookMatcher]]?
|
|
929
|
+
attr_reader permission_mode: String?
|
|
930
|
+
|
|
931
|
+
def initialize: (model: String, ?path_to_claude_code_executable: String?, ?env: Hash[String, String]?, ?allowed_tools: Array[String]?, ?disallowed_tools: Array[String]?, ?can_use_tool: (^(String, Hash[String, untyped], untyped) -> permission_result)?, ?hooks: Hash[String, Array[HookMatcher]]?, ?permission_mode: String?) -> void
|
|
932
|
+
end
|
|
933
|
+
|
|
934
|
+
# V2 Session interface for multi-turn conversations
|
|
935
|
+
class Session
|
|
936
|
+
attr_reader session_id: String?
|
|
937
|
+
attr_reader options: SessionOptions
|
|
938
|
+
|
|
939
|
+
def initialize: (Hash[Symbol, untyped] | SessionOptions options) -> void
|
|
940
|
+
def send: (String | UserMessage message) -> void
|
|
941
|
+
def stream: () -> Enumerator[message, void]
|
|
942
|
+
| () { (message) -> void } -> void
|
|
943
|
+
def close: () -> void
|
|
944
|
+
def closed?: () -> bool
|
|
945
|
+
end
|
|
946
|
+
|
|
947
|
+
# V2 API module-level methods
|
|
948
|
+
def self.unstable_v2_create_session: (Hash[Symbol, untyped] | SessionOptions options) -> Session
|
|
949
|
+
def self.unstable_v2_resume_session: (String session_id, Hash[Symbol, untyped] | SessionOptions options) -> Session
|
|
950
|
+
def self.unstable_v2_prompt: (String message, Hash[Symbol, untyped] | SessionOptions options) -> ResultMessage
|
|
912
951
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: claude_agent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Carr
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- lib/claude_agent/permissions.rb
|
|
64
64
|
- lib/claude_agent/query.rb
|
|
65
65
|
- lib/claude_agent/sandbox_settings.rb
|
|
66
|
+
- lib/claude_agent/session.rb
|
|
66
67
|
- lib/claude_agent/spawn.rb
|
|
67
68
|
- lib/claude_agent/transport/base.rb
|
|
68
69
|
- lib/claude_agent/transport/subprocess.rb
|