Skip to content

Commit c550c2b

Browse files
authored
feat(plugins): commandInstallers 让宿主安装 systemCommand 启动缺的命令 (#53)
* feat(plugins): commandInstallers 让宿主安装 systemCommand 启动缺的命令 插件清单新增顶层 commandInstallers[](能力 commandInstallers 0、权限 commands.install),声明怎样用插件已依赖的工具安装 systemCommand 启动用到的 裸命令,例如用 go install 装 dlv。目标有两个:managed 装进宿主为插件管理的 目录(唯一模板变量 ${installDirectory}),toolDefault 装到工具默认位置,并 用探针读出目录。 新增宿主命令 plugins.commandInstallers.requirements、plan、defaultDirectory, Core 错误码 plugin.commandInstaller.unknown、targetUndeclared、 directoryInvalid、probeOutputsInvalid;安装声明进入安装审查。 lithe-platform 增加 path_list_separator、is_absolute_path、join_native; is_environment_name 收到 plugin-model::names 一处。 契约 README、schema、fixture、rust-core-api.md、协议更新记录、能力版本、 API 总表和工具链领域页同步更新。 * feat(diagnostics): 命令安装记为声明式贡献 commandInstaller/install 宿主每次执行用户确认的安装,用 diagnostics.recordPluginOperation 记一条 commandInstaller/install(命令执行生命周期):计划、找工具、启动、超时、 非零退出各有阶段,正常退出但命令不在目录里记 decode。用户取消不记录。 CONTRIBUTIONS 加一行,契约 README、rust-core-api.md、日志 README 的贡献表 和协议更新记录同步更新;不新增事件、通道或错误码。
1 parent 6477e9a commit c550c2b

30 files changed

Lines changed: 1863 additions & 47 deletions

File tree

‎rust/Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/contracts/rust-core-api.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ or removing a command fails until the table changes in the same commit.
447447
| `plugins.declarative.languageServerLaunchPlan` | Expand a declarative plugin's language-server, build-provider, VCS-provider, backend, or debug-adapter launch with host directories and architecture |
448448
| `plugins.languageServers.decodeLaunch` | Bound the answer of a plugin backend that resolved a language server's launch and return the plan the host starts |
449449
| `plugins.languageServers.stateRetention` | Choose which inactive per-workspace state directories of a plugin language server the host deletes |
450+
| `plugins.commandInstallers.requirements` | List each `systemCommand` launch of a plugin with its commands and the installer that provides each |
451+
| `plugins.commandInstallers.plan` | Expand one command installer for the target the user chose |
452+
| `plugins.commandInstallers.defaultDirectory` | Read where a `toolDefault` installation puts its commands from the output of its directory probes |
450453
| `plugins.contentProviders.decode` | Bound the answer of a plugin content provider function and return the document text |
451454
| `debug.adapters.startArguments` | Check one debug start against a plugin's `debugAdapters[]` entry and return its DAP launch arguments |
452455
| `debug.validateAdapterEndpoint` | Validate an IDE-to-DAP TCP endpoint and classify whether remote consent is required; performs no DNS or network I/O |
@@ -4040,6 +4043,34 @@ those older than `maxAgeDays` and those beyond the newest that fit are listed.
40404043
The host lists and deletes only directories under its own state storage, never
40414044
inside an app bundle or installation directory.
40424045

4046+
The `plugins.commandInstallers.*` commands implement
4047+
[Command installers](../../shared/plugins/contract/v1/README.md#command-installers).
4048+
They revalidate the manifest, read nothing and start nothing.
4049+
`plugins.commandInstallers.requirements` accepts `{ manifest }` and returns
4050+
`requirements: { consumers: [{ kind, id, commands: [{ command, installer }] }],
4051+
installers: [{ id, commands, tool, minimumVersion, mayUseNetwork, targets }] }`.
4052+
`kind` is `languageServer`, `buildProvider`, `vcsProvider`, `debugAdapter` or
4053+
`backend`; `id` is the language, build system, VCS or adapter ID, `null` for
4054+
the backend; `installer` is `null` for a command no installer provides.
4055+
`plugins.commandInstallers.plan` accepts `{ manifest, installerID, target:
4056+
"managed" | "toolDefault", installDirectory? }` and returns `plan: { installer,
4057+
target, commands, tool, minimumVersion, mayUseNetwork, timeoutMilliseconds,
4058+
arguments, environment, commandDirectory, directoryProbes: [{ arguments }] }`.
4059+
A `managed` plan needs the absolute directory the host made and expands
4060+
`${installDirectory}` in it; `commandDirectory` is that directory or the
4061+
declared path below it, and `directoryProbes` is empty. A `toolDefault` plan
4062+
takes no `installDirectory`, has a `null` `commandDirectory` and lists the
4063+
probes. `plugins.commandInstallers.defaultDirectory` accepts `{ manifest,
4064+
installerID, outputs }`, one standard output per probe in plan order (`null`
4065+
for a probe that failed), and returns `directory`: the first probe output that
4066+
names an absolute directory, its first path-list entry for a `pathList` probe,
4067+
with `append` joined; `null` when none does. Paths follow the platform Core
4068+
runs on. Refusals are `plugin.commandInstaller.unknown`,
4069+
`plugin.commandInstaller.targetUndeclared`,
4070+
`plugin.commandInstaller.directoryInvalid` and
4071+
`plugin.commandInstaller.probeOutputsInvalid`; the golden cases are
4072+
`shared/plugins/contract/v1/fixtures/command-installers/command-installer-plans.json`.
4073+
40434074
`plugins.contentProviders.decode` accepts `{ result }`, the value a plugin
40444075
function returned for a document of its content scheme, and returns
40454076
`{ content }`. `result` is a string, or an object whose only member is
@@ -5995,6 +6026,7 @@ a code has one meaning across every contribution with that lifecycle:
59956026
| `debugAdapter/start` | `debugAdapters[]` | process start |
59966027
| `lithe/build/model` | `buildSystems[].model` command source | command run |
59976028
| `lithe/build/dependencies` | `buildSystems[].dependencies` command source | command run |
6029+
| `commandInstaller/install` | `commandInstallers[]` installation the user confirmed; `decode` when a provided command is missing after a successful exit | command run |
59986030

59996031
| `stage` | Process start | Command run |
60006032
| --- | --- | --- |

‎rust/crates/build/src/manifest.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use super::template::{self, Allowed, Availability, BuildArgument, Variable};
1515
use lithe_plugin_model::process::{ServerProcess, ServerRole};
1616
use lithe_plugin_model::settings::is_setting_identifier;
1717
use lithe_plugin_model::{
18-
invalid, invalid_template as template_error, is_bare_command, is_identifier,
19-
is_safe_relative_path, sorted_unique, validate_minimum_version, PluginRejection, UIIcon,
20-
Validation,
18+
invalid, invalid_template as template_error, is_bare_command, is_environment_name,
19+
is_identifier, is_safe_relative_path, sorted_unique, validate_minimum_version, PluginRejection,
20+
UIIcon, Validation,
2121
};
2222
use regex::Regex;
2323
use serde::{Deserialize, Deserializer, Serialize};

‎rust/crates/build/src/manifest/checks.rs‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,6 @@ pub(crate) fn is_tag(value: &str) -> bool {
107107
is_identifier(value) && value.len() <= MAX_IDENTIFIER
108108
}
109109

110-
pub(crate) fn is_environment_name(value: &str) -> bool {
111-
!value.is_empty()
112-
&& value.len() <= MAX_IDENTIFIER
113-
&& value
114-
.chars()
115-
.next()
116-
.is_some_and(|first| first.is_ascii_uppercase() || first == '_')
117-
&& value.chars().all(|character| {
118-
character.is_ascii_uppercase() || character.is_ascii_digit() || character == '_'
119-
})
120-
}
121-
122110
/// A file name with no directory part.
123111
pub(crate) fn is_file_name(value: &str) -> bool {
124112
is_safe_relative_path(value) && !value.contains('/') && value != "."

‎rust/crates/build/src/plans.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub(crate) fn provider_hints(request: &OutputPlanRequest) -> Validation<Map<Stri
187187
params.insert("tool".to_string(), json!({ "executable": executable }));
188188
if tool.environment.len() > 64
189189
|| tool.environment.iter().any(|(key, value)| {
190-
!super::manifest::is_environment_name(key)
190+
!lithe_plugin_model::is_environment_name(key)
191191
|| value.len() > 32768
192192
|| value.contains('\0')
193193
})

‎rust/crates/core/src/protocol/command.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ pub enum PluginsCommand {
235235
LanguageServersDecodeLaunch,
236236
/// Picks the stored language-server state the host may delete (`plugins.languageServers.stateRetention`).
237237
LanguageServersStateRetention,
238+
/// Lists the bare commands a plugin's launches need and their installers (`plugins.commandInstallers.requirements`).
239+
CommandInstallersRequirements,
240+
/// Expands a command installer for the target the user chose (`plugins.commandInstallers.plan`).
241+
CommandInstallersPlan,
242+
/// Reads where a `toolDefault` installation puts its commands (`plugins.commandInstallers.defaultDirectory`).
243+
CommandInstallersDefaultDirectory,
238244
/// Checks a plugin content provider's answer (`plugins.contentProviders.decode`).
239245
ContentProvidersDecode,
240246
/// Merges a plugin's stored setting layers into effective values (`plugins.declarative.resolveSettings`).
@@ -994,6 +1000,15 @@ impl CoreCommand {
9941000
"plugins.languageServers.stateRetention" => {
9951001
Some(Self::Plugins(PluginsCommand::LanguageServersStateRetention))
9961002
}
1003+
"plugins.commandInstallers.requirements" => {
1004+
Some(Self::Plugins(PluginsCommand::CommandInstallersRequirements))
1005+
}
1006+
"plugins.commandInstallers.plan" => {
1007+
Some(Self::Plugins(PluginsCommand::CommandInstallersPlan))
1008+
}
1009+
"plugins.commandInstallers.defaultDirectory" => Some(Self::Plugins(
1010+
PluginsCommand::CommandInstallersDefaultDirectory,
1011+
)),
9971012
"plugins.contentProviders.decode" => {
9981013
Some(Self::Plugins(PluginsCommand::ContentProvidersDecode))
9991014
}
@@ -1601,6 +1616,9 @@ mod tests {
16011616
"lsp.pluginServerNotify",
16021617
"plugins.languageServers.decodeLaunch",
16031618
"plugins.languageServers.stateRetention",
1619+
"plugins.commandInstallers.requirements",
1620+
"plugins.commandInstallers.plan",
1621+
"plugins.commandInstallers.defaultDirectory",
16041622
"plugins.contentProviders.decode",
16051623
"lsp.cancelOperation",
16061624
"lsp.pollEvents",

‎rust/crates/core/src/runtime/dispatcher/plugins.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ pub(super) fn dispatch(
6363
payload,
6464
lithe_plugin_language_servers::state_retention_command,
6565
),
66+
PluginsCommand::CommandInstallersRequirements => plugin_response(
67+
id,
68+
payload,
69+
lithe_plugin_manifest::command_installer_requirements_command,
70+
),
71+
PluginsCommand::CommandInstallersPlan => plugin_response(
72+
id,
73+
payload,
74+
lithe_plugin_manifest::command_installer_plan_command,
75+
),
76+
PluginsCommand::CommandInstallersDefaultDirectory => plugin_response(
77+
id,
78+
payload,
79+
lithe_plugin_manifest::command_installer_default_directory_command,
80+
),
6681
PluginsCommand::ContentProvidersDecode => plugin_response(
6782
id,
6883
payload,

‎rust/crates/core/src/tests/declarative_plugins.rs‎

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use lithe_plugin_manifest::{
2-
discover_tests_command, language_server_launch_plan_command, resolve_settings_command,
3-
run_plan_command, test_plan_command, validate_command, workspace_configuration_command,
2+
command_installer_default_directory_command, command_installer_plan_command,
3+
command_installer_requirements_command, discover_tests_command,
4+
language_server_launch_plan_command, resolve_settings_command, run_plan_command,
5+
test_plan_command, validate_command, workspace_configuration_command,
46
};
57
use serde_json::{json, Value};
68

@@ -63,6 +65,10 @@ const PROJECT_GENERATOR_FIXTURE: &str =
6365
contract_file!("fixtures/project-generators/project-generator.plugin.json");
6466
const PROJECT_GENERATOR_TOOL_FIXTURE: &str =
6567
contract_file!("fixtures/project-generators/project-generator-tool-field.plugin.json");
68+
const COMMAND_INSTALLER_FIXTURE: &str =
69+
contract_file!("fixtures/command-installers/command-installer.plugin.json");
70+
const COMMAND_INSTALLER_PLANS: &str =
71+
contract_file!("fixtures/command-installers/command-installer-plans.json");
6672
const INVALID_MANIFESTS: &str = contract_file!("fixtures/manifest/invalid-manifests.json");
6773
const COMMAND_PLANS: &str = contract_file!("fixtures/languages/command-plans.json");
6874

@@ -95,6 +101,7 @@ fn fixture(name: &str) -> Value {
95101
"editor-providers.plugin.json" => EDITOR_PROVIDERS_FIXTURE,
96102
"project-generator.plugin.json" => PROJECT_GENERATOR_FIXTURE,
97103
"project-generator-tool-field.plugin.json" => PROJECT_GENERATOR_TOOL_FIXTURE,
104+
"command-installer.plugin.json" => COMMAND_INSTALLER_FIXTURE,
98105
other => panic!("unknown fixture {other}"),
99106
};
100107
serde_json::from_str(source).expect("fixture manifest is JSON")
@@ -126,6 +133,7 @@ fn contract_fixtures_and_official_plugins_validate() {
126133
LANGUAGE_SERVER_BACKEND_FIXTURE,
127134
EDITOR_PROVIDERS_FIXTURE,
128135
PROJECT_GENERATOR_TOOL_FIXTURE,
136+
COMMAND_INSTALLER_FIXTURE,
129137
] {
130138
let outcome = validate(serde_json::from_str(source).unwrap());
131139
assert_eq!(outcome["status"], "ok", "{outcome}");
@@ -253,6 +261,93 @@ fn invalid_manifest_fixtures_report_their_stable_codes() {
253261
}
254262
}
255263

264+
/// The command-installer commands answer the golden cases for this host's
265+
/// platform; `lithe-plugin-manifest` checks the same cases for every
266+
/// platform.
267+
#[test]
268+
fn command_installer_fixtures_match_on_this_host() {
269+
let plans: Value = serde_json::from_str(COMMAND_INSTALLER_PLANS).unwrap();
270+
let platform = if cfg!(windows) { "windows" } else { "unix" };
271+
for case in plans["cases"].as_array().unwrap() {
272+
let name = case["name"].as_str().unwrap();
273+
let specific = &case["platforms"][platform];
274+
let mut payload = json!({ "manifest": fixture("command-installer.plugin.json") });
275+
for source in [&case["payload"], &specific["payload"]] {
276+
for (field, value) in source.as_object().into_iter().flatten() {
277+
payload[field] = value.clone();
278+
}
279+
}
280+
for edit in case["manifestEdits"].as_array().into_iter().flatten() {
281+
let pointer = edit["path"].as_str().unwrap();
282+
*payload["manifest"].pointer_mut(pointer).unwrap() = edit["value"].clone();
283+
}
284+
let outcome = match case["operation"].as_str().unwrap() {
285+
"requirements" => command_installer_requirements_command(payload),
286+
"plan" => command_installer_plan_command(payload),
287+
"defaultDirectory" => command_installer_default_directory_command(payload),
288+
other => panic!("unknown operation {other}"),
289+
}
290+
.expect("payload is well formed");
291+
let expected = if specific.get("expected").is_some() {
292+
&specific["expected"]
293+
} else {
294+
&case["expected"]
295+
};
296+
if expected["status"] == "rejected" {
297+
assert_eq!(outcome["status"], "rejected", "{name}: {outcome}");
298+
assert_eq!(
299+
outcome["error"]["code"], expected["code"],
300+
"{name}: {outcome}"
301+
);
302+
assert_eq!(
303+
outcome["error"]["field"], expected["field"],
304+
"{name}: {outcome}"
305+
);
306+
} else {
307+
assert_eq!(&outcome, expected, "{name}");
308+
}
309+
}
310+
}
311+
312+
/// The install review shows everything an installer runs, so changing its
313+
/// arguments or targets is a new program the user approves again.
314+
#[test]
315+
fn command_installers_are_reviewed_programs() {
316+
let programs = |manifest: Value| {
317+
let outcome = lithe_plugin_marketplace::install_review_command(json!({
318+
"manifest": manifest,
319+
}))
320+
.expect("payload is well formed");
321+
outcome["review"]["programs"].as_array().unwrap().clone()
322+
};
323+
let manifest = fixture("command-installer.plugin.json");
324+
let before = programs(manifest.clone());
325+
let installers: Vec<&Value> = before
326+
.iter()
327+
.filter(|program| program["kind"] == "commandInstaller")
328+
.collect();
329+
assert_eq!(installers.len(), 2);
330+
assert_eq!(installers[0]["installer"], "sample-dap");
331+
assert_eq!(installers[1]["timeoutSeconds"], 300);
332+
let mut changed = manifest;
333+
changed["commandInstallers"][0]["arguments"] = json!(["install", "example.org/other@latest"]);
334+
assert_ne!(programs(changed), before);
335+
}
336+
337+
/// A malformed request is a Core failure, not a rejection.
338+
#[test]
339+
fn command_installer_requests_decode_strictly() {
340+
let manifest = fixture("command-installer.plugin.json");
341+
assert!(command_installer_plan_command(
342+
json!({ "manifest": manifest, "installerID": "sample-ls", "target": "elsewhere" })
343+
)
344+
.is_err());
345+
assert!(command_installer_default_directory_command(
346+
json!({ "manifest": manifest, "installerID": "sample-ls" })
347+
)
348+
.is_err());
349+
}
350+
256351
#[test]
257352
fn command_plan_fixtures_match_golden_expansions() {
258353
let fixtures: Value = serde_json::from_str(COMMAND_PLANS).unwrap();

‎rust/crates/diagnostics/src/plugin_operations.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,22 @@ pub static BUILD_DEPENDENCIES: Contribution = Contribution {
111111
lifecycle: Lifecycle::CommandRun,
112112
};
113113

114+
/// `commandInstallers[]`: one installation the user confirmed, from planning the
115+
/// chosen target to finding every provided command in its directory. A command
116+
/// still missing after a successful exit is the `decode` stage.
117+
pub static COMMAND_INSTALLER_INSTALL: Contribution = Contribution {
118+
operation: "commandInstaller/install",
119+
lifecycle: Lifecycle::CommandRun,
120+
};
121+
114122
/// Every contribution kind this ingress accepts. Supporting a new declarative
115123
/// contract means adding its row here and reporting the same token from its owner.
116124
pub static CONTRIBUTIONS: &[&Contribution] = &[
117125
&LANGUAGE_SERVER_START,
118126
&DEBUG_ADAPTER_START,
119127
&BUILD_MODEL,
120128
&BUILD_DEPENDENCIES,
129+
&COMMAND_INSTALLER_INSTALL,
121130
];
122131

123132
impl Contribution {
@@ -430,6 +439,7 @@ mod tests {
430439
("debugAdapter/start", Lifecycle::ProcessStart),
431440
("lithe/build/model", Lifecycle::CommandRun),
432441
("lithe/build/dependencies", Lifecycle::CommandRun),
442+
("commandInstaller/install", Lifecycle::CommandRun),
433443
];
434444
let rows: Vec<_> = CONTRIBUTIONS
435445
.iter()

0 commit comments

Comments
 (0)