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

Đang mở
#1,796 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
57/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, typescript
Lĩnh vực
backend, ci-cd, testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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,确认没有重复建议。
Ngôn ngữ chính
TypeScript
Star
1.8k
Fork
151
Merge trung bình
10 giờ 29 phút
Pull request đã merge (30 ngày)
407

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của 1lck/Lithe-IDEA

Tất cả issue của 1lck/Lithe-IDEA

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.