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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ Core 能校验一个能力,不代表宿主能运行它。宿主在 `plugins.de

macOS 宿主接受级别 1 到 3(`supportedDeclarativeAPIVersions = [1, 2, 3]`),能力表是 `PluginManifest.hostCapabilities`,在校验、索引和安装审查时都发给 Core;其中的 `buildSystems: [1]` 随 macOS 的 Build 工具窗口一起加入,`buildProviders: [1]` 在 macOS 接入构建 Provider 会话后才加入。`vcsProviders: [1]` 同样等 macOS 接入 VCS Provider 会话(版本控制工具窗口、项目树状态和文件移动)后才加入,见[统一 VCS 模型提案](../../proposed/architecture/2026-10-22-unified-vcs-provider-model.md)的 P3。Core 自己支持 `buildProviders: 1` 和 `vcsProviders: 1`,不传宿主表时仍可校验清单、生成 Provider 计划、识别工作副本根并转发请求。Windows 还没有声明式插件宿主,不发送能力表,所以 Windows 不列出级别 3 的插件。宿主接入某个能力时,要做两件事:让宿主接受级别 3,并在宿主自己的能力表里加上这个能力的版本,而且只在宿主真正能运行它时才加。

### 2.1 工具链只读查询的 macOS 准入

macOS 的运行环境设置页已有声明式扫描、版本探测、后端协商与 `toolchains/query` 查询后,
宿主登记 `toolDefinitions: [1]`、`toolchainProviders: [1]` 和 `executableResolution: [1, 2]`。
三个准入入口继续使用同一张能力表;漏登记会让最新 AutoBuild 仍把 mise 等插件显示为“需要更新 Lithe”。
此登记只承诺现有只读查询,不代表 Build、Run、LSP 已消费工具链选择,Windows 仍不登记。

仅有工具定义的合法插件必须拥有启用状态。描述器在没有其他模块时生成不启动进程的
`<pluginID>.toolchains` 应用级模块,组合根为它登记普通声明式工厂;有后端的提供方仍使用已有
backend 模块,不增加第二个开关。正确做法是让纯定义插件通过普通插件启用流程进入设置加载器;
不要用空模块列表、按插件名强行启用,或扩大 `canActivateWithoutRestart` 来跳过启动注册。
新增安装仍在重启后进入设置加载器的启动快照,禁用则随已有启用状态从后续查询中撤回。

备选是只增加能力表、或等待所有运行时消费者迁移完毕。前者会把纯定义插件留在
`emptyPlugin` / `missingModuleFactory` 拒绝路径;后者让已经具备的只读能力持续不可安装,均不采用。
本次不新增下载资源或可写路径;查询沿用平台用户状态目录,发行 bundle 和插件包保持只读,
不改变代码签名或 Sparkle delta 基线。代价是纯定义模块也须遵循现有重启和模块所有权规则。

`ToolchainPluginAdmissionTests` 用正式契约样例和真实 Core 覆盖索引、安装审查、清单、
纯定义模块与工厂登记;`MacToolchainDiscoveryTests` 和 `ToolchainSettingsLoaderTests` 覆盖已有查询路线。
这类组件证据不代替真实 mise 应用内验收,完整框架状态继续由功能矩阵记录。

### 3. 市场索引带上能力版本

- 索引里级别 3 的 `versions[].requires` 必填,内容就是包内清单的 `requires`;级别 1、2 禁止出现。宿主因此在下载之前就能判断装不装得了。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ final class MacServiceContainer {
|| $0.manifest.id == .debugAdaptersExtension(descriptor.id.rawValue)
|| $0.manifest.id == .grammarsExtension(descriptor.id.rawValue)
|| $0.manifest.id == .backendExtension(descriptor.id.rawValue)
|| $0.manifest.id == .toolchainsExtension(descriptor.id.rawValue)
|| $0.manifest.id == .projectGeneratorsExtension(descriptor.id.rawValue)
}.map { declaration in
ModuleFactory(manifest: declaration.manifest, contributions: declaration.contributions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,15 @@ public struct DeclarativePluginDescriptor: Equatable, Sendable {
activationPolicy: .onDemand
)))
}
if decoded.hasToolDefinitions && modules.isEmpty {
// Definitions are valid on their own. Give them an enablement owner
// so plugin management can expose them to the settings loader.
modules.append(PluginModuleDeclaration(manifest: ModuleManifest(
id: .toolchainsExtension(decoded.id), displayName: decoded.displayName,
scope: .application, defaultState: enabledByDefault ? .enabled : .disabled,
activationPolicy: .onDemand
)))
}
let debuggedLanguages = Set(debugAdapters.flatMap(\.languageIDs))
let languageSupports = decoded.languages.map { language in
let execution = executionByLanguage[language.id]
Expand Down Expand Up @@ -1385,6 +1394,8 @@ public struct DeclarativePluginDescriptor: Equatable, Sendable {
/// Launch fields stay with Rust Core; the host only needs to know
/// a backend exists.
let backend: ToolingJSONValue?
/// Core owns definition semantics; this bit only supplies an enablement module.
let hasToolDefinitions: Bool

/// What plugin management lists. Fields and steps stay with Rust Core,
/// which evaluates the New Project form and plans every step.
Expand Down Expand Up @@ -1414,12 +1425,13 @@ public struct DeclarativePluginDescriptor: Equatable, Sendable {
settingActions = try values.decodeIfPresent([SettingAction].self, forKey: .settingActions) ?? []
projectGenerators = try values.decodeIfPresent([ProjectGenerator].self, forKey: .projectGenerators) ?? []
backend = try values.decodeIfPresent(ToolingJSONValue.self, forKey: .backend)
hasToolDefinitions = !(try values.decodeIfPresent([ToolingJSONValue].self, forKey: .toolDefinitions) ?? []).isEmpty
}

private enum CodingKeys: String, CodingKey {
case id, displayName, version, pluginAPIVersion, vendor, permissions, activationEvents
case languages, languageServers, executionProviders, buildSystems, vcsProviders, ui, settings, settingActions
case projectGenerators, backend, debugAdapters
case projectGenerators, backend, debugAdapters, toolDefinitions
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions macos/Sources/LitheModuleAPI/Lifecycle/ModuleTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ public extension ModuleID {
ModuleID("\(pluginID).backend")
}

/// Enablement for tool definitions with no process or other contribution module.
static func toolchainsExtension(_ pluginID: String) -> ModuleID {
ModuleID("\(pluginID).toolchains")
}

/// The language grammars one declarative plugin declares, enabled
/// together. Nothing runs while it is enabled; it only gates highlighting.
static func grammarsExtension(_ pluginID: String) -> ModuleID {
Expand Down
5 changes: 4 additions & 1 deletion macos/Sources/LitheModuleAPI/Plugins/PluginTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,16 @@ public struct PluginManifest: Equatable, Codable, Sendable {
"packageTrust": [1],
"backend": [1, 2],
"buildProviders": [1, 2, 3, 4, 5, 6], "buildModelInputs": [1],
"buildSystems": [1, 2], "debugAdapters": [1, 2], "executableResolution": [1],
"buildSystems": [1, 2], "debugAdapters": [1, 2], "executableResolution": [1, 2],
"executionProviders": [1],
"languageServers": [1, 2],
"languages": [1, 2],
"projectGenerators": [1],
"serverProcess": [1],
"settings": [1, 2],
// Toolchain discovery and provider queries are hosted by the read-only settings pages.
"toolDefinitions": [1],
"toolchainProviders": [1],
"ui": [1, 2, 3, 4],
"vcsProviders": [1]
]
Expand Down
67 changes: 67 additions & 0 deletions macos/Tests/LitheTests/ToolchainPluginAdmissionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Foundation
import LitheApplicationKernel
import LitheCoreContracts
import LitheModuleAPI
import Testing
@testable import Lithe

/// Uses the published contract fixtures and production Core adapters at all three admission gates.
@Suite("Toolchain plugin admission")
@MainActor
struct ToolchainPluginAdmissionTests {
@Test func providerIsAvailableReviewedAndLoadedWithBackendEnablement() throws {
let manifest = try fixture("toolchain-provider.plugin.json")
let descriptor = try checkAdmission(manifest)
#expect(descriptor.declaresBackend)
#expect(descriptor.pluginManifest.modules.map(\.manifest.id) == [.backendExtension(descriptor.id.rawValue)])
#expect(MacPluginBackendSessions.toolchainProviderIDs(ofManifest: descriptor.normalizedManifest) == ["mise"])
let review = try PluginMarketplaceTestSupport.evaluator.installReview(
manifest: manifest, expectedID: descriptor.id.rawValue,
expectedVersion: descriptor.pluginManifest.version.description, approvedPrograms: nil)
#expect(review.permissions == ["backend.launch", "toolchains.provide"])
#expect(review.programs.map(\.path) == ["bin/mise-provider"])
}

@Test func standaloneDefinitionHasEnablementAndRequiresRestart() throws {
let descriptor = try checkAdmission(fixture("tool-definition.plugin.json"))
#expect(!descriptor.declaresBackend)
#expect(descriptor.pluginManifest.modules.map(\.manifest.id) == [.toolchainsExtension(descriptor.id.rawValue)])
#expect(descriptor.pluginManifest.modules.allSatisfy { $0.manifest.defaultState == .disabled })
#expect(!descriptor.canActivateWithoutRestart)
let registry = try ValidatedPluginCatalog(manifests: [descriptor.pluginManifest],
hostVersion: BuiltInPluginCatalog.hostVersion)
#expect(registry.manifests.count == 1)
let installed = InstalledPluginPackage(descriptor: descriptor,
installation: PluginInstallationRecord(pluginID: descriptor.id,
activeVersion: descriptor.pluginManifest.version, origin: .localDevelopment),
packageURL: DeclarativePluginTestSupport.repositoryRoot)
let factories = MacServiceContainer.declarativePluginFactories([installed],
executionHost: MacLanguageExecutionHost(processRegistry: ManagedProcessRegistry()),
planner: DeclarativePluginTestSupport.operations)
#expect(factories.map(\.manifest.id) == descriptor.pluginManifest.modules.map(\.manifest.id))
}

private func fixture(_ name: String) throws -> Data {
try Data(contentsOf: DeclarativePluginTestSupport.repositoryRoot
.appendingPathComponent("shared/contracts/plugins/v1/fixtures/\(name)"))
}

private func checkAdmission(_ manifest: Data) throws -> DeclarativePluginDescriptor {
let object = try #require(try JSONSerialization.jsonObject(with: manifest) as? [String: Any])
let id = try #require(object["id"] as? String)
var entry = PluginMarketplaceTestSupport.entry(id: id, repository: "https://github.com/example/toolchain",
version: "1.0.0", archiveURL: "https://github.com/example/toolchain/releases/download/v1.0.0/toolchain.zip",
sha256: String(repeating: "a", count: 64))
var versions = try #require(entry["versions"] as? [[String: Any]])
versions[0]["pluginAPIVersion"] = object["pluginAPIVersion"]
versions[0]["requires"] = object["requires"]
entry["versions"] = versions
let index = try PluginMarketplaceTestSupport.evaluator.validateIndex(
PluginMarketplaceTestSupport.indexData([entry]), sourceKind: .official, platform: "darwin-arm64")
let listed = try #require(index.plugins.first)
#expect(listed.availability.download?.version == "1.0.0")
_ = try PluginMarketplaceTestSupport.evaluator.installReview(manifest: manifest,
expectedID: id, expectedVersion: "1.0.0", approvedPrograms: nil)
return try DeclarativePluginTestSupport.operations.validate(manifest: manifest)
}
}
23 changes: 12 additions & 11 deletions shared/contracts/plugins/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ admit new sources into existing Build candidate sets. Definitions are entirely
plugin-owned, with reserved short IDs checked against host-verified official
provenance when constructing the registry.

Neither native host advertises or integrates this foundation yet. Core consumes
captured host facts; it does not start a provider, run a probe, watch files, scan
the system, persist pins, or change current Java/Maven selection. The broader
proposal remains unsupported where it exceeds this implemented slice. In
particular, `toolchainConsumers`, generic runtime launches, settings pages, mise
and SDKMAN providers, and live backend activation are not implemented here.
Proposal envelopes remain separate from production manifests.
macOS advertises these capabilities for its read-only toolchain settings pages.
The native adapter scans declarations, probes checked executables, queries plugin
backends and watches their inputs; Core consumes captured facts and owns validation
and resolution. Windows does not advertise the capabilities. Saving pins,
`toolchainConsumers`, generic runtime launches and live backend activation remain
unsupported, and current Java/Maven/Build/Run selection is unchanged. Version-manager
implementations such as mise belong to their own plugin packages. Proposal
envelopes remain separate from production manifests. See [the implemented slice](toolchains.md).

## Package layout

Expand Down Expand Up @@ -96,7 +97,7 @@ symbolic links. A host treats an installed package as read-only.
| `settings` | User-adjustable plugin options (level 2 and later). |
| `ui` | Host-rendered tool windows and commands (level 2 and later). |
| `buildSystems` | Project-level build tools (level 3). |
| `toolDefinitions` | Plugin-owned tool policy ([Core foundation](toolchains.md)); requires `toolDefinitions: 1` and `executableResolution: 2`; native adapters are not connected. |
| `toolDefinitions` | Plugin-owned tool policy ([Core foundation](toolchains.md)); requires `toolDefinitions: 1` and `executableResolution: 2`; macOS hosts read-only discovery. |
| `toolchainProviders` | Backend fact-provider declarations ([Core foundation](toolchains.md)); requires `toolchainProviders: 1`, backend/server-process capabilities and `toolchains.provide`. |

Unknown fields are refused (`plugin.manifest.invalid`) so an older host
Expand Down Expand Up @@ -513,9 +514,9 @@ hosts. Level 3 versions each section on its own. A level 3 manifest lists in
| `debugAdapters` | [`debugAdapters[]`](#api-level-4-debug-adapters); v2 adds target arguments/environment | `1`, `2` |
| `projectGenerators` | [`projectGenerators[]`](#project-generators): entries of the New Project window | `1` |
| `backend` | [`backend`](#plugin-backend): the plugin's own long-lived process | `1`, `2` (adds [start without a page and workspace contexts](#backend-2-workspace-contexts)) |
| `toolDefinitions` | [Tool identities, layouts, discovery and four-layer candidates](toolchains.md) | `1` (Core only) |
| `toolchainProviders` | [Provider declarations and permission-bound answer validation](toolchains.md) | `1` (Core only) |
| `executableResolution` | [Shared executable candidates](#shared-executable-candidates-executableresolution-1); v2 adds tool-definition candidates without changing existing Build candidate sets | `1`, `2` (v2 Core only) |
| `toolDefinitions` | [Tool identities, layouts, discovery and four-layer candidates](toolchains.md) | `1` (Core; macOS read-only settings) |
| `toolchainProviders` | [Provider declarations and permission-bound answer validation](toolchains.md) | `1` (Core; macOS read-only settings) |
| `executableResolution` | [Shared executable candidates](#shared-executable-candidates-executableresolution-1); v2 adds tool-definition candidates without changing existing Build candidate sets | `1`, `2` (v2 Core; macOS read-only settings) |

Version 1 of every capability means what its section means at level 2
(runtime launches, launch templates, `initializationOptions`, and so on), so
Expand Down
Loading
Loading