vault

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 19 Imported by: 0 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 vault loads an Obsidian vault that is also an OKF bundle, keeps an in-memory snapshot (concepts, link graph) and performs safe writes.

Nothing derived is stored inside the vault: the snapshot is rebuilt from the Markdown files, so the vault stays fully committable to git.

Index

Constants

View Source
const (
	Error   = "error"
	Warning = "warning"
)

Severity of a lint finding.

View Source
const (
	ReasonStale      = "stale"      // stale_after has passed
	ReasonUnverified = "unverified" // written by an agent and not checked by a person since
	ReasonDraft      = "draft"
	ReasonBroken     = "broken-links"
	ReasonNoOwner    = "no-owner" // only reported when the vault configures owners
)

Review reasons.

View Source
const IgnoreFile = ".vaultignore"

IgnoreFile names the vault-root file listing paths okvault leaves out of the index, in a subset of .gitignore syntax.

Variables

View Source
var ErrConflict = errors.New("vault: conflict")

ErrConflict means the note changed since the caller read it.

View Source
var ErrInvalidPath = errors.New("vault: invalid path")

ErrInvalidPath is returned for write targets outside the vault or not allowed.

Functions

func CleanPath

func CleanPath(p string) (string, error)

CleanPath validates a vault-relative concept path supplied by a client.

func Revision

func Revision(src []byte) string

Revision identifies the exact bytes of a note on disk. kb_write accepts it as base_revision so two writers cannot silently overwrite each other.

Types

type Commit

type Commit struct {
	SHA   string `json:"sha,omitempty"`
	Error string `json:"error,omitempty"` // the write is on disk but was not committed
}

Commit reports the commit that recorded a write.

type Committer

type Committer interface {
	// Begin is called before a write touches any file. It blocks other git
	// work on the checkout (including other okvault processes) until end runs.
	Begin() (end func(), err error)
	// Commit commits exactly these vault-relative paths (nothing else that
	// happens to be staged). It returns "" when there was nothing to commit.
	Commit(paths []string, subject, body string) (sha string, err error)
}

Committer records changed vault files as a commit. gitsync implements it; the vault calls it after each write while holding its write lock.

type Finding

type Finding struct {
	Severity string `json:"severity"`
	Path     string `json:"path"`
	Message  string `json:"message"`
}

Finding is one lint result.

type Ignore added in v0.3.0

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

Ignore is a parsed .vaultignore: gitignore-style rules, the last match wins.

Supported: blank lines and # comments, ! to re-include, a trailing / for directories only, a leading / (or any inner /) to anchor the pattern at the vault root, *, ? and **. A pattern without a slash matches a name at any depth. As in git, a file inside an ignored directory cannot be re-included.

func LoadIgnore added in v0.3.0

func LoadIgnore(root string) (*Ignore, error)

LoadIgnore reads root/.vaultignore; a missing file ignores nothing.

func ParseIgnore added in v0.3.0

func ParseIgnore(src string) *Ignore

ParseIgnore parses .vaultignore text.

func (*Ignore) Empty added in v0.3.0

func (ig *Ignore) Empty() bool

Empty reports whether no rule is set.

func (*Ignore) Match added in v0.3.0

func (ig *Ignore) Match(rel string, dir bool) bool

Match reports whether a vault-relative, slash-separated path is ignored, itself or through one of its parent directories.

type Issue

type Issue struct {
	Path    string `json:"path"`
	Message string `json:"message"`
	Warning bool   `json:"warning,omitempty"` // a recommendation, not a load failure
}

Issue is a problem found while loading (or linting) a file.

type Locked

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

Locked is the vault as seen by a git operation holding the write lock.

func (Locked) RegenerateIndexes

func (l Locked) RegenerateIndexes() ([]string, error)

RegenerateIndexes rewrites generated index.md files and repairs log.md.

func (Locked) Reload

func (l Locked) Reload() (*Snapshot, error)

Reload rebuilds the snapshot from the work tree.

type ReviewItem

type ReviewItem struct {
	Path      string     `json:"path"`
	Title     string     `json:"title"`
	Type      string     `json:"type"`
	Owners    []string   `json:"owners,omitempty"`
	Reasons   []string   `json:"reasons"`
	Generated *okf.Stamp `json:"generated,omitempty"`
	Verified  *okf.Stamp `json:"last_verified,omitempty"`
	Detail    string     `json:"detail,omitempty"`
}

ReviewItem is a note that needs a person's attention.

type ReviewQuery

type ReviewQuery struct {
	Owner  string // only notes owned by this person or group (case-insensitive)
	Reason string // only notes with this reason
}

ReviewQuery filters the review queue.

type Snapshot

