diff --git a/packages/cli/src/commands/install.ts b/packages/cli/src/commands/install.ts index 2b96e90f..595c6fdc 100644 --- a/packages/cli/src/commands/install.ts +++ b/packages/cli/src/commands/install.ts @@ -472,7 +472,15 @@ export class InstallCommand extends Command { mkdirSync(installDir, { recursive: true }); } - const isStandaloneFile = statSync(sourcePath).isFile(); + let isStandaloneFile: boolean; + try { + isStandaloneFile = statSync(sourcePath).isFile(); + } catch { + if (!this.quiet) { + warn(`Skipping ${skillName} for ${adapter.name} (source not accessible)`); + } + continue; + } const targetPath = isStandaloneFile ? join(installDir, skillName.endsWith(".md") ? skillName : `${skillName}.md`) : join(installDir, skillName); diff --git a/packages/cli/src/commands/remove.ts b/packages/cli/src/commands/remove.ts index ba19133f..8e061dd1 100644 --- a/packages/cli/src/commands/remove.ts +++ b/packages/cli/src/commands/remove.ts @@ -48,7 +48,7 @@ export class RemoveCommand extends Command { if (this.source) { skillsToRemove = allSkills.filter((s) => { const meta = loadMetadata(s.path); - return meta && meta.source.includes(this.source!); + return meta?.source?.includes(this.source!) ?? false; }).map((s) => ({ name: s.name, path: s.path })); if (skillsToRemove.length === 0) { warn(`No skills found from source: ${this.source}`); diff --git a/packages/core/src/providers/base.ts b/packages/core/src/providers/base.ts index 6b62e58c..b4dcfe29 100644 --- a/packages/core/src/providers/base.ts +++ b/packages/core/src/providers/base.ts @@ -104,27 +104,34 @@ export async function cloneRepo( } if (partialCloneOk) { - execFileSync('git', ['-C', tempDir, 'sparse-checkout', 'init', '--cone'], { - stdio: ['pipe', 'pipe', 'pipe'], - }); + try { + execFileSync('git', ['-C', tempDir, 'sparse-checkout', 'init', '--cone'], { + stdio: ['pipe', 'pipe', 'pipe'], + }); - const sparsePaths = [...SKILL_DISCOVERY_PATHS]; - if (options.subpath) { - sparsePaths.push(options.subpath); - for (const dp of SKILL_DISCOVERY_PATHS) { - sparsePaths.push(`${options.subpath}/${dp}`); + const sparsePaths = [...SKILL_DISCOVERY_PATHS]; + if (options.subpath) { + sparsePaths.push(options.subpath); + for (const dp of SKILL_DISCOVERY_PATHS) { + sparsePaths.push(`${options.subpath}/${dp}`); + } + } + execFileSync( + 'git', + ['-C', tempDir, 'sparse-checkout', 'set', '--', ...sparsePaths], + { stdio: ['pipe', 'pipe', 'pipe'] }, + ); + + options.onProgress?.('Checking out files'); + await spawnGit(['-C', tempDir, 'checkout'], options.onProgress); + + return; + } catch { + options.onProgress?.('Sparse checkout failed, falling back to full clone'); + if (existsSync(tempDir)) { + rmSync(tempDir, { recursive: true, force: true }); } } - execFileSync( - 'git', - ['-C', tempDir, 'sparse-checkout', 'set', '--', ...sparsePaths], - { stdio: ['pipe', 'pipe', 'pipe'] }, - ); - - options.onProgress?.('Checking out files'); - await spawnGit(['-C', tempDir, 'checkout'], options.onProgress); - - return; } } diff --git a/packages/core/src/scanner/analyzers/static.ts b/packages/core/src/scanner/analyzers/static.ts index 6bceb7b4..2e02e666 100644 --- a/packages/core/src/scanner/analyzers/static.ts +++ b/packages/core/src/scanner/analyzers/static.ts @@ -60,7 +60,7 @@ function ruleMatchesFileType(rule: SecurityRule, fileType: string | undefined): function stripMarkdownCodeAndFrontmatter(content: string): string { const lines = content.split('\n'); - let inCodeBlock = false; + let fenceDelimiter: string | null = null; let inFrontmatter = false; let frontmatterDone = false; @@ -82,11 +82,18 @@ function stripMarkdownCodeAndFrontmatter(content: string): string { return ''; } - if (/^(`{3,}|~{3,})/.test(trimmed)) { - inCodeBlock = !inCodeBlock; - return line; + const fenceMatch = trimmed.match(/^(`{3,}|~{3,})/); + if (fenceMatch) { + const char = fenceMatch[1][0]; + if (fenceDelimiter === null) { + fenceDelimiter = char; + return line; + } else if (char === fenceDelimiter) { + fenceDelimiter = null; + return line; + } } - if (inCodeBlock) return ''; + if (fenceDelimiter !== null) return ''; return line; }).join('\n'); diff --git a/packages/core/src/skills.ts b/packages/core/src/skills.ts index de5c9bab..5724c7ec 100644 --- a/packages/core/src/skills.ts +++ b/packages/core/src/skills.ts @@ -314,11 +314,12 @@ export function findSkill(name: string, searchDirs: string[]): Skill | null { for (const dir of searchDirs) { if (!existsSync(dir)) continue; - const location: SkillLocation = dir.includes(process.cwd()) ? 'project' : 'global'; + const location: SkillLocation = isPathInside(dir, process.cwd()) ? 'project' : 'global'; const skillPath = join(dir, name); if (existsSync(skillPath)) { - return parseSkill(skillPath, location); + const skill = parseSkill(skillPath, location); + if (skill) return skill; } const mdPath = join(dir, name.endsWith('.md') ? name : `${name}.md`); @@ -337,7 +338,7 @@ export function findAllSkills(searchDirs: string[]): Skill[] { for (const dir of searchDirs) { if (!existsSync(dir)) continue; - const location: SkillLocation = dir.includes(process.cwd()) ? 'project' : 'global'; + const location: SkillLocation = isPathInside(dir, process.cwd()) ? 'project' : 'global'; const discovered = discoverSkills(dir); for (const skill of discovered) {