MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / removeRulesEntry

Function removeRulesEntry

src/installer/targets/cursor.ts:208–245  ·  view source on GitHub ↗

* Remove the Cursor rules file on uninstall (and as a self-heal on * install — see issue #529). * * Unlike the shared CLAUDE.md / AGENTS.md files (where codegraph owns * only a marker-delimited section), `.cursor/rules/codegraph.mdc` is a * file we create OUTRIGHT — the frontmatter is ours too.

()

Source from the content-addressed store, hash-verified

206 * own content outside our markers do we keep the file (minus our block).
207 */
208function removeRulesEntry(): WriteResult['files'][number] {
209 const file = rulesPath();
210 if (!fs.existsSync(file)) return { path: file, action: 'not-found' };
211
212 let content: string;
213 try {
214 content = fs.readFileSync(file, 'utf-8');
215 } catch {
216 return { path: file, action: 'not-found' };
217 }
218
219 const ourFrontmatter = MDC_FRONTMATTER.trim();
220 const startIdx = content.indexOf(CODEGRAPH_SECTION_START);
221 const endIdx = content.indexOf(CODEGRAPH_SECTION_END);
222
223 // Our marked block is present — strip it, then decide what's left.
224 if (startIdx !== -1 && endIdx > startIdx) {
225 const before = content.substring(0, startIdx).trimEnd();
226 const after = content.substring(endIdx + CODEGRAPH_SECTION_END.length).trimStart();
227 const remainder = (before + (before && after ? '\n\n' : '') + after).trim();
228 if (remainder === '' || remainder === ourFrontmatter) {
229 try { fs.unlinkSync(file); } catch { /* ignore */ }
230 } else {
231 atomicWriteFileSync(file, remainder + '\n');
232 }
233 return { path: file, action: 'removed' };
234 }
235
236 // No block, but the file is still our pristine frontmatter-only file
237 // — it's ours, so remove it.
238 if (content.trim() === ourFrontmatter) {
239 try { fs.unlinkSync(file); } catch { /* ignore */ }
240 return { path: file, action: 'removed' };
241 }
242
243 // Foreign content we don't recognize — leave it alone.
244 return { path: file, action: 'not-found' };
245}
246
247export const cursorTarget: AgentTarget = new CursorTarget();

Callers 2

installMethod · 0.85
uninstallMethod · 0.85

Calls 2

atomicWriteFileSyncFunction · 0.90
rulesPathFunction · 0.85

Tested by

no test coverage detected