Skip to content

feat: Contract Guardian on the CLI and MCP (preview) - #691

Merged
aryamthecodebreaker merged 3 commits into
mainfrom
claude/contract-guardian
Nov 22, 2026
Merged

aryamthecodebreaker merged 3 commits into
mainfrom
claude/contract-guardian

Conversation

@aryamthecodebreaker

Copy link
Copy Markdown
Owner

Work package codex-briefs/01-contract-guardian-surfaces.md, without step 4 (GitHub Action parity comes later in a separate change; packages/action/src is untouched, and only dist/index.mjs is rebuilt because Core changed).

What ships (all labelled preview)

  • fixmap contracts [--repo] [--format markdown|json] [--output] [--no-cache] lists the contract surfaces in the working tree: path, kind, name, declared version (OpenAPI/AsyncAPI version, $schema, proto3/edition), entry count, and exact worktree:sha256 fingerprint.
  • fixmap contracts diff <from>..<to> compares two exact Git refs through git ls-tree + git cat-file --batch (the fixmap history pattern). It never checks out a ref and never touches the worktree. Changes come out grouped as breaking / unknown / compatible, each with its git:<oid> before and after fingerprints. Three-dot ranges, refs that start with -, and --no-cache are rejected.
  • MCP fixmap_contracts takes action: "list" | "diff", from, to, repo, format. It sets readOnlyHint: true (plus destructiveHint: false, idempotentHint: true, openWorldHint: false) and validates strictly: unknown arguments, a bad action, one-sided or unbounded refs, refs containing .. or starting with -, remote repos and bad formats all fail. It delegates to the CLI command, so both surfaces print the same output.
  • YAML parity. OpenAPI/AsyncAPI in .yaml/.yml now go through a bounded, dependency-free YAML-subset reader (packages/core/src/yaml-subset.ts) and then the same decoder as JSON. YAML and JSON therefore produce identical entries and deltas: parameters, requiredness, schema fields, $refs and flow collections. Before this, YAML extracted only operations. Constructs the reader can't represent faithfully are reported as contract-parse-failed instead of guessed: anchors, aliases, tags, merge keys, duplicate keys, tab indentation and multi-document files.
  • Feature catalog entry "Contract Guardian" with preview: true. CLI help reads Preview: , the MCP description reads Preview (may change before v0.10.0): , and the preview-set tests are updated.

