memory

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package memory stores searchable project and session memory entries.

Index

Constants

View Source
const MaxFileBytes = 64 * 1024

MaxFileBytes limits how much of each instruction file is loaded into memory.

Variables

View Source
var CandidateNames = []string{
	"AGENTS.md",
	"AGENTS.local.md",
	"CLAUDE.md",
	"CLAUDE.local.md",
	filepath.Join(".claude", "CLAUDE.md"),
	"CLAW.md",
	"CLAW.local.md",
	filepath.Join(".claw", "CLAUDE.md"),
	filepath.Join(".claw", "instructions.md"),
	filepath.Join(".codog", "instructions.md"),
}

CandidateNames lists workspace-relative instruction file names Codog treats as project memory.

Functions

func Render

func Render(files []File) string

Render formats loaded memory files for inclusion in the system prompt.

func RenderAppendReport

func RenderAppendReport(w io.Writer, report AppendReport)

RenderAppendReport writes a human-readable memory append report.

func RenderFileReport

func RenderFileReport(w io.Writer, report FileReport)

RenderFileReport writes a human-readable memory file operation report.

func RenderReport

func RenderReport(w io.Writer, report Report)

RenderReport writes a human-readable memory discovery report.

func RenderResetReport

func RenderResetReport(w io.Writer, report ResetReport)

RenderResetReport writes a human-readable memory reset report.

func RenderSearchReport

func RenderSearchReport(w io.Writer, report SearchReport)

RenderSearchReport writes a human-readable memory search report.

func RenderSelectionReport

func RenderSelectionReport(w io.Writer, report SelectionReport)

RenderSelectionReport writes a human-readable memory selector report.

func RenderShowReport

func RenderShowReport(w io.Writer, report ShowReport)

RenderShowReport writes a human-readable memory file report.

func ResolvePath

func ResolvePath(workspace string, target string) (string, error)

ResolvePath converts a memory target into a workspace-contained absolute path.

Types

type AppendReport

type AppendReport struct {
	Kind   string `json:"kind"`
	Action string `json:"action"`
	Status string `json:"status"`
	Path   string `json:"path"`
	Bytes  int    `json:"bytes"`
}

AppendReport describes a successful append to a memory file.

func Append

func Append(workspace string, text string) (AppendReport, error)

Append adds text to the workspace AGENTS.md memory file.

type File

type File struct {
	Path       string    `json:"path"`
	Name       string    `json:"name"`
	Scope      string    `json:"scope"`
	Chars      int       `json:"chars"`
	SizeBytes  int64     `json:"size_bytes"`
	ModifiedAt time.Time `json:"modified_at"`
	Truncated  bool      `json:"truncated,omitempty"`
	Body       string    `json:"-"`
}

File is a loaded project-memory instruction file.

func Discover

func Discover(workspace string) ([]File, error)

Discover loads project-memory files between the workspace and its boundary.

func DiscoverWithRulesImport

func DiscoverWithRulesImport(workspace string, rulesImport RulesImportOptions) ([]File, error)

DiscoverWithRulesImport loads project-memory files and optional external framework rule files between the workspace and its boundary.

type FileReport

type FileReport struct {
	Kind    string `json:"kind"`
	Action  string `json:"action"`
	Status  string `json:"status"`
	Path    string `json:"path"`
	Created bool   `json:"created"`
	Opened  bool   `json:"opened,omitempty"`
	Editor  string `json:"editor,omitempty"`
	Message string `json:"message,omitempty"`
}

FileReport describes a memory file path, creation, or editor operation.

func Edit

func Edit(workspace string, target string, editor string, openEditor bool) (FileReport, error)

Edit ensures the target memory file exists and optionally opens it in an editor.

func Ensure

func Ensure(workspace string, target string) (FileReport, error)

Ensure creates the target memory file if it does not already exist.

func Path

func Path(workspace string, target string) (FileReport, error)

Path resolves the target memory file path without creating it.

type Metadata

type Metadata struct {
	Path           string `json:"path"`
	Name           string `json:"name"`
	Source         string `json:"source"`
	Origin         string `json:"origin"`
	Scope          string `json:"scope"`
	ScopePath      string `json:"scope_path"`
	OutsideProject bool   `json:"outside_project"`
	Chars          int    `json:"chars"`
	Lines          int    `json:"lines"`
	Words          int    `json:"words"`
	SizeBytes      int64  `json:"size_bytes"`
	ModifiedAt     string `json:"modified_at,omitempty"`
	AgeSeconds     int64  `json:"age_seconds,omitempty"`
	Empty          bool   `json:"empty"`
	Contributes    bool   `json:"contributes"`
	Truncated      bool   `json:"truncated,omitempty"`
}

Metadata is a JSON-safe description of one loaded project-memory file.

func MetadataFor

func MetadataFor(workspace string, files []File) []Metadata

MetadataFor returns JSON-safe metadata for loaded memory files.

type Report

type Report struct {
	Kind             string    `json:"kind"`
	Action           string    `json:"action"`
	Status           string    `json:"status"`
	WorkingDirectory string    `json:"working_directory"`
	InstructionFiles int       `json:"instruction_files"`
	Files            []Summary `json:"files"`
}

Report describes discovered project-memory files for a workspace.

func BuildReport

func BuildReport(workspace string) (Report, error)

BuildReport discovers and summarizes project-memory files for a workspace.

func BuildReportWithRulesImport

func BuildReportWithRulesImport(workspace string, rulesImport RulesImportOptions) (Report, error)

BuildReportWithRulesImport discovers and summarizes project-memory files using the provided external rule import policy.

type ResetFile

type ResetFile struct {
	Path         string `json:"path"`
	Name         string `json:"name"`
	Scope        string `json:"scope"`
	BytesRemoved int    `json:"bytes_removed"`
}

type ResetOptions

type ResetOptions struct {
	Target  string
	All     bool
	Confirm bool
}

type ResetReport

type ResetReport struct {
	Kind             string      `json:"kind"`
	Action           string      `json:"action"`
	Status           string      `json:"status"`
	WorkingDirectory string      `json:"working_directory"`
	Target           string      `json:"target,omitempty"`
	All              bool        `json:"all,omitempty"`
	ResetCount       int         `json:"reset_count"`
	Files            []ResetFile `json:"files"`
}

func Reset

func Reset(workspace string, opts ResetOptions) (ResetReport, error)

Reset clears one or more discovered project-memory files after confirmation.

type RulesImportOptions

type RulesImportOptions struct {
	Mode       string
	Frameworks []string
}

RulesImportOptions controls external AI coding rule imports.

func (RulesImportOptions) ShouldImport

func (o RulesImportOptions) ShouldImport(framework string) bool

type SearchMatch

type SearchMatch struct {
	Path         string   `json:"path"`
	Name         string   `json:"name"`
	Scope        string   `json:"scope"`
	LineNumber   int      `json:"line_number"`
	Line         string   `json:"line"`
	Score        int      `json:"score"`
	MatchedTerms []string `json:"matched_terms,omitempty"`
}

SearchMatch records one relevant line found in project memory.

type SearchReport

type SearchReport struct {
	Kind             string        `json:"kind"`
	Action           string        `json:"action"`
	Status           string        `json:"status"`
	WorkingDirectory string        `json:"working_directory"`
	Query            string        `json:"query"`
	MatchCount       int           `json:"match_count"`
	Matches          []SearchMatch `json:"matches"`
}

SearchReport describes a project-memory search result.

func Search(workspace string, query string, limit int) (SearchReport, error)

Search finds lines in project memory that match the query terms.

func SearchWithRulesImport

func SearchWithRulesImport(workspace string, query string, limit int, rulesImport RulesImportOptions) (SearchReport, error)

SearchWithRulesImport finds lines in project memory using the provided external rule import policy.

type SelectionOption

type SelectionOption struct {
	Path     string `json:"path"`
	Name     string `json:"name"`
	Source   string `json:"source"`
	Origin   string `json:"origin"`
	Scope    string `json:"scope"`
	Exists   bool   `json:"exists"`
	Selected bool   `json:"selected,omitempty"`
}

SelectionOption describes a memory file candidate for selector UIs.

type SelectionReport

type SelectionReport struct {
	Kind             string            `json:"kind"`
	Action           string            `json:"action"`
	Status           string            `json:"status"`
	WorkingDirectory string            `json:"working_directory"`
	Target           string            `json:"target,omitempty"`
	Selected         string            `json:"selected"`
	OptionCount      int               `json:"option_count"`
	Options          []SelectionOption `json:"options"`
}

SelectionReport previews the memory file that would be edited or created.

func Select

func Select(workspace string, target string) (SelectionReport, error)

Select returns memory selector candidates without creating files or opening an editor.

type ShowReport

type ShowReport struct {
	Kind   string `json:"kind"`
	Action string `json:"action"`
	Status string `json:"status"`
	File   File   `json:"file"`
	Body   string `json:"body,omitempty"`
}

ShowReport contains the selected memory file and its body.

func Show

func Show(workspace string, target string) (ShowReport, error)

Show returns a selected memory file, requiring a target when multiple files are available.

func ShowWithRulesImport

func ShowWithRulesImport(workspace string, target string, rulesImport RulesImportOptions) (ShowReport, error)

ShowWithRulesImport returns a selected memory file using the provided rule import policy.

type Summary

type Summary struct {
	Path       string `json:"path"`
	Name       string `json:"name"`
	Scope      string `json:"scope"`
	Lines      int    `json:"lines"`
	Words      int    `json:"words"`
	Chars      int    `json:"chars"`
	SizeBytes  int64  `json:"size_bytes"`
	ModifiedAt string `json:"modified_at,omitempty"`
	AgeSeconds int64  `json:"age_seconds,omitempty"`
	Empty      bool   `json:"empty"`
	Preview    string `json:"preview"`
	Truncated  bool   `json:"truncated,omitempty"`
}

Summary is the JSON-safe metadata view of a memory file.

func Summaries

func Summaries(files []File) []Summary

Summaries converts loaded memory files to metadata-only summaries.

func SummariesAt

func SummariesAt(files []File, now time.Time) []Summary

SummariesAt converts loaded memory files to metadata-only summaries using a caller-provided clock for age calculation.

Jump to

Keyboard shortcuts

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