Skip to content

Commit 545ca11

Browse files
authored
feat(plugins): 插件视图(界面树与画布节点)取代原生 UI 文档,新增设置区域与三个 SDK 的 view() (#104)
* feat(plugins): 插件视图(界面树与画布节点)取代原生 UI 文档,新增设置区域与三个 SDK 的 view() - 契约:plugin-ui.schema.json 取代 native-ui.schema.json。工具窗口和设置区域的 view.function 指向后端视图函数,按 open/close/click/change/select/activate/ viewport/settings 事件返回整个视图、补丁或 {}。 - Core:plugin-native-ui 改名为 plugin-ui,新增界面树、画布、补丁和字段检查; 新命令 plugins.ui.applyResult 按清单、界面和上一版视图校验结果,超出预算或违反 界面规则时返回 plugin.ui.invalidView(带 field)。 - 清单新增 settingRegions(最多 16 个):在语言、构建系统、编译器页或插件自己的 设置标签放搜索关键词和插件视图;l10n 可追加其他语言的关键词。 - SDK:Node、Rust、Java 新增 view(id, handler),统一按同一规则读视图事件,不合法时 sdk.view.invalidEvent,处理函数不会运行;null 的可选字段视为缺省。 - 文档:契约 README、ui/settings 领域页、API 总表(API-13、API-19、API-37)、 能力版本页和协议更新记录。 - 顺手修正:toolchain_definitions 测试的 clippy err_expect,settings_view 测试的 rustfmt 格式。 * docs(plugins): 更新记录待合入条目链接 #104
1 parent a76f7d1 commit 545ca11

72 files changed

Lines changed: 5834 additions & 2490 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎rust/Cargo.lock‎

Lines changed: 10 additions & 12 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: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ or removing a command fails until the table changes in the same commit.
445445
| `ai.inlineEdit.plan` | Plan a credential-free inline edit request |
446446
| `ai.inlineEdit.decode` | Decode the replacement text of an inline edit response |
447447
| `plugins.declarative.validate` | Validate and normalize a declarative plugin manifest |
448-
| `plugins.nativeUI.validateData` | Validate native plugin UI data with declaration identity and node budgets |
448+
| `plugins.ui.applyResult` | Check a backend result for a plugin view and return the whole view to draw |
449449
| `plugins.web.open` | Register a plugin page for a web tool window |
450450
| `plugins.web.close` | Forget a plugin page and lists its calls to cancel |
451451
| `plugins.web.resource` | Decide how a plugin page request is served |
@@ -4953,6 +4953,12 @@ Success returns `{ status: "ok", state }`. The state contains:
49534953
the manifest's section title (the empty heading first), so a translation
49544954
changes only the shown `title`. References are zero-based indices
49554955
into `rows` and `actions`; declaration order is retained within each section.
4956+
- `region`: present when the plugin placed a settings region on its own
4957+
Settings tab: `{ id, keywords, view? }`. `keywords` are the manifest
4958+
keywords followed by the translated ones that differ, so both languages
4959+
find the page. `view` is `{ function }`; the host calls it and draws each
4960+
result through `plugins.ui.applyResult`. Each entry of `pages` carries the
4961+
region placed on that page in the same shape.
49564962
- `editors`: `{ global, project }`, each an array in exactly `rows` order.
49574963
Every entry contains `value`, `resetValue`, `source`, `editable`, `overridden`
49584964
and `invalidStored`, plus `input`/`resetInput` native-control projections.
@@ -6224,21 +6230,33 @@ registered in Core for their lifetime:
62246230
`build.runChanged` and returns `{ message }`, `null` when the page is
62256231
closed or the progress is for a call that ended or has no page ID.
62266232

6227-
### Native plugin UI data
6228-
6229-
`plugins.nativeUI.validateData` accepts `{ ui, data }`, where `ui` is the
6230-
validated native declaration (`schemaVersion` 0) and `data` is a provider's `{ nodes }`
6231-
reply. It returns `{ status: "ok", nodes }` or
6232-
`{ status: "rejected", error: { code: "plugin.ui.invalidData", message } }`.
6233-
Malformed envelopes remain Core `invalid_request` failures. The operation uses
6234-
the same identity, literal label, nesting and node budgets as manifest validation
6235-
and rejects data above 1 MiB. Form declarations validate bounded input/select/checkbox
6236-
controls (including search/editor/segmented/stepper), typed scalar defaults, choices,
6237-
info, button action references/width policies and onCommit references; form source replies
6238-
require empty nodes. Hosts inject this typed operation into their
6239-
presentation feature; views never call the C ABI. Windows can reuse validation
6240-
when it later adds a native renderer; Core support does not make Windows
6241-
advertise native plugin content.
6233+
### Plugin views
6234+
6235+
`plugins.ui.applyResult` accepts `{ manifest, surface, view?, result }`.
6236+
`surface` names exactly one declared place that draws a view:
6237+
`{ toolWindowID }` for a tool window whose body is `view`, or
6238+
`{ settingRegionID }` for a settings region with a `view`. `view` is the
6239+
view the host drew last and is absent before the first result. `result` is
6240+
what the plugin's view function returned: `{ view }` (a whole view),
6241+
`{ patches }` (edits to `view`) or `{}` (nothing changed).
6242+
6243+
It returns `{ status: "ok", view: { view, changed } }`, where `view` is the
6244+
complete checked view to draw and `changed` tells whether it differs from
6245+
the one drawn, or `{ status: "rejected", error: { code:
6246+
"plugin.ui.invalidView", message, field } }`, where `field` is the JSON path
6247+
of the first problem (`result.view[0].type`, `result.patches[1].id`, or
6248+
`view[...]` for a patched view). After a refusal the host keeps drawing the
6249+
previous view. Malformed envelopes remain Core `invalid_request` failures.
6250+
6251+
Core checks the node vocabulary, the budgets, which nodes each surface
6252+
allows, and every reference to the manifest: bound controls and setting rows
6253+
name declared settings of a type the control edits, setting-action buttons
6254+
name declared setting actions, and tool rows name tools the plugin defines
6255+
or requires. Patches apply in order to a copy of `view`; a patch whose target
6256+
is missing refuses the whole result. Hosts call this operation for every
6257+
result and only render; they keep no second validator or patch engine. The
6258+
vocabulary and budgets are in the plugin contract README and
6259+
`plugin-ui.schema.json`.
62426260

62436261
### Workspace indexing policy
62446262

@@ -7186,16 +7204,23 @@ This is an internal desktop command, not a new public plugin host method.
71867204

71877205
Internal desktop commands reuse the validated settings manifest. They do not
71887206
add plugin RPCs or admit capabilities. `plugins.settings.catalog` accepts up to
7189-
64 `{manifest, owner: {pluginID, version}, enabled}` records. It validates all
7207+
64 `{manifest, owner: {pluginID, version}, enabled, localizations?}` records
7208+
and an optional `language`. It validates all
71907209
identities, rejects duplicates and returns deterministic `pages` (up to 512),
7191-
with stable `key`, `kind` (`language` or `buildSystem`), opaque `id`, display
7192-
`title`, and plugin-ID ordered `contributors` (`pluginID`, `version`, `title`,
7193-
`sections`). Sections reference indices in the complete settingsState rows and
7194-
actions. Only enabled contributors create pages; action-only pages are valid.
7210+
with stable `key`, `kind` (`language`, `buildSystem` or `compiler`), opaque
7211+
`id`, display `title`, and plugin-ID ordered `contributors` (`pluginID`,
7212+
`version`, `title`, `sections`, `region?`, `localization?`). Sections reference
7213+
indices in the complete settingsState rows and actions. Only enabled
7214+
contributors create pages; action-only and region-only pages are valid.
71957215
Names come from enabled language/build declarations, with opaque ID fallback.
7196-
`settingsState.pages` supplies the same per-plugin placement projections, with
7197-
section titles translated when the state is. Catalog contributor sections keep
7198-
the manifest headings.
7216+
`settingsState.pages` supplies the same per-plugin placement projections.
7217+
`region` is the settings region the contributor placed on the page
7218+
(`{ id, keywords, view? }`, as in settingsState); hosts add its keywords to
7219+
the page's search terms. With `language`, each record's `localizations`
7220+
follows the settingsState rules: section titles are translated, translated
7221+
region keywords are appended, and `localization` is that plugin's report.
7222+
Without `language`, sections keep the manifest headings and no report is
7223+
returned.
71997224

72007225
`plugins.settings.navigation` accepts at most 576 `items` (512 contributed pages plus 64 host entries), up to three levels
72017226
deep, with stable `id`, `title`, nullable `parent`, `group`, `expanded` and optional `keywords`, plus `query` (at

‎rust/crates/core/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ lithe-plugin-manifest = { path = "../plugin-manifest" }
4040
lithe-plugin-lifecycle = { path = "../plugin-lifecycle" }
4141
lithe-plugin-marketplace = { path = "../plugin-marketplace" }
4242
lithe-plugin-model = { path = "../plugin-model" }
43-
lithe-plugin-native-ui = { path = "../plugin-native-ui" }
43+
lithe-plugin-ui = { path = "../plugin-ui" }
4444
lithe-plugin-output-links = { path = "../plugin-output-links" }
4545
lithe-plugin-rpc = { path = "../plugin-rpc" }
4646
lithe-plugin-web-content = { path = "../plugin-web-content" }

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum CoreCommand {
5959
SearchActions,
6060
/// AI commit, pull request and inline edit planning run by `lithe-ai` (`ai.*`).
6161
Ai(AiCommand),
62-
/// Plugin manifests, native UI and web content, plugin settings, installed
62+
/// Plugin manifests, plugin views and web content, plugin settings, installed
6363
/// plugins and the marketplace (`plugins.*`).
6464
Plugins(PluginsCommand),
6565
/// Debug adapters, transports, sessions, breakpoints and inspection (`debug.*`).
@@ -206,8 +206,8 @@ pub enum AiCommand {
206206
pub enum PluginsCommand {
207207
/// Validates and normalizes a declarative plugin manifest (`plugins.declarative.validate`).
208208
DeclarativeValidate,
209-
/// Validates native plugin UI data with declaration identity and node budgets.
210-
NativeUIValidateData,
209+
/// Checks what a backend returned for a plugin view and gives the whole view to draw (`plugins.ui.applyResult`).
210+
UIApplyResult,
211211
/// Registers a plugin page for a web tool window (`plugins.web.open`).
212212
WebOpen,
213213
/// Forgets a plugin page and lists its calls to cancel (`plugins.web.close`).
@@ -1040,9 +1040,7 @@ impl CoreCommand {
10401040
"plugins.declarative.validate" => {
10411041
Some(Self::Plugins(PluginsCommand::DeclarativeValidate))
10421042
}
1043-
"plugins.nativeUI.validateData" => {
1044-
Some(Self::Plugins(PluginsCommand::NativeUIValidateData))
1045-
}
1043+
"plugins.ui.applyResult" => Some(Self::Plugins(PluginsCommand::UIApplyResult)),
10461044
"plugins.web.open" => Some(Self::Plugins(PluginsCommand::WebOpen)),
10471045
"plugins.web.close" => Some(Self::Plugins(PluginsCommand::WebClose)),
10481046
"plugins.web.resource" => Some(Self::Plugins(PluginsCommand::WebResource)),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `plugins.*` commands: plugin manifests, native UI and web content, plugin settings,
1+
//! `plugins.*` commands: plugin manifests, plugin views and web content, plugin settings,
22
//! installed plugins and the marketplace.
33
44
use super::plugin_response;
@@ -12,8 +12,8 @@ pub(super) fn dispatch(
1212
payload: Value,
1313
) -> CoreResponse {
1414
match command {
15-
PluginsCommand::NativeUIValidateData => {
16-
plugin_response(id, payload, lithe_plugin_native_ui::validate_data_command)
15+
PluginsCommand::UIApplyResult => {
16+
plugin_response(id, payload, lithe_plugin_manifest::apply_result_command)
1717
}
1818
PluginsCommand::WebOpen => {
1919
plugin_response(id, payload, lithe_plugin_web_content::open_command)

0 commit comments

Comments
 (0)