From 16d00a8ec9a2e225ab9014f2444fb12c78af2fd8 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare <48523873+rohitg00@users.noreply.github.com> Date: Fri, 10 Apr 2026 21:40:45 +0100 Subject: [PATCH] fix: address review findings in cloneRepo and scanner - spawnGit: set stdout to 'ignore' instead of 'pipe' to prevent buffer deadlock (git clone writes to stderr, not stdout) - tryPartialClone: emit fallback message via onProgress instead of silently swallowing the error - scanner: preserve fence markers so PI011 delimiter injection is still detected, only strip inner code block content - scanner: guard against unclosed frontmatter by looking ahead for closing --- before entering frontmatter mode --- packages/core/src/providers/base.ts | 5 +++-- packages/core/src/scanner/analyzers/static.ts | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/core/src/providers/base.ts b/packages/core/src/providers/base.ts index 5586c565..f14c492d 100644 --- a/packages/core/src/providers/base.ts +++ b/packages/core/src/providers/base.ts @@ -54,7 +54,7 @@ function spawnGit(args: string[]): Promise; function spawnGit(args: string[], onProgress: (msg: string) => void): Promise; function spawnGit(args: string[], onProgress?: (msg: string) => void): Promise { return new Promise((resolve, reject) => { - const proc = spawn('git', args, { stdio: ['pipe', 'pipe', 'pipe'] }); + const proc = spawn('git', args, { stdio: ['pipe', 'ignore', 'pipe'] }); let stderr = ''; proc.stderr?.on('data', (data: Buffer) => { @@ -118,7 +118,8 @@ export async function cloneRepo( await spawnGit(['-C', tempDir, 'checkout'], options.onProgress ?? (() => {})); return; - } catch { + } catch (err) { + options.onProgress?.(`Partial clone unsupported, falling back to full clone`); if (existsSync(tempDir)) { rmSync(tempDir, { recursive: true, force: true }); } diff --git a/packages/core/src/scanner/analyzers/static.ts b/packages/core/src/scanner/analyzers/static.ts index 55c17814..6bceb7b4 100644 --- a/packages/core/src/scanner/analyzers/static.ts +++ b/packages/core/src/scanner/analyzers/static.ts @@ -64,25 +64,27 @@ function stripMarkdownCodeAndFrontmatter(content: string): string { let inFrontmatter = false; let frontmatterDone = false; + if (lines.length > 0 && /^---\s*$/.test(lines[0].trim())) { + const hasCloser = lines.slice(1).some((l) => /^---\s*$/.test(l.trim())); + if (hasCloser) { + inFrontmatter = true; + } + } + return lines.map((line, i) => { const trimmed = line.trim(); - if (!frontmatterDone && /^---\s*$/.test(trimmed)) { - if (!inFrontmatter && i < 2) { - inFrontmatter = true; - return ''; - } - if (inFrontmatter) { + if (inFrontmatter && !frontmatterDone) { + if (i > 0 && /^---\s*$/.test(trimmed)) { inFrontmatter = false; frontmatterDone = true; - return ''; } + return ''; } - if (inFrontmatter) return ''; if (/^(`{3,}|~{3,})/.test(trimmed)) { inCodeBlock = !inCodeBlock; - return ''; + return line; } if (inCodeBlock) return '';