Documentation
¶
Overview ¶
Package kb owns all access to knowledge-base files.
Index ¶
- Variables
- func ApplyMove(root string, plan MovePlan) error
- func CanonicalID(id string) string
- func CaptureContent(text, title string, now time.Time) (string, string, error)
- func CommitWrite(root string, paths []string, message string, commitOnWrite bool) error
- func CommitWriteStatus(root string, paths []string, message string, commitOnWrite bool) (bool, error)
- func Content(body string, metadata *Frontmatter) (string, error)
- func Init(path string) error
- func LockWrites(root string) (func(), error)
- func NoteNotFound(id string) error
- func PreviewInit(path string) error
- func PreviewWrite(root, id, mode string) error
- func Resolve(target string, notes []Note) (string, bool)
- func ResolveLink(target string, notes []Note) (id, reason string)
- func RewriteLinks(body, old, new string, before, after []Note) (string, int)
- func Slug(text string) string
- func UnifiedDiff(oldPath, newPath, before, after string) string
- func ValidateID(id string, write bool) error
- type Details
- type Frontmatter
- type LinkRef
- type MoveChange
- type MovePlan
- type MoveResult
- type Note
- type Resolver
- type Rewritten
- type WriteResult
Constants ¶
This section is empty.
Variables ¶
var ErrWriteRefused = errors.New("write refused")
Functions ¶
func CanonicalID ¶
CanonicalID is the spelling used for comparisons and public note IDs.
func CaptureContent ¶
CaptureContent shares timestamp, filename and frontmatter rules across front ends.
func CommitWrite ¶
CommitWrite stages and commits only the supplied root-relative paths.
func CommitWriteStatus ¶
func CommitWriteStatus(root string, paths []string, message string, commitOnWrite bool) (bool, error)
CommitWriteStatus reports whether CommitWrite actually advanced HEAD.
func Content ¶
func Content(body string, metadata *Frontmatter) (string, error)
Content serializes safe YAML frontmatter without interpreting body text.
func LockWrites ¶
LockWrites serializes file mutations and cache transactions across processes. The returned release function must run after reindexing and any git commit.
func NoteNotFound ¶
NoteNotFound gives file and index reads the same public error and exit identity.
func PreviewInit ¶
PreviewInit performs the same safety checks as Init without writing.
func PreviewWrite ¶
PreviewWrite validates a proposed write without creating directories or files.
func ResolveLink ¶
ResolveLink also explains unresolved references for the broken-link report.
func RewriteLinks ¶
RewriteLinks preserves resolved destinations across a move, retaining link suffixes.
func UnifiedDiff ¶
UnifiedDiff emits a valid whole-file unified hunk without external tools.
func ValidateID ¶
ValidateID shares path rules for reads and writes; writes refuse an accidental extension.
Types ¶
type Details ¶
type Details struct {
Problem map[string]string `json:"problem,omitempty" jsonschema:"Inspector problems by component"`
Embeddings struct {
Model string `json:"model"`
Notes int `json:"notes"`
Chunks int `json:"chunks"`
} `json:"embeddings"`
Links int `json:"links" jsonschema:"links"`
BrokenLinks int `json:"broken_links" jsonschema:"broken links"`
Orphans int `json:"orphans" jsonschema:"orphans"`
Problems int `json:"problems" jsonschema:"problems"`
IndexedNotes int `json:"indexed_notes" jsonschema:"indexed notes"`
IndexPath string `json:"index_path" jsonschema:"index path"`
Root string `json:"root" jsonschema:"root"`
NoteCount int `json:"note_count" jsonschema:"note count"`
Initialized bool `json:"initialized" jsonschema:"initialized"`
}
Details is the stable info response, including for an uninitialized directory.
type Frontmatter ¶
type Frontmatter struct {
Title string `json:"title,omitempty" yaml:"title,omitempty" jsonschema:"Optional display title"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty" jsonschema:"Optional tags"`
Aliases []string `json:"aliases,omitempty" yaml:"aliases,omitempty" jsonschema:"Optional link aliases"`
Created string `json:"-" yaml:"created,omitempty"`
}
Frontmatter is optional metadata supplied with agent writes.
type LinkRef ¶
LinkRef retains the spelling inside brackets and a body-relative, one-based line.
func ExtractLinks ¶
ExtractLinks scans wikilinks outside fences and matched inline code spans.
type MoveChange ¶
type MoveChange struct{ ID, Path, Before, After string }
type MovePlan ¶
type MovePlan struct {
OldPath, NewPath string
Result MoveResult
Changes []MoveChange
}
type MoveResult ¶
type Note ¶
type Note struct {
ID string `json:"id"`
Path string `json:"path"`
Title string `json:"title"`
Aliases []string `json:"aliases"`
Tags []string `json:"tags"`
Created string `json:"created"`
Updated string `json:"updated"`
MTime int64 `json:"mtime"`
Size int64 `json:"size"`
Problem string `json:"problem,omitempty"`
Body string `json:"body"`
}
Note is a Markdown file; Path and ID are relative to the KB root.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver indexes exact IDs, basenames and aliases for one graph snapshot.
func NewResolver ¶
NewResolver records ambiguous matches as empty IDs.
func (*Resolver) ResolveLink ¶
ResolveLink tries exact ID, unique basename, then unique case-insensitive alias.
type WriteResult ¶
type WriteResult struct {
Commit bool `json:"commit" jsonschema:"Whether the write committed successfully"`
Changed bool `json:"-" jsonschema:"-"`
CommitError string `json:"-" jsonschema:"-"`
ID string `json:"id" jsonschema:"Note ID relative to root without .md"`
Path string `json:"path" jsonschema:"Relative Markdown path"`
Bytes int `json:"bytes" jsonschema:"Total bytes in the resulting file"`
Mode string `json:"mode" jsonschema:"Applied write mode"`
}
func Write ¶
func Write(root, id, content, mode string) (WriteResult, error)
Write atomically publishes a note; cache updates belong to the application layer.