recall

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package recall is the one recall for memory notes and pages (itd-2610091918433290, itd-39; spc-2610111627213138). The prompt router calls it once per prompt, after rules.Inject, with the items the memory layers yield, and it returns one block headed "## MEMORY" for the hook to append after the rules block.

Matching is the loader's own (rules.TermMatcher), so a note's recall word and a rule domain's recall word hit on exactly the same prompts. The per-session ledger is SessionState.Recalled, keyed on each item's content, cleared by the loader's resets. The budget is what the rules leave of the loader's one per-turn budget (rules.InjectionBudgetBytes). Until the relevance ranking lands (step 4), the candidates are taken in id order.

Step 2 recalls notes; pages join the same path in step 3. Nothing here writes to stdout or knows a transport.

Index

Constants

View Source
const (
	LayerProject = "project"
	LayerMachine = "machine"
)

The layers an item comes from, as the diagnostic names them.

Variables

This section is empty.

Functions

func ReadLayers

func ReadLayers(home, repoRoot string) (Layers, []Refusal)

ReadLayers is the one reader of both note layers, for the recall and for the memory verb alike: the machine's under home, the project's under repoRoot, the root the rules loader resolved, each through memnote's layer reader. A layer that cannot be read is a Refusal and yields no notes, never an error: the hook still injects the rules, and the verb still shows what the other layer holds. It asks git nothing.

func ReadNotes

func ReadNotes(home, repoRoot string) ([]Item, []Refusal)

ReadNotes is ReadLayers turned into the recall's items. A personal note's tie is judged after matching, against the RootFunc the recall is handed.

func Reason

func Reason(err error) string

Reason is a memory error's text as it is printed: home-redacted and terminal-safe.

Types

type Candidate

type Candidate struct {
	Item Item
	Hits []string
}

Candidate is an item the prompt matched, with the recall words that hit.

func Matching

func Matching(items []Item, prompt string, root RootFunc) ([]Candidate, error)

Matching is candidates with each personal note's tie judged: a candidate tied to a root is kept only when root answers that same root. root is asked only when a tied item matched, and then once, so a prompt that matches no tied item costs no git call; a nil root answers "". When root errs, every tied candidate is left out and the error is returned beside the rest.

type Item

type Item struct {
	Key    string
	Layer  string
	Title  string
	Body   string
	Recall []string
	Tie    *string
}

Item is one thing the recall can bring back: a note now, a page from step 3. Key is its ledger key and its place in the id order — a note's id (mem-…), and a page's "page:<filename>" after every note. Tie is the root commit a personal note is tied to; nil for a note recalled everywhere and for every item in the project's file.

type Layers

type Layers struct {
	Machine []memnote.Note
	Project []memnote.Note
}

Layers is what a read of both note layers gave: the notes as they stand in the machine's file and in the project's.

type Refusal

type Refusal struct {
	File   string `json:"file"`
	Reason string `json:"reason"`
}

Refusal names a layer the recall could not read, and why, in words safe to print: the file in tilde or repository-relative form, the reason home-redacted and terminal-safe.

type Request

type Request struct {
	// Items are what the memory layers yield (noteItems, ReadNotes).
	Items []Item
	// Prompt is the prompt the hook was handed.
	Prompt string
	// Ledger is the session's recalled ledger (rules.SessionState.Recalled):
	// item key to the content signature last sent.
	Ledger map[string]string
	// Budget is what the rules left of the loader's per-turn budget,
	// rules.InjectionBudgetBytes less the rules text's length.
	Budget int
	// Disabled is the loader's kill switch: recall is the loader's, so the
	// switch silences it too.
	Disabled bool
	// Root answers the repository's root commit, for the items tied to one;
	// asked only once a tied item matched (Matching).
	Root RootFunc
}

Request is one prompt's recall.

type Result

type Result struct {
	Text     string
	Recalled []string
	Omitted  []string
	Ledger   map[string]string
	RootErr  error
	// contains filtered or unexported fields
}

Result is one prompt's recall. Text is empty when nothing new comes back. Recalled names each item Text carries, in order; Omitted each new candidate that did not fit the budget, not recorded and so retried on the next turn. Ledger is the updated recalled ledger, a copy. RootErr is the root-commit lookup's error (git did not answer in time) when a tied item matched and was left out for it — unrecorded, so retried on the next turn.

func Recall

func Recall(req Request) Result

Recall matches the items against the prompt, drops every candidate already sent this session with unchanged content, and takes the rest in id order while they fit the budget: the first that does not fit stops the take, so an item never comes back ahead of one before it in the order. Its only I/O is req.Root, asked when a tied item matched, and it never reflects prompt bytes into the block.

func (Result) Labels

func (r Result) Labels(keys []string) []string

Labels names keys as the hook's diagnostic does, each with its layer — "mem-… (project)", "mem-… (machine)" — so the out-of-band log says whose words went into the context, as the rules line's "(repo override)" does. A key this recall did not take or omit is named bare.

type RootFunc

type RootFunc func() (string, error)

RootFunc answers the repository's root commit, "" where there is none. The recall asks it only once matching has found a tied item, and at most once per call, so a prompt that matches no tied item costs no git call. A caller that hands the same RootFunc to more than one call memoises it (sync.OnceValues). An error is git not answering in time (gitutil.RootCommitContext): the tied items are then left out.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL