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
- Variables
- func CleanPath(dir string) (string, error)
- func TitleOf(rel string) string
- func Walk(ctx context.Context, root string) ([]file, error)
- type Note
- type Result
- type Service
- func (s *Service) Add(ctx context.Context, dir string, agents bool) (store.BrainVault, Result, error)
- func (s *Service) Refresh(ctx context.Context, id int64, force bool) (store.BrainVault, Result, error)
- func (s *Service) RefreshAll(ctx context.Context)
- func (s *Service) Remove(ctx context.Context, id int64) error
- func (s *Service) Run(ctx context.Context)
- func (s *Service) SetAgents(ctx context.Context, id int64, on bool) (store.BrainVault, error)
Constants ¶
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.
const ExcerptRunes = 400
ExcerptRunes is how much of a note's body is kept: Second Brain's summary length (store.BrainSummaryRunes).
Variables ¶
var ErrNotAbsolute = errors.New("the vault's path must be absolute")
ErrNotAbsolute is a vault path that is not absolute.
var ErrNotFolder = errors.New("not a folder on this computer")
ErrNotFolder is a vault path that is not a folder on this machine.
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 ¶
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.
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 ¶
RefreshAll looks at every vault: a walk, and reads only of what changed.