fix: 修复 AgentRun provider 假活性与容量可见性

This commit is contained in:
Codex
2026-07-11 04:16:58 +02:00
parent ce5c20f627
commit 04cd3e5f12
21 changed files with 3063 additions and 214 deletions
+108 -1
View File
@@ -148,10 +148,90 @@ export function renderResourceResult(command: string, raw: Record<string, unknow
export function renderDescribe(command: string, raw: Record<string, unknown>, options: AgentRunResourceOptions, ref: AgentRunResourceRef, text: string): RenderedCliResult {
if (options.raw) return renderMachine(command, raw, "json", raw.ok !== false);
if (options.output === "json" || options.output === "yaml") return renderMachine(command, { kind: ref.kind, name: ref.name, resource: innerData(raw) }, options.output, raw.ok !== false);
if (options.output === "json" || options.output === "yaml") {
const resource = record(innerData(raw));
const visibleResource = ref.kind === "runnerjob" && !options.full ? compactRunnerJobDescriptionPayload(resource) : resource;
return renderMachine(command, { kind: ref.kind, name: ref.name, resource: visibleResource }, options.output, raw.ok !== false);
}
return renderedCliResult(raw.ok !== false, command, text);
}
export function compactRunnerJobDescriptionPayload(value: Record<string, unknown>): Record<string, unknown> {
const observation = record(value.runtimeObservation);
const runner = record(observation.runner);
const target = record(observation.target);
const runId = value.runId ?? runner.runId ?? null;
const commandId = value.commandId ?? runner.commandId ?? null;
const runnerJobId = value.id ?? runner.runnerJobId ?? null;
const targetArgs = typeof target.node === "string" && typeof target.lane === "string"
? ` --node ${target.node} --lane ${target.lane}`
: "";
return {
id: runnerJobId,
runId,
commandId,
attemptId: value.attemptId ?? null,
runnerId: value.runnerId ?? runner.runnerId ?? null,
namespace: value.namespace ?? runner.namespace ?? target.namespace ?? null,
jobName: value.jobName ?? runner.name ?? null,
state: value.state ?? null,
managerPhase: value.managerPhase ?? value.phase ?? null,
terminalStatus: value.terminalStatus ?? null,
failureKind: value.failureKind ?? null,
image: value.image ?? null,
createdAt: value.createdAt ?? null,
startedAt: value.startedAt ?? null,
finishedAt: value.finishedAt ?? null,
runtimeObservation: {
ok: observation.ok ?? false,
reason: observation.reason ?? null,
observedAt: observation.observedAt ?? null,
target,
managerFacts: observation.managerFacts ?? null,
kubernetesFacts: observation.kubernetesFacts ?? null,
runner: Object.keys(runner).length === 0 ? null : {
name: runner.name ?? null,
runId: runner.runId ?? null,
commandId: runner.commandId ?? null,
runnerJobId: runner.runnerJobId ?? null,
runnerId: runner.runnerId ?? null,
createdAt: runner.createdAt ?? null,
lastActiveAt: runner.lastActiveAt ?? null,
lastActiveAgeMs: runner.lastActiveAgeMs ?? null,
runStatus: runner.runStatus ?? null,
runClaimedBy: runner.runClaimedBy ?? null,
commandState: runner.commandState ?? null,
heartbeatAt: runner.heartbeatAt ?? null,
heartbeatAgeMs: runner.heartbeatAgeMs ?? null,
state: runner.state ?? null,
jobStatus: runner.jobStatus ?? null,
podPhases: Array.isArray(runner.podPhases) ? runner.podPhases.slice(0, 4) : [],
waitingReasons: Array.isArray(runner.waitingReasons) ? runner.waitingReasons.slice(0, 8) : [],
podObservations: Array.isArray(runner.podObservations) ? runner.podObservations.slice(0, 2) : [],
identityComplete: runner.identityComplete === true,
managerFactsComplete: runner.managerFactsComplete === true,
podFactsComplete: runner.podFactsComplete === true,
cleanupAuthority: runner.cleanupAuthority ?? null,
cleanupDecisionComputed: runner.cleanupDecisionComputed === true,
safeCleanupCandidate: typeof runner.safeCleanupCandidate === "boolean" ? runner.safeCleanupCandidate : null,
protectedActive: typeof runner.protectedActive === "boolean" ? runner.protectedActive : null,
protectedReason: runner.protectedReason ?? null,
candidateKind: runner.candidateKind ?? null,
classification: runner.classification ?? null,
valuesPrinted: false,
},
mutation: false,
valuesPrinted: false,
},
next: {
events: typeof runId === "string" ? `bun scripts/cli.ts agentrun events run/${runId} --after-seq 0 --limit 100${targetArgs}` : null,
command: typeof runId === "string" && typeof commandId === "string" ? `bun scripts/cli.ts agentrun describe command/${commandId} --run ${runId}${targetArgs}` : null,
full: typeof runId === "string" && typeof runnerJobId === "string" ? `bun scripts/cli.ts agentrun describe runnerjob/${runnerJobId} --run ${runId}${targetArgs} --full -o json` : null,
},
valuesPrinted: false,
};
}
export function renderEventLike(command: string, raw: Record<string, unknown>, options: AgentRunResourceOptions, kind: string, items: Record<string, unknown>[], sourceName: string): RenderedCliResult {
if (options.raw) return renderMachine(command, raw, "json", raw.ok !== false);
const data = record(innerData(raw));
@@ -925,6 +1005,8 @@ export function renderGenericDescription(ref: AgentRunResourceRef, data: unknown
];
const identity = renderResourceIdentityLines(ref, value);
if (identity.length > 0) lines.push("", ...identity);
const runnerObservation = renderRunnerJobObservationLines(ref, value);
if (runnerObservation.length > 0) lines.push("", "Runtime observation:", ...runnerObservation.map((line) => ` ${line}`));
const supervisor = renderSupervisorLines(ref, value);
if (supervisor.length > 0) lines.push("", "Supervisor:", ...supervisor.map((line) => ` ${line}`));
const failure = renderFailureLines(value);
@@ -941,6 +1023,31 @@ export function renderGenericDescription(ref: AgentRunResourceRef, data: unknown
return lines.join("\n");
}
export function renderRunnerJobObservationLines(ref: AgentRunResourceRef, value: Record<string, unknown>): string[] {
if (ref.kind !== "runnerjob") return [];
const observation = record(value.runtimeObservation);
const runner = record(observation.runner);
if (Object.keys(observation).length === 0) return [];
if (Object.keys(runner).length === 0) {
return [
`Available: false`,
`Reason: ${displayValue(observation.reason ?? "runtime-observation-unavailable")}`,
];
}
const podPhases = Array.isArray(runner.podPhases) ? runner.podPhases.map(String).join(",") : "-";
const waitingReasons = Array.isArray(runner.waitingReasons) ? runner.waitingReasons.map(String).join(",") : "-";
return [
`Manager phase: ${displayValue(value.managerPhase ?? "-")}`,
`Pod phase: ${podPhases || "-"}`,
`Waiting: ${waitingReasons || "-"}`,
`AgeMs: ${displayValue(runner.lastActiveAgeMs ?? "-")}`,
`Run: ${displayValue(runner.runStatus ?? "-")} claimedBy=${displayValue(runner.runClaimedBy ?? "-")}`,
`Command: ${displayValue(runner.commandState ?? "-")}`,
`Heartbeat: ${displayValue(runner.heartbeatAt ?? "-")} ageMs=${displayValue(runner.heartbeatAgeMs ?? "-")}`,
`Classification: ${displayValue(runner.classification ?? "-")} protected=${displayValue(runner.protectedActive ?? "-")}`,
];
}
export function renderResourceIdentityLines(ref: AgentRunResourceRef, value: Record<string, unknown>): string[] {
const supervisor = record(value.supervisor);
const fields: [string, unknown][] = [