π OpenHands: AI-Driven Development
fix: single-line agent-server logs in dev:automation mode (#1178)
Tim O'Farrell80e01e099def
diff --git a/scripts/dev-with-automation.mjs b/scripts/dev-with-automation.mjsindex 1e712625b0..6393fe539c 100644--- a/scripts/dev-with-automation.mjs+++ b/scripts/dev-with-automation.mjs@@ -119,6 +119,38 @@ function logError(message) {console.error(`${c.red}β${c.reset} ${message}`);}+/**+ * Parse one JSON log line produced by the SDK's JsonFormatter and return a+ * single-line human-readable string + an appropriate ANSI color.+ *+ * Returns null for non-JSON lines so callers can fall back to the raw text.+ *+ * @param {string} rawLine+ * @returns {{ text: string; color: string } | null}+ */+function parseAgentServerLogLine(rawLine) {+ try {+ const obj = JSON.parse(rawLine);+ if (!obj.levelname || obj.message === undefined) return null;+ const level = obj.levelname.padEnd(8);+ const location =+ obj.filename && obj.lineno ? ` ${obj.filename}:${obj.lineno}` : "";+ const text = `${level} ${obj.message}${location}`;+ const lvl = obj.levelname;+ const color =+ lvl === "DEBUG"+ ? c.dim+ : lvl === "WARNING"+ ? c.yellow+ : lvl === "ERROR" || lvl === "CRITICAL"+ ? c.red+ : c.blue;+ return { text, color };+ } catch {+ return null;+ }+}+// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// Configuration// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ@@ -521,6 +553,7 @@ function spawnService(name, command, args, options = {}) {);const color = options.color || c.reset;+ const parseLogLine = options.parseLogLine;proc.stdout.on("data", (data) => {data@@ -528,7 +561,8 @@ function spawnService(name, command, args, options = {}) {.split("\n").filter(Boolean).forEach((line) => {- logService(name, line.trim(), color);+ const parsed = parseLogLine ? parseLogLine(line.trim()) : null;+ logService(name, parsed ? parsed.text : line.trim(), parsed ? parsed.color : color);});});@@ -538,7 +572,8 @@ function spawnService(name, command, args, options = {}) {.split("\n").filter(Boolean).forEach((line) => {- logService(name, line.trim(), c.yellow);+ const parsed = parseLogLine ? parseLogLine(line.trim()) : null;+ logService(name, parsed ? parsed.text : line.trim(), parsed ? parsed.color : c.yellow);});});@@ -699,6 +734,11 @@ function startAgentServer(config) {// Ensure the agent-server uses the resolved key from config. This is// LOCAL_BACKEND_API_KEY when set, or the auto-generated persisted key.OH_SESSION_API_KEYS_0: config.sessionApiKey,+ // Emit structured JSON log lines instead of Rich-formatted output.+ // Rich wraps long messages across multiple lines and prepends its own+ // timestamp; LOG_JSON=true produces one JSON object per record which+ // parseAgentServerLogLine re-formats into a clean single-line entry.+ LOG_JSON: "true",};spawnService(@@ -715,6 +755,7 @@ function startAgentServer(config) {cwd: safeConfig.workspacesPath,env: agentServerEnv,color: c.blue,+ parseLogLine: parseAgentServerLogLine,},);}