zignet
Version:
MCP server for Zig — AI-powered code analysis, validation, and documentation with fine-tuned LLM
95 lines (93 loc) • 2.76 kB
JavaScript
const require_config = require('./config-C2ufArDU.cjs');
const require_executor = require('./executor-ON2Rt60w.cjs');
//#region src/tools/analyze.ts
/**
* Analyze Zig code using official Zig compiler
*/
async function analyzeZig(input) {
const { code, zig_version = require_config.DEFAULT_ZIG_VERSION } = input;
if (!code || code.trim().length === 0) return {
success: true,
errors: [],
warnings: [],
summary: "✅ Analysis Result: Empty code (valid)",
zig_version
};
try {
const result = await Promise.resolve(require_executor.zigAstCheck(code, zig_version));
const errors = result.diagnostics.filter((d) => d.severity === "error").map((d) => ({
message: d.message,
line: d.line,
column: d.column,
severity: "error"
}));
const warnings = result.diagnostics.filter((d) => d.severity === "warning").map((d) => ({
message: d.message,
line: d.line,
column: d.column
}));
const summary = result.success ? `✅ Analysis Result (Zig ${zig_version}):
- Syntax: Valid
- Type Check: PASS
- Warnings: ${warnings.length}
- Errors: 0` : `❌ Analysis Result (Zig ${zig_version}):
- Syntax: ${errors.some((e) => e.message.includes("expected")) ? "Invalid" : "Valid"}
- Type Check: FAIL
- Warnings: ${warnings.length}
- Errors: ${errors.length}`;
return {
success: result.success,
errors,
warnings,
summary,
zig_version
};
} catch (error) {
return {
success: false,
errors: [{
message: `Failed to run Zig compiler: ${error instanceof Error ? error.message : String(error)}`,
severity: "error"
}],
warnings: [],
summary: `❌ Analysis failed: Could not execute Zig ${zig_version}`,
zig_version
};
}
}
/**
* Format analysis result for MCP response
*/
function formatAnalyzeResult(result) {
let output = result.summary + "\n\n";
if (result.errors.length > 0) {
output += "🔴 Errors:\n";
result.errors.forEach((error, index) => {
const location = error.line ? ` (line ${error.line}${error.column ? `, col ${error.column}` : ""})` : "";
output += `${index + 1}. ${error.message}${location}\n`;
});
output += "\n";
}
if (result.warnings.length > 0) {
output += "⚠️ Warnings:\n";
result.warnings.forEach((warning, index) => {
const location = warning.line ? ` (line ${warning.line}${warning.column ? `, col ${warning.column}` : ""})` : "";
output += `${index + 1}. ${warning.message}${location}\n`;
});
}
return output.trim();
}
//#endregion
Object.defineProperty(exports, 'analyzeZig', {
enumerable: true,
get: function () {
return analyzeZig;
}
});
Object.defineProperty(exports, 'formatAnalyzeResult', {
enumerable: true,
get: function () {
return formatAnalyzeResult;
}
});
//# sourceMappingURL=analyze-CKCU4PaJ.cjs.map