api

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api is the notesd RPC contract: JSON-RPC 2.0 over a Unix socket or a WebSocket, specified in docs/specs/rpc-protocol.md. zz_generated.go is generated by tools/rpcgen from schema/rpc; this file and its siblings name the runtime it relies on, which lodge's kit provides (github.com/frostyard/lodge/kit/jsonrpc). Edit the schema, never the generated file.

Index

Constants

View Source
const (
	MaxMessageSize = jsonrpc.MaxMessageSize
	EventBuffer    = jsonrpc.EventBuffer
	EventMethod    = jsonrpc.EventMethod
)

The wire limits and types (jsonrpc).

View Source
const Protocol = 1

Protocol is the protocol major version this package speaks.

Variables

View Source
var (
	ErrParseError       = &Error{Code: CodeParseError}
	ErrInvalidRequest   = &Error{Code: CodeInvalidRequest}
	ErrMethodNotFound   = &Error{Code: CodeMethodNotFound}
	ErrInvalidParams    = &Error{Code: CodeInvalidParams}
	ErrInternal         = &Error{Code: CodeInternal}
	ErrNotFound         = &Error{Code: CodeNotFound}
	ErrConflict         = &Error{Code: CodeConflict}
	ErrProtocolMismatch = &Error{Code: CodeProtocolMismatch}
	ErrNotReady         = &Error{Code: CodeNotReady}
	ErrUnavailable      = &Error{Code: CodeUnavailable}
	ErrRevoked          = &Error{Code: CodeRevoked}
)

Sentinels for errors.Is: an *Error matches the sentinel with its code.

View Source
var ErrEventsOverflow = jsonrpc.ErrEventsOverflow

ErrEventsOverflow means the caller stopped reading Client.Notifications.

View Source
var Methods = []string{
	"events.subscribe",
	"hub.status",
	"hub.serve",
	"hub.vaults",
	"hub.pending",
	"hub.approve",
	"hub.devices",
	"hub.revoke",
	"hub.setURL",
	"log.hub",
	"log.vaults",
	"log.join",
	"log.missing",
	"log.push",
	"log.pull",
	"log.match",
	"log.history",
	"log.revision",
	"log.pushes",
	"log.resolve",
	"note.list",
	"note.read",
	"note.search",
	"note.backlinks",
	"note.links",
	"note.create",
	"note.write",
	"note.move",
	"note.delete",
	"note.versions",
	"note.revert",
	"note.daily",
	"note.appendDaily",
	"note.files",
	"note.resolve",
	"note.render",
	"note.upload",
	"note.readVersion",
	"note.tags",
	"note.properties",
	"note.template",
	"note.mkdir",
	"note.moveFolder",
	"note.deleteFolder",
	"rpc.hello",
	"rpc.ping",
	"rpc.shutdown",
	"sync.pair",
	"sync.paired",
	"sync.hubs",
	"sync.relocate",
	"sync.join",
	"sync.leave",
	"sync.status",
	"sync.conflicts",
	"sync.resolve",
	"sync.reset",
	"sync.verify",
	"sync.history",
	"sync.readRevision",
	"vault.list",
	"vault.add",
	"vault.remove",
	"vault.status",
	"vault.reindex",
	"vault.settings",
	"vault.configure",
}

Methods is every method's wire name, in schema order.

Functions

func CheckDaily

func CheckDaily(ctx context.Context, p string, today bool) error

CheckDaily refuses, for an agent, writing the daily note at p unless its scope may write p, or allows daily and today is true; except= wins.

func CheckMakeFolder

func CheckMakeFolder(ctx context.Context, p string) error

CheckMakeFolder refuses, for an agent, creating folder p where its scope does not allow it.

func CheckWrite

func CheckWrite(ctx context.Context, paths ...string) error

CheckWrite refuses, for an agent, a write of any file at paths that its scope does not allow (ADR-0028). Other callers write anywhere.

func CheckWriteFolder

func CheckWriteFolder(ctx context.Context, folders ...string) error

CheckWriteFolder refuses, for an agent, moving or deleting folders its scope does not allow whole.

func Dial

func Dial(ctx context.Context, socketPath, clientName string) (*Client, *Hello, error)

Dial connects to the notesd socket and completes rpc.hello.

func EventAdmits

func EventAdmits(name string, caller Caller) bool

EventAdmits reports whether the domain of the named event admits caller: the server delivers an event only to connections of the callers its domain admits, as Router.Dispatch does for methods.

func HasMethod

func HasMethod(method string) bool

HasMethod reports whether the schema defines method.

func SameName

func SameName(a, b string) bool

SameName compares two names in a path as a scope does: after NFC normalization and case folding, as a file system that ignores case and normalizes Unicode would.

func Scoped

func Scoped(ctx context.Context) bool

Scoped reports whether a scope binds ctx's calls: an agent's.

func WithCaller

func WithCaller(ctx context.Context, c Caller) context.Context

WithCaller returns ctx carrying the caller kind; the RPC server sets it for every request from what the connection authenticated as.

func WithIdentity

func WithIdentity(ctx context.Context, id Identity) context.Context

WithIdentity returns ctx carrying id and its caller kind; the RPC server sets it for every request.

Types

type Backlink struct {
	// The linking note's path.
	Source string `json:"source"`
	Link   Link   `json:"link"`
	// The link's line in the source, the link itself marked as matching, cut with
	// '…' about 120 characters from it; empty when the source's text is not at
	// hand.
	Context []SnippetPart `json:"context"`
}

Backlink: A link to a file from a note.

type Caller

type Caller string

Caller is the kind of client a connection serves; each domain in schema/rpc lists the kinds it admits, and a method may narrow its domain's (ADR-0008, ADR-0026).

const (
	// CallerLocal is a process of the same user on notesd's Unix socket
	// (the desktop app, notesctl, notesctl mcp), or the loopback
	// development gateway that stands in for the app's bridge.
	CallerLocal Caller = "local"
	// CallerSession is a browser lodge signed in, on the lodge app
	// socket's /api.
	CallerSession Caller = "session"
	// CallerDevice is a paired device's notesd syncing with a hub.
	CallerDevice Caller = "device"
	// CallerAgent is an MCP session behind lodge's /mcp, in process,
	// bound to its token's scope.
	CallerAgent Caller = "agent"
)

func CallerFrom

func CallerFrom(ctx context.Context) Caller

CallerFrom returns the caller kind in ctx, or "" when none was set.

type Client

type Client struct {
	*jsonrpc.Client[ErrorCode]
}

Client is a notesd connection. It is safe for concurrent use; calls are multiplexed by request ID.

func NewClient

func NewClient(conn net.Conn) *Client

NewClient starts a client on an established connection. The caller must call rpc.hello before anything else; Dial does.

func (*Client) Events

func (c *Client) Events() EventsClient

Events returns the events methods.

func (*Client) Hub

func (c *Client) Hub() HubClient

Hub returns the hub methods.

func (*Client) Log

func (c *Client) Log() LogClient

Log returns the log methods.

func (*Client) Note

func (c *Client) Note() NoteClient

Note returns the note methods.

func (*Client) RPC

func (c *Client) RPC() RPCClient

RPC returns the rpc methods.

func (*Client) Sync

func (c *Client) Sync() SyncClient

Sync returns the sync methods.

func (*Client) Vault

func (c *Client) Vault() VaultClient

Vault returns the vault methods.

type Conn

type Conn interface {
	// Notify sends a transient event to this connection only.
	Notify(Event) error
	// Done is closed when the connection ends.
	Done() <-chan struct{}
	// Client is the client name the connection gave rpc.hello, such as
	// "notesctl": the default author of the writes it makes.
	Client() string
}

Conn is the client connection a request arrived on, for services that keep per-connection state, such as views.

func ConnFrom

func ConnFrom(ctx context.Context) Conn

ConnFrom returns the connection a request arrived on, or nil.

type DailyAppend

type DailyAppend struct {
	// The append's write.
	Write WriteResult `json:"write"`
	// notesd created the note from the vault's template for this call, before
	// appending.
	Created bool `json:"created"`
}

DailyAppend: A day's daily note after an append.

type DailyNote

type DailyNote struct {
	Note Note `json:"note"`
	// notesd created it from the vault's template for this call.
	Created bool `json:"created"`
}

DailyNote: A day's daily note.

type Error

type Error = jsonrpc.Error[ErrorCode]

Error is a JSON-RPC error object. Handlers return one to choose the code; any other error reaches the client as CodeInternal.

func Conflict

func Conflict(format string, args ...any) *Error

Conflict returns an error with CodeConflict.

func Errorf

func Errorf(code ErrorCode, format string, args ...any) *Error

Errorf returns an *Error with a formatted message.

func Internal

func Internal(format string, args ...any) *Error

Internal returns an error with CodeInternal.

func InvalidParams

func InvalidParams(format string, args ...any) *Error

InvalidParams returns an error with CodeInvalidParams.

func InvalidRequest

func InvalidRequest(format string, args ...any) *Error

InvalidRequest returns an error with CodeInvalidRequest.

func MethodNotFound

func MethodNotFound(format string, args ...any) *Error

MethodNotFound returns an error with CodeMethodNotFound.

func NotFound

func NotFound(format string, args ...any) *Error

NotFound returns an error with CodeNotFound.

func NotReady

func NotReady(format string, args ...any) *Error

NotReady returns an error with CodeNotReady.

func ParseError

func ParseError(format string, args ...any) *Error

ParseError returns an error with CodeParseError.

func ProtocolMismatch

func ProtocolMismatch(format string, args ...any) *Error

ProtocolMismatch returns an error with CodeProtocolMismatch.

func Revoked added in v0.2.0

func Revoked(format string, args ...any) *Error

Revoked returns an error with CodeRevoked.

func Unavailable

func Unavailable(format string, args ...any) *Error

Unavailable returns an error with CodeUnavailable.

type ErrorCode

type ErrorCode int

ErrorCode is a JSON-RPC error code; the generated constants name them.

const (
	// The request is not valid JSON.
	CodeParseError ErrorCode = -32700
	// The request is not a valid JSON-RPC 2.0 request object.
	CodeInvalidRequest ErrorCode = -32600
	// The method does not exist.
	CodeMethodNotFound ErrorCode = -32601
	// The params are missing, unknown or invalid.
	CodeInvalidParams ErrorCode = -32602
	// The server failed; the message says why.
	CodeInternal ErrorCode = -32603
	// The referenced entity does not exist.
	CodeNotFound ErrorCode = 1001
	// The request conflicts with existing state, such as a vault that is already
	// registered.
	CodeConflict ErrorCode = 1002
	// The server does not speak the client's protocol major version.
	CodeProtocolMismatch ErrorCode = 1003
	// The connection has not completed rpc.hello.
	CodeNotReady ErrorCode = 1004
	// The operation cannot run now, for example while the hub is unreachable;
	// retrying later can succeed.
	CodeUnavailable ErrorCode = 1005
	// The hub refused this device's token, or the device holds none: pair again.
	CodeRevoked ErrorCode = 1006
)

Error codes. JSON-RPC 2.0 defines the negative codes.

func (ErrorCode) String

func (c ErrorCode) String() string

String is the code's schema name.

type Event

type Event = jsonrpc.Event

Event is a generated event type, and EventEnvelope the params of an "event" notification.

func DecodeEvent

func DecodeEvent(name string, data jsontext.Value) (Event, error)

DecodeEvent decodes the data of the named event.

type EventEnvelope

type EventEnvelope = jsonrpc.EventEnvelope

Event is a generated event type, and EventEnvelope the params of an "event" notification.

func NewEnvelope

func NewEnvelope(seq int64, ev Event) (EventEnvelope, error)

NewEnvelope encodes ev for delivery.

type EventsClient

type EventsClient struct {
	// contains filtered or unexported fields
}

EventsClient calls the events methods; it implements EventsService.

func (EventsClient) Subscribe

Subscribe calls events.subscribe.

type EventsService

type EventsService interface {
	// Subscribe implements events.subscribe. Start receiving events on this
	// connection. Durable events after sinceSeq are replayed before live events.
	Subscribe(ctx context.Context, p *EventsSubscribeParams) (*Subscription, error)
}

EventsService: Change notifications. After events.subscribe, the server sends JSON-RPC notifications with method "event" on the same connection. Durable events carry a sequence number and are kept in the changes log, so a client that reconnects can resume from the last sequence number it saw.

type EventsSubscribeParams

type EventsSubscribeParams struct {
	// Replay durable events after this sequence number. Omit to receive live
	// events only.
	SinceSeq *int64 `json:"sinceSeq,omitzero"`
}

EventsSubscribeParams holds the params of events.subscribe.

type ExpandedTemplate

type ExpandedTemplate struct {
	Content string `json:"content"`
}

ExpandedTemplate: A template with its variables expanded.

type FileBase

type FileBase struct {
	Path string `json:"path"`
	Base string `json:"base"`
}

FileBase: A file and the hash a delete expects it to have.

type FileKind

type FileKind string

FileKind: What the index makes of a file.

const (
	// A markdown note (.md), parsed and indexed.
	FileKindNote FileKind = "note"
	// Any other file: indexed by name and hash only.
	FileKindAttachment FileKind = "attachment"
)

func (FileKind) Valid

func (v FileKind) Valid() bool

Valid reports whether v is one of the declared values.

type FolderDeleteResult

type FolderDeleteResult struct {
	// The files deleted, by path.
	Deleted []string `json:"deleted"`
	// Files kept: changed since their base, or not named (made since the
	// listing). An edit beats a delete (ADR-0005).
	Kept []string `json:"kept"`
	// The folder itself is gone: nothing was kept in it.
	Removed bool `json:"removed"`
}

FolderDeleteResult: What a folder delete did.

type FolderMoveResult

type FolderMoveResult struct {
	// The folder's new path.
	Path string `json:"path"`
	// The files moved, by their new paths.
	Moved []string `json:"moved"`
	// The notes whose links were rewritten, by path.
	Rewritten []string `json:"rewritten"`
}

FolderMoveResult: A folder after a move.

type Frame

type Frame = jsonrpc.Frame[ErrorCode]

Frame is one JSON-RPC 2.0 message in either direction.

type Hello

type Hello struct {
	// Protocol major version the server speaks.
	Protocol int64 `json:"protocol"`
	// Server name and version, for logs.
	Server string `json:"server"`
	// The connection's caller kind: local, session, device or agent
	// (docs/specs/rpc-protocol.md#caller-kinds).
	Caller string `json:"caller"`
	// A session's tailnet login, from lodge.
	Login *string `json:"login,omitzero"`
	// A session's display name, when lodge sends one.
	DisplayName *string `json:"displayName,omitzero"`
	// A session's node: its short host name, from lodge.
	Node *string `json:"node,omitzero"`
	// A session's key for content URLs, 32 bytes in unpadded base64url: a file's
	// URL on lodge-content names it by an HMAC under this key
	// (docs/specs/lodge-app.md#contentblobs).
	ContentKey *string `json:"contentKey,omitzero"`
	// The Flatpak build this notesd runs from: the app-commit of its instance,
	// which differs for every build, even of one version. Absent outside the
	// Flatpak (ADR-0032).
	Build *string `json:"build,omitzero"`
}

Hello: Server identity, the negotiated protocol, and who the connection is.

type HubApproveParams

type HubApproveParams struct {
	Code string `json:"code"`
}

HubApproveParams holds the params of hub.approve.

type HubClient

type HubClient struct {
	// contains filtered or unexported fields
}

HubClient calls the hub methods; it implements HubService.

func (HubClient) Approve

Approve calls hub.approve.

func (HubClient) Devices

func (x HubClient) Devices(ctx context.Context, p *HubDevicesParams) ([]HubDevice, error)

Devices calls hub.devices.

func (HubClient) Pending

Pending calls hub.pending.

func (HubClient) Revoke

func (x HubClient) Revoke(ctx context.Context, p *HubRevokeParams) error

Revoke calls hub.revoke.

func (HubClient) Serve

func (x HubClient) Serve(ctx context.Context, p *HubServeParams) (*HubVault, error)

Serve calls hub.serve.

func (HubClient) SetURL

func (x HubClient) SetURL(ctx context.Context, p *HubSetURLParams) (*HubStatus, error)

SetURL calls hub.setURL.

func (HubClient) Status

func (x HubClient) Status(ctx context.Context, p *HubStatusParams) (*HubStatus, error)

Status calls hub.status.

func (HubClient) Vaults

func (x HubClient) Vaults(ctx context.Context, p *HubVaultsParams) ([]HubVault, error)

Vaults calls hub.vaults.

type HubDevice

type HubDevice struct {
	ID       int64     `json:"id"`
	Name     string    `json:"name"`
	PairedAt time.Time `json:"pairedAt"`
	// Its last request; absent when it never used its token.
	SeenAt    *time.Time `json:"seenAt,omitzero"`
	Connected bool       `json:"connected"`
	Revoked   bool       `json:"revoked"`
}

HubDevice: A paired device.

type HubDevicesParams

type HubDevicesParams struct{}

HubDevicesParams holds the params of hub.devices.

type HubPendingParams

type HubPendingParams struct{}

HubPendingParams holds the params of hub.pending.

type HubRevokeParams

type HubRevokeParams struct {
	Device int64 `json:"device"`
}

HubRevokeParams holds the params of hub.revoke.

type HubServeParams

type HubServeParams struct {
	VaultID int64 `json:"vaultId"`
}

HubServeParams holds the params of hub.serve.

type HubService

type HubService interface {
	// Status implements hub.status. This notesd's hub role.
	Status(ctx context.Context, p *HubStatusParams) (*HubStatus, error)
	// Serve implements hub.serve. Serve a registered vault to devices: it gets a
	// sync ID, and each of its files a create revision, by path.
	Serve(ctx context.Context, p *HubServeParams) (*HubVault, error)
	// Vaults implements hub.vaults. The vaults this hub serves.
	Vaults(ctx context.Context, p *HubVaultsParams) ([]HubVault, error)
	// Pending implements hub.pending. Pairings waiting for approval, oldest
	// first.
	Pending(ctx context.Context, p *HubPendingParams) ([]PendingPairing, error)
	// Approve implements hub.approve. Approve the pending pairing with this code
	// (case, spaces and '-' ignored).
	Approve(ctx context.Context, p *HubApproveParams) (*PendingPairing, error)
	// Devices implements hub.devices. The paired devices, by ID.
	Devices(ctx context.Context, p *HubDevicesParams) ([]HubDevice, error)
	// Revoke implements hub.revoke. Revoke a device's token and close its
	// connections; its revisions keep its name.
	Revoke(ctx context.Context, p *HubRevokeParams) error
	// SetURL implements hub.setURL. Record the URL devices should use: an
	// https:// URL, or http:// on loopback, by sync-protocol's rules; empty
	// forgets it. Devices learn it with log.hub and move to it, and it is the URL
	// a relocation proof names (docs/specs/lodge-app.md#device).
	SetURL(ctx context.Context, p *HubSetURLParams) (*HubStatus, error)
}

HubService: On a hub: the vaults it serves, the devices paired with it and the URL they should use (docs/specs/sync-protocol.md, docs/specs/lodge-app.md). Approving a device, serving a vault and recording the URL happen only over the local socket (ADR-0016, ADR-0026); a session may list and revoke.

type HubSetURLParams

type HubSetURLParams struct {
	URL string `json:"url"`
}

HubSetURLParams holds the params of hub.setURL.

type HubStatus

type HubStatus struct {
	// The hub's ID; empty until it serves a vault.
	Hub string `json:"hub"`
	// The address notesd --hub serves; absent without --hub.
	Listen *string `json:"listen,omitzero"`
	// The URL devices should use, from hub.setURL; absent until one is recorded.
	URL    *string `json:"url,omitzero"`
	Vaults int64   `json:"vaults"`
	// Paired devices that are not revoked.
	Devices int64 `json:"devices"`
	// Devices connected now.
	Connected int64 `json:"connected"`
}

HubStatus: This notesd's hub role.

type HubStatusParams

type HubStatusParams struct{}

HubStatusParams holds the params of hub.status.

type HubVault

type HubVault struct {
	VaultID int64 `json:"vaultId"`
	// Its sync ID.
	Sync string `json:"sync"`
	Name string `json:"name"`
	// Its log's latest sequence number.
	Seq      int64     `json:"seq"`
	ServedAt time.Time `json:"servedAt"`
}

HubVault: A vault the hub serves.

type HubVaultsParams

type HubVaultsParams struct{}

HubVaultsParams holds the params of hub.vaults.

type Identity

type Identity struct {
	Caller Caller
	// Login, DisplayName and Node name a session's browser: the tailnet
	// login, its owner's display name and the node's short host name, from
	// Lodge-Login, Lodge-Display-Name and Lodge-Node-Name.
	Login, DisplayName, Node string
	// Token is an agent's token name, from Lodge-Token.
	Token string
	// ContentKey is a session's key for content URLs, unpadded base64url,
	// which rpc.hello hands it.
	ContentKey string
	// Scope binds an agent's calls. An agent without one reaches no vault
	// and writes nothing.
	Scope *Scope
}

Identity is who a connection's listener authenticated, fixed for the connection's lifetime: its caller kind, the names lodge gave a session or an agent, and an agent's scope.

func IdentityFrom

func IdentityFrom(ctx context.Context) Identity

IdentityFrom returns the identity in ctx. Without one it is the caller kind alone.

func (Identity) Author

func (id Identity) Author() (source VersionSource, name string, ok bool)

Author is who a connection's writes are by, when the connection fixes it (ok): a session writes as source editor and "<node> (web)", an agent as source agent and its token's name. Other connections name their writes in the params, and ok is false.

type Link struct {
	Kind LinkKind `json:"kind"`
	// The file named, as written (percent-decoded in a markdown link); empty for
	// the note itself.
	Target string `json:"target"`
	// A heading or block ID with its '#'; empty when none.
	Subpath string `json:"subpath"`
	// The display text; empty when none.
	Alias string `json:"alias"`
	Embed bool   `json:"embed"`
	// The frontmatter key of a property link; empty otherwise.
	Key string `json:"key"`
	// 1-based line in the note; a property link's key's line.
	Line int64 `json:"line"`
	// The path of the file it resolves to; absent when unresolved.
	Resolved *string `json:"resolved,omitzero"`
}

Link: A link in a note (docs/specs/markdown.md#parse-output).

type LinkFormat

type LinkFormat string

LinkFormat: How a new link names its file (Obsidian's New link format).

const (
	// The file's name when that resolves to it, else its path (Obsidian's
	// default).
	LinkFormatShortest LinkFormat = "shortest"
	// Its path from the linking note's folder.
	LinkFormatRelative LinkFormat = "relative"
	// Its path from the vault's root.
	LinkFormatAbsolute LinkFormat = "absolute"
)

func (LinkFormat) Valid

func (v LinkFormat) Valid() bool

Valid reports whether v is one of the declared values.

type LinkKind

type LinkKind string

LinkKind: Where a link is written (docs/specs/markdown.md).

const (
	// A [[wikilink]] or ![[embed]] in the body.
	LinkKindWiki LinkKind = "wiki"
	// A markdown link or image to a vault file.
	LinkKindMarkdown LinkKind = "markdown"
	// A wikilink in a frontmatter value.
	LinkKindProperty LinkKind = "property"
)

func (LinkKind) Valid

func (v LinkKind) Valid() bool

Valid reports whether v is one of the declared values.

type LogAppended

type LogAppended struct {
	// The vault's sync ID.
	Vault string `json:"vault"`
	// Its latest sequence number.
	Seq int64 `json:"seq"`
}

LogAppended: A vault's log grew.

func (LogAppended) Durable

func (LogAppended) Durable() bool

Durable reports whether LogAppended is kept in the changes log.

func (LogAppended) EventName

func (LogAppended) EventName() string

EventName is the wire name of LogAppended.

type LogClient

type LogClient struct {
	// contains filtered or unexported fields
}

LogClient calls the log methods; it implements LogService.

func (LogClient) History

func (x LogClient) History(ctx context.Context, p *LogHistoryParams) ([]Revision, error)

History calls log.history.

func (LogClient) Hub

func (x LogClient) Hub(ctx context.Context, p *LogHubParams) (*LogHub, error)

Hub calls log.hub.

func (LogClient) Join

func (x LogClient) Join(ctx context.Context, p *LogJoinParams) (*Replica, error)

Join calls log.join.

func (LogClient) Match

func (x LogClient) Match(ctx context.Context, p *LogMatchParams) ([]LogMatch, error)

Match calls log.match.

func (LogClient) Missing

func (x LogClient) Missing(ctx context.Context, p *LogMissingParams) ([]string, error)

Missing calls log.missing.

func (LogClient) Pull

func (x LogClient) Pull(ctx context.Context, p *LogPullParams) (*LogPage, error)

Pull calls log.pull.

func (LogClient) Push

func (x LogClient) Push(ctx context.Context, p *LogPushParams) ([]PushAnswer, error)

Push calls log.push.

func (LogClient) Pushes

func (x LogClient) Pushes(ctx context.Context, p *LogPushesParams) ([]PushRecord, error)

Pushes calls log.pushes.

func (LogClient) Resolve

func (x LogClient) Resolve(ctx context.Context, p *LogResolveParams) (*LogFile, error)

Resolve calls log.resolve.

func (LogClient) Revision

func (x LogClient) Revision(ctx context.Context, p *LogRevisionParams) (*Revision, error)

Revision calls log.revision.

func (LogClient) Vaults

func (x LogClient) Vaults(ctx context.Context, p *LogVaultsParams) ([]LogVault, error)

Vaults calls log.vaults.

type LogFile

type LogFile struct {
	File int64 `json:"file"`
	// Its latest revision of any kind.
	Seq int64 `json:"seq"`
	// Its head: the latest create, put, move or delete.
	Revision int64  `json:"revision"`
	Path     string `json:"path"`
	// The head's content hash; empty when deleted.
	Hash    string `json:"hash"`
	Deleted bool   `json:"deleted"`
	Size    int64  `json:"size"`
	// A conflict revision came after the last resolve.
	Conflicted bool `json:"conflicted"`
	// Who made the head, on the device or hub that made it; empty for an outside
	// edit.
	Author string `json:"author"`
	// The device that made the head, or hub.
	DeviceName string `json:"deviceName"`
}

LogFile: A file's state in the log.

type LogHistoryParams

type LogHistoryParams struct {
	Vault string `json:"vault"`
	File  int64  `json:"file"`
	// Only revisions before this sequence number.
	Before *int64 `json:"before,omitzero"`
	// At most this many; default 50, at most 200.
	Limit *int64 `json:"limit,omitzero"`
}

LogHistoryParams holds the params of log.history.

type LogHub

type LogHub struct {
	// The hub's ID.
	Hub string `json:"hub"`
	// The URL the hub records for devices (hub.setURL); absent when it records
	// none.
	URL *string `json:"url,omitzero"`
}

LogHub: The hub a device is connected to.

type LogHubParams

type LogHubParams struct{}

LogHubParams holds the params of log.hub.

type LogJoinParams

type LogJoinParams struct {
	Vault string `json:"vault"`
}

LogJoinParams holds the params of log.join.

type LogMatch

type LogMatch struct {
	Path string `json:"path"`
	Hash string `json:"hash"`
	// Absent when no file was at the path.
	File *int64 `json:"file,omitzero"`
	// Absent when no revision of that file has the hash.
	Revision *int64 `json:"revision,omitzero"`
	// The revision's content hash, with revision: not hash when the copy has a
	// later revision's content at an earlier path.
	RevisionHash *string `json:"revisionHash,omitzero"`
}

LogMatch: The revision a copy at a path with a hash is agreed at, of the file last at the path, live or deleted (docs/specs/sync-protocol.md, Joining).

type LogMatchParams

type LogMatchParams struct {
	Vault string `json:"vault"`
	// At most 1,000.
	Files []MatchQuery `json:"files"`
}

LogMatchParams holds the params of log.match.

type LogMissingParams

type LogMissingParams struct {
	Vault string `json:"vault"`
	// At most 1,000.
	Hashes []string `json:"hashes"`
}

LogMissingParams holds the params of log.missing.

type LogPage

type LogPage struct {
	Files []LogFile `json:"files"`
	// The cursor after this page: the last file's seq, or the one asked for when
	// empty.
	Next int64 `json:"next"`
	// More files follow; pull again from next.
	More bool `json:"more"`
}

LogPage: Files whose latest revision is after a cursor, in sequence order.

type LogPullParams

type LogPullParams struct {
	Vault string `json:"vault"`
	// The cursor: 0 for everything.
	After int64 `json:"after"`
	// At most this many; default 500, at most 1,000.
	Limit *int64 `json:"limit,omitzero"`
}

LogPullParams holds the params of log.pull.

type LogPushParams

type LogPushParams struct {
	Vault   string `json:"vault"`
	Replica int64  `json:"replica"`
	// At most 100.
	Items []PushItem `json:"items"`
}

LogPushParams holds the params of log.push.

type LogPushesParams

type LogPushesParams struct {
	Vault   string `json:"vault"`
	Replica int64  `json:"replica"`
	// Push IDs; at most 1,000.
	Pushes []int64 `json:"pushes"`
}

LogPushesParams holds the params of log.pushes.

type LogResolveParams

type LogResolveParams struct {
	Vault string `json:"vault"`
	File  int64  `json:"file"`
	Seq   int64  `json:"seq"`
}

LogResolveParams holds the params of log.resolve.

type LogRevisionParams

type LogRevisionParams struct {
	Vault string `json:"vault"`
	Seq   int64  `json:"seq"`
}

LogRevisionParams holds the params of log.revision.

type LogService

type LogService interface {
	// Hub implements log.hub. The hub's ID and the URL it records for devices. A
	// device asks at each connection, and moves to a URL that differs from its
	// own record, keeping its token, replicas, agreed states and cursors.
	Hub(ctx context.Context, p *LogHubParams) (*LogHub, error)
	// Vaults implements log.vaults. The vaults this hub serves.
	Vaults(ctx context.Context, p *LogVaultsParams) ([]LogVault, error)
	// Join implements log.join. Start a replica of a vault for this device; push
	// IDs count from 1 within it.
	Join(ctx context.Context, p *LogJoinParams) (*Replica, error)
	// Missing implements log.missing. The hashes whose content the hub lacks, to
	// upload before pushing.
	Missing(ctx context.Context, p *LogMissingParams) ([]string, error)
	// Push implements log.push. Apply changed files, one at a time, in order
	// (docs/specs/sync-protocol.md, A push on the hub). A push ID the replica
	// sent before gets its first answer again.
	Push(ctx context.Context, p *LogPushParams) ([]PushAnswer, error)
	// Pull implements log.pull. The files whose latest revision is after a
	// cursor, with their heads.
	Pull(ctx context.Context, p *LogPullParams) (*LogPage, error)
	// Match implements log.match. For each path and hash, the newest revision
	// with that hash of the file last at the path, as a join matches files.
	Match(ctx context.Context, p *LogMatchParams) ([]LogMatch, error)
	// History implements log.history. A file's revisions, newest first.
	History(ctx context.Context, p *LogHistoryParams) ([]Revision, error)
	// Revision implements log.revision. One revision by its sequence number, for
	// sync.readRevision (M3).
	Revision(ctx context.Context, p *LogRevisionParams) (*Revision, error)
	// Pushes implements log.pushes. The revisions the hub appended for each of a
	// replica's pushes, for sync.verify.
	Pushes(ctx context.Context, p *LogPushesParams) ([]PushRecord, error)
	// Resolve implements log.resolve. Clear a file's conflict flag with a resolve
	// revision. seq is the newest conflict revision the user has seen; a newer
	// one is a conflict.
	Resolve(ctx context.Context, p *LogResolveParams) (*LogFile, error)
}

LogService: A hub vault's revision log, for paired devices over the hub's /sync WebSocket (docs/specs/sync-protocol.md). A vault is named by its sync ID. Devices push changed files with the revision they last agreed on; only the hub merges (ADR-0005, ADR-0017). Contents move over /sync/blobs, never in these messages (ADR-0018).

type LogVault

type LogVault struct {
	// Its sync ID: 32 lowercase hex digits.
	Sync string `json:"sync"`
	Name string `json:"name"`
	// Its log's latest sequence number.
	Seq int64 `json:"seq"`
}

LogVault: A vault the hub serves.

type LogVaultsParams

type LogVaultsParams struct{}

LogVaultsParams holds the params of log.vaults.

type MatchQuery

type MatchQuery struct {
	Path string `json:"path"`
	Hash string `json:"hash"`
}

MatchQuery: A device's file, to find among a hub vault's revisions.

type MoveResult

type MoveResult struct {
	// The new path.
	Path string `json:"path"`
	// The notes whose links to the file were rewritten, by path.
	Rewritten []string `json:"rewritten"`
}

MoveResult: A file after a move.

type NewNoteLocation

type NewNoteLocation string

NewNoteLocation: Where a new note goes (Obsidian's Default location for new notes).

const (
	// The vault's root (Obsidian's default).
	NewNoteLocationRoot NewNoteLocation = "root"
	// The folder of the note open when it is made.
	NewNoteLocationCurrent NewNoteLocation = "current"
	// The folder newNoteFolder names.
	NewNoteLocationFolder NewNoteLocation = "folder"
)

func (NewNoteLocation) Valid

func (v NewNoteLocation) Valid() bool

Valid reports whether v is one of the declared values.

type Note

type Note struct {
	Path string `json:"path"`
	// The file name without .md.
	Title string `json:"title"`
	// The SHA-256 of content, lowercase hex: the base for the next write.
	Hash string `json:"hash"`
	// The file's modification time.
	ModifiedAt time.Time `json:"modifiedAt"`
	// The file's text, byte for byte, except that each sequence of bytes that is
	// not UTF-8 reads as U+FFFD; note.write keeps those bytes where a write
	// leaves them be (ADR-0014).
	Content string `json:"content"`
	// The frontmatter as a JSON object; {} without one or when it is not a YAML
	// mapping.
	Props jsontext.Value `json:"props"`
	// Why the frontmatter is not a YAML mapping.
	PropError *string  `json:"propError,omitzero"`
	Aliases   []string `json:"aliases"`
	// Frontmatter and inline tags, each once, as first spelled, without '#'.
	Tags []string `json:"tags"`
}

Note: A note's content and what the index found in it.

type NoteAppendDailyParams

type NoteAppendDailyParams struct {
	VaultID int64 `json:"vaultId"`
	// The text to append; not empty.
	Text string `json:"text"`
	// YYYY-MM-DD; default today in notesd's time zone.
	Date *string `json:"date,omitzero"`
	// editor (the default) or agent; a session's or an agent's connection fixes
	// it.
	Source *VersionSource `json:"source,omitzero"`
	// Who is writing, for the version list; defaults to the client name given to
	// rpc.hello. A session's or an agent's connection fixes it.
	Author *string `json:"author,omitzero"`
}

NoteAppendDailyParams holds the params of note.appendDaily.

type NoteBacklinksParams

type NoteBacklinksParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
}

NoteBacklinksParams holds the params of note.backlinks.

type NoteChanged

type NoteChanged struct {
	VaultID int64         `json:"vaultId"`
	Path    string        `json:"path"`
	Hash    string        `json:"hash"`
	Source  VersionSource `json:"source"`
}

NoteChanged: A file was created or its content changed, by a write or on disk.

func (NoteChanged) Durable

func (NoteChanged) Durable() bool

Durable reports whether NoteChanged is kept in the changes log.

func (NoteChanged) EventName

func (NoteChanged) EventName() string

EventName is the wire name of NoteChanged.

type NoteClient

type NoteClient struct {
	// contains filtered or unexported fields
}

NoteClient calls the note methods; it implements NoteService.

func (NoteClient) AppendDaily

func (x NoteClient) AppendDaily(ctx context.Context, p *NoteAppendDailyParams) (*DailyAppend, error)

AppendDaily calls note.appendDaily.

func (x NoteClient) Backlinks(ctx context.Context, p *NoteBacklinksParams) ([]Backlink, error)

Backlinks calls note.backlinks.

func (NoteClient) Create

Create calls note.create.

func (NoteClient) Daily

Daily calls note.daily.

func (NoteClient) Delete

func (x NoteClient) Delete(ctx context.Context, p *NoteDeleteParams) error

Delete calls note.delete.

func (NoteClient) DeleteFolder

DeleteFolder calls note.deleteFolder.

func (NoteClient) Files

Files calls note.files.

func (x NoteClient) Links(ctx context.Context, p *NoteLinksParams) ([]Link, error)

Links calls note.links.

func (NoteClient) List

func (x NoteClient) List(ctx context.Context, p *NoteListParams) ([]NoteEntry, error)

List calls note.list.

func (NoteClient) Mkdir

func (x NoteClient) Mkdir(ctx context.Context, p *NoteMkdirParams) error

Mkdir calls note.mkdir.

func (NoteClient) Move

Move calls note.move.

func (NoteClient) MoveFolder

MoveFolder calls note.moveFolder.

func (NoteClient) Properties

Properties calls note.properties.

func (NoteClient) Read

func (x NoteClient) Read(ctx context.Context, p *NoteReadParams) (*Note, error)

Read calls note.read.

func (NoteClient) ReadVersion

ReadVersion calls note.readVersion.

func (NoteClient) Render

Render calls note.render.

func (NoteClient) Resolve

func (x NoteClient) Resolve(ctx context.Context, p *NoteResolveParams) ([]Resolution, error)

Resolve calls note.resolve.

func (NoteClient) Revert

Revert calls note.revert.

func (NoteClient) Search

func (x NoteClient) Search(ctx context.Context, p *NoteSearchParams) ([]SearchHit, error)

Search calls note.search.

func (NoteClient) Tags

func (x NoteClient) Tags(ctx context.Context, p *NoteTagsParams) ([]TagCount, error)

Tags calls note.tags.

func (NoteClient) Template

Template calls note.template.

func (NoteClient) Upload

Upload calls note.upload.

func (NoteClient) Versions

func (x NoteClient) Versions(ctx context.Context, p *NoteVersionsParams) ([]Version, error)

Versions calls note.versions.

func (NoteClient) Write

Write calls note.write.

type NoteCreateParams

type NoteCreateParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	Content string `json:"content"`
	// editor (the default) or agent; a session's or an agent's connection fixes
	// it.
	Source *VersionSource `json:"source,omitzero"`
	// Who is writing, for the version list; defaults to the client name given to
	// rpc.hello. A session's or an agent's connection fixes it.
	Author *string `json:"author,omitzero"`
}

NoteCreateParams holds the params of note.create.

type NoteDailyParams

type NoteDailyParams struct {
	VaultID int64 `json:"vaultId"`
	// YYYY-MM-DD; default today in notesd's time zone.
	Date *string `json:"date,omitzero"`
	// Who creates it when it is missing: editor (the default) or agent; a
	// session's or an agent's connection fixes it.
	Source *VersionSource `json:"source,omitzero"`
	// Who creates it, for the version list; defaults to the client name given to
	// rpc.hello. A session's or an agent's connection fixes it.
	Author *string `json:"author,omitzero"`
}

NoteDailyParams holds the params of note.daily.

type NoteDeleteFolderParams

type NoteDeleteFolderParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	// The folder's files as the caller listed them.
	Files []FileBase `json:"files"`
}

NoteDeleteFolderParams holds the params of note.deleteFolder.

type NoteDeleteParams

type NoteDeleteParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	Base    string `json:"base"`
}

NoteDeleteParams holds the params of note.delete.

type NoteEntry

type NoteEntry struct {
	Path string `json:"path"`
	// The file name without .md.
	Title string `json:"title"`
	// The SHA-256 of the content, lowercase hex: the base for the next write.
	Hash string `json:"hash"`
	// In bytes.
	Size int64 `json:"size"`
	// The file's modification time.
	ModifiedAt time.Time `json:"modifiedAt"`
	// The note's frontmatter aliases, in order; empty without any.
	Aliases []string `json:"aliases"`
}

NoteEntry: A note in a listing.

type NoteFilesParams

type NoteFilesParams struct {
	VaultID int64 `json:"vaultId"`
}

NoteFilesParams holds the params of note.files.

type NoteLinksParams

type NoteLinksParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
}

NoteLinksParams holds the params of note.links.

type NoteListParams

type NoteListParams struct {
	VaultID int64 `json:"vaultId"`
	// Only notes in this folder or below it; "/" is the whole vault.
	Folder *string `json:"folder,omitzero"`
	// Only notes with this tag or one nested under it (tag/…), ignoring case; a
	// leading '#' is ignored.
	Tag *string `json:"tag,omitzero"`
	// Only notes whose frontmatter has this key.
	Property *string `json:"property,omitzero"`
	// With property: only notes where the key's value, or an item of its list,
	// equals this, ignoring case.
	Value *string `json:"value,omitzero"`
}

NoteListParams holds the params of note.list.

type NoteMkdirParams

type NoteMkdirParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
}

NoteMkdirParams holds the params of note.mkdir.

type NoteMoveFolderParams

type NoteMoveFolderParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	// The new path; it must not exist.
	To          string `json:"to"`
	UpdateLinks *bool  `json:"updateLinks,omitzero"`
}

NoteMoveFolderParams holds the params of note.moveFolder.

type NoteMoveParams

type NoteMoveParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	// The new path; it must not exist.
	To string `json:"to"`
	// Rewrite links to the file, as Obsidian's "Automatically update internal
	// links" does.
	UpdateLinks *bool `json:"updateLinks,omitzero"`
}

NoteMoveParams holds the params of note.move.

type NoteMoved

type NoteMoved struct {
	VaultID int64  `json:"vaultId"`
	From    string `json:"from"`
	To      string `json:"to"`
}

NoteMoved: A file was renamed or moved.

func (NoteMoved) Durable

func (NoteMoved) Durable() bool

Durable reports whether NoteMoved is kept in the changes log.

func (NoteMoved) EventName

func (NoteMoved) EventName() string

EventName is the wire name of NoteMoved.

type NotePropertiesParams

type NotePropertiesParams struct {
	VaultID int64 `json:"vaultId"`
}

NotePropertiesParams holds the params of note.properties.

type NoteReadParams

type NoteReadParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
}

NoteReadParams holds the params of note.read.

type NoteReadVersionParams

type NoteReadVersionParams struct {
	VaultID int64 `json:"vaultId"`
	// The version's id, from note.versions or a write's conflictVersion.
	Version int64 `json:"version"`
}

NoteReadVersionParams holds the params of note.readVersion.

type NoteRemoved

type NoteRemoved struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
}

NoteRemoved: A file was deleted, by note.delete or on disk.

func (NoteRemoved) Durable

func (NoteRemoved) Durable() bool

Durable reports whether NoteRemoved is kept in the changes log.

func (NoteRemoved) EventName

func (NoteRemoved) EventName() string

EventName is the wire name of NoteRemoved.

type NoteRenderParams

type NoteRenderParams struct {
	VaultID int64   `json:"vaultId"`
	Path    string  `json:"path"`
	Content *string `json:"content,omitzero"`
}

NoteRenderParams holds the params of note.render.

type NoteResolveParams

type NoteResolveParams struct {
	VaultID int64 `json:"vaultId"`
	// The linking note's path; it need not exist yet.
	From string `json:"from"`
	// Link targets as written, without subpath or alias; at most 1,000.
	Targets []string `json:"targets"`
}

NoteResolveParams holds the params of note.resolve.

type NoteRevertParams

type NoteRevertParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	// The version's id, from note.versions.
	Version int64 `json:"version"`
	// The file's current hash; empty when it is deleted.
	Base string `json:"base"`
}

NoteRevertParams holds the params of note.revert.

type NoteSearchParams

type NoteSearchParams struct {
	VaultID int64  `json:"vaultId"`
	Query   string `json:"query"`
	// At most this many; default 20, at most 100.
	Limit *int64 `json:"limit,omitzero"`
}

NoteSearchParams holds the params of note.search.

type NoteService

