@xqli02/mneme 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,175 +1,170 @@
1
1
  # mneme
2
2
 
3
- 面向长期工程项目的 AI Agent 上下文与记忆架构。解决 coding agent 在跨 session 工作中的状态丢失、事实遗忘和重复分析问题。
3
+ **Three-layer memory architecture for AI coding agents.**
4
4
 
5
- > 架构设计详见 [ARCHITECTURE.md](ARCHITECTURE.md)
5
+ mneme gives coding agents (like [OpenCode](https://opencode.ai)) persistent memory across sessions. It separates long-term facts, task state, and short-term execution into three distinct layers — so agents stop forgetting decisions, losing progress, and repeating work.
6
6
 
7
- ---
7
+ ## The problem
8
8
 
9
- ## 快速开始
9
+ AI coding agents work in sessions. Each session has a context window that fills up and gets compacted. When that happens:
10
10
 
11
- ```bash
12
- # 安装
13
- npm install -g @xqli02/mneme
11
+ - **Architectural decisions get forgotten.** The agent re-analyzes problems it already solved.
12
+ - **Task progress is lost.** The agent doesn't know what it finished yesterday.
13
+ - **Lessons disappear.** The agent hits the same pitfalls again.
14
14
 
15
- # 在任意项目目录下初始化
16
- mkdir my-project && cd my-project
17
- mneme init
15
+ Prompt engineering doesn't fix this. The issue is structural: agents have no separation between things that must survive forever, things that must survive across sessions, and things that only matter right now.
18
16
 
19
- # 开始使用
20
- mneme
17
+ ## The solution: three layers
18
+
19
+ ```
20
+ ┌─────────────────────────────────────────┐
21
+ │ OpenClaw — Facts (long-term) │ survives forever
22
+ ├─────────────────────────────────────────┤
23
+ │ Beads — Tasks (mid-term) │ survives across sessions
24
+ ├─────────────────────────────────────────┤
25
+ │ OpenCode — Execution (short-term) │ lives within one session
26
+ └─────────────────────────────────────────┘
21
27
  ```
22
28
 
23
- `mneme init` 会自动完成:
24
- 1. 安装依赖(git、dolt、bd)
25
- 2. 初始化 git 仓库
26
- 3. 创建三层架构文件(`.openclaw/`、`.opencode/`、`AGENTS.md`、`.gitignore`)
27
- 4. 启动 dolt server + 初始化 beads
29
+ | Layer | What it stores | Lifetime | Example |
30
+ |-------|---------------|----------|---------|
31
+ | **OpenClaw** | Verified engineering facts — architecture decisions, constraints, pitfalls | Project lifetime | "Database must use PostgreSQL" |
32
+ | **Beads** | Task state — what's done, what's blocked, what's next | Cross-session | "Auth module: JWT signing done, verification pending" |
33
+ | **OpenCode** | Current execution context — code analysis, file edits | Single session | "This function's third parameter is timeout" |
34
+
35
+ Each layer has clear ownership. Facts can't be modified without human approval. Tasks are managed through a dependency-aware tracker. Execution context is disposable.
28
36
 
29
- ### CLI 命令
37
+ ## Quick start
38
+
39
+ Prerequisites: [Node.js](https://nodejs.org/) >= 18, [Git](https://git-scm.com/), [OpenCode](https://opencode.ai)
30
40
 
31
41
  ```bash
32
- mneme # 启动 opencode TUI(等同于 mneme start)
33
- mneme init # 初始化当前目录
34
- mneme doctor # 检查依赖和项目健康状态
35
- mneme status # 三层记忆状态总览
36
- mneme compact # 压缩前持久化检查
37
- mneme version # 打印版本号
38
-
39
- # OpenClaw — 长期事实管理
40
- mneme facts # 查看事实文件列表
41
- mneme facts --stats # 查看行数/预算统计
42
- mneme facts architecture # 查看某个事实文件内容
43
- mneme propose --file=pitfalls --content="..." --reason="..." # 提议新事实
44
- mneme review # 列出待审批提议
45
- mneme review <id> --approve # 批准提议,写入 facts
46
- mneme review <id> --reject # 拒绝提议
47
-
48
- # Beads — 任务管理
49
- mneme ready # 查看可执行任务
50
- mneme list --status=open # 列出所有未完成任务
51
- mneme show <id> # 查看任务详情
52
- mneme create --title="..." --description="..." --type=task -p 2 # 创建任务
53
- mneme update <id> --notes="进度说明" # 更新任务
54
- mneme close <id> --reason="完成" # 关闭任务
55
-
56
- # OpenCode — AI agent(opencode 透传)
57
- mneme auto # 自主 agent 监督循环(自动选取任务)
58
- mneme auto "fix the bug" # 指定目标启动
59
- mneme auto --attach URL # 连接已有 opencode 服务
60
- mneme run "fix the bug" # 非交互模式运行
61
- mneme web # 启动 Web 界面
62
- mneme serve # 启动 headless server
42
+ npm install -g @xqli02/mneme
43
+
44
+ cd your-project
45
+ mneme init
46
+ mneme
63
47
  ```
64
48
 
65
- ---
49
+ `mneme init` sets up everything in one command:
50
+ 1. Installs [Dolt](https://www.dolthub.com/repositories) and [bd](https://github.com/steveyegge/beads) if missing
51
+ 2. Initializes a git repo (if needed)
52
+ 3. Creates the three-layer structure (`.openclaw/`, `.beads/`, `.opencode/`, `AGENTS.md`)
53
+ 4. Starts the task database
54
+
55
+ That's it. Run `mneme` to launch the agent, or `mneme doctor` to verify your setup.
66
56
 
67
- ## 自主模式 (`mneme auto`)
57
+ ## How it works
68
58
 
69
- `mneme auto` 启动一个自主 agent 监督循环,自动从 beads 中选取任务并驱动 opencode 完成:
59
+ ### Every session starts the same way
60
+
61
+ The agent reads facts, checks tasks, picks one to focus on:
70
62
 
71
63
  ```bash
72
- mneme auto # 自动从 ready beads 中选取任务
73
- mneme auto "Build auth module" # 以指定目标启动
74
- mneme auto --attach http://localhost:4097 # 连接已有 opencode 服务
75
- mneme auto --port 4097 # 指定服务端口
76
- mneme auto --max-turns 50 # 限制最大轮次
64
+ mneme facts # Read long-term facts (agent does this automatically)
65
+ mneme ready # See which tasks have no blockers
66
+ mneme update <id> --status=in_progress # Claim a task
77
67
  ```
78
68
 
79
- 运行时可随时输入:
80
- - **任意文本** — 在下一轮注入反馈给 agent
81
- - `/status` — 查看当前任务状态
82
- - `/skip` — 跳过当前 bead
83
- - `/quit` — 停止并退出
69
+ ### During work
84
70
 
85
- 工作流程:
86
- 1. 启动(或连接)opencode serve 后端
87
- 2. 注入系统上下文(AGENTS.md + OpenClaw facts)
88
- 3. 从 `mneme ready` 选取最高优先级 bead
89
- 4. Claim bead → 构造 prompt → 发送给 opencode
90
- 5. 流式展示 agent 进度
91
- 6. 完成后自动选取下一个 bead
92
- 7. 无可执行 bead 时等待用户输入
71
+ The agent records progress and creates sub-tasks as it goes:
93
72
 
94
- ---
73
+ ```bash
74
+ mneme update <id> --notes="Implemented JWT signing, discovered need for refresh tokens"
75
+ mneme create --title="Add refresh token support" --type=task -p 2
76
+ ```
95
77
 
96
- ## 三层记忆架构
78
+ ### When done
97
79
 
98
- | 层 | 工具 | 职责 | 生命周期 |
99
- |---|---|---|---|
100
- | OpenClaw | `.openclaw/facts/*.md` | 不能忘的事实 | 跨项目 |
101
- | Beads | [bd](https://github.com/steveyegge/beads) | 不能断的进度 | 跨 session |
102
- | OpenCode | 对话上下文 | 当下的执行 | 单 session |
80
+ ```bash
81
+ mneme close <id> --reason="JWT auth complete with signing and verification"
82
+ ```
103
83
 
104
- ## 项目结构
84
+ ### New facts require approval
105
85
 
106
- `mneme init` 创建的文件:
86
+ Agents can propose facts, but only humans can approve them:
107
87
 
108
- ```
109
- .openclaw/facts/ 长期事实(架构、约束、红线、陷阱)
110
- .openclaw/proposals/ 待审批的事实提议(mneme propose 创建)
111
- .beads/ 任务状态(由 bd 管理)
112
- .opencode/prompt.md Session 启动 prompt
113
- AGENTS.md Agent 行为规则
114
- .gitignore 排除 dolt 数据等运行时文件
88
+ ```bash
89
+ mneme propose --file=architecture --content="Auth uses JWT with RS256" --reason="Decided after evaluating HMAC vs RSA"
90
+ mneme review # Human reviews pending proposals
91
+ mneme review <id> --approve # Write to facts
115
92
  ```
116
93
 
117
- ## Session 工作流
94
+ ### Autonomous mode
118
95
 
119
- ```bash
120
- # 1. 读取长期事实(agent 自动执行)
121
- mneme facts
96
+ `mneme auto` runs a supervisor loop that picks tasks and drives the agent continuously:
122
97
 
123
- # 2. 查看可执行任务
124
- mneme ready
98
+ ```bash
99
+ mneme auto # Auto-pick from ready tasks
100
+ mneme auto "Build auth module" # Start with a specific goal
101
+ ```
125
102
 
126
- # 3. Claim 一个任务
127
- mneme update <id> --status=in_progress
103
+ Type feedback anytime while it runs. `/status` to check progress, `/quit` to stop.
128
104
 
129
- # 4. 工作、记录进度
130
- mneme update <id> --notes="完成了 X,发现了 Y"
105
+ ## CLI reference
131
106
 
132
- # 5. 完成
133
- mneme close <id> --reason="Done"
134
107
  ```
108
+ mneme Launch agent (OpenCode TUI)
109
+ mneme init Initialize mneme in current directory
110
+ mneme doctor Check dependencies and project health
111
+ mneme status Three-layer memory dashboard
112
+ mneme auto [goal] Autonomous agent supervisor
113
+
114
+ mneme facts [name] [--stats] View long-term facts
115
+ mneme propose --file=... ... Propose a new fact
116
+ mneme review [id] [--approve] Review pending proposals
117
+
118
+ mneme ready Tasks with no blockers
119
+ mneme list [--status=STATUS] List tasks
120
+ mneme show <id> Task details
121
+ mneme create --title="..." Create a task
122
+ mneme update <id> [--notes=..] Update a task
123
+ mneme close <id> [--reason=..] Close a task
124
+ mneme blocked Show blocked tasks
125
+ mneme dep add <child> <parent> Add dependency
126
+
127
+ mneme run [message] Run agent non-interactively
128
+ mneme serve Start headless server
129
+ mneme compact Pre-compaction persistence check
130
+ mneme version Print version
131
+ ```
132
+
133
+ ## Project structure
135
134
 
136
- ## 什么信息放哪一层?
135
+ After `mneme init`, your project contains:
137
136
 
138
137
  ```
139
- 新信息产生
140
-
141
- ├─ 6 个月后还有用?
142
- │ ├─ YES + 事实/约束/教训 OpenClaw(提议写入,需人工确认)
143
- │ ├─ YES + 待办/进度 → Beads(直接写入)
144
- │ └─ NO 下个 session 需要?
145
- │ ├─ YES Beads
146
- │ └─ NO → 留在 OpenCode,不持久化
138
+ .openclaw/
139
+ facts/ Long-term facts (architecture, constraints, pitfalls)
140
+ proposals/ Pending fact proposals awaiting human review
141
+ .beads/ Task database (managed by bd, backed by Dolt)
142
+ .opencode/
143
+ prompt.md Session startup prompt for the agent
144
+ AGENTS.md Agent behavior rules and routing logic
147
145
  ```
148
146
 
149
- | 信息示例 | 写入层 |
150
- |---|---|
151
- | "数据库必须用 PostgreSQL" | OpenClaw `mneme propose --file=architecture` |
152
- | "禁止在生产环境直接改数据" | OpenClaw `mneme propose --file=invariants` |
153
- | "需要实现用户认证模块" | Beads `mneme create` |
154
- | "函数第 3 个参数是 timeout" | 不写,留在 OpenCode |
147
+ ## What mneme is
148
+
149
+ - A CLI that unifies agent execution, task tracking, and fact management
150
+ - A structure that gives agents persistent memory without custom infrastructure
151
+ - A workflow where humans stay in control of long-term decisions
155
152
 
156
- ## 核心文件说明
153
+ ## What mneme is not
157
154
 
158
- ### `.openclaw/facts/`
155
+ - Not a new AI model or agent — it wraps [OpenCode](https://opencode.ai)
156
+ - Not a RAG system — facts are curated, not retrieved from embeddings
157
+ - Not a framework — it's a single CLI with zero npm dependencies
158
+ - Not opinionated about your code — it only manages agent memory
159
159
 
160
- 存放已确认的长期工程事实,agent 不可单方面修改。
160
+ ## Example
161
161
 
162
- | 文件 | 内容 |
163
- |---|---|
164
- | `architecture.md` | 架构决策 |
165
- | `invariants.md` | 不可违反的约束与红线 |
166
- | `performance_rules.md` | 性能规则 |
167
- | `pitfalls.md` | 已知陷阱与教训 |
162
+ See [examples/basic/](examples/basic/) for a complete example of what a mneme-managed project looks like after initialization, with realistic facts filled in for a hypothetical todo-api project.
168
163
 
169
- ### `AGENTS.md`
164
+ ## Architecture
170
165
 
171
- 定义 agent session 启动流程、执行规则、三层路由决策树、compaction 前动作和禁止行为。
166
+ See [ARCHITECTURE.md](ARCHITECTURE.md) for the full design document.
172
167
 
173
- ### `.opencode/prompt.md`
168
+ ## License
174
169
 
175
- 每个新 session 的启动 prompt,引导 agent 按正确顺序建立上下文。
170
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xqli02/mneme",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Three-layer memory architecture for AI coding agents (OpenClaw + Beads + OpenCode)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -3,8 +3,7 @@
3
3
  */
4
4
 
5
5
  import { has, run, log, color } from "../utils.mjs";
6
- import { existsSync } from "node:fs";
7
- import { readdirSync } from "node:fs";
6
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
8
7
 
9
8
  /**
10
9
  * Check a single dependency. Returns true if OK.
@@ -20,13 +19,21 @@ function checkCmd(name, versionCmd) {
20
19
  }
21
20
 
22
21
  /**
23
- * Check if dolt server is reachable by bd.
22
+ * Check if dolt server is reachable by bd. Show which database is in use.
24
23
  */
25
24
  function checkDoltServer() {
26
25
  if (!has("bd")) return false;
27
26
  const result = run("bd list --status=open 2>&1");
28
27
  if (result !== null && !result.includes("unreachable") && !result.includes("Error")) {
29
- log.ok("dolt server reachable");
28
+ // Show which database this project uses
29
+ let dbInfo = "";
30
+ if (existsSync(".beads/metadata.json")) {
31
+ try {
32
+ const meta = JSON.parse(readFileSync(".beads/metadata.json", "utf-8"));
33
+ if (meta.dolt_database) dbInfo = ` ${color.dim(`(db: ${meta.dolt_database})`)}`;
34
+ } catch { /* ignore */ }
35
+ }
36
+ log.ok(`dolt server reachable${dbInfo}`);
30
37
  return true;
31
38
  }
32
39
  log.warn("dolt server not running or not reachable");
@@ -221,24 +221,34 @@ function installBd() {
221
221
 
222
222
  // ── Dolt server + bd init ───────────────────────────────────────────────────
223
223
 
224
+ /**
225
+ * Shared dolt data directory. All projects store their databases here,
226
+ * isolated by database name (e.g. beads_projectA, beads_projectB).
227
+ * One dolt server on port 3307 serves all projects on this machine.
228
+ */
229
+ const DOLT_DATA_DIR = process.env.MNEME_DOLT_DATA_DIR
230
+ || join(process.env.HOME, ".dolt", "databases");
231
+
232
+ const DOLT_PORT = parseInt(process.env.MNEME_DOLT_PORT || "3307", 10);
233
+
224
234
  function ensureDoltServer() {
225
- // Check if bd can already talk to dolt
235
+ if (!existsSync(DOLT_DATA_DIR)) {
236
+ mkdirSync(DOLT_DATA_DIR, { recursive: true });
237
+ }
238
+
239
+ // Check if a dolt server is already running and reachable
226
240
  const test = run("bd list --status=open 2>&1");
227
241
  if (test !== null && !test.includes("unreachable") && !test.includes("connection refused")) {
228
- log.ok("dolt server already running");
242
+ log.ok(`dolt server already running ${color.dim(`(port ${DOLT_PORT})`)}`);
229
243
  return true;
230
244
  }
231
245
 
232
- log.info("Starting dolt server...");
233
- const dataDir = existsSync(".beads/dolt") ? ".beads/dolt" : `${process.env.HOME}/.dolt/databases`;
234
-
235
- if (!existsSync(dataDir)) {
236
- mkdirSync(dataDir, { recursive: true });
237
- }
246
+ log.info(`Starting dolt server (port ${DOLT_PORT}, data-dir ${DOLT_DATA_DIR})...`);
247
+ const logFile = join(DOLT_DATA_DIR, "server.log");
238
248
 
239
- // Start in background
249
+ // Start in background — shared data dir, all project databases coexist
240
250
  run(
241
- `nohup dolt sql-server --host 127.0.0.1 --port 3307 --data-dir "${dataDir}" > /tmp/dolt-server.log 2>&1 &`,
251
+ `nohup dolt sql-server --host 127.0.0.1 --port ${DOLT_PORT} --data-dir "${DOLT_DATA_DIR}" > "${logFile}" 2>&1 &`,
242
252
  );
243
253
 
244
254
  // Wait for server to be ready (up to 10s)
@@ -246,12 +256,12 @@ function ensureDoltServer() {
246
256
  run("sleep 1");
247
257
  const check = run("bd list --status=open 2>&1");
248
258
  if (check !== null && !check.includes("unreachable") && !check.includes("connection refused")) {
249
- log.ok("dolt server started");
259
+ log.ok(`dolt server started ${color.dim(`(port ${DOLT_PORT})`)}`);
250
260
  return true;
251
261
  }
252
262
  }
253
263
 
254
- log.fail("dolt server failed to start. Check /tmp/dolt-server.log");
264
+ log.fail(`dolt server failed to start. Check ${logFile}`);
255
265
  return false;
256
266
  }
257
267
 
@@ -1,259 +1,258 @@
1
- # AGENTS.md — OpenCode Agent 行为规则
1
+ # AGENTS.md
2
2
 
3
- ## 身份与定位
3
+ Rules for AI coding agents operating within a mneme-managed project.
4
4
 
5
- 你是一个长期工程项目中的执行 agent。你**不承担长期记忆**,也**不承担任务管理**。你的记忆和任务状态分别由 OpenClaw Beads 管理。
5
+ This file is read by the agent at the start of every session. It defines what agents are allowed to do, what they are not allowed to do, and how to prioritize conflicting information.
6
6
 
7
- ---
7
+ ## Context priority order
8
8
 
9
- ## Session 启动流程(必须严格遵守)
9
+ When information conflicts, resolve it using this priority chain (highest first):
10
10
 
11
- 每个新 session 开始时,按以下顺序执行:
11
+ | Priority | Source | Example |
12
+ |----------|--------|---------|
13
+ | 1 (highest) | **OpenClaw facts** (`.openclaw/facts/`) | "Database must use PostgreSQL" |
14
+ | 2 | **This file** (AGENTS.md) | "Never skip the startup sequence" |
15
+ | 3 | **Beads task state** (`mneme ready`, `mneme list`) | "Auth module is in progress" |
16
+ | 4 | **User instructions** in the current session | "Focus on the auth module first" |
17
+ | 5 (lowest) | **Agent reasoning** and conversation history | "I think we should use SQLite" |
12
18
 
13
- 1. **读取 OpenClaw facts(长期事实)**
14
- - 阅读 `.openclaw/facts/` 下的所有文件
15
- - 这些内容优先级**高于**你的推理和对话历史
16
- - 若发现 facts 与当前情况矛盾,**提出质疑**而非直接修改
19
+ If an agent's reasoning contradicts an OpenClaw fact, the fact wins. If the agent believes the fact is outdated, it must raise the contradiction to the user rather than silently overriding it.
17
20
 
18
- 2. **读取 Beads 当前任务列表**
19
- - 执行 `mneme ready` 查看当前可执行的任务
20
- - 执行 `mneme list --status=open` 查看所有未完成任务
21
- - 了解当前所有未完成任务及其状态和依赖关系
21
+ ## What agents are allowed to do
22
22
 
23
- 3. **选择一个 bead 作为本 session 的 focus**
24
- - 只选一个,不要同时推进多个不相关任务
25
- - 优先从 `mneme ready` 的结果中选择(无阻塞依赖的 open 状态 bead)
23
+ ### Read from all three layers
26
24
 
27
- 4. **开始执行**
25
+ - Read all files in `.openclaw/facts/` at session start
26
+ - Run `mneme ready` and `mneme list` to check task state
27
+ - Read any project file needed for the current task
28
28
 
29
- ---
29
+ ### Manage tasks through mneme
30
30
 
31
- ## 执行过程中的规则
31
+ - Claim a task: `mneme update <id> --status=in_progress`
32
+ - Record progress: `mneme update <id> --notes="what was done"`
33
+ - Create sub-tasks: `mneme create --title="..." --description="..." --type=task -p 2`
34
+ - Add dependencies: `mneme dep add <child> <parent>`
35
+ - Close completed work: `mneme close <id> --reason="what was accomplished"`
32
36
 
33
- ### Beads 管理
37
+ ### Propose facts (with human approval)
34
38
 
35
- - 开始工作前先 claim 任务:`mneme update <id> --status=in_progress`
36
- - 完成一个阶段性目标后,更新对应 bead `notes`:`mneme update <id> --notes="进度说明"`
37
- - **不要依赖对话历史记住进度**,所有进度必须写入 Beads
38
- - 新发现的子任务应创建为新的 bead:`mneme create --title="..." --description="..." --type=task -p 2`
39
- - 关联发现的工作:`mneme dep add <new-id> <parent-id>`
40
- - **WARNING**: 禁止使用 `bd edit`,它会打开交互式编辑器。始终使用 `mneme update` 加参数
39
+ - Propose new long-term facts: `mneme propose --file=<name> --content="..." --reason="..."`
40
+ - A proposal must specify: which facts file, the exact content, and why it qualifies as a long-term fact
41
+ - The proposal is not written to facts until a human approves it via `mneme review`
41
42
 
42
- ### OpenClaw 管理
43
+ ### Execute code operations
43
44
 
44
- - 在执行过程中若发现新的长期事实(架构决策、红线、陷阱等),**提议**写入 OpenClaw
45
- - 提议需明确说明:
46
- - 写入哪个 facts 文件
47
- - 具体内容
48
- - 为什么这是一个"长期事实"而非临时结论
49
- - **等待人工确认后才能写入**
45
+ - Read, analyze, and modify code files
46
+ - Run commands (build, test, lint, etc.)
47
+ - Create commits and push to remote
48
+ - All code operations must serve the current focused task
50
49
 
51
- ### 代码操作
50
+ ### Persist state before compaction
52
51
 
53
- - 只负责代码分析、文件修改、命令执行等即时操作
54
- - 所有操作应服务于当前 focus bead 的目标
52
+ When context is getting long or a milestone is reached:
53
+ - Flush confirmed conclusions to Beads: `mneme update <id> --notes="..."`
54
+ - Propose any discovered facts to OpenClaw
55
+ - Close completed tasks or update notes with current progress and blockers
56
+ - Then allow compaction to proceed
55
57
 
56
- ---
58
+ ### Complete sessions cleanly
57
59
 
58
- ## 三层路由决策(自动分类)
59
-
60
- 在工作过程中,你会不断产生新的信息。**你必须主动判断每条信息属于哪一层**,而不是等待用户指示。以下是决策逻辑:
61
-
62
- ### 决策树
63
-
64
- ```
65
- 新信息产生
66
-
67
- ├─ 问:"6 个月后这条信息还有用吗?"
68
- │ │
69
- │ ├─ YES → 问:"这是一个事实/约束/教训,还是一个待办/进度?"
70
- │ │ │
71
- │ │ ├─ 事实/约束/教训 → **OpenClaw**(提议写入,等待确认)
72
- │ │ │
73
- │ │ └─ 待办/进度 → **Beads**(直接写入)
74
- │ │
75
- │ └─ NO → 问:"下个 session 需要这条信息吗?"
76
- │ │
77
- │ ├─ YES → **Beads**(写入 notes 或创建新 bead)
78
- │ │
79
- │ └─ NO → **OpenCode**(留在当前上下文,不持久化)
80
- ```
60
+ Before ending a session:
61
+ 1. Create tasks for any remaining work: `mneme create`
62
+ 2. Run quality gates if code changed (tests, linters, builds)
63
+ 3. Close finished tasks, update in-progress tasks with notes
64
+ 4. Push to remote — this is mandatory:
65
+ ```bash
66
+ git pull --rebase
67
+ git push
68
+ git status # Must show "up to date with origin"
69
+ ```
70
+ 5. If push fails, resolve and retry until it succeeds
81
71
 
82
- ### 分类示例
72
+ ## What agents are not allowed to do
83
73
 
84
- | 信息 | 分类 | 动作 |
85
- |----------------------------------------------|-----------|------------------------------------------------|
86
- | "这个项目用 Dolt 作为数据库后端" | OpenClaw | 提议写入 `facts/architecture.md` |
87
- | "禁止在生产环境直接修改 Dolt 数据" | OpenClaw | 提议写入 `facts/invariants.md` |
88
- | "`bd edit` 会打开交互式编辑器导致 agent 卡住"| OpenClaw | 提议写入 `facts/pitfalls.md` |
89
- | "需要实现用户认证模块" | Beads | `mneme create --title="实现用户认证" ...` |
90
- | "认证模块完成了 JWT 签发部分,还差验证" | Beads | `mneme update <id> --notes="JWT 签发完成..."` |
91
- | "这个函数的第 3 个参数是 timeout" | OpenCode | 不持久化,仅在当前操作中使用 |
92
- | "正在对比两种实现方案的 trade-off" | OpenCode | 不持久化,除非最终选择成为架构决策 |
74
+ ### Never skip the startup sequence
93
75
 
94
- ### 自动路由规则
76
+ Every session must begin with:
77
+ 1. Read `.openclaw/facts/` (all files)
78
+ 2. Run `mneme ready` and `mneme list --status=open`
79
+ 3. Pick one task as the session focus
80
+ 4. Begin work
95
81
 
96
- 1. **架构决策** 一旦做出并确认,提议写入 `facts/architecture.md`
97
- 2. **红线/约束** → 发现不可违反的规则时,提议写入 `facts/invariants.md`
98
- 3. **踩坑经验** → 遇到非显而易见的陷阱时,提议写入 `facts/pitfalls.md`
99
- 4. **性能基准** → 发现关键性能约束时,提议写入 `facts/performance_rules.md`
100
- 5. **新任务/子任务** → 发现需要做的工作时,`mneme create` 创建 bead
101
- 6. **进度更新** → 完成阶段性目标时,`mneme update --notes` 记录
102
- 7. **临时分析** → 代码分析、调试过程、方案对比 → 留在 OpenCode,不持久化
82
+ Skipping any step is prohibited. Do not start coding before reading facts and tasks.
103
83
 
104
- ### 写入 OpenClaw 的门槛检查
84
+ ### Never modify OpenClaw facts directly
105
85
 
106
- 在提议写入 OpenClaw 前,必须通过以下所有检查:
86
+ - Do not edit, delete, or overwrite files in `.openclaw/facts/`
87
+ - Do not write unverified hypotheses, temporary conclusions, or speculative analysis to facts
88
+ - The only path to changing facts is `mneme propose` followed by human `mneme review --approve`
107
89
 
108
- - [ ] 这条信息已被验证(不是假设或推测)
109
- - [ ] 这条信息在未来 session 中会被反复需要(不是一次性的)
110
- - [ ] 这条信息不会快速过时(不是某个临时状态)
111
- - [ ] 现有 facts 文件中没有等价信息(避免重复)
90
+ ### Never recover state from conversation history
112
91
 
113
- 只有全部通过才提议写入。提议后仍需等待人工确认。
92
+ - Do not reconstruct task progress from earlier messages in the conversation
93
+ - All task state must come from Beads (`mneme list`, `mneme show`)
94
+ - If a bead's notes are empty, ask the user rather than guessing from context
114
95
 
115
- ---
96
+ ### Never work on multiple unrelated tasks
116
97
 
117
- ## Compaction 前的固定动作
98
+ - Each session focuses on one task (one bead)
99
+ - Do not switch between unrelated tasks within a single session
100
+ - If a new urgent task is discovered, create it as a bead and let the next session pick it up
118
101
 
119
- 当感知到上下文即将过长,或在完成阶段性目标后,执行以下步骤:
102
+ ### Never create vague tasks
120
103
 
121
- 1. **持久化已确认的结论**
122
- - 将本 session 中已确认的结论更新到对应 bead:`mneme update <id> --notes="结论"`
104
+ - Every bead must have a clear, verifiable completion condition
105
+ - Bad: "Improve performance" no way to know when it's done
106
+ - Good: "Reduce API response time below 200ms for /users endpoint"
123
107
 
124
- 2. **提议新的长期事实**
125
- - 若发现应加入 OpenClaw 的内容,提出提议
108
+ ### Never use bd edit
126
109
 
127
- 3. **更新 bead 状态**
128
- - 若当前 bead 已完成,关闭它:`mneme close <id> --reason="完成说明"`
129
- - 若未完成,确保 `notes` 中记录了当前进度和卡点
110
+ - `bd edit` opens an interactive editor (`$EDITOR`), which hangs non-interactive agents
111
+ - Always use `mneme update <id>` with flags (`--notes`, `--status`, `--title`, `--description`)
130
112
 
131
- 4. **允许 compaction**
113
+ ### Never use markdown TODOs for task tracking
132
114
 
133
- > 原则:**可以丢失推理过程,但不能丢失状态与事实**
115
+ - All task tracking goes through mneme/beads
116
+ - Do not create TODO lists in markdown files, code comments, or any other format
117
+ - Do not use external issue trackers
134
118
 
135
- ---
119
+ ### Never stop before pushing
136
120
 
137
- ## 禁止行为
121
+ - Work is not complete until `git push` succeeds
122
+ - Do not say "ready to push when you are" — push immediately
123
+ - If push fails, resolve the conflict and retry
138
124
 
139
- - 禁止跳过 session 启动流程直接开始工作
140
- - 禁止从对话历史恢复任务进度
141
- - 禁止单方面修改或删除 OpenClaw facts
142
- - 禁止在一个 session 中同时推进多个不相关的 bead
143
- - 禁止将未验证的假设写入 OpenClaw
144
- - 禁止创建模糊的、无法验证完成与否的 bead
145
- - 禁止使用 `bd edit`(会打开交互式编辑器)
125
+ ## Session lifecycle
146
126
 
147
- <!-- BEGIN BEADS INTEGRATION -->
148
- ## Issue Tracking with mneme (beads)
127
+ ### 1. Startup
149
128
 
150
- **IMPORTANT**: This project uses **mneme** (backed by bd/beads) for ALL issue tracking. Do NOT use markdown TODOs, task lists, or other tracking methods.
129
+ ```bash
130
+ # Read long-term facts
131
+ cat .openclaw/facts/*.md
151
132
 
152
- ### Why beads?
133
+ # Check available work
134
+ mneme ready
135
+ mneme list --status=open
136
+ mneme list --status=in_progress
153
137
 
154
- - Dolt-Powered: Version-controlled SQL database with cell-level merge and native branching
155
- - Dependency-aware: Track blockers and relationships between issues
156
- - Agent-optimized: JSON output (`--json`), ready work detection, hash-based IDs
157
- - Zero conflict: Hash-based IDs (`bd-a1b2`) prevent merge collisions
158
- - Compaction: Semantic "memory decay" summarizes old closed tasks
138
+ # Claim a task
139
+ mneme update <id> --status=in_progress
140
+ ```
159
141
 
160
- ### Essential Commands
142
+ ### 2. Execution
161
143
 
162
- **Finding work:**
144
+ Work on the focused task. After each milestone:
163
145
 
164
146
  ```bash
165
- mneme ready # Show issues with no open blockers
166
- mneme list --status=open # All open issues
167
- mneme list --status=in_progress # Your active work
168
- mneme show <id> # Detailed issue view with dependencies
147
+ mneme update <id> --notes="Completed X. Next step: Y."
169
148
  ```
170
149
 
171
- **Creating issues:**
150
+ If you discover a sub-task:
172
151
 
173
152
  ```bash
174
- mneme create --title="Issue title" --description="Context" --type=task -p 2
175
- mneme create --title="Bug found" --description="Details" --type=bug -p 1
153
+ mneme create --title="Sub-task title" --description="Context" --type=task -p 2
154
+ mneme dep add <new-id> <parent-id>
176
155
  ```
177
156
 
178
- **Claiming and updating:**
157
+ ### 3. Pre-compaction
179
158
 
180
- ```bash
181
- mneme update <id> --status=in_progress # Claim work
182
- mneme update <id> --notes="Progress notes" # Add notes
183
- mneme update <id> --title="New title" # Update title
184
- mneme update <id> --description="Updated" # Update description
185
- ```
159
+ When context is growing long or you've finished a milestone:
186
160
 
187
- **Dependencies:**
161
+ 1. Write confirmed conclusions to Beads notes
162
+ 2. Propose any new facts via `mneme propose`
163
+ 3. Close completed tasks or update notes with blockers
188
164
 
189
- ```bash
190
- mneme dep add <child> <parent> # child depends on parent
191
- mneme blocked # Show all blocked issues
192
- ```
165
+ Principle: **you can lose the reasoning, but you must not lose the state or the facts.**
193
166
 
194
- **Completing work:**
167
+ ### 4. Completion
195
168
 
196
169
  ```bash
197
- mneme close <id> --reason "Done" # Close single issue
198
- mneme close <id1> <id2> ... # Close multiple at once
170
+ # Close finished work
171
+ mneme close <id> --reason="Summary of what was done"
172
+
173
+ # Create tasks for remaining work
174
+ mneme create --title="Follow-up" --description="..." --type=task -p 2
175
+
176
+ # Push everything
177
+ git pull --rebase && git push
199
178
  ```
200
179
 
201
- ### Issue Types
180
+ ## Information routing
202
181
 
203
- - `bug` - Something broken
204
- - `feature` - New functionality
205
- - `task` - Work item (tests, docs, refactoring)
206
- - `epic` - Large feature with subtasks
207
- - `chore` - Maintenance (dependencies, tooling)
182
+ When you encounter new information, classify it immediately:
208
183
 
209
- ### Priorities
184
+ ```
185
+ New information
186
+
187
+ ├─ Will this matter in 6 months?
188
+ │ ├─ Yes + it's a fact/constraint/lesson → Propose to OpenClaw
189
+ │ ├─ Yes + it's a task or progress update → Write to Beads
190
+ │ └─ No → Will the next session need it?
191
+ │ ├─ Yes → Write to Beads (notes or new task)
192
+ │ └─ No → Keep in context, don't persist
193
+ ```
210
194
 
211
- - `0` / `P0` - Critical (security, data loss, broken builds)
212
- - `1` / `P1` - High (major features, important bugs)
213
- - `2` / `P2` - Medium (default)
214
- - `3` / `P3` - Low (polish, optimization)
215
- - `4` / `P4` - Backlog (future ideas)
195
+ | Information | Layer | Action |
196
+ |---|---|---|
197
+ | "This project uses event sourcing" | OpenClaw | `mneme propose --file=architecture` |
198
+ | "Never call the payments API without idempotency keys" | OpenClaw | `mneme propose --file=invariants` |
199
+ | "Batch size over 1000 causes OOM" | OpenClaw | `mneme propose --file=performance_rules` |
200
+ | "The config parser silently drops unknown keys" | OpenClaw | `mneme propose --file=pitfalls` |
201
+ | "Need to add rate limiting to the API" | Beads | `mneme create --title="Add API rate limiting"` |
202
+ | "Rate limiting: token bucket implemented, need tests" | Beads | `mneme update <id> --notes="..."` |
203
+ | "This function returns null on line 47" | Context | Don't persist |
216
204
 
217
- ### Workflow for AI Agents
205
+ ### Proposing facts: threshold check
218
206
 
219
- 1. **Check ready work**: `mneme ready` shows unblocked issues
220
- 2. **Claim your task**: `mneme update <id> --status=in_progress`
221
- 3. **Work on it**: Implement, test, document
222
- 4. **Discover new work?** Create linked issue with `mneme create` + `mneme dep add`
223
- 5. **Complete**: `mneme close <id> --reason "Done"`
207
+ Before proposing a fact, verify all four conditions:
224
208
 
225
- ### Important Rules
209
+ - [ ] The information has been verified (not a hypothesis or guess)
210
+ - [ ] Future sessions will repeatedly need it (not one-time)
211
+ - [ ] It won't become outdated quickly (not a temporary state)
212
+ - [ ] No equivalent fact already exists in `.openclaw/facts/`
226
213
 
227
- - Use mneme for ALL task tracking
228
- - Always use `--json` flag for programmatic use
229
- - Check `mneme ready` before asking "what should I work on?"
230
- - Do NOT use `bd edit` (opens interactive editor)
231
- - Do NOT create markdown TODO lists for task tracking
232
- - Do NOT use external issue trackers
214
+ All four must pass. Then propose and wait for human approval.
233
215
 
234
- <!-- END BEADS INTEGRATION -->
216
+ ## Task management reference
235
217
 
236
- ## Landing the Plane (Session Completion)
218
+ ### Issue types
237
219
 
238
- **When ending a work session**, you MUST complete ALL steps below. Work is NOT complete until `git push` succeeds.
220
+ | Type | Use for |
221
+ |---|---|
222
+ | `bug` | Something broken |
223
+ | `feature` | New functionality |
224
+ | `task` | Work items: tests, docs, refactoring |
225
+ | `epic` | Large feature with sub-tasks |
226
+ | `chore` | Maintenance: dependencies, tooling |
239
227
 
240
- **MANDATORY WORKFLOW:**
228
+ ### Priorities
241
229
 
242
- 1. **File issues for remaining work** - Create issues for anything that needs follow-up
243
- 2. **Run quality gates** (if code changed) - Tests, linters, builds
244
- 3. **Update issue status** - Close finished work, update in-progress items
245
- 4. **PUSH TO REMOTE** - This is MANDATORY:
246
- ```bash
247
- git pull --rebase
248
- git push
249
- git status # MUST show "up to date with origin"
250
- ```
251
- 5. **Clean up** - Clear stashes, prune remote branches
252
- 6. **Verify** - All changes committed AND pushed
253
- 7. **Hand off** - Provide context for next session
254
-
255
- **CRITICAL RULES:**
256
- - Work is NOT complete until `git push` succeeds
257
- - NEVER stop before pushing - that leaves work stranded locally
258
- - NEVER say "ready to push when you are" - YOU must push
259
- - If push fails, resolve and retry until it succeeds
230
+ | Priority | Level | Use for |
231
+ |---|---|---|
232
+ | `0` / P0 | Critical | Security, data loss, broken builds |
233
+ | `1` / P1 | High | Major features, important bugs |
234
+ | `2` / P2 | Medium | Default priority |
235
+ | `3` / P3 | Low | Polish, optimization |
236
+ | `4` / P4 | Backlog | Future ideas |
237
+
238
+ ### Commands
239
+
240
+ ```bash
241
+ # Find work
242
+ mneme ready # Unblocked tasks
243
+ mneme list --status=open # All open tasks
244
+ mneme list --status=in_progress # Active work
245
+ mneme show <id> # Task details with dependencies
246
+ mneme blocked # Tasks waiting on blockers
247
+
248
+ # Create and link
249
+ mneme create --title="..." --description="..." --type=task -p 2
250
+ mneme dep add <child> <parent>
251
+
252
+ # Update
253
+ mneme update <id> --status=in_progress
254
+ mneme update <id> --notes="Progress notes"
255
+
256
+ # Complete
257
+ mneme close <id> --reason="Done"
258
+ ```
@@ -1,6 +1,6 @@
1
1
  # Architecture
2
2
 
3
- <!-- 在此记录项目的架构决策。示例:-->
4
- <!-- - 数据库使用 PostgreSQL,ORM 使用 SQLAlchemy -->
5
- <!-- - API 层使用 FastAPI,前端使用 React -->
6
- <!-- - 部署采用 Docker + K8s -->
3
+ <!-- Record your project's architecture decisions here. Examples: -->
4
+ <!-- - Database: PostgreSQL with pg (node-postgres) connection pool -->
5
+ <!-- - API: Express 5 with JSON envelope responses -->
6
+ <!-- - Deployment: Docker container behind nginx reverse proxy -->
@@ -1,6 +1,6 @@
1
- # Invariants — 不可违反的约束
1
+ # Invariants
2
2
 
3
- <!-- 在此记录项目的硬性约束和红线。示例:-->
4
- <!-- - 所有 API 必须经过认证,禁止匿名访问 -->
5
- <!-- - 数据库 migration 必须向后兼容 -->
6
- <!-- - 响应时间不得超过 200ms (P99) -->
3
+ <!-- Record hard constraints and rules that must never be violated. Examples: -->
4
+ <!-- - All API endpoints require authentication (no anonymous access) -->
5
+ <!-- - Database migrations must be backward-compatible -->
6
+ <!-- - P99 response time must stay below 200ms -->
@@ -1,5 +1,5 @@
1
1
  # Performance Rules
2
2
 
3
- <!-- 在此记录性能相关的规则和约束。示例:-->
4
- <!-- - 批量操作优于逐条操作 -->
5
- <!-- - 缓存 TTL 不超过 5 分钟 -->
3
+ <!-- Record performance-related rules and constraints. Examples: -->
4
+ <!-- - Batch operations over bulk row-by-row inserts -->
5
+ <!-- - Cache TTL must not exceed 5 minutes -->
@@ -1,5 +1,5 @@
1
- # Pitfalls — 已知陷阱
1
+ # Pitfalls
2
2
 
3
- <!-- 在此记录踩过的坑和非显而易见的陷阱。示例:-->
4
- <!-- - MySQL utf8 实际是 3 字节,需要用 utf8mb4 -->
5
- <!-- - Docker build COPY 会导致缓存失效,注意顺序 -->
3
+ <!-- Record non-obvious traps and lessons learned. Examples: -->
4
+ <!-- - MySQL's utf8 is only 3 bytes; use utf8mb4 for full Unicode support -->
5
+ <!-- - COPY in Dockerfile invalidates the build cache; order layers carefully -->
@@ -1,48 +1,46 @@
1
- 这是一个长期工程项目,请严格按以下顺序建立上下文:
1
+ This is a long-running engineering project. Follow this sequence strictly at session start:
2
2
 
3
- ## 第一步:读取 OpenClaw facts(长期事实)
3
+ ## Step 1: Read OpenClaw facts (long-term knowledge)
4
4
 
5
- 请完整阅读以下文件:
5
+ Read all of these files completely:
6
6
  - .openclaw/facts/architecture.md
7
7
  - .openclaw/facts/invariants.md
8
8
  - .openclaw/facts/performance_rules.md
9
9
  - .openclaw/facts/pitfalls.md
10
10
 
11
- 这些内容是长期事实:
12
- - 优先级高于对话历史和你的推理
13
- - 不要随意推翻
14
- - 若发现矛盾,请提出而不是修改
11
+ These are verified long-term facts:
12
+ - They take priority over conversation history and your own reasoning
13
+ - Do not override or dismiss them
14
+ - If you find a contradiction, raise it instead of silently changing facts
15
15
 
16
- ## 第二步:读取 Beads 当前任务列表
16
+ ## Step 2: Read current task state from Beads
17
17
 
18
- 使用 `mneme` 命令查看当前任务状态:
19
- - `mneme ready` — 查看可执行任务(无阻塞依赖)
20
- - `mneme list --status=open` — 查看所有未完成任务
21
- - `mneme show <id>` — 查看具体任务详情
18
+ Use `mneme` commands to check what work is available:
19
+ - `mneme ready` — tasks with no blocking dependencies
20
+ - `mneme list --status=open` — all incomplete tasks
21
+ - `mneme show <id>` — details for a specific task
22
22
 
23
- ## 第三步:选择 focus
23
+ ## Step 3: Pick a focus
24
24
 
25
- - 只选择一个 bead 作为本 session 的目标
26
- - 优先从 `mneme ready` 结果中选择
27
- - 选定后 claim 它:`mneme update <id> --status=in_progress`
28
- - 不要试图从对话历史中恢复状态
25
+ - Choose exactly one task (bead) as this session's goal
26
+ - Prefer tasks from `mneme ready` (no blockers)
27
+ - Claim it: `mneme update <id> --status=in_progress`
28
+ - Do not reconstruct progress from conversation history
29
29
 
30
- ## 信息路由(自动执行,不需要用户指示)
30
+ ## Information routing (automatic — no user prompting needed)
31
31
 
32
- 在工作过程中你会产生新信息。**你必须自动判断它属于哪一层**:
32
+ As you work, you will discover new information. Classify it immediately:
33
33
 
34
- - **6 个月后还有用?** + 是事实/约束/教训 **提议写入 OpenClaw**(需人工确认)
35
- - **6 个月后还有用?** + 是待办/进度 **写入 Beads**(`mneme create` `mneme update --notes`)
36
- - **下个 session 需要?** **写入 Beads**
37
- - **仅当前操作需要?** → 留在 OpenCode,不持久化
34
+ - **Long-term fact or constraint?** Propose to OpenClaw: `mneme propose --file=<name> --content="..." --reason="..."`
35
+ - **Task or progress update?** Write to Beads: `mneme create` or `mneme update <id> --notes="..."`
36
+ - **Only relevant right now?** Keep in context, do not persist
38
37
 
39
- 写入 OpenClaw 前的检查:已验证 + 反复需要 + 不会快速过时 + 无重复。详见 AGENTS.md "三层路由决策" 一节。
38
+ Before proposing a fact, verify: it's confirmed (not a guess), future sessions will need it, it won't become stale quickly, and no duplicate exists.
40
39
 
41
- ## 重要原则
40
+ ## Key rules
42
41
 
43
- - 不要跳过上述步骤直接开始工作
44
- - 完成阶段性目标后更新 Beads:`mneme update <id> --notes="进度"`
45
- - 完成任务后关闭:`mneme close <id> --reason="完成说明"`
46
- - 发现新的长期事实时提议写入 OpenClaw(需人工确认)
47
- - Compaction 前必须持久化状态与结论
48
- - 禁止使用 `bd edit`(会打开交互式编辑器),使用 `mneme update` 代替
42
+ - Do not skip these steps and jump straight to coding
43
+ - After completing a milestone: `mneme update <id> --notes="what was done"`
44
+ - After finishing a task: `mneme close <id> --reason="summary"`
45
+ - Before compaction: persist all confirmed conclusions to Beads
46
+ - Never use `bd edit` (opens interactive editor) — use `mneme update` with flags instead