Class ClaudeMdMerge

java.lang.Object
network.ike.plugin.ws.bootstrap.ClaudeMdMerge

public final class ClaudeMdMerge extends Object
Non-destructive regeneration of a subproject CLAUDE.md (IKE-Network/ike-issues#917, #920).

ws:scaffold-init regenerates each subproject's CLAUDE.md from a template on every run. A naive full overwrite destroyed two kinds of content the template does not own:

  • #920 — the ike-managed regions that ike:scaffold-publish appends (<!-- BEGIN ike-managed: <name> --> … <!-- END ike-managed: <name> -->), causing the two generators to ping-pong the file on alternate runs.
  • #917 — hand-authored ## sections a developer added (e.g. a project's fast-dev build notes), silently dropped on regeneration.

merge(String, String) is a pure function so it can be unit-tested without touching the filesystem. It:

  1. extracts every ike-managed region from the existing file verbatim (byte-for-byte, on its own lines, so the emitting plugin's line-exact marker matching still locates it) and re-appends them after the freshly generated template;
  2. returns any top-level (## ) section whose heading the template does not itself produce as a rescued section, for the caller to preserve in CLAUDE-<name>.md — the file the scaffold never overwrites — rather than carrying it into the regenerated CLAUDE.md.

Template-owned sections are regenerated from the template (that is the point of regeneration); only sections the template does not emit are treated as hand-authored. A section added as prose inside a template-owned section (no new ## heading) is a residual gap — it is regenerated with its section — but the reported real-world losses were whole sections, which this preserves.

  • Method Details

    • merge

      public static ClaudeMdMerge.Result merge(String existing, String generated)
      Merge existing CLAUDE.md content with a freshly generated template.
      Parameters:
      existing - the current on-disk CLAUDE.md, or null when the file does not exist yet (fresh write)
      generated - the freshly generated template content
      Returns:
      the merged content plus any hand-authored sections to rescue
    • normalize

      public static String normalize(String text)
      The text with every CRLF, and any lone CR, as LF; null stays null.