@lelouchhe/agent-evals 0.0.0-stage → 0.2.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/.env.example +27 -0
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/dist/checkers/file/index.d.ts +26 -0
- package/dist/checkers/file/index.js +396 -0
- package/dist/checkers/judge/index.d.ts +20 -0
- package/dist/checkers/judge/index.js +474 -0
- package/dist/checkers/judge/prompt.d.ts +19 -0
- package/dist/checkers/judge/prompt.js +55 -0
- package/dist/checkers/judge/trace.d.ts +6 -0
- package/dist/checkers/judge/trace.js +41 -0
- package/dist/checkers/mock/index.d.ts +18 -0
- package/dist/checkers/mock/index.js +127 -0
- package/dist/checkers/shell/index.d.ts +10 -0
- package/dist/checkers/shell/index.js +61 -0
- package/dist/checkers/trace/index.d.ts +22 -0
- package/dist/checkers/trace/index.js +183 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +453 -0
- package/dist/engine/authoring.d.ts +24 -0
- package/dist/engine/authoring.js +356 -0
- package/dist/engine/check-runner.d.ts +1 -0
- package/dist/engine/check-runner.js +127 -0
- package/dist/engine/check-sandbox.d.ts +18 -0
- package/dist/engine/check-sandbox.js +171 -0
- package/dist/engine/config.d.ts +171 -0
- package/dist/engine/config.js +368 -0
- package/dist/engine/env-source.d.ts +10 -0
- package/dist/engine/env-source.js +114 -0
- package/dist/engine/files.d.ts +84 -0
- package/dist/engine/files.js +304 -0
- package/dist/engine/forwarder.sh +61 -0
- package/dist/engine/ignore.d.ts +29 -0
- package/dist/engine/ignore.js +67 -0
- package/dist/engine/messages.d.ts +8 -0
- package/dist/engine/messages.js +9 -0
- package/dist/engine/mock-match.d.ts +44 -0
- package/dist/engine/mock-match.js +104 -0
- package/dist/engine/mocks.d.ts +35 -0
- package/dist/engine/mocks.js +336 -0
- package/dist/engine/params.d.ts +18 -0
- package/dist/engine/params.js +96 -0
- package/dist/engine/placement.d.ts +26 -0
- package/dist/engine/placement.js +107 -0
- package/dist/engine/regex.d.ts +10 -0
- package/dist/engine/regex.js +16 -0
- package/dist/engine/registry.d.ts +243 -0
- package/dist/engine/registry.js +127 -0
- package/dist/engine/report.d.ts +17 -0
- package/dist/engine/report.js +420 -0
- package/dist/engine/results.d.ts +50 -0
- package/dist/engine/results.js +42 -0
- package/dist/engine/run.d.ts +50 -0
- package/dist/engine/run.js +710 -0
- package/dist/engine/runtime-assets.d.ts +6 -0
- package/dist/engine/runtime-assets.js +11 -0
- package/dist/engine/skills.d.ts +49 -0
- package/dist/engine/skills.js +270 -0
- package/dist/engine/truncate.d.ts +3 -0
- package/dist/engine/truncate.js +7 -0
- package/dist/engine/values.d.ts +18 -0
- package/dist/engine/values.js +75 -0
- package/dist/engine/view.d.ts +10 -0
- package/dist/engine/view.js +150 -0
- package/dist/engine/workspace.d.ts +63 -0
- package/dist/engine/workspace.js +305 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +7 -0
- package/dist/platform/macos/launch.d.ts +13 -0
- package/dist/platform/macos/launch.js +14 -0
- package/dist/platform/macos/policy.d.ts +33 -0
- package/dist/platform/macos/policy.js +131 -0
- package/dist/platform/macos/supervise.d.ts +26 -0
- package/dist/platform/macos/supervise.js +98 -0
- package/dist/platform/macos/supervisor.sh +13 -0
- package/dist/runners/acp/agent.d.ts +17 -0
- package/dist/runners/acp/agent.js +38 -0
- package/dist/runners/acp/commands.d.ts +2 -0
- package/dist/runners/acp/commands.js +112 -0
- package/dist/runners/acp/environment.d.ts +71 -0
- package/dist/runners/acp/environment.js +280 -0
- package/dist/runners/acp/index.d.ts +21 -0
- package/dist/runners/acp/index.js +135 -0
- package/dist/runners/acp/session.d.ts +7 -0
- package/dist/runners/acp/session.js +48 -0
- package/dist/runners/acp/trace.d.ts +23 -0
- package/dist/runners/acp/trace.js +44 -0
- package/dist/runners/acp/usage.d.ts +12 -0
- package/dist/runners/acp/usage.js +56 -0
- package/dist/runners/noop/index.d.ts +12 -0
- package/dist/runners/noop/index.js +22 -0
- package/dist/runners/pi/index.d.ts +21 -0
- package/dist/runners/pi/index.js +116 -0
- package/dist/runners/pi/params.d.ts +10 -0
- package/dist/runners/pi/params.js +3 -0
- package/dist/runners/pi/rpc.d.ts +30 -0
- package/dist/runners/pi/rpc.js +341 -0
- package/dist/runners/pi/safe-process-group.d.ts +7 -0
- package/dist/runners/pi/safe-process-group.js +13 -0
- package/dist/runners/pi/session.d.ts +56 -0
- package/dist/runners/pi/session.js +298 -0
- package/dist/runners/pi/shell-wrapper.sh +46 -0
- package/dist/runners/pi/supervisor.d.ts +1 -0
- package/dist/runners/pi/supervisor.js +101 -0
- package/package.json +77 -4
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { errorMessage } from "../../engine/config.js";
|
|
2
|
+
import { truncate } from "../../engine/truncate.js";
|
|
3
|
+
const MAX_PROTOCOL_LINE_BYTES = 2 * 1024 * 1024;
|
|
4
|
+
const MAX_STDERR_CHARS = 16 * 1024;
|
|
5
|
+
const DEFAULT_COMMAND_TIMEOUT_MS = 30_000;
|
|
6
|
+
const DEFAULT_STOP_GRACE_MS = 3_000;
|
|
7
|
+
export class PiRpcError extends Error {
|
|
8
|
+
diagnostics;
|
|
9
|
+
constructor(message, diagnostics = []) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "PiRpcError";
|
|
12
|
+
this.diagnostics = diagnostics;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Minimal strict-JSONL client for Pi RPC mode. */
|
|
16
|
+
export class PiProcess {
|
|
17
|
+
#child;
|
|
18
|
+
#commandTimeoutMs;
|
|
19
|
+
#stopGraceMs;
|
|
20
|
+
#pending = new Map();
|
|
21
|
+
#waiters = new Set();
|
|
22
|
+
#protocolErrors = [];
|
|
23
|
+
#errorEvents = [];
|
|
24
|
+
#buffer = Buffer.alloc(0);
|
|
25
|
+
#stderr = "";
|
|
26
|
+
#nextId = 0;
|
|
27
|
+
#exit;
|
|
28
|
+
#exitResolve = () => { };
|
|
29
|
+
#exitPromise;
|
|
30
|
+
#startupError;
|
|
31
|
+
#closed = false;
|
|
32
|
+
#stopped = false;
|
|
33
|
+
#stopPromise;
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.#commandTimeoutMs = options.commandTimeoutMs ?? DEFAULT_COMMAND_TIMEOUT_MS;
|
|
36
|
+
this.#stopGraceMs = options.stopGraceMs ?? DEFAULT_STOP_GRACE_MS;
|
|
37
|
+
this.#exitPromise = new Promise((resolve) => {
|
|
38
|
+
this.#exitResolve = resolve;
|
|
39
|
+
});
|
|
40
|
+
this.#child = options.spawn();
|
|
41
|
+
this.#child.stdout.on("data", (chunk) => this.#onStdout(chunk));
|
|
42
|
+
this.#child.stderr.on("data", (chunk) => this.#onStderr(chunk));
|
|
43
|
+
this.#child.on("error", (error) => {
|
|
44
|
+
this.#startupError = new Error(`Pi process failed: ${errorMessage(error)}`);
|
|
45
|
+
this.#failAll(this.#startupError);
|
|
46
|
+
});
|
|
47
|
+
this.#child.on("exit", (code, signal) => {
|
|
48
|
+
this.#exit = { code, signal };
|
|
49
|
+
this.#exitResolve(this.#exit);
|
|
50
|
+
if (!this.#stopped) {
|
|
51
|
+
this.#failAll(new Error(`Pi exited unexpectedly (${describeExit(code, signal)})`));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
get stderrTail() {
|
|
56
|
+
return this.#stderr;
|
|
57
|
+
}
|
|
58
|
+
get protocolErrors() {
|
|
59
|
+
return this.#protocolErrors;
|
|
60
|
+
}
|
|
61
|
+
get errorEvents() {
|
|
62
|
+
return this.#errorEvents;
|
|
63
|
+
}
|
|
64
|
+
get exited() {
|
|
65
|
+
return this.#exit !== undefined;
|
|
66
|
+
}
|
|
67
|
+
get pid() {
|
|
68
|
+
return this.#child.pid;
|
|
69
|
+
}
|
|
70
|
+
/** Send a command and resolve its matching successful response. */
|
|
71
|
+
async command(type, payload = {}, timeoutMs = this.#commandTimeoutMs) {
|
|
72
|
+
if (this.#startupError !== undefined) {
|
|
73
|
+
throw this.#withDiagnostics(this.#startupError.message);
|
|
74
|
+
}
|
|
75
|
+
if (this.#closed) {
|
|
76
|
+
throw this.#withDiagnostics("cannot send a command after the Pi process was closed");
|
|
77
|
+
}
|
|
78
|
+
const id = `req-${++this.#nextId}`;
|
|
79
|
+
const response = new Promise((resolve, reject) => {
|
|
80
|
+
const timer = setTimeout(() => {
|
|
81
|
+
this.#pending.delete(id);
|
|
82
|
+
reject(this.#withDiagnostics(`Pi did not respond to "${type}" within ${timeoutMs}ms`));
|
|
83
|
+
}, timeoutMs);
|
|
84
|
+
this.#pending.set(id, { resolve, reject, timer });
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
await this.#writeLine({ id, type, ...payload });
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
const pending = this.#pending.get(id);
|
|
91
|
+
if (pending !== undefined) {
|
|
92
|
+
clearTimeout(pending.timer);
|
|
93
|
+
this.#pending.delete(id);
|
|
94
|
+
pending.reject(this.#withDiagnostics(`could not send "${type}" to Pi: ${errorMessage(error)}`));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return response;
|
|
98
|
+
}
|
|
99
|
+
/** Register a waiter before issuing the command that triggers the event. */
|
|
100
|
+
waitForEvent(type, timeoutMs, signal) {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
const cleanup = () => {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
signal?.removeEventListener("abort", onAbort);
|
|
105
|
+
this.#waiters.delete(waiter);
|
|
106
|
+
};
|
|
107
|
+
const timer = setTimeout(() => {
|
|
108
|
+
cleanup();
|
|
109
|
+
reject(this.#withDiagnostics(`Pi did not emit "${type}" within ${timeoutMs}ms`));
|
|
110
|
+
}, timeoutMs);
|
|
111
|
+
const waiter = {
|
|
112
|
+
type,
|
|
113
|
+
resolve: (event) => {
|
|
114
|
+
cleanup();
|
|
115
|
+
resolve(event);
|
|
116
|
+
},
|
|
117
|
+
reject: (error) => {
|
|
118
|
+
cleanup();
|
|
119
|
+
reject(error);
|
|
120
|
+
},
|
|
121
|
+
timer,
|
|
122
|
+
};
|
|
123
|
+
const onAbort = () => {
|
|
124
|
+
cleanup();
|
|
125
|
+
reject(this.#withDiagnostics(`waiting for "${type}" was aborted`));
|
|
126
|
+
};
|
|
127
|
+
if (signal?.aborted === true) {
|
|
128
|
+
cleanup();
|
|
129
|
+
reject(this.#withDiagnostics(`waiting for "${type}" was aborted`));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
133
|
+
this.#waiters.add(waiter);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** Close stdin, then escalate through SIGTERM and SIGKILL for the process group. */
|
|
137
|
+
stop() {
|
|
138
|
+
this.#stopPromise ??= this.#stop();
|
|
139
|
+
return this.#stopPromise;
|
|
140
|
+
}
|
|
141
|
+
async #stop() {
|
|
142
|
+
this.#stopped = true;
|
|
143
|
+
this.#closed = true;
|
|
144
|
+
this.#failAll(this.#withDiagnostics("Pi process was stopped"));
|
|
145
|
+
try {
|
|
146
|
+
this.#child.stdin.end();
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// The process may already have closed its stdin.
|
|
150
|
+
}
|
|
151
|
+
if (this.#exit !== undefined) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (await this.#waitForExit(this.#stopGraceMs)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.#signalGroup("SIGTERM");
|
|
158
|
+
if (await this.#waitForExit(this.#stopGraceMs)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.#signalGroup("SIGKILL");
|
|
162
|
+
await this.#waitForExit(this.#stopGraceMs);
|
|
163
|
+
}
|
|
164
|
+
#onStdout(chunk) {
|
|
165
|
+
this.#buffer = this.#buffer.length === 0 ? chunk : Buffer.concat([this.#buffer, chunk]);
|
|
166
|
+
while (true) {
|
|
167
|
+
const newline = this.#buffer.indexOf(0x0a);
|
|
168
|
+
if (newline === -1) {
|
|
169
|
+
if (this.#buffer.length > MAX_PROTOCOL_LINE_BYTES) {
|
|
170
|
+
this.#protocolFailure("Pi emitted a protocol line larger than the 2 MiB limit");
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
let line = this.#buffer.subarray(0, newline);
|
|
175
|
+
this.#buffer = this.#buffer.subarray(newline + 1);
|
|
176
|
+
if (line.length > 0 && line[line.length - 1] === 0x0d) {
|
|
177
|
+
line = line.subarray(0, line.length - 1);
|
|
178
|
+
}
|
|
179
|
+
if (line.length === 0) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
this.#onRecord(line.toString("utf8"));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
#onRecord(line) {
|
|
186
|
+
let record;
|
|
187
|
+
try {
|
|
188
|
+
const parsed = JSON.parse(line);
|
|
189
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
190
|
+
throw new Error("record is not a JSON object");
|
|
191
|
+
}
|
|
192
|
+
record = parsed;
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
this.#protocolFailure(`invalid JSON from Pi: ${errorMessage(error)} (line: ${truncate(line, 160)})`);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const type = record.type;
|
|
199
|
+
if (type === "response") {
|
|
200
|
+
this.#onResponse(record);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (typeof type !== "string") {
|
|
204
|
+
this.#protocolFailure(`Pi record has no type (line: ${truncate(line, 160)})`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (type === "error") {
|
|
208
|
+
this.#errorEvents.push(describeErrorEvent(record));
|
|
209
|
+
}
|
|
210
|
+
const event = record;
|
|
211
|
+
for (const waiter of [...this.#waiters]) {
|
|
212
|
+
if (waiter.type !== type) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
clearTimeout(waiter.timer);
|
|
216
|
+
this.#waiters.delete(waiter);
|
|
217
|
+
waiter.resolve(event);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
#onResponse(record) {
|
|
221
|
+
const id = record.id;
|
|
222
|
+
if (typeof id !== "string") {
|
|
223
|
+
this.#protocolFailure(`Pi response has no request id: ${truncate(JSON.stringify(record), 160)}`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const pending = this.#pending.get(id);
|
|
227
|
+
if (pending === undefined) {
|
|
228
|
+
this.#protocolErrors.push(`response for unknown request id ${id}`);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
clearTimeout(pending.timer);
|
|
232
|
+
this.#pending.delete(id);
|
|
233
|
+
if (record.success === true) {
|
|
234
|
+
pending.resolve(record.data);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
pending.reject(this.#withDiagnostics(`Pi command failed: ${String(record.error ?? "unknown error")}`));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
#protocolFailure(message) {
|
|
241
|
+
this.#protocolErrors.push(message);
|
|
242
|
+
this.#buffer = Buffer.alloc(0);
|
|
243
|
+
this.#failAll(new PiRpcError(message, this.#diagnostics()));
|
|
244
|
+
}
|
|
245
|
+
#failAll(error) {
|
|
246
|
+
for (const [id, pending] of this.#pending) {
|
|
247
|
+
clearTimeout(pending.timer);
|
|
248
|
+
pending.reject(error);
|
|
249
|
+
this.#pending.delete(id);
|
|
250
|
+
}
|
|
251
|
+
for (const waiter of [...this.#waiters]) {
|
|
252
|
+
clearTimeout(waiter.timer);
|
|
253
|
+
waiter.reject(error);
|
|
254
|
+
this.#waiters.delete(waiter);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
async #writeLine(record) {
|
|
258
|
+
const line = JSON.stringify(record) + "\n";
|
|
259
|
+
const stdin = this.#child.stdin;
|
|
260
|
+
if (stdin.destroyed || !stdin.writable) {
|
|
261
|
+
throw new Error("stdin is closed");
|
|
262
|
+
}
|
|
263
|
+
if (stdin.write(line)) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
await new Promise((resolve, reject) => {
|
|
267
|
+
const onDrain = () => {
|
|
268
|
+
cleanup();
|
|
269
|
+
resolve();
|
|
270
|
+
};
|
|
271
|
+
const onError = (error) => {
|
|
272
|
+
cleanup();
|
|
273
|
+
reject(error);
|
|
274
|
+
};
|
|
275
|
+
const cleanup = () => {
|
|
276
|
+
stdin.off("drain", onDrain);
|
|
277
|
+
stdin.off("error", onError);
|
|
278
|
+
};
|
|
279
|
+
stdin.once("drain", onDrain);
|
|
280
|
+
stdin.once("error", onError);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
#onStderr(chunk) {
|
|
284
|
+
this.#stderr = (this.#stderr + chunk.toString("utf8")).slice(-MAX_STDERR_CHARS);
|
|
285
|
+
}
|
|
286
|
+
#signalGroup(signal) {
|
|
287
|
+
const pid = this.#child.pid;
|
|
288
|
+
if (pid === undefined) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
process.kill(-pid, signal);
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
try {
|
|
296
|
+
this.#child.kill(signal);
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
// The process is already gone.
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async #waitForExit(timeoutMs) {
|
|
304
|
+
if (this.#exit !== undefined) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
let timer;
|
|
308
|
+
const timeout = new Promise((resolve) => {
|
|
309
|
+
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
310
|
+
});
|
|
311
|
+
try {
|
|
312
|
+
return await Promise.race([this.#exitPromise.then(() => true), timeout]);
|
|
313
|
+
}
|
|
314
|
+
finally {
|
|
315
|
+
if (timer !== undefined) {
|
|
316
|
+
clearTimeout(timer);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
#withDiagnostics(message) {
|
|
321
|
+
return new PiRpcError(message, this.#diagnostics());
|
|
322
|
+
}
|
|
323
|
+
#diagnostics() {
|
|
324
|
+
const diagnostics = [...this.#protocolErrors, ...this.#errorEvents];
|
|
325
|
+
if (this.#stderr.trim().length > 0) {
|
|
326
|
+
diagnostics.push(`stderr: ${truncate(this.#stderr.trim(), 2_000)}`);
|
|
327
|
+
}
|
|
328
|
+
return diagnostics;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function describeExit(code, signal) {
|
|
332
|
+
if (signal !== null) {
|
|
333
|
+
return `signal ${signal}`;
|
|
334
|
+
}
|
|
335
|
+
return `exit code ${String(code)}`;
|
|
336
|
+
}
|
|
337
|
+
function describeErrorEvent(record) {
|
|
338
|
+
const reason = typeof record.reason === "string" ? record.reason : "error";
|
|
339
|
+
const error = typeof record.error === "string" ? record.error : "";
|
|
340
|
+
return truncate(`${reason}${error.length > 0 ? `: ${error}` : ""}`, 500);
|
|
341
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a candidate process-group id before the sandboxed supervisor sends
|
|
3
|
+
* any signal. The registry is agent-writable, so this is a safety filter, not
|
|
4
|
+
* an authorization mechanism: the supervisor itself runs inside Seatbelt and
|
|
5
|
+
* can signal only processes in the same sandbox.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSafeProcessGroup(value: unknown): value is number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a candidate process-group id before the sandboxed supervisor sends
|
|
3
|
+
* any signal. The registry is agent-writable, so this is a safety filter, not
|
|
4
|
+
* an authorization mechanism: the supervisor itself runs inside Seatbelt and
|
|
5
|
+
* can signal only processes in the same sandbox.
|
|
6
|
+
*/
|
|
7
|
+
export function isSafeProcessGroup(value) {
|
|
8
|
+
if (typeof value === "string" && !/^[1-9][0-9]*$/.test(value)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const pgid = typeof value === "number" ? value : Number(value);
|
|
12
|
+
return Number.isSafeInteger(pgid) && pgid > 1 && pgid <= 2_147_483_647 && pgid !== process.pid;
|
|
13
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type SandboxPolicy } from "../../platform/macos/policy.js";
|
|
2
|
+
import { PiProcess } from "./rpc.js";
|
|
3
|
+
export declare const THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
4
|
+
export type ThinkingLevel = (typeof THINKING_LEVELS)[number];
|
|
5
|
+
export interface PiSessionDirs {
|
|
6
|
+
readonly workspaceDir: string;
|
|
7
|
+
readonly homeDir: string;
|
|
8
|
+
readonly configDir: string;
|
|
9
|
+
readonly scratchDir: string;
|
|
10
|
+
}
|
|
11
|
+
export interface PiSessionConfig {
|
|
12
|
+
readonly executable: string;
|
|
13
|
+
/** Run root used for read-only shell tooling and destructive cleanup state. */
|
|
14
|
+
readonly runRootDir: string;
|
|
15
|
+
/** Omit only for model-free probes; normal runner and judge sessions require it. */
|
|
16
|
+
readonly model?: string;
|
|
17
|
+
readonly thinking: ThinkingLevel;
|
|
18
|
+
readonly dirs: PiSessionDirs;
|
|
19
|
+
/** Absolute skill paths, already staged inside the isolated config area. */
|
|
20
|
+
readonly skills: readonly string[];
|
|
21
|
+
/** Built-in tools exposed to Pi, or null to disable every tool. */
|
|
22
|
+
readonly tools: readonly string[] | null;
|
|
23
|
+
/** Ephemeral provider API key transported through an isolated config file and environment. */
|
|
24
|
+
readonly apiKey?: string;
|
|
25
|
+
readonly allowNetwork: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface PiInvocationResult {
|
|
28
|
+
readonly finalText: string | null;
|
|
29
|
+
readonly diagnostics: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export declare class PiSessionError extends Error {
|
|
32
|
+
readonly diagnostics: readonly string[];
|
|
33
|
+
constructor(message: string, diagnostics?: readonly string[]);
|
|
34
|
+
}
|
|
35
|
+
/** Resolve the configured executable through PATH and canonicalize it. */
|
|
36
|
+
export declare function resolvePiExecutable(executable: string): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Run one isolated Pi RPC invocation. The Pi process and its descendants are
|
|
39
|
+
* always stopped before this function returns or throws.
|
|
40
|
+
*/
|
|
41
|
+
export declare function invokePi(config: PiSessionConfig, message: string, options: {
|
|
42
|
+
timeoutMs: number;
|
|
43
|
+
signal: AbortSignal;
|
|
44
|
+
/** Lets the owner request process termination, for example on an engine timeout. */
|
|
45
|
+
onProcess?: (stop: () => Promise<void>) => void;
|
|
46
|
+
}): Promise<PiInvocationResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Stop Pi. The in-sandbox supervisor terminates tracked shell groups and exits
|
|
49
|
+
* before this resolves; the host never signals groups from registry data.
|
|
50
|
+
*/
|
|
51
|
+
export declare function stopPiSession(process: PiProcess): Promise<void>;
|
|
52
|
+
export declare function shellToolsDirectory(config: PiSessionConfig): string;
|
|
53
|
+
export declare function shellStateDirectory(config: PiSessionConfig): string;
|
|
54
|
+
/** Prepare isolated state and start an RPC process without prompting it. */
|
|
55
|
+
export declare function createPiProcess(config: PiSessionConfig): Promise<PiProcess>;
|
|
56
|
+
export declare function buildPolicy(executable: string, config: PiSessionConfig): Promise<SandboxPolicy>;
|