Skip to content

Commit 651340a

Browse files
committed
feat(templates): integrate xMemory 4-layer architecture into skill and workflow
Update templates to support xMemory hierarchical memory: - AGENTS.md: Add themes/ directory and L3 layer to architecture diagram - workflow.md v3.0: Add [10] 主题检索 menu option for theme search - steps/themes.md (NEW): Theme search step with omp --level theme - steps/search.md: Add xMemory layer selection (theme/semantic/all) - SKILL.md v3.0: Add L3 theme assimilation flow and themes/ structure xMemory integration points: - Theme search: omp search 'query' --level theme [--no-expand] - Auto-assimilation: New semantics automatically attach to themes - Configurable thresholds in _omp/memory/themes/index.yaml
1 parent 5b2be46 commit 651340a

5 files changed

Lines changed: 223 additions & 33 deletions

File tree

cli/templates/shared/_omp/AGENTS.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,37 @@ This file provides complete instructions for AI agents to use the dual-layer mem
88
- View project memory: `cat _omp/memory/*.md`
99
- Check workflows: `ls _omp/workflows/memory/`
1010

11-
## Memory Architecture
11+
## Memory Architecture (xMemory 4-Layer)
1212

1313
```
14-
├── _omp/memory/ ← Project-level memory (this repo)
15-
│ ├── projectbrief.md ← Project overview & goals
16-
│ ├── productContext.md ← Product requirements & features
17-
│ ├── techContext.md ← Technical stack & architecture
18-
│ ├── activeContext.md ← Current work session context
19-
│ ├── systemPatterns.md ← Patterns & conventions
20-
│ ├── decisions.yaml ← Architecture decisions log
21-
│ └── progress.md ← Task progress tracking
14+
├── _omp/memory/ ← Project-level memory (this repo)
15+
│ ├── projectbrief.md ← Project overview & goals
16+
│ ├── productContext.md ← Product requirements & features
17+
│ ├── techContext.md ← Technical stack & architecture
18+
│ ├── activeContext.md ← Current work session context
19+
│ ├── systemPatterns.md ← Patterns & conventions
20+
│ ├── decisions.yaml ← Architecture decisions log
21+
│ ├── progress.md ← Task progress tracking
22+
│ ├── sessions/ ← L1 Episode memories
23+
│ └── themes/ ← L3 Theme layer (NEW)
24+
│ ├── index.yaml ← Theme index & config
25+
│ └── embeddings.json ← Theme centroids
2226
23-
└── OpenMemory MCP ← User-level memory (personal prefs)
27+
├── OpenMemory MCP ← L2 Semantic layer (Qdrant)
28+
│ └── User preferences, skills, cross-project memories
29+
30+
└── L0 Message Layer ← Raw conversation (not persisted)
2431
```
2532

33+
### xMemory Layer Summary
34+
35+
| Layer | Storage | Purpose |
36+
|-------|---------|---------|
37+
| L3 Theme | `themes/` | Aggregated topics from semantics |
38+
| L2 Semantic | OpenMemory MCP | Searchable knowledge fragments |
39+
| L1 Episode | `sessions/` | Conversation context |
40+
| L0 Message | In-memory | Raw messages (transient) |
41+
2642
## Trigger Signals for Auto-Extraction
2743

2844
Extract and save when you detect:

