@workbench-ai/workbench-built-in-adapters 0.0.64 → 0.0.66
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/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +29 -117
- package/package.json +9 -4
package/dist/execute.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,IAAI,EAKL,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,IAAI,EAKL,MAAM,kCAAkC,CAAC;AAoB1C,OAAO,KAAK,EAEV,0BAA0B,EAG3B,MAAM,iBAAiB,CAAC;AAQzB,MAAM,WAAW,4CAA4C;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,IAAI,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAwDD,wBAAsB,qCAAqC,CACzD,IAAI,GAAE,4CAAiD,GACtD,OAAO,CAAC,IAAI,CAAC,CAiDf"}
|
package/dist/execute.js
CHANGED
|
@@ -2,10 +2,16 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { promises as fs } from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { jsonRecord, normalizeRelativePath, readSurfaceFiles, writeSurfaceFiles, } from "@workbench-ai/workbench-core";
|
|
5
6
|
import { ensureWorkbenchAdapterOutputDir, readWorkbenchAdapterOperationResult, readWorkbenchAdapterOperationRequest, runWorkbenchRuntimeOperationSequence, writeWorkbenchAdapterOperationResult, workbenchAdapterOperationResultPath, } from "@workbench-ai/workbench-protocol";
|
|
6
7
|
import YAML from "yaml";
|
|
7
8
|
import { isWorkbenchBuiltInAdapterId, adapterCommandName, } from "./manifests.js";
|
|
8
9
|
import { importWorkbenchRuntime } from "./runtime.js";
|
|
10
|
+
const DIRECT_ADAPTER_HANDLERS = {
|
|
11
|
+
command: executeCommandAdapterRequest,
|
|
12
|
+
tests: executeTestsEngineRequest,
|
|
13
|
+
workbench: executeWorkbenchEngineRequest,
|
|
14
|
+
};
|
|
9
15
|
const TASK_CONTROL_FILE = "task.yaml";
|
|
10
16
|
const DEFAULT_RUBRIC_PARALLELISM = 4;
|
|
11
17
|
export async function executeWorkbenchBuiltInAdapterCommand(args = {}) {
|
|
@@ -21,49 +27,33 @@ export async function executeWorkbenchBuiltInAdapterCommand(args = {}) {
|
|
|
21
27
|
request.paths.output = args.outputRoot;
|
|
22
28
|
}
|
|
23
29
|
await ensureWorkbenchAdapterOutputDir(request);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await executeTestsEngineRequest(request);
|
|
30
|
+
const agentOptions = {
|
|
31
|
+
agentExecutor: args.agentExecutor,
|
|
32
|
+
adapterAuthRoot: args.adapterAuthRoot,
|
|
33
|
+
adapterAuthRequest: args.adapterAuthRequest ?? request.auth,
|
|
34
|
+
adapterAuthEnv: args.adapterAuthEnv,
|
|
35
|
+
};
|
|
36
|
+
const directHandler = DIRECT_ADAPTER_HANDLERS[adapterId];
|
|
37
|
+
if (directHandler) {
|
|
38
|
+
await directHandler(request);
|
|
34
39
|
return;
|
|
35
40
|
}
|
|
36
41
|
if (adapterId === "rubric") {
|
|
37
42
|
if (request.operation !== "engine.run") {
|
|
38
43
|
throw new Error(`Rubric adapter cannot handle ${request.operation}.`);
|
|
39
44
|
}
|
|
40
|
-
await writeRubricJudgeResult(request, workloadFromAdapterOperationRequest(request), builtInRubricSpecFromRequest(request),
|
|
41
|
-
agentExecutor: args.agentExecutor,
|
|
42
|
-
adapterAuthRoot: args.adapterAuthRoot,
|
|
43
|
-
adapterAuthRequest: args.adapterAuthRequest ?? request.auth,
|
|
44
|
-
adapterAuthEnv: args.adapterAuthEnv,
|
|
45
|
-
});
|
|
45
|
+
await writeRubricJudgeResult(request, workloadFromAdapterOperationRequest(request), builtInRubricSpecFromRequest(request), agentOptions);
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
if (isBuiltInAgentAdapterId(adapterId)) {
|
|
49
49
|
const workload = workloadFromAdapterOperationRequest(request);
|
|
50
50
|
const agent = builtInAgentSpecFromRequest(request);
|
|
51
51
|
if (request.operation === "candidate.improve") {
|
|
52
|
-
await writeAgentCandidateRevisionOutput(request, workload, agent,
|
|
53
|
-
agentExecutor: args.agentExecutor,
|
|
54
|
-
adapterAuthRoot: args.adapterAuthRoot,
|
|
55
|
-
adapterAuthRequest: args.adapterAuthRequest ?? request.auth,
|
|
56
|
-
adapterAuthEnv: args.adapterAuthEnv,
|
|
57
|
-
});
|
|
52
|
+
await writeAgentCandidateRevisionOutput(request, workload, agent, agentOptions);
|
|
58
53
|
return;
|
|
59
54
|
}
|
|
60
55
|
if (request.operation === "candidate.run") {
|
|
61
|
-
await writeAgentCandidateOutput(request, workload, agent,
|
|
62
|
-
agentExecutor: args.agentExecutor,
|
|
63
|
-
adapterAuthRoot: args.adapterAuthRoot,
|
|
64
|
-
adapterAuthRequest: args.adapterAuthRequest ?? request.auth,
|
|
65
|
-
adapterAuthEnv: args.adapterAuthEnv,
|
|
66
|
-
});
|
|
56
|
+
await writeAgentCandidateOutput(request, workload, agent, agentOptions);
|
|
67
57
|
return;
|
|
68
58
|
}
|
|
69
59
|
throw new Error(`Agent adapter ${adapterId} cannot handle ${request.operation}.`);
|
|
@@ -270,7 +260,7 @@ async function readOptionalSurfaceFiles(root) {
|
|
|
270
260
|
if (!root) {
|
|
271
261
|
return [];
|
|
272
262
|
}
|
|
273
|
-
return await
|
|
263
|
+
return await readSurfaceFiles(root).catch((error) => {
|
|
274
264
|
if (error.code === "ENOENT") {
|
|
275
265
|
return [];
|
|
276
266
|
}
|
|
@@ -434,26 +424,14 @@ async function snapshotEditableCandidateWorkspace(request) {
|
|
|
434
424
|
};
|
|
435
425
|
}
|
|
436
426
|
async function readEditableCandidateWorkspaceFiles(root, edits) {
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
const absolutePath = path.join(root, normalized);
|
|
444
|
-
const stat = await fs.stat(absolutePath).catch(() => null);
|
|
445
|
-
if (!stat) {
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
if (stat.isDirectory()) {
|
|
449
|
-
await readSurfaceFilesInto(root, normalized, files);
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
if (stat.isFile()) {
|
|
453
|
-
files.push(await readSurfaceFile(root, normalized));
|
|
454
|
-
}
|
|
427
|
+
const editPaths = edits
|
|
428
|
+
.map(normalizeRelativePath)
|
|
429
|
+
.filter((filePath) => !isRuntimeWorkspacePath(filePath));
|
|
430
|
+
if (editPaths.length === 0) {
|
|
431
|
+
return [];
|
|
455
432
|
}
|
|
456
|
-
|
|
433
|
+
const files = await readSurfaceFiles(root);
|
|
434
|
+
return dedupeSurfaceFiles(files.filter((file) => isCandidateEditPath(file.path, editPaths) &&
|
|
457
435
|
!isRuntimeWorkspacePath(file.path)));
|
|
458
436
|
}
|
|
459
437
|
async function firstExistingFile(files) {
|
|
@@ -499,7 +477,7 @@ async function listWorkbenchTaskDirectories(root) {
|
|
|
499
477
|
return tasks.sort((left, right) => left.localeCompare(right));
|
|
500
478
|
}
|
|
501
479
|
async function readWorkbenchEngineCase(args) {
|
|
502
|
-
const sourceFiles = await
|
|
480
|
+
const sourceFiles = await readSurfaceFiles(args.taskDir);
|
|
503
481
|
const taskFile = sourceFiles.find((file) => normalizeRelativePath(file.path) === TASK_CONTROL_FILE && file.encoding === "utf8");
|
|
504
482
|
if (!taskFile) {
|
|
505
483
|
throw new Error(`Task ${args.id} is missing ${TASK_CONTROL_FILE}.`);
|
|
@@ -579,42 +557,6 @@ function stripTaskDirectory(files, prefix) {
|
|
|
579
557
|
return [{ ...file, path: normalized.slice(prefix.length) }];
|
|
580
558
|
}).sort((left, right) => left.path.localeCompare(right.path));
|
|
581
559
|
}
|
|
582
|
-
async function readSurfaceFilesRecursive(root) {
|
|
583
|
-
const result = [];
|
|
584
|
-
await readSurfaceFilesInto(root, "", result);
|
|
585
|
-
return result.sort((left, right) => left.path.localeCompare(right.path));
|
|
586
|
-
}
|
|
587
|
-
async function readSurfaceFilesInto(root, relativeDir, result) {
|
|
588
|
-
const entries = await fs.readdir(path.join(root, relativeDir), { withFileTypes: true });
|
|
589
|
-
for (const entry of entries) {
|
|
590
|
-
const relativePath = normalizeRelativePath(path.join(relativeDir, entry.name));
|
|
591
|
-
const absolutePath = path.join(root, relativePath);
|
|
592
|
-
if (entry.isDirectory()) {
|
|
593
|
-
await readSurfaceFilesInto(root, relativePath, result);
|
|
594
|
-
continue;
|
|
595
|
-
}
|
|
596
|
-
if (!entry.isFile()) {
|
|
597
|
-
continue;
|
|
598
|
-
}
|
|
599
|
-
result.push(await readSurfaceFile(root, relativePath));
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
async function readSurfaceFile(root, relativePath) {
|
|
603
|
-
const absolutePath = path.join(root, normalizeRelativePath(relativePath));
|
|
604
|
-
const [body, stat] = await Promise.all([
|
|
605
|
-
fs.readFile(absolutePath),
|
|
606
|
-
fs.stat(absolutePath),
|
|
607
|
-
]);
|
|
608
|
-
const text = body.toString("utf8");
|
|
609
|
-
const isUtf8 = Buffer.from(text, "utf8").equals(body);
|
|
610
|
-
return {
|
|
611
|
-
path: normalizeRelativePath(relativePath),
|
|
612
|
-
kind: isUtf8 ? "text" : "binary",
|
|
613
|
-
encoding: isUtf8 ? "utf8" : "base64",
|
|
614
|
-
content: isUtf8 ? text : body.toString("base64"),
|
|
615
|
-
executable: (stat.mode & 0o111) !== 0,
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
560
|
async function fileExists(filePath) {
|
|
619
561
|
return fs.stat(filePath).then((stat) => stat.isFile(), () => false);
|
|
620
562
|
}
|
|
@@ -1340,9 +1282,9 @@ function requireWorkloadTask(workload, label) {
|
|
|
1340
1282
|
}
|
|
1341
1283
|
}
|
|
1342
1284
|
async function createCandidatePatchFromWorkspace(args) {
|
|
1343
|
-
const before = new Map((await
|
|
1285
|
+
const before = new Map((await readSurfaceFiles(args.beforeRoot))
|
|
1344
1286
|
.map((file) => [normalizeRelativePath(file.path), file]));
|
|
1345
|
-
const changedFiles = (await
|
|
1287
|
+
const changedFiles = (await readSurfaceFiles(args.afterRoot))
|
|
1346
1288
|
.map((file) => ({ ...file, path: normalizeRelativePath(file.path) }))
|
|
1347
1289
|
.filter((file) => isCandidateEditPath(file.path, args.edits) &&
|
|
1348
1290
|
!isRuntimeWorkspacePath(file.path) &&
|
|
@@ -1371,19 +1313,6 @@ function isRuntimeWorkspacePath(filePath) {
|
|
|
1371
1313
|
normalized === "private" ||
|
|
1372
1314
|
normalized.startsWith("private/");
|
|
1373
1315
|
}
|
|
1374
|
-
async function writeSurfaceFiles(root, files) {
|
|
1375
|
-
for (const file of files) {
|
|
1376
|
-
const target = path.join(root, normalizeRelativePath(file.path));
|
|
1377
|
-
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
1378
|
-
const body = file.encoding === "base64"
|
|
1379
|
-
? Buffer.from(file.content, "base64")
|
|
1380
|
-
: Buffer.from(file.content, "utf8");
|
|
1381
|
-
await fs.writeFile(target, body);
|
|
1382
|
-
if (file.executable) {
|
|
1383
|
-
await fs.chmod(target, 0o755).catch(() => undefined);
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
1316
|
function isCandidateEditPath(filePath, edits) {
|
|
1388
1317
|
const normalized = normalizeRelativePath(filePath);
|
|
1389
1318
|
return edits.some((entry) => {
|
|
@@ -1391,10 +1320,6 @@ function isCandidateEditPath(filePath, edits) {
|
|
|
1391
1320
|
return normalized === editPath || normalized.startsWith(`${editPath}/`);
|
|
1392
1321
|
});
|
|
1393
1322
|
}
|
|
1394
|
-
function normalizeRelativePath(filePath) {
|
|
1395
|
-
const normalized = filePath.replace(/\\/gu, "/").replace(/^\/+/u, "");
|
|
1396
|
-
return normalized.split("/").filter(Boolean).join("/");
|
|
1397
|
-
}
|
|
1398
1323
|
function parseAgentJsonObject(output, label) {
|
|
1399
1324
|
const trimmed = output.trim();
|
|
1400
1325
|
const start = trimmed.indexOf("{");
|
|
@@ -1491,16 +1416,3 @@ function weightedCriteriaScore(criteria, specCriteria) {
|
|
|
1491
1416
|
}
|
|
1492
1417
|
return denominator > 0 ? Number((numerator / denominator).toFixed(6)) : undefined;
|
|
1493
1418
|
}
|
|
1494
|
-
function jsonRecord(value) {
|
|
1495
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
1496
|
-
? value
|
|
1497
|
-
: {};
|
|
1498
|
-
}
|
|
1499
|
-
function isJsonPayload(value) {
|
|
1500
|
-
return value === null ||
|
|
1501
|
-
typeof value === "string" ||
|
|
1502
|
-
typeof value === "number" ||
|
|
1503
|
-
typeof value === "boolean" ||
|
|
1504
|
-
(Array.isArray(value) && value.every(isJsonPayload)) ||
|
|
1505
|
-
(typeof value === "object" && value !== null && Object.values(value).every(isJsonPayload));
|
|
1506
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workbench-ai/workbench-built-in-adapters",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/workbench-ai/workbench.git",
|
|
7
|
+
"directory": "packages/built-in-adapters"
|
|
8
|
+
},
|
|
4
9
|
"type": "module",
|
|
5
10
|
"main": "dist/index.js",
|
|
6
11
|
"types": "dist/index.d.ts",
|
|
@@ -29,10 +34,10 @@
|
|
|
29
34
|
"yaml": "^2.8.2",
|
|
30
35
|
"@workbench-ai/agent-driver-anthropic-claude-code": "0.0.46",
|
|
31
36
|
"@workbench-ai/agent-driver-openai-codex": "0.0.46",
|
|
32
|
-
"@workbench-ai/workbench-
|
|
37
|
+
"@workbench-ai/workbench-contract": "0.0.66",
|
|
33
38
|
"@workbench-ai/agent-driver": "0.0.46",
|
|
34
|
-
"@workbench-ai/workbench-
|
|
35
|
-
"@workbench-ai/workbench-
|
|
39
|
+
"@workbench-ai/workbench-core": "0.0.66",
|
|
40
|
+
"@workbench-ai/workbench-protocol": "0.0.66"
|
|
36
41
|
},
|
|
37
42
|
"devDependencies": {
|
|
38
43
|
"@types/node": "^24.3.1",
|