@moxt-ai/cli 0.8.2 → 0.9.0-beta.1

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
@@ -3787,8 +3787,8 @@ var require_common = __commonJS({
3787
3787
  }
3788
3788
  return debug2;
3789
3789
  }
3790
- function extend(namespace, delimiter2) {
3791
- const newDebug = createDebug(this.namespace + (typeof delimiter2 === "undefined" ? ":" : delimiter2) + namespace);
3790
+ function extend(namespace, delimiter3) {
3791
+ const newDebug = createDebug(this.namespace + (typeof delimiter3 === "undefined" ? ":" : delimiter3) + namespace);
3792
3792
  newDebug.log = this.log;
3793
3793
  return newDebug;
3794
3794
  }
@@ -4495,10 +4495,6 @@ var init_v1 = __esm({
4495
4495
  });
4496
4496
 
4497
4497
  // ../machine-connector/dist/runtime/process-executor.js
4498
- async function executeCommand(rootPath, spec, callbacks) {
4499
- const workingDirectory = await resolveCanonicalWorkingDirectory(rootPath, spec.relativeWorkingDirectory);
4500
- return await executeProcess(spec.executable, spec.arguments, workingDirectory, spec.environment, spec.stdin, spec.timeoutSeconds, callbacks);
4501
- }
4502
4498
  async function executeProcess(executable, argumentsList, workingDirectory, environment, stdin, timeoutSeconds, callbacks) {
4503
4499
  if (callbacks.canSpawn && !callbacks.canSpawn()) {
4504
4500
  return {
@@ -4509,7 +4505,7 @@ async function executeProcess(executable, argumentsList, workingDirectory, envir
4509
4505
  const child = (0, import_node_child_process.spawn)(executable, argumentsList, {
4510
4506
  cwd: workingDirectory,
4511
4507
  detached: (0, import_node_os.platform)() !== "win32",
4512
- env: buildChildEnvironment(environment),
4508
+ env: { ...environment },
4513
4509
  shell: false,
4514
4510
  stdio: ["pipe", "pipe", "pipe"],
4515
4511
  windowsHide: true
@@ -4641,19 +4637,6 @@ async function executeProcess(executable, argumentsList, workingDirectory, envir
4641
4637
  status: processExit.exitCode === 0 ? MachineJobStatus.Succeeded : MachineJobStatus.Failed
4642
4638
  };
4643
4639
  }
4644
- function buildChildEnvironment(overrides) {
4645
- const environment = {};
4646
- for (const [name, value] of Object.entries(process.env)) {
4647
- if (name === "MOXT_MACHINE_ACCESS_TOKEN" || name === "MOXT_MACHINE_REFRESH_TOKEN" || name === "MOXT_MACHINE_DEVICE_PRIVATE_KEY" || name === "MOXT_API_TOKEN" || name === "MOXT_CLI_TOKEN") {
4648
- continue;
4649
- }
4650
- environment[name] = value;
4651
- }
4652
- return {
4653
- ...environment,
4654
- ...overrides
4655
- };
4656
- }
4657
4640
  async function resolveCanonicalWorkingDirectory(rootPath, relativeWorkingDirectory) {
4658
4641
  const canonicalRoot = await (0, import_promises3.realpath)(rootPath);
4659
4642
  const lexicalCandidate = resolveWorkingDirectory(canonicalRoot, relativeWorkingDirectory);
@@ -4767,9 +4750,9 @@ var init_process_executor = __esm({
4767
4750
  });
4768
4751
 
4769
4752
  // ../machine-connector/dist/runtime/claude-executor.js
4770
- async function executeClaudeStart(workingDirectory, spec, callbacks) {
4753
+ async function executeClaudeStart(workingDirectory, environment, spec, callbacks) {
4771
4754
  const sessionId = (0, import_node_crypto.randomUUID)();
4772
- return await executeClaude(workingDirectory, [
4755
+ return await executeClaude(workingDirectory, environment, [
4773
4756
  "--print",
4774
4757
  "--output-format",
4775
4758
  "stream-json",
@@ -4779,8 +4762,8 @@ async function executeClaudeStart(workingDirectory, spec, callbacks) {
4779
4762
  sessionId
4780
4763
  ], spec.prompt, sessionId, callbacks);
4781
4764
  }
4782
- async function executeClaudeReply(workingDirectory, spec, callbacks) {
4783
- return await executeClaude(workingDirectory, [
4765
+ async function executeClaudeReply(workingDirectory, environment, spec, callbacks) {
4766
+ return await executeClaude(workingDirectory, environment, [
4784
4767
  "--print",
4785
4768
  "--output-format",
4786
4769
  "stream-json",
@@ -4790,7 +4773,7 @@ async function executeClaudeReply(workingDirectory, spec, callbacks) {
4790
4773
  spec.threadId
4791
4774
  ], spec.prompt, spec.threadId, callbacks);
4792
4775
  }
4793
- async function executeClaude(workingDirectory, argumentsList, prompt, expectedSessionId, callbacks) {
4776
+ async function executeClaude(workingDirectory, environment, argumentsList, prompt, expectedSessionId, callbacks) {
4794
4777
  const metadata = {
4795
4778
  threadId: expectedSessionId
4796
4779
  };
@@ -4811,7 +4794,7 @@ async function executeClaude(workingDirectory, argumentsList, prompt, expectedSe
4811
4794
  },
4812
4795
  onSpawn: callbacks.onSpawn
4813
4796
  };
4814
- const result = await executeProcess(process.env.MOXT_CLAUDE_PATH ?? "claude", argumentsList, workingDirectory, {}, prompt, 43200, processCallbacks);
4797
+ const result = await executeProcess(process.env.MOXT_CLAUDE_PATH ?? "claude", argumentsList, workingDirectory, environment, prompt, 43200, processCallbacks);
4815
4798
  if (bufferedStdout.trim().length > 0) {
4816
4799
  await processClaudeLine(bufferedStdout, metadata, callbacks);
4817
4800
  }
@@ -4867,9 +4850,9 @@ var init_claude_executor = __esm({
4867
4850
  });
4868
4851
 
4869
4852
  // ../machine-connector/dist/runtime/codex-executor.js
4870
- async function executeCodexStart(workingDirectory, runtimeDirectory, spec, callbacks) {
4853
+ async function executeCodexStart(workingDirectory, runtimeDirectory, environment, spec, callbacks) {
4871
4854
  const outputPath = createOutputPath(runtimeDirectory);
4872
- return await executeCodex(workingDirectory, outputPath, [
4855
+ return await executeCodex(workingDirectory, outputPath, environment, [
4873
4856
  "exec",
4874
4857
  "--json",
4875
4858
  "--dangerously-bypass-approvals-and-sandbox",
@@ -4879,9 +4862,9 @@ async function executeCodexStart(workingDirectory, runtimeDirectory, spec, callb
4879
4862
  "-"
4880
4863
  ], spec.prompt, callbacks);
4881
4864
  }
4882
- async function executeCodexReply(workingDirectory, runtimeDirectory, spec, callbacks) {
4865
+ async function executeCodexReply(workingDirectory, runtimeDirectory, environment, spec, callbacks) {
4883
4866
  const outputPath = createOutputPath(runtimeDirectory);
4884
- return await executeCodex(workingDirectory, outputPath, [
4867
+ return await executeCodex(workingDirectory, outputPath, environment, [
4885
4868
  "exec",
4886
4869
  "resume",
4887
4870
  "--json",
@@ -4893,7 +4876,7 @@ async function executeCodexReply(workingDirectory, runtimeDirectory, spec, callb
4893
4876
  "-"
4894
4877
  ], spec.prompt, callbacks);
4895
4878
  }
4896
- async function executeCodex(workingDirectory, outputPath, argumentsList, prompt, callbacks) {
4879
+ async function executeCodex(workingDirectory, outputPath, environment, argumentsList, prompt, callbacks) {
4897
4880
  const executionMetadata = {};
4898
4881
  const turnCompletion = createCodexTurnCompletion();
4899
4882
  let bufferedStdout = "";
@@ -4926,7 +4909,7 @@ async function executeCodex(workingDirectory, outputPath, argumentsList, prompt,
4926
4909
  return result2;
4927
4910
  })
4928
4911
  };
4929
- const result = await executeProcess(process.env.MOXT_CODEX_PATH ?? "codex", argumentsList, workingDirectory, {}, prompt, 43200, processCallbacks);
4912
+ const result = await executeProcess(process.env.MOXT_CODEX_PATH ?? "codex", argumentsList, workingDirectory, environment, prompt, 43200, processCallbacks);
4930
4913
  if (bufferedStdout.trim().length > 0) {
4931
4914
  const event = parseCodexEvent(bufferedStdout).value;
4932
4915
  if (event !== void 0) {
@@ -5238,6 +5221,7 @@ var init_execution_cancellation = __esm({
5238
5221
  ExecutionCancellationReason2["Stopping"] = "stopping";
5239
5222
  })(ExecutionCancellationReason || (ExecutionCancellationReason = {}));
5240
5223
  ExecutionCancellation = class {
5224
+ abortController = new AbortController();
5241
5225
  handle;
5242
5226
  reason;
5243
5227
  requested;
@@ -5253,6 +5237,9 @@ var init_execution_cancellation = __esm({
5253
5237
  currentReason() {
5254
5238
  return this.reason;
5255
5239
  }
5240
+ signal() {
5241
+ return this.abortController.signal;
5242
+ }
5256
5243
  register(handle) {
5257
5244
  this.handle = handle;
5258
5245
  if (this.reason !== void 0) {
@@ -5269,6 +5256,7 @@ var init_execution_cancellation = __esm({
5269
5256
  async request(reason) {
5270
5257
  if (this.reason === void 0) {
5271
5258
  this.reason = reason;
5259
+ this.abortController.abort(reason);
5272
5260
  this.resolveRequested(reason);
5273
5261
  }
5274
5262
  if (this.handle) {
@@ -5555,6 +5543,12 @@ var init_image_viewer = __esm({
5555
5543
 
5556
5544
  // ../machine-connector/dist/runtime/local-ipc.js
5557
5545
  async function requestRuntimeStatus(store, timeoutMilliseconds = 1e3) {
5546
+ return await requestLocalIpc(store, "status", timeoutMilliseconds);
5547
+ }
5548
+ async function requestEnvironmentRefresh(store, timeoutMilliseconds = 1e4) {
5549
+ return await requestLocalIpc(store, "environment_refresh", timeoutMilliseconds);
5550
+ }
5551
+ async function requestLocalIpc(store, action, timeoutMilliseconds) {
5558
5552
  return await new Promise((resolvePromise, rejectPromise) => {
5559
5553
  const socket = (0, import_node_net.createConnection)(store.runtimeSocketPath());
5560
5554
  let responseText = "";
@@ -5574,7 +5568,7 @@ async function requestRuntimeStatus(store, timeoutMilliseconds = 1e3) {
5574
5568
  }
5575
5569
  });
5576
5570
  socket.once("connect", () => {
5577
- socket.write(`${JSON.stringify({ action: "status" })}
5571
+ socket.write(`${JSON.stringify({ action })}
5578
5572
  `);
5579
5573
  });
5580
5574
  });
@@ -5590,10 +5584,12 @@ var init_local_ipc = __esm({
5590
5584
  LocalIpcServer = class {
5591
5585
  store;
5592
5586
  getStatus;
5587
+ refreshEnvironment;
5593
5588
  server;
5594
- constructor(store, getStatus) {
5589
+ constructor(store, getStatus, refreshEnvironment) {
5595
5590
  this.store = store;
5596
5591
  this.getStatus = getStatus;
5592
+ this.refreshEnvironment = refreshEnvironment;
5597
5593
  }
5598
5594
  async start() {
5599
5595
  const socketPath = this.store.runtimeSocketPath();
@@ -5602,15 +5598,18 @@ var init_local_ipc = __esm({
5602
5598
  }
5603
5599
  this.server = (0, import_node_net.createServer)((socket) => {
5604
5600
  let requestText = "";
5601
+ let handled = false;
5605
5602
  socket.setEncoding("utf8");
5606
5603
  socket.on("data", (chunk) => {
5607
5604
  requestText += chunk;
5608
- if (!requestText.includes("\n")) {
5605
+ if (handled || !requestText.includes("\n")) {
5609
5606
  return;
5610
5607
  }
5611
- const response = this.handleRequest(requestText);
5612
- socket.end(`${JSON.stringify(response)}
5608
+ handled = true;
5609
+ void this.handleRequest(requestText).then((response) => {
5610
+ socket.end(`${JSON.stringify(response)}
5613
5611
  `);
5612
+ });
5614
5613
  });
5615
5614
  });
5616
5615
  await new Promise((resolvePromise, rejectPromise) => {
@@ -5632,12 +5631,20 @@ var init_local_ipc = __esm({
5632
5631
  await (0, import_promises6.rm)(this.store.runtimeSocketPath(), { force: true });
5633
5632
  }
5634
5633
  }
5635
- handleRequest(requestText) {
5634
+ async handleRequest(requestText) {
5636
5635
  try {
5637
5636
  const request2 = JSON.parse(requestText.trim());
5638
5637
  if (request2.action === "status") {
5639
5638
  return { status: this.getStatus() };
5640
5639
  }
5640
+ if (request2.action === "environment_refresh") {
5641
+ if (!this.refreshEnvironment) {
5642
+ return { error: "Environment refresh is unavailable" };
5643
+ }
5644
+ return {
5645
+ environmentRefresh: await this.refreshEnvironment()
5646
+ };
5647
+ }
5641
5648
  return { error: `Unsupported IPC action: ${request2.action}` };
5642
5649
  } catch (error) {
5643
5650
  return {
@@ -5973,6 +5980,483 @@ var init_process_lock = __esm({
5973
5980
  }
5974
5981
  });
5975
5982
 
5983
+ // ../machine-connector/dist/runtime/shell-environment.js
5984
+ function sanitizeEnvironment(source) {
5985
+ const environment = createEnvironmentMap();
5986
+ for (const [name, value] of Object.entries(source)) {
5987
+ if (value === void 0 || isConnectorCredentialName(name)) {
5988
+ continue;
5989
+ }
5990
+ environment[name] = value;
5991
+ }
5992
+ return environment;
5993
+ }
5994
+ function parseNullSeparatedEnvironment(output) {
5995
+ if (output.length === 0 || output.at(-1) !== 0) {
5996
+ throw new Error("shell_environment_malformed");
5997
+ }
5998
+ const text3 = decodeUtf8(output, "shell_environment_malformed");
5999
+ const environment = createEnvironmentMap();
6000
+ const frames2 = text3.slice(0, -1).split("\0");
6001
+ for (const frame of frames2) {
6002
+ const separator = frame.indexOf("=");
6003
+ const name = frame.slice(0, separator);
6004
+ if (separator <= 0 || !environmentNamePattern.test(name) || Object.hasOwn(environment, name)) {
6005
+ throw new Error("shell_environment_malformed");
6006
+ }
6007
+ environment[name] = frame.slice(separator + 1);
6008
+ }
6009
+ return environment;
6010
+ }
6011
+ function parseDirenvJson(text3) {
6012
+ try {
6013
+ let index2 = skipWhitespace(text3, 0);
6014
+ if (text3[index2] !== "{")
6015
+ throw new Error("object expected");
6016
+ index2 = skipWhitespace(text3, index2 + 1);
6017
+ const exports2 = createEnvironmentMap();
6018
+ if (text3[index2] === "}") {
6019
+ index2 = skipWhitespace(text3, index2 + 1);
6020
+ if (index2 !== text3.length)
6021
+ throw new Error("trailing input");
6022
+ return exports2;
6023
+ }
6024
+ while (index2 < text3.length) {
6025
+ const key = readJsonString(text3, index2);
6026
+ if (!environmentNamePattern.test(key.value) || Object.hasOwn(exports2, key.value)) {
6027
+ throw new Error("invalid or duplicate key");
6028
+ }
6029
+ index2 = skipWhitespace(text3, key.next);
6030
+ if (text3[index2] !== ":")
6031
+ throw new Error("colon expected");
6032
+ index2 = skipWhitespace(text3, index2 + 1);
6033
+ if (text3.startsWith("null", index2)) {
6034
+ exports2[key.value] = null;
6035
+ index2 += 4;
6036
+ } else {
6037
+ const value = readJsonString(text3, index2);
6038
+ exports2[key.value] = value.value;
6039
+ index2 = value.next;
6040
+ }
6041
+ index2 = skipWhitespace(text3, index2);
6042
+ if (text3[index2] === "}") {
6043
+ index2 = skipWhitespace(text3, index2 + 1);
6044
+ if (index2 !== text3.length)
6045
+ throw new Error("trailing input");
6046
+ return exports2;
6047
+ }
6048
+ if (text3[index2] !== ",")
6049
+ throw new Error("comma expected");
6050
+ index2 = skipWhitespace(text3, index2 + 1);
6051
+ }
6052
+ throw new Error("unterminated object");
6053
+ } catch {
6054
+ throw new Error("direnv_malformed");
6055
+ }
6056
+ }
6057
+ function sanitizeDirenvExports(source) {
6058
+ const exports2 = createEnvironmentMap();
6059
+ for (const [name, value] of Object.entries(source)) {
6060
+ if (!isConnectorCredentialName(name)) {
6061
+ exports2[name] = value;
6062
+ }
6063
+ }
6064
+ return exports2;
6065
+ }
6066
+ function isConnectorCredentialName(name) {
6067
+ if (name === "MOXT_API_TOKEN" || name === "MOXT_CLI_TOKEN")
6068
+ return true;
6069
+ return name.startsWith("MOXT_MACHINE_") && /(?:^|_)(?:TOKEN|SECRET|CREDENTIALS?|PASSWORD|PRIVATE_KEY)(?:_|$)/.test(name.slice("MOXT_MACHINE_".length));
6070
+ }
6071
+ async function validateShell(shellPath) {
6072
+ if (!(0, import_node_path6.isAbsolute)(shellPath))
6073
+ throw new Error("default shell is not absolute");
6074
+ const canonicalPath = await validateExecutable(shellPath);
6075
+ const shellName = (0, import_node_path6.basename)(canonicalPath);
6076
+ if (shellName !== "bash" && shellName !== "zsh") {
6077
+ throw new Error("default shell is not Bash or Zsh");
6078
+ }
6079
+ return canonicalPath;
6080
+ }
6081
+ async function validateExecutable(path4) {
6082
+ const canonicalPath = await (0, import_promises8.realpath)(path4);
6083
+ const metadata = await (0, import_promises8.stat)(canonicalPath);
6084
+ if (!metadata.isFile())
6085
+ throw new Error("executable is not a regular file");
6086
+ await (0, import_promises8.access)(canonicalPath, import_promises8.constants.X_OK);
6087
+ return canonicalPath;
6088
+ }
6089
+ async function findExecutable(name, pathValue) {
6090
+ for (const directory of (pathValue ?? "").split(import_node_path6.delimiter)) {
6091
+ if (!(0, import_node_path6.isAbsolute)(directory))
6092
+ continue;
6093
+ try {
6094
+ const candidate = await validateExecutable((0, import_node_path6.join)(directory, name));
6095
+ if ((0, import_node_path6.basename)(candidate) === name)
6096
+ return candidate;
6097
+ } catch {
6098
+ }
6099
+ }
6100
+ return void 0;
6101
+ }
6102
+ async function findNearestEnvrc(canonicalRoot, canonicalWorkingDirectory) {
6103
+ let directory = canonicalWorkingDirectory;
6104
+ while (true) {
6105
+ const candidate = (0, import_node_path6.join)(directory, ".envrc");
6106
+ try {
6107
+ const metadata = await (0, import_promises8.stat)(candidate);
6108
+ if (!metadata.isFile()) {
6109
+ throw new JobEnvironmentError("direnv_malformed");
6110
+ }
6111
+ return candidate;
6112
+ } catch (error) {
6113
+ if (!isNodeError(error, "ENOENT"))
6114
+ throw error;
6115
+ }
6116
+ if (directory === canonicalRoot)
6117
+ return void 0;
6118
+ const parent = (0, import_node_path6.dirname)(directory);
6119
+ if (parent === directory)
6120
+ return void 0;
6121
+ directory = parent;
6122
+ }
6123
+ }
6124
+ async function executeBounded(options) {
6125
+ if (options.cancellationSignal?.aborted) {
6126
+ return {
6127
+ exitCode: -1,
6128
+ outcome: "cancelled",
6129
+ stderr: Buffer.alloc(0),
6130
+ stdout: Buffer.alloc(0)
6131
+ };
6132
+ }
6133
+ return await new Promise((resolvePromise) => {
6134
+ const child = (0, import_node_child_process2.spawn)(options.executable, options.argumentsList, {
6135
+ cwd: options.cwd,
6136
+ detached: (0, import_node_os3.platform)() !== "win32",
6137
+ env: options.environment,
6138
+ shell: false,
6139
+ stdio: ["ignore", "pipe", "pipe"],
6140
+ windowsHide: true
6141
+ });
6142
+ const stdout = [];
6143
+ const stderr = [];
6144
+ let bytes = 0;
6145
+ let outcome = "completed";
6146
+ let settled = false;
6147
+ let timeout;
6148
+ const finish = (exitCode) => {
6149
+ if (settled)
6150
+ return;
6151
+ settled = true;
6152
+ if (timeout)
6153
+ clearTimeout(timeout);
6154
+ options.cancellationSignal?.removeEventListener("abort", cancel);
6155
+ resolvePromise({
6156
+ exitCode,
6157
+ outcome,
6158
+ stderr: Buffer.concat(stderr),
6159
+ stdout: Buffer.concat(stdout)
6160
+ });
6161
+ };
6162
+ const terminateAndFinish = (terminalOutcome) => {
6163
+ if (settled || outcome !== "completed")
6164
+ return;
6165
+ outcome = terminalOutcome;
6166
+ terminateBoundedProcess(child.pid);
6167
+ child.stdout.destroy();
6168
+ child.stderr.destroy();
6169
+ finish(-1);
6170
+ };
6171
+ function cancel() {
6172
+ terminateAndFinish("cancelled");
6173
+ }
6174
+ const capture = (target) => (chunk) => {
6175
+ if (outcome !== "completed")
6176
+ return;
6177
+ bytes += chunk.length;
6178
+ if (bytes > options.outputLimitBytes) {
6179
+ terminateAndFinish("overflow");
6180
+ return;
6181
+ }
6182
+ target.push(Buffer.from(chunk));
6183
+ };
6184
+ child.stdout.on("data", capture(stdout));
6185
+ child.stderr.on("data", capture(stderr));
6186
+ child.once("error", () => {
6187
+ outcome = "spawn_failed";
6188
+ finish(-1);
6189
+ });
6190
+ child.once("close", (exitCode) => finish(exitCode ?? -1));
6191
+ timeout = setTimeout(() => terminateAndFinish("timeout"), options.timeoutMilliseconds);
6192
+ timeout.unref();
6193
+ options.cancellationSignal?.addEventListener("abort", cancel, {
6194
+ once: true
6195
+ });
6196
+ if (options.cancellationSignal?.aborted)
6197
+ cancel();
6198
+ });
6199
+ }
6200
+ function throwIfCancelled(signal) {
6201
+ if (signal?.aborted)
6202
+ throw new JobEnvironmentCancelledError();
6203
+ }
6204
+ function terminateBoundedProcess(pid) {
6205
+ if (pid === void 0)
6206
+ return;
6207
+ try {
6208
+ process.kill((0, import_node_os3.platform)() === "win32" ? pid : -pid, "SIGKILL");
6209
+ } catch (error) {
6210
+ if (isNodeError(error, "ESRCH"))
6211
+ return;
6212
+ try {
6213
+ process.kill(pid, "SIGKILL");
6214
+ } catch {
6215
+ }
6216
+ }
6217
+ }
6218
+ function readJsonString(text3, start) {
6219
+ if (text3[start] !== '"')
6220
+ throw new Error("string expected");
6221
+ let escaped = false;
6222
+ for (let index2 = start + 1; index2 < text3.length; index2 += 1) {
6223
+ const character = text3[index2];
6224
+ if (escaped) {
6225
+ escaped = false;
6226
+ continue;
6227
+ }
6228
+ if (character === "\\") {
6229
+ escaped = true;
6230
+ continue;
6231
+ }
6232
+ if (character === '"') {
6233
+ return {
6234
+ next: index2 + 1,
6235
+ value: JSON.parse(text3.slice(start, index2 + 1))
6236
+ };
6237
+ }
6238
+ }
6239
+ throw new Error("unterminated string");
6240
+ }
6241
+ function skipWhitespace(text3, start) {
6242
+ let index2 = start;
6243
+ while (/\s/.test(text3[index2] ?? ""))
6244
+ index2 += 1;
6245
+ return index2;
6246
+ }
6247
+ function decodeUtf8(value, category) {
6248
+ try {
6249
+ return new TextDecoder("utf-8", { fatal: true }).decode(value);
6250
+ } catch {
6251
+ throw new Error(category);
6252
+ }
6253
+ }
6254
+ function freezeEnvironment(environment) {
6255
+ return Object.freeze({ ...environment });
6256
+ }
6257
+ function createEnvironmentMap() {
6258
+ return /* @__PURE__ */ Object.create(null);
6259
+ }
6260
+ function degradedCapture(category) {
6261
+ return { status: { category, state: "degraded" } };
6262
+ }
6263
+ function isNodeError(error, code) {
6264
+ return error instanceof Error && "code" in error && error.code === code;
6265
+ }
6266
+ var import_node_child_process2, import_promises8, import_node_os3, import_node_path6, defaultCaptureTimeoutMilliseconds, defaultCaptureOutputLimitBytes, defaultDirenvTimeoutMilliseconds, defaultDirenvOutputLimitBytes, shellCaptureScript, environmentNamePattern, JobEnvironmentError, JobEnvironmentCancelledError, ShellEnvironmentManager;
6267
+ var init_shell_environment = __esm({
6268
+ "../machine-connector/dist/runtime/shell-environment.js"() {
6269
+ "use strict";
6270
+ init_cjs_shims();
6271
+ import_node_child_process2 = require("child_process");
6272
+ import_promises8 = require("fs/promises");
6273
+ import_node_os3 = require("os");
6274
+ import_node_path6 = require("path");
6275
+ defaultCaptureTimeoutMilliseconds = 5e3;
6276
+ defaultCaptureOutputLimitBytes = 1048576;
6277
+ defaultDirenvTimeoutMilliseconds = 5e3;
6278
+ defaultDirenvOutputLimitBytes = 1048576;
6279
+ shellCaptureScript = `exec "$1" -e 'for (const [name, value] of Object.entries(process.env)) process.stdout.write(name + "=" + value + "\\0")'`;
6280
+ environmentNamePattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
6281
+ JobEnvironmentError = class extends Error {
6282
+ category;
6283
+ constructor(category) {
6284
+ super(`Local Machine Job environment resolution failed (${category})`);
6285
+ this.category = category;
6286
+ this.name = "JobEnvironmentError";
6287
+ }
6288
+ };
6289
+ JobEnvironmentCancelledError = class extends Error {
6290
+ constructor() {
6291
+ super("Local Machine Job environment resolution was cancelled");
6292
+ this.name = "JobEnvironmentCancelledError";
6293
+ }
6294
+ };
6295
+ ShellEnvironmentManager = class {
6296
+ captureOutputLimitBytes;
6297
+ captureTimeoutMilliseconds;
6298
+ daemonEnvironment;
6299
+ defaultShell;
6300
+ direnvOutputLimitBytes;
6301
+ direnvTimeoutMilliseconds;
6302
+ currentEnvironment;
6303
+ currentStatus = { state: "degraded" };
6304
+ refreshPromise;
6305
+ constructor(options = {}) {
6306
+ this.captureOutputLimitBytes = options.captureOutputLimitBytes ?? defaultCaptureOutputLimitBytes;
6307
+ this.captureTimeoutMilliseconds = options.captureTimeoutMilliseconds ?? defaultCaptureTimeoutMilliseconds;
6308
+ this.daemonEnvironment = freezeEnvironment(sanitizeEnvironment(options.daemonEnvironment ?? process.env));
6309
+ this.defaultShell = options.defaultShell ?? (0, import_node_os3.userInfo)().shell ?? "";
6310
+ this.direnvOutputLimitBytes = options.direnvOutputLimitBytes ?? defaultDirenvOutputLimitBytes;
6311
+ this.direnvTimeoutMilliseconds = options.direnvTimeoutMilliseconds ?? defaultDirenvTimeoutMilliseconds;
6312
+ this.currentEnvironment = this.daemonEnvironment;
6313
+ }
6314
+ async initialize() {
6315
+ const capture = await this.capture();
6316
+ this.currentEnvironment = capture.environment ?? this.daemonEnvironment;
6317
+ this.currentStatus = capture.status;
6318
+ return { ...this.currentStatus };
6319
+ }
6320
+ async refresh() {
6321
+ if (!this.refreshPromise) {
6322
+ this.refreshPromise = this.refreshOnce().finally(() => {
6323
+ this.refreshPromise = void 0;
6324
+ });
6325
+ }
6326
+ return await this.refreshPromise;
6327
+ }
6328
+ snapshot() {
6329
+ return this.currentEnvironment;
6330
+ }
6331
+ status() {
6332
+ return { ...this.currentStatus };
6333
+ }
6334
+ async resolveForJob(canonicalRoot, canonicalWorkingDirectory, explicitEnvironment, cancellationSignal) {
6335
+ throwIfCancelled(cancellationSignal);
6336
+ const relativeWorkingDirectory = (0, import_node_path6.relative)(canonicalRoot, canonicalWorkingDirectory);
6337
+ if (relativeWorkingDirectory === ".." || relativeWorkingDirectory.startsWith(`..${import_node_path6.sep}`) || (0, import_node_path6.isAbsolute)(relativeWorkingDirectory)) {
6338
+ throw new JobEnvironmentError("direnv_malformed");
6339
+ }
6340
+ const baseSnapshot = this.currentEnvironment;
6341
+ const envrcPath = await findNearestEnvrc(canonicalRoot, canonicalWorkingDirectory);
6342
+ throwIfCancelled(cancellationSignal);
6343
+ if (!envrcPath) {
6344
+ return freezeEnvironment({
6345
+ ...baseSnapshot,
6346
+ ...explicitEnvironment
6347
+ });
6348
+ }
6349
+ const direnvExecutable = await findExecutable("direnv", baseSnapshot.PATH);
6350
+ if (!direnvExecutable) {
6351
+ throw new JobEnvironmentError("direnv_missing");
6352
+ }
6353
+ const result = await executeBounded({
6354
+ argumentsList: ["export", "json"],
6355
+ cwd: canonicalWorkingDirectory,
6356
+ environment: baseSnapshot,
6357
+ executable: direnvExecutable,
6358
+ outputLimitBytes: this.direnvOutputLimitBytes,
6359
+ timeoutMilliseconds: this.direnvTimeoutMilliseconds,
6360
+ cancellationSignal
6361
+ });
6362
+ if (result.outcome === "cancelled") {
6363
+ throw new JobEnvironmentCancelledError();
6364
+ }
6365
+ if (result.outcome === "timeout") {
6366
+ throw new JobEnvironmentError("direnv_timeout");
6367
+ }
6368
+ if (result.outcome === "overflow") {
6369
+ throw new JobEnvironmentError("direnv_overflow");
6370
+ }
6371
+ if (result.outcome === "spawn_failed") {
6372
+ throw new JobEnvironmentError("direnv_spawn_failed");
6373
+ }
6374
+ if (result.exitCode !== 0) {
6375
+ const stderr = decodeUtf8(result.stderr, "direnv_malformed");
6376
+ throw new JobEnvironmentError(/blocked|not allowed|denied/i.test(stderr) ? "direnv_blocked" : "direnv_nonzero");
6377
+ }
6378
+ let parsedExports;
6379
+ try {
6380
+ parsedExports = parseDirenvJson(decodeUtf8(result.stdout, "direnv_malformed"));
6381
+ } catch {
6382
+ throw new JobEnvironmentError("direnv_malformed");
6383
+ }
6384
+ const exports2 = sanitizeDirenvExports(parsedExports);
6385
+ const environment = { ...baseSnapshot };
6386
+ for (const [name, value] of Object.entries(exports2)) {
6387
+ if (value === null) {
6388
+ delete environment[name];
6389
+ } else {
6390
+ environment[name] = value;
6391
+ }
6392
+ }
6393
+ return freezeEnvironment({
6394
+ ...environment,
6395
+ ...explicitEnvironment
6396
+ });
6397
+ }
6398
+ async capture() {
6399
+ let shell;
6400
+ try {
6401
+ shell = await validateShell(this.defaultShell);
6402
+ } catch {
6403
+ return degradedCapture("shell_environment_invalid_shell");
6404
+ }
6405
+ const result = await executeBounded({
6406
+ argumentsList: [
6407
+ "-l",
6408
+ "-i",
6409
+ "-c",
6410
+ shellCaptureScript,
6411
+ "moxt-shell-environment",
6412
+ process.execPath
6413
+ ],
6414
+ cwd: this.daemonEnvironment.HOME,
6415
+ environment: this.daemonEnvironment,
6416
+ executable: shell,
6417
+ outputLimitBytes: this.captureOutputLimitBytes,
6418
+ timeoutMilliseconds: this.captureTimeoutMilliseconds
6419
+ });
6420
+ if (result.outcome === "timeout") {
6421
+ return degradedCapture("shell_environment_timeout");
6422
+ }
6423
+ if (result.outcome === "overflow") {
6424
+ return degradedCapture("shell_environment_overflow");
6425
+ }
6426
+ if (result.outcome === "spawn_failed") {
6427
+ return degradedCapture("shell_environment_spawn_failed");
6428
+ }
6429
+ if (result.exitCode !== 0) {
6430
+ return degradedCapture("shell_environment_nonzero");
6431
+ }
6432
+ try {
6433
+ const snapshot = parseNullSeparatedEnvironment(result.stdout);
6434
+ return {
6435
+ environment: freezeEnvironment({
6436
+ ...this.daemonEnvironment,
6437
+ ...sanitizeEnvironment(snapshot)
6438
+ }),
6439
+ status: {
6440
+ capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
6441
+ state: "captured"
6442
+ }
6443
+ };
6444
+ } catch {
6445
+ return degradedCapture("shell_environment_malformed");
6446
+ }
6447
+ }
6448
+ async refreshOnce() {
6449
+ const capture = await this.capture();
6450
+ if (capture.environment) {
6451
+ this.currentEnvironment = capture.environment;
6452
+ this.currentStatus = capture.status;
6453
+ }
6454
+ return { ...capture.status };
6455
+ }
6456
+ };
6457
+ }
6458
+ });
6459
+
5976
6460
  // ../machine-connector/dist/runtime/version.js
5977
6461
  var connectorVersion;
5978
6462
  var init_version = __esm({
@@ -6160,12 +6644,12 @@ var init_relay_client = __esm({
6160
6644
  });
6161
6645
 
6162
6646
  // ../machine-connector/dist/runtime/runtime-logger.js
6163
- var import_promises8, RuntimeLogger;
6647
+ var import_promises9, RuntimeLogger;
6164
6648
  var init_runtime_logger = __esm({
6165
6649
  "../machine-connector/dist/runtime/runtime-logger.js"() {
6166
6650
  "use strict";
6167
6651
  init_cjs_shims();
6168
- import_promises8 = require("fs/promises");
6652
+ import_promises9 = require("fs/promises");
6169
6653
  RuntimeLogger = class {
6170
6654
  store;
6171
6655
  constructor(store) {
@@ -6179,7 +6663,7 @@ var init_runtime_logger = __esm({
6179
6663
  await this.write("error", message, metadata, this.store.runtimeErrorLogPath());
6180
6664
  }
6181
6665
  async write(level, message, metadata, path4) {
6182
- await (0, import_promises8.appendFile)(path4, `${JSON.stringify({
6666
+ await (0, import_promises9.appendFile)(path4, `${JSON.stringify({
6183
6667
  level,
6184
6668
  message,
6185
6669
  metadata,
@@ -6200,12 +6684,12 @@ function defaultRuntimeDirectory() {
6200
6684
  if (override) {
6201
6685
  return override;
6202
6686
  }
6203
- const homeDirectory = process.env.HOME ?? (0, import_node_os3.homedir)();
6204
- if ((0, import_node_os3.platform)() === "darwin") {
6205
- return (0, import_node_path6.join)(homeDirectory, "Library", "Application Support", "Moxt", "Machine Connector");
6687
+ const homeDirectory = process.env.HOME ?? (0, import_node_os4.homedir)();
6688
+ if ((0, import_node_os4.platform)() === "darwin") {
6689
+ return (0, import_node_path7.join)(homeDirectory, "Library", "Application Support", "Moxt", "Machine Connector");
6206
6690
  }
6207
- const stateHome = process.env.XDG_STATE_HOME ?? (0, import_node_path6.join)(homeDirectory, ".local", "state");
6208
- return (0, import_node_path6.join)(stateHome, "moxt", "machine-connector");
6691
+ const stateHome = process.env.XDG_STATE_HOME ?? (0, import_node_path7.join)(homeDirectory, ".local", "state");
6692
+ return (0, import_node_path7.join)(stateHome, "moxt", "machine-connector");
6209
6693
  }
6210
6694
  function isNodeErrorCode3(error, expectedCode) {
6211
6695
  if (!(error instanceof Error) || !("code" in error)) {
@@ -6213,14 +6697,14 @@ function isNodeErrorCode3(error, expectedCode) {
6213
6697
  }
6214
6698
  return error.code === expectedCode;
6215
6699
  }
6216
- var import_promises9, import_node_os3, import_node_path6, privateFileMode, privateDirectoryMode, MachineRuntimeStore;
6700
+ var import_promises10, import_node_os4, import_node_path7, privateFileMode, privateDirectoryMode, MachineRuntimeStore;
6217
6701
  var init_store = __esm({
6218
6702
  "../machine-connector/dist/runtime/store.js"() {
6219
6703
  "use strict";
6220
6704
  init_cjs_shims();
6221
- import_promises9 = require("fs/promises");
6222
- import_node_os3 = require("os");
6223
- import_node_path6 = require("path");
6705
+ import_promises10 = require("fs/promises");
6706
+ import_node_os4 = require("os");
6707
+ import_node_path7 = require("path");
6224
6708
  privateFileMode = 384;
6225
6709
  privateDirectoryMode = 448;
6226
6710
  MachineRuntimeStore = class {
@@ -6229,20 +6713,20 @@ var init_store = __esm({
6229
6713
  this.baseDirectory = baseDirectory;
6230
6714
  }
6231
6715
  async initialize() {
6232
- await (0, import_promises9.mkdir)(this.jobsDirectory(), {
6716
+ await (0, import_promises10.mkdir)(this.jobsDirectory(), {
6233
6717
  mode: privateDirectoryMode,
6234
6718
  recursive: true
6235
6719
  });
6236
- await (0, import_promises9.mkdir)(this.detachedProcessesDirectory(), {
6720
+ await (0, import_promises10.mkdir)(this.detachedProcessesDirectory(), {
6237
6721
  mode: privateDirectoryMode,
6238
6722
  recursive: true
6239
6723
  });
6240
- await (0, import_promises9.chmod)(this.baseDirectory, privateDirectoryMode);
6241
- await (0, import_promises9.chmod)(this.jobsDirectory(), privateDirectoryMode);
6242
- await (0, import_promises9.chmod)(this.detachedProcessesDirectory(), privateDirectoryMode);
6724
+ await (0, import_promises10.chmod)(this.baseDirectory, privateDirectoryMode);
6725
+ await (0, import_promises10.chmod)(this.jobsDirectory(), privateDirectoryMode);
6726
+ await (0, import_promises10.chmod)(this.detachedProcessesDirectory(), privateDirectoryMode);
6243
6727
  }
6244
6728
  async getCanonicalRoot(rootPath) {
6245
- return await (0, import_promises9.realpath)(rootPath);
6729
+ return await (0, import_promises10.realpath)(rootPath);
6246
6730
  }
6247
6731
  async readIdentity() {
6248
6732
  return await this.readOptionalJson(this.identityPath());
@@ -6285,7 +6769,7 @@ var init_store = __esm({
6285
6769
  await this.writePrivateJson(this.serviceManagerPath(), serviceManager);
6286
6770
  }
6287
6771
  async removeServiceManager() {
6288
- await (0, import_promises9.rm)(this.serviceManagerPath(), { force: true });
6772
+ await (0, import_promises10.rm)(this.serviceManagerPath(), { force: true });
6289
6773
  }
6290
6774
  async readJob(jobId) {
6291
6775
  return await this.readOptionalJson(this.jobPath(jobId));
@@ -6296,7 +6780,7 @@ var init_store = __esm({
6296
6780
  async listJobs() {
6297
6781
  let names = [];
6298
6782
  try {
6299
- names = await (0, import_promises9.readdir)(this.jobsDirectory());
6783
+ names = await (0, import_promises10.readdir)(this.jobsDirectory());
6300
6784
  } catch (error) {
6301
6785
  if (isNodeErrorCode3(error, "ENOENT")) {
6302
6786
  return [];
@@ -6305,7 +6789,7 @@ var init_store = __esm({
6305
6789
  }
6306
6790
  const jobs = [];
6307
6791
  for (const name of names.filter((entry) => entry.endsWith(".json"))) {
6308
- const job = await this.readOptionalJson((0, import_node_path6.join)(this.jobsDirectory(), name));
6792
+ const job = await this.readOptionalJson((0, import_node_path7.join)(this.jobsDirectory(), name));
6309
6793
  if (job.value) {
6310
6794
  jobs.push(job.value);
6311
6795
  }
@@ -6313,7 +6797,7 @@ var init_store = __esm({
6313
6797
  return jobs;
6314
6798
  }
6315
6799
  async deleteJob(jobId) {
6316
- await (0, import_promises9.rm)(this.jobPath(jobId), { force: true });
6800
+ await (0, import_promises10.rm)(this.jobPath(jobId), { force: true });
6317
6801
  }
6318
6802
  async writeDetachedProcess(resource) {
6319
6803
  await this.writePrivateJson(this.detachedProcessPath(resource.jobId), resource);
@@ -6321,7 +6805,7 @@ var init_store = __esm({
6321
6805
  async listDetachedProcesses() {
6322
6806
  let names = [];
6323
6807
  try {
6324
- names = await (0, import_promises9.readdir)(this.detachedProcessesDirectory());
6808
+ names = await (0, import_promises10.readdir)(this.detachedProcessesDirectory());
6325
6809
  } catch (error) {
6326
6810
  if (isNodeErrorCode3(error, "ENOENT")) {
6327
6811
  return [];
@@ -6330,7 +6814,7 @@ var init_store = __esm({
6330
6814
  }
6331
6815
  const resources = [];
6332
6816
  for (const name of names.filter((entry) => entry.endsWith(".json"))) {
6333
- const resource = await this.readOptionalJson((0, import_node_path6.join)(this.detachedProcessesDirectory(), name));
6817
+ const resource = await this.readOptionalJson((0, import_node_path7.join)(this.detachedProcessesDirectory(), name));
6334
6818
  if (resource.value) {
6335
6819
  resources.push(resource.value);
6336
6820
  }
@@ -6338,52 +6822,52 @@ var init_store = __esm({
6338
6822
  return resources;
6339
6823
  }
6340
6824
  async deleteDetachedProcess(jobId) {
6341
- await (0, import_promises9.rm)(this.detachedProcessPath(jobId), { force: true });
6825
+ await (0, import_promises10.rm)(this.detachedProcessPath(jobId), { force: true });
6342
6826
  }
6343
6827
  runtimeLogPath() {
6344
- return (0, import_node_path6.join)(this.baseDirectory, "machine-connector.log");
6828
+ return (0, import_node_path7.join)(this.baseDirectory, "machine-connector.log");
6345
6829
  }
6346
6830
  runtimeErrorLogPath() {
6347
- return (0, import_node_path6.join)(this.baseDirectory, "machine-connector.error.log");
6831
+ return (0, import_node_path7.join)(this.baseDirectory, "machine-connector.error.log");
6348
6832
  }
6349
6833
  runtimeStatusPath() {
6350
- return (0, import_node_path6.join)(this.baseDirectory, "runtime-status.json");
6834
+ return (0, import_node_path7.join)(this.baseDirectory, "runtime-status.json");
6351
6835
  }
6352
6836
  runtimeSocketPath() {
6353
- if ((0, import_node_os3.platform)() === "win32") {
6837
+ if ((0, import_node_os4.platform)() === "win32") {
6354
6838
  return String.raw`\\.\pipe\moxt-machine-connector`;
6355
6839
  }
6356
- return (0, import_node_path6.join)(this.baseDirectory, "machine-connector.sock");
6840
+ return (0, import_node_path7.join)(this.baseDirectory, "machine-connector.sock");
6357
6841
  }
6358
6842
  daemonLockPath() {
6359
- return (0, import_node_path6.join)(this.baseDirectory, "daemon.lock");
6843
+ return (0, import_node_path7.join)(this.baseDirectory, "daemon.lock");
6360
6844
  }
6361
6845
  reconcileLockPath() {
6362
- return (0, import_node_path6.join)(this.baseDirectory, "daemon-reconcile.lock");
6846
+ return (0, import_node_path7.join)(this.baseDirectory, "daemon-reconcile.lock");
6363
6847
  }
6364
6848
  connectionsPath() {
6365
- return (0, import_node_path6.join)(this.baseDirectory, "connections.json");
6849
+ return (0, import_node_path7.join)(this.baseDirectory, "connections.json");
6366
6850
  }
6367
6851
  detachedProcessesDirectory() {
6368
- return (0, import_node_path6.join)(this.baseDirectory, "detached-processes");
6852
+ return (0, import_node_path7.join)(this.baseDirectory, "detached-processes");
6369
6853
  }
6370
6854
  detachedProcessPath(jobId) {
6371
- return (0, import_node_path6.join)(this.detachedProcessesDirectory(), `${jobId}.json`);
6855
+ return (0, import_node_path7.join)(this.detachedProcessesDirectory(), `${jobId}.json`);
6372
6856
  }
6373
6857
  identityPath() {
6374
- return (0, import_node_path6.join)(this.baseDirectory, "identity.json");
6858
+ return (0, import_node_path7.join)(this.baseDirectory, "identity.json");
6375
6859
  }
6376
6860
  serviceManagerPath() {
6377
- return (0, import_node_path6.join)(this.baseDirectory, "service-manager.json");
6861
+ return (0, import_node_path7.join)(this.baseDirectory, "service-manager.json");
6378
6862
  }
6379
6863
  privateKeyPath() {
6380
- return (0, import_node_path6.join)(this.baseDirectory, "device-private-key.pem");
6864
+ return (0, import_node_path7.join)(this.baseDirectory, "device-private-key.pem");
6381
6865
  }
6382
6866
  jobsDirectory() {
6383
- return (0, import_node_path6.join)(this.baseDirectory, "jobs");
6867
+ return (0, import_node_path7.join)(this.baseDirectory, "jobs");
6384
6868
  }
6385
6869
  jobPath(jobId) {
6386
- return (0, import_node_path6.join)(this.jobsDirectory(), `${jobId}.json`);
6870
+ return (0, import_node_path7.join)(this.jobsDirectory(), `${jobId}.json`);
6387
6871
  }
6388
6872
  async readOptionalJson(path4) {
6389
6873
  const content3 = await this.readOptionalText(path4);
@@ -6394,7 +6878,7 @@ var init_store = __esm({
6394
6878
  }
6395
6879
  async readOptionalText(path4) {
6396
6880
  try {
6397
- return { value: await (0, import_promises9.readFile)(path4, "utf8") };
6881
+ return { value: await (0, import_promises10.readFile)(path4, "utf8") };
6398
6882
  } catch (error) {
6399
6883
  if (isNodeErrorCode3(error, "ENOENT")) {
6400
6884
  return {};
@@ -6407,17 +6891,17 @@ var init_store = __esm({
6407
6891
  `);
6408
6892
  }
6409
6893
  async writePrivateText(path4, value) {
6410
- await (0, import_promises9.mkdir)((0, import_node_path6.dirname)(path4), {
6894
+ await (0, import_promises10.mkdir)((0, import_node_path7.dirname)(path4), {
6411
6895
  mode: privateDirectoryMode,
6412
6896
  recursive: true
6413
6897
  });
6414
6898
  const temporaryPath = `${path4}.${process.pid}.tmp`;
6415
- await (0, import_promises9.writeFile)(temporaryPath, value, {
6899
+ await (0, import_promises10.writeFile)(temporaryPath, value, {
6416
6900
  encoding: "utf8",
6417
6901
  mode: privateFileMode
6418
6902
  });
6419
- await (0, import_promises9.chmod)(temporaryPath, privateFileMode);
6420
- await (0, import_promises9.rename)(temporaryPath, path4);
6903
+ await (0, import_promises10.chmod)(temporaryPath, privateFileMode);
6904
+ await (0, import_promises10.rename)(temporaryPath, path4);
6421
6905
  }
6422
6906
  };
6423
6907
  }
@@ -6447,12 +6931,12 @@ function delay4(milliseconds) {
6447
6931
  setTimeout(resolvePromise, milliseconds);
6448
6932
  });
6449
6933
  }
6450
- var import_node_os4, import_node_crypto5, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumEventUploadRetryMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, EventUploadOutcome, MachineConnectorDaemon;
6934
+ var import_node_os5, import_node_crypto5, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumEventUploadRetryMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, EventUploadOutcome, MachineConnectorDaemon;
6451
6935
  var init_daemon = __esm({
6452
6936
  "../machine-connector/dist/runtime/daemon.js"() {
6453
6937
  "use strict";
6454
6938
  init_cjs_shims();
6455
- import_node_os4 = require("os");
6939
+ import_node_os5 = require("os");
6456
6940
  import_node_crypto5 = require("crypto");
6457
6941
  init_enums();
6458
6942
  init_contracts();
@@ -6464,6 +6948,7 @@ var init_daemon = __esm({
6464
6948
  init_local_ipc();
6465
6949
  init_process_lock();
6466
6950
  init_process_executor();
6951
+ init_shell_environment();
6467
6952
  init_relay_client();
6468
6953
  init_runtime_logger();
6469
6954
  init_runtime_types();
@@ -6510,6 +6995,7 @@ var init_daemon = __esm({
6510
6995
  random;
6511
6996
  terminalForegroundBudgetMilliseconds;
6512
6997
  cliVersion;
6998
+ shellEnvironmentManager;
6513
6999
  constructor(store = new MachineRuntimeStore(), options = {}) {
6514
7000
  this.store = store;
6515
7001
  this.lifetimeSettled = new Promise((resolvePromise) => {
@@ -6520,6 +7006,7 @@ var init_daemon = __esm({
6520
7006
  });
6521
7007
  this.logger = new RuntimeLogger(store);
6522
7008
  this.cliVersion = options.cliVersion;
7009
+ this.shellEnvironmentManager = options.shellEnvironmentManager ?? new ShellEnvironmentManager();
6523
7010
  this.leaseSafetyMarginMilliseconds = options.leaseSafetyMarginMilliseconds ?? defaultLeaseSafetyMarginMilliseconds;
6524
7011
  this.leaseSeconds = options.leaseSeconds ?? defaultLeaseSeconds;
6525
7012
  this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds;
@@ -6538,14 +7025,27 @@ var init_daemon = __esm({
6538
7025
  throw new Error("Another Moxt Machine Connector daemon is already running or starting");
6539
7026
  }
6540
7027
  this.throwIfStopping();
7028
+ const shellEnvironmentStatus = await this.shellEnvironmentManager.initialize();
7029
+ await this.logger.info("Local Machine shell environment initialized", {
7030
+ category: shellEnvironmentStatus.category,
7031
+ state: shellEnvironmentStatus.state
7032
+ });
7033
+ this.throwIfStopping();
6541
7034
  await this.recoverInterruptedJobs();
6542
7035
  this.throwIfStopping();
6543
- this.ipcServer = new LocalIpcServer(this.store, () => this.getStatus());
7036
+ this.ipcServer = new LocalIpcServer(this.store, () => this.getStatus(), async () => {
7037
+ const status = await this.shellEnvironmentManager.refresh();
7038
+ await this.logger.info("Local Machine shell environment refreshed", {
7039
+ category: status.category,
7040
+ state: status.state
7041
+ });
7042
+ return status;
7043
+ });
6544
7044
  await this.ipcServer.start();
6545
7045
  this.throwIfStopping();
6546
7046
  await this.logger.info("Moxt Machine Connector started", {
6547
7047
  connectorInstanceId: this.connectorInstanceId,
6548
- hostname: (0, import_node_os4.hostname)(),
7048
+ hostname: (0, import_node_os5.hostname)(),
6549
7049
  version: connectorVersion
6550
7050
  });
6551
7051
  this.connections = await this.store.listConnections();
@@ -6611,6 +7111,7 @@ var init_daemon = __esm({
6611
7111
  connectorInstanceId: this.connectorInstanceId,
6612
7112
  pid: process.pid,
6613
7113
  startedAt: this.startedAt,
7114
+ shellEnvironment: this.shellEnvironmentManager.status(),
6614
7115
  version: connectorVersion
6615
7116
  };
6616
7117
  }
@@ -6824,12 +7325,27 @@ var init_daemon = __esm({
6824
7325
  const { claim } = activeJob;
6825
7326
  const registerProcess = activeJob.cancellation.register.bind(activeJob.cancellation);
6826
7327
  const canSpawn = activeJob.cancellation.canSpawn.bind(activeJob.cancellation);
7328
+ const resolveEnvironment = async (workingDirectory2, explicitEnvironment) => {
7329
+ try {
7330
+ return await this.shellEnvironmentManager.resolveForJob(activeJob.connection.rootPath, workingDirectory2, explicitEnvironment, activeJob.cancellation.signal());
7331
+ } catch (error) {
7332
+ if (error instanceof JobEnvironmentCancelledError) {
7333
+ return void 0;
7334
+ }
7335
+ throw error;
7336
+ }
7337
+ };
7338
+ if (!canSpawn()) {
7339
+ return this.cancellationResult(activeJob);
7340
+ }
6827
7341
  if (claim.kind === MachineJobKind.Command) {
6828
7342
  const request2 = claim.requestPayload;
6829
- const result = await executeCommand(activeJob.connection.rootPath, {
6830
- ...request2,
6831
- relativeWorkingDirectory: claim.relativeWorkingDirectory
6832
- }, {
7343
+ const workingDirectory2 = await resolveCanonicalWorkingDirectory(activeJob.connection.rootPath, claim.relativeWorkingDirectory);
7344
+ const environment2 = await resolveEnvironment(workingDirectory2, request2.environment);
7345
+ if (!environment2 || !canSpawn()) {
7346
+ return this.cancellationResult(activeJob);
7347
+ }
7348
+ const result = await executeProcess(request2.executable, request2.arguments, workingDirectory2, environment2, request2.stdin, request2.timeoutSeconds, {
6833
7349
  canSpawn,
6834
7350
  onOutput: async (output) => {
6835
7351
  if (activeJob.cancellation.currentReason() !== void 0) {
@@ -6856,6 +7372,10 @@ var init_daemon = __esm({
6856
7372
  if (!canSpawn()) {
6857
7373
  return this.cancellationResult(activeJob);
6858
7374
  }
7375
+ const environment = await resolveEnvironment(workingDirectory, {});
7376
+ if (!environment || !canSpawn()) {
7377
+ return this.cancellationResult(activeJob);
7378
+ }
6859
7379
  const callbacks = {
6860
7380
  canSpawn,
6861
7381
  onEvent: async (event) => {
@@ -6877,7 +7397,7 @@ var init_daemon = __esm({
6877
7397
  };
6878
7398
  if (claim.kind === MachineJobKind.CodexStart) {
6879
7399
  const request2 = claim.requestPayload;
6880
- const result = await executeCodexStart(workingDirectory, this.store.baseDirectory, {
7400
+ const result = await executeCodexStart(workingDirectory, this.store.baseDirectory, environment, {
6881
7401
  ...request2,
6882
7402
  relativeWorkingDirectory: claim.relativeWorkingDirectory
6883
7403
  }, callbacks);
@@ -6891,7 +7411,7 @@ var init_daemon = __esm({
6891
7411
  }
6892
7412
  if (claim.kind === MachineJobKind.CodexReply) {
6893
7413
  const request2 = claim.requestPayload;
6894
- const result = await executeCodexReply(workingDirectory, this.store.baseDirectory, {
7414
+ const result = await executeCodexReply(workingDirectory, this.store.baseDirectory, environment, {
6895
7415
  ...request2,
6896
7416
  relativeWorkingDirectory: claim.relativeWorkingDirectory
6897
7417
  }, callbacks);
@@ -6906,7 +7426,7 @@ var init_daemon = __esm({
6906
7426
  }
6907
7427
  if (claim.kind === MachineJobKind.ClaudeStart) {
6908
7428
  const request2 = claim.requestPayload;
6909
- const result = await executeClaudeStart(workingDirectory, {
7429
+ const result = await executeClaudeStart(workingDirectory, environment, {
6910
7430
  ...request2,
6911
7431
  relativeWorkingDirectory: claim.relativeWorkingDirectory
6912
7432
  }, callbacks);
@@ -6920,7 +7440,7 @@ var init_daemon = __esm({
6920
7440
  }
6921
7441
  if (claim.kind === MachineJobKind.ClaudeReply) {
6922
7442
  const request2 = claim.requestPayload;
6923
- const result = await executeClaudeReply(workingDirectory, {
7443
+ const result = await executeClaudeReply(workingDirectory, environment, {
6924
7444
  ...request2,
6925
7445
  relativeWorkingDirectory: claim.relativeWorkingDirectory
6926
7446
  }, callbacks);
@@ -7393,12 +7913,12 @@ async function installUserService(store, request2, runtime = defaultServiceManag
7393
7913
  }
7394
7914
  function createServiceEnvironment(options) {
7395
7915
  const inheritedPath = options.environment.PATH ?? process.env.PATH ?? "";
7396
- const nodeDirectory = (0, import_node_path7.dirname)(options.nodePath);
7397
- const pathEntries = [nodeDirectory, ...inheritedPath.split(import_node_path7.delimiter)].filter((entry, index2, entries) => entry.length > 0 && entries.indexOf(entry) === index2);
7916
+ const nodeDirectory = (0, import_node_path8.dirname)(options.nodePath);
7917
+ const pathEntries = [nodeDirectory, ...inheritedPath.split(import_node_path8.delimiter)].filter((entry, index2, entries) => entry.length > 0 && entries.indexOf(entry) === index2);
7398
7918
  return {
7399
7919
  ...options.environment,
7400
- HOME: options.environment.HOME ?? process.env.HOME ?? (0, import_node_os5.homedir)(),
7401
- PATH: pathEntries.join(import_node_path7.delimiter)
7920
+ HOME: options.environment.HOME ?? process.env.HOME ?? (0, import_node_os6.homedir)(),
7921
+ PATH: pathEntries.join(import_node_path8.delimiter)
7402
7922
  };
7403
7923
  }
7404
7924
  async function restartUserService(store, runtime = defaultServiceManagerRuntime) {
@@ -7581,7 +8101,7 @@ async function uninstallManager(manager, store, runtime) {
7581
8101
  "bootout",
7582
8102
  `gui/${process.getuid?.() ?? 0}/${launchAgentLabel}`
7583
8103
  ]);
7584
- await (0, import_promises10.rm)(launchAgentPath(), { force: true });
8104
+ await (0, import_promises11.rm)(launchAgentPath(), { force: true });
7585
8105
  return;
7586
8106
  }
7587
8107
  if (manager === UserServiceManager.Systemd) {
@@ -7591,7 +8111,7 @@ async function uninstallManager(manager, store, runtime) {
7591
8111
  "--now",
7592
8112
  "moxt-machine-connector.service"
7593
8113
  ]);
7594
- await (0, import_promises10.rm)(systemdUnitPath(), { force: true });
8114
+ await (0, import_promises11.rm)(systemdUnitPath(), { force: true });
7595
8115
  await runCommandIgnoringFailure(runtime, "systemctl", [
7596
8116
  "--user",
7597
8117
  "daemon-reload"
@@ -7605,7 +8125,7 @@ async function uninstallManager(manager, store, runtime) {
7605
8125
  supervisorProgramName
7606
8126
  ]);
7607
8127
  await runCommandIgnoringFailure(runtime, "supervisorctl", ["-c", supervisorConfigPath(store), "shutdown"]);
7608
- await (0, import_promises10.rm)(supervisorDirectory(store), {
8128
+ await (0, import_promises11.rm)(supervisorDirectory(store), {
7609
8129
  force: true,
7610
8130
  recursive: true
7611
8131
  });
@@ -7631,7 +8151,7 @@ async function readStoredServiceManager(store) {
7631
8151
  }
7632
8152
  async function readManagedServiceDefinition(manager, store) {
7633
8153
  try {
7634
- return await (0, import_promises10.readFile)(managedServiceDefinitionPath(manager, store), "utf8");
8154
+ return await (0, import_promises11.readFile)(managedServiceDefinitionPath(manager, store), "utf8");
7635
8155
  } catch (error) {
7636
8156
  if (isNodeErrorCode4(error, "ENOENT"))
7637
8157
  return void 0;
@@ -7640,8 +8160,8 @@ async function readManagedServiceDefinition(manager, store) {
7640
8160
  }
7641
8161
  async function restoreManagedServiceDefinition(manager, store, definition2, runtime) {
7642
8162
  const path4 = managedServiceDefinitionPath(manager, store);
7643
- await (0, import_promises10.mkdir)((0, import_node_path7.dirname)(path4), { recursive: true });
7644
- await (0, import_promises10.writeFile)(path4, definition2, { encoding: "utf8", mode: 384 });
8163
+ await (0, import_promises11.mkdir)((0, import_node_path8.dirname)(path4), { recursive: true });
8164
+ await (0, import_promises11.writeFile)(path4, definition2, { encoding: "utf8", mode: 384 });
7645
8165
  if (manager === UserServiceManager.Launchd) {
7646
8166
  const domain = `gui/${process.getuid?.() ?? 0}`;
7647
8167
  await runCommandIgnoringFailure(runtime, "launchctl", [
@@ -7716,10 +8236,10 @@ function automaticSelectionDetail(manager) {
7716
8236
  }
7717
8237
  async function installLaunchAgent(store, options, runtime) {
7718
8238
  const path4 = launchAgentPath();
7719
- await (0, import_promises10.mkdir)((0, import_node_path7.dirname)(path4), { recursive: true });
8239
+ await (0, import_promises11.mkdir)((0, import_node_path8.dirname)(path4), { recursive: true });
7720
8240
  const programArguments = [
7721
8241
  options.nodePath,
7722
- (0, import_node_path7.resolve)(options.entrypointPath),
8242
+ (0, import_node_path8.resolve)(options.entrypointPath),
7723
8243
  ...options.commandArguments
7724
8244
  ];
7725
8245
  const plist = `<?xml version="1.0" encoding="UTF-8"?>
@@ -7750,7 +8270,7 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
7750
8270
  </dict>
7751
8271
  </plist>
7752
8272
  `;
7753
- await (0, import_promises10.writeFile)(path4, plist, { encoding: "utf8", mode: 384 });
8273
+ await (0, import_promises11.writeFile)(path4, plist, { encoding: "utf8", mode: 384 });
7754
8274
  const domain = `gui/${process.getuid?.() ?? 0}`;
7755
8275
  await runCommandIgnoringFailure(runtime, "launchctl", [
7756
8276
  "bootout",
@@ -7766,10 +8286,10 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
7766
8286
  }
7767
8287
  async function installSystemdUserService(store, options, runtime) {
7768
8288
  const path4 = systemdUnitPath();
7769
- await (0, import_promises10.mkdir)((0, import_node_path7.dirname)(path4), { recursive: true });
8289
+ await (0, import_promises11.mkdir)((0, import_node_path8.dirname)(path4), { recursive: true });
7770
8290
  const command = [
7771
8291
  options.nodePath,
7772
- (0, import_node_path7.resolve)(options.entrypointPath),
8292
+ (0, import_node_path8.resolve)(options.entrypointPath),
7773
8293
  ...options.commandArguments
7774
8294
  ].map(escapeSystemdArgument).join(" ");
7775
8295
  const unit = `[Unit]
@@ -7788,7 +8308,7 @@ ${Object.entries(options.environment).map(([name, value]) => `Environment=${esca
7788
8308
  [Install]
7789
8309
  WantedBy=default.target
7790
8310
  `;
7791
- await (0, import_promises10.writeFile)(path4, unit, { encoding: "utf8", mode: 384 });
8311
+ await (0, import_promises11.writeFile)(path4, unit, { encoding: "utf8", mode: 384 });
7792
8312
  await runtime.run("systemctl", ["--user", "daemon-reload"]);
7793
8313
  await runtime.run("systemctl", [
7794
8314
  "--user",
@@ -7798,21 +8318,21 @@ WantedBy=default.target
7798
8318
  ]);
7799
8319
  await runCommandIgnoringFailure(runtime, "loginctl", [
7800
8320
  "enable-linger",
7801
- (0, import_node_os5.userInfo)().username
8321
+ (0, import_node_os6.userInfo)().username
7802
8322
  ]);
7803
8323
  }
7804
8324
  async function installSupervisorUserService(store, options, runtime) {
7805
8325
  const directory = supervisorDirectory(store);
7806
8326
  const configPath = supervisorConfigPath(store);
7807
- await (0, import_promises10.mkdir)(directory, { recursive: true, mode: 448 });
7808
- await (0, import_promises10.writeFile)(configPath, createSupervisorConfiguration(store, options), {
8327
+ await (0, import_promises11.mkdir)(directory, { recursive: true, mode: 448 });
8328
+ await (0, import_promises11.writeFile)(configPath, createSupervisorConfiguration(store, options), {
7809
8329
  encoding: "utf8",
7810
8330
  mode: 384
7811
8331
  });
7812
8332
  const supervisorWasRunning = await supervisorIsRunning(store, runtime);
7813
8333
  if (!supervisorWasRunning) {
7814
- await (0, import_promises10.rm)(supervisorSocketPath(store), { force: true });
7815
- await (0, import_promises10.rm)(supervisorPidPath(store), { force: true });
8334
+ await (0, import_promises11.rm)(supervisorSocketPath(store), { force: true });
8335
+ await (0, import_promises11.rm)(supervisorPidPath(store), { force: true });
7816
8336
  await runtime.run("supervisord", ["-c", configPath]);
7817
8337
  await waitForSupervisorControl(store, runtime);
7818
8338
  return;
@@ -7822,7 +8342,7 @@ async function installSupervisorUserService(store, options, runtime) {
7822
8342
  function createSupervisorConfiguration(store, options) {
7823
8343
  const command = [
7824
8344
  options.nodePath,
7825
- (0, import_node_path7.resolve)(options.entrypointPath),
8345
+ (0, import_node_path8.resolve)(options.entrypointPath),
7826
8346
  ...options.commandArguments
7827
8347
  ].map(escapeSupervisorArgument).join(" ");
7828
8348
  const environment = Object.entries(options.environment).map(([name, value]) => `${name}="${escapeSupervisorEnvironment(value)}"`).join(",");
@@ -7846,7 +8366,7 @@ serverurl=unix://${supervisorSocketPath(store)}
7846
8366
 
7847
8367
  [program:${supervisorProgramName}]
7848
8368
  command=${command}
7849
- directory=${escapeSupervisorPath((0, import_node_path7.dirname)((0, import_node_path7.resolve)(options.entrypointPath)))}
8369
+ directory=${escapeSupervisorPath((0, import_node_path8.dirname)((0, import_node_path8.resolve)(options.entrypointPath)))}
7850
8370
  environment=${environment}
7851
8371
  autostart=true
7852
8372
  autorestart=true
@@ -7867,8 +8387,8 @@ stderr_logfile_backups=3
7867
8387
  async function restartSupervisorUserService(store, runtime) {
7868
8388
  const configPath = supervisorConfigPath(store);
7869
8389
  if (!await supervisorIsRunning(store, runtime)) {
7870
- await (0, import_promises10.rm)(supervisorSocketPath(store), { force: true });
7871
- await (0, import_promises10.rm)(supervisorPidPath(store), { force: true });
8390
+ await (0, import_promises11.rm)(supervisorSocketPath(store), { force: true });
8391
+ await (0, import_promises11.rm)(supervisorPidPath(store), { force: true });
7872
8392
  await runtime.run("supervisord", ["-c", configPath]);
7873
8393
  await waitForSupervisorControl(store, runtime);
7874
8394
  return;
@@ -7944,26 +8464,26 @@ async function waitForSupervisorControl(store, runtime) {
7944
8464
  throw new Error("Supervisor did not become ready within 5 seconds");
7945
8465
  }
7946
8466
  function launchAgentPath() {
7947
- return (0, import_node_path7.join)(process.env.HOME ?? (0, import_node_os5.homedir)(), "Library", "LaunchAgents", `${launchAgentLabel}.plist`);
8467
+ return (0, import_node_path8.join)(process.env.HOME ?? (0, import_node_os6.homedir)(), "Library", "LaunchAgents", `${launchAgentLabel}.plist`);
7948
8468
  }
7949
8469
  function systemdUnitPath() {
7950
- const configHome = process.env.XDG_CONFIG_HOME ?? (0, import_node_path7.join)(process.env.HOME ?? (0, import_node_os5.homedir)(), ".config");
7951
- return (0, import_node_path7.join)(configHome, "systemd", "user", "moxt-machine-connector.service");
8470
+ const configHome = process.env.XDG_CONFIG_HOME ?? (0, import_node_path8.join)(process.env.HOME ?? (0, import_node_os6.homedir)(), ".config");
8471
+ return (0, import_node_path8.join)(configHome, "systemd", "user", "moxt-machine-connector.service");
7952
8472
  }
7953
8473
  function supervisorDirectory(store) {
7954
- return (0, import_node_path7.join)(store.baseDirectory, "supervisor");
8474
+ return (0, import_node_path8.join)(store.baseDirectory, "supervisor");
7955
8475
  }
7956
8476
  function supervisorConfigPath(store) {
7957
- return (0, import_node_path7.join)(supervisorDirectory(store), "supervisord.conf");
8477
+ return (0, import_node_path8.join)(supervisorDirectory(store), "supervisord.conf");
7958
8478
  }
7959
8479
  function supervisorSocketPath(store) {
7960
- return (0, import_node_path7.join)(supervisorDirectory(store), "supervisor.sock");
8480
+ return (0, import_node_path8.join)(supervisorDirectory(store), "supervisor.sock");
7961
8481
  }
7962
8482
  function supervisorPidPath(store) {
7963
- return (0, import_node_path7.join)(supervisorDirectory(store), "supervisord.pid");
8483
+ return (0, import_node_path8.join)(supervisorDirectory(store), "supervisord.pid");
7964
8484
  }
7965
8485
  function supervisorLogPath(store) {
7966
- return (0, import_node_path7.join)(supervisorDirectory(store), "supervisord.log");
8486
+ return (0, import_node_path8.join)(supervisorDirectory(store), "supervisord.log");
7967
8487
  }
7968
8488
  async function commandSucceeds(runtime, command, argumentsList) {
7969
8489
  try {
@@ -8024,17 +8544,17 @@ function delay5(milliseconds) {
8024
8544
  setTimeout(resolvePromise, milliseconds);
8025
8545
  });
8026
8546
  }
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;
8547
+ var import_node_child_process3, import_promises11, import_node_os6, import_node_path8, import_node_util2, execFileAsync, launchAgentLabel, serviceManagerProbeTimeoutMilliseconds, serviceManagerMutationTimeoutMilliseconds, supervisorProgramName, ServiceManagerPreference, UserServiceManager, defaultServiceManagerRuntime;
8028
8548
  var init_service_manager = __esm({
8029
8549
  "../machine-connector/dist/runtime/service-manager.js"() {
8030
8550
  "use strict";
8031
8551
  init_cjs_shims();
8032
- import_node_child_process2 = require("child_process");
8033
- import_promises10 = require("fs/promises");
8034
- import_node_os5 = require("os");
8035
- import_node_path7 = require("path");
8552
+ import_node_child_process3 = require("child_process");
8553
+ import_promises11 = require("fs/promises");
8554
+ import_node_os6 = require("os");
8555
+ import_node_path8 = require("path");
8036
8556
  import_node_util2 = require("util");
8037
- execFileAsync = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
8557
+ execFileAsync = (0, import_node_util2.promisify)(import_node_child_process3.execFile);
8038
8558
  launchAgentLabel = "ai.moxt.machine-connector";
8039
8559
  serviceManagerProbeTimeoutMilliseconds = 5e3;
8040
8560
  serviceManagerMutationTimeoutMilliseconds = 3e4;
@@ -8052,7 +8572,7 @@ var init_service_manager = __esm({
8052
8572
  UserServiceManager2["Systemd"] = "systemd";
8053
8573
  })(UserServiceManager || (UserServiceManager = {}));
8054
8574
  defaultServiceManagerRuntime = {
8055
- operatingSystem: (0, import_node_os5.platform)(),
8575
+ operatingSystem: (0, import_node_os6.platform)(),
8056
8576
  async run(command, argumentsList, options) {
8057
8577
  const result = await execFileAsync(command, argumentsList, {
8058
8578
  encoding: "utf8",
@@ -8110,9 +8630,9 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
8110
8630
  try {
8111
8631
  refresh = await refreshManagedUserService(store, {
8112
8632
  commandArguments: [...options.commandArguments],
8113
- entrypointPath: (0, import_node_path8.resolve)(options.entrypointPath),
8633
+ entrypointPath: (0, import_node_path9.resolve)(options.entrypointPath),
8114
8634
  environment: { ...options.environment },
8115
- nodePath: (0, import_node_path8.resolve)(options.nodePath)
8635
+ nodePath: (0, import_node_path9.resolve)(options.nodePath)
8116
8636
  });
8117
8637
  if (!refresh) {
8118
8638
  throw new Error("The Connector service is no longer managed by Moxt");
@@ -8143,10 +8663,10 @@ async function validateCliEntrypoint(options, store) {
8143
8663
  if (options.commandArguments.length !== 2 || options.commandArguments[0] !== "machine" || options.commandArguments[1] !== "daemon") {
8144
8664
  throw new Error("The managed daemon command must be `machine daemon`");
8145
8665
  }
8146
- const nodePath = await (0, import_promises11.realpath)((0, import_node_path8.resolve)(options.nodePath));
8147
- const entrypointPath = await (0, import_promises11.realpath)((0, import_node_path8.resolve)(options.entrypointPath));
8148
- await (0, import_promises11.access)(nodePath, import_promises11.constants.X_OK);
8149
- await (0, import_promises11.access)(entrypointPath, import_promises11.constants.R_OK);
8666
+ const nodePath = await (0, import_promises12.realpath)((0, import_node_path9.resolve)(options.nodePath));
8667
+ const entrypointPath = await (0, import_promises12.realpath)((0, import_node_path9.resolve)(options.entrypointPath));
8668
+ await (0, import_promises12.access)(nodePath, import_promises12.constants.X_OK);
8669
+ await (0, import_promises12.access)(entrypointPath, import_promises12.constants.R_OK);
8150
8670
  const probe = await execFileAsync2(nodePath, [entrypointPath, "--version"], {
8151
8671
  encoding: "utf8",
8152
8672
  env: {
@@ -8179,21 +8699,21 @@ function delay6(milliseconds) {
8179
8699
  function errorMessage2(error) {
8180
8700
  return error instanceof Error ? error.message : String(error);
8181
8701
  }
8182
- var import_node_child_process3, import_promises11, import_node_path8, import_node_util3, reconcileTimeoutMilliseconds, execFileAsync2, DaemonReconcileOutcome, DaemonRefreshError;
8702
+ var import_node_child_process4, import_promises12, import_node_path9, import_node_util3, reconcileTimeoutMilliseconds, execFileAsync2, DaemonReconcileOutcome, DaemonRefreshError;
8183
8703
  var init_daemon_reconcile = __esm({
8184
8704
  "../machine-connector/dist/runtime/daemon-reconcile.js"() {
8185
8705
  "use strict";
8186
8706
  init_cjs_shims();
8187
- import_node_child_process3 = require("child_process");
8188
- import_promises11 = require("fs/promises");
8189
- import_node_path8 = require("path");
8707
+ import_node_child_process4 = require("child_process");
8708
+ import_promises12 = require("fs/promises");
8709
+ import_node_path9 = require("path");
8190
8710
  import_node_util3 = require("util");
8191
8711
  init_local_ipc();
8192
8712
  init_process_lock();
8193
8713
  init_service_manager();
8194
8714
  init_store();
8195
8715
  reconcileTimeoutMilliseconds = 12e3;
8196
- execFileAsync2 = (0, import_node_util3.promisify)(import_node_child_process3.execFile);
8716
+ execFileAsync2 = (0, import_node_util3.promisify)(import_node_child_process4.execFile);
8197
8717
  (function(DaemonReconcileOutcome2) {
8198
8718
  DaemonReconcileOutcome2["Restarted"] = "restarted";
8199
8719
  DaemonReconcileOutcome2["Skipped"] = "skipped";
@@ -8225,6 +8745,14 @@ async function runMachineDoctor(store) {
8225
8745
  name: "daemon",
8226
8746
  status: response.error ? DoctorCheckStatus.Failed : DoctorCheckStatus.Passed
8227
8747
  });
8748
+ if (response.status) {
8749
+ const shellEnvironment = response.status.shellEnvironment;
8750
+ checks.push({
8751
+ detail: shellEnvironment.state === "captured" ? "User shell environment captured" : `Using sanitized daemon environment (${shellEnvironment.category ?? "unavailable"})`,
8752
+ name: "shell-environment",
8753
+ status: shellEnvironment.state === "captured" ? DoctorCheckStatus.Passed : DoctorCheckStatus.Warning
8754
+ });
8755
+ }
8228
8756
  } catch (error) {
8229
8757
  checks.push({
8230
8758
  detail: errorMessage3(error),
@@ -8234,7 +8762,7 @@ async function runMachineDoctor(store) {
8234
8762
  }
8235
8763
  for (const connection of connections) {
8236
8764
  try {
8237
- await (0, import_promises12.access)(connection.rootPath, import_node_fs.constants.R_OK | import_node_fs.constants.X_OK);
8765
+ await (0, import_promises13.access)(connection.rootPath, import_node_fs.constants.R_OK | import_node_fs.constants.X_OK);
8238
8766
  checks.push({
8239
8767
  detail: connection.rootPath,
8240
8768
  name: `root:${connection.connectionId}`,
@@ -8249,7 +8777,7 @@ async function runMachineDoctor(store) {
8249
8777
  }
8250
8778
  const relayUrl = new URL(connection.relayOrigin);
8251
8779
  try {
8252
- const address = await (0, import_promises13.lookup)(relayUrl.hostname);
8780
+ const address = await (0, import_promises14.lookup)(relayUrl.hostname);
8253
8781
  checks.push({
8254
8782
  detail: `${relayUrl.hostname} resolves to ${address.address}`,
8255
8783
  name: `dns:${connection.connectionId}`,
@@ -8331,18 +8859,18 @@ async function runMachineDoctor(store) {
8331
8859
  function errorMessage3(error) {
8332
8860
  return error instanceof Error ? error.message : String(error);
8333
8861
  }
8334
- var import_node_child_process4, import_promises12, import_node_fs, import_promises13, import_node_util4, execFileAsync3, DoctorCheckStatus;
8862
+ var import_node_child_process5, import_promises13, import_node_fs, import_promises14, import_node_util4, execFileAsync3, DoctorCheckStatus;
8335
8863
  var init_doctor = __esm({
8336
8864
  "../machine-connector/dist/runtime/doctor.js"() {
8337
8865
  "use strict";
8338
8866
  init_cjs_shims();
8339
- import_node_child_process4 = require("child_process");
8340
- import_promises12 = require("fs/promises");
8867
+ import_node_child_process5 = require("child_process");
8868
+ import_promises13 = require("fs/promises");
8341
8869
  import_node_fs = require("fs");
8342
- import_promises13 = require("dns/promises");
8870
+ import_promises14 = require("dns/promises");
8343
8871
  import_node_util4 = require("util");
8344
8872
  init_local_ipc();
8345
- execFileAsync3 = (0, import_node_util4.promisify)(import_node_child_process4.execFile);
8873
+ execFileAsync3 = (0, import_node_util4.promisify)(import_node_child_process5.execFile);
8346
8874
  (function(DoctorCheckStatus2) {
8347
8875
  DoctorCheckStatus2["Failed"] = "failed";
8348
8876
  DoctorCheckStatus2["Passed"] = "passed";
@@ -8608,7 +9136,7 @@ async function readRecentLogLines(store) {
8608
9136
  }
8609
9137
  async function readOptionalFile(path4) {
8610
9138
  try {
8611
- return await (0, import_promises14.readFile)(path4, "utf8");
9139
+ return await (0, import_promises15.readFile)(path4, "utf8");
8612
9140
  } catch (error) {
8613
9141
  if (isMissingFile(error)) {
8614
9142
  return "";
@@ -8667,13 +9195,13 @@ function isMissingFile(error) {
8667
9195
  function errorMessage4(error) {
8668
9196
  return error instanceof Error ? error.message : String(error);
8669
9197
  }
8670
- var import_promises14, import_promises15, import_node_readline, alternateScreenEnter, alternateScreenExit, clearScreen, cursorHide, cursorShow, styleReset, styleHeader, styleSelected, refreshIntervalMilliseconds, maximumLogLines, MachineManagerView, MachineManagerAction, MachineManagerSnapshotDepth, InteractiveMachineManager;
9198
+ var import_promises15, import_promises16, import_node_readline, alternateScreenEnter, alternateScreenExit, clearScreen, cursorHide, cursorShow, styleReset, styleHeader, styleSelected, refreshIntervalMilliseconds, maximumLogLines, MachineManagerView, MachineManagerAction, MachineManagerSnapshotDepth, InteractiveMachineManager;
8671
9199
  var init_machine_manager = __esm({
8672
9200
  "../machine-connector/dist/runtime/machine-manager.js"() {
8673
9201
  "use strict";
8674
9202
  init_cjs_shims();
8675
- import_promises14 = require("fs/promises");
8676
- import_promises15 = require("readline/promises");
9203
+ import_promises15 = require("fs/promises");
9204
+ import_promises16 = require("readline/promises");
8677
9205
  import_node_readline = require("readline");
8678
9206
  init_doctor();
8679
9207
  init_local_ipc();
@@ -8907,7 +9435,7 @@ var init_machine_manager = __esm({
8907
9435
  }
8908
9436
  async runCommandAction(action) {
8909
9437
  this.suspendTerminal();
8910
- const reader = (0, import_promises15.createInterface)({
9438
+ const reader = (0, import_promises16.createInterface)({
8911
9439
  input: process.stdin,
8912
9440
  output: process.stdout
8913
9441
  });
@@ -9086,7 +9614,7 @@ async function pairMachine(store, options) {
9086
9614
  await store.initialize();
9087
9615
  const canonicalRoot = await store.getCanonicalRoot(options.rootPath);
9088
9616
  const identity = await ensureMachineIdentity(store);
9089
- const machineName = options.machineName ?? (0, import_node_os6.hostname)();
9617
+ const machineName = options.machineName ?? (0, import_node_os7.hostname)();
9090
9618
  const operatingSystem = getOperatingSystem();
9091
9619
  const rootHandle = (0, import_node_crypto7.createHash)("sha256").update(identity.identity.deviceKeyFingerprint, "utf8").update("\0").update(canonicalRoot, "utf8").digest("base64url");
9092
9620
  const client = new PairingRelayClient(options.relayOrigin);
@@ -9097,7 +9625,7 @@ async function pairMachine(store, options) {
9097
9625
  machineName,
9098
9626
  operatingSystem,
9099
9627
  protocolVersion: machineProtocolVersion,
9100
- rootDisplayName: (0, import_node_path9.basename)(canonicalRoot),
9628
+ rootDisplayName: (0, import_node_path10.basename)(canonicalRoot),
9101
9629
  rootHandle
9102
9630
  });
9103
9631
  options.onConfirmation?.(proposal.confirmationUrl);
@@ -9125,7 +9653,7 @@ async function pairMachine(store, options) {
9125
9653
  operatingSystem,
9126
9654
  refreshToken: credentials.refreshToken,
9127
9655
  relayOrigin: options.relayOrigin.replace(/\/+$/, ""),
9128
- rootDisplayName: (0, import_node_path9.basename)(canonicalRoot),
9656
+ rootDisplayName: (0, import_node_path10.basename)(canonicalRoot),
9129
9657
  rootHandle,
9130
9658
  rootPath: canonicalRoot,
9131
9659
  targetId: credentials.targetId,
@@ -9146,17 +9674,17 @@ async function pairMachine(store, options) {
9146
9674
  throw new Error("Local Machine pairing expired");
9147
9675
  }
9148
9676
  function getOperatingSystem() {
9149
- if ((0, import_node_os6.platform)() === "darwin") {
9677
+ if ((0, import_node_os7.platform)() === "darwin") {
9150
9678
  return MachineOperatingSystem.MacOS;
9151
9679
  }
9152
- if ((0, import_node_os6.platform)() === "linux") {
9680
+ if ((0, import_node_os7.platform)() === "linux") {
9153
9681
  return MachineOperatingSystem.Linux;
9154
9682
  }
9155
9683
  return MachineOperatingSystem.Windows;
9156
9684
  }
9157
9685
  function openBrowser(url) {
9158
- const command = (0, import_node_os6.platform)() === "darwin" ? "open" : "xdg-open";
9159
- const child = (0, import_node_child_process5.execFile)(command, [url], () => void 0);
9686
+ const command = (0, import_node_os7.platform)() === "darwin" ? "open" : "xdg-open";
9687
+ const child = (0, import_node_child_process6.execFile)(command, [url], () => void 0);
9160
9688
  child.unref();
9161
9689
  }
9162
9690
  function delay7(milliseconds) {
@@ -9164,15 +9692,15 @@ function delay7(milliseconds) {
9164
9692
  setTimeout(resolvePromise, milliseconds);
9165
9693
  });
9166
9694
  }
9167
- var import_node_child_process5, import_node_crypto7, import_node_os6, import_node_path9, connectedPairingStatus, rejectedPairingStatus, expiredPairingStatus, pairingPollMilliseconds;
9695
+ var import_node_child_process6, import_node_crypto7, import_node_os7, import_node_path10, connectedPairingStatus, rejectedPairingStatus, expiredPairingStatus, pairingPollMilliseconds;
9168
9696
  var init_pairing = __esm({
9169
9697
  "../machine-connector/dist/runtime/pairing.js"() {
9170
9698
  "use strict";
9171
9699
  init_cjs_shims();
9172
- import_node_child_process5 = require("child_process");
9700
+ import_node_child_process6 = require("child_process");
9173
9701
  import_node_crypto7 = require("crypto");
9174
- import_node_os6 = require("os");
9175
- import_node_path9 = require("path");
9702
+ import_node_os7 = require("os");
9703
+ import_node_path10 = require("path");
9176
9704
  init_contracts();
9177
9705
  init_version();
9178
9706
  init_enums();
@@ -9207,6 +9735,10 @@ async function runMachineCli(argumentsList, entrypoint) {
9207
9735
  await doctorCommand(store, commandArguments);
9208
9736
  return;
9209
9737
  }
9738
+ if (command === "environment") {
9739
+ await environmentCommand(store, commandArguments);
9740
+ return;
9741
+ }
9210
9742
  if (command === "disconnect") {
9211
9743
  await disconnectCommand(store, commandArguments);
9212
9744
  return;
@@ -9236,7 +9768,7 @@ async function runMachineCli(argumentsList, entrypoint) {
9236
9768
  async function connectCommand(store, argumentsList, entrypoint) {
9237
9769
  const options = parseOptions(argumentsList);
9238
9770
  const connectionCode = requiredOption(options, "code");
9239
- const rootPath = (0, import_node_path10.resolve)(options.root ?? process.cwd());
9771
+ const rootPath = (0, import_node_path11.resolve)(options.root ?? process.cwd());
9240
9772
  const serviceManagerPreference = requestedServiceManagerPreference(options);
9241
9773
  await validateExplicitServiceManagerPreference(serviceManagerPreference);
9242
9774
  writeLine("Internal Full Host Access: enabled");
@@ -9344,6 +9876,24 @@ async function doctorCommand(store, argumentsList) {
9344
9876
  process.exitCode = 1;
9345
9877
  }
9346
9878
  }
9879
+ async function environmentCommand(store, argumentsList) {
9880
+ const action = argumentsList[0] ?? "status";
9881
+ const response = action === "refresh" ? await requestEnvironmentRefresh(store) : action === "status" ? await requestRuntimeStatus(store) : void 0;
9882
+ if (!response) {
9883
+ throw new Error(`Unsupported environment action: ${action}`);
9884
+ }
9885
+ if (response.error) {
9886
+ throw new Error(response.error);
9887
+ }
9888
+ const status = action === "refresh" ? response.environmentRefresh : response.status?.shellEnvironment;
9889
+ if (!status) {
9890
+ throw new Error("Connector did not return shell environment status");
9891
+ }
9892
+ writeLine(`Shell environment: ${status.state}${status.category ? ` (${status.category})` : ""}`);
9893
+ if (action === "refresh" && status.state === "degraded") {
9894
+ process.exitCode = 1;
9895
+ }
9896
+ }
9347
9897
  async function disconnectCommand(store, argumentsList) {
9348
9898
  const options = parseOptions(argumentsList);
9349
9899
  const connectionId = requiredOption(options, "connection");
@@ -9503,7 +10053,7 @@ async function waitForDaemonOnline(store) {
9503
10053
  }
9504
10054
  async function readOptionalFile2(path4) {
9505
10055
  try {
9506
- return await (0, import_promises16.readFile)(path4, "utf8");
10056
+ return await (0, import_promises17.readFile)(path4, "utf8");
9507
10057
  } catch {
9508
10058
  return "";
9509
10059
  }
@@ -9516,6 +10066,7 @@ Usage:
9516
10066
  moxt machine status [--json]
9517
10067
  moxt machine logs [--lines 100]
9518
10068
  moxt machine doctor [--json]
10069
+ moxt machine environment <status|refresh>
9519
10070
  moxt machine disconnect --connection <id> [--local-only]
9520
10071
  moxt machine manager
9521
10072
  moxt machine service install [--service-manager <auto|systemd|supervisor|none>]
@@ -9531,13 +10082,13 @@ function delay8(milliseconds) {
9531
10082
  setTimeout(resolvePromise, milliseconds);
9532
10083
  });
9533
10084
  }
9534
- var import_promises16, import_node_path10, defaultRelayOrigin;
10085
+ var import_promises17, import_node_path11, defaultRelayOrigin;
9535
10086
  var init_cli = __esm({
9536
10087
  "../machine-connector/dist/cli.js"() {
9537
10088
  "use strict";
9538
10089
  init_cjs_shims();
9539
- import_promises16 = require("fs/promises");
9540
- import_node_path10 = require("path");
10090
+ import_promises17 = require("fs/promises");
10091
+ import_node_path11 = require("path");
9541
10092
  init_daemon();
9542
10093
  init_daemon_reconcile();
9543
10094
  init_doctor();
@@ -9611,6 +10162,7 @@ __export(dist_exports, {
9611
10162
  recordedServiceManager: () => recordedServiceManager,
9612
10163
  refreshManagedUserService: () => refreshManagedUserService,
9613
10164
  renderMachineManager: () => renderMachineManager,
10165
+ requestEnvironmentRefresh: () => requestEnvironmentRefresh,
9614
10166
  requestRuntimeStatus: () => requestRuntimeStatus,
9615
10167
  resolveWorkingDirectory: () => resolveWorkingDirectory,
9616
10168
  restartUserService: () => restartUserService,
@@ -9818,7 +10370,7 @@ function getApiKeyOrUndefined() {
9818
10370
 
9819
10371
  // src/utils/http.ts
9820
10372
  function getUserAgent() {
9821
- return `moxt-cli/${"0.8.2"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
10373
+ return `moxt-cli/${"0.9.0-beta.1"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
9822
10374
  }
9823
10375
  async function sendRequest(method, path4, init) {
9824
10376
  const response = await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -9994,8 +10546,8 @@ function readCommentContentFile(path4) {
9994
10546
  if (!fs.existsSync(path4)) {
9995
10547
  throw new FileCommentOptionsError(`Error: comment content file not found: ${path4}`);
9996
10548
  }
9997
- const stat3 = fs.statSync(path4);
9998
- if (!stat3.isFile()) {
10549
+ const stat4 = fs.statSync(path4);
10550
+ if (!stat4.isFile()) {
9999
10551
  throw new FileCommentOptionsError(`Error: comment content path is not a file: ${path4}`);
10000
10552
  }
10001
10553
  const buffer2 = fs.readFileSync(path4);
@@ -10669,8 +11221,8 @@ var FileTokenizer = class _FileTokenizer extends AbstractTokenizer {
10669
11221
  */
10670
11222
  static async fromFile(sourceFilePath) {
10671
11223
  const fileHandle = await (0, import_promises.open)(sourceFilePath, "r");
10672
- const stat3 = await fileHandle.stat();
10673
- return new _FileTokenizer(fileHandle, { fileInfo: { path: sourceFilePath, size: stat3.size } });
11224
+ const stat4 = await fileHandle.stat();
11225
+ return new _FileTokenizer(fileHandle, { fileInfo: { path: sourceFilePath, size: stat4.size } });
10674
11226
  }
10675
11227
  constructor(fileHandle, options) {
10676
11228
  super(options);
@@ -21805,7 +22357,7 @@ init_cjs_shims();
21805
22357
 
21806
22358
  // src/update/install.ts
21807
22359
  init_cjs_shims();
21808
- var import_node_child_process6 = require("child_process");
22360
+ var import_node_child_process7 = require("child_process");
21809
22361
  var import_node_fs2 = require("fs");
21810
22362
  var path3 = __toESM(require("path"), 1);
21811
22363
 
@@ -21921,7 +22473,7 @@ function runUpgrade(channel, targetVersion) {
21921
22473
  }
21922
22474
  process.stderr.write(`Updating via \`${display}\`...
21923
22475
  `);
21924
- const installation = (0, import_node_child_process6.spawnSync)(plan.command, plan.args, {
22476
+ const installation = (0, import_node_child_process7.spawnSync)(plan.command, plan.args, {
21925
22477
  encoding: "utf8",
21926
22478
  env: process.env,
21927
22479
  maxBuffer: 10 * 1024 * 1024,
@@ -21936,7 +22488,7 @@ function runUpgrade(channel, targetVersion) {
21936
22488
  success: false
21937
22489
  };
21938
22490
  }
21939
- const verification = (0, import_node_child_process6.spawnSync)("moxt", ["--version"], {
22491
+ const verification = (0, import_node_child_process7.spawnSync)("moxt", ["--version"], {
21940
22492
  encoding: "utf8",
21941
22493
  env: process.env,
21942
22494
  maxBuffer: 1024 * 1024,
@@ -21950,7 +22502,7 @@ function runUpgrade(channel, targetVersion) {
21950
22502
  success: false
21951
22503
  };
21952
22504
  }
21953
- const daemonRefresh = (0, import_node_child_process6.spawnSync)(
22505
+ const daemonRefresh = (0, import_node_child_process7.spawnSync)(
21954
22506
  "moxt",
21955
22507
  ["machine", "daemon-reconcile", "--report"],
21956
22508
  {
@@ -22349,8 +22901,8 @@ function readDescFile(path4) {
22349
22901
  if (!fs5.existsSync(path4)) {
22350
22902
  throw new WorkflowOptionsError(`Error: desc file not found: ${path4}`);
22351
22903
  }
22352
- const stat3 = fs5.statSync(path4);
22353
- if (!stat3.isFile()) {
22904
+ const stat4 = fs5.statSync(path4);
22905
+ if (!stat4.isFile()) {
22354
22906
  throw new WorkflowOptionsError(`Error: desc file is not a file: ${path4}`);
22355
22907
  }
22356
22908
  const buffer2 = fs5.readFileSync(path4);
@@ -22367,11 +22919,11 @@ function readCommentContentFile2(path4) {
22367
22919
  if (!fs5.existsSync(path4)) {
22368
22920
  throw new WorkflowOptionsError(`Error: comment content file not found: ${path4}`);
22369
22921
  }
22370
- const stat3 = fs5.statSync(path4);
22371
- if (!stat3.isFile()) {
22922
+ const stat4 = fs5.statSync(path4);
22923
+ if (!stat4.isFile()) {
22372
22924
  throw new WorkflowOptionsError(`Error: comment content path is not a file: ${path4}`);
22373
22925
  }
22374
- if (stat3.size > MAX_COMMENT_CONTENT_BYTES) {
22926
+ if (stat4.size > MAX_COMMENT_CONTENT_BYTES) {
22375
22927
  throw new WorkflowOptionsError(
22376
22928
  `Error: comment content file must be at most ${MAX_COMMENT_CONTENT_LENGTH} characters.`
22377
22929
  );
@@ -23305,16 +23857,16 @@ function createProgram(version) {
23305
23857
 
23306
23858
  // src/telemetry/client.ts
23307
23859
  init_cjs_shims();
23308
- var import_node_os7 = require("os");
23860
+ var import_node_os8 = require("os");
23309
23861
  var buffer = [];
23310
23862
  var FLUSH_TIMEOUT_MS = 3e3;
23311
23863
  var MAX_BATCH_SIZE = 100;
23312
23864
  function commonLabels() {
23313
23865
  return {
23314
- cli_version: "0.8.2",
23866
+ cli_version: "0.9.0-beta.1",
23315
23867
  node_version: process.versions.node,
23316
- os: (0, import_node_os7.platform)(),
23317
- arch: (0, import_node_os7.arch)(),
23868
+ os: (0, import_node_os8.platform)(),
23869
+ arch: (0, import_node_os8.arch)(),
23318
23870
  is_ci: isCiEnvironment() ? "true" : "false"
23319
23871
  };
23320
23872
  }
@@ -23357,7 +23909,7 @@ async function flush() {
23357
23909
  }
23358
23910
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
23359
23911
  const payload = {
23360
- release_id: "0.8.2",
23912
+ release_id: "0.9.0-beta.1",
23361
23913
  client_type: "cli",
23362
23914
  metric_data_list: batch.map((m) => ({
23363
23915
  profile: "cli",
@@ -23558,7 +24110,7 @@ function registryWorker() {
23558
24110
 
23559
24111
  // src/update/prompt.ts
23560
24112
  init_cjs_shims();
23561
- var import_promises17 = require("readline/promises");
24113
+ var import_promises18 = require("readline/promises");
23562
24114
  async function promptForUpdate(input, output, currentVersion, latestVersion, timeoutMs) {
23563
24115
  output.write(`
23564
24116
  A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion}
@@ -23571,7 +24123,7 @@ A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion
23571
24123
  const controller = new AbortController();
23572
24124
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
23573
24125
  timeout.unref();
23574
- const readline = (0, import_promises17.createInterface)({ input, output, terminal: true });
24126
+ const readline = (0, import_promises18.createInterface)({ input, output, terminal: true });
23575
24127
  try {
23576
24128
  const answer = await readline.question("", { signal: controller.signal });
23577
24129
  if (answer.trim() === "1") return "update";
@@ -23674,7 +24226,7 @@ function commandPath2(command) {
23674
24226
 
23675
24227
  // src/update/daemon-reconcile-hook.ts
23676
24228
  init_cjs_shims();
23677
- var import_node_path11 = require("path");
24229
+ var import_node_path12 = require("path");
23678
24230
  function installDaemonReconcileHook(program3, cliVersion) {
23679
24231
  program3.hook("preAction", async (_thisCommand, actionCommand) => {
23680
24232
  if (!isEligible2(actionCommand)) return;
@@ -23688,9 +24240,9 @@ function installDaemonReconcileHook(program3, cliVersion) {
23688
24240
  await reconcileManagedDaemon2({
23689
24241
  cliVersion,
23690
24242
  commandArguments: ["machine", "daemon"],
23691
- entrypointPath: (0, import_node_path11.resolve)(entrypointPath),
24243
+ entrypointPath: (0, import_node_path12.resolve)(entrypointPath),
23692
24244
  environment: {},
23693
- nodePath: (0, import_node_path11.resolve)(process.execPath),
24245
+ nodePath: (0, import_node_path12.resolve)(process.execPath),
23694
24246
  onActiveJobs: (count) => {
23695
24247
  process.stderr.write(
23696
24248
  `Warning: restarting the managed Connector will interrupt ${count} active ${count === 1 ? "Job" : "Jobs"}.
@@ -23732,9 +24284,9 @@ function commandPath3(command) {
23732
24284
  }
23733
24285
 
23734
24286
  // src/index.ts
23735
- var program2 = createProgram("0.8.2");
23736
- installDaemonReconcileHook(program2, "0.8.2");
23737
- installUpdateHook(program2, "0.8.2");
24287
+ var program2 = createProgram("0.9.0-beta.1");
24288
+ installDaemonReconcileHook(program2, "0.9.0-beta.1");
24289
+ installUpdateHook(program2, "0.9.0-beta.1");
23738
24290
  instrumentProgram(program2);
23739
24291
  installExitHandler();
23740
24292
  program2.parseAsync(process.argv).then(async () => {