Skip to content

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): Tui Set default meta pipeline & optimize log viewing

ray_lec73eb4ece3c2
diff --git a/jiuwenclaw/agents/harness/common/auto_harness/scheduler.py b/jiuwenclaw/agents/harness/common/auto_harness/scheduler.py
index 1b5fc0c47e..84ed8c4675 100644
--- a/jiuwenclaw/agents/harness/common/auto_harness/scheduler.py
+++ b/jiuwenclaw/agents/harness/common/auto_harness/scheduler.py
@@ -292,6 +292,10 @@ class Scheduler:
request, session_id, execution_id, query, model=model
):
if chunk.payload:
+ # Skip context compression events - not needed in logs
+ event_type = chunk.payload.get("event_type", "")
+ if event_type in ("context.compressed", "context_compression_state"):
+ continue
# Append log chunk immediately (JSON Lines format)
log_file.write(json.dumps(chunk.payload, ensure_ascii=False) + "\n")
log_file.flush()
diff --git a/jiuwenclaw/agents/harness/common/auto_harness/service.py b/jiuwenclaw/agents/harness/common/auto_harness/service.py
index 03e6e7687c..38cf205dd3 100644
--- a/jiuwenclaw/agents/harness/common/auto_harness/service.py
+++ b/jiuwenclaw/agents/harness/common/auto_harness/service.py
@@ -23,6 +23,7 @@ import json
import logging
import os
import shutil
+import sys
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from pathlib import Path
@@ -68,6 +69,11 @@ _AUTO_HARNESS_DATA_DIR = get_user_workspace_dir() / "auto-harness"
_HARNESS_PACKAGES_FILE = _AUTO_HARNESS_DATA_DIR / "harness-packages.json"
# Default repo URL if not specified in request (per §5.5)
_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"
def reset_harness_packages_state() -> None:
@@ -228,10 +234,64 @@ class AutoHarnessService:
exc,
)
+ @staticmethod
+ def _fill_config_defaults(config_path: Path) -> None:
+ """Fill default values for missing config items and save to file.
+
+ Args:
+ config_path: Path to the config.yaml file
+
+ This function reads the config file, checks for missing defaults,
+ fills them in if needed, and saves the updated config.
+ """
+ config_dict: dict[str, Any] = {}
+ if config_path.exists():
+ try:
+ config_dict = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
+ except Exception as e:
+ logger.warning("[AutoHarnessService] Failed to parse config.yaml: %s", e)
+ config_dict = {}
+
+ needs_save = False
+
+ # Ensure local_repo is a string (not Path object which causes YAML serialization issues)
+ local_repo = config_dict.get("local_repo")
+ if not local_repo:
+ config_dict["local_repo"] = str(_DEFAULT_LOCAL_REPO)
+ needs_save = True
+ elif hasattr(local_repo, "__fspath__"): # Path-like object
+ config_dict["local_repo"] = str(local_repo)
+ needs_save = True
+
+ ci_gate = config_dict.get("ci_gate") or {}
+ if not ci_gate.get("python_executable"):
+ ci_gate["python_executable"] = _DEFAULT_CI_GATE_PYTHON_EXECUTABLE
+ needs_save = True
+
+ if not ci_gate.get("install_command"):
+ ci_gate["install_command"] = _DEFAULT_CI_GATE_INSTALL_COMMAND
+ needs_save = True
+
+ if needs_save:
+ config_dict["ci_gate"] = ci_gate
+ config_path.parent.mkdir(parents=True, exist_ok=True)
+ config_path.write_text(
+ yaml.dump(config_dict, allow_unicode=True, sort_keys=False, default_flow_style=False),
+ encoding="utf-8"
+ )
+ logger.info(
+ "[AutoHarnessService] Auto-filled config defaults: " \
+ "local_repo=%s, python_executable=%s, install_command=%s",
+ config_dict.get("local_repo"),
+ ci_gate.get("python_executable"),
+ ci_gate.get("install_command"),
+ )
+
def _load_base_config(self) -> None:
"""Load base config.yaml once at init (per §5.6.2).
Config is bootstrapped from template if not exists.
+ Auto-fills default values for missing config items and saves to file.
This provides default values; per-request overrides applied in build_auto_harness_config.
"""
try:
@@ -239,7 +299,19 @@ class AutoHarnessService:
"[AutoHarnessService] Loading base config from: %s",
self.config_path,
)
+
+ # Check if config file exists before calling load_auto_harness_config
+ config_exists = self.config_path.exists()
+
+ # Step 1: Call load_auto_harness_config to bootstrap default config file if not exists
self._base_config = load_auto_harness_config(str(self.config_path))
+
+ # Step 2: Fill defaults only when config file was newly created
+ if not config_exists:
+ self._fill_config_defaults(self.config_path)
+ # Reload config with updated values
+ self._base_config = load_auto_harness_config(str(self.config_path))
+
logger.info(
"[AutoHarnessService] Base config loaded successfully",
)
@@ -408,6 +480,7 @@ class AutoHarnessService:
local_repo: Path,
model: Optional[Model],
optimization_goal: str = "",
+ pipeline_preference: Optional[str] = None
) -> AutoHarnessConfig:
"""Build AutoHarnessConfig with per-request overrides (per §5.6.3).
@@ -442,7 +515,7 @@ class AutoHarnessService:
config.workspace = str(resolved_local_repo)
config.repo_url = repo_url
config.experience_dir = str(self.experience_dir)
- config.pipeline_preference = EXTENDED_EVOLVE_PIPELINE
+ config.pipeline_preference = pipeline_preference if pipeline_preference else EXTENDED_EVOLVE_PIPELINE
config.optimization_goal = str(optimization_goal or "")
# Set model from JiuwenClaw
@@ -1124,6 +1197,8 @@ class AutoHarnessService:
)
active_run: Optional[ActiveAutoHarnessRun] = None
+ params = getattr(request, "params", {}) or {}
+ pipeline_preference = params.get("pipeline_preference")
try:
# Clone/update repository
local_repo = await self.clone_or_update_repo(repo_url)
@@ -1135,6 +1210,7 @@ class AutoHarnessService:
local_repo,
model,
optimization_goal=query,
+ pipeline_preference=pipeline_preference
)
# Build optimization task from query
diff --git a/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/auto-harness.ts b/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/auto-harness.ts
index 86fc4fe30e..1623447271 100644
--- a/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/auto-harness.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/auto-harness.ts
@@ -265,6 +265,13 @@ const scheduleLogsCommand: SlashCommand = {
return !p.startsWith("-") && p !== historyIndexValue && !/^\d+$/.test(p);
}) || "";
+ // Helper: build completion string preserving existing arguments
+ // Returns the full argument string including existing args and the completion
+ const buildCompletion = (completion: string, replaceLast: boolean = true): string => {
+ const prefixParts = replaceLast ? parts.slice(0, -1) : parts;
+ return [...prefixParts, completion].join(" ");
+ };
+
// Step 1: Check if we need a history index value
// --history is present and we're at the value position
if (parts.includes("--history")) {
@@ -273,9 +280,20 @@ const scheduleLogsCommand: SlashCommand = {
if (parts.length === historyIdx + 1) {
const values = ["0", "1", "2", "3", "4"];
if (lastPart && /^\d/.test(lastPart)) {
- return values.filter((v) => v.startsWith(lastPart));
+ // Preserve existing task_id before --history when completing index value
+ const taskIdBeforeHistory = parts.slice(0, historyIdx).find((p) => !p.startsWith("-"));
+ const filtered = values.filter((v) => v.startsWith(lastPart));
+ if (taskIdBeforeHistory) {
+ return filtered.map((v) => `${taskIdBeforeHistory} --history ${v}`);
+ }
+ return filtered.map((v) => buildCompletion(v));
}
- return values;
+ // No number typed yet, suggest values with existing args preserved
+ const taskIdBeforeHistory = parts.slice(0, historyIdx).find((p) => !p.startsWith("-"));
+ if (taskIdBeforeHistory) {
+ return values.map((v) => `${taskIdBeforeHistory} --history ${v}`);
+ }
+ return values.map((v) => buildCompletion(v));
}
// If history index is complete with trailing space, suggest task_ids
// Check: history value exists AND there's a trailing space
@@ -283,7 +301,9 @@ const scheduleLogsCommand: SlashCommand = {
try {
const result = await ctx.request<{ tasks?: Array<{ task_id: string }> }>("schedule.list", {}, 5000);
const tasks = result.tasks || [];
- return tasks.map((t) => t.task_id);
+ // Return full string with existing args + task_id
+ const existingArgs = parts.slice(0, -1).join(" ");
+ return tasks.map((t) => `${existingArgs} ${t.task_id}`);
} catch {
return [];
}
@@ -296,18 +316,26 @@ const scheduleLogsCommand: SlashCommand = {
// Step 2: Check if lastPart is exactly --history - suggest values immediately
if (lastPart === "--history") {
- return ["0", "1", "2", "3", "4"];
+ // Preserve existing task_id when suggesting history index values
+ if (existingTaskId) {
+ return ["0", "1", "2", "3", "4"].map((v) => `${existingTaskId} --history ${v}`);
+ }
+ return ["0", "1", "2", "3", "4"].map((v) => buildCompletion(v));
}
- // Step 3: If typing a flag, suggest --history only (--current is default, no need to suggest)
+ // Step 3: If typing a flag, suggest --history with existing args preserved
if (lastPart.startsWith("-") && lastPart !== "--history") {
if (parts.includes("--history")) return [];
- return ["--history"].filter((f) => f.startsWith(lastPart));
+ // Preserve existing task_id when completing --history flag
+ if (existingTaskId) {
+ return ["--history"].filter((f) => f.startsWith(lastPart)).map((f) => `${existingTaskId} ${f}`);
+ }
+ return ["--history"].filter((f) => f.startsWith(lastPart)).map((f) => buildCompletion(f));
}
- // Step 4: If we have a task_id already, suggest --history flag
+ // Step 4: If we have a task_id already, suggest --history flag (preserve task_id)
if (existingTaskId && !parts.includes("--history")) {
- return ["--history"];
+ return [`${existingTaskId} --history`];
}
// Step 5: Otherwise, suggest task_ids
@@ -351,6 +379,14 @@ interface LogEntry {
source_chunk_type?: string;
tool_name?: string;
is_error?: boolean;
+ // Error message (from chat.error event)
+ error?: string;
+ // Pipeline and stages info (from harness.message)
+ pipeline?: string;
+ stages?: Array<{ slot: string; display_name: string }>;
+ // Session finished info
+ is_terminal?: boolean;
+ results_count?: number;
// Nested tool payload (as in history-parser.ts resolveToolPayload)
tool_call?: {
name?: string;
@@ -387,6 +423,9 @@ async function streamCurrentLogs(
let consecutiveEmptyPolls = 0;
const maxEmptyPolls = 3; // Stop after 3 consecutive empty polls when not running
+ // Parse state for maintaining pipeline info across batches
+ let parseState: ParseState | undefined;
+
// Clear any previous interrupt flag before starting new stream
ctx.clearInterruptRequested();
@@ -443,8 +482,8 @@ async function streamCurrentLogs(
task_id,
log_type: "current",
offset,
- limit: 1000,
- }, 30000); // 30s timeout
+ limit: 3000,
+ }, 1200000); // 60s timeout
// Request was interrupted - clear flag and show message via helper
if (result === null) {
@@ -474,49 +513,17 @@ async function streamCurrentLogs(
if (logs.length > 0) {
consecutiveEmptyPolls = 0;
- // Check first event type to decide how to handle reasoning
- const firstEventType = logs[0]?.event_type || "";
-
- if (firstEventType === "chat.reasoning") {
- // Logs start with reasoning - find first non-reasoning index
- let firstNonReasoningIdx = -1;
- for (let i = 0; i < logs.length; i++) {
- if (logs[i]?.event_type !== "chat.reasoning") {
- firstNonReasoningIdx = i;
- break;
- }
- }
-
- if (firstNonReasoningIdx === -1) {
- // All logs are reasoning - discard entire batch
- offset = offset + logs.length;
- } else {
- // Skip leading reasoning, display rest
- const logsToDisplay = logs.slice(firstNonReasoningIdx);
- const sections = parseAndAggregateLogs(logsToDisplay);
- for (const section of sections) {
- // Check interrupt during log display
- if (checkInterrupt()) return;
- const formattedLine = formatLogSection(section);
- if (formattedLine) {
- ctx.addItem(addInfo(ctx.sessionId, formattedLine, "i"));
- }
- }
- offset = offset + logs.length;
- }
- } else {
- // Not starting with reasoning - display all
- const sections = parseAndAggregateLogs(logs);
- for (const section of sections) {
- // Check interrupt during log display
- if (checkInterrupt()) return;
- const formattedLine = formatLogSection(section);
- if (formattedLine) {
- ctx.addItem(addInfo(ctx.sessionId, formattedLine, "i"));
- }
+ const parseResult = parseAndAggregateLogs(logs, parseState);
+ parseState = parseResult.state;
+ for (const section of parseResult.sections) {
+ // Check interrupt during log display
+ if (checkInterrupt()) return;
+ const formattedLine = formatLogSection(section);
+ if (formattedLine) {
+ ctx.addItem(addInfo(ctx.sessionId, formattedLine, "i"));
}
- offset = offset + logs.length;
}
+ offset = offset + logs.length;
} else {
consecutiveEmptyPolls++;
}
@@ -564,7 +571,7 @@ async function readFullHistoryLogs(
let allLogs: Array<LogEntry> = [];
let offset = 0;
- const batchSize = 2000;
+ const batchSize = 5000;
let executionId = "";
let completedAt = "";
let status = "";
@@ -612,29 +619,21 @@ async function readFullHistoryLogs(
hasMore = result.has_more ?? (logs.length >= batchSize);
}
- // Filter out ALL reasoning entries for history logs (no thinking display)
- // Remove chat.reasoning events AND chat.delta with llm_reasoning source
- allLogs = allLogs.filter((log) => {
- if (log.event_type === "chat.reasoning") return false;
- if (log.event_type === "chat.delta" && log.source_chunk_type === "llm_reasoning") return false;
- return true;
- });
-
// Display full aggregated logs
if (allLogs.length === 0) {
ctx.addItem(addInfo(ctx.sessionId, "日志为空"));
return;
}
- const sections = parseAndAggregateLogs(allLogs);
- const lines: string[] = [`\n【执行日志: ${executionId}】`];
+ const result = parseAndAggregateLogs(allLogs);
+ const lines: string[] = [`【执行日志: ${executionId}】`];
if (completedAt) {
lines.push(`完成时间: ${formatLocalTime(completedAt)} | 状态: ${status}`);
}
lines.push("");
lines.push("=" .repeat(60));
- for (const section of sections) {
+ for (const section of result.sections) {
const formattedLine = formatLogSectionDetailed(section);
if (formattedLine) {
lines.push(formattedLine);
@@ -644,7 +643,19 @@ async function readFullHistoryLogs(
lines.push("=" .repeat(60));
lines.push("");
- ctx.addItem(addInfo(ctx.sessionId, lines.join("\n")));
+ const formattedContent = lines.join("\n");
+
+ // Use FileViewer mode if available (TUI environment)
+ if (ctx.enterFileViewer) {
+ ctx.enterFileViewer(
+ formattedContent,
+ `执行日志: ${executionId}`,
+ `task_id: ${task_id}, history_index: ${history_index}`,
+ );
+ } else {
+ // Fallback: display directly (non-TUI environment)
+ ctx.addItem(addInfo(ctx.sessionId, formattedContent));
+ }
}
/**
@@ -652,13 +663,17 @@ async function readFullHistoryLogs(
* Merges streaming chunks (chat.delta, chat.reasoning) into complete messages.
*/
interface ParsedLogSection {
- type: "thinking" | "assistant" | "stage" | "status" | "error" | "info" | "tool";
+ type: "thinking" | "assistant" | "stage" | "status" | "error" | "info" | "tool" | "pipeline" | "session_finished";
content: string;
stage?: string;
status?: string;
timestamp?: string;
tool_name?: string;
tool_success?: boolean;
+ // Pipeline info
+ pipeline?: string;
+ stages?: Array<{ slot: string; display_name: string }>;
+ completed_stages?: string[];
}
// ANSI color codes for log display differentiation
@@ -668,46 +683,189 @@ const ANSI = {
red: "\x1b[31m", // 错误/失败
yellow: "\x1b[33m", // 阶段
blue: "\x1b[34m", // 状态
+ magenta: "\x1b[35m", // 压缩信息
brightWhite: "\x1b[97m", // 辅助输出 (柔和)
- gray: "\x1b[90m", // 思考 (dim)
+ gray: "\x1b[90m", // 普通 gray (bright black)
+ dimGray: "\x1b[38;5;240m", // 更暗的灰色 (256-color mode)
bold: "\x1b[1m",
reset: "\x1b[0m",
};
+// Helper function to calculate visual width (Chinese/CJK chars = 2, others = 1)
+function visualWidth(str: string): number {
+ let width = 0;
+ for (const char of str) {
+ const code = char.charCodeAt(0);
+ // Box drawing characters (U+2500-U+257F) are width 1
+ // Emoji and CJK characters (above U+257F or in CJK ranges) are width 2
+ // ASCII and other symbols are width 1
+ if (code >= 0x2500 && code <= 0x257F) {
+ width += 1; // Box drawing
+ } else if (
+ (code >= 0x4E00 && code <= 0x9FFF) || // CJK Unified Ideographs
+ (code >= 0x3000 && code <= 0x303F) || // CJK Symbols
+ (code >= 0xFF00 && code <= 0xFFEF) || // Halfwidth/Fullwidth
+ code >= 0x1F000 // Emoji and other high ranges
+ ) {
+ width += 2; // Wide characters (Chinese, emoji)
+ } else {
+ width += 1; // ASCII and others
+ }
+ }
+ return width;
+}
+
+// Helper function to wrap text to a maximum visual width
+function wrapText(text: string, maxWidth?: number): string {
+ // Auto-detect terminal width if not provided
+ // "💬 " prefix takes 4 visual chars (emoji=2, space=1), leave 2 margin on right
+ const defaultWidth = (process.stdout.columns || 100) - 6;
+ const wrapWidth = maxWidth ?? defaultWidth;
+
+ const lines: string[] = [];
+ const paragraphs = text.split('\n');
+
+ for (const paragraph of paragraphs) {
+ if (paragraph.trim() === '') {
+ lines.push('');
+ continue;
+ }
+
+ let currentLine = '';
+ let currentWidth = 0;
+
+ for (const char of paragraph) {
+ const charWidth = visualWidth(char);
+
+ if (currentWidth + charWidth > wrapWidth && currentLine.length > 0) {
+ lines.push(currentLine);
+ currentLine = char;
+ currentWidth = charWidth;
+ } else {
+ currentLine += char;
+ currentWidth += charWidth;
+ }
+ }
+
+ if (currentLine.length > 0) {
+ lines.push(currentLine);
+ }
+ }
+
+ return lines.join('\n');
+}
+
+// Helper function to create a proper box with title embedded in top border
+function createBox(title: string, content: string, color: string): string {
+ // Fixed structure: left padding 32 ═, right padding 37 ═ (asymmetric for visual balance)
+ const leftDashes = 32;
+ const rightDashes = 37;
+
+ // Calculate visual widths
+ const titleVisualWidth = visualWidth(title);
+ const contentVisualWidth = visualWidth(content);
+
+ // Calculate required widths:
+ // Top border: ╔(1) + ═(32) + sp(1) + title + sp(1) + ═(37) + ╗(1) = 72 + titleVisualWidth
+ const topVisualWidth = 72 + titleVisualWidth;
+
+ // Content line: ║(1) + sp(1) + content + padding + sp(1) + ║(1) = 4 + contentVisualWidth + padding
+ // We need content line to match top border width
+ // So: padding = topVisualWidth - 4 - contentVisualWidth
+ const contentPadding = topVisualWidth - 3 - contentVisualWidth;
+
+ // If content is wider than available space (negative padding), truncate
+ const topBorder = `╔${"═".repeat(leftDashes)} ${title} ${"═".repeat(rightDashes)}╗`;
+ const paddedContent = contentPadding < 0
+ ? `║ ${content.substring(0, topVisualWidth - 7)}... ║`
+ : `║ ${content}${" ".repeat(Math.max(0, contentPadding))} ║`;
+ // Bottom border: all ═ characters matching top visual width (minus corners)
+ const bottomBorder = `╚${"═".repeat(topVisualWidth - 1)}╝`;
+
+ return `${ANSI.bold}${color}${topBorder}${ANSI.reset}\n${color}${paddedContent}${ANSI.reset}\n${color}${ANSI.bold}${bottomBorder}${ANSI.reset}`;
+}
+
+// Helper: format thinking content (shared between formatLogSection and formatLogSectionDetailed)
+function formatThinkingContent(content: string): string {
+ // Apply wrapText for auto line break, then ensure gray color on each line
+ const wrapped = wrapText(content);
+ const lines = wrapped.split('\n');
+ // First line has 🧠 思考: prefix, subsequent lines have indentation
+ const coloredLines = lines.map((line, index) => {
+ if (index === 0) {
+ return `${ANSI.gray}🧠 思考: ${line}${ANSI.reset}`;
+ }
+ return `${ANSI.gray} ${line}${ANSI.reset}`; // 9 spaces indent to align with "🧠 思考: "
+ });
+ return coloredLines.join('\n');
+}
+
+// Helper: format assistant content with proper indentation for multi-line
+function formatAssistantContent(content: string): string {
+ const wrapped = wrapText(content);
+ const lines = wrapped.split('\n');
+ // First line has 💬 prefix, subsequent lines have indentation
+ const formattedLines = lines.map((line, index) => {
+ if (index === 0) {
+ return `${ANSI.brightWhite}💬 ${line}${ANSI.reset}`;
+ }
+ return `${ANSI.brightWhite} ${line}${ANSI.reset}`; // 3 spaces indent to align with 💬
+ });
+ return formattedLines.join('\n');
+}
+
// Format log section for streaming display (compact but differentiated with colors)
function formatLogSection(section: ParsedLogSection): string | null {
switch (section.type) {
case "thinking":
- // Thinking content - display truncated preview with brain icon
- const thinkingPreview = section.content.length > 150
- ? section.content.substring(0, 150) + "..."
- : section.content;
- return `${ANSI.gray}🧠 思考: ${thinkingPreview}${ANSI.reset}`;
+ return formatThinkingContent(section.content);
case "assistant":
- // Assistant output - bright white color, no truncation
- return `${ANSI.brightWhite}💬 ${section.content}${ANSI.reset}`;
+ // Assistant output - bright white color with proper multi-line formatting
+ return formatAssistantContent(section.content);
+
+ case "pipeline":
+ // Pipeline header - show workflow structure in a proper box
+ const stagesDisplay = section.stages?.map((s) => s.display_name).join(" → ") || "";
+ return `\n${createBox(`Pipeline: ${section.pipeline || "unknown"}`, `流程: ${stagesDisplay}`, ANSI.cyan)}\n`;
case "stage":
+ // Get display_name for this stage
+ const stageDisplayName = section.stages?.find((s) => s.slot === section.stage)?.display_name || section.stage || "?";
+
if (section.status) {
- // Stage completion - prominent double-line separator
+ // Stage completion - show progress bar and simple completion line
+ const progressBar = formatStageProgress(section.stages, section.completed_stages);
const icon = section.status === "success" ? "✅" :
section.status === "failed" ? "❌" : "⏸️";
const color = section.status === "success" ? ANSI.green :
section.status === "failed" ? ANSI.red : ANSI.yellow;
const statusText = section.status === "success" ? "完成" :
section.status === "failed" ? "失败" : section.status;
- return `\n${ANSI.bold}${color}╔═════════════════ ${icon} 阶段${statusText}: ${section.stage || "?"} ═════════════════╗${ANSI.reset}\n`;
+ return `\n${progressBar}\n${color}${ANSI.bold}${icon} ${stageDisplayName} ${statusText}${ANSI.reset}\n`;
}
- // Stage start - prominent single-line header
- const stageContent = section.content.length > 100
- ? section.content.substring(0, 100) + "..."
- : section.content;
- return `\n${ANSI.bold}${ANSI.yellow}┌───────────────── 📊 Stage Running: ${section.stage} ─────────────────┐${ANSI.reset}\n${ANSI.yellow}│ ${stageContent}${ANSI.reset}`;
+ // Stage start - show progress bar and current stage indicator
+ const startProgressBar = formatStageProgress(section.stages, section.completed_stages, section.stage);
+ // Skip duplicate content - if content equals display_name, don't show it again
+ const showContent = section.content && section.content !== stageDisplayName;
+ if (showContent) {
+ const stageContent = section.content.length > 80
+ ? section.content.substring(0, 80) + "..."
+ : section.content;
+ return `\n${startProgressBar}\n${ANSI.yellow}${ANSI.bold}▶ 📊 ${stageDisplayName}${ANSI.reset}\n${ANSI.yellow}${stageContent}${ANSI.reset}\n`;
+ }
+ // Only show progress bar and stage name
+ return `\n${startProgressBar}\n${ANSI.yellow}${ANSI.bold}▶ 📊 ${stageDisplayName}${ANSI.reset}\n`;
+
+ case "session_finished":
+ // Session finished - prominent completion banner in a proper box
+ const finishedIcon = section.status === "success" ? "🎉" : "⚠️";
+ const finishedColor = section.status === "success" ? ANSI.green : ANSI.yellow;
+ return `\n${createBox(`${finishedIcon} ${section.content}`, `Pipeline: ${section.pipeline || "unknown"}`, finishedColor)}\n`;
case "status":
- // Status change - blue separator
- return `${ANSI.blue}────────────────── ⏳ ${section.content} ──────────────────${ANSI.reset}`;
+ // Status change - simple indicator
+ return `${ANSI.blue}▶ ${section.content}${ANSI.reset}`;
case "error":
// Error - red color
@@ -719,11 +877,11 @@ function formatLogSection(section: ParsedLogSection): string | null {
// Tool call start - skip, only show result
return null;
} else if (section.tool_success) {
- // Tool success result - green incoming arrow
- return `${ANSI.green} ← ✅ ${section.tool_name || "unknown"}${ANSI.reset}`;
+ // Tool success result - green check
+ return `${ANSI.green} ✓ ${section.tool_name || "unknown"}${ANSI.reset}`;
} else {
- // Tool failure result - red incoming arrow
- return `${ANSI.red} ← ❌ ${section.tool_name || "unknown"}${ANSI.reset}`;
+ // Tool failure result - red cross
+ return `${ANSI.red} ✗ ${section.tool_name || "unknown"}${ANSI.reset}`;
}
case "info":
@@ -734,11 +892,64 @@ function formatLogSection(section: ParsedLogSection): string | null {
}
}
-function parseAndAggregateLogs(logs: Array<LogEntry>): ParsedLogSection[] {
+// Helper: format stage progress bar with visual progress indicator
+function formatStageProgress(
+ stages?: Array<{ slot: string; display_name: string }>,
+ completedStages?: string[],
+ currentStage?: string
+): string {
+ if (!stages || stages.length === 0) return "";
+
+ // Calculate progress
+ const completedCount = completedStages?.length || 0;
+ const total = stages.length;
+ const percent = Math.round((completedCount / total) * 100);
+
+ // Create visual progress bar: ████████░░░░░░░░░░░░ 50%
+ const barLength = 80;
+ const filledLength = Math.round((completedCount / total) * barLength);
+ const bar = `${ANSI.green}${"█".repeat(filledLength)}${ANSI.reset}${ANSI.gray}${"░".repeat(barLength - filledLength)}${ANSI.reset}`;
+
+ // Create stage status line with icons
+ const parts = stages.map((s) => {
+ const isCompleted = completedStages?.includes(s.slot);
+ const isCurrent = currentStage === s.slot;
+
+ if (isCompleted) {
+ return `${ANSI.green}✅ ${s.display_name}${ANSI.reset}`;
+ } else if (isCurrent) {
+ return `${ANSI.yellow}▶ ${s.display_name}${ANSI.reset}`;
+ } else {
+ // 沙漏图标单独使用更暗淡的颜色,名称用普通 gray
+ return `${ANSI.dimGray}⏳${ANSI.reset}${ANSI.gray} ${s.display_name}${ANSI.reset}`;
+ }
+ });
+
+ // Combine: progress bar with percent, then stage names on separate line
+ return `${ANSI.bold}进度: ${ANSI.reset}${bar} ${percent}%\n${ANSI.gray}${parts.join(" → ")}${ANSI.reset}`;
+}
+
+// State for incremental log parsing (to maintain pipeline info across batches)
+interface ParseState {
+ pipelineInfo: { pipeline: string; stages: Array<{ slot: string; display_name: string }> } | null;
+ completedStages: string[];
+ currentThinking: string | null;
+ currentAssistant: string | null;
+ currentStage: string | null;
+}
+
+function parseAndAggregateLogs(
+ logs: Array<LogEntry>,
+ initialState?: ParseState
+): { sections: ParsedLogSection[]; state: ParseState } {
const sections: ParsedLogSection[] = [];
- let currentThinking: string | null = null;
- let currentAssistant: string | null = null;
- let currentStage: string | null = null;
+
+ // Track pipeline progress - use initial state if provided (for incremental parsing)
+ let pipelineInfo = initialState?.pipelineInfo ?? null;
+ const completedStages: string[] = initialState?.completedStages ?? [];
+ let currentThinking = initialState?.currentThinking ?? null;
+ let currentAssistant = initialState?.currentAssistant ?? null;
+ let currentStage = initialState?.currentStage ?? null;
for (const log of logs) {
const eventType = log.event_type || "";
@@ -777,37 +988,38 @@ function parseAndAggregateLogs(logs: Array<LogEntry>): ParsedLogSection[] {
} else {
currentThinking += content;
}
- } else {
- // Regular assistant content
- if (currentAssistant === null) {
- currentAssistant = content;
- } else {
- currentAssistant += content;
- }
}
+ // Don't accumulate assistant content from chat.delta - use chat.final instead
break;
case "chat.final":
- // Final message - finalize assistant content
- if (content) {
- if (currentAssistant !== null) {
- currentAssistant += content;
- } else {
- currentAssistant = content;
- }
- }
+ // Final message - finalize accumulated content (don't append, chat.delta already accumulated)
if (currentThinking !== null) {
sections.push({ type: "thinking", content: currentThinking });
currentThinking = null;
}
- if (currentAssistant !== null) {
- sections.push({ type: "assistant", content: currentAssistant });
- currentAssistant = null;
+ // Use chat.final's content directly (it contains the complete message)
+ if (content) {
+ sections.push({ type: "assistant", content: content });
}
+ currentAssistant = null; // Clear any accumulated chat.delta content (should be empty now)
break;
case "harness.message":
- // Harness stage messages - finalize pending content before stage start
+ // Check if this is pipeline info with stages
+ if (log.stages && log.pipeline) {
+ // Pipeline header - show workflow structure
+ pipelineInfo = { pipeline: log.pipeline, stages: log.stages };
+ sections.push({
+ type: "pipeline",
+ content: log.content || "",
+ pipeline: log.pipeline,
+ stages: log.stages,
+ });
+ break;
+ }
+
+ // Regular stage message - finalize pending content before stage start
const stage = log.stage || "";
if (currentStage !== stage) {
// Stage change - finalize any pending content from previous stage
@@ -821,7 +1033,15 @@ function parseAndAggregateLogs(logs: Array<LogEntry>): ParsedLogSection[] {
}
currentStage = stage;
}
- sections.push({ type: "stage", content: content, stage: stage });
+
+ // Show stage with progress info if we have pipeline info
+ sections.push({
+ type: "stage",
+ content: content,
+ stage: stage,
+ stages: pipelineInfo?.stages,
+ completed_stages: [...completedStages],
+ });
break;
case "harness.stage_result":
@@ -834,14 +1054,44 @@ function parseAndAggregateLogs(logs: Array<LogEntry>): ParsedLogSection[] {
sections.push({ type: "assistant", content: currentAssistant });
currentAssistant = null;
}
+
+ // Track completed stage
+ if (log.stage) {
+ completedStages.push(log.stage);
+ }
+
sections.push({
type: "stage",
content: `阶段完成: ${log.stage || "unknown"}`,
stage: log.stage,
status: log.status,
+ stages: pipelineInfo?.stages,
+ completed_stages: [...completedStages],
+ });
+ break;
+
+ case "harness.session_finished":
+ // Session finished - finalize pending content and show completion
+ if (currentThinking !== null) {
+ sections.push({ type: "thinking", content: currentThinking });
+ currentThinking = null;
+ }
+ if (currentAssistant !== null) {
+ sections.push({ type: "assistant", content: currentAssistant });
+ currentAssistant = null;
+ }
+ sections.push({
+ type: "session_finished",
+ content: log.status === "success" ? "任务执行成功" : `任务执行${log.status || "完成"}`,
+ status: log.status,
+ pipeline: log.pipeline,
});
break;
+ case "context.compressed":
+ // Context compression event
+ break;
+
case "chat.tool_call":
// Extract tool name from nested payload or direct fields
const toolCallPayload = log.tool_call || log;
@@ -876,11 +1126,12 @@ function parseAndAggregateLogs(logs: Array<LogEntry>): ParsedLogSection[] {
sections.push({ type: "assistant", content: currentAssistant });
currentAssistant = null;
}
- sections.push({ type: "error", content: content || "未知错误" });
+ const errorMsg = log.error || content || "未知错误";
+ sections.push({ type: "error", content: errorMsg });
break;
default:
- // Other events
+ // Other events - skip empty content events
if (content) {
sections.push({ type: "info", content: `[${eventType}] ${content.substring(0, 100)}` });
}
@@ -888,47 +1139,70 @@ function parseAndAggregateLogs(logs: Array<LogEntry>): ParsedLogSection[] {
}
}
- // Finalize any remaining pending content
- if (currentThinking !== null) {
- sections.push({ type: "thinking", content: currentThinking });
- }
- if (currentAssistant !== null) {
- sections.push({ type: "assistant", content: currentAssistant });
+ if (!initialState) {
+ if (currentThinking !== null) {
+ sections.push({ type: "thinking", content: currentThinking });
+ currentThinking = null;
+ }
+ if (currentAssistant !== null) {
+ sections.push({ type: "assistant", content: currentAssistant });
+ currentAssistant = null;
+ }
}
- return sections;
+ return { sections, state: { pipelineInfo, completedStages, currentThinking, currentAssistant, currentStage } };
}
// Format log section for history display (detailed with colors)
function formatLogSectionDetailed(section: ParsedLogSection): string | null {
switch (section.type) {
case "thinking":
- return null;
+ return formatThinkingContent(section.content);
case "assistant":
// Assistant output - bright white color
- return `${ANSI.brightWhite}💬 ${section.content}${ANSI.reset}`;
+ return formatAssistantContent(section.content);
+ case "pipeline":
+ // Pipeline header - show workflow structure in a proper box
+ const stagesDisplayDetailed = section.stages?.map((s) => s.display_name).join(" → ") || "";
+ return `\n${createBox(`Pipeline: ${section.pipeline || "unknown"}`, `流程: ${stagesDisplayDetailed}`, ANSI.cyan)}\n`;
case "stage":
+ // Get display_name for this stage
+ const stageDisplayNameDetailed = section.stages?.find((s) => s.slot === section.stage)?.display_name || section.stage || "?";
+
if (section.status) {
- const statusText = section.status === "success" ? "✓ 成功" :
- section.status === "failed" ? "✗ 失败" : section.status;
+ // Stage completion - show progress bar and simple completion line
+ const progressBarDetailed = formatStageProgress(section.stages, section.completed_stages);
const icon = section.status === "success" ? "✅" :
section.status === "failed" ? "❌" : "⏸️";
const color = section.status === "success" ? ANSI.green :
section.status === "failed" ? ANSI.red : ANSI.yellow;
- return `\n${ANSI.bold}${color}╔══ ${icon} Stage Complete: ${section.stage} (${statusText}) ══╗${ANSI.reset}\n`;
+ const statusText = section.status === "success" ? "完成" :
+ section.status === "failed" ? "失败" : section.status;
+ return `\n${progressBarDetailed}\n${color}${ANSI.bold}${icon} ${stageDisplayNameDetailed} ${statusText}${ANSI.reset}\n`;
+ }
+ // Stage start - show progress bar and current stage indicator
+ const startProgressBarDetailed = formatStageProgress(section.stages, section.completed_stages, section.stage);
+ // Skip duplicate content display
+ const showContentDetailed = section.content && section.content !== stageDisplayNameDetailed;
+ if (showContentDetailed) {
+ return `\n${startProgressBarDetailed}\n${ANSI.yellow}${ANSI.bold}▶ 📊 ${stageDisplayNameDetailed}${ANSI.reset}\n${ANSI.yellow}${indentMultiline(section.content, " ", 300)}${ANSI.reset}\n`;
}
- // Stage start - with full content in detailed view
- return `\n${ANSI.bold}${ANSI.yellow}┌───────────────── 📊 Stage Running: ${section.stage} ─────────────────┐${ANSI.reset}\n${ANSI.yellow}│ ${indentMultiline(section.content, "│ ", 300)}${ANSI.reset}\n${ANSI.yellow}└──${ANSI.reset}`;
+ return `\n${startProgressBarDetailed}\n${ANSI.yellow}${ANSI.bold}▶ 📊 ${stageDisplayNameDetailed}${ANSI.reset}\n`;
+ case "session_finished":
+ // Session finished - completion banner in a proper box
+ const finishedIconDetailed = section.status === "success" ? "🎉" : "⚠️";
+ const finishedColorDetailed = section.status === "success" ? ANSI.green : ANSI.yellow;
+ return `\n${createBox(`${finishedIconDetailed} ${section.content}`, `Pipeline: ${section.pipeline || "unknown"}`, finishedColorDetailed)}\n`;
case "status":
- return `${ANSI.blue}⏳ ${section.content}${ANSI.reset}`;
+ return `${ANSI.blue}▶ ${section.content}${ANSI.reset}`;
case "error":
- return `${ANSI.red}❌ 错误: ${section.content}${ANSI.reset}`;
+ return `${ANSI.red}🔥 错误: ${section.content}${ANSI.reset}`;
case "tool":
// Only show tool results, skip call starts to reduce noise
if (section.tool_success === undefined) {
return null;
} else if (section.tool_success) {
- return `${ANSI.green} ← ✅ ${section.tool_name || "unknown"}${ANSI.reset}`;
+ return `${ANSI.green} ✓ ${section.tool_name || "unknown"}${ANSI.reset}`;
} else {
return `${ANSI.red} ← ❌ ${section.tool_name || "unknown"}${ANSI.reset}`;
}
diff --git a/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts b/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts
index 12feb3b36d..fa71181c6c 100644
--- a/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts
@@ -87,6 +87,8 @@ export interface CommandContext {
) => void;
enterStatusView?: (tab?: StatusViewTab) => void;
openInEditor?: (filePath: string) => void;
+ /** Enter FileViewer mode to view large content (e.g., formatted logs) */
+ enterFileViewer?: (content: string, title: string, source: string) => void;
restartStatusLine?: () => void;
}
diff --git a/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
index 36c7ce2a59..8a048e8db6 100644
--- a/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/ui/app-screen.ts
@@ -10,6 +10,7 @@ import {
type SlashCommand as TuiSlashCommand,
TUI,
matchesKey,
+ truncateToWidth,
} from "@mariozechner/pi-tui";
import { spawnSync } from "node:child_process";
import { statSync } from "node:fs";
@@ -152,6 +153,16 @@ type StatusViewState = {
configPayload: (Record<string, unknown> & { schema?: ConfigItemSchema[] }) | null;
};
+// FileViewer state for viewing large content (e.g., formatted logs)
+type FileViewerState = {
+ content: string; // Full content text
+ title: string; // Title for header
+ source: string; // Source info
+ scrollOffset: number; // Current scroll position
+ searchMode: boolean; // Whether in search mode
+ searchTerm: string; // Search term
+};
+
class ComposerAutocompleteProvider implements AutocompleteProvider {
constructor(private readonly inner: AutocompleteProvider) {}
@@ -477,6 +488,8 @@ export class AppScreen implements Component, Focusable {
private transcriptScrollOffset = 0;
/** Image attachments keyed by composer `@path` tokens (e.g. cached base64 for terminal preview). */
private composerAttachments: FileAttachment[] = [];
+ /** FileViewer state for viewing large content (e.g., formatted logs) */
+ private fileViewerState: FileViewerState | null = null;
constructor(
private readonly tui: TUI,
@@ -574,6 +587,124 @@ export class AppScreen implements Component, Focusable {
this.editor.invalidate();
}
+ /** Enter FileViewer mode to view large content (e.g., formatted logs) */
+ enterFileViewer(content: string, title: string, source: string): void {
+ this.fileViewerState = {
+ content,
+ title,
+ source,
+ scrollOffset: 0,
+ searchMode: false,
+ searchTerm: "",
+ };
+ this.tui.requestRender();
+ }
+
+ /** Exit FileViewer mode and return to normal view */
+ exitFileViewer(): void {
+ this.fileViewerState = null;
+ this.tui.requestRender();
+ }
+
+ /** Handle FileViewer input - scrolling and navigation */
+ private handleFileViewerInput(data: string): void {
+ if (!this.fileViewerState) return;
+
+ const contentLines = this.fileViewerState.content.split("\n");
+ const height = this.tui.terminal.rows;
+ const availableHeight = Math.max(1, height - 2); // Reserve for title + hint
+
+ // Esc or q to exit
+ if (matchesKey(data, "escape") || data.toLowerCase() === "q") {
+ this.exitFileViewer();
+ return;
+ }
+
+ // Scroll up (up arrow or k)
+ if (matchesKey(data, "up") || data.toLowerCase() === "k") {
+ this.fileViewerState.scrollOffset = Math.max(0, this.fileViewerState.scrollOffset - 1);
+ this.tui.requestRender();
+ return;
+ }
+
+ // Scroll down (down arrow or j)
+ if (matchesKey(data, "down") || data.toLowerCase() === "j") {
+ const maxScroll = Math.max(0, contentLines.length - availableHeight);
+ this.fileViewerState.scrollOffset = Math.min(maxScroll, this.fileViewerState.scrollOffset + 1);
+ this.tui.requestRender();
+ return;
+ }
+
+ // Page up
+ if (matchesKey(data, "pageUp")) {
+ this.fileViewerState.scrollOffset = Math.max(0, this.fileViewerState.scrollOffset - availableHeight);
+ this.tui.requestRender();
+ return;
+ }
+
+ // Page down
+ if (matchesKey(data, "pageDown")) {
+ const maxScroll = Math.max(0, contentLines.length - availableHeight);
+ this.fileViewerState.scrollOffset = Math.min(maxScroll, this.fileViewerState.scrollOffset + availableHeight);
+ this.tui.requestRender();
+ return;
+ }
+
+ // Go to top (Home)
+ if (matchesKey(data, "home") || data.toLowerCase() === "g") {
+ this.fileViewerState.scrollOffset = 0;
+ this.tui.requestRender();
+ return;
+ }
+
+ // Go to bottom (End)
+ if (matchesKey(data, "end") || data.toLowerCase() === "shift+g") {
+ const maxScroll = Math.max(0, contentLines.length - availableHeight);
+ this.fileViewerState.scrollOffset = maxScroll;
+ this.tui.requestRender();
+ return;
+ }
+ }
+
+ /** Render FileViewer mode - show content in a scrollable viewer */
+ private renderFileViewer(width: number): string[] {
+ if (!this.fileViewerState) return [];
+
+ const height = Math.max(3, this.tui.terminal.rows);
+ const safeWidth = Math.max(1, width);
+ const lines: string[] = [];
+
+ // Title bar (line 1)
+ const titleText = `━━━ ${this.fileViewerState.title} ━━━`;
+ lines.push(padToWidth(palette.border.panel(titleText), safeWidth));
+
+ // Content area
+ const contentLines = this.fileViewerState.content.split("\n");
+ const availableHeight = Math.max(1, height - 2);
+ const scrollOffset = this.fileViewerState.scrollOffset;
+
+ // Add visible content lines
+ for (let i = 0; i < availableHeight; i++) {
+ const lineIndex = scrollOffset + i;
+ if (lineIndex < contentLines.length) {
+ const rawLine = contentLines[lineIndex] || "";
+ lines.push(truncateToWidth(rawLine, safeWidth, ""));
+ } else {
+ // Pad with empty lines
+ lines.push(" ".repeat(safeWidth));
+ }
+ }
+
+ // Hint bar (last line) - show scroll position
+ const totalLines = contentLines.length;
+ const scrollPercent = totalLines > 0 ? Math.round((scrollOffset / totalLines) * 100) : 0;
+ const positionInfo = totalLines > availableHeight ? ` [${scrollOffset + 1}-${Math.min(scrollOffset + availableHeight, totalLines)}/${totalLines} (${scrollPercent}%)]` : "";
+ const hintText = `按 Esc/q 退出 | ↑↓ 滚动 | PgUp/PgDown 翻页${positionInfo}`;
+ lines.push(padToWidth(palette.text.dim(hintText), safeWidth));
+
+ return lines;
+ }
+
/**
* Ctrl+C / SIGINT 始终尝试向服务端发送当前 session 的中断请求。
* 是否真的存在运行任务由服务端判断;CLI/TUI 本身不退出。
@@ -585,6 +716,12 @@ export class AppScreen implements Component, Focusable {
}
handleInput(data: string): void {
+ // FileViewer mode: handle input separately
+ if (this.fileViewerState) {
+ this.handleFileViewerInput(data);
+ return;
+ }
+
const snapshot = this.state.getSnapshot();
const pendingQuestion = snapshot.pendingQuestion;
const activeQuestion =
@@ -912,6 +1049,11 @@ export class AppScreen implements Component, Focusable {
}
render(width: number): string[] {
+ // FileViewer mode: render file viewer instead of normal view
+ if (this.fileViewerState) {
+ return this.renderFileViewer(width);
+ }
+
const snapshot = this.state.getSnapshot();
const teamWorking =
isTeamMode(snapshot.mode) &&
@@ -1080,6 +1222,9 @@ export class AppScreen implements Component, Focusable {
openInEditor: (filePath: string) => {
openInExternalEditor(this.tui, filePath);
},
+ enterFileViewer: (content, title, source) => {
+ this.enterFileViewer(content, title, source);
+ },
});
} finally {
this.clearPendingSubmittedInput();
diff --git a/jiuwenclaw/channels/tui/frontend/src/ui/components/todo-list.ts b/jiuwenclaw/channels/tui/frontend/src/ui/components/todo-list.ts
index bf74b777d2..1d444f83d2 100644
--- a/jiuwenclaw/channels/tui/frontend/src/ui/components/todo-list.ts
+++ b/jiuwenclaw/channels/tui/frontend/src/ui/components/todo-list.ts
@@ -37,6 +37,10 @@ export function renderTodoList(
collapsed: boolean = false,
animationPhase: number = 0
): string[] {
+ if (todos.length === 0) {
+ return [];
+ }
+
const pendingCount = todos.filter((t) => t.status === "pending").length;
const inProgressCount = todos.filter((t) => t.status === "in_progress").length;
const completedCount = todos.filter((t) => t.status === "completed").length;
diff --git a/jiuwenclaw/gateway/channel_manager/tui/tui_connect.py b/jiuwenclaw/gateway/channel_manager/tui/tui_connect.py
index d77a740c9c..d1d0e26bdf 100644
--- a/jiuwenclaw/gateway/channel_manager/tui/tui_connect.py
+++ b/jiuwenclaw/gateway/channel_manager/tui/tui_connect.py
@@ -6,6 +6,7 @@ import inspect
import logging
import os
import shutil
+import sys
import time
from dataclasses import dataclass
from typing import Any
@@ -42,17 +43,52 @@ logger = logging.getLogger(__name__)
# Auto-Harness config file path
_AUTO_HARNESS_CONFIG_DIR = get_user_workspace_dir() / "auto-harness"
_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"
def _get_auto_harness_config() -> dict[str, Any]:
- """Load auto-harness config.yaml."""
- if not _AUTO_HARNESS_CONFIG_FILE.exists():
- return {}
- try:
- return yaml.safe_load(_AUTO_HARNESS_CONFIG_FILE.read_text(encoding="utf-8")) or {}
- except Exception as e:
- logger.warning("[auto-harness config] Failed to load: %s", e)
- return {}
+ """Load auto-harness config.yaml with auto-fill for ci_gate defaults."""
+ config: dict[str, Any] = {}
+
+ if _AUTO_HARNESS_CONFIG_FILE.exists():
+ try:
+ config = yaml.safe_load(_AUTO_HARNESS_CONFIG_FILE.read_text(encoding="utf-8")) or {}
+ except Exception as e:
+ logger.warning("[auto-harness config] Failed to load: %s", e)
+ config = {}
+
+ # Auto-fill ci_gate defaults if missing
+ ci_gate = config.get("ci_gate") or {}
+ needs_save = False
+
+ # Ensure local_repo is a string (not Path object which causes YAML serialization issues)
+ local_repo = config.get("local_repo")
+ if not local_repo:
+ config["local_repo"] = str(_AUTO_HARNESS_LOCAL_REPO)
+ needs_save = True
+ elif hasattr(local_repo, "__fspath__"): # Path-like object
+ config["local_repo"] = str(local_repo)
+ needs_save = True
+
+ if not ci_gate.get("python_executable"):
+ ci_gate["python_executable"] = _DEFAULT_CI_GATE_PYTHON_EXECUTABLE
+ needs_save = True
+
+ if not ci_gate.get("install_command"):
+ ci_gate["install_command"] = _DEFAULT_CI_GATE_INSTALL_COMMAND
+ needs_save = True
+
+ if needs_save:
+ config["ci_gate"] = ci_gate
+ _save_auto_harness_config(config)
+ logger.info("[auto-harness config] Auto-filled ci_gate defaults: python_executable=%s, install_command=%s",
+ ci_gate.get("python_executable"), ci_gate.get("install_command"))
+
+ return config
def _save_auto_harness_config(config: dict[str, Any]) -> None: