Skip to main content
Glama
README.md
# Lydite

[![CI](https://github.com/foxsplendid/Lydite/actions/workflows/ci.yml/badge.svg)](https://github.com/foxsplendid/Lydite/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

[中文文档](README.zh.md) · [User Guide](docs/USER_GUIDE.md) · [Overview](docs/OVERVIEW.md) · [Privacy](docs/PRIVACY.md)

**Lydite** (*Lydian stone*, the siliceous black touchstone used by goldsmiths to separate real gold from counterfeits) is a local-first, anchor-verified memory kernel and MCP server for AI coding agents (`claude`, `codex`, and any MCP-compatible host).

Instead of letting agents silently consolidate unverified guesses or external prompt injections into long-term memory ("memory laundering"), Lydite binds **6 structured memory kinds** (`state`, `decision`, `fact`, `preference`, `todo`, `procedure`) to **4 epistemic origins** (`user_stated`, `tool_verified`, `agent_inferred`, `external_doc`), enforces repository file anchors and bi-temporal validity, and injects only confirmed, non-drifted context.

![Lydite touchstone memory loop](docs/assets/lydite-loop.svg)

## Why Lydite?

Long-horizon multi-agent coding breaks down when a new session treats stale or unvetted notes as current truth:

- **Memory laundering**: unreviewed web/RAG snippets (`external_doc`) or speculative model summaries get saved and later recalled as authoritative user decisions.
- **Silent code drift**: refactored files invalidate earlier architecture facts and runbooks, yet flat memory stores keep serving obsolete instructions.
- **Startup context bloat**: dumping raw transcripts or verbose procedures into every prompt wastes tokens and degrades reasoning.

Lydite runs on **zero third-party Python dependencies** (Python `>= 3.11` stdlib + SQLite `>= 3.34` FTS5 `trigram`). All databases live locally under `$LYDITE_HOME` (`~/.local/share/lydite` on macOS/Linux, `%LOCALAPPDATA%\Lydite` on Windows).

## Core capabilities

| Capability | Mechanism & Surface |
| --- | --- |
| **Touchstone anti-laundering gate** | Pre-hash secret/PII redaction, mandatory `draft` staging on MCP `propose_entries`, `derived_from` origin clamping, 4-gate deterministic `--auto-verify` for anchored `tool_verified` claims, and permanent `rejected` tombstones. |
| **Tri-axis grounded invalidation** | Bi-temporal windows (`valid_from` / `valid_until` / `event_time` + `--as-of`), LF-normalized repository file-blob & path anchors, AGM explicit retraction (`retracts`), and cycle-safe `depends_on` cascade (`lydite/invalidation.py`). |
| **Two-tier lock-free recall** | Prompt-cache-friendly `?mode=ro` Tier-1 startup briefing (`lyd brief` / `SessionStart`, `<= 6,000` chars) + Tier-2 stdio MCP (`lyd mcp`: intent-routed hybrid RRF `search`, `recall_procedures`, `get_entry`, `propose_entries`, `record_outcome`). |
| **Skills bridge & clean exit** | Export verified `procedure` entries into validated `SKILL.md` files (`lyd export-skill`), import browser chat archives (`lyd import-chat`), and run lossless JSONL export/import or guarded `.jsonl.gz` cold archival (`lyd gc`). |

## 30-second quick start

Install with `uv` (or `pip install -e .` inside a Python `>= 3.11` virtual environment):

```bash
uv tool install .
# Or inside a local virtualenv:
python3 -m venv .venv && ./.venv/bin/pip install -e .
```

Initialize your repository and wire Claude Code / Codex hooks & MCP in one step:

```bash
# Preview host config diffs first (dry-run), then apply with automatic *.bak backups:
lyd setup all
lyd init --setup all
lyd doctor
```

### Daily workflow

1. **Work normally in `claude` or `codex`** — `SessionStart` injects a lock-free confirmed Tier-1 briefing; agents recall procedures and propose anchored `draft` memories over MCP.
2. **`lyd review -i`** — single-keypress interactive triage (`y` confirm, `n` reject, `v` revalidate drifted anchors, `s` skip, `q` quit), or run `lyd review --project <id> --auto-verify --run` for deterministic anchor verification.
3. **`lyd maintain`** — drain queued `SessionEnd` transcripts into redacted `transcripts.db`, scan code anchors for drift, and sync optional local embeddings.

## `lyd` CLI overview

| Group | Commands |
| --- | --- |
| **Onboarding & health** | `lyd init`, `lyd setup`, `lyd doctor`, `lyd config embed` |
| **Daily workflow** | `lyd status`, `lyd review` (`-i` / `--auto-verify`), `lyd maintain` |
| **Search & recall** | `lyd search`, `lyd show`, `lyd brief` |
| **Transcripts & web chat** | `lyd import-chat`, `lyd capture`, `lyd sessions` |
| **Skills, views & archival** | `lyd export-skill`, `lyd render-note`, `lyd gc`, `lyd export`, `lyd import`, `lyd mcp` |

## Optional browser exporter (`browser-capture/`)

When an architectural discussion happens in ChatGPT or Claude on the web, the standalone Manifest V3 extension under [`browser-capture/`](browser-capture/README.md) (**Lydite Capture**) exports selected conversations to a local `.zip` with zero third-party JS libraries. Import it straight into Lydite's redacted fallback transcript store with:

```bash
lyd import-chat ~/Downloads/lydite-chatgpt-20261205T000000Z.zip --project my-repo
```

## Verification & evaluation

```bash
python -m unittest discover -s tests -v
python eval/continuity_eval.py
python eval/ablation_runner.py --include-m4-plus
python -B browser-capture/tests/test_extension.py
python tools/check_public_tree.py
```

## License

MIT. See [LICENSE](LICENSE).