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
- Variables
- func CleanPath(p string) (string, error)
- func Revision(src []byte) string
- type Commit
- type Committer
- type Finding
- type Ignore
- type Issue
- type Locked
- type ReviewItem
- type ReviewQuery
- type Snapshot
- type TicketRef
- type Vault
- func (v *Vault) Busy() bool
- func (v *Vault) Exclusive(fn func(Locked) error) error
- func (v *Vault) Lint() []Finding
- func (v *Vault) ReadFile(rel string) ([]byte, error)
- func (v *Vault) RegenerateIndexes() ([]string, error)
- func (v *Vault) Reload() (*Snapshot, error)
- func (v *Vault) Snapshot() *Snapshot
- func (v *Vault) Verify(p, by string, now time.Time) (*WriteResult, error)
- func (v *Vault) Watch(ctx context.Context, debounce time.Duration, onReload func(*Snapshot)) error
- func (v *Vault) Write(req WriteRequest, now time.Time) (*WriteResult, error)
- type WriteRequest
- type WriteResult
Constants ¶
const ( Error = "error" Warning = "warning" )
Severity of a lint finding.
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.
const IgnoreFile = ".vaultignore"
IgnoreFile names the vault-root file listing paths okvault leaves out of the index, in a subset of .gitignore syntax.
Variables ¶
var ErrConflict = errors.New("vault: conflict")
ErrConflict means the note changed since the caller read it.
var ErrInvalidPath = errors.New("vault: invalid path")
ErrInvalidPath is returned for write targets outside the vault or not allowed.
Functions ¶
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
LoadIgnore reads root/.vaultignore; a missing file ignores nothing.
func ParseIgnore ¶ added in v0.3.0
ParseIgnore parses .vaultignore text.
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 ¶
RegenerateIndexes rewrites generated index.md files and repairs log.md.
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 ¶
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.
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 (*Vault) Exclusive ¶
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 ¶
Lint checks OKF conformance (errors) and vault hygiene (warnings). Errors are the spec's own conformance rules; warnings are recommendations.
func (*Vault) RegenerateIndexes ¶
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) Verify ¶
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 ¶
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.