From 6a9bf2bfbee45f61150044dfa7af8e5e7f165381 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 15 Nov 2026 14:09:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(toolchain):=20=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=9A=84=E7=89=88=E6=9C=AC=E6=8E=A2=E9=92=88?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=94=A8=E5=AD=90=E5=91=BD=E4=BB=A4=E5=BC=80?= =?UTF-8?q?=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Go 只能用 go version 打印版本,原来的校验要求每个探针参数都是选项, 工具定义写不出 Go。现在第一个参数可以是子命令,之后的参数仍然只能是选项, 探针仍然不能把脚本或文件交给工具。 --- .../core/src/tests/toolchain_definitions.rs | 33 +++++++++++++++++ rust/crates/toolchain/src/definitions.rs | 35 +++++++++++++++---- .../contract/v1/plugin-manifest.schema.json | 9 +++++ .../plugins/contract/v1/toolchains/README.md | 9 +++++ .../plugins/reference/domains/toolchains.md | 4 +++ 5 files changed, 83 insertions(+), 7 deletions(-) diff --git a/rust/crates/core/src/tests/toolchain_definitions.rs b/rust/crates/core/src/tests/toolchain_definitions.rs index 4154252d..4d99ba11 100644 --- a/rust/crates/core/src/tests/toolchain_definitions.rs +++ b/rust/crates/core/src/tests/toolchain_definitions.rs @@ -187,6 +187,39 @@ fn definition_nested_objects_fail_closed_and_enforce_safe_exports() { } } +// A tool that prints its version only for a subcommand, such as `go version`, +// is probed with that subcommand first; every later argument stays a flag, so a +// probe cannot hand the tool an operand to run. +#[test] +fn a_version_probe_may_lead_with_a_subcommand_followed_only_by_flags() { + let plugin = "dev.lithe.fixture.compiler"; + let base = definition(&format!("{plugin}:compiler")); + for (arguments, accepted) in [ + (json!(["version"]), true), + (json!(["version", "--json"]), true), + (json!(["-version"]), true), + (json!(["--version", "-v"]), true), + (json!(["version", "script"]), false), + (json!(["--version", "run"]), false), + (json!(["-c", "script"]), false), + (json!(["./version"]), false), + (json!(["version=1"]), false), + ] { + let mut changed = base.clone(); + changed["version"]["arguments"] = arguments.clone(); + assert_eq!( + validate_declarations(plugin, &[changed.clone()], &[]).is_ok(), + accepted, + "{arguments}" + ); + assert_eq!( + validate_manifest_value(manifest(plugin, changed)).is_ok(), + accepted, + "{arguments}" + ); + } +} + #[test] fn definition_metadata_cannot_disagree_with_executable_plan_or_cross_layers() { let base = definition("dev.lithe.fixture.compiler:compiler"); diff --git a/rust/crates/toolchain/src/definitions.rs b/rust/crates/toolchain/src/definitions.rs index 72071af1..6638e2a9 100644 --- a/rust/crates/toolchain/src/definitions.rs +++ b/rust/crates/toolchain/src/definitions.rs @@ -125,6 +125,20 @@ fn strings( Ok(()) } +/// A word of a version probe: a subcommand, or the name of a flag. +fn probe_word(word: &str) -> bool { + word.as_bytes().first().is_some_and(u8::is_ascii_alphabetic) + && word.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-') +} + +/// A version probe flag such as `-version` or `--version`, without a value. +fn probe_flag(argument: &str) -> bool { + argument + .strip_prefix("--") + .or_else(|| argument.strip_prefix('-')) + .is_some_and(probe_word) +} + fn command(value: &str) -> bool { value.len() <= 64 && value @@ -546,14 +560,21 @@ fn definition(plugin_id: &str, value: &Value) -> Validation<()> { "version", )?; strings(&version["arguments"], 1, 8, "version.arguments", |arg| { - let flag = arg - .strip_prefix("--") - .or_else(|| arg.strip_prefix('-')) - .unwrap_or(""); - arg.len() <= 64 - && flag.as_bytes().first().is_some_and(u8::is_ascii_alphabetic) - && flag.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-') + arg.len() <= 64 && (probe_word(arg) || probe_flag(arg)) })?; + // Some tools print their version only for a subcommand (`go version`, + // `zig version`). A bare word after the first would be an operand, such + // as a script for the tool to run, which a probe must never pass. + if version["arguments"].as_array().is_some_and(|arguments| { + arguments[1..] + .iter() + .any(|arg| !arg.as_str().is_some_and(probe_flag)) + }) { + return Err(invalid( + "version.arguments", + "Only the first argument may be a subcommand; the others must be flags.", + )); + } let pattern = text(&version["pattern"], 512, "version.pattern")?; if Regex::new(pattern).map_or(true, |regex| regex.captures_len() < 2) { return Err(invalid( diff --git a/shared/plugins/contract/v1/plugin-manifest.schema.json b/shared/plugins/contract/v1/plugin-manifest.schema.json index 666bac2c..d894f42a 100644 --- a/shared/plugins/contract/v1/plugin-manifest.schema.json +++ b/shared/plugins/contract/v1/plugin-manifest.schema.json @@ -3398,9 +3398,18 @@ ], "properties": { "arguments": { + "description": "The first argument is a flag or a subcommand such as `version`; every later argument is a flag.", "type": "array", "minItems": 1, "maxItems": 8, + "uniqueItems": true, + "prefixItems": [ + { + "type": "string", + "pattern": "^(--?)?[A-Za-z][A-Za-z0-9-]*$", + "maxLength": 64 + } + ], "items": { "type": "string", "pattern": "^--?[A-Za-z][A-Za-z0-9-]*$", diff --git a/shared/plugins/contract/v1/toolchains/README.md b/shared/plugins/contract/v1/toolchains/README.md index 92cec321..028c5c95 100644 --- a/shared/plugins/contract/v1/toolchains/README.md +++ b/shared/plugins/contract/v1/toolchains/README.md @@ -37,6 +37,15 @@ fields fail closed. Candidate graph ordering reuses the existing shared graph validator and cannot cross layer barriers. This slice does not support a definition candidate of `kind: runtime`, or `toolchainConsumers`. +`version` is `{arguments, pattern}`. `arguments` lists one to eight distinct +literal words of at most 64 bytes. The first is a flag (`-version`, +`--version`) or a subcommand (`version`, for a tool such as Go that prints its +version only that way); every later one is a flag. A flag or subcommand is an +ASCII letter followed by letters, digits and `-`; flags carry no `=value`. +A bare word after the first is refused, so a probe never passes the tool an +operand such as a script or a file. `pattern` is a bounded Rust regular +expression whose first capture is the dotted numeric version. + Provider entries contain `{id, displayName, tools, watchFiles?}`; each watch entry is `{pattern, reader: "native" | "compatible"}`. A present `watchFiles` lists 1-32 unique patterns; an absent one makes an installation-only provider, whose diff --git a/shared/plugins/reference/domains/toolchains.md b/shared/plugins/reference/domains/toolchains.md index 5e318d6f..2a83a02e 100644 --- a/shared/plugins/reference/domains/toolchains.md +++ b/shared/plugins/reference/domains/toolchains.md @@ -29,6 +29,8 @@ 声明式原语已经冻结:根目录只有 `home`、`environment`、`absolute` 三种,通配只有单段 `*`。新的安装形状由提供者回答,不再增加根目录类型或宿主解析器。没有 `watchFiles` 的提供者只报告安装,应答里不能有版本要求。 +版本探针 `version.arguments` 的第一个参数可以是选项(`-version`、`--version`),也可以是子命令(Go 这类只用 `go version` 打印版本的工具写 `version`);之后的参数只能是选项,选项不带 `=值`。第一个参数之后出现不带 `-` 的词就拒绝,所以探针不会把脚本、文件之类的操作数交给工具。 + ### 选择顺序 | 层 | 规则 | @@ -183,6 +185,8 @@ A tool may use one route, both, or neither (relying only on pins, project files, The declarative primitives are frozen: root kinds are `home`, `environment`, and `absolute`, and patterns are single-component `*` globs. A new installation shape is answered by a provider, not by a new root kind or host parser. A provider without `watchFiles` only reports installations, and its replies may not contain version requirements. +The first argument of the version probe `version.arguments` is a flag (`-version`, `--version`) or a subcommand (`version`, for a tool such as Go that prints its version only with `go version`); every later argument is a flag, and flags carry no `=value`. A bare word after the first argument is refused, so a probe never hands the tool an operand such as a script or a file. + ### Selection order | Layer | Rule | From ff7533aca88b4e53b87a1faef5b5c03adcd5d07f Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 15 Nov 2026 14:10:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?docs(plugins):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=99=BB=E8=AE=B0=20#52?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/plugins/reference/protocol-changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index 7edd54c5..2f2f79d1 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -133,6 +133,7 @@ | PR | 修改人 | API 编号 | 协议 / 能力 | 改了什么 | | --- | --- | --- | --- | --- | +| [#52](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/52) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-23 | `toolDefinitions` 0 内的补充 | 工具定义的版本探针 `version.arguments` 第一个参数可以是子命令(如 Go 的 `go version` 写 `["version"]`),之后的参数仍然只能是选项,第一个之后出现裸词以 `plugin.manifest.invalid`(字段 `version.arguments`)拒绝;清单 schema 改用 `prefixItems` 并补上 `uniqueItems`。不需要新能力版本。 | | [#47](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/47) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-30 | `debugAdapters` 0 内的补充 | `targetBindings.program` 新增来源 `target.directory`:`target.path` 所在的目录,供 Delve 这类按包构建再调试的适配器使用;路径没有所在目录时以 `debug.target.invalid`(字段 `target.path`)拒绝。新增宿主命令 `debug.adapters.readAnnouncement`,宿主把 `tcpAnnounced` 适配器的输出逐行交给它,第一行含 `prefix` 的输出是公告,前缀之后是 `port`(连 `127.0.0.1`)或带回环主机的 `host:port`,返回 `none`、`announced` 或 `invalid`(`malformed`、`notLoopback`);契约写明宿主怎样读公告、10 秒内没有公告就启动失败。清单格式只多了一个枚举值,不需要新能力版本。 | ### 2026-11-14