@kitman-sh/cli 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/{chunk-a0bjjbhg.js → chunk-1zb8h7gv.js} +42 -29
  2. package/dist/{chunk-rbpn35g5.js → chunk-4qjfn1sa.js} +1 -1
  3. package/dist/{chunk-znhjs0t6.js → chunk-5kqt4bqp.js} +1 -1
  4. package/dist/{chunk-z0gqrc8c.js → chunk-8fyfsajs.js} +17 -17
  5. package/dist/{chunk-er0e8d8v.js → chunk-9nbqzdqp.js} +60 -14
  6. package/dist/{chunk-5hp8ams4.js → chunk-9tyv6211.js} +12 -12
  7. package/dist/{chunk-ah59jrtr.js → chunk-a9ncx2a8.js} +1 -1
  8. package/dist/{chunk-af8kftyw.js → chunk-ak1qrm4q.js} +7 -7
  9. package/dist/{chunk-6e6t0f8y.js → chunk-bnhb3cth.js} +2 -2
  10. package/dist/{chunk-c8eg05nh.js → chunk-gnq1ryhx.js} +4 -4
  11. package/dist/{chunk-61dmxexa.js → chunk-h2f26xbd.js} +28 -70
  12. package/dist/{chunk-awx0zevr.js → chunk-hgxhpj6m.js} +4 -4
  13. package/dist/{chunk-4tzzmrz2.js → chunk-jrwpte6y.js} +40 -40
  14. package/dist/{chunk-3cneth9k.js → chunk-mhx0tgm3.js} +7 -7
  15. package/dist/{chunk-r3mjxsmn.js → chunk-np5n54ky.js} +5 -5
  16. package/dist/{chunk-nb6h112w.js → chunk-nwbry6c8.js} +117 -116
  17. package/dist/{chunk-1an3xh3b.js → chunk-py3133q0.js} +6 -6
  18. package/dist/{chunk-x4d4t28n.js → chunk-racse7zf.js} +356 -33
  19. package/dist/{chunk-56gs4z53.js → chunk-s34am3kw.js} +7 -7
  20. package/dist/{chunk-4qrb09w4.js → chunk-samxkpbz.js} +3 -3
  21. package/dist/{chunk-acmyagwp.js → chunk-sgkgwzvb.js} +5 -5
  22. package/dist/{chunk-1hgsf81a.js → chunk-tsx0347c.js} +1 -1
  23. package/dist/{chunk-q8e58p57.js → chunk-vz38kngm.js} +2 -2
  24. package/dist/{chunk-qqb6djs7.js → chunk-x29m7k25.js} +2 -2
  25. package/dist/{chunk-abyssa8p.js → chunk-xkkyx7bn.js} +3 -3
  26. package/dist/{chunk-rnm5ybw4.js → chunk-yveqd8ye.js} +4 -4
  27. package/dist/index.js +4 -4
  28. package/package.json +1 -1
