feat(codex): default task query to review summary
This commit is contained in:
@@ -17,6 +17,7 @@ const submitLockStaleMs = 120_000;
|
||||
const submitThrottleMs = nonNegativeIntegerEnv("UNIDESK_CODEX_SUBMIT_THROTTLE_MS", 2000);
|
||||
|
||||
interface CodexTaskOptions {
|
||||
detail: boolean;
|
||||
trace: boolean;
|
||||
traceLimit: number;
|
||||
traceMode: "tail" | "after" | "before";
|
||||
@@ -117,6 +118,7 @@ interface CodexTasksEntry {
|
||||
steer: string;
|
||||
read: string;
|
||||
full: string;
|
||||
detail: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -493,6 +495,19 @@ function compactLastAssistant(value: unknown, full: boolean): Record<string, unk
|
||||
};
|
||||
}
|
||||
|
||||
function compactFinalResponse(value: unknown, full: boolean): Record<string, unknown> {
|
||||
const record = compactLastAssistant(value, full);
|
||||
return {
|
||||
at: record.at,
|
||||
seq: record.seq,
|
||||
source: record.source,
|
||||
text: record.text,
|
||||
chars: record.chars,
|
||||
truncated: record.truncated,
|
||||
omittedChars: record.omittedChars,
|
||||
};
|
||||
}
|
||||
|
||||
function compactQueuedReason(value: unknown): Record<string, unknown> | null {
|
||||
const record = asRecord(value);
|
||||
if (record === null) return null;
|
||||
@@ -684,7 +699,53 @@ function compactSummary(summary: unknown, options: CodexTaskOptions, taskId: str
|
||||
nextPageTemplate: `bun scripts/cli.ts codex task ${taskId} --trace --after-seq <nextAfterSeq> --limit ${defaultTraceLimit}`,
|
||||
previousPageTemplate: `bun scripts/cli.ts codex task ${taskId} --trace --before-seq <previousBeforeSeq> --limit ${defaultTraceLimit}`,
|
||||
rawOutputTemplate: `bun scripts/cli.ts codex output ${taskId} --after-seq <rawSeq> --limit ${defaultOutputLimit}`,
|
||||
fullTextSummary: `bun scripts/cli.ts codex task ${taskId} --full --tool-limit ${Math.max(options.toolLimit, defaultToolLimit)}`,
|
||||
fullTextSummary: `bun scripts/cli.ts codex task ${taskId} --detail --full --tool-limit ${Math.max(options.toolLimit, defaultToolLimit)}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function compactReviewSummary(summary: unknown, options: CodexTaskOptions, taskId: string): Record<string, unknown> {
|
||||
const record = asRecord(summary) ?? {};
|
||||
const initialPrompt = asString(record.basePrompt || record.initialPrompt || record.prompt);
|
||||
const transcriptCount = asNumber(record.transcriptCount, 0);
|
||||
return {
|
||||
id: record.id ?? taskId,
|
||||
queueId: record.queueId ?? null,
|
||||
status: record.status ?? null,
|
||||
providerId: record.providerId ?? null,
|
||||
model: record.model ?? null,
|
||||
agentPort: record.agentPort ?? null,
|
||||
agentPortInfo: record.agentPortInfo ?? null,
|
||||
cwd: record.cwd ?? null,
|
||||
attempts: {
|
||||
currentAttempt: record.currentAttempt ?? null,
|
||||
maxAttempts: record.maxAttempts ?? null,
|
||||
currentMode: record.currentMode ?? null,
|
||||
},
|
||||
timing: record.timing ?? null,
|
||||
createdAt: record.createdAt ?? null,
|
||||
startedAt: record.startedAt ?? null,
|
||||
updatedAt: record.updatedAt ?? null,
|
||||
finishedAt: record.finishedAt ?? null,
|
||||
originalPrompt: textView(initialPrompt, options.full, 3000),
|
||||
finalResponse: compactFinalResponse(record.lastAssistantMessage, options.full),
|
||||
lastError: record.lastError ?? null,
|
||||
counts: {
|
||||
transcript: record.transcriptCount ?? null,
|
||||
output: record.outputCount ?? null,
|
||||
events: record.eventCount ?? null,
|
||||
},
|
||||
disclosure: {
|
||||
mode: "review",
|
||||
defaultScope: "original prompt and final response only; use detail/trace/output commands for progressive disclosure",
|
||||
fullPromptAndResponse: `bun scripts/cli.ts codex task ${taskId} --full`,
|
||||
detail: `bun scripts/cli.ts codex task ${taskId} --detail`,
|
||||
fullDetail: `bun scripts/cli.ts codex task ${taskId} --detail --full --tool-limit ${Math.max(options.toolLimit, defaultToolLimit)}`,
|
||||
traceTail: `bun scripts/cli.ts codex task ${taskId} --trace --tail --limit ${defaultTraceLimit}`,
|
||||
outputTail: `bun scripts/cli.ts codex output ${taskId} --tail --limit ${defaultOutputLimit}`,
|
||||
rawOutputTemplate: `bun scripts/cli.ts codex output ${taskId} --after-seq <rawSeq> --limit ${defaultOutputLimit}`,
|
||||
transcriptTotal: transcriptCount,
|
||||
transcriptMaxSeq: transcriptCount > 0 ? record.transcriptMaxSeq ?? null : null,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -853,7 +914,7 @@ function compactTracePage(body: Record<string, unknown>, taskId: string, limit:
|
||||
|
||||
function parseTaskOptions(args: string[]): CodexTaskOptions {
|
||||
assertKnownOptions(args, {
|
||||
flags: ["--trace", "--tail", "--from-start", "--first", "--full", "--raw-summary"],
|
||||
flags: ["--detail", "--trace", "--tail", "--from-start", "--first", "--full", "--raw-summary"],
|
||||
valueOptions: ["--before-seq", "--beforeSeq", "--after-seq", "--afterSeq", "--trace-limit", "--limit", "--tool-limit"],
|
||||
}, "codex task");
|
||||
const beforeSeq = nullablePositiveNumberOption(args, ["--before-seq", "--beforeSeq"]);
|
||||
@@ -861,7 +922,9 @@ function parseTaskOptions(args: string[]): CodexTaskOptions {
|
||||
const fromStart = hasFlag(args, "--from-start") || hasFlag(args, "--first");
|
||||
const trace = hasFlag(args, "--trace") || beforeSeq !== null || args.some((arg) => arg === "--after-seq" || arg === "--afterSeq") || fromStart || hasFlag(args, "--tail");
|
||||
const traceMode = beforeSeq !== null ? "before" : fromStart || args.some((arg) => arg === "--after-seq" || arg === "--afterSeq") ? "after" : "tail";
|
||||
const rawSummary = hasFlag(args, "--raw-summary");
|
||||
return {
|
||||
detail: hasFlag(args, "--detail") || rawSummary,
|
||||
trace,
|
||||
traceLimit: positiveIntegerOption(args, ["--trace-limit", "--limit"], defaultTraceLimit, maxTraceLimit),
|
||||
traceMode,
|
||||
@@ -869,7 +932,7 @@ function parseTaskOptions(args: string[]): CodexTaskOptions {
|
||||
beforeSeq,
|
||||
toolLimit: positiveIntegerOption(args, ["--tool-limit"], defaultToolLimit, 500),
|
||||
full: hasFlag(args, "--full") || hasFlag(args, "--raw-summary"),
|
||||
rawSummary: hasFlag(args, "--raw-summary"),
|
||||
rawSummary,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -963,7 +1026,7 @@ function codexTaskSummary(taskId: string, options: CodexTaskOptions, fetcher: Co
|
||||
const summary = summaryResponse.body.summary;
|
||||
const result: Record<string, unknown> = {
|
||||
upstream: summaryResponse.upstream,
|
||||
summary: compactSummary(summary, options, taskId),
|
||||
summary: options.detail ? compactSummary(summary, options, taskId) : compactReviewSummary(summary, options, taskId),
|
||||
};
|
||||
if (options.rawSummary) result.rawSummary = summary;
|
||||
if (options.trace) {
|
||||
@@ -1124,6 +1187,7 @@ function taskWatchEntry(task: Record<string, unknown>, summary: Record<string, u
|
||||
steer: steerCommand,
|
||||
read: `bun scripts/cli.ts codex read ${taskId}`,
|
||||
full: `bun scripts/cli.ts codex task ${taskId} --full`,
|
||||
detail: `bun scripts/cli.ts codex task ${taskId} --detail`,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1462,7 +1526,7 @@ async function codexTaskSummaryAsync(taskId: string, options: CodexTaskOptions,
|
||||
const summary = summaryResponse.body.summary;
|
||||
const result: Record<string, unknown> = {
|
||||
upstream: summaryResponse.upstream,
|
||||
summary: compactSummary(summary, options, taskId),
|
||||
summary: options.detail ? compactSummary(summary, options, taskId) : compactReviewSummary(summary, options, taskId),
|
||||
};
|
||||
if (options.rawSummary) result.rawSummary = summary;
|
||||
if (options.trace) {
|
||||
|
||||
+2
-2
@@ -49,7 +49,7 @@ export function rootHelp(): unknown {
|
||||
{ command: "schedule upsert-pgdata-backup [--time HH:MM] [--remote-base /SERVER_DATA/UNIDESK_PG_DATA]", description: "Create or update the daily PGDATA physical backup task that uploads monthly rotated archives to Baidu Netdisk." },
|
||||
{ command: "codex deploy <commitId> [--provider-id D601] [--timeout-ms N]", description: "Disabled legacy Code Queue deploy path; use the dev-only artifact consumer instead." },
|
||||
{ command: "codex submit [prompt] [--prompt-file path|--prompt-stdin] [--queue queueId] [--provider-id id] [--cwd path] [--model model] [--execution-mode mode] [--max-attempts N] [--reference-task-id id] [--dry-run]", description: "Submit a Code Queue task through backend-core -> code-queue proxy; --dry-run shows the structured request without enqueueing." },
|
||||
{ command: "codex task <taskId> [--trace --tail|--from-start|--after-seq N|--before-seq N --limit N] [--full]", description: "Fetch a compact Code Queue task summary; trace rows are opt-in and paged with next/previous commands to avoid output explosion." },
|
||||
{ command: "codex task <taskId> [--detail] [--trace --tail|--from-start|--after-seq N|--before-seq N --limit N] [--full]", description: "Fetch the bounded review view by default: original prompt, final response, and drill-down commands; detail and trace are opt-in." },
|
||||
{ command: "codex tasks [--view supervisor|full] [--queue id] [--status status[,status]] [--unread|--unread-only] [--limit N] [--before-id id]", description: "Show the bounded supervisor view by default: running, unread terminal, recent completed, queued, diagnostics, and drill-down commands." },
|
||||
{ command: "codex output <taskId> [--tail|--from-start|--after-seq N|--before-seq N --limit N] [--full-text]", description: "Fetch paged raw Code Queue output records by seq when a trace row has omitted command/output text." },
|
||||
{ command: "codex read <taskId>", description: "Mark one reviewed terminal task read; never run automatically as part of listing." },
|
||||
@@ -209,7 +209,7 @@ function codexHelp(): unknown {
|
||||
usage: [
|
||||
"bun scripts/cli.ts codex deploy <commitId> # disabled legacy deployment entry",
|
||||
"bun scripts/cli.ts codex submit [prompt] [--prompt-file path|--prompt-stdin] [--queue id] [--dry-run]",
|
||||
"bun scripts/cli.ts codex task <taskId> [--trace --tail|--from-start|--after-seq N|--before-seq N --limit N] [--full]",
|
||||
"bun scripts/cli.ts codex task <taskId> [--detail] [--trace --tail|--from-start|--after-seq N|--before-seq N --limit N] [--full]",
|
||||
"bun scripts/cli.ts codex tasks [--view supervisor|full] [--queue id] [--status succeeded,running] [--unread|--unread-only] [--limit N] [--before-id id]",
|
||||
"bun scripts/cli.ts codex output <taskId> [--tail|--from-start|--after-seq N|--before-seq N --limit N] [--full-text]",
|
||||
"bun scripts/cli.ts codex read <taskId>",
|
||||
|
||||
Reference in New Issue
Block a user