GitNexus/gitnexus/src
azizur100389 e262dda35b
fix(cli): only match <!-- gitnexus:* --> markers at section position (#1041) (#1042)
`upsertGitNexusSection` in ai-context.ts uses `indexOf` to locate the
bounds of the GitNexus section in CLAUDE.md / AGENTS.md before
replacement. `indexOf` matches the first occurrence of the marker
anywhere in the file, including inline prose references in backtick-
quoted fragments mid-sentence.

The shipped CLAUDE.md contains exactly such a reference ("See the
`<!-- gitnexus:start --> … <!-- gitnexus:end -->` block in AGENTS.md
for the canonical MCP tools..."). Running `gitnexus analyze` on a
fresh install matches those inline markers as section delimiters and
replaces the prose between them with the full ~100-line injected
block, breaking the backtick and corrupting markdown for every user.

Fix: new private `findSectionMarkerIndex` helper that only matches
markers occupying their own line — preceded by `\n` or start-of-file,
followed by `\n` / `\r` (CRLF files) / end-of-file. `\r` is explicit
so CRLF-terminated sections on Windows (core.autocrlf = true) still
match. The generator always emits markers alone on their line, so
every legitimate section continues to update in place; only inline
prose references now fall through to the append branch, which leaves
existing content untouched.

Two new unit tests:
- #1041 regression — seed CLAUDE.md with the shipped inline prose
  line, run analyze twice, assert inline prose preserved verbatim
  and marker counts stay at 2/2 (1 inline + 1 section-position)
- CRLF handling — seed a CRLF file with inline prose + legitimate
  section, run analyze, assert section replaced in place, inline
  prose preserved, stale stub content removed

No destructive ops, no bypass flags, no new deps. Behaviour change
is strictly narrowing — files that previously updated correctly
still do; files that previously got corrupted now fall through to
the safer append branch.

Closes #1041.
2026-04-23 07:58:07 +01:00
..
cli fix(cli): only match <!-- gitnexus:* --> markers at section position (#1041) (#1042) 2026-04-23 07:58:07 +01:00
config fix(ignore): respect negation patterns in .gitnexusignore (#654) 2026-04-06 08:32:47 +01:00
core feat(cli): Fingerprint indexed repos by remote URL to detect sibling-clone graph drift (#982) 2026-04-21 21:58:54 +01:00
lib feat: configure prettier with pre-commit hook (#563) 2026-03-28 14:58:04 +00:00
mcp feat(cli): Fingerprint indexed repos by remote URL to detect sibling-clone graph drift (#982) 2026-04-21 21:58:54 +01:00
server feat(embeddings): AST-aware chunking with offset-based splitting (#889) 2026-04-16 22:55:04 +01:00
storage feat(cli): Fingerprint indexed repos by remote URL to detect sibling-clone graph drift (#982) 2026-04-21 21:58:54 +01:00
types feat(ingestion): language-agnostic heritage extractor with config+factory pattern (#890) 2026-04-17 17:51:17 +01:00