ContractSutra AIv0.2.1GitHub

Architecture

 before.json --+                                     +--> contract-diff.json / .sarif.json
 after.json  --+--> load --> normalize --> compare --+--> compatibility.md / .html
 consumers   --+   (bounded,  (resolve $ref,  (rules, +--> release-note-draft.md
                    validate)  summarize)     stable  +--> generated-cases.json (NOT_RUN)
                                              IDs)    +--> audit.jsonl (hash chain + report hashes)
                                                              |
              audit --dir  <----------------------------------+   recompute everything
                  `--> audit-report.json / .md / .html  (sealed with SHA-256)

Modules (src/)

ModuleResponsibility
core/utils.mjsSHA-256, JSON-pointer escaping, HTML escaping, bounded file reads, atomic writes
core/load.mjsJSON parse (BOM tolerant), structural validation, local $ref resolution, cycle and depth guard
core/normalize.mjsReduces a spec to operations, parameters, request body, responses and schema summaries; records every unresolved fragment
core/compare.mjsDirection-aware rules; finding ID = CS- + first 12 hex of SHA-256(code, pointer, description)
core/consumers.mjsLoads the manifest, maps operations, labels USER_DECLARED_UNVERIFIED
core/cases.mjsDeterministic positive and negative sample templates, NOT_RUN
core/report.mjsMarkdown, HTML (CSP, no scripts), SARIF, migration plan
core/audit.mjsAppend-only SHA-256 hash chain (prevHash, hash)
core/assure.mjsIndependent replay audit AUD-01..AUD-12 and report seal
core/run.mjsOne orchestration path shared by CLI, demo and tests
cli/main.mjsStrict flag parsing and exit codes
server/index.mjsRead-only loopback HTTP, bearer token of 32+ chars, rate limit, realpath containment
mcp/stdio.mjsExperimental read-only MCP (protocol 2025-11-25), root-contained paths
adapters/ide.mjsProject-local copy of instruction packs; rejects symlinks

Design decisions

  1. Local-first / offline: specs are sensitive, so nothing leaves the machine.
  2. Fail closed: unknown semantics produce a needs review finding, never silence.
  3. Direction matters: the same schema change is breaking in a request and safe in a response, or the reverse.
  4. Evidence over assertion: every report names its input hashes; the audit recomputes rather than trusts.
  5. Zero dependencies: no runtime supply-chain surface.

Trust boundaries

Input files are untrusted: bounded size and depth, no remote $ref. Reports are rendered with escaping and a restrictive CSP. The HTTP and MCP servers confine reads to a root via realpath.

Data model: a finding

{
  "id": "CS-1A2B3C4D5E6F",
  "kind": "breaking",
  "code": "FIELD_REMOVED",
  "pointer": "#/paths/~1invitations/post/responses/201/content/application~1json/schema/properties/role",
  "description": "Schema field removed: role",
  "direction": "response",
  "evidence": "static-contract-diff",
  "verification": "OBSERVED_IN_SPEC",
  "consumerImpact": "UNKNOWN",
  "affectedConsumers": []
}