Skip to content

refactor(core): 拆出 protocol、network、terminal、process、diff、github 基础 crate,keymap 与 action_search 并入 core-rules - #27

Merged
xiaoyumuxi merged 1 commit into
mainfrom
refactor/core-base-crates
Nov 13, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
refactor/core-base-crates

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

关联

这个 PR 做什么

1. 新增 6 个 crate

都放在 rust/crates/ 下,代码从 lithe-core 原样搬出,只做了可见性和导入路径调整:

crate 目录 内容 依赖的工作区 crate
lithe-protocol crates/protocol 响应信封 CoreResponse/ResponseData、CoreError/ErrorCode、取消 cancellation、JSON 唯一键解析 json_document 无
lithe-network crates/network network.proxyPolicy 代理策略归一化 无
lithe-process crates/process processLifecycle.resolve/inventory/settle 进程生命周期决策 无
lithe-terminal crates/terminal terminal.parseLinkTarget 终端链接识别 lithe-protocol
lithe-diff crates/diff diff.compareTexts、行配对和行内差异 lithe-protocol
lithe-github crates/github GitHub 请求规划和响应归一化、github.pullRequestCheckoutPlan lithe-protocol

拆分后的依赖关系:

lithe-core
├── lithe-protocol
├── lithe-network      lithe-process
├── lithe-terminal ─┐
├── lithe-diff ─────┼── lithe-protocol
├── lithe-github ───┘
├── lithe-core-rules   lithe-ai   lithe-git-host   lithe-ide-host   lithe-remote

这 6 个 crate 互不依赖(除了都依赖 lithe-protocol),可以和 lithe-core 的其他依赖并行编译。lithe-core 的源码从 185 784 行减到 180 358 行。

2. keymap 和 action_search 移入 lithe-core-rules

这些命令都是纯规则,没有 I/O,和已经在 lithe-core-rules 里的 keymap.modifierGestureStep 属于一类:

命令 现在位置
keymap.parseContext、keymap.evaluateContext core-rules/src/keymap/context.rs
keymap.analyzeConflicts core-rules/src/keymap/bindings.rs
keymap.schemes.reduce core-rules/src/keymap/schemes.rs
search.actions core-rules/src/action_search.rs
  • 每个模块按 core-rules 的现有写法提供命令名常量和 *_json(payload) -> Result<Value, RuleError> 适配函数,并登记到 dispatch.rs 的 COMMANDS。已有测试 every_rules_crate_command_is_routed_by_core 会检查每个登记的命令都能被 lithe-core 解析。
  • lithe-core 分发器里这 10 个规则命令统一走 rules_response,替换原来的 agent_response 命名。
  • 错误信息、details 和错误码保持原样。比如 keymap.schemes.reduce 的 invalid_name、duplicate_name 等 details 不变。
  • unicode-normalization 依赖跟着 action_search 移到 lithe-core-rules。

3. lithe-core 的调整

  • protocol 模块改为在 lithe-protocol 之上补充请求解析(CoreCommand)、领域响应模型和事件,并原样重新导出 CoreError、CoreResponse、ErrorCode、ResponseData、invalid_relative_path。lithe-core 的公开 API 不变。
  • 孤儿规则不允许在 lithe-core 里给 lithe-protocol 的 CoreError 实现 From<AiError> 和 From<RuleError>,所以改成两个显式函数 protocol::ai_error、protocol::rule_error,映射关系一一对应,和原来相同。
  • 去掉 similar(移到 lithe-diff)和 unicode-normalization 依赖。
  • rust/contracts/rust-core-api.md:移入 core-rules 的 5 组命令,在正文和命令表中注明 “lives in rust/crates/core-rules”,写法和已有的 keymap.modifierGestureStep 一致。

拆分时补的文档

新 crate 根导出的项会受注释门禁的 -D missing_docs 检查。下面这些原来在 lithe-core 内部、可见性只到 crate 级的字段和变体,这次补了英文文档:lithe-diff 14 处、lithe-network 17 处、lithe-github 2 处、lithe-terminal 1 处,以及 cancellation::cancel。

不动的部分

  • 命令名、C ABI、头文件位置、JSON 字段、错误码都不变。桌面端除了将来升级固定版本,不需要改代码。
  • 没有改动任何算法和行为。测试随代码一起搬,没有删除测试。
  • CI 工作流不变。注释门禁本来就遍历 rust/crates/*,新 crate 自动接受检查,不需要改脚本。

验证

…rate,keymap 与 action_search 并入 core-rules

- lithe-protocol:响应信封、错误码、取消和 JSON 唯一键解析,lithe-core 原样重新导出
- lithe-network、lithe-terminal、lithe-process、lithe-diff、lithe-github:从 lithe-core 原样搬出的叶子模块
- keymap.parseContext/evaluateContext/analyzeConflicts、keymap.schemes.reduce、search.actions 移入 lithe-core-rules,分发表统一走 rules_response
- AiError、RuleError 到 CoreError 的转换改为 protocol::ai_error、protocol::rule_error(孤儿规则)
- lithe-core 去掉 similar、unicode-normalization 依赖;契约文档注明新增的 core-rules 命令

命令名、C ABI、JSON 字段和错误码都不变。
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 13, 2026 17:37
@xiaoyumuxi
xiaoyumuxi merged commit 0be1d34 into main Nov 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant