feat: sync codex thread goals
This commit is contained in:
@@ -74,10 +74,35 @@ function isThreadRenameTask(task) {
|
||||
return task?.intentCategory === "thread_rename" || task?.taskType === "thread_rename";
|
||||
}
|
||||
|
||||
function isThreadGoalSyncTask(task) {
|
||||
return task?.intentCategory === "thread_goal_sync" || task?.taskType === "thread_goal_sync";
|
||||
}
|
||||
|
||||
function resolveThreadRenameName(task) {
|
||||
return trimToDefined(task?.threadRenameName || task?.threadName || task?.name);
|
||||
}
|
||||
|
||||
function resolveThreadGoalObjective(task) {
|
||||
return trimToDefined(task?.threadGoalObjective || task?.goalObjective || task?.objective);
|
||||
}
|
||||
|
||||
function resolveThreadGoalStatus(task) {
|
||||
const status = trimToDefined(task?.threadGoalStatus || task?.goalStatus);
|
||||
return status === "active" ||
|
||||
status === "paused" ||
|
||||
status === "blocked" ||
|
||||
status === "usageLimited" ||
|
||||
status === "budgetLimited" ||
|
||||
status === "complete"
|
||||
? status
|
||||
: "active";
|
||||
}
|
||||
|
||||
function resolveThreadGoalTokenBudget(task) {
|
||||
const numeric = Number(task?.threadGoalTokenBudget ?? task?.goalTokenBudget);
|
||||
return Number.isFinite(numeric) && numeric > 0 ? Math.floor(numeric) : undefined;
|
||||
}
|
||||
|
||||
function resolveThreadLifecycleAction(task) {
|
||||
if (
|
||||
task?.threadLifecycleAction === "archive" ||
|
||||
@@ -3118,6 +3143,40 @@ export async function executeCodexAppServerTask(runnerConfig, task) {
|
||||
});
|
||||
notify("initialized", {});
|
||||
|
||||
if (isThreadGoalSyncTask(task)) {
|
||||
const goalThreadId = targetThreadRef;
|
||||
const objective = resolveThreadGoalObjective(task);
|
||||
const status = resolveThreadGoalStatus(task);
|
||||
const tokenBudget = resolveThreadGoalTokenBudget(task);
|
||||
if (!goalThreadId) {
|
||||
throw new Error("CODEX_APP_SERVER_THREAD_ID_MISSING");
|
||||
}
|
||||
if (!objective) {
|
||||
throw new Error("CODEX_APP_SERVER_THREAD_GOAL_OBJECTIVE_MISSING");
|
||||
}
|
||||
await request("thread/goal/set", {
|
||||
threadId: goalThreadId,
|
||||
objective,
|
||||
status,
|
||||
tokenBudget,
|
||||
});
|
||||
return {
|
||||
status: "completed",
|
||||
replyBody: `已同步 Codex 线程目标:${objective}。`,
|
||||
threadId: goalThreadId,
|
||||
turnControl: "goal_sync",
|
||||
threadGoal: {
|
||||
objective,
|
||||
status,
|
||||
...(tokenBudget ? { tokenBudget } : {}),
|
||||
},
|
||||
cwd,
|
||||
transport: runnerConfig.transport,
|
||||
executionProgress: progressCollector.snapshot(),
|
||||
canFallbackToCli: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (isThreadRenameTask(task)) {
|
||||
const renameThreadId = targetThreadRef;
|
||||
const name = resolveThreadRenameName(task);
|
||||
|
||||
Reference in New Issue
Block a user