Documentation
¶
Overview ¶
Package knowledge is the agent's persistent memory: a JSON-backed store of Pitfalls (lessons) it has learned. It is the mechanism that lets the agent actually remember experience across restarts — the store is read on startup and written after each task's reflection pass.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGenericErrorPattern ¶ added in v0.41.12
IsGenericErrorPattern reports whether pattern is too generic to usefully key a lesson on (see genericErrorPattern). Checked both when a new lesson is about to be stored (internal/reflect) and whenever existing lessons are queried (Query below) — a pitfall stored before this check existed, or by any other future write path, must not surface either.
Types ¶
type KB ¶
type KB struct {
// contains filtered or unexported fields
}
KB is an in-memory view of the pitfall store plus its backing file path. The same *KB is shared by the main agent and parallel sub-agents (which record lessons and Query from concurrent tool calls), so it guards its state with mu.
func (*KB) Add ¶
Add inserts a pitfall, de-duplicating on (domain, normalized error pattern). A duplicate bumps Hits and back-fills any empty fields; returns true only when a genuinely new lesson was stored.
func (*KB) Purge ¶ added in v0.9.3
Purge drops lessons last seen more than maxAgeDays ago (by LastSeen), returning how many were removed. maxAgeDays <= 0 is a no-op. Undated entries are kept (Open back-fills them, so they age from first load).
func (*KB) Query ¶
Query returns pitfalls for a domain. With a non-empty errText it keeps only keyword-overlapping lessons, ranked by overlap then Hits. With an empty errText it returns every lesson in the domain ranked by Hits (used by the help tool). limit <= 0 means no cap.
func (*KB) Save ¶
Save writes the store to disk as pretty JSON, creating the parent directory. Before writing, it re-reads the file and replays this KB's own pending Add() lessons onto that fresh copy instead of blindly overwriting it with pitfalls — otherwise two separate ipsupport-code processes sharing the same global KB could have one's learned lesson silently lost to the other's last write (the mutex only protects against races WITHIN one process). Purge/ Clear set overwrite, skipping the merge: those are a deliberate replace of the whole store. When neither applies — nothing pending and no overwrite due — there is nothing of this KB's own to persist, so Save skips the write entirely instead of falling through to an unconditional write of k.pitfalls: that write would have no fresh read backing it, so a stale in-memory snapshot (e.g. after an idle flush, or a no-op Purge, with no Add in between) could silently clobber a fresher file a different process wrote since this one last read it. A file lock around the whole read-merge-write cycle keeps two such processes from interleaving (one's read landing before the other's write, so each only ever merges its own delta) the same way the in-process mutex keeps two goroutines from interleaving; an in-memory KB (path=="") skips it, since there's nothing on disk to serialize around. The write itself is atomic (temp + rename) so a crash mid-write can't truncate the lessons file either. pending/overwrite are only cleared once that write actually succeeds — if it fails, they're left intact so the next Save replays them instead of silently losing them (a concurrent Add's own Save wouldn't otherwise know to replay a lesson it never recorded).
type KnowledgeError ¶
KnowledgeError wraps a host-level failure of the knowledge store (read, parse, or write). Model-recoverable conditions never surface as this type.
func (*KnowledgeError) Error ¶
func (e *KnowledgeError) Error() string
func (*KnowledgeError) Unwrap ¶
func (e *KnowledgeError) Unwrap() error
type Pitfall ¶
type Pitfall struct {
Domain string `json:"domain"`
ErrorPattern string `json:"error_pattern"`
Context string `json:"context"`
ProvenFix string `json:"proven_fix"`
Hits int `json:"hits"`
Added string `json:"added,omitempty"`
LastSeen string `json:"last_seen,omitempty"`
}
Pitfall is one durable lesson: when ErrorPattern is seen in Domain while doing Context, ProvenFix is what worked. Hits counts reuse, for ranking and pruning. Added/LastSeen (YYYY-MM-DD) drive age-based pruning — LastSeen bumps each time the lesson recurs, so a still-relevant lesson stays fresh.