Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/2026-11-01_design_id805.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,26 @@ repeatable size/CPU measurements in phases 4–5.
`pkgs/id/src/web/world_ws.rs`, and `pkgs/id/web/src/world-surface.ts`.
- `pkgs/id/contract/shell-contract.v1.json`.
- [F12.11 roadmap entry](../.opencode/plans/phase-12-platform-flexibility.md#L50).

---

## 2026-11-21T12:34:42Z Clarification: Q1 and Q2 answered; phase 3 unblocked

The answers were recorded on [issue #805](https://github.com/developing-today/code/issues/805#issuecomment-7062344563):

- **Q1: option B.** F11.12 gates journaled frame kinds. Binary screen encoding
is a versioned v2 representation of the existing ephemeral `View`, on a
separately negotiated route, with no journal entry. V1 JSON stays. The shell
contract wording must say the gate applies to journaled kinds only.
- **Q2: option B.** The future under-10% measurement uses the complete logical
`View` payload passed to `SessionIo`, patch metadata included and outer
transport framing excluded, compared with a full snapshot in the same
protocol version and codec. F11.9 raw sizes are reported separately.

This clears the phase-3 gate; it does not pull compression or the size
measurement into phase 3. The implementation adds a distinct v2 route while
leaving v1 text JSON unchanged. Phases 1 and 2 are already represented in the
current Rust code (revisioned JSON patches and retained resume baselines),
despite the older path references and open questions above. Phase 3 must keep
the event `sequence`, view revisions, full-view fallback, and join
authorization semantics intact.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Negotiated binary ScreenPatch v2 completion

This note records the design for completing the in-progress #12242 transport slice in a returning implementation session. The governing requirements remain [design_id805](../../../doc/2026-11-01_design_id805.md) §§3, 5–6 and issue [#12242](https://github.com/developing-today/code/issues/12242); this note narrows how the existing v2 transport makes binary delivery explicit and recoverable.

## Intent

Use the versioned `/ws/world/2`, `/id-world/2`, and `id-world/2` transports for ephemeral MessagePack ScreenPatch frames while preserving v1 text-JSON behavior and authorization. Binary delivery must be an explicit client opt-in, not an accidental consequence of reaching a v2 route. Preserve sequence, view-revision, event-cursor, and resume-token semantics; compression and bandwidth measurement remain out of scope.

## Decisions

- Add an optional `binary_view_patches` boolean to the join frame. A server sends binary ScreenPatch frames only when this flag and the existing `screen_patches` flag are both true and the selected transport supports binary. Missing or false means text-JSON full views/patches. The versioned route remains a transport-version choice; the join field negotiates this optional representation.
- Keep the join capability as the sole authorization check. Resume tokens remain cursors, not credentials; an absent, stale, foreign, or malformed token results in a full view.
- The browser opts in on the v2 WebSocket route, retains the most recently applied view's resume token, and includes it on reconnect. A binary decode failure requests a fresh viewport/full-view resynchronization.
- Bump the additive shell-contract revision and document the new join field plus the `version` field in the binary envelope. V1 clients remain compatible because the field is optional and omitted by them.
- Keep SSH and Iroh adapters' legacy text framing unless their negotiated adapter implements byte-safe framing; the existing v2 transport registration may advertise support only where the adapter supports it.

## Completion checks

Add Rust coverage for the join gate and codec rejection, plus TypeScript coverage for the shared binary golden vector, resume-token round-trip, and decode-error resynchronization. Run the focused Rust and browser checks and record exact outcomes in the task checkpoint. Do not alter patch/resume-token semantics or add compression.
1 change: 1 addition & 0 deletions pkgs/id/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 32 additions & 2 deletions pkgs/id/contract/shell-contract.v1.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"contract": "id-shell",
"version": 1,
"revision": 11,
"description": "The client-server frame protocol every id shell (terminal, web, native) speaks to a world host. Version 1 is the protocol behind the /id-world/1 ALPN. A shell sends only frames and fields named here; it ignores server frame types and fields it does not know. Additive changes bump `revision`; removing or changing a frame or field needs version 2 and a new ALPN. Event-producing frames must name their stable world-event contract here.",
"revision": 12,
"description": "The client-server frame protocol every id shell (terminal, web, native) speaks to a world host. Version 1 is the protocol behind the /id-world/1 ALPN. A shell sends only frames and fields named here; it ignores server frame types and fields it does not know. Additive changes bump `revision`; removing or changing a frame or field needs version 2 and a new ALPN. Event-producing frames must name their stable world-event contract here. Protocol v2 is a separate transport version for ephemeral binary screen-view patches only; it does not change the journaled frame kinds or v1 JSON behavior.",
"max_frame_bytes": 1048576,
"routing_fields": ["world"],
"transports": {
Expand All @@ -22,6 +22,35 @@
"session": "one SSH session channel running the exec command"
}
},
"protocol_v2": {
"client_frames": "Same text-JSON client frames and authorization rules as v1; binary_view_patches on join explicitly opts into binary ScreenPatch delivery and requires screen_patches.",
"server_view_patch": {
"class": "ephemeral",
"encoding": "versioned-messagepack",
"codec_version": 1,
"fields": ["version", "type", "sequence", "view_revision", "base_view_revision", "resume_token?", "patch"],
"compatibility": "Only selected view patches are binary when the join explicitly opts in with binary_view_patches and screen_patches; full views and all other server frames remain text JSON. The v1 transports and payloads are unchanged. Browser clients fall back to the v1 WebSocket path when the v2 route is unavailable before opening.",
"compression": "not negotiated"
},
"transports": {
"iroh": {
"alpn": "/id-world/2",
"envelope": "u32be-length-prefix",
"session": "one bidirectional QUIC stream"
},
"websocket": {
"path": "/ws/world/2",
"envelope": "text-message-controls-and-full-views;binary-message-view-patches",
"session": "one WebSocket connection"
},
"ssh-exec": {
"command": "id-world/2",
"envelope": "u32be-length-prefix",
"session": "one SSH session channel running the exec command"
}
},
"gate": "F11.12 applies to journaled frame kinds; ephemeral presentation view patches may use this versioned transport."
},
"phases": {
"opening": "The session's first frame. It may carry the `world` routing field; absent means the host's default world.",
"query": "After an opening query frame: further query frames, or a join.",
Expand All @@ -45,6 +74,7 @@
"capability": { "type": "string", "max_bytes": 256 },
"after": "u64?",
"screen_patches": { "type": "bool", "optional": true, "nullable": false },
"binary_view_patches": { "type": "bool", "optional": true, "nullable": false },
"agent_profile": { "type": "bool", "optional": true, "nullable": false },
"resume_token": { "type": "string", "optional": true, "nullable": true, "max_bytes": 64 }
}
Expand Down
6 changes: 5 additions & 1 deletion pkgs/id/crates/id-cli/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,11 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> {
#[cfg(feature = "world")]
let router_builder = match (world_hub.as_ref(), world_protocol) {
(Some(hub), Some(world_protocol)) => router_builder
.accept(id_worlds::world_net::WORLD_ALPN, world_protocol)
.accept(id_worlds::world_net::WORLD_ALPN, world_protocol.clone())
.accept(
id_worlds::world_net::WORLD_ALPN_V2,
world_protocol.with_binary_view_patches(),
)
.accept(
id_worlds::world_replication_net::REPLICATION_ALPN,
id_worlds::world_replication_net::WorldReplicationProtocol::new(
Expand Down
3 changes: 2 additions & 1 deletion pkgs/id/crates/id-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"

[features]
default = ["world", "sandbox"]
world = []
world = ["dep:rmp-serde"]
sandbox = []
web = ["dep:qrcode"]
test-utils = []
Expand Down Expand Up @@ -45,6 +45,7 @@ postcard = { version = "1", features = ["alloc"] }
qrcode = { version = "0.14.1", default-features = false, optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
rmp-serde = { version = "1", optional = true }
tempfile = "3"
thiserror = "2"
tokio = { version = "1", features = ["full"] }
Expand Down
2 changes: 2 additions & 0 deletions pkgs/id/crates/id-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub mod test_forgeries;
pub mod petname;
#[cfg(feature = "world")]
pub mod world_presentation;
#[cfg(feature = "world")]
pub mod screen_codec;

#[cfg(feature = "web")]
pub mod qr;
Expand Down
Loading