Rust SDK: add typed per-session capability controls#1455
Draft
Morabbin wants to merge 5 commits into
Draft
Conversation
8899958 to
cb93071
Compare
e59f4d0 to
e205d4c
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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make `with_enabled_capabilities` / `with_disabled_capabilities` append to the existing list (via `extend`) instead of replacing it, so the plural builders are consistent with the singular `with_enable_capability` / `with_disable_capability`. Update the builder docs and the round-trip test accordingly. Trim the README capability section to drop implementation details and the hand-maintained variants table, deferring to the enum's own documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
38e8640 to
0a783bb
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 typed
SessionConfig/ResumeSessionConfigfields and builder methods backed by the generatedSessionCapabilityenum, so callers can express per-session capability opt-in / opt-out 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.Why
Some SDK consumers use
Transport::External, so spawn-time CLI flags have no effect. A per-session wire API is the correct approach for session-scoped runtime capabilities.What
SessionCapabilityenumgithub_copilot_sdk::SessionCapability.Memory,PlanMode,CanvasRenderer,Elicitation,McpApps,SessionStore,TuiHints,CliDocumentation,AskUser,InteractiveMode, andSystemNotifications.SessionCapability::Unknownas invalid outbound create/resume configuration, since that variant is only a deserialization fallback.SessionConfigandResumeSessionConfig(rust/src/types.rs)New fields:
enabled_capabilities: Vec<SessionCapability>-- opt this session into additional capabilities.disabled_capabilities: Vec<SessionCapability>-- opt this session out of capabilities; disable wins over enable on overlap.Four builders on each config type:
with_enable_capability,with_disable_capabilitywith_enabled_capabilities,with_disabled_capabilitiesWire serialization (
rust/src/wire.rs)SessionCreateWireandSessionResumeWiregain:enabledCapabilities?: SessionCapability[]disabledCapabilities?: SessionCapability[]Both fields are omitted from the wire when empty. The generated enum serde emits the protocol strings such as
memory,plan-mode, andcanvas-renderer.Runtime dependency
Requires a runtime version that supports
enabledCapabilitiesanddisabledCapabilities. On older runtimes the fields are silently ignored.Validation
cargo +nightly fmt --checkcargo clippy --lib --tests -- -D warningscargo test --lib(154 passed)cargo test --doc(20 passed, 30 ignored)cargo build