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) {
|
||||
|
||||
Reference in New Issue
Block a user