Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.git
.venv
venv
.mimir
**/__pycache__
**/*.pyc
**/*.egg-info
dist
build
client
backstage-plugin
docs
tests
.github
.claude
.DS_Store
68 changes: 26 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,56 @@ on:
push:
branches: [main, develop]

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Tests
name: Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/checkout@v7

- uses: actions/setup-python@v5
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install dependencies
run: pip install -e ".[dev]"

- name: Run tests
run: pytest --tb=short -q

guardrails:
name: Architectural Guardrails
build:
name: Build verification
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
fetch-depth: 0
fetch-depth: 0 # setuptools-scm derives the version from git tags

- uses: actions/setup-python@v5
- uses: actions/setup-python@v7
with:
python-version: "3.13"

- name: Install Mimir
run: pip install -e .
- name: Install build tools
run: pip install build twine

- name: Build code graph
run: mimir index
- name: Build server package
run: python -m build --outdir dist/

- name: Run guardrail check
id: guardrails
run: |
EXIT_CODE=0
git diff origin/${{ github.base_ref }}...${{ github.event.pull_request.head.sha }} | \
mimir guardrail check --diff - \
--rules mimir-rules.yaml \
--base origin/${{ github.base_ref }} \
--head ${{ github.event.pull_request.head.sha }} \
--output github-pr-comment \
--report-file guardrail-report.md \
|| EXIT_CODE=$?
echo "exit_code=$EXIT_CODE" >> $GITHUB_ENV
cat guardrail-report.md >> $GITHUB_STEP_SUMMARY

- name: Comment on PR
if: always() && hashFiles('guardrail-report.md') != ''
uses: marocchino/sticky-pull-request-comment@v2
with:
header: mimir-guardrails
path: guardrail-report.md
- name: Build client package
run: python -m build --outdir dist/
working-directory: client

