claude-agent-sdk 0.37.0 → 1.0.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +6 -2
  4. data/UPGRADING-1.0.md +151 -0
  5. data/docs/errors.md +6 -0
  6. data/docs/sessions.md +20 -1
  7. data/docs/types.md +17 -14
  8. data/lib/claude_agent_sdk/deprecation.rb +1 -40
  9. data/lib/claude_agent_sdk/errors.rb +10 -0
  10. data/lib/claude_agent_sdk/session_resume.rb +11 -5
  11. data/lib/claude_agent_sdk/types/attributes.rb +14 -49
  12. data/lib/claude_agent_sdk/types/base.rb +2 -0
  13. data/lib/claude_agent_sdk/version.rb +1 -1
  14. data/lib/claude_agent_sdk.rb +11 -11
  15. data/sig/claude_agent_sdk/cancellation_signal.rbs +14 -0
  16. data/sig/claude_agent_sdk/configuration.rbs +14 -0
  17. data/sig/claude_agent_sdk/errors.rbs +86 -0
  18. data/sig/claude_agent_sdk/observer.rbs +42 -0
  19. data/sig/claude_agent_sdk/railtie.rbs +10 -0
  20. data/sig/claude_agent_sdk/sdk_mcp_server.rbs +76 -0
  21. data/sig/claude_agent_sdk/session_store.rbs +105 -0
  22. data/sig/claude_agent_sdk/streaming.rbs +15 -0
  23. data/sig/claude_agent_sdk/transport.rbs +98 -0
  24. data/sig/claude_agent_sdk/types/base.rbs +39 -0
  25. data/sig/claude_agent_sdk/types/content_blocks.rbs +79 -0
  26. data/sig/claude_agent_sdk/types/hooks.rbs +528 -0
  27. data/sig/claude_agent_sdk/types/mcp.rbs +216 -0
  28. data/sig/claude_agent_sdk/types/messages.rbs +586 -0
  29. data/sig/claude_agent_sdk/types/option_values.rbs +245 -0
  30. data/sig/claude_agent_sdk/types/options.rbs +288 -0
  31. data/sig/claude_agent_sdk/types/permissions.rbs +108 -0
  32. data/sig/claude_agent_sdk/types/sessions.rbs +66 -0
  33. data/sig/claude_agent_sdk.rbs +231 -0
  34. data/sig/manifest.yaml +5 -0
  35. metadata +22 -1
