refactor: 命令执行走工作空间终端,AI 不再直接执行

流程改为:AI 提出命令 → 用户确认 → 工作空间终端执行(实时显示)→ 结果反馈 AI → AI 回复

- handleRunCommand 直接 spawn 子进程,stdout/stderr 实时通过 cmd:output 推送
- 进程结束后通过 cmd:done 通知渲染进程
- 停止按钮通过 cmd:kill 终止进程
- 清理 workspace.ts 中不再需要的 execWorkspaceCommand 工具集成代码
- 去掉 workspace:execTool/killTool,改为 cmd:output/cmd:done/cmd:kill
This commit is contained in:
thzxx
2026-04-08 13:12:18 +08:00
parent d5e5f5f58a
commit 0431ed56c0
7 changed files with 107 additions and 84 deletions
+3 -5
View File
@@ -161,14 +161,14 @@ export async function executeTool(toolName: string, args: Record<string, unknown
try {
logToolStart(toolName, JSON.stringify(args));
// run_command 走 workspace 无超时 IPC,其他工具走标准 IPC
// run_command 走 workspace IPC
if (toolName === 'run_command') {
const command = args.command as string;
const cwd = args.cwd as string | undefined;
if (!command) {
return { success: false, error: '缺少 command 参数' };
}
logInfo(`Workspace 命令执行: ${command.slice(0, 100)}`);
logInfo(`工作空间命令执行: ${command.slice(0, 100)}`);
const result = await bridge.workspace.execTool(command, cwd);
logToolResult('run_command', result.success, result.success ? undefined : result.stderr?.slice(0, 200));
return {
@@ -176,9 +176,7 @@ export async function executeTool(toolName: string, args: Record<string, unknown
stdout: result.stdout,
stderr: result.stderr,
exitCode: result.exitCode,
duration: result.duration,
userTerminated: result.userTerminated,
truncated: result.truncated
duration: result.duration
};
}