@fabersep/memory 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -2,16 +2,64 @@
2
2
 
3
3
  [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
4
4
 
5
- > Layer 0 of the FaberSEP engineering context stack (`@fabersep/memory` -> `@fabersep/spec` -> `@fabersep/atlas`).
6
-
7
5
  **Prefix-cache-first, Git-backed Markdown memory for AI coding agents.**
8
6
 
9
7
  Zero databases. Zero native addons. Zero runtime dependencies. Just plain Markdown files in Git, a deterministic compiled index that keeps your prompt cache warm, a human-approved `pre-memory` inbox so agents never pollute your rules, and a 3-tool MCP server (`memory_search`, `memory_get`, `memory_propose`).
10
8
 
11
9
  ---
12
10
 
11
+ ## Table of Contents
12
+
13
+ - [Why FaberSEP Memory?](#why-fabersep-memory)
14
+ - [How It Works](#how-it-works-the-2-minute-mental-model)
15
+ - [Prerequisites](#prerequisites)
16
+ - [Solo / Personal Setup (5 Steps)](#step-by-step-quickstart-solo--personal-setup)
17
+ - [Team Mode Setup (Shared Private Repo)](#team-mode-setup-shared-private-git-repo)
18
+ - [Everyday Workflow](#everyday-workflow)
19
+ - [Updating to a Newer Version](#updating-to-a-newer-version)
20
+ - [Cleaning Up or Resetting](#cleaning-up-or-resetting)
21
+ - [CLI Command Reference](#cli-command-reference)
22
+ - [MCP Tools](#mcp-tools)
23
+ - [FAQ & Comparisons](docs/why-faber-memory.md)
24
+ - [Troubleshooting & Edge Cases](docs/troubleshooting.md)
25
+
26
+ ---
27
+
28
+ ## Why FaberSEP Memory?
29
+
30
+ *"Doesn't Claude Code, Antigravity, or Cursor already have built-in memory?"*
31
+
32
+ Built-in auto-memory is tied to a single tool and lets agents silently overwrite your rules. Vector-DB memory servers add Docker/DB overhead and break prompt caching with dynamic injections. **`@fabersep/memory` solves all four at once:**
33
+
34
+ | | Built-in Auto-Memory | Vector-DB Memory MCPs | `@fabersep/memory` |
35
+ | :--- | :--- | :--- | :--- |
36
+ | **Portability** | Locked to one tool | Needs hosted DB/SDK | **One Git repo across Claude, Antigravity, Cursor, Codex** |
37
+ | **Safety** | Agents write silently (drift) | Auto-extracted noise | **Read-only active memory + human `pre-memory` review** |
38
+ | **Prompt Cache** | Grows unpredictably | Dynamic RAG breaks prefix | **Deterministic L0 (<1,500 tok), cache-warm (~80%+)** |
39
+ | **Setup & Team** | Local only, no PRs | Docker / DB / API keys | **Zero dependencies, pure Git `HEAD` + team PRs** |
40
+
41
+ > Want the full breakdown (why BM25 over embeddings, why prompt caching matters, mobile/remote access)? Read **[Why FaberSEP Memory? (FAQ & Comparisons)](docs/why-faber-memory.md)**.
42
+
43
+ ---
44
+
13
45
  ## How It Works (The 2-Minute Mental Model)
14
46
 
47
+ ```mermaid
48
+ flowchart LR
49
+ subgraph Git["Git HEAD (Source of Truth)"]
50
+ T["Team Repo<br/>(shared private repo)"]
51
+ P["Personal Repo<br/>(~/.faber/memory)"]
52
+ PR["Project Repo<br/>(.faber/memory/)"]
53
+ end
54
+
55
+ T & P -->|"Deterministic compile<br/>(< 1,500 tokens)"| L0["L0: MEMORY.md<br/>(always loaded, cache-warm)"]
56
+ T & P & PR -->|"In-memory BM25<br/>(auto-reindexes on HEAD)"| L1["L1: memory_search<br/>(compact summaries)"]
57
+ L1 -->|"Fetch exact ID"| L2["L2: memory_get<br/>(full Markdown body)"]
58
+
59
+ L0 --> Agent["AI Coding Agent"]
60
+ L2 --> Agent
61
+ ```
62
+
15
63
  If you are new to agent memory systems, here is everything you need to know:
16
64
 
17
65
  1. **Git is the single source of truth.** Every active memory entry is a small Markdown file committed to Git (`HEAD`). Uncommitted files are never silently trusted.
@@ -33,7 +81,7 @@ If you are new to agent memory systems, here is everything you need to know:
33
81
  - **Git** (`git --version` to check)
34
82
 
35
83
  You do **not** need to install anything globally to try it — `npx @fabersep/memory` runs the CLI directly.
36
- *(If you prefer shorter commands, you can install it globally once with `npm install -g @fabersep/memory` and use `faber-memory` instead of `npx @fabersep/memory`.)*
84
+ *(If you prefer shorter commands, install globally once with `npm install -g @fabersep/memory` and use `faber-memory` instead of `npx @fabersep/memory`.)*
37
85
 
38
86
  ---
39
87
 
@@ -55,15 +103,13 @@ npx @fabersep/memory setup ~/.faber/memory
55
103
 
56
104
  ### Step 2: Connect your AI coding agent
57
105
 
58
- First, run a **dry-run** to preview the exact file changes without modifying anything:
106
+ First, run a **dry-run** to preview the exact **Before / After** changes without modifying anything:
59
107
 
60
108
  ```bash
61
109
  npx @fabersep/memory init
62
110
  ```
63
111
 
64
- You will see a unified diff showing which instruction file and MCP config will be updated for the agents detected on your machine (`claude-code`, `antigravity`, `cursor`).
65
-
66
- When the diff looks good, apply it:
112
+ When the preview looks good, apply it:
67
113
 
68
114
  ```bash
69
115
  npx @fabersep/memory init --apply
@@ -73,12 +119,13 @@ npx @fabersep/memory init --apply
73
119
  - Compiles your L0 index first to `~/.faber/memory-state/MEMORY.md`.
74
120
  - Creates a `.bak` backup of every file it touches.
75
121
  - Adds a clearly marked `<!-- faber-memory:start --> ... <!-- faber-memory:end -->` block and registers the `faber-memory` MCP server (`npx -y @fabersep/memory serve`).
122
+ - **Trust & safety:** `init --apply` never disables your AI tool's built-in settings behind your back (for example, it does not edit `~/.claude/settings.json`). If you use Claude Code and want to avoid running two parallel memory systems, see [how to optionally disable Claude auto-memory](docs/troubleshooting.md#claude-auto-memory).
76
123
 
77
- > **Tip:** Want to target only specific engines? Pass `--engine`:
124
+ > **Tip:** Target specific engines with `--engine`:
78
125
  > ```bash
79
126
  > npx @fabersep/memory init --engine claude-code,antigravity --apply
80
127
  > ```
81
- > Want to revert the wiring cleanly at any time?
128
+ > Revert the wiring cleanly at any time (keeps your memory repos & proposals intact):
82
129
  > ```bash
83
130
  > npx @fabersep/memory init --undo
84
131
  > ```
@@ -114,9 +161,9 @@ npx @fabersep/memory import --from cursor-rules ./.cursor/rules
114
161
  ```
115
162
 
116
163
  **What this does:**
117
- - Scans your files, infers frontmatter (`id`, `type`, `summary`), checks for near-duplicates and hygiene issues (like hardcoded machine paths or secrets), and stages valid items into **`pre-memory`**.
118
- - Nothing becomes active until you approve it in Step 4. *(In solo mode, if you trust the whole folder and want to skip manual review, you can add `--approve`.)*
119
- - If you imported from `claude-memory`, the CLI also prints how to disable Claude's built-in auto-memory (`"autoMemoryEnabled": false` in `~/.claude/settings.json`) so future notes go through `pre-memory`.
164
+ - Scans your files, infers frontmatter (`id`, `type`, `summary`), skips old index files (`MEMORY.md`, `CATALOG.md`, `README.md`, `INDEX.md`), checks for near-duplicates and hygiene issues (secrets or machine-specific paths), and stages valid items into **`pre-memory`**.
165
+ - Nothing becomes active until you approve it in Step 4.
166
+ - **Have `/Users/<name>/...` or `/home/<name>/...` paths in your old notes?** Add `--normalize-paths` to automatically convert them to portable `~/` paths in the staged copy (your source files stay untouched). See [Machine-Specific Paths](docs/troubleshooting.md#machine-specific-paths).
120
167
 
121
168
  ### Step 4: Review and approve staged proposals
122
169
 
@@ -126,13 +173,14 @@ Review everything waiting in `pre-memory`:
126
173
  npx @fabersep/memory review
127
174
  ```
128
175
 
129
- For each proposal, you will see its `scope`, `type`, `summary`, and full `body`, and choose:
130
- - `a` — **approve** (queued for a single batch commit at the end)
176
+ You will see a numbered progress bar (`[ 1 / 17 ] Approved: 0 | Rejected: 0 | Skipped: 0`) and each proposal in a clean card. Actions:
177
+ - `a` — **approve** (queued for a single batch commit)
131
178
  - `e` — **edit** the body before approving
132
- - `r` — **reject** and delete the proposal
179
+ - `r` — **reject** and remove the proposal
133
180
  - `s` — **skip** for now
134
-
135
- Once you finish the list, all approved proposals are written to your memory repo, committed in **one Git commit**, and your L0 `MEMORY.md` is recompiled automatically.
181
+ - `v` — **view full** body (when a long entry is truncated)
182
+ - `b` — **back** to the previous proposal to change your mind
183
+ - `q` — **quit & save** everything you approved/rejected so far in one commit (pressing `Ctrl+C` also saves your progress safely)
136
184
 
137
185
  *(Shortcuts: `npx @fabersep/memory review --approve-all`, `npx @fabersep/memory approve <id1> <id2>`, or `npx @fabersep/memory reject <id>`.)*
138
186
 
@@ -156,24 +204,53 @@ If both succeed, restart (or start a new session in) your AI coding agent — it
156
204
 
157
205
  ## Team Mode Setup (Shared Private Git Repo)
158
206
 
159
- If you want to share rules across a team (or across multiple machines via a private Git repo):
207
+ Use Team Mode to share rules across a team — or across your own multiple machines via a private Git repo.
208
+
209
+ If you are **starting from scratch in Team Mode**, run these 4 steps:
160
210
 
161
211
  ```bash
162
- # Clone and register your private team memory repo
163
- npx @fabersep/memory setup --team git@github.com:your-org/team-memory.git
212
+ # 1. Clone and register your private team memory repo
213
+ # Accepts HTTPS, github.com/org/repo, org/repo, or SSH (git@github.com:org/repo.git)
214
+ npx @fabersep/memory setup --team https://github.com/your-org/team-memory.git
164
215
 
165
- # Pull the latest team changes and recompile L0
216
+ # Optional: clone into a custom directory (default: ~/.faber/memory-state/clones/team)
217
+ # npx @fabersep/memory setup --team https://github.com/your-org/team-memory.git --path ~/team-memory
218
+
219
+ # 2. Connect your AI coding agent (skip if you already ran init --apply in Solo setup)
220
+ npx @fabersep/memory init --apply
221
+
222
+ # 3. (Optional) Import existing Markdown notes into the team scope
223
+ npx @fabersep/memory import --from markdown-dir ./path/to/your/memory --scope team
224
+
225
+ # 4. Review & approve (pushes to the team repo and compiles L0)
226
+ npx @fabersep/memory review
227
+ ```
228
+
229
+ To pull teammates' updates later:
230
+
231
+ ```bash
166
232
  npx @fabersep/memory sync
167
233
  ```
168
234
 
169
- When you approve a `team` proposal via `review` or `approve`:
235
+ **How team approvals push:**
170
236
  - **`--submit-mode auto` (default):** Pushes directly to the team repo's default branch via a clean temporary worktree. If branch protection rejects the push, it automatically falls back to creating a branch and opening a PR.
171
237
  - **`--submit-mode pr`:** Always submits via a Pull Request (`npx @fabersep/memory config set-submit-mode pr`).
172
238
 
239
+ *(See also: [Step 2: Connect your AI coding agent](#step-2-connect-your-ai-coding-agent) · [Step 3: Import](#step-3-import-your-existing-memory-files-optional-zero-llm) · [Step 4: Review](#step-4-review-and-approve-staged-proposals))*
240
+
173
241
  ---
174
242
 
175
243
  ## Everyday Workflow
176
244
 
245
+ ```mermaid
246
+ flowchart LR
247
+ A["AI Agent works<br/>in your repo"] -->|"Calls memory_propose"| B["pre-memory Inbox<br/>(safe staging)"]
248
+ B -->|"Human runs<br/>faber-memory review"| C{"Approve / Edit<br/>/ Reject"}
249
+ C -->|"Reject"| D["Discarded<br/>(no Git commit)"]
250
+ C -->|"Approve (batched)"| E["Single Git Commit<br/>(or Team PR)"]
251
+ E -->|"Auto-recompile"| F["Updated L0 MEMORY.md<br/>(ready for next session)"]
252
+ ```
253
+
177
254
  Once set up, daily use is simple:
178
255
 
179
256
  1. **During a session:** Your agent loads the compact L0 index, searches deeper with `memory_search` + `memory_get`, and proposes new lessons via `memory_propose`.
@@ -202,6 +279,53 @@ After editing or adding a file manually in your memory repo, commit it with Git
202
279
 
203
280
  ---
204
281
 
282
+ ## Updating to a Newer Version
283
+
284
+ How you update depends on how you run `@fabersep/memory`:
285
+
286
+ - **Using `npx` (no global install):**
287
+ Pass `@latest` to make sure `npx` fetches the newest release instead of a cached copy:
288
+ ```bash
289
+ npx @fabersep/memory@latest --help
290
+ ```
291
+ - **Installed globally via npm:**
292
+ ```bash
293
+ npm install -g @fabersep/memory@latest
294
+ ```
295
+ - **Cloned from GitHub source:**
296
+ ```bash
297
+ cd /path/to/memory
298
+ git pull
299
+ npm install
300
+ npm run build
301
+ ```
302
+
303
+ After updating, your existing memory repos and config continue working as-is. If a new version updates engine wiring, re-running `npx @fabersep/memory@latest init --apply` is safe and idempotent.
304
+
305
+ ---
306
+
307
+ ## Cleaning Up or Resetting
308
+
309
+ - **Remove only agent wiring** (keeps all memory repos and pending proposals):
310
+ ```bash
311
+ npx @fabersep/memory init --undo
312
+ ```
313
+ - **Clear all pending `pre-memory` proposals** (with confirmation):
314
+ ```bash
315
+ npx @fabersep/memory reject --all
316
+ ```
317
+ - **Disconnect a configured root** (removes it from `config.json` without deleting files on disk):
318
+ ```bash
319
+ npx @fabersep/memory config unset personal
320
+ # or: npx @fabersep/memory config unset team
321
+ ```
322
+ - **Full reset** (undoes agent wiring and deletes `~/.faber/memory-state/` after confirmation; add `--include-personal-repo` to also remove your local personal Git repo):
323
+ ```bash
324
+ npx @fabersep/memory reset
325
+ ```
326
+
327
+ ---
328
+
205
329
  ## Installing Globally or Running from Source
206
330
 
207
331
  **Global npm install** (gives you the `faber-memory` command directly):
@@ -228,18 +352,20 @@ npm link
228
352
  | Command | Description |
229
353
  | :--- | :--- |
230
354
  | `setup [path]` | Initialize a local solo (personal) memory Git repo. |
231
- | `setup --team <git-url> [--path <dir>] [--submit-mode auto\|pr]` | Clone and configure a shared team memory repo. |
355
+ | `setup --team <url\|org/repo> [--path <dir>] [--submit-mode auto\|pr]` | Clone and configure a shared team memory repo. |
232
356
  | `config` | Print current `~/.faber/memory-state/config.json`. |
233
357
  | `config set-path <personal\|team> <new-path>` | Move a configured memory root while keeping its UUID. |
234
358
  | `config set-submit-mode <auto\|pr>` | Change team approval mode (`auto` push with PR fallback, or always `pr`). |
235
- | `init [--apply \| --undo] [--engine ...] [--project-hint]` | Preview, apply (with `.bak` backups), or undo user-level agent wiring. |
359
+ | `config unset <personal\|team>` | Disconnect a root from config without deleting files on disk. |
360
+ | `init [--apply \| --undo] [--engine ...] [--project-hint]` | Preview (Before/After), apply (with `.bak` backups), or undo user-level agent wiring. |
236
361
  | `compile [--check] [--repo <dir>]` | Compile L0 `MEMORY.md`, or validate schema/budget/hygiene in CI (`--check`). |
237
362
  | `sync [--timeout <ms>]` | Fast-forward pull remote updates and recompile L0. |
238
363
  | `status` | Show compiled L0 status, configured roots, warnings, and pending/stale proposals. |
239
- | `review [--approve-all]` | Interactively approve, edit, reject, or skip pending `pre-memory` proposals. |
364
+ | `review [--approve-all]` | Interactively approve, edit, reject, skip, go back, or quit & save `pre-memory` proposals. |
240
365
  | `approve <id...> [--mode auto\|pr]` | Approve one or more proposals by ID in a single batch commit. |
241
- | `reject <id>` | Reject and delete a pending proposal. |
242
- | `import --from <type> <path> [--split-headings] [--approve]` | Deterministically import existing memory into `pre-memory`. |
366
+ | `reject <id>` / `reject --all [--yes]` | Reject and delete one or all pending proposals. |
367
+ | `reset [--include-personal-repo] [--yes]` | Undo agent wiring and wipe local state (optionally including personal repo). |
368
+ | `import --from <type> <path> [--scope ...] [--split-headings] [--normalize-paths] [--approve]` | Deterministically import existing memory into `pre-memory`. |
243
369
  | `serve` | Run the 3-tool stdio MCP server (used by your AI agent's MCP config). |
244
370
 
245
371
  ---
@@ -260,6 +386,8 @@ The MCP server exposes exactly **3 lean tools** (~350 tokens total tool schema):
260
386
 
261
387
  This repository follows the [FaberSEP Spec](https://github.com/fabersep/spec) standard:
262
388
 
389
+ - [Why FaberSEP Memory? (FAQ & Comparisons)](docs/why-faber-memory.md)
390
+ - [Troubleshooting & Edge Cases](docs/troubleshooting.md)
263
391
  - [Master PRD](docs/master-prd.md)
264
392
  - [Architecture](docs/architecture.md)
265
393
  - [Core Memory PRD](docs/features/01-core-memory/prd.md)
@@ -0,0 +1,47 @@
1
+ import { CompileMetricEvent } from './metrics.js';
2
+ export type CacheEngineOption = 'claude-code' | 'antigravity' | 'all' | 'cursor' | 'codex' | string;
3
+ export declare const CACHE_TTL_MS: number;
4
+ export interface ModelCacheSummary {
5
+ model: string;
6
+ sessions: number;
7
+ steps: number;
8
+ firstSteps: number;
9
+ warmSteps: number;
10
+ idleGapExcludedSteps: number;
11
+ firstStepHitPct: number;
12
+ warmStepHitPct: number;
13
+ }
14
+ export interface EngineCacheReport {
15
+ engine: 'claude-code' | 'antigravity';
16
+ foundDir: boolean;
17
+ unrecognizedFormat?: boolean;
18
+ sessions: number;
19
+ steps: number;
20
+ firstSteps: number;
21
+ warmSteps: number;
22
+ idleGapExcludedSteps: number;
23
+ firstStepHitPct: number;
24
+ warmStepHitPct: number;
25
+ skippedLines: number;
26
+ byModel: ModelCacheSummary[];
27
+ correlation?: {
28
+ applicable: boolean;
29
+ note?: string;
30
+ eligibleSessions: number;
31
+ correlatedBreaks: number;
32
+ };
33
+ }
34
+ export interface CacheAnalysisResult {
35
+ unsupportedEngine?: string;
36
+ unsupportedMessage?: string;
37
+ engines: EngineCacheReport[];
38
+ skippedLines: number;
39
+ }
40
+ export declare function analyzeCacheLogs(options: {
41
+ engine?: CacheEngineOption;
42
+ logDir?: string;
43
+ days: number;
44
+ nowMs?: number;
45
+ userHome?: string;
46
+ changedCompiles?: CompileMetricEvent[];
47
+ }): CacheAnalysisResult;