Documentation
¶
Overview ¶
Package memory is lectern's seam onto a durable knowledge store.
lectern owns OPERATIONAL state — what the agents are doing: sessions, tasks, worktrees, diffs, costs. It deliberately does not own SEMANTIC state — what the project knows: decisions, discoveries, conventions. That belongs in a memory system, and the boundary is worth keeping: lectern is useful with no memory provider at all, and a memory provider is useful with no lectern.
The interface exists so that relationship stays a composition rather than a dependency. Grimoire is the first-class provider; `none` is the default.
Index ¶
- func Prime(facts []Fact) string
- func ProjectHint(provider Provider, project, topic string) string
- type Activity
- type ActivityProvider
- type AutomaticProvider
- type Brief
- type Change
- type ContextResult
- type ContextScope
- type Delivery
- type Entry
- type Fact
- type Grimoire
- func (g *Grimoire) Automatic(ctx context.Context, project, query string, excluded []string) (ContextResult, error)
- func (g *Grimoire) AutomaticProject(ctx context.Context, project, topic, query string, excluded []string) (ContextResult, error)
- func (g *Grimoire) Available(ctx context.Context) bool
- func (g *Grimoire) Challenge(ctx context.Context, itemID, reason string) error
- func (g *Grimoire) ConfigureContext(mode, projects string) error
- func (g *Grimoire) ContextScope(project string) ContextScope
- func (g *Grimoire) Feedback(ctx context.Context, itemID string, helpful bool, note string) error
- func (g *Grimoire) Name() string
- func (g *Grimoire) ProjectHint(project, topic string) string
- func (g *Grimoire) ProjectLink(ctx context.Context, project, topic string) (Link, error)
- func (g *Grimoire) Provision(ctx context.Context, project, topic string) (string, error)
- func (g *Grimoire) Recall(ctx context.Context, project string, limit int) ([]Fact, error)
- func (g *Grimoire) Remember(ctx context.Context, e Entry) error
- func (g *Grimoire) SessionActivity(ctx context.Context, session string, since time.Time) (Activity, error)
- type Item
- type Link
- type LinkProvider
- type LinkedPath
- type None
- type ProjectProvider
- type Provider
- type Reviewer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Prime ¶
Prime renders recalled knowledge as a block to hand a fresh agent, citing where each piece came from so it can go and read the rest.
func ProjectHint ¶
Types ¶
type Activity ¶
type Activity struct {
Session string `json:"session"`
Since string `json:"since"`
Counts map[string]int `json:"counts"`
Changes []Change `json:"changes"`
}
Activity is what one session wrote, as the store itself recorded it.
type ActivityProvider ¶
type ActivityProvider interface {
SessionActivity(ctx context.Context, session string, since time.Time) (Activity, error)
}
ActivityProvider is a memory provider that can say what a given run wrote. It is what turns "the agent has a memory tool" into something the control plane can actually see: without it Lectern knew what it wrote itself at a handoff and nothing of what the agent wrote on its own.
type AutomaticProvider ¶
type Brief ¶
type Brief struct {
Provider string `json:"provider"`
Status string `json:"status"`
Message string `json:"message"`
Facts []Fact `json:"facts"`
}
Brief reports empty knowledge separately from a failed or partial lookup.
type Change ¶
type Change struct {
Kind string `json:"kind"` // learned | changed | retracted | expired
At string `json:"at"`
Text string `json:"text"`
Path string `json:"path"`
Agent string `json:"agent"`
Topic string `json:"topic"`
ReplacedText string `json:"replaced_text,omitempty"`
}
Change is one thing a session's agent did to the memory store.
type ContextResult ¶
type ContextResult struct {
Context string `json:"context"`
Keys []string `json:"keys"`
// Mode is how the store was searched for this delivery (scoped, all, the
// name of a project's managed note). It is recorded alongside the delivery
// because "why did the agent see this" is often answered by "what was it
// allowed to read" — see docs/memory-visibility.md.
Mode string `json:"mode,omitempty"`
// Items describe each delivered record for the operator: which record it
// was, where it came from, and enough of it to recognise. A store that does
// not send them still delivers context; the delivery log then names only
// the keys that went out.
Items []Item `json:"items,omitempty"`
}
func (ContextResult) ItemsJSON ¶ added in v2.4.0
func (r ContextResult) ItemsJSON() string
ItemsJSON renders the delivered items for the delivery log's items_json column. It never fails: an item that will not marshal would be a bug in a plain struct of strings, and losing the rest of the record over it would be worse than losing that one entry.
func (ContextResult) Size ¶ added in v2.4.0
func (r ContextResult) Size() int
Size is how many bytes of context this delivery actually handed over. The budget in Automatic is a byte bound, so this is the honest number to record.
type ContextScope ¶
type Delivery ¶ added in v2.4.0
type Delivery struct {
ID int64 `json:"id"`
SessionID *int64 `json:"session_id"`
TaskID *int64 `json:"task_id"`
AttemptID *int64 `json:"attempt_id"`
At float64 `json:"at"`
Mode string `json:"mode"`
Bytes int `json:"bytes"`
Items []Item `json:"items"`
}
Delivery is one recorded context injection, as the API reports it. It mirrors a memory_deliveries row plus the parsed items, so a client never has to know the row stores its items as JSON.
type Entry ¶
type Entry struct {
// Key requests an immutable, retry-safe checkpoint instead of inferred facts.
Key string
Project string
Topic string
Session string
Agent string
Category string
Text string
}
Entry is something worth remembering, with the provenance that makes it findable later. Every field here is operational context lectern already has and a memory store otherwise never learns.
type Fact ¶
type Fact struct {
Text string `json:"text"`
// Source is where it came from — a note path, usually. Worth carrying: an
// agent that can see which note a claim came from can go read the rest of it.
Source string `json:"source,omitempty"`
Topic string `json:"topic,omitempty"`
When string `json:"when,omitempty"`
Score float64 `json:"score,omitempty"`
Trust string `json:"trust"`
Authority string `json:"authority"`
Origin string `json:"origin,omitempty"`
Agent string `json:"agent,omitempty"`
ID string `json:"id,omitempty"`
}
Fact is one durable thing a project knows.
type Grimoire ¶
type Grimoire struct {
ContextMode string
ContextProjects map[string]ContextScope
BaseURL string
Token string // X-Grimoire-Admin, only needed for gated surfaces
Client *http.Client
// MinScore is the relevance floor. A similarity search always returns its
// best N matches, and when a store holds little about a project those are
// whatever else is in it — measured here, a real match scored 0.37 while
// unrelated queries all landed at 0.06-0.10. Without a floor every project
// gets the same two facts and a brief that looks informed and is not.
MinScore float64
}
Grimoire talks to a Grimoire instance over its HTTP API.
func NewGrimoire ¶
NewGrimoire builds a Grimoire-backed provider.
func (*Grimoire) AutomaticProject ¶
func (*Grimoire) Available ¶
Available pings the instance. Short timeout: this runs on the dispatch path.
func (*Grimoire) Challenge ¶ added in v2.4.0
Challenge asks the store to review one item as possibly wrong.
func (*Grimoire) ConfigureContext ¶
func (*Grimoire) ContextScope ¶
func (g *Grimoire) ContextScope(project string) ContextScope
func (*Grimoire) ProjectHint ¶
func (*Grimoire) ProjectLink ¶
ProjectLink resolves the scope retrieval would use and checks each path against what the store holds.
func (*Grimoire) Recall ¶
Recall asks Grimoire what it knows about a project.
Notes first, then the fact store. A vault holds a written note per project — that is what "what does this project know" actually means — while the fact store holds short atomic claims and is usually much smaller. Reading only the facts is how every project ended up with the same two.
func (*Grimoire) SessionActivity ¶
func (g *Grimoire) SessionActivity(ctx context.Context, session string, since time.Time) (Activity, error)
SessionActivity asks Grimoire for the writes stamped with this session key. The key reaches those writes through the agent's environment, so an agent launched before that existed, or one whose MCP server was not handed the variable, simply has nothing recorded under it.
type Item ¶ added in v2.4.0
type Item struct {
ID string `json:"id,omitempty"`
Source string `json:"source,omitempty"`
Title string `json:"title,omitempty"`
Snippet string `json:"snippet,omitempty"`
}
Item is one delivered memory record, described for the operator rather than for the model. Whatever the store calls these, what a person needs in order to judge a delivery is: which record it was, where it came from, and enough of the text to recognise it. See docs/memory-visibility.md.
func ParseItems ¶ added in v2.4.0
ParseItems reads an items_json column back. It tolerates the empty and the malformed alike: a bad blob degrades the Memory section, it does not take the session or task view down with it.
type Link ¶
type Link struct {
Mode string `json:"mode"` // scoped | all | manual | off
Basis string `json:"basis"` // managed | configured | guessed | <mode>
Paths []LinkedPath `json:"paths"`
// Linked is whether any of those paths holds a note. A guessed link whose
// paths are all empty is the quiet failure: retrieval runs, finds nothing,
// and the project looks as though it simply has no memory.
Linked bool `json:"linked"`
}
Link is the connection between a project and the memory store, as it actually is rather than as it is assumed to be.
type LinkProvider ¶
type LinkProvider interface {
ProjectLink(ctx context.Context, project, topic string) (Link, error)
}
LinkProvider is a memory provider that can say where a project's memory lives.
type LinkedPath ¶
type LinkedPath struct {
Path string `json:"path"`
Exists bool `json:"exists"`
Notes int `json:"notes"` // for a folder, how many notes are under it
}
LinkedPath is one place a project's memory is read from.
type None ¶
type None struct{}
None is the default provider: lectern works perfectly well without a memory system, and says so rather than pretending to have one.
type ProjectProvider ¶
type Provider ¶
type Provider interface {
// Name is what the UI calls this provider.
Name() string
// Available reports whether the store is reachable right now. It must never
// block a dispatch: an unreachable store degrades context, it does not fail
// the work.
Available(ctx context.Context) bool
// Recall returns facts relevant to a project, best-effort and ranked.
Recall(ctx context.Context, project string, limit int) ([]Fact, error)
// Remember stores one durable fact.
Remember(ctx context.Context, e Entry) error
}
Provider is a durable memory store.
type Reviewer ¶ added in v2.4.0
type Reviewer interface {
// Feedback records whether one item helped. helpful=false is "not
// relevant", not "wrong".
Feedback(ctx context.Context, itemID string, helpful bool, note string) error
// Challenge marks one item as possibly wrong, for review. A store that
// supports this keeps the claim and the objection side by side rather than
// silently deleting either.
Challenge(ctx context.Context, itemID, reason string) error
}
Reviewer is a memory provider that accepts an operator's verdict on one delivered item. "That was useful" and "that is wrong" are different claims — the first tunes ranking, the second asks for review — so they are two calls rather than one with a flag.
Both are irreversible from lectern's side: they change the operator's own memory store, which is why the API requires a human principal for them (docs/memory-visibility.md).