fix(cicd): keep branch follower debug JSON parseable

This commit is contained in:
Codex
2026-07-04 03:54:57 +00:00
parent a65804b609
commit bd10aae68e
2 changed files with 61 additions and 12 deletions
+31 -8
View File
@@ -2862,16 +2862,39 @@ function parseJsonObject(text: string): Record<string, unknown> | null {
const parsed = JSON.parse(trimmed) as unknown;
return asOptionalRecord(parsed);
} catch {
const start = trimmed.indexOf("{");
const end = trimmed.lastIndexOf("}");
if (start < 0 || end <= start) return null;
try {
const parsed = JSON.parse(trimmed.slice(start, end + 1)) as unknown;
return asOptionalRecord(parsed);
} catch {
return null;
return parseFirstJsonObject(trimmed);
}
}
function parseFirstJsonObject(text: string): Record<string, unknown> | null {
const start = text.indexOf("{");
if (start < 0) return null;
let depth = 0;
let inString = false;
let escaped = false;
for (let index = start; index < text.length; index += 1) {
const char = text[index];
if (inString) {
if (escaped) escaped = false;
else if (char === "\\") escaped = true;
else if (char === "\"") inString = false;
continue;
}
if (char === "\"") inString = true;
else if (char === "{") depth += 1;
else if (char === "}") {
depth -= 1;
if (depth === 0) {
try {
const parsed = JSON.parse(text.slice(start, index + 1)) as unknown;
return asOptionalRecord(parsed);
} catch {
return null;
}
}
}
}
return null;
}
function recordAt(root: Record<string, unknown>, path: string[]): Record<string, unknown> | null {