ccgauge 1.1.0 → 1.1.2

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.
Files changed (127) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/app-build-manifest.json +42 -42
  3. package/.next/standalone/.next/app-path-routes-manifest.json +6 -6
  4. package/.next/standalone/.next/build-manifest.json +2 -2
  5. package/.next/standalone/.next/prerender-manifest.json +3 -3
  6. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  7. package/.next/standalone/.next/server/app/api/blocks/route_client-reference-manifest.js +1 -1
  8. package/.next/standalone/.next/server/app/api/export/usage/route.js +1 -1
  9. package/.next/standalone/.next/server/app/api/export/usage/route_client-reference-manifest.js +1 -1
  10. package/.next/standalone/.next/server/app/api/pricing/route_client-reference-manifest.js +1 -1
  11. package/.next/standalone/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
  12. package/.next/standalone/.next/server/app/api/scan/route_client-reference-manifest.js +1 -1
  13. package/.next/standalone/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -1
  14. package/.next/standalone/.next/server/app/api/usage/route_client-reference-manifest.js +1 -1
  15. package/.next/standalone/.next/server/app/models/page.js +1 -1
  16. package/.next/standalone/.next/server/app/models/page_client-reference-manifest.js +1 -1
  17. package/.next/standalone/.next/server/app/page.js +2 -2
  18. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  19. package/.next/standalone/.next/server/app/projects/[id]/page_client-reference-manifest.js +1 -1
  20. package/.next/standalone/.next/server/app/projects/page.js +1 -1
  21. package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
  22. package/.next/standalone/.next/server/app/sessions/[id]/page_client-reference-manifest.js +1 -1
  23. package/.next/standalone/.next/server/app/sessions/page.js +1 -1
  24. package/.next/standalone/.next/server/app/sessions/page_client-reference-manifest.js +1 -1
  25. package/.next/standalone/.next/server/app/settings/page.js +2 -2
  26. package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  27. package/.next/standalone/.next/server/app/usage/page.js +1 -1
  28. package/.next/standalone/.next/server/app/usage/page_client-reference-manifest.js +1 -1
  29. package/.next/standalone/.next/server/app-paths-manifest.json +6 -6
  30. package/.next/standalone/.next/server/chunks/125.js +1 -1
  31. package/.next/standalone/.next/server/chunks/567.js +3 -3
  32. package/.next/standalone/.next/server/chunks/716.js +1 -1
  33. package/.next/standalone/.next/server/chunks/98.js +1 -1
  34. package/.next/standalone/.next/server/functions-config-manifest.json +1 -1
  35. package/.next/standalone/.next/server/middleware-manifest.json +5 -5
  36. package/.next/standalone/.next/server/pages/500.html +1 -1
  37. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  38. package/.next/standalone/.next/static/chunks/148-edf90b0918345dc2.js +1 -0
  39. package/.next/standalone/.next/static/chunks/app/layout-af71188a257674b5.js +1 -0
  40. package/.next/standalone/.next/static/chunks/app/page-1a147d12fca0b184.js +1 -0
  41. package/.next/standalone/.next/static/chunks/app/usage/{page-7fcc2a2d931307d5.js → page-051223f62647aadc.js} +1 -1
  42. package/.next/standalone/.next/static/css/fabb40b2545c70dd.css +5 -0
  43. package/.next/standalone/package.json +8 -2
  44. package/.next/standalone/public/codex-logo.webp +0 -0
  45. package/CHANGELOG.md +160 -0
  46. package/README.md +136 -384
  47. package/README.zh-CN.md +146 -398
  48. package/bin/cli.mjs +30 -190
  49. package/dist/mcp/server.mjs +11 -11
  50. package/dist/report/index.mjs +36 -3127
  51. package/package.json +8 -2
  52. package/.next/standalone/.next/static/chunks/148-f2cba0b76260b8d3.js +0 -1
  53. package/.next/standalone/.next/static/chunks/app/layout-0adb4fc0305adf29.js +0 -1
  54. package/.next/standalone/.next/static/chunks/app/page-3cda7f70ecf5017a.js +0 -1
  55. package/.next/standalone/.next/static/css/bde47638beb0c717.css +0 -3
  56. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/constants.js +0 -10
  57. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/fontkit/index.js +0 -1
  58. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/format-available-values.js +0 -9
  59. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/fetch-css-from-google-fonts.js +0 -28
  60. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/fetch-font-file.js +0 -24
  61. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/fetch-resource.js +0 -46
  62. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/find-font-files-in-css.js +0 -34
  63. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/font-data.json +0 -17669
  64. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/get-fallback-font-override-metrics.js +0 -62
  65. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/get-font-axes.js +0 -66
  66. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/get-google-fonts-url.js +0 -55
  67. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/get-proxy-agent.js +0 -23
  68. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/google-fonts-metadata.js +0 -8
  69. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/loader.js +0 -175
  70. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/retry.js +0 -18
  71. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/sort-fonts-variant-values.js +0 -26
  72. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/google/validate-google-font-function-call.js +0 -101
  73. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/local/get-fallback-metrics-from-font-file.js +0 -85
  74. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/local/loader.js +0 -78
  75. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/local/pick-font-file-for-fallback-generation.js +0 -85
  76. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/local/validate-local-font-function-call.js +0 -66
  77. package/.next/standalone/node_modules/next/dist/compiled/@next/font/dist/next-font-error.js +0 -11
  78. package/.next/standalone/node_modules/next/dist/compiled/@next/font/google/loader.js +0 -1
  79. package/.next/standalone/node_modules/next/dist/compiled/@next/font/local/loader.js +0 -1
  80. package/.next/standalone/node_modules/next/dist/compiled/@next/font/package.json +0 -1
  81. package/.next/standalone/node_modules/next/dist/compiled/amphtml-validator/index.js +0 -1
  82. package/.next/standalone/node_modules/next/dist/compiled/amphtml-validator/package.json +0 -1
  83. package/.next/standalone/node_modules/next/dist/compiled/amphtml-validator/validator_wasm.js +0 -2672
  84. package/.next/standalone/node_modules/next/dist/compiled/babel/bundle.js +0 -227
  85. package/.next/standalone/node_modules/next/dist/compiled/babel/code-frame.js +0 -1
  86. package/.next/standalone/node_modules/next/dist/compiled/babel/core-lib-block-hoist-plugin.js +0 -1
  87. package/.next/standalone/node_modules/next/dist/compiled/babel/core-lib-config.js +0 -1
  88. package/.next/standalone/node_modules/next/dist/compiled/babel/core-lib-normalize-file.js +0 -1
  89. package/.next/standalone/node_modules/next/dist/compiled/babel/core-lib-normalize-opts.js +0 -1
  90. package/.next/standalone/node_modules/next/dist/compiled/babel/core-lib-plugin-pass.js +0 -1
  91. package/.next/standalone/node_modules/next/dist/compiled/babel/core.js +0 -1
  92. package/.next/standalone/node_modules/next/dist/compiled/babel/generator.js +0 -1
  93. package/.next/standalone/node_modules/next/dist/compiled/babel/package.json +0 -1
  94. package/.next/standalone/node_modules/next/dist/compiled/babel/parser.js +0 -1
  95. package/.next/standalone/node_modules/next/dist/compiled/babel/plugin-syntax-jsx.js +0 -1
  96. package/.next/standalone/node_modules/next/dist/compiled/babel/plugin-transform-define.js +0 -1
  97. package/.next/standalone/node_modules/next/dist/compiled/babel/plugin-transform-modules-commonjs.js +0 -1
  98. package/.next/standalone/node_modules/next/dist/compiled/babel/preset-typescript.js +0 -1
  99. package/.next/standalone/node_modules/next/dist/compiled/babel/traverse.js +0 -1
  100. package/.next/standalone/node_modules/next/dist/compiled/babel/types.js +0 -1
  101. package/.next/standalone/node_modules/next/dist/compiled/babel-packages/package.json +0 -1
  102. package/.next/standalone/node_modules/next/dist/compiled/babel-packages/packages-bundle.js +0 -335
  103. package/.next/standalone/node_modules/next/dist/server/capsize-font-metrics.json +0 -181516
  104. package/.next/standalone/node_modules/next/node_modules/@img/sharp-darwin-arm64/LICENSE +0 -191
  105. package/.next/standalone/node_modules/next/node_modules/@img/sharp-darwin-arm64/lib/sharp-darwin-arm64.node +0 -0
  106. package/.next/standalone/node_modules/next/node_modules/@img/sharp-darwin-arm64/package.json +0 -40
  107. package/.next/standalone/node_modules/next/node_modules/@img/sharp-libvips-darwin-arm64/lib/index.js +0 -1
  108. package/.next/standalone/node_modules/next/node_modules/@img/sharp-libvips-darwin-arm64/lib/libvips-cpp.8.17.3.dylib +0 -0
  109. package/.next/standalone/node_modules/next/node_modules/@img/sharp-libvips-darwin-arm64/package.json +0 -36
  110. package/.next/standalone/node_modules/next/node_modules/@img/sharp-libvips-darwin-arm64/versions.json +0 -30
  111. package/.next/standalone/node_modules/next/node_modules/sharp/lib/channel.js +0 -177
  112. package/.next/standalone/node_modules/next/node_modules/sharp/lib/colour.js +0 -195
  113. package/.next/standalone/node_modules/next/node_modules/sharp/lib/composite.js +0 -212
  114. package/.next/standalone/node_modules/next/node_modules/sharp/lib/constructor.js +0 -499
  115. package/.next/standalone/node_modules/next/node_modules/sharp/lib/index.js +0 -16
  116. package/.next/standalone/node_modules/next/node_modules/sharp/lib/input.js +0 -809
  117. package/.next/standalone/node_modules/next/node_modules/sharp/lib/is.js +0 -143
  118. package/.next/standalone/node_modules/next/node_modules/sharp/lib/libvips.js +0 -207
  119. package/.next/standalone/node_modules/next/node_modules/sharp/lib/operation.js +0 -1016
  120. package/.next/standalone/node_modules/next/node_modules/sharp/lib/output.js +0 -1666
  121. package/.next/standalone/node_modules/next/node_modules/sharp/lib/resize.js +0 -595
  122. package/.next/standalone/node_modules/next/node_modules/sharp/lib/sharp.js +0 -121
  123. package/.next/standalone/node_modules/next/node_modules/sharp/lib/utility.js +0 -291
  124. package/.next/standalone/node_modules/next/node_modules/sharp/package.json +0 -202
  125. package/.next/standalone/public/codex-logo.png +0 -0
  126. /package/.next/standalone/.next/static/{jncTEohJB76Iq9TUm3G21 → EQqRlXV5HyaCYSZWOVllH}/_buildManifest.js +0 -0
  127. /package/.next/standalone/.next/static/{jncTEohJB76Iq9TUm3G21 → EQqRlXV5HyaCYSZWOVllH}/_ssgManifest.js +0 -0
