Skip to content

fix: replace legacy unmarked OpenWiki sections instead of appending a duplicate#362

Open
Wenyu Chiou (WenyuChiou) wants to merge 1 commit into
langchain-ai:mainfrom
WenyuChiou:fix/agent-snippet-legacy-dedupe
Open

fix: replace legacy unmarked OpenWiki sections instead of appending a duplicate#362
Wenyu Chiou (WenyuChiou) wants to merge 1 commit into
langchain-ai:mainfrom
WenyuChiou:fix/agent-snippet-legacy-dedupe

Conversation

@WenyuChiou

Copy link
Copy Markdown

What

writeCodeModeAgentSnippet now removes legacy unmarked ## OpenWiki sections 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:

  • A bare ## OpenWiki section 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).
  • 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.
  • When a marked block already exists, the legacy section alongside it is removed (this is exactly the state of this repository's own root 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 ## OpenWiki sections that are never reconciled — as visible in this repo's own root files.

Design tradeoff, stated explicitly: if a user hand-wrote a ## OpenWiki section that references openwiki/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

  • 5 new regression tests in 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 in test/env-behavior.test.ts (0600-permission and HOME-resolution checks), reproduce on pristine main on win32, and are unrelated to this change — CI (ubuntu) should be fully green.

Fixes #361

🤖 Generated with Claude Code

… 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>
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.

bug: code mode appends a duplicate "## OpenWiki" section when a legacy unmarked section exists

1 participant