GitHub - interface-delta/diffpact: Local, stateless Git task contracts, deterministic diff boundaries, and non-self-certified review gates for AI coding agents.

GitHub

9 min read Original article ↗

diffpact (v0.4.3)

Local, stateless Git task contracts, deterministic diff boundaries, post-merge verification, and cross-harness review gates for multi-agent coding workflows.

Built by InterfaceDelta · MIT License · Zero runtime dependencies · Node >= 22.6 · Changelog · npm CI


Install & Put diffpact on Your PATH

Choose one installation method (zero runtime dependencies, Node >= 22.6):

Option A (Recommended): Install globally from npm

Or run without installing globally:

Option B: Clone from GitHub and symlink globally (runs npm run build automatically)

git clone https://github.com/interface-delta/diffpact.git
cd diffpact && npm link

Option C: Install globally from a local checkout

npm install -g /path/to/diffpact

Verify your environment and try the 30-second self-contained quickstart demo:

diffpact doctor
npm run quickstart

See examples/quickstart/ for the interactive walkthrough and examples/harnesses/ for drop-in Claude Code, Codex CLI, Crush, Gemini/Antigravity, and @vercel/board configs.

Every command supports per-command help:

diffpact <command> --help
diffpact help <command>

Why diffpact?

Shared message boards (@vercel/board) and subagent harnesses let multiple coding agents claim tasks in parallel—but ticket locks alone do not stop agents from editing forbidden files, skipping test suites while exiting 0, silently altering pinned constants, introducing regressions when two parallel branches are merged, or rubber-stamping their own commits.

diffpact enforces explicit, SHA-pinned Task Contracts directly against Git:

  • 100% Local & Stateless: No daemon, no database, no sign-up. Truth is recomputed directly from Git (HEAD, git diff -M -z, untracked files, and symlink checks) plus RFC 8785 canonical SHA-256 receipts.
  • Boundary Precedence (.git deny > forbidden > read_only > allowed): Unconditionally blocks .git/ metadata/hook tampering, symlinks (120000), submodules (160000), unauthorized edits/renames (-M -z), and destructive shell or inline interpreter commands (Bash, python -c, node -e) before and after execution.
  • No Silent Zero: Empty check lists, skipped test suites (vitest / node --test / jest skipped counts), or missing commits return exit code 2 (INCOMPLETE), never 0.
  • Non-Self-Certified, Diff-Bound Review: Enforces distinct implementer vs. reviewer identities, explicit raw-diff attestation (--diff-sha <sha> from diffpact diff or --inspected-raw-diff), optional orchestrator HMAC signing (DIFFPACT_REVIEWER_SECRET, automatically stripped from worker subprocesses), and automatic invalidation (exit 3) if HEAD moves.
  • Worktree Lifecycle & Durable Evidence Archiving: diffpact worktree create --share-node-modules handles standard repos, npm/pnpm monorepo workspace overlays, and subdirectory apps (site/node_modules). diffpact worktree remove automatically archives .diffpact/ evidence (contract.json, receipt.json, reviews/, report.md, report.json) to <main>/.diffpact/archive/ before removing the worktree.
  • Post-Merge Integration Gate (diffpact merge-verify): After joining 2+ parallel branches onto main, runs the deduplicated union of all participating contracts' checks and path boundaries on the merged tree and writes a signed merge-receipt.json.
  • Cross-Harness Support: Ready out of the box for Claude Code, OpenAI Codex CLI, Crush, Google Gemini CLI / Antigravity (agy & agy-worker), and @vercel/board.

Real-World Trajectory: Why Passing Tests Aren't Enough

In a typical single-agent workflow, the moment npm run typecheck and npm test exit 0, the branch looks ready to merge. Here is an actual generalized trajectory from a 7-package TypeScript monorepo running diffpact v0.4.x with two separate models (Author Agent A and Independent Reviewer Agent B):