@@ -0,0 +1,528 @@
1
+ module ClaudeAgentSDK
2
+ # Every hook event name the CLI can send (keys of ClaudeAgentOptions#hooks).
3
+ HOOK_EVENTS: Array[String]
4
+
5
+ # The typed input a hook callback receives (UnknownHookInput for an event
6
+ # this SDK version does not model).
7
+ type hook_input = PreToolUseHookInput
8
+ | PostToolUseHookInput
9
+ | UserPromptSubmitHookInput
10
+ | StopHookInput
11
+ | SubagentStopHookInput
12
+ | PostToolUseFailureHookInput
13
+ | NotificationHookInput
14
+ | SubagentStartHookInput
15
+ | PermissionRequestHookInput
16
+ | PreCompactHookInput
17
+ | SessionStartHookInput
18
+ | SessionEndHookInput
19
+ | SetupHookInput
20
+ | TeammateIdleHookInput
21
+ | TaskCompletedHookInput
22
+ | ConfigChangeHookInput
23
+ | WorktreeCreateHookInput
24
+ | WorktreeRemoveHookInput
25
+ | StopFailureHookInput
26
+ | PostCompactHookInput
27
+ | PermissionDeniedHookInput
28
+ | TaskCreatedHookInput
29
+ | ElicitationHookInput
30
+ | ElicitationResultHookInput
31
+ | InstructionsLoadedHookInput
32
+ | CwdChangedHookInput
33
+ | FileChangedHookInput
34
+ | UnknownHookInput
35
+
36
+ # A *HookSpecificOutput (SyncHookJSONOutput#hook_specific_output).
37
+ type hook_specific_output = SetupHookSpecificOutput
38
+ | PreToolUseHookSpecificOutput
39
+ | PostToolUseHookSpecificOutput
40
+ | PostToolUseFailureHookSpecificOutput
41
+ | UserPromptSubmitHookSpecificOutput
42
+ | NotificationHookSpecificOutput
43
+ | SubagentStartHookSpecificOutput
44
+ | PermissionRequestHookSpecificOutput
45
+ | SessionStartHookSpecificOutput
46
+ | PermissionDeniedHookSpecificOutput
47
+ | CwdChangedHookSpecificOutput
48
+ | FileChangedHookSpecificOutput
49
+
50
+ # What a hook callback returns: a Hash (snake_case or camelCase keys), a
51
+ # typed output, or nil (treated as {}).
52
+ type hook_output = Hash[Symbol | String, untyped] | SyncHookJSONOutput | AsyncHookJSONOutput | nil
53
+
54
+ # A hook callback (HookMatcher#hooks entries). tool_use_id is nil for
55
+ # events without a tool call.
56
+ interface _HookCallback
57
+ def call: (hook_input input, String? tool_use_id, HookContext context) -> hook_output
58
+ end
59
+
60
+ # Routes one hook event to callbacks (ClaudeAgentOptions#hooks values).
61
+ class HookMatcher < Type
62
+ def initialize: (?matcher: String?, ?hooks: Array[_HookCallback]?, ?timeout: Numeric?) -> void
63
+ | (Hash[Symbol | String, untyped]? attributes) -> void
64
+
65
+ # Tool-name pattern (e.g. "Bash", "Write|Edit"); nil matches everything.
66
+ attr_accessor matcher: String?
67
+
68
+ # Never nil after construction ([] by default).
69
+ attr_accessor hooks: Array[_HookCallback]?
70
+
71
+ # Seconds.
72
+ attr_accessor timeout: Numeric?
73
+ end
74
+
75
+ # The context passed to a hook callback.
76
+ class HookContext < Type
77
+ attr_accessor signal: CancellationSignal?
78
+
79
+ attr_accessor request_id: String?
80
+ end
81
+
82
+ # Fields every hook input carries. Hook inputs are parsed from CLI output
83
+ # and stay lenient: a field the CLI did not send reads nil.
84
+ class BaseHookInput < Type
85
+ attr_accessor session_id: String?
86
+
87
+ attr_accessor transcript_path: String?
88
+
89
+ attr_accessor cwd: String?
90
+
91
+ attr_accessor permission_mode: String?
92
+
93
+ # The event name, fixed by the subclass (read-only).
94
+ attr_reader hook_event_name: String?
95
+ end
96
+
97
+ class PreToolUseHookInput < BaseHookInput
98
+ attr_accessor tool_name: String?
99
+
100
+ attr_accessor tool_input: wire_hash?
101
+
102
+ attr_accessor tool_use_id: String?
103
+
104
+ attr_accessor agent_id: String?
105
+
106
+ attr_accessor agent_type: String?
107
+ end
108
+
109
+ class PostToolUseHookInput < BaseHookInput
110
+ attr_accessor tool_name: String?
111
+
112
+ attr_accessor tool_input: wire_hash?
113
+
114
+ attr_accessor tool_response: untyped
115
+
116
+ attr_accessor tool_use_id: String?
117
+
118
+ attr_accessor agent_id: String?
119
+
120
+ attr_accessor agent_type: String?
121
+ end
122
+
123
+ class UserPromptSubmitHookInput < BaseHookInput
124
+ attr_accessor prompt: String?
125
+ end
126
+
127
+ class StopHookInput < BaseHookInput
128
+ attr_accessor stop_hook_active: bool?
129
+
130
+ attr_accessor last_assistant_message: String?
131
+
132
+ attr_accessor background_tasks: Array[wire_hash]?
133
+
134
+ attr_accessor session_crons: Array[wire_hash]?
135
+ end
136
+
137
+ class SubagentStopHookInput < BaseHookInput
138
+ attr_accessor stop_hook_active: bool?
139
+
140
+ attr_accessor agent_id: String?
141
+
142
+ attr_accessor agent_transcript_path: String?
143
+
144
+ attr_accessor agent_type: String?
145
+
146
+ attr_accessor last_assistant_message: String?
147
+
148
+ attr_accessor background_tasks: Array[wire_hash]?
149
+
150
+ attr_accessor session_crons: Array[wire_hash]?
151
+ end
152
+
153
+ class PostToolUseFailureHookInput < BaseHookInput
154
+ attr_accessor tool_name: String?
155
+
156
+ attr_accessor tool_input: wire_hash?
157
+
158
+ attr_accessor tool_use_id: String?
159
+
160
+ attr_accessor error: String?
161
+
162
+ attr_accessor is_interrupt: bool?
163
+
164
+ attr_accessor agent_id: String?
165
+
166
+ attr_accessor agent_type: String?
167
+ end
168
+
169
+ class NotificationHookInput < BaseHookInput
170
+ attr_accessor message: String?
171
+
172
+ attr_accessor title: String?
173
+
174
+ attr_accessor notification_type: String?
175
+ end
176
+
177
+ class SubagentStartHookInput < BaseHookInput
178
+ attr_accessor agent_id: String?
179
+
180
+ attr_accessor agent_type: String?
181
+ end
182
+
183
+ class PermissionRequestHookInput < BaseHookInput
184
+ attr_accessor tool_name: String?
185
+
186
+ attr_accessor tool_input: wire_hash?
187
+
188
+ attr_accessor permission_suggestions: Array[wire_hash]?
189
+
190
+ attr_accessor agent_id: String?
191
+
192
+ attr_accessor agent_type: String?
193
+ end
194
+
195
+ class PreCompactHookInput < BaseHookInput
196
+ attr_accessor trigger: String?
197
+
198
+ attr_accessor custom_instructions: String?
199
+ end
200
+
201
+ class SessionStartHookInput < BaseHookInput
202
+ attr_accessor source: String?
203
+
204
+ attr_accessor agent_type: String?
205
+
206
+ attr_accessor model: String?
207
+ end
208
+
209
+ class SessionEndHookInput < BaseHookInput
210
+ attr_accessor reason: String?
211
+ end
212
+
213
+ class SetupHookInput < BaseHookInput
214
+ attr_accessor trigger: String?
215
+ end
216
+
217
+ class TeammateIdleHookInput < BaseHookInput
218
+ attr_accessor teammate_name: String?
219
+
220
+ attr_accessor team_name: String?
221
+ end
222
+
223
+ class TaskCompletedHookInput < BaseHookInput
224
+ attr_accessor task_id: String?
225
+
226
+ attr_accessor task_subject: String?
227
+
228
+ attr_accessor task_description: String?
229
+
230
+ attr_accessor teammate_name: String?
231
+
232
+ attr_accessor team_name: String?
233
+ end
234
+
235
+ class ConfigChangeHookInput < BaseHookInput
236
+ attr_accessor source: String?
237
+
238
+ attr_accessor file_path: String?
239
+ end
240
+
241
+ class WorktreeCreateHookInput < BaseHookInput
242
+ attr_accessor name: String?
243
+ end
244
+
245
+ class WorktreeRemoveHookInput < BaseHookInput
246
+ attr_accessor worktree_path: String?
247
+ end
248
+
249
+ class StopFailureHookInput < BaseHookInput
250
+ attr_accessor error: String?
251
+
252
+ attr_accessor error_details: String?
253
+
254
+ attr_accessor last_assistant_message: String?
255
+ end
256
+
257
+ class PostCompactHookInput < BaseHookInput
258
+ attr_accessor trigger: String?
259
+
260
+ attr_accessor compact_summary: String?
261
+ end
262
+
263
+ class PermissionDeniedHookInput < BaseHookInput
264
+ attr_accessor tool_name: String?
265
+
266
+ attr_accessor tool_input: wire_hash?
267
+
268
+ attr_accessor tool_use_id: String?
269
+
270
+ attr_accessor reason: String?
271
+
272
+ attr_accessor agent_id: String?
273
+
274
+ attr_accessor agent_type: String?
275
+ end
276
+
277
+ class TaskCreatedHookInput < BaseHookInput
278
+ attr_accessor task_id: String?
279
+
280
+ attr_accessor task_subject: String?
281
+
282
+ attr_accessor task_description: String?
283
+
284
+ attr_accessor teammate_name: String?
285
+
286
+ attr_accessor team_name: String?
287
+ end
288
+
289
+ class ElicitationHookInput < BaseHookInput
290
+ attr_accessor mcp_server_name: String?
291
+
292
+ attr_accessor message: String?
293
+
294
+ attr_accessor mode: String?
295
+
296
+ attr_accessor url: String?
297
+
298
+ attr_accessor elicitation_id: String?
299
+
300
+ attr_accessor requested_schema: wire_hash?
301
+ end
302
+
303
+ class ElicitationResultHookInput < BaseHookInput
304
+ attr_accessor mcp_server_name: String?
305
+
306
+ attr_accessor elicitation_id: String?
307
+
308
+ attr_accessor mode: String?
309
+
310
+ attr_accessor action: String?
311
+
312
+ # The elicitation result as the CLI sent it; its shape depends on the
313
+ # mode (form: a wire_hash of field values, url: a token String).
314
+ attr_accessor content: untyped
315
+ end
316
+
317
+ class InstructionsLoadedHookInput < BaseHookInput
318
+ attr_accessor file_path: String?
319
+
320
+ attr_accessor memory_type: String?
321
+
322
+ attr_accessor load_reason: String?
323
+
324
+ attr_accessor globs: Array[String]?
325
+
326
+ attr_accessor trigger_file_path: String?
327
+ end
328
+
329
+ class CwdChangedHookInput < BaseHookInput
330
+ attr_accessor old_cwd: String?
331
+
332
+ attr_accessor new_cwd: String?
333
+ end
334
+
335
+ class FileChangedHookInput < BaseHookInput
336
+ attr_accessor file_path: String?
337
+
338
+ attr_accessor event: String?
339
+ end
340
+
341
+ class UnknownHookInput < BaseHookInput
342
+ attr_accessor raw_input: Hash[Symbol | String, untyped]?
343
+ end
344
+
345
+ # Hook outputs are built by the caller: keyword constructors (the Hash
346
+ # form is accepted too), an unknown key raises ArgumentError, and
347
+ # hook_event_name is fixed by the class. #to_h is the camelCase wire form.
348
+
349
+ class SetupHookSpecificOutput < Type
350
+ def initialize: (?additional_context: String?) -> void
351
+ | (Hash[Symbol | String, untyped]? attributes) -> void
352
+
353
+ attr_accessor additional_context: String?
354
+
355
+ attr_reader hook_event_name: String
356
+
357
+ def to_h: () -> Hash[Symbol, untyped]
358
+ end
359
+
360
+ class PreToolUseHookSpecificOutput < Type
361
+ def initialize: (?permission_decision: String?, ?permission_decision_reason: String?, ?updated_input: Hash[Symbol | String, untyped]?, ?additional_context: String?) -> void
362
+ | (Hash[Symbol | String, untyped]? attributes) -> void
363
+
364
+ attr_accessor permission_decision: String?
365
+
366
+ attr_accessor permission_decision_reason: String?
367
+
368
+ attr_accessor updated_input: Hash[Symbol | String, untyped]?
369
+
370
+ attr_accessor additional_context: String?
371
+
372
+ attr_reader hook_event_name: String
373
+
374
+ def to_h: () -> Hash[Symbol, untyped]
375
+ end
376
+
377
+ class PostToolUseHookSpecificOutput < Type
378
+ def initialize: (?additional_context: String?, ?updated_mcp_tool_output: untyped, ?updated_tool_output: untyped) -> void
379
+ | (Hash[Symbol | String, untyped]? attributes) -> void
380
+
381
+ attr_accessor additional_context: String?
382
+
383
+ attr_accessor updated_mcp_tool_output: untyped
384
+
385
+ attr_accessor updated_tool_output: untyped
386
+
387
+ attr_reader hook_event_name: String
388
+
389
+ def to_h: () -> Hash[Symbol, untyped]
390
+ end
391
+
392
+ class PostToolUseFailureHookSpecificOutput < Type
393
+ def initialize: (?additional_context: String?) -> void
394
+ | (Hash[Symbol | String, untyped]? attributes) -> void
395
+
396
+ attr_accessor additional_context: String?
397
+
398
+ attr_reader hook_event_name: String
399
+
400
+ def to_h: () -> Hash[Symbol, untyped]
401
+ end
402
+
403
+ class UserPromptSubmitHookSpecificOutput < Type
404
+ def initialize: (?additional_context: String?) -> void
405
+ | (Hash[Symbol | String, untyped]? attributes) -> void
406
+
407
+ attr_accessor additional_context: String?
408
+
409
+ attr_reader hook_event_name: String
410
+
411
+ def to_h: () -> Hash[Symbol, untyped]
412
+ end
413
+
414
+ class NotificationHookSpecificOutput < Type
415
+ def initialize: (?additional_context: String?) -> void
416
+ | (Hash[Symbol | String, untyped]? attributes) -> void
417
+
418
+ attr_accessor additional_context: String?
419
+
420
+ attr_reader hook_event_name: String
421
+
422
+ def to_h: () -> Hash[Symbol, untyped]
423
+ end
424
+
425
+ class SubagentStartHookSpecificOutput < Type
426
+ def initialize: (?additional_context: String?) -> void
427
+ | (Hash[Symbol | String, untyped]? attributes) -> void
428
+
429
+ attr_accessor additional_context: String?
430
+
431
+ attr_reader hook_event_name: String
432
+
433
+ def to_h: () -> Hash[Symbol, untyped]
434
+ end
435
+
436
+ class PermissionRequestHookSpecificOutput < Type
437
+ def initialize: (?decision: Hash[Symbol | String, untyped]?) -> void
438
+ | (Hash[Symbol | String, untyped]? attributes) -> void
439
+
440
+ attr_accessor decision: Hash[Symbol | String, untyped]?
441
+
442
+ attr_reader hook_event_name: String
443
+
444
+ def to_h: () -> Hash[Symbol, untyped]
445
+ end
446
+
447
+ class SessionStartHookSpecificOutput < Type
448
+ def initialize: (?additional_context: String?) -> void
449
+ | (Hash[Symbol | String, untyped]? attributes) -> void
450
+
451
+ attr_accessor additional_context: String?
452
+
453
+ attr_reader hook_event_name: String
454
+
455
+ def to_h: () -> Hash[Symbol, untyped]
456
+ end
457
+
458
+ class PermissionDeniedHookSpecificOutput < Type
459
+ def initialize: (?retry: bool?) -> void
460
+ | (Hash[Symbol | String, untyped]? attributes) -> void
461
+
462
+ attr_accessor retry: bool?
463
+
464
+ attr_reader hook_event_name: String
465
+
466
+ def to_h: () -> Hash[Symbol, untyped]
467
+ end
468
+
469
+ class CwdChangedHookSpecificOutput < Type
470
+ def initialize: (?watch_paths: Array[String]?) -> void
471
+ | (Hash[Symbol | String, untyped]? attributes) -> void
472
+
473
+ attr_accessor watch_paths: Array[String]?
474
+
475
+ attr_reader hook_event_name: String
476
+
477
+ def to_h: () -> Hash[Symbol, untyped]
478
+ end
479
+
480
+ class FileChangedHookSpecificOutput < Type
481
+ def initialize: (?watch_paths: Array[String]?) -> void
482
+ | (Hash[Symbol | String, untyped]? attributes) -> void
483
+
484
+ attr_accessor watch_paths: Array[String]?
485
+
486
+ attr_reader hook_event_name: String
487
+
488
+ def to_h: () -> Hash[Symbol, untyped]
489
+ end
490
+
491
+ # Defers the hook's decision (async: true by default).
492
+ class AsyncHookJSONOutput < Type
493
+ def initialize: (?async: bool?, ?async_timeout: Integer?) -> void
494
+ | (Hash[Symbol | String, untyped]? attributes) -> void
495
+
496
+ attr_accessor async: bool?
497
+
498
+ # Milliseconds.
499
+ attr_accessor async_timeout: Integer?
500
+
501
+ def to_h: () -> Hash[Symbol, untyped]
502
+ end
503
+
504
+ # A synchronous hook result (continue: true, suppress_output: false by
505
+ # default).
506
+ class SyncHookJSONOutput < Type
507
+ def initialize: (?continue: bool?, ?suppress_output: bool?, ?stop_reason: String?, ?decision: String?, ?system_message: String?, ?reason: String?, ?hook_specific_output: (hook_specific_output | Hash[Symbol | String, untyped])?) -> void
508
+ | (Hash[Symbol | String, untyped]? attributes) -> void
509
+
510
+ attr_accessor continue: bool?
511
+
512
+ attr_accessor suppress_output: bool?
513
+
514
+ attr_accessor stop_reason: String?
515
+
516
+ # "block" (or nil).
517
+ attr_accessor decision: String?
518
+
519
+ attr_accessor system_message: String?
520
+
521
+ attr_accessor reason: String?
522
+
523
+ # A typed output, or the equivalent Hash (camelCase wire keys, sent as-is).
524
+ attr_accessor hook_specific_output: (hook_specific_output | Hash[Symbol | String, untyped])?
525
+
526
+ def to_h: () -> Hash[Symbol, untyped]
527
+ end
528
+ end