@agents-inc/cli 0.86.0 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/chunk-5UJJQFET.js +564 -0
  3. package/dist/chunk-5UJJQFET.js.map +1 -0
  4. package/dist/{chunk-GED2F75H.js → chunk-7FFNNDJQ.js} +176 -120
  5. package/dist/chunk-7FFNNDJQ.js.map +1 -0
  6. package/dist/{chunk-BV2MIQ3O.js → chunk-I5AZKNNL.js} +1 -1
  7. package/dist/chunk-I5AZKNNL.js.map +1 -0
  8. package/dist/chunk-J6PI73YV.js +68 -0
  9. package/dist/chunk-J6PI73YV.js.map +1 -0
  10. package/dist/commands/compile.js +26 -20
  11. package/dist/commands/compile.js.map +1 -1
  12. package/dist/commands/diff.js +681 -82
  13. package/dist/commands/diff.js.map +1 -1
  14. package/dist/commands/doctor.js +30 -58
  15. package/dist/commands/doctor.js.map +1 -1
  16. package/dist/commands/edit.js +164 -32
  17. package/dist/commands/edit.js.map +1 -1
  18. package/dist/commands/eject.js +177 -27
  19. package/dist/commands/eject.js.map +1 -1
  20. package/dist/commands/import/skill.js +197 -33
  21. package/dist/commands/import/skill.js.map +1 -1
  22. package/dist/commands/info.js +41 -34
  23. package/dist/commands/info.js.map +1 -1
  24. package/dist/commands/init.js +3 -6
  25. package/dist/commands/new/agent.js +140 -44
  26. package/dist/commands/new/agent.js.map +1 -1
  27. package/dist/commands/new/marketplace.js +4 -4
  28. package/dist/commands/new/marketplace.js.map +1 -1
  29. package/dist/commands/new/skill.js +194 -30
  30. package/dist/commands/new/skill.js.map +1 -1
  31. package/dist/commands/outdated.js +1 -3
  32. package/dist/commands/outdated.js.map +1 -1
  33. package/dist/commands/search.js +162 -65
  34. package/dist/commands/search.js.map +1 -1
  35. package/dist/commands/uninstall.js +259 -62
  36. package/dist/commands/uninstall.js.map +1 -1
  37. package/dist/commands/update.js +232 -163
  38. package/dist/commands/update.js.map +1 -1
  39. package/dist/components/skill-search/skill-search.js +1 -1
  40. package/dist/hooks/init.js +2 -4
  41. package/dist/hooks/init.js.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/chunk-BV2MIQ3O.js.map +0 -1
  44. package/dist/chunk-DCVCFBQ7.js +0 -1800
  45. package/dist/chunk-DCVCFBQ7.js.map +0 -1
  46. package/dist/chunk-GED2F75H.js.map +0 -1
  47. package/dist/chunk-O5ZWS26C.js +0 -166
  48. package/dist/chunk-O5ZWS26C.js.map +0 -1
  49. package/dist/chunk-XQK4S22C.js +0 -202
  50. package/dist/chunk-XQK4S22C.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli/lib/operations/detect-both-installations.ts","../src/cli/lib/operations/load-source.ts","../src/cli/lib/operations/get-dashboard-data.ts","../src/cli/lib/operations/detect-project.ts","../src/cli/lib/operations/load-agent-defs.ts","../src/cli/lib/operations/copy-local-skills.ts","../src/cli/lib/operations/install-plugin-skills.ts","../src/cli/lib/operations/uninstall-plugin-skills.ts","../src/cli/lib/operations/collect-scoped-skill-dirs.ts","../src/cli/lib/operations/compare-skills.ts","../src/cli/lib/operations/ensure-marketplace.ts","../src/cli/lib/operations/write-project-config.ts","../src/cli/lib/operations/compile-agents.ts","../src/cli/lib/operations/detect-config-changes.ts","../src/cli/lib/operations/update-local-skills.ts","../src/cli/lib/operations/discover-skills.ts","../src/cli/lib/operations/find-skill-match.ts","../node_modules/chalk/source/index.js","../node_modules/chalk/source/vendor/ansi-styles/index.js","../node_modules/chalk/source/vendor/supports-color/index.js","../node_modules/chalk/source/utilities.js","../src/cli/lib/operations/generate-skill-diff.ts","../src/cli/lib/operations/resolve-skill-info.ts","../src/cli/lib/operations/eject-project.ts","../src/cli/lib/operations/uninstall-project.ts","../src/cli/lib/operations/search-skills.ts","../src/cli/lib/operations/scaffold-agent.ts","../src/cli/lib/operations/migrate-plugin-scope.ts","../src/cli/lib/operations/index.ts"],"sourcesContent":["import os from \"os\";\nimport {\n detectGlobalInstallation,\n detectProjectInstallation,\n type Installation,\n} from \"../installation/index.js\";\n\nexport type BothInstallations = {\n global: Installation | null;\n project: Installation | null;\n hasBoth: boolean;\n};\n\n/**\n * Detects both global and project installations.\n *\n * Skips project detection when projectDir is the home directory\n * to avoid double-compile. Returns a convenience `hasBoth` flag\n * used by callers to set scopeFilter on compile passes.\n */\nexport async function detectBothInstallations(projectDir: string): Promise<BothInstallations> {\n const global = await detectGlobalInstallation();\n const project = projectDir === os.homedir() ? null : await detectProjectInstallation(projectDir);\n return { global, project, hasBoth: !!global && !!project };\n}\n","import { loadSkillsMatrixFromSource, type SourceLoadResult } from \"../loading/index.js\";\nimport {\n enableBuffering,\n drainBuffer,\n disableBuffering,\n type StartupMessage,\n} from \"../../utils/logger.js\";\n\nexport type LoadSourceOptions = {\n sourceFlag?: string;\n projectDir: string;\n forceRefresh?: boolean;\n /** When true, enables message buffering and captures startup messages. Default: false. */\n captureStartupMessages?: boolean;\n};\n\nexport type LoadedSource = {\n sourceResult: SourceLoadResult;\n /** Empty array when captureStartupMessages is false. */\n startupMessages: StartupMessage[];\n};\n\n/**\n * Loads the skills matrix from a resolved source.\n *\n * When `captureStartupMessages` is true, wraps the load in buffer mode so\n * warn() calls during loading are captured instead of written to stderr.\n * The caller (init/edit) passes these messages to the Wizard's <Static> block.\n *\n * @throws {Error} If source resolution or fetching fails.\n */\nexport async function loadSource(options: LoadSourceOptions): Promise<LoadedSource> {\n const { sourceFlag, projectDir, forceRefresh, captureStartupMessages } = options;\n\n if (captureStartupMessages) {\n enableBuffering();\n }\n\n let sourceResult: SourceLoadResult;\n try {\n sourceResult = await loadSkillsMatrixFromSource({\n sourceFlag,\n projectDir,\n forceRefresh,\n });\n } catch (error) {\n if (captureStartupMessages) {\n disableBuffering();\n }\n throw error;\n }\n\n let startupMessages: StartupMessage[] = [];\n if (captureStartupMessages) {\n startupMessages = drainBuffer();\n disableBuffering();\n }\n\n return { sourceResult, startupMessages };\n}\n","import { getInstallationInfo } from \"../plugins/plugin-info.js\";\nimport { loadProjectConfig } from \"../configuration/project-config.js\";\nimport { deriveInstallMode } from \"../installation/index.js\";\n\nexport type DashboardData = {\n skillCount: number;\n agentCount: number;\n mode: string;\n source?: string;\n};\n\n/** Gathers dashboard data from the installation and project config. */\nexport async function getDashboardData(projectDir: string): Promise<DashboardData> {\n const [info, loaded] = await Promise.all([getInstallationInfo(), loadProjectConfig(projectDir)]);\n\n // Skill count from config (canonical source of truth for installed skills)\n const skillCount = loaded?.config?.skills?.length ?? 0;\n // Agent count from filesystem (compiled .md files in agents dir)\n const agentCount = info?.agentCount ?? 0;\n const mode =\n info?.mode ?? (loaded?.config?.skills ? deriveInstallMode(loaded.config.skills) : \"local\");\n const source = loaded?.config?.source;\n\n return { skillCount, agentCount, mode, source };\n}\n","import { detectInstallation, type Installation } from \"../installation/index.js\";\nimport { loadProjectConfig } from \"../configuration/index.js\";\nimport type { ProjectConfig } from \"../../types/index.js\";\n\nexport type DetectedProject = {\n installation: Installation;\n config: ProjectConfig | null;\n configPath: string | null;\n};\n\n/**\n * Detects an existing CLI installation and loads its project config.\n *\n * Uses detectInstallation() which checks project-level first, then falls back\n * to global. Returns the installation metadata plus the loaded config.\n *\n * Does NOT throw. Returns null if no installation found.\n * Commands decide how to handle null (error out, warn, etc.).\n */\nexport async function detectProject(projectDir?: string): Promise<DetectedProject | null> {\n const resolvedDir = projectDir ?? process.cwd();\n const installation = await detectInstallation(resolvedDir);\n\n if (!installation) {\n return null;\n }\n\n const loaded = await loadProjectConfig(installation.projectDir);\n\n return {\n installation,\n config: loaded?.config ?? null,\n configPath: loaded?.configPath ?? null,\n };\n}\n","import { getAgentDefinitions } from \"../agents/index.js\";\nimport { loadAllAgents } from \"../loading/index.js\";\nimport { PROJECT_ROOT } from \"../../consts.js\";\nimport type { AgentDefinition, AgentName, AgentSourcePaths } from \"../../types/index.js\";\n\nexport type AgentDefs = {\n /** Merged agent definitions (CLI defaults + source overrides). Source takes precedence. */\n agents: Record<AgentName, AgentDefinition>;\n /** The sourcePath used to load agent partials (for compilation). */\n sourcePath: string;\n /** Full agent source paths (agentsDir, templatesDir, sourcePath). */\n agentSourcePaths: AgentSourcePaths;\n};\n\n/**\n * Loads agent definitions from the CLI and optionally from a remote source.\n *\n * Merges CLI built-in agents with source repository agents (source overrides CLI).\n * Returns the merged definitions plus the source path for compilation.\n */\nexport async function loadAgentDefs(\n agentSource?: string,\n options?: { projectDir?: string; forceRefresh?: boolean },\n): Promise<AgentDefs> {\n const agentSourcePaths = await getAgentDefinitions(agentSource, options);\n const cliAgents = await loadAllAgents(PROJECT_ROOT);\n const sourceAgents = await loadAllAgents(agentSourcePaths.sourcePath);\n const agents: Record<AgentName, AgentDefinition> = { ...cliAgents, ...sourceAgents };\n\n return {\n agents,\n sourcePath: agentSourcePaths.sourcePath,\n agentSourcePaths,\n };\n}\n","import { resolveInstallPaths } from \"../installation/index.js\";\nimport { copySkillsToLocalFlattened, type CopiedSkill } from \"../skills/index.js\";\nimport { ensureDir } from \"../../utils/fs.js\";\nimport type { SkillConfig } from \"../../types/config.js\";\nimport type { SourceLoadResult } from \"../loading/source-loader.js\";\n\nexport type SkillCopyResult = {\n projectCopied: CopiedSkill[];\n globalCopied: CopiedSkill[];\n totalCopied: number;\n};\n\n/**\n * Copies local-source skills to their scope-appropriate directories.\n *\n * Splits skills by scope (project vs global), resolves install paths,\n * ensures directories exist, and copies from source.\n */\nexport async function copyLocalSkills(\n skills: SkillConfig[],\n projectDir: string,\n sourceResult: SourceLoadResult,\n): Promise<SkillCopyResult> {\n const projectLocalSkills = skills.filter((s) => s.scope !== \"global\");\n const globalLocalSkills = skills.filter((s) => s.scope === \"global\");\n\n const projectPaths = resolveInstallPaths(projectDir, \"project\");\n const globalPaths = resolveInstallPaths(projectDir, \"global\");\n\n let projectCopied: CopiedSkill[] = [];\n if (projectLocalSkills.length > 0) {\n await ensureDir(projectPaths.skillsDir);\n projectCopied = await copySkillsToLocalFlattened(\n projectLocalSkills.map((s) => s.id),\n projectPaths.skillsDir,\n sourceResult.matrix,\n sourceResult,\n );\n }\n\n let globalCopied: CopiedSkill[] = [];\n if (globalLocalSkills.length > 0) {\n await ensureDir(globalPaths.skillsDir);\n globalCopied = await copySkillsToLocalFlattened(\n globalLocalSkills.map((s) => s.id),\n globalPaths.skillsDir,\n sourceResult.matrix,\n sourceResult,\n );\n }\n\n return {\n projectCopied,\n globalCopied,\n totalCopied: projectCopied.length + globalCopied.length,\n };\n}\n","import { claudePluginInstall } from \"../../utils/exec.js\";\nimport { getErrorMessage } from \"../../utils/errors.js\";\nimport type { SkillId } from \"../../types/index.js\";\nimport type { SkillConfig } from \"../../types/config.js\";\n\nexport type PluginInstallResult = {\n installed: Array<{ id: SkillId; ref: string }>;\n failed: Array<{ id: SkillId; error: string }>;\n};\n\n/**\n * Installs skill plugins via the Claude CLI, routing by scope.\n *\n * For each skill, constructs the plugin ref as `{skillId}@{marketplace}`\n * and invokes `claudePluginInstall` with the correct scope.\n */\nexport async function installPluginSkills(\n skills: SkillConfig[],\n marketplace: string,\n projectDir: string,\n): Promise<PluginInstallResult> {\n const pluginSkills = skills.filter((s) => s.source !== \"local\");\n const installed: PluginInstallResult[\"installed\"] = [];\n const failed: PluginInstallResult[\"failed\"] = [];\n\n for (const skill of pluginSkills) {\n const pluginRef = `${skill.id}@${marketplace}`;\n const pluginScope = skill.scope === \"global\" ? \"user\" : \"project\";\n try {\n await claudePluginInstall(pluginRef, pluginScope, projectDir);\n installed.push({ id: skill.id, ref: pluginRef });\n } catch (error) {\n failed.push({ id: skill.id, error: getErrorMessage(error) });\n }\n }\n\n return { installed, failed };\n}\n","import { claudePluginUninstall } from \"../../utils/exec.js\";\nimport { getErrorMessage } from \"../../utils/errors.js\";\nimport type { SkillId } from \"../../types/index.js\";\nimport type { SkillConfig } from \"../../types/config.js\";\n\nexport type PluginUninstallResult = {\n uninstalled: SkillId[];\n failed: Array<{ id: SkillId; error: string }>;\n};\n\n/**\n * Uninstalls skill plugins via the Claude CLI, using scope from old config.\n */\nexport async function uninstallPluginSkills(\n skillIds: SkillId[],\n oldSkills: SkillConfig[],\n projectDir: string,\n): Promise<PluginUninstallResult> {\n const uninstalled: SkillId[] = [];\n const failed: PluginUninstallResult[\"failed\"] = [];\n\n for (const skillId of skillIds) {\n const oldSkill = oldSkills.find((s) => s.id === skillId);\n const pluginScope = oldSkill?.scope === \"global\" ? \"user\" : \"project\";\n try {\n await claudePluginUninstall(skillId, pluginScope, projectDir);\n uninstalled.push(skillId);\n } catch (error) {\n failed.push({ id: skillId, error: getErrorMessage(error) });\n }\n }\n\n return { uninstalled, failed };\n}\n","import os from \"os\";\nimport path from \"path\";\nimport { fileExists, listDirectories } from \"../../utils/fs.js\";\nimport { LOCAL_SKILLS_PATH } from \"../../consts.js\";\n\nexport type ScopedSkillDir = {\n dirName: string;\n localSkillsPath: string;\n scope: \"project\" | \"global\";\n};\n\nexport type ScopedSkillDirsResult = {\n dirs: ScopedSkillDir[];\n hasProject: boolean;\n hasGlobal: boolean;\n projectLocalPath: string;\n globalLocalPath: string;\n};\n\n/**\n * Collects local skill directories from both project and global scopes.\n * Project-scoped dirs take precedence over global on name conflict.\n *\n * @returns directories with scope annotations, plus path/existence metadata\n */\nexport async function collectScopedSkillDirs(projectDir: string): Promise<ScopedSkillDirsResult> {\n const homeDir = os.homedir();\n const projectLocalPath = path.join(projectDir, LOCAL_SKILLS_PATH);\n const globalLocalPath = path.join(homeDir, LOCAL_SKILLS_PATH);\n const hasProject = await fileExists(projectLocalPath);\n const hasGlobal = projectDir !== homeDir && (await fileExists(globalLocalPath));\n\n const dirs: ScopedSkillDir[] = [];\n\n if (hasProject) {\n for (const dirName of await listDirectories(projectLocalPath)) {\n dirs.push({ dirName, localSkillsPath: projectLocalPath, scope: \"project\" });\n }\n }\n\n if (hasGlobal) {\n const projectDirNames = new Set(dirs.map((d) => d.dirName));\n for (const dirName of await listDirectories(globalLocalPath)) {\n if (!projectDirNames.has(dirName)) {\n dirs.push({ dirName, localSkillsPath: globalLocalPath, scope: \"global\" });\n }\n }\n }\n\n return { dirs, hasProject, hasGlobal, projectLocalPath, globalLocalPath };\n}\n","import os from \"os\";\nimport { compareLocalSkillsWithSource, type SkillComparisonResult } from \"../skills/index.js\";\nimport { typedEntries } from \"../../utils/typed-object.js\";\nimport { collectScopedSkillDirs } from \"./collect-scoped-skill-dirs.js\";\nimport type { MergedSkillsMatrix } from \"../../types/index.js\";\n\nexport type SkillComparisonResults = {\n projectResults: SkillComparisonResult[];\n globalResults: SkillComparisonResult[];\n /** Merged results with project taking precedence over global. */\n merged: SkillComparisonResult[];\n};\n\n/**\n * Builds a map of source skill IDs to their paths, excluding local-only skills.\n * Used by both compareSkillsWithSource and diff command.\n */\nexport function buildSourceSkillsMap(matrix: MergedSkillsMatrix): Record<string, { path: string }> {\n const sourceSkills: Record<string, { path: string }> = {};\n for (const [skillId, skill] of typedEntries(matrix.skills)) {\n if (!skill) continue;\n if (!skill.local) {\n sourceSkills[skillId] = { path: skill.path };\n }\n }\n return sourceSkills;\n}\n\n/**\n * Compares local skills (project + global scope) against their source versions.\n *\n * Builds a source skills map from the matrix (excluding local-only skills),\n * runs compareLocalSkillsWithSource for both project and global scopes,\n * and merges results with project taking precedence.\n */\nexport async function compareSkillsWithSource(\n projectDir: string,\n sourcePath: string,\n matrix: MergedSkillsMatrix,\n): Promise<SkillComparisonResults> {\n const sourceSkills = buildSourceSkillsMap(matrix);\n\n const { hasProject, hasGlobal } = await collectScopedSkillDirs(projectDir);\n const homeDir = os.homedir();\n\n const projectResults = hasProject\n ? await compareLocalSkillsWithSource(projectDir, sourcePath, sourceSkills)\n : [];\n\n const globalResults = hasGlobal\n ? await compareLocalSkillsWithSource(homeDir, sourcePath, sourceSkills)\n : [];\n\n const seenIds = new Set(projectResults.map((r) => r.id));\n const merged = [...projectResults, ...globalResults.filter((r) => !seenIds.has(r.id))];\n\n return { projectResults, globalResults, merged };\n}\n","import {\n claudePluginMarketplaceExists,\n claudePluginMarketplaceAdd,\n claudePluginMarketplaceUpdate,\n} from \"../../utils/exec.js\";\nimport { fetchMarketplace } from \"../loading/index.js\";\nimport { warn } from \"../../utils/logger.js\";\nimport type { SourceLoadResult } from \"../loading/source-loader.js\";\n\nexport type MarketplaceResult = {\n /** The resolved marketplace name, or null if no marketplace is configured. */\n marketplace: string | null;\n /** Whether a new marketplace was registered (vs. updated or already existed). */\n registered: boolean;\n};\n\n/**\n * Ensures the marketplace is registered with the Claude CLI.\n *\n * If the marketplace does not exist, registers it. If it exists, updates it.\n * Handles lazy marketplace name resolution when sourceResult.marketplace is undefined.\n *\n * Operation is intentionally SILENT — commands decide what to log based on the\n * `registered` flag.\n */\nexport async function ensureMarketplace(\n sourceResult: SourceLoadResult,\n): Promise<MarketplaceResult> {\n if (!sourceResult.marketplace) {\n try {\n const marketplaceResult = await fetchMarketplace(sourceResult.sourceConfig.source, {});\n sourceResult.marketplace = marketplaceResult.marketplace.name;\n } catch {\n return { marketplace: null, registered: false };\n }\n }\n\n const marketplace = sourceResult.marketplace;\n const exists = await claudePluginMarketplaceExists(marketplace);\n\n if (!exists) {\n const marketplaceSource = sourceResult.sourceConfig.source.replace(/^github:/, \"\");\n await claudePluginMarketplaceAdd(marketplaceSource);\n return { marketplace, registered: true };\n }\n\n try {\n await claudePluginMarketplaceUpdate(marketplace);\n } catch {\n warn(\"Could not update marketplace — continuing with cached version\");\n }\n\n return { marketplace, registered: false };\n}\n","import fs from \"fs\";\nimport os from \"os\";\nimport path from \"path\";\nimport {\n buildAndMergeConfig,\n writeScopedConfigs,\n resolveInstallPaths,\n} from \"../installation/index.js\";\nimport { loadAllAgents, type SourceLoadResult } from \"../loading/index.js\";\nimport { ensureBlankGlobalConfig } from \"../configuration/config-writer.js\";\nimport { ensureDir } from \"../../utils/fs.js\";\nimport { PROJECT_ROOT } from \"../../consts.js\";\nimport type { ProjectConfig, AgentDefinition, AgentName } from \"../../types/index.js\";\nimport type { WizardResultV2 } from \"../../components/wizard/wizard.js\";\n\nexport type ConfigWriteOptions = {\n wizardResult: WizardResultV2;\n sourceResult: SourceLoadResult;\n projectDir: string;\n sourceFlag?: string;\n /** Pre-loaded agent definitions. If omitted, loads from CLI + source. */\n agents?: Record<AgentName, AgentDefinition>;\n};\n\nexport type ConfigWriteResult = {\n config: ProjectConfig;\n configPath: string;\n globalConfigPath?: string;\n wasMerged: boolean;\n existingConfigPath?: string;\n filesWritten: number;\n};\n\n/**\n * Builds, merges, and writes project configuration files.\n *\n * Handles the full config pipeline:\n * 1. buildAndMergeConfig() — generates config from wizard result, merges with existing\n * 2. loadAllAgents() — loads agent definitions for config-types generation\n * 3. ensureBlankGlobalConfig() — ensures global config exists (when in project context)\n * 4. writeScopedConfigs() — writes config.ts and config-types.ts split by scope\n */\nexport async function writeProjectConfig(options: ConfigWriteOptions): Promise<ConfigWriteResult> {\n const { wizardResult, sourceResult, projectDir, sourceFlag } = options;\n const projectPaths = resolveInstallPaths(projectDir, \"project\");\n\n await ensureDir(path.dirname(projectPaths.configPath));\n\n let agents: Record<AgentName, AgentDefinition>;\n if (options.agents) {\n agents = options.agents;\n } else {\n const cliAgents = await loadAllAgents(PROJECT_ROOT);\n const sourceAgents = await loadAllAgents(sourceResult.sourcePath);\n agents = { ...cliAgents, ...sourceAgents };\n }\n\n const mergeResult = await buildAndMergeConfig(wizardResult, sourceResult, projectDir, sourceFlag);\n const finalConfig = mergeResult.config;\n\n const isProjectContext = fs.realpathSync(projectDir) !== fs.realpathSync(os.homedir());\n\n if (isProjectContext) {\n await ensureBlankGlobalConfig();\n }\n\n await writeScopedConfigs(\n finalConfig,\n sourceResult.matrix,\n agents,\n projectDir,\n projectPaths.configPath,\n isProjectContext,\n );\n\n return {\n config: finalConfig,\n configPath: projectPaths.configPath,\n wasMerged: mergeResult.merged,\n existingConfigPath: mergeResult.existingConfigPath,\n filesWritten: isProjectContext ? 4 : 2,\n };\n}\n","import { recompileAgents } from \"../agents/index.js\";\nimport { loadProjectConfigFromDir } from \"../configuration/index.js\";\nimport { buildAgentScopeMap } from \"../installation/index.js\";\nimport type { AgentName, SkillDefinitionMap } from \"../../types/index.js\";\nimport type { InstallMode } from \"../installation/index.js\";\n\nexport type CompileAgentsOptions = {\n projectDir: string;\n sourcePath: string;\n pluginDir?: string;\n skills?: SkillDefinitionMap;\n agentScopeMap?: Map<AgentName, \"project\" | \"global\">;\n agents?: AgentName[];\n /** When set, loads config and filters agents to only those matching this scope. */\n scopeFilter?: \"project\" | \"global\";\n outputDir?: string;\n installMode?: InstallMode;\n};\n\nexport type CompilationResult = {\n compiled: AgentName[];\n failed: AgentName[];\n warnings: string[];\n};\n\n/**\n * Compiles agent markdown files from templates + skill content.\n *\n * Thin wrapper around recompileAgents() that standardizes options.\n * The caller invokes this once (edit, update) or twice with scopeFilter (compile).\n */\nexport async function compileAgents(options: CompileAgentsOptions): Promise<CompilationResult> {\n let resolvedAgents = options.agents;\n let resolvedAgentScopeMap = options.agentScopeMap;\n\n if (options.scopeFilter) {\n const loadedConfig = await loadProjectConfigFromDir(options.projectDir);\n\n // Auto-build agentScopeMap from config if not provided\n if (!resolvedAgentScopeMap && loadedConfig?.config) {\n resolvedAgentScopeMap = buildAgentScopeMap(loadedConfig.config);\n }\n\n const filteredAgents = loadedConfig?.config?.agents\n ?.filter((a) => a.scope === options.scopeFilter)\n .map((a) => a.name);\n\n if (resolvedAgents && filteredAgents) {\n const filterSet = new Set(filteredAgents);\n resolvedAgents = resolvedAgents.filter((a) => filterSet.has(a));\n } else if (filteredAgents) {\n resolvedAgents = filteredAgents;\n }\n }\n\n const recompileResult = await recompileAgents({\n pluginDir: options.pluginDir ?? options.projectDir,\n sourcePath: options.sourcePath,\n agents: resolvedAgents,\n skills: options.skills,\n projectDir: options.projectDir,\n outputDir: options.outputDir,\n installMode: options.installMode,\n agentScopeMap: resolvedAgentScopeMap,\n });\n\n return {\n compiled: recompileResult.compiled,\n failed: recompileResult.failed,\n warnings: recompileResult.warnings,\n };\n}\n","import type { SkillId, AgentName } from \"../../types/index.js\";\nimport type { ProjectConfig } from \"../../types/index.js\";\nimport type { WizardResultV2 } from \"../../components/wizard/wizard.js\";\n\nexport type ConfigChanges = {\n addedSkills: SkillId[];\n removedSkills: SkillId[];\n addedAgents: AgentName[];\n removedAgents: AgentName[];\n sourceChanges: Map<SkillId, { from: string; to: string }>;\n scopeChanges: Map<SkillId, { from: \"project\" | \"global\"; to: \"project\" | \"global\" }>;\n agentScopeChanges: Map<AgentName, { from: \"project\" | \"global\"; to: \"project\" | \"global\" }>;\n};\n\n/**\n * Computes the diff between an existing project config and a new wizard result.\n *\n * Detects added/removed skills and agents, skill source changes,\n * skill scope changes, and agent scope changes.\n *\n * Pure function - no side effects, no logging.\n */\nexport function detectConfigChanges(\n oldConfig: ProjectConfig | null,\n wizardResult: WizardResultV2,\n currentSkillIds: SkillId[],\n): ConfigChanges {\n const newSkillIds = wizardResult.skills.map((s) => s.id);\n const addedSkills = newSkillIds.filter((id) => !currentSkillIds.includes(id));\n const removedSkills = currentSkillIds.filter((id) => !newSkillIds.includes(id));\n\n const oldAgentNames = oldConfig?.agents?.map((a) => a.name) ?? [];\n const newAgentNames = wizardResult.agentConfigs.map((a) => a.name);\n const addedAgents = newAgentNames.filter((name) => !oldAgentNames.includes(name));\n const removedAgents = oldAgentNames.filter((name) => !newAgentNames.includes(name));\n\n const sourceChanges = new Map<SkillId, { from: string; to: string }>();\n const scopeChanges = new Map<SkillId, { from: \"project\" | \"global\"; to: \"project\" | \"global\" }>();\n if (oldConfig?.skills) {\n for (const newSkill of wizardResult.skills) {\n const oldSkill = oldConfig.skills.find((s) => s.id === newSkill.id);\n if (oldSkill && oldSkill.source !== newSkill.source) {\n sourceChanges.set(newSkill.id, {\n from: oldSkill.source,\n to: newSkill.source,\n });\n }\n if (oldSkill && oldSkill.scope !== newSkill.scope) {\n scopeChanges.set(newSkill.id, {\n from: oldSkill.scope,\n to: newSkill.scope,\n });\n }\n }\n }\n\n const agentScopeChanges = new Map<\n AgentName,\n { from: \"project\" | \"global\"; to: \"project\" | \"global\" }\n >();\n if (oldConfig?.agents) {\n for (const newAgent of wizardResult.agentConfigs) {\n const oldAgent = oldConfig.agents.find((a) => a.name === newAgent.name);\n if (oldAgent && oldAgent.scope !== newAgent.scope) {\n agentScopeChanges.set(newAgent.name, {\n from: oldAgent.scope,\n to: newAgent.scope,\n });\n }\n }\n }\n\n return {\n addedSkills,\n removedSkills,\n addedAgents,\n removedAgents,\n sourceChanges,\n scopeChanges,\n agentScopeChanges,\n };\n}\n","import path from \"path\";\nimport { copy } from \"../../utils/fs.js\";\nimport { getErrorMessage } from \"../../utils/errors.js\";\nimport { injectForkedFromMetadata } from \"../skills/index.js\";\nimport { LOCAL_SKILLS_PATH } from \"../../consts.js\";\nimport type { SourceLoadResult } from \"../loading/source-loader.js\";\nimport type { SkillComparisonResult } from \"../skills/index.js\";\n\nexport type SkillUpdateResult = {\n id: string;\n success: boolean;\n newHash: string | null;\n error?: string;\n};\n\nexport type UpdateLocalSkillsResult = {\n updated: SkillUpdateResult[];\n failed: SkillUpdateResult[];\n totalUpdated: number;\n totalFailed: number;\n};\n\nexport type UpdateLocalSkillsOptions = {\n skills: SkillComparisonResult[];\n sourceResult: SourceLoadResult;\n skillBaseDir: Map<string, string>;\n /** Called before each skill update starts. Use for progress logging. */\n onProgress?: (skillId: string) => void;\n};\n\n/**\n * Updates local skills by copying from source and injecting metadata.\n *\n * For each outdated skill, copies the source version to the local skills\n * directory and injects forked-from metadata for change tracking.\n */\nexport async function updateLocalSkills(\n options: UpdateLocalSkillsOptions,\n): Promise<UpdateLocalSkillsResult> {\n const { skills, sourceResult, skillBaseDir, onProgress } = options;\n const updated: SkillUpdateResult[] = [];\n const failed: SkillUpdateResult[] = [];\n\n for (const skill of skills) {\n onProgress?.(skill.id);\n if (!skill.sourcePath || !skill.sourceHash) {\n failed.push({\n id: skill.id,\n success: false,\n newHash: null,\n error: \"No source path available\",\n });\n continue;\n }\n\n const baseDir = skillBaseDir.get(skill.id) ?? process.cwd();\n const localSkillsPath = path.join(baseDir, LOCAL_SKILLS_PATH);\n const destPath = path.join(localSkillsPath, skill.dirName);\n const srcPath = path.join(sourceResult.sourcePath, \"src\", skill.sourcePath);\n\n try {\n await copy(srcPath, destPath);\n await injectForkedFromMetadata(destPath, skill.id, skill.sourceHash);\n updated.push({ id: skill.id, success: true, newHash: skill.sourceHash });\n } catch (error) {\n failed.push({ id: skill.id, success: false, newHash: null, error: getErrorMessage(error) });\n }\n }\n\n return {\n updated,\n failed,\n totalUpdated: updated.length,\n totalFailed: failed.length,\n };\n}\n","import os from \"os\";\nimport path from \"path\";\nimport { discoverAllPluginSkills } from \"../plugins/index.js\";\nimport { directoryExists, glob, readFile, fileExists } from \"../../utils/fs.js\";\nimport { parseFrontmatter } from \"../loading/index.js\";\nimport { verbose, warn } from \"../../utils/logger.js\";\nimport { GLOBAL_INSTALL_ROOT, LOCAL_SKILLS_PATH, STANDARD_FILES } from \"../../consts.js\";\nimport { typedEntries, typedKeys } from \"../../utils/typed-object.js\";\nimport type { SkillDefinition, SkillDefinitionMap, SkillId } from \"../../types/index.js\";\n\nexport type DiscoveredSkills = {\n allSkills: SkillDefinitionMap;\n totalSkillCount: number;\n pluginSkillCount: number;\n localSkillCount: number;\n globalPluginSkillCount: number;\n globalLocalSkillCount: number;\n};\n\n/**\n * Loads SKILL.md files from a directory, parsing frontmatter for skill metadata.\n * Returns a map of skillId -> SkillDefinition.\n */\nexport async function loadSkillsFromDir(\n skillsDir: string,\n pathPrefix = \"\",\n): Promise<SkillDefinitionMap> {\n const skills: SkillDefinitionMap = {};\n\n if (!(await directoryExists(skillsDir))) {\n return skills;\n }\n\n const skillFiles = await glob(\"**/SKILL.md\", skillsDir);\n\n for (const skillFile of skillFiles) {\n const skillPath = path.join(skillsDir, skillFile);\n const skillDir = path.dirname(skillPath);\n const relativePath = path.relative(skillsDir, skillDir);\n const skillDirName = path.basename(skillDir);\n\n const metadataPath = path.join(skillDir, STANDARD_FILES.METADATA_YAML);\n if (!(await fileExists(metadataPath))) {\n const displayPath = pathPrefix ? `${pathPrefix}/${relativePath}/` : `${relativePath}/`;\n warn(\n `Skill '${skillDirName}' in '${displayPath}' is missing ${STANDARD_FILES.METADATA_YAML} — skipped. Add ${STANDARD_FILES.METADATA_YAML} to register it with the CLI.`,\n );\n continue;\n }\n\n try {\n const content = await readFile(skillPath);\n const frontmatter = parseFrontmatter(content, skillPath);\n\n if (!frontmatter?.name) {\n warn(`Skipping skill in '${skillDirName}': missing or invalid frontmatter name`);\n continue;\n }\n\n const canonicalId = frontmatter.name;\n\n const skill: SkillDefinition = {\n id: canonicalId,\n path: pathPrefix ? `${pathPrefix}/${relativePath}/` : `${relativePath}/`,\n description: frontmatter?.description || \"\",\n };\n\n skills[canonicalId] = skill;\n verbose(` Loaded skill: ${canonicalId}`);\n } catch (error) {\n verbose(` Failed to load skill: ${skillFile} - ${error}`);\n }\n }\n\n return skills;\n}\n\n/**\n * Discovers local project skills from the .claude/skills/ directory.\n */\nexport async function discoverLocalProjectSkills(projectDir: string): Promise<SkillDefinitionMap> {\n const localSkillsDir = path.join(projectDir, LOCAL_SKILLS_PATH);\n return loadSkillsFromDir(localSkillsDir, LOCAL_SKILLS_PATH);\n}\n\n/** Merges skill maps — later sources take precedence over earlier ones. */\nexport function mergeSkills(...skillSources: SkillDefinitionMap[]): SkillDefinitionMap {\n const merged: SkillDefinitionMap = {};\n\n for (const source of skillSources) {\n for (const [id, skill] of typedEntries<SkillId, SkillDefinition | undefined>(source)) {\n if (skill) {\n merged[id] = skill;\n }\n }\n }\n\n return merged;\n}\n\n/**\n * Discovers all installed skills for a project directory using 4-way merge:\n * 1. Global plugins (from ~/.claude/plugins/)\n * 2. Global local (from ~/.claude/skills/)\n * 3. Project plugins (from <projectDir>/.claude/plugins/)\n * 4. Project local (from <projectDir>/.claude/skills/)\n *\n * Pure function — no user-facing logging. Callers add their own log messages.\n * Uses verbose() for diagnostic output only.\n */\nexport async function discoverInstalledSkills(projectDir: string): Promise<DiscoveredSkills> {\n const isGlobalProject = projectDir === os.homedir();\n\n // 1. Global plugins\n const globalPluginSkills = isGlobalProject ? {} : await discoverAllPluginSkills(os.homedir());\n const globalPluginSkillCount = typedKeys<SkillId>(globalPluginSkills).length;\n if (globalPluginSkillCount > 0) {\n verbose(` Found ${globalPluginSkillCount} skills from global plugins`);\n }\n\n // 2. Global local skills\n const globalLocalSkillsDir = path.join(GLOBAL_INSTALL_ROOT, LOCAL_SKILLS_PATH);\n const globalLocalSkills = isGlobalProject\n ? {}\n : await loadSkillsFromDir(globalLocalSkillsDir, LOCAL_SKILLS_PATH);\n const globalLocalSkillCount = typedKeys<SkillId>(globalLocalSkills).length;\n if (globalLocalSkillCount > 0) {\n verbose(` Found ${globalLocalSkillCount} global local skills from ~/.claude/skills/`);\n }\n\n // 3. Project plugins\n const pluginSkills = await discoverAllPluginSkills(projectDir);\n const pluginSkillCount = typedKeys<SkillId>(pluginSkills).length;\n verbose(` Found ${pluginSkillCount} skills from installed plugins`);\n\n // 4. Project local skills\n const localSkills = await discoverLocalProjectSkills(projectDir);\n const localSkillCount = typedKeys<SkillId>(localSkills).length;\n verbose(` Found ${localSkillCount} local skills from .claude/skills/`);\n\n // Merge: global first, project second — project wins on conflict\n const allSkills = mergeSkills(globalPluginSkills, globalLocalSkills, pluginSkills, localSkills);\n const totalSkillCount = typedKeys<SkillId>(allSkills).length;\n\n return {\n allSkills,\n totalSkillCount,\n pluginSkillCount: globalPluginSkillCount + pluginSkillCount,\n localSkillCount: globalLocalSkillCount + localSkillCount,\n globalPluginSkillCount,\n globalLocalSkillCount,\n };\n}\n","import type { SkillComparisonResult } from \"../skills/index.js\";\n\nexport type SkillMatchResult = {\n match: SkillComparisonResult | null;\n similar: string[];\n};\n\n/**\n * Finds a skill by exact ID, partial name, or directory name.\n * Falls back to fuzzy matching and returns similar suggestions.\n */\nexport function findSkillMatch(\n skillName: string,\n results: SkillComparisonResult[],\n): SkillMatchResult {\n // Exact match by ID\n const exact = results.find((r) => r.id === skillName);\n if (exact) return { match: exact, similar: [] };\n\n // Partial match (without author suffix)\n const partial = results.find((r) => {\n const nameWithoutAuthor = r.id.replace(/\\s*\\(@\\w+\\)$/, \"\").toLowerCase();\n return nameWithoutAuthor === skillName.toLowerCase();\n });\n if (partial) return { match: partial, similar: [] };\n\n // Match by directory name\n const byDir = results.find((r) => r.dirName.toLowerCase() === skillName.toLowerCase());\n if (byDir) return { match: byDir, similar: [] };\n\n // No match — find similar suggestions\n const lowered = skillName.toLowerCase();\n const similar = results\n .filter((r) => {\n const name = r.id.toLowerCase();\n const dir = r.dirName.toLowerCase();\n return (\n name.includes(lowered) || dir.includes(lowered) || lowered.includes(name.split(\" \")[0])\n );\n })\n .map((r) => r.id)\n .slice(0, 3);\n\n return { match: null, similar };\n}\n","import ansiStyles from '#ansi-styles';\nimport supportsColor from '#supports-color';\nimport { // eslint-disable-line import/order\n\tstringReplaceAll,\n\tstringEncaseCRLFWithFirstIndex,\n} from './utilities.js';\n\nconst {stdout: stdoutColor, stderr: stderrColor} = supportsColor;\n\nconst GENERATOR = Symbol('GENERATOR');\nconst STYLER = Symbol('STYLER');\nconst IS_EMPTY = Symbol('IS_EMPTY');\n\n// `supportsColor.level` → `ansiStyles.color[name]` mapping\nconst levelMapping = [\n\t'ansi',\n\t'ansi',\n\t'ansi256',\n\t'ansi16m',\n];\n\nconst styles = Object.create(null);\n\nconst applyOptions = (object, options = {}) => {\n\tif (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {\n\t\tthrow new Error('The `level` option should be an integer from 0 to 3');\n\t}\n\n\t// Detect level if not set manually\n\tconst colorLevel = stdoutColor ? stdoutColor.level : 0;\n\tobject.level = options.level === undefined ? colorLevel : options.level;\n};\n\nexport class Chalk {\n\tconstructor(options) {\n\t\t// eslint-disable-next-line no-constructor-return\n\t\treturn chalkFactory(options);\n\t}\n}\n\nconst chalkFactory = options => {\n\tconst chalk = (...strings) => strings.join(' ');\n\tapplyOptions(chalk, options);\n\n\tObject.setPrototypeOf(chalk, createChalk.prototype);\n\n\treturn chalk;\n};\n\nfunction createChalk(options) {\n\treturn chalkFactory(options);\n}\n\nObject.setPrototypeOf(createChalk.prototype, Function.prototype);\n\nfor (const [styleName, style] of Object.entries(ansiStyles)) {\n\tstyles[styleName] = {\n\t\tget() {\n\t\t\tconst builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);\n\t\t\tObject.defineProperty(this, styleName, {value: builder});\n\t\t\treturn builder;\n\t\t},\n\t};\n}\n\nstyles.visible = {\n\tget() {\n\t\tconst builder = createBuilder(this, this[STYLER], true);\n\t\tObject.defineProperty(this, 'visible', {value: builder});\n\t\treturn builder;\n\t},\n};\n\nconst getModelAnsi = (model, level, type, ...arguments_) => {\n\tif (model === 'rgb') {\n\t\tif (level === 'ansi16m') {\n\t\t\treturn ansiStyles[type].ansi16m(...arguments_);\n\t\t}\n\n\t\tif (level === 'ansi256') {\n\t\t\treturn ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));\n\t\t}\n\n\t\treturn ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));\n\t}\n\n\tif (model === 'hex') {\n\t\treturn getModelAnsi('rgb', level, type, ...ansiStyles.hexToRgb(...arguments_));\n\t}\n\n\treturn ansiStyles[type][model](...arguments_);\n};\n\nconst usedModels = ['rgb', 'hex', 'ansi256'];\n\nfor (const model of usedModels) {\n\tstyles[model] = {\n\t\tget() {\n\t\t\tconst {level} = this;\n\t\t\treturn function (...arguments_) {\n\t\t\t\tconst styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]);\n\t\t\t\treturn createBuilder(this, styler, this[IS_EMPTY]);\n\t\t\t};\n\t\t},\n\t};\n\n\tconst bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);\n\tstyles[bgModel] = {\n\t\tget() {\n\t\t\tconst {level} = this;\n\t\t\treturn function (...arguments_) {\n\t\t\t\tconst styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]);\n\t\t\t\treturn createBuilder(this, styler, this[IS_EMPTY]);\n\t\t\t};\n\t\t},\n\t};\n}\n\nconst proto = Object.defineProperties(() => {}, {\n\t...styles,\n\tlevel: {\n\t\tenumerable: true,\n\t\tget() {\n\t\t\treturn this[GENERATOR].level;\n\t\t},\n\t\tset(level) {\n\t\t\tthis[GENERATOR].level = level;\n\t\t},\n\t},\n});\n\nconst createStyler = (open, close, parent) => {\n\tlet openAll;\n\tlet closeAll;\n\tif (parent === undefined) {\n\t\topenAll = open;\n\t\tcloseAll = close;\n\t} else {\n\t\topenAll = parent.openAll + open;\n\t\tcloseAll = close + parent.closeAll;\n\t}\n\n\treturn {\n\t\topen,\n\t\tclose,\n\t\topenAll,\n\t\tcloseAll,\n\t\tparent,\n\t};\n};\n\nconst createBuilder = (self, _styler, _isEmpty) => {\n\t// Single argument is hot path, implicit coercion is faster than anything\n\t// eslint-disable-next-line no-implicit-coercion\n\tconst builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));\n\n\t// We alter the prototype because we must return a function, but there is\n\t// no way to create a function with a different prototype\n\tObject.setPrototypeOf(builder, proto);\n\n\tbuilder[GENERATOR] = self;\n\tbuilder[STYLER] = _styler;\n\tbuilder[IS_EMPTY] = _isEmpty;\n\n\treturn builder;\n};\n\nconst applyStyle = (self, string) => {\n\tif (self.level <= 0 || !string) {\n\t\treturn self[IS_EMPTY] ? '' : string;\n\t}\n\n\tlet styler = self[STYLER];\n\n\tif (styler === undefined) {\n\t\treturn string;\n\t}\n\n\tconst {openAll, closeAll} = styler;\n\tif (string.includes('\\u001B')) {\n\t\twhile (styler !== undefined) {\n\t\t\t// Replace any instances already present with a re-opening code\n\t\t\t// otherwise only the part of the string until said closing code\n\t\t\t// will be colored, and the rest will simply be 'plain'.\n\t\t\tstring = stringReplaceAll(string, styler.close, styler.open);\n\n\t\t\tstyler = styler.parent;\n\t\t}\n\t}\n\n\t// We can move both next actions out of loop, because remaining actions in loop won't have\n\t// any/visible effect on parts we add here. Close the styling before a linebreak and reopen\n\t// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92\n\tconst lfIndex = string.indexOf('\\n');\n\tif (lfIndex !== -1) {\n\t\tstring = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);\n\t}\n\n\treturn openAll + string + closeAll;\n};\n\nObject.defineProperties(createChalk.prototype, styles);\n\nconst chalk = createChalk();\nexport const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});\n\nexport {\n\tmodifierNames,\n\tforegroundColorNames,\n\tbackgroundColorNames,\n\tcolorNames,\n\n\t// TODO: Remove these aliases in the next major version\n\tmodifierNames as modifiers,\n\tforegroundColorNames as foregroundColors,\n\tbackgroundColorNames as backgroundColors,\n\tcolorNames as colors,\n} from './vendor/ansi-styles/index.js';\n\nexport {\n\tstdoutColor as supportsColor,\n\tstderrColor as supportsColorStderr,\n};\n\nexport default chalk;\n","const ANSI_BACKGROUND_OFFSET = 10;\n\nconst wrapAnsi16 = (offset = 0) => code => `\\u001B[${code + offset}m`;\n\nconst wrapAnsi256 = (offset = 0) => code => `\\u001B[${38 + offset};5;${code}m`;\n\nconst wrapAnsi16m = (offset = 0) => (red, green, blue) => `\\u001B[${38 + offset};2;${red};${green};${blue}m`;\n\nconst styles = {\n\tmodifier: {\n\t\treset: [0, 0],\n\t\t// 21 isn't widely supported and 22 does the same thing\n\t\tbold: [1, 22],\n\t\tdim: [2, 22],\n\t\titalic: [3, 23],\n\t\tunderline: [4, 24],\n\t\toverline: [53, 55],\n\t\tinverse: [7, 27],\n\t\thidden: [8, 28],\n\t\tstrikethrough: [9, 29],\n\t},\n\tcolor: {\n\t\tblack: [30, 39],\n\t\tred: [31, 39],\n\t\tgreen: [32, 39],\n\t\tyellow: [33, 39],\n\t\tblue: [34, 39],\n\t\tmagenta: [35, 39],\n\t\tcyan: [36, 39],\n\t\twhite: [37, 39],\n\n\t\t// Bright color\n\t\tblackBright: [90, 39],\n\t\tgray: [90, 39], // Alias of `blackBright`\n\t\tgrey: [90, 39], // Alias of `blackBright`\n\t\tredBright: [91, 39],\n\t\tgreenBright: [92, 39],\n\t\tyellowBright: [93, 39],\n\t\tblueBright: [94, 39],\n\t\tmagentaBright: [95, 39],\n\t\tcyanBright: [96, 39],\n\t\twhiteBright: [97, 39],\n\t},\n\tbgColor: {\n\t\tbgBlack: [40, 49],\n\t\tbgRed: [41, 49],\n\t\tbgGreen: [42, 49],\n\t\tbgYellow: [43, 49],\n\t\tbgBlue: [44, 49],\n\t\tbgMagenta: [45, 49],\n\t\tbgCyan: [46, 49],\n\t\tbgWhite: [47, 49],\n\n\t\t// Bright color\n\t\tbgBlackBright: [100, 49],\n\t\tbgGray: [100, 49], // Alias of `bgBlackBright`\n\t\tbgGrey: [100, 49], // Alias of `bgBlackBright`\n\t\tbgRedBright: [101, 49],\n\t\tbgGreenBright: [102, 49],\n\t\tbgYellowBright: [103, 49],\n\t\tbgBlueBright: [104, 49],\n\t\tbgMagentaBright: [105, 49],\n\t\tbgCyanBright: [106, 49],\n\t\tbgWhiteBright: [107, 49],\n\t},\n};\n\nexport const modifierNames = Object.keys(styles.modifier);\nexport const foregroundColorNames = Object.keys(styles.color);\nexport const backgroundColorNames = Object.keys(styles.bgColor);\nexport const colorNames = [...foregroundColorNames, ...backgroundColorNames];\n\nfunction assembleStyles() {\n\tconst codes = new Map();\n\n\tfor (const [groupName, group] of Object.entries(styles)) {\n\t\tfor (const [styleName, style] of Object.entries(group)) {\n\t\t\tstyles[styleName] = {\n\t\t\t\topen: `\\u001B[${style[0]}m`,\n\t\t\t\tclose: `\\u001B[${style[1]}m`,\n\t\t\t};\n\n\t\t\tgroup[styleName] = styles[styleName];\n\n\t\t\tcodes.set(style[0], style[1]);\n\t\t}\n\n\t\tObject.defineProperty(styles, groupName, {\n\t\t\tvalue: group,\n\t\t\tenumerable: false,\n\t\t});\n\t}\n\n\tObject.defineProperty(styles, 'codes', {\n\t\tvalue: codes,\n\t\tenumerable: false,\n\t});\n\n\tstyles.color.close = '\\u001B[39m';\n\tstyles.bgColor.close = '\\u001B[49m';\n\n\tstyles.color.ansi = wrapAnsi16();\n\tstyles.color.ansi256 = wrapAnsi256();\n\tstyles.color.ansi16m = wrapAnsi16m();\n\tstyles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);\n\tstyles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);\n\tstyles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);\n\n\t// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js\n\tObject.defineProperties(styles, {\n\t\trgbToAnsi256: {\n\t\t\tvalue(red, green, blue) {\n\t\t\t\t// We use the extended greyscale palette here, with the exception of\n\t\t\t\t// black and white. normal palette only has 4 greyscale shades.\n\t\t\t\tif (red === green && green === blue) {\n\t\t\t\t\tif (red < 8) {\n\t\t\t\t\t\treturn 16;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (red > 248) {\n\t\t\t\t\t\treturn 231;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn Math.round(((red - 8) / 247) * 24) + 232;\n\t\t\t\t}\n\n\t\t\t\treturn 16\n\t\t\t\t\t+ (36 * Math.round(red / 255 * 5))\n\t\t\t\t\t+ (6 * Math.round(green / 255 * 5))\n\t\t\t\t\t+ Math.round(blue / 255 * 5);\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToRgb: {\n\t\t\tvalue(hex) {\n\t\t\t\tconst matches = /[a-f\\d]{6}|[a-f\\d]{3}/i.exec(hex.toString(16));\n\t\t\t\tif (!matches) {\n\t\t\t\t\treturn [0, 0, 0];\n\t\t\t\t}\n\n\t\t\t\tlet [colorString] = matches;\n\n\t\t\t\tif (colorString.length === 3) {\n\t\t\t\t\tcolorString = [...colorString].map(character => character + character).join('');\n\t\t\t\t}\n\n\t\t\t\tconst integer = Number.parseInt(colorString, 16);\n\n\t\t\t\treturn [\n\t\t\t\t\t/* eslint-disable no-bitwise */\n\t\t\t\t\t(integer >> 16) & 0xFF,\n\t\t\t\t\t(integer >> 8) & 0xFF,\n\t\t\t\t\tinteger & 0xFF,\n\t\t\t\t\t/* eslint-enable no-bitwise */\n\t\t\t\t];\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToAnsi256: {\n\t\t\tvalue: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),\n\t\t\tenumerable: false,\n\t\t},\n\t\tansi256ToAnsi: {\n\t\t\tvalue(code) {\n\t\t\t\tif (code < 8) {\n\t\t\t\t\treturn 30 + code;\n\t\t\t\t}\n\n\t\t\t\tif (code < 16) {\n\t\t\t\t\treturn 90 + (code - 8);\n\t\t\t\t}\n\n\t\t\t\tlet red;\n\t\t\t\tlet green;\n\t\t\t\tlet blue;\n\n\t\t\t\tif (code >= 232) {\n\t\t\t\t\tred = (((code - 232) * 10) + 8) / 255;\n\t\t\t\t\tgreen = red;\n\t\t\t\t\tblue = red;\n\t\t\t\t} else {\n\t\t\t\t\tcode -= 16;\n\n\t\t\t\t\tconst remainder = code % 36;\n\n\t\t\t\t\tred = Math.floor(code / 36) / 5;\n\t\t\t\t\tgreen = Math.floor(remainder / 6) / 5;\n\t\t\t\t\tblue = (remainder % 6) / 5;\n\t\t\t\t}\n\n\t\t\t\tconst value = Math.max(red, green, blue) * 2;\n\n\t\t\t\tif (value === 0) {\n\t\t\t\t\treturn 30;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tlet result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));\n\n\t\t\t\tif (value === 2) {\n\t\t\t\t\tresult += 60;\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\trgbToAnsi: {\n\t\t\tvalue: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToAnsi: {\n\t\t\tvalue: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),\n\t\t\tenumerable: false,\n\t\t},\n\t});\n\n\treturn styles;\n}\n\nconst ansiStyles = assembleStyles();\n\nexport default ansiStyles;\n","import process from 'node:process';\nimport os from 'node:os';\nimport tty from 'node:tty';\n\n// From: https://github.com/sindresorhus/has-flag/blob/main/index.js\n/// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {\nfunction hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {\n\tconst prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');\n\tconst position = argv.indexOf(prefix + flag);\n\tconst terminatorPosition = argv.indexOf('--');\n\treturn position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);\n}\n\nconst {env} = process;\n\nlet flagForceColor;\nif (\n\thasFlag('no-color')\n\t|| hasFlag('no-colors')\n\t|| hasFlag('color=false')\n\t|| hasFlag('color=never')\n) {\n\tflagForceColor = 0;\n} else if (\n\thasFlag('color')\n\t|| hasFlag('colors')\n\t|| hasFlag('color=true')\n\t|| hasFlag('color=always')\n) {\n\tflagForceColor = 1;\n}\n\nfunction envForceColor() {\n\tif ('FORCE_COLOR' in env) {\n\t\tif (env.FORCE_COLOR === 'true') {\n\t\t\treturn 1;\n\t\t}\n\n\t\tif (env.FORCE_COLOR === 'false') {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);\n\t}\n}\n\nfunction translateLevel(level) {\n\tif (level === 0) {\n\t\treturn false;\n\t}\n\n\treturn {\n\t\tlevel,\n\t\thasBasic: true,\n\t\thas256: level >= 2,\n\t\thas16m: level >= 3,\n\t};\n}\n\nfunction _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {\n\tconst noFlagForceColor = envForceColor();\n\tif (noFlagForceColor !== undefined) {\n\t\tflagForceColor = noFlagForceColor;\n\t}\n\n\tconst forceColor = sniffFlags ? flagForceColor : noFlagForceColor;\n\n\tif (forceColor === 0) {\n\t\treturn 0;\n\t}\n\n\tif (sniffFlags) {\n\t\tif (hasFlag('color=16m')\n\t\t\t|| hasFlag('color=full')\n\t\t\t|| hasFlag('color=truecolor')) {\n\t\t\treturn 3;\n\t\t}\n\n\t\tif (hasFlag('color=256')) {\n\t\t\treturn 2;\n\t\t}\n\t}\n\n\t// Check for Azure DevOps pipelines.\n\t// Has to be above the `!streamIsTTY` check.\n\tif ('TF_BUILD' in env && 'AGENT_NAME' in env) {\n\t\treturn 1;\n\t}\n\n\tif (haveStream && !streamIsTTY && forceColor === undefined) {\n\t\treturn 0;\n\t}\n\n\tconst min = forceColor || 0;\n\n\tif (env.TERM === 'dumb') {\n\t\treturn min;\n\t}\n\n\tif (process.platform === 'win32') {\n\t\t// Windows 10 build 10586 is the first Windows release that supports 256 colors.\n\t\t// Windows 10 build 14931 is the first release that supports 16m/TrueColor.\n\t\tconst osRelease = os.release().split('.');\n\t\tif (\n\t\t\tNumber(osRelease[0]) >= 10\n\t\t\t&& Number(osRelease[2]) >= 10_586\n\t\t) {\n\t\t\treturn Number(osRelease[2]) >= 14_931 ? 3 : 2;\n\t\t}\n\n\t\treturn 1;\n\t}\n\n\tif ('CI' in env) {\n\t\tif (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {\n\t\t\treturn 3;\n\t\t}\n\n\t\tif (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {\n\t\t\treturn 1;\n\t\t}\n\n\t\treturn min;\n\t}\n\n\tif ('TEAMCITY_VERSION' in env) {\n\t\treturn /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;\n\t}\n\n\tif (env.COLORTERM === 'truecolor') {\n\t\treturn 3;\n\t}\n\n\tif (env.TERM === 'xterm-kitty') {\n\t\treturn 3;\n\t}\n\n\tif (env.TERM === 'xterm-ghostty') {\n\t\treturn 3;\n\t}\n\n\tif (env.TERM === 'wezterm') {\n\t\treturn 3;\n\t}\n\n\tif ('TERM_PROGRAM' in env) {\n\t\tconst version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);\n\n\t\tswitch (env.TERM_PROGRAM) {\n\t\t\tcase 'iTerm.app': {\n\t\t\t\treturn version >= 3 ? 3 : 2;\n\t\t\t}\n\n\t\t\tcase 'Apple_Terminal': {\n\t\t\t\treturn 2;\n\t\t\t}\n\t\t\t// No default\n\t\t}\n\t}\n\n\tif (/-256(color)?$/i.test(env.TERM)) {\n\t\treturn 2;\n\t}\n\n\tif (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {\n\t\treturn 1;\n\t}\n\n\tif ('COLORTERM' in env) {\n\t\treturn 1;\n\t}\n\n\treturn min;\n}\n\nexport function createSupportsColor(stream, options = {}) {\n\tconst level = _supportsColor(stream, {\n\t\tstreamIsTTY: stream && stream.isTTY,\n\t\t...options,\n\t});\n\n\treturn translateLevel(level);\n}\n\nconst supportsColor = {\n\tstdout: createSupportsColor({isTTY: tty.isatty(1)}),\n\tstderr: createSupportsColor({isTTY: tty.isatty(2)}),\n};\n\nexport default supportsColor;\n","// TODO: When targeting Node.js 16, use `String.prototype.replaceAll`.\nexport function stringReplaceAll(string, substring, replacer) {\n\tlet index = string.indexOf(substring);\n\tif (index === -1) {\n\t\treturn string;\n\t}\n\n\tconst substringLength = substring.length;\n\tlet endIndex = 0;\n\tlet returnValue = '';\n\tdo {\n\t\treturnValue += string.slice(endIndex, index) + substring + replacer;\n\t\tendIndex = index + substringLength;\n\t\tindex = string.indexOf(substring, endIndex);\n\t} while (index !== -1);\n\n\treturnValue += string.slice(endIndex);\n\treturn returnValue;\n}\n\nexport function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {\n\tlet endIndex = 0;\n\tlet returnValue = '';\n\tdo {\n\t\tconst gotCR = string[index - 1] === '\\r';\n\t\treturnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\\r\\n' : '\\n') + postfix;\n\t\tendIndex = index + 1;\n\t\tindex = string.indexOf('\\n', endIndex);\n\t} while (index !== -1);\n\n\treturnValue += string.slice(endIndex);\n\treturn returnValue;\n}\n","import path from \"path\";\nimport chalk from \"chalk\";\nimport { createTwoFilesPatch } from \"diff\";\nimport { readForkedFromMetadata, type ForkedFromMetadata } from \"../skills/index.js\";\nimport { fileExists, readFile } from \"../../utils/fs.js\";\nimport { LOCAL_SKILLS_PATH, STANDARD_FILES } from \"../../consts.js\";\n\nexport type SkillDiffResult = {\n skillDirName: string;\n forkedFrom: ForkedFromMetadata | null;\n hasDiff: boolean;\n diffOutput: string;\n};\n\n/**\n * Generates a unified diff between a local skill and its source version.\n *\n * Reads forkedFrom metadata to find the original skill ID, locates the source\n * SKILL.md, and produces a unified diff patch.\n */\nexport async function generateSkillDiff(\n localSkillsPath: string,\n skillDirName: string,\n sourcePath: string,\n sourceSkills: Record<string, { path: string }>,\n): Promise<SkillDiffResult> {\n const skillDir = path.join(localSkillsPath, skillDirName);\n const forkedFrom = await readForkedFromMetadata(skillDir);\n\n if (!forkedFrom) {\n return {\n skillDirName,\n forkedFrom: null,\n hasDiff: false,\n diffOutput: \"\",\n };\n }\n\n const sourceSkill = sourceSkills[forkedFrom.skillId];\n\n if (!sourceSkill) {\n return {\n skillDirName,\n forkedFrom,\n hasDiff: false,\n diffOutput: `Source skill '${forkedFrom.skillId}' no longer exists`,\n };\n }\n\n const sourceSkillMdPath = path.join(sourcePath, \"src\", sourceSkill.path, STANDARD_FILES.SKILL_MD);\n\n if (!(await fileExists(sourceSkillMdPath))) {\n return {\n skillDirName,\n forkedFrom,\n hasDiff: false,\n diffOutput: `Source ${STANDARD_FILES.SKILL_MD} not found at ${sourceSkillMdPath}`,\n };\n }\n\n const sourceContent = await readFile(sourceSkillMdPath);\n\n const localSkillMdPath = path.join(skillDir, STANDARD_FILES.SKILL_MD);\n\n if (!(await fileExists(localSkillMdPath))) {\n return {\n skillDirName,\n forkedFrom,\n hasDiff: false,\n diffOutput: `Local ${STANDARD_FILES.SKILL_MD} not found at ${localSkillMdPath}`,\n };\n }\n\n const localContent = await readFile(localSkillMdPath);\n\n const sourceLabel = `source/${sourceSkill.path}/SKILL.md`;\n const localLabel = `local/${LOCAL_SKILLS_PATH}/${skillDirName}/SKILL.md`;\n\n const diff = createTwoFilesPatch(\n sourceLabel,\n localLabel,\n sourceContent,\n localContent,\n \"\", // No source header\n \"\", // No local header\n );\n\n const hasDiff = diff.split(\"\\n\").some((line) => {\n return (\n (line.startsWith(\"+\") || line.startsWith(\"-\")) &&\n !line.startsWith(\"+++\") &&\n !line.startsWith(\"---\")\n );\n });\n\n return {\n skillDirName,\n forkedFrom,\n hasDiff,\n diffOutput: diff,\n };\n}\n\n/**\n * Colorizes a unified diff string for terminal display.\n * Applies chalk formatting: bold for file headers, green for additions,\n * red for removals, cyan for hunk headers.\n */\nexport function formatColoredDiff(diffText: string): string {\n return diffText\n .split(\"\\n\")\n .map((line) => {\n if (line.startsWith(\"+++\") || line.startsWith(\"---\")) {\n return chalk.bold(line);\n }\n if (line.startsWith(\"+\")) {\n return chalk.green(line);\n }\n if (line.startsWith(\"-\")) {\n return chalk.red(line);\n }\n if (line.startsWith(\"@@\")) {\n return chalk.cyan(line);\n }\n return line;\n })\n .join(\"\\n\");\n}\n","import path from \"path\";\nimport { fileExists, readFile } from \"../../utils/fs.js\";\nimport { discoverLocalSkills } from \"../skills/index.js\";\nimport { STANDARD_FILES } from \"../../consts.js\";\nimport type { ResolvedSkill, SkillId, SkillSlug } from \"../../types/index.js\";\nimport { truncateText } from \"../../utils/string.js\";\n\nconst CONTENT_PREVIEW_LINES = 10;\nconst MAX_LINE_LENGTH = 80;\nconst MAX_SUGGESTIONS = 5;\n\nexport type ResolvedSkillInfo = {\n skill: ResolvedSkill;\n isInstalled: boolean;\n preview: string[];\n};\n\nexport type SkillInfoResult = {\n resolved: ResolvedSkillInfo | null;\n suggestions: string[];\n};\n\nexport type ResolveSkillInfoOptions = {\n /** The skill ID, slug, or search query from user input */\n query: string;\n /** Full skills map from the loaded matrix */\n skills: Partial<Record<SkillId, ResolvedSkill>>;\n /** Slug-to-ID lookup map from the loaded matrix */\n slugToId: Partial<Record<SkillSlug, SkillId>>;\n /** Project directory for local skill discovery */\n projectDir: string;\n /** Resolved source path from loadSource */\n sourcePath: string;\n /** Whether the source is local */\n isLocal: boolean;\n /** Whether to load the content preview */\n includePreview: boolean;\n};\n\n/**\n * Strips YAML frontmatter delimiters and content from markdown.\n */\nfunction stripFrontmatter(content: string): string {\n const lines = content.split(\"\\n\");\n let inFrontmatter = false;\n let frontmatterEndIndex = 0;\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i].trim();\n if (line === \"---\") {\n if (!inFrontmatter) {\n inFrontmatter = true;\n } else {\n frontmatterEndIndex = i + 1;\n break;\n }\n }\n }\n\n return lines.slice(frontmatterEndIndex).join(\"\\n\");\n}\n\n/**\n * Extracts the first N non-empty lines from markdown content (after frontmatter).\n */\nfunction getPreviewLines(content: string, maxLines: number): string[] {\n const body = stripFrontmatter(content);\n const lines = body.split(\"\\n\");\n const result: string[] = [];\n\n for (const line of lines) {\n if (result.length >= maxLines) break;\n if (line.trim() || result.length > 0) {\n result.push(truncateText(line, MAX_LINE_LENGTH));\n }\n }\n\n return result;\n}\n\n/**\n * Finds similar skill names for \"did you mean\" suggestions.\n */\nfunction findSuggestions(\n skills: Partial<Record<SkillId, ResolvedSkill>>,\n query: string,\n maxSuggestions: number,\n): string[] {\n const lowerQuery = query.toLowerCase();\n const matches: string[] = [];\n\n for (const skill of Object.values(skills)) {\n if (!skill) continue;\n if (matches.length >= maxSuggestions) break;\n if (\n skill.id.toLowerCase().includes(lowerQuery) ||\n skill.displayName.toLowerCase().includes(lowerQuery) ||\n skill.slug.toLowerCase().includes(lowerQuery)\n ) {\n matches.push(skill.id);\n }\n }\n\n return matches;\n}\n\n/**\n * Resolves complete skill information for display.\n *\n * Looks up the skill by ID or slug, discovers local installation status,\n * and optionally loads a content preview from SKILL.md.\n */\nexport async function resolveSkillInfo(options: ResolveSkillInfoOptions): Promise<SkillInfoResult> {\n const { query, skills, slugToId, projectDir, sourcePath, isLocal, includePreview } = options;\n\n // CLI arg is an untyped string — try as skill ID first, then as slug\n const slugResolvedId = slugToId[query as SkillSlug];\n const skill = skills[query as SkillId] ?? (slugResolvedId ? skills[slugResolvedId] : undefined);\n\n if (!skill) {\n const suggestions = findSuggestions(skills, query, MAX_SUGGESTIONS);\n return { resolved: null, suggestions };\n }\n\n const localSkillsResult = await discoverLocalSkills(projectDir);\n const localSkillIds = localSkillsResult?.skills.map((s) => s.id) || [];\n const isInstalled = localSkillIds.includes(skill.id);\n\n let preview: string[] = [];\n if (includePreview) {\n let skillMdPath: string;\n\n if (skill.local && skill.localPath) {\n skillMdPath = path.join(projectDir, skill.localPath, STANDARD_FILES.SKILL_MD);\n } else {\n const sourceDir = isLocal ? sourcePath : path.dirname(sourcePath);\n skillMdPath = path.join(sourceDir, skill.path, STANDARD_FILES.SKILL_MD);\n }\n\n if (await fileExists(skillMdPath)) {\n const content = await readFile(skillMdPath);\n preview = getPreviewLines(content, CONTENT_PREVIEW_LINES);\n }\n }\n\n return {\n resolved: { skill, isInstalled, preview },\n suggestions: [],\n };\n}\n","import path from \"path\";\nimport {\n copy,\n ensureDir,\n directoryExists,\n fileExists,\n listDirectories,\n writeFile,\n} from \"../../utils/fs.js\";\nimport {\n CLAUDE_SRC_DIR,\n DIRS,\n LOCAL_SKILLS_PATH,\n PROJECT_ROOT,\n STANDARD_FILES,\n} from \"../../consts.js\";\nimport { copySkillsToLocalFlattened, type CopiedSkill } from \"../skills/index.js\";\nimport { resolveSource, loadProjectSourceConfig } from \"../configuration/index.js\";\nimport type { SourceLoadResult } from \"../loading/index.js\";\nimport type { MergedSkillsMatrix, SkillId } from \"../../types/index.js\";\nimport { typedKeys } from \"../../utils/typed-object.js\";\n\n// ---------------------------------------------------------------------------\n// ejectAgentPartials\n// ---------------------------------------------------------------------------\n\nexport type EjectAgentPartialsOptions = {\n outputBase: string;\n force: boolean;\n /** When true, outputBase is used directly as the destination (no subdirectory nesting). */\n directOutput?: boolean;\n /** When true, ejects only the _templates directory instead of the full agents directory. */\n templatesOnly?: boolean;\n};\n\nexport type EjectAgentPartialsResult = {\n /** Whether the operation was skipped (e.g. destination already exists without --force). */\n skipped: boolean;\n /** Human-readable reason when skipped. */\n skipReason?: string;\n /** Destination directory that was written to (undefined when skipped). */\n destDir?: string;\n /** Whether templates were skipped during a full agent-partials eject (existing templates preserved). */\n templatesSkipped: boolean;\n};\n\n/**\n * Copies agent partials or templates from the CLI source to a target directory.\n *\n * When `templatesOnly` is true, copies only the _templates subdirectory.\n * When false, copies the full agents directory (optionally skipping existing templates).\n *\n * Returns structured data — the command decides what to log.\n */\nexport async function ejectAgentPartials(\n options: EjectAgentPartialsOptions,\n): Promise<EjectAgentPartialsResult> {\n const { outputBase, force, directOutput = false, templatesOnly = false } = options;\n\n const sourceDir = templatesOnly\n ? path.join(PROJECT_ROOT, DIRS.templates)\n : path.join(PROJECT_ROOT, DIRS.agents);\n\n if (!(await directoryExists(sourceDir))) {\n return {\n skipped: true,\n skipReason: templatesOnly\n ? \"No agent templates found in CLI.\"\n : \"No agent partials found in CLI.\",\n templatesSkipped: false,\n };\n }\n\n const destDir = directOutput\n ? outputBase\n : templatesOnly\n ? path.join(outputBase, path.basename(DIRS.agents), path.basename(DIRS.templates))\n : path.join(outputBase, path.basename(DIRS.agents));\n\n const templatesBasename = path.basename(DIRS.templates);\n\n if ((await directoryExists(destDir)) && !force) {\n if (templatesOnly) {\n return {\n skipped: true,\n skipReason: `Agent templates already exist at ${destDir}. Use --force to overwrite.`,\n templatesSkipped: false,\n };\n }\n\n const hasTemplates = await directoryExists(path.join(destDir, templatesBasename));\n if ((await hasAgentPartialDirs(destDir)) && !hasTemplates) {\n return {\n skipped: true,\n skipReason: `Agent partials already exist at ${destDir}. Use --force to overwrite.`,\n templatesSkipped: false,\n };\n }\n }\n\n await ensureDir(destDir);\n\n const skipTemplates =\n !templatesOnly && !force && (await directoryExists(path.join(destDir, templatesBasename)));\n\n if (skipTemplates) {\n const sourceEntries = await listDirectories(sourceDir);\n const nonTemplateEntries = sourceEntries.filter((entry) => entry !== templatesBasename);\n for (const entry of nonTemplateEntries) {\n await copy(path.join(sourceDir, entry), path.join(destDir, entry));\n }\n } else {\n await copy(sourceDir, destDir);\n }\n\n return {\n skipped: false,\n destDir,\n templatesSkipped: skipTemplates,\n };\n}\n\n// ---------------------------------------------------------------------------\n// ejectSkills\n// ---------------------------------------------------------------------------\n\nexport type EjectSkillsOptions = {\n projectDir: string;\n force: boolean;\n sourceResult: SourceLoadResult;\n matrix: MergedSkillsMatrix;\n /** When true, uses customOutputBase as destination instead of LOCAL_SKILLS_PATH. */\n directOutput?: boolean;\n customOutputBase?: string;\n};\n\nexport type EjectSkillsResult = {\n /** Whether the operation was skipped. */\n skipped: boolean;\n /** Human-readable reason when skipped. */\n skipReason?: string;\n /** Array of skills that were copied. */\n copiedSkills: CopiedSkill[];\n /** Destination directory that was written to. */\n destDir?: string;\n /** Label describing the source that skills were copied from. */\n sourceLabel?: string;\n};\n\n/**\n * Copies non-local skills from source to a target directory.\n *\n * Filters out skills already marked as local, then copies the remaining skills\n * using copySkillsToLocalFlattened.\n *\n * Returns structured data — the command decides what to log.\n */\nexport async function ejectSkills(options: EjectSkillsOptions): Promise<EjectSkillsResult> {\n const {\n projectDir,\n force,\n sourceResult,\n matrix,\n directOutput = false,\n customOutputBase,\n } = options;\n\n const destDir =\n directOutput && customOutputBase ? customOutputBase : path.join(projectDir, LOCAL_SKILLS_PATH);\n\n if ((await directoryExists(destDir)) && !force) {\n return {\n skipped: true,\n skipReason: `Skills already exist at ${destDir}. Use --force to overwrite.`,\n copiedSkills: [],\n };\n }\n\n const skillIds = typedKeys<SkillId>(matrix.skills).filter(\n (skillId) => !matrix.skills[skillId]?.local,\n );\n\n if (skillIds.length === 0) {\n return {\n skipped: true,\n skipReason: \"No skills found in source to eject.\",\n copiedSkills: [],\n };\n }\n\n await ensureDir(destDir);\n\n const copiedSkills = await copySkillsToLocalFlattened(skillIds, destDir, matrix, sourceResult);\n\n const sourceLabel = sourceResult.isLocal\n ? sourceResult.sourcePath\n : sourceResult.marketplace || sourceResult.sourceConfig.source;\n\n return {\n skipped: false,\n copiedSkills,\n destDir,\n sourceLabel,\n };\n}\n\n// ---------------------------------------------------------------------------\n// ensureMinimalConfig\n// ---------------------------------------------------------------------------\n\nexport type EnsureMinimalConfigOptions = {\n projectDir: string;\n sourceFlag?: string;\n sourceResult?: SourceLoadResult;\n};\n\nexport type EnsureMinimalConfigResult = {\n /** Path to the config file. */\n configPath: string;\n /** Whether a new config was created. */\n created: boolean;\n};\n\n/**\n * Ensures a minimal config.ts exists so `agentsinc compile` works after eject.\n *\n * If the config already exists, returns immediately with `created: false`.\n * Otherwise generates a minimal config from the resolved source and project metadata.\n *\n * Returns structured data — the command decides what to log.\n */\nexport async function ensureMinimalConfig(\n options: EnsureMinimalConfigOptions,\n): Promise<EnsureMinimalConfigResult> {\n const { projectDir, sourceFlag, sourceResult } = options;\n\n const tsConfigPath = path.join(projectDir, CLAUDE_SRC_DIR, STANDARD_FILES.CONFIG_TS);\n\n if (await fileExists(tsConfigPath)) {\n return { configPath: tsConfigPath, created: false };\n }\n\n const projectName = path.basename(projectDir);\n\n const config: Record<string, unknown> = {\n name: projectName,\n };\n\n const resolvedConfig =\n sourceResult?.sourceConfig ?? (await resolveSource(sourceFlag, projectDir));\n\n if (sourceFlag) {\n config.source = sourceFlag;\n } else if (resolvedConfig.source) {\n config.source = resolvedConfig.source;\n }\n\n if (resolvedConfig.marketplace) {\n config.marketplace = resolvedConfig.marketplace;\n }\n\n const existingProjectConfig = await loadProjectSourceConfig(projectDir);\n if (existingProjectConfig?.author) {\n config.author = existingProjectConfig.author;\n }\n if (existingProjectConfig?.agentsSource) {\n config.agentsSource = existingProjectConfig.agentsSource;\n }\n\n await ensureDir(path.join(projectDir, CLAUDE_SRC_DIR));\n\n // JSON.parse(JSON.stringify(x)) removes undefined values\n const cleaned = JSON.parse(JSON.stringify(config));\n const body = JSON.stringify(cleaned, null, 2);\n const content = `export default ${body};\\n`;\n\n await writeFile(tsConfigPath, content);\n\n return { configPath: tsConfigPath, created: true };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Checks whether the agents directory contains any agent subdirectories (not just _templates). */\nasync function hasAgentPartialDirs(agentsDir: string): Promise<boolean> {\n const subdirs = await listDirectories(agentsDir);\n const templatesBasename = path.basename(DIRS.templates);\n return subdirs.some((dir) => dir !== templatesBasename);\n}\n","import path from \"path\";\nimport { readdir } from \"fs/promises\";\nimport { directoryExists, listDirectories, remove } from \"../../utils/fs.js\";\nimport { claudePluginUninstall, isClaudeCLIAvailable } from \"../../utils/exec.js\";\nimport { listPluginNames, getProjectPluginsDir } from \"../plugins/index.js\";\nimport { readForkedFromMetadata } from \"../skills/index.js\";\nimport { loadProjectConfigFromDir } from \"../configuration/project-config.js\";\nimport { getErrorMessage } from \"../../utils/errors.js\";\nimport { CLAUDE_DIR, CLAUDE_SRC_DIR } from \"../../consts.js\";\nimport type { ProjectConfig } from \"../../types/index.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport type UninstallTarget = {\n hasPlugins: boolean;\n pluginNames: string[];\n /** Plugin names filtered to only those installed by this CLI (matched against config skills) */\n cliPluginNames: string[];\n hasLocalSkills: boolean;\n hasLocalAgents: boolean;\n hasClaudeDir: boolean;\n hasClaudeSrcDir: boolean;\n pluginsDir: string;\n skillsDir: string;\n agentsDir: string;\n claudeDir: string;\n claudeSrcDir: string;\n /** Resolved project source config from .claude-src/config.ts */\n config: Partial<ProjectConfig> | null;\n /** Agent names from the generated config (e.g., [\"web-developer\"]) */\n configuredAgents: string[];\n};\n\nexport type SkillRemovalResult = {\n removedCount: number;\n skippedCount: number;\n removedNames: string[];\n skippedNames: string[];\n /** Whether the skills directory was cleaned up (empty after removal) */\n dirCleaned: boolean;\n};\n\nexport type AgentRemovalResult = {\n removedCount: number;\n removedNames: string[];\n /** Whether the agents directory was cleaned up (empty after removal) */\n dirCleaned: boolean;\n};\n\nexport type UninstallPluginsResult = {\n uninstalledNames: string[];\n totalUninstalled: number;\n};\n\nexport type CleanupResult = {\n claudeDirRemoved: boolean;\n claudeSrcDirRemoved: boolean;\n /** Whether .claude/ still exists with user content after cleanup */\n claudeDirKept: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// detectUninstallTarget\n// ---------------------------------------------------------------------------\n\nfunction collectConfiguredAgents(config: Partial<ProjectConfig> | null): string[] {\n if (!config?.agents) return [];\n return config.agents.map((a) => a.name);\n}\n\nfunction getCliInstalledPluginKeys(config: Partial<ProjectConfig> | null): Set<string> {\n if (!config?.skills) return new Set();\n return new Set(config.skills.map((skill) => `${skill.id}@${skill.source}`));\n}\n\n/**\n * Detects what's installed in a project directory for uninstallation.\n *\n * Checks for plugins, local skills, agents, config directories, and\n * resolves which plugins were installed by this CLI.\n */\nexport async function detectUninstallTarget(projectDir: string): Promise<UninstallTarget> {\n const pluginsDir = getProjectPluginsDir(projectDir);\n const skillsDir = path.join(projectDir, CLAUDE_DIR, \"skills\");\n const agentsDir = path.join(projectDir, CLAUDE_DIR, \"agents\");\n const claudeDir = path.join(projectDir, CLAUDE_DIR);\n const claudeSrcDir = path.join(projectDir, CLAUDE_SRC_DIR);\n\n const [hasLocalSkills, hasLocalAgents, hasClaudeDir, hasClaudeSrcDir, config] = await Promise.all(\n [\n directoryExists(skillsDir),\n directoryExists(agentsDir),\n directoryExists(claudeDir),\n directoryExists(claudeSrcDir),\n loadProjectConfigFromDir(projectDir).then((result) => result?.config ?? null),\n ],\n );\n\n let pluginNames: string[] = [];\n try {\n pluginNames = await listPluginNames(projectDir);\n } catch {\n // Best-effort: plugin detection may fail\n }\n\n const configuredAgents = collectConfiguredAgents(config);\n const cliInstalledKeys = getCliInstalledPluginKeys(config);\n const cliPluginNames = pluginNames.filter((name) => cliInstalledKeys.has(name));\n\n return {\n hasPlugins: cliPluginNames.length > 0,\n pluginNames,\n cliPluginNames,\n hasLocalSkills,\n hasLocalAgents,\n hasClaudeDir,\n hasClaudeSrcDir,\n pluginsDir,\n skillsDir,\n agentsDir,\n claudeDir,\n claudeSrcDir,\n config,\n configuredAgents,\n };\n}\n\n// ---------------------------------------------------------------------------\n// removeMatchingSkills\n// ---------------------------------------------------------------------------\n\nfunction shouldRemoveSkill(forkedFrom: { source?: string } | null): boolean {\n return forkedFrom !== null;\n}\n\n/**\n * Removes local skills that were installed by the CLI (have forked-from metadata).\n *\n * Scans the skills directory, checks each skill for CLI-installed metadata,\n * and removes matching skills. User-created skills (without metadata) are preserved.\n *\n * @param onRemoved - Called for each removed skill directory name (for logging)\n * @param onSkipped - Called for each skipped skill directory name (for logging)\n */\nexport async function removeMatchingSkills(\n target: Pick<UninstallTarget, \"hasLocalSkills\" | \"skillsDir\">,\n onRemoved?: (dirName: string) => void,\n onSkipped?: (dirName: string) => void,\n): Promise<SkillRemovalResult> {\n if (!target.hasLocalSkills) {\n return {\n removedCount: 0,\n skippedCount: 0,\n removedNames: [],\n skippedNames: [],\n dirCleaned: false,\n };\n }\n\n const skillDirNames = await listDirectories(target.skillsDir);\n const removedNames: string[] = [];\n const skippedNames: string[] = [];\n\n for (const skillDirName of skillDirNames) {\n const skillDir = path.join(target.skillsDir, skillDirName);\n const forkedFrom = await readForkedFromMetadata(skillDir);\n\n if (shouldRemoveSkill(forkedFrom)) {\n await remove(skillDir);\n removedNames.push(skillDirName);\n onRemoved?.(skillDirName);\n } else {\n skippedNames.push(skillDirName);\n onSkipped?.(skillDirName);\n }\n }\n\n let dirCleaned = false;\n if (skippedNames.length === 0 && (await directoryExists(target.skillsDir))) {\n if (await isDirectoryEmpty(target.skillsDir)) {\n await remove(target.skillsDir);\n dirCleaned = true;\n }\n }\n\n return {\n removedCount: removedNames.length,\n skippedCount: skippedNames.length,\n removedNames,\n skippedNames,\n dirCleaned,\n };\n}\n\n// ---------------------------------------------------------------------------\n// removeMatchingAgents\n// ---------------------------------------------------------------------------\n\n/**\n * Removes compiled agent .md files that match configured agent names.\n *\n * Only removes agents that are listed in the project config (CLI-compiled).\n * Cleans up the agents directory if empty after removal.\n *\n * @param onRemoved - Called for each removed agent name (for logging)\n */\nexport async function removeMatchingAgents(\n target: Pick<UninstallTarget, \"hasLocalAgents\" | \"agentsDir\" | \"configuredAgents\">,\n onRemoved?: (agentName: string) => void,\n): Promise<AgentRemovalResult> {\n if (!target.hasLocalAgents) {\n return { removedCount: 0, removedNames: [], dirCleaned: false };\n }\n\n if (target.configuredAgents.length === 0) {\n return { removedCount: 0, removedNames: [], dirCleaned: false };\n }\n\n const agentFiles = await listAgentFiles(target.agentsDir);\n const removedNames: string[] = [];\n\n for (const agentFile of agentFiles) {\n const agentName = agentFile.replace(/\\.md$/, \"\");\n if (!target.configuredAgents.includes(agentName)) continue;\n\n await remove(path.join(target.agentsDir, agentFile));\n removedNames.push(agentName);\n onRemoved?.(agentName);\n }\n\n let dirCleaned = false;\n if (await directoryExists(target.agentsDir)) {\n if (await isDirectoryEmpty(target.agentsDir)) {\n await remove(target.agentsDir);\n dirCleaned = true;\n }\n }\n\n return {\n removedCount: removedNames.length,\n removedNames,\n dirCleaned,\n };\n}\n\n// ---------------------------------------------------------------------------\n// uninstallPlugins\n// ---------------------------------------------------------------------------\n\n/**\n * Uninstalls CLI-managed plugins by removing them from the Claude CLI\n * and deleting their local directories.\n *\n * Derives scope from per-skill config when available; falls back to project-level.\n *\n * @param onUninstalled - Called for each successfully uninstalled plugin name (for logging)\n */\nexport async function uninstallPlugins(\n target: Pick<UninstallTarget, \"hasPlugins\" | \"cliPluginNames\" | \"pluginsDir\" | \"config\">,\n projectDir: string,\n onUninstalled?: (pluginName: string) => void,\n): Promise<UninstallPluginsResult> {\n if (!target.hasPlugins) {\n return { uninstalledNames: [], totalUninstalled: 0 };\n }\n\n const cliAvailable = await isClaudeCLIAvailable();\n const uninstalledNames: string[] = [];\n\n for (const pluginName of target.cliPluginNames) {\n if (cliAvailable) {\n try {\n // Derive scope from per-skill config; fall back to project-level heuristic\n const skillId = pluginName.split(\"@\")[0];\n const skillConfig = target.config?.skills?.find((s) => s.id === skillId);\n const pluginScope = skillConfig?.scope === \"global\" ? \"user\" : \"project\";\n await claudePluginUninstall(pluginName, pluginScope, projectDir);\n } catch {\n // Best-effort: plugin may not be registered with Claude CLI\n }\n }\n\n const pluginPath = path.join(target.pluginsDir, pluginName);\n await remove(pluginPath);\n uninstalledNames.push(pluginName);\n onUninstalled?.(pluginName);\n }\n\n return {\n uninstalledNames,\n totalUninstalled: uninstalledNames.length,\n };\n}\n\n// ---------------------------------------------------------------------------\n// cleanupEmptyDirs\n// ---------------------------------------------------------------------------\n\n/**\n * Removes empty .claude/ and .claude-src/ directories after uninstall.\n *\n * Only removes .claude-src/ when `removeAll` is true.\n * Only removes .claude/ when it's completely empty.\n */\nexport async function cleanupEmptyDirs(\n target: Pick<UninstallTarget, \"hasClaudeDir\" | \"hasClaudeSrcDir\" | \"claudeDir\" | \"claudeSrcDir\">,\n removeAll: boolean,\n): Promise<CleanupResult> {\n let claudeSrcDirRemoved = false;\n if (removeAll && target.hasClaudeSrcDir) {\n await remove(target.claudeSrcDir);\n claudeSrcDirRemoved = true;\n }\n\n let claudeDirRemoved = false;\n let claudeDirKept = false;\n if (target.hasClaudeDir && (await directoryExists(target.claudeDir))) {\n if (await isDirectoryEmpty(target.claudeDir)) {\n await remove(target.claudeDir);\n claudeDirRemoved = true;\n } else {\n claudeDirKept = true;\n }\n }\n\n return { claudeDirRemoved, claudeSrcDirRemoved, claudeDirKept };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nasync function isDirectoryEmpty(dirPath: string): Promise<boolean> {\n try {\n const allEntries = await readdir(dirPath);\n return allEntries.length === 0;\n } catch {\n return true;\n }\n}\n\nasync function listAgentFiles(agentsDir: string): Promise<string[]> {\n try {\n return (await readdir(agentsDir)).filter((f) => f.endsWith(\".md\"));\n } catch {\n return [];\n }\n}\n","import path from \"path\";\n\nimport { DEFAULT_SKILLS_SUBDIR, LOCAL_SKILLS_PATH, STANDARD_FILES } from \"../../consts.js\";\nimport type { SourceEntry } from \"../../types/config.js\";\nimport type { CategoryPath, ResolvedSkill, SkillSlug } from \"../../types/index.js\";\nimport { copy, ensureDir, fileExists, listDirectories, readFile } from \"../../utils/fs.js\";\nimport { fetchFromSource, parseFrontmatter } from \"../loading/index.js\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** A skill with source provenance info, used for search results and imports. */\nexport type SourcedSkill = ResolvedSkill & {\n sourceName: string;\n sourceUrl?: string;\n};\n\nexport type FilterSkillsOptions = {\n query: string;\n category?: string;\n};\n\nexport type CopySearchedSkillResult = {\n id: string;\n copied: boolean;\n /** Reason when `copied` is false */\n reason?: string;\n};\n\n// ---------------------------------------------------------------------------\n// Fetching\n// ---------------------------------------------------------------------------\n\n/**\n * Fetches skills from an external (non-primary) source entry.\n *\n * Discovers SKILL.md files in the source's skills directory, parses\n * frontmatter, and returns typed SourcedSkill entries.\n * Returns an empty array when the source is unavailable or has no skills.\n */\nexport async function fetchSkillsFromExternalSource(\n source: SourceEntry,\n forceRefresh: boolean,\n): Promise<SourcedSkill[]> {\n try {\n const result = await fetchFromSource(source.url, { forceRefresh });\n const skillsDir = path.join(result.path, DEFAULT_SKILLS_SUBDIR);\n\n if (!(await fileExists(skillsDir))) {\n return [];\n }\n\n const skillDirs = await listDirectories(skillsDir);\n const skills: SourcedSkill[] = [];\n\n for (const skillDir of skillDirs) {\n const skillMdPath = path.join(skillsDir, skillDir, STANDARD_FILES.SKILL_MD);\n if (!(await fileExists(skillMdPath))) continue;\n\n const content = await readFile(skillMdPath);\n const frontmatter = parseFrontmatter(content, skillMdPath);\n if (!frontmatter) continue;\n\n skills.push({\n id: frontmatter.name,\n description: frontmatter.description,\n // Boundary cast: directory name used as slug for third-party source skill\n slug: skillDir as SkillSlug,\n displayName: skillDir,\n // Boundary cast: external source skills have no real category; \"imported\" is a display-only placeholder\n category: \"imported\" as CategoryPath,\n author: `@${source.name}`,\n conflictsWith: [],\n isRecommended: false,\n requires: [],\n alternatives: [],\n discourages: [],\n compatibleWith: [],\n sourceName: source.name,\n sourceUrl: source.url,\n path: path.join(skillsDir, skillDir),\n });\n }\n\n return skills;\n } catch {\n // Source unavailable, return empty\n return [];\n }\n}\n\n// ---------------------------------------------------------------------------\n// Filtering\n// ---------------------------------------------------------------------------\n\nfunction matchesQuery(skill: ResolvedSkill, query: string): boolean {\n const lowerQuery = query.toLowerCase();\n\n if (skill.id.toLowerCase().includes(lowerQuery)) return true;\n if (skill.displayName.toLowerCase().includes(lowerQuery)) return true;\n if (skill.slug.toLowerCase().includes(lowerQuery)) return true;\n if (skill.description.toLowerCase().includes(lowerQuery)) return true;\n if (skill.category.toLowerCase().includes(lowerQuery)) return true;\n\n return false;\n}\n\nfunction matchesCategory(skill: ResolvedSkill, category: string): boolean {\n const lowerCategory = category.toLowerCase();\n return skill.category.toLowerCase().includes(lowerCategory);\n}\n\n/**\n * Filters skills by text query and optional category.\n *\n * Matches against id, displayName, slug, description, and category fields.\n */\nexport function filterSkillsByQuery(\n skills: ResolvedSkill[],\n options: FilterSkillsOptions,\n): ResolvedSkill[] {\n let results = skills.filter((skill) => matchesQuery(skill, options.query));\n\n if (options.category) {\n results = results.filter((skill) => matchesCategory(skill, options.category!));\n }\n\n return results;\n}\n\n// ---------------------------------------------------------------------------\n// Conversion\n// ---------------------------------------------------------------------------\n\n/** Converts a ResolvedSkill to a SourcedSkill by attaching source provenance. */\nexport function toSourcedSkill(\n skill: ResolvedSkill,\n sourceName: string,\n sourceUrl?: string,\n): SourcedSkill {\n return {\n ...skill,\n sourceName,\n sourceUrl,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Copy\n// ---------------------------------------------------------------------------\n\n/**\n * Copies selected searched skills to the project's local skills directory.\n *\n * Each skill must have a `path` property pointing to its source directory.\n * Skills without a path are skipped and reported in the result.\n */\nexport async function copySearchedSkillsToLocal(\n skills: SourcedSkill[],\n projectDir: string,\n): Promise<CopySearchedSkillResult[]> {\n const destDir = path.join(projectDir, LOCAL_SKILLS_PATH);\n const results: CopySearchedSkillResult[] = [];\n\n for (const skill of skills) {\n if (skill.path) {\n const destPath = path.join(destDir, skill.id);\n await ensureDir(path.dirname(destPath));\n await copy(skill.path, destPath);\n results.push({ id: skill.id, copied: true });\n } else {\n results.push({ id: skill.id, copied: false, reason: \"No source path available\" });\n }\n }\n\n return results;\n}\n","import { spawn } from \"child_process\";\nimport matter from \"gray-matter\";\nimport path from \"path\";\n\nimport { CLAUDE_DIR } from \"../../consts.js\";\nimport { getAgentDefinitions } from \"../agents/index.js\";\nimport { fileExists, readFile } from \"../../utils/fs.js\";\n\nconst META_AGENT_NAME = \"agent-summoner\";\n\nexport type NewAgentInput = {\n description: string;\n prompt: string;\n model?: string;\n tools?: string[];\n};\n\nexport type LoadMetaAgentOptions = {\n projectDir: string;\n source: string;\n forceRefresh: boolean;\n};\n\nexport type InvokeMetaAgentOptions = {\n agentDef: NewAgentInput;\n prompt: string;\n nonInteractive: boolean;\n};\n\n/**\n * Parses a compiled agent markdown file to extract the agent definition.\n *\n * Reads YAML frontmatter for description/model/tools and the body as the prompt.\n */\nexport function parseCompiledAgent(content: string): NewAgentInput {\n const { data: frontmatter, content: body } = matter(content);\n const tools =\n typeof frontmatter.tools === \"string\"\n ? frontmatter.tools.split(\",\").map((t: string) => t.trim())\n : frontmatter.tools;\n\n return {\n description: frontmatter.description || \"Creates new agents\",\n prompt: body.trim(),\n model: frontmatter.model,\n tools,\n };\n}\n\n/**\n * Loads the meta-agent (agent-summoner) from either a compiled local agent\n * or a remote source. Parses the compiled agent markdown.\n *\n * @throws {Error} If the meta-agent cannot be found locally or remotely.\n */\nexport async function loadMetaAgent(options: LoadMetaAgentOptions): Promise<NewAgentInput> {\n const { projectDir, source, forceRefresh } = options;\n const compiledFileName = `${META_AGENT_NAME}.md`;\n\n // Check for compiled agent in the current project\n const localAgentPath = path.join(projectDir, CLAUDE_DIR, \"agents\", compiledFileName);\n if (await fileExists(localAgentPath)) {\n return parseCompiledAgent(await readFile(localAgentPath));\n }\n\n // Fall back to remote source (may not have agents)\n try {\n const agentPaths = await getAgentDefinitions(source, { forceRefresh, projectDir });\n const remoteAgentPath = path.join(\n agentPaths.sourcePath,\n CLAUDE_DIR,\n \"agents\",\n compiledFileName,\n );\n if (await fileExists(remoteAgentPath)) {\n return parseCompiledAgent(await readFile(remoteAgentPath));\n }\n } catch {\n // Source does not contain agents — fall through to error\n }\n\n throw new Error(\n `Agent '${META_AGENT_NAME}' not found.\\n\\n` + `Run 'compile' first to generate agents.`,\n );\n}\n\n/**\n * Constructs the prompt for the meta-agent based on user input.\n */\nexport function buildAgentPrompt(agentName: string, purpose: string, outputDir: string): string {\n return `Create a new Claude Code agent named \"${agentName}\" in the directory \"${outputDir}\".\n\nAgent Purpose: ${purpose}\n\nRequirements:\n1. Create the agent directory structure at ${outputDir}/${agentName}/\n2. Create metadata.yaml with appropriate configuration\n3. Create intro.md with the agent's role and context\n4. Create workflow.md with the agent's operational process\n5. Optionally create examples.md if relevant examples would help\n6. Optionally create critical-requirements.md for important rules\n7. Include \\`custom: true\\` in the metadata.yaml configuration\n\nFollow the existing agent patterns in the codebase. Keep the agent focused and practical.`;\n}\n\n/**\n * Spawns the Claude CLI to execute the meta-agent with the constructed prompt.\n *\n * Uses `stdio: \"inherit\"` so the CLI output streams directly to the terminal.\n *\n * @throws {Error} If the Claude CLI fails to spawn or exits with a non-zero code.\n */\nexport async function invokeMetaAgent(options: InvokeMetaAgentOptions): Promise<void> {\n const { agentDef, prompt, nonInteractive } = options;\n\n const agentsJson = JSON.stringify({\n [META_AGENT_NAME]: {\n description: agentDef.description,\n prompt: agentDef.prompt,\n model: agentDef.model,\n tools: agentDef.tools,\n },\n });\n\n const args = [\"--agents\", agentsJson, \"--agent\", META_AGENT_NAME];\n\n if (nonInteractive) {\n args.push(\"-p\", prompt);\n } else {\n args.push(\"--prompt\", prompt);\n }\n\n return new Promise((resolve, reject) => {\n const child = spawn(\"claude\", args, {\n stdio: \"inherit\",\n });\n\n child.on(\"error\", (error) => {\n reject(new Error(`Failed to spawn claude CLI: ${error.message}`));\n });\n\n child.on(\"close\", (code) => {\n if (code === 0) {\n resolve();\n } else {\n reject(new Error(`Claude CLI exited with code ${code}`));\n }\n });\n });\n}\n","import { claudePluginInstall, claudePluginUninstall } from \"../../utils/exec.js\";\nimport { getErrorMessage } from \"../../utils/errors.js\";\nimport type { SkillId } from \"../../types/index.js\";\n\nexport type PluginScopeMigrationResult = {\n migrated: SkillId[];\n failed: Array<{ id: SkillId; error: string }>;\n};\n\n/**\n * Migrates plugin skills between scopes by uninstalling from the old scope\n * and reinstalling to the new scope via the Claude CLI.\n *\n * Only processes plugin skills (source !== \"local\"). Local skills are\n * handled separately via `migrateLocalSkillScope`.\n */\nexport async function migratePluginSkillScopes(\n scopeChanges: Map<SkillId, { from: \"project\" | \"global\"; to: \"project\" | \"global\" }>,\n skills: Array<{ id: SkillId; source: string }>,\n marketplace: string,\n projectDir: string,\n): Promise<PluginScopeMigrationResult> {\n const migrated: SkillId[] = [];\n const failed: PluginScopeMigrationResult[\"failed\"] = [];\n\n for (const [skillId, change] of scopeChanges) {\n const skillConfig = skills.find((s) => s.id === skillId);\n if (!skillConfig || skillConfig.source === \"local\") {\n continue;\n }\n\n const oldPluginScope = change.from === \"global\" ? \"user\" : \"project\";\n const newPluginScope = change.to === \"global\" ? \"user\" : \"project\";\n const pluginRef = `${skillId}@${marketplace}`;\n\n try {\n await claudePluginUninstall(skillId, oldPluginScope, projectDir);\n await claudePluginInstall(pluginRef, newPluginScope, projectDir);\n migrated.push(skillId);\n } catch (error) {\n failed.push({ id: skillId, error: getErrorMessage(error) });\n }\n }\n\n return { migrated, failed };\n}\n","// Operations — composable building blocks for CLI commands.\n// Each operation wraps lower-level lib functions into a single typed call.\n\nexport { detectBothInstallations, type BothInstallations } from \"./detect-both-installations.js\";\nexport { loadSource, type LoadSourceOptions, type LoadedSource } from \"./load-source.js\";\nexport { getDashboardData, type DashboardData } from \"./get-dashboard-data.js\";\nexport { detectProject, type DetectedProject } from \"./detect-project.js\";\nexport { loadAgentDefs, type AgentDefs } from \"./load-agent-defs.js\";\nexport { copyLocalSkills, type SkillCopyResult } from \"./copy-local-skills.js\";\nexport { installPluginSkills, type PluginInstallResult } from \"./install-plugin-skills.js\";\nexport { uninstallPluginSkills, type PluginUninstallResult } from \"./uninstall-plugin-skills.js\";\nexport {\n compareSkillsWithSource,\n buildSourceSkillsMap,\n type SkillComparisonResults,\n} from \"./compare-skills.js\";\nexport { ensureMarketplace, type MarketplaceResult } from \"./ensure-marketplace.js\";\nexport {\n writeProjectConfig,\n type ConfigWriteOptions,\n type ConfigWriteResult,\n} from \"./write-project-config.js\";\nexport {\n compileAgents,\n type CompileAgentsOptions,\n type CompilationResult,\n} from \"./compile-agents.js\";\nexport { detectConfigChanges, type ConfigChanges } from \"./detect-config-changes.js\";\nexport {\n executeInstallation,\n type ExecuteInstallationOptions,\n type ExecuteInstallationResult,\n} from \"./execute-installation.js\";\nexport {\n recompileProject,\n type RecompileProjectOptions,\n type RecompileProjectResult,\n} from \"./recompile-project.js\";\nexport {\n updateLocalSkills,\n type SkillUpdateResult,\n type UpdateLocalSkillsResult,\n type UpdateLocalSkillsOptions,\n} from \"./update-local-skills.js\";\nexport {\n discoverInstalledSkills,\n loadSkillsFromDir,\n discoverLocalProjectSkills,\n mergeSkills,\n type DiscoveredSkills,\n} from \"./discover-skills.js\";\nexport {\n collectScopedSkillDirs,\n type ScopedSkillDir,\n type ScopedSkillDirsResult,\n} from \"./collect-scoped-skill-dirs.js\";\nexport { findSkillMatch, type SkillMatchResult } from \"./find-skill-match.js\";\nexport {\n generateSkillDiff,\n formatColoredDiff,\n type SkillDiffResult,\n} from \"./generate-skill-diff.js\";\nexport {\n resolveSkillInfo,\n type ResolveSkillInfoOptions,\n type ResolvedSkillInfo,\n type SkillInfoResult,\n} from \"./resolve-skill-info.js\";\nexport {\n ejectAgentPartials,\n ejectSkills,\n ensureMinimalConfig,\n type EjectAgentPartialsOptions,\n type EjectAgentPartialsResult,\n type EjectSkillsOptions,\n type EjectSkillsResult,\n type EnsureMinimalConfigOptions,\n type EnsureMinimalConfigResult,\n} from \"./eject-project.js\";\nexport {\n detectUninstallTarget,\n removeMatchingSkills,\n removeMatchingAgents,\n uninstallPlugins,\n cleanupEmptyDirs,\n type UninstallTarget,\n type SkillRemovalResult,\n type AgentRemovalResult,\n type UninstallPluginsResult,\n type CleanupResult,\n} from \"./uninstall-project.js\";\nexport {\n fetchSkillsFromExternalSource,\n filterSkillsByQuery,\n toSourcedSkill,\n copySearchedSkillsToLocal,\n type SourcedSkill,\n type FilterSkillsOptions,\n type CopySearchedSkillResult,\n} from \"./search-skills.js\";\nexport {\n parseGitHubSource,\n fetchSkillSource,\n discoverValidSkills,\n importSkillFromSource,\n type ImportedForkedFromMetadata,\n type ParsedGitHubSource,\n type FetchSourceOptions,\n type FetchedSource,\n type ImportSkillOptions,\n type ImportSkillResult,\n} from \"./import-skill.js\";\nexport {\n parseCompiledAgent,\n loadMetaAgent,\n buildAgentPrompt,\n invokeMetaAgent,\n type NewAgentInput,\n type LoadMetaAgentOptions,\n type InvokeMetaAgentOptions,\n} from \"./scaffold-agent.js\";\nexport {\n migratePluginSkillScopes,\n type PluginScopeMigrationResult,\n} from \"./migrate-plugin-scope.js\";\nexport {\n validateSkillName,\n toTitleCase,\n generateSkillMd,\n generateMetadataYaml,\n generateSkillCategoriesTs,\n generateSkillRulesTs,\n scaffoldSkillFiles,\n updateSkillRegistryConfig,\n type ScaffoldSkillOptions,\n type ScaffoldSkillResult,\n type RegistryUpdateOptions,\n type RegistryUpdateResult,\n} from \"./scaffold-skill.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,OAAO,QAAQ;AAoBf,eAAsB,wBAAwB,YAAgD;AAC5F,QAAM,SAAS,MAAM,yBAAyB;AAC9C,QAAM,UAAU,eAAe,GAAG,QAAQ,IAAI,OAAO,MAAM,0BAA0B,UAAU;AAC/F,SAAO,EAAE,QAAQ,SAAS,SAAS,CAAC,CAAC,UAAU,CAAC,CAAC,QAAQ;AAC3D;;;ACxBA;AA+BA,eAAsB,WAAW,SAAmD;AAClF,QAAM,EAAE,YAAY,YAAY,cAAc,uBAAuB,IAAI;AAEzE,MAAI,wBAAwB;AAC1B,oBAAgB;AAAA,EAClB;AAEA,MAAI;AACJ,MAAI;AACF,mBAAe,MAAM,2BAA2B;AAAA,MAC9C;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAO;AACd,QAAI,wBAAwB;AAC1B,uBAAiB;AAAA,IACnB;AACA,UAAM;AAAA,EACR;AAEA,MAAI,kBAAoC,CAAC;AACzC,MAAI,wBAAwB;AAC1B,sBAAkB,YAAY;AAC9B,qBAAiB;AAAA,EACnB;AAEA,SAAO,EAAE,cAAc,gBAAgB;AACzC;;;AC3DA;AAYA,eAAsB,iBAAiB,YAA4C;AACjF,QAAM,CAAC,MAAM,MAAM,IAAI,MAAM,QAAQ,IAAI,CAAC,oBAAoB,GAAG,kBAAkB,UAAU,CAAC,CAAC;AAG/F,QAAM,aAAa,QAA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3C,QAAI;AACF,YAAM,sBAAsB,SAAS,gBAAgB,UAAU;AAC/D,YAAM,oBAAoB,WAAW,gBAAgB,UAAU;AAC/D,eAAS,KAAK,OAAO;AAAA,IACvB,SAAS,OAAO;AACd,aAAO,KAAK,EAAE,IAAI,SAAS,OAAO,gBAAgB,KAAK,EAAE,CAAC;AAAA,IAC5D;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,OAAO;AAC5B;;;AC7CA;","names":["os","os","os","os","os","path","path","os","path","path","os","path","path","os","process","os","styles","chalk","styles","path","path","path","path","path","path","path","path","path","path","path","path"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli/commands/init.tsx","../src/cli/lib/permission-checker.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { Flags } from \"@oclif/core\";\nimport { render, Box, Text, useApp } from \"ink\";\nimport fs from \"fs\";\n\nimport { BaseCommand } from \"../base-command.js\";\nimport { Wizard, type WizardResultV2 } from \"../components/wizard/wizard.js\";\nimport { type SourceLoadResult } from \"../lib/loading/index.js\";\nimport {\n loadSource,\n loadAgentDefs,\n copyLocalSkills,\n ensureMarketplace,\n installPluginSkills,\n writeProjectConfig,\n compileAgents,\n getDashboardData,\n type DashboardData,\n} from \"../lib/operations/index.js\";\nimport {\n detectProjectInstallation,\n deriveInstallMode,\n resolveInstallPaths,\n buildAgentScopeMap,\n} from \"../lib/installation/index.js\";\nimport { checkPermissions } from \"../lib/permission-checker.js\";\nimport {\n ASCII_LOGO,\n CLAUDE_SRC_DIR,\n CLI_BIN_NAME,\n DEFAULT_BRANDING,\n GLOBAL_INSTALL_ROOT,\n} from \"../consts.js\";\nimport { SelectList, type SelectListItem } from \"../components/common/select-list.js\";\nimport {\n KEY_LABEL_ARROWS_VERT,\n KEY_LABEL_ENTER,\n KEY_LABEL_ESC,\n} from \"../components/wizard/hotkeys.js\";\nimport { getErrorMessage } from \"../utils/errors.js\";\nimport { EXIT_CODES } from \"../lib/exit-codes.js\";\nimport { getSkillById } from \"../lib/matrix/matrix-provider\";\nimport { type StartupMessage } from \"../utils/logger.js\";\nimport { SUCCESS_MESSAGES, STATUS_MESSAGES } from \"../utils/messages.js\";\nimport { ensureBlankGlobalConfig } from \"../lib/configuration/config-writer.js\";\n\n/** Clears the visible terminal area so the next render starts clean. */\nfunction clearTerminalOutput(): void {\n process.stdout.write(\"\\x1b[2J\\x1b[H\");\n}\n\nconst DASHBOARD_OPTIONS: SelectListItem<string>[] = [\n { label: \"Edit\", value: \"edit\" },\n { label: \"Compile\", value: \"compile\" },\n { label: \"Doctor\", value: \"doctor\" },\n { label: \"List\", value: \"list\" },\n];\n\ntype DashboardProps = {\n onSelect: (command: string) => void;\n onCancel: () => void;\n};\n\nconst Dashboard: React.FC<DashboardProps> = ({ onSelect, onCancel }) => {\n const { exit } = useApp();\n\n return (\n <Box flexDirection=\"column\">\n <Text bold>{DEFAULT_BRANDING.NAME}</Text>\n <Text> </Text>\n <SelectList\n items={DASHBOARD_OPTIONS}\n onSelect={(command) => {\n onSelect(command);\n exit();\n }}\n onCancel={() => {\n onCancel();\n exit();\n }}\n />\n <Text> </Text>\n <Text dimColor>\n {\" \"}\n {KEY_LABEL_ARROWS_VERT} Navigate {\" \"}\n {KEY_LABEL_ENTER} Confirm {\" \"}\n {KEY_LABEL_ESC} Exit\n </Text>\n </Box>\n );\n};\n\n// Re-export from operations so existing consumers can keep importing from init.\nexport { getDashboardData, type DashboardData } from \"../lib/operations/index.js\";\n\n/** Formats the dashboard summary as plain text lines (for non-interactive/test output). */\nexport function formatDashboardText(data: DashboardData): string {\n const modeLabel = data.mode === \"plugin\" ? \"Plugin\" : data.mode === \"mixed\" ? \"Mixed\" : \"Local\";\n const lines = [\n DEFAULT_BRANDING.NAME,\n \"\",\n ` Skills: ${data.skillCount} installed`,\n ` Agents: ${data.agentCount} compiled`,\n ` Mode: ${modeLabel}`,\n ];\n if (data.source) {\n lines.push(` Source: ${data.source}`);\n }\n lines.push(\"\");\n lines.push(` [Edit] [Compile] [Doctor] [List]`);\n return lines.join(\"\\n\");\n}\n\n/**\n * Shows the project dashboard and returns the selected command (or null if cancelled).\n * In non-interactive environments (no TTY), prints the summary text and returns null.\n */\nexport async function showDashboard(\n projectDir: string,\n log?: (message: string) => void,\n): Promise<string | null> {\n const data = await getDashboardData(projectDir);\n\n // Non-interactive: print text summary and exit (CI, piped, tests)\n if (!process.stdin.isTTY) {\n const output = log ?? console.log;\n output(formatDashboardText(data));\n return null;\n }\n\n let selectedCommand: string | null = null;\n\n const { waitUntilExit } = render(\n <Dashboard\n onSelect={(command) => {\n selectedCommand = command;\n }}\n onCancel={() => {\n selectedCommand = null;\n }}\n />,\n );\n\n await waitUntilExit();\n clearTerminalOutput();\n\n return selectedCommand;\n}\n\nexport default class Init extends BaseCommand {\n static summary = `Initialize ${DEFAULT_BRANDING.NAME} in this project`;\n static description =\n \"Interactive wizard to set up skills and agents. Supports Plugin Mode (native install) and Local Mode (copy to .claude/).\";\n\n static examples = [\n {\n description: \"Start the setup wizard\",\n command: \"<%= config.bin %> <%= command.id %>\",\n },\n {\n description: \"Initialize from a custom marketplace\",\n command: \"<%= config.bin %> <%= command.id %> --source github:org/marketplace\",\n },\n {\n description: \"Force refresh skills from remote\",\n command: \"<%= config.bin %> <%= command.id %> --refresh\",\n },\n ];\n\n static flags = {\n ...BaseCommand.baseFlags,\n refresh: Flags.boolean({\n description: \"Force refresh from remote source\",\n default: false,\n }),\n };\n\n async run(): Promise<void> {\n const { flags } = await this.parse(Init);\n const projectDir = process.cwd();\n\n // For \"already initialized\" check, only look at the target directory (no global fallback)\n const existingInstallation = await detectProjectInstallation(projectDir);\n\n if (existingInstallation) {\n const selectedCommand = await showDashboard(projectDir, (msg) => this.log(msg));\n if (selectedCommand) {\n await this.config.runCommand(selectedCommand);\n }\n return;\n }\n\n // Auto-create blank global config on first init from a project directory.\n // This ensures the project config can always import from global.\n // Resolve both paths through realpathSync — on macOS /var is a symlink to\n // /private/var, so os.homedir() and process.cwd() can return different\n // prefixes for the same directory.\n const isGlobalRoot = fs.realpathSync(projectDir) === fs.realpathSync(GLOBAL_INSTALL_ROOT);\n if (!isGlobalRoot) {\n const created = await ensureBlankGlobalConfig();\n if (created) {\n this.log(\"Created blank global config at ~/\" + CLAUDE_SRC_DIR);\n }\n }\n\n let sourceResult: SourceLoadResult;\n let startupMessages: StartupMessage[] = [];\n try {\n const loaded = await loadSource({\n sourceFlag: flags.source,\n projectDir,\n forceRefresh: flags.refresh,\n captureStartupMessages: true,\n });\n sourceResult = loaded.sourceResult;\n startupMessages = loaded.startupMessages;\n } catch (error) {\n this.error(getErrorMessage(error), {\n exit: EXIT_CODES.ERROR,\n });\n }\n\n let wizardResult: WizardResultV2 | null = null;\n\n const { waitUntilExit } = render(\n <Wizard\n version={this.config.version}\n logo={ASCII_LOGO}\n projectDir={projectDir}\n startupMessages={startupMessages}\n onComplete={(result) => {\n wizardResult = result;\n }}\n onCancel={() => {\n this.log(\"Setup cancelled\");\n }}\n />,\n );\n\n await waitUntilExit();\n\n // TypeScript can't track that onComplete callback mutates wizardResult before waitUntilExit resolves\n const result = wizardResult as WizardResultV2 | null;\n\n if (!result || result.cancelled) {\n this.exit(EXIT_CODES.CANCELLED);\n }\n\n if (result.skills.length === 0) {\n this.error(\"No skills selected\", { exit: EXIT_CODES.ERROR });\n }\n\n await this.handleInstallation(result, sourceResult, flags);\n }\n\n private async handleInstallation(\n result: WizardResultV2,\n sourceResult: SourceLoadResult,\n flags: { source?: string; refresh: boolean },\n ): Promise<void> {\n const projectDir = process.cwd();\n let installMode = deriveInstallMode(result.skills);\n\n const localSkills = result.skills.filter((s) => s.source === \"local\");\n const pluginSkills = result.skills.filter((s) => s.source !== \"local\");\n\n this.log(\"\\n\");\n this.log(`Selected ${result.skills.length} skills`);\n this.log(\n `Install mode: ${\n installMode === \"plugin\"\n ? \"Plugin (native install)\"\n : installMode === \"mixed\"\n ? `Mixed (${localSkills.length} local, ${pluginSkills.length} plugin)`\n : \"Local (copy to .claude/skills/)\"\n }`,\n );\n\n // Step 1: Copy local skills (for local or mixed modes)\n let copiedSkills: typeof localSkills = [];\n if (installMode === \"local\" || installMode === \"mixed\") {\n this.log(\"Copying skills to local directory...\");\n const copyResult = await copyLocalSkills(localSkills, projectDir, sourceResult);\n copiedSkills = localSkills;\n\n if (installMode === \"mixed\") {\n if (copyResult.projectCopied.length > 0 && copyResult.globalCopied.length > 0) {\n this.log(\n `Copied ${copyResult.totalCopied} local skills (${copyResult.projectCopied.length} project, ${copyResult.globalCopied.length} global)`,\n );\n } else if (copyResult.globalCopied.length > 0) {\n this.log(`Copied ${copyResult.globalCopied.length} local skills to ~/.claude/skills/`);\n } else {\n this.log(`Copied ${copyResult.projectCopied.length} local skills to .claude/skills/`);\n }\n } else {\n this.log(`Copied ${copyResult.totalCopied} skills to .claude/skills/\\n`);\n }\n }\n\n // Step 2: Marketplace + plugin installation (for plugin or mixed modes)\n let pluginModeSucceeded = false;\n if (installMode === \"plugin\" || installMode === \"mixed\") {\n const mpResult = await ensureMarketplace(sourceResult);\n\n if (!mpResult.marketplace) {\n this.warn(\"Could not resolve marketplace. Falling back to Local Mode...\");\n // Marketplace unavailable — copy all plugin-intended skills locally as fallback.\n // In \"mixed\" mode, localSkills were already copied in Step 1; only copy plugin-intended skills.\n // In \"plugin\" mode, no skills were copied yet; copy all skills.\n const fallbackSkills = installMode === \"mixed\" ? pluginSkills : result.skills;\n const fallbackCopyResult = await copyLocalSkills(fallbackSkills, projectDir, sourceResult);\n copiedSkills = [...copiedSkills, ...fallbackSkills];\n installMode = \"local\";\n this.log(`Copied ${fallbackCopyResult.totalCopied} skills to .claude/skills/\\n`);\n } else {\n if (mpResult.registered) {\n this.log(`Registering marketplace \"${mpResult.marketplace}\"...`);\n }\n\n this.log(\"Installing skill plugins...\");\n const pluginResult = await installPluginSkills(\n pluginSkills,\n mpResult.marketplace,\n projectDir,\n );\n\n for (const item of pluginResult.installed) {\n this.log(` Installed ${item.ref}`);\n }\n for (const item of pluginResult.failed) {\n this.warn(`Failed to install plugin ${item.id}: ${item.error}`);\n }\n\n this.log(`Installed ${pluginResult.installed.length} skill plugins\\n`);\n pluginModeSucceeded = true;\n }\n }\n\n // Step 3: Write config (all modes)\n this.log(\"Generating configuration...\");\n try {\n const configResult = await writeProjectConfig({\n wizardResult: result,\n sourceResult,\n projectDir,\n sourceFlag: flags.source,\n });\n\n if (configResult.wasMerged) {\n this.log(`Merged with existing config at ${configResult.existingConfigPath}`);\n }\n\n this.log(`Configuration saved (${configResult.config.agents.length} agents)\\n`);\n\n // Step 4: Compile agents\n this.log(STATUS_MESSAGES.COMPILING_AGENTS);\n const projectPaths = resolveInstallPaths(projectDir, \"project\");\n const agentDefs = await loadAgentDefs();\n const compileResult = await compileAgents({\n projectDir,\n sourcePath: agentDefs.sourcePath,\n installMode,\n agentScopeMap: buildAgentScopeMap(configResult.config),\n outputDir: projectPaths.agentsDir,\n });\n this.log(`Compiled ${compileResult.compiled.length} agents to .claude/agents/\\n`);\n\n // Step 5: Report success\n this.log(`${SUCCESS_MESSAGES.INIT_SUCCESS}\\n`);\n\n // Show copied skills summary for local/mixed modes (when not in plugin-only mode)\n const isLocalOutput =\n installMode === \"local\" || (installMode === \"mixed\" && !pluginModeSucceeded);\n if (isLocalOutput && copiedSkills.length > 0) {\n this.log(\"Skills copied to:\");\n this.log(` ${projectPaths.skillsDir}`);\n for (const skill of copiedSkills) {\n const displayName = getSkillById(skill.id).displayName;\n this.log(` ${displayName}/`);\n }\n this.log(\"\");\n }\n this.log(\"Agents compiled to:\");\n this.log(` ${projectPaths.agentsDir}`);\n for (const agentName of compileResult.compiled) {\n this.log(` ${agentName}.md`);\n }\n this.log(\"\");\n this.log(\"Configuration:\");\n this.log(` ${configResult.configPath}`);\n this.log(\"\");\n this.log(\"To customize agent-skill assignments:\");\n this.log(` 1. Edit .claude-src/config.ts`);\n this.log(` 2. Run '${CLI_BIN_NAME} compile' to regenerate agents`);\n this.log(\"\");\n\n const permissionWarning = await checkPermissions(projectDir);\n if (permissionWarning) {\n const { waitUntilExit } = render(permissionWarning);\n await waitUntilExit();\n }\n } catch (error) {\n this.handleError(error);\n }\n }\n}\n","import React from \"react\";\n\nimport { Text, Box } from \"ink\";\nimport path from \"path\";\n\nimport { CLAUDE_DIR, CLI_COLORS, MAX_CONFIG_FILE_SIZE } from \"../consts\";\nimport { fileExists, readFileSafe } from \"../utils/fs\";\nimport { warn } from \"../utils/logger\";\nimport { settingsFileSchema, warnUnknownFields } from \"./schemas\";\n\ntype PermissionConfig = {\n allow?: string[];\n deny?: string[];\n};\n\ntype SettingsFile = {\n permissions?: PermissionConfig;\n};\n\nexport async function checkPermissions(projectRoot: string): Promise<React.ReactElement | null> {\n const settingsPath = path.join(projectRoot, CLAUDE_DIR, \"settings.json\");\n const localSettingsPath = path.join(projectRoot, CLAUDE_DIR, \"settings.local.json\");\n\n let permissions: PermissionConfig | undefined;\n\n for (const filePath of [localSettingsPath, settingsPath]) {\n if (await fileExists(filePath)) {\n try {\n const content = await readFileSafe(filePath, MAX_CONFIG_FILE_SIZE);\n const raw = JSON.parse(content);\n if (typeof raw === \"object\" && raw !== null && !Array.isArray(raw)) {\n // Known Claude CLI settings.json fields (permissions is ours; the rest are managed by Claude CLI)\n const EXPECTED_SETTINGS_KEYS = [\n \"permissions\",\n \"enabledPlugins\",\n \"env\",\n \"allowedTools\",\n \"customInstructions\",\n \"defaultModel\",\n ] as const;\n warnUnknownFields(\n raw as Record<string, unknown>,\n EXPECTED_SETTINGS_KEYS,\n `settings file '${filePath}'`,\n );\n }\n const result = settingsFileSchema.safeParse(raw);\n const parsed: SettingsFile = result.success ? (result.data as SettingsFile) : {};\n if (parsed.permissions) {\n permissions = parsed.permissions;\n break;\n }\n } catch {\n warn(`Malformed settings file at '${filePath}' — skipping`);\n }\n }\n }\n\n if (!permissions) {\n return (\n <Box flexDirection=\"column\" borderStyle=\"round\" borderColor={CLI_COLORS.WARNING} padding={1}>\n <Text bold color={CLI_COLORS.WARNING}>\n Permission Notice\n </Text>\n <Text>No permissions configured in .claude/settings.json</Text>\n <Text>Agents will prompt for approval on each tool use.</Text>\n <Text> </Text>\n <Text>For autonomous operation, add to .claude/settings.json:</Text>\n <Text> </Text>\n <Text color=\"dim\">{\"{\"}</Text>\n <Text color=\"dim\">{' \"permissions\": {'}</Text>\n <Text color=\"dim\">{' \"allow\": ['}</Text>\n <Text color=\"dim\">{' \"Read(*)\",'}</Text>\n <Text color=\"dim\">{' \"Bash(git *)\",'}</Text>\n <Text color=\"dim\">{' \"Bash(bun *)\"'}</Text>\n <Text color=\"dim\">{\" ]\"}</Text>\n <Text color=\"dim\">{\" }\"}</Text>\n <Text color=\"dim\">{\"}\"}</Text>\n </Box>\n );\n }\n\n const hasRestrictiveBash = permissions.deny?.some(\n (rule) => rule === \"Bash(*)\" || rule === \"Bash\",\n );\n const hasNoAllows = !permissions.allow || permissions.allow.length === 0;\n\n if (hasRestrictiveBash || hasNoAllows) {\n return (\n <Box flexDirection=\"column\" borderStyle=\"round\" borderColor={CLI_COLORS.WARNING} padding={1}>\n <Text bold color={CLI_COLORS.WARNING}>\n Permission Warnings\n </Text>\n {hasRestrictiveBash && (\n <Text>\n ⚠ Bash is denied in permissions. Some agents require Bash for git, testing, and build\n commands.\n </Text>\n )}\n {hasNoAllows && (\n <Text>⚠ No allow rules configured. Agents will prompt for each tool use.</Text>\n )}\n </Box>\n );\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA,SAAS,aAAa;AACtB,SAAS,QAAQ,OAAAA,MAAK,QAAAC,OAAM,cAAc;AAC1C,OAAO,QAAQ;;;ACJf;AAEA,SAAS,MAAM,WAAW;AAC1B,OAAO,UAAU;AAyDX,SACE,KADF;AAzCN,eAAsB,iBAAiB,aAAyD;AAC9F,QAAM,eAAe,KAAK,KAAK,aAAa,YAAY,eAAe;AACvE,QAAM,oBAAoB,KAAK,KAAK,aA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AS,KAAK;AAAA,MAChC;AACA,WAAK,IAAI,EAAE;AACX,WAAK,IAAI,gBAAgB;AACzB,WAAK,IAAI,KAAK,aAAa,UAAU,EAAE;AACvC,WAAK,IAAI,EAAE;AACX,WAAK,IAAI,uCAAuC;AAChD,WAAK,IAAI,iCAAiC;AAC1C,WAAK,IAAI,aAAa,YAAY,gCAAgC;AAClE,WAAK,IAAI,EAAE;AAEX,YAAM,oBAAoB,MAAM,iBAAiB,UAAU;AAC3D,UAAI,mBAAmB;AACrB,cAAM,EAAE,cAAc,IAAI,OAAO,iBAAiB;AAClD,cAAM,cAAc;AAAA,MACtB;AAAA,IACF,SAAS,OAAO;AACd,WAAK,YAAY,KAAK;AAAA,IACxB;AAAA,EACF;AACF;","names":["Box","Text","jsx","jsxs","Box","Text","result"]}
@@ -1,166 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- IMPORT_DEFAULTS,
4
- computeFileHash,
5
- fetchFromSource,
6
- getCurrentDate
7
- } from "./chunk-TMTUTUEV.js";
8
- import {
9
- copy,
10
- ensureDir,
11
- fileExists,
12
- importedSkillMetadataSchema,
13
- listDirectories,
14
- readFile,
15
- warn,
16
- writeFile
17
- } from "./chunk-NUU3U43A.js";
18
- import {
19
- GITHUB_SOURCE,
20
- STANDARD_FILES,
21
- YAML_FORMATTING
22
- } from "./chunk-6PGL2XMY.js";
23
- import {
24
- init_esm_shims
25
- } from "./chunk-DHET7RCE.js";
26
-
27
- // src/cli/lib/operations/import-skill.ts
28
- init_esm_shims();
29
- import path from "path";
30
- import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
31
- function parseGitHubSource(source) {
32
- if (source.startsWith(GITHUB_SOURCE.HTTPS_PREFIX)) {
33
- const path2 = source.replace(GITHUB_SOURCE.HTTPS_PREFIX, "");
34
- return {
35
- gigetSource: `${GITHUB_SOURCE.GITHUB_PREFIX}${path2}`,
36
- displaySource: source
37
- };
38
- }
39
- if (source.startsWith(GITHUB_SOURCE.GITHUB_PREFIX) || source.startsWith(GITHUB_SOURCE.GH_PREFIX)) {
40
- const normalized = source.startsWith(GITHUB_SOURCE.GH_PREFIX) ? GITHUB_SOURCE.GITHUB_PREFIX + source.slice(GITHUB_SOURCE.GH_PREFIX.length) : source;
41
- return {
42
- gigetSource: normalized,
43
- displaySource: `${GITHUB_SOURCE.HTTPS_PREFIX}${normalized.replace(GITHUB_SOURCE.GITHUB_PREFIX, "")}`
44
- };
45
- }
46
- if (source.includes("/") && !source.includes(":")) {
47
- return {
48
- gigetSource: `${GITHUB_SOURCE.GITHUB_PREFIX}${source}`,
49
- displaySource: `${GITHUB_SOURCE.HTTPS_PREFIX}${source}`
50
- };
51
- }
52
- return {
53
- gigetSource: source,
54
- displaySource: source
55
- };
56
- }
57
- async function fetchSkillSource(options) {
58
- const result = await fetchFromSource(options.gigetSource, {
59
- forceRefresh: options.forceRefresh
60
- });
61
- return { path: result.path, fromCache: result.fromCache };
62
- }
63
- async function discoverValidSkills(skillsDir) {
64
- const skillDirs = await listDirectories(skillsDir);
65
- const validSkills = [];
66
- for (const skillDir of skillDirs) {
67
- const skillMdPath = path.join(skillsDir, skillDir, STANDARD_FILES.SKILL_MD);
68
- if (await fileExists(skillMdPath)) {
69
- validSkills.push(skillDir);
70
- }
71
- }
72
- return validSkills.sort();
73
- }
74
- async function importSkillFromSource(options) {
75
- const { sourcePath, destPath, skillName, displaySource } = options;
76
- const skillMdPath = path.join(sourcePath, STANDARD_FILES.SKILL_MD);
77
- if (!await fileExists(skillMdPath)) {
78
- throw new Error(
79
- `Missing required SKILL.md file at ${skillMdPath}
80
- Every skill must have a SKILL.md file containing the skill's prompt content.
81
- Create one with:
82
- echo "# ${skillName}" > ${path.join(sourcePath, STANDARD_FILES.SKILL_MD)}`
83
- );
84
- }
85
- const contentHash = await computeFileHash(skillMdPath);
86
- await ensureDir(path.dirname(destPath));
87
- await copy(sourcePath, destPath);
88
- await injectImportedForkedFromMetadata(destPath, skillName, displaySource, contentHash);
89
- }
90
- async function injectImportedForkedFromMetadata(destPath, skillName, source, contentHash) {
91
- const metadataYamlPath = path.join(destPath, STANDARD_FILES.METADATA_YAML);
92
- const metadataJsonPath = path.join(destPath, STANDARD_FILES.METADATA_JSON);
93
- const forkedFrom = {
94
- source,
95
- skillName,
96
- contentHash,
97
- date: getCurrentDate()
98
- };
99
- if (await fileExists(metadataYamlPath)) {
100
- const rawContent = await readFile(metadataYamlPath);
101
- const lines = rawContent.split("\n");
102
- let yamlContent2 = rawContent;
103
- let schemaComment = "";
104
- if (lines[0]?.startsWith("# yaml-language-server:")) {
105
- schemaComment = `${lines[0]}
106
- `;
107
- yamlContent2 = lines.slice(1).join("\n");
108
- }
109
- const raw = parseYaml(yamlContent2);
110
- const parseResult = importedSkillMetadataSchema.safeParse(raw);
111
- if (!parseResult.success) {
112
- warn(
113
- `Malformed metadata.yaml at ${metadataYamlPath} \u2014 existing fields may be lost
114
- Validation errors: ${parseResult.error.issues.map((i) => i.message).join(", ")}
115
- Expected fields: displayName (string), cliDescription (string), category (string)
116
- Validate your YAML syntax at https://yamllint.com`
117
- );
118
- }
119
- const metadata = parseResult.success ? parseResult.data : { forkedFrom: void 0 };
120
- metadata.forkedFrom = forkedFrom;
121
- const newYamlContent = stringifyYaml(metadata, {
122
- lineWidth: YAML_FORMATTING.LINE_WIDTH_NONE
123
- });
124
- await writeFile(metadataYamlPath, schemaComment + newYamlContent);
125
- return;
126
- }
127
- if (await fileExists(metadataJsonPath)) {
128
- const rawContent = await readFile(metadataJsonPath);
129
- let jsonParsed;
130
- try {
131
- jsonParsed = JSON.parse(rawContent);
132
- } catch {
133
- warn(
134
- `Malformed JSON in ${metadataJsonPath} \u2014 skipping metadata injection
135
- Common issues: trailing commas, unquoted keys, single quotes instead of double quotes
136
- Validate your JSON at https://jsonlint.com`
137
- );
138
- return;
139
- }
140
- const jsonResult = importedSkillMetadataSchema.safeParse(jsonParsed);
141
- const metadata = jsonResult.success ? jsonResult.data : { forkedFrom: void 0 };
142
- metadata.forkedFrom = forkedFrom;
143
- const yamlContent2 = stringifyYaml(metadata, { lineWidth: YAML_FORMATTING.LINE_WIDTH_NONE });
144
- await writeFile(metadataYamlPath, yamlContent2);
145
- return;
146
- }
147
- const minimalMetadata = {
148
- displayName: skillName.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" "),
149
- cliDescription: "Imported from third-party repository",
150
- category: IMPORT_DEFAULTS.CATEGORY,
151
- author: IMPORT_DEFAULTS.AUTHOR,
152
- forkedFrom
153
- };
154
- const yamlContent = stringifyYaml(minimalMetadata, {
155
- lineWidth: YAML_FORMATTING.LINE_WIDTH_NONE
156
- });
157
- await writeFile(metadataYamlPath, yamlContent);
158
- }
159
-
160
- export {
161
- parseGitHubSource,
162
- fetchSkillSource,
163
- discoverValidSkills,
164
- importSkillFromSource
165
- };
166
- //# sourceMappingURL=chunk-O5ZWS26C.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli/lib/operations/import-skill.ts"],"sourcesContent":["import path from \"path\";\nimport { parse as parseYaml, stringify as stringifyYaml } from \"yaml\";\nimport { fetchFromSource } from \"../loading/index.js\";\nimport { importedSkillMetadataSchema } from \"../schemas.js\";\nimport { getCurrentDate, computeFileHash } from \"../versioning.js\";\nimport {\n copy,\n fileExists,\n listDirectories,\n readFile,\n writeFile,\n ensureDir,\n} from \"../../utils/fs.js\";\nimport { warn } from \"../../utils/logger.js\";\nimport { GITHUB_SOURCE, STANDARD_FILES, YAML_FORMATTING } from \"../../consts.js\";\nimport { IMPORT_DEFAULTS } from \"../metadata-keys.js\";\n\n/**\n * Metadata for tracking third-party imports. Different from ForkedFromMetadata\n * in skill-metadata.ts which tracks internal fork lineage (uses skillId\n * instead of source/skillName).\n */\nexport type ImportedForkedFromMetadata = {\n source: string;\n skillName: string;\n contentHash: string;\n date: string;\n};\n\ntype SkillMetadata = {\n forkedFrom?: ImportedForkedFromMetadata;\n [key: string]: unknown;\n};\n\nexport type ParsedGitHubSource = {\n gigetSource: string;\n displaySource: string;\n};\n\nexport type FetchSourceOptions = {\n gigetSource: string;\n forceRefresh?: boolean;\n};\n\nexport type FetchedSource = {\n path: string;\n fromCache: boolean;\n};\n\nexport type ImportSkillOptions = {\n sourcePath: string;\n destPath: string;\n skillName: string;\n displaySource: string;\n};\n\nexport type ImportSkillResult = {\n imported: string[];\n skipped: string[];\n errors: Array<{ skillName: string; error: string }>;\n};\n\n/**\n * Parses various GitHub URL formats into a normalized giget source string\n * and a human-readable display URL.\n *\n * Supports: `https://github.com/owner/repo`, `github:owner/repo`,\n * `gh:owner/repo`, and bare `owner/repo` formats.\n */\nexport function parseGitHubSource(source: string): ParsedGitHubSource {\n if (source.startsWith(GITHUB_SOURCE.HTTPS_PREFIX)) {\n const path = source.replace(GITHUB_SOURCE.HTTPS_PREFIX, \"\");\n return {\n gigetSource: `${GITHUB_SOURCE.GITHUB_PREFIX}${path}`,\n displaySource: source,\n };\n }\n\n if (\n source.startsWith(GITHUB_SOURCE.GITHUB_PREFIX) ||\n source.startsWith(GITHUB_SOURCE.GH_PREFIX)\n ) {\n const normalized = source.startsWith(GITHUB_SOURCE.GH_PREFIX)\n ? GITHUB_SOURCE.GITHUB_PREFIX + source.slice(GITHUB_SOURCE.GH_PREFIX.length)\n : source;\n return {\n gigetSource: normalized,\n displaySource: `${GITHUB_SOURCE.HTTPS_PREFIX}${normalized.replace(GITHUB_SOURCE.GITHUB_PREFIX, \"\")}`,\n };\n }\n\n if (source.includes(\"/\") && !source.includes(\":\")) {\n return {\n gigetSource: `${GITHUB_SOURCE.GITHUB_PREFIX}${source}`,\n displaySource: `${GITHUB_SOURCE.HTTPS_PREFIX}${source}`,\n };\n }\n\n return {\n gigetSource: source,\n displaySource: source,\n };\n}\n\n/**\n * Fetches a source repository using giget. Wraps `fetchFromSource` from the\n * loading layer.\n */\nexport async function fetchSkillSource(options: FetchSourceOptions): Promise<FetchedSource> {\n const result = await fetchFromSource(options.gigetSource, {\n forceRefresh: options.forceRefresh,\n });\n return { path: result.path, fromCache: result.fromCache };\n}\n\n/**\n * Discovers valid skill directories within a source path by checking\n * for the presence of SKILL.md files.\n *\n * @returns Sorted list of directory names that contain a SKILL.md file.\n */\nexport async function discoverValidSkills(skillsDir: string): Promise<string[]> {\n const skillDirs = await listDirectories(skillsDir);\n const validSkills: string[] = [];\n\n for (const skillDir of skillDirs) {\n const skillMdPath = path.join(skillsDir, skillDir, STANDARD_FILES.SKILL_MD);\n if (await fileExists(skillMdPath)) {\n validSkills.push(skillDir);\n }\n }\n\n return validSkills.sort();\n}\n\n/**\n * Imports a single skill from a source directory into the destination.\n *\n * Validates that the source skill has a SKILL.md file, copies the directory,\n * and injects `forkedFrom` metadata into the destination's metadata.yaml.\n *\n * @throws {Error} If the source skill is missing a SKILL.md file.\n */\nexport async function importSkillFromSource(options: ImportSkillOptions): Promise<void> {\n const { sourcePath, destPath, skillName, displaySource } = options;\n const skillMdPath = path.join(sourcePath, STANDARD_FILES.SKILL_MD);\n\n if (!(await fileExists(skillMdPath))) {\n throw new Error(\n `Missing required SKILL.md file at ${skillMdPath}\\n` +\n `Every skill must have a SKILL.md file containing the skill's prompt content.\\n` +\n `Create one with:\\n` +\n ` echo \"# ${skillName}\" > ${path.join(sourcePath, STANDARD_FILES.SKILL_MD)}`,\n );\n }\n\n const contentHash = await computeFileHash(skillMdPath);\n\n await ensureDir(path.dirname(destPath));\n await copy(sourcePath, destPath);\n\n await injectImportedForkedFromMetadata(destPath, skillName, displaySource, contentHash);\n}\n\n/**\n * Injects `forkedFrom` metadata into a third-party imported skill's metadata.yaml.\n *\n * Handles three cases:\n * 1. Existing metadata.yaml — preserves fields, adds/overwrites forkedFrom\n * 2. Existing metadata.json — converts to YAML, adds forkedFrom\n * 3. No metadata file — creates minimal metadata.yaml with forkedFrom\n *\n * @remarks\n * Different from `injectForkedFromMetadata` in `skill-metadata.ts` which tracks\n * internal marketplace fork lineage using `skillId`. This function tracks\n * third-party imports using `source` + `skillName`.\n */\nasync function injectImportedForkedFromMetadata(\n destPath: string,\n skillName: string,\n source: string,\n contentHash: string,\n): Promise<void> {\n const metadataYamlPath = path.join(destPath, STANDARD_FILES.METADATA_YAML);\n const metadataJsonPath = path.join(destPath, STANDARD_FILES.METADATA_JSON);\n\n const forkedFrom: ImportedForkedFromMetadata = {\n source,\n skillName,\n contentHash,\n date: getCurrentDate(),\n };\n\n if (await fileExists(metadataYamlPath)) {\n const rawContent = await readFile(metadataYamlPath);\n const lines = rawContent.split(\"\\n\");\n let yamlContent = rawContent;\n let schemaComment = \"\";\n\n if (lines[0]?.startsWith(\"# yaml-language-server:\")) {\n schemaComment = `${lines[0]}\\n`;\n yamlContent = lines.slice(1).join(\"\\n\");\n }\n\n const raw = parseYaml(yamlContent);\n const parseResult = importedSkillMetadataSchema.safeParse(raw);\n if (!parseResult.success) {\n warn(\n `Malformed metadata.yaml at ${metadataYamlPath} — existing fields may be lost\\n` +\n ` Validation errors: ${parseResult.error.issues.map((i) => i.message).join(\", \")}\\n` +\n ` Expected fields: displayName (string), cliDescription (string), category (string)\\n` +\n ` Validate your YAML syntax at https://yamllint.com`,\n );\n }\n const metadata = parseResult.success\n ? (parseResult.data as SkillMetadata)\n : { forkedFrom: undefined };\n metadata.forkedFrom = forkedFrom;\n\n const newYamlContent = stringifyYaml(metadata, {\n lineWidth: YAML_FORMATTING.LINE_WIDTH_NONE,\n });\n await writeFile(metadataYamlPath, schemaComment + newYamlContent);\n return;\n }\n\n if (await fileExists(metadataJsonPath)) {\n const rawContent = await readFile(metadataJsonPath);\n let jsonParsed: unknown;\n try {\n jsonParsed = JSON.parse(rawContent);\n } catch {\n warn(\n `Malformed JSON in ${metadataJsonPath} — skipping metadata injection\\n` +\n ` Common issues: trailing commas, unquoted keys, single quotes instead of double quotes\\n` +\n ` Validate your JSON at https://jsonlint.com`,\n );\n return;\n }\n const jsonResult = importedSkillMetadataSchema.safeParse(jsonParsed);\n const metadata = jsonResult.success\n ? (jsonResult.data as SkillMetadata)\n : { forkedFrom: undefined };\n metadata.forkedFrom = forkedFrom;\n\n const yamlContent = stringifyYaml(metadata, { lineWidth: YAML_FORMATTING.LINE_WIDTH_NONE });\n await writeFile(metadataYamlPath, yamlContent);\n return;\n }\n\n const minimalMetadata: SkillMetadata = {\n displayName: skillName\n .split(\"-\")\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(\" \"),\n cliDescription: \"Imported from third-party repository\",\n category: IMPORT_DEFAULTS.CATEGORY,\n author: IMPORT_DEFAULTS.AUTHOR,\n forkedFrom,\n };\n\n const yamlContent = stringifyYaml(minimalMetadata, {\n lineWidth: YAML_FORMATTING.LINE_WIDTH_NONE,\n });\n await writeFile(metadataYamlPath, yamlContent);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,OAAO,UAAU;AACjB,SAAS,SAAS,WAAW,aAAa,qBAAqB;AAoExD,SAAS,kBAAkB,QAAoC;AACpE,MAAI,OAAO,WAAW,cAAc,YAAY,GAAG;AACjD,UAAMA,QAAO,OAAO,QAAQ,cAAc,cAAc,EAAE;AAC1D,WAAO;AAAA,MACL,aAAa,GAAG,cAAc,aAAa,GAAGA,KAAI;AAAA,MAClD,eAAe;AAAA,IACjB;AAAA,EACF;AAEA,MACE,OAAO,WAAW,cAAc,aAAa,KAC7C,OAAO,WAAW,cAAc,SAAS,GACzC;AACA,UAAM,aAAa,OAAO,WAAW,cAAc,SAAS,IACxD,cAAc,gBAAgB,OAAO,MAAM,cAAc,UAAU,MAAM,IACzE;AACJ,WAAO;AAAA,MACL,aAAa;AAAA,MACb,eAAe,GAAG,cAAc,YAAY,GAAG,WAAW,QAAQ,cAAc,eAAe,EAAE,CAAC;AAAA,IACpG;AAAA,EACF;AAEA,MAAI,OAAO,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,GAAG;AACjD,WAAO;AAAA,MACL,aAAa,GAAG,cAAc,aAAa,GAAG,MAAM;AAAA,MACpD,eAAe,GAAG,cAAc,YAAY,GAAG,MAAM;AAAA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