@moxt-ai/cli 0.11.0-beta.6 → 0.11.0-beta.8

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
@@ -5397,7 +5397,7 @@ var init_app_server_client = __esm({
5397
5397
  init_version();
5398
5398
  init_contracts2();
5399
5399
  maximumFrameBytes = 8e6;
5400
- requestTimeoutMilliseconds = 3e4;
5400
+ requestTimeoutMilliseconds = 6e4;
5401
5401
  processExitGraceMilliseconds = 2e3;
5402
5402
  processTreePollMilliseconds = 250;
5403
5403
  processTableTimeoutMilliseconds = 1e3;
@@ -9491,14 +9491,14 @@ var init_local_file_source = __esm({
9491
9491
  size: stat6.size
9492
9492
  };
9493
9493
  }
9494
- async validate(path4) {
9495
- const file = await this.resolveFile(path4);
9496
- const stat6 = await (0, import_promises12.lstat)(file);
9494
+ async validate(path4, kind = "file") {
9495
+ const target = kind === "directory" ? await this.resolveDirectory(path4) : await this.resolveFile(path4);
9496
+ const stat6 = await (0, import_promises12.lstat)(target);
9497
9497
  return {
9498
- kind: "file",
9499
- name: (0, import_node_path9.basename)(file),
9500
- path: portable((0, import_node_path9.relative)(this.workingDirectory, file)),
9501
- size: stat6.size
9498
+ kind,
9499
+ name: (0, import_node_path9.basename)(target),
9500
+ path: portable((0, import_node_path9.relative)(this.workingDirectory, target)),
9501
+ ...kind === "file" ? { size: stat6.size } : {}
9502
9502
  };
9503
9503
  }
9504
9504
  async resolveDirectory(path4) {
@@ -9577,6 +9577,147 @@ var init_local_file_source = __esm({
9577
9577
  }
9578
9578
  });
9579
9579
 
9580
+ // ../machine-connector/dist/runtime/local-codex-runtime/discovery-worker.js
9581
+ async function executeLocalFileDiscovery(pairedRoot, request2) {
9582
+ if (request2.kind !== LocalCodexDiscoveryKindWire.LocalFileList && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileSearch && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileRead && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileValidate) {
9583
+ throw new Error(`Unsupported Local file discovery kind ${request2.kind}`);
9584
+ }
9585
+ const source = await LocalFileSource.create(pairedRoot, request2.workingDirectory ?? ".");
9586
+ if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileList) {
9587
+ const page2 = await source.list(request2.relativeDirectory ?? ".", request2.cursor, request2.limit);
9588
+ return {
9589
+ ...page2,
9590
+ requestId: request2.requestId,
9591
+ status: LocalCodexDiscoveryStatusWire.Succeeded
9592
+ };
9593
+ }
9594
+ if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileSearch) {
9595
+ const page2 = await source.search(request2.query ?? "", request2.cursor, request2.limit);
9596
+ return {
9597
+ ...page2,
9598
+ requestId: request2.requestId,
9599
+ status: LocalCodexDiscoveryStatusWire.Succeeded
9600
+ };
9601
+ }
9602
+ if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileValidate) {
9603
+ return {
9604
+ entries: [
9605
+ await source.validate(request2.filePath ?? "", request2.fileKind ?? "file")
9606
+ ],
9607
+ requestId: request2.requestId,
9608
+ status: LocalCodexDiscoveryStatusWire.Succeeded
9609
+ };
9610
+ }
9611
+ const content3 = await source.read(request2.filePath ?? "");
9612
+ return {
9613
+ content: content3.content,
9614
+ encoding: content3.encoding,
9615
+ entries: [
9616
+ {
9617
+ kind: "file",
9618
+ name: content3.name,
9619
+ path: content3.path,
9620
+ size: content3.size
9621
+ }
9622
+ ],
9623
+ requestId: request2.requestId,
9624
+ status: LocalCodexDiscoveryStatusWire.Succeeded
9625
+ };
9626
+ }
9627
+ async function waitForAbort(signal, milliseconds) {
9628
+ if (signal.aborted) {
9629
+ return;
9630
+ }
9631
+ await new Promise((resolvePromise) => {
9632
+ const complete = () => {
9633
+ clearTimeout(timeout);
9634
+ signal.removeEventListener("abort", complete);
9635
+ resolvePromise();
9636
+ };
9637
+ const timeout = setTimeout(complete, milliseconds);
9638
+ timeout.unref();
9639
+ signal.addEventListener("abort", complete, { once: true });
9640
+ });
9641
+ }
9642
+ var discoveryWaitSeconds, defaultNetworkRetryMilliseconds, maximumNetworkRetryMilliseconds, LocalCodexDiscoveryWorker;
9643
+ var init_discovery_worker = __esm({
9644
+ "../machine-connector/dist/runtime/local-codex-runtime/discovery-worker.js"() {
9645
+ "use strict";
9646
+ init_cjs_shims();
9647
+ init_retry_backoff();
9648
+ init_contracts2();
9649
+ init_local_file_source();
9650
+ discoveryWaitSeconds = 25;
9651
+ defaultNetworkRetryMilliseconds = 2e3;
9652
+ maximumNetworkRetryMilliseconds = 6e4;
9653
+ LocalCodexDiscoveryWorker = class {
9654
+ params;
9655
+ lifetimeAbort = new AbortController();
9656
+ running;
9657
+ constructor(params) {
9658
+ this.params = params;
9659
+ }
9660
+ async run() {
9661
+ if (this.running !== void 0) {
9662
+ return await this.running;
9663
+ }
9664
+ this.running = this.runLoop();
9665
+ return await this.running;
9666
+ }
9667
+ async stop() {
9668
+ this.revoke();
9669
+ await this.running;
9670
+ }
9671
+ revoke() {
9672
+ this.lifetimeAbort.abort();
9673
+ }
9674
+ async runLoop() {
9675
+ const retryBackoff = new RetryBackoff({
9676
+ maximumMilliseconds: maximumNetworkRetryMilliseconds,
9677
+ minimumMilliseconds: this.params.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds,
9678
+ random: this.params.random
9679
+ });
9680
+ while (!this.lifetimeAbort.signal.aborted && !this.params.relay.isRevoked()) {
9681
+ try {
9682
+ const response = await this.params.relay.claimCodexRuntimeDiscovery({
9683
+ connectorInstanceId: this.params.connectorInstanceId,
9684
+ protocolVersion: localCodexRuntimeProtocolVersion,
9685
+ waitSeconds: discoveryWaitSeconds
9686
+ }, this.lifetimeAbort.signal);
9687
+ if (response.request !== void 0) {
9688
+ await this.complete(response.request);
9689
+ }
9690
+ retryBackoff.reset();
9691
+ } catch (error) {
9692
+ if (this.lifetimeAbort.signal.aborted || this.params.relay.isRevoked()) {
9693
+ return;
9694
+ }
9695
+ await this.params.logger.error(`Local Codex discovery loop failed for connection ${this.params.connectionId}`, error);
9696
+ await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
9697
+ }
9698
+ }
9699
+ }
9700
+ async complete(request2) {
9701
+ let result;
9702
+ try {
9703
+ result = await this.params.execute(request2);
9704
+ } catch (error) {
9705
+ await this.params.logger.error(`Local Codex ${request2.kind} discovery failed for connection ${this.params.connectionId}`, error);
9706
+ result = {
9707
+ errorCode: this.params.failureErrorCode(request2),
9708
+ requestId: request2.requestId,
9709
+ status: LocalCodexDiscoveryStatusWire.Failed
9710
+ };
9711
+ }
9712
+ const completion = await this.params.relay.completeCodexRuntimeDiscovery(request2.requestId, this.params.connectorInstanceId, result, this.lifetimeAbort.signal);
9713
+ if (!completion.accepted) {
9714
+ await this.params.logger.info(`Local Codex discovery request ${request2.requestId} expired before completion`);
9715
+ }
9716
+ }
9717
+ };
9718
+ }
9719
+ });
9720
+
9580
9721
  // ../machine-connector/dist/runtime/local-codex-runtime/durable-attempt.js
