feat: 工作空间与 AI Tool Calling 深度集成
核心变更: - 新增 execWorkspaceCommand() 无超时进程执行(workspace.ts) - 新增 workspace:execTool IPC 通道(无超时,5MB 输出上限) - run_command 工具改用 workspace IPC,移除 30s 超时限制 - run_command 默认启用(需用户确认),AI 上下文注入工作空间目录 - Agent Loop 工具执行:run_command 无超时,其他工具保持 30s - Agent 系统提示词新增工作空间规则(userTerminated/truncated 反馈) UI 修复: - Header z-index 提升至 50,Model Bar 提升至 40,Input Area 提升至 30 - 工作空间面板 top 调整为 90px(header + model-bar),不再遮挡菜单 - Input Area 增加 position: relative 确保 z-index 生效 其他: - 新增 docs/DEVELOPMENT.md 开发规范文档 - 设置面板 run_command 开关文案优化,默认值改为 true
This commit is contained in:
@@ -108,14 +108,13 @@ export const TOOL_DEFINITIONS: ToolDefinition[] = [
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'run_command',
|
||||
description: 'Execute a shell command. DANGEROUS: disabled by default, must be enabled in settings.',
|
||||
description: 'Execute a shell command via workspace. No timeout limit — runs until the process exits. Requires user confirmation. Output is streamed in real-time through the workspace process.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
required: ['command'],
|
||||
properties: {
|
||||
command: { type: 'string', description: 'Shell command to execute.' },
|
||||
cwd: { type: 'string', description: 'Working directory.' },
|
||||
timeout: { type: 'integer', description: 'Timeout ms. Max 120000.' }
|
||||
cwd: { type: 'string', description: 'Working directory. Defaults to workspace directory.' }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +129,8 @@ export function needsConfirmation(toolName: string): boolean {
|
||||
|
||||
let enabledTools: Set<string> = new Set([
|
||||
'read_file', 'list_directory', 'search_files',
|
||||
'write_file', 'create_directory', 'delete_file'
|
||||
'write_file', 'create_directory', 'delete_file',
|
||||
'run_command' // 默认启用,需要用户确认
|
||||
]);
|
||||
|
||||
export function setToolEnabled(toolName: string, enabled: boolean): void {
|
||||
@@ -160,7 +160,29 @@ export async function executeTool(toolName: string, args: Record<string, unknown
|
||||
|
||||
try {
|
||||
logToolStart(toolName, JSON.stringify(args));
|
||||
// IPC 调用 + 25 秒硬超时(比 agent-engine 的 30 秒先触发)
|
||||
|
||||
// run_command 走 workspace 无超时 IPC,其他工具走标准 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)}`);
|
||||
const result = await bridge.workspace.execTool(command, cwd);
|
||||
logToolResult('run_command', result.success, result.success ? undefined : result.stderr?.slice(0, 200));
|
||||
return {
|
||||
success: result.success,
|
||||
stdout: result.stdout,
|
||||
stderr: result.stderr,
|
||||
exitCode: result.exitCode,
|
||||
duration: result.duration,
|
||||
userTerminated: result.userTerminated,
|
||||
truncated: result.truncated
|
||||
};
|
||||
}
|
||||
|
||||
// 其他工具:IPC 调用 + 25 秒硬超时
|
||||
const result = await Promise.race([
|
||||
bridge.tool.execute(toolName, args),
|
||||
new Promise<ToolResult>((_, reject) =>
|
||||
|
||||
Reference in New Issue
Block a user