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

Function removeRulesEntry

src/installer/targets/cursor.ts:209–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

207 * own content outside our markers do we keep the file (minus our block).
208 */
209function removeRulesEntry(): WriteResult['files'][number] {
210 const file = rulesPath();
211 if (!fs.existsSync(file)) return { path: file, action: 'not-found' };
212
213 let content: string;
214 try {
215 content = fs.readFileSync(file, 'utf-8');
216 } catch {
217 return { path: file, action: 'not-found' };
218 }
219
220 const ourFrontmatter = MDC_FRONTMATTER.trim();
221
222 // Our marked block is present — strip it, then decide what's left. Only
223 // well-formed blocks are stripped, so a stray marker never takes the
224 // user's rules with it (#2506).
225 const remainder = stripMarkedSections(content, CODEGRAPH_SECTION_START, CODEGRAPH_SECTION_END);
226 if (remainder !== null) {
227 const rest = remainder.trim();
228 if (rest === '' || rest === ourFrontmatter) {
229 try { fs.unlinkSync(file); } catch { /* ignore */ }
230 } else {
231 atomicWriteFileSync(file, remainder);
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 3

stripMarkedSectionsFunction · 0.90
atomicWriteFileSyncFunction · 0.90
rulesPathFunction · 0.70

Tested by

no test coverage detected