fix: replace legacy unmarked OpenWiki sections instead of appending a duplicate#362
Open
Wenyu Chiou (WenyuChiou) wants to merge 1 commit into
Open
Conversation
… duplicate Versions of OpenWiki before the OPENWIKI:START/END managed-block markers wrote a bare "## OpenWiki" section into AGENTS.md and CLAUDE.md. When a newer version runs against such a file, the marker-based upsert never matches, so it appends a second "## OpenWiki" section next to the legacy one - this repository's own root CLAUDE.md and AGENTS.md both exhibit the duplication. writeCodeModeAgentSnippet now strips bare "## OpenWiki" sections outside the markers before the upsert, but only when the section references the generated wiki entrypoint (openwiki/quickstart.md); same-named user-authored sections that do not reference it are preserved. When the markers are absent, the refreshed block is inserted where the legacy section was instead of being appended at the end of the file. Adds five regression tests; three fail against the previous code. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
writeCodeModeAgentSnippetnow removes legacy unmarked## OpenWikisections before running the marker-based upsert, so refreshes no longer append a duplicate section next to one written by a pre-marker version of OpenWiki:## OpenWikisection outside the<!-- OPENWIKI:START/END -->markers is treated as OpenWiki-owned only when it references the generated wiki entrypoint (openwiki/quickstart.md) — user-authored sections that merely share the heading are preserved (covered by a test).CLAUDE.md/AGENTS.md, which both currently carry the duplicate — unmarked section at line 1, managed block at lines 13–21).Why
The agent files are the integration surface coding agents are told to trust. Any repo that adopted OpenWiki before the managed-block markers (or hand-copied the snippet) ends up with two adjacent, drifting
## OpenWikisections that are never reconciled — as visible in this repo's own root files.Design tradeoff, stated explicitly: if a user hand-wrote a
## OpenWikisection that referencesopenwiki/quickstart.md, this change replaces it with the managed block. The signature heuristic is what keeps unrelated same-named sections safe; happy to tighten it further if you'd prefer stricter matching.How tested
test/code-mode.test.ts, mirroring the existing temp-repo patterns: legacy section replaced in place (position asserted), legacy section removed when a marked block coexists (the dogfood shape), user-authored same-named section preserved, idempotency after legacy replacement, plus the existing 4 tests unchanged. 3 of the 5 new tests fail against the previous code — verified before applying the fix.pnpm run format,pnpm run lint,pnpm test: 299/301 pass on my machine (Windows). The 2 failures are intest/env-behavior.test.ts(0600-permission and HOME-resolution checks), reproduce on pristinemainon win32, and are unrelated to this change — CI (ubuntu) should be fully green.Fixes #361
🤖 Generated with Claude Code