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

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;
@@ -9395,6 +9395,7 @@ var init_local_file_source = __esm({
9395
9395
  import_promises12 = require("fs/promises");
9396
9396
  import_node_path9 = require("path");
9397
9397
  import_ignore = __toESM(require_ignore(), 1);
9398
+ init_image_viewer();
9398
9399
  maximumReadBytes = 5 * 1024 * 1024;
9399
9400
  defaultPageSize = 100;
9400
9401
  maximumPageSize = 200;
@@ -9491,16 +9492,25 @@ var init_local_file_source = __esm({
9491
9492
  size: stat6.size
9492
9493
  };
9493
9494
  }
9494
- async validate(path4) {
9495
- const file = await this.resolveFile(path4);
9496
- const stat6 = await (0, import_promises12.lstat)(file);
9495
+ async validate(path4, kind = "file") {
9496
+ const target = kind === "directory" ? await this.resolveDirectory(path4) : await this.resolveFile(path4);
9497
+ const stat6 = await (0, import_promises12.lstat)(target);
9497
9498
  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
9499
+ kind,
9500
+ name: (0, import_node_path9.basename)(target),
9501
+ path: portable((0, import_node_path9.relative)(this.workingDirectory, target)),
9502
+ ...kind === "file" ? { size: stat6.size } : {}
9502
9503
  };
9503
9504
  }
9505
+ async validateImage(path4) {
9506
+ const entry = await this.validate(path4, "file");
9507
+ if (entry.size === void 0 || entry.size > maximumReadBytes) {
9508
+ throw new Error(`Local image exceeds the ${maximumReadBytes}-byte limit`);
9509
+ }
9510
+ const target = await this.resolveFile(path4);
9511
+ detectSupportedImageType(await (0, import_promises12.readFile)(target));
9512
+ return entry;
9513
+ }
9504
9514
  async resolveDirectory(path4) {
9505
9515
  const absolute = resolveWithin(this.workingDirectory, path4);
9506
9516
  const directStat = await (0, import_promises12.lstat)(absolute);
@@ -9577,6 +9587,147 @@ var init_local_file_source = __esm({
9577
9587
  }
9578
9588
  });
9579
9589
 
9590
+ // ../machine-connector/dist/runtime/local-codex-runtime/discovery-worker.js
9591
+ async function executeLocalFileDiscovery(pairedRoot, request2) {
9592
+ if (request2.kind !== LocalCodexDiscoveryKindWire.LocalFileList && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileSearch && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileRead && request2.kind !== LocalCodexDiscoveryKindWire.LocalFileValidate) {
9593
+ throw new Error(`Unsupported Local file discovery kind ${request2.kind}`);
9594
+ }
9595
+ const source = await LocalFileSource.create(pairedRoot, request2.workingDirectory ?? ".");
9596
+ if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileList) {
9597
+ const page2 = await source.list(request2.relativeDirectory ?? ".", request2.cursor, request2.limit);
9598
+ return {
9599
+ ...page2,
9600
+ requestId: request2.requestId,
9601
+ status: LocalCodexDiscoveryStatusWire.Succeeded
9602
+ };
9603
+ }
9604
+ if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileSearch) {
9605
+ const page2 = await source.search(request2.query ?? "", request2.cursor, request2.limit);
9606
+ return {
9607
+ ...page2,
9608
+ requestId: request2.requestId,
9609
+ status: LocalCodexDiscoveryStatusWire.Succeeded
9610
+ };
9611
+ }
9612
+ if (request2.kind === LocalCodexDiscoveryKindWire.LocalFileValidate) {
9613
+ return {
9614
+ entries: [
9615
+ await source.validate(request2.filePath ?? "", request2.fileKind ?? "file")
9616
+ ],
9617
+ requestId: request2.requestId,
9618
+ status: LocalCodexDiscoveryStatusWire.Succeeded
9619
+ };
9620
+ }
9621
+ const content3 = await source.read(request2.filePath ?? "");
9622
+ return {
9623
+ content: content3.content,
9624
+ encoding: content3.encoding,
9625
+ entries: [
9626
+ {
9627
+ kind: "file",
9628
+ name: content3.name,
9629
+ path: content3.path,
9630
+ size: content3.size
9631
+ }
9632
+ ],
9633
+ requestId: request2.requestId,
9634
+ status: LocalCodexDiscoveryStatusWire.Succeeded
9635
+ };
9636
+ }
9637
+ async function waitForAbort(signal, milliseconds) {
9638
+ if (signal.aborted) {
9639
+ return;
9640
+ }
9641
+ await new Promise((resolvePromise) => {
9642
+ const complete = () => {
9643
+ clearTimeout(timeout);
9644
+ signal.removeEventListener("abort", complete);
9645
+ resolvePromise();
9646
+ };
9647
+ const timeout = setTimeout(complete, milliseconds);
9648
+ timeout.unref();
9649
+ signal.addEventListener("abort", complete, { once: true });
9650
+ });
9651
+ }
9652
+ var discoveryWaitSeconds, defaultNetworkRetryMilliseconds, maximumNetworkRetryMilliseconds, LocalCodexDiscoveryWorker;
9653
+ var init_discovery_worker = __esm({
9654
+ "../machine-connector/dist/runtime/local-codex-runtime/discovery-worker.js"() {
9655
+ "use strict";
9656
+ init_cjs_shims();
9657
+ init_retry_backoff();
9658
+ init_contracts2();
9659
+ init_local_file_source();
9660
+ discoveryWaitSeconds = 25;
9661
+ defaultNetworkRetryMilliseconds = 2e3;
9662
+ maximumNetworkRetryMilliseconds = 6e4;
9663
+ LocalCodexDiscoveryWorker = class {
9664
+ params;
9665
+ lifetimeAbort = new AbortController();
9666
+ running;
9667
+ constructor(params) {
9668
+ this.params = params;
9669
+ }
9670
+ async run() {
9671
+ if (this.running !== void 0) {
9672
+ return await this.running;
9673
+ }
9674
+ this.running = this.runLoop();
9675
+ return await this.running;
9676
+ }
9677
+ async stop() {
9678
+ this.revoke();
9679
+ await this.running;
9680
+ }
9681
+ revoke() {
9682
+ this.lifetimeAbort.abort();
9683
+ }
9684
+ async runLoop() {
9685
+ const retryBackoff = new RetryBackoff({
9686
+ maximumMilliseconds: maximumNetworkRetryMilliseconds,
9687
+ minimumMilliseconds: this.params.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds,
9688
+ random: this.params.random
9689
+ });
9690
+ while (!this.lifetimeAbort.signal.aborted && !this.params.relay.isRevoked()) {
9691
+ try {
9692
+ const response = await this.params.relay.claimCodexRuntimeDiscovery({
9693
+ connectorInstanceId: this.params.connectorInstanceId,
9694
+ protocolVersion: localCodexRuntimeProtocolVersion,
9695
+ waitSeconds: discoveryWaitSeconds
9696
+ }, this.lifetimeAbort.signal);
9697
+ if (response.request !== void 0) {
9698
+ await this.complete(response.request);
9699
+ }
9700
+ retryBackoff.reset();
9701
+ } catch (error) {
9702
+ if (this.lifetimeAbort.signal.aborted || this.params.relay.isRevoked()) {
9703
+ return;
9704
+ }
9705
+ await this.params.logger.error(`Local Codex discovery loop failed for connection ${this.params.connectionId}`, error);
9706
+ await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
9707
+ }
9708
+ }
9709
+ }
9710
+ async complete(request2) {
9711
+ let result;
9712
+ try {
9713
+ result = await this.params.execute(request2);
9714
+ } catch (error) {
9715
+ await this.params.logger.error(`Local Codex ${request2.kind} discovery failed for connection ${this.params.connectionId}`, error);
9716
+ result = {
9717
+ errorCode: this.params.failureErrorCode(request2),
9718
+ requestId: request2.requestId,
9719
+ status: LocalCodexDiscoveryStatusWire.Failed
9720
+ };
9721
+ }
9722
+ const completion = await this.params.relay.completeCodexRuntimeDiscovery(request2.requestId, this.params.connectorInstanceId, result, this.lifetimeAbort.signal);
9723
+ if (!completion.accepted) {
9724
+ await this.params.logger.info(`Local Codex discovery request ${request2.requestId} expired before completion`);
9725
+ }
9726
+ }
9727
+ };
9728
+ }
9729
+ });
9730
+
9580
9731
  // ../machine-connector/dist/runtime/local-codex-runtime/durable-attempt.js
