@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.
Files changed (79) hide show
  1. package/README.md +27 -18
  2. package/dist/checkers/file/index.js +181 -13
  3. package/dist/checkers/judge/index.d.ts +1 -1
  4. package/dist/checkers/judge/index.js +243 -31
  5. package/dist/checkers/judge/prompt.d.ts +4 -3
  6. package/dist/checkers/judge/prompt.js +22 -3
  7. package/dist/cli.js +171 -35
  8. package/dist/engine/authoring.js +108 -13
  9. package/dist/engine/check-runner.js +18 -3
  10. package/dist/engine/check-sandbox.js +9 -6
  11. package/dist/engine/config.d.ts +31 -2
  12. package/dist/engine/config.js +16 -10
  13. package/dist/engine/env-source.js +82 -14
  14. package/dist/engine/files.d.ts +2 -5
  15. package/dist/engine/files.js +4 -6
  16. package/dist/engine/mocks.js +72 -46
  17. package/dist/engine/params.d.ts +2 -0
  18. package/dist/engine/params.js +10 -0
  19. package/dist/engine/registry.d.ts +11 -0
  20. package/dist/engine/report.js +43 -8
  21. package/dist/engine/results.d.ts +7 -0
  22. package/dist/engine/results.js +9 -6
  23. package/dist/engine/run.d.ts +4 -1
  24. package/dist/engine/run.js +171 -28
  25. package/dist/engine/skills.js +12 -5
  26. package/dist/engine/view.d.ts +1 -1
  27. package/dist/engine/view.js +125 -10
  28. package/dist/engine/workspace.d.ts +7 -0
  29. package/dist/engine/workspace.js +37 -27
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +2 -2
  32. package/dist/platform/index.d.ts +31 -0
  33. package/dist/platform/index.js +88 -0
  34. package/dist/platform/linux/index.d.ts +2 -0
  35. package/dist/platform/linux/index.js +40 -0
  36. package/dist/platform/linux/launch.d.ts +8 -0
  37. package/dist/platform/linux/launch.js +25 -0
  38. package/dist/platform/linux/policy.d.ts +46 -0
  39. package/dist/platform/linux/policy.js +388 -0
  40. package/dist/platform/linux/supervise.d.ts +8 -0
  41. package/dist/platform/linux/supervise.js +124 -0
  42. package/dist/platform/macos/index.d.ts +2 -0
  43. package/dist/platform/macos/index.js +59 -0
  44. package/dist/platform/macos/launch.d.ts +2 -8
  45. package/dist/platform/macos/launch.js +5 -3
  46. package/dist/platform/macos/policy.d.ts +3 -21
  47. package/dist/platform/macos/policy.js +5 -2
  48. package/dist/platform/macos/supervise.d.ts +3 -25
  49. package/dist/platform/posix-forwarder-client.mjs +129 -0
  50. package/dist/platform/posix-forwarder.sh +9 -0
  51. package/dist/platform/posix-helpers.d.ts +22 -0
  52. package/dist/platform/posix-helpers.js +97 -0
  53. package/dist/platform/types.d.ts +118 -0
  54. package/dist/platform/types.js +1 -0
  55. package/dist/platform/windows/forwarder-client.mjs +165 -0
  56. package/dist/platform/windows/forwarder.cmd +3 -0
  57. package/dist/platform/windows/forwarder.ps1 +2 -0
  58. package/dist/platform/windows/forwarder.sh +2 -0
  59. package/dist/platform/windows/index.d.ts +2 -0
  60. package/dist/platform/windows/index.js +225 -0
  61. package/dist/platform/windows/launch.d.ts +3 -0
  62. package/dist/platform/windows/launch.js +30 -0
  63. package/dist/platform/windows/policy.d.ts +17 -0
  64. package/dist/platform/windows/policy.js +155 -0
  65. package/dist/platform/windows/setup.ps1 +112 -0
  66. package/dist/platform/windows/supervise.d.ts +2 -0
  67. package/dist/platform/windows/supervise.js +142 -0
  68. package/dist/platform/windows/win-sandbox.exe +0 -0
  69. package/dist/runners/acp/commands.js +2 -3
  70. package/dist/runners/acp/environment.d.ts +1 -7
  71. package/dist/runners/acp/environment.js +18 -48
  72. package/dist/runners/acp/index.js +5 -1
  73. package/dist/runners/acp/session.d.ts +1 -1
  74. package/dist/runners/pi/index.js +2 -2
  75. package/dist/runners/pi/session.d.ts +1 -1
  76. package/dist/runners/pi/session.js +27 -44
  77. package/dist/runners/pi/supervisor.js +1 -0
  78. package/package.json +5 -3
  79. package/dist/engine/forwarder.sh +0 -61