type Snapshot struct {
	Concepts  map[string]*okf.Concept // by vault-relative path
	Links     map[string][]string     // outgoing, resolved paths
	Backlinks map[string][]string     // incoming
	Broken    map[string][]string     // unresolved targets per source
	Issues    []Issue
	Dirs      map[string]bool // directories containing concepts (vault-relative, "." is root)
	LoadedAt  time.Time

	Config      *config.Config         // team settings from .okvault.yaml (never nil)
	Revisions   map[string]string      // note path -> revision of its bytes on disk
	Tickets     map[string][]TicketRef // ticket key -> related notes, linked first
	NoteTickets map[string][]string    // note path -> ticket keys (linked and mentioned)
	Ignore      *Ignore                // rules from .vaultignore (never nil)
}

Snapshot is an immutable view of the vault at one point in time.

func (*Snapshot) Owners

func (s *Snapshot) Owners(p string) []string

Owners returns a note's owners: its `owners` frontmatter, else the folder default from .okvault.yaml.

func (*Snapshot) Review

func (s *Snapshot) Review(q ReviewQuery, now time.Time) []ReviewItem

Review lists notes needing attention, most reasons first.

func (*Snapshot) Sorted

func (s *Snapshot) Sorted() []string

Sorted returns concept paths in lexical order.

type TicketRef

type TicketRef struct {
	Path   string `json:"path"`
	Linked bool   `json:"linked"` // listed in the note's `tickets` frontmatter; false = mentioned in the body
}

TicketRef is a note related to a ticket.

type Vault

type Vault struct {
	Root string // absolute

	// Git, when set, records okvault's writes as commits.
	Git Committer
	// contains filtered or unexported fields
}

Vault is a vault root on disk.

func Open

func Open(root string) (*Vault, error)

Open opens a vault root and loads a first snapshot.

func (*Vault) Busy

func (v *Vault) Busy() bool

Busy reports whether a git operation is rewriting the work tree.

func (*Vault) Exclusive

func (v *Vault) Exclusive(fn func(Locked) error) error

Exclusive runs fn with writes blocked and Busy reporting true, for git operations that rewrite the work tree (rebase, reset). The file watcher checks Busy so it does not regenerate indexes into a tree git is rewriting.

func (*Vault) Lint

func (v *Vault) Lint() []Finding

Lint checks OKF conformance (errors) and vault hygiene (warnings). Errors are the spec's own conformance rules; warnings are recommendations.

func (*Vault) ReadFile

func (v *Vault) ReadFile(rel string) ([]byte, error)

ReadFile reads a vault-relative file (any file, used for index.md/log.md).

func (*Vault) RegenerateIndexes

func (v *Vault) RegenerateIndexes() ([]string, error)

RegenerateIndexes rewrites every okvault-owned index.md (and creates missing ones), and repairs log.md after a merge (see okf.NormalizeLog). Hand-written index.md files without the generated marker are left alone.

func (*Vault) Reload

func (v *Vault) Reload() (*Snapshot, error)

Reload rebuilds the snapshot from disk.

func (*Vault) Snapshot

func (v *Vault) Snapshot() *Snapshot

Snapshot returns the current snapshot.

func (*Vault) Verify

func (v *Vault) Verify(p, by string, now time.Time) (*WriteResult, error)

Verify records that a person checked a note: it appends `{by, at}` to the OKF `verified` list and moves `stale_after` one review interval ahead. It does not touch `generated`, so the note reads as human-checked.

func (*Vault) Watch

func (v *Vault) Watch(ctx context.Context, debounce time.Duration, onReload func(*Snapshot)) error

Watch reloads the vault when Markdown files change (debounced) and calls onReload with the new snapshot. It blocks until ctx is done.

func (*Vault) Write

func (v *Vault) Write(req WriteRequest, now time.Time) (*WriteResult, error)

Write creates or updates a concept, then refreshes the directory index.md and records the change in the root log.md.

type WriteRequest

type WriteRequest struct {
	Path        string
	Type        string
	Title       string
	Description string
	Tags        []string
	Aliases     []string
	Status      string
	Body        string
	Tickets     []string // ticket keys (replaces `tickets` when non-nil)
	Owners      []string // owners (replaces `owners` when non-nil)
	Mode        string   // "create" (fail if exists), "update" (fail if missing), "upsert"
	Author      string   // recorded in generated.by
	Note        string   // log message
	// BaseRevision, when set, must equal the note's current revision (from
	// kb_get); otherwise the write fails with ErrConflict instead of
	// overwriting someone else's change.
	BaseRevision string
}

WriteRequest describes a concept to create or update.

type WriteResult

type WriteResult struct {
	Path     string  `json:"path"`
	Created  bool    `json:"created"`
	Revision string  `json:"revision"`        // revision of the written note
	Index    string  `json:"index,omitempty"` // index file regenerated, if any
	Git      *Commit `json:"git,omitempty"`   // the commit recording it, when git is on
}

WriteResult reports what a write did.

Jump to

Keyboard shortcuts

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