fix: render agentrun session supervisor facts
This commit is contained in:
+68
-16
@@ -689,14 +689,21 @@ function renderResultSummary(command: string, raw: Record<string, unknown>, opti
|
||||
if (options.raw) return renderMachine(command, raw, "json", raw.ok !== false);
|
||||
const data = record(innerData(raw));
|
||||
if (options.output === "json" || options.output === "yaml") return renderMachine(command, { kind: "Result", ref, result: data }, options.output, raw.ok !== false);
|
||||
const executionOk = typeof data.executionOk === "boolean"
|
||||
? data.executionOk
|
||||
: typeof data.ok === "boolean"
|
||||
? data.ok
|
||||
: raw.ok !== false;
|
||||
const lines = [
|
||||
`Result: ${ref.kind}/${shortId(ref.name)}`,
|
||||
`State: ${displayValue(data.state ?? data.status ?? data.terminalStatus ?? "-")}`,
|
||||
`OK: ${String(raw.ok !== false)}`,
|
||||
`OK: ${String(executionOk)}`,
|
||||
];
|
||||
const providerTerminalFailure = typeof data.providerTerminalFailure === "boolean" ? data.providerTerminalFailure : null;
|
||||
const authority = stringOrNull(data.finalResponseAuthority);
|
||||
const fallback = typeof data.finalResponseFallback === "boolean" ? data.finalResponseFallback : null;
|
||||
const needsContinuation = typeof data.needsContinuation === "boolean" ? data.needsContinuation : null;
|
||||
if (providerTerminalFailure !== null) lines.push(`ProviderTerminalFailure: ${String(providerTerminalFailure)}`);
|
||||
if (authority !== null) lines.push(`Authority: ${authority}`);
|
||||
if (fallback !== null) lines.push(`Fallback: ${String(fallback)}`);
|
||||
if (needsContinuation !== null) lines.push(`NeedsContinuation: ${String(needsContinuation)}`);
|
||||
@@ -1357,10 +1364,12 @@ function renderGenericDescription(ref: AgentRunResourceRef, data: unknown): stri
|
||||
const value = record(data);
|
||||
const lines = [
|
||||
`Name: ${ref.kind}/${ref.name}`,
|
||||
`State: ${displayValue(value.state ?? value.status ?? value.phase ?? "-")}`,
|
||||
`State: ${displayValue(value.state ?? value.status ?? value.phase ?? value.executionState ?? value.terminalStatus ?? "-")}`,
|
||||
];
|
||||
const identity = renderResourceIdentityLines(ref, value);
|
||||
if (identity.length > 0) lines.push("", ...identity);
|
||||
const supervisor = renderSupervisorLines(ref, value);
|
||||
if (supervisor.length > 0) lines.push("", "Supervisor:", ...supervisor.map((line) => ` ${line}`));
|
||||
const failure = renderFailureLines(value);
|
||||
if (failure.length > 0) lines.push("", ...failure);
|
||||
const next = renderResourceNextLines(ref, value);
|
||||
@@ -1376,11 +1385,12 @@ function renderGenericDescription(ref: AgentRunResourceRef, data: unknown): stri
|
||||
}
|
||||
|
||||
function renderResourceIdentityLines(ref: AgentRunResourceRef, value: Record<string, unknown>): string[] {
|
||||
const supervisor = record(value.supervisor);
|
||||
const fields: [string, unknown][] = [
|
||||
["Run", value.runId],
|
||||
["Command", value.commandId],
|
||||
["Run", firstKnownString(value.runId, value.activeRunId, value.lastRunId, supervisor.runId, supervisor.activeRunId, supervisor.lastRunId)],
|
||||
["Command", firstKnownString(value.commandId, value.activeCommandId, value.lastCommandId, supervisor.commandId, supervisor.activeCommandId, supervisor.lastCommandId)],
|
||||
["RunnerJob", value.runnerJobId ?? (ref.kind === "runnerjob" ? value.id : null)],
|
||||
["Session", value.sessionId],
|
||||
["Session", firstKnownString(value.sessionId, supervisor.sessionId)],
|
||||
["Namespace", value.namespace],
|
||||
["Job", value.jobName],
|
||||
["Image", value.image],
|
||||
@@ -1397,27 +1407,67 @@ function renderResourceIdentityLines(ref: AgentRunResourceRef, value: Record<str
|
||||
return fields.map(([label, item]) => formatResourceField(label, item)).filter((line): line is string => line !== null);
|
||||
}
|
||||
|
||||
function firstKnownString(...values: unknown[]): string | null {
|
||||
for (const value of values) {
|
||||
const text = stringOrNull(value);
|
||||
if (text !== null && text.length > 0) return text;
|
||||
}
|
||||
return 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 renderSupervisorLines(ref: AgentRunResourceRef, value: Record<string, unknown>): string[] {
|
||||
if (ref.kind !== "session" && ref.kind !== "task") return [];
|
||||
const supervisor = record(value.supervisor);
|
||||
const liveness = record(value.liveness);
|
||||
const source = Object.keys(supervisor).length > 0 ? supervisor : liveness;
|
||||
if (Object.keys(source).length === 0) return [];
|
||||
const timeoutBudget = record(source.timeoutBudget);
|
||||
const terminalClassification = record(source.terminalClassification);
|
||||
const runId = firstKnownString(source.activeRunId, source.runId, source.lastRunId, value.activeRunId, value.runId, value.lastRunId);
|
||||
const commandId = firstKnownString(source.activeCommandId, source.commandId, source.lastCommandId, value.activeCommandId, value.commandId, value.lastCommandId);
|
||||
const lines: string[] = [];
|
||||
const executionState = firstKnownString(source.executionState, value.executionState);
|
||||
if (executionState !== null) lines.push(`Execution: ${executionState}`);
|
||||
if (typeof source.active === "boolean") lines.push(`Active: ${String(source.active)}`);
|
||||
if (runId !== null) lines.push(`Run: run/${runId}`);
|
||||
if (commandId !== null) lines.push(`Command: command/${commandId}`);
|
||||
const phase = firstKnownString(source.phase, liveness.phase);
|
||||
const lastEventAgeMs = typeof source.lastEventAgeMs === "number" ? source.lastEventAgeMs : typeof liveness.lastEventAgeMs === "number" ? liveness.lastEventAgeMs : null;
|
||||
if (phase !== null || lastEventAgeMs !== null) lines.push(`Liveness: ${displayValue(phase)}${lastEventAgeMs === null ? "" : ` ageMs=${String(lastEventAgeMs)}`}`);
|
||||
const timeoutKind = firstKnownString(timeoutBudget.timeoutKind);
|
||||
const timeoutState = firstKnownString(timeoutBudget.state);
|
||||
const remainingMs = typeof timeoutBudget.remainingMs === "number" ? timeoutBudget.remainingMs : null;
|
||||
if (timeoutKind !== null || timeoutState !== null || remainingMs !== null) lines.push(`Timeout: ${displayValue(timeoutKind)} / ${displayValue(timeoutState)}${remainingMs === null ? "" : ` remainingMs=${String(remainingMs)}`}`);
|
||||
const category = firstKnownString(terminalClassification.category);
|
||||
const reason = firstKnownString(terminalClassification.reason);
|
||||
if (category !== null || reason !== null) lines.push(`Classification: ${displayValue(category)}${reason === null ? "" : `; ${reason}`}`);
|
||||
return lines;
|
||||
}
|
||||
|
||||
function renderFailureLines(value: Record<string, unknown>): string[] {
|
||||
const terminalClassification = record(value.terminalClassification);
|
||||
const nestedTerminalClassification = Object.keys(terminalClassification).length > 0
|
||||
? terminalClassification
|
||||
: record(record(value.liveness).terminalClassification);
|
||||
const failureKind = stringOrNull(value.failureKind)
|
||||
?? stringOrNull(terminalClassification.failureKind)
|
||||
?? stringOrNull(nestedTerminalClassification.failureKind)
|
||||
?? stringOrNull(value.degradedReason);
|
||||
const failureMessage = stringOrNull(value.failureMessage)
|
||||
?? stringOrNull(terminalClassification.failureMessage)
|
||||
?? stringOrNull(nestedTerminalClassification.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 category = stringOrNull(nestedTerminalClassification.category);
|
||||
const timeoutKind = stringOrNull(nestedTerminalClassification.timeoutKind);
|
||||
const timeoutState = stringOrNull(nestedTerminalClassification.timeoutState);
|
||||
const providerInterruption = stringOrNull(nestedTerminalClassification.providerInterruption);
|
||||
const lastActivity = stringOrNull(nestedTerminalClassification.lastActivityKind);
|
||||
const lastActivitySeq = nestedTerminalClassification.lastActivitySeq;
|
||||
const lines: string[] = [];
|
||||
if (failureKind !== null) lines.push(`Failure: ${failureKind}`);
|
||||
if (failureMessage !== null) lines.push(`Message: ${failureMessage}`);
|
||||
@@ -1429,16 +1479,18 @@ function renderFailureLines(value: Record<string, unknown>): string[] {
|
||||
}
|
||||
|
||||
function renderResourceNextLines(ref: AgentRunResourceRef, value: Record<string, unknown>): string[] {
|
||||
const runId = stringOrNull(value.runId);
|
||||
const commandId = stringOrNull(value.commandId);
|
||||
const supervisor = record(value.supervisor);
|
||||
const runId = firstKnownString(value.runId, value.activeRunId, value.lastRunId, supervisor.runId, supervisor.activeRunId, supervisor.lastRunId);
|
||||
const commandId = firstKnownString(value.commandId, value.activeCommandId, value.lastCommandId, supervisor.commandId, supervisor.activeCommandId, supervisor.lastCommandId);
|
||||
const runnerJobId = stringOrNull(value.runnerJobId) ?? (ref.kind === "runnerjob" ? ref.name : null);
|
||||
const sessionId = stringOrNull(value.sessionId);
|
||||
const sessionId = firstKnownString(value.sessionId, supervisor.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`,
|
||||
ref.kind !== "session" || sessionId === null ? null : `bun scripts/cli.ts agentrun send session/${sessionId} --prompt-stdin`,
|
||||
];
|
||||
const unique: string[] = [];
|
||||
for (const line of lines) {
|
||||
|
||||
Reference in New Issue
Block a user