9581
9732
  function assertCompatibleClaim(persisted, connectionId, claim, allowRestartFenceRotation) {
9582
9733
  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) {
@@ -10354,31 +10505,48 @@ async function toCodexInput(items, pairedRoot, relativeWorkingDirectory) {
10354
10505
  };
10355
10506
  }
10356
10507
  if (item.itemType === "image") {
10508
+ const url = optionalString3(payload.url).value;
10509
+ if (url === void 0 || !isSecureImageUrl(url)) {
10510
+ throw new Error("Remote image input requires a valid HTTPS URL");
10511
+ }
10357
10512
  return {
10358
10513
  type: "image",
10359
- url: optionalString3(payload.url).value ?? ""
10514
+ url
10360
10515
  };
10361
10516
  }
10362
10517
  if (item.itemType === "local_image") {
10518
+ const path4 = optionalString3(payload.path).value;
10519
+ if (path4 === void 0)
10520
+ throw new Error("Local image input has no path");
10521
+ await source.validateImage(path4);
10363
10522
  return {
10364
10523
  type: "localImage",
10365
- path: optionalString3(payload.path).value ?? ""
10524
+ path: path4
10366
10525
  };
10367
10526
  }
10368
10527
  if (item.itemType === "local_file") {
10369
10528
  const path4 = optionalString3(payload.path).value;
10370
10529
  if (path4 === void 0)
10371
10530
  throw new Error("Local file input has no path");
10372
- await source.validate(path4);
10531
+ const kind = payload.kind === "directory" ? "directory" : "file";
10532
+ await source.validate(path4, kind);
10373
10533
  return {
10374
10534
  type: "text",
10375
- text: `@${path4}`,
10535
+ text: `@${path4}${kind === "directory" && !path4.endsWith("/") ? "/" : ""}`,
10376
10536
  text_elements: []
10377
10537
  };
10378
10538
  }
