apple
Create, read, search, and edit notes in the macOS Notes app. macOS only. The first call asks for Automation permission with a system dialog. If nobody answers the dialog, the call fails after 30 seconds.
import { createNote } from "std::notes/apple"
node main() {
const result = createNote("Findings", "## Summary\n\n- one\n- two")
print(result)
}Notes are addressed by id
Two notes in the same folder can share a title, so a title is not an address. Every read and edit takes the note's id, which comes from listNotes or searchNotes:
import { searchNotes, appendToNote } from "std::notes/apple"
node main() {
const found = searchNotes("Q3 planning")
if (found is success(notes)) {
appendToNote(notes[0].id, "\n## Update\n\nShipped.")
}
}createNote returns the note it made, including its id, so create-then-append needs no search.
Bodies are Markdown going in, plain text coming out
createNote and appendToNote take Markdown and convert it to the HTML that Notes stores. readNote returns plain text. That makes a read-then-write round trip lossy: reading strips the formatting, and writing the text back would flatten the note. Use appendToNote instead of reading, editing, and rewriting a note yourself.
Confining an agent to one folder
Bind folder on tools before handing them to an agent. Search and list calls then stay within that folder. Reads, appends, and deletes fail if the note belongs to another folder. The model cannot see or change the bound folder, because a bound parameter is removed from the tool's schema:
import { listNotes, readNote } from "std::notes/apple"
node main() {
const reader = readNote.partial(folder: "Work").rename("readWorkNote")
const lister = listNotes.partial(folder: "Work").rename("listWorkNotes")
llm("Summarise my Work notes", { tools: [lister, reader] })
}These tools only list or read notes in Work. The model may pass any note id it likes; anything outside Work fails closed.
Deciding with a policy
Each operation raises its own effect, so a policy can approve reads and reject deletes:
{
"std::notes::read": [
{ "match": { "folder": "Work" }, "action": "approve" },
{ "action": "reject" }
],
"std::notes::delete": [{ "action": "reject" }]
}readNote, appendToNote, and deleteNote look the note up before raising their interrupt, so the payload carries the note's real title, folder, and account even when the call passed only an id. The rule above therefore matches a bare readNote(id) for a note that lives in Work.
Only those three calls populate account. createNote, searchNotes, and listNotes send it as an empty string, and an empty string matches no glob. A rule that matches on account never applies to them, so match on folder instead.
The NotesRead, NotesWrite, and Notes sets in std::effectSets cover the same split for constraining a whole node.
Locked notes
A note locked with a password cannot be read or edited, and this module will not try. Calls against a locked note fail before their interrupt is raised, with a message naming the note.
Deleting is recoverable
deleteNote moves a note to Recently Deleted, where it stays for about 30 days. listFolders returns that folder like any other.
For an Obsidian vault, use std::fs to read and write its Markdown files.
Types
Folder
A folder in Notes, including the number of notes it contains.
/** A folder in Notes, including the number of notes it contains. */
export type Folder = {
id: string;
name: string;
noteCount: number
}(source)
Note
Note metadata from a listing, search, or write, without the body.
/** Note metadata from a listing, search, or write, without the body. */
export type Note = {
id: string;
title: string;
folder: string;
account: string;
modified: string;
passwordProtected: boolean
}(source)
NoteContent
A note including its content, as plaintext.
/** A note including its content, as plaintext. */
export type NoteContent = {
id: string;
title: string;
folder: string;
account: string;
body: string;
modified: string
}(source)
Effects
std::notes::create
@always(folder)
effect std::notes::create {
account: string;
folder: string;
title: string;
folderCreated: boolean
}(source)
std::notes::append
@always(folder)
effect std::notes::append {
account: string;
folder: string;
title: string;
id: string
}(source)
std::notes::read
@always(folder)
effect std::notes::read {
account: string;
folder: string;
title: string;
id: string
}(source)
std::notes::search
@always(folder)
effect std::notes::search {
account: string;
folder: string;
query: string
}(source)
std::notes::list
@always(folder)
effect std::notes::list {
account: string;
folder: string
}(source)
std::notes::delete
@always(folder)
effect std::notes::delete {
account: string;
folder: string;
title: string;
id: string
}(source)
Functions
createNote
createNote(
title: string,
body: string,
folder: string = "Agency Notes",
): Result<Note> raises <std::notes::create>Create a note in the macOS Notes app.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| title | string | ||
| body | string | The note's content as Markdown. | |
| folder | string | "Agency Notes" | The folder to use, creating it if missing. |
Returns: Result<Note>
Throws: std::notes::create
Needs: subprocess
(source)
appendToNote
appendToNote(
id: string,
body: string,
folder: string | null = null,
): Result<Note> raises <std::notes::append>Append Markdown to an existing note.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| id | string | A note ID from a listing, search, or create result. | |
| body | string | Markdown content to add to the existing body. | |
| folder | string | null | null | If supplied, fail unless the note belongs to this folder. |
Returns: Result<Note>
Throws: std::notes::append
Needs: subprocess
(source)
readNote
readNote(
id: string,
folder: string | null = null,
): Result<NoteContent> raises <std::notes::read>Read a note's contents as plain text.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| id | string | A note ID from a listing, search, or create result. | |
| folder | string | null | null | If supplied, fail unless the note belongs to this folder. |
Returns: Result<NoteContent>
Throws: std::notes::read
Needs: subprocess
(source)
searchNotes
searchNotes(
query: string,
folder: string | null = null,
): Result<Note[]> raises <std::notes::search>Search notes by their text and return matching notes' metadata, without their contents.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| query | string | The text to search for | |
| folder | string | null | null | If given, only search this folder |
Returns: Result<Note[]>
Throws: std::notes::search
Needs: subprocess
(source)
listNotes
listNotes(
folder: string | null = null,
): Result<Note[]> raises <std::notes::list>List notes' metadata, without their contents.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| folder | string | null | null | If given, only list this folder |
Returns: Result<Note[]>
Throws: std::notes::list
Needs: subprocess
(source)
listFolders
listFolders(): Result<Folder[]> raises <std::notes::list>List the folders in the Notes app, with a count of the notes in each.
Returns: Result<Folder[]>
Throws: std::notes::list
Needs: subprocess
(source)
deleteNote
deleteNote(
id: string,
folder: string | null = null,
): Result<null> raises <std::notes::delete>Move a note to Recently Deleted, where it remains for about 30 days.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| id | string | A note ID from a listing, search, or create result. | |
| folder | string | null | null | If supplied, fail unless the note belongs to this folder. |
Returns: Result<null>
Throws: std::notes::delete
Needs: subprocess
(source)