@@ -4,12 +4,12 @@ import {
4
4
  runnerRpcUrl2,
5
5
  makeRunnerRpcClient2,
6
6
  makeProgramRpcClient2
7
- } from "./chunk-3cneth9k.js";
8
- import"./chunk-r3mjxsmn.js";
9
- import"./chunk-nb6h112w.js";
10
- import"./chunk-rbpn35g5.js";
11
- import"./chunk-z0gqrc8c.js";
12
- import"./chunk-61dmxexa.js";
7
+ } from "./chunk-mhx0tgm3.js";
8
+ import"./chunk-np5n54ky.js";
9
+ import"./chunk-nwbry6c8.js";
10
+ import"./chunk-4qjfn1sa.js";
11
+ import"./chunk-8fyfsajs.js";
12
+ import"./chunk-h2f26xbd.js";
13
13
  export {
14
14
  makeProgramRpcClient2 as makeProgramRpcClient,
15
15
  makeRunnerRpcClient2 as makeRunnerRpcClient,
@@ -14,6 +14,7 @@ import {
14
14
  isSome,
15
15
  match,
16
16
  getOrElse,
17
+ fromUndefinedOr,
17
18
  getOrUndefined,
18
19
  liftThrowable,
19
20
  map4,
@@ -43,7 +44,7 @@ import {
43
44
  isFailure2,
44
45
  hasInterrupts,
45
46
  makeUnsafe5,
46
- make15,
47
+ make16,
47
48
  _await,
48
49
  fail5,
49
50
  isDoneUnsafe,
@@ -125,6 +126,7 @@ import {
125
126
  repeat,
126
127
  forkIn,
127
128
  forkScoped,
129
+ forkDetach,
128
130
  fnUntraced,
129
131
  logWarning,
130
132
  logError,
@@ -172,7 +174,7 @@ import {
172
174
  decodeJsonStringSync,
173
175
  encodeUnknownJsonStringSync,
174
176
  storable
175
- } from "./chunk-61dmxexa.js";
177
+ } from "./chunk-h2f26xbd.js";
176
178
  import {
177
179
  SecureRandom,
178
180
  layerWebCrypto,
@@ -260,7 +262,7 @@ import {
260
262
  checkServicesFile,
261
263
  checkServices,
262
264
  serviceChecks
263
- } from "./chunk-nb6h112w.js";
265
+ } from "./chunk-nwbry6c8.js";
264
266
  import {
265
267
  currentTimeMillis,
266
268
  join,
@@ -270,7 +272,7 @@ import {
270
272
  unbounded2,
271
273
  offer,
272
274
  makeUnsafe3,
273
- make10,
275
+ make11,
274
276
  fromQueue,
275
277
  fromPubSub,
276
278
  map2,
@@ -289,6 +291,8 @@ import {
289
291
  Path,
290
292
  embeddedFile,
291
293
  extractEmbeddedFile,
294
+ withDefault,
295
+ String2,
292
296
  optionalEnv,
293
297
  operatorConfigHome,
294
298
  tempDirectoryScoped,
@@ -307,7 +311,7 @@ import {
307
311
  writeSrtSettings2,
308
312
  srtStepArgv2,
309
313
  srtArgv2
310
- } from "./chunk-z0gqrc8c.js";
314
+ } from "./chunk-8fyfsajs.js";
311
315
  import {
312
316
  writeAgentEnvironmentConfigFile2,
313
317
  readManifestSkillPaths2,
@@ -323,8 +327,8 @@ import {
323
327
  applyAgentEnvironmentMaterialization2,
324
328
  isPathWithin2,
325
329
  skillIdentity2
326
- } from "./chunk-awx0zevr.js";
327
- import"./chunk-abyssa8p.js";
330
+ } from "./chunk-hgxhpj6m.js";
331
+ import"./chunk-xkkyx7bn.js";
328
332
  import {
329
333
  egressAllowed,
330
334
  writeSecretRegistry,
@@ -334,7 +338,7 @@ import {
334
338
  secretFilter2,
335
339
  opaqueTunnelRefusal2,
336
340
  isOpaqueConnectReason2
337
- } from "./chunk-q8e58p57.js";
341
+ } from "./chunk-vz38kngm.js";
338
342
  import {
339
343
  sliceBytes2,
340
344
  maxLineBytes2,
@@ -344,29 +348,29 @@ import {
344
348
  lookAtOpencode2,
345
349
  readOpencode2,
346
350
  databaseStamp2
347
- } from "./chunk-56gs4z53.js";
351
+ } from "./chunk-s34am3kw.js";
348
352
  import {
349
353
  uploadRunFile,
350
354
  programLease,
351
355
  rpcRunFiles,
352
356
  programHostsEnv,
353
357
  undeclaredHostsEnv
354
- } from "./chunk-acmyagwp.js";
355
- import"./chunk-3cneth9k.js";
358
+ } from "./chunk-sgkgwzvb.js";
359
+ import"./chunk-mhx0tgm3.js";
356
360
  import {
357
361
  nextInt
358
- } from "./chunk-znhjs0t6.js";
359
- import"./chunk-1hgsf81a.js";
362
+ } from "./chunk-5kqt4bqp.js";
363
+ import"./chunk-tsx0347c.js";
360
364
  import {
361
365
  ChildProcessSpawner,
362
- make2
363
- } from "./chunk-er0e8d8v.js";
364
- import"./chunk-r3mjxsmn.js";
366
+ make3
367
+ } from "./chunk-9nbqzdqp.js";
368
+ import"./chunk-np5n54ky.js";
365
369
  import {
366
370
  Id,
367
371
  secretReference,
368
372
  secretPlaceholder
369
- } from "./chunk-rbpn35g5.js";
373
+ } from "./chunk-4qjfn1sa.js";
370
374
 
371
375
  // packages/core/src/sync-kit.ts
372
376
  import { createHash } from "crypto";
@@ -3975,6 +3979,294 @@ var stepSecretRegistry = (directory, initial, references) => gen(function* () {
3975
3979
  };
3976
3980
  });
3977
3981
 
