Skip to content

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

Description

What happens

When openwiki code mode runs against a repository whose AGENTS.md/CLAUDE.md contains an unmarked ## OpenWiki section (written by a version before the <!-- OPENWIKI:START/END --> markers existed, or hand-copied), the marker-based upsert in writeCodeModeAgentSnippet (src/code-mode.ts) finds no markers and appends a second ## OpenWiki section instead of replacing the legacy one. Subsequent runs keep the duplicate forever: the marked block is refreshed in place, but the legacy section is never detected or removed.

Reproduction — visible in this repo's own root files

CLAUDE.md and AGENTS.md at the repository root both currently contain the duplication:

  • an unmarked ## OpenWiki section at line 1 (old snippet wording: "This repository has documentation located in the /openwiki directory…"), and
  • the managed block with a second ## OpenWiki inside <!-- OPENWIKI:START --> / <!-- OPENWIKI:END --> at lines 13–21.

Every agent that reads these files sees two adjacent, slightly-contradictory OpenWiki sections.

Why it matters

The agent files are the product's integration surface — coding agents are told to trust them for orientation. Duplicated/stale instruction blocks propagate confusion to every consumer, and the duplication grows worse for any user who upgraded across the marker introduction.

Expected

A refresh should own exactly one OpenWiki section: detect a legacy unmarked ## OpenWiki section, replace it in place (or remove it when a marked block already exists), while leaving user-authored sections that merely share the heading untouched.

I have a tightly-scoped fix with regression tests ready — PR incoming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions