@lelouchhe/agent-evals 0.1.1 → 0.3.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/README.md +27 -18
- package/dist/checkers/file/index.js +181 -13
- package/dist/checkers/judge/index.d.ts +1 -1
- package/dist/checkers/judge/index.js +243 -31
- package/dist/checkers/judge/prompt.d.ts +4 -3
- package/dist/checkers/judge/prompt.js +22 -3
- package/dist/cli.js +171 -35
- package/dist/engine/authoring.js +108 -13
- package/dist/engine/check-runner.js +18 -3
- package/dist/engine/check-sandbox.js +9 -6
- package/dist/engine/config.d.ts +31 -2
- package/dist/engine/config.js +16 -10
- package/dist/engine/env-source.js +82 -14
- package/dist/engine/files.d.ts +2 -5
- package/dist/engine/files.js +4 -6
- package/dist/engine/mocks.js +72 -46
- package/dist/engine/params.d.ts +2 -0
- package/dist/engine/params.js +10 -0
- package/dist/engine/registry.d.ts +11 -0
- package/dist/engine/report.js +43 -8
- package/dist/engine/results.d.ts +7 -0
- package/dist/engine/results.js +9 -6
- package/dist/engine/run.d.ts +4 -1
- package/dist/engine/run.js +171 -28
- package/dist/engine/skills.js +12 -5
- package/dist/engine/view.d.ts +1 -1
- package/dist/engine/view.js +125 -10
- package/dist/engine/workspace.d.ts +7 -0
- package/dist/engine/workspace.js +37 -27
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/platform/index.d.ts +31 -0
- package/dist/platform/index.js +88 -0
- package/dist/platform/linux/index.d.ts +2 -0
- package/dist/platform/linux/index.js +40 -0
- package/dist/platform/linux/launch.d.ts +8 -0
- package/dist/platform/linux/launch.js +25 -0
- package/dist/platform/linux/policy.d.ts +46 -0
- package/dist/platform/linux/policy.js +388 -0
- package/dist/platform/linux/supervise.d.ts +8 -0
- package/dist/platform/linux/supervise.js +124 -0
- package/dist/platform/macos/index.d.ts +2 -0
- package/dist/platform/macos/index.js +59 -0
- package/dist/platform/macos/launch.d.ts +2 -8
- package/dist/platform/macos/launch.js +5 -3
- package/dist/platform/macos/policy.d.ts +3 -21
- package/dist/platform/macos/policy.js +5 -2
- package/dist/platform/macos/supervise.d.ts +3 -25
- package/dist/platform/posix-forwarder-client.mjs +129 -0
- package/dist/platform/posix-forwarder.sh +9 -0
- package/dist/platform/posix-helpers.d.ts +22 -0
- package/dist/platform/posix-helpers.js +97 -0
- package/dist/platform/types.d.ts +118 -0
- package/dist/platform/types.js +1 -0
- package/dist/platform/windows/forwarder-client.mjs +165 -0
- package/dist/platform/windows/forwarder.cmd +3 -0
- package/dist/platform/windows/forwarder.ps1 +2 -0
- package/dist/platform/windows/forwarder.sh +2 -0
- package/dist/platform/windows/index.d.ts +2 -0
- package/dist/platform/windows/index.js +225 -0
- package/dist/platform/windows/launch.d.ts +3 -0
- package/dist/platform/windows/launch.js +30 -0
- package/dist/platform/windows/policy.d.ts +17 -0
- package/dist/platform/windows/policy.js +155 -0
- package/dist/platform/windows/setup.ps1 +112 -0
- package/dist/platform/windows/supervise.d.ts +2 -0
- package/dist/platform/windows/supervise.js +142 -0
- package/dist/platform/windows/win-sandbox.exe +0 -0
- package/dist/runners/acp/commands.js +2 -3
- package/dist/runners/acp/environment.d.ts +1 -7
- package/dist/runners/acp/environment.js +18 -48
- package/dist/runners/acp/index.js +5 -1
- package/dist/runners/acp/session.d.ts +1 -1
- package/dist/runners/pi/index.js +2 -2
- package/dist/runners/pi/session.d.ts +1 -1
- package/dist/runners/pi/session.js +27 -44
- package/dist/runners/pi/supervisor.js +1 -0
- package/package.json +5 -3
- package/dist/engine/forwarder.sh +0 -61
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
3
|
+
import { delimiter, dirname, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
const SYSTEM_ROOT = process.env.SystemRoot ?? process.env.WINDIR ?? "C:\\Windows";
|
|
6
|
+
const PROGRAM_FILES = process.env.ProgramFiles ?? "C:\\Program Files";
|
|
7
|
+
export const SYSTEM_PATH = [
|
|
8
|
+
join(SYSTEM_ROOT, "System32"),
|
|
9
|
+
SYSTEM_ROOT,
|
|
10
|
+
join(SYSTEM_ROOT, "System32", "Wbem"),
|
|
11
|
+
join(SYSTEM_ROOT, "System32", "WindowsPowerShell", "v1.0"),
|
|
12
|
+
join(PROGRAM_FILES, "PowerShell", "7"),
|
|
13
|
+
];
|
|
14
|
+
const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
15
|
+
let resolvedHelperPath;
|
|
16
|
+
export function winSandboxExecutablePath() {
|
|
17
|
+
if (resolvedHelperPath !== undefined)
|
|
18
|
+
return resolvedHelperPath;
|
|
19
|
+
const candidates = [
|
|
20
|
+
process.env.AGENT_EVALS_WIN_SANDBOX_BIN,
|
|
21
|
+
fileURLToPath(new URL("./win-sandbox.exe", import.meta.url)),
|
|
22
|
+
join(REPO_ROOT, "native", "win-sandbox", "target", "release", "win-sandbox.exe"),
|
|
23
|
+
join(REPO_ROOT, "native", "win-sandbox", "target", "debug", "win-sandbox.exe"),
|
|
24
|
+
].filter((p) => typeof p === "string" && p.length > 0);
|
|
25
|
+
for (const candidate of candidates) {
|
|
26
|
+
try {
|
|
27
|
+
accessSync(candidate, constants.F_OK);
|
|
28
|
+
resolvedHelperPath = candidate;
|
|
29
|
+
return candidate;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Try next candidate.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`Windows sandbox helper (win-sandbox.exe) not found; checked: ${candidates.join(", ")}. Set AGENT_EVALS_WIN_SANDBOX_BIN or build native/win-sandbox.`);
|
|
36
|
+
}
|
|
37
|
+
export function defaultTempParent() {
|
|
38
|
+
const fromEnv = process.env.AGENT_EVALS_WIN_RUNS_DIR;
|
|
39
|
+
if (typeof fromEnv === "string" && fromEnv.length > 0)
|
|
40
|
+
return resolve(fromEnv);
|
|
41
|
+
return join(process.env.ProgramData ?? "C:\\ProgramData", "agent-evals", "runs");
|
|
42
|
+
}
|
|
43
|
+
export function winSandboxCredentialsPath() {
|
|
44
|
+
const fromEnv = process.env.AGENT_EVALS_WIN_SANDBOX_CREDENTIALS;
|
|
45
|
+
if (typeof fromEnv === "string" && fromEnv.length > 0)
|
|
46
|
+
return resolve(fromEnv);
|
|
47
|
+
const localAppData = process.env.LOCALAPPDATA;
|
|
48
|
+
if (typeof localAppData === "string" && localAppData.length > 0) {
|
|
49
|
+
return join(localAppData, "agent-evals", "sandbox-users.json");
|
|
50
|
+
}
|
|
51
|
+
throw new Error("Cannot locate Windows sandbox credentials file; run `agent-evals setup sandbox` as Administrator or set AGENT_EVALS_WIN_SANDBOX_CREDENTIALS.");
|
|
52
|
+
}
|
|
53
|
+
let probed = false;
|
|
54
|
+
export function assertWinSandboxAvailable() {
|
|
55
|
+
if (probed)
|
|
56
|
+
return;
|
|
57
|
+
const helper = winSandboxExecutablePath();
|
|
58
|
+
const credsPath = winSandboxCredentialsPath();
|
|
59
|
+
try {
|
|
60
|
+
execFileSync(helper, ["--probe", credsPath], {
|
|
61
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
62
|
+
windowsHide: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
67
|
+
throw new Error(`Windows sandbox-user preflight failed (${helper} --probe ${credsPath}): ${detail}. Run \`agent-evals setup sandbox\` as Administrator.`, { cause: error });
|
|
68
|
+
}
|
|
69
|
+
probed = true;
|
|
70
|
+
}
|
|
71
|
+
export function createSandboxPolicy(options) {
|
|
72
|
+
return {
|
|
73
|
+
writableRoots: options.writableRoots.map((p) => resolve(p)),
|
|
74
|
+
readableRoots: options.readableRoots.map((p) => resolve(p)),
|
|
75
|
+
...(options.readableFiles === undefined ? {} : { readableFiles: options.readableFiles.map((p) => resolve(p)) }),
|
|
76
|
+
...(options.writableFiles === undefined ? {} : { writableFiles: options.writableFiles.map((p) => resolve(p)) }),
|
|
77
|
+
...(options.denyExecutables === undefined
|
|
78
|
+
? {}
|
|
79
|
+
: { denyExecutables: options.denyExecutables.map((p) => resolve(p)) }),
|
|
80
|
+
allowNetwork: options.allowNetwork,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function buildWindowsWorkloadEnv(env) {
|
|
84
|
+
const result = {};
|
|
85
|
+
const seenLower = new Set();
|
|
86
|
+
for (const [key, value] of Object.entries(env)) {
|
|
87
|
+
if (value === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
if (key.includes("\0") || key.includes("=") || value.includes("\0")) {
|
|
90
|
+
throw new Error(`invalid environment variable "${key}": NUL bytes and '=' in keys are not allowed`);
|
|
91
|
+
}
|
|
92
|
+
result[key] = value;
|
|
93
|
+
seenLower.add(key.toLowerCase());
|
|
94
|
+
}
|
|
95
|
+
const setDefault = (key, value) => {
|
|
96
|
+
if (!seenLower.has(key.toLowerCase())) {
|
|
97
|
+
result[key] = value;
|
|
98
|
+
seenLower.add(key.toLowerCase());
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const systemDrive = process.env.SystemDrive ?? SYSTEM_ROOT.slice(0, 2);
|
|
102
|
+
const userProfile = result.USERPROFILE ?? result.HOME ?? result.TEMP ?? result.TMP ?? SYSTEM_ROOT;
|
|
103
|
+
setDefault("SystemRoot", SYSTEM_ROOT);
|
|
104
|
+
setDefault("WINDIR", SYSTEM_ROOT);
|
|
105
|
+
setDefault("SystemDrive", systemDrive);
|
|
106
|
+
setDefault("ProgramFiles", PROGRAM_FILES);
|
|
107
|
+
if (process.env["ProgramFiles(x86)"] !== undefined && process.env["ProgramFiles(x86)"].length > 0) {
|
|
108
|
+
setDefault("ProgramFiles(x86)", process.env["ProgramFiles(x86)"]);
|
|
109
|
+
}
|
|
110
|
+
setDefault("ProgramData", process.env.ProgramData ?? join(systemDrive, "ProgramData"));
|
|
111
|
+
setDefault("ComSpec", join(SYSTEM_ROOT, "System32", "cmd.exe"));
|
|
112
|
+
setDefault("PATHEXT", ".COM;.EXE;.BAT;.CMD");
|
|
113
|
+
setDefault("USERPROFILE", userProfile);
|
|
114
|
+
setDefault("LOCALAPPDATA", join(userProfile, "AppData", "Local"));
|
|
115
|
+
setDefault("APPDATA", join(userProfile, "AppData", "Roaming"));
|
|
116
|
+
setDefault("PATH", SYSTEM_PATH.join(";"));
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Resolve a bare program name against the workload's PATH (including `.exe`/`.cmd`/`.bat`)
|
|
121
|
+
* and wrap `.cmd`/`.bat` shims with `cmd.exe /d /c` because Win32 `CreateProcessAsUserW`
|
|
122
|
+
* cannot execute batch files directly.
|
|
123
|
+
*/
|
|
124
|
+
export function resolveWindowsCommand(program, args, env) {
|
|
125
|
+
const comSpec = env.ComSpec ?? join(SYSTEM_ROOT, "System32", "cmd.exe");
|
|
126
|
+
const isRegular = (p) => {
|
|
127
|
+
try {
|
|
128
|
+
return statSync(p).isFile();
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
let resolved = program;
|
|
135
|
+
if (!program.includes("\\") && !program.includes("/")) {
|
|
136
|
+
const pathKey = Object.keys(env).find((k) => k.toLowerCase() === "path");
|
|
137
|
+
const pathVal = pathKey === undefined ? "" : (env[pathKey] ?? "");
|
|
138
|
+
const exts = /\.[a-z0-9]+$/iu.test(program) ? [""] : [".exe", ".cmd", ".bat", ".com", ""];
|
|
139
|
+
outer: for (const dir of pathVal.split(delimiter)) {
|
|
140
|
+
if (dir.length === 0)
|
|
141
|
+
continue;
|
|
142
|
+
for (const ext of exts) {
|
|
143
|
+
const candidate = join(dir, `${program}${ext}`);
|
|
144
|
+
if (isRegular(candidate)) {
|
|
145
|
+
resolved = candidate;
|
|
146
|
+
break outer;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (/\.(?:cmd|bat)$/iu.test(resolved)) {
|
|
152
|
+
return { command: comSpec, args: ["/d", "/c", resolved, ...args] };
|
|
153
|
+
}
|
|
154
|
+
return { command: resolved, args };
|
|
155
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#Requires -RunAsAdministrator
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
One-time setup (or teardown) for @lelouchhe/agent-evals native Windows sandbox users.
|
|
5
|
+
.DESCRIPTION
|
|
6
|
+
Creates two unprivileged local accounts:
|
|
7
|
+
- agent-evals-online : network-enabled sandbox user for evaluated agents
|
|
8
|
+
- agent-evals-offline : network-blocked sandbox user (Windows Firewall outbound block by SID)
|
|
9
|
+
Stores freshly generated random passwords in an owner-only JSON file so win-sandbox.exe
|
|
10
|
+
can log on via LogonUserW without any real user credentials.
|
|
11
|
+
#>
|
|
12
|
+
param(
|
|
13
|
+
[string]$CredentialsPath = (Join-Path $env:LOCALAPPDATA "agent-evals\sandbox-users.json"),
|
|
14
|
+
[switch]$Teardown
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
$ErrorActionPreference = "Stop"
|
|
18
|
+
|
|
19
|
+
$OnlineUser = "agent-evals-online"
|
|
20
|
+
$OfflineUser = "agent-evals-offline"
|
|
21
|
+
$FirewallRuleName = "agent-evals-offline outbound block"
|
|
22
|
+
|
|
23
|
+
if ($Teardown) {
|
|
24
|
+
Get-NetFirewallRule -DisplayName $FirewallRuleName -ErrorAction SilentlyContinue | Remove-NetFirewallRule
|
|
25
|
+
foreach ($name in @($OnlineUser, $OfflineUser)) {
|
|
26
|
+
if (Get-LocalUser -Name $name -ErrorAction SilentlyContinue) {
|
|
27
|
+
Remove-LocalUser -Name $name
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (Test-Path $CredentialsPath) {
|
|
31
|
+
Remove-Item -Force $CredentialsPath
|
|
32
|
+
}
|
|
33
|
+
Write-Host "Removed $OnlineUser, $OfflineUser, firewall rule, and credentials file."
|
|
34
|
+
exit 0
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function New-RandomPassword {
|
|
38
|
+
$bytes = New-Object byte[] 24
|
|
39
|
+
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes)
|
|
40
|
+
# Ensure Windows complexity requirements (upper, lower, digit, symbol).
|
|
41
|
+
return "Ae!9" + [Convert]::ToBase64String($bytes)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Ensure-SandboxUser([string]$Name, [string]$Description) {
|
|
45
|
+
$plain = New-RandomPassword
|
|
46
|
+
$secure = ConvertTo-SecureString $plain -AsPlainText -Force
|
|
47
|
+
$existing = Get-LocalUser -Name $Name -ErrorAction SilentlyContinue
|
|
48
|
+
if ($existing) {
|
|
49
|
+
Set-LocalUser -Name $Name -Password $secure -PasswordNeverExpires $true -UserMayNotChangePassword $true
|
|
50
|
+
} else {
|
|
51
|
+
New-LocalUser -Name $Name -Password $secure -Description $Description -PasswordNeverExpires -UserMayNotChangePassword | Out-Null
|
|
52
|
+
}
|
|
53
|
+
# Add to standard Users group (read/execute on system binaries, NO access to other users' %USERPROFILE%).
|
|
54
|
+
$isMember = (Get-LocalGroupMember -Group "Users" -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*\$Name" })
|
|
55
|
+
if (-not $isMember) {
|
|
56
|
+
Add-LocalGroupMember -Group "Users" -Member $Name
|
|
57
|
+
}
|
|
58
|
+
$sid = (Get-LocalUser -Name $Name).SID.Value
|
|
59
|
+
return @{
|
|
60
|
+
username = $Name
|
|
61
|
+
password = $plain
|
|
62
|
+
sid = $sid
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
$online = Ensure-SandboxUser -Name $OnlineUser -Description "agent-evals online sandbox user"
|
|
67
|
+
$offline = Ensure-SandboxUser -Name $OfflineUser -Description "agent-evals offline sandbox user"
|
|
68
|
+
|
|
69
|
+
# Ensure Windows Defender Firewall is enabled so the offline user outbound block is enforced.
|
|
70
|
+
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True
|
|
71
|
+
|
|
72
|
+
# Recreate outbound block rule scoped strictly to agent-evals-offline's SID.
|
|
73
|
+
Get-NetFirewallRule -DisplayName $FirewallRuleName -ErrorAction SilentlyContinue | Remove-NetFirewallRule
|
|
74
|
+
$localUserSddl = "D:(A;;CC;;;$($offline.sid))"
|
|
75
|
+
New-NetFirewallRule `
|
|
76
|
+
-DisplayName $FirewallRuleName `
|
|
77
|
+
-Direction Outbound `
|
|
78
|
+
-Action Block `
|
|
79
|
+
-LocalUser $localUserSddl `
|
|
80
|
+
-Profile Any `
|
|
81
|
+
-Enabled True | Out-Null
|
|
82
|
+
|
|
83
|
+
$credDir = Split-Path -Parent $CredentialsPath
|
|
84
|
+
New-Item -ItemType Directory -Force -Path $credDir | Out-Null
|
|
85
|
+
|
|
86
|
+
$payload = @{
|
|
87
|
+
online = @{
|
|
88
|
+
username = $online.username
|
|
89
|
+
password = $online.password
|
|
90
|
+
sid = $online.sid
|
|
91
|
+
}
|
|
92
|
+
offline = @{
|
|
93
|
+
username = $offline.username
|
|
94
|
+
password = $offline.password
|
|
95
|
+
sid = $offline.sid
|
|
96
|
+
}
|
|
97
|
+
} | ConvertTo-Json -Depth 4
|
|
98
|
+
|
|
99
|
+
Set-Content -Path $CredentialsPath -Value $payload -Encoding UTF8
|
|
100
|
+
|
|
101
|
+
# Restrict credentials file to current user + SYSTEM + Administrators (strip Users/Everyone).
|
|
102
|
+
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
103
|
+
icacls $CredentialsPath /inheritance:r /grant:r "${currentUser}:(F)" "SYSTEM:(F)" "Administrators:(F)" | Out-Null
|
|
104
|
+
|
|
105
|
+
# Create neutral run-root parent outside %USERPROFILE% so sandboxed Node realpathSync can lstat ancestors.
|
|
106
|
+
$RunsDir = Join-Path $env:ProgramData "agent-evals\runs"
|
|
107
|
+
New-Item -ItemType Directory -Force -Path $RunsDir | Out-Null
|
|
108
|
+
icacls $RunsDir /grant "${currentUser}:(OI)(CI)(F)" "Users:(RX)" | Out-Null
|
|
109
|
+
|
|
110
|
+
Write-Host "Configured $OnlineUser ($($online.sid)) and $OfflineUser ($($offline.sid))"
|
|
111
|
+
Write-Host "Credentials saved to $CredentialsPath"
|
|
112
|
+
Write-Host "Neutral runs directory ready at $RunsDir"
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { createServer } from "node:net";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
import { PassThrough } from "node:stream";
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
import { buildWindowsWorkloadEnv, resolveWindowsCommand, winSandboxCredentialsPath, winSandboxExecutablePath, } from "./policy.js";
|
|
9
|
+
export async function spawnSupervised(options) {
|
|
10
|
+
const helper = winSandboxExecutablePath();
|
|
11
|
+
const [program, ...args] = options.command;
|
|
12
|
+
await mkdir(options.policyDirectory, { recursive: true });
|
|
13
|
+
const controlPipe = `\\\\.\\pipe\\agent-evals-stop-${randomUUID()}`;
|
|
14
|
+
let controlSocket;
|
|
15
|
+
let stopRequested = false;
|
|
16
|
+
const controlServer = createServer((socket) => {
|
|
17
|
+
controlSocket = socket;
|
|
18
|
+
socket.on("error", () => { });
|
|
19
|
+
if (stopRequested) {
|
|
20
|
+
socket.end("stop\n");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
controlServer.unref();
|
|
24
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
25
|
+
controlServer.once("error", rejectListen);
|
|
26
|
+
controlServer.listen(controlPipe, () => {
|
|
27
|
+
controlServer.off("error", rejectListen);
|
|
28
|
+
resolveListen();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
let report;
|
|
32
|
+
let reportPipe;
|
|
33
|
+
let reportServer;
|
|
34
|
+
if (options.report === true) {
|
|
35
|
+
report = new PassThrough();
|
|
36
|
+
reportPipe = `\\\\.\\pipe\\agent-evals-host-report-${randomUUID()}`;
|
|
37
|
+
const reportStream = report;
|
|
38
|
+
reportServer = createServer((socket) => {
|
|
39
|
+
socket.on("error", () => { });
|
|
40
|
+
socket.on("data", (chunk) => reportStream.write(chunk));
|
|
41
|
+
socket.on("end", () => reportStream.end());
|
|
42
|
+
});
|
|
43
|
+
reportServer.unref();
|
|
44
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
45
|
+
reportServer.once("error", rejectListen);
|
|
46
|
+
reportServer.listen(reportPipe, () => {
|
|
47
|
+
reportServer.off("error", rejectListen);
|
|
48
|
+
resolveListen();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const workloadEnv = buildWindowsWorkloadEnv(options.env);
|
|
53
|
+
const resolvedCmd = resolveWindowsCommand(program, args, workloadEnv);
|
|
54
|
+
const configPath = join(options.policyDirectory, `win-sandbox-${randomUUID()}.json`);
|
|
55
|
+
const config = {
|
|
56
|
+
command: resolvedCmd.command,
|
|
57
|
+
args: [...resolvedCmd.args],
|
|
58
|
+
cwd: resolve(options.cwd),
|
|
59
|
+
env: workloadEnv,
|
|
60
|
+
writableRoots: options.policy.writableRoots,
|
|
61
|
+
readableRoots: options.policy.readableRoots,
|
|
62
|
+
writableFiles: options.policy.writableFiles ?? [],
|
|
63
|
+
readableFiles: options.policy.readableFiles ?? [],
|
|
64
|
+
allowNetwork: options.policy.allowNetwork,
|
|
65
|
+
credentialsPath: winSandboxCredentialsPath(),
|
|
66
|
+
controlPipe,
|
|
67
|
+
...(reportPipe === undefined ? {} : { reportPipe }),
|
|
68
|
+
};
|
|
69
|
+
await writeFile(configPath, JSON.stringify(config), "utf8");
|
|
70
|
+
const mode = options.interactive ? "inherit" : "pipe";
|
|
71
|
+
const child = spawn(helper, ["--config", configPath, "--delete-config"], {
|
|
72
|
+
cwd: options.cwd,
|
|
73
|
+
stdio: [mode, mode, mode],
|
|
74
|
+
windowsHide: !options.interactive,
|
|
75
|
+
});
|
|
76
|
+
const closeServers = () => {
|
|
77
|
+
controlSocket?.destroy();
|
|
78
|
+
controlServer.close();
|
|
79
|
+
reportServer?.close();
|
|
80
|
+
if (report !== undefined && !report.writableEnded) {
|
|
81
|
+
report.end();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
let exited = false;
|
|
85
|
+
const exit = new Promise((resolveExit, rejectExit) => {
|
|
86
|
+
child.once("exit", (code, signal) => {
|
|
87
|
+
exited = true;
|
|
88
|
+
closeServers();
|
|
89
|
+
resolveExit({ code, signal });
|
|
90
|
+
});
|
|
91
|
+
child.once("error", (error) => {
|
|
92
|
+
exited = true;
|
|
93
|
+
closeServers();
|
|
94
|
+
rejectExit(error);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
const completion = exit.then(({ code }) => {
|
|
98
|
+
if (code === null) {
|
|
99
|
+
throw new Error("sandbox supervisor exited without a workload completion record");
|
|
100
|
+
}
|
|
101
|
+
return code;
|
|
102
|
+
});
|
|
103
|
+
completion.catch(() => { });
|
|
104
|
+
const waitForExit = async (ms) => {
|
|
105
|
+
const deadline = new AbortController();
|
|
106
|
+
try {
|
|
107
|
+
return await Promise.race([exit.then(() => true), delay(ms, false, { signal: deadline.signal })]);
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
deadline.abort();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
let stopping;
|
|
114
|
+
const stop = () => (stopping ??= (async () => {
|
|
115
|
+
try {
|
|
116
|
+
if (!exited) {
|
|
117
|
+
stopRequested = true;
|
|
118
|
+
if (controlSocket !== undefined) {
|
|
119
|
+
controlSocket.end("stop\n");
|
|
120
|
+
}
|
|
121
|
+
if (!(await waitForExit(2_500))) {
|
|
122
|
+
child.kill();
|
|
123
|
+
const reaped = await waitForExit(2_000);
|
|
124
|
+
if (!reaped) {
|
|
125
|
+
throw new Error("Windows sandbox supervisor did not exit after kill");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
await exit;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
closeServers();
|
|
135
|
+
child.stdin?.destroy();
|
|
136
|
+
child.stdout?.destroy();
|
|
137
|
+
child.stderr?.destroy();
|
|
138
|
+
report?.destroy();
|
|
139
|
+
}
|
|
140
|
+
})());
|
|
141
|
+
return { child, completion, stop, ...(report === undefined ? {} : { report }) };
|
|
142
|
+
}
|
|
Binary file
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { mkdir, realpath, rm } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
3
|
import { join } from "node:path";
|
|
5
4
|
import { stringify } from "yaml";
|
|
6
5
|
import { loadImplementationParameters } from "../../engine/authoring.js";
|
|
7
6
|
import { ConfigError, errorMessage } from "../../engine/config.js";
|
|
8
7
|
import { createEnvSource } from "../../engine/env-source.js";
|
|
9
|
-
import { spawnSupervised } from "../../platform/
|
|
8
|
+
import { defaultTempParent, spawnSupervised } from "../../platform/index.js";
|
|
10
9
|
import { agentSchema } from "./agent.js";
|
|
11
10
|
import { harnessEnvironment, prepareHarnessHome, resolveHarnessHome, saveLogin } from "./environment.js";
|
|
12
11
|
import { withSession } from "./session.js";
|
|
@@ -14,7 +13,7 @@ import { withSession } from "./session.js";
|
|
|
14
13
|
export async function runAgentCommand(command, path, signal) {
|
|
15
14
|
// Placeholders need the directories' paths; they are created only after validation. The
|
|
16
15
|
// parent is canonical so the sandbox authorizes traversal through the `deps` link.
|
|
17
|
-
const directory = join(await realpath(
|
|
16
|
+
const directory = join(await realpath(defaultTempParent()), `ae-acp-${randomBytes(6).toString("hex")}`);
|
|
18
17
|
const dirs = {
|
|
19
18
|
home: join(directory, "home"),
|
|
20
19
|
workspace: join(directory, "workspace"),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MockWiring } from "../../engine/registry.js";
|
|
2
2
|
import { type RunRoot } from "../../engine/workspace.js";
|
|
3
|
-
import { createSandboxPolicy } from "../../platform/
|
|
3
|
+
import { createSandboxPolicy } from "../../platform/index.js";
|
|
4
4
|
import type { AgentConfig } from "./agent.js";
|
|
5
5
|
/** Persistent login state: where it lives, which files compose it, and how to obtain it. */
|
|
6
6
|
export interface HarnessLogin {
|
|
@@ -63,9 +63,3 @@ export declare function harnessEnvironment(source: HarnessHome, dirs: {
|
|
|
63
63
|
}>;
|
|
64
64
|
/** Save declared login files after a successful native login. */
|
|
65
65
|
export declare function saveLogin(source: HarnessHome, homeRoot: RunRoot, selected: readonly string[]): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* The real binaries behind PATH targets whose rules never pass. Besides the first PATH match,
|
|
68
|
-
* the active developer directory is included because `/usr/bin/make` and `/usr/bin/git` are
|
|
69
|
-
* shims that start the toolchain's own copy.
|
|
70
|
-
*/
|
|
71
|
-
export declare function deniedBinaries(targets: readonly string[], pathEntries: readonly string[], developerDir: string | undefined): Promise<readonly string[]>;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { constants } from "node:fs";
|
|
2
|
-
import { execFile } from "node:child_process";
|
|
3
|
-
import { promisify } from "node:util";
|
|
4
1
|
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { lstat, mkdir,
|
|
6
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
2
|
+
import { lstat, mkdir, realpath, rename, rm, symlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { basename, delimiter, dirname, join, resolve } from "node:path";
|
|
7
4
|
import { ConfigError, errorMessage, expectPlacementDestination, expectRelativePath } from "../../engine/config.js";
|
|
8
5
|
import { copyPlacement, homePathOf, isHomeDestination, placedPaths, stageEntries } from "../../engine/files.js";
|
|
9
6
|
import { isMissing, isWithin, openRunRoot, resolveWorkspacePath } from "../../engine/workspace.js";
|
|
10
|
-
import {
|
|
7
|
+
import { assertSandboxAvailable, createSandboxPolicy, dirEnv, openRegularFileNoFollow, resolveDeniedExecutables, SYSTEM_PATH, } from "../../platform/index.js";
|
|
11
8
|
/** Validate the caller-owned software, HOME content and login state without creating run state. */
|
|
12
9
|
export async function resolveHarnessHome(agent, declaringDir) {
|
|
13
|
-
|
|
10
|
+
assertSandboxAvailable();
|
|
14
11
|
let deps;
|
|
15
12
|
try {
|
|
16
13
|
deps = (await openRunRoot(resolve(declaringDir, agent.deps))).path;
|
|
@@ -169,20 +166,29 @@ export async function harnessEnvironment(source, dirs, options) {
|
|
|
169
166
|
const mocks = options.mocks;
|
|
170
167
|
const depsLink = join(dirs.runRootDir, "deps");
|
|
171
168
|
const pathEntries = [...source.path.map((path) => join(depsLink, path)), ...SYSTEM_PATH];
|
|
169
|
+
let denyExecutables = [];
|
|
170
|
+
if (mocks !== undefined) {
|
|
171
|
+
denyExecutables = await resolveDeniedExecutables(mocks.denyTargets, pathEntries);
|
|
172
|
+
const runtimeNode = await realpath(process.execPath);
|
|
173
|
+
if (denyExecutables.includes(runtimeNode)) {
|
|
174
|
+
throw new ConfigError(`cannot deny ${runtimeNode} while mocks are active because mock forwarders execute with this Node interpreter`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
172
177
|
const policy = createSandboxPolicy({
|
|
173
178
|
writableRoots: [dirs.home, dirs.workspace, dirs.tmp],
|
|
174
179
|
// A mocked command's forwarder is readable and executable, never writable.
|
|
175
180
|
readableRoots: mocks === undefined ? [depsLink] : [depsLink, mocks.forwarderDir],
|
|
176
|
-
|
|
181
|
+
...(mocks?.readableFiles === undefined ? {} : { readableFiles: mocks.readableFiles }),
|
|
182
|
+
...(mocks === undefined ? {} : { writableFiles: [mocks.socketPath] }),
|
|
183
|
+
denyExecutables,
|
|
177
184
|
allowNetwork: true,
|
|
178
185
|
interactive: options.interactive,
|
|
179
186
|
});
|
|
180
187
|
const env = {
|
|
181
188
|
...source.environment,
|
|
182
189
|
...(process.env.TERM === undefined ? {} : { TERM: process.env.TERM }),
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
PATH: [...(mocks === undefined ? [] : [mocks.forwarderDir]), ...pathEntries].join(":"),
|
|
190
|
+
...dirEnv({ home: dirs.home, tmp: dirs.tmp }),
|
|
191
|
+
PATH: [...(mocks === undefined ? [] : [mocks.forwarderDir]), ...pathEntries].join(delimiter),
|
|
186
192
|
};
|
|
187
193
|
return { env, policy };
|
|
188
194
|
}
|
|
@@ -219,41 +225,6 @@ async function persistLogin(login, selected) {
|
|
|
219
225
|
}
|
|
220
226
|
}
|
|
221
227
|
}
|
|
222
|
-
/**
|
|
223
|
-
* The real binaries behind PATH targets whose rules never pass. Besides the first PATH match,
|
|
224
|
-
* the active developer directory is included because `/usr/bin/make` and `/usr/bin/git` are
|
|
225
|
-
* shims that start the toolchain's own copy.
|
|
226
|
-
*/
|
|
227
|
-
export async function deniedBinaries(targets, pathEntries, developerDir) {
|
|
228
|
-
const denied = [];
|
|
229
|
-
for (const target of targets) {
|
|
230
|
-
const candidates = [
|
|
231
|
-
...pathEntries.map((entry) => join(entry, target)),
|
|
232
|
-
...(developerDir === undefined ? [] : [join(developerDir, "usr", "bin", target)]),
|
|
233
|
-
];
|
|
234
|
-
for (const candidate of candidates) {
|
|
235
|
-
try {
|
|
236
|
-
if ((await stat(candidate)).isFile())
|
|
237
|
-
denied.push(candidate, await realpath(candidate));
|
|
238
|
-
}
|
|
239
|
-
catch {
|
|
240
|
-
// Not installed here.
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return denied;
|
|
245
|
-
}
|
|
246
|
-
/** The directory the platform shims start tools from, when a developer directory is selected. */
|
|
247
|
-
async function activeDeveloperDir() {
|
|
248
|
-
try {
|
|
249
|
-
const { stdout } = await promisify(execFile)("/usr/bin/xcode-select", ["-p"]);
|
|
250
|
-
const path = stdout.trim();
|
|
251
|
-
return path.length === 0 ? undefined : path;
|
|
252
|
-
}
|
|
253
|
-
catch {
|
|
254
|
-
return undefined;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
228
|
/** Canonicalize existing ancestors too, without creating a first-login directory. */
|
|
258
229
|
async function canonicalPath(path) {
|
|
259
230
|
try {
|
|
@@ -267,8 +238,7 @@ async function canonicalPath(path) {
|
|
|
267
238
|
}
|
|
268
239
|
async function readRegular(root, file) {
|
|
269
240
|
const path = await resolveWorkspacePath(root, file);
|
|
270
|
-
|
|
271
|
-
const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
241
|
+
const handle = await openRegularFileNoFollow(path);
|
|
272
242
|
try {
|
|
273
243
|
if (!(await handle.stat()).isFile())
|
|
274
244
|
throw new ConfigError(`login path is not a regular file: ${file}`);
|
|
@@ -2,7 +2,7 @@ import { methods } from "@agentclientprotocol/sdk";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { loadImplementationParameters } from "../../engine/authoring.js";
|
|
4
4
|
import { resolveAuthoringAsset } from "../../engine/config.js";
|
|
5
|
-
import { spawnSupervised } from "../../platform/
|
|
5
|
+
import { spawnSupervised } from "../../platform/index.js";
|
|
6
6
|
import { agentSchema } from "./agent.js";
|
|
7
7
|
import { harnessEnvironment, prepareHarnessHome, resolveHarnessHome } from "./environment.js";
|
|
8
8
|
import { withSession } from "./session.js";
|
|
@@ -31,6 +31,7 @@ class AcpRunner {
|
|
|
31
31
|
#command;
|
|
32
32
|
#home;
|
|
33
33
|
homeFiles;
|
|
34
|
+
concurrencyKey;
|
|
34
35
|
#config;
|
|
35
36
|
#process;
|
|
36
37
|
#copyBack;
|
|
@@ -41,6 +42,9 @@ class AcpRunner {
|
|
|
41
42
|
this.#command = command;
|
|
42
43
|
this.#home = home;
|
|
43
44
|
this.homeFiles = home.login?.files ?? [];
|
|
45
|
+
if (home.login !== undefined) {
|
|
46
|
+
this.concurrencyKey = home.login.dir;
|
|
47
|
+
}
|
|
44
48
|
this.#config = config;
|
|
45
49
|
}
|
|
46
50
|
/** Place the agent file's HOME content and login state before the case's own `~/` entries. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ClientContext, type InitializeResponse, type NewSessionResponse, type SessionUpdate } from "@agentclientprotocol/sdk";
|
|
2
|
-
import type { SupervisedProcess } from "../../platform/
|
|
2
|
+
import type { SupervisedProcess } from "../../platform/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Initialize the agent, create one session in `cwd` and run `use` while the
|
|
5
5
|
* connection is open. Fails when the agent exits or the connection breaks.
|
package/dist/runners/pi/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { z } from "zod";
|
|
|
4
4
|
import { ConfigError, errorMessage, resolveAuthoringAsset } from "../../engine/config.js";
|
|
5
5
|
import { authoringCopyFilter } from "../../engine/files.js";
|
|
6
6
|
import { nonEmptyTrimmedString } from "../../engine/params.js";
|
|
7
|
-
import {
|
|
7
|
+
import { assertSandboxAvailable } from "../../platform/index.js";
|
|
8
8
|
import { thinkingSchema } from "./params.js";
|
|
9
9
|
import { invokePi, resolvePiExecutable } from "./session.js";
|
|
10
10
|
const piRunnerParamsSchema = z.strictObject({
|
|
@@ -21,7 +21,7 @@ export const piRunner = {
|
|
|
21
21
|
async create(params, context) {
|
|
22
22
|
await resolvePiExecutable(params.executable);
|
|
23
23
|
await assertSkillsAvailable(params.skills, context.authoringDir);
|
|
24
|
-
|
|
24
|
+
assertSandboxAvailable();
|
|
25
25
|
return new PiRunner(params, context.authoringDir);
|
|
26
26
|
},
|
|
27
27
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SandboxPolicy } from "../../platform/
|
|
1
|
+
import { type SandboxPolicy } from "../../platform/index.js";
|
|
2
2
|
import { PiProcess } from "./rpc.js";
|
|
3
3
|
export declare const THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
4
4
|
export type ThinkingLevel = (typeof THINKING_LEVELS)[number];
|