3982
+ // packages/agent-runtime/src/step-containers.ts
3983
+ import * as net from "net";
3984
+ var stepAttemptDockerLabel = (attemptId) => `kitman.step-attempt.${attemptId}`;
3985
+ var stepRunnerDockerLabel = (runnerId) => `kitman.step-runner.${runnerId}`;
3986
+ var handedOnDockerLabel = "kitman.handed-on";
3987
+ var createPath = /^\/(?:v[\d.]+\/)?(?:containers|networks|volumes)\/create(?:\?|$)/;
3988
+ var attachPath = /^\/(?:v[\d.]+\/)?containers\/[^/]+\/attach(?:\?|$)/;
3989
+ var execStartPath = /^\/(?:v[\d.]+\/)?exec\/[^/]+\/start(?:\?|$)/;
3990
+ var crlf = Buffer.from(`\r
3991
+ `);
3992
+ var headEnd = Buffer.from(`\r
3993
+ \r
3994
+ `);
3995
+ var maxHead = 1024 * 1024;
3996
+ var parseHead = (head) => {
3997
+ const [requestLine = "", ...lines] = head.split(`\r
3998
+ `);
3999
+ const [method = "", path = ""] = requestLine.split(" ");
4000
+ return { method, path, lines: [requestLine, ...lines] };
4001
+ };
4002
+ var header = (head, name) => head.lines.slice(1).flatMap((line) => {
4003
+ const at = line.indexOf(":");
4004
+ return at > 0 && line.slice(0, at).trim().toLowerCase() === name ? [line.slice(at + 1).trim()] : [];
4005
+ }).at(0);
4006
+ var decodeChunked = (data) => {
4007
+ const parts = [];
4008
+ let at = 0;
4009
+ for (;; ) {
4010
+ const lineEnd = data.indexOf(crlf, at);
4011
+ if (lineEnd < 0)
4012
+ return;
4013
+ const size = Number.parseInt(data.subarray(at, lineEnd).toString().split(";")[0] ?? "", 16);
4014
+ at = lineEnd + 2;
4015
+ if (size === 0 || Number.isNaN(size))
4016
+ break;
4017
+ if (data.length < at + size + 2)
4018
+ return;
4019
+ parts.push(data.subarray(at, at + size));
4020
+ at += size + 2;
4021
+ }
4022
+ for (;; ) {
4023
+ const lineEnd = data.indexOf(crlf, at);
4024
+ if (lineEnd < 0)
4025
+ return;
4026
+ const empty = lineEnd === at;
4027
+ at = lineEnd + 2;
4028
+ if (empty)
4029
+ break;
4030
+ }
4031
+ return { body: Buffer.concat(parts), consumed: at };
4032
+ };
4033
+ var CreateBody = fromJsonString(Record(String4, Unknown));
4034
+ var detached = (body) => match(decodeOption(CreateBody)(body.toString()), {
4035
+ onNone: () => false,
4036
+ onSome: (parsed) => parsed["Detach"] === true
4037
+ });
4038
+ var Labels = Record(String4, Unknown);
4039
+ var labelled = (body, labels) => {
4040
+ const parsed = decodeOption(CreateBody)(body.toString());
4041
+ if (isNone(parsed))
4042
+ return body;
4043
+ const current = getOrElse(decodeUnknownOption(Labels)(parsed.value["Labels"]), () => ({}));
4044
+ if (handedOnDockerLabel in current)
4045
+ return body;
4046
+ return Buffer.from(JSON.stringify({ ...parsed.value, Labels: { ...current, ...labels } }));
4047
+ };
4048
+ var labelDockerRequests = (labels, answer = () => {
4049
+ return;
4050
+ }) => {
4051
+ let pending = Buffer.alloc(0);
4052
+ let state = { kind: "head" };
4053
+ const take = (count) => {
4054
+ const taken = pending.subarray(0, count);
4055
+ pending = pending.subarray(count);
4056
+ return taken;
4057
+ };
4058
+ const step = (out) => {
4059
+ switch (state.kind) {
4060
+ case "raw": {
4061
+ if (pending.length === 0)
4062
+ return false;
4063
+ out.push(take(pending.length));
4064
+ return true;
4065
+ }
4066
+ case "head": {
4067
+ const end = pending.indexOf(headEnd);
4068
+ if (end < 0) {
4069
+ if (pending.length > maxHead)
4070
+ state = { kind: "raw" };
4071
+ return pending.length > maxHead;
4072
+ }
4073
+ const raw = take(end + 4);
4074
+ const head = parseHead(raw.subarray(0, end).toString("latin1"));
4075
+ const chunked = /chunked/i.test(header(head, "transfer-encoding") ?? "");
4076
+ const length = Number(header(head, "content-length") ?? 0);
4077
+ const held = head.method === "POST" && createPath.test(head.path) ? "create" : head.method === "POST" && execStartPath.test(head.path) ? "exec" : undefined;
4078
+ if (header(head, "upgrade") !== undefined || attachPath.test(head.path)) {
4079
+ out.push(raw);
4080
+ state = { kind: "raw" };
4081
+ } else if (held !== undefined) {
4082
+ const continues = /100-continue/i.test(header(head, "expect") ?? "");
4083
+ if (continues)
4084
+ answer(Buffer.from(`HTTP/1.1 100 Continue\r
4085
+ \r
4086
+ `, "latin1"));
4087
+ state = {
4088
+ kind: held,
4089
+ head: continues ? { ...head, lines: head.lines.filter((line) => !/^expect\s*:/i.test(line)) } : head,
4090
+ length: chunked ? "chunked" : length
4091
+ };
4092
+ } else {
4093
+ out.push(raw);
4094
+ state = chunked ? { kind: "chunk-size" } : length > 0 ? { kind: "fixed", remaining: length } : { kind: "head" };
4095
+ }
4096
+ return true;
4097
+ }
4098
+ case "fixed":
4099
+ case "chunk-data": {
4100
+ if (pending.length === 0)
4101
+ return false;
4102
+ const taken = take(Math.min(state.remaining, pending.length));
4103
+ out.push(taken);
4104
+ state.remaining -= taken.length;
4105
+ if (state.remaining === 0)
4106
+ state = state.kind === "fixed" ? { kind: "head" } : { kind: "chunk-size" };
4107
+ return true;
4108
+ }
4109
+ case "chunk-size":
4110
+ case "trailer": {
4111
+ const end = pending.indexOf(crlf);
4112
+ if (end < 0)
4113
+ return false;
4114
+ const line = take(end + 2);
4115
+ out.push(line);
4116
+ if (state.kind === "trailer") {
4117
+ if (end === 0)
4118
+ state = { kind: "head" };
4119
+ } else {
4120
+ const size = Number.parseInt(line.toString("latin1").split(";")[0] ?? "", 16);
4121
+ state = size > 0 ? { kind: "chunk-data", remaining: size + 2 } : { kind: "trailer" };
4122
+ }
4123
+ return true;
4124
+ }
4125
+ case "create":
4126
+ case "exec": {
4127
+ const { kind, head, length } = state;
4128
+ const decoded = length === "chunked" ? decodeChunked(pending) : pending.length >= length ? { body: pending.subarray(0, length), consumed: length } : undefined;
4129
+ if (decoded === undefined)
4130
+ return false;
4131
+ take(decoded.consumed);
4132
+ const body = kind === "create" ? labelled(decoded.body, labels) : decoded.body;
4133
+ const lines = head.lines.filter((line, index) => index === 0 || !/^(content-length|transfer-encoding)\s*:/i.test(line));
4134
+ out.push(Buffer.from([...lines, `Content-Length: ${body.length}`, "", ""].join(`\r
4135
+ `), "latin1"), body);
4136
+ state = kind === "exec" && !detached(body) ? { kind: "raw" } : { kind: "head" };
4137
+ return true;
4138
+ }
4139
+ }
4140
+ };
4141
+ return {
4142
+ push: (chunk) => {
4143
+ pending = Buffer.concat([pending, chunk]);
4144
+ const out = [];
4145
+ while (step(out))
4146
+ ;
4147
+ return out;
4148
+ }
4149
+ };
4150
+ };
4151
+ var serveStepDocker = (input) => acquireRelease(callback3((resume) => {
4152
+ const open = new Set;
4153
+ const server = net.createServer({ allowHalfOpen: true }, (client) => {
4154
+ const upstream = net.connect({ path: input.upstream, allowHalfOpen: true });
4155
+ const labeller = labelDockerRequests(input.labels, (reply) => client.write(reply));
4156
+ for (const connection of [client, upstream]) {
4157
+ open.add(connection);
4158
+ connection.on("close", () => open.delete(connection));
4159
+ }
4160
+ client.on("data", (data) => {
4161
+ const writes = labeller.push(Buffer.from(data)).map((chunk) => upstream.write(chunk));
4162
+ if (writes.includes(false))
4163
+ client.pause();
4164
+ });
4165
+ upstream.on("drain", () => client.resume());
4166
+ client.on("end", () => upstream.end());
4167
+ upstream.pipe(client);
4168
+ client.on("error", () => upstream.destroy());
4169
+ upstream.on("error", () => client.destroy());
4170
+ });
4171
+ server.once("error", (error) => resume(fail7(error)));
4172
+ server.listen(input.socket, () => resume(succeed6({ server, open })));
4173
+ }), ({ server, open }) => callback3((resume) => {
4174
+ server.close(() => resume(void_3));
4175
+ open.forEach((connection) => connection.destroy());
4176
+ })).pipe(as(input.socket));
4177
+ var unixPath = (host) => host.startsWith("unix://") ? host.slice("unix://".length) : undefined;
4178
+ var dockerSocket = (spawner) => gen(function* () {
4179
+ const configured = yield* String2("DOCKER_HOST").pipe(withDefault(""), orElseSucceed(() => ""));
4180
+ if (configured !== "")
4181
+ return unixPath(configured);
4182
+ const host = yield* runCommand2("docker", ["context", "inspect", "--format", "{{.Endpoints.docker.Host}}"], {
4183
+ timeout: "10 seconds"
4184
+ }).pipe(provideService(ChildProcessSpawner, spawner), option2);
4185
+ return getOrUndefined(flatMap(host, (value) => fromUndefinedOr(unixPath(value.trim()))));
4186
+ });
4187
+ var dockerStepContainers = gen(function* () {
4188
+ const fs = yield* FileSystem;
4189
+ const spawner = yield* ChildProcessSpawner;
4190
+ const upstream = yield* dockerSocket(spawner);
4191
+ if (upstream === undefined)
4192
+ return;
4193
+ const docker = (args) => runCommand2("docker", args, { timeout: "2 minutes" }).pipe(provideService(ChildProcessSpawner, spawner));
4194
+ const ids = (listing) => listing.split(`
4195
+ `).map((line) => line.trim()).filter((line) => line !== "");
4196
+ const removeAll = (kind, label) => gen(function* () {
4197
+ const found = ids(yield* docker([kind, "ls", "--all", "--quiet", "--filter", `label=${label}`].filter((arg) => kind === "container" || arg !== "--all")));
4198
+ if (found.length === 0)
4199
+ return true;
4200
+ yield* docker(kind === "container" ? ["container", "rm", "--force", "--volumes", ...found] : [kind, "rm", ...found]);
4201
+ yield* logInfo("step_docker_removed", { of: label, kind, count: found.length });
4202
+ return true;
4203
+ }).pipe(catch_((error) => as(logWarning("step_docker_unremoved", { of: label, kind, error: error.message }), false)));
4204
+ return {
4205
+ environment: (runnerId, attemptId) => gen(function* () {
4206
+ const dir = yield* tempDirectoryScoped(fs, { prefix: "kitman-docker-" });
4207
+ const socket = yield* serveStepDocker({
4208
+ upstream,
4209
+ socket: `${dir}/docker.sock`,
4210
+ labels: { [stepAttemptDockerLabel(attemptId)]: "", [stepRunnerDockerLabel(runnerId)]: "" }
4211
+ });
4212
+ return { DOCKER_HOST: `unix://${socket}` };
4213
+ }).pipe(catch_((error) => as(logWarning("step_docker_unlabelled", { attempt: attemptId, error: String(error) }), {}))),
4214
+ remove: (label) => map9(all3([removeAll("container", label), removeAll("network", label), removeAll("volume", label)], {
4215
+ concurrency: 1
4216
+ }), (removed) => removed.every(Boolean))
4217
+ };
4218
+ });
4219
+ var dockerRootDirectory = runCommand2("docker", ["info", "--format", "{{.DockerRootDir}}"], {
4220
+ timeout: "10 seconds"
4221
+ }).pipe(map9((directory) => directory.trim() || undefined), orElseSucceed(() => {
4222
+ return;
4223
+ }));
4224
+ var gib = 1024 ** 3;
4225
+ var shown = (bytes) => `${(bytes / gib).toFixed(1)} GiB`;
4226
+ var diskSpaceProblem = (disks) => {
4227
+ const full = disks.filter((disk) => disk.available < Math.min(10 * gib, disk.size / 10));
4228
+ if (full.length === 0)
4229
+ return;
4230
+ const message = `The disk is nearly full, so checks and Steps may fail on it: ${full.map((disk) => `${shown(disk.available)} free of ${shown(disk.size)} where ${disk.paths.join(", ")} ${disk.paths.length === 1 ? "is" : "are"}`).join("; ")}.`;
4231
+ return {
4232
+ code: "disk_nearly_full",
4233
+ message: message.length <= 500 ? message : `${message.slice(0, 499)}\u2026`,
4234
+ fix: "Free space on the Runner's host, such as with `docker container prune`, `docker volume prune` and `docker image prune` for what nothing uses, or give it a larger disk."
4235
+ };
4236
+ };
4237
+ var diskSpaceFromDf = (listing, paths) => {
4238
+ const disks = new Map;
4239
+ listing.split(`
4240
+ `).slice(1).filter((line) => line.trim() !== "").forEach((line, index) => {
4241
+ const [, size, available, mountPoint] = /^.*?\s+(\d+)\s+\d+\s+(\d+)\s+\d+%\s+(.*)$/.exec(line.trim()) ?? [];
4242
+ const path = paths[index];
4243
+ if (path === undefined || size === undefined || available === undefined || mountPoint === undefined)
4244
+ return;
4245
+ const disk = disks.get(mountPoint);
4246
+ if (disk === undefined)
4247
+ disks.set(mountPoint, { paths: [path], available: Number(available) * 1024, size: Number(size) * 1024 });
4248
+ else
4249
+ disk.paths.push(path);
4250
+ });
4251
+ return [...disks.values()];
4252
+ };
4253
+ var diskSpaceMeter = gen(function* () {
4254
+ const fs = yield* FileSystem;
4255
+ const spawner = yield* ChildProcessSpawner;
4256
+ const measure = (path) => gen(function* () {
4257
+ if (!(yield* fs.exists(path)))
4258
+ return [];
4259
+ const listing = yield* runCommand2("df", ["-P", "-k", "--", path], { timeout: "10 seconds" }).pipe(provideService(ChildProcessSpawner, spawner));
4260
+ return listing.split(`
4261
+ `).filter((line) => line.trim() !== "").slice(1, 2).map((line) => ({ path, line }));
4262
+ }).pipe(orElseSucceed(() => []));
4263
+ return (paths) => map9(forEach(paths, measure, { concurrency: "unbounded" }), (measured) => {
4264
+ const found = measured.flat();
4265
+ return diskSpaceFromDf(["", ...found.map(({ line }) => line)].join(`
4266
+ `), found.map(({ path }) => path));
4267
+ });
4268
+ });
4269
+
3978
4270
  // packages/agent-runtime/src/step-processes.ts
