@slayzone/cli 0.43.0 → 0.45.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 +233 -33
- package/package.json +1 -1
package/dist/slay.js
CHANGED
|
@@ -16370,7 +16370,8 @@ var HUB_SWITCH_ENV = {
|
|
|
16370
16370
|
enableSso: "SLAYZONE_HUB_ENABLE_SSO",
|
|
16371
16371
|
enableProcesses: "SLAYZONE_HUB_ENABLE_PROCESSES",
|
|
16372
16372
|
enableIntegrations: "SLAYZONE_HUB_ENABLE_INTEGRATIONS",
|
|
16373
|
-
enableTelemetry: "SLAYZONE_HUB_ENABLE_TELEMETRY"
|
|
16373
|
+
enableTelemetry: "SLAYZONE_HUB_ENABLE_TELEMETRY",
|
|
16374
|
+
enablePush: "SLAYZONE_HUB_ENABLE_PUSH"
|
|
16374
16375
|
};
|
|
16375
16376
|
var HUB_SWITCH_DEFAULTS = {
|
|
16376
16377
|
requireLogin: false,
|
|
@@ -16378,7 +16379,8 @@ var HUB_SWITCH_DEFAULTS = {
|
|
|
16378
16379
|
enableSso: false,
|
|
16379
16380
|
enableProcesses: true,
|
|
16380
16381
|
enableIntegrations: true,
|
|
16381
|
-
enableTelemetry: true
|
|
16382
|
+
enableTelemetry: true,
|
|
16383
|
+
enablePush: true
|
|
16382
16384
|
};
|
|
16383
16385
|
var HUB_SSO_ENV = {
|
|
16384
16386
|
tenantId: "SLAYZONE_HUB_SSO_TENANT_ID",
|
|
@@ -16415,12 +16417,17 @@ var HUB_ADDRESS_ENV = {
|
|
|
16415
16417
|
/** Signing key of hub-auth. */
|
|
16416
16418
|
authSecret: "SLAYZONE_HUB_AUTH_SECRET"
|
|
16417
16419
|
};
|
|
16420
|
+
var HUB_CREDENTIALS_ENV = {
|
|
16421
|
+
secret: "SLAYZONE_HUB_CREDENTIALS_SECRET",
|
|
16422
|
+
fd: "SLAYZONE_HUB_CREDENTIALS_FD"
|
|
16423
|
+
};
|
|
16418
16424
|
var LEGACY_HUB_LISTEN_ENV = "SLAYZONE_HUB_ADDRESS";
|
|
16419
16425
|
var HUB_SESSION_RETENTION_DAYS_ENV = "SLAYZONE_HUB_SESSION_RETENTION_DAYS";
|
|
16420
16426
|
var HUB_ALLOWED_WEB_ORIGINS_ENV = "SLAYZONE_HUB_ALLOWED_WEB_ORIGINS";
|
|
16421
16427
|
var HUB_TRUSTED_PROXIES_ENV = "SLAYZONE_HUB_TRUSTED_PROXIES";
|
|
16422
16428
|
var HUB_CONVEX_ADDRESS_ENV = "SLAYZONE_HUB_CONVEX_ADDRESS";
|
|
16423
16429
|
var HUB_STUN_ADDRESSES_ENV = "SLAYZONE_HUB_STUN_ADDRESSES";
|
|
16430
|
+
var HUB_PUSH_SERVICE_ADDRESS_ENV = "SLAYZONE_HUB_PUSH_SERVICE_ADDRESS";
|
|
16424
16431
|
var HUB_PROCESS_ENV = [
|
|
16425
16432
|
...Object.values(HUB_SWITCH_ENV),
|
|
16426
16433
|
...Object.values(HUB_SSO_ENV),
|
|
@@ -16428,12 +16435,14 @@ var HUB_PROCESS_ENV = [
|
|
|
16428
16435
|
...Object.values(IDP_ROLE_ENV),
|
|
16429
16436
|
RETIRED_HUB_SSO_CLIENT_SECRET_ENV,
|
|
16430
16437
|
...Object.values(HUB_ADDRESS_ENV),
|
|
16438
|
+
...Object.values(HUB_CREDENTIALS_ENV),
|
|
16431
16439
|
LEGACY_HUB_LISTEN_ENV,
|
|
16432
16440
|
HUB_ALLOWED_WEB_ORIGINS_ENV,
|
|
16433
16441
|
HUB_TRUSTED_PROXIES_ENV,
|
|
16434
16442
|
HUB_SESSION_RETENTION_DAYS_ENV,
|
|
16435
16443
|
HUB_CONVEX_ADDRESS_ENV,
|
|
16436
|
-
HUB_STUN_ADDRESSES_ENV
|
|
16444
|
+
HUB_STUN_ADDRESSES_ENV,
|
|
16445
|
+
HUB_PUSH_SERVICE_ADDRESS_ENV
|
|
16437
16446
|
];
|
|
16438
16447
|
|
|
16439
16448
|
// ../../shared/platform/src/paths.ts
|
|
@@ -16664,7 +16673,8 @@ var MESSAGES = {
|
|
|
16664
16673
|
HUB_PASSWORD_DISABLED: `Password sign-in is switched off on this hub (${HUB_SWITCH_ENV.enablePassword}=0).`,
|
|
16665
16674
|
HUB_CONVEX_NOT_CONFIGURED: `GitHub sign-in is off on this hub: no Convex deployment is configured (${HUB_CONVEX_ADDRESS_ENV}).`,
|
|
16666
16675
|
HUB_CONVEX_MISMATCH: `This hub starts GitHub sign-in only against its own Convex deployment (${HUB_CONVEX_ADDRESS_ENV}); the request named another.`,
|
|
16667
|
-
HUB_TELEMETRY_DISABLED: `GitHub sign-in (leaderboard, feedback) is off on this hub: third-party telemetry is switched off (${HUB_SWITCH_ENV.enableTelemetry}=0)
|
|
16676
|
+
HUB_TELEMETRY_DISABLED: `GitHub sign-in (leaderboard, feedback) is off on this hub: third-party telemetry is switched off (${HUB_SWITCH_ENV.enableTelemetry}=0).`,
|
|
16677
|
+
HUB_PUSH_DISABLED: `Push notifications are switched off on this hub (${HUB_SWITCH_ENV.enablePush}=0).`
|
|
16668
16678
|
};
|
|
16669
16679
|
var VARIABLES = {
|
|
16670
16680
|
HUB_PROCESSES_DISABLED: HUB_SWITCH_ENV.enableProcesses,
|
|
@@ -16673,7 +16683,8 @@ var VARIABLES = {
|
|
|
16673
16683
|
HUB_PASSWORD_DISABLED: HUB_SWITCH_ENV.enablePassword,
|
|
16674
16684
|
HUB_CONVEX_NOT_CONFIGURED: HUB_CONVEX_ADDRESS_ENV,
|
|
16675
16685
|
HUB_CONVEX_MISMATCH: HUB_CONVEX_ADDRESS_ENV,
|
|
16676
|
-
HUB_TELEMETRY_DISABLED: HUB_SWITCH_ENV.enableTelemetry
|
|
16686
|
+
HUB_TELEMETRY_DISABLED: HUB_SWITCH_ENV.enableTelemetry,
|
|
16687
|
+
HUB_PUSH_DISABLED: HUB_SWITCH_ENV.enablePush
|
|
16677
16688
|
};
|
|
16678
16689
|
|
|
16679
16690
|
// ../../shared/platform/src/cli-install.ts
|
|
@@ -51003,7 +51014,8 @@ var HUB_CONFIG_SWITCH_KEYS = [
|
|
|
51003
51014
|
"enableSso",
|
|
51004
51015
|
"enableProcesses",
|
|
51005
51016
|
"enableIntegrations",
|
|
51006
|
-
"enableTelemetry"
|
|
51017
|
+
"enableTelemetry",
|
|
51018
|
+
"enablePush"
|
|
51007
51019
|
];
|
|
51008
51020
|
function readComputerAgentResources(value) {
|
|
51009
51021
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
@@ -51063,6 +51075,7 @@ function coerceHubConfig(raw) {
|
|
|
51063
51075
|
}
|
|
51064
51076
|
function coerceComputerConfig(raw) {
|
|
51065
51077
|
const cfg = {};
|
|
51078
|
+
if (typeof raw.followHubVersion === "boolean") cfg.followHubVersion = raw.followHubVersion;
|
|
51066
51079
|
if (typeof raw.autoUpgrade === "boolean") cfg.autoUpgrade = raw.autoUpgrade;
|
|
51067
51080
|
if (typeof raw.joinToken === "string" && raw.joinToken.length > 0) cfg.joinToken = raw.joinToken;
|
|
51068
51081
|
if (typeof raw.computerName === "string" && raw.computerName.length > 0)
|
|
@@ -51161,6 +51174,8 @@ var import_node_child_process3 = require("node:child_process");
|
|
|
51161
51174
|
var import_node_fs14 = require("node:fs");
|
|
51162
51175
|
var import_node_os5 = require("node:os");
|
|
51163
51176
|
var import_node_path14 = require("node:path");
|
|
51177
|
+
|
|
51178
|
+
// ../../shared/platform/src/service-identity.ts
|
|
51164
51179
|
var KINDS = {
|
|
51165
51180
|
"computer-host": {
|
|
51166
51181
|
labelPrefix: "com.slayzone.session-host.",
|
|
@@ -51203,6 +51218,16 @@ function assertValidServiceName(kind, name) {
|
|
|
51203
51218
|
);
|
|
51204
51219
|
}
|
|
51205
51220
|
}
|
|
51221
|
+
function systemdUnitName(kind, name) {
|
|
51222
|
+
assertValidServiceName(kind, name);
|
|
51223
|
+
return `${KINDS[kind].systemdPrefix}${name}.service`;
|
|
51224
|
+
}
|
|
51225
|
+
function launchdLabel(kind, name) {
|
|
51226
|
+
assertValidServiceName(kind, name);
|
|
51227
|
+
return `${KINDS[kind].labelPrefix}${name}`;
|
|
51228
|
+
}
|
|
51229
|
+
|
|
51230
|
+
// ../../shared/platform/src/service-unit.ts
|
|
51206
51231
|
function defaultUnitDir(backend) {
|
|
51207
51232
|
const home = process.env.HOME ?? (0, import_node_os5.homedir)();
|
|
51208
51233
|
if (backend === "launchd") return (0, import_node_path14.join)(home, "Library", "LaunchAgents");
|
|
@@ -51345,12 +51370,18 @@ ${envEntries}
|
|
|
51345
51370
|
</plist>
|
|
51346
51371
|
`;
|
|
51347
51372
|
}
|
|
51373
|
+
function systemdStopRecord(spec) {
|
|
51374
|
+
if (spec.kind === "hub") return "";
|
|
51375
|
+
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"';
|
|
51376
|
+
return `ExecStopPost=-/bin/sh -c '${script}' sh "${(0, import_node_path14.join)(spec.root, "logs")}"
|
|
51377
|
+
`;
|
|
51378
|
+
}
|
|
51348
51379
|
function renderSystemdUnit(spec) {
|
|
51349
51380
|
assertValidServiceName(spec.kind, spec.name);
|
|
51350
51381
|
const kind = KINDS[spec.kind];
|
|
51351
51382
|
const exec = [spec.command, ...spec.args].join(" ");
|
|
51352
51383
|
const envLines = unitEnv(spec).map(([k, v]) => `Environment=${k}=${v}`).join("\n");
|
|
51353
|
-
const agentIsolation = spec.kind === "hub" ? "" : "\nDelegate=memory\nDelegateSubgroup=supervisor
|
|
51384
|
+
const agentIsolation = spec.kind === "hub" ? "" : "\nDelegate=memory\nDelegateSubgroup=supervisor";
|
|
51354
51385
|
return `[Unit]
|
|
51355
51386
|
Description=${kind.description} (${spec.name})
|
|
51356
51387
|
Documentation=https://github.com/debuglebowski/slayzone
|
|
@@ -51364,7 +51395,10 @@ ExecStart=${exec}
|
|
|
51364
51395
|
Restart=on-failure
|
|
51365
51396
|
RestartSec=2
|
|
51366
51397
|
OOMScoreAdjust=-750${agentIsolation}
|
|
51367
|
-
#
|
|
51398
|
+
# A process the kernel OOM-kills (an agent's build, a headless browser) must not take
|
|
51399
|
+
# the whole service down with it: systemd's default (OOMPolicy=stop) did, twice a day.
|
|
51400
|
+
OOMPolicy=continue
|
|
51401
|
+
${systemdStopRecord(spec)}# stdout/stderr go to journald; read them with \`${kind.logsCommand} ${spec.name}\`.
|
|
51368
51402
|
StandardOutput=journal
|
|
51369
51403
|
StandardError=journal
|
|
51370
51404
|
|
|
@@ -51427,14 +51461,6 @@ function readUnitRoot(kind, name, backend, unitDir = defaultUnitDir(backend)) {
|
|
|
51427
51461
|
function serviceLogNames(kind) {
|
|
51428
51462
|
return { out: KINDS[kind].outLog, err: KINDS[kind].errLog };
|
|
51429
51463
|
}
|
|
51430
|
-
function systemdUnitName(kind, name) {
|
|
51431
|
-
assertValidServiceName(kind, name);
|
|
51432
|
-
return `${KINDS[kind].systemdPrefix}${name}.service`;
|
|
51433
|
-
}
|
|
51434
|
-
function launchdLabel(kind, name) {
|
|
51435
|
-
assertValidServiceName(kind, name);
|
|
51436
|
-
return `${KINDS[kind].labelPrefix}${name}`;
|
|
51437
|
-
}
|
|
51438
51464
|
function readUnitEnv(kind, name, backend, unitDir = defaultUnitDir(backend)) {
|
|
51439
51465
|
let text;
|
|
51440
51466
|
try {
|
|
@@ -51465,45 +51491,216 @@ function readUnitSecrets(kind, name, backend, unitDir = defaultUnitDir(backend))
|
|
|
51465
51491
|
// ../../shared/platform/src/computer-launcher.ts
|
|
51466
51492
|
var import_node_fs15 = require("node:fs");
|
|
51467
51493
|
var import_node_path15 = require("node:path");
|
|
51494
|
+
|
|
51495
|
+
// ../../shared/platform/src/computer-endpoints.ts
|
|
51496
|
+
var UNIX_SOCKET_PATH_MAX_BYTES = {
|
|
51497
|
+
darwin: 104,
|
|
51498
|
+
linux: 108
|
|
51499
|
+
};
|
|
51500
|
+
var HOST_SUPERSEDED_NOTICE = "host-superseded";
|
|
51501
|
+
var LEGACY_HOST_SUPERSEDED_EXIT_CODE = 79;
|
|
51502
|
+
var ENDPOINT_IN_USE_LISTEN_ERRORS = ["EADDRINUSE", "EEXIST"];
|
|
51503
|
+
|
|
51504
|
+
// ../../shared/platform/src/computer-launcher.ts
|
|
51468
51505
|
var import_node_fs16 = require("node:fs");
|
|
51469
51506
|
var COMPUTER_LAUNCHER = String.raw`#!/usr/bin/env node
|
|
51470
51507
|
const fs = require('node:fs'), path = require('node:path'), cp = require('node:child_process');
|
|
51508
|
+
const net = require('node:net'), os = require('node:os'), crypto = require('node:crypto');
|
|
51471
51509
|
const root = process.env.SLAYZONE_ROOT;
|
|
51472
51510
|
if (!root) throw Error('computer launcher requires SLAYZONE_ROOT');
|
|
51473
51511
|
const role = process.argv.includes('--session-host') ? 'host' : 'supervisor';
|
|
51474
51512
|
const dir = path.join(root, 'computer-runtime'), pointer = path.join(dir, role === 'host' ? 'host-release.json' : 'supervisor.json');
|
|
51475
|
-
|
|
51513
|
+
// Restart delay after consecutive failures: 2s doubling to 60s, reset once a child is healthy.
|
|
51514
|
+
const BACKOFF_MIN_MS = 2000, BACKOFF_MAX_MS = 60000, LOG_MAX_BYTES = 5 * 1024 * 1024;
|
|
51515
|
+
// A session host that found another live host on its control endpoint (computer-endpoints.ts
|
|
51516
|
+
// HOST_SUPERSEDED_EXIT_CODE): it says so over IPC, then exits 0. A 0.44.0 host exited 79 instead.
|
|
51517
|
+
const SUPERSEDED_NOTICE = ${JSON.stringify(HOST_SUPERSEDED_NOTICE)}, LEGACY_SUPERSEDED_EXIT = ${LEGACY_HOST_SUPERSEDED_EXIT_CODE};
|
|
51518
|
+
// This root's endpoints, derived exactly as computer-endpoints.ts derives them.
|
|
51519
|
+
const endpointKey = crypto.createHash('sha256').update(path.resolve(root)).digest('hex').slice(0, 24);
|
|
51520
|
+
const endpointDir = process.platform === 'win32' ? null : path.join(os.tmpdir(), 'slay-computer-' + (process.getuid ? process.getuid() : 'user') + '-' + endpointKey);
|
|
51521
|
+
const endpoints = endpointDir
|
|
51522
|
+
? {control: path.join(endpointDir, 'control.sock'), launcher: path.join(endpointDir, 'l.sock')}
|
|
51523
|
+
: {control: '\\\\.\\pipe\\slay-computer-' + endpointKey, launcher: '\\\\.\\pipe\\slay-computer-launcher-' + endpointKey};
|
|
51524
|
+
// Longest Unix socket path Node accepts (computer-endpoints.ts UNIX_SOCKET_PATH_MAX_BYTES):
|
|
51525
|
+
// a longer one fails listen/connect with a bare EINVAL, so it is refused by name first.
|
|
51526
|
+
const SOCKET_PATH_MAX = ${JSON.stringify(UNIX_SOCKET_PATH_MAX_BYTES)}[process.platform] || 104;
|
|
51527
|
+
// listen errors meaning the endpoint path is already held (computer-endpoints.ts
|
|
51528
|
+
// ENDPOINT_IN_USE_LISTEN_ERRORS): EADDRINUSE, or EEXIST when macOS sees another
|
|
51529
|
+
// launcher bind the same path at the same moment. Either way: probe, never bail.
|
|
51530
|
+
const IN_USE_LISTEN_ERRORS = ${JSON.stringify(ENDPOINT_IN_USE_LISTEN_ERRORS)};
|
|
51531
|
+
function socketPathError(p) {
|
|
51532
|
+
const bytes = Buffer.byteLength(p);
|
|
51533
|
+
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';
|
|
51534
|
+
}
|
|
51535
|
+
if (process.argv.includes('--print-endpoints')) { process.stdout.write(JSON.stringify(endpoints) + '\n'); return; }
|
|
51536
|
+
let child, stopping = false, healthy = false, timer, probation, killTimer, failures = 0, nextTimer, lock;
|
|
51537
|
+
// What a waiting supervisor asks over the launcher endpoint (queryHostLauncher).
|
|
51538
|
+
const status = {state: 'starting', childPid: null, nextLaunchAt: null, lastExit: null};
|
|
51476
51539
|
function read() { return JSON.parse(fs.readFileSync(pointer, 'utf8')); }
|
|
51540
|
+
// Every start and exit of the child, timestamped, to stderr and to logs/computer.log
|
|
51541
|
+
// (shared by every computer process). Before, an exit left no trace at all here.
|
|
51542
|
+
function log(msg) {
|
|
51543
|
+
const line = new Date().toISOString() + ' [launcher ' + process.pid + '] ' + role + ' ' + msg + '\n';
|
|
51544
|
+
try { process.stderr.write(line); } catch {}
|
|
51545
|
+
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 {}
|
|
51546
|
+
}
|
|
51547
|
+
// The session host's launcher writes, for its whole life, to the host.log it was started
|
|
51548
|
+
// with: rotated only when a host was spawned, it grew without bound (32 MB). Copy, then
|
|
51549
|
+
// truncate in place: every holder of the file appends, so all keep writing to its start.
|
|
51550
|
+
function rotateHostLog() {
|
|
51551
|
+
if (role !== 'host') return;
|
|
51552
|
+
try {
|
|
51553
|
+
const file = path.join(dir, 'host.log'), out = fs.fstatSync(1), st = fs.statSync(file);
|
|
51554
|
+
if (out.ino !== st.ino || out.dev !== st.dev || st.size <= LOG_MAX_BYTES) return;
|
|
51555
|
+
fs.copyFileSync(file, file + '.1'); fs.truncateSync(file, 0);
|
|
51556
|
+
} catch {}
|
|
51557
|
+
}
|
|
51558
|
+
setInterval(rotateHostLog, 600000).unref();
|
|
51559
|
+
// ── One session-host launcher per root ──────────────────────────────────────────
|
|
51560
|
+
// The launcher endpoint is held for this launcher's whole life: a second launcher for
|
|
51561
|
+
// the root finds it live and stops before starting any child. (Two once ran at once,
|
|
51562
|
+
// one restarting an EADDRINUSE-failing child forever, rolling back good releases.)
|
|
51563
|
+
function prepareEndpointDir() {
|
|
51564
|
+
if (!endpointDir) return;
|
|
51565
|
+
try { fs.mkdirSync(endpointDir, {mode: 0o700}); } catch (e) { if (e.code !== 'EEXIST') throw e; }
|
|
51566
|
+
const st = fs.lstatSync(endpointDir);
|
|
51567
|
+
if (st.isSymbolicLink() || !st.isDirectory() || (process.getuid && st.uid !== process.getuid()) || (st.mode & 0o077))
|
|
51568
|
+
throw Error('unsafe computer endpoint directory ' + endpointDir + ': must be a directory owned by this user with mode 0700');
|
|
51569
|
+
}
|
|
51570
|
+
// live / stale / absent as probeEndpoint (computer-endpoints.ts) tells them; any other
|
|
51571
|
+
// connect error says nothing about an owner and is passed on (cb(null, err)).
|
|
51572
|
+
function probe(cb) {
|
|
51573
|
+
const s = net.connect(endpoints.launcher); let done = false;
|
|
51574
|
+
const fin = (r, err) => { if (done) return; done = true; clearTimeout(t); s.destroy(); cb(r, err); };
|
|
51575
|
+
const t = setTimeout(() => fin('live'), 2000);
|
|
51576
|
+
s.once('connect', () => fin('live'));
|
|
51577
|
+
s.once('error', (e) => e.code === 'ENOENT' ? fin('absent') : e.code === 'ECONNREFUSED' ? fin('stale') : e.code === 'EAGAIN' ? fin('live') : fin(null, e));
|
|
51578
|
+
}
|
|
51579
|
+
function serveStatus(socket) {
|
|
51580
|
+
let buf = '';
|
|
51581
|
+
socket.setEncoding('utf8'); socket.on('error', () => {}); socket.setTimeout(2000, () => socket.destroy());
|
|
51582
|
+
socket.on('data', (chunk) => {
|
|
51583
|
+
buf += chunk; const end = buf.indexOf('\n');
|
|
51584
|
+
if (end < 0) { if (buf.length > 1024) socket.destroy(); return; }
|
|
51585
|
+
let command; try { command = JSON.parse(buf.slice(0, end)).command; } catch {}
|
|
51586
|
+
if (command === 'launch-now' && status.state === 'backoff' && !stopping) { clearTimeout(nextTimer); log('launching now, at a waiting supervisor\'s request'); launch(); }
|
|
51587
|
+
socket.end(JSON.stringify(status) + '\n');
|
|
51588
|
+
});
|
|
51589
|
+
}
|
|
51590
|
+
function bail(msg) { log(msg + '; stopping'); process.exit(1); }
|
|
51591
|
+
// Every bind of the launcher endpoint happens inside one short critical section (an
|
|
51592
|
+
// atomic mkdir of the guard). listen() on a Unix socket is bind() then listen(): in
|
|
51593
|
+
// between, the file exists but refuses connections, exactly like one whose launcher
|
|
51594
|
+
// died. With binds serialized, a refusing socket seen while holding the guard can only
|
|
51595
|
+
// be a dead launcher's, so replacing it is safe. (2026-11-27: under full CPU load a
|
|
51596
|
+
// launcher probed a winner preempted in that gap, "took over" its live endpoint, and
|
|
51597
|
+
// two launchers each ran a host.) Windows: named pipes are exclusive; no guard needed.
|
|
51598
|
+
// The guard keeps its old name so an older launcher.cjs still running excludes with it.
|
|
51599
|
+
const GUARD_STALE_MS = 10000;
|
|
51600
|
+
function acquire(then, attempt) {
|
|
51601
|
+
attempt = attempt || 0;
|
|
51602
|
+
if (attempt > 50) return bail('cannot take the launcher endpoint ' + endpoints.launcher);
|
|
51603
|
+
if (endpointDir) { const tooLong = socketPathError(endpoints.launcher) || socketPathError(endpoints.control); if (tooLong) return bail(tooLong); }
|
|
51604
|
+
try { prepareEndpointDir(); } catch (e) { return bail(e.message); }
|
|
51605
|
+
const retry = (ms) => setTimeout(() => acquire(then, attempt + 1), ms);
|
|
51606
|
+
const guard = endpointDir ? endpoints.launcher + '.takeover' : null;
|
|
51607
|
+
if (guard) {
|
|
51608
|
+
try { fs.mkdirSync(guard, {mode: 0o700}); } catch (e) {
|
|
51609
|
+
// ENOENT: a launcher exiting just removed the (empty) endpoint directory.
|
|
51610
|
+
if (e.code === 'ENOENT') return retry(0);
|
|
51611
|
+
if (e.code !== 'EEXIST') return bail('cannot take ' + guard + ': ' + e.message);
|
|
51612
|
+
// Held for a bind (milliseconds). Waiting on it is not a failed attempt: it ends
|
|
51613
|
+
// when the holder finishes, or GUARD_STALE_MS after a holder that died holding it.
|
|
51614
|
+
try { if (Date.now() - fs.statSync(guard).mtimeMs > GUARD_STALE_MS) fs.rmdirSync(guard); } catch {}
|
|
51615
|
+
return setTimeout(() => acquire(then, attempt), 25);
|
|
51616
|
+
}
|
|
51617
|
+
}
|
|
51618
|
+
const unguard = () => { if (guard) try { fs.rmdirSync(guard); } catch {} };
|
|
51619
|
+
const won = (server, how) => { unguard(); if (how) log(how); lock = server; then(); };
|
|
51620
|
+
const server = net.createServer(serveStatus);
|
|
51621
|
+
server.once('error', (err) => {
|
|
51622
|
+
if (!IN_USE_LISTEN_ERRORS.includes(err.code)) { unguard(); return bail('cannot bind ' + endpoints.launcher + ': ' + err.message); }
|
|
51623
|
+
probe((state, probeErr) => {
|
|
51624
|
+
if (probeErr) { unguard(); return bail('cannot probe ' + endpoints.launcher + ': ' + (probeErr.code || probeErr.message)); }
|
|
51625
|
+
if (state === 'live') { unguard(); log('launcher already running for this root; superseded, stopping'); process.exit(0); }
|
|
51626
|
+
if (state === 'absent' || !guard) { unguard(); return retry(50); }
|
|
51627
|
+
// Stale: its launcher died (no live one binds without the guard this one holds).
|
|
51628
|
+
try { fs.unlinkSync(endpoints.launcher); } catch {}
|
|
51629
|
+
const taken = net.createServer(serveStatus);
|
|
51630
|
+
taken.once('error', () => { unguard(); retry(0); });
|
|
51631
|
+
taken.listen(endpoints.launcher, () => won(taken, 'took over a launcher endpoint left by a dead launcher'));
|
|
51632
|
+
});
|
|
51633
|
+
});
|
|
51634
|
+
server.listen(endpoints.launcher, () => won(server));
|
|
51635
|
+
}
|
|
51636
|
+
// Ends this launcher: frees its endpoint (and the directory, once empty), then exits.
|
|
51637
|
+
function release(code) {
|
|
51638
|
+
status.state = 'stopping'; status.nextLaunchAt = null; clearTimeout(nextTimer);
|
|
51639
|
+
process.exitCode = code;
|
|
51640
|
+
if (!lock) return;
|
|
51641
|
+
lock.close(() => { if (endpointDir) try { fs.rmdirSync(endpointDir); } catch {} });
|
|
51642
|
+
lock = undefined;
|
|
51643
|
+
}
|
|
51477
51644
|
function launch() {
|
|
51478
51645
|
if (stopping) return;
|
|
51479
|
-
|
|
51646
|
+
rotateHostLog();
|
|
51647
|
+
const state = read(); let timedOut = false, superseded = false; healthy = false; probation = undefined;
|
|
51648
|
+
const startedAt = Date.now();
|
|
51480
51649
|
child = cp.fork(state.current.entry, [role === 'host' ? '--session-host' : '--supervisor'], {env: {...process.env, SLAYZONE_NONINTERACTIVE:'1'}, stdio:['inherit','inherit','inherit','ipc']});
|
|
51650
|
+
status.state = 'running'; status.childPid = child.pid; status.nextLaunchAt = null;
|
|
51651
|
+
log(state.current.version + ' started pid=' + child.pid + (failures ? ' (after ' + failures + ' consecutive failures)' : ''));
|
|
51481
51652
|
timer = setTimeout(() => {
|
|
51482
51653
|
timedOut = true;
|
|
51483
|
-
|
|
51654
|
+
log(state.current.version + ' startup timed out; restarting');
|
|
51484
51655
|
// A supervisor SIGTERM means explicit shutdown, including its persistent host.
|
|
51485
51656
|
// Crash only the supervisor; its connectors stop on IPC loss and work survives.
|
|
51486
51657
|
if (role === 'supervisor') child.kill('SIGKILL');
|
|
51487
51658
|
else { child.kill('SIGTERM'); killTimer = setTimeout(() => child.kill('SIGKILL'), 10000); }
|
|
51488
51659
|
}, 90000);
|
|
51489
|
-
child.on('message', m => { if (m && m.type === 'supervisor-ready') {clearTimeout(timer); if (!probation) probation = setTimeout(() => {healthy = true;}, 60000);} });
|
|
51490
|
-
child.on('error', () => {});
|
|
51491
|
-
child.on('exit', (code) => {
|
|
51660
|
+
child.on('message', m => { if (m && m.type === SUPERSEDED_NOTICE) superseded = true; if (m && m.type === 'supervisor-ready') {clearTimeout(timer); if (!probation) probation = setTimeout(() => {healthy = true; failures = 0;}, 60000);} });
|
|
51661
|
+
child.on('error', (err) => { log(state.current.version + ' child error: ' + (err && err.message)); });
|
|
51662
|
+
child.on('exit', (code, signal) => {
|
|
51492
51663
|
clearTimeout(timer); clearTimeout(probation); clearTimeout(killTimer);
|
|
51493
|
-
|
|
51494
|
-
|
|
51664
|
+
// A clean exit may still have its last IPC message (the superseded notice) unread:
|
|
51665
|
+
// read the channel to its end first, bounded (a grandchild could hold it open).
|
|
51666
|
+
if (code !== 0 || !child.connected) return exited(code, signal);
|
|
51667
|
+
let settled = false;
|
|
51668
|
+
const settle = () => { if (settled) return; settled = true; clearTimeout(drain); exited(code, signal); };
|
|
51669
|
+
const drain = setTimeout(settle, 1000);
|
|
51670
|
+
child.once('disconnect', settle);
|
|
51671
|
+
});
|
|
51672
|
+
function exited(code, signal) {
|
|
51673
|
+
const ended = state.current.version + ' pid=' + child.pid + ' exited code=' + code + ' signal=' + signal + ' after ' + (Date.now() - startedAt) + 'ms';
|
|
51674
|
+
status.childPid = null; status.lastExit = {version: state.current.version, code, signal, at: Date.now()};
|
|
51675
|
+
if (stopping) {log(ended + '; stopping'); release(code || 0); return;}
|
|
51676
|
+
// Another live host owns the endpoint: not a failure of this release (no
|
|
51677
|
+
// quarantine, no rollback), and nothing to restart. This launcher is redundant.
|
|
51678
|
+
if (role === 'host' && !timedOut && ((superseded && code === 0) || code === LEGACY_SUPERSEDED_EXIT)) {log(ended + '; superseded by a live session host, stopping'); stopping = true; release(0); return;}
|
|
51679
|
+
if (code === 75 && !timedOut) {log(ended + '; relaunching (requested)'); launch(); return;}
|
|
51495
51680
|
const failed = timedOut || code !== 0;
|
|
51681
|
+
let rolledBack = '';
|
|
51496
51682
|
if (!healthy && failed && state.previous) {
|
|
51497
51683
|
fs.writeFileSync(path.join(dir, role + '-quarantine.json'), JSON.stringify({version: state.current.version, until: Date.now() + 900000}), {mode:0o600});
|
|
51498
51684
|
const temp = pointer + '.tmp';
|
|
51499
51685
|
fs.writeFileSync(temp, JSON.stringify({current:state.previous}) + '\n', {mode:0o600}); fs.renameSync(temp,pointer);
|
|
51686
|
+
rolledBack = '; quarantined, rolled back to ' + state.previous.version;
|
|
51500
51687
|
}
|
|
51501
|
-
if (!failed) return;
|
|
51502
|
-
|
|
51503
|
-
|
|
51688
|
+
if (!failed) {log(ended + '; not restarting'); release(0); return;}
|
|
51689
|
+
failures += 1;
|
|
51690
|
+
const delay = Math.min(BACKOFF_MIN_MS * Math.pow(2, failures - 1), BACKOFF_MAX_MS);
|
|
51691
|
+
log(ended + rolledBack + '; restarting in ' + delay + 'ms (failure ' + failures + ')');
|
|
51692
|
+
status.state = 'backoff'; status.nextLaunchAt = Date.now() + delay;
|
|
51693
|
+
nextTimer = setTimeout(launch, delay);
|
|
51694
|
+
}
|
|
51504
51695
|
}
|
|
51505
|
-
for (const signal of ['SIGINT','SIGTERM']) process.on(signal, () => {
|
|
51506
|
-
|
|
51696
|
+
for (const signal of ['SIGINT','SIGTERM']) process.on(signal, () => {
|
|
51697
|
+
stopping = true; log('received ' + signal + ', stopping');
|
|
51698
|
+
// No child up (backing off, or not started yet): nothing to wait for.
|
|
51699
|
+
if (child && child.exitCode === null && child.signalCode === null) child.kill(signal);
|
|
51700
|
+
else release(0);
|
|
51701
|
+
});
|
|
51702
|
+
if (role === 'host') acquire(() => (stopping ? release(0) : launch()));
|
|
51703
|
+
else launch();
|
|
51507
51704
|
`;
|
|
51508
51705
|
function ensureComputerLauncher(root, release, forceUpgrade = false) {
|
|
51509
51706
|
const dir = (0, import_node_path15.join)(root, "computer-runtime");
|
|
@@ -51547,7 +51744,7 @@ var import_node_child_process4 = require("node:child_process");
|
|
|
51547
51744
|
var import_node_fs17 = require("node:fs");
|
|
51548
51745
|
var import_node_module = require("node:module");
|
|
51549
51746
|
var import_node_path16 = require("node:path");
|
|
51550
|
-
var CLI_VERSION = true ? "0.
|
|
51747
|
+
var CLI_VERSION = true ? "0.45.0" : "";
|
|
51551
51748
|
function fail(message) {
|
|
51552
51749
|
console.error(message);
|
|
51553
51750
|
process.exit(1);
|
|
@@ -52238,7 +52435,8 @@ var nodeHubTransport = (request2) => new Promise((resolve2, reject) => {
|
|
|
52238
52435
|
let text = "";
|
|
52239
52436
|
res.setEncoding("utf8");
|
|
52240
52437
|
res.on("data", (chunk) => {
|
|
52241
|
-
if (text.length < request2.maxResponseChars)
|
|
52438
|
+
if (text.length < request2.maxResponseChars)
|
|
52439
|
+
text += chunk.slice(0, request2.maxResponseChars - text.length);
|
|
52242
52440
|
});
|
|
52243
52441
|
res.on(
|
|
52244
52442
|
"end",
|
|
@@ -52350,7 +52548,9 @@ function signedInEmail(baseUrl, token) {
|
|
|
52350
52548
|
var import_node_crypto6 = require("node:crypto");
|
|
52351
52549
|
var HUB_AUTH_SECRET_LABELS = {
|
|
52352
52550
|
/** The bootstrap owner of a reachable password hub (apps/hub bootstrap-owner.ts). */
|
|
52353
|
-
bootstrapOwnerPassword: "slayzone-hub/bootstrap-owner-password/v1"
|
|
52551
|
+
bootstrapOwnerPassword: "slayzone-hub/bootstrap-owner-password/v1",
|
|
52552
|
+
/** The key integration tokens are encrypted under (integrations hub-cipher.ts). */
|
|
52553
|
+
integrationCredentials: "slayzone-hub/integration-credentials/v1"
|
|
52354
52554
|
};
|
|
52355
52555
|
function deriveFromHubAuthSecret(secret, label, bytes) {
|
|
52356
52556
|
if (!secret) throw new Error("[slayzone] cannot derive from an empty hub auth secret");
|
|
@@ -54251,7 +54451,7 @@ function updateCommand() {
|
|
|
54251
54451
|
}
|
|
54252
54452
|
|
|
54253
54453
|
// src/index.ts
|
|
54254
|
-
var program2 = new Command().enablePositionalOptions().name("slay").description("SlayZone CLI").version("0.
|
|
54454
|
+
var program2 = new Command().enablePositionalOptions().name("slay").description("SlayZone CLI").version("0.45.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) => {
|
|
54255
54455
|
const root = thisCommand.parent ?? thisCommand;
|
|
54256
54456
|
const opts = root.opts();
|
|
54257
54457
|
if (opts.dev) process.env.SLAYZONE_DEV = "1";
|