Skip to content

refactor(ai): AI 命令拆成独立 crate lithe-ai - #25

Merged
xiaoyumuxi merged 6 commits into
mainfrom
refactor/core-ai-crate
Nov 13, 2026
Merged

xiaoyumuxi merged 6 commits into
mainfrom
refactor/core-ai-crate

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

关联

这个 PR 做什么

把 rust/lithe-core/src/ai 整体移到新的 crate rust/lithe-ai。行为不变,只是换了位置。

新 crate lithe-ai

内容 说明
范围 9 个 ai.* 命令:ai.commitInputBudget、ai.planCommit、ai.decodeCommitMessage、ai.configuration.sources、ai.configuration.parse、ai.pullRequest.plan、ai.pullRequest.decode、ai.inlineEdit.plan、ai.inlineEdit.decode
依赖 只有 serde、serde_json(开启 preserve_order,和 lithe-core 一致,规划出的请求体字段顺序不变)、toml、url。不读文件、不访问网络、不持有凭据
入口 COMMANDS、is_ai_command、execute(command, payload)、execute_json(request),形状和 lithe-core-rules 一致
错误 AiError { code, message },AiErrorCode 只有 InvalidRequest、NotSupported,序列化名和 Core 的错误码相同

lithe-core 的改动

  • runtime/dispatcher.rs:9 个 ai.* 分支改为调用 lithe_ai::execute,新增辅助函数 ai_response。
  • protocol/error.rs:新增 From<lithe_ai::AiError> for CoreError,InvalidRequest、NotSupported 一一对应,错误码不变。
  • lib.rs:删除 pub mod ai,改为 pub use lithe_ai as ai,原来的 lithe_core::ai::… 路径仍然可用。
  • git/commit_message_context.rs:git.commitMessageContext 要执行 git,所以留在 lithe-core,改为引用 lithe_ai 的敏感路径判断和输入预算。为此 commit_input_budget、sensitive_path(导出名为 is_sensitive_commit_path)和 InputBudget 改为 pub 并补上文档注释。

不动的部分

  • 命令名、C ABI、JSON 字段、错误码都不变。
  • 契约文档仍在 rust/contracts/(ai-commit.md、ai-generation-requests.md、rust-core-api.md 的 AI configuration 章节),只各补一句“命令在 lithe-ai crate 中实现”。
  • fixture 仍在 rust/fixtures/ai/,桌面端读取路径不变。
  • IDE API(lithe-ide-host、lithe-mcp)不动。

新增测试

  • lithe-ai 的 every_listed_command_is_routed:COMMANDS 里的每个命令在 crate 内都有路由,未知命令返回 not_supported。
  • lithe-core 的 tests/protocol.rs 新增 every_ai_crate_command_is_routed_by_core:COMMANDS 里的每个命令都能被 CoreCommand::parse 解析,并且经 Core 实际转发到 lithe-ai。我验证过,故意把分发器里的一个命令名写错,这个测试会失败。

脚本和文档

  • scripts/rust-core/verify-rust-core-comments.sh:SOURCE_DIRS 和 rustdoc -D missing_docs 检查都加上 lithe-ai。
  • scripts/rust-core/README.md:补充 lithe-ai。

验证

  • cargo fmt --all --check:通过。
  • scripts/rust-core/verify-rust-core-comments.sh:通过。
  • node shared/plugins/scripts/verify-docs.mjs:通过。
  • cargo clippy -p lithe-ai --all-targets:0 个警告。
  • cargo test --workspace:1937 passed / 0 failed。其中 lithe-ai 29 个,lithe-core 1716 个(原 1744 个,减去随代码移走的 28 个)。

Core 对 Java 等语言零依赖、零特判,语言和工具专属知识全部由插件注入。

- 删除 execution.planLaunchCommand(JDK @argfile 规划)及 execution/launch_plan.rs
- 删除 LSP 内置语言目录:lsp/languages/catalog.rs、resources/lsp/language-providers.json、
  FFI lithe_core_lsp_provider_catalog_json 与头文件声明
- 删除 tree-sitter、tree-sitter-java 依赖
- 删除 lithe-ide-host 目录里的 Java/Maven 工具
- 删除只存在于契约、fixture、测试中的 23 个命令名(java.*、lsp.jdt*、maven.*、
  mybatis.index、spring.index、runConfig.selectJava、build.languageImport、
  agent.attachments.retentionPlan)及其 fixture
- 删除 maven-launch-context-v1、maven-portable-configuration-v1、run-configuration-v1 schema
- run/start 的 temporaryFiles 增加 {name, base64} 字节文件,宿主原样写入
- 模板 ${field.<id>.major} 取第一个数字分量,不再特判 1.x
- 旧版工具链 pin 的条目改为不透明字符串记录,不再点名 javaHome
- 契约文档和测试 fixture 去掉 Java/Maven/JDT 专属内容

Refs 1lck/Lithe-IDEA#1856, 1lck/Lithe-IDEA#1857, 1lck/Lithe-IDEA#1858, 1lck/Lithe-IDEA#1853
run-start.json 增加三条拒绝用例:同时给出 contents 和 base64、两者都不给、
base64 不是标准编码。Core 的 fixture 回放测试改为传入临时目录,
让这些用例走到逐项校验,而不是停在缺少临时目录。
- rust-core-api.md 补回 #19 误删的命令总表(375 条,每个 CoreCommand::parse 接受的命令一行)
  和 AI configuration 章节;Build systems 表补上 build.resolveStoredOptions、build.editStoredOption。
- protocol::command 新增测试:命令表与解析器逐条比对,增删改命令必须同一次提交更新表格。
- 删除 rust/fixtures/i18n(归 Lithe-IDEA i18n 生成器所有,迁到 shared/i18n/fixtures)
  和无人读取的 rust/fixtures/phpunit-project。

Refs 1lck/Lithe-IDEA#1853
- rust/lithe-core/src/ai 整体移到 rust/lithe-ai:提交信息生成、PR 描述、内联编辑、
  AI CLI 配置解析。新 crate 只依赖 serde、serde_json、toml、url,不做文件、网络和凭据访问。
- lithe-ai 提供 COMMANDS / execute / execute_json 和 AiError,形状与 lithe-core-rules 一致;
  lithe-core 的 9 个 ai.* 分发分支改为调用 lithe_ai::execute,AiError 一一映射到 CoreError。
- git.commitMessageContext 仍在 lithe-core(要跑 git),改用 lithe_ai 的敏感路径与预算规则。
- lithe_core::ai 改为 re-export lithe_ai,原有路径不变。命令名、C ABI、JSON 和错误码不变。
- 注释规范检查覆盖 lithe-ai;新增测试确认每个 lithe-ai 命令都经 Core 路由到 lithe-ai。
@xiaoyumuxi
xiaoyumuxi changed the base branch from docs/core-app-contracts-single-source to main November 13, 2026 16:24
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