type NoteService interface {
	// List implements note.list. The notes in a vault, by path. The filters
	// combine: a note must match every one given.
	List(ctx context.Context, p *NoteListParams) ([]NoteEntry, error)
	// Read implements note.read. A note's content and what the index found in it.
	Read(ctx context.Context, p *NoteReadParams) (*Note, error)
	// Search implements note.search. Full-text search over titles, aliases,
	// bodies and frontmatter, best match first. Each word matches as a prefix
	// ("plan" finds "planting"), a phrase in double quotes matches as written,
	// and every word or phrase must match. Case and diacritics are ignored.
	// Filters narrow it, each as its own word: path:TEXT (the path contains
	// TEXT), file:TEXT (the file name contains TEXT), tag:#TAG (the note has TAG
	// or a tag nested under it); a filter alone lists matching notes by path.
	Search(ctx context.Context, p *NoteSearchParams) ([]SearchHit, error)
	// Backlinks implements note.backlinks. The links to a note or attachment from
	// the notes of its vault, by source path, then line.
	Backlinks(ctx context.Context, p *NoteBacklinksParams) ([]Backlink, error)
	// Links implements note.links. A note's links in the order they are written,
	// each with the file it resolves to.
	Links(ctx context.Context, p *NoteLinksParams) ([]Link, error)
	// Create implements note.create. Create a note or attachment, and any missing
	// folders. Fails with conflict if the path exists.
	Create(ctx context.Context, p *NoteCreateParams) (*WriteResult, error)
	// Write implements note.write. Replace a file's content. base is the hash the
	// writer started from. If the file changed since, notesd merges: frontmatter
	// by key, then the body by line and word (ADR-0005). A base notesd has no
	// version of (pruned after 30 days) is refused with conflict: read again, as
	// is a stale base of a file that is not text, which does not merge. Bytes of
	// the base that are not UTF-8, which note.read showed as U+FFFD, are kept
	// wherever content leaves the words around them as they were (ADR-0014).
	Write(ctx context.Context, p *NoteWriteParams) (*WriteResult, error)
	// Move implements note.move. Rename or move a note or attachment, creating
	// missing folders. The file keeps its versions. With updateLinks, every link
	// to it from another note is rewritten to the new path, each as a write.
	Move(ctx context.Context, p *NoteMoveParams) (*MoveResult, error)
	// Delete implements note.delete. Delete a note or attachment: notesd removes
	// the file, and its versions stay for 30 days, so note.revert can bring it
	// back. base must be its current hash: a file changed since base is not
	// deleted (conflict), because an edit beats a delete (ADR-0005).
	Delete(ctx context.Context, p *NoteDeleteParams) error
	// Versions implements note.versions. A file's versions, newest first, its
	// deletion included. For a deleted file, the versions of the last file at
	// that path.
	Versions(ctx context.Context, p *NoteVersionsParams) ([]Version, error)
	// Revert implements note.revert. Make a file's content that of one of its
	// versions, as a write with a base. A deleted file comes back at its last
	// path.
	Revert(ctx context.Context, p *NoteRevertParams) (*WriteResult, error)
	// Daily implements note.daily. A day's daily note, created from the vault's
	// daily-note template when missing (docs/design/vault.md#daily-notes).
	Daily(ctx context.Context, p *NoteDailyParams) (*DailyNote, error)
	// AppendDaily implements note.appendDaily. Append text at the end of a day's
	// daily note, after a line break when the note does not end in one, ending it
	// with a line break. A missing note is created first, as note.daily creates
	// it. The append is a write whose base is the note as notesd reads it under
	// the vault's lock, so it never changes text already there (ADR-0028); an
	// edit that lands on disk meanwhile merges as for note.write.
	AppendDaily(ctx context.Context, p *NoteAppendDailyParams) (*DailyAppend, error)
	// Files implements note.files. Every file and folder of a vault: the Files
	// pane's listing and the hashes the app loads files by (ADR-0023).
	// note.changed, note.moved and note.removed keep it current.
	Files(ctx context.Context, p *NoteFilesParams) (*VaultFiles, error)
	// Resolve implements note.resolve. Where link targets lead from a note, by
	// the vault's link resolution (docs/specs/markdown.md#link-resolution), for
	// links the editor shows before the index has them.
	Resolve(ctx context.Context, p *NoteResolveParams) ([]Resolution, error)
	// Render implements note.render. A note rendered to sanitized HTML for the
	// reading view and embeds (ADR-0007): Obsidian's syntax, embeds of notes
	// three levels deep, a single newline as a line break (Obsidian's default).
	// With content, that text is rendered as if it were the note at path, so an
	// editor shows what was typed before it is saved.
	Render(ctx context.Context, p *NoteRenderParams) (*RenderedNote, error)
	// Upload implements note.upload. Create an attachment from bytes, as
	// note.create creates a note: it fails with conflict if the path exists
	// (ADR-0023). data is base64, at most 10 MB decoded.
	Upload(ctx context.Context, p *NoteUploadParams) (*WriteResult, error)
	// ReadVersion implements note.readVersion. A version's content, for the
	// history view and the merge view.
	ReadVersion(ctx context.Context, p *NoteReadVersionParams) (*VersionContent, error)
	// Tags implements note.tags. Every tag in the vault's notes and how many
	// notes have it, by tag ignoring case.
	Tags(ctx context.Context, p *NoteTagsParams) ([]TagCount, error)
	// Properties implements note.properties. Every frontmatter key in the vault's
	// notes, its type and how many notes have it, by key ignoring case.
	Properties(ctx context.Context, p *NotePropertiesParams) ([]PropertyCount, error)
	// Template implements note.template. A template note's content with
	// {{title}}, {{date}}, {{time}} and their formats and offsets expanded, as
	// Obsidian's Insert template does (docs/design/vault.md#daily-notes).
	Template(ctx context.Context, p *NoteTemplateParams) (*ExpandedTemplate, error)
	// Mkdir implements note.mkdir. Create a folder and any missing parents. An
	// existing folder is not an error.
	Mkdir(ctx context.Context, p *NoteMkdirParams) error
	// MoveFolder implements note.moveFolder. Rename or move a folder with
	// everything in it, creating missing parents. Each file moves as note.move
	// moves it, keeping its versions; with updateLinks, links to them from notes
	// outside the folder are rewritten.
	MoveFolder(ctx context.Context, p *NoteMoveFolderParams) (*FolderMoveResult, error)
	// DeleteFolder implements note.deleteFolder. Delete a folder's files, each
	// with the base the caller listed, then the folder when nothing is left in
	// it. A file changed since its base, or not listed, is kept: an edit beats a
	// delete (ADR-0005). Every deleted file's versions stay for note.revert.
	DeleteFolder(ctx context.Context, p *NoteDeleteFolderParams) (*FolderDeleteResult, error)
}

NoteService: The notes and attachments in a vault, and what notesd's index knows of them (docs/design/vault.md). A path is vault-relative and slash-separated, as on disk. Every write names the hash of the content it started from, as note.read returns it (ADR-0006): when the file changed since, notesd merges three ways, writes the result and returns it. Only a create has no base.

type NoteTagsParams

type NoteTagsParams struct {
	VaultID int64 `json:"vaultId"`
}

NoteTagsParams holds the params of note.tags.

type NoteTemplateParams

type NoteTemplateParams struct {
	VaultID int64 `json:"vaultId"`
	// The template note's path.
	Template string `json:"template"`
	// {{title}}: the note it goes into; empty by default.
	Title *string `json:"title,omitzero"`
	// The date and time {{date}} and {{time}} give; now by default.
	At *time.Time `json:"at,omitzero"`
}

NoteTemplateParams holds the params of note.template.

type NoteUploadParams

type NoteUploadParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	// The file's bytes, base64 (standard alphabet, padded).
	Data string `json:"data"`
	// editor (the default) or agent; a session's or an agent's connection fixes
	// it.
	Source *VersionSource `json:"source,omitzero"`
	// Who is writing; defaults to the client name given to rpc.hello. A session's
	// or an agent's connection fixes it.
	Author *string `json:"author,omitzero"`
}

NoteUploadParams holds the params of note.upload.

type NoteVersionsParams

type NoteVersionsParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	// At most this many; default 50.
	Limit *int64 `json:"limit,omitzero"`
}

NoteVersionsParams holds the params of note.versions.

type NoteWriteParams

type NoteWriteParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	// The hash of the content this write started from.
	Base    string `json:"base"`
	Content string `json:"content"`
	// editor (the default) or agent; a session's or an agent's connection fixes
	// it.
	Source *VersionSource `json:"source,omitzero"`
	// Who is writing, for the version list; defaults to the client name given to
	// rpc.hello. A session's or an agent's connection fixes it.
	Author *string `json:"author,omitzero"`
}

NoteWriteParams holds the params of note.write.

type PairResult

type PairResult struct {
	State PairingState `json:"state"`
	// The hub's ID.
	Hub string `json:"hub"`
}

PairResult: A pairing's state.

type Pairing

type Pairing struct {
	// Its ID, for sync.paired.
	Pairing string `json:"pairing"`
	// The one-time code to approve on the hub, as XXXX-XXXX.
	Code string `json:"code"`
	// The hub's ID.
	Hub       string    `json:"hub"`
	URL       string    `json:"url"`
	ExpiresAt time.Time `json:"expiresAt"`
}

Pairing: A pairing the device started.

type PairingState

type PairingState string

PairingState: Where a pairing stands.

const (
	// Waiting for the user to approve the code on the hub.
	PairingStatePending PairingState = "pending"
	// Approved; the device keeps its token.
	PairingStateApproved PairingState = "approved"
	// Not approved within 10 minutes.
	PairingStateExpired PairingState = "expired"
)

func (PairingState) Valid

func (v PairingState) Valid() bool

Valid reports whether v is one of the declared values.

type PendingPairing

type PendingPairing struct {
	Code string `json:"code"`
	// The name the device gave.
	Name string `json:"name"`
	// The address it asked from, as the hub saw it.
	Addr      string    `json:"addr"`
	CreatedAt time.Time `json:"createdAt"`
	ExpiresAt time.Time `json:"expiresAt"`
	// Approved, and not yet collected.
	Approved bool `json:"approved"`
}

PendingPairing: A device waiting to pair.

type PropertyCount

type PropertyCount struct {
	// As first spelled.
	Key string `json:"key"`
	// Its type from the vault's property types (text, multitext, number,
	// checkbox, date, datetime, aliases, tags); empty when it has none.
	Type string `json:"type"`
	// Notes with the key, ignoring case.
	Count int64 `json:"count"`
}

PropertyCount: A frontmatter key and how many notes have it.

type PushAnswer

type PushAnswer struct {
	Push   int64      `json:"push"`
	Status PushStatus `json:"status"`
	// Why, when refused.
	Reason *RefuseReason `json:"reason,omitzero"`
	// The file after the push; absent only for a refused create.
	File *LogFile `json:"file,omitzero"`
	// Hunks the head won.
	Conflicts int64 `json:"conflicts"`
	// The base's content was gone, so the push merged as a create (ADR-0019).
	BasePruned bool `json:"basePruned"`
}

PushAnswer: What the hub did with one pushed item.

type PushItem

type PushItem struct {
	// The push ID: never reused within the replica.
	Push int64 `json:"push"`
	// The hub's file ID; absent for a create.
	File *int64 `json:"file,omitzero"`
	// The revision the device last agreed on; 0 for a create.
	Base int64 `json:"base"`
	// That revision's hash; empty for a create.
	BaseHash string `json:"baseHash"`
	// The file's path on the device.
	Path string `json:"path"`
	// The content's hash; absent when deleted.
	Hash *string `json:"hash,omitzero"`
	// The device deleted the file.
	Deleted *bool `json:"deleted,omitzero"`
	// Who changed it on the device: editor, agent or outside.
	Source VersionSource `json:"source"`
	// The writer's name on the device; empty for an outside edit.
	Author string `json:"author"`
	// When the device recorded the change.
	At time.Time `json:"at"`
	// The content lost conflicting hunks in a merge on the device (a writer with
	// a stale base); the hub keeps it as a conflict revision of the file, which
	// flags it.
	Conflict *bool `json:"conflict,omitzero"`
}

PushItem: A file's whole new state on a device, and the revision it was based on.

type PushRecord

type PushRecord struct {
	Push int64 `json:"push"`
	// Empty when the hub has no record of the push, or it changed nothing.
	Revisions []Revision `json:"revisions"`
}

PushRecord: The revisions the hub appended for one push.

type PushStatus

type PushStatus string

PushStatus: What the hub did with a pushed change.

const (
	// Applied as pushed, or already there.
	PushStatusAccepted PushStatus = "accepted"
	// Merged with changes the device had not seen; file holds the result.
	PushStatusMerged PushStatus = "merged"
	// Merged, but hunks both sides changed differently kept the head's side; the
	// pushed content is a conflict revision and the file is flagged.
	PushStatusConflicted PushStatus = "conflicted"
	// Not applied; reason says why.
	PushStatusRefused PushStatus = "refused"
)

