vsm 0.0.1 → 0.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/.claude/settings.local.json +17 -0
  3. data/CLAUDE.md +134 -0
  4. data/README.md +531 -17
  5. data/examples/01_echo_tool.rb +70 -0
  6. data/examples/02_openai_streaming.rb +73 -0
  7. data/examples/02b_anthropic_streaming.rb +61 -0
  8. data/examples/02c_gemini_streaming.rb +60 -0
  9. data/examples/03_openai_tools.rb +106 -0
  10. data/examples/03b_anthropic_tools.rb +96 -0
  11. data/examples/03c_gemini_tools.rb +95 -0
  12. data/lib/vsm/async_channel.rb +21 -0
  13. data/lib/vsm/capsule.rb +44 -0
  14. data/lib/vsm/drivers/anthropic/async_driver.rb +210 -0
  15. data/lib/vsm/drivers/family.rb +16 -0
  16. data/lib/vsm/drivers/gemini/async_driver.rb +149 -0
  17. data/lib/vsm/drivers/openai/async_driver.rb +202 -0
  18. data/lib/vsm/dsl.rb +50 -0
  19. data/lib/vsm/executors/fiber_executor.rb +10 -0
  20. data/lib/vsm/executors/thread_executor.rb +19 -0
  21. data/lib/vsm/homeostat.rb +19 -0
  22. data/lib/vsm/lens/event_hub.rb +73 -0
  23. data/lib/vsm/lens/server.rb +188 -0
  24. data/lib/vsm/lens/stats.rb +58 -0
  25. data/lib/vsm/lens/tui.rb +88 -0
  26. data/lib/vsm/lens.rb +79 -0
  27. data/lib/vsm/message.rb +6 -0
  28. data/lib/vsm/observability/ledger.rb +25 -0
  29. data/lib/vsm/port.rb +11 -0
  30. data/lib/vsm/roles/coordination.rb +49 -0
  31. data/lib/vsm/roles/governance.rb +9 -0
  32. data/lib/vsm/roles/identity.rb +11 -0
  33. data/lib/vsm/roles/intelligence.rb +168 -0
  34. data/lib/vsm/roles/operations.rb +33 -0
  35. data/lib/vsm/runtime.rb +18 -0
  36. data/lib/vsm/tool/acts_as_tool.rb +20 -0
  37. data/lib/vsm/tool/capsule.rb +12 -0
  38. data/lib/vsm/tool/descriptor.rb +16 -0
  39. data/lib/vsm/version.rb +1 -1
  40. data/lib/vsm.rb +33 -0
  41. data/llms.txt +322 -0
  42. metadata +67 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed61754f22a8b9a5c56bae55d84fc5e387df438669706f063a94f53ddda4d98c
4
- data.tar.gz: 4ac4a2c1d1e6c8cb7f078687ecfa1b448cdbd97b5813f89f67d87545848bb053
3
+ metadata.gz: 9bdbe6ab3817a25d90829e9880efb85860948748281eedd885004411ff0221b3
4
+ data.tar.gz: 7b47991a4af3167b8c3968e41e062dedad7f6050a74af7ad5f4f48952ccedb72
5
5
  SHA512:
