contextlift

CI setup and governance

Run contextlift automatically on pull requests to catch broken rules at $0, prove accuracy lift on real SQL before merging, post one idempotent PR comment, and seal every verdict with an HMAC-SHA256 integrity attestation.

End-to-end dbt + GitHub Actions example

Drop this workflow into .github/workflows/context-ci.yml. On every PR touching spec/, dbt/, or golds.csv, it runs the Cross-Layer Conflict Radar, gates the answer key, executes a paired offline or live round, enforces policy: from contextlift.yaml, signs attestation.json, and updates one PR comment (<!-- contextlift-pr-summary -->):

name: Context CI
on:
  pull_request:
    paths:
      - "spec/**"
      - "dbt/**"
      - "golds.csv"

permissions:
  contents: read
  pull-requests: write

jobs:
  context-ci:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: moutasemalakkad/context-lift@v0.3.2
        with:
          spec-dir: spec/
          dbt-dir: dbt/
          db-path: duckdb://analytics_extract.duckdb
          golds-csv: golds.csv
          predictions-control: arms/baseline.csv
          predictions-treatment: arms/candidate.csv
          attestation-out: .contextlift/attestation.json
          otel-out: .contextlift/otel.json
          sign-key: ${{ secrets.CONTEXTLIFT_SIGN_KEY }}
          fail-on-refusal: "true"

Swap predictions-control/predictions-treatment for runner: openai:gpt-4.1, budget: "5", and target-lift: "20" (with OPENAI_API_KEY in env:) to run a live model round directly in CI. On fork PRs where GITHUB_TOKEN lacks write permission, the action logs a clean warning and still returns the real gate exit code.

Reusable workflow (workflow_call)

Call .github/workflows/contextlift-pr-gate.yml across multiple domain repositories (installs contextlift[duckdb,yaml] from PyPI and supports file paths as well as duckdb://, postgresql://, snowflake://, databricks://, and bq:// URIs):

jobs:
  gate:
    uses: moutasemalakkad/context-lift/.github/workflows/contextlift-pr-gate.yml@v0.3.2
    with:
      spec-dir: spec/
      dbt-dir: dbt/
      db-path: duckdb://analytics_extract.duckdb
      domain: finance
    secrets: inherit

Key action.yml inputs

InputPurpose
spec-dir, domainPath to spec/ and optional domain scope (spec/domains/<name>).
dbt-dir, snowflake-semantic, ossie-dir, lookml-dirSemantic layer sources compared by the Cross-Layer Conflict Radar.
db-path, db-roleWarehouse path or URI and read-only role (Postgres/Snowflake) for live enum checks, gate, and round.
golds-csvGold set CSV for lint --golds, gate (non-zero gate exits fail CI), and round.
predictions-control, predictions-treatmentOffline baseline and candidate CSVs for $0 CI rounds.
runner, budget, target-liftOptional live LLM runner, USD ceiling, and resolvable-lift target.
sign-key, attestation-out, otel-outHMAC-SHA256 signing key and paths for attestation.json and OTLP JSON export.
post-comment, fail-on-refusalToggle idempotent paginated PR commenting and exit-code gating.

Pre-commit hooks

Catch broken enum literals, conflicting definitions, defective golds, and leaked secrets before git commit. Add to .pre-commit-config.yaml:

repos:
  - repo: https://github.com/moutasemalakkad/context-lift
    rev: v0.3.2
    hooks:
      - id: contextlift-lint
        args: ["--spec", "spec/", "--dbt", "dbt/"]
      - id: contextlift-gate
        args: ["--db", "warehouse.duckdb", "--golds", "golds.csv", "--timeout", "60"]
      - id: contextlift-scan

.pre-commit-hooks.yaml bundles pyyaml>=6 for contextlift-lint, duckdb>=1 for contextlift-gate, and zero extra dependencies for contextlift-scan.

Declarative merge policy in contextlift.yaml

Place a policy: block in contextlift.yaml (at repo root, --workspace, or beside --spec). round validates policy keys and types upfront (failing closed with exit code 2 on unknown keys or non-numeric thresholds), records the verdict in attestation.json, and exits non-zero on violation:

db: duckdb://warehouse.duckdb
spec: spec/
golds: golds.csv
workspace: .contextlift
timeout: 60
reps: 3
policy:
  min_lift: 2.0
  max_regressions: 0
  require_holdout: true
  require_lint_clean: true
  require_leak_clean: true
  allowed_verdicts:
    - REAL GAIN

Signed attestations, PR summaries, and OpenTelemetry

# 1. Produce a signed attestation (HMAC-SHA256)
export CONTEXTLIFT_SIGN_KEY="$CI_ATTESTATION_HMAC_KEY"
contextlift round --out round.json --attestation-out .contextlift/attestation.json

# 2. Verify signature and chain before deploying or serving over MCP
contextlift verify-attestation .contextlift/attestation.json --require-signature --prev previous_attestation.json

# 3. Render one Markdown/JSON PR comment and export OTLP metrics
contextlift pr-summary --report round.json --lint lint.json --format markdown --out pr_summary.md
contextlift export-otel --input .contextlift/attestation.json --out otel_metrics.json --service-name finance-context-ci

export-otel also accepts round.json and ablate.json directly, emitting OTLP error status (code=2) on INVALID, REAL LOSS, OVERFIT, regressions, or policy failures. attestation.json is an HMAC-SHA256 integrity seal, not asymmetric PKI; see Security.