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

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
@@ -6686,6 +6686,12 @@ var init_version = __esm({
6686
6686
  });
6687
6687
 
6688
6688
  // ../machine-connector/dist/runtime/relay-client.js
6689
+ function localCodexRuntimeEventsRequestBody(fence, firstSequence, events) {
6690
+ return { ...fence, events, firstSequence };
6691
+ }
6692
+ function localCodexRuntimeEventsRequestBytes(fence, firstSequence, events) {
6693
+ return Buffer.byteLength(JSON.stringify(localCodexRuntimeEventsRequestBody(fence, firstSequence, events)), "utf8");
6694
+ }
6689
6695
  async function postJson(url, body, accessToken, externalSignal) {
6690
6696
  const headers = {
6691
6697
  "Content-Type": "application/json",
@@ -6849,7 +6855,7 @@ var init_relay_client = __esm({
6849
6855
  return await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/lease`, fence, signal);
6850
6856
  }
6851
6857
  async appendCodexRuntimeEvents(attemptId, fence, firstSequence, events) {
6852
- return await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/events`, { ...fence, events, firstSequence });
6858
+ return await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/events`, localCodexRuntimeEventsRequestBody(fence, firstSequence, events));
6853
6859
  }
6854
6860
  async updateCodexRuntimeState(attemptId, fence, state) {
6855
6861
  await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/state`, { ...fence, ...state });
@@ -6947,9 +6953,9 @@ var init_runtime_logger = __esm({
6947
6953
  async info(message, metadata = {}) {
6948
6954
  await this.write("info", message, metadata, this.store.runtimeLogPath());
6949
6955
  }
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());
6956
+ async error(message, error, context = {}) {
6957
+ const errorMetadata = error instanceof Error ? { message: error.message, stack: error.stack } : { error };
6958
+ await this.write("error", message, { ...context, ...errorMetadata }, this.store.runtimeErrorLogPath());
6953
6959
  }
6954
6960
  async write(level, message, metadata, path4) {
6955
6961
  await (0, import_promises10.appendFile)(path4, `${JSON.stringify({
@@ -8108,6 +8114,9 @@ function normalizeItem(item, completed, baseCorrelation, canonicalRoot) {
8108
8114
  if (itemType === "fileChange") {
8109
8115
  return event(completed ? "file_change_completed" : "file_change_started", { changes: item.changes, status: item.status }, correlation, canonicalRoot);
8110
8116
  }
8117
+ if (itemType === "contextCompaction") {
8118
+ return event(completed ? "context_compaction_completed" : "context_compaction_started", {}, correlation, canonicalRoot);
8119
+ }
8111
8120
  if (itemType === "mcpToolCall" || itemType === "dynamicToolCall" || itemType === "collabAgentToolCall" || itemType === "webSearch" || itemType === "imageGeneration" || itemType === "imageView") {
8112
8121
  return event(completed ? "tool_completed" : "tool_started", sanitizeThreadItem(item), correlation, canonicalRoot);
8113
8122
  }
@@ -8278,6 +8287,9 @@ var init_event_normalizer = __esm({
8278
8287
  function isMissingThreadResponse(message, threadId) {
8279
8288
  return message === `thread not found: ${threadId}` || message === `no rollout found for thread id ${threadId}` || message === `no rollout found for conversation id ${threadId}`;
8280
8289
  }
8290
+ function isThreadNameMetadataPendingResponse(message) {
8291
+ return message.startsWith("failed to set thread name:") && message.includes("failed to read session metadata ") && message.includes(": rollout at ") && message.endsWith(" is empty");
8292
+ }
8281
8293
  function createActiveAttempt(claim, durable, workingDirectory) {
8282
8294
  let resolveTerminal = (_value) => void 0;
8283
8295
  const terminal = new Promise((resolve9) => {
@@ -8307,6 +8319,16 @@ function createActiveAttempt(claim, durable, workingDirectory) {
8307
8319
  workingDirectory
8308
8320
  };
8309
8321
  }
8322
+ function createInitialThreadNameState() {
8323
+ let resolveCompletion = () => void 0;
8324
+ const completion = new Promise((resolve9) => {
8325
+ resolveCompletion = resolve9;
8326
+ });
8327
+ return {
8328
+ completion,
8329
+ resolve: resolveCompletion
8330
+ };
8331
+ }
8310
8332
  function fenceFor(claim, connectorInstanceId) {
8311
8333
  return {
8312
8334
  attemptGeneration: claim.attemptGeneration,
@@ -8327,6 +8349,36 @@ function persistedFence(persisted) {
8327
8349
  runToken: persisted.claim.runToken
8328
8350
  };
8329
8351
  }
8352
+ function preferredEventUploadBatch(fence, pendingEvents) {
8353
+ if (pendingEvents.length === 0) {
8354
+ throw new Error("Local Codex event upload requires a pending event");
8355
+ }
8356
+ const firstSequence = pendingEvents[0].sequence;
8357
+ const events = [];
8358
+ let requestBytes = localCodexRuntimeEventsRequestBytes(fence, firstSequence, events);
8359
+ for (const event2 of pendingEvents.slice(0, maximumEventUploadCount)) {
8360
+ const serializedEvent = JSON.stringify(event2);
8361
+ if (serializedEvent === void 0) {
8362
+ throw new Error(`Local Codex event ${event2.sequence} cannot be serialized`);
8363
+ }
8364
+ const candidateBytes = requestBytes + Buffer.byteLength(serializedEvent, "utf8") + (events.length === 0 ? 0 : 1);
8365
+ if (events.length > 0 && candidateBytes > preferredEventUploadRequestBytes) {
8366
+ break;
8367
+ }
8368
+ events.push(event2);
8369
+ requestBytes = candidateBytes;
8370
+ }
8371
+ return { events, requestBytes };
8372
+ }
8373
+ function eventUploadBatch(fence, events) {
8374
+ if (events.length === 0) {
8375
+ throw new Error("Local Codex event upload batch cannot be empty");
8376
+ }
8377
+ return {
8378
+ events,
8379
+ requestBytes: localCodexRuntimeEventsRequestBytes(fence, events[0].sequence, events)
8380
+ };
8381
+ }
8330
8382
  function requireThreadId(response) {
8331
8383
  const id = response.thread?.id;
8332
8384
  if (id === void 0 || id === "") {
@@ -8540,7 +8592,7 @@ function parseLeaseDeadline(value) {
8540
8592
  }
8541
8593
  return parsed;
8542
8594
  }
8543
- var import_node_child_process4, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, eventUploadCoalesceMilliseconds, eventUploadRetryMilliseconds, leaseRenewIntervalMilliseconds, leaseRenewRetryMilliseconds, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryRetryMilliseconds, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, LocalCodexRuntimeConnectionWorker;
8595
+ var import_node_child_process4, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, eventUploadCoalesceMilliseconds, eventUploadRetryMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewRetryMilliseconds, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryRetryMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, LocalCodexRuntimeConnectionWorker;
8544
8596
  var init_runtime_worker = __esm({
8545
8597
  "../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
8546
8598
  "use strict";
@@ -8557,11 +8609,16 @@ var init_runtime_worker = __esm({
8557
8609
  claimWaitSeconds = 25;
8558
8610
  eventUploadCoalesceMilliseconds = 500;
8559
8611
  eventUploadRetryMilliseconds = 1e3;
8612
+ maximumEventUploadCount = 500;
8613
+ preferredEventUploadRequestBytes = 96e3;
8560
8614
  leaseRenewIntervalMilliseconds = 1e4;
8561
8615
  leaseRenewRetryMilliseconds = 1e3;
8562
8616
  interactionTimeoutMilliseconds = 10 * 60 * 1e3;
8563
8617
  executableProbeTimeoutMilliseconds = 5e3;
8564
8618
  recoveryRetryMilliseconds = 1e3;
8619
+ initialThreadNameRetryMilliseconds = 250;
8620
+ maximumThreadNameRetryMilliseconds = 2e3;
8621
+ maximumInitialThreadNameAttempts = 8;
8565
8622
  ThreadUnavailableError = class extends Error {
8566
8623
  constructor(message) {
8567
8624
  super(message);
@@ -8638,9 +8695,13 @@ var init_runtime_worker = __esm({
8638
8695
  if (normalized === void 0) {
8639
8696
  return;
8640
8697
  }
8698
+ const initialThreadName = active.initialThreadName;
8641
8699
  if (normalized.correlation.nativeThreadId !== void 0 && active.nativeThreadId !== void 0 && normalized.correlation.nativeThreadId !== active.nativeThreadId) {
8642
8700
  return;
8643
8701
  }
8702
+ if (normalized.kind === "thread_title_updated" && normalized.payload.title === initialThreadName?.projectedTitle) {
8703
+ return;
8704
+ }
8644
8705
  const notificationTurnId = normalized.correlation.nativeTurnId;
8645
8706
  if (notificationTurnId !== void 0) {
8646
8707
  if (this.processPool.isRetiredTurn(notificationTurnId)) {
@@ -8655,6 +8716,12 @@ var init_runtime_worker = __esm({
8655
8716
  return;
8656
8717
  }
8657
8718
  }
8719
+ if (normalized.terminalStatus !== void 0 && initialThreadName !== void 0) {
8720
+ await initialThreadName.completion;
8721
+ if (active.finished.signal.aborted) {
8722
+ return;
8723
+ }
8724
+ }
8658
8725
  void this.enqueueSpool(active, async () => {
8659
8726
  const persisted = await active.durable.appendEvent(normalized.kind, normalized.payload, normalized.correlation);
8660
8727
  if (normalized.correlation.nativeThreadId !== void 0 && active.nativeThreadId === void 0) {
@@ -8818,6 +8885,9 @@ var init_runtime_worker = __esm({
8818
8885
  active.nativeThreadId = nativeThreadId;
8819
8886
  await durable.markThreadPrepared(nativeThreadId);
8820
8887
  await active.spoolQueue;
8888
+ if (isNewThread) {
8889
+ active.initialThreadName = createInitialThreadNameState();
8890
+ }
8821
8891
  if (isNewThread && !active.durable.snapshot().events.some((event2) => event2.kind === "thread_started")) {
8822
8892
  await active.durable.appendEvent("thread_started", {}, { nativeThreadId });
8823
8893
  }
@@ -8852,7 +8922,11 @@ var init_runtime_worker = __esm({
8852
8922
  });
8853
8923
  await this.interruptActiveTurnIfRequested(active, client);
8854
8924
  if (isNewThread) {
8855
- await this.setInitialThreadName(client, claim, nativeThreadId);
8925
+ try {
8926
+ await this.setInitialThreadName(client, active, nativeThreadId);
8927
+ } finally {
8928
+ active.initialThreadName?.resolve();
8929
+ }
8856
8930
  }
8857
8931
  const terminal = await Promise.race([
8858
8932
  active.terminal,
@@ -8884,6 +8958,7 @@ var init_runtime_worker = __esm({
8884
8958
  await this.failAttempt(active, error);
8885
8959
  }
8886
8960
  } finally {
8961
+ active.initialThreadName?.resolve();
8887
8962
  if (active.acceptedByAppServer && active.nativeTurnId !== void 0) {
8888
8963
  this.processPool.retireTurn(active.nativeTurnId);
8889
8964
  }
@@ -9028,9 +9103,11 @@ var init_runtime_worker = __esm({
9028
9103
  let snapshot = durable.snapshot();
9029
9104
  const fence = persistedFence(snapshot);
9030
9105
  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);
9106
+ await this.uploadNextEventBatch({
9107
+ attemptId: snapshot.claim.attemptId,
9108
+ durable,
9109
+ fence
9110
+ });
9034
9111
  snapshot = durable.snapshot();
9035
9112
  }
9036
9113
  if (snapshot.phase !== LocalCodexAttemptPhase.TerminalPendingUpload || snapshot.finalSequence === void 0 || snapshot.finalStatus === void 0) {
@@ -9204,12 +9281,44 @@ var init_runtime_worker = __esm({
9204
9281
  }
9205
9282
  async flushEvents(active) {
9206
9283
  await active.spoolQueue;
9207
- const events = active.durable.pendingEvents().slice(0, 500);
9208
- if (events.length === 0) {
9284
+ await this.uploadNextEventBatch({
9285
+ attemptId: active.claim.attemptId,
9286
+ durable: active.durable,
9287
+ fence: fenceFor(active.claim, this.connectorInstanceId)
9288
+ });
9289
+ }
9290
+ async uploadNextEventBatch(request2) {
9291
+ const pendingEvents = request2.durable.pendingEvents();
9292
+ if (pendingEvents.length === 0) {
9209
9293
  return;
9210
9294
  }
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);
9295
+ let batch = preferredEventUploadBatch(request2.fence, pendingEvents);
9296
+ while (true) {
9297
+ try {
9298
+ const response = await this.relay.appendCodexRuntimeEvents(request2.attemptId, request2.fence, batch.events[0].sequence, batch.events);
9299
+ await request2.durable.acknowledgeEvents(response.acknowledgedSequence);
9300
+ return;
9301
+ } catch (error) {
9302
+ const firstSequence = batch.events[0].sequence;
9303
+ const metadata = {
9304
+ attemptId: request2.attemptId,
9305
+ eventCount: batch.events.length,
9306
+ firstSequence,
9307
+ requestBytes: batch.requestBytes
9308
+ };
9309
+ if (error instanceof RelayHttpError) {
9310
+ metadata.status = error.status;
9311
+ }
9312
+ if (error instanceof RelayHttpError && error.status === 413 && batch.events.length > 1) {
9313
+ await this.logger.info(`Local Codex event upload exceeded the relay request limit; retrying a smaller batch`, metadata);
9314
+ const eventCount = Math.ceil(batch.events.length / 2);
9315
+ batch = eventUploadBatch(request2.fence, batch.events.slice(0, eventCount));
9316
+ continue;
9317
+ }
9318
+ await this.logger.error(`Failed to upload Local Codex events for ${request2.attemptId}`, error, metadata);
9319
+ throw error;
9320
+ }
9321
+ }
9213
9322
  }
9214
9323
  enqueueEventFlush(active) {
9215
9324
  if (active.eventUploadScheduled) {
@@ -9323,7 +9432,8 @@ var init_runtime_worker = __esm({
9323
9432
  const status = this.processPool.status();
9324
9433
  return status.appServerStatus === LocalCodexComponentStatusWire.Ready && status.codexAuthStatus === LocalCodexComponentStatusWire.Ready && status.codexBinaryStatus === LocalCodexComponentStatusWire.Ready;
9325
9434
  }
9326
- async setInitialThreadName(client, claim, threadId) {
9435
+ async setInitialThreadName(client, active, threadId) {
9436
+ const claim = active.claim;
9327
9437
  if (claim.executionContext.workflowTaskId !== void 0 || claim.executionContext.workflowWatcherId !== void 0) {
9328
9438
  return;
9329
9439
  }
@@ -9335,13 +9445,42 @@ var init_runtime_worker = __esm({
9335
9445
  if (name === "") {
9336
9446
  return;
9337
9447
  }
9338
- try {
9339
- await client.request("thread/name/set", {
9340
- name,
9341
- threadId
9448
+ const signal = active.finished.signal;
9449
+ let retryMilliseconds = initialThreadNameRetryMilliseconds;
9450
+ for (let attempt = 1; attempt <= maximumInitialThreadNameAttempts; attempt += 1) {
9451
+ if (signal.aborted) {
9452
+ return;
9453
+ }
9454
+ try {
9455
+ await client.request("thread/name/set", {
9456
+ name,
9457
+ threadId
9458
+ });
9459
+ } catch (error) {
9460
+ const metadataPending = error instanceof AppServerResponseError && isThreadNameMetadataPendingResponse(error.responseMessage);
9461
+ if (!metadataPending || attempt === maximumInitialThreadNameAttempts) {
9462
+ await this.logger.error(`Failed to name Local Codex thread ${threadId}`, error);
9463
+ return;
9464
+ }
9465
+ await waitForAbort(signal, retryMilliseconds);
9466
+ retryMilliseconds = Math.min(retryMilliseconds * 2, maximumThreadNameRetryMilliseconds);
9467
+ continue;
9468
+ }
9469
+ const initialThreadName = active.initialThreadName;
9470
+ if (initialThreadName === void 0) {
9471
+ throw new AppServerProtocolError("Initial thread name state is unavailable");
9472
+ }
9473
+ initialThreadName.projectedTitle = name;
9474
+ await this.enqueueSpool(active, async () => {
9475
+ const titleAlreadyProjected = active.durable.snapshot().events.some((event2) => {
9476
+ return event2.kind === "thread_title_updated" && event2.payload.title === name;
9477
+ });
9478
+ if (titleAlreadyProjected) {
9479
+ return;
9480
+ }
9481
+ await active.durable.appendEvent("thread_title_updated", { title: name }, { nativeThreadId: threadId });
9342
9482
  });
9343
- } catch (error) {
9344
- await this.logger.error(`Failed to name Local Codex thread ${threadId}`, error);
9483
+ return;
9345
9484
  }
9346
9485
  }
9347
9486
  unregisterRoute() {
@@ -12995,6 +13134,7 @@ __export(dist_exports, {
12995
13134
  executeClaudeStart: () => executeClaudeStart,
12996
13135
  installUserService: () => installUserService,
12997
13136
  isTerminalJobStatus: () => isTerminalJobStatus,
13137
+ localCodexRuntimeEventsRequestBytes: () => localCodexRuntimeEventsRequestBytes,
12998
13138
  localMachineJobTargetRelationship: () => localMachineJobTargetRelationship,
12999
13139
  machineExecutionContextEnvironmentName: () => machineExecutionContextEnvironmentName,
13000
13140
  machineManagerActions: () => machineManagerActions,
@@ -13218,7 +13358,7 @@ function getApiKeyOrUndefined() {
13218
13358
 
13219
13359
  // src/utils/http.ts
13220
13360
  function getUserAgent() {
13221
- return `moxt-cli/${"0.10.0-beta.2"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
13361
+ return `moxt-cli/${"0.10.0-beta.3"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
13222
13362
  }
13223
13363
  async function sendRequest(method, path4, init) {
13224
13364
  return await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -26801,7 +26941,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
26801
26941
  var MAX_BATCH_SIZE = 100;
26802
26942
  function commonLabels() {
26803
26943
  return {
26804
- cli_version: "0.10.0-beta.2",
26944
+ cli_version: "0.10.0-beta.3",
26805
26945
  node_version: process.versions.node,
26806
26946
  os: (0, import_node_os9.platform)(),
26807
26947
  arch: (0, import_node_os9.arch)(),
@@ -26847,7 +26987,7 @@ async function flush() {
26847
26987
  }
26848
26988
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
26849
26989
  const payload = {
26850
- release_id: "0.10.0-beta.2",
26990
+ release_id: "0.10.0-beta.3",
26851
26991
  client_type: "cli",
26852
26992
  metric_data_list: batch.map((m) => ({
26853
26993
  profile: "cli",
@@ -27230,9 +27370,9 @@ function commandPath3(command) {
27230
27370
  }
27231
27371
 
27232
27372
  // 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");
27373
+ var program2 = createProgram("0.10.0-beta.3");
27374
+ installDaemonReconcileHook(program2, "0.10.0-beta.3");
27375
+ installUpdateHook(program2, "0.10.0-beta.3");
27236
27376
  instrumentProgram(program2);
27237
27377
  installExitHandler();
27238
27378
  program2.parseAsync(process.argv).then(async () => {