fix(runner): support recursive package.json scanning in build verification
This commit is contained in:
78
vibn-agent-runner/dist/agent-session-runner.js
vendored
78
vibn-agent-runner/dist/agent-session-runner.js
vendored
@@ -18,35 +18,61 @@ function runBuildVerification(repoRoot, appPath) {
|
||||
const path = require("path");
|
||||
const { execSync } = require("child_process");
|
||||
const absoluteAppPath = path.join(repoRoot, appPath);
|
||||
const pkgJsonPath = path.join(absoluteAppPath, "package.json");
|
||||
if (!fs.existsSync(pkgJsonPath)) {
|
||||
return { success: true }; // No package.json, skip build check
|
||||
}
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
||||
// Only verify if there is an explicit build script
|
||||
if (!pkg.scripts || !pkg.scripts.build) {
|
||||
return { success: true };
|
||||
// Find all directories containing package.json (excluding node_modules, .git, .next, .vibncode, dist)
|
||||
const pkgDirs = [];
|
||||
function scan(dir) {
|
||||
try {
|
||||
const files = fs.readdirSync(dir);
|
||||
if (files.includes("package.json")) {
|
||||
pkgDirs.push(dir);
|
||||
}
|
||||
for (const file of files) {
|
||||
if (file === "node_modules" ||
|
||||
file === ".git" ||
|
||||
file === ".next" ||
|
||||
file === ".vibncode" ||
|
||||
file === "dist") {
|
||||
continue;
|
||||
}
|
||||
const full = path.join(dir, file);
|
||||
if (fs.statSync(full).isDirectory()) {
|
||||
scan(full);
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(`[Ralph Loop] Running automatic build verification: npm run build inside ${absoluteAppPath}...`);
|
||||
// Run npm run build with a 45s timeout to prevent hanging
|
||||
execSync("npm run build", {
|
||||
cwd: absoluteAppPath,
|
||||
stdio: "pipe",
|
||||
timeout: 45000,
|
||||
});
|
||||
return { success: true };
|
||||
catch { }
|
||||
}
|
||||
catch (err) {
|
||||
const stderr = err.stderr
|
||||
? err.stderr.toString()
|
||||
: err.message || String(err);
|
||||
console.warn(`[Ralph Loop] Build verification failed:`, stderr);
|
||||
return {
|
||||
success: false,
|
||||
error: stderr.slice(-3000), // Cap the log length to avoid flooding the prompt context
|
||||
};
|
||||
scan(absoluteAppPath);
|
||||
if (pkgDirs.length === 0) {
|
||||
return { success: true }; // No package.json anywhere, skip build check
|
||||
}
|
||||
for (const dir of pkgDirs) {
|
||||
const pkgJsonPath = path.join(dir, "package.json");
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
||||
// Skip if there's no build script or if it's the root container which is just a workspace wrapper
|
||||
if (!pkg.scripts || !pkg.scripts.build || pkg.name === "workspace") {
|
||||
continue;
|
||||
}
|
||||
console.log(`[Ralph Loop] Running automatic build verification: npm run build inside ${dir}...`);
|
||||
execSync("npm run build", {
|
||||
cwd: dir,
|
||||
stdio: "pipe",
|
||||
timeout: 60000,
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
const stderr = err.stderr
|
||||
? err.stderr.toString()
|
||||
: err.message || String(err);
|
||||
console.warn(`[Ralph Loop] Build verification failed inside ${dir}:`, stderr);
|
||||
return {
|
||||
success: false,
|
||||
error: `Build failed in directory "${path.relative(repoRoot, dir)}":\n${stderr.slice(-3000)}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
// ── VIBN DB bridge ────────────────────────────────────────────────────────────
|
||||
async function patchSession(opts, payload) {
|
||||
|
||||
@@ -24,39 +24,73 @@ function runBuildVerification(
|
||||
const { execSync } = require("child_process");
|
||||
|
||||
const absoluteAppPath = path.join(repoRoot, appPath);
|
||||
const pkgJsonPath = path.join(absoluteAppPath, "package.json");
|
||||
|
||||
if (!fs.existsSync(pkgJsonPath)) {
|
||||
return { success: true }; // No package.json, skip build check
|
||||
// Find all directories containing package.json (excluding node_modules, .git, .next, .vibncode, dist)
|
||||
const pkgDirs: string[] = [];
|
||||
|
||||
function scan(dir: string) {
|
||||
try {
|
||||
const files = fs.readdirSync(dir);
|
||||
if (files.includes("package.json")) {
|
||||
pkgDirs.push(dir);
|
||||
}
|
||||
for (const file of files) {
|
||||
if (
|
||||
file === "node_modules" ||
|
||||
file === ".git" ||
|
||||
file === ".next" ||
|
||||
file === ".vibncode" ||
|
||||
file === "dist"
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const full = path.join(dir, file);
|
||||
if (fs.statSync(full).isDirectory()) {
|
||||
scan(full);
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
||||
// Only verify if there is an explicit build script
|
||||
if (!pkg.scripts || !pkg.scripts.build) {
|
||||
return { success: true };
|
||||
scan(absoluteAppPath);
|
||||
|
||||
if (pkgDirs.length === 0) {
|
||||
return { success: true }; // No package.json anywhere, skip build check
|
||||
}
|
||||
|
||||
for (const dir of pkgDirs) {
|
||||
const pkgJsonPath = path.join(dir, "package.json");
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
||||
// Skip if there's no build script or if it's the root container which is just a workspace wrapper
|
||||
if (!pkg.scripts || !pkg.scripts.build || pkg.name === "workspace") {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Ralph Loop] Running automatic build verification: npm run build inside ${dir}...`,
|
||||
);
|
||||
execSync("npm run build", {
|
||||
cwd: dir,
|
||||
stdio: "pipe",
|
||||
timeout: 60000,
|
||||
});
|
||||
} catch (err: any) {
|
||||
const stderr = err.stderr
|
||||
? err.stderr.toString()
|
||||
: err.message || String(err);
|
||||
console.warn(
|
||||
`[Ralph Loop] Build verification failed inside ${dir}:`,
|
||||
stderr,
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
error: `Build failed in directory "${path.relative(repoRoot, dir)}":\n${stderr.slice(-3000)}`,
|
||||
};
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[Ralph Loop] Running automatic build verification: npm run build inside ${absoluteAppPath}...`,
|
||||
);
|
||||
// Run npm run build with a 45s timeout to prevent hanging
|
||||
execSync("npm run build", {
|
||||
cwd: absoluteAppPath,
|
||||
stdio: "pipe",
|
||||
timeout: 45000,
|
||||
});
|
||||
return { success: true };
|
||||
} catch (err: any) {
|
||||
const stderr = err.stderr
|
||||
? err.stderr.toString()
|
||||
: err.message || String(err);
|
||||
console.warn(`[Ralph Loop] Build verification failed:`, stderr);
|
||||
return {
|
||||
success: false,
|
||||
error: stderr.slice(-3000), // Cap the log length to avoid flooding the prompt context
|
||||
};
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
export interface OutputLine {
|
||||
|
||||
Reference in New Issue
Block a user