fix: surface AgentRun resource failures in human output
This commit is contained in:
+89
-4
@@ -622,7 +622,10 @@ function renderResultSummary(command: string, raw: Record<string, unknown>, opti
|
||||
];
|
||||
const final = stringOrNull(data.finalResponse) ?? stringOrNull(data.output) ?? stringOrNull(data.summary) ?? stringOrNull(data.result);
|
||||
if (final !== null) lines.push("", truncateMultiline(final, options.fullText ? 8000 : 1600));
|
||||
else lines.push("", JSON.stringify(pickCompact(data, ["failureKind", "terminalClassification", "degradedReason", "message", "valuesPrinted"]), null, 2));
|
||||
else {
|
||||
const failure = renderFailureLines(data);
|
||||
lines.push("", ...(failure.length > 0 ? failure : ["No final response is available yet."]));
|
||||
}
|
||||
return renderedCliResult(raw.ok !== false, command, lines.join("\n"));
|
||||
}
|
||||
|
||||
@@ -921,13 +924,95 @@ function renderGenericDescription(ref: AgentRunResourceRef, data: unknown): stri
|
||||
const lines = [
|
||||
`Name: ${ref.kind}/${ref.name}`,
|
||||
`State: ${displayValue(value.state ?? value.status ?? value.phase ?? "-")}`,
|
||||
"",
|
||||
"Summary:",
|
||||
JSON.stringify(pickCompact(value, ["id", "name", "runId", "commandId", "runnerJobId", "sessionId", "state", "status", "phase", "reason", "failureKind", "terminalClassification", "valuesPrinted"]), null, 2),
|
||||
];
|
||||
const identity = renderResourceIdentityLines(ref, value);
|
||||
if (identity.length > 0) lines.push("", ...identity);
|
||||
const failure = renderFailureLines(value);
|
||||
if (failure.length > 0) lines.push("", ...failure);
|
||||
const next = renderResourceNextLines(ref, value);
|
||||
if (next.length > 0) lines.push("", "Next:", ...next.map((line) => ` ${line}`));
|
||||
if (identity.length === 0 && failure.length === 0 && next.length === 0) {
|
||||
lines.push(
|
||||
"",
|
||||
"Summary:",
|
||||
JSON.stringify(pickCompact(value, ["id", "name", "runId", "commandId", "runnerJobId", "sessionId", "state", "status", "phase", "reason", "failureKind", "valuesPrinted"]), null, 2),
|
||||
);
|
||||
}
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function renderResourceIdentityLines(ref: AgentRunResourceRef, value: Record<string, unknown>): string[] {
|
||||
const fields: [string, unknown][] = [
|
||||
["Run", value.runId],
|
||||
["Command", value.commandId],
|
||||
["RunnerJob", value.runnerJobId ?? (ref.kind === "runnerjob" ? value.id : null)],
|
||||
["Session", value.sessionId],
|
||||
["Namespace", value.namespace],
|
||||
["Job", value.jobName],
|
||||
["Image", value.image],
|
||||
["LogPath", value.logPath],
|
||||
["Started", value.startedAt],
|
||||
["Finished", value.finishedAt],
|
||||
];
|
||||
if (ref.kind !== "runnerjob") {
|
||||
return fields
|
||||
.filter(([label]) => label === "Run" || label === "Command" || label === "RunnerJob" || label === "Session")
|
||||
.map(([label, item]) => formatResourceField(label, item))
|
||||
.filter((line): line is string => line !== null);
|
||||
}
|
||||
return fields.map(([label, item]) => formatResourceField(label, item)).filter((line): line is string => line !== null);
|
||||
}
|
||||
|
||||
function formatResourceField(label: string, value: unknown): string | null {
|
||||
const text = stringOrNull(value);
|
||||
if (text === null || text.length === 0) return null;
|
||||
return `${label}: ${text}`;
|
||||
}
|
||||
|
||||
function renderFailureLines(value: Record<string, unknown>): string[] {
|
||||
const terminalClassification = record(value.terminalClassification);
|
||||
const failureKind = stringOrNull(value.failureKind)
|
||||
?? stringOrNull(terminalClassification.failureKind)
|
||||
?? stringOrNull(value.degradedReason);
|
||||
const failureMessage = stringOrNull(value.failureMessage)
|
||||
?? stringOrNull(terminalClassification.failureMessage)
|
||||
?? stringOrNull(value.message)
|
||||
?? stringOrNull(value.reason);
|
||||
const category = stringOrNull(terminalClassification.category);
|
||||
const timeoutKind = stringOrNull(terminalClassification.timeoutKind);
|
||||
const timeoutState = stringOrNull(terminalClassification.timeoutState);
|
||||
const providerInterruption = stringOrNull(terminalClassification.providerInterruption);
|
||||
const lastActivity = stringOrNull(terminalClassification.lastActivityKind);
|
||||
const lastActivitySeq = terminalClassification.lastActivitySeq;
|
||||
const lines: string[] = [];
|
||||
if (failureKind !== null) lines.push(`Failure: ${failureKind}`);
|
||||
if (failureMessage !== null) lines.push(`Message: ${failureMessage}`);
|
||||
if (category !== null) lines.push(`Category: ${category}`);
|
||||
if (timeoutKind !== null || timeoutState !== null) lines.push(`Timeout: ${displayValue(timeoutKind)} / ${displayValue(timeoutState)}`);
|
||||
if (providerInterruption !== null) lines.push(`Provider: ${providerInterruption}`);
|
||||
if (lastActivity !== null) lines.push(`LastActivity: ${lastActivity}${lastActivitySeq === undefined ? "" : ` seq=${String(lastActivitySeq)}`}`);
|
||||
return lines;
|
||||
}
|
||||
|
||||
function renderResourceNextLines(ref: AgentRunResourceRef, value: Record<string, unknown>): string[] {
|
||||
const runId = stringOrNull(value.runId);
|
||||
const commandId = stringOrNull(value.commandId);
|
||||
const runnerJobId = stringOrNull(value.runnerJobId) ?? (ref.kind === "runnerjob" ? ref.name : null);
|
||||
const sessionId = stringOrNull(value.sessionId);
|
||||
const lines = [
|
||||
runId === null ? null : `bun scripts/cli.ts agentrun events run/${runId} --after-seq 0 --limit 100`,
|
||||
sessionId === null ? null : `bun scripts/cli.ts agentrun logs session/${sessionId} --tail 100`,
|
||||
runId === null || commandId === null ? null : `bun scripts/cli.ts agentrun result run/${runId} --command ${commandId}`,
|
||||
runId === null || commandId === null ? null : `bun scripts/cli.ts agentrun describe command/${commandId} --run ${runId} --full`,
|
||||
runId === null || runnerJobId === null ? null : `bun scripts/cli.ts agentrun describe runnerjob/${runnerJobId} --run ${runId} --full`,
|
||||
];
|
||||
const unique: string[] = [];
|
||||
for (const line of lines) {
|
||||
if (line !== null && !unique.includes(line)) unique.push(line);
|
||||
}
|
||||
return unique.slice(0, 5);
|
||||
}
|
||||
|
||||
function parseTaskManifest(raw: string, source: string): Record<string, unknown> {
|
||||
const parsed = source.endsWith(".json") ? JSON.parse(raw) as unknown : Bun.YAML.parse(raw) as unknown;
|
||||
const input = record(parsed);
|
||||
|
||||
Reference in New Issue
Block a user