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
docs(llm): add concrete per-scenario examples for script context
Elian Doran6fdcabe14ab0
diff --git a/apps/server/src/assets/llm/skills/backend_scripting.md b/apps/server/src/assets/llm/skills/backend_scripting.mdindex 07aa8ba67a..3b9ee127b6 100644--- a/apps/server/src/assets/llm/skills/backend_scripting.md+++ b/apps/server/src/assets/llm/skills/backend_scripting.md@@ -30,6 +30,18 @@ Note that most `api.*` methods (e.g. `api.getNote`, `api.searchForNotes`, `api.c- `api.currentNote` - note containing the source code currently executing (in C terms, `__FILE__`). Equal to `startNote` except inside child module notes loaded via `require()`. NOT the note open in the UI.- `api.originEntity` - entity whose event triggered this execution; `undefined` when the run was not event-driven (manual Execute button, `note.executeScript()`). For `~runOn*` relations see the table under "Events and triggers"; for scheduled scripts (`#run=hourly`/`#run=daily`) it is the script note itself; for `~searchScript` scripts it is the search note.+Concrete examples:++| Scenario | `startNote` | `currentNote` | `originEntity` |+|---|---|---|---|+| Execute button / `note.executeScript()` on "Job" | "Job" | "Job" (a child module note while its code runs) | `undefined` |+| Scheduled "Job" (`#run=backendStartup`/`hourly`/`daily`) | "Job" | "Job" (or module note) | "Job" (the script note itself) |+| Note "Diary" has `~runOnNoteContentChange` → script "OnChange" | "OnChange" | "OnChange" (or module note) | "Diary" (the changed note; a BAttribute/BBranch for attribute/branch events) |+| Custom request handler "Endpoint" (`#customRequestHandler`) | "Endpoint" | "Endpoint" (or module note) | `undefined` — the request is in `api.req` |+| `api.runOnBackend()` called from frontend widget "Clock" | "Clock" (the frontend's `startNote`, preserved) | the frontend note whose function was serialized (the frontend's `currentNote`) | the frontend's `originEntity` (a note) or `null` |++Note: `#customResourceProvider` notes never execute a script — the note's content is served directly as the HTTP response, so there is no `api` context at all. Only `#customRequestHandler` runs code.+### Note retrieval- `api.getNote(noteId)` - get note by ID- `api.searchForNotes(query, searchParams)` - search notes (returns array)diff --git a/apps/server/src/assets/llm/skills/frontend_scripting.md b/apps/server/src/assets/llm/skills/frontend_scripting.mdindex 0622538585..f34a7de945 100644--- a/apps/server/src/assets/llm/skills/frontend_scripting.md+++ b/apps/server/src/assets/llm/skills/frontend_scripting.md@@ -199,6 +199,15 @@ In JSX, use `import { method } from "trilium:api"`. In JavaScript (Trilium front- `currentNote` - note containing the source code currently executing. Equal to `startNote` except inside child module notes. NOT the note open in the UI — that is `getActiveContextNote()`.- `originEntity` - note whose event triggered this execution, or `null`. Usually `null` (scripts started by the user or the UI). It is set for render notes — the note being rendered, i.e. the one carrying the `~renderNote` relation — and for `api.runOnFrontend()` calls from the backend (the backend's `originEntity`, if it was a note).+Concrete examples:++| Scenario | `startNote` | `currentNote` | `originEntity` |+|---|---|---|---|+| Widget script "Clock" (`#widget`) | "Clock" | "Clock" (a child module note while its code runs) | `null` |+| Startup script (`#run=frontendStartup`) or manual Execute on "Setup" | "Setup" | "Setup" (or module note) | `null` |+| Render note "Stats" with `~renderNote` → JSX note "StatsComponent" | "StatsComponent" | "StatsComponent" (or module note) | "Stats" (the render note) |+| `api.runOnFrontend()` called from a backend script | the backend execution's `currentNote` | same | the backend's `originEntity` if it was a note, else `null` |+### Navigation & tabs- `activateNote(notePath)` - navigate to a note- `activateNewNote(notePath)` - navigate and wait for sync