@vibedeckx/darwin-arm64 0.3.52 → 0.3.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin.js +354 -291
  2. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -271111,10 +271111,306 @@ function judgeLiveness(status, pid, now3 = /* @__PURE__ */ new Date()) {
271111
271111
 
271112
271112
  // src/connect-service.ts
271113
271113
  import { spawnSync } from "node:child_process";
271114
- import { createHash as createHash12 } from "node:crypto";
271115
- import fs12 from "node:fs";
271114
+ import { createHash as createHash13 } from "node:crypto";
271115
+ import fs13 from "node:fs";
271116
271116
  import os2 from "node:os";
271117
+ import path28 from "node:path";
271118
+
271119
+ // src/connect-runtime.ts
271120
+ import { createHash as createHash12, randomUUID as randomUUID33 } from "node:crypto";
271121
+ import fs12 from "node:fs";
271117
271122
  import path27 from "node:path";
271123
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
271124
+ var LAUNCHER_NAME = "launcher";
271125
+ var SERVICE_ENV_NAME = "service.env";
271126
+ var SERVICE_ENV_FLAG = "--service-env";
271127
+ var MANIFEST_NAME = "manifest.json";
271128
+ var VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._+-]*$/;
271129
+ function runtimeRoot(dataDir) {
271130
+ return path27.join(dataDir, "runtime");
271131
+ }
271132
+ function launcherPath(dataDir) {
271133
+ return path27.join(runtimeRoot(dataDir), LAUNCHER_NAME);
271134
+ }
271135
+ function serviceEnvPath(dataDir) {
271136
+ return path27.join(runtimeRoot(dataDir), SERVICE_ENV_NAME);
271137
+ }
271138
+ function shellQuote(value) {
271139
+ return `'${value.replace(/'/g, `'\\''`)}'`;
271140
+ }
271141
+ function renderServiceEnv(pathEnv) {
271142
+ return `# Generated by \`vibedeckx connect install\`. Do not edit.
271143
+ PATH=${shellQuote(pathEnv)}
271144
+ export PATH
271145
+ `;
271146
+ }
271147
+ function writeServiceEnv(dataDir, pathEnv) {
271148
+ const file2 = serviceEnvPath(dataDir);
271149
+ const content = renderServiceEnv(pathEnv);
271150
+ let before;
271151
+ try {
271152
+ before = fs12.readFileSync(file2, "utf8");
271153
+ } catch {
271154
+ before = void 0;
271155
+ }
271156
+ if (before === content) return false;
271157
+ fs12.mkdirSync(path27.dirname(file2), { recursive: true, mode: 493 });
271158
+ writeFileAtomic(file2, content, { mode: 420 });
271159
+ return true;
271160
+ }
271161
+ function detectRuntimeSource(options = {}) {
271162
+ const entry = fileURLToPath3(options.entryUrl ?? import.meta.url);
271163
+ const packageRoot = path27.resolve(path27.dirname(entry), "..");
271164
+ return validateRuntimeSource(packageRoot, options.nodePath ?? process.execPath);
271165
+ }
271166
+ function validateRuntimeSource(packageRoot, nodePath) {
271167
+ const notRelease = (reason) => new Error(
271168
+ `Cannot install the worker runtime from ${packageRoot}: ${reason}. Run \`vibedeckx connect install\` from an installed release, e.g. \`npx vibedeckx@latest connect install\`.`
271169
+ );
271170
+ let pkg;
271171
+ try {
271172
+ pkg = JSON.parse(fs12.readFileSync(path27.join(packageRoot, "package.json"), "utf8"));
271173
+ } catch {
271174
+ throw notRelease("package.json is missing");
271175
+ }
271176
+ if (typeof pkg.version !== "string" || !VERSION_PATTERN.test(pkg.version)) {
271177
+ throw notRelease("package version is missing or invalid");
271178
+ }
271179
+ if (!fs12.existsSync(path27.join(packageRoot, "dist", "bin.js"))) {
271180
+ throw notRelease("dist/bin.js is missing");
271181
+ }
271182
+ for (const nativeModule of ["better-sqlite3", "node-pty"]) {
271183
+ const modulePath = path27.join(packageRoot, "node_modules", nativeModule);
271184
+ let stat3;
271185
+ try {
271186
+ stat3 = fs12.lstatSync(modulePath);
271187
+ } catch {
271188
+ throw notRelease(`bundled ${nativeModule} is missing`);
271189
+ }
271190
+ if (stat3.isSymbolicLink()) {
271191
+ throw notRelease(`${nativeModule} is a symlink (source checkout)`);
271192
+ }
271193
+ }
271194
+ return { packageRoot, version: pkg.version, nodePath };
271195
+ }
271196
+ function sha256File(filePath) {
271197
+ const hash2 = createHash12("sha256");
271198
+ const fd = fs12.openSync(filePath, "r");
271199
+ try {
271200
+ const buffer = Buffer.allocUnsafe(1 << 20);
271201
+ for (; ; ) {
271202
+ const read = fs12.readSync(fd, buffer, 0, buffer.length, null);
271203
+ if (read === 0) break;
271204
+ hash2.update(buffer.subarray(0, read));
271205
+ }
271206
+ } finally {
271207
+ fs12.closeSync(fd);
271208
+ }
271209
+ return hash2.digest("hex");
271210
+ }
271211
+ function walk(root) {
271212
+ const files = [];
271213
+ const links = [];
271214
+ const dirs = [];
271215
+ const visit2 = (relative) => {
271216
+ const absolute = path27.join(root, relative);
271217
+ for (const entry of fs12.readdirSync(absolute, { withFileTypes: true })) {
271218
+ const child = relative ? path27.join(relative, entry.name) : entry.name;
271219
+ if (entry.isSymbolicLink()) links.push(child);
271220
+ else if (entry.isDirectory()) {
271221
+ dirs.push(child);
271222
+ visit2(child);
271223
+ } else if (entry.isFile()) files.push(child);
271224
+ }
271225
+ };
271226
+ visit2("");
271227
+ return { files, links, dirs };
271228
+ }
271229
+ function hashTree(root, relativeFiles) {
271230
+ const result = {};
271231
+ for (const file2 of relativeFiles) {
271232
+ result[file2.split(path27.sep).join("/")] = sha256File(path27.join(root, file2));
271233
+ }
271234
+ return result;
271235
+ }
271236
+ function fsyncTree(root) {
271237
+ const { files, dirs } = walk(root);
271238
+ for (const file2 of files) {
271239
+ const fd = fs12.openSync(path27.join(root, file2), "r");
271240
+ try {
271241
+ fs12.fsyncSync(fd);
271242
+ } finally {
271243
+ fs12.closeSync(fd);
271244
+ }
271245
+ }
271246
+ for (const dir of [...dirs].reverse()) fsyncDirectory(path27.join(root, dir));
271247
+ fsyncDirectory(root);
271248
+ }
271249
+ function readManifest(versionDir) {
271250
+ try {
271251
+ const parsed = JSON.parse(
271252
+ fs12.readFileSync(path27.join(versionDir, MANIFEST_NAME), "utf8")
271253
+ );
271254
+ if (parsed.schemaVersion !== 1 || typeof parsed.files !== "object") return void 0;
271255
+ return parsed;
271256
+ } catch {
271257
+ return void 0;
271258
+ }
271259
+ }
271260
+ function verifyRuntimeVersion(versionDir) {
271261
+ const manifest = readManifest(versionDir);
271262
+ if (!manifest) return false;
271263
+ for (const [relative, expected] of Object.entries(manifest.files)) {
271264
+ const absolute = path27.join(versionDir, ...relative.split("/"));
271265
+ try {
271266
+ if (sha256File(absolute) !== expected) return false;
271267
+ } catch {
271268
+ return false;
271269
+ }
271270
+ }
271271
+ return true;
271272
+ }
271273
+ function readCurrentVersion(dataDir) {
271274
+ try {
271275
+ const value = fs12.readFileSync(path27.join(runtimeRoot(dataDir), "current"), "utf8").trim();
271276
+ return VERSION_PATTERN.test(value) ? value : void 0;
271277
+ } catch {
271278
+ return void 0;
271279
+ }
271280
+ }
271281
+ function readPreviousVersion(dataDir) {
271282
+ try {
271283
+ const value = fs12.readFileSync(path27.join(runtimeRoot(dataDir), "previous"), "utf8").trim();
271284
+ return VERSION_PATTERN.test(value) ? value : void 0;
271285
+ } catch {
271286
+ return void 0;
271287
+ }
271288
+ }
271289
+ function renderLauncher() {
271290
+ return `#!/bin/sh
271291
+ # Generated by \`vibedeckx connect install\`. Do not edit.
271292
+ set -eu
271293
+ RUNTIME_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
271294
+ if [ "\${1:-}" = "${SERVICE_ENV_FLAG}" ]; then
271295
+ shift
271296
+ if [ -f "$RUNTIME_ROOT/${SERVICE_ENV_NAME}" ]; then . "$RUNTIME_ROOT/${SERVICE_ENV_NAME}"; fi
271297
+ fi
271298
+ VERSION=$(cat "$RUNTIME_ROOT/current" 2>/dev/null || true)
271299
+ case "$VERSION" in
271300
+ ''|*[!0-9A-Za-z._+-]*) echo "vibedeckx launcher: invalid or missing $RUNTIME_ROOT/current" >&2; exit 78 ;;
271301
+ esac
271302
+ VERSION_DIR="$RUNTIME_ROOT/$VERSION"
271303
+ if [ ! -x "$VERSION_DIR/node" ] || [ ! -f "$VERSION_DIR/package/dist/bin.js" ]; then
271304
+ echo "vibedeckx launcher: runtime $VERSION_DIR is incomplete" >&2
271305
+ exit 78
271306
+ fi
271307
+ export VIBEDECKX_RUNTIME_DIR="$VERSION_DIR"
271308
+ exec "$VERSION_DIR/node" "$VERSION_DIR/package/dist/bin.js" "$@"
271309
+ `;
271310
+ }
271311
+ function installRuntime(dataDir, source) {
271312
+ if (process.platform === "win32") {
271313
+ throw new Error("The installed worker runtime is not supported on Windows yet");
271314
+ }
271315
+ if (!VERSION_PATTERN.test(source.version)) {
271316
+ throw new Error(`Invalid runtime version: ${source.version}`);
271317
+ }
271318
+ const root = runtimeRoot(dataDir);
271319
+ fs12.mkdirSync(root, { recursive: true, mode: 493 });
271320
+ const expected = sourceManifestFiles(source);
271321
+ const buildId = `${source.version}+${buildHash(expected)}`;
271322
+ let versionDir = path27.join(root, buildId);
271323
+ let copied = false;
271324
+ if (!isInstalledCopyOf(versionDir, expected)) {
271325
+ if (fs12.existsSync(versionDir)) {
271326
+ versionDir = path27.join(root, `${buildId}.r${randomUUID33().slice(0, 8)}`);
271327
+ }
271328
+ const staging = path27.join(root, `.staging-${buildId}-${randomUUID33()}`);
271329
+ try {
271330
+ stageRuntime(staging, source, expected);
271331
+ fs12.renameSync(staging, versionDir);
271332
+ fsyncDirectory(root);
271333
+ copied = true;
271334
+ } finally {
271335
+ fs12.rmSync(staging, { recursive: true, force: true });
271336
+ }
271337
+ }
271338
+ const installedId = path27.basename(versionDir);
271339
+ const launcher = launcherPath(dataDir);
271340
+ writeFileAtomic(launcher, renderLauncher(), { mode: 493 });
271341
+ const before = readCurrentVersion(dataDir);
271342
+ if (before !== installedId) {
271343
+ if (before) writeFileAtomic(path27.join(root, "previous"), `${before}
271344
+ `);
271345
+ writeFileAtomic(path27.join(root, "current"), `${installedId}
271346
+ `);
271347
+ }
271348
+ const previous = before !== installedId ? before : readPreviousVersion(dataDir);
271349
+ const pruned = pruneRuntimeVersions(dataDir, [installedId, previous]);
271350
+ return { version: source.version, buildId: installedId, versionDir, launcher, copied, previous, pruned };
271351
+ }
271352
+ function buildHash(files) {
271353
+ const hash2 = createHash12("sha256");
271354
+ for (const relative of Object.keys(files).sort()) hash2.update(`${relative}\0${files[relative]}
271355
+ `);
271356
+ return hash2.digest("hex").slice(0, 12);
271357
+ }
271358
+ function sourceManifestFiles(source) {
271359
+ const expected = {};
271360
+ const packageTree = walk(source.packageRoot);
271361
+ for (const [relative, hash2] of Object.entries(hashTree(source.packageRoot, packageTree.files))) {
271362
+ expected[`package/${relative}`] = hash2;
271363
+ }
271364
+ expected.node = sha256File(source.nodePath);
271365
+ return expected;
271366
+ }
271367
+ function isInstalledCopyOf(versionDir, expected) {
271368
+ const manifest = readManifest(versionDir);
271369
+ if (!manifest) return false;
271370
+ const installed = Object.entries(manifest.files);
271371
+ if (installed.length !== Object.keys(expected).length) return false;
271372
+ if (installed.some(([relative, hash2]) => expected[relative] !== hash2)) return false;
271373
+ return verifyRuntimeVersion(versionDir);
271374
+ }
271375
+ function stageRuntime(staging, source, expected) {
271376
+ fs12.mkdirSync(staging, { recursive: true, mode: 493 });
271377
+ fs12.cpSync(source.packageRoot, path27.join(staging, "package"), {
271378
+ recursive: true,
271379
+ verbatimSymlinks: true
271380
+ });
271381
+ const stagedNode = path27.join(staging, "node");
271382
+ fs12.copyFileSync(source.nodePath, stagedNode);
271383
+ fs12.chmodSync(stagedNode, 493);
271384
+ const actual = hashTree(staging, walk(staging).files);
271385
+ for (const [relative, hash2] of Object.entries(expected)) {
271386
+ if (actual[relative] !== hash2) {
271387
+ throw new Error(`Runtime copy failed verification: ${relative} does not match the source`);
271388
+ }
271389
+ }
271390
+ const manifest = { schemaVersion: 1, version: source.version, files: expected };
271391
+ fs12.writeFileSync(path27.join(staging, MANIFEST_NAME), `${JSON.stringify(manifest)}
271392
+ `);
271393
+ fsyncTree(staging);
271394
+ }
271395
+ function pruneRuntimeVersions(dataDir, keep) {
271396
+ const root = runtimeRoot(dataDir);
271397
+ const keepSet = new Set(keep.filter((value) => Boolean(value)));
271398
+ const current = readCurrentVersion(dataDir);
271399
+ if (current) keepSet.add(current);
271400
+ const removed = [];
271401
+ for (const entry of fs12.readdirSync(root, { withFileTypes: true })) {
271402
+ if (!entry.isDirectory()) continue;
271403
+ const isStaleStaging = entry.name.startsWith(".staging-") && Date.now() - fs12.statSync(path27.join(root, entry.name)).mtimeMs > 60 * 6e4;
271404
+ if (!isStaleStaging && (!VERSION_PATTERN.test(entry.name) || keepSet.has(entry.name))) {
271405
+ continue;
271406
+ }
271407
+ fs12.rmSync(path27.join(root, entry.name), { recursive: true, force: true });
271408
+ removed.push(entry.name);
271409
+ }
271410
+ return removed;
271411
+ }
271412
+
271413
+ // src/connect-service.ts
271118
271414
  var defaultExec = (command, args) => {
271119
271415
  const result = spawnSync(command, args, { encoding: "utf8" });
271120
271416
  if (result.error) {
@@ -271124,17 +271420,17 @@ var defaultExec = (command, args) => {
271124
271420
  };
271125
271421
  function readIfExists(file2) {
271126
271422
  try {
271127
- return fs12.readFileSync(file2, "utf8");
271423
+ return fs13.readFileSync(file2, "utf8");
271128
271424
  } catch {
271129
271425
  return void 0;
271130
271426
  }
271131
271427
  }
271132
271428
  function serviceRecordPath(dataDir) {
271133
- return path27.join(connectConfigDir(dataDir), "service.json");
271429
+ return path28.join(connectConfigDir(dataDir), "service.json");
271134
271430
  }
271135
271431
  function readServiceRecord(dataDir) {
271136
271432
  try {
271137
- const parsed = JSON.parse(fs12.readFileSync(serviceRecordPath(dataDir), "utf8"));
271433
+ const parsed = JSON.parse(fs13.readFileSync(serviceRecordPath(dataDir), "utf8"));
271138
271434
  if (parsed.schemaVersion !== 1 || parsed.kind !== "systemd" && parsed.kind !== "launchd" || typeof parsed.name !== "string") {
271139
271435
  return void 0;
271140
271436
  }
@@ -271155,11 +271451,11 @@ function writeServiceRecord(dataDir, adapter) {
271155
271451
  `, { mode: 384 });
271156
271452
  }
271157
271453
  function removeServiceRecord(dataDir) {
271158
- fs12.rmSync(serviceRecordPath(dataDir), { force: true });
271454
+ fs13.rmSync(serviceRecordPath(dataDir), { force: true });
271159
271455
  }
271160
271456
  function serviceSuffix(dataDir) {
271161
- if (path27.resolve(dataDir) === path27.resolve(VIBEDECKX_HOME)) return "";
271162
- return `-${createHash12("sha256").update(path27.resolve(dataDir)).digest("hex").slice(0, 8)}`;
271457
+ if (path28.resolve(dataDir) === path28.resolve(VIBEDECKX_HOME)) return "";
271458
+ return `-${createHash13("sha256").update(path28.resolve(dataDir)).digest("hex").slice(0, 8)}`;
271163
271459
  }
271164
271460
  function fail(action, result) {
271165
271461
  const detail = (result.stderr || result.stdout).trim();
@@ -271182,8 +271478,7 @@ function renderSystemdUnit(spec, systemdVersion) {
271182
271478
  "",
271183
271479
  "[Service]",
271184
271480
  "Type=simple",
271185
- `ExecStart=${[spec.launcher, "connect", "--data-dir", spec.dataDir].map(systemdQuote).join(" ")}`,
271186
- `Environment=${systemdQuote(`PATH=${spec.pathEnv}`)}`,
271481
+ `ExecStart=${[spec.launcher, SERVICE_ENV_FLAG, "connect", "--data-dir", spec.dataDir].map(systemdQuote).join(" ")}`,
271187
271482
  `Environment=${systemdQuote(`HOME=${spec.home}`)}`,
271188
271483
  'Environment="VIBEDECKX_SUPERVISOR=systemd"',
271189
271484
  'Environment="VIBEDECKX_INSTALL_MODE=native-service"',
@@ -271217,8 +271512,8 @@ var SystemdUserAdapter = class {
271217
271512
  this.env = env;
271218
271513
  this.user = user;
271219
271514
  this.name = `vibedeckx-connect${serviceSuffix(dataDir)}.service`;
271220
- const configHome = env.XDG_CONFIG_HOME || path27.join(env.HOME || os2.homedir(), ".config");
271221
- this.definitionPath = path27.join(configHome, "systemd", "user", this.name);
271515
+ const configHome = env.XDG_CONFIG_HOME || path28.join(env.HOME || os2.homedir(), ".config");
271516
+ this.definitionPath = path28.join(configHome, "systemd", "user", this.name);
271222
271517
  }
271223
271518
  exec;
271224
271519
  env;
@@ -271256,7 +271551,7 @@ var SystemdUserAdapter = class {
271256
271551
  const unit = renderSystemdUnit(spec, this.version);
271257
271552
  const changed = readIfExists(this.definitionPath) !== unit;
271258
271553
  if (changed) {
271259
- fs12.mkdirSync(path27.dirname(this.definitionPath), { recursive: true });
271554
+ fs13.mkdirSync(path28.dirname(this.definitionPath), { recursive: true });
271260
271555
  writeFileAtomic(this.definitionPath, unit);
271261
271556
  this.systemctl(["daemon-reload"], "systemctl --user daemon-reload");
271262
271557
  }
@@ -271280,7 +271575,7 @@ var SystemdUserAdapter = class {
271280
271575
  }
271281
271576
  uninstall() {
271282
271577
  this.exec("systemctl", ["--user", "disable", "--now", this.name]);
271283
- fs12.rmSync(this.definitionPath, { force: true });
271578
+ fs13.rmSync(this.definitionPath, { force: true });
271284
271579
  this.exec("systemctl", ["--user", "daemon-reload"]);
271285
271580
  this.exec("systemctl", ["--user", "reset-failed", this.name]);
271286
271581
  }
@@ -271312,16 +271607,15 @@ function xmlEscape(value) {
271312
271607
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
271313
271608
  }
271314
271609
  function renderLaunchdPlist(label, spec) {
271315
- const args = [spec.launcher, "connect", "--data-dir", spec.dataDir].map((arg) => ` <string>${xmlEscape(arg)}</string>`).join("\n");
271610
+ const args = [spec.launcher, SERVICE_ENV_FLAG, "connect", "--data-dir", spec.dataDir].map((arg) => ` <string>${xmlEscape(arg)}</string>`).join("\n");
271316
271611
  const env = {
271317
- PATH: spec.pathEnv,
271318
271612
  HOME: spec.home,
271319
271613
  VIBEDECKX_SUPERVISOR: "launchd",
271320
271614
  VIBEDECKX_INSTALL_MODE: "native-service"
271321
271615
  };
271322
271616
  const envXml = Object.entries(env).map(([key2, value]) => ` <key>${key2}</key>
271323
271617
  <string>${xmlEscape(value)}</string>`).join("\n");
271324
- const logPath = path27.join(spec.dataDir, "logs", "launchd.log");
271618
+ const logPath = path28.join(spec.dataDir, "logs", "launchd.log");
271325
271619
  return `<?xml version="1.0" encoding="UTF-8"?>
271326
271620
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
271327
271621
  <!-- Generated by \`vibedeckx connect install\`. Do not edit. -->
@@ -271354,14 +271648,21 @@ ${envXml}
271354
271648
  </plist>
271355
271649
  `;
271356
271650
  }
271651
+ var sleepSync = (ms) => {
271652
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
271653
+ };
271654
+ var BOOTOUT_WAIT_MS = 15e3;
271655
+ var BOOTOUT_POLL_MS = 100;
271357
271656
  var LaunchdAgentAdapter = class {
271358
- constructor(dataDir, exec4 = defaultExec, uid = process.getuid?.() ?? 0, home = os2.homedir()) {
271657
+ constructor(dataDir, exec4 = defaultExec, uid = process.getuid?.() ?? 0, home = os2.homedir(), sleep2 = sleepSync) {
271359
271658
  this.exec = exec4;
271659
+ this.sleep = sleep2;
271360
271660
  this.name = `dev.vibedeckx.connect${serviceSuffix(dataDir)}`;
271361
- this.definitionPath = path27.join(home, "Library", "LaunchAgents", `${this.name}.plist`);
271661
+ this.definitionPath = path28.join(home, "Library", "LaunchAgents", `${this.name}.plist`);
271362
271662
  this.domain = `gui/${uid}`;
271363
271663
  }
271364
271664
  exec;
271665
+ sleep;
271365
271666
  kind = "launchd";
271366
271667
  name;
271367
271668
  definitionPath;
@@ -271374,6 +271675,26 @@ var LaunchdAgentAdapter = class {
271374
271675
  if (result.status !== 0) fail(action, result);
271375
271676
  return result;
271376
271677
  }
271678
+ /**
271679
+ * `launchctl bootout` returns while the job is still being torn down: a
271680
+ * `kickstart` then finds no service (113) and a `bootstrap` fails with
271681
+ * "Input/output error" (5). Wait until the job is really gone.
271682
+ */
271683
+ bootout() {
271684
+ if (!this.isLoaded()) return;
271685
+ const result = this.exec("launchctl", ["bootout", this.target]);
271686
+ for (let waited = 0; this.isLoaded(); waited += BOOTOUT_POLL_MS) {
271687
+ if (waited >= BOOTOUT_WAIT_MS) fail(`launchctl bootout ${this.target}`, result);
271688
+ this.sleep(BOOTOUT_POLL_MS);
271689
+ }
271690
+ }
271691
+ /** `print-disabled` says "disabled"/"enabled" (macOS 13+) or "true"/"false" (older). */
271692
+ isEnabled() {
271693
+ const result = this.exec("launchctl", ["print-disabled", this.domain]);
271694
+ const escaped = this.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
271695
+ const match2 = new RegExp(`"${escaped}"\\s*=>\\s*(\\w+)`).exec(result.stdout);
271696
+ return !match2 || match2[1] === "enabled" || match2[1] === "false";
271697
+ }
271377
271698
  preflight() {
271378
271699
  const result = this.exec("launchctl", ["print", this.domain]);
271379
271700
  if (result.status !== 0) {
@@ -271383,12 +271704,12 @@ var LaunchdAgentAdapter = class {
271383
271704
  }
271384
271705
  }
271385
271706
  install(spec) {
271386
- fs12.mkdirSync(path27.dirname(this.definitionPath), { recursive: true });
271387
- fs12.mkdirSync(path27.join(spec.dataDir, "logs"), { recursive: true });
271707
+ fs13.mkdirSync(path28.dirname(this.definitionPath), { recursive: true });
271708
+ fs13.mkdirSync(path28.join(spec.dataDir, "logs"), { recursive: true });
271388
271709
  const plist = renderLaunchdPlist(this.name, spec);
271389
271710
  const changed = readIfExists(this.definitionPath) !== plist;
271390
271711
  if (changed) {
271391
- this.exec("launchctl", ["bootout", this.target]);
271712
+ this.bootout();
271392
271713
  writeFileAtomic(this.definitionPath, plist);
271393
271714
  }
271394
271715
  this.launchctl(["enable", this.target], `launchctl enable ${this.target}`);
@@ -271402,12 +271723,14 @@ var LaunchdAgentAdapter = class {
271402
271723
  this.launchctl(["kickstart", this.target], `launchctl kickstart ${this.target}`);
271403
271724
  return;
271404
271725
  }
271726
+ if (!this.isEnabled()) {
271727
+ throw new Error(`${this.name} is disabled. Run \`vibedeckx connect enable\` to start it.`);
271728
+ }
271405
271729
  this.launchctl(["bootstrap", this.domain, this.definitionPath], `launchctl bootstrap ${this.domain}`);
271406
271730
  }
271407
271731
  /** bootout leaves the plist in place, so it loads again at the next login. */
271408
271732
  stop() {
271409
- if (!this.isLoaded()) return;
271410
- this.launchctl(["bootout", this.target], `launchctl bootout ${this.target}`);
271733
+ this.bootout();
271411
271734
  }
271412
271735
  restart() {
271413
271736
  if (!this.isLoaded()) {
@@ -271425,8 +271748,8 @@ var LaunchdAgentAdapter = class {
271425
271748
  this.stop();
271426
271749
  }
271427
271750
  uninstall() {
271428
- this.exec("launchctl", ["bootout", this.target]);
271429
- fs12.rmSync(this.definitionPath, { force: true });
271751
+ this.bootout();
271752
+ fs13.rmSync(this.definitionPath, { force: true });
271430
271753
  }
271431
271754
  isActive() {
271432
271755
  const result = this.exec("launchctl", ["print", this.target]);
@@ -271457,268 +271780,6 @@ function adapterForRecord(dataDir, record2, options = {}) {
271457
271780
  return record2.kind === "systemd" ? new SystemdUserAdapter(dataDir, options.exec, options.env ?? process.env) : new LaunchdAgentAdapter(dataDir, options.exec, void 0, homeFrom(options.env));
271458
271781
  }
271459
271782
 
271460
- // src/connect-runtime.ts
271461
- import { createHash as createHash13, randomUUID as randomUUID33 } from "node:crypto";
271462
- import fs13 from "node:fs";
271463
- import path28 from "node:path";
271464
- import { fileURLToPath as fileURLToPath3 } from "node:url";
271465
- var LAUNCHER_NAME = "launcher";
271466
- var MANIFEST_NAME = "manifest.json";
271467
- var VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._+-]*$/;
271468
- function runtimeRoot(dataDir) {
271469
- return path28.join(dataDir, "runtime");
271470
- }
271471
- function launcherPath(dataDir) {
271472
- return path28.join(runtimeRoot(dataDir), LAUNCHER_NAME);
271473
- }
271474
- function detectRuntimeSource(options = {}) {
271475
- const entry = fileURLToPath3(options.entryUrl ?? import.meta.url);
271476
- const packageRoot = path28.resolve(path28.dirname(entry), "..");
271477
- return validateRuntimeSource(packageRoot, options.nodePath ?? process.execPath);
271478
- }
271479
- function validateRuntimeSource(packageRoot, nodePath) {
271480
- const notRelease = (reason) => new Error(
271481
- `Cannot install the worker runtime from ${packageRoot}: ${reason}. Run \`vibedeckx connect install\` from an installed release, e.g. \`npx vibedeckx@latest connect install\`.`
271482
- );
271483
- let pkg;
271484
- try {
271485
- pkg = JSON.parse(fs13.readFileSync(path28.join(packageRoot, "package.json"), "utf8"));
271486
- } catch {
271487
- throw notRelease("package.json is missing");
271488
- }
271489
- if (typeof pkg.version !== "string" || !VERSION_PATTERN.test(pkg.version)) {
271490
- throw notRelease("package version is missing or invalid");
271491
- }
271492
- if (!fs13.existsSync(path28.join(packageRoot, "dist", "bin.js"))) {
271493
- throw notRelease("dist/bin.js is missing");
271494
- }
271495
- for (const nativeModule of ["better-sqlite3", "node-pty"]) {
271496
- const modulePath = path28.join(packageRoot, "node_modules", nativeModule);
271497
- let stat3;
271498
- try {
271499
- stat3 = fs13.lstatSync(modulePath);
271500
- } catch {
271501
- throw notRelease(`bundled ${nativeModule} is missing`);
271502
- }
271503
- if (stat3.isSymbolicLink()) {
271504
- throw notRelease(`${nativeModule} is a symlink (source checkout)`);
271505
- }
271506
- }
271507
- return { packageRoot, version: pkg.version, nodePath };
271508
- }
271509
- function sha256File(filePath) {
271510
- const hash2 = createHash13("sha256");
271511
- const fd = fs13.openSync(filePath, "r");
271512
- try {
271513
- const buffer = Buffer.allocUnsafe(1 << 20);
271514
- for (; ; ) {
271515
- const read = fs13.readSync(fd, buffer, 0, buffer.length, null);
271516
- if (read === 0) break;
271517
- hash2.update(buffer.subarray(0, read));
271518
- }
271519
- } finally {
271520
- fs13.closeSync(fd);
271521
- }
271522
- return hash2.digest("hex");
271523
- }
271524
- function walk(root) {
271525
- const files = [];
271526
- const links = [];
271527
- const dirs = [];
271528
- const visit2 = (relative) => {
271529
- const absolute = path28.join(root, relative);
271530
- for (const entry of fs13.readdirSync(absolute, { withFileTypes: true })) {
271531
- const child = relative ? path28.join(relative, entry.name) : entry.name;
271532
- if (entry.isSymbolicLink()) links.push(child);
271533
- else if (entry.isDirectory()) {
271534
- dirs.push(child);
271535
- visit2(child);
271536
- } else if (entry.isFile()) files.push(child);
271537
- }
271538
- };
271539
- visit2("");
271540
- return { files, links, dirs };
271541
- }
271542
- function hashTree(root, relativeFiles) {
271543
- const result = {};
271544
- for (const file2 of relativeFiles) {
271545
- result[file2.split(path28.sep).join("/")] = sha256File(path28.join(root, file2));
271546
- }
271547
- return result;
271548
- }
271549
- function fsyncTree(root) {
271550
- const { files, dirs } = walk(root);
271551
- for (const file2 of files) {
271552
- const fd = fs13.openSync(path28.join(root, file2), "r");
271553
- try {
271554
- fs13.fsyncSync(fd);
271555
- } finally {
271556
- fs13.closeSync(fd);
271557
- }
271558
- }
271559
- for (const dir of [...dirs].reverse()) fsyncDirectory(path28.join(root, dir));
271560
- fsyncDirectory(root);
271561
- }
271562
- function readManifest(versionDir) {
271563
- try {
271564
- const parsed = JSON.parse(
271565
- fs13.readFileSync(path28.join(versionDir, MANIFEST_NAME), "utf8")
271566
- );
271567
- if (parsed.schemaVersion !== 1 || typeof parsed.files !== "object") return void 0;
271568
- return parsed;
271569
- } catch {
271570
- return void 0;
271571
- }
271572
- }
271573
- function verifyRuntimeVersion(versionDir) {
271574
- const manifest = readManifest(versionDir);
271575
- if (!manifest) return false;
271576
- for (const [relative, expected] of Object.entries(manifest.files)) {
271577
- const absolute = path28.join(versionDir, ...relative.split("/"));
271578
- try {
271579
- if (sha256File(absolute) !== expected) return false;
271580
- } catch {
271581
- return false;
271582
- }
271583
- }
271584
- return true;
271585
- }
271586
- function readCurrentVersion(dataDir) {
271587
- try {
271588
- const value = fs13.readFileSync(path28.join(runtimeRoot(dataDir), "current"), "utf8").trim();
271589
- return VERSION_PATTERN.test(value) ? value : void 0;
271590
- } catch {
271591
- return void 0;
271592
- }
271593
- }
271594
- function readPreviousVersion(dataDir) {
271595
- try {
271596
- const value = fs13.readFileSync(path28.join(runtimeRoot(dataDir), "previous"), "utf8").trim();
271597
- return VERSION_PATTERN.test(value) ? value : void 0;
271598
- } catch {
271599
- return void 0;
271600
- }
271601
- }
271602
- function renderLauncher() {
271603
- return `#!/bin/sh
271604
- # Generated by \`vibedeckx connect install\`. Do not edit.
271605
- set -eu
271606
- RUNTIME_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
271607
- VERSION=$(cat "$RUNTIME_ROOT/current" 2>/dev/null || true)
271608
- case "$VERSION" in
271609
- ''|*[!0-9A-Za-z._+-]*) echo "vibedeckx launcher: invalid or missing $RUNTIME_ROOT/current" >&2; exit 78 ;;
271610
- esac
271611
- VERSION_DIR="$RUNTIME_ROOT/$VERSION"
271612
- if [ ! -x "$VERSION_DIR/node" ] || [ ! -f "$VERSION_DIR/package/dist/bin.js" ]; then
271613
- echo "vibedeckx launcher: runtime $VERSION_DIR is incomplete" >&2
271614
- exit 78
271615
- fi
271616
- export VIBEDECKX_RUNTIME_DIR="$VERSION_DIR"
271617
- exec "$VERSION_DIR/node" "$VERSION_DIR/package/dist/bin.js" "$@"
271618
- `;
271619
- }
271620
- function installRuntime(dataDir, source) {
271621
- if (process.platform === "win32") {
271622
- throw new Error("The installed worker runtime is not supported on Windows yet");
271623
- }
271624
- if (!VERSION_PATTERN.test(source.version)) {
271625
- throw new Error(`Invalid runtime version: ${source.version}`);
271626
- }
271627
- const root = runtimeRoot(dataDir);
271628
- fs13.mkdirSync(root, { recursive: true, mode: 493 });
271629
- const expected = sourceManifestFiles(source);
271630
- const buildId = `${source.version}+${buildHash(expected)}`;
271631
- let versionDir = path28.join(root, buildId);
271632
- let copied = false;
271633
- if (!isInstalledCopyOf(versionDir, expected)) {
271634
- if (fs13.existsSync(versionDir)) {
271635
- versionDir = path28.join(root, `${buildId}.r${randomUUID33().slice(0, 8)}`);
271636
- }
271637
- const staging = path28.join(root, `.staging-${buildId}-${randomUUID33()}`);
271638
- try {
271639
- stageRuntime(staging, source, expected);
271640
- fs13.renameSync(staging, versionDir);
271641
- fsyncDirectory(root);
271642
- copied = true;
271643
- } finally {
271644
- fs13.rmSync(staging, { recursive: true, force: true });
271645
- }
271646
- }
271647
- const installedId = path28.basename(versionDir);
271648
- const launcher = launcherPath(dataDir);
271649
- writeFileAtomic(launcher, renderLauncher(), { mode: 493 });
271650
- const before = readCurrentVersion(dataDir);
271651
- if (before !== installedId) {
271652
- if (before) writeFileAtomic(path28.join(root, "previous"), `${before}
271653
- `);
271654
- writeFileAtomic(path28.join(root, "current"), `${installedId}
271655
- `);
271656
- }
271657
- const previous = before !== installedId ? before : readPreviousVersion(dataDir);
271658
- const pruned = pruneRuntimeVersions(dataDir, [installedId, previous]);
271659
- return { version: source.version, buildId: installedId, versionDir, launcher, copied, previous, pruned };
271660
- }
271661
- function buildHash(files) {
271662
- const hash2 = createHash13("sha256");
271663
- for (const relative of Object.keys(files).sort()) hash2.update(`${relative}\0${files[relative]}
271664
- `);
271665
- return hash2.digest("hex").slice(0, 12);
271666
- }
271667
- function sourceManifestFiles(source) {
271668
- const expected = {};
271669
- const packageTree = walk(source.packageRoot);
271670
- for (const [relative, hash2] of Object.entries(hashTree(source.packageRoot, packageTree.files))) {
271671
- expected[`package/${relative}`] = hash2;
271672
- }
271673
- expected.node = sha256File(source.nodePath);
271674
- return expected;
271675
- }
271676
- function isInstalledCopyOf(versionDir, expected) {
271677
- const manifest = readManifest(versionDir);
271678
- if (!manifest) return false;
271679
- const installed = Object.entries(manifest.files);
271680
- if (installed.length !== Object.keys(expected).length) return false;
271681
- if (installed.some(([relative, hash2]) => expected[relative] !== hash2)) return false;
271682
- return verifyRuntimeVersion(versionDir);
271683
- }
271684
- function stageRuntime(staging, source, expected) {
271685
- fs13.mkdirSync(staging, { recursive: true, mode: 493 });
271686
- fs13.cpSync(source.packageRoot, path28.join(staging, "package"), {
271687
- recursive: true,
271688
- verbatimSymlinks: true
271689
- });
271690
- const stagedNode = path28.join(staging, "node");
271691
- fs13.copyFileSync(source.nodePath, stagedNode);
271692
- fs13.chmodSync(stagedNode, 493);
271693
- const actual = hashTree(staging, walk(staging).files);
271694
- for (const [relative, hash2] of Object.entries(expected)) {
271695
- if (actual[relative] !== hash2) {
271696
- throw new Error(`Runtime copy failed verification: ${relative} does not match the source`);
271697
- }
271698
- }
271699
- const manifest = { schemaVersion: 1, version: source.version, files: expected };
271700
- fs13.writeFileSync(path28.join(staging, MANIFEST_NAME), `${JSON.stringify(manifest)}
271701
- `);
271702
- fsyncTree(staging);
271703
- }
271704
- function pruneRuntimeVersions(dataDir, keep) {
271705
- const root = runtimeRoot(dataDir);
271706
- const keepSet = new Set(keep.filter((value) => Boolean(value)));
271707
- const current = readCurrentVersion(dataDir);
271708
- if (current) keepSet.add(current);
271709
- const removed = [];
271710
- for (const entry of fs13.readdirSync(root, { withFileTypes: true })) {
271711
- if (!entry.isDirectory()) continue;
271712
- const isStaleStaging = entry.name.startsWith(".staging-") && Date.now() - fs13.statSync(path28.join(root, entry.name)).mtimeMs > 60 * 6e4;
271713
- if (!isStaleStaging && (!VERSION_PATTERN.test(entry.name) || keepSet.has(entry.name))) {
271714
- continue;
271715
- }
271716
- fs13.rmSync(path28.join(root, entry.name), { recursive: true, force: true });
271717
- removed.push(entry.name);
271718
- }
271719
- return removed;
271720
- }
271721
-
271722
271783
  // src/connect-shim.ts
271723
271784
  import fs14 from "node:fs";
271724
271785
  import path29 from "node:path";
@@ -271932,7 +271993,7 @@ function describeService(dataDir, exec4) {
271932
271993
  if (!record2) return void 0;
271933
271994
  const adapter = adapterForRecord(dataDir, record2, { exec: exec4 });
271934
271995
  let autoStart = "";
271935
- if (adapter instanceof SystemdUserAdapter) {
271996
+ if (adapter instanceof SystemdUserAdapter || adapter instanceof LaunchdAgentAdapter) {
271936
271997
  autoStart = adapter.isEnabled() ? ", auto-start enabled" : ", auto-start disabled";
271937
271998
  }
271938
271999
  return `Service: ${record2.kind} (${record2.name}${autoStart})`;
@@ -272183,9 +272244,11 @@ async function installService(options) {
272183
272244
  return false;
272184
272245
  }
272185
272246
  })();
272247
+ let envChanged;
272186
272248
  let definitionChanged;
272187
272249
  try {
272188
- definitionChanged = adapter.install({ dataDir, launcher, pathEnv, home: env.HOME ?? os3.homedir() });
272250
+ envChanged = writeServiceEnv(dataDir, pathEnv);
272251
+ definitionChanged = adapter.install({ dataDir, launcher, home: env.HOME ?? os3.homedir() });
272189
272252
  writeServiceRecord(dataDir, adapter);
272190
272253
  } catch (error48) {
272191
272254
  return failed(`Writing the service definition failed: ${errorMessage(error48)}`);
@@ -272205,7 +272268,7 @@ async function installService(options) {
272205
272268
  }
272206
272269
  if (wasActive) {
272207
272270
  const running = readWorkerStatus(dataDir);
272208
- const upToDate = !runtimeChanged && !definitionChanged && !options.force && readIfExists2(savedConfigPath(dataDir)) === configBefore && readIfExists2(savedTokenPath(dataDir)) === tokenBefore && // A worker left on an older build (e.g. an earlier restart failed).
272271
+ const upToDate = !runtimeChanged && !envChanged && !definitionChanged && !options.force && readIfExists2(savedConfigPath(dataDir)) === configBefore && readIfExists2(savedTokenPath(dataDir)) === tokenBefore && // A worker left on an older build (e.g. an earlier restart failed).
272209
272272
  (running === void 0 || running.version === runtimeVersion);
272210
272273
  if (upToDate) {
272211
272274
  const state = running && judgeLiveness(running, running.pid)?.live ? running : void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibedeckx/darwin-arm64",
3
- "version": "0.3.52",
3
+ "version": "0.3.53",
4
4
  "description": "Vibedeckx platform binaries for macOS ARM64",
5
5
  "repository": {
6
6
  "type": "git",