|
| 1 | +# ARCP Ruby SDK Samples |
| 2 | + |
| 3 | +Numbered short samples (`01_*`–`06_*`) live alongside fourteen |
| 4 | +single-purpose sample directories, each named for the protocol |
| 5 | +primitive it demonstrates. |
| 6 | + |
| 7 | +> **Illustrative, not runnable.** Each example imports `arcp` as if |
| 8 | +> it were a published gem. Setup boilerplate (transport URL, |
| 9 | +> identity, auth) is elided as `client = nil # ARCPClient(...)`. LLM |
| 10 | +> and framework calls live in tiny stub modules so the protocol code |
| 11 | +> in `main.rb` is what you read. |
| 12 | +
|
| 13 | +## The fourteen primitives |
| 14 | + |
| 15 | +| Directory | Demonstrates | Spec | |
| 16 | +|---|---|---| |
| 17 | +| [`subscriptions/`](./subscriptions) | Three Observer clients on one session, three filters, three sinks. | §5, §13 | |
| 18 | +| [`leases/`](./leases) | Lease-gated shell agent. Reads coarse, writes scoped. | §15.4–§15.5 | |
| 19 | +| [`lease_revocation/`](./lease_revocation) | Per-table leases with `lease.revoked` / `lease.extended` mid-flight. | §15.5 | |
| 20 | +| [`permission_challenge/`](./permission_challenge) | Two-party permission challenge — generator asks, reviewer holds veto. | §15.4, §6.4 | |
| 21 | +| [`delegation/`](./delegation) | `agent.delegate` fan-out + `JobMux` to demux events by `job_id`. | §14, §6.4 | |
| 22 | +| [`handoff/`](./handoff) | `agent.handoff` with transcript packed as artifact, runtime fingerprint pinned. | §14, §16, §8.3 | |
| 23 | +| [`heartbeats/`](./heartbeats) | Worker federation; heartbeat-loss reroute via `idempotency_key`. | §10.3, §6.4 | |
| 24 | +| [`capability_negotiation/`](./capability_negotiation) | Capability-driven peer routing; standard `cost.usd` rollups. | §7, §17.3.1, §18.3 | |
| 25 | +| [`resumability/`](./resumability) | Real crash and resume via `Process.exit!` + `resume` envelope. | §10, §19, §6.4 | |
| 26 | +| [`reasoning_streams/`](./reasoning_streams) | `kind: thought` stream + a peer runtime that subscribes and delegates critiques back. | §11.4, §13, §14 | |
| 27 | +| [`extensions/`](./extensions) | Custom `arcpx.sdr.*.v1` namespace with correct unknown-message handling. | §21 | |
| 28 | +| [`human_input/`](./human_input) | `human.input.request` fanned across phone/email/Slack; first-wins resolution. | §12 | |
| 29 | +| [`cancellation/`](./cancellation) | Cooperative `cancel` (terminate) vs `interrupt` (pause and ask). | §10.4–§10.5 | |
| 30 | +| [`mcp/`](./mcp) | ARCP runtime fronting an MCP server: `tool.invoke` → MCP `call_tool`. | §20 | |
| 31 | + |
| 32 | +## Conventions |
| 33 | + |
| 34 | +- Ruby 3.4+, `# frozen_string_literal: true` on every file, single |
| 35 | + quotes per repo `.rubocop.yml`. |
| 36 | +- Each example is one `main.rb` (the protocol code) + 0–2 stub |
| 37 | + modules named for what they elide (`agents.rb`, `steps.rb`, |
| 38 | + `cheap.rb`, `synth.rb`, `work.rb`, `channels.rb`, `sql.rb`, |
| 39 | + `upstream.rb`, `sinks/*.rb`). |
| 40 | +- `client = nil # ARCPClient(...)` literally — transport, identity, |
| 41 | + and auth are setup noise, not the point. |
| 42 | +- Envelopes match RFC-0001 v2 exactly. Custom message types follow |
| 43 | + §21.1 `arcpx.<domain>.<name>.v<n>` naming. |
| 44 | +- `Async {}` blocks for concurrency, `case/in` pattern matching for |
| 45 | + envelope dispatch, `Data.define` for value objects. |
| 46 | + |
| 47 | +## What's where in the SDK |
| 48 | + |
| 49 | +- `Arcp::Client::Client` — handshake driver. |
| 50 | +- `Arcp::Envelope.build(type:, payload:, ...)` — envelope minting. |
| 51 | +- `Arcp::Envelope`, `Arcp::ErrorCode`, `Arcp::Error` — wire primitives. |
| 52 | +- `Arcp::Transport::WebSocket` / `Arcp::Transport::Memory` — transports. |
| 53 | +- `Arcp::Store::EventLog` — SQLite schema reused by `subscriptions`. |
| 54 | + |
| 55 | +## Reading order |
| 56 | + |
| 57 | +For a brisk tour: `subscriptions`, `leases`, `delegation`, |
| 58 | +`resumability` (this one actually crashes and recovers), |
| 59 | +`cancellation`, `extensions`, `mcp`. These seven exercise the bulk |
| 60 | +of the protocol. |
0 commit comments