9581
9722
  function assertCompatibleClaim(persisted, connectionId, claim, allowRestartFenceRotation) {
9582
9723
  if (persisted.connectionId !== connectionId || persisted.claim.attemptId !== claim.attemptId || persisted.claim.attemptGeneration !== claim.attemptGeneration || persisted.claim.conversationId !== claim.conversationId || persisted.claim.turnId !== claim.turnId || persisted.claim.expectedNativeStoreIdentity !== claim.expectedNativeStoreIdentity) {
@@ -10369,10 +10510,11 @@ async function toCodexInput(items, pairedRoot, relativeWorkingDirectory) {
10369
10510
  const path4 = optionalString3(payload.path).value;
10370
10511
  if (path4 === void 0)
10371
10512
  throw new Error("Local file input has no path");
10372
- await source.validate(path4);
10513
+ const kind = payload.kind === "directory" ? "directory" : "file";
10514
+ await source.validate(path4, kind);
10373
10515
  return {
10374
10516
  type: "text",
10375
- text: `@${path4}`,
10517
+ text: `@${path4}${kind === "directory" && !path4.endsWith("/") ? "/" : ""}`,
10376
10518
  text_elements: []
10377
10519
  };
10378
10520
  }
@@ -10561,7 +10703,7 @@ async function probeExecutable(executable, environment) {
10561
10703
  };
10562
10704
  }
10563
10705
  }
