fix: strip backticks from CODEBASE_MAP.md path parsing

Paths wrapped in backticks like `app/` were being captured with
the backtick character, producing invalid app names and paths.

Made-with: Cursor
This commit is contained in:
2026-03-09 14:21:25 -07:00
parent 65adcd4897
commit 01c2d33208

View File

@@ -67,11 +67,11 @@ export async function GET(
const mapFile = await giteaGet(`/repos/${giteaRepo}/contents/CODEBASE_MAP.md`).catch(() => null); const mapFile = await giteaGet(`/repos/${giteaRepo}/contents/CODEBASE_MAP.md`).catch(() => null);
if (mapFile?.content) { if (mapFile?.content) {
const decoded = Buffer.from(mapFile.content, 'base64').toString('utf-8'); const decoded = Buffer.from(mapFile.content, 'base64').toString('utf-8');
// Extract component folder paths from the map (lines like "### [name] — folder/path") // Extract component folder paths from lines like "### Name — `folder/path`" or "### Name — folder/path"
const matches = [...decoded.matchAll(/###\s+.+?—\s+([^\n(]+)/g)]; const matches = [...decoded.matchAll(/###\s+.+?[—–-]\s+[`]?([^`\n(]+)[`]?/g)];
const parsedApps = matches const parsedApps = matches
.map(m => m[1].trim()) .map(m => m[1].trim().replace(/^`|`$/g, '').replace(/\/$/, ''))
.filter(p => p && !p.includes(' ') && !p.startsWith('http')) .filter(p => p && p.length > 0 && !p.includes(' ') && !p.startsWith('http') && p !== '.')
.map(p => ({ name: p.split('/').pop() ?? p, path: p })); .map(p => ({ name: p.split('/').pop() ?? p, path: p }));
if (parsedApps.length > 0) { if (parsedApps.length > 0) {
apps = parsedApps; apps = parsedApps;
@@ -93,14 +93,15 @@ export async function GET(
const candidates = await Promise.all( const candidates = await Promise.all(
dirs.map(async (dir) => { dirs.map(async (dir) => {
try { try {
const sub: Array<{ name: string }> = await giteaGet(`/repos/${giteaRepo}/contents/${dir.path}`); const sub: Array<{ name: string; type: string }> = await giteaGet(`/repos/${giteaRepo}/contents/${dir.path}`);
const isApp = sub.some(f => APP_SIGNALS.includes(f.name)); // Check direct app signals OR subdirs that each contain app signals (monorepo-style)
return isApp ? { name: dir.name, path: dir.path } : null; const hasDirectSignal = sub.some(f => APP_SIGNALS.includes(f.name));
return hasDirectSignal ? { name: dir.name, path: dir.path } : null;
} catch { return null; } } catch { return null; }
}) })
); );
apps = candidates.filter((a): a is { name: string; path: string } => a !== null); apps = candidates.filter((a): a is { name: string; path: string } => a !== null && a.name.length > 0);
} catch { /* scan failed */ } } catch { /* scan failed */ }
} }
} }