Config · Diff · MIT

SemanticDiff — Understand What Changed. Know What Matters.

A local-first semantic change intelligence and governance toolkit for JSON, YAML, configuration repositories and OpenAPI contracts — comparing parsed structures instead of lines, with schema validation, policy guardrails and drift detection built in.

View on GitHub Download ZIP

Overview

SemanticDiff (published from the SemanticDiffReviewer repository) is a local-first semantic change intelligence and governance toolkit for JSON, YAML, configuration repositories and OpenAPI contracts. It compares parsed structures rather than lines, validates both documents against JSON Schema, classifies operational risk, redacts likely secrets, enforces path-based policies, detects drift and produces reports designed for developers and CI/CD.

It exists because a text diff marks formatting, key order and array movement as noise. Two configs can differ by 400 lines of reformatting and zero behavioral change — or by one flipped boolean and a critical outage. SemanticDiff understands objects, scalar types, keyed collections, tolerances, ignored paths and domain presets, so the review focuses on behavioral impact.

It is built for platform and DevOps engineers, API maintainers and anyone who reviews configuration pull requests: teams gating config changes in CI, API owners enforcing OpenAPI compatibility, and SREs comparing environments for drift.

Use cases

  • Config PR review — semanticdiff git config/app.yaml --base main --head WORKTREE --format pr produces a Markdown report of behavioral changes for the pull request.
  • OpenAPI breaking-change gate — semanticdiff openapi v1.yaml v2.yaml --fail-on-breaking catches removed operations, required-parameter changes, removed responses and removed security requirements.
  • Config-tree governance — semanticdiff project ./approved ./candidate recursively compares entire configuration directories against policy.
  • Drift detection — snapshot a known-good config with semanticdiff baseline create, then baseline check on a schedule to catch environment drift.
  • Migration guides — semanticdiff migrate old.yaml new.yaml -o MIGRATION.md generates a human-readable upgrade guide.
  • Policy enforcement in CI — the reusable GitHub Action fails the build on high-severity differences, invalid schema or policy violations.
  • Secret redaction in reports — sensitive paths like /credentials/* are redacted automatically; attach reports to tickets safely.
  • Git hooks and code scanning — export SARIF and upload findings to GitHub code scanning, or gate commits locally.

How to work with it

A typical day: you edit config/app.yaml, run semanticdiff git config/app.yaml --base main --head WORKTREE --format pr, and get a Markdown summary of exactly what changed semantically — not a 900-line reformatted diff. You tighten a rule in rules.yaml (numeric tolerance on error rates, unordered tags), re-run, and paste the clean report into the PR. In CI, the Action re-runs the same comparison with --fail-level high; the build fails only when it matters. Weekly, a scheduled baseline check confirms production config hasn't drifted from the approved snapshot.

semanticdiff compare old.yaml new.yaml --rules rules.yaml --fail-level high --format pr
semanticdiff rules explain rules.yaml /security/tls

Features

  • Structured comparison — JSON ↔ JSON, YAML ↔ YAML and JSON ↔ YAML, parsing into typed structures.
  • JSON Schema validation — both documents validate before comparison; --fail-on-invalid blocks invalid input.
  • Policy guardrails and severity gates — path-based rules, severities (including critical) and --fail-on-policy / --fail-level high gates.
  • Rule model with presets — ignore_paths, unordered_paths, case_insensitive_paths, numeric_tolerance, keyed_arrays (match on id) and severity_paths. Diagnose rules with semanticdiff rules test and rules explain.
  • Git-aware review — compare a working tree against main directly, without manual file extraction.
  • Recursive project comparison — diff entire configuration trees, not just single files.
  • OpenAPI breaking-change checks — removed operations, required parameters, parameter type changes, removed responses and removed security requirements.
  • Baseline and drift detection — create named baselines and check live config against them.
  • Migration guide generation — emit a Markdown migration document from any comparison.
  • Secret redaction and sensitive-path rules — values under sensitive paths never appear in reports.
  • Eight output formats — JSON, CSV, JSON Patch, Markdown PR, HTML and SARIF (plus console text).
  • Everywhere it belongs — CLI, Python API, responsive local web UI (semanticdiff-ui on http://127.0.0.1:8765), hardened Docker image and a reusable GitHub Action.
  • Plugin discovery — extend via semanticdiff.plugins entry points.

Installation

Requires Python 3.10+. From a virtual environment (recommended):

python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
python -m pip install -e ".[dev]"
semanticdiff examples/left.yaml examples/right.json --rules examples/rules.yaml

Or with plain pip:

python -m pip install -e .

Launch the local web UI:

semanticdiff-ui
# Open http://127.0.0.1:8765

Docker (non-root image, read-only root filesystem, health check):

docker compose up --build

Quickstart (30 seconds)

$ semanticdiff examples/left.yaml examples/right.json --rules examples/rules.yaml
~ /service/replicas        2 -> 4            (high)
~ /metrics/error_rate      0.02 -> 0.015     (within tolerance: ignored)
+ /service/endpoints[id=grpc]                (medium)
2 differences (1 ignored by rules) / policy: PASS

One command compares, applies your rules (tolerances, keyed arrays, ignored paths) and prints a severity-classified summary. Add --format pr -o report.md for a pull-request-ready report, or --format sarif -o semanticdiff.sarif for code scanning.

Workflow & architecture

SemanticDiff runs a governed pipeline: load both documents (safe YAML) → validate against JSON Schema → apply the rule model (ignores, unordered collections, tolerances, keyed arrays, severities) → classify operational risk → redact sensitive paths → emit the requested format. Exit codes are precise: 0 clean, 1 diff with --fail-on-diff, 2 schema invalid, 3 severity threshold reached, 4 policy guardrail failed, 5 OpenAPI breaking change.

load → schema-validate → rules → risk classification → redact → report (JSON/CSV/Patch/Markdown/HTML/SARIF)

The repository ships action.yml (composite GitHub Action), a hardened Dockerfile, and CI/CodeQL/release workflows. Before exposing the web UI beyond localhost, put authentication, TLS and limits in front of it.

Troubleshooting

  • Exit code 2 (schema invalid) — the document failed JSON Schema validation before comparison; fix the document or relax --fail-on-invalid.
  • Too much noise in the diff — add ignore_paths for volatile metadata (e.g. /metadata/generated_at), unordered_paths for tag lists, and numeric_tolerance for metrics.
  • Keyed arrays report as removed/added — declare them: keyed_arrays: {/service/endpoints: id} so items match by id instead of position.
  • Exit code 5 on an OpenAPI change — a breaking change was detected (removed operation/response/security requirement); the --fail-on-breaking gate is doing its job.
  • SARIF upload rejected — confirm the report was generated with --format sarif and the workflow has security-events: write permission.
  • Action can't find files — check the left/right/rules/schema paths in the workflow step and that actions/checkout ran first; replace OWNER with the actual GitHub owner.
← Back to RepositoriesMore Help →