@swmansion/argent 0.36.0 → 0.36.1-next.0

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.
@@ -33502,6 +33502,7 @@ import * as path14 from "node:path";
33502
33502
 
33503
33503
  // ../registry/src/types.ts
33504
33504
  var LINKED_CALL_HEADER = "x-argent-linked";
33505
+ var CALLER_DEADLINE_HEADER = "x-argent-deadline-ms";
33505
33506
  var E2E_DIR_CLIENT_HEADER = "x-argent-e2e-dir";
33506
33507
  var CLIENT_SECRETS_HEADER = "x-argent-client-secrets";
33507
33508
  var SESSION_HEADER = "x-argent-session";
@@ -33784,6 +33785,8 @@ var FAILURE_CODES = {
33784
33785
  REGISTRY_TOOL_EXECUTION_FAILED: "REGISTRY_TOOL_EXECUTION_FAILED",
33785
33786
  REGISTRY_TOOL_FAILURE_UNCLASSIFIED: "REGISTRY_TOOL_FAILURE_UNCLASSIFIED",
33786
33787
  REGISTRY_SERVICE_TERMINATING: "REGISTRY_SERVICE_TERMINATING",
33788
+ REGISTRY_TOOL_CALL_CANCELLED: "REGISTRY_TOOL_CALL_CANCELLED",
33789
+ REGISTRY_TOOL_CALL_TIMED_OUT: "REGISTRY_TOOL_CALL_TIMED_OUT",
33787
33790
  HTTP_TOOL_NOT_FOUND: "HTTP_TOOL_NOT_FOUND",
33788
33791
  HTTP_ZOD_VALIDATION_FAILED: "HTTP_ZOD_VALIDATION_FAILED",
33789
33792
  HTTP_CAPABILITY_UNSUPPORTED_OPERATION: "HTTP_CAPABILITY_UNSUPPORTED_OPERATION",
@@ -33990,7 +33993,6 @@ var FAILURE_CODES = {
33990
33993
  DEBUGGER_RELOAD_FAILED: "DEBUGGER_RELOAD_FAILED",
33991
33994
  // e2e-add-step refused a debugger-* call that answered `not_connected`.
33992
33995
  DEBUGGER_NOT_CONNECTED: "DEBUGGER_NOT_CONNECTED",
33993
- JS_RUNTIME_CONSOLE_SERVER_BIND_FAILED: "JS_RUNTIME_CONSOLE_SERVER_BIND_FAILED",
33994
33996
  JS_RUNTIME_PAYLOAD_INVALID: "JS_RUNTIME_PAYLOAD_INVALID",
33995
33997
  JS_RUNTIME_PAYLOAD_DEVICE_MISSING: "JS_RUNTIME_PAYLOAD_DEVICE_MISSING",
33996
33998
  JS_RUNTIME_PAYLOAD_PORT_INVALID: "JS_RUNTIME_PAYLOAD_PORT_INVALID",
@@ -34244,6 +34246,7 @@ var FAILURE_KINDS = [
34244
34246
  "network",
34245
34247
  "subprocess",
34246
34248
  "crash",
34249
+ "cancelled",
34247
34250
  "unknown"
34248
34251
  ];
34249
34252
  var FAILURE_COMMANDS = [
@@ -34305,6 +34308,18 @@ var FAILURE_SPAWN_CODE_SET = new Set(FAILURE_SPAWN_CODES);
34305
34308
  import { randomUUID as randomUUID3 } from "node:crypto";
34306
34309
  import { AsyncLocalStorage } from "node:async_hooks";
34307
34310
  var resolvedDuringInvocation = new AsyncLocalStorage();
34311
+ var CANCELLED_SIGNAL = {
34312
+ error_code: FAILURE_CODES.REGISTRY_TOOL_CALL_CANCELLED,
34313
+ failure_stage: "registry_tool_cancelled",
34314
+ failure_area: "registry",
34315
+ error_kind: "cancelled"
34316
+ };
34317
+ var TIMED_OUT_SIGNAL = {
34318
+ error_code: FAILURE_CODES.REGISTRY_TOOL_CALL_TIMED_OUT,
34319
+ failure_stage: "registry_tool_timed_out",
34320
+ failure_area: "registry",
34321
+ error_kind: "timeout"
34322
+ };
34308
34323
  function valueAtPath(root, path20) {
34309
34324
  let current = root;
34310
34325
  for (const key of path20) {
@@ -34848,34 +34863,33 @@ function uploadFailure(url, res, text, bytes) {
34848
34863
  }
34849
34864
  async function uploadTar(tarPath, format, endpoint, signal) {
34850
34865
  const { size } = await stat3(tarPath);
34851
- const stream = createReadStream2(tarPath);
34866
+ const body = createReadStream2(tarPath).on("error", () => {
34867
+ });
34852
34868
  const init = {
34853
34869
  method: "POST",
34854
34870
  headers: {
34855
34871
  "content-type": ARCHIVE_CONTENT_TYPES[format],
34856
34872
  ...endpoint.token ? { Authorization: `Bearer ${endpoint.token}` } : {}
34857
34873
  },
34858
- body: stream,
34874
+ body,
34859
34875
  duplex: "half",
34860
34876
  signal
34861
34877
  };
34862
- let res;
34863
34878
  try {
34864
- res = await fetch(`${endpoint.url}/upload`, init);
34865
- } catch (err) {
34866
- stream.destroy();
34867
- throw err;
34868
- }
34869
- if (!res.ok) {
34870
- let text = "";
34871
- try {
34872
- text = await res.text();
34873
- } catch {
34879
+ const res = await fetch(`${endpoint.url}/upload`, init);
34880
+ if (!res.ok) {
34881
+ let text = "";
34882
+ try {
34883
+ text = await res.text();
34884
+ } catch {
34885
+ }
34886
+ throw uploadFailure(endpoint.url, res, text, size);
34874
34887
  }
34875
- throw uploadFailure(endpoint.url, res, text, size);
34888
+ const json = await res.json();
34889
+ return json.uploadId;
34890
+ } finally {
34891
+ body.destroy();
34876
34892
  }
34877
- const json = await res.json();
34878
- return json.uploadId;
34879
34893
  }
34880
34894
  async function uploadFile(sourcePath, endpoint, signal) {
34881
34895
  const format = pickArchiveFormat(endpoint.formats);
@@ -35538,6 +35552,197 @@ async function e2eShadowWarningFor(tool, args) {
35538
35552
  return picked.shadowed === void 0 ? void 0 : e2eShadowWarning(picked.path, picked.shadowed);
35539
35553
  }
35540
35554
 
35555
+ // ../argent-tools-client/src/auto-capture.ts
35556
+ import { setTimeout as sleep } from "node:timers/promises";
35557
+ var AUTO_SCREENSHOT_TOOLS = /* @__PURE__ */ new Set([
35558
+ "gesture-tap",
35559
+ "gesture-swipe",
35560
+ "gesture-scroll",
35561
+ "gesture-drag",
35562
+ "gesture-hover",
35563
+ "gesture-custom",
35564
+ "gesture-pinch",
35565
+ "gesture-rotate",
35566
+ "button",
35567
+ "keyboard",
35568
+ "paste",
35569
+ "rotate",
35570
+ "fold",
35571
+ "tv-remote",
35572
+ "launch-app",
35573
+ "restart-app",
35574
+ "open-url",
35575
+ "describe",
35576
+ "run-sequence",
35577
+ // A wait is almost always followed by a look at the screen it waited for.
35578
+ "await-ui-element",
35579
+ "file-panel",
35580
+ "menu-bar"
35581
+ ]);
35582
+ var AUTO_SCREENSHOT_DELAY_MS_BY_TOOL = {
35583
+ "launch-app": 3e3,
35584
+ "restart-app": 3e3,
35585
+ "open-url": 2e3,
35586
+ "gesture-swipe": 1500,
35587
+ "gesture-scroll": 1500,
35588
+ "gesture-drag": 1500,
35589
+ "gesture-hover": 1500,
35590
+ "gesture-custom": 1500,
35591
+ "gesture-tap": 1500,
35592
+ "gesture-pinch": 1500,
35593
+ "gesture-rotate": 1500,
35594
+ // Only the settle after the last step; each step is an in-app action.
35595
+ "run-sequence": 3e3,
35596
+ "button": 1500,
35597
+ "tv-remote": 1500,
35598
+ "rotate": 1e3,
35599
+ // The fold tool already waits for the panel hand-over; the cap covers the
35600
+ // repaint after it.
35601
+ "fold": 1500,
35602
+ "keyboard": 300,
35603
+ "paste": 300,
35604
+ "describe": 100,
35605
+ // The wait returns on the first match, often mid-transition; the cap must
35606
+ // leave `await-screen-idle` room to see two identical reads.
35607
+ "await-ui-element": 1500
35608
+ };
35609
+ var DEFAULT_DELAY_MS = 1400;
35610
+ var LAUNCH_SETTLE_MS = 3e3;
35611
+ var CAPTURE_TIMEOUT_MS = 15e3;
35612
+ function autoScreenshotEnabled(options) {
35613
+ return !isFlagEnabled("disable-auto-screenshot", options);
35614
+ }
35615
+ var AUTO_DESCRIBE_TOOLS = /* @__PURE__ */ new Set([
35616
+ "gesture-tap",
35617
+ "gesture-swipe",
35618
+ "gesture-scroll",
35619
+ "gesture-drag",
35620
+ "gesture-hover",
35621
+ "gesture-custom",
35622
+ "gesture-pinch",
35623
+ "gesture-rotate",
35624
+ "button",
35625
+ "keyboard",
35626
+ "paste",
35627
+ "rotate",
35628
+ "fold",
35629
+ "tv-remote",
35630
+ "launch-app",
35631
+ "restart-app",
35632
+ "open-url",
35633
+ "run-sequence",
35634
+ "await-ui-element",
35635
+ "file-panel",
35636
+ "menu-bar"
35637
+ ]);
35638
+ function autoDescribeEnabled(options) {
35639
+ return !isFlagEnabled("disable-auto-describe", options);
35640
+ }
35641
+ var PROFILING_CAPTURE_SKIPPED_NOTE = "Auto-screenshot and element tree skipped while a profiler is recording on this device. Call screenshot or describe if you need to see the screen.";
35642
+ var SECRET_CAPTURE_SKIPPED_NOTE = "Auto-screenshot and element tree skipped: the input contains a {{secret:\u2026}} placeholder, and a capture of this screen could reveal the typed secret. The secret is already typed \u2014 do not send the typing step again, or the field will hold two copies of it. Submit or navigate away, then verify the resulting screen as usual. Only this call is covered: the next call is captured normally, and shows the secret if the field is still on screen. To cover the submit as well, put the typing and the submit in ONE `run-sequence` the next time you type a secret.";
35643
+ var AUTO_DESCRIBE_HEADER = "--- Elements after action (describe) ---";
35644
+ function shouldAutoDescribe(toolName, args) {
35645
+ const canonical = normalizeToolName(toolName);
35646
+ return AUTO_DESCRIBE_TOOLS.has(canonical) && !isListCall(canonical, args);
35647
+ }
35648
+ var SECRET_PLACEHOLDER_MARKER = "{{secret:";
35649
+ function containsSecretPlaceholder(args) {
35650
+ try {
35651
+ return JSON.stringify(args)?.includes(SECRET_PLACEHOLDER_MARKER) ?? false;
35652
+ } catch {
35653
+ return true;
35654
+ }
35655
+ }
35656
+ function getUdidFromArgs(args) {
35657
+ if (args && typeof args === "object" && "udid" in args && typeof args.udid === "string") {
35658
+ return args.udid;
35659
+ }
35660
+ return void 0;
35661
+ }
35662
+ function normalizeToolName(name) {
35663
+ const idx = name.lastIndexOf("__");
35664
+ return idx === -1 ? name : name.slice(idx + 2);
35665
+ }
35666
+ function shouldAutoScreenshot(toolName, args) {
35667
+ const canonical = normalizeToolName(toolName);
35668
+ return canonical !== "screenshot" && AUTO_SCREENSHOT_TOOLS.has(canonical) && !isListCall(canonical, args);
35669
+ }
35670
+ function isListCall(canonical, args) {
35671
+ return (canonical === "menu-bar" || canonical === "file-panel") && args?.action === "list";
35672
+ }
35673
+ function getAutoScreenshotDelayMs(toolName) {
35674
+ const canonical = normalizeToolName(toolName);
35675
+ const base = AUTO_SCREENSHOT_DELAY_MS_BY_TOOL[canonical] ?? DEFAULT_DELAY_MS;
35676
+ const envOverride = process.env.ARGENT_AUTO_SCREENSHOT_DELAY_MS;
35677
+ if (envOverride) {
35678
+ const envMs = parseInt(envOverride, 10);
35679
+ if (!Number.isNaN(envMs)) return Math.max(base, envMs);
35680
+ }
35681
+ return base;
35682
+ }
35683
+ function describedTree(result) {
35684
+ const { description, hint } = result ?? {};
35685
+ if (typeof description !== "string" || description.length === 0) return void 0;
35686
+ const hintLine = typeof hint === "string" && hint && !description.includes(hint) ? `Hint: ${hint}
35687
+ ` : "";
35688
+ return `${hintLine}${description}`;
35689
+ }
35690
+ var deadlines = /* @__PURE__ */ new WeakMap();
35691
+ async function withDeadline(signal, ms, work) {
35692
+ const deadline = new AbortController();
35693
+ const timer = setTimeout(
35694
+ () => deadline.abort(new DOMException("The operation was aborted due to timeout", "TimeoutError")),
35695
+ ms
35696
+ );
35697
+ const bounded = AbortSignal.any([signal, deadline.signal]);
35698
+ deadlines.set(bounded, performance.now() + ms);
35699
+ try {
35700
+ return await work(bounded);
35701
+ } finally {
35702
+ clearTimeout(timer);
35703
+ }
35704
+ }
35705
+ function signalDeadline(signal) {
35706
+ return deadlines.get(signal);
35707
+ }
35708
+ async function awaitScreenSettled(call, udid, toolName, signal, captureTimeoutMs) {
35709
+ const maxWaitMs = getAutoScreenshotDelayMs(toolName);
35710
+ if (maxWaitMs === 0) return { settled: true };
35711
+ const started = Date.now();
35712
+ const awaitIdle = async (timeoutMs) => await withDeadline(
35713
+ signal,
35714
+ timeoutMs + captureTimeoutMs,
35715
+ (s) => call("await-screen-idle", { udid, timeoutMs }, s)
35716
+ );
35717
+ try {
35718
+ let idle = await awaitIdle(maxWaitMs);
35719
+ if (idle?.launching === true && normalizeToolName(toolName) !== "describe") {
35720
+ idle = await awaitIdle(LAUNCH_SETTLE_MS);
35721
+ }
35722
+ return {
35723
+ settled: idle?.settled === true,
35724
+ readiness: { maxWaitMs, ...idle }
35725
+ };
35726
+ } catch {
35727
+ await sleep(Math.max(0, maxWaitMs - (Date.now() - started)), void 0, { signal }).catch(
35728
+ () => {
35729
+ }
35730
+ );
35731
+ return { settled: false };
35732
+ }
35733
+ }
35734
+ async function captureSettledScreen(options) {
35735
+ const { call, udid, toolName, signal, captureTimeoutMs } = options;
35736
+ const settledResult = await awaitScreenSettled(call, udid, toolName, signal, captureTimeoutMs);
35737
+ await options.onSettled?.(settledResult);
35738
+ return withDeadline(signal, captureTimeoutMs, async (captureSignal) => {
35739
+ const screenshot = options.screenshot?.(captureSignal) ?? Promise.resolve([]);
35740
+ if (!settledResult.settled) await screenshot;
35741
+ const tree = options.tree?.(captureSignal) ?? Promise.resolve([]);
35742
+ return [...await screenshot, ...await tree];
35743
+ });
35744
+ }
35745
+
35541
35746
  // ../argent-tools-client/src/tools-client.ts
35542
35747
  function authHeaders2(token) {
35543
35748
  return token ? { Authorization: `Bearer ${token}` } : {};
@@ -35796,6 +36001,12 @@ function secretsTransportRefusal(url) {
35796
36001
  return void 0;
35797
36002
  }
35798
36003
  var FETCH_HEAD_BYTES = 256;
36004
+ var FETCH_IDLE_TIMEOUT_MS = 3e5;
36005
+ function callerDeadlineMs(signal) {
36006
+ const deadline = signal ? signalDeadline(signal) : void 0;
36007
+ if (deadline === void 0) return FETCH_IDLE_TIMEOUT_MS;
36008
+ return Math.max(1, Math.min(FETCH_IDLE_TIMEOUT_MS, Math.ceil(deadline - performance.now())));
36009
+ }
35799
36010
  function isRecord2(value) {
35800
36011
  return typeof value === "object" && value !== null && !Array.isArray(value);
35801
36012
  }
@@ -35979,6 +36190,8 @@ function createToolsClient(options = {}) {
35979
36190
  // Tells the tool-server this client writes recordings under
35980
36191
  // `.argent/e2e/`; an older client writes only `.argent/flows/`.
35981
36192
  [E2E_DIR_CLIENT_HEADER]: "1",
36193
+ // So the tool-server reads a hang-up at this time as a timeout, not a cancel.
36194
+ [CALLER_DEADLINE_HEADER]: String(callerDeadlineMs(opts?.signal)),
35982
36195
  ...encodedSecrets ? { [CLIENT_SECRETS_HEADER]: encodedSecrets } : {},
35983
36196
  // A proxy that compresses the stream holds each line until its buffer
35984
36197
  // fills. `identity` keeps the stream uncompressed end to end.
@@ -36373,191 +36586,6 @@ function getDeviceIdFromArgs(args) {
36373
36586
  return void 0;
36374
36587
  }
36375
36588
 
36376
- // ../argent-tools-client/src/auto-capture.ts
36377
- import { setTimeout as sleep } from "node:timers/promises";
36378
- var AUTO_SCREENSHOT_TOOLS = /* @__PURE__ */ new Set([
36379
- "gesture-tap",
36380
- "gesture-swipe",
36381
- "gesture-scroll",
36382
- "gesture-drag",
36383
- "gesture-hover",
36384
- "gesture-custom",
36385
- "gesture-pinch",
36386
- "gesture-rotate",
36387
- "button",
36388
- "keyboard",
36389
- "paste",
36390
- "rotate",
36391
- "fold",
36392
- "tv-remote",
36393
- "launch-app",
36394
- "restart-app",
36395
- "open-url",
36396
- "describe",
36397
- "run-sequence",
36398
- // A wait is almost always followed by a look at the screen it waited for.
36399
- "await-ui-element",
36400
- "file-panel",
36401
- "menu-bar"
36402
- ]);
36403
- var AUTO_SCREENSHOT_DELAY_MS_BY_TOOL = {
36404
- "launch-app": 3e3,
36405
- "restart-app": 3e3,
36406
- "open-url": 2e3,
36407
- "gesture-swipe": 1500,
36408
- "gesture-scroll": 1500,
36409
- "gesture-drag": 1500,
36410
- "gesture-hover": 1500,
36411
- "gesture-custom": 1500,
36412
- "gesture-tap": 1500,
36413
- "gesture-pinch": 1500,
36414
- "gesture-rotate": 1500,
36415
- // Only the settle after the last step; each step is an in-app action.
36416
- "run-sequence": 3e3,
36417
- "button": 1500,
36418
- "tv-remote": 1500,
36419
- "rotate": 1e3,
36420
- // The fold tool already waits for the panel hand-over; the cap covers the
36421
- // repaint after it.
36422
- "fold": 1500,
36423
- "keyboard": 300,
36424
- "paste": 300,
36425
- "describe": 100,
36426
- // The wait returns on the first match, often mid-transition; the cap must
36427
- // leave `await-screen-idle` room to see two identical reads.
36428
- "await-ui-element": 1500
36429
- };
36430
- var DEFAULT_DELAY_MS = 1400;
36431
- var LAUNCH_SETTLE_MS = 3e3;
36432
- var CAPTURE_TIMEOUT_MS = 15e3;
36433
- function autoScreenshotEnabled(options) {
36434
- return !isFlagEnabled("disable-auto-screenshot", options);
36435
- }
36436
- var AUTO_DESCRIBE_TOOLS = /* @__PURE__ */ new Set([
36437
- "gesture-tap",
36438
- "gesture-swipe",
36439
- "gesture-scroll",
36440
- "gesture-drag",
36441
- "gesture-hover",
36442
- "gesture-custom",
36443
- "gesture-pinch",
36444
- "gesture-rotate",
36445
- "button",
36446
- "keyboard",
36447
- "paste",
36448
- "rotate",
36449
- "fold",
36450
- "tv-remote",
36451
- "launch-app",
36452
- "restart-app",
36453
- "open-url",
36454
- "run-sequence",
36455
- "await-ui-element",
36456
- "file-panel",
36457
- "menu-bar"
36458
- ]);
36459
- function autoDescribeEnabled(options) {
36460
- return !isFlagEnabled("disable-auto-describe", options);
36461
- }
36462
- var PROFILING_CAPTURE_SKIPPED_NOTE = "Auto-screenshot and element tree skipped while a profiler is recording on this device. Call screenshot or describe if you need to see the screen.";
36463
- var SECRET_CAPTURE_SKIPPED_NOTE = "Auto-screenshot and element tree skipped: the input contains a {{secret:\u2026}} placeholder, and a capture of this screen could reveal the typed secret. The secret is already typed \u2014 do not send the typing step again, or the field will hold two copies of it. Submit or navigate away, then verify the resulting screen as usual. Only this call is covered: the next call is captured normally, and shows the secret if the field is still on screen. To cover the submit as well, put the typing and the submit in ONE `run-sequence` the next time you type a secret.";
36464
- var AUTO_DESCRIBE_HEADER = "--- Elements after action (describe) ---";
36465
- function shouldAutoDescribe(toolName, args) {
36466
- const canonical = normalizeToolName(toolName);
36467
- return AUTO_DESCRIBE_TOOLS.has(canonical) && !isListCall(canonical, args);
36468
- }
36469
- var SECRET_PLACEHOLDER_MARKER = "{{secret:";
36470
- function containsSecretPlaceholder(args) {
36471
- try {
36472
- return JSON.stringify(args)?.includes(SECRET_PLACEHOLDER_MARKER) ?? false;
36473
- } catch {
36474
- return true;
36475
- }
36476
- }
36477
- function getUdidFromArgs(args) {
36478
- if (args && typeof args === "object" && "udid" in args && typeof args.udid === "string") {
36479
- return args.udid;
36480
- }
36481
- return void 0;
36482
- }
36483
- function normalizeToolName(name) {
36484
- const idx = name.lastIndexOf("__");
36485
- return idx === -1 ? name : name.slice(idx + 2);
36486
- }
36487
- function shouldAutoScreenshot(toolName, args) {
36488
- const canonical = normalizeToolName(toolName);
36489
- return canonical !== "screenshot" && AUTO_SCREENSHOT_TOOLS.has(canonical) && !isListCall(canonical, args);
36490
- }
36491
- function isListCall(canonical, args) {
36492
- return (canonical === "menu-bar" || canonical === "file-panel") && args?.action === "list";
36493
- }
36494
- function getAutoScreenshotDelayMs(toolName) {
36495
- const canonical = normalizeToolName(toolName);
36496
- const base = AUTO_SCREENSHOT_DELAY_MS_BY_TOOL[canonical] ?? DEFAULT_DELAY_MS;
36497
- const envOverride = process.env.ARGENT_AUTO_SCREENSHOT_DELAY_MS;
36498
- if (envOverride) {
36499
- const envMs = parseInt(envOverride, 10);
36500
- if (!Number.isNaN(envMs)) return Math.max(base, envMs);
36501
- }
36502
- return base;
36503
- }
36504
- function describedTree(result) {
36505
- const { description, hint } = result ?? {};
36506
- if (typeof description !== "string" || description.length === 0) return void 0;
36507
- const hintLine = typeof hint === "string" && hint && !description.includes(hint) ? `Hint: ${hint}
36508
- ` : "";
36509
- return `${hintLine}${description}`;
36510
- }
36511
- async function withDeadline(signal, ms, work) {
36512
- const deadline = new AbortController();
36513
- const timer = setTimeout(
36514
- () => deadline.abort(new DOMException("The operation was aborted due to timeout", "TimeoutError")),
36515
- ms
36516
- );
36517
- try {
36518
- return await work(AbortSignal.any([signal, deadline.signal]));
36519
- } finally {
36520
- clearTimeout(timer);
36521
- }
36522
- }
36523
- async function awaitScreenSettled(call, udid, toolName, signal, captureTimeoutMs) {
36524
- const maxWaitMs = getAutoScreenshotDelayMs(toolName);
36525
- if (maxWaitMs === 0) return { settled: true };
36526
- const started = Date.now();
36527
- const awaitIdle = async (timeoutMs) => await withDeadline(
36528
- signal,
36529
- timeoutMs + captureTimeoutMs,
36530
- (s) => call("await-screen-idle", { udid, timeoutMs }, s)
36531
- );
36532
- try {
36533
- let idle = await awaitIdle(maxWaitMs);
36534
- if (idle?.launching === true && normalizeToolName(toolName) !== "describe") {
36535
- idle = await awaitIdle(LAUNCH_SETTLE_MS);
36536
- }
36537
- return {
36538
- settled: idle?.settled === true,
36539
- readiness: { maxWaitMs, ...idle }
36540
- };
36541
- } catch {
36542
- await sleep(Math.max(0, maxWaitMs - (Date.now() - started)), void 0, { signal }).catch(
36543
- () => {
36544
- }
36545
- );
36546
- return { settled: false };
36547
- }
36548
- }
36549
- async function captureSettledScreen(options) {
36550
- const { call, udid, toolName, signal, captureTimeoutMs } = options;
36551
- const settledResult = await awaitScreenSettled(call, udid, toolName, signal, captureTimeoutMs);
36552
- await options.onSettled?.(settledResult);
36553
- return withDeadline(signal, captureTimeoutMs, async (captureSignal) => {
36554
- const screenshot = options.screenshot?.(captureSignal) ?? Promise.resolve([]);
36555
- if (!settledResult.settled) await screenshot;
36556
- const tree = options.tree?.(captureSignal) ?? Promise.resolve([]);
36557
- return [...await screenshot, ...await tree];
36558
- });
36559
- }
36560
-
36561
36589
  // ../telemetry/src/debug.ts
36562
36590
  import * as fs11 from "node:fs";
36563
36591
 
@@ -37377,7 +37405,9 @@ async function flowRunToMcpContent(result, ctx) {
37377
37405
  const num = step.index !== void 0 ? step.index + 1 : i + 1;
37378
37406
  const glyph = step.status ? `${STATUS_GLYPH[step.status] ?? "\u2022"} ` : "";
37379
37407
  const reason = step.reason ?? step.error;
37380
- const suffix = reason ? ` \u2014 ${reason}` : "";
37408
+ const continued = `
37409
+ ${stepIndent(step.depth)}`;
37410
+ const suffix = reason ? ` \u2014 ${String(reason).replaceAll("\n", continued)}` : "";
37381
37411
  const warning = step.warning ? ` \u26A0 ${step.warning}` : "";
37382
37412
  const timing = step.kind === "echo" ? "" : durationSuffix(step.durationMs);
37383
37413
  blocks.push({
@@ -38360,7 +38390,18 @@ async function fetchWithReconnect(getUrl, reconnect, config2) {
38360
38390
  const attemptInit = typeof init === "function" ? init() : init;
38361
38391
  callerSignal = attemptInit?.signal;
38362
38392
  const signal = callerSignal ? AbortSignal.any([controller.signal, callerSignal]) : controller.signal;
38363
- return await fetch(getUrl(), { ...attemptInit, signal });
38393
+ const headers = new Headers(attemptInit?.headers);
38394
+ const declared = Number(headers.get(CALLER_DEADLINE_HEADER));
38395
+ const callerDeadline = callerSignal ? signalDeadline(callerSignal) : void 0;
38396
+ const waitMs = Math.min(
38397
+ Number.isSafeInteger(declared) && declared > 0 ? declared : Infinity,
38398
+ fetchTimeoutMs ?? Infinity,
38399
+ callerDeadline === void 0 ? Infinity : callerDeadline - performance.now()
38400
+ );
38401
+ if (waitMs !== Infinity) {
38402
+ headers.set(CALLER_DEADLINE_HEADER, String(Math.max(1, Math.ceil(waitMs))));
38403
+ }
38404
+ return await fetch(getUrl(), { ...attemptInit, headers, signal });
38364
38405
  } catch (err) {
38365
38406
  lastError = err;
38366
38407
  if (callerSignal?.aborted || attempt === maxRetries) break;
@@ -38628,7 +38669,7 @@ async function startMcpServer(options) {
38628
38669
  const autoDescribeOn = autoDescribeEnabled();
38629
38670
  const whatsNewOn = whatsNewEnabled();
38630
38671
  const installedVersion = getInstalledVersion();
38631
- const highlightsVersion = true ? "0.36.0" : installedVersion;
38672
+ const highlightsVersion = true ? "0.36.1-next.0" : installedVersion;
38632
38673
  const captureTimeoutMs = options.captureTimeoutMs ?? CAPTURE_TIMEOUT_MS;
38633
38674
  const trees = createTreeMemory();
38634
38675
  const screenshots = createScreenshotMemory();