- name: Fail if violations
if: env.exit_code != '0'
run: exit 1
- name: Check package metadata
run: twine check --strict dist/* client/dist/*
46 changes: 34 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,41 @@ on:
- "v*"

permissions:
contents: write
id-token: write
contents: read

jobs:
test:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- uses: actions/setup-python@v7
with:
python-version: "3.13"
cache: pip

- name: Install dependencies
run: pip install -e ".[dev]"

- name: Run tests
run: pytest --tb=short -q

build:
name: Build packages
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
fetch-depth: 0

- uses: actions/setup-python@v5
- uses: actions/setup-python@v7
with:
python-version: "3.13"

- name: Install build tools
run: pip install build
run: pip install build twine

- name: Build server package
run: python -m build --outdir dist/
Expand All @@ -32,8 +49,11 @@ jobs:
run: python -m build --outdir dist/
working-directory: client

- name: Check package metadata
run: twine check --strict dist/* client/dist/*

- name: Upload artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: dist
path: |
Expand All @@ -42,13 +62,15 @@ jobs:

github-release:
name: Create GitHub Release
needs: build
needs: [publish-server, publish-client]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7

- name: Download artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
name: dist
path: artifacts
Expand All @@ -63,7 +85,7 @@ jobs:
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ github.ref_name }}
name: Mimir ${{ steps.version.outputs.version }}
Expand All @@ -79,7 +101,7 @@ jobs:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
name: dist
path: artifacts
Expand All @@ -101,7 +123,7 @@ jobs:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
name: dist
path: artifacts
Expand Down
40 changes: 25 additions & 15 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ pip install -e ".[dev]"
# Run tests (the venv lives at ./.venv — activate it or call it directly)
.venv/bin/pytest
# or: source .venv/bin/activate && pytest
.venv/bin/pytest tests/test_guardrail_service.py -k test_name # Single test/module

# No linter or formatter is configured (no ruff/black/mypy). Tests are the only gate.
# pytest runs in asyncio_mode = "auto" — async tests need no @pytest.mark.asyncio.

# CLI usage
mimir init # Create mimir.toml config
mimir index # Build/update semantic code graph
mimir search "query" # Search and assemble context
mimir serve # Start MCP server (stdio)
mimir serve --http # Start shared HTTP server (port 8421)
mimir quality # Analyze graph connectivity gaps
mimir indexer run # Build and publish an index version
mimir query search "query" # Search the active published index
mimir query serve # Start MCP server (stdio)
mimir query serve --http # Start shared HTTP server (port 8421)
mimir query status # Show the active index version and graph counts

# Guardrails
mimir guardrail init # Generate example rules + agent policy
Expand All @@ -48,10 +52,10 @@ Mimir-Approved-Reason: legal signoff ticket #4821

Workflow:

1. CI fails on a BLOCK violation. PR comment lists the failing rule ids.
1. `mimir guardrail check` (local run or pre-commit hook) fails on a BLOCK violation and lists the failing rule ids.
2. Someone runs `mimir guardrail approve <rule-ids> --reason "..."` on the
PR branch. This creates an empty commit with the trailer.
3. Push. CI re-runs, reads HEAD trailers, clears the matching BLOCKs.
3. Re-run the check; it reads HEAD trailers and clears the matching BLOCKs. (Repo CI does not run guardrails.)
4. Any subsequent commit without the trailer invalidates the approval because
HEAD has moved. No `revoke` command is needed.

Expand All @@ -73,18 +77,18 @@ Services (business logic: indexing, retrieval, temporal, quality, intent, sessio
↓
Domain (core models: CodeGraph, Node, Edge, Config, Session — all frozen dataclasses/enums)
↓
Ports (protocol interfaces: Parser, Embedder, VectorStore, GraphStore, SessionStore, LLMClient)
Ports (protocol interfaces: Parser, Embedder, VectorStore, GraphStore, SessionStore)
↓
Infra (concrete implementations: tree-sitter, sentence-transformers/jina, SQLite, ChromaDB, LiteLLM)
Infra (concrete implementations: tree-sitter, ONNX Runtime embeddings (local) / Jina API, SQLite, in-memory NumPy vector index)
```

### Key Layers

- **`mimir/domain/`** — Immutable core: `models.py` (NodeKind/EdgeKind enums, Node/Edge), `graph.py` (NetworkX-backed CodeGraph), `config.py` (TOML-mapped dataclasses), `guardrails.py` (Rule/Violation/ChangeSet/GuardrailResult)
- **`mimir/ports/`** — Protocol interfaces for dependency injection boundaries
- **`mimir/services/`** — All business logic. Heaviest files: `indexing.py` (parse→graph→embed pipeline), `retrieval.py` (query→seed→expand→rank→budget-fit), `guardrail.py` (rule evaluation engine), `diff_analyzer.py` (git diff→ChangeSet), `agent_policy.py` (bounded autonomy)
- **`mimir/infra/`** — Pluggable implementations: `parsers/tree_sitter.py`, `embedders/local.py`+`jina.py`, `stores/sqlite_graph.py`, `vector_stores/numpy_store.py`+`chroma.py`
- **`mimir/adapters/`** — External interfaces: `cli.py` (Typer entry point), `mcp_server.py` (MCP stdio), `http_server.py` (REST API)
- **`mimir/services/`** — All business logic (19 modules). Core pipeline: `indexing.py` (parse→graph→embed), `retrieval.py` (query→seed→expand→rank→budget-fit), `summarizer.py`, `graph_linker.py` (cross-file reference resolution). Ranking signals: `intent.py` (query classification), `quality.py`, `temporal.py`. Guardrails: `guardrail.py` (rule engine), `guardrail_report.py`, `guardrail_trailers.py` (approval trailers), `diff_analyzer.py` (git diff→ChangeSet), `agent_policy.py` (bounded autonomy). Also `impact.py` (blast-radius reverse-tracing), `session.py` (dedup w/ exponential decay), `write_context.py` (write-path bundles), `catalog.py` (Backstage), `watcher.py` (live re-index)
- **`mimir/infra/`** — Pluggable implementations: `parsers/tree_sitter.py`, `embedders/local.py`+`jina.py`, `stores/sqlite_graph.py`+`sqlite_session.py`, `vector_stores/numpy_store.py` (in-memory, rebuilt from `graph.db` embeddings on startup)
- **`mimir/adapters/`** — External interfaces: `cli.py` (Typer entry point) + `cli_support/`, `mcp_server.py` (MCP stdio), `remote_mcp.py` (proxy to remote server), `http_server.py` (REST API), `web/server.py` (Web Inspector UI), plus `ci/` (GitHub Action) and `hooks/` (pre-commit) integration assets
- **`mimir/container.py`** — Wires all layers together via DI

### Retrieval Pipeline
Expand All @@ -95,9 +99,15 @@ Infra (concrete implementations: tree-sitter, sentence-transformers/jina, SQLite

1. Tree-sitter parse → 2. Build node/edge graph → 3. Cross-file reference resolution → 4. Heuristic summarization → 5. Embedding → 6. Persist to SQLite + vector store. Supports incremental indexing via git diff.

## CI

`.github/workflows/ci.yml` runs on PRs and pushes to `main`/`develop` and does only two things: `pytest --tb=short -q` on Python 3.11/3.12/3.13, and build verification (`python -m build` for the server and `client/` packages + `twine check --strict`). Guardrail checks are not run in CI; use `mimir guardrail check` locally or via the pre-commit hook.

`.github/workflows/publish.yml` releases on `v*` tag pushes only: tests → build → publish both packages to PyPI (trusted publishing, `pypi` environment) → GitHub Release with the dists attached. Versions come from the git tag via setuptools-scm.

## Configuration

Primary config: `mimir.toml` (TOML). Key sections: `[[repos]]`, `[indexing]`, `[embeddings]`, `[retrieval]`, `[temporal]`, `[session]`, `[vector_db]`, `[llm]`.
Primary config: `mimir.toml` (TOML). Key sections: `[[repos]]`, `[indexing]`, `[embeddings]`, `[retrieval]`, `[temporal]`, `[session]`, `[watcher]`.

`mimir.toml` indexes the Mimir source itself (used for both development and CI).

Expand All @@ -108,9 +118,9 @@ Guardrails config: `mimir-rules.yaml` (architectural rules) and `mimir-agent-pol
Default location: `.mimir/`, split into two subfolders:

- **`.mimir/project/`** — tracked in git. Contains `graph.db` (the code graph). Committing this lets CI skip re-indexing and lets new developers get a working context engine on clone.
- **`.mimir/session/`** — ignored by git. Contains `sessions.db` (session state), `models/` (downloaded embedding weights), `chroma/` (derived vector store). Anything personal or re-derivable lives here.
- **`.mimir/session/`** — ignored by git. Contains `sessions.db` (session state), `models/` (downloaded ONNX embedding models). Anything personal or re-derivable lives here.

Run `mimir index` and commit `.mimir/project/graph.db` after significant code changes.
Run `mimir indexer run` and commit `.mimir/project/graph.db` after significant code changes.

## Docker

Expand Down
37 changes: 23 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
FROM python:3.11-slim
# syntax=docker/dockerfile:1
FROM python:3.13-slim

# Install system dependencies: git for repo operations, build-essential for native extensions
# git for repo operations (indexing, temporal signals, diffs). Every Python
# dependency ships wheels, so no compiler toolchain is needed.
RUN apt-get update && \
apt-get install -y --no-install-recommends git build-essential && \
apt-get install -y --no-install-recommends git && \
rm -rf /var/lib/apt/lists/*

# Fix for "dubious ownership" error in mounted volumes
RUN git config --global --add safe.directory '*'

WORKDIR /app

# Upgrade pip
RUN pip install --no-cache-dir --upgrade pip
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

# Copy project metadata and source code
# Third-party dependencies only, read from pyproject.toml. This layer (and the
# model download below) is reused across source-code changes.
COPY pyproject.toml ./
COPY mimir/ ./mimir/
RUN --mount=type=cache,target=/root/.cache/pip \
python -c "import tomllib; print('\n'.join(tomllib.load(open('pyproject.toml','rb'))['project']['dependencies']))" > /tmp/requirements.txt && \
pip install -r /tmp/requirements.txt

# Install application and all dependencies
RUN pip install --no-cache-dir .
# Pre-download the standard embedding model (ONNX export) so the container
# runs 100% offline. File list matches _MODEL_FILES in mimir/infra/embedders/local.py.
RUN python -c "from huggingface_hub import snapshot_download; snapshot_download('sentence-transformers/all-mpnet-base-v2', allow_patterns=['onnx/model.onnx', 'onnx/model.onnx_data', 'tokenizer.json', 'config.json', 'modules.json', 'sentence_bert_config.json', '1_Pooling/config.json'])"

# Pre-download the standard embedding model
# This caches model weights into the Docker layer so the container runs 100% offline
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-mpnet-base-v2')"
# The build context has no .git, so setuptools-scm cannot derive the version.
# Pass it explicitly: docker build --build-arg MIMIR_VERSION=1.2.0 .
ARG MIMIR_VERSION=0.0.0
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MIMIR_CONTEXT_SERVER=${MIMIR_VERSION}

# Remove build tools to shrink final image
RUN apt-get purge -y build-essential && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
# Application code last — only this layer rebuilds on a code change
COPY README.md ./
COPY mimir/ ./mimir/
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-deps .

# Offline hugging face mode
ENV HF_HUB_OFFLINE=1
Expand Down
9 changes: 4 additions & 5 deletions client/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=68.0", "wheel>=0.46", "setuptools-scm>=8"]
requires = ["setuptools>=84.0", "wheel>=0.48", "setuptools-scm>=10.3"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -8,13 +8,12 @@ dynamic = ["version"]
description = "Lightweight MCP proxy client for remote Mimir context servers — no repos, no models, no indexing needed"
readme = "README.md"
requires-python = ">=3.10"
license = {text = "MIT"}
license = "MIT"
keywords = ["mcp", "context", "code", "llm", "proxy", "mimir"]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -25,8 +24,8 @@ classifiers = [
]

dependencies = [
"aiohttp>=3.9",
"typer>=0.9",
"aiohttp>=3.14.3",
"typer>=0.27.2",
]

[project.urls]
Expand Down
Loading
Loading