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 path = require("path");
|
||||||
const { execSync } = require("child_process");
|
const { execSync } = require("child_process");
|
||||||
const absoluteAppPath = path.join(repoRoot, appPath);
|
const absoluteAppPath = path.join(repoRoot, appPath);
|
||||||
const pkgJsonPath = path.join(absoluteAppPath, "package.json");
|
// Find all directories containing package.json (excluding node_modules, .git, .next, .vibncode, dist)
|
||||||
if (!fs.existsSync(pkgJsonPath)) {
|
const pkgDirs = [];
|
||||||
return { success: true }; // No package.json, skip build check
|
function scan(dir) {
|
||||||
}
|
try {
|
||||||
try {
|
const files = fs.readdirSync(dir);
|
||||||
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
if (files.includes("package.json")) {
|
||||||
// Only verify if there is an explicit build script
|
pkgDirs.push(dir);
|
||||||
if (!pkg.scripts || !pkg.scripts.build) {
|
}
|
||||||
return { success: true };
|
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}...`);
|
catch { }
|
||||||
// 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) {
|
scan(absoluteAppPath);
|
||||||
const stderr = err.stderr
|
if (pkgDirs.length === 0) {
|
||||||
? err.stderr.toString()
|
return { success: true }; // No package.json anywhere, skip build check
|
||||||
: 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
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
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 ────────────────────────────────────────────────────────────
|
// ── VIBN DB bridge ────────────────────────────────────────────────────────────
|
||||||
async function patchSession(opts, payload) {
|
async function patchSession(opts, payload) {
|
||||||
|
|||||||
@@ -24,39 +24,73 @@ function runBuildVerification(
|
|||||||
const { execSync } = require("child_process");
|
const { execSync } = require("child_process");
|
||||||
|
|
||||||
const absoluteAppPath = path.join(repoRoot, appPath);
|
const absoluteAppPath = path.join(repoRoot, appPath);
|
||||||
const pkgJsonPath = path.join(absoluteAppPath, "package.json");
|
|
||||||
|
|
||||||
if (!fs.existsSync(pkgJsonPath)) {
|
// Find all directories containing package.json (excluding node_modules, .git, .next, .vibncode, dist)
|
||||||
return { success: true }; // No package.json, skip build check
|
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 {
|
scan(absoluteAppPath);
|
||||||
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
||||||
// Only verify if there is an explicit build script
|
if (pkgDirs.length === 0) {
|
||||||
if (!pkg.scripts || !pkg.scripts.build) {
|
return { success: true }; // No package.json anywhere, skip build check
|
||||||
return { success: true };
|
}
|
||||||
|
|
||||||
|
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 {
|
export interface OutputLine {
|
||||||
|
|||||||
Reference in New Issue
Block a user