fix(installer): stop duplicating agent instructions; MCP server is the single source of truth (#529) (#538)
The installer wrote a `## CodeGraph` usage block into each agent's
instructions file (CLAUDE.md / AGENTS.md / GEMINI.md / .cursor/rules /
Kiro steering) that duplicated, almost verbatim, the guidance the MCP
server already emits in its `initialize` response — so agents that
surface MCP instructions (Claude Code) read the same playbook twice
every turn.
All 6 instruction-writing targets (claude, cursor, codex, opencode,
gemini, kiro) now stop writing the block. install self-heals by
stripping a block a previous version wrote (uninstall already did), so
the next `codegraph install`/`uninstall` cleans up existing installs;
upgrading the package alone does not (the leftover block is harmless).
server-instructions.ts is now the single source of truth — the two
steers unique to the old template ("trust codegraph, don't re-verify
with grep" and the not-initialized -> `init -i` hint) are ported there.
Removes the now-dead INSTRUCTIONS_TEMPLATE / CLAUDE_MD_TEMPLATE,
claude-md-template.ts, writeClaudeMd / hasClaudeMdSection, and the
Cursor-only wireProjectSurfaces bootstrap. The install log learned a
"Removed" verb. Tests rewritten to the new contract + self-heal
coverage (140/140 installer tests pass).
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
cea78ceb1b
commit
a9c9e76d8c
@@ -28,12 +28,10 @@ import {
|
||||
atomicWriteFileSync,
|
||||
getMcpServerConfig,
|
||||
removeMarkedSection,
|
||||
replaceOrAppendMarkedSection,
|
||||
} from './shared';
|
||||
import {
|
||||
CODEGRAPH_SECTION_END,
|
||||
CODEGRAPH_SECTION_START,
|
||||
INSTRUCTIONS_TEMPLATE,
|
||||
} from '../instructions-template';
|
||||
import { buildTomlTable, removeTomlTable, upsertTomlTable } from './toml';
|
||||
|
||||
@@ -84,7 +82,12 @@ class CodexTarget implements AgentTarget {
|
||||
const files: WriteResult['files'] = [];
|
||||
|
||||
files.push(writeMcpEntry());
|
||||
files.push(writeInstructionsEntry());
|
||||
|
||||
// AGENTS.md is no longer written — the codegraph usage guidance
|
||||
// ships in the MCP server's `initialize` response (issue #529).
|
||||
// Strip a block a previous install left so an upgrade self-heals.
|
||||
const instrCleanup = removeInstructionsEntry();
|
||||
if (instrCleanup.action === 'removed') files.push(instrCleanup);
|
||||
|
||||
return { files };
|
||||
}
|
||||
@@ -111,9 +114,7 @@ class CodexTarget implements AgentTarget {
|
||||
files.push({ path: tomlPath, action: 'not-found' });
|
||||
}
|
||||
|
||||
const instr = instructionsPath();
|
||||
const instrAction = removeMarkedSection(instr, CODEGRAPH_SECTION_START, CODEGRAPH_SECTION_END);
|
||||
files.push({ path: instr, action: instrAction });
|
||||
files.push(removeInstructionsEntry());
|
||||
|
||||
return { files };
|
||||
}
|
||||
@@ -160,22 +161,15 @@ function writeMcpEntry(): WriteResult['files'][number] {
|
||||
return { path: file, action: created ? 'created' : 'updated' };
|
||||
}
|
||||
|
||||
function writeInstructionsEntry(): WriteResult['files'][number] {
|
||||
/**
|
||||
* Strip the marker-delimited CodeGraph block from `~/.codex/AGENTS.md`
|
||||
* if a prior install wrote one. Used by both install (self-heal on
|
||||
* upgrade) and uninstall — see issue #529.
|
||||
*/
|
||||
function removeInstructionsEntry(): WriteResult['files'][number] {
|
||||
const file = instructionsPath();
|
||||
const dir = path.dirname(file);
|
||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
||||
|
||||
const action = replaceOrAppendMarkedSection(
|
||||
file,
|
||||
INSTRUCTIONS_TEMPLATE,
|
||||
CODEGRAPH_SECTION_START,
|
||||
CODEGRAPH_SECTION_END,
|
||||
);
|
||||
const mapped: 'created' | 'updated' | 'unchanged' =
|
||||
action === 'created' ? 'created'
|
||||
: action === 'unchanged' ? 'unchanged'
|
||||
: 'updated';
|
||||
return { path: file, action: mapped };
|
||||
const action = removeMarkedSection(file, CODEGRAPH_SECTION_START, CODEGRAPH_SECTION_END);
|
||||
return { path: file, action };
|
||||
}
|
||||
|
||||
export const codexTarget: AgentTarget = new CodexTarget();
|
||||
|
||||
Reference in New Issue
Block a user