Skip to content

Commit b3dc687

Browse files
Updated documentation
1 parent 8c2f118 commit b3dc687

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

docs/user/features/templates.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ async function createNote({ trigger, foam, resolver, foamDate }) {
8686
// if you need a variable you can use the resolver
8787
// const title = await resolver.resolveFromName('FOAM_TITLE');
8888

89-
console.log(
90-
'Creating note for today: ' + formattedDay,
91-
JSON.stringify(trigger)
92-
);
89+
console.log('Creating note for today: ' + formattedDay, JSON.stringify(trigger));
9390

9491
let content = `# Daily Note - ${formattedDay}
9592
@@ -208,21 +205,23 @@ return {
208205

209206
### Security and limitations
210207

211-
JavaScript templates run in a best-effort secured environment:
208+
JavaScript templates execute real JavaScript. Foam guards where and when
209+
they run, but the in-process sandbox is **not** a security boundary — a
210+
malicious template can escape it. Trust controls are the real protection:
212211

213-
- ✅ Can only run from trusted VS Code workspaces
214-
- ✅ Can access Foam workspace and utilities
215-
- ✅ Can use standard JavaScript features
216-
- ✅ Have a 30-second execution timeout
217-
- ❌ Cannot access the file system directly
218-
- ❌ Cannot make network requests
219-
- ❌ Cannot access Node.js modules
212+
- ✅ Only run in **trusted** VS Code workspaces
213+
- ✅ When using the `foam` CLI, only run with the `--trust` flag
214+
-**Never run under the MCP server.** `foam mcp` and the
215+
`create_resource` tool refuse `.js` templates with an
216+
`untrusted_workspace` error
217+
- ⏱ 10-second execution timeout
220218

221-
This increases the chances that templates stay safe while still being powerful enough for complex logic.
219+
> ⚠️ **Treat a `new-note.js` like a script you'd execute by hand.
220+
> ** Only use JS templates from workspaces whose contributors you trust.
222221
223-
STILL - PLEASE BE AWARE YOU ARE EXECUTING CODE ON YOUR MACHINE. THIS SANDBOX IS NOT MEANT TO BE THE ULTIMATE SECURITY SOLUTION.
224-
225-
**YOU MUST TRUST THE REPO CONTRIBUTORS**
222+
If you don't need the power of arbitrary JavaScript, prefer a Markdown
223+
template — those run everywhere (CLI, MCP, web extension) and have no
224+
trust requirement.
226225

227226
## Markdown templates
228227

@@ -240,15 +239,15 @@ Markdown templates can use all the variables available in [VS Code Snippets](htt
240239

241240
In addition, you can also use variables provided by Foam:
242241

243-
| Name | Description |
244-
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
245-
| `FOAM_SELECTED_TEXT` | Foam will fill it with selected text when creating a new note, if any text is selected. Selected text will be replaced with a wikilink to the new |
246-
| `FOAM_TITLE` | The title of the note. If used, Foam will prompt you to enter a title for the note. |
247-
| `FOAM_TITLE_SAFE` | The title of the note in a file system safe format. If used, Foam will prompt you to enter a title for the note unless `FOAM_TITLE` has already caused the prompt. |
248-
| `FOAM_SLUG` | The sluggified title of the note (using the default github slug method). If used, Foam will prompt you to enter a title for the note unless `FOAM_TITLE` has already caused the prompt. |
249-
| `FOAM_CURRENT_DIR` | The current editor's directory path. Resolves to the directory of the currently active file, or falls back to workspace root if no editor is active. Useful for creating notes in the current directory context. |
242+
| Name | Description |
243+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
244+
| `FOAM_SELECTED_TEXT` | Foam will fill it with selected text when creating a new note, if any text is selected. Selected text will be replaced with a wikilink to the new |
245+
| `FOAM_TITLE` | The title of the note. If used, Foam will prompt you to enter a title for the note. |
246+
| `FOAM_TITLE_SAFE` | The title of the note in a file system safe format. If used, Foam will prompt you to enter a title for the note unless `FOAM_TITLE` has already caused the prompt. |
247+
| `FOAM_SLUG` | The sluggified title of the note (using the default github slug method). If used, Foam will prompt you to enter a title for the note unless `FOAM_TITLE` has already caused the prompt. |
248+
| `FOAM_CURRENT_DIR` | The current editor's directory path. Resolves to the directory of the currently active file, or falls back to workspace root if no editor is active. Useful for creating notes in the current directory context. |
250249
| `FOAM_DATE_FORMAT` | The Foam date formatted using a [dayjs format string](https://day.js.org/docs/en/display/format). Defaults to ISO 8601 with local timezone offset (e.g. `2026-03-12T22:06:55+01:00`). Use as `$FOAM_DATE_FORMAT` for the default, or `${FOAM_DATE_FORMAT:YYYY-MM-DD}` for a custom format. |
251-
| `FOAM_DATE_*` | `FOAM_DATE_YEAR`, `FOAM_DATE_MONTH`, `FOAM_DATE_WEEK`, `FOAM_DATE_DAY_ISO` etc. Foam-specific versions of [VS Code's datetime snippet variables](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables). Prefer these versions over VS Code's. |
250+
| `FOAM_DATE_*` | `FOAM_DATE_YEAR`, `FOAM_DATE_MONTH`, `FOAM_DATE_WEEK`, `FOAM_DATE_DAY_ISO` etc. Foam-specific versions of [VS Code's datetime snippet variables](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables). Prefer these versions over VS Code's. |
252251

253252
### `FOAM_DATE_FORMAT` variable
254253

packages/foam-cli/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,16 @@ Show, create, move, or delete a note.
107107

108108
```bash
109109
foam note show my-note
110-
foam note show my-note --links # include incoming/outgoing links
111-
foam note show my-note --content # print raw file content
112-
foam note id my-note # print Foam identifier
110+
foam note show my-note --links # include incoming/outgoing links
111+
foam note show my-note --content # print raw file content
112+
foam note id my-note # print Foam identifier
113113
foam note create --title "My Note"
114114
foam note create --title "My Note" --dir subdir --property status=draft
115+
foam note create --title "My Note" --trust # allow JS templates to execute
115116
foam note move my-note --to new-name.md
116-
foam note delete my-note # moves to .foam/trash/ (prompts for confirmation)
117-
foam note delete my-note --force # skip confirmation
118-
foam note delete my-note --permanent # delete permanently
117+
foam note delete my-note # moves to .foam/trash/ (prompts for confirmation)
118+
foam note delete my-note --force # skip confirmation
119+
foam note delete my-note --permanent # delete permanently
119120
```
120121

121122
### `outline`

0 commit comments

Comments
 (0)