← 返回首页

CmdCode V0.5 模块拆分报告

大型 TypeScript 文件结构重构 · 零功能变更
58→75
文件数
+17
新增模块
0
新错误
5
>300行文件

📊 原始 vs 现在 — 文件拆分对照

文件 原始行数 当前行数 新子模块
src/i18n.ts 782 已删除 en.ts, zh.ts, index.ts (共772行)
src/tools.ts 828 13 (barrel) sandbox.ts, security.ts, definitions.ts, execution.ts (共851行)
src/crypto-util.ts 600 86 (barrel) core.ts, secrets.ts, keypool.ts, config.ts (共639行)
src/web.ts 1068 906 helpers.ts, sessions.ts, auth.ts (共176行)
src/cli.ts 768 416 colors.ts, input.ts (共370行)
src/chat-enhanced.ts 865 159 executor.ts, pavr-phases.ts, helpers.ts (共768行)
src/chat.ts 407 333 config.ts, prompt.ts, helpers.ts (共92行)

📈 模块统计

  • 总源码文件数: 58 → 75(17个新子模块)
  • 超过500行的文件: 6个 → 1个(仅 web.ts 906行)
  • 超过300行的文件: 9个 → 5个(主要是无法拆分的自然模块边界)

🎯 设计原则

  • barrel 文件保留原导入路径,对外接口不变(tools.ts, crypto-util.ts 保持为 import from './tools.js'
  • 只有 i18n.ts 改为 ./i18n/index.js(因为已没有 i18n.ts barrel)
  • 子模块间导入使用 .js 扩展名,与项目规范一致

🎯 零功能变更 — 所有代码只是搬迁,逻辑完全不变

🗂️ 拆分详情

src/i18n.ts → 3个文件
i18n/en.ts       — 英文翻译对象
i18n/zh.ts       — 中文翻译对象
i18n/index.ts    — 导出 + 语言切换逻辑
src/tools.ts → 4个文件 + barrel
tools/sandbox.ts      — 沙箱执行环境
tools/security.ts     — 安全检查
tools/definitions.ts  — 工具定义
tools/execution.ts    — 执行引擎
src/crypto-util.ts → 4个文件 + barrel
crypto-util/core.ts    — 核心加解密
crypto-util/secrets.ts — secrets.enc 读写
crypto-util/keypool.ts — 密钥池管理
crypto-util/config.ts  — 配置文件加密
src/web.ts → helpers.ts, sessions.ts, auth.ts (web.ts 本身仍906行)
src/cli.ts → colors.ts, input.ts
src/chat-enhanced.ts → executor.ts, pavr-phases.ts, helpers.ts
src/chat.ts → config.ts, prompt.ts, helpers.ts

✅ 构建结果

0
新错误
2
入口点
17
新模块
构建通过

cli.ts 和 web.ts 两个入口点均构建通过

来源:DeepSeek 分享 · 仅供学习参考