@wix/evalforge-evaluator 0.191.0 → 0.192.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +79 -37
- package/build/index.js.map +3 -3
- package/build/index.mjs +82 -40
- package/build/index.mjs.map +3 -3
- package/build/types/run-scenario/install-dependencies.d.ts +14 -2
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -7372,6 +7372,37 @@ var import_fs = require("fs");
|
|
|
7372
7372
|
var import_crypto = require("crypto");
|
|
7373
7373
|
var import_path2 = __toESM(require("path"));
|
|
7374
7374
|
var import_child_process = require("child_process");
|
|
7375
|
+
var INSTALL_TIMEOUT_MS = 9e4;
|
|
7376
|
+
var HEARTBEAT_INTERVAL_MS = 5e3;
|
|
7377
|
+
function defaultExec(cmd, args, opts) {
|
|
7378
|
+
return new Promise((resolve3, reject) => {
|
|
7379
|
+
const child = (0, import_child_process.spawn)(cmd, args, {
|
|
7380
|
+
cwd: opts.cwd,
|
|
7381
|
+
env: opts.env,
|
|
7382
|
+
stdio: "inherit"
|
|
7383
|
+
});
|
|
7384
|
+
const timer = setTimeout(() => {
|
|
7385
|
+
child.kill("SIGKILL");
|
|
7386
|
+
reject(
|
|
7387
|
+
new Error(
|
|
7388
|
+
`${cmd} ${args.join(" ")} timed out after ${opts.timeoutMs}ms`
|
|
7389
|
+
)
|
|
7390
|
+
);
|
|
7391
|
+
}, opts.timeoutMs);
|
|
7392
|
+
child.on("error", (err) => {
|
|
7393
|
+
clearTimeout(timer);
|
|
7394
|
+
reject(err);
|
|
7395
|
+
});
|
|
7396
|
+
child.on("close", (code) => {
|
|
7397
|
+
clearTimeout(timer);
|
|
7398
|
+
if (code === 0) {
|
|
7399
|
+
resolve3();
|
|
7400
|
+
} else {
|
|
7401
|
+
reject(new Error(`${cmd} exited with code ${code}`));
|
|
7402
|
+
}
|
|
7403
|
+
});
|
|
7404
|
+
});
|
|
7405
|
+
}
|
|
7375
7406
|
function detectPackageManager(workDir) {
|
|
7376
7407
|
if ((0, import_fs.existsSync)(import_path2.default.join(workDir, "pnpm-lock.yaml"))) {
|
|
7377
7408
|
return {
|
|
@@ -7409,7 +7440,34 @@ function cloneDirectory(src, dest) {
|
|
|
7409
7440
|
(0, import_fs.cpSync)(src, dest, { recursive: true });
|
|
7410
7441
|
}
|
|
7411
7442
|
}
|
|
7412
|
-
function
|
|
7443
|
+
async function runInstall(exec, pm, workDir, onProgress) {
|
|
7444
|
+
onProgress(`[diag] npm install starting: ${pm.cmd} ${pm.args.join(" ")}`);
|
|
7445
|
+
const startedAt = Date.now();
|
|
7446
|
+
const heartbeat = setInterval(() => {
|
|
7447
|
+
onProgress(
|
|
7448
|
+
`[diag] npm install still running: ${Math.round(
|
|
7449
|
+
(Date.now() - startedAt) / 1e3
|
|
7450
|
+
)}s elapsed`
|
|
7451
|
+
);
|
|
7452
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
7453
|
+
try {
|
|
7454
|
+
await exec(pm.cmd, pm.args, {
|
|
7455
|
+
cwd: workDir,
|
|
7456
|
+
timeoutMs: INSTALL_TIMEOUT_MS,
|
|
7457
|
+
env: { ...process.env, NODE_ENV: "development" }
|
|
7458
|
+
});
|
|
7459
|
+
onProgress(`[diag] npm install finished in ${Date.now() - startedAt}ms`);
|
|
7460
|
+
return true;
|
|
7461
|
+
} catch (err) {
|
|
7462
|
+
onProgress(
|
|
7463
|
+
`[diag] npm install FAILED after ${Date.now() - startedAt}ms: ${err instanceof Error ? err.message : String(err)}`
|
|
7464
|
+
);
|
|
7465
|
+
return false;
|
|
7466
|
+
} finally {
|
|
7467
|
+
clearInterval(heartbeat);
|
|
7468
|
+
}
|
|
7469
|
+
}
|
|
7470
|
+
async function installWithCache(workDir, exec, cacheBase, pm, onProgress) {
|
|
7413
7471
|
const sourceContent = (0, import_fs.readFileSync)(
|
|
7414
7472
|
import_path2.default.join(workDir, pm.cacheSourceFile),
|
|
7415
7473
|
"utf-8"
|
|
@@ -7423,29 +7481,19 @@ function installWithCache(workDir, exec, cacheBase, pm) {
|
|
|
7423
7481
|
console.log(
|
|
7424
7482
|
`[environment] Restoring node_modules from cache (key: ${cacheKey})`
|
|
7425
7483
|
);
|
|
7484
|
+
onProgress(`[diag] node_modules cache HIT (key: ${cacheKey}) \u2014 restoring`);
|
|
7426
7485
|
if (!(0, import_fs.existsSync)(targetNodeModules)) {
|
|
7427
7486
|
cloneDirectory(cachedNodeModules, targetNodeModules);
|
|
7428
7487
|
}
|
|
7429
7488
|
if ((0, import_fs.existsSync)(cachedYarnLock)) {
|
|
7430
7489
|
(0, import_fs.copyFileSync)(cachedYarnLock, import_path2.default.join(workDir, "yarn.lock"));
|
|
7431
7490
|
}
|
|
7491
|
+
onProgress("[diag] node_modules cache restore complete");
|
|
7432
7492
|
return;
|
|
7433
7493
|
}
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
)
|
|
7437
|
-
try {
|
|
7438
|
-
exec(pm.cmd, pm.args, {
|
|
7439
|
-
cwd: workDir,
|
|
7440
|
-
stdio: "inherit",
|
|
7441
|
-
timeout: 18e4,
|
|
7442
|
-
env: { ...process.env, NODE_ENV: "development" }
|
|
7443
|
-
});
|
|
7444
|
-
} catch (err) {
|
|
7445
|
-
console.error(
|
|
7446
|
-
"[environment] Dependency installation failed:",
|
|
7447
|
-
err instanceof Error ? err.message : String(err)
|
|
7448
|
-
);
|
|
7494
|
+
onProgress(`[diag] node_modules cache MISS (key: ${cacheKey})`);
|
|
7495
|
+
const ok = await runInstall(exec, pm, workDir, onProgress);
|
|
7496
|
+
if (!ok) {
|
|
7449
7497
|
return;
|
|
7450
7498
|
}
|
|
7451
7499
|
console.log(
|
|
@@ -7469,31 +7517,15 @@ async function installDependencies(workDir, onProgress, options = {}) {
|
|
|
7469
7517
|
if (!(0, import_fs.existsSync)(import_path2.default.join(workDir, "package.json"))) {
|
|
7470
7518
|
return;
|
|
7471
7519
|
}
|
|
7472
|
-
const exec = options.exec ??
|
|
7520
|
+
const exec = options.exec ?? defaultExec;
|
|
7473
7521
|
const cacheBase = options.cacheBase;
|
|
7474
7522
|
onProgress("Installing dependencies...");
|
|
7475
7523
|
const pm = detectPackageManager(workDir);
|
|
7476
7524
|
if (cacheBase) {
|
|
7477
|
-
installWithCache(workDir, exec, cacheBase, pm);
|
|
7525
|
+
await installWithCache(workDir, exec, cacheBase, pm, onProgress);
|
|
7478
7526
|
return;
|
|
7479
7527
|
}
|
|
7480
|
-
|
|
7481
|
-
`[environment] Running ${pm.cmd} ${pm.args.join(" ")} in ${workDir}`
|
|
7482
|
-
);
|
|
7483
|
-
try {
|
|
7484
|
-
exec(pm.cmd, pm.args, {
|
|
7485
|
-
cwd: workDir,
|
|
7486
|
-
stdio: "inherit",
|
|
7487
|
-
timeout: 18e4,
|
|
7488
|
-
env: { ...process.env, NODE_ENV: "development" }
|
|
7489
|
-
});
|
|
7490
|
-
console.log("[environment] Dependency installation complete");
|
|
7491
|
-
} catch (err) {
|
|
7492
|
-
console.error(
|
|
7493
|
-
"[environment] Dependency installation failed:",
|
|
7494
|
-
err instanceof Error ? err.message : String(err)
|
|
7495
|
-
);
|
|
7496
|
-
}
|
|
7528
|
+
await runInstall(exec, pm, workDir, onProgress);
|
|
7497
7529
|
}
|
|
7498
7530
|
|
|
7499
7531
|
// src/run-scenario/environment.ts
|
|
@@ -7569,7 +7601,9 @@ async function fetchAndWriteTemplateFiles(template, workDir, onProgress) {
|
|
|
7569
7601
|
`Template "${template.name}" has no source configured, creating empty directory`
|
|
7570
7602
|
);
|
|
7571
7603
|
}
|
|
7604
|
+
onProgress(`[diag] writing ${sourceFiles.length} source file(s) to workDir`);
|
|
7572
7605
|
await writeFilesToDirectory(workDir, sourceFiles);
|
|
7606
|
+
onProgress(`[diag] ${sourceFiles.length} source file(s) written`);
|
|
7573
7607
|
const extraFiles = template.extraFiles ?? [];
|
|
7574
7608
|
onProgress(`[diag] resolving ${extraFiles.length} extra file(s)`);
|
|
7575
7609
|
await Promise.all(
|
|
@@ -7650,10 +7684,13 @@ async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId,
|
|
|
7650
7684
|
onProgress("Fetching template files...");
|
|
7651
7685
|
await fetchAndWriteTemplateFiles(template, workDir2, onProgress);
|
|
7652
7686
|
console.log(`Template files written to ${workDir2}`);
|
|
7687
|
+
onProgress("[diag] writing wix env file");
|
|
7653
7688
|
writeWixEnvFile(workDir2);
|
|
7689
|
+
onProgress("[diag] entering installDependencies");
|
|
7654
7690
|
await installDependencies(workDir2, onProgress, {
|
|
7655
7691
|
cacheBase: nodeModulesCacheDir
|
|
7656
7692
|
});
|
|
7693
|
+
onProgress("[diag] installDependencies returned");
|
|
7657
7694
|
onProgress("Environment ready");
|
|
7658
7695
|
return workDir2;
|
|
7659
7696
|
}
|
|
@@ -8460,7 +8497,7 @@ async function executeWithClaudeCode(skills, scenario, options) {
|
|
|
8460
8497
|
const SDK_TIMEOUT_MS = resolveTimeoutMs(maxTurns, options.maxDurationMs);
|
|
8461
8498
|
let timeoutHandle;
|
|
8462
8499
|
let timedOut = false;
|
|
8463
|
-
const
|
|
8500
|
+
const HEARTBEAT_INTERVAL_MS2 = 1e4;
|
|
8464
8501
|
let heartbeatHandle;
|
|
8465
8502
|
const executionStartTime = Date.now();
|
|
8466
8503
|
try {
|
|
@@ -8512,7 +8549,7 @@ async function executeWithClaudeCode(skills, scenario, options) {
|
|
|
8512
8549
|
isComplete: false
|
|
8513
8550
|
};
|
|
8514
8551
|
emitTraceEvent(progressEvent, traceContext.pushEvent);
|
|
8515
|
-
},
|
|
8552
|
+
}, HEARTBEAT_INTERVAL_MS2);
|
|
8516
8553
|
}
|
|
8517
8554
|
const sdkPromise = (async () => {
|
|
8518
8555
|
const hasImages = scenario.triggerPromptImages && scenario.triggerPromptImages.length > 0;
|
|
@@ -12106,11 +12143,15 @@ async function runScenario(config, evalRunId2, scenario, evalData, template, res
|
|
|
12106
12143
|
);
|
|
12107
12144
|
let provisionedSite;
|
|
12108
12145
|
if (apiClient && projectId2 && scenario.siteSetup && scenario.siteSetup.mode !== "none") {
|
|
12146
|
+
emitSetupProgress(
|
|
12147
|
+
`[diag] provisioning scenario site (mode: ${scenario.siteSetup.mode})...`
|
|
12148
|
+
);
|
|
12109
12149
|
provisionedSite = await apiClient.provisionScenarioSite(
|
|
12110
12150
|
projectId2,
|
|
12111
12151
|
evalRunId2,
|
|
12112
12152
|
scenario.id
|
|
12113
12153
|
);
|
|
12154
|
+
emitSetupProgress("[diag] scenario site provisioned");
|
|
12114
12155
|
}
|
|
12115
12156
|
const failedStep = provisionedSite?.bootstrapResult?.steps.find((s) => !s.ok);
|
|
12116
12157
|
if (failedStep) {
|
|
@@ -12143,6 +12184,7 @@ Site ID: ${provisionedSite.id}` : scenario.triggerPrompt;
|
|
|
12143
12184
|
emitSetupProgress,
|
|
12144
12185
|
{ template }
|
|
12145
12186
|
);
|
|
12187
|
+
emitSetupProgress("[diag] starting agent run");
|
|
12146
12188
|
const partialResult = await runAgentWithContext(
|
|
12147
12189
|
config,
|
|
12148
12190
|
evalRunId2,
|