@swmansion/argent 0.35.1-next.83 → 0.35.1-next.85

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.
@@ -22308,7 +22308,6 @@ var require_semver2 = __commonJS({
22308
22308
 
22309
22309
  // ../argent-mcp/src/mcp-server.ts
22310
22310
  import { join as join20 } from "node:path";
22311
- import { setTimeout as sleep } from "node:timers/promises";
22312
22311
 
22313
22312
  // ../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
22314
22313
  import process2 from "node:process";
@@ -35817,6 +35816,7 @@ function failedRun(result) {
35817
35816
  function createToolsClient(options = {}) {
35818
35817
  let cached2 = null;
35819
35818
  let linkedNoticeShown = false;
35819
+ let cachedToolList;
35820
35820
  const doFetch = options.fetchImpl ?? ((url, init) => fetch(url, init));
35821
35821
  const diagnose = options.onDiagnostic ?? ((message) => void process.stderr.write(`${message}
35822
35822
  `));
@@ -35849,13 +35849,16 @@ function createToolsClient(options = {}) {
35849
35849
  async function fetchToolList(opts) {
35850
35850
  opts?.signal?.throwIfAborted();
35851
35851
  const { url, token } = await baseUrl();
35852
+ if (cachedToolList?.url === url) return cachedToolList.list;
35852
35853
  const res = await doFetch(
35853
35854
  `${url}/tools`,
35854
35855
  { headers: { ...options.headers?.(), ...authHeaders2(token) }, signal: opts?.signal },
35855
35856
  { longRunning: false, carriesUpload: false }
35856
35857
  );
35857
35858
  if (!res.ok) throw new Error(`GET /tools failed: ${res.status} ${res.statusText}`);
35858
- return await res.json();
35859
+ const list = await res.json();
35860
+ if (options.cacheToolList) cachedToolList = { url, list };
35861
+ return list;
35859
35862
  }
35860
35863
  async function fetchTools(opts) {
35861
35864
  return (await fetchToolList(opts)).tools;
@@ -36344,6 +36347,191 @@ function getDeviceIdFromArgs(args) {
36344
36347
  return void 0;
36345
36348
  }
36346
36349
 
36350
+ // ../argent-tools-client/src/auto-capture.ts
36351
+ import { setTimeout as sleep } from "node:timers/promises";
36352
+ var AUTO_SCREENSHOT_TOOLS = /* @__PURE__ */ new Set([
36353
+ "gesture-tap",
36354
+ "gesture-swipe",
36355
+ "gesture-scroll",
36356
+ "gesture-drag",
36357
+ "gesture-hover",
36358
+ "gesture-custom",
36359
+ "gesture-pinch",
36360
+ "gesture-rotate",
36361
+ "button",
36362
+ "keyboard",
36363
+ "paste",
36364
+ "rotate",
36365
+ "fold",
36366
+ "tv-remote",
36367
+ "launch-app",
36368
+ "restart-app",
36369
+ "open-url",
36370
+ "describe",
36371
+ "run-sequence",
36372
+ // A wait is almost always followed by a look at the screen it waited for.
36373
+ "await-ui-element",
36374
+ "file-panel",
36375
+ "menu-bar"
36376
+ ]);
36377
+ var AUTO_SCREENSHOT_DELAY_MS_BY_TOOL = {
36378
+ "launch-app": 3e3,
36379
+ "restart-app": 3e3,
36380
+ "open-url": 2e3,
36381
+ "gesture-swipe": 1500,
36382
+ "gesture-scroll": 1500,
36383
+ "gesture-drag": 1500,
36384
+ "gesture-hover": 1500,
36385
+ "gesture-custom": 1500,
36386
+ "gesture-tap": 1500,
36387
+ "gesture-pinch": 1500,
36388
+ "gesture-rotate": 1500,
36389
+ // Only the settle after the last step; each step is an in-app action.
36390
+ "run-sequence": 3e3,
36391
+ "button": 1500,
36392
+ "tv-remote": 1500,
36393
+ "rotate": 1e3,
36394
+ // The fold tool already waits for the panel hand-over; the cap covers the
36395
+ // repaint after it.
36396
+ "fold": 1500,
36397
+ "keyboard": 300,
36398
+ "paste": 300,
36399
+ "describe": 100,
36400
+ // The wait returns on the first match, often mid-transition; the cap must
36401
+ // leave `await-screen-idle` room to see two identical reads.
36402
+ "await-ui-element": 1500
36403
+ };
36404
+ var DEFAULT_DELAY_MS = 1400;
36405
+ var LAUNCH_SETTLE_MS = 3e3;
36406
+ var CAPTURE_TIMEOUT_MS = 15e3;
36407
+ function autoScreenshotEnabled(options) {
36408
+ return !isFlagEnabled("disable-auto-screenshot", options);
36409
+ }
36410
+ var AUTO_DESCRIBE_TOOLS = /* @__PURE__ */ new Set([
36411
+ "gesture-tap",
36412
+ "gesture-swipe",
36413
+ "gesture-scroll",
36414
+ "gesture-drag",
36415
+ "gesture-hover",
36416
+ "gesture-custom",
36417
+ "gesture-pinch",
36418
+ "gesture-rotate",
36419
+ "button",
36420
+ "keyboard",
36421
+ "paste",
36422
+ "rotate",
36423
+ "fold",
36424
+ "tv-remote",
36425
+ "launch-app",
36426
+ "restart-app",
36427
+ "open-url",
36428
+ "run-sequence",
36429
+ "await-ui-element",
36430
+ "file-panel",
36431
+ "menu-bar"
36432
+ ]);
36433
+ function autoDescribeEnabled(options) {
36434
+ return !isFlagEnabled("disable-auto-describe", options);
36435
+ }
36436
+ 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.";
36437
+ 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.";
36438
+ var AUTO_DESCRIBE_HEADER = "--- Elements after action (describe) ---";
36439
+ function shouldAutoDescribe(toolName, args) {
36440
+ const canonical = normalizeToolName(toolName);
36441
+ return AUTO_DESCRIBE_TOOLS.has(canonical) && !isListCall(canonical, args);
36442
+ }
36443
+ var SECRET_PLACEHOLDER_MARKER = "{{secret:";
36444
+ function containsSecretPlaceholder(args) {
36445
+ try {
36446
+ return JSON.stringify(args)?.includes(SECRET_PLACEHOLDER_MARKER) ?? false;
36447
+ } catch {
36448
+ return true;
36449
+ }
36450
+ }
36451
+ function getUdidFromArgs(args) {
36452
+ if (args && typeof args === "object" && "udid" in args && typeof args.udid === "string") {
36453
+ return args.udid;
36454
+ }
36455
+ return void 0;
36456
+ }
36457
+ function normalizeToolName(name) {
36458
+ const idx = name.lastIndexOf("__");
36459
+ return idx === -1 ? name : name.slice(idx + 2);
36460
+ }
36461
+ function shouldAutoScreenshot(toolName, args) {
36462
+ const canonical = normalizeToolName(toolName);
36463
+ return canonical !== "screenshot" && AUTO_SCREENSHOT_TOOLS.has(canonical) && !isListCall(canonical, args);
36464
+ }
36465
+ function isListCall(canonical, args) {
36466
+ return (canonical === "menu-bar" || canonical === "file-panel") && args?.action === "list";
36467
+ }
36468
+ function getAutoScreenshotDelayMs(toolName) {
36469
+ const canonical = normalizeToolName(toolName);
36470
+ const base = AUTO_SCREENSHOT_DELAY_MS_BY_TOOL[canonical] ?? DEFAULT_DELAY_MS;
36471
+ const envOverride = process.env.ARGENT_AUTO_SCREENSHOT_DELAY_MS;
36472
+ if (envOverride) {
36473
+ const envMs = parseInt(envOverride, 10);
36474
+ if (!Number.isNaN(envMs)) return Math.max(base, envMs);
36475
+ }
36476
+ return base;
36477
+ }
36478
+ function describedTree(result) {
36479
+ const { description, hint } = result ?? {};
36480
+ if (typeof description !== "string" || description.length === 0) return void 0;
36481
+ const hintLine = typeof hint === "string" && hint && !description.includes(hint) ? `Hint: ${hint}
36482
+ ` : "";
36483
+ return `${hintLine}${description}`;
36484
+ }
36485
+ async function withDeadline(signal, ms, work) {
36486
+ const deadline = new AbortController();
36487
+ const timer = setTimeout(
36488
+ () => deadline.abort(new DOMException("The operation was aborted due to timeout", "TimeoutError")),
36489
+ ms
36490
+ );
36491
+ try {
36492
+ return await work(AbortSignal.any([signal, deadline.signal]));
36493
+ } finally {
36494
+ clearTimeout(timer);
36495
+ }
36496
+ }
36497
+ async function awaitScreenSettled(call, udid, toolName, signal, captureTimeoutMs) {
36498
+ const maxWaitMs = getAutoScreenshotDelayMs(toolName);
36499
+ if (maxWaitMs === 0) return { settled: true };
36500
+ const started = Date.now();
36501
+ const awaitIdle = async (timeoutMs) => await withDeadline(
36502
+ signal,
36503
+ timeoutMs + captureTimeoutMs,
36504
+ (s) => call("await-screen-idle", { udid, timeoutMs }, s)
36505
+ );
36506
+ try {
36507
+ let idle = await awaitIdle(maxWaitMs);
36508
+ if (idle?.launching === true && normalizeToolName(toolName) !== "describe") {
36509
+ idle = await awaitIdle(LAUNCH_SETTLE_MS);
36510
+ }
36511
+ return {
36512
+ settled: idle?.settled === true,
36513
+ readiness: { maxWaitMs, ...idle }
36514
+ };
36515
+ } catch {
36516
+ await sleep(Math.max(0, maxWaitMs - (Date.now() - started)), void 0, { signal }).catch(
36517
+ () => {
36518
+ }
36519
+ );
36520
+ return { settled: false };
36521
+ }
36522
+ }
36523
+ async function captureSettledScreen(options) {
36524
+ const { call, udid, toolName, signal, captureTimeoutMs } = options;
36525
+ const settledResult = await awaitScreenSettled(call, udid, toolName, signal, captureTimeoutMs);
36526
+ await options.onSettled?.(settledResult);
36527
+ return withDeadline(signal, captureTimeoutMs, async (captureSignal) => {
36528
+ const screenshot = options.screenshot?.(captureSignal) ?? Promise.resolve([]);
36529
+ if (!settledResult.settled) await screenshot;
36530
+ const tree = options.tree?.(captureSignal) ?? Promise.resolve([]);
36531
+ return [...await screenshot, ...await tree];
36532
+ });
36533
+ }
36534
+
36347
36535
  // ../telemetry/src/debug.ts
36348
36536
  import * as fs11 from "node:fs";
36349
36537
 
@@ -37200,132 +37388,6 @@ async function stepArtifactBlocks(artifacts, status, ctx, depth) {
37200
37388
  return blocks;
37201
37389
  }
37202
37390
 
37203
- // ../argent-mcp/src/auto-capture.ts
37204
- var AUTO_SCREENSHOT_TOOLS = /* @__PURE__ */ new Set([
37205
- "gesture-tap",
37206
- "gesture-swipe",
37207
- "gesture-scroll",
37208
- "gesture-drag",
37209
- "gesture-hover",
37210
- "gesture-custom",
37211
- "gesture-pinch",
37212
- "gesture-rotate",
37213
- "button",
37214
- "keyboard",
37215
- "paste",
37216
- "rotate",
37217
- "fold",
37218
- "tv-remote",
37219
- "launch-app",
37220
- "restart-app",
37221
- "open-url",
37222
- "describe",
37223
- "run-sequence",
37224
- // A wait is almost always followed by a look at the screen it waited for.
37225
- "await-ui-element",
37226
- "file-panel",
37227
- "menu-bar"
37228
- ]);
37229
- var AUTO_SCREENSHOT_DELAY_MS_BY_TOOL = {
37230
- "launch-app": 3e3,
37231
- "restart-app": 3e3,
37232
- "open-url": 2e3,
37233
- "gesture-swipe": 1500,
37234
- "gesture-scroll": 1500,
37235
- "gesture-drag": 1500,
37236
- "gesture-hover": 1500,
37237
- "gesture-custom": 1500,
37238
- "gesture-tap": 1500,
37239
- "gesture-pinch": 1500,
37240
- "gesture-rotate": 1500,
37241
- // Only the settle after the last step; each step is an in-app action.
37242
- "run-sequence": 3e3,
37243
- "button": 1500,
37244
- "tv-remote": 1500,
37245
- "rotate": 1e3,
37246
- // The fold tool already waits for the panel hand-over; the cap covers the
37247
- // repaint after it.
37248
- "fold": 1500,
37249
- "keyboard": 300,
37250
- "paste": 300,
37251
- "describe": 100,
37252
- // The wait returns on the first match, often mid-transition; the cap must
37253
- // leave `await-screen-idle` room to see two identical reads.
37254
- "await-ui-element": 1500
37255
- };
37256
- var DEFAULT_DELAY_MS = 1400;
37257
- var CAPTURE_TIMEOUT_MS = 15e3;
37258
- function autoScreenshotEnabled(options) {
37259
- return !isFlagEnabled("disable-auto-screenshot", options);
37260
- }
37261
- var AUTO_DESCRIBE_TOOLS = /* @__PURE__ */ new Set([
37262
- "gesture-tap",
37263
- "gesture-swipe",
37264
- "gesture-scroll",
37265
- "gesture-drag",
37266
- "gesture-hover",
37267
- "gesture-custom",
37268
- "gesture-pinch",
37269
- "gesture-rotate",
37270
- "button",
37271
- "keyboard",
37272
- "paste",
37273
- "rotate",
37274
- "fold",
37275
- "tv-remote",
37276
- "launch-app",
37277
- "restart-app",
37278
- "open-url",
37279
- "run-sequence",
37280
- "await-ui-element",
37281
- "file-panel",
37282
- "menu-bar"
37283
- ]);
37284
- function autoDescribeEnabled(options) {
37285
- return !isFlagEnabled("disable-auto-describe", options);
37286
- }
37287
- 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.";
37288
- var AUTO_DESCRIBE_HEADER = "--- Elements after action (describe) ---";
37289
- function shouldAutoDescribe(toolName, args) {
37290
- const canonical = normalizeToolName(toolName);
37291
- return AUTO_DESCRIBE_TOOLS.has(canonical) && !isListCall(canonical, args);
37292
- }
37293
- var SECRET_PLACEHOLDER_MARKER = "{{secret:";
37294
- function containsSecretPlaceholder(args) {
37295
- try {
37296
- return JSON.stringify(args)?.includes(SECRET_PLACEHOLDER_MARKER) ?? false;
37297
- } catch {
37298
- return true;
37299
- }
37300
- }
37301
- function getUdidFromArgs(args) {
37302
- if (args && typeof args === "object" && "udid" in args && typeof args.udid === "string") {
37303
- return args.udid;
37304
- }
37305
- return void 0;
37306
- }
37307
- function normalizeToolName(name) {
37308
- const idx = name.lastIndexOf("__");
37309
- return idx === -1 ? name : name.slice(idx + 2);
37310
- }
37311
- function shouldAutoScreenshot(toolName, args) {
37312
- const canonical = normalizeToolName(toolName);
37313
- return canonical !== "screenshot" && AUTO_SCREENSHOT_TOOLS.has(canonical) && !isListCall(canonical, args);
37314
- }
37315
- function isListCall(canonical, args) {
37316
- return (canonical === "menu-bar" || canonical === "file-panel") && args?.action === "list";
37317
- }
37318
- function getAutoScreenshotDelayMs(toolName) {
37319
- const canonical = normalizeToolName(toolName);
37320
- const base = AUTO_SCREENSHOT_DELAY_MS_BY_TOOL[canonical] ?? DEFAULT_DELAY_MS;
37321
- const envOverride = process.env.ARGENT_AUTO_SCREENSHOT_DELAY_MS;
37322
- if (envOverride) {
37323
- const envMs = parseInt(envOverride, 10);
37324
- if (!Number.isNaN(envMs)) return Math.max(base, envMs);
37325
- }
37326
- return base;
37327
- }
37328
-
37329
37391
  // ../argent-mcp/src/unchanged-tree.ts
37330
37392
  import { randomInt } from "node:crypto";
37331
37393
  var MAX_UNCHANGED_IN_A_ROW = 3;
@@ -37573,13 +37635,6 @@ ${tree}`, mode: "full", identical, note: false };
37573
37635
  }
37574
37636
  };
37575
37637
  }
37576
- function describedTree(result) {
37577
- const { description, hint } = result ?? {};
37578
- if (typeof description !== "string" || description.length === 0) return void 0;
37579
- const hintLine = typeof hint === "string" && hint && !description.includes(hint) ? `Hint: ${hint}
37580
- ` : "";
37581
- return `${hintLine}${description}`;
37582
- }
37583
37638
 
37584
37639
  // ../argent-mcp/src/unchanged-screenshot.ts
37585
37640
  import { createHash as createHash5, randomInt as randomInt2 } from "node:crypto";
@@ -38483,18 +38538,6 @@ function takeWhatsNewNote(current) {
38483
38538
 
38484
38539
  // ../argent-mcp/src/mcp-server.ts
38485
38540
  var SAVES_FILES_AFTER_CANCEL = /* @__PURE__ */ new Set(["screen-recording-stop", "native-profiler-stop"]);
38486
- async function withDeadline(signal, ms, work) {
38487
- const deadline = new AbortController();
38488
- const timer = setTimeout(
38489
- () => deadline.abort(new DOMException("The operation was aborted due to timeout", "TimeoutError")),
38490
- ms
38491
- );
38492
- try {
38493
- return await work(AbortSignal.any([signal, deadline.signal]));
38494
- } finally {
38495
- clearTimeout(timer);
38496
- }
38497
- }
38498
38541
  async function startMcpServer(options) {
38499
38542
  assertPrivateArgentHome();
38500
38543
  if (shouldShowFirstRunNotice()) {
@@ -38506,7 +38549,7 @@ async function startMcpServer(options) {
38506
38549
  const autoDescribeOn = autoDescribeEnabled();
38507
38550
  const whatsNewOn = whatsNewEnabled();
38508
38551
  const installedVersion = getInstalledVersion();
38509
- const highlightsVersion = true ? "0.35.1-next.82" : installedVersion;
38552
+ const highlightsVersion = true ? "0.35.1-next.84" : installedVersion;
38510
38553
  const captureTimeoutMs = options.captureTimeoutMs ?? CAPTURE_TIMEOUT_MS;
38511
38554
  const trees = createTreeMemory();
38512
38555
  const screenshots = createScreenshotMemory();
@@ -38562,31 +38605,15 @@ async function startMcpServer(options) {
38562
38605
  reconnect,
38563
38606
  extraHeaders: aiClientHeaders
38564
38607
  });
38565
- async function awaitScreenSettled(udid, toolName, signal) {
38566
- const maxWaitMs = getAutoScreenshotDelayMs(toolName);
38567
- if (maxWaitMs === 0) return true;
38568
- const started = Date.now();
38569
- try {
38570
- const idle = await withDeadline(
38571
- signal,
38572
- maxWaitMs + captureTimeoutMs,
38573
- (s) => callTool("await-screen-idle", { udid, timeoutMs: maxWaitMs }, { signal: s })
38574
- );
38575
- await spyLog({
38576
- ts: (/* @__PURE__ */ new Date()).toISOString(),
38577
- event: "auto_screenshot_readiness",
38578
- name: toolName,
38579
- maxWaitMs,
38580
- ...idle.result
38581
- });
38582
- return idle.result?.settled === true;
38583
- } catch {
38584
- await sleep(Math.max(0, maxWaitMs - (Date.now() - started)), void 0, { signal }).catch(
38585
- () => {
38586
- }
38587
- );
38588
- return false;
38589
- }
38608
+ const callForCapture = async (name, args, signal) => (await callTool(name, args, { signal })).result;
38609
+ async function logReadiness(toolName, settled) {
38610
+ if (!settled.readiness) return;
38611
+ await spyLog({
38612
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
38613
+ event: "auto_screenshot_readiness",
38614
+ name: toolName,
38615
+ ...settled.readiness
38616
+ });
38590
38617
  }
38591
38618
  async function captureScreenshotBlocks(udid, toolName, signal) {
38592
38619
  const t1 = Date.now();
@@ -38763,27 +38790,27 @@ ${shown.text}` }];
38763
38790
  const wantScreenshot = autoScreenshotOn && shouldAutoScreenshot(params.name, params.arguments);
38764
38791
  const wantTree = autoDescribeOn && shouldAutoDescribe(params.name, params.arguments);
38765
38792
  if (udid && (wantScreenshot || wantTree) && containsSecretPlaceholder(params.arguments)) {
38766
- content = [
38767
- ...content,
38768
- {
38769
- type: "text",
38770
- text: "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."
38771
- }
38772
- ];
38793
+ content = [...content, { type: "text", text: SECRET_CAPTURE_SKIPPED_NOTE }];
38773
38794
  } else if (udid && (wantScreenshot || wantTree) && profiling) {
38774
38795
  if (params.name !== "describe") {
38775
- await awaitScreenSettled(udid, params.name, signal);
38796
+ await logReadiness(
38797
+ params.name,
38798
+ await awaitScreenSettled(callForCapture, udid, params.name, signal, captureTimeoutMs)
38799
+ );
38776
38800
  content = [...content, { type: "text", text: PROFILING_CAPTURE_SKIPPED_NOTE }];
38777
38801
  }
38778
38802
  } else if (udid && (wantScreenshot || wantTree)) {
38779
- const screenSettled = await awaitScreenSettled(udid, params.name, signal);
38780
38803
  if (wantScreenshot) screenshotUdid = udid;
38781
38804
  if (wantTree) treeUdid = udid;
38782
- const captured = await withDeadline(signal, captureTimeoutMs, async (captureSignal) => {
38783
- const screenshot = wantScreenshot ? captureScreenshotBlocks(udid, params.name, captureSignal) : Promise.resolve([]);
38784
- if (!screenSettled) await screenshot;
38785
- const tree = wantTree ? captureTreeBlocks(udid, params.name, captureSignal) : Promise.resolve([]);
38786
- return [...await screenshot, ...await tree];
38805
+ const captured = await captureSettledScreen({
38806
+ call: callForCapture,
38807
+ udid,
38808
+ toolName: params.name,
38809
+ signal,
38810
+ captureTimeoutMs,
38811
+ screenshot: wantScreenshot ? (s) => captureScreenshotBlocks(udid, params.name, s) : void 0,
38812
+ tree: wantTree ? (s) => captureTreeBlocks(udid, params.name, s) : void 0,
38813
+ onSettled: (settled) => logReadiness(params.name, settled)
38787
38814
  });
38788
38815
  content = [...content, ...captured];
38789
38816
  }