@moxt-ai/cli 0.10.0-beta.2 → 0.10.0-beta.4

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
@@ -6685,7 +6685,69 @@ var init_version = __esm({
6685
6685
  }
6686
6686
  });
6687
6687
 
6688
+ // ../machine-connector/dist/runtime/local-codex-runtime/contracts.js
6689
+ var localCodexRuntimeProtocolVersion, localCodexRuntimeEventSchemaVersion, localCodexRuntimeEventRedactionVersion, LocalCodexComponentStatusWire, LocalCodexTurnStatusWire, LocalCodexControlKindWire, LocalCodexControlOutcomeWire, LocalCodexDiscoveryKindWire, LocalCodexDiscoveryStatusWire, LocalCodexAttemptPhase, LocalCodexControlApplyPhase;
6690
+ var init_contracts2 = __esm({
6691
+ "../machine-connector/dist/runtime/local-codex-runtime/contracts.js"() {
6692
+ "use strict";
6693
+ init_cjs_shims();
6694
+ localCodexRuntimeProtocolVersion = "1.0";
6695
+ localCodexRuntimeEventSchemaVersion = 1;
6696
+ localCodexRuntimeEventRedactionVersion = 1;
6697
+ (function(LocalCodexComponentStatusWire2) {
6698
+ LocalCodexComponentStatusWire2["AuthenticationRequired"] = "authentication_required";
6699
+ LocalCodexComponentStatusWire2["Error"] = "error";
6700
+ LocalCodexComponentStatusWire2["Incompatible"] = "incompatible";
6701
+ LocalCodexComponentStatusWire2["Missing"] = "missing";
6702
+ LocalCodexComponentStatusWire2["Ready"] = "ready";
6703
+ LocalCodexComponentStatusWire2["Unknown"] = "unknown";
6704
+ })(LocalCodexComponentStatusWire || (LocalCodexComponentStatusWire = {}));
6705
+ (function(LocalCodexTurnStatusWire2) {
6706
+ LocalCodexTurnStatusWire2["Cancelled"] = "cancelled";
6707
+ LocalCodexTurnStatusWire2["Failed"] = "failed";
6708
+ LocalCodexTurnStatusWire2["Interrupted"] = "interrupted";
6709
+ LocalCodexTurnStatusWire2["Running"] = "running";
6710
+ LocalCodexTurnStatusWire2["RuntimeLost"] = "runtime_lost";
6711
+ LocalCodexTurnStatusWire2["Succeeded"] = "succeeded";
6712
+ })(LocalCodexTurnStatusWire || (LocalCodexTurnStatusWire = {}));
6713
+ (function(LocalCodexControlKindWire2) {
6714
+ LocalCodexControlKindWire2["Abort"] = "abort";
6715
+ LocalCodexControlKindWire2["InteractionResponse"] = "interaction_response";
6716
+ LocalCodexControlKindWire2["Steer"] = "steer";
6717
+ })(LocalCodexControlKindWire || (LocalCodexControlKindWire = {}));
6718
+ (function(LocalCodexControlOutcomeWire2) {
6719
+ LocalCodexControlOutcomeWire2["Applied"] = "applied";
6720
+ LocalCodexControlOutcomeWire2["Rejected"] = "rejected";
6721
+ LocalCodexControlOutcomeWire2["Stale"] = "stale";
6722
+ })(LocalCodexControlOutcomeWire || (LocalCodexControlOutcomeWire = {}));
6723
+ (function(LocalCodexDiscoveryKindWire2) {
6724
+ LocalCodexDiscoveryKindWire2["DirectoryList"] = "directory_list";
6725
+ LocalCodexDiscoveryKindWire2["ModelList"] = "model_list";
6726
+ })(LocalCodexDiscoveryKindWire || (LocalCodexDiscoveryKindWire = {}));
6727
+ (function(LocalCodexDiscoveryStatusWire2) {
6728
+ LocalCodexDiscoveryStatusWire2["Failed"] = "failed";
6729
+ LocalCodexDiscoveryStatusWire2["Succeeded"] = "succeeded";
6730
+ })(LocalCodexDiscoveryStatusWire || (LocalCodexDiscoveryStatusWire = {}));
6731
+ (function(LocalCodexAttemptPhase2) {
6732
+ LocalCodexAttemptPhase2["Claimed"] = "claimed";
6733
+ LocalCodexAttemptPhase2["Running"] = "running";
6734
+ LocalCodexAttemptPhase2["TerminalPendingUpload"] = "terminal_pending_upload";
6735
+ LocalCodexAttemptPhase2["Uploaded"] = "uploaded";
6736
+ })(LocalCodexAttemptPhase || (LocalCodexAttemptPhase = {}));
6737
+ (function(LocalCodexControlApplyPhase2) {
6738
+ LocalCodexControlApplyPhase2["Applied"] = "applied";
6739
+ LocalCodexControlApplyPhase2["Recorded"] = "recorded";
6740
+ })(LocalCodexControlApplyPhase || (LocalCodexControlApplyPhase = {}));
6741
+ }
6742
+ });
6743
+
6688
6744
  // ../machine-connector/dist/runtime/relay-client.js
