@wix/evalforge-evaluator 0.191.0 → 0.193.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 +103 -37
- package/build/index.js.map +3 -3
- package/build/index.mjs +116 -43
- 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,58 @@ 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 = 1e5;
|
|
7376
|
+
var HEARTBEAT_INTERVAL_MS = 5e3;
|
|
7377
|
+
function reportRegistry(workDir, onProgress) {
|
|
7378
|
+
try {
|
|
7379
|
+
const registry = (0, import_child_process.execFileSync)("npm", ["config", "get", "registry"], {
|
|
7380
|
+
cwd: workDir,
|
|
7381
|
+
encoding: "utf8"
|
|
7382
|
+
}).trim();
|
|
7383
|
+
onProgress(`[diag] npm registry = ${registry}`);
|
|
7384
|
+
} catch (err) {
|
|
7385
|
+
onProgress(
|
|
7386
|
+
`[diag] npm registry = <unreadable: ${err instanceof Error ? err.message : String(err)}>`
|
|
7387
|
+
);
|
|
7388
|
+
}
|
|
7389
|
+
}
|
|
7390
|
+
function reportNodeModules(workDir, onProgress) {
|
|
7391
|
+
try {
|
|
7392
|
+
const nm = import_path2.default.join(workDir, "node_modules");
|
|
7393
|
+
const count = (0, import_fs.existsSync)(nm) ? (0, import_fs.readdirSync)(nm).length : 0;
|
|
7394
|
+
onProgress(`[diag] node_modules top-level entries: ${count}`);
|
|
7395
|
+
} catch {
|
|
7396
|
+
}
|
|
7397
|
+
}
|
|
7398
|
+
function defaultExec(cmd, args, opts) {
|
|
7399
|
+
return new Promise((resolve3, reject) => {
|
|
7400
|
+
const child = (0, import_child_process.spawn)(cmd, args, {
|
|
7401
|
+
cwd: opts.cwd,
|
|
7402
|
+
env: opts.env,
|
|
7403
|
+
stdio: "inherit"
|
|
7404
|
+
});
|
|
7405
|
+
const timer = setTimeout(() => {
|
|
7406
|
+
child.kill("SIGKILL");
|
|
7407
|
+
reject(
|
|
7408
|
+
new Error(
|
|
7409
|
+
`${cmd} ${args.join(" ")} timed out after ${opts.timeoutMs}ms`
|
|
7410
|
+
)
|
|
7411
|
+
);
|
|
7412
|
+
}, opts.timeoutMs);
|
|
7413
|
+
child.on("error", (err) => {
|
|
7414
|
+
clearTimeout(timer);
|
|
7415
|
+
reject(err);
|
|
7416
|
+
});
|
|
7417
|
+
child.on("close", (code) => {
|
|
7418
|
+
clearTimeout(timer);
|
|
7419
|
+
if (code === 0) {
|
|
7420
|
+
resolve3();
|
|
7421
|
+
} else {
|
|
7422
|
+
reject(new Error(`${cmd} exited with code ${code}`));
|
|
7423
|
+
}
|
|
7424
|
+
});
|
|
7425
|
+
});
|
|
7426
|
+
}
|
|
7375
7427
|
function detectPackageManager(workDir) {
|
|
7376
7428
|
if ((0, import_fs.existsSync)(import_path2.default.join(workDir, "pnpm-lock.yaml"))) {
|
|
7377
7429
|
return {
|
|
@@ -7409,7 +7461,37 @@ function cloneDirectory(src, dest) {
|
|
|
7409
7461
|
(0, import_fs.cpSync)(src, dest, { recursive: true });
|
|
7410
7462
|
}
|
|
7411
7463
|
}
|
|
7412
|
-
function
|
|
7464
|
+
async function runInstall(exec, pm, workDir, onProgress) {
|
|
7465
|
+
reportRegistry(workDir, onProgress);
|
|
7466
|
+
onProgress(`[diag] npm install starting: ${pm.cmd} ${pm.args.join(" ")}`);
|
|
7467
|
+
const startedAt = Date.now();
|
|
7468
|
+
const heartbeat = setInterval(() => {
|
|
7469
|
+
onProgress(
|
|
7470
|
+
`[diag] npm install still running: ${Math.round(
|
|
7471
|
+
(Date.now() - startedAt) / 1e3
|
|
7472
|
+
)}s elapsed`
|
|
7473
|
+
);
|
|
7474
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
7475
|
+
try {
|
|
7476
|
+
await exec(pm.cmd, pm.args, {
|
|
7477
|
+
cwd: workDir,
|
|
7478
|
+
timeoutMs: INSTALL_TIMEOUT_MS,
|
|
7479
|
+
env: { ...process.env, NODE_ENV: "development" }
|
|
7480
|
+
});
|
|
7481
|
+
onProgress(`[diag] npm install finished in ${Date.now() - startedAt}ms`);
|
|
7482
|
+
reportNodeModules(workDir, onProgress);
|
|
7483
|
+
return true;
|
|
7484
|
+
} catch (err) {
|
|
7485
|
+
onProgress(
|
|
7486
|
+
`[diag] npm install FAILED after ${Date.now() - startedAt}ms: ${err instanceof Error ? err.message : String(err)}`
|
|
7487
|
+
);
|
|
7488
|
+
reportNodeModules(workDir, onProgress);
|
|
7489
|
+
return false;
|
|
7490
|
+
} finally {
|
|
7491
|
+
clearInterval(heartbeat);
|
|
7492
|
+
}
|
|
7493
|
+
}
|
|
7494
|
+
async function installWithCache(workDir, exec, cacheBase, pm, onProgress) {
|
|
7413
7495
|
const sourceContent = (0, import_fs.readFileSync)(
|
|
7414
7496
|
import_path2.default.join(workDir, pm.cacheSourceFile),
|
|
7415
7497
|
"utf-8"
|
|
@@ -7423,29 +7505,19 @@ function installWithCache(workDir, exec, cacheBase, pm) {
|
|
|
7423
7505
|
console.log(
|
|
7424
7506
|
`[environment] Restoring node_modules from cache (key: ${cacheKey})`
|
|
7425
7507
|
);
|
|
7508
|
+
onProgress(`[diag] node_modules cache HIT (key: ${cacheKey}) \u2014 restoring`);
|
|
7426
7509
|
if (!(0, import_fs.existsSync)(targetNodeModules)) {
|
|
7427
7510
|
cloneDirectory(cachedNodeModules, targetNodeModules);
|
|
7428
7511
|
}
|
|
7429
7512
|
if ((0, import_fs.existsSync)(cachedYarnLock)) {
|
|
7430
7513
|
(0, import_fs.copyFileSync)(cachedYarnLock, import_path2.default.join(workDir, "yarn.lock"));
|
|
7431
7514
|
}
|
|
7515
|
+
onProgress("[diag] node_modules cache restore complete");
|
|
7432
7516
|
return;
|
|
7433
7517
|
}
|
|
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
|
-
);
|
|
7518
|
+
onProgress(`[diag] node_modules cache MISS (key: ${cacheKey})`);
|
|
7519
|
+
const ok = await runInstall(exec, pm, workDir, onProgress);
|
|
7520
|
+
if (!ok) {
|
|
7449
7521
|
return;
|
|
7450
7522
|
}
|
|
7451
7523
|
console.log(
|
|
@@ -7469,31 +7541,15 @@ async function installDependencies(workDir, onProgress, options = {}) {
|
|
|
7469
7541
|
if (!(0, import_fs.existsSync)(import_path2.default.join(workDir, "package.json"))) {
|
|
7470
7542
|
return;
|
|
7471
7543
|
}
|
|
7472
|
-
const exec = options.exec ??
|
|
7544
|
+
const exec = options.exec ?? defaultExec;
|
|
7473
7545
|
const cacheBase = options.cacheBase;
|
|
7474
7546
|
onProgress("Installing dependencies...");
|
|
7475
7547
|
const pm = detectPackageManager(workDir);
|
|
7476
7548
|
if (cacheBase) {
|
|
7477
|
-
installWithCache(workDir, exec, cacheBase, pm);
|
|
7549
|
+
await installWithCache(workDir, exec, cacheBase, pm, onProgress);
|
|
7478
7550
|
return;
|
|
7479
7551
|
}
|
|
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
|
-
}
|
|
7552
|
+
await runInstall(exec, pm, workDir, onProgress);
|
|
7497
7553
|
}
|
|
7498
7554
|
|
|
7499
7555
|
// src/run-scenario/environment.ts
|
|
@@ -7569,7 +7625,9 @@ async function fetchAndWriteTemplateFiles(template, workDir, onProgress) {
|
|
|
7569
7625
|
`Template "${template.name}" has no source configured, creating empty directory`
|
|
7570
7626
|
);
|
|
7571
7627
|
}
|
|
7628
|
+
onProgress(`[diag] writing ${sourceFiles.length} source file(s) to workDir`);
|
|
7572
7629
|
await writeFilesToDirectory(workDir, sourceFiles);
|
|
7630
|
+
onProgress(`[diag] ${sourceFiles.length} source file(s) written`);
|
|
7573
7631
|
const extraFiles = template.extraFiles ?? [];
|
|
7574
7632
|
onProgress(`[diag] resolving ${extraFiles.length} extra file(s)`);
|
|
7575
7633
|
await Promise.all(
|
|
@@ -7650,10 +7708,13 @@ async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId,
|
|
|
7650
7708
|
onProgress("Fetching template files...");
|
|
7651
7709
|
await fetchAndWriteTemplateFiles(template, workDir2, onProgress);
|
|
7652
7710
|
console.log(`Template files written to ${workDir2}`);
|
|
7711
|
+
onProgress("[diag] writing wix env file");
|
|
7653
7712
|
writeWixEnvFile(workDir2);
|
|
7713
|
+
onProgress("[diag] entering installDependencies");
|
|
7654
7714
|
await installDependencies(workDir2, onProgress, {
|
|
7655
7715
|
cacheBase: nodeModulesCacheDir
|
|
7656
7716
|
});
|
|
7717
|
+
onProgress("[diag] installDependencies returned");
|
|
7657
7718
|
onProgress("Environment ready");
|
|
7658
7719
|
return workDir2;
|
|
7659
7720
|
}
|
|
@@ -8460,7 +8521,7 @@ async function executeWithClaudeCode(skills, scenario, options) {
|
|
|
8460
8521
|
const SDK_TIMEOUT_MS = resolveTimeoutMs(maxTurns, options.maxDurationMs);
|
|
8461
8522
|
let timeoutHandle;
|
|
8462
8523
|
let timedOut = false;
|
|
8463
|
-
const
|
|
8524
|
+
const HEARTBEAT_INTERVAL_MS2 = 1e4;
|
|
8464
8525
|
let heartbeatHandle;
|
|
8465
8526
|
const executionStartTime = Date.now();
|
|
8466
8527
|
try {
|
|
@@ -8512,7 +8573,7 @@ async function executeWithClaudeCode(skills, scenario, options) {
|
|
|
8512
8573
|
isComplete: false
|
|
8513
8574
|
};
|
|
8514
8575
|
emitTraceEvent(progressEvent, traceContext.pushEvent);
|
|
8515
|
-
},
|
|
8576
|
+
}, HEARTBEAT_INTERVAL_MS2);
|
|
8516
8577
|
}
|
|
8517
8578
|
const sdkPromise = (async () => {
|
|
8518
8579
|
const hasImages = scenario.triggerPromptImages && scenario.triggerPromptImages.length > 0;
|
|
@@ -12106,11 +12167,15 @@ async function runScenario(config, evalRunId2, scenario, evalData, template, res
|
|
|
12106
12167
|
);
|
|
12107
12168
|
let provisionedSite;
|
|
12108
12169
|
if (apiClient && projectId2 && scenario.siteSetup && scenario.siteSetup.mode !== "none") {
|
|
12170
|
+
emitSetupProgress(
|
|
12171
|
+
`[diag] provisioning scenario site (mode: ${scenario.siteSetup.mode})...`
|
|
12172
|
+
);
|
|
12109
12173
|
provisionedSite = await apiClient.provisionScenarioSite(
|
|
12110
12174
|
projectId2,
|
|
12111
12175
|
evalRunId2,
|
|
12112
12176
|
scenario.id
|
|
12113
12177
|
);
|
|
12178
|
+
emitSetupProgress("[diag] scenario site provisioned");
|
|
12114
12179
|
}
|
|
12115
12180
|
const failedStep = provisionedSite?.bootstrapResult?.steps.find((s) => !s.ok);
|
|
12116
12181
|
if (failedStep) {
|
|
@@ -12143,6 +12208,7 @@ Site ID: ${provisionedSite.id}` : scenario.triggerPrompt;
|
|
|
12143
12208
|
emitSetupProgress,
|
|
12144
12209
|
{ template }
|
|
12145
12210
|
);
|
|
12211
|
+
emitSetupProgress("[diag] starting agent run");
|
|
12146
12212
|
const partialResult = await runAgentWithContext(
|
|
12147
12213
|
config,
|
|
12148
12214
|
evalRunId2,
|