JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(auto_harness): cancel support & bug fixes
ray_lea47ab7c95941
diff --git a/jiuwenswarm/agents/harness/common/auto_harness/service.py b/jiuwenswarm/agents/harness/common/auto_harness/service.pyindex 4558ae7f05..66fd6867d4 100644--- a/jiuwenswarm/agents/harness/common/auto_harness/service.py+++ b/jiuwenswarm/agents/harness/common/auto_harness/service.py@@ -75,6 +75,7 @@ _DEFAULT_REPO_URL = "https://gitcode.com/openJiuwen/agent-core.git"# Default local repo path_DEFAULT_LOCAL_REPO = _AUTO_HARNESS_DATA_DIR / "repo" / "openJiuwen--agent-core"# Default values for ci_gate config+_DEFAULT_CI_GATE_PYTHON_EXECUTABLE = sys.executable_DEFAULT_CI_GATE_INSTALL_COMMAND = "uv sync --active --group dev --extra cli"@@ -265,14 +266,20 @@ class AutoHarnessService:needs_save = Trueci_gate = config_dict.get("ci_gate") or {}- if ci_gate.get("python_executable"):- ci_gate["python_executable"] = ""+ if not ci_gate.get("python_executable"):+ ci_gate["python_executable"] = str(_DEFAULT_CI_GATE_PYTHON_EXECUTABLE)needs_save = Trueif not ci_gate.get("install_command"):ci_gate["install_command"] = _DEFAULT_CI_GATE_INSTALL_COMMANDneeds_save = True+ budget = config_dict.get("budget", {})+ max_tasks_per_session = budget.get("max_tasks_per_session", 5)+ if max_tasks_per_session > 5:+ budget["max_tasks_per_session"] = 5+ needs_save = True+if needs_save:config_dict["ci_gate"] = ci_gateconfig_path.parent.mkdir(parents=True, exist_ok=True)@@ -612,6 +619,8 @@ class AutoHarnessService:# of a raw URL. The named remote is added in clone_or_update_repo().if not config.git_base_branch:config.git_base_branch = "develop-auto-harness"+ if config.pipeline_preference == EXTENDED_EVOLVE_PIPELINE:+ config.git_base_branch = "develop"if not config.git_remote:config.git_remote = "origin"@@ -1793,7 +1802,11 @@ class AutoHarnessService:logger.info("[AutoHarnessService] Cancelling run for session %s", session_id)active_run.cancelled = True- # Cancel the task+ # Signal the orchestrator to stop (pipelines check should_cancel)+ if active_run.orchestrator is not None:+ active_run.orchestrator.cancel()++ # Cancel the asyncio taskif not active_run.task.done():active_run.task.cancel()diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/auto-harness.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/auto-harness.tsindex 0dc5fcf7d5..6e4c0e2056 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/auto-harness.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/auto-harness.ts@@ -264,7 +264,7 @@ const scheduleStartCommand: SlashCommand = {const parsed = parseScheduleStartArgs(args);if (parsed.interval < 1) {- const hint = parsed.interval === 0 ? "间隔不能为 0,请设置至少 1 小时" : parsed.interval === -1 ? "请提供有效的 --interval 数值(小时)" : "间隔必须大于 0 小时";+ const hint = parsed.interval === 0 ? "间隔不能为 0,请设置至少 1 小时\n示例: /auto-harness schedule start --interval 4 优化上下文压缩能力" : parsed.interval === -1 ? "请提供有效的 --interval 数值(小时)\n示例: /auto-harness schedule start --interval 4 优化上下文压缩能力" : "间隔必须大于 0 小时";ctx.addItem(addError(ctx.sessionId, `${hint}`));@@ -273,7 +273,7 @@ const scheduleStartCommand: SlashCommand = {if (!parsed.query) {ctx.addItem(- addError(ctx.sessionId, "请提供执行目标 query")+ addError(ctx.sessionId, "请提供执行目标 query\n示例: /auto-harness schedule start --interval 4 优化上下文压缩能力"));return;}@@ -359,7 +359,7 @@ const scheduleStartCommand: SlashCommand = {ctx.addItem(addInfo(ctx.sessionId,- `\n定时任务已创建\nID: ${result.task_id}\nPipeline: ${pipelineDisplayLabel(pipeline)}\n下次执行: ${formatLocalTime(result.next_run_time)}\n间隔: 每 ${parsed.interval} 小时${run_immediately ? "\n(已立即执行一次)" : ""}\n`+ `\n⏰ 定时任务已创建\n━━━━━━━━━━━━━━━━━━━━━━\n任务ID: ${result.task_id}\nPipeline: ${pipelineDisplayLabel(pipeline)}\n执行间隔: 每 ${parsed.interval} 小时\n下次执行: ${formatLocalTime(result.next_run_time)}${run_immediately ? "\n备注: 已立即执行一次" : ""}\n━━━━━━━━━━━━━━━━━━━━━━\n💡 使用 /auto-harness schedule list 查看所有任务\n 使用 /auto-harness schedule logs ${result.task_id} 查看执行日志\n`));},@@ -371,32 +371,33 @@ const scheduleListCommand: SlashCommand = {kind: CommandKind.BUILT_IN,takesArgs: false,action: async (ctx, _args) => {- ctx.addItem(addInfo(ctx.sessionId, "\n正在查询任务...\n", "i"));+ ctx.addItem(addInfo(ctx.sessionId, "\n🔍 正在查询任务...\n", "i"));const result = await ctx.request<{ tasks?: Array<{ task_id: string; query: string; status: string; interval_hours: number; next_run_time: string; created_at: string; is_one_time?: boolean; pipeline?: string }> }>("schedule.list", {});const tasks = result.tasks as Array<{ task_id: string; query: string; status: string; interval_hours: number; next_run_time: string; created_at: string; is_one_time?: boolean; pipeline?: string }> | undefined;if (!tasks || tasks.length === 0) {- ctx.addItem(addInfo(ctx.sessionId, "\n暂无任务\n", "i"));+ ctx.addItem(addInfo(ctx.sessionId, "\n📭 暂无任务\n💡 使用 /auto-harness schedule start 创建定时任务\n 使用 /auto-harness run 创建一次性任务\n", "i"));return;}- const lines = ["\n【任务列表】"];+ const lines = ["\n📋 任务列表\n━━━━━━━━━━━━━━━━━━━━━━"];for (const task of tasks) {- const statusEmoji = task.status === "running" ? "[运行中]" :- task.status === "pending" ? "[等待]" :- task.status === "cancelled" ? "[已取消]" :- task.status === "failed" ? "[失败]" :- task.status === "success" ? "[成功]" : "[已完成]";- const isOneTime = task.is_one_time ? "[一次性]" : "";+ const statusIcon = task.status === "running" ? "🔄" :+ task.status === "pending" ? "⏳" :+ task.status === "cancelled" ? "🛑" :+ task.status === "failed" ? "❌" :+ task.status === "success" ? "✅" : "📦";+ const isOneTime = task.is_one_time ? " [一次性]" : " [定时]";const queryPreview = task.query.length > 50 ? task.query.substring(0, 50) + "..." : task.query;const pipelineInfo = task.pipeline ? `Pipeline: ${pipelineDisplayLabel(task.pipeline)}` : "";lines.push(- `${statusEmoji}${isOneTime} ${task.task_id} - ${queryPreview}`+ `${statusIcon}${isOneTime} ${task.task_id}`);+ lines.push(` 目标: ${queryPreview}`);// Show interval only for recurring tasksif (task.is_one_time) {- lines.push(` 状态: ${task.status} | 类型: 一次性${pipelineInfo ? ` | ${pipelineInfo}` : ""}`);+ lines.push(` 状态: ${task.status}${pipelineInfo ? ` | ${pipelineInfo}` : ""}`);} else {lines.push(` 状态: ${task.status} | 间隔: ${task.interval_hours}h | 下次执行: ${formatLocalTime(task.next_run_time)}${pipelineInfo ? ` | ${pipelineInfo}` : ""}`);}@@ -404,6 +405,7 @@ const scheduleListCommand: SlashCommand = {lines.push("");}+ lines.push("💡 使用 /auto-harness schedule logs <task_id> 查看执行日志");lines.push("");ctx.addItem(addInfo(ctx.sessionId, lines.join("\n")));},@@ -432,7 +434,7 @@ const scheduleStatusCommand: SlashCommand = {if (!task_id) {ctx.addItem(- addError(ctx.sessionId, "用法: /auto-harness schedule status <task_id>")+ addError(ctx.sessionId, "用法: /auto-harness schedule status <task_id>\n示例: /auto-harness schedule status sch_abc123"));return;}@@ -447,36 +449,44 @@ const scheduleStatusCommand: SlashCommand = {}const isOneTime = result.is_one_time;- const lines = [`\n【任务详情: ${result.task_id}】`];+ const statusIcon = result.status === "running" ? "🔄" :+ result.status === "pending" ? "⏳" :+ result.status === "cancelled" ? "🛑" :+ result.status === "failed" ? "❌" :+ result.status === "success" ? "✅" : "📦";+ const lines = [`\n📄 任务详情\n━━━━━━━━━━━━━━━━━━━━━━`];+ lines.push(`任务ID: ${result.task_id}`);lines.push(`目标: ${result.query}`);- lines.push(`状态: ${result.status}`);+ lines.push(`状态: ${statusIcon} ${result.status}`);if (result.pipeline) {lines.push(`Pipeline: ${pipelineDisplayLabel(result.pipeline)}`);}if (isOneTime) {- lines.push(`类型: 一次性任务`);+ lines.push(`类型: 🎯 一次性任务`);} else {- lines.push(`类型: 定时任务 | 间隔: 每 ${result.interval_hours} 小时`);+ lines.push(`类型: ⏰ 定时任务 | 间隔: 每 ${result.interval_hours} 小时`);lines.push(`下次执行: ${formatLocalTime(result.next_run_time) || "已取消"}`);}lines.push(`创建时间: ${formatLocalTime(result.created_at)}`);if (result.current_execution_id) {- lines.push(`当前执行: ${result.current_execution_id}`);+ lines.push(`\n🔄 当前执行: ${result.current_execution_id}`);+ lines.push(`💡 使用 /auto-harness schedule logs ${result.task_id} 查看实时日志`);}const history = result.execution_history as Array<{ execution_id: string; status: string; completed_at?: string }> | undefined;if (history && history.length > 0) {- lines.push(`\n【执行历史】(${history.length} 次)`);+ lines.push(`\n📜 执行历史 (${history.length} 次)`);const recentHistory = history.slice(-5);for (const record of recentHistory) {- const statusText = record.status === "success" ? "[成功]" :- record.status === "failed" ? "[失败]" :- record.status === "cancelled" ? "[取消]" : "[异常]";- lines.push(`${statusText} ${record.execution_id} - ${formatLocalTime(record.completed_at) || "进行中"}`);+ const histIcon = record.status === "success" ? "✅" :+ record.status === "failed" ? "❌" :+ record.status === "cancelled" ? "🛑" : "⚠️";+ lines.push(` ${histIcon} ${record.execution_id} - ${formatLocalTime(record.completed_at) || "进行中"}`);}}+ lines.push("\n━━━━━━━━━━━━━━━━━━━━━━");lines.push("");ctx.addItem(addInfo(ctx.sessionId, lines.join("\n"))@@ -486,7 +496,7 @@ const scheduleStatusCommand: SlashCommand = {const scheduleLogsCommand: SlashCommand = {name: "logs",- description: "查看任务执行日志(默认显示当前运行日志,--history 查看历史日志)",+ description: "查看任务日志(自动适配:运行中则实时跟踪,已完成则显示历史)",usage: "/auto-harness schedule logs <task_id> [--history <n>]",example: "/auto-harness schedule logs sch_abc123 --history 0",kind: CommandKind.BUILT_IN,@@ -594,14 +604,34 @@ const scheduleLogsCommand: SlashCommand = {if (!parsed.task_id) {ctx.addItem(- addError(ctx.sessionId, "用法: /auto-harness schedule logs <task_id> [--history <n>]")+ addError(ctx.sessionId, "用法: /auto-harness schedule logs <task_id> [--history <n>]\n功能:\n 不带 --history: 自动适配 - 运行中则实时跟踪,已完成则显示最近历史日志\n --history <n>: 查看指定历史执行日志(0=最近一次,1=上一次...)\n示例:\n /auto-harness schedule logs sch_abc123 # 自动适配模式\n /auto-harness schedule logs sch_abc123 --history 0 # 查看最近一次历史日志"));return;}if (parsed.log_type === "current") {- // Tail -f style streaming for current running task- await streamCurrentLogs(ctx, parsed.task_id);+ // Try current logs first, auto-fallback to history if task is not running+ // First, check if task has a current execution (running)+ const statusResult = await ctx.request<{ error?: string; status?: string; current_execution_id?: string; execution_history?: Array<{ execution_id: string }> }>("schedule.status", { task_id: parsed.task_id });++ if (statusResult.error) {+ ctx.addItem(addError(ctx.sessionId, statusResult.error));+ return;+ }++ // If task is running and has current_execution_id, stream current logs+ if (statusResult.status === "running" && statusResult.current_execution_id) {+ await streamCurrentLogs(ctx, parsed.task_id);+ } else {+ // Task is not running, auto-switch to history mode (most recent)+ const history = statusResult.execution_history as Array<{ execution_id: string }> | undefined;+ if (history && history.length > 0) {+ ctx.addItem(addInfo(ctx.sessionId, `\n💡 任务已完成,自动显示最近一次历史日志\n任务状态: ${statusResult.status}\n`, "i"));+ await readFullHistoryLogs(ctx, parsed.task_id, 0); // Show most recent history+ } else {+ ctx.addItem(addInfo(ctx.sessionId, `\n📭 任务无执行历史\n任务状态: ${statusResult.status}\n`));+ }+ }} else {// History mode: read full log in batchesawait readFullHistoryLogs(ctx, parsed.task_id, parsed.history_index);@@ -689,13 +719,13 @@ async function streamCurrentLogs(// Clear any previous interrupt flag before starting new streamctx.clearInterruptRequested();- ctx.addItem(addInfo(ctx.sessionId, `\n【实时日志跟踪: ${task_id}】\n正在连接...\n`));+ ctx.addItem(addInfo(ctx.sessionId, `\n📋 实时日志跟踪: ${task_id}\n正在连接...\n💡 按 Ctrl+C 可中断日志查看,任务将继续后台运行\n`));// Helper: check interrupt and exit if requestedconst checkInterrupt = (): boolean => {if (ctx.isInterruptRequested()) {ctx.clearInterruptRequested();- ctx.addItem(addInfo(ctx.sessionId, `\n【日志跟踪已中断】`));+ ctx.addItem(addInfo(ctx.sessionId, `\n⏸️ 日志跟踪已中断\n💡 任务仍在后台运行,可使用 /auto-harness schedule logs ${task_id} 继续查看\n`));return true;}return false;@@ -758,7 +788,7 @@ async function streamCurrentLogs(if (result.error) {// Execution finished - show completion messageif (result.error.includes("当前无正在执行的日志") || result.error.includes("不存在")) {- ctx.addItem(addInfo(ctx.sessionId, `\n【任务执行完成】`));+ ctx.addItem(addInfo(ctx.sessionId, `\n✅ 任务执行完成\n`));return;}ctx.addItem(addError(ctx.sessionId, result.error));@@ -809,15 +839,15 @@ async function streamCurrentLogs(await new Promise((resolve) => setTimeout(resolve, 1000));}} catch (e) {- ctx.addItem(addError(ctx.sessionId, `日志流错误: ${e}`));+ ctx.addItem(addError(ctx.sessionId, `⚠️ 日志流错误: ${e}\n💡 请稍后重试,或使用 /auto-harness schedule logs ${task_id} 查看日志`));return;}}if (pollCount >= maxPolls) {- ctx.addItem(addInfo(ctx.sessionId, `\n【日志跟踪退出,任务后台运行中,可再次调用 logs 指令查看。】`));+ ctx.addItem(addInfo(ctx.sessionId, `\n⏱️ 日志跟踪已超时退出 \n💡 任务仍在后台运行,可使用 /auto-harness schedule logs ${task_id} 继续查看\n`));} else {- ctx.addItem(addInfo(ctx.sessionId, `\n【日志跟踪完成: ${executionId}】`));+ ctx.addItem(addInfo(ctx.sessionId, `\n✅ 任务执行完成\n执行ID: ${executionId}\n`));}}@@ -827,7 +857,7 @@ async function readFullHistoryLogs(task_id: string,history_index: number): Promise<void> {- ctx.addItem(addInfo(ctx.sessionId, `\n正在读取完整日志...\n`, "i"));+ ctx.addItem(addInfo(ctx.sessionId, `\n📜 正在读取历史日志...\n`, "i"));let allLogs: Array<LogEntry> = [];let offset = 0;@@ -881,15 +911,19 @@ async function readFullHistoryLogs(// Display full aggregated logsif (allLogs.length === 0) {- ctx.addItem(addInfo(ctx.sessionId, "日志为空"));+ ctx.addItem(addInfo(ctx.sessionId, "\n📭 日志为空\n"));return;}const result = parseAndAggregateLogs(allLogs);- const lines: string[] = [`【执行日志: ${executionId}】`];+ const lines: string[] = [`\n📜 执行日志\n━━━━━━━━━━━━━━━━━━━━━━\n执行ID: ${executionId}`];if (completedAt) {- lines.push(`完成时间: ${formatLocalTime(completedAt)} | 状态: ${status}`);+ const statusIcon = status === "success" ? "✅" :+ status === "failed" ? "❌" :+ status === "cancelled" ? "🛑" : "⚠️";+ lines.push(`完成时间: ${formatLocalTime(completedAt)} | 状态: ${statusIcon} ${status}`);}+ lines.push("━━━━━━━━━━━━━━━━━━━━━━\n");lines.push("");lines.push("=" .repeat(80));@@ -1410,6 +1444,7 @@ interface ParseState {extensionsByName: Record<string, ExtensionProgressInfo>;gapCount: number;ciFixCount: number;+ hasFailure: boolean; // Track if any stage or extension failed during execution}function parseAndAggregateLogs(@@ -1426,6 +1461,7 @@ function parseAndAggregateLogs(const extensionsByName: Record<string, ExtensionProgressInfo> = initialState?.extensionsByName ?? {};let gapCount = initialState?.gapCount ?? 0;let ciFixCount = initialState?.ciFixCount ?? 0;+ let hasFailure = initialState?.hasFailure ?? false; // Track if any stage/extension failed// Note: pipeline type is determined dynamically in the loop when pipelineInfo is set@@ -1450,6 +1486,7 @@ function parseAndAggregateLogs(case "chat.error":const errorMsg = log.error || content || "未知错误";+ hasFailure = true; // Chat error indicates execution failuresections.push({ type: "error", content: errorMsg });break;@@ -1494,6 +1531,7 @@ function parseAndAggregateLogs(const extCount = extensionOrder.length;const mergeLabel = extCount > 0 ? `${extCount} 个扩展 → 1 个运行时扩展` : '合并扩展';const mergeText = mergeStatus === 'success' ? `✅ ${extName}: ${mergeLabel}完成` : mergeStatus === 'failed' ? `❌ ${extName}: ${mergeLabel}失败` : `⏳ ${extName}: ${mergeLabel}`;+ if (mergeStatus === 'failed') hasFailure = true;sections.push({type: "info",content: mergeText,@@ -1505,6 +1543,11 @@ function parseAndAggregateLogs(// Extension-level progress updateconst extStatus = (log.status || 'pending') as ExtensionProgressStatus;+ // Track extension failures+ if (extStatus === 'failed' || extStatus === 'timeout' || extStatus === 'rejected') {+ hasFailure = true;+ }+// Skip merged_extensions from extension matrix (it's a merge container)// Show activation status as info line, not full stage renderif (extName === 'merged_extensions') {@@ -1581,6 +1624,7 @@ function parseAndAggregateLogs(if (log.stage && !scope && (log.status === 'success' || log.status === 'failed') && !completedStages.includes(log.stage)) {completedStages.push(log.stage);+ if (log.status === 'failed') hasFailure = true;}// Track current running stage (from any scope="" event)if (log.stage && !scope && log.stage !== currentStage) {@@ -1657,10 +1701,21 @@ function parseAndAggregateLogs(if (currentStage && !completedStages.includes(currentStage)) {completedStages.push(currentStage);}++ let finalStatus: string;+ const pipelineType = pipelineInfo?.pipeline || log.pipeline || "";++ if (pipelineType === "extended_evolve_pipeline") {+ finalStatus = completedStages.includes("activate") ? "success" : "failed";+ } else {+ // For other pipelines (meta_evolve_pipeline etc): any failure means task failed+ finalStatus = hasFailure ? "failed" : (log.status || "success");+ }+sections.push({type: "session_finished",- content: log.status === "success" ? "任务执行成功" : `任务执行${log.status || "完成"}`,- status: log.status,+ content: finalStatus === "success" ? "任务执行成功" : `任务执行${finalStatus}`,+ status: finalStatus,pipeline: log.pipeline,});break;@@ -1713,7 +1768,7 @@ function parseAndAggregateLogs(}}- return { sections, state: { pipelineInfo, completedStages, currentStage, extensionOrder, extensionsByName, gapCount, ciFixCount } };+ return { sections, state: { pipelineInfo, completedStages, currentStage, extensionOrder, extensionsByName, gapCount, ciFixCount, hasFailure } };}// Format log section for history display (detailed with colors)@@ -1742,7 +1797,7 @@ const scheduleCancelCommand: SlashCommand = {if (!task_id) {ctx.addItem(- addError(ctx.sessionId, "用法: /auto-harness schedule cancel <task_id>")+ addError(ctx.sessionId, "用法: /auto-harness schedule cancel <task_id>\n示例: /auto-harness schedule cancel sch_abc123"));return;}@@ -1757,7 +1812,7 @@ const scheduleCancelCommand: SlashCommand = {}ctx.addItem(- addInfo(ctx.sessionId, `\n任务已取消: ${result.task_id}\n`)+ addInfo(ctx.sessionId, `\n🛑 任务已取消: ${result.task_id}\n💡 使用 /auto-harness schedule list 查看所有任务\n`));},};@@ -1785,7 +1840,7 @@ const scheduleDeleteCommand: SlashCommand = {if (!task_id) {ctx.addItem(- addError(ctx.sessionId, "用法: /auto-harness schedule delete <task_id>")+ addError(ctx.sessionId, "用法: /auto-harness schedule delete <task_id>\n示例: /auto-harness schedule delete sch_abc123"));return;}@@ -1800,7 +1855,7 @@ const scheduleDeleteCommand: SlashCommand = {}ctx.addItem(- addInfo(ctx.sessionId, `\n任务已删除: ${result.task_id}\n`)+ addInfo(ctx.sessionId, `\n🗑️ 任务已删除: ${result.task_id}\n`));},};@@ -1824,7 +1879,7 @@ const scheduleCommand: SlashCommand = {const subcommand = args.trim().split(/\s+/)[0];if (!subcommand) {ctx.addItem(- addError(ctx.sessionId, "用法: /auto-harness schedule <subcommand>\n子命令: start, list, status, logs, cancel, delete")+ addError(ctx.sessionId, "用法: /auto-harness schedule <子命令> [参数]\n子命令:\n start 创建定时任务\n list 列出所有任务\n status 查看任务详情\n logs 查看执行日志(实时跟踪或历史)\n cancel 取消任务\n delete 删除任务\n示例:\n /auto-harness schedule list\n /auto-harness schedule logs sch_abc123"));}},@@ -1849,7 +1904,7 @@ const runCommand: SlashCommand = {if (!parsed.query) {ctx.addItem(- addError(ctx.sessionId, "用法: /auto-harness run [--pipeline <pipeline>] <query>\npipeline: optimize_expert_harness (生成扩展包), optimize_meta_harness (提交 PR)")+ addError(ctx.sessionId, "用法: /auto-harness run [--pipeline <类型>] <目标>\nPipeline类型:\n optimize_expert_harness - 生成扩展包(本地harness package)\n optimize_meta_harness - 提交PR(需配置git)\n示例:\n /auto-harness run 优化数据库查询性能\n /auto-harness run --pipeline optimize_expert_harness 优化上下文压缩能力"));return;}@@ -1899,7 +1954,7 @@ const runCommand: SlashCommand = {}}- ctx.addItem(addInfo(ctx.sessionId, `\n正在创建一次性任务...\nPipeline: ${pipelineDisplayLabel(pipeline)}\n`, "i"));+ ctx.addItem(addInfo(ctx.sessionId, `\n🚀 正在创建一次性任务...\nPipeline: ${pipelineDisplayLabel(pipeline)}\n`, "i"));// Create and execute one-time taskconst result = await ctx.request<{ error?: string; task_id?: string; status?: string; message?: string }>("schedule.run", {@@ -1915,7 +1970,7 @@ const runCommand: SlashCommand = {}ctx.addItem(- addInfo(ctx.sessionId, `\n一次性任务已创建并开始执行\nID: ${result.task_id}\nPipeline: ${pipelineDisplayLabel(pipeline)}\n状态: ${result.status}\n任务后台运行,默认读取实时日志,可以通过 ctrl + c 中断查看\n`)+ addInfo(ctx.sessionId, `\n🚀 任务已创建并开始执行\n━━━━━━━━━━━━━━━━━━━━━━\n任务ID: ${result.task_id}\nPipeline: ${pipelineDisplayLabel(pipeline)}\n状态: ${result.status}\n━━━━━━━━━━━━━━━━━━━━━━\n💡 正在进入实时日志跟踪模式...\n 按 Ctrl+C 可中断日志查看,任务将继续后台运行\n`));// Start streaming logs@@ -1945,7 +2000,7 @@ export function createAutoHarnessCommand(): SlashCommand {const text = args.trim();if (!text) {ctx.addItem(- addError(ctx.sessionId, "用法: /auto-harness <run|schedule>\n子命令: run, schedule")+ addError(ctx.sessionId, "用法: /auto-harness <run|schedule> [参数]\n子命令:\n run 创建并执行一次性任务\n schedule 管理定时任务\n示例:\n /auto-harness run 优化上下文压缩能力\n /auto-harness schedule list\n /auto-harness schedule logs <task_id>"));}},diff --git a/jiuwenswarm/channels/web/frontend/src/components/HarnessPackagePanel/index.tsx b/jiuwenswarm/channels/web/frontend/src/components/HarnessPackagePanel/index.tsxindex 8a7f0d41dc..8b44dd056b 100644--- a/jiuwenswarm/channels/web/frontend/src/components/HarnessPackagePanel/index.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/HarnessPackagePanel/index.tsx@@ -275,26 +275,40 @@ export function HarnessPackagePanel({ sessionId }: HarnessPackagePanelProps) {setExportSuccess(null);try {- // Send via WebSocket- const result = await webRequest<{ file_content: string; filename: string }>('harness.export', {+ // Send via WebSocket - now returns download URL instead of base64 content+ const result = await webRequest<{+ download_url?: string; // new format - HTTP download URL+ file_content?: string; // legacy format - base64 encoded+ filename: string;+ }>('harness.export', {package_id: selectedPackageId,});- // Decode base64 content and download- const binaryString = atob(result.file_content);- const bytes = new Uint8Array(binaryString.length);- for (let i = 0; i < binaryString.length; i++) {- bytes[i] = binaryString.charCodeAt(i);+ if (result.download_url) {+ // New format: direct HTTP download (avoids WebSocket size limits)+ const a = document.createElement('a');+ a.href = result.download_url;+ a.download = result.filename || `${selectedPackage?.extension_name || 'package'}.zip`;+ document.body.appendChild(a);+ a.click();+ document.body.removeChild(a);+ } else if (result.file_content) {+ // Legacy format: decode base64 and download (for backwards compatibility)+ const binaryString = atob(result.file_content);+ const bytes = new Uint8Array(binaryString.length);+ for (let i = 0; i < binaryString.length; i++) {+ bytes[i] = binaryString.charCodeAt(i);+ }+ const blob = new Blob([bytes], { type: 'application/zip' });+ const url = window.URL.createObjectURL(blob);+ const a = document.createElement('a');+ a.href = url;+ a.download = result.filename || `${selectedPackage?.extension_name || 'package'}.zip`;+ document.body.appendChild(a);+ a.click();+ document.body.removeChild(a);+ window.URL.revokeObjectURL(url);}- const blob = new Blob([bytes], { type: 'application/zip' });- const url = window.URL.createObjectURL(blob);- const a = document.createElement('a');- a.href = url;- a.download = result.filename || `${selectedPackage?.extension_name || 'package'}.zip`;- document.body.appendChild(a);- a.click();- document.body.removeChild(a);- window.URL.revokeObjectURL(url);setExportSuccess(t('harnessPackage.exportSuccess'));} catch (err) {diff --git a/jiuwenswarm/channels/web/frontend/src/components/ToolPanel/HarnessExtensionTree.tsx b/jiuwenswarm/channels/web/frontend/src/components/ToolPanel/HarnessExtensionTree.tsxindex 906d246cec..fc0fd830a9 100644--- a/jiuwenswarm/channels/web/frontend/src/components/ToolPanel/HarnessExtensionTree.tsx+++ b/jiuwenswarm/channels/web/frontend/src/components/ToolPanel/HarnessExtensionTree.tsx@@ -4,11 +4,12 @@* Displays a file tree for runtime extension files in auto_harness mode.* Uses runtime_path from extension_ready event to fetch file listing.* Supports hierarchical directory structure with expand/collapse.+ * Uses global cache to avoid repeated API calls.*/import { useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';-import { useHarnessStore } from '../../stores';+import { useHarnessStore, CachedFileTreeEntry } from '../../stores';import { webRequest } from '../../services/webClient';import { ReadOnlyFileModal } from './ReadOnlyFileModal';@@ -26,6 +27,8 @@ interface HarnessExtensionTreeProps {extensionName?: string;/** Whether to show export button (default: true for ToolPanel, false for HarnessPackagePanel) */showExport?: boolean;+ /** Force refresh (bypass cache) */+ forceRefresh?: boolean;}const compareByName = (a: string, b: string) => a.localeCompare(b, 'zh-Hans-CN');@@ -43,9 +46,37 @@ function isPreviewableFile(fileName: string): boolean {);}+// Convert cached entries to FileInfo format+function cachedToFileInfo(cached: CachedFileTreeEntry[]): FileInfo[] {+ return cached.map(entry => ({+ name: entry.name,+ path: entry.path,+ is_dir: entry.is_dir,+ children: entry.children ? cachedToFileInfo(entry.children) : undefined,+ }));+}++// Convert FileInfo to cached format+function fileInfoToCached(files: FileInfo[]): CachedFileTreeEntry[] {+ return files.map(file => ({+ name: file.name,+ path: file.path,+ is_dir: file.is_dir,+ children: file.children ? fileInfoToCached(file.children) : undefined,+ }));+}+export function HarnessExtensionTree(props?: HarnessExtensionTreeProps) {const { t } = useTranslation();- const { extensionReady, packages } = useHarnessStore();+ const {+ extensionReady,+ packages,+ getFileTreeCache,+ setFileTreeCache,+ clearFileTreeCache,+ setFileTreeLoading,+ isFileTreeLoading,+ } = useHarnessStore();const [files, setFiles] = useState<FileInfo[]>([]);const [loading, setLoading] = useState(false);const [loadError, setLoadError] = useState<string | null>(null);@@ -67,7 +98,7 @@ export function HarnessExtensionTree(props?: HarnessExtensionTreeProps) {const packageId = currentPackage?.id || null;const canExport = !isSessionRuntimeRoot && packageId && packageId !== 'native';- // Recursively fetch directory contents+ // Recursively fetch directory contents (parallel fetch for subdirectories)const fetchDirectoryContents = async (dirPath: string): Promise<FileInfo[]> => {const encodedPath = encodeURIComponent(dirPath);const url = `/file-api/list-files?dir=${encodedPath}`;@@ -95,34 +126,55 @@ export function HarnessExtensionTree(props?: HarnessExtensionTreeProps) {return compareByName(a.name, b.name);});- // Recursively fetch contents for subdirectories- for (const entry of entries) {- if (entry.is_dir) {- try {- entry.children = await fetchDirectoryContents(entry.path);- } catch (err) {+ // Parallel fetch contents for all subdirectories using Promise.all+ const subdirEntries = entries.filter(e => e.is_dir);+ const subdirFetches = subdirEntries.map(entry =>+ fetchDirectoryContents(entry.path)+ .then(children => { entry.children = children; return entry; })+ .catch(err => {console.error(`Failed to load subdirectory ${entry.path}:`, err);entry.children = [];- }- }- }+ return entry;+ })+ );+ await Promise.all(subdirFetches);return entries;};- const loadFiles = async () => {+ const loadFiles = async (forceRefresh = false) => {if (!runtimePath) {setFiles([]);setLoading(false);return;}+ // Check cache first (unless force refresh)+ if (!forceRefresh && !props?.forceRefresh) {+ const cached = getFileTreeCache(runtimePath);+ if (cached && cached.length > 0) {+ setFiles(cachedToFileInfo(cached));+ // Auto-expand root level directories from cache+ const rootDirPaths = cached.filter(f => f.is_dir).map(f => f.path);+ setExpandedPaths(new Set(rootDirPaths));+ return;+ }+ }++ // Check if already loading this path (prevent duplicate requests)+ if (isFileTreeLoading(runtimePath)) {+ return;+ }+setLoading(true);setLoadError(null);+ setFileTreeLoading(runtimePath, true);try {const fileList = await fetchDirectoryContents(runtimePath);setFiles(fileList);+ // Save to cache+ setFileTreeCache(runtimePath, fileInfoToCached(fileList));// Auto-expand root level directoriesconst rootDirPaths = fileList.filter(f => f.is_dir).map(f => f.path);setExpandedPaths(new Set(rootDirPaths));@@ -132,9 +184,15 @@ export function HarnessExtensionTree(props?: HarnessExtensionTreeProps) {setFiles([]);} finally {setLoading(false);+ setFileTreeLoading(runtimePath, false);}};+ const handleRefresh = () => {+ clearFileTreeCache(runtimePath);+ loadFiles(true);+ };+useEffect(() => {loadFiles();}, [runtimePath]);@@ -161,10 +219,6 @@ export function HarnessExtensionTree(props?: HarnessExtensionTreeProps) {setModalOpen(false);};- const handleRefresh = () => {- loadFiles();- };-const handleExport = async () => {if (!packageId) return;@@ -172,26 +226,40 @@ export function HarnessExtensionTree(props?: HarnessExtensionTreeProps) {setExportError(null);try {- // Send via WebSocket- const result = await webRequest<{ file_content: string; filename: string }>('harness.export', {+ // Send via WebSocket - now returns download URL instead of base64 content+ const result = await webRequest<{+ download_url?: string; // new format - HTTP download URL+ file_content?: string; // legacy format - base64 encoded+ filename: string;+ }>('harness.export', {package_id: packageId,});- // Decode base64 content and download- const binaryString = atob(result.file_content);- const bytes = new Uint8Array(binaryString.length);- for (let i = 0; i < binaryString.length; i++) {- bytes[i] = binaryString.charCodeAt(i);+ if (result.download_url) {+ // New format: direct HTTP download (avoids WebSocket size limits)+ const a = document.createElement('a');+ a.href = result.download_url;+ a.download = result.filename || `${extensionName || 'package'}.zip`;+ document.body.appendChild(a);+ a.click();+ document.body.removeChild(a);+ } else if (result.file_content) {+ // Legacy format: decode base64 and download (for backwards compatibility)+ const binaryString = atob(result.file_content);+ const bytes = new Uint8Array(binaryString.length);+ for (let i = 0; i < binaryString.length; i++) {+ bytes[i] = binaryString.charCodeAt(i);+ }+ const blob = new Blob([bytes], { type: 'application/zip' });+ const url = window.URL.createObjectURL(blob);+ const a = document.createElement('a');+ a.href = url;+ a.download = result.filename || `${extensionName || 'package'}.zip`;+ document.body.appendChild(a);+ a.click();+ document.body.removeChild(a);+ window.URL.revokeObjectURL(url);}- const blob = new Blob([bytes], { type: 'application/zip' });- const url = window.URL.createObjectURL(blob);- const a = document.createElement('a');- a.href = url;- a.download = result.filename || `${extensionName || 'package'}.zip`;- document.body.appendChild(a);- a.click();- document.body.removeChild(a);- window.URL.revokeObjectURL(url);} catch (err) {console.error('Export failed:', err);setExportError(err instanceof Error ? err.message : t('harnessPackage.exportError'));diff --git a/jiuwenswarm/channels/web/frontend/src/stores/harnessStore.ts b/jiuwenswarm/channels/web/frontend/src/stores/harnessStore.tsindex ae3742c4e8..28a60ab16c 100644--- a/jiuwenswarm/channels/web/frontend/src/stores/harnessStore.ts+++ b/jiuwenswarm/channels/web/frontend/src/stores/harnessStore.ts@@ -84,6 +84,16 @@ export interface ActivateInteractionState {pending: boolean;}+/**+ * File tree entry for caching+ */+export interface CachedFileTreeEntry {+ name: string;+ path: string;+ is_dir: boolean;+ children?: CachedFileTreeEntry[];+}+/*** Harness state interface*/@@ -124,6 +134,11 @@ interface HarnessState {// Deactivating statedeactivatingPackage: boolean;+ // File tree cache by runtime path (key: runtimePath, value: file tree)+ extensionFileTreeCache: Record<string, CachedFileTreeEntry[]>;+ // Loading state for file tree by path+ fileTreeLoadingPaths: Record<string, boolean>;+// ActionssetStageDefinitions: (stages: HarnessStageDefinition[]) => void;addHarnessMessage: (content: string, stage?: string) => void;@@ -149,6 +164,13 @@ interface HarnessState {setLoadingPackages: (loading: boolean) => void;setActivatingPackage: (activating: boolean) => void;setDeactivatingPackage: (deactivating: boolean) => void;++ // File tree cache actions+ setFileTreeCache: (runtimePath: string, files: CachedFileTreeEntry[]) => void;+ getFileTreeCache: (runtimePath: string) => CachedFileTreeEntry[] | undefined;+ clearFileTreeCache: (runtimePath?: string) => void;+ setFileTreeLoading: (runtimePath: string, loading: boolean) => void;+ isFileTreeLoading: (runtimePath: string) => boolean;}/**@@ -229,6 +251,9 @@ export const useHarnessStore = create<HarnessState>((set, get) => ({activatingPackage: false,deactivatingPackage: false,+ extensionFileTreeCache: {},+ fileTreeLoadingPaths: {},+setStageDefinitions: (stages) => {// Only set stages once - ignore subsequent updatesset((state) => {@@ -453,6 +478,8 @@ export const useHarnessStore = create<HarnessState>((set, get) => ({loadingPackages: false,activatingPackage: false,deactivatingPackage: false,+ extensionFileTreeCache: {},+ fileTreeLoadingPaths: {},});},@@ -488,4 +515,55 @@ export const useHarnessStore = create<HarnessState>((set, get) => ({setDeactivatingPackage: (deactivating) => {set({ deactivatingPackage: deactivating });},++ // File tree cache actions+ setFileTreeCache: (runtimePath, files) => {+ set((state) => ({+ extensionFileTreeCache: {+ ...state.extensionFileTreeCache,+ [runtimePath]: files,+ },+ fileTreeLoadingPaths: {+ ...state.fileTreeLoadingPaths,+ [runtimePath]: false,+ },+ }));+ },++ getFileTreeCache: (runtimePath) => {+ return get().extensionFileTreeCache[runtimePath];+ },++ clearFileTreeCache: (runtimePath) => {+ if (runtimePath) {+ set((state) => {+ const newCache = { ...state.extensionFileTreeCache };+ delete newCache[runtimePath];+ const newLoading = { ...state.fileTreeLoadingPaths };+ delete newLoading[runtimePath];+ return {+ extensionFileTreeCache: newCache,+ fileTreeLoadingPaths: newLoading,+ };+ });+ } else {+ set({+ extensionFileTreeCache: {},+ fileTreeLoadingPaths: {},+ });+ }+ },++ setFileTreeLoading: (runtimePath, loading) => {+ set((state) => ({+ fileTreeLoadingPaths: {+ ...state.fileTreeLoadingPaths,+ [runtimePath]: loading,+ },+ }));+ },++ isFileTreeLoading: (runtimePath) => {+ return get().fileTreeLoadingPaths[runtimePath] || false;+ },}));diff --git a/jiuwenswarm/channels/web/frontend/src/stores/index.ts b/jiuwenswarm/channels/web/frontend/src/stores/index.tsindex e5d2315b36..2ee4f5fb4e 100644--- a/jiuwenswarm/channels/web/frontend/src/stores/index.ts+++ b/jiuwenswarm/channels/web/frontend/src/stores/index.ts@@ -6,4 +6,4 @@ export { useChatStore } from './chatStore';export { useTodoStore } from './todoStore';export { useSessionStore } from './sessionStore';export { useHarnessStore } from './harnessStore';-export type { HarnessStageInfo, HarnessStageStatus } from './harnessStore';+export type { HarnessStageInfo, HarnessStageStatus, CachedFileTreeEntry } from './harnessStore';diff --git a/jiuwenswarm/gateway/channel_manager/tui/tui_connect.py b/jiuwenswarm/gateway/channel_manager/tui/tui_connect.pyindex d9cc68645c..6282ef3431 100644--- a/jiuwenswarm/gateway/channel_manager/tui/tui_connect.py+++ b/jiuwenswarm/gateway/channel_manager/tui/tui_connect.py@@ -48,6 +48,7 @@ _AUTO_HARNESS_CONFIG_FILE = _AUTO_HARNESS_CONFIG_DIR / "config.yaml"_AUTO_HARNESS_LOCAL_REPO = _AUTO_HARNESS_CONFIG_DIR / "repo" / "openJiuwen--agent-core"# Default values for ci_gate config+_DEFAULT_CI_GATE_PYTHON_EXECUTABLE = sys.executable_DEFAULT_CI_GATE_INSTALL_COMMAND = "uv sync --active --group dev --extra cli"@@ -88,14 +89,20 @@ def _get_auto_harness_config() -> dict[str, Any]:config["local_repo"] = str(local_repo)needs_save = True- if ci_gate.get("python_executable"):- ci_gate["python_executable"] = ""+ if not ci_gate.get("python_executable"):+ ci_gate["python_executable"] = str(_DEFAULT_CI_GATE_PYTHON_EXECUTABLE)needs_save = Trueif not ci_gate.get("install_command"):ci_gate["install_command"] = _DEFAULT_CI_GATE_INSTALL_COMMANDneeds_save = True+ budget = config.get("budget", {})+ max_tasks_per_session = budget.get("max_tasks_per_session", 5)+ if max_tasks_per_session > 5:+ budget["max_tasks_per_session"] = 5+ needs_save = True+if needs_save:config["ci_gate"] = ci_gate_save_auto_harness_config(config)diff --git a/jiuwenswarm/gateway/channel_manager/web/app_web_handlers.py b/jiuwenswarm/gateway/channel_manager/web/app_web_handlers.pyindex 7368cdfd3d..7dc4b6a3e7 100644--- a/jiuwenswarm/gateway/channel_manager/web/app_web_handlers.py+++ b/jiuwenswarm/gateway/channel_manager/web/app_web_handlers.py@@ -48,6 +48,7 @@ from jiuwenswarm.common.utils import (get_user_workspace_dir)from jiuwenswarm.agents.harness.common.auto_harness import AutoHarnessService+from jiuwenswarm.agents.harness.common.tools.web_file_download import build_file_download_infofrom jiuwenswarm.common.version import __version__for _jiuwen_log in LogManager.get_all_loggers().values():@@ -2572,8 +2573,11 @@ def _register_web_handlers(bind: WebHandlersBindParams) -> None:channel.register_method("harness.import", _harness_import_handler)async def _harness_export_handler(ws, req_id, params, session_id):- """Export a harness package via WebSocket (returns base64 encoded zip content)."""- # Get package_id+ """Export a harness package - returns download URL instead of base64 content.++ Uses HTTP download endpoint to avoid WebSocket message size limits.+ The temporary zip file will be cleaned up after download or token expiry.+ """package_id = params.get("package_id")if not package_id:await channel.send_response(ws, req_id, ok=False, error="Missing package_id", code="BAD_REQUEST")@@ -2582,23 +2586,25 @@ def _register_web_handlers(bind: WebHandlersBindParams) -> None:try:service = AutoHarnessService(rail=None, agent=None)zip_path = service.export_package(package_id)- # Read zip file and encode as base64- zip_content = zip_path.read_bytes()- zip_content_b64 = base64.b64encode(zip_content).decode("utf-8")- filename = zip_path.name++ download_info = build_file_download_info(+ str(zip_path),+ zip_path.name,+ session_id,+ expires_in=600, # 10 minutes+ )await channel.send_response(ws, req_id, ok=True, payload={"ok": True,- "file_content": zip_content_b64,- "filename": filename,+ "download_url": download_info["download_url"],+ "download_token": download_info["download_token"],+ "filename": download_info["name"],+ "file_size": download_info["size"],+ "expires_at": download_info["expires_at"],"message": "Package exported successfully",})-- # Cleanup temp zip file- try:- zip_path.unlink(missing_ok=True)- except Exception:- pass+ # No cleanup here - file will be served via HTTP download endpoint+ # and cleaned up after download or when token expiresexcept ValueError as exc:msg = str(exc)if "not found" in msg.lower():diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.pyindex bd8a190380..7a2191326a 100644--- a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py@@ -3010,8 +3010,11 @@ class JiuWenClawDeepAdapter:str(channel_id or self._resolve_prompt_channel(session_id) or "web").strip() or "web")send_file_enabled = (- config_base.get("channels", {}).get(channel, {}).get("send_file_allowed", False)+ config_base.get("channels", {}).get(channel, {}).get("send_file_allowed"))+ # web channel defaults to True, others default to False+ if send_file_enabled is None:+ send_file_enabled = (channel == "web")if send_file_enabled and request_id and session_id:channel_for_tool = _CRON_TOOL_CHANNEL_ID.get()metadata_for_tool = _CRON_TOOL_METADATA.get()diff --git a/uv.lock b/uv.lockindex ab020665f2..e8a2ad017d 100644--- a/uv.lock+++ b/uv.lock@@ -2379,7 +2379,7 @@ wheels = [[[package]]name = "openjiuwen"version = "0.1.13"-source = { git = "https://gitcode.com/openJiuwen/agent-core.git?rev=develop#a218490d3dd1ada14e5f462d4df03e3a7f4494d1" }+source = { git = "https://gitcode.com/openJiuwen/agent-core.git?rev=develop#77df4fa7f48c1aa82434827b4ef0611fe74a0230" }dependencies = [{ name = "aiofiles" },{ name = "aiohttp" },