Core behaviour changes (worth a reviewer's eye)

  1. Unparseable on one side is now unknown, not silent. If a contract parses at one ref and not the other, compareContractInventories used to emit nothing. It now emits a contract-unavailable change with compatibility: "unknown" and the fingerprint from the readable side. It is still never reported as contract-removed/breaking. The existing test that pinned "no change" was updated to match the brief ("unknown or unparseable contracts are reported as unknown with a diagnostic, never silently skipped").
  2. Fixed a silent empty-surface bug. The scanner doesn't sample .graphql, .gql, .proto or .sql (not in SOURCE_FILE_EXTENSIONS), so contractSourcesFromRepo, which change-scope uses, parsed an empty string and reported those contracts with zero entries. It now flags them as contract-source-incomplete. The new Contract Guardian readers read contract files in full (2 MB per file, 64 MB in total; larger or non-UTF-8 files are reported as unread). I didn't add those extensions to the scanner because that would shift ranking.
  3. ContractSurface gains an optional version, and ContractChange.change gains "contract-unavailable". Both are additive.
  4. Contracts output (# FixMap Contracts / # FixMap Contract Diff Markdown and contractListVersion / contractDiffVersion JSON) is recognised as a FixMap artifact. --output refuses to overwrite any other repository file.

Evidence for the "Contract Guardian" ledger row

Closes these items from the row's "remain" list: YAML schema details and CLI/MCP parity (Action parity is still open). Public-language APIs, known-consumer edges and held-out evidence are also still open.

Tests:

  • packages/cli/test/contracts-command.test.ts (9 tests, real Git repos):
    • list covers all six kinds with versions and worktree: fingerprints, and GraphQL/Proto/SQL are parsed rather than empty
    • a repo with no contracts
    • malformed specs (YAML anchor, truncated JSON, non-SDL GraphQL) become diagnostics
    • diff across breaking + unknown (unparseable GraphQL, a migration statement change) + compatible, with severity ordering and both git: fingerprints
    • HEAD, git status --porcelain and a dirty working-tree file are unchanged after the diff
    • YAML and JSON spellings of the same change give identical deltas
    • removed contract gives breaking; identical refs give no change
    • unknown refs, a non-Git directory and a missing path fail clearly
    • 13 argument-validation cases
    • --output overwrite refusal and replacing its own prior artifact
  • packages/cli/test/mcp.test.ts: list and diff through MCP, readOnlyHint, schema shape, HEAD/status unchanged, unknown ref, 10 invalid-argument cases. The preview-set and tool-order tests are updated.
  • packages/cli/test/cli-runner.test.ts: catalog preview list and contracts Preview: help label.
  • packages/core/test/contracts.test.ts: OpenAPI JSON/YAML parity with entries and deltas, AsyncAPI parity, malformed or unsupported YAML, declared versions (YAML openapi: 3.0 stays "3.0"), and the contract-unavailable change.
  • packages/core/test/contracts-repository.test.ts: YAML subset reader (block/flow/quoted/block scalars, refusals), unsampled-contract fix, oversized and non-UTF-8 handling on both the worktree and ref paths, a content-marked .yml at a ref, and an unknown ref.

Verification

The release session asked us to skip the full local npm run ci because of CPU load, so I stopped my run early; GitHub CI runs the full gate. Run locally on this branch:

  • npm run typecheck: pass
  • npm run lint: pass
  • Core vitest run: 881 passed, 1 skipped. On the first run, 1 test failed; it passed on an immediate rerun, likely a timeout while other sessions loaded the machine. Its name wasn't captured.
  • CLI vitest run: 343 passed before the final rebase. After rebasing onto feat(action): preview change scope and capability maps #687 I reran the affected files: mcp, cli-runner and contracts-command (185 passed), plus the Action suite (66 passed).
  • npm run check:action-bundle: generated artifacts match the checked-in files.

Not edited: the ledger, CHANGELOG.md, package versions, the website changelog, package-lock.json, packages/action/src.

Note: the pre-rebase copy of this branch is still on the remote as claude/contract-guardian-138b5d because the force-push was blocked. It can be deleted.

🤖 Generated with Claude Code

aryamthecodebreaker and others added 2 commits November 22, 2026 20:12
- fixmap contracts lists OpenAPI, AsyncAPI, GraphQL, Protobuf, JSON Schema and
  SQL migration surfaces in the working tree with kind, declared version and
  exact fingerprint.
- fixmap contracts diff <from>..<to> compares two exact Git refs through Git
  objects (no checkout, no worktree change) and prints breaking / unknown /
  compatible changes with before/after fingerprints.
- Read-only MCP tool fixmap_contracts (action list|diff, readOnlyHint).
- YAML OpenAPI/AsyncAPI now go through a bounded YAML-subset reader and the
  same decoder as JSON, so both spellings yield identical deltas. Anchors,
  aliases, tags, merge keys, duplicate keys and multi-document files are
  reported as contract-parse-failed instead of guessed.
- A contract readable on one side and unparseable on the other is now an
  explicit "contract-unavailable" change with unknown compatibility.
- GraphQL/Protobuf/SQL files the scanner does not sample are read in full
  for contracts, and contractSourcesFromRepo reports them as incomplete
  rather than parsing an empty sample.
- Feature catalog entry (preview), artifact detection for contracts output,
  rebuilt action bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
fixmap Ready Ready Preview Nov 22, 2026 2:51pm UTC

…rites

The repository root was realpath'd but the --output path was not, so on
macOS (/var vs /private/var), through a symlinked directory, or a Windows
junction, an output inside the repository looked outside it and an existing
repository file was overwritten. Resolve the output's nearest existing
directory through realpath (the leaf stays unresolved so a symlinked output
file is still refused) and add a regression using a directory alias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aryamthecodebreaker
aryamthecodebreaker merged commit bfb7469 into main Nov 22, 2026
8 checks passed

This branch was successfully deployed

1 active deployment
Preview — 929e091c Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant