Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 71 additions & 34 deletions vibe-check-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_AI_API_KEY });

// Constants for scoring

async function fileOrDirExists(filePath) {
export async function fileOrDirExists(filePath) {
try {
await fsPromises.stat(filePath);
return true;
Expand All @@ -25,7 +25,7 @@ const SCORES = {
EFFICIENCY: 10,
};

function getModifiedFiles() {
export function getModifiedFiles() {
try {
// In CI (daily run), check files modified in the last 24 hours.
// We filter for non-empty lines that end in .md and are in frontend/ or backend/
Expand All @@ -43,7 +43,7 @@ function getModifiedFiles() {
}
}

async function syncBenchmarks(tech, mdContent, retries = 5, delay = 10000) {
export async function syncBenchmarks(tech, mdContent, retries = 5, delay = 10000) {
try {
const prompt = `Based on the following documentation:\n\n${mdContent}\n\n1. Generate a "Golden Prompt" (a comprehensive instruction for generating a typical module using this technology) in JSON format: {"golden_prompt": "...", "tech": "${tech}"}\n2. Generate a JSON Schema for TS-Morph AST validation rules enforcing DDD/FSD layers and strict typing for this technology. The generated JSON schema must explicitly follow a nested structure compatible with \`analyzeAST\`. Format: {"$schema": "...", "type": "object", "properties": {"forbidden_types": {"contains": {"enum": ["any"]}}}}.\n\nRespond strictly with ONLY a JSON array containing these two objects in order. No markdown wrappers.`;
const response = await ai.models.generateContent({
Expand Down Expand Up @@ -85,7 +85,7 @@ async function syncBenchmarks(tech, mdContent, retries = 5, delay = 10000) {
}
}

async function simulateAIGeneration(goldenPrompt, tech, mdContent, retries = 5, delay = 10000) {
export async function simulateAIGeneration(goldenPrompt, tech, mdContent, retries = 5, delay = 10000) {
try {
const prompt = `${goldenPrompt}\n\nConstraints and instructions from the following documentation:\n\n${mdContent}\n\nGenerate ONLY raw code. No markdown formatting, no explanations.`;
const response = await ai.models.generateContent({
Expand All @@ -110,7 +110,7 @@ async function simulateAIGeneration(goldenPrompt, tech, mdContent, retries = 5,
}
}

function analyzeAST(sourceFile, tech) {
export function analyzeAST(sourceFile, tech) {
let score = {
arch: SCORES.ARCH,
type: SCORES.TYPE,
Expand Down Expand Up @@ -222,7 +222,7 @@ function analyzeAST(sourceFile, tech) {
return { total, breakdown: score };
}

async function runVibeCheck() {
export async function runVibeCheck() {
console.log('Running Vibe-Check Runner...');

const modifiedFiles = getModifiedFiles();
Expand All @@ -241,12 +241,48 @@ async function runVibeCheck() {
console.warn('Failed to configure git user. If running locally, this is expected.');
}

// Group files by tech
const filesByTech = {};
for (const file of modifiedFiles) {
let tech = '';
if (file.includes('/angular/')) tech = 'angular';
else if (file.includes('/nestjs/')) tech = 'nestjs';
else if (file.includes('/typescript/')) tech = 'typescript';
else if (file.includes('/express/')) tech = 'express';
else if (file.includes('/nodejs/')) tech = 'nodejs';
else {
const parts = file.split('/');
if (parts.length > 1) tech = parts[1];
}
if (tech) {
if (!filesByTech[tech]) filesByTech[tech] = [];
filesByTech[tech].push(file);
}
}

// Deduplicate and process syncBenchmarks sequentially by technology
for (const [tech, files] of Object.entries(filesByTech)) {
console.log(`Syncing benchmarks for ${tech}...`);
let combinedMdContent = '';
for (const file of files) {
if (await fileOrDirExists(file)) {
combinedMdContent += (await fsPromises.readFile(file, 'utf-8')) + '\n\n';
}
}
if (combinedMdContent) {
await syncBenchmarks(tech, combinedMdContent);
}
}

const filesToCommit = [];

// Then process files concurrently
await Promise.all(modifiedFiles.map(async (file) => {
console.log(`Processing ${file}...`);

if (!fs.existsSync(file)) {
if (!(await fileOrDirExists(file))) {
console.log(`File ${file} does not exist. Skipping.`);
continue;
return;
}

let tech = '';
Expand All @@ -256,23 +292,17 @@ async function runVibeCheck() {
else if (file.includes('/express/')) tech = 'express';
else if (file.includes('/nodejs/')) tech = 'nodejs';
else {
// Fallback
const parts = file.split('/');
if (parts.length > 1) {
tech = parts[1];
} else {
continue;
}
if (parts.length > 1) tech = parts[1];
else return; // Promise.all maps replace continue with return
}

const mdContent = await fsPromises.readFile(file, 'utf-8');

await syncBenchmarks(tech, mdContent);

const suitePath = path.join('benchmarks', 'suites', `${tech}.json`);
if (!fs.existsSync(suitePath)) {
if (!(await fileOrDirExists(suitePath))) {
console.log(`No benchmark suite found for ${tech}. Skipping.`);
continue;
return;
}

const suiteConfig = JSON.parse(await fsPromises.readFile(suitePath, 'utf-8'));
Expand All @@ -281,7 +311,7 @@ async function runVibeCheck() {

if (!generatedCode) {
console.error(`Failed to generate code for ${tech}.`);
continue;
return;
}

const sourceFile = project.createSourceFile(`temp_${tech}.ts`, generatedCode, { overwrite: true });
Expand All @@ -299,20 +329,9 @@ async function runVibeCheck() {
await fsPromises.writeFile(file, content);
}

try {
execFileSync('git', ['add', file]);
try { execFileSync('sh', ['-c', 'git add benchmarks/suites/*.json benchmarks/criteria/*.json 2>/dev/null || true']); } catch (e) {}
// Only commit if there are changes (badge might already be there)
const status = execFileSync('git', ['status', '--porcelain'], { encoding: 'utf-8' });
if (status.includes(file) || status.includes('benchmarks/')) {
execFileSync('git', ['commit', '-m', '[chore: benchmark-sync]']);
execFileSync('git', ['push', 'origin', 'HEAD:main']);
} else {
console.log(`Badge already present in ${file}, skipping commit.`);
}
} catch (err) {
console.error('Failed to commit or push:', err.message);
}
// Git operations are stateful and can conflict if run concurrently
// Therefore, we'll collect the files to be staged, and handle git operations after Promise.all
filesToCommit.push(file);

} else {
console.error(`❌ Validation failed for ${file}. Score below 95%.`);
Expand All @@ -335,7 +354,25 @@ async function runVibeCheck() {

process.exitCode = 1;
}
})); // End Promise.all

if (filesToCommit.length > 0) {
try {
execFileSync('git', ['add', ...filesToCommit]);
try { execFileSync('sh', ['-c', 'git add benchmarks/suites/*.json benchmarks/criteria/*.json 2>/dev/null || true']); } catch (e) {}
const status = execFileSync('git', ['status', '--porcelain'], { encoding: 'utf-8' });
if (status.length > 0) {
execFileSync('git', ['commit', '-m', '[chore: benchmark-sync]']);
execFileSync('git', ['push', 'origin', 'HEAD:main']);
}
} catch (err) {
console.error('Failed to commit:', err.message);
}
}
}

runVibeCheck().catch(console.error);
import { pathToFileURL } from 'node:url';

if (import.meta.url === pathToFileURL(process.argv[1]).href) {
runVibeCheck().catch(console.error);
}
Loading