From 0867f57931341d965a4fb95689b87a2f35ec433b Mon Sep 17 00:00:00 2001 From: Dennis Palatov Date: Fri, 20 Mar 2026 23:20:51 -0700 Subject: [PATCH] feat: gitnexus:keep marker preserves custom context sections When is present inside the gitnexus block, analyze only updates the stats line instead of replacing the entire section with the verbose template. Lets users maintain lean custom context without it being overwritten on every reindex. Co-Authored-By: Claude Opus 4.6 (1M context) --- gitnexus/src/cli/ai-context.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gitnexus/src/cli/ai-context.ts b/gitnexus/src/cli/ai-context.ts index 8e18fed7d..d93b32e80 100644 --- a/gitnexus/src/cli/ai-context.ts +++ b/gitnexus/src/cli/ai-context.ts @@ -223,7 +223,24 @@ async function upsertGitNexusSection( ); if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) { - // Replace existing section + const existingSection = existingContent.substring(startIdx, endIdx + GITNEXUS_END_MARKER.length); + + // If the existing section contains , only update the stats line + // This lets users customize the section without it being overwritten on every analyze + if (existingSection.includes('')) { + // Update just the "Indexed as **Name** (N nodes, M edges, P flows)" line + const statsPattern = /Indexed as \*\*[^*]+\*\* \([^)]+\)/; + const statsLine = `Indexed as **${(content.match(/\*\*([^*]+)\*\*/)?.[1]) || 'unknown'}** (${(content.match(/\(([^)]+)\)/)?.[1]) || '0 nodes'})`; + if (statsPattern.test(existingSection)) { + const updatedSection = existingSection.replace(statsPattern, statsLine); + const before = existingContent.substring(0, startIdx); + const after = existingContent.substring(endIdx + GITNEXUS_END_MARKER.length); + await fs.writeFile(filePath, (before + updatedSection + after).trim() + '\n', 'utf-8'); + return 'updated'; + } + } + + // No keep marker — replace existing section with full verbose content const before = existingContent.substring(0, startIdx); const after = existingContent.substring(endIdx + GITNEXUS_END_MARKER.length); const newContent = before + content + after;