@kybernesis/create 0.13.0 → 0.13.1
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/doctor.js +21 -0
- package/dist/upgrade.js +65 -1
- package/package.json +1 -1
package/dist/doctor.js
CHANGED
|
@@ -275,6 +275,27 @@ export async function doctor() {
|
|
|
275
275
|
else {
|
|
276
276
|
add("fail", `self-hosted: ${shortQueueTimeouts.join(" and ")} left at the 30s default`, "one queue delivery holds a connection open for the entire turn, so any turn slower than the timeout is redelivered and its steps re-run — the agent answers the same question twice, with two different answers, and nothing reports an error. Set both to 900000 in .env.local and restart the server");
|
|
277
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Disk, on a host whose runtime does not clean up after itself.
|
|
280
|
+
*
|
|
281
|
+
* eve builds a sandbox template per session configuration and keeps every
|
|
282
|
+
* one, and leaves session containers running long after their turn ended.
|
|
283
|
+
* The result is gigabytes a day on a working agent, and the failure it
|
|
284
|
+
* eventually produces looks like anything except a full disk.
|
|
285
|
+
*/
|
|
286
|
+
if (capture("sh", ["-c", "command -v docker >/dev/null && echo yes"])?.trim() === "yes") {
|
|
287
|
+
const job = capture("sh", ["-c", "test -x /etc/cron.daily/kyb-docker-prune && echo yes"])?.trim();
|
|
288
|
+
const percent = Number(capture("sh", ["-c", "df / | awk 'NR==2{print $5}' | tr -d '%'"])?.trim() ?? 0);
|
|
289
|
+
if (job !== "yes") {
|
|
290
|
+
add("warn", "no daily docker reclaim on this host", "sandbox images and abandoned session containers accumulate by the gigabyte; `kyb upgrade` installs /etc/cron.daily/kyb-docker-prune");
|
|
291
|
+
}
|
|
292
|
+
else if (percent >= 80) {
|
|
293
|
+
add("fail", `disk ${percent}% full despite the reclaim job`, "run it now: sudo /etc/cron.daily/kyb-docker-prune, and check what else is on this host");
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
add("pass", `daily docker reclaim installed (disk ${percent}% used)`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
278
299
|
/**
|
|
279
300
|
* Instructions that name a tool the agent does not have.
|
|
280
301
|
*
|
package/dist/upgrade.js
CHANGED
|
@@ -179,14 +179,63 @@ function repairBuzzSetup(cwd, deps) {
|
|
|
179
179
|
console.log(` ${dim("Takes effect after the next build and restart.")}\n`);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Keep the agent host from filling up with what the runtime leaves behind.
|
|
184
|
+
*
|
|
185
|
+
* @remarks
|
|
186
|
+
* eve builds a sandbox template image per session configuration and never
|
|
187
|
+
* collects the old ones, and it leaves session CONTAINERS running — a turn that
|
|
188
|
+
* took four minutes can still own a container, and its writable layer, eight
|
|
189
|
+
* days later. Forty stale images accumulated on one agent in a week; another
|
|
190
|
+
* reached 94% full and began failing in ways that looked like anything but a
|
|
191
|
+
* disk problem. Every self-hosted agent hits this; it is a property of the
|
|
192
|
+
* runtime, not of any one deployment.
|
|
193
|
+
*
|
|
194
|
+
* Installed rather than documented, and DAILY rather than weekly, because the
|
|
195
|
+
* accumulation is measured in gigabytes per day on an agent doing real work.
|
|
196
|
+
* The first version of this ran weekly and was already too slow.
|
|
197
|
+
*/
|
|
198
|
+
function repairDockerPrune(cwd, deps) {
|
|
199
|
+
if (!deps["@kybernesis/exe"])
|
|
200
|
+
return;
|
|
201
|
+
if (capture("sh", ["-c", "command -v docker >/dev/null && echo yes"])?.trim() !== "yes")
|
|
202
|
+
return;
|
|
203
|
+
const installed = capture("sh", ["-c", "test -x /etc/cron.daily/kyb-docker-prune && echo yes"]);
|
|
204
|
+
if (installed?.trim() === "yes")
|
|
205
|
+
return;
|
|
206
|
+
const source = join(cwd, "node_modules/@kybernesis/exe/scripts/docker-prune.sh");
|
|
207
|
+
if (!existsSync(source))
|
|
208
|
+
return;
|
|
209
|
+
// `sudo -n`: this runs inside an upgrade, and an upgrade that stops to ask
|
|
210
|
+
// for a password in the middle of an unattended run is worse than one that
|
|
211
|
+
// says what it could not do.
|
|
212
|
+
const ok = run("sh", [
|
|
213
|
+
"-c",
|
|
214
|
+
// The weekly predecessor is removed in the same breath: two jobs pruning
|
|
215
|
+
// the same host is not twice as safe, it is one more thing to reason
|
|
216
|
+
// about when something unexpected disappears.
|
|
217
|
+
`sudo -n cp ${JSON.stringify(source)} /etc/cron.daily/kyb-docker-prune && ` +
|
|
218
|
+
`sudo -n chmod 755 /etc/cron.daily/kyb-docker-prune && ` +
|
|
219
|
+
`sudo -n rm -f /etc/cron.weekly/docker-prune`,
|
|
220
|
+
], { cwd, allowFail: true, quiet: true });
|
|
221
|
+
if (ok) {
|
|
222
|
+
console.log(` ${green("+")} installed the daily docker reclaim (/etc/cron.daily/kyb-docker-prune)`);
|
|
223
|
+
console.log(` ${dim("eve leaves sandbox images and running session containers behind; this collects them.")}\n`);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
console.log(` ${yellow("!")} could not install the docker reclaim job (needs sudo). Without it this host ` +
|
|
227
|
+
`fills with stale sandbox images. Run:\n` +
|
|
228
|
+
` ${dim("sudo cp node_modules/@kybernesis/exe/scripts/docker-prune.sh /etc/cron.daily/kyb-docker-prune && sudo chmod 755 /etc/cron.daily/kyb-docker-prune")}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
182
231
|
export async function upgrade(skipEval) {
|
|
183
232
|
const cwd = process.cwd();
|
|
184
233
|
const pkg = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
|
|
185
234
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
186
235
|
console.log(bold("\nkyb upgrade — checking @kybernesis/* and eve against npm\n"));
|
|
187
236
|
warnIfStale();
|
|
237
|
+
// Env-only, so it is safe before anything is installed.
|
|
188
238
|
repairLocalQueueTimeouts(cwd, deps);
|
|
189
|
-
repairBuzzSetup(cwd, deps);
|
|
190
239
|
const toUpgrade = [];
|
|
191
240
|
const unresolved = [];
|
|
192
241
|
for (const name of kybernesisPackages(deps)) {
|
|
@@ -241,10 +290,25 @@ export async function upgrade(skipEval) {
|
|
|
241
290
|
}
|
|
242
291
|
if (toUpgrade.length === 0) {
|
|
243
292
|
console.log(`\n${green("Everything is at latest certified versions.")}\n`);
|
|
293
|
+
// Still repair: being on the right versions is not the same as being set
|
|
294
|
+
// up. An agent can sit at latest for weeks with a capability switched off.
|
|
295
|
+
repairBuzzSetup(cwd, deps);
|
|
296
|
+
repairDockerPrune(cwd, deps);
|
|
244
297
|
return;
|
|
245
298
|
}
|
|
246
299
|
console.log(bold(`\nInstalling: ${toUpgrade.join(", ")}\n`));
|
|
247
300
|
run("npm", ["install", ...toUpgrade], { cwd });
|
|
301
|
+
/**
|
|
302
|
+
* Repairs run AFTER the install, not before.
|
|
303
|
+
*
|
|
304
|
+
* Both of these copy files out of packages that the install has just put
|
|
305
|
+
* there — a proxy script, a cron job, a CLI. Running them first meant looking
|
|
306
|
+
* for a file the older installed version did not ship: the repair found
|
|
307
|
+
* nothing, said nothing, and only worked on the NEXT upgrade. Which is a
|
|
308
|
+
* bug that hides itself, because by then it looks like it always worked.
|
|
309
|
+
*/
|
|
310
|
+
repairBuzzSetup(cwd, deps);
|
|
311
|
+
repairDockerPrune(cwd, deps);
|
|
248
312
|
run("npm", ["run", "typecheck"], { cwd });
|
|
249
313
|
if (eveChanged) {
|
|
250
314
|
// A framework bump must also pass discovery/compile, not just types.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kybernesis/create",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "The Kybernesis agent scaffolder and FDE toolkit: one command to a governed, remembering, multiplayer, self-testing eve agent — plus doctor and upgrade.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|