Rust SDK: add typed per-session capability controls#1455
Draft
Morabbin wants to merge 1 commit into
Draft
Conversation
23133c4 to
aa73621
Compare
Adds a typed `SessionCapability` enum and matching `SessionConfig` / `ResumeSessionConfig` fields plus builder methods, so callers can express "enable memory", "disable plan-mode", etc. as a per-session wire parameter rather than a spawn-time CLI flag. - `SessionCapability` is `#[non_exhaustive]`, kebab-case-serialized (via `Display` / `FromStr` / `From<&str>` / `From<String>`), and carries an `Other(String)` escape hatch for forward compatibility with capabilities the runtime adds without requiring an SDK rebuild. - `SessionConfig` and `ResumeSessionConfig` each gain `enabled_capabilities` / `disabled_capabilities` vectors and four builders: `with_enable_capability`, `with_disable_capability`, `with_enabled_capabilities`, `with_disabled_capabilities`. - `SessionConfig::into_wire` and `ResumeSessionConfig::into_wire` convert the vecs to `Option<Vec<String>>` and emit them as `enabledCapabilities` / `disabledCapabilities` in the `session.create` and `session.resume` JSON-RPC payloads. Empty vecs are serialised as `None` (field omitted). Disable wins over enable on conflict (the runtime applies enable first, then disable). - Works for every transport -- including `Transport::External` (Desktop app / shared CLI server) -- because it does not rely on CLI spawn arguments. Pairs with github/copilot-agent-runtime#8918 (per-session capability API) and github/agents#981 (Desktop missing memory capability). 10 new unit tests: 3 enum-level tests (Display / FromStr / From conversions) and 7 wire-serialisation tests in a dedicated `capability_tests` module in `types.rs` (empty omitted, single enable, single disable, bulk-replace, Other round-trip, resume empty, resume enable+disable). Pre-existing test breakage: rust/tests/session_test.rs and rust/tests/protocol_version_test.rs reference removed API methods on main and are unrelated to this change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
aa73621 to
37fd3e9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a typed
SessionCapabilityenum with matchingSessionConfigandResumeSessionConfigfields and builder methods, so callers can express capability opt-in / opt-out / provider registration without stringly-typed flags.This is a per-session API -- the capability fields are sent as JSON-RPC wire parameters on
session.createandsession.resume, so it works for every transport includingTransport::External(Desktop app / shared CLI server).Why
Part of the fix for github/agents#981 (Desktop app missing memory capability). The Desktop app uses
Transport::External, so spawn-time CLI flags have no effect -- a per-session wire API is the correct approach.What
SessionCapabilityenum (rust/src/lib.rs)Memory,PlanMode,CanvasRenderer,Elicitation,McpApps,TuiHints,CliDocumentation,AskUser,InteractiveMode,SystemNotifications) plusOther(String)escape hatch for forward compatibility.#[non_exhaustive],#[serde(rename_all = "kebab-case")].Display,FromStr(Infallible),From<&str>,From<String>,as_str(&self)impls.SessionConfigandResumeSessionConfig(rust/src/types.rs)New fields:
enabled_capabilities: Vec<SessionCapability>-- opt this session into additional capabilities (extends theSDK_CAPABILITIESbaseline).disabled_capabilities: Vec<SessionCapability>-- opt this session out of capabilities; disable wins over enable on overlap.capability_providers: Vec<SessionCapability>-- declare which capabilities this client actively provides (e.g. canvas renderer, elicitation driver).Four builders on each config type:
with_enable_capability,with_disable_capability,with_enabled_capabilities,with_disabled_capabilities, pluswith_capability_provider/with_capability_providers.Wire serialization (
rust/src/wire.rs)SessionCreateWireandSessionResumeWiregain:enabledCapabilities?: string[]disabledCapabilities?: string[]capabilityProviders?: string[]All three fields are
#[serde(skip_serializing_if = "Option::is_none")]-- omitted from the wire when empty.Runtime dependency
Requires github/copilot-agent-runtime#8918 for full runtime support. On older runtimes the fields are silently ignored.
Pairs with github/agents#981.
Tests
12 new unit tests covering:
SessionCapabilityDisplay,FromStr,From<&str>,From<String>, serde round-trip.SessionConfigandResumeSessionConfigwire serialization for all three capability fields.Fmt / clippy / lib / doc tests all pass.
cargo buildpasses.Pre-existing test breakage
rust/tests/session_test.rsandrust/tests/protocol_version_test.rshave pre-existing clippy errors onmain(they reference methods removed in upstream refactors). These are unrelated to this PR. The CI for this PR uses--lib --testswhich excludes those files.