Skip to content

Commit 410de06

Browse files
authored
feat(daemon): built-in capabilities (#52)
1 parent e4e3f2e commit 410de06

52 files changed

Lines changed: 1066 additions & 317 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@sideband/peer": minor
3+
"@sideband/cloud": minor
4+
"sideband": minor
5+
---
6+
7+
Add built-in daemon capabilities: `$sideband/stats` snapshot and live subscription, `$sideband/rpc.list` / `$sideband/rpc.describe` method introspection, `--name` CLI flag, and `capabilities` + `name` fields in `$sideband/info`. Adds `RpcInterface.listMethods()` to the peer SDK. Renames `AcceptedPeer` → `ConnectedPeer` and `CloudPeerServer` → `CloudServer`.

‎docs/adr/013-peer-sdk-design.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
```typescript
2424
/** Client-side SBRP (browser or CLI connecting to a daemon) */
25-
function sbrpClientNegotiator(options: SbrpClientOptions): Negotiator;
25+
function relayClientNegotiator(options: SbrpClientOptions): Negotiator;
2626

2727
/** Daemon-side SBRP (service accepting relay connections) */
28-
function sbrpDaemonNegotiator(options: SbrpDaemonOptions): Negotiator;
28+
function relayDaemonNegotiator(options: SbrpDaemonOptions): Negotiator;
2929
```
3030

3131
**Rationale:** `SbrpNegotiatorOptions` mixes client-only fields (TOFU pinning, `onFirstConnection`, `trustPolicy`, `controlPlaneUrl`) with daemon-only fields (`serverIdentity`, `resumable`, `pauseBufferLimitBytes`). Options A and B allow invalid combinations to compile and fail only at runtime — violating the "hard to misuse" design goal. Separate factories give each role a dedicated, focused type with unambiguous autocomplete and error messages.
@@ -76,7 +76,7 @@ SAFE_CHAR = ALPHA | DIGIT | "-" | "_"
7676

7777
## Consequences
7878

79-
- `@sideband/peer` exposes `sbrpClientNegotiator` and `sbrpDaemonNegotiator`. They live in peer (not secure-relay) because peer already depends on runtime for `Negotiator`/`SbpNegotiator`, while secure-relay stays a pure crypto library with zero runtime dependencies.
79+
- `@sideband/peer` exposes `relayClientNegotiator` and `relayDaemonNegotiator`. They live in peer (not secure-relay) because peer already depends on runtime for `Negotiator`/`SbpNegotiator`, while secure-relay stays a pure crypto library with zero runtime dependencies.
8080
- `@sideband/peer` validates event patterns client-side via `onPattern()` / `validatePattern()`.
8181
- All documentation and examples MUST use `>` (not `**`) for multi-segment wildcard patterns.
8282
- Server-side consumers import from `@sideband/peer/server`; browser consumers import from `@sideband/peer`.

‎docs/adr/014-peer-session-signals.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ Returning an unsubscribe function gives the SDK precise lifecycle control: on ea
7878
- ADR-013: Peer SDK Core Design Decisions
7979
- `packages/runtime/src/session/types.ts` — `NegotiationResult`, `SessionSignal`
8080
- `packages/peer/src/peer.ts` — `handleSessionSignal`, `transition`
81-
- `packages/peer/src/listen.ts` — `AcceptedPeerImpl.handleSessionSignal`
81+
- `packages/peer/src/listen.ts` — `ConnectedPeerImpl.handleSessionSignal`

‎docs/adr/015-p2p-direct-protocol.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bound to the Noise static key (binding details deferred to the SBDP specificatio
4242
- Both parties must provision Noise static keypairs before a direct session.
4343
- TOFU pinning applies to both directions independently.
4444
- MITM detection works in both directions.
45-
- `sbdpNegotiator()` requires a Noise static keypair from both sides (unlike `sbrpClientNegotiator`
45+
- `sbdpNegotiator()` requires a Noise static keypair from both sides (unlike `relayClientNegotiator`
4646
where the client has no persistent identity).
4747

4848
### 3. Transport is pluggable; no single P2P transport is mandated

‎docs/adr/016-relay-server-design.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
## Context
88

99
The hosted Sideband relay is the infrastructure that enables browser ↔ daemon communication
10-
through NAT. It is the bridge between `sbrpClientNegotiator` (browser/client) and
11-
`sbrpDaemonNegotiator` (local daemon). Without a relay endpoint, the E2EE value proposition
10+
through NAT. It is the bridge between `relayClientNegotiator` (browser/client) and
11+
`relayDaemonNegotiator` (local daemon). Without a relay endpoint, the E2EE value proposition
1212
is theoretical.
1313

1414
The relay must:
@@ -67,7 +67,7 @@ from consuming DO resources.
6767

6868
Connection routing uses a fixed endpoint with token-derived routing:
6969

70-
```
70+
```text
7171
wss://{region}.relay.sideband.cloud?token=<jwt>
7272
```
7373

@@ -90,7 +90,7 @@ Security note: query-string tokens MUST be short-lived and redacted from logs/an
9090
### 5. Pause/resume signaling
9191

9292
When a client connection drops, the relay emits `Control(session_ended)` to the daemon; the
93-
daemon's `AcceptedPeer` transitions to `closed` (no pause semantics for client drops — clients
93+
daemon's `ConnectedPeer` transitions to `closed` (no pause semantics for client drops — clients
9494
are ephemeral from the relay's perspective).
9595

9696
When the daemon connection closes unexpectedly, the DO emits `Control(session_paused)` to affected

‎docs/adr/017-cloud-sdk-design.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ RelayDaemonTransport.listen()
9696
│ known SID → route frame to existing RelayVirtualConn
9797
│ SID=0 Control → rate_limited: continue; other: reconnect
9898
↓
99-
sbrpDaemonNegotiator per session → AcceptedPeer → onConnection(peer)
99+
relayDaemonNegotiator per session → ConnectedPeer → onConnection(peer)
100100
```
101101

102102
`peerListen()` is unchanged — it sees a stream of `TransportConnection` objects regardless of
103103
whether they come from a local server or relay mux. Slow consumers are terminated (backpressure).
104104
Consecutive malformed frames trigger reconnect with backoff (circuit breaker against log storms
105105
on protocol version mismatch).
106106

107-
`listen()` returns `CloudPeerServer` (extends `PeerServer`) with three additional members that
107+
`listen()` returns `CloudServer` (extends `PeerServer`) with three additional members that
108108
are only available after the first relay connection resolves:
109109

110110
```typescript
111-
interface CloudPeerServer extends PeerServer {
111+
interface CloudServer extends PeerServer {
112112
readonly daemonId: string; // `did` claim extracted from the presence token
113113
readonly relayUrl: string; // e.g. "wss://relay.sideband.cloud"
114114
createQuickConnect(opts?: { ttlSeconds?: number }): Promise<{
@@ -135,4 +135,4 @@ stale even if the daemon ID was omitted from `ListenOptions`.
135135
- ADR-016: Relay Server Design
136136
- `packages/runtime/src/session/types.ts` — `Negotiator`, `NegotiatorConnectionParams`
137137
- `packages/cloud/src/connect.ts` — `CloudClientNegotiator`
138-
- `packages/cloud/src/listen.ts` — `RelayDaemonTransport`, `RelayVirtualConn`, `runMux`, `CloudPeerServer`
138+
- `packages/cloud/src/listen.ts` — `RelayDaemonTransport`, `RelayVirtualConn`, `runMux`, `CloudServer`
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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()`

‎docs/adr/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This section documents significant architectural decisions for the Sideband proj
2323
| [015](./015-p2p-direct-protocol.md) | P2P Direct Protocol (SBDP) | Accepted |
2424
| [016](./016-relay-server-design.md) | Relay Server Design | Accepted |
2525
| [017](./017-cloud-sdk-design.md) | Cloud SDK Design | Accepted |
26+
| [018](./018-daemon-capabilities.md) | Daemon Built-in Capabilities | Accepted |
2627

2728
## Creating a new ADR
2829

‎docs/architecture/packages.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Package boundaries and dependency direction for the current Sideband workspace.
7878

7979
### `@sideband/cloud`
8080

81-
- Provides: relay.sideband.cloud integration — `connect()` (client) and `listen()` (daemon). `listen()` returns `CloudPeerServer` (extends `PeerServer`) with `daemonId`, `relayUrl`, and `createQuickConnect()`. Also exports `renewPresenceToken` and `extractDaemonIdFromToken`.
81+
- Provides: relay.sideband.cloud integration — `connect()` (client) and `listen()` (daemon). `listen()` returns `CloudServer` (extends `PeerServer`) with `daemonId`, `relayUrl`, and `createQuickConnect()`. Also exports `renewPresenceToken` and `extractDaemonIdFromToken`.
8282
- Does not provide: protocol definitions or cryptographic primitives.
8383
- Runtime dependencies: `@sideband/peer`, `@sideband/secure-relay`, `@sideband/transport-ws`.
8484

‎docs/architecture/project-structure.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Optional root files (not shown): AI helper notes (`CLAUDE.md`), lockfiles (`bun.
6565
• Depends on: none (uses @noble/\* for crypto). Used by: relay implementations, browser/daemon apps.
6666

6767
`@sideband/cloud` — relay.sideband.cloud integration
68-
• `connect()` (client) and `listen()` (daemon). `listen()` returns `CloudPeerServer` with `daemonId`, `relayUrl`, and `createQuickConnect()` for zero-infrastructure Quick Connect URLs.
68+
• `connect()` (client) and `listen()` (daemon). `listen()` returns `CloudServer` with `daemonId`, `relayUrl`, and `createQuickConnect()` for zero-infrastructure Quick Connect URLs.
6969
• Depends on: peer, secure-relay, transport-ws.
7070

7171
`sideband` — Daemon CLI

0 commit comments

Comments
 (0)