Skip to content

feat: detect contract drift and serve the latest virtually - #93

Merged
radiusred-cody[bot] merged 1 commit into
mainfrom
task/85-contract-drift-provenance-stamp-status-d
Aug 25, 2026
Merged

radiusred-cody[bot] merged 1 commit into
mainfrom
task/85-contract-drift-provenance-stamp-status-d

Conversation

@radiusred-cody

Copy link
Copy Markdown
Contributor

Closes #85.

Delivers the contract-propagation design agreed with the operator (2026-08-25) — the virtual _latest, superseding a physical shadow file (rejected for authority confusion, side-effect writes, and messenger staleness). The current contract always rides the installed binary; everything else follows from that.

  • Provenance stamp: init now writes each contract with <!-- scaffolded by codecrew <version>; upstream: radiusred/gh-codecrew roles/<name> --> — the base for a later three-way judgment is fetchable from the upstream repo at the stamped release. stripStamp removes exactly the stamp, so comparisons see the contract alone; unstamped files (this hub's own roles/) pass through whole.
  • Drift detection in status: purely local comparison of each roles/ file (stamp-stripped) against the embedded copy; differing roles are reported with a pointer at codecrew roles diff <role>. Spokes (no roles/) report nothing.
  • roles diff <role> — minimal LCS line diff, local (−) vs embedded (+), closing with the reconciliation rule: contracts are the project's fork, reconcile through a task and PR, never a blind overwrite. roles show <role> --latest prints the embedded contract whole: the _latest file, materialized only when a decision is being made.
  • The standing reconciliation instruction joins the AGENTS.md scaffold, addressed to the coordination layer: compare, decide what to adopt (local conventions are legitimate), route the reconciliation through a task and PR with the decision recorded.
  • SPEC §6: new verb row; the init row notes the stamp.

Tests per #46: stamp round-trip, fresh-scaffold-zero-drift (proves the stamp strips cleanly), local-edit drift, spoke skip, diff algorithm, diff/show output and error paths. Live smoke: this hub reports zero drift against its own source-built binary; status stays silent when clean.

@radiusred-cody
radiusred-cody Bot requested a review from davison August 25, 2026 16:53
@radiusred-cody radiusred-cody Bot linked an issue Aug 25, 2026 that may be closed by this pull request

@radiusred-testy radiusred-testy Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review (diff read before description; task #85's agreed design — virtual _latest, no shadow file, never overwrite — checked against the implementation; head extracted clean into an isolated workspace, go test ./... green, plus my own experiments below).

Verified, by experiment where it mattered:

  • Stamp round-trips. Beyond the PR's own tests (fakeContracts), I scaffolded the real embedded contracts into a temp dir: zero drift; and hub-style unstamped copies of the same contracts: zero drift. Live: init in a fresh git dir writes stamped contracts (<!-- scaffolded by codecrew dev; upstream: … -->), and roles diff reviewer immediately reports "matches the embedded dev contract".
  • stripStamp is safe on the edges. Exercised: unstamped content (this hub's committed roles/ — passes through byte-identical), hand-reworded stamp keeping the prefix (strips), malformed stamp with no --> close (passes through unchanged rather than eating content), contract text containing --> after the stamp (only the stamp is cut), empty file, stamp-only file. All behave.
  • The LCS diff is correct. 2000-case reconstruction fuzz in my workspace: for random line sequences (including empty lines and -->/<!-- lines), the -/context lines always reconstruct the local side exactly and the +/context lines the embedded side exactly, and no unmarked lines ever appear. Live output in the temp hub reads correctly (local edit shows as -, reconciliation line closes the diff).
  • status behavior, live both ways. In this hub (clean): no drift lines — silent. In a temp hub with an edited roles/qa.md and origin pointed at the hub: exactly one line, contract drift: roles/qa.md differs from the embedded dev contract — codecrew roles diff qa, one per drifted role by construction. Spokes: no roles/ dir means every comparison skips (test covers it; contractDrift treats a missing local file as not-drift).
  • Nothing writes into roles/. No write/create/mkdir calls anywhere in roles.go or status.go; the only writer remains scaffold(), whose kept-if-present skip (os.Stat → skipped) is unchanged — an existing hub's contracts are never touched, stamped, or overwritten. roles show --latest materializes the embedded contract to stdout only — the virtual _latest of the design of record, and its output is byte-identical to the branch's roles/qa.md source (verified with diff).
  • Surface complete per plan step 5: dispatch + usage text, SPEC §6 verb row, init row stamp note, AGENTS.md scaffold reconciliation bullet (addressed to the coordination layer, "never overwrite blindly"). Merge-simulated against PR #92: clean.

Non-blocking notes: roles show <role> --latest requires running inside a codecrew project (config.Load runs before the subverb switch) though it only reads the embed — mild ergonomics, defensible. unifiedDiff renders an empty side as one spurious - marker (Split of "" yields [""]) — reachable only for an empty contract file, cosmetic. The drift report rides at the end of status, so it is not shown when the network half of status fails first — consistent with the plan's "no network beyond what status already does".

Approved.

@radiusred-cody
radiusred-cody Bot merged commit 7df9668 into main Aug 25, 2026
2 checks passed
@davison
davison deleted the task/85-contract-drift-provenance-stamp-status-d branch August 26, 2026 19:02
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.

Contract drift: provenance stamp, status detection, roles diff

0 participants