AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
refactor(ai): simplify selection prompts and restrict writes
tianma-if8dd73b975b1d
diff --git a/apps/web/src/components/ai-sidebar/AiSidebar.tsx b/apps/web/src/components/ai-sidebar/AiSidebar.tsxindex 11aca06c..6b9befc4 100644--- a/apps/web/src/components/ai-sidebar/AiSidebar.tsx+++ b/apps/web/src/components/ai-sidebar/AiSidebar.tsx@@ -1087,7 +1087,7 @@ function AiSidebarSession({onStopReady.current = () => { void stop(); };}, [onStopReady, stop]);- const launch = useCallback(async (message: string, options?: { includeCurrentNote?: boolean }): Promise<string> => {+ const launch = useCallback(async (message: string, options?: { includeCurrentNote?: boolean; readOnly?: boolean }): Promise<string> => {const text = message.trim();if (!text || locked.current) throw new Error("busy");const useCurrentNote = options?.includeCurrentNote ?? includeCurrentNote;@@ -1141,6 +1141,7 @@ function AiSidebarSession({adapterId: adapter.id,...(adapter.path ? { path: adapter.path } : {}),prompt: text,+ ...(options?.readOnly ? { noteAccess: false } : {}),...((noteContext || transcript) ? { contextText: [noteContext, transcript].filter(Boolean).join("\n\n") } : {}),...(snapshot.length ? {attachments: snapshot.map((item) => ({@@ -1205,7 +1206,7 @@ function AiSidebarSession({message: text,useMemory,allowNotes: true,- allowWrites: true,+ allowWrites: !options?.readOnly,locale: companionLocale(i18n.resolvedLanguage),...(uploaded.length ? { attachmentIds: uploaded.map((item) => item.id) } : {}),...(focus ? { focus } : {}),@@ -1294,7 +1295,7 @@ function AiSidebarSession({const retranslateSelection = useCallback((language: SelectionAiLanguage) => {const message = selectionMessage("translate", language);if (!message || locked.current) return;- void launch(message).then((id) => {+ void launch(message, { readOnly: true }).then((id) => {rememberSelectionTurn(id, "translate");}).catch(() => undefined);}, [launch, rememberSelectionTurn, selectionMessage]);@@ -1311,7 +1312,7 @@ function AiSidebarSession({const message = selectionMessage(request.kind);if (!message) return;handledSelectionRequestId.current = request.id;- void launch(message).then((id) => {+ void launch(message, { readOnly: true }).then((id) => {rememberSelectionTurn(id, request.kind === "explain" ? "explain" : "translate");}).catch(() => undefined);}, [busy, launch, loading, rememberSelectionTurn, selectionMessage, selectionPin, selectionRequest]);diff --git a/apps/web/src/lib/selection-ai.test.mjs b/apps/web/src/lib/selection-ai.test.mjsindex e6d1b9a8..b6d3591a 100644--- a/apps/web/src/lib/selection-ai.test.mjs+++ b/apps/web/src/lib/selection-ai.test.mjs@@ -60,7 +60,7 @@ describe("selection user message", () => {test("stays inside the companion message limit for a full clip", () => {const message = selectionAiUserMessage({- instruction: "请把下面这段翻译成简体中文。如果原文已经是简体中文,就译成英文,并在第一行说明,空一行后再写译文。否则只写译文。不要修改笔记。",+ instruction: "请把下面这段翻译成简体中文。如果原文已经是简体中文,就译成英文,并在第一行说明,空一行后再写译文。否则只写译文。",notice: "只发送了选区的前 2000 个字符。",quote: "字".repeat(SELECTION_AI_SEND_LIMIT),});diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex 5e3baa7d..41d8f3d2 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -1329,9 +1329,9 @@ export const enUS = {translate: "Translate",ask: "Ask",actions: "Selected text",- explainPrompt: "Explain the ideas in the passage below in English. Do not change the note.",- translatePrompt: "Translate the passage below into English. If it is already English, say so on the first line, leave a blank line, then write the English text. Otherwise write only the translation. Do not change the note.",- translateLanguagePrompt: "Translate the passage below into {{language}}. Write only the translation, with no preamble. Do not change the note.",+ explainPrompt: "Explain the ideas in the passage below.",+ translatePrompt: "Translate the passage below into English. If it is already English, say so on the first line, leave a blank line, then write the English text. Otherwise write only the translation.",+ translateLanguagePrompt: "Translate the passage below into {{language}}. Write only the translation, with no preamble.",truncated: "Only the first {{count}} characters of the selection were sent.",dismiss: "Unpin",copy: "Copy",diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.tsindex cc598a60..d457fa7e 100644--- a/packages/shared/src/i18n/ja.ts+++ b/packages/shared/src/i18n/ja.ts@@ -1329,9 +1329,9 @@ export const ja = {translate: "翻訳",ask: "質問",actions: "選択した文字",- explainPrompt: "下の文章に出てくる概念を日本語でわかりやすく説明してください。ノートは変更しないでください。",- translatePrompt: "下の文章を日本語に翻訳してください。原文がすでに日本語なら英語に訳し、1行目でその旨を書き、空行のあとに訳文だけを書いてください。そうでなければ訳文だけを書いてください。ノートは変更しないでください。",- translateLanguagePrompt: "下の文章を{{language}}に翻訳してください。説明は書かず、訳文だけを書いてください。ノートは変更しないでください。",+ explainPrompt: "下の文章に出てくる概念をわかりやすく説明してください。",+ translatePrompt: "下の文章を日本語に翻訳してください。原文がすでに日本語なら英語に訳し、1行目でその旨を書き、空行のあとに訳文だけを書いてください。そうでなければ訳文だけを書いてください。",+ translateLanguagePrompt: "下の文章を{{language}}に翻訳してください。説明は書かず、訳文だけを書いてください。",truncated: "選択範囲の先頭 {{count}} 文字だけを送信しました。",dismiss: "ピン留めを外す",copy: "コピー",diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex e04d7f6d..ad2f393e 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -1329,9 +1329,9 @@ export const zhCN = {translate: "翻译",ask: "询问",actions: "对选中文字",- explainPrompt: "请解释下面这段文字里的概念,用简体中文写清楚。不要修改笔记。",- translatePrompt: "请把下面这段翻译成简体中文。如果原文已经是简体中文,就译成英文,并在第一行说明,空一行后再写译文。否则只写译文。不要修改笔记。",- translateLanguagePrompt: "请把下面这段翻译成{{language}}。只写译文,不要说明。不要修改笔记。",+ explainPrompt: "请解释下面这段文字里的概念。",+ translatePrompt: "请把下面这段翻译成简体中文。如果原文已经是简体中文,就译成英文,并在第一行说明,空一行后再写译文。否则只写译文。",+ translateLanguagePrompt: "请把下面这段翻译成{{language}}。只写译文,不要说明。",truncated: "只发送了选区的前 {{count}} 个字符。",dismiss: "取消钉选",copy: "复制",