claude-agent-sdk 0.37.0 → 1.1.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -0
  3. data/README.md +6 -2
  4. data/UPGRADING-1.0.md +151 -0
  5. data/docs/client.md +11 -0
  6. data/docs/configuration.md +42 -0
  7. data/docs/errors.md +6 -0
  8. data/docs/sessions.md +20 -1
  9. data/docs/types.md +17 -14
  10. data/lib/claude_agent_sdk/cli_installer.rb +1 -1
  11. data/lib/claude_agent_sdk/deprecation.rb +1 -40
  12. data/lib/claude_agent_sdk/errors.rb +10 -0
  13. data/lib/claude_agent_sdk/query.rb +320 -56
  14. data/lib/claude_agent_sdk/session_resume.rb +11 -5
  15. data/lib/claude_agent_sdk/subprocess_cli_transport.rb +25 -0
  16. data/lib/claude_agent_sdk/types/attributes.rb +14 -49
  17. data/lib/claude_agent_sdk/types/base.rb +2 -0
  18. data/lib/claude_agent_sdk/types/messages.rb +7 -1
  19. data/lib/claude_agent_sdk/types/options.rb +69 -12
  20. data/lib/claude_agent_sdk/version.rb +1 -1
  21. data/lib/claude_agent_sdk.rb +28 -18
  22. data/sig/claude_agent_sdk/cancellation_signal.rbs +14 -0
  23. data/sig/claude_agent_sdk/configuration.rbs +14 -0
  24. data/sig/claude_agent_sdk/errors.rbs +86 -0
  25. data/sig/claude_agent_sdk/observer.rbs +42 -0
  26. data/sig/claude_agent_sdk/railtie.rbs +10 -0
  27. data/sig/claude_agent_sdk/sdk_mcp_server.rbs +76 -0
  28. data/sig/claude_agent_sdk/session_store.rbs +105 -0
  29. data/sig/claude_agent_sdk/streaming.rbs +15 -0
  30. data/sig/claude_agent_sdk/transport.rbs +98 -0
  31. data/sig/claude_agent_sdk/types/base.rbs +39 -0
  32. data/sig/claude_agent_sdk/types/content_blocks.rbs +79 -0
  33. data/sig/claude_agent_sdk/types/hooks.rbs +528 -0
  34. data/sig/claude_agent_sdk/types/mcp.rbs +216 -0
  35. data/sig/claude_agent_sdk/types/messages.rbs +586 -0
  36. data/sig/claude_agent_sdk/types/option_values.rbs +245 -0
  37. data/sig/claude_agent_sdk/types/options.rbs +297 -0
  38. data/sig/claude_agent_sdk/types/permissions.rbs +108 -0
  39. data/sig/claude_agent_sdk/types/sessions.rbs +66 -0
  40. data/sig/claude_agent_sdk.rbs +231 -0
  41. data/sig/manifest.yaml +5 -0
  42. metadata +23 -2
