@moxt-ai/cli 0.10.0-beta.1 → 0.10.0-beta.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/README.md CHANGED
@@ -25,15 +25,18 @@ When a same-channel update is cached, the next eligible command offers **Update
25
25
  command stdout remains safe to pipe. Daemon, help, version, telemetry, CI, and
26
26
  non-interactive invocations never prompt or install.
27
27
 
28
- After a CLI update, Moxt refreshes a running Local Machine Connector installed
29
- under launchd, a systemd user service, or Supervisor. The refresh preserves the
30
- configured service manager and updates its absolute Node and CLI paths. Active
31
- Jobs are reported before the restart and recover as interrupted with
32
- `daemon_restarted`. A foreground `moxt machine daemon` process is never
33
- restarted automatically. Updates performed by Homebrew, a package manager, or
34
- the standalone installer are reconciled on the new CLI's next normal command
35
- when it uses the managed service's recorded stable launcher path. A different
36
- CLI installation cannot take over the service automatically.
28
+ After a CLI update, Moxt refreshes a running Local Machine Connector or recovers
29
+ a temporarily offline managed Connector installed under launchd, a systemd user
30
+ service, or Supervisor. The refresh preserves the configured service manager
31
+ and updates its absolute Node and CLI paths. Active Jobs are reported before the
32
+ restart and recover as interrupted with `daemon_restarted`. A foreground `moxt
33
+ machine daemon` process is never restarted automatically. Updates performed by
34
+ Homebrew, a package manager, or the standalone installer are reconciled on the
35
+ new CLI's next normal command when it uses the managed service's recorded stable
36
+ launcher path. A different CLI installation cannot take over the service
37
+ automatically. A managed Connector explicitly stopped with `moxt machine
38
+ service stop` remains stopped across later CLI invocations until the user runs
39
+ `moxt machine service restart` or installs the service again.
37
40
 
38
41
  If the CLI installation succeeds but the Connector refresh fails, the CLI
39
42
  update remains successful. Moxt validates the new CLI entrypoint before changing
package/dist/index.cjs CHANGED
@@ -5175,7 +5175,7 @@ var init_codex_executor = __esm({
5175
5175
  });
5176
5176
 
5177
5177
  // ../machine-connector/dist/runtime/runtime-types.js
5178
- var PersistedMachineJobPhase;
5178
+ var PersistedMachineJobPhase, ManagedServiceDesiredState;
5179
5179
  var init_runtime_types = __esm({
5180
5180
  "../machine-connector/dist/runtime/runtime-types.js"() {
5181
5181
  "use strict";
@@ -5186,6 +5186,10 @@ var init_runtime_types = __esm({
5186
5186
  PersistedMachineJobPhase2["TerminalPendingUpload"] = "terminal_pending_upload";
5187
5187
  PersistedMachineJobPhase2["Uploaded"] = "uploaded";
5188
5188
  })(PersistedMachineJobPhase || (PersistedMachineJobPhase = {}));
5189
+ (function(ManagedServiceDesiredState2) {
5190
+ ManagedServiceDesiredState2["Running"] = "running";
5191
+ ManagedServiceDesiredState2["Stopped"] = "stopped";
5192
+ })(ManagedServiceDesiredState || (ManagedServiceDesiredState = {}));
5189
5193
  }
5190
5194
  });
5191
5195
 
