| 1 | use serde::Deserialize; |
| 2 | |
| 3 | // === Types === |
| 4 | |
| 5 | /// `[extension_host]`: settings for the experimental TypeScript extension |
| 6 | /// host (`[features] extension_host`). User config only: project-scope config |
| 7 | /// is applied by an explicit allowlist that does not include this table. |
| 8 | #[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] |
| 9 | #[serde(deny_unknown_fields)] |
| 10 | pub struct ExtensionHostConfig { |
| 11 | /// Explicit MCP protocol backend. Host is the default and supports stdio, |
| 12 | /// HTTP and SSE independently of optional Native extension activation. |
| 13 | #[serde(default)] |
| 14 | pub mcp_backend: crate::McpBackend, |
| 15 | /// Which runtime runs the host: `node` (the default), `bun`, or `auto` |
| 16 | /// (Bun when a supported one is found and starts, else Node). `bun` and |
| 17 | /// `auto` are opt-ins: Bun is not the default until it is qualified on |
| 18 | /// every platform. An explicit `bun` or `node` never falls back to the |
| 19 | /// other runtime. Unset means `node`, except that a table setting only |
| 20 | /// `bun` means `bun` ([`Self::effective_runtime`]). |
| 21 | #[serde(default)] |
| 22 | pub runtime: Option<ExtensionHostRuntime>, |
| 23 | /// Path to a Node.js runtime (`^22.19 || >=24`). When set it is the only |
| 24 | /// Node candidate: if it does not run or is below the floor, Node |
| 25 | /// resolution fails with that reason instead of searching `PATH`. |
| 26 | /// Unset, every `node` on `PATH` is tried in order, skipping any inside |
| 27 | /// a `node_modules` directory or the working directory. |
| 28 | #[serde(default)] |
| 29 | pub node: Option<String>, |
| 30 | /// Path to a Bun runtime (>= 1.4.0). When set it is the only Bun |
| 31 | /// candidate, as for `node`. Unset, `bun` on `PATH` and then |
| 32 | /// `$BUN_INSTALL/bin` (default `~/.bun/bin`) are tried, with the same |
| 33 | /// skips. |
| 34 | #[serde(default)] |
| 35 | pub bun: Option<String>, |
| 36 | } |
| 37 | |
| 38 | impl ExtensionHostConfig { |
| 39 | /// `runtime` as configured, else `bun` when only a Bun path is set (the |
| 40 | /// table names no other runtime), else `node`. |
| 41 | #[must_use] |
| 42 | pub fn effective_runtime(&self) -> ExtensionHostRuntime { |
| 43 | match (self.runtime, &self.node, &self.bun) { |
| 44 | (Some(runtime), _, _) => runtime, |
| 45 | (None, None, Some(_)) => ExtensionHostRuntime::Bun, |
| 46 | (None, _, _) => ExtensionHostRuntime::Node, |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /// `[extension_host] runtime`. Node is the default; Bun (`bun`, or `auto`, |
| 52 | /// which prefers it) stays an opt-in until an explicit, recorded cutover. |
| 53 | #[derive(Debug, Clone, Copy, Default, Deserialize, PartialEq, Eq)] |
| 54 | #[serde(rename_all = "lowercase")] |
| 55 | pub enum ExtensionHostRuntime { |
| 56 | Auto, |
| 57 | Bun, |
| 58 | #[default] |
| 59 | Node, |
| 60 | } |
| 61 | |
| 62 | impl ExtensionHostRuntime { |
| 63 | #[must_use] |
| 64 | pub fn as_str(self) -> &'static str { |
| 65 | match self { |
| 66 | Self::Auto => "auto", |
| 67 | Self::Bun => "bun", |
| 68 | Self::Node => "node", |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /// `[plugins."<name>"]`: per-plugin settings, keyed by the plugin's manifest |
| 74 | /// name. User config only (like `[extension_host]`): project-scope config is |
| 75 | /// applied by an explicit allowlist that does not include this table, so a |
| 76 | /// repository cannot configure the plugins it asks you to trust. |
| 77 | #[derive(Debug, Clone, Default, Deserialize, PartialEq)] |
| 78 | #[serde(deny_unknown_fields)] |
| 79 | pub struct PluginSettings { |
| 80 | /// `[plugins."<name>".config]`: a TOML table delivered as the `config` |
| 81 | /// argument of the plugin's `apply(ctx, config)` when the extension host |
| 82 | /// activates it, validated against the plugin's own `Config` schema when it |
| 83 | /// declares one. A change takes effect at `/plugin reload` (the plugin is |
| 84 | /// re-activated). Values are not secrets storage: they are shown to the |
| 85 | /// plugin's code, and `/plugin show` lists their keys. |
| 86 | #[serde(default)] |
| 87 | pub config: Option<toml::Table>, |
| 88 | } |
| 89 |