func (PushStatus) Valid

func (v PushStatus) Valid() bool

Valid reports whether v is one of the declared values.

type RPCClient

type RPCClient struct {
	// contains filtered or unexported fields
}

RPCClient calls the rpc methods; it implements RPCService.

func (RPCClient) Hello

func (x RPCClient) Hello(ctx context.Context, p *RPCHelloParams) (*Hello, error)

Hello calls rpc.hello.

func (RPCClient) Ping

func (x RPCClient) Ping(ctx context.Context, p *RPCPingParams) error

Ping calls rpc.ping.

func (RPCClient) Shutdown added in v0.3.0

func (x RPCClient) Shutdown(ctx context.Context, p *RPCShutdownParams) error

Shutdown calls rpc.shutdown.

type RPCHelloParams

type RPCHelloParams struct {
	// Protocol major version the client speaks.
	Protocol int64 `json:"protocol"`
	// Client name and version, for logs.
	Client string `json:"client"`
}

RPCHelloParams holds the params of rpc.hello.

type RPCPingParams

type RPCPingParams struct{}

RPCPingParams holds the params of rpc.ping.

type RPCService

type RPCService interface {
	// Hello implements rpc.hello. Negotiate the protocol major version. Changes
	// within a major version are additive only.
	Hello(ctx context.Context, p *RPCHelloParams) (*Hello, error)
	// Ping implements rpc.ping. Nothing, answered: the web app's heartbeat while
	// it is visible, which finds a connection a sleeping phone dropped.
	Ping(ctx context.Context, p *RPCPingParams) error
	// Shutdown implements rpc.shutdown. Stop notesd as SIGTERM does: it answers,
	// cancels the requests in hand and waits for their handlers to return, stops
	// the vaults and sync, closes the store, releases the data directory's lock
	// and exits 0. A request in hand can complete, return an error, or lose its
	// reply when its connection closes; a committed write stays whole and is
	// indexed, so a client must not treat a write without an answer as absent,
	// and sends it again on the same base. The Flatpak's launcher calls it to
	// replace an older build (ADR-0032).
	Shutdown(ctx context.Context, p *RPCShutdownParams) error
}

RPCService: Connection setup. A client calls rpc.hello first on every connection; the server answers any other method with notReady until hello succeeds.

type RPCShutdownParams added in v0.3.0

type RPCShutdownParams struct{}

RPCShutdownParams holds the params of rpc.shutdown.

type RefuseReason

type RefuseReason string

RefuseReason: Why the hub refused a pushed change.

const (
	// A path the path guard refuses, a malformed hash, or a create or delete that
	// names what it may not.
	RefuseReasonInvalid RefuseReason = "invalid"
	// The hub's vault settings ignore the path.
	RefuseReasonIgnored RefuseReason = "ignored"
	// The hub has no content for the hash: upload it first.
	RefuseReasonMissing RefuseReason = "missing"
	// The file ID is not a file of this vault.
	RefuseReasonUnknown RefuseReason = "unknown"
	// The base is not a revision of the file, or its hash differs.
	RefuseReasonBase RefuseReason = "base"
	// The path differs only by case from another live file's; no longer given,
	// since such a create gets a number.
	RefuseReasonCollision RefuseReason = "collision"
	// A delete of a file that changed since its base: an edit beats a delete.
	RefuseReasonEdited RefuseReason = "edited"
)

func (RefuseReason) Valid

func (v RefuseReason) Valid() bool

Valid reports whether v is one of the declared values.

type RenderedNote

type RenderedNote struct {
	// Sanitized HTML: no script, event handler, form, frame, style or javascript:
	// URL. Vault files appear as data-blob attributes, never as URLs (ADR-0023).
	HTML string `json:"html"`
}

RenderedNote: A note rendered for the reading view (docs/design/app.md#reading-view).

type Replica

type Replica struct {
	ID int64 `json:"id"`
	// The vault's sync ID.
	Vault string `json:"vault"`
	// The log's latest sequence number when the replica was made.
	Seq int64 `json:"seq"`
}

Replica: One device's join of one hub vault; push IDs count within it.

type Resolution

type Resolution struct {
	// The target as asked, without subpath or alias.
	Target string `json:"target"`
	// The file it resolves to; absent when unresolved.
	Path *string `json:"path,omitzero"`
}

Resolution: Where a link target leads from a note.

type Revision

type Revision struct {
	Seq  int64      `json:"seq"`
	File int64      `json:"file"`
	Op   RevisionOp `json:"op"`
	Path string     `json:"path"`
	// Empty for a delete.
	Hash string `json:"hash"`
	Size int64  `json:"size"`
	// The revision it was based on; 0 for a create.
	Base int64 `json:"base"`
	// The device that pushed it; absent for the hub's own writers.
	Device *int64 `json:"device,omitzero"`
	// That device's name, or hub.
	DeviceName string        `json:"deviceName"`
	Source     VersionSource `json:"source"`
	Author     string        `json:"author"`
	At         time.Time     `json:"at"`
	// For a conflict revision: the revision whose side stood.
	LostTo *int64 `json:"lostTo,omitzero"`
	// Its content is gone (ADR-0019).
	Pruned bool `json:"pruned"`
}

Revision: An entry in a hub vault's log (ADR-0017).

type RevisionContent

type RevisionContent struct {
	Revision Revision `json:"revision"`
	// As note.read gives content; empty for a delete or resolve.
	Content string `json:"content"`
}

RevisionContent: A hub revision's content.

type RevisionOp

type RevisionOp string

RevisionOp: What a revision did to its file.

const (
	// The file's first revision.
	RevisionOpCreate RevisionOp = "create"
	// New content.
	RevisionOpPut RevisionOp = "put"
	// A new path, the same content.
	RevisionOpMove RevisionOp = "move"
	// The file was deleted.
	RevisionOpDelete RevisionOp = "delete"
	// Content that lost conflicting hunks to the head; never a head itself.
	RevisionOpConflict RevisionOp = "conflict"
	// The user cleared the file's conflict flag.
	RevisionOpResolve RevisionOp = "resolve"
)

func (RevisionOp) Valid

func (v RevisionOp) Valid() bool

Valid reports whether v is one of the declared values.

type Router

type Router struct {
	*jsonrpc.Router[Caller, ErrorCode]
}

Router maps wire method names to service implementations, the callers each method admits and the methods that write.

func NewRouter

func NewRouter(s Services) (*Router, error)

NewRouter registers every service; a nil service is an error. Dispatch runs one method for the caller in ctx (WithCaller, WithIdentity): a method that does not exist, that does not admit the caller, or that writes under a scope that may not, returns ErrMethodNotFound. The generated handlers check the vault a scoped call names (inScope).

type ScanState

type ScanState string

ScanState: What a vault's scanner is doing.

const (
	// No scan is running; the index holds what the last scan and the watcher
	// found.
	ScanStateIdle ScanState = "idle"
	// A scan is running.
	ScanStateScanning ScanState = "scanning"
	// The last scan failed and error says why; the index keeps what it held.
	ScanStateFailed ScanState = "failed"
)

func (ScanState) Valid

func (v ScanState) Valid() bool

Valid reports whether v is one of the declared values.

type ScanStatus

type ScanStatus struct {
	VaultID int64     `json:"vaultId"`
	State   ScanState `json:"state"`
	// Files the running scan has compared with the index; 0 when none runs.
	Done int64 `json:"done"`
	// Files the running scan found; 0 when none runs.
	Total int64 `json:"total"`
	// Notes in the index.
	Notes int64 `json:"notes"`
	// Attachments in the index.
	Attachments int64 `json:"attachments"`
	// When the last scan finished; absent until one has since notesd started.
	ScannedAt *time.Time `json:"scannedAt,omitzero"`
	// The vault is on a network file system, so notesd rescans it every 10
	// seconds instead of every 5 minutes.
	Network bool `json:"network"`
	// Why the last scan failed.
	Error *string `json:"error,omitzero"`
}

ScanStatus: The state of a vault's index and its scans.

type Scope

type Scope struct {
	Vault int64
	// Write is a bare ";write": the whole vault, but Except.
	Write bool
	// WriteTo limits writes to paths in these folders ("write=").
	WriteTo []string
	// Except takes paths in these folders out of every write: Write,
	// WriteTo and Daily alike. It always wins.
	Except []string
	// Daily allows appending to today's daily note, and nothing more.
	Daily bool
}

Scope is what an agent's token allows (Lodge-Scope; ADR-0026, ADR-0028): one vault, read whole, and the writes its parts allow.

vault=<id>[;write[=<prefix>[,<prefix>…]]][;except=<prefix>[,<prefix>…]][;daily]

A prefix names a folder by its vault-relative path, ending in "/" and percent-encoded as a URL path segment is. A path is judged segment by segment, after NFC normalization and case folding, so that on a file system that ignores case no spelling escapes Except.

func ParseScope

func ParseScope(s string) (Scope, error)

ParseScope parses a scope. Its parts appear at most once each and in order, so a scope reads one way; anything else is an error.

func (Scope) CanWrite

func (s Scope) CanWrite() bool

CanWrite reports whether the scope may write beyond today's daily note: a bare write or a write= folder.

func (Scope) Describe

func (s Scope) Describe() string

Describe says what the scope may write, for a refusal's message and the MCP tools' descriptions.

func (Scope) Excepted

func (s Scope) Excepted(p string) bool

Excepted reports whether p is in an except= folder, or is one.

func (Scope) MayMakeFolder

func (s Scope) MayMakeFolder(p string) bool

MayMakeFolder reports whether the scope may create folder p: as Writable, but a write= folder itself counts as within it.

func (Scope) String

func (s Scope) String() string

String is the scope's canonical Lodge-Scope form.

func (Scope) Writable

func (s Scope) Writable(p string) bool

Writable reports whether the scope may write the file at p: in a write= folder, or anywhere under a bare write, and in no except= folder.

func (Scope) WritableFolder

func (s Scope) WritableFolder(p string) bool

WritableFolder reports whether the scope may move or delete folder p whole: p is in a write= folder, or anywhere under a bare write, and no except= folder is at, above or under p.

type SearchHit

type SearchHit struct {
	Path  string `json:"path"`
	Title string `json:"title"`
	// About 16 words around the best match, from the column that matched best;
	// '…' marks cut text.
	Snippet []SnippetPart `json:"snippet"`
}

SearchHit: A note that matched a search.

type Services

type Services struct {
	Events EventsService
	Hub    HubService
	Log    LogService
	Note   NoteService
	RPC    RPCService
	Sync   SyncService
	Vault  VaultService
}

Services is one implementation per domain, for NewRouter.

type SettingSource

type SettingSource string

SettingSource: Where a setting's value comes from.

const (
	// The vault's .frostnotes/vault.yaml.
	SettingSourceFrostnotes SettingSource = "frostnotes"
	// Obsidian's settings in .obsidian/, read while vault.yaml lacks the setting.
	SettingSourceObsidian SettingSource = "obsidian"
	// Neither has it: Obsidian's default.
	SettingSourceDefault SettingSource = "default"
)

func (SettingSource) Valid

func (v SettingSource) Valid() bool

Valid reports whether v is one of the declared values.

type SnippetPart

type SnippetPart struct {
	Text string `json:"text"`
	// This text matched the query.
	Match bool `json:"match"`
}

SnippetPart: A piece of a search snippet.

type Subscription

type Subscription struct {
	// The latest durable sequence number when the subscription started.
	Seq int64 `json:"seq"`
	// True when sinceSeq is older than the retained log; the client must refetch
	// all state.
	Resync bool `json:"resync"`
}

Subscription: The state of a new subscription.

type SyncChanged

type SyncChanged struct {
	Status SyncStatus `json:"status"`
}

SyncChanged: A synced vault's state changed.

func (SyncChanged) Durable

func (SyncChanged) Durable() bool

Durable reports whether SyncChanged is kept in the changes log.

func (SyncChanged) EventName

func (SyncChanged) EventName() string

EventName is the wire name of SyncChanged.

type SyncClient

type SyncClient struct {
	// contains filtered or unexported fields
}

SyncClient calls the sync methods; it implements SyncService.

func (SyncClient) Conflicts

func (x SyncClient) Conflicts(ctx context.Context, p *SyncConflictsParams) ([]SyncConflict, error)

Conflicts calls sync.conflicts.

func (SyncClient) History

func (x SyncClient) History(ctx context.Context, p *SyncHistoryParams) ([]Revision, error)

History calls sync.history.

func (SyncClient) Hubs

func (x SyncClient) Hubs(ctx context.Context, p *SyncHubsParams) ([]SyncHub, error)

Hubs calls sync.hubs.

func (SyncClient) Join

Join calls sync.join.

func (SyncClient) Leave

func (x SyncClient) Leave(ctx context.Context, p *SyncLeaveParams) error

Leave calls sync.leave.

func (SyncClient) Pair

func (x SyncClient) Pair(ctx context.Context, p *SyncPairParams) (*Pairing, error)

Pair calls sync.pair.

func (SyncClient) Paired

Paired calls sync.paired.

func (SyncClient) ReadRevision

ReadRevision calls sync.readRevision.

func (SyncClient) Relocate

func (x SyncClient) Relocate(ctx context.Context, p *SyncRelocateParams) (*SyncHub, error)

Relocate calls sync.relocate.

func (SyncClient) Reset

Reset calls sync.reset.

func (SyncClient) Resolve

func (x SyncClient) Resolve(ctx context.Context, p *SyncResolveParams) error

Resolve calls sync.resolve.

func (SyncClient) Status

func (x SyncClient) Status(ctx context.Context, p *SyncStatusParams) ([]SyncStatus, error)

Status calls sync.status.

func (SyncClient) Verify

Verify calls sync.verify.

type SyncConflict

type SyncConflict struct {
	Path string `json:"path"`
	// The hub's file ID.
	File      int64      `json:"file"`
	Revisions []Revision `json:"revisions"`
}

SyncConflict: A flagged file and the conflict revisions since its last resolve.

type SyncConflictsParams

type SyncConflictsParams struct {
	VaultID int64 `json:"vaultId"`
}

SyncConflictsParams holds the params of sync.conflicts.

type SyncHistoryParams

type SyncHistoryParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
	// At most this many; default 50, at most 200.
	Limit *int64 `json:"limit,omitzero"`
}

