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 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) ConfigureContext(mode, projects string) error
- func (g *Grimoire) ContextScope(project string) ContextScope
- 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 Link
- type LinkProvider
- type LinkedPath
- type None
- type ProjectProvider
- type Provider
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 ContextScope ¶
type Entry ¶
type Entry struct {
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) 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 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.