claude_agent 0.7.15 → 0.7.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 332a35645bfd711fc84e4fe7b537df19113bc30cf7b94879057c1d784e1bea2d
4
- data.tar.gz: 12eefc64eaed4f54078eb9d27ed8dd891968e11980350a777dcfa4d7281cc7b7
3
+ metadata.gz: df8d1374efdac7201f83dd2afc3b0042c44162b5ba58c650305b58c63c60397e
4
+ data.tar.gz: 957bd07189e6d3cf46771367088e9897ce993d2d2944d6108afd1352e2f19f01
5
5
  SHA512:
6
- metadata.gz: 809c6be65d3327939436ea2e64cd4e531584ffd3b955e504ffdfbb086991588fbec449ab123b4c3daeb1895406bbe963692e811cb51c0fa49aabf3bc7971d217
7
- data.tar.gz: f12b331660e1835e3b1ae0e2f48e0e16c91ce8be459cd72a0dbdd3908846fcc252a78d36febe34caeb0bd24733f31b3ecba2e2287a49801355fed11048fd0fdb
6
+ metadata.gz: 8dc4b9ec494ac9337b7860f4250361366184f6ca983c3b5f9754ac5050966708f0d220a6b5975dff49ab4badd47e6f24b3104467b2a9e511cc3e95114f3cb5fc
7
+ data.tar.gz: fe0357e27da9036fe90a740fecaa64eb5ce95736e7c5566cef0e746080eb014e9a55adb17372b34520d1985fa5d838806cc57e395170c8e2e1766a95563c0336
@@ -587,36 +587,86 @@ validate! \
587
587
 
588
588
  ## Advanced Patterns
589
589
 
590
- ### Global Coordinator (Use Sparingly)
590
+ ### Stripe-Style Global Configuration
591
591
 
592
- For CLI applications that need shared state:
592
+ Module-level config with `Forwardable` delegators for common fields. A `Configuration`
593
+ object holds defaults; `to_options(**overrides)` merges per-request overrides and returns
594
+ the internal `Options` type.
593
595
 
594
596
  ```ruby
595
- # lib/gem_name/cli.rb
596
- COORDINATOR = Coordinator.new
597
+ module GemName
598
+ require "forwardable"
599
+
600
+ @config = Configuration.setup
601
+
602
+ class << self
603
+ extend Forwardable
604
+ attr_reader :config
605
+
606
+ def_delegators :@config, :model, :model=,
607
+ :max_turns, :max_turns=
597
608
 
598
- class Cli::Base
599
- def initialize(*)
600
- super
601
- initialize_coordinator unless COORDINATOR.configured?
609
+ def configure = yield(@config)
610
+ def reset_config! = @config = Configuration.setup
602
611
  end
603
612
  end
613
+
614
+ # Usage:
615
+ GemName.model = "opus"
616
+ GemName.configure { |c| c.max_turns = 10 }
604
617
  ```
605
618
 
606
- ### Factory Methods in Coordinator
619
+ ### DSL Builder Pattern
620
+
621
+ Declarative builders that compile to the format consumed by internal plumbing.
622
+ The builder accumulates rules/matchers, then `to_*` produces the final artifact.
607
623
 
608
624
  ```ruby
609
- class Coordinator
610
- def app(role: nil, host: nil)
611
- Commands::App.new(config, role: role, host: host)
625
+ class PermissionPolicy
626
+ def initialize(&block)
627
+ @rules = []
628
+ yield self if block_given?
612
629
  end
613
630
 
614
- def builder
615
- @builder ||= Commands::Builder.new(config)
631
+ def allow(*names)
632
+ names.each { |n| @rules << { name: n, action: :allow } }
633
+ self
616
634
  end
617
635
 
618
- def configured?
619
- @config.present?
636
+ def to_can_use_tool
637
+ rules = @rules.dup.freeze
638
+ ->(tool_name, input, ctx) { ... }
620
639
  end
621
640
  end
622
641
  ```
