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
client/AI chat: include multi-state checkboxes formatting instructions
Adorian Doran92151c694f36
diff --git a/apps/server/src/services/llm/providers/base_provider.spec.ts b/apps/server/src/services/llm/providers/base_provider.spec.tsindex 7b5229eb46..1c311bab1f 100644--- a/apps/server/src/services/llm/providers/base_provider.spec.ts+++ b/apps/server/src/services/llm/providers/base_provider.spec.ts@@ -304,6 +304,15 @@ describe("BaseProvider system prompt", () => {expect(prompt).toContain("Tables");expect(prompt).toContain("Collapsible blocks");});++ it("lists the workspace's custom task-state markers so the model can recognize them", () => {+ // No _taskStates container in the test becca → getTaskStates falls back to the defaults.+ const prompt = provider.callBuildSystemPrompt([], {})!;+ expect(prompt).toContain("Task lists");+ expect(prompt).toContain("`- [/]` — Doing");+ expect(prompt).toContain("`- [?]` — Maybe");+ expect(prompt).toContain("`- [-]` — Cancelled");+ });});describe("BaseProvider applyNoteHint", () => {diff --git a/apps/server/src/services/llm/providers/base_provider.ts b/apps/server/src/services/llm/providers/base_provider.tsindex 28c61da86f..618ffa5ac9 100644--- a/apps/server/src/services/llm/providers/base_provider.ts+++ b/apps/server/src/services/llm/providers/base_provider.ts@@ -3,12 +3,12 @@* tool assembly, model pricing, and title generation.*/-import type { LlmMessage, LlmMessagePart } from "@triliumnext/commons";+import { isAnchorState, type LlmMessage, type LlmMessagePart } from "@triliumnext/commons";import { decodeUtf8 } from "@triliumnext/core/src/services/utils/binary.js";import { type FilePart, generateText, type ImagePart, type LanguageModel, type ModelMessage, stepCountIs, streamText, type SystemModelMessage, type TextPart, type ToolSet } from "ai";import { dump } from "js-yaml";-import { becca, getLog } from "@triliumnext/core";+import { becca, getLog, task_states } from "@triliumnext/core";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";@@ -162,6 +162,21 @@ export function buildModelList(baseModels: Omit<ModelInfo, "costMultiplier">[]):return { models, pricing };}+/**+ * The task-list formatting hint, extended with the workspace's user-defined multi-state checkboxes so+ * the model recognizes their markers (e.g. `- [/]` = "Doing") in the user's notes and can produce them.+ * Falls back to just the native open/completed states when no custom states are configured.+ */+function buildTaskListHint(): string {+ const base = "**Task lists** — use `- [ ]` for an open task and `- [x]` for a completed one.";+ const custom = task_states.getTaskStates().filter(s => !isAnchorState(s.name) && !s.isHidden && s.markdownSymbol);+ if (custom.length === 0) {+ return base;+ }+ const lines = custom.map(s => `- \`- [${s.markdownSymbol}]\` — ${s.title}${s.isCompleted ? " (completed)" : ""}`);+ return `${base} This workspace also defines extra task states — recognize these markers in the user's notes, and use them when a task fits:\n${lines.join("\n")}`;+}+export abstract class BaseProvider implements LlmProvider {abstract name: string;@@ -255,7 +270,7 @@ export abstract class BaseProvider implements LlmProvider {+ `**Collapsible blocks** — use the standard HTML \`<details>\`/\`<summary>\` form; the \`<summary>\` is the always-visible title. Placed back-to-back with nothing between them, consecutive collapsible blocks are grouped into an accordion — handy when presenting several options or alternatives the user can expand one at a time. Example:\n`+ `<details><summary>Option A</summary>\nDetails about the first option.\n</details>\n<details><summary>Option B</summary>\nDetails about the second option.\n</details>\n\n`+ `**Footnotes** — use \`[^1]\` in text and \`[^1]: explanation\` at the bottom.\n\n`- + `**Task lists** — use \`- [ ]\` for unchecked and \`- [x]\` for checked items.`+ + buildTaskListHint());// The markdown formatting hints above are pushed unconditionally, so