Skip to content

Commit c8f6a03

Browse files
committed
feat(toolchains): manage machine-wide SDK registrations without a project
1 parent dba2fd2 commit c8f6a03

13 files changed

Lines changed: 533 additions & 10 deletions

File tree

‎rust/contracts/application-boundary.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,16 @@ the prefix does not confer authority. Core deduplicates only the generated count
556556
of the effective saved selector and validates it before use. Prepared team/local Run
557557
layers can be resolved without filesystem publication; native adapters own cancellation,
558558
source checks, metadata-preserving conditional writes, rollback and readback.
559+
560+
561+
### Machine-wide SDK catalog ownership
562+
563+
Shared `toolchains.catalogState` / `toolchains.editCatalog` own the bounded global
564+
registration document and its merge semantics. Desktop adapters read it from the
565+
platform user-preference root, retain native source identity, publish only after
566+
explicit Save, and reread the result. No workspace is needed; opening settings
567+
creates no source. Registered homes and defaults become inert resolver inputs,
568+
never cached authority about an executable. A project may override the global
569+
default, while running processes retain their launch environment. Native SDK
570+
probing, cancellation and filesystem permissions remain adapter responsibilities;
571+
neither these commands nor runtime consumers write into SDKs or installed bundles.

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ or removing a command fails until the table changes in the same commit.
485485
| `toolchains.failureReply` | Build the JSON-RPC error reply for a query that missed its deadline or found no backend, so the host passes it to `toolchains.decodeReply` like a provider's own error; cancellation has none |
486486
| `toolchains.resolvePins` | Validate a captured local document and find the nearest ancestor directory pin, retaining dormant and legacy entries without probing or writing |
487487
| `toolchains.editPins` | Apply one bounded batch of directory pin edits to a captured local document without writing native files |
488+
| `toolchains.catalogState` | Validate machine-wide SDK registrations without a project |
489+
| `toolchains.editCatalog` | Merge confirmed machine-wide SDK registrations and defaults |
488490
| `toolchains.pinStoragePlan` | Declare bounded workspace-native pin and ignore sources |
489491
| `toolchains.decodePinDocument` | Validate a complete native source or supply the absent-source default |
490492
| `toolchains.editPinSources` | Plan deterministic pin and Git ignore source edits without native I/O |
@@ -6509,3 +6511,43 @@ and executable exports, then resolves/probes the main build tool in that same
65096511
environment. User-configured invocation environment retains its existing
65106512
precedence. Host-managed runtime candidates are explicit `runtime` plans; hosts
65116513
must not infer executable names from opaque runtime IDs.
6514+
6515+
6516+
### Global SDK registrations without an open project
6517+
6518+
`toolchains.catalogState` accepts `{document:string|null,platform,filesystemCaseSensitive?}`
6519+
and returns `{status:"ok",state:{document,storage:{relativePath:"toolchains/global.json",maximumBytes:262144}}}`.
6520+
Native clients resolve the relative path below their platform user-preference directory,
6521+
never below a workspace, SDK, installed package or application bundle. Reading an absent
6522+
source returns `{version:1,tools:{}}` and must not create a directory or file.
6523+
6524+
`toolchains.editCatalog` accepts the same source fields and a nonempty `edits` array of
6525+
`{tool,homes:[absoluteHome],defaultHome:string|null}`. Each edit replaces only that tool's
6526+
registrations and default; other tools, including dormant plugins, remain intact. At most
6527+
64 tools and 32 distinct homes per tool are accepted. Native platform path normalization
6528+
and case identity apply before deduplication. A selected default is registered if needed;
6529+
null clears only the default. Empty registrations plus null remove the tool entry.
6530+
The result is `{status:"ok",edit:{changed,document:string|null,catalog}}`; unchanged edits
6531+
return a null replacement and must not create a source. Invalid shapes, duplicate JSON keys,
6532+
unknown fields, relative homes, aliases and oversized documents reject with
6533+
`plugin.toolchain.invalidDocument`. The schema is
6534+
[`toolchain-global-v1.schema.json`](toolchain-global-v1.schema.json); cross-client vectors
6535+
are in `rust/fixtures/toolchain-global-catalog.json`.
6536+
6537+
Native clients retain the exact bytes and filesystem identity privately, verify them before
6538+
atomic publication, and reread after Save. Core owns the merge and bounds; the native client
6539+
owns read/write permissions, conflict detection and installation probing. Registrations
6540+
contain no cached version authority and never modify SDK directories. This user-settings
6541+
resource does not affect code signatures or update deltas.
6542+
6543+
`toolchains.candidates` and `toolchains.resolve` accept optional `global:true` with
6544+
`workspaceRoot:""`, allowing discovery and inspection before a project is open. Global mode
6545+
requires an empty local pin document, never selects project wrappers, project environments,
6546+
project settings or project provider statements, and does not require a fictitious workspace
6547+
filesystem fact. Additional `workspaceRoots` remain exclusion roots. Normal requests still
6548+
require the real project root. Native callers supply registered homes as ordinary
6549+
`systemInstallations` and the current catalog default as `globalDefault:{home}`; the
6550+
existing precedence remains fixed consumer choice, project override, global default, then
6551+
automatic discovery. Clearing the global default exposes live automatic selection without
6552+
removing manual registrations. Each new consumer resolves fresh facts and probes; already
6553+
running processes retain their launch-time environment.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://lithe.dev/contracts/toolchain-global-v1.schema.json",
4+
"title": "Machine-wide SDK catalog v1",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": [
8+
"version",
9+
"tools"
10+
],
11+
"properties": {
12+
"version": {
13+
"const": 1
14+
},
15+
"tools": {
16+
"type": "object",
17+
"maxProperties": 64,
18+
"additionalProperties": {
19+
"type": "object",
20+
"additionalProperties": false,
21+
"required": [
22+
"homes"
23+
],
24+
"properties": {
25+
"homes": {
26+
"type": "array",
27+
"maxItems": 32,
28+
"uniqueItems": true,
29+
"items": {
30+
"type": "string",
31+
"minLength": 1
32+
}
33+
},
34+
"defaultHome": {
35+
"type": "string",
36+
"minLength": 1
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ pub enum KeymapCommand {
389389
#[derive(Debug, Clone)]
390390
/// The `toolchains.*` commands; their names live in [`CoreCommand::parse`].
391391
pub enum ToolchainsCommand {
392+
/// Reads global SDK registrations and their native source plan.
393+
CatalogState,
394+
/// Plans a source-bound global SDK registration/default edit.
395+
EditCatalog,
392396
/// Registers plugin-owned tools with verified package provenance.
393397
Registry,
394398
/// Validates provider answers using native evidence supplied by the host.
@@ -1084,6 +1088,8 @@ impl CoreCommand {
10841088
"keymap.planImportSources" => Some(Self::Keymap(KeymapCommand::PlanImportSources)),
10851089
"keymap.planImportBindings" => Some(Self::Keymap(KeymapCommand::PlanImportBindings)),
10861090
"debug.startOrContinue" => Some(Self::Debug(DebugCommand::StartOrContinue)),
1091+
"toolchains.catalogState" => Some(Self::Toolchains(ToolchainsCommand::CatalogState)),
1092+
"toolchains.editCatalog" => Some(Self::Toolchains(ToolchainsCommand::EditCatalog)),
10871093
"toolchains.registry" => Some(Self::Toolchains(ToolchainsCommand::Registry)),
10881094
"toolchains.decodeReply" => Some(Self::Toolchains(ToolchainsCommand::DecodeReply)),
10891095
"toolchains.failureReply" => Some(Self::Toolchains(ToolchainsCommand::FailureReply)),

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ pub(super) fn dispatch(
3333
ToolchainsCommand::EditPins => {
3434
plugin_response(id, payload, crate::toolchain::edit_pins_command)
3535
}
36+
ToolchainsCommand::CatalogState => {
37+
plugin_response(id, payload, crate::toolchain::catalog_state_command)
38+
}
39+
ToolchainsCommand::EditCatalog => {
40+
plugin_response(id, payload, crate::toolchain::edit_catalog_command)
41+
}
3642
ToolchainsCommand::PinStoragePlan => {
3743
plugin_response(id, payload, crate::toolchain::pin_storage_plan_command)
3844
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,25 @@ fn source_edits_match_shared_fixture() {
397397
}
398398
}
399399
}
400+
#[test]
401+
fn global_catalog_commands_match_shared_fixture() {
402+
let fixture: Value = serde_json::from_str(include_str!(
403+
"../../../../fixtures/toolchain-global-catalog.json"
404+
))
405+
.unwrap();
406+
for case in fixture["cases"].as_array().unwrap() {
407+
let response: Value = serde_json::from_str(&crate::execute_json(
408+
&json!({"command": case["command"], "payload": case["input"]}).to_string(),
409+
))
410+
.unwrap();
411+
if let Some(code) = case.get("error") {
412+
assert_eq!(response["data"]["status"], "rejected", "{case}: {response}");
413+
assert_eq!(
414+
&response["data"]["error"]["code"], code,
415+
"{case}: {response}"
416+
);
417+
} else {
418+
assert_eq!(response["data"], case["expected"], "{case}: {response}");
419+
}
420+
}
421+
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,3 +1074,46 @@ fn consumer_preferences_json_dispatcher_preserves_the_value_boundary() {
10741074
json!({"home":"/fixture/sdk-one"})
10751075
);
10761076
}
1077+
1078+
#[test]
1079+
fn global_toolchain_discovery_and_defaults_need_no_project_directory() {
1080+
let mut value = input();
1081+
value["global"] = json!(true);
1082+
value["workspaceRoot"] = json!("");
1083+
value["filesystem"] = json!([]);
1084+
installation(&mut value, HOME, "21.0.4");
1085+
value["systemInstallations"] = json!([{"tool":"java","home":HOME}]);
1086+
value["globalDefault"] = json!({"home":HOME});
1087+
let result = resolve_command(value.clone(), validated_manifest_json).unwrap();
1088+
assert_eq!(result["status"], "ok", "{result}");
1089+
assert_eq!(result["resolution"]["outcome"]["selection"]["home"], HOME);
1090+
let mut listing = value_for_candidates(&value);
1091+
listing["global"] = json!(true);
1092+
let candidates = candidates_command(listing, validated_manifest_json).unwrap();
1093+
assert_eq!(candidates["status"], "ok", "{candidates}");
1094+
assert_eq!(candidates["candidates"]["installations"][0]["home"], HOME);
1095+
}
1096+
1097+
#[test]
1098+
fn global_toolchain_mode_refuses_project_pins_and_ignores_project_executables() {
1099+
let mut value = input();
1100+
value["global"] = json!(true);
1101+
value["workspaceRoot"] = json!("");
1102+
value["filesystem"] = json!([]);
1103+
installation(&mut value, HOME, "21.0.4");
1104+
value["systemInstallations"] = json!([{"tool":"java","home":HOME}]);
1105+
value["globalDefault"] = json!({"home":HOME});
1106+
value["registry"]["plugins"][0]["manifest"]["toolDefinitions"][0]["executables"].as_array_mut().unwrap().insert(1,
1107+
json!({"id":"project-env","kind":"projectFile","projectKind":"environment","home":".venv","path":".venv/bin/java","platforms":["macos","linux"]}));
1108+
value["projectCodeAllowed"] = json!(true);
1109+
let result = resolve(&value);
1110+
assert_eq!(result["outcome"]["selection"]["home"], HOME);
1111+
assert!(!result["trace"]
1112+
.as_array()
1113+
.unwrap()
1114+
.iter()
1115+
.any(|row| row["candidate"] == "project-env"));
1116+
value["local"] = local_pins();
1117+
let rejected = resolve_command(value, validated_manifest_json).unwrap();
1118+
assert_eq!(rejected["status"], "rejected", "{rejected}");
1119+
}

0 commit comments

Comments
 (0)