6745
+ function localCodexRuntimeEventsRequestBody(fence, firstSequence, events) {
6746
+ return { ...fence, events, firstSequence };
6747
+ }
6748
+ function localCodexRuntimeEventsRequestBytes(fence, firstSequence, events) {
6749
+ return Buffer.byteLength(JSON.stringify(localCodexRuntimeEventsRequestBody(fence, firstSequence, events)), "utf8");
6750
+ }
6689
6751
  async function postJson(url, body, accessToken, externalSignal) {
6690
6752
  const headers = {
6691
6753
  "Content-Type": "application/json",
@@ -6763,6 +6825,7 @@ var init_relay_client = __esm({
6763
6825
  "use strict";
6764
6826
  init_cjs_shims();
6765
6827
  init_version();
6828
+ init_contracts2();
6766
6829
  requestTimeoutMilliseconds = 65e3;
6767
6830
  RelayHttpError = class extends Error {
6768
6831
  responseBody;
@@ -6845,11 +6908,21 @@ var init_relay_client = __esm({
6845
6908
  async claimCodexRuntime(request2, signal) {
6846
6909
  return await this.authenticatedPost("codex-runtime/turns/claim", request2, signal);
6847
6910
  }
6911
+ async claimCodexRuntimeDiscovery(request2, signal) {
6912
+ return await this.authenticatedPost("codex-runtime/discovery/claim", request2, signal);
6913
+ }
6914
+ async completeCodexRuntimeDiscovery(requestId, connectorInstanceId, result) {
6915
+ return await this.authenticatedPost(`codex-runtime/discovery/requests/${encodeURIComponent(requestId)}/result`, {
6916
+ ...result,
6917
+ connectorInstanceId,
6918
+ protocolVersion: localCodexRuntimeProtocolVersion
6919
+ });
6920
+ }
6848
6921
  async renewCodexRuntimeLease(attemptId, fence, signal) {
6849
6922
  return await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/lease`, fence, signal);
6850
6923
  }
6851
6924
  async appendCodexRuntimeEvents(attemptId, fence, firstSequence, events) {
6852
- return await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/events`, { ...fence, events, firstSequence });
6925
+ return await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/events`, localCodexRuntimeEventsRequestBody(fence, firstSequence, events));
6853
6926
  }
6854
6927
  async updateCodexRuntimeState(attemptId, fence, state) {
6855
6928
  await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/state`, { ...fence, ...state });
@@ -6947,9 +7020,9 @@ var init_runtime_logger = __esm({
6947
7020
  async info(message, metadata = {}) {
6948
7021
  await this.write("info", message, metadata, this.store.runtimeLogPath());
6949
7022
  }
6950
- async error(message, error) {
6951
- const metadata = error instanceof Error ? { message: error.message, stack: error.stack } : { error };
6952
- await this.write("error", message, metadata, this.store.runtimeErrorLogPath());
7023
+ async error(message, error, context = {}) {
7024
+ const errorMetadata = error instanceof Error ? { message: error.message, stack: error.stack } : { error };
7025
+ await this.write("error", message, { ...context, ...errorMetadata }, this.store.runtimeErrorLogPath());
6953
7026
  }
6954
7027
  async write(level, message, metadata, path4) {
6955
7028
  await (0, import_promises10.appendFile)(path4, `${JSON.stringify({
@@ -7276,54 +7349,6 @@ var init_store = __esm({
7276
7349
  }
7277
7350
  });
7278
7351
 
7279
- // ../machine-connector/dist/runtime/local-codex-runtime/contracts.js
7280
- var localCodexRuntimeProtocolVersion, localCodexRuntimeEventSchemaVersion, localCodexRuntimeEventRedactionVersion, LocalCodexComponentStatusWire, LocalCodexTurnStatusWire, LocalCodexControlKindWire, LocalCodexControlOutcomeWire, LocalCodexAttemptPhase, LocalCodexControlApplyPhase;
7281
- var init_contracts2 = __esm({
7282
- "../machine-connector/dist/runtime/local-codex-runtime/contracts.js"() {
7283
- "use strict";
7284
- init_cjs_shims();
7285
- localCodexRuntimeProtocolVersion = "1.0";
7286
- localCodexRuntimeEventSchemaVersion = 1;
7287
- localCodexRuntimeEventRedactionVersion = 1;
7288
- (function(LocalCodexComponentStatusWire2) {
7289
- LocalCodexComponentStatusWire2["AuthenticationRequired"] = "authentication_required";
7290
- LocalCodexComponentStatusWire2["Error"] = "error";
7291
- LocalCodexComponentStatusWire2["Incompatible"] = "incompatible";
7292
- LocalCodexComponentStatusWire2["Missing"] = "missing";
7293
- LocalCodexComponentStatusWire2["Ready"] = "ready";
7294
- LocalCodexComponentStatusWire2["Unknown"] = "unknown";
7295
- })(LocalCodexComponentStatusWire || (LocalCodexComponentStatusWire = {}));
7296
- (function(LocalCodexTurnStatusWire2) {
7297
- LocalCodexTurnStatusWire2["Cancelled"] = "cancelled";
7298
- LocalCodexTurnStatusWire2["Failed"] = "failed";
7299
- LocalCodexTurnStatusWire2["Interrupted"] = "interrupted";
7300
- LocalCodexTurnStatusWire2["Running"] = "running";
7301
- LocalCodexTurnStatusWire2["RuntimeLost"] = "runtime_lost";
7302
- LocalCodexTurnStatusWire2["Succeeded"] = "succeeded";
7303
- })(LocalCodexTurnStatusWire || (LocalCodexTurnStatusWire = {}));
7304
- (function(LocalCodexControlKindWire2) {
7305
- LocalCodexControlKindWire2["Abort"] = "abort";
7306
- LocalCodexControlKindWire2["InteractionResponse"] = "interaction_response";
7307
- LocalCodexControlKindWire2["Steer"] = "steer";
7308
- })(LocalCodexControlKindWire || (LocalCodexControlKindWire = {}));
7309
- (function(LocalCodexControlOutcomeWire2) {
7310
- LocalCodexControlOutcomeWire2["Applied"] = "applied";
7311
- LocalCodexControlOutcomeWire2["Rejected"] = "rejected";
7312
- LocalCodexControlOutcomeWire2["Stale"] = "stale";
7313
- })(LocalCodexControlOutcomeWire || (LocalCodexControlOutcomeWire = {}));
7314
- (function(LocalCodexAttemptPhase2) {
7315
- LocalCodexAttemptPhase2["Claimed"] = "claimed";
7316
- LocalCodexAttemptPhase2["Running"] = "running";
7317
- LocalCodexAttemptPhase2["TerminalPendingUpload"] = "terminal_pending_upload";
7318
- LocalCodexAttemptPhase2["Uploaded"] = "uploaded";
7319
- })(LocalCodexAttemptPhase || (LocalCodexAttemptPhase = {}));
7320
- (function(LocalCodexControlApplyPhase2) {
7321
- LocalCodexControlApplyPhase2["Applied"] = "applied";
7322
- LocalCodexControlApplyPhase2["Recorded"] = "recorded";
7323
- })(LocalCodexControlApplyPhase || (LocalCodexControlApplyPhase = {}));
7324
- }
7325
- });
7326
-
7327
7352
  // ../machine-connector/dist/runtime/local-codex-runtime/app-server-client.js
7328
7353
  function appServerResponseMessage(response) {
7329
7354
  if (typeof response === "object" && response !== null && "message" in response && typeof response.message === "string") {
@@ -8108,6 +8133,9 @@ function normalizeItem(item, completed, baseCorrelation, canonicalRoot) {
8108
8133
  if (itemType === "fileChange") {
8109
8134
  return event(completed ? "file_change_completed" : "file_change_started", { changes: item.changes, status: item.status }, correlation, canonicalRoot);
8110
8135
  }
8136
+ if (itemType === "contextCompaction") {
8137
+ return event(completed ? "context_compaction_completed" : "context_compaction_started", {}, correlation, canonicalRoot);
8138
+ }
8111
8139
  if (itemType === "mcpToolCall" || itemType === "dynamicToolCall" || itemType === "collabAgentToolCall" || itemType === "webSearch" || itemType === "imageGeneration" || itemType === "imageView") {
8112
8140
  return event(completed ? "tool_completed" : "tool_started", sanitizeThreadItem(item), correlation, canonicalRoot);
8113
8141
  }
@@ -8278,6 +8306,9 @@ var init_event_normalizer = __esm({
8278
8306
  function isMissingThreadResponse(message, threadId) {
8279
8307
  return message === `thread not found: ${threadId}` || message === `no rollout found for thread id ${threadId}` || message === `no rollout found for conversation id ${threadId}`;
8280
8308
  }
8309
+ function isThreadNameMetadataPendingResponse(message) {
8310
+ return message.startsWith("failed to set thread name:") && message.includes("failed to read session metadata ") && message.includes(": rollout at ") && message.endsWith(" is empty");
8311
+ }
8281
8312
  function createActiveAttempt(claim, durable, workingDirectory) {
8282
8313
  let resolveTerminal = (_value) => void 0;
8283
8314
  const terminal = new Promise((resolve9) => {
@@ -8307,6 +8338,16 @@ function createActiveAttempt(claim, durable, workingDirectory) {
8307
8338
  workingDirectory
8308
8339
  };
8309
8340
  }
8341
+ function createInitialThreadNameState() {
8342
+ let resolveCompletion = () => void 0;
8343
+ const completion = new Promise((resolve9) => {
8344
+ resolveCompletion = resolve9;
8345
+ });
8346
+ return {
8347
+ completion,
8348
+ resolve: resolveCompletion
8349
+ };
8350
+ }
8310
8351
  function fenceFor(claim, connectorInstanceId) {
8311
8352
  return {
8312
8353
  attemptGeneration: claim.attemptGeneration,
@@ -8327,6 +8368,36 @@ function persistedFence(persisted) {
8327
8368
  runToken: persisted.claim.runToken
8328
8369
  };
8329
8370
  }
8371
+ function preferredEventUploadBatch(fence, pendingEvents) {
8372
+ if (pendingEvents.length === 0) {
8373
+ throw new Error("Local Codex event upload requires a pending event");
8374
+ }
8375
+ const firstSequence = pendingEvents[0].sequence;
8376
+ const events = [];
8377
+ let requestBytes = localCodexRuntimeEventsRequestBytes(fence, firstSequence, events);
8378
+ for (const event2 of pendingEvents.slice(0, maximumEventUploadCount)) {
8379
+ const serializedEvent = JSON.stringify(event2);
8380
+ if (serializedEvent === void 0) {
8381
+ throw new Error(`Local Codex event ${event2.sequence} cannot be serialized`);
8382
+ }
8383
+ const candidateBytes = requestBytes + Buffer.byteLength(serializedEvent, "utf8") + (events.length === 0 ? 0 : 1);
8384
+ if (events.length > 0 && candidateBytes > preferredEventUploadRequestBytes) {
8385
+ break;
8386
+ }
8387
+ events.push(event2);
8388
+ requestBytes = candidateBytes;
8389
+ }
8390
+ return { events, requestBytes };
8391
+ }
8392
+ function eventUploadBatch(fence, events) {
8393
+ if (events.length === 0) {
8394
+ throw new Error("Local Codex event upload batch cannot be empty");
8395
+ }
8396
+ return {
8397
+ events,
8398
+ requestBytes: localCodexRuntimeEventsRequestBytes(fence, events[0].sequence, events)
8399
+ };
8400
+ }
8330
8401
  function requireThreadId(response) {
8331
8402
  const id = response.thread?.id;
8332
8403
  if (id === void 0 || id === "") {
@@ -8461,6 +8532,36 @@ function terminalErrorMessage(payload) {
8461
8532
  const message = safeRecord(payload.error).message;
8462
8533
  return typeof message === "string" ? { value: message } : {};
8463
8534
  }
8535
+ function parseModelListResponse(value) {
8536
+ const response = safeRecord(value);
8537
+ if (!Array.isArray(response.data)) {
8538
+ throw new AppServerProtocolError("Codex App Server model/list returned no data array");
8539
+ }
8540
+ const models = [];
8541
+ for (const candidate of response.data) {
8542
+ const model = safeRecord(candidate);
8543
+ if (typeof model.model !== "string" || model.model.length === 0 || model.model.length > 128 || typeof model.displayName !== "string" || model.displayName.length === 0 || model.displayName.length > 255 || typeof model.description !== "string" || model.description.length > 2e3 || typeof model.isDefault !== "boolean") {
8544
+ throw new AppServerProtocolError("Codex App Server model/list returned an invalid model");
8545
+ }
8546
+ models.push({
8547
+ description: model.description,
8548
+ displayName: model.displayName,
8549
+ isDefault: model.isDefault,
8550
+ model: model.model
8551
+ });
8552
+ }
8553
+ const nextCursor = response.nextCursor;
8554
+ if (nextCursor === null || nextCursor === void 0) {
8555
+ return { models };
8556
+ }
8557
+ if (typeof nextCursor !== "string" || nextCursor.length === 0) {
8558
+ throw new AppServerProtocolError("Codex App Server model/list returned an invalid cursor");
8559
+ }
8560
+ return { models, nextCursor };
8561
+ }
8562
+ function portableRelativeDirectory(value) {
8563
+ return value === "" ? "." : value.replaceAll("\\", "/");
8564
+ }
8464
8565
  function safeRecord(value) {
8465
8566
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
8466
8567
  }
@@ -8540,12 +8641,14 @@ function parseLeaseDeadline(value) {
8540
8641
  }
8541
8642
  return parsed;
8542
8643
  }
8543
- var import_node_child_process4, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, eventUploadCoalesceMilliseconds, eventUploadRetryMilliseconds, leaseRenewIntervalMilliseconds, leaseRenewRetryMilliseconds, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryRetryMilliseconds, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, LocalCodexRuntimeConnectionWorker;
8644
+ var import_node_child_process4, import_promises12, import_node_path10, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, discoveryWaitSeconds, discoveryRetryMilliseconds, maximumDiscoveryDirectories, maximumDiscoveryModels, maximumModelListPages, eventUploadCoalesceMilliseconds, eventUploadRetryMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewRetryMilliseconds, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryRetryMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, LocalCodexRuntimeConnectionWorker;
8544
8645
  var init_runtime_worker = __esm({
8545
8646
  "../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
8546
8647
  "use strict";
8547
8648
  init_cjs_shims();
8548
8649
  import_node_child_process4 = require("child_process");
8650
+ import_promises12 = require("fs/promises");
8651
+ import_node_path10 = require("path");
8549
8652
  init_process_executor();
8550
8653
  init_relay_client();
8551
8654
  init_app_server_client();
@@ -8555,13 +8658,23 @@ var init_runtime_worker = __esm({
8555
8658
  heartbeatIntervalMilliseconds = 2e4;
8556
8659
  claimRetryMilliseconds = 250;
8557
8660
  claimWaitSeconds = 25;
8661
+ discoveryWaitSeconds = 25;
8662
+ discoveryRetryMilliseconds = 1e3;
8663
+ maximumDiscoveryDirectories = 1e3;
8664
+ maximumDiscoveryModels = 100;
8665
+ maximumModelListPages = 10;
8558
8666
  eventUploadCoalesceMilliseconds = 500;
8559
8667
  eventUploadRetryMilliseconds = 1e3;
8668
+ maximumEventUploadCount = 500;
8669
+ preferredEventUploadRequestBytes = 96e3;
8560
8670
  leaseRenewIntervalMilliseconds = 1e4;
8561
8671
  leaseRenewRetryMilliseconds = 1e3;
8562
8672
  interactionTimeoutMilliseconds = 10 * 60 * 1e3;
8563
8673
  executableProbeTimeoutMilliseconds = 5e3;
8564
8674
  recoveryRetryMilliseconds = 1e3;
8675
+ initialThreadNameRetryMilliseconds = 250;
8676
+ maximumThreadNameRetryMilliseconds = 2e3;
8677
+ maximumInitialThreadNameAttempts = 8;
8565
8678
  ThreadUnavailableError = class extends Error {
8566
8679
  constructor(message) {
8567
8680
  super(message);
@@ -8638,9 +8751,13 @@ var init_runtime_worker = __esm({
8638
8751
  if (normalized === void 0) {
8639
8752
  return;
8640
8753
  }
8754
+ const initialThreadName = active.initialThreadName;
8641
8755
  if (normalized.correlation.nativeThreadId !== void 0 && active.nativeThreadId !== void 0 && normalized.correlation.nativeThreadId !== active.nativeThreadId) {
8642
8756
  return;
8643
8757
  }
8758
+ if (normalized.kind === "thread_title_updated" && normalized.payload.title === initialThreadName?.projectedTitle) {
8759
+ return;
8760
+ }
8644
8761
  const notificationTurnId = normalized.correlation.nativeTurnId;
8645
8762
  if (notificationTurnId !== void 0) {
8646
8763
  if (this.processPool.isRetiredTurn(notificationTurnId)) {
@@ -8655,6 +8772,12 @@ var init_runtime_worker = __esm({
8655
8772
  return;
8656
8773
  }
8657
8774
  }
8775
+ if (normalized.terminalStatus !== void 0 && initialThreadName !== void 0) {
8776
+ await initialThreadName.completion;
8777
+ if (active.finished.signal.aborted) {
8778
+ return;
8779
+ }
8780
+ }
8658
8781
  void this.enqueueSpool(active, async () => {
8659
8782
  const persisted = await active.durable.appendEvent(normalized.kind, normalized.payload, normalized.correlation);
8660
8783
  if (normalized.correlation.nativeThreadId !== void 0 && active.nativeThreadId === void 0) {
@@ -8738,6 +8861,7 @@ var init_runtime_worker = __esm({
8738
8861
  await Promise.all([
8739
8862
  this.runHeartbeatLoop(),
8740
8863
  this.runClaimLoop(),
8864
+ this.runDiscoveryLoop(),
8741
8865
  this.runRecoveryLoop()
8742
8866
  ]);
8743
8867
  } finally {
@@ -8794,6 +8918,105 @@ var init_runtime_worker = __esm({
8794
8918
  }
8795
8919
  }
8796
8920
  }
8921
+ async runDiscoveryLoop() {
8922
+ while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
8923
+ try {
8924
+ const response = await this.relay.claimCodexRuntimeDiscovery({
8925
+ connectorInstanceId: this.connectorInstanceId,
8926
+ protocolVersion: localCodexRuntimeProtocolVersion,
8927
+ waitSeconds: discoveryWaitSeconds
8928
+ }, this.lifetimeAbort.signal);
8929
+ if (response.request === void 0) {
8930
+ continue;
8931
+ }
8932
+ await this.completeDiscovery(response.request);
8933
+ } catch (error) {
8934
+ if (!this.lifetimeAbort.signal.aborted) {
8935
+ await this.logger.error(`Local Codex discovery loop failed for connection ${this.connection.connectionId}`, error);
8936
+ await waitForAbort(this.lifetimeAbort.signal, discoveryRetryMilliseconds);
8937
+ }
8938
+ }
8939
+ }
8940
+ }
8941
+ async completeDiscovery(request2) {
8942
+ let result;
8943
+ try {
8944
+ result = await this.executeDiscovery(request2);
8945
+ } catch (error) {
8946
+ await this.logger.error(`Local Codex ${request2.kind} discovery failed for connection ${this.connection.connectionId}`, error);
8947
+ result = {
8948
+ errorCode: request2.kind === LocalCodexDiscoveryKindWire.ModelList ? "model_discovery_failed" : "directory_unavailable",
8949
+ requestId: request2.requestId,
8950
+ status: LocalCodexDiscoveryStatusWire.Failed
8951
+ };
8952
+ }
8953
+ const completion = await this.relay.completeCodexRuntimeDiscovery(request2.requestId, this.connectorInstanceId, result);
8954
+ if (!completion.accepted) {
8955
+ await this.logger.info(`Local Codex discovery request ${request2.requestId} expired before completion`);
8956
+ }
8957
+ }
8958
+ async executeDiscovery(request2) {
8959
+ if (request2.kind === LocalCodexDiscoveryKindWire.ModelList) {
8960
+ return {
8961
+ models: await this.discoverModels(),
8962
+ requestId: request2.requestId,
8963
+ status: LocalCodexDiscoveryStatusWire.Succeeded
8964
+ };
8965
+ }
8966
+ if (request2.kind === LocalCodexDiscoveryKindWire.DirectoryList) {
8967
+ const listing = await this.discoverDirectories(request2.relativeDirectory ?? ".");
8968
+ return {
8969
+ ...listing,
8970
+ requestId: request2.requestId,
8971
+ status: LocalCodexDiscoveryStatusWire.Succeeded
8972
+ };
8973
+ }
8974
+ throw new Error("Unsupported Local Codex discovery kind");
8975
+ }
8976
+ async discoverModels() {
8977
+ const client = await this.processPool.ensureStarted();
8978
+ const models = /* @__PURE__ */ new Map();
8979
+ const cursor = {};
8980
+ for (let page = 0; page < maximumModelListPages; page += 1) {
8981
+ const response = await client.request("model/list", {
8982
+ cursor: cursor.value ?? null,
8983
+ includeHidden: false,
8984
+ limit: maximumDiscoveryModels
8985
+ });
8986
+ const parsed = parseModelListResponse(response);
8987
+ for (const model of parsed.models) {
8988
+ models.set(model.model, model);
8989
+ if (models.size >= maximumDiscoveryModels) {
8990
+ return [...models.values()];
8991
+ }
8992
+ }
8993
+ if (parsed.nextCursor === void 0) {
8994
+ return [...models.values()];
8995
+ }
8996
+ cursor.value = parsed.nextCursor;
8997
+ }
8998
+ throw new AppServerProtocolError("Codex App Server model/list pagination did not converge");
8999
+ }
9000
+ async discoverDirectories(relativeDirectory) {
9001
+ const canonicalRoot = await resolveCanonicalWorkingDirectory(this.connection.rootPath, ".");
9002
+ const canonicalDirectory = await resolveCanonicalWorkingDirectory(canonicalRoot, relativeDirectory);
9003
+ const entries = (await (0, import_promises12.readdir)(canonicalDirectory, {
9004
+ withFileTypes: true
9005
+ })).filter((entry) => entry.isDirectory()).filter((entry) => !entry.name.includes("\\")).sort((left, right) => left.name.localeCompare(right.name, void 0, {
9006
+ numeric: true,
9007
+ sensitivity: "base"
9008
+ }));
9009
+ const eligibleDirectories = entries.map((entry) => ({
9010
+ name: entry.name,
9011
+ relativePath: portableRelativeDirectory((0, import_node_path10.relative)(canonicalRoot, (0, import_node_path10.join)(canonicalDirectory, entry.name)))
9012
+ })).filter((entry) => entry.name.length <= 255 && entry.relativePath.length <= 1024);
9013
+ const directories = eligibleDirectories.slice(0, maximumDiscoveryDirectories);
9014
+ return {
9015
+ currentRelativeDirectory: portableRelativeDirectory((0, import_node_path10.relative)(canonicalRoot, canonicalDirectory)),
9016
+ directories,
9017
+ truncated: eligibleDirectories.length > maximumDiscoveryDirectories
9018
+ };
9019
+ }
8797
9020
  async executeAttempt(claim) {
8798
9021
  const durable = await DurableLocalCodexAttempt.create(this.store, this.connection.connectionId, this.connectorInstanceId, claim);
8799
9022
  const active = createActiveAttempt(claim, durable, this.connection.rootPath);
@@ -8818,6 +9041,9 @@ var init_runtime_worker = __esm({
8818
9041
  active.nativeThreadId = nativeThreadId;
8819
9042
  await durable.markThreadPrepared(nativeThreadId);
8820
9043
  await active.spoolQueue;
9044
+ if (isNewThread) {
9045
+ active.initialThreadName = createInitialThreadNameState();
9046
+ }
8821
9047
  if (isNewThread && !active.durable.snapshot().events.some((event2) => event2.kind === "thread_started")) {
8822
9048
  await active.durable.appendEvent("thread_started", {}, { nativeThreadId });
8823
9049
  }
@@ -8852,7 +9078,11 @@ var init_runtime_worker = __esm({
8852
9078
  });
8853
9079
  await this.interruptActiveTurnIfRequested(active, client);
8854
9080
  if (isNewThread) {
8855
- await this.setInitialThreadName(client, claim, nativeThreadId);
9081
+ try {
9082
+ await this.setInitialThreadName(client, active, nativeThreadId);
9083
+ } finally {
9084
+ active.initialThreadName?.resolve();
9085
+ }
8856
9086
  }
8857
9087
  const terminal = await Promise.race([
8858
9088
  active.terminal,
@@ -8884,6 +9114,7 @@ var init_runtime_worker = __esm({
8884
9114
  await this.failAttempt(active, error);
8885
9115
  }
8886
9116
  } finally {
9117
+ active.initialThreadName?.resolve();
8887
9118
  if (active.acceptedByAppServer && active.nativeTurnId !== void 0) {
8888
9119
  this.processPool.retireTurn(active.nativeTurnId);
8889
9120
  }
@@ -9028,9 +9259,11 @@ var init_runtime_worker = __esm({
9028
9259
  let snapshot = durable.snapshot();
9029
9260
  const fence = persistedFence(snapshot);
9030
9261
  while (durable.pendingEvents().length > 0) {
9031
- const events = durable.pendingEvents().slice(0, 500);
9032
- const response = await this.relay.appendCodexRuntimeEvents(snapshot.claim.attemptId, fence, events[0].sequence, events);
9033
- await durable.acknowledgeEvents(response.acknowledgedSequence);
9262
+ await this.uploadNextEventBatch({
9263
+ attemptId: snapshot.claim.attemptId,
9264
+ durable,
9265
+ fence
9266
+ });
9034
9267
  snapshot = durable.snapshot();
9035
9268
  }
9036
9269
  if (snapshot.phase !== LocalCodexAttemptPhase.TerminalPendingUpload || snapshot.finalSequence === void 0 || snapshot.finalStatus === void 0) {
@@ -9204,12 +9437,44 @@ var init_runtime_worker = __esm({
9204
9437
  }
9205
9438
  async flushEvents(active) {
9206
9439
  await active.spoolQueue;
9207
- const events = active.durable.pendingEvents().slice(0, 500);
9208
- if (events.length === 0) {
9440
+ await this.uploadNextEventBatch({
9441
+ attemptId: active.claim.attemptId,
9442
+ durable: active.durable,
9443
+ fence: fenceFor(active.claim, this.connectorInstanceId)
9444
+ });
9445
+ }
9446
+ async uploadNextEventBatch(request2) {
9447
+ const pendingEvents = request2.durable.pendingEvents();
9448
+ if (pendingEvents.length === 0) {
9209
9449
  return;
9210
9450
  }
9211
- const response = await this.relay.appendCodexRuntimeEvents(active.claim.attemptId, fenceFor(active.claim, this.connectorInstanceId), events[0].sequence, events);
9212
- await active.durable.acknowledgeEvents(response.acknowledgedSequence);
9451
+ let batch = preferredEventUploadBatch(request2.fence, pendingEvents);
9452
+ while (true) {
9453
+ try {
9454
+ const response = await this.relay.appendCodexRuntimeEvents(request2.attemptId, request2.fence, batch.events[0].sequence, batch.events);
9455
+ await request2.durable.acknowledgeEvents(response.acknowledgedSequence);
9456
+ return;
9457
+ } catch (error) {
9458
+ const firstSequence = batch.events[0].sequence;
9459
+ const metadata = {
9460
+ attemptId: request2.attemptId,
9461
+ eventCount: batch.events.length,
9462
+ firstSequence,
9463
+ requestBytes: batch.requestBytes
9464
+ };
9465
+ if (error instanceof RelayHttpError) {
9466
+ metadata.status = error.status;
9467
+ }
9468
+ if (error instanceof RelayHttpError && error.status === 413 && batch.events.length > 1) {
9469
+ await this.logger.info(`Local Codex event upload exceeded the relay request limit; retrying a smaller batch`, metadata);
9470
+ const eventCount = Math.ceil(batch.events.length / 2);
9471
+ batch = eventUploadBatch(request2.fence, batch.events.slice(0, eventCount));
9472
+ continue;
9473
+ }
9474
+ await this.logger.error(`Failed to upload Local Codex events for ${request2.attemptId}`, error, metadata);
9475
+ throw error;
9476
+ }
9477
+ }
9213
9478
  }
9214
9479
  enqueueEventFlush(active) {
9215
9480
  if (active.eventUploadScheduled) {
@@ -9323,7 +9588,8 @@ var init_runtime_worker = __esm({
9323
9588
  const status = this.processPool.status();
9324
9589
  return status.appServerStatus === LocalCodexComponentStatusWire.Ready && status.codexAuthStatus === LocalCodexComponentStatusWire.Ready && status.codexBinaryStatus === LocalCodexComponentStatusWire.Ready;
9325
9590
  }
9326
- async setInitialThreadName(client, claim, threadId) {
9591
+ async setInitialThreadName(client, active, threadId) {
9592
+ const claim = active.claim;
9327
9593
  if (claim.executionContext.workflowTaskId !== void 0 || claim.executionContext.workflowWatcherId !== void 0) {
9328
9594
  return;
9329
9595
  }
@@ -9335,13 +9601,42 @@ var init_runtime_worker = __esm({
9335
9601
  if (name === "") {
9336
9602
  return;
9337
9603
  }
9338
- try {
9339
- await client.request("thread/name/set", {
9340
- name,
9341
- threadId
9604
+ const signal = active.finished.signal;
9605
+ let retryMilliseconds = initialThreadNameRetryMilliseconds;
9606
+ for (let attempt = 1; attempt <= maximumInitialThreadNameAttempts; attempt += 1) {
9607
+ if (signal.aborted) {
9608
+ return;
9609
+ }
9610
+ try {
9611
+ await client.request("thread/name/set", {
9612
+ name,
9613
+ threadId
9614
+ });
9615
+ } catch (error) {
9616
+ const metadataPending = error instanceof AppServerResponseError && isThreadNameMetadataPendingResponse(error.responseMessage);
9617
+ if (!metadataPending || attempt === maximumInitialThreadNameAttempts) {
9618
+ await this.logger.error(`Failed to name Local Codex thread ${threadId}`, error);
9619
+ return;
9620
+ }
9621
+ await waitForAbort(signal, retryMilliseconds);
9622
+ retryMilliseconds = Math.min(retryMilliseconds * 2, maximumThreadNameRetryMilliseconds);
9623
+ continue;
9624
+ }
9625
+ const initialThreadName = active.initialThreadName;
9626
+ if (initialThreadName === void 0) {
9627
+ throw new AppServerProtocolError("Initial thread name state is unavailable");
9628
+ }
9629
+ initialThreadName.projectedTitle = name;
9630
+ await this.enqueueSpool(active, async () => {
9631
+ const titleAlreadyProjected = active.durable.snapshot().events.some((event2) => {
9632
+ return event2.kind === "thread_title_updated" && event2.payload.title === name;
9633
+ });
9634
+ if (titleAlreadyProjected) {
9635
+ return;
9636
+ }
9637
+ await active.durable.appendEvent("thread_title_updated", { title: name }, { nativeThreadId: threadId });
9342
9638
  });
9343
- } catch (error) {
9344
- await this.logger.error(`Failed to name Local Codex thread ${threadId}`, error);
9639
+ return;
9345
9640
  }
9346
9641
  }
9347
9642
  unregisterRoute() {
@@ -10590,12 +10885,12 @@ async function installUserService(store, request2, runtime = defaultServiceManag
10590
10885
  }
10591
10886
  function createServiceEnvironment(options) {
10592
10887
  const inheritedPath = options.environment.PATH ?? process.env.PATH ?? "";
10593
- const nodeDirectory = (0, import_node_path10.dirname)(options.nodePath);
10594
- const pathEntries = [nodeDirectory, ...inheritedPath.split(import_node_path10.delimiter)].filter((entry, index2, entries) => entry.length > 0 && entries.indexOf(entry) === index2);
10888
+ const nodeDirectory = (0, import_node_path11.dirname)(options.nodePath);
10889
+ const pathEntries = [nodeDirectory, ...inheritedPath.split(import_node_path11.delimiter)].filter((entry, index2, entries) => entry.length > 0 && entries.indexOf(entry) === index2);
10595
10890
  return {
10596
10891
  ...options.environment,
10597
10892
  HOME: options.environment.HOME ?? process.env.HOME ?? (0, import_node_os7.homedir)(),
10598
- PATH: pathEntries.join(import_node_path10.delimiter)
10893
+ PATH: pathEntries.join(import_node_path11.delimiter)
10599
10894
  };
10600
10895
  }
10601
10896
  async function restartUserService(store, runtime = defaultServiceManagerRuntime) {
@@ -10797,7 +11092,7 @@ async function uninstallManager(manager, store, runtime) {
10797
11092
  "bootout",
10798
11093
  `gui/${process.getuid?.() ?? 0}/${launchAgentLabel}`
10799
11094
  ]);
10800
- await (0, import_promises12.rm)(launchAgentPath(), { force: true });
11095
+ await (0, import_promises13.rm)(launchAgentPath(), { force: true });
10801
11096
  return;
10802
11097
  }
10803
11098
  if (manager === UserServiceManager.Systemd) {
@@ -10807,7 +11102,7 @@ async function uninstallManager(manager, store, runtime) {
10807
11102
  "--now",
10808
11103
  "moxt-machine-connector.service"
10809
11104
  ]);
10810
- await (0, import_promises12.rm)(systemdUnitPath(), { force: true });
11105
+ await (0, import_promises13.rm)(systemdUnitPath(), { force: true });
10811
11106
  await runCommandIgnoringFailure(runtime, "systemctl", [
10812
11107
  "--user",
10813
11108
  "daemon-reload"
@@ -10821,7 +11116,7 @@ async function uninstallManager(manager, store, runtime) {
10821
11116
  supervisorProgramName
10822
11117
  ]);
10823
11118
  await runCommandIgnoringFailure(runtime, "supervisorctl", ["-c", supervisorConfigPath(store), "shutdown"]);
10824
- await (0, import_promises12.rm)(supervisorDirectory(store), {
11119
+ await (0, import_promises13.rm)(supervisorDirectory(store), {
10825
11120
  force: true,
10826
11121
  recursive: true
10827
11122
  });
@@ -10847,7 +11142,7 @@ async function readStoredServiceManager(store) {
10847
11142
  }
10848
11143
  async function readManagedServiceDefinition(manager, store) {
10849
11144
  try {
10850
- return await (0, import_promises12.readFile)(managedServiceDefinitionPath(manager, store), "utf8");
11145
+ return await (0, import_promises13.readFile)(managedServiceDefinitionPath(manager, store), "utf8");
10851
11146
  } catch (error) {
10852
11147
  if (isNodeErrorCode4(error, "ENOENT"))
10853
11148
  return void 0;
@@ -10856,8 +11151,8 @@ async function readManagedServiceDefinition(manager, store) {
10856
11151
  }
10857
11152
  async function restoreManagedServiceDefinition(manager, store, definition2, runtime) {
10858
11153
  const path4 = managedServiceDefinitionPath(manager, store);
10859
- await (0, import_promises12.mkdir)((0, import_node_path10.dirname)(path4), { recursive: true });
10860
- await (0, import_promises12.writeFile)(path4, definition2, { encoding: "utf8", mode: 384 });
11154
+ await (0, import_promises13.mkdir)((0, import_node_path11.dirname)(path4), { recursive: true });
11155
+ await (0, import_promises13.writeFile)(path4, definition2, { encoding: "utf8", mode: 384 });
10861
11156
  if (manager === UserServiceManager.Launchd) {
10862
11157
  const domain = `gui/${process.getuid?.() ?? 0}`;
10863
11158
  await runCommandIgnoringFailure(runtime, "launchctl", [
@@ -10906,7 +11201,7 @@ function parseProcessId(value) {
10906
11201
  async function persistServiceManager(store, manager, managedEntrypointPath, desiredState = ManagedServiceDesiredState.Running) {
10907
11202
  await store.writeServiceManager({
10908
11203
  desiredState,
10909
- ...managedEntrypointPath ? { managedEntrypointPath: (0, import_node_path10.resolve)(managedEntrypointPath) } : {},
11204
+ ...managedEntrypointPath ? { managedEntrypointPath: (0, import_node_path11.resolve)(managedEntrypointPath) } : {},
10910
11205
  manager,
10911
11206
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
10912
11207
  });
@@ -10919,9 +11214,9 @@ async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
10919
11214
  const stored = (await store.readServiceManager()).value;
10920
11215
  if (!stored || stored.manager === UserServiceManager.None)
10921
11216
  return;
10922
- const candidate = (0, import_node_path10.resolve)(candidateEntrypointPath);
11217
+ const candidate = (0, import_node_path11.resolve)(candidateEntrypointPath);
10923
11218
  if (stored.managedEntrypointPath) {
10924
- if ((0, import_node_path10.resolve)(stored.managedEntrypointPath) !== candidate) {
11219
+ if ((0, import_node_path11.resolve)(stored.managedEntrypointPath) !== candidate) {
10925
11220
  throw new Error("The managed Connector belongs to a different CLI installation. Run service install from the owning CLI to transfer management.");
10926
11221
  }
10927
11222
  return;
@@ -10931,16 +11226,16 @@ async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
10931
11226
  }
10932
11227
  }
10933
11228
  async function isInsideSourceCheckout(path4) {
10934
- let directory = (0, import_node_path10.dirname)(path4);
11229
+ let directory = (0, import_node_path11.dirname)(path4);
10935
11230
  while (true) {
10936
11231
  try {
10937
- await (0, import_promises12.stat)((0, import_node_path10.join)(directory, ".git"));
11232
+ await (0, import_promises13.stat)((0, import_node_path11.join)(directory, ".git"));
10938
11233
  return true;
10939
11234
  } catch (error) {
10940
11235
  if (!isNodeErrorCode4(error, "ENOENT"))
10941
11236
  throw error;
10942
11237
  }
10943
- const parent = (0, import_node_path10.dirname)(directory);
11238
+ const parent = (0, import_node_path11.dirname)(directory);
10944
11239
  if (parent === directory)
10945
11240
  return false;
10946
11241
  directory = parent;
@@ -10969,10 +11264,10 @@ function automaticSelectionDetail(manager) {
10969
11264
  }
10970
11265
  async function installLaunchAgent(store, options, runtime) {
10971
11266
  const path4 = launchAgentPath();
10972
- await (0, import_promises12.mkdir)((0, import_node_path10.dirname)(path4), { recursive: true });
11267
+ await (0, import_promises13.mkdir)((0, import_node_path11.dirname)(path4), { recursive: true });
10973
11268
  const programArguments = [
10974
11269
  options.nodePath,
10975
- (0, import_node_path10.resolve)(options.entrypointPath),
11270
+ (0, import_node_path11.resolve)(options.entrypointPath),
10976
11271
  ...options.commandArguments
10977
11272
  ];
10978
11273
  const plist = `<?xml version="1.0" encoding="UTF-8"?>
@@ -11003,7 +11298,7 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
11003
11298
  </dict>
11004
11299
  </plist>
11005
11300
  `;
11006
- await (0, import_promises12.writeFile)(path4, plist, { encoding: "utf8", mode: 384 });
11301
+ await (0, import_promises13.writeFile)(path4, plist, { encoding: "utf8", mode: 384 });
11007
11302
  const domain = `gui/${process.getuid?.() ?? 0}`;
11008
11303
  await runCommandIgnoringFailure(runtime, "launchctl", [
11009
11304
  "bootout",
@@ -11019,10 +11314,10 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
11019
11314
  }
11020
11315
  async function installSystemdUserService(store, options, runtime) {
11021
11316
  const path4 = systemdUnitPath();
11022
- await (0, import_promises12.mkdir)((0, import_node_path10.dirname)(path4), { recursive: true });
11317
+ await (0, import_promises13.mkdir)((0, import_node_path11.dirname)(path4), { recursive: true });
11023
11318
  const command = [
11024
11319
  options.nodePath,
11025
- (0, import_node_path10.resolve)(options.entrypointPath),
11320
+ (0, import_node_path11.resolve)(options.entrypointPath),
11026
11321
  ...options.commandArguments
11027
11322
  ].map(escapeSystemdArgument).join(" ");
11028
11323
  const unit = `[Unit]
@@ -11041,7 +11336,7 @@ ${Object.entries(options.environment).map(([name, value]) => `Environment=${esca
11041
11336
  [Install]
11042
11337
  WantedBy=default.target
11043
11338
  `;
11044
- await (0, import_promises12.writeFile)(path4, unit, { encoding: "utf8", mode: 384 });
11339
+ await (0, import_promises13.writeFile)(path4, unit, { encoding: "utf8", mode: 384 });
11045
11340
  await runtime.run("systemctl", ["--user", "daemon-reload"]);
11046
11341
  await runtime.run("systemctl", [
11047
11342
  "--user",
@@ -11057,8 +11352,8 @@ WantedBy=default.target
11057
11352
  async function installSupervisorUserService(store, options, runtime) {
11058
11353
  const directory = supervisorDirectory(store);
11059
11354
  const configPath = supervisorConfigPath(store);
11060
- await (0, import_promises12.mkdir)(directory, { recursive: true, mode: 448 });
11061
- await (0, import_promises12.writeFile)(configPath, createSupervisorConfiguration(store, options), {
11355
+ await (0, import_promises13.mkdir)(directory, { recursive: true, mode: 448 });
11356
+ await (0, import_promises13.writeFile)(configPath, createSupervisorConfiguration(store, options), {
11062
11357
  encoding: "utf8",
11063
11358
  mode: 384
11064
11359
  });
@@ -11072,7 +11367,7 @@ async function installSupervisorUserService(store, options, runtime) {
11072
11367
  function createSupervisorConfiguration(store, options) {
11073
11368
  const command = [
11074
11369
  options.nodePath,
11075
- (0, import_node_path10.resolve)(options.entrypointPath),
11370
+ (0, import_node_path11.resolve)(options.entrypointPath),
11076
11371
  ...options.commandArguments
11077
11372
  ].map(escapeSupervisorArgument).join(" ");
11078
11373
  const environment = Object.entries(options.environment).map(([name, value]) => `${name}="${escapeSupervisorEnvironment(value)}"`).join(",");
@@ -11096,7 +11391,7 @@ serverurl=unix://${supervisorSocketPath(store)}
11096
11391
 
11097
11392
  [program:${supervisorProgramName}]
11098
11393
  command=${command}
11099
- directory=${escapeSupervisorPath((0, import_node_path10.dirname)((0, import_node_path10.resolve)(options.entrypointPath)))}
11394
+ directory=${escapeSupervisorPath((0, import_node_path11.dirname)((0, import_node_path11.resolve)(options.entrypointPath)))}
11100
11395
  environment=${environment}
11101
11396
  autostart=true
11102
11397
  autorestart=true
@@ -11129,8 +11424,8 @@ async function restartSupervisorUserService(store, runtime) {
11129
11424
  await startSupervisorUserService(store, runtime, supervisorProcessId, connectorProcessId);
11130
11425
  }
11131
11426
  async function startSupervisorUserService(store, runtime, previousSupervisorProcessId, previousConnectorProcessId) {
11132
- await (0, import_promises12.rm)(supervisorSocketPath(store), { force: true });
11133
- await (0, import_promises12.rm)(supervisorPidPath(store), { force: true });
11427
+ await (0, import_promises13.rm)(supervisorSocketPath(store), { force: true });
11428
+ await (0, import_promises13.rm)(supervisorPidPath(store), { force: true });
11134
11429
  await runtime.run("supervisord", ["-c", supervisorConfigPath(store)], {
11135
11430
  environment: sanitizeEnvironment(process.env),
11136
11431
  timeoutMilliseconds: serviceManagerMutationTimeoutMilliseconds
@@ -11227,7 +11522,7 @@ async function currentSupervisorProcessId(store, runtime) {
11227
11522
  } catch {
11228
11523
  }
11229
11524
  try {
11230
- const processId = parseProcessId(await (0, import_promises12.readFile)(supervisorPidPath(store), "utf8"));
11525
+ const processId = parseProcessId(await (0, import_promises13.readFile)(supervisorPidPath(store), "utf8"));
11231
11526
  return processId !== void 0 && serviceProcessIsRunning(runtime, processId) ? processId : void 0;
11232
11527
  } catch (error) {
11233
11528
  if (isNodeErrorCode4(error, "ENOENT"))
@@ -11249,26 +11544,26 @@ async function currentSupervisorProgramProcessId(store, runtime) {
11249
11544
  }
11250
11545
  }
11251
11546
  function launchAgentPath() {
11252
- return (0, import_node_path10.join)(process.env.HOME ?? (0, import_node_os7.homedir)(), "Library", "LaunchAgents", `${launchAgentLabel}.plist`);
11547
+ return (0, import_node_path11.join)(process.env.HOME ?? (0, import_node_os7.homedir)(), "Library", "LaunchAgents", `${launchAgentLabel}.plist`);
11253
11548
  }
11254
11549
  function systemdUnitPath() {
11255
- const configHome = process.env.XDG_CONFIG_HOME ?? (0, import_node_path10.join)(process.env.HOME ?? (0, import_node_os7.homedir)(), ".config");
11256
- return (0, import_node_path10.join)(configHome, "systemd", "user", "moxt-machine-connector.service");
11550
+ const configHome = process.env.XDG_CONFIG_HOME ?? (0, import_node_path11.join)(process.env.HOME ?? (0, import_node_os7.homedir)(), ".config");
11551
+ return (0, import_node_path11.join)(configHome, "systemd", "user", "moxt-machine-connector.service");
11257
11552
  }
11258
11553
  function supervisorDirectory(store) {
11259
- return (0, import_node_path10.join)(store.baseDirectory, "supervisor");
11554
+ return (0, import_node_path11.join)(store.baseDirectory, "supervisor");
11260
11555
  }
11261
11556
  function supervisorConfigPath(store) {
11262
- return (0, import_node_path10.join)(supervisorDirectory(store), "supervisord.conf");
11557
+ return (0, import_node_path11.join)(supervisorDirectory(store), "supervisord.conf");
11263
11558
  }
11264
11559
  function supervisorSocketPath(store) {
11265
- return (0, import_node_path10.join)(supervisorDirectory(store), "supervisor.sock");
11560
+ return (0, import_node_path11.join)(supervisorDirectory(store), "supervisor.sock");
11266
11561
  }
11267
11562
  function supervisorPidPath(store) {
11268
- return (0, import_node_path10.join)(supervisorDirectory(store), "supervisord.pid");
11563
+ return (0, import_node_path11.join)(supervisorDirectory(store), "supervisord.pid");
11269
11564
  }
11270
11565
  function supervisorLogPath(store) {
11271
- return (0, import_node_path10.join)(supervisorDirectory(store), "supervisord.log");
11566
+ return (0, import_node_path11.join)(supervisorDirectory(store), "supervisord.log");
11272
11567
  }
11273
11568
  async function commandSucceeds(runtime, command, argumentsList) {
11274
11569
  try {
@@ -11335,15 +11630,15 @@ function serviceManagerCurrentTime(runtime) {
11335
11630
  async function serviceManagerDelay(runtime, milliseconds) {
11336
11631
  await (runtime.delay?.(milliseconds) ?? delay5(milliseconds));
11337
11632
  }
11338
- var import_node_child_process5, import_promises12, import_node_os7, import_node_path10, import_node_util2, execFileAsync, launchAgentLabel, serviceManagerProbeTimeoutMilliseconds, serviceManagerMutationTimeoutMilliseconds, supervisorProgramName, supervisorControlTimeoutMilliseconds, supervisorProgramStartSeconds, supervisorProgramStartRetries, supervisorProgramStopWaitSeconds, supervisorLifecycleBufferMilliseconds, supervisorExitTimeoutMilliseconds, supervisorProgramStartTimeoutMilliseconds, ServiceManagerPreference, UserServiceManager, defaultServiceManagerRuntime;
11633
+ var import_node_child_process5, import_promises13, import_node_os7, import_node_path11, import_node_util2, execFileAsync, launchAgentLabel, serviceManagerProbeTimeoutMilliseconds, serviceManagerMutationTimeoutMilliseconds, supervisorProgramName, supervisorControlTimeoutMilliseconds, supervisorProgramStartSeconds, supervisorProgramStartRetries, supervisorProgramStopWaitSeconds, supervisorLifecycleBufferMilliseconds, supervisorExitTimeoutMilliseconds, supervisorProgramStartTimeoutMilliseconds, ServiceManagerPreference, UserServiceManager, defaultServiceManagerRuntime;
11339
11634
  var init_service_manager = __esm({
11340
11635
  "../machine-connector/dist/runtime/service-manager.js"() {
11341
11636
  "use strict";
11342
11637
  init_cjs_shims();
11343
11638
  import_node_child_process5 = require("child_process");
11344
- import_promises12 = require("fs/promises");
11639
+ import_promises13 = require("fs/promises");
11345
11640
  import_node_os7 = require("os");
11346
- import_node_path10 = require("path");
11641
+ import_node_path11 = require("path");
11347
11642
  import_node_util2 = require("util");
11348
11643
  init_runtime_types();
11349
11644
  init_shell_environment();
@@ -11437,9 +11732,9 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
11437
11732
  try {
11438
11733
  refresh = await refreshManagedUserService(store, {
11439
11734
  commandArguments: [...options.commandArguments],
11440
- entrypointPath: (0, import_node_path11.resolve)(options.entrypointPath),
11735
+ entrypointPath: (0, import_node_path12.resolve)(options.entrypointPath),
11441
11736
  environment: { ...options.environment },
11442
- nodePath: (0, import_node_path11.resolve)(options.nodePath)
11737
+ nodePath: (0, import_node_path12.resolve)(options.nodePath)
11443
11738
  });
11444
11739
  if (!refresh) {
11445
11740
  throw new Error("The Connector service is no longer managed by Moxt");
@@ -11471,10 +11766,10 @@ async function validateCliEntrypoint(options, store) {
11471
11766
  if (options.commandArguments.length !== 2 || options.commandArguments[0] !== "machine" || options.commandArguments[1] !== "daemon") {
11472
11767
  throw new Error("The managed daemon command must be `machine daemon`");
11473
11768
  }
11474
- const nodePath = await (0, import_promises13.realpath)((0, import_node_path11.resolve)(options.nodePath));
11475
- const entrypointPath = await (0, import_promises13.realpath)((0, import_node_path11.resolve)(options.entrypointPath));
11476
- await (0, import_promises13.access)(nodePath, import_promises13.constants.X_OK);
11477
- await (0, import_promises13.access)(entrypointPath, import_promises13.constants.R_OK);
11769
+ const nodePath = await (0, import_promises14.realpath)((0, import_node_path12.resolve)(options.nodePath));
11770
+ const entrypointPath = await (0, import_promises14.realpath)((0, import_node_path12.resolve)(options.entrypointPath));
11771
+ await (0, import_promises14.access)(nodePath, import_promises14.constants.X_OK);
11772
+ await (0, import_promises14.access)(entrypointPath, import_promises14.constants.R_OK);
11478
11773
  const probe = await execFileAsync2(nodePath, [entrypointPath, "--version"], {
11479
11774
  encoding: "utf8",
11480
11775
  env: {
@@ -11507,14 +11802,14 @@ function delay6(milliseconds) {
11507
11802
  function errorMessage4(error) {
11508
11803
  return error instanceof Error ? error.message : String(error);
11509
11804
  }
11510
- var import_node_child_process6, import_promises13, import_node_path11, import_node_util3, reconcileTimeoutMilliseconds, execFileAsync2, DaemonReconcileOutcome, DaemonRefreshError;
11805
+ var import_node_child_process6, import_promises14, import_node_path12, import_node_util3, reconcileTimeoutMilliseconds, execFileAsync2, DaemonReconcileOutcome, DaemonRefreshError;
11511
11806
  var init_daemon_reconcile = __esm({
11512
11807
  "../machine-connector/dist/runtime/daemon-reconcile.js"() {
11513
11808
  "use strict";
11514
11809
  init_cjs_shims();
11515
11810
  import_node_child_process6 = require("child_process");
11516
- import_promises13 = require("fs/promises");
11517
- import_node_path11 = require("path");
11811
+ import_promises14 = require("fs/promises");
11812
+ import_node_path12 = require("path");
11518
11813
  import_node_util3 = require("util");
11519
11814
  init_local_ipc();
11520
11815
  init_process_lock();
@@ -11571,7 +11866,7 @@ async function runMachineDoctor(store) {
11571
11866
  }
11572
11867
  for (const connection of connections) {
11573
11868
  try {
11574
- await (0, import_promises14.access)(connection.rootPath, import_node_fs.constants.R_OK | import_node_fs.constants.X_OK);
11869
+ await (0, import_promises15.access)(connection.rootPath, import_node_fs.constants.R_OK | import_node_fs.constants.X_OK);
11575
11870
  checks.push({
11576
11871
  detail: connection.rootPath,
11577
11872
  name: `root:${connection.connectionId}`,
@@ -11586,7 +11881,7 @@ async function runMachineDoctor(store) {
11586
11881
  }
11587
11882
  const relayUrl = new URL(connection.relayOrigin);
11588
11883
  try {
11589
- const address = await (0, import_promises15.lookup)(relayUrl.hostname);
11884
+ const address = await (0, import_promises16.lookup)(relayUrl.hostname);
11590
11885
  checks.push({
11591
11886
  detail: `${relayUrl.hostname} resolves to ${address.address}`,
11592
11887
  name: `dns:${connection.connectionId}`,
@@ -11668,15 +11963,15 @@ async function runMachineDoctor(store) {
11668
11963
  function errorMessage5(error) {
11669
11964
  return error instanceof Error ? error.message : String(error);
11670
11965
  }
11671
- var import_node_child_process7, import_promises14, import_node_fs, import_promises15, import_node_util4, execFileAsync3, DoctorCheckStatus;
11966
+ var import_node_child_process7, import_promises15, import_node_fs, import_promises16, import_node_util4, execFileAsync3, DoctorCheckStatus;
11672
11967
  var init_doctor = __esm({
11673
11968
  "../machine-connector/dist/runtime/doctor.js"() {
11674
11969
  "use strict";
11675
11970
  init_cjs_shims();
11676
11971
  import_node_child_process7 = require("child_process");
11677
- import_promises14 = require("fs/promises");
11972
+ import_promises15 = require("fs/promises");
11678
11973
  import_node_fs = require("fs");
11679
- import_promises15 = require("dns/promises");
11974
+ import_promises16 = require("dns/promises");
11680
11975
  import_node_util4 = require("util");
11681
11976
  init_local_ipc();
11682
11977
  execFileAsync3 = (0, import_node_util4.promisify)(import_node_child_process7.execFile);
@@ -11946,7 +12241,7 @@ async function readRecentLogLines(store) {
11946
12241
  }
11947
12242
  async function readOptionalFile(path4) {
11948
12243
  try {
11949
- return await (0, import_promises16.readFile)(path4, "utf8");
12244
+ return await (0, import_promises17.readFile)(path4, "utf8");
11950
12245
  } catch (error) {
11951
12246
  if (isMissingFile(error)) {
11952
12247
  return "";
@@ -12005,13 +12300,13 @@ function isMissingFile(error) {
12005
12300
  function errorMessage6(error) {
12006
12301
  return error instanceof Error ? error.message : String(error);
12007
12302
  }
12008
- var import_promises16, import_promises17, import_node_readline, alternateScreenEnter, alternateScreenExit, clearScreen, cursorHide, cursorShow, styleReset, styleHeader, styleSelected, refreshIntervalMilliseconds, maximumLogLines, MachineManagerView, MachineManagerAction, MachineManagerSnapshotDepth, InteractiveMachineManager;
12303
+ var import_promises17, import_promises18, import_node_readline, alternateScreenEnter, alternateScreenExit, clearScreen, cursorHide, cursorShow, styleReset, styleHeader, styleSelected, refreshIntervalMilliseconds, maximumLogLines, MachineManagerView, MachineManagerAction, MachineManagerSnapshotDepth, InteractiveMachineManager;
12009
12304
  var init_machine_manager = __esm({
12010
12305
  "../machine-connector/dist/runtime/machine-manager.js"() {
12011
12306
  "use strict";
12012
12307
  init_cjs_shims();
12013
- import_promises16 = require("fs/promises");
12014
- import_promises17 = require("readline/promises");
12308
+ import_promises17 = require("fs/promises");
12309
+ import_promises18 = require("readline/promises");
12015
12310
  import_node_readline = require("readline");
12016
12311
  init_doctor();
12017
12312
  init_local_ipc();
@@ -12245,7 +12540,7 @@ var init_machine_manager = __esm({
12245
12540
  }
12246
12541
  async runCommandAction(action) {
12247
12542
  this.suspendTerminal();
12248
- const reader = (0, import_promises17.createInterface)({
12543
+ const reader = (0, import_promises18.createInterface)({
12249
12544
  input: process.stdin,
12250
12545
  output: process.stdout
12251
12546
  });
@@ -12486,7 +12781,7 @@ async function pairMachine(store, options) {
12486
12781
  throw new Error("Local Machine pairing expired");
12487
12782
  }
12488
12783
  function displayNameForRoot(canonicalRoot) {
12489
- const name = (0, import_node_path12.basename)(canonicalRoot);
12784
+ const name = (0, import_node_path13.basename)(canonicalRoot);
12490
12785
  return name.length > 0 ? name : canonicalRoot;
12491
12786
  }
12492
12787
  function getOperatingSystem() {
@@ -12508,7 +12803,7 @@ function delay7(milliseconds) {
12508
12803
  setTimeout(resolvePromise, milliseconds);
12509
12804
  });
12510
12805
  }
12511
- var import_node_child_process8, import_node_crypto11, import_node_os8, import_node_path12, connectedPairingStatus, rejectedPairingStatus, expiredPairingStatus, pairingPollMilliseconds;
12806
+ var import_node_child_process8, import_node_crypto11, import_node_os8, import_node_path13, connectedPairingStatus, rejectedPairingStatus, expiredPairingStatus, pairingPollMilliseconds;
12512
12807
  var init_pairing = __esm({
12513
12808
  "../machine-connector/dist/runtime/pairing.js"() {
12514
12809
  "use strict";
@@ -12516,7 +12811,7 @@ var init_pairing = __esm({
12516
12811
  import_node_child_process8 = require("child_process");
12517
12812
  import_node_crypto11 = require("crypto");
12518
12813
  import_node_os8 = require("os");
12519
- import_node_path12 = require("path");
12814
+ import_node_path13 = require("path");
12520
12815
  init_contracts();
12521
12816
  init_version();
12522
12817
  init_enums();
@@ -12604,7 +12899,7 @@ function isMachineLifecycleMutation(command, commandArguments) {
12604
12899
  async function connectCommand(store, argumentsList, entrypoint) {
12605
12900
  const options = parseOptions(argumentsList);
12606
12901
  const connectionCode = requiredOption(options, "code");
12607
- const rootPath = (0, import_node_path13.resolve)(options.root ?? process.cwd());
12902
+ const rootPath = (0, import_node_path14.resolve)(options.root ?? process.cwd());
12608
12903
  const serviceManagerPreference = requestedServiceManagerPreference(options);
12609
12904
  await validateExplicitServiceManagerPreference(serviceManagerPreference);
12610
12905
  writeLine("Internal Full Host Access: enabled");
@@ -12890,7 +13185,7 @@ async function waitForDaemonOnline(store) {
12890
13185
  }
12891
13186
  async function readOptionalFile2(path4) {
12892
13187
  try {
12893
- return await (0, import_promises18.readFile)(path4, "utf8");
13188
+ return await (0, import_promises19.readFile)(path4, "utf8");
12894
13189
  } catch {
12895
13190
  return "";
12896
13191
  }
@@ -12919,13 +13214,13 @@ function delay8(milliseconds) {
12919
13214
  setTimeout(resolvePromise, milliseconds);
12920
13215
  });
12921
13216
  }
12922
- var import_promises18, import_node_path13, defaultRelayOrigin;
13217
+ var import_promises19, import_node_path14, defaultRelayOrigin;
12923
13218
  var init_cli = __esm({
12924
13219
  "../machine-connector/dist/cli.js"() {
12925
13220
  "use strict";
12926
13221
  init_cjs_shims();
12927
- import_promises18 = require("fs/promises");
12928
- import_node_path13 = require("path");
13222
+ import_promises19 = require("fs/promises");
13223
+ import_node_path14 = require("path");
12929
13224
  init_daemon();
12930
13225
  init_daemon_reconcile();
12931
13226
  init_doctor();
@@ -12995,6 +13290,7 @@ __export(dist_exports, {
12995
13290
  executeClaudeStart: () => executeClaudeStart,
12996
13291
  installUserService: () => installUserService,
12997
13292
  isTerminalJobStatus: () => isTerminalJobStatus,
13293
+ localCodexRuntimeEventsRequestBytes: () => localCodexRuntimeEventsRequestBytes,
12998
13294
  localMachineJobTargetRelationship: () => localMachineJobTargetRelationship,
12999
13295
  machineExecutionContextEnvironmentName: () => machineExecutionContextEnvironmentName,
13000
13296
  machineManagerActions: () => machineManagerActions,
@@ -13218,7 +13514,7 @@ function getApiKeyOrUndefined() {
13218
13514
 
13219
13515
  // src/utils/http.ts
13220
13516
  function getUserAgent() {
13221
- return `moxt-cli/${"0.10.0-beta.2"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
13517
+ return `moxt-cli/${"0.10.0-beta.4"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
13222
13518
  }
13223
13519
  async function sendRequest(method, path4, init) {
13224
13520
  return await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -26801,7 +27097,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
26801
27097
  var MAX_BATCH_SIZE = 100;
26802
27098
  function commonLabels() {
26803
27099
  return {
26804
- cli_version: "0.10.0-beta.2",
27100
+ cli_version: "0.10.0-beta.4",
26805
27101
  node_version: process.versions.node,
26806
27102
  os: (0, import_node_os9.platform)(),
26807
27103
  arch: (0, import_node_os9.arch)(),
@@ -26847,7 +27143,7 @@ async function flush() {
26847
27143
  }
26848
27144
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
26849
27145
  const payload = {
26850
- release_id: "0.10.0-beta.2",
27146
+ release_id: "0.10.0-beta.4",
26851
27147
  client_type: "cli",
26852
27148
  metric_data_list: batch.map((m) => ({
26853
27149
  profile: "cli",
@@ -27048,7 +27344,7 @@ function registryWorker() {
27048
27344
 
27049
27345
  // src/update/prompt.ts
27050
27346
  init_cjs_shims();
27051
- var import_promises19 = require("readline/promises");
27347
+ var import_promises20 = require("readline/promises");
27052
27348
  async function promptForUpdate(input, output, currentVersion, latestVersion, timeoutMs) {
27053
27349
  output.write(`
27054
27350
  A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion}
@@ -27061,7 +27357,7 @@ A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion
27061
27357
  const controller = new AbortController();
27062
27358
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
27063
27359
  timeout.unref();
27064
- const readline = (0, import_promises19.createInterface)({ input, output, terminal: true });
27360
+ const readline = (0, import_promises20.createInterface)({ input, output, terminal: true });
27065
27361
  try {
27066
27362
  const answer = await readline.question("", { signal: controller.signal });
27067
27363
  if (answer.trim() === "1") return "update";
@@ -27164,7 +27460,7 @@ function commandPath2(command) {
27164
27460
 
27165
27461
  // src/update/daemon-reconcile-hook.ts
27166
27462
  init_cjs_shims();
27167
- var import_node_path14 = require("path");
27463
+ var import_node_path15 = require("path");
27168
27464
  function installDaemonReconcileHook(program3, cliVersion) {
27169
27465
  program3.hook("preAction", async (_thisCommand, actionCommand) => {
27170
27466
  if (!isEligible2(actionCommand)) return;
@@ -27186,9 +27482,9 @@ function installDaemonReconcileHook(program3, cliVersion) {
27186
27482
  await reconcileManagedDaemon2({
27187
27483
  cliVersion,
27188
27484
  commandArguments: ["machine", "daemon"],
27189
- entrypointPath: (0, import_node_path14.resolve)(entrypointPath),
27485
+ entrypointPath: (0, import_node_path15.resolve)(entrypointPath),
27190
27486
  environment: {},
27191
- nodePath: (0, import_node_path14.resolve)(process.execPath),
27487
+ nodePath: (0, import_node_path15.resolve)(process.execPath),
27192
27488
  onActiveJobs: (count) => {
27193
27489
  process.stderr.write(
27194
27490
  `Warning: restarting the managed Connector will interrupt ${count} active ${count === 1 ? "Job" : "Jobs"}.
@@ -27230,9 +27526,9 @@ function commandPath3(command) {
27230
27526
  }
27231
27527
 
27232
27528
  // src/index.ts
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");
27529
+ var program2 = createProgram("0.10.0-beta.4");
27530
+ installDaemonReconcileHook(program2, "0.10.0-beta.4");
27531
+ installUpdateHook(program2, "0.10.0-beta.4");
27236
27532
  instrumentProgram(program2);
27237
27533
  installExitHandler();
27238
27534
  program2.parseAsync(process.argv).then(async () => {