fix: structure codex steer confirmation

Fixes #144.
This commit is contained in:
Lyon
2026-05-23 22:04:35 +08:00
committed by GitHub
parent 59776aa5d2
commit 12fdc9e238
2 changed files with 120 additions and 7 deletions
+75 -5
View File
@@ -261,6 +261,7 @@ type CodexSteerFailureReason =
| "invalid-proxy-response";
type CodexSteerAcceptanceStatus = "accepted" | "not_accepted" | "accepted_response_timeout" | "unknown";
type CodexSteerConfirmStatus = "confirmed" | "pending" | "unknown" | "not-supported";
type CodexResumeAcceptanceStatus = "queued" | "duplicate_suppressed" | "not_accepted" | "accepted_response_timeout" | "unknown";
type CodexResumeDeliveryState = ResumeDeliveryState;
@@ -927,6 +928,64 @@ function safeFetchSteerTraceConfirmation(taskId: string, steerId: string, fetche
}
}
function steerConfirmNotSupported(response: Record<string, unknown> | null, targetPath: string): boolean {
const status = responseStatus(response);
if (status !== 404 && status !== 405) return false;
const body = responseBody(response);
const bodyPath = asString(body?.path);
const bodyError = asString(body?.error).toLowerCase();
return bodyPath === targetPath
|| bodyError === "not found"
|| bodyError.includes("method not allowed");
}
function compactSteerConfirmUnsupported(taskId: string, steerId: string, response: Record<string, unknown> | null, targetPath: string, options: CodexSteerConfirmOptions): Record<string, unknown> {
const rawStatus = responseStatus(response);
const status: CodexSteerConfirmStatus = steerConfirmNotSupported(response, targetPath) ? "not-supported" : "unknown";
return {
ok: false,
traceConfirmation: {
taskId,
steerId,
found: false,
accepted: false,
status,
deliveryState: status,
matchCount: 0,
trace: null,
promptOmitted: true,
},
delivery: {
steerId,
status,
deliveryState: status,
promptOmitted: true,
supported: status === "not-supported" ? false : null,
},
diagnostics: {
reason: status === "not-supported" ? "steer-confirmation-endpoint-not-supported" : "steer-confirmation-lookup-failed",
status: rawStatus,
message: responseErrorMessage(response),
promptOmitted: true,
},
commands: {
task: `bun scripts/cli.ts codex task ${taskId}`,
trace: `bun scripts/cli.ts codex task ${taskId} --trace --tail --limit ${defaultTraceLimit}`,
retrySameSteerId: `bun scripts/cli.ts codex steer ${taskId} --prompt-file <path> --steer-id ${steerId}`,
rawLookup: rawSteerConfirmationCommand(taskId, steerId),
},
...(options.raw ? { raw: response } : {}),
};
}
function steerConfirmStatus(confirmation: Record<string, unknown>): CodexSteerConfirmStatus {
if (asBoolean(confirmation.accepted) || asBoolean(confirmation.found)) return "confirmed";
const deliveryState = asString(confirmation.deliveryState);
if (deliveryState === "not-supported") return "not-supported";
if (deliveryState === "unknown" || deliveryState.length === 0) return "pending";
return "unknown";
}
function unwrapSteerResponse(response: unknown, targetPath: string, stableProxyPath: string, rawProxyEquivalent: string): { ok: true; upstream: { ok: unknown; status: unknown }; body: Record<string, unknown> } | { ok: false; diagnostics: ClassifiedCodexSteerError; rawResponse: unknown } {
const record = asRecord(response);
const body = responseBody(record);
@@ -7590,17 +7649,28 @@ function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFe
function codexSteerTraceConfirm(taskId: string, args: string[], fetcher: CodexResponseFetcher = coreInternalFetch): unknown {
const options = parseSteerConfirmOptions(args);
const path = steerConfirmationPath(taskId, options.steerId);
const response = unwrapCodexResponse(fetcher(codeQueueProxyPath(path)));
const targetPath = `/api/tasks/${encodeURIComponent(taskId)}/steer-confirmation`;
const rawResponse = fetcher(codeQueueProxyPath(path));
const record = asRecord(rawResponse);
const body = responseBody(record);
if (record?.ok !== true || body?.ok !== true) return compactSteerConfirmUnsupported(taskId, options.steerId, record, targetPath, options);
const response = { upstream: { ok: record.ok, status: record.status }, body };
const confirmation = compactSteerTraceConfirmation(response.body, taskId, options.steerId);
const status = steerConfirmStatus(confirmation);
return {
ok: asBoolean(confirmation.accepted),
ok: status === "confirmed",
upstream: response.upstream,
traceConfirmation: confirmation,
traceConfirmation: {
...confirmation,
status,
deliveryState: status,
},
delivery: {
steerId: options.steerId,
status: asBoolean(confirmation.accepted) ? "accepted" : "unknown",
deliveryState: confirmation.deliveryState,
status,
deliveryState: status,
promptOmitted: true,
supported: true,
},
commands: {
task: `bun scripts/cli.ts codex task ${taskId}`,