Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(desktop): title Codex ACP sessions from user prompts

tianma-if46ba3d82c33c
diff --git a/apps/desktop/src/main/acp-host.mjs b/apps/desktop/src/main/acp-host.mjs
index d6662b69..4d1d2c97 100644
--- a/apps/desktop/src/main/acp-host.mjs
+++ b/apps/desktop/src/main/acp-host.mjs
@@ -339,11 +339,12 @@ const rejectAttachment = (attachment, reason) => ({
reason,
});
-export function buildPromptContent({ prompt, contextText, attachments, promptCapabilities = {} } = {}) {
+export function buildPromptContent({ prompt, contextText, attachments, promptCapabilities = {}, promptFirst = false } = {}) {
const blocks = [];
const rejectedAttachments = [];
+ if (promptFirst) blocks.push({ type: "text", text: typeof prompt === "string" ? prompt : "" });
if (typeof contextText === "string" && contextText.length > 0) blocks.push({ type: "text", text: contextText });
- blocks.push({ type: "text", text: typeof prompt === "string" ? prompt : "" });
+ if (!promptFirst) blocks.push({ type: "text", text: typeof prompt === "string" ? prompt : "" });
const list = Array.isArray(attachments) ? attachments : [];
list.forEach((attachment, index) => {
if (index >= MAX_ATTACHMENTS) {
@@ -936,9 +937,11 @@ export function createAcpHostRuntime(options = {}) {
contextText: input.contextText,
attachments: input.attachments,
promptCapabilities: connected.promptCapabilities,
+ // Codex derives its thread title from the start of the first user turn.
+ promptFirst: input.adapterId === "codex",
});
if (mcpBridge) {
- content.blocks.unshift({
+ content.blocks.splice(input.adapterId === "codex" ? 1 : 0, 0, {
type: "text",
text: "For EdgeEver note operations in this conversation, use only the session-provided MCP server named edgeever-current-workspace. It is connected to the account currently signed in to EdgeEver. Ignore any EdgeEver MCP server from your persistent configuration, which may target a different instance or account.",
});
diff --git a/apps/desktop/src/main/acp-host.test.mjs b/apps/desktop/src/main/acp-host.test.mjs
index c23e8e04..fc486b02 100644
--- a/apps/desktop/src/main/acp-host.test.mjs
+++ b/apps/desktop/src/main/acp-host.test.mjs
@@ -430,6 +430,14 @@ describe("ACP prompt blocks", () => {
expect(JSON.stringify(blocked.blocks)).not.toContain("resource_link");
});
+ test("puts a Codex user's request before context for a useful thread title", () => {
+ const content = buildPromptContent({ prompt: "分析资金往来", contextText: "Current note and earlier turns", promptFirst: true });
+ expect(content.blocks).toEqual([
+ { type: "text", text: "分析资金往来" },
+ { type: "text", text: "Current note and earlier turns" },
+ ]);
+ });
+
test("includes images and embedded PDFs without a filesystem path", () => {
const allowed = buildPromptContent({
prompt: "go",
@@ -675,6 +683,35 @@ describe("ACP stdio session", () => {
}
}, 15_000);
+ sessionTest("starts Codex prompts with the request while preserving workspace MCP guidance", async () => {
+ const directory = await mkdtemp(path.join(tmpdir(), "edgeever-codex-title-"));
+ const reportPath = path.join(directory, "report.json");
+ try {
+ const scriptPath = await writeFakeAgent(directory, {
+ reportPath,
+ secretPath: path.join(directory, "secret.txt"),
+ allowImage: false,
+ allowEmbedded: false,
+ hold: false,
+ });
+ const runtime = createAcpHostRuntime({
+ adapterManager: { get: (id) => id === "codex" ? { version: "test", command: { command: scriptPath, args: [] } } : null },
+ mcpAccess: () => ({ baseUrl: "https://notes.example", sessionToken: "login-secret" }),
+ startMcpBridge: () => ({ url: "http://127.0.0.1:12345", secret: "temporary-secret", close: async () => {} }),
+ });
+ const events = collector();
+ await runtime.prompt({ adapterId: "codex", prompt: "分析资金往来", contextText: "Current note and earlier turns" }, events.emit);
+ await events.waitFor((event) => event.type === "done");
+ const report = await readReport(reportPath);
+ expect(report.prompt[0]).toEqual({ type: "text", text: "分析资金往来" });
+ expect(report.prompt[1].text).toContain("edgeever-current-workspace");
+ expect(report.prompt[2]).toEqual({ type: "text", text: "Current note and earlier turns" });
+ expect(report.newSession.mcpServers[0].name).toBe("edgeever-current-workspace");
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+ }, 15_000);
+
sessionTest("keeps infographic prompts from granting note write access", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "edgeever-acp-infographic-"));
const reportPath = path.join(directory, "report.json");