scai
Version:
> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.
47 lines (46 loc) • 1.78 kB
JavaScript
import { logInputOutput } from "../utils/promptLogHelper.js";
export const structuralAnalysisStep = {
name: "structuralAnalysis",
description: "Derive structural characteristics from workingFiles using existing metadata only. " +
"Produces a durable, machine-usable summary of file shape and relationships.",
groups: ["analysis"],
run: async (input) => {
const ctx = input.context;
if (!ctx) {
throw new Error("[structuralAnalysis] StructuredContext is required but was not provided.");
}
const workingFiles = ctx.workingFiles;
if (!Array.isArray(workingFiles) || workingFiles.length === 0) {
const output = {
query: input.query,
data: {
notes: "No workingFiles present; structural analysis skipped."
}
};
logInputOutput("structuralAnalysis", "output", output.data);
return output;
}
const files = workingFiles.map((file) => ({
path: file.path,
imports: file.imports ?? [],
exports: file.exports ?? [],
functions: file.functions?.length ?? 0,
classes: file.classes?.length ?? 0,
}));
// 🧠 Persist durable structural understanding
ctx.analysis ?? (ctx.analysis = {});
ctx.analysis.structure = {
files,
};
const output = {
query: input.query,
data: {
fileCount: files.length,
files,
notes: "Structural characteristics derived from loaded workingFiles.",
}
};
logInputOutput("structuralAnalysis", "output", output.data);
return output;
}
};