agent-recall-core 3.3.27 → 3.4.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 (80) hide show
  1. package/README.md +1014 -206
  2. package/dist/digest/store.d.ts.map +1 -1
  3. package/dist/digest/store.js +9 -2
  4. package/dist/digest/store.js.map +1 -1
  5. package/dist/helpers/alignment-patterns.d.ts +8 -0
  6. package/dist/helpers/alignment-patterns.d.ts.map +1 -1
  7. package/dist/helpers/alignment-patterns.js +76 -0
  8. package/dist/helpers/alignment-patterns.js.map +1 -1
  9. package/dist/index.d.ts +11 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +14 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/palace/awareness.d.ts +3 -2
  14. package/dist/palace/awareness.d.ts.map +1 -1
  15. package/dist/palace/awareness.js +16 -10
  16. package/dist/palace/awareness.js.map +1 -1
  17. package/dist/palace/insights-index.d.ts.map +1 -1
  18. package/dist/palace/insights-index.js +28 -0
  19. package/dist/palace/insights-index.js.map +1 -1
  20. package/dist/palace/rooms.d.ts +1 -1
  21. package/dist/palace/rooms.d.ts.map +1 -1
  22. package/dist/palace/rooms.js +28 -3
  23. package/dist/palace/rooms.js.map +1 -1
  24. package/dist/supabase/client.d.ts +9 -0
  25. package/dist/supabase/client.d.ts.map +1 -0
  26. package/dist/supabase/client.js +22 -0
  27. package/dist/supabase/client.js.map +1 -0
  28. package/dist/supabase/config.d.ts +10 -0
  29. package/dist/supabase/config.d.ts.map +1 -0
  30. package/dist/supabase/config.js +45 -0
  31. package/dist/supabase/config.js.map +1 -0
  32. package/dist/supabase/embedding.d.ts +25 -0
  33. package/dist/supabase/embedding.d.ts.map +1 -0
  34. package/dist/supabase/embedding.js +76 -0
  35. package/dist/supabase/embedding.js.map +1 -0
  36. package/dist/supabase/recall-backend.d.ts +21 -0
  37. package/dist/supabase/recall-backend.d.ts.map +1 -0
  38. package/dist/supabase/recall-backend.js +128 -0
  39. package/dist/supabase/recall-backend.js.map +1 -0
  40. package/dist/supabase/sync.d.ts +21 -0
  41. package/dist/supabase/sync.d.ts.map +1 -0
  42. package/dist/supabase/sync.js +158 -0
  43. package/dist/supabase/sync.js.map +1 -0
  44. package/dist/tools-logic/bootstrap.d.ts +63 -0
  45. package/dist/tools-logic/bootstrap.d.ts.map +1 -0
  46. package/dist/tools-logic/bootstrap.js +650 -0
  47. package/dist/tools-logic/bootstrap.js.map +1 -0
  48. package/dist/tools-logic/check.d.ts +13 -0
  49. package/dist/tools-logic/check.d.ts.map +1 -1
  50. package/dist/tools-logic/check.js +55 -1
  51. package/dist/tools-logic/check.js.map +1 -1
  52. package/dist/tools-logic/journal-write.d.ts.map +1 -1
  53. package/dist/tools-logic/journal-write.js +3 -0
  54. package/dist/tools-logic/journal-write.js.map +1 -1
  55. package/dist/tools-logic/palace-search.d.ts.map +1 -1
  56. package/dist/tools-logic/palace-search.js +3 -0
  57. package/dist/tools-logic/palace-search.js.map +1 -1
  58. package/dist/tools-logic/palace-write.d.ts.map +1 -1
  59. package/dist/tools-logic/palace-write.js +4 -0
  60. package/dist/tools-logic/palace-write.js.map +1 -1
  61. package/dist/tools-logic/recall-backend.d.ts +29 -0
  62. package/dist/tools-logic/recall-backend.d.ts.map +1 -0
  63. package/dist/tools-logic/recall-backend.js +58 -0
  64. package/dist/tools-logic/recall-backend.js.map +1 -0
  65. package/dist/tools-logic/session-end.d.ts.map +1 -1
  66. package/dist/tools-logic/session-end.js +4 -1
  67. package/dist/tools-logic/session-end.js.map +1 -1
  68. package/dist/tools-logic/session-start.d.ts +1 -0
  69. package/dist/tools-logic/session-start.d.ts.map +1 -1
  70. package/dist/tools-logic/session-start.js +67 -4
  71. package/dist/tools-logic/session-start.js.map +1 -1
  72. package/dist/tools-logic/smart-recall.d.ts +10 -0
  73. package/dist/tools-logic/smart-recall.d.ts.map +1 -1
  74. package/dist/tools-logic/smart-recall.js +56 -32
  75. package/dist/tools-logic/smart-recall.js.map +1 -1
  76. package/dist/types.d.ts +6 -1
  77. package/dist/types.d.ts.map +1 -1
  78. package/dist/types.js +2 -1
  79. package/dist/types.js.map +1 -1
  80. package/package.json +6 -4
package/README.md CHANGED
@@ -1,336 +1,1144 @@
1
- <h1 align="center">AgentRecall — Core</h1>
1
+ <h1 align="center">AgentRecall</h1>
2
2
 
3
3
  <p align="center"><strong>Your agent doesn't just remember. It learns how you think.</strong></p>
4
- <p align="center">Core engine for AgentRecall. Use this package if you're building with the SDK calling functions directly from LangChain, CrewAI, Vercel AI SDK, or your own agent framework.</p>
4
+ <p align="center">Every correction saved is a mistake never repeated. Every insight compounded is tokens never wasted rebuilding context.</p>
5
+ <p align="center">Persistent, compounding memory + automatic correction capture. MCP server + SDK + CLI.</p>
5
6
 
6
7
  <p align="center">
7
- <a href="https://www.npmjs.com/package/agent-recall-core"><img src="https://img.shields.io/npm/v/agent-recall-core?style=flat-square&label=core&color=5D34F2" alt="core npm"></a>
8
+ <a href="https://www.npmjs.com/package/agent-recall-mcp"><img src="https://img.shields.io/npm/v/agent-recall-mcp?style=flat-square&label=MCP&color=5D34F2" alt="MCP npm"></a>
9
+ <a href="https://www.npmjs.com/package/agent-recall-sdk"><img src="https://img.shields.io/npm/v/agent-recall-sdk?style=flat-square&label=SDK&color=0EA5E9" alt="SDK npm"></a>
10
+ <a href="https://www.npmjs.com/package/agent-recall-cli"><img src="https://img.shields.io/npm/v/agent-recall-cli?style=flat-square&label=CLI&color=10B981" alt="CLI npm"></a>
8
11
  <a href="https://github.com/Goldentrii/AgentRecall/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen?style=flat-square" alt="License"></a>
12
+ <a href="https://lobehub.com/mcp/goldentrii-agentrecall"><img src="https://lobehub.com/badge/mcp/goldentrii-agentrecall" alt="MCP Badge"></a>
13
+ <img src="https://img.shields.io/badge/MCP-10_tools-orange?style=flat-square" alt="Tools">
9
14
  <img src="https://img.shields.io/badge/cloud-zero-blue?style=flat-square" alt="Zero Cloud">
15
+ <img src="https://img.shields.io/badge/Obsidian-compatible-7C3AED?style=flat-square" alt="Obsidian">
16
+ <img src="https://img.shields.io/badge/digest_cache-83%25_token_savings-FF6B6B?style=flat-square" alt="Digest cache savings">
17
+ <img src="https://img.shields.io/badge/saves_up_to-57%25_tokens-FF6B6B?style=flat-square" alt="Token savings">
18
+ <img src="https://img.shields.io/badge/break--even-3--4_sessions-22C55E?style=flat-square" alt="Break-even">
10
19
  <img src="https://img.shields.io/badge/scoring-RRF_(Cormack_2009)-7C3AED?style=flat-square" alt="RRF scoring">
11
20
  <img src="https://img.shields.io/badge/decay-Ebbinghaus%2BZipf-3B82F6?style=flat-square" alt="Ebbinghaus+Zipf decay">
12
- <img src="https://img.shields.io/badge/feedback-Bayesian_Beta_(designed)-F59E0B?style=flat-square" alt="Beta distribution">
21
+ <img src="https://img.shields.io/badge/feedback-Bayesian_Beta_(active)-F59E0B?style=flat-square" alt="Beta distribution">
22
+ <img src="https://img.shields.io/badge/semantic_recall-pgvector_%2B_RRF-8B5CF6?style=flat-square" alt="Semantic recall">
13
23
  </p>
14
24
 
15
25
  <p align="center">
16
- <a href="#install"><b>Install</b></a> ·
17
- <a href="#sdk-api-reference"><b>SDK API</b></a> ·
18
- <a href="#example-session-lifecycle"><b>Example</b></a> ·
19
- <a href="#scoring-architecture"><b>Scoring</b></a> ·
20
- <a href="#storage-layout"><b>Storage</b></a>
26
+ <b>EN:</b>&nbsp;
27
+ <a href="#why-choose-agentrecall">Why</a> ·
28
+ <a href="#three-ways-to-use-it">Use</a> ·
29
+ <a href="#quick-start">Install</a> ·
30
+ <a href="#semantic-recall--pgvector-backend-v340">Semantic Recall</a> ·
31
+ <a href="#10-mcp-tools">Tools</a> ·
32
+ <a href="#how-memory-compounds">Compounding</a> ·
33
+ <a href="#sdk-api">SDK</a> ·
34
+ <a href="#architecture">Architecture</a> ·
35
+ <a href="#docs">Docs</a>
21
36
  &nbsp;&nbsp;|&nbsp;&nbsp;
22
- <a href="#agent-recall-core中文文档">中文</a>
37
+ <b>中文:</b>&nbsp;
38
+ <a href="#agentrecall中文文档">简介</a> ·
39
+ <a href="#快速开始">安装</a> ·
40
+ <a href="#语义召回--pgvector-v340">语义召回</a> ·
41
+ <a href="#10-个-mcp-工具">工具</a> ·
42
+ <a href="#记忆如何复合增长">复合</a> ·
43
+ <a href="#架构">架构</a>
23
44
  </p>
24
45
 
25
- > **Not building an app?** If you want to add memory to Claude Code, Cursor, or any MCP-compatible agent, use [`agent-recall-mcp`](../mcp-server/README.md) instead.
26
-
27
46
  ---
28
47
 
