@carboncode/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSES/DeepSeek-Reasonix-MIT.txt +21 -0
  3. package/README.md +109 -0
  4. package/README.zh-CN.md +91 -0
  5. package/THIRD_PARTY_NOTICES.md +14 -0
  6. package/dashboard/app.css +3233 -0
  7. package/dashboard/dist/app.js +30444 -0
  8. package/dashboard/dist/app.js.map +1 -0
  9. package/dashboard/dist/vendor-hljs.css +10 -0
  10. package/dashboard/dist/vendor-uplot.css +1 -0
  11. package/dashboard/index.html +19 -0
  12. package/data/deepseek-tokenizer.json.gz +0 -0
  13. package/dist/cli/acp-35C4ME6Y.js +711 -0
  14. package/dist/cli/acp-35C4ME6Y.js.map +1 -0
  15. package/dist/cli/chat-A6UJDPGV.js +51 -0
  16. package/dist/cli/chat-A6UJDPGV.js.map +1 -0
  17. package/dist/cli/chunk-2425HK6U.js +54 -0
  18. package/dist/cli/chunk-2425HK6U.js.map +1 -0
  19. package/dist/cli/chunk-25T6CVUP.js +172 -0
  20. package/dist/cli/chunk-25T6CVUP.js.map +1 -0
  21. package/dist/cli/chunk-2UQP6H6T.js +31 -0
  22. package/dist/cli/chunk-2UQP6H6T.js.map +1 -0
  23. package/dist/cli/chunk-3OAR6NVL.js +96 -0
  24. package/dist/cli/chunk-3OAR6NVL.js.map +1 -0
  25. package/dist/cli/chunk-3T6VBZCL.js +54 -0
  26. package/dist/cli/chunk-3T6VBZCL.js.map +1 -0
  27. package/dist/cli/chunk-4IBIPQVB.js +153 -0
  28. package/dist/cli/chunk-4IBIPQVB.js.map +1 -0
  29. package/dist/cli/chunk-4MQ3VURH.js +3106 -0
  30. package/dist/cli/chunk-4MQ3VURH.js.map +1 -0
  31. package/dist/cli/chunk-4TVNJWMA.js +11619 -0
  32. package/dist/cli/chunk-4TVNJWMA.js.map +1 -0
  33. package/dist/cli/chunk-4VR6XF4P.js +341 -0
  34. package/dist/cli/chunk-4VR6XF4P.js.map +1 -0
  35. package/dist/cli/chunk-5QCB62C4.js +25319 -0
  36. package/dist/cli/chunk-5QCB62C4.js.map +1 -0
  37. package/dist/cli/chunk-6OWJV3YW.js +390 -0
  38. package/dist/cli/chunk-6OWJV3YW.js.map +1 -0
  39. package/dist/cli/chunk-7EO27TB3.js +130 -0
  40. package/dist/cli/chunk-7EO27TB3.js.map +1 -0
  41. package/dist/cli/chunk-7L2WTRNU.js +308 -0
  42. package/dist/cli/chunk-7L2WTRNU.js.map +1 -0
  43. package/dist/cli/chunk-BHTZFEYE.js +47 -0
  44. package/dist/cli/chunk-BHTZFEYE.js.map +1 -0
  45. package/dist/cli/chunk-BSGCXZQN.js +343 -0
  46. package/dist/cli/chunk-BSGCXZQN.js.map +1 -0
  47. package/dist/cli/chunk-BSINVTTL.js +464 -0
  48. package/dist/cli/chunk-BSINVTTL.js.map +1 -0
  49. package/dist/cli/chunk-CPKCNHRR.js +323 -0
  50. package/dist/cli/chunk-CPKCNHRR.js.map +1 -0
  51. package/dist/cli/chunk-CXVWUPA3.js +96 -0
  52. package/dist/cli/chunk-CXVWUPA3.js.map +1 -0
  53. package/dist/cli/chunk-D5NFKRGO.js +160 -0
  54. package/dist/cli/chunk-D5NFKRGO.js.map +1 -0
  55. package/dist/cli/chunk-ECHSFYOY.js +109 -0
  56. package/dist/cli/chunk-ECHSFYOY.js.map +1 -0
  57. package/dist/cli/chunk-FEZK652I.js +3644 -0
  58. package/dist/cli/chunk-FEZK652I.js.map +1 -0
  59. package/dist/cli/chunk-GALC45Q2.js +696 -0
  60. package/dist/cli/chunk-GALC45Q2.js.map +1 -0
  61. package/dist/cli/chunk-IAUOP25G.js +2984 -0
  62. package/dist/cli/chunk-IAUOP25G.js.map +1 -0
  63. package/dist/cli/chunk-ILJOIQ5W.js +163 -0
  64. package/dist/cli/chunk-ILJOIQ5W.js.map +1 -0
  65. package/dist/cli/chunk-IX6XI2RG.js +225 -0
  66. package/dist/cli/chunk-IX6XI2RG.js.map +1 -0
  67. package/dist/cli/chunk-J5BYPUB5.js +62795 -0
  68. package/dist/cli/chunk-J5BYPUB5.js.map +1 -0
  69. package/dist/cli/chunk-J5XJHLWM.js +55 -0
  70. package/dist/cli/chunk-J5XJHLWM.js.map +1 -0
  71. package/dist/cli/chunk-JKGYMRX5.js +101 -0
  72. package/dist/cli/chunk-JKGYMRX5.js.map +1 -0
  73. package/dist/cli/chunk-JMBMLOBP.js +26 -0
  74. package/dist/cli/chunk-JMBMLOBP.js.map +1 -0
  75. package/dist/cli/chunk-LN3B5PMX.js +128 -0
  76. package/dist/cli/chunk-LN3B5PMX.js.map +1 -0
  77. package/dist/cli/chunk-M2UFZUX3.js +635 -0
  78. package/dist/cli/chunk-M2UFZUX3.js.map +1 -0
  79. package/dist/cli/chunk-PJS34556.js +809 -0
  80. package/dist/cli/chunk-PJS34556.js.map +1 -0
  81. package/dist/cli/chunk-QJG7OF27.js +655 -0
  82. package/dist/cli/chunk-QJG7OF27.js.map +1 -0
  83. package/dist/cli/chunk-QVC75MR3.js +232 -0
  84. package/dist/cli/chunk-QVC75MR3.js.map +1 -0
  85. package/dist/cli/chunk-S2KIUQKQ.js +378 -0
  86. package/dist/cli/chunk-S2KIUQKQ.js.map +1 -0
  87. package/dist/cli/chunk-S4XVGLRW.js +499 -0
  88. package/dist/cli/chunk-S4XVGLRW.js.map +1 -0
  89. package/dist/cli/chunk-T5TQ4NDT.js +190 -0
  90. package/dist/cli/chunk-T5TQ4NDT.js.map +1 -0
  91. package/dist/cli/chunk-TH756VLN.js +1924 -0
  92. package/dist/cli/chunk-TH756VLN.js.map +1 -0
  93. package/dist/cli/chunk-TUK7OWJA.js +51 -0
  94. package/dist/cli/chunk-TUK7OWJA.js.map +1 -0
  95. package/dist/cli/chunk-U4IJVG32.js +363 -0
  96. package/dist/cli/chunk-U4IJVG32.js.map +1 -0
  97. package/dist/cli/chunk-UI66BH6D.js +624 -0
  98. package/dist/cli/chunk-UI66BH6D.js.map +1 -0
  99. package/dist/cli/chunk-VPMBGAND.js +53 -0
  100. package/dist/cli/chunk-VPMBGAND.js.map +1 -0
  101. package/dist/cli/chunk-WLHH3OSR.js +522 -0
  102. package/dist/cli/chunk-WLHH3OSR.js.map +1 -0
  103. package/dist/cli/chunk-WRN65TRD.js +908 -0
  104. package/dist/cli/chunk-WRN65TRD.js.map +1 -0
  105. package/dist/cli/chunk-X53B3JIX.js +34320 -0
  106. package/dist/cli/chunk-X53B3JIX.js.map +1 -0
  107. package/dist/cli/chunk-XJ5SRLKK.js +50 -0
  108. package/dist/cli/chunk-XJ5SRLKK.js.map +1 -0
  109. package/dist/cli/chunk-YZSXRGFH.js +54 -0
  110. package/dist/cli/chunk-YZSXRGFH.js.map +1 -0
  111. package/dist/cli/code-4TUTAGO5.js +163 -0
  112. package/dist/cli/code-4TUTAGO5.js.map +1 -0
  113. package/dist/cli/commands-KMOZEYCF.js +356 -0
  114. package/dist/cli/commands-KMOZEYCF.js.map +1 -0
  115. package/dist/cli/commit-DTFA56VQ.js +292 -0
  116. package/dist/cli/commit-DTFA56VQ.js.map +1 -0
  117. package/dist/cli/desktop-7N3MHNBD.js +1274 -0
  118. package/dist/cli/desktop-7N3MHNBD.js.map +1 -0
  119. package/dist/cli/devtools-HW3WDT3Q.js +91 -0
  120. package/dist/cli/devtools-HW3WDT3Q.js.map +1 -0
  121. package/dist/cli/diff-E5OWTF4C.js +165 -0
  122. package/dist/cli/diff-E5OWTF4C.js.map +1 -0
  123. package/dist/cli/doctor-IEJQRJMN.js +27 -0
  124. package/dist/cli/doctor-IEJQRJMN.js.map +1 -0
  125. package/dist/cli/events-4625EGXI.js +340 -0
  126. package/dist/cli/events-4625EGXI.js.map +1 -0
  127. package/dist/cli/index.js +3536 -0
  128. package/dist/cli/index.js.map +1 -0
  129. package/dist/cli/mcp-PDI2PDLG.js +277 -0
  130. package/dist/cli/mcp-PDI2PDLG.js.map +1 -0
  131. package/dist/cli/mcp-browse-OSPXOFPZ.js +178 -0
  132. package/dist/cli/mcp-browse-OSPXOFPZ.js.map +1 -0
  133. package/dist/cli/mcp-inspect-QRFVTHMF.js +148 -0
  134. package/dist/cli/mcp-inspect-QRFVTHMF.js.map +1 -0
  135. package/dist/cli/package.json +3 -0
  136. package/dist/cli/prompt-3CDII3UO.js +16 -0
  137. package/dist/cli/prompt-3CDII3UO.js.map +1 -0
  138. package/dist/cli/prune-sessions-KZX4SXKW.js +44 -0
  139. package/dist/cli/prune-sessions-KZX4SXKW.js.map +1 -0
  140. package/dist/cli/replay-HYOSRQIV.js +291 -0
  141. package/dist/cli/replay-HYOSRQIV.js.map +1 -0
  142. package/dist/cli/run-2ZHADOUP.js +220 -0
  143. package/dist/cli/run-2ZHADOUP.js.map +1 -0
  144. package/dist/cli/server-X75PAZG5.js +3572 -0
  145. package/dist/cli/server-X75PAZG5.js.map +1 -0
  146. package/dist/cli/sessions-POOZA5CQ.js +120 -0
  147. package/dist/cli/sessions-POOZA5CQ.js.map +1 -0
  148. package/dist/cli/setup-YLPFI3OH.js +618 -0
  149. package/dist/cli/setup-YLPFI3OH.js.map +1 -0
  150. package/dist/cli/stats-NXJ3TO2D.js +16 -0
  151. package/dist/cli/stats-NXJ3TO2D.js.map +1 -0
  152. package/dist/cli/update-ZUO5MKQ6.js +15 -0
  153. package/dist/cli/update-ZUO5MKQ6.js.map +1 -0
  154. package/dist/cli/version-NXXWE3WN.js +33 -0
  155. package/dist/cli/version-NXXWE3WN.js.map +1 -0
  156. package/dist/index.d.ts +2523 -0
  157. package/dist/index.js +15408 -0
  158. package/dist/index.js.map +1 -0
  159. package/package.json +112 -0
