Skip to content

Rust SDK: add typed per-session capability controls#1455

Draft
Morabbin wants to merge 5 commits into
github:mainfrom
Morabbin:morabbin/rust-typed-session-capabilities
Draft

Rust SDK: add typed per-session capability controls#1455
Morabbin wants to merge 5 commits into
github:mainfrom
Morabbin:morabbin/rust-typed-session-capabilities

Conversation

@Morabbin

@Morabbin Morabbin commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds typed SessionConfig / ResumeSessionConfig fields and builder methods backed by the generated SessionCapability enum, 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.create and session.resume, so it works for every transport including Transport::External.

Experimental. The new capability enable/disable surface is part of an experimental wire-protocol API. The Rust SDK marks the new fields and builders with the repository's <div class="warning">**Experimental.**</div> rustdoc block (the convention used in rust/src/generated/); there is no #[experimental] attribute, so the marker is documentation-only.

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

SessionCapability enum

  • Reuses the generated protocol enum and re-exports it from the crate root as github_copilot_sdk::SessionCapability.
  • Includes generated typed variants such as Memory, PlanMode, CanvasRenderer, Elicitation, McpApps, SessionStore, TuiHints, CliDocumentation, AskUser, InteractiveMode, and SystemNotifications.
  • Preserves generated per-variant rustdoc and serde wire names.
  • Rejects SessionCapability::Unknown as invalid outbound create/resume configuration, since that variant is only a deserialization fallback.

SessionConfig and ResumeSessionConfig (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_capability
  • with_enabled_capabilities, with_disabled_capabilities

Wire serialization (rust/src/wire.rs)

SessionCreateWire and SessionResumeWire gain:

  • 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, and canvas-renderer.

Runtime dependency

Requires a runtime version that supports enabledCapabilities and disabledCapabilities. On older runtimes the fields are silently ignored.

Validation

  • cargo +nightly fmt --check
  • cargo clippy --lib --tests -- -D warnings
  • cargo test --lib (154 passed)
  • cargo test --doc (20 passed, 30 ignored)
  • cargo build

Copilot AI review requested due to automatic review settings May 27, 2026 14:47
@Morabbin Morabbin requested a review from a team as a code owner May 27, 2026 14:47
@Morabbin Morabbin marked this pull request as draft May 27, 2026 15:06
@Morabbin Morabbin changed the title rust: add typed SessionCapability enum and ClientOptions builders Rust SDK: add typed SessionCapability enum and ClientOptions builders May 27, 2026
@Morabbin Morabbin changed the title Rust SDK: add typed SessionCapability enum and ClientOptions builders Rust SDK: add typed per-session capability controls May 27, 2026
@Morabbin Morabbin force-pushed the morabbin/rust-typed-session-capabilities branch 6 times, most recently from 8899958 to cb93071 Compare June 3, 2026 11:48
@Morabbin Morabbin force-pushed the morabbin/rust-typed-session-capabilities branch 2 times, most recently from e59f4d0 to e205d4c Compare June 9, 2026 07:20
Comment thread rust/README.md Outdated
Comment thread rust/src/lib.rs Outdated
Comment thread rust/src/lib.rs Outdated
Comment thread rust/src/types.rs Outdated
Comment thread rust/README.md Outdated
Comment thread rust/README.md Outdated
Comment thread rust/README.md
Comment thread rust/README.md Outdated
Morabbin and others added 5 commits June 9, 2026 21:37
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>
@Morabbin Morabbin force-pushed the morabbin/rust-typed-session-capabilities branch from 38e8640 to 0a783bb Compare June 9, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants