@kairyou/agent-tools 0.3.0 → 0.5.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.
- package/README.md +57 -39
- package/README.zh-CN.md +54 -40
- package/dist/statusline/claude-statusline.mjs +1160 -0
- package/dist/usage/cli.mjs +25 -0
- package/dist/usage/codex-hook.mjs +144 -0
- package/dist/usage/core.mjs +1876 -0
- package/dist/usage/opencode-plugin.mjs +80 -0
- package/dist/usage/opencode-tui.mjs +46 -0
- package/integrations/statusline/claude-statusline.mjs +8 -38
- package/integrations/usage/core.mjs +13 -1074
- package/integrations/usage/lib/cache.mjs +110 -0
- package/integrations/usage/lib/config.mjs +99 -0
- package/integrations/usage/lib/context.mjs +138 -0
- package/integrations/usage/lib/format.mjs +265 -0
- package/integrations/usage/lib/http.mjs +186 -0
- package/integrations/usage/lib/routes.mjs +265 -0
- package/integrations/usage/lib/urls.mjs +48 -0
- package/package.json +5 -5
- package/scripts/build.mjs +65 -0
- package/scripts/install.mjs +26 -15
- package/scripts/build-vision.mjs +0 -35
|
@@ -0,0 +1,1160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// integrations/statusline/claude-statusline.mjs
|
|
4
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { basename, dirname, join } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
10
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
11
|
+
const len = text.length;
|
|
12
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
13
|
+
function scanHexDigits(count, exact) {
|
|
14
|
+
let digits = 0;
|
|
15
|
+
let value2 = 0;
|
|
16
|
+
while (digits < count || !exact) {
|
|
17
|
+
let ch = text.charCodeAt(pos);
|
|
18
|
+
if (ch >= 48 && ch <= 57) {
|
|
19
|
+
value2 = value2 * 16 + ch - 48;
|
|
20
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
21
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
22
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
23
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
24
|
+
} else {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
pos++;
|
|
28
|
+
digits++;
|
|
29
|
+
}
|
|
30
|
+
if (digits < count) {
|
|
31
|
+
value2 = -1;
|
|
32
|
+
}
|
|
33
|
+
return value2;
|
|
34
|
+
}
|
|
35
|
+
function setPosition(newPosition) {
|
|
36
|
+
pos = newPosition;
|
|
37
|
+
value = "";
|
|
38
|
+
tokenOffset = 0;
|
|
39
|
+
token = 16;
|
|
40
|
+
scanError = 0;
|
|
41
|
+
}
|
|
42
|
+
function scanNumber() {
|
|
43
|
+
let start = pos;
|
|
44
|
+
if (text.charCodeAt(pos) === 48) {
|
|
45
|
+
pos++;
|
|
46
|
+
} else {
|
|
47
|
+
pos++;
|
|
48
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
49
|
+
pos++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
53
|
+
pos++;
|
|
54
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
55
|
+
pos++;
|
|
56
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
57
|
+
pos++;
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
scanError = 3;
|
|
61
|
+
return text.substring(start, pos);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let end = pos;
|
|
65
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
66
|
+
pos++;
|
|
67
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
68
|
+
pos++;
|
|
69
|
+
}
|
|
70
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
71
|
+
pos++;
|
|
72
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
73
|
+
pos++;
|
|
74
|
+
}
|
|
75
|
+
end = pos;
|
|
76
|
+
} else {
|
|
77
|
+
scanError = 3;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return text.substring(start, end);
|
|
81
|
+
}
|
|
82
|
+
function scanString() {
|
|
83
|
+
let result = "", start = pos;
|
|
84
|
+
while (true) {
|
|
85
|
+
if (pos >= len) {
|
|
86
|
+
result += text.substring(start, pos);
|
|
87
|
+
scanError = 2;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
const ch = text.charCodeAt(pos);
|
|
91
|
+
if (ch === 34) {
|
|
92
|
+
result += text.substring(start, pos);
|
|
93
|
+
pos++;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
if (ch === 92) {
|
|
97
|
+
result += text.substring(start, pos);
|
|
98
|
+
pos++;
|
|
99
|
+
if (pos >= len) {
|
|
100
|
+
scanError = 2;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const ch2 = text.charCodeAt(pos++);
|
|
104
|
+
switch (ch2) {
|
|
105
|
+
case 34:
|
|
106
|
+
result += '"';
|
|
107
|
+
break;
|
|
108
|
+
case 92:
|
|
109
|
+
result += "\\";
|
|
110
|
+
break;
|
|
111
|
+
case 47:
|
|
112
|
+
result += "/";
|
|
113
|
+
break;
|
|
114
|
+
case 98:
|
|
115
|
+
result += "\b";
|
|
116
|
+
break;
|
|
117
|
+
case 102:
|
|
118
|
+
result += "\f";
|
|
119
|
+
break;
|
|
120
|
+
case 110:
|
|
121
|
+
result += "\n";
|
|
122
|
+
break;
|
|
123
|
+
case 114:
|
|
124
|
+
result += "\r";
|
|
125
|
+
break;
|
|
126
|
+
case 116:
|
|
127
|
+
result += " ";
|
|
128
|
+
break;
|
|
129
|
+
case 117:
|
|
130
|
+
const ch3 = scanHexDigits(4, true);
|
|
131
|
+
if (ch3 >= 0) {
|
|
132
|
+
result += String.fromCharCode(ch3);
|
|
133
|
+
} else {
|
|
134
|
+
scanError = 4;
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
default:
|
|
138
|
+
scanError = 5;
|
|
139
|
+
}
|
|
140
|
+
start = pos;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (ch >= 0 && ch <= 31) {
|
|
144
|
+
if (isLineBreak(ch)) {
|
|
145
|
+
result += text.substring(start, pos);
|
|
146
|
+
scanError = 2;
|
|
147
|
+
break;
|
|
148
|
+
} else {
|
|
149
|
+
scanError = 6;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
pos++;
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
function scanNext() {
|
|
157
|
+
value = "";
|
|
158
|
+
scanError = 0;
|
|
159
|
+
tokenOffset = pos;
|
|
160
|
+
lineStartOffset = lineNumber;
|
|
161
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
162
|
+
if (pos >= len) {
|
|
163
|
+
tokenOffset = len;
|
|
164
|
+
return token = 17;
|
|
165
|
+
}
|
|
166
|
+
let code = text.charCodeAt(pos);
|
|
167
|
+
if (isWhiteSpace(code)) {
|
|
168
|
+
do {
|
|
169
|
+
pos++;
|
|
170
|
+
value += String.fromCharCode(code);
|
|
171
|
+
code = text.charCodeAt(pos);
|
|
172
|
+
} while (isWhiteSpace(code));
|
|
173
|
+
return token = 15;
|
|
174
|
+
}
|
|
175
|
+
if (isLineBreak(code)) {
|
|
176
|
+
pos++;
|
|
177
|
+
value += String.fromCharCode(code);
|
|
178
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
179
|
+
pos++;
|
|
180
|
+
value += "\n";
|
|
181
|
+
}
|
|
182
|
+
lineNumber++;
|
|
183
|
+
tokenLineStartOffset = pos;
|
|
184
|
+
return token = 14;
|
|
185
|
+
}
|
|
186
|
+
switch (code) {
|
|
187
|
+
// tokens: []{}:,
|
|
188
|
+
case 123:
|
|
189
|
+
pos++;
|
|
190
|
+
return token = 1;
|
|
191
|
+
case 125:
|
|
192
|
+
pos++;
|
|
193
|
+
return token = 2;
|
|
194
|
+
case 91:
|
|
195
|
+
pos++;
|
|
196
|
+
return token = 3;
|
|
197
|
+
case 93:
|
|
198
|
+
pos++;
|
|
199
|
+
return token = 4;
|
|
200
|
+
case 58:
|
|
201
|
+
pos++;
|
|
202
|
+
return token = 6;
|
|
203
|
+
case 44:
|
|
204
|
+
pos++;
|
|
205
|
+
return token = 5;
|
|
206
|
+
// strings
|
|
207
|
+
case 34:
|
|
208
|
+
pos++;
|
|
209
|
+
value = scanString();
|
|
210
|
+
return token = 10;
|
|
211
|
+
// comments
|
|
212
|
+
case 47:
|
|
213
|
+
const start = pos - 1;
|
|
214
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
215
|
+
pos += 2;
|
|
216
|
+
while (pos < len) {
|
|
217
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
pos++;
|
|
221
|
+
}
|
|
222
|
+
value = text.substring(start, pos);
|
|
223
|
+
return token = 12;
|
|
224
|
+
}
|
|
225
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
226
|
+
pos += 2;
|
|
227
|
+
const safeLength = len - 1;
|
|
228
|
+
let commentClosed = false;
|
|
229
|
+
while (pos < safeLength) {
|
|
230
|
+
const ch = text.charCodeAt(pos);
|
|
231
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
232
|
+
pos += 2;
|
|
233
|
+
commentClosed = true;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
pos++;
|
|
237
|
+
if (isLineBreak(ch)) {
|
|
238
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
239
|
+
pos++;
|
|
240
|
+
}
|
|
241
|
+
lineNumber++;
|
|
242
|
+
tokenLineStartOffset = pos;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!commentClosed) {
|
|
246
|
+
pos++;
|
|
247
|
+
scanError = 1;
|
|
248
|
+
}
|
|
249
|
+
value = text.substring(start, pos);
|
|
250
|
+
return token = 13;
|
|
251
|
+
}
|
|
252
|
+
value += String.fromCharCode(code);
|
|
253
|
+
pos++;
|
|
254
|
+
return token = 16;
|
|
255
|
+
// numbers
|
|
256
|
+
case 45:
|
|
257
|
+
value += String.fromCharCode(code);
|
|
258
|
+
pos++;
|
|
259
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
260
|
+
return token = 16;
|
|
261
|
+
}
|
|
262
|
+
// found a minus, followed by a number so
|
|
263
|
+
// we fall through to proceed with scanning
|
|
264
|
+
// numbers
|
|
265
|
+
case 48:
|
|
266
|
+
case 49:
|
|
267
|
+
case 50:
|
|
268
|
+
case 51:
|
|
269
|
+
case 52:
|
|
270
|
+
case 53:
|
|
271
|
+
case 54:
|
|
272
|
+
case 55:
|
|
273
|
+
case 56:
|
|
274
|
+
case 57:
|
|
275
|
+
value += scanNumber();
|
|
276
|
+
return token = 11;
|
|
277
|
+
// literals and unknown symbols
|
|
278
|
+
default:
|
|
279
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
280
|
+
pos++;
|
|
281
|
+
code = text.charCodeAt(pos);
|
|
282
|
+
}
|
|
283
|
+
if (tokenOffset !== pos) {
|
|
284
|
+
value = text.substring(tokenOffset, pos);
|
|
285
|
+
switch (value) {
|
|
286
|
+
case "true":
|
|
287
|
+
return token = 8;
|
|
288
|
+
case "false":
|
|
289
|
+
return token = 9;
|
|
290
|
+
case "null":
|
|
291
|
+
return token = 7;
|
|
292
|
+
}
|
|
293
|
+
return token = 16;
|
|
294
|
+
}
|
|
295
|
+
value += String.fromCharCode(code);
|
|
296
|
+
pos++;
|
|
297
|
+
return token = 16;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function isUnknownContentCharacter(code) {
|
|
301
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
switch (code) {
|
|
305
|
+
case 125:
|
|
306
|
+
case 93:
|
|
307
|
+
case 123:
|
|
308
|
+
case 91:
|
|
309
|
+
case 34:
|
|
310
|
+
case 58:
|
|
311
|
+
case 44:
|
|
312
|
+
case 47:
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
function scanNextNonTrivia() {
|
|
318
|
+
let result;
|
|
319
|
+
do {
|
|
320
|
+
result = scanNext();
|
|
321
|
+
} while (result >= 12 && result <= 15);
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
setPosition,
|
|
326
|
+
getPosition: () => pos,
|
|
327
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
328
|
+
getToken: () => token,
|
|
329
|
+
getTokenValue: () => value,
|
|
330
|
+
getTokenOffset: () => tokenOffset,
|
|
331
|
+
getTokenLength: () => pos - tokenOffset,
|
|
332
|
+
getTokenStartLine: () => lineStartOffset,
|
|
333
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
334
|
+
getTokenError: () => scanError
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function isWhiteSpace(ch) {
|
|
338
|
+
return ch === 32 || ch === 9;
|
|
339
|
+
}
|
|
340
|
+
function isLineBreak(ch) {
|
|
341
|
+
return ch === 10 || ch === 13;
|
|
342
|
+
}
|
|
343
|
+
function isDigit(ch) {
|
|
344
|
+
return ch >= 48 && ch <= 57;
|
|
345
|
+
}
|
|
346
|
+
var CharacterCodes;
|
|
347
|
+
(function(CharacterCodes2) {
|
|
348
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
349
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
350
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
351
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
352
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
353
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
354
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
355
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
356
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
357
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
358
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
359
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
360
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
361
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
362
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
363
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
364
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
365
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
366
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
367
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
368
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
369
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
370
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
371
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
372
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
373
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
374
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
375
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
376
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
377
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
378
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
379
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
380
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
381
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
382
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
383
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
384
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
385
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
386
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
387
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
388
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
389
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
390
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
391
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
392
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
393
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
394
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
395
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
396
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
397
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
398
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
399
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
400
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
401
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
402
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
403
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
404
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
405
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
406
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
407
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
408
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
409
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
410
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
411
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
412
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
413
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
414
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
415
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
416
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
417
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
418
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
419
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
420
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
421
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
422
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
423
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
424
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
425
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
426
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
427
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
428
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
429
|
+
|
|
430
|
+
// node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
431
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
432
|
+
return " ".repeat(index);
|
|
433
|
+
});
|
|
434
|
+
var maxCachedValues = 200;
|
|
435
|
+
var cachedBreakLinesWithSpaces = {
|
|
436
|
+
" ": {
|
|
437
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
438
|
+
return "\n" + " ".repeat(index);
|
|
439
|
+
}),
|
|
440
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
441
|
+
return "\r" + " ".repeat(index);
|
|
442
|
+
}),
|
|
443
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
444
|
+
return "\r\n" + " ".repeat(index);
|
|
445
|
+
})
|
|
446
|
+
},
|
|
447
|
+
" ": {
|
|
448
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
449
|
+
return "\n" + " ".repeat(index);
|
|
450
|
+
}),
|
|
451
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
452
|
+
return "\r" + " ".repeat(index);
|
|
453
|
+
}),
|
|
454
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
455
|
+
return "\r\n" + " ".repeat(index);
|
|
456
|
+
})
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
// node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
461
|
+
var ParseOptions;
|
|
462
|
+
(function(ParseOptions2) {
|
|
463
|
+
ParseOptions2.DEFAULT = {
|
|
464
|
+
allowTrailingComma: false
|
|
465
|
+
};
|
|
466
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
467
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
468
|
+
let currentProperty = null;
|
|
469
|
+
let currentParent = [];
|
|
470
|
+
const previousParents = [];
|
|
471
|
+
function onValue(value) {
|
|
472
|
+
if (Array.isArray(currentParent)) {
|
|
473
|
+
currentParent.push(value);
|
|
474
|
+
} else if (currentProperty !== null) {
|
|
475
|
+
currentParent[currentProperty] = value;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const visitor = {
|
|
479
|
+
onObjectBegin: () => {
|
|
480
|
+
const object = {};
|
|
481
|
+
onValue(object);
|
|
482
|
+
previousParents.push(currentParent);
|
|
483
|
+
currentParent = object;
|
|
484
|
+
currentProperty = null;
|
|
485
|
+
},
|
|
486
|
+
onObjectProperty: (name) => {
|
|
487
|
+
currentProperty = name;
|
|
488
|
+
},
|
|
489
|
+
onObjectEnd: () => {
|
|
490
|
+
currentParent = previousParents.pop();
|
|
491
|
+
},
|
|
492
|
+
onArrayBegin: () => {
|
|
493
|
+
const array = [];
|
|
494
|
+
onValue(array);
|
|
495
|
+
previousParents.push(currentParent);
|
|
496
|
+
currentParent = array;
|
|
497
|
+
currentProperty = null;
|
|
498
|
+
},
|
|
499
|
+
onArrayEnd: () => {
|
|
500
|
+
currentParent = previousParents.pop();
|
|
501
|
+
},
|
|
502
|
+
onLiteralValue: onValue,
|
|
503
|
+
onError: (error, offset, length) => {
|
|
504
|
+
errors.push({ error, offset, length });
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
visit(text, visitor, options);
|
|
508
|
+
return currentParent[0];
|
|
509
|
+
}
|
|
510
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
511
|
+
const _scanner = createScanner(text, false);
|
|
512
|
+
const _jsonPath = [];
|
|
513
|
+
let suppressedCallbacks = 0;
|
|
514
|
+
function toNoArgVisit(visitFunction) {
|
|
515
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
516
|
+
}
|
|
517
|
+
function toOneArgVisit(visitFunction) {
|
|
518
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
519
|
+
}
|
|
520
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
521
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
522
|
+
}
|
|
523
|
+
function toBeginVisit(visitFunction) {
|
|
524
|
+
return visitFunction ? () => {
|
|
525
|
+
if (suppressedCallbacks > 0) {
|
|
526
|
+
suppressedCallbacks++;
|
|
527
|
+
} else {
|
|
528
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
529
|
+
if (cbReturn === false) {
|
|
530
|
+
suppressedCallbacks = 1;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
} : () => true;
|
|
534
|
+
}
|
|
535
|
+
function toEndVisit(visitFunction) {
|
|
536
|
+
return visitFunction ? () => {
|
|
537
|
+
if (suppressedCallbacks > 0) {
|
|
538
|
+
suppressedCallbacks--;
|
|
539
|
+
}
|
|
540
|
+
if (suppressedCallbacks === 0) {
|
|
541
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
542
|
+
}
|
|
543
|
+
} : () => true;
|
|
544
|
+
}
|
|
545
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
546
|
+
const disallowComments = options && options.disallowComments;
|
|
547
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
548
|
+
function scanNext() {
|
|
549
|
+
while (true) {
|
|
550
|
+
const token = _scanner.scan();
|
|
551
|
+
switch (_scanner.getTokenError()) {
|
|
552
|
+
case 4:
|
|
553
|
+
handleError(
|
|
554
|
+
14
|
|
555
|
+
/* ParseErrorCode.InvalidUnicode */
|
|
556
|
+
);
|
|
557
|
+
break;
|
|
558
|
+
case 5:
|
|
559
|
+
handleError(
|
|
560
|
+
15
|
|
561
|
+
/* ParseErrorCode.InvalidEscapeCharacter */
|
|
562
|
+
);
|
|
563
|
+
break;
|
|
564
|
+
case 3:
|
|
565
|
+
handleError(
|
|
566
|
+
13
|
|
567
|
+
/* ParseErrorCode.UnexpectedEndOfNumber */
|
|
568
|
+
);
|
|
569
|
+
break;
|
|
570
|
+
case 1:
|
|
571
|
+
if (!disallowComments) {
|
|
572
|
+
handleError(
|
|
573
|
+
11
|
|
574
|
+
/* ParseErrorCode.UnexpectedEndOfComment */
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
break;
|
|
578
|
+
case 2:
|
|
579
|
+
handleError(
|
|
580
|
+
12
|
|
581
|
+
/* ParseErrorCode.UnexpectedEndOfString */
|
|
582
|
+
);
|
|
583
|
+
break;
|
|
584
|
+
case 6:
|
|
585
|
+
handleError(
|
|
586
|
+
16
|
|
587
|
+
/* ParseErrorCode.InvalidCharacter */
|
|
588
|
+
);
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
switch (token) {
|
|
592
|
+
case 12:
|
|
593
|
+
case 13:
|
|
594
|
+
if (disallowComments) {
|
|
595
|
+
handleError(
|
|
596
|
+
10
|
|
597
|
+
/* ParseErrorCode.InvalidCommentToken */
|
|
598
|
+
);
|
|
599
|
+
} else {
|
|
600
|
+
onComment();
|
|
601
|
+
}
|
|
602
|
+
break;
|
|
603
|
+
case 16:
|
|
604
|
+
handleError(
|
|
605
|
+
1
|
|
606
|
+
/* ParseErrorCode.InvalidSymbol */
|
|
607
|
+
);
|
|
608
|
+
break;
|
|
609
|
+
case 15:
|
|
610
|
+
case 14:
|
|
611
|
+
break;
|
|
612
|
+
default:
|
|
613
|
+
return token;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
618
|
+
onError(error);
|
|
619
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
620
|
+
let token = _scanner.getToken();
|
|
621
|
+
while (token !== 17) {
|
|
622
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
623
|
+
scanNext();
|
|
624
|
+
break;
|
|
625
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
token = scanNext();
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
function parseString(isValue) {
|
|
633
|
+
const value = _scanner.getTokenValue();
|
|
634
|
+
if (isValue) {
|
|
635
|
+
onLiteralValue(value);
|
|
636
|
+
} else {
|
|
637
|
+
onObjectProperty(value);
|
|
638
|
+
_jsonPath.push(value);
|
|
639
|
+
}
|
|
640
|
+
scanNext();
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
function parseLiteral() {
|
|
644
|
+
switch (_scanner.getToken()) {
|
|
645
|
+
case 11:
|
|
646
|
+
const tokenValue = _scanner.getTokenValue();
|
|
647
|
+
let value = Number(tokenValue);
|
|
648
|
+
if (isNaN(value)) {
|
|
649
|
+
handleError(
|
|
650
|
+
2
|
|
651
|
+
/* ParseErrorCode.InvalidNumberFormat */
|
|
652
|
+
);
|
|
653
|
+
value = 0;
|
|
654
|
+
}
|
|
655
|
+
onLiteralValue(value);
|
|
656
|
+
break;
|
|
657
|
+
case 7:
|
|
658
|
+
onLiteralValue(null);
|
|
659
|
+
break;
|
|
660
|
+
case 8:
|
|
661
|
+
onLiteralValue(true);
|
|
662
|
+
break;
|
|
663
|
+
case 9:
|
|
664
|
+
onLiteralValue(false);
|
|
665
|
+
break;
|
|
666
|
+
default:
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
scanNext();
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
function parseProperty() {
|
|
673
|
+
if (_scanner.getToken() !== 10) {
|
|
674
|
+
handleError(3, [], [
|
|
675
|
+
2,
|
|
676
|
+
5
|
|
677
|
+
/* SyntaxKind.CommaToken */
|
|
678
|
+
]);
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
parseString(false);
|
|
682
|
+
if (_scanner.getToken() === 6) {
|
|
683
|
+
onSeparator(":");
|
|
684
|
+
scanNext();
|
|
685
|
+
if (!parseValue()) {
|
|
686
|
+
handleError(4, [], [
|
|
687
|
+
2,
|
|
688
|
+
5
|
|
689
|
+
/* SyntaxKind.CommaToken */
|
|
690
|
+
]);
|
|
691
|
+
}
|
|
692
|
+
} else {
|
|
693
|
+
handleError(5, [], [
|
|
694
|
+
2,
|
|
695
|
+
5
|
|
696
|
+
/* SyntaxKind.CommaToken */
|
|
697
|
+
]);
|
|
698
|
+
}
|
|
699
|
+
_jsonPath.pop();
|
|
700
|
+
return true;
|
|
701
|
+
}
|
|
702
|
+
function parseObject() {
|
|
703
|
+
onObjectBegin();
|
|
704
|
+
scanNext();
|
|
705
|
+
let needsComma = false;
|
|
706
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
707
|
+
if (_scanner.getToken() === 5) {
|
|
708
|
+
if (!needsComma) {
|
|
709
|
+
handleError(4, [], []);
|
|
710
|
+
}
|
|
711
|
+
onSeparator(",");
|
|
712
|
+
scanNext();
|
|
713
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
714
|
+
break;
|
|
715
|
+
}
|
|
716
|
+
} else if (needsComma) {
|
|
717
|
+
handleError(6, [], []);
|
|
718
|
+
}
|
|
719
|
+
if (!parseProperty()) {
|
|
720
|
+
handleError(4, [], [
|
|
721
|
+
2,
|
|
722
|
+
5
|
|
723
|
+
/* SyntaxKind.CommaToken */
|
|
724
|
+
]);
|
|
725
|
+
}
|
|
726
|
+
needsComma = true;
|
|
727
|
+
}
|
|
728
|
+
onObjectEnd();
|
|
729
|
+
if (_scanner.getToken() !== 2) {
|
|
730
|
+
handleError(7, [
|
|
731
|
+
2
|
|
732
|
+
/* SyntaxKind.CloseBraceToken */
|
|
733
|
+
], []);
|
|
734
|
+
} else {
|
|
735
|
+
scanNext();
|
|
736
|
+
}
|
|
737
|
+
return true;
|
|
738
|
+
}
|
|
739
|
+
function parseArray() {
|
|
740
|
+
onArrayBegin();
|
|
741
|
+
scanNext();
|
|
742
|
+
let isFirstElement = true;
|
|
743
|
+
let needsComma = false;
|
|
744
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
745
|
+
if (_scanner.getToken() === 5) {
|
|
746
|
+
if (!needsComma) {
|
|
747
|
+
handleError(4, [], []);
|
|
748
|
+
}
|
|
749
|
+
onSeparator(",");
|
|
750
|
+
scanNext();
|
|
751
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
} else if (needsComma) {
|
|
755
|
+
handleError(6, [], []);
|
|
756
|
+
}
|
|
757
|
+
if (isFirstElement) {
|
|
758
|
+
_jsonPath.push(0);
|
|
759
|
+
isFirstElement = false;
|
|
760
|
+
} else {
|
|
761
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
762
|
+
}
|
|
763
|
+
if (!parseValue()) {
|
|
764
|
+
handleError(4, [], [
|
|
765
|
+
4,
|
|
766
|
+
5
|
|
767
|
+
/* SyntaxKind.CommaToken */
|
|
768
|
+
]);
|
|
769
|
+
}
|
|
770
|
+
needsComma = true;
|
|
771
|
+
}
|
|
772
|
+
onArrayEnd();
|
|
773
|
+
if (!isFirstElement) {
|
|
774
|
+
_jsonPath.pop();
|
|
775
|
+
}
|
|
776
|
+
if (_scanner.getToken() !== 4) {
|
|
777
|
+
handleError(8, [
|
|
778
|
+
4
|
|
779
|
+
/* SyntaxKind.CloseBracketToken */
|
|
780
|
+
], []);
|
|
781
|
+
} else {
|
|
782
|
+
scanNext();
|
|
783
|
+
}
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
function parseValue() {
|
|
787
|
+
switch (_scanner.getToken()) {
|
|
788
|
+
case 3:
|
|
789
|
+
return parseArray();
|
|
790
|
+
case 1:
|
|
791
|
+
return parseObject();
|
|
792
|
+
case 10:
|
|
793
|
+
return parseString(true);
|
|
794
|
+
default:
|
|
795
|
+
return parseLiteral();
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
scanNext();
|
|
799
|
+
if (_scanner.getToken() === 17) {
|
|
800
|
+
if (options.allowEmptyContent) {
|
|
801
|
+
return true;
|
|
802
|
+
}
|
|
803
|
+
handleError(4, [], []);
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
if (!parseValue()) {
|
|
807
|
+
handleError(4, [], []);
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
if (_scanner.getToken() !== 17) {
|
|
811
|
+
handleError(9, [], []);
|
|
812
|
+
}
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// node_modules/jsonc-parser/lib/esm/main.js
|
|
817
|
+
var ScanError;
|
|
818
|
+
(function(ScanError2) {
|
|
819
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
820
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
821
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
822
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
823
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
824
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
825
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
826
|
+
})(ScanError || (ScanError = {}));
|
|
827
|
+
var SyntaxKind;
|
|
828
|
+
(function(SyntaxKind2) {
|
|
829
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
830
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
831
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
832
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
833
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
834
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
835
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
836
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
837
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
838
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
839
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
840
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
841
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
842
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
843
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
844
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
845
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
846
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
847
|
+
var parse2 = parse;
|
|
848
|
+
var ParseErrorCode;
|
|
849
|
+
(function(ParseErrorCode2) {
|
|
850
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
851
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
852
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
853
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
854
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
855
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
856
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
857
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
858
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
859
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
860
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
861
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
862
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
863
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
864
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
865
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
866
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
867
|
+
|
|
868
|
+
// integrations/statusline/claude-statusline.mjs
|
|
869
|
+
var SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
870
|
+
var AGENT_TOOLS_HOME = process.env.AGENT_TOOLS_HOME || join(SCRIPT_DIR, "..", "..");
|
|
871
|
+
var DEFAULT_CONFIG_FILE = join(AGENT_TOOLS_HOME, "config.jsonc");
|
|
872
|
+
var SNAPSHOT_FILE = join(AGENT_TOOLS_HOME, "cache", "usage-snapshot.json");
|
|
873
|
+
var REFRESH_STATE_FILE = join(AGENT_TOOLS_HOME, "cache", "usage-refresh-state.json");
|
|
874
|
+
var USAGE_RUNTIME = join(AGENT_TOOLS_HOME, "dist", "usage", "core.mjs");
|
|
875
|
+
var DEFAULT_SNAPSHOT_TTL_MS = 6e4;
|
|
876
|
+
var DEFAULT_REFRESH_COOLDOWN_MS = 3e4;
|
|
877
|
+
var DEFAULT_FAILURE_BACKOFF_MS = 12e4;
|
|
878
|
+
var DEFAULT_CONFIG = {
|
|
879
|
+
fields: ["branch", "model", "fiveHour", "week"],
|
|
880
|
+
separator: " | ",
|
|
881
|
+
symbols: {
|
|
882
|
+
branch: "\u2387",
|
|
883
|
+
reset: "\u27F3",
|
|
884
|
+
empty: "\u2013",
|
|
885
|
+
fiveHour: "5h",
|
|
886
|
+
week: "w",
|
|
887
|
+
context: "ctx"
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
var FIELD_ALIASES = {
|
|
891
|
+
cwd: "directory",
|
|
892
|
+
dir: "directory",
|
|
893
|
+
five: "fiveHour",
|
|
894
|
+
five_hour: "fiveHour",
|
|
895
|
+
"5h": "fiveHour",
|
|
896
|
+
sevenDay: "week",
|
|
897
|
+
seven_day: "week",
|
|
898
|
+
"7d": "week",
|
|
899
|
+
weekly: "week",
|
|
900
|
+
ctx: "context"
|
|
901
|
+
};
|
|
902
|
+
async function readStdin() {
|
|
903
|
+
const chunks = [];
|
|
904
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
905
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
906
|
+
}
|
|
907
|
+
function readJsonFile(file) {
|
|
908
|
+
try {
|
|
909
|
+
if (!fs.existsSync(file)) return {};
|
|
910
|
+
const raw = fs.readFileSync(file, "utf8").replace(/^\uFEFF/, "");
|
|
911
|
+
if (!raw.trim()) return {};
|
|
912
|
+
const errors = [];
|
|
913
|
+
const parsed = parse2(raw, errors, { allowTrailingComma: true });
|
|
914
|
+
return errors.length === 0 && parsed && typeof parsed === "object" ? parsed : {};
|
|
915
|
+
} catch {
|
|
916
|
+
return {};
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
function parseArgs(argv) {
|
|
920
|
+
const opts = {};
|
|
921
|
+
for (let i = 0; i < argv.length; i++) {
|
|
922
|
+
const arg = argv[i];
|
|
923
|
+
if (arg === "--fields" && argv[i + 1]) {
|
|
924
|
+
opts.fields = argv[++i];
|
|
925
|
+
} else if (arg.startsWith("--fields=")) {
|
|
926
|
+
opts.fields = arg.slice("--fields=".length);
|
|
927
|
+
} else if (arg === "--separator" && argv[i + 1]) {
|
|
928
|
+
opts.separator = argv[++i];
|
|
929
|
+
} else if (arg.startsWith("--separator=")) {
|
|
930
|
+
opts.separator = arg.slice("--separator=".length);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return opts;
|
|
934
|
+
}
|
|
935
|
+
function splitFields(value) {
|
|
936
|
+
if (Array.isArray(value)) return value;
|
|
937
|
+
if (typeof value !== "string") return null;
|
|
938
|
+
return value.split(/[,\s]+/).map((part) => part.trim()).filter(Boolean);
|
|
939
|
+
}
|
|
940
|
+
function normalizeField(field) {
|
|
941
|
+
return FIELD_ALIASES[field] || field;
|
|
942
|
+
}
|
|
943
|
+
function mergeConfig(cli) {
|
|
944
|
+
const rootConfig = readJsonFile(DEFAULT_CONFIG_FILE);
|
|
945
|
+
const fileConfig = rootConfig.statusline || {};
|
|
946
|
+
const envFields = process.env.AGENT_TOOLS_STATUSLINE_FIELDS;
|
|
947
|
+
const envSeparator = process.env.AGENT_TOOLS_STATUSLINE_SEPARATOR;
|
|
948
|
+
const config = {
|
|
949
|
+
...DEFAULT_CONFIG,
|
|
950
|
+
...fileConfig,
|
|
951
|
+
symbols: { ...DEFAULT_CONFIG.symbols, ...fileConfig.symbols || {} }
|
|
952
|
+
};
|
|
953
|
+
const fields = splitFields(cli.fields) || splitFields(envFields) || splitFields(fileConfig.fields) || DEFAULT_CONFIG.fields;
|
|
954
|
+
config.fields = fields.map(normalizeField);
|
|
955
|
+
if (typeof envSeparator === "string") config.separator = envSeparator;
|
|
956
|
+
if (typeof cli.separator === "string") config.separator = cli.separator;
|
|
957
|
+
return config;
|
|
958
|
+
}
|
|
959
|
+
function gitBranch(cwd) {
|
|
960
|
+
try {
|
|
961
|
+
const out = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
962
|
+
cwd,
|
|
963
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
964
|
+
encoding: "utf8"
|
|
965
|
+
}).trim();
|
|
966
|
+
return out && out !== "HEAD" ? out : "";
|
|
967
|
+
} catch {
|
|
968
|
+
return "";
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
function secondsUntil(unixSeconds) {
|
|
972
|
+
if (!unixSeconds) return null;
|
|
973
|
+
const seconds = Number(unixSeconds) - Math.floor(Date.now() / 1e3);
|
|
974
|
+
return Number.isFinite(seconds) ? Math.max(0, seconds) : null;
|
|
975
|
+
}
|
|
976
|
+
function compactDuration(totalSeconds) {
|
|
977
|
+
if (totalSeconds == null) return "";
|
|
978
|
+
if (totalSeconds <= 0) return "0m";
|
|
979
|
+
let seconds = totalSeconds;
|
|
980
|
+
const days = Math.floor(seconds / 86400);
|
|
981
|
+
seconds %= 86400;
|
|
982
|
+
const hours = Math.floor(seconds / 3600);
|
|
983
|
+
seconds %= 3600;
|
|
984
|
+
const minutes = Math.floor(seconds / 60);
|
|
985
|
+
if (days) return `${days}d${hours}h`;
|
|
986
|
+
if (hours) return `${hours}h${minutes}m`;
|
|
987
|
+
return `${minutes}m`;
|
|
988
|
+
}
|
|
989
|
+
function usageWindow(window, config) {
|
|
990
|
+
if (!window || typeof window.used_percentage !== "number") {
|
|
991
|
+
return "";
|
|
992
|
+
}
|
|
993
|
+
const pct = `${Math.round(window.used_percentage)}%`;
|
|
994
|
+
const left = compactDuration(secondsUntil(window.resets_at));
|
|
995
|
+
return left ? `${pct} ${config.symbols.reset}${left}` : pct;
|
|
996
|
+
}
|
|
997
|
+
function showMissingUsageWindow() {
|
|
998
|
+
const baseUrl = activeRelayBaseUrl();
|
|
999
|
+
return !baseUrl || isOfficialBaseUrl(baseUrl);
|
|
1000
|
+
}
|
|
1001
|
+
function shortModelName(name) {
|
|
1002
|
+
if (!name) return "";
|
|
1003
|
+
return String(name).replace(/^Claude\s+/i, "").replace(/\s*\[1m\]\s*$/i, "").trim();
|
|
1004
|
+
}
|
|
1005
|
+
function renderField(field, data, config) {
|
|
1006
|
+
const dir = data?.workspace?.current_dir || data?.cwd || process.cwd() || "";
|
|
1007
|
+
const projectDir = data?.workspace?.project_dir || dir;
|
|
1008
|
+
switch (field) {
|
|
1009
|
+
case "branch": {
|
|
1010
|
+
const branch = gitBranch(projectDir);
|
|
1011
|
+
return branch ? `${config.symbols.branch} ${branch}` : "";
|
|
1012
|
+
}
|
|
1013
|
+
case "model":
|
|
1014
|
+
return shortModelName(data?.model?.display_name || data?.model?.id || "");
|
|
1015
|
+
case "fiveHour": {
|
|
1016
|
+
const value = usageWindow(data?.rate_limits?.five_hour, config);
|
|
1017
|
+
return value || showMissingUsageWindow() ? `${config.symbols.fiveHour} ${value || config.symbols.empty}` : "";
|
|
1018
|
+
}
|
|
1019
|
+
case "week": {
|
|
1020
|
+
const value = usageWindow(data?.rate_limits?.seven_day, config);
|
|
1021
|
+
return value || showMissingUsageWindow() ? `${config.symbols.week} ${value || config.symbols.empty}` : "";
|
|
1022
|
+
}
|
|
1023
|
+
case "context": {
|
|
1024
|
+
const pct = data?.context_window?.used_percentage;
|
|
1025
|
+
return typeof pct === "number" ? `${config.symbols.context} ${Math.round(pct)}%` : "";
|
|
1026
|
+
}
|
|
1027
|
+
case "directory":
|
|
1028
|
+
return dir ? basename(dir) : "";
|
|
1029
|
+
default:
|
|
1030
|
+
return "";
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function numberFromEnv(name, fallback) {
|
|
1034
|
+
const value = Number(process.env[name]);
|
|
1035
|
+
return Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
1036
|
+
}
|
|
1037
|
+
function cleanBaseUrl(baseUrl) {
|
|
1038
|
+
return String(baseUrl || "").replace(/\/+$/, "");
|
|
1039
|
+
}
|
|
1040
|
+
function isOfficialBaseUrl(baseUrl) {
|
|
1041
|
+
if (!baseUrl) return true;
|
|
1042
|
+
const clean = cleanBaseUrl(baseUrl);
|
|
1043
|
+
return [
|
|
1044
|
+
"https://api.anthropic.com",
|
|
1045
|
+
"https://api.anthropic.com/v1",
|
|
1046
|
+
"https://api.openai.com",
|
|
1047
|
+
"https://api.openai.com/v1"
|
|
1048
|
+
].includes(clean);
|
|
1049
|
+
}
|
|
1050
|
+
function usageRouteCacheKey(baseUrl) {
|
|
1051
|
+
try {
|
|
1052
|
+
const url = new URL(cleanBaseUrl(baseUrl));
|
|
1053
|
+
url.hash = "";
|
|
1054
|
+
url.search = "";
|
|
1055
|
+
url.pathname = url.pathname.replace(/\/+$/, "").replace(/\/api\/v1$/i, "").replace(/\/v1$/i, "");
|
|
1056
|
+
return url.toString().replace(/\/$/, "");
|
|
1057
|
+
} catch {
|
|
1058
|
+
return cleanBaseUrl(baseUrl).endsWith("/v1") ? cleanBaseUrl(baseUrl).slice(0, -3) : cleanBaseUrl(baseUrl);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function readJsonFileRaw(file) {
|
|
1062
|
+
try {
|
|
1063
|
+
if (!fs.existsSync(file)) return {};
|
|
1064
|
+
const raw = fs.readFileSync(file, "utf8").replace(/^\uFEFF/, "");
|
|
1065
|
+
return raw.trim() ? JSON.parse(raw) : {};
|
|
1066
|
+
} catch {
|
|
1067
|
+
return {};
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
function activeRelayBaseUrl() {
|
|
1071
|
+
return process.env.PROVIDER_USAGE_BASE_URL || process.env.ANTHROPIC_BASE_URL || "";
|
|
1072
|
+
}
|
|
1073
|
+
function hasClaudeUsageToken() {
|
|
1074
|
+
return Boolean(
|
|
1075
|
+
process.env.PROVIDER_USAGE_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN || process.env.ANTHROPIC_API_KEY
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
function snapshotForBaseUrl(baseUrl) {
|
|
1079
|
+
const snapshot = readJsonFileRaw(SNAPSHOT_FILE);
|
|
1080
|
+
const key = usageRouteCacheKey(baseUrl);
|
|
1081
|
+
const item = snapshot?.items?.[key];
|
|
1082
|
+
return item?.text ? item : null;
|
|
1083
|
+
}
|
|
1084
|
+
function refreshStateForBaseUrl(baseUrl) {
|
|
1085
|
+
const state = readJsonFileRaw(REFRESH_STATE_FILE);
|
|
1086
|
+
return state?.items?.[usageRouteCacheKey(baseUrl)] || {};
|
|
1087
|
+
}
|
|
1088
|
+
function ageMs(isoDate) {
|
|
1089
|
+
const time = Date.parse(isoDate || "");
|
|
1090
|
+
return Number.isFinite(time) ? Date.now() - time : Number.POSITIVE_INFINITY;
|
|
1091
|
+
}
|
|
1092
|
+
function writeRefreshAttempt(baseUrl) {
|
|
1093
|
+
try {
|
|
1094
|
+
const state = readJsonFileRaw(REFRESH_STATE_FILE);
|
|
1095
|
+
const key = usageRouteCacheKey(baseUrl);
|
|
1096
|
+
state.version = 1;
|
|
1097
|
+
state.items = state.items && typeof state.items === "object" ? state.items : {};
|
|
1098
|
+
state.items[key] = {
|
|
1099
|
+
...state.items[key] || {},
|
|
1100
|
+
baseUrl,
|
|
1101
|
+
lastAttemptAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1102
|
+
};
|
|
1103
|
+
fs.mkdirSync(dirname(REFRESH_STATE_FILE), { recursive: true });
|
|
1104
|
+
fs.writeFileSync(REFRESH_STATE_FILE, `${JSON.stringify(state, null, 2)}
|
|
1105
|
+
`);
|
|
1106
|
+
} catch {
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function shouldRefreshUsage(baseUrl, snapshot) {
|
|
1110
|
+
if (process.env.AGENT_TOOLS_USAGE_REFRESH === "0") return false;
|
|
1111
|
+
if (!baseUrl || isOfficialBaseUrl(baseUrl)) return false;
|
|
1112
|
+
if (!hasClaudeUsageToken()) return false;
|
|
1113
|
+
if (!fs.existsSync(USAGE_RUNTIME)) return false;
|
|
1114
|
+
const ttlMs = numberFromEnv("AGENT_TOOLS_USAGE_SNAPSHOT_TTL_MS", DEFAULT_SNAPSHOT_TTL_MS);
|
|
1115
|
+
const cooldownMs = numberFromEnv("AGENT_TOOLS_USAGE_REFRESH_COOLDOWN_MS", DEFAULT_REFRESH_COOLDOWN_MS);
|
|
1116
|
+
const failureBackoffMs = numberFromEnv("AGENT_TOOLS_USAGE_FAILURE_BACKOFF_MS", DEFAULT_FAILURE_BACKOFF_MS);
|
|
1117
|
+
const state = refreshStateForBaseUrl(baseUrl);
|
|
1118
|
+
if (ageMs(state.lastAttemptAt) < cooldownMs) return false;
|
|
1119
|
+
if (state.lastError && ageMs(state.lastFailureAt) < failureBackoffMs) return false;
|
|
1120
|
+
return !snapshot || ageMs(snapshot.updatedAt) >= ttlMs;
|
|
1121
|
+
}
|
|
1122
|
+
function refreshUsageInBackground(baseUrl) {
|
|
1123
|
+
if (!shouldRefreshUsage(baseUrl, snapshotForBaseUrl(baseUrl))) return;
|
|
1124
|
+
writeRefreshAttempt(baseUrl);
|
|
1125
|
+
try {
|
|
1126
|
+
const child = spawn(process.execPath, [USAGE_RUNTIME, "refresh", "--agent", "claude"], {
|
|
1127
|
+
detached: true,
|
|
1128
|
+
stdio: "ignore",
|
|
1129
|
+
env: process.env,
|
|
1130
|
+
windowsHide: true
|
|
1131
|
+
});
|
|
1132
|
+
child.unref();
|
|
1133
|
+
} catch {
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
function providerUsageStatus() {
|
|
1137
|
+
const baseUrl = activeRelayBaseUrl();
|
|
1138
|
+
if (!baseUrl || isOfficialBaseUrl(baseUrl)) return "";
|
|
1139
|
+
const snapshot = snapshotForBaseUrl(baseUrl);
|
|
1140
|
+
if (shouldRefreshUsage(baseUrl, snapshot)) refreshUsageInBackground(baseUrl);
|
|
1141
|
+
return snapshot?.text || "";
|
|
1142
|
+
}
|
|
1143
|
+
function render(data, config) {
|
|
1144
|
+
const fields = config.fields.map((field) => renderField(field, data, config)).filter(Boolean);
|
|
1145
|
+
const providerUsage = providerUsageStatus();
|
|
1146
|
+
if (providerUsage) fields.push(providerUsage);
|
|
1147
|
+
return fields.join(config.separator);
|
|
1148
|
+
}
|
|
1149
|
+
async function main() {
|
|
1150
|
+
const config = mergeConfig(parseArgs(process.argv.slice(2)));
|
|
1151
|
+
let data = {};
|
|
1152
|
+
try {
|
|
1153
|
+
const raw = await readStdin();
|
|
1154
|
+
data = raw.trim() ? JSON.parse(raw) : {};
|
|
1155
|
+
} catch {
|
|
1156
|
+
data = {};
|
|
1157
|
+
}
|
|
1158
|
+
process.stdout.write(render(data, config));
|
|
1159
|
+
}
|
|
1160
|
+
main();
|