6
- metadata.gz: f882a9322bb12365ee34ea7fd594d05248b2f4dcf2b59eb6e2137c8a9780b236a86b15d3ea1e2f091b46fd4836bdfddbaa79db5f622f32127cef68f473c3abc2
7
- data.tar.gz: 9b040283be438d6243be473ee0b813d5e08607d092971b93069e35123c841fdc2c9c9aa8856fc7f8bbadbe9c4dd4395d587ecf928ff3e6ece73a44d1ee3715a1
6
+ metadata.gz: 1dd4ee44eaef8be76d7a02890312f7b3a4a99216ddcd613655cd8c47f81c9c188c471f164bfc2bd69071d9a5b392d89dc803e7600ae811f49f2db8b7b55bdc3f
7
+ data.tar.gz: 7fe63b320f208604cfe40e0440bec76f9ef8dbceb0a419cb2f7501fce7f4d8097c42ce01d6d9e61345e272a3f6d438e663de94ca8af3eee52f44fc8d401780d4
@@ -0,0 +1,17 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(bundle exec rspec:*)",
5
+ "Bash(cat:*)",
6
+ "Bash(gem list)",
7
+ "Bash(bundle exec rake:*)",
8
+ "Bash(gem install:*)",
9
+ "Bash(ruby test_tool_calls:*)"
10
+ ],
11
+ "deny": [],
12
+ "ask": [],
13
+ "additionalDirectories": [
14
+ "/Users/swerner/Development/gems/airb"
15
+ ]
16
+ }
17
+ }
data/CLAUDE.md ADDED
@@ -0,0 +1,134 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ VSM is a Ruby gem that provides an async, recursive agent framework based on the Viable System Model. It implements five named systems (Operations, Coordination, Intelligence, Governance, Identity) in a capsule-based architecture for building AI agents.
8
+
9
+ ## Development Commands
10
+
11
+ ### Testing
12
+ ```bash
13
+ bundle exec rspec # Run all tests
14
+ bundle exec rspec spec/vsm_spec.rb # Run specific test file
15
+ rake spec # Alternative test runner
16
+ ```
17
+
18
+ ### Code Quality
19
+ ```bash
20
+ bundle exec rubocop # Run linter
21
+ rake rubocop # Alternative linter runner
22
+ rake # Run both tests and linter (default task)
23
+ ```
24
+
25
+ ### Gem Development
26
+ ```bash
27
+ bundle install # Install dependencies
28
+ bundle exec rake build # Build the gem
29
+ bundle exec rake install # Install gem locally
30
+ bundle exec rake release # Release gem (maintainers only)
31
+ ```
32
+
33
+ ### Interactive Development
34
+ ```bash
35
+ bundle exec irb -r vsm # Start IRB with VSM loaded
36
+ ```
37
+
38
+ ## Architecture
39
+
40
+ ### Core Components
41
+
42
+ **Capsule** (`lib/vsm/capsule.rb:4`) - Main building block containing five systems plus AsyncChannel bus. The core dispatch loop runs in `lib/vsm/capsule.rb:18` processing messages through coordination → governance → routing.
43
+
44
+ **Five Systems** (Viable System Model roles):
45
+ - **Operations** (`lib/vsm/roles/operations.rb:7`) - Handles `:tool_call` messages, routes to child capsules/tools
46
+ - **Coordination** (`lib/vsm/roles/coordination.rb:3`) - Message scheduling, turn management, session floor control
47
+ - **Intelligence** (`lib/vsm/roles/intelligence.rb`) - Planning/decision making (typically LLM integration)
48
+ - **Governance** (`lib/vsm/roles/governance.rb`) - Policy enforcement, safety, budgets
49
+ - **Identity** (`lib/vsm/roles/identity.rb`) - Purpose definition, invariants, escalation
50
+
51
+ **AsyncChannel** (`lib/vsm/async_channel.rb:4`) - Non-blocking message bus built on `async` gem with pub/sub support.
52
+
53
+ **DSL Builder** (`lib/vsm/dsl.rb:4`) - Declarative capsule construction with role injection and child management.
54
+
55
+ ### Tool System
56
+
57
+ **ToolCapsule** (`lib/vsm/tool/capsule.rb:3`) - Base class for tools that are capsules with ActsAsTool mixin.
58
+
59
+ **ActsAsTool** (`lib/vsm/tool/acts_as_tool.rb:3`) - Mixin providing tool metadata (name, description, JSON schema) and descriptor generation.
60
+
61
+ **Tool Descriptors** (`lib/vsm/tool/descriptor.rb`) - Provider-agnostic tool definitions with `to_openai_tool`, `to_anthropic_tool`, `to_gemini_tool` methods.
62
+
63
+ ### Execution Models
64
+
65
+ **Executors** (`lib/vsm/executors/`) - Pluggable execution strategies:
66
+ - `FiberExecutor` - Default async/IO-bound execution
67
+ - `ThreadExecutor` - CPU-bound or blocking library execution
68
+
69
+ Tools specify execution mode via `execution_mode` method returning `:fiber` or `:thread`.
70
+
71
+ ### Message Flow
72
+
73
+ Messages follow this structure:
74
+ ```ruby
75
+ VSM::Message.new(
76
+ kind: :user | :assistant | :assistant_delta | :tool_call | :tool_result | :plan | :policy | :audit,
77
+ payload: any_data,
78
+ corr_id: "correlation_id_for_tool_calls",
79
+ meta: { session_id: "uuid", ... }
80
+ )
81
+ ```
82
+
83
+ Core flow: User input → Intelligence (planning) → Operations (tool execution) → Coordination (scheduling) → Assistant output.
84
+
85
+ ### Provider Integration
86
+
87
+ LLM drivers are in `lib/vsm/drivers/` with async implementations for:
88
+ - OpenAI (`drivers/openai/async_driver.rb`)
89
+ - Anthropic (`drivers/anthropic/async_driver.rb`)
90
+ - Gemini (`drivers/gemini/async_driver.rb`)
91
+
92
+ Drivers are provider-agnostic and integrate through Intelligence implementations.
93
+
94
+ ## Key Development Patterns
95
+
96
+ ### Creating Tools
97
+ Inherit from `VSM::ToolCapsule`, define tool metadata with class methods, implement `run(args)`:
98
+
99
+ ```ruby
100
+ class MyTool < VSM::ToolCapsule
101
+ tool_name "my_tool"
102
+ tool_description "Description"
103
+ tool_schema({ type: "object", properties: { ... }, required: [...] })
104
+
105
+ def run(args)
106
+ # Tool implementation
107
+ end
108
+
109
+ def execution_mode = :fiber # or :thread
110
+ end
111
+ ```
112
+
113
+ ### Building Capsules
114
+ Use the DSL in `lib/vsm/dsl.rb:45` to define capsules with five systems:
115
+
116
+ ```ruby
117
+ capsule = VSM::DSL.define(:name) do
118
+ identity klass: VSM::Identity, args: { identity: "name", invariants: [] }
119
+ governance klass: VSM::Governance
120
+ coordination klass: VSM::Coordination
121
+ intelligence klass: MyIntelligence
122
+ operations do
123
+ capsule :tool_name, klass: ToolClass
124
+ end
125
+ end
126
+ ```
127
+
128
+ ### Testing Approach
129
+ - Unit test individual roles and tools directly
130
+ - Test capsule message flow with queues to capture emissions
131
+ - Use RSpec with async-rspec for fiber-based testing
132
+ - Mock external dependencies (LLM APIs) in Intelligence tests
133
+
134
+ The codebase follows Ruby conventions with frozen string literals, clear namespacing, and small focused classes following SOLID principles.