29
- ## Install
48
+ <p align="center">
49
+ <a href="#arstatus-arsave-arstart-arsaveall-and-arbootstrap"><img src="https://img.shields.io/badge/%2Farstatus-START_HERE-22C55E?style=for-the-badge" alt="/arstatus"></a>
50
+ <a href="#arstatus-arsave-arstart-arsaveall-and-arbootstrap"><img src="https://img.shields.io/badge/%2Farstart-Load_Context-4ECDC4?style=for-the-badge" alt="/arstart"></a>
51
+ <a href="#arstatus-arsave-arstart-arsaveall-and-arbootstrap"><img src="https://img.shields.io/badge/%2Farsave-Save_Session-FF6B6B?style=for-the-badge" alt="/arsave"></a>
52
+ <a href="#arstatus-arsave-arstart-arsaveall-and-arbootstrap"><img src="https://img.shields.io/badge/%2Farsaveall-Batch_Save_All-FFD93D?style=for-the-badge" alt="/arsaveall"></a>
53
+ <a href="#already-using-another-memory-system-arbootstrap"><img src="https://img.shields.io/badge/%2Farbootstrap-Transfer_Memory-8B5CF6?style=for-the-badge" alt="/arbootstrap"></a>
54
+ </p>
55
+ <p align="center">
56
+ <img src="https://img.shields.io/badge/AUTO-hook--start-8B5CF6?style=for-the-badge" alt="hook-start">
57
+ <img src="https://img.shields.io/badge/AUTO-hook--correction-F97316?style=for-the-badge" alt="hook-correction">
58
+ <img src="https://img.shields.io/badge/AUTO-hook--end-06B6D4?style=for-the-badge" alt="hook-end">
59
+ </p>
60
+ <p align="center">
61
+ <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/1-AUTO--NAMING-5D34F2?style=for-the-badge" alt="Auto-Naming"></a>
62
+ <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/2-INDEXES-0EA5E9?style=for-the-badge" alt="Indexes"></a>
63
+ <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/3-RELATIVITY-10B981?style=for-the-badge" alt="Relativity"></a>
64
+ <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/4-WEIGHT_%2B_DECAY-F59E0B?style=for-the-badge" alt="Weight + Decay"></a>
65
+ <a href="#how-memory-compounds"><img src="https://img.shields.io/badge/5-FEEDBACK_LOOP-EF4444?style=for-the-badge" alt="Feedback Loop"></a>
66
+ </p>
67
+
68
+ ## Already Using Another Memory System? `/arbootstrap`
69
+
70
+ > [!NOTE]
71
+ > **You don't start from zero.** If you've been using Claude's built-in memory, Mem0, or just working in git repos — AgentRecall can discover and import your existing context automatically.
72
+
73
+ Most users installing AgentRecall aren't starting fresh. They already have:
74
+ - **Git repos** with months of commit history and project structure
75
+ - **Claude AutoMemory** (`~/.claude/projects/`) with user profiles, feedback, and project memories
76
+ - **CLAUDE.md files** with project conventions and architecture decisions
77
+
78
+ **`/arbootstrap`** scans your machine and imports everything in one shot:
79
+
80
+ ```
81
+ /arbootstrap
82
+
83
+ ──────────────────────────────────────────────────────────────
84
+ AgentRecall Bootstrap Scan 2026-04-26
85
+ ──────────────────────────────────────────────────────────────
86
+
87
+ Found on your machine:
88
+ 24 git repos
89
+ 92 Claude memory files
90
+ 3 CLAUDE.md files
91
+
92
+ Projects:
93
+ 18 new (not yet in AgentRecall)
94
+ 10 already imported
95
+
96
+ Scan time: 141ms
97
+ ──────────────────────────────────────────────────────────────
98
+ ```
99
+
100
+ **What gets imported per project:**
101
+ - **Identity** — project name, language, description → `palace/identity.md`
102
+ - **Architecture** — CLAUDE.md conventions → `palace/rooms/architecture/`
103
+ - **Memory** — Claude AutoMemory files → `palace/rooms/knowledge/`
104
+ - **Trajectory** — recent git history → initial journal entry
30
105
 
106
+ **Safety guarantees:**
107
+ - Scan is read-only — never writes to your machine
108
+ - Import only writes to `~/.agent-recall/` — never modifies source files
109
+ - Skips `.env`, credentials, `.pem`, `.key` — never reads secrets
110
+ - Projects already in AgentRecall are skipped (no double-import)
111
+
112
+ **For MCP-only environments** (Codex, Cursor, VS Code Copilot):
113
+ ```
114
+ bootstrap_scan() # discover what's on the machine
115
+ bootstrap_import({ scan_result }) # import selected projects
116
+ ```
117
+
118
+ **For CLI:**
31
119
  ```bash
32
- npm install agent-recall-core
120
+ ar bootstrap # scan and show results
121
+ ar bootstrap --dry-run # preview what would be imported
122
+ ar bootstrap --import # import all new projects
123
+ ar bootstrap --import --project X # import one project
33
124
  ```
34
125
 
35
- This package is the shared business logic layer used by `agent-recall-mcp`, `agent-recall-sdk`, and `agent-recall-cli`. Import it directly when you want low-level access to palace operations, scoring, awareness, and corrections.
126
+ After bootstrap, run `/arstatus` your projects are ready.
36
127
 
37
128
  ---
38
129
 
39
- ## SDK API Reference
130
+ ## `/arstatus`, `/arsave`, `/arstart`, `/arsaveall`, and `/arbootstrap`
131
+
132
+ > [!TIP]
133
+ > **New to AgentRecall?** Read the **[→ Command Reference](docs/commands.md)** — full instructions, all example outputs, installation, and troubleshooting in one place.
134
+
135
+ > [!IMPORTANT]
136
+ > **Run `/arstatus` at the start of every session.** It shows all your projects, what's pending, what's blocked, and lets you pick what to work on — by number, not by remembering project names. Without it, a fresh agent has no idea where to begin.
137
+
138
+ | Command | When | What it does |
139
+ |---------|------|-------------|
140
+ | ⭐ **`/arstatus`** | **Every session — run this first** | **Status board across ALL projects: pending work, blockers, numbered pick list. The true cold start.** |
141
+ | **`/arstart`** | After picking a project | Load deep context for one project: palace rooms, corrections, task-specific recall |
142
+ | **`/arsave`** | End of session | Write journal + consolidate to palace + update awareness |
143
+ | **`/arsaveall`** | End of day (multi-session) | **Batch save all parallel sessions at once** — scan, merge, deduplicate, done |
144
+ | **`/arbootstrap`** | **First install / switching from another memory system** | **Scan your machine for existing projects and import them into AgentRecall in seconds** |
145
+
146
+ **The session flow:** `/arstatus` → pick a number → `/arstart <project>` → work → `/arsave`.
147
+
148
+ **Running 5 agents in parallel?** Don't `/arsave` five times. Type **`/arsaveall`** once — it scans all of today's sessions across all projects, merges them into consolidated journals, deduplicates insights, and updates awareness in one shot. Each session writes to its own file (session-ID scoped), so **no conflicts, no data loss, no matter how many windows you have open.**
149
+
150
+ ### What You'll See
151
+
152
+ Type `/arstatus` → see everything in flight across all projects, pick by number:
153
+
154
+ ```
155
+ ──────────────────────────────────────────────────────────────
156
+ AgentRecall Status Board 2026-04-21 5 projects
157
+ ──────────────────────────────────────────────────────────────
158
+
159
+ 1 ⚠ novada-site 2026-04-21 BLOCKED
160
+ Blocked: .env.local missing — Phase 1 cannot proceed
161
+
162
+ 2 ● novada-mcp 2026-04-21
163
+ Next: fix novada_search POST /request → publish v0.8.0
164
+
165
+ 3 ● prismma-scraper 2026-04-17
166
+ Next: UI upgrade Option A — light mode + 3D visuals
167
+
168
+ 4 ✓ AgentRecall 2026-04-21 complete
169
+ Collecting real production data
170
+
171
+ ──────────────────────────────────────────────────────────────
172
+ Enter a number, or:
173
+ N New project (with memory — agent knows your full history)
174
+ X New project (clean slate — no prior context, pure objectivity)
175
+ ──────────────────────────────────────────────────────────────
176
+ ```
177
+
178
+ Type `/arsave` → the system saves everything and renders a card with exact file paths and counts:
179
+
180
+ ```
181
+ ──────────────────────────────────────────────────────────────
182
+ AgentRecall ✓ Saved my-project 2026-04-20 #12
183
+ ──────────────────────────────────────────────────────────────
184
+
185
+ Journal ~/.agent-recall/projects/my-project/journal/
186
+ └─ 2026-04-20--arsave--15L--review-feedback.md [written]
187
+
188
+ Awareness 2 insights added (8 total)
189
+
190
+ Palace ~/.agent-recall/projects/my-project/palace/
191
+ ├─ rooms/Architecture [updated]
192
+ └─ rooms/Goals [updated]
193
+
194
+ Corrections 3 stored (always loaded at session start)
195
+
196
+ ⚡ Similar entries found — consider merging:
197
+ 2026-04-19 (review, feedback, architecture)
198
+
199
+ ──────────────────────────────────────────────────────────────
200
+ ```
201
+
202
+ Type `/arstart` → loads all context from memory in one shot:
203
+
204
+ ```
205
+ ──────────────────────────────────────────────────────────────
206
+ AgentRecall ↻ Loaded my-project 2026-04-21
207
+ ──────────────────────────────────────────────────────────────
208
+
209
+ Project my-project — SaaS platform for AI agents
210
+ Last session 2026-04-20 — review + feedback loop shipped
211
+
212
+ Insights (top 3):
213
+ [5×] Server-rendered cards beat agent templates
214
+ [3×] Per-message dedup beats per-session dedup
215
+ [2×] Stemming + synonyms improve keyword recall
216
+
217
+ ⚠ Past corrections — watch out:
218
+ - "No dark backgrounds" (corrected 3×)
219
+ - "Use bb-browser, not Playwright" (corrected 2×)
220
+
221
+ Cross-project: 2 related insights from novada-mcp
222
+
223
+ ──────────────────────────────────────────────────────────────
224
+ ```
225
+
226
+ Type `/arsaveall` → batch-saves all parallel sessions at once:
227
+
228
+ ```
229
+ ──────────────────────────────────────────────────────────────
230
+ AgentRecall ✓ Batch Saved 2026-04-20
231
+ ──────────────────────────────────────────────────────────────
232
+
233
+ Sessions scanned 5
234
+ Projects saved my-project, novada-mcp, prismma-scraper
235
+ Insights merged 4 (deduplicated from 7)
236
+ Corrections 2 new (auto-captured via hooks)
237
+
238
+ ──────────────────────────────────────────────────────────────
239
+ ```
240
+
241
+ Type `/arbootstrap` → discover and import projects from your existing tools:
242
+
243
+ ```
244
+ ──────────────────────────────────────────────────────────────
245
+ AgentRecall Bootstrap Complete 2026-04-26
246
+ ──────────────────────────────────────────────────────────────
247
+
248
+ 12 projects created
249
+ 87 items imported (identity, memory, architecture, trajectory)
250
+ 3 items skipped
251
+ 0 errors
252
+
253
+ Run /arstatus to see your projects.
254
+ ──────────────────────────────────────────────────────────────
255
+ ```
256
+
257
+ The cards are **rendered server-side** — computed from actual operation results, not agent interpretation. What you see is always accurate.
258
+
259
+ ```bash
260
+ # Install commands (one-time, Claude Code only)
261
+ mkdir -p ~/.claude/commands
262
+ curl -o ~/.claude/commands/arstatus.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arstatus.md
263
+ curl -o ~/.claude/commands/arstart.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arstart.md
264
+ curl -o ~/.claude/commands/arsave.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsave.md
265
+ curl -o ~/.claude/commands/arsaveall.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsaveall.md
266
+ curl -o ~/.claude/commands/arbootstrap.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arbootstrap.md
267
+ ```
268
+
269
+ ### The Difference
40
270
 
