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
This commit is contained in:
Rohit Ghumare
2026-04-10 21:40:45 +01:00
parent 3457fbc011
commit 16d00a8ec9
2 changed files with 14 additions and 11 deletions
+3 -2
View File
@@ -54,7 +54,7 @@ function spawnGit(args: string[]): Promise<void>;
function spawnGit(args: string[], onProgress: (msg: string) => void): Promise<void>;
function spawnGit(args: string[], onProgress?: (msg: string) => void): Promise<void> {
return new Promise<void>((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 });
}
+11 -9
View File
@@ -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 '';