Skip to main content
Glama
README.md
# NEXUS Context (`nexus-context`)

[![CI](https://github.com/deusbr/nexus-context/actions/workflows/ci.yml/badge.svg)](https://github.com/deusbr/nexus-context/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Node.js >= 24](https://img.shields.io/badge/node-%3E%3D24.0.0-339933?logo=node.js&logoColor=white)](package.json)

Zero-dependency local context & evidence layer in **Node.js 24+ (`node:sqlite` + native FTS5)** for verifiable token reduction, deterministic evidence selection with expandable originals, and project-scoped versioned agent memory via MCP (`stdio`) and CLI.

## What It Solves

1. **Deterministic reduction with provenance (`select` / `expand`)**: Filters bulky logs (including numeric HTTP status codes such as `503` without relying on the word `ERROR`), compacts and projects JSON while preserving critical values, counts, and pagination metadata, slices code by line range, and stores recoverable originals (`ev_...`) with TTL, per-project LRU quotas, source-change detection (`sourceModified`), and prior secret redaction.
2. **Versioned memory and compact resume (`memory` / `checkpoint`)**: Strictly isolates records by `projectId`, tracks active decisions, rejected approaches with rationale, optimistic concurrency control (`expectedRevision`), idempotency (`eventId`), explicit historical queries, transactional forgetting across tables + FTS5 + blobs, and a resume card capped at ~500 tokens with branch/HEAD drift warnings.
3. **Ultra-lean MCP server (`stdio` JSON-RPC 2.0)**: Exposes **3 tools** (`nexus_evidence`, `nexus_memory`, `nexus_record`) to minimize catalog overhead, protects prompt caching with on-demand retrieval, and requires human approval (`candidate` -> `active`) by default.
4. **Honest metrics**: Separates filtered bytes, local token estimates, re-queries, and `p50/p95` latency, explicitly noting that actual billing cost depends on official provider telemetry.

## Prerequisites & Quick Start

Requires **Node.js >= 24.0.0** (for built-in `node:sqlite` and FTS5 support).

```powershell
# Filter logs for HTTP 503 with 3 context lines
node bin/nexus-context.js select --project my-app --file .\app.log --status 503 --context-lines 3 --max-tokens 300

# Expand the original content of a returned evidence item
node bin/nexus-context.js expand ev_<id> --project my-app --start-line 120 --end-line 150

# Record a decision and query active project memory
node bin/nexus-context.js memory record --project my-app --kind decision --title "Use SQLite FTS5" --content "Local lexical search without external services" --source "ADR-004"
node bin/nexus-context.js memory query --project my-app --query "FTS5"

# Save and resume a task checkpoint (<= 500 estimated tokens)
node bin/nexus-context.js checkpoint save --project my-app --task t-1 --objective "Fix 503" --pending "Validate retry"
node bin/nexus-context.js checkpoint resume --project my-app --task t-1

# Generate ready-to-use MCP client config (invokes node directly with bin/nexus-context-mcp.js, no cmd.exe)
node bin/nexus-context.js install-config openbot --project my-app
node bin/nexus-context.js install-config codex --project my-app
node bin/nexus-context.js install-config claude-code --project my-app
node bin/nexus-context.js install-config gemini-cli --project my-app
```

> **Windows Security:** Configs generated by `install-config` invoke `node.exe` directly with `bin/nexus-context-mcp.js` (without `cmd.exe` or `.cmd` wrappers), mitigating CVE-2024-24576, `&` command injection, and `%VAR%` expansion. When passing untrusted or arbitrary content to the CLI, prefer `stdin` or direct invocation via `node bin/nexus-context.js`.

## Documentation & Contract

- Technical contract: [CONTRACT.md](./CONTRACT.md)
- Integration guide (OpenBot, Codex CLI, Claude Code, Gemini CLI): [docs/INTEGRATION.md](./docs/INTEGRATION.md)
- Benchmark & validation reports: [Benchmark v1](reports/benchmark-v1.md) · [Core Engine Validation](reports/core-engine-validation.md)

## Tests & Benchmarks

```powershell
npm run check
npm test
node benchmarks/validate-report.js
node benchmarks/run-benchmark.js
```

## License

[MIT](./LICENSE) — Emerson Almeida (`@deusbr`).