记忆系统
CLI-JAW 拥有三层记忆系统:结构化文件存储、基于片段的对话摘要,以及带有 FTS5 索引的语义搜索。记忆在会话间持久保存,并注入到智能体的系统提示中。
三个层级
| 层级 | 用途 | 存储位置 |
|---|---|---|
| 结构化 | 用户档案、偏好设置、决策记录、灵魂/身份 | ~/.cli-jaw/memory/structured/ |
| 片段 | 记忆刷新产生的对话摘要 | ~/.cli-jaw/memory/structured/episodes/live/ |
| 语义 | 导入并分类的知识 | ~/.cli-jaw/memory/structured/semantic/ |
记忆目录结构
~/.cli-jaw/memory/structured/
├── profile.md # User profile and preferences
├── shared/
│ ├── preferences.md # Reflected preferences
│ ├── decisions.md # Key decisions
│ ├── projects.md # Project context
│ └── soul.md # Soul and identity
├── episodes/
│ ├── live/ # Daily conversation summaries
│ └── imported/ # Imported from legacy memory
├── semantic/ # Categorized knowledge
├── procedures/ # Runbooks and procedures
├── sessions/ # (not indexed)
└── index.sqlite # FTS5 search index
记忆的工作原理
1. 历史区块(对话上下文)
在新会话开始时,最近的对话历史(最多 8000 字符、10 个会话)会以 [Recent Context] 的形式添加到用户提示的前面。该内容仅限于当前 workingDir 的范围。
2. 记忆刷新(对话转存储)
每隔 N 次助手响应(默认为 10 次,可通过 settings.memory.flushEvery 配置),一个独立的智能体会提取关键信息并追加到当日的片段文件中。
## 15:30
User discussed refactoring the auth module. Decided to use JWT tokens.
Prefers ES Module only, no CommonJS.
3. 高级提示注入
当 FTS5 索引就绪后,系统提示中将包含:
- 用户档案上下文 -- 来自
profile.md(800 字符) - 灵魂与身份 -- 来自
shared/soul.md(1000 字符) - 任务快照 -- 与当前提示相关的 FTS5 搜索结果(最多 4 条匹配,2800 字符)
CLI 命令
# Search memory
jaw memory search "JWT authentication"
# Read a memory file
jaw memory read shared/decisions.md
# Save to memory
jaw memory save shared/notes.md "New note content"
# List memory files
jaw memory list
# Initialize memory
jaw memory init
# Reflect recent episodes into structured memory
jaw memory reflect
# Trigger memory flush
jaw memory flush
# Cleanup old entries
jaw memory cleanup --days 30
斜杠命令
| 命令 | 说明 |
|---|---|
/memory 或 /memory list | 列出记忆文件 |
/memory <query> | 搜索记忆 |
/memory status | 显示运行时状态 |
/memory bootstrap | 导入旧版记忆源 |
/memory reindex | 重建 FTS5 索引 |
/memory flush | 立即触发记忆刷新 |
/memory embed status | 显示嵌入状态 |
/memory embed estimate | 估算嵌入成本 |
L1 / L2 记忆边界
| 层 | 命令 | 作用范围 | 访问权限 |
|---|---|---|---|
| L1(实例本地) | jaw memory | 当前 JAW_HOME | 读/写 |
| L2(仪表盘联合) | jaw dashboard memory | 所有 ~/.cli-jaw* 实例 | 只读 |
日常操作请使用 L1(
jaw memory)。L2(jaw dashboard memory)用于需要从其他实例获取上下文时的跨实例搜索。仪表盘嵌入(可选)
仪表盘支持在 FTS5 搜索之上添加可选的向量嵌入。这是一个附加层,默认关闭。支持的提供商:OpenAI、Gemini、Voyage、Vertex、Local (Ollama)。
# Configure via dashboard settings or CLI:
jaw dashboard memory config set --provider openai --api-key sk-...
jaw dashboard memory reindex --embedding
记忆设置
{
"memory": {
"enabled": true,
"flushEvery": 10,
"cli": "claude",
"model": "haiku"
}
}