Documentation
¶
Index ¶
- Constants
- Variables
- func BodyHasLocalAsset(body string) bool
- func BuildExcerpt(body string) string
- func ExtractAssetEmbeds(body string) []string
- func ExtractTags(body string) []string
- func ExtractWikilinks(body string) []string
- func IsAtomicWriteTempPath(p string) bool
- func IsValidFolder(f NoteFolder) bool
- func NormalizeSystemFolderPaths(raw map[string]string) map[string]string
- func SafeDestination(root, rel string) (string, error)
- func SafeJoin(root, rel string) (string, error)
- func ToPosix(p string) string
- type AssetMeta
- type ChangeEvent
- type CustomTemplateFile
- type DailyNotesSettings
- type DateNotePatternSettings
- type DeletedAsset
- type DemoTourResult
- type FileLocationMode
- type FileLocationSetting
- type FolderColorID
- type FolderEntry
- type FolderIconID
- type HarperSettings
- type ImportedAsset
- type MonthlyNotesSettings
- type NoteComment
- type NoteContent
- type NoteFolder
- type NoteMeta
- type Options
- type ParseTasksOptions
- type PreparedWorkflowRun
- type PrimaryNotesLocation
- type ShareLocationMode
- type ShareLocationSetting
- type Task
- type TasksSettings
- type TemplateFolderSettings
- type TextSearchCapabilities
- type TextSearchMatch
- type TypstPreambleSettings
- type Vault
- func (v *Vault) ApplyPreparedWorkflow(input PreparedWorkflowRun) (WorkflowRunReceipt, error)
- func (v *Vault) ArchiveNote(rel string) (NoteMeta, error)
- func (v *Vault) AssetAbsPath(rel string) (string, error)
- func (v *Vault) Close()
- func (v *Vault) CreateExcalidraw(folder NoteFolder, title, subpath string) (NoteMeta, error)
- func (v *Vault) CreateFolder(folder NoteFolder, subpath string) error
- func (v *Vault) CreateNote(folder NoteFolder, title, subpath string) (NoteMeta, error)
- func (v *Vault) DeleteAsset(rel string) (DeletedAsset, error)
- func (v *Vault) DeleteFolder(folder NoteFolder, subpath string) error
- func (v *Vault) DeleteNote(rel string) error
- func (v *Vault) DeleteTemplate(sourcePath string) error
- func (v *Vault) DeleteWorkflow(sourcePath string) error
- func (v *Vault) DeleteWorkflowRuns(workflowID string) (int, error)
- func (v *Vault) DuplicateAsset(rel string) (AssetMeta, error)
- func (v *Vault) DuplicateFolder(folder NoteFolder, subpath string) (string, error)
- func (v *Vault) DuplicateNote(rel string) (NoteMeta, error)
- func (v *Vault) EmptyDeletedAssets() error
- func (v *Vault) EmptyTrash() error
- func (v *Vault) EnsureLayout() error
- func (v *Vault) GenerateDemoTour() (DemoTourResult, error)
- func (v *Vault) GetSettings() (VaultSettings, error)
- func (v *Vault) HasAssetsDir() bool
- func (v *Vault) ImportAsset(notePath, filename string, body io.Reader) (ImportedAsset, error)
- func (v *Vault) Info() VaultInfo
- func (v *Vault) ListAssets() ([]AssetMeta, error)
- func (v *Vault) ListDeletedAssets() ([]DeletedAsset, error)
- func (v *Vault) ListFolders() ([]FolderEntry, error)
- func (v *Vault) ListNotes() ([]NoteMeta, error)
- func (v *Vault) ListTemplates() ([]CustomTemplateFile, error)
- func (v *Vault) ListWorkflowRuns() ([]WorkflowRunSummary, error)
- func (v *Vault) ListWorkflows() ([]WorkflowFile, error)
- func (v *Vault) MoveAsset(rel, targetDir string) (AssetMeta, error)
- func (v *Vault) MoveNote(rel string, target NoteFolder, targetSubpath string) (NoteMeta, error)
- func (v *Vault) MoveToTrash(rel string) (NoteMeta, error)
- func (v *Vault) NoteSize(rel string) (int64, error)
- func (v *Vault) PurgeDeletedAsset(undoToken string) error
- func (v *Vault) ReadNote(rel string) (NoteContent, error)
- func (v *Vault) ReadNoteComments(rel string) ([]NoteComment, error)
- func (v *Vault) ReadTemplate(sourcePath string) (string, error)
- func (v *Vault) RemoveDemoTour() (DemoTourResult, error)
- func (v *Vault) RenameAsset(rel, nextName string) (AssetMeta, error)
- func (v *Vault) RenameFolder(folder NoteFolder, oldSub, newSub string) (string, error)
- func (v *Vault) RenameNote(rel, nextTitle string) (NoteMeta, error)
- func (v *Vault) RestoreDeletedAsset(deleted DeletedAsset) (AssetMeta, error)
- func (v *Vault) RestoreFromTrash(rel string) (NoteMeta, error)
- func (v *Vault) Root() string
- func (v *Vault) ScanTasks() ([]Task, error)
- func (v *Vault) ScanTasksForPath(rel string) ([]Task, error)
- func (v *Vault) ScanTasksForPathWith(rel string, opts ParseTasksOptions) ([]Task, error)
- func (v *Vault) ScanTasksWith(opts ParseTasksOptions) ([]Task, error)
- func (v *Vault) SearchCapabilities() TextSearchCapabilities
- func (v *Vault) SearchText(query string) ([]TextSearchMatch, error)
- func (v *Vault) SearchTextUpTo(query string, limit int) ([]TextSearchMatch, error)
- func (v *Vault) SetSettings(next VaultSettings) (VaultSettings, error)
- func (v *Vault) UnarchiveNote(rel string) (NoteMeta, error)
- func (v *Vault) UndoWorkflowRun(runID string) (WorkflowUndoResult, error)
- func (v *Vault) WriteNote(rel, body string) (NoteMeta, error)
- func (v *Vault) WriteNoteComments(rel string, comments []NoteComment) ([]NoteComment, error)
- func (v *Vault) WriteTemplate(input WriteTemplateInput) (CustomTemplateFile, error)
- func (v *Vault) WriteWorkflow(input WriteWorkflowInput) (WorkflowFile, error)
- type VaultInfo
- type VaultSettings
- type WeeklyNotesSettings
- type WorkflowFile
- type WorkflowRollback
- type WorkflowRunFileChange
- type WorkflowRunMove
- type WorkflowRunReceipt
- type WorkflowRunSummary
- type WorkflowUndoResult
- type WriteTemplateInput
- type WriteWorkflowInput
Constants ¶
const ( FolderInbox NoteFolder = "inbox" FolderQuick NoteFolder = "quick" FolderArchive NoteFolder = "archive" FolderTrash NoteFolder = "trash" PrimaryNotesInbox PrimaryNotesLocation = "inbox" PrimaryNotesRoot PrimaryNotesLocation = "root" DefaultDailyNotesDirectory = "Daily Notes" DefaultDailyNoteTitlePattern = "yyyy-MM-dd" DefaultDailyNoteLocale = "system" DefaultWeeklyNotesDirectory = "Weekly Notes" DefaultWeeklyNoteTitlePattern = "yyyy-'W'ww" DefaultWeeklyNoteLocale = "system" DefaultMonthlyNotesDirectory = "Monthly Notes" DefaultMonthlyNoteTitlePattern = "yyyy-MM" DefaultMonthlyNoteLocale = "system" )
const ( // AssetsDir is the canonical top-level folder for assets; attachements/_assets // are recognized legacy dirs. Asset migration runs on the desktop (#185). AssetsDir = "assets" PrimaryAttachmentsDir = "attachements" )
const ( DefaultTextSearchLimit = 200 MaxTextSearchLimit = 50000 )
DefaultTextSearchLimit is how many matches a search returns unless told otherwise, and MaxTextSearchLimit the most it may be told.
const DefaultTypstPreambleFolder = "typst"
DefaultTypstPreambleFolder is the folder name used when the vault says nothing.
Variables ¶
var ( ErrInvalidWorkflow = errors.New("invalid workflow request") ErrWorkflowConflict = errors.New("workflow plan is stale") )
var AllFolders = []NoteFolder{FolderInbox, FolderQuick, FolderArchive, FolderTrash}
var ErrAssetTooLarge = errors.New("asset exceeds maximum size")
ErrAssetTooLarge is returned when an asset upload exceeds the vault's MaxAssetBytes limit.
var ErrInvalidTemplate = errors.New("invalid template request")
var ErrIsDirectory = errors.New("path is a directory, not a file")
ErrIsDirectory is returned when a caller asks to read a directory as a file, which a client does by accident whenever it treats a `.base` database folder as a note. It is classified here, from a stat the read already performs, rather than from the errno the read returns: Unix answers EISDIR but Windows answers ERROR_INVALID_FUNCTION ("Incorrect function"), so an errno test makes the same request a 400 on one platform and a 500 on another.
var ErrPathEscape = errors.New("path escapes vault root")
var ErrThroughSymlink = errors.New("path goes through a symbolic link")
ErrThroughSymlink is returned for a destination that goes through a symbolic link. See SafeDestination.
Functions ¶
func BodyHasLocalAsset ¶
BodyHasLocalAsset is the same cheap heuristic as the TS version.
func BuildExcerpt ¶
BuildExcerpt makes a short plaintext preview from markdown.
func ExtractAssetEmbeds ¶
ExtractAssetEmbeds mirrors extractAssetEmbeds in apps/desktop/src/main/vault.ts. Keep target order and URI decoding equivalent so both hosts report the same usage.
func ExtractTags ¶
ExtractTags returns unique tags from first-class frontmatter `tags` and inline #tags.
func ExtractWikilinks ¶
ExtractWikilinks returns unique [[wikilink]] targets, ignoring code.
func IsAtomicWriteTempPath ¶
IsAtomicWriteTempPath reports whether p is one of those scratch files. The watcher drops them: a temp file appearing and vanishing is not a vault change, and a client that heard about it would rebuild its asset list on every keystroke-driven note save.
func IsValidFolder ¶
func IsValidFolder(f NoteFolder) bool
func NormalizeSystemFolderPaths ¶
NormalizeSystemFolderPaths validates a raw systemFolderPaths map the way the vault settings reader does. Exported so callers that read vault.json without going through GetSettings (the watcher) classify against the same paths the vault itself uses. Mirrors normalizeSystemFolderPaths in packages/shared-domain/src/system-folder-paths.ts.
func SafeDestination ¶
SafeDestination is SafeJoin for a place a client names to create or move something into. On top of what SafeJoin refuses, every part of `rel` that already exists must be a real directory, so a link never takes a new file or folder somewhere other than the path it was asked for, even a place inside the vault.
The listings skip links to folders, so a client sees a linked folder as a path with nothing there. `zn mcp --allow-path Projects` checks a destination against those listings, and could be walked into a hidden folder by a link at Projects/inner if the write followed it.
Routes that take a note's own path keep using SafeJoin: read, write, rename, duplicate and delete. A link to a note file is a supported way to file a note in two places, and a client limiting itself to part of a vault only sends paths it found in the listings. `root` itself is not examined, so a vault or a system folder that is a link keeps working. The assets folder is the exception (ImportAsset), since its name is not one a client chooses.
A regular file on the way is left to the operation that follows, which fails with ENOTDIR. Anything else is refused, which covers Windows junctions, which Lstat reports as neither a link nor a directory.
func SafeJoin ¶
SafeJoin cleans a user-supplied relative POSIX path and joins it onto `root`, refusing anything that resolves outside `root`. Any existing component of the joined path that is a symbolic link is resolved and must still resolve to a location inside `root`; otherwise ErrPathEscape is returned. Components that do not yet exist (write-create case) are left alone — they cannot be symlinks until they're created.
The returned path is in the same namespace as `root` (i.e. rooted at the abs form of the caller's root, not the canonical form), so callers can still strip the root prefix to get a stable relative path.
Types ¶
type AssetMeta ¶
type AssetMeta struct {
Path string `json:"path"`
Name string `json:"name"`
Kind string `json:"kind"`
SiblingOrder int `json:"siblingOrder"`
Size int64 `json:"size"`
UpdatedAt int64 `json:"updatedAt"`
// Symlink marks an asset listed from a link rather than a file, as on
// NoteMeta.
Symlink bool `json:"symlink,omitempty"`
}
AssetMeta — mirrors shared/ipc.ts AssetMeta.
type ChangeEvent ¶
type ChangeEvent struct {
Kind string `json:"kind"` // "add" | "change" | "unlink"
Path string `json:"path"`
Folder NoteFolder `json:"folder"`
Scope string `json:"scope,omitempty"`
}
ChangeEvent — mirrors shared/ipc.ts VaultChangeEvent.
type CustomTemplateFile ¶
CustomTemplateFile matches bridge-contract's CustomTemplateFile.
type DailyNotesSettings ¶
type DailyNotesSettings struct {
Enabled bool `json:"enabled"`
Directory string `json:"directory"`
TitlePattern string `json:"titlePattern,omitempty"`
Locale string `json:"locale,omitempty"`
LegacyPatterns []DateNotePatternSettings `json:"legacyPatterns,omitempty"`
TemplateID string `json:"templateId,omitempty"`
// Pointers so an absent field round-trips as "unset" (the TS client applies
// the real default — true for TasksDueOnNoteDate, false for rollover). These
// drive purely client-side behavior; the server only persists them.
TasksDueOnNoteDate *bool `json:"tasksDueOnNoteDate,omitempty"`
RolloverUnfinishedTasks *bool `json:"rolloverUnfinishedTasks,omitempty"`
}
type DateNotePatternSettings ¶
type DeletedAsset ¶
type DeletedAsset struct {
Path string `json:"path"`
Name string `json:"name"`
UndoToken string `json:"undoToken"`
DeletedAt string `json:"deletedAt,omitempty"`
}
DeletedAsset — mirrors shared/ipc.ts DeletedAsset. The meta file it is read from (.zn-deleted.json) is shared with the desktop app: a vault can be served remotely today and opened locally tomorrow, so the field set must stay byte-compatible with desktop vault.ts.
type DemoTourResult ¶
type DemoTourResult struct {
NotePaths []string `json:"notePaths"`
AssetPaths []string `json:"assetPaths"`
}
DemoTourResult mirrors shared/ipc.ts VaultDemoTourResult.
type FileLocationMode ¶
type FileLocationMode string
FileLocationMode mirrors shared/ipc.ts FileLocationMode: where a new drawing / database / task file is created.
const ( FileLocationPrimary FileLocationMode = "primary" FileLocationActiveNote FileLocationMode = "active-note" FileLocationFolder FileLocationMode = "folder" )
type FileLocationSetting ¶
type FileLocationSetting struct {
Mode FileLocationMode `json:"mode"`
Folder string `json:"folder,omitempty"`
}
FileLocationSetting mirrors shared/ipc.ts FileLocationSetting. Persisted so the web client's Drawings / Databases / Tasks location choices survive a round-trip instead of being silently dropped by the settings struct (#446).
type FolderColorID ¶
type FolderColorID string
type FolderEntry ¶
type FolderEntry struct {
Folder NoteFolder `json:"folder"`
Subpath string `json:"subpath"`
SiblingOrder int `json:"siblingOrder"`
}
FolderEntry — mirrors shared/ipc.ts FolderEntry.
type FolderIconID ¶
type FolderIconID string
type HarperSettings ¶
type HarperSettings struct {
Words []string `json:"words"`
IgnoredLints []string `json:"ignoredLints"`
}
HarperSettings mirrors shared/ipc.ts VaultSettings.harper. IgnoredLints are Harper's unsigned 64-bit context hashes carried as digit strings, because the browser clients cannot hold them as numbers without rounding.
type ImportedAsset ¶
type ImportedAsset struct {
Name string `json:"name"`
Path string `json:"path"`
Markdown string `json:"markdown"`
Kind string `json:"kind"`
}
ImportedAsset — mirrors shared/ipc.ts ImportedAsset.
type MonthlyNotesSettings ¶
type MonthlyNotesSettings struct {
Enabled bool `json:"enabled"`
Directory string `json:"directory"`
TitlePattern string `json:"titlePattern,omitempty"`
Locale string `json:"locale,omitempty"`
LegacyPatterns []DateNotePatternSettings `json:"legacyPatterns,omitempty"`
TemplateID string `json:"templateId,omitempty"`
}
type NoteComment ¶
type NoteComment struct {
ID string `json:"id"`
NotePath string `json:"notePath"`
AnchorStart int `json:"anchorStart"`
AnchorEnd int `json:"anchorEnd"`
AnchorText string `json:"anchorText"`
Body string `json:"body"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
ResolvedAt *int64 `json:"resolvedAt"`
// Author is who wrote it: empty for the vault's owner, an assistant's
// name otherwise. ParentID threads a reply under a top-level comment.
// Both mirror shared-domain/note-comments.ts (#738).
Author string `json:"author,omitempty"`
ParentID string `json:"parentId,omitempty"`
}
NoteComment — sidecar annotation/comment data for a note.
type NoteContent ¶
NoteContent extends NoteMeta with the raw body.
type NoteFolder ¶
type NoteFolder string
func FolderForRelativePath ¶
func FolderForRelativePath(rel string) (NoteFolder, bool)
func FolderForRelativePathWithSettings ¶
func FolderForRelativePathWithSettings(rel string, paths map[string]string) (NoteFolder, bool)
func SystemFolderForDirName ¶
func SystemFolderForDirName(name string, paths map[string]string) (NoteFolder, bool)
SystemFolderForDirName returns the system folder that owns a top-level directory name, or false when the name belongs to no system folder (an ordinary user folder, an assets dir, anything else).
This is THE classification rule for a path's first segment, because only the RESOLVED name of each folder counts: with inbox remapped to `01 - Entry`, `01 - Entry/` is the inbox and a directory literally named `inbox/` is just a user folder. Case-insensitive, since macOS and Windows preserve whatever case the directory was created with (#186). Mirrors systemFolderForDirName in packages/shared-domain/src/system-folder-paths.ts.
type NoteMeta ¶
type NoteMeta struct {
Path string `json:"path"`
Title string `json:"title"`
Folder NoteFolder `json:"folder"`
SiblingOrder int `json:"siblingOrder"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
Size int64 `json:"size"`
Tags []string `json:"tags"`
Wikilinks []string `json:"wikilinks"`
AssetEmbeds []string `json:"assetEmbeds"`
HasAttachments bool `json:"hasAttachments"`
Excerpt string `json:"excerpt"`
// Symlink marks a note listed from a link rather than a file, in listings
// only. The content belongs to whatever the link names, which may be a
// folder a scoped client (`zn mcp --allow-path`) must not reach.
Symlink bool `json:"symlink,omitempty"`
}
NoteMeta — vault-relative note metadata. Mirrors shared/ipc.ts NoteMeta.
type Options ¶
Options tunes vault filesystem permissions and limits. Zero values fall back to a private-by-default profile (0o600 / 0o700, 50 MiB).
type ParseTasksOptions ¶
type ParseTasksOptions struct {
// IncludeExcluded scans past the note-level frontmatter `tasks:` opt-out:
// the GET /tasks?includeExcluded=1 escape hatch. Default listing never sets
// it.
IncludeExcluded bool
}
ParseTasksOptions controls scanning past task exclusions (#458).
type PreparedWorkflowRun ¶
type PreparedWorkflowRun struct {
WorkflowID string `json:"workflowId"`
Ops []json.RawMessage `json:"ops"`
Applied int `json:"applied"`
Irreversible int `json:"irreversible"`
Changes []WorkflowRunFileChange `json:"changes"`
// Moves is absent from a client that predates it, which then gets what it
// always got: the Markdown moved, the comments left behind.
Moves []WorkflowRunMove `json:"moves,omitempty"`
}
type PrimaryNotesLocation ¶
type PrimaryNotesLocation string
type ShareLocationMode ¶
type ShareLocationMode string
ShareLocationMode mirrors shared/ipc.ts ShareLocationMode: where a share from the macOS Share menu is filed. No active-note: the app files a share with no note in view.
const ( )
type ShareLocationSetting ¶
type ShareLocationSetting struct {
// folder mode.
Folder string
}
ShareLocationSetting mirrors shared/ipc.ts ShareLocationSetting. The desktop app reads it from the server to file a share into a server vault, so it is a first-class field for the #446/#379 round-trip rule. Its JSON hooks and normalizer live in share_location.go.
func (ShareLocationSetting) MarshalJSON ¶
func (s ShareLocationSetting) MarshalJSON() ([]byte, error)
MarshalJSON writes what the TypeScript normalizer returns: `folder` in folder mode only, and there always, an empty one included, so the server stores and serves the same bytes for a folder still being typed.
func (*ShareLocationSetting) UnmarshalJSON ¶
func (s *ShareLocationSetting) UnmarshalJSON(data []byte) error
UnmarshalJSON reads the setting the way the TypeScript normalizer reads an `unknown`: a value that is not an object, a mode that is not a string and a folder that is not a string each count as absent. A plain struct decode would fail the whole vault.json on any of them, and every request that reads settings with it. Keys match exactly, as a JavaScript property read does, not case-insensitively as Go's struct decoding does.
type Task ¶
type Task struct {
ID string `json:"id"`
// ParentID is the id of the task this one is a subtask of
// (ZenNotes/zennotes#1028): the checkbox whose list item this line's list
// item sits directly inside, or the note's file task (path + "#task") for
// a checkbox in a task note that no other checkbox owns. Empty on a
// top-level task. Mirrors VaultTask.parentId; the web Kanban board folds
// subtasks into their parent's card from it.
ParentID string `json:"parentId,omitempty"`
SourcePath string `json:"sourcePath"`
NoteTitle string `json:"noteTitle"`
NoteFolder NoteFolder `json:"noteFolder"`
LineNumber int `json:"lineNumber"`
TaskIndex int `json:"taskIndex"`
RawText string `json:"rawText"`
Content string `json:"content"`
Checked bool `json:"checked"`
// Cancelled is true for a `[-]` task — intentionally abandoned (#450).
Cancelled bool `json:"cancelled,omitempty"`
// InProgress is true for a `[/]` task: started, not finished (#512).
// Unlike Checked/Cancelled it is still open work, so it keeps its place
// in the active buckets on every surface.
InProgress bool `json:"inProgress,omitempty"`
// Forwarded is true for a `[>]` record: the task moved to another note
// and a live copy exists there (#316). Without it, a web client read
// carried tasks as open twice, record and copy alike (#611 review).
Forwarded bool `json:"forwarded,omitempty"`
Due string `json:"due,omitempty"`
Priority string `json:"priority,omitempty"`
Waiting bool `json:"waiting"`
// Fields contains inline @key:value metadata (or a file task's explicit
// frontmatter status) so remote Kanban boards group tasks exactly like the
// desktop parser (#643). Status is the effective status: Fields["status"]
// when set, and "open" for a file task whose frontmatter says nothing,
// which deliberately stays out of Fields (#672).
Fields map[string]string `json:"fields"`
Status string `json:"status,omitempty"`
Tags []string `json:"tags"`
// Kind is how the task is stored: "file" for a whole-note task
// (TaskNotes-style, tagged `task` with metadata in frontmatter) or
// empty/"inline" for a classic `- [ ]` checkbox line. The renderer
// branches its toggle logic on this.
Kind string `json:"kind,omitempty"`
// Scheduled and CompletedDate are file-task-only frontmatter dates
// (YYYY-MM-DD). They mirror the TS VaultTask shape.
Scheduled string `json:"scheduled,omitempty"`
CompletedDate string `json:"completedDate,omitempty"`
}
Task — mirrors shared/tasks.ts VaultTask.
func ParseTasks ¶
func ParseTasks(path, title string, folder NoteFolder, body string) []Task
ParseTasks walks a markdown body and returns every checkbox task.
func ParseTasksWith ¶
func ParseTasksWith(path, title string, folder NoteFolder, body string, opts ParseTasksOptions) []Task
ParseTasksWith is ParseTasks honoring options. The frontmatter `tasks:` gate lives here rather than in the parse helpers (the TS mirrors gate inside parseTaskFile/parseTasksFromBody because their callers invoke the two separately); the semantics are identical: `tasks: false`/`off` emits nothing and wins over `tags: [task]`, `tasks: note` keeps only the file task, anything else emits everything.
type TasksSettings ¶
type TasksSettings struct {
// ExcludedFolders lists vault-relative directory paths (as they exist on
// disk) whose notes never feed the Tasks surfaces.
ExcludedFolders []string `json:"excludedFolders,omitempty"`
// IncludedFolders, the Task folders (#962), narrows Tasks to the notes
// inside the folders it lists. Empty means the whole vault, and
// ExcludedFolders still applies inside them.
IncludedFolders []string `json:"includedFolders,omitempty"`
}
TasksSettings mirrors shared/ipc.ts VaultSettings.tasks (#458, #962). A new field here also needs normalizeTasksSettings and cloneSettings, or GetSettings hands it back stripped.
type TemplateFolderSettings ¶
type TemplateFolderSettings struct {
// Folder is a vault-relative directory path as it exists on disk, such as
// `Templates`. Every note inside it, at any depth, is a template, kept out
// of the task scan and of text search.
Folder string `json:"folder,omitempty"`
}
TemplateFolderSettings mirrors shared/ipc.ts VaultSettings.templates (#1024). A new field here also needs normalizeTemplateFolderSettings, cloneSettings and UnmarshalJSON, or GetSettings hands it back stripped.
func (*TemplateFolderSettings) UnmarshalJSON ¶
func (s *TemplateFolderSettings) UnmarshalJSON(data []byte) error
UnmarshalJSON reads `templates` the way the TypeScript normalizer reads an `unknown`: a value that is not an object, or a folder that is not a string, counts as absent instead of failing the whole vault.json (and every request that reads settings with it). Keys match exactly, as a JavaScript property read does, not case-insensitively as Go's struct decoding does.
type TextSearchCapabilities ¶
TextSearchCapabilities — mirrors shared/ipc.ts VaultTextSearchCapabilities.
type TextSearchMatch ¶
type TextSearchMatch struct {
Path string `json:"path"`
Title string `json:"title"`
Folder NoteFolder `json:"folder"`
LineNumber int `json:"lineNumber"`
Offset int `json:"offset"`
LineText string `json:"lineText"`
}
TextSearchMatch — mirrors shared/ipc.ts VaultTextSearchMatch.
type TypstPreambleSettings ¶
type TypstPreambleSettings struct {
// Folder names the directory whose notes are Typst preambles, matched at
// any depth. Empty means the default, `typst`.
Folder string `json:"folder,omitempty"`
}
TypstPreambleSettings mirrors shared/ipc.ts VaultSettings.typstPreambles (#562).
type Vault ¶
type Vault struct {
// contains filtered or unexported fields
}
Vault encapsulates all operations against a filesystem vault root. It is concurrency-safe at the public-method level; internally most ops do a short RW-lock dance around mutating operations.
func (*Vault) ApplyPreparedWorkflow ¶
func (v *Vault) ApplyPreparedWorkflow(input PreparedWorkflowRun) (WorkflowRunReceipt, error)
func (*Vault) Close ¶
func (v *Vault) Close()
Close waits for background writers such as the delayed note-meta cache snapshot. The vault remains usable afterwards; Close only drains.
func (*Vault) CreateExcalidraw ¶
func (v *Vault) CreateExcalidraw(folder NoteFolder, title, subpath string) (NoteMeta, error)
CreateExcalidraw writes a new empty `.excalidraw` drawing under folder/subpath and returns its meta. Mirrors CreateNote but seeds an empty Excalidraw scene.
func (*Vault) CreateFolder ¶
func (v *Vault) CreateFolder(folder NoteFolder, subpath string) error
func (*Vault) CreateNote ¶
func (v *Vault) CreateNote(folder NoteFolder, title, subpath string) (NoteMeta, error)
func (*Vault) DeleteAsset ¶
func (v *Vault) DeleteAsset(rel string) (DeletedAsset, error)
DeleteAsset moves an asset into the deleted-assets store and returns the restore handle, mirroring the desktop deleteAsset.
func (*Vault) DeleteFolder ¶
func (v *Vault) DeleteFolder(folder NoteFolder, subpath string) error
func (*Vault) DeleteNote ¶
func (*Vault) DeleteTemplate ¶
DeleteTemplate removes a template; a file that is already gone is a success, as it is on the desktop.
func (*Vault) DeleteWorkflow ¶
func (*Vault) DeleteWorkflowRuns ¶
func (*Vault) DuplicateAsset ¶
DuplicateAsset copies an asset next to itself as "<name> copy<ext>", mirroring the desktop duplicateAsset.
func (*Vault) DuplicateFolder ¶
func (v *Vault) DuplicateFolder(folder NoteFolder, subpath string) (string, error)
func (*Vault) EmptyDeletedAssets ¶
EmptyDeletedAssets permanently deletes every entry in the store.
func (*Vault) EmptyTrash ¶
func (*Vault) EnsureLayout ¶
EnsureLayout creates the four top-level folders and seeds a welcome note if the vault is empty. Matches src/main/vault.ts ensureVaultLayout.
func (*Vault) GenerateDemoTour ¶
func (v *Vault) GenerateDemoTour() (DemoTourResult, error)
GenerateDemoTour seeds the vault with the built-in tour notes and the demo attachment. Existing files are overwritten, and a tour seeded under the older note names is replaced rather than left beside the new one.
func (*Vault) GetSettings ¶
func (v *Vault) GetSettings() (VaultSettings, error)
GetSettings reads the vault settings, reparsing vault.json only when the file on disk has actually changed. Every folderRoot() call consults the settings, so a single client refresh asked for them about five times and each ask meant a ReadDir of the root plus a read and a JSON parse of vault.json.
The cache is keyed on the file's mtime and size, and one open handle serves both the stat and the read so the key always describes the bytes that were parsed. A stat of the path followed by a read of the path would leave a window where the file is swapped in between (js/file-system-race). This mirrors getVaultSettings in apps/desktop/src/main/vault.ts.
func (*Vault) HasAssetsDir ¶
func (*Vault) ImportAsset ¶
ImportAsset writes raw bytes into the unified assets/ folder and returns the vault-relative markdown snippet to embed. The destination mirrors the desktop importFiles/importPastedImage (#377): uploads used to land at the vault root, which in Vault Root mode dumped them right next to the notes. notePath is no longer read: the link is vault-relative now, so where the note lives does not change what gets written. It stays in the signature because the HTTP handler and clients still send it.
func (*Vault) Info ¶
Info describes the vault as the clients name it: its display name from vault.json when it has one (#692), else the folder name. Reads through the settings cache, so it costs one stat once the file has been parsed.
func (*Vault) ListAssets ¶
ListAssets walks the attachments directory.
func (*Vault) ListDeletedAssets ¶
func (v *Vault) ListDeletedAssets() ([]DeletedAsset, error)
ListDeletedAssets enumerates restorable entries in the deleted-assets store, newest first. Entries without metadata are skipped, exactly like the desktop (pre-2.11 deletes have none).
func (*Vault) ListFolders ¶
func (v *Vault) ListFolders() ([]FolderEntry, error)
ListFolders enumerates every non-root subdirectory under each top-level folder.
func (*Vault) ListTemplates ¶
func (v *Vault) ListTemplates() ([]CustomTemplateFile, error)
ListTemplates returns every custom template with its raw bytes. A vault without a templates directory has no templates rather than an error, and an unreadable file is skipped, as the desktop does.
func (*Vault) ListWorkflowRuns ¶
func (v *Vault) ListWorkflowRuns() ([]WorkflowRunSummary, error)
func (*Vault) ListWorkflows ¶
func (v *Vault) ListWorkflows() ([]WorkflowFile, error)
func (*Vault) MoveAsset ¶
MoveAsset moves an asset file into targetDir (vault-relative; empty means the unified assets/ folder), mirroring the desktop moveAsset. The filename is made unique in the destination. (#379) Every note that referenced the asset is then re-targeted to its new location, like RenameAsset. (#785)
func (*Vault) PurgeDeletedAsset ¶
PurgeDeletedAsset permanently deletes one entry from the store.
func (*Vault) ReadNoteComments ¶
func (v *Vault) ReadNoteComments(rel string) ([]NoteComment, error)
func (*Vault) RemoveDemoTour ¶
func (v *Vault) RemoveDemoTour() (DemoTourResult, error)
RemoveDemoTour deletes the demo notes + asset if they exist, including notes still under the older names. Also removes empty parent directories under inbox/demo.
func (*Vault) RenameAsset ¶
RenameAsset renames an asset file in place (same directory), mirroring the desktop renameAsset. It refuses internal files and markdown notes, and handles a case-only rename on case-insensitive filesystems. (#379) Every note that referenced the asset is then rewritten to its new name, the way RenameNote handles inbound wikilinks. (#785)
func (*Vault) RenameFolder ¶
func (v *Vault) RenameFolder(folder NoteFolder, oldSub, newSub string) (string, error)
func (*Vault) RestoreDeletedAsset ¶
func (v *Vault) RestoreDeletedAsset(deleted DeletedAsset) (AssetMeta, error)
RestoreDeletedAsset moves an asset back to its original folder, deduping the filename if something new took its place, mirroring the desktop. Only the token comes from the caller; the stored .zn-deleted.json decides what gets restored and where. Trusting a client-supplied name here once let a request naming the metadata file itself "restore" that file and then destroy the real asset bytes with the trash dir cleanup.
func (*Vault) ScanTasksForPathWith ¶
func (v *Vault) ScanTasksForPathWith(rel string, opts ParseTasksOptions) ([]Task, error)
ScanTasksForPathWith is ScanTasksForPath honoring options. IncludeExcluded scans past the excluded-folders list and the frontmatter `tasks:` opt-out (never the trash gate): the remote task-toggle flow re-parses through here, and an explicitly-named task id is an explicit ask.
func (*Vault) ScanTasksWith ¶
func (v *Vault) ScanTasksWith(opts ParseTasksOptions) ([]Task, error)
ScanTasksWith is ScanTasks honoring options: IncludeExcluded scans past the vault-level folder lists (the excluded folders and the Task folders, #962) and the note-level frontmatter `tasks:` opt-out (#458).
func (*Vault) SearchCapabilities ¶
func (v *Vault) SearchCapabilities() TextSearchCapabilities
func (*Vault) SearchText ¶
func (v *Vault) SearchText(query string) ([]TextSearchMatch, error)
func (*Vault) SearchTextUpTo ¶
func (v *Vault) SearchTextUpTo(query string, limit int) ([]TextSearchMatch, error)
SearchTextUpTo is SearchText returning at most limit matches.
func (*Vault) SetSettings ¶
func (v *Vault) SetSettings(next VaultSettings) (VaultSettings, error)
func (*Vault) UndoWorkflowRun ¶
func (v *Vault) UndoWorkflowRun(runID string) (WorkflowUndoResult, error)
func (*Vault) WriteNoteComments ¶
func (v *Vault) WriteNoteComments(rel string, comments []NoteComment) ([]NoteComment, error)
func (*Vault) WriteTemplate ¶
func (v *Vault) WriteTemplate(input WriteTemplateInput) (CustomTemplateFile, error)
WriteTemplate saves a template under a slug derived from the request, and removes the file it replaces when an edit changed the slug. The previous path is validated before anything is written, so a bad one cannot leave a stray new file behind.
func (*Vault) WriteWorkflow ¶
func (v *Vault) WriteWorkflow(input WriteWorkflowInput) (WorkflowFile, error)
type VaultInfo ¶
type VaultInfo struct {
Root string `json:"root"`
Name string `json:"name"`
// LinkedSystemFolders are the system folders that are, or sit under, a
// symbolic link, as vault-relative paths. They work as usual, but what is in
// one may belong to another folder, which a client limiting itself to part
// of a vault cannot see from the listings or a read. Always sent, empty when
// there are none, so a client can tell "none" from a server that does not say.
LinkedSystemFolders []string `json:"linkedSystemFolders"`
}
VaultInfo — mirrors shared/ipc.ts VaultInfo.
type VaultSettings ¶
type VaultSettings struct {
// DisplayName is what the clients call the vault (#692): the sidebar
// header, the vault switcher, the title bar. Mirrors shared/ipc.ts
// VaultSettings.displayName; absent means the folder's own name. A
// first-class field for the same round-trip reason as Tasks below, and
// what Info() answers with when it is set.
DisplayName string `json:"displayName,omitempty"`
PrimaryNotesLocation PrimaryNotesLocation `json:"primaryNotesLocation"`
DailyNotes DailyNotesSettings `json:"dailyNotes"`
WeeklyNotes WeeklyNotesSettings `json:"weeklyNotes"`
MonthlyNotes MonthlyNotesSettings `json:"monthlyNotes"`
DrawingsLocation FileLocationSetting `json:"drawingsLocation"`
DatabasesLocation FileLocationSetting `json:"databasesLocation"`
TasksLocation FileLocationSetting `json:"tasksLocation"`
FolderIcons map[string]FolderIconID `json:"folderIcons"`
// FolderColors are per-folder accent colors, keyed by `folder:subpath` (the
// same key as FolderIcons). Persisted so the web client's recolors survive a
// round-trip instead of being silently dropped. (#379)
FolderColors map[string]FolderColorID `json:"folderColors"`
// Favorites are note paths or `folder:subpath` keys pinned to the top of
// the sidebar. Persisted so the web client's favorites survive a round-trip.
Favorites []string `json:"favorites"`
// Per-system-folder on-disk path overrides (#115). Maps internal folder IDs
// to vault-relative directory names. Absent entries fall back to the default.
SystemFolderPaths map[string]string `json:"systemFolderPaths,omitempty"`
// Tasks-system settings (#458). Mirrors shared/ipc.ts VaultSettings.tasks;
// persisted as a first-class field so a web client's settings write never
// drops a desktop-written exclusion list (the #446/#379 round-trip rule).
Tasks *TasksSettings `json:"tasks,omitempty"`
// Typst preamble settings (#486, #562). Mirrors shared/ipc.ts
// VaultSettings.typstPreambles; a first-class field for the same round-trip
// reason as Tasks above.
TypstPreambles *TypstPreambleSettings `json:"typstPreambles,omitempty"`
// The template folder (#1024). Mirrors shared/ipc.ts
// VaultSettings.templates; a first-class field for the same round-trip
// reason as Tasks above. Its JSON hook and normalizer live in
// template_folder.go.
Templates *TemplateFolderSettings `json:"templates,omitempty"`
// Harper grammar-checker data that belongs to the vault (dictionary words
// and ignored-suggestion hashes). Mirrors shared/ipc.ts VaultSettings.harper;
// a first-class field for the same round-trip reason as Tasks above.
Harper *HarperSettings `json:"harper,omitempty"`
}
type WeeklyNotesSettings ¶
type WeeklyNotesSettings struct {
Enabled bool `json:"enabled"`
Directory string `json:"directory"`
TitlePattern string `json:"titlePattern,omitempty"`
Locale string `json:"locale,omitempty"`
LegacyPatterns []DateNotePatternSettings `json:"legacyPatterns,omitempty"`
TemplateID string `json:"templateId,omitempty"`
}
type WorkflowFile ¶
type WorkflowRollback ¶
type WorkflowRollback struct {
Reason string `json:"reason"`
}
type WorkflowRunFileChange ¶
type WorkflowRunMove ¶
WorkflowRunMove is one path op as the client planned it to land. The changes name only notes; a note's comments live in .zennotes, which a change may not name, so the server carries them for each move itself.
type WorkflowRunReceipt ¶
type WorkflowRunSummary ¶
type WorkflowUndoResult ¶
type WriteTemplateInput ¶
type WriteTemplateInput struct {
Slug string `json:"slug"`
Raw string `json:"raw"`
PreviousSourcePath string `json:"previousSourcePath,omitempty"`
}
WriteTemplateInput matches bridge-contract's WriteTemplateInput.