642
+
643
+ Key conventions:
644
+ - Constructor takes `&block` and yields `self`
645
+ - Methods return `self` for chaining
646
+ - `to_*` method compiles to the internal format
647
+ - `empty?` predicate for skipping when unconfigured
648
+
649
+ ### Prepending Modules into Data.define Types
650
+
651
+ To add shared behavior (like `deconstruct_keys` overrides) to `Data.define` classes,
652
+ use `prepend` not `include`. Data.define generates methods on the class itself, so
653
+ `include` would be shadowed. When overriding `deconstruct_keys`, filter virtual keys
654
+ out before calling `super` — Data's implementation stops early on unknown member keys.
655
+
656
+ ```ruby
657
+ module Message
658
+ def deconstruct_keys(keys)
659
+ if keys.nil?
660
+ { type: type }.merge(super)
661
+ elsif keys.include?(:type)
662
+ member_keys = keys - [ :type ]
663
+ base = member_keys.empty? ? {} : super(member_keys)
664
+ { type: type }.merge(base)
665
+ else
666
+ super
667
+ end
668
+ end
669
+ end
670
+
671
+ MESSAGE_TYPES.each { |klass| klass.prepend(Message) }
672
+ ```
data/CHANGELOG.md CHANGED
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.7.16] - 2026-03-15
11
+
10
12
  ## [0.7.15] - 2026-03-15
11
13
 
12
14
  ### Added
data/CLAUDE.md CHANGED
@@ -1,6 +1,23 @@
1
1
  # ClaudeAgent Ruby SDK
2
2
 
3
- Ruby SDK for building autonomous AI agents that interact with Claude Code CLI. See [README.md](README.md) for API usage, message types, configuration, and examples.
3
+ Ruby SDK for building autonomous AI agents that interact with Claude Code CLI. See [README.md](README.md) for a quick start, and the [docs/](docs/) folder for full guides:
4
+
5
+ | Guide | What's in it |
6
+ |--------------------------------------------|------------------------------------------------------|
7
+ | [Getting Started](docs/getting-started.md) | Install, first queries, multi-turn basics |
8
+ | [Configuration](docs/configuration.md) | Global config, Options, sandbox, agents |
9
+ | [Conversations](docs/conversations.md) | Multi-turn API, TurnResult, callbacks, tool tracking |
10
+ | [Queries](docs/queries.md) | One-shot: ask, query_turn, query |
11
+ | [Permissions](docs/permissions.md) | PermissionPolicy DSL, can_use_tool, queue |
12
+ | [Hooks](docs/hooks.md) | HookRegistry DSL, hook events, input types |
13
+ | [MCP Tools](docs/mcp.md) | In-process tools, servers, schemas |
14
+ | [Events](docs/events.md) | EventHandler, typed callbacks |
15
+ | [Messages](docs/messages.md) | 22 message types, 8 content blocks, pattern matching |
16
+ | [Sessions](docs/sessions.md) | Session discovery, mutations, forking |
17
+ | [Client](docs/client.md) | Low-level bidirectional API |
18
+ | [Errors](docs/errors.md) | Error hierarchy |
19
+ | [Logging](docs/logging.md) | Debug logging, log levels |
20
+ | [Architecture](docs/architecture.md) | Internal design, data flow |
4
21
 
5
22
  ## Stack
6
23
 
@@ -36,11 +53,14 @@ bin/release VERSION # Release gem (e.g., bin/release 1.2.0)
36
53
 
37
54
  ## Conventions
38
55
 
39
- - **Immutable data types**: All messages and options use `Data.define`
56
+ - **Immutable data types**: All messages and content blocks use `Data.define`, frozen at construction
40
57
  - **Frozen string literals**: Every file starts with `# frozen_string_literal: true`
41
- - **Message polymorphism**: Use `case` statements or `is_a?()` for content block types
58
+ - **Message module**: All message/block types include `ClaudeAgent::Message` (text_content, pattern matching)
59
+ - **Stripe-style config**: `ClaudeAgent.model = "opus"`, `ClaudeAgent.configure { |c| ... }`, `Configuration#to_options`
60
+ - **Convenience entry points**: `ClaudeAgent.ask(prompt)` (one-shot), `ClaudeAgent.chat { |c| ... }` (multi-turn)
61
+ - **DSL builders**: `PermissionPolicy` and `HookRegistry` compile to lambdas/hashes consumed by Options
42
62
  - **Error hierarchy**: All errors inherit from `ClaudeAgent::Error` with context (exit code, stderr, etc.)
43
- - **Protocol flow**: Transport → ControlProtocol → MessageParser → typed message objects
63
+ - **Protocol flow**: Configuration → Options → Transport → ControlProtocol → MessageParser → typed messages
44
64
 
45
65
  ## Testing Notes
46
66