Skip to content

Fix #1982: codev update no longer reports unedited CLAUDE.md / AGENTS.md as conflicts; dry run matches the real run - #1984

Open
waleedkadous wants to merge 13 commits into
mainfrom
builder/bugfix-1982
Open

waleedkadous wants to merge 13 commits into
mainfrom
builder/bugfix-1982

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

codev update reported CLAUDE.md and AGENTS.md as conflicts on a project nobody had edited, and wrote .codev-new copies byte-identical to them. Its --dry-run also printed hot-tier, cold-tier and managed-block lines the real run did not. Root docs are now compared with the template outside the managed block, and the dry run computes the same result as the real run.

Fixes #1982

Root Cause

  1. False conflicts. copyRootFiles (packages/codev/src/lib/scaffold.ts), which update calls with handleConflicts: true, compared nothing: any existing CLAUDE.md / AGENTS.md was a conflict, and the template was written beside it. update.ts used to skip a doc identical to the template (3cb6232, Dec 2025). That check was lost when Spec 618 (e66a014, Mar 2026) moved update onto copyRootFiles, a helper written for adopt. The issue's guess (a comparison made before the block is rendered) was wrong: there was no comparison. The templates already carry the rendered managed block, which is why the .codev-new was byte-identical. The existing "second update" test asserted only result.conflicts (skills), never rootConflicts, so it never caught this.
  2. Dry run disagreed. update.ts printed the hot-tier, cold-tier and managed-block lines unconditionally under --dry-run. The real run prints only what copyHotTierDefaults / copyColdTierDefaults copied and what syncHotContextBlock changed.

Fix

  • Comparison. copyRootFiles now asks matchesTemplate: does the doc match the template outside the managed block? Both sides go through withEmptyHotBlock (managed-block.ts), which leaves them as the block refresh would but with the block emptied. So the block's content, or its absence, never counts as an edit. The template varies only by {{PROJECT_NAME}}, filled from the checkout's directory name, so the placeholder matches any name. A team-mate's clone under another directory name is not a conflict. Line endings are normalised, as skills already do, so a Windows CRLF checkout is not a conflict either.
    • Matches: up to date. No conflict, no .codev-new.
    • Edited outside the block: a conflict as before, and the edit is kept. A .codev-new is never written identical to the file beside it.
  • Edits inside the managed block are not adopter content. The block is regenerated from codev/resources/{arch,lessons}-critical.md on every update (syncHotContextBlock always did this, and the marker says do not edit). Such an edit is replaced and reported as ~ (hot-tier block refreshed) <doc>, never as a conflict.
  • One code path for the dry run. copyHotTierDefaults, copyColdTierDefaults and syncHotContextBlock take dryRun, and the flag only decides whether to write. When rendering the block, a dry run counts the hot files it would have created as present. Both modes print the same per-file lines; the dry run adds "would be". The real run's block line changes from ~ (hot-tier block) to ~ (hot-tier block refreshed) so that the only difference is that wording.
  • Adjacent fix: leftover .codev-new copies. A .codev-new beside an up-to-date doc that matches the template the same way is removed, and reported as - (removed, nothing left to merge) <file> (dry run: would be removed). This cleans up the byte-identical leftovers this bug wrote in adopters' projects, following skills' removeResolvedCodevNew precedent. A .codev-new with any other content is kept.
  • Side effects on codev adopt, which shares copyRootFiles. An adopted repo whose root doc already matches the template is no longer a conflict; the block is still injected on the next codev update, as before. Adopt can now remove a resolved leftover .codev-new, which it logs.
  • codev/resources/commands/codev.md and its skeleton twin now say how root docs are judged.

Known limit (out of scope, pinned by a test)

A doc an adopter never edited, written by an older release whose template has since changed outside the block, is still a conflict. The template changed 11 times since May. Root docs carry no record of the version a release installed, so such a doc cannot be told from an edit. The doc is kept and the new template is offered as .codev-new, as before. The test known limit: an unedited doc from an older template that changed outside the block is still a conflict records this as a decision. Remedy I see: give root docs a shipped-template hash list like skills' SHIPPED_SKILL_HASHES (generated from git history), hashed after the same normalisation used here (managed block emptied, project name as wildcard, LF). A doc matching any shipped version is then unedited and can be replaced.

