holix-rs 1.4.0

Local-first context-folding index runtime with SQLite WAL/FTS5 persistence, Orion HNSW semantic routing, BlobSource hydration, and AST/CSV/XLSX/EML slicers.
Documentation
# holix


[![Crates.io](https://img.shields.io/crates/v/holix-cli.svg)](https://crates.io/crates/holix-cli)
[![Docs.rs](https://docs.rs/holix-rs/badge.svg)](https://docs.rs/holix-rs)
[![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](LICENSE-MIT)
[![Verified: Lean 4 + Kani](https://img.shields.io/badge/verified-Lean%204%20%2B%20Kani-success.svg)](formal/)

`holix` (Holographic + Index) is a local-first context-folding engine and semantic memory MCP server in Rust for code, prose, tables, email, and PDFs, backed by SQLite FTS5, Orion HNSW, and Lean 4/Kani proofs. Unlike standard RAG pipelines that copy files and stuff raw chunks into your prompt, `holix` folds assets into a local SQLite + Orion index and only hydrates exact byte spans on demand.

## Core Problem


LLM agents burn through context windows when they read raw files directly into prompts. `holix` avoids that by slicing `.rs`, `.py`, `.md`, `.yml`, `.pdf`, `.csv`, `.xlsx`, and `.eml` files into folded projections inside a `.holix/index.db` SQLite WAL and `FTS5` database. Every query enforces a strict `max_token_budget` and keeps raw byte reads behind a fail-closed hydration gate capped at 4 MiB with FNV-1a content hash checks, which gives predictable token usage without losing exact byte provenance.

## Architecture


The workspace splits formal invariants, runtime indexing, and transport into three layers so that proof obligations stay isolated from I/O and FFI.

| Layer | Crates / Modules | Responsibility | Verification |
| :--- | :--- | :--- | :--- |
| Layer 1 | `holix-core-verified` | Pure `#![no_std]` math for coordinate bounds, token packing, concept DAG acyclicity (`src_rank < dst_rank`), and hydration gates | Charon/Aeneas extraction into Lean 4 (`HolixSpec`, `HolixProofs`, `--wfail`, 0 `sorry`) |
| Layer 2 | `holix-rs` | SQLite WAL + `FTS5` index persistence, `BlobSource` lazy hydration, push `ingest_bytes`, Tree-sitter AST, YAML, CSV/XLSX, EML slicers, pure-Rust PDF page text extraction (`lopdf`), TextTiling prose folding, and `OrionRouter` (`orion-vdb`) | Unit tests and Kani bounded model checking (`default-unwind = 1`) |
| Layer 3 | `holix-cli` | CLI binary (`holix`) and MCP `2026-07-28` JSON-RPC stdio server (`holix serve`) | Integration and piped stdio E2E tests |

## Complexity


Where `B` is raw corpus bytes, `N` is indexed entries (folds, edges, blackboard, annotations), `D` is embedding dimension (`64` default `FeatureHashEmbedder`, `1 byte/dim` SQ8 in `orion`), `ef` is the HNSW search beam width, `K` is top-K candidates, and `S` is hydrated span bytes (`<= 4 MiB`):

| Operation | Time | Space / Disk |
| :--- | :--- | :--- |
| **`holix ingest` (full)** | `O(B + N * D * log N)` | Disk `O(N * D)`, zero raw file copies |
| **`holix ingest` (incremental)** | `O(B_dirty + n_dirty * D * log N)` | Appends to `.vdb.delta` without rewriting `.vdb` |
| **`holix_discover` (warm)** | `O(ef * D * log N + K log K)` | RAM `O(K + ef)` per query |
| **`holix_hydrate` (byte spans)** | `O(S)` bounded | RAM `O(S) <= 4 MiB` (Layer 1 fail-closed gate) |



## Storage Decoupling (`BlobSource` and `ingest_bytes`)


When `holix-rs` runs inside a backend or object-store pipeline, it should not assume files live on a local filesystem. `holix_rs::ingest_bytes` accepts an in-memory byte slice, a logical URI, an optional external `locator`, an `immutable` flag, and faceted `BTreeMap` tags. Later reads hydrate exact byte ranges through `&dyn BlobSource` (`content_len`, `read_range`, `read_all`), skipping full-blob FNV-1a hashing on immutable blobs so hydrating a 200-byte span never buffers a 50 MB PDF in RAM.

```rust
use std::collections::BTreeMap;
use holix_rs::hydrate::{hydrate_projection_with_source, BlobSource, HydrateError};
use holix_rs::ingest::ingest_bytes;
use holix_rs::persist::IndexSnapshot;
use holix_rs::store::AssetRecord;

struct MemoryStore(Vec<u8>);

impl BlobSource for MemoryStore {
    fn content_len(&self, _asset: &AssetRecord) -> Result<u64, HydrateError> {
        Ok(self.0.len() as u64)
    }
    fn read_range(&self, _asset: &AssetRecord, offset: u64, len: usize) -> Result<Vec<u8>, HydrateError> {
        let start = offset as usize;
        Ok(self.0[start..start + len].to_vec())
    }
    fn read_all(&self, _asset: &AssetRecord) -> Result<Vec<u8>, HydrateError> {
        Ok(self.0.clone())
    }
}

fn example() -> Result<(), Box<dyn std::error::Error>> {
    let payload = b"# Agreement\n\nClause 4: Net 30 payment terms.\n";
    let mut snap = IndexSnapshot::default();
    let mut tags = BTreeMap::new();
    tags.insert("project".into(), "core".into());

    let asset_id = ingest_bytes(
        &mut snap,
        "workspace/core/agreement.md".into(),
        Some("s3://workspace/core/agreement.md".into()),
        "md",
        payload,
        true,
        tags,
    )?;

    let (store, _, _, _) = snap.restore()?;
    let proj_id = store.projections_for_asset(asset_id)[0].id;
    let slice = hydrate_projection_with_source(&store, &MemoryStore(payload.to_vec()), proj_id, false, 4096, None)?;
    assert!(!slice.bytes.is_empty());
    Ok(())
}
```

## Feature Flags


| Crate | Feature | Purpose |
| :--- | :--- | :--- |
| `holix-rs` | `sqlite` *(default)* | Enables SQLite WAL snapshot persistence and `FTS5` `projections_fts` search |
| `holix-rs` | `semantic` *(default)* | Enables `orion-vdb` HNSW vector routing (`.holix/router.vdb`) and hybrid RRF discovery |
| `holix-rs` | `pdf` *(enabled in `holix-cli`)* | Pure-Rust per-page PDF text extraction (`lopdf`), structural outline, and `#p:N` hydration |
| `holix-rs` | `tree-sitter-ast` | Slices `.rs`, `.py`, and `.md` via Tree-sitter syntax trees |
| `holix-rs` | `csv-xlsx` | Slices `.csv` and `.xlsx` (`calamine`) into 50-row chunks with searchable header and cell previews |
| `holix-rs` | `email` | Slices `.eml` headers (folded RFC 5322 lines) and text bodies while stubbing base64 MIME attachments |

`holix-rs` with `--no-default-features` stays strictly zero-dependency.

## Key Features


- **Federated Mounts:** Upstream repositories mount read-only (`ro`) and a global Markdown DMZ repository mounts read-write (`rw`) through `~/.holix/registry.toml` and `.holix/mounts.toml`. Each mount keeps its own SQLite connection and namespace, which prevents asset ID collisions and `SQLITE_BUSY` contention.
- **Portable `holix://` URIs:** References use `holix://<repo>/<rel-path>#<anchor>` with `#b:start-end`, `#p:page`, `#t:start-end`, `#symbol`, and `@concept/<label>` anchors. Path normalization strips Windows verbatim prefixes and matches relative paths across Windows and WSL2, with `stale_anchor` fallback when line offsets drift.
- **Passive Delta Sync:** Reads run lazy `mtime_ms` and root checks on disk instead of spawning background daemons or `notify` watcher threads. Edits, new files, and deletions sync on the next MCP read, and `immutable == true` object-store assets skip filesystem `metadata` checks altogether.
- **Sub-2 ms `FTS5` and Faceted Tag Filtering:** `projections_fts` indexes projection labels and asset URIs atomically inside SQLite transactions using quoted prefix queries (`"TASK-9042"*`) and key-value `tags` filters.
- **Global DMZ Issue Tracking:** `holix dmz init <path>` scaffolds a Git-ready Markdown repository, and `holix_report` atomically writes YAML-frontmatter `.md` reports into an `rw` DMZ mount before indexing them locally. Writes to `ro` mounts fail closed with `ReadOnlyMountBlocked`.

## MCP Tools (`holix serve`)


| Tool | Purpose |
| :--- | :--- |
| `holix_ingest` | Index files or directories into `.holix/index.db` and `.holix/router.vdb` (`no_semantic` opt-out) |
| `holix_discover` | Run token-budgeted hybrid search across local and mounted repos (`repo`, `include_mounts`, `tags`, `ref`, `expand_hops`) |
| `holix_unfold` | Expand folded projection layers within `max_token_budget` |
| `holix_hydrate` | Perform fail-closed raw byte or `#p:N` page reads (`discovery_mode: false`, `ref` self-healing) |
| `holix_annotate` | Write anchored `warn`/`override`/`info` notes on `holix://` URIs, `ConceptNode` entries, and upward edges |
| `holix_link` | Manage cross-document semantic edges (`create`, `list`, `auto_entities`) |
| `holix_blackboard` | Store and query session or project memory (`write`, `query`, `resolve`, `supersede`) |
| `holix_concepts` | Query full concept `gist`, upward edges, `evidence_proj_ids`, and blackboard notes |
| `holix_report` | Write and auto-ingest cross-repo bug or workaround `.md` reports to an `rw` DMZ mount |

## CLI Reference and Quickstart


**Prebuilt Binaries:** Download `v1.4.0` archives and `.sha256` checksums for Linux (`x86_64`, `aarch64`), macOS (`x86_64`, `aarch64`), and Windows (`x86_64`) from [GitHub Releases](https://github.com/steveSujo/holix/releases/latest).

Or install from crates.io:

```bash
cargo install holix-cli --locked
```

Or from a local checkout:

```bash
cargo install --path crates/holix-cli --locked
```

| Command | Action |
| :--- | :--- |
| `holix ingest . [--no-semantic]` | Slice and index the current repository into `.holix/index.db` and `.holix/router.vdb` |
| `holix reindex` | Clean-rebuild `.holix/router.vdb` from the current `.holix/index.db` |
| `holix find <query> [--prefix <p>] [--tag k=v] [--json]` | Run one-shot `FTS5` + tag queries without starting MCP JSON-RPC |
| `holix status` | Print indexed asset, projection, concept, edge, and blackboard counts |
| `holix dmz init <dmz-path>` | Initialize a Git-ready DMZ Markdown repository |
| `holix mount dmz <dmz-path> --rw --global` | Register the DMZ mount read-write in `~/.holix/registry.toml` |
| `holix mount <alias> <upstream-path> --global` | Register an upstream repository mount read-only |
| `holix mounts` | List merged global and local mounts |
| `holix serve` | Start the MCP `2026-07-28` stdio server |
| `holix skill` | Emit the `SKILL.md` agent usage prompt |

Quick CLI walkthrough:

```bash
holix ingest .
holix find "TASK-9042" --json
```

Example output:

```json
[{"proj_id":42,"uri":"records.csv","label":"csv rows:1-2 | id,owner,status,priority | TASK-9042,platform-core,open,p1","coord":{"kind":"text_range","start_char":0,"end_char":72}}]
```

## Needle-in-a-Haystack Benchmark


The in-repo benchmark measures end-to-end discovery, exact span hydration, semantic prose retrieval, and drifted-anchor self-healing across a `168,688`-token corpus built from `40` noisy local Markdown decoys alongside planted needles in local `.csv`, local `.eml` (with a base64 PDF attachment), local `.txt` (unstructured prose queried with `"customs tariffs mitigated"` via `OrionRouter`), and a mounted `.md` repository (`docs`).

| Metric | Measured Value (`--release`) |
| :--- | :--- |
| Raw corpus tokens | `168,688` |
| `holix_discover` tokens (4 queries) | `463` |
| `holix_hydrate` tokens (4 spans) | `150` |
| Total `holix` tokens (`discover + hydrate`) | `613` (`99.64%` reduction) |
| `Recall@budget` (local + semantic prose + mounted) | `4 / 4` (`100%`) |
| Total latency (`holix serve` round-trips) | `1,420 ms` |
| Drifted-anchor self-heal | Pass (`holix://docs/addendum.md#b:0-10`) |

Reproduce the live release benchmark locally:

```bash
cargo test --release -p holix-cli --test mcp_e2e niah_benchmark_measures_recall_at_budget_and_self_heal -- --nocapture
```

## External Benchmarks ([`holix-bench`]https://github.com/steveSujo/holix-bench)


External suites in [`steveSujo/holix-bench`](https://github.com/steveSujo/holix-bench) test `holix` (`--release`, warm `OrionRouter`) across multi-format workspaces, `32k`–`131k` Paul Graham essay haystacks, and `AmazonScience/document-haystack` PDFs ([`results/v1.3.0.md`](https://github.com/steveSujo/holix-bench/blob/main/results/v1.3.0.md), [`results/v1.4.0.md`](https://github.com/steveSujo/holix-bench/blob/main/results/v1.4.0.md)):

| Suite | Raw Input | Holix Tokens | Reduction | Recall | MCP Latency |
| :--- | :--- | ---: | ---: | :---: | ---: |
| [`mixed_workspace`]https://github.com/steveSujo/holix-bench/blob/main/suites/mixed_workspace/run.py | `161,574` tokens (`.md`/`.csv`/`.eml` + mount) | `101` | `99.94%` | `3/3` | `534.2 ms` |
| [`text_niah` (`32k`)]https://github.com/steveSujo/holix-bench/blob/main/suites/text_niah/run.py | `32,902` tokens | `23` | `99.93%` | `1/1` | `89.7 ms` |
| [`text_niah` (`65k`)]https://github.com/steveSujo/holix-bench/blob/main/suites/text_niah/run.py | `65,674` tokens | `26` | `99.96%` | `1/1` | `88.9 ms` |
| [`text_niah` (`131k`)]https://github.com/steveSujo/holix-bench/blob/main/suites/text_niah/run.py | `131,212` tokens | `23` | `99.98%` | `1/1` | `110.1 ms` |
| [`text_niah` (`prose_paraphrase`)]https://github.com/steveSujo/holix-bench/blob/main/suites/text_niah/run.py | `32,821` tokens (paraphrase in haystack) | `86` | `99.74%` | `1/1` | `124.4 ms` |
| [`pdf_haystack` (`synthetic`)]https://github.com/steveSujo/holix-bench/blob/main/suites/pdf_haystack/run.py | `0.47 MB` (`23` PDFs, `690` pages) | `816` | — | `3/3` | `152.7 ms` |
| [`pdf_haystack` (`document-haystack`, `v1.4.0`)]https://github.com/steveSujo/holix-bench/blob/main/suites/pdf_haystack/run.py | `54.14 MB` (`6` PDFs, `> 4 MiB` each) | `2,121` (`1,509` discover + `6/6` `#p:N` hydrate) | — | `6/6` | `3,673.2 ms` (total 6 queries + 6 hydrations) |

In `v1.4.0`, `holix` decodes PDFs page-by-page via `lopdf` (`feature = "pdf"`), folds extracted text through `prose.rs`, and hydrates `#p:N` pages through Layer 1's `allow_raw_hydration` gate (`6/6` hydrated, `0` `SpanExceedsMaxBytes` errors).

## Verification


Run Rust lints, default-feature checks, and workspace tests:

```bash
cargo clippy --workspace --all-features --all-targets -- -D warnings
cargo test --workspace --all-features
cargo test -p holix-rs --no-default-features
```

Run the WSL2 formal verification pipeline (`HolixSpec`, `HolixProofs`, Charon/Aeneas sync, and Kani):

```powershell
scripts\verify.ps1 -Mode dev
scripts\verify.ps1 -Mode release
```

The WSL2 formal pipeline expects `elan`, `cargo-kani`, `charon`, and `aeneas` (default `$HOME/aeneas`, overridable via `AENEAS_ROOT`).

## License and Author


Dual-licensed under `MIT OR Apache-2.0` ([LICENSE-MIT](LICENSE-MIT), [LICENSE-APACHE](LICENSE-APACHE)).

Written by Steve Sujo Pulikottil.