@@ -1,12 +1,10 @@
1
- import { access, mkdir, readFile, realpath, stat, writeFile } from "node:fs/promises";
2
- import { constants } from "node:fs";
3
- import { basename, dirname, join, resolve } from "node:path";
1
+ import { mkdir, readFile, realpath, stat, writeFile } from "node:fs/promises";
2
+ import { basename, delimiter, dirname, join, resolve, sep } from "node:path";
4
3
  import { fileURLToPath } from "node:url";
5
4
  import { ConfigError, errorMessage } from "../../engine/config.js";
6
5
  import { truncate } from "../../engine/truncate.js";
7
6
  import { siblingRuntimeModule } from "../../engine/runtime-assets.js";
8
- import { spawnSandboxed } from "../../platform/macos/launch.js";
9
- import { writeSeatbeltPolicy } from "../../platform/macos/policy.js";
7
+ import { createSandboxPolicy, dirEnv, executableExtensions, isExecutableAccessible, spawnSandboxed, SYSTEM_PATH, usesPiShellWrapper, wrapExecutableCommand, } from "../../platform/index.js";
10
8
  import { PiProcess, PiRpcError } from "./rpc.js";
11
9
  export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
12
10
  export class PiSessionError extends Error {
@@ -22,7 +20,7 @@ export async function resolvePiExecutable(executable) {
22
20
  if (executable.length === 0) {
23
21
  throw new ConfigError("pi executable must be a non-empty string");
24
22
  }
25
- const candidate = executable.includes("/") ? resolve(executable) : await findOnPath(executable);
23
+ const candidate = executable.includes("/") || executable.includes(sep) ? resolve(executable) : await findOnPath(executable);
26
24
  if (candidate === undefined) {
27
25
  throw new ConfigError(`pi executable not found on PATH: ${executable}`);
28
26
  }
@@ -102,7 +100,7 @@ export async function createPiProcess(config) {
102
100
  await writeFile(supervisorPath, await readFile(supervisorSource, "utf8"), { mode: 0o700 });
103
101
  await writeFile(safeGroupPath, await readFile(safeGroupSource, "utf8"), { mode: 0o700 });
104
102
  let shellPath;
105
- if (config.tools !== null) {
103
+ if (config.tools !== null && usesPiShellWrapper) {
106
104
  shellPath = join(toolsDir, "shell-wrapper.sh");
107
105
  await writeFile(shellPath, await readFile(new URL("./shell-wrapper.sh", import.meta.url), "utf8"), { mode: 0o700 });
108
106
  await mkdir(shellStateDirectory(config), { recursive: true, mode: 0o700 });
@@ -112,35 +110,24 @@ export async function createPiProcess(config) {
112
110
  await writeApiKeyConfig(config.dirs.configDir, config);
113
111
  }
114
112
  const policy = await buildPolicy(executable, config);
115
- const policyPath = await writeSeatbeltPolicy(config.dirs.scratchDir, policy);
116
113
  const args = buildPiArgs(config);
117
114
  const env = buildEnvironment(config);
118
115
  const nodeExecutable = await realpath(process.execPath);
119
- return new PiProcess({
120
- spawn: () => spawnSandboxed({
121
- policyPath,
122
- command: nodeExecutable,
123
- args: [supervisorPath, executable, ...args],
124
- cwd: config.dirs.workspaceDir,
125
- env,
126
- }),
116
+ const [wrappedExecutable, ...wrappedArgs] = wrapExecutableCommand(executable, args);
117
+ const child = await spawnSandboxed({
118
+ policy,
119
+ policyDirectory: config.dirs.scratchDir,
120
+ command: nodeExecutable,
121
+ args: [supervisorPath, wrappedExecutable, ...wrappedArgs],
122
+ cwd: config.dirs.workspaceDir,
123
+ env,
127
124
  });
125
+ return new PiProcess({ spawn: () => child });
128
126
  }
129
127
  export async function buildPolicy(executable, config) {
130
128
  const nodeExecutable = await realpath(process.execPath);
131
129
  const nodeDirectory = dirname(nodeExecutable);
132
- const readableRoots = new Set([
133
- "/System",
134
- "/usr",
135
- "/bin",
136
- "/sbin",
137
- "/private/etc",
138
- "/Library",
139
- "/dev",
140
- "/private/var/select",
141
- "/private/var/db/timezone",
142
- nodeDirectory,
143
- ]);
130
+ const readableRoots = new Set([nodeDirectory]);
144
131
  if (basename(nodeDirectory) === "bin") {
145
132
  readableRoots.add(dirname(nodeDirectory));
146
133
  }
@@ -156,14 +143,13 @@ export async function buildPolicy(executable, config) {
156
143
  readableRoots.add(nodeModulesRoot);
157
144
  }
158
145
  readableRoots.add(shellToolsDirectory(config));
159
- return {
146
+ return createSandboxPolicy({
160
147
  writableRoots: [config.dirs.workspaceDir, config.dirs.homeDir, config.dirs.configDir, config.dirs.scratchDir],
161
148
  readableRoots: [...readableRoots],
162
- // The resolver's fallback stats `/etc` and `/var` (symlinks to `/private/...`) before it
163
- // reads `/private/etc/resolv.conf`; without them a sandboxed Node fails DNS with ENOTFOUND.
164
- readableFiles: [executable, "/etc", "/var"],
149
+ readableFiles: [executable],
165
150
  allowNetwork: config.allowNetwork,
166
- };
151
+ interactive: false,
152
+ });
167
153
  }
168
154
  function buildPiArgs(config) {
169
155
  const args = [
@@ -189,9 +175,8 @@ function buildPiArgs(config) {
189
175
  function buildEnvironment(config) {
190
176
  const nodeDirectory = dirname(process.execPath);
191
177
  const env = {
192
- PATH: [nodeDirectory, "/usr/bin", "/bin", "/usr/sbin", "/sbin"].join(":"),
193
- HOME: config.dirs.homeDir,
194
- TMPDIR: config.dirs.scratchDir,
178
+ PATH: [nodeDirectory, ...SYSTEM_PATH].join(delimiter),
179
+ ...dirEnv({ home: config.dirs.homeDir, tmp: config.dirs.scratchDir }),
195
180
  TMP: config.dirs.scratchDir,
196
181
  TEMP: config.dirs.scratchDir,
197
182
  PI_CODING_AGENT_DIR: config.dirs.configDir,
@@ -228,17 +213,15 @@ async function writeIsolatedSettings(configDir, shellPath) {
228
213
  }
229
214
  async function findOnPath(name) {
230
215
  const path = process.env.PATH ?? "";
231
- for (const directory of path.split(":")) {
216
+ for (const directory of path.split(delimiter)) {
232
217
  if (directory.length === 0) {
233
218
  continue;
234
219
  }
235
- const candidate = join(directory, name);
236
- try {
237
- await access(candidate, constants.X_OK);
238
- return candidate;
239
- }
240
- catch {
241
- // Keep searching.
220
+ for (const ext of executableExtensions) {
221
+ const candidate = join(directory, `${name}${ext}`);
222
+ if (await isExecutableAccessible(candidate)) {
223
+ return candidate;
224
+ }
242
225
  }
243
226
  }
244
227
  return undefined;
@@ -72,6 +72,7 @@ function finish(code) {
72
72
  const child = spawn(command, args, {
73
73
  stdio: ["inherit", "inherit", "inherit"],
74
74
  env: process.env,
75
+ windowsHide: true,
75
76
  });
76
77
  let stopping = false;
77
78
  function stop() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lelouchhe/agent-evals",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "A toolkit for evaluating AI agent systems.",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "format": "prettier --write .",
28
28
  "format:check": "prettier --check .",
29
29
  "typecheck": "tsc --noEmit",
30
- "test": "node --test --test-timeout=30000",
30
+ "test": "node scripts/test.mjs",
31
31
  "test:package": "node --test --test-timeout=180000 tests/package-install.ts",
32
32
  "pretest": "npm run build",
33
33
  "check": "npm run lint && npm run format:check && npm run typecheck && npm test",
@@ -74,6 +74,8 @@
74
74
  "access": "public"
75
75
  },
76
76
  "os": [
77
- "darwin"
77
+ "darwin",
78
+ "linux",
79
+ "win32"
78
80
  ]
79
81
  }
@@ -1,61 +0,0 @@
1
- #!/bin/sh
2
- self=$0
3
- bindir=__BINDIR__
4
- socket=__SOCKET__
5
- fault=__FAULT__
6
- encode() {
7
- printf '%s' "$1" | /usr/bin/base64 | /usr/bin/tr -d '\n'
8
- printf '\n'
9
- }
10
- # Canonicalise our own path so the host can tell which forwarder directory we came from.
11
- folder=${self%/*}
12
- [ "$folder" = "$self" ] && folder=.
13
- self=$(cd "$folder" && pwd -P)/${self##*/}
14
- reply=$(
15
- {
16
- encode "$self"
17
- for argument in "$@"; do
18
- encode "$argument"
19
- done
20
- } | /usr/bin/nc -U "$socket"
21
- ) || {
22
- printf '%s: Service unavailable\n' "${self##*/}" >&2
23
- printf '%s\n' "${self##*/}" >>"$fault" 2>/dev/null
24
- exit 126
25
- }
26
- IFS=' ' read -r kind code out err <<EOF
27
- $reply
28
- EOF
29
- if [ "$kind" = pass ]; then
30
- name=${self##*/}
31
- case $self in
32
- "$bindir"/*)
33
- oldifs=$IFS
34
- IFS=:
35
- set -f
36
- for folder in $PATH; do
37
- candidate=$folder/$name
38
- [ -f "$candidate" ] || continue
39
- [ -x "$candidate" ] || continue
40
- # Skip our own entry even when PATH spells the directory differently.
41
- if [ "$(cd "$folder" 2>/dev/null && pwd -P)/$name" = "$self" ]; then continue; fi
42
- set +f
43
- IFS=$oldifs
44
- exec "$candidate" "$@"
45
- done
46
- set +f
47
- IFS=$oldifs
48
- ;;
49
- *)
50
- real=${self%/*}/.${name}
51
- if [ -x "$real" ]; then exec "$real" "$@"; fi
52
- ;;
53
- esac
54
- printf '%s: Operation not permitted\n' "$name" >&2
55
- exit 126
56
- fi
57
- [ "$out" = - ] && out=""
58
- [ "$err" = - ] && err=""
59
- if [ -n "$out" ]; then printf '%s' "$out" | /usr/bin/base64 -D; fi
60
- if [ -n "$err" ]; then printf '%s' "$err" | /usr/bin/base64 -D >&2; fi
61
- exit "$code"