Skip to content

Commit 003bbce

Browse files
committed
feat: update memory rules
1 parent 0ad786a commit 003bbce

1 file changed

Lines changed: 106 additions & 45 deletions

File tree

Lines changed: 106 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,143 @@
1-
# User Teaching Memory Rule
1+
# 用户指令记忆规则
22

3-
## Description
4-
When a user teaches or instructs the AI assistant on how to perform a task or behave in a certain way during a chat conversation, these teachings should be recorded in a .monkeycode/MEMORY.md file located in the repository root.
3+
## 描述
54

6-
## Implementation
7-
- Monitor chat conversations for teaching-oriented instructions from users
8-
- Before adding a new entry, scan .monkeycode/MEMORY.md for similar or identical instructions
9-
- If a duplicate is found, either skip adding the new entry or merge it with the existing one
10-
- When merging, update the existing entry with new context or date
11-
- If no duplicate is found, append the instruction to .monkeycode/MEMORY.md in the repository root
12-
- Format entries with date, user instruction, and context
13-
- Preserve user privacy while capturing useful behavioral instructions
5+
当用户在对话中教导或指示 AI 助手如何执行任务或以某种方式行动时,这些教导应被记录到仓库根目录的 `.monkeycode/MEMORY.md` 文件中。此外,当 Agent 在执行任务过程中发现有价值的项目知识(如代码结构模式、代码生成工作流、构建方法等),也应主动将这些发现记录到同一文件中。
146

15-
## Purpose
16-
This creates a persistent memory of user preferences and instructions that can guide future interactions and customizations.
7+
## 实现方式
178

18-
## MUST DO
9+
- 监控对话中用户的教导性指令
10+
- 在任务执行过程中,主动识别并记录项目特有的知识(代码结构、代码生成时机/方法、构建方法、测试模式等)
11+
- 添加新条目前,先扫描 `.monkeycode/MEMORY.md` 检查是否存在相似或相同的指令
12+
- 若发现重复,跳过新条目或与已有条目合并
13+
- 合并时,更新已有条目的上下文或日期
14+
- 若无重复,将指令追加到仓库根目录的 `.monkeycode/MEMORY.md`
15+
- 条目格式应包含日期、用户指令和上下文
16+
- 在记录有用的行为指令时注意保护用户隐私
1917

20-
- You MUST CREATE the [Memory File](.monkeycode/MEMORY.md) according to the **File Template** before your first reply IF IT'S NOT EXIST!
21-
- You MUST READ the [Memory File](.monkeycode/MEMORY.md) as project level instruction before your first reply!
22-
- EVERY user input should be validated by the following **Trigger Conditions**, Once MATCHED, UPDATE the [Memory File](.monkeycode/MEMORY.md) with user's instruction IMMEDIATLY BEFORE DOING ANYTHING
18+
## 目的
2319

24-
## Trigger Conditions
20+
建立用户偏好和指令的持久化记忆,用于指导未来的交互和定制。
2521

26-
### 1. User provides EXPLICIT INSTRUCTIONS about how to behave
22+
## 强制执行事项
2723

28-
> Examples:
24+
- 如果 [记忆文件](.monkeycode/MEMORY.md) 不存在,**必须**在首次回复前按照**文件模板**创建该文件!
25+
- **必须**在首次回复前读取 [记忆文件](.monkeycode/MEMORY.md) 作为项目级指令!
26+
- **每一条**用户输入都应按照以下**触发条件**进行验证,一旦匹配,**必须立即**更新 [记忆文件](.monkeycode/MEMORY.md),然后再执行其他任何操作
27+
28+
## 触发条件
29+
30+
### 1. 用户提供关于行为方式的明确指令
31+
32+
> 示例:
2933
> - "回复我的时候请用中文"
3034
> - "Always respond in bullet points"
3135
> - "代码注释统一用英文写"
3236
> - "不要在回复中使用 emoji"
3337
34-
### 2. User INSTRUCTS or CORRECTS the assistant's behavior
38+
### 2. 用户指示或纠正助手的行为
3539

36-
> Examples:
37-
> - **Do something when some condition**: "每次改完代码后自动跑一下 lint"、"When I ask you to refactor, always write unit tests first"
38-
> - **Don't do something when some condition**: "不要自动删除注释掉的代码"、"Don't modify files outside the src/ directory unless I explicitly say so"
39-
> - **Use (or don't use) XXX to do something in XXX project/module**: "这个项目用 pnpm 不要用 npm"、"Use `pytest` instead of `unittest` in this repo"、"在 backend 模块里不要用 print,用 logger"
40+
> 示例:
41+
> - **满足某条件时做某事**"每次改完代码后自动跑一下 lint"、"When I ask you to refactor, always write unit tests first"
42+
> - **满足某条件时不做某事**"不要自动删除注释掉的代码"、"Don't modify files outside the src/ directory unless I explicitly say so"
43+
> - **在某项目/模块中使用(或不使用)某工具**"这个项目用 pnpm 不要用 npm"、"Use `pytest` instead of `unittest` in this repo"、"在 backend 模块里不要用 print,用 logger"
4044
41-
### 3. User gives advice on preferred approaches
45+
### 3. 用户提出偏好的实现方式
4246

43-
> Examples:
47+
> 示例:
4448
> - "我更喜欢函数式写法,少用 class"
4549
> - "Prefer composition over inheritance in this project"
4650
> - "写 SQL 的时候用 CTE 而不是子查询"
4751
> - "CSS 优先用 Tailwind 的 utility class,不要写自定义样式"
4852
49-
### 4. User explains how they'd like tasks to be performed
53+
### 4. 用户说明期望的任务执行方式
5054

51-
> Examples:
55+
> 示例:
5256
> - "改 bug 之前先帮我写个能复现问题的测试用例"
5357
> - "每次提交代码前先跑 `make check`"
5458
> - "重构的时候一次只改一个文件,改完我确认了再继续"
5559
> - "When adding a new API endpoint, always update the OpenAPI spec first"
5660
57-
## File Template for MEMORY.md
61+
### 5. Agent 在执行任务过程中主动发现项目知识
62+
63+
Agent 在阅读代码、执行构建、调试问题等任务过程中,如果发现了对后续开发有参考价值的项目知识,应主动记录到 MEMORY.md 中。这类知识不需要用户明确指示,Agent 应自行判断并记录。
64+
65+
#### 触发时机
66+
67+
- **阅读代码时**:发现项目的典型代码结构、分层模式、命名约定等
68+
- **执行构建时**:了解到项目的构建命令、构建工具链、构建配置等
69+
- **运行测试时**:了解到测试框架、测试命令、测试约定等
70+
- **代码生成时**:发现项目使用了代码生成工具(如 protobuf、OpenAPI codegen、ORM migration 等),记录生成的时机和方法
71+
- **调试问题时**:发现项目的特殊依赖关系、环境要求、已知陷阱等
72+
73+
#### 应记录的内容类别
74+
75+
| 类别 | 说明 | 示例 |
76+
|------|------|------|
77+
| 代码结构 | 项目的目录组织、分层架构、模块划分 | "项目采用 DDD 分层:domain/application/infrastructure/interfaces" |
78+
| 代码模式 | 项目中反复出现的典型写法和约定 | "所有 API handler 统一使用 `handleXxx` 命名,返回值包裹在 `Result<T>` 中" |
79+
| 代码生成 | 自动生成代码的工具、触发时机、生成命令 | "修改 proto 文件后需执行 `make gen-proto` 重新生成 gRPC 代码" |
80+
| 构建方法 | 项目的构建命令、构建工具、构建流程 | "前端使用 `pnpm build`,后端使用 `go build ./cmd/server`" |
81+
| 测试方法 | 测试框架、测试命令、测试约定 | "单元测试使用 `pytest`,集成测试使用 `pytest -m integration`" |
82+
| 依赖关系 | 模块间的关键依赖、外部服务依赖 | "用户模块依赖 Redis 做会话存储,启动前需确保 Redis 可用" |
83+
| 环境配置 | 开发环境的特殊配置要求 | "需要设置环境变量 `DATABASE_URL` 才能启动本地开发服务器" |
84+
85+
#### 记录格式
86+
87+
使用与用户指令相同的条目格式,但 Context 字段标注为 Agent 自主发现:
88+
89+
```
90+
[项目知识摘要]
91+
- Date: [YYYY-MM-DD]
92+
- Context: Agent 在执行 [具体任务描述] 时发现
93+
- Category: [代码结构|代码模式|代码生成|构建方法|测试方法|依赖关系|环境配置]
94+
- Instructions:
95+
- [具体的知识点,逐行描述]
96+
```
97+
98+
#### 注意事项
99+
100+
- **避免记录显而易见的内容**:如 "项目使用了 JavaScript" 这类不需要特别记忆的信息
101+
- **聚焦可操作性**:记录的内容应对后续开发任务有直接帮助
102+
- **遵循去重策略**:与用户指令条目一样,新发现的知识需要先检查是否已有类似记录
103+
- **不记录敏感信息**:不记录密钥、密码、token 等敏感内容
104+
- **及时记录**:在发现后尽快写入 MEMORY.md,不要等到任务结束
105+
106+
## MEMORY.md 文件模板
58107

59108
```markdown
60-
# Memory of User Instructions
109+
# 用户指令记忆
61110

62-
This file contains a record of user instructions, preferences, and teachings that should be remembered for future interactions.
111+
本文件记录了用户的指令、偏好和教导,用于在未来的交互中提供参考。
112+
113+
## 格式
114+
115+
### 用户指令条目
116+
用户指令条目应遵循以下格式:
117+
118+
[用户指令摘要]
119+
- Date: [YYYY-MM-DD]
120+
- Context: [提及的场景或时间]
121+
- Instructions:
122+
- [用户教导或指示的内容,逐行描述]
63123

64-
## Format
65-
Entries should follow this format:
124+
### 项目知识条目
125+
Agent 在任务执行过程中发现的条目应遵循以下格式:
66126

67-
[User instruction summary]
127+
[项目知识摘要]
68128
- Date: [YYYY-MM-DD]
69-
- Context: [Where or when this was mentioned]
129+
- Context: Agent 在执行 [具体任务描述] 时发现
130+
- Category: [代码结构|代码模式|代码生成|构建方法|测试方法|依赖关系|环境配置]
70131
- Instructions:
71-
- [What the user taught or instructed, line by line]
132+
- [具体的知识点,逐行描述]
72133

73-
## Deduplication Policy
74-
- Before adding a new entry, check for similar or identical instructions
75-
- If a duplicate is found, either skip the new entry or merge with existing one
76-
- When merging, update with new context or date information
77-
- This helps prevent redundant entries and keeps the memory clean
134+
## 去重策略
135+
- 添加新条目前,检查是否存在相似或相同的指令
136+
- 若发现重复,跳过新条目或与已有条目合并
137+
- 合并时,更新上下文或日期信息
138+
- 这有助于避免冗余条目,保持记忆文件整洁
78139

79-
## Entries
140+
## 条目
80141

81-
[some memory entries in the Format declared above]
82-
```
142+
[按上述格式记录的记忆条目]
143+
```

0 commit comments

Comments
 (0)