poe-code 3.0.202 → 3.0.204
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/cli/commands/braintrust.d.ts +3 -0
- package/dist/cli/commands/braintrust.js +77 -0
- package/dist/cli/commands/braintrust.js.map +1 -0
- package/dist/cli/commands/configure.d.ts +1 -0
- package/dist/cli/commands/configure.js +197 -0
- package/dist/cli/commands/configure.js.map +1 -1
- package/dist/cli/commands/experiment.js +51 -7
- package/dist/cli/commands/experiment.js.map +1 -1
- package/dist/cli/commands/harness.d.ts +3 -0
- package/dist/cli/commands/harness.js +260 -0
- package/dist/cli/commands/harness.js.map +1 -0
- package/dist/cli/commands/pipeline.js +58 -24
- package/dist/cli/commands/pipeline.js.map +1 -1
- package/dist/cli/commands/ralph.js +19 -7
- package/dist/cli/commands/ralph.js.map +1 -1
- package/dist/cli/commands/runtime/build.d.ts +7 -0
- package/dist/cli/commands/runtime/build.js +128 -0
- package/dist/cli/commands/runtime/build.js.map +1 -0
- package/dist/cli/commands/runtime/index.d.ts +3 -0
- package/dist/cli/commands/runtime/index.js +14 -0
- package/dist/cli/commands/runtime/index.js.map +1 -0
- package/dist/cli/commands/runtime/init.d.ts +7 -0
- package/dist/cli/commands/runtime/init.js +39 -0
- package/dist/cli/commands/runtime/init.js.map +1 -0
- package/dist/cli/commands/runtime/jobs/attach.d.ts +3 -0
- package/dist/cli/commands/runtime/jobs/attach.js +35 -0
- package/dist/cli/commands/runtime/jobs/attach.js.map +1 -0
- package/dist/cli/commands/runtime/jobs/index.d.ts +3 -0
- package/dist/cli/commands/runtime/jobs/index.js +16 -0
- package/dist/cli/commands/runtime/jobs/index.js.map +1 -0
- package/dist/cli/commands/runtime/jobs/logs.d.ts +3 -0
- package/dist/cli/commands/runtime/jobs/logs.js +27 -0
- package/dist/cli/commands/runtime/jobs/logs.js.map +1 -0
- package/dist/cli/commands/runtime/jobs/ls.d.ts +3 -0
- package/dist/cli/commands/runtime/jobs/ls.js +60 -0
- package/dist/cli/commands/runtime/jobs/ls.js.map +1 -0
- package/dist/cli/commands/runtime/jobs/sandbox.d.ts +3 -0
- package/dist/cli/commands/runtime/jobs/sandbox.js +15 -0
- package/dist/cli/commands/runtime/jobs/sandbox.js.map +1 -0
- package/dist/cli/commands/runtime/jobs/shared.d.ts +22 -0
- package/dist/cli/commands/runtime/jobs/shared.js +124 -0
- package/dist/cli/commands/runtime/jobs/shared.js.map +1 -0
- package/dist/cli/commands/runtime/jobs/stop.d.ts +3 -0
- package/dist/cli/commands/runtime/jobs/stop.js +31 -0
- package/dist/cli/commands/runtime/jobs/stop.js.map +1 -0
- package/dist/cli/commands/runtime/jobs/sync.d.ts +3 -0
- package/dist/cli/commands/runtime/jobs/sync.js +25 -0
- package/dist/cli/commands/runtime/jobs/sync.js.map +1 -0
- package/dist/cli/commands/runtime/shared.d.ts +20 -0
- package/dist/cli/commands/runtime/shared.js +69 -0
- package/dist/cli/commands/runtime/shared.js.map +1 -0
- package/dist/cli/commands/runtime/templates/clear.d.ts +3 -0
- package/dist/cli/commands/runtime/templates/clear.js +53 -0
- package/dist/cli/commands/runtime/templates/clear.js.map +1 -0
- package/dist/cli/commands/runtime/templates/index.d.ts +3 -0
- package/dist/cli/commands/runtime/templates/index.js +10 -0
- package/dist/cli/commands/runtime/templates/index.js.map +1 -0
- package/dist/cli/commands/runtime/templates/ls.d.ts +3 -0
- package/dist/cli/commands/runtime/templates/ls.js +52 -0
- package/dist/cli/commands/runtime/templates/ls.js.map +1 -0
- package/dist/cli/commands/runtime-options.d.ts +11 -0
- package/dist/cli/commands/runtime-options.js +26 -0
- package/dist/cli/commands/runtime-options.js.map +1 -0
- package/dist/cli/commands/spawn.js +36 -7
- package/dist/cli/commands/spawn.js.map +1 -1
- package/dist/cli/program.js +17 -1
- package/dist/cli/program.js.map +1 -1
- package/dist/index.js +70879 -47381
- package/dist/index.js.map +4 -4
- package/dist/providers/claude-code.js +3486 -852
- package/dist/providers/claude-code.js.map +4 -4
- package/dist/providers/codex.js +3486 -852
- package/dist/providers/codex.js.map +4 -4
- package/dist/providers/goose.js +3432 -798
- package/dist/providers/goose.js.map +4 -4
- package/dist/providers/kimi.js +3486 -852
- package/dist/providers/kimi.js.map +4 -4
- package/dist/providers/opencode.js +3486 -852
- package/dist/providers/opencode.js.map +4 -4
- package/dist/providers/poe-agent.js +20641 -17147
- package/dist/providers/poe-agent.js.map +4 -4
- package/dist/providers/spawn-options.d.ts +10 -1
- package/dist/sdk/experiment.js +6 -0
- package/dist/sdk/experiment.js.map +1 -1
- package/dist/sdk/ralph.js +108 -11
- package/dist/sdk/ralph.js.map +1 -1
- package/dist/sdk/spawn.js +27 -4
- package/dist/sdk/spawn.js.map +1 -1
- package/dist/sdk/types.d.ts +23 -1
- package/dist/utils/command-checks.js +2 -29
- package/dist/utils/command-checks.js.map +1 -1
- package/package.json +12 -7
- package/packages/design-system/dist/components/help-formatter-plain.d.ts +4 -0
- package/packages/design-system/dist/components/help-formatter-plain.js +132 -0
- package/packages/design-system/dist/components/help-formatter.d.ts +13 -0
- package/packages/design-system/dist/components/help-formatter.js +116 -7
- package/packages/design-system/dist/components/index.d.ts +2 -2
- package/packages/design-system/dist/components/index.js +1 -1
- package/packages/design-system/dist/components/text.d.ts +1 -0
- package/packages/design-system/dist/components/text.js +8 -0
- package/packages/design-system/dist/index.d.ts +3 -2
- package/packages/design-system/dist/index.js +2 -1
- package/packages/memory/dist/index.js +3406 -387
- package/packages/memory/dist/index.js.map +4 -4
- package/packages/superintendent/dist/commands/run.d.ts +45 -0
- package/packages/superintendent/dist/commands/run.js +133 -38
- package/packages/superintendent/dist/commands/superintendent-group.d.ts +36 -0
- package/packages/superintendent/dist/runtime/agent-runner.d.ts +31 -0
- package/packages/superintendent/dist/runtime/agent-runner.js +121 -0
- package/packages/superintendent/dist/runtime/loop.d.ts +7 -1
- package/packages/superintendent/dist/runtime/loop.js +3 -11
- package/packages/superintendent/dist/runtime/run-builder.d.ts +1 -0
- package/packages/superintendent/dist/runtime/run-builder.js +3 -25
- package/packages/superintendent/dist/runtime/run-inspector.d.ts +1 -0
- package/packages/superintendent/dist/runtime/run-inspector.js +3 -25
- package/packages/superintendent/dist/runtime/run-owner-review.d.ts +1 -0
- package/packages/superintendent/dist/runtime/run-owner-review.js +3 -25
- package/packages/superintendent/dist/runtime/run-superintendent.d.ts +1 -0
- package/packages/superintendent/dist/runtime/run-superintendent.js +3 -25
package/dist/providers/codex.js
CHANGED
|
@@ -52,19 +52,11 @@ var require_config_toml = __commonJS({
|
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
// packages/agent-spawn/src/
|
|
56
|
-
import { spawn } from "node:child_process";
|
|
55
|
+
// packages/agent-spawn/src/register-factories.ts
|
|
56
|
+
import { spawn as spawnChildProcess2 } from "node:child_process";
|
|
57
57
|
|
|
58
|
-
// packages/agent-
|
|
59
|
-
|
|
60
|
-
if (Array.isArray(modeConfig)) {
|
|
61
|
-
return { args: modeConfig };
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
args: modeConfig.args ?? [],
|
|
65
|
-
env: modeConfig.env && Object.keys(modeConfig.env).length > 0 ? modeConfig.env : void 0
|
|
66
|
-
};
|
|
67
|
-
}
|
|
58
|
+
// packages/agent-harness-tools/src/paths.ts
|
|
59
|
+
import path from "node:path";
|
|
68
60
|
|
|
69
61
|
// packages/agent-defs/src/agents/claude-code.ts
|
|
70
62
|
var claudeCodeAgent = {
|
|
@@ -205,918 +197,935 @@ function resolveAgentId(input) {
|
|
|
205
197
|
return lookup.get(input.toLowerCase());
|
|
206
198
|
}
|
|
207
199
|
|
|
208
|
-
// packages/agent-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
200
|
+
// packages/agent-harness-tools/src/select-agent.ts
|
|
201
|
+
var loopAgents = allAgents.filter(
|
|
202
|
+
(agent) => agent.binaryName !== void 0 || agent.id === "poe-agent"
|
|
203
|
+
);
|
|
204
|
+
var supportedAgents = loopAgents.map((agent) => agent.id).join(", ");
|
|
205
|
+
|
|
206
|
+
// packages/file-lock/src/lock.ts
|
|
207
|
+
import * as fsPromises from "node:fs/promises";
|
|
208
|
+
import * as os from "node:os";
|
|
209
|
+
|
|
210
|
+
// packages/agent-harness-tools/src/run-logs.ts
|
|
211
|
+
import path2 from "node:path";
|
|
212
|
+
|
|
213
|
+
// packages/agent-harness-tools/src/log-stream.ts
|
|
214
|
+
import nodeFs from "node:fs";
|
|
215
|
+
var JOB_DIR = "/tmp/poe-jobs";
|
|
216
|
+
var POLL_INTERVAL_MS = 250;
|
|
217
|
+
async function* streamLogFile(env, jobId, opts) {
|
|
218
|
+
const fs = env.fs ?? nodeFs;
|
|
219
|
+
const file = jobLogPath(jobId);
|
|
220
|
+
let byteOffset = opts.sinceByte ?? 0;
|
|
221
|
+
while (true) {
|
|
222
|
+
if (opts.since !== void 0 && !await wasModifiedSince(fs, file, opts.since)) {
|
|
223
|
+
await waitForLogChange(fs, file);
|
|
224
|
+
continue;
|
|
215
225
|
}
|
|
216
|
-
|
|
217
|
-
|
|
226
|
+
const result = await readLogChunk(fs, file, byteOffset);
|
|
227
|
+
if (result !== null) {
|
|
228
|
+
byteOffset = result.nextByteOffset;
|
|
229
|
+
yield result.chunk;
|
|
230
|
+
continue;
|
|
218
231
|
}
|
|
219
|
-
|
|
220
|
-
|
|
232
|
+
await waitForLogChange(fs, file);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function wasModifiedSince(fs, file, since) {
|
|
236
|
+
if (fs.promises.stat === void 0) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
const stat2 = await fs.promises.stat(file);
|
|
241
|
+
return stat2.mtimeMs >= since.getTime();
|
|
242
|
+
} catch (error2) {
|
|
243
|
+
if (isNodeError(error2) && error2.code === "ENOENT") {
|
|
244
|
+
return false;
|
|
221
245
|
}
|
|
222
|
-
|
|
246
|
+
throw error2;
|
|
223
247
|
}
|
|
224
|
-
return out;
|
|
225
248
|
}
|
|
226
|
-
function
|
|
227
|
-
|
|
249
|
+
async function waitForExit(env, jobId, opts = {}) {
|
|
250
|
+
const fs = env.fs ?? nodeFs;
|
|
251
|
+
const file = jobExitPath(jobId);
|
|
252
|
+
while (true) {
|
|
253
|
+
throwIfAborted(opts.signal);
|
|
254
|
+
const contents = await readTextFileIfExists(fs, file);
|
|
255
|
+
if (contents !== null) {
|
|
256
|
+
const text4 = contents.trim();
|
|
257
|
+
const exitCode = Number(text4);
|
|
258
|
+
if (text4.length === 0 || !Number.isInteger(exitCode)) {
|
|
259
|
+
throw new Error(`Invalid exit code in ${file}: ${contents}`);
|
|
260
|
+
}
|
|
261
|
+
return { exitCode };
|
|
262
|
+
}
|
|
263
|
+
await sleep(POLL_INTERVAL_MS, opts.signal);
|
|
264
|
+
}
|
|
228
265
|
}
|
|
229
|
-
function
|
|
230
|
-
|
|
231
|
-
return `[${serialized.join(", ")}]`;
|
|
266
|
+
function jobLogPath(jobId) {
|
|
267
|
+
return `${JOB_DIR}/${jobId}.log`;
|
|
232
268
|
}
|
|
233
|
-
function
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
269
|
+
function jobExitPath(jobId) {
|
|
270
|
+
return `${JOB_DIR}/${jobId}.exit`;
|
|
271
|
+
}
|
|
272
|
+
async function readLogChunk(fs, file, byteOffset) {
|
|
273
|
+
const contents = await readFileIfExists(fs, file);
|
|
274
|
+
if (contents === null || byteOffset >= contents.byteLength) {
|
|
275
|
+
return null;
|
|
237
276
|
}
|
|
238
|
-
return
|
|
277
|
+
return {
|
|
278
|
+
chunk: {
|
|
279
|
+
byteOffset,
|
|
280
|
+
data: contents.subarray(byteOffset).toString("utf8")
|
|
281
|
+
},
|
|
282
|
+
nextByteOffset: contents.byteLength
|
|
283
|
+
};
|
|
239
284
|
}
|
|
240
|
-
function
|
|
241
|
-
|
|
285
|
+
async function readTextFileIfExists(fs, file) {
|
|
286
|
+
const contents = await readFileIfExists(fs, file);
|
|
287
|
+
return contents?.toString("utf8") ?? null;
|
|
242
288
|
}
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
289
|
+
async function readFileIfExists(fs, file) {
|
|
290
|
+
try {
|
|
291
|
+
const contents = await fs.promises.readFile(file);
|
|
292
|
+
return Buffer.isBuffer(contents) ? contents : Buffer.from(contents);
|
|
293
|
+
} catch (error2) {
|
|
294
|
+
if (isNodeError(error2) && error2.code === "ENOENT") {
|
|
295
|
+
return null;
|
|
249
296
|
}
|
|
250
|
-
|
|
297
|
+
throw error2;
|
|
251
298
|
}
|
|
252
|
-
return { OPENCODE_CONFIG_CONTENT: JSON.stringify({ mcp }) };
|
|
253
299
|
}
|
|
254
|
-
function
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
300
|
+
async function waitForLogChange(fs, file) {
|
|
301
|
+
const watch = fs.watch;
|
|
302
|
+
if (typeof watch !== "function") {
|
|
303
|
+
await sleep(POLL_INTERVAL_MS);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
await new Promise((resolve2) => {
|
|
307
|
+
let watcher = null;
|
|
308
|
+
const timer = setTimeout(done, POLL_INTERVAL_MS);
|
|
309
|
+
function done() {
|
|
310
|
+
clearTimeout(timer);
|
|
311
|
+
watcher?.close();
|
|
312
|
+
resolve2();
|
|
261
313
|
}
|
|
262
|
-
|
|
263
|
-
|
|
314
|
+
try {
|
|
315
|
+
watcher = watch(file, done);
|
|
316
|
+
} catch {
|
|
317
|
+
done();
|
|
264
318
|
}
|
|
265
|
-
|
|
266
|
-
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function sleep(ms, signal) {
|
|
322
|
+
return new Promise((resolve2, reject) => {
|
|
323
|
+
let timer = null;
|
|
324
|
+
const abort = () => {
|
|
325
|
+
if (timer !== null) {
|
|
326
|
+
clearTimeout(timer);
|
|
327
|
+
}
|
|
328
|
+
reject(new Error("waitForExit aborted."));
|
|
329
|
+
};
|
|
330
|
+
if (signal?.aborted) {
|
|
331
|
+
abort();
|
|
332
|
+
return;
|
|
267
333
|
}
|
|
334
|
+
timer = setTimeout(() => {
|
|
335
|
+
signal?.removeEventListener("abort", abort);
|
|
336
|
+
resolve2();
|
|
337
|
+
}, ms);
|
|
338
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function throwIfAborted(signal) {
|
|
342
|
+
if (signal?.aborted) {
|
|
343
|
+
throw new Error("waitForExit aborted.");
|
|
268
344
|
}
|
|
269
|
-
return args;
|
|
270
345
|
}
|
|
271
|
-
function
|
|
272
|
-
return
|
|
273
|
-
"--with-extension",
|
|
274
|
-
[server.command, ...server.args ?? []].join(" ")
|
|
275
|
-
]);
|
|
346
|
+
function isNodeError(error2) {
|
|
347
|
+
return error2 instanceof Error && "code" in error2;
|
|
276
348
|
}
|
|
277
349
|
|
|
278
|
-
// packages/agent-
|
|
279
|
-
|
|
280
|
-
kind: "cli",
|
|
281
|
-
agentId: "claude-code",
|
|
282
|
-
// ACP adapter support: yes (adapter: "claude")
|
|
283
|
-
adapter: "claude",
|
|
284
|
-
promptFlag: "-p",
|
|
285
|
-
modelFlag: "--model",
|
|
286
|
-
modelStripProviderPrefix: true,
|
|
287
|
-
modelTransform: (model) => model.replaceAll(".", "-"),
|
|
288
|
-
defaultArgs: [
|
|
289
|
-
"--output-format",
|
|
290
|
-
"stream-json",
|
|
291
|
-
"--verbose"
|
|
292
|
-
],
|
|
293
|
-
mcpArgs: serializeJsonMcpArgs,
|
|
294
|
-
modes: {
|
|
295
|
-
yolo: ["--dangerously-skip-permissions"],
|
|
296
|
-
edit: ["--permission-mode", "acceptEdits", "--allowedTools", "Bash,Read,Write,Edit,Glob,Grep,NotebookEdit"],
|
|
297
|
-
read: ["--permission-mode", "plan"]
|
|
298
|
-
},
|
|
299
|
-
stdinMode: {
|
|
300
|
-
omitPrompt: true,
|
|
301
|
-
extraArgs: ["--input-format", "text"]
|
|
302
|
-
},
|
|
303
|
-
interactive: {
|
|
304
|
-
defaultArgs: []
|
|
305
|
-
},
|
|
306
|
-
resumeCommand: (threadId) => ["--resume", threadId]
|
|
307
|
-
};
|
|
350
|
+
// packages/agent-harness-tools/src/run-poe-command.ts
|
|
351
|
+
import { randomBytes } from "node:crypto";
|
|
308
352
|
|
|
309
|
-
// packages/agent-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
353
|
+
// packages/agent-harness-tools/src/binary-exists.ts
|
|
354
|
+
function createBinaryExistsDetectors(binaryName) {
|
|
355
|
+
const commonPaths = [
|
|
356
|
+
`/usr/local/bin/${binaryName}`,
|
|
357
|
+
`/usr/bin/${binaryName}`,
|
|
358
|
+
`$HOME/.local/bin/${binaryName}`,
|
|
359
|
+
`$HOME/.claude/local/bin/${binaryName}`
|
|
360
|
+
];
|
|
361
|
+
return [
|
|
362
|
+
{
|
|
363
|
+
command: "which",
|
|
364
|
+
args: [binaryName],
|
|
365
|
+
validate: (result) => result.exitCode === 0
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
command: "where",
|
|
369
|
+
args: [binaryName],
|
|
370
|
+
validate: (result) => result.exitCode === 0 && result.stdout.trim().length > 0
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
command: "sh",
|
|
374
|
+
args: ["-c", commonPaths.map((p) => `test -f "${p}"`).join(" || ")],
|
|
375
|
+
validate: (result) => result.exitCode === 0
|
|
376
|
+
}
|
|
377
|
+
];
|
|
378
|
+
}
|
|
335
379
|
|
|
336
|
-
// packages/agent-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
agentId: "opencode",
|
|
340
|
-
// ACP adapter support: yes (adapter: "opencode").
|
|
341
|
-
// OpenCode's `--format json` emits NDJSON events with `{ type, sessionID, part }`
|
|
342
|
-
// (no `{ event, ... }` field), so it needs the OpenCode adapter (not "native").
|
|
343
|
-
adapter: "opencode",
|
|
344
|
-
promptFlag: "run",
|
|
345
|
-
modelFlag: "--model",
|
|
346
|
-
modelStripProviderPrefix: false,
|
|
347
|
-
modelTransform: (model) => {
|
|
348
|
-
return model.startsWith("poe/") ? model : `poe/${model}`;
|
|
349
|
-
},
|
|
350
|
-
defaultArgs: ["--format", "json"],
|
|
351
|
-
modes: {
|
|
352
|
-
yolo: [],
|
|
353
|
-
edit: [],
|
|
354
|
-
read: ["--agent", "plan"]
|
|
355
|
-
},
|
|
356
|
-
interactive: {
|
|
357
|
-
defaultArgs: [],
|
|
358
|
-
promptFlag: "--prompt"
|
|
359
|
-
},
|
|
360
|
-
resumeCommand: (threadId, cwd) => [cwd, "--session", threadId],
|
|
361
|
-
mcpEnv: serializeOpenCodeMcpEnv
|
|
362
|
-
};
|
|
363
|
-
var openCodeAcpSpawnConfig = {
|
|
364
|
-
kind: "acp",
|
|
365
|
-
agentId: "opencode",
|
|
366
|
-
acpArgs: ["acp"],
|
|
367
|
-
skipAuth: true,
|
|
368
|
-
mcpEnv: serializeOpenCodeMcpEnv
|
|
369
|
-
};
|
|
380
|
+
// packages/agent-harness-tools/src/poe-command-execution.ts
|
|
381
|
+
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
382
|
+
import os3 from "node:os";
|
|
370
383
|
|
|
371
|
-
// packages/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
384
|
+
// packages/poe-code-config/src/runtime.ts
|
|
385
|
+
import { existsSync } from "node:fs";
|
|
386
|
+
import path3 from "node:path";
|
|
387
|
+
var defaultWorkspaceExclude = [
|
|
388
|
+
".git",
|
|
389
|
+
"node_modules",
|
|
390
|
+
"dist",
|
|
391
|
+
".turbo",
|
|
392
|
+
".next",
|
|
393
|
+
".poe-code/state.json"
|
|
394
|
+
];
|
|
395
|
+
var runtimeConfigScope = {
|
|
396
|
+
scope: "runtime",
|
|
397
|
+
schema: {
|
|
398
|
+
type: {
|
|
399
|
+
type: "string",
|
|
400
|
+
default: "host",
|
|
401
|
+
doc: "Runtime backend: host, docker, or e2b"
|
|
402
|
+
},
|
|
403
|
+
build_args: {
|
|
404
|
+
type: "json",
|
|
405
|
+
default: {},
|
|
406
|
+
parse: parseBuildArgs,
|
|
407
|
+
doc: "Build arguments passed to the runtime image build"
|
|
408
|
+
},
|
|
409
|
+
mounts: {
|
|
410
|
+
type: "json",
|
|
411
|
+
default: [],
|
|
412
|
+
parse: parseMounts,
|
|
413
|
+
doc: "Additional runtime mounts"
|
|
414
|
+
},
|
|
415
|
+
runner: {
|
|
416
|
+
type: "json",
|
|
417
|
+
default: createDefaultRunnerScope(),
|
|
418
|
+
parse: parseRunner,
|
|
419
|
+
doc: "Runner process and workspace transfer settings"
|
|
420
|
+
},
|
|
421
|
+
link: {
|
|
422
|
+
type: "string",
|
|
423
|
+
default: "",
|
|
424
|
+
doc: "Informational link for the runtime definition"
|
|
425
|
+
},
|
|
426
|
+
image: {
|
|
427
|
+
type: "string",
|
|
428
|
+
default: "",
|
|
429
|
+
doc: "Prebuilt Docker image"
|
|
430
|
+
},
|
|
431
|
+
dockerfile: {
|
|
432
|
+
type: "string",
|
|
433
|
+
default: "",
|
|
434
|
+
doc: "Path to the Dockerfile used for docker or e2b builds"
|
|
435
|
+
},
|
|
436
|
+
build_context: {
|
|
437
|
+
type: "string",
|
|
438
|
+
default: "",
|
|
439
|
+
doc: "Path to the Docker build context"
|
|
440
|
+
},
|
|
441
|
+
workspace_dir: {
|
|
442
|
+
type: "string",
|
|
443
|
+
default: "/workspace",
|
|
444
|
+
doc: "Sandbox-local workspace directory for E2B runtime upload, execution, and download"
|
|
445
|
+
},
|
|
446
|
+
engine: {
|
|
447
|
+
type: "string",
|
|
448
|
+
default: "",
|
|
449
|
+
doc: "Container engine for Docker runtime"
|
|
450
|
+
},
|
|
451
|
+
network: {
|
|
452
|
+
type: "string",
|
|
453
|
+
default: "",
|
|
454
|
+
doc: "Docker network"
|
|
455
|
+
},
|
|
456
|
+
extra_args: {
|
|
457
|
+
type: "json",
|
|
458
|
+
default: void 0,
|
|
459
|
+
parse: parseOptionalStringArray,
|
|
460
|
+
doc: "Extra Docker runtime arguments"
|
|
461
|
+
},
|
|
462
|
+
template_id: {
|
|
463
|
+
type: "string",
|
|
464
|
+
default: "",
|
|
465
|
+
doc: "Prebuilt E2B template id"
|
|
466
|
+
},
|
|
467
|
+
from_template: {
|
|
468
|
+
type: "string",
|
|
469
|
+
default: "",
|
|
470
|
+
doc: "Existing E2B template alias to extend instead of using the Dockerfile FROM image"
|
|
471
|
+
},
|
|
472
|
+
cpu: {
|
|
473
|
+
type: "json",
|
|
474
|
+
default: void 0,
|
|
475
|
+
parse: parseOptionalNumber,
|
|
476
|
+
doc: "E2B CPU count"
|
|
477
|
+
},
|
|
478
|
+
memory_mb: {
|
|
479
|
+
type: "json",
|
|
480
|
+
default: void 0,
|
|
481
|
+
parse: parseOptionalNumber,
|
|
482
|
+
doc: "E2B memory in megabytes"
|
|
483
|
+
},
|
|
484
|
+
timeout_minutes: {
|
|
485
|
+
type: "json",
|
|
486
|
+
default: void 0,
|
|
487
|
+
parse: parseOptionalNumber,
|
|
488
|
+
doc: "E2B timeout in minutes"
|
|
489
|
+
},
|
|
490
|
+
preserve_after_exit_hours: {
|
|
491
|
+
type: "json",
|
|
492
|
+
default: void 0,
|
|
493
|
+
parse: parseOptionalNumber,
|
|
494
|
+
doc: "Hours to keep an E2B sandbox alive after job exit"
|
|
495
|
+
}
|
|
496
|
+
}
|
|
402
497
|
};
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
stdinMode: {
|
|
423
|
-
omitPrompt: true,
|
|
424
|
-
extraArgs: ["--instructions", "-"]
|
|
425
|
-
},
|
|
426
|
-
interactive: {
|
|
427
|
-
defaultArgs: ["session"],
|
|
428
|
-
defaultArgsPosition: "beforePrompt"
|
|
429
|
-
},
|
|
430
|
-
resumeCommand: () => ["run", "--resume", "--text", "continue"]
|
|
431
|
-
};
|
|
432
|
-
var gooseAcpSpawnConfig = {
|
|
433
|
-
kind: "acp",
|
|
434
|
-
agentId: "goose",
|
|
435
|
-
acpArgs: ["acp"],
|
|
436
|
-
env: gooseFileSecretsEnv,
|
|
437
|
-
skipAuth: true
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
// packages/agent-spawn/src/configs/index.ts
|
|
441
|
-
var allSpawnConfigs = [
|
|
442
|
-
claudeCodeSpawnConfig,
|
|
443
|
-
codexSpawnConfig,
|
|
444
|
-
openCodeSpawnConfig,
|
|
445
|
-
kimiSpawnConfig,
|
|
446
|
-
gooseSpawnConfig
|
|
447
|
-
];
|
|
448
|
-
var lookup2 = /* @__PURE__ */ new Map();
|
|
449
|
-
for (const config of allSpawnConfigs) {
|
|
450
|
-
lookup2.set(config.agentId, config);
|
|
498
|
+
function parseRunner(raw) {
|
|
499
|
+
if (raw === void 0) {
|
|
500
|
+
return createDefaultRunnerScope();
|
|
501
|
+
}
|
|
502
|
+
const record = asRecord(raw);
|
|
503
|
+
if (record === void 0) {
|
|
504
|
+
throw new Error("runner: expected an object.");
|
|
505
|
+
}
|
|
506
|
+
const uploadMaxFileMb = parseOptionalNumber(record.upload_max_file_mb, "runner.upload_max_file_mb") ?? 100;
|
|
507
|
+
if (uploadMaxFileMb <= 0) {
|
|
508
|
+
throw new Error("runner.upload_max_file_mb: expected a positive finite number.");
|
|
509
|
+
}
|
|
510
|
+
return omitUndefined({
|
|
511
|
+
detach: parseOptionalBoolean(record.detach, "runner.detach") ?? false,
|
|
512
|
+
upload_max_file_mb: uploadMaxFileMb,
|
|
513
|
+
download_conflict: parseDownloadConflict(record.download_conflict),
|
|
514
|
+
sync: parseRunnerSync(record.sync),
|
|
515
|
+
workspace: parseRunnerWorkspace(record.workspace)
|
|
516
|
+
});
|
|
451
517
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
518
|
+
function createDefaultRunnerScope() {
|
|
519
|
+
return {
|
|
520
|
+
detach: false,
|
|
521
|
+
upload_max_file_mb: 100,
|
|
522
|
+
download_conflict: "refuse",
|
|
523
|
+
sync: "both",
|
|
524
|
+
workspace: {
|
|
525
|
+
exclude: [...defaultWorkspaceExclude]
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function parseRunnerWorkspace(value) {
|
|
530
|
+
if (value === void 0) {
|
|
531
|
+
return {
|
|
532
|
+
exclude: [...defaultWorkspaceExclude]
|
|
533
|
+
};
|
|
460
534
|
}
|
|
461
|
-
|
|
535
|
+
const record = asRecord(value);
|
|
536
|
+
if (record === void 0) {
|
|
537
|
+
throw new Error("runner.workspace: expected an object.");
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
exclude: parseOptionalStringArray(record.exclude, "runner.workspace.exclude") ?? [
|
|
541
|
+
...defaultWorkspaceExclude
|
|
542
|
+
]
|
|
543
|
+
};
|
|
462
544
|
}
|
|
463
|
-
function
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
if (config.kind !== "cli" || typeof config.mcpArgs !== "function" && typeof config.mcpEnv !== "function") {
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
supported.push(config.agentId);
|
|
545
|
+
function parseDownloadConflict(value) {
|
|
546
|
+
if (value === void 0) {
|
|
547
|
+
return "refuse";
|
|
470
548
|
}
|
|
471
|
-
|
|
549
|
+
if (value === "refuse" || value === "overwrite") {
|
|
550
|
+
return value;
|
|
551
|
+
}
|
|
552
|
+
throw new Error('runner.download_conflict: expected "refuse" or "overwrite".');
|
|
472
553
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
import { mkdirSync, openSync, writeSync, closeSync } from "node:fs";
|
|
477
|
-
import path from "node:path";
|
|
478
|
-
|
|
479
|
-
// packages/agent-spawn/src/configs/resolve-config.ts
|
|
480
|
-
function resolveConfig(agentId) {
|
|
481
|
-
const resolvedAgentId = resolveAgentId(agentId);
|
|
482
|
-
if (!resolvedAgentId) {
|
|
483
|
-
throw new Error(`Unknown agent "${agentId}".`);
|
|
554
|
+
function parseRunnerSync(value) {
|
|
555
|
+
if (value === void 0) {
|
|
556
|
+
return "both";
|
|
484
557
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
throw new Error(`Unknown agent "${agentId}".`);
|
|
558
|
+
if (value === "both" || value === "upload" || value === "none") {
|
|
559
|
+
return value;
|
|
488
560
|
}
|
|
489
|
-
|
|
490
|
-
const binaryName = agentDefinition.binaryName;
|
|
491
|
-
return { agentId: resolvedAgentId, binaryName, spawnConfig };
|
|
561
|
+
throw new Error('runner.sync: expected "both", "upload", or "none".');
|
|
492
562
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
if (!servers) {
|
|
497
|
-
return false;
|
|
563
|
+
function parseBuildArgs(value) {
|
|
564
|
+
if (value === void 0) {
|
|
565
|
+
return {};
|
|
498
566
|
}
|
|
499
|
-
|
|
567
|
+
const record = asRecord(value);
|
|
568
|
+
if (record === void 0) {
|
|
569
|
+
throw new Error("build_args: expected an object.");
|
|
570
|
+
}
|
|
571
|
+
const parsed = {};
|
|
572
|
+
for (const [key, entry] of Object.entries(record)) {
|
|
573
|
+
if (typeof entry !== "string") {
|
|
574
|
+
throw new Error(`build_args.${key}: expected a string.`);
|
|
575
|
+
}
|
|
576
|
+
parsed[key] = entry;
|
|
577
|
+
}
|
|
578
|
+
return parsed;
|
|
500
579
|
}
|
|
501
|
-
function
|
|
502
|
-
if (
|
|
580
|
+
function parseMounts(value) {
|
|
581
|
+
if (value === void 0) {
|
|
503
582
|
return [];
|
|
504
583
|
}
|
|
505
|
-
if (!
|
|
506
|
-
throw new Error(
|
|
584
|
+
if (!Array.isArray(value)) {
|
|
585
|
+
throw new Error("mounts: expected an array.");
|
|
507
586
|
}
|
|
508
|
-
|
|
509
|
-
|
|
587
|
+
return value.map((entry, index) => {
|
|
588
|
+
const record = asRecord(entry);
|
|
589
|
+
if (record === void 0) {
|
|
590
|
+
throw new Error(`mounts[${index}]: expected an object.`);
|
|
591
|
+
}
|
|
592
|
+
const source = record.source;
|
|
593
|
+
const target = record.target;
|
|
594
|
+
if (typeof source !== "string") {
|
|
595
|
+
throw new Error(`mounts[${index}].source: expected a string.`);
|
|
596
|
+
}
|
|
597
|
+
if (typeof target !== "string") {
|
|
598
|
+
throw new Error(`mounts[${index}].target: expected a string.`);
|
|
599
|
+
}
|
|
600
|
+
return omitUndefined({
|
|
601
|
+
source,
|
|
602
|
+
target,
|
|
603
|
+
readonly: parseOptionalBoolean(record.readonly, `mounts[${index}].readonly`)
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
function parseOptionalStringArray(value, key = "") {
|
|
608
|
+
if (value === void 0) {
|
|
609
|
+
return void 0;
|
|
510
610
|
}
|
|
511
|
-
|
|
611
|
+
if (!Array.isArray(value)) {
|
|
612
|
+
throw new Error(`${key ? `${key}: ` : ""}expected an array.`);
|
|
613
|
+
}
|
|
614
|
+
return value.map((entry, index) => {
|
|
615
|
+
if (typeof entry !== "string") {
|
|
616
|
+
throw new Error(`${key}[${index}]: expected a string.`);
|
|
617
|
+
}
|
|
618
|
+
return entry;
|
|
619
|
+
});
|
|
512
620
|
}
|
|
513
|
-
function
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
621
|
+
function parseOptionalNumber(value, key = "") {
|
|
622
|
+
if (value === void 0) {
|
|
623
|
+
return void 0;
|
|
624
|
+
}
|
|
625
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
626
|
+
throw new Error(`${key ? `${key}: ` : ""}expected a finite number.`);
|
|
627
|
+
}
|
|
628
|
+
return value;
|
|
518
629
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
630
|
+
function parseOptionalBoolean(value, key) {
|
|
631
|
+
if (value === void 0) {
|
|
632
|
+
return void 0;
|
|
633
|
+
}
|
|
634
|
+
if (typeof value !== "boolean") {
|
|
635
|
+
throw new Error(`${key}: expected a boolean.`);
|
|
636
|
+
}
|
|
637
|
+
return value;
|
|
638
|
+
}
|
|
639
|
+
function asRecord(value) {
|
|
640
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
641
|
+
return void 0;
|
|
642
|
+
}
|
|
643
|
+
return value;
|
|
644
|
+
}
|
|
645
|
+
function omitUndefined(value) {
|
|
646
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
|
|
524
647
|
}
|
|
525
648
|
|
|
526
|
-
// packages/
|
|
527
|
-
function
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
649
|
+
// packages/poe-code-config/src/schema.ts
|
|
650
|
+
function defineScope(scope, schema) {
|
|
651
|
+
return {
|
|
652
|
+
scope,
|
|
653
|
+
schema
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
var integrationsConfigScope = defineScope("integrations", {
|
|
657
|
+
braintrust: {
|
|
658
|
+
type: "json",
|
|
659
|
+
default: {
|
|
660
|
+
enabled: false
|
|
661
|
+
},
|
|
662
|
+
parse: parseBraintrustIntegrationConfig,
|
|
663
|
+
doc: "Braintrust integration configuration"
|
|
531
664
|
}
|
|
532
|
-
|
|
533
|
-
|
|
665
|
+
});
|
|
666
|
+
function parseBraintrustIntegrationConfig(value) {
|
|
667
|
+
if (!isRecord(value)) {
|
|
668
|
+
throw new Error("expected an object");
|
|
534
669
|
}
|
|
535
|
-
|
|
536
|
-
|
|
670
|
+
const enabled = value.enabled === void 0 ? false : value.enabled;
|
|
671
|
+
if (typeof enabled !== "boolean") {
|
|
672
|
+
throw new Error("enabled must be a boolean");
|
|
537
673
|
}
|
|
538
674
|
return {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
675
|
+
enabled,
|
|
676
|
+
...optionalStringEntry("apiKey", value.apiKey),
|
|
677
|
+
...optionalStringEntry("apiUrl", value.apiUrl),
|
|
678
|
+
...optionalStringEntry("project", value.project)
|
|
542
679
|
};
|
|
543
680
|
}
|
|
544
|
-
function
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
function getMcpArgsPosition(config) {
|
|
548
|
-
if (config.mcpArgsPosition) {
|
|
549
|
-
return config.mcpArgsPosition;
|
|
681
|
+
function optionalStringEntry(key, value) {
|
|
682
|
+
if (value === void 0) {
|
|
683
|
+
return {};
|
|
550
684
|
}
|
|
551
|
-
|
|
685
|
+
if (typeof value !== "string") {
|
|
686
|
+
throw new Error(`${key} must be a string`);
|
|
687
|
+
}
|
|
688
|
+
return { [key]: value };
|
|
552
689
|
}
|
|
553
|
-
function
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
690
|
+
function isRecord(value) {
|
|
691
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// packages/poe-code-config/src/plan-scope.ts
|
|
695
|
+
var planConfigScope = defineScope("plan", {
|
|
696
|
+
plan_directory: {
|
|
697
|
+
type: "string",
|
|
698
|
+
default: "docs/plans",
|
|
699
|
+
env: "POE_PLAN_DIRECTORY",
|
|
700
|
+
doc: "Directory where planning documents are stored"
|
|
560
701
|
}
|
|
561
|
-
|
|
562
|
-
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
// packages/poe-code-config/src/store.ts
|
|
705
|
+
import path8 from "node:path";
|
|
706
|
+
|
|
707
|
+
// packages/config-extends/src/discover.ts
|
|
708
|
+
import path4 from "node:path";
|
|
709
|
+
async function findBase(name, bases, fs) {
|
|
710
|
+
const checkedPaths = [];
|
|
711
|
+
for (const basePath of bases) {
|
|
712
|
+
for (const extension of [".md", ".yaml", ".yml", ".json"]) {
|
|
713
|
+
const filePath = path4.join(basePath, `${name}${extension}`);
|
|
714
|
+
checkedPaths.push(filePath);
|
|
715
|
+
try {
|
|
716
|
+
return {
|
|
717
|
+
content: await fs.readFile(filePath, "utf8"),
|
|
718
|
+
filePath
|
|
719
|
+
};
|
|
720
|
+
} catch (error2) {
|
|
721
|
+
if (hasCode(error2, "ENOENT")) {
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
throw error2;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
563
727
|
}
|
|
564
|
-
|
|
565
|
-
|
|
728
|
+
throw new Error(`Base "${name}" not found.
|
|
729
|
+
Checked paths:
|
|
730
|
+
- ${checkedPaths.join("\n- ")}`);
|
|
731
|
+
}
|
|
732
|
+
function hasCode(error2, code) {
|
|
733
|
+
return typeof error2 === "object" && error2 !== null && "code" in error2 && error2.code === code;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// packages/config-extends/src/parse.ts
|
|
737
|
+
import path5 from "node:path";
|
|
738
|
+
import matter from "gray-matter";
|
|
739
|
+
import { parse as parseYaml } from "yaml";
|
|
740
|
+
function parseDocument(content, filePath) {
|
|
741
|
+
const normalizedContent = stripBom(content);
|
|
742
|
+
const format = detectFormat(normalizedContent, filePath);
|
|
743
|
+
const data = format === "markdown" ? parseMarkdown(normalizedContent) : toData(format === "json" ? JSON.parse(normalizedContent) : parseYaml(normalizedContent));
|
|
744
|
+
const hasExtendsField = Object.hasOwn(data, "extends");
|
|
745
|
+
const extendsValue = data.extends === true;
|
|
746
|
+
delete data.extends;
|
|
747
|
+
return {
|
|
748
|
+
data,
|
|
749
|
+
format,
|
|
750
|
+
extends: extendsValue,
|
|
751
|
+
hasExtendsField
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
function detectFormat(content, filePath) {
|
|
755
|
+
const extension = path5.extname(filePath).toLowerCase();
|
|
756
|
+
if (extension === ".md") {
|
|
757
|
+
return "markdown";
|
|
566
758
|
}
|
|
567
|
-
if (
|
|
568
|
-
|
|
569
|
-
config.promptFlag,
|
|
570
|
-
...stdinMode.omitPrompt ? [] : [options.prompt],
|
|
571
|
-
...stdinMode.extraArgs
|
|
572
|
-
);
|
|
573
|
-
} else {
|
|
574
|
-
args.push(config.promptFlag, options.prompt);
|
|
759
|
+
if (extension === ".yaml" || extension === ".yml") {
|
|
760
|
+
return "yaml";
|
|
575
761
|
}
|
|
576
|
-
if (
|
|
577
|
-
|
|
578
|
-
if (config.modelTransform) model = config.modelTransform(model);
|
|
579
|
-
args.push(config.modelFlag, model);
|
|
762
|
+
if (extension === ".json") {
|
|
763
|
+
return "json";
|
|
580
764
|
}
|
|
581
|
-
if (
|
|
582
|
-
|
|
765
|
+
if (content.startsWith("{")) {
|
|
766
|
+
return "json";
|
|
583
767
|
}
|
|
584
|
-
if (
|
|
585
|
-
|
|
768
|
+
if (content.startsWith("---\n") || content.startsWith("---\r\n")) {
|
|
769
|
+
return "markdown";
|
|
586
770
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
771
|
+
return "yaml";
|
|
772
|
+
}
|
|
773
|
+
function parseMarkdown(content) {
|
|
774
|
+
const document = matter(content);
|
|
775
|
+
return {
|
|
776
|
+
...toData(document.data),
|
|
777
|
+
prompt: document.content
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
function toData(value) {
|
|
781
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
782
|
+
return {};
|
|
591
783
|
}
|
|
592
|
-
return {
|
|
784
|
+
return { ...value };
|
|
593
785
|
}
|
|
594
|
-
function
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
return
|
|
786
|
+
function stripBom(content) {
|
|
787
|
+
if (!content.startsWith("\uFEFF")) {
|
|
788
|
+
return content;
|
|
789
|
+
}
|
|
790
|
+
return content.slice(1);
|
|
599
791
|
}
|
|
600
792
|
|
|
601
|
-
// packages/
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
muted: (text4) => chalk.dim(text4),
|
|
616
|
-
success: (text4) => chalk.green(text4),
|
|
617
|
-
warning: (text4) => chalk.yellow(text4),
|
|
618
|
-
error: (text4) => chalk.red(text4),
|
|
619
|
-
info: (text4) => chalk.magenta(text4),
|
|
620
|
-
badge: (text4) => chalk.bgYellow.black(` ${text4} `)
|
|
621
|
-
};
|
|
622
|
-
var light = {
|
|
623
|
-
header: (text4) => chalk.hex("#a200ff").bold(text4),
|
|
624
|
-
divider: (text4) => chalk.hex("#666666")(text4),
|
|
625
|
-
prompt: (text4) => chalk.hex("#006699").bold(text4),
|
|
626
|
-
number: (text4) => chalk.hex("#0077cc").bold(text4),
|
|
627
|
-
intro: (text4) => chalk.bgHex("#a200ff").white(` Poe - ${text4} `),
|
|
628
|
-
resolvedSymbol: chalk.hex("#a200ff")("\u25C7"),
|
|
629
|
-
errorSymbol: chalk.hex("#cc0000")("\u25A0"),
|
|
630
|
-
accent: (text4) => chalk.hex("#006699").bold(text4),
|
|
631
|
-
muted: (text4) => chalk.hex("#666666")(text4),
|
|
632
|
-
success: (text4) => chalk.hex("#008800")(text4),
|
|
633
|
-
warning: (text4) => chalk.hex("#cc6600")(text4),
|
|
634
|
-
error: (text4) => chalk.hex("#cc0000")(text4),
|
|
635
|
-
info: (text4) => chalk.hex("#a200ff")(text4),
|
|
636
|
-
badge: (text4) => chalk.bgHex("#cc6600").white(` ${text4} `)
|
|
637
|
-
};
|
|
638
|
-
|
|
639
|
-
// packages/design-system/src/tokens/typography.ts
|
|
640
|
-
import chalk2 from "chalk";
|
|
641
|
-
|
|
642
|
-
// packages/design-system/src/components/text.ts
|
|
643
|
-
import chalk3 from "chalk";
|
|
644
|
-
|
|
645
|
-
// packages/design-system/src/internal/output-format.ts
|
|
646
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
647
|
-
var VALID_FORMATS = /* @__PURE__ */ new Set(["terminal", "markdown", "json"]);
|
|
648
|
-
var formatStorage = new AsyncLocalStorage();
|
|
649
|
-
var cached;
|
|
650
|
-
function resolveOutputFormat(env = process.env) {
|
|
651
|
-
const scoped = formatStorage.getStore();
|
|
652
|
-
if (scoped) {
|
|
653
|
-
return scoped;
|
|
654
|
-
}
|
|
655
|
-
if (cached) {
|
|
656
|
-
return cached;
|
|
793
|
+
// packages/config-extends/src/merge.ts
|
|
794
|
+
function mergeLayers(layers) {
|
|
795
|
+
return mergeObjectLayers(layers, []);
|
|
796
|
+
}
|
|
797
|
+
function mergeObjectLayers(layers, path22) {
|
|
798
|
+
const data = {};
|
|
799
|
+
const sources = {};
|
|
800
|
+
for (const key of collectKeys(layers)) {
|
|
801
|
+
const resolved = resolveKey(layers, key, path22);
|
|
802
|
+
if (resolved === void 0) {
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
data[key] = resolved.value;
|
|
806
|
+
Object.assign(sources, resolved.sources);
|
|
657
807
|
}
|
|
658
|
-
|
|
659
|
-
cached = VALID_FORMATS.has(raw) ? raw : "terminal";
|
|
660
|
-
return cached;
|
|
808
|
+
return { data, sources };
|
|
661
809
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
810
|
+
function collectKeys(layers) {
|
|
811
|
+
const keys = /* @__PURE__ */ new Set();
|
|
812
|
+
for (const layer of layers) {
|
|
813
|
+
for (const key of Object.keys(layer.data)) {
|
|
814
|
+
keys.add(key);
|
|
815
|
+
}
|
|
668
816
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
817
|
+
return [...keys];
|
|
818
|
+
}
|
|
819
|
+
function resolveKey(layers, key, path22) {
|
|
820
|
+
let winningSource;
|
|
821
|
+
let winningValue;
|
|
822
|
+
const objectLayers = [];
|
|
823
|
+
for (const layer of layers) {
|
|
824
|
+
const candidate = layer.data[key];
|
|
825
|
+
if (!isWinningCandidate(key, candidate)) {
|
|
826
|
+
continue;
|
|
674
827
|
}
|
|
675
|
-
if (
|
|
676
|
-
|
|
828
|
+
if (winningSource === void 0) {
|
|
829
|
+
winningSource = layer.source;
|
|
830
|
+
winningValue = candidate;
|
|
831
|
+
if (isPlainObject(candidate)) {
|
|
832
|
+
objectLayers.push({
|
|
833
|
+
source: layer.source,
|
|
834
|
+
data: candidate
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
continue;
|
|
677
838
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
if (Number.isFinite(background)) {
|
|
684
|
-
return background >= 8 ? "light" : "dark";
|
|
839
|
+
if (isPlainObject(winningValue) && isPlainObject(candidate)) {
|
|
840
|
+
objectLayers.push({
|
|
841
|
+
source: layer.source,
|
|
842
|
+
data: candidate
|
|
843
|
+
});
|
|
685
844
|
}
|
|
686
845
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
function resolveThemeName(env = process.env) {
|
|
690
|
-
const raw = (env.POE_CODE_THEME ?? env.POE_THEME)?.toLowerCase();
|
|
691
|
-
if (raw === "light" || raw === "dark") {
|
|
692
|
-
return raw;
|
|
846
|
+
if (winningSource === void 0) {
|
|
847
|
+
return void 0;
|
|
693
848
|
}
|
|
694
|
-
const
|
|
695
|
-
if (
|
|
696
|
-
|
|
849
|
+
const fullPath = buildPath(path22, key);
|
|
850
|
+
if (isPlainObject(winningValue)) {
|
|
851
|
+
const merged = mergeObjectLayers(objectLayers, [...path22, key]);
|
|
852
|
+
return {
|
|
853
|
+
value: merged.data,
|
|
854
|
+
sources: {
|
|
855
|
+
[fullPath]: winningSource,
|
|
856
|
+
...merged.sources
|
|
857
|
+
}
|
|
858
|
+
};
|
|
697
859
|
}
|
|
698
|
-
return
|
|
860
|
+
return {
|
|
861
|
+
value: cloneValue(winningValue),
|
|
862
|
+
sources: {
|
|
863
|
+
[fullPath]: winningSource
|
|
864
|
+
}
|
|
865
|
+
};
|
|
699
866
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
return cachedTheme;
|
|
867
|
+
function isWinningCandidate(key, value) {
|
|
868
|
+
if (value === void 0) {
|
|
869
|
+
return false;
|
|
704
870
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
871
|
+
if (key === "prompt" && value === "") {
|
|
872
|
+
return false;
|
|
873
|
+
}
|
|
874
|
+
return true;
|
|
708
875
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
if (format === "json") return "info";
|
|
716
|
-
if (format === "markdown") return "(i)";
|
|
717
|
-
return chalk4.magenta("\u25CF");
|
|
718
|
-
},
|
|
719
|
-
get success() {
|
|
720
|
-
const format = resolveOutputFormat();
|
|
721
|
-
if (format === "json") return "success";
|
|
722
|
-
if (format === "markdown") return "[ok]";
|
|
723
|
-
return chalk4.magenta("\u25C6");
|
|
724
|
-
},
|
|
725
|
-
get resolved() {
|
|
726
|
-
const format = resolveOutputFormat();
|
|
727
|
-
if (format === "json") return "resolved";
|
|
728
|
-
if (format === "markdown") return ">";
|
|
729
|
-
return getTheme().resolvedSymbol;
|
|
730
|
-
},
|
|
731
|
-
get errorResolved() {
|
|
732
|
-
const format = resolveOutputFormat();
|
|
733
|
-
if (format === "json") return "error";
|
|
734
|
-
if (format === "markdown") return "[!]";
|
|
735
|
-
return getTheme().errorSymbol;
|
|
736
|
-
},
|
|
737
|
-
get bar() {
|
|
738
|
-
const format = resolveOutputFormat();
|
|
739
|
-
if (format === "json") return "";
|
|
740
|
-
if (format === "markdown") return "|";
|
|
741
|
-
return "\u2502";
|
|
742
|
-
},
|
|
743
|
-
cornerTopRight: "\u256E",
|
|
744
|
-
cornerBottomRight: "\u256F",
|
|
745
|
-
get warning() {
|
|
746
|
-
const format = resolveOutputFormat();
|
|
747
|
-
if (format === "json") return "warning";
|
|
748
|
-
if (format === "markdown") return "[!]";
|
|
749
|
-
return "\u25B2";
|
|
750
|
-
},
|
|
751
|
-
get active() {
|
|
752
|
-
const format = resolveOutputFormat();
|
|
753
|
-
if (format === "json") return "active";
|
|
754
|
-
if (format === "markdown") return "[x]";
|
|
755
|
-
return "\u25C6";
|
|
756
|
-
},
|
|
757
|
-
get inactive() {
|
|
758
|
-
const format = resolveOutputFormat();
|
|
759
|
-
if (format === "json") return "inactive";
|
|
760
|
-
if (format === "markdown") return "[ ]";
|
|
761
|
-
return "\u25CB";
|
|
876
|
+
function buildPath(path22, key) {
|
|
877
|
+
return [...path22, key].join(".");
|
|
878
|
+
}
|
|
879
|
+
function isPlainObject(value) {
|
|
880
|
+
if (value === null || Array.isArray(value) || typeof value !== "object") {
|
|
881
|
+
return false;
|
|
762
882
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
// packages/design-system/src/components/logger.ts
|
|
766
|
-
import chalk6 from "chalk";
|
|
767
|
-
|
|
768
|
-
// packages/design-system/src/prompts/primitives/log.ts
|
|
769
|
-
import chalk5 from "chalk";
|
|
770
|
-
|
|
771
|
-
// packages/design-system/src/internal/strip-ansi.ts
|
|
772
|
-
function stripAnsi(value) {
|
|
773
|
-
return value.replace(/\u001b\[[0-9;]*m/g, "");
|
|
883
|
+
const prototype = Object.getPrototypeOf(value);
|
|
884
|
+
return prototype === Object.prototype || prototype === null;
|
|
774
885
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
symbol = chalk5.gray("\u2502"),
|
|
779
|
-
secondarySymbol = chalk5.gray("\u2502"),
|
|
780
|
-
spacing: spacing2 = 1,
|
|
781
|
-
withGuide = true
|
|
782
|
-
} = {}) {
|
|
783
|
-
const lines = [];
|
|
784
|
-
const showGuide = withGuide !== false;
|
|
785
|
-
const contentLines = msg.split("\n");
|
|
786
|
-
const prefix = showGuide ? `${symbol} ` : "";
|
|
787
|
-
const continuationPrefix = showGuide ? `${secondarySymbol} ` : "";
|
|
788
|
-
const emptyGuide = showGuide ? secondarySymbol : "";
|
|
789
|
-
for (let index = 0; index < spacing2; index += 1) {
|
|
790
|
-
lines.push(emptyGuide);
|
|
886
|
+
function cloneValue(value) {
|
|
887
|
+
if (Array.isArray(value)) {
|
|
888
|
+
return value.map((entry) => cloneValue(entry));
|
|
791
889
|
}
|
|
792
|
-
if (
|
|
793
|
-
|
|
794
|
-
return;
|
|
890
|
+
if (!isPlainObject(value)) {
|
|
891
|
+
return value;
|
|
795
892
|
}
|
|
796
|
-
const
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
} else {
|
|
800
|
-
lines.push(showGuide ? symbol : "");
|
|
893
|
+
const clone = Object.create(Object.getPrototypeOf(value));
|
|
894
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
895
|
+
clone[key] = cloneValue(entry);
|
|
801
896
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
897
|
+
return clone;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// packages/config-extends/src/resolve.ts
|
|
901
|
+
import path6 from "node:path";
|
|
902
|
+
var MAX_EXTENDS_DEPTH = 5;
|
|
903
|
+
var YIELD_TOKEN = "{{yield}}";
|
|
904
|
+
async function resolve(chain, options) {
|
|
905
|
+
const { baseLayers, documentIndex, documentLayer } = classifyChain(chain);
|
|
906
|
+
const parsedDocument = parseDocument(documentLayer.content, documentLayer.filePath);
|
|
907
|
+
const resolvedBase = shouldResolveBase(parsedDocument, options.autoExtend) ? await resolveBaseChain({
|
|
908
|
+
name: documentLayer.baseName ?? getBaseName(documentLayer.filePath),
|
|
909
|
+
baseLayers,
|
|
910
|
+
options,
|
|
911
|
+
optional: !parsedDocument.extends,
|
|
912
|
+
visited: /* @__PURE__ */ new Set([documentLayer.filePath]),
|
|
913
|
+
depth: 1
|
|
914
|
+
}) : void 0;
|
|
915
|
+
const composedPrompt = composePromptChain(
|
|
916
|
+
{
|
|
917
|
+
source: documentLayer.source,
|
|
918
|
+
data: parsedDocument.data
|
|
919
|
+
},
|
|
920
|
+
resolvedBase?.layers ?? []
|
|
921
|
+
);
|
|
922
|
+
const merged = mergeLayers([
|
|
923
|
+
...collectDataLayers(chain.slice(0, documentIndex)),
|
|
924
|
+
{
|
|
925
|
+
source: documentLayer.source,
|
|
926
|
+
data: withResolvedPrompt(parsedDocument.data, composedPrompt?.prompt)
|
|
927
|
+
},
|
|
928
|
+
...stripResolvedBasePrompts(resolvedBase?.layers ?? [], composedPrompt?.consumedBaseIndexes ?? /* @__PURE__ */ new Set()),
|
|
929
|
+
...collectDataLayers(chain.slice(documentIndex + 1))
|
|
930
|
+
]);
|
|
931
|
+
if (composedPrompt !== void 0 && merged.sources.prompt === documentLayer.source && composedPrompt.source !== void 0) {
|
|
932
|
+
merged.sources.prompt = composedPrompt.source;
|
|
933
|
+
}
|
|
934
|
+
return {
|
|
935
|
+
data: merged.data,
|
|
936
|
+
sources: merged.sources,
|
|
937
|
+
chain: [documentLayer.filePath, ...resolvedBase?.chain ?? []]
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
function classifyChain(chain) {
|
|
941
|
+
const baseLayers = [];
|
|
942
|
+
const documentLayers = [];
|
|
943
|
+
for (const [index, layer] of chain.entries()) {
|
|
944
|
+
if (isDataLayer(layer)) {
|
|
805
945
|
continue;
|
|
806
946
|
}
|
|
807
|
-
|
|
947
|
+
if (isDocumentLayer(layer)) {
|
|
948
|
+
documentLayers.push({ index, layer });
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
if (isBaseLayer(layer)) {
|
|
952
|
+
baseLayers.push(layer);
|
|
953
|
+
}
|
|
808
954
|
}
|
|
809
|
-
|
|
810
|
-
`);
|
|
955
|
+
if (documentLayers.length !== 1) {
|
|
956
|
+
throw new Error(`Exactly one document layer is required, received ${documentLayers.length}.`);
|
|
957
|
+
}
|
|
958
|
+
return {
|
|
959
|
+
baseLayers,
|
|
960
|
+
documentIndex: documentLayers[0].index,
|
|
961
|
+
documentLayer: documentLayers[0].layer
|
|
962
|
+
};
|
|
811
963
|
}
|
|
812
|
-
function
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
964
|
+
async function resolveBaseChain({
|
|
965
|
+
name,
|
|
966
|
+
baseLayers,
|
|
967
|
+
options,
|
|
968
|
+
optional,
|
|
969
|
+
visited,
|
|
970
|
+
depth
|
|
971
|
+
}) {
|
|
972
|
+
if (depth > MAX_EXTENDS_DEPTH) {
|
|
973
|
+
throw new Error(`Maximum extends depth exceeded (${MAX_EXTENDS_DEPTH}).`);
|
|
974
|
+
}
|
|
975
|
+
let discoveredBase;
|
|
976
|
+
try {
|
|
977
|
+
discoveredBase = await findBase(
|
|
978
|
+
name,
|
|
979
|
+
baseLayers.map((layer) => layer.path),
|
|
980
|
+
options.fs
|
|
981
|
+
);
|
|
982
|
+
} catch (error2) {
|
|
983
|
+
if (optional && isBaseNotFoundError(error2)) {
|
|
984
|
+
return void 0;
|
|
985
|
+
}
|
|
986
|
+
throw error2;
|
|
818
987
|
}
|
|
819
|
-
if (
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
988
|
+
if (visited.has(discoveredBase.filePath)) {
|
|
989
|
+
if (optional) {
|
|
990
|
+
return void 0;
|
|
991
|
+
}
|
|
992
|
+
throw new Error(
|
|
993
|
+
`Circular extends detected.
|
|
994
|
+
Visited files:
|
|
995
|
+
- ${[...visited, discoveredBase.filePath].join("\n- ")}`
|
|
823
996
|
);
|
|
824
|
-
return;
|
|
825
997
|
}
|
|
826
|
-
|
|
998
|
+
const matchedBaseIndex = baseLayers.findIndex(
|
|
999
|
+
(layer) => layer.path === path6.dirname(discoveredBase.filePath)
|
|
1000
|
+
);
|
|
1001
|
+
if (matchedBaseIndex === -1) {
|
|
1002
|
+
throw new Error(`Resolved base is outside configured base paths: ${discoveredBase.filePath}`);
|
|
1003
|
+
}
|
|
1004
|
+
const parsedBase = parseDocument(discoveredBase.content, discoveredBase.filePath);
|
|
1005
|
+
const nextVisited = new Set(visited);
|
|
1006
|
+
nextVisited.add(discoveredBase.filePath);
|
|
1007
|
+
const nestedBase = parsedBase.extends ? await resolveBaseChain({
|
|
1008
|
+
name: getBaseName(discoveredBase.filePath),
|
|
1009
|
+
baseLayers: baseLayers.slice(matchedBaseIndex + 1),
|
|
1010
|
+
options,
|
|
1011
|
+
optional: false,
|
|
1012
|
+
visited: nextVisited,
|
|
1013
|
+
depth: depth + 1
|
|
1014
|
+
}) : void 0;
|
|
1015
|
+
return {
|
|
1016
|
+
layers: [
|
|
1017
|
+
{
|
|
1018
|
+
source: baseLayers[matchedBaseIndex].source,
|
|
1019
|
+
data: parsedBase.data
|
|
1020
|
+
},
|
|
1021
|
+
...nestedBase?.layers ?? []
|
|
1022
|
+
],
|
|
1023
|
+
chain: [discoveredBase.filePath, ...nestedBase?.chain ?? []]
|
|
1024
|
+
};
|
|
827
1025
|
}
|
|
828
|
-
function
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1026
|
+
function collectDataLayers(chain) {
|
|
1027
|
+
return chain.filter(isDataLayer);
|
|
1028
|
+
}
|
|
1029
|
+
function composePromptChain(documentLayer, baseLayers) {
|
|
1030
|
+
const documentPrompt = documentLayer.data.prompt;
|
|
1031
|
+
if (documentPrompt !== void 0 && typeof documentPrompt !== "string") {
|
|
1032
|
+
return void 0;
|
|
834
1033
|
}
|
|
835
|
-
if (
|
|
836
|
-
|
|
837
|
-
`${JSON.stringify({ level: "info", message: stripAnsi(msg) })}
|
|
838
|
-
`
|
|
839
|
-
);
|
|
840
|
-
return;
|
|
1034
|
+
if (documentPrompt !== void 0) {
|
|
1035
|
+
assertValidYieldCount(documentPrompt);
|
|
841
1036
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
const
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
1037
|
+
let prompt = documentPrompt;
|
|
1038
|
+
let source = prompt === void 0 || prompt === "" ? void 0 : documentLayer.source;
|
|
1039
|
+
const consumedBaseIndexes = /* @__PURE__ */ new Set();
|
|
1040
|
+
for (const [index, layer] of baseLayers.entries()) {
|
|
1041
|
+
const candidate = layer.data.prompt;
|
|
1042
|
+
if (candidate === void 0) {
|
|
1043
|
+
continue;
|
|
1044
|
+
}
|
|
1045
|
+
if (typeof candidate !== "string") {
|
|
1046
|
+
break;
|
|
1047
|
+
}
|
|
1048
|
+
assertValidYieldCount(candidate);
|
|
1049
|
+
consumedBaseIndexes.add(index);
|
|
1050
|
+
prompt = composeAdjacentPrompts(prompt, candidate);
|
|
1051
|
+
if (source === void 0 && candidate !== "") {
|
|
1052
|
+
source = layer.source;
|
|
1053
|
+
}
|
|
850
1054
|
}
|
|
851
|
-
if (
|
|
852
|
-
|
|
853
|
-
`${JSON.stringify({ level: "success", message: stripAnsi(msg) })}
|
|
854
|
-
`
|
|
855
|
-
);
|
|
856
|
-
return;
|
|
1055
|
+
if (prompt !== void 0 && prompt.includes(YIELD_TOKEN)) {
|
|
1056
|
+
throw new Error('Final resolved prompt contains an unresolved "{{yield}}" token.');
|
|
857
1057
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
function warn(msg) {
|
|
861
|
-
const format = resolveOutputFormat();
|
|
862
|
-
if (format === "markdown") {
|
|
863
|
-
process.stdout.write(`- **warning:** ${stripAnsi(msg)}
|
|
864
|
-
`);
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
if (format === "json") {
|
|
868
|
-
process.stdout.write(
|
|
869
|
-
`${JSON.stringify({ level: "warn", message: stripAnsi(msg) })}
|
|
870
|
-
`
|
|
871
|
-
);
|
|
872
|
-
return;
|
|
1058
|
+
if (prompt === void 0) {
|
|
1059
|
+
return void 0;
|
|
873
1060
|
}
|
|
874
|
-
|
|
1061
|
+
return {
|
|
1062
|
+
consumedBaseIndexes,
|
|
1063
|
+
prompt,
|
|
1064
|
+
source
|
|
1065
|
+
};
|
|
875
1066
|
}
|
|
876
|
-
function
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
process.stdout.write(`- **error:** ${stripAnsi(msg)}
|
|
880
|
-
`);
|
|
881
|
-
return;
|
|
1067
|
+
function composeAdjacentPrompts(high, low) {
|
|
1068
|
+
if (high === void 0 || high === "") {
|
|
1069
|
+
return low.includes(YIELD_TOKEN) ? replaceYield(low, "") : low;
|
|
882
1070
|
}
|
|
883
|
-
if (
|
|
884
|
-
|
|
885
|
-
`${JSON.stringify({ level: "error", message: stripAnsi(msg) })}
|
|
886
|
-
`
|
|
887
|
-
);
|
|
888
|
-
return;
|
|
1071
|
+
if (high.includes(YIELD_TOKEN)) {
|
|
1072
|
+
return replaceYield(high, low);
|
|
889
1073
|
}
|
|
890
|
-
|
|
1074
|
+
if (low.includes(YIELD_TOKEN)) {
|
|
1075
|
+
return replaceYield(low, high);
|
|
1076
|
+
}
|
|
1077
|
+
return high;
|
|
891
1078
|
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
success,
|
|
895
|
-
message,
|
|
896
|
-
warn,
|
|
897
|
-
error
|
|
898
|
-
};
|
|
899
|
-
|
|
900
|
-
// packages/design-system/src/components/logger.ts
|
|
901
|
-
function createLogger(emitter) {
|
|
902
|
-
const emit = (level, message2) => {
|
|
903
|
-
if (emitter) {
|
|
904
|
-
emitter(message2);
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
907
|
-
if (level === "success") {
|
|
908
|
-
log.success(message2);
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
911
|
-
if (level === "warn") {
|
|
912
|
-
log.warn(message2);
|
|
913
|
-
return;
|
|
914
|
-
}
|
|
915
|
-
if (level === "error") {
|
|
916
|
-
log.error(message2);
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
log.info(message2);
|
|
920
|
-
};
|
|
921
|
-
return {
|
|
922
|
-
info(message2) {
|
|
923
|
-
emit("info", message2);
|
|
924
|
-
},
|
|
925
|
-
success(message2) {
|
|
926
|
-
emit("success", message2);
|
|
927
|
-
},
|
|
928
|
-
warn(message2) {
|
|
929
|
-
emit("warn", message2);
|
|
930
|
-
},
|
|
931
|
-
error(message2) {
|
|
932
|
-
emit("error", message2);
|
|
933
|
-
},
|
|
934
|
-
resolved(label, value) {
|
|
935
|
-
if (emitter) {
|
|
936
|
-
emitter(`${label}: ${value}`);
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
log.message(`${label}
|
|
940
|
-
${value}`, { symbol: symbols.resolved });
|
|
941
|
-
},
|
|
942
|
-
errorResolved(label, value) {
|
|
943
|
-
if (emitter) {
|
|
944
|
-
emitter(`${label}: ${value}`);
|
|
945
|
-
return;
|
|
946
|
-
}
|
|
947
|
-
log.message(`${label}
|
|
948
|
-
${value}`, { symbol: symbols.errorResolved });
|
|
949
|
-
},
|
|
950
|
-
message(message2, symbol) {
|
|
951
|
-
if (emitter) {
|
|
952
|
-
emitter(message2);
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
log.message(message2, { symbol: symbol ?? chalk6.gray("\u2502") });
|
|
956
|
-
}
|
|
957
|
-
};
|
|
1079
|
+
function replaceYield(prompt, replacement) {
|
|
1080
|
+
return prompt.replace(YIELD_TOKEN, replacement);
|
|
958
1081
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
// packages/design-system/src/acp/components.ts
|
|
965
|
-
import chalk7 from "chalk";
|
|
966
|
-
|
|
967
|
-
// packages/design-system/src/acp/writer.ts
|
|
968
|
-
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
969
|
-
var storage = new AsyncLocalStorage2();
|
|
970
|
-
|
|
971
|
-
// packages/design-system/src/acp/components.ts
|
|
972
|
-
var AGENT_PREFIX = `${chalk7.green.bold("\u2713")} agent: `;
|
|
973
|
-
|
|
974
|
-
// packages/design-system/src/dashboard/buffer.ts
|
|
975
|
-
import chalk8 from "chalk";
|
|
976
|
-
|
|
977
|
-
// packages/design-system/src/dashboard/terminal.ts
|
|
978
|
-
import readline from "node:readline";
|
|
979
|
-
import { PassThrough } from "node:stream";
|
|
980
|
-
|
|
981
|
-
// packages/design-system/src/prompts/index.ts
|
|
982
|
-
import chalk15 from "chalk";
|
|
983
|
-
import * as clack from "@clack/prompts";
|
|
984
|
-
|
|
985
|
-
// packages/design-system/src/prompts/primitives/cancel.ts
|
|
986
|
-
import chalk9 from "chalk";
|
|
987
|
-
import { isCancel } from "@clack/prompts";
|
|
988
|
-
|
|
989
|
-
// packages/design-system/src/prompts/primitives/intro.ts
|
|
990
|
-
import chalk10 from "chalk";
|
|
991
|
-
|
|
992
|
-
// packages/design-system/src/prompts/primitives/note.ts
|
|
993
|
-
import chalk11 from "chalk";
|
|
994
|
-
|
|
995
|
-
// packages/design-system/src/prompts/primitives/outro.ts
|
|
996
|
-
import chalk12 from "chalk";
|
|
997
|
-
|
|
998
|
-
// packages/design-system/src/prompts/primitives/spinner.ts
|
|
999
|
-
import chalk14 from "chalk";
|
|
1000
|
-
|
|
1001
|
-
// packages/design-system/src/static/spinner.ts
|
|
1002
|
-
import chalk13 from "chalk";
|
|
1003
|
-
|
|
1004
|
-
// packages/design-system/src/static/menu.ts
|
|
1005
|
-
import chalk16 from "chalk";
|
|
1006
|
-
|
|
1007
|
-
// packages/agent-spawn/src/autonomous.ts
|
|
1008
|
-
var DEFAULT_ACTIVITY_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
1009
|
-
|
|
1010
|
-
// packages/agent-spawn/src/acp/replay.ts
|
|
1011
|
-
import path2 from "node:path";
|
|
1012
|
-
import { homedir as homedir2 } from "node:os";
|
|
1013
|
-
import { open, readdir } from "node:fs/promises";
|
|
1014
|
-
import { createInterface } from "node:readline";
|
|
1015
|
-
|
|
1016
|
-
// packages/poe-acp-client/src/acp-client.ts
|
|
1017
|
-
import { isAbsolute } from "node:path";
|
|
1018
|
-
|
|
1019
|
-
// packages/poe-acp-client/src/acp-transport.ts
|
|
1020
|
-
import {
|
|
1021
|
-
spawn as spawnChildProcess3
|
|
1022
|
-
} from "node:child_process";
|
|
1023
|
-
|
|
1024
|
-
// packages/poe-acp-client/src/run-report.ts
|
|
1025
|
-
import * as fsPromises from "node:fs/promises";
|
|
1026
|
-
import { homedir } from "node:os";
|
|
1027
|
-
import { join } from "node:path";
|
|
1028
|
-
|
|
1029
|
-
// packages/agent-spawn/src/acp/spawn.ts
|
|
1030
|
-
import { spawn as spawnChildProcess4 } from "node:child_process";
|
|
1031
|
-
|
|
1032
|
-
// packages/agent-spawn/src/acp/middlewares/spawn-log.ts
|
|
1033
|
-
import path3 from "node:path";
|
|
1034
|
-
import { homedir as homedir3 } from "node:os";
|
|
1035
|
-
import { mkdir, open as open2 } from "node:fs/promises";
|
|
1036
|
-
|
|
1037
|
-
// src/utils/command-checks.ts
|
|
1038
|
-
function formatCommandRunnerResult(result) {
|
|
1039
|
-
const stdout = result.stdout.length > 0 ? result.stdout : "<empty>";
|
|
1040
|
-
const stderr = result.stderr.length > 0 ? result.stderr : "<empty>";
|
|
1041
|
-
return `stdout:
|
|
1042
|
-
${stdout}
|
|
1043
|
-
stderr:
|
|
1044
|
-
${stderr}`;
|
|
1082
|
+
function assertValidYieldCount(prompt) {
|
|
1083
|
+
if (countYieldTokens(prompt) > 1) {
|
|
1084
|
+
throw new Error('Prompt composition supports exactly one "{{yield}}" token per prompt.');
|
|
1085
|
+
}
|
|
1045
1086
|
}
|
|
1046
|
-
function
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
1087
|
+
function countYieldTokens(prompt) {
|
|
1088
|
+
return prompt.split(YIELD_TOKEN).length - 1;
|
|
1089
|
+
}
|
|
1090
|
+
function withResolvedPrompt(data, prompt) {
|
|
1091
|
+
if (prompt === void 0) {
|
|
1092
|
+
return data;
|
|
1093
|
+
}
|
|
1053
1094
|
return {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
async run(context) {
|
|
1057
|
-
if (context.isDryRun) {
|
|
1058
|
-
context.logDryRun?.(
|
|
1059
|
-
`Dry run: ${[binaryName, ...args].join(" ")} (expecting "${options.expectedOutput}")`
|
|
1060
|
-
);
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
const result = modeEnv ? await context.runCommand(binaryName, args, { env: modeEnv }) : await context.runCommand(binaryName, args);
|
|
1064
|
-
if (result.exitCode !== 0) {
|
|
1065
|
-
throw new Error(
|
|
1066
|
-
`spawn ${agentId} failed with exit code ${result.exitCode}.
|
|
1067
|
-
${formatCommandRunnerResult(result)}`
|
|
1068
|
-
);
|
|
1069
|
-
}
|
|
1070
|
-
if (!result.stdout.includes(options.expectedOutput)) {
|
|
1071
|
-
throw new Error(
|
|
1072
|
-
`spawn ${agentId}: expected "${options.expectedOutput}" in stdout.
|
|
1073
|
-
${formatCommandRunnerResult(result)}`
|
|
1074
|
-
);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1095
|
+
...data,
|
|
1096
|
+
prompt
|
|
1077
1097
|
};
|
|
1078
1098
|
}
|
|
1079
|
-
function
|
|
1080
|
-
return {
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
async run({ runCommand: runCommand2 }) {
|
|
1084
|
-
const commonPaths = [
|
|
1085
|
-
`/usr/local/bin/${binaryName}`,
|
|
1086
|
-
`/usr/bin/${binaryName}`,
|
|
1087
|
-
`$HOME/.local/bin/${binaryName}`,
|
|
1088
|
-
`$HOME/.claude/local/bin/${binaryName}`
|
|
1089
|
-
];
|
|
1090
|
-
const detectors = [
|
|
1091
|
-
{
|
|
1092
|
-
command: "which",
|
|
1093
|
-
args: [binaryName],
|
|
1094
|
-
validate: (result) => result.exitCode === 0
|
|
1095
|
-
},
|
|
1096
|
-
{
|
|
1097
|
-
command: "where",
|
|
1098
|
-
args: [binaryName],
|
|
1099
|
-
validate: (result) => result.exitCode === 0 && result.stdout.trim().length > 0
|
|
1100
|
-
},
|
|
1101
|
-
// Check common installation paths using shell expansion for $HOME
|
|
1102
|
-
{
|
|
1103
|
-
command: "sh",
|
|
1104
|
-
args: [
|
|
1105
|
-
"-c",
|
|
1106
|
-
commonPaths.map((p) => `test -f "${p}"`).join(" || ")
|
|
1107
|
-
],
|
|
1108
|
-
validate: (result) => result.exitCode === 0
|
|
1109
|
-
}
|
|
1110
|
-
];
|
|
1111
|
-
for (const detector of detectors) {
|
|
1112
|
-
const result = await runCommand2(detector.command, detector.args);
|
|
1113
|
-
if (detector.validate(result)) {
|
|
1114
|
-
return;
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
throw new Error(`${binaryName} CLI binary not found on PATH.`);
|
|
1099
|
+
function stripResolvedBasePrompts(layers, consumedBaseIndexes) {
|
|
1100
|
+
return layers.map((layer, index) => {
|
|
1101
|
+
if (!consumedBaseIndexes.has(index) || typeof layer.data.prompt !== "string") {
|
|
1102
|
+
return layer;
|
|
1118
1103
|
}
|
|
1119
|
-
|
|
1104
|
+
const { prompt: ignoredPrompt, ...data } = layer.data;
|
|
1105
|
+
void ignoredPrompt;
|
|
1106
|
+
return {
|
|
1107
|
+
source: layer.source,
|
|
1108
|
+
data
|
|
1109
|
+
};
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
function getBaseName(filePath) {
|
|
1113
|
+
return path6.basename(filePath, path6.extname(filePath));
|
|
1114
|
+
}
|
|
1115
|
+
function shouldResolveBase(parsedDocument, autoExtend) {
|
|
1116
|
+
return parsedDocument.extends || autoExtend === true && !parsedDocument.hasExtendsField;
|
|
1117
|
+
}
|
|
1118
|
+
function isBaseNotFoundError(error2) {
|
|
1119
|
+
return error2 instanceof Error && error2.message.startsWith('Base "') && error2.message.includes('" not found.\nChecked paths:');
|
|
1120
|
+
}
|
|
1121
|
+
function isDataLayer(layer) {
|
|
1122
|
+
return "data" in layer;
|
|
1123
|
+
}
|
|
1124
|
+
function isDocumentLayer(layer) {
|
|
1125
|
+
return "filePath" in layer && "content" in layer;
|
|
1126
|
+
}
|
|
1127
|
+
function isBaseLayer(layer) {
|
|
1128
|
+
return "path" in layer;
|
|
1120
1129
|
}
|
|
1121
1130
|
|
|
1122
1131
|
// packages/config-mutations/src/mutations/config-mutation.ts
|
|
@@ -1245,7 +1254,7 @@ import * as jsonc from "jsonc-parser";
|
|
|
1245
1254
|
function isConfigObject(value) {
|
|
1246
1255
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1247
1256
|
}
|
|
1248
|
-
function
|
|
1257
|
+
function parse2(content) {
|
|
1249
1258
|
if (!content || content.trim() === "") {
|
|
1250
1259
|
return {};
|
|
1251
1260
|
}
|
|
@@ -1318,7 +1327,7 @@ function prune2(obj, shape) {
|
|
|
1318
1327
|
return { changed, result };
|
|
1319
1328
|
}
|
|
1320
1329
|
var jsonFormat = {
|
|
1321
|
-
parse:
|
|
1330
|
+
parse: parse2,
|
|
1322
1331
|
serialize,
|
|
1323
1332
|
merge: merge2,
|
|
1324
1333
|
prune: prune2
|
|
@@ -1329,7 +1338,7 @@ import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
|
1329
1338
|
function isConfigObject2(value) {
|
|
1330
1339
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1331
1340
|
}
|
|
1332
|
-
function
|
|
1341
|
+
function parse3(content) {
|
|
1333
1342
|
if (!content || content.trim() === "") {
|
|
1334
1343
|
return {};
|
|
1335
1344
|
}
|
|
@@ -1393,22 +1402,22 @@ function prune3(obj, shape) {
|
|
|
1393
1402
|
return { changed, result };
|
|
1394
1403
|
}
|
|
1395
1404
|
var tomlFormat = {
|
|
1396
|
-
parse:
|
|
1405
|
+
parse: parse3,
|
|
1397
1406
|
serialize: serialize2,
|
|
1398
1407
|
merge: merge3,
|
|
1399
1408
|
prune: prune3
|
|
1400
1409
|
};
|
|
1401
1410
|
|
|
1402
1411
|
// packages/config-mutations/src/formats/yaml.ts
|
|
1403
|
-
import { parse as
|
|
1412
|
+
import { parse as parseYaml2, stringify as stringifyYaml } from "yaml";
|
|
1404
1413
|
function isConfigObject3(value) {
|
|
1405
1414
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1406
1415
|
}
|
|
1407
|
-
function
|
|
1416
|
+
function parse4(content) {
|
|
1408
1417
|
if (!content || content.trim() === "") {
|
|
1409
1418
|
return {};
|
|
1410
1419
|
}
|
|
1411
|
-
const parsed =
|
|
1420
|
+
const parsed = parseYaml2(content);
|
|
1412
1421
|
if (parsed === null || parsed === void 0) {
|
|
1413
1422
|
return {};
|
|
1414
1423
|
}
|
|
@@ -1468,7 +1477,7 @@ function prune4(obj, shape) {
|
|
|
1468
1477
|
return { changed, result };
|
|
1469
1478
|
}
|
|
1470
1479
|
var yamlFormat = {
|
|
1471
|
-
parse:
|
|
1480
|
+
parse: parse4,
|
|
1472
1481
|
serialize: serialize3,
|
|
1473
1482
|
merge: merge4,
|
|
1474
1483
|
prune: prune4
|
|
@@ -1499,20 +1508,20 @@ function getConfigFormat(pathOrFormat) {
|
|
|
1499
1508
|
}
|
|
1500
1509
|
return formatRegistry[formatName];
|
|
1501
1510
|
}
|
|
1502
|
-
function
|
|
1503
|
-
const ext = getExtension(
|
|
1511
|
+
function detectFormat2(path22) {
|
|
1512
|
+
const ext = getExtension(path22);
|
|
1504
1513
|
return extensionMap[ext];
|
|
1505
1514
|
}
|
|
1506
|
-
function getExtension(
|
|
1507
|
-
const lastDot =
|
|
1515
|
+
function getExtension(path22) {
|
|
1516
|
+
const lastDot = path22.lastIndexOf(".");
|
|
1508
1517
|
if (lastDot === -1) {
|
|
1509
1518
|
return "";
|
|
1510
1519
|
}
|
|
1511
|
-
return
|
|
1520
|
+
return path22.slice(lastDot).toLowerCase();
|
|
1512
1521
|
}
|
|
1513
1522
|
|
|
1514
1523
|
// packages/config-mutations/src/execution/path-utils.ts
|
|
1515
|
-
import
|
|
1524
|
+
import path7 from "node:path";
|
|
1516
1525
|
function expandHome(targetPath, homeDir) {
|
|
1517
1526
|
if (!targetPath?.startsWith("~")) {
|
|
1518
1527
|
return targetPath;
|
|
@@ -1529,7 +1538,7 @@ function expandHome(targetPath, homeDir) {
|
|
|
1529
1538
|
remainder = remainder.slice(1);
|
|
1530
1539
|
}
|
|
1531
1540
|
}
|
|
1532
|
-
return remainder.length === 0 ? homeDir :
|
|
1541
|
+
return remainder.length === 0 ? homeDir : path7.join(homeDir, remainder);
|
|
1533
1542
|
}
|
|
1534
1543
|
function validateHomePath(targetPath) {
|
|
1535
1544
|
if (typeof targetPath !== "string" || targetPath.length === 0) {
|
|
@@ -1547,19 +1556,19 @@ function resolvePath(rawPath, homeDir, pathMapper) {
|
|
|
1547
1556
|
if (!pathMapper) {
|
|
1548
1557
|
return expanded;
|
|
1549
1558
|
}
|
|
1550
|
-
const rawDirectory =
|
|
1559
|
+
const rawDirectory = path7.dirname(expanded);
|
|
1551
1560
|
const mappedDirectory = pathMapper.mapTargetDirectory({
|
|
1552
1561
|
targetDirectory: rawDirectory
|
|
1553
1562
|
});
|
|
1554
|
-
const filename =
|
|
1555
|
-
return filename.length === 0 ? mappedDirectory :
|
|
1563
|
+
const filename = path7.basename(expanded);
|
|
1564
|
+
return filename.length === 0 ? mappedDirectory : path7.join(mappedDirectory, filename);
|
|
1556
1565
|
}
|
|
1557
1566
|
|
|
1558
1567
|
// packages/config-mutations/src/fs-utils.ts
|
|
1559
1568
|
function isNotFound(error2) {
|
|
1560
1569
|
return typeof error2 === "object" && error2 !== null && "code" in error2 && error2.code === "ENOENT";
|
|
1561
1570
|
}
|
|
1562
|
-
async function
|
|
1571
|
+
async function readFileIfExists2(fs, target) {
|
|
1563
1572
|
try {
|
|
1564
1573
|
return await fs.readFile(target, "utf8");
|
|
1565
1574
|
} catch (error2) {
|
|
@@ -1810,8 +1819,8 @@ async function applyChmod(mutation, context, options) {
|
|
|
1810
1819
|
};
|
|
1811
1820
|
}
|
|
1812
1821
|
try {
|
|
1813
|
-
const
|
|
1814
|
-
const currentMode = typeof
|
|
1822
|
+
const stat2 = await context.fs.stat(targetPath);
|
|
1823
|
+
const currentMode = typeof stat2.mode === "number" ? stat2.mode & 511 : null;
|
|
1815
1824
|
if (currentMode === mutation.mode) {
|
|
1816
1825
|
return {
|
|
1817
1826
|
outcome: { changed: false, effect: "none", detail: "noop" },
|
|
@@ -1843,7 +1852,7 @@ async function applyBackup(mutation, context, options) {
|
|
|
1843
1852
|
label: mutation.label ?? describeMutation(mutation.kind, targetPath),
|
|
1844
1853
|
targetPath
|
|
1845
1854
|
};
|
|
1846
|
-
const content = await
|
|
1855
|
+
const content = await readFileIfExists2(context.fs, targetPath);
|
|
1847
1856
|
if (content === null) {
|
|
1848
1857
|
return {
|
|
1849
1858
|
outcome: { changed: false, effect: "none", detail: "noop" },
|
|
@@ -1867,14 +1876,14 @@ async function applyConfigMerge(mutation, context, options) {
|
|
|
1867
1876
|
label: mutation.label ?? describeMutation(mutation.kind, targetPath),
|
|
1868
1877
|
targetPath
|
|
1869
1878
|
};
|
|
1870
|
-
const formatName = mutation.format ??
|
|
1879
|
+
const formatName = mutation.format ?? detectFormat2(rawPath);
|
|
1871
1880
|
if (!formatName) {
|
|
1872
1881
|
throw new Error(
|
|
1873
1882
|
`Cannot detect config format for "${rawPath}". Provide explicit format option.`
|
|
1874
1883
|
);
|
|
1875
1884
|
}
|
|
1876
1885
|
const format = getConfigFormat(formatName);
|
|
1877
|
-
const rawContent = await
|
|
1886
|
+
const rawContent = await readFileIfExists2(context.fs, targetPath);
|
|
1878
1887
|
let current;
|
|
1879
1888
|
try {
|
|
1880
1889
|
current = rawContent === null ? {} : format.parse(rawContent);
|
|
@@ -1913,14 +1922,14 @@ async function applyConfigPrune(mutation, context, options) {
|
|
|
1913
1922
|
label: mutation.label ?? describeMutation(mutation.kind, targetPath),
|
|
1914
1923
|
targetPath
|
|
1915
1924
|
};
|
|
1916
|
-
const rawContent = await
|
|
1925
|
+
const rawContent = await readFileIfExists2(context.fs, targetPath);
|
|
1917
1926
|
if (rawContent === null) {
|
|
1918
1927
|
return {
|
|
1919
1928
|
outcome: { changed: false, effect: "none", detail: "noop" },
|
|
1920
1929
|
details
|
|
1921
1930
|
};
|
|
1922
1931
|
}
|
|
1923
|
-
const formatName = mutation.format ??
|
|
1932
|
+
const formatName = mutation.format ?? detectFormat2(rawPath);
|
|
1924
1933
|
if (!formatName) {
|
|
1925
1934
|
throw new Error(
|
|
1926
1935
|
`Cannot detect config format for "${rawPath}". Provide explicit format option.`
|
|
@@ -1976,14 +1985,14 @@ async function applyConfigTransform(mutation, context, options) {
|
|
|
1976
1985
|
label: mutation.label ?? describeMutation(mutation.kind, targetPath),
|
|
1977
1986
|
targetPath
|
|
1978
1987
|
};
|
|
1979
|
-
const formatName = mutation.format ??
|
|
1988
|
+
const formatName = mutation.format ?? detectFormat2(rawPath);
|
|
1980
1989
|
if (!formatName) {
|
|
1981
1990
|
throw new Error(
|
|
1982
1991
|
`Cannot detect config format for "${rawPath}". Provide explicit format option.`
|
|
1983
1992
|
);
|
|
1984
1993
|
}
|
|
1985
1994
|
const format = getConfigFormat(formatName);
|
|
1986
|
-
const rawContent = await
|
|
1995
|
+
const rawContent = await readFileIfExists2(context.fs, targetPath);
|
|
1987
1996
|
let current;
|
|
1988
1997
|
try {
|
|
1989
1998
|
current = rawContent === null ? {} : format.parse(rawContent);
|
|
@@ -2083,7 +2092,7 @@ async function applyTemplateMerge(mutation, context, options, formatName) {
|
|
|
2083
2092
|
{ cause: error2 }
|
|
2084
2093
|
);
|
|
2085
2094
|
}
|
|
2086
|
-
const rawContent = await
|
|
2095
|
+
const rawContent = await readFileIfExists2(context.fs, targetPath);
|
|
2087
2096
|
let current;
|
|
2088
2097
|
try {
|
|
2089
2098
|
current = rawContent === null ? {} : format.parse(rawContent);
|
|
@@ -2163,6 +2172,2631 @@ function isConfigObject5(value) {
|
|
|
2163
2172
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2164
2173
|
}
|
|
2165
2174
|
|
|
2175
|
+
// packages/poe-code-config/src/store.ts
|
|
2176
|
+
async function readMergedDocument(fs, globalPath, projectPath) {
|
|
2177
|
+
const globalDocument = await readStoredDocument(fs, globalPath);
|
|
2178
|
+
if (!projectPath || projectPath === globalPath) {
|
|
2179
|
+
return globalDocument.data;
|
|
2180
|
+
}
|
|
2181
|
+
const projectDocument = await readStoredDocument(fs, projectPath);
|
|
2182
|
+
const resolved = await resolve(
|
|
2183
|
+
[
|
|
2184
|
+
{
|
|
2185
|
+
source: "project",
|
|
2186
|
+
filePath: projectPath,
|
|
2187
|
+
content: projectDocument.content
|
|
2188
|
+
},
|
|
2189
|
+
{
|
|
2190
|
+
source: "base",
|
|
2191
|
+
path: path8.dirname(globalPath)
|
|
2192
|
+
}
|
|
2193
|
+
],
|
|
2194
|
+
{
|
|
2195
|
+
fs: createResolvedConfigFs(fs, globalPath, globalDocument.content),
|
|
2196
|
+
autoExtend: true
|
|
2197
|
+
}
|
|
2198
|
+
);
|
|
2199
|
+
return normalizeDocument(resolved.data);
|
|
2200
|
+
}
|
|
2201
|
+
async function readStoredDocument(fs, filePath) {
|
|
2202
|
+
try {
|
|
2203
|
+
const raw = await fs.readFile(filePath, "utf8");
|
|
2204
|
+
return await parseStoredDocument(fs, filePath, raw);
|
|
2205
|
+
} catch (error2) {
|
|
2206
|
+
if (isNotFound(error2)) {
|
|
2207
|
+
return {
|
|
2208
|
+
content: EMPTY_DOCUMENT,
|
|
2209
|
+
data: {}
|
|
2210
|
+
};
|
|
2211
|
+
}
|
|
2212
|
+
throw error2;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
async function parseStoredDocument(fs, filePath, raw) {
|
|
2216
|
+
try {
|
|
2217
|
+
return {
|
|
2218
|
+
content: raw,
|
|
2219
|
+
data: normalizeDocument(JSON.parse(raw))
|
|
2220
|
+
};
|
|
2221
|
+
} catch (error2) {
|
|
2222
|
+
if (error2 instanceof SyntaxError) {
|
|
2223
|
+
await recoverInvalidDocument(fs, filePath, raw);
|
|
2224
|
+
return {
|
|
2225
|
+
content: EMPTY_DOCUMENT,
|
|
2226
|
+
data: {}
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
throw error2;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
function normalizeDocument(value) {
|
|
2233
|
+
if (!isRecord2(value)) {
|
|
2234
|
+
return {};
|
|
2235
|
+
}
|
|
2236
|
+
const document = {};
|
|
2237
|
+
for (const [scope, scopeValues] of Object.entries(value)) {
|
|
2238
|
+
const normalizedValues = normalizeScopeValues(scopeValues);
|
|
2239
|
+
if (Object.keys(normalizedValues).length > 0) {
|
|
2240
|
+
document[scope] = normalizedValues;
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
return document;
|
|
2244
|
+
}
|
|
2245
|
+
function normalizeScopeValues(value) {
|
|
2246
|
+
if (!isRecord2(value)) {
|
|
2247
|
+
return {};
|
|
2248
|
+
}
|
|
2249
|
+
const normalized = {};
|
|
2250
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
2251
|
+
if (entry !== void 0) {
|
|
2252
|
+
normalized[key] = entry;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
return normalized;
|
|
2256
|
+
}
|
|
2257
|
+
function createResolvedConfigFs(fs, globalPath, globalContent) {
|
|
2258
|
+
return {
|
|
2259
|
+
readFile(filePath, _encoding) {
|
|
2260
|
+
if (filePath === globalPath) {
|
|
2261
|
+
return Promise.resolve(globalContent);
|
|
2262
|
+
}
|
|
2263
|
+
return fs.readFile(filePath, "utf8");
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
async function recoverInvalidDocument(fs, filePath, content) {
|
|
2268
|
+
await fs.mkdir(path8.dirname(filePath), { recursive: true });
|
|
2269
|
+
const backupPath = createInvalidBackupPath(filePath);
|
|
2270
|
+
await fs.writeFile(backupPath, content, { encoding: "utf8" });
|
|
2271
|
+
await fs.writeFile(filePath, EMPTY_DOCUMENT, { encoding: "utf8" });
|
|
2272
|
+
}
|
|
2273
|
+
function createInvalidBackupPath(filePath) {
|
|
2274
|
+
const directory = path8.dirname(filePath);
|
|
2275
|
+
const baseName = path8.basename(filePath);
|
|
2276
|
+
return path8.join(directory, `${baseName}.invalid-${createTimestamp()}.json`);
|
|
2277
|
+
}
|
|
2278
|
+
function isRecord2(value) {
|
|
2279
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
2280
|
+
}
|
|
2281
|
+
function resolveConfigPath(homeDir) {
|
|
2282
|
+
return path8.join(homeDir, ".poe-code", "config.json");
|
|
2283
|
+
}
|
|
2284
|
+
function resolveProjectConfigPath(cwd) {
|
|
2285
|
+
return path8.join(cwd, ".poe-code", "config.json");
|
|
2286
|
+
}
|
|
2287
|
+
var EMPTY_DOCUMENT = `${JSON.stringify({}, null, 2)}
|
|
2288
|
+
`;
|
|
2289
|
+
|
|
2290
|
+
// packages/poe-code-config/src/resolve.ts
|
|
2291
|
+
function resolveScope(schema, fileValues, env = {}) {
|
|
2292
|
+
const resolved = {};
|
|
2293
|
+
for (const key of Object.keys(schema)) {
|
|
2294
|
+
const field = schema[key];
|
|
2295
|
+
const envValue = resolveEnvValue(field, env, key);
|
|
2296
|
+
const fileValue = resolveFileValue(field, fileValues?.[key], key);
|
|
2297
|
+
resolved[key] = envValue ?? fileValue ?? field.default;
|
|
2298
|
+
}
|
|
2299
|
+
return resolved;
|
|
2300
|
+
}
|
|
2301
|
+
function resolveEnvValue(field, env, key) {
|
|
2302
|
+
if (!field.env) {
|
|
2303
|
+
return void 0;
|
|
2304
|
+
}
|
|
2305
|
+
const raw = env[field.env];
|
|
2306
|
+
if (raw === void 0) {
|
|
2307
|
+
return void 0;
|
|
2308
|
+
}
|
|
2309
|
+
return coerceValue(field, raw, key);
|
|
2310
|
+
}
|
|
2311
|
+
function resolveFileValue(field, value, key) {
|
|
2312
|
+
return coerceValue(field, value, key);
|
|
2313
|
+
}
|
|
2314
|
+
function coerceValue(field, value, key) {
|
|
2315
|
+
switch (field.type) {
|
|
2316
|
+
case "string":
|
|
2317
|
+
return typeof value === "string" ? value : void 0;
|
|
2318
|
+
case "number":
|
|
2319
|
+
return coerceNumber(value);
|
|
2320
|
+
case "boolean":
|
|
2321
|
+
return coerceBoolean(value);
|
|
2322
|
+
case "json":
|
|
2323
|
+
return coerceJson(field, value, key);
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
function coerceNumber(value) {
|
|
2327
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
2328
|
+
return value;
|
|
2329
|
+
}
|
|
2330
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
2331
|
+
return void 0;
|
|
2332
|
+
}
|
|
2333
|
+
const parsed = Number(value);
|
|
2334
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
2335
|
+
}
|
|
2336
|
+
function coerceBoolean(value) {
|
|
2337
|
+
if (typeof value === "boolean") {
|
|
2338
|
+
return value;
|
|
2339
|
+
}
|
|
2340
|
+
if (value === "true" || value === "1") {
|
|
2341
|
+
return true;
|
|
2342
|
+
}
|
|
2343
|
+
if (value === "false" || value === "0") {
|
|
2344
|
+
return false;
|
|
2345
|
+
}
|
|
2346
|
+
return void 0;
|
|
2347
|
+
}
|
|
2348
|
+
function coerceJson(field, value, key) {
|
|
2349
|
+
if (value === void 0) {
|
|
2350
|
+
return void 0;
|
|
2351
|
+
}
|
|
2352
|
+
const parsedValue = parseJsonValue(value, key);
|
|
2353
|
+
try {
|
|
2354
|
+
return field.parse(parsedValue);
|
|
2355
|
+
} catch (error2) {
|
|
2356
|
+
const message2 = error2 instanceof Error ? error2.message : "Invalid JSON value.";
|
|
2357
|
+
throw new Error(`Invalid config value for "${key}": ${message2}`);
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
function parseJsonValue(value, key) {
|
|
2361
|
+
if (typeof value !== "string") {
|
|
2362
|
+
return value;
|
|
2363
|
+
}
|
|
2364
|
+
try {
|
|
2365
|
+
return JSON.parse(value);
|
|
2366
|
+
} catch {
|
|
2367
|
+
throw new Error(`Invalid config value for "${key}": expected valid JSON.`);
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
// packages/poe-code-config/src/inspect.ts
|
|
2372
|
+
import path9 from "node:path";
|
|
2373
|
+
var EMPTY_DOCUMENT2 = `${JSON.stringify({}, null, 2)}
|
|
2374
|
+
`;
|
|
2375
|
+
|
|
2376
|
+
// packages/poe-code-config/src/state/index.ts
|
|
2377
|
+
import os2 from "node:os";
|
|
2378
|
+
|
|
2379
|
+
// packages/poe-code-config/src/state/jobs.ts
|
|
2380
|
+
import path10 from "node:path";
|
|
2381
|
+
|
|
2382
|
+
// packages/poe-code-config/src/state/fs.ts
|
|
2383
|
+
import * as nodeFs2 from "node:fs/promises";
|
|
2384
|
+
|
|
2385
|
+
// packages/poe-code-config/src/state/templates.ts
|
|
2386
|
+
import path11 from "node:path";
|
|
2387
|
+
|
|
2388
|
+
// packages/agent-harness-tools/src/execution-env.ts
|
|
2389
|
+
var executionEnvFactories = /* @__PURE__ */ new Map();
|
|
2390
|
+
function registerExecutionEnvFactory(factory) {
|
|
2391
|
+
executionEnvFactories.set(factory.type, factory);
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
// packages/agent-harness-tools/src/workspace-transfer.ts
|
|
2395
|
+
import { createHash } from "node:crypto";
|
|
2396
|
+
import { promises as nodeFs3 } from "node:fs";
|
|
2397
|
+
import path12 from "node:path";
|
|
2398
|
+
|
|
2399
|
+
// packages/process-runner/src/docker/context.ts
|
|
2400
|
+
import { execSync } from "node:child_process";
|
|
2401
|
+
function detectContext() {
|
|
2402
|
+
try {
|
|
2403
|
+
const output = execSync("colima list --json", {
|
|
2404
|
+
encoding: "utf-8",
|
|
2405
|
+
stdio: ["pipe", "pipe", "ignore"]
|
|
2406
|
+
});
|
|
2407
|
+
const lines = output.trim().split("\n").filter(Boolean);
|
|
2408
|
+
for (const line of lines) {
|
|
2409
|
+
const profile = JSON.parse(line);
|
|
2410
|
+
if (profile.status === "Running" && profile.runtime === "docker") {
|
|
2411
|
+
const name = profile.name ?? profile.profile;
|
|
2412
|
+
if (!name) {
|
|
2413
|
+
continue;
|
|
2414
|
+
}
|
|
2415
|
+
return name === "default" ? "colima" : `colima-${name}`;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
} catch {
|
|
2419
|
+
return null;
|
|
2420
|
+
}
|
|
2421
|
+
return null;
|
|
2422
|
+
}
|
|
2423
|
+
function buildContextArgs(engine, context) {
|
|
2424
|
+
if (engine === "docker" && context) {
|
|
2425
|
+
return ["--context", context];
|
|
2426
|
+
}
|
|
2427
|
+
return [];
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
// packages/process-runner/src/docker/engine.ts
|
|
2431
|
+
import { execSync as execSync2 } from "node:child_process";
|
|
2432
|
+
function detectEngine() {
|
|
2433
|
+
if (isEngineAvailable("docker")) {
|
|
2434
|
+
return "docker";
|
|
2435
|
+
}
|
|
2436
|
+
if (isEngineAvailable("podman")) {
|
|
2437
|
+
return "podman";
|
|
2438
|
+
}
|
|
2439
|
+
throw new Error(
|
|
2440
|
+
"No container engine found. Please install Docker or Podman:\n - Docker Desktop: https://www.docker.com/products/docker-desktop\n - Colima (macOS): brew install colima && colima start\n - Podman: https://podman.io/docs/installation"
|
|
2441
|
+
);
|
|
2442
|
+
}
|
|
2443
|
+
function isEngineAvailable(engine) {
|
|
2444
|
+
try {
|
|
2445
|
+
execSync2(`${engine} --version`, {
|
|
2446
|
+
stdio: "ignore"
|
|
2447
|
+
});
|
|
2448
|
+
return true;
|
|
2449
|
+
} catch {
|
|
2450
|
+
return false;
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
// packages/process-runner/src/docker/docker-runner.ts
|
|
2455
|
+
import * as childProcess from "node:child_process";
|
|
2456
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
2457
|
+
|
|
2458
|
+
// packages/process-runner/src/docker/args.ts
|
|
2459
|
+
import path13 from "node:path";
|
|
2460
|
+
function buildDockerRunArgs(input) {
|
|
2461
|
+
const args = [input.engine];
|
|
2462
|
+
if (input.engine === "docker" && input.context) {
|
|
2463
|
+
args.push("--context", input.context);
|
|
2464
|
+
}
|
|
2465
|
+
args.push("run");
|
|
2466
|
+
if (input.rm) {
|
|
2467
|
+
args.push("--rm");
|
|
2468
|
+
}
|
|
2469
|
+
if (input.detached) {
|
|
2470
|
+
args.push("-d");
|
|
2471
|
+
}
|
|
2472
|
+
if (input.interactive) {
|
|
2473
|
+
args.push("-i");
|
|
2474
|
+
}
|
|
2475
|
+
if (input.tty) {
|
|
2476
|
+
args.push("-t");
|
|
2477
|
+
}
|
|
2478
|
+
args.push("--name", input.containerName);
|
|
2479
|
+
if (input.cwd !== void 0) {
|
|
2480
|
+
args.push("-w", input.cwd);
|
|
2481
|
+
}
|
|
2482
|
+
for (const [key, value] of Object.entries(input.env ?? {})) {
|
|
2483
|
+
args.push("-e", `${key}=${value}`);
|
|
2484
|
+
}
|
|
2485
|
+
for (const mount of input.mounts) {
|
|
2486
|
+
const volume = `${path13.resolve(mount.source)}:${mount.target}${mount.readonly ? ":ro" : ""}`;
|
|
2487
|
+
args.push("-v", volume);
|
|
2488
|
+
}
|
|
2489
|
+
for (const port of input.ports) {
|
|
2490
|
+
const mapping = `${port.host}:${port.container}${port.protocol === void 0 || port.protocol === "tcp" ? "" : `/${port.protocol}`}`;
|
|
2491
|
+
args.push("-p", mapping);
|
|
2492
|
+
}
|
|
2493
|
+
if (input.network !== void 0) {
|
|
2494
|
+
args.push("--network", input.network);
|
|
2495
|
+
}
|
|
2496
|
+
args.push(...input.extraArgs, input.image, input.command, ...input.args);
|
|
2497
|
+
return args;
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
// packages/process-runner/src/docker/docker-execution-env.ts
|
|
2501
|
+
import { createHash as createHash2, randomBytes as randomBytes3 } from "node:crypto";
|
|
2502
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
2503
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
2504
|
+
import { tmpdir } from "node:os";
|
|
2505
|
+
import path14 from "node:path";
|
|
2506
|
+
|
|
2507
|
+
// packages/process-runner/src/host/host-runner.ts
|
|
2508
|
+
import { spawn as spawnChildProcess } from "node:child_process";
|
|
2509
|
+
function createHostRunner(options = {}) {
|
|
2510
|
+
const detached = options.detached === true;
|
|
2511
|
+
return {
|
|
2512
|
+
name: "host",
|
|
2513
|
+
exec(spec) {
|
|
2514
|
+
const stdinMode = spec.stdin ?? "ignore";
|
|
2515
|
+
const stdoutMode = spec.stdout ?? "pipe";
|
|
2516
|
+
const stderrMode = spec.stderr ?? "pipe";
|
|
2517
|
+
const stdio = stdinMode === "inherit" && stdoutMode === "inherit" && stderrMode === "inherit" ? "inherit" : [stdinMode, stdoutMode, stderrMode];
|
|
2518
|
+
const child = spawnChildProcess(spec.command, spec.args ?? [], {
|
|
2519
|
+
cwd: spec.cwd,
|
|
2520
|
+
env: spec.env,
|
|
2521
|
+
stdio,
|
|
2522
|
+
...detached ? { detached: true } : {}
|
|
2523
|
+
});
|
|
2524
|
+
if (detached) {
|
|
2525
|
+
child.unref();
|
|
2526
|
+
}
|
|
2527
|
+
const kill = (signal) => {
|
|
2528
|
+
if (detached && process.platform !== "win32" && child.pid !== void 0) {
|
|
2529
|
+
process.kill(-child.pid, signal);
|
|
2530
|
+
return;
|
|
2531
|
+
}
|
|
2532
|
+
child.kill(signal);
|
|
2533
|
+
};
|
|
2534
|
+
let settled = false;
|
|
2535
|
+
let resolveResult = null;
|
|
2536
|
+
const result = new Promise((resolve2) => {
|
|
2537
|
+
resolveResult = resolve2;
|
|
2538
|
+
});
|
|
2539
|
+
const cleanupAbort = bindAbortSignal(spec.signal, () => {
|
|
2540
|
+
kill("SIGTERM");
|
|
2541
|
+
});
|
|
2542
|
+
child.once("close", (code) => {
|
|
2543
|
+
if (settled) return;
|
|
2544
|
+
settled = true;
|
|
2545
|
+
cleanupAbort();
|
|
2546
|
+
resolveResult?.({ exitCode: code ?? 1 });
|
|
2547
|
+
});
|
|
2548
|
+
child.once("error", () => {
|
|
2549
|
+
if (settled) return;
|
|
2550
|
+
settled = true;
|
|
2551
|
+
cleanupAbort();
|
|
2552
|
+
resolveResult?.({ exitCode: 1 });
|
|
2553
|
+
});
|
|
2554
|
+
return {
|
|
2555
|
+
pid: child.pid ?? null,
|
|
2556
|
+
stdin: child.stdin,
|
|
2557
|
+
stdout: child.stdout,
|
|
2558
|
+
stderr: child.stderr,
|
|
2559
|
+
result,
|
|
2560
|
+
kill
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
};
|
|
2564
|
+
}
|
|
2565
|
+
function bindAbortSignal(signal, onAbort) {
|
|
2566
|
+
if (signal === void 0) {
|
|
2567
|
+
return () => {
|
|
2568
|
+
};
|
|
2569
|
+
}
|
|
2570
|
+
if (signal.aborted) {
|
|
2571
|
+
onAbort();
|
|
2572
|
+
return () => {
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2576
|
+
return () => {
|
|
2577
|
+
signal.removeEventListener("abort", onAbort);
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
// packages/process-runner/src/docker/docker-execution-env.ts
|
|
2582
|
+
var containerCommand = ["sh", "-c", "while :; do sleep 3600; done"];
|
|
2583
|
+
var dockerExecutionEnvFactory = {
|
|
2584
|
+
type: "docker",
|
|
2585
|
+
supportsDetach: true,
|
|
2586
|
+
async open(spec) {
|
|
2587
|
+
const runtime = parseDockerRuntime(spec.runtime);
|
|
2588
|
+
const runner = spec.hostRunner ?? createHostRunner();
|
|
2589
|
+
const engine = runtime.engine ?? detectEngine();
|
|
2590
|
+
const context = detectContext();
|
|
2591
|
+
const image = await resolveImage({
|
|
2592
|
+
spec,
|
|
2593
|
+
runtime,
|
|
2594
|
+
runner,
|
|
2595
|
+
engine,
|
|
2596
|
+
context
|
|
2597
|
+
});
|
|
2598
|
+
const containerName = createContainerName();
|
|
2599
|
+
const runArgs = buildDockerRunArgs({
|
|
2600
|
+
engine,
|
|
2601
|
+
context,
|
|
2602
|
+
image,
|
|
2603
|
+
command: containerCommand[0],
|
|
2604
|
+
args: containerCommand.slice(1),
|
|
2605
|
+
cwd: void 0,
|
|
2606
|
+
env: void 0,
|
|
2607
|
+
mounts: runtime.mounts ?? [],
|
|
2608
|
+
ports: [],
|
|
2609
|
+
network: runtime.network,
|
|
2610
|
+
containerName,
|
|
2611
|
+
detached: true,
|
|
2612
|
+
interactive: true,
|
|
2613
|
+
tty: false,
|
|
2614
|
+
rm: false,
|
|
2615
|
+
extraArgs: runtime.extra_args ?? []
|
|
2616
|
+
});
|
|
2617
|
+
const [command, ...args] = runArgs;
|
|
2618
|
+
const id = (await runAndRead(runner, { command, args, stdout: "pipe", stderr: "pipe" })).trim();
|
|
2619
|
+
return createDockerEnv({
|
|
2620
|
+
id,
|
|
2621
|
+
spec,
|
|
2622
|
+
runner,
|
|
2623
|
+
engine,
|
|
2624
|
+
context
|
|
2625
|
+
});
|
|
2626
|
+
},
|
|
2627
|
+
async attach(envId, context) {
|
|
2628
|
+
const engine = detectEngine();
|
|
2629
|
+
return createDockerEnv({
|
|
2630
|
+
id: envId,
|
|
2631
|
+
spec: createAttachedSpec(context?.cwd),
|
|
2632
|
+
runner: createHostRunner(),
|
|
2633
|
+
engine,
|
|
2634
|
+
context: detectContext(),
|
|
2635
|
+
attachedJobId: context?.jobId
|
|
2636
|
+
});
|
|
2637
|
+
}
|
|
2638
|
+
};
|
|
2639
|
+
function createDockerEnv(input) {
|
|
2640
|
+
const containerRef = input.id;
|
|
2641
|
+
return {
|
|
2642
|
+
id: containerRef,
|
|
2643
|
+
job: input.attachedJobId === void 0 ? null : createContainerJob(containerRef, input.runner, input.engine, input.context, input.attachedJobId),
|
|
2644
|
+
async uploadWorkspace() {
|
|
2645
|
+
const tempDir = mkdtempSync(path14.join(tmpdir(), "poe-docker-upload-"));
|
|
2646
|
+
const archivePath = path14.join(tempDir, "workspace.tar");
|
|
2647
|
+
try {
|
|
2648
|
+
const excludeArgs = input.spec.uploadIgnoreFiles.flatMap((ignored) => [
|
|
2649
|
+
"--exclude",
|
|
2650
|
+
ignored
|
|
2651
|
+
]);
|
|
2652
|
+
const tarArgs = [...excludeArgs, "-cf", archivePath, "-C", input.spec.cwd, "."];
|
|
2653
|
+
await runOrThrow(input.runner, {
|
|
2654
|
+
command: "tar",
|
|
2655
|
+
args: tarArgs,
|
|
2656
|
+
stdout: "pipe",
|
|
2657
|
+
stderr: "pipe"
|
|
2658
|
+
});
|
|
2659
|
+
await runOrThrow(input.runner, {
|
|
2660
|
+
command: input.engine,
|
|
2661
|
+
args: [
|
|
2662
|
+
...buildContextArgs(input.engine, input.context),
|
|
2663
|
+
"cp",
|
|
2664
|
+
archivePath,
|
|
2665
|
+
`${containerRef}:/tmp/poe-workspace-upload.tar`
|
|
2666
|
+
],
|
|
2667
|
+
stdout: "pipe",
|
|
2668
|
+
stderr: "pipe"
|
|
2669
|
+
});
|
|
2670
|
+
await runOrThrow(input.runner, {
|
|
2671
|
+
command: input.engine,
|
|
2672
|
+
args: [
|
|
2673
|
+
...buildContextArgs(input.engine, input.context),
|
|
2674
|
+
"exec",
|
|
2675
|
+
containerRef,
|
|
2676
|
+
"sh",
|
|
2677
|
+
"-c",
|
|
2678
|
+
`mkdir -p ${shellQuote(input.spec.cwd)} && tar -xf /tmp/poe-workspace-upload.tar -C ${shellQuote(input.spec.cwd)}`
|
|
2679
|
+
],
|
|
2680
|
+
stdout: "pipe",
|
|
2681
|
+
stderr: "pipe"
|
|
2682
|
+
});
|
|
2683
|
+
return { files: 0, bytes: 0, skipped: [] };
|
|
2684
|
+
} finally {
|
|
2685
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
2686
|
+
}
|
|
2687
|
+
},
|
|
2688
|
+
async downloadWorkspace(opts) {
|
|
2689
|
+
const tempDir = mkdtempSync(path14.join(tmpdir(), "poe-docker-download-"));
|
|
2690
|
+
const archivePath = path14.join(tempDir, "workspace.tar");
|
|
2691
|
+
try {
|
|
2692
|
+
await runOrThrow(input.runner, {
|
|
2693
|
+
command: input.engine,
|
|
2694
|
+
args: [
|
|
2695
|
+
...buildContextArgs(input.engine, input.context),
|
|
2696
|
+
"exec",
|
|
2697
|
+
containerRef,
|
|
2698
|
+
"sh",
|
|
2699
|
+
"-c",
|
|
2700
|
+
`tar -cf /tmp/poe-workspace-download.tar -C ${shellQuote(input.spec.cwd)} .`
|
|
2701
|
+
],
|
|
2702
|
+
stdout: "pipe",
|
|
2703
|
+
stderr: "pipe"
|
|
2704
|
+
});
|
|
2705
|
+
await runOrThrow(input.runner, {
|
|
2706
|
+
command: input.engine,
|
|
2707
|
+
args: [
|
|
2708
|
+
...buildContextArgs(input.engine, input.context),
|
|
2709
|
+
"cp",
|
|
2710
|
+
`${containerRef}:/tmp/poe-workspace-download.tar`,
|
|
2711
|
+
archivePath
|
|
2712
|
+
],
|
|
2713
|
+
stdout: "pipe",
|
|
2714
|
+
stderr: "pipe"
|
|
2715
|
+
});
|
|
2716
|
+
const extractMode = opts.conflictPolicy === "refuse" ? "-xkf" : "-xf";
|
|
2717
|
+
await runOrThrow(input.runner, {
|
|
2718
|
+
command: "tar",
|
|
2719
|
+
args: [extractMode, archivePath, "-C", input.spec.cwd],
|
|
2720
|
+
stdout: "pipe",
|
|
2721
|
+
stderr: "pipe"
|
|
2722
|
+
});
|
|
2723
|
+
return { files: 0, bytes: 0, conflicts: [] };
|
|
2724
|
+
} finally {
|
|
2725
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
2726
|
+
}
|
|
2727
|
+
},
|
|
2728
|
+
exec(spec) {
|
|
2729
|
+
return input.runner.exec({
|
|
2730
|
+
command: input.engine,
|
|
2731
|
+
args: [
|
|
2732
|
+
...buildContextArgs(input.engine, input.context),
|
|
2733
|
+
"exec",
|
|
2734
|
+
...spec.stdin === "pipe" || spec.stdin === "inherit" ? ["-i"] : [],
|
|
2735
|
+
...spec.tty === true ? ["-t"] : [],
|
|
2736
|
+
...spec.cwd !== void 0 ? ["-w", spec.cwd] : [],
|
|
2737
|
+
...buildEnvArgs(spec.env),
|
|
2738
|
+
containerRef,
|
|
2739
|
+
spec.command,
|
|
2740
|
+
...spec.args ?? []
|
|
2741
|
+
],
|
|
2742
|
+
stdin: spec.stdin,
|
|
2743
|
+
stdout: spec.stdout,
|
|
2744
|
+
stderr: spec.stderr,
|
|
2745
|
+
tty: spec.tty
|
|
2746
|
+
});
|
|
2747
|
+
},
|
|
2748
|
+
async detach() {
|
|
2749
|
+
return createContainerJob(containerRef, input.runner, input.engine, input.context);
|
|
2750
|
+
},
|
|
2751
|
+
shell() {
|
|
2752
|
+
const shellSpec = input.spec.shellSpec;
|
|
2753
|
+
return this.exec({
|
|
2754
|
+
command: shellSpec?.command ?? input.spec.env.SHELL ?? "sh",
|
|
2755
|
+
...shellSpec?.args ? { args: shellSpec.args } : {},
|
|
2756
|
+
cwd: input.spec.cwd,
|
|
2757
|
+
env: shellSpec && "env" in shellSpec ? shellSpec.env : input.spec.env,
|
|
2758
|
+
stdin: "inherit",
|
|
2759
|
+
stdout: "inherit",
|
|
2760
|
+
stderr: "inherit",
|
|
2761
|
+
tty: true
|
|
2762
|
+
});
|
|
2763
|
+
},
|
|
2764
|
+
async close() {
|
|
2765
|
+
await runOrThrow(input.runner, {
|
|
2766
|
+
command: input.engine,
|
|
2767
|
+
args: [...buildContextArgs(input.engine, input.context), "rm", "-f", containerRef],
|
|
2768
|
+
stdout: "pipe",
|
|
2769
|
+
stderr: "pipe"
|
|
2770
|
+
});
|
|
2771
|
+
}
|
|
2772
|
+
};
|
|
2773
|
+
}
|
|
2774
|
+
async function resolveImage(input) {
|
|
2775
|
+
if (input.runtime.image !== void 0) {
|
|
2776
|
+
return input.runtime.image;
|
|
2777
|
+
}
|
|
2778
|
+
const result = await buildDockerRuntimeTemplate({
|
|
2779
|
+
cwd: input.spec.cwd,
|
|
2780
|
+
runtime: input.runtime,
|
|
2781
|
+
state: input.spec.state,
|
|
2782
|
+
runner: input.runner
|
|
2783
|
+
});
|
|
2784
|
+
return result.image;
|
|
2785
|
+
}
|
|
2786
|
+
async function buildDockerRuntimeTemplate(input) {
|
|
2787
|
+
const runner = input.runner ?? createHostRunner();
|
|
2788
|
+
const engine = input.runtime.engine ?? detectEngine();
|
|
2789
|
+
const context = detectContext();
|
|
2790
|
+
const dockerfilePath = path14.resolve(
|
|
2791
|
+
input.cwd,
|
|
2792
|
+
input.runtime.dockerfile ?? path14.join(".poe-code", "Dockerfile")
|
|
2793
|
+
);
|
|
2794
|
+
const buildContext = path14.resolve(input.cwd, input.runtime.build_context ?? ".");
|
|
2795
|
+
const dockerfileBytes = await readFile2(dockerfilePath);
|
|
2796
|
+
const hash = hashDockerTemplate(dockerfileBytes, input.runtime.build_args ?? {});
|
|
2797
|
+
const cached2 = input.force ? null : await input.state?.templates.get("docker", hash);
|
|
2798
|
+
if (cached2?.image !== void 0) {
|
|
2799
|
+
return {
|
|
2800
|
+
backend: "docker",
|
|
2801
|
+
hash,
|
|
2802
|
+
image: cached2.image,
|
|
2803
|
+
cached: true
|
|
2804
|
+
};
|
|
2805
|
+
}
|
|
2806
|
+
const image = `poe-code/local:${hash}`;
|
|
2807
|
+
await buildImage({
|
|
2808
|
+
runner,
|
|
2809
|
+
engine,
|
|
2810
|
+
context,
|
|
2811
|
+
image,
|
|
2812
|
+
dockerfilePath,
|
|
2813
|
+
buildContext,
|
|
2814
|
+
buildArgs: input.runtime.build_args ?? {}
|
|
2815
|
+
});
|
|
2816
|
+
await input.state?.templates.put("docker", {
|
|
2817
|
+
hash,
|
|
2818
|
+
image,
|
|
2819
|
+
runtime_type: "docker",
|
|
2820
|
+
dockerfile_path: dockerfilePath,
|
|
2821
|
+
built_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2822
|
+
});
|
|
2823
|
+
return {
|
|
2824
|
+
backend: "docker",
|
|
2825
|
+
hash,
|
|
2826
|
+
image,
|
|
2827
|
+
cached: false
|
|
2828
|
+
};
|
|
2829
|
+
}
|
|
2830
|
+
function hashDockerTemplate(dockerfileBytes, buildArgs) {
|
|
2831
|
+
const hash = createHash2("sha256");
|
|
2832
|
+
hash.update(dockerfileBytes);
|
|
2833
|
+
hash.update("\0");
|
|
2834
|
+
for (const [key, value] of sortedBuildArgs(buildArgs)) {
|
|
2835
|
+
hash.update(key);
|
|
2836
|
+
hash.update("=");
|
|
2837
|
+
hash.update(value);
|
|
2838
|
+
hash.update("\0");
|
|
2839
|
+
}
|
|
2840
|
+
return hash.digest("hex");
|
|
2841
|
+
}
|
|
2842
|
+
async function buildImage(input) {
|
|
2843
|
+
await runOrThrow(input.runner, {
|
|
2844
|
+
command: input.engine,
|
|
2845
|
+
args: [
|
|
2846
|
+
...buildContextArgs(input.engine, input.context),
|
|
2847
|
+
"build",
|
|
2848
|
+
"--tag",
|
|
2849
|
+
input.image,
|
|
2850
|
+
"-f",
|
|
2851
|
+
input.dockerfilePath,
|
|
2852
|
+
...sortedBuildArgs(input.buildArgs).flatMap(([key, value]) => [
|
|
2853
|
+
"--build-arg",
|
|
2854
|
+
`${key}=${value}`
|
|
2855
|
+
]),
|
|
2856
|
+
input.buildContext
|
|
2857
|
+
],
|
|
2858
|
+
stdout: "pipe",
|
|
2859
|
+
stderr: "pipe"
|
|
2860
|
+
});
|
|
2861
|
+
}
|
|
2862
|
+
function parseDockerRuntime(runtime) {
|
|
2863
|
+
if (!runtime || typeof runtime !== "object" || Array.isArray(runtime)) {
|
|
2864
|
+
throw new Error("docker runtime must be an object");
|
|
2865
|
+
}
|
|
2866
|
+
const record = runtime;
|
|
2867
|
+
if (record.type !== "docker") {
|
|
2868
|
+
throw new Error('docker runtime type must be "docker"');
|
|
2869
|
+
}
|
|
2870
|
+
return record;
|
|
2871
|
+
}
|
|
2872
|
+
async function runAndRead(runner, spec) {
|
|
2873
|
+
const handle = runner.exec(spec);
|
|
2874
|
+
const stdout = readStream(handle.stdout);
|
|
2875
|
+
const stderr = readStream(handle.stderr);
|
|
2876
|
+
const result = await handle.result;
|
|
2877
|
+
const output = await stdout;
|
|
2878
|
+
if (result.exitCode !== 0) {
|
|
2879
|
+
const errorOutput = await stderr;
|
|
2880
|
+
throw new Error(
|
|
2881
|
+
`Command failed with exit code ${result.exitCode}: ${spec.command} ${(spec.args ?? []).join(" ")}${errorOutput ? `
|
|
2882
|
+
${errorOutput}` : ""}`
|
|
2883
|
+
);
|
|
2884
|
+
}
|
|
2885
|
+
return output;
|
|
2886
|
+
}
|
|
2887
|
+
async function runOrThrow(runner, spec) {
|
|
2888
|
+
await runAndRead(runner, spec);
|
|
2889
|
+
}
|
|
2890
|
+
async function readStream(stream) {
|
|
2891
|
+
if (stream === null) {
|
|
2892
|
+
return "";
|
|
2893
|
+
}
|
|
2894
|
+
stream.setEncoding("utf8");
|
|
2895
|
+
const chunks = [];
|
|
2896
|
+
for await (const chunk of stream) {
|
|
2897
|
+
chunks.push(String(chunk));
|
|
2898
|
+
}
|
|
2899
|
+
return chunks.join("");
|
|
2900
|
+
}
|
|
2901
|
+
function sortedBuildArgs(buildArgs) {
|
|
2902
|
+
return Object.entries(buildArgs).sort(([left], [right]) => left.localeCompare(right));
|
|
2903
|
+
}
|
|
2904
|
+
function buildEnvArgs(env) {
|
|
2905
|
+
if (env === void 0) {
|
|
2906
|
+
return [];
|
|
2907
|
+
}
|
|
2908
|
+
return Object.entries(env).flatMap(([key, value]) => ["-e", `${key}=${value}`]);
|
|
2909
|
+
}
|
|
2910
|
+
function createContainerName() {
|
|
2911
|
+
return `poe-env-${randomBytes3(6).toString("hex")}`;
|
|
2912
|
+
}
|
|
2913
|
+
function createContainerJob(containerId, runner, engine, context, jobId = containerId) {
|
|
2914
|
+
return {
|
|
2915
|
+
id: jobId,
|
|
2916
|
+
envId: containerId,
|
|
2917
|
+
tool: "docker",
|
|
2918
|
+
argv: ["attach", containerId],
|
|
2919
|
+
async status() {
|
|
2920
|
+
const handle = runner.exec({
|
|
2921
|
+
command: engine,
|
|
2922
|
+
args: [
|
|
2923
|
+
...buildContextArgs(engine, context),
|
|
2924
|
+
"inspect",
|
|
2925
|
+
"-f",
|
|
2926
|
+
"{{.State.Status}}",
|
|
2927
|
+
containerId
|
|
2928
|
+
],
|
|
2929
|
+
stdout: "pipe",
|
|
2930
|
+
stderr: "pipe"
|
|
2931
|
+
});
|
|
2932
|
+
const stdout = await readStream(handle.stdout);
|
|
2933
|
+
const result = await handle.result;
|
|
2934
|
+
if (result.exitCode !== 0) {
|
|
2935
|
+
return "lost";
|
|
2936
|
+
}
|
|
2937
|
+
return stdout.trim() === "running" ? "running" : "exited";
|
|
2938
|
+
},
|
|
2939
|
+
async *stream(opts) {
|
|
2940
|
+
const handle = runner.exec({
|
|
2941
|
+
command: engine,
|
|
2942
|
+
args: [
|
|
2943
|
+
...buildContextArgs(engine, context),
|
|
2944
|
+
"exec",
|
|
2945
|
+
containerId,
|
|
2946
|
+
"sh",
|
|
2947
|
+
"-c",
|
|
2948
|
+
`test -f ${shellQuote(`/tmp/poe-jobs/${jobId}.log`)} && tail -c +${(opts?.sinceByte ?? 0) + 1} ${shellQuote(`/tmp/poe-jobs/${jobId}.log`)} || true`
|
|
2949
|
+
],
|
|
2950
|
+
stdout: "pipe",
|
|
2951
|
+
stderr: "pipe"
|
|
2952
|
+
});
|
|
2953
|
+
const stdout = await readStream(handle.stdout);
|
|
2954
|
+
await handle.result;
|
|
2955
|
+
if (stdout.length > 0) {
|
|
2956
|
+
yield { byteOffset: opts?.sinceByte ?? 0, data: stdout };
|
|
2957
|
+
}
|
|
2958
|
+
},
|
|
2959
|
+
async wait() {
|
|
2960
|
+
const handle = runner.exec({
|
|
2961
|
+
command: engine,
|
|
2962
|
+
args: [...buildContextArgs(engine, context), "wait", containerId],
|
|
2963
|
+
stdout: "pipe",
|
|
2964
|
+
stderr: "pipe"
|
|
2965
|
+
});
|
|
2966
|
+
const stdout = await readStream(handle.stdout);
|
|
2967
|
+
const result = await handle.result;
|
|
2968
|
+
return { exitCode: Number.parseInt(stdout.trim(), 10) || result.exitCode };
|
|
2969
|
+
},
|
|
2970
|
+
async kill(signal) {
|
|
2971
|
+
const args = signal === void 0 || signal === "SIGTERM" ? ["stop", containerId] : ["kill", ...signal === "SIGKILL" ? [] : [`--signal=${signal}`], containerId];
|
|
2972
|
+
await runOrThrow(runner, {
|
|
2973
|
+
command: engine,
|
|
2974
|
+
args: [...buildContextArgs(engine, context), ...args],
|
|
2975
|
+
stdout: "pipe",
|
|
2976
|
+
stderr: "pipe"
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2979
|
+
};
|
|
2980
|
+
}
|
|
2981
|
+
function createAttachedSpec(cwd = "/workspace") {
|
|
2982
|
+
return {
|
|
2983
|
+
cwd,
|
|
2984
|
+
runtime: {
|
|
2985
|
+
type: "docker",
|
|
2986
|
+
image: "attached",
|
|
2987
|
+
build_args: {},
|
|
2988
|
+
mounts: []
|
|
2989
|
+
},
|
|
2990
|
+
env: {},
|
|
2991
|
+
uploadIgnoreFiles: [],
|
|
2992
|
+
jobLabel: {
|
|
2993
|
+
tool: "docker",
|
|
2994
|
+
argv: []
|
|
2995
|
+
}
|
|
2996
|
+
};
|
|
2997
|
+
}
|
|
2998
|
+
function shellQuote(value) {
|
|
2999
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
// packages/process-runner/src/host/host-execution-env.ts
|
|
3003
|
+
var hostExecutionEnvFactory = {
|
|
3004
|
+
type: "host",
|
|
3005
|
+
supportsDetach: false,
|
|
3006
|
+
async open(openSpec) {
|
|
3007
|
+
return {
|
|
3008
|
+
id: "host",
|
|
3009
|
+
job: null,
|
|
3010
|
+
async uploadWorkspace() {
|
|
3011
|
+
return {
|
|
3012
|
+
files: 0,
|
|
3013
|
+
bytes: 0,
|
|
3014
|
+
skipped: []
|
|
3015
|
+
};
|
|
3016
|
+
},
|
|
3017
|
+
async downloadWorkspace() {
|
|
3018
|
+
return {
|
|
3019
|
+
files: 0,
|
|
3020
|
+
bytes: 0,
|
|
3021
|
+
conflicts: []
|
|
3022
|
+
};
|
|
3023
|
+
},
|
|
3024
|
+
exec(spec) {
|
|
3025
|
+
return createHostRunner().exec(spec);
|
|
3026
|
+
},
|
|
3027
|
+
async detach() {
|
|
3028
|
+
throw new Error("host runtime does not support detach because host has no addressable env");
|
|
3029
|
+
},
|
|
3030
|
+
shell() {
|
|
3031
|
+
const shellSpec = openSpec.shellSpec;
|
|
3032
|
+
return createHostRunner().exec({
|
|
3033
|
+
command: shellSpec?.command ?? openSpec.env.SHELL ?? process.env.SHELL ?? "sh",
|
|
3034
|
+
...shellSpec?.args ? { args: shellSpec.args } : {},
|
|
3035
|
+
cwd: openSpec.cwd,
|
|
3036
|
+
env: shellSpec && "env" in shellSpec ? shellSpec.env : openSpec.env,
|
|
3037
|
+
stdin: "inherit",
|
|
3038
|
+
stdout: "inherit",
|
|
3039
|
+
stderr: "inherit",
|
|
3040
|
+
tty: true
|
|
3041
|
+
});
|
|
3042
|
+
},
|
|
3043
|
+
async close() {
|
|
3044
|
+
}
|
|
3045
|
+
};
|
|
3046
|
+
},
|
|
3047
|
+
async attach() {
|
|
3048
|
+
throw new Error("host runtime does not support reattach");
|
|
3049
|
+
}
|
|
3050
|
+
};
|
|
3051
|
+
|
|
3052
|
+
// packages/process-runner/src/testing/mock-runner.ts
|
|
3053
|
+
import { Readable, Writable } from "node:stream";
|
|
3054
|
+
|
|
3055
|
+
// packages/runner-e2b/src/factory.ts
|
|
3056
|
+
import path18 from "node:path";
|
|
3057
|
+
|
|
3058
|
+
// packages/runner-e2b/src/sdk.ts
|
|
3059
|
+
import { Template, Sandbox } from "e2b";
|
|
3060
|
+
async function createSandbox(opts) {
|
|
3061
|
+
return Sandbox.create(opts.templateId, {
|
|
3062
|
+
apiKey: opts.apiKey,
|
|
3063
|
+
envs: opts.env,
|
|
3064
|
+
...opts.timeoutMinutes === void 0 ? {} : { timeoutMs: opts.timeoutMinutes * 6e4 }
|
|
3065
|
+
});
|
|
3066
|
+
}
|
|
3067
|
+
async function connectSandbox(id, apiKey) {
|
|
3068
|
+
return Sandbox.connect(id, apiKey === void 0 ? void 0 : { apiKey });
|
|
3069
|
+
}
|
|
3070
|
+
async function buildTemplate(opts) {
|
|
3071
|
+
const template = Template({ fileContextPath: opts.buildContext }).fromDockerfile(
|
|
3072
|
+
opts.dockerfilePath
|
|
3073
|
+
);
|
|
3074
|
+
if (opts.fromTemplate !== void 0 && opts.fromTemplate.length > 0) {
|
|
3075
|
+
template.fromTemplate(opts.fromTemplate);
|
|
3076
|
+
}
|
|
3077
|
+
const result = await Template.build(template, opts.name, {
|
|
3078
|
+
apiKey: opts.apiKey,
|
|
3079
|
+
...opts.cpu === void 0 ? {} : { cpuCount: opts.cpu },
|
|
3080
|
+
...opts.memoryMb === void 0 ? {} : { memoryMB: opts.memoryMb },
|
|
3081
|
+
...opts.onLog ? { onBuildLogs: opts.onLog } : {}
|
|
3082
|
+
});
|
|
3083
|
+
return { templateId: result.templateId };
|
|
3084
|
+
}
|
|
3085
|
+
function toArrayBuffer(buffer) {
|
|
3086
|
+
const output = new ArrayBuffer(buffer.byteLength);
|
|
3087
|
+
new Uint8Array(output).set(buffer);
|
|
3088
|
+
return output;
|
|
3089
|
+
}
|
|
3090
|
+
async function readableToString(stream) {
|
|
3091
|
+
if (stream === null) {
|
|
3092
|
+
return "";
|
|
3093
|
+
}
|
|
3094
|
+
stream.setEncoding("utf8");
|
|
3095
|
+
const chunks = [];
|
|
3096
|
+
for await (const chunk of stream) {
|
|
3097
|
+
chunks.push(String(chunk));
|
|
3098
|
+
}
|
|
3099
|
+
return chunks.join("");
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
// packages/runner-e2b/src/template-build.ts
|
|
3103
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
3104
|
+
import { readdir, readFile as readFile3 } from "node:fs/promises";
|
|
3105
|
+
import path15 from "node:path";
|
|
3106
|
+
var BUILD_LOG_TAIL_SIZE = 30;
|
|
3107
|
+
async function buildE2bRuntimeTemplate(input) {
|
|
3108
|
+
const dockerfileBytes = await readFile3(input.dockerfilePath);
|
|
3109
|
+
const buildContextFiles = await readBuildContextFiles(input.buildContext);
|
|
3110
|
+
const hash = hashTemplate(dockerfileBytes, buildContextFiles, input.runtime.build_args);
|
|
3111
|
+
const cached2 = input.force === true ? null : await input.state?.templates.get("e2b", hash);
|
|
3112
|
+
if (cached2?.template_id !== void 0) {
|
|
3113
|
+
return { backend: "e2b", hash, templateId: cached2.template_id, cached: true };
|
|
3114
|
+
}
|
|
3115
|
+
const tail = [];
|
|
3116
|
+
const onLog = (entry) => {
|
|
3117
|
+
tail.push(entry.message);
|
|
3118
|
+
if (tail.length > BUILD_LOG_TAIL_SIZE) {
|
|
3119
|
+
tail.shift();
|
|
3120
|
+
}
|
|
3121
|
+
input.onLog?.(entry);
|
|
3122
|
+
};
|
|
3123
|
+
let built;
|
|
3124
|
+
try {
|
|
3125
|
+
built = await buildTemplate({
|
|
3126
|
+
apiKey: input.apiKey,
|
|
3127
|
+
name: `poe-code-${hash.slice(0, 32)}`,
|
|
3128
|
+
dockerfilePath: input.dockerfilePath,
|
|
3129
|
+
buildContext: input.buildContext,
|
|
3130
|
+
cpu: input.runtime.cpu,
|
|
3131
|
+
memoryMb: input.runtime.memory_mb,
|
|
3132
|
+
fromTemplate: input.runtime.from_template,
|
|
3133
|
+
onLog
|
|
3134
|
+
});
|
|
3135
|
+
} catch (error2) {
|
|
3136
|
+
throw decorateBuildError(error2, tail);
|
|
3137
|
+
}
|
|
3138
|
+
await input.state?.templates.put("e2b", {
|
|
3139
|
+
hash,
|
|
3140
|
+
template_id: built.templateId,
|
|
3141
|
+
runtime_type: "e2b",
|
|
3142
|
+
dockerfile_path: input.dockerfilePath,
|
|
3143
|
+
built_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3144
|
+
});
|
|
3145
|
+
return { backend: "e2b", hash, templateId: built.templateId, cached: false };
|
|
3146
|
+
}
|
|
3147
|
+
function decorateBuildError(error2, tail) {
|
|
3148
|
+
const original = error2 instanceof Error ? error2 : new Error(String(error2));
|
|
3149
|
+
if (tail.length === 0) {
|
|
3150
|
+
return original;
|
|
3151
|
+
}
|
|
3152
|
+
const decorated = new Error(`${original.message}
|
|
3153
|
+
|
|
3154
|
+
Last build output:
|
|
3155
|
+
${tail.join("\n")}`);
|
|
3156
|
+
decorated.stack = original.stack;
|
|
3157
|
+
decorated.cause = original;
|
|
3158
|
+
return decorated;
|
|
3159
|
+
}
|
|
3160
|
+
function hashTemplate(dockerfileBytes, buildContextFiles, buildArgs) {
|
|
3161
|
+
const hash = createHash3("sha256");
|
|
3162
|
+
hash.update(dockerfileBytes);
|
|
3163
|
+
hash.update("\0");
|
|
3164
|
+
for (const file of buildContextFiles) {
|
|
3165
|
+
hash.update(file.relativePath);
|
|
3166
|
+
hash.update("\0");
|
|
3167
|
+
hash.update(file.bytes);
|
|
3168
|
+
hash.update("\0");
|
|
3169
|
+
}
|
|
3170
|
+
for (const [key, value] of Object.entries(buildArgs).sort(
|
|
3171
|
+
([left], [right]) => left.localeCompare(right)
|
|
3172
|
+
)) {
|
|
3173
|
+
hash.update(key);
|
|
3174
|
+
hash.update("=");
|
|
3175
|
+
hash.update(value);
|
|
3176
|
+
hash.update("\0");
|
|
3177
|
+
}
|
|
3178
|
+
return hash.digest("hex");
|
|
3179
|
+
}
|
|
3180
|
+
async function readBuildContextFiles(buildContext) {
|
|
3181
|
+
const files = [];
|
|
3182
|
+
await collectBuildContextFiles(buildContext, "", files);
|
|
3183
|
+
return files.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
3184
|
+
}
|
|
3185
|
+
async function collectBuildContextFiles(buildContext, relativeDir, files) {
|
|
3186
|
+
const absoluteDir = path15.join(buildContext, relativeDir);
|
|
3187
|
+
const entries = await readdir(absoluteDir, { withFileTypes: true });
|
|
3188
|
+
for (const entry of entries) {
|
|
3189
|
+
const relativePath = path15.join(relativeDir, entry.name);
|
|
3190
|
+
if (entry.isDirectory()) {
|
|
3191
|
+
await collectBuildContextFiles(buildContext, relativePath, files);
|
|
3192
|
+
continue;
|
|
3193
|
+
}
|
|
3194
|
+
if (!entry.isFile()) {
|
|
3195
|
+
continue;
|
|
3196
|
+
}
|
|
3197
|
+
files.push({
|
|
3198
|
+
relativePath: relativePath.split(path15.sep).join("/"),
|
|
3199
|
+
bytes: await readFile3(path15.join(buildContext, relativePath))
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
// packages/runner-e2b/src/opened-env.ts
|
|
3205
|
+
import { mkdtempSync as mkdtempSync2, rmSync as rmSync2 } from "node:fs";
|
|
3206
|
+
import { readFile as readFile4, writeFile } from "node:fs/promises";
|
|
3207
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
3208
|
+
import path17 from "node:path";
|
|
3209
|
+
import { PassThrough, Writable as Writable2 } from "node:stream";
|
|
3210
|
+
|
|
3211
|
+
// packages/runner-e2b/src/job-handle.ts
|
|
3212
|
+
import path16 from "node:path";
|
|
3213
|
+
var JOB_DIR2 = "/tmp/poe-jobs";
|
|
3214
|
+
function createE2bJobHandle(input) {
|
|
3215
|
+
const fs = createE2bLogStreamFs(input.sandbox);
|
|
3216
|
+
return {
|
|
3217
|
+
id: input.jobId,
|
|
3218
|
+
envId: input.envId,
|
|
3219
|
+
tool: input.tool,
|
|
3220
|
+
argv: input.argv,
|
|
3221
|
+
async status() {
|
|
3222
|
+
const exit = await readExitCode(input.sandbox, input.jobId);
|
|
3223
|
+
if (exit !== null) {
|
|
3224
|
+
return "exited";
|
|
3225
|
+
}
|
|
3226
|
+
const processes = await input.sandbox.commands.list();
|
|
3227
|
+
const isRunning = input.pid === void 0 ? processes.some((process2) => processMentionsJob(process2, input.jobId)) : processes.some((process2) => process2.pid === input.pid);
|
|
3228
|
+
return isRunning ? "running" : "lost";
|
|
3229
|
+
},
|
|
3230
|
+
stream(opts = {}) {
|
|
3231
|
+
return streamLogFile({ fs }, input.jobId, opts);
|
|
3232
|
+
},
|
|
3233
|
+
async wait() {
|
|
3234
|
+
const result = await waitForExit({ fs }, input.jobId);
|
|
3235
|
+
const preserveMs = input.preserveAfterExitHours * 60 * 60 * 1e3;
|
|
3236
|
+
if (preserveMs > 0) {
|
|
3237
|
+
await input.sandbox.setTimeout(preserveMs);
|
|
3238
|
+
}
|
|
3239
|
+
return result;
|
|
3240
|
+
},
|
|
3241
|
+
async kill() {
|
|
3242
|
+
const pids = input.pid === void 0 ? (await input.sandbox.commands.list()).filter((process2) => processMentionsJob(process2, input.jobId)).map((process2) => process2.pid) : [input.pid];
|
|
3243
|
+
await Promise.all(pids.map((pid) => input.sandbox.commands.kill(pid)));
|
|
3244
|
+
}
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
function createE2bLogStreamFs(sandbox) {
|
|
3248
|
+
return {
|
|
3249
|
+
promises: {
|
|
3250
|
+
async readFile(filePath) {
|
|
3251
|
+
return Buffer.from(await sandbox.files.read(filePath, { format: "bytes" }));
|
|
3252
|
+
},
|
|
3253
|
+
async stat(filePath) {
|
|
3254
|
+
const result = await sandbox.commands.run(
|
|
3255
|
+
`stat -c %Y ${shellQuote2(filePath)} 2>/dev/null || stat -f %m ${shellQuote2(filePath)}`
|
|
3256
|
+
);
|
|
3257
|
+
if (!("stdout" in result)) {
|
|
3258
|
+
throw new Error(`Unable to stat ${filePath}`);
|
|
3259
|
+
}
|
|
3260
|
+
const seconds = Number(result.stdout?.trim());
|
|
3261
|
+
if (!Number.isFinite(seconds)) {
|
|
3262
|
+
throw new Error(`Unable to stat ${filePath}`);
|
|
3263
|
+
}
|
|
3264
|
+
return { mtimeMs: seconds * 1e3 };
|
|
3265
|
+
}
|
|
3266
|
+
},
|
|
3267
|
+
watch(filePath, listener) {
|
|
3268
|
+
let closed = false;
|
|
3269
|
+
let stop = null;
|
|
3270
|
+
void sandbox.files.watchDir(path16.dirname(filePath), listener, { recursive: false }).then((handle) => {
|
|
3271
|
+
if (closed) {
|
|
3272
|
+
void handle.stop();
|
|
3273
|
+
return;
|
|
3274
|
+
}
|
|
3275
|
+
stop = () => {
|
|
3276
|
+
void handle.stop();
|
|
3277
|
+
};
|
|
3278
|
+
});
|
|
3279
|
+
return {
|
|
3280
|
+
close() {
|
|
3281
|
+
closed = true;
|
|
3282
|
+
stop?.();
|
|
3283
|
+
}
|
|
3284
|
+
};
|
|
3285
|
+
}
|
|
3286
|
+
};
|
|
3287
|
+
}
|
|
3288
|
+
function processMentionsJob(process2, jobId) {
|
|
3289
|
+
const needle = `/tmp/poe-jobs/${jobId}`;
|
|
3290
|
+
return process2.cmd.includes(needle) || process2.args.some((arg) => arg.includes(needle));
|
|
3291
|
+
}
|
|
3292
|
+
function shellQuote2(value) {
|
|
3293
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
3294
|
+
}
|
|
3295
|
+
async function readExitCode(sandbox, jobId) {
|
|
3296
|
+
try {
|
|
3297
|
+
const contents = await sandbox.files.read(`${JOB_DIR2}/${jobId}.exit`);
|
|
3298
|
+
const exitCode = Number(contents.trim());
|
|
3299
|
+
return Number.isInteger(exitCode) ? exitCode : null;
|
|
3300
|
+
} catch {
|
|
3301
|
+
return null;
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
|
|
3305
|
+
// packages/runner-e2b/src/opened-env.ts
|
|
3306
|
+
var REMOTE_COMMAND_STDERR_TAIL_SIZE = 30;
|
|
3307
|
+
function createOpenedE2bEnv(input) {
|
|
3308
|
+
const hostRunner = input.spec.hostRunner ?? createHostRunner();
|
|
3309
|
+
const hostWorkspaceDir = path17.resolve(input.spec.cwd);
|
|
3310
|
+
const sandboxWorkspaceDir = normalizeSandboxWorkspaceDir(input.runtime.workspace_dir);
|
|
3311
|
+
let lastProcess = null;
|
|
3312
|
+
let detachedJobContext = null;
|
|
3313
|
+
const mapWorkspaceCwd = (cwd) => {
|
|
3314
|
+
if (cwd === void 0) {
|
|
3315
|
+
return void 0;
|
|
3316
|
+
}
|
|
3317
|
+
if (path17.isAbsolute(cwd) && path17.resolve(cwd) === hostWorkspaceDir) {
|
|
3318
|
+
return sandboxWorkspaceDir;
|
|
3319
|
+
}
|
|
3320
|
+
return cwd;
|
|
3321
|
+
};
|
|
3322
|
+
const attachedJobId = input.spec.detachedJobId;
|
|
3323
|
+
const env = {
|
|
3324
|
+
id: input.sandbox.sandboxId,
|
|
3325
|
+
job: attachedJobId ? createE2bJobHandle({
|
|
3326
|
+
sandbox: input.sandbox,
|
|
3327
|
+
envId: input.sandbox.sandboxId,
|
|
3328
|
+
jobId: attachedJobId,
|
|
3329
|
+
tool: input.spec.jobLabel.tool,
|
|
3330
|
+
argv: input.spec.jobLabel.argv,
|
|
3331
|
+
preserveAfterExitHours: input.runtime.preserve_after_exit_hours ?? 24
|
|
3332
|
+
}) : null,
|
|
3333
|
+
fs: createE2bLogStreamFs(input.sandbox),
|
|
3334
|
+
setDetachedJobContext(context) {
|
|
3335
|
+
detachedJobContext = context;
|
|
3336
|
+
},
|
|
3337
|
+
async uploadWorkspace() {
|
|
3338
|
+
if (input.spec.runner?.sync === "none") {
|
|
3339
|
+
return { files: 0, bytes: 0, skipped: [] };
|
|
3340
|
+
}
|
|
3341
|
+
const tempDir = mkdtempSync2(path17.join(tmpdir2(), "poe-e2b-upload-"));
|
|
3342
|
+
const archivePath = path17.join(tempDir, "workspace.tar");
|
|
3343
|
+
try {
|
|
3344
|
+
await runOrThrow2(hostRunner, {
|
|
3345
|
+
command: "tar",
|
|
3346
|
+
args: [
|
|
3347
|
+
...input.spec.uploadIgnoreFiles.flatMap((ignored) => ["--exclude", ignored]),
|
|
3348
|
+
"-cf",
|
|
3349
|
+
archivePath,
|
|
3350
|
+
"-C",
|
|
3351
|
+
input.spec.cwd,
|
|
3352
|
+
"."
|
|
3353
|
+
],
|
|
3354
|
+
stdout: "pipe",
|
|
3355
|
+
stderr: "pipe"
|
|
3356
|
+
});
|
|
3357
|
+
await input.sandbox.files.write(
|
|
3358
|
+
"/tmp/poe-workspace-upload.tar",
|
|
3359
|
+
toArrayBuffer(await readFile4(archivePath))
|
|
3360
|
+
);
|
|
3361
|
+
await runRemoteOrThrow(
|
|
3362
|
+
input.sandbox,
|
|
3363
|
+
createUploadWorkspaceCommand(sandboxWorkspaceDir)
|
|
3364
|
+
);
|
|
3365
|
+
return { files: 0, bytes: 0, skipped: [] };
|
|
3366
|
+
} finally {
|
|
3367
|
+
rmSync2(tempDir, { recursive: true, force: true });
|
|
3368
|
+
}
|
|
3369
|
+
},
|
|
3370
|
+
async downloadWorkspace(opts) {
|
|
3371
|
+
if (input.spec.runner?.sync === "upload" || input.spec.runner?.sync === "none") {
|
|
3372
|
+
return { files: 0, bytes: 0, conflicts: [] };
|
|
3373
|
+
}
|
|
3374
|
+
const tempDir = mkdtempSync2(path17.join(tmpdir2(), "poe-e2b-download-"));
|
|
3375
|
+
const archivePath = path17.join(tempDir, "workspace.tar");
|
|
3376
|
+
try {
|
|
3377
|
+
await runRemoteOrThrow(
|
|
3378
|
+
input.sandbox,
|
|
3379
|
+
`tar -cf /tmp/poe-workspace-download.tar -C ${shellQuote3(sandboxWorkspaceDir)} .`
|
|
3380
|
+
);
|
|
3381
|
+
const archive = await input.sandbox.files.read("/tmp/poe-workspace-download.tar", {
|
|
3382
|
+
format: "bytes"
|
|
3383
|
+
});
|
|
3384
|
+
await writeFile(archivePath, Buffer.from(archive));
|
|
3385
|
+
await runOrThrow2(hostRunner, {
|
|
3386
|
+
command: "tar",
|
|
3387
|
+
args: [
|
|
3388
|
+
opts.conflictPolicy === "refuse" ? "-xkf" : "-xf",
|
|
3389
|
+
archivePath,
|
|
3390
|
+
"-C",
|
|
3391
|
+
input.spec.cwd
|
|
3392
|
+
],
|
|
3393
|
+
stdout: "pipe",
|
|
3394
|
+
stderr: "pipe"
|
|
3395
|
+
});
|
|
3396
|
+
return { files: 0, bytes: archive.byteLength, conflicts: [] };
|
|
3397
|
+
} finally {
|
|
3398
|
+
rmSync2(tempDir, { recursive: true, force: true });
|
|
3399
|
+
}
|
|
3400
|
+
},
|
|
3401
|
+
exec(spec) {
|
|
3402
|
+
const handle = runE2bCommand(input.sandbox, {
|
|
3403
|
+
...spec,
|
|
3404
|
+
cwd: mapWorkspaceCwd(spec.cwd),
|
|
3405
|
+
env: resolveSandboxCommandEnv(spec.env)
|
|
3406
|
+
});
|
|
3407
|
+
lastProcess = { started: handle.started };
|
|
3408
|
+
return handle;
|
|
3409
|
+
},
|
|
3410
|
+
async detach() {
|
|
3411
|
+
if (detachedJobContext === null) {
|
|
3412
|
+
throw new Error("Cannot detach E2B environment before a job context is registered.");
|
|
3413
|
+
}
|
|
3414
|
+
if (lastProcess === null) {
|
|
3415
|
+
throw new Error("Cannot detach E2B environment before a command is running.");
|
|
3416
|
+
}
|
|
3417
|
+
const command = await lastProcess.started;
|
|
3418
|
+
const preserveAfterExitHours = input.runtime.preserve_after_exit_hours ?? 24;
|
|
3419
|
+
const preserveMs = preserveAfterExitHours * 60 * 60 * 1e3;
|
|
3420
|
+
if (preserveMs > 0) {
|
|
3421
|
+
await input.sandbox.setTimeout(preserveMs);
|
|
3422
|
+
}
|
|
3423
|
+
return createE2bJobHandle({
|
|
3424
|
+
sandbox: input.sandbox,
|
|
3425
|
+
envId: input.sandbox.sandboxId,
|
|
3426
|
+
jobId: detachedJobContext.id,
|
|
3427
|
+
tool: detachedJobContext.tool,
|
|
3428
|
+
argv: detachedJobContext.argv,
|
|
3429
|
+
pid: command.pid,
|
|
3430
|
+
preserveAfterExitHours
|
|
3431
|
+
});
|
|
3432
|
+
},
|
|
3433
|
+
shell() {
|
|
3434
|
+
const shellSpec = input.spec.shellSpec;
|
|
3435
|
+
const command = shellSpec?.command ?? input.spec.env.SHELL ?? "sh";
|
|
3436
|
+
return runE2bPty(input.sandbox, {
|
|
3437
|
+
command,
|
|
3438
|
+
...shellSpec?.args ? { args: shellSpec.args } : {},
|
|
3439
|
+
cwd: mapWorkspaceCwd(shellSpec?.cwd ?? input.spec.cwd),
|
|
3440
|
+
env: resolveSandboxCommandEnv(
|
|
3441
|
+
shellSpec && "env" in shellSpec ? shellSpec.env : input.spec.env
|
|
3442
|
+
),
|
|
3443
|
+
stdin: "inherit",
|
|
3444
|
+
stdout: "inherit",
|
|
3445
|
+
stderr: "inherit",
|
|
3446
|
+
tty: true
|
|
3447
|
+
});
|
|
3448
|
+
},
|
|
3449
|
+
async close() {
|
|
3450
|
+
await input.sandbox.kill();
|
|
3451
|
+
}
|
|
3452
|
+
};
|
|
3453
|
+
return env;
|
|
3454
|
+
}
|
|
3455
|
+
function runE2bCommand(sandbox, spec) {
|
|
3456
|
+
const stdout = spec.stdout === "inherit" ? null : new PassThrough();
|
|
3457
|
+
const stderr = spec.stderr === "inherit" ? null : new PassThrough();
|
|
3458
|
+
let e2bHandle = null;
|
|
3459
|
+
const command = shellCommand([spec.command, ...spec.args ?? []]);
|
|
3460
|
+
const started = sandbox.commands.run(command, {
|
|
3461
|
+
background: true,
|
|
3462
|
+
cwd: spec.cwd,
|
|
3463
|
+
envs: spec.env,
|
|
3464
|
+
stdin: spec.stdin === "pipe",
|
|
3465
|
+
onStdout(data) {
|
|
3466
|
+
stdout?.write(data);
|
|
3467
|
+
if (spec.stdout === "inherit") {
|
|
3468
|
+
process.stdout.write(data);
|
|
3469
|
+
}
|
|
3470
|
+
},
|
|
3471
|
+
onStderr(data) {
|
|
3472
|
+
stderr?.write(data);
|
|
3473
|
+
if (spec.stderr === "inherit") {
|
|
3474
|
+
process.stderr.write(data);
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
});
|
|
3478
|
+
const stdin = spec.stdin === "pipe" ? new Writable2({
|
|
3479
|
+
write(chunk, _encoding, callback) {
|
|
3480
|
+
started.then(
|
|
3481
|
+
(handle) => sandbox.commands.sendStdin(
|
|
3482
|
+
handle.pid,
|
|
3483
|
+
Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))
|
|
3484
|
+
)
|
|
3485
|
+
).then(() => callback(), callback);
|
|
3486
|
+
},
|
|
3487
|
+
final(callback) {
|
|
3488
|
+
if (sandbox.commands.closeStdin === void 0) {
|
|
3489
|
+
callback();
|
|
3490
|
+
return;
|
|
3491
|
+
}
|
|
3492
|
+
started.then((handle) => sandbox.commands.closeStdin(handle.pid)).then(() => callback(), callback);
|
|
3493
|
+
}
|
|
3494
|
+
}) : null;
|
|
3495
|
+
const result = started.then((handle) => {
|
|
3496
|
+
e2bHandle = handle;
|
|
3497
|
+
return handle.wait();
|
|
3498
|
+
}).then(
|
|
3499
|
+
(result2) => {
|
|
3500
|
+
stdout?.end();
|
|
3501
|
+
stderr?.end();
|
|
3502
|
+
return { exitCode: result2.exitCode ?? 0 };
|
|
3503
|
+
},
|
|
3504
|
+
(error2) => {
|
|
3505
|
+
stdout?.end();
|
|
3506
|
+
stderr?.end();
|
|
3507
|
+
if (isExitError(error2)) {
|
|
3508
|
+
return { exitCode: error2.exitCode };
|
|
3509
|
+
}
|
|
3510
|
+
return { exitCode: 1 };
|
|
3511
|
+
}
|
|
3512
|
+
);
|
|
3513
|
+
return {
|
|
3514
|
+
get pid() {
|
|
3515
|
+
return e2bHandle?.pid ?? null;
|
|
3516
|
+
},
|
|
3517
|
+
stdin,
|
|
3518
|
+
stdout,
|
|
3519
|
+
stderr,
|
|
3520
|
+
result,
|
|
3521
|
+
kill() {
|
|
3522
|
+
void e2bHandle?.kill();
|
|
3523
|
+
},
|
|
3524
|
+
get e2bHandle() {
|
|
3525
|
+
return e2bHandle;
|
|
3526
|
+
},
|
|
3527
|
+
started
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
function runE2bPty(sandbox, spec) {
|
|
3531
|
+
const stdout = new PassThrough();
|
|
3532
|
+
let handleRef = null;
|
|
3533
|
+
const stdin = new Writable2({
|
|
3534
|
+
write(chunk, _encoding, callback) {
|
|
3535
|
+
if (handleRef === null) {
|
|
3536
|
+
callback(new Error("E2B PTY stdin is not ready."));
|
|
3537
|
+
return;
|
|
3538
|
+
}
|
|
3539
|
+
sandbox.pty.sendInput(handleRef.pid, Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))).then(() => callback(), callback);
|
|
3540
|
+
}
|
|
3541
|
+
});
|
|
3542
|
+
const started = sandbox.pty.create({
|
|
3543
|
+
cols: process.stdout.columns || 80,
|
|
3544
|
+
rows: process.stdout.rows || 24,
|
|
3545
|
+
cwd: spec.cwd,
|
|
3546
|
+
envs: spec.env,
|
|
3547
|
+
onData(data) {
|
|
3548
|
+
stdout.write(Buffer.from(data));
|
|
3549
|
+
if (spec.stdout === "inherit") {
|
|
3550
|
+
process.stdout.write(Buffer.from(data));
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
});
|
|
3554
|
+
const result = started.then((handle) => {
|
|
3555
|
+
handleRef = handle;
|
|
3556
|
+
return handle.wait();
|
|
3557
|
+
}).then(
|
|
3558
|
+
(result2) => {
|
|
3559
|
+
stdout.end();
|
|
3560
|
+
return { exitCode: result2.exitCode ?? 0 };
|
|
3561
|
+
},
|
|
3562
|
+
() => {
|
|
3563
|
+
stdout.end();
|
|
3564
|
+
return { exitCode: 1 };
|
|
3565
|
+
}
|
|
3566
|
+
);
|
|
3567
|
+
return {
|
|
3568
|
+
get pid() {
|
|
3569
|
+
return handleRef?.pid ?? null;
|
|
3570
|
+
},
|
|
3571
|
+
stdin: spec.stdin === "inherit" ? process.stdin : stdin,
|
|
3572
|
+
stdout: spec.stdout === "inherit" ? null : stdout,
|
|
3573
|
+
stderr: null,
|
|
3574
|
+
result,
|
|
3575
|
+
kill() {
|
|
3576
|
+
void (handleRef === null ? void 0 : sandbox.pty.kill(handleRef.pid));
|
|
3577
|
+
}
|
|
3578
|
+
};
|
|
3579
|
+
}
|
|
3580
|
+
async function runRemoteOrThrow(sandbox, command) {
|
|
3581
|
+
const stdoutTail = createLineTail(REMOTE_COMMAND_STDERR_TAIL_SIZE);
|
|
3582
|
+
const stderrTail = createLineTail(REMOTE_COMMAND_STDERR_TAIL_SIZE);
|
|
3583
|
+
let result;
|
|
3584
|
+
try {
|
|
3585
|
+
result = await sandbox.commands.run(command, {
|
|
3586
|
+
onStdout(data) {
|
|
3587
|
+
stdoutTail.push(data);
|
|
3588
|
+
},
|
|
3589
|
+
onStderr(data) {
|
|
3590
|
+
stderrTail.push(data);
|
|
3591
|
+
}
|
|
3592
|
+
});
|
|
3593
|
+
} catch (error2) {
|
|
3594
|
+
appendRemoteCommandOutput(error2, stdoutTail, stderrTail);
|
|
3595
|
+
if (isCommandExitError(error2)) {
|
|
3596
|
+
throw decorateRemoteCommandError(error2, command, stderrTail.values());
|
|
3597
|
+
}
|
|
3598
|
+
throw error2;
|
|
3599
|
+
}
|
|
3600
|
+
appendRemoteCommandOutput(result, stdoutTail, stderrTail);
|
|
3601
|
+
if ("exitCode" in result && result.exitCode !== 0) {
|
|
3602
|
+
throw decorateRemoteCommandError(
|
|
3603
|
+
new Error(`E2B command failed with exit code ${result.exitCode}`),
|
|
3604
|
+
command,
|
|
3605
|
+
stderrTail.values()
|
|
3606
|
+
);
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
function appendRemoteCommandOutput(source, stdoutTail, stderrTail) {
|
|
3610
|
+
if (!source || typeof source !== "object") {
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
const output = source;
|
|
3614
|
+
if (typeof output.stdout === "string") {
|
|
3615
|
+
stdoutTail.push(output.stdout);
|
|
3616
|
+
}
|
|
3617
|
+
if (typeof output.stderr === "string") {
|
|
3618
|
+
stderrTail.push(output.stderr);
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
function decorateRemoteCommandError(error2, command, stderrTail) {
|
|
3622
|
+
const original = error2 instanceof Error ? error2 : new Error(String(error2));
|
|
3623
|
+
const tail = stderrTail.length === 0 ? "" : `
|
|
3624
|
+
|
|
3625
|
+
Last stderr output:
|
|
3626
|
+
${stderrTail.join("\n")}`;
|
|
3627
|
+
const decorated = new Error(`E2B command failed: ${command}
|
|
3628
|
+
${original.message}${tail}`);
|
|
3629
|
+
decorated.stack = original.stack;
|
|
3630
|
+
decorated.cause = original;
|
|
3631
|
+
return decorated;
|
|
3632
|
+
}
|
|
3633
|
+
function createLineTail(maxLines) {
|
|
3634
|
+
const lines = [];
|
|
3635
|
+
let pending = "";
|
|
3636
|
+
const appendLine = (line) => {
|
|
3637
|
+
lines.push(trimTrailingCarriageReturn(line));
|
|
3638
|
+
while (lines.length > maxLines) {
|
|
3639
|
+
lines.shift();
|
|
3640
|
+
}
|
|
3641
|
+
};
|
|
3642
|
+
return {
|
|
3643
|
+
push(chunk) {
|
|
3644
|
+
pending += chunk;
|
|
3645
|
+
const parts = pending.split("\n");
|
|
3646
|
+
pending = parts.pop() ?? "";
|
|
3647
|
+
for (const line of parts) {
|
|
3648
|
+
appendLine(line);
|
|
3649
|
+
}
|
|
3650
|
+
},
|
|
3651
|
+
values() {
|
|
3652
|
+
const output = [...lines];
|
|
3653
|
+
if (pending.length > 0) {
|
|
3654
|
+
output.push(trimTrailingCarriageReturn(pending));
|
|
3655
|
+
}
|
|
3656
|
+
return output.slice(-maxLines);
|
|
3657
|
+
}
|
|
3658
|
+
};
|
|
3659
|
+
}
|
|
3660
|
+
function trimTrailingCarriageReturn(value) {
|
|
3661
|
+
return value.endsWith("\r") ? value.slice(0, -1) : value;
|
|
3662
|
+
}
|
|
3663
|
+
async function runOrThrow2(runner, spec) {
|
|
3664
|
+
const handle = runner.exec(spec);
|
|
3665
|
+
const stderr = readableToString(handle.stderr);
|
|
3666
|
+
const result = await handle.result;
|
|
3667
|
+
if (result.exitCode !== 0) {
|
|
3668
|
+
throw new Error(
|
|
3669
|
+
`Command failed with exit code ${result.exitCode}: ${spec.command} ${(spec.args ?? []).join(" ")}
|
|
3670
|
+
${await stderr}`
|
|
3671
|
+
);
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
function shellCommand(argv) {
|
|
3675
|
+
return argv.map(shellQuote3).join(" ");
|
|
3676
|
+
}
|
|
3677
|
+
function shellQuote3(value) {
|
|
3678
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
3679
|
+
}
|
|
3680
|
+
function createUploadWorkspaceCommand(sandboxWorkspaceDir) {
|
|
3681
|
+
const quotedWorkspaceDir = shellQuote3(sandboxWorkspaceDir);
|
|
3682
|
+
return [
|
|
3683
|
+
`mkdir -p ${quotedWorkspaceDir} || { command -v sudo >/dev/null 2>&1 && sudo mkdir -p ${quotedWorkspaceDir} && sudo chown "$(id -u):$(id -g)" ${quotedWorkspaceDir}; }`,
|
|
3684
|
+
`test -w ${quotedWorkspaceDir} && tar -xf /tmp/poe-workspace-upload.tar -C ${quotedWorkspaceDir}`
|
|
3685
|
+
].join("\n");
|
|
3686
|
+
}
|
|
3687
|
+
function resolveSandboxCommandEnv(env) {
|
|
3688
|
+
if (env === void 0) {
|
|
3689
|
+
return void 0;
|
|
3690
|
+
}
|
|
3691
|
+
return {
|
|
3692
|
+
...env,
|
|
3693
|
+
HOME: "/home/user"
|
|
3694
|
+
};
|
|
3695
|
+
}
|
|
3696
|
+
function normalizeSandboxWorkspaceDir(workspaceDir) {
|
|
3697
|
+
const resolvedWorkspaceDir = workspaceDir ?? "/workspace";
|
|
3698
|
+
if (!path17.posix.isAbsolute(resolvedWorkspaceDir)) {
|
|
3699
|
+
throw new Error("E2B runtime workspace_dir must be an absolute sandbox path.");
|
|
3700
|
+
}
|
|
3701
|
+
let normalized = path17.posix.normalize(resolvedWorkspaceDir);
|
|
3702
|
+
while (normalized.length > 1 && normalized.endsWith("/")) {
|
|
3703
|
+
normalized = normalized.slice(0, -1);
|
|
3704
|
+
}
|
|
3705
|
+
return normalized;
|
|
3706
|
+
}
|
|
3707
|
+
function isExitError(error2) {
|
|
3708
|
+
return Boolean(
|
|
3709
|
+
error2 && typeof error2 === "object" && typeof error2.exitCode === "number"
|
|
3710
|
+
);
|
|
3711
|
+
}
|
|
3712
|
+
function isCommandExitError(error2) {
|
|
3713
|
+
return isExitError(error2) || Boolean(
|
|
3714
|
+
error2 && typeof error2 === "object" && error2.name === "CommandExitError"
|
|
3715
|
+
);
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3718
|
+
// packages/runner-e2b/src/auth-scope.ts
|
|
3719
|
+
import os4 from "node:os";
|
|
3720
|
+
import { promises as nodeFs4 } from "node:fs";
|
|
3721
|
+
var e2bAuthScope = defineScope("e2b", {
|
|
3722
|
+
api_key: {
|
|
3723
|
+
type: "string",
|
|
3724
|
+
default: "",
|
|
3725
|
+
doc: "E2B API key",
|
|
3726
|
+
env: "E2B_API_KEY"
|
|
3727
|
+
}
|
|
3728
|
+
});
|
|
3729
|
+
async function resolveE2bApiKey(input) {
|
|
3730
|
+
const homeDir = input.homeDir ?? os4.homedir();
|
|
3731
|
+
const fs = input.fs ?? nodeFs4;
|
|
3732
|
+
const env = input.env ?? process.env;
|
|
3733
|
+
const document = await readMergedDocument(
|
|
3734
|
+
fs,
|
|
3735
|
+
resolveConfigPath(homeDir),
|
|
3736
|
+
resolveProjectConfigPath(input.cwd)
|
|
3737
|
+
);
|
|
3738
|
+
const resolved = resolveScope(e2bAuthScope.schema, document.e2b, env);
|
|
3739
|
+
if (resolved.api_key.length === 0) {
|
|
3740
|
+
throw new Error(
|
|
3741
|
+
"No E2B API key. Set E2B_API_KEY or e2b.api_key in ~/.poe-code/config.json."
|
|
3742
|
+
);
|
|
3743
|
+
}
|
|
3744
|
+
return resolved.api_key;
|
|
3745
|
+
}
|
|
3746
|
+
|
|
3747
|
+
// packages/runner-e2b/src/factory.ts
|
|
3748
|
+
var e2bExecutionEnvFactory = {
|
|
3749
|
+
type: "e2b",
|
|
3750
|
+
supportsDetach: true,
|
|
3751
|
+
async open(spec) {
|
|
3752
|
+
const runtime = parseE2bRuntime(spec.runtime);
|
|
3753
|
+
const runtimeCwd = spec.runtimeCwd ?? spec.cwd;
|
|
3754
|
+
const apiKey = await resolveE2bApiKey({ cwd: runtimeCwd });
|
|
3755
|
+
const templateId = runtime.template_id ?? (await buildE2bRuntimeTemplate({
|
|
3756
|
+
runtime,
|
|
3757
|
+
dockerfilePath: path18.resolve(
|
|
3758
|
+
runtimeCwd,
|
|
3759
|
+
runtime.dockerfile ?? path18.join(".poe-code", "Dockerfile")
|
|
3760
|
+
),
|
|
3761
|
+
buildContext: path18.resolve(runtimeCwd, runtime.build_context ?? "."),
|
|
3762
|
+
state: spec.state,
|
|
3763
|
+
apiKey
|
|
3764
|
+
})).templateId;
|
|
3765
|
+
const sandbox = await createSandbox({
|
|
3766
|
+
apiKey,
|
|
3767
|
+
templateId,
|
|
3768
|
+
env: spec.env,
|
|
3769
|
+
timeoutMinutes: runtime.timeout_minutes
|
|
3770
|
+
});
|
|
3771
|
+
return createOpenedE2bEnv({ sandbox, spec, runtime });
|
|
3772
|
+
},
|
|
3773
|
+
async attach(envId, context) {
|
|
3774
|
+
const cwd = context?.cwd ?? process.cwd();
|
|
3775
|
+
const apiKey = await resolveE2bApiKey({ cwd });
|
|
3776
|
+
const sandbox = await connectSandbox(envId, apiKey);
|
|
3777
|
+
return createOpenedE2bEnv({
|
|
3778
|
+
sandbox,
|
|
3779
|
+
spec: {
|
|
3780
|
+
cwd: context?.cwd ?? "/workspace",
|
|
3781
|
+
runtime: {
|
|
3782
|
+
type: "e2b",
|
|
3783
|
+
build_args: {},
|
|
3784
|
+
mounts: [],
|
|
3785
|
+
workspace_dir: "/workspace",
|
|
3786
|
+
preserve_after_exit_hours: 24
|
|
3787
|
+
},
|
|
3788
|
+
env: {},
|
|
3789
|
+
uploadIgnoreFiles: [],
|
|
3790
|
+
jobLabel: { tool: context?.tool ?? "e2b", argv: context?.argv ?? [] },
|
|
3791
|
+
...context?.jobId ? { detachedJobId: context.jobId } : {}
|
|
3792
|
+
},
|
|
3793
|
+
runtime: {
|
|
3794
|
+
type: "e2b",
|
|
3795
|
+
build_args: {},
|
|
3796
|
+
mounts: [],
|
|
3797
|
+
workspace_dir: "/workspace",
|
|
3798
|
+
preserve_after_exit_hours: 24
|
|
3799
|
+
}
|
|
3800
|
+
});
|
|
3801
|
+
}
|
|
3802
|
+
};
|
|
3803
|
+
function parseE2bRuntime(runtime) {
|
|
3804
|
+
if (!runtime || typeof runtime !== "object" || Array.isArray(runtime)) {
|
|
3805
|
+
throw new Error("e2b runtime must be an object");
|
|
3806
|
+
}
|
|
3807
|
+
const record = runtime;
|
|
3808
|
+
if (record.type !== "e2b") {
|
|
3809
|
+
throw new Error('e2b runtime type must be "e2b"');
|
|
3810
|
+
}
|
|
3811
|
+
return record;
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
// packages/runner-e2b/src/index.ts
|
|
3815
|
+
var e2bExecutionEnvFactory2 = e2bExecutionEnvFactory;
|
|
3816
|
+
|
|
3817
|
+
// packages/agent-spawn/src/register-factories.ts
|
|
3818
|
+
registerExecutionEnvFactory(hostExecutionEnvFactory);
|
|
3819
|
+
registerExecutionEnvFactory(dockerExecutionEnvFactory);
|
|
3820
|
+
registerExecutionEnvFactory(e2bExecutionEnvFactory2);
|
|
3821
|
+
if (isVitest()) {
|
|
3822
|
+
registerExecutionEnvFactory(createTestHostExecutionEnvFactory());
|
|
3823
|
+
}
|
|
3824
|
+
function isVitest() {
|
|
3825
|
+
return process.env.VITEST !== void 0 || process.env.VITEST_POOL_ID !== void 0;
|
|
3826
|
+
}
|
|
3827
|
+
function createTestHostExecutionEnvFactory() {
|
|
3828
|
+
return {
|
|
3829
|
+
type: "host",
|
|
3830
|
+
supportsDetach: false,
|
|
3831
|
+
open: ((openSpec) => {
|
|
3832
|
+
return {
|
|
3833
|
+
id: "host",
|
|
3834
|
+
job: null,
|
|
3835
|
+
async uploadWorkspace() {
|
|
3836
|
+
return { files: 0, bytes: 0, skipped: [] };
|
|
3837
|
+
},
|
|
3838
|
+
async downloadWorkspace() {
|
|
3839
|
+
return { files: 0, bytes: 0, conflicts: [] };
|
|
3840
|
+
},
|
|
3841
|
+
exec(spec) {
|
|
3842
|
+
return runHost(spawnChildProcess2, spec);
|
|
3843
|
+
},
|
|
3844
|
+
async detach() {
|
|
3845
|
+
throw new Error(
|
|
3846
|
+
"host runtime does not support detach because host has no addressable env"
|
|
3847
|
+
);
|
|
3848
|
+
},
|
|
3849
|
+
shell() {
|
|
3850
|
+
return runHost(spawnChildProcess2, {
|
|
3851
|
+
command: openSpec.shellSpec?.command ?? openSpec.env.SHELL ?? process.env.SHELL ?? "sh",
|
|
3852
|
+
args: openSpec.shellSpec?.args,
|
|
3853
|
+
cwd: openSpec.cwd,
|
|
3854
|
+
env: openSpec.shellSpec && "env" in openSpec.shellSpec ? openSpec.shellSpec.env : openSpec.env,
|
|
3855
|
+
stdin: "inherit",
|
|
3856
|
+
stdout: "inherit",
|
|
3857
|
+
stderr: "inherit",
|
|
3858
|
+
tty: true
|
|
3859
|
+
});
|
|
3860
|
+
},
|
|
3861
|
+
async close() {
|
|
3862
|
+
}
|
|
3863
|
+
};
|
|
3864
|
+
}),
|
|
3865
|
+
async attach() {
|
|
3866
|
+
throw new Error("host runtime does not support reattach");
|
|
3867
|
+
}
|
|
3868
|
+
};
|
|
3869
|
+
}
|
|
3870
|
+
function runHost(spawnProcess, spec) {
|
|
3871
|
+
const stdin = spec.stdin ?? "ignore";
|
|
3872
|
+
const stdout = spec.stdout ?? "pipe";
|
|
3873
|
+
const stderr = spec.stderr ?? "pipe";
|
|
3874
|
+
const stdio = stdin === "inherit" && stdout === "inherit" && stderr === "inherit" ? "inherit" : [stdin, stdout, stderr];
|
|
3875
|
+
const child = spawnProcess(spec.command, spec.args ?? [], {
|
|
3876
|
+
cwd: spec.cwd,
|
|
3877
|
+
env: spec.env,
|
|
3878
|
+
stdio
|
|
3879
|
+
});
|
|
3880
|
+
const result = new Promise((resolve2) => {
|
|
3881
|
+
child.once("close", (code) => {
|
|
3882
|
+
resolve2({ exitCode: code ?? 1 });
|
|
3883
|
+
});
|
|
3884
|
+
child.once("error", () => {
|
|
3885
|
+
resolve2({ exitCode: 1 });
|
|
3886
|
+
});
|
|
3887
|
+
});
|
|
3888
|
+
const kill = (signal) => {
|
|
3889
|
+
child.kill(signal);
|
|
3890
|
+
};
|
|
3891
|
+
if (spec.signal?.aborted) {
|
|
3892
|
+
kill("SIGTERM");
|
|
3893
|
+
} else {
|
|
3894
|
+
spec.signal?.addEventListener("abort", () => kill("SIGTERM"), { once: true });
|
|
3895
|
+
}
|
|
3896
|
+
return {
|
|
3897
|
+
pid: child.pid ?? null,
|
|
3898
|
+
stdin: child.stdin,
|
|
3899
|
+
stdout: child.stdout,
|
|
3900
|
+
stderr: child.stderr,
|
|
3901
|
+
result,
|
|
3902
|
+
kill
|
|
3903
|
+
};
|
|
3904
|
+
}
|
|
3905
|
+
|
|
3906
|
+
// packages/agent-spawn/src/run-command.ts
|
|
3907
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
3908
|
+
|
|
3909
|
+
// packages/agent-spawn/src/types.ts
|
|
3910
|
+
function resolveModeConfig(modeConfig) {
|
|
3911
|
+
if (Array.isArray(modeConfig)) {
|
|
3912
|
+
return { args: modeConfig };
|
|
3913
|
+
}
|
|
3914
|
+
return {
|
|
3915
|
+
args: modeConfig.args ?? [],
|
|
3916
|
+
env: modeConfig.env && Object.keys(modeConfig.env).length > 0 ? modeConfig.env : void 0
|
|
3917
|
+
};
|
|
3918
|
+
}
|
|
3919
|
+
|
|
3920
|
+
// packages/agent-spawn/src/configs/mcp.ts
|
|
3921
|
+
function toJsonMcpServers(servers) {
|
|
3922
|
+
const out = {};
|
|
3923
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
3924
|
+
const mapped = { command: server.command };
|
|
3925
|
+
if (server.args && server.args.length > 0) {
|
|
3926
|
+
mapped.args = server.args;
|
|
3927
|
+
}
|
|
3928
|
+
if (server.env && Object.keys(server.env).length > 0) {
|
|
3929
|
+
mapped.env = server.env;
|
|
3930
|
+
}
|
|
3931
|
+
if (server.timeout !== void 0) {
|
|
3932
|
+
mapped.timeout = server.timeout;
|
|
3933
|
+
}
|
|
3934
|
+
out[name] = mapped;
|
|
3935
|
+
}
|
|
3936
|
+
return out;
|
|
3937
|
+
}
|
|
3938
|
+
function toTomlString(value) {
|
|
3939
|
+
return JSON.stringify(value);
|
|
3940
|
+
}
|
|
3941
|
+
function toTomlArray(values) {
|
|
3942
|
+
const serialized = values.map((value) => toTomlString(value));
|
|
3943
|
+
return `[${serialized.join(", ")}]`;
|
|
3944
|
+
}
|
|
3945
|
+
function toTomlInlineTable(values) {
|
|
3946
|
+
const parts = [];
|
|
3947
|
+
for (const [key, value] of Object.entries(values)) {
|
|
3948
|
+
parts.push(`${JSON.stringify(key)}=${toTomlString(value)}`);
|
|
3949
|
+
}
|
|
3950
|
+
return `{${parts.join(", ")}}`;
|
|
3951
|
+
}
|
|
3952
|
+
function serializeJsonMcpArgs(servers) {
|
|
3953
|
+
return ["--mcp-config", JSON.stringify({ mcpServers: toJsonMcpServers(servers) })];
|
|
3954
|
+
}
|
|
3955
|
+
function serializeOpenCodeMcpEnv(servers) {
|
|
3956
|
+
const mcp = {};
|
|
3957
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
3958
|
+
const entry = { type: "local", command: [server.command, ...server.args ?? []] };
|
|
3959
|
+
if (server.env && Object.keys(server.env).length > 0) {
|
|
3960
|
+
entry.environment = server.env;
|
|
3961
|
+
}
|
|
3962
|
+
mcp[name] = entry;
|
|
3963
|
+
}
|
|
3964
|
+
return { OPENCODE_CONFIG_CONTENT: JSON.stringify({ mcp }) };
|
|
3965
|
+
}
|
|
3966
|
+
function serializeCodexMcpArgs(servers) {
|
|
3967
|
+
const args = [];
|
|
3968
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
3969
|
+
const prefix = `mcp_servers.${name}`;
|
|
3970
|
+
args.push("-c", `${prefix}.command=${toTomlString(server.command)}`);
|
|
3971
|
+
if (server.args && server.args.length > 0) {
|
|
3972
|
+
args.push("-c", `${prefix}.args=${toTomlArray(server.args)}`);
|
|
3973
|
+
}
|
|
3974
|
+
if (server.env && Object.keys(server.env).length > 0) {
|
|
3975
|
+
args.push("-c", `${prefix}.env=${toTomlInlineTable(server.env)}`);
|
|
3976
|
+
}
|
|
3977
|
+
if (server.timeout !== void 0) {
|
|
3978
|
+
args.push("-c", `${prefix}.timeout=${server.timeout}`);
|
|
3979
|
+
}
|
|
3980
|
+
}
|
|
3981
|
+
return args;
|
|
3982
|
+
}
|
|
3983
|
+
function serializeGooseMcpArgs(servers) {
|
|
3984
|
+
return Object.values(servers).flatMap((server) => [
|
|
3985
|
+
"--with-extension",
|
|
3986
|
+
[server.command, ...server.args ?? []].join(" ")
|
|
3987
|
+
]);
|
|
3988
|
+
}
|
|
3989
|
+
|
|
3990
|
+
// packages/agent-spawn/src/configs/claude-code.ts
|
|
3991
|
+
var claudeCodeSpawnConfig = {
|
|
3992
|
+
kind: "cli",
|
|
3993
|
+
agentId: "claude-code",
|
|
3994
|
+
// ACP adapter support: yes (adapter: "claude")
|
|
3995
|
+
adapter: "claude",
|
|
3996
|
+
promptFlag: "-p",
|
|
3997
|
+
modelFlag: "--model",
|
|
3998
|
+
modelStripProviderPrefix: true,
|
|
3999
|
+
modelTransform: (model) => model.replaceAll(".", "-"),
|
|
4000
|
+
defaultArgs: [
|
|
4001
|
+
"--output-format",
|
|
4002
|
+
"stream-json",
|
|
4003
|
+
"--verbose"
|
|
4004
|
+
],
|
|
4005
|
+
mcpArgs: serializeJsonMcpArgs,
|
|
4006
|
+
modes: {
|
|
4007
|
+
yolo: ["--dangerously-skip-permissions"],
|
|
4008
|
+
edit: ["--permission-mode", "acceptEdits", "--allowedTools", "Bash,Read,Write,Edit,Glob,Grep,NotebookEdit"],
|
|
4009
|
+
read: ["--permission-mode", "plan"]
|
|
4010
|
+
},
|
|
4011
|
+
stdinMode: {
|
|
4012
|
+
omitPrompt: true,
|
|
4013
|
+
extraArgs: ["--input-format", "text"]
|
|
4014
|
+
},
|
|
4015
|
+
interactive: {
|
|
4016
|
+
defaultArgs: []
|
|
4017
|
+
},
|
|
4018
|
+
resumeCommand: (threadId) => ["--resume", threadId]
|
|
4019
|
+
};
|
|
4020
|
+
|
|
4021
|
+
// packages/agent-spawn/src/configs/codex.ts
|
|
4022
|
+
var codexSpawnConfig = {
|
|
4023
|
+
kind: "cli",
|
|
4024
|
+
agentId: "codex",
|
|
4025
|
+
// ACP adapter support: yes (adapter: "codex")
|
|
4026
|
+
adapter: "codex",
|
|
4027
|
+
promptFlag: "exec",
|
|
4028
|
+
modelFlag: "--model",
|
|
4029
|
+
modelStripProviderPrefix: true,
|
|
4030
|
+
defaultArgs: ["--skip-git-repo-check", "--json"],
|
|
4031
|
+
mcpArgs: serializeCodexMcpArgs,
|
|
4032
|
+
mcpArgsBeforeCommand: true,
|
|
4033
|
+
modes: {
|
|
4034
|
+
yolo: ["-s", "danger-full-access"],
|
|
4035
|
+
edit: ["-s", "workspace-write"],
|
|
4036
|
+
read: ["-s", "read-only"]
|
|
4037
|
+
},
|
|
4038
|
+
stdinMode: {
|
|
4039
|
+
omitPrompt: true,
|
|
4040
|
+
extraArgs: ["-"]
|
|
4041
|
+
},
|
|
4042
|
+
interactive: {
|
|
4043
|
+
defaultArgs: ["-a", "never"]
|
|
4044
|
+
},
|
|
4045
|
+
resumeCommand: (threadId, cwd) => ["resume", "-C", cwd, threadId]
|
|
4046
|
+
};
|
|
4047
|
+
|
|
4048
|
+
// packages/agent-spawn/src/configs/opencode.ts
|
|
4049
|
+
var openCodeSpawnConfig = {
|
|
4050
|
+
kind: "cli",
|
|
4051
|
+
agentId: "opencode",
|
|
4052
|
+
// ACP adapter support: yes (adapter: "opencode").
|
|
4053
|
+
// OpenCode's `--format json` emits NDJSON events with `{ type, sessionID, part }`
|
|
4054
|
+
// (no `{ event, ... }` field), so it needs the OpenCode adapter (not "native").
|
|
4055
|
+
adapter: "opencode",
|
|
4056
|
+
promptFlag: "run",
|
|
4057
|
+
modelFlag: "--model",
|
|
4058
|
+
modelStripProviderPrefix: false,
|
|
4059
|
+
modelTransform: (model) => {
|
|
4060
|
+
return model.startsWith("poe/") ? model : `poe/${model}`;
|
|
4061
|
+
},
|
|
4062
|
+
defaultArgs: ["--format", "json"],
|
|
4063
|
+
modes: {
|
|
4064
|
+
yolo: [],
|
|
4065
|
+
edit: [],
|
|
4066
|
+
read: ["--agent", "plan"]
|
|
4067
|
+
},
|
|
4068
|
+
interactive: {
|
|
4069
|
+
defaultArgs: [],
|
|
4070
|
+
promptFlag: "--prompt"
|
|
4071
|
+
},
|
|
4072
|
+
resumeCommand: (threadId, cwd) => [cwd, "--session", threadId],
|
|
4073
|
+
mcpEnv: serializeOpenCodeMcpEnv
|
|
4074
|
+
};
|
|
4075
|
+
var openCodeAcpSpawnConfig = {
|
|
4076
|
+
kind: "acp",
|
|
4077
|
+
agentId: "opencode",
|
|
4078
|
+
acpArgs: ["acp"],
|
|
4079
|
+
skipAuth: true,
|
|
4080
|
+
mcpEnv: serializeOpenCodeMcpEnv
|
|
4081
|
+
};
|
|
4082
|
+
|
|
4083
|
+
// packages/agent-spawn/src/configs/kimi.ts
|
|
4084
|
+
var kimiSpawnConfig = {
|
|
4085
|
+
kind: "cli",
|
|
4086
|
+
agentId: "kimi",
|
|
4087
|
+
// ACP adapter support: yes (adapter: "kimi").
|
|
4088
|
+
// Kimi's `--output-format stream-json` emits OpenAI-style `{ role, content }` JSON
|
|
4089
|
+
// (no `{ event, ... }` field), so it needs the Kimi adapter (not "native").
|
|
4090
|
+
adapter: "kimi",
|
|
4091
|
+
promptFlag: "-p",
|
|
4092
|
+
modelStripProviderPrefix: true,
|
|
4093
|
+
defaultArgs: ["--print", "--output-format", "stream-json"],
|
|
4094
|
+
mcpArgs: serializeJsonMcpArgs,
|
|
4095
|
+
modes: {
|
|
4096
|
+
yolo: ["--yolo"],
|
|
4097
|
+
edit: [],
|
|
4098
|
+
read: []
|
|
4099
|
+
},
|
|
4100
|
+
stdinMode: {
|
|
4101
|
+
omitPrompt: true,
|
|
4102
|
+
extraArgs: ["--input-format", "stream-json"]
|
|
4103
|
+
},
|
|
4104
|
+
interactive: {
|
|
4105
|
+
defaultArgs: [],
|
|
4106
|
+
promptFlag: "-p"
|
|
4107
|
+
},
|
|
4108
|
+
resumeCommand: (threadId, cwd) => ["--session", threadId, "--work-dir", cwd]
|
|
4109
|
+
};
|
|
4110
|
+
var kimiAcpSpawnConfig = {
|
|
4111
|
+
kind: "acp",
|
|
4112
|
+
agentId: "kimi",
|
|
4113
|
+
acpArgs: ["acp"]
|
|
4114
|
+
};
|
|
4115
|
+
|
|
4116
|
+
// packages/agent-spawn/src/configs/goose.ts
|
|
4117
|
+
var gooseFileSecretsEnv = { GOOSE_DISABLE_KEYRING: "1" };
|
|
4118
|
+
var gooseSpawnConfig = {
|
|
4119
|
+
kind: "cli",
|
|
4120
|
+
agentId: "goose",
|
|
4121
|
+
adapter: "native",
|
|
4122
|
+
promptFlag: "--text",
|
|
4123
|
+
modelFlag: "--model",
|
|
4124
|
+
modelStripProviderPrefix: false,
|
|
4125
|
+
defaultArgs: ["run", "--output-format", "stream-json"],
|
|
4126
|
+
defaultArgsPosition: "beforePrompt",
|
|
4127
|
+
mcpArgs: serializeGooseMcpArgs,
|
|
4128
|
+
mcpArgsPosition: "beforePrompt",
|
|
4129
|
+
modes: {
|
|
4130
|
+
yolo: { env: { ...gooseFileSecretsEnv, GOOSE_MODE: "auto" } },
|
|
4131
|
+
edit: { env: { ...gooseFileSecretsEnv, GOOSE_MODE: "smart_approve" } },
|
|
4132
|
+
read: { env: { ...gooseFileSecretsEnv, GOOSE_MODE: "chat" } }
|
|
4133
|
+
},
|
|
4134
|
+
stdinMode: {
|
|
4135
|
+
omitPrompt: true,
|
|
4136
|
+
extraArgs: ["--instructions", "-"]
|
|
4137
|
+
},
|
|
4138
|
+
interactive: {
|
|
4139
|
+
defaultArgs: ["session"],
|
|
4140
|
+
defaultArgsPosition: "beforePrompt"
|
|
4141
|
+
},
|
|
4142
|
+
resumeCommand: () => ["run", "--resume", "--text", "continue"]
|
|
4143
|
+
};
|
|
4144
|
+
var gooseAcpSpawnConfig = {
|
|
4145
|
+
kind: "acp",
|
|
4146
|
+
agentId: "goose",
|
|
4147
|
+
acpArgs: ["acp"],
|
|
4148
|
+
env: gooseFileSecretsEnv,
|
|
4149
|
+
skipAuth: true
|
|
4150
|
+
};
|
|
4151
|
+
|
|
4152
|
+
// packages/agent-spawn/src/configs/index.ts
|
|
4153
|
+
var allSpawnConfigs = [
|
|
4154
|
+
claudeCodeSpawnConfig,
|
|
4155
|
+
codexSpawnConfig,
|
|
4156
|
+
openCodeSpawnConfig,
|
|
4157
|
+
kimiSpawnConfig,
|
|
4158
|
+
gooseSpawnConfig
|
|
4159
|
+
];
|
|
4160
|
+
var lookup2 = /* @__PURE__ */ new Map();
|
|
4161
|
+
for (const config of allSpawnConfigs) {
|
|
4162
|
+
lookup2.set(config.agentId, config);
|
|
4163
|
+
}
|
|
4164
|
+
var acpLookup = /* @__PURE__ */ new Map();
|
|
4165
|
+
acpLookup.set(openCodeAcpSpawnConfig.agentId, openCodeAcpSpawnConfig);
|
|
4166
|
+
acpLookup.set(kimiAcpSpawnConfig.agentId, kimiAcpSpawnConfig);
|
|
4167
|
+
acpLookup.set(gooseAcpSpawnConfig.agentId, gooseAcpSpawnConfig);
|
|
4168
|
+
function getSpawnConfig(input) {
|
|
4169
|
+
const resolvedId = resolveAgentId(input);
|
|
4170
|
+
if (!resolvedId) {
|
|
4171
|
+
return void 0;
|
|
4172
|
+
}
|
|
4173
|
+
return lookup2.get(resolvedId);
|
|
4174
|
+
}
|
|
4175
|
+
function listMcpSupportedAgents() {
|
|
4176
|
+
const supported = [];
|
|
4177
|
+
for (const config of allSpawnConfigs) {
|
|
4178
|
+
if (config.kind !== "cli" || typeof config.mcpArgs !== "function" && typeof config.mcpEnv !== "function") {
|
|
4179
|
+
continue;
|
|
4180
|
+
}
|
|
4181
|
+
supported.push(config.agentId);
|
|
4182
|
+
}
|
|
4183
|
+
return supported;
|
|
4184
|
+
}
|
|
4185
|
+
|
|
4186
|
+
// packages/agent-spawn/src/spawn.ts
|
|
4187
|
+
import { mkdirSync, openSync, writeSync, closeSync } from "node:fs";
|
|
4188
|
+
import path19 from "node:path";
|
|
4189
|
+
|
|
4190
|
+
// packages/agent-spawn/src/configs/resolve-config.ts
|
|
4191
|
+
function resolveConfig(agentId) {
|
|
4192
|
+
const resolvedAgentId = resolveAgentId(agentId);
|
|
4193
|
+
if (!resolvedAgentId) {
|
|
4194
|
+
throw new Error(`Unknown agent "${agentId}".`);
|
|
4195
|
+
}
|
|
4196
|
+
const agentDefinition = allAgents.find((agent) => agent.id === resolvedAgentId);
|
|
4197
|
+
if (!agentDefinition) {
|
|
4198
|
+
throw new Error(`Unknown agent "${agentId}".`);
|
|
4199
|
+
}
|
|
4200
|
+
const spawnConfig = getSpawnConfig(resolvedAgentId);
|
|
4201
|
+
const binaryName = agentDefinition.binaryName;
|
|
4202
|
+
return { agentId: resolvedAgentId, binaryName, spawnConfig };
|
|
4203
|
+
}
|
|
4204
|
+
|
|
4205
|
+
// packages/agent-spawn/src/mcp-args.ts
|
|
4206
|
+
function hasMcpServers(servers) {
|
|
4207
|
+
if (!servers) {
|
|
4208
|
+
return false;
|
|
4209
|
+
}
|
|
4210
|
+
return Object.keys(servers).length > 0;
|
|
4211
|
+
}
|
|
4212
|
+
function getMcpArgs(config, servers) {
|
|
4213
|
+
if (!hasMcpServers(servers)) {
|
|
4214
|
+
return [];
|
|
4215
|
+
}
|
|
4216
|
+
if (!config.mcpArgs && !config.mcpEnv) {
|
|
4217
|
+
throw new Error(formatUnsupportedMcpSpawnMessage(config.agentId));
|
|
4218
|
+
}
|
|
4219
|
+
if (!config.mcpArgs) {
|
|
4220
|
+
return [];
|
|
4221
|
+
}
|
|
4222
|
+
return config.mcpArgs(servers);
|
|
4223
|
+
}
|
|
4224
|
+
function formatUnsupportedMcpSpawnMessage(agentId) {
|
|
4225
|
+
const supported = listMcpSupportedAgents();
|
|
4226
|
+
const supportedText = supported.length > 0 ? supported.join(", ") : "(none)";
|
|
4227
|
+
return `Agent "${agentId}" does not support MCP servers at spawn time.
|
|
4228
|
+
Agents with spawn-time MCP support: ${supportedText}`;
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4231
|
+
// packages/agent-spawn/src/model-utils.ts
|
|
4232
|
+
function stripModelNamespace(model) {
|
|
4233
|
+
const slashIndex = model.indexOf("/");
|
|
4234
|
+
return slashIndex === -1 ? model : model.slice(slashIndex + 1);
|
|
4235
|
+
}
|
|
4236
|
+
|
|
4237
|
+
// packages/agent-spawn/src/spawn.ts
|
|
4238
|
+
function resolveCliConfig(agentId) {
|
|
4239
|
+
const resolved = resolveConfig(agentId);
|
|
4240
|
+
if (!resolved.spawnConfig) {
|
|
4241
|
+
throw new Error(`Agent "${resolved.agentId}" has no spawn config.`);
|
|
4242
|
+
}
|
|
4243
|
+
if (resolved.spawnConfig.kind !== "cli") {
|
|
4244
|
+
throw new Error(`Agent "${resolved.agentId}" does not support CLI spawn.`);
|
|
4245
|
+
}
|
|
4246
|
+
if (!resolved.binaryName) {
|
|
4247
|
+
throw new Error(`Agent "${resolved.agentId}" has no binaryName.`);
|
|
4248
|
+
}
|
|
4249
|
+
return {
|
|
4250
|
+
agentId: resolved.agentId,
|
|
4251
|
+
binaryName: resolved.binaryName,
|
|
4252
|
+
spawnConfig: resolved.spawnConfig
|
|
4253
|
+
};
|
|
4254
|
+
}
|
|
4255
|
+
function getDefaultArgsPosition(config) {
|
|
4256
|
+
return config.defaultArgsPosition ?? "afterPrompt";
|
|
4257
|
+
}
|
|
4258
|
+
function getMcpArgsPosition(config) {
|
|
4259
|
+
if (config.mcpArgsPosition) {
|
|
4260
|
+
return config.mcpArgsPosition;
|
|
4261
|
+
}
|
|
4262
|
+
return config.mcpArgsBeforeCommand ? "beforeCommand" : "afterCommand";
|
|
4263
|
+
}
|
|
4264
|
+
function buildCliArgs(config, options, stdinMode) {
|
|
4265
|
+
const mcpArgs = getMcpArgs(config, options.mcpServers);
|
|
4266
|
+
const defaultArgsPosition = getDefaultArgsPosition(config);
|
|
4267
|
+
const mcpArgsPosition = getMcpArgsPosition(config);
|
|
4268
|
+
const args = [];
|
|
4269
|
+
if (mcpArgsPosition === "beforeCommand") {
|
|
4270
|
+
args.push(...mcpArgs);
|
|
4271
|
+
}
|
|
4272
|
+
if (defaultArgsPosition === "beforePrompt") {
|
|
4273
|
+
args.push(...config.defaultArgs);
|
|
4274
|
+
}
|
|
4275
|
+
if (mcpArgsPosition === "beforePrompt") {
|
|
4276
|
+
args.push(...mcpArgs);
|
|
4277
|
+
}
|
|
4278
|
+
if (stdinMode) {
|
|
4279
|
+
args.push(
|
|
4280
|
+
config.promptFlag,
|
|
4281
|
+
...stdinMode.omitPrompt ? [] : [options.prompt],
|
|
4282
|
+
...stdinMode.extraArgs
|
|
4283
|
+
);
|
|
4284
|
+
} else {
|
|
4285
|
+
args.push(config.promptFlag, options.prompt);
|
|
4286
|
+
}
|
|
4287
|
+
if (options.model && config.modelFlag) {
|
|
4288
|
+
let model = config.modelStripProviderPrefix ? stripModelNamespace(options.model) : options.model;
|
|
4289
|
+
if (config.modelTransform) model = config.modelTransform(model);
|
|
4290
|
+
args.push(config.modelFlag, model);
|
|
4291
|
+
}
|
|
4292
|
+
if (defaultArgsPosition === "afterPrompt") {
|
|
4293
|
+
args.push(...config.defaultArgs);
|
|
4294
|
+
}
|
|
4295
|
+
if (mcpArgsPosition === "afterCommand") {
|
|
4296
|
+
args.push(...mcpArgs);
|
|
4297
|
+
}
|
|
4298
|
+
const mode = resolveModeConfig(config.modes[options.mode ?? "yolo"]);
|
|
4299
|
+
args.push(...mode.args);
|
|
4300
|
+
if (options.args && options.args.length > 0) {
|
|
4301
|
+
args.push(...options.args);
|
|
4302
|
+
}
|
|
4303
|
+
return { args, env: mode.env };
|
|
4304
|
+
}
|
|
4305
|
+
function buildSpawnArgs(agentId, options) {
|
|
4306
|
+
const { binaryName, spawnConfig } = resolveCliConfig(agentId);
|
|
4307
|
+
const stdinMode = options.useStdin && spawnConfig.stdinMode ? spawnConfig.stdinMode : void 0;
|
|
4308
|
+
const result = buildCliArgs(spawnConfig, options, stdinMode);
|
|
4309
|
+
return { binaryName, args: result.args, env: result.env };
|
|
4310
|
+
}
|
|
4311
|
+
|
|
4312
|
+
// packages/design-system/src/tokens/colors.ts
|
|
4313
|
+
import chalk from "chalk";
|
|
4314
|
+
var dark = {
|
|
4315
|
+
header: (text4) => chalk.magentaBright.bold(text4),
|
|
4316
|
+
divider: (text4) => chalk.dim(text4),
|
|
4317
|
+
prompt: (text4) => chalk.cyan(text4),
|
|
4318
|
+
number: (text4) => chalk.cyanBright(text4),
|
|
4319
|
+
intro: (text4) => chalk.bgMagenta.white(` Poe - ${text4} `),
|
|
4320
|
+
resolvedSymbol: chalk.magenta("\u25C7"),
|
|
4321
|
+
errorSymbol: chalk.red("\u25A0"),
|
|
4322
|
+
accent: (text4) => chalk.cyan(text4),
|
|
4323
|
+
muted: (text4) => chalk.dim(text4),
|
|
4324
|
+
success: (text4) => chalk.green(text4),
|
|
4325
|
+
warning: (text4) => chalk.yellow(text4),
|
|
4326
|
+
error: (text4) => chalk.red(text4),
|
|
4327
|
+
info: (text4) => chalk.magenta(text4),
|
|
4328
|
+
badge: (text4) => chalk.bgYellow.black(` ${text4} `)
|
|
4329
|
+
};
|
|
4330
|
+
var light = {
|
|
4331
|
+
header: (text4) => chalk.hex("#a200ff").bold(text4),
|
|
4332
|
+
divider: (text4) => chalk.hex("#666666")(text4),
|
|
4333
|
+
prompt: (text4) => chalk.hex("#006699").bold(text4),
|
|
4334
|
+
number: (text4) => chalk.hex("#0077cc").bold(text4),
|
|
4335
|
+
intro: (text4) => chalk.bgHex("#a200ff").white(` Poe - ${text4} `),
|
|
4336
|
+
resolvedSymbol: chalk.hex("#a200ff")("\u25C7"),
|
|
4337
|
+
errorSymbol: chalk.hex("#cc0000")("\u25A0"),
|
|
4338
|
+
accent: (text4) => chalk.hex("#006699").bold(text4),
|
|
4339
|
+
muted: (text4) => chalk.hex("#666666")(text4),
|
|
4340
|
+
success: (text4) => chalk.hex("#008800")(text4),
|
|
4341
|
+
warning: (text4) => chalk.hex("#cc6600")(text4),
|
|
4342
|
+
error: (text4) => chalk.hex("#cc0000")(text4),
|
|
4343
|
+
info: (text4) => chalk.hex("#a200ff")(text4),
|
|
4344
|
+
badge: (text4) => chalk.bgHex("#cc6600").white(` ${text4} `)
|
|
4345
|
+
};
|
|
4346
|
+
|
|
4347
|
+
// packages/design-system/src/tokens/typography.ts
|
|
4348
|
+
import chalk2 from "chalk";
|
|
4349
|
+
|
|
4350
|
+
// packages/design-system/src/components/text.ts
|
|
4351
|
+
import chalk3 from "chalk";
|
|
4352
|
+
|
|
4353
|
+
// packages/design-system/src/internal/output-format.ts
|
|
4354
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4355
|
+
var VALID_FORMATS = /* @__PURE__ */ new Set(["terminal", "markdown", "json"]);
|
|
4356
|
+
var formatStorage = new AsyncLocalStorage();
|
|
4357
|
+
var cached;
|
|
4358
|
+
function resolveOutputFormat(env = process.env) {
|
|
4359
|
+
const scoped = formatStorage.getStore();
|
|
4360
|
+
if (scoped) {
|
|
4361
|
+
return scoped;
|
|
4362
|
+
}
|
|
4363
|
+
if (cached) {
|
|
4364
|
+
return cached;
|
|
4365
|
+
}
|
|
4366
|
+
const raw = env.OUTPUT_FORMAT?.toLowerCase();
|
|
4367
|
+
cached = VALID_FORMATS.has(raw) ? raw : "terminal";
|
|
4368
|
+
return cached;
|
|
4369
|
+
}
|
|
4370
|
+
|
|
4371
|
+
// packages/design-system/src/internal/theme-detect.ts
|
|
4372
|
+
function detectThemeFromEnv(env) {
|
|
4373
|
+
const apple = env.APPLE_INTERFACE_STYLE;
|
|
4374
|
+
if (typeof apple === "string") {
|
|
4375
|
+
return apple.toLowerCase() === "dark" ? "dark" : "light";
|
|
4376
|
+
}
|
|
4377
|
+
const vscodeKind = env.VSCODE_COLOR_THEME_KIND;
|
|
4378
|
+
if (typeof vscodeKind === "string") {
|
|
4379
|
+
const normalized = vscodeKind.toLowerCase();
|
|
4380
|
+
if (normalized.includes("light")) {
|
|
4381
|
+
return "light";
|
|
4382
|
+
}
|
|
4383
|
+
if (normalized.includes("dark")) {
|
|
4384
|
+
return "dark";
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4387
|
+
const colorFGBG = env.COLORFGBG;
|
|
4388
|
+
if (typeof colorFGBG === "string") {
|
|
4389
|
+
const parts = colorFGBG.split(";").map((part) => Number.parseInt(part, 10));
|
|
4390
|
+
const background = parts.at(-1);
|
|
4391
|
+
if (Number.isFinite(background)) {
|
|
4392
|
+
return background >= 8 ? "light" : "dark";
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
return void 0;
|
|
4396
|
+
}
|
|
4397
|
+
function resolveThemeName(env = process.env) {
|
|
4398
|
+
const raw = (env.POE_CODE_THEME ?? env.POE_THEME)?.toLowerCase();
|
|
4399
|
+
if (raw === "light" || raw === "dark") {
|
|
4400
|
+
return raw;
|
|
4401
|
+
}
|
|
4402
|
+
const detected = detectThemeFromEnv(env);
|
|
4403
|
+
if (detected) {
|
|
4404
|
+
return detected;
|
|
4405
|
+
}
|
|
4406
|
+
return "dark";
|
|
4407
|
+
}
|
|
4408
|
+
var cachedTheme;
|
|
4409
|
+
function getTheme(env) {
|
|
4410
|
+
if (cachedTheme) {
|
|
4411
|
+
return cachedTheme;
|
|
4412
|
+
}
|
|
4413
|
+
const themeName = resolveThemeName(env);
|
|
4414
|
+
cachedTheme = themeName === "light" ? light : dark;
|
|
4415
|
+
return cachedTheme;
|
|
4416
|
+
}
|
|
4417
|
+
|
|
4418
|
+
// packages/design-system/src/components/symbols.ts
|
|
4419
|
+
import chalk4 from "chalk";
|
|
4420
|
+
var symbols = {
|
|
4421
|
+
get info() {
|
|
4422
|
+
const format = resolveOutputFormat();
|
|
4423
|
+
if (format === "json") return "info";
|
|
4424
|
+
if (format === "markdown") return "(i)";
|
|
4425
|
+
return chalk4.magenta("\u25CF");
|
|
4426
|
+
},
|
|
4427
|
+
get success() {
|
|
4428
|
+
const format = resolveOutputFormat();
|
|
4429
|
+
if (format === "json") return "success";
|
|
4430
|
+
if (format === "markdown") return "[ok]";
|
|
4431
|
+
return chalk4.magenta("\u25C6");
|
|
4432
|
+
},
|
|
4433
|
+
get resolved() {
|
|
4434
|
+
const format = resolveOutputFormat();
|
|
4435
|
+
if (format === "json") return "resolved";
|
|
4436
|
+
if (format === "markdown") return ">";
|
|
4437
|
+
return getTheme().resolvedSymbol;
|
|
4438
|
+
},
|
|
4439
|
+
get errorResolved() {
|
|
4440
|
+
const format = resolveOutputFormat();
|
|
4441
|
+
if (format === "json") return "error";
|
|
4442
|
+
if (format === "markdown") return "[!]";
|
|
4443
|
+
return getTheme().errorSymbol;
|
|
4444
|
+
},
|
|
4445
|
+
get bar() {
|
|
4446
|
+
const format = resolveOutputFormat();
|
|
4447
|
+
if (format === "json") return "";
|
|
4448
|
+
if (format === "markdown") return "|";
|
|
4449
|
+
return "\u2502";
|
|
4450
|
+
},
|
|
4451
|
+
cornerTopRight: "\u256E",
|
|
4452
|
+
cornerBottomRight: "\u256F",
|
|
4453
|
+
get warning() {
|
|
4454
|
+
const format = resolveOutputFormat();
|
|
4455
|
+
if (format === "json") return "warning";
|
|
4456
|
+
if (format === "markdown") return "[!]";
|
|
4457
|
+
return "\u25B2";
|
|
4458
|
+
},
|
|
4459
|
+
get active() {
|
|
4460
|
+
const format = resolveOutputFormat();
|
|
4461
|
+
if (format === "json") return "active";
|
|
4462
|
+
if (format === "markdown") return "[x]";
|
|
4463
|
+
return "\u25C6";
|
|
4464
|
+
},
|
|
4465
|
+
get inactive() {
|
|
4466
|
+
const format = resolveOutputFormat();
|
|
4467
|
+
if (format === "json") return "inactive";
|
|
4468
|
+
if (format === "markdown") return "[ ]";
|
|
4469
|
+
return "\u25CB";
|
|
4470
|
+
}
|
|
4471
|
+
};
|
|
4472
|
+
|
|
4473
|
+
// packages/design-system/src/components/logger.ts
|
|
4474
|
+
import chalk6 from "chalk";
|
|
4475
|
+
|
|
4476
|
+
// packages/design-system/src/prompts/primitives/log.ts
|
|
4477
|
+
import chalk5 from "chalk";
|
|
4478
|
+
|
|
4479
|
+
// packages/design-system/src/internal/strip-ansi.ts
|
|
4480
|
+
function stripAnsi(value) {
|
|
4481
|
+
return value.replace(/\u001b\[[0-9;]*m/g, "");
|
|
4482
|
+
}
|
|
4483
|
+
|
|
4484
|
+
// packages/design-system/src/prompts/primitives/log.ts
|
|
4485
|
+
function writeTerminalMessage(msg, {
|
|
4486
|
+
symbol = chalk5.gray("\u2502"),
|
|
4487
|
+
secondarySymbol = chalk5.gray("\u2502"),
|
|
4488
|
+
spacing: spacing2 = 1,
|
|
4489
|
+
withGuide = true
|
|
4490
|
+
} = {}) {
|
|
4491
|
+
const lines = [];
|
|
4492
|
+
const showGuide = withGuide !== false;
|
|
4493
|
+
const contentLines = msg.split("\n");
|
|
4494
|
+
const prefix = showGuide ? `${symbol} ` : "";
|
|
4495
|
+
const continuationPrefix = showGuide ? `${secondarySymbol} ` : "";
|
|
4496
|
+
const emptyGuide = showGuide ? secondarySymbol : "";
|
|
4497
|
+
for (let index = 0; index < spacing2; index += 1) {
|
|
4498
|
+
lines.push(emptyGuide);
|
|
4499
|
+
}
|
|
4500
|
+
if (contentLines.length === 0) {
|
|
4501
|
+
process.stdout.write("\n");
|
|
4502
|
+
return;
|
|
4503
|
+
}
|
|
4504
|
+
const [firstLine = "", ...continuationLines] = contentLines;
|
|
4505
|
+
if (firstLine.length > 0) {
|
|
4506
|
+
lines.push(`${prefix}${firstLine}`);
|
|
4507
|
+
} else {
|
|
4508
|
+
lines.push(showGuide ? symbol : "");
|
|
4509
|
+
}
|
|
4510
|
+
for (const line of continuationLines) {
|
|
4511
|
+
if (line.length > 0) {
|
|
4512
|
+
lines.push(`${continuationPrefix}${line}`);
|
|
4513
|
+
continue;
|
|
4514
|
+
}
|
|
4515
|
+
lines.push(emptyGuide);
|
|
4516
|
+
}
|
|
4517
|
+
process.stdout.write(`${lines.join("\n")}
|
|
4518
|
+
`);
|
|
4519
|
+
}
|
|
4520
|
+
function message(msg, options) {
|
|
4521
|
+
const format = resolveOutputFormat();
|
|
4522
|
+
if (format === "markdown") {
|
|
4523
|
+
process.stdout.write(`- ${stripAnsi(msg)}
|
|
4524
|
+
`);
|
|
4525
|
+
return;
|
|
4526
|
+
}
|
|
4527
|
+
if (format === "json") {
|
|
4528
|
+
process.stdout.write(
|
|
4529
|
+
`${JSON.stringify({ level: "message", message: stripAnsi(msg) })}
|
|
4530
|
+
`
|
|
4531
|
+
);
|
|
4532
|
+
return;
|
|
4533
|
+
}
|
|
4534
|
+
writeTerminalMessage(msg, options);
|
|
4535
|
+
}
|
|
4536
|
+
function info(msg) {
|
|
4537
|
+
const format = resolveOutputFormat();
|
|
4538
|
+
if (format === "markdown") {
|
|
4539
|
+
process.stdout.write(`- **info:** ${stripAnsi(msg)}
|
|
4540
|
+
`);
|
|
4541
|
+
return;
|
|
4542
|
+
}
|
|
4543
|
+
if (format === "json") {
|
|
4544
|
+
process.stdout.write(
|
|
4545
|
+
`${JSON.stringify({ level: "info", message: stripAnsi(msg) })}
|
|
4546
|
+
`
|
|
4547
|
+
);
|
|
4548
|
+
return;
|
|
4549
|
+
}
|
|
4550
|
+
message(msg, { symbol: symbols.info });
|
|
4551
|
+
}
|
|
4552
|
+
function success(msg) {
|
|
4553
|
+
const format = resolveOutputFormat();
|
|
4554
|
+
if (format === "markdown") {
|
|
4555
|
+
process.stdout.write(`- **success:** ${stripAnsi(msg)}
|
|
4556
|
+
`);
|
|
4557
|
+
return;
|
|
4558
|
+
}
|
|
4559
|
+
if (format === "json") {
|
|
4560
|
+
process.stdout.write(
|
|
4561
|
+
`${JSON.stringify({ level: "success", message: stripAnsi(msg) })}
|
|
4562
|
+
`
|
|
4563
|
+
);
|
|
4564
|
+
return;
|
|
4565
|
+
}
|
|
4566
|
+
message(msg, { symbol: symbols.success });
|
|
4567
|
+
}
|
|
4568
|
+
function warn(msg) {
|
|
4569
|
+
const format = resolveOutputFormat();
|
|
4570
|
+
if (format === "markdown") {
|
|
4571
|
+
process.stdout.write(`- **warning:** ${stripAnsi(msg)}
|
|
4572
|
+
`);
|
|
4573
|
+
return;
|
|
4574
|
+
}
|
|
4575
|
+
if (format === "json") {
|
|
4576
|
+
process.stdout.write(
|
|
4577
|
+
`${JSON.stringify({ level: "warn", message: stripAnsi(msg) })}
|
|
4578
|
+
`
|
|
4579
|
+
);
|
|
4580
|
+
return;
|
|
4581
|
+
}
|
|
4582
|
+
message(msg, { symbol: chalk5.yellow("\u25B2") });
|
|
4583
|
+
}
|
|
4584
|
+
function error(msg) {
|
|
4585
|
+
const format = resolveOutputFormat();
|
|
4586
|
+
if (format === "markdown") {
|
|
4587
|
+
process.stdout.write(`- **error:** ${stripAnsi(msg)}
|
|
4588
|
+
`);
|
|
4589
|
+
return;
|
|
4590
|
+
}
|
|
4591
|
+
if (format === "json") {
|
|
4592
|
+
process.stdout.write(
|
|
4593
|
+
`${JSON.stringify({ level: "error", message: stripAnsi(msg) })}
|
|
4594
|
+
`
|
|
4595
|
+
);
|
|
4596
|
+
return;
|
|
4597
|
+
}
|
|
4598
|
+
message(msg, { symbol: chalk5.red("\u25A0") });
|
|
4599
|
+
}
|
|
4600
|
+
var log = {
|
|
4601
|
+
info,
|
|
4602
|
+
success,
|
|
4603
|
+
message,
|
|
4604
|
+
warn,
|
|
4605
|
+
error
|
|
4606
|
+
};
|
|
4607
|
+
|
|
4608
|
+
// packages/design-system/src/components/logger.ts
|
|
4609
|
+
function createLogger(emitter) {
|
|
4610
|
+
const emit = (level, message2) => {
|
|
4611
|
+
if (emitter) {
|
|
4612
|
+
emitter(message2);
|
|
4613
|
+
return;
|
|
4614
|
+
}
|
|
4615
|
+
if (level === "success") {
|
|
4616
|
+
log.success(message2);
|
|
4617
|
+
return;
|
|
4618
|
+
}
|
|
4619
|
+
if (level === "warn") {
|
|
4620
|
+
log.warn(message2);
|
|
4621
|
+
return;
|
|
4622
|
+
}
|
|
4623
|
+
if (level === "error") {
|
|
4624
|
+
log.error(message2);
|
|
4625
|
+
return;
|
|
4626
|
+
}
|
|
4627
|
+
log.info(message2);
|
|
4628
|
+
};
|
|
4629
|
+
return {
|
|
4630
|
+
info(message2) {
|
|
4631
|
+
emit("info", message2);
|
|
4632
|
+
},
|
|
4633
|
+
success(message2) {
|
|
4634
|
+
emit("success", message2);
|
|
4635
|
+
},
|
|
4636
|
+
warn(message2) {
|
|
4637
|
+
emit("warn", message2);
|
|
4638
|
+
},
|
|
4639
|
+
error(message2) {
|
|
4640
|
+
emit("error", message2);
|
|
4641
|
+
},
|
|
4642
|
+
resolved(label, value) {
|
|
4643
|
+
if (emitter) {
|
|
4644
|
+
emitter(`${label}: ${value}`);
|
|
4645
|
+
return;
|
|
4646
|
+
}
|
|
4647
|
+
log.message(`${label}
|
|
4648
|
+
${value}`, { symbol: symbols.resolved });
|
|
4649
|
+
},
|
|
4650
|
+
errorResolved(label, value) {
|
|
4651
|
+
if (emitter) {
|
|
4652
|
+
emitter(`${label}: ${value}`);
|
|
4653
|
+
return;
|
|
4654
|
+
}
|
|
4655
|
+
log.message(`${label}
|
|
4656
|
+
${value}`, { symbol: symbols.errorResolved });
|
|
4657
|
+
},
|
|
4658
|
+
message(message2, symbol) {
|
|
4659
|
+
if (emitter) {
|
|
4660
|
+
emitter(message2);
|
|
4661
|
+
return;
|
|
4662
|
+
}
|
|
4663
|
+
log.message(message2, { symbol: symbol ?? chalk6.gray("\u2502") });
|
|
4664
|
+
}
|
|
4665
|
+
};
|
|
4666
|
+
}
|
|
4667
|
+
var logger = createLogger();
|
|
4668
|
+
|
|
4669
|
+
// packages/design-system/src/components/table.ts
|
|
4670
|
+
import { Table } from "console-table-printer";
|
|
4671
|
+
|
|
4672
|
+
// packages/design-system/src/acp/components.ts
|
|
4673
|
+
import chalk7 from "chalk";
|
|
4674
|
+
|
|
4675
|
+
// packages/design-system/src/acp/writer.ts
|
|
4676
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
4677
|
+
var storage = new AsyncLocalStorage2();
|
|
4678
|
+
|
|
4679
|
+
// packages/design-system/src/acp/components.ts
|
|
4680
|
+
var AGENT_PREFIX = `${chalk7.green.bold("\u2713")} agent: `;
|
|
4681
|
+
|
|
4682
|
+
// packages/design-system/src/dashboard/buffer.ts
|
|
4683
|
+
import chalk8 from "chalk";
|
|
4684
|
+
|
|
4685
|
+
// packages/design-system/src/dashboard/terminal.ts
|
|
4686
|
+
import readline from "node:readline";
|
|
4687
|
+
import { PassThrough as PassThrough2 } from "node:stream";
|
|
4688
|
+
|
|
4689
|
+
// packages/design-system/src/prompts/index.ts
|
|
4690
|
+
import chalk15 from "chalk";
|
|
4691
|
+
import * as clack from "@clack/prompts";
|
|
4692
|
+
|
|
4693
|
+
// packages/design-system/src/prompts/primitives/cancel.ts
|
|
4694
|
+
import chalk9 from "chalk";
|
|
4695
|
+
import { isCancel } from "@clack/prompts";
|
|
4696
|
+
|
|
4697
|
+
// packages/design-system/src/prompts/primitives/intro.ts
|
|
4698
|
+
import chalk10 from "chalk";
|
|
4699
|
+
|
|
4700
|
+
// packages/design-system/src/prompts/primitives/note.ts
|
|
4701
|
+
import chalk11 from "chalk";
|
|
4702
|
+
|
|
4703
|
+
// packages/design-system/src/prompts/primitives/outro.ts
|
|
4704
|
+
import chalk12 from "chalk";
|
|
4705
|
+
|
|
4706
|
+
// packages/design-system/src/prompts/primitives/spinner.ts
|
|
4707
|
+
import chalk14 from "chalk";
|
|
4708
|
+
|
|
4709
|
+
// packages/design-system/src/static/spinner.ts
|
|
4710
|
+
import chalk13 from "chalk";
|
|
4711
|
+
|
|
4712
|
+
// packages/design-system/src/static/menu.ts
|
|
4713
|
+
import chalk16 from "chalk";
|
|
4714
|
+
|
|
4715
|
+
// packages/agent-spawn/src/autonomous.ts
|
|
4716
|
+
var DEFAULT_ACTIVITY_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
4717
|
+
|
|
4718
|
+
// packages/agent-spawn/src/acp/replay.ts
|
|
4719
|
+
import path20 from "node:path";
|
|
4720
|
+
import { homedir as homedir2 } from "node:os";
|
|
4721
|
+
import { open as open2, readdir as readdir2 } from "node:fs/promises";
|
|
4722
|
+
import { createInterface } from "node:readline";
|
|
4723
|
+
|
|
4724
|
+
// packages/poe-acp-client/src/acp-client.ts
|
|
4725
|
+
import { isAbsolute } from "node:path";
|
|
4726
|
+
|
|
4727
|
+
// packages/poe-acp-client/src/acp-transport.ts
|
|
4728
|
+
import {
|
|
4729
|
+
spawn as spawnChildProcess3
|
|
4730
|
+
} from "node:child_process";
|
|
4731
|
+
|
|
4732
|
+
// packages/poe-acp-client/src/run-report.ts
|
|
4733
|
+
import * as fsPromises2 from "node:fs/promises";
|
|
4734
|
+
import { homedir } from "node:os";
|
|
4735
|
+
import { join } from "node:path";
|
|
4736
|
+
|
|
4737
|
+
// packages/agent-spawn/src/acp/middlewares/spawn-log.ts
|
|
4738
|
+
import path21 from "node:path";
|
|
4739
|
+
import { homedir as homedir3 } from "node:os";
|
|
4740
|
+
import { mkdir, open as open3 } from "node:fs/promises";
|
|
4741
|
+
|
|
4742
|
+
// src/utils/command-checks.ts
|
|
4743
|
+
function formatCommandRunnerResult(result) {
|
|
4744
|
+
const stdout = result.stdout.length > 0 ? result.stdout : "<empty>";
|
|
4745
|
+
const stderr = result.stderr.length > 0 ? result.stderr : "<empty>";
|
|
4746
|
+
return `stdout:
|
|
4747
|
+
${stdout}
|
|
4748
|
+
stderr:
|
|
4749
|
+
${stderr}`;
|
|
4750
|
+
}
|
|
4751
|
+
function createSpawnHealthCheck(agentId, options) {
|
|
4752
|
+
const prompt = `Output exactly: ${options.expectedOutput}`;
|
|
4753
|
+
const { binaryName, args, env: modeEnv } = buildSpawnArgs(agentId, {
|
|
4754
|
+
prompt,
|
|
4755
|
+
model: options.model,
|
|
4756
|
+
mode: "yolo"
|
|
4757
|
+
});
|
|
4758
|
+
return {
|
|
4759
|
+
id: `${agentId}-cli-health`,
|
|
4760
|
+
description: `spawn ${agentId} (expecting "${options.expectedOutput}")`,
|
|
4761
|
+
async run(context) {
|
|
4762
|
+
if (context.isDryRun) {
|
|
4763
|
+
context.logDryRun?.(
|
|
4764
|
+
`Dry run: ${[binaryName, ...args].join(" ")} (expecting "${options.expectedOutput}")`
|
|
4765
|
+
);
|
|
4766
|
+
return;
|
|
4767
|
+
}
|
|
4768
|
+
const result = modeEnv ? await context.runCommand(binaryName, args, { env: modeEnv }) : await context.runCommand(binaryName, args);
|
|
4769
|
+
if (result.exitCode !== 0) {
|
|
4770
|
+
throw new Error(
|
|
4771
|
+
`spawn ${agentId} failed with exit code ${result.exitCode}.
|
|
4772
|
+
${formatCommandRunnerResult(result)}`
|
|
4773
|
+
);
|
|
4774
|
+
}
|
|
4775
|
+
if (!result.stdout.includes(options.expectedOutput)) {
|
|
4776
|
+
throw new Error(
|
|
4777
|
+
`spawn ${agentId}: expected "${options.expectedOutput}" in stdout.
|
|
4778
|
+
${formatCommandRunnerResult(result)}`
|
|
4779
|
+
);
|
|
4780
|
+
}
|
|
4781
|
+
}
|
|
4782
|
+
};
|
|
4783
|
+
}
|
|
4784
|
+
function createBinaryExistsCheck(binaryName, id, description) {
|
|
4785
|
+
return {
|
|
4786
|
+
id,
|
|
4787
|
+
description,
|
|
4788
|
+
async run({ runCommand: runCommand2 }) {
|
|
4789
|
+
for (const detector of createBinaryExistsDetectors(binaryName)) {
|
|
4790
|
+
const result = await runCommand2(detector.command, detector.args);
|
|
4791
|
+
if (detector.validate(result)) {
|
|
4792
|
+
return;
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4795
|
+
throw new Error(`${binaryName} CLI binary not found on PATH.`);
|
|
4796
|
+
}
|
|
4797
|
+
};
|
|
4798
|
+
}
|
|
4799
|
+
|
|
2166
4800
|
// src/services/service-install.ts
|
|
2167
4801
|
async function runServiceInstall(definition, context) {
|
|
2168
4802
|
const checkContext = {
|