@moxt-ai/cli 0.8.1 → 0.8.2

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/index.cjs CHANGED
@@ -5650,6 +5650,175 @@ var init_local_ipc = __esm({
5650
5650
  });
5651
5651
 
5652
5652
  // ../machine-connector/dist/runtime/process-lock.js
5653
+ async function createCompleteLock(path4, record2) {
5654
+ await (0, import_promises7.mkdir)(path4, { mode: 448 });
5655
+ let metadata;
5656
+ try {
5657
+ metadata = await (0, import_promises7.stat)(path4);
5658
+ } catch (error) {
5659
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "ENOTDIR")) {
5660
+ throw nodeError("EEXIST", "Lock directory changed while publishing");
5661
+ }
5662
+ throw error;
5663
+ }
5664
+ const ownerPath = (0, import_node_path5.join)(path4, `${metadata.dev}.${metadata.ino}.${record2.pid}.${record2.token}.owner`);
5665
+ try {
5666
+ await (0, import_promises7.writeFile)(ownerPath, `${JSON.stringify(record2)}
5667
+ `, {
5668
+ encoding: "utf8",
5669
+ flag: "wx",
5670
+ mode: 384
5671
+ });
5672
+ let current2;
5673
+ try {
5674
+ current2 = await (0, import_promises7.stat)(path4);
5675
+ } catch (error) {
5676
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "ENOTDIR")) {
5677
+ throw nodeError("EEXIST", "Lock directory changed while publishing");
5678
+ }
5679
+ throw error;
5680
+ }
5681
+ if (!sameDirectoryIdentity(metadata, current2)) {
5682
+ throw nodeError("EEXIST", "Lock directory was replaced while publishing");
5683
+ }
5684
+ return ownerPath;
5685
+ } catch (error) {
5686
+ await removeFileIfPresent(ownerPath);
5687
+ await removeEmptyDirectory(path4);
5688
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "ENOTDIR")) {
5689
+ throw nodeError("EEXIST", "Lock directory changed while publishing");
5690
+ }
5691
+ throw error;
5692
+ }
5693
+ }
5694
+ async function readLockState(path4) {
5695
+ let metadata;
5696
+ try {
5697
+ metadata = await (0, import_promises7.stat)(path4);
5698
+ } catch (error) {
5699
+ if (isNodeErrorCode2(error, "ENOENT"))
5700
+ return void 0;
5701
+ throw error;
5702
+ }
5703
+ if (!metadata.isDirectory()) {
5704
+ return {
5705
+ metadata,
5706
+ record: await readRecord(path4)
5707
+ };
5708
+ }
5709
+ const ownerPrefix = `${metadata.dev}.${metadata.ino}.`;
5710
+ let names;
5711
+ try {
5712
+ names = await (0, import_promises7.readdir)(path4);
5713
+ } catch (error) {
5714
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "ENOTDIR")) {
5715
+ return void 0;
5716
+ }
5717
+ throw error;
5718
+ }
5719
+ const ownerName = names.find((name) => name.startsWith(ownerPrefix) && name.endsWith(".owner"));
5720
+ if (!ownerName)
5721
+ return { metadata };
5722
+ const ownerPath = (0, import_node_path5.join)(path4, ownerName);
5723
+ return {
5724
+ metadata,
5725
+ ownerPath,
5726
+ record: await readRecord(ownerPath)
5727
+ };
5728
+ }
5729
+ async function readRecord(path4) {
5730
+ try {
5731
+ const parsed = JSON.parse(await (0, import_promises7.readFile)(path4, "utf8"));
5732
+ if (typeof parsed.createdAt !== "number" || !Number.isFinite(parsed.createdAt) || typeof parsed.pid !== "number" || !Number.isSafeInteger(parsed.pid) || parsed.pid <= 0 || typeof parsed.token !== "string" || parsed.token.length === 0) {
5733
+ return void 0;
5734
+ }
5735
+ return parsed;
5736
+ } catch (error) {
5737
+ if (isNodeErrorCode2(error, "ENOENT"))
5738
+ return void 0;
5739
+ if (error instanceof SyntaxError)
5740
+ return void 0;
5741
+ throw error;
5742
+ }
5743
+ }
5744
+ async function removeLockIfTokenMatches(path4, token) {
5745
+ const state = await readLockState(path4);
5746
+ if (state?.record?.token !== token)
5747
+ return;
5748
+ if (state.ownerPath) {
5749
+ await removeOwnedDirectoryLock(path4, state.ownerPath, token);
5750
+ return;
5751
+ }
5752
+ try {
5753
+ await (0, import_promises7.rm)(path4);
5754
+ } catch (error) {
5755
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "EISDIR") || isNodeErrorCode2(error, "ERR_FS_EISDIR") || isNodeErrorCode2(error, "EPERM")) {
5756
+ return;
5757
+ }
5758
+ throw error;
5759
+ }
5760
+ }
5761
+ async function removeOwnedDirectoryLock(path4, ownerPath, token) {
5762
+ if ((await readRecord(ownerPath))?.token !== token)
5763
+ return;
5764
+ await removeFileIfPresent(ownerPath);
5765
+ await removeEmptyDirectory(path4);
5766
+ }
5767
+ async function removeStaleIncompleteLock(path4, metadata) {
5768
+ if (Date.now() - Number(metadata.mtimeMs) < incompleteLockStaleMilliseconds) {
5769
+ return false;
5770
+ }
5771
+ const current2 = await readLockState(path4);
5772
+ if (!current2 || current2.record || !sameFileMetadata(metadata, current2.metadata)) {
5773
+ return false;
5774
+ }
5775
+ if (!metadata.isDirectory()) {
5776
+ try {
5777
+ await (0, import_promises7.rm)(path4);
5778
+ return true;
5779
+ } catch (error) {
5780
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "EISDIR") || isNodeErrorCode2(error, "ERR_FS_EISDIR") || isNodeErrorCode2(error, "EPERM")) {
5781
+ return false;
5782
+ }
5783
+ throw error;
5784
+ }
5785
+ }
5786
+ const ownerPrefix = `${metadata.dev}.${metadata.ino}.`;
5787
+ let names;
5788
+ try {
5789
+ names = await (0, import_promises7.readdir)(path4);
5790
+ } catch (error) {
5791
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "ENOTDIR")) {
5792
+ return false;
5793
+ }
5794
+ throw error;
5795
+ }
5796
+ const ownerNames = names.filter((name) => name.startsWith(ownerPrefix) && name.endsWith(".owner"));
5797
+ const deadOwnerNames = [];
5798
+ for (const name of ownerNames) {
5799
+ const ownerProcessId = directoryOwnerProcessId(ownerPrefix, name);
5800
+ if (ownerProcessId === void 0 || processIsAlive(ownerProcessId)) {
5801
+ return false;
5802
+ }
5803
+ deadOwnerNames.push(name);
5804
+ }
5805
+ for (const name of deadOwnerNames) {
5806
+ await removeFileIfPresent((0, import_node_path5.join)(path4, name));
5807
+ }
5808
+ return await removeEmptyDirectory(path4);
5809
+ }
5810
+ function directoryOwnerProcessId(ownerPrefix, ownerName) {
5811
+ const identity = ownerName.slice(ownerPrefix.length, -".owner".length);
5812
+ const separator = identity.indexOf(".");
5813
+ if (separator <= 0)
5814
+ return void 0;
5815
+ const processId = Number(identity.slice(0, separator));
5816
+ const token = identity.slice(separator + 1);
5817
+ if (!Number.isSafeInteger(processId) || processId <= 0 || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(token)) {
5818
+ return void 0;
5819
+ }
5820
+ return processId;
5821
+ }
5653
5822
  async function removeStalePendingLockCandidates(path4) {
5654
5823
  const directory = (0, import_node_path5.dirname)(path4);
5655
5824
  const lockName = (0, import_node_path5.basename)(path4);
@@ -5688,7 +5857,7 @@ async function removeOldUnchangedFile(path4) {
5688
5857
  } catch (error) {
5689
5858
  return isNodeErrorCode2(error, "ENOENT");
5690
5859
  }
5691
- if (Date.now() - metadata.mtimeMs < incompleteLockStaleMilliseconds) {
5860
+ if (Date.now() - Number(metadata.mtimeMs) < incompleteLockStaleMilliseconds) {
5692
5861
  return false;
5693
5862
  }
5694
5863
  let current2;
@@ -5702,62 +5871,29 @@ async function removeOldUnchangedFile(path4) {
5702
5871
  await (0, import_promises7.rm)(path4, { force: true });
5703
5872
  return true;
5704
5873
  }
5705
- async function createCompleteLock(path4, record2) {
5706
- const candidatePath = `${path4}.${record2.pid}.${record2.token}.pending`;
5874
+ async function removeEmptyDirectory(path4) {
5707
5875
  try {
5708
- await (0, import_promises7.writeFile)(candidatePath, `${JSON.stringify(record2)}
5709
- `, {
5710
- encoding: "utf8",
5711
- flag: "wx",
5712
- mode: 384
5713
- });
5714
- await (0, import_promises7.link)(candidatePath, path4);
5715
- } finally {
5716
- await (0, import_promises7.rm)(candidatePath, { force: true });
5717
- }
5718
- }
5719
- async function readLockRecord(path4) {
5720
- try {
5721
- const parsed = JSON.parse(await (0, import_promises7.readFile)(path4, "utf8"));
5722
- if (typeof parsed.createdAt !== "number" || !Number.isFinite(parsed.createdAt) || typeof parsed.pid !== "number" || !Number.isSafeInteger(parsed.pid) || parsed.pid <= 0 || typeof parsed.token !== "string" || parsed.token.length === 0) {
5723
- return void 0;
5724
- }
5725
- return parsed;
5876
+ await (0, import_promises7.rmdir)(path4);
5877
+ return true;
5726
5878
  } catch (error) {
5727
- if (isNodeErrorCode2(error, "ENOENT"))
5728
- return void 0;
5729
- if (error instanceof SyntaxError)
5730
- return void 0;
5879
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "ENOTEMPTY") || isNodeErrorCode2(error, "EEXIST") || isNodeErrorCode2(error, "ENOTDIR")) {
5880
+ return false;
5881
+ }
5731
5882
  throw error;
5732
5883
  }
5733
5884
  }
5734
- async function removeLockIfTokenMatches(path4, token) {
5735
- const current2 = await readLockRecord(path4);
5736
- if (current2?.token === token)
5737
- await (0, import_promises7.rm)(path4, { force: true });
5738
- }
5739
- async function removeStaleIncompleteLock(path4) {
5740
- let metadata;
5741
- try {
5742
- metadata = await (0, import_promises7.stat)(path4);
5743
- } catch (error) {
5744
- return isNodeErrorCode2(error, "ENOENT");
5745
- }
5746
- if (Date.now() - metadata.mtimeMs < incompleteLockStaleMilliseconds) {
5747
- return false;
5748
- }
5749
- if (await readLockRecord(path4))
5750
- return false;
5751
- let current2;
5885
+ async function removeFileIfPresent(path4) {
5752
5886
  try {
5753
- current2 = await (0, import_promises7.stat)(path4);
5887
+ await (0, import_promises7.rm)(path4, { force: true });
5754
5888
  } catch (error) {
5755
- return isNodeErrorCode2(error, "ENOENT");
5889
+ if (isNodeErrorCode2(error, "ENOENT") || isNodeErrorCode2(error, "ENOTDIR")) {
5890
+ return;
5891
+ }
5892
+ throw error;
5756
5893
  }
5757
- if (!sameFileMetadata(metadata, current2))
5758
- return false;
5759
- await (0, import_promises7.rm)(path4, { force: true });
5760
- return true;
5894
+ }
5895
+ function sameDirectoryIdentity(first, second) {
5896
+ return first.isDirectory() && second.isDirectory() && first.dev === second.dev && first.ino === second.ino;
5761
5897
  }
5762
5898
  function sameFileMetadata(first, second) {
5763
5899
  return first.dev === second.dev && first.ino === second.ino && first.mtimeMs === second.mtimeMs && first.size === second.size;
@@ -5773,6 +5909,9 @@ function processIsAlive(pid) {
5773
5909
  function isNodeErrorCode2(error, expectedCode) {
5774
5910
  return error instanceof Error && "code" in error && error.code === expectedCode;
5775
5911
  }
5912
+ function nodeError(code, message) {
5913
+ return Object.assign(new Error(message), { code });
5914
+ }
5776
5915
  function delay3(milliseconds) {
5777
5916
  return new Promise((resolvePromise) => setTimeout(resolvePromise, milliseconds));
5778
5917
  }
@@ -5787,10 +5926,12 @@ var init_process_lock = __esm({
5787
5926
  incompleteLockStaleMilliseconds = 3e4;
5788
5927
  ProcessLock = class _ProcessLock {
5789
5928
  path;
5929
+ ownerPath;
5790
5930
  token;
5791
5931
  released = false;
5792
- constructor(path4, token) {
5932
+ constructor(path4, ownerPath, token) {
5793
5933
  this.path = path4;
5934
+ this.ownerPath = ownerPath;
5794
5935
  this.token = token;
5795
5936
  }
5796
5937
  static async acquire(path4, options) {
@@ -5799,22 +5940,22 @@ var init_process_lock = __esm({
5799
5940
  const token = (0, import_node_crypto4.randomUUID)();
5800
5941
  while (true) {
5801
5942
  try {
5802
- await createCompleteLock(path4, {
5943
+ const ownerPath = await createCompleteLock(path4, {
5803
5944
  createdAt: Date.now(),
5804
5945
  pid: process.pid,
5805
5946
  token
5806
5947
  });
5807
- return new _ProcessLock(path4, token);
5948
+ return new _ProcessLock(path4, ownerPath, token);
5808
5949
  } catch (error) {
5809
5950
  if (!isNodeErrorCode2(error, "EEXIST"))
5810
5951
  throw error;
5811
5952
  }
5812
- const existing = await readLockRecord(path4);
5813
- if (existing && !processIsAlive(existing.pid)) {
5814
- await removeLockIfTokenMatches(path4, existing.token);
5953
+ const existing = await readLockState(path4);
5954
+ if (existing?.record && !processIsAlive(existing.record.pid)) {
5955
+ await removeLockIfTokenMatches(path4, existing.record.token);
5815
5956
  continue;
5816
5957
  }
5817
- if (!existing && await removeStaleIncompleteLock(path4)) {
5958
+ if (existing && !existing.record && await removeStaleIncompleteLock(path4, existing.metadata)) {
5818
5959
  continue;
5819
5960
  }
5820
5961
  if (Date.now() >= deadline)
@@ -5826,7 +5967,7 @@ var init_process_lock = __esm({
5826
5967
  if (this.released)
5827
5968
  return;
5828
5969
  this.released = true;
5829
- await removeLockIfTokenMatches(this.path, this.token);
5970
+ await removeOwnedDirectoryLock(this.path, this.ownerPath, this.token);
5830
5971
  }
5831
5972
  };
5832
5973
  }
@@ -6358,6 +6499,10 @@ var init_daemon = __esm({
6358
6499
  connections = [];
6359
6500
  daemonLock;
6360
6501
  ipcServer;
6502
+ lifetimeSettled;
6503
+ settleLifetime;
6504
+ startupSettled;
6505
+ settleStartup;
6361
6506
  stopping = false;
6362
6507
  leaseSafetyMarginMilliseconds;
6363
6508
  leaseSeconds;
@@ -6367,6 +6512,12 @@ var init_daemon = __esm({
6367
6512
  cliVersion;
6368
6513
  constructor(store = new MachineRuntimeStore(), options = {}) {
6369
6514
  this.store = store;
6515
+ this.lifetimeSettled = new Promise((resolvePromise) => {
6516
+ this.settleLifetime = resolvePromise;
6517
+ });
6518
+ this.startupSettled = new Promise((resolvePromise) => {
6519
+ this.settleStartup = resolvePromise;
6520
+ });
6370
6521
  this.logger = new RuntimeLogger(store);
6371
6522
  this.cliVersion = options.cliVersion;
6372
6523
  this.leaseSafetyMarginMilliseconds = options.leaseSafetyMarginMilliseconds ?? defaultLeaseSafetyMarginMilliseconds;
@@ -6376,36 +6527,51 @@ var init_daemon = __esm({
6376
6527
  this.terminalForegroundBudgetMilliseconds = options.terminalForegroundBudgetMilliseconds ?? defaultTerminalForegroundBudgetMilliseconds;
6377
6528
  }
6378
6529
  async start() {
6379
- if (process.getuid?.() === 0) {
6380
- throw new Error("Moxt Machine Connector must run as an unprivileged user");
6381
- }
6382
- await this.store.initialize();
6383
- this.daemonLock = await ProcessLock.acquire(this.store.daemonLockPath(), { timeoutMilliseconds: 1e3 });
6384
- if (!this.daemonLock) {
6385
- throw new Error("Another Moxt Machine Connector daemon is already running or starting");
6386
- }
6387
6530
  try {
6531
+ if (process.getuid?.() === 0) {
6532
+ throw new Error("Moxt Machine Connector must run as an unprivileged user");
6533
+ }
6534
+ await this.store.initialize();
6535
+ this.throwIfStopping();
6536
+ this.daemonLock = await ProcessLock.acquire(this.store.daemonLockPath(), { timeoutMilliseconds: 1e3 });
6537
+ if (!this.daemonLock) {
6538
+ throw new Error("Another Moxt Machine Connector daemon is already running or starting");
6539
+ }
6540
+ this.throwIfStopping();
6388
6541
  await this.recoverInterruptedJobs();
6542
+ this.throwIfStopping();
6389
6543
  this.ipcServer = new LocalIpcServer(this.store, () => this.getStatus());
6390
6544
  await this.ipcServer.start();
6545
+ this.throwIfStopping();
6391
6546
  await this.logger.info("Moxt Machine Connector started", {
6392
6547
  connectorInstanceId: this.connectorInstanceId,
6393
6548
  hostname: (0, import_node_os4.hostname)(),
6394
6549
  version: connectorVersion
6395
6550
  });
6396
6551
  this.connections = await this.store.listConnections();
6552
+ this.throwIfStopping();
6397
6553
  if (this.connections.length === 0) {
6398
6554
  await this.logger.info("No Local Machine connections are configured");
6399
6555
  }
6556
+ this.settleStartup();
6400
6557
  await Promise.all(this.connections.map(async (connection) => {
6401
6558
  await this.runConnection(connection);
6402
6559
  }));
6403
6560
  await this.waitForExecutionTasks();
6404
6561
  } catch (error) {
6405
- await this.ipcServer?.close();
6406
- this.ipcServer = void 0;
6407
- await this.releaseDaemonLock();
6562
+ try {
6563
+ await this.ipcServer?.close();
6564
+ } finally {
6565
+ this.ipcServer = void 0;
6566
+ try {
6567
+ await this.releaseDaemonLock();
6568
+ } finally {
6569
+ this.settleStartup();
6570
+ }
6571
+ }
6408
6572
  throw error;
6573
+ } finally {
6574
+ this.settleLifetime();
6409
6575
  }
6410
6576
  }
6411
6577
  async stop() {
@@ -6413,10 +6579,15 @@ var init_daemon = __esm({
6413
6579
  await Promise.all([...this.activeJobs.values()].map(async (activeJob) => {
6414
6580
  await activeJob.cancellation.request(ExecutionCancellationReason.Stopping);
6415
6581
  }));
6582
+ await this.startupSettled;
6416
6583
  await this.ipcServer?.close();
6417
6584
  this.ipcServer = void 0;
6418
- await this.releaseDaemonLock();
6419
- await this.logger.info("Moxt Machine Connector stopped");
6585
+ await this.lifetimeSettled;
6586
+ try {
6587
+ await this.logger.info("Moxt Machine Connector stopped");
6588
+ } finally {
6589
+ await this.releaseDaemonLock();
6590
+ }
6420
6591
  }
6421
6592
  getStatus() {
6422
6593
  return {
@@ -7012,6 +7183,11 @@ var init_daemon = __esm({
7012
7183
  await this.daemonLock?.release();
7013
7184
  this.daemonLock = void 0;
7014
7185
  }
7186
+ throwIfStopping() {
7187
+ if (this.stopping) {
7188
+ throw new Error("Moxt Machine Connector stopped during startup");
7189
+ }
7190
+ }
7015
7191
  async recoverInterruptedJobs() {
7016
7192
  const jobs = await this.store.listJobs();
7017
7193
  for (const job of jobs) {
@@ -7265,39 +7441,35 @@ async function refreshManagedUserService(store, options, runtime = defaultServic
7265
7441
  return { manager, rollback };
7266
7442
  }
7267
7443
  async function managedServiceOwnsProcess(manager, processId, store, runtime = defaultServiceManagerRuntime) {
7268
- try {
7269
- if (manager === UserServiceManager.Launchd) {
7270
- const result = await runtime.run("launchctl", [
7271
- "print",
7272
- `gui/${process.getuid?.() ?? 0}/${launchAgentLabel}`
7273
- ]);
7274
- const match = /(?:^|\s)pid\s*=\s*(\d+)(?:\s|$)/m.exec(result.stdout);
7275
- return match ? Number(match[1]) === processId : false;
7276
- }
7277
- if (manager === UserServiceManager.Systemd) {
7278
- const result = await runtime.run("systemctl", [
7279
- "--user",
7280
- "show",
7281
- "--property",
7282
- "MainPID",
7283
- "--value",
7284
- "moxt-machine-connector.service"
7285
- ]);
7286
- return parseProcessId(result.stdout) === processId;
7287
- }
7288
- if (manager === UserServiceManager.Supervisor) {
7289
- const result = await runtime.run("supervisorctl", [
7290
- "-c",
7291
- supervisorConfigPath(store),
7292
- "pid",
7293
- supervisorProgramName
7294
- ]);
7295
- return parseProcessId(result.stdout) === processId;
7296
- }
7297
- return false;
7298
- } catch {
7299
- return false;
7444
+ if (manager === UserServiceManager.Launchd) {
7445
+ const result = await runServiceProbe(runtime, "launchctl", [
7446
+ "print",
7447
+ `gui/${process.getuid?.() ?? 0}/${launchAgentLabel}`
7448
+ ]);
7449
+ const match = /(?:^|\s)pid\s*=\s*(\d+)(?:\s|$)/m.exec(result.stdout);
7450
+ return match ? Number(match[1]) === processId : false;
7300
7451
  }
7452
+ if (manager === UserServiceManager.Systemd) {
7453
+ const result = await runServiceProbe(runtime, "systemctl", [
7454
+ "--user",
7455
+ "show",
7456
+ "--property",
7457
+ "MainPID",
7458
+ "--value",
7459
+ "moxt-machine-connector.service"
7460
+ ]);
7461
+ return parseProcessId(result.stdout) === processId;
7462
+ }
7463
+ if (manager === UserServiceManager.Supervisor) {
7464
+ const result = await runServiceProbe(runtime, "supervisorctl", [
7465
+ "-c",
7466
+ supervisorConfigPath(store),
7467
+ "pid",
7468
+ supervisorProgramName
7469
+ ]);
7470
+ return parseProcessId(result.stdout) === processId;
7471
+ }
7472
+ return false;
7301
7473
  }
7302
7474
  async function recordedServiceManager(store) {
7303
7475
  return await readStoredServiceManager(store);
@@ -7481,8 +7653,7 @@ async function restoreManagedServiceDefinition(manager, store, definition2, runt
7481
7653
  } else if (manager === UserServiceManager.Systemd) {
7482
7654
  await runtime.run("systemctl", ["--user", "daemon-reload"]);
7483
7655
  } else if (manager === UserServiceManager.Supervisor) {
7484
- await runtime.run("supervisorctl", ["-c", path4, "reread"]);
7485
- await runtime.run("supervisorctl", ["-c", path4, "update"]);
7656
+ await reloadSupervisorConfiguration(store, runtime);
7486
7657
  return;
7487
7658
  }
7488
7659
  await restartManager(manager, store, runtime);
@@ -7646,8 +7817,7 @@ async function installSupervisorUserService(store, options, runtime) {
7646
7817
  await waitForSupervisorControl(store, runtime);
7647
7818
  return;
7648
7819
  }
7649
- await runtime.run("supervisorctl", ["-c", configPath, "reread"]);
7650
- await runtime.run("supervisorctl", ["-c", configPath, "update"]);
7820
+ await reloadSupervisorConfiguration(store, runtime);
7651
7821
  }
7652
7822
  function createSupervisorConfiguration(store, options) {
7653
7823
  const command = [
@@ -7719,6 +7889,43 @@ async function restartSupervisorUserService(store, runtime) {
7719
7889
  ]);
7720
7890
  }
7721
7891
  }
7892
+ async function reloadSupervisorConfiguration(store, runtime) {
7893
+ const configPath = supervisorConfigPath(store);
7894
+ const processIdBeforeStop = await runServiceProbe(runtime, "supervisorctl", [
7895
+ "-c",
7896
+ configPath,
7897
+ "pid",
7898
+ supervisorProgramName
7899
+ ]);
7900
+ if ((parseProcessId(processIdBeforeStop.stdout) ?? 0) > 0) {
7901
+ await runtime.run("supervisorctl", [
7902
+ "-c",
7903
+ configPath,
7904
+ "stop",
7905
+ supervisorProgramName
7906
+ ]);
7907
+ const processIdAfterStop = await runServiceProbe(runtime, "supervisorctl", ["-c", configPath, "pid", supervisorProgramName]);
7908
+ if ((parseProcessId(processIdAfterStop.stdout) ?? 0) > 0) {
7909
+ throw new Error("Supervisor did not stop the existing Moxt Machine Connector process");
7910
+ }
7911
+ }
7912
+ await runtime.run("supervisorctl", ["-c", configPath, "reread"]);
7913
+ await runtime.run("supervisorctl", ["-c", configPath, "update"]);
7914
+ const processId = await runServiceProbe(runtime, "supervisorctl", [
7915
+ "-c",
7916
+ configPath,
7917
+ "pid",
7918
+ supervisorProgramName
7919
+ ]);
7920
+ if ((parseProcessId(processId.stdout) ?? 0) > 0)
7921
+ return;
7922
+ await runtime.run("supervisorctl", [
7923
+ "-c",
7924
+ configPath,
7925
+ "start",
7926
+ supervisorProgramName
7927
+ ]);
7928
+ }
7722
7929
  async function supervisorIsRunning(store, runtime) {
7723
7930
  return await commandSucceeds(runtime, "supervisorctl", [
7724
7931
  "-c",
@@ -7760,12 +7967,17 @@ function supervisorLogPath(store) {
7760
7967
  }
7761
7968
  async function commandSucceeds(runtime, command, argumentsList) {
7762
7969
  try {
7763
- await runtime.run(command, argumentsList);
7970
+ await runServiceProbe(runtime, command, argumentsList);
7764
7971
  return true;
7765
7972
  } catch {
7766
7973
  return false;
7767
7974
  }
7768
7975
  }
7976
+ async function runServiceProbe(runtime, command, argumentsList) {
7977
+ return await runtime.run(command, argumentsList, {
7978
+ timeoutMilliseconds: serviceManagerProbeTimeoutMilliseconds
7979
+ });
7980
+ }
7769
7981
  async function runCommandIgnoringFailure(runtime, command, argumentsList) {
7770
7982
  try {
7771
7983
  await runtime.run(command, argumentsList);
@@ -7812,7 +8024,7 @@ function delay5(milliseconds) {
7812
8024
  setTimeout(resolvePromise, milliseconds);
7813
8025
  });
7814
8026
  }
7815
- var import_node_child_process2, import_promises10, import_node_os5, import_node_path7, import_node_util2, execFileAsync, launchAgentLabel, serviceManagerCommandTimeoutMilliseconds, supervisorProgramName, ServiceManagerPreference, UserServiceManager, defaultServiceManagerRuntime;
8027
+ var import_node_child_process2, import_promises10, import_node_os5, import_node_path7, import_node_util2, execFileAsync, launchAgentLabel, serviceManagerProbeTimeoutMilliseconds, serviceManagerMutationTimeoutMilliseconds, supervisorProgramName, ServiceManagerPreference, UserServiceManager, defaultServiceManagerRuntime;
7816
8028
  var init_service_manager = __esm({
7817
8029
  "../machine-connector/dist/runtime/service-manager.js"() {
7818
8030
  "use strict";
@@ -7824,7 +8036,8 @@ var init_service_manager = __esm({
7824
8036
  import_node_util2 = require("util");
7825
8037
  execFileAsync = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
7826
8038
  launchAgentLabel = "ai.moxt.machine-connector";
7827
- serviceManagerCommandTimeoutMilliseconds = 5e3;
8039
+ serviceManagerProbeTimeoutMilliseconds = 5e3;
8040
+ serviceManagerMutationTimeoutMilliseconds = 3e4;
7828
8041
  supervisorProgramName = "moxt-machine-connector";
7829
8042
  (function(ServiceManagerPreference2) {
7830
8043
  ServiceManagerPreference2["Auto"] = "auto";
@@ -7840,11 +8053,11 @@ var init_service_manager = __esm({
7840
8053
  })(UserServiceManager || (UserServiceManager = {}));
7841
8054
  defaultServiceManagerRuntime = {
7842
8055
  operatingSystem: (0, import_node_os5.platform)(),
7843
- async run(command, argumentsList) {
8056
+ async run(command, argumentsList, options) {
7844
8057
  const result = await execFileAsync(command, argumentsList, {
7845
8058
  encoding: "utf8",
7846
8059
  killSignal: "SIGKILL",
7847
- timeout: serviceManagerCommandTimeoutMilliseconds
8060
+ timeout: options?.timeoutMilliseconds ?? serviceManagerMutationTimeoutMilliseconds
7848
8061
  });
7849
8062
  return {
7850
8063
  stderr: String(result.stderr),
@@ -7874,7 +8087,13 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
7874
8087
  if (initial.cliVersion === options.cliVersion) {
7875
8088
  return { manager, outcome: DaemonReconcileOutcome.Skipped };
7876
8089
  }
7877
- if (!await managedServiceOwnsProcess(manager, initial.pid, store)) {
8090
+ let managerOwnsProcess;
8091
+ try {
8092
+ managerOwnsProcess = await managedServiceOwnsProcess(manager, initial.pid, store);
8093
+ } catch (error) {
8094
+ throw new DaemonRefreshError("ownership", `could not verify that the reachable Connector belongs to ${manager}: ${errorMessage2(error)}`, { cause: error });
8095
+ }
8096
+ if (!managerOwnsProcess) {
7878
8097
  return { outcome: DaemonReconcileOutcome.Skipped };
7879
8098
  }
7880
8099
  try {
@@ -9599,7 +9818,7 @@ function getApiKeyOrUndefined() {
9599
9818
 
9600
9819
  // src/utils/http.ts
9601
9820
  function getUserAgent() {
9602
- return `moxt-cli/${"0.8.1"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
9821
+ return `moxt-cli/${"0.8.2"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
9603
9822
  }
9604
9823
  async function sendRequest(method, path4, init) {
9605
9824
  const response = await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -19713,7 +19932,7 @@ function compiler(options) {
19713
19932
  transforms: [],
19714
19933
  canContainEols: ["emphasis", "fragment", "heading", "paragraph", "strong"],
19715
19934
  enter: {
19716
- autolink: opener(link2),
19935
+ autolink: opener(link),
19717
19936
  autolinkProtocol: onenterdata,
19718
19937
  autolinkEmail: onenterdata,
19719
19938
  atxHeading: opener(heading),
@@ -19741,7 +19960,7 @@ function compiler(options) {
19741
19960
  htmlTextData: onenterdata,
19742
19961
  image: opener(image),
19743
19962
  label: buffer2,
19744
- link: opener(link2),
19963
+ link: opener(link),
19745
19964
  listItem: opener(listItem),
19746
19965
  listItemValue: onenterlistitemvalue,
19747
19966
  listOrdered: opener(list2, onenterlistordered),
@@ -20293,7 +20512,7 @@ function compiler(options) {
20293
20512
  alt: null
20294
20513
  };
20295
20514
  }
20296
- function link2() {
20515
+ function link() {
20297
20516
  return {
20298
20517
  type: "link",
20299
20518
  title: null,
@@ -22203,6 +22422,7 @@ function parseAssigneeBody(options, allowClear) {
22203
22422
  }
22204
22423
  function parseTaskListFilterQuery(options) {
22205
22424
  const filterOwnerHumanId = parseOptionalPositiveInteger(options.ownerHumanId, "--owner-human-id");
22425
+ const filterPriority = parsePriority(options.priority);
22206
22426
  const filterAssigneeHumanId = parseOptionalPositiveInteger(options.assigneeHumanId, "--assignee-human-id");
22207
22427
  const filterAssigneeAssistantId = parseOptionalPositiveInteger(
22208
22428
  options.assigneeAssistantId,
@@ -22218,6 +22438,7 @@ function parseTaskListFilterQuery(options) {
22218
22438
  }
22219
22439
  return {
22220
22440
  filterOwnerHumanId,
22441
+ filterPriority,
22221
22442
  filterAssigneeHumanId,
22222
22443
  filterAssigneeAssistantId,
22223
22444
  filterAssigneeTeammateId
@@ -22696,7 +22917,7 @@ function registerTransitionCommands(workflow) {
22696
22917
  function registerTaskCommands(workflow) {
22697
22918
  const task = workflow.command("task").description("Workflow task operations");
22698
22919
  addWorkspaceOption(
22699
- task.command("list").description("List workflow tasks").option("--workflow-file-id <workflowFileId>", "Filter by workflow file ID").option("--scope <scope>", "Task scope", "all").option("-l, --limit <limit>", "Maximum number of tasks to return", "50").option("--cursor <cursor>", "Pagination cursor").option("--owner-human-id <humanId>", "Filter by task owner human ID").option("--assignee-human-id <humanId>", "Filter by human assignee ID").option("--assignee-assistant-id <assistantId>", "Filter by AI assistant assignee ID").option("--assignee-teammate-id <teammateId>", "Filter by AI teammate assignee ID")
22920
+ task.command("list").description("List workflow tasks").option("--workflow-file-id <workflowFileId>", "Filter by workflow file ID").option("--scope <scope>", "Task scope", "all").option("-l, --limit <limit>", "Maximum number of tasks to return", "50").option("--cursor <cursor>", "Pagination cursor").option("--priority <priority>", "Filter by priority: urgent, high, medium, or low").option("--owner-human-id <humanId>", "Filter by task owner human ID").option("--assignee-human-id <humanId>", "Filter by human assignee ID").option("--assignee-assistant-id <assistantId>", "Filter by AI assistant assignee ID").option("--assignee-teammate-id <teammateId>", "Filter by AI teammate assignee ID")
22700
22921
  ).action(
22701
22922
  async (options) => {
22702
22923
  const query = runOrExit4(
@@ -23090,7 +23311,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
23090
23311
  var MAX_BATCH_SIZE = 100;
23091
23312
  function commonLabels() {
23092
23313
  return {
23093
- cli_version: "0.8.1",
23314
+ cli_version: "0.8.2",
23094
23315
  node_version: process.versions.node,
23095
23316
  os: (0, import_node_os7.platform)(),
23096
23317
  arch: (0, import_node_os7.arch)(),
@@ -23136,7 +23357,7 @@ async function flush() {
23136
23357
  }
23137
23358
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
23138
23359
  const payload = {
23139
- release_id: "0.8.1",
23360
+ release_id: "0.8.2",
23140
23361
  client_type: "cli",
23141
23362
  metric_data_list: batch.map((m) => ({
23142
23363
  profile: "cli",
@@ -23511,9 +23732,9 @@ function commandPath3(command) {
23511
23732
  }
23512
23733
 
23513
23734
  // src/index.ts
23514
- var program2 = createProgram("0.8.1");
23515
- installDaemonReconcileHook(program2, "0.8.1");
23516
- installUpdateHook(program2, "0.8.1");
23735
+ var program2 = createProgram("0.8.2");
23736
+ installDaemonReconcileHook(program2, "0.8.2");
23737
+ installUpdateHook(program2, "0.8.2");
23517
23738
  instrumentProgram(program2);
23518
23739
  installExitHandler();
23519
23740
  program2.parseAsync(process.argv).then(async () => {