SyncHistoryParams holds the params of sync.history.

type SyncHub

type SyncHub struct {
	ID int64 `json:"id"`
	// The hub's ID.
	Hub string `json:"hub"`
	URL string `json:"url"`
	// This device's ID on the hub.
	Device   int64     `json:"device"`
	PairedAt time.Time `json:"pairedAt"`
}

SyncHub: A hub this device paired with.

type SyncHubsParams

type SyncHubsParams struct{}

SyncHubsParams holds the params of sync.hubs.

type SyncJoinParams

type SyncJoinParams struct {
	VaultID int64 `json:"vaultId"`
	// A paired hub's URL.
	URL string `json:"url"`
	// The hub vault's name.
	Name string `json:"name"`
}

SyncJoinParams holds the params of sync.join.

type SyncLeaveParams

type SyncLeaveParams struct {
	VaultID int64 `json:"vaultId"`
}

SyncLeaveParams holds the params of sync.leave.

type SyncPairParams

type SyncPairParams struct {
	// https://, or http:// on loopback.
	URL string `json:"url"`
	// This device's name on the hub; default the host name.
	Name *string `json:"name,omitzero"`
}

SyncPairParams holds the params of sync.pair.

type SyncPairedParams

type SyncPairedParams struct {
	Pairing string `json:"pairing"`
}

SyncPairedParams holds the params of sync.paired.

type SyncReadRevisionParams

type SyncReadRevisionParams struct {
	VaultID int64 `json:"vaultId"`
	// The revision's sequence number, from sync.history or sync.conflicts.
	Seq int64 `json:"seq"`
}

SyncReadRevisionParams holds the params of sync.readRevision.

type SyncRefusal

type SyncRefusal struct {
	Path   string       `json:"path"`
	Reason RefuseReason `json:"reason"`
	At     time.Time    `json:"at"`
}

SyncRefusal: A local change the hub refused; it is not pushed again until the file changes.

type SyncRelocateParams

type SyncRelocateParams struct {
	// The paired hub's URL now, as sync.hubs lists it.
	Hub string `json:"hub"`
	// Its new URL: https://, or http:// on loopback.
	URL string `json:"url"`
}

SyncRelocateParams holds the params of sync.relocate.

type SyncResetParams

type SyncResetParams struct {
	VaultID int64 `json:"vaultId"`
}

SyncResetParams holds the params of sync.reset.

type SyncResolveParams

type SyncResolveParams struct {
	VaultID int64  `json:"vaultId"`
	Path    string `json:"path"`
}

SyncResolveParams holds the params of sync.resolve.

type SyncService

type SyncService interface {
	// Pair implements sync.pair. Start pairing with the hub at url; approve the
	// code on the hub, then call sync.paired.
	Pair(ctx context.Context, p *SyncPairParams) (*Pairing, error)
	// Paired implements sync.paired. Wait up to 30 seconds for a pairing to be
	// approved or to expire.
	Paired(ctx context.Context, p *SyncPairedParams) (*PairResult, error)
	// Hubs implements sync.hubs. The hubs this device paired with.
	Hubs(ctx context.Context, p *SyncHubsParams) ([]SyncHub, error)
	// Relocate implements sync.relocate. Move a paired hub to url, for a device
	// that missed log.hub's move: it posts a fresh nonce to url's /sync/hub and
	// keeps url only when the answer names that hub, records url as its own, and
	// proves it holds this device's token's hash; else conflict, and nothing
	// changes (docs/specs/lodge-app.md#device). The token is never sent.
	Relocate(ctx context.Context, p *SyncRelocateParams) (*SyncHub, error)
	// Join implements sync.join. Sync a local vault with a hub vault: files the
	// hub has had at the same path match by hash, others are pushed as creates,
	// and the hub's heads are pulled.
	Join(ctx context.Context, p *SyncJoinParams) (*SyncStatus, error)
	// Leave implements sync.leave. Stop syncing a vault and drop its sync state;
	// its files stay.
	Leave(ctx context.Context, p *SyncLeaveParams) error
	// Status implements sync.status. The synced vaults' states.
	Status(ctx context.Context, p *SyncStatusParams) ([]SyncStatus, error)
	// Conflicts implements sync.conflicts. A synced vault's flagged files.
	Conflicts(ctx context.Context, p *SyncConflictsParams) ([]SyncConflict, error)
	// Resolve implements sync.resolve. Clear a file's conflict flag on the hub,
	// once the user has merged it by hand or kept it as it is.
	Resolve(ctx context.Context, p *SyncResolveParams) error
	// Reset implements sync.reset. Leave and join again, with a new replica;
	// files match by hash.
	Reset(ctx context.Context, p *SyncResetParams) (*SyncStatus, error)
	// Verify implements sync.verify. Compare a synced vault with its hub.
	Verify(ctx context.Context, p *SyncVerifyParams) (*VerifyReport, error)
	// History implements sync.history. The hub's revisions of a file, newest
	// first.
	History(ctx context.Context, p *SyncHistoryParams) ([]Revision, error)
	// ReadRevision implements sync.readRevision. A hub revision's content, for
	// the merge view: from this device's blob store when it has it, else fetched
	// from the hub (ADR-0018). Content the hub has pruned is notFound (ADR-0019);
	// like note.read, it reads at most 10 MB.
	ReadRevision(ctx context.Context, p *SyncReadRevisionParams) (*RevisionContent, error)
}

SyncService: On a device: pairing with hubs and syncing vaults through them (docs/design/sync.md, docs/specs/sync-protocol.md). The device token stays in notesd's secret store and never crosses this API.

type SyncState

type SyncState string

SyncState: What a vault's sync is doing.

const (
	// In step with the hub as far as the device knows.
	SyncStateIdle SyncState = "idle"
	// Pushing or pulling.
	SyncStateSyncing SyncState = "syncing"
	// The hub cannot be reached; changes wait and sync on reconnect.
	SyncStateOffline SyncState = "offline"
	// The hub refused the device token: pair again.
	SyncStateRevoked SyncState = "revoked"
	// The hub no longer serves the vault as the device knew it: sync.reset.
	SyncStateReset SyncState = "reset"
)

func (SyncState) Valid

func (v SyncState) Valid() bool

Valid reports whether v is one of the declared values.

type SyncStatus

type SyncStatus struct {
	VaultID int64 `json:"vaultId"`
	// The hub's URL.
	URL string `json:"url"`
	// The hub vault's name.
	HubVault string    `json:"hubVault"`
	State    SyncState `json:"state"`
	// The highest sequence number whose heads the device applied.
	Cursor int64 `json:"cursor"`
	// The hub log's latest sequence number, as last seen.
	HubSeq int64 `json:"hubSeq"`
	// Files with a change to push, and local conflict versions not yet pushed.
	Pending int64 `json:"pending"`
	// Flagged files.
	Conflicts int64         `json:"conflicts"`
	Refused   []SyncRefusal `json:"refused"`
	// Pulled paths this device ignores or cannot hold.
	Skipped []string `json:"skipped"`
	// When the device was last in step with the hub.
	SyncedAt *time.Time `json:"syncedAt,omitzero"`
	// The last failure, while offline, revoked or reset.
	Error *string `json:"error,omitzero"`
}

SyncStatus: A synced vault's state.

type SyncStatusParams

type SyncStatusParams struct {
	// Only this vault.
	VaultID *int64 `json:"vaultId,omitzero"`
}

SyncStatusParams holds the params of sync.status.

type SyncVerifyParams

type SyncVerifyParams struct {
	VaultID int64 `json:"vaultId"`
}

SyncVerifyParams holds the params of sync.verify.

type TagCount

type TagCount struct {
	// As first spelled, without '#'; nested tags are listed whole (a/b), and
	// their parents only when a note has the parent itself.
	Tag string `json:"tag"`
	// Notes with the tag, ignoring case.
	Count int64 `json:"count"`
}

TagCount: A tag and how many notes have it.

type Vault

type Vault struct {
	// Stable local identifier.
	ID int64 `json:"id"`
	// Display name; the directory's base name unless one was given.
	Name string `json:"name"`
	// Absolute, cleaned path of the vault directory.
	Path      string    `json:"path"`
	CreatedAt time.Time `json:"createdAt"`
}

Vault: A registered vault.

type VaultAddParams

type VaultAddParams struct {
	// Absolute path of the vault directory.
	Path string `json:"path"`
	// Display name; defaults to the directory's base name.
	Name *string `json:"name,omitzero"`
	// Make the directory first; its parent must exist and it must not.
	Create *bool `json:"create,omitzero"`
}

VaultAddParams holds the params of vault.add.

