feat: add controlled codex thread archive
This commit is contained in:
@@ -70,6 +70,24 @@ function isThreadCompactTask(task) {
|
||||
return task?.intentCategory === "thread_compact" || task?.taskType === "thread_compact";
|
||||
}
|
||||
|
||||
function resolveThreadLifecycleAction(task) {
|
||||
if (
|
||||
task?.threadLifecycleAction === "archive" ||
|
||||
task?.intentCategory === "thread_archive" ||
|
||||
task?.taskType === "thread_archive"
|
||||
) {
|
||||
return "archive";
|
||||
}
|
||||
if (
|
||||
task?.threadLifecycleAction === "unarchive" ||
|
||||
task?.intentCategory === "thread_unarchive" ||
|
||||
task?.taskType === "thread_unarchive"
|
||||
) {
|
||||
return "unarchive";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function resolveRollbackNumTurns(task) {
|
||||
const numeric = Number(task?.rollbackNumTurns ?? 1);
|
||||
return Number.isFinite(numeric) && numeric >= 1 ? Math.floor(numeric) : undefined;
|
||||
@@ -3092,6 +3110,31 @@ export async function executeCodexAppServerTask(runnerConfig, task) {
|
||||
});
|
||||
notify("initialized", {});
|
||||
|
||||
const lifecycleAction = resolveThreadLifecycleAction(task);
|
||||
if (lifecycleAction) {
|
||||
const lifecycleThreadId = targetThreadRef;
|
||||
if (!lifecycleThreadId) {
|
||||
throw new Error("CODEX_APP_SERVER_THREAD_ID_MISSING");
|
||||
}
|
||||
const method = lifecycleAction === "archive" ? "thread/archive" : "thread/unarchive";
|
||||
await request(method, { threadId: lifecycleThreadId });
|
||||
const actionLabel = lifecycleAction === "archive" ? "归档" : "恢复";
|
||||
return {
|
||||
status: "completed",
|
||||
replyBody: `已${actionLabel} Codex 线程。该动作只改变线程生命周期状态,不代表完成代码修改或文件恢复。`,
|
||||
threadId: lifecycleThreadId,
|
||||
turnControl: lifecycleAction,
|
||||
threadLifecycle: {
|
||||
action: lifecycleAction,
|
||||
status: "completed",
|
||||
},
|
||||
cwd,
|
||||
transport: runnerConfig.transport,
|
||||
executionProgress: progressCollector.snapshot(),
|
||||
canFallbackToCli: false,
|
||||
};
|
||||
}
|
||||
|
||||
const threadResult = targetThreadRef
|
||||
? await request("thread/resume", {
|
||||
threadId: targetThreadRef,
|
||||
|
||||
Reference in New Issue
Block a user