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 +4 -4
- data/.claude/rules/conventions.md +66 -16
- data/CHANGELOG.md +2 -0
- data/CLAUDE.md +24 -4
- data/README.md +52 -1529
- data/docs/architecture.md +339 -0
- data/docs/client.md +526 -0
- data/docs/configuration.md +571 -0
- data/docs/conversations.md +461 -0
- data/docs/errors.md +127 -0
- data/docs/events.md +225 -0
- data/docs/getting-started.md +310 -0
- data/docs/hooks.md +380 -0
- data/docs/logging.md +96 -0
- data/docs/mcp.md +308 -0
- data/docs/messages.md +871 -0
- data/docs/permissions.md +611 -0
- data/docs/queries.md +227 -0
- data/docs/sessions.md +335 -0
- data/lib/claude_agent/configuration.rb +129 -0
- data/lib/claude_agent/conversation.rb +28 -3
- data/lib/claude_agent/errors.rb +3 -0
- data/lib/claude_agent/event_handler.rb +14 -0
- data/lib/claude_agent/hook_registry.rb +110 -0
- data/lib/claude_agent/mcp/server.rb +22 -0
- data/lib/claude_agent/mcp/tool.rb +24 -3
- data/lib/claude_agent/message.rb +93 -0
- data/lib/claude_agent/options.rb +10 -0
- data/lib/claude_agent/permission_policy.rb +174 -0
- data/lib/claude_agent/session.rb +100 -11
- data/lib/claude_agent/session_paths.rb +5 -2
- data/lib/claude_agent/version.rb +1 -1
- data/lib/claude_agent.rb +175 -0
- metadata +19 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df8d1374efdac7201f83dd2afc3b0042c44162b5ba58c650305b58c63c60397e
|
|
4
|
+
data.tar.gz: 957bd07189e6d3cf46771367088e9897ce993d2d2944d6108afd1352e2f19f01
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8dc4b9ec494ac9337b7860f4250361366184f6ca983c3b5f9754ac5050966708f0d220a6b5975dff49ab4badd47e6f24b3104467b2a9e511cc3e95114f3cb5fc
|
|
7
|
+
data.tar.gz: fe0357e27da9036fe90a740fecaa64eb5ce95736e7c5566cef0e746080eb014e9a55adb17372b34520d1985fa5d838806cc57e395170c8e2e1766a95563c0336
|
|
@@ -587,36 +587,86 @@ validate! \
|
|
|
587
587
|
|
|
588
588
|
## Advanced Patterns
|
|
589
589
|
|
|
590
|
-
### Global
|
|
590
|
+
### Stripe-Style Global Configuration
|
|
591
591
|
|
|
592
|
-
|
|
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
|
-
|
|
596
|
-
|
|
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
|
-
|
|
599
|
-
|
|
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
|
-
###
|
|
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
|
|
610
|
-
def
|
|
611
|
-
|
|
625
|
+
class PermissionPolicy
|
|
626
|
+
def initialize(&block)
|
|
627
|
+
@rules = []
|
|
628
|
+
yield self if block_given?
|
|
612
629
|
end
|
|
613
630
|
|
|
614
|
-
def
|
|
615
|
-
@
|
|
631
|
+
def allow(*names)
|
|
632
|
+
names.each { |n| @rules << { name: n, action: :allow } }
|
|
633
|
+
self
|
|
616
634
|
end
|
|
617
635
|
|
|
618
|
-
def
|
|
619
|
-
@
|
|
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
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
|
|
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
|
|
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
|
|
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
|
|
63
|
+
- **Protocol flow**: Configuration → Options → Transport → ControlProtocol → MessageParser → typed messages
|
|
44
64
|
|
|
45
65
|
## Testing Notes
|
|
46
66
|
|