claude-discover 1.10.12 → 1.10.13

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.
package/out/main/main.js CHANGED
@@ -9,7 +9,7 @@ import { LAUNCH_MODES, launchMode } from "electron-update-from-npm/launch-mode";
9
9
  import fsp from "node:fs/promises";
10
10
  import { pathToFileURL } from "node:url";
11
11
  import { execFile } from "node:child_process";
12
- import { promisify } from "node:util";
12
+ import { promisify, stripVTControlCharacters } from "node:util";
13
13
  import windowStateKeeper from "electron-window-state";
14
14
  import process$1 from "node:process";
15
15
  import { FindOverlay } from "electron-find-overlay";
@@ -1037,6 +1037,14 @@ var SessionFile = class {
1037
1037
  return null;
1038
1038
  }
1039
1039
  }
1040
+ async agentMeta() {
1041
+ if (!this.parentSessionId) return null;
1042
+ try {
1043
+ return JSON.parse(await fsp.readFile(this.filePath.replace(/\.jsonl$/, ".meta.json"), "utf8"));
1044
+ } catch {
1045
+ return null;
1046
+ }
1047
+ }
1040
1048
  async stream(onLine) {
1041
1049
  let leftover = "";
1042
1050
  await new Promise((resolve) => {
@@ -1138,7 +1146,8 @@ var classifyRequest = (req, url) => {
1138
1146
  var isLoop = (kind) => !kind || [
1139
1147
  "main",
1140
1148
  "tools",
1141
- "agent"
1149
+ "agent",
1150
+ "compact"
1142
1151
  ].includes(kind[0]);
1143
1152
  var REMINDER_LABELS = [
1144
1153
  ["As you answer the user", "Session Context"],
@@ -1428,15 +1437,24 @@ var RequestFile = class {
1428
1437
  async readInstructions(range = null) {
1429
1438
  const parser = new RequestParser();
1430
1439
  const strips = [];
1440
+ const compacts = [];
1431
1441
  for (const rec of await this.read()) {
1432
1442
  if (!rec.request || rec.kind?.[0] === "count") continue;
1433
1443
  const found = parser.strips(rec);
1434
- if (!isLoop(rec.kind) && inRange(rec.timestamp, range)) strips.push(...found.map((f) => ({
1444
+ if (!inRange(rec.timestamp, range)) continue;
1445
+ if (rec.kind?.[0] === "compact" && rec.response?.usage) compacts.push({
1446
+ timestamp: rec.timestamp,
1447
+ usage: rec.response.usage
1448
+ });
1449
+ if (!isLoop(rec.kind)) strips.push(...found.map((f) => ({
1435
1450
  timestamp: rec.timestamp,
1436
1451
  ...f
1437
1452
  })));
1438
1453
  }
1439
- return strips;
1454
+ return {
1455
+ strips,
1456
+ compacts
1457
+ };
1440
1458
  }
1441
1459
  };
1442
1460
  // src/main/requests/TranscriptInstructions.js
@@ -1505,6 +1523,17 @@ var pickParts = (byModel, part) => Object.fromEntries(Object.entries(byModel).ma
1505
1523
  function addUsage(target, delta) {
1506
1524
  for (const k of TOKEN_FIELDS) target[k] += delta[k];
1507
1525
  }
1526
+ function usageOf(u) {
1527
+ const cc = u.cache_creation || {};
1528
+ return {
1529
+ input: u.input_tokens || 0,
1530
+ output: u.output_tokens || 0,
1531
+ cacheRead: u.cache_read_input_tokens || 0,
1532
+ cacheCreation: u.cache_creation_input_tokens || 0,
1533
+ cacheCreation5m: cc.ephemeral_5m_input_tokens || 0,
1534
+ cacheCreation1h: cc.ephemeral_1h_input_tokens || 0
1535
+ };
1536
+ }
1508
1537
  var CACHE_TTL_MS = {
1509
1538
  "5m": 3e5,
1510
1539
  "1h": 36e5
@@ -1605,6 +1634,7 @@ function freshMetrics() {
1605
1634
  tokensByModel: {},
1606
1635
  tokensByModelFast: {},
1607
1636
  lastContextTokens: 0,
1637
+ contextCompacted: false,
1608
1638
  serverToolUse: {
1609
1639
  webSearch: 0,
1610
1640
  webFetch: 0
@@ -1668,6 +1698,8 @@ var SessionParser = class {
1668
1698
  if (this.range && (ts < this.range.start || ts > this.range.end)) {
1669
1699
  if (inherited != null && ts < this.range.start && ts > meta.continuesFrom) meta.continuesFrom = ts;
1670
1700
  if (inherited != null && ts > this.range.end && (meta.continuesTo == null || ts < meta.continuesTo)) meta.continuesTo = ts;
1701
+ const msg = obj.message;
1702
+ if (ts < this.range.start && msg?.usage && msg.id) this._growth(msg.id, usageOf(msg.usage));
1671
1703
  return false;
1672
1704
  }
1673
1705
  obj._ts = ts;
@@ -1682,6 +1714,10 @@ var SessionParser = class {
1682
1714
  }
1683
1715
  this.seenUuids.add(obj.uuid);
1684
1716
  }
1717
+ if (obj.subtype === "compact_boundary" && obj.compactMetadata?.postTokens) {
1718
+ meta.lastContextTokens = obj.compactMetadata.postTokens;
1719
+ meta.contextCompacted = true;
1720
+ }
1685
1721
  if (t === "attachment") {
1686
1722
  obj.isMeta = true;
1687
1723
  return true;
@@ -1761,15 +1797,7 @@ var SessionParser = class {
1761
1797
  const u = msg?.usage;
1762
1798
  const msgId = msg?.id;
1763
1799
  if (!u || !msgId) return;
1764
- const cc = u.cache_creation || {};
1765
- const usage = {
1766
- input: u.input_tokens || 0,
1767
- output: u.output_tokens || 0,
1768
- cacheRead: u.cache_read_input_tokens || 0,
1769
- cacheCreation: u.cache_creation_input_tokens || 0,
1770
- cacheCreation5m: cc.ephemeral_5m_input_tokens || 0,
1771
- cacheCreation1h: cc.ephemeral_1h_input_tokens || 0
1772
- };
1800
+ const usage = usageOf(u);
1773
1801
  const model = msg.model || "unknown";
1774
1802
  const fast = u.speed === "fast";
1775
1803
  const contextSize = usage.input + usage.cacheRead + usage.cacheCreation;
@@ -1778,8 +1806,7 @@ var SessionParser = class {
1778
1806
  this._stampRunningTotals(obj, contextSize, usage.output);
1779
1807
  }
1780
1808
  if (this.excludeIds?.has(msgId)) return;
1781
- const applied = this.appliedById.get(msgId);
1782
- if (!applied) {
1809
+ if (!this.appliedById.has(msgId)) {
1783
1810
  const sentAt = this.prevMessage?.type === "user" ? Math.min(this.prevMessage._ts, obj._ts) : obj._ts;
1784
1811
  this.calls.push({
1785
1812
  ts: sentAt,
@@ -1788,6 +1815,7 @@ var SessionParser = class {
1788
1815
  usage
1789
1816
  });
1790
1817
  meta.lastContextTokens = contextSize;
1818
+ meta.contextCompacted = false;
1791
1819
  if (u.service_tier) meta.serviceTier = u.service_tier;
1792
1820
  if (this.pricing && this.pricing.priceFor(model) == null) meta.priceUnknown = true;
1793
1821
  if (fast) {
@@ -1799,15 +1827,8 @@ var SessionParser = class {
1799
1827
  meta.serverToolUse.webFetch += u.server_tool_use.web_fetch_requests || 0;
1800
1828
  }
1801
1829
  }
1802
- const growth = emptyBucket();
1803
- let changed = false;
1804
- for (const k of TOKEN_FIELDS) {
1805
- growth[k] = Math.max(0, usage[k] - (applied?.[k] ?? 0));
1806
- if (growth[k] !== 0) changed = true;
1807
- }
1808
- if (applied) addUsage(applied, growth);
1809
- else this.appliedById.set(msgId, usage);
1810
- if (!changed) return;
1830
+ const growth = this._growth(msgId, usage);
1831
+ if (TOKEN_FIELDS.every((k) => !growth[k])) return;
1811
1832
  const byModel = fast ? meta.tokensByModelFast : meta.tokensByModel;
1812
1833
  addUsage(meta.tokens, growth);
1813
1834
  addUsage(byModel[model] ??= emptyBucket(), growth);
@@ -1823,10 +1844,24 @@ var SessionParser = class {
1823
1844
  });
1824
1845
  }
1825
1846
  }
1847
+ _growth(msgId, usage) {
1848
+ const applied = this.appliedById.get(msgId);
1849
+ if (!applied) {
1850
+ this.appliedById.set(msgId, usage);
1851
+ return usage;
1852
+ }
1853
+ const growth = Object.fromEntries(TOKEN_FIELDS.map((k) => [k, Math.max(0, usage[k] - applied[k])]));
1854
+ addUsage(applied, growth);
1855
+ return growth;
1856
+ }
1826
1857
  finalize(mtimeFallback) {
1827
1858
  const meta = this.meta;
1828
1859
  if (meta.startedAt == null) meta.startedAt = mtimeFallback;
1829
1860
  if (meta.lastActivityAt == null) meta.lastActivityAt = mtimeFallback;
1861
+ if (!meta.models.length && this.modelId) {
1862
+ meta.model = this.modelId;
1863
+ meta.models.push(this.modelId);
1864
+ }
1830
1865
  meta.source = classifySource(meta);
1831
1866
  meta.activeMs = meta.activityPeriods.reduce((sum, p) => sum + Math.max(0, p.end - p.start), 0);
1832
1867
  const t = meta.tokens;
@@ -2522,7 +2557,10 @@ var SessionsService = class extends EventEmitter {
2522
2557
  await reader.stream((obj) => {
2523
2558
  if (feed(obj, parser.feed(obj))) items.push(obj);
2524
2559
  });
2525
- const side = [...await sides, ...source.side.filter((s) => inRange(s.timestamp, range))];
2560
+ const own = await sides;
2561
+ const shown = (list) => list.filter((s) => inRange(s.timestamp, range));
2562
+ const side = [...own.strips, ...shown(source.side)];
2563
+ const compacts = [...shown(source.compacts), ...own.compacts];
2526
2564
  if (start?.length && !loop.includes(start[0])) loop.unshift(...start);
2527
2565
  items.sort((a, b) => a._ts - b._ts);
2528
2566
  const keys = new Set(loop.map((s) => s.hash));
@@ -2534,7 +2572,8 @@ var SessionsService = class extends EventEmitter {
2534
2572
  items,
2535
2573
  instructions: {
2536
2574
  loop,
2537
- side
2575
+ side,
2576
+ compacts
2538
2577
  },
2539
2578
  requestLog: await requests.exists() ? requests.filePath : null
2540
2579
  };
@@ -2542,7 +2581,8 @@ var SessionsService = class extends EventEmitter {
2542
2581
  #branchSource({ filePath, forkedFrom, forkedAt }) {
2543
2582
  if (!forkedFrom) return {
2544
2583
  records: [],
2545
- side: []
2584
+ side: [],
2585
+ compacts: []
2546
2586
  };
2547
2587
  const key = `${filePath} ${forkedAt}`;
2548
2588
  if (this.#branch?.key !== key) this.#branch = {
@@ -2553,7 +2593,7 @@ var SessionsService = class extends EventEmitter {
2553
2593
  }
2554
2594
  async #readBranchSource(filePath, sessionId, at) {
2555
2595
  const records = [];
2556
- const [side] = await Promise.all([new RequestFile(sessionId).readInstructions({
2596
+ const [{ strips: side, compacts }] = await Promise.all([new RequestFile(sessionId).readInstructions({
2557
2597
  start: 0,
2558
2598
  end: at
2559
2599
  }), new SessionFile(path.join(path.dirname(filePath), `${sessionId}.jsonl`)).stream((obj) => {
@@ -2561,7 +2601,8 @@ var SessionsService = class extends EventEmitter {
2561
2601
  })]);
2562
2602
  return {
2563
2603
  records: records.slice(0, records.findLastIndex((o) => o.type === "api-request" && Date.parse(o.timestamp) <= at) + 1),
2564
- side
2604
+ side,
2605
+ compacts
2565
2606
  };
2566
2607
  }
2567
2608
  async readRequests(filePath, date = null, granularity = "day") {
@@ -2657,7 +2698,13 @@ var SessionsService = class extends EventEmitter {
2657
2698
  });
2658
2699
  await reader.stream((obj) => parser.feed(obj));
2659
2700
  const meta = parser.finalize(stat.mtimeMs);
2660
- const [project, avatar] = await Promise.all([this.projects.resolve(meta.project), this.projects.avatar(meta.project)]);
2701
+ const [project, avatar, agent] = await Promise.all([
2702
+ this.projects.resolve(meta.project),
2703
+ this.projects.avatar(meta.project),
2704
+ reader.agentMeta()
2705
+ ]);
2706
+ meta.agentName ??= agent?.name ?? agent?.agentType ?? null;
2707
+ meta.agentDescription = agent?.description ?? null;
2661
2708
  return Object.assign(meta, project, { avatar });
2662
2709
  }
2663
2710
  async _dedupSessions(metas, range) {
@@ -2873,7 +2920,10 @@ var AgentRunner = class {
2873
2920
  settingSources: []
2874
2921
  }
2875
2922
  });
2876
- return withTimeout(q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true }), USAGE_TIMEOUT, () => q.close());
2923
+ return withTimeout(Promise.all([q.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true }), q.accountInfo()]).then(([usage, account]) => ({
2924
+ ...usage,
2925
+ account
2926
+ })), USAGE_TIMEOUT, () => q.close());
2877
2927
  }
2878
2928
  };
2879
2929
  // node_modules/isexe/dist/commonjs/index.min.js
@@ -3527,10 +3577,10 @@ var RateLimits = class {
3527
3577
  }
3528
3578
  async #fetch() {
3529
3579
  try {
3530
- const { subscription_type: plan, rate_limits: rl } = await this.#agentRunner.usage();
3580
+ const { subscription_type: type, account, rate_limits: rl } = await this.#agentRunner.usage();
3531
3581
  return rl && {
3532
3582
  at: Date.now(),
3533
- plan,
3583
+ plan: account?.subscriptionType?.replace(/^Claude /, "") ?? type,
3534
3584
  fiveHour: toWindow(rl.five_hour),
3535
3585
  sevenDay: toWindow(rl.seven_day),
3536
3586
  models: (rl.model_scoped ?? []).filter((m) => m.utilization != null).map((m) => ({
@@ -3551,9 +3601,13 @@ var RateLimits = class {
3551
3601
  };
3552
3602
  // node_modules/ansi-styles/index.js
3553
3603
  var ANSI_BACKGROUND_OFFSET = 10;
3554
- var wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
3555
- var wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
3556
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
3604
+ var ANSI_UNDERLINE_OFFSET = 20;
3605
+ var wrapAnsi16 = (offset = 0) => (code) => `\u{1B}[${code + offset}m`;
3606
+ var wrapAnsi256 = (offset = 0) => (code) => `\u{1B}[${38 + offset};5;${code}m`;
3607
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u{1B}[${38 + offset};2;${red};${green};${blue}m`;
3608
+ var wrapUnderlineAnsi = (code) => `\u{1B}[58;5;${code < 90 ? code - 30 : code - 90 + 8}m`;
3609
+ var blackBright = [90, 39];
3610
+ var bgBlackBright = [100, 49];
3557
3611
  var styles = {
3558
3612
  modifier: {
3559
3613
  reset: [0, 0],
@@ -3561,6 +3615,10 @@ var styles = {
3561
3615
  dim: [2, 22],
3562
3616
  italic: [3, 23],
3563
3617
  underline: [4, 24],
3618
+ underlineDouble: ["4:2", 24],
3619
+ underlineCurly: ["4:3", 24],
3620
+ underlineDotted: ["4:4", 24],
3621
+ underlineDashed: ["4:5", 24],
3564
3622
  overline: [53, 55],
3565
3623
  inverse: [7, 27],
3566
3624
  hidden: [8, 28],
@@ -3575,9 +3633,9 @@ var styles = {
3575
3633
  magenta: [35, 39],
3576
3634
  cyan: [36, 39],
3577
3635
  white: [37, 39],
3578
- blackBright: [90, 39],
3579
- gray: [90, 39],
3580
- grey: [90, 39],
3636
+ blackBright,
3637
+ gray: blackBright,
3638
+ grey: blackBright,
3581
3639
  redBright: [91, 39],
3582
3640
  greenBright: [92, 39],
3583
3641
  yellowBright: [93, 39],
@@ -3595,9 +3653,9 @@ var styles = {
3595
3653
  bgMagenta: [45, 49],
3596
3654
  bgCyan: [46, 49],
3597
3655
  bgWhite: [47, 49],
3598
- bgBlackBright: [100, 49],
3599
- bgGray: [100, 49],
3600
- bgGrey: [100, 49],
3656
+ bgBlackBright,
3657
+ bgGray: bgBlackBright,
3658
+ bgGrey: bgBlackBright,
3601
3659
  bgRedBright: [101, 49],
3602
3660
  bgGreenBright: [102, 49],
3603
3661
  bgYellowBright: [103, 49],
@@ -3605,22 +3663,43 @@ var styles = {
3605
3663
  bgMagentaBright: [105, 49],
3606
3664
  bgCyanBright: [106, 49],
3607
3665
  bgWhiteBright: [107, 49]
3666
+ },
3667
+ underlineColor: {
3668
+ underlineBlack: ["58;5;0", 59],
3669
+ underlineRed: ["58;5;1", 59],
3670
+ underlineGreen: ["58;5;2", 59],
3671
+ underlineYellow: ["58;5;3", 59],
3672
+ underlineBlue: ["58;5;4", 59],
3673
+ underlineMagenta: ["58;5;5", 59],
3674
+ underlineCyan: ["58;5;6", 59],
3675
+ underlineWhite: ["58;5;7", 59],
3676
+ underlineBlackBright: ["58;5;8", 59],
3677
+ underlineGray: ["58;5;8", 59],
3678
+ underlineGrey: ["58;5;8", 59],
3679
+ underlineRedBright: ["58;5;9", 59],
3680
+ underlineGreenBright: ["58;5;10", 59],
3681
+ underlineYellowBright: ["58;5;11", 59],
3682
+ underlineBlueBright: ["58;5;12", 59],
3683
+ underlineMagentaBright: ["58;5;13", 59],
3684
+ underlineCyanBright: ["58;5;14", 59],
3685
+ underlineWhiteBright: ["58;5;15", 59]
3608
3686
  }
3609
3687
  };
3610
3688
  Object.keys(styles.modifier);
3611
3689
  var foregroundColorNames = Object.keys(styles.color);
3612
3690
  var backgroundColorNames = Object.keys(styles.bgColor);
3691
+ Object.keys(styles.underlineColor);
3613
3692
  [...foregroundColorNames, ...backgroundColorNames];
3614
3693
  function assembleStyles() {
3615
3694
  const codes = /* @__PURE__ */ new Map();
3616
3695
  for (const [groupName, group] of Object.entries(styles)) {
3617
3696
  for (const [styleName, style] of Object.entries(group)) {
3618
3697
  styles[styleName] = {
3619
- open: `\u001B[${style[0]}m`,
3620
- close: `\u001B[${style[1]}m`
3698
+ open: `\u{1B}[${style[0]}m`,
3699
+ close: `\u{1B}[${style[1]}m`
3621
3700
  };
3622
3701
  group[styleName] = styles[styleName];
3623
- codes.set(style[0], style[1]);
3702
+ codes.set(Number(String(style[0]).split(/[:;]/v, 1)[0]), style[1]);
3624
3703
  }
3625
3704
  Object.defineProperty(styles, groupName, {
3626
3705
  value: group,
@@ -3633,12 +3712,16 @@ function assembleStyles() {
3633
3712
  });
3634
3713
  styles.color.close = "\x1B[39m";
3635
3714
  styles.bgColor.close = "\x1B[49m";
3715
+ styles.underlineColor.close = "\x1B[59m";
3636
3716
  styles.color.ansi = wrapAnsi16();
3637
3717
  styles.color.ansi256 = wrapAnsi256();
3638
3718
  styles.color.ansi16m = wrapAnsi16m();
3639
3719
  styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
3640
3720
  styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
3641
3721
  styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
3722
+ styles.underlineColor.ansi = wrapUnderlineAnsi;
3723
+ styles.underlineColor.ansi256 = wrapAnsi256(ANSI_UNDERLINE_OFFSET);
3724
+ styles.underlineColor.ansi16m = wrapAnsi16m(ANSI_UNDERLINE_OFFSET);
3642
3725
  Object.defineProperties(styles, {
3643
3726
  rgbToAnsi256: {
3644
3727
  value(red, green, blue) {
@@ -3653,7 +3736,7 @@ function assembleStyles() {
3653
3736
  },
3654
3737
  hexToRgb: {
3655
3738
  value(hex) {
3656
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
3739
+ const matches = /[\da-f]{6}|[\da-f]{3}/iv.exec(hex.toString(16));
3657
3740
  if (!matches) return [
3658
3741
  0,
3659
3742
  0,
@@ -3712,6 +3795,21 @@ function assembleStyles() {
3712
3795
  return styles;
3713
3796
  }
3714
3797
  var ansiStyles = assembleStyles();
3798
+ // node_modules/ansi-regex/index.js
3799
+ function ansiRegex({ onlyFirst = false } = {}) {
3800
+ const ST = String.raw`(?:\u0007|\u001B\u005C|\u009C)`;
3801
+ const osc = String.raw`(?:(?:\u001B\]|\u009D)[^\u0007\u001B\u009C\u009D]*${ST})`;
3802
+ const csi = String.raw`[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[A-PR-TZcf-nq-uy=><~]`;
3803
+ const pattern = `${osc}|${String.raw`(?:\u001B\[|\u009B)[<=>][0-9;:]*[A-PR-TZcf-nq-uy~]`}|${csi}`;
3804
+ return new RegExp(pattern, onlyFirst ? void 0 : "g");
3805
+ }
3806
+ // node_modules/strip-ansi/index.js
3807
+ var regex = ansiRegex();
3808
+ function stripAnsi(string) {
3809
+ if (typeof string !== "string") throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
3810
+ if (!string.includes("\x1B") && !string.includes("›")) return string;
3811
+ return string.replace(regex, "");
3812
+ }
3715
3813
  var ambiguousRanges = [
3716
3814
  161,
3717
3815
  161,
@@ -4391,10 +4489,111 @@ function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
4391
4489
  if (isFullwidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
4392
4490
  return 1;
4393
4491
  }
4394
- // node_modules/is-fullwidth-code-point/index.js
4395
- function isFullwidthCodePoint(codePoint) {
4396
- if (!Number.isInteger(codePoint)) return false;
4397
- return isFullwidth(codePoint) || isWide(codePoint);
4492
+ // node_modules/string-width/index.js
4493
+ /**
4494
+ Logic:
4495
+ - Segment graphemes to match how terminals render clusters.
4496
+ - Width rules:
4497
+ 1. Skip non-printing clusters (Default_Ignorable, Control, pure nonspacing/enclosing Mark, lone Surrogates). Tabs are ignored by design.
4498
+ 2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
4499
+ 3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
4500
+ 4. Hangul jamo collapse each standard modern Hangul L+V or L+V+T syllable piece to width 2.
4501
+ Unmatched repeated leading/vowel/trailing jamo stay additive because that matches how the terminals we target render them.
4502
+ 5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing spacing marks and Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
4503
+ */
4504
+ var segmenter = new Intl.Segmenter();
4505
+ var visibleCharacterRegex = /[^\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]/v;
4506
+ var spacingMarkRegex = /\p{Spacing_Mark}/v;
4507
+ var rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
4508
+ var unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
4509
+ var extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
4510
+ function isDoubleWidthNonRgiEmojiSequence(segment) {
4511
+ if (segment.length > 50) return false;
4512
+ if (unqualifiedKeycapRegex.test(segment)) return true;
4513
+ if (segment.includes("‍")) {
4514
+ const pictographics = segment.match(extendedPictographicRegex);
4515
+ return pictographics !== null && pictographics.length >= 2;
4516
+ }
4517
+ return false;
4518
+ }
4519
+ function baseVisible(segment) {
4520
+ const index = segment.search(visibleCharacterRegex);
4521
+ return index === -1 ? void 0 : segment.slice(index);
4522
+ }
4523
+ function isHangulLeadingJamo(codePoint) {
4524
+ return codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388;
4525
+ }
4526
+ function isHangulVowelJamo(codePoint) {
4527
+ return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
4528
+ }
4529
+ function isHangulTrailingJamo(codePoint) {
4530
+ return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
4531
+ }
4532
+ function isHangulJamo(codePoint) {
4533
+ return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
4534
+ }
4535
+ function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
4536
+ const codePoints = [];
4537
+ for (const character of visibleSegment) {
4538
+ if (!visibleCharacterRegex.test(character)) continue;
4539
+ codePoints.push(character.codePointAt(0));
4540
+ }
4541
+ if (codePoints.length === 0) return;
4542
+ let width = 0;
4543
+ for (let index = 0; index < codePoints.length; index++) {
4544
+ const codePoint = codePoints[index];
4545
+ if (!isHangulJamo(codePoint)) {
4546
+ if (width === 0) return;
4547
+ for (let remaining = index; remaining < codePoints.length; remaining++) width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
4548
+ return width;
4549
+ }
4550
+ if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index + 1])) {
4551
+ width += 2;
4552
+ index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
4553
+ continue;
4554
+ }
4555
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
4556
+ }
4557
+ return width;
4558
+ }
4559
+ function trailingWidth(visibleSegment, eastAsianWidthOptions) {
4560
+ let extra = 0;
4561
+ let first = true;
4562
+ for (const character of visibleSegment) {
4563
+ if (first) {
4564
+ first = false;
4565
+ continue;
4566
+ }
4567
+ if (spacingMarkRegex.test(character) || character >= "＀" && character <= "￯") extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
4568
+ }
4569
+ return extra;
4570
+ }
4571
+ function stringWidth(input, options = {}) {
4572
+ if (typeof input !== "string" || input.length === 0) return 0;
4573
+ const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
4574
+ let string = input;
4575
+ if (!countAnsiEscapeCodes && (string.includes("\x1B") || string.includes("›"))) string = stripAnsi(string);
4576
+ if (string.length === 0) return 0;
4577
+ if (/^[\u0020-\u007E]*$/.test(string)) return string.length;
4578
+ let width = 0;
4579
+ const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
4580
+ for (const { segment } of segmenter.segment(string)) {
4581
+ const visibleSegment = baseVisible(segment);
4582
+ if (visibleSegment === void 0) continue;
4583
+ if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
4584
+ width += 2;
4585
+ continue;
4586
+ }
4587
+ const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
4588
+ if (hangulWidth !== void 0) {
4589
+ width += hangulWidth;
4590
+ continue;
4591
+ }
4592
+ const codePoint = visibleSegment.codePointAt(0);
4593
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
4594
+ width += trailingWidth(visibleSegment, eastAsianWidthOptions);
4595
+ }
4596
+ return width;
4398
4597
  }
4399
4598
  // node_modules/slice-ansi/tokenize-ansi.js
4400
4599
  var ESCAPE_CODE_POINT = 27;
@@ -4442,8 +4641,6 @@ var CODE_POINT_CSI_INTERMEDIATE_START = " ".codePointAt(0);
4442
4641
  var CODE_POINT_CSI_INTERMEDIATE_END = "/".codePointAt(0);
4443
4642
  var CODE_POINT_CSI_FINAL_START = "@".codePointAt(0);
4444
4643
  var CODE_POINT_CSI_FINAL_END = "~".codePointAt(0);
4445
- var REGIONAL_INDICATOR_SYMBOL_LETTER_A = 127462;
4446
- var REGIONAL_INDICATOR_SYMBOL_LETTER_Z = 127487;
4447
4644
  var SGR_RESET_CODE = 0;
4448
4645
  var SGR_EXTENDED_FOREGROUND_CODE = 38;
4449
4646
  var SGR_DEFAULT_FOREGROUND_CODE = 39;
@@ -4455,9 +4652,6 @@ var SGR_ANSI_256_FRAGMENT_LENGTH = 3;
4455
4652
  var SGR_TRUECOLOR_FRAGMENT_LENGTH = 5;
4456
4653
  var SGR_ANSI_256_LAST_PARAMETER_OFFSET = 2;
4457
4654
  var SGR_TRUECOLOR_LAST_PARAMETER_OFFSET = 4;
4458
- var VARIATION_SELECTOR_16_CODE_POINT = 65039;
4459
- var COMBINING_ENCLOSING_KEYCAP_CODE_POINT = 8419;
4460
- var EMOJI_PRESENTATION_GRAPHEME_REGEX = /\p{Emoji_Presentation}/v;
4461
4655
  var GRAPHEME_SEGMENTER = new Intl.Segmenter(void 0, { granularity: "grapheme" });
4462
4656
  var endCodeNumbers = /* @__PURE__ */ new Set();
4463
4657
  for (const [, end] of ansiStyles.codes) endCodeNumbers.add(end);
@@ -4473,9 +4667,6 @@ function isCsiIntermediateCharacter(codePoint) {
4473
4667
  function isCsiFinalCharacter(codePoint) {
4474
4668
  return codePoint >= CODE_POINT_CSI_FINAL_START && codePoint <= CODE_POINT_CSI_FINAL_END;
4475
4669
  }
4476
- function isRegionalIndicatorCodePoint(codePoint) {
4477
- return codePoint >= REGIONAL_INDICATOR_SYMBOL_LETTER_A && codePoint <= REGIONAL_INDICATOR_SYMBOL_LETTER_Z;
4478
- }
4479
4670
  function createControlParseResult(code, endIndex) {
4480
4671
  return {
4481
4672
  token: {
@@ -4485,28 +4676,8 @@ function createControlParseResult(code, endIndex) {
4485
4676
  endIndex
4486
4677
  };
4487
4678
  }
4488
- function isEmojiStyleGrapheme(grapheme) {
4489
- if (EMOJI_PRESENTATION_GRAPHEME_REGEX.test(grapheme)) return true;
4490
- for (const character of grapheme) {
4491
- const codePoint = character.codePointAt(0);
4492
- if (codePoint === VARIATION_SELECTOR_16_CODE_POINT || codePoint === COMBINING_ENCLOSING_KEYCAP_CODE_POINT) return true;
4493
- }
4494
- return false;
4495
- }
4496
- function getGraphemeWidth(grapheme) {
4497
- let regionalIndicatorCount = 0;
4498
- for (const character of grapheme) {
4499
- const codePoint = character.codePointAt(0);
4500
- if (isFullwidthCodePoint(codePoint)) return 2;
4501
- if (isRegionalIndicatorCodePoint(codePoint)) regionalIndicatorCount++;
4502
- }
4503
- if (regionalIndicatorCount >= 1) return 2;
4504
- if (isEmojiStyleGrapheme(grapheme)) return 2;
4505
- return 1;
4506
- }
4507
4679
  function getSgrPrefix(code) {
4508
- if (code.startsWith("›")) return "›";
4509
- return `${ESCAPE}${ANSI_CSI}`;
4680
+ return code.startsWith("›") ? "›" : `${ESCAPE}${ANSI_CSI}`;
4510
4681
  }
4511
4682
  function createSgrCode(prefix, values) {
4512
4683
  return `${prefix}${values.join(";")}${ANSI_SGR_TERMINATOR}`;
@@ -4605,7 +4776,7 @@ function parseCsiCode(string, index) {
4605
4776
  const codePoint = string.codePointAt(sequenceIndex);
4606
4777
  if (isCsiFinalCharacter(codePoint)) {
4607
4778
  const code = string.slice(index, sequenceIndex + 1);
4608
- if (string[sequenceIndex] !== ANSI_SGR_TERMINATOR || !hasCanonicalSgrParameters) return createControlParseResult(code, sequenceIndex + 1);
4779
+ if (!hasCanonicalSgrParameters || string[sequenceIndex] !== ANSI_SGR_TERMINATOR) return createControlParseResult(code, sequenceIndex + 1);
4609
4780
  return {
4610
4781
  token: {
4611
4782
  type: "sgr",
@@ -4679,13 +4850,13 @@ function parseHyperlinkCode(string, index) {
4679
4850
  function parseControlStringCode(string, index) {
4680
4851
  const codePoint = string.codePointAt(index);
4681
4852
  let sequenceStartIndex;
4682
- let supportsBellTerminator = false;
4853
+ let isBellTerminatorSupported = false;
4683
4854
  switch (codePoint) {
4684
4855
  case ESCAPE_CODE_POINT:
4685
4856
  switch (string[index + 1]) {
4686
4857
  case ANSI_OSC:
4687
4858
  sequenceStartIndex = index + 2;
4688
- supportsBellTerminator = true;
4859
+ isBellTerminatorSupported = true;
4689
4860
  break;
4690
4861
  case ANSI_DCS:
4691
4862
  case ANSI_SOS:
@@ -4699,7 +4870,7 @@ function parseControlStringCode(string, index) {
4699
4870
  break;
4700
4871
  case C1_OSC_CODE_POINT:
4701
4872
  sequenceStartIndex = index + 1;
4702
- supportsBellTerminator = true;
4873
+ isBellTerminatorSupported = true;
4703
4874
  break;
4704
4875
  case C1_DCS_CODE_POINT:
4705
4876
  case C1_SOS_CODE_POINT:
@@ -4711,7 +4882,7 @@ function parseControlStringCode(string, index) {
4711
4882
  default: return;
4712
4883
  }
4713
4884
  for (let sequenceIndex = sequenceStartIndex; sequenceIndex < string.length; sequenceIndex++) {
4714
- if (supportsBellTerminator && string[sequenceIndex] === ANSI_BELL) return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
4885
+ if (isBellTerminatorSupported && string[sequenceIndex] === ANSI_BELL) return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
4715
4886
  if (string[sequenceIndex] === ESCAPE && string[sequenceIndex + 1] === ANSI_OSC_TERMINATOR) return createControlParseResult(string.slice(index, sequenceIndex + 2), sequenceIndex + 2);
4716
4887
  if (string[sequenceIndex] === C1_STRING_TERMINATOR) return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
4717
4888
  }
@@ -4723,9 +4894,7 @@ function parseAnsiCode(string, index) {
4723
4894
  const hyperlinkCode = parseHyperlinkCode(string, index);
4724
4895
  if (hyperlinkCode) return hyperlinkCode;
4725
4896
  }
4726
- const controlStringCode = parseControlStringCode(string, index);
4727
- if (controlStringCode) return controlStringCode;
4728
- return parseCsiCode(string, index);
4897
+ return parseControlStringCode(string, index) || parseCsiCode(string, index);
4729
4898
  }
4730
4899
  function appendTrailingAnsiTokens(string, index, tokens) {
4731
4900
  while (index < string.length) {
@@ -4745,7 +4914,7 @@ function parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments)
4745
4914
  token: {
4746
4915
  type: "character",
4747
4916
  value: segment.segment,
4748
- visibleWidth: getGraphemeWidth(segment.segment),
4917
+ visibleWidth: stringWidth(segment.segment),
4749
4918
  isGraphemeContinuation: false
4750
4919
  },
4751
4920
  endIndex: index + segment.segment.length
@@ -4788,7 +4957,7 @@ function applyGraphemeMetadata(visibleCharacters) {
4788
4957
  let graphemeIndex = scalarIndex;
4789
4958
  let isFirstInGrapheme = true;
4790
4959
  while (graphemeIndex < visibleCharacters.length && scalarOffsets[graphemeIndex] < segment.index + segment.segment.length) {
4791
- visibleCharacters[graphemeIndex].visibleWidth = isFirstInGrapheme ? getGraphemeWidth(segment.segment) : 0;
4960
+ visibleCharacters[graphemeIndex].visibleWidth = isFirstInGrapheme ? stringWidth(segment.segment) : 0;
4792
4961
  visibleCharacters[graphemeIndex].isGraphemeContinuation = !isFirstInGrapheme;
4793
4962
  isFirstInGrapheme = false;
4794
4963
  graphemeIndex++;
@@ -4796,7 +4965,7 @@ function applyGraphemeMetadata(visibleCharacters) {
4796
4965
  scalarIndex = graphemeIndex;
4797
4966
  }
4798
4967
  }
4799
- function tokenizeAnsiWithVisibleSegmentation(string, { endCharacter = Number.POSITIVE_INFINITY } = {}) {
4968
+ function tokenizeAnsiWithVisibleSegmentation(string, { endCharacter = Infinity } = {}) {
4800
4969
  const tokens = [];
4801
4970
  const visibleCharacters = collectVisibleCharacters(string);
4802
4971
  applyGraphemeMetadata(visibleCharacters);
@@ -4815,24 +4984,21 @@ function tokenizeAnsiWithVisibleSegmentation(string, { endCharacter = Number.POS
4815
4984
  }
4816
4985
  const value = String.fromCodePoint(codePoint);
4817
4986
  const visibleCharacter = visibleCharacters[visibleCharacterIndex];
4818
- let visibleWidth = isFullwidthCodePoint(codePoint) ? 2 : value.length;
4819
- if (visibleCharacter) visibleWidth = visibleCharacter.visibleWidth;
4820
4987
  const token = {
4821
4988
  type: "character",
4822
4989
  value,
4823
- visibleWidth,
4824
- isGraphemeContinuation: visibleCharacter ? visibleCharacter.isGraphemeContinuation : false
4990
+ visibleWidth: visibleCharacter.visibleWidth,
4991
+ isGraphemeContinuation: visibleCharacter.isGraphemeContinuation
4825
4992
  };
4826
4993
  tokens.push(token);
4827
4994
  index += value.length;
4828
4995
  visibleCharacterIndex++;
4829
4996
  visibleCount += token.visibleWidth;
4830
- if (visibleCount >= endCharacter) {
4831
- const nextVisibleCharacter = visibleCharacters[visibleCharacterIndex];
4832
- if (!nextVisibleCharacter || !nextVisibleCharacter.isGraphemeContinuation) {
4833
- index = appendTrailingAnsiTokens(string, index, tokens);
4834
- break;
4835
- }
4997
+ if (visibleCount < endCharacter) continue;
4998
+ const nextVisibleCharacter = visibleCharacters[visibleCharacterIndex];
4999
+ if (!nextVisibleCharacter || !nextVisibleCharacter.isGraphemeContinuation) {
5000
+ index = appendTrailingAnsiTokens(string, index, tokens);
5001
+ break;
4836
5002
  }
4837
5003
  }
4838
5004
  return tokens;
@@ -4862,12 +5028,11 @@ function hasAnsiSplitContinuationAhead(string, startIndex, previousVisibleValue,
4862
5028
  }
4863
5029
  if (!hasAnsiCode) return false;
4864
5030
  const characterToken = parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments);
4865
- if (!characterToken) return true;
4866
- return areValuesInSameGrapheme(previousVisibleValue, characterToken.token.value);
5031
+ return characterToken ? areValuesInSameGrapheme(previousVisibleValue, characterToken.token.value) : true;
4867
5032
  }
4868
5033
  return false;
4869
5034
  }
4870
- function tokenizeAnsi(string, { endCharacter = Number.POSITIVE_INFINITY } = {}) {
5035
+ function tokenizeAnsi(string, { endCharacter = Infinity } = {}) {
4871
5036
  const tokens = [];
4872
5037
  const graphemeSegments = GRAPHEME_SEGMENTER.segment(string);
4873
5038
  let index = 0;
@@ -5003,22 +5168,22 @@ function applyCharacterToken(state) {
5003
5168
  }
5004
5169
  state.position += state.token.visibleWidth;
5005
5170
  }
5006
- var tokenHandlers = {
5007
- sgr: applySgrToken,
5008
- hyperlink: applyHyperlinkToken,
5009
- control: applyControlToken,
5010
- character: applyCharacterToken
5011
- };
5171
+ var tokenHandlers = /* @__PURE__ */ new Map([
5172
+ ["sgr", applySgrToken],
5173
+ ["hyperlink", applyHyperlinkToken],
5174
+ ["control", applyControlToken],
5175
+ ["character", applyCharacterToken]
5176
+ ]);
5012
5177
  function applyToken(state) {
5013
- tokenHandlers[state.token.type]?.(state);
5178
+ tokenHandlers.get(state.token.type)?.(state);
5014
5179
  }
5015
5180
  function createHasContinuationAheadMap(tokens) {
5016
5181
  const hasContinuationAhead = Array.from({ length: tokens.length }, () => false);
5017
- let nextCharacterIsContinuation = false;
5182
+ let isNextCharacterContinuation = false;
5018
5183
  for (let tokenIndex = tokens.length - 1; tokenIndex >= 0; tokenIndex--) {
5019
5184
  const token = tokens[tokenIndex];
5020
- hasContinuationAhead[tokenIndex] = nextCharacterIsContinuation;
5021
- if (token.type === "character") nextCharacterIsContinuation = Boolean(token.isGraphemeContinuation);
5185
+ hasContinuationAhead[tokenIndex] = isNextCharacterContinuation;
5186
+ if (token.type === "character") isNextCharacterContinuation = Boolean(token.isGraphemeContinuation);
5022
5187
  }
5023
5188
  return hasContinuationAhead;
5024
5189
  }
@@ -5066,138 +5231,33 @@ function sliceAnsi(string, start, end) {
5066
5231
  state.returnValue += undoAnsiCodes(state.activeStyles);
5067
5232
  return state.returnValue;
5068
5233
  }
5069
- // node_modules/ansi-regex/index.js
5070
- function ansiRegex({ onlyFirst = false } = {}) {
5071
- return new RegExp(`(?:(?:\\u001B\\]|\\u009D)[^\\u0007\\u001B\\u009C\\u009D]*(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]`, onlyFirst ? void 0 : "g");
5072
- }
5073
- // node_modules/strip-ansi/index.js
5074
- var regex = ansiRegex();
5075
- function stripAnsi(string) {
5076
- if (typeof string !== "string") throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
5077
- if (!string.includes("\x1B") && !string.includes("›")) return string;
5078
- return string.replace(regex, "");
5079
- }
5080
- // node_modules/string-width/index.js
5081
- /**
5082
- Logic:
5083
- - Segment graphemes to match how terminals render clusters.
5084
- - Width rules:
5085
- 1. Skip non-printing clusters (Default_Ignorable, Control, pure nonspacing/enclosing Mark, lone Surrogates). Tabs are ignored by design.
5086
- 2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
5087
- 3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
5088
- 4. Hangul jamo collapse each standard modern Hangul L+V or L+V+T syllable piece to width 2.
5089
- Unmatched repeated leading/vowel/trailing jamo stay additive because that matches how the terminals we target render them.
5090
- 5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing spacing marks and Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
5091
- */
5092
- var segmenter = new Intl.Segmenter();
5093
- var visibleCharacterRegex = /[^\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]/v;
5094
- var spacingMarkRegex = /\p{Spacing_Mark}/v;
5095
- var rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
5096
- var unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
5097
- var extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
5098
- function isDoubleWidthNonRgiEmojiSequence(segment) {
5099
- if (segment.length > 50) return false;
5100
- if (unqualifiedKeycapRegex.test(segment)) return true;
5101
- if (segment.includes("‍")) {
5102
- const pictographics = segment.match(extendedPictographicRegex);
5103
- return pictographics !== null && pictographics.length >= 2;
5104
- }
5105
- return false;
5106
- }
5107
- function baseVisible(segment) {
5108
- const index = segment.search(visibleCharacterRegex);
5109
- return index === -1 ? void 0 : segment.slice(index);
5110
- }
5111
- function isHangulLeadingJamo(codePoint) {
5112
- return codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388;
5113
- }
5114
- function isHangulVowelJamo(codePoint) {
5115
- return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
5116
- }
5117
- function isHangulTrailingJamo(codePoint) {
5118
- return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
5119
- }
5120
- function isHangulJamo(codePoint) {
5121
- return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
5122
- }
5123
- function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
5124
- const codePoints = [];
5125
- for (const character of visibleSegment) {
5126
- if (!visibleCharacterRegex.test(character)) continue;
5127
- codePoints.push(character.codePointAt(0));
5128
- }
5129
- if (codePoints.length === 0) return;
5130
- let width = 0;
5131
- for (let index = 0; index < codePoints.length; index++) {
5132
- const codePoint = codePoints[index];
5133
- if (!isHangulJamo(codePoint)) {
5134
- if (width === 0) return;
5135
- for (let remaining = index; remaining < codePoints.length; remaining++) width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
5136
- return width;
5137
- }
5138
- if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index + 1])) {
5139
- width += 2;
5140
- index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
5141
- continue;
5142
- }
5143
- width += eastAsianWidth(codePoint, eastAsianWidthOptions);
5144
- }
5145
- return width;
5146
- }
5147
- function trailingWidth(visibleSegment, eastAsianWidthOptions) {
5148
- let extra = 0;
5149
- let first = true;
5150
- for (const character of visibleSegment) {
5151
- if (first) {
5152
- first = false;
5153
- continue;
5154
- }
5155
- if (spacingMarkRegex.test(character) || character >= "＀" && character <= "￯") extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
5156
- }
5157
- return extra;
5158
- }
5159
- function stringWidth(input, options = {}) {
5160
- if (typeof input !== "string" || input.length === 0) return 0;
5161
- const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
5162
- let string = input;
5163
- if (!countAnsiEscapeCodes && (string.includes("\x1B") || string.includes("›"))) string = stripAnsi(string);
5164
- if (string.length === 0) return 0;
5165
- if (/^[\u0020-\u007E]*$/.test(string)) return string.length;
5166
- let width = 0;
5167
- const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
5168
- for (const { segment } of segmenter.segment(string)) {
5169
- const visibleSegment = baseVisible(segment);
5170
- if (visibleSegment === void 0) continue;
5171
- if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
5172
- width += 2;
5173
- continue;
5174
- }
5175
- const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
5176
- if (hangulWidth !== void 0) {
5177
- width += hangulWidth;
5178
- continue;
5179
- }
5180
- const codePoint = visibleSegment.codePointAt(0);
5181
- width += eastAsianWidth(codePoint, eastAsianWidthOptions);
5182
- width += trailingWidth(visibleSegment, eastAsianWidthOptions);
5183
- }
5184
- return width;
5185
- }
5186
5234
  // node_modules/cli-truncate/index.js
5187
5235
  var validPositions = /* @__PURE__ */ new Set([
5188
5236
  "start",
5189
5237
  "middle",
5190
5238
  "end"
5191
5239
  ]);
5192
- function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight) {
5193
- if (string.charAt(wantedIndex) === " ") return wantedIndex;
5240
+ function getVisibleColumns(text) {
5241
+ const visibleColumns = [];
5242
+ for (const { segment } of new Intl.Segmenter().segment(stripVTControlCharacters(text))) {
5243
+ const width = stringWidth(segment);
5244
+ for (let column = 0; column < width; column++) visibleColumns.push(column === 0 ? segment : "");
5245
+ }
5246
+ return visibleColumns;
5247
+ }
5248
+ function getIndexOfNearestSpace(visibleColumns, wantedIndex, shouldSearchRight) {
5249
+ if (visibleColumns[wantedIndex] === " ") return wantedIndex;
5194
5250
  const direction = shouldSearchRight ? 1 : -1;
5195
5251
  for (let index = 0; index <= 3; index++) {
5196
5252
  const finalIndex = wantedIndex + index * direction;
5197
- if (string.charAt(finalIndex) === " ") return finalIndex;
5253
+ if (visibleColumns[finalIndex] === " ") return finalIndex;
5198
5254
  }
5199
5255
  return wantedIndex;
5200
5256
  }
5257
+ function getIndexAfterSpaces(visibleColumns, index) {
5258
+ while (visibleColumns[index] === " ") index++;
5259
+ return index;
5260
+ }
5201
5261
  function validateInput(text, columns, position, truncationCharacter) {
5202
5262
  if (typeof text !== "string") throw new TypeError(`Expected \`input\` to be a string, got ${typeof text}`);
5203
5263
  if (typeof columns !== "number") throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
@@ -5213,6 +5273,7 @@ function cliTruncate(text, columns, options = {}) {
5213
5273
  const length = stringWidth(text);
5214
5274
  if (length <= columns) return text;
5215
5275
  if (columns === 1) return truncationCharacter;
5276
+ const visibleColumns = preferTruncationOnSpace ? getVisibleColumns(text) : void 0;
5216
5277
  const ANSI = {
5217
5278
  ESC: 27,
5218
5279
  LEFT_BRACKET: 91,
@@ -5247,17 +5308,15 @@ function cliTruncate(text, columns, options = {}) {
5247
5308
  }
5248
5309
  function appendWithInheritedStyleFromEnd(visible, suffix) {
5249
5310
  const start = trailingSgrSpanStartIndex(visible);
5250
- if (start === visible.length) return visible + suffix;
5251
- return visible.slice(0, start) + suffix + visible.slice(start);
5311
+ return start === visible.length ? visible + suffix : visible.slice(0, start) + suffix + visible.slice(start);
5252
5312
  }
5253
5313
  function prependWithInheritedStyleFromStart(prefix, visible) {
5254
5314
  const end = leadingSgrSpanEndIndex(visible);
5255
- if (end === 0) return prefix + visible;
5256
- return visible.slice(0, end) + prefix + visible.slice(end);
5315
+ return end === 0 ? prefix + visible : visible.slice(0, end) + prefix + visible.slice(end);
5257
5316
  }
5258
5317
  if (position === "start") {
5259
5318
  if (preferTruncationOnSpace) {
5260
- const right = sliceAnsi(text, getIndexOfNearestSpace(text, length - columns + stringWidth(truncationCharacter), true), length).trim();
5319
+ const right = sliceAnsi(text, getIndexAfterSpaces(visibleColumns, getIndexOfNearestSpace(visibleColumns, length - columns + stringWidth(truncationCharacter), true)), length);
5261
5320
  return prependWithInheritedStyleFromStart(truncationCharacter, right);
5262
5321
  }
5263
5322
  if (space) truncationCharacter += " ";
@@ -5272,17 +5331,15 @@ function cliTruncate(text, columns, options = {}) {
5272
5331
  const truncationWidth = stringWidth(truncationCharacter);
5273
5332
  const half = Math.min(Math.floor(columns / 2), Math.max(0, columns - truncationWidth));
5274
5333
  if (preferTruncationOnSpace) {
5275
- const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
5276
- const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + truncationWidth, true);
5277
- return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, spaceNearSecondBreakPoint, length).trim();
5334
+ const spaceNearFirstBreakPoint = getIndexOfNearestSpace(visibleColumns, half);
5335
+ const spaceNearSecondBreakPoint = getIndexOfNearestSpace(visibleColumns, length - (columns - half) + truncationWidth, true);
5336
+ return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, getIndexAfterSpaces(visibleColumns, spaceNearSecondBreakPoint), length);
5278
5337
  }
5279
5338
  return sliceAnsi(text, 0, half) + truncationCharacter + sliceAnsi(text, length - (columns - half) + truncationWidth, length);
5280
5339
  }
5281
- if (position === "end") {
5282
- if (preferTruncationOnSpace) return appendWithInheritedStyleFromEnd(sliceAnsi(text, 0, getIndexOfNearestSpace(text, columns - stringWidth(truncationCharacter))), truncationCharacter);
5283
- if (space) truncationCharacter = ` ${truncationCharacter}`;
5284
- return appendWithInheritedStyleFromEnd(sliceAnsi(text, 0, columns - stringWidth(truncationCharacter)), truncationCharacter);
5285
- }
5340
+ if (preferTruncationOnSpace) return appendWithInheritedStyleFromEnd(sliceAnsi(text, 0, getIndexOfNearestSpace(visibleColumns, columns - stringWidth(truncationCharacter))), truncationCharacter);
5341
+ if (space) truncationCharacter = ` ${truncationCharacter}`;
5342
+ return appendWithInheritedStyleFromEnd(sliceAnsi(text, 0, columns - stringWidth(truncationCharacter)), truncationCharacter);
5286
5343
  }
5287
5344
  Object.freeze([
5288
5345
  "",
@@ -5309,7 +5366,7 @@ function assertSafeFilename(filename) {
5309
5366
  if (typeof filename !== "string") throw new TypeError("Expected a string");
5310
5367
  if (!isSafeFilename(filename)) throw new Error(`Unsafe filename: ${JSON.stringify(filename)}`);
5311
5368
  }
5312
- // node_modules/path-exists/index.js
5369
+ // node_modules/unused-filename/node_modules/path-exists/index.js
5313
5370
  function pathExistsSync(path) {
5314
5371
  try {
5315
5372
  fs.accessSync(path);
@@ -13720,7 +13777,7 @@ var MainWindow = class {
13720
13777
  // src/main/updater.js
13721
13778
  var updater = new NpmUpdater({
13722
13779
  name: "claude-discover",
13723
- version: "1.10.12",
13780
+ version: "1.10.13",
13724
13781
  bin: { "claude-discover": "bin/claude-discover.mjs" }
13725
13782
  }, { dev: false });
13726
13783
  // src/main/Application.js