This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Memory OS 是一个本地 CLI 工具,用于管理个人上下文信息(profile、projects、insights),并将其导出为适合粘贴到 AI system prompt 的格式。
# 开发模式(无需编译)
npm run dev -- <command> [args]
# 编译 TypeScript
npm run build
# 运行编译后的 CLI
npm run start -- <command> [args]
# 或直接使用
node dist/index.js <command> [args]
# 全局链接(开发用)
npm link
mem <command> # 可直接使用 mem 命令- 所有数据存储在
~/.memory-os/memory.json(用户目录下) storage.ts负责所有文件 I/O 操作models.ts定义了完整的 TypeScript 类型- 命令实现位于
src/commands/目录下
src/index.ts - CLI 入口点
- 使用 commander 定义所有命令和子命令
- 命令组织:
init,edit,add,export,list
src/storage.ts - 存储层
readMemory(): 读取并校验 JSONwriteMemory(data): 写入 JSONgetDefaultMemory(): 默认数据结构- 错误处理:文件不存在或 JSON 格式不合法时会
process.exit(1)
src/models.ts - 类型系统
MemoryData: 顶层数据结构(包含selfProfile,projects,insights)Project: 项目信息(id, name, description, goals, audience, status, focusThisWeek)Insight: 洞察记录(title, scenario, content, projectId)SelfProfile: 个人信息(name, languages, bio, writingStyle, capabilities)
src/commands/ - 命令实现
init.ts: 初始化数据文件,已存在则跳过edit.ts: 调用$EDITOR编辑 JSON,保存后校验格式add.ts: 使用 inquirer 交互式添加 project/insightexport.ts: 将数据格式化为自然语言输出(profile/context/insights)
项目和洞察的 ID 使用 Date.now().toString(36) + Math.random().toString(36).slice(2, 6) 生成,确保唯一性。
项目使用 ES Modules ("type": "module"),所有本地模块导入必须带 .js 后缀(即使源文件是 .ts):
import { readMemory } from "./storage.js"; // ✓ 正确
import { readMemory } from "./storage"; // ✗ 错误添加新命令时:
- 在
src/commands/下创建新文件 - 在
src/index.ts中注册命令 - 如果需要修改数据结构,同时更新
models.ts和storage.ts中的getDefaultMemory()