@slayzone/cli 0.42.0 → 0.44.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/slay.js +245 -19
- package/package.json +1 -1
package/dist/slay.js
CHANGED
|
@@ -49901,6 +49901,12 @@ async function waitForSession(sessionId, timeoutMs) {
|
|
|
49901
49901
|
// src/commands/chat.ts
|
|
49902
49902
|
var import_node_crypto5 = require("node:crypto");
|
|
49903
49903
|
var EXIT_PROMPT = 3;
|
|
49904
|
+
function deliverOption(prefix = "") {
|
|
49905
|
+
return new Option(
|
|
49906
|
+
"--deliver <how>",
|
|
49907
|
+
`${prefix}queue = after the running turn, steer = into it now (required mid-turn)`
|
|
49908
|
+
).choices(["queue", "steer"]);
|
|
49909
|
+
}
|
|
49904
49910
|
var enc = encodeURIComponent;
|
|
49905
49911
|
function withTargetOptions(cmd) {
|
|
49906
49912
|
return cmd.option("-t, --task <id>", "Task id or prefix (default: $SLAYZONE_TASK_ID)").option("--tab <id>", "Another chat tab of the task (default: the task's main tab)");
|
|
@@ -50004,7 +50010,9 @@ function chatCommand() {
|
|
|
50004
50010
|
}
|
|
50005
50011
|
for (const [k, v] of Object.entries(data)) if (v !== null) console.log(`${k.padEnd(16)} ${v}`);
|
|
50006
50012
|
});
|
|
50007
|
-
withTargetOptions(cmd.command("send [text]")).description(
|
|
50013
|
+
withTargetOptions(cmd.command("send [text]")).description(
|
|
50014
|
+
"Send a message. Mid-turn, --deliver is required: queue (after this turn) or steer (into it now)"
|
|
50015
|
+
).addOption(deliverOption()).option("--wait", "Wait until the agent answered it (or stops on a prompt)").option("--timeout <ms>", "Timeout for --wait in milliseconds", "600000").option("--json", "Output as JSON").action(
|
|
50008
50016
|
async (text, opts) => {
|
|
50009
50017
|
if (!text) text = await readStdin();
|
|
50010
50018
|
if (!text.trim()) {
|
|
@@ -50017,7 +50025,7 @@ function chatCommand() {
|
|
|
50017
50025
|
const { data } = await apiPost(await chatPath(opts, "send", {}, { tabInQuery: false }), {
|
|
50018
50026
|
text,
|
|
50019
50027
|
messageId,
|
|
50020
|
-
...opts.
|
|
50028
|
+
...opts.deliver ? { deliver: opts.deliver } : {},
|
|
50021
50029
|
...bodyTab(opts)
|
|
50022
50030
|
});
|
|
50023
50031
|
if (data.steered === false && !opts.json)
|
|
@@ -50332,7 +50340,9 @@ function agentCommand() {
|
|
|
50332
50340
|
if (opts.json) console.log(JSON.stringify(data, null, 2));
|
|
50333
50341
|
else console.log(data.started ? "started" : "already running");
|
|
50334
50342
|
});
|
|
50335
|
-
withTask(cmd.command("send [text]")).description(
|
|
50343
|
+
withTask(cmd.command("send [text]")).description(
|
|
50344
|
+
"Send a message (chat: --deliver queue|steer, required mid-turn; terminal: submitted), starting the agent if needed"
|
|
50345
|
+
).addOption(deliverOption("Chat: ")).option("--wait", "Then wait until the agent settles").option("--timeout <ms>", "Timeout for --wait in milliseconds", "600000").option("--json", "Output as JSON").action(
|
|
50336
50346
|
async (text, opts) => {
|
|
50337
50347
|
if (!text) text = await readStdin2();
|
|
50338
50348
|
if (!text.trim()) {
|
|
@@ -50342,7 +50352,7 @@ function agentCommand() {
|
|
|
50342
50352
|
if (opts.wait) refuseSelfWait(await resolveId(opts.task), void 0);
|
|
50343
50353
|
const { data } = await apiPost(
|
|
50344
50354
|
await agentPath(opts, "send"),
|
|
50345
|
-
{ text, ...opts.
|
|
50355
|
+
{ text, ...opts.deliver ? { deliver: opts.deliver } : {} }
|
|
50346
50356
|
);
|
|
50347
50357
|
if (!opts.wait) {
|
|
50348
50358
|
if (opts.json) console.log(JSON.stringify(data, null, 2));
|
|
@@ -50995,6 +51005,34 @@ var HUB_CONFIG_SWITCH_KEYS = [
|
|
|
50995
51005
|
"enableIntegrations",
|
|
50996
51006
|
"enableTelemetry"
|
|
50997
51007
|
];
|
|
51008
|
+
function readComputerAgentResources(value) {
|
|
51009
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
51010
|
+
const raw = value;
|
|
51011
|
+
const policy = {};
|
|
51012
|
+
const integer2 = (key, min, max) => {
|
|
51013
|
+
const value2 = raw[key];
|
|
51014
|
+
return typeof value2 === "number" && Number.isSafeInteger(value2) && value2 >= min && value2 <= max ? value2 : void 0;
|
|
51015
|
+
};
|
|
51016
|
+
const maxLiveAgents = raw.maxLiveAgents === "auto" ? "auto" : integer2("maxLiveAgents", 1, 1e4);
|
|
51017
|
+
const minAvailableMemoryPercent = integer2("minAvailableMemoryPercent", 1, 95);
|
|
51018
|
+
const idleBeforeHibernateMs = integer2("idleBeforeHibernateMs", 0, Number.MAX_SAFE_INTEGER);
|
|
51019
|
+
const warmPoolSize = integer2("warmPoolSize", 0, 1e4);
|
|
51020
|
+
const startConcurrency = integer2("startConcurrency", 1, 128);
|
|
51021
|
+
if (maxLiveAgents !== void 0) policy.maxLiveAgents = maxLiveAgents;
|
|
51022
|
+
if (typeof raw.hibernate === "boolean") policy.hibernate = raw.hibernate;
|
|
51023
|
+
if (minAvailableMemoryPercent !== void 0)
|
|
51024
|
+
policy.minAvailableMemoryPercent = minAvailableMemoryPercent;
|
|
51025
|
+
if (idleBeforeHibernateMs !== void 0) policy.idleBeforeHibernateMs = idleBeforeHibernateMs;
|
|
51026
|
+
if (warmPoolSize !== void 0) policy.warmPoolSize = warmPoolSize;
|
|
51027
|
+
if (startConcurrency !== void 0) policy.startConcurrency = startConcurrency;
|
|
51028
|
+
if (Array.isArray(raw.pinnedTaskIds))
|
|
51029
|
+
policy.pinnedTaskIds = [
|
|
51030
|
+
...new Set(
|
|
51031
|
+
raw.pinnedTaskIds.filter((id) => typeof id === "string" && id.length > 0)
|
|
51032
|
+
)
|
|
51033
|
+
];
|
|
51034
|
+
return policy;
|
|
51035
|
+
}
|
|
50998
51036
|
function getHubConfigFilePath() {
|
|
50999
51037
|
return (0, import_node_path13.join)(getSlayzoneHomeDir(), "hub.config.json");
|
|
51000
51038
|
}
|
|
@@ -51041,6 +51079,8 @@ function coerceComputerConfig(raw) {
|
|
|
51041
51079
|
}
|
|
51042
51080
|
if (typeof raw.directListenAddress === "string") cfg.directListenAddress = raw.directListenAddress;
|
|
51043
51081
|
if (typeof raw.directPublicAddress === "string") cfg.directPublicAddress = raw.directPublicAddress;
|
|
51082
|
+
const agentResources = readComputerAgentResources(raw.agentResources);
|
|
51083
|
+
if (agentResources) cfg.agentResources = agentResources;
|
|
51044
51084
|
return cfg;
|
|
51045
51085
|
}
|
|
51046
51086
|
function readJsonObject2(path17) {
|
|
@@ -51305,11 +51345,18 @@ ${envEntries}
|
|
|
51305
51345
|
</plist>
|
|
51306
51346
|
`;
|
|
51307
51347
|
}
|
|
51348
|
+
function systemdStopRecord(spec) {
|
|
51349
|
+
if (spec.kind === "hub") return "";
|
|
51350
|
+
const script = 'mkdir -p "$1" && printf "%%s [systemd] service stopped result=%%s exit=%%s status=%%s\\n" "$$(date -u +%%Y-%%m-%%dT%%H:%%M:%%SZ)" "$$SERVICE_RESULT" "$$EXIT_CODE" "$$EXIT_STATUS" >> "$1/computer.log"';
|
|
51351
|
+
return `ExecStopPost=-/bin/sh -c '${script}' sh "${(0, import_node_path14.join)(spec.root, "logs")}"
|
|
51352
|
+
`;
|
|
51353
|
+
}
|
|
51308
51354
|
function renderSystemdUnit(spec) {
|
|
51309
51355
|
assertValidServiceName(spec.kind, spec.name);
|
|
51310
51356
|
const kind = KINDS[spec.kind];
|
|
51311
51357
|
const exec = [spec.command, ...spec.args].join(" ");
|
|
51312
51358
|
const envLines = unitEnv(spec).map(([k, v]) => `Environment=${k}=${v}`).join("\n");
|
|
51359
|
+
const agentIsolation = spec.kind === "hub" ? "" : "\nDelegate=memory\nDelegateSubgroup=supervisor";
|
|
51313
51360
|
return `[Unit]
|
|
51314
51361
|
Description=${kind.description} (${spec.name})
|
|
51315
51362
|
Documentation=https://github.com/debuglebowski/slayzone
|
|
@@ -51322,7 +51369,11 @@ ${envLines}
|
|
|
51322
51369
|
ExecStart=${exec}
|
|
51323
51370
|
Restart=on-failure
|
|
51324
51371
|
RestartSec=2
|
|
51325
|
-
|
|
51372
|
+
OOMScoreAdjust=-750${agentIsolation}
|
|
51373
|
+
# A process the kernel OOM-kills (an agent's build, a headless browser) must not take
|
|
51374
|
+
# the whole service down with it: systemd's default (OOMPolicy=stop) did, twice a day.
|
|
51375
|
+
OOMPolicy=continue
|
|
51376
|
+
${systemdStopRecord(spec)}# stdout/stderr go to journald; read them with \`${kind.logsCommand} ${spec.name}\`.
|
|
51326
51377
|
StandardOutput=journal
|
|
51327
51378
|
StandardError=journal
|
|
51328
51379
|
|
|
@@ -51423,45 +51474,205 @@ function readUnitSecrets(kind, name, backend, unitDir = defaultUnitDir(backend))
|
|
|
51423
51474
|
// ../../shared/platform/src/computer-launcher.ts
|
|
51424
51475
|
var import_node_fs15 = require("node:fs");
|
|
51425
51476
|
var import_node_path15 = require("node:path");
|
|
51477
|
+
|
|
51478
|
+
// ../../shared/platform/src/computer-endpoints.ts
|
|
51479
|
+
var UNIX_SOCKET_PATH_MAX_BYTES = {
|
|
51480
|
+
darwin: 104,
|
|
51481
|
+
linux: 108
|
|
51482
|
+
};
|
|
51483
|
+
var HOST_SUPERSEDED_EXIT_CODE = 79;
|
|
51484
|
+
var ENDPOINT_IN_USE_LISTEN_ERRORS = ["EADDRINUSE", "EEXIST"];
|
|
51485
|
+
|
|
51486
|
+
// ../../shared/platform/src/computer-launcher.ts
|
|
51426
51487
|
var import_node_fs16 = require("node:fs");
|
|
51427
51488
|
var COMPUTER_LAUNCHER = String.raw`#!/usr/bin/env node
|
|
51428
51489
|
const fs = require('node:fs'), path = require('node:path'), cp = require('node:child_process');
|
|
51490
|
+
const net = require('node:net'), os = require('node:os'), crypto = require('node:crypto');
|
|
51429
51491
|
const root = process.env.SLAYZONE_ROOT;
|
|
51430
51492
|
if (!root) throw Error('computer launcher requires SLAYZONE_ROOT');
|
|
51431
51493
|
const role = process.argv.includes('--session-host') ? 'host' : 'supervisor';
|
|
51432
51494
|
const dir = path.join(root, 'computer-runtime'), pointer = path.join(dir, role === 'host' ? 'host-release.json' : 'supervisor.json');
|
|
51433
|
-
|
|
51495
|
+
// Restart delay after consecutive failures: 2s doubling to 60s, reset once a child is healthy.
|
|
51496
|
+
const BACKOFF_MIN_MS = 2000, BACKOFF_MAX_MS = 60000, LOG_MAX_BYTES = 5 * 1024 * 1024;
|
|
51497
|
+
// A session host that found another live host on its control endpoint (computer-endpoints.ts).
|
|
51498
|
+
const SUPERSEDED_EXIT = ${HOST_SUPERSEDED_EXIT_CODE};
|
|
51499
|
+
// This root's endpoints, derived exactly as computer-endpoints.ts derives them.
|
|
51500
|
+
const endpointKey = crypto.createHash('sha256').update(path.resolve(root)).digest('hex').slice(0, 24);
|
|
51501
|
+
const endpointDir = process.platform === 'win32' ? null : path.join(os.tmpdir(), 'slay-computer-' + (process.getuid ? process.getuid() : 'user') + '-' + endpointKey);
|
|
51502
|
+
const endpoints = endpointDir
|
|
51503
|
+
? {control: path.join(endpointDir, 'control.sock'), launcher: path.join(endpointDir, 'l.sock')}
|
|
51504
|
+
: {control: '\\\\.\\pipe\\slay-computer-' + endpointKey, launcher: '\\\\.\\pipe\\slay-computer-launcher-' + endpointKey};
|
|
51505
|
+
// Longest Unix socket path Node accepts (computer-endpoints.ts UNIX_SOCKET_PATH_MAX_BYTES):
|
|
51506
|
+
// a longer one fails listen/connect with a bare EINVAL, so it is refused by name first.
|
|
51507
|
+
const SOCKET_PATH_MAX = ${JSON.stringify(UNIX_SOCKET_PATH_MAX_BYTES)}[process.platform] || 104;
|
|
51508
|
+
// listen errors meaning the endpoint path is already held (computer-endpoints.ts
|
|
51509
|
+
// ENDPOINT_IN_USE_LISTEN_ERRORS): EADDRINUSE, or EEXIST when macOS sees another
|
|
51510
|
+
// launcher bind the same path at the same moment. Either way: probe, never bail.
|
|
51511
|
+
const IN_USE_LISTEN_ERRORS = ${JSON.stringify(ENDPOINT_IN_USE_LISTEN_ERRORS)};
|
|
51512
|
+
function socketPathError(p) {
|
|
51513
|
+
const bytes = Buffer.byteLength(p);
|
|
51514
|
+
return bytes <= SOCKET_PATH_MAX ? null : 'computer endpoint ' + p + ' is ' + bytes + ' bytes, over the ' + SOCKET_PATH_MAX + '-byte Unix socket path limit on ' + process.platform + '; point TMPDIR at a shorter directory';
|
|
51515
|
+
}
|
|
51516
|
+
if (process.argv.includes('--print-endpoints')) { process.stdout.write(JSON.stringify(endpoints) + '\n'); return; }
|
|
51517
|
+
let child, stopping = false, healthy = false, timer, probation, killTimer, failures = 0, nextTimer, lock;
|
|
51518
|
+
// What a waiting supervisor asks over the launcher endpoint (queryHostLauncher).
|
|
51519
|
+
const status = {state: 'starting', childPid: null, nextLaunchAt: null, lastExit: null};
|
|
51434
51520
|
function read() { return JSON.parse(fs.readFileSync(pointer, 'utf8')); }
|
|
51521
|
+
// Every start and exit of the child, timestamped, to stderr and to logs/computer.log
|
|
51522
|
+
// (shared by every computer process). Before, an exit left no trace at all here.
|
|
51523
|
+
function log(msg) {
|
|
51524
|
+
const line = new Date().toISOString() + ' [launcher ' + process.pid + '] ' + role + ' ' + msg + '\n';
|
|
51525
|
+
try { process.stderr.write(line); } catch {}
|
|
51526
|
+
try { const logs = path.join(root, 'logs'); fs.mkdirSync(logs, {recursive: true, mode: 0o700}); fs.appendFileSync(path.join(logs, 'computer.log'), line, {mode: 0o600}); } catch {}
|
|
51527
|
+
}
|
|
51528
|
+
// The session host's launcher writes, for its whole life, to the host.log it was started
|
|
51529
|
+
// with: rotated only when a host was spawned, it grew without bound (32 MB). Copy, then
|
|
51530
|
+
// truncate in place: every holder of the file appends, so all keep writing to its start.
|
|
51531
|
+
function rotateHostLog() {
|
|
51532
|
+
if (role !== 'host') return;
|
|
51533
|
+
try {
|
|
51534
|
+
const file = path.join(dir, 'host.log'), out = fs.fstatSync(1), st = fs.statSync(file);
|
|
51535
|
+
if (out.ino !== st.ino || out.dev !== st.dev || st.size <= LOG_MAX_BYTES) return;
|
|
51536
|
+
fs.copyFileSync(file, file + '.1'); fs.truncateSync(file, 0);
|
|
51537
|
+
} catch {}
|
|
51538
|
+
}
|
|
51539
|
+
setInterval(rotateHostLog, 600000).unref();
|
|
51540
|
+
// ── One session-host launcher per root ──────────────────────────────────────────
|
|
51541
|
+
// The launcher endpoint is held for this launcher's whole life: a second launcher for
|
|
51542
|
+
// the root finds it live and stops before starting any child. (Two once ran at once,
|
|
51543
|
+
// one restarting an EADDRINUSE-failing child forever, rolling back good releases.)
|
|
51544
|
+
function prepareEndpointDir() {
|
|
51545
|
+
if (!endpointDir) return;
|
|
51546
|
+
try { fs.mkdirSync(endpointDir, {mode: 0o700}); } catch (e) { if (e.code !== 'EEXIST') throw e; }
|
|
51547
|
+
const st = fs.lstatSync(endpointDir);
|
|
51548
|
+
if (st.isSymbolicLink() || !st.isDirectory() || (process.getuid && st.uid !== process.getuid()) || (st.mode & 0o077))
|
|
51549
|
+
throw Error('unsafe computer endpoint directory ' + endpointDir + ': must be a directory owned by this user with mode 0700');
|
|
51550
|
+
}
|
|
51551
|
+
// live / stale / absent as probeEndpoint (computer-endpoints.ts) tells them; any other
|
|
51552
|
+
// connect error says nothing about an owner and is passed on (cb(null, err)).
|
|
51553
|
+
function probe(cb) {
|
|
51554
|
+
const s = net.connect(endpoints.launcher); let done = false;
|
|
51555
|
+
const fin = (r, err) => { if (done) return; done = true; clearTimeout(t); s.destroy(); cb(r, err); };
|
|
51556
|
+
const t = setTimeout(() => fin('live'), 2000);
|
|
51557
|
+
s.once('connect', () => fin('live'));
|
|
51558
|
+
s.once('error', (e) => e.code === 'ENOENT' ? fin('absent') : e.code === 'ECONNREFUSED' ? fin('stale') : e.code === 'EAGAIN' ? fin('live') : fin(null, e));
|
|
51559
|
+
}
|
|
51560
|
+
function serveStatus(socket) {
|
|
51561
|
+
let buf = '';
|
|
51562
|
+
socket.setEncoding('utf8'); socket.on('error', () => {}); socket.setTimeout(2000, () => socket.destroy());
|
|
51563
|
+
socket.on('data', (chunk) => {
|
|
51564
|
+
buf += chunk; const end = buf.indexOf('\n');
|
|
51565
|
+
if (end < 0) { if (buf.length > 1024) socket.destroy(); return; }
|
|
51566
|
+
let command; try { command = JSON.parse(buf.slice(0, end)).command; } catch {}
|
|
51567
|
+
if (command === 'launch-now' && status.state === 'backoff' && !stopping) { clearTimeout(nextTimer); log('launching now, at a waiting supervisor\'s request'); launch(); }
|
|
51568
|
+
socket.end(JSON.stringify(status) + '\n');
|
|
51569
|
+
});
|
|
51570
|
+
}
|
|
51571
|
+
function bail(msg) { log(msg + '; stopping'); process.exit(1); }
|
|
51572
|
+
// Every bind of the launcher endpoint happens inside one short critical section (an
|
|
51573
|
+
// atomic mkdir of the guard). listen() on a Unix socket is bind() then listen(): in
|
|
51574
|
+
// between, the file exists but refuses connections, exactly like one whose launcher
|
|
51575
|
+
// died. With binds serialized, a refusing socket seen while holding the guard can only
|
|
51576
|
+
// be a dead launcher's, so replacing it is safe. (2026-11-27: under full CPU load a
|
|
51577
|
+
// launcher probed a winner preempted in that gap, "took over" its live endpoint, and
|
|
51578
|
+
// two launchers each ran a host.) Windows: named pipes are exclusive; no guard needed.
|
|
51579
|
+
// The guard keeps its old name so an older launcher.cjs still running excludes with it.
|
|
51580
|
+
const GUARD_STALE_MS = 10000;
|
|
51581
|
+
function acquire(then, attempt) {
|
|
51582
|
+
attempt = attempt || 0;
|
|
51583
|
+
if (attempt > 50) return bail('cannot take the launcher endpoint ' + endpoints.launcher);
|
|
51584
|
+
if (endpointDir) { const tooLong = socketPathError(endpoints.launcher) || socketPathError(endpoints.control); if (tooLong) return bail(tooLong); }
|
|
51585
|
+
try { prepareEndpointDir(); } catch (e) { return bail(e.message); }
|
|
51586
|
+
const retry = (ms) => setTimeout(() => acquire(then, attempt + 1), ms);
|
|
51587
|
+
const guard = endpointDir ? endpoints.launcher + '.takeover' : null;
|
|
51588
|
+
if (guard) {
|
|
51589
|
+
try { fs.mkdirSync(guard, {mode: 0o700}); } catch (e) {
|
|
51590
|
+
// ENOENT: a launcher exiting just removed the (empty) endpoint directory.
|
|
51591
|
+
if (e.code === 'ENOENT') return retry(0);
|
|
51592
|
+
if (e.code !== 'EEXIST') return bail('cannot take ' + guard + ': ' + e.message);
|
|
51593
|
+
// Held for a bind (milliseconds). Waiting on it is not a failed attempt: it ends
|
|
51594
|
+
// when the holder finishes, or GUARD_STALE_MS after a holder that died holding it.
|
|
51595
|
+
try { if (Date.now() - fs.statSync(guard).mtimeMs > GUARD_STALE_MS) fs.rmdirSync(guard); } catch {}
|
|
51596
|
+
return setTimeout(() => acquire(then, attempt), 25);
|
|
51597
|
+
}
|
|
51598
|
+
}
|
|
51599
|
+
const unguard = () => { if (guard) try { fs.rmdirSync(guard); } catch {} };
|
|
51600
|
+
const won = (server, how) => { unguard(); if (how) log(how); lock = server; then(); };
|
|
51601
|
+
const server = net.createServer(serveStatus);
|
|
51602
|
+
server.once('error', (err) => {
|
|
51603
|
+
if (!IN_USE_LISTEN_ERRORS.includes(err.code)) { unguard(); return bail('cannot bind ' + endpoints.launcher + ': ' + err.message); }
|
|
51604
|
+
probe((state, probeErr) => {
|
|
51605
|
+
if (probeErr) { unguard(); return bail('cannot probe ' + endpoints.launcher + ': ' + (probeErr.code || probeErr.message)); }
|
|
51606
|
+
if (state === 'live') { unguard(); log('launcher already running for this root; superseded, stopping'); process.exit(0); }
|
|
51607
|
+
if (state === 'absent' || !guard) { unguard(); return retry(50); }
|
|
51608
|
+
// Stale: its launcher died (no live one binds without the guard this one holds).
|
|
51609
|
+
try { fs.unlinkSync(endpoints.launcher); } catch {}
|
|
51610
|
+
const taken = net.createServer(serveStatus);
|
|
51611
|
+
taken.once('error', () => { unguard(); retry(0); });
|
|
51612
|
+
taken.listen(endpoints.launcher, () => won(taken, 'took over a launcher endpoint left by a dead launcher'));
|
|
51613
|
+
});
|
|
51614
|
+
});
|
|
51615
|
+
server.listen(endpoints.launcher, () => won(server));
|
|
51616
|
+
}
|
|
51617
|
+
// Ends this launcher: frees its endpoint (and the directory, once empty), then exits.
|
|
51618
|
+
function release(code) {
|
|
51619
|
+
status.state = 'stopping'; status.nextLaunchAt = null; clearTimeout(nextTimer);
|
|
51620
|
+
process.exitCode = code;
|
|
51621
|
+
if (!lock) return;
|
|
51622
|
+
lock.close(() => { if (endpointDir) try { fs.rmdirSync(endpointDir); } catch {} });
|
|
51623
|
+
lock = undefined;
|
|
51624
|
+
}
|
|
51435
51625
|
function launch() {
|
|
51436
51626
|
if (stopping) return;
|
|
51627
|
+
rotateHostLog();
|
|
51437
51628
|
const state = read(); let timedOut = false; healthy = false; probation = undefined;
|
|
51629
|
+
const startedAt = Date.now();
|
|
51438
51630
|
child = cp.fork(state.current.entry, [role === 'host' ? '--session-host' : '--supervisor'], {env: {...process.env, SLAYZONE_NONINTERACTIVE:'1'}, stdio:['inherit','inherit','inherit','ipc']});
|
|
51631
|
+
status.state = 'running'; status.childPid = child.pid; status.nextLaunchAt = null;
|
|
51632
|
+
log(state.current.version + ' started pid=' + child.pid + (failures ? ' (after ' + failures + ' consecutive failures)' : ''));
|
|
51439
51633
|
timer = setTimeout(() => {
|
|
51440
51634
|
timedOut = true;
|
|
51441
|
-
|
|
51635
|
+
log(state.current.version + ' startup timed out; restarting');
|
|
51442
51636
|
// A supervisor SIGTERM means explicit shutdown, including its persistent host.
|
|
51443
51637
|
// Crash only the supervisor; its connectors stop on IPC loss and work survives.
|
|
51444
51638
|
if (role === 'supervisor') child.kill('SIGKILL');
|
|
51445
51639
|
else { child.kill('SIGTERM'); killTimer = setTimeout(() => child.kill('SIGKILL'), 10000); }
|
|
51446
51640
|
}, 90000);
|
|
51447
|
-
child.on('message', m => { if (m && m.type === 'supervisor-ready') {clearTimeout(timer); if (!probation) probation = setTimeout(() => {healthy = true;}, 60000);} });
|
|
51448
|
-
child.on('error', () => {});
|
|
51449
|
-
child.on('exit', (code) => {
|
|
51641
|
+
child.on('message', m => { if (m && m.type === 'supervisor-ready') {clearTimeout(timer); if (!probation) probation = setTimeout(() => {healthy = true; failures = 0;}, 60000);} });
|
|
51642
|
+
child.on('error', (err) => { log(state.current.version + ' child error: ' + (err && err.message)); });
|
|
51643
|
+
child.on('exit', (code, signal) => {
|
|
51450
51644
|
clearTimeout(timer); clearTimeout(probation); clearTimeout(killTimer);
|
|
51451
|
-
|
|
51452
|
-
|
|
51645
|
+
const ended = state.current.version + ' pid=' + child.pid + ' exited code=' + code + ' signal=' + signal + ' after ' + (Date.now() - startedAt) + 'ms';
|
|
51646
|
+
status.childPid = null; status.lastExit = {version: state.current.version, code, signal, at: Date.now()};
|
|
51647
|
+
if (stopping) {log(ended + '; stopping'); release(code || 0); return;}
|
|
51648
|
+
// Another live host owns the endpoint: not a failure of this release (no
|
|
51649
|
+
// quarantine, no rollback), and nothing to restart. This launcher is redundant.
|
|
51650
|
+
if (role === 'host' && code === SUPERSEDED_EXIT && !timedOut) {log(ended + '; superseded by a live session host, stopping'); stopping = true; release(0); return;}
|
|
51651
|
+
if (code === 75 && !timedOut) {log(ended + '; relaunching (requested)'); launch(); return;}
|
|
51453
51652
|
const failed = timedOut || code !== 0;
|
|
51653
|
+
let rolledBack = '';
|
|
51454
51654
|
if (!healthy && failed && state.previous) {
|
|
51455
51655
|
fs.writeFileSync(path.join(dir, role + '-quarantine.json'), JSON.stringify({version: state.current.version, until: Date.now() + 900000}), {mode:0o600});
|
|
51456
51656
|
const temp = pointer + '.tmp';
|
|
51457
51657
|
fs.writeFileSync(temp, JSON.stringify({current:state.previous}) + '\n', {mode:0o600}); fs.renameSync(temp,pointer);
|
|
51658
|
+
rolledBack = '; quarantined, rolled back to ' + state.previous.version;
|
|
51458
51659
|
}
|
|
51459
|
-
if (!failed) return;
|
|
51460
|
-
|
|
51660
|
+
if (!failed) {log(ended + '; not restarting'); release(0); return;}
|
|
51661
|
+
failures += 1;
|
|
51662
|
+
const delay = Math.min(BACKOFF_MIN_MS * Math.pow(2, failures - 1), BACKOFF_MAX_MS);
|
|
51663
|
+
log(ended + rolledBack + '; restarting in ' + delay + 'ms (failure ' + failures + ')');
|
|
51664
|
+
status.state = 'backoff'; status.nextLaunchAt = Date.now() + delay;
|
|
51665
|
+
nextTimer = setTimeout(launch, delay);
|
|
51461
51666
|
});
|
|
51462
51667
|
}
|
|
51463
|
-
for (const signal of ['SIGINT','SIGTERM']) process.on(signal, () => {
|
|
51464
|
-
|
|
51668
|
+
for (const signal of ['SIGINT','SIGTERM']) process.on(signal, () => {
|
|
51669
|
+
stopping = true; log('received ' + signal + ', stopping');
|
|
51670
|
+
// No child up (backing off, or not started yet): nothing to wait for.
|
|
51671
|
+
if (child && child.exitCode === null && child.signalCode === null) child.kill(signal);
|
|
51672
|
+
else release(0);
|
|
51673
|
+
});
|
|
51674
|
+
if (role === 'host') acquire(() => (stopping ? release(0) : launch()));
|
|
51675
|
+
else launch();
|
|
51465
51676
|
`;
|
|
51466
51677
|
function ensureComputerLauncher(root, release, forceUpgrade = false) {
|
|
51467
51678
|
const dir = (0, import_node_path15.join)(root, "computer-runtime");
|
|
@@ -51505,7 +51716,7 @@ var import_node_child_process4 = require("node:child_process");
|
|
|
51505
51716
|
var import_node_fs17 = require("node:fs");
|
|
51506
51717
|
var import_node_module = require("node:module");
|
|
51507
51718
|
var import_node_path16 = require("node:path");
|
|
51508
|
-
var CLI_VERSION = true ? "0.
|
|
51719
|
+
var CLI_VERSION = true ? "0.44.0" : "";
|
|
51509
51720
|
function fail(message) {
|
|
51510
51721
|
console.error(message);
|
|
51511
51722
|
process.exit(1);
|
|
@@ -52196,7 +52407,8 @@ var nodeHubTransport = (request2) => new Promise((resolve2, reject) => {
|
|
|
52196
52407
|
let text = "";
|
|
52197
52408
|
res.setEncoding("utf8");
|
|
52198
52409
|
res.on("data", (chunk) => {
|
|
52199
|
-
if (text.length < request2.maxResponseChars)
|
|
52410
|
+
if (text.length < request2.maxResponseChars)
|
|
52411
|
+
text += chunk.slice(0, request2.maxResponseChars - text.length);
|
|
52200
52412
|
});
|
|
52201
52413
|
res.on(
|
|
52202
52414
|
"end",
|
|
@@ -53929,6 +54141,20 @@ Start it with \`slay computer start ${name}\`, or remove it with \`slay computer
|
|
|
53929
54141
|
const logDir = ensureLogDir("computer", root);
|
|
53930
54142
|
if (opts.upgrade) {
|
|
53931
54143
|
const bin = resolveServiceBin("computer", root, true);
|
|
54144
|
+
if ((0, import_node_fs20.existsSync)(unitPath("computer-host", name, backend))) {
|
|
54145
|
+
writeUnit(
|
|
54146
|
+
{
|
|
54147
|
+
kind: "computer-host",
|
|
54148
|
+
name,
|
|
54149
|
+
root,
|
|
54150
|
+
command: bin.command,
|
|
54151
|
+
args: [...bin.args, "--session-host"],
|
|
54152
|
+
logDir,
|
|
54153
|
+
...bin.env ? { env: bin.env } : {}
|
|
54154
|
+
},
|
|
54155
|
+
backend
|
|
54156
|
+
);
|
|
54157
|
+
}
|
|
53932
54158
|
writeUnit(
|
|
53933
54159
|
{
|
|
53934
54160
|
kind: "computer",
|
|
@@ -54195,7 +54421,7 @@ function updateCommand() {
|
|
|
54195
54421
|
}
|
|
54196
54422
|
|
|
54197
54423
|
// src/index.ts
|
|
54198
|
-
var program2 = new Command().enablePositionalOptions().name("slay").description("SlayZone CLI").version("0.
|
|
54424
|
+
var program2 = new Command().enablePositionalOptions().name("slay").description("SlayZone CLI").version("0.44.0").option("--dev", "Use development database (slayzone.dev.data.sqlite)").option("--hub <name|port>", "Target a specific hub on this machine (see `slay hub ls`)").showSuggestionAfterError(true).showHelpAfterError(true).hook("preAction", async (thisCommand) => {
|
|
54199
54425
|
const root = thisCommand.parent ?? thisCommand;
|
|
54200
54426
|
const opts = root.opts();
|
|
54201
54427
|
if (opts.dev) process.env.SLAYZONE_DEV = "1";
|