fix: compact codex pr preflight output

This commit is contained in:
Codex
2026-05-23 01:06:09 +00:00
parent 6f40350a62
commit d4c6fadc49
5 changed files with 329 additions and 72 deletions
+209 -10
View File
@@ -4180,9 +4180,193 @@ function prPreflightAuthScopeSummary(tokenCoverage: Record<string, unknown> | nu
};
}
function prPreflightTokenCoverage(record: Record<string, unknown>): Record<string, unknown> | null {
const preflight = asRecord(record.preflight);
const schedulerPreflight = asRecord(record.schedulerPreflight);
const schedulerAuth = asRecord(schedulerPreflight?.auth);
const schedulerSummary = schedulerPreflight === null ? null : {
ok: schedulerPreflight.authReady ?? null,
source: schedulerPreflight.authSource ?? null,
credentialSource: schedulerPreflight.credentialSource ?? null,
scope: schedulerPreflight.scope ?? null,
missing: Array.isArray(schedulerPreflight.missing) && schedulerPreflight.missing.length > 0
? schedulerPreflight.missing.map(String)
: schedulerPreflight.authReady === false
? ["GH_TOKEN", "GITHUB_TOKEN"]
: [],
runnerDisposition: schedulerPreflight.authReady === true ? "ready" : "infra-blocked",
};
return asRecord(record.tokenCoverage)
?? asRecord(preflight?.tokenCoverage)
?? schedulerAuth
?? schedulerSummary
?? null;
}
function prPreflightAuthBroker(record: Record<string, unknown>): Record<string, unknown> | null {
const preflight = asRecord(record.preflight);
const schedulerPreflight = asRecord(record.schedulerPreflight);
return asRecord(record.authBroker)
?? asRecord(preflight?.authBroker)
?? asRecord(schedulerPreflight?.authBroker)
?? null;
}
function prPreflightCapabilityContract(record: Record<string, unknown>): Record<string, unknown> | null {
const preflight = asRecord(record.preflight);
const prCapability = asRecord(record.prCapability);
return asRecord(record.prCapabilityContract)
?? asRecord(preflight?.prCapabilityContract)
?? prCapability
?? null;
}
function prPreflightCommandSet(record: Record<string, unknown>, options: CodexPrPreflightOptions): Record<string, unknown> {
const preflight = asRecord(record.preflight);
const commands = asRecord(record.commands) ?? asRecord(preflight?.commands) ?? {};
const activeRunnerDevContainer = asRecord(record.activeRunnerDevContainer) ?? activeRunnerDevContainerCapability();
const activeCommands = asRecord(activeRunnerDevContainer.commands) ?? {};
const remoteFlag = options.remote ? " --remote" : "";
const fullDetail = `bun scripts/cli.ts codex pr-preflight${remoteFlag} --full`;
return {
verifyActiveRunnerAuth: activeCommands.authStatus ?? commands.local ?? "bun scripts/cli.ts gh auth status --repo pikasTech/unidesk",
verifyActiveRunnerPrCreateDryRun: activeCommands.prCreateDryRun ?? "bun scripts/cli.ts gh pr create --repo pikasTech/unidesk --title <title> --body-file <file> --base master --head <head> --dry-run",
rerunSchedulerPreflight: commands.runner ?? `bun scripts/cli.ts codex pr-preflight${remoteFlag}`,
fullDetail,
rawProxy: commands.rawProxy ?? "bun scripts/cli.ts microservice proxy code-queue /api/runtime-preflight?remote=1 --raw --full",
schedulerAuthSource: "configure auth-broker or inject GH_TOKEN/GITHUB_TOKEN into the scheduler runtime secret",
};
}
function compactRecommendedActions(record: Record<string, unknown>): Record<string, unknown>[] {
const actions = Array.isArray(record.recommendedActions) ? record.recommendedActions : [];
if (actions.length > 0) {
return actions.slice(0, 3).map((item) => {
const action = asRecord(item) ?? {};
return {
scope: action.scope ?? null,
priority: action.priority ?? null,
action: action.action ?? null,
command: action.command ?? null,
writesRemote: action.writesRemote ?? false,
};
});
}
const tokenCoverage = prPreflightTokenCoverage(record);
return prPreflightRecommendedActions(tokenCoverage);
}
function compactPrPreflightCommanderView(record: Record<string, unknown>, options: CodexPrPreflightOptions): Record<string, unknown> {
if (options.full) return record;
const tokenCoverage = prPreflightTokenCoverage(record);
const authBroker = prPreflightAuthBroker(record);
const capability = prPreflightCapabilityContract(record);
const activeRunnerDevContainer = asRecord(record.activeRunnerDevContainer) ?? activeRunnerDevContainerCapability();
const activeCommands = asRecord(activeRunnerDevContainer.commands) ?? {};
const authBrokerCapability = asRecord(authBroker?.capability);
const expectedPrHandoff = asRecord(capability?.expectedPrHandoff);
const unideskGhCli = asRecord(capability?.unideskGhCli);
const pushDryRun = asRecord(capability?.pushDryRun);
const prCreateDryRun = asRecord(capability?.prCreateDryRun);
const unsupportedMergeBoundary = asRecord(capability?.unsupportedMergeBoundary);
const commands = prPreflightCommandSet(record, options);
const schedulerAuthReady = tokenCoverage?.ok === true;
const activeRunnerTokenCandidatePresent = activeRunnerDevContainer.ok === true;
const failureKind = record.failureKind ?? (schedulerAuthReady ? null : "auth-missing");
const degradedReason = record.degradedReason ?? (schedulerAuthReady ? null : "auth-broker-needed");
const githubTransient = asRecord(record.githubTransient);
return {
ok: record.ok === true,
runnerDisposition: record.runnerDisposition ?? (record.ok === true ? "ready" : "infra-blocked"),
failureKind,
degradedReason,
...(record.retryable === true ? { retryable: true } : {}),
...(typeof record.commanderAction === "string" ? { commanderAction: record.commanderAction } : {}),
...(githubTransient === null ? {} : { githubTransient }),
summary: {
status: record.ok === true ? "ready" : "blocked",
schedulerPreflightAuthReady: schedulerAuthReady,
schedulerPreflightScope: tokenCoverage?.scope ?? "scheduler-runner-env",
activeRunnerTokenCandidatePresent,
activeRunnerScope: activeRunnerDevContainer.scope ?? "current-cli-process",
interpretation: schedulerAuthReady
? "scheduler preflight auth is ready; still use active-runner dry-runs before writes"
: "scheduler auth is missing for preflight admission only; this does not prove the active runner/dev container cannot create or comment PRs",
},
schedulerPreflight: {
scope: tokenCoverage?.scope ?? "scheduler-runner-env",
authReady: schedulerAuthReady,
authSource: tokenCoverage?.source ?? null,
credentialSource: tokenCoverage?.credentialSource ?? null,
missing: Array.isArray(tokenCoverage?.missing) ? tokenCoverage.missing.map(String) : [],
failureKind: schedulerAuthReady ? null : failureKind,
degradedReason: schedulerAuthReady ? null : degradedReason,
authBroker: authBroker === null ? null : {
ok: authBroker.ok ?? schedulerAuthReady,
source: authBroker.source ?? null,
configured: authBroker.configured ?? null,
needed: authBroker.needed ?? !schedulerAuthReady,
nextAction: authBroker.nextAction ?? null,
capabilitySource: authBrokerCapability?.source ?? tokenCoverage?.credentialSource ?? null,
},
},
activeRunnerPrCapability: {
scope: activeRunnerDevContainer.scope ?? "current-cli-process",
tokenCandidatePresent: activeRunnerTokenCandidatePresent,
credentialSource: activeRunnerDevContainer.credentialSource ?? null,
ghTokenPresent: activeRunnerDevContainer.ghTokenPresent ?? false,
githubTokenPresent: activeRunnerDevContainer.githubTokenPresent ?? false,
independentOfSchedulerPreflight: activeRunnerDevContainer.notEquivalentToSchedulerEnv ?? true,
verifyCommands: {
authStatus: activeCommands.authStatus ?? commands.verifyActiveRunnerAuth,
prCreateDryRun: activeCommands.prCreateDryRun ?? commands.verifyActiveRunnerPrCreateDryRun,
},
},
prCapability: capability === null ? null : {
targetBranch: capability.targetBranch ?? "master",
sourceBranch: expectedPrHandoff?.sourceBranch ?? prCreateDryRun?.headBranch ?? null,
unideskGhCliOk: unideskGhCli?.ok ?? null,
systemGhBinaryRequiredForWrites: capability.systemGhBinaryRequiredForWrites ?? false,
realPrCreateRequiresCommanderAuthorization: capability.realPrCreateRequiresCommanderAuthorization ?? true,
pushDryRun: pushDryRun === null ? null : {
requested: pushDryRun.requested ?? false,
writesRemote: pushDryRun.writesRemote ?? false,
commandShape: pushDryRun.commandShape ?? null,
},
prCreateDryRun: prCreateDryRun === null ? null : {
requested: prCreateDryRun.requested ?? false,
writesRemote: prCreateDryRun.writesRemote ?? false,
commandShape: prCreateDryRun.commandShape ?? null,
},
mergeSupported: unsupportedMergeBoundary?.supported ?? false,
mergeCommand: unsupportedMergeBoundary?.command ?? "bun scripts/cli.ts gh pr merge <number> --repo pikasTech/unidesk",
},
authScopeSummary: record.authScopeSummary ?? prPreflightAuthScopeSummary(tokenCoverage, activeRunnerDevContainer),
scopeBoundary: record.scopeBoundary ?? prPreflightScopeBoundary(tokenCoverage),
recommendedActions: compactRecommendedActions(record),
upstream: record.upstream ?? null,
controlPlane: record.controlPlane ?? null,
observationGap: record.observationGap ?? undefined,
localObservationGap: record.localObservationGap ?? undefined,
localObservationSummary: record.localObservationSummary ?? undefined,
remoteObservationSummary: record.remoteObservationSummary ?? undefined,
commands,
disclosure: {
defaultView: "commander-compact",
fullDetailOmitted: true,
fullObservationsOmitted: asRecord(record.disclosure)?.fullObservationsOmitted ?? true,
expandWith: commands.fullDetail,
rawProxy: commands.rawProxy,
detailFieldsOmitted: ["preflight", "tools", "agentPorts", "git", "egress", "remote", "limitations", "risks", "rawRuntimePreflight"],
},
};
}
function decoratePrPreflightScopeBoundary(record: Record<string, unknown>): Record<string, unknown> {
const preflight = asRecord(record.preflight);
const tokenCoverage = asRecord(record.tokenCoverage) ?? asRecord(preflight?.tokenCoverage);
const tokenCoverage = prPreflightTokenCoverage(record);
const scopeBoundary = prPreflightScopeBoundary(tokenCoverage);
const activeRunnerDevContainer = activeRunnerDevContainerCapability();
const authScopeSummary = prPreflightAuthScopeSummary(tokenCoverage, activeRunnerDevContainer);
@@ -4224,7 +4408,20 @@ function prPreflightObservationGap(kind: Exclude<CodeQueueObservationGapKind, nu
function prPreflightObservationSummary(record: Record<string, unknown> | null): Record<string, unknown> | null {
if (record === null) return null;
const preflight = asRecord(record.preflight);
const tokenCoverage = asRecord(record.tokenCoverage) ?? asRecord(preflight?.tokenCoverage);
const schedulerPreflight = asRecord(record.schedulerPreflight);
const tokenCoverage = asRecord(record.tokenCoverage)
?? asRecord(preflight?.tokenCoverage)
?? (schedulerPreflight === null ? null : {
ok: schedulerPreflight.authReady ?? null,
source: schedulerPreflight.authSource ?? null,
credentialSource: schedulerPreflight.credentialSource ?? null,
scope: schedulerPreflight.scope ?? null,
missing: Array.isArray(schedulerPreflight.missing) && schedulerPreflight.missing.length > 0
? schedulerPreflight.missing.map(String)
: schedulerPreflight.authReady === false
? ["GH_TOKEN", "GITHUB_TOKEN"]
: [],
});
const controlPlane = asRecord(record.controlPlane);
const targetStack = asRecord(record.targetStack);
return {
@@ -4561,7 +4758,7 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
const remoteRecord = asRecord(remoteResponse);
if (remoteRecord !== null) {
if (remoteRecord.ok === false) {
return decoratePrPreflightScopeBoundary({
return compactPrPreflightCommanderView(decoratePrPreflightScopeBoundary({
...remoteRecord,
observationGap: prPreflightObservationGap(
remoteRecord.failureKind === "control-plane-missing" ? "control-plane-observation-gap" : "runner-local-observation-gap",
@@ -4584,9 +4781,9 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
remoteFallbackUsed: true,
},
...maybeFullPrPreflightObservations(options, localRecord, remoteRecord),
});
}), options);
}
return decoratePrPreflightScopeBoundary({
return compactPrPreflightCommanderView(decoratePrPreflightScopeBoundary({
...remoteRecord,
localObservationGap: prPreflightObservationGap("runner-local-observation-gap", {
reason: "local backend-core target-stack absence was bypassed by healthy remote control-plane fallback",
@@ -4603,7 +4800,7 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
remoteFallbackUsed: true,
},
...maybeFullPrPreflightObservations(options, localRecord, remoteRecord),
});
}), options);
}
}
if (localRecord?.ok !== true) {
@@ -4693,13 +4890,14 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
};
}
const compact = compactPrRuntimePreflight(preflight, options);
return {
return compactPrPreflightCommanderView({
ok: compact.ok,
runnerDisposition: compact.runnerDisposition,
failureKind: compact.failureKind ?? null,
degradedReason: compact.degradedReason ?? null,
...(compact.retryable === true ? { retryable: true } : {}),
...(typeof compact.commanderAction === "string" ? { commanderAction: compact.commanderAction } : {}),
...(asRecord(compact.githubTransient) === null ? {} : { githubTransient: compact.githubTransient }),
authScopeSummary: compact.authScopeSummary,
scopeBoundary: compact.scopeBoundary,
activeRunnerDevContainer: compact.activeRunnerDevContainer,
@@ -4711,7 +4909,7 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
remoteFallbackUsed: false,
},
preflight: compact,
};
}, options);
}
export function codexPrPreflightQueryForTest(optionArgs: string[], transport: CodeQueuePrPreflightTransport = {}): unknown {
@@ -4751,13 +4949,14 @@ export async function codexPrPreflightQueryAsync(optionArgs: string[], fetcher:
};
}
const compact = compactPrRuntimePreflight(preflight, options);
return {
return compactPrPreflightCommanderView({
ok: compact.ok,
runnerDisposition: compact.runnerDisposition,
failureKind: compact.failureKind ?? null,
degradedReason: compact.degradedReason ?? null,
...(compact.retryable === true ? { retryable: true } : {}),
...(typeof compact.commanderAction === "string" ? { commanderAction: compact.commanderAction } : {}),
...(asRecord(compact.githubTransient) === null ? {} : { githubTransient: compact.githubTransient }),
authScopeSummary: compact.authScopeSummary,
scopeBoundary: compact.scopeBoundary,
activeRunnerDevContainer: compact.activeRunnerDevContainer,
@@ -4769,7 +4968,7 @@ export async function codexPrPreflightQueryAsync(optionArgs: string[], fetcher:
remoteFallbackUsed: false,
},
preflight: compact,
};
}, options);
}
export function codexSubmitRoutingRecommendationForTest(prompt: string, model?: string): SubmitRoutingRecommendation {