@@ -10597,6 +10601,9 @@ function createServiceEnvironment(options) {
10597
10601
  async function restartUserService(store, runtime = defaultServiceManagerRuntime) {
10598
10602
  const manager = await configuredServiceManager(store, runtime);
10599
10603
  await restartManager(manager, store, runtime);
10604
+ if (manager !== UserServiceManager.None) {
10605
+ await persistServiceDesiredState(store, manager, ManagedServiceDesiredState.Running);
10606
+ }
10600
10607
  return manager;
10601
10608
  }
10602
10609
  async function refreshManagedUserService(store, options, runtime = defaultServiceManagerRuntime) {
@@ -10668,9 +10675,24 @@ async function managedServiceOwnsProcess(manager, processId, store, runtime = de
10668
10675
  async function recordedServiceManager(store) {
10669
10676
  return await readStoredServiceManager(store);
10670
10677
  }
10678
+ async function recordedServiceDesiredState(store) {
10679
+ const desiredState = (await store.readServiceManager()).value?.desiredState;
10680
+ if (desiredState === void 0)
10681
+ return ManagedServiceDesiredState.Running;
10682
+ if (desiredState === ManagedServiceDesiredState.Running) {
10683
+ return ManagedServiceDesiredState.Running;
10684
+ }
10685
+ if (desiredState === ManagedServiceDesiredState.Stopped) {
10686
+ return ManagedServiceDesiredState.Stopped;
10687
+ }
10688
+ throw new Error(`Unsupported managed service desired state: ${desiredState}`);
10689
+ }
10671
10690
  async function stopUserService(store, runtime = defaultServiceManagerRuntime) {
10672
10691
  const manager = await configuredServiceManager(store, runtime);
10673
10692
  await stopManager(manager, store, runtime);
10693
+ if (manager !== UserServiceManager.None) {
10694
+ await persistServiceDesiredState(store, manager, ManagedServiceDesiredState.Stopped);
10695
+ }
10674
10696
  return manager;
10675
10697
  }
10676
10698
  async function uninstallUserService(store, runtime = defaultServiceManagerRuntime) {
@@ -10881,13 +10903,18 @@ function parseProcessId(value) {
10881
10903
  const processId = Number.parseInt(value.trim(), 10);
10882
10904
  return Number.isSafeInteger(processId) && processId > 0 ? processId : void 0;
10883
10905
  }
10884
- async function persistServiceManager(store, manager, managedEntrypointPath) {
10906
+ async function persistServiceManager(store, manager, managedEntrypointPath, desiredState = ManagedServiceDesiredState.Running) {
10885
10907
  await store.writeServiceManager({
10908
+ desiredState,
10886
10909
  ...managedEntrypointPath ? { managedEntrypointPath: (0, import_node_path10.resolve)(managedEntrypointPath) } : {},
10887
10910
  manager,
10888
10911
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
10889
10912
  });
10890
10913
  }
10914
+ async function persistServiceDesiredState(store, manager, desiredState) {
10915
+ const stored = (await store.readServiceManager()).value;
10916
+ await persistServiceManager(store, manager, stored?.managedEntrypointPath, desiredState);
10917
+ }
10891
10918
  async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
10892
10919
  const stored = (await store.readServiceManager()).value;
10893
10920
  if (!stored || stored.manager === UserServiceManager.None)
@@ -11113,33 +11140,23 @@ async function startSupervisorUserService(store, runtime, previousSupervisorProc
11113
11140
  }
11114
11141
  async function reloadSupervisorConfiguration(store, runtime) {
11115
11142
  const configPath = supervisorConfigPath(store);
11116
- const processIdBeforeStop = await runServiceProbe(runtime, "supervisorctl", [
11117
- "-c",
11118
- configPath,
11119
- "pid",
11120
- supervisorProgramName
11121
- ]);
11122
- if ((parseProcessId(processIdBeforeStop.stdout) ?? 0) > 0) {
11143
+ const processIdBeforeStop = await currentSupervisorProgramProcessId(store, runtime);
11144
+ if (processIdBeforeStop !== void 0) {
11123
11145
  await runtime.run("supervisorctl", [
11124
11146
  "-c",
11125
11147
  configPath,
11126
11148
  "stop",
11127
11149
  supervisorProgramName
11128
11150
  ]);
11129
- const processIdAfterStop = await runServiceProbe(runtime, "supervisorctl", ["-c", configPath, "pid", supervisorProgramName]);
11130
- if ((parseProcessId(processIdAfterStop.stdout) ?? 0) > 0) {
11151
+ const processIdAfterStop = await currentSupervisorProgramProcessId(store, runtime);
11152
+ if (processIdAfterStop !== void 0) {
11131
11153
  throw new Error("Supervisor did not stop the existing Moxt Machine Connector process");
11132
11154
  }
11133
11155
  }
11134
11156
  await runtime.run("supervisorctl", ["-c", configPath, "reread"]);
11135
11157
  await runtime.run("supervisorctl", ["-c", configPath, "update"]);
11136
- const processId = await runServiceProbe(runtime, "supervisorctl", [
11137
- "-c",
11138
- configPath,
11139
- "pid",
11140
- supervisorProgramName
11141
- ]);
11142
- if ((parseProcessId(processId.stdout) ?? 0) > 0)
11158
+ const processId = await currentSupervisorProgramProcessId(store, runtime);
11159
+ if (processId !== void 0)
11143
11160
  return;
11144
11161
  await runtime.run("supervisorctl", [
11145
11162
  "-c",
@@ -11328,6 +11345,7 @@ var init_service_manager = __esm({
11328
11345
  import_node_os7 = require("os");
11329
11346
  import_node_path10 = require("path");
11330
11347
  import_node_util2 = require("util");
11348
+ init_runtime_types();
11331
11349
  init_shell_environment();
11332
11350
  execFileAsync = (0, import_node_util2.promisify)(import_node_child_process5.execFile);
11333
11351
  launchAgentLabel = "ai.moxt.machine-connector";
@@ -11383,24 +11401,27 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
11383
11401
  if (!lock)
11384
11402
  return { outcome: DaemonReconcileOutcome.Skipped };
11385
11403
  try {
11386
- const initial = await reachableRuntimeStatus(store);
11387
- if (!initial)
11388
- return { outcome: DaemonReconcileOutcome.Skipped };
11389
11404
  const manager = await recordedServiceManager(store);
11390
11405
  if (manager === UserServiceManager.None) {
11391
11406
  return { outcome: DaemonReconcileOutcome.Skipped };
11392
11407
  }
11393
- if (initial.cliVersion === options.cliVersion) {
11408
+ if (await recordedServiceDesiredState(store) === ManagedServiceDesiredState.Stopped) {
11394
11409
  return { manager, outcome: DaemonReconcileOutcome.Skipped };
11395
11410
  }
11396
- let managerOwnsProcess;
11397
- try {
11398
- managerOwnsProcess = await managedServiceOwnsProcess(manager, initial.pid, store);
11399
- } catch (error) {
11400
- throw new DaemonRefreshError("ownership", `could not verify that the reachable Connector belongs to ${manager}: ${errorMessage4(error)}`, { cause: error });
11411
+ const initial = await reachableRuntimeStatus(store);
11412
+ if (initial?.cliVersion === options.cliVersion) {
11413
+ return { manager, outcome: DaemonReconcileOutcome.Skipped };
11401
11414
  }
11402
- if (!managerOwnsProcess) {
11403
- return { outcome: DaemonReconcileOutcome.Skipped };
11415
+ if (initial) {
11416
+ let managerOwnsProcess;
11417
+ try {
11418
+ managerOwnsProcess = await managedServiceOwnsProcess(manager, initial.pid, store);
11419
+ } catch (error) {
11420
+ throw new DaemonRefreshError("ownership", `could not verify that the reachable Connector belongs to ${manager}: ${errorMessage4(error)}`, { cause: error });
11421
+ }
11422
+ if (!managerOwnsProcess) {
11423
+ return { outcome: DaemonReconcileOutcome.Skipped };
11424
+ }
11404
11425
  }
11405
11426
  try {
11406
11427
  await validateCliEntrypoint(options, store);
@@ -11409,7 +11430,7 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
11409
11430
  cause: error
11410
11431
  });
11411
11432
  }
11412
- if (initial.activeJobs.length > 0) {
11433
+ if (initial && initial.activeJobs.length > 0) {
11413
11434
  options.onActiveJobs?.(initial.activeJobs.length);
11414
11435
  }
11415
11436
  let refresh;
@@ -11429,12 +11450,12 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
11429
11450
  const deadline = Date.now() + reconcileTimeoutMilliseconds;
11430
11451
  while (Date.now() < deadline) {
11431
11452
  const current2 = await reachableRuntimeStatus(store);
11432
- if (current2?.cliVersion === options.cliVersion && current2.connectorInstanceId !== initial.connectorInstanceId) {
11453
+ if (current2?.cliVersion === options.cliVersion && current2.connectorInstanceId !== initial?.connectorInstanceId) {
11433
11454
  return { manager, outcome: DaemonReconcileOutcome.Restarted };
11434
11455
  }
11435
11456
  await delay6(100);
11436
11457
  }
11437
- const verificationMessage = `managed daemon did not report CLI ${options.cliVersion} with a new instance ID`;
11458
+ const verificationMessage = initial ? `managed daemon did not report CLI ${options.cliVersion} with a new instance ID` : `managed daemon did not become reachable with CLI ${options.cliVersion}`;
11438
11459
  try {
11439
11460
  await refresh.rollback();
11440
11461
  } catch (error) {
@@ -11498,6 +11519,7 @@ var init_daemon_reconcile = __esm({
11498
11519
  init_local_ipc();
11499
11520
  init_process_lock();
11500
11521
  init_service_manager();
11522
+ init_runtime_types();
11501
11523
  init_store();
11502
11524
  reconcileTimeoutMilliseconds = 12e3;
11503
11525
  execFileAsync2 = (0, import_node_util3.promisify)(import_node_child_process6.execFile);
@@ -12401,6 +12423,7 @@ var init_device_identity = __esm({
12401
12423
  async function pairMachine(store, options) {
12402
12424
  await store.initialize();
12403
12425
  const canonicalRoot = await store.getCanonicalRoot(options.rootPath);
12426
+ const rootDisplayName = displayNameForRoot(canonicalRoot);
12404
12427
  const identity = await ensureMachineIdentity(store);
12405
12428
  const machineName = options.machineName ?? (0, import_node_os8.hostname)();
12406
12429
  const operatingSystem = getOperatingSystem();
@@ -12413,7 +12436,7 @@ async function pairMachine(store, options) {
12413
12436
  machineName,
12414
12437
  operatingSystem,
12415
12438
  protocolVersion: machineProtocolVersion,
12416
- rootDisplayName: (0, import_node_path12.basename)(canonicalRoot),
12439
+ rootDisplayName,
12417
12440
  rootHandle
12418
12441
  });
12419
12442
  options.onConfirmation?.(proposal.confirmationUrl);
@@ -12442,7 +12465,7 @@ async function pairMachine(store, options) {
12442
12465
  purpose: credentials.purpose,
12443
12466
  refreshToken: credentials.refreshToken,
12444
12467
  relayOrigin: options.relayOrigin.replace(/\/+$/, ""),
12445
- rootDisplayName: (0, import_node_path12.basename)(canonicalRoot),
12468
+ rootDisplayName,
12446
12469
  rootHandle,
12447
12470
  rootPath: canonicalRoot,
12448
12471
  targetId: credentials.targetId,
@@ -12462,6 +12485,10 @@ async function pairMachine(store, options) {
12462
12485
  }
12463
12486
  throw new Error("Local Machine pairing expired");
12464
12487
  }
12488
+ function displayNameForRoot(canonicalRoot) {
12489
+ const name = (0, import_node_path12.basename)(canonicalRoot);
12490
+ return name.length > 0 ? name : canonicalRoot;
12491
+ }
12465
12492
  function getOperatingSystem() {
12466
12493
  if ((0, import_node_os8.platform)() === "darwin") {
12467
12494
  return MachineOperatingSystem.MacOS;
@@ -12943,6 +12970,7 @@ __export(dist_exports, {
12943
12970
  MachineProtocolInvariantError: () => MachineProtocolInvariantError,
12944
12971
  MachineRelayClient: () => MachineRelayClient,
12945
12972
  MachineRuntimeStore: () => MachineRuntimeStore,
12973
+ ManagedServiceDesiredState: () => ManagedServiceDesiredState,
12946
12974
  PairingRelayClient: () => PairingRelayClient,
12947
12975
  PersistedMachineJobPhase: () => PersistedMachineJobPhase,
12948
12976
  RelayHttpError: () => RelayHttpError,
@@ -12976,6 +13004,7 @@ __export(dist_exports, {
12976
13004
  parseLocalMachineJobExecutionContext: () => parseLocalMachineJobExecutionContext,
12977
13005
  parseServiceManagerPreference: () => parseServiceManagerPreference,
12978
13006
  reconcileManagedDaemon: () => reconcileManagedDaemon,
13007
+ recordedServiceDesiredState: () => recordedServiceDesiredState,
12979
13008
  recordedServiceManager: () => recordedServiceManager,
12980
13009
  refreshManagedUserService: () => refreshManagedUserService,
12981
13010
  renderMachineManager: () => renderMachineManager,
@@ -13189,7 +13218,7 @@ function getApiKeyOrUndefined() {
13189
13218
 
13190
13219
  // src/utils/http.ts
13191
13220
  function getUserAgent() {
13192
- return `moxt-cli/${"0.10.0-beta.1"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
13221
+ return `moxt-cli/${"0.10.0-beta.2"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
13193
13222
  }
13194
13223
  async function sendRequest(method, path4, init) {
13195
13224
  return await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -26772,7 +26801,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
26772
26801
  var MAX_BATCH_SIZE = 100;
26773
26802
  function commonLabels() {
26774
26803
  return {
26775
- cli_version: "0.10.0-beta.1",
26804
+ cli_version: "0.10.0-beta.2",
26776
26805
  node_version: process.versions.node,
26777
26806
  os: (0, import_node_os9.platform)(),
26778
26807
  arch: (0, import_node_os9.arch)(),
@@ -26818,7 +26847,7 @@ async function flush() {
26818
26847
  }
26819
26848
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
26820
26849
  const payload = {
26821
- release_id: "0.10.0-beta.1",
26850
+ release_id: "0.10.0-beta.2",
26822
26851
  client_type: "cli",
26823
26852
  metric_data_list: batch.map((m) => ({
26824
26853
  profile: "cli",
@@ -27201,9 +27230,9 @@ function commandPath3(command) {
27201
27230
  }
27202
27231
 
27203
27232
  // src/index.ts
27204
- var program2 = createProgram("0.10.0-beta.1");
27205
- installDaemonReconcileHook(program2, "0.10.0-beta.1");
27206
- installUpdateHook(program2, "0.10.0-beta.1");
27233
+ var program2 = createProgram("0.10.0-beta.2");
27234
+ installDaemonReconcileHook(program2, "0.10.0-beta.2");
27235
+ installUpdateHook(program2, "0.10.0-beta.2");
27207
27236
  instrumentProgram(program2);
27208
27237
  installExitHandler();
27209
27238
  program2.parseAsync(process.argv).then(async () => {