memdir

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package memdir manages the auto-memory directory and MEMORY.md file.

Mirrors src/memdir/memdir.ts + src/memdir/paths.ts + src/memdir/memoryTypes.ts from the reference TypeScript source.

The memory directory lives at:

~/.claude/projects/<sanitized-cwd>/memory/

The system prompt block injected by BuildPrompt contains:

  1. Full behavioral instructions (memory types, how to save, when to access)
  2. MEMORY.md content (truncated to MaxLines/MaxBytes)

Auto-dream consolidation fires after 24h and 5+ new sessions to compact memory files via a forked sub-agent.

Index

Constants

View Source
const (
	MaxLines       = 200
	MaxBytes       = 25_000
	EntrypointName = "MEMORY.md"
)

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(cwd string) string

BuildPrompt returns the full memory system-prompt block for the given cwd. Mirrors buildMemoryLines() + loadMemoryPrompt() in src/memdir/memdir.ts — includes the full type taxonomy, how-to-save instructions, when-to-access guidance, and MEMORY.md content.

Returns "" if MEMORY.md doesn't exist AND the directory doesn't exist (no-op for fresh installs without memory configured).

func EnsureDir

func EnsureDir(cwd string) error

EnsureDir creates the memory directory if it doesn't exist.

func EntrypointPath

func EntrypointPath(cwd string) string

EntrypointPath returns the path to MEMORY.md for the given cwd.

func FormatMemoryList

func FormatMemoryList(files []MemoryFile) string

FormatMemoryList returns a human-readable summary of memory files.

func Path

func Path(cwd string) string

Path returns the auto-memory directory for the given cwd. Mirrors getAutoMemPath() — respects CLAUDE_CONFIG_DIR env override.

func RunDream

func RunDream(ctx context.Context, cwd, sessionDir string, runAgent func(context.Context, string) (string, error)) error

RunDream runs the memory consolidation sub-agent ("dream"). Mirrors runForkedAgent(buildConsolidationPrompt(...)) in autoDream.ts. The runAgent closure is Loop.RunSubAgent from the agent package.

func RunExtract

func RunExtract(ctx context.Context, cwd, recentSummary string, runAgent func(context.Context, string) (string, error)) error

RunExtract spawns a memory-extraction sub-agent over the most recent N model-visible messages (user + assistant). Mirrors the post-Stop pattern from src/services/extractMemories/extractMemories.ts but is invoked manually via /memory extract rather than firing on every Stop event — avoids the surprise per-turn cost of CC's auto-extract.

The runAgent closure runs the sub-agent with the constructed prompt; the sub-agent writes new/updated files into the auto-memory directory using its restricted tool set (read-only + memory-dir-only writes).

recentSummary is a brief textual rendering of the recent conversation that the sub-agent will analyze. Conduit doesn't have CC's full Message type tree, so callers pass a pre-rendered summary string.

func ShouldDream

func ShouldDream(cwd string, sessionDir string) bool

ShouldDream checks whether the auto-dream consolidation gate is open. Mirrors the gate checks in src/services/autoDream/autoDream.ts:

  1. Time: hours since last consolidation >= MinHours
  2. Sessions: transcript count newer than last consolidation >= MinSessions
  3. Lock: no other dream in progress

Types

type DreamConfig

type DreamConfig struct {
	MinHours    float64
	MinSessions int
}

DreamConfig controls when auto-dream fires.

type MemoryFile

type MemoryFile struct {
	Path    string
	Name    string // filename without directory
	ModTime time.Time
	Size    int64
	Type    string // "user" | "feedback" | "project" | "reference" | "unknown"
}

MemoryFile is one memory file's metadata.

func RelevantMemories

func RelevantMemories(cwd string, keywords []string) ([]MemoryFile, error)

RelevantMemories finds memory files that mention any of the given keywords. Simple keyword matching — no embeddings required.

func ScanMemories

func ScanMemories(cwd string) ([]MemoryFile, error)

ScanMemories lists all memory files in the memory directory for cwd. Returns files sorted by modification time (newest first).

Jump to

Keyboard shortcuts

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