# contextlift

> GitHub-native Context CI for AI SQL agents, dbt semantic layers, and enterprise data warehouses. Pure Python stdlib core (zero core dependencies), Apache-2.0.

contextlift measures whether written business context (Markdown rules, dbt MetricFlow YAML, Snowflake Semantic Views, Apache Ossie, LookML, or catalog docs) improves SQL execution accuracy on your real database. It runs fail-closed read-only SQL diffs (SQLite, DuckDB, BigQuery, plus beta Postgres, Snowflake, and Databricks connectors), paired McNemar tests with 95% Tango intervals on sealed holdouts, zero-LLM Cross-Layer Conflict Radar, AST rule blame attribution, offline Business Steward sign-off packs, HMAC-SHA256 integrity seals, and a local stdio-only certified MCP runtime server.

## Quickstart

- Zero-install offline demo: `uvx contextlift demo`
- Install with local DuckDB + YAML: `pip install "contextlift[duckdb,yaml]"`
- Optional cloud warehouse extras: `[postgres]`, `[snowflake]`, `[databricks]`, `[bigquery]`, `[lookml]`
- Bootstrap a workspace + starter schemas: `contextlift init --db warehouse.duckdb --dbt .`
- Run zero-LLM Cross-Layer Conflict Radar: `contextlift lint --spec spec/ --dbt . --db warehouse.duckdb --db-role readonly_role`
- Ingest production failures into a Steward sheet: `contextlift ingest-failures --input prod.jsonl --out review/review.csv`
- Run a paired round with attestation: `contextlift round --runner openai:gpt-4.1 --budget 5 --out round.json --attestation-out .contextlift/attestation.json`
- Serve certified context over MCP stdio: `contextlift serve-mcp --spec spec/ --attestation .contextlift/attestation.json`
- Compile to semantic layers: `contextlift compile --spec spec/ --target snowflake-yaml --attestation .contextlift/attestation.json`

## Documentation

- [README](README.md): Overview, three-verdict forest plot, 3 progressive levels, and install matrix
- [Quickstart](docs/quickstart.md): 10-minute copy-paste walkthrough from Level 0 demo to Level 3 MCP serving
- [How it works](docs/how-it-works.md): Arm 0d vs Arm 1, sealed holdout firewall, McNemar/Tango stats, verdicts, safety badges, and pre-flight gates
- [CI setup](docs/guides/ci.md): GitHub Action, reusable workflow, pre-commit hooks, merge policy gates, HMAC attestations, and OpenTelemetry export
- [Warehouses and agents](docs/guides/connect.md): DuckDB, SQLite, BigQuery, beta Postgres/Snowflake/Databricks, OpenAI/Anthropic/Gemini/Ollama/vLLM, custom CLI runners, and CSV replay
- [Building a gold set](docs/guides/questions.md): `init --sql-dir`, `mine`, `ingest-failures`, offline Business Steward review packs, `gate`, `split`, and curate-only `suggest`
- [Semantic layers and MCP](docs/guides/semantic-layers.md): Cross-Layer Conflict Radar across Markdown, dbt, Snowflake, Ossie, and LookML; bidirectional `compile`; Claude Code and Cursor MCP setup
- [Extending contextlift](docs/guides/extending.md): Structural Python protocols for custom `Executor` and `Runner` classes
- [CLI reference](docs/reference/cli.md): 8 core verbs and all 61 verbs grouped by stage
- [File formats](docs/reference/formats.md): `spec/`, CSV schemas, `contextlift.yaml`, `attestation.json`, and `.contextlift/` layout
- [Empirical results](docs/results.md): Published results table, three core findings, retraction postmortem, and research archive links
- [Security](docs/security.md): Fail-closed read-only SQL rails, SSRF guard, stdio-only MCP, PII redaction, and HMAC-SHA256 trust model

## Optional

- [Full LLM Reference](llms-full.txt): Complete CLI command map, architecture, and empirical benchmarks
- [MCP Registry Manifest](server.json): Standard stdio MCP server definition for `contextlift serve-mcp`
- [GitHub Action](action.yml): Composite PR gate action for GitHub Actions
- [Pre-Commit Hook](.pre-commit-hooks.yaml): Local `contextlift-lint`, `contextlift-gate`, and `contextlift-scan` hooks
