@swmansion/argent 0.13.0 → 0.13.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.
@@ -3648,49 +3648,49 @@ var require_fast_uri = __commonJS({
3648
3648
  schemelessOptions.skipEscape = true;
3649
3649
  return serialize(resolved, schemelessOptions);
3650
3650
  }
3651
- function resolveComponent(base, relative2, options, skipNormalization) {
3651
+ function resolveComponent(base, relative, options, skipNormalization) {
3652
3652
  const target = {};
3653
3653
  if (!skipNormalization) {
3654
3654
  base = parse3(serialize(base, options), options);
3655
- relative2 = parse3(serialize(relative2, options), options);
3655
+ relative = parse3(serialize(relative, options), options);
3656
3656
  }
3657
3657
  options = options || {};
3658
- if (!options.tolerant && relative2.scheme) {
3659
- target.scheme = relative2.scheme;
3660
- target.userinfo = relative2.userinfo;
3661
- target.host = relative2.host;
3662
- target.port = relative2.port;
3663
- target.path = removeDotSegments(relative2.path || "");
3664
- target.query = relative2.query;
3658
+ if (!options.tolerant && relative.scheme) {
3659
+ target.scheme = relative.scheme;
3660
+ target.userinfo = relative.userinfo;
3661
+ target.host = relative.host;
3662
+ target.port = relative.port;
3663
+ target.path = removeDotSegments(relative.path || "");
3664
+ target.query = relative.query;
3665
3665
  } else {
3666
- if (relative2.userinfo !== void 0 || relative2.host !== void 0 || relative2.port !== void 0) {
3667
- target.userinfo = relative2.userinfo;
3668
- target.host = relative2.host;
3669
- target.port = relative2.port;
3670
- target.path = removeDotSegments(relative2.path || "");
3671
- target.query = relative2.query;
3666
+ if (relative.userinfo !== void 0 || relative.host !== void 0 || relative.port !== void 0) {
3667
+ target.userinfo = relative.userinfo;
3668
+ target.host = relative.host;
3669
+ target.port = relative.port;
3670
+ target.path = removeDotSegments(relative.path || "");
3671
+ target.query = relative.query;
3672
3672
  } else {
3673
- if (!relative2.path) {
3673
+ if (!relative.path) {
3674
3674
  target.path = base.path;
3675
- if (relative2.query !== void 0) {
3676
- target.query = relative2.query;
3675
+ if (relative.query !== void 0) {
3676
+ target.query = relative.query;
3677
3677
  } else {
3678
3678
  target.query = base.query;
3679
3679
  }
3680
3680
  } else {
3681
- if (relative2.path[0] === "/") {
3682
- target.path = removeDotSegments(relative2.path);
3681
+ if (relative.path[0] === "/") {
3682
+ target.path = removeDotSegments(relative.path);
3683
3683
  } else {
3684
3684
  if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) {
3685
- target.path = "/" + relative2.path;
3685
+ target.path = "/" + relative.path;
3686
3686
  } else if (!base.path) {
3687
- target.path = relative2.path;
3687
+ target.path = relative.path;
3688
3688
  } else {
3689
- target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative2.path;
3689
+ target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
3690
3690
  }
3691
3691
  target.path = removeDotSegments(target.path);
3692
3692
  }
3693
- target.query = relative2.query;
3693
+ target.query = relative.query;
3694
3694
  }
3695
3695
  target.userinfo = base.userinfo;
3696
3696
  target.host = base.host;
@@ -3698,7 +3698,7 @@ var require_fast_uri = __commonJS({
3698
3698
  }
3699
3699
  target.scheme = base.scheme;
3700
3700
  }
3701
- target.fragment = relative2.fragment;
3701
+ target.fragment = relative.fragment;
3702
3702
  return target;
3703
3703
  }
3704
3704
  function equal(uriA, uriB, options) {
@@ -6891,7 +6891,7 @@ var require_dist = __commonJS({
6891
6891
 
6892
6892
  // ../argent-mcp/src/mcp-server.ts
6893
6893
  import { appendFile, mkdir as mkdir5 } from "node:fs/promises";
6894
- import { dirname as dirname4 } from "node:path";
6894
+ import { dirname as dirname3 } from "node:path";
6895
6895
  import { homedir as homedir5 } from "node:os";
6896
6896
 
6897
6897
  // ../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
@@ -15460,12 +15460,13 @@ import * as fs from "node:fs";
15460
15460
  import * as path from "node:path";
15461
15461
  import * as readline from "node:readline";
15462
15462
  import { homedir } from "node:os";
15463
- import { spawn } from "node:child_process";
15463
+ import { spawn, execFileSync } from "node:child_process";
15464
15464
  import { randomBytes } from "node:crypto";
15465
15465
  import { mkdir, writeFile, readFile, unlink, rename, chmod } from "node:fs/promises";
15466
15466
  var STATE_DIR = path.join(homedir(), ".argent");
15467
15467
  var STATE_FILE = path.join(STATE_DIR, "tool-server.json");
15468
15468
  var LOG_FILE = path.join(STATE_DIR, "tool-server.log");
15469
+ var LOCK_FILE = path.join(STATE_DIR, "tool-server.lock");
15469
15470
  var AUTH_TOKEN_BYTES = 32;
15470
15471
  var AUTH_TOKEN_ENV = "ARGENT_AUTH_TOKEN";
15471
15472
  var AUTOSPAWN_IDLE_TIMEOUT_MINUTES = 30;
@@ -15532,6 +15533,8 @@ async function isToolsServerHealthy(port, host = "127.0.0.1", timeoutMs = 2e3, t
15532
15533
  signal: controller.signal,
15533
15534
  headers: authHeaders(token)
15534
15535
  });
15536
+ await res.body?.cancel().catch(() => {
15537
+ });
15535
15538
  return res.ok;
15536
15539
  } catch {
15537
15540
  return false;
@@ -15539,6 +15542,17 @@ async function isToolsServerHealthy(port, host = "127.0.0.1", timeoutMs = 2e3, t
15539
15542
  clearTimeout(timer);
15540
15543
  }
15541
15544
  }
15545
+ var SPAWN_READY_TIMEOUT_MS = 15e3;
15546
+ function killSpawnedChild(child, pid) {
15547
+ try {
15548
+ process.kill(-pid, "SIGKILL");
15549
+ } catch {
15550
+ try {
15551
+ child.kill("SIGKILL");
15552
+ } catch {
15553
+ }
15554
+ }
15555
+ }
15542
15556
  function spawnToolsServer(paths, port, options = {}) {
15543
15557
  return new Promise((resolve3, reject) => {
15544
15558
  let logFd;
@@ -15565,6 +15579,10 @@ function spawnToolsServer(paths, port, options = {}) {
15565
15579
  settled = true;
15566
15580
  fn();
15567
15581
  };
15582
+ const rejectAndKill = (err) => settle(() => {
15583
+ killSpawnedChild(child, pid);
15584
+ reject(err);
15585
+ });
15568
15586
  const rl = readline.createInterface({ input: child.stdout });
15569
15587
  rl.on("line", (line) => {
15570
15588
  const match = line.match(/Tools server listening on http:\/\/.+:(\d+)/);
@@ -15577,7 +15595,7 @@ function spawnToolsServer(paths, port, options = {}) {
15577
15595
  });
15578
15596
  child.on("error", (err) => {
15579
15597
  rl.close();
15580
- settle(() => reject(err));
15598
+ rejectAndKill(err);
15581
15599
  });
15582
15600
  child.on("exit", (code) => {
15583
15601
  rl.close();
@@ -15585,8 +15603,8 @@ function spawnToolsServer(paths, port, options = {}) {
15585
15603
  });
15586
15604
  const timer = setTimeout(() => {
15587
15605
  rl.close();
15588
- settle(() => reject(new Error("Timed out waiting for tools server to become ready")));
15589
- }, 15e3);
15606
+ rejectAndKill(new Error("Timed out waiting for tools server to become ready"));
15607
+ }, options.readyTimeoutMs ?? SPAWN_READY_TIMEOUT_MS);
15590
15608
  rl.on("close", () => clearTimeout(timer));
15591
15609
  });
15592
15610
  }
@@ -15623,37 +15641,146 @@ async function clearToolsServerState() {
15623
15641
  var readState = readToolsServerState;
15624
15642
  var writeState = writeToolsServerState;
15625
15643
  var clearState = clearToolsServerState;
15626
- async function ensureToolsServer(paths) {
15627
- const state = await readState();
15628
- if (state) {
15629
- const alive = isProcessAlive(state.pid);
15630
- if (alive) {
15631
- const host = state.host ?? "127.0.0.1";
15632
- const healthy = await isToolsServerHealthy(state.port, host, 2e3, state.token);
15633
- if (healthy) {
15634
- return {
15635
- url: formatUrl(healthCheckHost(host), state.port),
15636
- token: state.token ?? ""
15637
- };
15644
+ var SIGTERM_GRACE_MS = 6e3;
15645
+ var SIGKILL_GRACE_MS = 1e3;
15646
+ var KILL_POLL_MS = 100;
15647
+ async function waitForExit(pid, timeoutMs) {
15648
+ const deadline = Date.now() + timeoutMs;
15649
+ while (Date.now() < deadline) {
15650
+ if (!isProcessAlive(pid)) return true;
15651
+ await new Promise((r) => setTimeout(r, KILL_POLL_MS));
15652
+ }
15653
+ return !isProcessAlive(pid);
15654
+ }
15655
+ async function terminatePid(pid, stillOurs) {
15656
+ if (!isProcessAlive(pid)) return;
15657
+ if (stillOurs && !stillOurs()) return;
15658
+ try {
15659
+ process.kill(pid, "SIGTERM");
15660
+ } catch {
15661
+ return;
15662
+ }
15663
+ if (await waitForExit(pid, SIGTERM_GRACE_MS)) return;
15664
+ if (stillOurs && !(isProcessAlive(pid) && stillOurs())) return;
15665
+ try {
15666
+ process.kill(pid, "SIGKILL");
15667
+ } catch {
15668
+ return;
15669
+ }
15670
+ await waitForExit(pid, SIGKILL_GRACE_MS);
15671
+ }
15672
+ function processCommandMatches(pid, marker) {
15673
+ if (!marker) return false;
15674
+ try {
15675
+ const cmd = execFileSync("ps", ["-p", String(pid), "-o", "command="], {
15676
+ encoding: "utf8",
15677
+ timeout: 2e3,
15678
+ stdio: ["ignore", "pipe", "ignore"]
15679
+ }).trim();
15680
+ if (!cmd) return false;
15681
+ const argv = cmd.split(/\s+/);
15682
+ return argv.includes(marker) && argv.includes("start");
15683
+ } catch {
15684
+ return false;
15685
+ }
15686
+ }
15687
+ var LOCK_WAIT_TIMEOUT_MS = 3e4;
15688
+ var LOCK_STALE_MS = 45e3;
15689
+ var LOCK_POLL_MS = 100;
15690
+ function spawnLockIsStale() {
15691
+ try {
15692
+ const { pid, ts } = JSON.parse(fs.readFileSync(LOCK_FILE, "utf8"));
15693
+ if (typeof pid === "number" && pid > 0 && !isProcessAlive(pid)) return true;
15694
+ if (typeof ts === "number" && Date.now() - ts > LOCK_STALE_MS) return true;
15695
+ return false;
15696
+ } catch {
15697
+ try {
15698
+ return Date.now() - fs.statSync(LOCK_FILE).mtimeMs > LOCK_STALE_MS;
15699
+ } catch {
15700
+ return true;
15701
+ }
15702
+ }
15703
+ }
15704
+ async function acquireSpawnLock() {
15705
+ try {
15706
+ fs.mkdirSync(STATE_DIR, { recursive: true });
15707
+ } catch {
15708
+ return null;
15709
+ }
15710
+ const nonce = randomBytes(8).toString("hex");
15711
+ const deadline = Date.now() + LOCK_WAIT_TIMEOUT_MS;
15712
+ for (; ; ) {
15713
+ try {
15714
+ const fd = fs.openSync(LOCK_FILE, "wx");
15715
+ try {
15716
+ fs.writeSync(fd, JSON.stringify({ pid: process.pid, nonce, ts: Date.now() }));
15717
+ } finally {
15718
+ fs.closeSync(fd);
15719
+ }
15720
+ let released = false;
15721
+ return {
15722
+ release: () => {
15723
+ if (released) return;
15724
+ released = true;
15725
+ try {
15726
+ const cur = JSON.parse(fs.readFileSync(LOCK_FILE, "utf8"));
15727
+ if (cur.pid === process.pid && cur.nonce === nonce) fs.unlinkSync(LOCK_FILE);
15728
+ } catch {
15729
+ }
15730
+ }
15731
+ };
15732
+ } catch (err) {
15733
+ if (err.code !== "EEXIST") return null;
15734
+ if (spawnLockIsStale()) {
15735
+ try {
15736
+ fs.unlinkSync(LOCK_FILE);
15737
+ } catch {
15738
+ }
15739
+ if (!fs.existsSync(LOCK_FILE)) continue;
15638
15740
  }
15741
+ if (Date.now() >= deadline) return null;
15742
+ await new Promise((r) => setTimeout(r, LOCK_POLL_MS));
15743
+ }
15744
+ }
15745
+ }
15746
+ async function reusableHandle(state) {
15747
+ if (!state || !isProcessAlive(state.pid)) return null;
15748
+ const host = state.host ?? "127.0.0.1";
15749
+ const healthy = await isToolsServerHealthy(state.port, host, 2e3, state.token);
15750
+ if (!healthy) return null;
15751
+ return { url: formatUrl(healthCheckHost(host), state.port), token: state.token ?? "" };
15752
+ }
15753
+ async function ensureToolsServer(paths) {
15754
+ const fast = await reusableHandle(await readState());
15755
+ if (fast) return fast;
15756
+ const lock = await acquireSpawnLock();
15757
+ try {
15758
+ const state = await readState();
15759
+ const reuse = await reusableHandle(state);
15760
+ if (reuse) return reuse;
15761
+ if (state && state.managed === "autospawn" && isProcessAlive(state.pid) && processCommandMatches(state.pid, state.bundlePath)) {
15762
+ await terminatePid(state.pid, () => processCommandMatches(state.pid, state.bundlePath));
15639
15763
  }
15640
15764
  await clearState();
15765
+ const token = generateToken();
15766
+ const port = await findFreePort();
15767
+ const { port: actualPort, pid } = await spawnToolsServer(paths, port, {
15768
+ token,
15769
+ idleTimeoutMinutes: AUTOSPAWN_IDLE_TIMEOUT_MINUTES
15770
+ });
15771
+ await writeState({
15772
+ port: actualPort,
15773
+ pid,
15774
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
15775
+ bundlePath: paths.bundlePath,
15776
+ host: "127.0.0.1",
15777
+ token,
15778
+ managed: "autospawn"
15779
+ });
15780
+ return { url: formatUrl("127.0.0.1", actualPort), token };
15781
+ } finally {
15782
+ lock?.release();
15641
15783
  }
15642
- const token = generateToken();
15643
- const port = await findFreePort();
15644
- const { port: actualPort, pid } = await spawnToolsServer(paths, port, {
15645
- token,
15646
- idleTimeoutMinutes: AUTOSPAWN_IDLE_TIMEOUT_MINUTES
15647
- });
15648
- await writeState({
15649
- port: actualPort,
15650
- pid,
15651
- startedAt: (/* @__PURE__ */ new Date()).toISOString(),
15652
- bundlePath: paths.bundlePath,
15653
- host: "127.0.0.1",
15654
- token
15655
- });
15656
- return { url: formatUrl("127.0.0.1", actualPort), token };
15657
15784
  }
15658
15785
 
15659
15786
  // ../argent-tools-client/src/link-config.ts
@@ -15927,37 +16054,6 @@ function getDeviceIdFromArgs(args) {
15927
16054
  return void 0;
15928
16055
  }
15929
16056
 
15930
- // ../../node_modules/posthog-node/dist/extensions/error-tracking/modifiers/module.node.mjs
15931
- import { dirname as dirname2, posix, sep } from "path";
15932
- function createModulerModifier() {
15933
- const getModuleFromFileName = createGetModuleFromFilename();
15934
- return async (frames) => {
15935
- for (const frame of frames) frame.module = getModuleFromFileName(frame.filename);
15936
- return frames;
15937
- };
15938
- }
15939
- function createGetModuleFromFilename(basePath = process.argv[1] ? dirname2(process.argv[1]) : process.cwd(), isWindows = "\\" === sep) {
15940
- const normalizedBase = isWindows ? normalizeWindowsPath(basePath) : basePath;
15941
- return (filename) => {
15942
- if (!filename) return;
15943
- const normalizedFilename = isWindows ? normalizeWindowsPath(filename) : filename;
15944
- let { dir, base: file, ext } = posix.parse(normalizedFilename);
15945
- if (".js" === ext || ".mjs" === ext || ".cjs" === ext) file = file.slice(0, -1 * ext.length);
15946
- const decodedFile = decodeURIComponent(file);
15947
- if (!dir) dir = ".";
15948
- const n = dir.lastIndexOf("/node_modules");
15949
- if (n > -1) return `${dir.slice(n + 14).replace(/\//g, ".")}:${decodedFile}`;
15950
- if (dir.startsWith(normalizedBase)) {
15951
- const moduleName = dir.slice(normalizedBase.length + 1).replace(/\//g, ".");
15952
- return moduleName ? `${moduleName}:${decodedFile}` : decodedFile;
15953
- }
15954
- return decodedFile;
15955
- };
15956
- }
15957
- function normalizeWindowsPath(path9) {
15958
- return path9.replace(/^[A-Z]:/, "").replace(/\\/g, "/");
15959
- }
15960
-
15961
16057
  // ../../node_modules/@posthog/core/dist/utils/type-utils.mjs
15962
16058
  var nativeIsArray = Array.isArray;
15963
16059
  var ObjProto = Object.prototype;
@@ -15992,65 +16088,6 @@ function isInstanceOf(candidate, base) {
15992
16088
  }
15993
16089
  }
15994
16090
 
15995
- // ../../node_modules/@posthog/core/dist/utils/number-utils.mjs
15996
- function clampToRange(value, min, max, logger, fallbackValue) {
15997
- if (min > max) {
15998
- logger.warn("min cannot be greater than max.");
15999
- min = max;
16000
- }
16001
- if (isNumber(value)) if (value > max) {
16002
- logger.warn(" cannot be greater than max: " + max + ". Using max value instead.");
16003
- return max;
16004
- } else {
16005
- if (!(value < min)) return value;
16006
- logger.warn(" cannot be less than min: " + min + ". Using min value instead.");
16007
- return min;
16008
- }
16009
- logger.warn(" must be a number. using max or fallback. max: " + max + ", fallback: " + fallbackValue);
16010
- return clampToRange(fallbackValue || max, min, max, logger);
16011
- }
16012
-
16013
- // ../../node_modules/@posthog/core/dist/utils/bucketed-rate-limiter.mjs
16014
- var ONE_DAY_IN_MS = 864e5;
16015
- var BucketedRateLimiter = class {
16016
- constructor(options) {
16017
- this._buckets = {};
16018
- this._onBucketRateLimited = options._onBucketRateLimited;
16019
- this._bucketSize = clampToRange(options.bucketSize, 0, 100, options._logger);
16020
- this._refillRate = clampToRange(options.refillRate, 0, this._bucketSize, options._logger);
16021
- this._refillInterval = clampToRange(options.refillInterval, 0, ONE_DAY_IN_MS, options._logger);
16022
- }
16023
- _applyRefill(bucket, now) {
16024
- const elapsedMs = now - bucket.lastAccess;
16025
- const refillIntervals = Math.floor(elapsedMs / this._refillInterval);
16026
- if (refillIntervals > 0) {
16027
- const tokensToAdd = refillIntervals * this._refillRate;
16028
- bucket.tokens = Math.min(bucket.tokens + tokensToAdd, this._bucketSize);
16029
- bucket.lastAccess = bucket.lastAccess + refillIntervals * this._refillInterval;
16030
- }
16031
- }
16032
- consumeRateLimit(key) {
16033
- const now = Date.now();
16034
- const keyStr = String(key);
16035
- let bucket = this._buckets[keyStr];
16036
- if (bucket) this._applyRefill(bucket, now);
16037
- else {
16038
- bucket = {
16039
- tokens: this._bucketSize,
16040
- lastAccess: now
16041
- };
16042
- this._buckets[keyStr] = bucket;
16043
- }
16044
- if (0 === bucket.tokens) return true;
16045
- bucket.tokens--;
16046
- if (0 === bucket.tokens) this._onBucketRateLimited?.(key);
16047
- return 0 === bucket.tokens;
16048
- }
16049
- stop() {
16050
- this._buckets = {};
16051
- }
16052
- };
16053
-
16054
16091
  // ../../node_modules/@posthog/core/dist/utils/user-agent-utils.mjs
16055
16092
  var MOBILE = "Mobile";
16056
16093
  var IOS = "iOS";
@@ -16087,6 +16124,14 @@ var GENERIC_MOBILE = GENERIC + " " + MOBILE.toLowerCase();
16087
16124
  var GENERIC_TABLET = GENERIC + " " + TABLET.toLowerCase();
16088
16125
  var KONQUEROR = "Konqueror";
16089
16126
  var OCULUS_BROWSER = "Oculus Browser";
16127
+ var VIVALDI = "Vivaldi";
16128
+ var YANDEX = "Yandex";
16129
+ var WHALE = "Whale";
16130
+ var DUCKDUCKGO = "DuckDuckGo";
16131
+ var PALE_MOON = "Pale Moon";
16132
+ var WATERFOX = "Waterfox";
16133
+ var BRAVE = "Brave";
16134
+ var GOOGLE_SEARCH_APP = "Google Search App";
16090
16135
  var BROWSER_VERSION_REGEX_SUFFIX = "(\\d+(\\.\\d+)?)";
16091
16136
  var DEFAULT_BROWSER_VERSION_REGEX = new RegExp("Version/" + BROWSER_VERSION_REGEX_SUFFIX);
16092
16137
  var XBOX_REGEX = new RegExp(XBOX, "i");
@@ -16153,6 +16198,30 @@ var versionRegexes = {
16153
16198
  [OCULUS_BROWSER]: [
16154
16199
  new RegExp("OculusBrowser\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16155
16200
  ],
16201
+ [VIVALDI]: [
16202
+ new RegExp(VIVALDI + "\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16203
+ ],
16204
+ [YANDEX]: [
16205
+ new RegExp("YaBrowser\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16206
+ ],
16207
+ [WHALE]: [
16208
+ new RegExp(WHALE + "\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16209
+ ],
16210
+ [BRAVE]: [
16211
+ new RegExp(BRAVE + "\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16212
+ ],
16213
+ [DUCKDUCKGO]: [
16214
+ new RegExp("(DuckDuckGo|Ddg)\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16215
+ ],
16216
+ [PALE_MOON]: [
16217
+ new RegExp("PaleMoon\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16218
+ ],
16219
+ [WATERFOX]: [
16220
+ new RegExp(WATERFOX + "\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16221
+ ],
16222
+ [GOOGLE_SEARCH_APP]: [
16223
+ new RegExp("GSA\\/" + BROWSER_VERSION_REGEX_SUFFIX)
16224
+ ],
16156
16225
  [INTERNET_EXPLORER]: [
16157
16226
  new RegExp("(rv:|MSIE )" + BROWSER_VERSION_REGEX_SUFFIX)
16158
16227
  ],
@@ -17131,301 +17200,6 @@ import { createReadStream } from "node:fs";
17131
17200
  import { createInterface as createInterface2 } from "node:readline";
17132
17201
  var LRU_FILE_CONTENTS_CACHE = new error_tracking_exports.ReduceableCache(25);
17133
17202
  var LRU_FILE_CONTENTS_FS_READ_FAILED = new error_tracking_exports.ReduceableCache(20);
17134
- var DEFAULT_LINES_OF_CONTEXT = 7;
17135
- var MAX_CONTEXTLINES_COLNO = 1e3;
17136
- var MAX_CONTEXTLINES_LINENO = 1e4;
17137
- async function addSourceContext(frames) {
17138
- const filesToLines = {};
17139
- for (let i = frames.length - 1; i >= 0; i--) {
17140
- const frame = frames[i];
17141
- const filename = frame?.filename;
17142
- if (!frame || "string" != typeof filename || "number" != typeof frame.lineno || shouldSkipContextLinesForFile(filename) || shouldSkipContextLinesForFrame(frame)) continue;
17143
- const filesToLinesOutput = filesToLines[filename];
17144
- if (!filesToLinesOutput) filesToLines[filename] = [];
17145
- filesToLines[filename].push(frame.lineno);
17146
- }
17147
- const files = Object.keys(filesToLines);
17148
- if (0 == files.length) return frames;
17149
- const readlinePromises = [];
17150
- for (const file of files) {
17151
- if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(file)) continue;
17152
- const filesToLineRanges = filesToLines[file];
17153
- if (!filesToLineRanges) continue;
17154
- filesToLineRanges.sort((a, b) => a - b);
17155
- const ranges = makeLineReaderRanges(filesToLineRanges);
17156
- if (ranges.every((r) => rangeExistsInContentCache(file, r))) continue;
17157
- const cache2 = emplace(LRU_FILE_CONTENTS_CACHE, file, {});
17158
- readlinePromises.push(getContextLinesFromFile(file, ranges, cache2));
17159
- }
17160
- await Promise.all(readlinePromises).catch(() => {
17161
- });
17162
- if (frames && frames.length > 0) addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE);
17163
- LRU_FILE_CONTENTS_CACHE.reduce();
17164
- return frames;
17165
- }
17166
- function getContextLinesFromFile(path9, ranges, output) {
17167
- return new Promise((resolve3) => {
17168
- const stream = createReadStream(path9);
17169
- const lineReaded = createInterface2({
17170
- input: stream
17171
- });
17172
- function destroyStreamAndResolve() {
17173
- stream.destroy();
17174
- resolve3();
17175
- }
17176
- let lineNumber = 0;
17177
- let currentRangeIndex = 0;
17178
- const range = ranges[currentRangeIndex];
17179
- if (void 0 === range) return void destroyStreamAndResolve();
17180
- let rangeStart = range[0];
17181
- let rangeEnd = range[1];
17182
- function onStreamError() {
17183
- LRU_FILE_CONTENTS_FS_READ_FAILED.set(path9, 1);
17184
- lineReaded.close();
17185
- lineReaded.removeAllListeners();
17186
- destroyStreamAndResolve();
17187
- }
17188
- stream.on("error", onStreamError);
17189
- lineReaded.on("error", onStreamError);
17190
- lineReaded.on("close", destroyStreamAndResolve);
17191
- lineReaded.on("line", (line) => {
17192
- lineNumber++;
17193
- if (lineNumber < rangeStart) return;
17194
- output[lineNumber] = snipLine(line, 0);
17195
- if (lineNumber >= rangeEnd) {
17196
- if (currentRangeIndex === ranges.length - 1) {
17197
- lineReaded.close();
17198
- lineReaded.removeAllListeners();
17199
- return;
17200
- }
17201
- currentRangeIndex++;
17202
- const range2 = ranges[currentRangeIndex];
17203
- if (void 0 === range2) {
17204
- lineReaded.close();
17205
- lineReaded.removeAllListeners();
17206
- return;
17207
- }
17208
- rangeStart = range2[0];
17209
- rangeEnd = range2[1];
17210
- }
17211
- });
17212
- });
17213
- }
17214
- function addSourceContextToFrames(frames, cache2) {
17215
- for (const frame of frames) if (frame.filename && void 0 === frame.context_line && "number" == typeof frame.lineno) {
17216
- const contents = cache2.get(frame.filename);
17217
- if (void 0 === contents) continue;
17218
- addContextToFrame(frame.lineno, frame, contents);
17219
- }
17220
- }
17221
- function addContextToFrame(lineno, frame, contents) {
17222
- if (void 0 === frame.lineno || void 0 === contents) return;
17223
- frame.pre_context = [];
17224
- for (let i = makeRangeStart(lineno); i < lineno; i++) {
17225
- const line = contents[i];
17226
- if (void 0 === line) return void clearLineContext(frame);
17227
- frame.pre_context.push(line);
17228
- }
17229
- if (void 0 === contents[lineno]) return void clearLineContext(frame);
17230
- frame.context_line = contents[lineno];
17231
- const end = makeRangeEnd(lineno);
17232
- frame.post_context = [];
17233
- for (let i = lineno + 1; i <= end; i++) {
17234
- const line = contents[i];
17235
- if (void 0 === line) break;
17236
- frame.post_context.push(line);
17237
- }
17238
- }
17239
- function clearLineContext(frame) {
17240
- delete frame.pre_context;
17241
- delete frame.context_line;
17242
- delete frame.post_context;
17243
- }
17244
- function shouldSkipContextLinesForFile(path9) {
17245
- return path9.startsWith("node:") || path9.endsWith(".min.js") || path9.endsWith(".min.cjs") || path9.endsWith(".min.mjs") || path9.startsWith("data:");
17246
- }
17247
- function shouldSkipContextLinesForFrame(frame) {
17248
- if (void 0 !== frame.lineno && frame.lineno > MAX_CONTEXTLINES_LINENO) return true;
17249
- if (void 0 !== frame.colno && frame.colno > MAX_CONTEXTLINES_COLNO) return true;
17250
- return false;
17251
- }
17252
- function rangeExistsInContentCache(file, range) {
17253
- const contents = LRU_FILE_CONTENTS_CACHE.get(file);
17254
- if (void 0 === contents) return false;
17255
- for (let i = range[0]; i <= range[1]; i++) if (void 0 === contents[i]) return false;
17256
- return true;
17257
- }
17258
- function makeLineReaderRanges(lines) {
17259
- if (!lines.length) return [];
17260
- let i = 0;
17261
- const line = lines[0];
17262
- if ("number" != typeof line) return [];
17263
- let current = makeContextRange(line);
17264
- const out = [];
17265
- while (true) {
17266
- if (i === lines.length - 1) {
17267
- out.push(current);
17268
- break;
17269
- }
17270
- const next = lines[i + 1];
17271
- if ("number" != typeof next) break;
17272
- if (next <= current[1]) current[1] = next + DEFAULT_LINES_OF_CONTEXT;
17273
- else {
17274
- out.push(current);
17275
- current = makeContextRange(next);
17276
- }
17277
- i++;
17278
- }
17279
- return out;
17280
- }
17281
- function makeContextRange(line) {
17282
- return [
17283
- makeRangeStart(line),
17284
- makeRangeEnd(line)
17285
- ];
17286
- }
17287
- function makeRangeStart(line) {
17288
- return Math.max(1, line - DEFAULT_LINES_OF_CONTEXT);
17289
- }
17290
- function makeRangeEnd(line) {
17291
- return line + DEFAULT_LINES_OF_CONTEXT;
17292
- }
17293
- function emplace(map, key, contents) {
17294
- const value = map.get(key);
17295
- if (void 0 === value) {
17296
- map.set(key, contents);
17297
- return contents;
17298
- }
17299
- return value;
17300
- }
17301
- function snipLine(line, colno) {
17302
- let newLine = line;
17303
- const lineLength = newLine.length;
17304
- if (lineLength <= 150) return newLine;
17305
- if (colno > lineLength) colno = lineLength;
17306
- let start = Math.max(colno - 60, 0);
17307
- if (start < 5) start = 0;
17308
- let end = Math.min(start + 140, lineLength);
17309
- if (end > lineLength - 5) end = lineLength;
17310
- if (end === lineLength) start = Math.max(end - 140, 0);
17311
- newLine = newLine.slice(start, end);
17312
- if (start > 0) newLine = `...${newLine}`;
17313
- if (end < lineLength) newLine += "...";
17314
- return newLine;
17315
- }
17316
-
17317
- // ../../node_modules/posthog-node/dist/extensions/error-tracking/modifiers/relative-path.node.mjs
17318
- import { isAbsolute as isAbsolute2, relative, sep as sep2 } from "path";
17319
- function createRelativePathModifier(basePath = process.cwd()) {
17320
- const isWindows = "\\" === sep2;
17321
- const toUnix = (p) => isWindows ? p.replace(/\\/g, "/") : p;
17322
- const normalizedBase = toUnix(basePath);
17323
- return async (frames) => {
17324
- for (const frame of frames) if (!(!frame.filename || frame.filename.startsWith("node:") || frame.filename.startsWith("data:"))) {
17325
- if (isAbsolute2(frame.filename)) frame.filename = toUnix(relative(normalizedBase, toUnix(frame.filename)));
17326
- }
17327
- return frames;
17328
- };
17329
- }
17330
-
17331
- // ../../node_modules/posthog-node/dist/extensions/error-tracking/autocapture.mjs
17332
- function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
17333
- let calledFatalError = false;
17334
- return Object.assign((error2) => {
17335
- const userProvidedListenersCount = global.process.listeners("uncaughtException").filter((listener) => "domainUncaughtExceptionClear" !== listener.name && true !== listener._posthogErrorHandler).length;
17336
- const processWouldExit = 0 === userProvidedListenersCount;
17337
- captureFn(error2, {
17338
- mechanism: {
17339
- type: "onuncaughtexception",
17340
- handled: false
17341
- }
17342
- });
17343
- if (!calledFatalError && processWouldExit) {
17344
- calledFatalError = true;
17345
- onFatalFn(error2);
17346
- }
17347
- }, {
17348
- _posthogErrorHandler: true
17349
- });
17350
- }
17351
- function addUncaughtExceptionListener(captureFn, onFatalFn) {
17352
- globalThis.process?.on("uncaughtException", makeUncaughtExceptionHandler(captureFn, onFatalFn));
17353
- }
17354
- function addUnhandledRejectionListener(captureFn) {
17355
- globalThis.process?.on("unhandledRejection", (reason) => captureFn(reason, {
17356
- mechanism: {
17357
- type: "onunhandledrejection",
17358
- handled: false
17359
- }
17360
- }));
17361
- }
17362
-
17363
- // ../../node_modules/posthog-node/dist/extensions/error-tracking/index.mjs
17364
- var SHUTDOWN_TIMEOUT = 2e3;
17365
- var ErrorTracking = class _ErrorTracking {
17366
- constructor(client, options, _logger) {
17367
- this.client = client;
17368
- this._exceptionAutocaptureEnabled = options.enableExceptionAutocapture || false;
17369
- this._logger = _logger;
17370
- this._rateLimiter = new BucketedRateLimiter({
17371
- refillRate: 1,
17372
- bucketSize: 10,
17373
- refillInterval: 1e4,
17374
- _logger: this._logger
17375
- });
17376
- this.startAutocaptureIfEnabled();
17377
- }
17378
- static isPreviouslyCapturedError(x) {
17379
- return isObject2(x) && "__posthog_previously_captured_error" in x && true === x.__posthog_previously_captured_error;
17380
- }
17381
- static async buildEventMessage(error2, hint, distinctId, additionalProperties) {
17382
- const properties = {
17383
- ...additionalProperties
17384
- };
17385
- const exceptionProperties = this.errorPropertiesBuilder.buildFromUnknown(error2, hint);
17386
- exceptionProperties.$exception_list = await this.errorPropertiesBuilder.modifyFrames(exceptionProperties.$exception_list);
17387
- return {
17388
- event: "$exception",
17389
- distinctId,
17390
- properties: {
17391
- ...exceptionProperties,
17392
- ...properties
17393
- },
17394
- _originatedFromCaptureException: true
17395
- };
17396
- }
17397
- startAutocaptureIfEnabled() {
17398
- if (this.isEnabled()) {
17399
- addUncaughtExceptionListener(this.onException.bind(this), this.onFatalError.bind(this));
17400
- addUnhandledRejectionListener(this.onException.bind(this));
17401
- }
17402
- }
17403
- onException(exception, hint) {
17404
- this.client.addPendingPromise((async () => {
17405
- if (!_ErrorTracking.isPreviouslyCapturedError(exception)) {
17406
- const eventMessage = await _ErrorTracking.buildEventMessage(exception, hint);
17407
- const exceptionProperties = eventMessage.properties;
17408
- const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? "Exception";
17409
- const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType);
17410
- if (isRateLimited) return void this._logger.info("Skipping exception capture because of client rate limiting.", {
17411
- exception: exceptionType
17412
- });
17413
- return this.client.capture(eventMessage);
17414
- }
17415
- })());
17416
- }
17417
- async onFatalError(exception) {
17418
- console.error(exception);
17419
- await this.client.shutdown(SHUTDOWN_TIMEOUT);
17420
- process.exit(1);
17421
- }
17422
- isEnabled() {
17423
- return !this.client.isDisabled && this._exceptionAutocaptureEnabled;
17424
- }
17425
- shutdown() {
17426
- this._rateLimiter.stop();
17427
- }
17428
- };
17429
17203
 
17430
17204
  // ../../node_modules/posthog-node/dist/extensions/context/context.mjs
17431
17205
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -17494,19 +17268,6 @@ var PostHogSentryIntegration = class {
17494
17268
  }
17495
17269
  };
17496
17270
 
17497
- // ../../node_modules/posthog-node/dist/entrypoints/index.node.mjs
17498
- ErrorTracking.errorPropertiesBuilder = new error_tracking_exports.ErrorPropertiesBuilder([
17499
- new error_tracking_exports.EventCoercer(),
17500
- new error_tracking_exports.ErrorCoercer(),
17501
- new error_tracking_exports.ObjectCoercer(),
17502
- new error_tracking_exports.StringCoercer(),
17503
- new error_tracking_exports.PrimitiveCoercer()
17504
- ], error_tracking_exports.createStackParser("node:javascript", error_tracking_exports.nodeStackLineParser), [
17505
- createModulerModifier(),
17506
- addSourceContext,
17507
- createRelativePathModifier()
17508
- ]);
17509
-
17510
17271
  // ../registry/src/artifacts.ts
17511
17272
  import { stat as stat3 } from "node:fs/promises";
17512
17273
  import { randomUUID } from "node:crypto";
@@ -17741,7 +17502,7 @@ var FAILURE_SPAWN_CODE_SET = new Set(FAILURE_SPAWN_CODES);
17741
17502
  import { randomUUID as randomUUID2 } from "node:crypto";
17742
17503
 
17743
17504
  // ../telemetry/src/events.ts
17744
- var PLATFORMS = ["ios", "android", "chromium", "vega"];
17505
+ var PLATFORMS = ["ios", "ios-remote", "android", "chromium", "vega"];
17745
17506
 
17746
17507
  // ../telemetry/src/ai-identity.ts
17747
17508
  var AI_CLIENTS = [
@@ -17946,6 +17707,9 @@ var ALLOWED = {
17946
17707
  // ../telemetry/src/base-props.ts
17947
17708
  import { randomUUID as randomUUID3 } from "node:crypto";
17948
17709
 
17710
+ // ../telemetry/src/cloud-agent-detect.ts
17711
+ import { existsSync as existsSync2 } from "node:fs";
17712
+
17949
17713
  // ../../node_modules/ci-info/vendors.json
17950
17714
  var vendors_default = [
17951
17715
  {
@@ -18356,7 +18120,7 @@ function readConfigObject() {
18356
18120
  }
18357
18121
  return {};
18358
18122
  }
18359
- var LOCK_STALE_MS = 1e4;
18123
+ var LOCK_STALE_MS2 = 1e4;
18360
18124
  var LOCK_MAX_WAIT_MS = 2e3;
18361
18125
  var LOCK_RETRY_MS = 25;
18362
18126
  function sleepSync(ms) {
@@ -18377,7 +18141,7 @@ function acquireConfigLock() {
18377
18141
  } catch (err) {
18378
18142
  if (err.code !== "EEXIST") return null;
18379
18143
  try {
18380
- if (Date.now() - fs3.statSync(lockPath).mtimeMs > LOCK_STALE_MS) {
18144
+ if (Date.now() - fs3.statSync(lockPath).mtimeMs > LOCK_STALE_MS2) {
18381
18145
  fs3.unlinkSync(lockPath);
18382
18146
  continue;
18383
18147
  }
@@ -18546,9 +18310,16 @@ function imageBlock(data, mimeType) {
18546
18310
  }
18547
18311
  async function fetchPngBytes(url) {
18548
18312
  try {
18549
- const res = await fetch(url);
18550
- if (!res.ok) return null;
18551
- const buf = Buffer.from(await res.arrayBuffer());
18313
+ let buf;
18314
+ if (url.startsWith("file://")) {
18315
+ const { readFile: readFile6 } = await import("node:fs/promises");
18316
+ const { fileURLToPath } = await import("node:url");
18317
+ buf = await readFile6(fileURLToPath(url));
18318
+ } else {
18319
+ const res = await fetch(url);
18320
+ if (!res.ok) return null;
18321
+ buf = Buffer.from(await res.arrayBuffer());
18322
+ }
18552
18323
  if (buf.length < PNG_SIGNATURE.length) return null;
18553
18324
  if (!buf.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) return null;
18554
18325
  return buf;
@@ -18899,7 +18670,7 @@ async function startMcpServer(options) {
18899
18670
  async function spyLog(entry) {
18900
18671
  try {
18901
18672
  if (!logDirReady) {
18902
- await mkdir5(dirname4(LOG_FILE2), { recursive: true });
18673
+ await mkdir5(dirname3(LOG_FILE2), { recursive: true });
18903
18674
  logDirReady = true;
18904
18675
  }
18905
18676
  await appendFile(LOG_FILE2, JSON.stringify(entry) + "\n");