@usecontextlayer/ctxe 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +54 -14
- package/dist/cli.mjs.map +1 -1
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="59a42f57-145c-5f77-afb2-f1f76467783d")}catch(e){}}();
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import * as Sentry from "@sentry/node";
|
|
6
6
|
import * as xi from "node:fs";
|
|
@@ -59,7 +59,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
59
59
|
|
|
60
60
|
//#endregion
|
|
61
61
|
//#region package.json
|
|
62
|
-
var version$1 = "0.4.
|
|
62
|
+
var version$1 = "0.4.3";
|
|
63
63
|
|
|
64
64
|
//#endregion
|
|
65
65
|
//#region sentry.ts
|
|
@@ -29490,7 +29490,7 @@ function validate(raw, sourcePath) {
|
|
|
29490
29490
|
}
|
|
29491
29491
|
function applyDefaults(input) {
|
|
29492
29492
|
return {
|
|
29493
|
-
synthesizerImage: input.synthesizerImage ?? "ghcr.io/usecontextlayer/ctx-sandbox:0.4.
|
|
29493
|
+
synthesizerImage: input.synthesizerImage ?? "ghcr.io/usecontextlayer/ctx-sandbox:0.4.3",
|
|
29494
29494
|
...input.microsandbox !== void 0 ? { microsandbox: input.microsandbox } : {},
|
|
29495
29495
|
...input.oldestConsideredPoint !== void 0 ? { oldestConsideredPoint: input.oldestConsideredPoint } : {},
|
|
29496
29496
|
maxSliceSize: input.maxSliceSize ?? 864e5,
|
|
@@ -31152,6 +31152,44 @@ function latestRunByName(entries) {
|
|
|
31152
31152
|
for (const { record } of entries) if (!latest.has(record.synthesizer)) latest.set(record.synthesizer, record);
|
|
31153
31153
|
return latest;
|
|
31154
31154
|
}
|
|
31155
|
+
const GUEST_MEMORY_MIB = 2048;
|
|
31156
|
+
const EXEC_INACTIVITY_TIMEOUT_MS = 600 * 1e3;
|
|
31157
|
+
const EXEC_MAX_DURATION_MS = 7200 * 1e3;
|
|
31158
|
+
const DRAIN_TIMED_OUT = Symbol("drain-timed-out");
|
|
31159
|
+
async function drainExecStream(handle, options) {
|
|
31160
|
+
const startedAt = Date.now();
|
|
31161
|
+
let lastEventAt = startedAt;
|
|
31162
|
+
for (;;) {
|
|
31163
|
+
const ceilingDeadline = startedAt + options.maxDurationMs;
|
|
31164
|
+
const inactivityDeadline = lastEventAt + options.inactivityMs;
|
|
31165
|
+
const deadline = Math.min(ceilingDeadline, inactivityDeadline);
|
|
31166
|
+
let timer;
|
|
31167
|
+
const timedOut = new Promise((resolve) => {
|
|
31168
|
+
timer = setTimeout(() => resolve(DRAIN_TIMED_OUT), Math.max(0, deadline - Date.now()));
|
|
31169
|
+
});
|
|
31170
|
+
const pending = handle.recv();
|
|
31171
|
+
let settled;
|
|
31172
|
+
try {
|
|
31173
|
+
settled = await Promise.race([pending, timedOut]);
|
|
31174
|
+
} finally {
|
|
31175
|
+
clearTimeout(timer);
|
|
31176
|
+
}
|
|
31177
|
+
if (settled === DRAIN_TIMED_OUT) {
|
|
31178
|
+
pending.catch(() => {});
|
|
31179
|
+
return {
|
|
31180
|
+
kind: "timed_out",
|
|
31181
|
+
reason: ceilingDeadline <= inactivityDeadline ? "max_duration" : "inactivity"
|
|
31182
|
+
};
|
|
31183
|
+
}
|
|
31184
|
+
if (settled === null) return { kind: "ended" };
|
|
31185
|
+
lastEventAt = Date.now();
|
|
31186
|
+
if (settled.kind === "stderr") options.onStderr(settled.data);
|
|
31187
|
+
else if (settled.kind === "exited") return {
|
|
31188
|
+
exitCode: settled.code,
|
|
31189
|
+
kind: "exited"
|
|
31190
|
+
};
|
|
31191
|
+
}
|
|
31192
|
+
}
|
|
31155
31193
|
var MicrosandboxClaudeExecutor = class {
|
|
31156
31194
|
async run(input) {
|
|
31157
31195
|
const microsandbox = await import("microsandbox");
|
|
@@ -31174,25 +31212,27 @@ var MicrosandboxClaudeExecutor = class {
|
|
|
31174
31212
|
synthesizerBody: input.synthesizerBody
|
|
31175
31213
|
});
|
|
31176
31214
|
await ensureHostFilesystemReady(fsPlan);
|
|
31177
|
-
let builder = microsandbox.Sandbox.builder(runPlan.sandboxName).image(runPlan.image).replace();
|
|
31215
|
+
let builder = microsandbox.Sandbox.builder(runPlan.sandboxName).image(runPlan.image).memory(GUEST_MEMORY_MIB).replace();
|
|
31178
31216
|
builder = applyUserMicrosandboxConfig(builder, runPlan.microsandboxConfig, stderrParts);
|
|
31179
31217
|
builder = applySandboxFilesystemPlan(builder, fsPlan);
|
|
31180
31218
|
sandbox = await builder.create();
|
|
31181
31219
|
const [cmd, ...args] = runPlan.command;
|
|
31182
31220
|
const stderrDecoder = new TextDecoder("utf-8", { fatal: false });
|
|
31183
31221
|
try {
|
|
31184
|
-
const
|
|
31185
|
-
|
|
31186
|
-
|
|
31222
|
+
const drained = await drainExecStream(await sandbox.execStreamWith(cmd, (e) => e.args(args)), {
|
|
31223
|
+
inactivityMs: EXEC_INACTIVITY_TIMEOUT_MS,
|
|
31224
|
+
maxDurationMs: EXEC_MAX_DURATION_MS,
|
|
31225
|
+
onStderr: (data) => stderrParts.push(stderrDecoder.decode(data, { stream: true }))
|
|
31226
|
+
});
|
|
31187
31227
|
stderrParts.push(stderrDecoder.decode());
|
|
31188
|
-
|
|
31189
|
-
if (
|
|
31228
|
+
if (drained.kind === "exited") exitCode = drained.exitCode;
|
|
31229
|
+
else if (drained.kind === "timed_out") {
|
|
31190
31230
|
exitCode = 124;
|
|
31191
|
-
stderrParts.push(`exec timed out: ${
|
|
31192
|
-
} else {
|
|
31193
|
-
exitCode = 1;
|
|
31194
|
-
stderrParts.push(`exec failed: ${formatError(error)}`);
|
|
31231
|
+
stderrParts.push(drained.reason === "inactivity" ? `exec stream timed out: no events for ${EXEC_INACTIVITY_TIMEOUT_MS / 6e4} minutes; abandoning the run and tearing the sandbox down\n` : `exec stream timed out: run exceeded the ${EXEC_MAX_DURATION_MS / 6e4}-minute ceiling; abandoning the run and tearing the sandbox down\n`);
|
|
31195
31232
|
}
|
|
31233
|
+
} catch (error) {
|
|
31234
|
+
exitCode = 1;
|
|
31235
|
+
stderrParts.push(`exec failed: ${formatError(error)}`);
|
|
31196
31236
|
}
|
|
31197
31237
|
} catch (error) {
|
|
31198
31238
|
exitCode = 1;
|
|
@@ -31743,4 +31783,4 @@ runCli().catch((error) => {
|
|
|
31743
31783
|
//#endregion
|
|
31744
31784
|
export { createProgram, resolveRepoContext, resolveRuntimePaths, runCli };
|
|
31745
31785
|
//# sourceMappingURL=cli.mjs.map
|
|
31746
|
-
//# debugId=
|
|
31786
|
+
//# debugId=59a42f57-145c-5f77-afb2-f1f76467783d
|