@moxt-ai/cli 0.12.0 → 0.12.2

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
@@ -9335,6 +9335,15 @@ var require_ignore = __commonJS({
9335
9335
  });
9336
9336
 
9337
9337
  // ../machine-connector/dist/runtime/local-codex-runtime/local-file-source.js
9338
+ function isPathWithin(path4, directory) {
9339
+ return path4 === directory || path4.startsWith(`${directory}/`);
9340
+ }
9341
+ function isStrictAncestorPath(path4, child) {
9342
+ if (child === void 0)
9343
+ return false;
9344
+ const normalizedPath = path4 === "." ? "" : path4;
9345
+ return normalizedPath === "" ? child !== "" : child.startsWith(`${normalizedPath}/`);
9346
+ }
9338
9347
  function resolveWithin(root, input) {
9339
9348
  if (input.length === 0 || input.includes("\0") || (0, import_node_path9.isAbsolute)(input) || import_node_path9.win32.isAbsolute(input) || /^[A-Za-z]:/.test(input) || input.split(/[\\/]/).includes("..")) {
9340
9349
  throw new Error("Local file path escapes its root");
@@ -9548,6 +9557,8 @@ var init_local_file_source = __esm({
9548
9557
  const matchers = [{ base: "", matcher: (0, import_ignore.default)().add(".git/").add(".git/**") }];
9549
9558
  const relativeThrough = (0, import_node_path9.relative)(this.pairedRoot, throughDirectory);
9550
9559
  const segments = relativeThrough === "" ? [] : relativeThrough.split(import_node_path9.sep);
9560
+ const workingDirectoryRootPath = portable((0, import_node_path9.relative)(this.pairedRoot, this.workingDirectory));
9561
+ const workingDirectorySegments = workingDirectoryRootPath === "." ? [] : workingDirectoryRootPath.split("/");
9551
9562
  let directory = this.pairedRoot;
9552
9563
  for (let index2 = 0; index2 <= segments.length; index2 += 1) {
9553
9564
  const matcher = (0, import_ignore.default)();
@@ -9565,17 +9576,28 @@ var init_local_file_source = __esm({
9565
9576
  if (segment !== void 0)
9566
9577
  directory = (0, import_node_path9.join)(directory, segment);
9567
9578
  }
9568
- return new ScopedIgnoreMatcher(matchers);
9579
+ if (workingDirectorySegments.length === 0) {
9580
+ return new ScopedIgnoreMatcher(matchers);
9581
+ }
9582
+ const inheritedMatchers = matchers.slice(0, workingDirectorySegments.length + 1);
9583
+ const workingDirectoryIsIgnored = new ScopedIgnoreMatcher(inheritedMatchers).ignores(workingDirectoryRootPath);
9584
+ return new ScopedIgnoreMatcher(matchers, workingDirectoryIsIgnored ? workingDirectoryRootPath : void 0);
9569
9585
  }
9570
9586
  };
9571
9587
  ScopedIgnoreMatcher = class {
9572
9588
  rules;
9573
- constructor(rules) {
9589
+ ignoredWorkingDirectory;
9590
+ constructor(rules, ignoredWorkingDirectory) {
9574
9591
  this.rules = rules;
9592
+ this.ignoredWorkingDirectory = ignoredWorkingDirectory;
9575
9593
  }
9576
9594
  ignores(rootPath) {
9577
9595
  let ignored = false;
9596
+ const skipInheritedRules = this.ignoredWorkingDirectory !== void 0 && isPathWithin(rootPath, this.ignoredWorkingDirectory);
9578
9597
  for (const rule of this.rules) {
9598
+ if (skipInheritedRules && isStrictAncestorPath(rule.base, this.ignoredWorkingDirectory)) {
9599
+ continue;
9600
+ }
9579
9601
  const localPath = relativePortable(rule.base, rootPath);
9580
9602
  if (localPath === void 0 || localPath === ".")
9581
9603
  continue;
@@ -9976,7 +9998,7 @@ var init_durable_attempt = __esm({
9976
9998
  });
9977
9999
 
9978
10000
  // ../machine-connector/dist/runtime/local-codex-runtime/event-normalizer.js
9979
- function normalizeAppServerNotification(message, canonicalRoot) {
10001
+ function normalizeAppServerNotification(message, canonicalRoot, remoteImageSourceUrls) {
9980
10002
  const method = message.method;
9981
10003
  if (method === void 0) {
9982
10004
  return {};
@@ -10059,7 +10081,7 @@ function normalizeAppServerNotification(message, canonicalRoot) {
10059
10081
  return event("usage_updated", { tokenUsage: params.tokenUsage }, correlation, canonicalRoot);
10060
10082
  }
10061
10083
  if (method === "item/started" || method === "item/completed") {
10062
- return normalizeItem(recordValue(params.item), method === "item/completed", correlation, canonicalRoot);
10084
+ return normalizeItem(recordValue(params.item), method === "item/completed", correlation, canonicalRoot, remoteImageSourceUrls);
10063
10085
  }
10064
10086
  if (method === "item/mcpToolCall/progress") {
10065
10087
  return event("tool_started", { message: params.message }, correlation, canonicalRoot);
@@ -10072,7 +10094,7 @@ function normalizeAppServerNotification(message, canonicalRoot) {
10072
10094
  function sanitizeAppServerPayload(value, canonicalRoot) {
10073
10095
  return sanitizeRecord(recordValue(value), canonicalRoot);
10074
10096
  }
10075
- function normalizeItem(item, completed, baseCorrelation, canonicalRoot) {
10097
+ function normalizeItem(item, completed, baseCorrelation, canonicalRoot, remoteImageSourceUrls) {
10076
10098
  const itemType = optionalString2(item.type).value;
10077
10099
  const correlation = {
10078
10100
  ...baseCorrelation,
@@ -10085,7 +10107,7 @@ function normalizeItem(item, completed, baseCorrelation, canonicalRoot) {
10085
10107
  }
10086
10108
  return event("user_message", {
10087
10109
  clientMessageId,
10088
- inputItems: userMessageInputItems(item.content)
10110
+ inputItems: userMessageInputItems(item.content, remoteImageSourceUrls)
10089
10111
  }, correlation, canonicalRoot);
10090
10112
  }
10091
10113
  if (itemType === "agentMessage") {
@@ -10115,7 +10137,7 @@ function normalizeItem(item, completed, baseCorrelation, canonicalRoot) {
10115
10137
  }
10116
10138
  return {};
10117
10139
  }
10118
- function userMessageInputItems(value) {
10140
+ function userMessageInputItems(value, remoteImageSourceUrls) {
10119
10141
  if (!Array.isArray(value)) {
10120
10142
  return [];
10121
10143
  }
@@ -10129,9 +10151,14 @@ function userMessageInputItems(value) {
10129
10151
  payload: { text: optionalString2(content3.text).value ?? "" }
10130
10152
  });
10131
10153
  } else if (contentType === "image") {
10154
+ const url = optionalString2(content3.url).value ?? "";
10155
+ const sourceUrl = remoteImageSourceUrls.get(url);
10156
+ if (url.startsWith("data:") && sourceUrl === void 0) {
10157
+ continue;
10158
+ }
10132
10159
  result.push({
10133
10160
  itemType: "image",
10134
- payload: { url: optionalString2(content3.url).value ?? "" }
10161
+ payload: { url: sourceUrl ?? url }
10135
10162
  });
10136
10163
  } else if (contentType === "localImage") {
10137
10164
  result.push({
@@ -10311,6 +10338,7 @@ function createActiveAttempt(claim, durable, workingDirectory) {
10311
10338
  leaseDeadlineMilliseconds: parseLeaseDeadline(claim.leaseExpiresAt),
10312
10339
  nativeThreadId: durable.snapshot().nativeThreadId ?? claim.nativeThreadId,
10313
10340
  processQuarantined: false,
10341
+ remoteImageSourceUrls: /* @__PURE__ */ new Map(),
10314
10342
  spoolQueue: Promise.resolve(),
10315
10343
  subagentThreadIds: /* @__PURE__ */ new Set(),
10316
10344
  terminal,
@@ -10497,36 +10525,42 @@ function requireTurnId2(response) {
10497
10525
  }
10498
10526
  return id;
10499
10527
  }
10500
- async function toCodexInput(items, pairedRoot, relativeWorkingDirectory) {
10528
+ async function toCodexInput(items, pairedRoot, relativeWorkingDirectory, signal, remoteImageSourceUrls) {
10501
10529
  const source = await LocalFileSource.create(pairedRoot, relativeWorkingDirectory);
10502
- return await Promise.all(items.map(async (item) => {
10530
+ const input = [];
10531
+ for (const item of items) {
10503
10532
  const payload = safeRecord2(item.payload);
10504
10533
  if (item.itemType === "text") {
10505
- return {
10534
+ input.push({
10506
10535
  type: "text",
10507
10536
  text: optionalString3(payload.text).value ?? "",
10508
10537
  text_elements: []
10509
- };
10538
+ });
10539
+ continue;
10510
10540
  }
10511
10541
  if (item.itemType === "image") {
10512
10542
  const url = optionalString3(payload.url).value;
10513
- if (url === void 0 || !isSecureImageUrl(url)) {
10514
- throw new Error("Remote image input requires a valid HTTPS URL");
10543
+ if (url === void 0) {
10544
+ throw new Error("Remote image input has no URL");
10515
10545
  }
10516
- return {
10546
+ const dataUrl = await downloadRemoteImageDataUrl(url, signal);
10547
+ remoteImageSourceUrls.set(dataUrl, url);
10548
+ input.push({
10517
10549
  type: "image",
10518
- url
10519
- };
10550
+ url: dataUrl
10551
+ });
10552
+ continue;
10520
10553
  }
10521
10554
  if (item.itemType === "local_image") {
10522
10555
  const path4 = optionalString3(payload.path).value;
10523
10556
  if (path4 === void 0)
10524
10557
  throw new Error("Local image input has no path");
10525
10558
  await source.validateImage(path4);
10526
- return {
10559
+ input.push({
10527
10560
  type: "localImage",
10528
10561
  path: path4
10529
- };
10562
+ });
10563
+ continue;
10530
10564
  }
10531
10565
  if (item.itemType === "local_file") {
10532
10566
  const path4 = optionalString3(payload.path).value;
@@ -10534,21 +10568,69 @@ async function toCodexInput(items, pairedRoot, relativeWorkingDirectory) {
10534
10568
  throw new Error("Local file input has no path");
10535
10569
  const kind = payload.kind === "directory" ? "directory" : "file";
10536
10570
  await source.validate(path4, kind);
10537
- return {
10571
+ input.push({
10538
10572
  type: "text",
10539
10573
  text: `@${path4}${kind === "directory" && !path4.endsWith("/") ? "/" : ""}`,
10540
10574
  text_elements: []
10541
- };
10575
+ });
10576
+ continue;
10542
10577
  }
10543
10578
  throw new Error(`Unsupported Local Codex input ${item.itemType}`);
10544
- }));
10579
+ }
10580
+ return input;
10581
+ }
10582
+ async function downloadRemoteImageDataUrl(value, signal) {
10583
+ const url = trustedRemoteImageUrl(value);
10584
+ const response = await fetch(url, {
10585
+ redirect: "error",
10586
+ signal: AbortSignal.any([signal, AbortSignal.timeout(remoteImageDownloadTimeoutMilliseconds)])
10587
+ });
10588
+ if (!response.ok) {
10589
+ await response.body?.cancel();
10590
+ throw new Error(`Remote image download failed with HTTP ${response.status}`);
10591
+ }
10592
+ const mimeType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
10593
+ if (mimeType === void 0 || !allowedRemoteImageMimeTypes.has(mimeType)) {
10594
+ await response.body?.cancel();
10595
+ throw new Error("Remote image response has an unsupported content type");
10596
+ }
10597
+ const contentLength = Number(response.headers.get("content-length"));
10598
+ if (Number.isFinite(contentLength) && contentLength > maximumRemoteImageBytes) {
10599
+ await response.body?.cancel();
10600
+ throw new Error("Remote image exceeds the 20 MiB limit");
10601
+ }
10602
+ if (response.body === null) {
10603
+ throw new Error("Remote image response has no body");
10604
+ }
10605
+ const reader = response.body.getReader();
10606
+ const chunks = [];
10607
+ let byteLength = 0;
10608
+ while (true) {
10609
+ const result = await reader.read();
10610
+ if (result.done) {
10611
+ break;
10612
+ }
10613
+ byteLength += result.value.byteLength;
10614
+ if (byteLength > maximumRemoteImageBytes) {
10615
+ await reader.cancel();
10616
+ throw new Error("Remote image exceeds the 20 MiB limit");
10617
+ }
10618
+ chunks.push(result.value);
10619
+ }
10620
+ if (byteLength === 0) {
10621
+ throw new Error("Remote image response is empty");
10622
+ }
10623
+ return `data:${mimeType};base64,${Buffer.concat(chunks, byteLength).toString("base64")}`;
10545
10624
  }
10546
- function isSecureImageUrl(value) {
10625
+ function trustedRemoteImageUrl(value) {
10547
10626
  try {
10548
10627
  const url = new URL(value);
10549
- return url.protocol === "https:" && url.username === "" && url.password === "" && url.hostname !== "";
10628
+ if (url.protocol !== "https:" || url.username !== "" || url.password !== "" || url.port !== "" || !allowedRemoteImageHosts.has(url.hostname) || !url.pathname.startsWith("/public/resource/")) {
10629
+ throw new Error("Remote image input requires a trusted Moxt image URL");
10630
+ }
10631
+ return url;
10550
10632
  } catch {
10551
- return false;
10633
+ throw new Error("Remote image input requires a trusted Moxt image URL");
10552
10634
  }
10553
10635
  }
10554
10636
  function localCodexInputItems(value) {
@@ -10784,7 +10866,7 @@ function parseLeaseDeadline(value) {
10784
10866
  function routineLeaseRenewalDelayMilliseconds(remainingLeaseMilliseconds) {
10785
10867
  return Math.min(leaseRenewIntervalMilliseconds, Math.max(1, Math.floor(remainingLeaseMilliseconds / leaseRenewalIntervalsBeforeDeadline)));
10786
10868
  }
10787
- 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;
10869
+ 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, remoteImageDownloadTimeoutMilliseconds, maximumRemoteImageBytes, allowedRemoteImageMimeTypes, allowedRemoteImageHosts, threadTitleGenerationInstructions, threadTitleGenerationOutputSchema, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, WorkerStoppedError, LocalCodexRuntimeConnectionWorker;
10788
10870
  var init_runtime_worker = __esm({
10789
10871
  "../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
10790
10872
  "use strict";
@@ -10825,6 +10907,18 @@ var init_runtime_worker = __esm({
10825
10907
  maximumThreadTitleSourceCharacters = 4e3;
10826
10908
  threadTitleGenerationTimeoutMilliseconds = 2e4;
10827
10909
  interruptedExecutionCleanupTimeoutMilliseconds = 3e3;
10910
+ remoteImageDownloadTimeoutMilliseconds = 3e4;
10911
+ maximumRemoteImageBytes = 20 * 1024 * 1024;
10912
+ allowedRemoteImageMimeTypes = /* @__PURE__ */ new Set([
10913
+ "image/gif",
10914
+ "image/jpeg",
10915
+ "image/png",
10916
+ "image/webp"
10917
+ ]);
10918
+ allowedRemoteImageHosts = /* @__PURE__ */ new Set([
10919
+ "static-dev.moxtcontent.com",
10920
+ "static.moxtcontent.com"
10921
+ ]);
10828
10922
  threadTitleGenerationInstructions = "Generate a concise semantic UI title for a coding conversation from its opening request. Use the request language. Prefer a specific noun phrase over a sentence, omit filler and incidental identifiers, and do not copy the full request unless it is already concise. Return only the structured result.";
10829
10923
  threadTitleGenerationOutputSchema = {
10830
10924
  additionalProperties: false,
@@ -10979,7 +11073,7 @@ var init_runtime_worker = __esm({
10979
11073
  if (captureThreadTitleGenerationNotification(active, message)) {
10980
11074
  return;
10981
11075
  }
10982
- const normalized = normalizeAppServerNotification(message, active.workingDirectory).value;
11076
+ const normalized = normalizeAppServerNotification(message, active.workingDirectory, active.remoteImageSourceUrls).value;
10983
11077
  if (normalized === void 0) {
10984
11078
  return;
10985
11079
  }
@@ -11440,7 +11534,7 @@ var init_runtime_worker = __esm({
11440
11534
  approvalPolicy: claim.approvalPolicy,
11441
11535
  cwd: active.workingDirectory,
11442
11536
  effort: claim.reasoningEffort,
11443
- input: await toCodexInput(claim.inputItems, this.connection.rootPath, claim.relativeWorkingDirectory),
11537
+ input: await toCodexInput(claim.inputItems, this.connection.rootPath, claim.relativeWorkingDirectory, active.finished.signal, active.remoteImageSourceUrls),
11444
11538
  ...claim.model === void 0 ? {} : { model: claim.model },
11445
11539
  sandboxPolicy: toSandboxPolicy(claim.sandboxPolicy, active.workingDirectory),
11446
11540
  summary: "auto",
@@ -11851,7 +11945,7 @@ var init_runtime_worker = __esm({
11851
11945
  const response = await client.request("turn/steer", {
11852
11946
  clientUserMessageId: clientMessageId,
11853
11947
  expectedTurnId: active.nativeTurnId,
11854
- input: await toCodexInput(inputItems, this.connection.rootPath, active.claim.relativeWorkingDirectory),
11948
+ input: await toCodexInput(inputItems, this.connection.rootPath, active.claim.relativeWorkingDirectory, active.finished.signal, active.remoteImageSourceUrls),
11855
11949
  threadId: active.nativeThreadId
11856
11950
  });
11857
11951
  if (response.turnId !== active.nativeTurnId) {
@@ -16535,7 +16629,7 @@ function getApiKeyOrUndefined() {
16535
16629
 
16536
16630
  // src/utils/http.ts
16537
16631
  function getUserAgent() {
16538
- return `moxt-cli/${"0.12.0"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
16632
+ return `moxt-cli/${"0.12.2"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
16539
16633
  }
16540
16634
  async function sendRequest(method, path4, init) {
16541
16635
  return await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -31121,7 +31215,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
31121
31215
  var MAX_BATCH_SIZE = 100;
31122
31216
  function commonLabels() {
31123
31217
  return {
31124
- cli_version: "0.12.0",
31218
+ cli_version: "0.12.2",
31125
31219
  node_version: process.versions.node,
31126
31220
  os: (0, import_node_os11.platform)(),
31127
31221
  arch: (0, import_node_os11.arch)(),
@@ -31167,7 +31261,7 @@ async function flush() {
31167
31261
  }
31168
31262
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
31169
31263
  const payload = {
31170
- release_id: "0.12.0",
31264
+ release_id: "0.12.2",
31171
31265
  client_type: "cli",
31172
31266
  metric_data_list: batch.map((m) => ({
31173
31267
  profile: "cli",
@@ -31550,9 +31644,9 @@ function commandPath3(command) {
31550
31644
  }
31551
31645
 
31552
31646
  // src/index.ts
31553
- var program2 = createProgram("0.12.0");
31554
- installDaemonReconcileHook(program2, "0.12.0");
31555
- installUpdateHook(program2, "0.12.0");
31647
+ var program2 = createProgram("0.12.2");
31648
+ installDaemonReconcileHook(program2, "0.12.2");
31649
+ installUpdateHook(program2, "0.12.2");
31556
31650
  instrumentProgram(program2);
31557
31651
  installExitHandler();
31558
31652
  program2.parseAsync(process.argv).then(async () => {