Test Plan

  • Regression test packages/codev/src/__tests__/bugfix-1982-update-root-docs.test.ts. It runs the real init() then update(), with execSync stubbed only for git init / codev doctor. The original 10 cases fail on the pre-fix source and pass with the fix. Each later case also failed on the commit before it. It covers:
    • untouched project: zero conflicts, zero .codev-new, docs unchanged;
    • edit outside the block: one conflict, edit kept, template as .codev-new;
    • edit inside the block: block refresh, no conflict;
    • missing block: put back, no conflict;
    • leftover .codev-new resolved and reported;
    • renamed checkout: up to date, its leftover resolved;
    • CRLF checkout: up to date;
    • edited skill: still kept with .codev-new;
    • the known limit;
    • dry run against real run, on the same project, comparing report and result in four scenarios: untouched; edited outside and inside the block; leftover .codev-new; one hot file, the cold files and AGENTS.md missing. The comparison runs in agent mode. The one documented divergence is the bootstrap-docs hint, which a dry run never prints.
  • Build passes, and the full suite passes (porch fix-phase checks, re-run after the CMAP follow-ups).
  • Verified on an installed build (four packed tarballs, npm install -g --prefix into a scratch prefix; no global install, no Tower restart), outside any repository. codev init fresh --yes && cd fresh && codev update --dry-run prints Already up to date!, and so does the real run, with no .codev-new. With CLAUDE.md edited outside the block, a skill edited, and AGENTS.md edited inside the block, both modes print the same two conflicts (edits kept) and an AGENTS.md block refresh. With governance files deleted, both modes print the same per-file + (new) lines.

No platform code (processes, shells, paths, terminals) is touched, so the Windows workflow was not dispatched.

CMAP

  • codex: REQUEST_CHANGES, twice, on one point only: the chore(porch): … commits lack the [Bugfix #1982] prefix. Rebutted: porch writes those commits itself for state transitions. 78 of the last 200 commits on main are chore(porch) commits merged unchanged. Rewriting them would mean force-pushing porch's state history. codex found no code, test, security or documentation issue. Its second pass also caught a stale function name in this body, now corrected.
  • claude: APPROVE (first pass), then COMMENT (second pass). Folded in from its notes: renamed-checkout false conflicts; logging the leftover removal in both modes and in adopt; CRLF checkouts; a renamed checkout's leftover. Not taken: an unreadable (EACCES) root doc now fails the update loudly instead of being treated as a conflict. That follows this project's fail-fast rule; a fallback would hide the fault. Noted as pre-existing and out of scope: a CRLF doc's block is rewritten with LF on its first refresh, as it always was.

… outside the managed block; dry run reports what the real run does

copyRootFiles treated any existing CLAUDE.md / AGENTS.md as a conflict and wrote
the template beside it, comparing nothing (the identical-content check was lost
when Spec 618 moved update onto this adopt helper). A doc that matches the
template outside the managed block is now up to date; an edit inside the block
is regenerated and reported as a block refresh; a .codev-new holding exactly the
template beside an up-to-date doc is removed.

The hot-tier, cold-tier and managed-block steps now run one code path in both
modes; --dry-run computes the same result and writes nothing.
…its outside the block conflict and are kept; dry run matches the real run

Also pins the known limit: an unedited doc from an older template that changed
outside the block is still a conflict.
…hes; report a resolved .codev-new

The template varies only by {{PROJECT_NAME}}, filled from the checkout's directory
name, so a clone under another name was a false conflict on both docs. The
comparison now treats the placeholder as any name. A .codev-new removed beside an
up-to-date doc is reported in update (both modes) and adopt instead of vanishing.
…dev-new is reported, in dry and real runs alike
…opy is judged the way the doc is

Line endings are normalised before the comparison, as skills already do, so a
Windows checkout with autocrlf is not a false conflict. A leftover .codev-new is
resolved when it matches the template the same way the doc does (any project
name, outside the block), so a renamed checkout's leftover is cleaned up too.
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.

codev update reports false conflicts on CLAUDE.md and AGENTS.md in an unedited project

1 participant