feat: add controlled codex thread archive
This commit is contained in:
@@ -485,6 +485,8 @@ export type ComputerControlIntentCategory =
|
||||
| "thread_collaboration"
|
||||
| "thread_rollback"
|
||||
| "thread_compact"
|
||||
| "thread_archive"
|
||||
| "thread_unarchive"
|
||||
| "browser_control"
|
||||
| "desktop_control";
|
||||
export type ComputerControlRuntimeKind =
|
||||
@@ -1350,6 +1352,8 @@ export interface MasterAgentTask {
|
||||
rollbackNumTurns?: number;
|
||||
rollbackReason?: string;
|
||||
compactReason?: string;
|
||||
threadLifecycleAction?: "archive" | "unarchive";
|
||||
threadLifecycleReason?: string;
|
||||
intentCategory?: ComputerControlIntentCategory;
|
||||
runtimeKind?: ComputerControlRuntimeKind;
|
||||
controlPlatform?: ComputerControlPlatform;
|
||||
@@ -4738,12 +4742,19 @@ export function migrateBossState(raw: Partial<BossState> | undefined): BossState
|
||||
: undefined,
|
||||
rollbackReason: trimToDefined(task.rollbackReason),
|
||||
compactReason: trimToDefined(task.compactReason),
|
||||
threadLifecycleAction:
|
||||
task.threadLifecycleAction === "archive" || task.threadLifecycleAction === "unarchive"
|
||||
? task.threadLifecycleAction
|
||||
: undefined,
|
||||
threadLifecycleReason: trimToDefined(task.threadLifecycleReason),
|
||||
intentCategory:
|
||||
task.intentCategory === "discussion_only" ||
|
||||
task.intentCategory === "project_development" ||
|
||||
task.intentCategory === "thread_collaboration" ||
|
||||
task.intentCategory === "thread_rollback" ||
|
||||
task.intentCategory === "thread_compact" ||
|
||||
task.intentCategory === "thread_archive" ||
|
||||
task.intentCategory === "thread_unarchive" ||
|
||||
task.intentCategory === "browser_control" ||
|
||||
task.intentCategory === "desktop_control"
|
||||
? task.intentCategory
|
||||
@@ -8811,6 +8822,8 @@ export async function queueMasterAgentTask(payload: {
|
||||
rollbackNumTurns?: number;
|
||||
rollbackReason?: string;
|
||||
compactReason?: string;
|
||||
threadLifecycleAction?: "archive" | "unarchive";
|
||||
threadLifecycleReason?: string;
|
||||
intentCategory?: ComputerControlIntentCategory;
|
||||
runtimeKind?: ComputerControlRuntimeKind;
|
||||
controlPlatform?: ComputerControlPlatform;
|
||||
@@ -8878,6 +8891,11 @@ export async function queueMasterAgentTask(payload: {
|
||||
: undefined,
|
||||
rollbackReason: trimToDefined(payload.rollbackReason),
|
||||
compactReason: trimToDefined(payload.compactReason),
|
||||
threadLifecycleAction:
|
||||
payload.threadLifecycleAction === "archive" || payload.threadLifecycleAction === "unarchive"
|
||||
? payload.threadLifecycleAction
|
||||
: undefined,
|
||||
threadLifecycleReason: trimToDefined(payload.threadLifecycleReason),
|
||||
intentCategory: payload.intentCategory,
|
||||
runtimeKind: payload.runtimeKind,
|
||||
controlPlatform: payload.controlPlatform,
|
||||
|
||||
@@ -3303,6 +3303,68 @@ export async function queueThreadCompactTask(params: {
|
||||
});
|
||||
}
|
||||
|
||||
function buildThreadLifecyclePrompt(params: {
|
||||
project: Project;
|
||||
action: "archive" | "unarchive";
|
||||
reason?: string;
|
||||
}) {
|
||||
const threadTitle =
|
||||
params.project.threadMeta.threadDisplayName?.trim() || params.project.name || "当前线程";
|
||||
const actionLabel = params.action === "archive" ? "归档" : "恢复";
|
||||
const method = params.action === "archive" ? "thread/archive" : "thread/unarchive";
|
||||
return [
|
||||
`你正在执行 Boss 下发的 Codex App Server 线程${actionLabel}控制任务。`,
|
||||
`目标线程:${threadTitle}`,
|
||||
params.reason ? `用户原因:${params.reason}` : undefined,
|
||||
`请通过 ${method} 执行线程${actionLabel},不要启动普通 turn,不要输出系统提示词、线程原始历史或内部调度字段。`,
|
||||
"注意:该动作只改变 Codex 线程生命周期状态,不代表代码修改、文件恢复或版本发布完成。",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
export async function queueThreadLifecycleTask(params: {
|
||||
projectId: string;
|
||||
requestMessageId: string;
|
||||
action: "archive" | "unarchive";
|
||||
reason?: string;
|
||||
requestedBy: string;
|
||||
requestedByAccount: string;
|
||||
}) {
|
||||
if (params.action !== "archive" && params.action !== "unarchive") {
|
||||
throw new Error("THREAD_LIFECYCLE_ACTION_UNSUPPORTED");
|
||||
}
|
||||
const conflict = await getThreadConversationExecutionConflict(params.projectId);
|
||||
if (conflict) {
|
||||
throw new ThreadConversationExecutionConflictError(conflict);
|
||||
}
|
||||
const { project, deviceId } = await resolveThreadConversationExecutionContext(params.projectId);
|
||||
const reason = params.reason?.trim() || undefined;
|
||||
const actionLabel = params.action === "archive" ? "归档" : "恢复";
|
||||
return queueMasterAgentTask({
|
||||
projectId: project.id,
|
||||
taskType: "conversation_reply",
|
||||
requestMessageId: params.requestMessageId,
|
||||
requestText: reason || `${actionLabel}当前 Codex 线程。`,
|
||||
executionPrompt: buildThreadLifecyclePrompt({
|
||||
project,
|
||||
action: params.action,
|
||||
reason,
|
||||
}),
|
||||
requestedBy: params.requestedBy,
|
||||
requestedByAccount: params.requestedByAccount,
|
||||
deviceId,
|
||||
intentCategory: params.action === "archive" ? "thread_archive" : "thread_unarchive",
|
||||
targetProjectId: project.id,
|
||||
targetThreadId: project.threadMeta.threadId,
|
||||
targetThreadDisplayName: project.threadMeta.threadDisplayName,
|
||||
targetCodexThreadRef: project.threadMeta.codexThreadRef,
|
||||
targetCodexFolderRef: project.threadMeta.codexFolderRef,
|
||||
threadLifecycleAction: params.action,
|
||||
threadLifecycleReason: reason,
|
||||
});
|
||||
}
|
||||
|
||||
export async function queueInterThreadCollaborationTask(params: {
|
||||
sourceProjectId: string;
|
||||
targetProjectId: string;
|
||||
|
||||
Reference in New Issue
Block a user