refactor: 重构为 Webview Review 面板架构

- 移除旧的 DiffEngine、InlineDecorator、CodeLensProvider 等模块
- 新增 ChangeSetManager 统一管理代码变更快照
- 新增 reviewPanel.ts 实现双栏 Review Webview 面板
- 简化 hookHandler.ts,直接通过 ChangeSet 收集变更
- 简化 extension.ts 入口,移除冗余模块导入
- 更新 types.ts,精简 ChangeSet 和 ChangeEntry 类型定义
- package.json 添加 onStartupFinished 激活事件
This commit is contained in:
2026-06-18 00:09:56 +08:00
parent 3168e81aa6
commit a7c992a804
12 changed files with 897 additions and 468 deletions
+33
View File
@@ -0,0 +1,33 @@
@echo off
echo ========================================
echo AI Code Diff Preview - 构建打包脚本
echo ========================================
echo.
echo [1/4] 清理旧文件...
if exist dist rmdir /s /q dist
if exist *.vsix del *.vsix
echo.
echo [2/4] 安装依赖...
call npm install
echo.
echo [3/4] 编译构建...
call npm run build
echo.
echo [4/4] 打包 VSIX...
call npx vsce package
echo.
echo ========================================
echo 构建完成!
echo.
echo 生成的文件:
dir /b *.vsix
echo.
echo 安装方法:
echo code --install-extension ai-diff-preview-0.1.0.vsix
echo ========================================
pause
+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env node
/**
* Claude Code PostToolUse Hook 脚本
*
* 当 Claude Code 执行 Write 或 Edit 工具后,此脚本被调用。
* 它从 stdin 读取 JSON,将事件写入触发文件,供 VSCode 扩展监听。
*
* stdin JSON 格式:
* {
* "session_id": "abc123",
* "tool_name": "Write" | "Edit",
* "tool_input": { "file_path": "...", "content": "..." },
* "tool_response": { "success": true }
* }
*/
const fs = require('fs');
const path = require('path');
// 触发文件目录 - VSCode 扩展会监听此目录
const TRIGGER_DIR = path.join(__dirname, '..', '.claude', 'hooks');
const TRIGGER_FILE = path.join(TRIGGER_DIR, 'pending.json');
async function main() {
// 读取 stdin
const chunks = [];
for await (const chunk of process.stdin) {
chunks.push(chunk);
}
const input = Buffer.concat(chunks).toString('utf-8');
let data;
try {
data = JSON.parse(input);
} catch (e) {
// 非 JSON 输入,忽略
process.exit(0);
}
const { tool_name, tool_input, tool_response } = data;
// 只处理成功的 Write/Edit 操作
if (!tool_response || tool_response.error) {
process.exit(0);
}
const filePath = tool_input?.file_path || tool_response?.filePath;
if (!filePath) {
process.exit(0);
}
// 构造事件数据
const event = {
type: tool_name === 'Write' ? 'after_write_file' : 'after_code_edit',
filePath: filePath,
content: tool_input?.content || '',
patch: tool_input?.new_content || tool_input?.content || '',
oldString: tool_input?.old_string || '',
newString: tool_input?.new_string || '',
timestamp: Date.now(),
toolName: tool_name,
};
// 确保目录存在
if (!fs.existsSync(TRIGGER_DIR)) {
fs.mkdirSync(TRIGGER_DIR, { recursive: true });
}
// 写入触发文件(原子写入:先写临时文件再重命名)
const tmpFile = TRIGGER_FILE + '.tmp';
fs.writeFileSync(tmpFile, JSON.stringify(event, null, 2), 'utf-8');
fs.renameSync(tmpFile, TRIGGER_FILE);
}
main().catch(() => {
// 静默失败,不阻塞 Claude Code
process.exit(0);
});
+19
View File
@@ -0,0 +1,19 @@
@echo off
echo ========================================
echo AI Code Diff Preview - 本地安装脚本
echo ========================================
echo.
echo [1/2] 构建插件...
call npm run build
echo.
echo [2/2] 安装到 VSCode...
call code --install-extension .
echo.
echo ========================================
echo 安装完成!
echo 请重启 VSCode 或重新加载窗口 (Ctrl+Shift+P -> Reload Window)
echo ========================================
pause