Repository navigation
feat(sdk): 三种 SDK 接入 litheLogging 1 结构化诊断 - #17
Merged
Merged
Conversation
- Node、Java、Rust SDK 在 initialize 中强制协商 litheLogging 1,删除自由文本 log API,改为通过 lithe/log 上报受控事实(finished/failed/degraded/recovered) - 操作终态自动上报并保留真实 op;成功可按注册或当前调用抑制,失败始终保留; 初始化完成前最多缓存八条,响应后发送;正常终态先于 RPC 响应 - 快捷键导入请求 lithe/keymap/import 也自动上报终态,事实中的 operation 用 Core 注册的线协议方法名,而不是按 provider 区分的调用 id;三种 SDK 的 operation 白名单同步加入该方法 - Rust SDK 在捕获范围内屏蔽 panic payload,范围外保留原 panic hook - 新增 guides/plugin-logging.md,更新三种 SDK README、示例与端到端场景
xiaoyumuxi
marked this pull request as ready for review
November 4, 2026 02:51
This was referenced Nov 4, 2026
Core's catalog queue is process-global and the tests of one binary run in parallel, so one test's drain could take another plugin's terminal facts (CI saw the Node build scenario consume the VCS checkin fact). Every drain now happens under one lock into a shared buffer, and each test takes only the facts on its own plugin's channel.
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.
概要
三种官方插件后端 SDK(Node、Java、Rust)接入结构化日志 v2:SDK 在 initialize 中协商
litheLogging1,删除自由文本日志 API,改为通过lithe/log通知上报四种受控诊断事实,由 Core 统一校验、脱敏并写入plugins/<id>/host。依赖宿主 PR https://github.com/1lck/Lithe-IDEA/pull/1699(Core 侧协议、目录事件和共享契约)。本 PR 不直接修改
contract/v1:按仓库规则,宿主 PR 合并后再运行node scripts/contract.mjs sync --revision <合并后的 preview commit>同步契约副本和contract.lock.json。协议与公共 API(三种 SDK 一致)
experimental.litheLogging.versions是否包含 1,包含则回答litheLogging: {"version": 1};不包含时 initialize 返回错误 “The backend requires litheLogging version 1.”,不再退回旧的 stderr 文本日志。litheLogging由 SDK 协商,插件自己在 capabilities 里声明会被拒绝(和litheBuild等一致)。context.log/backend.log、JavaCallContext.log/Backend.log(含带Throwable的重载)、RustContext::log/Backend::log(原来都是写 stderr)。diagnostics()(Node 为diagnostics属性)提供degraded(operation, code, count?)和recovered(operation, code, count?),用于插件自己报告降级和恢复;suppressSuccessDiagnostics()(当前调用)和backend.suppressSuccessDiagnostics(operation)(按注册)用于静默高频成功。终态operationFinished/operationFailed只由 SDK 自动产生,插件不能手写。operationFinished(INFO)、operationFailed(ERROR)、degraded(WARN)、recovered(WARN),字段只有operation、durationMs、code、count、operationId,不能带消息正文、路径、SQL 或其他用户数据。Diagnostics模块(Nodesrc/diagnostics.mjs、JavaDiagnostics.java、Rustsrc/diagnostics.rs):在本地先校验 token 字符集和长度、已知 operation 白名单以及字段组合;不合法的事实在 SDK 内拒收(sdk.logging.invalidOperation等),不会发给 Core。initialize、shutdown、notification、function-call、result-encoding)、lithe/build/*、lithe/vcs/*和lithe/keymap/import,与 Core 的known_operation一一对应。自动上报行为
operationFinished带耗时,失败为operationFailed带稳定错误码;事实带 wire 请求号作为operationId,Core 据此关联回宿主 op。lithe/keymap/import请求也自动上报终态。事实中的operation使用 Core 注册的线协议方法名lithe/keymap/import,而不是按 provider 区分的调用 id(keymap:<provider>);公开的context.function_id()仍返回keymap:<provider>,与上游行为一致。各语言实现细节
backend.mjs的#run增加诊断 operation 参数,#invokeKeymap传入lithe/keymap/import;errors.mjs、host.mjs配合调整;index.d.ts删除log,新增Diagnostics接口、diagnostics与suppressSuccessDiagnostics。Backend.run增加诊断 operation 参数,invokeKeymap传入lithe/keymap/import;CallContext、Cancellation、HostChannel、PluginError、Processes配合删除自由文本日志、改用事实上报。backend.rs新增常量KEYMAP_IMPORT_METHOD,function_answer改为显式接收诊断 operation(普通调用传function_id,快捷键导入传线协议方法名);worker 启动失败按同一 operation 上报worker_start_failed;新增panic_boundary.rs,在 SDK 捕获范围内屏蔽 panic payload(不把 panic 文本当作日志外泄),范围外保留原 panic hook;修复 clippynonminimal_bool(改用is_none_or)。文档、示例与端到端
guides/plugin-logging.md:说明协商、四种事实与级别映射、自动上报规则、抑制规则、白名单,以及插件不应该自己写日志文件。README.md和三种 SDK 的 README 删除旧log用法,改为诊断事实示例;Node/Java/Rust 示例后端同步更新。scripts/sdk-e2e.mjs与sdk/e2e/plugin_sdk/{mod,backend,vcs}.rs:端到端场景校验 Core 写入的通道、级别、op 关联、耗时和隐私(不出现正文)。测试
diagnostics.test.mjs(新增)以及 backend/build/vcs/keymap 测试;keymap.test.mjs断言快捷键导入上报恰好一条operationFinished/lithe/keymap/import。BackendTest补诊断场景,KeymapTest断言同上,TestHost支持读取lithe/log消息。tests/session.rs补协商、缓存、顺序、抑制、panic 屏蔽等场景;tests/keymap.rs的 initialize 提供litheLogging,断言快捷键导入在响应前恰好一条事实。验证
本地在 rebase 到最新
main(f968e3f)之后完成:node --test sdk/node/test/*.test.mjs77/77;npm run test:types通过。mvn verify64 项通过(BUILD SUCCESS)。cargo fmt --check、cargo clippy -- -D warnings、全部单元、集成、文档测试通过。node --test scripts/*.test.mjs16/16。node scripts/sdk-e2e.mjs --source <宿主工作树> --ref codex/owned-plugin-logging(宿主 286c0090d)9/9 通过,含三种 SDK 的快捷键导入场景。本轮更新(宿主 #1699 合并后)
main,contract.lock.json固定到宿主合并提交7a24126eca3a26775daeb84db38ae04bec938d1a(含litheLogging1);本分支已合入该main。之前固定在旧宿主上的端到端失败,是因为新 SDK 按设计拒绝不支持litheLogging1 的宿主,现在不会再出现。sdk/rust/plugin-sdk/src/diagnostics.rs:请求号回退改用?,修复 CI 中 stable clippy 1.99 报的clippy::question_mark,行为不变。sdk/e2e/plugin_sdk/mod.rs:修复端到端 CI 偶发失败。同一个测试二进制里的测试并行运行,共用 Core 进程级的诊断事实队列(diagnostics.drainCoreEvents),一个测试排空时会把另一个测试插件的事实取走,导致对方断言找不到事实。现在所有排空都在一把锁下进行,排出的事实先放进共享暂存区,每个测试只取走自己插件通道(plugins/<id>/host)的事实,其余留给其他测试。断言内容不变。node scripts/sdk-e2e.mjs --source <Lithe 仓库> --build-workflows(宿主 7a24126ec)9/9 通过,包括 Node/Java 原生 build/test/run 流程、三种 SDK 的示例后端与快捷键导入;cargo fmt --check、cargo clippy --all-targets -- -D warnings(本机 1.96),以及cargo +1.87 test全部通过;contract.mjs verify --upstream(79 个文件)通过。sdk-e2e.mjs --build-workflows本地连续 3 次 9/9 通过;CI 五项检查(契约镜像、Java、Node、Rust、端到端)全部通过。合并顺序
宿主 PR feat(logging): 插件与调试适配器接入结构化日志 v2 1lck/Lithe-IDEA#1699 合入(已合入)。preview契约同步(Sync plugin logging contract #18 已合入)。litheLogging1 的 Lithe(包含 #1699)上启动,稳定版带上 #1699 之前,插件只能以预发布形式发布。限制
配套 PR: