mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-18 18:04:26 +00:00
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:
@@ -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 });
|
||||
}
|
||||
|
||||
@@ -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 '';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user