fix: parse paired status from leading lines
This commit is contained in:
@@ -14,22 +14,56 @@ export type ArbiterVerdictResult =
|
||||
| 'escalate'
|
||||
| 'unknown';
|
||||
|
||||
const VISIBLE_VERDICT_SCAN_LINE_LIMIT = 5;
|
||||
|
||||
function leadingVisibleLines(text: string, limit: number): string[] {
|
||||
const lines: string[] = [];
|
||||
let inFence = false;
|
||||
|
||||
for (const rawLine of text.split('\n')) {
|
||||
const line = rawLine.trim();
|
||||
if (/^(```|~~~)/.test(line)) {
|
||||
inFence = !inFence;
|
||||
continue;
|
||||
}
|
||||
if (inFence || line.length === 0) {
|
||||
continue;
|
||||
}
|
||||
lines.push(line);
|
||||
if (lines.length >= limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
function parseVisibleVerdictLine(line: string): VisibleVerdict | null {
|
||||
if (/^\*{0,2}BLOCKED(?:\*{0,2})?\b/i.test(line)) return 'blocked';
|
||||
if (/^\*{0,2}NEEDS_CONTEXT(?:\*{0,2})?\b/i.test(line)) return 'needs_context';
|
||||
if (/^\*{0,2}STEP_DONE(?:\*{0,2})?\b/i.test(line)) return 'step_done';
|
||||
if (/^\*{0,2}TASK_DONE(?:\*{0,2})?\b/i.test(line)) return 'task_done';
|
||||
if (/^\*{0,2}DONE_WITH_CONCERNS(?:\*{0,2})?\b/i.test(line))
|
||||
return 'done_with_concerns';
|
||||
if (/^\*{0,2}DONE(?:\*{0,2})?\b/i.test(line)) return 'done';
|
||||
if (/^\*{0,2}Approved\.?(?:\*{0,2})?/i.test(line)) return 'done';
|
||||
if (/^\*{0,2}LGTM(?:\*{0,2})?/i.test(line)) return 'done';
|
||||
return null;
|
||||
}
|
||||
|
||||
export function parseVisibleVerdict(
|
||||
summary: string | null | undefined,
|
||||
): VisibleVerdict {
|
||||
if (!summary) return 'continue';
|
||||
const cleaned = summary.replace(/<internal>[\s\S]*?<\/internal>/g, '').trim();
|
||||
if (!cleaned) return 'continue';
|
||||
const firstLine = cleaned.split('\n')[0].trim();
|
||||
if (/^\*{0,2}BLOCKED\*{0,2}\b/i.test(firstLine)) return 'blocked';
|
||||
if (/^\*{0,2}NEEDS_CONTEXT\*{0,2}\b/i.test(firstLine)) return 'needs_context';
|
||||
if (/^\*{0,2}STEP_DONE\*{0,2}\b/i.test(firstLine)) return 'step_done';
|
||||
if (/^\*{0,2}TASK_DONE\*{0,2}\b/i.test(firstLine)) return 'task_done';
|
||||
if (/^\*{0,2}DONE_WITH_CONCERNS\*{0,2}\b/i.test(firstLine))
|
||||
return 'done_with_concerns';
|
||||
if (/^\*{0,2}DONE\*{0,2}\b/i.test(firstLine)) return 'done';
|
||||
if (/^\*{0,2}Approved\.?\*{0,2}/i.test(firstLine)) return 'done';
|
||||
if (/^\*{0,2}LGTM\*{0,2}/i.test(firstLine)) return 'done';
|
||||
for (const line of leadingVisibleLines(
|
||||
cleaned,
|
||||
VISIBLE_VERDICT_SCAN_LINE_LIMIT,
|
||||
)) {
|
||||
const verdict = parseVisibleVerdictLine(line);
|
||||
if (verdict) return verdict;
|
||||
}
|
||||
return 'continue';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user