Skip to content

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

fix(ai): reuse translated note in replacement follow-ups

tianma-if40be9b571343
diff --git a/apps/api/src/companion-agent-tools.ts b/apps/api/src/companion-agent-tools.ts
index 142b46ad..c0a353c8 100644
--- a/apps/api/src/companion-agent-tools.ts
+++ b/apps/api/src/companion-agent-tools.ts
@@ -241,7 +241,7 @@ export function companionToolDefinitions(input: CompanionTurnInput): CompanionTo
},
{
name: "ask_user_question",
- description: "Ask the user 1-3 structured questions when you cannot proceed without a choice among existing notes or strategies. Do not use this to choose a notebook for a new note, diagram, infographic, or template. Do not use this to narrate writes you can already perform. Stop after calling it.",
+ description: "Ask the user 1-3 structured questions only when a necessary choice remains unresolved after checking the current request and recent conversation. Reuse a recent translation when the user asks to apply that translated content; do not ask for its language again. Do not use this to choose a notebook for a new note, diagram, infographic, or template. Do not use this to narrate writes you can already perform. Stop after calling it.",
inputSchema: ASK_USER_QUESTION_SCHEMA,
},
];
diff --git a/apps/api/src/companion-prepare.ts b/apps/api/src/companion-prepare.ts
index eae1117a..d4474347 100644
--- a/apps/api/src/companion-prepare.ts
+++ b/apps/api/src/companion-prepare.ts
@@ -28,6 +28,7 @@ Merging preserves source bodies/attachments and existing tags, moves sources to
Content changes use update_memo with the exact replacement Markdown. Prefer existing tags; remove tags only when requested.
Never operate on hypothetical IDs: confirm the prerequisite first, then use its real result.
For multi-step organization (≥3 steps), call todo_write first and keep it current. If you cannot choose among existing notes or strategies, call ask_user_question once and stop. Never ask which notebook should receive a new note, diagram, infographic, or template. Omit notebookId and it is saved in the inbox notebook (等待分类).
+Resolve follow-up references such as "the translated content" from the most recent relevant exchange in this thread before asking a question. If you just translated the open note and the user asks to replace its original with the translation, use that exact translated text as the replacement; do not translate it again or ask for a target language. An older translation of different text does not override the latest relevant translation. Read the current note before proposing an update_memo that changes only contentMarkdown. Ask only if the referenced result is missing or genuinely ambiguous.
Do not repeat writes already listed as applied in Historical operation receipts.
The user already sees each tool in a timeline. Do not narrate that you will search, read, or create, and do not write status updates such as "I will now" or "I have obtained". After tools finish, write only the user-facing answer: what you did, with note links.
Emptying the trash, public sharing, binary uploads, and system administration are not exposed. Do not claim otherwise.
diff --git a/apps/api/src/companion.test.mjs b/apps/api/src/companion.test.mjs
index dfc9b40a..3b510fff 100644
--- a/apps/api/src/companion.test.mjs
+++ b/apps/api/src/companion.test.mjs
@@ -105,6 +105,24 @@ describe("companion turn context", () => {
expect(parseCompanionMentionQuery("see @note", 9)).toEqual({ query: "note", start: 4, end: 9 });
expect(parseCompanionMentionQuery("hello", 5)).toBeNull();
});
+
+ test("a replacement follow-up retains the latest translation after an older, unrelated translation", () => {
+ const next = input({ allowNotes: true, useMemory: false, message: "用翻译后的内容替换原笔记。",
+ focus: { memoId: "memo_current", title: "Napoleon quote" } });
+ const base = { thread_id: next.threadId, status: "completed", memory_revision: 3, use_memory: 0,
+ allow_notes: 1, sources_json: "[]" };
+ const history = [
+ { ...base, id: "latest", message: "翻译一下当前笔记。", response: "拿破仑说:当你的敌人正在犯错时,千万不要打断他。" },
+ { ...base, id: "older", message: "请把下面这段翻译成日文:极客知识库", response: "ギーク知識ベース" },
+ ];
+ const messages = companionMessages(next, history, 3);
+ expect(messages.map(message => message.content)).toEqual([
+ history[1].message, history[1].response, history[0].message, history[0].response,
+ expect.stringContaining("用翻译后的内容替换原笔记。"),
+ ]);
+ expect(messages.at(-1).content).toContain("[note:memo_current]");
+ expect(COMPANION_INSTRUCTIONS).toContain("An older translation of different text does not override the latest relevant translation.");
+ });
});
describe("companion organization proposals", () => {