feat: sync codex thread metadata

This commit is contained in:
AI Bot
2026-06-03 14:38:15 +08:00
parent 0186ef7057
commit 5537fde7a6
11 changed files with 518 additions and 1 deletions

View File

@@ -78,6 +78,10 @@ function isThreadGoalSyncTask(task) {
return task?.intentCategory === "thread_goal_sync" || task?.taskType === "thread_goal_sync";
}
function isThreadMetadataSyncTask(task) {
return task?.intentCategory === "thread_metadata_sync" || task?.taskType === "thread_metadata_sync";
}
function resolveThreadRenameName(task) {
return trimToDefined(task?.threadRenameName || task?.threadName || task?.name);
}
@@ -103,6 +107,26 @@ function resolveThreadGoalTokenBudget(task) {
return Number.isFinite(numeric) && numeric > 0 ? Math.floor(numeric) : undefined;
}
function resolveThreadMetadataGitInfo(task) {
const input = task?.threadMetadataGitInfo || task?.gitInfo;
if (!input || typeof input !== "object" || Array.isArray(input)) {
return undefined;
}
const gitInfo = {};
for (const key of ["sha", "branch", "originUrl"]) {
const value = input[key];
if (value === null) {
gitInfo[key] = null;
} else if (typeof value === "string") {
const trimmed = value.trim();
if (trimmed) {
gitInfo[key] = trimmed;
}
}
}
return Object.keys(gitInfo).length > 0 ? gitInfo : undefined;
}
function resolveThreadLifecycleAction(task) {
if (
task?.threadLifecycleAction === "archive" ||
@@ -3177,6 +3201,34 @@ export async function executeCodexAppServerTask(runnerConfig, task) {
};
}
if (isThreadMetadataSyncTask(task)) {
const metadataThreadId = targetThreadRef;
const gitInfo = resolveThreadMetadataGitInfo(task);
if (!metadataThreadId) {
throw new Error("CODEX_APP_SERVER_THREAD_ID_MISSING");
}
if (!gitInfo) {
throw new Error("CODEX_APP_SERVER_THREAD_METADATA_GIT_INFO_MISSING");
}
await request("thread/metadata/update", {
threadId: metadataThreadId,
gitInfo,
});
return {
status: "completed",
replyBody: "已同步 Codex 线程 Git 元数据。",
threadId: metadataThreadId,
turnControl: "metadata_sync",
threadMetadata: {
gitInfo,
},
cwd,
transport: runnerConfig.transport,
executionProgress: progressCollector.snapshot(),
canFallbackToCli: false,
};
}
if (isThreadRenameTask(task)) {
const renameThreadId = targetThreadRef;
const name = resolveThreadRenameName(task);