@swmansion/argent 0.35.1-next.84 → 0.35.1-next.86

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";
@@ -32309,7 +32308,7 @@ function configFilePath(scope = "global", options = {}) {
32309
32308
  }
32310
32309
 
32311
32310
  // ../configuration-core/src/config.ts
32312
- import * as crypto from "node:crypto";
32311
+ import * as crypto2 from "node:crypto";
32313
32312
  import * as fs4 from "node:fs";
32314
32313
  import * as path4 from "node:path";
32315
32314
  function readConfigObject(scope = "global", options = {}) {
@@ -32411,7 +32410,7 @@ function updateConfig(mutate, scope = "global", options = {}) {
32411
32410
  try {
32412
32411
  const next = readConfigObject(scope, options);
32413
32412
  mutate(next);
32414
- const tmpPath = path4.join(dir, `.config.tmp.${process.pid}.${crypto.randomUUID()}`);
32413
+ const tmpPath = path4.join(dir, `.config.tmp.${process.pid}.${crypto2.randomUUID()}`);
32415
32414
  const fd = fs4.openSync(tmpPath, "wx", 384);
32416
32415
  try {
32417
32416
  fs4.writeSync(fd, JSON.stringify(next, null, 2) + "\n");
@@ -33504,6 +33503,10 @@ import * as path14 from "node:path";
33504
33503
  var LINKED_CALL_HEADER = "x-argent-linked";
33505
33504
  var E2E_DIR_CLIENT_HEADER = "x-argent-e2e-dir";
33506
33505
  var CLIENT_SECRETS_HEADER = "x-argent-client-secrets";
33506
+ var SESSION_HEADER = "x-argent-session";
33507
+ function isValidSession(session) {
33508
+ return /^[\x21-\x7e]{1,128}$/.test(session);
33509
+ }
33507
33510
  var CLIENT_SECRET_SOURCES_HEADER = "x-argent-client-secret-sources";
33508
33511
 
33509
33512
  // ../registry/src/artifacts.ts
@@ -33785,6 +33788,8 @@ var FAILURE_CODES = {
33785
33788
  HTTP_CAPABILITY_UNSUPPORTED_OPERATION: "HTTP_CAPABILITY_UNSUPPORTED_OPERATION",
33786
33789
  HTTP_DEVICE_RESOLUTION_FAILED: "HTTP_DEVICE_RESOLUTION_FAILED",
33787
33790
  HTTP_DEPENDENCY_PREFLIGHT_MISSING: "HTTP_DEPENDENCY_PREFLIGHT_MISSING",
33791
+ // Another session holds a claim on the device the call names.
33792
+ DEVICE_IN_USE: "DEVICE_IN_USE",
33788
33793
  // The client's POST /upload of a file input was refused, so the call was not sent.
33789
33794
  FILE_INPUT_UPLOAD_FAILED: "FILE_INPUT_UPLOAD_FAILED",
33790
33795
  CLI_RUN_TOOL_NOT_FOUND: "CLI_RUN_TOOL_NOT_FOUND",
@@ -34789,6 +34794,9 @@ function removePendingArchives() {
34789
34794
  function removeArchivesOnSignal(signal) {
34790
34795
  removePendingArchives();
34791
34796
  if (process.listenerCount(signal) > 0) return;
34797
+ raiseSignal(signal);
34798
+ }
34799
+ function raiseSignal(signal) {
34792
34800
  try {
34793
34801
  process.kill(process.pid, signal);
34794
34802
  } catch {
@@ -35814,9 +35822,23 @@ function failedRun(result) {
35814
35822
  }
35815
35823
  return result;
35816
35824
  }
35825
+ function sessionFromEnv() {
35826
+ const session = process.env.ARGENT_SESSION?.trim();
35827
+ if (!session) return void 0;
35828
+ if (!isValidSession(session)) {
35829
+ throw new ToolInvocationError(
35830
+ "ARGENT_SESSION must be 1 to 128 printable ASCII characters without spaces."
35831
+ );
35832
+ }
35833
+ return session;
35834
+ }
35835
+ function hasSessionHeader(headers) {
35836
+ return Object.keys(headers).some((name) => name.toLowerCase() === SESSION_HEADER);
35837
+ }
35817
35838
  function createToolsClient(options = {}) {
35818
35839
  let cached2 = null;
35819
35840
  let linkedNoticeShown = false;
35841
+ let cachedToolList;
35820
35842
  const doFetch = options.fetchImpl ?? ((url, init) => fetch(url, init));
35821
35843
  const diagnose = options.onDiagnostic ?? ((message) => void process.stderr.write(`${message}
35822
35844
  `));
@@ -35849,13 +35871,16 @@ function createToolsClient(options = {}) {
35849
35871
  async function fetchToolList(opts) {
35850
35872
  opts?.signal?.throwIfAborted();
35851
35873
  const { url, token } = await baseUrl();
35874
+ if (cachedToolList?.url === url) return cachedToolList.list;
35852
35875
  const res = await doFetch(
35853
35876
  `${url}/tools`,
35854
35877
  { headers: { ...options.headers?.(), ...authHeaders2(token) }, signal: opts?.signal },
35855
35878
  { longRunning: false, carriesUpload: false }
35856
35879
  );
35857
35880
  if (!res.ok) throw new Error(`GET /tools failed: ${res.status} ${res.statusText}`);
35858
- return await res.json();
35881
+ const list = await res.json();
35882
+ if (options.cacheToolList) cachedToolList = { url, list };
35883
+ return list;
35859
35884
  }
35860
35885
  async function fetchTools(opts) {
35861
35886
  return (await fetchToolList(opts)).tools;
@@ -35866,6 +35891,7 @@ function createToolsClient(options = {}) {
35866
35891
  async function callTool(name, args, opts) {
35867
35892
  opts?.signal?.throwIfAborted();
35868
35893
  assertFiniteNumbers(args);
35894
+ const envSession = options.ignoreEnvSession || hasSessionHeader(options.headers?.() ?? {}) ? void 0 : sessionFromEnv();
35869
35895
  const { url, token, remote } = await route();
35870
35896
  let finalArgs = canonicalToolArgs(name, args);
35871
35897
  const { tools, uploadFormats } = await fetchToolList({ signal: opts?.signal });
@@ -35942,6 +35968,7 @@ function createToolsClient(options = {}) {
35942
35968
  }
35943
35969
  const toolUrl = `${url}/tools/${encodeURIComponent(meta2?.name ?? name)}`;
35944
35970
  const headers = {
35971
+ ...envSession ? { [SESSION_HEADER]: envSession } : {},
35945
35972
  ...options.headers?.(),
35946
35973
  "Content-Type": "application/json",
35947
35974
  // Tells the tool-server the call came over a link, a link to
@@ -36344,6 +36371,191 @@ function getDeviceIdFromArgs(args) {
36344
36371
  return void 0;
36345
36372
  }
36346
36373
 
36374
+ // ../argent-tools-client/src/auto-capture.ts
36375
+ import { setTimeout as sleep } from "node:timers/promises";
36376
+ var AUTO_SCREENSHOT_TOOLS = /* @__PURE__ */ new Set([
36377
+ "gesture-tap",
36378
+ "gesture-swipe",
36379
+ "gesture-scroll",
36380
+ "gesture-drag",
36381
+ "gesture-hover",
36382
+ "gesture-custom",
36383
+ "gesture-pinch",
36384
+ "gesture-rotate",
36385
+ "button",
36386
+ "keyboard",
36387
+ "paste",
36388
+ "rotate",
36389
+ "fold",
36390
+ "tv-remote",
36391
+ "launch-app",
36392
+ "restart-app",
36393
+ "open-url",
36394
+ "describe",
36395
+ "run-sequence",
36396
+ // A wait is almost always followed by a look at the screen it waited for.
36397
+ "await-ui-element",
36398
+ "file-panel",
36399
+ "menu-bar"
36400
+ ]);
36401
+ var AUTO_SCREENSHOT_DELAY_MS_BY_TOOL = {
36402
+ "launch-app": 3e3,
36403
+ "restart-app": 3e3,
36404
+ "open-url": 2e3,
36405
+ "gesture-swipe": 1500,
36406
+ "gesture-scroll": 1500,
36407
+ "gesture-drag": 1500,
36408
+ "gesture-hover": 1500,
36409
+ "gesture-custom": 1500,
36410
+ "gesture-tap": 1500,
36411
+ "gesture-pinch": 1500,
36412
+ "gesture-rotate": 1500,
36413
+ // Only the settle after the last step; each step is an in-app action.
36414
+ "run-sequence": 3e3,
36415
+ "button": 1500,
36416
+ "tv-remote": 1500,
36417
+ "rotate": 1e3,
36418
+ // The fold tool already waits for the panel hand-over; the cap covers the
36419
+ // repaint after it.
36420
+ "fold": 1500,
36421
+ "keyboard": 300,
36422
+ "paste": 300,
36423
+ "describe": 100,
36424
+ // The wait returns on the first match, often mid-transition; the cap must
36425
+ // leave `await-screen-idle` room to see two identical reads.
36426
+ "await-ui-element": 1500
36427
+ };
36428
+ var DEFAULT_DELAY_MS = 1400;
36429
+ var LAUNCH_SETTLE_MS = 3e3;
36430
+ var CAPTURE_TIMEOUT_MS = 15e3;
36431
+ function autoScreenshotEnabled(options) {
36432
+ return !isFlagEnabled("disable-auto-screenshot", options);
36433
+ }
36434
+ var AUTO_DESCRIBE_TOOLS = /* @__PURE__ */ new Set([
36435
+ "gesture-tap",
36436
+ "gesture-swipe",
36437
+ "gesture-scroll",
36438
+ "gesture-drag",
36439
+ "gesture-hover",
36440
+ "gesture-custom",
36441
+ "gesture-pinch",
36442
+ "gesture-rotate",
36443
+ "button",
36444
+ "keyboard",
36445
+ "paste",
36446
+ "rotate",
36447
+ "fold",
36448
+ "tv-remote",
36449
+ "launch-app",
36450
+ "restart-app",
36451
+ "open-url",
36452
+ "run-sequence",
36453
+ "await-ui-element",
36454
+ "file-panel",
36455
+ "menu-bar"
36456
+ ]);
36457
+ function autoDescribeEnabled(options) {
36458
+ return !isFlagEnabled("disable-auto-describe", options);
36459
+ }
36460
+ 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.";
36461
+ 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.";
36462
+ var AUTO_DESCRIBE_HEADER = "--- Elements after action (describe) ---";
36463
+ function shouldAutoDescribe(toolName, args) {
36464
+ const canonical = normalizeToolName(toolName);
36465
+ return AUTO_DESCRIBE_TOOLS.has(canonical) && !isListCall(canonical, args);
36466
+ }
36467
+ var SECRET_PLACEHOLDER_MARKER = "{{secret:";
36468
+ function containsSecretPlaceholder(args) {
36469
+ try {
36470
+ return JSON.stringify(args)?.includes(SECRET_PLACEHOLDER_MARKER) ?? false;
36471
+ } catch {
36472
+ return true;
36473
+ }
36474
+ }
36475
+ function getUdidFromArgs(args) {
36476
+ if (args && typeof args === "object" && "udid" in args && typeof args.udid === "string") {
36477
+ return args.udid;
36478
+ }
36479
+ return void 0;
36480
+ }
36481
+ function normalizeToolName(name) {
36482
+ const idx = name.lastIndexOf("__");
36483
+ return idx === -1 ? name : name.slice(idx + 2);
36484
+ }
36485
+ function shouldAutoScreenshot(toolName, args) {
36486
+ const canonical = normalizeToolName(toolName);
36487
+ return canonical !== "screenshot" && AUTO_SCREENSHOT_TOOLS.has(canonical) && !isListCall(canonical, args);
36488
+ }
36489
+ function isListCall(canonical, args) {
36490
+ return (canonical === "menu-bar" || canonical === "file-panel") && args?.action === "list";
36491
+ }
36492
+ function getAutoScreenshotDelayMs(toolName) {
36493
+ const canonical = normalizeToolName(toolName);
36494
+ const base = AUTO_SCREENSHOT_DELAY_MS_BY_TOOL[canonical] ?? DEFAULT_DELAY_MS;
36495
+ const envOverride = process.env.ARGENT_AUTO_SCREENSHOT_DELAY_MS;
36496
+ if (envOverride) {
36497
+ const envMs = parseInt(envOverride, 10);
36498
+ if (!Number.isNaN(envMs)) return Math.max(base, envMs);
36499
+ }
36500
+ return base;
36501
+ }
36502
+ function describedTree(result) {
36503
+ const { description, hint } = result ?? {};
36504
+ if (typeof description !== "string" || description.length === 0) return void 0;
36505
+ const hintLine = typeof hint === "string" && hint && !description.includes(hint) ? `Hint: ${hint}
36506
+ ` : "";
36507
+ return `${hintLine}${description}`;
36508
+ }
36509
+ async function withDeadline(signal, ms, work) {
36510
+ const deadline = new AbortController();
36511
+ const timer = setTimeout(
36512
+ () => deadline.abort(new DOMException("The operation was aborted due to timeout", "TimeoutError")),
36513
+ ms
36514
+ );
36515
+ try {
36516
+ return await work(AbortSignal.any([signal, deadline.signal]));
36517
+ } finally {
36518
+ clearTimeout(timer);
36519
+ }
36520
+ }
36521
+ async function awaitScreenSettled(call, udid, toolName, signal, captureTimeoutMs) {
36522
+ const maxWaitMs = getAutoScreenshotDelayMs(toolName);
36523
+ if (maxWaitMs === 0) return { settled: true };
36524
+ const started = Date.now();
36525
+ const awaitIdle = async (timeoutMs) => await withDeadline(
36526
+ signal,
36527
+ timeoutMs + captureTimeoutMs,
36528
+ (s) => call("await-screen-idle", { udid, timeoutMs }, s)
36529
+ );
36530
+ try {
36531
+ let idle = await awaitIdle(maxWaitMs);
36532
+ if (idle?.launching === true && normalizeToolName(toolName) !== "describe") {
36533
+ idle = await awaitIdle(LAUNCH_SETTLE_MS);
36534
+ }
36535
+ return {
36536
+ settled: idle?.settled === true,
36537
+ readiness: { maxWaitMs, ...idle }
36538
+ };
36539
+ } catch {
36540
+ await sleep(Math.max(0, maxWaitMs - (Date.now() - started)), void 0, { signal }).catch(
36541
+ () => {
36542
+ }
36543
+ );
36544
+ return { settled: false };
36545
+ }
36546
+ }
36547
+ async function captureSettledScreen(options) {
36548
+ const { call, udid, toolName, signal, captureTimeoutMs } = options;
36549
+ const settledResult = await awaitScreenSettled(call, udid, toolName, signal, captureTimeoutMs);
36550
+ await options.onSettled?.(settledResult);
36551
+ return withDeadline(signal, captureTimeoutMs, async (captureSignal) => {
36552
+ const screenshot = options.screenshot?.(captureSignal) ?? Promise.resolve([]);
36553
+ if (!settledResult.settled) await screenshot;
36554
+ const tree = options.tree?.(captureSignal) ?? Promise.resolve([]);
36555
+ return [...await screenshot, ...await tree];
36556
+ });
36557
+ }
36558
+
36347
36559
  // ../telemetry/src/debug.ts
36348
36560
  import * as fs11 from "node:fs";
36349
36561
 
@@ -36679,7 +36891,7 @@ import { existsSync as existsSync4 } from "node:fs";
36679
36891
  var SESSION_ID2 = randomUUID5();
36680
36892
 
36681
36893
  // ../telemetry/src/identity.ts
36682
- import * as crypto2 from "node:crypto";
36894
+ import * as crypto3 from "node:crypto";
36683
36895
  import * as fs12 from "node:fs";
36684
36896
  import * as path16 from "node:path";
36685
36897
 
@@ -37200,132 +37412,6 @@ async function stepArtifactBlocks(artifacts, status, ctx, depth) {
37200
37412
  return blocks;
37201
37413
  }
37202
37414
 
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
37415
  // ../argent-mcp/src/unchanged-tree.ts
37330
37416
  import { randomInt } from "node:crypto";
37331
37417
  var MAX_UNCHANGED_IN_A_ROW = 3;
@@ -37573,13 +37659,6 @@ ${tree}`, mode: "full", identical, note: false };
37573
37659
  }
37574
37660
  };
37575
37661
  }
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
37662
 
37584
37663
  // ../argent-mcp/src/unchanged-screenshot.ts
37585
37664
  import { createHash as createHash5, randomInt as randomInt2 } from "node:crypto";
@@ -38316,6 +38395,7 @@ function createToolCaller(deps) {
38316
38395
  const client = createToolsClient({
38317
38396
  baseUrl: async () => ({ ...deps.getHandle(), remote: deps.remote }),
38318
38397
  headers: deps.extraHeaders,
38398
+ ignoreEnvSession: true,
38319
38399
  refuseRelativeProjectPaths: true,
38320
38400
  fetchImpl: async (url, init, meta2) => {
38321
38401
  parseUrl(url);
@@ -38338,6 +38418,19 @@ function createToolCaller(deps) {
38338
38418
  };
38339
38419
  }
38340
38420
 
38421
+ // ../argent-mcp/src/release-on-exit.ts
38422
+ var EXIT_SIGNALS = ["SIGTERM", "SIGINT", "SIGHUP"];
38423
+ function releaseOnExit(release) {
38424
+ process.stdin.on("close", () => void release());
38425
+ function releaseThenRaise(signal) {
38426
+ void release().finally(() => {
38427
+ for (const s of EXIT_SIGNALS) process.removeListener(s, releaseThenRaise);
38428
+ raiseSignal(signal);
38429
+ });
38430
+ }
38431
+ for (const signal of EXIT_SIGNALS) process.on(signal, releaseThenRaise);
38432
+ }
38433
+
38341
38434
  // ../argent-mcp/src/call-log.ts
38342
38435
  import {
38343
38436
  appendFileSync as appendFileSync2,
@@ -38483,18 +38576,6 @@ function takeWhatsNewNote(current) {
38483
38576
 
38484
38577
  // ../argent-mcp/src/mcp-server.ts
38485
38578
  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
38579
  async function startMcpServer(options) {
38499
38580
  assertPrivateArgentHome();
38500
38581
  if (shouldShowFirstRunNotice()) {
@@ -38506,7 +38587,7 @@ async function startMcpServer(options) {
38506
38587
  const autoDescribeOn = autoDescribeEnabled();
38507
38588
  const whatsNewOn = whatsNewEnabled();
38508
38589
  const installedVersion = getInstalledVersion();
38509
- const highlightsVersion = true ? "0.35.1-next.84" : installedVersion;
38590
+ const highlightsVersion = true ? "0.35.1-next.86" : installedVersion;
38510
38591
  const captureTimeoutMs = options.captureTimeoutMs ?? CAPTURE_TIMEOUT_MS;
38511
38592
  const trees = createTreeMemory();
38512
38593
  const screenshots = createScreenshotMemory();
@@ -38541,6 +38622,13 @@ async function startMcpServer(options) {
38541
38622
  if (rawName) return { "X-Argent-AI-Client": "other" };
38542
38623
  return {};
38543
38624
  }
38625
+ const sessionId2 = crypto.randomUUID();
38626
+ let sessionCalledTools = false;
38627
+ let sessionEnded = false;
38628
+ function callerHeaders() {
38629
+ if (sessionEnded) return aiClientHeaders();
38630
+ return { ...aiClientHeaders(), [SESSION_HEADER]: sessionId2 };
38631
+ }
38544
38632
  let reconnectPromise = null;
38545
38633
  async function reconnect() {
38546
38634
  if (remote) return;
@@ -38560,33 +38648,17 @@ async function startMcpServer(options) {
38560
38648
  getHandle: () => ({ url: TOOLS_URL, token: AUTH_TOKEN }),
38561
38649
  remote,
38562
38650
  reconnect,
38563
- extraHeaders: aiClientHeaders
38651
+ extraHeaders: callerHeaders
38564
38652
  });
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
- }
38653
+ const callForCapture = async (name, args, signal) => (await callTool(name, args, { signal })).result;
38654
+ async function logReadiness(toolName, settled) {
38655
+ if (!settled.readiness) return;
38656
+ await spyLog({
38657
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
38658
+ event: "auto_screenshot_readiness",
38659
+ name: toolName,
38660
+ ...settled.readiness
38661
+ });
38590
38662
  }
38591
38663
  async function captureScreenshotBlocks(udid, toolName, signal) {
38592
38664
  const t1 = Date.now();
@@ -38700,6 +38772,7 @@ ${shown.text}` }];
38700
38772
  });
38701
38773
  server.setRequestHandler(CallToolRequestSchema, async ({ params }, { signal }) => {
38702
38774
  const t0 = Date.now();
38775
+ sessionCalledTools = true;
38703
38776
  const callSignal = SAVES_FILES_AFTER_CANCEL.has(canonicalToolId(params.name)) ? void 0 : signal;
38704
38777
  let treeUdid;
38705
38778
  let screenshotUdid;
@@ -38763,27 +38836,27 @@ ${shown.text}` }];
38763
38836
  const wantScreenshot = autoScreenshotOn && shouldAutoScreenshot(params.name, params.arguments);
38764
38837
  const wantTree = autoDescribeOn && shouldAutoDescribe(params.name, params.arguments);
38765
38838
  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
- ];
38839
+ content = [...content, { type: "text", text: SECRET_CAPTURE_SKIPPED_NOTE }];
38773
38840
  } else if (udid && (wantScreenshot || wantTree) && profiling) {
38774
38841
  if (params.name !== "describe") {
38775
- await awaitScreenSettled(udid, params.name, signal);
38842
+ await logReadiness(
38843
+ params.name,
38844
+ await awaitScreenSettled(callForCapture, udid, params.name, signal, captureTimeoutMs)
38845
+ );
38776
38846
  content = [...content, { type: "text", text: PROFILING_CAPTURE_SKIPPED_NOTE }];
38777
38847
  }
38778
38848
  } else if (udid && (wantScreenshot || wantTree)) {
38779
- const screenSettled = await awaitScreenSettled(udid, params.name, signal);
38780
38849
  if (wantScreenshot) screenshotUdid = udid;
38781
38850
  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];
38851
+ const captured = await captureSettledScreen({
38852
+ call: callForCapture,
38853
+ udid,
38854
+ toolName: params.name,
38855
+ signal,
38856
+ captureTimeoutMs,
38857
+ screenshot: wantScreenshot ? (s) => captureScreenshotBlocks(udid, params.name, s) : void 0,
38858
+ tree: wantTree ? (s) => captureTreeBlocks(udid, params.name, s) : void 0,
38859
+ onSettled: (settled) => logReadiness(params.name, settled)
38787
38860
  });
38788
38861
  content = [...content, ...captured];
38789
38862
  }
@@ -38841,6 +38914,21 @@ ${shown.text}` }];
38841
38914
  }, HEALTH_INTERVAL_MS);
38842
38915
  healthInterval.unref();
38843
38916
  }
38917
+ let release;
38918
+ function releaseSessionDevices() {
38919
+ if (!sessionCalledTools) return Promise.resolve();
38920
+ release ??= fetch(`${TOOLS_URL}/tools/release-device`, {
38921
+ method: "POST",
38922
+ headers: { ...authHeader(), ...callerHeaders(), "Content-Type": "application/json" },
38923
+ body: "{}",
38924
+ signal: AbortSignal.timeout(2e3)
38925
+ }).catch(() => {
38926
+ });
38927
+ sessionEnded = true;
38928
+ return release;
38929
+ }
38930
+ server.onclose = () => void releaseSessionDevices();
38931
+ if (!options.transport) releaseOnExit(releaseSessionDevices);
38844
38932
  if (process.env.ARGENT_TOOL_SERVER_SHUTDOWN_ON_MCP_EXIT === "1") {
38845
38933
  process.stdin.on("close", () => {
38846
38934
  fetch(`${TOOLS_URL}/shutdown`, { method: "POST", headers: authHeader() }).catch(() => {
@@ -1014,6 +1014,10 @@ export interface ArgentToolArgs {
1014
1014
  /** Path to `.app` (iOS), `.apk` (Android), `.vpkg` (Vega), or `.hap` (HarmonyOS). */
1015
1015
  appPath: string;
1016
1016
  };
1017
+ "release-device": {
1018
+ /** The device to release. Omit it to release every device of the session. */
1019
+ udid?: string;
1020
+ };
1017
1021
  "restart-app": {
1018
1022
  /** Target device id from `list-devices`. */
1019
1023
  udid: string;