From 144ec47704c7764745f329becb1f8ff0354dcb6f Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 07:03:45 +0000 Subject: [PATCH 1/2] fix(toolchains): version permission and authority error codes --- rust/contracts/rust-core-api.md | 7 +- .../core/src/tests/toolchain_definitions.rs | 24 ++++++ .../core/src/tests/toolchain_queries.rs | 73 +++++++++++++++---- .../core/src/tests/toolchain_vectors.rs | 12 ++- .../lsp-client/src/toolchain_provider.rs | 20 ++--- rust/crates/lsp-engine/src/tests.rs | 2 +- rust/crates/plugin-model/src/capabilities.rs | 4 +- rust/crates/plugin-rpc/src/failures.rs | 3 +- rust/crates/toolchain/src/definitions.rs | 3 +- rust/crates/toolchain/src/query.rs | 34 +++++++-- .../toolchains/error-code-versions.json | 17 +++++ shared/plugins/README.md | 4 +- shared/plugins/contract/v1/README.md | 7 +- .../contract/v1/plugin-manifest.schema.json | 2 +- .../plugins/contract/v1/toolchains/README.md | 39 ++++++---- .../reference/capabilities-and-versions.md | 14 ++-- .../plugins/reference/domains/toolchains.md | 32 ++++---- .../plugins/reference/protocol-changelog.md | 3 + .../plugins/sdk/e2e/plugin_sdk/toolchains.rs | 36 ++++++++- shared/plugins/sdk/rust/README.md | 16 +++- .../rust/examples/sample-backend/src/main.rs | 12 ++- .../sdk/rust/plugin-sdk/src/backend.rs | 27 +++++-- .../sdk/rust/plugin-sdk/src/toolchains.rs | 40 ++++++++-- .../sdk/rust/plugin-sdk/tests/toolchains.rs | 67 ++++++++++++++++- 24 files changed, 393 insertions(+), 105 deletions(-) create mode 100644 rust/fixtures/toolchains/error-code-versions.json diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index 1ea4ef58..0d2ecc54 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -3456,10 +3456,11 @@ operation. See the [provider execution contract](../../shared/plugins/contract/v `lsp.toolchainRequest` accepts `{ sessionId, operationId?, params, timeoutMilliseconds? }` and returns `{ operationId }`. `lsp.startServer` takes `toolchainProviders`, the manifest's provider IDs; only a plugin-owned session -with some offers `capabilities.experimental.litheToolchains: { versions: [0], -providers }`. A backend that answers `{ version: 0, providers }` with a non-empty, +with some offers `capabilities.experimental.litheToolchains: { versions: [0, 1], +providers }`. A backend answers +`{ version, providers }` with its manifest's `toolchainProviders` version. A non-empty, duplicate-free subset of the offer emits a `toolchainProviders` runtime event -with `result: { providers }`; any other answer enables none. A request whose +with `result: { providers }`; an unsupported version or invalid subset enables none. A request whose `params.providerID` was not negotiated is `not_supported` with details `plugin.toolchain.providerUnavailable`, and nothing is written. The `requestCompleted` event carries `result.value: { id, response }`: the JSON-RPC diff --git a/rust/crates/core/src/tests/toolchain_definitions.rs b/rust/crates/core/src/tests/toolchain_definitions.rs index 959352a1..53912882 100644 --- a/rust/crates/core/src/tests/toolchain_definitions.rs +++ b/rust/crates/core/src/tests/toolchain_definitions.rs @@ -460,6 +460,30 @@ fn production_toolchain_fixtures_require_explicit_host_capabilities() { } } +#[test] +fn toolchain_provider_version_one_is_not_admitted_by_a_legacy_only_host() { + let mut manifest: Value = serde_json::from_str(include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../../shared/plugins/contract/v1/fixtures/toolchains/toolchain-provider.plugin.json" + ))) + .unwrap(); + manifest["requires"]["toolchainProviders"] = json!(1); + let legacy = validate_command(json!({ + "manifest": manifest, + "hostCapabilities": {"backend": [0], "toolchainProviders": [0]} + })) + .unwrap(); + assert_eq!(legacy["status"], "rejected"); + assert_eq!(legacy["error"]["code"], "plugin.api.unsupported"); + assert_eq!(legacy["error"]["field"], "requires.toolchainProviders"); + let current = validate_command(json!({ + "manifest": manifest, + "hostCapabilities": {"backend": [0], "toolchainProviders": [0, 1]} + })) + .unwrap(); + assert_eq!(current["status"], "ok", "{current}"); +} + /// Launches, tool references, and executable candidates belong to the base /// contract, so naming them in `requires` is refused. #[test] diff --git a/rust/crates/core/src/tests/toolchain_queries.rs b/rust/crates/core/src/tests/toolchain_queries.rs index 968854dd..21438170 100644 --- a/rust/crates/core/src/tests/toolchain_queries.rs +++ b/rust/crates/core/src/tests/toolchain_queries.rs @@ -236,26 +236,69 @@ fn toolchain_queries_refuse_mismatched_rpc_and_operation_generations() { #[test] fn toolchain_queries_keep_every_error_mapping_unique_and_validate_the_pair() { - let mut numbers = std::collections::BTreeSet::new(); - for mut response in error_responses() { + for version in [0, 1] { + let mut numbers = std::collections::BTreeSet::new(); + for mut response in error_responses(version) { + let mut value = input(); + value["registry"]["plugins"][1]["manifest"]["requires"]["toolchainProviders"] = + json!(version); + response["id"] = value["request"]["id"].clone(); + response["error"]["data"]["operationID"] = + value["request"]["params"]["operationID"].clone(); + value["response"] = response; + let error = query::decode(&value, validated_manifest_json).unwrap_err(); + assert_eq!( + Some(error.code()), + value["response"]["error"]["data"]["code"].as_str() + ); + let number = query::rpc_code_for_version(error.code(), version).unwrap(); + assert_eq!(value["response"]["error"]["code"], number); + assert!(numbers.insert(number)); + if version == 0 { + assert_eq!(query::rpc_code(error.code()), Some(number)); + } else { + for relayed in ["plugin.function.failed", "plugin.function.invalidResult"] { + assert_ne!(number, lithe_plugin_rpc::host_rpc_code(relayed)); + } + } + value["response"]["error"]["code"] = json!(-1); + assert_eq!( + query::decode(&value, validated_manifest_json) + .unwrap_err() + .code(), + "plugin.toolchain.invalidReply" + ); + } + } + assert_eq!( + query::rpc_code_for_version("plugin.toolchain.timeout", 2), + None + ); +} + +#[test] +fn toolchain_queries_bind_error_numbers_to_the_declared_capability_version() { + let fixture: Value = serde_json::from_str(include_str!( + "../../../../fixtures/toolchains/error-code-versions.json" + )) + .unwrap(); + for case in fixture["cases"].as_array().unwrap() { let mut value = input(); - response["id"] = value["request"]["id"].clone(); - response["error"]["data"]["operationID"] = - value["request"]["params"]["operationID"].clone(); - value["response"] = response; - let error = query::decode(&value, validated_manifest_json).unwrap_err(); - assert_eq!( - Some(error.code()), - value["response"]["error"]["data"]["code"].as_str() - ); - let number = query::rpc_code(error.code()).unwrap(); - assert!(numbers.insert(number)); - value["response"]["error"]["code"] = json!(-1); + value["registry"]["plugins"][1]["manifest"]["requires"]["toolchainProviders"] = + case["version"].clone(); + value["response"] = json!({ + "jsonrpc": "2.0", "id": value["request"]["id"], + "error": {"code": case["number"], "message": "Fixture diagnostic.", "data": { + "code": case["code"], "operationID": "query-1", "providerID": "mise" + }} + }); assert_eq!( query::decode(&value, validated_manifest_json) .unwrap_err() .code(), - "plugin.toolchain.invalidReply" + case["expected"].as_str().unwrap(), + "{}", + case["name"] ); } } diff --git a/rust/crates/core/src/tests/toolchain_vectors.rs b/rust/crates/core/src/tests/toolchain_vectors.rs index f0433f32..eecbfac4 100644 --- a/rust/crates/core/src/tests/toolchain_vectors.rs +++ b/rust/crates/core/src/tests/toolchain_vectors.rs @@ -73,13 +73,14 @@ pub(super) fn query_response() -> Value { /// test pairing each reply with its decoded code checks the mapping itself. /// Ids and operation IDs are distinct placeholders; tests rewrite both to match /// the request they answer. -pub(super) fn error_responses() -> Vec { +pub(super) fn error_responses(version: u32) -> Vec { + assert!(matches!(version, 0 | 1)); const FAILURES: [(i64, &str); 11] = [ (-32601, "methodUnavailable"), (-32602, "invalidParams"), (-32800, "cancelled"), - (-32070, "permissionDenied"), - (-32071, "authorityUnsupported"), + (-32080, "permissionDenied"), + (-32081, "authorityUnsupported"), (-32072, "timeout"), (-32073, "providerUnavailable"), (-32074, "invalidReply"), @@ -91,6 +92,11 @@ pub(super) fn error_responses() -> Vec { .iter() .zip(100..) .map(|(&(number, name), id)| { + let number = match (version, number) { + (0, -32080) => -32070, + (0, -32081) => -32071, + _ => number, + }; json!({"jsonrpc":"2.0","id":id,"error":{"code":number,"message":"Fixture diagnostic.", "data":{"code":format!("plugin.toolchain.{name}"),"operationID":format!("query-{id}"),"providerID":"mise"}}}) }) diff --git a/rust/crates/lsp-client/src/toolchain_provider.rs b/rust/crates/lsp-client/src/toolchain_provider.rs index 6871f472..38206b48 100644 --- a/rust/crates/lsp-client/src/toolchain_provider.rs +++ b/rust/crates/lsp-client/src/toolchain_provider.rs @@ -83,21 +83,23 @@ mod tests { assert_eq!(key, "litheToolchains"); assert_eq!( offer, - json!({ "versions": [0], "providers": ["asdf", "mise"] }) + json!({ "versions": [0, 1], "providers": ["asdf", "mise"] }) ); } #[test] fn negotiation_accepts_only_a_complete_subset_of_the_offer() { - assert_eq!( - negotiate( - &answer(json!({ "version": 0, "providers": ["mise"], "future": true })), - &offered() - ), - Some(vec!["mise".to_string()]) - ); + for version in [0, 1] { + assert_eq!( + negotiate( + &answer(json!({ "version": version, "providers": ["mise"], "future": true })), + &offered() + ), + Some(vec!["mise".to_string()]) + ); + } for rejected in [ - json!({ "version": 1, "providers": ["mise"] }), + json!({ "version": 2, "providers": ["mise"] }), json!({ "version": 0 }), json!({ "version": 0, "providers": [] }), json!({ "version": 0, "providers": "mise" }), diff --git a/rust/crates/lsp-engine/src/tests.rs b/rust/crates/lsp-engine/src/tests.rs index 660cac82..75f34a6c 100644 --- a/rust/crates/lsp-engine/src/tests.rs +++ b/rust/crates/lsp-engine/src/tests.rs @@ -3598,7 +3598,7 @@ fn a_query_reaches_only_a_selected_provider_and_returns_the_raw_response() { .expect("initialize should have been written"); assert_eq!( initialize["params"]["capabilities"]["experimental"]["litheToolchains"], - json!({ "versions": [0], "providers": ["mise"] }) + json!({ "versions": [0, 1], "providers": ["mise"] }) ); let event = harness .await_event(|event| event.kind == "toolchainProviders") diff --git a/rust/crates/plugin-model/src/capabilities.rs b/rust/crates/plugin-model/src/capabilities.rs index e2f13787..3837d910 100644 --- a/rust/crates/plugin-model/src/capabilities.rs +++ b/rust/crates/plugin-model/src/capabilities.rs @@ -121,6 +121,8 @@ pub const PLUGIN_FUNCTIONS: &str = "pluginFunctions"; /// `audience` that place a tool in the settings list. pub const TOOL_DEFINITIONS: &str = "toolDefinitions"; /// Backend facts that can influence the executable selected for a defined tool. +/// Version 1 gives permission and authority failures distinct JSON-RPC numbers, +/// leaving version 0's published error mapping unchanged. pub const TOOLCHAIN_PROVIDERS: &str = "toolchainProviders"; /// `outputLinkMatchers[]`: patterns that turn console output into links; see /// `lithe_plugin_output_links`. @@ -149,7 +151,7 @@ pub const SUPPORTED_CAPABILITIES: &[(&str, &[u32])] = &[ (SETTINGS, &[0]), (SOURCE_SETTINGS, &[0, 1]), (TOOL_DEFINITIONS, &[0, 1]), - (TOOLCHAIN_PROVIDERS, &[0]), + (TOOLCHAIN_PROVIDERS, &[0, 1]), (UI, &[0]), (VCS_PROVIDERS, &[0]), ]; diff --git a/rust/crates/plugin-rpc/src/failures.rs b/rust/crates/plugin-rpc/src/failures.rs index 4d53cf40..b0ae8e03 100644 --- a/rust/crates/plugin-rpc/src/failures.rs +++ b/rust/crates/plugin-rpc/src/failures.rs @@ -42,7 +42,8 @@ pub fn host_rpc_code(code: &str) -> i64 { // must tell the provider's error from Core's by the number alone. codes::FAILED => -32070, codes::INVALID_RESULT => -32071, - // -32072 to -32077 are the toolchain provider protocol's. + // Toolchains own -32072..=-32077 and, since capability version 1, + // -32080/-32081. Only legacy version 0 overlaps -32070/-32071. codes::HOST_REMOTE_DISCONNECTED => -32078, codes::HOST_PLATFORM_UNAVAILABLE => -32079, _ => -32603, diff --git a/rust/crates/toolchain/src/definitions.rs b/rust/crates/toolchain/src/definitions.rs index befa615c..9914172d 100644 --- a/rust/crates/toolchain/src/definitions.rs +++ b/rust/crates/toolchain/src/definitions.rs @@ -802,7 +802,8 @@ pub fn registry(input: &Value, validate_manifest: ManifestValidator) -> Validati definitions.push(json!({"pluginID":plugin_id,"definition":normalized})); } for provider in optional_list(&manifest, "toolchainProviders", 8)? { - providers.push(json!({"pluginID":plugin_id,"provider":provider})); + providers.push(json!({"pluginID":plugin_id, + "version":manifest["requires"]["toolchainProviders"],"provider":provider})); } if definitions.len() > 512 || providers.len() > 256 { return Err(invalid( diff --git a/rust/crates/toolchain/src/query.rs b/rust/crates/toolchain/src/query.rs index ae0c40da..78d3b706 100644 --- a/rust/crates/toolchain/src/query.rs +++ b/rust/crates/toolchain/src/query.rs @@ -219,14 +219,27 @@ fn object_keys( Ok(()) } -/// Maps each query error to one stable JSON-RPC number without transport work. +/// Maps a query error to the published version 0 number without transport work. +/// New callers with a manifest version use [`rpc_code_for_version`]. pub fn rpc_code(code: &str) -> Option { + rpc_code_for_version(code, 0) +} + +/// Maps a stable query error using the manifest's `toolchainProviders` version. +/// Unknown versions or error names have no mapping. Version 0 retains its +/// published numbers; version 1 no longer overlaps relayed function failures. +pub fn rpc_code_for_version(code: &str, version: u32) -> Option { + if !matches!(version, 0 | 1) { + return None; + } Some(match code { "plugin.toolchain.methodUnavailable" => -32601, INVALID => -32602, "plugin.toolchain.cancelled" => -32800, - "plugin.toolchain.permissionDenied" => -32070, - "plugin.toolchain.authorityUnsupported" => -32071, + "plugin.toolchain.permissionDenied" if version == 0 => -32070, + "plugin.toolchain.permissionDenied" => -32080, + "plugin.toolchain.authorityUnsupported" if version == 0 => -32071, + "plugin.toolchain.authorityUnsupported" => -32081, "plugin.toolchain.timeout" => -32072, "plugin.toolchain.providerUnavailable" => -32073, REPLY => -32074, @@ -237,7 +250,7 @@ pub fn rpc_code(code: &str) -> Option { }) } -fn error_reply(response: &Value, params: &Params) -> Validation { +fn error_reply(response: &Value, params: &Params, version: u32) -> Validation { let error = &response["error"]; object_keys( error, @@ -253,7 +266,7 @@ fn error_reply(response: &Value, params: &Params) -> Validation { REPLY, )?; let code = data["code"].as_str().unwrap_or(""); - if rpc_code(code) != error["code"].as_i64() + if rpc_code_for_version(code, version) != error["code"].as_i64() || data["operationID"] != params.operation_id || data["providerID"] != params.provider_id || !error["message"] @@ -274,8 +287,8 @@ fn error_reply(response: &Value, params: &Params) -> Validation { Some(-32601) => "plugin.toolchain.methodUnavailable", Some(-32602) => INVALID, Some(-32800) => "plugin.toolchain.cancelled", - Some(-32070) => "plugin.toolchain.permissionDenied", - Some(-32071) => "plugin.toolchain.authorityUnsupported", + Some(-32070 | -32080) => "plugin.toolchain.permissionDenied", + Some(-32071 | -32081) => "plugin.toolchain.authorityUnsupported", Some(-32072) => "plugin.toolchain.timeout", Some(-32073) => "plugin.toolchain.providerUnavailable", Some(-32074) => REPLY, @@ -835,6 +848,11 @@ pub fn decode(input: &Value, validate_manifest: ManifestValidator) -> Validation "The enabled provider is not in the revalidated registry.", ) })?; + // The registry is rebuilt from complete validated manifests above. Neither + // an error number nor provider-owned response data can choose its version. + let provider_version = provider["version"] + .as_u64() + .expect("validated toolchain capability version") as u32; let provider = &provider["provider"]; let declared: BTreeSet<&str> = provider["tools"] .as_array() @@ -885,7 +903,7 @@ pub fn decode(input: &Value, validate_manifest: ManifestValidator) -> Validation )); } if response.get("error").is_some() { - return error_reply(response, params); + return error_reply(response, params, provider_version); } let reply: Reply = serde_json::from_value(response["result"].clone()).map_err(|_| { reject( diff --git a/rust/fixtures/toolchains/error-code-versions.json b/rust/fixtures/toolchains/error-code-versions.json new file mode 100644 index 00000000..71efccaa --- /dev/null +++ b/rust/fixtures/toolchains/error-code-versions.json @@ -0,0 +1,17 @@ +{ + "cases": [ + {"name":"legacy permission", "version":0, "number":-32070, "code":"plugin.toolchain.permissionDenied", "expected":"plugin.toolchain.permissionDenied"}, + {"name":"legacy authority", "version":0, "number":-32071, "code":"plugin.toolchain.authorityUnsupported", "expected":"plugin.toolchain.authorityUnsupported"}, + {"name":"version 1 permission", "version":1, "number":-32080, "code":"plugin.toolchain.permissionDenied", "expected":"plugin.toolchain.permissionDenied"}, + {"name":"version 1 authority", "version":1, "number":-32081, "code":"plugin.toolchain.authorityUnsupported", "expected":"plugin.toolchain.authorityUnsupported"}, + {"name":"legacy rejects new permission number", "version":0, "number":-32080, "code":"plugin.toolchain.permissionDenied", "expected":"plugin.toolchain.invalidReply"}, + {"name":"legacy rejects new authority number", "version":0, "number":-32081, "code":"plugin.toolchain.authorityUnsupported", "expected":"plugin.toolchain.invalidReply"}, + {"name":"version 1 rejects legacy permission number", "version":1, "number":-32070, "code":"plugin.toolchain.permissionDenied", "expected":"plugin.toolchain.invalidReply"}, + {"name":"version 1 rejects legacy authority number", "version":1, "number":-32071, "code":"plugin.toolchain.authorityUnsupported", "expected":"plugin.toolchain.invalidReply"}, + {"name":"legacy rejects relayed function failure", "version":0, "number":-32070, "code":"plugin.function.failed", "expected":"plugin.toolchain.invalidReply"}, + {"name":"version 1 rejects relayed function failure", "version":1, "number":-32070, "code":"plugin.function.failed", "expected":"plugin.toolchain.invalidReply"}, + {"name":"legacy rejects relayed invalid result", "version":0, "number":-32071, "code":"plugin.function.invalidResult", "expected":"plugin.toolchain.invalidReply"}, + {"name":"version 1 rejects relayed invalid result", "version":1, "number":-32071, "code":"plugin.function.invalidResult", "expected":"plugin.toolchain.invalidReply"}, + {"name":"unknown capability version", "version":2, "number":-32080, "code":"plugin.toolchain.permissionDenied", "expected":"plugin.api.unsupported"} + ] +} diff --git a/shared/plugins/README.md b/shared/plugins/README.md index ef425bcd..f9232b95 100644 --- a/shared/plugins/README.md +++ b/shared/plugins/README.md @@ -182,7 +182,7 @@ SDK 与插件后端在构建时下载,并按锁定的 SHA-256(或 Git commit | [`plugin-index.schema.json`](contract/v1/plugin-index.schema.json) | `lithe-plugin-index.json` 的 JSON Schema | | [`plugin-ui.schema.json`](contract/v1/plugin-ui.schema.json) | 插件视图(工具窗口和设置区域)的视图函数返回的界面树、画布节点和补丁的 JSON Schema | | [`plugin-l10n.schema.json`](contract/v1/plugin-l10n.schema.json) | 插件翻译文件 `l10n/<语言>.json` 的 JSON Schema | -| [`toolchains/`](contract/v1/toolchains/README.md) | 插件提供的工具链:工具定义、版本管理器提供方、提供方后端协商(`litheToolchains`)、查询与回复校验(含稳定失败码)、固定值(pin)和四层解析。Core 实现这些命令;Lithe 桌面端声明 `toolDefinitions`,未声明 `toolchainProviders` | +| [`toolchains/`](contract/v1/toolchains/README.md) | 插件提供的工具链:工具定义、版本管理器提供方、提供方后端协商(`litheToolchains`)、查询与回复校验(含稳定失败码)、固定值(pin)和四层解析。Core 实现这些命令;Lithe 桌面端声明 `toolDefinitions` 和 `toolchainProviders` 0,后者的版本 1 尚未声明 | | [`fixtures/`](contract/v1/fixtures) | 标准用例,按功能分目录(`manifest`、`languages`、`backend`、`build-systems`、`build-providers`、`marketplace` 等),和 [reference 功能页](reference/README.md#功能页)一一对应:合法和非法的清单、命令和构建规划、插件函数协议、市场索引,以及 Lithe 对每个用例的预期结果 | fixture 放在 `fixtures/<功能>/` 下,文件按演示的能力命名,例如 `build-systems/build-command-stdout.plugin.json` 演示“解码命令的标准输出”。它们借 Cargo、Go、Gradle、Maven 等真实工具作为输入,但不是这些插件本身;要参考完整插件,看[示例插件](#示例插件)。每个目录的文件和用例数量见对应功能页的“示例与用例”。 @@ -403,7 +403,7 @@ The plugin contract defines the meaning, validation rules, and error codes of ev | [`plugin-index.schema.json`](contract/v1/plugin-index.schema.json) | JSON Schema for `lithe-plugin-index.json` | | [`plugin-ui.schema.json`](contract/v1/plugin-ui.schema.json) | JSON Schema for the UI trees, canvas nodes and patches a plugin view function returns, in tool windows and settings regions | | [`plugin-l10n.schema.json`](contract/v1/plugin-l10n.schema.json) | JSON Schema for a plugin's translation file `l10n/.json` | -| [`toolchains/`](contract/v1/toolchains/README.md) | Plugin-owned toolchains: tool definitions, version manager providers, provider backend negotiation (`litheToolchains`), query and reply validation (with stable failure codes), pins, and four-layer resolution. Core implements these commands; the Lithe desktop client declares `toolDefinitions` and does not declare `toolchainProviders` | +| [`toolchains/`](contract/v1/toolchains/README.md) | Plugin-owned toolchains: tool definitions, version manager providers, provider backend negotiation (`litheToolchains`), query and reply validation (with stable failure codes), pins, and four-layer resolution. Core implements these commands; the Lithe desktop client declares `toolDefinitions` and `toolchainProviders` 0, but not version 1 of the latter | | [`fixtures/`](contract/v1/fixtures) | Conformance cases in one directory per feature (`manifest`, `languages`, `backend`, `build-systems`, `build-providers`, `marketplace`, and so on), matching the [reference feature pages](reference/README.md#feature-pages): valid and invalid manifests, command and build plans, plugin function protocol, marketplace indexes, and Lithe's expected result for each case | Fixtures live under `fixtures//` and are named for the capability they demonstrate; for example `build-systems/build-command-stdout.plugin.json` demonstrates decoding a command's standard output. They use real tools such as Cargo, Go, Gradle, and Maven as inputs but are not those plugins; for complete plugins, see the [example plugins](#example-plugins). Each feature page's "Examples and cases" section lists its files and case counts. diff --git a/shared/plugins/contract/v1/README.md b/shared/plugins/contract/v1/README.md index d260eede..db71367a 100644 --- a/shared/plugins/contract/v1/README.md +++ b/shared/plugins/contract/v1/README.md @@ -64,7 +64,7 @@ does not add a built-in tool-definition table or interpret version-manager configuration formats. The [implemented Core contract](toolchains/README.md) accepts `toolDefinitions: 0` -and `toolchainProviders: 0` declarations and provides the `toolchains.*` commands +and `toolchainProviders: 0` or `1` declarations and provides the `toolchains.*` commands listed there. Tool-definition candidates follow [Executable resolution](#executable-resolution) and do not admit new sources into existing Build candidate sets. Definitions are entirely @@ -184,7 +184,7 @@ symbolic links. A host treats an installed package as read-only. | `commandInstallers` | How the host installs a bare command a `systemCommand` launch needs; requires `commandInstallers: 0` and `commands.install`; see [Command installers](#command-installers). | | `managedRuntimes` | Pinned dependencies qualified by a packaged backend and installed in host-owned storage independent of plugin version; requires `managedRuntimes: 0` and `runtimes.install`; see [Managed runtimes](#managed-runtimes). | | `toolDefinitions` | Plugin-owned tool policy ([Core foundation](toolchains/README.md)); requires `toolDefinitions: 0`, or `1` when a definition sets the settings-list `category` or `audience`; a host may offer read-only discovery and resolve Build and run tools. | -| `toolchainProviders` | Backend fact-provider declarations ([Core foundation](toolchains/README.md)); requires `toolchainProviders: 0`, `backend: 0` and `toolchains.provide`. | +| `toolchainProviders` | Backend fact-provider declarations ([Core foundation](toolchains/README.md)); requires `toolchainProviders: 0` or `1`, `backend: 0` and `toolchains.provide`. Version 1 uses distinct permission and authority error numbers. | | `keymapImportProviders` | Independent shortcut import providers; requires `keymapImportProviders: 0`, `backend: 0` and `keymaps.provide`. A host provides access to explicitly selected sources. | | `pluginFunctions` | [Functions the plugin exports to, and calls from, other plugins](#cross-plugin-calls); requires `pluginFunctions: 0` and `backend: 0`, and grants no permission. A host that advertises this capability relays the calls. | @@ -974,7 +974,8 @@ per capability. `buildProviders`, `litheFunctions` from `backend`, `litheVcs` from `vcsProviders`, the toolchain provider protocol from `toolchainProviders`, `litheKeymapImport` from `keymapImportProviders`, and `litheLogging` from - `pluginAPIVersion`. `litheBuild` is at `1`; all the others are `0`. + `pluginAPIVersion`. `litheBuild` and `litheToolchains` support `0` and `1`; + all the others are `0`. 3. **A host declares a capability version when it can serve every form of it.** See [Host capabilities](#host-capabilities). 4. **A future change gives one capability version `1`.** The manifest section diff --git a/shared/plugins/contract/v1/plugin-manifest.schema.json b/shared/plugins/contract/v1/plugin-manifest.schema.json index 9a7342ed..1b17ee95 100644 --- a/shared/plugins/contract/v1/plugin-manifest.schema.json +++ b/shared/plugins/contract/v1/plugin-manifest.schema.json @@ -51,7 +51,7 @@ "settings": { "description": "Required exactly when settings, settingActions or settingRegions is non-empty. Covers integer, enum, boolean, multiSelect, text, file, and directory options, scope, effect, page, section, settingActions, and settingRegions.", "enum": [0] }, "sourceSettings": { "description": "Required exactly when a setting action declares sourceEditor. Native-source settings projection, compiler placement, confirmed staging and read-back. Version 1 adds sidebar groups, nested sources, field sections and entry lists.", "enum": [0, 1] }, "toolDefinitions": { "description": "Required exactly when toolDefinitions is present. Version 1 adds the display-only category and audience of a definition.", "enum": [0, 1] }, - "toolchainProviders": { "enum": [0] }, + "toolchainProviders": { "description": "Version 1 uses distinct permission and authority error numbers (-32080/-32081); version 0 keeps -32070/-32071.", "enum": [0, 1] }, "keymapImportProviders": { "enum": [0] }, "pluginFunctions": { "description": "Required exactly when pluginFunctions is present: functions this plugin's backend exports to other plugins, and exported functions it calls. Needs backend.", "enum": [0] }, "ui": { "description": "Required exactly when ui is present or a settings region declares a view. Covers tool windows with text, web content, or a plugin view, settings-region views, and backend-only commands.", "enum": [0] }, diff --git a/shared/plugins/contract/v1/toolchains/README.md b/shared/plugins/contract/v1/toolchains/README.md index 250ae1d2..7be3d34d 100644 --- a/shared/plugins/contract/v1/toolchains/README.md +++ b/shared/plugins/contract/v1/toolchains/README.md @@ -12,15 +12,15 @@ runs the definition's version probe on executables Core returns from settings detections are never used as launch permits. A host that also declares `toolchainProviders` starts or reuses each enabled provider's plugin backend, sends `toolchains/query` through `lsp.toolchainRequest`, and passes every raw -reply with native facts to `decodeReply` (the desktop client does not declare -`toolchainProviders` yet, so packages requiring it are not offered for -installation there). The manifest shape is +reply with native facts to `decodeReply`. The desktop client declares +`toolchainProviders: 0`; version 1 requires a host that also advertises it. +The manifest shape is [plugin-manifest.schema.json](../plugin-manifest.schema.json). ## Manifest admission and registry `toolDefinitions[]` needs `requires.toolDefinitions: 0`. `toolchainProviders[]` -needs `requires.toolchainProviders: 0`, `backend: 0`, and permissions +needs `requires.toolchainProviders: 0` or `1`, `backend: 0`, and permissions `backend.launch` / `toolchains.provide`. Capability lists are exact: missing or unused capabilities reject the manifest. A definition/provider alone is a valid contribution. Executable candidate sets keep their strict source types; the @@ -149,7 +149,9 @@ Every `registry` input is the raw `{plugins:[{manifest}]}` request of the enable plugins, not a previously normalized result. Core revalidates complete production manifests; the host supplies no proof of a plugin's origin, and a plugin's own claim of one is not read. Output is `{definitions:[{pluginID,definition}], -providers:[{pluginID,provider}],conflicts:[{tool,pluginIDs}]}` in stable order. +providers:[{pluginID,version,provider}],conflicts:[{tool,pluginIDs}]}` in stable +order. A provider row's `version` is its revalidated manifest's +`requires.toolchainProviders`, never a number claimed by a query response. A short ID defined by more than one enabled plugin belongs to none of them. Core registers none of those definitions and registers every other definition as @@ -178,18 +180,20 @@ at least one provider is offered the protocol, in the client capabilities of `initialize`: ```json -{"experimental": {"litheToolchains": {"versions": [0], "providers": ["first", "second"]}}} +{"experimental": {"litheToolchains": {"versions": [0, 1], "providers": ["first", "second"]}}} ``` `providers` lists the declared IDs in sorted order. The backend selects in the server capabilities of its `initialize` result: ```json -{"experimental": {"litheToolchains": {"version": 0, "providers": ["first"]}}} +{"experimental": {"litheToolchains": {"version": 1, "providers": ["first"]}}} ``` The protocol has no version of its own: its version is that of the -`toolchainProviders` capability, `0`. `version` must be an offered version and +`toolchainProviders` capability, `0` or `1`. The backend selects the version +its manifest declares; version 0 backends remain supported without changing +their error numbers. `version` must be an offered version and `providers` a non-empty list of offered IDs without repeats; other fields are ignored. Any other answer, including an unoffered version, an undeclared, repeated or non-string ID, or an empty list, @@ -261,8 +265,10 @@ A provider that cannot answer returns a JSON-RPC `error` instead of `result`. `error` has exactly `{code,message,data}`, and `data` has `{code,operationID, providerID}` plus an optional `details`: -- `code` is a number from the table below and `data.code` is the stable code - on its row. Each number has exactly one stable code. +- `code` is a number for the manifest's `requires.toolchainProviders` version + and `data.code` is the stable code on its row. Version 1 gives the two + toolchain-specific failures their own numbers, distinct from plugin-function + relay failures. The decoder derives the version from the revalidated registry. - `operationID` and `providerID` equal those of the request `params`. - `message` is non-empty diagnostic text of at most 1,024 UTF-8 bytes without control characters. It is shown as provider text and never selects behavior. @@ -274,13 +280,13 @@ An error reply that breaks any of these rules, including an unknown number or a number that does not match `data.code`, is refused as `plugin.toolchain.invalidReply`. -| JSON-RPC | Stable code | Meaning | +| JSON-RPC (version 1) | Stable code | Meaning | | --- | --- | --- | | `-32601` | `plugin.toolchain.methodUnavailable` | The backend does not serve the query method | | `-32602` | `plugin.toolchain.invalidParams` | Malformed request or invalid declared input | | `-32800` | `plugin.toolchain.cancelled` | The caller cancelled the request | -| `-32070` | `plugin.toolchain.permissionDenied` | A permission, review or enabled-state prerequisite is missing | -| `-32071` | `plugin.toolchain.authorityUnsupported` | The provider cannot serve the requested authority | +| `-32080` | `plugin.toolchain.permissionDenied` | A permission, review or enabled-state prerequisite is missing | +| `-32081` | `plugin.toolchain.authorityUnsupported` | The provider cannot serve the requested authority | | `-32072` | `plugin.toolchain.timeout` | The local deadline passed | | `-32073` | `plugin.toolchain.providerUnavailable` | The backend failed to start, disconnected, or its upstream query failed | | `-32074` | `plugin.toolchain.invalidReply` | Malformed reply, or an installation reference to another tool | @@ -288,6 +294,13 @@ number that does not match `data.code`, is refused as | `-32076` | `plugin.toolchain.unsafePath` | A path is not absolute, escapes its containment or fails executable checks | | `-32077` | `plugin.toolchain.operationExpired` | The context or generation was already stale when the query was sent | +Version 0 keeps `-32070` for `plugin.toolchain.permissionDenied` and `-32071` +for `plugin.toolchain.authorityUnsupported`; all other rows are identical. A +version 0 provider using the new numbers, or a version 1 provider using the old +ones, is rejected as `plugin.toolchain.invalidReply`. The stable string codes +do not change. A relayed `plugin.function.failed` or `plugin.function.invalidResult` +error is not a toolchain error in either version: its `data.code` fails validation. + A missing installation, an incompatible version or conflicting requirements are not errors: report them in `result` (an unmet requirement has `installation:null`) and let the resolver give the reason. diff --git a/shared/plugins/reference/capabilities-and-versions.md b/shared/plugins/reference/capabilities-and-versions.md index 8c9d4a6c..2f0dfbfd 100644 --- a/shared/plugins/reference/capabilities-and-versions.md +++ b/shared/plugins/reference/capabilities-and-versions.md @@ -17,7 +17,7 @@ Core 列以本仓库 `main` 上的 Core 源码为准([`capabilities.rs`](https | 进程协议版本 `experimental.lithe*` | 不写进清单;进程启动时在 LSP `initialize` 里协商 | 宿主给出版本列表,后端从中选一个 | 该协议不启用,例如不向这个进程发构建请求 | | 文档格式版本 | 各文档自己的 `schemaVersion` 或 `version` 字段 | Core | 解析失败 | -能力版本决定**能不能安装**;协议版本决定**进程启动后能说什么**。进程协议没有独立的版本,它的版本就是拥有它的能力的版本,宿主给出的列表恰好是这一个版本。 +能力版本决定**能不能安装**;协议版本决定**进程启动后能说什么**。进程协议没有独立的版本,它的版本就是拥有它的能力的版本,宿主给出的列表来自 Core 对该能力的支持表。 以后的变化遵循契约的规则: @@ -68,7 +68,8 @@ Core 列以本仓库 `main` 上的 Core 源码为准([`capabilities.rs`](https | `backend` `0` | [`backend`](../contract/v1/README.md#plugin-backend):插件自己的长驻进程,带或不带页面启动,按权限提供宿主服务,说 `litheFunctions` | ✅ | ✅¹ | [插件后端与插件函数](domains/backend.md) | | `toolDefinitions` `0` | `toolDefinitions[]`:[工具身份、布局、发现和四层候选](../contract/v1/toolchains/README.md) | ✅ | ✅¹ | [工具链](domains/toolchains.md) | | `toolDefinitions` `1` | 在 `0` 之上加:工具定义的 `category`(设置页「工具链」里的分组)和 `audience`(`plugin` 表示插件自用的运行时,单独放在最后一组),只影响显示位置 | ✅ | 未声明 | [Settings list](../contract/v1/toolchains/README.md#settings-list) | -| `toolchainProviders` `0` | `toolchainProviders[]`:[提供者声明和按权限校验应答](../contract/v1/toolchains/README.md);说 `litheToolchains` | ✅ | 未声明 | [工具链](domains/toolchains.md) | +| `toolchainProviders` `0` | `toolchainProviders[]`:[提供者声明和按权限校验应答](../contract/v1/toolchains/README.md);说 `litheToolchains` | ✅ | ✅ | [工具链](domains/toolchains.md) | +| `toolchainProviders` `1` | 权限和 authority 错误改为独立号码 `-32080`、`-32081`,稳定字符串码不变;版本 0 保留旧码 | ✅ | 未声明 | [工具链](domains/toolchains.md) | | `pluginFunctions` `0` | 清单顶层 [`pluginFunctions`](../contract/v1/README.md#cross-plugin-calls):导出的函数(`exports`)和要调用的其他插件函数(`calls`);不授予任何清单权限,调用经 Core 中转 | ✅ | ✅¹ | [插件后端与插件函数](domains/backend.md) | | `keymapImportProviders` `0` | `keymapImportProviders[]`:[独立的快捷键导入提供者](../contract/v1/README.md#shortcut-import-providers-core-foundation);说 `litheKeymapImport` | ✅ | 未声明 | [快捷键导入](domains/keymap-import.md) | @@ -92,7 +93,7 @@ Core 列以本仓库 `main` 上的 Core 源码为准([`capabilities.rs`](https | `litheBuild` `0`(`buildProviders`) | `lithe/build/*`:模型与依赖、任务执行、测试执行与发现、运行准备、原生调试准备、只读模型输入、原生配置、内联测试报告、语义测试选择器、类型化运行选项、注册表连接调试。提供给构建提供者 | ✅ | ✅¹ | [Build providers](../contract/v1/README.md#build-providers) | | `litheBuild` `1`(`buildProviders`) | 在 `0` 之上加 `lithe/build/runEntrypoints`:按源文件找运行入口 | ✅ | ✅ | [Run entrypoints](../contract/v1/README.md#run-entrypoints-buildproviders-1) | | `litheVcs` `0`(`vcsProviders`) | VCS 提供者的能力和请求(`lithe/vcs/*`)。提供给 VCS 提供者 | ✅ | ✅¹ | [VCS providers](../contract/v1/README.md#vcs-providers) | -| `litheToolchains` `0`(`toolchainProviders`) | `toolchains/query`;后端从声明的提供者中选出子集。提供给声明了工具链提供者的插件会话 | ✅ | 未声明 | [Provider backend negotiation](../contract/v1/toolchains/README.md#provider-backend-negotiation) | +| `litheToolchains` `0`、`1`(`toolchainProviders`) | `toolchains/query`;后端从声明的提供者中选出子集。提供给声明了工具链提供者的插件会话 | ✅ | 版本 `0` | [Provider backend negotiation](../contract/v1/toolchains/README.md#provider-backend-negotiation) | | `litheKeymapImport` `0`(`keymapImportProviders`) | 后端从声明的提供者中选出要启用的子集;`lithe/keymap/import`。提供给声明了 `keymapImportProviders` 的插件会话 | ✅ | 未声明 | [Shortcut import](../contract/v1/README.md#shortcut-import-providers-core-foundation) | | `litheLogging` `0`(`pluginAPIVersion`) | 结构化诊断通知 `lithe/log`;官方 SDK 要求宿主提供它,否则拒绝初始化。提供给每个插件拥有的进程 | ✅ | ✅ | [Structured diagnostics](../contract/v1/README.md#structured-plugin-diagnostics) | @@ -135,7 +136,7 @@ The Core column follows the Core source on this repository's `main` (`SUPPORTED_ | Process protocol version `experimental.lithe*` | Not in the manifest; negotiated in LSP `initialize` when the process starts | The host offers a list, the backend picks one | The protocol is not enabled, for example no build request goes to that process | | Document format version | The document's own `schemaVersion` or `version` field | Core | Decoding fails | -A capability version decides **whether a plugin installs**; a protocol version decides **what a running process can say**. A process protocol has no version of its own: its version is that of the capability that owns it, and the host offers exactly that one version. +A capability version decides **whether a plugin installs**; a protocol version decides **what a running process can say**. A process protocol has no version of its own: its version is that of the capability that owns it, and the host's offer comes from Core's support table for that capability. Future changes follow the contract's rules: @@ -186,7 +187,8 @@ Each row is one capability. `requires` lists **exactly** the capabilities a mani | `backend` `0` | [`backend`](../contract/v1/README.md#plugin-backend): the plugin's own long-lived process, started with or without a page, serving the host services its permissions grant and speaking `litheFunctions` | ✅ | ✅¹ | [Plugin backend and plugin functions](domains/backend.md) | | `toolDefinitions` `0` | `toolDefinitions[]`: [tool identities, layouts, discovery, and four-layer candidates](../contract/v1/toolchains/README.md) | ✅ | ✅¹ | [Toolchains](domains/toolchains.md) | | `toolDefinitions` `1` | Adds to `0`: a definition's `category` (its group in the settings page's Toolchains list) and `audience` (`plugin` for a runtime a plugin runs for itself, shown in its own last group); display placement only | ✅ | Not declared | [Settings list](../contract/v1/toolchains/README.md#settings-list) | -| `toolchainProviders` `0` | `toolchainProviders[]`: [provider declarations and permission-bound answer validation](../contract/v1/toolchains/README.md); they speak `litheToolchains` | ✅ | Not declared | [Toolchains](domains/toolchains.md) | +| `toolchainProviders` `0` | `toolchainProviders[]`: [provider declarations and permission-bound answer validation](../contract/v1/toolchains/README.md); they speak `litheToolchains` | ✅ | ✅ | [Toolchains](domains/toolchains.md) | +| `toolchainProviders` `1` | Distinct permission and authority error numbers `-32080` and `-32081`, with unchanged stable string codes; version 0 retains the legacy numbers | ✅ | Not declared | [Toolchains](domains/toolchains.md) | | `pluginFunctions` `0` | The manifest's top-level [`pluginFunctions`](../contract/v1/README.md#cross-plugin-calls): the functions the plugin exports (`exports`) and the functions of other plugins it calls (`calls`); grants no manifest permission, and Core relays the calls | ✅ | ✅¹ | [Plugin backend and plugin functions](domains/backend.md) | | `keymapImportProviders` `0` | `keymapImportProviders[]`: [independent shortcut import providers](../contract/v1/README.md#shortcut-import-providers-core-foundation); they speak `litheKeymapImport` | ✅ | Not declared | [Shortcut import](domains/keymap-import.md) | @@ -210,7 +212,7 @@ These protocols are negotiated when a process starts and never appear in the man | `litheBuild` `0` (`buildProviders`) | `lithe/build/*`: model and dependencies, task execution, test execution and discovery, run preparation, native debug preparation, read-only model inputs, native configuration, inline test reports, semantic test selectors, typed run options, registry connection debugging. Offered to build providers | ✅ | ✅¹ | [Build providers](../contract/v1/README.md#build-providers) | | `litheBuild` `1` (`buildProviders`) | Adds `lithe/build/runEntrypoints` to `0`: the run entrypoints of a source file | ✅ | ✅ | [Run entrypoints](../contract/v1/README.md#run-entrypoints-buildproviders-1) | | `litheVcs` `0` (`vcsProviders`) | VCS provider capabilities and requests (`lithe/vcs/*`). Offered to VCS providers | ✅ | ✅¹ | [VCS providers](../contract/v1/README.md#vcs-providers) | -| `litheToolchains` `0` (`toolchainProviders`) | `toolchains/query`; the backend selects a subset of its declared providers. Offered to plugin sessions that declare toolchain providers | ✅ | Not declared | [Provider backend negotiation](../contract/v1/toolchains/README.md#provider-backend-negotiation) | +| `litheToolchains` `0`, `1` (`toolchainProviders`) | `toolchains/query`; the backend selects a subset of its declared providers. Offered to plugin sessions that declare toolchain providers | ✅ | Version `0` | [Provider backend negotiation](../contract/v1/toolchains/README.md#provider-backend-negotiation) | | `litheKeymapImport` `0` (`keymapImportProviders`) | The backend selects a subset of its declared providers; `lithe/keymap/import`. Offered to plugin sessions with declared `keymapImportProviders` | ✅ | Not declared | [Shortcut import](../contract/v1/README.md#shortcut-import-providers-core-foundation) | | `litheLogging` `0` (`pluginAPIVersion`) | Structured diagnostic notification `lithe/log`; the official SDKs require the host to offer it and refuse to initialize otherwise. Offered to every plugin-owned process | ✅ | ✅ | [Structured diagnostics](../contract/v1/README.md#structured-plugin-diagnostics) | diff --git a/shared/plugins/reference/domains/toolchains.md b/shared/plugins/reference/domains/toolchains.md index 38e5425a..6e6be61d 100644 --- a/shared/plugins/reference/domains/toolchains.md +++ b/shared/plugins/reference/domains/toolchains.md @@ -9,13 +9,13 @@ | 项目 | 内容 | | --- | --- | | 清单字段 | `toolDefinitions[]`(工具定义)、`toolchainProviders[]`(工具链提供者)、顶层 `requiresTools`(启动时引用的工具定义 ID) | -| 能力 | `toolDefinitions` 0(用到 `category`、`audience` 时为 1);`toolchainProviders` 0(还需要 `backend` 0) | -| 协议 | 工具链提供者协议 `litheToolchains`,版本 `0`:宿主通过 `toolchains/query` 向提供者的后端查询。协商见[契约](../../contract/v1/toolchains/README.md#provider-backend-negotiation) | +| 能力 | `toolDefinitions` 0(用到 `category`、`audience` 时为 1);`toolchainProviders` 0 或 1(还需要 `backend` 0) | +| 协议 | 工具链提供者协议 `litheToolchains`,版本 `0` 或 `1`:宿主通过 `toolchains/query` 向提供者的后端查询。协商见[契约](../../contract/v1/toolchains/README.md#provider-backend-negotiation) | | API 编号 | [API-23](../api-catalog.md#现在能用的-api):工具链与受管进程(部分完成) | | 权限 | 工具定义不需要权限;提供者需要 `backend.launch` 和 `toolchains.provide` | | 激活事件 | 不需要。提供者由宿主的第一次查询唤起,不需要页面或启动事件 | | 后端启动 | 提供者的后端只能是包内可执行文件(`packaged`),或包内运行时(`runtime` 加 `packagedRuntime`),不能依赖需要发现的运行时 | -| 桌面端 | 声明 `toolDefinitions`;未声明 `toolchainProviders`,见“桌面端现状” | +| 桌面端 | 声明 `toolDefinitions` 和 `toolchainProviders` 0;后者的版本 1 尚未声明,见“桌面端现状” | | 官方 SDK | [Rust SDK](../../sdk/rust/README.md#toolchain-providers) 提供类型化的 `toolchains/query`、能力协商和取消处理。Go、Node 和 Java 后端自行处理该协议 | ### 两条安装来源 @@ -86,15 +86,15 @@ | 身份 | JSON-RPC `id`、`operationID`、`generation`、`providerID` 必须和请求一致;数字 `1` 和字符串 `"1"` 是不同的 ID;远程 authority 一律拒绝 | | 版本要求 | `request` 的写法对 Core 不透明(例如 `lts`),宿主不解释;`installation: null` 表示要求没有被满足 | -提供者可以在 JSON-RPC 错误里使用下面的错误码,`decodeReply` 按这张表校验(一个数字只对应一个语义): +下面是版本 1 的 JSON-RPC 错误码。`decodeReply` 从重新校验的清单读取 `requires.toolchainProviders`,再校验数字与稳定字符串码。版本 0 继续使用 `-32070`(permissionDenied)、`-32071`(authorityUnsupported),其余号码相同;两个版本不能混用这两组号码。原样转发的 `plugin.function.*` 错误在两个版本里都被拒绝为 `plugin.toolchain.invalidReply`。 -| JSON-RPC | 语义码 | 含义 | +| JSON-RPC(版本 1) | 语义码 | 含义 | | --- | --- | --- | | `-32601` | `plugin.toolchain.methodUnavailable` | 查询方法或能力没有协商 | | `-32602` | `plugin.toolchain.invalidParams` | 请求格式错误或声明的输入无效 | | `-32800` | `plugin.toolchain.cancelled` | 调用方取消了请求 | -| `-32070` | `plugin.toolchain.permissionDenied` | 缺少权限、审查或启用状态 | -| `-32071` | `plugin.toolchain.authorityUnsupported` | 没有这个 authority 的适配器 | +| `-32080` | `plugin.toolchain.permissionDenied` | 缺少权限、审查或启用状态 | +| `-32081` | `plugin.toolchain.authorityUnsupported` | 没有这个 authority 的适配器 | | `-32072` | `plugin.toolchain.timeout` | 超过本地截止时间 | | `-32073` | `plugin.toolchain.providerUnavailable` | 后端启动失败、断开或上游查询失败 | | `-32074` | `plugin.toolchain.invalidReply` | 应答格式错误,或安装引用了别的工具 | @@ -149,7 +149,7 @@ Core 的 `plugins.managedRuntimes.plan` 选择准确平台并生成缓存键,` | 用途 | Lithe 桌面端 | | --- | --- | | 工具定义(`toolDefinitions`) | 已声明(macOS、Windows、Linux)。设置页发现、项目环境信任、目录固定保存,以及构建、运行、调试、语言服务器和新建项目选择工具,都通过共享 Core 解析器完成 | -| 工具链提供者(`toolchainProviders`) | 未声明。提供者查询路线不可用,需要它的插件不会被提供安装 | +| 工具链提供者(`toolchainProviders`) | 已声明 `0`,按需通过共享插件后端查询,并由 Core 校验原始应答与本机文件系统事实;版本 `1` 尚未声明 | | 安装缺失的命令(`commandInstallers`) | 已声明 `0`。插件管理页展示工具、命令行、网络与目标目录,用户确认后安装到受管目录或工具默认目录;下载安装(`1`)由配套宿主接入后声明 | | 语言服务器的 `{kind: "tool"}` 启动 | 按工作区工具链四层选择解析后启动(见[语言](languages.md)) | | `toolchainConsumers`、提供者热激活 | 契约尚未提供 | @@ -201,13 +201,13 @@ A plugin can tell Lithe what a tool (a JDK, Maven, Node, Go and so on) looks lik | Item | Value | | --- | --- | | Manifest fields | `toolDefinitions[]`, `toolchainProviders[]`, and the top-level `requiresTools` (tool-definition IDs that launches reference) | -| Capabilities | `toolDefinitions` 0; `toolchainProviders` 0 (also needs `backend` 0) | -| Protocol | The toolchain provider protocol `litheToolchains`, version `0`: the host queries the provider's backend with `toolchains/query`. Negotiation is in the [contract](../../contract/v1/toolchains/README.md#provider-backend-negotiation) | +| Capabilities | `toolDefinitions` 0; `toolchainProviders` 0 or 1 (also needs `backend` 0) | +| Protocol | The toolchain provider protocol `litheToolchains`, version `0` or `1`: the host queries the provider's backend with `toolchains/query`. Negotiation is in the [contract](../../contract/v1/toolchains/README.md#provider-backend-negotiation) | | API IDs | [API-23](../api-catalog.md#apis-usable-now): toolchains and managed processes (partly complete) | | Permissions | None for definitions; a provider needs `backend.launch` and `toolchains.provide` | | Activation | None needed. The host's first query starts a provider; no page or startup event is needed | | Backend launch | The provider's backend must be `packaged`, or `runtime` with `packagedRuntime`, and must not depend on a discovered runtime | -| Desktop | Declares `toolDefinitions`; does not declare `toolchainProviders`. See "Desktop status" | +| Desktop | Declares `toolDefinitions` and `toolchainProviders` 0; version 1 of the latter is not declared yet. See "Desktop status" | | Official SDKs | The [Rust SDK](../../sdk/rust/README.md#toolchain-providers) handles typed `toolchains/query`, negotiation, and cancellation. Go, Node, and Java backends handle the protocol directly | ### Two installation routes @@ -278,15 +278,15 @@ Every command accepts UTF-8 JSON, has a 4 MiB input budget, and performs no nati | Identity | The JSON-RPC `id`, `operationID`, `generation`, and `providerID` must match the request. The number `1` and the string `"1"` are different IDs. Remote authorities are always refused | | Version requirements | `request` is opaque to Core (for example `lts`) and the host does not interpret it. `installation: null` means the requirement is unmet | -A provider may use these codes in its JSON-RPC errors; `decodeReply` validates against this table, and each number has one meaning: +These are the version 1 JSON-RPC error numbers. `decodeReply` reads `requires.toolchainProviders` from the revalidated manifest before checking the number and stable code. Version 0 retains `-32070` (permissionDenied) and `-32071` (authorityUnsupported); the other numbers are identical. A provider cannot mix the two versions' numbers. Forwarded `plugin.function.*` errors are rejected as `plugin.toolchain.invalidReply` in both versions. -| JSON-RPC | Semantic code | Meaning | +| JSON-RPC (version 1) | Semantic code | Meaning | | --- | --- | --- | | `-32601` | `plugin.toolchain.methodUnavailable` | The query method or capability was not negotiated | | `-32602` | `plugin.toolchain.invalidParams` | Malformed request or invalid declared input | | `-32800` | `plugin.toolchain.cancelled` | The caller cancelled the request | -| `-32070` | `plugin.toolchain.permissionDenied` | A permission, review, or enabled-state prerequisite is missing | -| `-32071` | `plugin.toolchain.authorityUnsupported` | The provider has no adapter for this authority | +| `-32080` | `plugin.toolchain.permissionDenied` | A permission, review, or enabled-state prerequisite is missing | +| `-32081` | `plugin.toolchain.authorityUnsupported` | The provider has no adapter for this authority | | `-32072` | `plugin.toolchain.timeout` | The local deadline passed | | `-32073` | `plugin.toolchain.providerUnavailable` | The backend failed to start or disconnected, or its upstream query failed | | `-32074` | `plugin.toolchain.invalidReply` | Malformed reply, or an installation refers to another tool | @@ -341,7 +341,7 @@ Core's `plugins.managedRuntimes.plan` selects the exact platform and generates c | Use | Lithe desktop | | --- | --- | | Tool definitions (`toolDefinitions`) | Declared (macOS, Windows, and Linux). Settings discovery, workspace project-environment trust, saving pins, and Build, Run, Debug, language-server, and project-generator tool selection all go through the shared Core resolver | -| Toolchain providers (`toolchainProviders`) | Not declared. The provider query route is unavailable, and a plugin that needs it is not offered for installation | +| Toolchain providers (`toolchainProviders`) | Declares `0`: queries the shared plugin backend on demand and passes raw replies and native filesystem facts to Core for validation; version `1` is not declared yet | | Installing missing commands (`commandInstallers`) | `0` declared. Plugin management displays the tool, command line, network use, and target directory, and installs into the managed directory or tool default directory after user confirmation; download installers (`1`) are declared with companion host integration | | Language server `{kind: "tool"}` launch | Resolved through the workspace's four toolchain layers and started (see [Languages](languages.md)) | | `toolchainConsumers`, live provider activation | Not provided by the contract yet | diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index c9ab575c..1e731f9e 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -14,6 +14,7 @@ ## 待合入 +- 本 PR(关联 [1lck/Lithe-IDEA#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)),`lithe-support[bot]`,**`toolchainProviders` 1 / `litheToolchains` 1**(API-23):权限和 authority 错误改用 `-32080`、`-32081`,稳定字符串码不变。Core 按重新校验的清单版本解码;版本 0 保留 `-32070`、`-32071`,不同版本的号码互不接受。Rust SDK 保留版本 0 默认语义,通过 `Backend::toolchain_provider_version(ToolchainProviderVersion::V1)` 显式选择新版本;没有匹配的协商版本就不启用提供者。四个 SDK 的 `plugin.function.*` 号码不变。 - [#176](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/176),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`languageServers` 0 内的说明补充(—):写明后端决定启动方式的语言服务器在 `immediate` 设置变化时的行为。启动应答自带 `workspaceConfiguration` 时,宿主用这次启动的四个目录、工作区 `context` 和新的 `settings` 再调用一次启动函数,同样交给 `plugins.languageServers.decodeLaunch` 解码,只把计划里的 `workspaceConfiguration` 通过 `lsp.updateWorkspaceConfiguration` 发出(整体替换原配置),应答的其余部分等下次启动;应答不带时发送声明的展开,不再调用函数。所以这类启动函数每次启动可能被调用多次,安装或下载只应在缺少时进行。契约 README 的 Workspace configuration 和 Backend-resolved launch 两节、`reference/domains/languages.md` 与 `settings.md` 的中英文随之补充。桌面端实现见 1lck/Lithe-IDEA#2319。Core 代码、能力版本、宿主方法、通知和协议字段都不变。 - [#175](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/175),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`ui` 0 内的补充(API-13、API-23):撤回 #174 新增的 `ui` 1,设置区域 `tool` 行的可选布尔字段 `choose` 改为 `ui` 0 内的补充,清单写 `requires.ui: 0` 即可使用。`capabilities.rs` 和清单 schema 的 `requires.ui` 回到只有 0,能力对照表删去 `ui` 1 一行。`choose` 不是布尔值时 Core 以 `plugin.ui.invalidView` 拒绝整个结果,位置指向 `choose`;旧宿主的 Core 不认识这个字段,同样会拒绝带它的视图,所以插件要等包含本改动的桌面端发布后再写。fixture `ui/view-results.json` 改为两个用例(接受选择器、`choose` 不是布尔值时拒绝),替换原来“`requires.ui` 为 0 时拒绝”的用例。`ui` 1 没有随任何宿主发布过。没有新增能力版本、宿主方法、通知或进程协议字段。 - [#174](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/174),[@xiaoyumuxi](https://github.com/xiaoyumuxi),**`ui` 1**(API-13、API-23):设置区域视图的 `tool` 行新增可选的布尔字段 `choose`,带上后这一行同时是该工具的选择器,像解释器下拉框一样列出自动选择、已发现和已添加的安装(带版本和来源)、添加目录和打开工具链页的入口;选择只改设置窗口的草稿,“应用”提交、“取消”丢弃,行上显示待提交的选择,应用后启动和运行拿到选中的安装。清单 `requires.ui` 为 0 时 Core 以 `plugin.ui.invalidView` 拒绝整个结果,位置指向 `choose`。契约 README 的插件视图一节补充:为某个工作区显示的视图(项目窗口里的工具窗口,或从项目窗口打开的设置页)调用时,带上该窗口的工作区上下文作为 invoke 的 `params.context`,后端可以在 `click` 里用它调用 `run/start` 等需要上下文的宿主方法;没有工作区时不带。fixture `ui/view-results.json` 新增一个用例,Node SDK 的视图节点类型加上 `choose`,Rust 和 Go SDK 的工作区上下文说明随之修正。没有新增宿主方法、通知或进程协议字段。(`ui` 1 已由 #175 撤回,`choose` 改为 `ui` 0 内的补充。) @@ -76,6 +77,7 @@ | `toolDefinitions` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | `toolDefinitions` | 1 | 2026-11-18 | [#99](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/99) | | `toolchainProviders` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | +| `toolchainProviders` | 1 | 待合入 | 本 PR([#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)) | | `ui` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | `vcsProviders` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | @@ -90,6 +92,7 @@ | `litheBuild`(`buildProviders`) | 1 | 2026-11-18 | [#89](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/89) | | `litheVcs`(`vcsProviders`) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | `litheToolchains`(`toolchainProviders`) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | +| `litheToolchains`(`toolchainProviders`) | 1 | 待合入 | 本 PR([#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)) | | `litheKeymapImport`(`keymapImportProviders`) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | `litheLogging`(`pluginAPIVersion`) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | diff --git a/shared/plugins/sdk/e2e/plugin_sdk/toolchains.rs b/shared/plugins/sdk/e2e/plugin_sdk/toolchains.rs index 0821b018..e8089309 100644 --- a/shared/plugins/sdk/e2e/plugin_sdk/toolchains.rs +++ b/shared/plugins/sdk/e2e/plugin_sdk/toolchains.rs @@ -14,10 +14,10 @@ pub fn run(executable: &str) { let manifest = json!({ "schemaVersion": 0, "pluginAPIVersion": 0, "id": plugin_id, "displayName": "SDK toolchain fixture", "version": "1.0.0", - "requires": {"backend": 0, "toolchainProviders": 0}, + "requires": {"backend": 0, "toolchainProviders": 1}, "vendor": {"id": "org.example", "displayName": "Fixture publisher", "signatureRequirement": "publisherPackage"}, "permissions": ["backend.launch", "toolchains.provide"], - "toolchainProviders": [{"id": "fixture", "displayName": "SDK fixture", "tools": ["fixture-runtime"]}], + "toolchainProviders": [{"id": "fixture", "displayName": "SDK fixture", "tools": ["fixture-denied", "fixture-runtime"]}], "backend": {"launch": {"kind": "packaged", "path": "bin/sample-backend"}, "arguments": ["--state", "${stateDir}"]}, }); let registry = json!({"plugins": [{"manifest": manifest}]}); @@ -27,6 +27,7 @@ pub fn run(executable: &str) { validated["registry"]["providers"][0]["provider"]["id"], "fixture" ); + assert_eq!(validated["registry"]["providers"][0]["version"], 1); let started = core( "lsp.startServer", json!({ @@ -69,7 +70,7 @@ pub fn run(executable: &str) { let decoded = core( "toolchains.decodeReply", json!({ - "registry": registry, "pluginID": plugin_id, "currentGeneration": 3, + "registry": registry.clone(), "pluginID": plugin_id, "currentGeneration": 3, "request": {"jsonrpc": "2.0", "id": wire["id"], "method": "toolchains/query", "params": params}, "response": wire["response"], "platform": "macos", "filesystem": [], }), @@ -78,5 +79,34 @@ pub fn run(executable: &str) { assert_eq!(decoded["snapshot"]["installations"], json!([])); assert_eq!(decoded["snapshot"]["statements"], json!([])); assert_eq!(decoded["snapshot"]["watch"], json!([])); + + let denied_operation = "sdk-toolchain-denied"; + let mut denied_params = params; + denied_params["operationID"] = json!(denied_operation); + denied_params["tools"] = json!(["fixture-denied"]); + core( + "lsp.toolchainRequest", + json!({ + "sessionId": session.id, "operationId": denied_operation, "params": denied_params, + "timeoutMilliseconds": 5000, + }), + ); + let denied = session.completion(denied_operation); + assert!(denied.get("error").is_none(), "{denied}"); + let wire = &denied["result"]["value"]; + assert_eq!(wire["response"]["error"]["code"], -32080); + let decoded = core( + "toolchains.decodeReply", + json!({ + "registry": registry, "pluginID": plugin_id, "currentGeneration": 3, + "request": {"jsonrpc": "2.0", "id": wire["id"], "method": "toolchains/query", "params": denied_params}, + "response": wire["response"], "platform": "macos", "filesystem": [], + }), + ); + assert_eq!(decoded["status"], "rejected", "{decoded}"); + assert_eq!( + decoded["error"]["code"], + "plugin.toolchain.permissionDenied" + ); session.stop(); } diff --git a/shared/plugins/sdk/rust/README.md b/shared/plugins/sdk/rust/README.md index 02f759f2..daf242c6 100644 --- a/shared/plugins/sdk/rust/README.md +++ b/shared/plugins/sdk/rust/README.md @@ -135,12 +135,17 @@ Declare the same provider ID in the manifest's [`toolchainProviders`](../../contract/v1/toolchains/README.md#provider-backend-negotiation) and via `Backend::toolchain_provider`. The host offers the IDs it recognizes at initialization. The SDK selects registered IDs in the offer and routes each -query to that handler: +query to that handler. Existing code defaults to version 0. To use +`requires.toolchainProviders: 1`, explicitly select the same version before +listening; upgrading the SDK alone never changes a provider's protocol: ```rust -use lithe_plugin_sdk::{toolchains::ToolchainQueryResult, Backend}; +use lithe_plugin_sdk::{ + toolchains::{ToolchainProviderVersion, ToolchainQueryResult}, Backend, +}; -let mut backend = Backend::new("version-manager"); +let mut backend = Backend::new("version-manager") + .toolchain_provider_version(ToolchainProviderVersion::V1); backend.toolchain_provider("manager", |_query, cancellation| { cancellation.check()?; // Read this manager's own data for query.tools and query.workspace. @@ -148,6 +153,11 @@ backend.toolchain_provider("manager", |_query, cancellation| { }).expect("valid provider ID"); ``` +The SDK negotiates only the configured version: version 1 does not silently +fall back to version 0 on an older host. Version 1 encodes `PermissionDenied` +as `-32080` and `AuthorityUnsupported` as `-32081`; version 0 retains `-32070` +and `-32071`. All stable string codes and other error numbers are unchanged. + Handlers return installations, version statements and watch paths. An empty result is valid. Set a statement's `installation` to `None` for an unmet requirement. Use `ToolchainQueryError` for a query failure and check the diff --git a/shared/plugins/sdk/rust/examples/sample-backend/src/main.rs b/shared/plugins/sdk/rust/examples/sample-backend/src/main.rs index 1e132db9..0d19b199 100644 --- a/shared/plugins/sdk/rust/examples/sample-backend/src/main.rs +++ b/shared/plugins/sdk/rust/examples/sample-backend/src/main.rs @@ -13,7 +13,9 @@ //! (`files.nextChange`), answers its command with a message in the window //! it ran in, and lists the open workspaces when they change. -use lithe_plugin_sdk::toolchains::{ToolchainQueryError, ToolchainQueryResult}; +use lithe_plugin_sdk::toolchains::{ + ToolchainProviderVersion, ToolchainQueryError, ToolchainQueryResult, +}; use lithe_plugin_sdk::{ BackendHandle, Cancelled, Context, FunctionError, PluginError, SdkError, Value, }; @@ -36,8 +38,9 @@ fn main() { std::process::exit(2); } }; - let mut backend = - lithe_plugin_sdk::Backend::new("sample-backend").version(env!("CARGO_PKG_VERSION")); + let mut backend = lithe_plugin_sdk::Backend::new("sample-backend") + .version(env!("CARGO_PKG_VERSION")) + .toolchain_provider_version(ToolchainProviderVersion::V1); // Exercised only when the Core end-to-end harness offers this provider. backend.keymap_import_provider("fixture", |snapshot, context| { @@ -50,6 +53,9 @@ fn main() { backend .toolchain_provider("fixture", |query, cancellation| { cancellation.check()?; + if query.tools == ["fixture-denied"] { + return Err(ToolchainQueryError::PermissionDenied); + } if query.tools != ["fixture-runtime"] { return Err(ToolchainQueryError::InvalidParams); } diff --git a/shared/plugins/sdk/rust/plugin-sdk/src/backend.rs b/shared/plugins/sdk/rust/plugin-sdk/src/backend.rs index 7b3e5ec7..46995599 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/src/backend.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/src/backend.rs @@ -74,6 +74,8 @@ pub(crate) struct State { selected_keymap_providers: BTreeSet, toolchain_providers: BTreeMap, selected_toolchain_providers: BTreeSet, + /// The manifest's toolchain capability version; never upgraded by an offer. + toolchain_provider_version: toolchains::ToolchainProviderVersion, /// Build-provider handlers, by wire method. build_handlers: BTreeMap<&'static str, BuildHandler>, /// The negotiated `litheBuild` version, when the backend has build @@ -170,6 +172,7 @@ impl Backend { selected_keymap_providers: BTreeSet::new(), toolchain_providers: BTreeMap::new(), selected_toolchain_providers: BTreeSet::new(), + toolchain_provider_version: toolchains::ToolchainProviderVersion::V0, build_handlers: BTreeMap::new(), build_version: None, logging: false, @@ -291,6 +294,15 @@ impl Backend { Ok(self) } + /// Selects the manifest's `requires.toolchainProviders` version before listening. + /// The default is [`toolchains::ToolchainProviderVersion::V0`]. A backend only + /// negotiates this version; it does not downgrade or upgrade its error codes + /// when a host offers a different version. + pub fn toolchain_provider_version(self, version: toolchains::ToolchainProviderVersion) -> Self { + lock(&self.shared.state).toolchain_provider_version = version; + self + } + /// Registers a provider ID declared in the plugin manifest. The handler /// receives typed inputs and a cancellation token. The SDK echoes the /// query identity in the reply, while Core validates the returned facts. @@ -785,8 +797,8 @@ impl Backend { } } } - if let Some(offer) = - toolchain_offer.filter(|offer| offers(Some(offer), toolchains::VERSION)) + if let Some(offer) = toolchain_offer + .filter(|offer| offers(Some(offer), state.toolchain_provider_version.number())) { if let Some(providers) = offer["providers"] .as_array() @@ -801,7 +813,7 @@ impl Backend { if !state.selected_toolchain_providers.is_empty() { experimental.insert( toolchains::CAPABILITY.into(), - json!({"version": toolchains::VERSION, "providers": state.selected_toolchain_providers}), + json!({"version": state.toolchain_provider_version.number(), "providers": state.selected_toolchain_providers}), ); } } @@ -1062,6 +1074,7 @@ impl Shared { } fn invoke_toolchain(shared: &Arc, id: Value, params: Value) { + let version = lock(&shared.state).toolchain_provider_version; let query = match ToolchainQuery::parse(¶ms) { Ok(query) => query, Err(error) => { @@ -1070,6 +1083,7 @@ impl Shared { Err(error.response( params["operationID"].as_str().unwrap_or_default(), params["providerID"].as_str().unwrap_or_default(), + version, )), ); } @@ -1113,7 +1127,7 @@ impl Shared { Err(error) => { return shared.respond( &id, - Err(error.response(&query.operation_id, &query.provider_id)), + Err(error.response(&query.operation_id, &query.provider_id, version)), ) } }; @@ -1149,7 +1163,7 @@ impl Shared { Ok(response) => worker.write(&response), Err(error) => worker.respond( &thread_id, - Err(error.response(&query.operation_id, &query.provider_id)), + Err(error.response(&query.operation_id, &query.provider_id, version)), ), } }); @@ -1157,7 +1171,8 @@ impl Shared { lock(&shared.state).incoming.remove(&key); shared.respond( &id, - Err(ToolchainQueryError::ProviderUnavailable.response(&operation, &provider)), + Err(ToolchainQueryError::ProviderUnavailable + .response(&operation, &provider, version)), ); } } diff --git a/shared/plugins/sdk/rust/plugin-sdk/src/toolchains.rs b/shared/plugins/sdk/rust/plugin-sdk/src/toolchains.rs index 28169cca..16cd0893 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/src/toolchains.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/src/toolchains.rs @@ -1,4 +1,4 @@ -//! Typed handler inputs and outputs for the version 0 toolchain provider protocol. +//! Typed handler inputs and outputs for the versioned toolchain provider protocol. use crate::Cancelled; use serde::{Deserialize, Serialize}; @@ -6,7 +6,6 @@ use serde_json::{json, Value}; pub(crate) const METHOD: &str = "toolchains/query"; pub(crate) const CAPABILITY: &str = "litheToolchains"; -pub(crate) const VERSION: u64 = 0; pub(crate) const MAX_PROVIDERS: usize = 8; pub(crate) const MAX_RUNNING_QUERIES: usize = 8; pub(crate) const MAX_REPLY_BYTES: usize = 1024 * 1024; @@ -14,6 +13,26 @@ const MAX_INSTALLATIONS: usize = 512; const MAX_STATEMENTS: usize = 256; const MAX_WATCH_PATHS: usize = 256; +/// The `requires.toolchainProviders` version declared by this backend's manifest. +/// Version 0 remains the default so upgrading the SDK does not change a plugin's +/// protocol. Version 1 separates toolchain failures from relayed function errors. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum ToolchainProviderVersion { + /// The published protocol, including the legacy -32070/-32071 errors. + V0, + /// The same query protocol with permission/authority errors -32080/-32081. + V1, +} + +impl ToolchainProviderVersion { + pub(crate) fn number(self) -> u64 { + match self { + Self::V0 => 0, + Self::V1 => 1, + } + } +} + /// A query routed to a provider selected during initialization. #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] @@ -125,7 +144,12 @@ impl From for ToolchainQueryError { } impl ToolchainQueryError { - pub(crate) fn response(self, operation: &str, provider: &str) -> Value { + pub(crate) fn response( + self, + operation: &str, + provider: &str, + version: ToolchainProviderVersion, + ) -> Value { let (number, code, message) = match self { Self::MethodUnavailable => ( -32601, @@ -139,12 +163,18 @@ impl ToolchainQueryError { ), Self::Cancelled => (-32800, "cancelled", "The toolchain query was cancelled."), Self::PermissionDenied => ( - -32070, + match version { + ToolchainProviderVersion::V0 => -32070, + ToolchainProviderVersion::V1 => -32080, + }, "permissionDenied", "The toolchain query was not permitted.", ), Self::AuthorityUnsupported => ( - -32071, + match version { + ToolchainProviderVersion::V0 => -32071, + ToolchainProviderVersion::V1 => -32081, + }, "authorityUnsupported", "The provider accepts only local queries.", ), diff --git a/shared/plugins/sdk/rust/plugin-sdk/tests/toolchains.rs b/shared/plugins/sdk/rust/plugin-sdk/tests/toolchains.rs index dc23c29a..c6e93fb7 100644 --- a/shared/plugins/sdk/rust/plugin-sdk/tests/toolchains.rs +++ b/shared/plugins/sdk/rust/plugin-sdk/tests/toolchains.rs @@ -4,7 +4,7 @@ mod common; use common::Host; use lithe_plugin_sdk::toolchains::{ - ToolchainInstallation, ToolchainQueryError, ToolchainQueryResult, + ToolchainInstallation, ToolchainProviderVersion, ToolchainQueryError, ToolchainQueryResult, }; use lithe_plugin_sdk::Backend; use serde_json::{json, Value}; @@ -20,12 +20,16 @@ fn query(provider: &str) -> Value { } fn initialize(host: &mut Host, providers: Value, version: u64) -> Value { + initialize_versions(host, providers, json!([version])) +} + +fn initialize_versions(host: &mut Host, providers: Value, versions: Value) -> Value { host.request( 0, "initialize", json!({"capabilities": {"experimental": { "litheLogging": {"versions": [0]}, - "litheToolchains": {"versions": [version], "providers": providers} + "litheToolchains": {"versions": versions, "providers": providers} }}}), ); host.answer(0).0["result"]["capabilities"]["experimental"]["litheToolchains"].clone() @@ -141,6 +145,65 @@ fn declines_an_unoffered_protocol_version() { finish(host); } +#[test] +fn version_one_requires_an_explicit_choice_and_keeps_legacy_sources_compatible() { + // The first case deliberately uses the old constructor: recompiling a + // version-0 provider with a newer SDK must not change its wire protocol. + for (configured, version, permission, authority) in [ + (None, 0, -32070, -32071), + (Some(ToolchainProviderVersion::V0), 0, -32070, -32071), + (Some(ToolchainProviderVersion::V1), 1, -32080, -32081), + ] { + let mut backend = Backend::new("test-backend"); + if let Some(configured) = configured { + backend = backend.toolchain_provider_version(configured); + } + backend + .toolchain_provider("fixture", |_, _| Err(ToolchainQueryError::PermissionDenied)) + .unwrap(); + let mut host = Host::start(backend); + assert_eq!( + initialize_versions(&mut host, json!(["fixture"]), json!([0, 1])), + json!({"version": version, "providers": ["fixture"]}) + ); + host.request("denied", "toolchains/query", query("fixture")); + let denied = host.answer("denied").0; + assert_eq!(denied["error"]["code"], permission); + assert_eq!( + denied["error"]["data"], + json!({ + "code": "plugin.toolchain.permissionDenied", "operationID": "query-1", "providerID": "fixture" + }) + ); + let mut remote = query("fixture"); + remote["authority"] = json!({"kind": "remote", "id": "remote-1"}); + host.request("remote", "toolchains/query", remote); + let unsupported = host.answer("remote").0; + assert_eq!(unsupported["error"]["code"], authority); + assert_eq!( + unsupported["error"]["data"], + json!({ + "code": "plugin.toolchain.authorityUnsupported", "operationID": "query-1", "providerID": "fixture" + }) + ); + finish(host); + } +} + +#[test] +fn version_one_does_not_downgrade_when_only_legacy_is_offered() { + let mut backend = + Backend::new("test-backend").toolchain_provider_version(ToolchainProviderVersion::V1); + backend + .toolchain_provider("fixture", |_, _| panic!("unnegotiated handler ran")) + .unwrap(); + let mut host = Host::start(backend); + assert!(initialize(&mut host, json!(["fixture"]), 0).is_null()); + host.request(1, "toolchains/query", query("fixture")); + assert_eq!(host.answer(1).0["error"]["code"], -32601); + finish(host); +} + #[test] fn cancellation_returns_the_protocol_error_with_the_original_identity() { let mut backend = Backend::new("test-backend"); From 07afd011bbe7ed7b645d8b74c97dbf12527f09d3 Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 07:05:13 +0000 Subject: [PATCH 2/2] docs(plugins): link versioned toolchain errors to PR 182 --- shared/plugins/reference/protocol-changelog.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index 1e731f9e..b2eddc6e 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -14,7 +14,7 @@ ## 待合入 -- 本 PR(关联 [1lck/Lithe-IDEA#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)),`lithe-support[bot]`,**`toolchainProviders` 1 / `litheToolchains` 1**(API-23):权限和 authority 错误改用 `-32080`、`-32081`,稳定字符串码不变。Core 按重新校验的清单版本解码;版本 0 保留 `-32070`、`-32071`,不同版本的号码互不接受。Rust SDK 保留版本 0 默认语义,通过 `Backend::toolchain_provider_version(ToolchainProviderVersion::V1)` 显式选择新版本;没有匹配的协商版本就不启用提供者。四个 SDK 的 `plugin.function.*` 号码不变。 +- [#182](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/182)(关联 [1lck/Lithe-IDEA#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)),`lithe-support[bot]`,**`toolchainProviders` 1 / `litheToolchains` 1**(API-23):权限和 authority 错误改用 `-32080`、`-32081`,稳定字符串码不变。Core 按重新校验的清单版本解码;版本 0 保留 `-32070`、`-32071`,不同版本的号码互不接受。Rust SDK 保留版本 0 默认语义,通过 `Backend::toolchain_provider_version(ToolchainProviderVersion::V1)` 显式选择新版本;没有匹配的协商版本就不启用提供者。四个 SDK 的 `plugin.function.*` 号码不变。 - [#176](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/176),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`languageServers` 0 内的说明补充(—):写明后端决定启动方式的语言服务器在 `immediate` 设置变化时的行为。启动应答自带 `workspaceConfiguration` 时,宿主用这次启动的四个目录、工作区 `context` 和新的 `settings` 再调用一次启动函数,同样交给 `plugins.languageServers.decodeLaunch` 解码,只把计划里的 `workspaceConfiguration` 通过 `lsp.updateWorkspaceConfiguration` 发出(整体替换原配置),应答的其余部分等下次启动;应答不带时发送声明的展开,不再调用函数。所以这类启动函数每次启动可能被调用多次,安装或下载只应在缺少时进行。契约 README 的 Workspace configuration 和 Backend-resolved launch 两节、`reference/domains/languages.md` 与 `settings.md` 的中英文随之补充。桌面端实现见 1lck/Lithe-IDEA#2319。Core 代码、能力版本、宿主方法、通知和协议字段都不变。 - [#175](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/175),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`ui` 0 内的补充(API-13、API-23):撤回 #174 新增的 `ui` 1,设置区域 `tool` 行的可选布尔字段 `choose` 改为 `ui` 0 内的补充,清单写 `requires.ui: 0` 即可使用。`capabilities.rs` 和清单 schema 的 `requires.ui` 回到只有 0,能力对照表删去 `ui` 1 一行。`choose` 不是布尔值时 Core 以 `plugin.ui.invalidView` 拒绝整个结果,位置指向 `choose`;旧宿主的 Core 不认识这个字段,同样会拒绝带它的视图,所以插件要等包含本改动的桌面端发布后再写。fixture `ui/view-results.json` 改为两个用例(接受选择器、`choose` 不是布尔值时拒绝),替换原来“`requires.ui` 为 0 时拒绝”的用例。`ui` 1 没有随任何宿主发布过。没有新增能力版本、宿主方法、通知或进程协议字段。 - [#174](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/174),[@xiaoyumuxi](https://github.com/xiaoyumuxi),**`ui` 1**(API-13、API-23):设置区域视图的 `tool` 行新增可选的布尔字段 `choose`,带上后这一行同时是该工具的选择器,像解释器下拉框一样列出自动选择、已发现和已添加的安装(带版本和来源)、添加目录和打开工具链页的入口;选择只改设置窗口的草稿,“应用”提交、“取消”丢弃,行上显示待提交的选择,应用后启动和运行拿到选中的安装。清单 `requires.ui` 为 0 时 Core 以 `plugin.ui.invalidView` 拒绝整个结果,位置指向 `choose`。契约 README 的插件视图一节补充:为某个工作区显示的视图(项目窗口里的工具窗口,或从项目窗口打开的设置页)调用时,带上该窗口的工作区上下文作为 invoke 的 `params.context`,后端可以在 `click` 里用它调用 `run/start` 等需要上下文的宿主方法;没有工作区时不带。fixture `ui/view-results.json` 新增一个用例,Node SDK 的视图节点类型加上 `choose`,Rust 和 Go SDK 的工作区上下文说明随之修正。没有新增宿主方法、通知或进程协议字段。(`ui` 1 已由 #175 撤回,`choose` 改为 `ui` 0 内的补充。) @@ -77,7 +77,7 @@ | `toolDefinitions` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | `toolDefinitions` | 1 | 2026-11-18 | [#99](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/99) | | `toolchainProviders` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| `toolchainProviders` | 1 | 待合入 | 本 PR([#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)) | +| `toolchainProviders` | 1 | 待合入 | [#182](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/182)([#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)) | | `ui` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | `vcsProviders` | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | @@ -92,7 +92,7 @@ | `litheBuild`(`buildProviders`) | 1 | 2026-11-18 | [#89](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/89) | | `litheVcs`(`vcsProviders`) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | `litheToolchains`(`toolchainProviders`) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | -| `litheToolchains`(`toolchainProviders`) | 1 | 待合入 | 本 PR([#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)) | +| `litheToolchains`(`toolchainProviders`) | 1 | 待合入 | [#182](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/182)([#2260](https://github.com/1lck/Lithe-IDEA/issues/2260)) | | `litheKeymapImport`(`keymapImportProviders`) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) | | `litheLogging`(`pluginAPIVersion`) | 0 | 2026-11-11 | [#17](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/17) |