3979
4271
  var stepAttemptVariable = "KITMAN_STEP_ATTEMPT";
3980
4272
  var stepRunnerVariable = "KITMAN_STEP_RUNNER";
@@ -4091,7 +4383,10 @@ var systemdScopes = gen(function* () {
4091
4383
  var reapRounds = 3;
4092
4384
  var problemText = (text) => text.length <= 500 ? text : `${text.slice(0, 499)}\u2026`;
4093
4385
  var makeStepProcesses = (table, options = {}) => {
4094
- const { scopes } = options;
4386
+ const { scopes, containers } = options;
4387
+ const unremoved = new Set;
4388
+ let removingAgain = false;
4389
+ const labelling = new Set;
4095
4390
  const unreaped = new Map;
4096
4391
  const pollMs = options.pollMs ?? 50;
4097
4392
  const finding = (marker, scoped) => map9(all3([table.marked(marker), scoped]), ([marked, inScopes]) => {
@@ -4139,7 +4434,20 @@ var makeStepProcesses = (table, options = {}) => {
4139
4434
  }
4140
4435
  return left;
4141
4436
  });
4437
+ const removeLabelled = (label) => containers === undefined ? void_3 : map9(containers.remove(label), (removed) => {
4438
+ if (removed)
4439
+ unremoved.delete(label);
4440
+ else
4441
+ unremoved.add(label);
4442
+ });
4443
+ const removeAgain = suspend3(() => {
4444
+ if (removingAgain || unremoved.size === 0)
4445
+ return void_3;
4446
+ removingAgain = true;
4447
+ return forEach([...unremoved], removeLabelled, { discard: true }).pipe(ensuring2(sync2(() => removingAgain = false)), forkDetach, asVoid);
4448
+ });
4142
4449
  const problems = gen(function* () {
4450
+ yield* removeAgain;
4143
4451
  for (const [key, entry] of unreaped) {
4144
4452
  entry.left = yield* running(yield* entry.find);
4145
4453
  if (entry.left.length === 0)
@@ -4164,8 +4472,12 @@ var makeStepProcesses = (table, options = {}) => {
4164
4472
  return {
4165
4473
  scoped: scopes !== undefined,
4166
4474
  contain: (runnerId, attemptId, argv) => scopes === undefined ? succeed6(argv) : scopes.contain(runnerId, attemptId, argv),
4167
- reapAttempt: (runnerId, attemptId) => reap(`attempt ${attemptId}`, finding({ name: stepAttemptVariable, value: attemptId }, scopes === undefined ? none : scopes.processes(runnerId, attemptId))),
4168
- reapRunner: (runnerId) => reap(`runner ${runnerId}`, finding({ name: stepRunnerVariable, value: runnerId }, scopes === undefined ? none : scopes.processes(runnerId))),
4475
+ dockerEnvironment: (runnerId, attemptId) => containers === undefined ? succeed6({}) : tap2(containers.environment(runnerId, attemptId), (environment) => sync2(() => {
4476
+ if (Object.keys(environment).length > 0)
4477
+ labelling.add(attemptId);
4478
+ })),
4479
+ reapAttempt: (runnerId, attemptId) => reap(`attempt ${attemptId}`, finding({ name: stepAttemptVariable, value: attemptId }, scopes === undefined ? none : scopes.processes(runnerId, attemptId))).pipe(tap2(() => labelling.delete(attemptId) ? removeLabelled(stepAttemptDockerLabel(attemptId)) : void_3)),
4480
+ reapRunner: (runnerId) => reap(`runner ${runnerId}`, finding({ name: stepRunnerVariable, value: runnerId }, scopes === undefined ? none : scopes.processes(runnerId))).pipe(tap2(() => removeLabelled(stepRunnerDockerLabel(runnerId)))),
4169
4481
  problems
4170
4482
  };
4171
4483
  };
@@ -4185,7 +4497,7 @@ class StepProcesses extends Service2()("StepProcesses") {
4185
4497
  var stepProcessesLayer = effect(StepProcesses, map9(systemProcessTable, (table) => makeStepProcesses(table)));
4186
4498
  var systemStepProcessesLayer = effect(StepProcesses, gen(function* () {
4187
4499
  const table = yield* systemProcessTable;
4188
- return makeStepProcesses(table, { scopes: yield* systemdScopes });
4500
+ return makeStepProcesses(table, { scopes: yield* systemdScopes, containers: yield* dockerStepContainers });
4189
4501
  }));
4190
4502
 
4191
4503
  // packages/agent-runtime/src/thread-budget.ts
@@ -4536,6 +4848,7 @@ var runAttempt = (request, options) => gen(function* () {
4536
4848
  const env = {
4537
4849
  ...yield* inheritedEnvironment2(["SSH_AUTH_SOCK"]),
4538
4850
  ...policy.environment,
4851
+ ...yield* options.stepProcesses.dockerEnvironment(request.runnerId, attempt.id),
4539
4852
  ...attemptEnvironment
4540
4853
  };
4541
4854
  return { argv: harnessArgv, env, registry: undefined };
@@ -7768,7 +8081,7 @@ var harnessesInSrt = (input) => gen(function* () {
7768
8081
  };
7769
8082
  });
7770
8083
  // packages/agent-runtime/src/loopback-tunnel.ts
7771
- import * as net from "net";
8084
+ import * as net2 from "net";
7772
8085
  class LoopbackTunnelUnavailable extends TaggedError("LoopbackTunnelUnavailable") {
7773
8086
  }
7774
8087
  var srtLoopbackTunnel = (tunnel) => [
@@ -7807,8 +8120,8 @@ var loopbackSocketForwarder = (hostPort, socket) => gen(function* () {
7807
8120
  const dir = yield* flatMap3(tempDirectoryScoped(fs, { prefix: "kitman-lo-" }), fs.realPath).pipe(mapError2((error) => new LoopbackTunnelUnavailable({ reason: error.message })));
7808
8121
  yield* acquireRelease(callback3((resume) => {
7809
8122
  const open = new Set;
7810
- const server = net.createServer({ allowHalfOpen: true }, (client) => {
7811
- const upstream = net.connect({ port: hostPort, host: "127.0.0.1", allowHalfOpen: true });
8123
+ const server = net2.createServer({ allowHalfOpen: true }, (client) => {
8124
+ const upstream = net2.connect({ port: hostPort, host: "127.0.0.1", allowHalfOpen: true });
7812
8125
  for (const connection of [client, upstream]) {
7813
8126
  open.add(connection);
7814
8127
  connection.on("close", () => open.delete(connection));
@@ -8164,7 +8477,7 @@ var codexAppServer = (binary = "codex") => (env) => gen(function* () {
8164
8477
  const input = yield* unbounded2();
8165
8478
  const pending = new Map;
8166
8479
  let lastId = 0;
8167
- const handle = yield* spawner.spawn(make2(binary, ["app-server"], {
8480
+ const handle = yield* spawner.spawn(make3(binary, ["app-server"], {
8168
8481
  cwd: env.home,
8169
8482
  extendEnv: true,
8170
8483
  env: { HOME: env.home, CODEX_HOME: env.codexHome },
@@ -8187,7 +8500,7 @@ var codexAppServer = (binary = "codex") => (env) => gen(function* () {
8187
8500
  return {
8188
8501
  request: (method, params) => gen(function* () {
8189
8502
  const id = ++lastId;
8190
- const deferred = yield* make15();
8503
+ const deferred = yield* make16();
8191
8504
  pending.set(id, deferred);
8192
8505
  yield* send({ id, method, params });
8193
8506
  return yield* _await(deferred).pipe(mapError2((error) => new CodexAppServerFailed({ reason: `${method}: ${error.message}` })));
@@ -8327,10 +8640,10 @@ var handshake = [
8327
8640
  `).join("");
8328
8641
  var kitmanMcpPreflight = (mcp) => gen(function* () {
8329
8642
  const spawner = yield* ChildProcessSpawner;
8330
- const server = yield* spawner.spawn(make2(mcp.command, [...mcp.args], {
8643
+ const server = yield* spawner.spawn(make3(mcp.command, [...mcp.args], {
8331
8644
  extendEnv: true,
8332
8645
  env: mcp.env,
8333
- stdin: { stream: make10(new TextEncoder().encode(handshake)), endOnDone: false },
8646
+ stdin: { stream: make11(new TextEncoder().encode(handshake)), endOnDone: false },
8334
8647
  stderr: "ignore"
8335
8648
  }));
8336
8649
  const reply = yield* server.stdout.pipe(decodeText, splitLines, map2((line) => getOrUndefined(decodeJsonStringOption(line))), filter((message) => isJsonObject(message) && message.id === 2), runHead);
@@ -8403,8 +8716,8 @@ var programProcessExecutor = (input) => (work) => gen(function* () {
8403
8716
  };
8404
8717
  const exitCode = sandbox === undefined ? yield* gen(function* () {
8405
8718
  const spawner = yield* ChildProcessSpawner;
8406
- const handle = yield* spawner.spawn(make2(input.bun ?? process.execPath, [file], {
8407
- stdin: make10(new TextEncoder().encode(stdin)),
8719
+ const handle = yield* spawner.spawn(make3(input.bun ?? process.execPath, [file], {
8720
+ stdin: make11(new TextEncoder().encode(stdin)),
8408
8721
  stdout: "inherit",
8409
8722
  stderr: "inherit",
8410
8723
  extendEnv: false,
@@ -8686,7 +8999,7 @@ var readCommitHistory = (checkout, spec, commitMax = compareCommitMax) => gen(fu
8686
8999
 
8687
9000
  // packages/agent-runtime/src/half-close-relay.ts
8688
9001
  import { once } from "events";
8689
- import { connect as connect2, createServer as createServer2 } from "net";
9002
+ import { connect as connect3, createServer as createServer3 } from "net";
8690
9003
  var frameHeader = 4;
8691
9004
  var endOfInput = Buffer.alloc(frameHeader);
8692
9005
  var maxFrame = 1024 * 1024;
@@ -8701,8 +9014,8 @@ var closeTogether = (...sockets) => sockets.forEach((socket) => {
8701
9014
  socket.on("close", () => sockets.forEach((other) => other.end()));
8702
9015
  });
8703
9016
  var listening = (server, port) => once(server.listen(port, "127.0.0.1"), "listening").then(() => server);
8704
- var startHalfCloseDecoder = (input) => listening(createServer2({ allowHalfOpen: true }, (client) => {
8705
- const upstream = connect2({ port: input.targetPort, host: "127.0.0.1", allowHalfOpen: true });
9017
+ var startHalfCloseDecoder = (input) => listening(createServer3({ allowHalfOpen: true }, (client) => {
9018
+ const upstream = connect3({ port: input.targetPort, host: "127.0.0.1", allowHalfOpen: true });
8706
9019
  let pending = Buffer.alloc(0);
8707
9020
  client.on("data", (chunk) => {
8708
9021
  pending = Buffer.concat([pending, chunk]);
@@ -9919,18 +10232,24 @@ export {
9919
10232
  controlFailureKind,
9920
10233
  defaultAgentRuntimeUserConfigPath,
9921
10234
  detectHarnesses2 as detectHarnesses,
10235
+ diskSpaceFromDf,
10236
+ diskSpaceMeter,
10237
+ diskSpaceProblem,
9922
10238
  dockerCheckDaemon,
9923
10239
  dockerCheckPostgres,
9924
10240
  dockerContainerRunner,
9925
10241
  dockerExecArgv,
9926
10242
  dockerHome,
9927
10243
  dockerMissing,
10244
+ dockerRootDirectory,
10245
+ dockerStepContainers,
9928
10246
  failed,
9929
10247
  failedWhenUnrun,
9930
10248
  firstMessage,
9931
10249
  gitCheckouts2 as gitCheckouts,
9932
10250
  gitRemote,
9933
10251
  halfCloseListener,
10252
+ handedOnDockerLabel,
9934
10253
  harnessAdapter,
9935
10254
  harnessConfigUnwritable,
9936
10255
  harnessNetworkHosts,
@@ -9956,6 +10275,7 @@ export {
9956
10275
  kitmanMcpPreflight,
9957
10276
  kitmanMcpToolTimeout,
9958
10277
  kitmanMcpToolTimeoutSeconds,
10278
+ labelDockerRequests,
9959
10279
  lacksLoginSecret,
9960
10280
  listBuiltInLaunchProfiles,
9961
10281
  listenForSignals,
@@ -10009,6 +10329,7 @@ export {
10009
10329
  runsOnHost,
10010
10330
  sampleMetrics,
10011
10331
  sandboxedLaunch,
10332
+ serveStepDocker,
10012
10333
  setDefaultAgentRuntimeProfile,
10013
10334
  sha256,
10014
10335
  shellOutputTailChars2 as shellOutputTailChars,
@@ -10021,11 +10342,13 @@ export {
10021
10342
  srtSettings2 as srtSettings,
10022
10343
  srtStepArgv2 as srtStepArgv,
10023
10344
  startDockerSandbox,
10345
+ stepAttemptDockerLabel,
10024
10346
  stepAttemptVariable,
10025
10347
  stepKitSetup,
10026
10348
  stepProcessEnvironment,
10027
10349
  stepProcessesLayer,
10028
10350
  stepProcessesUncontained,
10351
+ stepRunnerDockerLabel,
10029
10352
  stepRunnerVariable,
10030
10353
  stepSandboxPolicy,
10031
10354
  superviseReplica,
@@ -35,19 +35,19 @@ import {
35
35
  isJsonObject,
36
36
  isString2,
37
37
  encodeUnknownJsonStringSync
38
- } from "./chunk-61dmxexa.js";
38
+ } from "./chunk-h2f26xbd.js";
39
39
  import {
40
40
  currentTimeMillis,
41
- make10,
41
+ make11,
42
42
  runForEach,
43
43
  toPull,
44
44
  FileSystem,
45
45
  compiled2
46
- } from "./chunk-z0gqrc8c.js";
46
+ } from "./chunk-8fyfsajs.js";
47
47
  import {
48
48
  ChildProcessSpawner,
49
- make2
50
- } from "./chunk-er0e8d8v.js";
49
+ make3
50
+ } from "./chunk-9nbqzdqp.js";
51
51
 
52
52
  // packages/agent-runtime/src/opencode-store.ts
53
53
  import { lstatSync, readFileSync, realpathSync, writeSync } from "fs";
@@ -265,8 +265,8 @@ var opencodeReaderCommand = () => compiled2 ? [process.execPath, "opencode-read"
265
265
  var spawnReader = (request) => gen(function* () {
266
266
  const spawner = yield* ChildProcessSpawner;
267
267
  const [command, ...args] = opencodeReaderCommand();
268
- return yield* spawner.spawn(make2(command, args, {
269
- stdin: make10(new TextEncoder().encode(request)),
268
+ return yield* spawner.spawn(make3(command, args, {
269
+ stdin: make11(new TextEncoder().encode(request)),
270
270
  stderr: "ignore",
271
271
  extendEnv: false,
272
272
  env: {},
@@ -4,9 +4,9 @@ import {
4
4
  opaqueTunnelRefusal2,
5
5
  isOpaqueConnectReason2,
6
6
  runSrtStep2
7
- } from "./chunk-q8e58p57.js";
8
- import"./chunk-rbpn35g5.js";
9
- import"./chunk-61dmxexa.js";
7
+ } from "./chunk-vz38kngm.js";
8
+ import"./chunk-4qjfn1sa.js";
9
+ import"./chunk-h2f26xbd.js";
10
10
  export {
11
11
  isOpaqueConnectReason2 as isOpaqueConnectReason,
12
12
  opaqueTunnelRefusal2 as opaqueTunnelRefusal,