@kitman-sh/cli 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-nb6h112w.js → chunk-0m8ktgmz.js} +360 -187
- package/dist/{chunk-awx0zevr.js → chunk-2a40hhfz.js} +4 -4
- package/dist/{chunk-ah59jrtr.js → chunk-2gz59jcx.js} +1 -1
- package/dist/{chunk-z0gqrc8c.js → chunk-337drcr7.js} +35 -184
- package/dist/{chunk-r3mjxsmn.js → chunk-3jxdtkwd.js} +20 -20
- package/dist/{chunk-q8e58p57.js → chunk-6387vj9z.js} +2 -2
- package/dist/{chunk-4qrb09w4.js → chunk-6hxtg6eb.js} +3 -3
- package/dist/{chunk-rnm5ybw4.js → chunk-89ygm64f.js} +4 -4
- package/dist/{chunk-4tzzmrz2.js → chunk-8p5csa63.js} +64 -64
- package/dist/{chunk-5hp8ams4.js → chunk-9da9b7ys.js} +19 -19
- package/dist/{chunk-6e6t0f8y.js → chunk-a230abnk.js} +2 -2
- package/dist/{chunk-af8kftyw.js → chunk-d64j8v9n.js} +7 -7
- package/dist/{chunk-x4d4t28n.js → chunk-djzfaqaq.js} +352 -29
- package/dist/{chunk-61dmxexa.js → chunk-ew07nt2d.js} +60 -102
- package/dist/{chunk-c8eg05nh.js → chunk-fr0qseam.js} +4 -4
- package/dist/{chunk-56gs4z53.js → chunk-g5b61tek.js} +5 -5
- package/dist/{chunk-er0e8d8v.js → chunk-gy7nygep.js} +60 -14
- package/dist/{chunk-1hgsf81a.js → chunk-haq904fk.js} +1 -1
- package/dist/{chunk-qqb6djs7.js → chunk-hwjp28rh.js} +2 -2
- package/dist/{chunk-acmyagwp.js → chunk-phx3zffc.js} +8 -8
- package/dist/{chunk-rbpn35g5.js → chunk-qvpkwnky.js} +1 -1
- package/dist/{chunk-3cneth9k.js → chunk-r90j80q5.js} +9 -9
- package/dist/{chunk-abyssa8p.js → chunk-swc0ctf2.js} +3 -3
- package/dist/{chunk-a0bjjbhg.js → chunk-w8hf2etp.js} +81 -49
- package/dist/{chunk-1an3xh3b.js → chunk-wkbsbxp8.js} +6 -6
- package/dist/{chunk-znhjs0t6.js → chunk-y7bth30s.js} +1 -1
- package/dist/index.js +4 -4
- package/package.json +1 -1
|
@@ -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,
|
|
@@ -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-
|
|
177
|
+
} from "./chunk-ew07nt2d.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-
|
|
265
|
+
} from "./chunk-0m8ktgmz.js";
|
|
264
266
|
import {
|
|
265
267
|
currentTimeMillis,
|
|
266
268
|
join,
|
|
@@ -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-
|
|
314
|
+
} from "./chunk-337drcr7.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-
|
|
327
|
-
import"./chunk-
|
|
330
|
+
} from "./chunk-2a40hhfz.js";
|
|
331
|
+
import"./chunk-swc0ctf2.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-
|
|
341
|
+
} from "./chunk-6387vj9z.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-
|
|
351
|
+
} from "./chunk-g5b61tek.js";
|
|
348
352
|
import {
|
|
349
353
|
uploadRunFile,
|
|
350
354
|
programLease,
|
|
351
355
|
rpcRunFiles,
|
|
352
356
|
programHostsEnv,
|
|
353
357
|
undeclaredHostsEnv
|
|
354
|
-
} from "./chunk-
|
|
355
|
-
import"./chunk-
|
|
358
|
+
} from "./chunk-phx3zffc.js";
|
|
359
|
+
import"./chunk-r90j80q5.js";
|
|
356
360
|
import {
|
|
357
361
|
nextInt
|
|
358
|
-
} from "./chunk-
|
|
359
|
-
import"./chunk-
|
|
362
|
+
} from "./chunk-y7bth30s.js";
|
|
363
|
+
import"./chunk-haq904fk.js";
|
|
360
364
|
import {
|
|
361
365
|
ChildProcessSpawner,
|
|
362
|
-
|
|
363
|
-
} from "./chunk-
|
|
364
|
-
import"./chunk-
|
|
366
|
+
make3
|
|
367
|
+
} from "./chunk-gy7nygep.js";
|
|
368
|
+
import"./chunk-3jxdtkwd.js";
|
|
365
369
|
import {
|
|
366
370
|
Id,
|
|
367
371
|
secretReference,
|
|
368
372
|
secretPlaceholder
|
|
369
|
-
} from "./chunk-
|
|
373
|
+
} from "./chunk-qvpkwnky.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
|
-
|
|
4168
|
-
|
|
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 };
|
|
@@ -6928,7 +7241,7 @@ var listenForSignals = (input) => gen(function* () {
|
|
|
6928
7241
|
const dropSettled = (runIds) => forEach(runIds, (runId) => ignore(input.checkouts.drop(runId)), { discard: true }).pipe(provideContext2(services), andThen2(clearCheckpoints), forkIn(scope), asVoid);
|
|
6929
7242
|
const held = yield* input.checkouts.held;
|
|
6930
7243
|
yield* dropSettled(held.length === 0 ? [] : yield* input.rpc.settledRuns(held));
|
|
6931
|
-
yield* input.rpc.listen(input.runnerReplicaId, (signal) => isUpdateAvailable(signal) ? input.update?.(signal.version) ?? void_3 : isRunSettled(signal) ? dropSettled([signal.runId]) : input.signals.push(signal));
|
|
7244
|
+
yield* input.rpc.listen(input.runnerReplicaId, (signal) => isUpdateAvailable(signal) ? input.update?.(signal.version, { now: signal.now === true }) ?? void_3 : isRunSettled(signal) ? dropSettled([signal.runId]) : input.signals.push(signal));
|
|
6932
7245
|
}).pipe(scoped, catch_((error) => logWarning("runner_signals_disconnected", error.message)), catchDefect((defect) => logError("runner_signals_failed", pretty(die2(defect)))), andThen2(sleep(input.reconnectAfter)), forever);
|
|
6933
7246
|
var pushWork = (worktree, branch, step, shared, env) => gen(function* () {
|
|
6934
7247
|
const git = (...args) => runCommand2("git", ["-C", worktree, ...args]);
|
|
@@ -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
|
|
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 =
|
|
7811
|
-
const upstream =
|
|
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(
|
|
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 },
|
|
@@ -8327,7 +8640,7 @@ var handshake = [
|
|
|
8327
8640
|
`).join("");
|
|
8328
8641
|
var kitmanMcpPreflight = (mcp) => gen(function* () {
|
|
8329
8642
|
const spawner = yield* ChildProcessSpawner;
|
|
8330
|
-
const server = yield* spawner.spawn(
|
|
8643
|
+
const server = yield* spawner.spawn(make3(mcp.command, [...mcp.args], {
|
|
8331
8644
|
extendEnv: true,
|
|
8332
8645
|
env: mcp.env,
|
|
8333
8646
|
stdin: { stream: make10(new TextEncoder().encode(handshake)), endOnDone: false },
|
|
@@ -8403,7 +8716,7 @@ 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(
|
|
8719
|
+
const handle = yield* spawner.spawn(make3(input.bun ?? process.execPath, [file], {
|
|
8407
8720
|
stdin: make10(new TextEncoder().encode(stdin)),
|
|
8408
8721
|
stdout: "inherit",
|
|
8409
8722
|
stderr: "inherit",
|
|
@@ -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
|
|
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(
|
|
8705
|
-
const upstream =
|
|
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,
|