UNPKG

@brianlovin/notion-skills

Version:

Sync agent skills from a Notion database to Claude Code, Codex, OpenCode, Cursor, Gemini CLI.

55 lines 2.2 kB
import { existsSync } from "node:fs"; import { rm } from "node:fs/promises"; import { join } from "node:path"; import { readManifest, writeManifest } from "./manifest.js"; import { MANIFEST_FILE, SKILLS_STORE } from "./paths.js"; import { writeScope } from "./scope.js"; import { removeSymlink, targetSkillPath, targetsForKeys } from "./targets.js"; /** * Drop a source from scope.json and reconcile manifest + filesystem. * * - mode = "uninstall": delete skill dirs and target symlinks too. * - mode = "keep": leave dirs and symlinks; just clear the manifest * entries so the skills become local-only drafts. * * Mutates `scope.sources` in place and writes both files. Used by the * `source remove` command and by sync's deleted-source disconnect flow. */ export async function applySourceRemoval(scope, key, mode) { const manifest = await loadManifestForKey(scope, key); const installedFromSource = manifest ? Object.entries(manifest.skills).filter(([, e]) => e.source_key === key) : []; if (manifest) { if (mode === "uninstall") { const targets = targetsForKeys(scope.targets); for (const [localSlug] of installedFromSource) { const dir = join(SKILLS_STORE, localSlug); if (existsSync(dir)) await rm(dir, { recursive: true, force: true }); for (const t of targets) { await removeSymlink(targetSkillPath(t, localSlug)); } } } for (const [localSlug] of installedFromSource) { delete manifest.skills[localSlug]; } await writeManifest(MANIFEST_FILE, manifest); } scope.sources = scope.sources.filter((s) => s.key !== key); await writeScope({ sources: scope.sources, targets: scope.targets, gen_agent: scope.gen_agent, }); return { mode, affectedLocalSlugs: installedFromSource.map(([slug]) => slug), }; } async function loadManifestForKey(scope, key) { const fallbackKey = scope.sources[0]?.key ?? key; return readManifest(MANIFEST_FILE, fallbackKey); } //# sourceMappingURL=source-state.js.map