memory_vault
by ylx9000
README.md
<div align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/logo.svg">
<img src="assets/logo-light.svg" width="128" alt="AnchorDex logo">
</picture>
# AnchorDex
[简体中文](README.zh-CN.md) · Changelog: [CHANGELOG.md](CHANGELOG.md)






</div>
A pull-based, self-verifying Markdown Memory Vault for AI coding agents — built on Node.js with zero external npm dependencies.
AnchorDex keeps permanent system prompts (`AGENTS.md`, `CLAUDE.md`, `GEMINI.md`) lean by storing durable engineering knowledge as scoped Markdown cards in `~/.memory-vault`. Agents retrieve only cards that match the active task, verify file and line anchors against disk before indexing, preserve immutable revision history, and share the same local knowledge store across **Antigravity**, **Claude Code**, **Codex CLI**, **Cursor**, and **DSH**.
> [!NOTE]
> All storage, indexing, search, anchor verification, and atomic file operations run locally on plain Markdown files inside `~/.memory-vault` (or `$MEMORY_VAULT_DIR`) without external databases or network services.
## Core Mechanisms
### 1. Compact Index & On-Demand Retrieval
- **`00-System/INDEX.md`**: Maintains a concise routing table and recent-card summary so agents inspect available topics without pre-loading full notes into every conversation.
- **`00-System/INDEX-full.md` & Hash-Isolated Cache**: Generates a full metadata catalog alongside a single-file JSON cache (`~/.cache/memory-vault/memory-search-cache-<vault-hash>.json`), checking per-card `statSync` metadata so direct file edits invalidate stale cache entries automatically.
### 2. Applicability Boundaries & Abstention
- **Explicit Scoping (`applies_when` / `not_when`)**: Every active card declares concrete trigger conditions in YAML frontmatter. Cards missing required boundaries are excluded from active auto-recall.
- **Layered Hybrid Search (`memory-search.mjs`)**: Scores EN/CJK queries with BM25+IDF weighting while separating strict synonym groups (`strict`), unidirectional weak associations (`weak`), and cross-domain generic terms (`generic`).
- **Abstention-First `PreInvocation` Hook**: Injects `0–3` relevant cards when specificity thresholds are met, and returns `{}` silently on unrelated prompts to keep context clean.
### 3. Anchor Verification & Write Guards
- **Disk-Backed Checks (`memory-verify.mjs`)**: Verifies referenced local file paths, `file:line` anchors, numeric counts, and `superseded_by` links against the filesystem.
- **Write Gate**: Writes or corrections with failing anchors return `isError: true` from MCP and skip updating `INDEX.md` and the search cache until resolved.
- **Direct-Edit Guards**: `PostToolUse` strips UTF-8 BOMs and stages modified paths without premature indexing; `Stop` validates staged writes and `[git-delta]` direct edits across both Git and non-Git vaults before rebuilding indexes.
### 4. Honest Metadata & Immutable History
- **Strict `verified_at` Discipline**: `memory_write` records `verified_at` only when explicitly provided after verification; `status: draft` omits `verified_at` automatically.
- **Non-Destructive Revisions (`memory_correct`)**: Prepends a dated `CORRECTION` block above preserved original text, or retires replaced entries via `--supersede <new-card>` (`status: superseded`).
- **Bi-Temporal States**: Supports `approved`, `draft`, `pending`, `archived` (searchable and exempt from 30-day environment staleness warnings), `superseded`, and `reverted`.
## Architecture
```text
User Prompt ─▶ PreInvocation Hook (autoRecall gate + cache) ─▶ Injects 0–3 scoped cards, or abstains
Agent Turn ─▶ MCP Server (stdio JSON-RPC 2.0) or CLI fallback resolved from SKILL_DIR
Direct Edit ─▶ PostToolUse Hook (strip UTF-8 BOM + stage touched path)
Turn End ─▶ Stop Hook (checks PostToolUse + [git-delta]; rebuilds index & commits baseline on 0 FAIL)
Shared Store ─▶ ~/.memory-vault/ (atomic rename via writeFileAtomic + per-vault SHA-1 cache)
```
### Supported Frameworks
| Client | Install Path (`install.mjs`) | MCP Registration | Vault Alignment |
| --- | --- | --- | --- |
| **Antigravity** | `~/.gemini/config/plugins/memory-vault` | `mcp_config.json` + 4 Hooks | `MEMORY_VAULT_DIR` + `plugin-config.json` |
| **Claude Code** | `~/.claude/skills/memory-vault` | `~/.claude.json` (`mcpServers.memory_vault`) | `MEMORY_VAULT_DIR` + `plugin-config.json` |
| **Codex CLI** | `~/.codex/skills/memory-vault` | `~/.codex/config.toml` (`[mcp_servers.memory_vault]`) | `MEMORY_VAULT_DIR` + `plugin-config.json` |
| **Cursor** | `~/.cursor/skills/memory-vault` | `~/.cursor/mcp.json` (`mcpServers.memory_vault`) | `MEMORY_VAULT_DIR` + `plugin-config.json` |
| **DSH** | `~/.dsh/skills/memory-vault` | Native Skill / CLI tools | `plugin-config.json` |
All card writes, index rebuilds, corrections, and installer config updates use `writeFileAtomic()` (same-directory temporary file + `renameSync` with transient lock retry) for safe concurrent access across clients.
## Installation
Requires **Node.js >= 20** (no `npm install` needed; **Node.js >= 22.15.0** is optional if you want `memory_harvest` to decompress `.zst`/`.zstd` session logs via built-in `zlib.zstdDecompressSync`).
### Auto-Detect Installed Clients
```bash
git clone https://github.com/ylx9000/anchordex.git
cd anchordex
# Install only into frameworks already present on this machine
node scripts/install.mjs --target auto
# Read-only status check: vault counts, MCP registration, and path alignment
node scripts/install.mjs --status
```
### Target-Specific & Custom Vault Options
```bash
node scripts/install.mjs --target antigravity
node scripts/install.mjs --target claude
node scripts/install.mjs --target codex
node scripts/install.mjs --target cursor
node scripts/install.mjs --target dsh
node scripts/install.mjs --target all
# Point all detected clients to a custom shared vault (syncs plugin-config.json)
node scripts/install.mjs --target auto --vault ~/notes/agent-memory
# Standalone Agent Skill only (no MCP config edits)
node scripts/install.mjs --target skill --skill-dir ~/.agents/skills/memory-vault --no-mcp
# Remove AnchorDex skill bundles and MCP registrations (preserves ~/.memory-vault)
node scripts/install.mjs --uninstall --target auto
```
### Agent Skills CLI (`npx skills`)
```bash
npx skills add ylx9000/anchordex
```
`npx skills add` installs the standalone Agent Skill and CLI fallback scripts (initializing `~/.memory-vault/` automatically on first use). Run `node scripts/install.mjs --target auto` if you also want automatic MCP server registration (`Claude Code`, `Codex CLI`, `Cursor`) and Antigravity lifecycle hooks (`PreInvocation`, `PostToolUse`, `Stop`).
## Customization & Session Harvesting
- **`00-System/routes.json`** ([routes.json.example](templates/vault/00-System/routes.json.example)): Pin custom task-to-card routes at the top of `INDEX.md`.
- **`00-System/synonyms.json`** ([synonyms.json.example](templates/vault/00-System/synonyms.json.example)): Extend `strict` alias groups, `weak` associations, and `generic` stop-guard terms.
- **`memory_harvest` (`memory-harvest.mjs`)**: Scans recent Claude Code, Codex CLI, Antigravity (`transcript_full.jsonl` / `transcript.jsonl`), and DSH logs for user corrections and repeated tool errors.
## Verification
```bash
npm test # Isolated E2E suite (MCP, hooks, atomic writes, multi-client install, cold start)
npm run test:eval # EN/CJK precision, abstention benchmark, and in-place cache invalidation
npm run check # UTF-8 no-BOM, LF line endings, version parity, and secret scan
npm run status # Read-only cross-client Vault status report
```
## License
[MIT](LICENSE) © ylx9000
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues