autosnippet
Version:
Extract code patterns into a knowledge base for AI coding assistants
48 lines (47 loc) • 1.65 kB
JavaScript
/**
* Shared helpers for recipe relevance audit.
*
* Previously duplicated in:
* - rescan-internal.ts (Step 4)
* - rescan-external.ts (Step 4)
*
* @module bootstrap/shared/audit-helpers
*/
// ── AST entity extraction ────────────────────────────────
/**
* Extract code entities from AST project summary for audit evidence matching.
*/
export function extractCodeEntities(astProjectSummary) {
const entities = [];
if (!astProjectSummary) {
return entities;
}
for (const cls of astProjectSummary.classes || []) {
entities.push({ name: cls.name, kind: 'class', file: cls.relativePath || cls.file });
}
for (const proto of astProjectSummary.protocols || []) {
entities.push({ name: proto.name, kind: 'protocol', file: proto.relativePath || proto.file });
}
if (astProjectSummary.categories) {
for (const cat of astProjectSummary.categories) {
entities.push({ name: cat.name || '', kind: 'category', file: cat.relativePath || cat.file });
}
}
return entities;
}
// ── Dependency edge extraction ───────────────────────────
/**
* Extract dependency edges from the dependency graph for audit evidence matching.
*/
export function extractDependencyEdges(depGraphData) {
const edges = [];
if (!depGraphData?.edges) {
return edges;
}
for (const edge of depGraphData.edges) {
if (edge.from && edge.to) {
edges.push({ from: edge.from, to: edge.to });
}
}
return edges;
}