From a2752f12ea6a6ed473ac0a9768ab6e4cfb82cdf1 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Mon, 16 Nov 2026 12:49:35 -0600 Subject: [PATCH] =?UTF-8?q?feat(id-worlds):=20F13.7=20step=202=20=E2=80=94?= =?UTF-8?q?=20provider=20offer/request/reply=20shell=20frames=20(#5532)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/id/contract/shell-contract.v1.json | 23 ++++++- .../id-worlds/src/shell_contract/tests.rs | 60 +++++++++++++++++++ .../crates/id-worlds/src/world_session/mod.rs | 22 ++++++- .../id-worlds/src/world_session/types.rs | 45 ++++++++++++++ 4 files changed, 145 insertions(+), 5 deletions(-) diff --git a/pkgs/id/contract/shell-contract.v1.json b/pkgs/id/contract/shell-contract.v1.json index b059dd79c7..708b386bf4 100644 --- a/pkgs/id/contract/shell-contract.v1.json +++ b/pkgs/id/contract/shell-contract.v1.json @@ -1,7 +1,7 @@ { "contract": "id-shell", "version": 1, - "revision": 8, + "revision": 9, "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.", "max_frame_bytes": 1048576, "routing_fields": ["world"], @@ -312,6 +312,16 @@ "scopes": "string[]", "expires_at": "u64?" } + }, + "provider_offer": { + "class": "ephemeral", + "phases": ["joined"], + "fields": { "providers": "string[]" } + }, + "provider_reply": { + "class": "ephemeral", + "phases": ["joined"], + "fields": { "nonce": "hex", "ok": "bool", "result_hex": "hex?", "error": "string?" } } }, "server_frames": { @@ -463,6 +473,15 @@ "error": { "class": "reply", "fields": { "message": "string", "code": "string?" } + }, + "provider_request": { + "class": "ephemeral", + "fields": { + "nonce": "hex", + "provider": { "type": "string", "max_bytes": 128 }, + "args": "object", + "deadline_ms": "u64" + } } }, "projection": { @@ -476,6 +495,6 @@ "presentation_tiers": "In-band terminal tier detection and negotiation (F13.4). Needs a new frame kind, so it waits for F11.12.", "focus": "A focus frame for typed input (F13.4/F13.5). Not in version 1.", "kitty_keyboard": "Kitty keyboard protocol key events (F13.5).", - "client_providers": "Client-side capability requests and replies (F13.7). Gated on F12.4 and F12.6." + "client_providers": "Client-side capability requests and replies (F13.7). The offer/request/reply frames landed in revision 9 (F13.7 step 2); the broker that sends requests is F13.7 step 3." } } diff --git a/pkgs/id/crates/id-worlds/src/shell_contract/tests.rs b/pkgs/id/crates/id-worlds/src/shell_contract/tests.rs index db44683e1f..2371e985ad 100644 --- a/pkgs/id/crates/id-worlds/src/shell_contract/tests.rs +++ b/pkgs/id/crates/id-worlds/src/shell_contract/tests.rs @@ -58,6 +58,7 @@ fn server_frame_type(frame: &ServerFrame<'_>) -> &'static str { ServerFrame::EventHistoryBegin { .. } => "event_history_begin", ServerFrame::EventHistoryEvent { .. } => "event_history_event", ServerFrame::Error { .. } => "error", + ServerFrame::ProviderRequest { .. } => "provider_request", } } @@ -93,6 +94,7 @@ const SERVER_FRAME_TYPES: &[&str] = &[ "event_history_begin", "event_history_event", "error", + "provider_request", ]; #[test] @@ -227,6 +229,12 @@ fn every_server_frame_variant_is_in_the_contract_and_nothing_else_is() { message: "denied", code: Some("actor_denied"), }, + ServerFrame::ProviderRequest { + nonce: "ab12", + provider: "client.file.read", + args: serde_json::json!({"path": "notes.txt"}), + deadline_ms: 5000, + }, ServerFrame::Revoked { participant_id: 7, revoked: true, @@ -497,3 +505,55 @@ fn a_transcript_follows_the_session_phases() { assert!(check_transcript(contract, "not json").is_err()); assert!(check_transcript(contract, r#"{"from": "peer", "frame": {}}"#).is_err()); } + +#[test] +fn provider_frames_conform_only_where_the_contract_allows_them() { + let contract = contract(); + + // F13.7 step 2: the offer and the reply are client frames for a + // joined session only — a provider frame in the opening phase is + // a violation, so a session that has not joined can neither + // advertise a provider nor answer a request. + let offer = json!({"type": "provider_offer", "providers": ["client.file.read"]}); + assert_eq!( + contract.check_client_frame(&offer, Phase::Joined).unwrap(), + "provider_offer" + ); + assert!(contract.check_client_frame(&offer, Phase::Opening).is_err()); + let parsed: ClientFrame = serde_json::from_value(offer).unwrap(); + assert!(matches!(parsed, ClientFrame::ProviderOffer { .. })); + + let reply = + json!({"type": "provider_reply", "nonce": "ab12", "ok": true, "result_hex": "00ff"}); + assert_eq!( + contract.check_client_frame(&reply, Phase::Joined).unwrap(), + "provider_reply" + ); + assert!(contract.check_client_frame(&reply, Phase::Query).is_err()); + let parsed: ClientFrame = serde_json::from_value(reply).unwrap(); + assert!(matches!(parsed, ClientFrame::ProviderReply { .. })); + + // The request is a server frame; an undeclared field (a session + // or participant claim the design says never to trust from the + // wire) is a violation. + let request = json!({ + "type": "provider_request", + "nonce": "ab12", + "provider": "client.file.read", + "args": {"path": "notes.txt"}, + "deadline_ms": 5000 + }); + assert_eq!( + contract.check_server_frame(&request).unwrap(), + "provider_request" + ); + let mut claimed = request.clone(); + claimed["session"] = json!("someone-else"); + assert!(contract.check_server_frame(&claimed).is_err()); + + // Nothing about the v1 frame set changed: every pre-existing + // client frame type is still in the contract (the sync test + // above pins the exact set both ways). + assert!(contract.client_frames.contains_key("join")); + assert!(contract.server_frames.contains_key("view")); +} diff --git a/pkgs/id/crates/id-worlds/src/world_session/mod.rs b/pkgs/id/crates/id-worlds/src/world_session/mod.rs index 01a5962d5d..7379cf988a 100644 --- a/pkgs/id/crates/id-worlds/src/world_session/mod.rs +++ b/pkgs/id/crates/id-worlds/src/world_session/mod.rs @@ -990,6 +990,8 @@ async fn run_world_session( | ClientFrame::Resize { .. } | ClientFrame::Revoke { .. } | ClientFrame::Paste { .. } + | ClientFrame::ProviderOffer { .. } + | ClientFrame::ProviderReply { .. } | ClientFrame::FormResult { .. } => { let _ = send_error( service.frame_meter(), @@ -1188,9 +1190,15 @@ async fn query_session( io.mark_authorized(); } let store = documents_store.as_ref().or(service.blobs.as_ref()); - if let Err(message) = - document_session(service.frame_meter(), service.world(), io, token, store, &name) - .await + if let Err(message) = document_session( + service.frame_meter(), + service.world(), + io, + token, + store, + &name, + ) + .await { let _ = send_error(service.frame_meter(), io, message).await; return; @@ -2655,6 +2663,14 @@ async fn handle_client_frame( return send_error(service.frame_meter(), io, "invalid world frame").await; }; let result = match frame { + ClientFrame::ProviderOffer { .. } | ClientFrame::ProviderReply { .. } => { + // F13.7 step 2 lands the frame types and the contract + // rules only: no broker exists yet (step 3), so an offer + // enables nothing and a reply correlates with nothing. + // Both are contract-valid in a joined session and are + // ignored here — fail-closed, and never a session error. + return true; + } ClientFrame::Attenuate { name, scopes, diff --git a/pkgs/id/crates/id-worlds/src/world_session/types.rs b/pkgs/id/crates/id-worlds/src/world_session/types.rs index 9b39b2fb88..647f4ad443 100644 --- a/pkgs/id/crates/id-worlds/src/world_session/types.rs +++ b/pkgs/id/crates/id-worlds/src/world_session/types.rs @@ -337,6 +337,34 @@ pub(crate) enum ClientFrame { Revoke { participant_id: u64, }, + /// F13.7 step 2: the shell advertises the client-side providers + /// it can serve for this session — only ones the local user has + /// opted into. An offer enables nothing by itself: the host + /// broker (step 3) may only request an offered provider, and + /// only when world policy also allows it. A shell that never + /// offers is a v1 shell for provider purposes and receives no + /// `provider_request` frames. + ProviderOffer { + /// Provider names, each under the `client.` namespace. + providers: Vec, + }, + /// F13.7 step 2: the shell's answer to one `provider_request`, + /// correlated by the host-minted `nonce`. Exactly one of + /// `result_hex` / `error` is meaningful, per `ok`. The reply is + /// ephemeral: only the broker's accepted result event is + /// journaled, never the reply itself. + ProviderReply { + /// The nonce from the request being answered, hex-encoded. + nonce: String, + /// Whether the local adapter executed the request. + ok: bool, + /// The bounded result bytes, hex-encoded, when `ok`. + #[serde(default, skip_serializing_if = "Option::is_none")] + result_hex: Option, + /// A stable refusal code when not `ok`. + #[serde(default, skip_serializing_if = "Option::is_none")] + error: Option, + }, } /// Signer metadata supplied with an uploaded module. Public keys and @@ -360,6 +388,23 @@ pub(crate) enum ServerFrame<'a> { Event { event: &'a WorldEvent, }, + /// F13.7 step 2: the host broker asks the originating session's + /// shell to execute one client-side provider. Sent only to a + /// session that advertised the provider in `provider_offer`; + /// shells that do not know this frame ignore it (the contract's + /// additive-revision rule), and a reply is accepted only for the + /// bound session and nonce (broker rules, step 3). Ephemeral: + /// the pending request is never journaled. + ProviderRequest { + /// Host-minted correlation nonce, hex-encoded. + nonce: &'a str, + /// The provider name, under the `client.` namespace. + provider: &'a str, + /// The request arguments, per the provider's manifest schema. + args: serde_json::Value, + /// The broker's deadline for the reply, in milliseconds. + deadline_ms: u64, + }, /// Acknowledges a deferred form answer; on field validation failure the /// fresh token lets the trusted presenter show the pending form again. FormResultStatus {