|
| 1 | +# ADR-018: Daemon Built-in Capabilities and `$sideband/*` Namespace |
| 2 | + |
| 3 | +- **Date**: 2026-03-07 |
| 4 | +- **Status**: Accepted |
| 5 | +- **Affects**: SDK, CLI |
| 6 | + |
| 7 | +## Context |
| 8 | + |
| 9 | +The connect page needs something meaningful to render when a peer connects. Before this PR the daemon had only two methods (`$sideband/echo`, `$sideband/info`) with no introspection surface and no way for a UI to discover what a daemon can do. Three design questions arose: |
| 10 | + |
| 11 | +1. **How should a UI discover which RPC methods exist?** — enumerating all handlers vs. a dedicated introspection protocol. |
| 12 | +2. **How should user-facing features (stats, future file browser) be advertised?** — a free-form capability bag vs. a fixed schema. |
| 13 | +3. **Where does method introspection belong in the SDK?** — a separate introspection API vs. a method on `RpcInterface`. |
| 14 | + |
| 15 | +## Decision |
| 16 | + |
| 17 | +### 1. `$sideband/*` — reserved namespace for platform-provided handlers |
| 18 | + |
| 19 | +All handlers registered by the Sideband platform (CLI built-ins, SDK infrastructure) use the `$sideband/` prefix. User-registered methods MUST NOT use this prefix. |
| 20 | + |
| 21 | +This makes the platform surface unambiguous and lets UIs apply consistent treatment (e.g., grouping, filtering) without heuristics. |
| 22 | + |
| 23 | +### 2. Two-tier introspection: infrastructure vs. capabilities |
| 24 | + |
| 25 | +**Infrastructure handlers** (`$sideband/rpc.list`, `$sideband/rpc.describe`) are always available on every daemon, CLI or programmatic. They are universal and are NOT listed in `capabilities` — their presence is implicit. |
| 26 | + |
| 27 | +**Capabilities** (`stats`, future `fs`) represent user-facing functional areas that may or may not be present. They are advertised explicitly in `$sideband/info`: |
| 28 | + |
| 29 | +```typescript |
| 30 | +// $sideband/info response |
| 31 | +{ |
| 32 | + daemonId: string; |
| 33 | + name: string; |
| 34 | + version: string; |
| 35 | + capabilities: Record<string, object>; // { stats: {}, fs: { root, write } … } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +The key design invariant: **`rpc.list` is the truth; `rpc.describe` is optional display metadata; `capabilities` is the user-feature contract.** |
| 40 | + |
| 41 | +Rationale for the separation: |
| 42 | + |
| 43 | +- `rpc.list` returns all registered methods — including user-defined ones. The UI uses it for the full method set. |
| 44 | +- `capabilities` is a curated, stable API for feature detection. A UI checking `capabilities.stats` is more robust than checking whether `$sideband/stats` appears in `rpc.list`. |
| 45 | +- `rpc.describe` is sparse metadata for human display. It is intentionally not filtered against `rpc.list` — undescribed methods appear in `rpc.list` but not in `rpc.describe`, which is correct and expected. |
| 46 | + |
| 47 | +### 3. `listMethods()` on `RpcInterface` |
| 48 | + |
| 49 | +Method introspection is placed on `RpcInterface` rather than a separate API: |
| 50 | + |
| 51 | +```typescript |
| 52 | +interface RpcInterface { |
| 53 | + listMethods(): string[]; // Returns registered handler names, sorted lexicographically. |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +**Rationale:** `$sideband/rpc.list` must work for every daemon — CLI and programmatic. Placing `listMethods()` on `RpcInterface` means any daemon, regardless of how it was created, exposes the same introspection surface. A separate top-level introspection API would require daemon authors to opt in explicitly; an `RpcInterface` method is always there. |
| 58 | + |
| 59 | +### 4. Stats subscriptions are session-scoped |
| 60 | + |
| 61 | +`$sideband/stats.start` subscriptions are not resumed across reconnects. The client must call `stats.start` again after a new session is established. Rationale: resuming a subscription requires the daemon to track per-client state across sessions, which adds complexity and creates implicit cleanup obligations. Explicit restart is simpler, predictable, and keeps the daemon stateless between sessions. |
| 62 | + |
| 63 | +## Invariants |
| 64 | + |
| 65 | +- `$sideband/*` prefix is reserved for platform use. User handlers MUST NOT use it. |
| 66 | +- `rpc.list` and `rpc.describe` MUST NOT appear in `capabilities`. |
| 67 | +- `listMethods()` returns a sorted array — clients may rely on lexicographic order for stable display. |
| 68 | +- Stats subscriptions are terminal at session end — not resumed on reconnect. |
| 69 | + |
| 70 | +## Consequences |
| 71 | + |
| 72 | +- UI can use `capabilities` for feature detection and `rpc.list` + `rpc.describe` for the RPC explorer. |
| 73 | +- New CLI capabilities (e.g., `fs`) follow the same pattern: register handlers, return `{ fs: <descriptor> }` from the handler registrar, merge into `$sideband/info`. |
| 74 | +- Programmatic daemons that want `rpc.list` to work correctly call `registerRpcMeta()` themselves; it is opt-in, not automatic. |
| 75 | + |
| 76 | +## References |
| 77 | + |
| 78 | +- ADR-013: Peer SDK Core Design Decisions |
| 79 | +- `packages/cli/src/handlers/rpc-meta.ts` — `registerRpcMeta()` |
| 80 | +- `packages/cli/src/handlers/stats.ts` — `registerStatsHandlers()` |
| 81 | +- `packages/peer/src/types.ts` — `RpcInterface.listMethods()` |
0 commit comments