Merge pull request #622 from pikasTech/fix/job-status-text-progress-20260621

修复 job status 识别文本 progress
This commit is contained in:
Lyon
2026-06-22 02:29:14 +08:00
committed by GitHub
+41 -4
View File
@@ -553,13 +553,11 @@ const agentRunYamlLaneProgressEvents = [
] as const;
function hasAgentRunYamlLaneProgressEvents(text: string): boolean {
return agentRunYamlLaneProgressEvents.some(({ event }) => parseJsonLineEvents(text, event).length > 0);
return parseAgentRunYamlLaneProgressEvents(text).length > 0;
}
function summarizeAgentRunYamlLaneTriggerJobProgress(job: JobRecord, stdoutTail: string, stderrTail: string, nowMs = Date.now()): JobProgressSummary {
const events = agentRunYamlLaneProgressEvents
.flatMap(({ event, stage }) => parseJsonLineEvents(stderrTail, event).map((item) => ({ ...item, stage })))
.sort((left, right) => String(left.at ?? "").localeCompare(String(right.at ?? "")));
const events = parseAgentRunYamlLaneProgressEvents(stderrTail);
const lastEvent = events.at(-1) ?? {};
const stage = stringField(lastEvent.stage);
const stageStatus = agentRunYamlLaneStageStatus(lastEvent);
@@ -629,6 +627,45 @@ function summarizeAgentRunYamlLaneTriggerJobProgress(job: JobRecord, stdoutTail:
};
}
function parseAgentRunYamlLaneProgressEvents(text: string): Record<string, unknown>[] {
const eventToStage = new Map(agentRunYamlLaneProgressEvents.map((item) => [item.event, item.stage]));
const events: Record<string, unknown>[] = [];
const lines = text.split(/\r?\n/u);
for (let index = 0; index < lines.length; index += 1) {
const line = lines[index]?.trim() ?? "";
if (line.length === 0) continue;
if (line.startsWith("{")) {
try {
const parsed = JSON.parse(line) as unknown;
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
const record = parsed as Record<string, unknown>;
const event = typeof record.event === "string" ? record.event : null;
const stage = event === null ? null : eventToStage.get(event) ?? null;
if (event !== null && stage !== null) events.push({ ...record, stage, __order: index });
}
} catch {
// Ignore non-JSON progress noise; raw tails remain visible.
}
continue;
}
const match = line.match(/^status\s+(agentrun\.yaml-lane\.[a-z-]+\.progress)\s+([a-z-]+)(?:\s+(.*))?$/u);
if (!match) continue;
const event = match[1]!;
const stage = eventToStage.get(event);
if (stage === undefined) continue;
const payload: Record<string, unknown> = { event, stage, status: match[2]!, __order: index };
for (const token of (match[3] ?? "").split(/\s+/u).filter(Boolean)) {
const tokenMatch = token.match(/^([A-Za-z][A-Za-z0-9_]*)=(.+)$/u);
if (!tokenMatch) continue;
const key = tokenMatch[1]!;
const value = tokenMatch[2]!;
payload[key] = /^-?\d+$/u.test(value) ? Number(value) : value;
}
events.push(payload);
}
return events.sort((left, right) => Number(left.__order ?? 0) - Number(right.__order ?? 0));
}
function agentRunYamlLaneStageStatus(event: Record<string, unknown>): string | null {
const explicitStatus = stringField(event.status);
if (explicitStatus !== null) return explicitStatus;