Repository navigation
Conversation
…n protocol 2) Pins the commit of 1lck/Lithe-IDEA#1470 that adds the backend capability, plugin-function protocol 2 with the credentials host service, and lists the Rust SDK. Re-pin to preview once that pull request merges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lithe-plugin-sdk implements plugin-function protocols 1 and 2 for the
packaged backend a plugin declares under `backend`: framing, negotiation,
functions on their own threads with progress and cancellation, runtime
registration, error mapping (PluginError, internal failures, panics), and
the credentials host service. It depends only on serde_json.
The sample backend (notes in ${stateDir}, a secret in the host's
credential store, cancellation) runs a new end-to-end scenario against
Rust Core in which the test serves the host requests. CI tests on Rust
1.87 and lints on stable; sdk-rust-v* tags release a .crate and its SHA-256.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 tasks done
…plugin) Lithe preview merged 1lck/Lithe-IDEA#1470. The mirror now matches that merge commit: web bridge 2 file dialogs (dialog.openFile, dialog.saveFile) and the current Windows WebView2 status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1lck
marked this pull request as ready for review
October 25, 2026 04:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
数据库模块已改造成独立插件(主仓库 1lck/Lithe-IDEA#1470,已合并;插件现作为 Lithe Store 社区插件发布)。插件后端用 Rust 写,同一份代码给两个平台用,所以需要一个官方 Rust SDK。主仓库 #1470 已经在契约里新增了:
backend1 能力:插件自己的后端进程;lithe/host/credentials/*)。本 PR 是这些契约在 SDK 侧的实现。
改动
1. 契约镜像(单独提交
contract: pin …)contract.lock.json和contract/v1/同步到 Lithe previewd046fd1(#1470 的合并提交;新增网页桥接第 2 版的文件对话框和当前 Windows WebView2 状态)。backend.plugin.jsonfixture、函数协议 v2 /hostRequestsgolden cases、backend的拒绝用例和 schema 字段。18345cc)之后主仓库已合入的契约变更:native UI schema 和 fixtures、项目生成器 fixtures。2.
sdk/rust:lithe-plugin-sdkcrate(新增)只依赖
serde_json,基于线程,MSRV Rust 1.87。framing:LSP
Content-Length帧,限制与 Node SDK 一致(header 8 KiB、body 64 MiB)。非 JSON 的 body 回-32700,不破坏帧位置。生命周期:
initialize→shutdown→exit。初始化前的请求回-32002,关闭中回-32600。退出码为shutdown+exit→ 0,其余 → 1。协商:优先应答 host 提供的最新版本(2 → 1)。host 没提供就不声明函数,此时调用回
-32602。函数:
lithe/function/progress上报,message 截到 1024 字节、percentage 截到 100,调用结束后丢弃。$/cancelRequest、shutdown、反注册都会触发Cancellation。它提供is_cancelled、check、wait_timeout、on_cancel回调。错误映射:
PluginError-32000,data.code带插件自己的错误码-32603通用消息,细节只写 stderr-32800运行时注册:
BackendHandle::register_function/unregister_function发lithe/function/register/unregister,并按调用顺序串行。注册被拒绝时回滚;反注册时取消该函数正在运行的调用。凭据:
Credentials::get/set/delete,只在协商到 v2 时可用,否则返回sdk.protocol.notNegotiated,不发送任何请求。key 和 secret 先在本地校验。从Context拿到的凭据请求会随调用取消立即返回sdk.call.cancelled,?会把它转成取消应答。stdout 保护:Unix 上
listen()把协议输出移到 stdout 的 dup,再把 fd 1 指向 stderr。这样插件或依赖里误用println!不会破坏协议。测试:
tests/session.rs有 13 个用例,脚本化 host 通过进程内 pipe 驱动 session,所有等待都有上限,本地连跑 30 次稳定。3. 示例
sdk/rust/examples/sample-backend完整插件:
plugin.json(backend+credentials.store+ web 工具窗口)、CSP 合规的网页(ui/)和后端。演示的能力:${stateDir}存笔记,带进度;note.clear,重启时如果已有笔记,就在on_initialize里直接提供;4. 端到端:
sdk/e2e/plugin_sdk/backend.rs+plugin_sdk_rust.rs测试扮演宿主:
backend: true展开 launch plan,以pluginBackend:<id>启动打包好的示例,并传入hostServices;hostRequest事件(lsp.hostResponse)。覆盖:
credentials.store时 Core 直接拒绝,请求不会到达宿主;scripts/sdk-e2e.mjs会用 Cargo 编译示例(也可以用LITHE_PLUGIN_SDK_RUST_SAMPLE指定已编译的可执行文件),并多跑plugin_sdk_rust。5. CI / 发布 / 文档
verify.yml新增Rust SDKjob:Rust 1.87 跑测试,stable 跑fmt --check和clippy -D warnings。e2e 的缓存加上sdk/rust/target。release-rust-sdk.yml:推sdk-rust-v*标签时校验版本、跑测试,并发布lithe-plugin-sdk-rust-<v>.crate和.sha256。sdk/rust/README.md;根 README 的 SDK 表、测试命令和发版说明加入 Rust;.gitignore忽略sdk/rust/target/。验证(本地,macOS arm64)
cargo test --locked:22 个测试全部通过。cargo clippy --all-targets -D warnings和cargo fmt --check都干净。node scripts/sdk-e2e.mjs --source <#1470 工作树> --ref feat/database-plugin:Node(构建、VCS)、Java、Rust 三个 e2e 全部通过。node scripts/sdk-e2e.mjs(默认用锁定的d046fd1)三个 e2e 全部通过;node scripts/contract.mjs verify --upstream39 个文件校验通过;CI 全绿。node scripts/contract.mjs verify:39 个文件与锁一致。node --test scripts/*.test.mjs:13 个通过。🤖 Generated with Claude Code