@@ -1,3127 +1,36 @@
1
- // lib/providers/claude/index.ts
2
- import path from "node:path";
3
- import os from "node:os";
4
-
5
- // lib/data-loader/parse-jsonl.ts
6
- import { createReadStream } from "node:fs";
7
- import readline from "node:readline";
8
- var TEXT_PREVIEW_MAX = 200;
9
- async function parseJsonlFile(file) {
10
- const stream = createReadStream(file, { encoding: "utf8" });
11
- const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
12
- const assistant = [];
13
- const user = [];
14
- const parentLinks = [];
15
- for await (const line of rl) {
16
- if (!line.trim()) continue;
17
- let raw;
18
- try {
19
- raw = JSON.parse(line);
20
- } catch {
21
- continue;
22
- }
23
- if (!raw || typeof raw !== "object") continue;
24
- if (raw.uuid) parentLinks.push([raw.uuid, raw.parentUuid ?? null]);
25
- if (raw.type === "assistant") {
26
- const a = parseAssistant(raw, file);
27
- if (a) assistant.push(a);
28
- } else if (raw.type === "user") {
29
- const u = parseUser(raw, file);
30
- if (u) user.push(u);
31
- }
32
- }
33
- return { assistant, user, parentLinks };
34
- }
35
- function parseAssistant(raw, file) {
36
- const msg = raw.message;
37
- if (!msg) return null;
38
- const usage = msg.usage;
39
- if (!usage) return null;
40
- const model = msg.model ?? "";
41
- if (!model || model === "<synthetic>") return null;
42
- const messageId = msg.id ?? raw.uuid ?? "";
43
- if (!messageId && !raw.requestId) return null;
44
- const cacheCreation = usage.cache_creation;
45
- const content = Array.isArray(msg.content) ? msg.content : [];
46
- const toolNames = [];
47
- let hasThinking = false;
48
- let textPreview = "";
49
- for (const c of content) {
50
- if (c.type === "tool_use" && typeof c.name === "string") {
51
- toolNames.push(c.name);
52
- } else if (c.type === "thinking") {
53
- hasThinking = true;
54
- } else if (c.type === "text" && typeof c.text === "string" && !textPreview) {
55
- textPreview = c.text.slice(0, TEXT_PREVIEW_MAX);
56
- }
57
- }
58
- return {
59
- type: "assistant",
60
- source: "claude",
61
- uuid: raw.uuid ?? messageId,
62
- parentUuid: raw.parentUuid ?? null,
63
- timestamp: raw.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
64
- sessionId: raw.sessionId ?? "",
65
- requestId: raw.requestId ?? "",
66
- cwd: raw.cwd ?? "",
67
- gitBranch: raw.gitBranch,
68
- version: raw.version,
69
- model,
70
- messageId,
71
- usage: {
72
- input_tokens: Number(usage.input_tokens) || 0,
73
- output_tokens: Number(usage.output_tokens) || 0,
74
- cache_creation_input_tokens: Number(usage.cache_creation_input_tokens) || 0,
75
- cache_read_input_tokens: Number(usage.cache_read_input_tokens) || 0,
76
- cache_creation_5m: Number(cacheCreation?.ephemeral_5m_input_tokens) || 0,
77
- cache_creation_1h: Number(cacheCreation?.ephemeral_1h_input_tokens) || 0
78
- },
79
- toolNames,
80
- hasThinking,
81
- textPreview,
82
- filePath: file,
83
- isSidechain: raw.isSidechain === true ? true : void 0
84
- };
85
- }
86
- function parseUser(raw, file) {
87
- if (!raw.uuid) return null;
88
- const msg = raw.message;
89
- let textPreview = "";
90
- if (msg) {
91
- const content = msg.content;
92
- if (typeof content === "string") {
93
- textPreview = content.slice(0, TEXT_PREVIEW_MAX);
94
- } else if (Array.isArray(content)) {
95
- for (const c of content) {
96
- if (c.type === "text" && typeof c.text === "string") {
97
- textPreview = c.text.slice(0, TEXT_PREVIEW_MAX);
98
- break;
99
- }
100
- }
101
- }
102
- }
103
- const isSidechain = raw.isSidechain === true;
104
- const isSynthetic = isSidechain || !!textPreview && isSyntheticUserText(textPreview);
105
- return {
106
- type: "user",
107
- source: "claude",
108
- uuid: raw.uuid,
109
- parentUuid: raw.parentUuid ?? null,
110
- timestamp: raw.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
111
- sessionId: raw.sessionId ?? "",
112
- cwd: raw.cwd ?? "",
113
- textPreview,
114
- isSynthetic,
115
- isSidechain: isSidechain ? true : void 0,
116
- filePath: file
117
- };
118
- }
119
- function isSyntheticUserText(text) {
120
- const t = text.trimStart();
121
- if (t.startsWith("Base directory for this skill:")) return true;
122
- if (t.startsWith("<system-reminder>")) return true;
123
- if (t.startsWith("Caveat: The messages below were generated by")) return true;
124
- return false;
125
- }
126
-
127
- // lib/pricing/builtin.ts
128
- var BUILTIN_PRICING = {
129
- "claude-opus-4-7": {
130
- input: 5,
131
- output: 25,
132
- cacheCreation5m: 6.25,
133
- cacheCreation1h: 10,
134
- cacheRead: 0.5
135
- },
136
- "claude-opus-4-6": {
137
- input: 5,
138
- output: 25,
139
- cacheCreation5m: 6.25,
140
- cacheCreation1h: 10,
141
- cacheRead: 0.5
142
- },
143
- "claude-opus-4-5": {
144
- input: 5,
145
- output: 25,
146
- cacheCreation5m: 6.25,
147
- cacheCreation1h: 10,
148
- cacheRead: 0.5
149
- },
150
- "claude-sonnet-4-6": {
151
- input: 3,
152
- output: 15,
153
- cacheCreation5m: 3.75,
154
- cacheCreation1h: 6,
155
- cacheRead: 0.3
156
- },
157
- "claude-sonnet-4-5": {
158
- input: 3,
159
- output: 15,
160
- cacheCreation5m: 3.75,
161
- cacheCreation1h: 6,
162
- cacheRead: 0.3
163
- },
164
- "claude-haiku-4-5": {
165
- input: 1,
166
- output: 5,
167
- cacheCreation5m: 1.25,
168
- cacheCreation1h: 2,
169
- cacheRead: 0.1
170
- },
171
- "claude-haiku-3-5": {
172
- input: 0.8,
173
- output: 4,
174
- cacheCreation5m: 1,
175
- cacheCreation1h: 1.6,
176
- cacheRead: 0.08
177
- },
178
- "claude-opus-4-1": {
179
- input: 15,
180
- output: 75,
181
- cacheCreation5m: 18.75,
182
- cacheCreation1h: 30,
183
- cacheRead: 1.5
184
- },
185
- "claude-opus-4": {
186
- input: 15,
187
- output: 75,
188
- cacheCreation5m: 18.75,
189
- cacheCreation1h: 30,
190
- cacheRead: 1.5
191
- },
192
- "claude-sonnet-4": {
193
- input: 3,
194
- output: 15,
195
- cacheCreation5m: 3.75,
196
- cacheCreation1h: 6,
197
- cacheRead: 0.3
198
- },
199
- "claude-sonnet-3-7": {
200
- input: 3,
201
- output: 15,
202
- cacheCreation5m: 3.75,
203
- cacheCreation1h: 6,
204
- cacheRead: 0.3
205
- },
206
- "claude-haiku-3": {
207
- input: 0.25,
208
- output: 1.25,
209
- cacheCreation5m: 0.3,
210
- cacheCreation1h: 0.5,
211
- cacheRead: 0.03
212
- }
213
- };
214
- var FALLBACK_BY_FAMILY = {
215
- opus: BUILTIN_PRICING["claude-opus-4-7"],
216
- sonnet: BUILTIN_PRICING["claude-sonnet-4-6"],
217
- haiku: BUILTIN_PRICING["claude-haiku-4-5"]
218
- };
219
-
220
- // lib/pricing/cost-from-usage.ts
221
- var PER_MTOK = 1e6;
222
- function costFromUsage(usage, pricing) {
223
- if (!pricing) {
224
- return {
225
- input: 0,
226
- output: 0,
227
- cacheCreation5m: 0,
228
- cacheCreation1h: 0,
229
- cacheRead: 0,
230
- total: 0,
231
- saved: 0
232
- };
233
- }
234
- const input = usage.input_tokens / PER_MTOK * pricing.input;
235
- const output = usage.output_tokens / PER_MTOK * pricing.output;
236
- let cc5 = usage.cache_creation_5m / PER_MTOK * pricing.cacheCreation5m;
237
- const cc1 = usage.cache_creation_1h / PER_MTOK * pricing.cacheCreation1h;
238
- if (cc5 + cc1 === 0 && usage.cache_creation_input_tokens > 0) {
239
- cc5 = usage.cache_creation_input_tokens / PER_MTOK * pricing.cacheCreation5m;
240
- }
241
- const cacheRead = usage.cache_read_input_tokens / PER_MTOK * pricing.cacheRead;
242
- const total = input + output + cc5 + cc1 + cacheRead;
243
- const saved = usage.cache_read_input_tokens / PER_MTOK * (pricing.input - pricing.cacheRead);
244
- return {
245
- input,
246
- output,
247
- cacheCreation5m: cc5,
248
- cacheCreation1h: cc1,
249
- cacheRead,
250
- total,
251
- saved
252
- };
253
- }
254
-
255
- // lib/providers/claude/shorten-model.ts
256
- function capitalize(s) {
257
- return s.replace(/\b\w/g, (c) => c.toUpperCase());
258
- }
259
- function shortenClaudeModel(model) {
260
- if (!model) return "(unknown)";
261
- let m = model.replace(/-(\d{8})$/, "").replace(/^(vertex_ai|bedrock|anthropic)\//, "");
262
- m = m.replace(/^claude-/, "");
263
- const parts = m.split("-");
264
- if (parts.length >= 2) {
265
- const family = parts[0];
266
- const version = parts.slice(1).join(".");
267
- return capitalize(family) + " " + version;
268
- }
269
- return capitalize(m.replace(/-/g, " "));
270
- }
271
-
272
- // lib/providers/claude/index.ts
273
- var dateSuffix = /-\d{8}$/;
274
- var prefixRe = /^(vertex_ai|bedrock|anthropic)\//;
275
- function resolvePricing(model) {
276
- if (!model) return { pricing: null, matchType: "none", matchedKey: null };
277
- if (BUILTIN_PRICING[model]) {
278
- return { pricing: BUILTIN_PRICING[model], matchType: "exact", matchedKey: model };
279
- }
280
- const stripped = model.replace(dateSuffix, "");
281
- if (BUILTIN_PRICING[stripped]) {
282
- return {
283
- pricing: BUILTIN_PRICING[stripped],
284
- matchType: "date-stripped",
285
- matchedKey: stripped
286
- };
287
- }
288
- const noPrefix = stripped.replace(prefixRe, "");
289
- if (BUILTIN_PRICING[noPrefix]) {
290
- return {
291
- pricing: BUILTIN_PRICING[noPrefix],
292
- matchType: "prefix-stripped",
293
- matchedKey: noPrefix
294
- };
295
- }
296
- for (const family of ["opus", "sonnet", "haiku"]) {
297
- if (model.toLowerCase().includes(family)) {
298
- return {
299
- pricing: FALLBACK_BY_FAMILY[family],
300
- matchType: "family-fallback",
301
- matchedKey: `claude-${family}-(latest)`
302
- };
303
- }
304
- }
305
- return { pricing: null, matchType: "none", matchedKey: null };
306
- }
307
- function getDirs() {
308
- const home = os.homedir();
309
- const candidates = [
310
- path.join(home, ".claude", "projects"),
311
- path.join(home, ".config", "claude", "projects")
312
- ];
313
- if (process.env.CCGAUGE_CONFIG_DIR) {
314
- candidates.push(path.join(process.env.CCGAUGE_CONFIG_DIR, "projects"));
315
- }
316
- if (process.env.CLAUDE_CONFIG_DIR) {
317
- candidates.push(path.join(process.env.CLAUDE_CONFIG_DIR, "projects"));
318
- }
319
- return Array.from(new Set(candidates));
320
- }
321
- var claudeAdapter = {
322
- id: "claude",
323
- displayName: { en: "Claude", zh: "Claude" },
324
- shortLabel: "C",
325
- color: { fg: "#b45309", bg: "#fef3c7" },
326
- logoSrc: "/claude-logo.webp",
327
- // v1 → v3 (no v2 ever shipped on npm): user records now carry an
328
- // `isSynthetic` flag so skill metadata + <system-reminder> blocks can
329
- // still be displayed as the per-call "prompt" on child rows, but are
330
- // skipped as turn-boundary anchors so they don't wrongly split a single
331
- // conversation into multiple turns.
332
- // v4: extend `isSynthetic` to sub-agent first-user records (every record
333
- // in a `subagents/agent-*.jsonl` file has `isSidechain: true`); also
334
- // propagate `isSidechain` to all records so the indexer's post-link pass
335
- // can stitch sub-agent files into the parent session's turn graph.
336
- parserVersion: "claude-v4-sidechain-merge",
337
- capabilities: {
338
- hasCacheCreation: true,
339
- hasReasoningTokens: false,
340
- blockWindowMs: 5 * 60 * 60 * 1e3
341
- },
342
- getDirs,
343
- shouldSkipDir: (name) => name === "tool-results" || name === "memory",
344
- parseFile: async (file) => {
345
- const parsed = await parseJsonlFile(file);
346
- return parsed;
347
- },
348
- resolvePricing,
349
- shortenModel: shortenClaudeModel,
350
- costFromUsage,
351
- costFootnoteKey: null
352
- };
353
-
354
- // lib/providers/codex/index.ts
355
- import path2 from "node:path";
356
- import os2 from "node:os";
357
-
358
- // lib/providers/codex/parse-codex-jsonl.ts
359
- import { createReadStream as createReadStream2, promises as fs } from "node:fs";
360
- import readline2 from "node:readline";
361
- var TEXT_PREVIEW_MAX2 = 200;
362
- async function fileMtimeIso(file) {
363
- try {
364
- const stat = await fs.stat(file);
365
- return new Date(stat.mtimeMs).toISOString();
366
- } catch {
367
- return (/* @__PURE__ */ new Date()).toISOString();
368
- }
369
- }
370
- function asString(v) {
371
- return typeof v === "string" ? v : "";
372
- }
373
- function asNumber(v) {
374
- const n = Number(v);
375
- return Number.isFinite(n) ? n : 0;
376
- }
377
- function extractMessageText(payload) {
378
- const msg = payload.message;
379
- if (typeof msg === "string") return msg;
380
- const content = payload.content;
381
- if (typeof content === "string") return content;
382
- if (Array.isArray(content)) {
383
- for (const c of content) {
384
- const t = c?.type;
385
- if ((t === "input_text" || t === "output_text" || t === "text") && typeof c.text === "string") {
386
- return c.text;
387
- }
388
- }
389
- }
390
- return "";
391
- }
392
- async function parseCodexJsonlFile(file) {
393
- const stream = createReadStream2(file, { encoding: "utf8" });
394
- const rl = readline2.createInterface({ input: stream, crlfDelay: Infinity });
395
- const assistant = [];
396
- const user = [];
397
- const parentLinks = [];
398
- let sessionId = "";
399
- let cliVersion;
400
- let defaultCwd = "";
401
- let userIdx = 0;
402
- let assistantIdx = 0;
403
- let prevTotal = null;
404
- const fileMtime = await fileMtimeIso(file);
405
- let lastValidTs = fileMtime;
406
- const turn = {
407
- turnId: null,
408
- cwd: "",
409
- model: "gpt-unknown",
410
- userUuid: null,
411
- toolNames: [],
412
- hasThinking: false,
413
- pendingTextPreview: ""
414
- };
415
- for await (const line of rl) {
416
- if (!line.trim()) continue;
417
- let evt;
418
- try {
419
- evt = JSON.parse(line);
420
- } catch {
421
- continue;
422
- }
423
- if (!evt || typeof evt !== "object" || !evt.type) continue;
424
- const payload = evt.payload ?? {};
425
- const rawTs = asString(evt.timestamp);
426
- const ts = rawTs || lastValidTs;
427
- if (rawTs) lastValidTs = rawTs;
428
- if (evt.type === "session_meta") {
429
- sessionId = asString(payload.id);
430
- defaultCwd = asString(payload.cwd);
431
- cliVersion = asString(payload.cli_version) || void 0;
432
- const metaTs = asString(payload.timestamp);
433
- if (metaTs) lastValidTs = metaTs;
434
- if (!turn.cwd) turn.cwd = defaultCwd;
435
- continue;
436
- }
437
- if (evt.type === "turn_context") {
438
- turn.turnId = asString(payload.turn_id) || turn.turnId;
439
- turn.cwd = asString(payload.cwd) || defaultCwd;
440
- const m = asString(payload.model);
441
- if (m) turn.model = m;
442
- const eff = asString(payload.effort);
443
- if (eff) turn.effort = eff;
444
- turn.toolNames = [];
445
- turn.hasThinking = false;
446
- turn.pendingTextPreview = "";
447
- continue;
448
- }
449
- if (evt.type === "event_msg") {
450
- const sub = asString(payload.type);
451
- if (sub === "user_message") {
452
- const text = extractMessageText(payload);
453
- if (!text) continue;
454
- const uuid = `${sessionId}::u${userIdx++}`;
455
- user.push({
456
- type: "user",
457
- source: "codex",
458
- uuid,
459
- parentUuid: null,
460
- timestamp: ts,
461
- sessionId,
462
- cwd: turn.cwd || defaultCwd,
463
- textPreview: text.slice(0, TEXT_PREVIEW_MAX2),
464
- filePath: file
465
- });
466
- parentLinks.push([uuid, null]);
467
- turn.userUuid = uuid;
468
- continue;
469
- }
470
- if (sub === "agent_message") {
471
- const text = extractMessageText(payload);
472
- if (text && !turn.pendingTextPreview) {
473
- turn.pendingTextPreview = text.slice(0, TEXT_PREVIEW_MAX2);
474
- }
475
- continue;
476
- }
477
- if (sub === "agent_reasoning") {
478
- turn.hasThinking = true;
479
- continue;
480
- }
481
- if (sub === "token_count") {
482
- const info = payload.info;
483
- if (!info) continue;
484
- const total = info.total_token_usage;
485
- const last = info.last_token_usage;
486
- const cur = total ? {
487
- input: asNumber(total.input_tokens),
488
- cached: asNumber(total.cached_input_tokens),
489
- output: asNumber(total.output_tokens),
490
- reasoning: asNumber(total.reasoning_output_tokens)
491
- } : null;
492
- let deltaInput;
493
- let deltaCached;
494
- let deltaOutput;
495
- let deltaReasoning;
496
- if (cur) {
497
- if (prevTotal === null) {
498
- deltaInput = cur.input;
499
- deltaCached = cur.cached;
500
- deltaOutput = cur.output;
501
- deltaReasoning = cur.reasoning;
502
- } else {
503
- deltaInput = Math.max(0, cur.input - prevTotal.input);
504
- deltaCached = Math.max(0, cur.cached - prevTotal.cached);
505
- deltaOutput = Math.max(0, cur.output - prevTotal.output);
506
- deltaReasoning = Math.max(0, cur.reasoning - prevTotal.reasoning);
507
- }
508
- if (deltaInput === 0 && deltaCached === 0 && deltaOutput === 0 && deltaReasoning === 0) {
509
- continue;
510
- }
511
- if (prevTotal === null) {
512
- prevTotal = { ...cur };
513
- } else {
514
- prevTotal = {
515
- input: Math.max(prevTotal.input, cur.input),
516
- cached: Math.max(prevTotal.cached, cur.cached),
517
- output: Math.max(prevTotal.output, cur.output),
518
- reasoning: Math.max(prevTotal.reasoning, cur.reasoning)
519
- };
520
- }
521
- } else if (last) {
522
- deltaInput = asNumber(last.input_tokens);
523
- deltaCached = asNumber(last.cached_input_tokens);
524
- deltaOutput = asNumber(last.output_tokens);
525
- deltaReasoning = asNumber(last.reasoning_output_tokens);
526
- if (deltaInput === 0 && deltaCached === 0 && deltaOutput === 0 && deltaReasoning === 0) {
527
- continue;
528
- }
529
- } else {
530
- continue;
531
- }
532
- const uuid = `${sessionId}::a${assistantIdx++}`;
533
- const requestId = turn.turnId ? `${turn.turnId}::a${assistantIdx}` : `${sessionId}::a${assistantIdx}`;
534
- assistant.push({
535
- type: "assistant",
536
- source: "codex",
537
- uuid,
538
- parentUuid: turn.userUuid,
539
- timestamp: ts,
540
- sessionId,
541
- requestId,
542
- cwd: turn.cwd || defaultCwd,
543
- version: cliVersion,
544
- model: turn.model || "gpt-unknown",
545
- messageId: requestId,
546
- usage: {
547
- input_tokens: Math.max(0, deltaInput - deltaCached),
548
- // output_tokens already includes reasoning (per OpenAI API
549
- // billing convention). reasoning_tokens below is a display-only
550
- // breakdown that MUST NOT be added again to total/cost.
551
- output_tokens: deltaOutput + deltaReasoning,
552
- cache_creation_input_tokens: 0,
553
- cache_read_input_tokens: deltaCached,
554
- cache_creation_5m: 0,
555
- cache_creation_1h: 0,
556
- reasoning_tokens: deltaReasoning
557
- },
558
- toolNames: [...turn.toolNames],
559
- hasThinking: turn.hasThinking,
560
- textPreview: turn.pendingTextPreview,
561
- filePath: file,
562
- effort: turn.effort
563
- });
564
- parentLinks.push([uuid, turn.userUuid]);
565
- turn.toolNames = [];
566
- turn.hasThinking = false;
567
- turn.pendingTextPreview = "";
568
- continue;
569
- }
570
- continue;
571
- }
572
- if (evt.type === "response_item") {
573
- const sub = asString(payload.type);
574
- if (sub === "function_call" || sub === "custom_tool_call") {
575
- const name = asString(payload.name);
576
- if (name) turn.toolNames.push(name);
577
- continue;
578
- }
579
- if (sub === "reasoning") {
580
- turn.hasThinking = true;
581
- continue;
582
- }
583
- if (sub === "message") {
584
- const role = asString(payload.role);
585
- if (role === "assistant") {
586
- const text = extractMessageText(payload);
587
- if (text && !turn.pendingTextPreview) {
588
- turn.pendingTextPreview = text.slice(0, TEXT_PREVIEW_MAX2);
589
- }
590
- }
591
- continue;
592
- }
593
- continue;
594
- }
595
- }
596
- return { assistant, user, parentLinks };
597
- }
598
-
599
- // lib/providers/codex/pricing.ts
600
- var BUILTIN_PRICING_OPENAI = {
601
- "gpt-5": {
602
- input: 1.25,
603
- output: 10,
604
- cacheRead: 0.13,
605
- cacheCreation5m: 0,
606
- cacheCreation1h: 0
607
- },
608
- "gpt-5-mini": {
609
- input: 0.25,
610
- output: 2,
611
- cacheRead: 0.025,
612
- cacheCreation5m: 0,
613
- cacheCreation1h: 0
614
- },
615
- "gpt-5-nano": {
616
- input: 0.05,
617
- output: 0.4,
618
- cacheRead: 5e-3,
619
- cacheCreation5m: 0,
620
- cacheCreation1h: 0
621
- },
622
- "gpt-5.4": {
623
- input: 1.25,
624
- output: 10,
625
- cacheRead: 0.13,
626
- cacheCreation5m: 0,
627
- cacheCreation1h: 0
628
- },
629
- "gpt-5.5": {
630
- input: 1.25,
631
- output: 10,
632
- cacheRead: 0.13,
633
- cacheCreation5m: 0,
634
- cacheCreation1h: 0
635
- },
636
- "gpt-5.5-mini": {
637
- input: 0.25,
638
- output: 2,
639
- cacheRead: 0.025,
640
- cacheCreation5m: 0,
641
- cacheCreation1h: 0
642
- },
643
- "gpt-5.5-nano": {
644
- input: 0.05,
645
- output: 0.4,
646
- cacheRead: 5e-3,
647
- cacheCreation5m: 0,
648
- cacheCreation1h: 0
649
- },
650
- "gpt-4.1": {
651
- input: 2,
652
- output: 8,
653
- cacheRead: 0.5,
654
- cacheCreation5m: 0,
655
- cacheCreation1h: 0
656
- },
657
- "gpt-4.1-mini": {
658
- input: 0.4,
659
- output: 1.6,
660
- cacheRead: 0.1,
661
- cacheCreation5m: 0,
662
- cacheCreation1h: 0
663
- },
664
- "o3": {
665
- input: 2,
666
- output: 8,
667
- cacheRead: 0.5,
668
- cacheCreation5m: 0,
669
- cacheCreation1h: 0
670
- },
671
- "o4-mini": {
672
- input: 1.1,
673
- output: 4.4,
674
- cacheRead: 0.275,
675
- cacheCreation5m: 0,
676
- cacheCreation1h: 0
677
- }
678
- };
679
- var FALLBACK_FAMILY_OPENAI = {
680
- gpt: BUILTIN_PRICING_OPENAI["gpt-5"],
681
- o: BUILTIN_PRICING_OPENAI["o3"]
682
- };
683
- var dateSuffix2 = /-\d{8}$/;
684
- var prefixRe2 = /^(openai)\//;
685
- function resolveCodexPricing(model) {
686
- if (!model) return { pricing: null, matchType: "none", matchedKey: null };
687
- if (BUILTIN_PRICING_OPENAI[model]) {
688
- return {
689
- pricing: BUILTIN_PRICING_OPENAI[model],
690
- matchType: "exact",
691
- matchedKey: model
692
- };
693
- }
694
- const stripped = model.replace(dateSuffix2, "");
695
- if (BUILTIN_PRICING_OPENAI[stripped]) {
696
- return {
697
- pricing: BUILTIN_PRICING_OPENAI[stripped],
698
- matchType: "date-stripped",
699
- matchedKey: stripped
700
- };
701
- }
702
- const noPrefix = stripped.replace(prefixRe2, "");
703
- if (BUILTIN_PRICING_OPENAI[noPrefix]) {
704
- return {
705
- pricing: BUILTIN_PRICING_OPENAI[noPrefix],
706
- matchType: "prefix-stripped",
707
- matchedKey: noPrefix
708
- };
709
- }
710
- const lower = model.toLowerCase();
711
- if (lower.startsWith("gpt-") || lower === "gpt") {
712
- return {
713
- pricing: FALLBACK_FAMILY_OPENAI.gpt,
714
- matchType: "family-fallback",
715
- matchedKey: "gpt-(latest)"
716
- };
717
- }
718
- if (/^o\d/.test(lower)) {
719
- return {
720
- pricing: FALLBACK_FAMILY_OPENAI.o,
721
- matchType: "family-fallback",
722
- matchedKey: "o-(latest)"
723
- };
724
- }
725
- return { pricing: null, matchType: "none", matchedKey: null };
726
- }
727
-
728
- // lib/providers/codex/shorten-model.ts
729
- function capitalize2(s) {
730
- return s.replace(/\b\w/g, (c) => c.toUpperCase());
731
- }
732
- var FAMILY_LABEL = {
733
- mini: "Mini",
734
- nano: "Nano",
735
- pro: "Pro",
736
- turbo: "Turbo",
737
- preview: "Preview"
738
- };
739
- function shortenCodexModel(model) {
740
- if (!model) return "(unknown)";
741
- const m = model.replace(/^openai\//, "");
742
- if (m.toLowerCase().startsWith("gpt-")) {
743
- const rest = m.slice(4);
744
- const parts = rest.split("-").map((p) => FAMILY_LABEL[p.toLowerCase()] ?? p);
745
- return "GPT-" + parts.join(" ");
746
- }
747
- if (m.toLowerCase().startsWith("o")) {
748
- return m.toUpperCase();
749
- }
750
- return capitalize2(m.replace(/-/g, " "));
751
- }
752
-
753
- // lib/providers/codex/index.ts
754
- function getDirs2() {
755
- const home = os2.homedir();
756
- const candidates = [
757
- path2.join(home, ".codex", "sessions"),
758
- path2.join(home, ".codex", "archived_sessions")
759
- ];
760
- if (process.env.CCGAUGE_CODEX_DIR) {
761
- candidates.push(process.env.CCGAUGE_CODEX_DIR);
762
- }
763
- if (process.env.CODEX_HOME) {
764
- candidates.push(path2.join(process.env.CODEX_HOME, "sessions"));
765
- candidates.push(path2.join(process.env.CODEX_HOME, "archived_sessions"));
766
- }
767
- return Array.from(new Set(candidates));
768
- }
769
- var codexAdapter = {
770
- id: "codex",
771
- displayName: { en: "Codex", zh: "Codex" },
772
- shortLabel: "X",
773
- color: { fg: "#047857", bg: "#d1fae5" },
774
- logoSrc: "/codex-logo.png",
775
- // v2: switched from last_token_usage to total_token_usage delta (fixed
776
- // ~26% over-counting from duplicate/refresh token_count events).
777
- // v3: split reasoning_tokens out as a display-only breakdown alongside
778
- // output_tokens (which still includes reasoning for billing).
779
- // v4: persist `effort` from turn_context onto each emitted record so the
780
- // UI can tag the model column (e.g. `gpt-5.2-codex · high`).
781
- parserVersion: "codex-v4-effort",
782
- capabilities: {
783
- hasCacheCreation: false,
784
- hasReasoningTokens: true,
785
- blockWindowMs: 5 * 60 * 60 * 1e3
786
- },
787
- getDirs: getDirs2,
788
- shouldSkipDir: () => false,
789
- parseFile: parseCodexJsonlFile,
790
- resolvePricing: resolveCodexPricing,
791
- shortenModel: shortenCodexModel,
792
- costFromUsage,
793
- costFootnoteKey: "cost.footnote.codex"
794
- };
795
-
796
- // lib/providers/index.ts
797
- var PROVIDERS = {
798
- claude: claudeAdapter,
799
- codex: codexAdapter
800
- };
801
- var ALL_PROVIDER_IDS = ["claude", "codex"];
802
- function getProvider(id) {
803
- return PROVIDERS[id];
804
- }
805
- function listProviders() {
806
- return ALL_PROVIDER_IDS.map((id) => PROVIDERS[id]);
807
- }
808
- function isProviderId(v) {
809
- return typeof v === "string" && (v === "claude" || v === "codex");
810
- }
811
-
812
- // lib/data-loader/indexer.ts
813
- import { promises as fs3, watch as fsWatch } from "node:fs";
814
- import path4 from "node:path";
815
-
816
- // lib/dedup.ts
817
- function dedupKey(r) {
818
- const prefix = `${r.source}:`;
819
- if (r.messageId && r.requestId) return `${prefix}${r.messageId}::${r.requestId}`;
820
- if (r.messageId) return `${prefix}mid:${r.messageId}`;
821
- if (r.requestId) return `${prefix}req:${r.requestId}`;
822
- return `${prefix}uuid:${r.uuid}`;
823
- }
824
- function dedupAssistantRecords(records) {
825
- const seen = /* @__PURE__ */ new Map();
826
- for (const r of records) {
827
- const k = dedupKey(r);
828
- const existing = seen.get(k);
829
- if (!existing) {
830
- seen.set(k, r);
831
- continue;
832
- }
833
- if (r.timestamp < existing.timestamp) {
834
- seen.set(k, r);
835
- }
836
- }
837
- return Array.from(seen.values());
838
- }
839
-
840
- // lib/data-loader/index-persist.ts
841
- import { promises as fs2 } from "node:fs";
842
- import path3 from "node:path";
843
- import os3 from "node:os";
844
- var SCHEMA_VERSION = 2;
845
- var DEFAULT_INDEX_NAME = "default";
846
- function getStateDir() {
847
- if (process.env.CCGAUGE_STATE_DIR) return process.env.CCGAUGE_STATE_DIR;
848
- return path3.join(os3.homedir(), ".ccgauge");
849
- }
850
- function getIndexPath(name) {
851
- const fileName = name === DEFAULT_INDEX_NAME ? `index-v${SCHEMA_VERSION}.json` : `index-${name}-v${SCHEMA_VERSION}.json`;
852
- return path3.join(getStateDir(), "cache", fileName);
853
- }
854
- async function loadPersistedIndex(name = DEFAULT_INDEX_NAME) {
855
- const filePath = getIndexPath(name);
856
- try {
857
- const raw = await fs2.readFile(filePath, "utf8");
858
- const parsed = JSON.parse(raw);
859
- if (parsed.schemaVersion !== SCHEMA_VERSION) return null;
860
- if (!Array.isArray(parsed.files)) return null;
861
- return parsed;
862
- } catch {
863
- return null;
864
- }
865
- }
866
- async function savePersistedIndex(payload, name = DEFAULT_INDEX_NAME) {
867
- const filePath = getIndexPath(name);
868
- const dir = path3.dirname(filePath);
869
- await fs2.mkdir(dir, { recursive: true });
870
- const data = {
871
- schemaVersion: SCHEMA_VERSION,
872
- savedAt: payload.savedAt,
873
- files: payload.files
874
- };
875
- const tmp = `${filePath}.tmp-${process.pid}`;
876
- await fs2.writeFile(tmp, JSON.stringify(data));
877
- await fs2.rename(tmp, filePath);
878
- }
879
-
880
- // lib/data-loader/link-sidechain.ts
881
- var SUBAGENT_FILE_PATTERN = /\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/subagents\/agent-[^/]+\.jsonl$/i;
882
- function extractParentSessionFromSubagentPath(filePath) {
883
- const m = SUBAGENT_FILE_PATTERN.exec(filePath);
884
- return m ? m[1] : null;
885
- }
886
- function linkSidechainParents({
887
- assistantRecords,
888
- userRecords,
889
- parentMap
890
- }) {
891
- const parentAssistantsBySession = /* @__PURE__ */ new Map();
892
- for (const a of assistantRecords) {
893
- if (a.isSidechain) continue;
894
- if (!a.sessionId) continue;
895
- let list = parentAssistantsBySession.get(a.sessionId);
896
- if (!list) {
897
- list = [];
898
- parentAssistantsBySession.set(a.sessionId, list);
899
- }
900
- list.push(a);
901
- }
902
- for (const list of parentAssistantsBySession.values()) {
903
- list.sort((x, y) => x.timestamp < y.timestamp ? -1 : x.timestamp > y.timestamp ? 1 : 0);
904
- }
905
- const firstSidechainUserByFile = /* @__PURE__ */ new Map();
906
- for (const u of userRecords) {
907
- if (!u.isSidechain) continue;
908
- const existing = firstSidechainUserByFile.get(u.filePath);
909
- if (!existing || u.timestamp < existing.timestamp) {
910
- firstSidechainUserByFile.set(u.filePath, u);
911
- }
912
- }
913
- const stats = {
914
- subagentFiles: 0,
915
- relinked: 0,
916
- orphans: 0,
917
- alreadyLinked: 0
918
- };
919
- for (const [filePath, firstUser] of firstSidechainUserByFile) {
920
- const parentSessionId = extractParentSessionFromSubagentPath(filePath);
921
- if (!parentSessionId) continue;
922
- stats.subagentFiles += 1;
923
- const existingParent = parentMap[firstUser.uuid];
924
- if (existingParent !== null && existingParent !== void 0) {
925
- stats.alreadyLinked += 1;
926
- continue;
927
- }
928
- const parentAssistants = parentAssistantsBySession.get(parentSessionId);
929
- if (!parentAssistants || parentAssistants.length === 0) {
930
- stats.orphans += 1;
931
- continue;
932
- }
933
- const t0 = firstUser.timestamp;
934
- let anchor;
935
- for (let i = parentAssistants.length - 1; i >= 0; i -= 1) {
936
- if (parentAssistants[i].timestamp <= t0) {
937
- anchor = parentAssistants[i];
938
- break;
939
- }
940
- }
941
- if (!anchor) anchor = parentAssistants[0];
942
- parentMap[firstUser.uuid] = anchor.uuid;
943
- stats.relinked += 1;
944
- }
945
- return stats;
946
- }
947
-
948
- // lib/sanitize.ts
949
- import { homedir } from "node:os";
950
- function sanitizeForUser(s) {
951
- const home = homedir();
952
- if (!home) return s;
953
- const variants = /* @__PURE__ */ new Set([home]);
954
- if (process.platform === "win32") {
955
- variants.add(home.replace(/\\/g, "/"));
956
- variants.add(home.replace(/\\/g, "\\\\"));
957
- variants.add("\\\\?\\" + home);
958
- variants.add("\\\\?\\" + home.replace(/\\/g, "/"));
959
- }
960
- let out = s;
961
- for (const v of variants) {
962
- const escaped = v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
963
- out = out.replace(new RegExp(escaped, "g"), "~");
964
- }
965
- return out;
966
- }
967
-
968
- // lib/data-loader/indexer.ts
969
- var RECONCILE_DEBOUNCE_MS = 200;
970
- var SNAPSHOT_REBUILD_DEBOUNCE_MS = 100;
971
- var POLL_INTERVAL_MS = 3e4;
972
- var PERSIST_DEBOUNCE_MS = 2e3;
973
- var SCAN_DEPTH_LIMIT = 8;
974
- var MAX_ERROR_HISTORY = 20;
975
- var FileIndexer = class {
976
- /** Cache namespace — different consumers (web vs MCP) use different
977
- * names so they don't fight over the same on-disk persisted file. */
978
- cacheName;
979
- files = /* @__PURE__ */ new Map();
980
- snapshot = null;
981
- watchers = /* @__PURE__ */ new Map();
982
- pollTimer = null;
983
- snapshotRebuildTimer = null;
984
- persistTimer = null;
985
- fileDebouncers = /* @__PURE__ */ new Map();
986
- initPromise = null;
987
- isIndexing = false;
988
- lastIndexedAt = null;
989
- indexDurationMs = null;
990
- existingDirs = [];
991
- dirToProvider = /* @__PURE__ */ new Map();
992
- errors = [];
993
- loadedFromDisk = false;
994
- /** When set, rebuildSnapshotNow uses this as duration start so stats.durationMs
995
- * reflects the full operation (parse + dedup + sort), not just snapshot rebuild. */
996
- lastWorkStart = null;
997
- /** In-flight forceRescan promise. Concurrent callers coalesce onto this so we
998
- * never have two full scans clobbering each other's `files` map. */
999
- rescanPromise = null;
1000
- constructor(cacheName = DEFAULT_INDEX_NAME) {
1001
- this.cacheName = cacheName;
1002
- }
1003
- init() {
1004
- if (!this.initPromise) {
1005
- this.initPromise = this.doInit();
1006
- }
1007
- return this.initPromise;
1008
- }
1009
- async doInit() {
1010
- const start = Date.now();
1011
- this.isIndexing = true;
1012
- this.lastWorkStart = start;
1013
- try {
1014
- await this.detectProviderDirs();
1015
- const persisted = await loadPersistedIndex(this.cacheName);
1016
- this.loadedFromDisk = persisted !== null;
1017
- const persistedMap = /* @__PURE__ */ new Map();
1018
- if (persisted) {
1019
- for (const entry of persisted.files) persistedMap.set(entry.filePath, entry);
1020
- }
1021
- await this.fullScan(persistedMap);
1022
- this.rebuildSnapshotNow();
1023
- this.indexDurationMs = Date.now() - start;
1024
- this.lastIndexedAt = (/* @__PURE__ */ new Date()).toISOString();
1025
- this.syncWatchersToDirs();
1026
- this.setupPolling();
1027
- this.schedulePersist();
1028
- } finally {
1029
- this.isIndexing = false;
1030
- }
1031
- }
1032
- /** Re-detect provider data directories. Updates `dirToProvider` and `existingDirs`
1033
- * in place. Returns the diff so callers can act on added/removed dirs. */
1034
- async detectProviderDirs() {
1035
- const wanted = /* @__PURE__ */ new Map();
1036
- const dirs = [];
1037
- for (const provider of listProviders()) {
1038
- for (const dir of provider.getDirs()) {
1039
- if (await dirExists(dir)) {
1040
- if (!wanted.has(dir)) {
1041
- wanted.set(dir, provider);
1042
- dirs.push(dir);
1043
- }
1044
- }
1045
- }
1046
- }
1047
- const added = [];
1048
- const removed = [];
1049
- for (const dir of wanted.keys()) {
1050
- if (!this.dirToProvider.has(dir)) added.push(dir);
1051
- }
1052
- for (const dir of this.dirToProvider.keys()) {
1053
- if (!wanted.has(dir)) removed.push(dir);
1054
- }
1055
- this.dirToProvider = wanted;
1056
- this.existingDirs = dirs;
1057
- return { added, removed };
1058
- }
1059
- async fullScan(persistedMap) {
1060
- const fileTasks = [];
1061
- for (const [dir, provider] of this.dirToProvider) {
1062
- const files = await listJsonlFiles(dir, provider);
1063
- for (const f of files) fileTasks.push({ file: f, provider });
1064
- }
1065
- const seenPaths = new Set(fileTasks.map((t) => t.file));
1066
- await Promise.all(
1067
- fileTasks.map(async ({ file, provider }) => {
1068
- try {
1069
- const stat = await fs3.stat(file);
1070
- const persistedEntry = persistedMap.get(file);
1071
- if (persistedEntry && persistedEntry.source === provider.id && persistedEntry.parserVersion === provider.parserVersion && persistedEntry.mtimeMs === stat.mtimeMs && persistedEntry.size === stat.size) {
1072
- this.files.set(file, {
1073
- source: provider.id,
1074
- parserVersion: provider.parserVersion,
1075
- mtimeMs: stat.mtimeMs,
1076
- size: stat.size,
1077
- assistantRecords: persistedEntry.assistantRecords,
1078
- userRecords: persistedEntry.userRecords,
1079
- parentLinks: persistedEntry.parentLinks
1080
- });
1081
- return;
1082
- }
1083
- const parsed = await provider.parseFile(file);
1084
- this.files.set(file, {
1085
- source: provider.id,
1086
- parserVersion: provider.parserVersion,
1087
- mtimeMs: stat.mtimeMs,
1088
- size: stat.size,
1089
- assistantRecords: parsed.assistant,
1090
- userRecords: parsed.user,
1091
- parentLinks: parsed.parentLinks
1092
- });
1093
- } catch (err) {
1094
- this.recordError(`parse ${file}: ${err.message}`);
1095
- }
1096
- })
1097
- );
1098
- for (const tracked of Array.from(this.files.keys())) {
1099
- if (!seenPaths.has(tracked)) this.files.delete(tracked);
1100
- }
1101
- }
1102
- /** Reconcile watchers to currently-known dirs. Adds watchers for new dirs,
1103
- * closes watchers for dirs that no longer exist. Idempotent. */
1104
- syncWatchersToDirs() {
1105
- for (const [dir, watcher] of this.watchers) {
1106
- if (!this.dirToProvider.has(dir)) {
1107
- try {
1108
- watcher.close();
1109
- } catch {
1110
- }
1111
- this.watchers.delete(dir);
1112
- }
1113
- }
1114
- for (const [dir, provider] of this.dirToProvider) {
1115
- if (this.watchers.has(dir)) continue;
1116
- try {
1117
- const watcher = fsWatch(dir, { recursive: true }, (_eventType, filename) => {
1118
- if (!filename || typeof filename !== "string") return;
1119
- if (!filename.endsWith(".jsonl")) return;
1120
- const fullPath = path4.join(dir, filename);
1121
- this.scheduleFileReconcile(fullPath, provider);
1122
- });
1123
- watcher.on("error", (err) => {
1124
- this.recordError(`watcher ${dir}: ${err.message}`);
1125
- });
1126
- this.watchers.set(dir, watcher);
1127
- } catch (err) {
1128
- this.recordError(`watch ${dir}: ${err.message}`);
1129
- }
1130
- }
1131
- }
1132
- setupPolling() {
1133
- if (this.pollTimer) clearInterval(this.pollTimer);
1134
- const isMcp = this.cacheName === "mcp";
1135
- const envOpt = process.env.CCGAUGE_POLL_FALLBACK;
1136
- const enable = envOpt === "1" ? true : envOpt === "0" ? false : !isMcp;
1137
- if (!enable) return;
1138
- this.pollTimer = setInterval(() => {
1139
- this.pollOnce().catch((err) => this.recordError(`poll: ${err.message}`));
1140
- }, POLL_INTERVAL_MS);
1141
- this.pollTimer.unref?.();
1142
- }
1143
- async pollOnce() {
1144
- const start = Date.now();
1145
- const dirDiff = await this.detectProviderDirs();
1146
- let changed = dirDiff.added.length > 0 || dirDiff.removed.length > 0;
1147
- if (changed) this.syncWatchersToDirs();
1148
- const fileTasks = [];
1149
- for (const [dir, provider] of this.dirToProvider) {
1150
- const files = await listJsonlFiles(dir, provider);
1151
- for (const f of files) fileTasks.push({ file: f, provider });
1152
- }
1153
- const seenPaths = new Set(fileTasks.map((t) => t.file));
1154
- await Promise.all(
1155
- fileTasks.map(async ({ file, provider }) => {
1156
- try {
1157
- const stat = await fs3.stat(file);
1158
- const existing = this.files.get(file);
1159
- if (existing && existing.mtimeMs === stat.mtimeMs && existing.size === stat.size) {
1160
- return;
1161
- }
1162
- const parsed = await provider.parseFile(file);
1163
- this.files.set(file, {
1164
- source: provider.id,
1165
- parserVersion: provider.parserVersion,
1166
- mtimeMs: stat.mtimeMs,
1167
- size: stat.size,
1168
- assistantRecords: parsed.assistant,
1169
- userRecords: parsed.user,
1170
- parentLinks: parsed.parentLinks
1171
- });
1172
- changed = true;
1173
- } catch (err) {
1174
- this.recordError(`poll-parse ${file}: ${err.message}`);
1175
- }
1176
- })
1177
- );
1178
- for (const tracked of Array.from(this.files.keys())) {
1179
- if (!seenPaths.has(tracked)) {
1180
- this.files.delete(tracked);
1181
- changed = true;
1182
- }
1183
- }
1184
- if (changed) {
1185
- this.lastWorkStart = start;
1186
- this.scheduleSnapshotRebuild();
1187
- this.schedulePersist();
1188
- }
1189
- }
1190
- scheduleFileReconcile(filePath, provider) {
1191
- const existing = this.fileDebouncers.get(filePath);
1192
- if (existing) clearTimeout(existing);
1193
- const timer = setTimeout(() => {
1194
- this.fileDebouncers.delete(filePath);
1195
- this.reconcileFile(filePath, provider).catch(
1196
- (err) => this.recordError(`reconcile ${filePath}: ${err.message}`)
1197
- );
1198
- }, RECONCILE_DEBOUNCE_MS);
1199
- timer.unref?.();
1200
- this.fileDebouncers.set(filePath, timer);
1201
- }
1202
- async reconcileFile(filePath, provider) {
1203
- const workStart = Date.now();
1204
- let stat = null;
1205
- try {
1206
- stat = await fs3.stat(filePath);
1207
- } catch {
1208
- }
1209
- if (!stat || !stat.isFile()) {
1210
- if (this.files.has(filePath)) {
1211
- this.files.delete(filePath);
1212
- this.lastWorkStart = workStart;
1213
- this.scheduleSnapshotRebuild();
1214
- this.schedulePersist();
1215
- }
1216
- return;
1217
- }
1218
- const existing = this.files.get(filePath);
1219
- if (existing && existing.mtimeMs === stat.mtimeMs && existing.size === stat.size) {
1220
- return;
1221
- }
1222
- try {
1223
- const parsed = await provider.parseFile(filePath);
1224
- this.files.set(filePath, {
1225
- source: provider.id,
1226
- parserVersion: provider.parserVersion,
1227
- mtimeMs: stat.mtimeMs,
1228
- size: stat.size,
1229
- assistantRecords: parsed.assistant,
1230
- userRecords: parsed.user,
1231
- parentLinks: parsed.parentLinks
1232
- });
1233
- this.lastWorkStart = workStart;
1234
- this.scheduleSnapshotRebuild();
1235
- this.schedulePersist();
1236
- } catch (err) {
1237
- this.recordError(`parse ${filePath}: ${err.message}`);
1238
- }
1239
- }
1240
- scheduleSnapshotRebuild() {
1241
- if (this.snapshotRebuildTimer) clearTimeout(this.snapshotRebuildTimer);
1242
- this.snapshotRebuildTimer = setTimeout(() => {
1243
- this.snapshotRebuildTimer = null;
1244
- this.rebuildSnapshotNow();
1245
- }, SNAPSHOT_REBUILD_DEBOUNCE_MS);
1246
- this.snapshotRebuildTimer.unref?.();
1247
- }
1248
- rebuildSnapshotNow() {
1249
- const snapshotStart = Date.now();
1250
- const workStart = this.lastWorkStart ?? snapshotStart;
1251
- const assistant = [];
1252
- const user = [];
1253
- const parentMap = {};
1254
- let recordsParsed = 0;
1255
- const bySource = {
1256
- claude: {
1257
- source: "claude",
1258
- filesScanned: 0,
1259
- recordsParsed: 0,
1260
- assistantRecords: 0,
1261
- scannedDirs: []
1262
- },
1263
- codex: {
1264
- source: "codex",
1265
- filesScanned: 0,
1266
- recordsParsed: 0,
1267
- assistantRecords: 0,
1268
- scannedDirs: []
1269
- }
1270
- };
1271
- for (const [dir, provider] of this.dirToProvider) {
1272
- bySource[provider.id].scannedDirs.push(dir);
1273
- }
1274
- for (const entry of this.files.values()) {
1275
- assistant.push(...entry.assistantRecords);
1276
- user.push(...entry.userRecords);
1277
- for (const [uuid, parent] of entry.parentLinks) parentMap[uuid] = parent;
1278
- recordsParsed += entry.assistantRecords.length + entry.userRecords.length;
1279
- bySource[entry.source].filesScanned += 1;
1280
- bySource[entry.source].recordsParsed += entry.assistantRecords.length + entry.userRecords.length;
1281
- }
1282
- const dedupedAssistants = dedupAssistantRecords(assistant).sort(
1283
- (a, b) => a.timestamp.localeCompare(b.timestamp)
1284
- );
1285
- const dedupedUsers = dedupUserRecords(user).sort(
1286
- (a, b) => a.timestamp.localeCompare(b.timestamp)
1287
- );
1288
- linkSidechainParents({
1289
- assistantRecords: dedupedAssistants,
1290
- userRecords: dedupedUsers,
1291
- parentMap
1292
- });
1293
- for (const rec of dedupedAssistants) bySource[rec.source].assistantRecords += 1;
1294
- const stats = {
1295
- filesScanned: this.files.size,
1296
- recordsParsed,
1297
- assistantRecords: dedupedAssistants.length,
1298
- // Wall-clock from when this work started (parse/poll/init) to snapshot ready.
1299
- // Falls back to snapshot rebuild duration if no parse work preceded.
1300
- durationMs: Date.now() - workStart,
1301
- scannedDirs: this.existingDirs
1302
- };
1303
- this.snapshot = {
1304
- records: dedupedAssistants,
1305
- userRecords: dedupedUsers,
1306
- parentMap,
1307
- stats,
1308
- bySource: Object.values(bySource)
1309
- };
1310
- this.lastWorkStart = null;
1311
- }
1312
- getSnapshot() {
1313
- if (!this.snapshot) {
1314
- throw new Error("Indexer not initialized \u2014 call init() first.");
1315
- }
1316
- return this.snapshot;
1317
- }
1318
- async forceRescan() {
1319
- if (!this.initPromise) {
1320
- await this.init();
1321
- return this.snapshot;
1322
- }
1323
- if (this.rescanPromise) return this.rescanPromise;
1324
- this.rescanPromise = this.runRescan();
1325
- try {
1326
- return await this.rescanPromise;
1327
- } finally {
1328
- this.rescanPromise = null;
1329
- }
1330
- }
1331
- async runRescan() {
1332
- const start = Date.now();
1333
- this.isIndexing = true;
1334
- this.lastWorkStart = start;
1335
- try {
1336
- this.files.clear();
1337
- await this.detectProviderDirs();
1338
- await this.fullScan(/* @__PURE__ */ new Map());
1339
- this.rebuildSnapshotNow();
1340
- this.indexDurationMs = Date.now() - start;
1341
- this.lastIndexedAt = (/* @__PURE__ */ new Date()).toISOString();
1342
- this.syncWatchersToDirs();
1343
- this.schedulePersist();
1344
- return this.snapshot;
1345
- } finally {
1346
- this.isIndexing = false;
1347
- }
1348
- }
1349
- getStatus() {
1350
- const snap = this.snapshot;
1351
- return {
1352
- initialized: snap !== null,
1353
- isIndexing: this.isIndexing,
1354
- lastIndexedAt: this.lastIndexedAt,
1355
- indexDurationMs: this.indexDurationMs,
1356
- filesIndexed: this.files.size,
1357
- recordsIndexed: snap?.stats.assistantRecords ?? 0,
1358
- bySource: snap?.bySource ?? [],
1359
- watchers: this.watchers.size,
1360
- errors: this.errors.slice(-MAX_ERROR_HISTORY),
1361
- pendingReconciles: this.fileDebouncers.size,
1362
- loadedFromDisk: this.loadedFromDisk
1363
- };
1364
- }
1365
- schedulePersist() {
1366
- if (this.persistTimer) clearTimeout(this.persistTimer);
1367
- this.persistTimer = setTimeout(() => {
1368
- this.persistTimer = null;
1369
- const entries = [];
1370
- for (const [filePath, entry] of this.files) {
1371
- entries.push({
1372
- filePath,
1373
- source: entry.source,
1374
- parserVersion: entry.parserVersion,
1375
- mtimeMs: entry.mtimeMs,
1376
- size: entry.size,
1377
- assistantRecords: entry.assistantRecords,
1378
- userRecords: entry.userRecords,
1379
- parentLinks: entry.parentLinks
1380
- });
1381
- }
1382
- savePersistedIndex(
1383
- {
1384
- savedAt: (/* @__PURE__ */ new Date()).toISOString(),
1385
- files: entries
1386
- },
1387
- this.cacheName
1388
- ).catch((err) => this.recordError(`persist: ${err.message}`));
1389
- }, PERSIST_DEBOUNCE_MS);
1390
- this.persistTimer.unref?.();
1391
- }
1392
- recordError(msg) {
1393
- const stamped = `${(/* @__PURE__ */ new Date()).toISOString()} ${sanitizeForUser(msg)}`;
1394
- this.errors.push(stamped);
1395
- if (this.errors.length > MAX_ERROR_HISTORY * 2) {
1396
- this.errors.splice(0, this.errors.length - MAX_ERROR_HISTORY);
1397
- }
1398
- if (process.env.CCGAUGE_DEBUG) {
1399
- console.error(`[ccgauge:indexer] ${(/* @__PURE__ */ new Date()).toISOString()} ${msg}`);
1400
- }
1401
- }
1402
- disposeWatchers() {
1403
- for (const w of this.watchers.values()) {
1404
- try {
1405
- w.close();
1406
- } catch {
1407
- }
1408
- }
1409
- this.watchers.clear();
1410
- }
1411
- dispose() {
1412
- this.disposeWatchers();
1413
- if (this.pollTimer) clearInterval(this.pollTimer);
1414
- if (this.snapshotRebuildTimer) clearTimeout(this.snapshotRebuildTimer);
1415
- if (this.persistTimer) clearTimeout(this.persistTimer);
1416
- for (const t of this.fileDebouncers.values()) clearTimeout(t);
1417
- this.fileDebouncers.clear();
1418
- }
1419
- };
1420
- async function dirExists(p) {
1421
- try {
1422
- const s = await fs3.stat(p);
1423
- return s.isDirectory();
1424
- } catch {
1425
- return false;
1426
- }
1427
- }
1428
- async function listJsonlFiles(rootDir, provider) {
1429
- const out = [];
1430
- async function walk(dir, depth) {
1431
- if (depth > SCAN_DEPTH_LIMIT) return;
1432
- let entries;
1433
- try {
1434
- entries = await fs3.readdir(dir, { withFileTypes: true });
1435
- } catch {
1436
- return;
1437
- }
1438
- for (const e of entries) {
1439
- const full = path4.join(dir, e.name);
1440
- if (e.isDirectory()) {
1441
- if (provider.shouldSkipDir(e.name)) continue;
1442
- await walk(full, depth + 1);
1443
- } else if (e.isFile() && e.name.endsWith(".jsonl")) {
1444
- out.push(full);
1445
- }
1446
- }
1447
- }
1448
- await walk(rootDir, 0);
1449
- return out;
1450
- }
1451
- function dedupUserRecords(records) {
1452
- const seen = /* @__PURE__ */ new Set();
1453
- return records.filter((r) => {
1454
- const k = r.uuid;
1455
- if (!k) return true;
1456
- if (seen.has(k)) return false;
1457
- seen.add(k);
1458
- return true;
1459
- });
1460
- }
1461
- function indexerRegistry() {
1462
- if (!globalThis.__ccgaugeIndexers) {
1463
- globalThis.__ccgaugeIndexers = /* @__PURE__ */ new Map();
1464
- }
1465
- return globalThis.__ccgaugeIndexers;
1466
- }
1467
- function getIndexer(cacheName = DEFAULT_INDEX_NAME) {
1468
- const reg = indexerRegistry();
1469
- let inst = reg.get(cacheName);
1470
- if (!inst) {
1471
- inst = new FileIndexer(cacheName);
1472
- reg.set(cacheName, inst);
1473
- }
1474
- return inst;
1475
- }
1476
- var indexer = getIndexer();
1477
-
1478
- // lib/data-loader/scan.ts
1479
- async function getCachedScan(opts = {}) {
1480
- if (opts.force) {
1481
- return indexer.forceRescan();
1482
- }
1483
- await indexer.init();
1484
- return indexer.getSnapshot();
1485
- }
1486
-
1487
- // lib/pricing/calculate.ts
1488
- function costOfRecord(rec) {
1489
- const provider = getProvider(rec.source);
1490
- const { pricing } = provider.resolvePricing(rec.model);
1491
- return provider.costFromUsage(rec.usage, pricing);
1492
- }
1493
-
1494
- // lib/utils.ts
1495
- function formatNumber(n, opts) {
1496
- return new Intl.NumberFormat("en-US", {
1497
- maximumFractionDigits: opts?.maxFrac ?? 0
1498
- }).format(n);
1499
- }
1500
- function formatTokensCompact(n, locale = "en") {
1501
- if (!Number.isFinite(n)) return "0";
1502
- if (locale === "zh") {
1503
- if (n >= 1e8) return (n / 1e8).toFixed(2) + "\u4EBF";
1504
- if (n >= 1e4) return (n / 1e4).toFixed(1) + "\u4E07";
1505
- return formatNumber(n);
1506
- }
1507
- if (n >= 1e9) return (n / 1e9).toFixed(2) + "B";
1508
- if (n >= 1e6) return (n / 1e6).toFixed(2) + "M";
1509
- if (n >= 1e3) return (n / 1e3).toFixed(1) + "K";
1510
- return formatNumber(n);
1511
- }
1512
- function formatUSD(n, opts) {
1513
- return new Intl.NumberFormat("en-US", {
1514
- style: "currency",
1515
- currency: "USD",
1516
- minimumFractionDigits: opts?.minFrac ?? 2,
1517
- maximumFractionDigits: opts?.maxFrac ?? 2
1518
- }).format(n);
1519
- }
1520
- function formatPct(n, frac = 1) {
1521
- if (!Number.isFinite(n)) return "0%";
1522
- return `${(n * 100).toFixed(frac)}%`;
1523
- }
1524
- function formatDuration(ms) {
1525
- if (ms < 1e3) return `${ms}ms`;
1526
- const sec = Math.floor(ms / 1e3);
1527
- if (sec < 60) return `${sec}s`;
1528
- const min = Math.floor(sec / 60);
1529
- if (min < 60) {
1530
- const s = sec % 60;
1531
- return s ? `${min}m ${s}s` : `${min}m`;
1532
- }
1533
- const hr = Math.floor(min / 60);
1534
- const m = min % 60;
1535
- return m ? `${hr}h ${m}m` : `${hr}h`;
1536
- }
1537
- function projectNameFromCwd(cwd) {
1538
- if (!cwd) return "(unknown)";
1539
- const trimmed = cwd.replace(/[/\\]+$/, "");
1540
- const parts = trimmed.split(/[/\\]+/);
1541
- return parts[parts.length - 1] || cwd;
1542
- }
1543
-
1544
- // lib/project-label.ts
1545
- import { readFileSync, statSync } from "node:fs";
1546
- import { basename } from "node:path";
1547
- var cache = /* @__PURE__ */ new Map();
1548
- var GITDIR_PATTERN = /^(.+?)[/\\]\.git[/\\]worktrees[/\\]([^/\\]+)[/\\]?$/;
1549
- var CWD_WORKTREE_PATTERN = /^(.+?)[/\\](?:\.git|\.claude)[/\\]worktrees[/\\]([^/\\]+)(?:[/\\].*)?$/;
1550
- function resolveRaw(cwd) {
1551
- const fallbackName = projectNameFromCwd(cwd);
1552
- if (!cwd) {
1553
- return { label: fallbackName, isWorktree: false, mainName: fallbackName, worktreeName: "", canonicalCwd: cwd };
1554
- }
1555
- const pathMatch = CWD_WORKTREE_PATTERN.exec(cwd);
1556
- if (pathMatch) {
1557
- const mainRepoPath = pathMatch[1];
1558
- const worktreeName = pathMatch[2];
1559
- const mainName = basename(mainRepoPath) || mainRepoPath;
1560
- return {
1561
- label: `${mainName} (${worktreeName})`,
1562
- isWorktree: true,
1563
- mainName,
1564
- worktreeName,
1565
- canonicalCwd: mainRepoPath
1566
- };
1567
- }
1568
- try {
1569
- const gitPath = `${cwd}/.git`;
1570
- const s = statSync(gitPath);
1571
- if (!s.isFile()) {
1572
- return { label: fallbackName, isWorktree: false, mainName: fallbackName, worktreeName: "", canonicalCwd: cwd };
1573
- }
1574
- const text = readFileSync(gitPath, "utf8").trim();
1575
- const firstLine = text.split(/\r?\n/, 1)[0] ?? "";
1576
- const m = /^gitdir:\s*(.+)$/.exec(firstLine);
1577
- if (!m) {
1578
- return { label: fallbackName, isWorktree: false, mainName: fallbackName, worktreeName: "", canonicalCwd: cwd };
1579
- }
1580
- const gitdir = m[1].trim();
1581
- const wt = GITDIR_PATTERN.exec(gitdir);
1582
- if (!wt) {
1583
- return { label: fallbackName, isWorktree: false, mainName: fallbackName, worktreeName: "", canonicalCwd: cwd };
1584
- }
1585
- const mainRepoPath = wt[1];
1586
- const worktreeName = wt[2];
1587
- const mainName = basename(mainRepoPath) || mainRepoPath;
1588
- return {
1589
- label: `${mainName} (${worktreeName})`,
1590
- isWorktree: true,
1591
- mainName,
1592
- worktreeName,
1593
- canonicalCwd: mainRepoPath
1594
- };
1595
- } catch {
1596
- return { label: fallbackName, isWorktree: false, mainName: fallbackName, worktreeName: "", canonicalCwd: cwd };
1597
- }
1598
- }
1599
- function resolveProjectLabel(cwd) {
1600
- const cached = cache.get(cwd);
1601
- if (cached) return cached.label;
1602
- const r = resolveRaw(cwd);
1603
- cache.set(cwd, r);
1604
- return r.label;
1605
- }
1606
-
1607
- // lib/aggregator/index.ts
1608
- var GRANULARITIES = ["hour", "day", "week", "month"];
1609
- function isGranularity(v) {
1610
- return typeof v === "string" && GRANULARITIES.includes(v);
1611
- }
1612
- function bucketKey(ts, gran) {
1613
- const d = new Date(ts);
1614
- const yyyy = d.getFullYear();
1615
- const mm = String(d.getMonth() + 1).padStart(2, "0");
1616
- const dd = String(d.getDate()).padStart(2, "0");
1617
- const hh = String(d.getHours()).padStart(2, "0");
1618
- if (gran === "hour") {
1619
- return { key: `${yyyy}-${mm}-${dd}T${hh}`, label: `${mm}/${dd} ${hh}:00` };
1620
- }
1621
- if (gran === "day") {
1622
- return { key: `${yyyy}-${mm}-${dd}`, label: `${mm}/${dd}` };
1623
- }
1624
- if (gran === "week") {
1625
- const monday = new Date(d);
1626
- const day = monday.getDay() || 7;
1627
- monday.setDate(monday.getDate() - day + 1);
1628
- const wm = String(monday.getMonth() + 1).padStart(2, "0");
1629
- const wd = String(monday.getDate()).padStart(2, "0");
1630
- return {
1631
- key: `${monday.getFullYear()}-W${wm}${wd}`,
1632
- label: `Wk ${wm}/${wd}`
1633
- };
1634
- }
1635
- return { key: `${yyyy}-${mm}`, label: `${yyyy}-${mm}` };
1636
- }
1637
- function prepareOpts(opts) {
1638
- return {
1639
- source: opts.source,
1640
- fromIso: opts.from?.toISOString(),
1641
- toIso: opts.to?.toISOString(),
1642
- models: opts.models && opts.models.length ? new Set(opts.models) : void 0,
1643
- projects: opts.projects && opts.projects.length ? new Set(opts.projects) : void 0
1644
- };
1645
- }
1646
- function withinRangePrepared(rec, p) {
1647
- if (rec.source !== p.source) return false;
1648
- if (p.fromIso && rec.timestamp < p.fromIso) return false;
1649
- if (p.toIso && rec.timestamp > p.toIso) return false;
1650
- if (p.models && !p.models.has(rec.model)) return false;
1651
- if (p.projects && !p.projects.has(rec.cwd)) return false;
1652
- return true;
1653
- }
1654
- function aggregateByTime(records, gran, opts) {
1655
- const buckets = /* @__PURE__ */ new Map();
1656
- const prepared = prepareOpts(opts);
1657
- for (const rec of records) {
1658
- if (!withinRangePrepared(rec, prepared)) continue;
1659
- const { key, label } = bucketKey(rec.timestamp, gran);
1660
- let b = buckets.get(key);
1661
- if (!b) {
1662
- b = makeBucket(key, label);
1663
- buckets.set(key, b);
1664
- }
1665
- pushRecord(b, rec);
1666
- }
1667
- return Array.from(buckets.values()).sort((a, b) => a.key.localeCompare(b.key));
1668
- }
1669
- function makeBucket(key, label) {
1670
- return {
1671
- key,
1672
- label,
1673
- inputTokens: 0,
1674
- outputTokens: 0,
1675
- cacheReadTokens: 0,
1676
- cacheCreationTokens: 0,
1677
- totalTokens: 0,
1678
- cost: 0,
1679
- saved: 0,
1680
- requests: 0,
1681
- models: {}
1682
- };
1683
- }
1684
- function pushRecord(b, rec) {
1685
- const cost = costOfRecord(rec);
1686
- b.inputTokens += rec.usage.input_tokens;
1687
- b.outputTokens += rec.usage.output_tokens;
1688
- b.cacheReadTokens += rec.usage.cache_read_input_tokens;
1689
- b.cacheCreationTokens += rec.usage.cache_creation_input_tokens;
1690
- b.totalTokens = b.inputTokens + b.outputTokens + b.cacheReadTokens + b.cacheCreationTokens;
1691
- b.cost += cost.total;
1692
- b.saved += cost.saved;
1693
- b.requests += 1;
1694
- const m = b.models[rec.model] ?? { tokens: 0, cost: 0, requests: 0 };
1695
- m.tokens += rec.usage.input_tokens + rec.usage.output_tokens + rec.usage.cache_read_input_tokens + rec.usage.cache_creation_input_tokens;
1696
- m.cost += cost.total;
1697
- m.requests += 1;
1698
- b.models[rec.model] = m;
1699
- }
1700
- function aggregateByModel(records, opts) {
1701
- const map = /* @__PURE__ */ new Map();
1702
- const prepared = prepareOpts(opts);
1703
- for (const rec of records) {
1704
- if (!withinRangePrepared(rec, prepared)) continue;
1705
- let s = map.get(rec.model);
1706
- if (!s) {
1707
- const { pricing, matchType } = getProvider(rec.source).resolvePricing(rec.model);
1708
- s = {
1709
- model: rec.model,
1710
- source: rec.source,
1711
- requests: 0,
1712
- inputTokens: 0,
1713
- outputTokens: 0,
1714
- cacheReadTokens: 0,
1715
- cacheCreationTokens: 0,
1716
- totalTokens: 0,
1717
- cost: 0,
1718
- saved: 0,
1719
- pricing,
1720
- pricingResolved: matchType === "exact" || matchType === "date-stripped" || matchType === "prefix-stripped"
1721
- };
1722
- map.set(rec.model, s);
1723
- }
1724
- const cost = costOfRecord(rec);
1725
- s.requests += 1;
1726
- s.inputTokens += rec.usage.input_tokens;
1727
- s.outputTokens += rec.usage.output_tokens;
1728
- s.cacheReadTokens += rec.usage.cache_read_input_tokens;
1729
- s.cacheCreationTokens += rec.usage.cache_creation_input_tokens;
1730
- s.totalTokens = s.inputTokens + s.outputTokens + s.cacheReadTokens + s.cacheCreationTokens;
1731
- s.cost += cost.total;
1732
- s.saved += cost.saved;
1733
- }
1734
- return Array.from(map.values()).sort((a, b) => b.cost - a.cost);
1735
- }
1736
- function aggregateByProject(records, opts) {
1737
- const map = /* @__PURE__ */ new Map();
1738
- const sessionsByProject = /* @__PURE__ */ new Map();
1739
- const prepared = prepareOpts(opts);
1740
- for (const rec of records) {
1741
- if (!withinRangePrepared(rec, prepared)) continue;
1742
- const cwd = rec.cwd || "(unknown)";
1743
- let s = map.get(cwd);
1744
- if (!s) {
1745
- s = {
1746
- source: opts.source,
1747
- cwd,
1748
- projectName: projectNameFromCwd(cwd),
1749
- sessions: 0,
1750
- requests: 0,
1751
- inputTokens: 0,
1752
- outputTokens: 0,
1753
- cacheReadTokens: 0,
1754
- cacheCreationTokens: 0,
1755
- totalTokens: 0,
1756
- cost: 0,
1757
- saved: 0,
1758
- firstActivity: rec.timestamp,
1759
- lastActivity: rec.timestamp,
1760
- models: []
1761
- };
1762
- map.set(cwd, s);
1763
- sessionsByProject.set(cwd, /* @__PURE__ */ new Set());
1764
- }
1765
- sessionsByProject.get(cwd).add(rec.sessionId);
1766
- const cost = costOfRecord(rec);
1767
- s.requests += 1;
1768
- s.inputTokens += rec.usage.input_tokens;
1769
- s.outputTokens += rec.usage.output_tokens;
1770
- s.cacheReadTokens += rec.usage.cache_read_input_tokens;
1771
- s.cacheCreationTokens += rec.usage.cache_creation_input_tokens;
1772
- s.totalTokens = s.inputTokens + s.outputTokens + s.cacheReadTokens + s.cacheCreationTokens;
1773
- s.cost += cost.total;
1774
- s.saved += cost.saved;
1775
- if (rec.timestamp < s.firstActivity) s.firstActivity = rec.timestamp;
1776
- if (rec.timestamp > s.lastActivity) s.lastActivity = rec.timestamp;
1777
- if (!s.models.includes(rec.model)) s.models.push(rec.model);
1778
- }
1779
- for (const [cwd, set] of sessionsByProject) {
1780
- const s = map.get(cwd);
1781
- s.sessions = set.size;
1782
- }
1783
- return Array.from(map.values()).sort((a, b) => b.cost - a.cost);
1784
- }
1785
- function aggregateBySession(records, userRecords, opts) {
1786
- const map = /* @__PURE__ */ new Map();
1787
- const prepared = prepareOpts(opts);
1788
- for (const rec of records) {
1789
- if (!withinRangePrepared(rec, prepared)) continue;
1790
- const sid = rec.sessionId || rec.uuid;
1791
- let s = map.get(sid);
1792
- if (!s) {
1793
- s = {
1794
- sessionId: sid,
1795
- source: rec.source,
1796
- cwd: rec.cwd,
1797
- projectName: projectNameFromCwd(rec.cwd),
1798
- // Worktree-aware label so the sessions table shows the same
1799
- // identifier the usage table does for the same record (e.g.
1800
- // `ai-self-web (playwright)` instead of just `playwright`).
1801
- // `resolveProjectLabel` caches per-cwd, so this is one fs.stat
1802
- // per unique cwd across the whole aggregation.
1803
- projectLabel: resolveProjectLabel(rec.cwd),
1804
- startTime: rec.timestamp,
1805
- endTime: rec.timestamp,
1806
- durationMs: 0,
1807
- requests: 0,
1808
- inputTokens: 0,
1809
- outputTokens: 0,
1810
- cacheReadTokens: 0,
1811
- cacheCreationTokens: 0,
1812
- totalTokens: 0,
1813
- cost: 0,
1814
- saved: 0,
1815
- models: [],
1816
- modelBreakdown: {}
1817
- };
1818
- map.set(sid, s);
1819
- }
1820
- const cost = costOfRecord(rec);
1821
- s.requests += 1;
1822
- s.inputTokens += rec.usage.input_tokens;
1823
- s.outputTokens += rec.usage.output_tokens;
1824
- s.cacheReadTokens += rec.usage.cache_read_input_tokens;
1825
- s.cacheCreationTokens += rec.usage.cache_creation_input_tokens;
1826
- s.totalTokens = s.inputTokens + s.outputTokens + s.cacheReadTokens + s.cacheCreationTokens;
1827
- s.cost += cost.total;
1828
- s.saved += cost.saved;
1829
- if (rec.timestamp < s.startTime) s.startTime = rec.timestamp;
1830
- if (rec.timestamp > s.endTime) s.endTime = rec.timestamp;
1831
- if (!s.models.includes(rec.model)) s.models.push(rec.model);
1832
- const mb = s.modelBreakdown[rec.model] ?? { tokens: 0, cost: 0, requests: 0 };
1833
- mb.tokens += rec.usage.input_tokens + rec.usage.output_tokens + rec.usage.cache_read_input_tokens + rec.usage.cache_creation_input_tokens;
1834
- mb.cost += cost.total;
1835
- mb.requests += 1;
1836
- s.modelBreakdown[rec.model] = mb;
1837
- }
1838
- const firstUserBySession = /* @__PURE__ */ new Map();
1839
- for (const u of userRecords) {
1840
- const existing = firstUserBySession.get(u.sessionId);
1841
- if (!existing || u.timestamp < existing.timestamp) {
1842
- firstUserBySession.set(u.sessionId, u);
1843
- }
1844
- }
1845
- for (const s of map.values()) {
1846
- s.durationMs = Math.max(0, new Date(s.endTime).getTime() - new Date(s.startTime).getTime());
1847
- const u = firstUserBySession.get(s.sessionId);
1848
- if (u && u.textPreview) {
1849
- s.firstUserMessage = u.textPreview;
1850
- s.title = u.textPreview.slice(0, 80);
1851
- }
1852
- }
1853
- return Array.from(map.values()).sort((a, b) => b.endTime.localeCompare(a.endTime));
1854
- }
1855
- function aggregateTotals(records, opts) {
1856
- let inputTokens = 0;
1857
- let outputTokens = 0;
1858
- let cacheReadTokens = 0;
1859
- let cacheCreationTokens = 0;
1860
- let cost = 0;
1861
- let saved = 0;
1862
- let requests = 0;
1863
- const prepared = prepareOpts(opts);
1864
- for (const rec of records) {
1865
- if (!withinRangePrepared(rec, prepared)) continue;
1866
- const c = costOfRecord(rec);
1867
- inputTokens += rec.usage.input_tokens;
1868
- outputTokens += rec.usage.output_tokens;
1869
- cacheReadTokens += rec.usage.cache_read_input_tokens;
1870
- cacheCreationTokens += rec.usage.cache_creation_input_tokens;
1871
- cost += c.total;
1872
- saved += c.saved;
1873
- requests += 1;
1874
- }
1875
- return {
1876
- inputTokens,
1877
- outputTokens,
1878
- cacheReadTokens,
1879
- cacheCreationTokens,
1880
- totalTokens: inputTokens + outputTokens + cacheReadTokens + cacheCreationTokens,
1881
- cost,
1882
- saved,
1883
- requests
1884
- };
1885
- }
1886
-
1887
- // lib/range.ts
1888
- var USAGE_RANGES = ["1d", "7d", "30d", "90d", "all", "custom"];
1889
- function isUsageRange(v) {
1890
- return typeof v === "string" && USAGE_RANGES.includes(v);
1891
- }
1892
- function rangeToDates(range) {
1893
- const now = /* @__PURE__ */ new Date();
1894
- if (range === "all" || range === "custom") return {};
1895
- if (range === "1d") {
1896
- const from2 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
1897
- return { from: from2 };
1898
- }
1899
- const m = range.match(/^(\d+)([dwm])$/);
1900
- if (!m) return {};
1901
- const n = parseInt(m[1], 10);
1902
- const unit = m[2];
1903
- const from = new Date(now);
1904
- if (unit === "d") from.setDate(from.getDate() - n);
1905
- else if (unit === "w") from.setDate(from.getDate() - n * 7);
1906
- else if (unit === "m") from.setMonth(from.getMonth() - n);
1907
- return { from };
1908
- }
1909
-
1910
- // lib/turns.ts
1911
- var MAX_PARENT_WALK = 5e3;
1912
- function buildTurnIndex(assistants, users, parentMap) {
1913
- const userTextMap = /* @__PURE__ */ new Map();
1914
- for (const u of users) {
1915
- if (u.isSynthetic) continue;
1916
- if (u.textPreview && u.textPreview.trim()) userTextMap.set(u.uuid, u.textPreview);
1917
- }
1918
- const result = /* @__PURE__ */ new Map();
1919
- const memo = /* @__PURE__ */ new Map();
1920
- function resolve(startUuid) {
1921
- const path5 = [];
1922
- let cur = startUuid;
1923
- let answer = null;
1924
- let steps = 0;
1925
- const seen = /* @__PURE__ */ new Set();
1926
- while (cur && steps++ < MAX_PARENT_WALK) {
1927
- if (seen.has(cur)) break;
1928
- seen.add(cur);
1929
- const m = memo.get(cur);
1930
- if (m) {
1931
- answer = m;
1932
- break;
1933
- }
1934
- path5.push(cur);
1935
- if (userTextMap.has(cur)) {
1936
- answer = cur;
1937
- break;
1938
- }
1939
- cur = parentMap[cur] ?? null;
1940
- }
1941
- if (!answer) answer = startUuid;
1942
- for (const id of path5) memo.set(id, answer);
1943
- return answer;
1944
- }
1945
- for (const a of assistants) {
1946
- result.set(a.uuid, resolve(a.uuid));
1947
- }
1948
- return result;
1949
- }
1950
- function summarizeTurns(records, users, parentMap) {
1951
- const turnIndex = buildTurnIndex(records, users, parentMap);
1952
- const out = /* @__PURE__ */ new Map();
1953
- for (const r of records) {
1954
- const turnId = turnIndex.get(r.uuid) ?? r.uuid;
1955
- const existing = out.get(turnId);
1956
- if (!existing || r.timestamp < existing.firstTimestamp) {
1957
- out.set(turnId, {
1958
- turnId,
1959
- firstTimestamp: r.timestamp,
1960
- firstModel: r.model,
1961
- cwd: r.cwd,
1962
- sessionId: r.sessionId,
1963
- source: r.source
1964
- });
1965
- }
1966
- }
1967
- return out;
1968
- }
1969
-
1970
- // lib/blocks/compute.ts
1971
- var DEFAULT_BLOCK_WINDOW_MS = 5 * 60 * 60 * 1e3;
1972
- function computeBlocks(records, windowMs = DEFAULT_BLOCK_WINDOW_MS) {
1973
- if (records.length === 0) return [];
1974
- const sorted = [...records].sort((a, b) => a.timestamp.localeCompare(b.timestamp));
1975
- const blocks = [];
1976
- let current = null;
1977
- let blockStartMs = 0;
1978
- const now = Date.now();
1979
- for (const rec of sorted) {
1980
- const t = new Date(rec.timestamp).getTime();
1981
- if (!current || t - blockStartMs >= windowMs) {
1982
- blockStartMs = t;
1983
- current = {
1984
- id: rec.timestamp,
1985
- startTime: rec.timestamp,
1986
- endTime: new Date(t + windowMs).toISOString(),
1987
- actualEndTime: rec.timestamp,
1988
- isActive: false,
1989
- inputTokens: 0,
1990
- outputTokens: 0,
1991
- cacheReadTokens: 0,
1992
- cacheCreationTokens: 0,
1993
- totalTokens: 0,
1994
- cost: 0,
1995
- saved: 0,
1996
- models: [],
1997
- requests: 0
1998
- };
1999
- blocks.push(current);
2000
- }
2001
- const cost = costOfRecord(rec);
2002
- current.inputTokens += rec.usage.input_tokens;
2003
- current.outputTokens += rec.usage.output_tokens;
2004
- current.cacheReadTokens += rec.usage.cache_read_input_tokens;
2005
- current.cacheCreationTokens += rec.usage.cache_creation_input_tokens;
2006
- current.totalTokens = current.inputTokens + current.outputTokens + current.cacheReadTokens + current.cacheCreationTokens;
2007
- current.cost += cost.total;
2008
- current.saved += cost.saved;
2009
- current.requests += 1;
2010
- current.actualEndTime = rec.timestamp;
2011
- if (!current.models.includes(rec.model)) current.models.push(rec.model);
2012
- }
2013
- for (const b of blocks) {
2014
- const endMs = new Date(b.endTime).getTime();
2015
- b.isActive = now < endMs;
2016
- }
2017
- return blocks;
2018
- }
2019
- function getActiveBlock(records, windowMs = DEFAULT_BLOCK_WINDOW_MS) {
2020
- const blocks = computeBlocks(records, windowMs);
2021
- const active = blocks.find((b) => b.isActive);
2022
- return active ?? null;
2023
- }
2024
- function blockProgress(records, windowMs = DEFAULT_BLOCK_WINDOW_MS) {
2025
- const block = getActiveBlock(records, windowMs);
2026
- if (!block) {
2027
- return {
2028
- block: null,
2029
- windowMs,
2030
- elapsedMs: 0,
2031
- remainingMs: 0,
2032
- progress: 0,
2033
- burnRatePerMin: 0,
2034
- costPerMin: 0,
2035
- projectedTotal: 0,
2036
- projectedCost: 0
2037
- };
2038
- }
2039
- const now = Date.now();
2040
- const startMs = new Date(block.startTime).getTime();
2041
- const endMs = new Date(block.endTime).getTime();
2042
- const elapsedMs = now - startMs;
2043
- const remainingMs = Math.max(0, endMs - now);
2044
- const progress = Math.min(1, elapsedMs / windowMs);
2045
- const elapsedMin = elapsedMs / 6e4;
2046
- const burnRatePerMin = elapsedMin > 0 ? block.totalTokens / elapsedMin : 0;
2047
- const costPerMin = elapsedMin > 0 ? block.cost / elapsedMin : 0;
2048
- const totalMin = windowMs / 6e4;
2049
- return {
2050
- block,
2051
- windowMs,
2052
- elapsedMs,
2053
- remainingMs,
2054
- progress,
2055
- burnRatePerMin,
2056
- costPerMin,
2057
- projectedTotal: burnRatePerMin * totalMin,
2058
- projectedCost: costPerMin * totalMin
2059
- };
2060
- }
2061
-
2062
- // lib/aggregator/activity.ts
2063
- var DAY_MS = 864e5;
2064
- function computeActivityStats(records, opts) {
2065
- const filtered = opts.source === "all" ? records : records.filter((r) => r.source === opts.source);
2066
- if (filtered.length === 0) {
2067
- return {
2068
- sessions: 0,
2069
- messages: 0,
2070
- totalTokens: 0,
2071
- activeDays: 0,
2072
- currentStreak: 0,
2073
- longestStreak: 0,
2074
- peakHour: -1,
2075
- favoriteModel: null,
2076
- heatmap: emptyHeatmap(),
2077
- heatmapMax: 0,
2078
- tokenHeatmap: emptyHeatmap(),
2079
- tokensSummed: 0
2080
- };
2081
- }
2082
- const sessionSet = /* @__PURE__ */ new Set();
2083
- const dayKeys = /* @__PURE__ */ new Set();
2084
- const hourCounts = new Array(24).fill(0);
2085
- const modelCounts = /* @__PURE__ */ new Map();
2086
- const heatmap = emptyHeatmap();
2087
- const tokenHeatmap = emptyHeatmap();
2088
- let totalTokens2 = 0;
2089
- let messages = 0;
2090
- for (const r of filtered) {
2091
- if (r.sessionId) sessionSet.add(r.sessionId);
2092
- const d = new Date(r.timestamp);
2093
- if (Number.isNaN(d.getTime())) continue;
2094
- const dayKey = localDayKey(d);
2095
- dayKeys.add(dayKey);
2096
- const dow = d.getDay();
2097
- const hour = d.getHours();
2098
- hourCounts[hour] += 1;
2099
- heatmap[dow][hour] += 1;
2100
- modelCounts.set(r.model, (modelCounts.get(r.model) ?? 0) + 1);
2101
- const u = r.usage;
2102
- const recTokens = u.input_tokens + u.output_tokens + u.cache_read_input_tokens + u.cache_creation_input_tokens;
2103
- tokenHeatmap[dow][hour] += recTokens;
2104
- totalTokens2 += recTokens;
2105
- messages += 1;
2106
- }
2107
- const peakHour = argMax(hourCounts);
2108
- const favoriteModel = pickTopKey(modelCounts);
2109
- const { current, longest } = computeStreaks(dayKeys, opts.streakWindowDays ?? 365);
2110
- let heatmapMax = 0;
2111
- for (const row of heatmap) for (const v of row) if (v > heatmapMax) heatmapMax = v;
2112
- return {
2113
- sessions: sessionSet.size,
2114
- messages,
2115
- totalTokens: totalTokens2,
2116
- activeDays: dayKeys.size,
2117
- currentStreak: current,
2118
- longestStreak: longest,
2119
- peakHour,
2120
- favoriteModel,
2121
- heatmap,
2122
- heatmapMax,
2123
- tokenHeatmap,
2124
- tokensSummed: totalTokens2
2125
- };
2126
- }
2127
- function emptyHeatmap() {
2128
- return Array.from({ length: 7 }, () => new Array(24).fill(0));
2129
- }
2130
- function localDayKey(d) {
2131
- const yyyy = d.getFullYear();
2132
- const mm = String(d.getMonth() + 1).padStart(2, "0");
2133
- const dd = String(d.getDate()).padStart(2, "0");
2134
- return `${yyyy}-${mm}-${dd}`;
2135
- }
2136
- function argMax(arr) {
2137
- let bestIdx = -1;
2138
- let best = -1;
2139
- for (let i = 0; i < arr.length; i += 1) {
2140
- if (arr[i] > best) {
2141
- best = arr[i];
2142
- bestIdx = i;
2143
- }
2144
- }
2145
- return bestIdx;
2146
- }
2147
- function pickTopKey(m) {
2148
- let best = null;
2149
- let bestN = -1;
2150
- for (const [k, v] of m) {
2151
- if (v > bestN) {
2152
- best = k;
2153
- bestN = v;
2154
- }
2155
- }
2156
- return best;
2157
- }
2158
- function computeStreaks(dayKeys, windowDays) {
2159
- if (dayKeys.size === 0) return { current: 0, longest: 0 };
2160
- const days = Array.from(dayKeys).map((k) => (/* @__PURE__ */ new Date(k + "T00:00:00")).getTime()).filter((t) => Number.isFinite(t)).sort((a, b) => a - b);
2161
- let longest = 1;
2162
- let run = 1;
2163
- for (let i = 1; i < days.length; i += 1) {
2164
- if (days[i] - days[i - 1] === DAY_MS) {
2165
- run += 1;
2166
- if (run > longest) longest = run;
2167
- } else {
2168
- run = 1;
2169
- }
2170
- }
2171
- const todayMs = atMidnight(Date.now());
2172
- const lastDay = days[days.length - 1];
2173
- if (todayMs - lastDay > DAY_MS) {
2174
- return { current: 0, longest };
2175
- }
2176
- let cursor = lastDay;
2177
- let current = 0;
2178
- let scanned = 0;
2179
- const inSet = new Set(days);
2180
- while (scanned < windowDays && inSet.has(cursor)) {
2181
- current += 1;
2182
- cursor -= DAY_MS;
2183
- scanned += 1;
2184
- }
2185
- return { current, longest };
2186
- }
2187
- function atMidnight(ms) {
2188
- const d = new Date(ms);
2189
- d.setHours(0, 0, 0, 0);
2190
- return d.getTime();
2191
- }
2192
-
2193
- // lib/cli-report/ansi.ts
2194
- var RGB = {
2195
- brand: [129, 140, 248],
2196
- // indigo-400
2197
- green: [34, 197, 94],
2198
- red: [239, 68, 68],
2199
- yellow: [234, 179, 8],
2200
- cyan: [34, 211, 238],
2201
- input: [96, 165, 250],
2202
- // blue-400
2203
- cacheWrite: [167, 139, 250],
2204
- // purple-400
2205
- cacheRead: [52, 211, 153],
2206
- // emerald-400
2207
- output: [251, 146, 60]
2208
- // orange-400
2209
- };
2210
- function fg(rgb, useColor) {
2211
- if (!useColor) return (s) => s;
2212
- const prefix = `\x1B[38;2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
2213
- return (s) => `${prefix}${s}\x1B[39m`;
2214
- }
2215
- function wrap(open, close, useColor) {
2216
- if (!useColor) return (s) => s;
2217
- return (s) => `${open}${s}${close}`;
2218
- }
2219
- function makePalette(useColor) {
2220
- return {
2221
- reset: useColor ? "\x1B[0m" : "",
2222
- bold: wrap("\x1B[1m", "\x1B[22m", useColor),
2223
- dim: wrap("\x1B[2m", "\x1B[22m", useColor),
2224
- brand: fg(RGB.brand, useColor),
2225
- green: fg(RGB.green, useColor),
2226
- red: fg(RGB.red, useColor),
2227
- yellow: fg(RGB.yellow, useColor),
2228
- cyan: fg(RGB.cyan, useColor),
2229
- input: fg(RGB.input, useColor),
2230
- cacheWrite: fg(RGB.cacheWrite, useColor),
2231
- cacheRead: fg(RGB.cacheRead, useColor),
2232
- output: fg(RGB.output, useColor)
2233
- };
2234
- }
2235
- var ANSI_RE = /\x1b\[[0-9;]*m/g;
2236
- function visibleLen(s) {
2237
- return s.replace(ANSI_RE, "").length;
2238
- }
2239
- function padEnd(s, w, fill = " ") {
2240
- const need = w - visibleLen(s);
2241
- return need > 0 ? s + fill.repeat(need) : s;
2242
- }
2243
- function padStart(s, w, fill = " ") {
2244
- const need = w - visibleLen(s);
2245
- return need > 0 ? fill.repeat(need) + s : s;
2246
- }
2247
- function center(s, w, fill = " ") {
2248
- const need = w - visibleLen(s);
2249
- if (need <= 0) return s;
2250
- const l = Math.floor(need / 2);
2251
- const r = need - l;
2252
- return fill.repeat(l) + s + fill.repeat(r);
2253
- }
2254
- function truncate(s, w) {
2255
- if (visibleLen(s) <= w) return s;
2256
- return s.slice(0, Math.max(0, w - 1)) + "\u2026";
2257
- }
2258
- var HBAR_CHARS = ["", "\u258F", "\u258E", "\u258D", "\u258C", "\u258B", "\u258A", "\u2589", "\u2588"];
2259
- function hbar(ratio, width, color) {
2260
- if (width <= 0 || !Number.isFinite(ratio) || ratio <= 0) {
2261
- return " ".repeat(Math.max(0, width));
2262
- }
2263
- const r = Math.min(1, ratio);
2264
- const filledCells = r * width;
2265
- const fullCells = Math.floor(filledCells);
2266
- const remainder = filledCells - fullCells;
2267
- const subIdx = Math.round(remainder * 8);
2268
- let bar = "\u2588".repeat(fullCells);
2269
- if (subIdx > 0 && fullCells < width) bar += HBAR_CHARS[subIdx];
2270
- const out = padEnd(bar, width, " ");
2271
- return color ? color(out) : out;
2272
- }
2273
- var SPARK = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
2274
- function sparkline(values, width, color) {
2275
- if (width <= 0) return "";
2276
- if (values.length === 0) return color ? color("\u2500".repeat(width)) : "\u2500".repeat(width);
2277
- const sampled = [];
2278
- if (values.length === width) {
2279
- sampled.push(...values);
2280
- } else if (values.length > width) {
2281
- const step = values.length / width;
2282
- for (let i = 0; i < width; i += 1) {
2283
- const lo = Math.floor(i * step);
2284
- const hi = Math.floor((i + 1) * step);
2285
- let sum = 0;
2286
- let n = 0;
2287
- for (let j = lo; j < Math.min(hi, values.length); j += 1) {
2288
- sum += values[j];
2289
- n += 1;
2290
- }
2291
- sampled.push(n > 0 ? sum / n : 0);
2292
- }
2293
- } else {
2294
- const pad = width - values.length;
2295
- for (let i = 0; i < pad; i += 1) sampled.push(0);
2296
- sampled.push(...values);
2297
- }
2298
- const max = Math.max(...sampled, 0);
2299
- if (max <= 0) {
2300
- const flat = "\u2500".repeat(width);
2301
- return color ? color(flat) : flat;
2302
- }
2303
- const out = sampled.map((v) => SPARK[Math.min(7, Math.max(0, Math.round(v / max * 7)))]).join("");
2304
- return color ? color(out) : out;
2305
- }
2306
- var VBAR_CHARS = ["", "\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
2307
- function stackedColumn(segments, height, maxValue) {
2308
- const lines = new Array(height).fill(" ");
2309
- if (height <= 0 || maxValue <= 0) return lines;
2310
- const total = segments.reduce((s, x) => s + Math.max(0, x.value), 0);
2311
- if (total <= 0) return lines;
2312
- const totalUnits = total / maxValue * height * 8;
2313
- const cap = height * 8;
2314
- const used = Math.min(totalUnits, cap);
2315
- let remaining = used;
2316
- let cursorUnits = 0;
2317
- for (const seg of segments) {
2318
- if (seg.value <= 0 || remaining <= 0) continue;
2319
- const segUnits = Math.min(remaining, seg.value / total * used);
2320
- const startUnits = cursorUnits;
2321
- const endUnits = cursorUnits + segUnits;
2322
- const startRow = Math.floor(startUnits / 8);
2323
- const endRow = Math.min(height - 1, Math.floor((endUnits - 1e-4) / 8));
2324
- for (let row = startRow; row <= endRow; row += 1) {
2325
- const rowBottom = row * 8;
2326
- const rowTop = (row + 1) * 8;
2327
- const fillBottom = Math.max(0, startUnits - rowBottom);
2328
- const fillTop = Math.min(8, endUnits - rowBottom);
2329
- let ch;
2330
- if (fillTop >= 8) {
2331
- ch = "\u2588";
2332
- } else if (fillBottom <= 0) {
2333
- const idx = Math.max(1, Math.round(fillTop));
2334
- ch = VBAR_CHARS[Math.min(8, idx)] || "\u2581";
2335
- } else {
2336
- ch = "\u2588";
2337
- }
2338
- lines[height - 1 - row] = seg.color ? seg.color(ch) : ch;
2339
- }
2340
- remaining -= segUnits;
2341
- cursorUnits = endUnits;
2342
- }
2343
- return lines;
2344
- }
2345
- function box(title, contentLines, innerWidth, c) {
2346
- const titleStr = title ? ` ${title} ` : "";
2347
- const tLen = visibleLen(titleStr);
2348
- const beforeLen = Math.max(1, Math.floor((innerWidth - tLen) / 2));
2349
- const afterLen = Math.max(1, innerWidth - tLen - beforeLen);
2350
- const top = c.dim("\u250C" + "\u2500".repeat(beforeLen)) + (title ? c.bold(titleStr) : "\u2500".repeat(tLen)) + c.dim("\u2500".repeat(afterLen) + "\u2510");
2351
- const bot = c.dim("\u2514" + "\u2500".repeat(innerWidth) + "\u2518");
2352
- const body = contentLines.map((line) => c.dim("\u2502") + " " + padEnd(line, innerWidth - 2) + " " + c.dim("\u2502")).join("\n");
2353
- return [top, body, bot].join("\n");
2354
- }
2355
- function twoColumns(left, right, gap = 2) {
2356
- const ls = left.split("\n");
2357
- const rs = right.split("\n");
2358
- const h = Math.max(ls.length, rs.length);
2359
- const lw = Math.max(0, ...ls.map(visibleLen));
2360
- const sep = " ".repeat(Math.max(1, gap));
2361
- const out = [];
2362
- for (let i = 0; i < h; i += 1) {
2363
- const L = padEnd(ls[i] ?? "", lw);
2364
- const R = rs[i] ?? "";
2365
- out.push(L + sep + R);
2366
- }
2367
- return out.join("\n");
2368
- }
2369
-
2370
- // lib/cli-report/dash.ts
2371
- function renderDash(scan, data, opts, filteredRecords) {
2372
- const width = opts.width ?? process.stdout.columns ?? 100;
2373
- const useColor = opts.color !== false;
2374
- const c = makePalette(useColor);
2375
- if (width < 80) {
2376
- return [
2377
- `[ccgauge] terminal width (${width}) is below the dashboard's 80-column floor.`,
2378
- `Resize wider for the rich layout, or omit --dashboard for the standard report.`,
2379
- "",
2380
- ...renderText(data, opts).split("\n")
2381
- ].join("\n");
2382
- }
2383
- const inner = width - 4;
2384
- const lines = [];
2385
- if (opts.banner !== false) {
2386
- lines.push(...renderBanner(c, inner, data));
2387
- lines.push("");
2388
- }
2389
- lines.push(...renderKpiTiles(c, inner, scan, data));
2390
- lines.push("");
2391
- if (opts.compact !== true && data.trend.length > 0) {
2392
- lines.push(...renderTrend(c, inner, data));
2393
- lines.push("");
2394
- }
2395
- lines.push(...renderBreakdowns(c, inner, data));
2396
- lines.push("");
2397
- lines.push(...renderHeatmap(c, inner, filteredRecords));
2398
- lines.push("");
2399
- lines.push(...renderFooter(c, inner, filteredRecords, data, opts));
2400
- return lines.map((l) => " " + l).join("\n");
2401
- }
2402
- function renderBanner(c, w, data) {
2403
- const title = `${c.brand(c.bold("ccgauge"))} ${c.bold("dashboard")}`;
2404
- const meta = c.dim(
2405
- [
2406
- `range: ${data.range}`,
2407
- `source: ${data.source}`,
2408
- `by: ${data.by}`,
2409
- `generated ${new Date(data.generatedAt).toLocaleString()}`
2410
- ].join(" \xB7 ")
2411
- );
2412
- const titlePart = ` ${title} `;
2413
- const metaPart = ` ${meta} `;
2414
- const fillLen = Math.max(0, w - visibleLen(titlePart) - visibleLen(metaPart) - 2);
2415
- const dash = c.dim("\u2500");
2416
- const left = c.dim("\u256D") + dash + titlePart + dash.repeat(Math.floor(fillLen / 2));
2417
- const right = dash.repeat(fillLen - Math.floor(fillLen / 2)) + metaPart + dash + c.dim("\u256E");
2418
- return [left + right];
2419
- }
2420
- function pickActiveBlock(records, source) {
2421
- function compute(provider) {
2422
- return blockProgress(
2423
- records.filter((r) => r.source === provider),
2424
- getProvider(provider).capabilities.blockWindowMs
2425
- );
2426
- }
2427
- if (source === "claude") return compute("claude");
2428
- if (source === "codex") return compute("codex");
2429
- const c = compute("claude");
2430
- if (c.block) return c;
2431
- const x = compute("codex");
2432
- return x.block ? x : c;
2433
- }
2434
- function renderKpiTiles(c, w, scan, data) {
2435
- const t = data.totals;
2436
- const sparkTokens = data.trend.map((b) => b.tokens);
2437
- const sparkCost = data.trend.map((b) => b.cost);
2438
- const sparkSaved = data.trend.map((b) => Math.max(0, b.cost - b.cost * 0.95));
2439
- const sparkConvos = data.trend.map((b) => b.turns);
2440
- const cacheIn = t.input + t.cacheRead + t.cacheWrite;
2441
- const cacheHit = cacheIn > 0 ? t.cacheRead / cacheIn : 0;
2442
- const activeBlock = pickActiveBlock(scan.records, data.source);
2443
- const tiles = [
2444
- {
2445
- label: "Total tokens",
2446
- value: c.bold(formatTokensCompact(t.total)),
2447
- sub: `${t.requests.toLocaleString()} reqs \xB7 ${t.turns.toLocaleString()} convs`,
2448
- spark: sparkline(sparkTokens, 12, c.input)
2449
- },
2450
- {
2451
- label: "Cost",
2452
- value: c.bold(formatUSD(t.cost)),
2453
- sub: t.cost > 0 ? `${formatUSD(t.cost / Math.max(1, t.requests))} / req` : "\u2014",
2454
- spark: sparkline(sparkCost, 12, c.output)
2455
- },
2456
- {
2457
- label: "Cache saved",
2458
- value: c.bold(c.green(formatUSD(t.saved))),
2459
- sub: `vs full input pricing`,
2460
- spark: sparkline(sparkSaved, 12, c.green)
2461
- },
2462
- {
2463
- label: "Cache hit",
2464
- value: c.bold(c.green(formatPct(cacheHit, 0))),
2465
- // Render the progress bar in the sparkline slot so this tile's
2466
- // row layout matches the others; the sub line then carries the
2467
- // raw ratio for users who care about the exact number.
2468
- spark: hbar(cacheHit, 12, c.green),
2469
- sub: `${formatTokensCompact(t.cacheRead)} cached`
2470
- },
2471
- {
2472
- label: "Conversations",
2473
- value: c.bold(t.turns.toLocaleString()),
2474
- sub: t.requests > 0 ? `${(t.requests / Math.max(1, t.turns)).toFixed(1)} reqs/turn` : "\u2014",
2475
- spark: sparkline(sparkConvos, 12, c.cacheRead)
2476
- },
2477
- {
2478
- label: "Active 5h block",
2479
- value: activeBlock?.block ? c.bold(formatDuration(activeBlock.remainingMs)) : c.dim("idle"),
2480
- spark: activeBlock?.block ? hbar(activeBlock.progress, 12, c.yellow) : void 0,
2481
- sub: activeBlock?.block ? `${formatPct(activeBlock.progress, 0)} elapsed` : "no active window"
2482
- }
2483
- ];
2484
- return layoutTiles(tiles, c, w);
2485
- }
2486
- function layoutTiles(tiles, c, w) {
2487
- const tileInner = 24;
2488
- const tileOuter = tileInner + 2;
2489
- const gap = 1;
2490
- const perRow = Math.max(1, Math.floor((w + gap) / (tileOuter + gap)));
2491
- const out = [];
2492
- for (let i = 0; i < tiles.length; i += perRow) {
2493
- const slice = tiles.slice(i, i + perRow);
2494
- const blocks = slice.map((t) => renderTile(t, tileInner, c));
2495
- out.push(...mergeHorizontally(blocks, gap).split("\n"));
2496
- if (i + perRow < tiles.length) out.push("");
2497
- }
2498
- return out;
2499
- }
2500
- function renderTile(t, inner, c) {
2501
- const cap = inner - 2;
2502
- const body = [""];
2503
- body.push(truncate(t.value, cap));
2504
- body.push(t.spark ? truncate(t.spark, cap) : "");
2505
- body.push(c.dim(truncate(t.sub, cap)));
2506
- return box(t.label, body, inner, c);
2507
- }
2508
- function mergeHorizontally(blocks, gap) {
2509
- const rows = blocks.map((b) => b.split("\n"));
2510
- const h = Math.max(...rows.map((r) => r.length));
2511
- const widths = rows.map((r) => Math.max(...r.map(visibleLen)));
2512
- const sep = " ".repeat(gap);
2513
- const lines = [];
2514
- for (let i = 0; i < h; i += 1) {
2515
- const cells = rows.map((r, idx) => padEnd(r[i] ?? "", widths[idx]));
2516
- lines.push(cells.join(sep));
2517
- }
2518
- return lines.join("\n");
2519
- }
2520
- function renderTrend(c, w, data) {
2521
- const trend = data.trend;
2522
- const height = 10;
2523
- const cellWidth = Math.max(4, Math.min(8, Math.floor((w - 8) / Math.max(1, trend.length))));
2524
- const max = Math.max(...trend.map((b) => b.input + b.output + b.cacheRead + b.cacheWrite), 1);
2525
- const heading = `${c.brand("\u25B8")} ${c.bold("Token usage trend")} ${c.dim(
2526
- `(${data.gran} \xD7 stacked: input / cache-w / cache-r / output)`
2527
- )}`;
2528
- const colsPerBucket = trend.map(
2529
- (b) => stackedColumn(
2530
- [
2531
- { value: b.input, color: c.input },
2532
- { value: b.cacheWrite, color: c.cacheWrite },
2533
- { value: b.cacheRead, color: c.cacheRead },
2534
- { value: b.output, color: c.output }
2535
- ],
2536
- height,
2537
- max
2538
- )
2539
- );
2540
- const yLabels = [
2541
- padStart(formatTokensCompact(max), 7),
2542
- padStart(formatTokensCompact(max / 2), 7),
2543
- padStart("0", 7)
2544
- ];
2545
- const yLabelRow = (row) => {
2546
- if (row === 0) return yLabels[0];
2547
- if (row === Math.floor((height - 1) / 2)) return yLabels[1];
2548
- if (row === height - 1) return yLabels[2];
2549
- return " ".repeat(7);
2550
- };
2551
- const lines = [heading, ""];
2552
- for (let row = 0; row < height; row += 1) {
2553
- const cells = colsPerBucket.map((col) => center(col[row], cellWidth));
2554
- lines.push(`${c.dim(yLabelRow(row))} ${c.dim("\u2502")} ${cells.join("")}`);
2555
- }
2556
- const baseline = "\u2500".repeat(Math.min(w - 9, cellWidth * trend.length));
2557
- lines.push(`${" ".repeat(7)} ${c.dim("\u2514")}${c.dim(baseline)}`);
2558
- const sampleLabel = trend[0]?.label ?? "";
2559
- const labelStep = Math.max(1, Math.ceil((sampleLabel.length + 1) / cellWidth));
2560
- const xCells = trend.map((b, i) => {
2561
- if (i % labelStep !== 0) return " ".repeat(cellWidth);
2562
- const span = cellWidth * Math.min(labelStep, trend.length - i);
2563
- return center(b.label, span);
2564
- });
2565
- let xLine = "";
2566
- for (let i = 0; i < xCells.length; i += 1) {
2567
- if (i % labelStep === 0) xLine += xCells[i];
2568
- }
2569
- lines.push(`${" ".repeat(8)} ${c.dim(xLine)}`);
2570
- lines.push("");
2571
- lines.push(
2572
- `${" ".repeat(8)}${c.input("\u25CF")} input ${c.cacheWrite("\u25CF")} cache-write ${c.cacheRead("\u25CF")} cache-read ${c.output("\u25CF")} output`
2573
- );
2574
- return lines;
2575
- }
2576
- function renderBreakdowns(c, w, data) {
2577
- const primary = data.breakdown.slice(0, 10);
2578
- const left = renderBreakdownColumn(
2579
- c,
2580
- Math.floor((w - 2) / 2),
2581
- `Top ${data.by}s (by cost)`,
2582
- primary,
2583
- data.totals.cost
2584
- );
2585
- const right = renderBreakdownColumn(
2586
- c,
2587
- Math.floor((w - 2) / 2),
2588
- `Top ${data.by}s (by conversations)`,
2589
- primary.slice().sort((a, b) => b.turns - a.turns).slice(0, 10),
2590
- Math.max(1, ...primary.map((r) => r.turns)),
2591
- "turns"
2592
- );
2593
- return twoColumns(left, right, 2).split("\n");
2594
- }
2595
- function renderBreakdownColumn(c, innerWidth, title, rows, scale, metric = "cost") {
2596
- const labelW = Math.max(10, Math.min(22, innerWidth - 30));
2597
- const headers = [
2598
- padEnd("#", 2),
2599
- padEnd(metric === "cost" ? "Item" : "Item", labelW),
2600
- padStart("Conv", 5),
2601
- padStart("Reqs", 6),
2602
- padStart("Tokens", 8),
2603
- padStart(metric === "cost" ? "Cost" : "Cost", 8)
2604
- ];
2605
- const bodyLines = [];
2606
- bodyLines.push(c.dim(headers.join(" ")));
2607
- bodyLines.push(c.dim("\u2500".repeat(Math.min(innerWidth - 2, headers.join(" ").length))));
2608
- if (rows.length === 0) {
2609
- bodyLines.push(c.dim("(no data in this window)"));
2610
- }
2611
- rows.forEach((r, i) => {
2612
- const lbl = truncate(r.label, labelW);
2613
- bodyLines.push(
2614
- [
2615
- padEnd(String(i + 1), 2),
2616
- padEnd(lbl, labelW),
2617
- padStart(r.turns.toLocaleString(), 5),
2618
- padStart(r.requests.toLocaleString(), 6),
2619
- padStart(formatTokensCompact(r.tokens), 8),
2620
- padStart(formatUSD(r.cost), 8)
2621
- ].join(" ")
2622
- );
2623
- const ratio = metric === "cost" ? r.cost / Math.max(1e-9, scale) : r.turns / Math.max(1e-9, scale);
2624
- const barW = innerWidth - 4 - 2 - labelW;
2625
- bodyLines.push(`${" ".repeat(3)}${hbar(ratio, Math.max(8, Math.min(40, barW)), c.brand)}`);
2626
- });
2627
- return box(title, bodyLines, innerWidth, c);
2628
- }
2629
- function renderHeatmap(c, w, records) {
2630
- const stats = computeActivityStats(records, { source: "all" });
2631
- const heat = stats.heatmap;
2632
- const max = stats.heatmapMax;
2633
- if (max === 0) {
2634
- return [`${c.brand("\u25B8")} ${c.bold("Activity heatmap")}`, "", c.dim(" (no activity yet \u2014 start a session and re-run)")];
2635
- }
2636
- const dayLabels = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
2637
- const density = ["\xB7", "\u25A2", "\u25A3", "\u25A4", "\u25A5", "\u25A6"];
2638
- const cell = (v) => {
2639
- if (v === 0) return c.dim("\xB7");
2640
- const idx = Math.min(density.length - 1, Math.max(1, Math.ceil(v / max * (density.length - 1))));
2641
- const ch = density[idx];
2642
- return idx < 3 ? c.input(ch) : idx < 5 ? c.cacheRead(ch) : c.output(ch);
2643
- };
2644
- const heading = `${c.brand("\u25B8")} ${c.bold("Activity heatmap")} ${c.dim("(local time, day-of-week \xD7 hour)")}`;
2645
- const hourHeader = " " + Array.from({ length: 24 }, (_, h) => padStart(String(h), 2)).join(" ");
2646
- const lines = [heading, "", c.dim(hourHeader)];
2647
- for (let dow = 0; dow < 7; dow += 1) {
2648
- const sourceDow = (dow + 1) % 7;
2649
- const row = heat[sourceDow] ?? new Array(24).fill(0);
2650
- const cells = row.map((v) => padStart(cell(v), 2)).join(" ");
2651
- lines.push(`${c.dim(padEnd(dayLabels[dow], 4))}${cells}`);
2652
- }
2653
- return lines;
2654
- }
2655
- function renderFooter(c, w, records, data, opts) {
2656
- const filters = [];
2657
- if (opts.model) filters.push(`model~${opts.model}`);
2658
- if (opts.project) filters.push(`project~${opts.project}`);
2659
- if (data.fromIso || data.untilIso) {
2660
- const range = `${data.fromIso?.slice(0, 10) ?? "\u2026"} \u2192 ${data.untilIso?.slice(0, 10) ?? "\u2026"}`;
2661
- filters.push(range);
2662
- }
2663
- const scope = [
2664
- `range: ${data.range}`,
2665
- `source: ${data.source}`,
2666
- `scope: ${records.length.toLocaleString()} records \xB7 ${data.totals.turns.toLocaleString()} conversations`
2667
- ];
2668
- if (filters.length > 0) scope.push(`filters: ${filters.join(", ")}`);
2669
- return [
2670
- c.dim(scope.join(" \xB7 ")),
2671
- c.dim(`Use \`ccgauge report\` for a CI-friendly text summary, or \`ccgauge report -d --json\` to pipe.`)
2672
- ];
2673
- }
2674
-
2675
- // lib/cli-report/index.ts
2676
- var REPORT_RANGES = ["today", "1d", "7d", "30d", "90d", "all"];
2677
- var DIMS = ["model", "project", "session"];
2678
- var DATE_ONLY_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
2679
- var DEFAULT_REPORT = {
2680
- range: "7d",
2681
- source: "all",
2682
- by: "model",
2683
- gran: "day",
2684
- limit: 10,
2685
- json: false,
2686
- color: true,
2687
- showTrend: true,
2688
- showBreakdown: true,
2689
- dashboard: false,
2690
- compact: false,
2691
- banner: true
2692
- };
2693
- async function runReport(opts) {
2694
- const filled = normalizeReportOptions(opts);
2695
- const scan = await getCachedScan();
2696
- const sources = filled.source === "all" ? ALL_PROVIDER_IDS : [filled.source];
2697
- const data = computeReportData(scan, sources, filled);
2698
- if (filled.json) return JSON.stringify(data, null, 2);
2699
- if (filled.dashboard) {
2700
- const filteredRecords = filterRecordsForReport(scan, sources, filled);
2701
- return renderDash(scan, data, filled, filteredRecords);
2702
- }
2703
- return renderText(data, filled);
2704
- }
2705
- function filterRecordsForReport(scan, sources, o) {
2706
- const dates = resolveRange(o);
2707
- const fromIso = dates.from?.toISOString();
2708
- const toIso = dates.until?.toISOString();
2709
- const sourceSet = new Set(sources);
2710
- const modelNeedle = o.model?.toLowerCase();
2711
- const projectNeedle = o.project?.toLowerCase();
2712
- return scan.records.filter((r) => {
2713
- if (!sourceSet.has(r.source)) return false;
2714
- if (fromIso && r.timestamp < fromIso) return false;
2715
- if (toIso && r.timestamp > toIso) return false;
2716
- if (modelNeedle && !r.model.toLowerCase().includes(modelNeedle)) return false;
2717
- if (projectNeedle) {
2718
- const cwd = (r.cwd || "").toLowerCase();
2719
- const leaf = cwd.split(/[/\\]+/).pop() ?? "";
2720
- if (!cwd.includes(projectNeedle) && !leaf.includes(projectNeedle)) return false;
2721
- }
2722
- return true;
2723
- });
2724
- }
2725
- function normalizeReportOptions(opts) {
2726
- const filled = { ...DEFAULT_REPORT, ...opts };
2727
- if (!isReportRange(filled.range)) {
2728
- throw new Error(invalidOptionMessage("range", filled.range, REPORT_RANGES));
2729
- }
2730
- if (filled.source !== "all" && !isProviderId(filled.source)) {
2731
- throw new Error(invalidOptionMessage("source", filled.source, ["claude", "codex", "all"]));
2732
- }
2733
- if (!isDim(filled.by)) {
2734
- throw new Error(invalidOptionMessage("by", filled.by, DIMS));
2735
- }
2736
- if (!isGranularity(filled.gran)) {
2737
- throw new Error(invalidOptionMessage("gran", filled.gran, ["hour", "day", "week", "month"]));
2738
- }
2739
- if (filled.since) parseReportDate(filled.since, "since");
2740
- if (filled.until) parseReportDate(filled.until, "until");
2741
- const dates = resolveRange(filled);
2742
- if (dates.from && dates.until && dates.from.getTime() > dates.until.getTime()) {
2743
- throw new Error("invalid date range: --since must be before or equal to --until");
2744
- }
2745
- return filled;
2746
- }
2747
- function isReportRange(v) {
2748
- return typeof v === "string" && REPORT_RANGES.includes(v);
2749
- }
2750
- function isDim(v) {
2751
- return typeof v === "string" && DIMS.includes(v);
2752
- }
2753
- function invalidOptionMessage(name, value, expected) {
2754
- return `invalid ${name}: ${JSON.stringify(value)}. Expected one of: ${expected.join(", ")}`;
2755
- }
2756
- function computeReportData(scan, sources, o) {
2757
- const allRecords = scan.records;
2758
- const dates = resolveRange(o);
2759
- const baseOpts = {
2760
- from: dates.from ?? void 0,
2761
- to: dates.until ?? void 0
2762
- // `o.model` / `o.project` are substring patterns, not exact matches —
2763
- // they're applied per-record by `withinSrcAndFilters` below, so we
2764
- // deliberately leave the aggregator's exact-match filters unset.
2765
- };
2766
- const totals = {
2767
- input: 0,
2768
- output: 0,
2769
- reasoning: 0,
2770
- cacheRead: 0,
2771
- cacheWrite: 0,
2772
- total: 0,
2773
- cost: 0,
2774
- saved: 0,
2775
- requests: 0,
2776
- turns: 0
2777
- };
2778
- const trendBuckets = /* @__PURE__ */ new Map();
2779
- for (const source of sources) {
2780
- const opts = { ...baseOpts, source };
2781
- const sourceRecs = allRecords.filter((r) => withinSrcAndFilters(r, opts, o));
2782
- const t = aggregateTotals(sourceRecs, opts);
2783
- totals.input += t.inputTokens;
2784
- totals.output += t.outputTokens;
2785
- totals.cacheRead += t.cacheReadTokens;
2786
- totals.cacheWrite += t.cacheCreationTokens;
2787
- totals.total += t.totalTokens;
2788
- totals.cost += t.cost;
2789
- totals.saved += t.saved;
2790
- totals.requests += t.requests;
2791
- for (const r of sourceRecs) totals.reasoning += r.usage.reasoning_tokens ?? 0;
2792
- const turnSummaries = summarizeTurns(sourceRecs, scan.userRecords, scan.parentMap);
2793
- totals.turns += turnSummaries.size;
2794
- const turnsByKey = /* @__PURE__ */ new Map();
2795
- for (const tn of turnSummaries.values()) {
2796
- const { key } = bucketKey(tn.firstTimestamp, o.gran);
2797
- turnsByKey.set(key, (turnsByKey.get(key) ?? 0) + 1);
2798
- }
2799
- const buckets = aggregateByTime(sourceRecs, o.gran, opts);
2800
- for (const b of buckets) {
2801
- const ex = trendBuckets.get(b.key);
2802
- const tnCount = turnsByKey.get(b.key) ?? 0;
2803
- if (ex) {
2804
- ex.cost += b.cost;
2805
- ex.tokens += b.totalTokens;
2806
- ex.turns += tnCount;
2807
- ex.input += b.inputTokens;
2808
- ex.output += b.outputTokens;
2809
- ex.cacheRead += b.cacheReadTokens;
2810
- ex.cacheWrite += b.cacheCreationTokens;
2811
- } else {
2812
- trendBuckets.set(b.key, {
2813
- label: b.label,
2814
- cost: b.cost,
2815
- tokens: b.totalTokens,
2816
- turns: tnCount,
2817
- input: b.inputTokens,
2818
- output: b.outputTokens,
2819
- cacheRead: b.cacheReadTokens,
2820
- cacheWrite: b.cacheCreationTokens
2821
- });
2822
- }
2823
- }
2824
- }
2825
- const trend = Array.from(trendBuckets.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([, v]) => v);
2826
- const breakdown = buildBreakdown(scan, sources, baseOpts, o);
2827
- return {
2828
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
2829
- range: o.range,
2830
- source: o.source,
2831
- by: o.by,
2832
- gran: o.gran,
2833
- fromIso: dates.from?.toISOString() ?? null,
2834
- untilIso: dates.until?.toISOString() ?? null,
2835
- totals,
2836
- trend,
2837
- breakdown
2838
- };
2839
- }
2840
- function buildBreakdown(scan, sources, base, o) {
2841
- const allRecords = scan.records;
2842
- if (o.by === "model") {
2843
- const rows2 = [];
2844
- for (const source of sources) {
2845
- const opts = { ...base, source };
2846
- const filtered = allRecords.filter((r) => withinSrcAndFilters(r, opts, o));
2847
- const models = aggregateByModel(filtered, opts);
2848
- const provider = getProvider(source);
2849
- const turnsByModel = /* @__PURE__ */ new Map();
2850
- for (const tn of summarizeTurns(filtered, scan.userRecords, scan.parentMap).values()) {
2851
- turnsByModel.set(tn.firstModel, (turnsByModel.get(tn.firstModel) ?? 0) + 1);
2852
- }
2853
- for (const m of models) {
2854
- rows2.push({
2855
- key: `${source}::${m.model}`,
2856
- label: provider.shortenModel(m.model),
2857
- requests: m.requests,
2858
- turns: turnsByModel.get(m.model) ?? 0,
2859
- tokens: m.totalTokens,
2860
- cost: m.cost,
2861
- share: 0,
2862
- // filled after total
2863
- sub: m.model
2864
- });
2865
- }
2866
- }
2867
- return finalizeShare(rows2, o.limit);
2868
- }
2869
- if (o.by === "project") {
2870
- const rows2 = [];
2871
- for (const source of sources) {
2872
- const opts = { ...base, source };
2873
- const filtered = allRecords.filter((r) => withinSrcAndFilters(r, opts, o));
2874
- const projects = aggregateByProject(filtered, opts);
2875
- const turnsByCwd = /* @__PURE__ */ new Map();
2876
- for (const tn of summarizeTurns(filtered, scan.userRecords, scan.parentMap).values()) {
2877
- const key = tn.cwd || "(unknown)";
2878
- turnsByCwd.set(key, (turnsByCwd.get(key) ?? 0) + 1);
2879
- }
2880
- for (const p of projects) {
2881
- rows2.push({
2882
- key: `${source}::${p.cwd}`,
2883
- label: p.projectName,
2884
- requests: p.requests,
2885
- turns: turnsByCwd.get(p.cwd) ?? 0,
2886
- tokens: p.totalTokens,
2887
- cost: p.cost,
2888
- share: 0,
2889
- sub: p.cwd
2890
- });
2891
- }
2892
- }
2893
- return finalizeShare(rows2, o.limit);
2894
- }
2895
- const rows = [];
2896
- for (const source of sources) {
2897
- const opts = { ...base, source };
2898
- const filtered = allRecords.filter((r) => withinSrcAndFilters(r, opts, o));
2899
- const sessions = aggregateBySession(filtered, [], opts);
2900
- const turnsBySession = /* @__PURE__ */ new Map();
2901
- for (const tn of summarizeTurns(filtered, scan.userRecords, scan.parentMap).values()) {
2902
- turnsBySession.set(tn.sessionId, (turnsBySession.get(tn.sessionId) ?? 0) + 1);
2903
- }
2904
- for (const s of sessions) {
2905
- rows.push({
2906
- key: `${source}::${s.sessionId}`,
2907
- label: s.title ?? s.sessionId.slice(0, 8),
2908
- requests: s.requests,
2909
- turns: turnsBySession.get(s.sessionId) ?? 0,
2910
- tokens: s.totalTokens,
2911
- cost: s.cost,
2912
- share: 0,
2913
- // Worktree-aware so the breakdown reads
2914
- // `ai-self-web (playwright)` instead of just `playwright`,
2915
- // matching the dashboard's usage / sessions tables.
2916
- sub: s.projectLabel
2917
- });
2918
- }
2919
- }
2920
- return finalizeShare(rows, o.limit);
2921
- }
2922
- function finalizeShare(rows, limit) {
2923
- const total = rows.reduce((s, r) => s + r.cost, 0);
2924
- rows.sort((a, b) => b.cost - a.cost);
2925
- const top = rows.slice(0, Math.max(1, limit));
2926
- if (total > 0) for (const r of top) r.share = r.cost / total;
2927
- return top;
2928
- }
2929
- function withinSrcAndFilters(rec, opts, o) {
2930
- if (rec.source !== opts.source) return false;
2931
- if (opts.from && rec.timestamp < opts.from.toISOString()) return false;
2932
- if (opts.to && rec.timestamp > opts.to.toISOString()) return false;
2933
- if (o.model && !rec.model.toLowerCase().includes(o.model.toLowerCase())) return false;
2934
- if (o.project) {
2935
- const needle = o.project.toLowerCase();
2936
- const cwd = (rec.cwd || "").toLowerCase();
2937
- const leaf = cwd.split(/[/\\]+/).pop() ?? "";
2938
- if (!cwd.includes(needle) && !leaf.includes(needle)) return false;
2939
- }
2940
- return true;
2941
- }
2942
- function resolveRange(o) {
2943
- if (o.since || o.until) {
2944
- return {
2945
- from: o.since ? parseReportDate(o.since, "since") : null,
2946
- until: o.until ? parseReportDate(o.until, "until") : null
2947
- };
2948
- }
2949
- const r = o.range === "today" ? "1d" : o.range;
2950
- if (!isUsageRange(r)) {
2951
- throw new Error(invalidOptionMessage("range", o.range, REPORT_RANGES));
2952
- }
2953
- const d = rangeToDates(r);
2954
- return { from: d.from ?? null, until: d.to ?? null };
2955
- }
2956
- function parseReportDate(raw, boundary) {
2957
- const m = raw.match(DATE_ONLY_RE);
2958
- if (m) {
2959
- const year = Number(m[1]);
2960
- const month = Number(m[2]);
2961
- const day = Number(m[3]);
2962
- const date2 = boundary === "since" ? new Date(year, month - 1, day, 0, 0, 0, 0) : new Date(year, month - 1, day, 23, 59, 59, 999);
2963
- if (date2.getFullYear() !== year || date2.getMonth() !== month - 1 || date2.getDate() !== day) {
2964
- throw new Error(`invalid ${boundary} date: ${raw}`);
2965
- }
2966
- return date2;
2967
- }
2968
- const date = new Date(raw);
2969
- if (Number.isNaN(date.getTime())) {
2970
- throw new Error(`invalid ${boundary} date: ${raw}`);
2971
- }
2972
- return date;
2973
- }
2974
- function makeColors(enabled) {
2975
- const wrap2 = (code) => (s) => enabled ? `\x1B[${code}m${s}\x1B[0m` : String(s);
2976
- return {
2977
- bold: wrap2("1"),
2978
- dim: wrap2("2"),
2979
- cyan: wrap2("36"),
2980
- green: wrap2("32"),
2981
- yellow: wrap2("33"),
2982
- red: wrap2("31"),
2983
- blue: wrap2("34"),
2984
- magenta: wrap2("35"),
2985
- brand: wrap2("38;2;129;140;248")
2986
- };
2987
- }
2988
- function renderText(d, o) {
2989
- const c = makeColors(o.color !== false);
2990
- const lines = [];
2991
- const ts = new Date(d.generatedAt).toLocaleString();
2992
- lines.push("");
2993
- lines.push(`${c.brand(c.bold("ccgauge"))} ${c.bold("report")}`);
2994
- lines.push(
2995
- c.dim(
2996
- [
2997
- `range: ${d.range}`,
2998
- `source: ${d.source}`,
2999
- `by: ${d.by}`,
3000
- `gran: ${d.gran}`,
3001
- `generated ${ts}`
3002
- ].join(" \xB7 ")
3003
- )
3004
- );
3005
- lines.push("");
3006
- lines.push(c.brand("\u25B8") + " " + c.bold("Tokens"));
3007
- const t = d.totals;
3008
- const tokenRows = [
3009
- ["Input", formatTokensCompact(t.input), "Output", formatTokensCompact(t.output)],
3010
- [
3011
- "Cache R",
3012
- c.green(formatTokensCompact(t.cacheRead)),
3013
- "Cache W",
3014
- formatTokensCompact(t.cacheWrite)
3015
- ]
3016
- ];
3017
- if (t.reasoning > 0) {
3018
- tokenRows.push(["Reasoning", c.dim(formatTokensCompact(t.reasoning)), "", ""]);
3019
- }
3020
- tokenRows.push(["Total", c.bold(formatTokensCompact(t.total)), "", ""]);
3021
- tokenRows.push([
3022
- "Convos",
3023
- c.bold(t.turns.toLocaleString()),
3024
- "Requests",
3025
- t.requests.toLocaleString()
3026
- ]);
3027
- lines.push(renderPairedKv(tokenRows, c));
3028
- lines.push("");
3029
- lines.push(c.brand("\u25B8") + " " + c.bold("Cost"));
3030
- const totalInputForCache = t.input + t.cacheRead + t.cacheWrite;
3031
- const cacheHit = totalInputForCache > 0 ? t.cacheRead / totalInputForCache : 0;
3032
- const avgPerReq = t.requests > 0 ? t.cost / t.requests : 0;
3033
- const costRows = [
3034
- ["Total", c.bold(formatUSD(t.cost)), "Saved by cache", c.green(formatUSD(t.saved))],
3035
- [
3036
- "Avg / request",
3037
- avgPerReq < 0.01 ? `$${avgPerReq.toFixed(4)}` : formatUSD(avgPerReq),
3038
- "Cache hit",
3039
- c.green(formatPct(cacheHit, 1))
3040
- ]
3041
- ];
3042
- lines.push(renderPairedKv(costRows, c));
3043
- lines.push("");
3044
- if (o.showTrend !== false && d.trend.length > 0) {
3045
- lines.push(c.brand("\u25B8") + " " + c.bold("Trend") + " " + c.dim(`(${o.gran}, by cost)`));
3046
- const maxCost = Math.max(...d.trend.map((b) => b.cost), 1e-9);
3047
- const maxLabelLen = Math.max(...d.trend.map((b) => b.label.length));
3048
- const maxCostStr = Math.max(...d.trend.map((b) => formatUSD(b.cost).length));
3049
- for (const b of d.trend) {
3050
- const bar = barString(b.cost / maxCost, 44);
3051
- const label = b.label.padEnd(maxLabelLen);
3052
- const cost = formatUSD(b.cost).padStart(maxCostStr);
3053
- lines.push(` ${c.dim(label)} ${cost} ${c.brand(bar)}`);
3054
- }
3055
- lines.push("");
3056
- }
3057
- if (o.showBreakdown !== false && d.breakdown.length > 0) {
3058
- const dimLabel = d.by[0].toUpperCase() + d.by.slice(1);
3059
- lines.push(
3060
- c.brand("\u25B8") + " " + c.bold(`Top ${d.breakdown.length} ${dimLabel}s`) + " " + c.dim("(by cost)")
3061
- );
3062
- const headers = ["#", dimLabel, "Convos", "Reqs", "Tokens", "Cost", "Share"];
3063
- const rows = d.breakdown.map((r, i) => [
3064
- String(i + 1),
3065
- truncate2(r.label, 28),
3066
- r.turns.toLocaleString(),
3067
- r.requests.toLocaleString(),
3068
- formatTokensCompact(r.tokens),
3069
- formatUSD(r.cost),
3070
- formatPct(r.share, 1)
3071
- ]);
3072
- lines.push(renderTable(headers, rows, c, [false, false, true, true, true, true, true]));
3073
- lines.push("");
3074
- }
3075
- return lines.join("\n");
3076
- }
3077
- function renderPairedKv(rows, c) {
3078
- const w = [0, 0, 0, 0];
3079
- for (const r of rows) for (let i = 0; i < 4; i += 1) {
3080
- const cell = r[i];
3081
- if (visibleLen2(cell) > w[i]) w[i] = visibleLen2(cell);
3082
- }
3083
- const lines = [];
3084
- for (const [lk, lv, rk, rv] of rows) {
3085
- const left = `${c.dim(padEnd2(lk, w[0]))} ${padEnd2(lv, w[1])}`;
3086
- const right = rk ? `${c.dim(padEnd2(rk, w[2]))} ${rv}` : "";
3087
- lines.push(` ${left} ${right}`.replace(/\s+$/, ""));
3088
- }
3089
- return lines.join("\n");
3090
- }
3091
- function renderTable(headers, rows, c, rightAlign) {
3092
- const widths = headers.map(
3093
- (h, i) => Math.max(h.length, ...rows.map((r) => visibleLen2(r[i] ?? "")))
3094
- );
3095
- const headLine = " " + headers.map((h, i) => rightAlign[i] ? padStart2(h, widths[i]) : padEnd2(h, widths[i])).map((s) => c.dim(s)).join(" ");
3096
- const sepLine = " " + widths.map((w) => "\u2500".repeat(w)).map((s) => c.dim(s)).join(" ");
3097
- const bodyLines = rows.map(
3098
- (row) => " " + row.map((cell, i) => rightAlign[i] ? padStart2(cell, widths[i]) : padEnd2(cell, widths[i])).join(" ")
3099
- );
3100
- return [headLine, sepLine, ...bodyLines].join("\n");
3101
- }
3102
- function barString(ratio, width) {
3103
- const r = Math.max(0, Math.min(1, ratio));
3104
- const filled = Math.round(r * width);
3105
- return "\u2587".repeat(filled) + "\u2500".repeat(width - filled);
3106
- }
3107
- var ESC = String.fromCharCode(27);
3108
- var ANSI_RE2 = new RegExp(ESC + "\\[[0-9;]*m", "g");
3109
- function visibleLen2(s) {
3110
- return s.replace(ANSI_RE2, "").length;
3111
- }
3112
- function padEnd2(s, w) {
3113
- return s + " ".repeat(Math.max(0, w - visibleLen2(s)));
3114
- }
3115
- function padStart2(s, w) {
3116
- return " ".repeat(Math.max(0, w - visibleLen2(s))) + s;
3117
- }
3118
- function truncate2(s, max) {
3119
- if (s.length <= max) return s;
3120
- return s.slice(0, max - 1) + "\u2026";
3121
- }
3122
- export {
3123
- DEFAULT_REPORT,
3124
- filterRecordsForReport,
3125
- renderText,
3126
- runReport
3127
- };
1
+ var Wr=Object.create;var At=Object.defineProperty;var jr=Object.getOwnPropertyDescriptor;var Gr=Object.getOwnPropertyNames;var qr=Object.getPrototypeOf,Hr=Object.prototype.hasOwnProperty;var yt=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(u,t)=>(typeof require<"u"?require:u)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var A=(e,u)=>()=>(u||e((u={exports:{}}).exports,u),u.exports);var Vr=(e,u,t,n)=>{if(u&&typeof u=="object"||typeof u=="function")for(let D of Gr(u))!Hr.call(e,D)&&D!==t&&At(e,D,{get:()=>u[D],enumerable:!(n=jr(u,D))||n.enumerable});return e};var le=(e,u,t)=>(t=e!=null?Wr(qr(e)):{},Vr(u||!e||!e.__esModule?At(t,"default",{value:e,enumerable:!0}):t,e));var hn=A((uF,pn)=>{pn.exports=()=>/[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E-\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED8\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])))?))?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3C-\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE8A\uDE8E-\uDEC2\uDEC6\uDEC8\uDECD-\uDEDC\uDEDF-\uDEEA\uDEEF]|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g});var _n=A((gF,Tn)=>{Tn.exports=()=>/[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E-\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED8\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])))?))?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3C-\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE8A\uDE8E-\uDEC2\uDEC6\uDEC8\uDECD-\uDEDC\uDEDF-\uDEEA\uDEEF]|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g});var In=A((yF,ci)=>{ci.exports={single:{topLeft:"\u250C",top:"\u2500",topRight:"\u2510",right:"\u2502",bottomRight:"\u2518",bottom:"\u2500",bottomLeft:"\u2514",left:"\u2502"},double:{topLeft:"\u2554",top:"\u2550",topRight:"\u2557",right:"\u2551",bottomRight:"\u255D",bottom:"\u2550",bottomLeft:"\u255A",left:"\u2551"},round:{topLeft:"\u256D",top:"\u2500",topRight:"\u256E",right:"\u2502",bottomRight:"\u256F",bottom:"\u2500",bottomLeft:"\u2570",left:"\u2502"},bold:{topLeft:"\u250F",top:"\u2501",topRight:"\u2513",right:"\u2503",bottomRight:"\u251B",bottom:"\u2501",bottomLeft:"\u2517",left:"\u2503"},singleDouble:{topLeft:"\u2553",top:"\u2500",topRight:"\u2556",right:"\u2551",bottomRight:"\u255C",bottom:"\u2500",bottomLeft:"\u2559",left:"\u2551"},doubleSingle:{topLeft:"\u2552",top:"\u2550",topRight:"\u2555",right:"\u2502",bottomRight:"\u255B",bottom:"\u2550",bottomLeft:"\u2558",left:"\u2502"},classic:{topLeft:"+",top:"-",topRight:"+",right:"|",bottomRight:"+",bottom:"-",bottomLeft:"+",left:"|"},arrow:{topLeft:"\u2198",top:"\u2193",topRight:"\u2199",right:"\u2190",bottomRight:"\u2196",bottom:"\u2191",bottomLeft:"\u2197",left:"\u2192"}}});var Lu=A((xF,Ou)=>{"use strict";var Mn=In();Ou.exports=Mn;Ou.exports.default=Mn});var Uu=A((wF,$n)=>{"use strict";$n.exports=({onlyFirst:e=!1}={})=>{let u=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(u,e?void 0:"g")}});var Wn=A((kF,Un)=>{"use strict";var Ci=Uu();Un.exports=e=>typeof e=="string"?e.replace(Ci(),""):e});var ju=A((SF,Wu)=>{"use strict";var jn=e=>Number.isNaN(e)?!1:e>=4352&&(e<=4447||e===9001||e===9002||11904<=e&&e<=12871&&e!==12351||12880<=e&&e<=19903||19968<=e&&e<=42182||43360<=e&&e<=43388||44032<=e&&e<=55203||63744<=e&&e<=64255||65040<=e&&e<=65049||65072<=e&&e<=65131||65281<=e&&e<=65376||65504<=e&&e<=65510||110592<=e&&e<=110593||127488<=e&&e<=127569||131072<=e&&e<=262141);Wu.exports=jn;Wu.exports.default=jn});var Gu=A((TF,Gn)=>{"use strict";Gn.exports=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g}});var Hn=A((_F,qu)=>{"use strict";var gi=Wn(),mi=ju(),Ei=Gu(),qn=e=>{if(typeof e!="string"||e.length===0||(e=gi(e),e.length===0))return 0;e=e.replace(Ei()," ");let u=0;for(let t=0;t<e.length;t++){let n=e.codePointAt(t);n<=31||n>=127&&n<=159||n>=768&&n<=879||(n>65535&&t++,u+=mi(n)?2:1)}return u};qu.exports=qn;qu.exports.default=qn});var zn=A((vF,Vn)=>{"use strict";var Bi=Hn();function ae(e,u){if(!e)return e;u=u||{};let t=u.align||"center";if(t==="left")return e;let n=u.split||`
2
+ `,D=u.pad||" ",r=t!=="right"?bi:Ai,o=!1;Array.isArray(e)||(o=!0,e=String(e).split(n));let i,s=0;return e=e.map(function(a){return a=String(a),i=Bi(a),s=Math.max(i,s),{str:a,width:i}}).map(function(a){return new Array(r(s,a.width)+1).join(D)+a.str}),o?e.join(n):e}ae.left=function(u){return ae(u,{align:"left"})};ae.center=function(u){return ae(u,{align:"center"})};ae.right=function(u){return ae(u,{align:"right"})};Vn.exports=ae;function bi(e,u){return Math.floor((e-u)/2)}function Ai(e,u){return e-u}});var Du=A((zF,sD)=>{var Ju=[],iD=0,T=(e,u)=>{iD>=u&&Ju.push(e)};T.WARN=1;T.INFO=2;T.DEBUG=3;T.reset=()=>{Ju=[]};T.setDebugLevel=e=>{iD=e};T.warn=e=>T(e,T.WARN);T.info=e=>T(e,T.INFO);T.debug=e=>T(e,T.DEBUG);T.debugMessages=()=>Ju;sD.exports=T});var cD=A((KF,aD)=>{"use strict";var ji=Uu();aD.exports=e=>typeof e=="string"?e.replace(ji(),""):e});var FD=A((YF,Xu)=>{"use strict";var Gi=cD(),qi=ju(),Hi=Gu(),lD=e=>{if(typeof e!="string"||e.length===0||(e=Gi(e),e.length===0))return 0;e=e.replace(Hi()," ");let u=0;for(let t=0;t<e.length;t++){let n=e.codePointAt(t);n<=31||n>=127&&n<=159||n>=768&&n<=879||(n>65535&&t++,u+=qi(n)?2:1)}return u};Xu.exports=lD;Xu.exports.default=lD});var Zu=A((JF,hD)=>{var dD=FD();function ru(e){return e?/\u001b\[((?:\d*;){0,5}\d*)m/g:/\u001b\[(?:\d*;){0,5}\d*m/g}function H(e){let u=ru();return(""+e).replace(u,"").split(`
3
+ `).reduce(function(D,r){return dD(r)>D?dD(r):D},0)}function Ie(e,u){return Array(u+1).join(e)}function Vi(e,u,t,n){let D=H(e);if(u+1>=D){let r=u-D;switch(n){case"right":{e=Ie(t,r)+e;break}case"center":{let o=Math.ceil(r/2),i=r-o;e=Ie(t,i)+e+Ie(t,o);break}default:{e=e+Ie(t,r);break}}}return e}var he={};function Me(e,u,t){u="\x1B["+u+"m",t="\x1B["+t+"m",he[u]={set:e,to:!0},he[t]={set:e,to:!1},he[e]={on:u,off:t}}Me("bold",1,22);Me("italics",3,23);Me("underline",4,24);Me("inverse",7,27);Me("strikethrough",9,29);function fD(e,u){let t=u[1]?parseInt(u[1].split(";")[0]):0;if(t>=30&&t<=39||t>=90&&t<=97){e.lastForegroundAdded=u[0];return}if(t>=40&&t<=49||t>=100&&t<=107){e.lastBackgroundAdded=u[0];return}if(t===0){for(let D in e)Object.prototype.hasOwnProperty.call(e,D)&&delete e[D];return}let n=he[u[0]];n&&(e[n.set]=n.to)}function zi(e){let u=ru(!0),t=u.exec(e),n={};for(;t!==null;)fD(n,t),t=u.exec(e);return n}function pD(e,u){let t=e.lastBackgroundAdded,n=e.lastForegroundAdded;return delete e.lastBackgroundAdded,delete e.lastForegroundAdded,Object.keys(e).forEach(function(D){e[D]&&(u+=he[D].off)}),t&&t!="\x1B[49m"&&(u+="\x1B[49m"),n&&n!="\x1B[39m"&&(u+="\x1B[39m"),u}function Ki(e,u){let t=e.lastBackgroundAdded,n=e.lastForegroundAdded;return delete e.lastBackgroundAdded,delete e.lastForegroundAdded,Object.keys(e).forEach(function(D){e[D]&&(u=he[D].on+u)}),t&&t!="\x1B[49m"&&(u=t+u),n&&n!="\x1B[39m"&&(u=n+u),u}function Yi(e,u){if(e.length===H(e))return e.substr(0,u);for(;H(e)>u;)e=e.slice(0,-1);return e}function Ji(e,u){let t=ru(!0),n=e.split(ru()),D=0,r=0,o="",i,s={};for(;r<u;){i=t.exec(e);let a=n[D];if(D++,r+H(a)>u&&(a=Yi(a,u-r)),o+=a,r+=H(a),r<u){if(!i)break;o+=i[0],fD(s,i)}}return pD(s,o)}function Xi(e,u,t){if(t=t||"\u2026",H(e)<=u)return e;u-=H(t);let D=Ji(e,u);D+=t;let r="\x1B]8;;\x07";return e.includes(r)&&!D.includes(r)&&(D+=r),D}function Zi(){return{chars:{top:"\u2500","top-mid":"\u252C","top-left":"\u250C","top-right":"\u2510",bottom:"\u2500","bottom-mid":"\u2534","bottom-left":"\u2514","bottom-right":"\u2518",left:"\u2502","left-mid":"\u251C",mid:"\u2500","mid-mid":"\u253C",right:"\u2502","right-mid":"\u2524",middle:"\u2502"},truncate:"\u2026",colWidths:[],rowHeights:[],colAligns:[],rowAligns:[],style:{"padding-left":1,"padding-right":1,head:["red"],border:["grey"],compact:!1},head:[]}}function Qi(e,u){e=e||{},u=u||Zi();let t=Object.assign({},u,e);return t.chars=Object.assign({},u.chars,e.chars),t.style=Object.assign({},u.style,e.style),t}function es(e,u){let t=[],n=u.split(/(\s+)/g),D=[],r=0,o;for(let i=0;i<n.length;i+=2){let s=n[i],a=r+H(s);r>0&&o&&(a+=o.length),a>e?(r!==0&&t.push(D.join("")),D=[s],r=H(s)):(D.push(o||"",s),r=a),o=n[i+1]}return r&&t.push(D.join("")),t}function us(e,u){let t=[],n="";function D(o,i){for(n.length&&i&&(n+=i),n+=o;n.length>e;)t.push(n.slice(0,e)),n=n.slice(e)}let r=u.split(/(\s+)/g);for(let o=0;o<r.length;o+=2)D(r[o],o&&r[o-1]);return n.length&&t.push(n),t}function ts(e,u,t=!0){let n=[];u=u.split(`
4
+ `);let D=t?es:us;for(let r=0;r<u.length;r++)n.push.apply(n,D(e,u[r]));return n}function ns(e){let u={},t=[];for(let n=0;n<e.length;n++){let D=Ki(u,e[n]);u=zi(D);let r=Object.assign({},u);t.push(pD(r,D))}return t}function Ds(e,u){return["\x1B]","8",";",";",e||u,"\x07",u,"\x1B]","8",";",";","\x07"].join("")}hD.exports={strlen:H,repeat:Ie,pad:Vi,truncate:Xi,mergeOptions:Qi,wordWrap:ts,colorizeLines:ns,hyperlink:Ds}});var ED=A((XF,mD)=>{var gD={};mD.exports=gD;var CD={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],grey:[90,39],brightRed:[91,39],brightGreen:[92,39],brightYellow:[93,39],brightBlue:[94,39],brightMagenta:[95,39],brightCyan:[96,39],brightWhite:[97,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgGray:[100,49],bgGrey:[100,49],bgBrightRed:[101,49],bgBrightGreen:[102,49],bgBrightYellow:[103,49],bgBrightBlue:[104,49],bgBrightMagenta:[105,49],bgBrightCyan:[106,49],bgBrightWhite:[107,49],blackBG:[40,49],redBG:[41,49],greenBG:[42,49],yellowBG:[43,49],blueBG:[44,49],magentaBG:[45,49],cyanBG:[46,49],whiteBG:[47,49]};Object.keys(CD).forEach(function(e){var u=CD[e],t=gD[e]=[];t.open="\x1B["+u[0]+"m",t.close="\x1B["+u[1]+"m"})});var bD=A((ZF,BD)=>{"use strict";BD.exports=function(e,u){u=u||process.argv;var t=u.indexOf("--"),n=/^-{1,2}/.test(e)?"":"--",D=u.indexOf(n+e);return D!==-1&&(t===-1?!0:D<t)}});var yD=A((QF,AD)=>{"use strict";var rs=yt("os"),W=bD(),_=process.env,Ce=void 0;W("no-color")||W("no-colors")||W("color=false")?Ce=!1:(W("color")||W("colors")||W("color=true")||W("color=always"))&&(Ce=!0);"FORCE_COLOR"in _&&(Ce=_.FORCE_COLOR.length===0||parseInt(_.FORCE_COLOR,10)!==0);function os(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function is(e){if(Ce===!1)return 0;if(W("color=16m")||W("color=full")||W("color=truecolor"))return 3;if(W("color=256"))return 2;if(e&&!e.isTTY&&Ce!==!0)return 0;var u=Ce?1:0;if(process.platform==="win32"){var t=rs.release().split(".");return Number(process.versions.node.split(".")[0])>=8&&Number(t[0])>=10&&Number(t[2])>=10586?Number(t[2])>=14931?3:2:1}if("CI"in _)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI"].some(function(D){return D in _})||_.CI_NAME==="codeship"?1:u;if("TEAMCITY_VERSION"in _)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(_.TEAMCITY_VERSION)?1:0;if("TERM_PROGRAM"in _){var n=parseInt((_.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(_.TERM_PROGRAM){case"iTerm.app":return n>=3?3:2;case"Hyper":return 3;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(_.TERM)?2:/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(_.TERM)||"COLORTERM"in _?1:(_.TERM==="dumb",u)}function Qu(e){var u=is(e);return os(u)}AD.exports={supportsColor:Qu,stdout:Qu(process.stdout),stderr:Qu(process.stderr)}});var RD=A((e0,xD)=>{xD.exports=function(u,t){var n="";u=u||"Run the trap, drop the bass",u=u.split("");var D={a:["@","\u0104","\u023A","\u0245","\u0394","\u039B","\u0414"],b:["\xDF","\u0181","\u0243","\u026E","\u03B2","\u0E3F"],c:["\xA9","\u023B","\u03FE"],d:["\xD0","\u018A","\u0500","\u0501","\u0502","\u0503"],e:["\xCB","\u0115","\u018E","\u0258","\u03A3","\u03BE","\u04BC","\u0A6C"],f:["\u04FA"],g:["\u0262"],h:["\u0126","\u0195","\u04A2","\u04BA","\u04C7","\u050A"],i:["\u0F0F"],j:["\u0134"],k:["\u0138","\u04A0","\u04C3","\u051E"],l:["\u0139"],m:["\u028D","\u04CD","\u04CE","\u0520","\u0521","\u0D69"],n:["\xD1","\u014B","\u019D","\u0376","\u03A0","\u048A"],o:["\xD8","\xF5","\xF8","\u01FE","\u0298","\u047A","\u05DD","\u06DD","\u0E4F"],p:["\u01F7","\u048E"],q:["\u09CD"],r:["\xAE","\u01A6","\u0210","\u024C","\u0280","\u042F"],s:["\xA7","\u03DE","\u03DF","\u03E8"],t:["\u0141","\u0166","\u0373"],u:["\u01B1","\u054D"],v:["\u05D8"],w:["\u0428","\u0460","\u047C","\u0D70"],x:["\u04B2","\u04FE","\u04FC","\u04FD"],y:["\xA5","\u04B0","\u04CB"],z:["\u01B5","\u0240"]};return u.forEach(function(r){r=r.toLowerCase();var o=D[r]||[" "],i=Math.floor(Math.random()*o.length);typeof D[r]<"u"?n+=D[r][i]:n+=r}),n}});var kD=A((u0,wD)=>{wD.exports=function(u,t){u=u||" he is here ";var n={up:["\u030D","\u030E","\u0304","\u0305","\u033F","\u0311","\u0306","\u0310","\u0352","\u0357","\u0351","\u0307","\u0308","\u030A","\u0342","\u0313","\u0308","\u034A","\u034B","\u034C","\u0303","\u0302","\u030C","\u0350","\u0300","\u0301","\u030B","\u030F","\u0312","\u0313","\u0314","\u033D","\u0309","\u0363","\u0364","\u0365","\u0366","\u0367","\u0368","\u0369","\u036A","\u036B","\u036C","\u036D","\u036E","\u036F","\u033E","\u035B","\u0346","\u031A"],down:["\u0316","\u0317","\u0318","\u0319","\u031C","\u031D","\u031E","\u031F","\u0320","\u0324","\u0325","\u0326","\u0329","\u032A","\u032B","\u032C","\u032D","\u032E","\u032F","\u0330","\u0331","\u0332","\u0333","\u0339","\u033A","\u033B","\u033C","\u0345","\u0347","\u0348","\u0349","\u034D","\u034E","\u0353","\u0354","\u0355","\u0356","\u0359","\u035A","\u0323"],mid:["\u0315","\u031B","\u0300","\u0301","\u0358","\u0321","\u0322","\u0327","\u0328","\u0334","\u0335","\u0336","\u035C","\u035D","\u035E","\u035F","\u0360","\u0362","\u0338","\u0337","\u0361"," \u0489"]},D=[].concat(n.up,n.down,n.mid);function r(s){var a=Math.floor(Math.random()*s);return a}function o(s){var a=!1;return D.filter(function(F){a=F===s}),a}function i(s,a){var F="",c,f;a=a||{},a.up=typeof a.up<"u"?a.up:!0,a.mid=typeof a.mid<"u"?a.mid:!0,a.down=typeof a.down<"u"?a.down:!0,a.size=typeof a.size<"u"?a.size:"maxi",s=s.split("");for(f in s)if(!o(f)){switch(F=F+s[f],c={up:0,down:0,mid:0},a.size){case"mini":c.up=r(8),c.mid=r(2),c.down=r(8);break;case"maxi":c.up=r(16)+3,c.mid=r(4)+1,c.down=r(64)+3;break;default:c.up=r(8)+1,c.mid=r(6)/2,c.down=r(8)+1;break}var d=["up","mid","down"];for(var l in d)for(var C=d[l],h=0;h<=c[C];h++)a[C]&&(F=F+n[C][r(n[C].length)])}return F}return i(u,t)}});var TD=A((t0,SD)=>{SD.exports=function(e){return function(u,t,n){if(u===" ")return u;switch(t%3){case 0:return e.red(u);case 1:return e.white(u);case 2:return e.blue(u)}}}});var vD=A((n0,_D)=>{_D.exports=function(e){return function(u,t,n){return t%2===0?u:e.inverse(u)}}});var MD=A((D0,ID)=>{ID.exports=function(e){var u=["red","yellow","green","blue","magenta"];return function(t,n,D){return t===" "?t:e[u[n++%u.length]](t)}}});var OD=A((r0,PD)=>{PD.exports=function(e){var u=["underline","inverse","grey","yellow","red","green","blue","white","cyan","magenta","brightYellow","brightRed","brightGreen","brightBlue","brightWhite","brightCyan","brightMagenta"];return function(t,n,D){return t===" "?t:e[u[Math.round(Math.random()*(u.length-2))]](t)}}});var jD=A((i0,WD)=>{var E={};WD.exports=E;E.themes={};var ss=yt("util"),ce=E.styles=ED(),ND=Object.defineProperties,as=new RegExp(/[\r\n]+/g);E.supportsColor=yD().supportsColor;typeof E.enabled>"u"&&(E.enabled=E.supportsColor()!==!1);E.enable=function(){E.enabled=!0};E.disable=function(){E.enabled=!1};E.stripColors=E.strip=function(e){return(""+e).replace(/\x1B\[\d+m/g,"")};var o0=E.stylize=function(u,t){if(!E.enabled)return u+"";var n=ce[t];return!n&&t in E?E[t](u):n.open+u+n.close},cs=/[|\\{}()[\]^$+*?.]/g,ls=function(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(cs,"\\$&")};function $D(e){var u=function t(){return ds.apply(t,arguments)};return u._styles=e,u.__proto__=Fs,u}var UD=(function(){var e={};return ce.grey=ce.gray,Object.keys(ce).forEach(function(u){ce[u].closeRe=new RegExp(ls(ce[u].close),"g"),e[u]={get:function(){return $D(this._styles.concat(u))}}}),e})(),Fs=ND(function(){},UD);function ds(){var e=Array.prototype.slice.call(arguments),u=e.map(function(o){return o!=null&&o.constructor===String?o:ss.inspect(o)}).join(" ");if(!E.enabled||!u)return u;for(var t=u.indexOf(`
5
+ `)!=-1,n=this._styles,D=n.length;D--;){var r=ce[n[D]];u=r.open+u.replace(r.closeRe,r.open)+r.close,t&&(u=u.replace(as,function(o){return r.close+o+r.open}))}return u}E.setTheme=function(e){if(typeof e=="string"){console.log("colors.setTheme now only accepts an object, not a string. If you are trying to set a theme from a file, it is now your (the caller's) responsibility to require the file. The old syntax looked like colors.setTheme(__dirname + '/../themes/generic-logging.js'); The new syntax looks like colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));");return}for(var u in e)(function(t){E[t]=function(n){if(typeof e[t]=="object"){var D=n;for(var r in e[t])D=E[e[t][r]](D);return D}return E[e[t]](n)}})(u)};function fs(){var e={};return Object.keys(UD).forEach(function(u){e[u]={get:function(){return $D([u])}}}),e}var ps=function(u,t){var n=t.split("");return n=n.map(u),n.join("")};E.trap=RD();E.zalgo=kD();E.maps={};E.maps.america=TD()(E);E.maps.zebra=vD()(E);E.maps.rainbow=MD()(E);E.maps.random=OD()(E);for(LD in E.maps)(function(e){E[e]=function(u){return ps(E.maps[e],u)}})(LD);var LD;ND(E,fs())});var qD=A((s0,GD)=>{var hs=jD();GD.exports=hs});var KD=A((a0,ou)=>{var{info:Cs,debug:zD}=Du(),L=Zu(),ut=class e{constructor(u){this.setOptions(u),this.x=null,this.y=null}setOptions(u){["boolean","number","bigint","string"].indexOf(typeof u)!==-1&&(u={content:""+u}),u=u||{},this.options=u;let t=u.content;if(["boolean","number","bigint","string"].indexOf(typeof t)!==-1)this.content=String(t);else if(!t)this.content=this.options.href||"";else throw new Error("Content needs to be a primitive, got: "+typeof t);this.colSpan=u.colSpan||1,this.rowSpan=u.rowSpan||1,this.options.href&&Object.defineProperty(this,"href",{get(){return this.options.href}})}mergeTableOptions(u,t){this.cells=t;let n=this.options.chars||{},D=u.chars,r=this.chars={};ms.forEach(function(s){et(n,D,s,r)}),this.truncate=this.options.truncate||u.truncate;let o=this.options.style=this.options.style||{},i=u.style;et(o,i,"padding-left",this),et(o,i,"padding-right",this),this.head=o.head||i.head,this.border=o.border||i.border,this.fixedWidth=u.colWidths[this.x],this.lines=this.computeLines(u),this.desiredWidth=L.strlen(this.content)+this.paddingLeft+this.paddingRight,this.desiredHeight=this.lines.length}computeLines(u){let t=u.wordWrap||u.textWrap,{wordWrap:n=t}=this.options;if(this.fixedWidth&&n){if(this.fixedWidth-=this.paddingLeft+this.paddingRight,this.colSpan){let o=1;for(;o<this.colSpan;)this.fixedWidth+=u.colWidths[this.x+o],o++}let{wrapOnWordBoundary:D=!0}=u,{wrapOnWordBoundary:r=D}=this.options;return this.wrapLines(L.wordWrap(this.fixedWidth,this.content,r))}return this.wrapLines(this.content.split(`
6
+ `))}wrapLines(u){let t=L.colorizeLines(u);return this.href?t.map(n=>L.hyperlink(this.href,n)):t}init(u){let t=this.x,n=this.y;this.widths=u.colWidths.slice(t,t+this.colSpan),this.heights=u.rowHeights.slice(n,n+this.rowSpan),this.width=this.widths.reduce(VD,-1),this.height=this.heights.reduce(VD,-1),this.hAlign=this.options.hAlign||u.colAligns[t],this.vAlign=this.options.vAlign||u.rowAligns[n],this.drawRight=t+this.colSpan==u.colWidths.length}draw(u,t){if(u=="top")return this.drawTop(this.drawRight);if(u=="bottom")return this.drawBottom(this.drawRight);let n=L.truncate(this.content,10,this.truncate);u||Cs(`${this.y}-${this.x}: ${this.rowSpan-u}x${this.colSpan} Cell ${n}`);let D=Math.max(this.height-this.lines.length,0),r;switch(this.vAlign){case"center":r=Math.ceil(D/2);break;case"bottom":r=D;break;default:r=0}if(u<r||u>=r+this.lines.length)return this.drawEmpty(this.drawRight,t);let o=this.lines.length>this.height&&u+1>=this.height;return this.drawLine(u-r,this.drawRight,o,t)}drawTop(u){let t=[];return this.cells?this.widths.forEach(function(n,D){t.push(this._topLeftChar(D)),t.push(L.repeat(this.chars[this.y==0?"top":"mid"],n))},this):(t.push(this._topLeftChar(0)),t.push(L.repeat(this.chars[this.y==0?"top":"mid"],this.width))),u&&t.push(this.chars[this.y==0?"topRight":"rightMid"]),this.wrapWithStyleColors("border",t.join(""))}_topLeftChar(u){let t=this.x+u,n;if(this.y==0)n=t==0?"topLeft":u==0?"topMid":"top";else if(t==0)n="leftMid";else if(n=u==0?"midMid":"bottomMid",this.cells&&(this.cells[this.y-1][t]instanceof e.ColSpanCell&&(n=u==0?"topMid":"mid"),u==0)){let r=1;for(;this.cells[this.y][t-r]instanceof e.ColSpanCell;)r++;this.cells[this.y][t-r]instanceof e.RowSpanCell&&(n="leftMid")}return this.chars[n]}wrapWithStyleColors(u,t){if(this[u]&&this[u].length)try{let n=qD();for(let D=this[u].length-1;D>=0;D--)n=n[this[u][D]];return n(t)}catch{return t}else return t}drawLine(u,t,n,D){let r=this.chars[this.x==0?"left":"middle"];if(this.x&&D&&this.cells){let f=this.cells[this.y+D][this.x-1];for(;f instanceof Pe;)f=this.cells[f.y][f.x-1];f instanceof Oe||(r=this.chars.rightMid)}let o=L.repeat(" ",this.paddingLeft),i=t?this.chars.right:"",s=L.repeat(" ",this.paddingRight),a=this.lines[u],F=this.width-(this.paddingLeft+this.paddingRight);n&&(a+=this.truncate||"\u2026");let c=L.truncate(a,F,this.truncate);return c=L.pad(c,F," ",this.hAlign),c=o+c+s,this.stylizeLine(r,c,i)}stylizeLine(u,t,n){return u=this.wrapWithStyleColors("border",u),n=this.wrapWithStyleColors("border",n),this.y===0&&(t=this.wrapWithStyleColors("head",t)),u+t+n}drawBottom(u){let t=this.chars[this.x==0?"bottomLeft":"bottomMid"],n=L.repeat(this.chars.bottom,this.width),D=u?this.chars.bottomRight:"";return this.wrapWithStyleColors("border",t+n+D)}drawEmpty(u,t){let n=this.chars[this.x==0?"left":"middle"];if(this.x&&t&&this.cells){let o=this.cells[this.y+t][this.x-1];for(;o instanceof Pe;)o=this.cells[o.y][o.x-1];o instanceof Oe||(n=this.chars.rightMid)}let D=u?this.chars.right:"",r=L.repeat(" ",this.width);return this.stylizeLine(n,r,D)}},Pe=class{constructor(){}draw(u){return typeof u=="number"&&zD(`${this.y}-${this.x}: 1x1 ColSpanCell`),""}init(){}mergeTableOptions(){}},Oe=class{constructor(u){this.originalCell=u}init(u){let t=this.y,n=this.originalCell.y;this.cellOffset=t-n,this.offset=gs(u.rowHeights,n,this.cellOffset)}draw(u){return u=="top"?this.originalCell.draw(this.offset,this.cellOffset):u=="bottom"?this.originalCell.draw("bottom"):(zD(`${this.y}-${this.x}: 1x${this.colSpan} RowSpanCell for ${this.originalCell.content}`),this.originalCell.draw(this.offset+1+u))}mergeTableOptions(){}};function HD(...e){return e.filter(u=>u!=null).shift()}function et(e,u,t,n){let D=t.split("-");D.length>1?(D[1]=D[1].charAt(0).toUpperCase()+D[1].substr(1),D=D.join(""),n[D]=HD(e[D],e[t],u[D],u[t])):n[t]=HD(e[t],u[t])}function gs(e,u,t){let n=e[u];for(let D=1;D<t;D++)n+=1+e[u+D];return n}function VD(e,u){return e+u+1}var ms=["top","top-mid","top-left","top-right","bottom","bottom-mid","bottom-left","bottom-right","left","left-mid","mid","mid-mid","right","right-mid","middle"];ou.exports=ut;ou.exports.ColSpanCell=Pe;ou.exports.RowSpanCell=Oe});var XD=A((c0,JD)=>{var{warn:Es,debug:Bs}=Du(),tt=KD(),{ColSpanCell:bs,RowSpanCell:As}=tt;(function(){function e(d,l){return d[l]>0?e(d,l+1):l}function u(d){let l={};d.forEach(function(C,h){let p=0;C.forEach(function(g){g.y=h,g.x=h?e(l,p):p;let B=g.rowSpan||1,m=g.colSpan||1;if(B>1)for(let b=0;b<m;b++)l[g.x+b]=B;p=g.x+m}),Object.keys(l).forEach(g=>{l[g]--,l[g]<1&&delete l[g]})})}function t(d){let l=0;return d.forEach(function(C){C.forEach(function(h){l=Math.max(l,h.x+(h.colSpan||1))})}),l}function n(d){return d.length}function D(d,l){let C=d.y,h=d.y-1+(d.rowSpan||1),p=l.y,g=l.y-1+(l.rowSpan||1),B=!(C>g||p>h),m=d.x,b=d.x-1+(d.colSpan||1),k=l.x,se=l.x-1+(l.colSpan||1),S=!(m>se||k>b);return B&&S}function r(d,l,C){let h=Math.min(d.length-1,C),p={x:l,y:C};for(let g=0;g<=h;g++){let B=d[g];for(let m=0;m<B.length;m++)if(D(p,B[m]))return!0}return!1}function o(d,l,C,h){for(let p=C;p<h;p++)if(r(d,p,l))return!1;return!0}function i(d){d.forEach(function(l,C){l.forEach(function(h){for(let p=1;p<h.rowSpan;p++){let g=new As(h);g.x=h.x,g.y=h.y+p,g.colSpan=h.colSpan,a(g,d[C+p])}})})}function s(d){for(let l=d.length-1;l>=0;l--){let C=d[l];for(let h=0;h<C.length;h++){let p=C[h];for(let g=1;g<p.colSpan;g++){let B=new bs;B.x=p.x+g,B.y=p.y,C.splice(h+1,0,B)}}}}function a(d,l){let C=0;for(;C<l.length&&l[C].x<d.x;)C++;l.splice(C,0,d)}function F(d){let l=n(d),C=t(d);Bs(`Max rows: ${l}; Max cols: ${C}`);for(let h=0;h<l;h++)for(let p=0;p<C;p++)if(!r(d,p,h)){let g={x:p,y:h,colSpan:1,rowSpan:1};for(p++;p<C&&!r(d,p,h);)g.colSpan++,p++;let B=h+1;for(;B<l&&o(d,B,g.x,g.x+g.colSpan);)g.rowSpan++,B++;let m=new tt(g);m.x=g.x,m.y=g.y,Es(`Missing cell at ${m.y}-${m.x}.`),a(m,d[h])}}function c(d){return d.map(function(l){if(!Array.isArray(l)){let C=Object.keys(l)[0];l=l[C],Array.isArray(l)?(l=l.slice(),l.unshift(C)):l=[C,l]}return l.map(function(C){return new tt(C)})})}function f(d){let l=c(d);return u(l),F(l),i(l),s(l),l}JD.exports={makeTableLayout:f,layoutTable:u,addRowSpanCells:i,maxWidth:t,fillInTable:F,computeWidths:YD("colSpan","desiredWidth","x",1),computeHeights:YD("rowSpan","desiredHeight","y",1)}})();function YD(e,u,t,n){return function(D,r){let o=[],i=[],s={};r.forEach(function(a){a.forEach(function(F){(F[e]||1)>1?i.push(F):o[F[t]]=Math.max(o[F[t]]||0,F[u]||0,n)})}),D.forEach(function(a,F){typeof a=="number"&&(o[F]=a)});for(let a=i.length-1;a>=0;a--){let F=i[a],c=F[e],f=F[t],d=o[f],l=typeof D[f]=="number"?0:1;if(typeof d=="number")for(let C=1;C<c;C++)d+=1+o[f+C],typeof D[f+C]!="number"&&l++;else d=u==="desiredWidth"?F.desiredWidth-1:1,(!s[f]||s[f]<d)&&(s[f]=d);if(F[u]>d){let C=0;for(;l>0&&F[u]>d;){if(typeof D[f+C]!="number"){let h=Math.round((F[u]-d)/l);d+=h,o[f+C]+=h,l--}C++}}}Object.assign(D,o,s);for(let a=0;a<D.length;a++)D[a]=Math.max(n,D[a]||0)}}});var QD=A((l0,ZD)=>{var Z=Du(),ys=Zu(),nt=XD(),iu=class extends Array{constructor(u){super();let t=ys.mergeOptions(u);if(Object.defineProperty(this,"options",{value:t,enumerable:t.debug}),t.debug){switch(typeof t.debug){case"boolean":Z.setDebugLevel(Z.WARN);break;case"number":Z.setDebugLevel(t.debug);break;case"string":Z.setDebugLevel(parseInt(t.debug,10));break;default:Z.setDebugLevel(Z.WARN),Z.warn(`Debug option is expected to be boolean, number, or string. Received a ${typeof t.debug}`)}Object.defineProperty(this,"messages",{get(){return Z.debugMessages()}})}}toString(){let u=this,t=this.options.head&&this.options.head.length;t?(u=[this.options.head],this.length&&u.push.apply(u,this)):this.options.style.head=[];let n=nt.makeTableLayout(u);n.forEach(function(r){r.forEach(function(o){o.mergeTableOptions(this.options,n)},this)},this),nt.computeWidths(this.options.colWidths,n),nt.computeHeights(this.options.rowHeights,n),n.forEach(function(r){r.forEach(function(o){o.init(this.options)},this)},this);let D=[];for(let r=0;r<n.length;r++){let o=n[r],i=this.options.rowHeights[r];(r===0||!this.options.style.compact||r==1&&t)&&Dt(o,"top",D);for(let s=0;s<i;s++)Dt(o,s,D);r+1==n.length&&Dt(o,"bottom",D)}return D.join(`
7
+ `)}get width(){return this.toString().split(`
8
+ `)[0].length}};iu.reset=()=>Z.reset();function Dt(e,u,t){let n=[];e.forEach(function(r){n.push(r.draw(u))});let D=n.join("");D.length&&t.push(D)}ZD.exports=iu});var ur=A((F0,er)=>{er.exports=QD()});import He from"node:path";import Zr from"node:os";import{createReadStream as zr}from"node:fs";import Kr from"node:readline";var Eu=200;async function xt(e){let u=zr(e,{encoding:"utf8"}),t=Kr.createInterface({input:u,crlfDelay:1/0}),n=[],D=[],r=[];for await(let o of t){if(!o.trim())continue;let i;try{i=JSON.parse(o)}catch{continue}if(!(!i||typeof i!="object")){if(i.uuid&&r.push([i.uuid,i.parentUuid??null]),i.type==="assistant"){let s=Yr(i,e);s&&n.push(s)}else if(i.type==="user"){let s=Jr(i,e);s&&D.push(s)}}}return{assistant:n,user:D,parentLinks:r}}function Yr(e,u){let t=e.message;if(!t)return null;let n=t.usage;if(!n)return null;let D=t.model??"";if(!D||D==="<synthetic>")return null;let r=t.id??e.uuid??"";if(!r&&!e.requestId)return null;let o=n.cache_creation,i=Array.isArray(t.content)?t.content:[],s=[],a=!1,F="";for(let c of i)c.type==="tool_use"&&typeof c.name=="string"?s.push(c.name):c.type==="thinking"?a=!0:c.type==="text"&&typeof c.text=="string"&&!F&&(F=c.text.slice(0,Eu));return{type:"assistant",source:"claude",uuid:e.uuid??r,parentUuid:e.parentUuid??null,timestamp:e.timestamp??new Date().toISOString(),sessionId:e.sessionId??"",requestId:e.requestId??"",cwd:e.cwd??"",gitBranch:e.gitBranch,version:e.version,model:D,messageId:r,usage:{input_tokens:Number(n.input_tokens)||0,output_tokens:Number(n.output_tokens)||0,cache_creation_input_tokens:Number(n.cache_creation_input_tokens)||0,cache_read_input_tokens:Number(n.cache_read_input_tokens)||0,cache_creation_5m:Number(o?.ephemeral_5m_input_tokens)||0,cache_creation_1h:Number(o?.ephemeral_1h_input_tokens)||0},toolNames:s,hasThinking:a,textPreview:F,filePath:u,isSidechain:e.isSidechain===!0?!0:void 0}}function Jr(e,u){if(!e.uuid)return null;let t=e.message,n="";if(t){let o=t.content;if(typeof o=="string")n=o.slice(0,Eu);else if(Array.isArray(o)){for(let i of o)if(i.type==="text"&&typeof i.text=="string"){n=i.text.slice(0,Eu);break}}}let D=e.isSidechain===!0,r=D||!!n&&Xr(n);return{type:"user",source:"claude",uuid:e.uuid,parentUuid:e.parentUuid??null,timestamp:e.timestamp??new Date().toISOString(),sessionId:e.sessionId??"",cwd:e.cwd??"",textPreview:n,isSynthetic:r,isSidechain:D?!0:void 0,filePath:u}}function Xr(e){let u=e.trimStart();return!!(u.startsWith("Base directory for this skill:")||u.startsWith("<system-reminder>")||u.startsWith("Caveat: The messages below were generated by"))}var q={"claude-opus-4-8":{input:5,output:25,cacheCreation5m:6.25,cacheCreation1h:10,cacheRead:.5},"claude-opus-4-7":{input:5,output:25,cacheCreation5m:6.25,cacheCreation1h:10,cacheRead:.5},"claude-opus-4-6":{input:5,output:25,cacheCreation5m:6.25,cacheCreation1h:10,cacheRead:.5},"claude-opus-4-5":{input:5,output:25,cacheCreation5m:6.25,cacheCreation1h:10,cacheRead:.5},"claude-sonnet-4-6":{input:3,output:15,cacheCreation5m:3.75,cacheCreation1h:6,cacheRead:.3},"claude-sonnet-4-5":{input:3,output:15,cacheCreation5m:3.75,cacheCreation1h:6,cacheRead:.3},"claude-haiku-4-5":{input:1,output:5,cacheCreation5m:1.25,cacheCreation1h:2,cacheRead:.1},"claude-haiku-3-5":{input:.8,output:4,cacheCreation5m:1,cacheCreation1h:1.6,cacheRead:.08},"claude-opus-4-1":{input:15,output:75,cacheCreation5m:18.75,cacheCreation1h:30,cacheRead:1.5},"claude-opus-4":{input:15,output:75,cacheCreation5m:18.75,cacheCreation1h:30,cacheRead:1.5},"claude-sonnet-4":{input:3,output:15,cacheCreation5m:3.75,cacheCreation1h:6,cacheRead:.3},"claude-sonnet-3-7":{input:3,output:15,cacheCreation5m:3.75,cacheCreation1h:6,cacheRead:.3},"claude-haiku-3":{input:.25,output:1.25,cacheCreation5m:.3,cacheCreation1h:.5,cacheRead:.03}},Rt={opus:q["claude-opus-4-8"],sonnet:q["claude-sonnet-4-6"],haiku:q["claude-haiku-4-5"]};function Be(e,u){if(!u)return{input:0,output:0,cacheCreation5m:0,cacheCreation1h:0,cacheRead:0,total:0,saved:0};let t=e.input_tokens/1e6*u.input,n=e.output_tokens/1e6*u.output,D=e.cache_creation_5m/1e6*u.cacheCreation5m,r=e.cache_creation_1h/1e6*u.cacheCreation1h;D+r===0&&e.cache_creation_input_tokens>0&&(D=e.cache_creation_input_tokens/1e6*u.cacheCreation5m);let o=e.cache_read_input_tokens/1e6*u.cacheRead,i=t+n+D+r+o,s=e.cache_read_input_tokens/1e6*(u.input-u.cacheRead);return{input:t,output:n,cacheCreation5m:D,cacheCreation1h:r,cacheRead:o,total:i,saved:s}}function wt(e){return e.replace(/\b\w/g,u=>u.toUpperCase())}function kt(e){if(!e)return"(unknown)";let u=e.replace(/-(\d{8})$/,"").replace(/^(vertex_ai|bedrock|anthropic)\//,"");u=u.replace(/^claude-/,"");let t=u.split("-");if(t.length>=2){let n=t[0],D=t.slice(1).join(".");return wt(n)+" "+D}return wt(u.replace(/-/g," "))}var Qr=/-\d{8}$/,eo=/^(vertex_ai|bedrock|anthropic)\//;function uo(e){if(!e)return{pricing:null,matchType:"none",matchedKey:null};if(q[e])return{pricing:q[e],matchType:"exact",matchedKey:e};let u=e.replace(Qr,"");if(q[u])return{pricing:q[u],matchType:"date-stripped",matchedKey:u};let t=u.replace(eo,"");if(q[t])return{pricing:q[t],matchType:"prefix-stripped",matchedKey:t};for(let n of["opus","sonnet","haiku"])if(e.toLowerCase().includes(n))return{pricing:Rt[n],matchType:"family-fallback",matchedKey:`claude-${n}-(latest)`};return{pricing:null,matchType:"none",matchedKey:null}}function to(){let e=Zr.homedir(),u=[He.join(e,".claude","projects"),He.join(e,".config","claude","projects")];return process.env.CCGAUGE_CONFIG_DIR&&u.push(He.join(process.env.CCGAUGE_CONFIG_DIR,"projects")),process.env.CLAUDE_CONFIG_DIR&&u.push(He.join(process.env.CLAUDE_CONFIG_DIR,"projects")),Array.from(new Set(u))}var St={id:"claude",displayName:{en:"Claude",zh:"Claude"},shortLabel:"C",color:{fg:"#b45309",bg:"#fef3c7"},logoSrc:"/claude-logo.webp",parserVersion:"claude-v4-sidechain-merge",capabilities:{hasCacheCreation:!0,hasReasoningTokens:!1,blockWindowMs:300*60*1e3},getDirs:to,shouldSkipDir:e=>e==="tool-results"||e==="memory",parseFile:async e=>await xt(e),resolvePricing:uo,shortenModel:kt,costFromUsage:Be,costFootnoteKey:null};import Ve from"node:path";import lo from"node:os";import{createReadStream as no,promises as Do}from"node:fs";import ro from"node:readline";var Bu=200;async function oo(e){try{let u=await Do.stat(e);return new Date(u.mtimeMs).toISOString()}catch{return new Date().toISOString()}}function M(e){return typeof e=="string"?e:""}function ne(e){let u=Number(e);return Number.isFinite(u)?u:0}function bu(e){let u=e.message;if(typeof u=="string")return u;let t=e.content;if(typeof t=="string")return t;if(Array.isArray(t))for(let n of t){let D=n?.type;if((D==="input_text"||D==="output_text"||D==="text")&&typeof n.text=="string")return n.text}return""}async function Tt(e){let u=no(e,{encoding:"utf8"}),t=ro.createInterface({input:u,crlfDelay:1/0}),n=[],D=[],r=[],o="",i,s="",a=0,F=0,c=null,d=await oo(e),l={turnId:null,cwd:"",model:"gpt-unknown",userUuid:null,toolNames:[],hasThinking:!1,pendingTextPreview:""};for await(let C of t){if(!C.trim())continue;let h;try{h=JSON.parse(C)}catch{continue}if(!h||typeof h!="object"||!h.type)continue;let p=h.payload??{},g=M(h.timestamp),B=g||d;if(g&&(d=g),h.type==="session_meta"){o=M(p.id),s=M(p.cwd),i=M(p.cli_version)||void 0;let m=M(p.timestamp);m&&(d=m),l.cwd||(l.cwd=s);continue}if(h.type==="turn_context"){l.turnId=M(p.turn_id)||l.turnId,l.cwd=M(p.cwd)||s;let m=M(p.model);m&&(l.model=m);let b=M(p.effort);b&&(l.effort=b),l.toolNames=[],l.hasThinking=!1,l.pendingTextPreview="";continue}if(h.type==="event_msg"){let m=M(p.type);if(m==="user_message"){let b=bu(p);if(!b)continue;let k=`${o}::u${a++}`;D.push({type:"user",source:"codex",uuid:k,parentUuid:null,timestamp:B,sessionId:o,cwd:l.cwd||s,textPreview:b.slice(0,Bu),filePath:e}),r.push([k,null]),l.userUuid=k;continue}if(m==="agent_message"){let b=bu(p);b&&!l.pendingTextPreview&&(l.pendingTextPreview=b.slice(0,Bu));continue}if(m==="agent_reasoning"){l.hasThinking=!0;continue}if(m==="token_count"){let b=p.info;if(!b)continue;let k=b.total_token_usage,se=b.last_token_usage,S=k?{input:ne(k.input_tokens),cached:ne(k.cached_input_tokens),output:ne(k.output_tokens),reasoning:ne(k.reasoning_output_tokens)}:null,ue,z,te,K;if(S){if(c===null?(ue=S.input,z=S.cached,te=S.output,K=S.reasoning):(ue=Math.max(0,S.input-c.input),z=Math.max(0,S.cached-c.cached),te=Math.max(0,S.output-c.output),K=Math.max(0,S.reasoning-c.reasoning)),ue===0&&z===0&&te===0&&K===0)continue;c===null?c={...S}:c={input:Math.max(c.input,S.input),cached:Math.max(c.cached,S.cached),output:Math.max(c.output,S.output),reasoning:Math.max(c.reasoning,S.reasoning)}}else if(se){if(ue=ne(se.input_tokens),z=ne(se.cached_input_tokens),te=ne(se.output_tokens),K=ne(se.reasoning_output_tokens),ue===0&&z===0&&te===0&&K===0)continue;c===null?c={input:ue,cached:z,output:te,reasoning:K}:c={input:c.input+ue,cached:c.cached+z,output:c.output+te,reasoning:c.reasoning+K}}else continue;let Bt=`${o}::a${F++}`,bt=l.turnId?`${l.turnId}::a${F}`:`${o}::a${F}`;n.push({type:"assistant",source:"codex",uuid:Bt,parentUuid:l.userUuid,timestamp:B,sessionId:o,requestId:bt,cwd:l.cwd||s,version:i,model:l.model||"gpt-unknown",messageId:bt,usage:{input_tokens:Math.max(0,ue-z),output_tokens:te+K,cache_creation_input_tokens:0,cache_read_input_tokens:z,cache_creation_5m:0,cache_creation_1h:0,reasoning_tokens:K},toolNames:[...l.toolNames],hasThinking:l.hasThinking,textPreview:l.pendingTextPreview,filePath:e,effort:l.effort}),r.push([Bt,l.userUuid]),l.toolNames=[],l.hasThinking=!1,l.pendingTextPreview="";continue}continue}if(h.type==="response_item"){let m=M(p.type);if(m==="function_call"||m==="custom_tool_call"){let b=M(p.name);b&&l.toolNames.push(b);continue}if(m==="reasoning"){l.hasThinking=!0;continue}if(m==="message"){if(M(p.role)==="assistant"){let k=bu(p);k&&!l.pendingTextPreview&&(l.pendingTextPreview=k.slice(0,Bu))}continue}continue}}return{assistant:n,user:D,parentLinks:r}}var De={"gpt-5":{input:1.25,output:10,cacheRead:.13,cacheCreation5m:0,cacheCreation1h:0},"gpt-5-mini":{input:.25,output:2,cacheRead:.025,cacheCreation5m:0,cacheCreation1h:0},"gpt-5-nano":{input:.05,output:.4,cacheRead:.005,cacheCreation5m:0,cacheCreation1h:0},"gpt-5.4":{input:1.25,output:10,cacheRead:.13,cacheCreation5m:0,cacheCreation1h:0},"gpt-5.5":{input:1.25,output:10,cacheRead:.13,cacheCreation5m:0,cacheCreation1h:0},"gpt-5.5-mini":{input:.25,output:2,cacheRead:.025,cacheCreation5m:0,cacheCreation1h:0},"gpt-5.5-nano":{input:.05,output:.4,cacheRead:.005,cacheCreation5m:0,cacheCreation1h:0},"gpt-4.1":{input:2,output:8,cacheRead:.5,cacheCreation5m:0,cacheCreation1h:0},"gpt-4.1-mini":{input:.4,output:1.6,cacheRead:.1,cacheCreation5m:0,cacheCreation1h:0},o3:{input:2,output:8,cacheRead:.5,cacheCreation5m:0,cacheCreation1h:0},"o4-mini":{input:1.1,output:4.4,cacheRead:.275,cacheCreation5m:0,cacheCreation1h:0}},_t={gpt:De["gpt-5"],o:De.o3},io=/-\d{8}$/,so=/^(openai)\//;function vt(e){if(!e)return{pricing:null,matchType:"none",matchedKey:null};if(De[e])return{pricing:De[e],matchType:"exact",matchedKey:e};let u=e.replace(io,"");if(De[u])return{pricing:De[u],matchType:"date-stripped",matchedKey:u};let t=u.replace(so,"");if(De[t])return{pricing:De[t],matchType:"prefix-stripped",matchedKey:t};let n=e.toLowerCase();return n.startsWith("gpt-")||n==="gpt"?{pricing:_t.gpt,matchType:"family-fallback",matchedKey:"gpt-(latest)"}:/^o\d/.test(n)?{pricing:_t.o,matchType:"family-fallback",matchedKey:"o-(latest)"}:{pricing:null,matchType:"none",matchedKey:null}}function ao(e){return e.replace(/\b\w/g,u=>u.toUpperCase())}var co={mini:"Mini",nano:"Nano",pro:"Pro",turbo:"Turbo",preview:"Preview"};function It(e){if(!e)return"(unknown)";let u=e.replace(/^openai\//,"");return u.toLowerCase().startsWith("gpt-")?"GPT-"+u.slice(4).split("-").map(D=>co[D.toLowerCase()]??D).join(" "):u.toLowerCase().startsWith("o")?u.toUpperCase():ao(u.replace(/-/g," "))}function Fo(){let e=lo.homedir(),u=[Ve.join(e,".codex","sessions"),Ve.join(e,".codex","archived_sessions")];return process.env.CCGAUGE_CODEX_DIR&&u.push(process.env.CCGAUGE_CODEX_DIR),process.env.CODEX_HOME&&(u.push(Ve.join(process.env.CODEX_HOME,"sessions")),u.push(Ve.join(process.env.CODEX_HOME,"archived_sessions"))),Array.from(new Set(u))}var Mt={id:"codex",displayName:{en:"Codex",zh:"Codex"},shortLabel:"X",color:{fg:"#047857",bg:"#d1fae5"},logoSrc:"/codex-logo.webp",parserVersion:"codex-v5-last-total-prev",capabilities:{hasCacheCreation:!1,hasReasoningTokens:!0,blockWindowMs:300*60*1e3},getDirs:Fo,shouldSkipDir:()=>!1,parseFile:Tt,resolvePricing:vt,shortenModel:It,costFromUsage:Be,costFootnoteKey:"cost.footnote.codex"};var Pt={claude:St,codex:Mt},Au=["claude","codex"];function re(e){return Pt[e]}function yu(){return Au.map(e=>Pt[e])}function Ot(e){return typeof e=="string"&&(e==="claude"||e==="codex")}import{promises as be,watch as Eo}from"node:fs";import qt from"node:path";function fo(e){let u=`${e.source}:`;return e.messageId&&e.requestId?`${u}${e.messageId}::${e.requestId}`:e.messageId?`${u}mid:${e.messageId}`:e.requestId?`${u}req:${e.requestId}`:`${u}uuid:${e.uuid}`}function Lt(e){let u=new Map;for(let t of e){let n=fo(t),D=u.get(n);if(!D){u.set(n,t);continue}t.timestamp<D.timestamp&&u.set(n,t)}return Array.from(u.values())}import{promises as ze}from"node:fs";import xu from"node:path";import po from"node:os";var Ke=2,Fe="default";function ho(){return process.env.CCGAUGE_STATE_DIR?process.env.CCGAUGE_STATE_DIR:xu.join(po.homedir(),".ccgauge")}function Nt(e){let u=e===Fe?`index-v${Ke}.json`:`index-${e}-v${Ke}.json`;return xu.join(ho(),"cache",u)}async function $t(e=Fe){let u=Nt(e);try{let t=await ze.readFile(u,"utf8"),n=JSON.parse(t);return n.schemaVersion!==Ke||!Array.isArray(n.files)?null:n}catch{return null}}async function Ut(e,u=Fe){let t=Nt(u),n=xu.dirname(t);await ze.mkdir(n,{recursive:!0});let D={schemaVersion:Ke,savedAt:e.savedAt,files:e.files},r=`${t}.tmp-${process.pid}`;await ze.writeFile(r,JSON.stringify(D)),await ze.rename(r,t)}var Co=/\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/subagents\/agent-[^/]+\.jsonl$/i;function go(e){let u=Co.exec(e);return u?u[1]:null}function Wt({assistantRecords:e,userRecords:u,parentMap:t}){let n=new Map;for(let o of e){if(o.isSidechain||!o.sessionId)continue;let i=n.get(o.sessionId);i||(i=[],n.set(o.sessionId,i)),i.push(o)}for(let o of n.values())o.sort((i,s)=>i.timestamp<s.timestamp?-1:i.timestamp>s.timestamp?1:0);let D=new Map;for(let o of u){if(!o.isSidechain)continue;let i=D.get(o.filePath);(!i||o.timestamp<i.timestamp)&&D.set(o.filePath,o)}let r={subagentFiles:0,relinked:0,orphans:0,alreadyLinked:0};for(let[o,i]of D){let s=go(o);if(!s)continue;r.subagentFiles+=1;let a=t[i.uuid];if(a!=null){r.alreadyLinked+=1;continue}let F=n.get(s);if(!F||F.length===0){r.orphans+=1;continue}let c=i.timestamp,f;for(let d=F.length-1;d>=0;d-=1)if(F[d].timestamp<=c){f=F[d];break}f||(f=F[0]),t[i.uuid]=f.uuid,r.relinked+=1}return r}import{homedir as mo}from"node:os";function jt(e){let u=mo();if(!u)return e;let t=new Set([u]);process.platform==="win32"&&(t.add(u.replace(/\\/g,"/")),t.add(u.replace(/\\/g,"\\\\")),t.add("\\\\?\\"+u),t.add("\\\\?\\"+u.replace(/\\/g,"/")));let n=e;for(let D of t){let r=D.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");n=n.replace(new RegExp(r,"g"),"~")}return n}var Bo=200,bo=100,Ao=3e4,yo=2e3,xo=8,Ru=20,wu=class{cacheName;files=new Map;snapshot=null;watchers=new Map;pollTimer=null;snapshotRebuildTimer=null;persistTimer=null;fileDebouncers=new Map;initPromise=null;isIndexing=!1;lastIndexedAt=null;indexDurationMs=null;existingDirs=[];dirToProvider=new Map;errors=[];loadedFromDisk=!1;lastWorkStart=null;rescanPromise=null;mutationTail=Promise.resolve();constructor(u=Fe){this.cacheName=u}runExclusive(u){let t=this.mutationTail.then(u,u);return this.mutationTail=t.then(()=>{},()=>{}),t}init(){return this.initPromise||(this.initPromise=this.doInit()),this.initPromise}async doInit(){let u=Date.now();this.isIndexing=!0,this.lastWorkStart=u;try{await this.detectProviderDirs();let t=await $t(this.cacheName);this.loadedFromDisk=t!==null;let n=new Map;if(t)for(let D of t.files)n.set(D.filePath,D);await this.runExclusive(async()=>{await this.fullScan(n),this.rebuildSnapshotNow(),this.indexDurationMs=Date.now()-u,this.lastIndexedAt=new Date().toISOString(),this.schedulePersist()}),this.syncWatchersToDirs(),this.setupPolling()}finally{this.isIndexing=!1}}async detectProviderDirs(){let u=new Map,t=[];for(let r of yu())for(let o of r.getDirs())await Ro(o)&&(u.has(o)||(u.set(o,r),t.push(o)));let n=[],D=[];for(let r of u.keys())this.dirToProvider.has(r)||n.push(r);for(let r of this.dirToProvider.keys())u.has(r)||D.push(r);return this.dirToProvider=u,this.existingDirs=t,{added:n,removed:D}}async fullScan(u){let t=[];for(let[D,r]of this.dirToProvider){let o=await Gt(D,r);for(let i of o)t.push({file:i,provider:r})}let n=new Set(t.map(D=>D.file));await Promise.all(t.map(async({file:D,provider:r})=>{try{let o=await be.stat(D),i=u.get(D);if(i&&i.source===r.id&&i.parserVersion===r.parserVersion&&i.mtimeMs===o.mtimeMs&&i.size===o.size){this.files.set(D,{source:r.id,parserVersion:r.parserVersion,mtimeMs:o.mtimeMs,size:o.size,assistantRecords:i.assistantRecords,userRecords:i.userRecords,parentLinks:i.parentLinks});return}let s=await r.parseFile(D);this.files.set(D,{source:r.id,parserVersion:r.parserVersion,mtimeMs:o.mtimeMs,size:o.size,assistantRecords:s.assistant,userRecords:s.user,parentLinks:s.parentLinks})}catch(o){this.recordError(`parse ${D}: ${o.message}`)}}));for(let D of Array.from(this.files.keys()))n.has(D)||this.files.delete(D)}syncWatchersToDirs(){for(let[u,t]of this.watchers)if(!this.dirToProvider.has(u)){try{t.close()}catch{}this.watchers.delete(u)}for(let[u,t]of this.dirToProvider)if(!this.watchers.has(u))try{let n=Eo(u,{recursive:!0},(D,r)=>{if(!r||typeof r!="string"||!r.endsWith(".jsonl"))return;let o=qt.join(u,r);this.scheduleFileReconcile(o,t)});n.on("error",D=>{this.recordError(`watcher ${u}: ${D.message}`)}),this.watchers.set(u,n)}catch(n){this.recordError(`watch ${u}: ${n.message}`)}}setupPolling(){this.pollTimer&&clearInterval(this.pollTimer);let u=this.cacheName==="mcp",t=process.env.CCGAUGE_POLL_FALLBACK;(t==="1"||t!=="0"&&!u)&&(this.pollTimer=setInterval(()=>{this.pollOnce().catch(D=>this.recordError(`poll: ${D.message}`))},Ao),this.pollTimer.unref?.())}async pollOnce(){await this.runExclusive(async()=>{let u=Date.now(),t=await this.detectProviderDirs(),n=t.added.length>0||t.removed.length>0;n&&this.syncWatchersToDirs();let D=[];for(let[o,i]of this.dirToProvider){let s=await Gt(o,i);for(let a of s)D.push({file:a,provider:i})}let r=new Set(D.map(o=>o.file));await Promise.all(D.map(async({file:o,provider:i})=>{try{let s=await be.stat(o),a=this.files.get(o);if(a&&a.mtimeMs===s.mtimeMs&&a.size===s.size)return;let F=await i.parseFile(o);this.files.set(o,{source:i.id,parserVersion:i.parserVersion,mtimeMs:s.mtimeMs,size:s.size,assistantRecords:F.assistant,userRecords:F.user,parentLinks:F.parentLinks}),n=!0}catch(s){this.recordError(`poll-parse ${o}: ${s.message}`)}}));for(let o of Array.from(this.files.keys()))r.has(o)||(this.files.delete(o),n=!0);n&&(this.lastWorkStart=u,this.scheduleSnapshotRebuild(),this.schedulePersist())})}scheduleFileReconcile(u,t){let n=this.fileDebouncers.get(u);n&&clearTimeout(n);let D=setTimeout(()=>{this.fileDebouncers.delete(u),this.reconcileFile(u,t).catch(r=>this.recordError(`reconcile ${u}: ${r.message}`))},Bo);D.unref?.(),this.fileDebouncers.set(u,D)}async reconcileFile(u,t){await this.runExclusive(async()=>{let n=Date.now(),D=null;try{D=await be.stat(u)}catch{}if(!D||!D.isFile()){this.files.has(u)&&(this.files.delete(u),this.lastWorkStart=n,this.scheduleSnapshotRebuild(),this.schedulePersist());return}let r=this.files.get(u);if(!(r&&r.mtimeMs===D.mtimeMs&&r.size===D.size))try{let o=await t.parseFile(u);this.files.set(u,{source:t.id,parserVersion:t.parserVersion,mtimeMs:D.mtimeMs,size:D.size,assistantRecords:o.assistant,userRecords:o.user,parentLinks:o.parentLinks}),this.lastWorkStart=n,this.scheduleSnapshotRebuild(),this.schedulePersist()}catch(o){this.recordError(`parse ${u}: ${o.message}`)}})}scheduleSnapshotRebuild(){this.snapshotRebuildTimer&&clearTimeout(this.snapshotRebuildTimer),this.snapshotRebuildTimer=setTimeout(()=>{this.snapshotRebuildTimer=null,this.rebuildSnapshotNow()},bo),this.snapshotRebuildTimer.unref?.()}rebuildSnapshotNow(){let u=Date.now(),t=this.lastWorkStart??u,n=[],D=[],r={},o=0,i={claude:{source:"claude",filesScanned:0,recordsParsed:0,assistantRecords:0,scannedDirs:[]},codex:{source:"codex",filesScanned:0,recordsParsed:0,assistantRecords:0,scannedDirs:[]}};for(let[c,f]of this.dirToProvider)i[f.id].scannedDirs.push(c);for(let c of this.files.values()){n.push(...c.assistantRecords),D.push(...c.userRecords);for(let[f,d]of c.parentLinks)r[f]=d;o+=c.assistantRecords.length+c.userRecords.length,i[c.source].filesScanned+=1,i[c.source].recordsParsed+=c.assistantRecords.length+c.userRecords.length}let s=Lt(n).sort((c,f)=>c.timestamp.localeCompare(f.timestamp)),a=wo(D).sort((c,f)=>c.timestamp.localeCompare(f.timestamp));Wt({assistantRecords:s,userRecords:a,parentMap:r});for(let c of s)i[c.source].assistantRecords+=1;let F={filesScanned:this.files.size,recordsParsed:o,assistantRecords:s.length,durationMs:Date.now()-t,scannedDirs:this.existingDirs};this.snapshot={records:s,userRecords:a,parentMap:r,stats:F,bySource:Object.values(i)},this.lastWorkStart=null}getSnapshot(){if(!this.snapshot)throw new Error("Indexer not initialized \u2014 call init() first.");return this.snapshot}async forceRescan(){let u=!this.initPromise;if(await this.init(),u)return this.snapshot;if(this.rescanPromise)return this.rescanPromise;this.rescanPromise=this.runRescan();try{return await this.rescanPromise}finally{this.rescanPromise=null}}async runRescan(){this.isIndexing=!0;try{return await this.runExclusive(async()=>{let u=Date.now();return this.lastWorkStart=u,this.snapshotRebuildTimer&&(clearTimeout(this.snapshotRebuildTimer),this.snapshotRebuildTimer=null),this.persistTimer&&(clearTimeout(this.persistTimer),this.persistTimer=null),this.files.clear(),await this.detectProviderDirs(),await this.fullScan(new Map),this.rebuildSnapshotNow(),this.indexDurationMs=Date.now()-u,this.lastIndexedAt=new Date().toISOString(),this.syncWatchersToDirs(),this.schedulePersist(),this.snapshot})}finally{this.isIndexing=!1}}getStatus(){let u=this.snapshot;return{initialized:u!==null,isIndexing:this.isIndexing,lastIndexedAt:this.lastIndexedAt,indexDurationMs:this.indexDurationMs,filesIndexed:this.files.size,recordsIndexed:u?.stats.assistantRecords??0,bySource:u?.bySource??[],watchers:this.watchers.size,errors:this.errors.slice(-Ru),pendingReconciles:this.fileDebouncers.size,loadedFromDisk:this.loadedFromDisk}}schedulePersist(){this.persistTimer&&clearTimeout(this.persistTimer),this.persistTimer=setTimeout(()=>{this.persistTimer=null;let u=[];for(let[t,n]of this.files)u.push({filePath:t,source:n.source,parserVersion:n.parserVersion,mtimeMs:n.mtimeMs,size:n.size,assistantRecords:n.assistantRecords,userRecords:n.userRecords,parentLinks:n.parentLinks});Ut({savedAt:new Date().toISOString(),files:u},this.cacheName).catch(t=>this.recordError(`persist: ${t.message}`))},yo),this.persistTimer.unref?.()}recordError(u){let t=`${new Date().toISOString()} ${jt(u)}`;this.errors.push(t),this.errors.length>Ru*2&&this.errors.splice(0,this.errors.length-Ru),process.env.CCGAUGE_DEBUG&&console.error(`[ccgauge:indexer] ${new Date().toISOString()} ${u}`)}disposeWatchers(){for(let u of this.watchers.values())try{u.close()}catch{}this.watchers.clear()}dispose(){this.disposeWatchers(),this.pollTimer&&clearInterval(this.pollTimer),this.snapshotRebuildTimer&&clearTimeout(this.snapshotRebuildTimer),this.persistTimer&&clearTimeout(this.persistTimer);for(let u of this.fileDebouncers.values())clearTimeout(u);this.fileDebouncers.clear()}};async function Ro(e){try{return(await be.stat(e)).isDirectory()}catch{return!1}}async function Gt(e,u){let t=[];async function n(D,r){if(r>xo)return;let o;try{o=await be.readdir(D,{withFileTypes:!0})}catch{return}for(let i of o){let s=qt.join(D,i.name);if(i.isDirectory()){if(u.shouldSkipDir(i.name))continue;await n(s,r+1)}else i.isFile()&&i.name.endsWith(".jsonl")&&t.push(s)}}return await n(e,0),t}function wo(e){let u=new Set;return e.filter(t=>{let n=t.uuid;return n?u.has(n)?!1:(u.add(n),!0):!0})}function ko(){return globalThis.__ccgaugeIndexers||(globalThis.__ccgaugeIndexers=new Map),globalThis.__ccgaugeIndexers}function Ht(e=Fe){let u=ko(),t=u.get(e);return t||(t=new wu(e),u.set(e,t)),t}async function Vt(e={}){let u=Ht();return e.force?u.forceRescan():(await u.init(),u.getSnapshot())}function oe(e){let u=re(e.source),{pricing:t}=u.resolvePricing(e.model);return u.costFromUsage(e.usage,t)}function zt(e,u){return new Intl.NumberFormat("en-US",{maximumFractionDigits:u?.maxFrac??0}).format(e)}function v(e,u="en"){return Number.isFinite(e)?u==="zh"?e>=1e8?(e/1e8).toFixed(2)+"\u4EBF":e>=1e4?(e/1e4).toFixed(1)+"\u4E07":zt(e):e>=1e9?(e/1e9).toFixed(2)+"B":e>=1e6?(e/1e6).toFixed(2)+"M":e>=1e3?(e/1e3).toFixed(1)+"K":zt(e):"0"}function N(e,u){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:u?.minFrac??2,maximumFractionDigits:u?.maxFrac??2}).format(e)}function de(e,u=1){return Number.isFinite(e)?`${(e*100).toFixed(u)}%`:"0%"}function Kt(e){if(e<1e3)return`${e}ms`;let u=Math.floor(e/1e3);if(u<60)return`${u}s`;let t=Math.floor(u/60);if(t<60){let r=u%60;return r?`${t}m ${r}s`:`${t}m`}let n=Math.floor(t/60),D=t%60;return D?`${n}h ${D}m`:`${n}h`}function Ae(e){if(!e)return"(unknown)";let t=e.replace(/[/\\]+$/,"").split(/[/\\]+/);return t[t.length-1]||e}import{readFileSync as So,statSync as To}from"node:fs";import{basename as Yt}from"node:path";var Jt=new Map,_o=/^(.+?)[/\\]\.git[/\\]worktrees[/\\]([^/\\]+)[/\\]?$/,vo=/^(.+?)[/\\](?:\.git|\.claude)[/\\]worktrees[/\\]([^/\\]+)(?:[/\\].*)?$/;function Io(e){let u=Ae(e);if(!e)return{label:u,isWorktree:!1,mainName:u,worktreeName:"",canonicalCwd:e};let t=vo.exec(e);if(t){let n=t[1],D=t[2],r=Yt(n)||n;return{label:`${r} (${D})`,isWorktree:!0,mainName:r,worktreeName:D,canonicalCwd:n}}try{let n=`${e}/.git`;if(!To(n).isFile())return{label:u,isWorktree:!1,mainName:u,worktreeName:"",canonicalCwd:e};let o=So(n,"utf8").trim().split(/\r?\n/,1)[0]??"",i=/^gitdir:\s*(.+)$/.exec(o);if(!i)return{label:u,isWorktree:!1,mainName:u,worktreeName:"",canonicalCwd:e};let s=i[1].trim(),a=_o.exec(s);if(!a)return{label:u,isWorktree:!1,mainName:u,worktreeName:"",canonicalCwd:e};let F=a[1],c=a[2],f=Yt(F)||F;return{label:`${f} (${c})`,isWorktree:!0,mainName:f,worktreeName:c,canonicalCwd:F}}catch{return{label:u,isWorktree:!1,mainName:u,worktreeName:"",canonicalCwd:e}}}function Xt(e){let u=Jt.get(e);if(u)return u.label;let t=Io(e);return Jt.set(e,t),t.label}var Mo=["hour","day","week","month"];function Zt(e){return typeof e=="string"&&Mo.includes(e)}function ku(e,u){let t=new Date(e),n=t.getFullYear(),D=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),o=String(t.getHours()).padStart(2,"0");if(u==="hour")return{key:`${n}-${D}-${r}T${o}`,label:`${D}/${r} ${o}:00`};if(u==="day")return{key:`${n}-${D}-${r}`,label:`${D}/${r}`};if(u==="week"){let i=new Date(t),s=i.getDay()||7;i.setDate(i.getDate()-s+1);let a=String(i.getMonth()+1).padStart(2,"0"),F=String(i.getDate()).padStart(2,"0");return{key:`${i.getFullYear()}-W${a}${F}`,label:`Wk ${a}/${F}`}}return{key:`${n}-${D}`,label:`${n}-${D}`}}function ye(e){return{source:e.source,fromIso:e.from?.toISOString(),toIso:e.to?.toISOString(),models:e.models&&e.models.length?new Set(e.models):void 0,projects:e.projects&&e.projects.length?new Set(e.projects):void 0}}function xe(e,u){return!(e.source!==u.source||u.fromIso&&e.timestamp<u.fromIso||u.toIso&&e.timestamp>u.toIso||u.models&&!u.models.has(e.model)||u.projects&&!u.projects.has(e.cwd))}function Qt(e,u,t){let n=new Map,D=ye(t);for(let r of e){if(!xe(r,D))continue;let{key:o,label:i}=ku(r.timestamp,u),s=n.get(o);s||(s=Po(o,i),n.set(o,s)),Oo(s,r)}return Array.from(n.values()).sort((r,o)=>r.key.localeCompare(o.key))}function Po(e,u){return{key:e,label:u,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,totalTokens:0,cost:0,saved:0,requests:0,models:{}}}function Oo(e,u){let t=oe(u);e.inputTokens+=u.usage.input_tokens,e.outputTokens+=u.usage.output_tokens,e.cacheReadTokens+=u.usage.cache_read_input_tokens,e.cacheCreationTokens+=u.usage.cache_creation_input_tokens,e.totalTokens=e.inputTokens+e.outputTokens+e.cacheReadTokens+e.cacheCreationTokens,e.cost+=t.total,e.saved+=t.saved,e.requests+=1;let n=e.models[u.model]??{tokens:0,cost:0,requests:0};n.tokens+=u.usage.input_tokens+u.usage.output_tokens+u.usage.cache_read_input_tokens+u.usage.cache_creation_input_tokens,n.cost+=t.total,n.requests+=1,e.models[u.model]=n}function en(e,u){let t=new Map,n=ye(u);for(let D of e){if(!xe(D,n))continue;let r=t.get(D.model);if(!r){let{pricing:i,matchType:s}=re(D.source).resolvePricing(D.model);r={model:D.model,source:D.source,requests:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,totalTokens:0,cost:0,saved:0,pricing:i,pricingResolved:s==="exact"||s==="date-stripped"||s==="prefix-stripped"},t.set(D.model,r)}let o=oe(D);r.requests+=1,r.inputTokens+=D.usage.input_tokens,r.outputTokens+=D.usage.output_tokens,r.cacheReadTokens+=D.usage.cache_read_input_tokens,r.cacheCreationTokens+=D.usage.cache_creation_input_tokens,r.totalTokens=r.inputTokens+r.outputTokens+r.cacheReadTokens+r.cacheCreationTokens,r.cost+=o.total,r.saved+=o.saved}return Array.from(t.values()).sort((D,r)=>r.cost-D.cost)}function un(e,u){let t=new Map,n=new Map,D=ye(u);for(let r of e){if(!xe(r,D))continue;let o=r.cwd||"(unknown)",i=t.get(o);i||(i={source:u.source,cwd:o,projectName:Ae(o),sessions:0,requests:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,totalTokens:0,cost:0,saved:0,firstActivity:r.timestamp,lastActivity:r.timestamp,models:[]},t.set(o,i),n.set(o,new Set)),n.get(o).add(r.sessionId);let s=oe(r);i.requests+=1,i.inputTokens+=r.usage.input_tokens,i.outputTokens+=r.usage.output_tokens,i.cacheReadTokens+=r.usage.cache_read_input_tokens,i.cacheCreationTokens+=r.usage.cache_creation_input_tokens,i.totalTokens=i.inputTokens+i.outputTokens+i.cacheReadTokens+i.cacheCreationTokens,i.cost+=s.total,i.saved+=s.saved,r.timestamp<i.firstActivity&&(i.firstActivity=r.timestamp),r.timestamp>i.lastActivity&&(i.lastActivity=r.timestamp),i.models.includes(r.model)||i.models.push(r.model)}for(let[r,o]of n){let i=t.get(r);i.sessions=o.size}return Array.from(t.values()).sort((r,o)=>o.cost-r.cost)}function tn(e,u,t){let n=new Map,D=ye(t);for(let o of e){if(!xe(o,D))continue;let i=o.sessionId||o.uuid,s=n.get(i);s||(s={sessionId:i,source:o.source,cwd:o.cwd,projectName:Ae(o.cwd),projectLabel:Xt(o.cwd),startTime:o.timestamp,endTime:o.timestamp,durationMs:0,requests:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,totalTokens:0,cost:0,saved:0,models:[],modelBreakdown:{}},n.set(i,s));let a=oe(o);s.requests+=1,s.inputTokens+=o.usage.input_tokens,s.outputTokens+=o.usage.output_tokens,s.cacheReadTokens+=o.usage.cache_read_input_tokens,s.cacheCreationTokens+=o.usage.cache_creation_input_tokens,s.totalTokens=s.inputTokens+s.outputTokens+s.cacheReadTokens+s.cacheCreationTokens,s.cost+=a.total,s.saved+=a.saved,o.timestamp<s.startTime&&(s.startTime=o.timestamp),o.timestamp>s.endTime&&(s.endTime=o.timestamp),s.models.includes(o.model)||s.models.push(o.model);let F=s.modelBreakdown[o.model]??{tokens:0,cost:0,requests:0};F.tokens+=o.usage.input_tokens+o.usage.output_tokens+o.usage.cache_read_input_tokens+o.usage.cache_creation_input_tokens,F.cost+=a.total,F.requests+=1,s.modelBreakdown[o.model]=F}let r=new Map;for(let o of u){let i=r.get(o.sessionId);(!i||o.timestamp<i.timestamp)&&r.set(o.sessionId,o)}for(let o of n.values()){o.durationMs=Math.max(0,new Date(o.endTime).getTime()-new Date(o.startTime).getTime());let i=r.get(o.sessionId);i&&i.textPreview&&(o.firstUserMessage=i.textPreview,o.title=i.textPreview.slice(0,80))}return Array.from(n.values()).sort((o,i)=>i.endTime.localeCompare(o.endTime))}function nn(e,u){let t=0,n=0,D=0,r=0,o=0,i=0,s=0,a=ye(u);for(let F of e){if(!xe(F,a))continue;let c=oe(F);t+=F.usage.input_tokens,n+=F.usage.output_tokens,D+=F.usage.cache_read_input_tokens,r+=F.usage.cache_creation_input_tokens,o+=c.total,i+=c.saved,s+=1}return{inputTokens:t,outputTokens:n,cacheReadTokens:D,cacheCreationTokens:r,totalTokens:t+n+D+r,cost:o,saved:i,requests:s}}var Lo=["1d","7d","30d","90d","all","custom"];function Dn(e){return typeof e=="string"&&Lo.includes(e)}function rn(e){let u=new Date;if(e==="all"||e==="custom")return{};if(e==="1d")return{from:new Date(u.getFullYear(),u.getMonth(),u.getDate())};let t=e.match(/^(\d+)([dwm])$/);if(!t)return{};let n=parseInt(t[1],10),D=t[2],r=new Date(u);return D==="d"?r.setDate(r.getDate()-n):D==="w"?r.setDate(r.getDate()-n*7):D==="m"&&r.setMonth(r.getMonth()-n),{from:r}}function No(e,u,t){let n=new Map;for(let i of u)i.isSynthetic||i.textPreview&&i.textPreview.trim()&&n.set(i.uuid,i.textPreview);let D=new Map,r=new Map;function o(i){let s=[],a=i,F=null,c=0,f=new Set;for(;a&&c++<5e3&&!f.has(a);){f.add(a);let d=r.get(a);if(d){F=d;break}if(s.push(a),n.has(a)){F=a;break}a=t[a]??null}F||(F=i);for(let d of s)r.set(d,F);return F}for(let i of e)D.set(i.uuid,o(i.uuid));return D}function Re(e,u,t){let n=No(e,u,t),D=new Map;for(let r of e){let o=n.get(r.uuid)??r.uuid,i=D.get(o);(!i||r.timestamp<i.firstTimestamp)&&D.set(o,{turnId:o,firstTimestamp:r.timestamp,firstModel:r.model,cwd:r.cwd,sessionId:r.sessionId,source:r.source})}return D}import nu from"node:process";function Su({onlyFirst:e=!1}={}){let D="(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";return new RegExp(D,e?void 0:"g")}var $o=Su();function Y(e){if(typeof e!="string")throw new TypeError(`Expected a \`string\`, got \`${typeof e}\``);return!e.includes("\x1B")&&!e.includes("\x9B")?e:e.replace($o,"")}var on=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],sn=12288,an=65510,cn=[12288,12288,65281,65376,65504,65510];var ln=4352,Fn=262141,Tu=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141];var Ye=(e,u)=>{let t=0,n=Math.floor(e.length/2)-1;for(;t<=n;){let D=Math.floor((t+n)/2),r=D*2;if(u<e[r])n=D-1;else if(u>e[r+1])t=D+1;else return!0}return!1};var dn=19968,[jo,Go]=qo(Tu);function qo(e){let u=e[0],t=e[1];for(let n=0;n<e.length;n+=2){let D=e[n],r=e[n+1];if(dn>=D&&dn<=r)return[D,r];r-D>t-u&&(u=D,t=r)}return[u,t]}var fn=e=>e<161||e>1114109?!1:Ye(on,e),we=e=>e<sn||e>an?!1:Ye(cn,e);var ke=e=>e>=jo&&e<=Go?!0:e<ln||e>Fn?!1:Ye(Tu,e);function Ho(e){if(!Number.isSafeInteger(e))throw new TypeError(`Expected a code point, got \`${typeof e}\`.`)}function J(e,{ambiguousAsWide:u=!1}={}){return Ho(e),we(e)||ke(e)||u&&fn(e)?2:1}var Cn=le(hn(),1),Vo=new Intl.Segmenter,zo=new RegExp("^\\p{Default_Ignorable_Code_Point}$","u");function P(e,u={}){if(typeof e!="string"||e.length===0)return 0;let{ambiguousIsNarrow:t=!0,countAnsiEscapeCodes:n=!1}=u;if(n||(e=Y(e)),e.length===0)return 0;let D=0,r={ambiguousAsWide:!t};for(let{segment:o}of Vo.segment(e)){let i=o.codePointAt(0);if(!(i<=31||i>=127&&i<=159)&&!(i>=8203&&i<=8207||i===65279)&&!(i>=768&&i<=879||i>=6832&&i<=6911||i>=7616&&i<=7679||i>=8400&&i<=8447||i>=65056&&i<=65071)&&!(i>=55296&&i<=57343)&&!(i>=65024&&i<=65039)&&!zo.test(o)){if((0,Cn.default)().test(o)){D+=2;continue}D+=J(i,r)}}return D}var gn=(e=0)=>u=>`\x1B[${u+e}m`,mn=(e=0)=>u=>`\x1B[${38+e};5;${u}m`,En=(e=0)=>(u,t,n)=>`\x1B[${38+e};2;${u};${t};${n}m`,y={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},rF=Object.keys(y.modifier),Ko=Object.keys(y.color),Yo=Object.keys(y.bgColor),oF=[...Ko,...Yo];function Jo(){let e=new Map;for(let[u,t]of Object.entries(y)){for(let[n,D]of Object.entries(t))y[n]={open:`\x1B[${D[0]}m`,close:`\x1B[${D[1]}m`},t[n]=y[n],e.set(D[0],D[1]);Object.defineProperty(y,u,{value:t,enumerable:!1})}return Object.defineProperty(y,"codes",{value:e,enumerable:!1}),y.color.close="\x1B[39m",y.bgColor.close="\x1B[49m",y.color.ansi=gn(),y.color.ansi256=mn(),y.color.ansi16m=En(),y.bgColor.ansi=gn(10),y.bgColor.ansi256=mn(10),y.bgColor.ansi16m=En(10),Object.defineProperties(y,{rgbToAnsi256:{value(u,t,n){return u===t&&t===n?u<8?16:u>248?231:Math.round((u-8)/247*24)+232:16+36*Math.round(u/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(u){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(r=>r+r).join(""));let D=Number.parseInt(n,16);return[D>>16&255,D>>8&255,D&255]},enumerable:!1},hexToAnsi256:{value:u=>y.rgbToAnsi256(...y.hexToRgb(u)),enumerable:!1},ansi256ToAnsi:{value(u){if(u<8)return 30+u;if(u<16)return 90+(u-8);let t,n,D;if(u>=232)t=((u-232)*10+8)/255,n=t,D=t;else{u-=16;let i=u%36;t=Math.floor(u/36)/5,n=Math.floor(i/6)/5,D=i%6/5}let r=Math.max(t,n,D)*2;if(r===0)return 30;let o=30+(Math.round(D)<<2|Math.round(n)<<1|Math.round(t));return r===2&&(o+=60),o},enumerable:!1},rgbToAnsi:{value:(u,t,n)=>y.ansi256ToAnsi(y.rgbToAnsi256(u,t,n)),enumerable:!1},hexToAnsi:{value:u=>y.ansi256ToAnsi(y.hexToAnsi256(u)),enumerable:!1}}),y}var Xo=Jo(),U=Xo;import _u from"node:process";import Zo from"node:os";import Bn from"node:tty";function $(e,u=globalThis.Deno?globalThis.Deno.args:_u.argv){let t=e.startsWith("-")?"":e.length===1?"-":"--",n=u.indexOf(t+e),D=u.indexOf("--");return n!==-1&&(D===-1||n<D)}var{env:x}=_u,Je;$("no-color")||$("no-colors")||$("color=false")||$("color=never")?Je=0:($("color")||$("colors")||$("color=true")||$("color=always"))&&(Je=1);function Qo(){if("FORCE_COLOR"in x)return x.FORCE_COLOR==="true"?1:x.FORCE_COLOR==="false"?0:x.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(x.FORCE_COLOR,10),3)}function ei(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function ui(e,{streamIsTTY:u,sniffFlags:t=!0}={}){let n=Qo();n!==void 0&&(Je=n);let D=t?Je:n;if(D===0)return 0;if(t){if($("color=16m")||$("color=full")||$("color=truecolor"))return 3;if($("color=256"))return 2}if("TF_BUILD"in x&&"AGENT_NAME"in x)return 1;if(e&&!u&&D===void 0)return 0;let r=D||0;if(x.TERM==="dumb")return r;if(_u.platform==="win32"){let o=Zo.release().split(".");return Number(o[0])>=10&&Number(o[2])>=10586?Number(o[2])>=14931?3:2:1}if("CI"in x)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(o=>o in x)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(o=>o in x)||x.CI_NAME==="codeship"?1:r;if("TEAMCITY_VERSION"in x)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(x.TEAMCITY_VERSION)?1:0;if(x.COLORTERM==="truecolor"||x.TERM==="xterm-kitty"||x.TERM==="xterm-ghostty"||x.TERM==="wezterm")return 3;if("TERM_PROGRAM"in x){let o=Number.parseInt((x.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(x.TERM_PROGRAM){case"iTerm.app":return o>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(x.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(x.TERM)||"COLORTERM"in x?1:r}function bn(e,u={}){let t=ui(e,{streamIsTTY:e&&e.isTTY,...u});return ei(t)}var ti={stdout:bn({isTTY:Bn.isatty(1)}),stderr:bn({isTTY:Bn.isatty(2)})},An=ti;function yn(e,u,t){let n=e.indexOf(u);if(n===-1)return e;let D=u.length,r=0,o="";do o+=e.slice(r,n)+u+t,r=n+D,n=e.indexOf(u,r);while(n!==-1);return o+=e.slice(r),o}function xn(e,u,t,n){let D=0,r="";do{let o=e[n-1]==="\r";r+=e.slice(D,o?n-1:n)+u+(o?`\r
9
+ `:`
10
+ `)+t,D=n+1,n=e.indexOf(`
11
+ `,D)}while(n!==-1);return r+=e.slice(D),r}var{stdout:Rn,stderr:wn}=An,vu=Symbol("GENERATOR"),fe=Symbol("STYLER"),Se=Symbol("IS_EMPTY"),kn=["ansi","ansi","ansi256","ansi16m"],pe=Object.create(null),ni=(e,u={})=>{if(u.level&&!(Number.isInteger(u.level)&&u.level>=0&&u.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=Rn?Rn.level:0;e.level=u.level===void 0?t:u.level},Xe=class{constructor(u){return Sn(u)}},Sn=e=>{let u=(...t)=>t.join(" ");return ni(u,e),Object.setPrototypeOf(u,Te.prototype),u};function Te(e){return Sn(e)}Object.setPrototypeOf(Te.prototype,Function.prototype);for(let[e,u]of Object.entries(U))pe[e]={get(){let t=Ze(this,Mu(u.open,u.close,this[fe]),this[Se]);return Object.defineProperty(this,e,{value:t}),t}};pe.visible={get(){let e=Ze(this,this[fe],!0);return Object.defineProperty(this,"visible",{value:e}),e}};var Iu=(e,u,t,...n)=>e==="rgb"?u==="ansi16m"?U[t].ansi16m(...n):u==="ansi256"?U[t].ansi256(U.rgbToAnsi256(...n)):U[t].ansi(U.rgbToAnsi(...n)):e==="hex"?Iu("rgb",u,t,...U.hexToRgb(...n)):U[t][e](...n),Di=["rgb","hex","ansi256"];for(let e of Di){pe[e]={get(){let{level:t}=this;return function(...n){let D=Mu(Iu(e,kn[t],"color",...n),U.color.close,this[fe]);return Ze(this,D,this[Se])}}};let u="bg"+e[0].toUpperCase()+e.slice(1);pe[u]={get(){let{level:t}=this;return function(...n){let D=Mu(Iu(e,kn[t],"bgColor",...n),U.bgColor.close,this[fe]);return Ze(this,D,this[Se])}}}}var ri=Object.defineProperties(()=>{},{...pe,level:{enumerable:!0,get(){return this[vu].level},set(e){this[vu].level=e}}}),Mu=(e,u,t)=>{let n,D;return t===void 0?(n=e,D=u):(n=t.openAll+e,D=u+t.closeAll),{open:e,close:u,openAll:n,closeAll:D,parent:t}},Ze=(e,u,t)=>{let n=(...D)=>oi(n,D.length===1?""+D[0]:D.join(" "));return Object.setPrototypeOf(n,ri),n[vu]=e,n[fe]=u,n[Se]=t,n},oi=(e,u)=>{if(e.level<=0||!u)return e[Se]?"":u;let t=e[fe];if(t===void 0)return u;let{openAll:n,closeAll:D}=t;if(u.includes("\x1B"))for(;t!==void 0;)u=yn(u,t.close,t.open),t=t.parent;let r=u.indexOf(`
12
+ `);return r!==-1&&(u=xn(u,D,n,r)),n+u+D};Object.defineProperties(Te.prototype,pe);var ii=Te(),hF=Te({level:wn?wn.level:0});var X=ii;var vn=le(_n(),1),si=new Intl.Segmenter,ai=new RegExp("^\\p{Default_Ignorable_Code_Point}$","u");function Pu(e,u={}){if(typeof e!="string"||e.length===0)return 0;let{ambiguousIsNarrow:t=!0,countAnsiEscapeCodes:n=!1}=u;if(n||(e=Y(e)),e.length===0)return 0;let D=0,r={ambiguousAsWide:!t};for(let{segment:o}of si.segment(e)){let i=o.codePointAt(0);if(!(i<=31||i>=127&&i<=159)&&!(i>=8203&&i<=8207||i===65279)&&!(i>=768&&i<=879||i>=6832&&i<=6911||i>=7616&&i<=7679||i>=8400&&i<=8447||i>=65056&&i<=65071)&&!(i>=55296&&i<=57343)&&!(i>=65024&&i<=65039)&&!ai.test(o)){if((0,vn.default)().test(o)){D+=2;continue}D+=J(i,r)}}return D}function Qe(e){let u=0;for(let t of e.split(`
13
+ `))u=Math.max(u,Pu(t));return u}var rD=le(Lu(),1);var li=/[\p{Lu}]/u,Fi=/[\p{Ll}]/u,Pn=/^[\p{Lu}](?![\p{Lu}])/gu,Nn=/([\p{Alpha}\p{N}_]|$)/u,Nu=/[_.\- ]+/,di=new RegExp("^"+Nu.source),On=new RegExp(Nu.source+Nn.source,"gu"),Ln=new RegExp("\\d+"+Nn.source,"gu"),fi=(e,u,t,n)=>{let D=!1,r=!1,o=!1,i=!1;for(let s=0;s<e.length;s++){let a=e[s];i=s>2?e[s-3]==="-":!0,D&&li.test(a)?(e=e.slice(0,s)+"-"+e.slice(s),D=!1,o=r,r=!0,s++):r&&o&&Fi.test(a)&&(!i||n)?(e=e.slice(0,s-1)+"-"+e.slice(s-1),o=r,r=!1,D=!0):(D=u(a)===a&&t(a)!==a,o=r,r=t(a)===a&&u(a)!==a)}return e},pi=(e,u)=>(Pn.lastIndex=0,e.replaceAll(Pn,t=>u(t))),hi=(e,u)=>(On.lastIndex=0,Ln.lastIndex=0,e.replaceAll(Ln,(t,n,D)=>["_","-"].includes(e.charAt(D+t.length))?t:u(t)).replaceAll(On,(t,n)=>u(n)));function $u(e,u){if(!(typeof e=="string"||Array.isArray(e)))throw new TypeError("Expected the input to be `string | string[]`");if(u={pascalCase:!1,preserveConsecutiveUppercase:!1,...u},Array.isArray(e)?e=e.map(r=>r.trim()).filter(r=>r.length).join("-"):e=e.trim(),e.length===0)return"";let t=u.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(u.locale),n=u.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(u.locale);return e.length===1?Nu.test(e)?"":u.pascalCase?n(e):t(e):(e!==t(e)&&(e=fi(e,t,n,u.preserveConsecutiveUppercase)),e=e.replace(di,""),e=u.preserveConsecutiveUppercase?pi(e,t):t(e),u.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),hi(e,n))}var zu=le(zn(),1);var Kn=(e=0)=>u=>`\x1B[${u+e}m`,Yn=(e=0)=>u=>`\x1B[${38+e};5;${u}m`,Jn=(e=0)=>(u,t,n)=>`\x1B[${38+e};2;${u};${t};${n}m`,R={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},IF=Object.keys(R.modifier),yi=Object.keys(R.color),xi=Object.keys(R.bgColor),MF=[...yi,...xi];function Ri(){let e=new Map;for(let[u,t]of Object.entries(R)){for(let[n,D]of Object.entries(t))R[n]={open:`\x1B[${D[0]}m`,close:`\x1B[${D[1]}m`},t[n]=R[n],e.set(D[0],D[1]);Object.defineProperty(R,u,{value:t,enumerable:!1})}return Object.defineProperty(R,"codes",{value:e,enumerable:!1}),R.color.close="\x1B[39m",R.bgColor.close="\x1B[49m",R.color.ansi=Kn(),R.color.ansi256=Yn(),R.color.ansi16m=Jn(),R.bgColor.ansi=Kn(10),R.bgColor.ansi256=Yn(10),R.bgColor.ansi16m=Jn(10),Object.defineProperties(R,{rgbToAnsi256:{value(u,t,n){return u===t&&t===n?u<8?16:u>248?231:Math.round((u-8)/247*24)+232:16+36*Math.round(u/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(u){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(r=>r+r).join(""));let D=Number.parseInt(n,16);return[D>>16&255,D>>8&255,D&255]},enumerable:!1},hexToAnsi256:{value:u=>R.rgbToAnsi256(...R.hexToRgb(u)),enumerable:!1},ansi256ToAnsi:{value(u){if(u<8)return 30+u;if(u<16)return 90+(u-8);let t,n,D;if(u>=232)t=((u-232)*10+8)/255,n=t,D=t;else{u-=16;let i=u%36;t=Math.floor(u/36)/5,n=Math.floor(i/6)/5,D=i%6/5}let r=Math.max(t,n,D)*2;if(r===0)return 30;let o=30+(Math.round(D)<<2|Math.round(n)<<1|Math.round(t));return r===2&&(o+=60),o},enumerable:!1},rgbToAnsi:{value:(u,t,n)=>R.ansi256ToAnsi(R.rgbToAnsi256(u,t,n)),enumerable:!1},hexToAnsi:{value:u=>R.ansi256ToAnsi(R.hexToAnsi256(u)),enumerable:!1}}),R}var wi=Ri(),Xn=wi;var uu=new Set(["\x1B","\x9B"]),ki=39,Vu="\x07",eD="[",Si="]",uD="m",eu=`${Si}8;;`,Zn=e=>`${uu.values().next().value}${eD}${e}${uD}`,Qn=e=>`${uu.values().next().value}${eu}${e}${Vu}`,Ti=e=>e.split(" ").map(u=>P(u)),Hu=(e,u,t)=>{let n=[...u],D=!1,r=!1,o=P(Y(e.at(-1)));for(let[i,s]of n.entries()){let a=P(s);if(o+a<=t?e[e.length-1]+=s:(e.push(s),o=0),uu.has(s)&&(D=!0,r=n.slice(i+1,i+1+eu.length).join("")===eu),D){r?s===Vu&&(D=!1,r=!1):s===uD&&(D=!1);continue}o+=a,o===t&&i<n.length-1&&(e.push(""),o=0)}!o&&e.at(-1).length>0&&e.length>1&&(e[e.length-2]+=e.pop())},_i=e=>{let u=e.split(" "),t=u.length;for(;t>0&&!(P(u[t-1])>0);)t--;return t===u.length?e:u.slice(0,t).join(" ")+u.slice(t).join("")},vi=(e,u,t={})=>{if(t.trim!==!1&&e.trim()==="")return"";let n="",D,r,o=Ti(e),i=[""];for(let[c,f]of e.split(" ").entries()){t.trim!==!1&&(i[i.length-1]=i.at(-1).trimStart());let d=P(i.at(-1));if(c!==0&&(d>=u&&(t.wordWrap===!1||t.trim===!1)&&(i.push(""),d=0),(d>0||t.trim===!1)&&(i[i.length-1]+=" ",d++)),t.hard&&o[c]>u){let l=u-d,C=1+Math.floor((o[c]-l-1)/u);Math.floor((o[c]-1)/u)<C&&i.push(""),Hu(i,f,u);continue}if(d+o[c]>u&&d>0&&o[c]>0){if(t.wordWrap===!1&&d<u){Hu(i,f,u);continue}i.push("")}if(d+o[c]>u&&t.wordWrap===!1){Hu(i,f,u);continue}i[i.length-1]+=f}t.trim!==!1&&(i=i.map(c=>_i(c)));let s=i.join(`
14
+ `),a=[...s],F=0;for(let[c,f]of a.entries()){if(n+=f,uu.has(f)){let{groups:l}=new RegExp(`(?:\\${eD}(?<code>\\d+)m|\\${eu}(?<uri>.*)${Vu})`).exec(s.slice(F))||{groups:{}};if(l.code!==void 0){let C=Number.parseFloat(l.code);D=C===ki?void 0:C}else l.uri!==void 0&&(r=l.uri.length===0?void 0:l.uri)}let d=Xn.codes.get(Number(D));a[c+1]===`
15
+ `?(r&&(n+=Qn("")),D&&d&&(n+=Zn(d))):f===`
16
+ `&&(D&&d&&(n+=Zn(D)),r&&(n+=Qn(r))),F+=f.length}return n};function tu(e,u,t){return String(e).normalize().replaceAll(`\r
17
+ `,`
18
+ `).split(`
19
+ `).map(n=>vi(n,u,t)).join(`
20
+ `)}var Wi=le(Lu(),1),ie=`
21
+ `,O=" ",_e="none",oD=()=>{let{env:e,stdout:u,stderr:t}=nu;return u?.columns?u.columns:t?.columns?t.columns:e.COLUMNS?Number.parseInt(e.COLUMNS,10):80},tD=e=>typeof e=="number"?{top:e,right:e*3,bottom:e,left:e*3}:{top:0,right:0,bottom:0,left:0,...e},ve=e=>e===_e?0:2,Ii=e=>{let u=["topLeft","topRight","bottomRight","bottomLeft","left","right","top","bottom"],t;if(e===_e){e={};for(let n of u)e[n]=""}if(typeof e=="string"){if(t=rD.default[e],!t)throw new TypeError(`Invalid border style: ${e}`)}else{typeof e?.vertical=="string"&&(e.left=e.vertical,e.right=e.vertical),typeof e?.horizontal=="string"&&(e.top=e.horizontal,e.bottom=e.horizontal);for(let n of u)if(e[n]===null||typeof e[n]!="string")throw new TypeError(`Invalid border style: ${n}`);t=e}return t},Mi=(e,u,t)=>{let n="",D=P(e);switch(t){case"left":{n=e+u.slice(D);break}case"right":{n=u.slice(D)+e;break}default:{u=u.slice(D),u.length%2===1?(u=u.slice(Math.floor(u.length/2)),n=u.slice(1)+e+u):(u=u.slice(u.length/2),n=u+e+u);break}}return n},Pi=(e,{padding:u,width:t,textAlignment:n,height:D})=>{e=(0,zu.default)(e,{align:n});let r=e.split(ie),o=Qe(e),i=t-u.left-u.right;if(o>i){let F=[];for(let c of r){let f=tu(c,i,{hard:!0}),l=(0,zu.default)(f,{align:n}).split(`
22
+ `),C=Math.max(...l.map(h=>P(h)));for(let h of l){let p;switch(n){case"center":{p=O.repeat((i-C)/2)+h;break}case"right":{p=O.repeat(i-C)+h;break}default:{p=h;break}}F.push(p)}}r=F}n==="center"&&o<i?r=r.map(F=>O.repeat((i-o)/2)+F):n==="right"&&o<i&&(r=r.map(F=>O.repeat(i-o)+F));let s=O.repeat(u.left),a=O.repeat(u.right);return r=r.map(F=>{let c=s+F+a;return c+O.repeat(t-P(c))}),u.top>0&&(r=[...Array.from({length:u.top}).fill(O.repeat(t)),...r]),u.bottom>0&&(r=[...r,...Array.from({length:u.bottom}).fill(O.repeat(t))]),D&&r.length>D?r=r.slice(0,D):D&&r.length<D&&(r=[...r,...Array.from({length:D-r.length}).fill(O.repeat(t))]),r.join(ie)},Oi=(e,u,t)=>{let n=F=>{let c=t.borderColor?$i(t.borderColor)(F):F;return t.dimBorder?X.dim(c):c},D=F=>t.backgroundColor?Ui(t.backgroundColor)(F):F,r=Ii(t.borderStyle),o=oD(),i=O.repeat(t.margin.left);if(t.float==="center"){let F=Math.max((o-u-ve(t.borderStyle))/2,0);i=O.repeat(F)}else if(t.float==="right"){let F=Math.max(o-u-t.margin.right-ve(t.borderStyle),0);i=O.repeat(F)}let s="";t.margin.top&&(s+=ie.repeat(t.margin.top)),(t.borderStyle!==_e||t.title)&&(s+=n(i+r.topLeft+(t.title?Mi(t.title,r.top.repeat(u),t.titleAlignment):r.top.repeat(u))+r.topRight)+ie);let a=e.split(ie);return s+=a.map(F=>i+n(r.left)+D(F)+n(r.right)).join(ie),t.borderStyle!==_e&&(s+=ie+n(i+r.bottomLeft+r.bottom.repeat(u)+r.bottomRight)),t.margin.bottom&&(s+=ie.repeat(t.margin.bottom)),s},Li=e=>{if(e.fullscreen&&nu?.stdout){let u=[nu.stdout.columns,nu.stdout.rows];typeof e.fullscreen=="function"&&(u=e.fullscreen(...u)),e.width||=u[0],e.height||=u[1]}return e.width&&=Math.max(1,e.width-ve(e.borderStyle)),e.height&&=Math.max(1,e.height-ve(e.borderStyle)),e},nD=(e,u)=>u===_e?e:` ${e} `,Ni=(e,u)=>{u=Li(u);let t=u.width!==void 0,n=oD(),D=ve(u.borderStyle),r=n-u.margin.left-u.margin.right-D,o=Qe(tu(e,n-D,{hard:!0,trim:!1}))+u.padding.left+u.padding.right;if(u.title&&t?(u.title=u.title.slice(0,Math.max(0,u.width-2)),u.title&&=nD(u.title,u.borderStyle)):u.title&&(u.title=u.title.slice(0,Math.max(0,r-2)),u.title&&(u.title=nD(u.title,u.borderStyle),P(u.title)>o&&(u.width=P(u.title)))),u.width||=o,!t){if(u.margin.left&&u.margin.right&&u.width>r){let s=(n-u.width-D)/(u.margin.left+u.margin.right);u.margin.left=Math.max(0,Math.floor(u.margin.left*s)),u.margin.right=Math.max(0,Math.floor(u.margin.right*s))}u.width=Math.min(u.width,n-D-u.margin.left-u.margin.right)}return u.width-(u.padding.left+u.padding.right)<=0&&(u.padding.left=0,u.padding.right=0),u.height&&u.height-(u.padding.top+u.padding.bottom)<=0&&(u.padding.top=0,u.padding.bottom=0),u},Ku=e=>e.match(/^#(?:[0-f]{3}){1,2}$/i),DD=e=>typeof e=="string"&&(X[e]??Ku(e)),$i=e=>Ku(e)?X.hex(e):X[e],Ui=e=>Ku(e)?X.bgHex(e):X[$u(["bg",e])];function Yu(e,u){if(u={padding:0,borderStyle:"single",dimBorder:!1,textAlignment:"left",float:"left",titleAlignment:"left",...u},u.align&&(u.textAlignment=u.align),u.borderColor&&!DD(u.borderColor))throw new Error(`${u.borderColor} is not a valid borderColor`);if(u.backgroundColor&&!DD(u.backgroundColor))throw new Error(`${u.backgroundColor} is not a valid backgroundColor`);return u.padding=tD(u.padding),u.margin=tD(u.margin),u=Ni(e,u),e=Pi(e,u),Oi(e,u.width,u)}var Pr=le(ur(),1);import tr from"node:process";function rt(){let{env:e}=tr,{TERM:u,TERM_PROGRAM:t}=e;return tr.platform!=="win32"?u!=="linux":!!e.WT_SESSION||!!e.TERMINUS_SUBLIME||e.ConEmuTask==="{cmd::Cmder}"||t==="Terminus-Sublime"||t==="vscode"||u==="xterm-256color"||u==="alacritty"||u==="rxvt-unicode"||u==="rxvt-unicode-256color"||e.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var nr={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"\u2588",squareDarkShade:"\u2593",squareMediumShade:"\u2592",squareLightShade:"\u2591",squareTop:"\u2580",squareBottom:"\u2584",squareLeft:"\u258C",squareRight:"\u2590",squareCenter:"\u25A0",bullet:"\u25CF",dot:"\u2024",ellipsis:"\u2026",pointerSmall:"\u203A",triangleUp:"\u25B2",triangleUpSmall:"\u25B4",triangleDown:"\u25BC",triangleDownSmall:"\u25BE",triangleLeftSmall:"\u25C2",triangleRightSmall:"\u25B8",home:"\u2302",heart:"\u2665",musicNote:"\u266A",musicNoteBeamed:"\u266B",arrowUp:"\u2191",arrowDown:"\u2193",arrowLeft:"\u2190",arrowRight:"\u2192",arrowLeftRight:"\u2194",arrowUpDown:"\u2195",almostEqual:"\u2248",notEqual:"\u2260",lessOrEqual:"\u2264",greaterOrEqual:"\u2265",identical:"\u2261",infinity:"\u221E",subscriptZero:"\u2080",subscriptOne:"\u2081",subscriptTwo:"\u2082",subscriptThree:"\u2083",subscriptFour:"\u2084",subscriptFive:"\u2085",subscriptSix:"\u2086",subscriptSeven:"\u2087",subscriptEight:"\u2088",subscriptNine:"\u2089",oneHalf:"\xBD",oneThird:"\u2153",oneQuarter:"\xBC",oneFifth:"\u2155",oneSixth:"\u2159",oneEighth:"\u215B",twoThirds:"\u2154",twoFifths:"\u2156",threeQuarters:"\xBE",threeFifths:"\u2157",threeEighths:"\u215C",fourFifths:"\u2158",fiveSixths:"\u215A",fiveEighths:"\u215D",sevenEighths:"\u215E",line:"\u2500",lineBold:"\u2501",lineDouble:"\u2550",lineDashed0:"\u2504",lineDashed1:"\u2505",lineDashed2:"\u2508",lineDashed3:"\u2509",lineDashed4:"\u254C",lineDashed5:"\u254D",lineDashed6:"\u2574",lineDashed7:"\u2576",lineDashed8:"\u2578",lineDashed9:"\u257A",lineDashed10:"\u257C",lineDashed11:"\u257E",lineDashed12:"\u2212",lineDashed13:"\u2013",lineDashed14:"\u2010",lineDashed15:"\u2043",lineVertical:"\u2502",lineVerticalBold:"\u2503",lineVerticalDouble:"\u2551",lineVerticalDashed0:"\u2506",lineVerticalDashed1:"\u2507",lineVerticalDashed2:"\u250A",lineVerticalDashed3:"\u250B",lineVerticalDashed4:"\u254E",lineVerticalDashed5:"\u254F",lineVerticalDashed6:"\u2575",lineVerticalDashed7:"\u2577",lineVerticalDashed8:"\u2579",lineVerticalDashed9:"\u257B",lineVerticalDashed10:"\u257D",lineVerticalDashed11:"\u257F",lineDownLeft:"\u2510",lineDownLeftArc:"\u256E",lineDownBoldLeftBold:"\u2513",lineDownBoldLeft:"\u2512",lineDownLeftBold:"\u2511",lineDownDoubleLeftDouble:"\u2557",lineDownDoubleLeft:"\u2556",lineDownLeftDouble:"\u2555",lineDownRight:"\u250C",lineDownRightArc:"\u256D",lineDownBoldRightBold:"\u250F",lineDownBoldRight:"\u250E",lineDownRightBold:"\u250D",lineDownDoubleRightDouble:"\u2554",lineDownDoubleRight:"\u2553",lineDownRightDouble:"\u2552",lineUpLeft:"\u2518",lineUpLeftArc:"\u256F",lineUpBoldLeftBold:"\u251B",lineUpBoldLeft:"\u251A",lineUpLeftBold:"\u2519",lineUpDoubleLeftDouble:"\u255D",lineUpDoubleLeft:"\u255C",lineUpLeftDouble:"\u255B",lineUpRight:"\u2514",lineUpRightArc:"\u2570",lineUpBoldRightBold:"\u2517",lineUpBoldRight:"\u2516",lineUpRightBold:"\u2515",lineUpDoubleRightDouble:"\u255A",lineUpDoubleRight:"\u2559",lineUpRightDouble:"\u2558",lineUpDownLeft:"\u2524",lineUpBoldDownBoldLeftBold:"\u252B",lineUpBoldDownBoldLeft:"\u2528",lineUpDownLeftBold:"\u2525",lineUpBoldDownLeftBold:"\u2529",lineUpDownBoldLeftBold:"\u252A",lineUpDownBoldLeft:"\u2527",lineUpBoldDownLeft:"\u2526",lineUpDoubleDownDoubleLeftDouble:"\u2563",lineUpDoubleDownDoubleLeft:"\u2562",lineUpDownLeftDouble:"\u2561",lineUpDownRight:"\u251C",lineUpBoldDownBoldRightBold:"\u2523",lineUpBoldDownBoldRight:"\u2520",lineUpDownRightBold:"\u251D",lineUpBoldDownRightBold:"\u2521",lineUpDownBoldRightBold:"\u2522",lineUpDownBoldRight:"\u251F",lineUpBoldDownRight:"\u251E",lineUpDoubleDownDoubleRightDouble:"\u2560",lineUpDoubleDownDoubleRight:"\u255F",lineUpDownRightDouble:"\u255E",lineDownLeftRight:"\u252C",lineDownBoldLeftBoldRightBold:"\u2533",lineDownLeftBoldRightBold:"\u252F",lineDownBoldLeftRight:"\u2530",lineDownBoldLeftBoldRight:"\u2531",lineDownBoldLeftRightBold:"\u2532",lineDownLeftRightBold:"\u252E",lineDownLeftBoldRight:"\u252D",lineDownDoubleLeftDoubleRightDouble:"\u2566",lineDownDoubleLeftRight:"\u2565",lineDownLeftDoubleRightDouble:"\u2564",lineUpLeftRight:"\u2534",lineUpBoldLeftBoldRightBold:"\u253B",lineUpLeftBoldRightBold:"\u2537",lineUpBoldLeftRight:"\u2538",lineUpBoldLeftBoldRight:"\u2539",lineUpBoldLeftRightBold:"\u253A",lineUpLeftRightBold:"\u2536",lineUpLeftBoldRight:"\u2535",lineUpDoubleLeftDoubleRightDouble:"\u2569",lineUpDoubleLeftRight:"\u2568",lineUpLeftDoubleRightDouble:"\u2567",lineUpDownLeftRight:"\u253C",lineUpBoldDownBoldLeftBoldRightBold:"\u254B",lineUpDownBoldLeftBoldRightBold:"\u2548",lineUpBoldDownLeftBoldRightBold:"\u2547",lineUpBoldDownBoldLeftRightBold:"\u254A",lineUpBoldDownBoldLeftBoldRight:"\u2549",lineUpBoldDownLeftRight:"\u2540",lineUpDownBoldLeftRight:"\u2541",lineUpDownLeftBoldRight:"\u253D",lineUpDownLeftRightBold:"\u253E",lineUpBoldDownBoldLeftRight:"\u2542",lineUpDownLeftBoldRightBold:"\u253F",lineUpBoldDownLeftBoldRight:"\u2543",lineUpBoldDownLeftRightBold:"\u2544",lineUpDownBoldLeftBoldRight:"\u2545",lineUpDownBoldLeftRightBold:"\u2546",lineUpDoubleDownDoubleLeftDoubleRightDouble:"\u256C",lineUpDoubleDownDoubleLeftRight:"\u256B",lineUpDownLeftDoubleRightDouble:"\u256A",lineCross:"\u2573",lineBackslash:"\u2572",lineSlash:"\u2571"},Dr={tick:"\u2714",info:"\u2139",warning:"\u26A0",cross:"\u2718",squareSmall:"\u25FB",squareSmallFilled:"\u25FC",circle:"\u25EF",circleFilled:"\u25C9",circleDotted:"\u25CC",circleDouble:"\u25CE",circleCircle:"\u24DE",circleCross:"\u24E7",circlePipe:"\u24BE",radioOn:"\u25C9",radioOff:"\u25EF",checkboxOn:"\u2612",checkboxOff:"\u2610",checkboxCircleOn:"\u24E7",checkboxCircleOff:"\u24BE",pointer:"\u276F",triangleUpOutline:"\u25B3",triangleLeft:"\u25C0",triangleRight:"\u25B6",lozenge:"\u25C6",lozengeOutline:"\u25C7",hamburger:"\u2630",smiley:"\u32E1",mustache:"\u0DF4",star:"\u2605",play:"\u25B6",nodejs:"\u2B22",oneSeventh:"\u2150",oneNinth:"\u2151",oneTenth:"\u2152"},xs={tick:"\u221A",info:"i",warning:"\u203C",cross:"\xD7",squareSmall:"\u25A1",squareSmallFilled:"\u25A0",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(\u25CB)",circleCross:"(\xD7)",circlePipe:"(\u2502)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[\xD7]",checkboxOff:"[ ]",checkboxCircleOn:"(\xD7)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"\u2206",triangleLeft:"\u25C4",triangleRight:"\u25BA",lozenge:"\u2666",lozengeOutline:"\u25CA",hamburger:"\u2261",smiley:"\u263A",mustache:"\u250C\u2500\u2510",star:"\u2736",play:"\u25BA",nodejs:"\u2666",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},Rs={...nr,...Dr},ws={...nr,...xs},ks=rt(),Ss=ks?Rs:ws,I=Ss,h0=Object.entries(Dr);var rr=(e=0)=>u=>`\x1B[${u+e}m`,or=(e=0)=>u=>`\x1B[${38+e};5;${u}m`,ir=(e=0)=>(u,t,n)=>`\x1B[${38+e};2;${u};${t};${n}m`,w={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},g0=Object.keys(w.modifier),Ts=Object.keys(w.color),_s=Object.keys(w.bgColor),m0=[...Ts,..._s];function vs(){let e=new Map;for(let[u,t]of Object.entries(w)){for(let[n,D]of Object.entries(t))w[n]={open:`\x1B[${D[0]}m`,close:`\x1B[${D[1]}m`},t[n]=w[n],e.set(D[0],D[1]);Object.defineProperty(w,u,{value:t,enumerable:!1})}return Object.defineProperty(w,"codes",{value:e,enumerable:!1}),w.color.close="\x1B[39m",w.bgColor.close="\x1B[49m",w.color.ansi=rr(),w.color.ansi256=or(),w.color.ansi16m=ir(),w.bgColor.ansi=rr(10),w.bgColor.ansi256=or(10),w.bgColor.ansi16m=ir(10),Object.defineProperties(w,{rgbToAnsi256:{value(u,t,n){return u===t&&t===n?u<8?16:u>248?231:Math.round((u-8)/247*24)+232:16+36*Math.round(u/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(u){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(r=>r+r).join(""));let D=Number.parseInt(n,16);return[D>>16&255,D>>8&255,D&255]},enumerable:!1},hexToAnsi256:{value:u=>w.rgbToAnsi256(...w.hexToRgb(u)),enumerable:!1},ansi256ToAnsi:{value(u){if(u<8)return 30+u;if(u<16)return 90+(u-8);let t,n,D;if(u>=232)t=((u-232)*10+8)/255,n=t,D=t;else{u-=16;let i=u%36;t=Math.floor(u/36)/5,n=Math.floor(i/6)/5,D=i%6/5}let r=Math.max(t,n,D)*2;if(r===0)return 30;let o=30+(Math.round(D)<<2|Math.round(n)<<1|Math.round(t));return r===2&&(o+=60),o},enumerable:!1},rgbToAnsi:{value:(u,t,n)=>w.ansi256ToAnsi(w.rgbToAnsi256(u,t,n)),enumerable:!1},hexToAnsi:{value:u=>w.ansi256ToAnsi(w.hexToAnsi256(u)),enumerable:!1}}),w}var Is=vs(),Q=Is;function su(e){return Number.isInteger(e)?we(e)||ke(e):!1}var Ne=27,lr=144,Fr=152,dr=155,fr=156,Fu=157,pr=158,hr=159,$e=new Set([Ne,lr,Fr,dr,fr,Fu,pr,hr]),ge="\x1B",at="\x07",Ft="[",Cr="]",Ms="P",Ps="X",Os="^",Ls="_",gr="m",cu="\\",mr=`${ge}${cu}`,Ns="\x9D",lu="\x9C",ct=`${ge}${Cr}8;`,lt=`${Ns}8;`,$s=`${ct};`,Us=`${lt};`,Ws="0".codePointAt(0),js="9".codePointAt(0),Gs=";".codePointAt(0),qs=":".codePointAt(0),Hs="0".codePointAt(0),Vs="?".codePointAt(0),zs=" ".codePointAt(0),Ks="/".codePointAt(0),Ys="@".codePointAt(0),Js="~".codePointAt(0),Xs=127462,Zs=127487,sr=0,au=38,ot=39,Qs=48,it=49,ea=5,ua=2,ar=3,cr=5,ta=2,na=4,Da=65039,ra=8419,oa=new RegExp("\\p{Emoji_Presentation}","v"),dt=new Intl.Segmenter(void 0,{granularity:"grapheme"}),Er=new Set;for(let[,e]of Q.codes)Er.add(e);function ia(e){return e>=Ws&&e<=js||e===Gs||e===qs}function sa(e){return e>=Hs&&e<=Vs}function aa(e){return e>=zs&&e<=Ks}function ca(e){return e>=Ys&&e<=Js}function la(e){return e>=Xs&&e<=Zs}function j(e,u){return{token:{type:"control",code:e},endIndex:u}}function Fa(e){if(oa.test(e))return!0;for(let u of e){let t=u.codePointAt(0);if(t===Da||t===ra)return!0}return!1}function Br(e){let u=0;for(let t of e){let n=t.codePointAt(0);if(su(n))return 2;la(n)&&u++}return u>=1||Fa(e)?2:1}function da(e){return e.startsWith("\x9B")?"\x9B":`${ge}${Ft}`}function Le(e,u){return`${e}${u.join(";")}${gr}`}function fa(e){let u=[],t=da(e),n;if(e.startsWith(`${ge}${Ft}`))n=e.slice(2,-1);else if(e.startsWith("\x9B"))n=e.slice(1,-1);else return u;let D=n.length===0?[String(sr)]:n.split(";"),r=0;for(;r<D.length;){let o=Number.parseInt(D[r],10);if(Number.isNaN(o)){r++;continue}if(o===sr){u.push({type:"reset"}),r++;continue}if(o===au||o===Qs){let a=Number.parseInt(D[r+1],10);if(a===ea&&r+ta<D.length){let c=Le(t,D.slice(r,r+ar));u.push({type:"start",code:c,endCode:Q.color.ansi(o===au?ot:it)}),r+=ar;continue}if(a===ua&&r+na<D.length){let c=Le(t,D.slice(r,r+cr));u.push({type:"start",code:c,endCode:Q.color.ansi(o===au?ot:it)}),r+=cr;continue}let F=Le(t,[D[r]]);u.push({type:"start",code:F,endCode:Q.color.ansi(o===au?ot:it)}),r++;continue}if(Er.has(o)){u.push({type:"end",endCode:Q.color.ansi(o)}),r++;continue}let i=Q.codes.get(o);if(i!==void 0){let a=Le(t,[D[r]]);u.push({type:"start",code:a,endCode:Q.color.ansi(i)}),r++;continue}let s=Le(t,[D[r]]);u.push({type:"start",code:s,endCode:Q.reset.open}),r++}return u.length===0&&u.push({type:"reset"}),u}function pa(e,u){let t=e.codePointAt(u),n;if(t===Ne){if(e[u+1]!==Ft)return;n=u+2}else if(t===dr)n=u+1;else return;let D=!0;for(let r=n;r<e.length;r++){let o=e.codePointAt(r);if(ca(o)){let s=e.slice(u,r+1);return e[r]!==gr||!D?j(s,r+1):{token:{type:"sgr",code:s,fragments:fa(s)},endIndex:r+1}}if(sa(o)){ia(o)||(D=!1);continue}if(aa(o)){D=!1;continue}let i=r;return j(e.slice(u,i),i)}return j(e.slice(u),e.length)}function ha(e,u){let t,n,D=e.codePointAt(u);if(D===Ne&&e.startsWith(ct,u))t=ct,n=$s;else if(D===Fu&&e.startsWith(lt,u))t=lt,n=Us;else return;let r=e.indexOf(";",u+t.length);if(r===-1)return j(e.slice(u),e.length);for(let o=r+1;o<e.length;o++){let i=e[o];if(i===at){let s=e.slice(u,o+1),a=o===r+1?"close":"open";return{token:{type:"hyperlink",code:s,action:a,closePrefix:n,terminator:at},endIndex:o+1}}if(i===ge&&e[o+1]===cu){let s=e.slice(u,o+2),a=o===r+1?"close":"open";return{token:{type:"hyperlink",code:s,action:a,closePrefix:n,terminator:mr},endIndex:o+2}}if(i===lu){let s=e.slice(u,o+1),a=o===r+1?"close":"open";return{token:{type:"hyperlink",code:s,action:a,closePrefix:n,terminator:lu},endIndex:o+1}}}return j(e.slice(u),e.length)}function Ca(e,u){let t=e.codePointAt(u),n,D=!1;switch(t){case Ne:{switch(e[u+1]){case Cr:{n=u+2,D=!0;break}case Ms:case Ps:case Os:case Ls:{n=u+2;break}case cu:return j(mr,u+2);default:return}break}case Fu:{n=u+1,D=!0;break}case lr:case Fr:case pr:case hr:{n=u+1;break}case fr:return j(lu,u+1);default:return}for(let r=n;r<e.length;r++){if(D&&e[r]===at)return j(e.slice(u,r+1),r+1);if(e[r]===ge&&e[r+1]===cu)return j(e.slice(u,r+2),r+2);if(e[r]===lu)return j(e.slice(u,r+1),r+1)}return j(e.slice(u),e.length)}function Ue(e,u){let t=e.codePointAt(u);if(t===Ne||t===Fu){let D=ha(e,u);if(D)return D}let n=Ca(e,u);return n||pa(e,u)}function br(e,u,t){for(;u<e.length;){let n=e.codePointAt(u);if(!$e.has(n))break;let D=Ue(e,u);if(!D)break;t.push(D.token),u=D.endIndex}return u}function Ar(e,u,t){let n=t.containing(u);if(!(!n||n.index!==u))return{token:{type:"character",value:n.segment,visibleWidth:Br(n.segment),isGraphemeContinuation:!1},endIndex:u+n.segment.length}}function ga(e){let u=[],t=0;for(;t<e.length;){let n=e.codePointAt(t);if($e.has(n)){let r=Ue(e,t);if(r){t=r.endIndex;continue}}let D=String.fromCodePoint(n);u.push({value:D,visibleWidth:1,isGraphemeContinuation:!1}),t+=D.length}return u}function ma(e){if(e.length===0)return;let u=e.map(({value:r})=>r).join(""),t=[],n=0;for(let r of e)t.push(n),n+=r.value.length;let D=0;for(let r of dt.segment(u)){for(;D<e.length&&t[D]<r.index;)D++;let o=D,i=!0;for(;o<e.length&&t[o]<r.index+r.segment.length;)e[o].visibleWidth=i?Br(r.segment):0,e[o].isGraphemeContinuation=!i,i=!1,o++;D=o}}function st(e,{endCharacter:u=Number.POSITIVE_INFINITY}={}){let t=[],n=ga(e);ma(n);let D=0,r=0,o=0;for(;D<e.length;){let i=e.codePointAt(D);if($e.has(i)){let f=Ue(e,D);if(f){t.push(f.token),D=f.endIndex;continue}}let s=String.fromCodePoint(i),a=n[r],F=su(i)?2:s.length;a&&(F=a.visibleWidth);let c={type:"character",value:s,visibleWidth:F,isGraphemeContinuation:a?a.isGraphemeContinuation:!1};if(t.push(c),D+=s.length,r++,o+=c.visibleWidth,o>=u){let f=n[r];if(!f||!f.isGraphemeContinuation){D=br(e,D,t);break}}}return t}function yr(e,u){let t=`${e}${u}`,n=e.length;for(let D of dt.segment(t)){if(D.index===n)return!1;if(D.index>n)return!0}return!0}function Ea(e,u,t,n){if(!t)return!1;let D=u,r=!1;for(;D<e.length;){let o=e.codePointAt(D);if($e.has(o)){let s=Ue(e,D);if(s){r=!0,D=s.endIndex;continue}}if(!r)return!1;let i=Ar(e,D,n);return i?yr(t,i.token.value):!0}return!1}function ft(e,{endCharacter:u=Number.POSITIVE_INFINITY}={}){let t=[],n=dt.segment(e),D=0,r=0,o,i=!1;for(;D<e.length;){let s=e.codePointAt(D);if($e.has(s)){let F=Ue(e,D);if(F){t.push(F.token),D=F.endIndex,i=!0;continue}}let a=Ar(e,D,n);if(!a)return st(e,{endCharacter:u});if(i&&o&&yr(o,a.token.value))return st(e,{endCharacter:u});if(t.push(a.token),D=a.endIndex,r+=a.token.visibleWidth,i=!1,o=a.token.value,r>=u){if(Ea(e,D,o,n))return st(e,{endCharacter:u});D=br(e,D,t);break}}return t}function Ba(e,u){for(let t of u)switch(t.type){case"reset":{e.clear();break}case"end":{e.delete(t.endCode);break}case"start":{e.delete(t.endCode),e.set(t.endCode,t.code);break}default:break}return e}function ba(e){return[...e.keys()].toReversed().join("")}function Aa(e){return`${e.closePrefix}${e.terminator}`}function ya(e,u){let t=!1,n=!1;for(let D of e.fragments){if(D.type==="start"){t=!0;continue}if(D.type==="reset"&&u.size>0){n=!0;continue}D.type==="end"&&u.has(D.endCode)&&(n=!0)}return n&&!t}function xa(e){return e.fragments.some(u=>u.type==="start")}function xr(e){if(e.activeHyperlink&&!e.activeHyperlinkHasVisibleText&&e.activeHyperlinkOutputIndex!==void 0){let u=e.activeHyperlink.code.length;e.returnValue=e.returnValue.slice(0,e.activeHyperlinkOutputIndex)+e.returnValue.slice(e.activeHyperlinkOutputIndex+u),e.pendingSgrOutputIndex!==void 0&&e.pendingSgrOutputIndex>e.activeHyperlinkOutputIndex&&(e.pendingSgrOutputIndex-=u)}e.activeHyperlink=void 0,e.activeHyperlinkHasVisibleText=!1,e.activeHyperlinkOutputIndex=void 0}function Ra(e){return e.isPastEnd&&!ya(e.token,e.activeStyles)||(e.include&&xa(e.token)&&e.pendingSgrOutputIndex===void 0&&(e.pendingSgrOutputIndex=e.returnValue.length,e.pendingSgrActiveStyles=new Map(e.activeStyles)),e.activeStyles=Ba(e.activeStyles,e.token.fragments),e.include&&(e.returnValue+=e.token.code)),e}function wa(e){if(e.isPastEnd&&(e.token.action!=="close"||!e.activeHyperlink))return e;if(e.token.action==="open")e.activeHyperlink=e.token,e.activeHyperlinkHasVisibleText=!1,e.activeHyperlinkOutputIndex=void 0,e.include&&(e.activeHyperlinkOutputIndex=e.returnValue.length);else if(e.token.action==="close"){if(e.include&&e.activeHyperlink&&!e.activeHyperlinkHasVisibleText)return xr(e),e;e.activeHyperlink=void 0,e.activeHyperlinkHasVisibleText=!1,e.activeHyperlinkOutputIndex=void 0}return e.include&&(e.returnValue+=e.token.code),e}function ka(e){return!e.isPastEnd&&e.include&&(e.returnValue+=e.token.code),e}function Sa(e){return!e.include&&e.position>=e.start&&!e.token.isGraphemeContinuation&&(e.include=!0,e.returnValue=[...e.activeStyles.values()].join(""),e.activeHyperlink&&(e.activeHyperlinkOutputIndex=e.returnValue.length,e.returnValue+=e.activeHyperlink.code)),e.include&&(e.returnValue+=e.token.value,e.pendingSgrOutputIndex=void 0,e.pendingSgrActiveStyles=void 0,e.activeHyperlink&&(e.activeHyperlinkHasVisibleText=!0)),e.position+=e.token.visibleWidth,e}var Ta={sgr:Ra,hyperlink:wa,control:ka,character:Sa};function _a(e){let u=Ta[e.token.type];return u?u(e):e}function va(e){let u=Array.from({length:e.length},()=>!1),t=!1;for(let n=e.length-1;n>=0;n--){let D=e[n];u[n]=t,D.type==="character"&&(t=!!D.isGraphemeContinuation)}return u}function Ia(e,u,t){return t===void 0?!1:u>=t?!0:e.type==="character"&&!e.isGraphemeContinuation&&u+e.visibleWidth>t}function V(e,u,t){let n=ft(e,{endCharacter:t}),D=va(n),r=new Map,o,i=!1,s,a,F,c=0,f="",d=!1;for(let[l,C]of n.entries()){let h=Ia(C,c,t);if(h&&C.type!=="character"&&D[l]&&(h=!1),h&&C.type==="character"&&!C.isGraphemeContinuation){if(o&&!i){let p={activeHyperlink:o,activeHyperlinkHasVisibleText:i,activeHyperlinkOutputIndex:s,pendingSgrOutputIndex:a,returnValue:f};xr(p),{activeHyperlink:o,activeHyperlinkHasVisibleText:i,activeHyperlinkOutputIndex:s,pendingSgrOutputIndex:a,returnValue:f}=p}a!==void 0&&(f=f.slice(0,a),r=F,a=void 0,F=void 0);break}({activeStyles:r,activeHyperlink:o,activeHyperlinkHasVisibleText:i,activeHyperlinkOutputIndex:s,pendingSgrOutputIndex:a,pendingSgrActiveStyles:F,position:c,returnValue:f,include:d}=_a({token:C,isPastEnd:h,start:u,activeStyles:r,activeHyperlink:o,activeHyperlinkHasVisibleText:i,activeHyperlinkOutputIndex:s,pendingSgrOutputIndex:a,pendingSgrActiveStyles:F,position:c,returnValue:f,include:d}))}return d?(o&&(f+=Aa(o)),f+=ba(r),f):""}var Ma=new Intl.Segmenter,Rr=new RegExp("^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Format}|\\p{Mark}|\\p{Surrogate})+$","v"),Pa=new RegExp("^[\\p{Default_Ignorable_Code_Point}\\p{Control}\\p{Format}\\p{Mark}\\p{Surrogate}]+","v"),Oa=new RegExp("^\\p{RGI_Emoji}$","v"),La=/^[\d#*]\u20E3$/,Na=new RegExp("\\p{Extended_Pictographic}","gu");function $a(e){if(e.length>50)return!1;if(La.test(e))return!0;if(e.includes("\u200D")){let u=e.match(Na);return u!==null&&u.length>=2}return!1}function Ua(e){return e.replace(Pa,"")}function Wa(e){return Rr.test(e)}function wr(e){return e>=4352&&e<=4447||e>=43360&&e<=43388}function kr(e){return e>=4448&&e<=4519||e>=55216&&e<=55238}function Sr(e){return e>=4520&&e<=4607||e>=55243&&e<=55291}function ja(e){return wr(e)||kr(e)||Sr(e)}function Ga(e,u){let t=[];for(let D of e)Rr.test(D)||t.push(D.codePointAt(0));if(t.length===0)return;let n=0;for(let D=0;D<t.length;D++){let r=t[D];if(!ja(r)){if(n===0)return;for(let o=D;o<t.length;o++)n+=J(t[o],u);return n}if(wr(r)&&kr(t[D+1])){n+=2,D+=Sr(t[D+2])?2:1;continue}n+=J(r,u)}return n}function qa(e,u){let t=0,n=!0;for(let D of e){if(n){n=!1;continue}D>="\uFF00"&&D<="\uFFEF"&&(t+=J(D.codePointAt(0),u))}return t}function G(e,u={}){if(typeof e!="string"||e.length===0)return 0;let{ambiguousIsNarrow:t=!0,countAnsiEscapeCodes:n=!1}=u,D=e;if(!n&&(D.includes("\x1B")||D.includes("\x9B"))&&(D=Y(D)),D.length===0)return 0;if(/^[\u0020-\u007E]*$/.test(D))return D.length;let r=0,o={ambiguousAsWide:!t};for(let{segment:i}of Ma.segment(D)){if(Wa(i))continue;if(Oa.test(i)||$a(i)){r+=2;continue}let s=Ua(i),a=Ga(s,o);if(a!==void 0){r+=a;continue}let F=s.codePointAt(0);r+=J(F,o),r+=qa(s,o)}return r}function du(e,u,t){if(e.charAt(u)===" ")return u;let n=t?1:-1;for(let D=0;D<=3;D++){let r=u+D*n;if(e.charAt(r)===" ")return r}return u}function me(e,u,t={}){let{position:n="end",space:D=!1,preferTruncationOnSpace:r=!1}=t,{truncationCharacter:o="\u2026"}=t;if(typeof e!="string")throw new TypeError(`Expected \`input\` to be a string, got ${typeof e}`);if(typeof u!="number")throw new TypeError(`Expected \`columns\` to be a number, got ${typeof u}`);if(u<1)return"";let i=G(e);if(i<=u)return e;if(u===1)return o;let s={ESC:27,LEFT_BRACKET:91,LETTER_M:109},a=l=>l>=48&&l<=57||l===59;function F(l){let C=0;for(;C+2<l.length&&l.codePointAt(C)===s.ESC&&l.codePointAt(C+1)===s.LEFT_BRACKET;){let h=C+2;for(;h<l.length&&a(l.codePointAt(h));)h++;if(h<l.length&&l.codePointAt(h)===s.LETTER_M){C=h+1;continue}break}return C}function c(l){let C=l.length;for(;C>1&&l.codePointAt(C-1)===s.LETTER_M;){let h=C-2;for(;h>=0&&a(l.codePointAt(h));)h--;if(h>=1&&l.codePointAt(h-1)===s.ESC&&l.codePointAt(h)===s.LEFT_BRACKET){C=h-1;continue}break}return C}function f(l,C){let h=c(l);return h===l.length?l+C:l.slice(0,h)+C+l.slice(h)}function d(l,C){let h=F(C);return h===0?l+C:C.slice(0,h)+l+C.slice(h)}if(n==="start"){if(r){let C=du(e,i-u+1,!0),h=V(e,C,i).trim();return d(o,h)}D&&(o+=" ");let l=V(e,i-u+G(o),i);return d(o,l)}if(n==="middle"){D&&(o=` ${o} `);let l=Math.floor(u/2);if(r){let C=du(e,l),h=du(e,i-(u-l)+1,!0);return V(e,0,C)+o+V(e,h,i).trim()}return V(e,0,l)+o+V(e,i-(u-l)+G(o),i)}if(n==="end"){if(r){let C=du(e,u-1),h=V(e,0,C);return f(h,o)}D&&(o=` ${o}`);let l=V(e,0,u-G(o));return f(l,o)}throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${n}`)}var pt=300*60*1e3;function Ha(e,u=pt){if(e.length===0)return[];let t=[...e].sort((i,s)=>i.timestamp.localeCompare(s.timestamp)),n=[],D=null,r=0,o=Date.now();for(let i of t){let s=new Date(i.timestamp).getTime();(!D||s-r>=u)&&(r=s,D={id:i.timestamp,startTime:i.timestamp,endTime:new Date(s+u).toISOString(),actualEndTime:i.timestamp,isActive:!1,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,totalTokens:0,cost:0,saved:0,models:[],requests:0},n.push(D));let a=oe(i);D.inputTokens+=i.usage.input_tokens,D.outputTokens+=i.usage.output_tokens,D.cacheReadTokens+=i.usage.cache_read_input_tokens,D.cacheCreationTokens+=i.usage.cache_creation_input_tokens,D.totalTokens=D.inputTokens+D.outputTokens+D.cacheReadTokens+D.cacheCreationTokens,D.cost+=a.total,D.saved+=a.saved,D.requests+=1,D.actualEndTime=i.timestamp,D.models.includes(i.model)||D.models.push(i.model)}for(let i of n){let s=new Date(i.endTime).getTime();i.isActive=o<s}return n}function Va(e,u=pt){return Ha(e,u).find(D=>D.isActive)??null}function Tr(e,u=pt){let t=Va(e,u);if(!t)return{block:null,windowMs:u,elapsedMs:0,remainingMs:0,progress:0,burnRatePerMin:0,costPerMin:0,projectedTotal:0,projectedCost:0};let n=Date.now(),D=new Date(t.startTime).getTime(),r=new Date(t.endTime).getTime(),o=n-D,i=Math.max(0,r-n),s=Math.min(1,o/u),a=o/6e4,F=a>0?t.totalTokens/a:0,c=a>0?t.cost/a:0,f=u/6e4;return{block:t,windowMs:u,elapsedMs:o,remainingMs:i,progress:s,burnRatePerMin:F,costPerMin:c,projectedTotal:F*f,projectedCost:c*f}}function _r(e,u){let t=u.source==="all"?e:e.filter(h=>h.source===u.source);if(t.length===0)return{sessions:0,messages:0,totalTokens:0,activeDays:0,currentStreak:0,longestStreak:0,peakHour:-1,favoriteModel:null,heatmap:fu(),heatmapMax:0,tokenHeatmap:fu(),tokensSummed:0};let n=new Set,D=new Set,r=new Array(24).fill(0),o=new Map,i=fu(),s=fu(),a=0,F=0;for(let h of t){h.sessionId&&n.add(h.sessionId);let p=new Date(h.timestamp);if(Number.isNaN(p.getTime()))continue;let g=za(p);D.add(g);let B=p.getDay(),m=p.getHours();r[m]+=1,i[B][m]+=1,o.set(h.model,(o.get(h.model)??0)+1);let b=h.usage,k=b.input_tokens+b.output_tokens+b.cache_read_input_tokens+b.cache_creation_input_tokens;s[B][m]+=k,a+=k,F+=1}let c=Ka(r),f=Ya(o),{current:d,longest:l}=Ja(D,u.streakWindowDays??365),C=0;for(let h of i)for(let p of h)p>C&&(C=p);return{sessions:n.size,messages:F,totalTokens:a,activeDays:D.size,currentStreak:d,longestStreak:l,peakHour:c,favoriteModel:f,heatmap:i,heatmapMax:C,tokenHeatmap:s,tokensSummed:a}}function fu(){return Array.from({length:7},()=>new Array(24).fill(0))}function za(e){let u=e.getFullYear(),t=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`${u}-${t}-${n}`}function Ka(e){let u=-1,t=-1;for(let n=0;n<e.length;n+=1)e[n]>t&&(t=e[n],u=n);return u}function Ya(e){let u=null,t=-1;for(let[n,D]of e)D>t&&(u=n,t=D);return u}function Ja(e,u){if(e.size===0)return{current:0,longest:0};let t=Array.from(e).map(c=>new Date(c+"T00:00:00").getTime()).filter(c=>Number.isFinite(c)).sort((c,f)=>c-f),n=1,D=1;for(let c=1;c<t.length;c+=1)t[c]-t[c-1]===864e5?(D+=1,D>n&&(n=D)):D=1;let r=Xa(Date.now()),o=t[t.length-1];if(r-o>864e5)return{current:0,longest:n};let i=o,s=0,a=0,F=new Set(t);for(;a<u&&F.has(i);)s+=1,i-=864e5,a+=1;return{current:s,longest:n}}function Xa(e){let u=new Date(e);return u.setHours(0,0,0,0),u.getTime()}var ee={brand:[129,140,248],green:[34,197,94],red:[239,68,68],yellow:[234,179,8],cyan:[34,211,238],input:[96,165,250],cacheWrite:[167,139,250],cacheRead:[52,211,153],output:[251,146,60]};function vr(e){let u=new Xe({level:e?3:0}),t=n=>e?D=>u.rgb(n[0],n[1],n[2])(D):D=>D;return{reset:e?"\x1B[0m":"",bold:n=>u.bold(n),dim:n=>u.dim(n),brand:t(ee.brand),green:t(ee.green),red:t(ee.red),yellow:t(ee.yellow),cyan:t(ee.cyan),input:t(ee.input),cacheWrite:t(ee.cacheWrite),cacheRead:t(ee.cacheRead),output:t(ee.output)}}function pu(e){return G(e)}function hu(e,u,t=" "){let n=u-G(e);return n>0?e+t.repeat(n):e}function Ee(e,u,t=" "){let n=u-G(e);return n>0?t.repeat(n)+e:e}function ht(e,u,t=" "){let n=u-G(e);if(n<=0)return e;let D=Math.floor(n/2),r=n-D;return t.repeat(D)+e+t.repeat(r)}var Za=["","\u258F","\u258E","\u258D","\u258C","\u258B","\u258A","\u2589","\u2588"];function Cu(e,u,t){if(u<=0||!Number.isFinite(e)||e<=0)return" ".repeat(Math.max(0,u));let D=Math.min(1,e)*u,r=Math.floor(D),o=D-r,i=Math.round(o*8),s="\u2588".repeat(r);i>0&&r<u&&(s+=Za[i]);let a=hu(s,u," ");return t?t(a):a}var Qa=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"];function We(e,u,t){if(u<=0)return"";if(e.length===0)return t?t("\u2500".repeat(u)):"\u2500".repeat(u);let n=[];if(e.length===u)n.push(...e);else if(e.length>u){let o=e.length/u;for(let i=0;i<u;i+=1){let s=Math.floor(i*o),a=Math.floor((i+1)*o),F=0,c=0;for(let f=s;f<Math.min(a,e.length);f+=1)F+=e[f],c+=1;n.push(c>0?F/c:0)}}else{let o=u-e.length;for(let i=0;i<o;i+=1)n.push(0);n.push(...e)}let D=Math.max(...n,0);if(D<=0){let o="\u2500".repeat(u);return t?t(o):o}let r=n.map(o=>Qa[Math.min(7,Math.max(0,Math.round(o/D*7)))]).join("");return t?t(r):r}var ec=["","\u2581","\u2582","\u2583","\u2584","\u2585","\u2586","\u2587","\u2588"];function Ir(e,u,t){let n=new Array(u).fill(" ");if(u<=0||t<=0)return n;let D=e.reduce((F,c)=>F+Math.max(0,c.value),0);if(D<=0)return n;let r=D/t*u*8,o=u*8,i=Math.min(r,o),s=i,a=0;for(let F of e){if(F.value<=0||s<=0)continue;let c=Math.min(s,F.value/D*i),f=a,d=a+c,l=Math.floor(f/8),C=Math.min(u-1,Math.floor((d-1e-4)/8));for(let h=l;h<=C;h+=1){let p=h*8,g=Math.max(0,f-p),B=Math.min(8,d-p),m;if(B>=8)m="\u2588";else if(g<=0){let b=Math.max(1,Math.round(B));m=ec[Math.min(8,b)]||"\u2581"}else m="\u2588";n[u-1-h]=F.color?F.color(m):m}s-=c,a=d}return n}function Or(e,u,t,n){let D=t.width??process.stdout.columns??100,r=t.color!==!1;X.level=r?3:0;let o=vr(r);if(D<80)return[`[ccgauge] terminal width (${D}) is below the dashboard's 80-column floor.`,"Resize wider for the rich layout, or omit --dashboard for the standard report.","",...Ct(u,t).split(`
23
+ `)].join(`
24
+ `);let i=D-4,s=[];return t.banner!==!1&&(s.push(...uc(o,i,u)),s.push("")),s.push(...nc(o,i,e,u)),s.push(""),t.compact!==!0&&u.trend.length>0&&(s.push(...oc(o,i,u)),s.push("")),s.push(...ic(o,i,u)),s.push(""),s.push(...sc(o,i,n)),s.push(""),s.push(...ac(o,n,u,t)),s.map(a=>" "+a).join(`
25
+ `)}function uc(e,u,t){let n=`${e.brand(e.bold("ccgauge"))} ${e.dim(I.line)} ${e.bold("dashboard")}`,D=e.dim([`range: ${t.range}`,`source: ${t.source}`,`by: ${t.by}`,`generated ${new Date(t.generatedAt).toLocaleString()}`].join(` ${I.bullet} `)),r=pu(n),o=pu(D),i=Math.max(2,u-r-o);return[`${n}${" ".repeat(i)}${D}`]}function tc(e,u){function t(r){return Tr(e.filter(o=>o.source===r),re(r).capabilities.blockWindowMs)}if(u==="claude")return t("claude");if(u==="codex")return t("codex");let n=t("claude");if(n.block)return n;let D=t("codex");return D.block?D:n}function nc(e,u,t,n){let D=n.totals,r=n.trend.map(d=>d.tokens),o=n.trend.map(d=>d.cost),i=n.trend.map(d=>Math.max(0,d.cost-d.cost*.95)),s=n.trend.map(d=>d.turns),a=D.input+D.cacheRead+D.cacheWrite,F=a>0?D.cacheRead/a:0,c=tc(t.records,n.source),f=[{label:"Total tokens",value:e.bold(v(D.total)),sub:`${D.requests.toLocaleString()} reqs \xB7 ${D.turns.toLocaleString()} convs`,spark:We(r,14,e.input)},{label:"Cost",value:e.bold(N(D.cost)),sub:D.cost>0?`${N(D.cost/Math.max(1,D.requests))} / req`:"\u2014",spark:We(o,14,e.output)},{label:"Cache saved",value:e.bold(e.green(N(D.saved))),sub:"vs full input pricing",spark:We(i,14,e.green)},{label:"Cache hit",value:e.bold(e.green(de(F,0))),spark:Cu(F,14,e.green),sub:`${v(D.cacheRead)} cached`},{label:"Conversations",value:e.bold(D.turns.toLocaleString()),sub:D.requests>0?`${(D.requests/Math.max(1,D.turns)).toFixed(1)} reqs/turn`:"\u2014",spark:We(s,14,e.cacheRead)},{label:"Active 5h block",value:c?.block?e.bold(Kt(c.remainingMs)):e.dim("idle"),spark:c?.block?Cu(c.progress,14,e.yellow):void 0,sub:c?.block?`${de(c.progress,0)} elapsed`:"no active window"}];return Dc(f,e,u)}function Dc(e,u,t){let o=Math.max(1,Math.floor((t+1)/27)),i=[];for(let s=0;s<e.length;s+=o){let F=e.slice(s,s+o).map(c=>rc(c,22,u));i.push(...Lr(F,1).split(`
26
+ `)),s+o<e.length&&i.push("")}return i}function rc(e,u,t){let n=u,D=[t.dim(e.label.toUpperCase()),"",me(e.value,n),e.spark?me(e.spark,n):"",t.dim(me(e.sub,n))].join(`
27
+ `);return Yu(D,{padding:{top:0,right:1,bottom:0,left:1},borderStyle:"round",borderColor:"#5a5a64",width:u+4,textAlignment:"left"})}function Lr(e,u){let t=e.map(i=>i.split(`
28
+ `)),n=Math.max(...t.map(i=>i.length)),D=t.map(i=>Math.max(...i.map(pu))),r=" ".repeat(u),o=[];for(let i=0;i<n;i+=1){let s=t.map((a,F)=>hu(a[i]??"",D[F]));o.push(s.join(r))}return o.join(`
29
+ `)}function oc(e,u,t){let n=t.trend,D=10,r=Math.max(4,Math.min(8,Math.floor((u-8)/Math.max(1,n.length)))),o=Math.max(...n.map(p=>p.input+p.output+p.cacheRead+p.cacheWrite),1),i=`${e.brand(I.pointerSmall)} ${e.bold("Token usage trend")} ${e.dim(`(${t.gran} ${I.bullet} stacked: input / cache-w / cache-r / output)`)}`,s=n.map(p=>Ir([{value:p.input,color:e.input},{value:p.cacheWrite,color:e.cacheWrite},{value:p.cacheRead,color:e.cacheRead},{value:p.output,color:e.output}],D,o)),a=[Ee(v(o),7),Ee(v(o/2),7),Ee("0",7)],F=p=>p===0?a[0]:p===Math.floor((D-1)/2)?a[1]:p===D-1?a[2]:" ".repeat(7),c=[i,""];for(let p=0;p<D;p+=1){let g=s.map(B=>ht(B[p],r));c.push(`${e.dim(F(p))} ${e.dim("\u2502")} ${g.join("")}`)}let f="\u2500".repeat(Math.min(u-9,r*n.length));c.push(`${" ".repeat(7)} ${e.dim("\u2514")}${e.dim(f)}`);let d=n[0]?.label??"",l=Math.max(1,Math.ceil((d.length+1)/r)),C=n.map((p,g)=>{if(g%l!==0)return" ".repeat(r);let B=r*Math.min(l,n.length-g);return ht(p.label,B)}),h="";for(let p=0;p<C.length;p+=1)p%l===0&&(h+=C[p]);return c.push(`${" ".repeat(8)} ${e.dim(h)}`),c.push(""),c.push(`${" ".repeat(8)}${e.input(I.circleFilled)} input ${e.cacheWrite(I.circleFilled)} cache-write ${e.cacheRead(I.circleFilled)} cache-read ${e.output(I.circleFilled)} output`),c}function ic(e,u,t){let n=t.breakdown.slice(0,8),D=Math.floor((u-2)/2),r=Mr(e,D,`Top ${t.by}s by cost`,n,"cost",t.totals.cost),o=Mr(e,D,`Top ${t.by}s by conversations`,n.slice().sort((i,s)=>s.turns-i.turns).slice(0,8),"turns",Math.max(1,...n.map(i=>i.turns)));return Lr([r,o],2).split(`
30
+ `)}function Mr(e,u,t,n,D,r){let o=`${e.brand(I.pointerSmall)} ${e.bold(t)}`;if(n.length===0)return[o,e.dim(" (no data in this window)")].join(`
31
+ `);let i=new Pr.default({head:[e.dim("#"),e.dim("Item"),e.dim("Conv"),e.dim("Reqs"),e.dim("Tokens"),e.dim("Cost")],style:{head:[],border:["gray"],"padding-left":1,"padding-right":1},chars:{top:"\u2500","top-mid":"\u252C","top-left":"\u256D","top-right":"\u256E",bottom:"\u2500","bottom-mid":"\u2534","bottom-left":"\u2570","bottom-right":"\u256F",left:"\u2502","left-mid":"\u251C",mid:"\u2500","mid-mid":"\u253C",right:"\u2502","right-mid":"\u2524",middle:"\u2502"},wordWrap:!1,colAligns:["right","left","right","right","right","right"]});return n.forEach((s,a)=>{let F=me(s.label,Math.max(8,u-40)),c=D==="cost"?s.cost/Math.max(1e-9,r):s.turns/Math.max(1e-9,r),f=Math.max(8,Math.min(24,u-40)),d=Cu(c,f,e.brand);i.push([String(a+1),`${F}
32
+ ${d}`,s.turns.toLocaleString(),s.requests.toLocaleString(),v(s.tokens),N(s.cost)])}),[o,"",i.toString()].join(`
33
+ `)}function sc(e,u,t){let n=_r(t,{source:"all"}),D=n.heatmap,r=n.heatmapMax;if(r===0)return[`${e.brand(I.pointerSmall)} ${e.bold("Activity heatmap")}`,"",e.dim(" (no activity yet \u2014 start a session and re-run)")];let o=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],i=c=>{if(c===0)return e.dim("\xB7");let f=c/r;return f<.2?e.input("\u2591"):f<.4?e.input("\u2592"):f<.6?e.cacheRead("\u2592"):f<.8?e.cacheRead("\u2593"):e.output("\u2588")},s=`${e.brand(I.pointerSmall)} ${e.bold("Activity heatmap")} ${e.dim("(local time, day-of-week \xD7 hour)")}`,a=" "+Array.from({length:24},(c,f)=>Ee(String(f),2)).join(" "),F=[s,"",e.dim(a)];for(let c=0;c<7;c+=1){let f=(c+1)%7,l=(D[f]??new Array(24).fill(0)).map(C=>Ee(i(C),2)).join(" ");F.push(`${e.dim(hu(o[c],4))} ${l}`)}return F}function ac(e,u,t,n){let D=[];if(n.model&&D.push(`model~${n.model}`),n.project&&D.push(`project~${n.project}`),t.fromIso||t.untilIso){let o=`${t.fromIso?.slice(0,10)??"\u2026"} \u2192 ${t.untilIso?.slice(0,10)??"\u2026"}`;D.push(o)}let r=[`range: ${t.range}`,`source: ${t.source}`,`scope: ${u.length.toLocaleString()} records \xB7 ${t.totals.turns.toLocaleString()} conversations`];return D.length>0&&r.push(`filters: ${D.join(", ")}`),[e.dim(r.join(` ${I.bullet} `)),e.dim(`${I.info} Use ${e.cyan("`ccgauge report`")} for a CI-friendly text summary, or ${e.cyan("`ccgauge report -d --json`")} to pipe.`)]}var mt=["today","1d","7d","30d","90d","all"],Ur=["model","project","session"],cc=/^(\d{4})-(\d{2})-(\d{2})$/,lc={range:"7d",source:"all",by:"model",gran:"day",limit:10,json:!1,color:!0,showTrend:!0,showBreakdown:!0,dashboard:!1,compact:!1,banner:!0};async function rd(e){let u=dc(e),t=await Vt(),n=u.source==="all"?Au:[u.source],D=hc(t,n,u);if(u.json)return JSON.stringify(D,null,2);if(u.dashboard){let r=Fc(t,n,u);return Or(t,D,u,r)}return Ct(D,u)}function Fc(e,u,t){let n=Et(t),D=n.from?.toISOString(),r=n.until?.toISOString(),o=new Set(u),i=t.model?.toLowerCase(),s=t.project?.toLowerCase();return e.records.filter(a=>{if(!o.has(a.source)||D&&a.timestamp<D||r&&a.timestamp>r||i&&!a.model.toLowerCase().includes(i))return!1;if(s){let F=(a.cwd||"").toLowerCase(),c=F.split(/[/\\]+/).pop()??"";if(!F.includes(s)&&!c.includes(s))return!1}return!0})}function dc(e){let u={...lc,...e};if(!fc(u.range))throw new Error(je("range",u.range,mt));if(u.source!=="all"&&!Ot(u.source))throw new Error(je("source",u.source,["claude","codex","all"]));if(!pc(u.by))throw new Error(je("by",u.by,Ur));if(!Zt(u.gran))throw new Error(je("gran",u.gran,["hour","day","week","month"]));u.since&&mu(u.since,"since"),u.until&&mu(u.until,"until");let t=Et(u);if(t.from&&t.until&&t.from.getTime()>t.until.getTime())throw new Error("invalid date range: --since must be before or equal to --until");return u}function fc(e){return typeof e=="string"&&mt.includes(e)}function pc(e){return typeof e=="string"&&Ur.includes(e)}function je(e,u,t){return`invalid ${e}: ${JSON.stringify(u)}. Expected one of: ${t.join(", ")}`}function hc(e,u,t){let n=e.records,D=Et(t),r={from:D.from??void 0,to:D.until??void 0},o={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0,cost:0,saved:0,requests:0,turns:0},i=new Map;for(let F of u){let c={...r,source:F},f=n.filter(p=>gu(p,c,t)),d=nn(f,c);o.input+=d.inputTokens,o.output+=d.outputTokens,o.cacheRead+=d.cacheReadTokens,o.cacheWrite+=d.cacheCreationTokens,o.total+=d.totalTokens,o.cost+=d.cost,o.saved+=d.saved,o.requests+=d.requests;for(let p of f)o.reasoning+=p.usage.reasoning_tokens??0;let l=Re(f,e.userRecords,e.parentMap);o.turns+=l.size;let C=new Map;for(let p of l.values()){let{key:g}=ku(p.firstTimestamp,t.gran);C.set(g,(C.get(g)??0)+1)}let h=Qt(f,t.gran,c);for(let p of h){let g=i.get(p.key),B=C.get(p.key)??0;g?(g.cost+=p.cost,g.tokens+=p.totalTokens,g.turns+=B,g.input+=p.inputTokens,g.output+=p.outputTokens,g.cacheRead+=p.cacheReadTokens,g.cacheWrite+=p.cacheCreationTokens):i.set(p.key,{label:p.label,cost:p.cost,tokens:p.totalTokens,turns:B,input:p.inputTokens,output:p.outputTokens,cacheRead:p.cacheReadTokens,cacheWrite:p.cacheCreationTokens})}}let s=Array.from(i.entries()).sort(([F],[c])=>F.localeCompare(c)).map(([,F])=>F),a=Cc(e,u,r,t);return{generatedAt:new Date().toISOString(),range:t.range,source:t.source,by:t.by,gran:t.gran,fromIso:D.from?.toISOString()??null,untilIso:D.until?.toISOString()??null,totals:o,trend:s,breakdown:a}}function Cc(e,u,t,n){let D=e.records;if(n.by==="model"){let o=[];for(let i of u){let s={...t,source:i},a=D.filter(d=>gu(d,s,n)),F=en(a,s),c=re(i),f=new Map;for(let d of Re(a,e.userRecords,e.parentMap).values())f.set(d.firstModel,(f.get(d.firstModel)??0)+1);for(let d of F)o.push({key:`${i}::${d.model}`,label:c.shortenModel(d.model),requests:d.requests,turns:f.get(d.model)??0,tokens:d.totalTokens,cost:d.cost,share:0,sub:d.model})}return gt(o,n.limit)}if(n.by==="project"){let o=[];for(let i of u){let s={...t,source:i},a=D.filter(f=>gu(f,s,n)),F=un(a,s),c=new Map;for(let f of Re(a,e.userRecords,e.parentMap).values()){let d=f.cwd||"(unknown)";c.set(d,(c.get(d)??0)+1)}for(let f of F)o.push({key:`${i}::${f.cwd}`,label:f.projectName,requests:f.requests,turns:c.get(f.cwd)??0,tokens:f.totalTokens,cost:f.cost,share:0,sub:f.cwd})}return gt(o,n.limit)}let r=[];for(let o of u){let i={...t,source:o},s=D.filter(c=>gu(c,i,n)),a=tn(s,[],i),F=new Map;for(let c of Re(s,e.userRecords,e.parentMap).values())F.set(c.sessionId,(F.get(c.sessionId)??0)+1);for(let c of a)r.push({key:`${o}::${c.sessionId}`,label:c.title??c.sessionId.slice(0,8),requests:c.requests,turns:F.get(c.sessionId)??0,tokens:c.totalTokens,cost:c.cost,share:0,sub:c.projectLabel})}return gt(r,n.limit)}function gt(e,u){let t=e.reduce((D,r)=>D+r.cost,0);e.sort((D,r)=>r.cost-D.cost);let n=e.slice(0,Math.max(1,u));if(t>0)for(let D of n)D.share=D.cost/t;return n}function gu(e,u,t){if(e.source!==u.source||u.from&&e.timestamp<u.from.toISOString()||u.to&&e.timestamp>u.to.toISOString()||t.model&&!e.model.toLowerCase().includes(t.model.toLowerCase()))return!1;if(t.project){let n=t.project.toLowerCase(),D=(e.cwd||"").toLowerCase(),r=D.split(/[/\\]+/).pop()??"";if(!D.includes(n)&&!r.includes(n))return!1}return!0}function Et(e){if(e.since||e.until)return{from:e.since?mu(e.since,"since"):null,until:e.until?mu(e.until,"until"):null};let u=e.range==="today"?"1d":e.range;if(!Dn(u))throw new Error(je("range",e.range,mt));let t=rn(u);return{from:t.from??null,until:t.to??null}}function mu(e,u){let t=e.match(cc);if(t){let D=Number(t[1]),r=Number(t[2]),o=Number(t[3]),i=u==="since"?new Date(D,r-1,o,0,0,0,0):new Date(D,r-1,o,23,59,59,999);if(i.getFullYear()!==D||i.getMonth()!==r-1||i.getDate()!==o)throw new Error(`invalid ${u} date: ${e}`);return i}let n=new Date(e);if(Number.isNaN(n.getTime()))throw new Error(`invalid ${u} date: ${e}`);return n}function gc(e){let u=t=>n=>e?`\x1B[${t}m${n}\x1B[0m`:String(n);return{bold:u("1"),dim:u("2"),cyan:u("36"),green:u("32"),yellow:u("33"),red:u("31"),blue:u("34"),magenta:u("35"),brand:u("38;2;129;140;248")}}function Ct(e,u){let t=gc(u.color!==!1),n=[],D=new Date(e.generatedAt).toLocaleString();n.push(""),n.push(`${t.brand(t.bold("ccgauge"))} ${t.bold("report")}`),n.push(t.dim([`range: ${e.range}`,`source: ${e.source}`,`by: ${e.by}`,`gran: ${e.gran}`,`generated ${D}`].join(" \xB7 "))),n.push(""),n.push(t.brand("\u25B8")+" "+t.bold("Tokens"));let r=e.totals,o=[["Input",v(r.input),"Output",v(r.output)],["Cache R",t.green(v(r.cacheRead)),"Cache W",v(r.cacheWrite)]];r.reasoning>0&&o.push(["Reasoning",t.dim(v(r.reasoning)),"",""]),o.push(["Total",t.bold(v(r.total)),"",""]),o.push(["Convos",t.bold(r.turns.toLocaleString()),"Requests",r.requests.toLocaleString()]),n.push(Nr(o,t)),n.push(""),n.push(t.brand("\u25B8")+" "+t.bold("Cost"));let i=r.input+r.cacheRead+r.cacheWrite,s=i>0?r.cacheRead/i:0,a=r.requests>0?r.cost/r.requests:0,F=[["Total",t.bold(N(r.cost)),"Saved by cache",t.green(N(r.saved))],["Avg / request",a<.01?`$${a.toFixed(4)}`:N(a),"Cache hit",t.green(de(s,1))]];if(n.push(Nr(F,t)),n.push(""),u.showTrend!==!1&&e.trend.length>0){n.push(t.brand("\u25B8")+" "+t.bold("Trend")+" "+t.dim(`(${u.gran}, by cost)`));let c=Math.max(...e.trend.map(l=>l.cost),1e-9),f=Math.max(...e.trend.map(l=>l.label.length)),d=Math.max(...e.trend.map(l=>N(l.cost).length));for(let l of e.trend){let C=Ec(l.cost/c,44),h=l.label.padEnd(f),p=N(l.cost).padStart(d);n.push(` ${t.dim(h)} ${p} ${t.brand(C)}`)}n.push("")}if(u.showBreakdown!==!1&&e.breakdown.length>0){let c=e.by[0].toUpperCase()+e.by.slice(1);n.push(t.brand("\u25B8")+" "+t.bold(`Top ${e.breakdown.length} ${c}s`)+" "+t.dim("(by cost)"));let f=["#",c,"Convos","Reqs","Tokens","Cost","Share"],d=e.breakdown.map((l,C)=>[String(C+1),Ac(l.label,28),l.turns.toLocaleString(),l.requests.toLocaleString(),v(l.tokens),N(l.cost),de(l.share,1)]);n.push(mc(f,d,t,[!1,!1,!0,!0,!0,!0,!0])),n.push("")}return n.join(`
34
+ `)}function Nr(e,u){let t=[0,0,0,0];for(let D of e)for(let r=0;r<4;r+=1){let o=D[r];qe(o)>t[r]&&(t[r]=qe(o))}let n=[];for(let[D,r,o,i]of e){let s=`${u.dim(Ge(D,t[0]))} ${Ge(r,t[1])}`,a=o?`${u.dim(Ge(o,t[2]))} ${i}`:"";n.push(` ${s} ${a}`.replace(/\s+$/,""))}return n.join(`
35
+ `)}function mc(e,u,t,n){let D=e.map((s,a)=>Math.max(s.length,...u.map(F=>qe(F[a]??"")))),r=" "+e.map((s,a)=>n[a]?$r(s,D[a]):Ge(s,D[a])).map(s=>t.dim(s)).join(" "),o=" "+D.map(s=>"\u2500".repeat(s)).map(s=>t.dim(s)).join(" "),i=u.map(s=>" "+s.map((a,F)=>n[F]?$r(a,D[F]):Ge(a,D[F])).join(" "));return[r,o,...i].join(`
36
+ `)}function Ec(e,u){let t=Math.max(0,Math.min(1,e)),n=Math.round(t*u);return"\u2587".repeat(n)+"\u2500".repeat(u-n)}var Bc="\x1B",bc=new RegExp(Bc+"\\[[0-9;]*m","g");function qe(e){return e.replace(bc,"").length}function Ge(e,u){return e+" ".repeat(Math.max(0,u-qe(e)))}function $r(e,u){return" ".repeat(Math.max(0,u-qe(e)))+e}function Ac(e,u){return e.length<=u?e:e.slice(0,u-1)+"\u2026"}export{lc as DEFAULT_REPORT,Fc as filterRecordsForReport,Ct as renderText,rd as runReport};