self-bench 0.3.0 → 0.3.3
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/.dockerignore +9 -0
- package/Dockerfile +38 -0
- package/Dockerfile.sandbox +24 -0
- package/README.md +103 -171
- package/biome.json +18 -0
- package/bun.lock +1182 -0
- package/compose.yaml +85 -0
- package/dist/agent-smoke-main.js +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +40 -2
- package/dist/api.js.map +1 -1
- package/dist/artifacts.d.ts +0 -1
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/artifacts.js +0 -3
- package/dist/artifacts.js.map +1 -1
- package/dist/build-metadata.d.ts +2 -0
- package/dist/build-metadata.d.ts.map +1 -0
- package/dist/build-metadata.js +2 -0
- package/dist/build-metadata.js.map +1 -0
- package/dist/cli.js +26 -8
- package/dist/cli.js.map +1 -1
- package/dist/codex-review.d.ts +2 -1
- package/dist/codex-review.d.ts.map +1 -1
- package/dist/codex-review.js +26 -22
- package/dist/codex-review.js.map +1 -1
- package/dist/config.d.ts +0 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -2
- package/dist/config.js.map +1 -1
- package/dist/contracts.d.ts +1 -1
- package/dist/contracts.d.ts.map +1 -1
- package/dist/eval-main.js +3 -3
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +12 -7
- package/dist/evaluate.js.map +1 -1
- package/dist/provenance.d.ts +0 -1
- package/dist/provenance.d.ts.map +1 -1
- package/dist/provenance.js.map +1 -1
- package/dist/reaudit-main.js +10 -7
- package/dist/reaudit-main.js.map +1 -1
- package/dist/repair-main.js +8 -5
- package/dist/repair-main.js.map +1 -1
- package/dist/review/assets/index-CZ3G759O.js +1568 -0
- package/dist/review/assets/index-DgSLzX8l.css +1 -0
- package/dist/review/assets/{mojo-Blby8dQK.js → mojo-DJz3ZmWd.js} +1 -1
- package/dist/review/assets/typst-BUadGCkm.js +1 -0
- package/dist/review/index.html +2 -2
- package/dist/sandbox-repair.bundle.js +8 -7
- package/dist/sandbox-repair.js +7 -7
- package/dist/sandbox-repair.js.map +1 -1
- package/dist/sandbox-review.bundle.js +29 -25
- package/dist/sandbox-review.js +5 -3
- package/dist/sandbox-review.js.map +1 -1
- package/dist/sandbox-validation-repair.bundle.js +9 -9
- package/dist/sandbox-validation-repair.js +11 -9
- package/dist/sandbox-validation-repair.js.map +1 -1
- package/dist/subscription-auth.d.ts +12 -1
- package/dist/subscription-auth.d.ts.map +1 -1
- package/dist/subscription-auth.js +16 -16
- package/dist/subscription-auth.js.map +1 -1
- package/dist/{activities.d.ts → temporal/activities.d.ts} +2 -3
- package/dist/temporal/activities.d.ts.map +1 -0
- package/dist/{activities.js → temporal/activities.js} +44 -33
- package/dist/temporal/activities.js.map +1 -0
- package/dist/{temporal.d.ts → temporal/connection.d.ts} +2 -2
- package/dist/temporal/connection.d.ts.map +1 -0
- package/dist/{temporal.js → temporal/connection.js} +1 -1
- package/dist/temporal/connection.js.map +1 -0
- package/dist/{worker-main.d.ts.map → temporal/worker-main.d.ts.map} +1 -1
- package/dist/{worker-main.js → temporal/worker-main.js} +5 -9
- package/dist/temporal/worker-main.js.map +1 -0
- package/dist/{workflow.d.ts → temporal/workflow.d.ts} +1 -1
- package/dist/temporal/workflow.d.ts.map +1 -0
- package/dist/temporal/workflow.js.map +1 -0
- package/dist/validate-main.js +1 -1
- package/docs/evaluations.md +68 -0
- package/docs/operations.md +169 -0
- package/docs/task-construction.md +94 -0
- package/package.json +33 -20
- package/scripts/verify-package.ts +57 -0
- package/scripts/write-build-metadata.ts +27 -0
- package/src/agent-smoke-main.ts +63 -0
- package/src/agent-smoke.ts +132 -0
- package/src/api-main.ts +12 -0
- package/src/api.ts +277 -0
- package/src/artifacts.ts +357 -0
- package/src/audit.ts +106 -0
- package/src/build-metadata.ts +3 -0
- package/src/cli.ts +359 -0
- package/src/codex-review.ts +229 -0
- package/src/config.ts +114 -0
- package/src/contracts.ts +204 -0
- package/src/coupling.ts +259 -0
- package/src/docker-executor.ts +115 -0
- package/src/eval-main.ts +92 -0
- package/src/evaluate.ts +298 -0
- package/src/github.ts +26 -0
- package/src/harbor-results.ts +142 -0
- package/src/harbor-task.ts +528 -0
- package/src/hash.ts +5 -0
- package/src/modal-auth.ts +11 -0
- package/src/modal-executor.ts +176 -0
- package/src/parallel.ts +24 -0
- package/src/process.ts +165 -0
- package/src/provenance.ts +457 -0
- package/src/reaudit-main.ts +195 -0
- package/src/repair-main.ts +206 -0
- package/src/repair.ts +55 -0
- package/src/run-wait.ts +40 -0
- package/src/sandbox-author.ts +19 -0
- package/src/sandbox-repair.ts +156 -0
- package/src/sandbox-review.ts +19 -0
- package/src/sandbox-validation-repair.ts +177 -0
- package/src/sandbox.ts +51 -0
- package/src/subscription-auth.ts +80 -0
- package/src/temporal/activities.ts +1241 -0
- package/src/temporal/connection.ts +23 -0
- package/src/temporal/worker-main.ts +28 -0
- package/src/temporal/workflow.ts +519 -0
- package/src/validate-main.ts +171 -0
- package/src/validation-repair.ts +94 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +21 -0
- package/dist/activities.d.ts.map +0 -1
- package/dist/activities.js.map +0 -1
- package/dist/extensions/review.d.ts +0 -3
- package/dist/extensions/review.d.ts.map +0 -1
- package/dist/extensions/review.js +0 -44
- package/dist/extensions/review.js.map +0 -1
- package/dist/review/assets/index-Dq-6DFzI.css +0 -1
- package/dist/review/assets/index-DurW_RD7.js +0 -1567
- package/dist/review/assets/typst-DHCkPAjA.js +0 -1
- package/dist/temporal.d.ts.map +0 -1
- package/dist/temporal.js.map +0 -1
- package/dist/worker-main.js.map +0 -1
- package/dist/workflow.d.ts.map +0 -1
- package/dist/workflow.js.map +0 -1
- package/src/extensions/review.ts +0 -54
- /package/dist/{worker-main.d.ts → temporal/worker-main.d.ts} +0 -0
- /package/dist/{workflow.js → temporal/workflow.js} +0 -0
package/src/sandbox.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SelfBenchConfig } from "./config.js";
|
|
2
|
+
import { DockerSandboxExecutor } from "./docker-executor.js";
|
|
3
|
+
import { ModalSandboxExecutor } from "./modal-executor.js";
|
|
4
|
+
|
|
5
|
+
export interface SandboxFile {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly contents: Uint8Array | string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SandboxRequest {
|
|
11
|
+
readonly runId: string;
|
|
12
|
+
readonly stage: string;
|
|
13
|
+
readonly command: readonly string[];
|
|
14
|
+
readonly files?: readonly SandboxFile[];
|
|
15
|
+
readonly outputPaths?: readonly string[];
|
|
16
|
+
readonly environment?: Readonly<Record<string, string>>;
|
|
17
|
+
readonly secrets?: Readonly<Record<string, string>>;
|
|
18
|
+
readonly timeoutMs: number;
|
|
19
|
+
readonly inactivityTimeoutMs?: number;
|
|
20
|
+
readonly cpu?: number;
|
|
21
|
+
readonly memoryMiB?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SandboxProgress {
|
|
25
|
+
readonly stream: "stdout" | "stderr";
|
|
26
|
+
readonly bytes: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface SandboxRunOptions {
|
|
30
|
+
readonly signal?: AbortSignal;
|
|
31
|
+
readonly onProgress?: (progress: SandboxProgress) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface SandboxResult {
|
|
35
|
+
readonly sandboxId: string;
|
|
36
|
+
readonly exitCode: number;
|
|
37
|
+
readonly stdout: string;
|
|
38
|
+
readonly stderr: string;
|
|
39
|
+
readonly outputs: Readonly<Record<string, Uint8Array>>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SandboxExecutor {
|
|
43
|
+
run(request: SandboxRequest, options?: SandboxRunOptions): Promise<SandboxResult>;
|
|
44
|
+
close(): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createSandboxExecutor(config: SelfBenchConfig["execution"]): SandboxExecutor {
|
|
48
|
+
return config.kind === "modal"
|
|
49
|
+
? new ModalSandboxExecutor(config)
|
|
50
|
+
: new DockerSandboxExecutor(config);
|
|
51
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { runCommand } from "./process.js";
|
|
5
|
+
|
|
6
|
+
export interface PiModelAuth {
|
|
7
|
+
readonly provider: "openai" | "openai-codex";
|
|
8
|
+
readonly apiKey?: string;
|
|
9
|
+
readonly authJson?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CodexModelAuth {
|
|
13
|
+
readonly apiKey?: string;
|
|
14
|
+
readonly authJson?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function openAiApiKey(): string | undefined {
|
|
18
|
+
const key = process.env.OPENAI_API_KEY?.trim();
|
|
19
|
+
return key || undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function loadPiModelAuth(): Promise<PiModelAuth> {
|
|
23
|
+
const apiKey = openAiApiKey();
|
|
24
|
+
return apiKey
|
|
25
|
+
? { provider: "openai", apiKey }
|
|
26
|
+
: { provider: "openai-codex", authJson: await loadPiSubscriptionAuth() };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function loadCodexModelAuth(): Promise<CodexModelAuth> {
|
|
30
|
+
const apiKey = openAiApiKey();
|
|
31
|
+
return apiKey ? { apiKey } : { authJson: await loadCodexSubscriptionAuth() };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function loadPiSubscriptionAuth(): Promise<string> {
|
|
35
|
+
const raw =
|
|
36
|
+
process.env.SELFBENCH_PI_AUTH_JSON ??
|
|
37
|
+
(await readFile(join(homedir(), ".pi/agent/auth.json"), "utf8"));
|
|
38
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
39
|
+
const credential = isRecord(parsed) ? parsed["openai-codex"] : undefined;
|
|
40
|
+
if (
|
|
41
|
+
!isRecord(credential) ||
|
|
42
|
+
credential.type !== "oauth" ||
|
|
43
|
+
typeof credential.access !== "string" ||
|
|
44
|
+
typeof credential.refresh !== "string"
|
|
45
|
+
) {
|
|
46
|
+
throw new Error("Pi auth does not contain an openai-codex subscription credential");
|
|
47
|
+
}
|
|
48
|
+
return JSON.stringify({ "openai-codex": credential });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function assertCodexSubscriptionAuth(value: unknown, source = "Codex auth"): void {
|
|
52
|
+
if (!isRecord(value) || value.auth_mode !== "chatgpt" || !isRecord(value.tokens)) {
|
|
53
|
+
throw new Error(`${source} does not contain a ChatGPT subscription token set`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function loadCodexSubscriptionAuth(): Promise<string> {
|
|
58
|
+
const path = process.env.CODEX_AUTH_JSON_PATH ?? join(homedir(), ".codex/auth.json");
|
|
59
|
+
const raw = process.env.SELFBENCH_CODEX_AUTH_JSON ?? (await readFile(path, "utf8"));
|
|
60
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
61
|
+
assertCodexSubscriptionAuth(parsed, path);
|
|
62
|
+
const auth = parsed as Record<string, unknown>;
|
|
63
|
+
return JSON.stringify({
|
|
64
|
+
auth_mode: "chatgpt",
|
|
65
|
+
tokens: auth.tokens,
|
|
66
|
+
...(typeof auth.last_refresh === "string" ? { last_refresh: auth.last_refresh } : {}),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function githubToken(): Promise<string | undefined> {
|
|
71
|
+
if (process.env.GH_TOKEN) {
|
|
72
|
+
return process.env.GH_TOKEN;
|
|
73
|
+
}
|
|
74
|
+
const result = await runCommand("gh", ["auth", "token"], { allowFailure: true });
|
|
75
|
+
return result.exitCode === 0 && result.stdout.trim() ? result.stdout.trim() : undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
79
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80
|
+
}
|