read

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 14 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 read answers queries over a vault: it scans the typed documents, filters and searches them, counts tags and builds the context bundle. It never changes a file.

Index

Constants

View Source
const (
	ContextTagDays = 30
	ContextTopTags = 10
)
View Source
const (
	DefaultListLimit = 50
	MaxListLimit     = 500
)
View Source
const (
	SortDateDesc = "date_desc"
	SortDateAsc  = "date_asc"
	SortTitle    = "title"
)

Orders a Filter can sort by. Every order breaks ties by path, ascending.

View Source
const (
	DefaultSearchLimit = 20
	MaxSearchLimit     = 500
	// MaxHitLines is how many matching lines a hit reports; Total counts all.
	MaxHitLines = 3
)

Variables

This section is empty.

Functions

func FormatISOWeek

func FormatISOWeek(t time.Time) string

FormatISOWeek formats t's ISO 8601 week as YYYY-Www (for example 2026-W03).

func MatchTag

func MatchTag(pattern, tag string) bool

MatchTag reports whether tag matches pattern. A trailing "/" makes the pattern a prefix ("issue/" matches "issue/x"); otherwise it is an exact match.

Types

type Doc

type Doc struct {
	Path, Type, Title string
	Tags              []string
	Date              time.Time // the type's date field, else the file's modification time
	DateFromMtime     bool
	Frontmatter       *yaml.Node // the mapping; read its fields with vault.Values
	Body              []byte
	BodyLine          int // 1-based file line where Body starts
	// contains filtered or unexported fields
}

Doc is one typed document: a .md file whose frontmatter has a type.

func (*Doc) BuildMeta

func (d *Doc) BuildMeta(fields []string) Meta

BuildMeta returns d's metadata, with each of fields that d sets.

func (*Doc) DateSource

func (d *Doc) DateSource() string

DateSource says where Date came from: "field" for the type's date field, "mtime" for the file's modification time.

func (*Doc) RenderField

func (d *Doc) RenderField(field string) string

RenderField renders field as a listing shows it: its values that are not "", joined by ", ", or "" when there are none.

type Filter

type Filter struct {
	Type         string      // exact type name
	Tags         []string    // all must match; a trailing "/" is a prefix
	AnyTags      []string    // at least one must match
	Where        vault.Where // frontmatter equality; a list means any of
	Since, Until *time.Time  // inclusive, compared as calendar dates
	Sort         string      // date_desc (default), date_asc, title
	Limit        int         // 0 means DefaultListLimit; capped at MaxListLimit
}

Filter selects and orders documents. Every set field must match (AND).

func (Filter) Apply

func (f Filter) Apply(docs []*Doc) ([]*Doc, error)

Apply filters, sorts and limits docs. It does not touch the input slice. Ties in every sort are broken by path, ascending.

type Group

type Group struct {
	Values []string `json:"values"` // one per grouped field, in the order asked
	Count  int      `json:"count"`
}

Group is one distinct combination of field values and how many documents have it.

type Hit

type Hit struct {
	Path  string `json:"path"`
	Title string `json:"title"`
	Total int    `json:"total"` // all matching lines
	Lines []Line `json:"lines"` // at most MaxHitLines, in file order
}

type Line

type Line struct {
	N    int    `json:"n"`
	Text string `json:"text"`
}

Line is one matching file line: 1-based number and the verbatim text.

type Meta

type Meta struct {
	Path       string            `json:"path"`
	Type       string            `json:"type"`
	Title      string            `json:"title"`
	Tags       []string          `json:"tags"`
	Date       string            `json:"date"`
	DateSource string            `json:"date_source"` // field (the type's date field) or mtime
	Updated    string            `json:"updated,omitempty"`
	Fields     map[string]string `json:"fields,omitempty"` // the fields to show that the document sets
}

Meta is a document's metadata as a listing shows it. Its keys, but path and fields, are config.AlwaysShown, so no field to show can collide with one.

type Problem

type Problem struct {
	Path string `json:"path"`
	Msg  string `json:"msg"`
}

Problem is a file the vault could not fully use, with what to do about it.

type Reader

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

func New

func New(v *vault.Vault, cfg *config.Config, now func() time.Time) *Reader

New returns a Reader for v. now is the clock that sets "today".

func (*Reader) BuildContext

func (r *Reader) BuildContext(day time.Time) (string, error)

BuildContext builds the start-of-conversation bundle for day: the working rules, the week document for day's ISO week, the configured open-item and recent queries as metadata lines, and the most used recent tags. Sections are introduced by "==== name ====" lines. It is deterministic for a given day and vault content.

Plain text, not JSON: it costs fewer tokens and reads well in a chat, and a "====" line cannot be confused with the week document's "##" headings. testdata/context.golden is the specification of the format.

func (*Reader) CountTags

func (r *Reader) CountTags(prefix string) ([]TagCount, error)

CountTags counts tags over typed documents, most used first, then by name, followed by the vocabulary's unused tags with count 0. prefix limits both to tags starting with it.

func (*Reader) Group

func (r *Reader) Group(f Filter, fields []string) ([]Group, []Problem, error)

Group scans the vault, keeps the documents f matches (its sort and limit do not apply), and counts them per combination of the fields' values: most documents first, then by the values. A list field counts a document once under each of its values.

func (*Reader) List

func (r *Reader) List(f Filter) ([]*Doc, []Problem, error)

List scans the vault and applies f. Problems are files the scan had to skip.

func (*Reader) Now

func (r *Reader) Now() time.Time

func (*Reader) ReadDoc

func (r *Reader) ReadDoc(p string) (rel string, content []byte, hash string, err error)

ReadDoc reads the file at a vault-relative path, or the one file a [[wikilink]] or bare name points to.

func (*Reader) Scan

func (r *Reader) Scan() ([]*Doc, []Problem, error)

Scan reads every typed document under the vault, sorted by path. It skips dot-folders and dot-files, the root templates/ folder, symlinks, and files without frontmatter or without a type. A file with broken frontmatter is skipped and reported as a Problem, so a typo neither hides it nor fails every query.

Every call scans; there is no index. The server writes, so an index built at startup is stale after the first write, and one stored on disk is a second copy of the frontmatter that can drift. Add an mtime-keyed cache (#2) only if BenchmarkScan or a real vault measures slow.

func (*Reader) Search

func (r *Reader) Search(q, typ string, limit int) ([]Hit, error)

Search finds documents whose body or title field contains q, ignoring case. Other frontmatter fields (list_docs answers those) and file names are not searched, or every document carrying a tag would match. Hits are ordered by path. typ, when set, limits the search to one type.

type TagCount

type TagCount struct {
	Tag     string
	Count   int       // documents carrying the tag
	Last    time.Time // newest document date; zero when Count is 0
	Unknown bool      // not in the tags file (never set without one)
}

Jump to

Keyboard shortcuts

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