MCPcopy
hub / github.com/upstash/context7 / uninstallRule

Function uninstallRule

packages/cli/src/commands/remove.ts:354–401  ·  view source on GitHub ↗
(agentName: SetupAgent, scope: Scope)

Source from the content-addressed store, hash-verified

352}
353
354async function uninstallRule(agentName: SetupAgent, scope: Scope): Promise<CleanupStatus> {
355 const agent = getAgent(agentName);
356 const rule = agent.rule;
357
358 if (rule.kind === "file") {
359 const rulePath =
360 scope === "global" ? rule.dir("global") : join(process.cwd(), rule.dir("project"));
361 const targetPath = join(rulePath, rule.filename);
362
363 try {
364 await rm(targetPath);
365 return { status: "removed", path: targetPath };
366 } catch (err) {
367 const error = err as NodeJS.ErrnoException;
368 if (error.code === "ENOENT") return { status: "not found", path: targetPath };
369 return { status: `failed: ${error.message}`, path: targetPath };
370 }
371 }
372
373 const filePath =
374 scope === "global" ? rule.file("global") : join(process.cwd(), rule.file("project"));
375
376 try {
377 const existing = await readFile(filePath, "utf-8");
378 if (!existing.includes(CONTEXT7_SECTION_MARKER)) {
379 return { status: "not found", path: filePath };
380 }
381
382 const escapedMarker = CONTEXT7_SECTION_MARKER.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
383 const updated = existing
384 .replace(new RegExp(`\\n?${escapedMarker}\\n[\\s\\S]*?${escapedMarker}\\n?`, "m"), "")
385 .replace(/\n{3,}/g, "\n\n")
386 .replace(/^\n+/, "")
387 .trimEnd();
388
389 if (updated.length === 0) {
390 await rm(filePath);
391 } else {
392 await writeFile(filePath, `${updated}\n`, "utf-8");
393 }
394
395 return { status: "removed", path: filePath };
396 } catch (err) {
397 const error = err as NodeJS.ErrnoException;
398 if (error.code === "ENOENT") return { status: "not found", path: filePath };
399 return { status: `failed: ${error.message}`, path: filePath };
400 }
401}
402
403async function uninstallSkills(
404 agentName: SetupAgent,

Callers 1

uninstallAgentFunction · 0.85

Calls 1

getAgentFunction · 0.85

Tested by

no test coverage detected