cli/templates/shared/_omp/skills/memory-extraction/SKILL.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
name: memory-extraction
3-
description: Agent-only workflow for extracting key information from conversations, code changes, and deployments into structured memory files. Automatically updates `_omp/memory/` directory and notifies other agents. Triggered automatically at conversation end or when valuable information is detected.
3+
description: Agent-only workflow for extracting key information from conversations, code changes, and deployments into structured memory files. Supports xMemory 4-layer architecture with theme assimilation. Automatically updates `_omp/memory/` directory and notifies other agents.
44
metadata:
55
author: Wendy (Workflow Builder)
6-
version: "2.1"
6+
version: "3.0"
77
language: zh-CN
88
audience: agent-only
99
---
@@ -34,18 +34,30 @@ _omp/ # OpenMemory Plus 核心目录
3434
│ ├── SKILL.md
3535
│ ├── scripts/validate.sh
3636
│ └── templates/*.tmpl
37-
└── memory/ # 项目级记忆
37+
└── memory/ # 项目级记忆
3838
├── project.yaml # 项目配置 (SSOT)
3939
├── decisions.yaml # 技术决策记录
4040
├── changelog.yaml # 变更历史
41-
└── sessions/ # 会话记录
41+
├── sessions/ # 会话记录 (L1 Episode)
42+
└── themes/ # 主题层 (L3 Theme) ← NEW
43+
├── index.yaml # 主题索引和配置
44+
└── embeddings.json # 主题质心向量
4245
```
4346

44-
## 双层记忆架构
47+
## xMemory 4-Layer Architecture
48+
49+
| 层级 | 存储位置 | 用途 |
50+
|------|----------|------|
51+
| **L3 Theme** | `_omp/memory/themes/` | 主题聚合,多个语义记忆的抽象 |
52+
| **L2 Semantic** | openmemory MCP (Qdrant) | 语义记忆,可检索的知识片段 |
53+
| **L1 Episode** | `_omp/memory/sessions/` | 情节记忆,会话上下文 |
54+
| **L0 Message** | 对话历史 | 原始消息(不持久化) |
55+
56+
## 双层记忆架构(简化视图)
4557

4658
| 系统 | 存储位置 | 用途 |
4759
|------|----------|------|
48-
| 项目级 | `_omp/memory/` | 项目配置、技术决策、变更记录 |
60+
| 项目级 | `_omp/memory/` | 项目配置、技术决策、变更记录、主题 |
4961
| 用户级 | `openmemory` MCP | 用户偏好、技能、跨项目上下文 |
5062

5163
## 分类规则
@@ -110,14 +122,30 @@ _omp/ # OpenMemory Plus 核心目录
110122

111123
---
112124

113-
## 🔄 自动化流程
125+
## 🔄 自动化流程 (xMemory Enhanced)
114126

115127
```
116-
对话/操作 → 信息检测 → 分类 → 提取 → 存储 → 通知
117-
↓ ↓ ↓ ↓ ↓ ↓
118-
输入源 触发判断 类型识别 结构化 写入YAML 更新Agent
128+
对话/操作 → 信息检测 → 分类 → 提取 → 存储 → 主题吸附 → 通知
129+
↓ ↓ ↓ ↓ ↓
130+
输入源 触发判断 类型识别 结构化 L2语义 L3主题聚合 更新Agent
119131
```
120132

133+
### xMemory 主题吸附 (L3 Assimilation)
134+
135+
当新的语义记忆存入 L2 层后,自动触发主题吸附:
136+
137+
```bash
138+
# 主题吸附流程
139+
1. 计算新记忆的 embedding
140+
2. 与现有主题 centroids 计算余弦相似度
141+
3. 相似度 >= 0.62 (attachThreshold): 吸附到现有主题
142+
4. 相似度 < 0.62: 创建新主题
143+
5. 主题语义数 > 10: 触发主题分裂
144+
6. 两主题相似度 > 0.78: 触发主题合并
145+
```
146+
147+
**配置位置**: `_omp/memory/themes/index.yaml`
148+
121149
### Phase 1: 信息检测
122150

123151
**检测规则**(按优先级):
@@ -470,6 +498,7 @@ pending_memories:
470498
471499
| 版本 | 变更 |
472500
|------|------|
501+
| v3.0 | xMemory 4 层架构:添加 L3 主题层、主题吸附流程、themes/ 目录 |
473502
| v2.1 | 目录重构:_omp/ 统一目录,移除 rules/,分类规则内嵌 |
474503
| v2.0 | 双层记忆架构:整合 openmemory MCP,智能分类路由 |
475504
| v1.1 | 添加错误处理、Schema 验证、模板文件、触发条件详解 |

cli/templates/shared/_omp/workflows/memory/steps/search.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: search
3-
description: 在项目级和用户级记忆中进行语义搜索
3+
description: 在项目级和用户级记忆中进行语义搜索(支持 xMemory 多层架构)
44
---
55

66
# Step: 搜索记忆
@@ -9,25 +9,51 @@ description: 在项目级和用户级记忆中进行语义搜索
99

1010
- ✅ Get search query from user if not provided
1111
- ✅ Search both project and user memory
12+
- ✅ Support xMemory layer selection (theme/semantic/all)
1213
- ✅ Display results with relevance scores
1314

1415
---
1516

17+
## xMemory Layers
18+
19+
| 层级 | CLI 选项 | 描述 |
20+
|------|----------|------|
21+
| L3 Theme | `--level theme` | 搜索主题层(聚合) |
22+
| L2 Semantic | `--level semantic` | 搜索语义层(默认) |
23+
| All | `--level all` | 自适应检索(L3→L2→L1) |
24+
25+
---
26+
1627
## EXECUTION
1728

1829
### 1. Get Search Query
1930

2031
If user provided query in their command, use it directly.
2132
Otherwise ask:
22-
> "请输入搜索关键词:"
33+
> "请输入搜索关键词(可选:指定层级 theme/semantic/all):"
34+
35+
### 2. Determine Search Level
2336

24-
### 2. Search User Memory
37+
根据用户输入或显式参数确定搜索层级:
38+
- 默认: `semantic` (L2 语义层)
39+
- 用户说 "主题/theme": `theme` (L3 主题层)
40+
- 用户说 "全部/all": `all` (自适应)
2541

26-
Call `search_memory_openmemory` with the query:
27-
- Get matching memories with scores
28-
- Sort by relevance
42+
### 3. Search User Memory
43+
44+
**L2 Semantic (默认):**
45+
```bash
46+
# 使用 openmemory MCP
47+
search_memory_openmemory(query="{query}")
48+
```
49+
50+
**L3 Theme (xMemory):**
51+
```bash
52+
omp search "{query}" --level theme
53+
# 不展开: omp search "{query}" --level theme --no-expand
54+
```
2955

30-
### 3. Search Project Memory
56+
### 4. Search Project Memory
3157

3258
Search `_omp/memory/*.md` and `_omp/memory/*.yaml` files:
3359
- Grep for query keywords
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
name: themes
3+
description: xMemory L3 主题层检索和管理
4+
---
5+
6+
# Step: 主题检索 (xMemory L3)
7+
8+
## EXECUTION RULES
9+
10+
- ✅ 使用 `omp search --level theme` 搜索主题层
11+
- ✅ 支持 `--no-expand` 选项仅返回主题,不展开到语义层
12+
- ✅ 显示主题的语义聚合信息
13+
14+
---
15+
16+
## xMemory 4-Layer Architecture
17+
18+
```
19+
L3 (Theme) ← 本操作的目标层
20+
↓ 包含
21+
L2 (Semantic) ← 语义记忆(Qdrant 向量)
22+
↓ 来源
23+
L1 (Episode) ← 情节记忆(会话)
24+
↓ 包含
25+
L0 (Message) ← 原始消息
26+
```
27+
28+
---
29+
30+
## EXECUTION
31+
32+
### 1. Get Search Query
33+
34+
如果用户没有提供查询词:
35+
> "请输入主题搜索关键词:"
36+
37+
### 2. Search Themes
38+
39+
使用 CLI 搜索主题层:
40+
41+
```bash
42+
# 搜索主题(自动展开到语义层)
43+
omp search "关键词" --level theme
44+
45+
# 仅返回主题,不展开
46+
omp search "关键词" --level theme --no-expand
47+
```
48+
49+
### 3. Display Results
50+
51+
```
52+
🎯 主题检索结果: "{query}"
53+
54+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
55+
56+
📁 L3 主题层:
57+
{foreach theme}
58+
[{n}] 主题: {theme_label}
59+
相似度: {score}
60+
包含语义记忆: {semantic_count} 条
61+
质心向量: [{centroid_preview}...]
62+
{/foreach}
63+
64+
📚 L2 语义层 (展开):
65+
{foreach semantic}
66+
[{n}] {content_preview}
67+
来源主题: {parent_theme}
68+
重要度: {importance}
69+
{/foreach}
70+
71+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
72+
73+
共找到 {theme_count} 个主题,{semantic_count} 条语义记忆
74+
```
75+
76+
### 4. Theme Management Actions
77+
78+
用户可继续操作:
79+
- `"展开 N"` → 查看主题 N 下的所有语义记忆
80+
- `"详情 N"` → 显示主题完整信息
81+
- `"搜索语义"` → 切换到 L2 语义层搜索
82+
83+
### 5. Theme Configuration
84+
85+
主题配置位于 `_omp/memory/themes/index.yaml`:
86+
87+
```yaml
88+
# 主题配置
89+
attachThreshold: 0.62 # 语义吸附到主题的阈值
90+
mergeThreshold: 0.78 # 主题合并阈值
91+
expandThreshold: 0.75 # 搜索时展开到语义层的阈值
92+
maxThemes: 50 # 最大主题数量
93+
splitThreshold: 10 # 单主题语义数超过此值时分裂
94+
```
95+
96+
---
97+
98+
## FALLBACK (CLI Unavailable)
99+
100+
如果 `omp` CLI 不可用:
101+
102+
1. 显示提示: `"⚠️ omp CLI 不可用,请先安装: npm install -g openmemory-plus"`
103+
2. 尝试直接读取 `_omp/memory/themes/index.yaml`
104+
3. 显示原始主题数据
105+
106+
---
107+
108+
## RETURN TO MENU
109+
110+
完成后提示:
111+
> "还需要其他操作吗?输入 **M** 返回菜单,或直接输入下一个操作"
112+

cli/templates/shared/_omp/workflows/memory/workflow.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: memory
3-
description: 记忆管理工作流 - 统一管理项目级和用户级记忆
4-
version: "2.0"
3+
description: 记忆管理工作流 - 统一管理项目级和用户级记忆(含 xMemory 4 层架构)
4+
version: "3.0"
55
---
66

77
# Memory Management Workflow
@@ -31,14 +31,19 @@ This uses **micro-file architecture** with **menu-driven routing**:
3131
- `memory_folder` = `{project-root}/_omp/memory`
3232
- `steps_path` = `{installed_path}/steps`
3333

34-
### ⚠️ DUAL-LAYER STORAGE RULE
34+
### ⚠️ xMemory 4-LAYER ARCHITECTURE
3535

36-
**CRITICAL: This system has TWO storage layers. You MUST use BOTH appropriately!**
36+
**CRITICAL: This system uses xMemory 4-layer hierarchical memory architecture!**
3737

3838
| Layer | Storage | What to Store |
3939
|-------|---------|---------------|
40-
| **项目级** | `_omp/memory/*.md` files | Project config, tech stack, decisions, URLs, paths |
41-
| **用户级** | openmemory MCP | User preferences, skills, cross-project habits |
40+
| **L3 Theme** | `_omp/memory/themes/` | 聚合主题,多个语义记忆的抽象 |
41+
| **L2 Semantic** | openmemory MCP (Qdrant) | 语义记忆,可检索的知识片段 |
42+
| **L1 Episode** | `_omp/memory/sessions/` | 情节记忆,会话上下文 |
43+
| **L0 Message** | 对话历史 | 原始消息(不持久化) |
44+
45+
**项目级文件** (`_omp/memory/*.md`): 项目配置、技术栈、决策、URL、路径
46+
**用户级记忆** (openmemory MCP): 用户偏好、技能、跨项目习惯
4247

4348
**DO NOT store everything to openmemory! Project-specific info MUST go to `_omp/memory/` files!**
4449

@@ -95,6 +100,7 @@ This uses **micro-file architecture** with **menu-driven routing**:
95100
[7] 🔗 知识图谱 查看实体关系
96101
[8] 📦 记忆整合 合并碎片化记忆
97102
[9] 📊 质量指标 查看记忆健康度和指标
103+
[10] 🎯 主题检索 搜索 L3 主题层(xMemory)
98104
99105
[M] 返回菜单 [X] 退出
100106
@@ -122,6 +128,7 @@ Based on user input, load the corresponding step file:
122128
| `7` | 图谱, 关系, graph, relation | `./steps/graph.md` |
123129
| `8` | 整合, 合并, consolidate, merge | `./steps/consolidate.md` |
124130
| `9` | 指标, 质量, metrics, health | `./steps/metrics.md` |
131+
| `10` | 主题, theme, L3, xmemory | `./steps/themes.md` |
125132
| `M` | 菜单, menu | Re-display menu |
126133
| `X` | 退出, exit, quit | Exit workflow |
127134

0 commit comments

Comments
 (0)