@@ -0,0 +1,586 @@
1
+ module ClaudeAgentSDK
2
+ # Possible AssistantMessage#error values (documentation, not validation).
3
+ ASSISTANT_MESSAGE_ERRORS: Array[String]
4
+
5
+ # task_notification statuses.
6
+ TASK_NOTIFICATION_STATUSES: Array[String]
7
+
8
+ # task_updated patch statuses.
9
+ TASK_UPDATED_STATUSES: Array[String]
10
+
11
+ # Statuses meaning a task has finished (both vocabularies).
12
+ TERMINAL_TASK_STATUSES: Array[String]
13
+
14
+ RATE_LIMIT_STATUSES: Array[String]
15
+
16
+ RATE_LIMIT_TYPES: Array[String]
17
+
18
+ # Message types are parsed from CLI output and stay lenient, so every
19
+ # attribute reads nil when the CLI did not send it (and on a hand-built
20
+ # instance). Hash attributes are passed through from the wire (wire_hash);
21
+ # see docs/types.md#hash-keys.
22
+
23
+ class UserMessage < Type
24
+ # A String prompt, or typed content blocks.
25
+ attr_accessor content: (String | Array[content_block])?
26
+
27
+ attr_accessor uuid: String?
28
+
29
+ attr_accessor parent_tool_use_id: String?
30
+
31
+ # Tool result data when the message is a tool response, as the CLI sent
32
+ # it (usually a wire_hash; some tools report a String or an Array).
33
+ attr_accessor tool_use_result: untyped
34
+
35
+ # Provenance of the message: `origin[:kind]` is always a String; nil when
36
+ # the CLI did not attribute it.
37
+ attr_accessor origin: wire_hash?
38
+
39
+ # Concatenated text ("" when there is none).
40
+ def text: () -> String
41
+
42
+ alias to_s text
43
+ end
44
+
45
+ class AssistantMessage < Type
46
+ attr_accessor content: Array[content_block]?
47
+
48
+ attr_accessor model: String?
49
+
50
+ attr_accessor parent_tool_use_id: String?
51
+
52
+ # One of ASSISTANT_MESSAGE_ERRORS (open set).
53
+ attr_accessor error: String?
54
+
55
+ attr_accessor usage: wire_hash?
56
+
57
+ attr_accessor message_id: String?
58
+
59
+ attr_accessor stop_reason: String?
60
+
61
+ attr_accessor session_id: String?
62
+
63
+ attr_accessor uuid: String?
64
+
65
+ # Concatenated text of the TextBlocks ("" when there is none).
66
+ def text: () -> String
67
+
68
+ alias to_s text
69
+ end
70
+
71
+ # A system message. Recognized subtypes are the typed subclasses below; any
72
+ # other subtype arrives as a bare SystemMessage whose #data holds the frame.
73
+ class SystemMessage < Type
74
+ attr_accessor subtype: String?
75
+
76
+ # The raw frame (defaults to the constructor's attributes Hash).
77
+ attr_accessor data: Hash[Symbol | String, untyped]?
78
+
79
+ def to_s: () -> String
80
+ end
81
+
82
+ # Emitted at session start and after /clear.
83
+ class InitMessage < SystemMessage
84
+ attr_accessor uuid: String?
85
+
86
+ attr_accessor session_id: String?
87
+
88
+ # Names of the available subagents.
89
+ attr_accessor agents: Array[String]?
90
+
91
+ attr_accessor api_key_source: String?
92
+
93
+ attr_accessor betas: Array[String]?
94
+
95
+ attr_accessor claude_code_version: String?
96
+
97
+ attr_accessor cwd: String?
98
+
99
+ attr_accessor tools: Array[String]?
100
+
101
+ attr_accessor mcp_servers: Array[wire_hash]?
102
+
103
+ attr_accessor model: String?
104
+
105
+ attr_accessor permission_mode: String?
106
+
107
+ attr_accessor slash_commands: Array[String]?
108
+
109
+ attr_accessor output_style: String?
110
+
111
+ attr_accessor skills: Array[String]?
112
+
113
+ # { name:, path: } wire_hashes.
114
+ attr_accessor plugins: Array[wire_hash]?
115
+
116
+ # "off", "cooldown" or "on".
117
+ attr_accessor fast_mode_state: String?
118
+ end
119
+
120
+ # Emitted after context compaction completes.
121
+ class CompactBoundaryMessage < SystemMessage
122
+ attr_accessor uuid: String?
123
+
124
+ attr_accessor session_id: String?
125
+
126
+ attr_reader compact_metadata: CompactMetadata?
127
+
128
+ # A Hash is converted to CompactMetadata.
129
+ def compact_metadata=: (CompactMetadata | Hash[Symbol | String, untyped] | nil value) -> (CompactMetadata | Hash[Symbol | String, untyped] | nil)
130
+ end
131
+
132
+ class CompactMetadata < Type
133
+ attr_accessor pre_tokens: Integer?
134
+
135
+ attr_accessor post_tokens: Integer?
136
+
137
+ attr_accessor trigger: String?
138
+
139
+ attr_accessor custom_instructions: String?
140
+
141
+ attr_accessor preserved_segment: wire_hash?
142
+ end
143
+
144
+ class StatusMessage < SystemMessage
145
+ attr_accessor uuid: String?
146
+
147
+ attr_accessor session_id: String?
148
+
149
+ attr_accessor status: String?
150
+
151
+ attr_accessor permission_mode: String?
152
+ end
153
+
154
+ class APIRetryMessage < SystemMessage
155
+ attr_accessor uuid: String?
156
+
157
+ attr_accessor session_id: String?
158
+
159
+ attr_accessor attempt: Integer?
160
+
161
+ attr_accessor max_retries: Integer?
162
+
163
+ attr_accessor retry_delay_ms: Numeric?
164
+
165
+ attr_accessor error_status: Integer?
166
+
167
+ # The retry cause, as the CLI reports it (open set).
168
+ attr_accessor error: String?
169
+ end
170
+
171
+ class LocalCommandOutputMessage < SystemMessage
172
+ attr_accessor uuid: String?
173
+
174
+ attr_accessor session_id: String?
175
+
176
+ attr_accessor content: String?
177
+ end
178
+
179
+ # Emitted when a session_store mirror batch was dropped.
180
+ class MirrorErrorMessage < SystemMessage
181
+ attr_accessor uuid: String?
182
+
183
+ attr_accessor session_id: String?
184
+
185
+ attr_accessor error: String?
186
+
187
+ # The SessionStore key of the dropped batch.
188
+ attr_accessor key: session_key?
189
+ end
190
+
191
+ class HookStartedMessage < SystemMessage
192
+ attr_accessor uuid: String?
193
+
194
+ attr_accessor session_id: String?
195
+
196
+ attr_accessor hook_id: String?
197
+
198
+ attr_accessor hook_name: String?
199
+
200
+ attr_accessor hook_event: String?
201
+ end
202
+
203
+ class HookProgressMessage < SystemMessage
204
+ attr_accessor uuid: String?
205
+
206
+ attr_accessor session_id: String?
207
+
208
+ attr_accessor hook_id: String?
209
+
210
+ attr_accessor hook_name: String?
211
+
212
+ attr_accessor hook_event: String?
213
+
214
+ attr_accessor stdout: String?
215
+
216
+ attr_accessor stderr: String?
217
+
218
+ attr_accessor output: String?
219
+ end
220
+
221
+ class HookResponseMessage < SystemMessage
222
+ attr_accessor uuid: String?
223
+
224
+ attr_accessor session_id: String?
225
+
226
+ attr_accessor hook_id: String?
227
+
228
+ attr_accessor hook_name: String?
229
+
230
+ attr_accessor hook_event: String?
231
+
232
+ attr_accessor output: String?
233
+
234
+ attr_accessor stdout: String?
235
+
236
+ attr_accessor stderr: String?
237
+
238
+ attr_accessor exit_code: Integer?
239
+
240
+ # "success", "error" or "cancelled".
241
+ attr_accessor outcome: String?
242
+ end
243
+
244
+ class SessionStateChangedMessage < SystemMessage
245
+ attr_accessor uuid: String?
246
+
247
+ attr_accessor session_id: String?
248
+
249
+ # "idle", "running" or "requires_action".
250
+ attr_accessor state: String?
251
+ end
252
+
253
+ class FilesPersistedMessage < SystemMessage
254
+ attr_accessor uuid: String?
255
+
256
+ attr_accessor session_id: String?
257
+
258
+ attr_accessor files: Array[wire_hash]?
259
+
260
+ attr_accessor failed: Array[wire_hash]?
261
+
262
+ attr_accessor processed_at: String?
263
+ end
264
+
265
+ class ElicitationCompleteMessage < SystemMessage
266
+ attr_accessor uuid: String?
267
+
268
+ attr_accessor session_id: String?
269
+
270
+ attr_accessor mcp_server_name: String?
271
+
272
+ attr_accessor elicitation_id: String?
273
+ end
274
+
275
+ # Typed task usage (build one with TaskUsage.from_hash(message.usage)).
276
+ # Each field defaults to 0.
277
+ class TaskUsage < Type
278
+ attr_accessor total_tokens: Integer?
279
+
280
+ attr_accessor tool_uses: Integer?
281
+
282
+ attr_accessor duration_ms: Integer?
283
+ end
284
+
285
+ class TaskStartedMessage < SystemMessage
286
+ attr_accessor task_id: String?
287
+
288
+ attr_accessor description: String?
289
+
290
+ attr_accessor uuid: String?
291
+
292
+ attr_accessor session_id: String?
293
+
294
+ attr_accessor tool_use_id: String?
295
+
296
+ attr_accessor task_type: String?
297
+
298
+ attr_accessor workflow_name: String?
299
+
300
+ attr_accessor prompt: String?
301
+
302
+ attr_accessor subagent_type: String?
303
+
304
+ # true: background; false: foreground (the spawning call blocks); nil:
305
+ # not reported.
306
+ attr_accessor is_backgrounded: bool?
307
+
308
+ attr_accessor spawn_depth: Integer?
309
+
310
+ attr_accessor skip_transcript: bool?
311
+
312
+ attr_accessor ambient: bool?
313
+ end
314
+
315
+ class TaskProgressMessage < SystemMessage
316
+ attr_accessor task_id: String?
317
+
318
+ attr_accessor description: String?
319
+
320
+ # Raw usage (wire_hash); TaskUsage.from_hash gives a typed view.
321
+ attr_accessor usage: wire_hash?
322
+
323
+ attr_accessor uuid: String?
324
+
325
+ attr_accessor session_id: String?
326
+
327
+ attr_accessor tool_use_id: String?
328
+
329
+ attr_accessor last_tool_name: String?
330
+
331
+ attr_accessor summary: String?
332
+
333
+ attr_accessor subagent_type: String?
334
+ end
335
+
336
+ class TaskNotificationMessage < SystemMessage
337
+ attr_accessor task_id: String?
338
+
339
+ # One of TASK_NOTIFICATION_STATUSES.
340
+ attr_accessor status: String?
341
+
342
+ attr_accessor output_file: String?
343
+
344
+ attr_accessor summary: String?
345
+
346
+ attr_accessor uuid: String?
347
+
348
+ attr_accessor session_id: String?
349
+
350
+ attr_accessor tool_use_id: String?
351
+
352
+ # Raw usage (wire_hash); TaskUsage.from_hash gives a typed view.
353
+ attr_accessor usage: wire_hash?
354
+
355
+ attr_accessor reason: String?
356
+
357
+ attr_accessor resource_links: Array[wire_hash]?
358
+
359
+ attr_accessor skip_transcript: bool?
360
+
361
+ attr_accessor ambient: bool?
362
+ end
363
+
364
+ # A background task's lifecycle patch; each derived reader is nil when the
365
+ # patch does not mention its field.
366
+ class TaskUpdatedMessage < SystemMessage
367
+ # Never nil after construction ("" when absent).
368
+ attr_accessor task_id: String?
369
+
370
+ # The patch as received ({} when absent or not a Hash).
371
+ attr_reader patch: Hash[Symbol | String, untyped]
372
+
373
+ # Any value is accepted (a lifecycle event must never raise); the
374
+ # constructor replaces a non-Hash with {}.
375
+ def patch=: (untyped value) -> untyped
376
+
377
+ # patch[:status]: one of TASK_UPDATED_STATUSES.
378
+ attr_accessor status: String?
379
+
380
+ attr_accessor uuid: String?
381
+
382
+ attr_accessor session_id: String?
383
+
384
+ attr_accessor description: String?
385
+
386
+ attr_accessor error: String?
387
+
388
+ # Epoch milliseconds.
389
+ attr_accessor end_time: Integer?
390
+
391
+ attr_accessor total_paused_ms: Integer?
392
+
393
+ attr_accessor is_backgrounded: bool?
394
+ end
395
+
396
+ # The full set of live background tasks (REPLACE semantics).
397
+ class BackgroundTasksChangedMessage < SystemMessage
398
+ # { task_id:, task_type:, description:, ambient:? } wire_hashes.
399
+ attr_accessor tasks: Array[wire_hash]?
400
+
401
+ attr_accessor uuid: String?
402
+
403
+ attr_accessor session_id: String?
404
+ end
405
+
406
+ # A tool call auto-denied without an interactive prompt (advisory).
407
+ class PermissionDeniedMessage < SystemMessage
408
+ attr_accessor uuid: String?
409
+
410
+ attr_accessor session_id: String?
411
+
412
+ attr_accessor tool_name: String?
413
+
414
+ attr_accessor tool_use_id: String?
415
+
416
+ attr_accessor agent_id: String?
417
+
418
+ attr_accessor decision_reason_type: String?
419
+
420
+ attr_accessor decision_reason: String?
421
+
422
+ attr_accessor message: String?
423
+ end
424
+
425
+ # The final message of a turn, with cost and usage.
426
+ class ResultMessage < Type
427
+ attr_accessor subtype: String?
428
+
429
+ attr_accessor duration_ms: Integer?
430
+
431
+ attr_accessor duration_api_ms: Integer?
432
+
433
+ attr_accessor is_error: bool?
434
+
435
+ attr_accessor num_turns: Integer?
436
+
437
+ attr_accessor session_id: String?
438
+
439
+ attr_accessor stop_reason: String?
440
+
441
+ attr_accessor total_cost_usd: Numeric?
442
+
443
+ attr_accessor usage: wire_hash?
444
+
445
+ # The final text result.
446
+ attr_accessor result: String?
447
+
448
+ # The structured output (with ClaudeAgentOptions#output_format): any JSON
449
+ # value, Symbol-keyed.
450
+ attr_accessor structured_output: untyped
451
+
452
+ # { model_name(Symbol) => usage wire_hash (camelCase keys) }.
453
+ attr_accessor model_usage: Hash[Symbol, wire_hash]?
454
+
455
+ # { tool_name:, tool_use_id:, tool_input: } wire_hashes.
456
+ attr_accessor permission_denials: Array[wire_hash]?
457
+
458
+ attr_accessor errors: Array[String]?
459
+
460
+ attr_accessor uuid: String?
461
+
462
+ attr_accessor fast_mode_state: String?
463
+
464
+ attr_accessor api_error_status: Integer?
465
+
466
+ attr_accessor terminal_reason: String?
467
+
468
+ attr_reader deferred_tool_use: DeferredToolUse?
469
+
470
+ # A Hash is converted to DeferredToolUse.
471
+ def deferred_tool_use=: (DeferredToolUse | Hash[Symbol | String, untyped] | nil value) -> (DeferredToolUse | Hash[Symbol | String, untyped] | nil)
472
+
473
+ # Provenance of the triggering user message (see UserMessage#origin).
474
+ attr_accessor origin: wire_hash?
475
+
476
+ # One line, e.g. "[result: success, 3 turns, 4.2s, $0.0120]".
477
+ def to_s: () -> String
478
+ end
479
+
480
+ # A partial-message stream event (ClaudeAgentOptions#include_partial_messages).
481
+ class StreamEvent < Type
482
+ attr_accessor uuid: String?
483
+
484
+ attr_accessor session_id: String?
485
+
486
+ # The raw API stream event.
487
+ attr_accessor event: wire_hash?
488
+
489
+ attr_accessor parent_tool_use_id: String?
490
+ end
491
+
492
+ class ToolProgressMessage < Type
493
+ attr_accessor uuid: String?
494
+
495
+ attr_accessor session_id: String?
496
+
497
+ attr_accessor tool_use_id: String?
498
+
499
+ attr_accessor tool_name: String?
500
+
501
+ attr_accessor parent_tool_use_id: String?
502
+
503
+ attr_accessor elapsed_time_seconds: Numeric?
504
+
505
+ attr_accessor task_id: String?
506
+ end
507
+
508
+ class AuthStatusMessage < Type
509
+ attr_accessor uuid: String?
510
+
511
+ attr_accessor session_id: String?
512
+
513
+ attr_accessor is_authenticating: bool?
514
+
515
+ attr_accessor output: (String | Array[String])?
516
+
517
+ attr_accessor error: String?
518
+ end
519
+
520
+ class ToolUseSummaryMessage < Type
521
+ attr_accessor uuid: String?
522
+
523
+ attr_accessor session_id: String?
524
+
525
+ attr_accessor summary: String?
526
+
527
+ attr_accessor preceding_tool_use_ids: Array[String]?
528
+ end
529
+
530
+ class PromptSuggestionMessage < Type
531
+ attr_accessor uuid: String?
532
+
533
+ attr_accessor session_id: String?
534
+
535
+ attr_accessor suggestion: String?
536
+ end
537
+
538
+ class RateLimitInfo < Type
539
+ # One of RATE_LIMIT_STATUSES.
540
+ attr_accessor status: String?
541
+
542
+ attr_accessor resets_at: Integer?
543
+
544
+ # One of RATE_LIMIT_TYPES.
545
+ attr_accessor rate_limit_type: String?
546
+
547
+ attr_accessor utilization: Numeric?
548
+
549
+ attr_accessor overage_status: String?
550
+
551
+ attr_accessor overage_resets_at: Integer?
552
+
553
+ attr_accessor overage_disabled_reason: String?
554
+
555
+ # The raw rate_limit_info payload ({} by default).
556
+ attr_accessor raw: Hash[Symbol | String, untyped]?
557
+ end
558
+
559
+ class RateLimitEvent < Type
560
+ attr_accessor uuid: String?
561
+
562
+ attr_accessor session_id: String?
563
+
564
+ attr_accessor raw_data: wire_hash?
565
+
566
+ # Never nil after construction.
567
+ attr_reader rate_limit_info: RateLimitInfo?
568
+
569
+ # A Hash is converted to RateLimitInfo (keeping it as #raw).
570
+ def rate_limit_info=: (RateLimitInfo | Hash[Symbol | String, untyped] | nil value) -> (RateLimitInfo | Hash[Symbol | String, untyped] | nil)
571
+
572
+ # The full raw event payload ({} when absent).
573
+ def data: () -> wire_hash
574
+ end
575
+
576
+ # Emitted when the conversation is replaced mid-connection (e.g. /clear).
577
+ class ConversationResetMessage < Type
578
+ # Id of the fresh conversation — NOT the session_id of later messages.
579
+ attr_accessor new_conversation_id: String?
580
+
581
+ attr_accessor uuid: String?
582
+
583
+ # The session that was reset.
584
+ attr_accessor session_id: String?
585
+ end
586
+ end