@melihmucuk/leash 1.0.9 → 1.0.11

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.
@@ -0,0 +1,1799 @@
1
+ #!/usr/bin/env node
2
+
3
+ // packages/cli/leash.ts
4
+ import { existsSync as existsSync3 } from "fs";
5
+ import { dirname as dirname3, join as join2 } from "path";
6
+ import { homedir } from "os";
7
+ import { fileURLToPath as fileURLToPath2 } from "url";
8
+ import { execSync } from "child_process";
9
+
10
+ // packages/cli/lib.ts
11
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
12
+ import { dirname } from "path";
13
+
14
+ // node_modules/jsonc-parser/lib/esm/impl/scanner.js
15
+ function createScanner(text, ignoreTrivia = false) {
16
+ const len = text.length;
17
+ let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
18
+ function scanHexDigits(count, exact) {
19
+ let digits = 0;
20
+ let value2 = 0;
21
+ while (digits < count || !exact) {
22
+ let ch = text.charCodeAt(pos);
23
+ if (ch >= 48 && ch <= 57) {
24
+ value2 = value2 * 16 + ch - 48;
25
+ } else if (ch >= 65 && ch <= 70) {
26
+ value2 = value2 * 16 + ch - 65 + 10;
27
+ } else if (ch >= 97 && ch <= 102) {
28
+ value2 = value2 * 16 + ch - 97 + 10;
29
+ } else {
30
+ break;
31
+ }
32
+ pos++;
33
+ digits++;
34
+ }
35
+ if (digits < count) {
36
+ value2 = -1;
37
+ }
38
+ return value2;
39
+ }
40
+ function setPosition(newPosition) {
41
+ pos = newPosition;
42
+ value = "";
43
+ tokenOffset = 0;
44
+ token = 16;
45
+ scanError = 0;
46
+ }
47
+ function scanNumber() {
48
+ let start = pos;
49
+ if (text.charCodeAt(pos) === 48) {
50
+ pos++;
51
+ } else {
52
+ pos++;
53
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
54
+ pos++;
55
+ }
56
+ }
57
+ if (pos < text.length && text.charCodeAt(pos) === 46) {
58
+ pos++;
59
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
60
+ pos++;
61
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
62
+ pos++;
63
+ }
64
+ } else {
65
+ scanError = 3;
66
+ return text.substring(start, pos);
67
+ }
68
+ }
69
+ let end = pos;
70
+ if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
71
+ pos++;
72
+ if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
73
+ pos++;
74
+ }
75
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
76
+ pos++;
77
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
78
+ pos++;
79
+ }
80
+ end = pos;
81
+ } else {
82
+ scanError = 3;
83
+ }
84
+ }
85
+ return text.substring(start, end);
86
+ }
87
+ function scanString() {
88
+ let result = "", start = pos;
89
+ while (true) {
90
+ if (pos >= len) {
91
+ result += text.substring(start, pos);
92
+ scanError = 2;
93
+ break;
94
+ }
95
+ const ch = text.charCodeAt(pos);
96
+ if (ch === 34) {
97
+ result += text.substring(start, pos);
98
+ pos++;
99
+ break;
100
+ }
101
+ if (ch === 92) {
102
+ result += text.substring(start, pos);
103
+ pos++;
104
+ if (pos >= len) {
105
+ scanError = 2;
106
+ break;
107
+ }
108
+ const ch2 = text.charCodeAt(pos++);
109
+ switch (ch2) {
110
+ case 34:
111
+ result += '"';
112
+ break;
113
+ case 92:
114
+ result += "\\";
115
+ break;
116
+ case 47:
117
+ result += "/";
118
+ break;
119
+ case 98:
120
+ result += "\b";
121
+ break;
122
+ case 102:
123
+ result += "\f";
124
+ break;
125
+ case 110:
126
+ result += "\n";
127
+ break;
128
+ case 114:
129
+ result += "\r";
130
+ break;
131
+ case 116:
132
+ result += " ";
133
+ break;
134
+ case 117:
135
+ const ch3 = scanHexDigits(4, true);
136
+ if (ch3 >= 0) {
137
+ result += String.fromCharCode(ch3);
138
+ } else {
139
+ scanError = 4;
140
+ }
141
+ break;
142
+ default:
143
+ scanError = 5;
144
+ }
145
+ start = pos;
146
+ continue;
147
+ }
148
+ if (ch >= 0 && ch <= 31) {
149
+ if (isLineBreak(ch)) {
150
+ result += text.substring(start, pos);
151
+ scanError = 2;
152
+ break;
153
+ } else {
154
+ scanError = 6;
155
+ }
156
+ }
157
+ pos++;
158
+ }
159
+ return result;
160
+ }
161
+ function scanNext() {
162
+ value = "";
163
+ scanError = 0;
164
+ tokenOffset = pos;
165
+ lineStartOffset = lineNumber;
166
+ prevTokenLineStartOffset = tokenLineStartOffset;
167
+ if (pos >= len) {
168
+ tokenOffset = len;
169
+ return token = 17;
170
+ }
171
+ let code = text.charCodeAt(pos);
172
+ if (isWhiteSpace(code)) {
173
+ do {
174
+ pos++;
175
+ value += String.fromCharCode(code);
176
+ code = text.charCodeAt(pos);
177
+ } while (isWhiteSpace(code));
178
+ return token = 15;
179
+ }
180
+ if (isLineBreak(code)) {
181
+ pos++;
182
+ value += String.fromCharCode(code);
183
+ if (code === 13 && text.charCodeAt(pos) === 10) {
184
+ pos++;
185
+ value += "\n";
186
+ }
187
+ lineNumber++;
188
+ tokenLineStartOffset = pos;
189
+ return token = 14;
190
+ }
191
+ switch (code) {
192
+ // tokens: []{}:,
193
+ case 123:
194
+ pos++;
195
+ return token = 1;
196
+ case 125:
197
+ pos++;
198
+ return token = 2;
199
+ case 91:
200
+ pos++;
201
+ return token = 3;
202
+ case 93:
203
+ pos++;
204
+ return token = 4;
205
+ case 58:
206
+ pos++;
207
+ return token = 6;
208
+ case 44:
209
+ pos++;
210
+ return token = 5;
211
+ // strings
212
+ case 34:
213
+ pos++;
214
+ value = scanString();
215
+ return token = 10;
216
+ // comments
217
+ case 47:
218
+ const start = pos - 1;
219
+ if (text.charCodeAt(pos + 1) === 47) {
220
+ pos += 2;
221
+ while (pos < len) {
222
+ if (isLineBreak(text.charCodeAt(pos))) {
223
+ break;
224
+ }
225
+ pos++;
226
+ }
227
+ value = text.substring(start, pos);
228
+ return token = 12;
229
+ }
230
+ if (text.charCodeAt(pos + 1) === 42) {
231
+ pos += 2;
232
+ const safeLength = len - 1;
233
+ let commentClosed = false;
234
+ while (pos < safeLength) {
235
+ const ch = text.charCodeAt(pos);
236
+ if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
237
+ pos += 2;
238
+ commentClosed = true;
239
+ break;
240
+ }
241
+ pos++;
242
+ if (isLineBreak(ch)) {
243
+ if (ch === 13 && text.charCodeAt(pos) === 10) {
244
+ pos++;
245
+ }
246
+ lineNumber++;
247
+ tokenLineStartOffset = pos;
248
+ }
249
+ }
250
+ if (!commentClosed) {
251
+ pos++;
252
+ scanError = 1;
253
+ }
254
+ value = text.substring(start, pos);
255
+ return token = 13;
256
+ }
257
+ value += String.fromCharCode(code);
258
+ pos++;
259
+ return token = 16;
260
+ // numbers
261
+ case 45:
262
+ value += String.fromCharCode(code);
263
+ pos++;
264
+ if (pos === len || !isDigit(text.charCodeAt(pos))) {
265
+ return token = 16;
266
+ }
267
+ // found a minus, followed by a number so
268
+ // we fall through to proceed with scanning
269
+ // numbers
270
+ case 48:
271
+ case 49:
272
+ case 50:
273
+ case 51:
274
+ case 52:
275
+ case 53:
276
+ case 54:
277
+ case 55:
278
+ case 56:
279
+ case 57:
280
+ value += scanNumber();
281
+ return token = 11;
282
+ // literals and unknown symbols
283
+ default:
284
+ while (pos < len && isUnknownContentCharacter(code)) {
285
+ pos++;
286
+ code = text.charCodeAt(pos);
287
+ }
288
+ if (tokenOffset !== pos) {
289
+ value = text.substring(tokenOffset, pos);
290
+ switch (value) {
291
+ case "true":
292
+ return token = 8;
293
+ case "false":
294
+ return token = 9;
295
+ case "null":
296
+ return token = 7;
297
+ }
298
+ return token = 16;
299
+ }
300
+ value += String.fromCharCode(code);
301
+ pos++;
302
+ return token = 16;
303
+ }
304
+ }
305
+ function isUnknownContentCharacter(code) {
306
+ if (isWhiteSpace(code) || isLineBreak(code)) {
307
+ return false;
308
+ }
309
+ switch (code) {
310
+ case 125:
311
+ case 93:
312
+ case 123:
313
+ case 91:
314
+ case 34:
315
+ case 58:
316
+ case 44:
317
+ case 47:
318
+ return false;
319
+ }
320
+ return true;
321
+ }
322
+ function scanNextNonTrivia() {
323
+ let result;
324
+ do {
325
+ result = scanNext();
326
+ } while (result >= 12 && result <= 15);
327
+ return result;
328
+ }
329
+ return {
330
+ setPosition,
331
+ getPosition: () => pos,
332
+ scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
333
+ getToken: () => token,
334
+ getTokenValue: () => value,
335
+ getTokenOffset: () => tokenOffset,
336
+ getTokenLength: () => pos - tokenOffset,
337
+ getTokenStartLine: () => lineStartOffset,
338
+ getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
339
+ getTokenError: () => scanError
340
+ };
341
+ }
342
+ function isWhiteSpace(ch) {
343
+ return ch === 32 || ch === 9;
344
+ }
345
+ function isLineBreak(ch) {
346
+ return ch === 10 || ch === 13;
347
+ }
348
+ function isDigit(ch) {
349
+ return ch >= 48 && ch <= 57;
350
+ }
351
+ var CharacterCodes;
352
+ (function(CharacterCodes2) {
353
+ CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
354
+ CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
355
+ CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
356
+ CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
357
+ CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
358
+ CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
359
+ CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
360
+ CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
361
+ CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
362
+ CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
363
+ CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
364
+ CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
365
+ CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
366
+ CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
367
+ CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
368
+ CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
369
+ CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
370
+ CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
371
+ CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
372
+ CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
373
+ CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
374
+ CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
375
+ CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
376
+ CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
377
+ CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
378
+ CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
379
+ CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
380
+ CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
381
+ CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
382
+ CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
383
+ CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
384
+ CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
385
+ CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
386
+ CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
387
+ CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
388
+ CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
389
+ CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
390
+ CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
391
+ CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
392
+ CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
393
+ CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
394
+ CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
395
+ CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
396
+ CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
397
+ CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
398
+ CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
399
+ CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
400
+ CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
401
+ CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
402
+ CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
403
+ CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
404
+ CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
405
+ CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
406
+ CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
407
+ CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
408
+ CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
409
+ CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
410
+ CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
411
+ CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
412
+ CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
413
+ CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
414
+ CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
415
+ CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
416
+ CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
417
+ CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
418
+ CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
419
+ CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
420
+ CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
421
+ CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
422
+ CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
423
+ CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
424
+ CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
425
+ CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
426
+ CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
427
+ CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
428
+ CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
429
+ CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
430
+ CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
431
+ CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
432
+ CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
433
+ })(CharacterCodes || (CharacterCodes = {}));
434
+
435
+ // node_modules/jsonc-parser/lib/esm/impl/string-intern.js
436
+ var cachedSpaces = new Array(20).fill(0).map((_, index) => {
437
+ return " ".repeat(index);
438
+ });
439
+ var maxCachedValues = 200;
440
+ var cachedBreakLinesWithSpaces = {
441
+ " ": {
442
+ "\n": new Array(maxCachedValues).fill(0).map((_, index) => {
443
+ return "\n" + " ".repeat(index);
444
+ }),
445
+ "\r": new Array(maxCachedValues).fill(0).map((_, index) => {
446
+ return "\r" + " ".repeat(index);
447
+ }),
448
+ "\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
449
+ return "\r\n" + " ".repeat(index);
450
+ })
451
+ },
452
+ " ": {
453
+ "\n": new Array(maxCachedValues).fill(0).map((_, index) => {
454
+ return "\n" + " ".repeat(index);
455
+ }),
456
+ "\r": new Array(maxCachedValues).fill(0).map((_, index) => {
457
+ return "\r" + " ".repeat(index);
458
+ }),
459
+ "\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
460
+ return "\r\n" + " ".repeat(index);
461
+ })
462
+ }
463
+ };
464
+ var supportedEols = ["\n", "\r", "\r\n"];
465
+
466
+ // node_modules/jsonc-parser/lib/esm/impl/format.js
467
+ function format(documentText, range, options) {
468
+ let initialIndentLevel;
469
+ let formatText;
470
+ let formatTextStart;
471
+ let rangeStart;
472
+ let rangeEnd;
473
+ if (range) {
474
+ rangeStart = range.offset;
475
+ rangeEnd = rangeStart + range.length;
476
+ formatTextStart = rangeStart;
477
+ while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
478
+ formatTextStart--;
479
+ }
480
+ let endOffset = rangeEnd;
481
+ while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
482
+ endOffset++;
483
+ }
484
+ formatText = documentText.substring(formatTextStart, endOffset);
485
+ initialIndentLevel = computeIndentLevel(formatText, options);
486
+ } else {
487
+ formatText = documentText;
488
+ initialIndentLevel = 0;
489
+ formatTextStart = 0;
490
+ rangeStart = 0;
491
+ rangeEnd = documentText.length;
492
+ }
493
+ const eol = getEOL(options, documentText);
494
+ const eolFastPathSupported = supportedEols.includes(eol);
495
+ let numberLineBreaks = 0;
496
+ let indentLevel = 0;
497
+ let indentValue;
498
+ if (options.insertSpaces) {
499
+ indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
500
+ } else {
501
+ indentValue = " ";
502
+ }
503
+ const indentType = indentValue === " " ? " " : " ";
504
+ let scanner = createScanner(formatText, false);
505
+ let hasError = false;
506
+ function newLinesAndIndent() {
507
+ if (numberLineBreaks > 1) {
508
+ return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
509
+ }
510
+ const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
511
+ if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
512
+ return eol + repeat(indentValue, initialIndentLevel + indentLevel);
513
+ }
514
+ if (amountOfSpaces <= 0) {
515
+ return eol;
516
+ }
517
+ return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
518
+ }
519
+ function scanNext() {
520
+ let token = scanner.scan();
521
+ numberLineBreaks = 0;
522
+ while (token === 15 || token === 14) {
523
+ if (token === 14 && options.keepLines) {
524
+ numberLineBreaks += 1;
525
+ } else if (token === 14) {
526
+ numberLineBreaks = 1;
527
+ }
528
+ token = scanner.scan();
529
+ }
530
+ hasError = token === 16 || scanner.getTokenError() !== 0;
531
+ return token;
532
+ }
533
+ const editOperations = [];
534
+ function addEdit(text, startOffset, endOffset) {
535
+ if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
536
+ editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
537
+ }
538
+ }
539
+ let firstToken = scanNext();
540
+ if (options.keepLines && numberLineBreaks > 0) {
541
+ addEdit(repeat(eol, numberLineBreaks), 0, 0);
542
+ }
543
+ if (firstToken !== 17) {
544
+ let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
545
+ let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
546
+ addEdit(initialIndent, formatTextStart, firstTokenStart);
547
+ }
548
+ while (firstToken !== 17) {
549
+ let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
550
+ let secondToken = scanNext();
551
+ let replaceContent = "";
552
+ let needsLineBreak = false;
553
+ while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
554
+ let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
555
+ addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
556
+ firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
557
+ needsLineBreak = secondToken === 12;
558
+ replaceContent = needsLineBreak ? newLinesAndIndent() : "";
559
+ secondToken = scanNext();
560
+ }
561
+ if (secondToken === 2) {
562
+ if (firstToken !== 1) {
563
+ indentLevel--;
564
+ }
565
+ ;
566
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
567
+ replaceContent = newLinesAndIndent();
568
+ } else if (options.keepLines) {
569
+ replaceContent = cachedSpaces[1];
570
+ }
571
+ } else if (secondToken === 4) {
572
+ if (firstToken !== 3) {
573
+ indentLevel--;
574
+ }
575
+ ;
576
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
577
+ replaceContent = newLinesAndIndent();
578
+ } else if (options.keepLines) {
579
+ replaceContent = cachedSpaces[1];
580
+ }
581
+ } else {
582
+ switch (firstToken) {
583
+ case 3:
584
+ case 1:
585
+ indentLevel++;
586
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
587
+ replaceContent = newLinesAndIndent();
588
+ } else {
589
+ replaceContent = cachedSpaces[1];
590
+ }
591
+ break;
592
+ case 5:
593
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
594
+ replaceContent = newLinesAndIndent();
595
+ } else {
596
+ replaceContent = cachedSpaces[1];
597
+ }
598
+ break;
599
+ case 12:
600
+ replaceContent = newLinesAndIndent();
601
+ break;
602
+ case 13:
603
+ if (numberLineBreaks > 0) {
604
+ replaceContent = newLinesAndIndent();
605
+ } else if (!needsLineBreak) {
606
+ replaceContent = cachedSpaces[1];
607
+ }
608
+ break;
609
+ case 6:
610
+ if (options.keepLines && numberLineBreaks > 0) {
611
+ replaceContent = newLinesAndIndent();
612
+ } else if (!needsLineBreak) {
613
+ replaceContent = cachedSpaces[1];
614
+ }
615
+ break;
616
+ case 10:
617
+ if (options.keepLines && numberLineBreaks > 0) {
618
+ replaceContent = newLinesAndIndent();
619
+ } else if (secondToken === 6 && !needsLineBreak) {
620
+ replaceContent = "";
621
+ }
622
+ break;
623
+ case 7:
624
+ case 8:
625
+ case 9:
626
+ case 11:
627
+ case 2:
628
+ case 4:
629
+ if (options.keepLines && numberLineBreaks > 0) {
630
+ replaceContent = newLinesAndIndent();
631
+ } else {
632
+ if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
633
+ replaceContent = cachedSpaces[1];
634
+ } else if (secondToken !== 5 && secondToken !== 17) {
635
+ hasError = true;
636
+ }
637
+ }
638
+ break;
639
+ case 16:
640
+ hasError = true;
641
+ break;
642
+ }
643
+ if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
644
+ replaceContent = newLinesAndIndent();
645
+ }
646
+ }
647
+ if (secondToken === 17) {
648
+ if (options.keepLines && numberLineBreaks > 0) {
649
+ replaceContent = newLinesAndIndent();
650
+ } else {
651
+ replaceContent = options.insertFinalNewline ? eol : "";
652
+ }
653
+ }
654
+ const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
655
+ addEdit(replaceContent, firstTokenEnd, secondTokenStart);
656
+ firstToken = secondToken;
657
+ }
658
+ return editOperations;
659
+ }
660
+ function repeat(s, count) {
661
+ let result = "";
662
+ for (let i = 0; i < count; i++) {
663
+ result += s;
664
+ }
665
+ return result;
666
+ }
667
+ function computeIndentLevel(content, options) {
668
+ let i = 0;
669
+ let nChars = 0;
670
+ const tabSize = options.tabSize || 4;
671
+ while (i < content.length) {
672
+ let ch = content.charAt(i);
673
+ if (ch === cachedSpaces[1]) {
674
+ nChars++;
675
+ } else if (ch === " ") {
676
+ nChars += tabSize;
677
+ } else {
678
+ break;
679
+ }
680
+ i++;
681
+ }
682
+ return Math.floor(nChars / tabSize);
683
+ }
684
+ function getEOL(options, text) {
685
+ for (let i = 0; i < text.length; i++) {
686
+ const ch = text.charAt(i);
687
+ if (ch === "\r") {
688
+ if (i + 1 < text.length && text.charAt(i + 1) === "\n") {
689
+ return "\r\n";
690
+ }
691
+ return "\r";
692
+ } else if (ch === "\n") {
693
+ return "\n";
694
+ }
695
+ }
696
+ return options && options.eol || "\n";
697
+ }
698
+ function isEOL(text, offset) {
699
+ return "\r\n".indexOf(text.charAt(offset)) !== -1;
700
+ }
701
+
702
+ // node_modules/jsonc-parser/lib/esm/impl/parser.js
703
+ var ParseOptions;
704
+ (function(ParseOptions2) {
705
+ ParseOptions2.DEFAULT = {
706
+ allowTrailingComma: false
707
+ };
708
+ })(ParseOptions || (ParseOptions = {}));
709
+ function parse(text, errors = [], options = ParseOptions.DEFAULT) {
710
+ let currentProperty = null;
711
+ let currentParent = [];
712
+ const previousParents = [];
713
+ function onValue(value) {
714
+ if (Array.isArray(currentParent)) {
715
+ currentParent.push(value);
716
+ } else if (currentProperty !== null) {
717
+ currentParent[currentProperty] = value;
718
+ }
719
+ }
720
+ const visitor = {
721
+ onObjectBegin: () => {
722
+ const object = {};
723
+ onValue(object);
724
+ previousParents.push(currentParent);
725
+ currentParent = object;
726
+ currentProperty = null;
727
+ },
728
+ onObjectProperty: (name) => {
729
+ currentProperty = name;
730
+ },
731
+ onObjectEnd: () => {
732
+ currentParent = previousParents.pop();
733
+ },
734
+ onArrayBegin: () => {
735
+ const array = [];
736
+ onValue(array);
737
+ previousParents.push(currentParent);
738
+ currentParent = array;
739
+ currentProperty = null;
740
+ },
741
+ onArrayEnd: () => {
742
+ currentParent = previousParents.pop();
743
+ },
744
+ onLiteralValue: onValue,
745
+ onError: (error, offset, length) => {
746
+ errors.push({ error, offset, length });
747
+ }
748
+ };
749
+ visit(text, visitor, options);
750
+ return currentParent[0];
751
+ }
752
+ function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
753
+ let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
754
+ function ensurePropertyComplete(endOffset) {
755
+ if (currentParent.type === "property") {
756
+ currentParent.length = endOffset - currentParent.offset;
757
+ currentParent = currentParent.parent;
758
+ }
759
+ }
760
+ function onValue(valueNode) {
761
+ currentParent.children.push(valueNode);
762
+ return valueNode;
763
+ }
764
+ const visitor = {
765
+ onObjectBegin: (offset) => {
766
+ currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
767
+ },
768
+ onObjectProperty: (name, offset, length) => {
769
+ currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
770
+ currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
771
+ },
772
+ onObjectEnd: (offset, length) => {
773
+ ensurePropertyComplete(offset + length);
774
+ currentParent.length = offset + length - currentParent.offset;
775
+ currentParent = currentParent.parent;
776
+ ensurePropertyComplete(offset + length);
777
+ },
778
+ onArrayBegin: (offset, length) => {
779
+ currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
780
+ },
781
+ onArrayEnd: (offset, length) => {
782
+ currentParent.length = offset + length - currentParent.offset;
783
+ currentParent = currentParent.parent;
784
+ ensurePropertyComplete(offset + length);
785
+ },
786
+ onLiteralValue: (value, offset, length) => {
787
+ onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
788
+ ensurePropertyComplete(offset + length);
789
+ },
790
+ onSeparator: (sep, offset, length) => {
791
+ if (currentParent.type === "property") {
792
+ if (sep === ":") {
793
+ currentParent.colonOffset = offset;
794
+ } else if (sep === ",") {
795
+ ensurePropertyComplete(offset);
796
+ }
797
+ }
798
+ },
799
+ onError: (error, offset, length) => {
800
+ errors.push({ error, offset, length });
801
+ }
802
+ };
803
+ visit(text, visitor, options);
804
+ const result = currentParent.children[0];
805
+ if (result) {
806
+ delete result.parent;
807
+ }
808
+ return result;
809
+ }
810
+ function findNodeAtLocation(root, path) {
811
+ if (!root) {
812
+ return void 0;
813
+ }
814
+ let node = root;
815
+ for (let segment of path) {
816
+ if (typeof segment === "string") {
817
+ if (node.type !== "object" || !Array.isArray(node.children)) {
818
+ return void 0;
819
+ }
820
+ let found = false;
821
+ for (const propertyNode of node.children) {
822
+ if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
823
+ node = propertyNode.children[1];
824
+ found = true;
825
+ break;
826
+ }
827
+ }
828
+ if (!found) {
829
+ return void 0;
830
+ }
831
+ } else {
832
+ const index = segment;
833
+ if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
834
+ return void 0;
835
+ }
836
+ node = node.children[index];
837
+ }
838
+ }
839
+ return node;
840
+ }
841
+ function visit(text, visitor, options = ParseOptions.DEFAULT) {
842
+ const _scanner = createScanner(text, false);
843
+ const _jsonPath = [];
844
+ let suppressedCallbacks = 0;
845
+ function toNoArgVisit(visitFunction) {
846
+ return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
847
+ }
848
+ function toOneArgVisit(visitFunction) {
849
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
850
+ }
851
+ function toOneArgVisitWithPath(visitFunction) {
852
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
853
+ }
854
+ function toBeginVisit(visitFunction) {
855
+ return visitFunction ? () => {
856
+ if (suppressedCallbacks > 0) {
857
+ suppressedCallbacks++;
858
+ } else {
859
+ let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
860
+ if (cbReturn === false) {
861
+ suppressedCallbacks = 1;
862
+ }
863
+ }
864
+ } : () => true;
865
+ }
866
+ function toEndVisit(visitFunction) {
867
+ return visitFunction ? () => {
868
+ if (suppressedCallbacks > 0) {
869
+ suppressedCallbacks--;
870
+ }
871
+ if (suppressedCallbacks === 0) {
872
+ visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
873
+ }
874
+ } : () => true;
875
+ }
876
+ 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);
877
+ const disallowComments = options && options.disallowComments;
878
+ const allowTrailingComma = options && options.allowTrailingComma;
879
+ function scanNext() {
880
+ while (true) {
881
+ const token = _scanner.scan();
882
+ switch (_scanner.getTokenError()) {
883
+ case 4:
884
+ handleError(
885
+ 14
886
+ /* ParseErrorCode.InvalidUnicode */
887
+ );
888
+ break;
889
+ case 5:
890
+ handleError(
891
+ 15
892
+ /* ParseErrorCode.InvalidEscapeCharacter */
893
+ );
894
+ break;
895
+ case 3:
896
+ handleError(
897
+ 13
898
+ /* ParseErrorCode.UnexpectedEndOfNumber */
899
+ );
900
+ break;
901
+ case 1:
902
+ if (!disallowComments) {
903
+ handleError(
904
+ 11
905
+ /* ParseErrorCode.UnexpectedEndOfComment */
906
+ );
907
+ }
908
+ break;
909
+ case 2:
910
+ handleError(
911
+ 12
912
+ /* ParseErrorCode.UnexpectedEndOfString */
913
+ );
914
+ break;
915
+ case 6:
916
+ handleError(
917
+ 16
918
+ /* ParseErrorCode.InvalidCharacter */
919
+ );
920
+ break;
921
+ }
922
+ switch (token) {
923
+ case 12:
924
+ case 13:
925
+ if (disallowComments) {
926
+ handleError(
927
+ 10
928
+ /* ParseErrorCode.InvalidCommentToken */
929
+ );
930
+ } else {
931
+ onComment();
932
+ }
933
+ break;
934
+ case 16:
935
+ handleError(
936
+ 1
937
+ /* ParseErrorCode.InvalidSymbol */
938
+ );
939
+ break;
940
+ case 15:
941
+ case 14:
942
+ break;
943
+ default:
944
+ return token;
945
+ }
946
+ }
947
+ }
948
+ function handleError(error, skipUntilAfter = [], skipUntil = []) {
949
+ onError(error);
950
+ if (skipUntilAfter.length + skipUntil.length > 0) {
951
+ let token = _scanner.getToken();
952
+ while (token !== 17) {
953
+ if (skipUntilAfter.indexOf(token) !== -1) {
954
+ scanNext();
955
+ break;
956
+ } else if (skipUntil.indexOf(token) !== -1) {
957
+ break;
958
+ }
959
+ token = scanNext();
960
+ }
961
+ }
962
+ }
963
+ function parseString(isValue) {
964
+ const value = _scanner.getTokenValue();
965
+ if (isValue) {
966
+ onLiteralValue(value);
967
+ } else {
968
+ onObjectProperty(value);
969
+ _jsonPath.push(value);
970
+ }
971
+ scanNext();
972
+ return true;
973
+ }
974
+ function parseLiteral() {
975
+ switch (_scanner.getToken()) {
976
+ case 11:
977
+ const tokenValue = _scanner.getTokenValue();
978
+ let value = Number(tokenValue);
979
+ if (isNaN(value)) {
980
+ handleError(
981
+ 2
982
+ /* ParseErrorCode.InvalidNumberFormat */
983
+ );
984
+ value = 0;
985
+ }
986
+ onLiteralValue(value);
987
+ break;
988
+ case 7:
989
+ onLiteralValue(null);
990
+ break;
991
+ case 8:
992
+ onLiteralValue(true);
993
+ break;
994
+ case 9:
995
+ onLiteralValue(false);
996
+ break;
997
+ default:
998
+ return false;
999
+ }
1000
+ scanNext();
1001
+ return true;
1002
+ }
1003
+ function parseProperty() {
1004
+ if (_scanner.getToken() !== 10) {
1005
+ handleError(3, [], [
1006
+ 2,
1007
+ 5
1008
+ /* SyntaxKind.CommaToken */
1009
+ ]);
1010
+ return false;
1011
+ }
1012
+ parseString(false);
1013
+ if (_scanner.getToken() === 6) {
1014
+ onSeparator(":");
1015
+ scanNext();
1016
+ if (!parseValue()) {
1017
+ handleError(4, [], [
1018
+ 2,
1019
+ 5
1020
+ /* SyntaxKind.CommaToken */
1021
+ ]);
1022
+ }
1023
+ } else {
1024
+ handleError(5, [], [
1025
+ 2,
1026
+ 5
1027
+ /* SyntaxKind.CommaToken */
1028
+ ]);
1029
+ }
1030
+ _jsonPath.pop();
1031
+ return true;
1032
+ }
1033
+ function parseObject() {
1034
+ onObjectBegin();
1035
+ scanNext();
1036
+ let needsComma = false;
1037
+ while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
1038
+ if (_scanner.getToken() === 5) {
1039
+ if (!needsComma) {
1040
+ handleError(4, [], []);
1041
+ }
1042
+ onSeparator(",");
1043
+ scanNext();
1044
+ if (_scanner.getToken() === 2 && allowTrailingComma) {
1045
+ break;
1046
+ }
1047
+ } else if (needsComma) {
1048
+ handleError(6, [], []);
1049
+ }
1050
+ if (!parseProperty()) {
1051
+ handleError(4, [], [
1052
+ 2,
1053
+ 5
1054
+ /* SyntaxKind.CommaToken */
1055
+ ]);
1056
+ }
1057
+ needsComma = true;
1058
+ }
1059
+ onObjectEnd();
1060
+ if (_scanner.getToken() !== 2) {
1061
+ handleError(7, [
1062
+ 2
1063
+ /* SyntaxKind.CloseBraceToken */
1064
+ ], []);
1065
+ } else {
1066
+ scanNext();
1067
+ }
1068
+ return true;
1069
+ }
1070
+ function parseArray() {
1071
+ onArrayBegin();
1072
+ scanNext();
1073
+ let isFirstElement = true;
1074
+ let needsComma = false;
1075
+ while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
1076
+ if (_scanner.getToken() === 5) {
1077
+ if (!needsComma) {
1078
+ handleError(4, [], []);
1079
+ }
1080
+ onSeparator(",");
1081
+ scanNext();
1082
+ if (_scanner.getToken() === 4 && allowTrailingComma) {
1083
+ break;
1084
+ }
1085
+ } else if (needsComma) {
1086
+ handleError(6, [], []);
1087
+ }
1088
+ if (isFirstElement) {
1089
+ _jsonPath.push(0);
1090
+ isFirstElement = false;
1091
+ } else {
1092
+ _jsonPath[_jsonPath.length - 1]++;
1093
+ }
1094
+ if (!parseValue()) {
1095
+ handleError(4, [], [
1096
+ 4,
1097
+ 5
1098
+ /* SyntaxKind.CommaToken */
1099
+ ]);
1100
+ }
1101
+ needsComma = true;
1102
+ }
1103
+ onArrayEnd();
1104
+ if (!isFirstElement) {
1105
+ _jsonPath.pop();
1106
+ }
1107
+ if (_scanner.getToken() !== 4) {
1108
+ handleError(8, [
1109
+ 4
1110
+ /* SyntaxKind.CloseBracketToken */
1111
+ ], []);
1112
+ } else {
1113
+ scanNext();
1114
+ }
1115
+ return true;
1116
+ }
1117
+ function parseValue() {
1118
+ switch (_scanner.getToken()) {
1119
+ case 3:
1120
+ return parseArray();
1121
+ case 1:
1122
+ return parseObject();
1123
+ case 10:
1124
+ return parseString(true);
1125
+ default:
1126
+ return parseLiteral();
1127
+ }
1128
+ }
1129
+ scanNext();
1130
+ if (_scanner.getToken() === 17) {
1131
+ if (options.allowEmptyContent) {
1132
+ return true;
1133
+ }
1134
+ handleError(4, [], []);
1135
+ return false;
1136
+ }
1137
+ if (!parseValue()) {
1138
+ handleError(4, [], []);
1139
+ return false;
1140
+ }
1141
+ if (_scanner.getToken() !== 17) {
1142
+ handleError(9, [], []);
1143
+ }
1144
+ return true;
1145
+ }
1146
+ function getNodeType(value) {
1147
+ switch (typeof value) {
1148
+ case "boolean":
1149
+ return "boolean";
1150
+ case "number":
1151
+ return "number";
1152
+ case "string":
1153
+ return "string";
1154
+ case "object": {
1155
+ if (!value) {
1156
+ return "null";
1157
+ } else if (Array.isArray(value)) {
1158
+ return "array";
1159
+ }
1160
+ return "object";
1161
+ }
1162
+ default:
1163
+ return "null";
1164
+ }
1165
+ }
1166
+
1167
+ // node_modules/jsonc-parser/lib/esm/impl/edit.js
1168
+ function setProperty(text, originalPath, value, options) {
1169
+ const path = originalPath.slice();
1170
+ const errors = [];
1171
+ const root = parseTree(text, errors);
1172
+ let parent = void 0;
1173
+ let lastSegment = void 0;
1174
+ while (path.length > 0) {
1175
+ lastSegment = path.pop();
1176
+ parent = findNodeAtLocation(root, path);
1177
+ if (parent === void 0 && value !== void 0) {
1178
+ if (typeof lastSegment === "string") {
1179
+ value = { [lastSegment]: value };
1180
+ } else {
1181
+ value = [value];
1182
+ }
1183
+ } else {
1184
+ break;
1185
+ }
1186
+ }
1187
+ if (!parent) {
1188
+ if (value === void 0) {
1189
+ throw new Error("Can not delete in empty document");
1190
+ }
1191
+ return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
1192
+ } else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
1193
+ const existing = findNodeAtLocation(parent, [lastSegment]);
1194
+ if (existing !== void 0) {
1195
+ if (value === void 0) {
1196
+ if (!existing.parent) {
1197
+ throw new Error("Malformed AST");
1198
+ }
1199
+ const propertyIndex = parent.children.indexOf(existing.parent);
1200
+ let removeBegin;
1201
+ let removeEnd = existing.parent.offset + existing.parent.length;
1202
+ if (propertyIndex > 0) {
1203
+ let previous = parent.children[propertyIndex - 1];
1204
+ removeBegin = previous.offset + previous.length;
1205
+ } else {
1206
+ removeBegin = parent.offset + 1;
1207
+ if (parent.children.length > 1) {
1208
+ let next = parent.children[1];
1209
+ removeEnd = next.offset;
1210
+ }
1211
+ }
1212
+ return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
1213
+ } else {
1214
+ return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
1215
+ }
1216
+ } else {
1217
+ if (value === void 0) {
1218
+ return [];
1219
+ }
1220
+ const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
1221
+ const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
1222
+ let edit;
1223
+ if (index > 0) {
1224
+ let previous = parent.children[index - 1];
1225
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1226
+ } else if (parent.children.length === 0) {
1227
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1228
+ } else {
1229
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
1230
+ }
1231
+ return withFormatting(text, edit, options);
1232
+ }
1233
+ } else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
1234
+ const insertIndex = lastSegment;
1235
+ if (insertIndex === -1) {
1236
+ const newProperty = `${JSON.stringify(value)}`;
1237
+ let edit;
1238
+ if (parent.children.length === 0) {
1239
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1240
+ } else {
1241
+ const previous = parent.children[parent.children.length - 1];
1242
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1243
+ }
1244
+ return withFormatting(text, edit, options);
1245
+ } else if (value === void 0 && parent.children.length >= 0) {
1246
+ const removalIndex = lastSegment;
1247
+ const toRemove = parent.children[removalIndex];
1248
+ let edit;
1249
+ if (parent.children.length === 1) {
1250
+ edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
1251
+ } else if (parent.children.length - 1 === removalIndex) {
1252
+ let previous = parent.children[removalIndex - 1];
1253
+ let offset = previous.offset + previous.length;
1254
+ let parentEndOffset = parent.offset + parent.length;
1255
+ edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
1256
+ } else {
1257
+ edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
1258
+ }
1259
+ return withFormatting(text, edit, options);
1260
+ } else if (value !== void 0) {
1261
+ let edit;
1262
+ const newProperty = `${JSON.stringify(value)}`;
1263
+ if (!options.isArrayInsertion && parent.children.length > lastSegment) {
1264
+ const toModify = parent.children[lastSegment];
1265
+ edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
1266
+ } else if (parent.children.length === 0 || lastSegment === 0) {
1267
+ edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
1268
+ } else {
1269
+ const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
1270
+ const previous = parent.children[index - 1];
1271
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1272
+ }
1273
+ return withFormatting(text, edit, options);
1274
+ } else {
1275
+ throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
1276
+ }
1277
+ } else {
1278
+ throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
1279
+ }
1280
+ }
1281
+ function withFormatting(text, edit, options) {
1282
+ if (!options.formattingOptions) {
1283
+ return [edit];
1284
+ }
1285
+ let newText = applyEdit(text, edit);
1286
+ let begin = edit.offset;
1287
+ let end = edit.offset + edit.content.length;
1288
+ if (edit.length === 0 || edit.content.length === 0) {
1289
+ while (begin > 0 && !isEOL(newText, begin - 1)) {
1290
+ begin--;
1291
+ }
1292
+ while (end < newText.length && !isEOL(newText, end)) {
1293
+ end++;
1294
+ }
1295
+ }
1296
+ const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
1297
+ for (let i = edits.length - 1; i >= 0; i--) {
1298
+ const edit2 = edits[i];
1299
+ newText = applyEdit(newText, edit2);
1300
+ begin = Math.min(begin, edit2.offset);
1301
+ end = Math.max(end, edit2.offset + edit2.length);
1302
+ end += edit2.content.length - edit2.length;
1303
+ }
1304
+ const editLength = text.length - (newText.length - end) - begin;
1305
+ return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
1306
+ }
1307
+ function applyEdit(text, edit) {
1308
+ return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
1309
+ }
1310
+
1311
+ // node_modules/jsonc-parser/lib/esm/main.js
1312
+ var ScanError;
1313
+ (function(ScanError2) {
1314
+ ScanError2[ScanError2["None"] = 0] = "None";
1315
+ ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
1316
+ ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
1317
+ ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
1318
+ ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
1319
+ ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
1320
+ ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
1321
+ })(ScanError || (ScanError = {}));
1322
+ var SyntaxKind;
1323
+ (function(SyntaxKind2) {
1324
+ SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
1325
+ SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
1326
+ SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
1327
+ SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
1328
+ SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
1329
+ SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
1330
+ SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
1331
+ SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
1332
+ SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
1333
+ SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
1334
+ SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
1335
+ SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
1336
+ SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
1337
+ SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
1338
+ SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
1339
+ SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
1340
+ SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
1341
+ })(SyntaxKind || (SyntaxKind = {}));
1342
+ var parse2 = parse;
1343
+ var ParseErrorCode;
1344
+ (function(ParseErrorCode2) {
1345
+ ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
1346
+ ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
1347
+ ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
1348
+ ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
1349
+ ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
1350
+ ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
1351
+ ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
1352
+ ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
1353
+ ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
1354
+ ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
1355
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
1356
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
1357
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
1358
+ ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
1359
+ ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
1360
+ ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
1361
+ })(ParseErrorCode || (ParseErrorCode = {}));
1362
+ function modify(text, path, value, options) {
1363
+ return setProperty(text, path, value, options);
1364
+ }
1365
+ function applyEdits(text, edits) {
1366
+ let sortedEdits = edits.slice(0).sort((a, b) => {
1367
+ const diff = a.offset - b.offset;
1368
+ if (diff === 0) {
1369
+ return a.length - b.length;
1370
+ }
1371
+ return diff;
1372
+ });
1373
+ let lastModifiedOffset = text.length;
1374
+ for (let i = sortedEdits.length - 1; i >= 0; i--) {
1375
+ let e = sortedEdits[i];
1376
+ if (e.offset + e.length <= lastModifiedOffset) {
1377
+ text = applyEdit(text, e);
1378
+ } else {
1379
+ throw new Error("Overlapping edit");
1380
+ }
1381
+ lastModifiedOffset = e.offset;
1382
+ }
1383
+ return text;
1384
+ }
1385
+
1386
+ // packages/cli/lib.ts
1387
+ function createHookPlatform(opts) {
1388
+ return {
1389
+ name: opts.name,
1390
+ configPath: opts.configPath,
1391
+ distPath: opts.distPath,
1392
+ setup: (config, leashPath) => {
1393
+ config.hooks = config.hooks || {};
1394
+ const hookCommand = { type: "command", command: `node ${leashPath}` };
1395
+ const inSessionStart = config.hooks.SessionStart?.some(
1396
+ (entry) => entry.hooks?.some((h) => h.command?.includes("leash"))
1397
+ );
1398
+ const inPreToolUse = config.hooks.PreToolUse?.some(
1399
+ (entry) => entry.hooks?.some((h) => h.command?.includes("leash"))
1400
+ );
1401
+ if (inSessionStart && inPreToolUse) {
1402
+ return { skipped: true };
1403
+ }
1404
+ if (!inSessionStart) {
1405
+ config.hooks.SessionStart = config.hooks.SessionStart || [];
1406
+ config.hooks.SessionStart.push({ hooks: [hookCommand] });
1407
+ }
1408
+ if (!inPreToolUse) {
1409
+ config.hooks.PreToolUse = config.hooks.PreToolUse || [];
1410
+ config.hooks.PreToolUse.push({
1411
+ matcher: opts.preToolUseMatcher,
1412
+ hooks: [hookCommand]
1413
+ });
1414
+ }
1415
+ return { skipped: false };
1416
+ },
1417
+ remove: (config) => {
1418
+ if (!config.hooks) return false;
1419
+ let removed = false;
1420
+ if (config.hooks.SessionStart) {
1421
+ const before = config.hooks.SessionStart.length;
1422
+ config.hooks.SessionStart = config.hooks.SessionStart.filter(
1423
+ (entry) => !entry.hooks?.some((h) => h.command?.includes("leash"))
1424
+ );
1425
+ if (config.hooks.SessionStart.length < before) removed = true;
1426
+ }
1427
+ if (config.hooks.PreToolUse) {
1428
+ const before = config.hooks.PreToolUse.length;
1429
+ config.hooks.PreToolUse = config.hooks.PreToolUse.filter(
1430
+ (entry) => !entry.hooks?.some((h) => h.command?.includes("leash"))
1431
+ );
1432
+ if (config.hooks.PreToolUse.length < before) removed = true;
1433
+ }
1434
+ return removed;
1435
+ }
1436
+ };
1437
+ }
1438
+ var PLATFORMS = {
1439
+ opencode: {
1440
+ name: "OpenCode",
1441
+ configPaths: [
1442
+ ".config/opencode/opencode.jsonc",
1443
+ ".config/opencode/opencode.json"
1444
+ ],
1445
+ distPath: "opencode/leash.js"
1446
+ // opencode config is JSONC (supports comments). Generic readConfig/writeConfig use JSON.stringify
1447
+ // which strips comments. setupOpenCode/removeOpenCode handle this via jsonc-parser instead.
1448
+ },
1449
+ pi: {
1450
+ name: "Pi",
1451
+ configPath: ".pi/agent/settings.json",
1452
+ distPath: "pi/leash.js",
1453
+ setup: (config, leashPath) => {
1454
+ config.extensions = config.extensions || [];
1455
+ if (config.extensions.some((e) => e.includes("leash"))) {
1456
+ return { skipped: true };
1457
+ }
1458
+ config.extensions.push(leashPath);
1459
+ return { skipped: false };
1460
+ },
1461
+ remove: (config) => {
1462
+ if (!config.extensions) return false;
1463
+ const before = config.extensions.length;
1464
+ config.extensions = config.extensions.filter((e) => !e.includes("leash"));
1465
+ return config.extensions.length < before;
1466
+ }
1467
+ },
1468
+ "claude-code": createHookPlatform({
1469
+ name: "Claude Code",
1470
+ configPath: ".claude/settings.json",
1471
+ distPath: "claude-code/leash.js",
1472
+ preToolUseMatcher: "Bash|Write|Edit"
1473
+ }),
1474
+ factory: createHookPlatform({
1475
+ name: "Factory",
1476
+ configPath: ".factory/settings.json",
1477
+ distPath: "factory/leash.js",
1478
+ preToolUseMatcher: "Execute|Write|Edit"
1479
+ })
1480
+ };
1481
+ function readConfig(configPath) {
1482
+ if (!existsSync(configPath)) {
1483
+ return {};
1484
+ }
1485
+ const content = readFileSync(configPath, "utf-8");
1486
+ const errors = [];
1487
+ const config = parse2(content, errors);
1488
+ if (errors.length > 0) {
1489
+ throw new Error(`Invalid JSON/JSONC in ${configPath}`);
1490
+ }
1491
+ return config;
1492
+ }
1493
+ function writeConfig(configPath, config) {
1494
+ const dir = dirname(configPath);
1495
+ if (!existsSync(dir)) {
1496
+ mkdirSync(dir, { recursive: true });
1497
+ }
1498
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
1499
+ }
1500
+ function setupOpenCode(configPath, leashPath) {
1501
+ const formatOptions = { tabSize: 2, insertSpaces: true };
1502
+ let content = "";
1503
+ let config = {};
1504
+ if (existsSync(configPath)) {
1505
+ content = readFileSync(configPath, "utf-8");
1506
+ const errors = [];
1507
+ config = parse2(content, errors);
1508
+ if (errors.length > 0) {
1509
+ return { error: `Invalid JSON/JSONC in ${configPath}` };
1510
+ }
1511
+ }
1512
+ if (config.plugin?.some((p) => p.includes("leash"))) {
1513
+ return { skipped: true, platform: "OpenCode" };
1514
+ }
1515
+ let edits;
1516
+ if (!config.plugin) {
1517
+ edits = modify(content, ["plugin"], [leashPath], { formattingOptions: formatOptions });
1518
+ } else {
1519
+ edits = modify(content, ["plugin", -1], leashPath, { formattingOptions: formatOptions });
1520
+ }
1521
+ const newContent = applyEdits(content, edits);
1522
+ const dir = dirname(configPath);
1523
+ if (!existsSync(dir)) {
1524
+ mkdirSync(dir, { recursive: true });
1525
+ }
1526
+ writeFileSync(configPath, newContent);
1527
+ return { success: true, platform: "OpenCode", configPath };
1528
+ }
1529
+ function removeOpenCode(configPath) {
1530
+ if (!existsSync(configPath)) {
1531
+ return { notFound: true, platform: "OpenCode" };
1532
+ }
1533
+ const content = readFileSync(configPath, "utf-8");
1534
+ const errors = [];
1535
+ const config = parse2(content, errors);
1536
+ if (errors.length > 0) {
1537
+ return { error: `Invalid JSON/JSONC in ${configPath}` };
1538
+ }
1539
+ if (!config.plugin) {
1540
+ return { notInstalled: true, platform: "OpenCode" };
1541
+ }
1542
+ const leashIndex = config.plugin.findIndex((p) => p.includes("leash"));
1543
+ if (leashIndex === -1) {
1544
+ return { notInstalled: true, platform: "OpenCode" };
1545
+ }
1546
+ const formatOptions = { tabSize: 2, insertSpaces: true };
1547
+ const edits = modify(content, ["plugin", leashIndex], void 0, { formattingOptions: formatOptions });
1548
+ const newContent = applyEdits(content, edits);
1549
+ writeFileSync(configPath, newContent);
1550
+ return { success: true, platform: "OpenCode" };
1551
+ }
1552
+ function setupPlatform(platformKey, configPath, leashPath) {
1553
+ const platform2 = PLATFORMS[platformKey];
1554
+ if (!platform2) {
1555
+ return { error: `Unknown platform: ${platformKey}` };
1556
+ }
1557
+ if (platformKey === "opencode") {
1558
+ return setupOpenCode(configPath, leashPath);
1559
+ }
1560
+ const config = readConfig(configPath);
1561
+ if (!platform2.setup) {
1562
+ return { error: `Platform ${platformKey} has no setup handler` };
1563
+ }
1564
+ const result = platform2.setup(config, leashPath);
1565
+ if (result.skipped) {
1566
+ return { skipped: true, platform: platform2.name };
1567
+ }
1568
+ writeConfig(configPath, config);
1569
+ return { success: true, platform: platform2.name, configPath };
1570
+ }
1571
+ function removePlatform(platformKey, configPath) {
1572
+ const platform2 = PLATFORMS[platformKey];
1573
+ if (!platform2) {
1574
+ return { error: `Unknown platform: ${platformKey}` };
1575
+ }
1576
+ if (platformKey === "opencode") {
1577
+ return removeOpenCode(configPath);
1578
+ }
1579
+ if (!existsSync(configPath)) {
1580
+ return { notFound: true, platform: platform2.name };
1581
+ }
1582
+ const config = readConfig(configPath);
1583
+ if (!platform2.remove) {
1584
+ return { error: `Platform ${platformKey} has no remove handler` };
1585
+ }
1586
+ const removed = platform2.remove(config);
1587
+ if (!removed) {
1588
+ return { notInstalled: true, platform: platform2.name };
1589
+ }
1590
+ writeConfig(configPath, config);
1591
+ return { success: true, platform: platform2.name };
1592
+ }
1593
+
1594
+ // packages/core/version-checker.ts
1595
+ import { readFileSync as readFileSync2, existsSync as existsSync2 } from "fs";
1596
+ import { dirname as dirname2, join } from "path";
1597
+ import { fileURLToPath } from "url";
1598
+ function getVersion() {
1599
+ const __dirname2 = dirname2(fileURLToPath(import.meta.url));
1600
+ const candidates = [
1601
+ join(__dirname2, "..", "..", "package.json"),
1602
+ join(__dirname2, "..", "..", "..", "package.json")
1603
+ ];
1604
+ for (const path of candidates) {
1605
+ if (existsSync2(path)) {
1606
+ try {
1607
+ const pkg = JSON.parse(readFileSync2(path, "utf-8"));
1608
+ if (pkg.name === "@melihmucuk/leash") {
1609
+ return pkg.version;
1610
+ }
1611
+ } catch {
1612
+ }
1613
+ }
1614
+ }
1615
+ return "0.0.0";
1616
+ }
1617
+ var CURRENT_VERSION = getVersion();
1618
+ var NPM_REGISTRY_URL = "https://registry.npmjs.org/@melihmucuk/leash/latest";
1619
+ async function checkForUpdates() {
1620
+ try {
1621
+ const response = await fetch(NPM_REGISTRY_URL);
1622
+ if (!response.ok) {
1623
+ return { hasUpdate: false, currentVersion: CURRENT_VERSION };
1624
+ }
1625
+ const data = await response.json();
1626
+ return {
1627
+ hasUpdate: data.version !== CURRENT_VERSION,
1628
+ latestVersion: data.version,
1629
+ currentVersion: CURRENT_VERSION
1630
+ };
1631
+ } catch {
1632
+ return { hasUpdate: false, currentVersion: CURRENT_VERSION };
1633
+ }
1634
+ }
1635
+
1636
+ // packages/cli/leash.ts
1637
+ var __dirname = dirname3(fileURLToPath2(import.meta.url));
1638
+ function getDistPath() {
1639
+ return join2(__dirname, "..");
1640
+ }
1641
+ function getConfigPath(platformKey) {
1642
+ const platform2 = PLATFORMS[platformKey];
1643
+ if (!platform2) return null;
1644
+ if (platform2.configPaths) {
1645
+ for (const p of platform2.configPaths) {
1646
+ const full = join2(homedir(), p);
1647
+ if (existsSync3(full)) return full;
1648
+ }
1649
+ return join2(homedir(), platform2.configPaths.at(-1));
1650
+ }
1651
+ return join2(homedir(), platform2.configPath);
1652
+ }
1653
+ function getLeashPath(platformKey) {
1654
+ const platform2 = PLATFORMS[platformKey];
1655
+ return platform2 ? join2(getDistPath(), platform2.distPath) : null;
1656
+ }
1657
+ function setup(platformKey) {
1658
+ const configPath = getConfigPath(platformKey);
1659
+ const leashPath = getLeashPath(platformKey);
1660
+ if (!configPath || !leashPath) {
1661
+ console.error(`Unknown platform: ${platformKey}`);
1662
+ console.error(`Available: ${Object.keys(PLATFORMS).join(", ")}`);
1663
+ process.exit(1);
1664
+ }
1665
+ if (!existsSync3(leashPath)) {
1666
+ console.error(`Leash not found at: ${leashPath}`);
1667
+ process.exit(1);
1668
+ }
1669
+ const result = setupPlatform(platformKey, configPath, leashPath);
1670
+ if (result.error) {
1671
+ console.error(result.error);
1672
+ process.exit(1);
1673
+ }
1674
+ if (result.skipped) {
1675
+ console.log(`[ok] Leash already installed for ${result.platform}`);
1676
+ return;
1677
+ }
1678
+ console.log(`[ok] Config: ${result.configPath}`);
1679
+ console.log(`[ok] Leash installed for ${result.platform}`);
1680
+ console.log(`[ok] Restart ${result.platform} to apply changes`);
1681
+ }
1682
+ function remove(platformKey) {
1683
+ const configPath = getConfigPath(platformKey);
1684
+ if (!configPath) {
1685
+ console.error(`Unknown platform: ${platformKey}`);
1686
+ console.error(`Available: ${Object.keys(PLATFORMS).join(", ")}`);
1687
+ process.exit(1);
1688
+ }
1689
+ const result = removePlatform(platformKey, configPath);
1690
+ if (result.error) {
1691
+ console.error(result.error);
1692
+ process.exit(1);
1693
+ }
1694
+ if (result.notFound) {
1695
+ console.log(`[ok] No config found for ${result.platform}`);
1696
+ return;
1697
+ }
1698
+ if (result.notInstalled) {
1699
+ console.log(`[ok] Leash not found in ${result.platform} config`);
1700
+ return;
1701
+ }
1702
+ console.log(`[ok] Leash removed from ${result.platform}`);
1703
+ console.log(`[ok] Restart ${result.platform} to apply changes`);
1704
+ }
1705
+ function showPath(platformKey) {
1706
+ const leashPath = getLeashPath(platformKey);
1707
+ if (!leashPath) {
1708
+ console.error(`Unknown platform: ${platformKey}`);
1709
+ console.error(`Available: ${Object.keys(PLATFORMS).join(", ")}`);
1710
+ process.exit(1);
1711
+ }
1712
+ console.log(leashPath);
1713
+ }
1714
+ async function update() {
1715
+ console.log("Checking for updates...");
1716
+ const result = await checkForUpdates();
1717
+ if (!result.hasUpdate) {
1718
+ console.log(`[ok] Already up to date (v${result.currentVersion})`);
1719
+ return;
1720
+ }
1721
+ console.log(`[ok] Update available: v${result.currentVersion} \u2192 v${result.latestVersion}`);
1722
+ console.log("[ok] Updating...");
1723
+ try {
1724
+ execSync("npm update -g @melihmucuk/leash", { stdio: "inherit" });
1725
+ console.log("[ok] Update complete");
1726
+ } catch {
1727
+ console.error("[error] Update failed. Try manually: npm update -g @melihmucuk/leash");
1728
+ process.exit(1);
1729
+ }
1730
+ }
1731
+ function showHelp() {
1732
+ console.log(`
1733
+ leash - Security guardrails for AI coding agents
1734
+
1735
+ Usage:
1736
+ leash --setup <platform> Install leash for a platform
1737
+ leash --remove <platform> Remove leash from a platform
1738
+ leash --path <platform> Show leash path for a platform
1739
+ leash --update Update leash to latest version
1740
+ leash --help Show this help
1741
+
1742
+ Platforms:
1743
+ opencode OpenCode
1744
+ pi Pi Coding Agent
1745
+ claude-code Claude Code
1746
+ factory Factory Droid
1747
+
1748
+ Examples:
1749
+ leash --setup opencode
1750
+ leash --remove claude-code
1751
+ leash --path pi
1752
+ leash --update
1753
+ `);
1754
+ }
1755
+ var args = process.argv.slice(2);
1756
+ var command = args[0];
1757
+ var platform = args[1];
1758
+ switch (command) {
1759
+ case "--setup":
1760
+ case "-s":
1761
+ if (!platform) {
1762
+ console.error("Missing platform argument");
1763
+ showHelp();
1764
+ process.exit(1);
1765
+ }
1766
+ setup(platform);
1767
+ break;
1768
+ case "--remove":
1769
+ case "-r":
1770
+ if (!platform) {
1771
+ console.error("Missing platform argument");
1772
+ showHelp();
1773
+ process.exit(1);
1774
+ }
1775
+ remove(platform);
1776
+ break;
1777
+ case "--path":
1778
+ case "-p":
1779
+ if (!platform) {
1780
+ console.error("Missing platform argument");
1781
+ showHelp();
1782
+ process.exit(1);
1783
+ }
1784
+ showPath(platform);
1785
+ break;
1786
+ case "--update":
1787
+ case "-u":
1788
+ await update();
1789
+ break;
1790
+ case "--help":
1791
+ case "-h":
1792
+ case void 0:
1793
+ showHelp();
1794
+ break;
1795
+ default:
1796
+ console.error(`Unknown command: ${command}`);
1797
+ showHelp();
1798
+ process.exit(1);
1799
+ }