Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions rust/crates/core/src/tests/toolchain_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
35 changes: 28 additions & 7 deletions rust/crates/toolchain/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions shared/plugins/contract/v1/plugin-manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-]*$",
Expand Down
9 changes: 9 additions & 0 deletions shared/plugins/contract/v1/toolchains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions shared/plugins/reference/domains/toolchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

声明式原语已经冻结:根目录只有 `home`、`environment`、`absolute` 三种,通配只有单段 `*`。新的安装形状由提供者回答,不再增加根目录类型或宿主解析器。没有 `watchFiles` 的提供者只报告安装,应答里不能有版本要求。

版本探针 `version.arguments` 的第一个参数可以是选项(`-version`、`--version`),也可以是子命令(Go 这类只用 `go version` 打印版本的工具写 `version`);之后的参数只能是选项,选项不带 `=值`。第一个参数之后出现不带 `-` 的词就拒绝,所以探针不会把脚本、文件之类的操作数交给工具。

### 选择顺序

| 层 | 规则 |
Expand Down Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions shared/plugins/reference/protocol-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading