| 文件 | 大小 | 核心函数 | 被调用位置 |
|---|---|---|---|
core.ts | 3.6 KB | runPAVRCycle(input, chat) | chat-factory.ts → chat-enhanced.ts |
engine.ts | 7.2 KB | executeWithPAVR(input, chat) | chat.ts 的 sendMessage 分支 |
两者都包装了 PAVR 的 意图识别 → 计划生成 → 分步执行 → 验证 → 响应 流程,引用的下层模块完全相同,差异仅在参数签名和前缀处理。
目标:保留 engine.ts 为唯一入口,将 core.ts 的差异逻辑移入 engine.ts,删除 core.ts,更新所有引用。
cd /home/administrator/CmdCode-V0.5
cp -r . ../CmdCode-V0.5.backup.dedup
# 找出所有引用 core.ts 或 engine.ts 的文件
grep -rn "from './core'" src/
grep -rn "from './engine'" src/
grep -rn 'core\.' src/
grep -rn 'engine\.' src/
# 预期发现:
# chat-factory.ts: import { runPAVRCycle } from './core'
# chat-enhanced.ts: import { runPAVRCycle } from './core'
# chat.ts: import { executeWithPAVR } from './engine'
将 core.ts 中的 setGlobalPAVR/getGlobalPAVR 移至 chat-factory.ts:
// 在 chat-factory.ts 顶部添加
export function setGlobalPAVR(enabled: boolean) {
globalPAVREnabled = enabled;
}
export function getGlobalPAVR(): boolean {
return globalPAVREnabled;
}
import { globalPAVREnabled } from './chat-factory';
// 兼容旧 core.ts 的 runPAVRCycle 签名
export async function runPAVRCycle(input: string, chat: any): Promise {
if (!globalPAVREnabled) {
return chat.send(input); // 直接回退到普通聊天
}
return executeWithPAVR(input, chat);
}
# 替换所有从 ./core 的导入为从 ./engine 导入
find src/ -type f -name "*.ts" -exec sed -i "s|from './core'|from './engine'|g" {} \;
find src/ -type f -name "*.ts" -exec sed -i 's|from "\./core"|from "\./engine"|g' {} \;
find src/ -type f -name "*.ts" -exec sed -i "s|from './core.js'|from './engine.js'|g" {} \;
# 将所有 runPAVRCycle( 替换为 executeWithPAVR(
find src/ -type f -name "*.ts" -exec sed -i 's/runPAVRCycle(/executeWithPAVR(/g' {} \;
# 检查是否还有残留
grep -rn "runPAVRCycle" src/
# 正式删除前确认无引用
grep -rn "src/core" src/ # 应该只有注释残留,无实际导入
rm src/core.ts
# 项目通常使用 bun build 或 tsc
bun run --if-present build 2>&1 | head -50
# 运行自动化测试
cd tests && bash auto_loop.sh
rm -rf /home/administrator/CmdCode-V0.5
cp -r ../CmdCode-V0.5.backup.dedup /home/administrator/CmdCode-V0.5
engine.ts 成为 PAVR 流程的唯一协调器,约 9 KBcore.ts 被移除,项目文件数减少至 54 个 TS 文件