10379
10539
  throw new Error(`Unsupported Local Codex input ${item.itemType}`);
10380
10540
  }));
10381
10541
  }
10542
+ function isSecureImageUrl(value) {
10543
+ try {
10544
+ const url = new URL(value);
10545
+ return url.protocol === "https:" && url.username === "" && url.password === "" && url.hostname !== "";
10546
+ } catch {
10547
+ return false;
10548
+ }
10549
+ }
10382
10550
  function localCodexInputItems(value) {
10383
10551
  if (!Array.isArray(value)) {
10384
10552
  return [];
@@ -10561,7 +10729,7 @@ async function probeExecutable(executable, environment) {
10561
10729
  };
10562
10730
  }
10563
10731
  }
10564
- async function waitForAbort(signal, milliseconds) {
10732
+ async function waitForAbort2(signal, milliseconds) {
10565
10733
  if (signal.aborted) {
10566
10734
  return;
10567
10735
  }
@@ -10612,7 +10780,7 @@ function parseLeaseDeadline(value) {
10612
10780
  function routineLeaseRenewalDelayMilliseconds(remainingLeaseMilliseconds) {
10613
10781
  return Math.min(leaseRenewIntervalMilliseconds, Math.max(1, Math.floor(remainingLeaseMilliseconds / leaseRenewalIntervalsBeforeDeadline)));
10614
10782
  }
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;
10783
+ 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
10784
  var init_runtime_worker = __esm({
10617
10785
  "../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
10618
10786
  "use strict";
@@ -10627,12 +10795,12 @@ var init_runtime_worker = __esm({
10627
10795
  init_app_server_client();
10628
10796
  init_contracts2();
10629
10797
  init_local_file_source();
10798
+ init_discovery_worker();
10630
10799
  init_durable_attempt();
10631
10800
  init_event_normalizer();
10632
10801
  heartbeatIntervalMilliseconds = 2e4;
10633
10802
  claimRetryMilliseconds = 250;
10634
10803
  claimWaitSeconds = 25;
10635
- discoveryWaitSeconds = 25;
10636
10804
  maximumDiscoveryDirectories = 1e3;
10637
10805
  maximumDiscoveryModels = 100;
10638
10806
  maximumModelListPages = 10;
@@ -10641,8 +10809,8 @@ var init_runtime_worker = __esm({
10641
10809
  preferredEventUploadRequestBytes = 96e3;
10642
10810
  leaseRenewIntervalMilliseconds = 1e4;
10643
10811
  leaseRenewalIntervalsBeforeDeadline = 3;
10644
- defaultNetworkRetryMilliseconds = 1e3;
10645
- maximumNetworkRetryMilliseconds = 6e4;
10812
+ defaultNetworkRetryMilliseconds2 = 1e3;
10813
+ maximumNetworkRetryMilliseconds2 = 6e4;
10646
10814
  interactionTimeoutMilliseconds = 10 * 60 * 1e3;
10647
10815
  executableProbeTimeoutMilliseconds = 5e3;
10648
10816
  recoveryScanIntervalMilliseconds = 1e3;
@@ -10708,6 +10876,7 @@ var init_runtime_worker = __esm({
10708
10876
  configured = false;
10709
10877
  enabled = false;
10710
10878
  executionTasks = /* @__PURE__ */ new Map();
10879
+ discoveryWorker;
10711
10880
  lastCapabilityStartError;
10712
10881
  lifetimeAbort = new AbortController();
10713
10882
  networkRetryMilliseconds;
@@ -10723,8 +10892,18 @@ var init_runtime_worker = __esm({
10723
10892
  this.environment = environment;
10724
10893
  this.connectorInstanceId = connectorInstanceId;
10725
10894
  this.logger = logger;
10726
- this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds;
10895
+ this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds2;
10727
10896
  this.random = options.random ?? Math.random;
10897
+ this.discoveryWorker = new LocalCodexDiscoveryWorker({
10898
+ connectionId: connection.connectionId,
10899
+ connectorInstanceId,
10900
+ execute: async (request2) => await this.executeDiscovery(request2),
10901
+ failureErrorCode: (request2) => request2.kind === LocalCodexDiscoveryKindWire.ModelList ? "model_discovery_failed" : "directory_unavailable",
10902
+ logger,
10903
+ networkRetryMilliseconds: this.networkRetryMilliseconds,
10904
+ random: this.random,
10905
+ relay
10906
+ });
10728
10907
  this.processPool.register(connection.connectionId, this);
10729
10908
  }
10730
10909
  async run() {
@@ -10740,6 +10919,7 @@ var init_runtime_worker = __esm({
10740
10919
  }
10741
10920
  revoke() {
10742
10921
  this.lifetimeAbort.abort();
10922
+ this.discoveryWorker.revoke();
10743
10923
  for (const active of this.activeAttempts.values()) {
10744
10924
  active.finished.abort();
10745
10925
  }
@@ -11037,7 +11217,7 @@ var init_runtime_worker = __esm({
11037
11217
  try {
11038
11218
  await Promise.all([
11039
11219
  this.runHeartbeatLoop(),
11040
- this.runDiscoveryLoop(),
11220
+ this.discoveryWorker.run(),
11041
11221
  this.runAttemptLoops()
11042
11222
  ]);
11043
11223
  } finally {
@@ -11055,7 +11235,7 @@ var init_runtime_worker = __esm({
11055
11235
  async runHeartbeatLoop() {
11056
11236
  while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
11057
11237
  if ([...this.activeAttempts.values()].some((active) => active.interruptedCleanupStarted)) {
11058
- await waitForAbort(this.lifetimeAbort.signal, claimRetryMilliseconds);
11238
+ await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
11059
11239
  continue;
11060
11240
  }
11061
11241
  try {
@@ -11068,19 +11248,19 @@ var init_runtime_worker = __esm({
11068
11248
  }
11069
11249
  await this.logger.error(`Local Codex Runtime heartbeat failed for connection ${this.connection.connectionId}`, error);
11070
11250
  }
11071
- await waitForAbort(this.lifetimeAbort.signal, heartbeatIntervalMilliseconds);
11251
+ await waitForAbort2(this.lifetimeAbort.signal, heartbeatIntervalMilliseconds);
11072
11252
  }
11073
11253
  }
11074
11254
  async runClaimLoop() {
11075
11255
  const retryBackoff = this.createNetworkRetryBackoff();
11076
11256
  while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
11077
11257
  if (!this.configured || !this.enabled || !this.runtimeReady()) {
11078
- await waitForAbort(this.lifetimeAbort.signal, claimRetryMilliseconds);
11258
+ await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
11079
11259
  continue;
11080
11260
  }
11081
11261
  const slot = this.processPool.tryAcquireExecutionSlot(this.connection.connectionId).value;
11082
11262
  if (slot === void 0) {
11083
- await waitForAbort(this.lifetimeAbort.signal, claimRetryMilliseconds);
11263
+ await waitForAbort2(this.lifetimeAbort.signal, claimRetryMilliseconds);
11084
11264
  continue;
11085
11265
  }
11086
11266
  let executionScheduled = false;
@@ -11103,14 +11283,14 @@ var init_runtime_worker = __esm({
11103
11283
  if (reclaimableClaimWindow.isAccepted()) {
11104
11284
  retryBackoff.reset();
11105
11285
  } else {
11106
- await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11286
+ await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11107
11287
  }
11108
11288
  } catch (error) {
11109
11289
  if (this.lifetimeAbort.signal.aborted || this.relay.isRevoked()) {
11110
11290
  return;
11111
11291
  }
11112
11292
  await this.logger.error(`Local Codex Runtime claim loop failed for connection ${this.connection.connectionId}`, error);
11113
- await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11293
+ await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11114
11294
  } finally {
11115
11295
  if (!executionScheduled) {
11116
11296
  this.processPool.releaseExecutionSlot(slot);
@@ -11132,47 +11312,6 @@ var init_runtime_worker = __esm({
11132
11312
  this.executionTasks.set(claim.attemptId, task);
11133
11313
  return reclaimableClaimWindow;
11134
11314
  }
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
11315
  async executeDiscovery(request2) {
11177
11316
  if (request2.kind === LocalCodexDiscoveryKindWire.ModelList) {
11178
11317
  return {
@@ -11189,33 +11328,7 @@ var init_runtime_worker = __esm({
11189
11328
  status: LocalCodexDiscoveryStatusWire.Succeeded
11190
11329
  };
11191
11330
  }
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");
11331
+ return await executeLocalFileDiscovery(this.connection.rootPath, request2);
11219
11332
  }
11220
11333
  async discoverModels() {
11221
11334
  const client = await this.processPool.ensureStarted();
@@ -11506,7 +11619,7 @@ var init_runtime_worker = __esm({
11506
11619
  if (scanSucceeded) {
11507
11620
  retryBackoff.reset();
11508
11621
  }
11509
- await waitForAbort(this.lifetimeAbort.signal, scanSucceeded ? recoveryScanIntervalMilliseconds : retryBackoff.nextDelayMilliseconds());
11622
+ await waitForAbort2(this.lifetimeAbort.signal, scanSucceeded ? recoveryScanIntervalMilliseconds : retryBackoff.nextDelayMilliseconds());
11510
11623
  }
11511
11624
  }
11512
11625
  async scanPersistedAttempts() {
@@ -11598,7 +11711,7 @@ var init_runtime_worker = __esm({
11598
11711
  await this.loseLease(active, "Local Codex execution lease expired");
11599
11712
  return;
11600
11713
  }
11601
- await waitForAbort(active.finished.signal, Math.min(nextRenewalDelayMilliseconds, remaining));
11714
+ await waitForAbort2(active.finished.signal, Math.min(nextRenewalDelayMilliseconds, remaining));
11602
11715
  if (active.finished.signal.aborted) {
11603
11716
  return;
11604
11717
  }
@@ -11655,6 +11768,9 @@ var init_runtime_worker = __esm({
11655
11768
  }
11656
11769
  }
11657
11770
  async loseLease(active, message) {
11771
+ if (active.terminalValue !== void 0) {
11772
+ return;
11773
+ }
11658
11774
  if (active.leaseLossCleanupTask !== void 0) {
11659
11775
  await active.leaseLossCleanupTask;
11660
11776
  return;
@@ -11683,7 +11799,7 @@ var init_runtime_worker = __esm({
11683
11799
  return;
11684
11800
  }
11685
11801
  await this.logger.error(`Failed to poll Local Codex controls for ${active.claim.attemptId}`, error);
11686
- await waitForAbort(active.finished.signal, retryBackoff.nextDelayMilliseconds());
11802
+ await waitForAbort2(active.finished.signal, retryBackoff.nextDelayMilliseconds());
11687
11803
  }
11688
11804
  }
11689
11805
  }
@@ -11743,7 +11859,7 @@ var init_runtime_worker = __esm({
11743
11859
  return LocalCodexControlOutcomeWire.Rejected;
11744
11860
  }
11745
11861
  }
11746
- await waitForAbort(active.finished.signal, 25);
11862
+ await waitForAbort2(active.finished.signal, 25);
11747
11863
  }
11748
11864
  return LocalCodexControlOutcomeWire.Stale;
11749
11865
  }
@@ -11817,7 +11933,7 @@ var init_runtime_worker = __esm({
11817
11933
  active.eventUploadScheduled = true;
11818
11934
  const next = active.eventUploadQueue.catch(() => void 0).then(async () => {
11819
11935
  try {
11820
- await waitForAbort(active.finished.signal, eventUploadCoalesceMilliseconds);
11936
+ await waitForAbort2(active.finished.signal, eventUploadCoalesceMilliseconds);
11821
11937
  await active.spoolQueue;
11822
11938
  while (active.durable.pendingEvents().length > 0) {
11823
11939
  await this.flushEvents(active);
@@ -11847,7 +11963,7 @@ var init_runtime_worker = __esm({
11847
11963
  if (active.finished.signal.aborted || this.lifetimeAbort.signal.aborted) {
11848
11964
  throw error;
11849
11965
  }
11850
- await waitForAbort(active.finished.signal, retryBackoff.nextDelayMilliseconds());
11966
+ await waitForAbort2(active.finished.signal, retryBackoff.nextDelayMilliseconds());
11851
11967
  }
11852
11968
  }
11853
11969
  }
@@ -11866,14 +11982,14 @@ var init_runtime_worker = __esm({
11866
11982
  throw error;
11867
11983
  }
11868
11984
  await this.logger.error(`Failed to update Local Codex state for ${active.claim.attemptId}`, error);
11869
- await waitForAbort(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11985
+ await waitForAbort2(this.lifetimeAbort.signal, retryBackoff.nextDelayMilliseconds());
11870
11986
  }
11871
11987
  }
11872
11988
  throw new Error("Local Codex Runtime stopped before state ACK");
11873
11989
  }
11874
11990
  createNetworkRetryBackoff() {
11875
11991
  return new RetryBackoff({
11876
- maximumMilliseconds: maximumNetworkRetryMilliseconds,
11992
+ maximumMilliseconds: maximumNetworkRetryMilliseconds2,
11877
11993
  minimumMilliseconds: this.networkRetryMilliseconds,
11878
11994
  random: this.random
11879
11995
  });
@@ -12050,7 +12166,7 @@ ${titleInput}`,
12050
12166
  }
12051
12167
  await Promise.race([
12052
12168
  generation.completion,
12053
- waitForAbort(active.finished.signal, threadTitleGenerationTimeoutMilliseconds),
12169
+ waitForAbort2(active.finished.signal, threadTitleGenerationTimeoutMilliseconds),
12054
12170
  active.fatal.then(() => void 0)
12055
12171
  ]);
12056
12172
  if (initialThreadName.completed) {
@@ -12106,7 +12222,7 @@ ${titleInput}`,
12106
12222
  await this.logger.error(`Failed to name Local Codex thread ${threadId}`, error);
12107
12223
  return;
12108
12224
  }
12109
- await waitForAbort(signal, retryMilliseconds);
12225
+ await waitForAbort2(signal, retryMilliseconds);
12110
12226
  retryMilliseconds = Math.min(retryMilliseconds * 2, maximumThreadNameRetryMilliseconds);
12111
12227
  continue;
12112
12228
  }
@@ -12551,7 +12667,7 @@ function delay3(milliseconds) {
12551
12667
  setTimeout(resolvePromise, milliseconds);
12552
12668
  });
12553
12669
  }
12554
- var import_node_os8, import_node_crypto8, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, commandOutputBatchMaxBytes, commandOutputFlushIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds2, defaultLocalCodexThreadCacheCapacity, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumEventUploadRetryMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, EventUploadOutcome, MachineConnectorDaemon;
12670
+ var import_node_os8, import_node_crypto8, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, commandOutputBatchMaxBytes, commandOutputFlushIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds3, defaultLocalCodexThreadCacheCapacity, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumEventUploadRetryMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, EventUploadOutcome, MachineConnectorDaemon;
12555
12671
  var init_daemon = __esm({
12556
12672
  "../machine-connector/dist/runtime/daemon.js"() {
12557
12673
  "use strict";
@@ -12578,6 +12694,8 @@ var init_daemon = __esm({
12578
12694
  init_store();
12579
12695
  init_version();
12580
12696
  init_runtime_worker();
12697
+ init_contracts2();
12698
+ init_discovery_worker();
12581
12699
  init_process_pool();
12582
12700
  claimTimeoutSeconds = 30;
12583
12701
  controlTimeoutSeconds = 30;
@@ -12586,7 +12704,7 @@ var init_daemon = __esm({
12586
12704
  commandOutputFlushIntervalMilliseconds = 250;
12587
12705
  agentOutputLimitBytes = 2e6;
12588
12706
  defaultLeaseSeconds = 90;
12589
- defaultNetworkRetryMilliseconds2 = 2e3;
12707
+ defaultNetworkRetryMilliseconds3 = 2e3;
12590
12708
  defaultLocalCodexThreadCacheCapacity = 64;
12591
12709
  defaultLeaseSafetyMarginMilliseconds = 1e4;
12592
12710
  defaultTerminalForegroundBudgetMilliseconds = 5e3;
@@ -12609,6 +12727,7 @@ var init_daemon = __esm({
12609
12727
  logger;
12610
12728
  relayClients = /* @__PURE__ */ new Map();
12611
12729
  localCodexWorkers = /* @__PURE__ */ new Map();
12730
+ localFileDiscoveryWorkers = /* @__PURE__ */ new Map();
12612
12731
  localCodexProcessPools = /* @__PURE__ */ new Map();
12613
12732
  startedAt = (/* @__PURE__ */ new Date()).toISOString();
12614
12733
  connections = [];
@@ -12641,7 +12760,7 @@ var init_daemon = __esm({
12641
12760
  this.shellEnvironmentManager = options.shellEnvironmentManager ?? new ShellEnvironmentManager();
12642
12761
  this.leaseSafetyMarginMilliseconds = options.leaseSafetyMarginMilliseconds ?? defaultLeaseSafetyMarginMilliseconds;
12643
12762
  this.leaseSeconds = options.leaseSeconds ?? defaultLeaseSeconds;
12644
- this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds2;
12763
+ this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds3;
12645
12764
  this.localCodexThreadCacheCapacity = options.localCodexThreadCacheCapacity ?? defaultLocalCodexThreadCacheCapacity;
12646
12765
  this.random = options.random ?? Math.random;
12647
12766
  this.terminalForegroundBudgetMilliseconds = options.terminalForegroundBudgetMilliseconds ?? defaultTerminalForegroundBudgetMilliseconds;
@@ -12718,6 +12837,9 @@ var init_daemon = __esm({
12718
12837
  await Promise.all([...this.localCodexWorkers.entries()].map(async ([connectionId, worker]) => {
12719
12838
  await this.stopRuntimeComponent(`Failed to stop Local Codex worker ${connectionId}`, async () => await worker.stop());
12720
12839
  }));
12840
+ await Promise.all([...this.localFileDiscoveryWorkers.entries()].map(async ([connectionId, worker]) => {
12841
+ await this.stopRuntimeComponent(`Failed to stop Local file discovery worker ${connectionId}`, async () => await worker.stop());
12842
+ }));
12721
12843
  await Promise.all([...this.localCodexProcessPools.values()].map(async (pool) => {
12722
12844
  await this.stopRuntimeComponent(`Failed to stop Local Codex App Server pool ${pool.poolKey}`, async () => await pool.stop());
12723
12845
  }));
@@ -12783,10 +12905,34 @@ var init_daemon = __esm({
12783
12905
  }
12784
12906
  await Promise.all([
12785
12907
  this.runHeartbeatLoop(connection, relay),
12908
+ this.runLocalFileDiscovery(connection, relay),
12786
12909
  this.runClaimLoop(connection, relay),
12787
12910
  this.runControlLoop(connection, relay)
12788
12911
  ]);
12789
12912
  }
12913
+ async runLocalFileDiscovery(connection, relay) {
12914
+ const worker = new LocalCodexDiscoveryWorker({
12915
+ connectionId: connection.connectionId,
12916
+ connectorInstanceId: this.connectorInstanceId,
12917
+ execute: async (request2) => await executeLocalFileDiscovery(connection.rootPath, request2),
12918
+ failureErrorCode: () => "directory_unavailable",
12919
+ logger: this.logger,
12920
+ networkRetryMilliseconds: this.networkRetryMilliseconds,
12921
+ random: this.random,
12922
+ relay
12923
+ });
12924
+ this.localFileDiscoveryWorkers.set(connection.connectionId, worker);
12925
+ if (this.stopping) {
12926
+ await worker.stop();
12927
+ }
12928
+ try {
12929
+ await worker.run();
12930
+ } finally {
12931
+ if (this.localFileDiscoveryWorkers.get(connection.connectionId) === worker) {
12932
+ this.localFileDiscoveryWorkers.delete(connection.connectionId);
12933
+ }
12934
+ }
12935
+ }
12790
12936
  async runLocalCodexRuntime(connection, relay) {
12791
12937
  const worker = new LocalCodexRuntimeConnectionWorker(connection, relay, this.store, this.localCodexProcessPool(connection.machineId), this.shellEnvironmentManager.snapshot(), this.connectorInstanceId, this.logger, {
12792
12938
  networkRetryMilliseconds: this.networkRetryMilliseconds,
@@ -12845,11 +12991,13 @@ var init_daemon = __esm({
12845
12991
  await activeJob.cancellation.request(ExecutionCancellationReason.LeaseLost);
12846
12992
  }));
12847
12993
  this.localCodexWorkers.get(connection.connectionId)?.revoke();
12994
+ this.localFileDiscoveryWorkers.get(connection.connectionId)?.revoke();
12848
12995
  }
12849
12996
  async runHeartbeatLoop(connection, relay) {
12850
12997
  while (!this.stopping && !relay.isRevoked()) {
12851
12998
  try {
12852
12999
  await relay.heartbeat({
13000
+ capabilities: [localFilesCapability],
12853
13001
  connectorInstanceId: this.connectorInstanceId,
12854
13002
  connectorVersion,
12855
13003
  protocolVersion: machineProtocolVersion
@@ -16383,7 +16531,7 @@ function getApiKeyOrUndefined() {
16383
16531
 
16384
16532
  // src/utils/http.ts
16385
16533
  function getUserAgent() {
16386
- return `moxt-cli/${"0.11.0-beta.6"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
16534
+ return `moxt-cli/${"0.11.0-beta.9"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
16387
16535
  }
16388
16536
  async function sendRequest(method, path4, init) {
16389
16537
  return await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -30969,7 +31117,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
30969
31117
  var MAX_BATCH_SIZE = 100;
30970
31118
  function commonLabels() {
30971
31119
  return {
30972
- cli_version: "0.11.0-beta.6",
31120
+ cli_version: "0.11.0-beta.9",
30973
31121
  node_version: process.versions.node,
30974
31122
  os: (0, import_node_os11.platform)(),
30975
31123
  arch: (0, import_node_os11.arch)(),
@@ -31015,7 +31163,7 @@ async function flush() {
31015
31163
  }
31016
31164
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
31017
31165
  const payload = {
31018
- release_id: "0.11.0-beta.6",
31166
+ release_id: "0.11.0-beta.9",
31019
31167
  client_type: "cli",
31020
31168
  metric_data_list: batch.map((m) => ({
31021
31169
  profile: "cli",
@@ -31398,9 +31546,9 @@ function commandPath3(command) {
31398
31546
  }
31399
31547
 
31400
31548
  // 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");
31549
+ var program2 = createProgram("0.11.0-beta.9");
31550
+ installDaemonReconcileHook(program2, "0.11.0-beta.9");
31551
+ installUpdateHook(program2, "0.11.0-beta.9");
31404
31552
  instrumentProgram(program2);
31405
31553
  installExitHandler();
31406
31554
  program2.parseAsync(process.argv).then(async () => {