10564
- async function waitForAbort(signal, milliseconds) {
10706
+ async function waitForAbort2(signal, milliseconds) {
10565
10707
  if (signal.aborted) {
10566
10708
  return;
10567
10709
  }
@@ -10612,7 +10754,7 @@ function parseLeaseDeadline(value) {
10612
10754
  function routineLeaseRenewalDelayMilliseconds(remainingLeaseMilliseconds) {
10613
10755
  return Math.min(leaseRenewIntervalMilliseconds, Math.max(1, Math.floor(remainingLeaseMilliseconds / leaseRenewalIntervalsBeforeDeadline)));
10614
10756
  }
10615
- var import_node_child_process4, import_promises13, import_node_os7, import_node_path11, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, discoveryWaitSeconds, maximumDiscoveryDirectories, maximumDiscoveryModels, maximumModelListPages, eventUploadCoalesceMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewalIntervalsBeforeDeadline, defaultNetworkRetryMilliseconds, maximumNetworkRetryMilliseconds, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryScanIntervalMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, maximumThreadTitleCharacters, maximumThreadTitleSourceCharacters, threadTitleGenerationTimeoutMilliseconds, interruptedExecutionCleanupTimeoutMilliseconds, threadTitleGenerationInstructions, threadTitleGenerationOutputSchema, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, WorkerStoppedError, LocalCodexRuntimeConnectionWorker;
10757
+ var import_node_child_process4, import_promises13, import_node_os7, import_node_path11, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, maximumDiscoveryDirectories, maximumDiscoveryModels, maximumModelListPages, eventUploadCoalesceMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewalIntervalsBeforeDeadline, defaultNetworkRetryMilliseconds2, maximumNetworkRetryMilliseconds2, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryScanIntervalMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, maximumThreadTitleCharacters, maximumThreadTitleSourceCharacters, threadTitleGenerationTimeoutMilliseconds, interruptedExecutionCleanupTimeoutMilliseconds, threadTitleGenerationInstructions, threadTitleGenerationOutputSchema, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, WorkerStoppedError, LocalCodexRuntimeConnectionWorker;
10616
10758
  var init_runtime_worker = __esm({
10617
10759
  "../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
10618
10760
  "use strict";
@@ -10627,12 +10769,12 @@ var init_runtime_worker = __esm({
10627
10769
  init_app_server_client();
10628
10770
  init_contracts2();
10629
10771
  init_local_file_source();
10772
+ init_discovery_worker();
10630
10773
  init_durable_attempt();
10631
10774
  init_event_normalizer();
10632
10775
  heartbeatIntervalMilliseconds = 2e4;
10633
10776
  claimRetryMilliseconds = 250;
10634
10777
  claimWaitSeconds = 25;
10635
- discoveryWaitSeconds = 25;
10636
10778
  maximumDiscoveryDirectories = 1e3;
10637
10779
  maximumDiscoveryModels = 100;
10638
10780
  maximumModelListPages = 10;
@@ -10641,8 +10783,8 @@ var init_runtime_worker = __esm({
10641
10783
  preferredEventUploadRequestBytes = 96e3;
10642
10784
  leaseRenewIntervalMilliseconds = 1e4;
10643
10785
  leaseRenewalIntervalsBeforeDeadline = 3;
10644
- defaultNetworkRetryMilliseconds = 1e3;
10645
- maximumNetworkRetryMilliseconds = 6e4;
10786
+ defaultNetworkRetryMilliseconds2 = 1e3;
10787
+ maximumNetworkRetryMilliseconds2 = 6e4;
10646
10788
  interactionTimeoutMilliseconds = 10 * 60 * 1e3;
10647
10789
  executableProbeTimeoutMilliseconds = 5e3;
10648
10790
  recoveryScanIntervalMilliseconds = 1e3;
@@ -10708,6 +10850,7 @@ var init_runtime_worker = __esm({
10708
10850
  configured = false;
10709
10851
  enabled = false;
10710
10852
  executionTasks = /* @__PURE__ */ new Map();
10853
+ discoveryWorker;
10711
10854
  lastCapabilityStartError;
10712
10855
  lifetimeAbort = new AbortController();
10713
10856
  networkRetryMilliseconds;
@@ -10723,8 +10866,18 @@ var init_runtime_worker = __esm({
10723
10866
  this.environment = environment;
10724
10867
  this.connectorInstanceId = connectorInstanceId;
10725
10868
  this.logger = logger;
10726
- this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds;
10869
+ this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds2;
10727
10870
  this.random = options.random ?? Math.random;
10871
+ this.discoveryWorker = new LocalCodexDiscoveryWorker({
10872
+ connectionId: connection.connectionId,
10873
+ connectorInstanceId,
10874
+ execute: async (request2) => await this.executeDiscovery(request2),
10875
+ failureErrorCode: (request2) => request2.kind === LocalCodexDiscoveryKindWire.ModelList ? "model_discovery_failed" : "directory_unavailable",
10876
+ logger,
10877
+ networkRetryMilliseconds: this.networkRetryMilliseconds,
10878
+ random: this.random,
10879
+ relay
10880
+ });
10728
10881
  this.processPool.register(connection.connectionId, this);
10729
10882
  }
10730
10883
  async run() {
@@ -10740,6 +10893,7 @@ var init_runtime_worker = __esm({
10740
10893
  }
10741
10894
  revoke() {
10742
10895
  this.lifetimeAbort.abort();
10896
+ this.discoveryWorker.revoke();
10743
10897
  for (const active of this.activeAttempts.values()) {
10744
10898
  active.finished.abort();
10745
10899
  }
@@ -11037,7 +11191,7 @@ var init_runtime_worker = __esm({
11037
11191
  try {
11038
11192
  await Promise.all([
11039
11193
  this.runHeartbeatLoop(),
11040
- this.runDiscoveryLoop(),
11194
+ this.discoveryWorker.run(),
11041
11195
  this.runAttemptLoops()
11042
11196
  ]);
11043
11197
  } finally {
@@ -11055,7 +11209,7 @@ var init_runtime_worker = __esm({
11055
11209
  async runHeartbeatLoop() {
11056
11210
  while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
11057
11211
  if ([...this.activeAttempts.values()].some((active) => active.interruptedCleanupStarted)) {
11058
- await waitForAbort(this.lifetimeAbort.signal, claimRetryMilliseconds);
11212
+ await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
11059
11213
  continue;
11060
11214
  }
11061
11215
  try {
@@ -11068,19 +11222,19 @@ var init_runtime_worker = __esm({
11068
11222
  }
11069
11223
  await this.logger.error(`Local Codex Runtime heartbeat failed for connection ${this.connection.connectionId}`, error);
11070
11224
  }
11071
- await waitForAbort(this.lifetimeAbort.signal, heartbeatIntervalMilliseconds);
11225
+ await waitForAbort2(this.lifetimeAbort.signal, heartbeatIntervalMilliseconds);
11072
11226
  }
11073
11227
  }
11074
11228
  async runClaimLoop() {
11075
11229
  const retryBackoff = this.createNetworkRetryBackoff();
11076
11230
  while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
11077
11231
  if (!this.configured || !this.enabled || !this.runtimeReady()) {
11078
- await waitForAbort(this.lifetimeAbort.signal, claimRetryMilliseconds);
11232
+ await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
11079
11233
  continue;
11080
11234
  }
11081
11235
  const slot = this.processPool.tryAcquireExecutionSlot(this.connection.connectionId).value;
11082
11236
  if (slot === void 0) {
11083
- await waitForAbort(this.lifetimeAbort.signal, claimRetryMilliseconds);
11237
+ await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
11084
11238
  continue;
11085
11239
  }
11086
11240
  let executionScheduled = false;
@@ -11103,14 +11257,14 @@ var init_runtime_worker = __esm({
11103
11257
  if (reclaimableClaimWindow.isAccepted()) {
11104
11258
  retryBackoff.reset();
11105
11259
  } else {
11106
- await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11260
+ await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11107
11261
  }
11108
11262
  } catch (error) {
11109
11263
  if (this.lifetimeAbort.signal.aborted || this.relay.isRevoked()) {
11110
11264
  return;
11111
11265
  }
11112
11266
  await this.logger.error(`Local Codex Runtime claim loop failed for connection ${this.connection.connectionId}`, error);
11113
- await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11267
+ await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11114
11268
  } finally {
11115
11269
  if (!executionScheduled) {
11116
11270
  this.processPool.releaseExecutionSlot(slot);
@@ -11132,47 +11286,6 @@ var init_runtime_worker = __esm({
11132
11286
  this.executionTasks.set(claim.attemptId, task);
11133
11287
  return reclaimableClaimWindow;
11134
11288
  }
11135
- async runDiscoveryLoop() {
11136
- const retryBackoff = this.createNetworkRetryBackoff();
11137
- while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
11138
- try {
11139
- const response = await this.relay.claimCodexRuntimeDiscovery({
11140
- connectorInstanceId: this.connectorInstanceId,
11141
- protocolVersion: localCodexRuntimeProtocolVersion,
11142
- waitSeconds: discoveryWaitSeconds
11143
- }, this.lifetimeAbort.signal);
11144
- if (response.request === void 0) {
11145
- retryBackoff.reset();
11146
- continue;
11147
- }
11148
- await this.completeDiscovery(response.request);
11149
- retryBackoff.reset();
11150
- } catch (error) {
11151
- if (this.lifetimeAbort.signal.aborted || this.relay.isRevoked()) {
11152
- return;
11153
- }
11154
- await this.logger.error(`Local Codex discovery loop failed for connection ${this.connection.connectionId}`, error);
11155
- await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11156
- }
11157
- }
11158
- }
11159
- async completeDiscovery(request2) {
11160
- let result;
11161
- try {
11162
- result = await this.executeDiscovery(request2);
11163
- } catch (error) {
11164
- await this.logger.error(`Local Codex ${request2.kind} discovery failed for connection ${this.connection.connectionId}`, error);
11165
- result = {
11166
- errorCode: request2.kind === LocalCodexDiscoveryKindWire.ModelList ? "model_discovery_failed" : "directory_unavailable",
11167
- requestId: request2.requestId,
11168
- status: LocalCodexDiscoveryStatusWire.Failed
11169
- };
11170
- }
11171
- const completion = await this.relay.completeCodexRuntimeDiscovery(request2.requestId, this.connectorInstanceId, result, this.lifetimeAbort.signal);
11172
- if (!completion.accepted) {
11173
- await this.logger.info(`Local Codex discovery request ${request2.requestId} expired before completion`);
11174
- }
11175
- }
11176
11289
  async executeDiscovery(request2) {
11177
11290
  if (request2.kind === LocalCodexDiscoveryKindWire.ModelList) {
11178
11291
  return {
@@ -11189,33 +11302,7 @@ var init_runtime_worker = __esm({
11189
11302
  status: LocalCodexDiscoveryStatusWire.Succeeded
11190
11303
  };
11191
11304
  }
11192
- if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileList || request2.kind === LocalCodexDiscoveryKindWire.LocalFileSearch || request2.kind === LocalCodexDiscoveryKindWire.LocalFileRead || request2.kind === LocalCodexDiscoveryKindWire.LocalFileValidate) {
11193
- const source = await LocalFileSource.create(this.connection.rootPath, request2.workingDirectory ?? ".");
11194
- if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileList) {
11195
- const result = await source.list(request2.relativeDirectory ?? ".", request2.cursor, request2.limit);
11196
- return { ...result, requestId: request2.requestId, status: LocalCodexDiscoveryStatusWire.Succeeded };
11197
- }
11198
- if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileSearch) {
11199
- const result = await source.search(request2.query ?? "", request2.cursor, request2.limit);
11200
- return { ...result, requestId: request2.requestId, status: LocalCodexDiscoveryStatusWire.Succeeded };
11201
- }
11202
- if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileValidate) {
11203
- return {
11204
- entries: [await source.validate(request2.filePath ?? "")],
11205
- requestId: request2.requestId,
11206
- status: LocalCodexDiscoveryStatusWire.Succeeded
11207
- };
11208
- }
11209
- const content3 = await source.read(request2.filePath ?? "");
11210
- return {
11211
- content: content3.content,
11212
- encoding: content3.encoding,
11213
- entries: [{ kind: "file", name: content3.name, path: content3.path, size: content3.size }],
11214
- requestId: request2.requestId,
11215
- status: LocalCodexDiscoveryStatusWire.Succeeded
11216
- };
11217
- }
11218
- throw new Error("Unsupported Local Codex discovery kind");
11305
+ return await executeLocalFileDiscovery(this.connection.rootPath, request2);
11219
11306
  }
11220
11307
  async discoverModels() {
11221
11308
  const client = await this.processPool.ensureStarted();
@@ -11506,7 +11593,7 @@ var init_runtime_worker = __esm({
11506
11593
  if (scanSucceeded) {
11507
11594
  retryBackoff.reset();
11508
11595
  }
11509
- await waitForAbort(this.lifetimeAbort.signal, scanSucceeded ? recoveryScanIntervalMilliseconds : retryBackoff.nextDelayMilliseconds());
11596
+ await waitForAbort2(this.lifetimeAbort.signal, scanSucceeded ? recoveryScanIntervalMilliseconds : retryBackoff.nextDelayMilliseconds());
11510
11597
  }
11511
11598
  }
11512
11599
  async scanPersistedAttempts() {
@@ -11598,7 +11685,7 @@ var init_runtime_worker = __esm({
11598
11685
  await this.loseLease(active, "Local Codex execution lease expired");
11599
11686
  return;
11600
11687
  }
11601
- await waitForAbort(active.finished.signal, Math.min(nextRenewalDelayMilliseconds, remaining));
11688
+ await waitForAbort2(active.finished.signal, Math.min(nextRenewalDelayMilliseconds, remaining));
11602
11689
  if (active.finished.signal.aborted) {
11603
11690
  return;
11604
11691
  }
@@ -11655,6 +11742,9 @@ var init_runtime_worker = __esm({
11655
11742
  }
11656
11743
  }
11657
11744
  async loseLease(active, message) {
11745
+ if (active.terminalValue !== void 0) {
11746
+ return;
11747
+ }
11658
11748
  if (active.leaseLossCleanupTask !== void 0) {
11659
11749
  await active.leaseLossCleanupTask;
11660
11750
  return;
@@ -11683,7 +11773,7 @@ var init_runtime_worker = __esm({
11683
11773
  return;
11684
11774
  }
11685
11775
  await this.logger.error(`Failed to poll Local Codex controls for ${active.claim.attemptId}`, error);
11686
- await waitForAbort(active.finished.signal, retryBackoff.nextDelayMilliseconds());
11776
+ await waitForAbort2(active.finished.signal, retryBackoff.nextDelayMilliseconds());
11687
11777
  }
11688
11778
  }
11689
11779
  }
@@ -11743,7 +11833,7 @@ var init_runtime_worker = __esm({
11743
11833
  return LocalCodexControlOutcomeWire.Rejected;
11744
11834
  }
11745
11835
  }
11746
- await waitForAbort(active.finished.signal, 25);
11836
+ await waitForAbort2(active.finished.signal, 25);
11747
11837
  }
11748
11838
  return LocalCodexControlOutcomeWire.Stale;
11749
11839
  }
@@ -11817,7 +11907,7 @@ var init_runtime_worker = __esm({
11817
11907
  active.eventUploadScheduled = true;
11818
11908
  const next = active.eventUploadQueue.catch(() => void 0).then(async () => {
11819
11909
  try {
11820
- await waitForAbort(active.finished.signal, eventUploadCoalesceMilliseconds);
11910
+ await waitForAbort2(active.finished.signal, eventUploadCoalesceMilliseconds);
11821
11911
  await active.spoolQueue;
11822
11912
  while (active.durable.pendingEvents().length > 0) {
11823
11913
  await this.flushEvents(active);
@@ -11847,7 +11937,7 @@ var init_runtime_worker = __esm({
11847
11937
  if (active.finished.signal.aborted || this.lifetimeAbort.signal.aborted) {
11848
11938
  throw error;
11849
11939
  }
11850
- await waitForAbort(active.finished.signal, retryBackoff.nextDelayMilliseconds());
11940
+ await waitForAbort2(active.finished.signal, retryBackoff.nextDelayMilliseconds());
11851
11941
  }
11852
11942
  }
11853
11943
  }
@@ -11866,14 +11956,14 @@ var init_runtime_worker = __esm({
11866
11956
  throw error;
11867
11957
  }
11868
11958
  await this.logger.error(`Failed to update Local Codex state for ${active.claim.attemptId}`, error);
11869
- await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11959
+ await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11870
11960
  }
11871
11961
  }
11872
11962
  throw new Error("Local Codex Runtime stopped before state ACK");
11873
11963
  }
11874
11964
  createNetworkRetryBackoff() {
11875
11965
  return new RetryBackoff({
11876
- maximumMilliseconds: maximumNetworkRetryMilliseconds,
11966
+ maximumMilliseconds: maximumNetworkRetryMilliseconds2,
11877
11967
  minimumMilliseconds: this.networkRetryMilliseconds,
11878
11968
  random: this.random
11879
11969
  });
@@ -12050,7 +12140,7 @@ ${titleInput}`,
12050
12140
  }
12051
12141
  await Promise.race([
12052
12142
  generation.completion,
12053
- waitForAbort(active.finished.signal, threadTitleGenerationTimeoutMilliseconds),
12143
+ waitForAbort2(active.finished.signal, threadTitleGenerationTimeoutMilliseconds),
12054
12144
  active.fatal.then(() => void 0)
12055
12145
  ]);
12056
12146
  if (initialThreadName.completed) {
@@ -12106,7 +12196,7 @@ ${titleInput}`,
12106
12196
  await this.logger.error(`Failed to name Local Codex thread ${threadId}`, error);
12107
12197
  return;
12108
12198
  }
12109
- await waitForAbort(signal, retryMilliseconds);
12199
+ await waitForAbort2(signal, retryMilliseconds);
12110
12200
  retryMilliseconds = Math.min(retryMilliseconds * 2, maximumThreadNameRetryMilliseconds);
12111
12201
  continue;
12112
12202
  }
@@ -12551,7 +12641,7 @@ function delay3(milliseconds) {
12551
12641
  setTimeout(resolvePromise, milliseconds);
12552
12642
  });
12553
12643
  }
12554
- var import_node_os8, import_node_crypto8, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, commandOutputBatchMaxBytes, commandOutputFlushIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds2, defaultLocalCodexThreadCacheCapacity, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumEventUploadRetryMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, EventUploadOutcome, MachineConnectorDaemon;
12644
+ var import_node_os8, import_node_crypto8, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, commandOutputBatchMaxBytes, commandOutputFlushIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds3, defaultLocalCodexThreadCacheCapacity, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumEventUploadRetryMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, EventUploadOutcome, MachineConnectorDaemon;
12555
12645
  var init_daemon = __esm({
12556
12646
  "../machine-connector/dist/runtime/daemon.js"() {
12557
12647
  "use strict";
@@ -12578,6 +12668,8 @@ var init_daemon = __esm({
12578
12668
  init_store();
12579
12669
  init_version();
12580
12670
  init_runtime_worker();
12671
+ init_contracts2();
12672
+ init_discovery_worker();
12581
12673
  init_process_pool();
12582
12674
  claimTimeoutSeconds = 30;
12583
12675
  controlTimeoutSeconds = 30;
@@ -12586,7 +12678,7 @@ var init_daemon = __esm({
12586
12678
  commandOutputFlushIntervalMilliseconds = 250;
12587
12679
  agentOutputLimitBytes = 2e6;
12588
12680
  defaultLeaseSeconds = 90;
12589
- defaultNetworkRetryMilliseconds2 = 2e3;
12681
+ defaultNetworkRetryMilliseconds3 = 2e3;
12590
12682
  defaultLocalCodexThreadCacheCapacity = 64;
12591
12683
  defaultLeaseSafetyMarginMilliseconds = 1e4;
12592
12684
  defaultTerminalForegroundBudgetMilliseconds = 5e3;
@@ -12609,6 +12701,7 @@ var init_daemon = __esm({
12609
12701
  logger;
12610
12702
  relayClients = /* @__PURE__ */ new Map();
12611
12703
  localCodexWorkers = /* @__PURE__ */ new Map();
12704
+ localFileDiscoveryWorkers = /* @__PURE__ */ new Map();
12612
12705
  localCodexProcessPools = /* @__PURE__ */ new Map();
12613
12706
  startedAt = (/* @__PURE__ */ new Date()).toISOString();
12614
12707
  connections = [];
@@ -12641,7 +12734,7 @@ var init_daemon = __esm({
12641
12734
  this.shellEnvironmentManager = options.shellEnvironmentManager ?? new ShellEnvironmentManager();
12642
12735
  this.leaseSafetyMarginMilliseconds = options.leaseSafetyMarginMilliseconds ?? defaultLeaseSafetyMarginMilliseconds;
12643
12736
  this.leaseSeconds = options.leaseSeconds ?? defaultLeaseSeconds;
12644
- this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds2;
12737
+ this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds3;
12645
12738
  this.localCodexThreadCacheCapacity = options.localCodexThreadCacheCapacity ?? defaultLocalCodexThreadCacheCapacity;
12646
12739
  this.random = options.random ?? Math.random;
12647
12740
  this.terminalForegroundBudgetMilliseconds = options.terminalForegroundBudgetMilliseconds ?? defaultTerminalForegroundBudgetMilliseconds;
@@ -12718,6 +12811,9 @@ var init_daemon = __esm({
12718
12811
  await Promise.all([...this.localCodexWorkers.entries()].map(async ([connectionId, worker]) => {
12719
12812
  await this.stopRuntimeComponent(`Failed to stop Local Codex worker ${connectionId}`, async () => await worker.stop());
12720
12813
  }));
12814
+ await Promise.all([...this.localFileDiscoveryWorkers.entries()].map(async ([connectionId, worker]) => {
12815
+ await this.stopRuntimeComponent(`Failed to stop Local file discovery worker ${connectionId}`, async () => await worker.stop());
12816
+ }));
12721
12817
  await Promise.all([...this.localCodexProcessPools.values()].map(async (pool) => {
12722
12818
  await this.stopRuntimeComponent(`Failed to stop Local Codex App Server pool ${pool.poolKey}`, async () => await pool.stop());
12723
12819
  }));
@@ -12783,10 +12879,34 @@ var init_daemon = __esm({
12783
12879
  }
12784
12880
  await Promise.all([
12785
12881
  this.runHeartbeatLoop(connection, relay),
12882
+ this.runLocalFileDiscovery(connection, relay),
12786
12883
  this.runClaimLoop(connection, relay),
12787
12884
  this.runControlLoop(connection, relay)
12788
12885
  ]);
12789
12886
  }
12887
+ async runLocalFileDiscovery(connection, relay) {
12888
+ const worker = new LocalCodexDiscoveryWorker({
12889
+ connectionId: connection.connectionId,
12890
+ connectorInstanceId: this.connectorInstanceId,
12891
+ execute: async (request2) => await executeLocalFileDiscovery(connection.rootPath, request2),
12892
+ failureErrorCode: () => "directory_unavailable",
12893
+ logger: this.logger,
12894
+ networkRetryMilliseconds: this.networkRetryMilliseconds,
12895
+ random: this.random,
12896
+ relay
12897
+ });
12898
+ this.localFileDiscoveryWorkers.set(connection.connectionId, worker);
12899
+ if (this.stopping) {
12900
+ await worker.stop();
12901
+ }
12902
+ try {
12903
+ await worker.run();
12904
+ } finally {
12905
+ if (this.localFileDiscoveryWorkers.get(connection.connectionId) === worker) {
12906
+ this.localFileDiscoveryWorkers.delete(connection.connectionId);
12907
+ }
12908
+ }
12909
+ }
12790
12910
  async runLocalCodexRuntime(connection, relay) {
12791
12911
  const worker = new LocalCodexRuntimeConnectionWorker(connection, relay, this.store, this.localCodexProcessPool(connection.machineId), this.shellEnvironmentManager.snapshot(), this.connectorInstanceId, this.logger, {
12792
12912
  networkRetryMilliseconds: this.networkRetryMilliseconds,
@@ -12845,11 +12965,13 @@ var init_daemon = __esm({
12845
12965
  await activeJob.cancellation.request(ExecutionCancellationReason.LeaseLost);
12846
12966
  }));
12847
12967
  this.localCodexWorkers.get(connection.connectionId)?.revoke();
12968
+ this.localFileDiscoveryWorkers.get(connection.connectionId)?.revoke();
12848
12969
  }
12849
12970
  async runHeartbeatLoop(connection, relay) {
12850
12971
  while (!this.stopping && !relay.isRevoked()) {
12851
12972
  try {
12852
12973
  await relay.heartbeat({
12974
+ capabilities: [localFilesCapability],
12853
12975
  connectorInstanceId: this.connectorInstanceId,
12854
12976
  connectorVersion,
12855
12977
  protocolVersion: machineProtocolVersion
@@ -16383,7 +16505,7 @@ function getApiKeyOrUndefined() {
16383
16505
 
16384
16506
  // src/utils/http.ts
16385
16507
  function getUserAgent() {
16386
- return `moxt-cli/${"0.11.0-beta.6"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
16508
+ return `moxt-cli/${"0.11.0-beta.8"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
16387
16509
  }
16388
16510
  async function sendRequest(method, path4, init) {
16389
16511
  return await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -30969,7 +31091,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
30969
31091
  var MAX_BATCH_SIZE = 100;
30970
31092
  function commonLabels() {
30971
31093
  return {
30972
- cli_version: "0.11.0-beta.6",
31094
+ cli_version: "0.11.0-beta.8",
30973
31095
  node_version: process.versions.node,
30974
31096
  os: (0, import_node_os11.platform)(),
30975
31097
  arch: (0, import_node_os11.arch)(),
@@ -31015,7 +31137,7 @@ async function flush() {
31015
31137
  }
31016
31138
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
31017
31139
  const payload = {
31018
- release_id: "0.11.0-beta.6",
31140
+ release_id: "0.11.0-beta.8",
31019
31141
  client_type: "cli",
31020
31142
  metric_data_list: batch.map((m) => ({
31021
31143
  profile: "cli",
@@ -31398,9 +31520,9 @@ function commandPath3(command) {
31398
31520
  }
31399
31521
 
31400
31522
  // src/index.ts
31401
- var program2 = createProgram("0.11.0-beta.6");
31402
- installDaemonReconcileHook(program2, "0.11.0-beta.6");
31403
- installUpdateHook(program2, "0.11.0-beta.6");
31523
+ var program2 = createProgram("0.11.0-beta.8");
31524
+ installDaemonReconcileHook(program2, "0.11.0-beta.8");
31525
+ installUpdateHook(program2, "0.11.0-beta.8");
31404
31526
  instrumentProgram(program2);
31405
31527
  installExitHandler();
31406
31528
  program2.parseAsync(process.argv).then(async () => {