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:
- Full behavioral instructions (memory types, how to save, when to access)
- 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
- func BuildPrompt(cwd string) string
- func EnsureDir(cwd string) error
- func EntrypointPath(cwd string) string
- func FormatMemoryList(files []MemoryFile) string
- func Path(cwd string) string
- func RunDream(ctx context.Context, cwd, sessionDir string, ...) error
- func RunExtract(ctx context.Context, cwd, recentSummary string, ...) error
- func ShouldDream(cwd string, sessionDir string) bool
- type DreamConfig
- type MemoryFile
Constants ¶
const ( MaxLines = 200 MaxBytes = 25_000 EntrypointName = "MEMORY.md" )
Variables ¶
This section is empty.
Functions ¶
func BuildPrompt ¶
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 EntrypointPath ¶
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 ¶
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 ¶
ShouldDream checks whether the auto-dream consolidation gate is open. Mirrors the gate checks in src/services/autoDream/autoDream.ts:
- Time: hours since last consolidation >= MinHours
- Sessions: transcript count newer than last consolidation >= MinSessions
- Lock: no other dream in progress
Types ¶
type DreamConfig ¶
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).