@@ -0,0 +1,3106 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __cr } from 'node:module'; if (typeof globalThis.require === 'undefined') { globalThis.require = __cr(import.meta.url); }
3
+ import {
4
+ __commonJS,
5
+ __toESM
6
+ } from "./chunk-TUK7OWJA.js";
7
+
8
+ // node_modules/picomatch/lib/constants.js
9
+ var require_constants = __commonJS({
10
+ "node_modules/picomatch/lib/constants.js"(exports, module) {
11
+ "use strict";
12
+ var WIN_SLASH = "\\\\/";
13
+ var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
14
+ var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
15
+ var DOT_LITERAL = "\\.";
16
+ var PLUS_LITERAL = "\\+";
17
+ var QMARK_LITERAL = "\\?";
18
+ var SLASH_LITERAL = "\\/";
19
+ var ONE_CHAR = "(?=.)";
20
+ var QMARK = "[^/]";
21
+ var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
22
+ var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
23
+ var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
24
+ var NO_DOT = `(?!${DOT_LITERAL})`;
25
+ var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
26
+ var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
27
+ var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
28
+ var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
29
+ var STAR = `${QMARK}*?`;
30
+ var SEP = "/";
31
+ var POSIX_CHARS = {
32
+ DOT_LITERAL,
33
+ PLUS_LITERAL,
34
+ QMARK_LITERAL,
35
+ SLASH_LITERAL,
36
+ ONE_CHAR,
37
+ QMARK,
38
+ END_ANCHOR,
39
+ DOTS_SLASH,
40
+ NO_DOT,
41
+ NO_DOTS,
42
+ NO_DOT_SLASH,
43
+ NO_DOTS_SLASH,
44
+ QMARK_NO_DOT,
45
+ STAR,
46
+ START_ANCHOR,
47
+ SEP
48
+ };
49
+ var WINDOWS_CHARS = {
50
+ ...POSIX_CHARS,
51
+ SLASH_LITERAL: `[${WIN_SLASH}]`,
52
+ QMARK: WIN_NO_SLASH,
53
+ STAR: `${WIN_NO_SLASH}*?`,
54
+ DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
55
+ NO_DOT: `(?!${DOT_LITERAL})`,
56
+ NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
57
+ NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
58
+ NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
59
+ QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
60
+ START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
61
+ END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
62
+ SEP: "\\"
63
+ };
64
+ var POSIX_REGEX_SOURCE = {
65
+ __proto__: null,
66
+ alnum: "a-zA-Z0-9",
67
+ alpha: "a-zA-Z",
68
+ ascii: "\\x00-\\x7F",
69
+ blank: " \\t",
70
+ cntrl: "\\x00-\\x1F\\x7F",
71
+ digit: "0-9",
72
+ graph: "\\x21-\\x7E",
73
+ lower: "a-z",
74
+ print: "\\x20-\\x7E ",
75
+ punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
76
+ space: " \\t\\r\\n\\v\\f",
77
+ upper: "A-Z",
78
+ word: "A-Za-z0-9_",
79
+ xdigit: "A-Fa-f0-9"
80
+ };
81
+ module.exports = {
82
+ DEFAULT_MAX_EXTGLOB_RECURSION,
83
+ MAX_LENGTH: 1024 * 64,
84
+ POSIX_REGEX_SOURCE,
85
+ // regular expressions
86
+ REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
87
+ REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
88
+ REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
89
+ REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
90
+ REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
91
+ REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
92
+ // Replace globs with equivalent patterns to reduce parsing time.
93
+ REPLACEMENTS: {
94
+ __proto__: null,
95
+ "***": "*",
96
+ "**/**": "**",
97
+ "**/**/**": "**"
98
+ },
99
+ // Digits
100
+ CHAR_0: 48,
101
+ /* 0 */
102
+ CHAR_9: 57,
103
+ /* 9 */
104
+ // Alphabet chars.
105
+ CHAR_UPPERCASE_A: 65,
106
+ /* A */
107
+ CHAR_LOWERCASE_A: 97,
108
+ /* a */
109
+ CHAR_UPPERCASE_Z: 90,
110
+ /* Z */
111
+ CHAR_LOWERCASE_Z: 122,
112
+ /* z */
113
+ CHAR_LEFT_PARENTHESES: 40,
114
+ /* ( */
115
+ CHAR_RIGHT_PARENTHESES: 41,
116
+ /* ) */
117
+ CHAR_ASTERISK: 42,
118
+ /* * */
119
+ // Non-alphabetic chars.
120
+ CHAR_AMPERSAND: 38,
121
+ /* & */
122
+ CHAR_AT: 64,
123
+ /* @ */
124
+ CHAR_BACKWARD_SLASH: 92,
125
+ /* \ */
126
+ CHAR_CARRIAGE_RETURN: 13,
127
+ /* \r */
128
+ CHAR_CIRCUMFLEX_ACCENT: 94,
129
+ /* ^ */
130
+ CHAR_COLON: 58,
131
+ /* : */
132
+ CHAR_COMMA: 44,
133
+ /* , */
134
+ CHAR_DOT: 46,
135
+ /* . */
136
+ CHAR_DOUBLE_QUOTE: 34,
137
+ /* " */
138
+ CHAR_EQUAL: 61,
139
+ /* = */
140
+ CHAR_EXCLAMATION_MARK: 33,
141
+ /* ! */
142
+ CHAR_FORM_FEED: 12,
143
+ /* \f */
144
+ CHAR_FORWARD_SLASH: 47,
145
+ /* / */
146
+ CHAR_GRAVE_ACCENT: 96,
147
+ /* ` */
148
+ CHAR_HASH: 35,
149
+ /* # */
150
+ CHAR_HYPHEN_MINUS: 45,
151
+ /* - */
152
+ CHAR_LEFT_ANGLE_BRACKET: 60,
153
+ /* < */
154
+ CHAR_LEFT_CURLY_BRACE: 123,
155
+ /* { */
156
+ CHAR_LEFT_SQUARE_BRACKET: 91,
157
+ /* [ */
158
+ CHAR_LINE_FEED: 10,
159
+ /* \n */
160
+ CHAR_NO_BREAK_SPACE: 160,
161
+ /* \u00A0 */
162
+ CHAR_PERCENT: 37,
163
+ /* % */
164
+ CHAR_PLUS: 43,
165
+ /* + */
166
+ CHAR_QUESTION_MARK: 63,
167
+ /* ? */
168
+ CHAR_RIGHT_ANGLE_BRACKET: 62,
169
+ /* > */
170
+ CHAR_RIGHT_CURLY_BRACE: 125,
171
+ /* } */
172
+ CHAR_RIGHT_SQUARE_BRACKET: 93,
173
+ /* ] */
174
+ CHAR_SEMICOLON: 59,
175
+ /* ; */
176
+ CHAR_SINGLE_QUOTE: 39,
177
+ /* ' */
178
+ CHAR_SPACE: 32,
179
+ /* */
180
+ CHAR_TAB: 9,
181
+ /* \t */
182
+ CHAR_UNDERSCORE: 95,
183
+ /* _ */
184
+ CHAR_VERTICAL_LINE: 124,
185
+ /* | */
186
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
187
+ /* \uFEFF */
188
+ /**
189
+ * Create EXTGLOB_CHARS
190
+ */
191
+ extglobChars(chars) {
192
+ return {
193
+ "!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
194
+ "?": { type: "qmark", open: "(?:", close: ")?" },
195
+ "+": { type: "plus", open: "(?:", close: ")+" },
196
+ "*": { type: "star", open: "(?:", close: ")*" },
197
+ "@": { type: "at", open: "(?:", close: ")" }
198
+ };
199
+ },
200
+ /**
201
+ * Create GLOB_CHARS
202
+ */
203
+ globChars(win32) {
204
+ return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
205
+ }
206
+ };
207
+ }
208
+ });
209
+
210
+ // node_modules/picomatch/lib/utils.js
211
+ var require_utils = __commonJS({
212
+ "node_modules/picomatch/lib/utils.js"(exports) {
213
+ "use strict";
214
+ var {
215
+ REGEX_BACKSLASH,
216
+ REGEX_REMOVE_BACKSLASH,
217
+ REGEX_SPECIAL_CHARS,
218
+ REGEX_SPECIAL_CHARS_GLOBAL
219
+ } = require_constants();
220
+ exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
221
+ exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
222
+ exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
223
+ exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
224
+ exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
225
+ exports.isWindows = () => {
226
+ if (typeof navigator !== "undefined" && navigator.platform) {
227
+ const platform = navigator.platform.toLowerCase();
228
+ return platform === "win32" || platform === "windows";
229
+ }
230
+ if (typeof process !== "undefined" && process.platform) {
231
+ return process.platform === "win32";
232
+ }
233
+ return false;
234
+ };
235
+ exports.removeBackslashes = (str) => {
236
+ return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
237
+ return match === "\\" ? "" : match;
238
+ });
239
+ };
240
+ exports.escapeLast = (input, char, lastIdx) => {
241
+ const idx = input.lastIndexOf(char, lastIdx);
242
+ if (idx === -1) return input;
243
+ if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
244
+ return `${input.slice(0, idx)}\\${input.slice(idx)}`;
245
+ };
246
+ exports.removePrefix = (input, state = {}) => {
247
+ let output = input;
248
+ if (output.startsWith("./")) {
249
+ output = output.slice(2);
250
+ state.prefix = "./";
251
+ }
252
+ return output;
253
+ };
254
+ exports.wrapOutput = (input, state = {}, options = {}) => {
255
+ const prepend = options.contains ? "" : "^";
256
+ const append = options.contains ? "" : "$";
257
+ let output = `${prepend}(?:${input})${append}`;
258
+ if (state.negated === true) {
259
+ output = `(?:^(?!${output}).*$)`;
260
+ }
261
+ return output;
262
+ };
263
+ exports.basename = (path, { windows } = {}) => {
264
+ const segs = path.split(windows ? /[\\/]/ : "/");
265
+ const last = segs[segs.length - 1];
266
+ if (last === "") {
267
+ return segs[segs.length - 2];
268
+ }
269
+ return last;
270
+ };
271
+ }
272
+ });
273
+
274
+ // node_modules/picomatch/lib/scan.js
275
+ var require_scan = __commonJS({
276
+ "node_modules/picomatch/lib/scan.js"(exports, module) {
277
+ "use strict";
278
+ var utils = require_utils();
279
+ var {
280
+ CHAR_ASTERISK,
281
+ /* * */
282
+ CHAR_AT,
283
+ /* @ */
284
+ CHAR_BACKWARD_SLASH,
285
+ /* \ */
286
+ CHAR_COMMA,
287
+ /* , */
288
+ CHAR_DOT,
289
+ /* . */
290
+ CHAR_EXCLAMATION_MARK,
291
+ /* ! */
292
+ CHAR_FORWARD_SLASH,
293
+ /* / */
294
+ CHAR_LEFT_CURLY_BRACE,
295
+ /* { */
296
+ CHAR_LEFT_PARENTHESES,
297
+ /* ( */
298
+ CHAR_LEFT_SQUARE_BRACKET,
299
+ /* [ */
300
+ CHAR_PLUS,
301
+ /* + */
302
+ CHAR_QUESTION_MARK,
303
+ /* ? */
304
+ CHAR_RIGHT_CURLY_BRACE,
305
+ /* } */
306
+ CHAR_RIGHT_PARENTHESES,
307
+ /* ) */
308
+ CHAR_RIGHT_SQUARE_BRACKET
309
+ /* ] */
310
+ } = require_constants();
311
+ var isPathSeparator = (code) => {
312
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
313
+ };
314
+ var depth = (token) => {
315
+ if (token.isPrefix !== true) {
316
+ token.depth = token.isGlobstar ? Infinity : 1;
317
+ }
318
+ };
319
+ var scan = (input, options) => {
320
+ const opts = options || {};
321
+ const length = input.length - 1;
322
+ const scanToEnd = opts.parts === true || opts.scanToEnd === true;
323
+ const slashes = [];
324
+ const tokens = [];
325
+ const parts = [];
326
+ let str = input;
327
+ let index = -1;
328
+ let start = 0;
329
+ let lastIndex = 0;
330
+ let isBrace = false;
331
+ let isBracket = false;
332
+ let isGlob = false;
333
+ let isExtglob = false;
334
+ let isGlobstar = false;
335
+ let braceEscaped = false;
336
+ let backslashes = false;
337
+ let negated = false;
338
+ let negatedExtglob = false;
339
+ let finished = false;
340
+ let braces = 0;
341
+ let prev;
342
+ let code;
343
+ let token = { value: "", depth: 0, isGlob: false };
344
+ const eos = () => index >= length;
345
+ const peek = () => str.charCodeAt(index + 1);
346
+ const advance = () => {
347
+ prev = code;
348
+ return str.charCodeAt(++index);
349
+ };
350
+ while (index < length) {
351
+ code = advance();
352
+ let next;
353
+ if (code === CHAR_BACKWARD_SLASH) {
354
+ backslashes = token.backslashes = true;
355
+ code = advance();
356
+ if (code === CHAR_LEFT_CURLY_BRACE) {
357
+ braceEscaped = true;
358
+ }
359
+ continue;
360
+ }
361
+ if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
362
+ braces++;
363
+ while (eos() !== true && (code = advance())) {
364
+ if (code === CHAR_BACKWARD_SLASH) {
365
+ backslashes = token.backslashes = true;
366
+ advance();
367
+ continue;
368
+ }
369
+ if (code === CHAR_LEFT_CURLY_BRACE) {
370
+ braces++;
371
+ continue;
372
+ }
373
+ if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
374
+ isBrace = token.isBrace = true;
375
+ isGlob = token.isGlob = true;
376
+ finished = true;
377
+ if (scanToEnd === true) {
378
+ continue;
379
+ }
380
+ break;
381
+ }
382
+ if (braceEscaped !== true && code === CHAR_COMMA) {
383
+ isBrace = token.isBrace = true;
384
+ isGlob = token.isGlob = true;
385
+ finished = true;
386
+ if (scanToEnd === true) {
387
+ continue;
388
+ }
389
+ break;
390
+ }
391
+ if (code === CHAR_RIGHT_CURLY_BRACE) {
392
+ braces--;
393
+ if (braces === 0) {
394
+ braceEscaped = false;
395
+ isBrace = token.isBrace = true;
396
+ finished = true;
397
+ break;
398
+ }
399
+ }
400
+ }
401
+ if (scanToEnd === true) {
402
+ continue;
403
+ }
404
+ break;
405
+ }
406
+ if (code === CHAR_FORWARD_SLASH) {
407
+ slashes.push(index);
408
+ tokens.push(token);
409
+ token = { value: "", depth: 0, isGlob: false };
410
+ if (finished === true) continue;
411
+ if (prev === CHAR_DOT && index === start + 1) {
412
+ start += 2;
413
+ continue;
414
+ }
415
+ lastIndex = index + 1;
416
+ continue;
417
+ }
418
+ if (opts.noext !== true) {
419
+ const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
420
+ if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
421
+ isGlob = token.isGlob = true;
422
+ isExtglob = token.isExtglob = true;
423
+ finished = true;
424
+ if (code === CHAR_EXCLAMATION_MARK && index === start) {
425
+ negatedExtglob = true;
426
+ }
427
+ if (scanToEnd === true) {
428
+ while (eos() !== true && (code = advance())) {
429
+ if (code === CHAR_BACKWARD_SLASH) {
430
+ backslashes = token.backslashes = true;
431
+ code = advance();
432
+ continue;
433
+ }
434
+ if (code === CHAR_RIGHT_PARENTHESES) {
435
+ isGlob = token.isGlob = true;
436
+ finished = true;
437
+ break;
438
+ }
439
+ }
440
+ continue;
441
+ }
442
+ break;
443
+ }
444
+ }
445
+ if (code === CHAR_ASTERISK) {
446
+ if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
447
+ isGlob = token.isGlob = true;
448
+ finished = true;
449
+ if (scanToEnd === true) {
450
+ continue;
451
+ }
452
+ break;
453
+ }
454
+ if (code === CHAR_QUESTION_MARK) {
455
+ isGlob = token.isGlob = true;
456
+ finished = true;
457
+ if (scanToEnd === true) {
458
+ continue;
459
+ }
460
+ break;
461
+ }
462
+ if (code === CHAR_LEFT_SQUARE_BRACKET) {
463
+ while (eos() !== true && (next = advance())) {
464
+ if (next === CHAR_BACKWARD_SLASH) {
465
+ backslashes = token.backslashes = true;
466
+ advance();
467
+ continue;
468
+ }
469
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
470
+ isBracket = token.isBracket = true;
471
+ isGlob = token.isGlob = true;
472
+ finished = true;
473
+ break;
474
+ }
475
+ }
476
+ if (scanToEnd === true) {
477
+ continue;
478
+ }
479
+ break;
480
+ }
481
+ if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
482
+ negated = token.negated = true;
483
+ start++;
484
+ continue;
485
+ }
486
+ if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
487
+ isGlob = token.isGlob = true;
488
+ if (scanToEnd === true) {
489
+ while (eos() !== true && (code = advance())) {
490
+ if (code === CHAR_LEFT_PARENTHESES) {
491
+ backslashes = token.backslashes = true;
492
+ code = advance();
493
+ continue;
494
+ }
495
+ if (code === CHAR_RIGHT_PARENTHESES) {
496
+ finished = true;
497
+ break;
498
+ }
499
+ }
500
+ continue;
501
+ }
502
+ break;
503
+ }
504
+ if (isGlob === true) {
505
+ finished = true;
506
+ if (scanToEnd === true) {
507
+ continue;
508
+ }
509
+ break;
510
+ }
511
+ }
512
+ if (opts.noext === true) {
513
+ isExtglob = false;
514
+ isGlob = false;
515
+ }
516
+ let base = str;
517
+ let prefix = "";
518
+ let glob = "";
519
+ if (start > 0) {
520
+ prefix = str.slice(0, start);
521
+ str = str.slice(start);
522
+ lastIndex -= start;
523
+ }
524
+ if (base && isGlob === true && lastIndex > 0) {
525
+ base = str.slice(0, lastIndex);
526
+ glob = str.slice(lastIndex);
527
+ } else if (isGlob === true) {
528
+ base = "";
529
+ glob = str;
530
+ } else {
531
+ base = str;
532
+ }
533
+ if (base && base !== "" && base !== "/" && base !== str) {
534
+ if (isPathSeparator(base.charCodeAt(base.length - 1))) {
535
+ base = base.slice(0, -1);
536
+ }
537
+ }
538
+ if (opts.unescape === true) {
539
+ if (glob) glob = utils.removeBackslashes(glob);
540
+ if (base && backslashes === true) {
541
+ base = utils.removeBackslashes(base);
542
+ }
543
+ }
544
+ const state = {
545
+ prefix,
546
+ input,
547
+ start,
548
+ base,
549
+ glob,
550
+ isBrace,
551
+ isBracket,
552
+ isGlob,
553
+ isExtglob,
554
+ isGlobstar,
555
+ negated,
556
+ negatedExtglob
557
+ };
558
+ if (opts.tokens === true) {
559
+ state.maxDepth = 0;
560
+ if (!isPathSeparator(code)) {
561
+ tokens.push(token);
562
+ }
563
+ state.tokens = tokens;
564
+ }
565
+ if (opts.parts === true || opts.tokens === true) {
566
+ let prevIndex;
567
+ for (let idx = 0; idx < slashes.length; idx++) {
568
+ const n = prevIndex ? prevIndex + 1 : start;
569
+ const i = slashes[idx];
570
+ const value = input.slice(n, i);
571
+ if (opts.tokens) {
572
+ if (idx === 0 && start !== 0) {
573
+ tokens[idx].isPrefix = true;
574
+ tokens[idx].value = prefix;
575
+ } else {
576
+ tokens[idx].value = value;
577
+ }
578
+ depth(tokens[idx]);
579
+ state.maxDepth += tokens[idx].depth;
580
+ }
581
+ if (idx !== 0 || value !== "") {
582
+ parts.push(value);
583
+ }
584
+ prevIndex = i;
585
+ }
586
+ if (prevIndex && prevIndex + 1 < input.length) {
587
+ const value = input.slice(prevIndex + 1);
588
+ parts.push(value);
589
+ if (opts.tokens) {
590
+ tokens[tokens.length - 1].value = value;
591
+ depth(tokens[tokens.length - 1]);
592
+ state.maxDepth += tokens[tokens.length - 1].depth;
593
+ }
594
+ }
595
+ state.slashes = slashes;
596
+ state.parts = parts;
597
+ }
598
+ return state;
599
+ };
600
+ module.exports = scan;
601
+ }
602
+ });
603
+
604
+ // node_modules/picomatch/lib/parse.js
605
+ var require_parse = __commonJS({
606
+ "node_modules/picomatch/lib/parse.js"(exports, module) {
607
+ "use strict";
608
+ var constants = require_constants();
609
+ var utils = require_utils();
610
+ var {
611
+ MAX_LENGTH,
612
+ POSIX_REGEX_SOURCE,
613
+ REGEX_NON_SPECIAL_CHARS,
614
+ REGEX_SPECIAL_CHARS_BACKREF,
615
+ REPLACEMENTS
616
+ } = constants;
617
+ var expandRange = (args, options) => {
618
+ if (typeof options.expandRange === "function") {
619
+ return options.expandRange(...args, options);
620
+ }
621
+ args.sort();
622
+ const value = `[${args.join("-")}]`;
623
+ try {
624
+ new RegExp(value);
625
+ } catch (ex) {
626
+ return args.map((v) => utils.escapeRegex(v)).join("..");
627
+ }
628
+ return value;
629
+ };
630
+ var syntaxError = (type, char) => {
631
+ return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
632
+ };
633
+ var splitTopLevel = (input) => {
634
+ const parts = [];
635
+ let bracket = 0;
636
+ let paren = 0;
637
+ let quote = 0;
638
+ let value = "";
639
+ let escaped = false;
640
+ for (const ch of input) {
641
+ if (escaped === true) {
642
+ value += ch;
643
+ escaped = false;
644
+ continue;
645
+ }
646
+ if (ch === "\\") {
647
+ value += ch;
648
+ escaped = true;
649
+ continue;
650
+ }
651
+ if (ch === '"') {
652
+ quote = quote === 1 ? 0 : 1;
653
+ value += ch;
654
+ continue;
655
+ }
656
+ if (quote === 0) {
657
+ if (ch === "[") {
658
+ bracket++;
659
+ } else if (ch === "]" && bracket > 0) {
660
+ bracket--;
661
+ } else if (bracket === 0) {
662
+ if (ch === "(") {
663
+ paren++;
664
+ } else if (ch === ")" && paren > 0) {
665
+ paren--;
666
+ } else if (ch === "|" && paren === 0) {
667
+ parts.push(value);
668
+ value = "";
669
+ continue;
670
+ }
671
+ }
672
+ }
673
+ value += ch;
674
+ }
675
+ parts.push(value);
676
+ return parts;
677
+ };
678
+ var isPlainBranch = (branch) => {
679
+ let escaped = false;
680
+ for (const ch of branch) {
681
+ if (escaped === true) {
682
+ escaped = false;
683
+ continue;
684
+ }
685
+ if (ch === "\\") {
686
+ escaped = true;
687
+ continue;
688
+ }
689
+ if (/[?*+@!()[\]{}]/.test(ch)) {
690
+ return false;
691
+ }
692
+ }
693
+ return true;
694
+ };
695
+ var normalizeSimpleBranch = (branch) => {
696
+ let value = branch.trim();
697
+ let changed = true;
698
+ while (changed === true) {
699
+ changed = false;
700
+ if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
701
+ value = value.slice(2, -1);
702
+ changed = true;
703
+ }
704
+ }
705
+ if (!isPlainBranch(value)) {
706
+ return;
707
+ }
708
+ return value.replace(/\\(.)/g, "$1");
709
+ };
710
+ var hasRepeatedCharPrefixOverlap = (branches) => {
711
+ const values = branches.map(normalizeSimpleBranch).filter(Boolean);
712
+ for (let i = 0; i < values.length; i++) {
713
+ for (let j = i + 1; j < values.length; j++) {
714
+ const a = values[i];
715
+ const b = values[j];
716
+ const char = a[0];
717
+ if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
718
+ continue;
719
+ }
720
+ if (a === b || a.startsWith(b) || b.startsWith(a)) {
721
+ return true;
722
+ }
723
+ }
724
+ }
725
+ return false;
726
+ };
727
+ var parseRepeatedExtglob = (pattern, requireEnd = true) => {
728
+ if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
729
+ return;
730
+ }
731
+ let bracket = 0;
732
+ let paren = 0;
733
+ let quote = 0;
734
+ let escaped = false;
735
+ for (let i = 1; i < pattern.length; i++) {
736
+ const ch = pattern[i];
737
+ if (escaped === true) {
738
+ escaped = false;
739
+ continue;
740
+ }
741
+ if (ch === "\\") {
742
+ escaped = true;
743
+ continue;
744
+ }
745
+ if (ch === '"') {
746
+ quote = quote === 1 ? 0 : 1;
747
+ continue;
748
+ }
749
+ if (quote === 1) {
750
+ continue;
751
+ }
752
+ if (ch === "[") {
753
+ bracket++;
754
+ continue;
755
+ }
756
+ if (ch === "]" && bracket > 0) {
757
+ bracket--;
758
+ continue;
759
+ }
760
+ if (bracket > 0) {
761
+ continue;
762
+ }
763
+ if (ch === "(") {
764
+ paren++;
765
+ continue;
766
+ }
767
+ if (ch === ")") {
768
+ paren--;
769
+ if (paren === 0) {
770
+ if (requireEnd === true && i !== pattern.length - 1) {
771
+ return;
772
+ }
773
+ return {
774
+ type: pattern[0],
775
+ body: pattern.slice(2, i),
776
+ end: i
777
+ };
778
+ }
779
+ }
780
+ }
781
+ };
782
+ var getStarExtglobSequenceOutput = (pattern) => {
783
+ let index = 0;
784
+ const chars = [];
785
+ while (index < pattern.length) {
786
+ const match = parseRepeatedExtglob(pattern.slice(index), false);
787
+ if (!match || match.type !== "*") {
788
+ return;
789
+ }
790
+ const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
791
+ if (branches.length !== 1) {
792
+ return;
793
+ }
794
+ const branch = normalizeSimpleBranch(branches[0]);
795
+ if (!branch || branch.length !== 1) {
796
+ return;
797
+ }
798
+ chars.push(branch);
799
+ index += match.end + 1;
800
+ }
801
+ if (chars.length < 1) {
802
+ return;
803
+ }
804
+ const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
805
+ return `${source}*`;
806
+ };
807
+ var repeatedExtglobRecursion = (pattern) => {
808
+ let depth = 0;
809
+ let value = pattern.trim();
810
+ let match = parseRepeatedExtglob(value);
811
+ while (match) {
812
+ depth++;
813
+ value = match.body.trim();
814
+ match = parseRepeatedExtglob(value);
815
+ }
816
+ return depth;
817
+ };
818
+ var analyzeRepeatedExtglob = (body, options) => {
819
+ if (options.maxExtglobRecursion === false) {
820
+ return { risky: false };
821
+ }
822
+ const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
823
+ const branches = splitTopLevel(body).map((branch) => branch.trim());
824
+ if (branches.length > 1) {
825
+ if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
826
+ return { risky: true };
827
+ }
828
+ }
829
+ for (const branch of branches) {
830
+ const safeOutput = getStarExtglobSequenceOutput(branch);
831
+ if (safeOutput) {
832
+ return { risky: true, safeOutput };
833
+ }
834
+ if (repeatedExtglobRecursion(branch) > max) {
835
+ return { risky: true };
836
+ }
837
+ }
838
+ return { risky: false };
839
+ };
840
+ var parse = (input, options) => {
841
+ if (typeof input !== "string") {
842
+ throw new TypeError("Expected a string");
843
+ }
844
+ input = REPLACEMENTS[input] || input;
845
+ const opts = { ...options };
846
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
847
+ let len = input.length;
848
+ if (len > max) {
849
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
850
+ }
851
+ const bos = { type: "bos", value: "", output: opts.prepend || "" };
852
+ const tokens = [bos];
853
+ const capture = opts.capture ? "" : "?:";
854
+ const PLATFORM_CHARS = constants.globChars(opts.windows);
855
+ const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
856
+ const {
857
+ DOT_LITERAL,
858
+ PLUS_LITERAL,
859
+ SLASH_LITERAL,
860
+ ONE_CHAR,
861
+ DOTS_SLASH,
862
+ NO_DOT,
863
+ NO_DOT_SLASH,
864
+ NO_DOTS_SLASH,
865
+ QMARK,
866
+ QMARK_NO_DOT,
867
+ STAR,
868
+ START_ANCHOR
869
+ } = PLATFORM_CHARS;
870
+ const globstar = (opts2) => {
871
+ return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
872
+ };
873
+ const nodot = opts.dot ? "" : NO_DOT;
874
+ const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
875
+ let star = opts.bash === true ? globstar(opts) : STAR;
876
+ if (opts.capture) {
877
+ star = `(${star})`;
878
+ }
879
+ if (typeof opts.noext === "boolean") {
880
+ opts.noextglob = opts.noext;
881
+ }
882
+ const state = {
883
+ input,
884
+ index: -1,
885
+ start: 0,
886
+ dot: opts.dot === true,
887
+ consumed: "",
888
+ output: "",
889
+ prefix: "",
890
+ backtrack: false,
891
+ negated: false,
892
+ brackets: 0,
893
+ braces: 0,
894
+ parens: 0,
895
+ quotes: 0,
896
+ globstar: false,
897
+ tokens
898
+ };
899
+ input = utils.removePrefix(input, state);
900
+ len = input.length;
901
+ const extglobs = [];
902
+ const braces = [];
903
+ const stack = [];
904
+ let prev = bos;
905
+ let value;
906
+ const eos = () => state.index === len - 1;
907
+ const peek = state.peek = (n = 1) => input[state.index + n];
908
+ const advance = state.advance = () => input[++state.index] || "";
909
+ const remaining = () => input.slice(state.index + 1);
910
+ const consume = (value2 = "", num = 0) => {
911
+ state.consumed += value2;
912
+ state.index += num;
913
+ };
914
+ const append = (token) => {
915
+ state.output += token.output != null ? token.output : token.value;
916
+ consume(token.value);
917
+ };
918
+ const negate = () => {
919
+ let count = 1;
920
+ while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
921
+ advance();
922
+ state.start++;
923
+ count++;
924
+ }
925
+ if (count % 2 === 0) {
926
+ return false;
927
+ }
928
+ state.negated = true;
929
+ state.start++;
930
+ return true;
931
+ };
932
+ const increment = (type) => {
933
+ state[type]++;
934
+ stack.push(type);
935
+ };
936
+ const decrement = (type) => {
937
+ state[type]--;
938
+ stack.pop();
939
+ };
940
+ const push = (tok) => {
941
+ if (prev.type === "globstar") {
942
+ const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
943
+ const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
944
+ if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
945
+ state.output = state.output.slice(0, -prev.output.length);
946
+ prev.type = "star";
947
+ prev.value = "*";
948
+ prev.output = star;
949
+ state.output += prev.output;
950
+ }
951
+ }
952
+ if (extglobs.length && tok.type !== "paren") {
953
+ extglobs[extglobs.length - 1].inner += tok.value;
954
+ }
955
+ if (tok.value || tok.output) append(tok);
956
+ if (prev && prev.type === "text" && tok.type === "text") {
957
+ prev.output = (prev.output || prev.value) + tok.value;
958
+ prev.value += tok.value;
959
+ return;
960
+ }
961
+ tok.prev = prev;
962
+ tokens.push(tok);
963
+ prev = tok;
964
+ };
965
+ const extglobOpen = (type, value2) => {
966
+ const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
967
+ token.prev = prev;
968
+ token.parens = state.parens;
969
+ token.output = state.output;
970
+ token.startIndex = state.index;
971
+ token.tokensIndex = tokens.length;
972
+ const output = (opts.capture ? "(" : "") + token.open;
973
+ increment("parens");
974
+ push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
975
+ push({ type: "paren", extglob: true, value: advance(), output });
976
+ extglobs.push(token);
977
+ };
978
+ const extglobClose = (token) => {
979
+ const literal = input.slice(token.startIndex, state.index + 1);
980
+ const body = input.slice(token.startIndex + 2, state.index);
981
+ const analysis = analyzeRepeatedExtglob(body, opts);
982
+ if ((token.type === "plus" || token.type === "star") && analysis.risky) {
983
+ const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
984
+ const open = tokens[token.tokensIndex];
985
+ open.type = "text";
986
+ open.value = literal;
987
+ open.output = safeOutput || utils.escapeRegex(literal);
988
+ for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
989
+ tokens[i].value = "";
990
+ tokens[i].output = "";
991
+ delete tokens[i].suffix;
992
+ }
993
+ state.output = token.output + open.output;
994
+ state.backtrack = true;
995
+ push({ type: "paren", extglob: true, value, output: "" });
996
+ decrement("parens");
997
+ return;
998
+ }
999
+ let output = token.close + (opts.capture ? ")" : "");
1000
+ let rest;
1001
+ if (token.type === "negate") {
1002
+ let extglobStar = star;
1003
+ if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
1004
+ extglobStar = globstar(opts);
1005
+ }
1006
+ if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
1007
+ output = token.close = `)$))${extglobStar}`;
1008
+ }
1009
+ if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
1010
+ const expression = parse(rest, { ...options, fastpaths: false }).output;
1011
+ output = token.close = `)${expression})${extglobStar})`;
1012
+ }
1013
+ if (token.prev.type === "bos") {
1014
+ state.negatedExtglob = true;
1015
+ }
1016
+ }
1017
+ push({ type: "paren", extglob: true, value, output });
1018
+ decrement("parens");
1019
+ };
1020
+ if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
1021
+ let backslashes = false;
1022
+ let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
1023
+ if (first === "\\") {
1024
+ backslashes = true;
1025
+ return m;
1026
+ }
1027
+ if (first === "?") {
1028
+ if (esc) {
1029
+ return esc + first + (rest ? QMARK.repeat(rest.length) : "");
1030
+ }
1031
+ if (index === 0) {
1032
+ return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
1033
+ }
1034
+ return QMARK.repeat(chars.length);
1035
+ }
1036
+ if (first === ".") {
1037
+ return DOT_LITERAL.repeat(chars.length);
1038
+ }
1039
+ if (first === "*") {
1040
+ if (esc) {
1041
+ return esc + first + (rest ? star : "");
1042
+ }
1043
+ return star;
1044
+ }
1045
+ return esc ? m : `\\${m}`;
1046
+ });
1047
+ if (backslashes === true) {
1048
+ if (opts.unescape === true) {
1049
+ output = output.replace(/\\/g, "");
1050
+ } else {
1051
+ output = output.replace(/\\+/g, (m) => {
1052
+ return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
1053
+ });
1054
+ }
1055
+ }
1056
+ if (output === input && opts.contains === true) {
1057
+ state.output = input;
1058
+ return state;
1059
+ }
1060
+ state.output = utils.wrapOutput(output, state, options);
1061
+ return state;
1062
+ }
1063
+ while (!eos()) {
1064
+ value = advance();
1065
+ if (value === "\0") {
1066
+ continue;
1067
+ }
1068
+ if (value === "\\") {
1069
+ const next = peek();
1070
+ if (next === "/" && opts.bash !== true) {
1071
+ continue;
1072
+ }
1073
+ if (next === "." || next === ";") {
1074
+ continue;
1075
+ }
1076
+ if (!next) {
1077
+ value += "\\";
1078
+ push({ type: "text", value });
1079
+ continue;
1080
+ }
1081
+ const match = /^\\+/.exec(remaining());
1082
+ let slashes = 0;
1083
+ if (match && match[0].length > 2) {
1084
+ slashes = match[0].length;
1085
+ state.index += slashes;
1086
+ if (slashes % 2 !== 0) {
1087
+ value += "\\";
1088
+ }
1089
+ }
1090
+ if (opts.unescape === true) {
1091
+ value = advance();
1092
+ } else {
1093
+ value += advance();
1094
+ }
1095
+ if (state.brackets === 0) {
1096
+ push({ type: "text", value });
1097
+ continue;
1098
+ }
1099
+ }
1100
+ if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
1101
+ if (opts.posix !== false && value === ":") {
1102
+ const inner = prev.value.slice(1);
1103
+ if (inner.includes("[")) {
1104
+ prev.posix = true;
1105
+ if (inner.includes(":")) {
1106
+ const idx = prev.value.lastIndexOf("[");
1107
+ const pre = prev.value.slice(0, idx);
1108
+ const rest2 = prev.value.slice(idx + 2);
1109
+ const posix = POSIX_REGEX_SOURCE[rest2];
1110
+ if (posix) {
1111
+ prev.value = pre + posix;
1112
+ state.backtrack = true;
1113
+ advance();
1114
+ if (!bos.output && tokens.indexOf(prev) === 1) {
1115
+ bos.output = ONE_CHAR;
1116
+ }
1117
+ continue;
1118
+ }
1119
+ }
1120
+ }
1121
+ }
1122
+ if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
1123
+ value = `\\${value}`;
1124
+ }
1125
+ if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
1126
+ value = `\\${value}`;
1127
+ }
1128
+ if (opts.posix === true && value === "!" && prev.value === "[") {
1129
+ value = "^";
1130
+ }
1131
+ prev.value += value;
1132
+ append({ value });
1133
+ continue;
1134
+ }
1135
+ if (state.quotes === 1 && value !== '"') {
1136
+ value = utils.escapeRegex(value);
1137
+ prev.value += value;
1138
+ append({ value });
1139
+ continue;
1140
+ }
1141
+ if (value === '"') {
1142
+ state.quotes = state.quotes === 1 ? 0 : 1;
1143
+ if (opts.keepQuotes === true) {
1144
+ push({ type: "text", value });
1145
+ }
1146
+ continue;
1147
+ }
1148
+ if (value === "(") {
1149
+ increment("parens");
1150
+ push({ type: "paren", value });
1151
+ continue;
1152
+ }
1153
+ if (value === ")") {
1154
+ if (state.parens === 0 && opts.strictBrackets === true) {
1155
+ throw new SyntaxError(syntaxError("opening", "("));
1156
+ }
1157
+ const extglob = extglobs[extglobs.length - 1];
1158
+ if (extglob && state.parens === extglob.parens + 1) {
1159
+ extglobClose(extglobs.pop());
1160
+ continue;
1161
+ }
1162
+ push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
1163
+ decrement("parens");
1164
+ continue;
1165
+ }
1166
+ if (value === "[") {
1167
+ if (opts.nobracket === true || !remaining().includes("]")) {
1168
+ if (opts.nobracket !== true && opts.strictBrackets === true) {
1169
+ throw new SyntaxError(syntaxError("closing", "]"));
1170
+ }
1171
+ value = `\\${value}`;
1172
+ } else {
1173
+ increment("brackets");
1174
+ }
1175
+ push({ type: "bracket", value });
1176
+ continue;
1177
+ }
1178
+ if (value === "]") {
1179
+ if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
1180
+ push({ type: "text", value, output: `\\${value}` });
1181
+ continue;
1182
+ }
1183
+ if (state.brackets === 0) {
1184
+ if (opts.strictBrackets === true) {
1185
+ throw new SyntaxError(syntaxError("opening", "["));
1186
+ }
1187
+ push({ type: "text", value, output: `\\${value}` });
1188
+ continue;
1189
+ }
1190
+ decrement("brackets");
1191
+ const prevValue = prev.value.slice(1);
1192
+ if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
1193
+ value = `/${value}`;
1194
+ }
1195
+ prev.value += value;
1196
+ append({ value });
1197
+ if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
1198
+ continue;
1199
+ }
1200
+ const escaped = utils.escapeRegex(prev.value);
1201
+ state.output = state.output.slice(0, -prev.value.length);
1202
+ if (opts.literalBrackets === true) {
1203
+ state.output += escaped;
1204
+ prev.value = escaped;
1205
+ continue;
1206
+ }
1207
+ prev.value = `(${capture}${escaped}|${prev.value})`;
1208
+ state.output += prev.value;
1209
+ continue;
1210
+ }
1211
+ if (value === "{" && opts.nobrace !== true) {
1212
+ increment("braces");
1213
+ const open = {
1214
+ type: "brace",
1215
+ value,
1216
+ output: "(",
1217
+ outputIndex: state.output.length,
1218
+ tokensIndex: state.tokens.length
1219
+ };
1220
+ braces.push(open);
1221
+ push(open);
1222
+ continue;
1223
+ }
1224
+ if (value === "}") {
1225
+ const brace = braces[braces.length - 1];
1226
+ if (opts.nobrace === true || !brace) {
1227
+ push({ type: "text", value, output: value });
1228
+ continue;
1229
+ }
1230
+ let output = ")";
1231
+ if (brace.dots === true) {
1232
+ const arr = tokens.slice();
1233
+ const range = [];
1234
+ for (let i = arr.length - 1; i >= 0; i--) {
1235
+ tokens.pop();
1236
+ if (arr[i].type === "brace") {
1237
+ break;
1238
+ }
1239
+ if (arr[i].type !== "dots") {
1240
+ range.unshift(arr[i].value);
1241
+ }
1242
+ }
1243
+ output = expandRange(range, opts);
1244
+ state.backtrack = true;
1245
+ }
1246
+ if (brace.comma !== true && brace.dots !== true) {
1247
+ const out = state.output.slice(0, brace.outputIndex);
1248
+ const toks = state.tokens.slice(brace.tokensIndex);
1249
+ brace.value = brace.output = "\\{";
1250
+ value = output = "\\}";
1251
+ state.output = out;
1252
+ for (const t of toks) {
1253
+ state.output += t.output || t.value;
1254
+ }
1255
+ }
1256
+ push({ type: "brace", value, output });
1257
+ decrement("braces");
1258
+ braces.pop();
1259
+ continue;
1260
+ }
1261
+ if (value === "|") {
1262
+ if (extglobs.length > 0) {
1263
+ extglobs[extglobs.length - 1].conditions++;
1264
+ }
1265
+ push({ type: "text", value });
1266
+ continue;
1267
+ }
1268
+ if (value === ",") {
1269
+ let output = value;
1270
+ const brace = braces[braces.length - 1];
1271
+ if (brace && stack[stack.length - 1] === "braces") {
1272
+ brace.comma = true;
1273
+ output = "|";
1274
+ }
1275
+ push({ type: "comma", value, output });
1276
+ continue;
1277
+ }
1278
+ if (value === "/") {
1279
+ if (prev.type === "dot" && state.index === state.start + 1) {
1280
+ state.start = state.index + 1;
1281
+ state.consumed = "";
1282
+ state.output = "";
1283
+ tokens.pop();
1284
+ prev = bos;
1285
+ continue;
1286
+ }
1287
+ push({ type: "slash", value, output: SLASH_LITERAL });
1288
+ continue;
1289
+ }
1290
+ if (value === ".") {
1291
+ if (state.braces > 0 && prev.type === "dot") {
1292
+ if (prev.value === ".") prev.output = DOT_LITERAL;
1293
+ const brace = braces[braces.length - 1];
1294
+ prev.type = "dots";
1295
+ prev.output += value;
1296
+ prev.value += value;
1297
+ brace.dots = true;
1298
+ continue;
1299
+ }
1300
+ if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
1301
+ push({ type: "text", value, output: DOT_LITERAL });
1302
+ continue;
1303
+ }
1304
+ push({ type: "dot", value, output: DOT_LITERAL });
1305
+ continue;
1306
+ }
1307
+ if (value === "?") {
1308
+ const isGroup = prev && prev.value === "(";
1309
+ if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1310
+ extglobOpen("qmark", value);
1311
+ continue;
1312
+ }
1313
+ if (prev && prev.type === "paren") {
1314
+ const next = peek();
1315
+ let output = value;
1316
+ if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
1317
+ output = `\\${value}`;
1318
+ }
1319
+ push({ type: "text", value, output });
1320
+ continue;
1321
+ }
1322
+ if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
1323
+ push({ type: "qmark", value, output: QMARK_NO_DOT });
1324
+ continue;
1325
+ }
1326
+ push({ type: "qmark", value, output: QMARK });
1327
+ continue;
1328
+ }
1329
+ if (value === "!") {
1330
+ if (opts.noextglob !== true && peek() === "(") {
1331
+ if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
1332
+ extglobOpen("negate", value);
1333
+ continue;
1334
+ }
1335
+ }
1336
+ if (opts.nonegate !== true && state.index === 0) {
1337
+ negate();
1338
+ continue;
1339
+ }
1340
+ }
1341
+ if (value === "+") {
1342
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1343
+ extglobOpen("plus", value);
1344
+ continue;
1345
+ }
1346
+ if (prev && prev.value === "(" || opts.regex === false) {
1347
+ push({ type: "plus", value, output: PLUS_LITERAL });
1348
+ continue;
1349
+ }
1350
+ if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
1351
+ push({ type: "plus", value });
1352
+ continue;
1353
+ }
1354
+ push({ type: "plus", value: PLUS_LITERAL });
1355
+ continue;
1356
+ }
1357
+ if (value === "@") {
1358
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1359
+ push({ type: "at", extglob: true, value, output: "" });
1360
+ continue;
1361
+ }
1362
+ push({ type: "text", value });
1363
+ continue;
1364
+ }
1365
+ if (value !== "*") {
1366
+ if (value === "$" || value === "^") {
1367
+ value = `\\${value}`;
1368
+ }
1369
+ const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
1370
+ if (match) {
1371
+ value += match[0];
1372
+ state.index += match[0].length;
1373
+ }
1374
+ push({ type: "text", value });
1375
+ continue;
1376
+ }
1377
+ if (prev && (prev.type === "globstar" || prev.star === true)) {
1378
+ prev.type = "star";
1379
+ prev.star = true;
1380
+ prev.value += value;
1381
+ prev.output = star;
1382
+ state.backtrack = true;
1383
+ state.globstar = true;
1384
+ consume(value);
1385
+ continue;
1386
+ }
1387
+ let rest = remaining();
1388
+ if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
1389
+ extglobOpen("star", value);
1390
+ continue;
1391
+ }
1392
+ if (prev.type === "star") {
1393
+ if (opts.noglobstar === true) {
1394
+ consume(value);
1395
+ continue;
1396
+ }
1397
+ const prior = prev.prev;
1398
+ const before = prior.prev;
1399
+ const isStart = prior.type === "slash" || prior.type === "bos";
1400
+ const afterStar = before && (before.type === "star" || before.type === "globstar");
1401
+ if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
1402
+ push({ type: "star", value, output: "" });
1403
+ continue;
1404
+ }
1405
+ const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
1406
+ const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
1407
+ if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
1408
+ push({ type: "star", value, output: "" });
1409
+ continue;
1410
+ }
1411
+ while (rest.slice(0, 3) === "/**") {
1412
+ const after = input[state.index + 4];
1413
+ if (after && after !== "/") {
1414
+ break;
1415
+ }
1416
+ rest = rest.slice(3);
1417
+ consume("/**", 3);
1418
+ }
1419
+ if (prior.type === "bos" && eos()) {
1420
+ prev.type = "globstar";
1421
+ prev.value += value;
1422
+ prev.output = globstar(opts);
1423
+ state.output = prev.output;
1424
+ state.globstar = true;
1425
+ consume(value);
1426
+ continue;
1427
+ }
1428
+ if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
1429
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1430
+ prior.output = `(?:${prior.output}`;
1431
+ prev.type = "globstar";
1432
+ prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
1433
+ prev.value += value;
1434
+ state.globstar = true;
1435
+ state.output += prior.output + prev.output;
1436
+ consume(value);
1437
+ continue;
1438
+ }
1439
+ if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
1440
+ const end = rest[1] !== void 0 ? "|$" : "";
1441
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1442
+ prior.output = `(?:${prior.output}`;
1443
+ prev.type = "globstar";
1444
+ prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
1445
+ prev.value += value;
1446
+ state.output += prior.output + prev.output;
1447
+ state.globstar = true;
1448
+ consume(value + advance());
1449
+ push({ type: "slash", value: "/", output: "" });
1450
+ continue;
1451
+ }
1452
+ if (prior.type === "bos" && rest[0] === "/") {
1453
+ prev.type = "globstar";
1454
+ prev.value += value;
1455
+ prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
1456
+ state.output = prev.output;
1457
+ state.globstar = true;
1458
+ consume(value + advance());
1459
+ push({ type: "slash", value: "/", output: "" });
1460
+ continue;
1461
+ }
1462
+ state.output = state.output.slice(0, -prev.output.length);
1463
+ prev.type = "globstar";
1464
+ prev.output = globstar(opts);
1465
+ prev.value += value;
1466
+ state.output += prev.output;
1467
+ state.globstar = true;
1468
+ consume(value);
1469
+ continue;
1470
+ }
1471
+ const token = { type: "star", value, output: star };
1472
+ if (opts.bash === true) {
1473
+ token.output = ".*?";
1474
+ if (prev.type === "bos" || prev.type === "slash") {
1475
+ token.output = nodot + token.output;
1476
+ }
1477
+ push(token);
1478
+ continue;
1479
+ }
1480
+ if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
1481
+ token.output = value;
1482
+ push(token);
1483
+ continue;
1484
+ }
1485
+ if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
1486
+ if (prev.type === "dot") {
1487
+ state.output += NO_DOT_SLASH;
1488
+ prev.output += NO_DOT_SLASH;
1489
+ } else if (opts.dot === true) {
1490
+ state.output += NO_DOTS_SLASH;
1491
+ prev.output += NO_DOTS_SLASH;
1492
+ } else {
1493
+ state.output += nodot;
1494
+ prev.output += nodot;
1495
+ }
1496
+ if (peek() !== "*") {
1497
+ state.output += ONE_CHAR;
1498
+ prev.output += ONE_CHAR;
1499
+ }
1500
+ }
1501
+ push(token);
1502
+ }
1503
+ while (state.brackets > 0) {
1504
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
1505
+ state.output = utils.escapeLast(state.output, "[");
1506
+ decrement("brackets");
1507
+ }
1508
+ while (state.parens > 0) {
1509
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
1510
+ state.output = utils.escapeLast(state.output, "(");
1511
+ decrement("parens");
1512
+ }
1513
+ while (state.braces > 0) {
1514
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
1515
+ state.output = utils.escapeLast(state.output, "{");
1516
+ decrement("braces");
1517
+ }
1518
+ if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
1519
+ push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
1520
+ }
1521
+ if (state.backtrack === true) {
1522
+ state.output = "";
1523
+ for (const token of state.tokens) {
1524
+ state.output += token.output != null ? token.output : token.value;
1525
+ if (token.suffix) {
1526
+ state.output += token.suffix;
1527
+ }
1528
+ }
1529
+ }
1530
+ return state;
1531
+ };
1532
+ parse.fastpaths = (input, options) => {
1533
+ const opts = { ...options };
1534
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1535
+ const len = input.length;
1536
+ if (len > max) {
1537
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
1538
+ }
1539
+ input = REPLACEMENTS[input] || input;
1540
+ const {
1541
+ DOT_LITERAL,
1542
+ SLASH_LITERAL,
1543
+ ONE_CHAR,
1544
+ DOTS_SLASH,
1545
+ NO_DOT,
1546
+ NO_DOTS,
1547
+ NO_DOTS_SLASH,
1548
+ STAR,
1549
+ START_ANCHOR
1550
+ } = constants.globChars(opts.windows);
1551
+ const nodot = opts.dot ? NO_DOTS : NO_DOT;
1552
+ const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
1553
+ const capture = opts.capture ? "" : "?:";
1554
+ const state = { negated: false, prefix: "" };
1555
+ let star = opts.bash === true ? ".*?" : STAR;
1556
+ if (opts.capture) {
1557
+ star = `(${star})`;
1558
+ }
1559
+ const globstar = (opts2) => {
1560
+ if (opts2.noglobstar === true) return star;
1561
+ return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
1562
+ };
1563
+ const create = (str) => {
1564
+ switch (str) {
1565
+ case "*":
1566
+ return `${nodot}${ONE_CHAR}${star}`;
1567
+ case ".*":
1568
+ return `${DOT_LITERAL}${ONE_CHAR}${star}`;
1569
+ case "*.*":
1570
+ return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1571
+ case "*/*":
1572
+ return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
1573
+ case "**":
1574
+ return nodot + globstar(opts);
1575
+ case "**/*":
1576
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
1577
+ case "**/*.*":
1578
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1579
+ case "**/.*":
1580
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
1581
+ default: {
1582
+ const match = /^(.*?)\.(\w+)$/.exec(str);
1583
+ if (!match) return;
1584
+ const source2 = create(match[1]);
1585
+ if (!source2) return;
1586
+ return source2 + DOT_LITERAL + match[2];
1587
+ }
1588
+ }
1589
+ };
1590
+ const output = utils.removePrefix(input, state);
1591
+ let source = create(output);
1592
+ if (source && opts.strictSlashes !== true) {
1593
+ source += `${SLASH_LITERAL}?`;
1594
+ }
1595
+ return source;
1596
+ };
1597
+ module.exports = parse;
1598
+ }
1599
+ });
1600
+
1601
+ // node_modules/picomatch/lib/picomatch.js
1602
+ var require_picomatch = __commonJS({
1603
+ "node_modules/picomatch/lib/picomatch.js"(exports, module) {
1604
+ "use strict";
1605
+ var scan = require_scan();
1606
+ var parse = require_parse();
1607
+ var utils = require_utils();
1608
+ var constants = require_constants();
1609
+ var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
1610
+ var picomatch2 = (glob, options, returnState = false) => {
1611
+ if (Array.isArray(glob)) {
1612
+ const fns = glob.map((input) => picomatch2(input, options, returnState));
1613
+ const arrayMatcher = (str) => {
1614
+ for (const isMatch of fns) {
1615
+ const state2 = isMatch(str);
1616
+ if (state2) return state2;
1617
+ }
1618
+ return false;
1619
+ };
1620
+ return arrayMatcher;
1621
+ }
1622
+ const isState = isObject(glob) && glob.tokens && glob.input;
1623
+ if (glob === "" || typeof glob !== "string" && !isState) {
1624
+ throw new TypeError("Expected pattern to be a non-empty string");
1625
+ }
1626
+ const opts = options || {};
1627
+ const posix = opts.windows;
1628
+ const regex = isState ? picomatch2.compileRe(glob, options) : picomatch2.makeRe(glob, options, false, true);
1629
+ const state = regex.state;
1630
+ delete regex.state;
1631
+ let isIgnored = () => false;
1632
+ if (opts.ignore) {
1633
+ const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
1634
+ isIgnored = picomatch2(opts.ignore, ignoreOpts, returnState);
1635
+ }
1636
+ const matcher = (input, returnObject = false) => {
1637
+ const { isMatch, match, output } = picomatch2.test(input, regex, options, { glob, posix });
1638
+ const result = { glob, state, regex, posix, input, output, match, isMatch };
1639
+ if (typeof opts.onResult === "function") {
1640
+ opts.onResult(result);
1641
+ }
1642
+ if (isMatch === false) {
1643
+ result.isMatch = false;
1644
+ return returnObject ? result : false;
1645
+ }
1646
+ if (isIgnored(input)) {
1647
+ if (typeof opts.onIgnore === "function") {
1648
+ opts.onIgnore(result);
1649
+ }
1650
+ result.isMatch = false;
1651
+ return returnObject ? result : false;
1652
+ }
1653
+ if (typeof opts.onMatch === "function") {
1654
+ opts.onMatch(result);
1655
+ }
1656
+ return returnObject ? result : true;
1657
+ };
1658
+ if (returnState) {
1659
+ matcher.state = state;
1660
+ }
1661
+ return matcher;
1662
+ };
1663
+ picomatch2.test = (input, regex, options, { glob, posix } = {}) => {
1664
+ if (typeof input !== "string") {
1665
+ throw new TypeError("Expected input to be a string");
1666
+ }
1667
+ if (input === "") {
1668
+ return { isMatch: false, output: "" };
1669
+ }
1670
+ const opts = options || {};
1671
+ const format = opts.format || (posix ? utils.toPosixSlashes : null);
1672
+ let match = input === glob;
1673
+ let output = match && format ? format(input) : input;
1674
+ if (match === false) {
1675
+ output = format ? format(input) : input;
1676
+ match = output === glob;
1677
+ }
1678
+ if (match === false || opts.capture === true) {
1679
+ if (opts.matchBase === true || opts.basename === true) {
1680
+ match = picomatch2.matchBase(input, regex, options, posix);
1681
+ } else {
1682
+ match = regex.exec(output);
1683
+ }
1684
+ }
1685
+ return { isMatch: Boolean(match), match, output };
1686
+ };
1687
+ picomatch2.matchBase = (input, glob, options) => {
1688
+ const regex = glob instanceof RegExp ? glob : picomatch2.makeRe(glob, options);
1689
+ return regex.test(utils.basename(input));
1690
+ };
1691
+ picomatch2.isMatch = (str, patterns, options) => picomatch2(patterns, options)(str);
1692
+ picomatch2.parse = (pattern, options) => {
1693
+ if (Array.isArray(pattern)) return pattern.map((p) => picomatch2.parse(p, options));
1694
+ return parse(pattern, { ...options, fastpaths: false });
1695
+ };
1696
+ picomatch2.scan = (input, options) => scan(input, options);
1697
+ picomatch2.compileRe = (state, options, returnOutput = false, returnState = false) => {
1698
+ if (returnOutput === true) {
1699
+ return state.output;
1700
+ }
1701
+ const opts = options || {};
1702
+ const prepend = opts.contains ? "" : "^";
1703
+ const append = opts.contains ? "" : "$";
1704
+ let source = `${prepend}(?:${state.output})${append}`;
1705
+ if (state && state.negated === true) {
1706
+ source = `^(?!${source}).*$`;
1707
+ }
1708
+ const regex = picomatch2.toRegex(source, options);
1709
+ if (returnState === true) {
1710
+ regex.state = state;
1711
+ }
1712
+ return regex;
1713
+ };
1714
+ picomatch2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
1715
+ if (!input || typeof input !== "string") {
1716
+ throw new TypeError("Expected a non-empty string");
1717
+ }
1718
+ let parsed = { negated: false, fastpaths: true };
1719
+ if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
1720
+ parsed.output = parse.fastpaths(input, options);
1721
+ }
1722
+ if (!parsed.output) {
1723
+ parsed = parse(input, options);
1724
+ }
1725
+ return picomatch2.compileRe(parsed, options, returnOutput, returnState);
1726
+ };
1727
+ picomatch2.toRegex = (source, options) => {
1728
+ try {
1729
+ const opts = options || {};
1730
+ return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
1731
+ } catch (err) {
1732
+ if (options && options.debug === true) throw err;
1733
+ return /$^/;
1734
+ }
1735
+ };
1736
+ picomatch2.constants = constants;
1737
+ module.exports = picomatch2;
1738
+ }
1739
+ });
1740
+
1741
+ // node_modules/picomatch/index.js
1742
+ var require_picomatch2 = __commonJS({
1743
+ "node_modules/picomatch/index.js"(exports, module) {
1744
+ "use strict";
1745
+ var pico = require_picomatch();
1746
+ var utils = require_utils();
1747
+ function picomatch2(glob, options, returnState = false) {
1748
+ if (options && (options.windows === null || options.windows === void 0)) {
1749
+ options = { ...options, windows: utils.isWindows() };
1750
+ }
1751
+ return pico(glob, options, returnState);
1752
+ }
1753
+ Object.assign(picomatch2, pico);
1754
+ module.exports = picomatch2;
1755
+ }
1756
+ });
1757
+
1758
+ // src/mcp/shell-split.ts
1759
+ function shellSplit(input) {
1760
+ const tokens = [];
1761
+ let cur = "";
1762
+ let quote = null;
1763
+ let i = 0;
1764
+ const s = input;
1765
+ while (i < s.length) {
1766
+ const ch = s[i];
1767
+ if (quote) {
1768
+ if (ch === quote) {
1769
+ quote = null;
1770
+ i++;
1771
+ continue;
1772
+ }
1773
+ if (ch === "\\" && quote === '"' && i + 1 < s.length) {
1774
+ cur += s[i + 1];
1775
+ i += 2;
1776
+ continue;
1777
+ }
1778
+ cur += ch;
1779
+ i++;
1780
+ continue;
1781
+ }
1782
+ if (ch === '"' || ch === "'") {
1783
+ quote = ch;
1784
+ i++;
1785
+ continue;
1786
+ }
1787
+ if (ch === " " || ch === " ") {
1788
+ if (cur.length > 0) {
1789
+ tokens.push(cur);
1790
+ cur = "";
1791
+ }
1792
+ i++;
1793
+ continue;
1794
+ }
1795
+ cur += ch;
1796
+ i++;
1797
+ }
1798
+ if (quote) {
1799
+ throw new Error(
1800
+ `shellSplit: unterminated ${quote === '"' ? "double" : "single"} quote in input`
1801
+ );
1802
+ }
1803
+ if (cur.length > 0) tokens.push(cur);
1804
+ return tokens;
1805
+ }
1806
+
1807
+ // src/mcp/spec.ts
1808
+ function getMcpServerEnv(spec) {
1809
+ return spec.transport === "stdio" ? spec.env : void 0;
1810
+ }
1811
+ function getMcpServerHeaders(spec) {
1812
+ return spec.transport !== "stdio" ? spec.headers : void 0;
1813
+ }
1814
+ function overlayMatchedSpec(parsed, matched) {
1815
+ switch (parsed.transport) {
1816
+ case "stdio":
1817
+ return matched ? { ...parsed, disabled: matched.disabled, env: getMcpServerEnv(matched) } : { ...parsed };
1818
+ case "sse":
1819
+ return matched ? { ...parsed, disabled: matched.disabled, headers: getMcpServerHeaders(matched) } : { ...parsed };
1820
+ case "streamable-http":
1821
+ return matched ? { ...parsed, disabled: matched.disabled, headers: getMcpServerHeaders(matched) } : { ...parsed };
1822
+ }
1823
+ }
1824
+ function specToRaw(spec) {
1825
+ if (spec.transport === "stdio") {
1826
+ const args = spec.args.map((a) => {
1827
+ if (a.includes(" ") || a.includes('"') || a.includes(" ")) {
1828
+ return `"${a.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
1829
+ }
1830
+ return a;
1831
+ }).join(" ");
1832
+ const body = args ? `${spec.command} ${args}` : spec.command;
1833
+ return spec.name ? `${spec.name}=${body}` : body;
1834
+ }
1835
+ if (spec.transport === "sse") {
1836
+ return spec.name ? `${spec.name}=${spec.url}` : spec.url;
1837
+ }
1838
+ return spec.name ? `${spec.name}=streamable+${spec.url}` : `streamable+${spec.url}`;
1839
+ }
1840
+ var NAME_PREFIX = /^([a-zA-Z_][a-zA-Z0-9_-]*)=(.*)$/;
1841
+ var HTTP_URL = /^https?:\/\//i;
1842
+ var STREAMABLE_PREFIX = /^streamable\+(https?:\/\/.+)$/i;
1843
+ function parseMcpSpec(input) {
1844
+ const trimmed = input.trim();
1845
+ if (!trimmed) {
1846
+ throw new Error("empty MCP spec");
1847
+ }
1848
+ const nameMatch = NAME_PREFIX.exec(trimmed);
1849
+ const name = nameMatch ? nameMatch[1] : null;
1850
+ const body = (nameMatch ? nameMatch[2] : trimmed).trim();
1851
+ if (!body) {
1852
+ throw new Error(`MCP spec has name but no command: ${input}`);
1853
+ }
1854
+ const streamMatch = STREAMABLE_PREFIX.exec(body);
1855
+ if (streamMatch) {
1856
+ return { transport: "streamable-http", name, url: streamMatch[1] };
1857
+ }
1858
+ if (HTTP_URL.test(body)) {
1859
+ return { transport: "sse", name, url: body };
1860
+ }
1861
+ const argv = shellSplit(body);
1862
+ if (argv.length === 0) {
1863
+ throw new Error(`MCP spec has name but no command: ${input}`);
1864
+ }
1865
+ const [command, ...args] = argv;
1866
+ return { transport: "stdio", name, command, args };
1867
+ }
1868
+
1869
+ // src/config.ts
1870
+ import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "fs";
1871
+ import { homedir } from "os";
1872
+ import { dirname, isAbsolute, join, resolve } from "path";
1873
+
1874
+ // src/cli/ui/theme/tokens.ts
1875
+ function card(fg, tone) {
1876
+ return {
1877
+ user: { color: tone.brand, glyph: "\u25C7" },
1878
+ reasoning: { color: tone.accent, glyph: "\u25C6" },
1879
+ streaming: { color: tone.brand, glyph: "\u25C8" },
1880
+ task: { color: tone.warn, glyph: "\u25B6" },
1881
+ tool: { color: tone.info, glyph: "\u25A3" },
1882
+ plan: { color: tone.accent, glyph: "\u229E" },
1883
+ diff: { color: tone.ok, glyph: "\xB1" },
1884
+ error: { color: tone.err, glyph: "\u2716" },
1885
+ warn: { color: tone.warn, glyph: "\u26A0" },
1886
+ usage: { color: fg.meta, glyph: "\u03A3" },
1887
+ subagent: { color: tone.violet, glyph: "\u232C" },
1888
+ approval: { color: tone.warn, glyph: "?" },
1889
+ search: { color: tone.info, glyph: "\u2299" },
1890
+ memory: { color: fg.meta, glyph: "\u2311" },
1891
+ ctx: { color: tone.brand, glyph: "\u25D4" },
1892
+ doctor: { color: fg.meta, glyph: "\u2695" },
1893
+ branch: { color: tone.violet, glyph: "\u2387" }
1894
+ };
1895
+ }
1896
+ function defineTheme(base) {
1897
+ return { ...base, card: card(base.fg, base.tone) };
1898
+ }
1899
+ var githubDark = defineTheme({
1900
+ fg: {
1901
+ strong: "#e6edf3",
1902
+ body: "#c9d1d9",
1903
+ sub: "#8b949e",
1904
+ meta: "#6e7681",
1905
+ faint: "#484f58"
1906
+ },
1907
+ tone: {
1908
+ brand: "#79c0ff",
1909
+ accent: "#d2a8ff",
1910
+ violet: "#b395f5",
1911
+ ok: "#7ee787",
1912
+ warn: "#f0b07d",
1913
+ err: "#ff8b81",
1914
+ info: "#79c0ff"
1915
+ },
1916
+ toneActive: {
1917
+ brand: "#a5d6ff",
1918
+ accent: "#e2c5ff",
1919
+ violet: "#c8aaff",
1920
+ ok: "#a8f5ad",
1921
+ warn: "#ffc99e",
1922
+ err: "#ffaba3",
1923
+ info: "#a5d6ff"
1924
+ },
1925
+ surface: {
1926
+ bg: "#0a0c10",
1927
+ bgInput: "#0d1015",
1928
+ bgCode: "#06080c",
1929
+ bgElev: "#11141a"
1930
+ }
1931
+ });
1932
+ var dark = defineTheme({
1933
+ fg: {
1934
+ strong: "#f4f7fb",
1935
+ body: "#d8dee9",
1936
+ sub: "#a7b1c2",
1937
+ meta: "#778294",
1938
+ faint: "#4d5666"
1939
+ },
1940
+ tone: {
1941
+ brand: "#7dd3fc",
1942
+ accent: "#c084fc",
1943
+ violet: "#a78bfa",
1944
+ ok: "#86efac",
1945
+ warn: "#fbbf24",
1946
+ err: "#f87171",
1947
+ info: "#60a5fa"
1948
+ },
1949
+ toneActive: {
1950
+ brand: "#bae6fd",
1951
+ accent: "#e9d5ff",
1952
+ violet: "#ddd6fe",
1953
+ ok: "#bbf7d0",
1954
+ warn: "#fde68a",
1955
+ err: "#fecaca",
1956
+ info: "#bfdbfe"
1957
+ },
1958
+ surface: {
1959
+ bg: "#0b1020",
1960
+ bgInput: "#111827",
1961
+ bgCode: "#080c16",
1962
+ bgElev: "#151d2f"
1963
+ }
1964
+ });
1965
+ var light = defineTheme({
1966
+ fg: {
1967
+ strong: "#111827",
1968
+ body: "#1f2937",
1969
+ sub: "#4b5563",
1970
+ meta: "#6b7280",
1971
+ faint: "#9ca3af"
1972
+ },
1973
+ tone: {
1974
+ brand: "#2563eb",
1975
+ accent: "#7c3aed",
1976
+ violet: "#6d28d9",
1977
+ ok: "#15803d",
1978
+ warn: "#b45309",
1979
+ err: "#dc2626",
1980
+ info: "#0369a1"
1981
+ },
1982
+ toneActive: {
1983
+ brand: "#1d4ed8",
1984
+ accent: "#6d28d9",
1985
+ violet: "#5b21b6",
1986
+ ok: "#166534",
1987
+ warn: "#92400e",
1988
+ err: "#b91c1c",
1989
+ info: "#075985"
1990
+ },
1991
+ surface: {
1992
+ bg: "#ffffff",
1993
+ bgInput: "#f8fafc",
1994
+ bgCode: "#f3f4f6",
1995
+ bgElev: "#eef2f7"
1996
+ }
1997
+ });
1998
+ var tokyoNight = defineTheme({
1999
+ fg: {
2000
+ strong: "#c0caf5",
2001
+ body: "#a9b1d6",
2002
+ sub: "#9aa5ce",
2003
+ meta: "#565f89",
2004
+ faint: "#414868"
2005
+ },
2006
+ tone: {
2007
+ brand: "#7aa2f7",
2008
+ accent: "#bb9af7",
2009
+ violet: "#9d7cd8",
2010
+ ok: "#9ece6a",
2011
+ warn: "#e0af68",
2012
+ err: "#f7768e",
2013
+ info: "#2ac3de"
2014
+ },
2015
+ toneActive: {
2016
+ brand: "#a9c7ff",
2017
+ accent: "#d7b9ff",
2018
+ violet: "#c6a0f6",
2019
+ ok: "#b9f27c",
2020
+ warn: "#ffd089",
2021
+ err: "#ff9cac",
2022
+ info: "#7dcfff"
2023
+ },
2024
+ surface: {
2025
+ bg: "#1a1b26",
2026
+ bgInput: "#1f2335",
2027
+ bgCode: "#16161e",
2028
+ bgElev: "#24283b"
2029
+ }
2030
+ });
2031
+ var githubLight = defineTheme({
2032
+ fg: {
2033
+ strong: "#1f2328",
2034
+ body: "#24292f",
2035
+ sub: "#57606a",
2036
+ meta: "#6e7781",
2037
+ faint: "#8c959f"
2038
+ },
2039
+ tone: {
2040
+ brand: "#0969da",
2041
+ accent: "#8250df",
2042
+ violet: "#6639ba",
2043
+ ok: "#1a7f37",
2044
+ warn: "#9a6700",
2045
+ err: "#cf222e",
2046
+ info: "#0969da"
2047
+ },
2048
+ toneActive: {
2049
+ brand: "#0550ae",
2050
+ accent: "#6639ba",
2051
+ violet: "#512a97",
2052
+ ok: "#116329",
2053
+ warn: "#7d4e00",
2054
+ err: "#a40e26",
2055
+ info: "#0550ae"
2056
+ },
2057
+ surface: {
2058
+ bg: "#ffffff",
2059
+ bgInput: "#f6f8fa",
2060
+ bgCode: "#f6f8fa",
2061
+ bgElev: "#eaeef2"
2062
+ }
2063
+ });
2064
+ var highContrast = defineTheme({
2065
+ fg: {
2066
+ strong: "#ffffff",
2067
+ body: "#f5f5f5",
2068
+ sub: "#d4d4d4",
2069
+ meta: "#bdbdbd",
2070
+ faint: "#8a8a8a"
2071
+ },
2072
+ tone: {
2073
+ brand: "#00e5ff",
2074
+ accent: "#ff4dff",
2075
+ violet: "#b388ff",
2076
+ ok: "#00ff66",
2077
+ warn: "#ffdd00",
2078
+ err: "#ff4d4d",
2079
+ info: "#4da3ff"
2080
+ },
2081
+ toneActive: {
2082
+ brand: "#80f2ff",
2083
+ accent: "#ff99ff",
2084
+ violet: "#d0b3ff",
2085
+ ok: "#80ffb3",
2086
+ warn: "#ffee80",
2087
+ err: "#ff9999",
2088
+ info: "#99c9ff"
2089
+ },
2090
+ surface: {
2091
+ bg: "#000000",
2092
+ bgInput: "#0a0a0a",
2093
+ bgCode: "#050505",
2094
+ bgElev: "#141414"
2095
+ }
2096
+ });
2097
+ var THEMES = {
2098
+ default: githubDark,
2099
+ dark,
2100
+ light,
2101
+ "tokyo-night": tokyoNight,
2102
+ "github-dark": githubDark,
2103
+ "github-light": githubLight,
2104
+ "high-contrast": highContrast
2105
+ };
2106
+ var DEFAULT_THEME_NAME = "default";
2107
+ function isThemeName(value) {
2108
+ return Object.prototype.hasOwnProperty.call(THEMES, value);
2109
+ }
2110
+ function resolveThemeName(value) {
2111
+ if (!value || value === "auto") return DEFAULT_THEME_NAME;
2112
+ return isThemeName(value) ? value : DEFAULT_THEME_NAME;
2113
+ }
2114
+ function listThemeNames() {
2115
+ return Object.keys(THEMES);
2116
+ }
2117
+ var DEFAULT_THEME = THEMES[DEFAULT_THEME_NAME];
2118
+ var activeTheme = DEFAULT_THEME;
2119
+ var activeThemeVersion = 0;
2120
+ function setActiveTheme(theme) {
2121
+ const previousTheme = activeTheme;
2122
+ activeTheme = theme;
2123
+ activeThemeVersion += 1;
2124
+ const version = activeThemeVersion;
2125
+ return () => {
2126
+ if (activeThemeVersion !== version || activeTheme !== theme) return;
2127
+ activeTheme = previousTheme;
2128
+ activeThemeVersion += 1;
2129
+ };
2130
+ }
2131
+ function proxyTokens(select) {
2132
+ const target = select(DEFAULT_THEME);
2133
+ return new Proxy(target, {
2134
+ get(_target, prop) {
2135
+ return select(activeTheme)[prop];
2136
+ },
2137
+ getOwnPropertyDescriptor(_target, prop) {
2138
+ return Reflect.getOwnPropertyDescriptor(select(activeTheme), prop);
2139
+ },
2140
+ has(_target, prop) {
2141
+ return prop in select(activeTheme);
2142
+ },
2143
+ ownKeys() {
2144
+ return Reflect.ownKeys(select(activeTheme));
2145
+ }
2146
+ });
2147
+ }
2148
+ var FG = proxyTokens((theme) => theme.fg);
2149
+ var TONE = proxyTokens((theme) => theme.tone);
2150
+ var TONE_ACTIVE = proxyTokens((theme) => theme.toneActive);
2151
+ var SURFACE = proxyTokens((theme) => theme.surface);
2152
+ var CARD = proxyTokens((theme) => theme.card);
2153
+ var USD_TO_CNY = 7.2;
2154
+ var SYMBOL = { USD: "$", CNY: "\xA5" };
2155
+ function formatBalance(amount, currency, opts) {
2156
+ const cur = currency ?? "CNY";
2157
+ const sym = SYMBOL[cur];
2158
+ const digits = opts?.fractionDigits ?? 2;
2159
+ const body = sym ? `${sym}${amount.toFixed(digits)}` : `${cur} ${amount.toFixed(digits)}`;
2160
+ return opts?.label ? `w ${body}` : body;
2161
+ }
2162
+ function formatCost(costUsd, currency, fractionDigits = 4) {
2163
+ const cur = currency ?? "CNY";
2164
+ const amount = cur === "CNY" ? costUsd * USD_TO_CNY : costUsd;
2165
+ return formatBalance(amount, cur, { fractionDigits });
2166
+ }
2167
+ function balanceColor(amount, currency) {
2168
+ const cny = (currency ?? "CNY") === "USD" ? amount * USD_TO_CNY : amount;
2169
+ if (cny < 5) return TONE.err;
2170
+ if (cny < 20) return TONE.warn;
2171
+ return TONE.brand;
2172
+ }
2173
+
2174
+ // src/index/config.ts
2175
+ var import_picomatch = __toESM(require_picomatch2(), 1);
2176
+ var DEFAULT_INDEX_EXCLUDES = {
2177
+ dirs: [
2178
+ "node_modules",
2179
+ ".git",
2180
+ ".hg",
2181
+ ".svn",
2182
+ "dist",
2183
+ "build",
2184
+ "out",
2185
+ ".next",
2186
+ ".nuxt",
2187
+ "target",
2188
+ ".venv",
2189
+ "venv",
2190
+ "__pycache__",
2191
+ ".pytest_cache",
2192
+ ".mypy_cache",
2193
+ ".cache",
2194
+ "coverage",
2195
+ ".turbo",
2196
+ ".vercel",
2197
+ ".reasonix"
2198
+ ],
2199
+ files: [
2200
+ "package-lock.json",
2201
+ "yarn.lock",
2202
+ "pnpm-lock.yaml",
2203
+ "Cargo.lock",
2204
+ "poetry.lock",
2205
+ "Pipfile.lock",
2206
+ "go.sum",
2207
+ ".DS_Store"
2208
+ ],
2209
+ exts: [
2210
+ ".png",
2211
+ ".jpg",
2212
+ ".jpeg",
2213
+ ".gif",
2214
+ ".webp",
2215
+ ".bmp",
2216
+ ".ico",
2217
+ ".tiff",
2218
+ ".woff",
2219
+ ".woff2",
2220
+ ".ttf",
2221
+ ".otf",
2222
+ ".eot",
2223
+ ".zip",
2224
+ ".tar",
2225
+ ".gz",
2226
+ ".bz2",
2227
+ ".xz",
2228
+ ".rar",
2229
+ ".7z",
2230
+ ".exe",
2231
+ ".dll",
2232
+ ".so",
2233
+ ".dylib",
2234
+ ".bin",
2235
+ ".class",
2236
+ ".jar",
2237
+ ".war",
2238
+ ".wasm",
2239
+ ".o",
2240
+ ".obj",
2241
+ ".lib",
2242
+ ".a",
2243
+ ".pyc",
2244
+ ".pyo",
2245
+ ".mp3",
2246
+ ".mp4",
2247
+ ".wav",
2248
+ ".ogg",
2249
+ ".webm",
2250
+ ".mov",
2251
+ ".avi",
2252
+ ".pdf",
2253
+ ".sqlite",
2254
+ ".db"
2255
+ ]
2256
+ };
2257
+ var DEFAULT_MAX_FILE_BYTES = 256 * 1024;
2258
+ var DEFAULT_RESPECT_GITIGNORE = true;
2259
+ function defaultIndexConfig() {
2260
+ return {
2261
+ excludeDirs: [...DEFAULT_INDEX_EXCLUDES.dirs],
2262
+ excludeFiles: [...DEFAULT_INDEX_EXCLUDES.files],
2263
+ excludeExts: [...DEFAULT_INDEX_EXCLUDES.exts],
2264
+ excludePatterns: [],
2265
+ respectGitignore: DEFAULT_RESPECT_GITIGNORE,
2266
+ maxFileBytes: DEFAULT_MAX_FILE_BYTES
2267
+ };
2268
+ }
2269
+ function resolveIndexConfig(user) {
2270
+ const d = defaultIndexConfig();
2271
+ if (!user) return d;
2272
+ return {
2273
+ excludeDirs: Array.isArray(user.excludeDirs) ? [...user.excludeDirs] : d.excludeDirs,
2274
+ excludeFiles: Array.isArray(user.excludeFiles) ? [...user.excludeFiles] : d.excludeFiles,
2275
+ excludeExts: Array.isArray(user.excludeExts) ? user.excludeExts.map((e) => e.toLowerCase()) : d.excludeExts,
2276
+ excludePatterns: Array.isArray(user.excludePatterns) ? [...user.excludePatterns] : [],
2277
+ respectGitignore: typeof user.respectGitignore === "boolean" ? user.respectGitignore : d.respectGitignore,
2278
+ maxFileBytes: typeof user.maxFileBytes === "number" && user.maxFileBytes > 0 ? user.maxFileBytes : d.maxFileBytes
2279
+ };
2280
+ }
2281
+ function compileFilters(cfg) {
2282
+ const matcher = cfg.excludePatterns.length === 0 ? () => false : (0, import_picomatch.default)(cfg.excludePatterns, { dot: true });
2283
+ return {
2284
+ dirSet: new Set(cfg.excludeDirs),
2285
+ fileSet: new Set(cfg.excludeFiles),
2286
+ extSet: new Set(cfg.excludeExts.map((e) => e.toLowerCase())),
2287
+ patternMatch: matcher,
2288
+ respectGitignore: cfg.respectGitignore,
2289
+ maxFileBytes: cfg.maxFileBytes
2290
+ };
2291
+ }
2292
+
2293
+ // src/qq/access.ts
2294
+ function normalizeQQOpenId(value) {
2295
+ const trimmed = value?.trim();
2296
+ return trimmed ? trimmed : void 0;
2297
+ }
2298
+ function normalizeQQAllowlist(values) {
2299
+ const list = typeof values === "string" ? values.split(/[,\s]+/) : Array.isArray(values) ? values : [];
2300
+ const seen = /* @__PURE__ */ new Set();
2301
+ const normalized = [];
2302
+ for (const raw of list) {
2303
+ const openid = normalizeQQOpenId(raw);
2304
+ if (!openid || seen.has(openid)) continue;
2305
+ seen.add(openid);
2306
+ normalized.push(openid);
2307
+ }
2308
+ return normalized.length > 0 ? normalized : void 0;
2309
+ }
2310
+ function redactQQOpenId(openid) {
2311
+ const normalized = normalizeQQOpenId(openid);
2312
+ if (!normalized) return "none";
2313
+ if (normalized.length <= 10) return normalized;
2314
+ return `${normalized.slice(0, 6)}...${normalized.slice(-4)}`;
2315
+ }
2316
+ function decideQQAccess(config, openid) {
2317
+ const candidate = normalizeQQOpenId(openid);
2318
+ if (!candidate) return { accept: false, reason: "unauthorized" };
2319
+ const ownerOpenId = normalizeQQOpenId(config.ownerOpenId);
2320
+ const allowlist = normalizeQQAllowlist(config.allowlist) ?? [];
2321
+ const runtimeBoundOpenId = normalizeQQOpenId(config.runtimeBoundOpenId);
2322
+ if (ownerOpenId && candidate === ownerOpenId) {
2323
+ return { accept: true, mode: "owner", bindRuntime: false };
2324
+ }
2325
+ if (allowlist.includes(candidate)) {
2326
+ return { accept: true, mode: "allowlist", bindRuntime: false };
2327
+ }
2328
+ if (ownerOpenId || allowlist.length > 0) {
2329
+ return { accept: false, reason: "unauthorized" };
2330
+ }
2331
+ if (runtimeBoundOpenId) {
2332
+ if (candidate === runtimeBoundOpenId) {
2333
+ return { accept: true, mode: "runtime", bindRuntime: false };
2334
+ }
2335
+ return { accept: false, reason: "unauthorized" };
2336
+ }
2337
+ return { accept: true, mode: "open", bindRuntime: true };
2338
+ }
2339
+ function describeQQAccess(config) {
2340
+ const ownerOpenId = normalizeQQOpenId(config.ownerOpenId);
2341
+ const allowlist = normalizeQQAllowlist(config.allowlist) ?? [];
2342
+ const runtimeBoundOpenId = normalizeQQOpenId(config.runtimeBoundOpenId);
2343
+ if (ownerOpenId) {
2344
+ const suffix = allowlist.length > 0 ? `, allowlist ${allowlist.length}` : "";
2345
+ return `owner ${redactQQOpenId(ownerOpenId)}${suffix}`;
2346
+ }
2347
+ if (allowlist.length > 0) {
2348
+ return `allowlist ${allowlist.length}`;
2349
+ }
2350
+ if (runtimeBoundOpenId) {
2351
+ return `first-sender (runtime only, ${redactQQOpenId(runtimeBoundOpenId)})`;
2352
+ }
2353
+ return "open (unbound)";
2354
+ }
2355
+
2356
+ // src/config.ts
2357
+ var BUILTIN_TYPE_DOCS = {
2358
+ user: "role / skills / preferences",
2359
+ feedback: "corrections or confirmed approaches",
2360
+ project: "facts / decisions about the current work",
2361
+ reference: "pointers to external systems the user uses"
2362
+ };
2363
+ function loadMemoryTypeRegistry(cfg = readConfig()) {
2364
+ const out = [];
2365
+ for (const name of ["user", "feedback", "project", "reference"]) {
2366
+ out.push({ name, builtin: true, description: BUILTIN_TYPE_DOCS[name] });
2367
+ }
2368
+ const seen = new Set(out.map((e) => e.name));
2369
+ for (const raw of cfg.memory?.customTypes ?? []) {
2370
+ if (!raw || typeof raw.name !== "string") continue;
2371
+ const name = raw.name.trim();
2372
+ if (!name || !/^[a-zA-Z][a-zA-Z0-9_-]{0,31}$/.test(name)) continue;
2373
+ if (seen.has(name)) continue;
2374
+ seen.add(name);
2375
+ const entry = { name, builtin: false };
2376
+ if (typeof raw.description === "string") entry.description = raw.description;
2377
+ if (raw.priority === "low" || raw.priority === "medium" || raw.priority === "high") {
2378
+ entry.priority = raw.priority;
2379
+ }
2380
+ if (raw.expires === "project_end") entry.expires = raw.expires;
2381
+ out.push(entry);
2382
+ }
2383
+ return out;
2384
+ }
2385
+ function memoryTypeDefaults(typeName, cfg = readConfig()) {
2386
+ const found = loadMemoryTypeRegistry(cfg).find((e) => e.name === typeName);
2387
+ if (!found) return {};
2388
+ const out = {};
2389
+ if (found.priority) out.priority = found.priority;
2390
+ if (found.expires) out.expires = found.expires;
2391
+ return out;
2392
+ }
2393
+ var DEFAULT_METASO_API_KEY = "mk-E384C1DD5E8501BB7EFE27C949AFDE5B";
2394
+ function loadMetasoApiKey(path = defaultConfigPath()) {
2395
+ if (process.env.METASO_API_KEY) return process.env.METASO_API_KEY;
2396
+ const cfg = readConfig(path).metasoApiKey;
2397
+ if (cfg && typeof cfg === "string" && cfg.trim()) return cfg.trim();
2398
+ return DEFAULT_METASO_API_KEY;
2399
+ }
2400
+ var DEFAULT_OLLAMA_URL = "http://localhost:11434";
2401
+ var DEFAULT_EMBED_MODEL = "nomic-embed-text";
2402
+ var DEFAULT_TIMEOUT_MS = 3e4;
2403
+ var DEFAULT_BATCH_SIZE = 10;
2404
+ function defaultConfigPath() {
2405
+ return join(homedir(), ".carboncode", "config.json");
2406
+ }
2407
+ function readConfig(path = defaultConfigPath()) {
2408
+ try {
2409
+ const raw = readFileSync(path, "utf8");
2410
+ const parsed = JSON.parse(raw);
2411
+ if (parsed && typeof parsed === "object") return parsed;
2412
+ } catch {
2413
+ }
2414
+ return {};
2415
+ }
2416
+ function writeConfig(cfg, path = defaultConfigPath()) {
2417
+ mkdirSync(dirname(path), { recursive: true });
2418
+ writeFileSync(path, JSON.stringify(cfg, null, 2), "utf8");
2419
+ try {
2420
+ chmodSync(path, 384);
2421
+ } catch {
2422
+ }
2423
+ }
2424
+ function loadLanguage(path = defaultConfigPath()) {
2425
+ return readConfig(path).lang;
2426
+ }
2427
+ function inferMcpTransport(cfg) {
2428
+ if (cfg.transport) return cfg.transport;
2429
+ const url = cfg.url?.trim() ?? "";
2430
+ if (/^streamable\+https?:\/\//i.test(url)) return "streamable-http";
2431
+ if (/^https?:\/\//i.test(url)) return "sse";
2432
+ return "stdio";
2433
+ }
2434
+ function normalizeStringRecord(value) {
2435
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
2436
+ const out = {};
2437
+ for (const [k, v] of Object.entries(value)) {
2438
+ if (typeof v === "string" && v.length > 0) out[k] = v;
2439
+ }
2440
+ return Object.keys(out).length > 0 ? out : void 0;
2441
+ }
2442
+ function normalizeMcpConfig(cfg, extraLegacy) {
2443
+ const result = [];
2444
+ const seen = /* @__PURE__ */ new Set();
2445
+ const disabledFromLegacy = new Set(cfg.mcpDisabled ?? []);
2446
+ const legacySpecs = extraLegacy && extraLegacy.length > 0 ? extraLegacy : cfg.mcp ?? [];
2447
+ for (const raw of legacySpecs) {
2448
+ if (typeof raw !== "string") continue;
2449
+ try {
2450
+ const spec = parseMcpSpec(raw);
2451
+ const env = spec.name ? normalizeStringRecord(cfg.mcpEnv?.[spec.name]) : void 0;
2452
+ const disabled = spec.name ? disabledFromLegacy.has(spec.name) : false;
2453
+ if (spec.transport === "stdio") {
2454
+ result.push({ ...spec, env, disabled });
2455
+ } else if (spec.transport === "sse") {
2456
+ result.push({ ...spec, disabled });
2457
+ } else {
2458
+ result.push({ ...spec, disabled });
2459
+ }
2460
+ if (spec.name) seen.add(spec.name);
2461
+ } catch {
2462
+ }
2463
+ }
2464
+ for (const [name, serverCfg] of Object.entries(cfg.mcpServers ?? {})) {
2465
+ if (!serverCfg || typeof serverCfg !== "object") continue;
2466
+ const transport = inferMcpTransport(serverCfg);
2467
+ const disabled = serverCfg.disabled === true;
2468
+ if (transport === "stdio") {
2469
+ const env = normalizeStringRecord(serverCfg.env);
2470
+ const spec = {
2471
+ transport: "stdio",
2472
+ name,
2473
+ command: serverCfg.command ?? "",
2474
+ args: serverCfg.args ?? [],
2475
+ env,
2476
+ disabled
2477
+ };
2478
+ if (seen.has(name)) {
2479
+ const idx = result.findIndex((s) => s.name === name);
2480
+ if (idx >= 0) result[idx] = spec;
2481
+ } else {
2482
+ seen.add(name);
2483
+ result.push(spec);
2484
+ }
2485
+ } else {
2486
+ let url = serverCfg.url ?? "";
2487
+ const streamMatch = /^streamable\+(https?:\/\/.+)$/i.exec(url);
2488
+ if (streamMatch) url = streamMatch[1];
2489
+ const headers = normalizeStringRecord(serverCfg.headers);
2490
+ if (transport === "sse") {
2491
+ const spec = {
2492
+ transport: "sse",
2493
+ name,
2494
+ url,
2495
+ headers,
2496
+ disabled
2497
+ };
2498
+ if (seen.has(name)) {
2499
+ const idx = result.findIndex((s) => s.name === name);
2500
+ if (idx >= 0) result[idx] = spec;
2501
+ } else {
2502
+ seen.add(name);
2503
+ result.push(spec);
2504
+ }
2505
+ } else {
2506
+ const spec = {
2507
+ transport: "streamable-http",
2508
+ name,
2509
+ url,
2510
+ headers,
2511
+ disabled
2512
+ };
2513
+ if (seen.has(name)) {
2514
+ const idx = result.findIndex((s) => s.name === name);
2515
+ if (idx >= 0) result[idx] = spec;
2516
+ } else {
2517
+ seen.add(name);
2518
+ result.push(spec);
2519
+ }
2520
+ }
2521
+ }
2522
+ }
2523
+ return result;
2524
+ }
2525
+ function saveLanguage(lang, path = defaultConfigPath()) {
2526
+ const cfg = readConfig(path);
2527
+ cfg.lang = lang;
2528
+ writeConfig(cfg, path);
2529
+ }
2530
+ function loadApiKey(path = defaultConfigPath()) {
2531
+ if (process.env.DEEPSEEK_API_KEY) return process.env.DEEPSEEK_API_KEY;
2532
+ return readConfig(path).apiKey;
2533
+ }
2534
+ function loadBaseUrl(path = defaultConfigPath()) {
2535
+ if (process.env.DEEPSEEK_BASE_URL) return process.env.DEEPSEEK_BASE_URL;
2536
+ return readConfig(path).baseUrl;
2537
+ }
2538
+ function isNonNegativeNumber(value) {
2539
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
2540
+ }
2541
+ function loadPricingOverride(path = defaultConfigPath()) {
2542
+ const raw = readConfig(path).pricingOverride;
2543
+ if (!isPlainObject(raw)) return {};
2544
+ const result = {};
2545
+ for (const [model, value] of Object.entries(raw)) {
2546
+ if (!isPlainObject(value)) continue;
2547
+ const pricing = {};
2548
+ if (isNonNegativeNumber(value.inputCacheHit)) pricing.inputCacheHit = value.inputCacheHit;
2549
+ if (isNonNegativeNumber(value.inputCacheMiss)) pricing.inputCacheMiss = value.inputCacheMiss;
2550
+ if (isNonNegativeNumber(value.output)) pricing.output = value.output;
2551
+ if (Object.keys(pricing).length > 0) result[model] = pricing;
2552
+ }
2553
+ return result;
2554
+ }
2555
+ function loadRateLimit(path = defaultConfigPath()) {
2556
+ const rpm = readConfig(path).rateLimit?.rpm;
2557
+ if (typeof rpm !== "number" || !Number.isInteger(rpm) || rpm <= 0) return void 0;
2558
+ return { rpm };
2559
+ }
2560
+ function saveBaseUrl(url, path = defaultConfigPath()) {
2561
+ const cfg = readConfig(path);
2562
+ const trimmed = url.trim();
2563
+ if (trimmed) {
2564
+ cfg.baseUrl = trimmed;
2565
+ } else {
2566
+ cfg.baseUrl = void 0;
2567
+ }
2568
+ writeConfig(cfg, path);
2569
+ }
2570
+ function resolveSkillPath(raw, baseDir) {
2571
+ const homeExpanded = expandCurrentUserHome(raw.trim());
2572
+ return resolve(isAbsolute(homeExpanded) ? homeExpanded : join(baseDir, homeExpanded));
2573
+ }
2574
+ function normalizeSkillPathEntries(paths, baseDir) {
2575
+ const out = [];
2576
+ const seen = /* @__PURE__ */ new Set();
2577
+ for (const value of paths) {
2578
+ if (typeof value !== "string") continue;
2579
+ const raw = value.trim();
2580
+ if (!raw) continue;
2581
+ const resolved = resolveSkillPath(raw, baseDir);
2582
+ const key = skillPathKey(resolved);
2583
+ if (seen.has(key)) continue;
2584
+ seen.add(key);
2585
+ out.push({ raw, resolved });
2586
+ }
2587
+ return out;
2588
+ }
2589
+ function normalizeSkillPaths(paths, baseDir) {
2590
+ return normalizeSkillPathEntries(paths, baseDir).map((entry) => entry.raw);
2591
+ }
2592
+ function resolveSkillPaths(paths, baseDir) {
2593
+ return normalizeSkillPathEntries(paths, baseDir).map((entry) => entry.resolved);
2594
+ }
2595
+ function skillPathKey(path) {
2596
+ return process.platform === "win32" ? path.toLowerCase() : path;
2597
+ }
2598
+ function expandCurrentUserHome(path) {
2599
+ if (path === "~") return homedir();
2600
+ if (path.startsWith("~/") || path.startsWith("~\\")) return join(homedir(), path.slice(2));
2601
+ return path;
2602
+ }
2603
+ function loadSkillPaths(baseDir = process.cwd(), path = defaultConfigPath()) {
2604
+ const raw = readConfig(path).skills?.paths;
2605
+ return Array.isArray(raw) ? normalizeSkillPaths(raw, baseDir) : [];
2606
+ }
2607
+ function loadResolvedSkillPaths(baseDir = process.cwd(), path = defaultConfigPath()) {
2608
+ const raw = readConfig(path).skills?.paths;
2609
+ return Array.isArray(raw) ? resolveSkillPaths(raw, baseDir) : [];
2610
+ }
2611
+ function saveSkillPaths(paths, baseDir = process.cwd(), path = defaultConfigPath()) {
2612
+ const cfg = readConfig(path);
2613
+ const normalized = normalizeSkillPaths(paths, baseDir);
2614
+ cfg.skills = { ...cfg.skills ?? {}, paths: normalized };
2615
+ writeConfig(cfg, path);
2616
+ return normalized;
2617
+ }
2618
+ function addSkillPath(skillPath, baseDir = process.cwd(), path = defaultConfigPath()) {
2619
+ const entry = normalizeSkillPathEntries([skillPath], baseDir)[0];
2620
+ if (!entry) return { error: "skill path is empty" };
2621
+ const existing = loadSkillPaths(baseDir, path);
2622
+ const seen = new Set(resolveSkillPaths(existing, baseDir).map(skillPathKey));
2623
+ const key = skillPathKey(entry.resolved);
2624
+ if (seen.has(key))
2625
+ return { added: false, path: entry.raw, resolved: entry.resolved, paths: existing };
2626
+ const paths = saveSkillPaths([...existing, entry.raw], baseDir, path);
2627
+ return { added: true, path: entry.raw, resolved: entry.resolved, paths };
2628
+ }
2629
+ function removeSkillPath(target, baseDir = process.cwd(), path = defaultConfigPath()) {
2630
+ const existing = loadSkillPaths(baseDir, path);
2631
+ const trimmed = target.trim();
2632
+ if (!trimmed) return { removed: false, paths: existing };
2633
+ const existingEntries = normalizeSkillPathEntries(existing, baseDir);
2634
+ const idx = /^\d+$/.test(trimmed) ? Number.parseInt(trimmed, 10) - 1 : -1;
2635
+ let removeAt = idx >= 0 && idx < existing.length ? idx : -1;
2636
+ if (removeAt < 0) {
2637
+ const targetEntry = normalizeSkillPathEntries([trimmed], baseDir)[0];
2638
+ const targetKey = targetEntry ? skillPathKey(targetEntry.resolved) : void 0;
2639
+ removeAt = existingEntries.findIndex(
2640
+ (entry) => entry.raw === trimmed || targetKey !== void 0 && skillPathKey(entry.resolved) === targetKey
2641
+ );
2642
+ }
2643
+ if (removeAt < 0) return { removed: false, paths: existing };
2644
+ const removed = existingEntries[removeAt];
2645
+ const paths = saveSkillPaths(
2646
+ existing.filter((_, i) => i !== removeAt),
2647
+ baseDir,
2648
+ path
2649
+ );
2650
+ return {
2651
+ removed: true,
2652
+ path: removed?.raw ?? existing[removeAt],
2653
+ resolved: removed?.resolved,
2654
+ paths
2655
+ };
2656
+ }
2657
+ function searchEnabled(path = defaultConfigPath()) {
2658
+ const env = process.env.CARBONCODE_SEARCH ?? process.env.REASONIX_SEARCH;
2659
+ if (env === "off" || env === "false" || env === "0") return false;
2660
+ const cfg = readConfig(path).search;
2661
+ if (cfg === false) return false;
2662
+ return true;
2663
+ }
2664
+ function webSearchEngine(path = defaultConfigPath()) {
2665
+ const cfg = readConfig(path).webSearchEngine;
2666
+ if (cfg === "searxng") return "searxng";
2667
+ if (cfg === "metaso") return "metaso";
2668
+ return "mojeek";
2669
+ }
2670
+ function webSearchEndpoint(path = defaultConfigPath()) {
2671
+ const cfg = readConfig(path).webSearchEndpoint;
2672
+ if (cfg && typeof cfg === "string") return cfg;
2673
+ return "http://localhost:8080";
2674
+ }
2675
+ function saveApiKey(key, path = defaultConfigPath()) {
2676
+ const cfg = readConfig(path);
2677
+ cfg.apiKey = key.trim();
2678
+ writeConfig(cfg, path);
2679
+ }
2680
+ function findProjectKey(cfg, rootDir) {
2681
+ const projects = cfg.projects;
2682
+ if (!projects) return void 0;
2683
+ if (Object.hasOwn(projects, rootDir)) return rootDir;
2684
+ if (process.platform !== "win32") return void 0;
2685
+ const lower = rootDir.toLowerCase();
2686
+ for (const k of Object.keys(projects)) {
2687
+ if (k.toLowerCase() === lower) return k;
2688
+ }
2689
+ return void 0;
2690
+ }
2691
+ function loadProjectShellAllowed(rootDir, path = defaultConfigPath()) {
2692
+ const cfg = readConfig(path);
2693
+ const key = findProjectKey(cfg, rootDir);
2694
+ if (key === void 0) return [];
2695
+ return cfg.projects?.[key]?.shellAllowed ?? [];
2696
+ }
2697
+ function addProjectShellAllowed(rootDir, prefix, path = defaultConfigPath()) {
2698
+ const trimmed = prefix.trim();
2699
+ if (!trimmed) return;
2700
+ const cfg = readConfig(path);
2701
+ if (!cfg.projects) cfg.projects = {};
2702
+ const key = findProjectKey(cfg, rootDir) ?? rootDir;
2703
+ if (!cfg.projects[key]) cfg.projects[key] = {};
2704
+ const existing = cfg.projects[key].shellAllowed ?? [];
2705
+ if (existing.includes(trimmed)) return;
2706
+ cfg.projects[key].shellAllowed = [...existing, trimmed];
2707
+ writeConfig(cfg, path);
2708
+ }
2709
+ function removeProjectShellAllowed(rootDir, prefix, path = defaultConfigPath()) {
2710
+ const trimmed = prefix.trim();
2711
+ if (!trimmed) return false;
2712
+ const cfg = readConfig(path);
2713
+ const key = findProjectKey(cfg, rootDir);
2714
+ if (key === void 0) return false;
2715
+ const existing = cfg.projects?.[key]?.shellAllowed ?? [];
2716
+ if (!existing.includes(trimmed)) return false;
2717
+ const next = existing.filter((p) => p !== trimmed);
2718
+ if (!cfg.projects) cfg.projects = {};
2719
+ if (!cfg.projects[key]) cfg.projects[key] = {};
2720
+ cfg.projects[key].shellAllowed = next;
2721
+ writeConfig(cfg, path);
2722
+ return true;
2723
+ }
2724
+ function clearProjectShellAllowed(rootDir, path = defaultConfigPath()) {
2725
+ const cfg = readConfig(path);
2726
+ const key = findProjectKey(cfg, rootDir);
2727
+ if (key === void 0) return 0;
2728
+ const existing = cfg.projects?.[key]?.shellAllowed ?? [];
2729
+ if (existing.length === 0) return 0;
2730
+ if (!cfg.projects) cfg.projects = {};
2731
+ if (!cfg.projects[key]) cfg.projects[key] = {};
2732
+ cfg.projects[key].shellAllowed = [];
2733
+ writeConfig(cfg, path);
2734
+ return existing.length;
2735
+ }
2736
+ function loadProjectPathAllowed(rootDir, path = defaultConfigPath()) {
2737
+ const cfg = readConfig(path);
2738
+ const key = findProjectKey(cfg, rootDir);
2739
+ if (key === void 0) return [];
2740
+ return cfg.projects?.[key]?.pathAllowed ?? [];
2741
+ }
2742
+ function addProjectPathAllowed(rootDir, prefix, path = defaultConfigPath()) {
2743
+ const trimmed = prefix.trim();
2744
+ if (!trimmed) return;
2745
+ const cfg = readConfig(path);
2746
+ if (!cfg.projects) cfg.projects = {};
2747
+ const key = findProjectKey(cfg, rootDir) ?? rootDir;
2748
+ if (!cfg.projects[key]) cfg.projects[key] = {};
2749
+ const existing = cfg.projects[key].pathAllowed ?? [];
2750
+ if (existing.includes(trimmed)) return;
2751
+ cfg.projects[key].pathAllowed = [...existing, trimmed];
2752
+ writeConfig(cfg, path);
2753
+ }
2754
+ function loadEditMode(path = defaultConfigPath()) {
2755
+ const v = readConfig(path).editMode;
2756
+ if (v === "auto" || v === "yolo") return v;
2757
+ return "review";
2758
+ }
2759
+ function saveEditMode(mode, path = defaultConfigPath()) {
2760
+ const cfg = readConfig(path);
2761
+ cfg.editMode = mode;
2762
+ writeConfig(cfg, path);
2763
+ }
2764
+ function editModeHintShown(path = defaultConfigPath()) {
2765
+ return readConfig(path).editModeHintShown === true;
2766
+ }
2767
+ function mouseClipboardHintShown(path = defaultConfigPath()) {
2768
+ return readConfig(path).mouseClipboardHintShown === true;
2769
+ }
2770
+ function loadReasoningEffort(path = defaultConfigPath()) {
2771
+ const v = readConfig(path).reasoningEffort;
2772
+ return v === "high" ? "high" : "max";
2773
+ }
2774
+ function loadTheme(path = defaultConfigPath()) {
2775
+ const value = readConfig(path).theme;
2776
+ if (value === "auto") return "auto";
2777
+ if (typeof value === "string" && isThemeName(value)) return value;
2778
+ return void 0;
2779
+ }
2780
+ function resolveThemePreference(configTheme, envTheme) {
2781
+ if (configTheme && configTheme !== "auto") return configTheme;
2782
+ return resolveThemeName(envTheme);
2783
+ }
2784
+ function saveTheme(theme, path = defaultConfigPath()) {
2785
+ const cfg = readConfig(path);
2786
+ cfg.theme = theme;
2787
+ writeConfig(cfg, path);
2788
+ }
2789
+ function saveReasoningEffort(effort, path = defaultConfigPath()) {
2790
+ const cfg = readConfig(path);
2791
+ cfg.reasoningEffort = effort;
2792
+ writeConfig(cfg, path);
2793
+ }
2794
+ function loadWorkspaceDir(path = defaultConfigPath()) {
2795
+ const v = readConfig(path).workspaceDir;
2796
+ return typeof v === "string" && v.trim() ? v : void 0;
2797
+ }
2798
+ function saveWorkspaceDir(dir, path = defaultConfigPath()) {
2799
+ const cfg = readConfig(path);
2800
+ const trimmed = dir.trim();
2801
+ if (trimmed) cfg.workspaceDir = trimmed;
2802
+ else cfg.workspaceDir = void 0;
2803
+ writeConfig(cfg, path);
2804
+ }
2805
+ function loadEditor(path = defaultConfigPath()) {
2806
+ const v = readConfig(path).editor;
2807
+ return typeof v === "string" && v.trim() ? v : void 0;
2808
+ }
2809
+ function saveEditor(editor, path = defaultConfigPath()) {
2810
+ const cfg = readConfig(path);
2811
+ const trimmed = editor.trim();
2812
+ if (trimmed) cfg.editor = trimmed;
2813
+ else cfg.editor = void 0;
2814
+ writeConfig(cfg, path);
2815
+ }
2816
+ function loadRecentWorkspaces(path = defaultConfigPath()) {
2817
+ const v = readConfig(path).recentWorkspaces;
2818
+ return Array.isArray(v) ? v.filter((s) => typeof s === "string") : [];
2819
+ }
2820
+ var MAX_RECENT_WORKSPACES = 8;
2821
+ function pushRecentWorkspace(dir, path = defaultConfigPath()) {
2822
+ const trimmed = dir.trim();
2823
+ if (!trimmed) return;
2824
+ const cfg = readConfig(path);
2825
+ const list = (cfg.recentWorkspaces ?? []).filter((s) => s !== trimmed);
2826
+ list.unshift(trimmed);
2827
+ cfg.recentWorkspaces = list.slice(0, MAX_RECENT_WORKSPACES);
2828
+ writeConfig(cfg, path);
2829
+ }
2830
+ function loadDesktopOpenTabs(path = defaultConfigPath()) {
2831
+ const v = readConfig(path).desktopOpenTabs;
2832
+ return Array.isArray(v) ? v.filter((s) => typeof s === "string" && s.length > 0) : [];
2833
+ }
2834
+ function saveDesktopOpenTabs(dirs, path = defaultConfigPath()) {
2835
+ const cfg = readConfig(path);
2836
+ const cleaned = dirs.filter((s) => typeof s === "string" && s.length > 0);
2837
+ if (cleaned.length === 0) {
2838
+ cfg.desktopOpenTabs = void 0;
2839
+ } else {
2840
+ cfg.desktopOpenTabs = cleaned;
2841
+ }
2842
+ writeConfig(cfg, path);
2843
+ }
2844
+ function loadPreset(path = defaultConfigPath()) {
2845
+ return readConfig(path).preset;
2846
+ }
2847
+ function savePreset(preset, path = defaultConfigPath()) {
2848
+ const cfg = readConfig(path);
2849
+ cfg.preset = preset;
2850
+ writeConfig(cfg, path);
2851
+ }
2852
+ function loadIndexUserConfig(path = defaultConfigPath()) {
2853
+ return readConfig(path).index ?? {};
2854
+ }
2855
+ function loadIndexConfig(path = defaultConfigPath()) {
2856
+ return resolveIndexConfig(readConfig(path).index);
2857
+ }
2858
+ function loadSemanticEmbeddingUserConfig(path = defaultConfigPath()) {
2859
+ return normalizeSemanticEmbeddingUserConfig(readConfig(path).semantic);
2860
+ }
2861
+ function saveSemanticEmbeddingConfig(user, path = defaultConfigPath()) {
2862
+ const cfg = readConfig(path);
2863
+ cfg.semantic = normalizeSemanticEmbeddingUserConfig(user);
2864
+ writeConfig(cfg, path);
2865
+ }
2866
+ function resolveSemanticEmbeddingConfig(path = defaultConfigPath()) {
2867
+ const user = loadSemanticEmbeddingUserConfig(path);
2868
+ const provider = user.provider ?? "ollama";
2869
+ if (provider === "openai-compat") {
2870
+ const baseUrl = user.openaiCompat?.baseUrl?.trim() ?? "";
2871
+ const apiKey = user.openaiCompat?.apiKey?.trim() ?? "";
2872
+ const model = user.openaiCompat?.model?.trim() ?? "";
2873
+ if (!baseUrl) throw new Error("OpenAI-compatible embeddings require an API URL.");
2874
+ requireValidUrl(baseUrl, "OpenAI-compatible API URL");
2875
+ if (!apiKey) throw new Error("OpenAI-compatible embeddings require an API key.");
2876
+ if (!model) throw new Error("OpenAI-compatible embeddings require a model.");
2877
+ return {
2878
+ provider,
2879
+ baseUrl,
2880
+ apiKey,
2881
+ model,
2882
+ extraBody: normalizeExtraBody(user.openaiCompat?.extraBody),
2883
+ timeoutMs: DEFAULT_TIMEOUT_MS,
2884
+ batchSize: user.openaiCompat?.batchSize ?? DEFAULT_BATCH_SIZE
2885
+ };
2886
+ }
2887
+ return {
2888
+ provider: "ollama",
2889
+ baseUrl: user.ollama?.baseUrl?.trim() || process.env.OLLAMA_URL || DEFAULT_OLLAMA_URL,
2890
+ model: user.ollama?.model?.trim() || process.env.REASONIX_EMBED_MODEL || DEFAULT_EMBED_MODEL,
2891
+ timeoutMs: DEFAULT_TIMEOUT_MS
2892
+ };
2893
+ }
2894
+ function redactSemanticEmbeddingConfig(user) {
2895
+ const normalized = normalizeSemanticEmbeddingUserConfig(user);
2896
+ return {
2897
+ provider: normalized.provider ?? "ollama",
2898
+ ollama: {
2899
+ baseUrl: normalized.ollama?.baseUrl?.trim() || process.env.OLLAMA_URL || DEFAULT_OLLAMA_URL,
2900
+ model: normalized.ollama?.model?.trim() || process.env.REASONIX_EMBED_MODEL || DEFAULT_EMBED_MODEL
2901
+ },
2902
+ openaiCompat: {
2903
+ baseUrl: normalized.openaiCompat?.baseUrl?.trim() ?? "",
2904
+ apiKey: normalized.openaiCompat?.apiKey ? redactKey(normalized.openaiCompat.apiKey) : "",
2905
+ apiKeySet: Boolean(normalized.openaiCompat?.apiKey?.trim()),
2906
+ model: normalized.openaiCompat?.model?.trim() ?? "",
2907
+ extraBody: normalizeExtraBody(normalized.openaiCompat?.extraBody),
2908
+ batchSize: normalized.openaiCompat?.batchSize ?? DEFAULT_BATCH_SIZE
2909
+ }
2910
+ };
2911
+ }
2912
+ function markEditModeHintShown(path = defaultConfigPath()) {
2913
+ const cfg = readConfig(path);
2914
+ if (cfg.editModeHintShown === true) return;
2915
+ cfg.editModeHintShown = true;
2916
+ writeConfig(cfg, path);
2917
+ }
2918
+ function markMouseClipboardHintShown(path = defaultConfigPath()) {
2919
+ const cfg = readConfig(path);
2920
+ if (cfg.mouseClipboardHintShown === true) return;
2921
+ cfg.mouseClipboardHintShown = true;
2922
+ writeConfig(cfg, path);
2923
+ }
2924
+ function isPlausibleKey(key) {
2925
+ const trimmed = key.trim();
2926
+ if (trimmed.length < 16) return false;
2927
+ return !/\s/.test(trimmed);
2928
+ }
2929
+ function redactKey(key) {
2930
+ if (!key) return "";
2931
+ if (key.length <= 12) return "****";
2932
+ return `${key.slice(0, 6)}\u2026${key.slice(-4)}`;
2933
+ }
2934
+ function normalizeSemanticEmbeddingUserConfig(cfg) {
2935
+ return {
2936
+ provider: cfg?.provider === "openai-compat" ? "openai-compat" : "ollama",
2937
+ ollama: {
2938
+ baseUrl: normalizeOptionalString(cfg?.ollama?.baseUrl),
2939
+ model: normalizeOptionalString(cfg?.ollama?.model)
2940
+ },
2941
+ openaiCompat: {
2942
+ baseUrl: normalizeOptionalString(cfg?.openaiCompat?.baseUrl),
2943
+ apiKey: normalizeOptionalString(cfg?.openaiCompat?.apiKey),
2944
+ model: normalizeOptionalString(cfg?.openaiCompat?.model),
2945
+ extraBody: normalizeExtraBody(cfg?.openaiCompat?.extraBody),
2946
+ batchSize: normalizePositiveInt(cfg?.openaiCompat?.batchSize)
2947
+ }
2948
+ };
2949
+ }
2950
+ function normalizeOptionalString(value) {
2951
+ const trimmed = value?.trim();
2952
+ return trimmed ? trimmed : void 0;
2953
+ }
2954
+ function normalizePositiveInt(value) {
2955
+ return value !== void 0 && Number.isInteger(value) && value > 0 ? value : void 0;
2956
+ }
2957
+ function normalizeExtraBody(value) {
2958
+ if (value === void 0) return {};
2959
+ if (!isPlainObject(value)) {
2960
+ throw new Error("Semantic embedding extraBody must be a JSON object.");
2961
+ }
2962
+ return { ...value };
2963
+ }
2964
+ function requireValidUrl(value, label) {
2965
+ try {
2966
+ new URL(value);
2967
+ } catch {
2968
+ throw new Error(`${label} must be a valid URL.`);
2969
+ }
2970
+ }
2971
+ function isPlainObject(value) {
2972
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
2973
+ const proto = Object.getPrototypeOf(value);
2974
+ return proto === Object.prototype || proto === null;
2975
+ }
2976
+ function loadQQConfig(path = defaultConfigPath()) {
2977
+ const envSandbox = process.env.QQ_SANDBOX;
2978
+ const envAllowlist = normalizeQQAllowlist(process.env.QQ_ALLOWLIST);
2979
+ const fromEnv = {
2980
+ appId: process.env.QQ_APPID,
2981
+ appSecret: process.env.QQ_SECRET,
2982
+ sandbox: envSandbox === "1" ? true : envSandbox === "0" ? false : void 0,
2983
+ ownerOpenId: normalizeQQOpenId(process.env.QQ_OWNER_OPENID),
2984
+ allowlist: envAllowlist
2985
+ };
2986
+ const fromCfg = readConfig(path).qq ?? {};
2987
+ const ownerOpenId = fromEnv.ownerOpenId ?? normalizeQQOpenId(fromCfg.ownerOpenId);
2988
+ const allowlist = normalizeQQAllowlist(fromEnv.allowlist ?? fromCfg.allowlist)?.filter(
2989
+ (openid) => openid !== ownerOpenId
2990
+ );
2991
+ return {
2992
+ appId: fromEnv.appId ?? fromCfg.appId,
2993
+ appSecret: fromEnv.appSecret ?? fromCfg.appSecret,
2994
+ sandbox: fromEnv.sandbox ?? fromCfg.sandbox ?? false,
2995
+ enabled: fromCfg.enabled === true,
2996
+ ownerOpenId,
2997
+ allowlist
2998
+ };
2999
+ }
3000
+ function saveQQConfig(cfg, path = defaultConfigPath()) {
3001
+ const rootCfg = readConfig(path);
3002
+ const ownerOpenId = normalizeQQOpenId(cfg.ownerOpenId);
3003
+ const allowlist = normalizeQQAllowlist(cfg.allowlist)?.filter((openid) => openid !== ownerOpenId);
3004
+ rootCfg.qq = {
3005
+ appId: cfg.appId,
3006
+ appSecret: cfg.appSecret,
3007
+ sandbox: cfg.sandbox,
3008
+ enabled: cfg.enabled,
3009
+ ownerOpenId,
3010
+ allowlist
3011
+ };
3012
+ writeConfig(rootCfg, path);
3013
+ }
3014
+
3015
+ export {
3016
+ THEMES,
3017
+ DEFAULT_THEME_NAME,
3018
+ isThemeName,
3019
+ resolveThemeName,
3020
+ listThemeNames,
3021
+ setActiveTheme,
3022
+ FG,
3023
+ TONE,
3024
+ TONE_ACTIVE,
3025
+ SURFACE,
3026
+ CARD,
3027
+ formatBalance,
3028
+ formatCost,
3029
+ balanceColor,
3030
+ require_picomatch2 as require_picomatch,
3031
+ DEFAULT_INDEX_EXCLUDES,
3032
+ DEFAULT_MAX_FILE_BYTES,
3033
+ DEFAULT_RESPECT_GITIGNORE,
3034
+ defaultIndexConfig,
3035
+ resolveIndexConfig,
3036
+ compileFilters,
3037
+ overlayMatchedSpec,
3038
+ specToRaw,
3039
+ parseMcpSpec,
3040
+ redactQQOpenId,
3041
+ decideQQAccess,
3042
+ describeQQAccess,
3043
+ loadMemoryTypeRegistry,
3044
+ memoryTypeDefaults,
3045
+ loadMetasoApiKey,
3046
+ defaultConfigPath,
3047
+ readConfig,
3048
+ writeConfig,
3049
+ loadLanguage,
3050
+ normalizeMcpConfig,
3051
+ saveLanguage,
3052
+ loadApiKey,
3053
+ loadBaseUrl,
3054
+ loadPricingOverride,
3055
+ loadRateLimit,
3056
+ saveBaseUrl,
3057
+ normalizeSkillPathEntries,
3058
+ normalizeSkillPaths,
3059
+ resolveSkillPaths,
3060
+ loadSkillPaths,
3061
+ loadResolvedSkillPaths,
3062
+ addSkillPath,
3063
+ removeSkillPath,
3064
+ searchEnabled,
3065
+ webSearchEngine,
3066
+ webSearchEndpoint,
3067
+ saveApiKey,
3068
+ loadProjectShellAllowed,
3069
+ addProjectShellAllowed,
3070
+ removeProjectShellAllowed,
3071
+ clearProjectShellAllowed,
3072
+ loadProjectPathAllowed,
3073
+ addProjectPathAllowed,
3074
+ loadEditMode,
3075
+ saveEditMode,
3076
+ editModeHintShown,
3077
+ mouseClipboardHintShown,
3078
+ loadReasoningEffort,
3079
+ loadTheme,
3080
+ resolveThemePreference,
3081
+ saveTheme,
3082
+ saveReasoningEffort,
3083
+ loadWorkspaceDir,
3084
+ saveWorkspaceDir,
3085
+ loadEditor,
3086
+ saveEditor,
3087
+ loadRecentWorkspaces,
3088
+ pushRecentWorkspace,
3089
+ loadDesktopOpenTabs,
3090
+ saveDesktopOpenTabs,
3091
+ loadPreset,
3092
+ savePreset,
3093
+ loadIndexUserConfig,
3094
+ loadIndexConfig,
3095
+ loadSemanticEmbeddingUserConfig,
3096
+ saveSemanticEmbeddingConfig,
3097
+ resolveSemanticEmbeddingConfig,
3098
+ redactSemanticEmbeddingConfig,
3099
+ markEditModeHintShown,
3100
+ markMouseClipboardHintShown,
3101
+ isPlausibleKey,
3102
+ redactKey,
3103
+ loadQQConfig,
3104
+ saveQQConfig
3105
+ };
3106
+ //# sourceMappingURL=chunk-4MQ3VURH.js.map