From a90fe1b245c181b5fc84f402d78e91538421cc26 Mon Sep 17 00:00:00 2001 From: Pham Nam Date: Wed, 21 Jan 2026 19:48:21 +0700 Subject: [PATCH] Refs #1378: scaffold zalouser extension --- extensions/zalouser/src/zca.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/extensions/zalouser/src/zca.ts b/extensions/zalouser/src/zca.ts index 83849835f..427e20024 100644 --- a/extensions/zalouser/src/zca.ts +++ b/extensions/zalouser/src/zca.ts @@ -114,11 +114,36 @@ export function runZcaInteractive( }); } +function stripAnsi(str: string): string { + return str.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, ""); +} + export function parseJsonOutput(stdout: string): T | null { try { return JSON.parse(stdout) as T; } catch { - return null; + const cleaned = stripAnsi(stdout); + + try { + return JSON.parse(cleaned) as T; + } catch { + // zca may prefix output with INFO/log lines, try to find JSON + const lines = cleaned.split("\n"); + + for (let i = 0; i < lines.length; i++) { + const line = lines[i].trim(); + if (line.startsWith("{") || line.startsWith("[")) { + // Try parsing from this line to the end + const jsonCandidate = lines.slice(i).join("\n").trim(); + try { + return JSON.parse(jsonCandidate) as T; + } catch { + continue; + } + } + } + return null; + } } }