fix: 修复 CLI repo 与状态别名解析
This commit is contained in:
+65
-12
@@ -59,6 +59,30 @@ const defaultSteerRetryAttempts = 2;
|
||||
const maxSteerRetryAttempts = 3;
|
||||
const defaultSteerRetryDelayMs = 750;
|
||||
const maxSteerRetryDelayMs = 5_000;
|
||||
const codexTaskStatuses = ["queued", "running", "judging", "retry_wait", "succeeded", "failed", "canceled"] as const;
|
||||
const codexTerminalTaskStatuses = ["succeeded", "failed", "canceled"] as const;
|
||||
const codexTaskStatusAliases: Record<string, string> = {
|
||||
completed: "succeeded",
|
||||
complete: "succeeded",
|
||||
success: "succeeded",
|
||||
successful: "succeeded",
|
||||
succeeded: "succeeded",
|
||||
cancelled: "canceled",
|
||||
canceled: "canceled",
|
||||
failed: "failed",
|
||||
failure: "failed",
|
||||
errored: "failed",
|
||||
error: "failed",
|
||||
running: "running",
|
||||
active: "running",
|
||||
judging: "judging",
|
||||
judge: "judging",
|
||||
queued: "queued",
|
||||
pending: "queued",
|
||||
retrying: "retry_wait",
|
||||
retry_wait: "retry_wait",
|
||||
"retry-wait": "retry_wait",
|
||||
};
|
||||
|
||||
interface CodexTaskOptions {
|
||||
detail: boolean;
|
||||
@@ -1176,6 +1200,45 @@ function assertKnownOptions(args: string[], spec: { flags?: string[]; valueOptio
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeCodexStatusFilter(raw: string, allowedValues: readonly string[], command: string): string[] {
|
||||
const requested = raw.split(/[,\s]+/u).map((item) => item.trim()).filter(Boolean);
|
||||
if (requested.length === 0) throw new Error(`${command} --status requires at least one status value`);
|
||||
const allowed = new Set(allowedValues);
|
||||
const normalized: string[] = [];
|
||||
const unsupported: string[] = [];
|
||||
for (const value of requested) {
|
||||
const key = value.toLowerCase();
|
||||
const canonical = codexTaskStatusAliases[key] ?? key;
|
||||
if (!allowed.has(canonical)) {
|
||||
unsupported.push(value);
|
||||
continue;
|
||||
}
|
||||
if (!normalized.includes(canonical)) normalized.push(canonical);
|
||||
}
|
||||
if (unsupported.length > 0) {
|
||||
const aliasHints = Object.entries(codexTaskStatusAliases)
|
||||
.filter(([alias, canonical]) => alias !== canonical && allowed.has(canonical))
|
||||
.map(([alias, canonical]) => `${alias}->${canonical}`);
|
||||
const detail = {
|
||||
ok: false,
|
||||
degradedReason: "validation-failed",
|
||||
command,
|
||||
option: "--status",
|
||||
unsupported,
|
||||
supported: allowedValues,
|
||||
aliases: aliasHints,
|
||||
examples: [
|
||||
`bun scripts/cli.ts ${command} --status ${allowedValues.join(",")}`,
|
||||
command === "codex tasks"
|
||||
? "bun scripts/cli.ts codex tasks --status completed,cancelled --view commander"
|
||||
: "bun scripts/cli.ts codex unread --status completed,cancelled",
|
||||
],
|
||||
};
|
||||
throw new Error(`${command} unsupported --status value: ${unsupported.join(", ")}; ${JSON.stringify(detail)}`);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function textView(text: string, full: boolean, maxChars: number): Record<string, unknown> {
|
||||
const truncated = !full && text.length > maxChars;
|
||||
return {
|
||||
@@ -2674,12 +2737,7 @@ function parseTasksOptions(args: string[]): CodexTasksOptions {
|
||||
const statusRaw = optionValue(args, ["--status"]);
|
||||
const statusFilter = statusRaw === undefined
|
||||
? null
|
||||
: statusRaw.split(/[,\s]+/u).map((item) => item.trim()).filter(Boolean);
|
||||
if (statusFilter !== null) {
|
||||
const supported = new Set(["queued", "running", "judging", "retry_wait", "succeeded", "failed", "canceled"]);
|
||||
const unsupported = statusFilter.filter((status) => !supported.has(status));
|
||||
if (unsupported.length > 0) throw new Error(`unsupported --status value: ${unsupported.join(", ")}; supported: ${Array.from(supported).join(", ")}`);
|
||||
}
|
||||
: normalizeCodexStatusFilter(statusRaw, codexTaskStatuses, "codex tasks");
|
||||
const requestedLimit = positiveIntegerOption(args, ["--limit"], defaultTasksLimit);
|
||||
return {
|
||||
queueId: optionValue(args, ["--queue", "--queue-id"]),
|
||||
@@ -2727,12 +2785,7 @@ function parseUnreadOptions(args: string[]): CodexUnreadOptions {
|
||||
const statusRaw = optionValue(optionArgs, ["--status"]);
|
||||
const statusFilter = statusRaw === undefined
|
||||
? null
|
||||
: statusRaw.split(/[,\s]+/u).map((item) => item.trim()).filter(Boolean);
|
||||
if (statusFilter !== null) {
|
||||
const supported = new Set(["succeeded", "failed", "canceled"]);
|
||||
const unsupported = statusFilter.filter((status) => !supported.has(status));
|
||||
if (unsupported.length > 0) throw new Error(`unsupported --status value for codex unread: ${unsupported.join(", ")}; supported terminal statuses: ${Array.from(supported).join(", ")}`);
|
||||
}
|
||||
: normalizeCodexStatusFilter(statusRaw, codexTerminalTaskStatuses, "codex unread");
|
||||
const requestedLimit = positiveIntegerOption(optionArgs, ["--limit"], defaultTasksLimit);
|
||||
const action: CodexUnreadAction = subcommand === "mark-read" || hasFlag(optionArgs, "--mark-read") ? "mark-read" : "summary";
|
||||
const explicitDryRun = hasFlag(optionArgs, "--dry-run");
|
||||
|
||||
Reference in New Issue
Block a user