@fabersep/memory 0.0.0-stage → 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.
Files changed (43) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +399 -2
  3. package/dist/src/bm25.d.ts +26 -0
  4. package/dist/src/bm25.js +183 -0
  5. package/dist/src/cache-logs.d.ts +47 -0
  6. package/dist/src/cache-logs.js +433 -0
  7. package/dist/src/cli.d.ts +2 -0
  8. package/dist/src/cli.js +701 -0
  9. package/dist/src/compiler.d.ts +23 -0
  10. package/dist/src/compiler.js +211 -0
  11. package/dist/src/config.d.ts +20 -0
  12. package/dist/src/config.js +134 -0
  13. package/dist/src/doctor.d.ts +23 -0
  14. package/dist/src/doctor.js +447 -0
  15. package/dist/src/frontmatter.d.ts +22 -0
  16. package/dist/src/frontmatter.js +199 -0
  17. package/dist/src/git.d.ts +33 -0
  18. package/dist/src/git.js +251 -0
  19. package/dist/src/hygiene.d.ts +7 -0
  20. package/dist/src/hygiene.js +89 -0
  21. package/dist/src/importer.d.ts +34 -0
  22. package/dist/src/importer.js +261 -0
  23. package/dist/src/index.d.ts +18 -0
  24. package/dist/src/index.js +18 -0
  25. package/dist/src/init.d.ts +43 -0
  26. package/dist/src/init.js +280 -0
  27. package/dist/src/mcp.d.ts +218 -0
  28. package/dist/src/mcp.js +437 -0
  29. package/dist/src/metrics.d.ts +72 -0
  30. package/dist/src/metrics.js +179 -0
  31. package/dist/src/proposals.d.ts +34 -0
  32. package/dist/src/proposals.js +420 -0
  33. package/dist/src/stats.d.ts +165 -0
  34. package/dist/src/stats.js +579 -0
  35. package/dist/src/store.d.ts +23 -0
  36. package/dist/src/store.js +161 -0
  37. package/dist/src/sync.d.ts +15 -0
  38. package/dist/src/sync.js +47 -0
  39. package/dist/src/types.d.ts +100 -0
  40. package/dist/src/types.js +17 -0
  41. package/dist/src/ui.d.ts +19 -0
  42. package/dist/src/ui.js +74 -0
  43. package/package.json +50 -4
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,400 @@
1
- # Temporary Holding Version
1
+ # FaberSEP Memory (`@fabersep/memory`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
4
+
5
+ **Prefix-cache-first, Git-backed Markdown memory for AI coding agents.**
6
+
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`).
8
+
9
+ ---
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
+
45
+ ## How It Works (The 2-Minute Mental Model)
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
+
63
+ If you are new to agent memory systems, here is everything you need to know:
64
+
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.
66
+ 2. **Three progressive layers (L0 -> L1 -> L2) keep context small and prompt-cache friendly:**
67
+ - **L0 (`MEMORY.md`):** A short, deterministic table of contents compiled from your active `team` and `personal` entries (hard cap: 1,500 tokens). No timestamps, no pending counts, no machine paths — so your LLM prompt cache stays warm turn after turn.
68
+ - **L1 (`memory_search`):** When an agent needs details, it searches your memory with a built-in pure-JS BM25 search tool and gets compact summaries back.
69
+ - **L2 (`memory_get`):** The agent fetches the full Markdown body only for the exact entry it needs.
70
+ 3. **Agents propose; humans approve (`pre-memory`).** Active memory is read-only for agents. When an agent learns a new rule or lesson, it calls `memory_propose`, which stages a proposal in `pre-memory`. You review and approve it in one batch — keeping your memory accurate and noise-free.
71
+ 4. **Three scopes:**
72
+ - **`personal`** — Your own rules, lessons, and preferences (solo local Git repo, e.g. `~/.faber/memory`).
73
+ - **`team`** — Shared engineering rules in a private team Git repo.
74
+ - **`project`** — Optional repo-specific memory in `<repo>/.faber/memory/`.
75
+
76
+ ---
77
+
78
+ ## Prerequisites
79
+
80
+ - **Node.js 20 or newer** (`node -v` to check)
81
+ - **Git** (`git --version` to check)
82
+
83
+ You do **not** need to install anything globally to try it — `npx @fabersep/memory` runs the CLI directly.
84
+ *(If you prefer shorter commands, install globally once with `npm install -g @fabersep/memory` and use `faber-memory` instead of `npx @fabersep/memory`.)*
85
+
86
+ ---
87
+
88
+ ## Step-by-Step Quickstart (Solo / Personal Setup)
89
+
90
+ Follow these 5 steps in order. Each step is safe and reversible.
91
+
92
+ ### Step 1: Create your personal memory folder
93
+
94
+ Run:
95
+
96
+ ```bash
97
+ npx @fabersep/memory setup ~/.faber/memory
98
+ ```
99
+
100
+ **What this does:**
101
+ - Creates `~/.faber/memory` (you can pick any folder path you like) and initializes a local Git repository on branch `main`.
102
+ - Saves your configuration in `~/.faber/memory-state/config.json`.
103
+
104
+ ### Step 2: Connect your AI coding agent
105
+
106
+ First, run a **dry-run** to preview the exact **Before / After** changes without modifying anything:
107
+
108
+ ```bash
109
+ npx @fabersep/memory init
110
+ ```
111
+
112
+ When the preview looks good, apply it:
113
+
114
+ ```bash
115
+ npx @fabersep/memory init --apply
116
+ ```
117
+
118
+ **What this does:**
119
+ - Compiles your L0 index first to `~/.faber/memory-state/MEMORY.md`.
120
+ - Creates a `.bak` backup of every file it touches.
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).
123
+
124
+ > **Tip:** Target specific engines with `--engine`:
125
+ > ```bash
126
+ > npx @fabersep/memory init --engine claude-code,antigravity --apply
127
+ > ```
128
+ > Revert the wiring cleanly at any time (keeps your memory repos & proposals intact):
129
+ > ```bash
130
+ > npx @fabersep/memory init --undo
131
+ > ```
132
+
133
+ #### Supported Engines & What `init --apply` Wires
134
+
135
+ | Engine | Instruction File | MCP Config | Notes |
136
+ | :--- | :--- | :--- | :--- |
137
+ | **Claude Code** | `~/.claude/CLAUDE.md` (`@path` include) | `~/.claude.json` | Native `@path` L0 include + MCP tools |
138
+ | **Antigravity** | `~/.gemini/GEMINI.md` (read-at-start rule) | `~/.gemini/config/mcp_config.json` | Reads L0 at start + MCP tools |
139
+ | **Claude Desktop** | — | `claude_desktop_config.json` | MCP tools (`--engine claude-desktop`) |
140
+ | **Cursor** | — (GAP) | `~/.cursor/mcp.json` | MCP-only |
141
+ | **Codex** | — (GAP) | — | MCP-only (manual config) |
142
+
143
+ ### Step 3: Import your existing memory files (optional, zero LLM)
144
+
145
+ Already have Markdown notes, Claude auto-memory files, an `AGENTS.md`, or Cursor rules? You can import them deterministically without spending any LLM tokens.
146
+
147
+ Pick the command that matches your source:
148
+
149
+ ```bash
150
+ # 1. Any folder of Markdown (.md) files
151
+ npx @fabersep/memory import --from markdown-dir ./path/to/your/memory
152
+
153
+ # 2. Existing Claude Code auto-memory folder
154
+ npx @fabersep/memory import --from claude-memory ~/.claude/projects/<your-project>/memory
155
+
156
+ # 3. A single AGENTS.md or CLAUDE.md (split each # / ## heading into its own entry)
157
+ npx @fabersep/memory import --from agents-md ./AGENTS.md --split-headings
158
+
159
+ # 4. Existing Cursor rules
160
+ npx @fabersep/memory import --from cursor-rules ./.cursor/rules
161
+ ```
162
+
163
+ **What this does:**
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).
167
+
168
+ ### Step 4: Review and approve staged proposals
169
+
170
+ Review everything waiting in `pre-memory`:
171
+
172
+ ```bash
173
+ npx @fabersep/memory review
174
+ ```
175
+
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)
178
+ - `e` — **edit** the body before approving
179
+ - `r` — **reject** and remove the proposal
180
+ - `s` — **skip** for now
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)
184
+
185
+ *(Shortcuts: `npx @fabersep/memory review --approve-all`, `npx @fabersep/memory approve <id1> <id2>`, or `npx @fabersep/memory reject <id>`.)*
186
+
187
+ ### Step 5: Verify everything is healthy
188
+
189
+ Check your current setup and pending queue:
190
+
191
+ ```bash
192
+ npx @fabersep/memory status
193
+ ```
194
+
195
+ Run the strict validation check (schema, duplicates, 1,500-token L0 budget, and hygiene rules):
196
+
197
+ ```bash
198
+ npx @fabersep/memory compile --check
199
+ ```
200
+
201
+ If both succeed, restart (or start a new session in) your AI coding agent — it now has access to your compiled L0 memory and the 3 `faber-memory` MCP tools.
202
+
203
+ ---
204
+
205
+ ## Team Mode Setup (Shared Private Git Repo)
206
+
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:
210
+
211
+ ```bash
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
215
+
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
232
+ npx @fabersep/memory sync
233
+ ```
234
+
235
+ **How team approvals push:**
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.
237
+ - **`--submit-mode pr`:** Always submits via a Pull Request (`npx @fabersep/memory config set-submit-mode pr`).
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
+
241
+ ---
242
+
243
+ ## Everyday Workflow
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
+
254
+ Once set up, daily use is simple:
255
+
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`.
257
+ 2. **Whenever you have a minute:** Run `npx @fabersep/memory status` to see pending proposals, then `npx @fabersep/memory review` to approve or reject them in one batch.
258
+ 3. **In team mode:** Run `npx @fabersep/memory sync` whenever you want to pull teammates' updates.
259
+
260
+ ### Writing a Memory File by Hand
261
+
262
+ Memory files are standard Markdown with a small YAML frontmatter block:
263
+
264
+ ```markdown
265
+ ---
266
+ id: no-broad-process-kill
267
+ type: rule
268
+ scope: personal
269
+ summary: Never run pkill or killall by broad pattern; stop only your own PID or task.
270
+ tags: [safety, shell]
271
+ ---
272
+
273
+ Never kill processes by broad name patterns like `pkill node` or `killall python`.
274
+ Always stop only the specific PID or background task you started.
275
+ ```
276
+
277
+ Valid `type` values: `rule`, `decision`, `lesson`, `preference`, `reference`.
278
+ After editing or adding a file manually in your memory repo, commit it with Git and run `npx @fabersep/memory compile`.
279
+
280
+ ---
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
+
329
+ ## Installing Globally or Running from Source
330
+
331
+ **Global npm install** (gives you the `faber-memory` command directly):
332
+
333
+ ```bash
334
+ npm install -g @fabersep/memory
335
+ faber-memory --help
336
+ ```
337
+
338
+ **From GitHub source** (for contributing or local development):
339
+
340
+ ```bash
341
+ git clone https://github.com/fabersep/memory.git
342
+ cd memory
343
+ npm install
344
+ npm test
345
+ npm link
346
+ ```
347
+
348
+ ---
349
+
350
+ ## CLI Command Reference
351
+
352
+ | Command | Description |
353
+ | :--- | :--- |
354
+ | `setup [path]` | Initialize a local solo (personal) memory Git repo. |
355
+ | `setup --team <url\|org/repo> [--path <dir>] [--submit-mode auto\|pr]` | Clone and configure a shared team memory repo. |
356
+ | `config` | Print current `~/.faber/memory-state/config.json`. |
357
+ | `config set-path <personal\|team> <new-path>` | Move a configured memory root while keeping its UUID. |
358
+ | `config set-submit-mode <auto\|pr>` | Change team approval mode (`auto` push with PR fallback, or always `pr`). |
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. |
361
+ | `compile [--check] [--repo <dir>]` | Compile L0 `MEMORY.md`, or validate schema/budget/hygiene in CI (`--check`). |
362
+ | `sync [--timeout <ms>]` | Fast-forward pull remote updates and recompile L0. |
363
+ | `status` | Show compiled L0 status, configured roots, warnings, and pending/stale proposals. |
364
+ | `review [--approve-all]` | Interactively approve, edit, reject, skip, go back, or quit & save `pre-memory` proposals. |
365
+ | `approve <id...> [--mode auto\|pr]` | Approve one or more proposals by ID in a single batch commit. |
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`. |
369
+ | `serve` | Run the 3-tool stdio MCP server (used by your AI agent's MCP config). |
370
+
371
+ ---
372
+
373
+ ## MCP Tools
374
+
375
+ The MCP server exposes exactly **3 lean tools** (~350 tokens total tool schema):
376
+
377
+ | Tool | Purpose |
378
+ | :--- | :--- |
379
+ | `memory_search` | Pure-JS BM25 full-text search across active `team`, `personal`, and `project` scopes (returns compact L1 summaries). Automatically reindexes on Git `HEAD` change. |
380
+ | `memory_get` | Fetch the full L2 Markdown body of a specific entry by ID. |
381
+ | `memory_propose` | Stage a new entry or update into `pre-memory` for human review (never writes directly to active memory). |
382
+
383
+ ---
384
+
385
+ ## Documentation & Specs
386
+
387
+ This repository follows the [FaberSEP Spec](https://github.com/fabersep/spec) standard:
388
+
389
+ - [Why FaberSEP Memory? (FAQ & Comparisons)](docs/why-faber-memory.md)
390
+ - [Troubleshooting & Edge Cases](docs/troubleshooting.md)
391
+ - [Master PRD](docs/master-prd.md)
392
+ - [Architecture](docs/architecture.md)
393
+ - [Core Memory PRD](docs/features/01-core-memory/prd.md)
394
+ - [BDD Acceptance Criteria (55 scenarios)](docs/features/01-core-memory/acceptance_criteria.md)
395
+
396
+ ---
397
+
398
+ ## License
399
+
400
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,26 @@
1
+ import { MemoryEntry, Proposal, Scope, SearchResultItem, EntryType } from './types.js';
2
+ export declare function tokenize(text: string): string[];
3
+ export declare class BM25Index {
4
+ private docs;
5
+ private docFreq;
6
+ private avgDocLen;
7
+ private readonly k1;
8
+ private readonly b;
9
+ rebuild(entries: MemoryEntry[], pendingProposals?: Proposal[]): void;
10
+ private addDoc;
11
+ search(query: string, options?: {
12
+ scope?: Scope;
13
+ type?: EntryType;
14
+ includePending?: boolean;
15
+ limit?: number;
16
+ }): SearchResultItem[];
17
+ }
18
+ export interface NearDuplicateMatch {
19
+ id: string;
20
+ scope: Scope;
21
+ summary: string;
22
+ pending: boolean;
23
+ similarity: number;
24
+ }
25
+ export declare function computeSimilarity(textA: string, textB: string): number;
26
+ export declare function findNearDuplicates(candidateSummary: string, candidateBody: string, activeEntries: MemoryEntry[], pendingProposals: Proposal[], threshold: number): NearDuplicateMatch[];