feat: sync codex thread names

This commit is contained in:
AI Bot
2026-06-03 14:06:15 +08:00
parent 0bcdcbfb9d
commit cc31b0d836
11 changed files with 311 additions and 2 deletions

View File

@@ -655,6 +655,22 @@ rl.on("line", (line) => {
return;
}
if (message.method === "thread/name/set") {
send({
id: message.id,
result: {},
});
send({
method: "thread/name/updated",
params: {
threadId: message.params?.threadId,
threadName: message.params?.name,
internalNameMutationSecret: "thread-name-secret-should-not-leak",
},
});
return;
}
if (message.method === "thread/read") {
send({
id: message.id,

View File

@@ -1618,6 +1618,34 @@ test("codex app-server runner archives and unarchives a thread without starting
assert.doesNotMatch(serialized, /private unarchived thread name should not leak/);
});
test("codex app-server runner renames a thread without starting a normal turn", async () => {
const runnerConfig = getCodexAppServerRunnerConfig(process.env, {
codexAppServerEnabled: true,
codexAppServerCommand: process.execPath,
codexAppServerArgs: ["tests/fixtures/codex-app-server-runtime.mjs"],
codexAppServerWorkdir: repoRoot,
codexAppServerTimeoutMs: 5000,
});
const result = await executeCodexAppServerTask(runnerConfig, {
taskId: "task-thread-rename",
taskType: "conversation_reply",
intentCategory: "thread_rename",
targetCodexThreadRef: "019d-app-server-thread",
targetCodexFolderRef: repoRoot,
threadRenameName: "Boss 量产治理线程",
executionPrompt: "同步 Codex 线程名称。",
});
assert.equal(result.status, "completed");
assert.equal(result.threadId, "019d-app-server-thread");
assert.equal(result.turnControl, "rename");
assert.equal(result.threadRename?.name, "Boss 量产治理线程");
assert.match(result.replyBody, /已同步 Codex 线程名称/);
assert.equal(result.turnId, undefined);
assert.doesNotMatch(JSON.stringify(result), /thread-name-secret-should-not-leak/);
});
test("codex app-server runner stays disabled unless feature flag is explicit", () => {
const runnerConfig = getCodexAppServerRunnerConfig(process.env, {
codexAppServerCommand: process.execPath,

View File

@@ -0,0 +1,125 @@
import test from "node:test";
import assert from "node:assert/strict";
import os from "node:os";
import path from "node:path";
import { mkdtemp, rm } from "node:fs/promises";
import { NextRequest } from "next/server";
let runtimeRoot = "";
let postRoute: (typeof import("../src/app/api/v1/projects/[projectId]/rename/route"))["POST"];
let createAuthSession: (typeof import("../src/lib/boss-data"))["createAuthSession"];
let readState: (typeof import("../src/lib/boss-data"))["readState"];
let writeState: (typeof import("../src/lib/boss-data"))["writeState"];
let AUTH_SESSION_COOKIE = "";
async function setup() {
if (runtimeRoot) return;
runtimeRoot = await mkdtemp(path.join(os.tmpdir(), "boss-thread-rename-"));
process.env.BOSS_RUNTIME_ROOT = runtimeRoot;
process.env.BOSS_STATE_FILE = path.join(runtimeRoot, "boss-state.json");
const [route, data, auth] = await Promise.all([
import("../src/app/api/v1/projects/[projectId]/rename/route.ts"),
import("../src/lib/boss-data.ts"),
import("../src/lib/boss-auth.ts"),
]);
postRoute = route.POST;
createAuthSession = data.createAuthSession;
readState = data.readState;
writeState = data.writeState;
AUTH_SESSION_COOKIE = auth.AUTH_SESSION_COOKIE;
}
test.after(async () => {
if (runtimeRoot) {
await rm(runtimeRoot, { recursive: true, force: true });
}
});
test.beforeEach(async () => {
await setup();
await rm(runtimeRoot, { recursive: true, force: true });
});
async function createAuthedRequest(projectId: string, body: unknown) {
const session = await createAuthSession({
account: "krisolo",
role: "highest_admin",
displayName: "Boss 超级管理员",
loginMethod: "password",
});
return new NextRequest(`http://127.0.0.1:3000/api/v1/projects/${projectId}/rename`, {
method: "POST",
headers: {
"content-type": "application/json",
cookie: `${AUTH_SESSION_COOKIE}=${session.sessionToken}`,
},
body: JSON.stringify(body),
});
}
function buildThreadProject() {
return {
id: "rename-project",
name: "旧线程名",
pinned: false,
systemPinned: false,
deviceIds: ["mac-studio"],
preview: "",
updatedAt: "2026-06-03T11:30:00+08:00",
lastMessageAt: "2026-06-03T11:30:00+08:00",
isGroup: false,
threadMeta: {
projectId: "rename-project",
threadId: "rename-thread",
threadDisplayName: "旧线程名",
folderName: "boss",
codexFolderRef: "/Users/kris/code/boss",
codexThreadRef: "codex-rename-thread",
updatedAt: "2026-06-03T11:30:00+08:00",
},
groupMembers: [],
createdByAgent: false,
collaborationMode: "development" as const,
approvalState: "not_required" as const,
unreadCount: 0,
riskLevel: "low" as const,
messages: [],
goals: [],
versions: [],
};
}
test("POST /rename updates Boss thread name and queues Codex thread name sync", async () => {
const state = await readState();
const project = buildThreadProject();
state.projects = [
...state.projects.filter((item) => item.id === "master-agent"),
project,
];
await writeState(state);
const response = await postRoute(
await createAuthedRequest(project.id, {
mode: "thread",
name: "Boss 量产治理线程",
}),
{ params: Promise.resolve({ projectId: project.id }) },
);
const payload = await response.json();
assert.equal(response.status, 200);
assert.equal(payload.ok, true);
assert.equal(payload.project.name, "Boss 量产治理线程");
assert.equal(payload.project.threadMeta.threadDisplayName, "Boss 量产治理线程");
assert.equal(payload.codexThreadRenameTask.intentCategory, "thread_rename");
assert.equal(payload.codexThreadRenameTask.threadRenameName, "Boss 量产治理线程");
assert.equal(payload.codexThreadRenameTask.targetCodexThreadRef, "codex-rename-thread");
const persisted = (await readState()).masterAgentTasks.find(
(task) => task.taskId === payload.codexThreadRenameTask.taskId,
);
assert.equal(persisted?.status, "queued");
assert.equal(persisted?.intentCategory, "thread_rename");
assert.equal(persisted?.threadRenameName, "Boss 量产治理线程");
});