@swmansion/argent 0.35.1-next.99 → 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.
@@ -32151,9 +32151,9 @@ function writeOwnFileInPlace(file, data, mode) {
32151
32151
  return false;
32152
32152
  }
32153
32153
  try {
32154
- const stat6 = fs.fstatSync(fd);
32155
- if (!stat6.isFile() || stat6.uid !== uid && uid !== 0) return false;
32156
- fs.fchmodSync(fd, stat6.mode & mode & 511);
32154
+ const stat7 = fs.fstatSync(fd);
32155
+ if (!stat7.isFile() || stat7.uid !== uid && uid !== 0) return false;
32156
+ fs.fchmodSync(fd, stat7.mode & mode & 511);
32157
32157
  fs.ftruncateSync(fd);
32158
32158
  fs.writeFileSync(fd, data);
32159
32159
  return true;
@@ -32863,21 +32863,21 @@ function primaryGid() {
32863
32863
  function untrusted(dir) {
32864
32864
  const uid = process.getuid?.();
32865
32865
  if (uid === void 0) return null;
32866
- const otherCanWrite = (stat7) => {
32867
- const ownPrivateGroup = process.platform === "linux" && stat7.gid === primaryGid();
32868
- return (stat7.mode & 2) !== 0 || (stat7.mode & 16) !== 0 && !ownPrivateGroup;
32866
+ const otherCanWrite = (stat8) => {
32867
+ const ownPrivateGroup = process.platform === "linux" && stat8.gid === primaryGid();
32868
+ return (stat8.mode & 2) !== 0 || (stat8.mode & 16) !== 0 && !ownPrivateGroup;
32869
32869
  };
32870
- let stat6;
32870
+ let stat7;
32871
32871
  let parent;
32872
32872
  try {
32873
- stat6 = fs7.lstatSync(dir);
32873
+ stat7 = fs7.lstatSync(dir);
32874
32874
  parent = fs7.statSync(path7.dirname(dir));
32875
32875
  } catch {
32876
32876
  return "it cannot be read";
32877
32877
  }
32878
- if (!stat6.isDirectory()) return "it is not a directory";
32879
- if (stat6.uid !== uid) return "another account owns it";
32880
- if ((stat6.mode & 63) !== 0) return "other accounts can read or write it";
32878
+ if (!stat7.isDirectory()) return "it is not a directory";
32879
+ if (stat7.uid !== uid) return "another account owns it";
32880
+ if ((stat7.mode & 63) !== 0) return "other accounts can read or write it";
32881
32881
  if (parent.uid !== uid && parent.uid !== 0 || otherCanWrite(parent)) {
32882
32882
  return "other accounts can write its parent directory";
32883
32883
  }
@@ -33214,13 +33214,13 @@ function isWritable(dir) {
33214
33214
  return false;
33215
33215
  }
33216
33216
  }
33217
- function homeRefusal(stat6, uid) {
33218
- if (stat6.uid !== uid && !(stat6.uid === 0 && isWritable(STATE_DIR))) {
33217
+ function homeRefusal(stat7, uid) {
33218
+ if (stat7.uid !== uid && !(stat7.uid === 0 && isWritable(STATE_DIR))) {
33219
33219
  return `The Argent home ${STATE_DIR} belongs to another user. Change its owner or set ARGENT_HOME_DIR to a directory you own.`;
33220
33220
  }
33221
- const ownPrivateGroup = process.platform === "linux" && stat6.gid === primaryGid2();
33222
- const groupCanWrite = (stat6.mode & 16) !== 0 && !ownPrivateGroup;
33223
- if ((stat6.mode & 2) !== 0 || groupCanWrite) {
33221
+ const ownPrivateGroup = process.platform === "linux" && stat7.gid === primaryGid2();
33222
+ const groupCanWrite = (stat7.mode & 16) !== 0 && !ownPrivateGroup;
33223
+ if ((stat7.mode & 2) !== 0 || groupCanWrite) {
33224
33224
  return `The Argent home ${STATE_DIR} is writable by other users. If only you have used it, run \`chmod -R go-w '${STATE_DIR}/'\`. Otherwise set ARGENT_HOME_DIR to a new private directory.`;
33225
33225
  }
33226
33226
  return null;
@@ -33228,9 +33228,9 @@ function homeRefusal(stat6, uid) {
33228
33228
  function assertPrivateArgentHome() {
33229
33229
  const uid = process.getuid?.();
33230
33230
  if (uid === void 0) return;
33231
- const stat6 = statHome();
33232
- if (!stat6) return;
33233
- const refusal = homeRefusal(stat6, uid);
33231
+ const stat7 = statHome();
33232
+ if (!stat7) return;
33233
+ const refusal = homeRefusal(stat7, uid);
33234
33234
  if (refusal) throw new UnsafeArgentHomeError(refusal);
33235
33235
  }
33236
33236
  async function writeToolsServerState(state) {
@@ -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
 
@@ -37043,7 +37071,8 @@ function shouldShowFirstRunNotice() {
37043
37071
  import { createHash as createHash4 } from "node:crypto";
37044
37072
 
37045
37073
  // ../argent-mcp/src/content.ts
37046
- import { readFile as readFile7 } from "node:fs/promises";
37074
+ import { mkdir as mkdir4, readFile as readFile7, stat as stat6, writeFile as writeFile3 } from "node:fs/promises";
37075
+ import { dirname as dirname11, isAbsolute as isAbsolute7 } from "node:path";
37047
37076
  var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
37048
37077
  function imageBlock(data, mimeType) {
37049
37078
  return { type: "image", data: data.toString("base64"), mimeType };
@@ -37073,13 +37102,20 @@ async function toMcpContent(result, outputHint, ctx, args) {
37073
37102
  const { result: rewritten, images } = await materializeArtifacts(result, ctx);
37074
37103
  if (outputHint === "image") {
37075
37104
  if (images.length > 0) {
37076
- const saved = { type: "text", text: `Saved: ${images[0].localPath}` };
37105
+ const saved = {
37106
+ type: "text",
37107
+ text: await savedText(images[0].localPath, images[0].data, args)
37108
+ };
37077
37109
  if (suppressImage) return [saved];
37078
37110
  const blocks2 = images.map((img) => imageBlock(img.data, img.mimeType));
37079
37111
  blocks2.push(saved);
37080
37112
  return blocks2;
37081
37113
  }
37082
- return legacyImageContent(rewritten, suppressImage, ctx.signal);
37114
+ const legacy = await legacyImageContent(rewritten, suppressImage, ctx.signal);
37115
+ const out = requestedOut(args);
37116
+ if (!out) return legacy;
37117
+ const notSaved = `Could not save to ${out}: no image file came back, so any file already there is not this capture.`;
37118
+ return [...legacy, { type: "text", text: notSaved }];
37083
37119
  }
37084
37120
  const blocks = [{ type: "text", text: stringifyForText(rewritten) }];
37085
37121
  if (!suppressImage) for (const img of images) blocks.push(imageBlock(img.data, img.mimeType));
@@ -37090,6 +37126,29 @@ async function toMcpContent(result, outputHint, ctx, args) {
37090
37126
  }
37091
37127
  return [{ type: "text", text: stringifyForText(result) }];
37092
37128
  }
37129
+ function requestedOut(args) {
37130
+ return isRecord3(args) && typeof args.out === "string" ? args.out.trim() : "";
37131
+ }
37132
+ async function savedText(scratchPath, data, args) {
37133
+ const out = requestedOut(args);
37134
+ if (!out) return `Saved: ${scratchPath}`;
37135
+ if (!isAbsolute7(out)) {
37136
+ return `Saved: ${scratchPath}
37137
+ Could not save to ${out}: not an absolute path on this computer`;
37138
+ }
37139
+ try {
37140
+ await mkdir4(dirname11(out), { recursive: true });
37141
+ if ((await stat6(out).catch(() => null))?.isFile() === false) {
37142
+ throw new Error("not a regular file");
37143
+ }
37144
+ await writeFile3(out, data);
37145
+ return `Saved: ${out}`;
37146
+ } catch (err) {
37147
+ const reason = err instanceof Error ? err.message : String(err);
37148
+ return `Saved: ${scratchPath}
37149
+ Could not save to ${out}: ${reason}`;
37150
+ }
37151
+ }
37093
37152
  function joinTextOnlyContent(blocks) {
37094
37153
  if (blocks.length < 2 || !blocks.every((b) => b.type === "text")) return blocks;
37095
37154
  return [{ type: "text", text: blocks.map((b) => b.text).join("\n") }];
@@ -37346,7 +37405,9 @@ async function flowRunToMcpContent(result, ctx) {
37346
37405
  const num = step.index !== void 0 ? step.index + 1 : i + 1;
37347
37406
  const glyph = step.status ? `${STATUS_GLYPH[step.status] ?? "\u2022"} ` : "";
37348
37407
  const reason = step.reason ?? step.error;
37349
- const suffix = reason ? ` \u2014 ${reason}` : "";
37408
+ const continued = `
37409
+ ${stepIndent(step.depth)}`;
37410
+ const suffix = reason ? ` \u2014 ${String(reason).replaceAll("\n", continued)}` : "";
37350
37411
  const warning = step.warning ? ` \u26A0 ${step.warning}` : "";
37351
37412
  const timing = step.kind === "echo" ? "" : durationSuffix(step.durationMs);
37352
37413
  blocks.push({
@@ -37362,7 +37423,8 @@ async function flowRunToMcpContent(result, ctx) {
37362
37423
  blocks.push({ type: "text", text: parts.join("\n") });
37363
37424
  }
37364
37425
  if (step.result !== void 0) {
37365
- blocks.push(...await toMcpContent(step.result, step.outputHint, ctx, step.args));
37426
+ const renderArgs = isRecord3(step.args) ? { includeImageInContext: step.args.includeImageInContext } : void 0;
37427
+ blocks.push(...await toMcpContent(step.result, step.outputHint, ctx, renderArgs));
37366
37428
  }
37367
37429
  if (isRecord3(step.artifacts)) {
37368
37430
  blocks.push(...await stepArtifactBlocks(step.artifacts, step.status, ctx, step.depth));
@@ -38328,7 +38390,18 @@ async function fetchWithReconnect(getUrl, reconnect, config2) {
38328
38390
  const attemptInit = typeof init === "function" ? init() : init;
38329
38391
  callerSignal = attemptInit?.signal;
38330
38392
  const signal = callerSignal ? AbortSignal.any([controller.signal, callerSignal]) : controller.signal;
38331
- 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 });
38332
38405
  } catch (err) {
38333
38406
  lastError = err;
38334
38407
  if (callerSignal?.aborted || attempt === maxRetries) break;
@@ -38445,7 +38518,7 @@ import {
38445
38518
  statSync as statSync5
38446
38519
  } from "node:fs";
38447
38520
  import { appendFile } from "node:fs/promises";
38448
- import { dirname as dirname11 } from "node:path";
38521
+ import { dirname as dirname12 } from "node:path";
38449
38522
  var CALL_LOG_MAX_BYTES = 10 * 1024 * 1024;
38450
38523
  var STAT_EVERY_BYTES = 1024 * 1024;
38451
38524
  function createCallLog(file, maxBytes = CALL_LOG_MAX_BYTES) {
@@ -38473,7 +38546,7 @@ function createCallLog(file, maxBytes = CALL_LOG_MAX_BYTES) {
38473
38546
  return async function write(entry) {
38474
38547
  try {
38475
38548
  if (!dirReady) {
38476
- mkdirSync7(dirname11(file), { recursive: true, mode: 448 });
38549
+ mkdirSync7(dirname12(file), { recursive: true, mode: 448 });
38477
38550
  dirReady = true;
38478
38551
  }
38479
38552
  if (!checked || estimate >= maxBytes || sinceStat >= STAT_EVERY_BYTES) {
@@ -38526,6 +38599,13 @@ var import_semver = __toESM(require_semver2(), 1);
38526
38599
 
38527
38600
  // ../argent-mcp/src/release-highlights.ts
38528
38601
  var RELEASE_HIGHLIGHTS = {
38602
+ "0.36.0": [
38603
+ "Reduced token usage by over 30% in a typical task through more compact element trees and trimmed MCP tool descriptions and schemas.",
38604
+ "`argent e2e check` validates E2E tests before running them, and E2E tests now support `shutdown:` cleanup blocks, `{{var:NAME}}` variables, `{{output:...}}` script outputs, and `--secrets-file`.",
38605
+ "`await-network-request` checks request and response bodies, headers, and JWT claims, and supports `absent` mode to assert no matching request was sent.",
38606
+ "Hover over points in Mac apps with `gesture-hover` and keep a finger down between custom gesture calls.",
38607
+ "Global Argent installations update automatically, and devices can be claimed per session."
38608
+ ],
38529
38609
  "0.35.0": [
38530
38610
  "UI sessions use less agent context: Argent skips unchanged automatic screenshots and sends just the changed lines for small element tree updates.",
38531
38611
  "Capture native network requests from iOS and Mac apps and inspect their headers and bodies.",
@@ -38589,7 +38669,7 @@ async function startMcpServer(options) {
38589
38669
  const autoDescribeOn = autoDescribeEnabled();
38590
38670
  const whatsNewOn = whatsNewEnabled();
38591
38671
  const installedVersion = getInstalledVersion();
38592
- const highlightsVersion = true ? "0.35.1-next.99" : installedVersion;
38672
+ const highlightsVersion = true ? "0.36.1-next.0" : installedVersion;
38593
38673
  const captureTimeoutMs = options.captureTimeoutMs ?? CAPTURE_TIMEOUT_MS;
38594
38674
  const trees = createTreeMemory();
38595
38675
  const screenshots = createScreenshotMemory();