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
13 changes: 13 additions & 0 deletions rust/contracts/application-boundary.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,16 @@ the prefix does not confer authority. Core deduplicates only the generated count
of the effective saved selector and validates it before use. Prepared team/local Run
layers can be resolved without filesystem publication; native adapters own cancellation,
source checks, metadata-preserving conditional writes, rollback and readback.


### Machine-wide SDK catalog ownership

Shared `toolchains.catalogState` / `toolchains.editCatalog` own the bounded global
registration document and its merge semantics. Desktop adapters read it from the
platform user-preference root, retain native source identity, publish only after
explicit Save, and reread the result. No workspace is needed; opening settings
creates no source. Registered homes and defaults become inert resolver inputs,
never cached authority about an executable. A project may override the global
default, while running processes retain their launch environment. Native SDK
probing, cancellation and filesystem permissions remain adapter responsibilities;
neither these commands nor runtime consumers write into SDKs or installed bundles.
42 changes: 42 additions & 0 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ or removing a command fails until the table changes in the same commit.
| `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 |
| `toolchains.resolvePins` | Validate a captured local document and find the nearest ancestor directory pin, retaining dormant and legacy entries without probing or writing |
| `toolchains.editPins` | Apply one bounded batch of directory pin edits to a captured local document without writing native files |
| `toolchains.catalogState` | Validate machine-wide SDK registrations without a project |
| `toolchains.editCatalog` | Merge confirmed machine-wide SDK registrations and defaults |
| `toolchains.pinStoragePlan` | Declare bounded workspace-native pin and ignore sources |
| `toolchains.decodePinDocument` | Validate a complete native source or supply the absent-source default |
| `toolchains.editPinSources` | Plan deterministic pin and Git ignore source edits without native I/O |
Expand Down Expand Up @@ -6509,3 +6511,43 @@ and executable exports, then resolves/probes the main build tool in that same
environment. User-configured invocation environment retains its existing
precedence. Host-managed runtime candidates are explicit `runtime` plans; hosts
must not infer executable names from opaque runtime IDs.


### Global SDK registrations without an open project

`toolchains.catalogState` accepts `{document:string|null,platform,filesystemCaseSensitive?}`
and returns `{status:"ok",state:{document,storage:{relativePath:"toolchains/global.json",maximumBytes:262144}}}`.
Native clients resolve the relative path below their platform user-preference directory,
never below a workspace, SDK, installed package or application bundle. Reading an absent
source returns `{version:1,tools:{}}` and must not create a directory or file.

`toolchains.editCatalog` accepts the same source fields and a nonempty `edits` array of
`{tool,homes:[absoluteHome],defaultHome:string|null}`. Each edit replaces only that tool's
registrations and default; other tools, including dormant plugins, remain intact. At most
64 tools and 32 distinct homes per tool are accepted. Native platform path normalization
and case identity apply before deduplication. A selected default is registered if needed;
null clears only the default. Empty registrations plus null remove the tool entry.
The result is `{status:"ok",edit:{changed,document:string|null,catalog}}`; unchanged edits
return a null replacement and must not create a source. Invalid shapes, duplicate JSON keys,
unknown fields, relative homes, aliases and oversized documents reject with
`plugin.toolchain.invalidDocument`. The schema is
[`toolchain-global-v1.schema.json`](toolchain-global-v1.schema.json); cross-client vectors
are in `rust/fixtures/toolchain-global-catalog.json`.

Native clients retain the exact bytes and filesystem identity privately, verify them before
atomic publication, and reread after Save. Core owns the merge and bounds; the native client
owns read/write permissions, conflict detection and installation probing. Registrations
contain no cached version authority and never modify SDK directories. This user-settings
resource does not affect code signatures or update deltas.

`toolchains.candidates` and `toolchains.resolve` accept optional `global:true` with
`workspaceRoot:""`, allowing discovery and inspection before a project is open. Global mode
requires an empty local pin document, never selects project wrappers, project environments,
project settings or project provider statements, and does not require a fictitious workspace
filesystem fact. Additional `workspaceRoots` remain exclusion roots. Normal requests still
require the real project root. Native callers supply registered homes as ordinary
`systemInstallations` and the current catalog default as `globalDefault:{home}`; the
existing precedence remains fixed consumer choice, project override, global default, then
automatic discovery. Clearing the global default exposes live automatic selection without
removing manual registrations. Each new consumer resolves fresh facts and probes; already
running processes retain their launch-time environment.
42 changes: 42 additions & 0 deletions rust/contracts/toolchain-global-v1.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://lithe.dev/contracts/toolchain-global-v1.schema.json",
"title": "Machine-wide SDK catalog v1",
"type": "object",
"additionalProperties": false,
"required": [
"version",
"tools"
],
"properties": {
"version": {
"const": 1
},
"tools": {
"type": "object",
"maxProperties": 64,
"additionalProperties": {
"type": "object",
"additionalProperties": false,
"required": [
"homes"
],
"properties": {
"homes": {
"type": "array",
"maxItems": 32,
"uniqueItems": true,
"items": {
"type": "string",
"minLength": 1
}
},
"defaultHome": {
"type": "string",
"minLength": 1
}
}
}
}
}
}
6 changes: 6 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ pub enum KeymapCommand {
#[derive(Debug, Clone)]
/// The `toolchains.*` commands; their names live in [`CoreCommand::parse`].
pub enum ToolchainsCommand {
/// Reads global SDK registrations and their native source plan.
CatalogState,
/// Plans a source-bound global SDK registration/default edit.
EditCatalog,
/// Registers plugin-owned tools with verified package provenance.
Registry,
/// Validates provider answers using native evidence supplied by the host.
Expand Down Expand Up @@ -1084,6 +1088,8 @@ impl CoreCommand {
"keymap.planImportSources" => Some(Self::Keymap(KeymapCommand::PlanImportSources)),
"keymap.planImportBindings" => Some(Self::Keymap(KeymapCommand::PlanImportBindings)),
"debug.startOrContinue" => Some(Self::Debug(DebugCommand::StartOrContinue)),
"toolchains.catalogState" => Some(Self::Toolchains(ToolchainsCommand::CatalogState)),
"toolchains.editCatalog" => Some(Self::Toolchains(ToolchainsCommand::EditCatalog)),
"toolchains.registry" => Some(Self::Toolchains(ToolchainsCommand::Registry)),
"toolchains.decodeReply" => Some(Self::Toolchains(ToolchainsCommand::DecodeReply)),
"toolchains.failureReply" => Some(Self::Toolchains(ToolchainsCommand::FailureReply)),
Expand Down
6 changes: 6 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/toolchains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ pub(super) fn dispatch(
ToolchainsCommand::EditPins => {
plugin_response(id, payload, crate::toolchain::edit_pins_command)
}
ToolchainsCommand::CatalogState => {
plugin_response(id, payload, crate::toolchain::catalog_state_command)
}
ToolchainsCommand::EditCatalog => {
plugin_response(id, payload, crate::toolchain::edit_catalog_command)
}
ToolchainsCommand::PinStoragePlan => {
plugin_response(id, payload, crate::toolchain::pin_storage_plan_command)
}
Expand Down
22 changes: 22 additions & 0 deletions rust/crates/core/src/tests/toolchain_pins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,25 @@ fn source_edits_match_shared_fixture() {
}
}
}
#[test]
fn global_catalog_commands_match_shared_fixture() {
let fixture: Value = serde_json::from_str(include_str!(
"../../../../fixtures/toolchain-global-catalog.json"
))
.unwrap();
for case in fixture["cases"].as_array().unwrap() {
let response: Value = serde_json::from_str(&crate::execute_json(
&json!({"command": case["command"], "payload": case["input"]}).to_string(),
))
.unwrap();
if let Some(code) = case.get("error") {
assert_eq!(response["data"]["status"], "rejected", "{case}: {response}");
assert_eq!(
&response["data"]["error"]["code"], code,
"{case}: {response}"
);
} else {
assert_eq!(response["data"], case["expected"], "{case}: {response}");
}
}
}
43 changes: 43 additions & 0 deletions rust/crates/core/src/tests/toolchain_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,3 +1074,46 @@ fn consumer_preferences_json_dispatcher_preserves_the_value_boundary() {
json!({"home":"/fixture/sdk-one"})
);
}

#[test]
fn global_toolchain_discovery_and_defaults_need_no_project_directory() {
let mut value = input();
value["global"] = json!(true);
value["workspaceRoot"] = json!("");
value["filesystem"] = json!([]);
installation(&mut value, HOME, "21.0.4");
value["systemInstallations"] = json!([{"tool":"java","home":HOME}]);
value["globalDefault"] = json!({"home":HOME});
let result = resolve_command(value.clone(), validated_manifest_json).unwrap();
assert_eq!(result["status"], "ok", "{result}");
assert_eq!(result["resolution"]["outcome"]["selection"]["home"], HOME);
let mut listing = value_for_candidates(&value);
listing["global"] = json!(true);
let candidates = candidates_command(listing, validated_manifest_json).unwrap();
assert_eq!(candidates["status"], "ok", "{candidates}");
assert_eq!(candidates["candidates"]["installations"][0]["home"], HOME);
}

#[test]
fn global_toolchain_mode_refuses_project_pins_and_ignores_project_executables() {
let mut value = input();
value["global"] = json!(true);
value["workspaceRoot"] = json!("");
value["filesystem"] = json!([]);
installation(&mut value, HOME, "21.0.4");
value["systemInstallations"] = json!([{"tool":"java","home":HOME}]);
value["globalDefault"] = json!({"home":HOME});
value["registry"]["plugins"][0]["manifest"]["toolDefinitions"][0]["executables"].as_array_mut().unwrap().insert(1,
json!({"id":"project-env","kind":"projectFile","projectKind":"environment","home":".venv","path":".venv/bin/java","platforms":["macos","linux"]}));
value["projectCodeAllowed"] = json!(true);
let result = resolve(&value);
assert_eq!(result["outcome"]["selection"]["home"], HOME);
assert!(!result["trace"]
.as_array()
.unwrap()
.iter()
.any(|row| row["candidate"] == "project-env"));
value["local"] = local_pins();
let rejected = resolve_command(value, validated_manifest_json).unwrap();
assert_eq!(rejected["status"], "rejected", "{rejected}");
}
Loading
Loading