Skip to content
Draft
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
8 changes: 5 additions & 3 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ or removing a command fails until the table changes in the same commit.
| `plugins.editorActions.decode` | Validate independent action registration, collection or click results |
| `plugins.hostApi.describe` | Describe backend host methods and their required grants from Core's method table |
| `plugins.hostApi.authorize` | Check a method, service and current session grants using Core's capability rules; the host still checks session and resource ownership |
| `plugins.workflow` | Validate workflow requests and project native preview, input, output, progress, status and network plans |
| `plugins.editorProviders.decode` | Validate editor provider registrations and provider function results |
| `keymap.decodeImport` | Validate a normalized shortcut import against the host's action catalog |
| `keymap.planImportSources` | Plan the selected provider's declared shortcut source inputs |
Expand Down Expand Up @@ -8813,9 +8814,10 @@ registration is permitted. See [fixtures](../fixtures/application/file-associati

## Plugin workflow projections (`plugins.workflow`)

`operation:"prepare"` takes `{method,params}` and returns strictly checked params
and `{textBytes,outputLines,outputBytes,resources}` limits. Network defaults are
resolved here. `quickPick` takes `{items,query}` and returns source `indices`;
`operation:"prepare"` takes `{method,params,manifest?}` and returns strictly checked params
and `{textBytes,httpHeaderBytes,outputLines,outputBytes,resources}` limits. Network and
preview defaults, resource preview types and status command declarations are resolved
here. `manifest` is the validated calling session manifest when `commandID` is used. `quickPick` takes `{items,query}` and returns source `indices`;
`input` takes `{pick,value}` and returns `{valid}`. `status` takes bounded
`items:[{id,priority}]` and returns ordered `ids`. `treePage` takes `{cursor,
lastCursor,count,lastCount,rows,lastVisible}` and returns `{load}` only near the
Expand Down
90 changes: 89 additions & 1 deletion rust/crates/plugin-rpc/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ pub fn command(payload: Value) -> Result<Value, CoreError> {
let p = payload.as_object().ok_or_else(core_invalid)?;
match p.get("operation").and_then(Value::as_str) {
Some("prepare") => {
object(&payload, &["operation", "method", "params"]).map_err(|_| core_invalid())?;
object(&payload, &["operation", "method", "params", "manifest"])
.map_err(|_| core_invalid())?;
let method = p
.get("method")
.and_then(Value::as_str)
Expand All @@ -374,6 +375,62 @@ pub fn command(payload: Value) -> Result<Value, CoreError> {
CoreError::new(ErrorCode::InvalidRequest, failure.message)
.with_details(failure.code)
})?;
let name = method.strip_prefix("lithe/host/").unwrap_or(method);
if name == "statusBar/setItem" {
if let Some(id) = params.get("commandID").and_then(Value::as_str) {
let declared = p
.get("manifest")
.and_then(|m| m.pointer("/ui/commands"))
.and_then(Value::as_array)
.is_some_and(|commands| {
commands.iter().any(|c| c["id"].as_str() == Some(id))
});
if !declared {
return Err(CoreError::new(
ErrorCode::InvalidRequest,
"The status command is not declared by this plugin.",
)
.with_details(codes::HOST_INVALID_PARAMS));
}
}
}
if matches!(
name,
"preview/openMarkdown" | "preview/openHTML" | "browser/openExternal"
) {
if let Some(path) = params.pointer("/resource/path").and_then(Value::as_str) {
let extension = path
.rsplit('.')
.next()
.unwrap_or_default()
.to_ascii_lowercase();
let supported = if name == "preview/openMarkdown" {
matches!(extension.as_str(), "md" | "markdown" | "mdown")
} else {
matches!(extension.as_str(), "html" | "htm" | "xhtml")
};
if !supported {
return Err(CoreError::new(
ErrorCode::InvalidRequest,
"The resource does not support this preview kind.",
)
.with_details(codes::HOST_UNSUPPORTED_OPTION));
}
}
if name.starts_with("preview/") {
params
.as_object_mut()
.ok_or_else(core_invalid)?
.entry("presentation")
.or_insert(json!("editorAndPreview"));
} else if params.get("resource").is_some() {
params
.as_object_mut()
.ok_or_else(core_invalid)?
.entry("unsaved")
.or_insert(json!("requireSaved"));
}
}
if method.ends_with("network/request") {
let map = params.as_object_mut().ok_or_else(core_invalid)?;
map.entry("method").or_insert(json!("GET"));
Expand Down Expand Up @@ -601,6 +658,37 @@ mod tests {
assert!(result["open"].as_str().unwrap().len() <= OUTPUT_LINE_BYTES);
}

#[test]
fn native_plans_check_preview_type_and_own_command_before_side_effects() {
let context = json!({"contextID":"workspace","generation":1});
let preview = json!({"operation":"prepare","method":"preview/openHTML","params":{
"context":context,"resource":{"rootID":"root","path":"notes.txt"}}});
assert!(command(preview.clone()).is_err());
let mut valid = preview;
valid["params"]["resource"]["path"] = json!("page.HTML");
assert_eq!(
command(valid).unwrap()["params"]["presentation"],
"editorAndPreview"
);
let mut browser = json!({"operation":"prepare","method":"browser/openExternal","params":{
"context":context,"resource":{"rootID":"root","path":"page.html"}}});
assert_eq!(
command(browser.clone()).unwrap()["params"]["unsaved"],
"requireSaved"
);
browser["params"]["unsaved"] = json!("openSavedFile");
assert_eq!(
command(browser).unwrap()["params"]["unsaved"],
"openSavedFile"
);
let mut status = json!({"operation":"prepare","method":"statusBar/setItem","params":{
"context":context,"id":"state","text":"Ready","commandID":"run"},
"manifest":{"ui":{"commands":[{"id":"other"}]}}});
assert!(command(status.clone()).is_err());
status["manifest"]["ui"]["commands"][0]["id"] = json!("run");
assert!(command(status).is_ok());
}

#[test]
fn workflow_fixture_covers_projection_and_paging_boundaries() {
let fixture: Value =
Expand Down
5 changes: 5 additions & 0 deletions rust/fixtures/plugins/workflow-v1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"cases": [
{
"name": "browser resource defaults to requiring saved contents",
"request": {"operation":"prepare","method":"browser/openExternal","params":{"context":{"contextID":"workspace","generation":1},"resource":{"rootID":"root","path":"page.html"}}},
"result": {"params":{"context":{"contextID":"workspace","generation":1},"resource":{"rootID":"root","path":"page.html"},"unsaved":"requireSaved"},"limits":{"textBytes":131072,"httpHeaderBytes":16384,"outputLines":4000,"outputBytes":524288,"resources":16}}
},
{
"name": "filter matches every word across item fields in source order",
"request": {"operation":"quickPick","items":[{"label":"Alpha","description":"Rust"},{"label":"Beta","detail":"RUST"}],"query":"rust beta"},
Expand Down
5 changes: 4 additions & 1 deletion shared/plugins/contract/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4478,7 +4478,10 @@ the user closes the tab or context. They do not write workspace files or bundle
resources. A new call with the same ID updates its tab. Inline Markdown cannot
resolve local or relative resources; inline HTML serves only its supplied
page and cannot read adjacent local files. Remote web content follows the
existing preview policy. Resource previews use the live editor buffer.
existing preview policy. Resource previews use the live editor buffer. Markdown
resources require `.md`, `.markdown` or `.mdown`; HTML resources require `.html`,
`.htm` or `.xhtml` (case-insensitive), otherwise `unsupportedOption` is returned
before opening an editor tab.
`presentation` defaults to `editorAndPreview`, or is `previewOnly`; `range`
uses the normal one-based UTF-16 range and reveals its start as a caret.
A missing native WebView may return `unsupportedOption` for HTML.
Expand Down
2 changes: 1 addition & 1 deletion shared/plugins/guides/plugin-api-pr-guide.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ PR 必须逐项回答:
1. 在契约 README 写清参数、结果、错误码、权限、生命周期、缺省行为及平台限制;schema、fixture 和执行代码一致。
2. 在对应 `guides/` 或 `reference/` 专题页补充用法,并从已有入口链接到新页面。仅写在 PR、实施计划、宿主源码或 Agent Note 中,不算公开契约。
3. 更新 [协议更新记录](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/reference/protocol-changelog.md):修改协议或 API、PR、修改人(PR 作者)及合入日期。未合入就如实写“待合入”,合入时回填真实日期;没有新版本也要登记。确有新版本时,另更新“按协议查首次出现”。
4. 新增或修改宿主方法、通知时,PR 正文逐个列出下表。Core 的 [API 总表](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/reference/api-catalog.md)中英方法或通知表,以及更新记录的“宿主方法(按 API 编号)”索引同步逐项登记;同类方法分几次 PR 加入时,分别记自己的 PR。
4. 新增或修改宿主方法、通知时,PR 正文逐个列出下表,按 API 编号升序排列,“用途”用中文,方法名保持真实协议名;没有编号的 `—` 放在最后。Core 的 [API 总表](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/reference/api-catalog.md)中英方法或通知表,以及更新记录的“宿主方法(按 API 编号)”索引同步逐项登记;同类方法分几次 PR 加入时,分别记自己的 PR。创建 PR 后将文档中的“本 PR”回填为真实编号;合入日期只在确认合并后回填。
5. 搜索并检查所有受影响消费者;新增或修改的公共插件 API 在 Rust、Go、Node、Java 四个官方 SDK 中同步补齐,更新对应类型、专题说明和能力支持表。不能只补提出需求的插件所用语言。

新增或修改方法、通知的表格格式如下;把每一项单独填一行:
Expand Down
4 changes: 4 additions & 0 deletions shared/plugins/guides/plugin-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ try {

`showInputBox` 的 `password:true` 用于明确向用户索取一个秘密,不预填、不记录;保存应调用本插件的 `credentials.set`。HTTP 不自动读取浏览器 Cookie,也不共享其他插件或宿主业务的凭据。默认返回重定向而不跟随,插件检查状态后自行决定下一步。网络请求由桌面发出,远程后端需要访问远端网络时使用自己的网络实现。

状态项的 `commandID` 只能引用本插件清单声明的命令。资源预览按 Markdown 或 HTML 的扩展名选择对应方法;省略呈现方式时显示编辑器和预览。浏览器打开资源默认要求缓冲区已保存;仅在明确希望打开磁盘旧内容时传 `unsaved: "openSavedFile"`,宿主不会自动保存。

树先返回已加载条目和 `cursor`。`expand` 再加载某父节点的子项;`loadMore` 返回累积范围或补丁,并更新 cursor。`views.refresh(workspace,{instance:event.instance})` 使当前显示失效;刷新后使用稳定 item ID 保留选择和展开。不要把每页当成新的整棵树而丢掉先前条目。

## English
Expand All @@ -51,6 +53,8 @@ ID returned by progress creation is also its progress ID. SDK end methods dispos
the local route; disposal of the subscription also ends the native progress.
Use cancellation events to abort your own operation.

Status commands must be declared by the same plugin. Use the preview method matching the resource extension; omitted presentation shows the editor and preview. Opening a browser resource defaults to requiring saved contents. Pass `unsaved: "openSavedFile"` only to explicitly open the disk version; the host never saves automatically.

For lazy trees, return retained items and an opaque cursor. On expand/loadMore,
return the full accumulated range or patches and advance the cursor. A repeated
cursor or non-growing range stops automatic paging. Refresh only an instance
Expand Down
16 changes: 8 additions & 8 deletions shared/plugins/reference/api-catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Lithe 的插件公共 API 按 [API 实施计划](https://github.com/1lck/Lithe-I
| --- | --- | --- | --- | --- |
| API-01、API-37 | `getCapabilities` | 查询协商的协议版本、后端运行位置(`backendAuthority`)、当前可用的服务和限制;由 Core 直接回答 | 每个插件会话都有 | 0 |
| API-01 | `subscriptions/dispose` | 取消一个订阅,即 `workspace/watch`、`editor/registerActions`、`terminal/onExit` 返回的 `subscriptionID`;未知或已取消的 ID 也返回 `null` | 每个插件会话都有 | 0 |
| API-03 | `statusBar/setItem` | 创建或替换状态项 | `statusBar.write` | 0 |
| API-03 | `statusBar/setItem` | 创建或替换状态项;命令须属于本插件清单 | `statusBar.write` | 0 |
| API-03 | `statusBar/removeItem` | 移除自己的状态项 | `statusBar.write` | 0 |
| API-05 | `workspace/listContexts` | 列出当前的工作区上下文,带变化序号 `revision` | `workspace.metadata` | 0 |
| API-05 | `workspace/getContext` | 读取一个工作区上下文 | `workspace.metadata` | 0 |
Expand Down Expand Up @@ -120,9 +120,9 @@ Lithe 的插件公共 API 按 [API 实施计划](https://github.com/1lck/Lithe-I
| API-13 | `views/refresh` | 使当前会话拥有的可见视图失效 | `views.refresh` | 0 |
| API-15 | `editor/open` | 在编辑器中打开文件,没有缓冲区时从磁盘读取;可以前台或后台打开,并定位光标 | `editor.open` | 0 |
| API-15 | `editor/reveal` | 参数和 `editor/open` 相同,但只处理已打开的文件;文件没打开时返回 `plugin.host.notFound`,不会从磁盘打开 | `editor.open` | 0 |
| API-16 | `preview/openMarkdown` | 预览资源或只读内联 Markdown | `preview.open` | 0 |
| API-16 | `preview/openHTML` | 预览 HTML 资源的实时缓冲区或只读内联文本(`editorAndPreview` 或 `previewOnly`) | `preview.open` | 0 |
| API-16 | `browser/openExternal` | 在外部浏览器打开 HTTP(S) 地址或已保存的 HTML 文件 | `browser.open` | 0 |
| API-16 | `preview/openMarkdown` | 预览 Markdown 资源(`.md`、`.markdown`、`.mdown`)或只读内联文本 | `preview.open` | 0 |
| API-16 | `preview/openHTML` | 预览 HTML 资源(`.html`、`.htm`、`.xhtml`)的实时缓冲区或只读内联文本;默认 `editorAndPreview` | `preview.open` | 0 |
| API-16 | `browser/openExternal` | 在外部浏览器打开 HTTP(S) 地址或已保存的 HTML 文件;默认 `requireSaved` | `browser.open` | 0 |
| API-17 | `window/showQuickPick` | 选择一个或多个稳定条目 ID | `window.input` | 0 |
| API-17 | `window/showInputBox` | 请求文本或掩码密码输入 | `window.input` | 0 |
| API-17 | `window/showInformation` | 显示信息消息,可以带按钮,返回用户点的按钮序号 | `window.messages` | 0 |
Expand Down Expand Up @@ -292,7 +292,7 @@ Requests a backend sends to the host, all prefixed `lithe/host/`; the tables omi
| --- | --- | --- | --- | --- |
| API-01, API-37 | `getCapabilities` | Reports the negotiated protocol version, where the backend runs (`backendAuthority`), and the services and limits available now; Core answers it itself | Every plugin-owned session | 0 |
| API-01 | `subscriptions/dispose` | Cancels a subscription, that is, a `subscriptionID` returned by `workspace/watch`, `editor/registerActions`, or `terminal/onExit`; an unknown or already disposed ID also returns `null` | Every plugin-owned session | 0 |
| API-03 | `statusBar/setItem` | Create or replace a status item | `statusBar.write` | 0 |
| API-03 | `statusBar/setItem` | Create or replace a status item; commands must belong to the plugin manifest | `statusBar.write` | 0 |
| API-03 | `statusBar/removeItem` | Remove an owned status item | `statusBar.write` | 0 |
| API-05 | `workspace/listContexts` | Lists the current workspace contexts with the change counter `revision` | `workspace.metadata` | 0 |
| API-05 | `workspace/getContext` | Reads one workspace context | `workspace.metadata` | 0 |
Expand Down Expand Up @@ -322,9 +322,9 @@ Requests a backend sends to the host, all prefixed `lithe/host/`; the tables omi
| API-13 | `views/refresh` | Invalidate a visible owned view instance | `views.refresh` | 0 |
| API-15 | `editor/open` | Opens a file in the editor, reading it from disk when no buffer exists; opens it in the foreground or background and can place the caret | `editor.open` | 0 |
| API-15 | `editor/reveal` | Takes the same params as `editor/open` but only handles files already open; a file that is not open returns `plugin.host.notFound` and is not opened from disk | `editor.open` | 0 |
| API-16 | `preview/openMarkdown` | Show a resource or read-only inline Markdown | `preview.open` | 0 |
| API-16 | `preview/openHTML` | Previews an HTML resource’s live buffer or read-only inline text (`editorAndPreview` or `previewOnly`) | `preview.open` | 0 |
| API-16 | `browser/openExternal` | Opens an HTTP(S) URL or a saved HTML file in the external browser | `browser.open` | 0 |
| API-16 | `preview/openMarkdown` | Show a Markdown resource (`.md`, `.markdown`, `.mdown`) or read-only inline text | `preview.open` | 0 |
| API-16 | `preview/openHTML` | Preview an HTML resource (`.html`, `.htm`, `.xhtml`) live buffer or read-only inline text; defaults to `editorAndPreview` | `preview.open` | 0 |
| API-16 | `browser/openExternal` | Open an HTTP(S) URL or a saved HTML file externally; defaults to `requireSaved` | `browser.open` | 0 |
| API-17 | `window/showQuickPick` | Choose one or more stable item IDs | `window.input` | 0 |
| API-17 | `window/showInputBox` | Request text or a masked password | `window.input` | 0 |
| API-17 | `window/showInformation` | Shows an information message, optionally with buttons, and returns the index of the button the user chose | `window.messages` | 0 |
Expand Down
Loading