llmcodegen/issues/refactor-split-core.issue

33 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 需求工单:拆分 core.py 为多个专注模块
name: 重构 core.py拆分为多个单一职责的模块
description: |
当前 core.py 文件过于庞大,包含 LLM 调用、文件操作、命令执行、依赖排序、状态管理、设计文件维护等多个职责,导致代码难以维护和测试。需要将其拆分为多个独立的模块,每个模块负责一个清晰的功能领域,并通过组合方式在 BaseGenerator 中集成。
主要拆分目标:
- 创建 `llm_client.py`:封装 LLM API 调用、响应保存和思考过程记录。
- 创建 `file_operations.py`:处理文件读写、目录创建和 diff 应用。
- 创建 `command_executor.py`:执行系统命令,集成危险命令拦截。
- 创建 `dependency_sorter.py`:提供依赖关系的拓扑排序及循环检测。
- 创建 `design_manager.py`:管理 design.json 的加载、保存、更新及同步操作。
- 创建 `state_manager.py`:管理断点续写状态文件的读写(线程安全)。
- 精简 `core.py` 中的 BaseGenerator使其组合以上组件保留对外接口不变。
同时需要更新 README.md反映新的模块结构和设计思想。
affected_files:
- src/llm_codegen/core.py
- src/llm_codegen/llm_client.py # 新增
- src/llm_codegen/file_operations.py # 新增
- src/llm_codegen/command_executor.py # 新增
- src/llm_codegen/dependency_sorter.py # 新增
- src/llm_codegen/design_manager.py # 新增
- src/llm_codegen/state_manager.py # 新增
- README.md
acceptance_criteria:
- 所有原有功能init、enhance、fix、design 子命令)在重构后行为完全一致,不引入新 bug。
- core.py 中的 _call_llm、_topological_sort、文件读写、命令执行、状态保存、design 操作等逻辑均迁移至对应新模块BaseGenerator 仅保留组合与高层流程。
- 新模块职责单一,相互之间通过明确的接口调用,无循环依赖。
- 单元测试覆盖核心功能,且原有测试用例全部通过。
- README.md 中的“项目结构”部分更新为新文件列表,并简要说明各模块职责。
- 日志记录、进度显示、错误提示等用户体验相关功能保持不变。
- 代码风格符合项目规范(通过 black、pylint 等检查)。
- 生成对应的单元测试。