Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(llm): let an absent note-tools flag mean the same on every provider
Elian Doranb0fccd960629
diff --git a/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.spec.ts b/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.spec.tsindex 923820f922..7080faeda9 100644--- a/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.spec.ts+++ b/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.spec.ts@@ -154,6 +154,15 @@ describe("buildAiAssistantStream", () => {];expect(await runOnce()).toEqual({ provider: "openai", providerId: "cfg-openai" });});++ // The assistant rewrites what it was handed and needs nothing from the note tools. It asks for+ // none by saying nothing about them, which every provider reads as off — see the two agent+ // providers' own specs, which pin that down on the side where it used to go the other way.+ it("asks for no note tools", async () => {+ storedProviders = [{ id: "cfg-openai", provider: "openai", selectedModels: [{ id: "gpt-5" }] }];++ expect(await runOnce()).not.toHaveProperty("enableNoteTools");+ });});describe("the Markdown pipeline", () => {diff --git a/apps/client/src/widgets/type_widgets/text/ai_model_picker.ts b/apps/client/src/widgets/type_widgets/text/ai_model_picker.tsindex 58f2459819..bc80afe100 100644--- a/apps/client/src/widgets/type_widgets/text/ai_model_picker.ts+++ b/apps/client/src/widgets/type_widgets/text/ai_model_picker.ts@@ -65,6 +65,9 @@ export function buildAiModelPicker(): AiQuickActionFooter[] {* `packages/trilium-core/src/services/llm/chat.ts`), which would fail outright for an* OpenAI-only setup and silently use the wrong provider for a mixed one. Naming the provider* without a model instead lets the server resolve that provider's own default.+ *+ * Nothing is said about the note tools, which is how the assistant asks for none of them: a+ * request that does not mention them does not get them, on every provider.*/export function pickModel(): LlmChatConfig {const { models, groups } = readSelectedModels();diff --git a/apps/server/src/services/llm/providers/claude_agent.spec.ts b/apps/server/src/services/llm/providers/claude_agent.spec.tsindex 1c2301f23f..b9ba9f463f 100644--- a/apps/server/src/services/llm/providers/claude_agent.spec.ts+++ b/apps/server/src/services/llm/providers/claude_agent.spec.ts@@ -357,7 +357,7 @@ describe("ClaudeAgentProvider.chatChunks", () => {it("wires Trilium's in-process MCP server instance and disables built-in tools", async () => {scriptAgent([successResult()]);const provider = new ClaudeAgentProvider();- await collect(provider.chatChunks([{ role: "user", content: "hi" }], {}));+ await collect(provider.chatChunks([{ role: "user", content: "hi" }], { enableNoteTools: true }));const options = queryMock.mock.calls[0][0].options;expect(options.tools).toEqual([]);@@ -455,6 +455,21 @@ describe("ClaudeAgentProvider.chatChunks", () => {expect(options.systemPrompt).toContain("do not have access to the user's notes");});+ // A caller with no opinion gets no note access, the same reading `base_provider` gives an+ // absent flag — so what a request leaves unsaid means one thing across every provider. This+ // used to go the other way here, handing the whole tree to anything that simply did not ask.+ it("omits note-tools wiring when the chat says nothing about them", async () => {+ scriptAgent([successResult()]);+ const provider = new ClaudeAgentProvider();+ await collect(provider.chatChunks([{ role: "user", content: "hi" }], {}));++ const options = queryMock.mock.calls[0][0].options;+ expect(options.mcpServers).toBeUndefined();+ expect(createMcpServerMock).not.toHaveBeenCalled();+ expect(options.allowedTools).toEqual([]);+ expect(options.systemPrompt).not.toContain("load_skill");+ });+it("logs a diagnostic when the in-process MCP bridge fails to connect", async () => {scriptAgent([{ type: "system", subtype: "init", session_id: "s", mcp_servers: [{ name: "trilium", status: "failed" }] },diff --git a/apps/server/src/services/llm/providers/claude_agent.ts b/apps/server/src/services/llm/providers/claude_agent.tsindex 010d58d484..590882a5fc 100644--- a/apps/server/src/services/llm/providers/claude_agent.ts+++ b/apps/server/src/services/llm/providers/claude_agent.ts@@ -646,9 +646,15 @@ export class ClaudeAgentProvider implements LlmProvider {* Whether the chat requested note tools. With in-process MCP the tools have no* external dependency, so this is simply the chat toggle — the tool wiring and* the system prompt both gate on it so they never disagree.+ *+ * A config that does not mention them does not get them. That reading matches+ * `base_provider`, which every AI-SDK provider inherits, so what a request+ * leaves unsaid means the same thing whichever provider answers it; the+ * previous `!== false` handed the whole note tree to any caller that simply+ * had no opinion.*/function areNoteToolsAvailable(config: Pick<LlmProviderConfig, "enableNoteTools">): boolean {- return config.enableNoteTools !== false;+ return !!config.enableNoteTools;}/**diff --git a/apps/server/src/services/llm/providers/copilot_agent.spec.ts b/apps/server/src/services/llm/providers/copilot_agent.spec.tsindex 9937556663..b9c9d142f3 100644--- a/apps/server/src/services/llm/providers/copilot_agent.spec.ts+++ b/apps/server/src/services/llm/providers/copilot_agent.spec.ts@@ -325,6 +325,18 @@ describe("CopilotAgentProvider.chatChunks", () => {expect(mcpEndpointMock).not.toHaveBeenCalled();});+ // A caller with no opinion gets no note access, the same reading `base_provider` gives an+ // absent flag — so what a request leaves unsaid means one thing across every provider. This+ // used to go the other way here, handing the whole tree to anything that simply did not ask.+ it("omits MCP servers when the chat says nothing about note tools", async () => {+ const provider = new CopilotAgentProvider();+ await collect(provider.chatChunks([userMessage("hi")], {}));++ const sessionNew = FakeAcpClient.current?.requests.find(r => r.method === "session/new");+ expect(sessionNew?.params).toMatchObject({ mcpServers: [] });+ expect(mcpEndpointMock).not.toHaveBeenCalled();+ });+it("spawns the CLI with the note-tool allow-list and built-in tool denials", async () => {const startSpy = vi.spyOn(FakeAcpClient, "start");const provider = new CopilotAgentProvider();diff --git a/apps/server/src/services/llm/providers/copilot_agent.ts b/apps/server/src/services/llm/providers/copilot_agent.tsindex 1967a87cb0..44be682213 100644--- a/apps/server/src/services/llm/providers/copilot_agent.ts+++ b/apps/server/src/services/llm/providers/copilot_agent.ts@@ -304,7 +304,10 @@ export class CopilotAgentProvider implements LlmProvider {const stored = config.chatNoteId ? sessionsByChatNote.get(config.chatNoteId) : undefined;const resume = stored && stored.transcriptHash === historyHash ? stored.sessionId : undefined;- const noteToolsEnabled = config.enableNoteTools !== false;+ // A config that does not mention the note tools does not get them, as `base_provider` reads+ // it and as the AI-SDK providers therefore behave — what a request leaves unsaid has to+ // mean the same thing whichever provider answers it.+ const noteToolsEnabled = !!config.enableNoteTools;const model = config.model || "auto";// Queue between the ACP notification callback and this generator: the