worktree create --share-node-modules  (7 local workspace packages linked, ~10s)
  └─▶ Author Agent A implements feature + tests ──▶ diffpact verify: PASS (exit 0)
        └─▶ diffpact status --require-review ──▶ HOLD (exit 2: review missing)
              └─▶ Reviewer Agent B runs `diffpact diff` (~90s raw-diff audit)
                    └─▶ REQUEST_CHANGES: 6 real bugs caught before merge!
                          1. Async cancellation race (queue cleared, active fetch unguarded)
                          2. Missing DOM data-attribute breaking replay buttons on one variant
                          3. Background audio volume left un-ducked during modal transition
                          4. Test file silently swallowing a ReferenceError inside try/catch
                          5. Missing profile metadata in peer-to-peer rendering path
                          6. Automated system notices unintentionally triggering TTS playback
              └─▶ Orchestrator runs `diffpact amend --add-allow packages/core/src/index.ts`
                  (hash-chained scope expansion required for bug #5; old receipt invalidated)
        └─▶ Author fixes all 6 bugs ──▶ diffpact verify: PASS (exit 0)
  └─▶ Reviewer B signs `diffpact review --diff-sha <sha> --verdict approve` (mode=diff-sha-bound)
        └─▶ diffpact status --require-review ──▶ PASS (exit 0, review: approved 1/1)
              └─▶ diffpact worktree remove --require-verified --delete-branch
                  (archived contract, receipt, amendment chain, reviews & reports to .diffpact/archive/)

Measured overhead: ~25 seconds for worktree setup, contract pinning, and archiving + ~90 seconds for independent raw-diff review — 6 subtle production bugs stopped before a single line touched main, including a broken test that had exited 0.


End-to-End Quickstart

# 0. Inspect environment, Git setup, and installed agent CLIs (with root/sandbox warnings)
diffpact doctor

# 1. Create an isolated linked worktree with clean dependency sharing
#    (monorepo workspace-aware; auto-discovers subdir apps like site/node_modules or use --node-modules-dir)
diffpact worktree create /var/tmp/wt-normalizer --branch feat/normalizer --share-node-modules
cd /var/tmp/wt-normalizer

# 2. Initialize a SHA-pinned task contract (with blocking + advisory checks and timeouts)
diffpact init \
  --task-id "feat-normalizer-01" \
  --mission "Implement normalizer slice without touching migrations" \
  --allow "src/normalizer/**" \
  --allow "test/normalizer/**" \
  --read-only "src/common/**" \
  --forbid "migrations/**" \
  --forbid "package.json" \
  --check "typecheck=npm run typecheck" \
  --check "unit=npm test" \
  --check-timeout "unit=60" \
  --advisory-check "baseline=npm run test:baseline" \
  --implementer "codex-worker:sess-01:codex"

# Tip for zsh users: wrap shell variables inside colon-delimited identity strings in braces
# (e.g. "codex:s-${n}:codex") or single quotes ('codex:s-1:codex'), because zsh parses
# unbraced "$n:c" in "codex:s-$n:codex" as a `:c` parameter expansion modifier.

# 3. Run any supported harness (claude | codex | crush | agy | gemini) with pre/post gate & live heartbeats
diffpact run --harness codex --model gpt-6-astra --prompt "Implement .diffpact/contract.json" --heartbeat-sec 30
# (Or wrap any custom worker command: diffpact exec [--resume] -- <cmd...>)

# 4. Check status (explicitly shows whether review is still missing)
diffpact status
# -> diffpact status: PASS (exit 0) — Checks verified; review: missing (0/1 — run `diffpact status --require-review` before merge)

# 5. Inspect the primary raw Git diff & record an independent, diff-SHA-bound review
diffpact diff
diffpact review \
  --reviewer "claude-rev:sess-99:claude-code" \
  --verdict approve \
  --diff-sha <raw_diff_sha256_prefix> \
  --summary "Verified raw diff and edge cases"

# 6. Gate merge (fails closed until verified + independently reviewed)
diffpact status --require-review
diffpact report --format markdown

# 7. Merge into main, then clean up worktree (auto-archives .diffpact/ evidence to <main>/.diffpact/archive/)
cd /path/to/main-repo
git merge --squash feat/normalizer && git commit -m "feat: normalizer"
diffpact worktree remove /var/tmp/wt-normalizer --require-verified --delete-branch

# 8. Post-merge verification across 2+ merged contracts / archived bundles
#    Recommended order: run merge-verify right after merging BEFORE any manual follow-up fixes on main.
diffpact merge-verify \
  --from .diffpact/archive/<bundle-branch-a> \
  --from .diffpact/archive/<bundle-branch-b>

#    If the orchestrator had to make small post-merge integration glue fixes on main, either:
#    (a) declare those files explicitly (recorded in merge-receipt.json; global forbidden paths stay blocked):
diffpact merge-verify \
  --from .diffpact/archive/<bundle-branch-a> \
  --from .diffpact/archive/<bundle-branch-b> \
  --allow-integration "src/index.ts" \
  --reason "Wire exported routes from both merged slices"
#    or (b) pass a lightweight follow-up contract via an extra `--from <contract.json>`.
#    If unrelated local untracked scratch notes sit on main, pass `--allow-untracked`
#    (alias `--committed-only`) to verify only the committed merge diff while still blocking dirty tracked files.

Command Reference

Run diffpact <command> --help for full flags and examples on any command.

Command Purpose
diffpact doctor Probe Node, Git, .git/info/exclude, installed agent CLIs (claude, codex, crush, agy, gemini, vercel), and root/sandbox warnings
diffpact worktree create Create linked Git worktree with .diffpact/ pre-excluded + workspace/subdir-aware --share-node-modules
diffpact worktree remove Auto-archive .diffpact/ evidence + reports to <main>/.diffpact/archive/, gate via --require-verified, and delete merged/squashed branch
diffpact init Create .diffpact/contract.json pinned to starting_sha, path boundaries, checks, timeouts, and advisory checks
diffpact amend Record hash-chained scope or starting_sha amendment in .diffpact/amendments.jsonl
diffpact run Harness-aware launcher (claude, codex, crush, agy, gemini) with linked-worktree Codex --add-dir, root-safe Claude flags, isolated Crush --data-dir, heartbeats, and host verify
diffpact exec (wrap) Wrap any worker command with pre-flight boundary check (--resume for in-scope dirty trees), tamper guard, and post-flight verify
diffpact verify Recompute Git diff boundaries, version pins, lockfiles, and run required + advisory checks (receipt.json)
diffpact merge-verify Post-merge gate across 2+ merged contracts/archives: verifies combined path boundaries and runs the union of all checks (merge-receipt.json)
diffpact diff Print primary raw Git diff (starting_sha..HEAD) and canonical raw_diff_sha256 token for independent review
diffpact review Record non-self-certified review attestation (--diff-sha or --inspected-raw-diff; optional DIFFPACT_REVIEWER_SECRET HMAC)
diffpact status Fast read-only gate check against live Git HEAD (shows explicit review: missing/approved/stale even without --require-review)
diffpact report Emit Markdown PR card, canonical JSON bundle, or SARIF 2.1.0 report
diffpact delegate Create monotonically narrowed child subcontract conserving parent max_budget_usd
diffpact install-hooks Idempotently merge diffpact hooks into claude-code, codex, gemini, or agy configs
diffpact print-config Print drop-in hook JSON config for claude-code, codex, gemini, or agy
diffpact board @vercel/board adapter (post-contract / complete gate)
diffpact agy-verify-patch Verify unattended agy-worker --diff unified patch before git apply

Strengthening Reviewer Integrity (DIFFPACT_REVIEWER_SECRET)

Because a local CLI has no central identity server, a plain --reviewer flag is self-declared unless bound by your orchestrator. diffpact supports three escalating levels of review assurance:

  1. Diff-SHA Binding (--diff-sha <sha>): Reviewer runs diffpact diff and passes the exact raw_diff_sha256 prefix (>= 12 hex chars), proving the review targets the exact inspected diff bytes.
  2. Orchestrator HMAC Signing (DIFFPACT_REVIEWER_SECRET): Export DIFFPACT_REVIEWER_SECRET in your orchestrator shell. diffpact exec and diffpact run automatically strip DIFFPACT_REVIEWER_SECRET from worker subprocesses, so a worker agent cannot forge a valid diffpact review attestation—only processes holding the orchestrator's secret pass diffpact status --require-review.
  3. Wrapped Read-Only Reviewer (--adapter codex -- <cmd...>): Spawns an independent read-only Codex session, extracts its real thread_id, and rejects any mutation of the working tree.

Exit Codes

Exit Code Status Meaning
0 PASS Boundaries, version pins, checks, and (when required) independent reviews verified against HEAD
1 VIOLATION Path/symlink/shell boundary breached, self-certification or forged HMAC, diff-SHA mismatch, budget exceeded, or check failed
2 INCOMPLETE Missing contract/receipt/review, unattested raw-diff inspection, zero commits, or skipped tests (No Silent Zero)
3 STALE Git HEAD or contract.json moved after receipt or review was issued

Built and maintained by InterfaceDelta: human-architected and developed with multi-model coding agents (Gemini, Claude Code, and OpenAI Codex) governed by diffpact itself with mandatory cross-model raw-diff review.