Metadata-Version: 2.5
Name: lorexplore
Version: 0.1.0a2
Summary: Local-first codebase intelligence, git archaeology, temporal co-change coupling, and progressive-disclosure MCP/CLI engine.
Project-URL: Homepage, https://github.com/Modzybear/lorexplore
Project-URL: Repository, https://github.com/Modzybear/lorexplore
Project-URL: Issues, https://github.com/Modzybear/lorexplore/issues
Author: Andrew Burnett
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: ast,cli,code-intelligence,fts5,git,mcp,sqlite,tree-sitter
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Version Control :: Git
Requires-Python: >=3.11
Requires-Dist: click<9,>=8.5.0
Requires-Dist: mcp<3,>=2.3.0
Requires-Dist: tree-sitter-bash>=0.25.1
Requires-Dist: tree-sitter-go>=0.25.0
Requires-Dist: tree-sitter-javascript>=0.23.0
Requires-Dist: tree-sitter-python>=0.23.0
Requires-Dist: tree-sitter-rust>=0.23.0
Requires-Dist: tree-sitter-typescript>=0.23.0
Requires-Dist: tree-sitter<0.28,>=0.25.0
Provides-Extra: dev
Requires-Dist: bandit[toml]>=1.9.4; extra == 'dev'
Requires-Dist: complexipy>=2.0.0; extra == 'dev'
Requires-Dist: hypothesis>=6.0; extra == 'dev'
Requires-Dist: mypy>=2.4.1; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.17.0; extra == 'dev'
Provides-Extra: polyglot
Requires-Dist: tree-sitter-language-pack<2,>=1.28.0; extra == 'polyglot'
Description-Content-Type: text/markdown

# lorexplore (`lxp`)

Local-first codebase intelligence, git archaeology, temporal co-change coupling, and progressive-disclosure MCP/CLI engine.

Single SQLite WAL + FTS5 index per repository. Zero cloud services, zero LLM API calls required for indexing or retrieval, strict token budgets, and real-time dirty working-tree overlay.

> **Status:** Alpha (`0.1.0a*`). CLI flags and MCP tool schemas may evolve before `0.1.0`.

## Architecture

Static AST search alone misses *why* code exists and which files silently break together. `lorexplore` joins four local layers into one queryable SQLite WAL index:

```mermaid
flowchart LR
    subgraph Inputs["Repository Inputs (Local Only)"]
        SRC["Source Files\n(Python AST + 6 Tree-sitter Grammars)"]
        GIT["Git History\n(Non-Squashed Commits, Renames, Lore Trailers)"]
        DOCS["Plans, ADRs & Runbooks\n(Bi-Temporal Supersession Chains)"]
        DIRTY["Dirty Working Tree\n(Uncommitted Edits Overlay)"]
    end

    subgraph Engine["SQLite WAL + FTS5 Engine (<= 64 MiB Cache, 0-mmap)"]
        AST["Symbols & Static Call Graph\n(EXTRACTED vs HEURISTIC)"]
        PPR["Personalized PageRank\n(Query & Focus-Seeded)"]
        CO["Temporal Co-Change Graph\n(90d Decay, <= 30-File Filter)"]
        FTS["Acronym-Safe FTS5\n(BM25 + RRF Fusion)"]
    end

    subgraph Surface["Progressive-Disclosure Interface"]
        CLI["CLI: lorexplore / lxp\n(Markdown & --json)"]
        MCP["MCP Server (MIT mcp SDK)\n(stdio & Localhost Streamable HTTP)"]
    end

    SRC --> AST
    SRC --> FTS
    AST --> PPR
    GIT --> CO
    GIT --> FTS
    DOCS --> FTS
    DIRTY -. "Live Overlay" .-> FTS
    DIRTY -. "Live Overlay" .-> PPR

    PPR --> CLI
    CO --> CLI
    FTS --> CLI
    PPR --> MCP
    CO --> MCP
    FTS --> MCP
```

1. **Structural AST & Call Graph:** Python stdlib `ast` (with error-tolerant `tree-sitter-python` fallback for broken dirty files) + offline official MIT Tree-sitter grammars for TypeScript/TSX, JavaScript, Go, Rust, and Bash.
2. **Git Archaeology & Temporal Coupling:** Non-squashed commit mining, Lore commit trailers (`Plan:`, `Directive:`, `Rejected:`), `git mv` rename lineage, symbol-level diff tracking (`-U0`), and 90-day time-decayed co-change coupling (excluding bulk `>30`-file sweeps).
3. **Bi-Temporal Docs & ADRs:** Indexes Plans/ADRs/runbooks, resolves `Supersedes:` chains, and flags drifted docs whose referenced files were deleted or heavily churned.
4. **FTS5 + Personalized PageRank:** Acronym-safe BM25 + Reciprocal Rank Fusion (RRF) with live dirty working-tree overlay.

## Progressive-Disclosure Workflow

Instead of dumping full files into an LLM context window, agents orient in bounded hops and check blast radius before editing:

```mermaid
sequenceDiagram
    participant Agent as Coding Agent / Dev
    participant LXP as lorexplore (CLI / MCP)

    Agent->>LXP: 1. repo_map(focus_paths, max_tokens=1024)
    LXP-->>Agent: PageRank-ranked files + top signatures
    Agent->>LXP: 2. locate(query="token_bucket", scope="all")
    LXP-->>Agent: RRF hits across code, commits & ADRs (with cursor)
    Agent->>LXP: 3. read_symbol(targets, mode="skeleton")
    LXP-->>Agent: Compact AST signatures (~70% token savings)
    Agent->>LXP: 4. explain_why(target="src/auth/policy.py")
    LXP-->>Agent: Lore directives, fix/revert history, rename lineage & ADRs
    Agent->>LXP: 5. co_change_impact(target="working_tree")
    LXP-->>Agent: Static callers + implicit temporal co-change companions
    Note over Agent,LXP: Targeted edit -> lxp draft-lore -> commit with Lore trailers
```

## Install

```bash
# Run directly via uvx (alpha pre-release)
uvx --prerelease=allow lorexplore --help

# Install into a project environment (alpha pre-release)
uv pip install --prerelease=allow lorexplore

# Local development install
uv sync --group dev
```

## Quickstart

```bash
# 1. Build local index (~/.cache/lorexplore/<repo_hash>.db)
lxp sync

# 2. Keep index fresh automatically on commit, merge, and checkout
lxp install-hooks

# 3. Progressive-disclosure queries (add --json for machine output)
lxp map --focus src/auth --max-tokens 1024
lxp locate "token_bucket"
lxp read src/auth/policy.py --mode skeleton
lxp trace src/auth/policy.py --direction callers
lxp why src/auth/policy.py
lxp impact working_tree
lxp history "TOKEN_TTL" --fixes-only
lxp stale
lxp timeline --target src/auth --since 30d
lxp draft-lore
```

## Agent Skills

Install the packaged progressive-disclosure `SKILL.md` so coding agents orient with `map`/`locate`/`read`, check `why`/`impact` before editing, and run `impact working_tree` + `draft-lore` + `stale` before committing:

```bash
# Workspace-local skill (.agents/skills/lorexplore/SKILL.md)
lxp init-skill

# Global skill for a specific agent runtime
lxp init-skill --target antigravity --global   # ~/.gemini/config/skills/lorexplore/SKILL.md
lxp init-skill --target claude --global        # ~/.claude/skills/lorexplore/SKILL.md
lxp init-skill --target cursor --global        # ~/.cursor/skills/lorexplore/SKILL.md

# Preview without writing
lxp init-skill --print
```

## MCP Server

Runs on the official MIT `mcp` SDK (`MCPServer`). Defaults to zero-socket `stdio`; `--read-only` opens SQLite read-only and omits `record_decision`.

```bash
# Recommended for IDE / agent clients (stdio, zero sockets)
lxp --repo /path/to/repo --read-only serve

# Optional localhost-only stateless Streamable HTTP (DNS-rebinding Host/Origin guard)
lxp --repo /path/to/repo --read-only serve --transport streamable-http --host 127.0.0.1 --port 8770
```

Example MCP client configuration:

```json
{
  "mcpServers": {
    "lorexplore": {
      "command": "lxp",
      "args": ["--repo", "/path/to/repo", "--read-only", "serve"]
    }
  }
}
```

### Tool Surface

| Tool | Purpose | Read-Only |
| :--- | :--- | :---: |
| `repo_map` | Personalized PageRank file/signature skeleton map | Yes |
| `locate` | RRF search across symbols, commits, and ADRs | Yes |
| `read_symbol` | Batch AST skeletons or exact line/symbol bodies | Yes |
| `trace_graph` | N-hop static callers, callees, imports, and tests | Yes |
| `explain_why` | Commits, Lore trailers, rename lineage, ADRs, and co-changes | Yes |
| `co_change_impact` | Pre-edit blast radius (static callers + temporal co-change) | Yes |
| `search_history` | FTS5 search over commits, Lore trailers, and ADRs | Yes |
| `audit_stale_docs` | Flags active docs with deleted or heavily churned file refs | Yes |
| `build_timeline` | Chronological SHA-anchored feed for onboarding or synthesis | Yes |
| `record_decision` | Records a bi-temporal decision and emits Lore trailers | No |

## Lore Commit Trailers

`lorexplore` indexes structured commit trailers automatically:

```text
Plan: Plan 02
Directive: Enforce token_bucket bounds; never re-enable legacy fixed fallback.
Rejected: Unbounded burst quota.
Verified-By: pytest tests/test_policy.py
```

Generate a pre-commit trailer draft and missed-companion check from your staged diff with `lxp draft-lore`.

## Quality & Security Gates

Every commit is verified across Linux, macOS, and Windows (Python 3.11–3.14):

- **Static & Complexity:** `ruff` (lint, format, McCabe `C901 <= 12`, branches `<= 12`, statements `<= 50`) + `complexipy` (Sonar cognitive complexity `<= 15`).
- **Type Safety:** `mypy --strict` + Astral `ty`.
- **Security & Compliance:** `bandit` SAST, `pip-audit` CVE scan, and automated runtime permissive license allowlist (`MIT`, `Apache-2.0`, `BSD`, `ISC`, `PSF-2.0`).
- **Testing & Performance:** `>= 90%` combined line and branch coverage (`pytest --cov-branch`), Hypothesis property fuzzing, `<= 50 ms` p95 query latency, `<= 150 MB` peak RSS, and `< 50 ms` lazy CLI cold start.
- **Releases:** Dynamic `hatch-vcs` versioning with automated PyPI OIDC Trusted Publishing and CycloneDX SBOM generation on merges to `main`.

## Optional Extras

- **`lorexplore[polyglot]`**: Opt-in `tree-sitter-language-pack` for long-tail languages beyond the 6 offline core grammars.
- **`eval` dependency group**: Offline agentic evaluation & Pareto prompt optimization (`Inspect AI`, `DSPy` + `GEPA`, local SQLite `MLflow`).

## License

Licensed under [Apache-2.0](LICENSE).
