Implement the following plan: Plan: AI-Powered Intelligent Merge for AGENTS.md/CLAUDE.md…
- User
Implement the following plan:
Plan: AI-Powered Intelligent Merge for AGENTS.md/CLAUDE.md Consolidation
Context
When a repo has both AGENTS.md and CLAUDE.md, the remediation system consolidates them before running fixes. Currently,
consolidateColocatedFiles()insrc/shared/remediation/file-consolidator.ts:49does a naive concatenation with a<!-- Merged from CLAUDE.md -->separator. This creates duplicate sections (commands, architecture, project structure appear twice) because both files typically overlap. The downstream AI then works on a bloated, duplicated file — and evaluators flag the duplicates as issues.Goal: Replace naive concatenation with an AI-powered intelligent merge that deduplicates content, integrates unique CLAUDE.md content into appropriate AGENTS.md sections, and produces a clean single file.
Implementation Steps
1. Create merge prompt builder
New file:
src/shared/remediation/merge-prompt.ts- Export
buildMergePrompt(agentsContent: string, claudeContent: string): string - Prompt instructs the AI to:
- Use AGENTS.md structure as the base skeleton
- Identify equivalent sections across both files and keep the more complete version
- Insert unique CLAUDE.md sections at relevant locations
- Never duplicate information
- Output raw merged markdown (no code fences, no preamble)
2. Create AI-powered consolidation function
New file:
src/shared/remediation/ai-file-consolidator.ts- Export
consolidateColocatedFilesWithAI(workDir, pairs, provider)→Promise<AIConsolidationResult> AIConsolidationResult = { results: ConsolidationResult[], stats?: IPromptExecutionStats }- For each pair:
- Skip if CLAUDE.md is already
@AGENTS.md(same as naive) - Read both files, build merge prompt, call
provider.invokeWithRetry(prompt, { writeMode: false }) - Validate AI output (non-empty, reasonable length)
- Write merged content to AGENTS.md, write
@AGENTS.mdto CLAUDE.md - On AI failure: fall back to naive
consolidateColocatedFiles()for that pair only
- Skip if CLAUDE.md is already
- Accumulate cost/tokens/duration stats across all pairs
3. Add
consolidationStatsto result type - Export
Assistant
I'll start by reading the key files to understand the current implementation.
Assistant
Now let me check the provider interface and existing test patterns.
Assistant
Now I have a clear picture. Let me implement all the changes.
Assistant
Now I need to wire up the AI consolidation in the engine. The key changes:
- Move
providercreation before the consolidation block - Replace naive consolidation with AI-powered version
- Track consolidation stats in totals and return object
- Move
Assistant
Now move the provider creation before the consolidation block and replace the naive consolidation call:
Assistant
Now replace the naive consolidation call with AI-powered version:
Assistant
Now remove the duplicate
const providerdeclaration:Assistant
Now include consolidation stats in the totals and return object:
Assistant
Now let me write the tests.
Assistant
One test failure - the
trimEnd()in the AI consolidator causes a trailing newline difference. Let me fix the test:Assistant
All 1318 tests pass. Now let me run lint.
Assistant
All clean. Let me also verify the existing
file-consolidator.test.tsstill passes (it checks naive merge behavior which should be untouched):Assistant
All done. Here's a summary of the changes:
New files:
src/shared/remediation/merge-prompt.ts— Builds the AI merge prompt instructing deduplication, using AGENTS.md as the base skeletonsrc/shared/remediation/ai-file-consolidator.ts—consolidateColocatedFilesWithAI()that calls the AI provider for intelligent merge, with fallback to naive concatenation on failuresrc/shared/remediation/merge-prompt.test.ts— 4 tests for prompt structuresrc/shared/remediation/ai-file-consolidator.test.ts— 5 tests covering: happy path, empty AI output fallback, error fallback, skip-already-referenced, and partial failure across multiple pairs
Modified files:
src/shared/types/remediation.ts— AddedconsolidationStats?: IPromptExecutionStatstoIRemediationResultsrc/shared/remediation/engine.ts— Moved provider creation before consolidation block, replacedconsolidateColocatedFiles()withconsolidateColocatedFilesWithAI(), included consolidation cost/tokens in running totals, added to return object. The post-execution re-consolidation safety net at line 628 remains naive as planned.
- User
Files Changed
File Action src/shared/remediation/merge-prompt.tsNEW src/shared/remediation/ai-file-consolidator.tsNEW src/shared/types/remediation.tsMODIFY — add consolidationStatsfieldsrc/shared/remediation/engine.tsMODIFY — use AI consolidation, track stats src/shared/remediation/ai-file-consolidator.test.tsNEW src/shared/remediation/merge-prompt.test.tsNEW Verification
bun run test— all existing tests pass, new tests passbun run lint— no lint errors- Manual test: run remediation on a repo with both AGENTS.md and CLAUDE.md → verify the merged file has no
<!-- Merged from CLAUDE.md -->separator, no duplicate sections, and all unique content preserved - Verify fallback: if AI provider fails, the naive concatenation still works
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /Users/cedricteyton/.REDACTED.jsonl
- User
Implementation Steps
- User
commit
Assistant
I see there are also unrelated frontend changes in the diff. I'll only stage the files related to this feature.
Assistant
TypeScript error - need to fix the
Usagetype in the test mock. Let me check theUsagetype.Assistant
Need to add the missing cache fields to the usage mocks.
Assistant
Lint formatting issue. Let me fix it.
Assistant
Commit successful. All pre-commit hooks passed (tests, lint, typecheck) and the commit was created:
code8225e0f Replace naive AGENTS.md/CLAUDE.md concatenation with AI-powered intelligent merge 9 files changed, 542 insertions(+), 5 deletions(-)