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
feat(llm): improve compliance in reading skills before creating scripts
Elian Dorande481672b9dc
diff --git a/apps/server/src/services/llm/providers/base_provider.ts b/apps/server/src/services/llm/providers/base_provider.tsindex cbac4f220e..8473e9ac8a 100644--- a/apps/server/src/services/llm/providers/base_provider.ts+++ b/apps/server/src/services/llm/providers/base_provider.ts@@ -10,7 +10,6 @@ import yaml from "js-yaml";import becca from "../../../becca/becca.js";import log from "../../log.js";-import { getSkillsSummary } from "../skills/index.js";import { getNoteMeta,SYSTEM_PROMPT_LIMITS } from "../tools/helpers.js";import { allToolRegistries } from "../tools/index.js";import type { LlmProvider, LlmProviderConfig, ModelInfo, ModelPricing, StreamResult } from "../types.js";@@ -182,7 +181,13 @@ export abstract class BaseProvider implements LlmProvider {// Note tools hintif (config.enableNoteTools) {parts.push(- `You have access to skills that provide specialized instructions. Load a skill with the load_skill tool before performing complex operations.\n\nAvailable skills:\n${getSkillsSummary()}`+ [+ `Before calling create_note (or any write tool) for Trilium-specific code or queries, you MUST call load_skill first — guessing the API produces broken code that doesn't run:`,+ `- Frontend code notes (mime "text/jsx" or "application/javascript;env=frontend") or render notes (type "render") → load_skill with name "frontend_scripting". Trilium uses Preact, NOT React, with imports from "trilium:preact".`,+ `- Backend code notes (mime "application/javascript;env=backend") → load_skill with name "backend_scripting".`,+ `- Search queries using boolean logic, attribute filters, relations, ordering, or regex → load_skill with name "search_syntax".`,+ `Loading is one cheap tool call. Skipping it wastes the user's time.`+ ].join("\n"));parts.push(`When referring to notes in your responses, use the wiki-link format [[noteId]] to create clickable internal links. Use the note ID (not the title) from tool results. The link will automatically display the note's title and icon, so don't repeat the title in your text. For example: "You can find more details in [[ZjSfLhzlqNY6]]" instead of "You can find more details in the Meeting Notes note ([[ZjSfLhzlqNY6]])".`diff --git a/apps/server/src/services/llm/skills/index.ts b/apps/server/src/services/llm/skills/index.tsindex a2ce5d97aa..13dd3fd098 100644--- a/apps/server/src/services/llm/skills/index.ts+++ b/apps/server/src/services/llm/skills/index.ts@@ -16,7 +16,10 @@ const SKILLS_DIR = join(resourceDir.RESOURCE_DIR, "llm", "skills");interface SkillDefinition {name: string;+ /** Long description shown in the load_skill tool's listing. */description: string;+ /** Short noun phrase for inline use in the system prompt. */+ summary: string;file: string;}@@ -24,16 +27,19 @@ const SKILLS: SkillDefinition[] = [{name: "search_syntax",description: "Trilium search query syntax reference — labels, relations, note properties, boolean logic, ordering, and more.",+ summary: "Trilium search query syntax",file: "search_syntax.md"},{name: "backend_scripting",description: "Backend (Node.js) scripting API — creating notes, handling events, accessing entities, database operations, and automation.",+ summary: "the backend Node.js scripting API",file: "backend_scripting.md"},{name: "frontend_scripting",description: "Frontend (browser) scripting API — UI widgets, navigation, dialogs, editor access, Preact/JSX components, and keyboard shortcuts.",+ summary: "the frontend browser scripting API",file: "frontend_scripting.md"}];@@ -47,12 +53,13 @@ function loadSkillContent(name: string): string | null {}/**- * Returns a summary of available skills for inclusion in the system prompt.+ * Returns an inline-prose summary of available skills for the system prompt.+ * Deliberately NOT a bulleted list — bullets with `- name: description` look+ * like a tool catalog to some models (notably Gemini), which then hallucinate+ * calls to the skill names as if they were tools.*/export function getSkillsSummary(): string {- return SKILLS- .map((s) => `- **${s.name}**: ${s.description}`)- .join("\n");+ return SKILLS.map((s) => `"${s.name}" for ${s.summary}`).join(", ");}export const skillTools = defineTools({