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
- func FormatISOWeek(t time.Time) string
- func MatchTag(pattern, tag string) bool
- type Doc
- type Filter
- type Group
- type Hit
- type Line
- type Meta
- type Problem
- type Reader
- func (r *Reader) BuildContext(day time.Time) (string, error)
- func (r *Reader) CountTags(prefix string) ([]TagCount, error)
- func (r *Reader) Group(f Filter, fields []string) ([]Group, []Problem, error)
- func (r *Reader) List(f Filter) ([]*Doc, []Problem, error)
- func (r *Reader) Now() time.Time
- func (r *Reader) ReadDoc(p string) (rel string, content []byte, hash string, err error)
- func (r *Reader) Scan() ([]*Doc, []Problem, error)
- func (r *Reader) Search(q, typ string, limit int) ([]Hit, error)
- type TagCount
Constants ¶
const ( ContextTagDays = 30 ContextTopTags = 10 )
const ( DefaultListLimit = 50 MaxListLimit = 500 )
const ( SortDateDesc = "date_desc" SortDateAsc = "date_asc" SortTitle = "title" )
Orders a Filter can sort by. Every order breaks ties by path, ascending.
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 ¶
FormatISOWeek formats t's ISO 8601 week as YYYY-Www (for example 2026-W03).
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) DateSource ¶
DateSource says where Date came from: "field" for the type's date field, "mtime" for the file's modification time.
func (*Doc) RenderField ¶
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).
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 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 Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func (*Reader) BuildContext ¶
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 ¶
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 ¶
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) ReadDoc ¶
ReadDoc reads the file at a vault-relative path, or the one file a [[wikilink]] or bare name points to.
func (*Reader) Scan ¶
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 ¶
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.