[Feature] 清理 lithe-core 与 lithe-agent-host 的 4 处无用导入和死代码,并为 Core 增加警告门禁

未关闭
#1,796 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
57/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust, typescript
领域
backend, ci-cd, testing

调研方向

Start with the four Rust locations named in the issue: rust/lithe-core/src/network/mod.rs, rust/lithe-core/src/git/workspace_status.rs, rust/lithe-core/src/lsp/interface/plugin_function.rs, and rust/lithe-agent-host/src/lib.rs; compare the proposed cleanup with the existing tests and contract fixture at shared/contracts/plugins/v1/fixtures/backend/function-protocol.json. Then check how the Core workspace runs CI linting, using #1789 as context for the warning gate. Done when the unused code is removed, BACKEND_EXITED has an explicit mapping covered by the fixture test, and Core warnings fail the chosen CI check.

由索引模型根据 Issue 内容生成。

描述

area:other enhancement P2 platform:cross-platform refactor review: high
Problem to solve / 要解决的问题

在 preview 5a54c41aa 上用 macOS arm64、rustc 1.96.0 执行 cd rust && cargo test --workspace,lithe-core 和 lithe-agent-host 会报 4 条无用代码警告。逐项核对如下,依据是全仓库搜索,范围包括 Swift、Windows、契约 fixture 和脚本:

  1. 网络代理类型的 re-export
    • 位置:rust/lithe-core/src/network/mod.rs:11-14,pub(crate) use proxy::{…} 中的 NetworkProxyMode、NetworkProxyPolicy、NetworkProxyPolicyKind、NetworkProxyType。这条 re-export 由 #1571 引入。
    • 警告:rustc unused_imports。
    • 依据:crate 内只用到同一行的 proxy_policy 和 NetworkProxyPolicyRequest。全仓库搜索这 4 个名字,其他命中都不经过这条 re-export:Swift 里同名但无关的类型(macos/Sources/Lithe/Models/Settings/NetworkProxyPreferences.swift),以及 CoreCommand::NetworkProxyPolicy 这个枚举成员。
  2. 测试模块的多余导入
    • 位置:rust/lithe-core/src/git/workspace_status.rs:102,测试模块的 use super::*;。
    • 警告:rustc unused_imports。
    • 依据:测试只通过 crate::execute_json 调用命令,没有用到父模块的符号。
  3. BACKEND_EXITED 常量
    • 位置:rust/lithe-core/src/lsp/interface/plugin_function.rs:252,codes::BACKEND_EXITED("plugin.backend.exited"),由 #1595 引入。
    • 警告:rustc dead_code。
    • 依据:Rust 内没有任何引用。这个码由宿主报给页面,macOS 在 macos/Sources/Lithe/Application/Features/PluginHostServiceDispatch.swift:66 另写了同一个字符串。契约 fixture shared/contracts/plugins/v1/fixtures/backend/function-protocol.json:713 要求:宿主把它报给后端时,要改写成 plugin.host.failed。host_failure(plugin_function.rs:1836-1862)现在是靠 _ => codes::HOST_FAILED 兜底满足这条要求,:1858 的注释提到了这种情况,但代码没有用这个常量。
  4. 测试辅助函数 resolve
    • 位置:rust/lithe-agent-host/src/lib.rs:296-299,#[cfg(test)] fn resolve。
    • 警告:rustc dead_code(lib test 构建)。
    • 依据:rust/lithe-agent-host/src/tests.rs:3278 定义了同名闭包 let resolve = |launch| resolve_with(launch, &codex_cli);,测试里的调用全部走这个闭包,lib 里的辅助函数没有调用方。

保留的代价:

  • Core 每次构建都带着这几条警告,新出现的警告容易被淹没,评审时也分不清哪些是本次改动引入的。
  • BACKEND_EXITED 留在 codes 里,看起来 Rust 会专门处理这个码,实际行为却来自兜底分支,读代码的人会误判它的处理路径。
  • Core crate 没有警告门禁:目前只有 scripts/remote/verify-remote-workspace.sh:44-45 对 lithe-remote 运行 clippy -D warnings,所以这类警告能合进 preview。

lithe-git-host 的 forward_slash_path 警告(rust/lithe-git-host/src/configuration.rs:52)已经由 #1789 跟踪,本单不重复处理。

Proposed solution / 建议方案
  1. re-export:从 network/mod.rs 的 re-export 中删掉未用的 4 个类型,保留 proxy_policy 和 NetworkProxyPolicyRequest。风险很低,只影响 crate 内可见性。
  2. 多余导入:删除 workspace_status.rs 测试模块中的 use super::*;。
  3. BACKEND_EXITED(推荐方案):在 host_failure 里显式写一条 Some(codes::BACKEND_EXITED) => codes::HOST_FAILED,把 :1858 的注释移到这一行。这样 fixture :713 的行为由具名分支保证,常量也有了用处。
    • 不推荐直接删除常量:这是契约里登记的错误码,Rust 侧保留具名常量,可以防止以后被别的含义复用(错误码必须一码一义)。
    • 风险:无行为变化,现有 fixture 测试即可验证。
  4. 测试辅助函数:删除 lithe-agent-host/src/lib.rs:296-299 的 #[cfg(test)] fn resolve。
  5. 警告门禁:清理完成后,为 Core workspace 增加警告门禁,例如在 CI 中运行 cargo clippy --workspace --all-targets -- -D warnings,并与 #1789 的处理一致。stable 工具链升级会带来新的 lint(#1789 就是这种情况),门禁放在哪个工作流、是否固定工具链版本,由维护者决定。
Target platform / 目标平台

Cross-platform / 跨平台

Area / 模块

Other / 其他

Priority / 优先级

P2 / 后续考虑:目前不着急,可安排到后续版本

Alternatives considered / 已考虑的替代方案

用 #[allow(unused_imports)] 或 #[allow(dead_code)] 压掉警告。不推荐:无用代码会继续留着,也违背 develop-lithe 第九节的清理要求。

Additional context / 补充信息
  • 复现命令:cd rust && cargo test --workspace --no-fail-fast,在构建输出中搜索 ^warning。
  • 发现经过:2026-11-07 把 Core 拆分为 Lithe-IDEA/Lithe-core-rust 时,跑完整 workspace 测试发现。拆分出的文件与主仓库逐字节一致,所以主仓库 preview 上有相同的警告。
  • 相关:#1789(lithe-git-host、lithe-core-rules 的 clippy 告警)。
Checklist / 提交前检查
  • I searched existing issues for duplicates. / 我已搜索现有 Issue,确认没有重复建议。
主要语言
TypeScript
星标
1.8k
派生
151
平均合并
10 小时 29 分钟
30 天内合并 PR
407

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

1lck/Lithe-IDEA 的其他 Issue

查看 1lck/Lithe-IDEA 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。