obsidian

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 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 obsidian imports an Obsidian vault into Second Brain (ADR-079; 03-contracts.md § Obsidian vaults). It reads Markdown files on this machine and never writes into the vault: a note becomes a node, its [[links]] edges, its #tags topics. The importer makes no network or model calls; sharing imported content with agents is a separate opt-in.

Index

Constants

View Source
const (
	MaxNotes     = 50_000
	MaxNoteBytes = 4 << 20
	// Interval is how often every vault is looked at: a walk that stats each
	// note and reads only the ones whose time or size changed.
	Interval = 10 * time.Minute
	// FirstLook is how long after the daemon starts the first look waits.
	FirstLook = 2 * time.Minute
)

Limits on what one vault may make the daemon do (resources are the moat): how many notes a vault may hold, how much of one note is read, and how often the vaults are looked at without being asked.

View Source
const ExcerptRunes = 400

ExcerptRunes is how much of a note's body is kept: Second Brain's summary length (store.BrainSummaryRunes).

Variables

View Source
var ErrNotAbsolute = errors.New("the vault's path must be absolute")

ErrNotAbsolute is a vault path that is not absolute.

View Source
var ErrNotFolder = errors.New("not a folder on this computer")

ErrNotFolder is a vault path that is not a folder on this machine.

View Source
var ErrTooMany = fmt.Errorf("more than %d notes: pick the vault's own folder", MaxNotes)

ErrTooMany is a folder with more notes than a vault may hold.

Functions

func CleanPath

func CleanPath(dir string) (string, error)

CleanPath checks a folder the user picked: absolute, a folder, cleaned.

func TitleOf

func TitleOf(rel string) string

TitleOf is a note's title from its path in the vault: the file name without the .md extension.

func Walk

func Walk(ctx context.Context, root string) ([]file, error)

Walk lists a vault's Markdown notes: every .md file under root, outside folders whose name starts with a dot (.obsidian, .trash, .git) and node_modules, not following links. Attachments are never opened.

Types

type Note

type Note struct {
	// Title is the file's name without .md, as Obsidian names a note.
	Title string
	// Aliases are the frontmatter's aliases (or alias), in order, without
	// duplicates.
	Aliases []string
	// Tags are the frontmatter's tags and the inline #tags, without the
	// '#', in order of first appearance, without duplicates (compared in
	// lower case).
	Tags []string
	// Links are the targets of [[links]], the note's name only: no heading
	// (#…), block (^…), display text (|…), folder or .md. Self-links and
	// empty targets ([[#Heading]]) are left out.
	Links []string
	// Excerpt is the body, frontmatter and Markdown dropped, flattened to
	// one paragraph and clipped (ExcerptRunes): what Second Brain shows as
	// the note's summary.
	Excerpt string
}

Note is what one Markdown file says, as the import uses it.

func Parse

func Parse(rel string, data []byte) Note

Parse reads one note. rel is its path in the vault, slash-separated.

type Result

type Result struct {
	// Notes is how many Markdown notes the vault holds.
	Notes int `json:"notes"`
	// Read is how many were read: new or changed since the last scan.
	Read int `json:"read"`
	// Added, Changed and Removed count note files new to Second Brain,
	// changed, and gone from the vault.
	Added   int `json:"added"`
	Changed int `json:"changed"`
	Removed int `json:"removed"`
	// Merged is how many added notes joined a node that was already there
	// (the same title or alias) instead of making one.
	Merged int `json:"merged"`
	// Links is how many edges the vault's import wants now; Linked and
	// Unlinked how many it added and dropped in this scan.
	Links    int `json:"links"`
	Linked   int `json:"linked"`
	Unlinked int `json:"unlinked"`
	// Skipped is how many notes could not be kept (no title, unreadable).
	Skipped int `json:"skipped"`
	// Ms is how long the scan took.
	Ms int64 `json:"ms"`
	// WriteMs includes acquiring, running and committing the write transaction.
	WriteMs int64 `json:"write_ms"`
}

Result is what one scan of a vault did.

type Service

type Service struct {
	Store *store.Store
	Log   *slog.Logger
	// Changed is told when a scan changed Second Brain, to publish a frame.
	Changed func(vaultID int64, removed bool)
	Now     func() time.Time
	// contains filtered or unexported fields
}

Service imports and refreshes vaults: one scan at a time.

func (*Service) Add

func (s *Service) Add(ctx context.Context, dir string, agents bool) (store.BrainVault, Result, error)

Add imports a vault: the folder is checked, kept, and scanned at once.

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context, id int64, force bool) (store.BrainVault, Result, error)

Refresh scans one vault again. force rereads every note and resolves every link and tag, including edits that kept their previous size and timestamp.

func (*Service) RefreshAll

func (s *Service) RefreshAll(ctx context.Context)

RefreshAll looks at every vault: a walk, and reads only of what changed.

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, id int64) error

Remove takes a vault out of Second Brain.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run looks at every vault FirstLook after it starts and every Interval after that, until ctx ends. No file watcher: a walk that stats is cheap on a large vault, a watcher per folder is not.

func (*Service) SetAgents

func (s *Service) SetAgents(ctx context.Context, id int64, on bool) (store.BrainVault, error)

SetAgents turns a vault's notes reaching agents on or off.

Jump to

Keyboard shortcuts

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