Implement the following plan: Plan: Fix Remediation Direction for CLAUDE.md/AGENTS.md…
- User
Implement the following plan:
Plan: Fix Remediation Direction for CLAUDE.md/AGENTS.md Colocated Pairs
Context
When both
AGENTS.mdandCLAUDE.mdcoexist in a directory, the system rule is:- AGENTS.md = single source of truth (canonical)
- CLAUDE.md = pointer only, containing solely
@AGENTS.md
The bug: a remediation plan chose the opposite direction — making CLAUDE.md canonical and having AGENTS.md redirect to it. This caused two problems:
- Wrong canonical file (CLAUDE.md instead of AGENTS.md)
- CLAUDE.md received content beyond the single
@AGENTS.mdline
Root Causes
Root Cause 1: stale evaluation metadata
evaluationData.result?.metadata?.projectContext?.colocatedPairsisundefinedfor evaluations predating the colocatedPairs feature. With emptycolocatedPairs, the remediation engine skips consolidation and omits the consolidation notice from all prompts. The AI planner then encounters both files with real content and makes its own judgment — choosing CLAUDE.md as canonical.Evidence:
engine.ts:188reads pairs from metadata; if evaluation was old,colocatedPairs === []→ no notice → no constraint.Root Cause 2: consolidation notice is too weak
The current notice (in
buildConsolidationNotice) says:"AGENTS.md is the single source of truth. Never edit CLAUDE.md files that contain
@AGENTS.md."This is soft language. The AI planner read the files, saw AGENTS.md had quality problems, and decided CLAUDE.md was a better canonical. The notice didn't prevent it.
Root Cause 3: no validation on the generated plan
Phase 1 generates a free-form markdown plan. There is no post-generation validation to catch a plan that targets CLAUDE.md as a canonical destination.
Fix
Change 1: Re-detect colocated pairs at remediation time (backward compat)
File:
src/shared/remediation/engine.tsAfter the working directory is set up and files exist on disk (before prompt generation), re-scan for colocated pairs using
identifyColocatedPairs()from the file-system module. Merge with any pairs already stored in evaluation metadata (union, dedup by directory). This ensures old evaluations without stored colocatedPairs still trigger correct consolidation behavior.typescript Assistant
Now let me check the
identifyColocatedPairsfunction signature and the existing tests:Assistant
Let me check how
findAgentsFilesworks and whatagentsFilePathscontains:Assistant
Now I have everything I need. Let me implement all changes:
Assistant
Change 1 & 4: Re-detect colocated pairs + plan validation in
engine.tsAssistant
Now replace the colocated pairs detection block to re-scan at remediation time:
Assistant
Now add plan validation after Phase 1 generates
errorPlan. Find the right insertion point:Assistant
Change 2 & 3: Harden consolidation notice and add planning constraints in
prompt-generator.tsAssistant
Now add planning constraints to
buildErrorPlanPrompt():Assistant
Now add planning constraints to
buildSuggestionPlanPrompt():Assistant
Now let's run the tests to make sure everything passes:
Assistant
The 2 failing tests are in
prompt-generator- the consolidation notice tests. Let me check them:Assistant
The failing tests check for the old notice text. I need to update them to match the new hardened notice:
Assistant
Also update the test that checks there's no notice when no pairs - the text changed from "File Consolidation Notice" to "CRITICAL FILE RULE":
Assistant
Now run the tests again:
Assistant
All 1309 tests pass. Now run lint:
Assistant
Biome wants to collapse the multi-line
toContaincall onto one line. Let me fix:Assistant
All tests pass and lint is clean. Let me summarize the changes made:
Assistant
All 4 changes are implemented and passing:
Change 1 — Re-detect colocated pairs at remediation time (
engine.ts:187-215):- Imports
identifyColocatedPairsfrom the file-system module - Converts
pc?.agentsFilePaths(relative) to absolute paths, then re-runs detection - Merges discovered pairs with stored
pc?.colocatedPairs(dedup by directory) - Old evaluations without stored
colocatedPairsnow correctly trigger consolidation behavior
Change 2 — Hardened consolidation notice (
prompt-generator.ts:buildConsolidationNotice()):- Replaced "File Consolidation Notice" section with
## ⚠ CRITICAL FILE RULE — CLAUDE.md IS READ-ONLY - Explicit per-pair path display (
agentsPathis canonical, contains only )
- Imports