41
- ### Session Lifecycle
271
+ ```
272
+ WITHOUT AgentRecall WITH AgentRecall
273
+ ────────────────── ────────────────
274
+
275
+ Day 1: Build monorepo Day 1: /arstart → /arsave
276
+ Day 2: "What monorepo?" Day 2: /arstart
277
+ → 20 min re-explaining → 2 sec: loads all decisions
278
+ → Agent repeats same mistakes → Knows "no version inflation"
279
+ → Forgets your priorities → Knows "arsave = hero section"
280
+ → Misses half the tasks → Pushes to both repos
281
+ ```
282
+
283
+ ```
284
+ WITHOUT AgentRecall (5 parallel agents) WITH AgentRecall (5 parallel agents)
285
+ ────────────────────────────────────── ────────────────────────────────────
286
+
287
+ Agent 1 finishes: you /arsave Agent 1-5 finish: you type /arsaveall once
288
+ Agent 2 finishes: you /arsave again → Scans all 5 sessions automatically
289
+ Agent 3 finishes: you /arsave again → Merges into consolidated journals
290
+ Agent 4 finishes: you /arsave again → Deduplicates insights across sessions
291
+ Agent 5 finishes: you /arsave again → Zero conflicts (session-ID scoped files)
292
+ → 5x the work, corrections lost → One command, everything saved
293
+ → Agent 3's correction unknown to Agent 5 → All agents share the same memory
294
+ ```
42
295
 
43
- | Function | Signature | Description |
44
- |----------|-----------|-------------|
45
- | `sessionStart(project, opts?)` | `Promise<SessionStartResult>` | Load project context: identity, insights, active rooms, cross-project matches, `watch_for` warnings |
46
- | `sessionEnd(summary, insights, trajectory, opts?)` | `Promise<SessionEndResult>` | Save everything: journal + awareness + palace consolidation |
47
- | `check(goal, confidence, opts?)` | `Promise<CheckResult>` | Record what you think the human wants; get `watch_for` patterns from past corrections |
296
+ ### Three Layers of Value
48
297
 
49
- ### Memory Storage
298
+ **Layer 1 (5 seconds):** It makes your AI agent remember what happened last session.
50
299
 
51
- | Function | Signature | Description |
52
- |----------|-----------|-------------|
53
- | `smartRemember(content, opts?)` | `Promise<RememberResult>` | Auto-classify and route to the right store (journal / palace / awareness / knowledge) |
54
- | `smartRecall(query, opts?)` | `Promise<RecallResult>` | RRF-ranked search across all stores; accepts `feedback` to adjust future rankings |
55
- | `generateTags(content)` | `string[]` | Rule-based multi-label tag generation for new memories |
300
+ **Layer 2 (30 seconds):** Every time you correct your agent — "no, not that version", "ask me first" — that correction is stored permanently and recalled before the agent makes the same mistake again. After 10 sessions, your agent understands your priorities, your communication style, your non-negotiables.
56
301
 