type VaultAdded

type VaultAdded struct {
	Vault Vault `json:"vault"`
}

VaultAdded: A vault was registered.

func (VaultAdded) Durable

func (VaultAdded) Durable() bool

Durable reports whether VaultAdded is kept in the changes log.

func (VaultAdded) EventName

func (VaultAdded) EventName() string

EventName is the wire name of VaultAdded.

type VaultClient

type VaultClient struct {
	// contains filtered or unexported fields
}

VaultClient calls the vault methods; it implements VaultService.

func (VaultClient) Add

func (x VaultClient) Add(ctx context.Context, p *VaultAddParams) (*Vault, error)

Add calls vault.add.

func (VaultClient) Configure

Configure calls vault.configure.

func (VaultClient) List

func (x VaultClient) List(ctx context.Context, p *VaultListParams) ([]Vault, error)

List calls vault.list.

func (VaultClient) Reindex

Reindex calls vault.reindex.

func (VaultClient) Remove

Remove calls vault.remove.

func (VaultClient) Settings

Settings calls vault.settings.

func (VaultClient) Status

Status calls vault.status.

type VaultConfigureParams

type VaultConfigureParams struct {
	ID                 int64            `json:"id"`
	DailyFolder        *string          `json:"dailyFolder,omitzero"`
	DailyFormat        *string          `json:"dailyFormat,omitzero"`
	DailyTemplate      *string          `json:"dailyTemplate,omitzero"`
	TemplateFolder     *string          `json:"templateFolder,omitzero"`
	TemplateDateFormat *string          `json:"templateDateFormat,omitzero"`
	TemplateTimeFormat *string          `json:"templateTimeFormat,omitzero"`
	NewNoteLocation    *NewNoteLocation `json:"newNoteLocation,omitzero"`
	NewNoteFolder      *string          `json:"newNoteFolder,omitzero"`
	AttachmentFolder   *string          `json:"attachmentFolder,omitzero"`
	LinkFormat         *LinkFormat      `json:"linkFormat,omitzero"`
	Wikilinks          *bool            `json:"wikilinks,omitzero"`
	UpdateLinks        *bool            `json:"updateLinks,omitzero"`
	Ignore             []string         `json:"ignore,omitzero"`
}

VaultConfigureParams holds the params of vault.configure.

type VaultConfigured

type VaultConfigured struct {
	ID int64 `json:"id"`
}

VaultConfigured: A vault's settings changed, by vault.configure or in .frostnotes/vault.yaml.

func (VaultConfigured) Durable

func (VaultConfigured) Durable() bool

Durable reports whether VaultConfigured is kept in the changes log.

func (VaultConfigured) EventName

func (VaultConfigured) EventName() string

EventName is the wire name of VaultConfigured.

type VaultFile

type VaultFile struct {
	Path string   `json:"path"`
	Kind FileKind `json:"kind"`
	// The SHA-256 of the content, lowercase hex: a write's base, and the name of
	// its bytes for the app (ADR-0023).
	Hash string `json:"hash"`
	// In bytes.
	Size int64 `json:"size"`
	// The file's modification time.
	ModifiedAt time.Time `json:"modifiedAt"`
}

VaultFile: A file of a vault, as the index has it.

type VaultFiles

type VaultFiles struct {
	// By path.
	Files []VaultFile `json:"files"`
	// Every folder below the root, empty ones included, by path; the root is not
	// listed.
	Folders []string `json:"folders"`
}

VaultFiles: Every file and folder of a vault.

type VaultListParams

type VaultListParams struct{}

VaultListParams holds the params of vault.list.

type VaultReindexParams

type VaultReindexParams struct {
	ID int64 `json:"id"`
}

VaultReindexParams holds the params of vault.reindex.

type VaultRemoveParams

type VaultRemoveParams struct {
	ID int64 `json:"id"`
}

VaultRemoveParams holds the params of vault.remove.

type VaultRemoved

type VaultRemoved struct {
	ID int64 `json:"id"`
}

VaultRemoved: A vault was forgotten.

func (VaultRemoved) Durable

func (VaultRemoved) Durable() bool

Durable reports whether VaultRemoved is kept in the changes log.

func (VaultRemoved) EventName

func (VaultRemoved) EventName() string

EventName is the wire name of VaultRemoved.

type VaultScan

type VaultScan struct {
	Status ScanStatus `json:"status"`
}

VaultScan: A vault's scan started, made progress (at most every 250 ms) or ended.

func (VaultScan) Durable

func (VaultScan) Durable() bool

Durable reports whether VaultScan is kept in the changes log.

func (VaultScan) EventName

func (VaultScan) EventName() string

EventName is the wire name of VaultScan.

type VaultService

type VaultService interface {
	// List implements vault.list. Every registered vault, by name.
	List(ctx context.Context, p *VaultListParams) ([]Vault, error)
	// Add implements vault.add. Register a directory as a vault. The path must be
	// absolute and name an existing directory, and no registered vault may
	// contain it or lie inside it. With create, notesd makes the directory first
	// (Create new vault, ADR-0024): its parent must exist and it must not; it is
	// made only when it may be registered.
	Add(ctx context.Context, p *VaultAddParams) (*Vault, error)
	// Remove implements vault.remove. Forget a vault. Its directory and files are
	// untouched.
	Remove(ctx context.Context, p *VaultRemoveParams) error
	// Status implements vault.status. The state of a vault's index and its scans.
	Status(ctx context.Context, p *VaultStatusParams) (*ScanStatus, error)
	// Reindex implements vault.reindex. Read every file of a vault again and
	// rebuild its index, as if none matched it. File IDs and versions are kept,
	// so nothing is lost. The scan runs in the background; vault.scan events
	// report its progress.
	Reindex(ctx context.Context, p *VaultReindexParams) (*ScanStatus, error)
	// Settings implements vault.settings. A vault's settings, and where each
	// comes from.
	Settings(ctx context.Context, p *VaultSettingsParams) (*VaultSettings, error)
	// Configure implements vault.configure. Change a vault's settings: each field
	// given is written to .frostnotes/vault.yaml, atomically, keeping the rest of
	// the file; the others keep their values. This is the only method that writes
	// .frostnotes/ (ADR-0021).
	Configure(ctx context.Context, p *VaultConfigureParams) (*VaultSettings, error)
}

VaultService: The vaults this notesd owns: directories of markdown notes (ADR-0003). Registering a vault never writes to it; add with create makes its empty directory first (ADR-0024).

type VaultSettings

type VaultSettings struct {
	// Where daily notes go; empty is the vault root.
	DailyFolder string `json:"dailyFolder"`
	// A moment.js format for a daily note's name; may hold '/' to name
	// subfolders.
	DailyFormat string `json:"dailyFormat"`
	// The daily-note template's path; empty for none.
	DailyTemplate string `json:"dailyTemplate"`
	// Where templates live; empty when unset.
	TemplateFolder string `json:"templateFolder"`
	// {{date}}'s moment.js format.
	TemplateDateFormat string `json:"templateDateFormat"`
	// {{time}}'s moment.js format.
	TemplateTimeFormat string          `json:"templateTimeFormat"`
	NewNoteLocation    NewNoteLocation `json:"newNoteLocation"`
	// With newNoteLocation folder: that folder; empty is the root.
	NewNoteFolder string `json:"newNoteFolder"`
	// Where pasted and dropped files go, as Obsidian writes it: "/" the vault
	// root, "./" the note's folder, "./NAME" a folder NAME beside the note, else
	// a folder's path.
	AttachmentFolder string     `json:"attachmentFolder"`
	LinkFormat       LinkFormat `json:"linkFormat"`
	// New links are [[wikilinks]] rather than markdown links.
	Wikilinks bool `json:"wikilinks"`
	// Moves rewrite links without asking (Obsidian's Automatically update
	// internal links).
	UpdateLinks bool `json:"updateLinks"`
	// Gitignore-style patterns of files the vault leaves out (Obsidian's Excluded
	// files).
	Ignore []string `json:"ignore"`
	// Where each setting above comes from, by its field name.
	Sources map[string]SettingSource `json:"sources"`
}

VaultSettings: A vault's settings (docs/design/vault.md#on-disk; ADR-0021): from .frostnotes/vault.yaml, else Obsidian's .obsidian/ files, else Obsidian's defaults.

type VaultSettingsParams

type VaultSettingsParams struct {
	ID int64 `json:"id"`
}

VaultSettingsParams holds the params of vault.settings.

type VaultStatusParams

type VaultStatusParams struct {
	ID int64 `json:"id"`
}

VaultStatusParams holds the params of vault.status.

type VerifyReport

type VerifyReport struct {
	// No file differs and every push is on record.
	Ok bool `json:"ok"`
	// Files compared.
	Files int64 `json:"files"`
	// Paths whose file differs from the hub's head, or that only one side has.
	Differing []string `json:"differing"`
	// Answered pushes the hub has no revision of with the pushed hash.
	Unrecorded []int64 `json:"unrecorded"`
	// Flagged files.
	Conflicts []string `json:"conflicts"`
}

VerifyReport: How a synced vault compares with its hub (M2's exit evidence).

type Version

type Version struct {
	ID int64 `json:"id"`
	// The file's path when this version was made.
	Path string `json:"path"`
	// The content's hash; empty for a deletion.
	Hash   string        `json:"hash"`
	Size   int64         `json:"size"`
	At     time.Time     `json:"at"`
	Source VersionSource `json:"source"`
	// The writer's name; empty for an outside edit.
	Author string `json:"author"`
	// This version records the file's deletion.
	Deleted bool `json:"deleted"`
	// A writer's content that lost a conflicting hunk in a merge: kept so nothing
	// is lost, but never the file's content.
	Conflict bool `json:"conflict"`
}

Version: A version of a file, as notesd wrote or scanned it.

type VersionContent

type VersionContent struct {
	Version Version `json:"version"`
	// As note.read gives content: bytes that are not UTF-8 read as U+FFFD
	// (ADR-0014); empty for a deletion.
	Content string `json:"content"`
}

VersionContent: A version's content.

type VersionSource

type VersionSource string

VersionSource: Who made a version.

const (
	// A client: the app, the web app or notesctl.
	VersionSourceEditor VersionSource = "editor"
	// An agent, through MCP.
	VersionSourceAgent VersionSource = "agent"
	// Another program: notesd found the change on disk.
	VersionSourceOutside VersionSource = "outside"
	// Another device, through the hub.
	VersionSourceSync VersionSource = "sync"
)

func (VersionSource) Valid

func (v VersionSource) Valid() bool

Valid reports whether v is one of the declared values.

type WriteResult

type WriteResult struct {
	Path string `json:"path"`
	// The new content's hash: the base for the next write.
	Hash string `json:"hash"`
	// The file had changed since the base, and notesd merged the write into it.
	Merged bool `json:"merged"`
	// What the file now holds, when merged is true.
	Content *string `json:"content,omitzero"`
	// Hunks both sides changed differently; the file's newer side of each stands,
	// and the content sent is kept as a conflict version (ADR-0005).
	Conflicts int64 `json:"conflicts"`
	// The conflict version's id, when conflicts is above zero: what
	// note.readVersion reads back.
	ConflictVersion *int64 `json:"conflictVersion,omitzero"`
	// When merged is true: who made the version the write was merged into.
	MergedSource *VersionSource `json:"mergedSource,omitzero"`
	// When merged is true: that version's author; empty for an outside edit.
	MergedAuthor *string `json:"mergedAuthor,omitzero"`
}

WriteResult: A note after a write.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL