memory

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

internal/memory/scanner.go 记忆文件扫描和加载,对标 CC src/memdir/memoryScan.ts

internal/memory/types.go 记忆类型定义,对标 CC src/memdir/memoryTypes.ts

Index

Constants

View Source
const (
	MaxMemoryFiles = 200   // 单个目录最大记忆文件数(CC: 200)
	MaxIndexLines  = 200   // MEMORY.md 最大行数(CC: 200)
	MaxIndexBytes  = 25000 // MEMORY.md 最大字节数(CC: ~25KB)
)

CC 对标常量

Variables

This section is empty.

Functions

func FormatMemoriesForPrompt

func FormatMemoriesForPrompt(memories []MemoryEntry, indexContent string) string

FormatMemoriesForPrompt 将记忆格式化为系统提示词片段

func GetMemoryDir

func GetMemoryDir(homeDir, projectDir string) string

GetMemoryDir 返回项目的记忆目录路径 CC 格式:~/.xincode/projects/{sanitized-cwd}/memory/ 路径安全化:非字母数字字符替换为 -,长路径截断 + 哈希后缀

func LoadIndex

func LoadIndex(dir string) string

LoadIndex 读取 MEMORY.md 索引内容,按 CC 规则截断

func UpdateIndex

func UpdateIndex(dir string) error

UpdateIndex 根据目录中的记忆文件重建 MEMORY.md 索引

func WriteMemory

func WriteMemory(dir, filename string, entry MemoryEntry) error

WriteMemory 写入一条记忆到文件

Types

type MemoryEntry

type MemoryEntry struct {
	MemoryHeader
	FilePath string    // 文件绝对路径
	Body     string    // Markdown 正文(不含 frontmatter)
	ModTime  time.Time // 文件修改时间
}

MemoryEntry 一条完整的记忆记录

func ScanMemoryDir

func ScanMemoryDir(dir string) ([]MemoryEntry, error)

ScanMemoryDir 扫描记忆目录,返回所有记忆条目 CC 参考:scanMemoryFiles() — 递归读取,按 mtime 排序,cap at 200

type MemoryHeader

type MemoryHeader struct {
	Name        string     `yaml:"name"`
	Description string     `yaml:"description"`
	Type        MemoryType `yaml:"type"`
}

MemoryHeader 记忆文件 YAML frontmatter

func ParseFrontmatter

func ParseFrontmatter(content string) (MemoryHeader, string)

ParseFrontmatter 解析 YAML frontmatter 和 body

type MemoryType

type MemoryType string

MemoryType 记忆类型

const (
	TypeUser      MemoryType = "user"      // 用户角色/偏好/知识背景
	TypeFeedback  MemoryType = "feedback"  // 用户反馈/纠正/确认
	TypeProject   MemoryType = "project"   // 项目进展/目标/截止日期
	TypeReference MemoryType = "reference" // 外部资源指针
)

Jump to

Keyboard shortcuts

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