57
- ### Palace Operations
302
+ **Layer 3 (2 minutes):** The [Intelligent Distance Protocol](https://github.com/Goldentrii/AgentRecall/wiki/Intelligent-Distance). The structural gap between human thinking and AI action can't be closed — but it can be navigated better every session. Corrections are training data. The 200-line awareness cap forces quality over quantity. Cross-project insights mean lessons learned once apply everywhere.
58
303
 
59
- | Function | Signature | Description |
60
- |----------|-----------|-------------|
61
- | `createRoom(project, room, opts?)` | `Promise<RoomMeta>` | Create a new palace room |
62
- | `listRooms(project)` | `Promise<RoomMeta[]>` | List all rooms with salience scores |
63
- | `fanOut(project, room, content, opts?)` | `Promise<FanOutResult>` | Write to a room; auto-update cross-references in related rooms |
64
- | `palaceSearch(project, query, opts?)` | `Promise<SearchResult[]>` | Tag-union + keyword search across palace rooms |
65
- | `ensurePalaceInitialized(project)` | `Promise<void>` | Initialize palace structure if not present |
66
- | `recordAccess(project, room)` | `Promise<void>` | Update room access time for salience scoring |
304
+ ---
67
305
 
68
- ### Awareness
306
+ ## Why Choose AgentRecall
69
307
 
70
- | Function | Signature | Description |
71
- |----------|-----------|-------------|
72
- | `readAwareness()` | `Promise<string>` | Read the 200-line compounding awareness document |
73
- | `writeAwareness(content)` | `Promise<void>` | Overwrite awareness document |
74
- | `addInsight(insight, opts?)` | `Promise<void>` | Add insight; triggers merge-or-replace against existing entries |
75
- | `detectCompoundInsights(project)` | `Promise<CompoundInsight[]>` | Detect patterns across multiple sessions |
76
- | `renderAwareness()` | `Promise<string>` | Render structured awareness for context injection |
308
+ **AgentRecall is not a memory tool. It's a learning loop.**
77
309
 
78
- ### Corrections Store
310
+ Memory is the mechanism. Understanding is the goal. Every time you correct your agent — "no, not that version", "put this section first", "ask me before you assume" — that correction is stored, weighted, and recalled next time. After 10 sessions, your agent doesn't just remember your project. It understands how you think: your priorities, your communication style, your non-negotiables.
79
311
 
80
- | Function | Signature | Description |
81
- |----------|-----------|-------------|
82
- | `writeCorrection(rule, why, howToApply, opts?)` | `Promise<void>` | Write a behavioral correction; P0 (never/always/don't) auto-detected |
83
- | `readP0Corrections(project, limit?)` | `Promise<Correction[]>` | Read highest-priority corrections (max 5, loaded on every session start) |
312
+ - **Your agent learns how you think.** Humans are inconsistent — we skip from A to E, forget what we said yesterday, change priorities mid-sentence. AgentRecall captures every correction and surfaces it before the next mistake. The gap between what you mean and what your agent does shrinks with every session.
84
313
 
85
- ### Insights Index
314
+ - **Compounding awareness, not infinite logs.** Memory is capped at 200 lines. New insights either merge with existing ones (strengthening them) or replace the weakest. After 100 sessions, your awareness file is still 200 lines — but each line carries the weight of cross-validated, confirmed observations.
86
315
 
87
- | Function | Signature | Description |
88
- |----------|-----------|-------------|
89
- | `recallInsights(context, opts?)` | `Promise<IndexedInsight[]>` | Cross-project insight recall; ranked by severity × confirmation count |
90
- | `addIndexedInsight(insight, opts?)` | `Promise<void>` | Add insight to the global index |
316
+ - **Cross-project recall.** Lessons learned in one project apply everywhere. Built a rate limiter last month? That lesson surfaces when you're building one today — in a different repo, through a different agent.
91
317
 
92
- ### Scoring Utilities
318
+ - **Near-universal compatibility.** MCP server for any MCP-compatible agent (Claude Code, Cursor, Windsurf, VS Code, Codex). SDK for any JS/TS framework (LangChain, CrewAI, Vercel AI SDK, custom agents). CLI for terminal and CI workflows. One memory system, every surface.
93
319
 
94
- | Function | Signature | Description |
95
- |----------|-----------|-------------|
96
- | `computeSalience(room)` | `number` | `recency(0.30) + access(0.25) + connections(0.20) + urgency(0.15) + importance(0.10)` |
320
+ - **Zero cloud, zero telemetry, all local.** Everything is markdown on disk. Browse it in Obsidian, grep it in the terminal, version it in git. No accounts, no API keys, no lock-in.
97
321
 
98
322
  ---
99
323
 
100
- ## Example: Session Lifecycle
324
+ ## Three Ways to Use It
101
325
 
326
+ **MCP** — for AI agents (Claude Code, Cursor, Windsurf, VS Code, Codex):
327
+ ```bash
328
+ claude mcp add --scope user agent-recall -- npx -y agent-recall-mcp
329
+ ```
330
+
331
+ **SDK** — for any JS/TS application (LangChain, CrewAI, Vercel AI SDK, custom):
102
332
  ```typescript
103
- import {
104
- sessionStart,
105
- smartRemember,
106
- smartRecall,
107
- sessionEnd,
108
- writeCorrection,
109
- readP0Corrections,
110
- setRoot,
111
- } from "agent-recall-core";
112
-
113
- // Optional: override storage root (default: ~/.agent-recall)
114
- setRoot("/custom/path");
115
-
116
- // --- Session Start ---
117
- const ctx = await sessionStart("my-project");
118
- console.log(ctx.identity); // Project identity card
119
- console.log(ctx.insights); // Cross-project insights matched to this project
120
- console.log(ctx.watch_for); // Past corrections that apply — agent should heed these
121
-
122
- // Load highest-priority behavioral corrections
123
- const corrections = await readP0Corrections("my-project");
124
- // e.g. [{ rule: "no black backgrounds", severity: "P0", ... }]
125
-
126
- // --- During Work ---
127
- await smartRemember("We switched from REST to GraphQL for the API layer", {
128
- project: "my-project",
129
- importance: "high",
130
- });
131
-
132
- const results = await smartRecall("API design decisions", {
133
- project: "my-project",
134
- });
135
- // results.items: ranked list from journal + palace + knowledge stores
136
-
137
- // If human corrects the agent:
138
- await writeCorrection(
139
- "Always ask before choosing a framework",
140
- "Human was surprised by the GraphQL choice",
141
- "When picking a framework, present options and get explicit approval",
142
- { project: "my-project" }
143
- );
144
-
145
- // --- Session End ---
146
- await sessionEnd(
147
- "Switched API layer to GraphQL. Documented reasoning in architecture room.",
148
- ["GraphQL reduces over-fetching on dashboard queries"],
149
- "Next: wire authentication middleware",
150
- { project: "my-project" }
151
- );
333
+ import { AgentRecall } from "agent-recall-sdk";
334
+ const memory = new AgentRecall({ project: "my-app" });
335
+ await memory.capture("What stack?", "Next.js + Postgres");
336
+ ```
337
+
338
+ **CLI** — for terminal workflows and CI:
339
+ ```bash
340
+ npx agent-recall-cli capture "What stack?" "Next.js + Postgres"
341
+ npx agent-recall-cli palace walk --depth active
152
342
  ```
153
343
 
154
344
  ---
155
345
 
156
- ## LangChain / CrewAI Integration
346
+ ## What Is AgentRecall?
347
+
348
+ A **learning system** that bridges the gap between how humans think and how AI agents work. Not a log. Not a database. A compounding loop where every correction, decision, and insight makes the next session better than the last.
349
+
350
+ | Without AgentRecall | With AgentRecall |
351
+ |---------------------|------------------|
352
+ | Agent forgets yesterday's decisions | Decisions live in palace rooms, loaded on cold start |
353
+ | Same mistake repeated across sessions | `recall_insight` surfaces past lessons before work starts |
354
+ | 5 min context recovery on each session start | 2 second cold start from palace (~200 tokens) |
355
+ | Flat memory files that grow forever | 200-line awareness cap forces merge-or-replace |
356
+ | Knowledge trapped in one project | Cross-project insights match by keyword |
357
+ | Agent misunderstands, you correct, it forgets | `alignment_check` records corrections permanently |
358
+
359
+ ---
360
+
361
+ ## Quick Start
362
+
363
+ ### MCP Server (for AI agents)
364
+
365
+ ```bash
366
+ # Claude Code
367
+ claude mcp add --scope user agent-recall -- npx -y agent-recall-mcp
368
+
369
+ # Cursor — .cursor/mcp.json
370
+ { "mcpServers": { "agent-recall": { "command": "npx", "args": ["-y", "agent-recall-mcp"] } } }
371
+
372
+ # VS Code — .vscode/mcp.json
373
+ { "servers": { "agent-recall": { "command": "npx", "args": ["-y", "agent-recall-mcp"] } } }
374
+
375
+ # Windsurf — ~/.codeium/windsurf/mcp_config.json
376
+ { "mcpServers": { "agent-recall": { "command": "npx", "args": ["-y", "agent-recall-mcp"] } } }
377
+
378
+ # Codex
379
+ codex mcp add agent-recall -- npx -y agent-recall-mcp
380
+ ```
381
+
382
+ **Skill (Claude Code only):**
383
+ ```bash
384
+ mkdir -p ~/.claude/skills/agent-recall
385
+ curl -o ~/.claude/skills/agent-recall/SKILL.md \
386
+ https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/SKILL.md
387
+ ```
388
+
389
+ ### SDK (for JS/TS applications)
390
+
391
+ ```bash
392
+ npm install agent-recall-sdk
393
+ ```
157
394
 
158
395
  ```typescript
159
- import { sessionStart, smartRecall, smartRemember, sessionEnd } from "agent-recall-core";
396
+ import { AgentRecall } from "agent-recall-sdk";
397
+ const memory = new AgentRecall({ project: "my-app" });
398
+ await memory.coldStart(); // load context (~200 tokens)
399
+ await memory.capture("Q", "A"); // quick capture
400
+ await memory.palaceWrite("architecture", "Stack: Next.js + Drizzle");
401
+ ```
402
+
403
+ ### CLI (for terminal and CI)
404
+
405
+ ```bash
406
+ npm install -g agent-recall-cli
407
+ ar capture "What ORM?" "Drizzle" --project my-app
408
+ ar palace walk --depth active
409
+ ar search "rate limiting" --include-palace
410
+ ```
160
411
 
161
- // Before your agent runs
162
- const ctx = await sessionStart("langchain-app");
163
- const insights = await smartRecall("current task", { project: "langchain-app" });
412
+ ---
413
+
414
+ ## Semantic Recall pgvector Backend (v3.4.0)
415
+
416
+ > [!NOTE]
417
+ > **New in v3.4.0.** Default keyword recall works without any configuration. Upgrade to Supabase + pgvector when keyword search hits its ceiling: synonyms, paraphrased queries, multi-language recall.
418
+
419
+ Keyword search matches tokens. Semantic search matches **meaning**. After upgrading:
420
+ - `recall("session expiry")` also surfaces entries about "token refresh" and "auth timeout"
421
+ - No hand-crafted synonyms needed — embeddings handle the gap
422
+ - Local files remain the source of truth — Supabase is a derived read index
423
+
424
+ ### Setup (3 steps)
164
425
 
165
- const systemPrompt = `You have persistent memory:\n${ctx.identity}\n\nRelevant:\n${
166
- insights.items.map((i) => i.content).join("\n")
167
- }`;
426
+ ```bash
427
+ # Step 1 — interactive setup wizard
428
+ ar setup supabase
168
429
 
169
- // Run your agent with systemPrompt injected...
430
+ # Step 2 apply pgvector migration to your Supabase project
431
+ ar setup supabase --migrate
170
432
 
171
- // After your agent runs
172
- await smartRemember(agentOutput, { project: "langchain-app" });
173
- await sessionEnd("Agent completed task.", ["Key decision from this run"], "Next: ...", {
174
- project: "langchain-app",
175
- });
433
+ # Step 3 done. Run /arstart — backfill happens automatically.
176
434
  ```
177
435
 
436
+ The wizard prompts for your Supabase project URL and service role key → writes to `~/.agent-recall/config.json`. Never committed to git.
437
+
438
+ ### How it works
439
+
440
+ ```
441
+ remember() / session_end()
442
+ → writes to local ~/.agent-recall/ as always ← source of truth, unchanged
443
+ → async: syncs to Supabase memories table
444
+ → OpenAI text-embedding-3-small (1536 dims)
445
+ or Voyage voyage-3-lite (512 dims, zero-padded to 1536)
446
+ → pgvector stores the embedding
447
+
448
+ recall(query)
449
+ → Supabase configured?
450
+ YES → cosine similarity search via pgvector, reranked with local RRF
451
+ NO → local keyword search (existing behavior, unchanged)
452
+ ```
453
+
454
+ ### Graceful degradation
455
+
456
+ If Supabase is unreachable (network error, quota exceeded, not configured), `recall()` falls back to local keyword search silently. Zero behavior change if the feature is never configured.
457
+
458
+ **Required:** `SUPABASE_URL` + `SUPABASE_SERVICE_ROLE_KEY` + either `OPENAI_API_KEY` or `VOYAGE_API_KEY`. All optional — AgentRecall works fully without them.
459
+
460
+ **Rebuild index:** `ar setup supabase --backfill` — re-embeds all local memories into Supabase.
461
+
178
462
  ---
179
463
 
180
- ## Scoring Architecture
464
+ ## How an Agent Uses AgentRecall
465
+
466
+ ### Automatic (Zero Discipline — Hooks)
467
+
468
+ Wire once in `~/.claude/settings.json`. Every session is captured automatically, even without `/arsave`:
469
+
470
+ ```json
471
+ {
472
+ "hooks": {
473
+ "SessionStart": [{
474
+ "command": "node ~/.local/share/npm/lib/node_modules/agent-recall-cli/dist/index.js hook-start 2>/dev/null || true"
475
+ }],
476
+ "UserPromptSubmit": [{
477
+ "command": "node ~/.local/share/npm/lib/node_modules/agent-recall-cli/dist/index.js hook-correction 2>/dev/null || true"
478
+ }],
479
+ "Stop": [{
480
+ "command": "node ~/.local/share/npm/lib/node_modules/agent-recall-cli/dist/index.js hook-end 2>/dev/null || true"
481
+ }]
482
+ }
483
+ }
484
+ ```
181
485
 
182
- AgentRecall uses three scoring algorithms layered together:
486
+ - **hook-start** on every session open: prints identity + top insights + watch_for warnings
487
+ - **hook-correction** — on every prompt: detects corrections (regex) and captures them silently
488
+ - **hook-end** — on every session close: appends a lightweight end-of-session log entry
183
489
 
184
- **1. Reciprocal Rank Fusion (RRF) — Cormack 2009**
185
- Each memory store (journal, palace, knowledge, awareness) ranks results internally. RRF merges the position lists: `score = Σ 1/(k + rank_i)` where `k=60`. No store dominates by default. Tag-union matches get a +0.3 bonus, capped at 1.0.
490
+ ### Session Start (`/arstart`)
491
+ ```
492
+ session_start() → identity, insights, active rooms, cross-project matches,
493
+ recent journal briefs, watch_for warnings — all in one call
494
+ recall(query) → surface task-specific past knowledge from all stores
495
+ ```
186
496
 
187
- **2. Ebbinghaus Forgetting Curve with Zipf Adjustment**
188
- `R(t) = e^(−t/S)` where S is memory-type-specific:
497
+ ### During Work
498
+ ```
499
+ remember("We decided to use GraphQL instead of REST") → auto-routes to the right store
500
+ recall("authentication design") → searches all stores, ranked results
501
+ check(goal="build auth", confidence="medium") → verify understanding, get warnings
502
+ ```
189
503
 
190
- | Memory type | S (days) | 1-day retention |
191
- |-------------|:--------:|:---------------:|
192
- | Journal (episodic) | 2 | 60% |
193
- | Knowledge / bug fix | 180 | 99% |
194
- | Palace / decisions | 9,999 | ≈100% |
504
+ ### Session End (`/arsave`)
505
+ ```
506
+ session_end(summary="...", insights=[...], trajectory="...") journal + awareness + consolidation
507
+ ```
508
+
509
+ ---
195
510
 
196
- Digest cache half-life is Zipf-adjusted: frequently-accessed digests decay slower.
511
+ ## 10 MCP Tools
197
512
 
198
- **3. Bayesian Beta Distribution (designed)**
199
- `E[Beta(α,β)] = (pos+1)/(pos+neg+2)` — optimal estimate of true usefulness from binary feedback. Feedback is query-aware; rating a result "useless" for one query doesn't penalize it for different queries. *Note: the scoring math is implemented but no activation path submits feedback signals yet.*
513
+ AgentRecall exposes 10 tools to agents. Each tool composes multiple subsystems internally — the agent doesn't need to know about the plumbing.
200
514
 
201
- Full rationale: [docs/SCORING.md](../../docs/SCORING.md)
515
+ | Tool | What it does |
516
+ |------|-------------|
517
+ | `session_start` | Load project context for a new session. Returns identity, top insights, active rooms, cross-project matches, recent activity, and predictive `watch_for` warnings from past corrections. One call, ~400 tokens. |
518
+ | `remember` | Save a memory. Auto-classifies content (bug fix, architecture decision, insight, session note) and routes to the right store (journal, palace, knowledge, or awareness). Auto-generates semantic names for future retrieval. |
519
+ | `recall` | Search all memory stores at once using **Reciprocal Rank Fusion (RRF)** — each source ranks internally, then positions are merged so no source dominates by default. Returns ranked results with stable IDs. Accepts `feedback` to rate previous results: positive boosts future ranking, negative penalizes. Query-aware — feedback from one search doesn't bleed into unrelated queries. |
520
+ | `session_end` | Save everything in one call. Writes journal, updates awareness with new insights, consolidates to palace rooms, archives demoted insights (not deleted — preserved with resurrection support). |
521
+ | `check` | Record what you think the human wants. Returns `watch_for` patterns from past correction history ("You've been corrected on X 3 times — ask about it"). Accepts `human_correction` and `delta` after the human responds. Auto-promotes strong patterns (3+) to awareness. |
522
+ | `digest` | **Context cache** — store pre-computed analysis results (codebase audits, subagent explorations) and recall them instead of recomputing. Actions: `store`, `recall`, `read`, `invalidate`. Scoring uses Ebbinghaus decay with Zipf-adjusted half-life. **Benchmarked: 83% token savings on repeated analysis vs. recompute.** |
523
+ | `project_board` | Status board across all AgentRecall projects — same data as `/arstatus`. Returns numbered project list with pending work, blockers, and last activity. Use at the start of any multi-project session. |
524
+ | `project_status` | Deep status for a single project — next actions, blockers, recent journal summary, palace room health. Use after `project_board` to pick and focus. |
525
+ | `bootstrap_scan` | Scan the machine for existing projects (git repos, Claude AutoMemory, CLAUDE.md files). Read-only — no writes. Returns scan results for review before import. |
526
+ | `bootstrap_import` | Import projects discovered by `bootstrap_scan` into AgentRecall. Writes identity, architecture, memory, and trajectory to `~/.agent-recall/`. Safe: never modifies source files. |
527
+
528
+ ### Legacy tools
529
+
530
+ The original 22 subsystem tools (palace_write, journal_capture, awareness_update, etc.) remain available via the SDK and CLI for backward compatibility and advanced use cases. They are not registered in the MCP server by default.
202
531
 
203
532
  ---
204
533
 
205
- ## Storage Layout
534
+ ## How Memory Compounds
535
+
536
+ <p align="center">
537
+ <a href="#1-auto-naming"><img src="https://img.shields.io/badge/1-AUTO--NAMING-5D34F2?style=for-the-badge" alt="Auto-Naming"></a>
538
+ <a href="#2-indexes"><img src="https://img.shields.io/badge/2-INDEXES-0EA5E9?style=for-the-badge" alt="Indexes"></a>
539
+ <a href="#3-relativity"><img src="https://img.shields.io/badge/3-RELATIVITY-10B981?style=for-the-badge" alt="Relativity"></a>
540
+ <a href="#4-weight--decay"><img src="https://img.shields.io/badge/4-WEIGHT_%2B_DECAY-F59E0B?style=for-the-badge" alt="Weight + Decay"></a>
541
+ <a href="#5-feedback-loop"><img src="https://img.shields.io/badge/5-FEEDBACK_LOOP-EF4444?style=for-the-badge" alt="Feedback Loop"></a>
542
+ </p>
543
+
544
+ > Memory is not a list. It's a compounding system where 1+1+1 > 3. Each subsystem feeds the next — naming enables retrieval, retrieval enables feedback, feedback enables ranking, ranking surfaces the right memory at the right time.
545
+
546
+ ### 1. Auto-Naming
547
+
548
+ The agent knows content best at the moment of saving. AgentRecall captures that understanding in a semantic slug — not `"mcp-verified"` but `"verified-agentrecall-mcp-22tools-functional"`. Good naming IS the first layer of retrieval. A well-named memory is 80% findable without any search algorithm.
549
+
550
+ **File naming:** `{date}--{saveType}--{lines}L--{slug}.md` — parseable by agents (`split("--")` → `[date, type, size, topic]`), readable by humans. Line count tells the agent the token cost before opening the file.
551
+
552
+ ### 2. Indexes
553
+
554
+ | Index | What it tracks | Token cost |
555
+ |-------|---------------|------------|
556
+ | **Palace index** | Room catalog + salience scores | ~50 tokens to scan |
557
+ | **Insights index** | Cross-project lessons + keyword matching | ~30 tokens to query |
558
+ | **Awareness** | 200-line compounding document (forced merge) | ~200 tokens, each line cross-validated |
559
+
560
+ ### 3. Relativity
561
+
562
+ Memories that relate to each other are connected automatically — no wikilinks needed. When you `recall("session security")`, the system surfaces keyword-matched memories across connected rooms. Edges are stored in `graph.json` — relativity turns isolated memories into a knowledge graph.
563
+
564
+ ### 4. Weight + Decay
565
+
566
+ Not all memories are equal. Salience scoring: `recency(0.30) + access(0.25) + connections(0.20) + urgency(0.15) + importance(0.10)`
567
+
568
+ `recall` applies the **Ebbinghaus forgetting curve** `R(t) = e^(−t/S)` with memory-type-specific strength values:
569
+
570
+ | Memory type | S (days) | 1-day retention | 1-week retention |
571
+ |-------------|----------|-----------------|------------------|
572
+ | Journal (episodic) | 2 | 60% | ~7% |
573
+ | Knowledge / bug fix (procedural) | 180 | 99% | 96% |
574
+ | Palace / decisions (semantic) | 9999 | ≈100% | ≈100% |
575
+
576
+ Old journal noise fades in days. Architecture decisions persist indefinitely. **Hot-window boost:** Items from the last 6 hours get a 3× score multiplier, last 24 hours get 2×, last 72 hours get 1.3×.
577
+
578
+ ### 5. Feedback Loop
579
+
580
+ The system uses a **Bayesian Beta distribution** — the mathematically optimal estimate of true usefulness from binary observations (`E[Beta(α,β)] = (pos+1)/(pos+neg+2)`). Rating a result "useless" for one query doesn't penalize it for unrelated queries. Feedback is query-aware, not global.
581
+
582
+ > **Feedback is now automatic.** The ambient recall hook tracks which memories were surfaced. Human's next message is a correction → negative feedback. Not a correction → positive feedback. No agent action required.
583
+
584
+ ### The Compounding Effect
585
+
586
+ ```
587
+ Session 1: Save 3 memories (auto-named, indexed, edges created)
588
+ Session 5: Recall surfaces memories from sessions 1-4, feedback refines ranking
589
+ Session 10: watch_for warns agent about past mistakes before they repeat
590
+ Session 20: Awareness contains 10 cross-validated insights (merged from 40+ raw observations)
591
+ Session 50: The agent knows your priorities, blind spots, and communication style
592
+ — not because it was told, but because every correction compounded
593
+ ```
594
+
595
+ **Stemming + synonyms:** "deploying" matches "deployment," "ship," and "release." A 19-rule suffix stemmer + 100-pair synonym table — no vector DB needed (keyword mode), zero external dependencies.
596
+
597
+ ---
598
+
599
+ ## SDK API
600
+
601
+ The `agent-recall-sdk` package exposes the `AgentRecall` class — a programmatic interface to the full memory system. Use it to add persistent, compounding memory to any JS/TS agent framework.
602
+
603
+ ```typescript
604
+ import { AgentRecall } from "agent-recall-sdk";
605
+ const ar = new AgentRecall({ project: "my-project" });
606
+ ```
607
+
608
+ ### Core Methods
609
+
610
+ | Method | Returns | Description |
611
+ |--------|---------|-------------|
612
+ | `capture(question, answer, opts?)` | `JournalCaptureResult` | Quick Q&A capture (L1 memory) |
613
+ | `journalWrite(content, opts?)` | `JournalWriteResult` | Write daily journal entry |
614
+ | `journalRead(opts?)` | `JournalReadResult` | Read journal by date or "latest" |
615
+ | `journalSearch(query, opts?)` | `JournalSearchResult` | Full-text search across journals |
616
+ | `coldStart()` | `JournalColdStartResult` | Palace-first context loading (~200 tokens) |
617
+
618
+ ### Palace Methods
619
+
620
+ | Method | Returns | Description |
621
+ |--------|---------|-------------|
622
+ | `palaceWrite(room, content, opts?)` | `PalaceWriteResult` | Write to a room with fan-out cross-refs |
623
+ | `palaceRead(room?, topic?)` | `PalaceReadResult` | Read room content or list all rooms |
624
+ | `walk(depth?, focus?)` | `PalaceWalkResult` | Progressive walk: identity → active → relevant → full |
625
+ | `palaceSearch(query, room?)` | `PalaceSearchResult` | Search rooms by content |
626
+ | `lint(fix?)` | `PalaceLintResult` | Health check and auto-archive |
627
+
628
+ ### Awareness & Insight Methods
629
+
630
+ | Method | Returns | Description |
631
+ |--------|---------|-------------|
632
+ | `awarenessUpdate(insights, opts?)` | `AwarenessUpdateResult` | Compound new insights into awareness |
633
+ | `readAwareness()` | `string` | Read the 200-line awareness document |
634
+ | `recallInsight(context, opts?)` | `RecallInsightResult` | Cross-project insight recall |
635
+
636
+ ### Alignment Methods
637
+
638
+ | Method | Returns | Description |
639
+ |--------|---------|-------------|
640
+ | `alignmentCheck(input)` | `AlignmentCheckResult` | Record confidence + assumptions |
641
+ | `nudge(input)` | `NudgeResult` | Detect contradictions with past decisions |
642
+ | `synthesize(opts?)` | `ContextSynthesizeResult` | L3 synthesis, optional palace consolidation |
643
+
644
+ ---
645
+
646
+ ## CLI Commands
647
+
648
+ The `agent-recall-cli` package provides the `ar` command for terminal workflows and CI pipelines.
649
+
650
+ ```
651
+ ar v3.4.0 — AgentRecall CLI
652
+
653
+ JOURNAL:
654
+ ar read [--date YYYY-MM-DD] [--section <name>]
655
+ ar write <content> [--section <name>]
656
+ ar capture <question> <answer> [--tags tag1,tag2]
657
+ ar list [--limit N]
658
+ ar search <query> [--include-palace]
659
+ ar state read|write [data]
660
+ ar cold-start
661
+ ar archive [--older-than-days N]
662
+ ar rollup [--min-age-days N] [--dry-run]
663
+
664
+ PALACE:
665
+ ar palace read [<room>] [--topic <name>]
666
+ ar palace write <room> <content> [--importance high|medium|low]
667
+ ar palace walk [--depth identity|active|relevant|full]
668
+ ar palace search <query>
669
+ ar palace lint [--fix]
670
+
671
+ AWARENESS:
672
+ ar awareness read
673
+ ar awareness update --insight "title" --evidence "ev" --applies-when kw1,kw2
674
+
675
+ INSIGHT:
676
+ ar insight <context> [--limit N]
677
+
678
+ SETUP:
679
+ ar setup supabase # interactive Supabase setup wizard
680
+ ar setup supabase --migrate # apply pgvector migration
681
+ ar setup supabase --backfill # re-embed all local memories
682
+
683
+ META:
684
+ ar projects
685
+ ar synthesize [--entries N]
686
+ ar knowledge write --category <cat> --title "t" --what "w" --cause "c" --fix "f"
687
+ ar knowledge read [--category <cat>]
688
+ ar bootstrap [--dry-run] [--import] [--project X]
689
+
690
+ HOOKS (auto-wired via settings.json — zero discipline required):
691
+ ar hook-start # SessionStart: prints identity + insights + watch_for
692
+ ar hook-correction # UserPromptSubmit: silently captures corrections from prompt
693
+ ar hook-end # Stop: appends end-of-session log entry
694
+
695
+ GLOBAL FLAGS:
696
+ --root <path> Storage root (default: ~/.agent-recall)
697
+ --project <slug> Project override
698
+ ```
699
+
700
+ ---
701
+
702
+ ## Architecture
703
+
704
+ ### Five-Layer Memory Pyramid
705
+
706
+ ```
707
+ L1: Working Memory journal_capture "what happened"
708
+ L2: Episodic Memory journal_write "what it means"
709
+ L3: Memory Palace palace_write / walk "knowledge across sessions"
710
+ L4: Awareness awareness_update "compounding insights"
711
+ L5: Insight Index recall_insight "cross-project experience"
712
+ ```
713
+
714
+ ### Key Mechanisms
715
+
716
+ **Fan-out writes** — Write to one room, cross-references auto-update in related rooms via `[[wikilinks]]`. Mechanical, zero LLM cost.
717
+
718
+ **Salience scoring** — Every room has a salience score: `recency(0.30) + access(0.25) + connections(0.20) + urgency(0.15) + importance(0.10)`. High-salience rooms surface first. Below threshold → auto-archive.
719
+
720
+ **Compounding awareness** — `awareness.md` is capped at 200 lines. When new insights are added, similar existing ones merge (strengthen), dissimilar ones compete (lowest-confirmation gets replaced). The constraint creates compression. Compression creates compounding.
721
+
722
+ **Cross-project insight recall** — `insights-index.json` maps insights to situations via keywords. `recall_insight("building quality gates")` returns relevant lessons from any project, ranked by severity x confirmation count.
723
+
724
+ **Obsidian-compatible** — Every palace file has YAML frontmatter + `[[wikilinks]]`. Open `palace/` as an Obsidian vault → graph view shows room connections. Zero Obsidian dependency.
725
+
726
+ ### Storage Layout
206
727
 
207
728
  ```
208
729
  ~/.agent-recall/
209
- awareness.md # 200-line global compounding document
730
+ awareness.md # 200-line compounding document (global)
210
731
  awareness-state.json # Structured awareness data
211
732
  awareness-archive.json # Demoted insights (preserved, not deleted)
212
733
  insights-index.json # Cross-project insight matching
734
+ config.json # Optional: Supabase URL + keys (never git-committed)
213
735
  projects/
214
736
  <project>/
215
737
  journal/
216
738
  YYYY-MM-DD.md # Daily journal
217
- YYYY-MM-DD-log.md # L1 captures (hook entries)
218
- index.jsonl # Fast machine-scannable index
739
+ YYYY-MM-DD-log.md # L1 captures (hook-start/hook-end entries)
740
+ YYYY-MM-DD.state.json # JSON state
741
+ index.jsonl # Fast machine-scannable index of all entries
219
742
  palace/
220
743
  identity.md # ~50 token project identity card
221
744
  palace-index.json # Room catalog + salience scores
222
- graph.json # Cross-reference edges
223
- feedback-log.json # Per-query feedback scores
224
- alignment-log.json # Past corrections for watch_for
225
- corrections.json # P0/P1 behavioral corrections store
745
+ graph.json # Cross-reference edges (relativity)
746
+ feedback-log.json # Per-query feedback scores (recall learning)
747
+ alignment-log.json # Past corrections for watch_for patterns
226
748
  rooms/
227
- goals/
228
- architecture/
229
- blockers/
230
- alignment/
231
- knowledge/
232
- <custom>/ # Agents create rooms on demand
749
+ goals/ # Active goals, evolution
750
+ architecture/ # Technical decisions, patterns
751
+ decisions/ # Decision trails with prior/posterior tracking
752
+ blockers/ # Current and resolved
753
+ alignment/ # Human corrections
754
+ knowledge/ # Learned lessons by category
755
+ <custom>/ # Agents create rooms on demand
233
756
  ```
234
757
 
235
- Everything is markdown + JSON on disk. Obsidian-compatible (YAML frontmatter + `[[wikilinks]]`). Version with git, grep in terminal, browse in Obsidian.
758
+ ---
759
+
760
+ ## Platform Compatibility
761
+
762
+ | Platform | MCP | SDK | CLI | Notes |
763
+ |----------|:---:|:---:|:---:|-------|
764
+ | Claude Code | ✅ | ✅ | ✅ | Full support — MCP + SKILL.md + commands |
765
+ | Cursor | ✅ | ✅ | ✅ | MCP via .cursor/mcp.json |
766
+ | VS Code (Copilot) | ✅ | ✅ | ✅ | MCP via .vscode/mcp.json |
767
+ | Windsurf | ✅ | ✅ | ✅ | MCP via mcp_config.json |
768
+ | OpenAI Codex | ✅ | ✅ | ✅ | `codex mcp add` — config.toml |
769
+ | Claude Desktop | ✅ | — | — | MCP server |
770
+ | LangChain / LangGraph | — | ✅ | — | `new AgentRecall()` in your chain |
771
+ | CrewAI | — | ✅ | — | SDK in tool definitions |
772
+ | Vercel AI SDK | — | ✅ | — | SDK in server actions |
773
+ | Custom JS/TS agents | — | ✅ | ✅ | SDK + CLI for any agent framework |
774
+ | CI / GitHub Actions | — | — | ✅ | `npx agent-recall-cli` in workflows |
775
+ | Any MCP agent | ✅ | — | — | Standard MCP protocol |
236
776
 
237
777
  ---
238
778
 
239
- ## Links
779
+ ## Benchmarked Token Savings
780
+
781
+ We ran two controlled benchmarks: a 5-round A/B test (Next.js + Drizzle + Stripe project) and a 10-round v3.3.16 benchmark validating `digest` cache, `arsaveall`, and cross-project recall. **Read this table honestly:** for simple throwaway tasks, AR is pure overhead. For anything with 3+ sessions, corrections, or multiple agents, it pays for itself — and the savings compound.
782
+
783
+ | Scenario | Without AR | With AR | **Saved** |
784
+ |----------|:---------:|:------:|:--------:|
785
+ | **A: Simple** (2 sessions, 0 corrections) | 567 | 1,131 | **+99% overhead** |
786
+ | **B: Medium** (5 sessions, 1 correction) | 6,220 | 4,382 | **-30%** |
787
+ | **C: Complex** (20 sessions, 5 corrections) | 40,910 | 17,520 | **-57%** |
788
+ | **D: Multi-agent** (3 agents × 5 sessions) | 20,781 | 13,140 | **-37%** |
789
+ | **E: Digest cache** (repeated analysis, 1 recall hit) | ~2,400 | ~400 | **-83%** |
790
+
791
+ **Break-even: ~3-4 sessions.** After that, every session with AR is cheaper than without.
792
+
793
+ ### Where the Savings Come From
794
+
795
+ | Source | Without AR cost | With AR cost | Why |
796
+ |--------|:-:|:-:|-----|
797
+ | **Context rebuild** | Up to ~1,100+ tokens/session | Fixed ~385 tokens (cold start) | AR loads palace context in one call |
798
+ | **Correction retention** | ~800 tokens per repeat | 0 (stored once, never repeated) | Biggest single savings driver in long projects |
799
+ | **Clarification avoidance** | ~400 tokens/session | 0 (already loaded) | Steady per-session savings |
800
+ | **Cross-project recall** | ~500 tokens per insight | ~350 tokens (automatic recall) | Compounds across projects |
801
+ | **Digest cache** | ~2,400 tokens (full re-analysis) | ~400 tokens (recall stored digest) | 83% savings on repeated heavy analysis |
240
802
 
241
- - **MCP server:** [agent-recall-mcp](../mcp-server/README.md) use this for Claude Code / Cursor / Windsurf
242
- - **CLI:** [agent-recall-cli](../cli/README.md) — `ar` command for terminal and CI
243
- - **Full documentation:** [Main README](../../README.md)
244
- - **Scoring rationale:** [docs/SCORING.md](../../docs/SCORING.md)
245
- - **GitHub:** [Goldentrii/AgentRecall](https://github.com/Goldentrii/AgentRecall)
246
- - **Issues:** [GitHub Issues](https://github.com/Goldentrii/AgentRecall/issues)
803
+ All benchmark code: [`benchmark/run.mjs`](benchmark/run.mjs), [`benchmark/ab-comparison.mjs`](benchmark/ab-comparison.mjs), and [`benchmark/v3316-benchmark.mjs`](benchmark/v3316-benchmark.mjs). Run them yourself: `node benchmark/run.mjs && node benchmark/ab-comparison.mjs`.
804
+
805
+ ---
806
+
807
+ ## Docs
808
+
809
+ | Document | Description |
810
+ |----------|-------------|
811
+ | **[→ Command Reference](docs/commands.md)** | **Full guide to `/arstatus`, `/arstart`, `/arsave`, `/arsaveall` — example outputs, modes, palace rules, troubleshooting** |
812
+ | [Intelligent Distance Protocol](docs/intelligent-distance-protocol.md) | The foundational theory — why the gap between human and AI is structural, and how to navigate it |
813
+ | [Scoring Design Rationale](docs/SCORING.md) | Why the scoring system works this way — RRF, Ebbinghaus, Beta distribution, and the bugs they fix |
814
+ | [MCP Adapter Spec](docs/mcp-adapter-spec.md) | Technical spec for building adapters on top of AgentRecall |
815
+ | [SDK Design](docs/sdk-design.md) | Design doc for the SDK architecture |
816
+ | [Upgrade v3.4](UPGRADE-v3.4.md) | Changelog: semantic recall, pgvector backend, 10 MCP tools, bootstrap, palace decisions room |
817
+ | [MCP Server README](packages/mcp-server/README.md) | Focused guide for Claude Code / Cursor / Windsurf users |
818
+ | [Core SDK README](packages/core/README.md) | SDK API reference for building with AgentRecall programmatically |
819
+
820
+ ---
821
+
822
+ ## Contributing
823
+
824
+ Built by [tongwu](https://github.com/Goldentrii) at [Novada](https://www.novada.com).
825
+
826
+ - Issues & feedback: [GitHub Issues](https://github.com/Goldentrii/AgentRecall/issues)
827
+ - Email: [tong.wu@novada.com](mailto:tong.wu@novada.com)
828
+ - Website: [novada.com](https://www.novada.com)
829
+
830
+ MIT License.
247
831
 
248
832
  ---
249
833
 
250
834
  ---
251
835
 
252
- # agent-recall-core(中文文档)
836
+ # AgentRecall(中文文档)
253
837
 
254
- > **Core 引擎包。** 如果你在用 SDK 直接集成 AgentRecall(LangChain、CrewAI、Vercel AI SDK、自定义 agent),使用这个包。
838
+ > **你的智能体记不清楚?听不懂你说话?每次项目都做得非常乱?**
839
+ >
840
+ > **AgentRecall 让它学会理解你的思维方式。**
841
+ >
842
+ > 赋能agent长期记忆,并从错误中学习和纠正,随时间和项目难度进化,越来越擅长和了解用户和agent的思维。
255
843
  >
256
- > 如果你只是想给 Claude Code / Cursor 添加记忆,请用 [`agent-recall-mcp`](../mcp-server/README.md)
844
+ > 持久复合记忆 + 智能距离协议。MCP 服务器 + SDK + CLI
257
845
 
258
846
  ---
259
847
 
260
- ## 安装
848
+ <p align="center">
849
+ <a href="#arstatus-arsave-arstart-和-arsaveall"><img src="https://img.shields.io/badge/%2Farstatus-从这里开始-22C55E?style=for-the-badge" alt="/arstatus"></a>
850
+ <a href="#arstatus-arsave-arstart-和-arsaveall"><img src="https://img.shields.io/badge/%2Farstart-加载上下文-4ECDC4?style=for-the-badge" alt="/arstart"></a>
851
+ <a href="#arstatus-arsave-arstart-和-arsaveall"><img src="https://img.shields.io/badge/%2Farsave-保存会话-FF6B6B?style=for-the-badge" alt="/arsave"></a>
852
+ <a href="#arstatus-arsave-arstart-和-arsaveall"><img src="https://img.shields.io/badge/%2Farsaveall-批量保存-FFD93D?style=for-the-badge" alt="/arsaveall"></a>
853
+ </p>
854
+ <p align="center">
855
+ <img src="https://img.shields.io/badge/自动-hook--start-8B5CF6?style=for-the-badge" alt="hook-start">
856
+ <img src="https://img.shields.io/badge/自动-hook--correction-F97316?style=for-the-badge" alt="hook-correction">
857
+ <img src="https://img.shields.io/badge/自动-hook--end-06B6D4?style=for-the-badge" alt="hook-end">
858
+ </p>
859
+
860
+ ## `/arstatus`、`/arsave`、`/arstart` 和 `/arsaveall`
861
+
862
+ > [!IMPORTANT]
863
+ > **每次新会话都先运行 `/arstatus`。** 它会显示你所有项目的状态、待完成的工作、阻塞项,让你用数字选择下一步——无需记住项目名称。没有它,全新的 agent 根本不知道从哪里开始。
864
+
865
+ | 命令 | 时机 | 功能 |
866
+ |------|------|------|
867
+ | ⭐ **`/arstatus`** | **每次会话——先运行这个** | **跨所有项目的状态看板:待办事项、阻塞项、编号选择列表。真正的冷启动。** |
868
+ | **`/arstart`** | 选好项目后 | 加载单个项目的深度上下文:宫殿房间、纠正记录、任务相关召回 |
869
+ | **`/arsave`** | 会话结束时 | 写入日志 + 整合到记忆宫殿 + 更新感知 |
870
+ | **`/arsaveall`** | 一天结束时(多会话) | **一次性批量保存所有并行会话** — 扫描、合并、去重、完成 |
871
+
872
+ **会话流程:** `/arstatus` → 输入编号 → `/arstart <项目>` → 工作 → `/arsave`。
873
+
874
+ ### 你会看到什么
875
+
876
+ 输入 `/arstatus` → 一眼看清所有项目进展:
877
+
878
+ ```
879
+ ──────────────────────────────────────────────────────────────
880
+ AgentRecall 状态看板 2026-04-21 5 个项目
881
+ ──────────────────────────────────────────────────────────────
882
+
883
+ 1 ⚠ novada-site 2026-04-21 阻塞
884
+ 阻塞:缺少 .env.local — Phase 1 无法继续
885
+
886
+ 2 ● novada-mcp 2026-04-21
887
+ 下一步:修复 novada_search POST /request → 发布 v0.8.0
888
+
889
+ 3 ● prismma-scraper 2026-04-17
890
+ 下一步:UI 升级 Option A — 浅色模式 + 3D 视觉
891
+
892
+ 4 ✓ AgentRecall 2026-04-21 已完成
893
+ 收集真实生产数据中
894
+
895
+ ──────────────────────────────────────────────────────────────
896
+ 输入编号,或:
897
+ N 新项目(带记忆——agent 了解你的完整历史)
898
+ X 新项目(空白状态——无历史上下文,纯客观模式)
899
+ ──────────────────────────────────────────────────────────────
900
+ ```
901
+
902
+ ### 效果对比
903
+
904
+ | 没有 AgentRecall | 有 AgentRecall |
905
+ |-----------------|---------------|
906
+ | 智能体忘记昨天的决策 | 决策存在宫殿房间,冷启动时加载 |
907
+ | 跨会话重复同样的错误 | `recall_insight` 工作前自动呈现过去教训 |
908
+ | 每次开始需要 5 分钟恢复上下文 | 2 秒冷启动,从宫殿加载(~200 token) |
909
+ | 平面记忆文件无限增长 | 200 行感知上限,强制合并或替换 |
910
+ | 知识锁在单个项目 | 跨项目洞察按关键词匹配 |
261
911
 
262
912
  ```bash
263
- npm install agent-recall-core
913
+ # 安装命令(一次性,仅 Claude Code)
914
+ mkdir -p ~/.claude/commands
915
+ curl -o ~/.claude/commands/arstatus.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arstatus.md
916
+ curl -o ~/.claude/commands/arstart.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arstart.md
917
+ curl -o ~/.claude/commands/arsave.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsave.md
918
+ curl -o ~/.claude/commands/arsaveall.md https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/commands/arsaveall.md
264
919
  ```
265
920
 
266
921
  ---
267
922
 
268
- ## 核心函数速查
923
+ ## 快速开始
269
924
 
270
- ### 会话生命周期
925
+ ```bash
926
+ # Claude Code
927
+ claude mcp add --scope user agent-recall -- npx -y agent-recall-mcp
271
928
 
272
- | 函数 | 说明 |
273
- |------|------|
274
- | `sessionStart(project, opts?)` | 加载项目上下文:身份、洞察、活跃房间、`watch_for` 警告 |
275
- | `sessionEnd(summary, insights, trajectory, opts?)` | 一次调用保存所有内容 |
276
- | `check(goal, confidence, opts?)` | 记录对用户意图的理解,返回历史纠正模式 |
929
+ # Cursor .cursor/mcp.json
930
+ { "mcpServers": { "agent-recall": { "command": "npx", "args": ["-y", "agent-recall-mcp"] } } }
277
931
 
278
- ### 记忆存储
932
+ # VS Code — .vscode/mcp.json
933
+ { "servers": { "agent-recall": { "command": "npx", "args": ["-y", "agent-recall-mcp"] } } }
279
934
 
280
- | 函数 | 说明 |
281
- |------|------|
282
- | `smartRemember(content, opts?)` | 自动分类,路由到正确存储 |
283
- | `smartRecall(query, opts?)` | RRF 融合搜索,可反馈调权 |
284
- | `generateTags(content)` | 规则驱动的多标签生成 |
935
+ # Codex
936
+ codex mcp add agent-recall -- npx -y agent-recall-mcp
937
+ ```
285
938
 
286
- ### 纠正存储
939
+ **Claude Code 技能安装:**
940
+ ```bash
941
+ mkdir -p ~/.claude/skills/agent-recall
942
+ curl -o ~/.claude/skills/agent-recall/SKILL.md \
943
+ https://raw.githubusercontent.com/Goldentrii/AgentRecall/main/SKILL.md
944
+ ```
287
945
 
288
- | 函数 | 说明 |
289
- |------|------|
290
- | `writeCorrection(rule, why, how, opts?)` | 写入行为纠正;自动检测 P0 级别(never/always/don't) |
291
- | `readP0Corrections(project, limit?)` | 读取最高优先级纠正(每次 session_start 自动加载) |
946
+ ---
947
+
948
+ ## 语义召回 pgvector (v3.4.0)
949
+
950
+ > [!NOTE]
951
+ > **v3.4.0 新功能。** 默认关键词召回无需任何配置。当关键词搜索遇到天花板时——同义词、改写查询、多语言——升级到 Supabase pgvector 后端。
952
+
953
+ 关键词搜索匹配词汇,语义搜索匹配**含义**。升级后:`recall("会话过期")` 也能找到"token 刷新"和"认证超时"相关的条目,无需手动添加同义词。
954
+
955
+ ```bash
956
+ # 第 1 步 — 交互式配置向导
957
+ ar setup supabase
958
+
959
+ # 第 2 步 — 将 pgvector 迁移应用到你的 Supabase 项目
960
+ ar setup supabase --migrate
292
961
 
293
- ### 感知系统
962
+ # 第 3 步 — 完成。运行 /arstart — 下次会话自动回填。
963
+ ```
964
+
965
+ 本地文件仍为数据源。Supabase 是派生的读取索引 — 随时可删除并用 `ar setup supabase --backfill` 重建。
966
+
967
+ **所需环境变量:** `SUPABASE_URL` + `SUPABASE_SERVICE_ROLE_KEY` + `OPENAI_API_KEY`(或 `VOYAGE_API_KEY`)。全部可选 — 不配置时 AgentRecall 完全正常运行。
294
968
 
295
- | 函数 | 说明 |
969
+ **优雅降级:** Supabase 不可达时,`recall()` 静默回退到本地关键词搜索,零行为变化。
970
+
971
+ ---
972
+
973
+ ## 10 个 MCP 工具
974
+
975
+ AgentRecall 目前向 agent 提供 10 个工具。每个工具内部组合多个子系统——agent 不需要了解内部管道。
976
+
977
+ | 工具 | 功能 |
296
978
  |------|------|
297
- | `readAwareness()` | 读取 200 行复合感知文档 |
298
- | `addInsight(insight, opts?)` | 添加洞察,触发合并或替换逻辑 |
299
- | `recallInsights(context, opts?)` | 跨项目洞察召回 |
979
+ | `session_start` | 加载项目上下文。返回身份、洞察、活跃房间、跨项目匹配、watch_for 预警。约 400 token。 |
980
+ | `remember` | 保存记忆。自动分类并路由到正确的存储(日志、宫殿、知识库或感知系统)。 |
981
+ | `recall` | 通过 **RRF** 一次搜索所有记忆。支持 `feedback` 评价:正面提升排名,负面降低。查询感知。 |
982
+ | `session_end` | 一次调用保存全部:写日志、更新感知、整合宫殿、归档被替换洞察。 |
983
+ | `check` | 记录对人类意图的理解。返回 `watch_for` 预警。3+ 次强模式自动提升为感知洞察。 |
984
+ | `digest` | **上下文缓存**。存储耗时分析结果(代码库探索、API 审计)。实测节省 83% token。 |
985
+ | `project_board` | 跨所有项目的状态看板,等同于 `/arstatus`。返回编号项目列表、待办、阻塞项。 |
986
+ | `project_status` | 单个项目的深度状态:下一步行动、阻塞项、最近日志摘要、宫殿健康度。 |
987
+ | `bootstrap_scan` | 扫描机器上的现有项目(git 仓库、Claude AutoMemory、CLAUDE.md)。只读,不写入。 |
988
+ | `bootstrap_import` | 将 `bootstrap_scan` 发现的项目导入 AgentRecall。安全:不修改源文件。 |
300
989
 
301
990
  ---
302
991
 
303
- ## 会话示例
992
+ ## 记忆如何复合增长
993
+
994
+ 不是所有记忆都平等。五个子系统相互喂养,自动命名让索引有意义,索引让关联性成为可能,关联性让检索精准,精准检索产生有意义的反馈,反馈让下一次检索更好。
995
+
996
+ **显著性评分:** `时效性(0.30) + 访问频率(0.25) + 连接数(0.20) + 紧迫性(0.15) + 重要性(0.10)`
997
+
998
+ **Ebbinghaus 衰减 `R(t) = e^(−t/S)`:**
999
+
1000
+ | 记忆类型 | S(天) | 1天后 | 1周后 |
1001
+ |----------|---------|-------|-------|
1002
+ | 日志(情景) | 2 | 60% | ~7% |
1003
+ | 知识/Bug修复(程序) | 180 | 99% | 96% |
1004
+ | 宫殿/架构决策(语义) | 9999 | ≈100% | ≈100% |
1005
+
1006
+ 旧日志噪音数天内消退,架构决策永久保留。
1007
+
1008
+ **复合效应:**
1009
+ ```
1010
+ 会话 1: 保存 3 条记忆(自动命名、索引、创建边)
1011
+ 会话 10: watch_for 在错误重复之前警告 agent
1012
+ 会话 20: 感知包含 10 条交叉验证的洞察(从 40+ 条原始观察合并)
1013
+ 会话 50: Agent 了解你的优先级、盲点和沟通风格
1014
+ ```
1015
+
1016
+ ---
1017
+
1018
+ ## SDK API
304
1019
 
305
1020
  ```typescript
306
- import { sessionStart, smartRemember, smartRecall, sessionEnd } from "agent-recall-core";
1021
+ import { AgentRecall } from "agent-recall-sdk";
1022
+ const ar = new AgentRecall({ project: "my-project" });
1023
+ ```
1024
+
1025
+ | 方法 | 说明 |
1026
+ |------|------|
1027
+ | `capture(question, answer, opts?)` | 快速问答捕获(L1 记忆) |
1028
+ | `journalWrite(content, opts?)` | 写入每日日志 |
1029
+ | `coldStart()` | 宫殿优先上下文加载(~200 token) |
1030
+ | `palaceWrite(room, content, opts?)` | 写入房间,自动扇出交叉引用 |
1031
+ | `palaceRead(room?, topic?)` | 读取房间内容 |
1032
+ | `walk(depth?, focus?)` | 渐进式宫殿漫步 |
1033
+ | `awarenessUpdate(insights, opts?)` | 复合新洞察到感知系统 |
1034
+ | `recallInsight(context, opts?)` | 跨项目洞察召回 |
1035
+ | `alignmentCheck(input)` | 记录置信度和假设 |
1036
+ | `synthesize(opts?)` | L3 合成,可选宫殿整合 |
1037
+
1038
+ ---
1039
+
1040
+ ## CLI 命令
1041
+
1042
+ ```bash
1043
+ # 日志
1044
+ ar capture <question> <answer> [--tags tag1,tag2]
1045
+ ar read [--date YYYY-MM-DD]
1046
+ ar search <query> [--include-palace]
1047
+ ar rollup [--min-age-days N] [--dry-run]
1048
+
1049
+ # 宫殿
1050
+ ar palace write <room> <content> [--importance high|medium|low]
1051
+ ar palace walk [--depth identity|active|relevant|full]
1052
+ ar palace search <query>
1053
+
1054
+ # 感知与洞察
1055
+ ar awareness update --insight "标题" --evidence "证据" --applies-when kw1,kw2
1056
+ ar insight <context> [--limit N]
1057
+
1058
+ # 语义召回配置
1059
+ ar setup supabase [--migrate] [--backfill]
1060
+
1061
+ # 全局选项
1062
+ --root <path> 存储根目录(默认:~/.agent-recall)
1063
+ --project <slug> 项目覆盖
1064
+ ```
307
1065
 
308
- const ctx = await sessionStart("my-project");
309
- // ctx.watch_for — 历史纠正警告
1066
+ ---
310
1067
 
311
- await smartRemember("改用 GraphQL 替代 REST", { project: "my-project", importance: "high" });
1068
+ ## 架构
312
1069
 
313
- const results = await smartRecall("API 设计决策", { project: "my-project" });
1070
+ ### 五层记忆模型
314
1071
 
315
- await sessionEnd("完成 API 层切换", ["GraphQL 减少 dashboard 过度请求"], "下一步:认证中间件", {
316
- project: "my-project",
317
- });
318
1072
  ```
1073
+ L1: 工作记忆 journal_capture 「发生了什么」
1074
+ L2: 情景记忆 journal_write 「这意味着什么」
1075
+ L3: 记忆宫殿 palace_write / walk 「跨会话的知识」
1076
+ L4: 感知系统 awareness_update 「复合的洞察」
1077
+ L5: 洞察索引 recall_insight 「跨项目的经验」
1078
+ ```
1079
+
1080
+ **扇出写入** — 写入一个房间,相关房间通过 `[[wikilinks]]` 自动更新交叉引用。零 LLM 成本。
1081
+
1082
+ **Obsidian 兼容** — YAML frontmatter + `[[wikilinks]]`。将 `palace/` 作为 Obsidian vault 打开即可。
1083
+
1084
+ ---
1085
+
1086
+ ## 平台兼容性
1087
+
1088
+ | 平台 | MCP | SDK | CLI | 说明 |
1089
+ |------|:---:|:---:|:---:|------|
1090
+ | Claude Code | ✅ | ✅ | ✅ | 完整支持 — MCP + 技能 + 命令 |
1091
+ | Cursor | ✅ | ✅ | ✅ | MCP via .cursor/mcp.json |
1092
+ | VS Code (Copilot) | ✅ | ✅ | ✅ | MCP via .vscode/mcp.json |
1093
+ | Windsurf | ✅ | ✅ | ✅ | MCP via mcp_config.json |
1094
+ | OpenAI Codex | ✅ | ✅ | ✅ | `codex mcp add` |
1095
+ | LangChain / CrewAI | — | ✅ | — | SDK 集成到你的 chain 中 |
1096
+ | Vercel AI SDK | — | ✅ | — | SDK 在 server actions 中使用 |
1097
+ | CI / GitHub Actions | — | — | ✅ | `npx agent-recall-cli` |
1098
+ | 任何 MCP 智能体 | ✅ | — | — | 标准 MCP 协议 |
319
1099
 
320
1100
  ---
321
1101
 
322
- ## 评分架构(简述)
1102
+ ## 实测 Token 节省
323
1103
 
324
- - **RRF(Cormack 2009)** 各存储内部排名,RRF 融合位置列表,任何存储不独占排名
325
- - **Ebbinghaus 遗忘曲线 + Zipf 调整** — 日志 2 天衰减,宫殿决策永久保留,高频访问的 digest 衰减更慢
326
- - **贝叶斯 Beta 分布** 从用户反馈估计记忆真实有用性,按查询上下文学习,不跨查询污染
1104
+ | 场景 | AR | 有 AR | **节省** |
1105
+ |------|:----:|:----:|:------:|
1106
+ | **A: 简单** (2 会话,0 纠正) | 567 | 1,131 | **+99% 纯开销** |
1107
+ | **B: 中等** (5 会话,1 次纠正) | 6,220 | 4,382 | **-30%** |
1108
+ | **C: 复杂** (20 会话,5 次纠正) | 40,910 | 17,520 | **-57%** |
1109
+ | **D: 多 Agent** (3 个 agent × 5 会话) | 20,781 | 13,140 | **-37%** |
1110
+ | **E: Digest 缓存** (重复分析,1 次命中) | ~2,400 | ~400 | **-83%** |
327
1111
 
328
- 详细说明:[docs/SCORING.md](../../docs/SCORING.md)
1112
+ > **盈亏平衡:~3-4 个会话。** 简单一次性任务,AR 是纯开销。3+ 会话、有纠正、多 agent 的场景,AR 都能回本。
329
1113
 
330
1114
  ---
331
1115
 
332
- ## 相关链接
1116
+ ## 文档
1117
+
1118
+ | 文档 | 说明 |
1119
+ |------|------|
1120
+ | **[→ 命令参考](docs/commands.md)** | **`/arstatus`、`/arstart`、`/arsave`、`/arsaveall` 完整指南** |
1121
+ | [智能距离协议](docs/intelligent-distance-protocol.md) | 基础理论 — 人类与 AI 之间的差距是结构性的,如何减少信息损失 |
1122
+ | [评分设计原理](docs/SCORING.md) | RRF、艾宾浩斯、Beta 分布及其修复的 bug |
1123
+ | [v3.4 升级说明](UPGRADE-v3.4.md) | 语义召回、pgvector、10 工具、bootstrap、decisions 房间 |
1124
+
1125
+ ---
1126
+
1127
+ ## 贡献
1128
+
1129
+ 由 [tongwu](https://github.com/Goldentrii) 在 [Novada](https://www.novada.com) 构建。
1130
+
1131
+ - Issues & 反馈:[GitHub Issues](https://github.com/Goldentrii/AgentRecall/issues)
1132
+ - 邮箱:[tong.wu@novada.com](mailto:tong.wu@novada.com)
1133
+
1134
+ MIT 许可证。
1135
+
1136
+ ## Star History
333
1137
 
334
- - **MCP 服务器:** [agent-recall-mcp](../mcp-server/README.md)
335
- - **完整文档:** [主 README](../../README.md)
336
- - **GitHub:** [Goldentrii/AgentRecall](https://github.com/Goldentrii/AgentRecall)
1138
+ <a href="https://www.star-history.com/?repos=Goldentrii%2FAgentRecall&type=date&legend=top-left">
1139
+ <picture>
1140
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=Goldentrii/AgentRecall&type=date&theme=dark&legend=top-left" />
1141
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=Goldentrii/AgentRecall&type=date&legend=top-left" />
1142
+ <img alt="Star History Chart" src="https://api.star-history.com/chart?repos=Goldentrii/AgentRecall&type=date&legend=top-left" />
1143
+ </picture>
1144
+ </a>