memory

package
v0.0.0-...-3024e77 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("memory entry not found")

Functions

func MatchQuestion

func MatchQuestion(a, b string) bool

MatchQuestion returns true if two questions match after normalization.

func NormalizeQuestion

func NormalizeQuestion(q string) string

NormalizeQuestion normalizes a question for comparison: lowercase, trim, remove punctuation, normalize whitespace. Hyphens, slashes, and similar separators are treated as whitespace.

Types

type AddInput

type AddInput struct {
	ProjectID string    `json:"project_id"`
	EntryType EntryType `json:"entry_type"`
	Title     string    `json:"title"`
	Question  string    `json:"question,omitempty"`
	Answer    string    `json:"answer,omitempty"`
	Content   string    `json:"content,omitempty"`
	Citation  string    `json:"citation,omitempty"`
	Source    string    `json:"source,omitempty"`
}

AddInput specifies the fields for creating a new memory entry.

type Entry

type Entry struct {
	ID        string    `json:"id"`
	ProjectID string    `json:"project_id"`
	EntryType EntryType `json:"entry_type"`
	Title     string    `json:"title"`
	Question  string    `json:"question,omitempty"`
	Answer    string    `json:"answer,omitempty"`
	Content   string    `json:"content,omitempty"`
	Citation  string    `json:"citation,omitempty"`
	Source    string    `json:"source,omitempty"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Entry is a single durable project memory record.

func NewEntry

func NewEntry(projectID string, entryType EntryType, title, content, citation, source string) Entry

NewEntry creates a new memory entry with generated ID.

func NewEntryFull

func NewEntryFull(projectID string, entryType EntryType, title, question, answer, content, citation, source string) Entry

NewEntryFull creates a memory entry with all fields including question/answer.

type EntryType

type EntryType string

EntryType categorizes a memory entry.

const (
	TypeDecision       EntryType = "decision"
	TypeApproval       EntryType = "approval"
	TypeQuestionAnswer EntryType = "question_answer"
	TypeReference      EntryType = "reference"
	TypeResearch       EntryType = "research"
	TypePlan           EntryType = "plan"
	TypeChange         EntryType = "change"
)

func (EntryType) Valid

func (et EntryType) Valid() bool

Valid returns true if the entry type is known.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder writes memory records automatically when important project events occur: approved context, approved research, applied proposals, change events. It is the single authority for "what gets remembered."

All writes use the memory.Service (and Store) underneath, ensuring FTS-backed storage. The Recorder also supports supersession and topic-key-based lookup.

func NewRecorder

func NewRecorder(store Store) *Recorder

NewRecorder creates a recorder backed by the given store.

func (*Recorder) FindByTopicKey

func (r *Recorder) FindByTopicKey(projectID, topicKey string) ([]Entry, error)

FindByTopicKey searches memory entries by their topic_key in source.

func (*Recorder) RecordAppliedProposal

func (r *Recorder) RecordAppliedProposal(projectID, proposalID, summary string) (Entry, error)

RecordAppliedProposal creates a memory entry from an applied proposal.

func (*Recorder) RecordApprovedContext

func (r *Recorder) RecordApprovedContext(projectID, atype, content string) (Entry, error)

RecordApprovedContext creates a memory entry for an approved context item.

func (*Recorder) RecordApprovedResearch

func (r *Recorder) RecordApprovedResearch(projectID, researchID, topic, summary string) (Entry, error)

RecordApprovedResearch creates a memory entry when research is approved.

func (*Recorder) RecordChangeEvent

func (r *Recorder) RecordChangeEvent(projectID, eventType, summary string) (Entry, error)

RecordChangeEvent creates a memory entry from a change event.

func (*Recorder) Search

func (r *Recorder) Search(projectID, query string) ([]Entry, error)

Search returns memory entries matching the given query using LIKE on title, content, and question fields.

func (*Recorder) Supersede

func (r *Recorder) Supersede(projectID, oldTopicKey string, newEntry Entry) (Entry, error)

Supersede marks an existing entry as "superseded" and creates a replacement. Returns the new entry.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides memory CRUD and question reuse.

func NewService

func NewService(store Store) *Service

NewService creates a memory service backed by the given store.

func (*Service) Add

func (s *Service) Add(input AddInput) (Entry, error)

Add creates a new memory entry.

func (*Service) Ask

func (s *Service) Ask(projectID, question string) (Entry, bool, error)

Ask searches for a matching question and reuses the answer if found. Returns the entry, reused=true if a match was found, or an empty entry with reused=false.

func (*Service) Get

func (s *Service) Get(id string) (Entry, error)

Get returns a single memory entry by ID.

func (*Service) List

func (s *Service) List(projectID string) ([]Entry, error)

List returns all memory entries for a project.

func (*Service) Search

func (s *Service) Search(projectID, query string) ([]Entry, error)

Search searches memory entries by keyword.

type Store

type Store interface {
	Add(e Entry) (Entry, error)
	List(projectID string) ([]Entry, error)
	Search(projectID, query string) ([]Entry, error)
	Get(id string) (Entry, error)
	Update(e Entry) (Entry, error)
}

Store defines persistence operations for memory entries.

Jump to

Keyboard shortcuts

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