pmem-ai 0.5.0

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE +21 -0
  3. package/README.md +349 -0
  4. package/dist/commands/ask.d.ts +3 -0
  5. package/dist/commands/ask.d.ts.map +1 -0
  6. package/dist/commands/ask.js +303 -0
  7. package/dist/commands/ask.js.map +1 -0
  8. package/dist/commands/distill.d.ts +6 -0
  9. package/dist/commands/distill.d.ts.map +1 -0
  10. package/dist/commands/distill.js +425 -0
  11. package/dist/commands/distill.js.map +1 -0
  12. package/dist/commands/graph.d.ts +6 -0
  13. package/dist/commands/graph.d.ts.map +1 -0
  14. package/dist/commands/graph.js +216 -0
  15. package/dist/commands/graph.js.map +1 -0
  16. package/dist/commands/init.d.ts +5 -0
  17. package/dist/commands/init.d.ts.map +1 -0
  18. package/dist/commands/init.js +566 -0
  19. package/dist/commands/init.js.map +1 -0
  20. package/dist/commands/integration.d.ts +2 -0
  21. package/dist/commands/integration.d.ts.map +1 -0
  22. package/dist/commands/integration.js +216 -0
  23. package/dist/commands/integration.js.map +1 -0
  24. package/dist/commands/migrate.d.ts +6 -0
  25. package/dist/commands/migrate.d.ts.map +1 -0
  26. package/dist/commands/migrate.js +379 -0
  27. package/dist/commands/migrate.js.map +1 -0
  28. package/dist/commands/rebuild.d.ts +8 -0
  29. package/dist/commands/rebuild.d.ts.map +1 -0
  30. package/dist/commands/rebuild.js +299 -0
  31. package/dist/commands/rebuild.js.map +1 -0
  32. package/dist/commands/recall.d.ts +3 -0
  33. package/dist/commands/recall.d.ts.map +1 -0
  34. package/dist/commands/recall.js +140 -0
  35. package/dist/commands/recall.js.map +1 -0
  36. package/dist/commands/session.d.ts +3 -0
  37. package/dist/commands/session.d.ts.map +1 -0
  38. package/dist/commands/session.js +147 -0
  39. package/dist/commands/session.js.map +1 -0
  40. package/dist/commands/status.d.ts +5 -0
  41. package/dist/commands/status.d.ts.map +1 -0
  42. package/dist/commands/status.js +275 -0
  43. package/dist/commands/status.js.map +1 -0
  44. package/dist/commands/update.d.ts +14 -0
  45. package/dist/commands/update.d.ts.map +1 -0
  46. package/dist/commands/update.js +536 -0
  47. package/dist/commands/update.js.map +1 -0
  48. package/dist/commands/verify.d.ts +4 -0
  49. package/dist/commands/verify.d.ts.map +1 -0
  50. package/dist/commands/verify.js +296 -0
  51. package/dist/commands/verify.js.map +1 -0
  52. package/dist/core/db.d.ts +47 -0
  53. package/dist/core/db.d.ts.map +1 -0
  54. package/dist/core/db.js +326 -0
  55. package/dist/core/db.js.map +1 -0
  56. package/dist/core/format.d.ts +3 -0
  57. package/dist/core/format.d.ts.map +1 -0
  58. package/dist/core/format.js +221 -0
  59. package/dist/core/format.js.map +1 -0
  60. package/dist/core/fs.d.ts +16 -0
  61. package/dist/core/fs.d.ts.map +1 -0
  62. package/dist/core/fs.js +175 -0
  63. package/dist/core/fs.js.map +1 -0
  64. package/dist/core/git.d.ts +6 -0
  65. package/dist/core/git.d.ts.map +1 -0
  66. package/dist/core/git.js +20 -0
  67. package/dist/core/git.js.map +1 -0
  68. package/dist/core/hash.d.ts +10 -0
  69. package/dist/core/hash.d.ts.map +1 -0
  70. package/dist/core/hash.js +25 -0
  71. package/dist/core/hash.js.map +1 -0
  72. package/dist/core/manifest.d.ts +6 -0
  73. package/dist/core/manifest.d.ts.map +1 -0
  74. package/dist/core/manifest.js +207 -0
  75. package/dist/core/manifest.js.map +1 -0
  76. package/dist/core/yaml.d.ts +11 -0
  77. package/dist/core/yaml.d.ts.map +1 -0
  78. package/dist/core/yaml.js +94 -0
  79. package/dist/core/yaml.js.map +1 -0
  80. package/dist/index.d.ts +3 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +167 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/types.d.ts +351 -0
  85. package/dist/types.d.ts.map +1 -0
  86. package/dist/types.js +4 -0
  87. package/dist/types.js.map +1 -0
  88. package/docs/Voorlopige projekidee.md +695 -0
  89. package/docs/handover-v0.3.md +355 -0
  90. package/docs/handover-v0.4.md +367 -0
  91. package/docs/prd.md +318 -0
  92. package/docs/project-roadmap.md +279 -0
  93. package/docs/release-checklist-v0.5.md +109 -0
  94. package/docs/v0.2 pre-design.md +182 -0
  95. package/docs/v0.2 pre-roadmap.md +270 -0
  96. package/docs/v0.3 pre-design.md +686 -0
  97. package/docs/v0.4 pre-design.md +417 -0
  98. package/docs/v0.5 pre-design.md +481 -0
  99. package/package.json +67 -0
@@ -0,0 +1,695 @@
1
+ # Project Graph Memory Kit
2
+
3
+ 简称可以叫:
4
+
5
+ **PGM / GraphMemo / Agent Project Memory / `.pmem`**
6
+
7
+ 它不是普通 docs,而是一个给任意 Agent 使用的:
8
+
9
+ > **模块化图记忆层 + skills 使用说明 + CLI 快速回忆工具 + 溯源证据系统**
10
+
11
+ 目标是让 Agent 在任何项目里用极少 token 获得三件事:
12
+
13
+ 1. **我在哪个项目里?**
14
+ 2. **当前项目状态是什么?**
15
+ 3. **下一步最应该做什么?为什么?证据在哪?**
16
+
17
+ ---
18
+
19
+ # 一、核心 Super Idea:不要让 Agent 读 docs,让 Agent 读"记忆图索引"
20
+
21
+ 传统方式是:
22
+
23
+ ```txt
24
+ Agent -> 读取 README / docs / changelog / issue / 代码 -> 自己总结
25
+ ```
26
+
27
+ 问题是 token 消耗大,而且每个 Agent 理解不稳定。
28
+
29
+ 你要做的是:
30
+
31
+ ```txt
32
+ Agent -> 读取 .pmem/index.md
33
+ -> 根据任务类型按需读取记忆卡片
34
+ -> CLI 查询相关节点和证据
35
+ -> 回写进度与决策
36
+ ```
37
+
38
+ ---
39
+
40
+ # 二、修订后的目录结构
41
+
42
+ ```txt
43
+ .pmem/
44
+ manifest.yml
45
+
46
+ index.md
47
+ state.md
48
+ next.md
49
+
50
+ modules/
51
+ features/
52
+ decisions/
53
+ tasks/
54
+ traces/
55
+ summaries/
56
+
57
+ skills/
58
+ recall.md
59
+ code-task.md
60
+ architecture-task.md
61
+ update.md
62
+
63
+ indexes/
64
+ graph.json
65
+ bm25.json
66
+
67
+ integrations/
68
+ claude-code/
69
+ CLAUDE.md
70
+ settings.example.json
71
+ cursor/
72
+ rules.example.md
73
+ codex/
74
+ AGENTS.md
75
+
76
+ AGENTS.md
77
+ ```
78
+
79
+ 关键变化:
80
+
81
+ - `graph.json` 移入 `indexes/`:语义更清楚——它是派生数据,不是主数据
82
+ - 新增 `integrations/`:Agent 框架适配模板,与 `skills/` 职责分离
83
+ - `features/` 与 `modules/` 并列:功能模块的记忆粒度更细
84
+
85
+ ---
86
+
87
+ # 三、第一条架构原则:Markdown 记忆卡片是单一真相来源
88
+
89
+ > **`.md` 记忆卡片是 Source of Truth,`graph.json` 是派生索引 / 缓存。**
90
+
91
+ ```txt
92
+ .pmem/**/*.md 主数据
93
+ .pmem/indexes/ 派生缓存
94
+ .pmem/index.md 人类/Agent 入口摘要,可由主数据辅助生成
95
+ ```
96
+
97
+ 禁止手动编辑 graph.json,它随时可以 `rm` 后重建。
98
+
99
+ ## 6 条设计规则
100
+
101
+ ```txt
102
+ Rule 1: Markdown memory cards are the source of truth.
103
+ Rule 2: Graph indexes are generated caches.
104
+ Rule 3: pmem ask must be explainable and graph-guided.
105
+ Rule 4: Agent update must not rely only on instruction; provide hooks and verification.
106
+ Rule 5: Graph storage must be abstracted and migration-ready.
107
+ Rule 6: AGENTS.md is entry instruction; skills are pmem workflows; integrations are framework adapters.
108
+ ```
109
+
110
+ ---
111
+
112
+ # 四、`.pmem/index.md`:Agent 的最小入口
113
+
114
+ 这个文件应该极短,控制在 300 到 800 tokens。
115
+
116
+ ```md
117
+ # Project Memory Index
118
+
119
+ ## Project
120
+ Name: StockBro
121
+ Type: AI trading assistant / backtest sandbox
122
+ Stage: MVP architecture design
123
+
124
+ ## Current Focus
125
+ Build a backtest sandbox that allows agents to test strategies in a simulated trading environment.
126
+
127
+ ## Read First
128
+ - .pmem/state.md
129
+ - .pmem/next.md
130
+ - .pmem/modules/agent_runtime.md
131
+ - .pmem/modules/backtest_sandbox.md
132
+
133
+ ## Stable Decisions
134
+ - Backtest is designed as agent virtual practice environment.
135
+ - Agent should not directly mutate core trading state.
136
+ - Data source layer must be abstracted.
137
+
138
+ ## Current Risks
139
+ - Product value may become too technical.
140
+ - Backtest system may become over-engineered before MVP.
141
+
142
+ ## CLI
143
+ Use:
144
+ pmem recall
145
+ pmem next
146
+ pmem trace backtest_sandbox
147
+ pmem ask "how does the agent use sandbox?"
148
+ ```
149
+
150
+ ---
151
+
152
+ # 五、记忆卡片格式
153
+
154
+ 每个记忆卡片是结构化 Markdown,以 frontmatter 存储机器可读 metadata。
155
+
156
+ ```md
157
+ ---
158
+ id: module.backtest_sandbox
159
+ type: module
160
+ status: designing
161
+ priority: high
162
+ tags:
163
+ - backtest
164
+ - agent
165
+ - sandbox
166
+ aliases:
167
+ - 回测沙盒
168
+ - virtual practice environment
169
+ related:
170
+ - module.agent_runtime
171
+ - decision.agent_tool_boundary
172
+ depends_on:
173
+ - module.market_data
174
+ updated: 2026-05-20
175
+ last_verified: 2026-05-20
176
+ freshness:
177
+ ttl: 14d
178
+ policy: verify_on_related_code_change
179
+ source_files:
180
+ - src/backtest/sandbox.ts
181
+ ---
182
+
183
+ # Backtest Sandbox
184
+
185
+ ## One-liner
186
+ A simulated trading environment for agents to test trading strategies safely.
187
+
188
+ ## Responsibilities
189
+ - Load historical market data.
190
+ - Run strategy simulation.
191
+ - Record agent actions.
192
+ - Produce evaluation metrics.
193
+
194
+ ## Non-goals
195
+ - Real-money trading.
196
+ - Broker integration.
197
+ - High-frequency execution.
198
+
199
+ ## Current State
200
+ Architecture not finalized.
201
+
202
+ ## Next Step
203
+ Design minimal sandbox API:
204
+ - reset()
205
+ - step(action)
206
+ - evaluate()
207
+ - export_report()
208
+
209
+ ## Evidence
210
+ - User discussed making backtest a virtual practice sandbox for agents.
211
+ - Related code: `src/backtest/`
212
+ ```
213
+
214
+ 关键字段:
215
+
216
+ - `aliases`:中文/英文/术语切换时的命中关键
217
+ - `freshness`:过时检测的 TTL 和触发策略
218
+ - `source_files`:关联的代码文件,变更时自动标记记忆可能过期
219
+ - `last_verified`:最后一次人工/Agent 确认此记忆仍然准确的时间
220
+
221
+ ---
222
+
223
+ # 六、图索引结构:Node + Edge + Evidence
224
+
225
+ ```json
226
+ {
227
+ "kind": "pmem.graph_index",
228
+ "pmem_version": "0.1.0",
229
+ "generated_at": "2026-05-20T12:00:00Z",
230
+ "source": {
231
+ "type": "markdown_frontmatter",
232
+ "glob": ".pmem/**/*.md",
233
+ "source_hash": "sha256:xxxx"
234
+ },
235
+ "node_count": 128,
236
+ "edge_count": 392,
237
+ "nodes": [
238
+ {
239
+ "id": "module.backtest_sandbox",
240
+ "type": "module",
241
+ "title": "Backtest Sandbox",
242
+ "status": "designing",
243
+ "file": ".pmem/modules/backtest_sandbox.md",
244
+ "tags": ["backtest", "agent", "sandbox"]
245
+ }
246
+ ],
247
+ "edges": [
248
+ {
249
+ "from": "module.backtest_sandbox",
250
+ "to": "module.agent_runtime",
251
+ "type": "related"
252
+ },
253
+ {
254
+ "from": "module.backtest_sandbox",
255
+ "to": "module.market_data",
256
+ "type": "depends_on"
257
+ }
258
+ ]
259
+ }
260
+ ```
261
+
262
+ 边分为三类:
263
+
264
+ 1. **显式边**:来自 frontmatter 的 `depends_on`、`related` 等字段(人工确认的高质量边)
265
+ 2. **推导边**:从字段自动推导,如 `type: task + module: module.X → belongs_to → module.X`
266
+ 3. **弱关联边**:由 tags / mentions 推导,标记 confidence(v0.2+)
267
+
268
+ 节点类型:`project | module | feature | task | decision | risk | assumption | constraint | person | resource | file | doc | trace`
269
+
270
+ 边类型:`depends_on | blocks | implements | constrains | decided_by | derived_from | related_to | supersedes | conflicts_with | next_step_of`
271
+
272
+ ---
273
+
274
+ # 七、`pmem ask`:可解释的图引导召回
275
+
276
+ `pmem ask` 不伪装成 AI 问答。它是**多阶段可解释召回器**。
277
+
278
+ ## 流程
279
+
280
+ ```txt
281
+ Input Query
282
+
283
+ Normalize query
284
+
285
+ Step 1: Exact match (id / title / alias / tag)
286
+
287
+ Step 2: Graph expansion (depends_on / constrained_by / implements / related / next_step_of)
288
+
289
+ Step 3: Keyword fallback (title / summary / headings / BM25)
290
+
291
+ Rank by: match type → graph distance → priority → status → updated_at
292
+
293
+ Return: summary + matched nodes + expanded nodes + recommended files + evidence paths
294
+ ```
295
+
296
+ ## 输出示例
297
+
298
+ ```txt
299
+ Query: 节点 CRUD 下一步怎么做?
300
+
301
+ Matched:
302
+ - feature.node_crud by alias: "节点 CRUD"
303
+
304
+ Expanded:
305
+ - module.persistence via depends_on
306
+ - decision.sqlite_for_v04 via constrained_by
307
+ - task.implement_node_repository via next_step_of
308
+
309
+ Recommended Read:
310
+ 1. .pmem/features/node_crud.md
311
+ 2. .pmem/modules/persistence.md
312
+ 3. .pmem/decisions/2026-05-20-sqlite-for-v04.md
313
+ 4. .pmem/tasks/implement_node_repository.md
314
+ ```
315
+
316
+ 每条结果标注匹配路径("Matched by alias" / "Expanded by depends_on" / "Fallback by keyword"),让 Agent 能判断召回质量。
317
+
318
+ ---
319
+
320
+ # 八、记忆更新的四级模式
321
+
322
+ 记忆更新不是全有或全无。分成四个层级:
323
+
324
+ ### 1. `pmem mark-dirty`
325
+
326
+ 只标记状态可能过期,不写 trace。
327
+
328
+ ```bash
329
+ pmem mark-dirty --reason code_changed
330
+ ```
331
+
332
+ ### 2. `pmem update --auto`
333
+
334
+ 自动检测变化,生成候选项但不直接写入。
335
+
336
+ ```bash
337
+ pmem update --auto
338
+ ```
339
+
340
+ ### 3. `pmem update --confirm`
341
+
342
+ 经确认后写入 state.md / next.md / traces / module cards / indexes。
343
+
344
+ ### 4. `pmem update --force`
345
+
346
+ 明确强制写入(适合高级 Agent 或人类)。
347
+
348
+ ---
349
+
350
+ ## trace 写入标准
351
+
352
+ 只有满足以下任一条件才写 trace:
353
+
354
+ ```txt
355
+ 产生新决策
356
+ 完成一个任务
357
+ 改变模块边界
358
+ 发现重要风险
359
+ 验证或推翻一个假设
360
+ 实现了影响后续开发的接口
361
+ 修复了关键 bug
362
+ 用户明确要求记录
363
+ ```
364
+
365
+ 不应该写 trace:简单重命名、格式化、无结论探索、临时 debug、失败的短尝试、微小重复修改。
366
+
367
+ ---
368
+
369
+ # 九、`pmem verify`:一致性检查
370
+
371
+ `verify` 检查 index 是否与主数据一致。任何不一致,修复方式永远是 `pmem rebuild`,不是手改 index。
372
+
373
+ ```txt
374
+ Memory Verify Result: Failed
375
+
376
+ Issue:
377
+ - indexes/graph.json is stale.
378
+ - Source cards changed after the graph index was generated.
379
+
380
+ Do not edit the index manually.
381
+
382
+ Fix:
383
+ pmem rebuild
384
+ ```
385
+
386
+ `--fix` 标志自动执行 rebuild + verify。
387
+
388
+ ---
389
+
390
+ # 十、记忆新鲜度与过时检测
391
+
392
+ 每张卡片携带 freshness metadata,`verify` 检查相关代码变更后是否应更新记忆:
393
+
394
+ ```txt
395
+ Potential stale memory:
396
+ - module.backtest_sandbox.md
397
+ Reason: source file src/backtest/sandbox.ts changed after last_verified.
398
+ Fix:
399
+ pmem update module.backtest_sandbox
400
+ ```
401
+
402
+ ---
403
+
404
+ # 十一、`pmem distill`:从流水到沉淀(v0.2)
405
+
406
+ `distill` 是 pmem 长期不衰减的关键机制。它做 4 件事:
407
+
408
+ ```txt
409
+ 1. 从 traces 中抽取稳定事实
410
+ 2. 更新 module / decision / task 卡片
411
+ 3. 压缩或归档旧 trace
412
+ 4. 标记过时记忆
413
+ ```
414
+
415
+ trace frontmatter 携带 `distilled: false` 标记,蒸馏后改为 `distilled: true` 并记录蒸馏目标。
416
+
417
+ ---
418
+
419
+ # 十二、`AGENTS.md`、`skills/`、`integrations/` 的层级关系
420
+
421
+ ```txt
422
+ Agent 框架入口文件
423
+
424
+ AGENTS.md / CLAUDE.md / Cursor Rules
425
+
426
+ 告诉 Agent 使用 pmem
427
+
428
+ pmem recall / pmem ask
429
+
430
+ 按需读取 .pmem/skills/
431
+
432
+ 按需读取 .pmem/modules / decisions / tasks
433
+ ```
434
+
435
+ - **`AGENTS.md`**:顶层入口,告诉 Agent "本项目使用 pmem,启动时先跑 pmem recall"
436
+ - **`.pmem/skills/`**:pmem 内部任务流程说明(recall、code-task、architecture-task、update)
437
+ - **`.pmem/integrations/`**:各 Agent 框架的适配模板(Claude Code、Cursor、Codex 等)
438
+
439
+ ---
440
+
441
+ # 十三、修订后的 `manifest.yml`
442
+
443
+ ```yml
444
+ version: 0.2
445
+ pmem_version: "0.1.0"
446
+
447
+ project:
448
+ name: StockBro
449
+ language: zh-CN
450
+
451
+ source_of_truth:
452
+ type: markdown_cards
453
+ path: ".pmem"
454
+ card_globs:
455
+ - ".pmem/modules/**/*.md"
456
+ - ".pmem/features/**/*.md"
457
+ - ".pmem/decisions/**/*.md"
458
+ - ".pmem/tasks/**/*.md"
459
+ - ".pmem/traces/**/*.md"
460
+
461
+ indexes:
462
+ path: ".pmem/indexes"
463
+ generated: true
464
+ graph:
465
+ mode: single
466
+ path: ".pmem/indexes/graph.json"
467
+ keyword:
468
+ mode: bm25
469
+ path: ".pmem/indexes/bm25.json"
470
+
471
+ auto_update:
472
+ enabled: true
473
+ on_code_change: mark_dirty
474
+ on_doc_change: mark_dirty
475
+ on_memory_change: rebuild_indexes
476
+ on_session_end: prompt
477
+ on_git_commit: suggest_trace
478
+ min_trace_interval: 30m
479
+ max_auto_traces_per_day: 5
480
+ ignore_patterns:
481
+ - "node_modules/**"
482
+ - "dist/**"
483
+ - "build/**"
484
+ - "*.lock"
485
+ - "*.log"
486
+ trace_policy:
487
+ require_meaningful_change: true
488
+ require_summary: true
489
+ require_related_node: true
490
+
491
+ distill:
492
+ enabled: true
493
+ cadence: weekly
494
+ max_undistilled_traces: 20
495
+ group_by:
496
+ - related
497
+ - module
498
+ - task
499
+ output:
500
+ update_cards: true
501
+ update_summaries: true
502
+ archive_traces: false
503
+ require_confirmation: true
504
+
505
+ freshness:
506
+ default_ttl: 14d
507
+ stale_on_related_code_change: true
508
+ require_last_verified: true
509
+
510
+ integrations:
511
+ active:
512
+ - claude-code
513
+
514
+ claude-code:
515
+ template_version: "0.2"
516
+ files:
517
+ - "CLAUDE.md"
518
+ - ".claude/settings.json"
519
+ hooks:
520
+ on_edit: "pmem mark-dirty --reason code_changed"
521
+ on_stop: "pmem update --auto --mode=suggest"
522
+
523
+ concurrency:
524
+ lock: file
525
+ lock_path: ".pmem/.lock"
526
+ timeout: 5s
527
+ ```
528
+
529
+ ---
530
+
531
+ # 十四、三层记忆压缩
532
+
533
+ ## 第一层:Hot Memory
534
+
535
+ Agent 每次都读,极短。
536
+
537
+ ```txt
538
+ .pmem/index.md
539
+ .pmem/state.md
540
+ .pmem/next.md
541
+ ```
542
+
543
+ 控制在 1000 到 2000 tokens。
544
+
545
+ ## 第二层:Warm Memory
546
+
547
+ 按需读取。
548
+
549
+ ```txt
550
+ .pmem/modules/*.md
551
+ .pmem/decisions/*.md
552
+ .pmem/tasks/*.md
553
+ ```
554
+
555
+ 只有相关时才读。
556
+
557
+ ## 第三层:Cold Memory
558
+
559
+ 只做溯源,不默认读取。
560
+
561
+ ```txt
562
+ .pmem/traces/*.md
563
+ .pmem/archive/*.md
564
+ .pmem/summaries/*.md
565
+ ```
566
+
567
+ 除非 Agent 需要查"为什么",否则不读。
568
+
569
+ ---
570
+
571
+ ## Token Budget Aware Recall
572
+
573
+ ```bash
574
+ pmem recall --budget 800
575
+ pmem recall --budget 2000
576
+ pmem recall --budget 5000
577
+ ```
578
+
579
+ 不同预算输出不同层级的内容。
580
+
581
+ ---
582
+
583
+ # 十五、核心命令体系
584
+
585
+ ```bash
586
+ pmem init # 初始化项目记忆
587
+ pmem recall # 快速回忆项目
588
+ pmem next # 只看下一步
589
+ pmem ask # 图引导召回
590
+ pmem related # 图谱邻居查询
591
+ pmem trace # 溯源
592
+ pmem update # 更新记忆(分级:mark-dirty / auto / confirm / force)
593
+ pmem mark-dirty # 标记状态可能过期
594
+ pmem rebuild # 从主数据重建所有索引
595
+ pmem verify # 一致性/新鲜度/集成检查
596
+ pmem distill # 长期记忆蒸馏(v0.2)
597
+ pmem integration # Agent 框架适配管理
598
+ ```
599
+
600
+ ---
601
+
602
+ # 十六、数据流总结
603
+
604
+ ```txt
605
+ 写入:
606
+ 用户 / Agent 修改项目
607
+
608
+ pmem mark-dirty(检测变化)
609
+
610
+ pmem update --confirm(确认后写入 .md 记忆卡)
611
+
612
+ pmem rebuild(解析 frontmatter,重建 indexes)
613
+
614
+ pmem verify(检查一致性)
615
+
616
+ 读取:
617
+ pmem recall / ask / related(使用 indexes)
618
+
619
+ 返回最小上下文包
620
+ ```
621
+
622
+ 一句话:
623
+
624
+ > **写入走 Markdown,读取走 Index。**
625
+
626
+ ---
627
+
628
+ # 十七、开发路线
629
+
630
+ ## v0.1:可用
631
+
632
+ ```txt
633
+ pmem init
634
+ pmem recall
635
+ pmem ask(精确匹配 + 图邻居 + BM25 兜底)
636
+ pmem related
637
+ pmem trace
638
+ pmem update(mark-dirty / auto / confirm / force)
639
+ pmem rebuild
640
+ pmem verify
641
+ pmem integration(list / install / verify)
642
+ ```
643
+
644
+ 技术栈:Node.js / TypeScript,文件系统 + frontmatter + JSON graph。
645
+
646
+ ## v0.2:可持续
647
+
648
+ ```txt
649
+ pmem distill(trace → card 蒸馏)
650
+ stale memory detection
651
+ trace 噪音控制
652
+ token-budget recall
653
+ graph 分片存储
654
+ integration hooks
655
+ ```
656
+
657
+ ## v0.3:更智能
658
+
659
+ ```txt
660
+ embeddings / semantic search
661
+ sqlite graph index
662
+ incremental rebuild
663
+ memory quality scoring
664
+ pmem serve(HTTP API / MCP Server)
665
+ ```
666
+
667
+ ---
668
+
669
+ # 十八、核心定位
670
+
671
+ > **面向 AI Agent 的图结构项目记忆运行时。**
672
+
673
+ 不是智能文档系统,不是知识库,而是:
674
+
675
+ > **低 token、可溯源、可恢复状态的 Agent 项目记忆协议。**
676
+
677
+ 它的核心交互不是"读文档",而是:
678
+
679
+ ```txt
680
+ 恢复状态 -> 查找相关记忆 -> 溯源依据 -> 规划下一步 -> 回写记忆
681
+ ```
682
+
683
+ ---
684
+
685
+ # 十九、解决问题的清单
686
+
687
+ ```txt
688
+ Agent 经常忘记项目背景 → pmem recall
689
+ Agent 每次都重复理解代码 → 按需读取 warm memory
690
+ Agent 容易推翻之前决策 → decisions/ + trace 溯源
691
+ Agent 不知道下一步做什么 → pmem next
692
+ Agent 读取上下文 token 消耗大 → token-budget recall + 三层记忆
693
+ 项目长期演进缺少可溯源记忆 → traces + distill
694
+ 记忆过时无人发现 → freshness detection + pmem verify
695
+ ```