ccman 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +4195 -0
  2. package/package.json +3 -2
package/dist/index.js ADDED
@@ -0,0 +1,4195 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJS = (cb, mod) => function __require() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+
29
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/parser.js
30
+ var require_parser = __commonJS({
31
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/parser.js"(exports2, module2) {
32
+ "use strict";
33
+ var ParserEND = 1114112;
34
+ var ParserError = class _ParserError extends Error {
35
+ /* istanbul ignore next */
36
+ constructor(msg, filename, linenumber) {
37
+ super("[ParserError] " + msg, filename, linenumber);
38
+ this.name = "ParserError";
39
+ this.code = "ParserError";
40
+ if (Error.captureStackTrace) Error.captureStackTrace(this, _ParserError);
41
+ }
42
+ };
43
+ var State = class {
44
+ constructor(parser) {
45
+ this.parser = parser;
46
+ this.buf = "";
47
+ this.returned = null;
48
+ this.result = null;
49
+ this.resultTable = null;
50
+ this.resultArr = null;
51
+ }
52
+ };
53
+ var Parser = class {
54
+ constructor() {
55
+ this.pos = 0;
56
+ this.col = 0;
57
+ this.line = 0;
58
+ this.obj = {};
59
+ this.ctx = this.obj;
60
+ this.stack = [];
61
+ this._buf = "";
62
+ this.char = null;
63
+ this.ii = 0;
64
+ this.state = new State(this.parseStart);
65
+ }
66
+ parse(str) {
67
+ if (str.length === 0 || str.length == null) return;
68
+ this._buf = String(str);
69
+ this.ii = -1;
70
+ this.char = -1;
71
+ let getNext;
72
+ while (getNext === false || this.nextChar()) {
73
+ getNext = this.runOne();
74
+ }
75
+ this._buf = null;
76
+ }
77
+ nextChar() {
78
+ if (this.char === 10) {
79
+ ++this.line;
80
+ this.col = -1;
81
+ }
82
+ ++this.ii;
83
+ this.char = this._buf.codePointAt(this.ii);
84
+ ++this.pos;
85
+ ++this.col;
86
+ return this.haveBuffer();
87
+ }
88
+ haveBuffer() {
89
+ return this.ii < this._buf.length;
90
+ }
91
+ runOne() {
92
+ return this.state.parser.call(this, this.state.returned);
93
+ }
94
+ finish() {
95
+ this.char = ParserEND;
96
+ let last;
97
+ do {
98
+ last = this.state.parser;
99
+ this.runOne();
100
+ } while (this.state.parser !== last);
101
+ this.ctx = null;
102
+ this.state = null;
103
+ this._buf = null;
104
+ return this.obj;
105
+ }
106
+ next(fn) {
107
+ if (typeof fn !== "function") throw new ParserError("Tried to set state to non-existent state: " + JSON.stringify(fn));
108
+ this.state.parser = fn;
109
+ }
110
+ goto(fn) {
111
+ this.next(fn);
112
+ return this.runOne();
113
+ }
114
+ call(fn, returnWith) {
115
+ if (returnWith) this.next(returnWith);
116
+ this.stack.push(this.state);
117
+ this.state = new State(fn);
118
+ }
119
+ callNow(fn, returnWith) {
120
+ this.call(fn, returnWith);
121
+ return this.runOne();
122
+ }
123
+ return(value) {
124
+ if (this.stack.length === 0) throw this.error(new ParserError("Stack underflow"));
125
+ if (value === void 0) value = this.state.buf;
126
+ this.state = this.stack.pop();
127
+ this.state.returned = value;
128
+ }
129
+ returnNow(value) {
130
+ this.return(value);
131
+ return this.runOne();
132
+ }
133
+ consume() {
134
+ if (this.char === ParserEND) throw this.error(new ParserError("Unexpected end-of-buffer"));
135
+ this.state.buf += this._buf[this.ii];
136
+ }
137
+ error(err) {
138
+ err.line = this.line;
139
+ err.col = this.col;
140
+ err.pos = this.pos;
141
+ return err;
142
+ }
143
+ /* istanbul ignore next */
144
+ parseStart() {
145
+ throw new ParserError("Must declare a parseStart method");
146
+ }
147
+ };
148
+ Parser.END = ParserEND;
149
+ Parser.Error = ParserError;
150
+ module2.exports = Parser;
151
+ }
152
+ });
153
+
154
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime.js
155
+ var require_create_datetime = __commonJS({
156
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime.js"(exports2, module2) {
157
+ "use strict";
158
+ module2.exports = (value) => {
159
+ const date = new Date(value);
160
+ if (isNaN(date)) {
161
+ throw new TypeError("Invalid Datetime");
162
+ } else {
163
+ return date;
164
+ }
165
+ };
166
+ }
167
+ });
168
+
169
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/format-num.js
170
+ var require_format_num = __commonJS({
171
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/format-num.js"(exports2, module2) {
172
+ "use strict";
173
+ module2.exports = (d, num) => {
174
+ num = String(num);
175
+ while (num.length < d) num = "0" + num;
176
+ return num;
177
+ };
178
+ }
179
+ });
180
+
181
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime-float.js
182
+ var require_create_datetime_float = __commonJS({
183
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime-float.js"(exports2, module2) {
184
+ "use strict";
185
+ var f = require_format_num();
186
+ var FloatingDateTime = class extends Date {
187
+ constructor(value) {
188
+ super(value + "Z");
189
+ this.isFloating = true;
190
+ }
191
+ toISOString() {
192
+ const date = `${this.getUTCFullYear()}-${f(2, this.getUTCMonth() + 1)}-${f(2, this.getUTCDate())}`;
193
+ const time = `${f(2, this.getUTCHours())}:${f(2, this.getUTCMinutes())}:${f(2, this.getUTCSeconds())}.${f(3, this.getUTCMilliseconds())}`;
194
+ return `${date}T${time}`;
195
+ }
196
+ };
197
+ module2.exports = (value) => {
198
+ const date = new FloatingDateTime(value);
199
+ if (isNaN(date)) {
200
+ throw new TypeError("Invalid Datetime");
201
+ } else {
202
+ return date;
203
+ }
204
+ };
205
+ }
206
+ });
207
+
208
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-date.js
209
+ var require_create_date = __commonJS({
210
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-date.js"(exports2, module2) {
211
+ "use strict";
212
+ var f = require_format_num();
213
+ var DateTime = global.Date;
214
+ var Date2 = class extends DateTime {
215
+ constructor(value) {
216
+ super(value);
217
+ this.isDate = true;
218
+ }
219
+ toISOString() {
220
+ return `${this.getUTCFullYear()}-${f(2, this.getUTCMonth() + 1)}-${f(2, this.getUTCDate())}`;
221
+ }
222
+ };
223
+ module2.exports = (value) => {
224
+ const date = new Date2(value);
225
+ if (isNaN(date)) {
226
+ throw new TypeError("Invalid Datetime");
227
+ } else {
228
+ return date;
229
+ }
230
+ };
231
+ }
232
+ });
233
+
234
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-time.js
235
+ var require_create_time = __commonJS({
236
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-time.js"(exports2, module2) {
237
+ "use strict";
238
+ var f = require_format_num();
239
+ var Time = class extends Date {
240
+ constructor(value) {
241
+ super(`0000-01-01T${value}Z`);
242
+ this.isTime = true;
243
+ }
244
+ toISOString() {
245
+ return `${f(2, this.getUTCHours())}:${f(2, this.getUTCMinutes())}:${f(2, this.getUTCSeconds())}.${f(3, this.getUTCMilliseconds())}`;
246
+ }
247
+ };
248
+ module2.exports = (value) => {
249
+ const date = new Time(value);
250
+ if (isNaN(date)) {
251
+ throw new TypeError("Invalid Datetime");
252
+ } else {
253
+ return date;
254
+ }
255
+ };
256
+ }
257
+ });
258
+
259
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/toml-parser.js
260
+ var require_toml_parser = __commonJS({
261
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/toml-parser.js"(exports, module) {
262
+ "use strict";
263
+ module.exports = makeParserClass(require_parser());
264
+ module.exports.makeParserClass = makeParserClass;
265
+ var TomlError = class _TomlError extends Error {
266
+ constructor(msg) {
267
+ super(msg);
268
+ this.name = "TomlError";
269
+ if (Error.captureStackTrace) Error.captureStackTrace(this, _TomlError);
270
+ this.fromTOML = true;
271
+ this.wrapped = null;
272
+ }
273
+ };
274
+ TomlError.wrap = (err) => {
275
+ const terr = new TomlError(err.message);
276
+ terr.code = err.code;
277
+ terr.wrapped = err;
278
+ return terr;
279
+ };
280
+ module.exports.TomlError = TomlError;
281
+ var createDateTime = require_create_datetime();
282
+ var createDateTimeFloat = require_create_datetime_float();
283
+ var createDate = require_create_date();
284
+ var createTime = require_create_time();
285
+ var CTRL_I = 9;
286
+ var CTRL_J = 10;
287
+ var CTRL_M = 13;
288
+ var CTRL_CHAR_BOUNDARY = 31;
289
+ var CHAR_SP = 32;
290
+ var CHAR_QUOT = 34;
291
+ var CHAR_NUM = 35;
292
+ var CHAR_APOS = 39;
293
+ var CHAR_PLUS = 43;
294
+ var CHAR_COMMA = 44;
295
+ var CHAR_HYPHEN = 45;
296
+ var CHAR_PERIOD = 46;
297
+ var CHAR_0 = 48;
298
+ var CHAR_1 = 49;
299
+ var CHAR_7 = 55;
300
+ var CHAR_9 = 57;
301
+ var CHAR_COLON = 58;
302
+ var CHAR_EQUALS = 61;
303
+ var CHAR_A = 65;
304
+ var CHAR_E = 69;
305
+ var CHAR_F = 70;
306
+ var CHAR_T = 84;
307
+ var CHAR_U = 85;
308
+ var CHAR_Z = 90;
309
+ var CHAR_LOWBAR = 95;
310
+ var CHAR_a = 97;
311
+ var CHAR_b = 98;
312
+ var CHAR_e = 101;
313
+ var CHAR_f = 102;
314
+ var CHAR_i = 105;
315
+ var CHAR_l = 108;
316
+ var CHAR_n = 110;
317
+ var CHAR_o = 111;
318
+ var CHAR_r = 114;
319
+ var CHAR_s = 115;
320
+ var CHAR_t = 116;
321
+ var CHAR_u = 117;
322
+ var CHAR_x = 120;
323
+ var CHAR_z = 122;
324
+ var CHAR_LCUB = 123;
325
+ var CHAR_RCUB = 125;
326
+ var CHAR_LSQB = 91;
327
+ var CHAR_BSOL = 92;
328
+ var CHAR_RSQB = 93;
329
+ var CHAR_DEL = 127;
330
+ var SURROGATE_FIRST = 55296;
331
+ var SURROGATE_LAST = 57343;
332
+ var escapes = {
333
+ [CHAR_b]: "\b",
334
+ [CHAR_t]: " ",
335
+ [CHAR_n]: "\n",
336
+ [CHAR_f]: "\f",
337
+ [CHAR_r]: "\r",
338
+ [CHAR_QUOT]: '"',
339
+ [CHAR_BSOL]: "\\"
340
+ };
341
+ function isDigit(cp) {
342
+ return cp >= CHAR_0 && cp <= CHAR_9;
343
+ }
344
+ function isHexit(cp) {
345
+ return cp >= CHAR_A && cp <= CHAR_F || cp >= CHAR_a && cp <= CHAR_f || cp >= CHAR_0 && cp <= CHAR_9;
346
+ }
347
+ function isBit(cp) {
348
+ return cp === CHAR_1 || cp === CHAR_0;
349
+ }
350
+ function isOctit(cp) {
351
+ return cp >= CHAR_0 && cp <= CHAR_7;
352
+ }
353
+ function isAlphaNumQuoteHyphen(cp) {
354
+ return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_APOS || cp === CHAR_QUOT || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
355
+ }
356
+ function isAlphaNumHyphen(cp) {
357
+ return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
358
+ }
359
+ var _type = Symbol("type");
360
+ var _declared = Symbol("declared");
361
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
362
+ var defineProperty = Object.defineProperty;
363
+ var descriptor = { configurable: true, enumerable: true, writable: true, value: void 0 };
364
+ function hasKey(obj, key) {
365
+ if (hasOwnProperty.call(obj, key)) return true;
366
+ if (key === "__proto__") defineProperty(obj, "__proto__", descriptor);
367
+ return false;
368
+ }
369
+ var INLINE_TABLE = Symbol("inline-table");
370
+ function InlineTable() {
371
+ return Object.defineProperties({}, {
372
+ [_type]: { value: INLINE_TABLE }
373
+ });
374
+ }
375
+ function isInlineTable(obj) {
376
+ if (obj === null || typeof obj !== "object") return false;
377
+ return obj[_type] === INLINE_TABLE;
378
+ }
379
+ var TABLE = Symbol("table");
380
+ function Table() {
381
+ return Object.defineProperties({}, {
382
+ [_type]: { value: TABLE },
383
+ [_declared]: { value: false, writable: true }
384
+ });
385
+ }
386
+ function isTable(obj) {
387
+ if (obj === null || typeof obj !== "object") return false;
388
+ return obj[_type] === TABLE;
389
+ }
390
+ var _contentType = Symbol("content-type");
391
+ var INLINE_LIST = Symbol("inline-list");
392
+ function InlineList(type) {
393
+ return Object.defineProperties([], {
394
+ [_type]: { value: INLINE_LIST },
395
+ [_contentType]: { value: type }
396
+ });
397
+ }
398
+ function isInlineList(obj) {
399
+ if (obj === null || typeof obj !== "object") return false;
400
+ return obj[_type] === INLINE_LIST;
401
+ }
402
+ var LIST = Symbol("list");
403
+ function List() {
404
+ return Object.defineProperties([], {
405
+ [_type]: { value: LIST }
406
+ });
407
+ }
408
+ function isList(obj) {
409
+ if (obj === null || typeof obj !== "object") return false;
410
+ return obj[_type] === LIST;
411
+ }
412
+ var _custom;
413
+ try {
414
+ const utilInspect = eval("require('util').inspect");
415
+ _custom = utilInspect.custom;
416
+ } catch (_) {
417
+ }
418
+ var _inspect = _custom || "inspect";
419
+ var BoxedBigInt = class {
420
+ constructor(value) {
421
+ try {
422
+ this.value = global.BigInt.asIntN(64, value);
423
+ } catch (_) {
424
+ this.value = null;
425
+ }
426
+ Object.defineProperty(this, _type, { value: INTEGER });
427
+ }
428
+ isNaN() {
429
+ return this.value === null;
430
+ }
431
+ /* istanbul ignore next */
432
+ toString() {
433
+ return String(this.value);
434
+ }
435
+ /* istanbul ignore next */
436
+ [_inspect]() {
437
+ return `[BigInt: ${this.toString()}]}`;
438
+ }
439
+ valueOf() {
440
+ return this.value;
441
+ }
442
+ };
443
+ var INTEGER = Symbol("integer");
444
+ function Integer(value) {
445
+ let num = Number(value);
446
+ if (Object.is(num, -0)) num = 0;
447
+ if (global.BigInt && !Number.isSafeInteger(num)) {
448
+ return new BoxedBigInt(value);
449
+ } else {
450
+ return Object.defineProperties(new Number(num), {
451
+ isNaN: { value: function() {
452
+ return isNaN(this);
453
+ } },
454
+ [_type]: { value: INTEGER },
455
+ [_inspect]: { value: () => `[Integer: ${value}]` }
456
+ });
457
+ }
458
+ }
459
+ function isInteger(obj) {
460
+ if (obj === null || typeof obj !== "object") return false;
461
+ return obj[_type] === INTEGER;
462
+ }
463
+ var FLOAT = Symbol("float");
464
+ function Float(value) {
465
+ return Object.defineProperties(new Number(value), {
466
+ [_type]: { value: FLOAT },
467
+ [_inspect]: { value: () => `[Float: ${value}]` }
468
+ });
469
+ }
470
+ function isFloat(obj) {
471
+ if (obj === null || typeof obj !== "object") return false;
472
+ return obj[_type] === FLOAT;
473
+ }
474
+ function tomlType(value) {
475
+ const type = typeof value;
476
+ if (type === "object") {
477
+ if (value === null) return "null";
478
+ if (value instanceof Date) return "datetime";
479
+ if (_type in value) {
480
+ switch (value[_type]) {
481
+ case INLINE_TABLE:
482
+ return "inline-table";
483
+ case INLINE_LIST:
484
+ return "inline-list";
485
+ /* istanbul ignore next */
486
+ case TABLE:
487
+ return "table";
488
+ /* istanbul ignore next */
489
+ case LIST:
490
+ return "list";
491
+ case FLOAT:
492
+ return "float";
493
+ case INTEGER:
494
+ return "integer";
495
+ }
496
+ }
497
+ }
498
+ return type;
499
+ }
500
+ function makeParserClass(Parser) {
501
+ class TOMLParser extends Parser {
502
+ constructor() {
503
+ super();
504
+ this.ctx = this.obj = Table();
505
+ }
506
+ /* MATCH HELPER */
507
+ atEndOfWord() {
508
+ return this.char === CHAR_NUM || this.char === CTRL_I || this.char === CHAR_SP || this.atEndOfLine();
509
+ }
510
+ atEndOfLine() {
511
+ return this.char === Parser.END || this.char === CTRL_J || this.char === CTRL_M;
512
+ }
513
+ parseStart() {
514
+ if (this.char === Parser.END) {
515
+ return null;
516
+ } else if (this.char === CHAR_LSQB) {
517
+ return this.call(this.parseTableOrList);
518
+ } else if (this.char === CHAR_NUM) {
519
+ return this.call(this.parseComment);
520
+ } else if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
521
+ return null;
522
+ } else if (isAlphaNumQuoteHyphen(this.char)) {
523
+ return this.callNow(this.parseAssignStatement);
524
+ } else {
525
+ throw this.error(new TomlError(`Unknown character "${this.char}"`));
526
+ }
527
+ }
528
+ // HELPER, this strips any whitespace and comments to the end of the line
529
+ // then RETURNS. Last state in a production.
530
+ parseWhitespaceToEOL() {
531
+ if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
532
+ return null;
533
+ } else if (this.char === CHAR_NUM) {
534
+ return this.goto(this.parseComment);
535
+ } else if (this.char === Parser.END || this.char === CTRL_J) {
536
+ return this.return();
537
+ } else {
538
+ throw this.error(new TomlError("Unexpected character, expected only whitespace or comments till end of line"));
539
+ }
540
+ }
541
+ /* ASSIGNMENT: key = value */
542
+ parseAssignStatement() {
543
+ return this.callNow(this.parseAssign, this.recordAssignStatement);
544
+ }
545
+ recordAssignStatement(kv) {
546
+ let target = this.ctx;
547
+ let finalKey = kv.key.pop();
548
+ for (let kw of kv.key) {
549
+ if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
550
+ throw this.error(new TomlError("Can't redefine existing key"));
551
+ }
552
+ target = target[kw] = target[kw] || Table();
553
+ }
554
+ if (hasKey(target, finalKey)) {
555
+ throw this.error(new TomlError("Can't redefine existing key"));
556
+ }
557
+ if (isInteger(kv.value) || isFloat(kv.value)) {
558
+ target[finalKey] = kv.value.valueOf();
559
+ } else {
560
+ target[finalKey] = kv.value;
561
+ }
562
+ return this.goto(this.parseWhitespaceToEOL);
563
+ }
564
+ /* ASSSIGNMENT expression, key = value possibly inside an inline table */
565
+ parseAssign() {
566
+ return this.callNow(this.parseKeyword, this.recordAssignKeyword);
567
+ }
568
+ recordAssignKeyword(key) {
569
+ if (this.state.resultTable) {
570
+ this.state.resultTable.push(key);
571
+ } else {
572
+ this.state.resultTable = [key];
573
+ }
574
+ return this.goto(this.parseAssignKeywordPreDot);
575
+ }
576
+ parseAssignKeywordPreDot() {
577
+ if (this.char === CHAR_PERIOD) {
578
+ return this.next(this.parseAssignKeywordPostDot);
579
+ } else if (this.char !== CHAR_SP && this.char !== CTRL_I) {
580
+ return this.goto(this.parseAssignEqual);
581
+ }
582
+ }
583
+ parseAssignKeywordPostDot() {
584
+ if (this.char !== CHAR_SP && this.char !== CTRL_I) {
585
+ return this.callNow(this.parseKeyword, this.recordAssignKeyword);
586
+ }
587
+ }
588
+ parseAssignEqual() {
589
+ if (this.char === CHAR_EQUALS) {
590
+ return this.next(this.parseAssignPreValue);
591
+ } else {
592
+ throw this.error(new TomlError('Invalid character, expected "="'));
593
+ }
594
+ }
595
+ parseAssignPreValue() {
596
+ if (this.char === CHAR_SP || this.char === CTRL_I) {
597
+ return null;
598
+ } else {
599
+ return this.callNow(this.parseValue, this.recordAssignValue);
600
+ }
601
+ }
602
+ recordAssignValue(value) {
603
+ return this.returnNow({ key: this.state.resultTable, value });
604
+ }
605
+ /* COMMENTS: #...eol */
606
+ parseComment() {
607
+ do {
608
+ if (this.char === Parser.END || this.char === CTRL_J) {
609
+ return this.return();
610
+ }
611
+ } while (this.nextChar());
612
+ }
613
+ /* TABLES AND LISTS, [foo] and [[foo]] */
614
+ parseTableOrList() {
615
+ if (this.char === CHAR_LSQB) {
616
+ this.next(this.parseList);
617
+ } else {
618
+ return this.goto(this.parseTable);
619
+ }
620
+ }
621
+ /* TABLE [foo.bar.baz] */
622
+ parseTable() {
623
+ this.ctx = this.obj;
624
+ return this.goto(this.parseTableNext);
625
+ }
626
+ parseTableNext() {
627
+ if (this.char === CHAR_SP || this.char === CTRL_I) {
628
+ return null;
629
+ } else {
630
+ return this.callNow(this.parseKeyword, this.parseTableMore);
631
+ }
632
+ }
633
+ parseTableMore(keyword) {
634
+ if (this.char === CHAR_SP || this.char === CTRL_I) {
635
+ return null;
636
+ } else if (this.char === CHAR_RSQB) {
637
+ if (hasKey(this.ctx, keyword) && (!isTable(this.ctx[keyword]) || this.ctx[keyword][_declared])) {
638
+ throw this.error(new TomlError("Can't redefine existing key"));
639
+ } else {
640
+ this.ctx = this.ctx[keyword] = this.ctx[keyword] || Table();
641
+ this.ctx[_declared] = true;
642
+ }
643
+ return this.next(this.parseWhitespaceToEOL);
644
+ } else if (this.char === CHAR_PERIOD) {
645
+ if (!hasKey(this.ctx, keyword)) {
646
+ this.ctx = this.ctx[keyword] = Table();
647
+ } else if (isTable(this.ctx[keyword])) {
648
+ this.ctx = this.ctx[keyword];
649
+ } else if (isList(this.ctx[keyword])) {
650
+ this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
651
+ } else {
652
+ throw this.error(new TomlError("Can't redefine existing key"));
653
+ }
654
+ return this.next(this.parseTableNext);
655
+ } else {
656
+ throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
657
+ }
658
+ }
659
+ /* LIST [[a.b.c]] */
660
+ parseList() {
661
+ this.ctx = this.obj;
662
+ return this.goto(this.parseListNext);
663
+ }
664
+ parseListNext() {
665
+ if (this.char === CHAR_SP || this.char === CTRL_I) {
666
+ return null;
667
+ } else {
668
+ return this.callNow(this.parseKeyword, this.parseListMore);
669
+ }
670
+ }
671
+ parseListMore(keyword) {
672
+ if (this.char === CHAR_SP || this.char === CTRL_I) {
673
+ return null;
674
+ } else if (this.char === CHAR_RSQB) {
675
+ if (!hasKey(this.ctx, keyword)) {
676
+ this.ctx[keyword] = List();
677
+ }
678
+ if (isInlineList(this.ctx[keyword])) {
679
+ throw this.error(new TomlError("Can't extend an inline array"));
680
+ } else if (isList(this.ctx[keyword])) {
681
+ const next = Table();
682
+ this.ctx[keyword].push(next);
683
+ this.ctx = next;
684
+ } else {
685
+ throw this.error(new TomlError("Can't redefine an existing key"));
686
+ }
687
+ return this.next(this.parseListEnd);
688
+ } else if (this.char === CHAR_PERIOD) {
689
+ if (!hasKey(this.ctx, keyword)) {
690
+ this.ctx = this.ctx[keyword] = Table();
691
+ } else if (isInlineList(this.ctx[keyword])) {
692
+ throw this.error(new TomlError("Can't extend an inline array"));
693
+ } else if (isInlineTable(this.ctx[keyword])) {
694
+ throw this.error(new TomlError("Can't extend an inline table"));
695
+ } else if (isList(this.ctx[keyword])) {
696
+ this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
697
+ } else if (isTable(this.ctx[keyword])) {
698
+ this.ctx = this.ctx[keyword];
699
+ } else {
700
+ throw this.error(new TomlError("Can't redefine an existing key"));
701
+ }
702
+ return this.next(this.parseListNext);
703
+ } else {
704
+ throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
705
+ }
706
+ }
707
+ parseListEnd(keyword) {
708
+ if (this.char === CHAR_RSQB) {
709
+ return this.next(this.parseWhitespaceToEOL);
710
+ } else {
711
+ throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
712
+ }
713
+ }
714
+ /* VALUE string, number, boolean, inline list, inline object */
715
+ parseValue() {
716
+ if (this.char === Parser.END) {
717
+ throw this.error(new TomlError("Key without value"));
718
+ } else if (this.char === CHAR_QUOT) {
719
+ return this.next(this.parseDoubleString);
720
+ }
721
+ if (this.char === CHAR_APOS) {
722
+ return this.next(this.parseSingleString);
723
+ } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
724
+ return this.goto(this.parseNumberSign);
725
+ } else if (this.char === CHAR_i) {
726
+ return this.next(this.parseInf);
727
+ } else if (this.char === CHAR_n) {
728
+ return this.next(this.parseNan);
729
+ } else if (isDigit(this.char)) {
730
+ return this.goto(this.parseNumberOrDateTime);
731
+ } else if (this.char === CHAR_t || this.char === CHAR_f) {
732
+ return this.goto(this.parseBoolean);
733
+ } else if (this.char === CHAR_LSQB) {
734
+ return this.call(this.parseInlineList, this.recordValue);
735
+ } else if (this.char === CHAR_LCUB) {
736
+ return this.call(this.parseInlineTable, this.recordValue);
737
+ } else {
738
+ throw this.error(new TomlError("Unexpected character, expecting string, number, datetime, boolean, inline array or inline table"));
739
+ }
740
+ }
741
+ recordValue(value) {
742
+ return this.returnNow(value);
743
+ }
744
+ parseInf() {
745
+ if (this.char === CHAR_n) {
746
+ return this.next(this.parseInf2);
747
+ } else {
748
+ throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
749
+ }
750
+ }
751
+ parseInf2() {
752
+ if (this.char === CHAR_f) {
753
+ if (this.state.buf === "-") {
754
+ return this.return(-Infinity);
755
+ } else {
756
+ return this.return(Infinity);
757
+ }
758
+ } else {
759
+ throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
760
+ }
761
+ }
762
+ parseNan() {
763
+ if (this.char === CHAR_a) {
764
+ return this.next(this.parseNan2);
765
+ } else {
766
+ throw this.error(new TomlError('Unexpected character, expected "nan"'));
767
+ }
768
+ }
769
+ parseNan2() {
770
+ if (this.char === CHAR_n) {
771
+ return this.return(NaN);
772
+ } else {
773
+ throw this.error(new TomlError('Unexpected character, expected "nan"'));
774
+ }
775
+ }
776
+ /* KEYS, barewords or basic, literal, or dotted */
777
+ parseKeyword() {
778
+ if (this.char === CHAR_QUOT) {
779
+ return this.next(this.parseBasicString);
780
+ } else if (this.char === CHAR_APOS) {
781
+ return this.next(this.parseLiteralString);
782
+ } else {
783
+ return this.goto(this.parseBareKey);
784
+ }
785
+ }
786
+ /* KEYS: barewords */
787
+ parseBareKey() {
788
+ do {
789
+ if (this.char === Parser.END) {
790
+ throw this.error(new TomlError("Key ended without value"));
791
+ } else if (isAlphaNumHyphen(this.char)) {
792
+ this.consume();
793
+ } else if (this.state.buf.length === 0) {
794
+ throw this.error(new TomlError("Empty bare keys are not allowed"));
795
+ } else {
796
+ return this.returnNow();
797
+ }
798
+ } while (this.nextChar());
799
+ }
800
+ /* STRINGS, single quoted (literal) */
801
+ parseSingleString() {
802
+ if (this.char === CHAR_APOS) {
803
+ return this.next(this.parseLiteralMultiStringMaybe);
804
+ } else {
805
+ return this.goto(this.parseLiteralString);
806
+ }
807
+ }
808
+ parseLiteralString() {
809
+ do {
810
+ if (this.char === CHAR_APOS) {
811
+ return this.return();
812
+ } else if (this.atEndOfLine()) {
813
+ throw this.error(new TomlError("Unterminated string"));
814
+ } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
815
+ throw this.errorControlCharInString();
816
+ } else {
817
+ this.consume();
818
+ }
819
+ } while (this.nextChar());
820
+ }
821
+ parseLiteralMultiStringMaybe() {
822
+ if (this.char === CHAR_APOS) {
823
+ return this.next(this.parseLiteralMultiString);
824
+ } else {
825
+ return this.returnNow();
826
+ }
827
+ }
828
+ parseLiteralMultiString() {
829
+ if (this.char === CTRL_M) {
830
+ return null;
831
+ } else if (this.char === CTRL_J) {
832
+ return this.next(this.parseLiteralMultiStringContent);
833
+ } else {
834
+ return this.goto(this.parseLiteralMultiStringContent);
835
+ }
836
+ }
837
+ parseLiteralMultiStringContent() {
838
+ do {
839
+ if (this.char === CHAR_APOS) {
840
+ return this.next(this.parseLiteralMultiEnd);
841
+ } else if (this.char === Parser.END) {
842
+ throw this.error(new TomlError("Unterminated multi-line string"));
843
+ } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
844
+ throw this.errorControlCharInString();
845
+ } else {
846
+ this.consume();
847
+ }
848
+ } while (this.nextChar());
849
+ }
850
+ parseLiteralMultiEnd() {
851
+ if (this.char === CHAR_APOS) {
852
+ return this.next(this.parseLiteralMultiEnd2);
853
+ } else {
854
+ this.state.buf += "'";
855
+ return this.goto(this.parseLiteralMultiStringContent);
856
+ }
857
+ }
858
+ parseLiteralMultiEnd2() {
859
+ if (this.char === CHAR_APOS) {
860
+ return this.return();
861
+ } else {
862
+ this.state.buf += "''";
863
+ return this.goto(this.parseLiteralMultiStringContent);
864
+ }
865
+ }
866
+ /* STRINGS double quoted */
867
+ parseDoubleString() {
868
+ if (this.char === CHAR_QUOT) {
869
+ return this.next(this.parseMultiStringMaybe);
870
+ } else {
871
+ return this.goto(this.parseBasicString);
872
+ }
873
+ }
874
+ parseBasicString() {
875
+ do {
876
+ if (this.char === CHAR_BSOL) {
877
+ return this.call(this.parseEscape, this.recordEscapeReplacement);
878
+ } else if (this.char === CHAR_QUOT) {
879
+ return this.return();
880
+ } else if (this.atEndOfLine()) {
881
+ throw this.error(new TomlError("Unterminated string"));
882
+ } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
883
+ throw this.errorControlCharInString();
884
+ } else {
885
+ this.consume();
886
+ }
887
+ } while (this.nextChar());
888
+ }
889
+ recordEscapeReplacement(replacement) {
890
+ this.state.buf += replacement;
891
+ return this.goto(this.parseBasicString);
892
+ }
893
+ parseMultiStringMaybe() {
894
+ if (this.char === CHAR_QUOT) {
895
+ return this.next(this.parseMultiString);
896
+ } else {
897
+ return this.returnNow();
898
+ }
899
+ }
900
+ parseMultiString() {
901
+ if (this.char === CTRL_M) {
902
+ return null;
903
+ } else if (this.char === CTRL_J) {
904
+ return this.next(this.parseMultiStringContent);
905
+ } else {
906
+ return this.goto(this.parseMultiStringContent);
907
+ }
908
+ }
909
+ parseMultiStringContent() {
910
+ do {
911
+ if (this.char === CHAR_BSOL) {
912
+ return this.call(this.parseMultiEscape, this.recordMultiEscapeReplacement);
913
+ } else if (this.char === CHAR_QUOT) {
914
+ return this.next(this.parseMultiEnd);
915
+ } else if (this.char === Parser.END) {
916
+ throw this.error(new TomlError("Unterminated multi-line string"));
917
+ } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
918
+ throw this.errorControlCharInString();
919
+ } else {
920
+ this.consume();
921
+ }
922
+ } while (this.nextChar());
923
+ }
924
+ errorControlCharInString() {
925
+ let displayCode = "\\u00";
926
+ if (this.char < 16) {
927
+ displayCode += "0";
928
+ }
929
+ displayCode += this.char.toString(16);
930
+ return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`));
931
+ }
932
+ recordMultiEscapeReplacement(replacement) {
933
+ this.state.buf += replacement;
934
+ return this.goto(this.parseMultiStringContent);
935
+ }
936
+ parseMultiEnd() {
937
+ if (this.char === CHAR_QUOT) {
938
+ return this.next(this.parseMultiEnd2);
939
+ } else {
940
+ this.state.buf += '"';
941
+ return this.goto(this.parseMultiStringContent);
942
+ }
943
+ }
944
+ parseMultiEnd2() {
945
+ if (this.char === CHAR_QUOT) {
946
+ return this.return();
947
+ } else {
948
+ this.state.buf += '""';
949
+ return this.goto(this.parseMultiStringContent);
950
+ }
951
+ }
952
+ parseMultiEscape() {
953
+ if (this.char === CTRL_M || this.char === CTRL_J) {
954
+ return this.next(this.parseMultiTrim);
955
+ } else if (this.char === CHAR_SP || this.char === CTRL_I) {
956
+ return this.next(this.parsePreMultiTrim);
957
+ } else {
958
+ return this.goto(this.parseEscape);
959
+ }
960
+ }
961
+ parsePreMultiTrim() {
962
+ if (this.char === CHAR_SP || this.char === CTRL_I) {
963
+ return null;
964
+ } else if (this.char === CTRL_M || this.char === CTRL_J) {
965
+ return this.next(this.parseMultiTrim);
966
+ } else {
967
+ throw this.error(new TomlError("Can't escape whitespace"));
968
+ }
969
+ }
970
+ parseMultiTrim() {
971
+ if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
972
+ return null;
973
+ } else {
974
+ return this.returnNow();
975
+ }
976
+ }
977
+ parseEscape() {
978
+ if (this.char in escapes) {
979
+ return this.return(escapes[this.char]);
980
+ } else if (this.char === CHAR_u) {
981
+ return this.call(this.parseSmallUnicode, this.parseUnicodeReturn);
982
+ } else if (this.char === CHAR_U) {
983
+ return this.call(this.parseLargeUnicode, this.parseUnicodeReturn);
984
+ } else {
985
+ throw this.error(new TomlError("Unknown escape character: " + this.char));
986
+ }
987
+ }
988
+ parseUnicodeReturn(char) {
989
+ try {
990
+ const codePoint = parseInt(char, 16);
991
+ if (codePoint >= SURROGATE_FIRST && codePoint <= SURROGATE_LAST) {
992
+ throw this.error(new TomlError("Invalid unicode, character in range 0xD800 - 0xDFFF is reserved"));
993
+ }
994
+ return this.returnNow(String.fromCodePoint(codePoint));
995
+ } catch (err) {
996
+ throw this.error(TomlError.wrap(err));
997
+ }
998
+ }
999
+ parseSmallUnicode() {
1000
+ if (!isHexit(this.char)) {
1001
+ throw this.error(new TomlError("Invalid character in unicode sequence, expected hex"));
1002
+ } else {
1003
+ this.consume();
1004
+ if (this.state.buf.length >= 4) return this.return();
1005
+ }
1006
+ }
1007
+ parseLargeUnicode() {
1008
+ if (!isHexit(this.char)) {
1009
+ throw this.error(new TomlError("Invalid character in unicode sequence, expected hex"));
1010
+ } else {
1011
+ this.consume();
1012
+ if (this.state.buf.length >= 8) return this.return();
1013
+ }
1014
+ }
1015
+ /* NUMBERS */
1016
+ parseNumberSign() {
1017
+ this.consume();
1018
+ return this.next(this.parseMaybeSignedInfOrNan);
1019
+ }
1020
+ parseMaybeSignedInfOrNan() {
1021
+ if (this.char === CHAR_i) {
1022
+ return this.next(this.parseInf);
1023
+ } else if (this.char === CHAR_n) {
1024
+ return this.next(this.parseNan);
1025
+ } else {
1026
+ return this.callNow(this.parseNoUnder, this.parseNumberIntegerStart);
1027
+ }
1028
+ }
1029
+ parseNumberIntegerStart() {
1030
+ if (this.char === CHAR_0) {
1031
+ this.consume();
1032
+ return this.next(this.parseNumberIntegerExponentOrDecimal);
1033
+ } else {
1034
+ return this.goto(this.parseNumberInteger);
1035
+ }
1036
+ }
1037
+ parseNumberIntegerExponentOrDecimal() {
1038
+ if (this.char === CHAR_PERIOD) {
1039
+ this.consume();
1040
+ return this.call(this.parseNoUnder, this.parseNumberFloat);
1041
+ } else if (this.char === CHAR_E || this.char === CHAR_e) {
1042
+ this.consume();
1043
+ return this.next(this.parseNumberExponentSign);
1044
+ } else {
1045
+ return this.returnNow(Integer(this.state.buf));
1046
+ }
1047
+ }
1048
+ parseNumberInteger() {
1049
+ if (isDigit(this.char)) {
1050
+ this.consume();
1051
+ } else if (this.char === CHAR_LOWBAR) {
1052
+ return this.call(this.parseNoUnder);
1053
+ } else if (this.char === CHAR_E || this.char === CHAR_e) {
1054
+ this.consume();
1055
+ return this.next(this.parseNumberExponentSign);
1056
+ } else if (this.char === CHAR_PERIOD) {
1057
+ this.consume();
1058
+ return this.call(this.parseNoUnder, this.parseNumberFloat);
1059
+ } else {
1060
+ const result = Integer(this.state.buf);
1061
+ if (result.isNaN()) {
1062
+ throw this.error(new TomlError("Invalid number"));
1063
+ } else {
1064
+ return this.returnNow(result);
1065
+ }
1066
+ }
1067
+ }
1068
+ parseNoUnder() {
1069
+ if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD || this.char === CHAR_E || this.char === CHAR_e) {
1070
+ throw this.error(new TomlError("Unexpected character, expected digit"));
1071
+ } else if (this.atEndOfWord()) {
1072
+ throw this.error(new TomlError("Incomplete number"));
1073
+ }
1074
+ return this.returnNow();
1075
+ }
1076
+ parseNoUnderHexOctBinLiteral() {
1077
+ if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD) {
1078
+ throw this.error(new TomlError("Unexpected character, expected digit"));
1079
+ } else if (this.atEndOfWord()) {
1080
+ throw this.error(new TomlError("Incomplete number"));
1081
+ }
1082
+ return this.returnNow();
1083
+ }
1084
+ parseNumberFloat() {
1085
+ if (this.char === CHAR_LOWBAR) {
1086
+ return this.call(this.parseNoUnder, this.parseNumberFloat);
1087
+ } else if (isDigit(this.char)) {
1088
+ this.consume();
1089
+ } else if (this.char === CHAR_E || this.char === CHAR_e) {
1090
+ this.consume();
1091
+ return this.next(this.parseNumberExponentSign);
1092
+ } else {
1093
+ return this.returnNow(Float(this.state.buf));
1094
+ }
1095
+ }
1096
+ parseNumberExponentSign() {
1097
+ if (isDigit(this.char)) {
1098
+ return this.goto(this.parseNumberExponent);
1099
+ } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
1100
+ this.consume();
1101
+ this.call(this.parseNoUnder, this.parseNumberExponent);
1102
+ } else {
1103
+ throw this.error(new TomlError("Unexpected character, expected -, + or digit"));
1104
+ }
1105
+ }
1106
+ parseNumberExponent() {
1107
+ if (isDigit(this.char)) {
1108
+ this.consume();
1109
+ } else if (this.char === CHAR_LOWBAR) {
1110
+ return this.call(this.parseNoUnder);
1111
+ } else {
1112
+ return this.returnNow(Float(this.state.buf));
1113
+ }
1114
+ }
1115
+ /* NUMBERS or DATETIMES */
1116
+ parseNumberOrDateTime() {
1117
+ if (this.char === CHAR_0) {
1118
+ this.consume();
1119
+ return this.next(this.parseNumberBaseOrDateTime);
1120
+ } else {
1121
+ return this.goto(this.parseNumberOrDateTimeOnly);
1122
+ }
1123
+ }
1124
+ parseNumberOrDateTimeOnly() {
1125
+ if (this.char === CHAR_LOWBAR) {
1126
+ return this.call(this.parseNoUnder, this.parseNumberInteger);
1127
+ } else if (isDigit(this.char)) {
1128
+ this.consume();
1129
+ if (this.state.buf.length > 4) this.next(this.parseNumberInteger);
1130
+ } else if (this.char === CHAR_E || this.char === CHAR_e) {
1131
+ this.consume();
1132
+ return this.next(this.parseNumberExponentSign);
1133
+ } else if (this.char === CHAR_PERIOD) {
1134
+ this.consume();
1135
+ return this.call(this.parseNoUnder, this.parseNumberFloat);
1136
+ } else if (this.char === CHAR_HYPHEN) {
1137
+ return this.goto(this.parseDateTime);
1138
+ } else if (this.char === CHAR_COLON) {
1139
+ return this.goto(this.parseOnlyTimeHour);
1140
+ } else {
1141
+ return this.returnNow(Integer(this.state.buf));
1142
+ }
1143
+ }
1144
+ parseDateTimeOnly() {
1145
+ if (this.state.buf.length < 4) {
1146
+ if (isDigit(this.char)) {
1147
+ return this.consume();
1148
+ } else if (this.char === CHAR_COLON) {
1149
+ return this.goto(this.parseOnlyTimeHour);
1150
+ } else {
1151
+ throw this.error(new TomlError("Expected digit while parsing year part of a date"));
1152
+ }
1153
+ } else {
1154
+ if (this.char === CHAR_HYPHEN) {
1155
+ return this.goto(this.parseDateTime);
1156
+ } else {
1157
+ throw this.error(new TomlError("Expected hyphen (-) while parsing year part of date"));
1158
+ }
1159
+ }
1160
+ }
1161
+ parseNumberBaseOrDateTime() {
1162
+ if (this.char === CHAR_b) {
1163
+ this.consume();
1164
+ return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerBin);
1165
+ } else if (this.char === CHAR_o) {
1166
+ this.consume();
1167
+ return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerOct);
1168
+ } else if (this.char === CHAR_x) {
1169
+ this.consume();
1170
+ return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerHex);
1171
+ } else if (this.char === CHAR_PERIOD) {
1172
+ return this.goto(this.parseNumberInteger);
1173
+ } else if (isDigit(this.char)) {
1174
+ return this.goto(this.parseDateTimeOnly);
1175
+ } else {
1176
+ return this.returnNow(Integer(this.state.buf));
1177
+ }
1178
+ }
1179
+ parseIntegerHex() {
1180
+ if (isHexit(this.char)) {
1181
+ this.consume();
1182
+ } else if (this.char === CHAR_LOWBAR) {
1183
+ return this.call(this.parseNoUnderHexOctBinLiteral);
1184
+ } else {
1185
+ const result = Integer(this.state.buf);
1186
+ if (result.isNaN()) {
1187
+ throw this.error(new TomlError("Invalid number"));
1188
+ } else {
1189
+ return this.returnNow(result);
1190
+ }
1191
+ }
1192
+ }
1193
+ parseIntegerOct() {
1194
+ if (isOctit(this.char)) {
1195
+ this.consume();
1196
+ } else if (this.char === CHAR_LOWBAR) {
1197
+ return this.call(this.parseNoUnderHexOctBinLiteral);
1198
+ } else {
1199
+ const result = Integer(this.state.buf);
1200
+ if (result.isNaN()) {
1201
+ throw this.error(new TomlError("Invalid number"));
1202
+ } else {
1203
+ return this.returnNow(result);
1204
+ }
1205
+ }
1206
+ }
1207
+ parseIntegerBin() {
1208
+ if (isBit(this.char)) {
1209
+ this.consume();
1210
+ } else if (this.char === CHAR_LOWBAR) {
1211
+ return this.call(this.parseNoUnderHexOctBinLiteral);
1212
+ } else {
1213
+ const result = Integer(this.state.buf);
1214
+ if (result.isNaN()) {
1215
+ throw this.error(new TomlError("Invalid number"));
1216
+ } else {
1217
+ return this.returnNow(result);
1218
+ }
1219
+ }
1220
+ }
1221
+ /* DATETIME */
1222
+ parseDateTime() {
1223
+ if (this.state.buf.length < 4) {
1224
+ throw this.error(new TomlError("Years less than 1000 must be zero padded to four characters"));
1225
+ }
1226
+ this.state.result = this.state.buf;
1227
+ this.state.buf = "";
1228
+ return this.next(this.parseDateMonth);
1229
+ }
1230
+ parseDateMonth() {
1231
+ if (this.char === CHAR_HYPHEN) {
1232
+ if (this.state.buf.length < 2) {
1233
+ throw this.error(new TomlError("Months less than 10 must be zero padded to two characters"));
1234
+ }
1235
+ this.state.result += "-" + this.state.buf;
1236
+ this.state.buf = "";
1237
+ return this.next(this.parseDateDay);
1238
+ } else if (isDigit(this.char)) {
1239
+ this.consume();
1240
+ } else {
1241
+ throw this.error(new TomlError("Incomplete datetime"));
1242
+ }
1243
+ }
1244
+ parseDateDay() {
1245
+ if (this.char === CHAR_T || this.char === CHAR_SP) {
1246
+ if (this.state.buf.length < 2) {
1247
+ throw this.error(new TomlError("Days less than 10 must be zero padded to two characters"));
1248
+ }
1249
+ this.state.result += "-" + this.state.buf;
1250
+ this.state.buf = "";
1251
+ return this.next(this.parseStartTimeHour);
1252
+ } else if (this.atEndOfWord()) {
1253
+ return this.returnNow(createDate(this.state.result + "-" + this.state.buf));
1254
+ } else if (isDigit(this.char)) {
1255
+ this.consume();
1256
+ } else {
1257
+ throw this.error(new TomlError("Incomplete datetime"));
1258
+ }
1259
+ }
1260
+ parseStartTimeHour() {
1261
+ if (this.atEndOfWord()) {
1262
+ return this.returnNow(createDate(this.state.result));
1263
+ } else {
1264
+ return this.goto(this.parseTimeHour);
1265
+ }
1266
+ }
1267
+ parseTimeHour() {
1268
+ if (this.char === CHAR_COLON) {
1269
+ if (this.state.buf.length < 2) {
1270
+ throw this.error(new TomlError("Hours less than 10 must be zero padded to two characters"));
1271
+ }
1272
+ this.state.result += "T" + this.state.buf;
1273
+ this.state.buf = "";
1274
+ return this.next(this.parseTimeMin);
1275
+ } else if (isDigit(this.char)) {
1276
+ this.consume();
1277
+ } else {
1278
+ throw this.error(new TomlError("Incomplete datetime"));
1279
+ }
1280
+ }
1281
+ parseTimeMin() {
1282
+ if (this.state.buf.length < 2 && isDigit(this.char)) {
1283
+ this.consume();
1284
+ } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
1285
+ this.state.result += ":" + this.state.buf;
1286
+ this.state.buf = "";
1287
+ return this.next(this.parseTimeSec);
1288
+ } else {
1289
+ throw this.error(new TomlError("Incomplete datetime"));
1290
+ }
1291
+ }
1292
+ parseTimeSec() {
1293
+ if (isDigit(this.char)) {
1294
+ this.consume();
1295
+ if (this.state.buf.length === 2) {
1296
+ this.state.result += ":" + this.state.buf;
1297
+ this.state.buf = "";
1298
+ return this.next(this.parseTimeZoneOrFraction);
1299
+ }
1300
+ } else {
1301
+ throw this.error(new TomlError("Incomplete datetime"));
1302
+ }
1303
+ }
1304
+ parseOnlyTimeHour() {
1305
+ if (this.char === CHAR_COLON) {
1306
+ if (this.state.buf.length < 2) {
1307
+ throw this.error(new TomlError("Hours less than 10 must be zero padded to two characters"));
1308
+ }
1309
+ this.state.result = this.state.buf;
1310
+ this.state.buf = "";
1311
+ return this.next(this.parseOnlyTimeMin);
1312
+ } else {
1313
+ throw this.error(new TomlError("Incomplete time"));
1314
+ }
1315
+ }
1316
+ parseOnlyTimeMin() {
1317
+ if (this.state.buf.length < 2 && isDigit(this.char)) {
1318
+ this.consume();
1319
+ } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
1320
+ this.state.result += ":" + this.state.buf;
1321
+ this.state.buf = "";
1322
+ return this.next(this.parseOnlyTimeSec);
1323
+ } else {
1324
+ throw this.error(new TomlError("Incomplete time"));
1325
+ }
1326
+ }
1327
+ parseOnlyTimeSec() {
1328
+ if (isDigit(this.char)) {
1329
+ this.consume();
1330
+ if (this.state.buf.length === 2) {
1331
+ return this.next(this.parseOnlyTimeFractionMaybe);
1332
+ }
1333
+ } else {
1334
+ throw this.error(new TomlError("Incomplete time"));
1335
+ }
1336
+ }
1337
+ parseOnlyTimeFractionMaybe() {
1338
+ this.state.result += ":" + this.state.buf;
1339
+ if (this.char === CHAR_PERIOD) {
1340
+ this.state.buf = "";
1341
+ this.next(this.parseOnlyTimeFraction);
1342
+ } else {
1343
+ return this.return(createTime(this.state.result));
1344
+ }
1345
+ }
1346
+ parseOnlyTimeFraction() {
1347
+ if (isDigit(this.char)) {
1348
+ this.consume();
1349
+ } else if (this.atEndOfWord()) {
1350
+ if (this.state.buf.length === 0) throw this.error(new TomlError("Expected digit in milliseconds"));
1351
+ return this.returnNow(createTime(this.state.result + "." + this.state.buf));
1352
+ } else {
1353
+ throw this.error(new TomlError("Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z"));
1354
+ }
1355
+ }
1356
+ parseTimeZoneOrFraction() {
1357
+ if (this.char === CHAR_PERIOD) {
1358
+ this.consume();
1359
+ this.next(this.parseDateTimeFraction);
1360
+ } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
1361
+ this.consume();
1362
+ this.next(this.parseTimeZoneHour);
1363
+ } else if (this.char === CHAR_Z) {
1364
+ this.consume();
1365
+ return this.return(createDateTime(this.state.result + this.state.buf));
1366
+ } else if (this.atEndOfWord()) {
1367
+ return this.returnNow(createDateTimeFloat(this.state.result + this.state.buf));
1368
+ } else {
1369
+ throw this.error(new TomlError("Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z"));
1370
+ }
1371
+ }
1372
+ parseDateTimeFraction() {
1373
+ if (isDigit(this.char)) {
1374
+ this.consume();
1375
+ } else if (this.state.buf.length === 1) {
1376
+ throw this.error(new TomlError("Expected digit in milliseconds"));
1377
+ } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
1378
+ this.consume();
1379
+ this.next(this.parseTimeZoneHour);
1380
+ } else if (this.char === CHAR_Z) {
1381
+ this.consume();
1382
+ return this.return(createDateTime(this.state.result + this.state.buf));
1383
+ } else if (this.atEndOfWord()) {
1384
+ return this.returnNow(createDateTimeFloat(this.state.result + this.state.buf));
1385
+ } else {
1386
+ throw this.error(new TomlError("Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z"));
1387
+ }
1388
+ }
1389
+ parseTimeZoneHour() {
1390
+ if (isDigit(this.char)) {
1391
+ this.consume();
1392
+ if (/\d\d$/.test(this.state.buf)) return this.next(this.parseTimeZoneSep);
1393
+ } else {
1394
+ throw this.error(new TomlError("Unexpected character in datetime, expected digit"));
1395
+ }
1396
+ }
1397
+ parseTimeZoneSep() {
1398
+ if (this.char === CHAR_COLON) {
1399
+ this.consume();
1400
+ this.next(this.parseTimeZoneMin);
1401
+ } else {
1402
+ throw this.error(new TomlError("Unexpected character in datetime, expected colon"));
1403
+ }
1404
+ }
1405
+ parseTimeZoneMin() {
1406
+ if (isDigit(this.char)) {
1407
+ this.consume();
1408
+ if (/\d\d$/.test(this.state.buf)) return this.return(createDateTime(this.state.result + this.state.buf));
1409
+ } else {
1410
+ throw this.error(new TomlError("Unexpected character in datetime, expected digit"));
1411
+ }
1412
+ }
1413
+ /* BOOLEAN */
1414
+ parseBoolean() {
1415
+ if (this.char === CHAR_t) {
1416
+ this.consume();
1417
+ return this.next(this.parseTrue_r);
1418
+ } else if (this.char === CHAR_f) {
1419
+ this.consume();
1420
+ return this.next(this.parseFalse_a);
1421
+ }
1422
+ }
1423
+ parseTrue_r() {
1424
+ if (this.char === CHAR_r) {
1425
+ this.consume();
1426
+ return this.next(this.parseTrue_u);
1427
+ } else {
1428
+ throw this.error(new TomlError("Invalid boolean, expected true or false"));
1429
+ }
1430
+ }
1431
+ parseTrue_u() {
1432
+ if (this.char === CHAR_u) {
1433
+ this.consume();
1434
+ return this.next(this.parseTrue_e);
1435
+ } else {
1436
+ throw this.error(new TomlError("Invalid boolean, expected true or false"));
1437
+ }
1438
+ }
1439
+ parseTrue_e() {
1440
+ if (this.char === CHAR_e) {
1441
+ return this.return(true);
1442
+ } else {
1443
+ throw this.error(new TomlError("Invalid boolean, expected true or false"));
1444
+ }
1445
+ }
1446
+ parseFalse_a() {
1447
+ if (this.char === CHAR_a) {
1448
+ this.consume();
1449
+ return this.next(this.parseFalse_l);
1450
+ } else {
1451
+ throw this.error(new TomlError("Invalid boolean, expected true or false"));
1452
+ }
1453
+ }
1454
+ parseFalse_l() {
1455
+ if (this.char === CHAR_l) {
1456
+ this.consume();
1457
+ return this.next(this.parseFalse_s);
1458
+ } else {
1459
+ throw this.error(new TomlError("Invalid boolean, expected true or false"));
1460
+ }
1461
+ }
1462
+ parseFalse_s() {
1463
+ if (this.char === CHAR_s) {
1464
+ this.consume();
1465
+ return this.next(this.parseFalse_e);
1466
+ } else {
1467
+ throw this.error(new TomlError("Invalid boolean, expected true or false"));
1468
+ }
1469
+ }
1470
+ parseFalse_e() {
1471
+ if (this.char === CHAR_e) {
1472
+ return this.return(false);
1473
+ } else {
1474
+ throw this.error(new TomlError("Invalid boolean, expected true or false"));
1475
+ }
1476
+ }
1477
+ /* INLINE LISTS */
1478
+ parseInlineList() {
1479
+ if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
1480
+ return null;
1481
+ } else if (this.char === Parser.END) {
1482
+ throw this.error(new TomlError("Unterminated inline array"));
1483
+ } else if (this.char === CHAR_NUM) {
1484
+ return this.call(this.parseComment);
1485
+ } else if (this.char === CHAR_RSQB) {
1486
+ return this.return(this.state.resultArr || InlineList());
1487
+ } else {
1488
+ return this.callNow(this.parseValue, this.recordInlineListValue);
1489
+ }
1490
+ }
1491
+ recordInlineListValue(value) {
1492
+ if (this.state.resultArr) {
1493
+ const listType = this.state.resultArr[_contentType];
1494
+ const valueType = tomlType(value);
1495
+ if (listType !== valueType) {
1496
+ throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`));
1497
+ }
1498
+ } else {
1499
+ this.state.resultArr = InlineList(tomlType(value));
1500
+ }
1501
+ if (isFloat(value) || isInteger(value)) {
1502
+ this.state.resultArr.push(value.valueOf());
1503
+ } else {
1504
+ this.state.resultArr.push(value);
1505
+ }
1506
+ return this.goto(this.parseInlineListNext);
1507
+ }
1508
+ parseInlineListNext() {
1509
+ if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
1510
+ return null;
1511
+ } else if (this.char === CHAR_NUM) {
1512
+ return this.call(this.parseComment);
1513
+ } else if (this.char === CHAR_COMMA) {
1514
+ return this.next(this.parseInlineList);
1515
+ } else if (this.char === CHAR_RSQB) {
1516
+ return this.goto(this.parseInlineList);
1517
+ } else {
1518
+ throw this.error(new TomlError("Invalid character, expected whitespace, comma (,) or close bracket (])"));
1519
+ }
1520
+ }
1521
+ /* INLINE TABLE */
1522
+ parseInlineTable() {
1523
+ if (this.char === CHAR_SP || this.char === CTRL_I) {
1524
+ return null;
1525
+ } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
1526
+ throw this.error(new TomlError("Unterminated inline array"));
1527
+ } else if (this.char === CHAR_RCUB) {
1528
+ return this.return(this.state.resultTable || InlineTable());
1529
+ } else {
1530
+ if (!this.state.resultTable) this.state.resultTable = InlineTable();
1531
+ return this.callNow(this.parseAssign, this.recordInlineTableValue);
1532
+ }
1533
+ }
1534
+ recordInlineTableValue(kv) {
1535
+ let target = this.state.resultTable;
1536
+ let finalKey = kv.key.pop();
1537
+ for (let kw of kv.key) {
1538
+ if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
1539
+ throw this.error(new TomlError("Can't redefine existing key"));
1540
+ }
1541
+ target = target[kw] = target[kw] || Table();
1542
+ }
1543
+ if (hasKey(target, finalKey)) {
1544
+ throw this.error(new TomlError("Can't redefine existing key"));
1545
+ }
1546
+ if (isInteger(kv.value) || isFloat(kv.value)) {
1547
+ target[finalKey] = kv.value.valueOf();
1548
+ } else {
1549
+ target[finalKey] = kv.value;
1550
+ }
1551
+ return this.goto(this.parseInlineTableNext);
1552
+ }
1553
+ parseInlineTableNext() {
1554
+ if (this.char === CHAR_SP || this.char === CTRL_I) {
1555
+ return null;
1556
+ } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
1557
+ throw this.error(new TomlError("Unterminated inline array"));
1558
+ } else if (this.char === CHAR_COMMA) {
1559
+ return this.next(this.parseInlineTable);
1560
+ } else if (this.char === CHAR_RCUB) {
1561
+ return this.goto(this.parseInlineTable);
1562
+ } else {
1563
+ throw this.error(new TomlError("Invalid character, expected whitespace, comma (,) or close bracket (])"));
1564
+ }
1565
+ }
1566
+ }
1567
+ return TOMLParser;
1568
+ }
1569
+ }
1570
+ });
1571
+
1572
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-pretty-error.js
1573
+ var require_parse_pretty_error = __commonJS({
1574
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-pretty-error.js"(exports2, module2) {
1575
+ "use strict";
1576
+ module2.exports = prettyError;
1577
+ function prettyError(err, buf) {
1578
+ if (err.pos == null || err.line == null) return err;
1579
+ let msg = err.message;
1580
+ msg += ` at row ${err.line + 1}, col ${err.col + 1}, pos ${err.pos}:
1581
+ `;
1582
+ if (buf && buf.split) {
1583
+ const lines = buf.split(/\n/);
1584
+ const lineNumWidth = String(Math.min(lines.length, err.line + 3)).length;
1585
+ let linePadding = " ";
1586
+ while (linePadding.length < lineNumWidth) linePadding += " ";
1587
+ for (let ii = Math.max(0, err.line - 1); ii < Math.min(lines.length, err.line + 2); ++ii) {
1588
+ let lineNum = String(ii + 1);
1589
+ if (lineNum.length < lineNumWidth) lineNum = " " + lineNum;
1590
+ if (err.line === ii) {
1591
+ msg += lineNum + "> " + lines[ii] + "\n";
1592
+ msg += linePadding + " ";
1593
+ for (let hh = 0; hh < err.col; ++hh) {
1594
+ msg += " ";
1595
+ }
1596
+ msg += "^\n";
1597
+ } else {
1598
+ msg += lineNum + ": " + lines[ii] + "\n";
1599
+ }
1600
+ }
1601
+ }
1602
+ err.message = msg + "\n";
1603
+ return err;
1604
+ }
1605
+ }
1606
+ });
1607
+
1608
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-string.js
1609
+ var require_parse_string = __commonJS({
1610
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-string.js"(exports2, module2) {
1611
+ "use strict";
1612
+ module2.exports = parseString;
1613
+ var TOMLParser = require_toml_parser();
1614
+ var prettyError = require_parse_pretty_error();
1615
+ function parseString(str) {
1616
+ if (global.Buffer && global.Buffer.isBuffer(str)) {
1617
+ str = str.toString("utf8");
1618
+ }
1619
+ const parser = new TOMLParser();
1620
+ try {
1621
+ parser.parse(str);
1622
+ return parser.finish();
1623
+ } catch (err) {
1624
+ throw prettyError(err, str);
1625
+ }
1626
+ }
1627
+ }
1628
+ });
1629
+
1630
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-async.js
1631
+ var require_parse_async = __commonJS({
1632
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-async.js"(exports2, module2) {
1633
+ "use strict";
1634
+ module2.exports = parseAsync;
1635
+ var TOMLParser = require_toml_parser();
1636
+ var prettyError = require_parse_pretty_error();
1637
+ function parseAsync(str, opts) {
1638
+ if (!opts) opts = {};
1639
+ const index = 0;
1640
+ const blocksize = opts.blocksize || 40960;
1641
+ const parser = new TOMLParser();
1642
+ return new Promise((resolve, reject) => {
1643
+ setImmediate(parseAsyncNext, index, blocksize, resolve, reject);
1644
+ });
1645
+ function parseAsyncNext(index2, blocksize2, resolve, reject) {
1646
+ if (index2 >= str.length) {
1647
+ try {
1648
+ return resolve(parser.finish());
1649
+ } catch (err) {
1650
+ return reject(prettyError(err, str));
1651
+ }
1652
+ }
1653
+ try {
1654
+ parser.parse(str.slice(index2, index2 + blocksize2));
1655
+ setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve, reject);
1656
+ } catch (err) {
1657
+ reject(prettyError(err, str));
1658
+ }
1659
+ }
1660
+ }
1661
+ }
1662
+ });
1663
+
1664
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-stream.js
1665
+ var require_parse_stream = __commonJS({
1666
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-stream.js"(exports2, module2) {
1667
+ "use strict";
1668
+ module2.exports = parseStream;
1669
+ var stream = require("stream");
1670
+ var TOMLParser = require_toml_parser();
1671
+ function parseStream(stm) {
1672
+ if (stm) {
1673
+ return parseReadable(stm);
1674
+ } else {
1675
+ return parseTransform(stm);
1676
+ }
1677
+ }
1678
+ function parseReadable(stm) {
1679
+ const parser = new TOMLParser();
1680
+ stm.setEncoding("utf8");
1681
+ return new Promise((resolve, reject) => {
1682
+ let readable;
1683
+ let ended = false;
1684
+ let errored = false;
1685
+ function finish() {
1686
+ ended = true;
1687
+ if (readable) return;
1688
+ try {
1689
+ resolve(parser.finish());
1690
+ } catch (err) {
1691
+ reject(err);
1692
+ }
1693
+ }
1694
+ function error(err) {
1695
+ errored = true;
1696
+ reject(err);
1697
+ }
1698
+ stm.once("end", finish);
1699
+ stm.once("error", error);
1700
+ readNext();
1701
+ function readNext() {
1702
+ readable = true;
1703
+ let data;
1704
+ while ((data = stm.read()) !== null) {
1705
+ try {
1706
+ parser.parse(data);
1707
+ } catch (err) {
1708
+ return error(err);
1709
+ }
1710
+ }
1711
+ readable = false;
1712
+ if (ended) return finish();
1713
+ if (errored) return;
1714
+ stm.once("readable", readNext);
1715
+ }
1716
+ });
1717
+ }
1718
+ function parseTransform() {
1719
+ const parser = new TOMLParser();
1720
+ return new stream.Transform({
1721
+ objectMode: true,
1722
+ transform(chunk, encoding, cb) {
1723
+ try {
1724
+ parser.parse(chunk.toString(encoding));
1725
+ } catch (err) {
1726
+ this.emit("error", err);
1727
+ }
1728
+ cb();
1729
+ },
1730
+ flush(cb) {
1731
+ try {
1732
+ this.push(parser.finish());
1733
+ } catch (err) {
1734
+ this.emit("error", err);
1735
+ }
1736
+ cb();
1737
+ }
1738
+ });
1739
+ }
1740
+ }
1741
+ });
1742
+
1743
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse.js
1744
+ var require_parse = __commonJS({
1745
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse.js"(exports2, module2) {
1746
+ "use strict";
1747
+ module2.exports = require_parse_string();
1748
+ module2.exports.async = require_parse_async();
1749
+ module2.exports.stream = require_parse_stream();
1750
+ module2.exports.prettyError = require_parse_pretty_error();
1751
+ }
1752
+ });
1753
+
1754
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/stringify.js
1755
+ var require_stringify = __commonJS({
1756
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/stringify.js"(exports2, module2) {
1757
+ "use strict";
1758
+ module2.exports = stringify;
1759
+ module2.exports.value = stringifyInline;
1760
+ function stringify(obj) {
1761
+ if (obj === null) throw typeError("null");
1762
+ if (obj === void 0) throw typeError("undefined");
1763
+ if (typeof obj !== "object") throw typeError(typeof obj);
1764
+ if (typeof obj.toJSON === "function") obj = obj.toJSON();
1765
+ if (obj == null) return null;
1766
+ const type = tomlType2(obj);
1767
+ if (type !== "table") throw typeError(type);
1768
+ return stringifyObject("", "", obj);
1769
+ }
1770
+ function typeError(type) {
1771
+ return new Error("Can only stringify objects, not " + type);
1772
+ }
1773
+ function arrayOneTypeError() {
1774
+ return new Error("Array values can't have mixed types");
1775
+ }
1776
+ function getInlineKeys(obj) {
1777
+ return Object.keys(obj).filter((key) => isInline(obj[key]));
1778
+ }
1779
+ function getComplexKeys(obj) {
1780
+ return Object.keys(obj).filter((key) => !isInline(obj[key]));
1781
+ }
1782
+ function toJSON(obj) {
1783
+ let nobj = Array.isArray(obj) ? [] : Object.prototype.hasOwnProperty.call(obj, "__proto__") ? { ["__proto__"]: void 0 } : {};
1784
+ for (let prop of Object.keys(obj)) {
1785
+ if (obj[prop] && typeof obj[prop].toJSON === "function" && !("toISOString" in obj[prop])) {
1786
+ nobj[prop] = obj[prop].toJSON();
1787
+ } else {
1788
+ nobj[prop] = obj[prop];
1789
+ }
1790
+ }
1791
+ return nobj;
1792
+ }
1793
+ function stringifyObject(prefix, indent, obj) {
1794
+ obj = toJSON(obj);
1795
+ var inlineKeys;
1796
+ var complexKeys;
1797
+ inlineKeys = getInlineKeys(obj);
1798
+ complexKeys = getComplexKeys(obj);
1799
+ var result = [];
1800
+ var inlineIndent = indent || "";
1801
+ inlineKeys.forEach((key) => {
1802
+ var type = tomlType2(obj[key]);
1803
+ if (type !== "undefined" && type !== "null") {
1804
+ result.push(inlineIndent + stringifyKey(key) + " = " + stringifyAnyInline(obj[key], true));
1805
+ }
1806
+ });
1807
+ if (result.length > 0) result.push("");
1808
+ var complexIndent = prefix && inlineKeys.length > 0 ? indent + " " : "";
1809
+ complexKeys.forEach((key) => {
1810
+ result.push(stringifyComplex(prefix, complexIndent, key, obj[key]));
1811
+ });
1812
+ return result.join("\n");
1813
+ }
1814
+ function isInline(value) {
1815
+ switch (tomlType2(value)) {
1816
+ case "undefined":
1817
+ case "null":
1818
+ case "integer":
1819
+ case "nan":
1820
+ case "float":
1821
+ case "boolean":
1822
+ case "string":
1823
+ case "datetime":
1824
+ return true;
1825
+ case "array":
1826
+ return value.length === 0 || tomlType2(value[0]) !== "table";
1827
+ case "table":
1828
+ return Object.keys(value).length === 0;
1829
+ /* istanbul ignore next */
1830
+ default:
1831
+ return false;
1832
+ }
1833
+ }
1834
+ function tomlType2(value) {
1835
+ if (value === void 0) {
1836
+ return "undefined";
1837
+ } else if (value === null) {
1838
+ return "null";
1839
+ } else if (typeof value === "bigint" || Number.isInteger(value) && !Object.is(value, -0)) {
1840
+ return "integer";
1841
+ } else if (typeof value === "number") {
1842
+ return "float";
1843
+ } else if (typeof value === "boolean") {
1844
+ return "boolean";
1845
+ } else if (typeof value === "string") {
1846
+ return "string";
1847
+ } else if ("toISOString" in value) {
1848
+ return isNaN(value) ? "undefined" : "datetime";
1849
+ } else if (Array.isArray(value)) {
1850
+ return "array";
1851
+ } else {
1852
+ return "table";
1853
+ }
1854
+ }
1855
+ function stringifyKey(key) {
1856
+ var keyStr = String(key);
1857
+ if (/^[-A-Za-z0-9_]+$/.test(keyStr)) {
1858
+ return keyStr;
1859
+ } else {
1860
+ return stringifyBasicString(keyStr);
1861
+ }
1862
+ }
1863
+ function stringifyBasicString(str) {
1864
+ return '"' + escapeString(str).replace(/"/g, '\\"') + '"';
1865
+ }
1866
+ function stringifyLiteralString(str) {
1867
+ return "'" + str + "'";
1868
+ }
1869
+ function numpad(num, str) {
1870
+ while (str.length < num) str = "0" + str;
1871
+ return str;
1872
+ }
1873
+ function escapeString(str) {
1874
+ return str.replace(/\\/g, "\\\\").replace(/[\b]/g, "\\b").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\f/g, "\\f").replace(/\r/g, "\\r").replace(/([\u0000-\u001f\u007f])/, (c) => "\\u" + numpad(4, c.codePointAt(0).toString(16)));
1875
+ }
1876
+ function stringifyMultilineString(str) {
1877
+ let escaped = str.split(/\n/).map((str2) => {
1878
+ return escapeString(str2).replace(/"(?="")/g, '\\"');
1879
+ }).join("\n");
1880
+ if (escaped.slice(-1) === '"') escaped += "\\\n";
1881
+ return '"""\n' + escaped + '"""';
1882
+ }
1883
+ function stringifyAnyInline(value, multilineOk) {
1884
+ let type = tomlType2(value);
1885
+ if (type === "string") {
1886
+ if (multilineOk && /\n/.test(value)) {
1887
+ type = "string-multiline";
1888
+ } else if (!/[\b\t\n\f\r']/.test(value) && /"/.test(value)) {
1889
+ type = "string-literal";
1890
+ }
1891
+ }
1892
+ return stringifyInline(value, type);
1893
+ }
1894
+ function stringifyInline(value, type) {
1895
+ if (!type) type = tomlType2(value);
1896
+ switch (type) {
1897
+ case "string-multiline":
1898
+ return stringifyMultilineString(value);
1899
+ case "string":
1900
+ return stringifyBasicString(value);
1901
+ case "string-literal":
1902
+ return stringifyLiteralString(value);
1903
+ case "integer":
1904
+ return stringifyInteger(value);
1905
+ case "float":
1906
+ return stringifyFloat(value);
1907
+ case "boolean":
1908
+ return stringifyBoolean(value);
1909
+ case "datetime":
1910
+ return stringifyDatetime(value);
1911
+ case "array":
1912
+ return stringifyInlineArray(value.filter((_) => tomlType2(_) !== "null" && tomlType2(_) !== "undefined" && tomlType2(_) !== "nan"));
1913
+ case "table":
1914
+ return stringifyInlineTable(value);
1915
+ /* istanbul ignore next */
1916
+ default:
1917
+ throw typeError(type);
1918
+ }
1919
+ }
1920
+ function stringifyInteger(value) {
1921
+ return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, "_");
1922
+ }
1923
+ function stringifyFloat(value) {
1924
+ if (value === Infinity) {
1925
+ return "inf";
1926
+ } else if (value === -Infinity) {
1927
+ return "-inf";
1928
+ } else if (Object.is(value, NaN)) {
1929
+ return "nan";
1930
+ } else if (Object.is(value, -0)) {
1931
+ return "-0.0";
1932
+ }
1933
+ var chunks = String(value).split(".");
1934
+ var int = chunks[0];
1935
+ var dec = chunks[1] || 0;
1936
+ return stringifyInteger(int) + "." + dec;
1937
+ }
1938
+ function stringifyBoolean(value) {
1939
+ return String(value);
1940
+ }
1941
+ function stringifyDatetime(value) {
1942
+ return value.toISOString();
1943
+ }
1944
+ function isNumber(type) {
1945
+ return type === "float" || type === "integer";
1946
+ }
1947
+ function arrayType(values) {
1948
+ var contentType = tomlType2(values[0]);
1949
+ if (values.every((_) => tomlType2(_) === contentType)) return contentType;
1950
+ if (values.every((_) => isNumber(tomlType2(_)))) return "float";
1951
+ return "mixed";
1952
+ }
1953
+ function validateArray(values) {
1954
+ const type = arrayType(values);
1955
+ if (type === "mixed") {
1956
+ throw arrayOneTypeError();
1957
+ }
1958
+ return type;
1959
+ }
1960
+ function stringifyInlineArray(values) {
1961
+ values = toJSON(values);
1962
+ const type = validateArray(values);
1963
+ var result = "[";
1964
+ var stringified = values.map((_) => stringifyInline(_, type));
1965
+ if (stringified.join(", ").length > 60 || /\n/.test(stringified)) {
1966
+ result += "\n " + stringified.join(",\n ") + "\n";
1967
+ } else {
1968
+ result += " " + stringified.join(", ") + (stringified.length > 0 ? " " : "");
1969
+ }
1970
+ return result + "]";
1971
+ }
1972
+ function stringifyInlineTable(value) {
1973
+ value = toJSON(value);
1974
+ var result = [];
1975
+ Object.keys(value).forEach((key) => {
1976
+ result.push(stringifyKey(key) + " = " + stringifyAnyInline(value[key], false));
1977
+ });
1978
+ return "{ " + result.join(", ") + (result.length > 0 ? " " : "") + "}";
1979
+ }
1980
+ function stringifyComplex(prefix, indent, key, value) {
1981
+ var valueType = tomlType2(value);
1982
+ if (valueType === "array") {
1983
+ return stringifyArrayOfTables(prefix, indent, key, value);
1984
+ } else if (valueType === "table") {
1985
+ return stringifyComplexTable(prefix, indent, key, value);
1986
+ } else {
1987
+ throw typeError(valueType);
1988
+ }
1989
+ }
1990
+ function stringifyArrayOfTables(prefix, indent, key, values) {
1991
+ values = toJSON(values);
1992
+ validateArray(values);
1993
+ var firstValueType = tomlType2(values[0]);
1994
+ if (firstValueType !== "table") throw typeError(firstValueType);
1995
+ var fullKey = prefix + stringifyKey(key);
1996
+ var result = "";
1997
+ values.forEach((table) => {
1998
+ if (result.length > 0) result += "\n";
1999
+ result += indent + "[[" + fullKey + "]]\n";
2000
+ result += stringifyObject(fullKey + ".", indent, table);
2001
+ });
2002
+ return result;
2003
+ }
2004
+ function stringifyComplexTable(prefix, indent, key, value) {
2005
+ var fullKey = prefix + stringifyKey(key);
2006
+ var result = "";
2007
+ if (getInlineKeys(value).length > 0) {
2008
+ result += indent + "[" + fullKey + "]\n";
2009
+ }
2010
+ return result + stringifyObject(fullKey + ".", indent, value);
2011
+ }
2012
+ }
2013
+ });
2014
+
2015
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/toml.js
2016
+ var require_toml = __commonJS({
2017
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/toml.js"(exports2) {
2018
+ "use strict";
2019
+ exports2.parse = require_parse();
2020
+ exports2.stringify = require_stringify();
2021
+ }
2022
+ });
2023
+
2024
+ // src/index.ts
2025
+ var import_commander = require("commander");
2026
+ var import_chalk17 = __toESM(require("chalk"));
2027
+
2028
+ // src/utils/logo.ts
2029
+ var import_chalk = __toESM(require("chalk"));
2030
+ function printLogo() {
2031
+ console.log(
2032
+ import_chalk.default.bold(
2033
+ `
2034
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557
2035
+ \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2588\u2588\u2557\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551
2036
+ \u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551
2037
+ \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551
2038
+ \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2554\u255D \u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551
2039
+ \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D
2040
+ `
2041
+ )
2042
+ );
2043
+ console.log(import_chalk.default.gray(" Codex/Claude Code API \u670D\u52A1\u5546\u914D\u7F6E\u7BA1\u7406\u5DE5\u5177\n"));
2044
+ }
2045
+
2046
+ // src/commands/codex/add.ts
2047
+ var import_chalk3 = __toESM(require("chalk"));
2048
+ var import_inquirer2 = __toESM(require("inquirer"));
2049
+
2050
+ // ../core/package.json
2051
+ var package_default = {
2052
+ name: "@ccman/core",
2053
+ version: "3.0.6",
2054
+ type: "module",
2055
+ description: "Core business logic for ccman",
2056
+ main: "./dist/index.js",
2057
+ types: "./dist/index.d.ts",
2058
+ files: [
2059
+ "dist"
2060
+ ],
2061
+ scripts: {
2062
+ build: "tsc",
2063
+ test: "vitest run",
2064
+ "test:watch": "vitest",
2065
+ clean: "rm -rf dist"
2066
+ },
2067
+ keywords: [
2068
+ "codex",
2069
+ "claude",
2070
+ "claude-code",
2071
+ "ai",
2072
+ "api",
2073
+ "config",
2074
+ "manager"
2075
+ ],
2076
+ author: "2ue",
2077
+ license: "MIT",
2078
+ repository: {
2079
+ type: "git",
2080
+ url: "https://github.com/2ue/ccm.git",
2081
+ directory: "packages/core"
2082
+ },
2083
+ homepage: "https://github.com/2ue/ccm#readme",
2084
+ bugs: {
2085
+ url: "https://github.com/2ue/ccm/issues"
2086
+ },
2087
+ dependencies: {
2088
+ "@iarna/toml": "^2.2.5",
2089
+ "proper-lockfile": "^4.1.2"
2090
+ },
2091
+ devDependencies: {
2092
+ vitest: "^1.0.0"
2093
+ },
2094
+ engines: {
2095
+ node: ">=18.0.0"
2096
+ }
2097
+ };
2098
+
2099
+ // ../core/dist/tool-manager.js
2100
+ var path3 = __toESM(require("path"), 1);
2101
+
2102
+ // ../core/dist/paths.js
2103
+ var os = __toESM(require("os"), 1);
2104
+ var path = __toESM(require("path"), 1);
2105
+ var isDev = process.env.NODE_ENV === "development";
2106
+ var isTest = process.env.NODE_ENV === "test";
2107
+ var ccmanDir;
2108
+ var codexDir;
2109
+ var claudeDir;
2110
+ if (isTest) {
2111
+ const testRoot = path.join(os.tmpdir(), `ccman-test-${process.pid}`);
2112
+ ccmanDir = path.join(testRoot, ".ccman");
2113
+ codexDir = path.join(testRoot, ".codex");
2114
+ claudeDir = path.join(testRoot, ".claude");
2115
+ } else if (isDev) {
2116
+ const devRoot = path.join(os.tmpdir(), "ccman-dev");
2117
+ ccmanDir = path.join(devRoot, ".ccman");
2118
+ codexDir = path.join(devRoot, ".codex");
2119
+ claudeDir = path.join(devRoot, ".claude");
2120
+ } else {
2121
+ ccmanDir = path.join(os.homedir(), ".ccman");
2122
+ codexDir = path.join(os.homedir(), ".codex");
2123
+ claudeDir = path.join(os.homedir(), ".claude");
2124
+ }
2125
+ function getCcmanDir() {
2126
+ return ccmanDir;
2127
+ }
2128
+ function getCodexDir() {
2129
+ return codexDir;
2130
+ }
2131
+ function getClaudeDir() {
2132
+ return claudeDir;
2133
+ }
2134
+ function getCodexConfigPath() {
2135
+ return path.join(codexDir, "config.toml");
2136
+ }
2137
+ function getCodexAuthPath() {
2138
+ return path.join(codexDir, "auth.json");
2139
+ }
2140
+ function getClaudeConfigPath() {
2141
+ return path.join(claudeDir, "settings.json");
2142
+ }
2143
+
2144
+ // ../core/dist/utils/file.js
2145
+ var fs = __toESM(require("fs"), 1);
2146
+ var path2 = __toESM(require("path"), 1);
2147
+ function ensureDir(dir) {
2148
+ fs.mkdirSync(dir, { recursive: true });
2149
+ }
2150
+ function readJSON(filePath) {
2151
+ const content = fs.readFileSync(filePath, "utf-8");
2152
+ return JSON.parse(content);
2153
+ }
2154
+ function writeJSON(filePath, data) {
2155
+ const dir = path2.dirname(filePath);
2156
+ ensureDir(dir);
2157
+ const tmpPath = `${filePath}.tmp`;
2158
+ fs.writeFileSync(tmpPath, JSON.stringify(data, null, 2), { mode: 384 });
2159
+ fs.renameSync(tmpPath, filePath);
2160
+ }
2161
+ function fileExists(filePath) {
2162
+ try {
2163
+ fs.accessSync(filePath, fs.constants.F_OK);
2164
+ return true;
2165
+ } catch {
2166
+ return false;
2167
+ }
2168
+ }
2169
+
2170
+ // ../core/dist/writers/codex.js
2171
+ var fs2 = __toESM(require("fs"), 1);
2172
+ var import_toml = __toESM(require_toml(), 1);
2173
+ function writeCodexConfig(provider) {
2174
+ ensureDir(getCodexDir());
2175
+ const configPath = getCodexConfigPath();
2176
+ let config;
2177
+ if (fileExists(configPath)) {
2178
+ const content = fs2.readFileSync(configPath, "utf-8");
2179
+ config = (0, import_toml.parse)(content);
2180
+ } else {
2181
+ config = {};
2182
+ }
2183
+ config.model_provider = provider.name;
2184
+ config.model_providers = config.model_providers || {};
2185
+ config.model_providers[provider.name] = {
2186
+ name: provider.name,
2187
+ base_url: provider.baseUrl,
2188
+ wire_api: "responses",
2189
+ // 固定值
2190
+ requires_openai_auth: true
2191
+ // 固定值
2192
+ };
2193
+ if (!config.model) {
2194
+ config.model = "gpt-5";
2195
+ }
2196
+ if (!config.model_reasoning_effort) {
2197
+ config.model_reasoning_effort = "high";
2198
+ }
2199
+ if (!("disable_response_storage" in config)) {
2200
+ config.disable_response_storage = true;
2201
+ }
2202
+ fs2.writeFileSync(configPath, (0, import_toml.stringify)(config), { mode: 384 });
2203
+ const authPath = getCodexAuthPath();
2204
+ let auth;
2205
+ if (fileExists(authPath)) {
2206
+ const content = fs2.readFileSync(authPath, "utf-8");
2207
+ auth = JSON.parse(content);
2208
+ } else {
2209
+ auth = { OPENAI_API_KEY: "" };
2210
+ }
2211
+ auth.OPENAI_API_KEY = provider.apiKey;
2212
+ fs2.writeFileSync(authPath, JSON.stringify(auth, null, 2), { mode: 384 });
2213
+ }
2214
+
2215
+ // ../core/dist/writers/claudecode.js
2216
+ var fs3 = __toESM(require("fs"), 1);
2217
+ function writeClaudeCodeConfig(provider) {
2218
+ ensureDir(getClaudeDir());
2219
+ const configPath = getClaudeConfigPath();
2220
+ let settings;
2221
+ if (fileExists(configPath)) {
2222
+ const content = fs3.readFileSync(configPath, "utf-8");
2223
+ settings = JSON.parse(content);
2224
+ } else {
2225
+ settings = {};
2226
+ }
2227
+ if (!settings.env) {
2228
+ settings.env = {};
2229
+ }
2230
+ settings.env.ANTHROPIC_AUTH_TOKEN = provider.apiKey;
2231
+ settings.env.ANTHROPIC_BASE_URL = provider.baseUrl;
2232
+ if (!("CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC" in settings.env)) {
2233
+ settings.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = 1;
2234
+ }
2235
+ if (!("CLAUDE_CODE_MAX_OUTPUT_TOKENS" in settings.env)) {
2236
+ settings.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS = 32e3;
2237
+ }
2238
+ if (!settings.permissions) {
2239
+ settings.permissions = { allow: [], deny: [] };
2240
+ }
2241
+ if (!settings.permissions.allow) {
2242
+ settings.permissions.allow = [];
2243
+ }
2244
+ if (!settings.permissions.deny) {
2245
+ settings.permissions.deny = [];
2246
+ }
2247
+ fs3.writeFileSync(configPath, JSON.stringify(settings, null, 2), { mode: 384 });
2248
+ }
2249
+
2250
+ // ../core/dist/presets/codex.js
2251
+ var CODEX_PRESETS = [
2252
+ {
2253
+ name: "Anthropic Official",
2254
+ baseUrl: "https://api.anthropic.com",
2255
+ description: "Anthropic \u5B98\u65B9 API"
2256
+ },
2257
+ {
2258
+ name: "AnyRouter",
2259
+ baseUrl: "https://anyrouter.top",
2260
+ description: "AnyRouter API \u670D\u52A1"
2261
+ },
2262
+ {
2263
+ name: "PackyCode",
2264
+ baseUrl: "https://api.packycode.com",
2265
+ description: "PackyCode API \u670D\u52A1"
2266
+ },
2267
+ {
2268
+ name: "CoordCode",
2269
+ baseUrl: "https://api.coordcode.com/api",
2270
+ description: "CoordCode API \u670D\u52A1"
2271
+ },
2272
+ {
2273
+ name: "88Code",
2274
+ baseUrl: "https://www.88code.org/api",
2275
+ description: "88Code API \u670D\u52A1"
2276
+ },
2277
+ {
2278
+ name: "BigModel",
2279
+ baseUrl: "https://open.bigmodel.cn/api/anthropic",
2280
+ description: "\u667A\u8C31 BigModel API"
2281
+ },
2282
+ {
2283
+ name: "ModelScope",
2284
+ baseUrl: "https://api-inference.modelscope.cn/v1/chat/completions",
2285
+ description: "\u963F\u91CC\u4E91 ModelScope API"
2286
+ }
2287
+ ];
2288
+
2289
+ // ../core/dist/presets/claudecode.js
2290
+ var CLAUDECODE_PRESETS = [
2291
+ {
2292
+ name: "Anthropic Official",
2293
+ baseUrl: "https://api.anthropic.com",
2294
+ description: "Anthropic \u5B98\u65B9 API"
2295
+ },
2296
+ {
2297
+ name: "AnyRouter",
2298
+ baseUrl: "https://anyrouter.top",
2299
+ description: "AnyRouter API \u670D\u52A1"
2300
+ },
2301
+ {
2302
+ name: "PackyCode",
2303
+ baseUrl: "https://api.packycode.com",
2304
+ description: "PackyCode API \u670D\u52A1"
2305
+ },
2306
+ {
2307
+ name: "CoordCode",
2308
+ baseUrl: "https://api.coordcode.com/api",
2309
+ description: "CoordCode API \u670D\u52A1"
2310
+ },
2311
+ {
2312
+ name: "88Code",
2313
+ baseUrl: "https://www.88code.org/api",
2314
+ description: "88Code API \u670D\u52A1"
2315
+ },
2316
+ {
2317
+ name: "BigModel",
2318
+ baseUrl: "https://open.bigmodel.cn/api/anthropic",
2319
+ description: "\u667A\u8C31 BigModel API"
2320
+ },
2321
+ {
2322
+ name: "ModelScope",
2323
+ baseUrl: "https://api-inference.modelscope.cn/v1/chat/completions",
2324
+ description: "\u963F\u91CC\u4E91 ModelScope API"
2325
+ }
2326
+ ];
2327
+
2328
+ // ../core/dist/tool-manager.js
2329
+ var ProviderNotFoundError = class extends Error {
2330
+ constructor(id) {
2331
+ super(`Provider not found: ${id}`);
2332
+ this.name = "ProviderNotFoundError";
2333
+ }
2334
+ };
2335
+ var ProviderNameConflictError = class extends Error {
2336
+ constructor(name) {
2337
+ super(`Provider name already exists: ${name}`);
2338
+ this.name = "ProviderNameConflictError";
2339
+ }
2340
+ };
2341
+ var PresetNameConflictError = class extends Error {
2342
+ constructor(name) {
2343
+ super(`Preset name already exists: ${name}`);
2344
+ this.name = "PresetNameConflictError";
2345
+ }
2346
+ };
2347
+ function generateId(tool) {
2348
+ const timestamp = Date.now();
2349
+ const random = Math.random().toString(36).substring(2, 8);
2350
+ return `${tool}-${timestamp}-${random}`;
2351
+ }
2352
+ function createCodexManager() {
2353
+ const configPath = path3.join(getCcmanDir(), "codex.json");
2354
+ function loadConfig() {
2355
+ if (!fileExists(configPath)) {
2356
+ ensureDir(getCcmanDir());
2357
+ const emptyConfig = {
2358
+ providers: []
2359
+ };
2360
+ writeJSON(configPath, emptyConfig);
2361
+ return emptyConfig;
2362
+ }
2363
+ return readJSON(configPath);
2364
+ }
2365
+ function saveConfig(config) {
2366
+ writeJSON(configPath, config);
2367
+ }
2368
+ return {
2369
+ add(input) {
2370
+ const config = loadConfig();
2371
+ const nameExists = config.providers.some((p) => p.name === input.name);
2372
+ if (nameExists) {
2373
+ throw new ProviderNameConflictError(input.name);
2374
+ }
2375
+ const provider = {
2376
+ id: generateId("codex"),
2377
+ name: input.name,
2378
+ baseUrl: input.baseUrl,
2379
+ apiKey: input.apiKey,
2380
+ createdAt: Date.now()
2381
+ };
2382
+ config.providers.push(provider);
2383
+ saveConfig(config);
2384
+ return provider;
2385
+ },
2386
+ list() {
2387
+ const config = loadConfig();
2388
+ return config.providers;
2389
+ },
2390
+ get(id) {
2391
+ const config = loadConfig();
2392
+ const provider = config.providers.find((p) => p.id === id);
2393
+ if (!provider) {
2394
+ throw new ProviderNotFoundError(id);
2395
+ }
2396
+ return provider;
2397
+ },
2398
+ findByName(name) {
2399
+ const config = loadConfig();
2400
+ return config.providers.find((p) => p.name === name);
2401
+ },
2402
+ switch(id) {
2403
+ const config = loadConfig();
2404
+ const provider = config.providers.find((p) => p.id === id);
2405
+ if (!provider) {
2406
+ throw new ProviderNotFoundError(id);
2407
+ }
2408
+ config.current = id;
2409
+ provider.lastUsedAt = Date.now();
2410
+ saveConfig(config);
2411
+ writeCodexConfig(provider);
2412
+ },
2413
+ getCurrent() {
2414
+ const config = loadConfig();
2415
+ if (!config.current) {
2416
+ return null;
2417
+ }
2418
+ const provider = config.providers.find((p) => p.id === config.current);
2419
+ return provider || null;
2420
+ },
2421
+ edit(id, updates) {
2422
+ const config = loadConfig();
2423
+ const provider = config.providers.find((p) => p.id === id);
2424
+ if (!provider) {
2425
+ throw new ProviderNotFoundError(id);
2426
+ }
2427
+ if (updates.name !== void 0 && updates.name !== provider.name) {
2428
+ const nameConflict = config.providers.some((p) => p.id !== id && p.name === updates.name);
2429
+ if (nameConflict) {
2430
+ throw new ProviderNameConflictError(updates.name);
2431
+ }
2432
+ }
2433
+ if (updates.name !== void 0)
2434
+ provider.name = updates.name;
2435
+ if (updates.baseUrl !== void 0)
2436
+ provider.baseUrl = updates.baseUrl;
2437
+ if (updates.apiKey !== void 0)
2438
+ provider.apiKey = updates.apiKey;
2439
+ saveConfig(config);
2440
+ if (config.current === id) {
2441
+ writeCodexConfig(provider);
2442
+ }
2443
+ return provider;
2444
+ },
2445
+ remove(id) {
2446
+ const config = loadConfig();
2447
+ const index = config.providers.findIndex((p) => p.id === id);
2448
+ if (index === -1) {
2449
+ throw new ProviderNotFoundError(id);
2450
+ }
2451
+ if (config.current === id) {
2452
+ config.current = void 0;
2453
+ }
2454
+ config.providers.splice(index, 1);
2455
+ saveConfig(config);
2456
+ },
2457
+ clone(sourceId, newName) {
2458
+ const source = this.get(sourceId);
2459
+ const config = loadConfig();
2460
+ const nameExists = config.providers.some((p) => p.name === newName);
2461
+ if (nameExists) {
2462
+ throw new ProviderNameConflictError(newName);
2463
+ }
2464
+ const newProvider = {
2465
+ ...source,
2466
+ id: generateId("codex"),
2467
+ name: newName,
2468
+ createdAt: Date.now(),
2469
+ lastUsedAt: void 0
2470
+ };
2471
+ config.providers.push(newProvider);
2472
+ saveConfig(config);
2473
+ return newProvider;
2474
+ },
2475
+ addPreset(input) {
2476
+ const config = loadConfig();
2477
+ if (!config.presets) {
2478
+ config.presets = [];
2479
+ }
2480
+ const allPresets = [...CODEX_PRESETS, ...config.presets];
2481
+ const nameExists = allPresets.some((p) => p.name === input.name);
2482
+ if (nameExists) {
2483
+ throw new PresetNameConflictError(input.name);
2484
+ }
2485
+ const preset = {
2486
+ name: input.name,
2487
+ baseUrl: input.baseUrl,
2488
+ description: input.description
2489
+ };
2490
+ config.presets.push(preset);
2491
+ saveConfig(config);
2492
+ return preset;
2493
+ },
2494
+ listPresets() {
2495
+ const config = loadConfig();
2496
+ const userPresets = config.presets || [];
2497
+ return [...CODEX_PRESETS, ...userPresets];
2498
+ },
2499
+ editPreset(name, updates) {
2500
+ const config = loadConfig();
2501
+ if (!config.presets) {
2502
+ config.presets = [];
2503
+ }
2504
+ const preset = config.presets.find((p) => p.name === name);
2505
+ if (!preset) {
2506
+ throw new Error(`Preset not found: ${name}`);
2507
+ }
2508
+ if (updates.name !== void 0 && updates.name !== preset.name) {
2509
+ const allPresets = [...CODEX_PRESETS, ...config.presets];
2510
+ const nameConflict = allPresets.some((p) => p.name !== name && p.name === updates.name);
2511
+ if (nameConflict) {
2512
+ throw new PresetNameConflictError(updates.name);
2513
+ }
2514
+ }
2515
+ if (updates.name !== void 0)
2516
+ preset.name = updates.name;
2517
+ if (updates.baseUrl !== void 0)
2518
+ preset.baseUrl = updates.baseUrl;
2519
+ if (updates.description !== void 0)
2520
+ preset.description = updates.description;
2521
+ saveConfig(config);
2522
+ return preset;
2523
+ },
2524
+ removePreset(name) {
2525
+ const config = loadConfig();
2526
+ if (!config.presets) {
2527
+ return;
2528
+ }
2529
+ const index = config.presets.findIndex((p) => p.name === name);
2530
+ if (index === -1) {
2531
+ throw new Error(`Preset not found: ${name}`);
2532
+ }
2533
+ config.presets.splice(index, 1);
2534
+ saveConfig(config);
2535
+ }
2536
+ };
2537
+ }
2538
+ function createClaudeCodeManager() {
2539
+ const configPath = path3.join(getCcmanDir(), "claudecode.json");
2540
+ function loadConfig() {
2541
+ if (!fileExists(configPath)) {
2542
+ ensureDir(getCcmanDir());
2543
+ const emptyConfig = {
2544
+ providers: []
2545
+ };
2546
+ writeJSON(configPath, emptyConfig);
2547
+ return emptyConfig;
2548
+ }
2549
+ return readJSON(configPath);
2550
+ }
2551
+ function saveConfig(config) {
2552
+ writeJSON(configPath, config);
2553
+ }
2554
+ return {
2555
+ add(input) {
2556
+ const config = loadConfig();
2557
+ const nameExists = config.providers.some((p) => p.name === input.name);
2558
+ if (nameExists) {
2559
+ throw new ProviderNameConflictError(input.name);
2560
+ }
2561
+ const provider = {
2562
+ id: generateId("claudecode"),
2563
+ name: input.name,
2564
+ baseUrl: input.baseUrl,
2565
+ apiKey: input.apiKey,
2566
+ createdAt: Date.now()
2567
+ };
2568
+ config.providers.push(provider);
2569
+ saveConfig(config);
2570
+ return provider;
2571
+ },
2572
+ list() {
2573
+ const config = loadConfig();
2574
+ return config.providers;
2575
+ },
2576
+ get(id) {
2577
+ const config = loadConfig();
2578
+ const provider = config.providers.find((p) => p.id === id);
2579
+ if (!provider) {
2580
+ throw new ProviderNotFoundError(id);
2581
+ }
2582
+ return provider;
2583
+ },
2584
+ findByName(name) {
2585
+ const config = loadConfig();
2586
+ return config.providers.find((p) => p.name === name);
2587
+ },
2588
+ switch(id) {
2589
+ const config = loadConfig();
2590
+ const provider = config.providers.find((p) => p.id === id);
2591
+ if (!provider) {
2592
+ throw new ProviderNotFoundError(id);
2593
+ }
2594
+ config.current = id;
2595
+ provider.lastUsedAt = Date.now();
2596
+ saveConfig(config);
2597
+ writeClaudeCodeConfig(provider);
2598
+ },
2599
+ getCurrent() {
2600
+ const config = loadConfig();
2601
+ if (!config.current) {
2602
+ return null;
2603
+ }
2604
+ const provider = config.providers.find((p) => p.id === config.current);
2605
+ return provider || null;
2606
+ },
2607
+ edit(id, updates) {
2608
+ const config = loadConfig();
2609
+ const provider = config.providers.find((p) => p.id === id);
2610
+ if (!provider) {
2611
+ throw new ProviderNotFoundError(id);
2612
+ }
2613
+ if (updates.name !== void 0 && updates.name !== provider.name) {
2614
+ const nameConflict = config.providers.some((p) => p.id !== id && p.name === updates.name);
2615
+ if (nameConflict) {
2616
+ throw new ProviderNameConflictError(updates.name);
2617
+ }
2618
+ }
2619
+ if (updates.name !== void 0)
2620
+ provider.name = updates.name;
2621
+ if (updates.baseUrl !== void 0)
2622
+ provider.baseUrl = updates.baseUrl;
2623
+ if (updates.apiKey !== void 0)
2624
+ provider.apiKey = updates.apiKey;
2625
+ saveConfig(config);
2626
+ if (config.current === id) {
2627
+ writeClaudeCodeConfig(provider);
2628
+ }
2629
+ return provider;
2630
+ },
2631
+ remove(id) {
2632
+ const config = loadConfig();
2633
+ const index = config.providers.findIndex((p) => p.id === id);
2634
+ if (index === -1) {
2635
+ throw new ProviderNotFoundError(id);
2636
+ }
2637
+ if (config.current === id) {
2638
+ config.current = void 0;
2639
+ }
2640
+ config.providers.splice(index, 1);
2641
+ saveConfig(config);
2642
+ },
2643
+ clone(sourceId, newName) {
2644
+ const source = this.get(sourceId);
2645
+ const config = loadConfig();
2646
+ const nameExists = config.providers.some((p) => p.name === newName);
2647
+ if (nameExists) {
2648
+ throw new ProviderNameConflictError(newName);
2649
+ }
2650
+ const newProvider = {
2651
+ ...source,
2652
+ id: generateId("claudecode"),
2653
+ name: newName,
2654
+ createdAt: Date.now(),
2655
+ lastUsedAt: void 0
2656
+ };
2657
+ config.providers.push(newProvider);
2658
+ saveConfig(config);
2659
+ return newProvider;
2660
+ },
2661
+ addPreset(input) {
2662
+ const config = loadConfig();
2663
+ if (!config.presets) {
2664
+ config.presets = [];
2665
+ }
2666
+ const allPresets = [...CLAUDECODE_PRESETS, ...config.presets];
2667
+ const nameExists = allPresets.some((p) => p.name === input.name);
2668
+ if (nameExists) {
2669
+ throw new PresetNameConflictError(input.name);
2670
+ }
2671
+ const preset = {
2672
+ name: input.name,
2673
+ baseUrl: input.baseUrl,
2674
+ description: input.description
2675
+ };
2676
+ config.presets.push(preset);
2677
+ saveConfig(config);
2678
+ return preset;
2679
+ },
2680
+ listPresets() {
2681
+ const config = loadConfig();
2682
+ const userPresets = config.presets || [];
2683
+ return [...CLAUDECODE_PRESETS, ...userPresets];
2684
+ },
2685
+ editPreset(name, updates) {
2686
+ const config = loadConfig();
2687
+ if (!config.presets) {
2688
+ config.presets = [];
2689
+ }
2690
+ const preset = config.presets.find((p) => p.name === name);
2691
+ if (!preset) {
2692
+ throw new Error(`Preset not found: ${name}`);
2693
+ }
2694
+ if (updates.name !== void 0 && updates.name !== preset.name) {
2695
+ const allPresets = [...CLAUDECODE_PRESETS, ...config.presets];
2696
+ const nameConflict = allPresets.some((p) => p.name !== name && p.name === updates.name);
2697
+ if (nameConflict) {
2698
+ throw new PresetNameConflictError(updates.name);
2699
+ }
2700
+ }
2701
+ if (updates.name !== void 0)
2702
+ preset.name = updates.name;
2703
+ if (updates.baseUrl !== void 0)
2704
+ preset.baseUrl = updates.baseUrl;
2705
+ if (updates.description !== void 0)
2706
+ preset.description = updates.description;
2707
+ saveConfig(config);
2708
+ return preset;
2709
+ },
2710
+ removePreset(name) {
2711
+ const config = loadConfig();
2712
+ if (!config.presets) {
2713
+ return;
2714
+ }
2715
+ const index = config.presets.findIndex((p) => p.name === name);
2716
+ if (index === -1) {
2717
+ throw new Error(`Preset not found: ${name}`);
2718
+ }
2719
+ config.presets.splice(index, 1);
2720
+ saveConfig(config);
2721
+ }
2722
+ };
2723
+ }
2724
+
2725
+ // ../core/dist/index.js
2726
+ var VERSION = package_default.version;
2727
+
2728
+ // src/interactive.ts
2729
+ var import_inquirer = __toESM(require("inquirer"));
2730
+ var import_chalk2 = __toESM(require("chalk"));
2731
+ async function promptProviderForm(defaults) {
2732
+ const answers = await import_inquirer.default.prompt([
2733
+ {
2734
+ type: "input",
2735
+ name: "name",
2736
+ message: "\u670D\u52A1\u5546\u540D\u79F0:",
2737
+ default: defaults?.name || void 0,
2738
+ validate: (value) => {
2739
+ if (!value) return "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A";
2740
+ return true;
2741
+ }
2742
+ },
2743
+ {
2744
+ type: "input",
2745
+ name: "baseUrl",
2746
+ message: "API \u5730\u5740:",
2747
+ default: defaults?.baseUrl || void 0,
2748
+ validate: (value) => {
2749
+ if (!value) return "API \u5730\u5740\u4E0D\u80FD\u4E3A\u7A7A";
2750
+ if (!value.startsWith("http://") && !value.startsWith("https://")) {
2751
+ return "API \u5730\u5740\u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934";
2752
+ }
2753
+ return true;
2754
+ }
2755
+ },
2756
+ {
2757
+ type: "password",
2758
+ name: "apiKey",
2759
+ message: "API \u5BC6\u94A5:",
2760
+ default: defaults?.apiKey || void 0,
2761
+ mask: "*",
2762
+ validate: (value) => {
2763
+ if (!value) return "API \u5BC6\u94A5\u4E0D\u80FD\u4E3A\u7A7A";
2764
+ return true;
2765
+ }
2766
+ }
2767
+ ]);
2768
+ return {
2769
+ name: answers.name,
2770
+ baseUrl: answers.baseUrl,
2771
+ apiKey: answers.apiKey
2772
+ };
2773
+ }
2774
+ async function startMainMenu() {
2775
+ while (true) {
2776
+ console.log();
2777
+ const { choice } = await import_inquirer.default.prompt([
2778
+ {
2779
+ type: "list",
2780
+ name: "choice",
2781
+ message: "\u8BF7\u9009\u62E9\u64CD\u4F5C:",
2782
+ choices: [
2783
+ { name: "\u{1F537} Claude Code \u7BA1\u7406", value: "claudecode" },
2784
+ { name: "\u{1F536} Codex \u7BA1\u7406", value: "codex" },
2785
+ { name: "\u{1F4E6} \u9884\u7F6E\u670D\u52A1\u5546\u7BA1\u7406", value: "presets" },
2786
+ { name: "\u274C \u9000\u51FA", value: "exit" }
2787
+ ]
2788
+ }
2789
+ ]);
2790
+ if (choice === "exit") {
2791
+ console.log(import_chalk2.default.gray("\n\u{1F44B} \u518D\u89C1!\n"));
2792
+ break;
2793
+ }
2794
+ if (choice === "claudecode") {
2795
+ await startClaudeCodeMenu();
2796
+ } else if (choice === "codex") {
2797
+ await startCodexMenu();
2798
+ } else if (choice === "presets") {
2799
+ await showPresetsMenu();
2800
+ }
2801
+ }
2802
+ }
2803
+ async function startClaudeCodeMenu() {
2804
+ await showToolMenu("claudecode");
2805
+ }
2806
+ async function startCodexMenu() {
2807
+ await showToolMenu("codex");
2808
+ }
2809
+ async function showToolMenu(tool) {
2810
+ const toolName = tool === "claudecode" ? "Claude Code" : "Codex";
2811
+ const toolEmoji = tool === "claudecode" ? "\u{1F537}" : "\u{1F536}";
2812
+ while (true) {
2813
+ console.log();
2814
+ const { action } = await import_inquirer.default.prompt([
2815
+ {
2816
+ type: "list",
2817
+ name: "action",
2818
+ message: `${toolEmoji} ${toolName} \u64CD\u4F5C:`,
2819
+ choices: [
2820
+ { name: "\u2795 \u6DFB\u52A0\u670D\u52A1\u5546", value: "add" },
2821
+ { name: "\u{1F504} \u5207\u6362\u670D\u52A1\u5546", value: "switch" },
2822
+ { name: "\u{1F4CB} \u5217\u51FA\u6240\u6709\u670D\u52A1\u5546", value: "list" },
2823
+ { name: "\u{1F441}\uFE0F \u67E5\u770B\u5F53\u524D\u670D\u52A1\u5546", value: "current" },
2824
+ { name: "\u270F\uFE0F \u7F16\u8F91\u670D\u52A1\u5546", value: "edit" },
2825
+ { name: "\u{1F4CB} \u514B\u9686\u670D\u52A1\u5546", value: "clone" },
2826
+ { name: "\u{1F5D1}\uFE0F \u5220\u9664\u670D\u52A1\u5546", value: "remove" },
2827
+ { name: "\u2B05\uFE0F \u8FD4\u56DE\u4E0A\u7EA7", value: "back" }
2828
+ ]
2829
+ }
2830
+ ]);
2831
+ if (action === "back") {
2832
+ break;
2833
+ }
2834
+ try {
2835
+ switch (action) {
2836
+ case "add":
2837
+ await handleAdd(tool);
2838
+ break;
2839
+ case "switch":
2840
+ await handleSwitch(tool);
2841
+ break;
2842
+ case "list":
2843
+ await handleList(tool);
2844
+ break;
2845
+ case "current":
2846
+ await handleCurrent(tool);
2847
+ break;
2848
+ case "edit":
2849
+ await handleEdit(tool);
2850
+ break;
2851
+ case "clone":
2852
+ await handleClone(tool);
2853
+ break;
2854
+ case "remove":
2855
+ await handleRemove(tool);
2856
+ break;
2857
+ }
2858
+ } catch (error) {
2859
+ console.error(import_chalk2.default.red(`
2860
+ \u274C ${error.message}
2861
+ `));
2862
+ }
2863
+ await import_inquirer.default.prompt([
2864
+ {
2865
+ type: "input",
2866
+ name: "continue",
2867
+ message: "\u6309\u56DE\u8F66\u7EE7\u7EED..."
2868
+ }
2869
+ ]);
2870
+ }
2871
+ }
2872
+ async function showPresetsMenu() {
2873
+ console.log(import_chalk2.default.yellow("\n\u26A0\uFE0F \u9884\u7F6E\u670D\u52A1\u5546\u7BA1\u7406\u529F\u80FD\u5373\u5C06\u63A8\u51FA\n"));
2874
+ }
2875
+ async function handleAdd(tool) {
2876
+ const manager = tool === "codex" ? createCodexManager() : createClaudeCodeManager();
2877
+ const toolName = tool === "claudecode" ? "Claude Code" : "Codex";
2878
+ const presets = manager.listPresets();
2879
+ console.log(import_chalk2.default.bold(`
2880
+ \u{1F4DD} \u6DFB\u52A0 ${toolName} \u670D\u52A1\u5546
2881
+ `));
2882
+ const { usePreset } = await import_inquirer.default.prompt([
2883
+ {
2884
+ type: "list",
2885
+ name: "usePreset",
2886
+ message: "\u9009\u62E9\u914D\u7F6E\u6765\u6E90:",
2887
+ choices: [
2888
+ { name: "\u{1F4E6} \u4F7F\u7528\u9884\u7F6E\u670D\u52A1\u5546", value: true },
2889
+ { name: "\u270F\uFE0F \u81EA\u5B9A\u4E49\u914D\u7F6E", value: false }
2890
+ ]
2891
+ }
2892
+ ]);
2893
+ let name;
2894
+ let baseUrl;
2895
+ let apiKey;
2896
+ if (usePreset) {
2897
+ const { presetName } = await import_inquirer.default.prompt([
2898
+ {
2899
+ type: "list",
2900
+ name: "presetName",
2901
+ message: "\u9009\u62E9\u9884\u7F6E\u670D\u52A1\u5546:",
2902
+ choices: presets.map((p) => ({
2903
+ name: `${p.name} - ${p.description}`,
2904
+ value: p.name
2905
+ }))
2906
+ }
2907
+ ]);
2908
+ const preset = presets.find((p) => p.name === presetName);
2909
+ const { inputApiKey } = await import_inquirer.default.prompt([
2910
+ {
2911
+ type: "password",
2912
+ name: "inputApiKey",
2913
+ message: "\u8F93\u5165 API \u5BC6\u94A5:",
2914
+ mask: "*",
2915
+ validate: (value) => value ? true : "API \u5BC6\u94A5\u4E0D\u80FD\u4E3A\u7A7A"
2916
+ }
2917
+ ]);
2918
+ name = preset.name;
2919
+ baseUrl = preset.baseUrl;
2920
+ apiKey = inputApiKey;
2921
+ } else {
2922
+ const answers = await import_inquirer.default.prompt([
2923
+ {
2924
+ type: "input",
2925
+ name: "name",
2926
+ message: "\u670D\u52A1\u5546\u540D\u79F0:",
2927
+ validate: (value) => value ? true : "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A"
2928
+ },
2929
+ {
2930
+ type: "input",
2931
+ name: "baseUrl",
2932
+ message: "API \u5730\u5740:",
2933
+ validate: (value) => {
2934
+ if (!value) return "API \u5730\u5740\u4E0D\u80FD\u4E3A\u7A7A";
2935
+ if (!value.startsWith("http://") && !value.startsWith("https://")) {
2936
+ return "API \u5730\u5740\u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934";
2937
+ }
2938
+ return true;
2939
+ }
2940
+ },
2941
+ {
2942
+ type: "password",
2943
+ name: "apiKey",
2944
+ message: "API \u5BC6\u94A5:",
2945
+ mask: "*",
2946
+ validate: (value) => value ? true : "API \u5BC6\u94A5\u4E0D\u80FD\u4E3A\u7A7A"
2947
+ }
2948
+ ]);
2949
+ name = answers.name;
2950
+ baseUrl = answers.baseUrl;
2951
+ apiKey = answers.apiKey;
2952
+ }
2953
+ const provider = manager.add({ name, baseUrl, apiKey });
2954
+ console.log();
2955
+ console.log(import_chalk2.default.green("\u2705 \u6DFB\u52A0\u6210\u529F"));
2956
+ console.log();
2957
+ console.log(` ${import_chalk2.default.bold(provider.name)} ${import_chalk2.default.blue(`[${toolName}]`)}`);
2958
+ console.log(` ${import_chalk2.default.gray(`ID: ${provider.id}`)}`);
2959
+ console.log(` ${import_chalk2.default.gray(`URL: ${provider.baseUrl}`)}`);
2960
+ console.log();
2961
+ const { switchNow } = await import_inquirer.default.prompt([
2962
+ {
2963
+ type: "confirm",
2964
+ name: "switchNow",
2965
+ message: "\u662F\u5426\u7ACB\u5373\u5207\u6362\u5230\u6B64\u670D\u52A1\u5546?",
2966
+ default: true
2967
+ }
2968
+ ]);
2969
+ if (switchNow) {
2970
+ manager.switch(provider.id);
2971
+ console.log(import_chalk2.default.green("\u2705 \u5DF2\u5207\u6362\u5230\u65B0\u670D\u52A1\u5546\n"));
2972
+ } else {
2973
+ console.log(import_chalk2.default.blue("\u{1F4A1} \u7A0D\u540E\u5207\u6362:") + import_chalk2.default.white(` ccman ${tool === "codex" ? "cx" : "cc"} use "${provider.name}"
2974
+ `));
2975
+ }
2976
+ }
2977
+ async function handleSwitch(tool) {
2978
+ const manager = tool === "codex" ? createCodexManager() : createClaudeCodeManager();
2979
+ const providers = manager.list();
2980
+ const current = manager.getCurrent();
2981
+ if (providers.length === 0) {
2982
+ console.log(import_chalk2.default.yellow("\n\u26A0\uFE0F \u6682\u65E0\u670D\u52A1\u5546\n"));
2983
+ return;
2984
+ }
2985
+ const { providerId } = await import_inquirer.default.prompt([
2986
+ {
2987
+ type: "list",
2988
+ name: "providerId",
2989
+ message: "\u9009\u62E9\u8981\u5207\u6362\u7684\u670D\u52A1\u5546:",
2990
+ choices: providers.map((p) => ({
2991
+ name: `${p.name}${current?.id === p.id ? import_chalk2.default.green(" (\u5F53\u524D)") : ""}`,
2992
+ value: p.id
2993
+ }))
2994
+ }
2995
+ ]);
2996
+ manager.switch(providerId);
2997
+ const provider = providers.find((p) => p.id === providerId);
2998
+ console.log(import_chalk2.default.green(`
2999
+ \u2705 \u5DF2\u5207\u6362\u5230: ${provider.name}
3000
+ `));
3001
+ }
3002
+ async function handleList(tool) {
3003
+ const manager = tool === "codex" ? createCodexManager() : createClaudeCodeManager();
3004
+ const providers = manager.list();
3005
+ const current = manager.getCurrent();
3006
+ const toolName = tool === "claudecode" ? "Claude Code" : "Codex";
3007
+ if (providers.length === 0) {
3008
+ console.log(import_chalk2.default.yellow(`
3009
+ \u26A0\uFE0F \u6682\u65E0 ${toolName} \u670D\u52A1\u5546
3010
+ `));
3011
+ return;
3012
+ }
3013
+ console.log(import_chalk2.default.bold(`
3014
+ \u{1F4CB} ${toolName} \u670D\u52A1\u5546\u5217\u8868 (\u5171 ${providers.length} \u4E2A)
3015
+ `));
3016
+ providers.forEach((p) => {
3017
+ const isCurrent = current?.id === p.id;
3018
+ const marker = isCurrent ? import_chalk2.default.green("\u25CF") : import_chalk2.default.gray("\u25CB");
3019
+ const nameStyle = isCurrent ? import_chalk2.default.green.bold : import_chalk2.default.white;
3020
+ console.log(`${marker} ${nameStyle(p.name)}`);
3021
+ console.log(` ${import_chalk2.default.gray(`ID: ${p.id}`)}`);
3022
+ console.log(` ${import_chalk2.default.gray(`URL: ${p.baseUrl}`)}`);
3023
+ if (p.lastUsedAt) {
3024
+ const date = new Date(p.lastUsedAt).toLocaleString("zh-CN");
3025
+ console.log(` ${import_chalk2.default.gray(`\u6700\u540E\u4F7F\u7528: ${date}`)}`);
3026
+ }
3027
+ console.log();
3028
+ });
3029
+ if (current) {
3030
+ console.log(import_chalk2.default.green(`\u2705 \u5F53\u524D\u4F7F\u7528: ${current.name}
3031
+ `));
3032
+ } else {
3033
+ console.log(import_chalk2.default.yellow("\u26A0\uFE0F \u672A\u9009\u62E9\u4EFB\u4F55\u670D\u52A1\u5546\n"));
3034
+ }
3035
+ }
3036
+ async function handleCurrent(tool) {
3037
+ const manager = tool === "codex" ? createCodexManager() : createClaudeCodeManager();
3038
+ const current = manager.getCurrent();
3039
+ const toolName = tool === "claudecode" ? "Claude Code" : "Codex";
3040
+ if (!current) {
3041
+ console.log(import_chalk2.default.yellow(`
3042
+ \u26A0\uFE0F \u672A\u9009\u62E9\u4EFB\u4F55 ${toolName} \u670D\u52A1\u5546
3043
+ `));
3044
+ return;
3045
+ }
3046
+ console.log(import_chalk2.default.bold(`
3047
+ \u{1F441}\uFE0F \u5F53\u524D ${toolName} \u670D\u52A1\u5546
3048
+ `));
3049
+ console.log(` ${import_chalk2.default.green.bold(current.name)}`);
3050
+ console.log(` ${import_chalk2.default.gray(`ID: ${current.id}`)}`);
3051
+ console.log(` ${import_chalk2.default.gray(`URL: ${current.baseUrl}`)}`);
3052
+ if (current.lastUsedAt) {
3053
+ const date = new Date(current.lastUsedAt).toLocaleString("zh-CN");
3054
+ console.log(` ${import_chalk2.default.gray(`\u6700\u540E\u4F7F\u7528: ${date}`)}`);
3055
+ }
3056
+ console.log();
3057
+ }
3058
+ async function handleEdit(tool) {
3059
+ const manager = tool === "codex" ? createCodexManager() : createClaudeCodeManager();
3060
+ const providers = manager.list();
3061
+ if (providers.length === 0) {
3062
+ console.log(import_chalk2.default.yellow("\n\u26A0\uFE0F \u6682\u65E0\u670D\u52A1\u5546\n"));
3063
+ return;
3064
+ }
3065
+ const { providerId } = await import_inquirer.default.prompt([
3066
+ {
3067
+ type: "list",
3068
+ name: "providerId",
3069
+ message: "\u9009\u62E9\u8981\u7F16\u8F91\u7684\u670D\u52A1\u5546:",
3070
+ choices: providers.map((p) => ({
3071
+ name: p.name,
3072
+ value: p.id
3073
+ }))
3074
+ }
3075
+ ]);
3076
+ const provider = providers.find((p) => p.id === providerId);
3077
+ const answers = await import_inquirer.default.prompt([
3078
+ {
3079
+ type: "input",
3080
+ name: "name",
3081
+ message: "\u670D\u52A1\u5546\u540D\u79F0:",
3082
+ default: provider.name,
3083
+ validate: (value) => value ? true : "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A"
3084
+ },
3085
+ {
3086
+ type: "input",
3087
+ name: "baseUrl",
3088
+ message: "API \u5730\u5740:",
3089
+ default: provider.baseUrl,
3090
+ validate: (value) => {
3091
+ if (!value) return "API \u5730\u5740\u4E0D\u80FD\u4E3A\u7A7A";
3092
+ if (!value.startsWith("http://") && !value.startsWith("https://")) {
3093
+ return "API \u5730\u5740\u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934";
3094
+ }
3095
+ return true;
3096
+ }
3097
+ },
3098
+ {
3099
+ type: "password",
3100
+ name: "apiKey",
3101
+ message: "API \u5BC6\u94A5 (\u7559\u7A7A\u4E0D\u4FEE\u6539):",
3102
+ mask: "*"
3103
+ }
3104
+ ]);
3105
+ manager.edit(providerId, {
3106
+ name: answers.name,
3107
+ baseUrl: answers.baseUrl,
3108
+ apiKey: answers.apiKey || void 0
3109
+ });
3110
+ console.log(import_chalk2.default.green("\n\u2705 \u7F16\u8F91\u6210\u529F\n"));
3111
+ }
3112
+ async function handleClone(tool) {
3113
+ const manager = tool === "codex" ? createCodexManager() : createClaudeCodeManager();
3114
+ const providers = manager.list();
3115
+ if (providers.length === 0) {
3116
+ console.log(import_chalk2.default.yellow("\n\u26A0\uFE0F \u6682\u65E0\u670D\u52A1\u5546\n"));
3117
+ return;
3118
+ }
3119
+ const { providerId } = await import_inquirer.default.prompt([
3120
+ {
3121
+ type: "list",
3122
+ name: "providerId",
3123
+ message: "\u9009\u62E9\u8981\u514B\u9686\u7684\u670D\u52A1\u5546:",
3124
+ choices: providers.map((p) => ({
3125
+ name: p.name,
3126
+ value: p.id
3127
+ }))
3128
+ }
3129
+ ]);
3130
+ const provider = providers.find((p) => p.id === providerId);
3131
+ const answers = await import_inquirer.default.prompt([
3132
+ {
3133
+ type: "input",
3134
+ name: "name",
3135
+ message: "\u65B0\u670D\u52A1\u5546\u540D\u79F0:",
3136
+ default: `${provider.name}\uFF08\u526F\u672C\uFF09`,
3137
+ validate: (value) => value ? true : "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A"
3138
+ },
3139
+ {
3140
+ type: "password",
3141
+ name: "apiKey",
3142
+ message: "API \u5BC6\u94A5:",
3143
+ mask: "*",
3144
+ validate: (value) => value ? true : "API \u5BC6\u94A5\u4E0D\u80FD\u4E3A\u7A7A"
3145
+ }
3146
+ ]);
3147
+ const newProvider = manager.add({
3148
+ name: answers.name,
3149
+ baseUrl: provider.baseUrl,
3150
+ apiKey: answers.apiKey
3151
+ });
3152
+ console.log(import_chalk2.default.green("\n\u2705 \u514B\u9686\u6210\u529F\n"));
3153
+ console.log(` ${import_chalk2.default.bold(newProvider.name)}`);
3154
+ console.log(` ${import_chalk2.default.gray(`ID: ${newProvider.id}`)}`);
3155
+ console.log();
3156
+ }
3157
+ async function handleRemove(tool) {
3158
+ const manager = tool === "codex" ? createCodexManager() : createClaudeCodeManager();
3159
+ const providers = manager.list();
3160
+ if (providers.length === 0) {
3161
+ console.log(import_chalk2.default.yellow("\n\u26A0\uFE0F \u6682\u65E0\u670D\u52A1\u5546\n"));
3162
+ return;
3163
+ }
3164
+ const { providerId } = await import_inquirer.default.prompt([
3165
+ {
3166
+ type: "list",
3167
+ name: "providerId",
3168
+ message: "\u9009\u62E9\u8981\u5220\u9664\u7684\u670D\u52A1\u5546:",
3169
+ choices: providers.map((p) => ({
3170
+ name: p.name,
3171
+ value: p.id
3172
+ }))
3173
+ }
3174
+ ]);
3175
+ const provider = providers.find((p) => p.id === providerId);
3176
+ const { confirm } = await import_inquirer.default.prompt([
3177
+ {
3178
+ type: "confirm",
3179
+ name: "confirm",
3180
+ message: `\u786E\u5B9A\u8981\u5220\u9664 "${provider.name}" \u5417?`,
3181
+ default: false
3182
+ }
3183
+ ]);
3184
+ if (confirm) {
3185
+ manager.remove(providerId);
3186
+ console.log(import_chalk2.default.green(`
3187
+ \u2705 \u5DF2\u5220\u9664: ${provider.name}
3188
+ `));
3189
+ } else {
3190
+ console.log(import_chalk2.default.gray("\n\u274C \u5DF2\u53D6\u6D88\n"));
3191
+ }
3192
+ }
3193
+
3194
+ // src/commands/codex/add.ts
3195
+ function addCommand(program2) {
3196
+ program2.command("add").description("\u6DFB\u52A0\u65B0\u7684 Codex \u670D\u52A1\u5546(\u4EA4\u4E92\u5F0F)").action(async () => {
3197
+ try {
3198
+ const manager = createCodexManager();
3199
+ console.log(import_chalk3.default.bold("\n\u{1F4DD} \u6DFB\u52A0 Codex \u670D\u52A1\u5546\n"));
3200
+ const { usePreset } = await import_inquirer2.default.prompt([
3201
+ {
3202
+ type: "list",
3203
+ name: "usePreset",
3204
+ message: "\u9009\u62E9\u914D\u7F6E\u6765\u6E90:",
3205
+ choices: [
3206
+ { name: "\u{1F4E6} \u4F7F\u7528\u9884\u7F6E\u670D\u52A1\u5546", value: true },
3207
+ { name: "\u270F\uFE0F \u81EA\u5B9A\u4E49\u914D\u7F6E", value: false }
3208
+ ]
3209
+ }
3210
+ ]);
3211
+ let name;
3212
+ let baseUrl;
3213
+ let apiKey;
3214
+ if (usePreset) {
3215
+ const { presetName } = await import_inquirer2.default.prompt([
3216
+ {
3217
+ type: "list",
3218
+ name: "presetName",
3219
+ message: "\u9009\u62E9\u9884\u7F6E\u670D\u52A1\u5546:",
3220
+ choices: CODEX_PRESETS.map((p) => ({
3221
+ name: `${p.name} - ${p.description}`,
3222
+ value: p.name
3223
+ }))
3224
+ }
3225
+ ]);
3226
+ const preset = CODEX_PRESETS.find((p) => p.name === presetName);
3227
+ console.log(import_chalk3.default.blue(`
3228
+ \u4F7F\u7528\u9884\u8BBE: ${preset.name} - ${preset.description}
3229
+ `));
3230
+ const input = await promptProviderForm({
3231
+ name: preset.name,
3232
+ baseUrl: preset.baseUrl,
3233
+ apiKey: ""
3234
+ });
3235
+ name = input.name;
3236
+ baseUrl = input.baseUrl;
3237
+ apiKey = input.apiKey;
3238
+ } else {
3239
+ const answers = await import_inquirer2.default.prompt([
3240
+ {
3241
+ type: "input",
3242
+ name: "name",
3243
+ message: "\u670D\u52A1\u5546\u540D\u79F0:",
3244
+ validate: (value) => {
3245
+ if (!value) return "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A";
3246
+ return true;
3247
+ }
3248
+ },
3249
+ {
3250
+ type: "input",
3251
+ name: "baseUrl",
3252
+ message: "API \u5730\u5740:",
3253
+ validate: (value) => {
3254
+ if (!value) return "API \u5730\u5740\u4E0D\u80FD\u4E3A\u7A7A";
3255
+ if (!value.startsWith("http://") && !value.startsWith("https://")) {
3256
+ return "API \u5730\u5740\u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934";
3257
+ }
3258
+ return true;
3259
+ }
3260
+ },
3261
+ {
3262
+ type: "password",
3263
+ name: "apiKey",
3264
+ message: "API \u5BC6\u94A5:",
3265
+ mask: "*",
3266
+ validate: (value) => {
3267
+ if (!value) return "API \u5BC6\u94A5\u4E0D\u80FD\u4E3A\u7A7A";
3268
+ return true;
3269
+ }
3270
+ }
3271
+ ]);
3272
+ name = answers.name;
3273
+ baseUrl = answers.baseUrl;
3274
+ apiKey = answers.apiKey;
3275
+ }
3276
+ const provider = manager.add({ name, baseUrl, apiKey });
3277
+ console.log();
3278
+ console.log(import_chalk3.default.green("\u2705 \u6DFB\u52A0\u6210\u529F"));
3279
+ console.log();
3280
+ console.log(` ${import_chalk3.default.bold(provider.name)} ${import_chalk3.default.blue("[Codex]")}`);
3281
+ console.log(` ${import_chalk3.default.gray(`ID: ${provider.id}`)}`);
3282
+ console.log(` ${import_chalk3.default.gray(`URL: ${provider.baseUrl}`)}`);
3283
+ console.log();
3284
+ const { switchNow } = await import_inquirer2.default.prompt([
3285
+ {
3286
+ type: "confirm",
3287
+ name: "switchNow",
3288
+ message: "\u662F\u5426\u7ACB\u5373\u5207\u6362\u5230\u6B64\u670D\u52A1\u5546?",
3289
+ default: true
3290
+ }
3291
+ ]);
3292
+ if (switchNow) {
3293
+ manager.switch(provider.id);
3294
+ console.log(import_chalk3.default.green("\u2705 \u5DF2\u5207\u6362\u5230\u65B0\u670D\u52A1\u5546"));
3295
+ console.log();
3296
+ console.log(import_chalk3.default.gray("\u914D\u7F6E\u5DF2\u66F4\u65B0:"));
3297
+ console.log(import_chalk3.default.gray(" - ~/.codex/config.toml"));
3298
+ console.log(import_chalk3.default.gray(" - ~/.codex/auth.json"));
3299
+ } else {
3300
+ console.log(import_chalk3.default.blue("\u{1F4A1} \u7A0D\u540E\u5207\u6362:") + import_chalk3.default.white(` ccman cx use "${provider.name}"`));
3301
+ }
3302
+ } catch (error) {
3303
+ console.error(import_chalk3.default.red(`
3304
+ \u274C ${error.message}
3305
+ `));
3306
+ process.exit(1);
3307
+ }
3308
+ });
3309
+ }
3310
+
3311
+ // src/commands/codex/list.ts
3312
+ var import_chalk4 = __toESM(require("chalk"));
3313
+ function listCommand(program2) {
3314
+ program2.command("list").alias("ls").description("\u5217\u51FA\u6240\u6709 Codex \u670D\u52A1\u5546").action(async () => {
3315
+ try {
3316
+ const manager = createCodexManager();
3317
+ const providers = manager.list();
3318
+ const current = manager.getCurrent();
3319
+ if (providers.length === 0) {
3320
+ console.log(import_chalk4.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Codex \u670D\u52A1\u5546\n"));
3321
+ console.log(import_chalk4.default.blue("\u{1F4A1} \u6DFB\u52A0\u670D\u52A1\u5546:") + import_chalk4.default.white(" ccman cx add\n"));
3322
+ return;
3323
+ }
3324
+ console.log(import_chalk4.default.bold(`
3325
+ \u{1F4CB} Codex \u670D\u52A1\u5546\u5217\u8868 (\u5171 ${providers.length} \u4E2A)
3326
+ `));
3327
+ providers.forEach((p) => {
3328
+ const isCurrent = current?.id === p.id;
3329
+ const marker = isCurrent ? import_chalk4.default.green("\u25CF") : import_chalk4.default.gray("\u25CB");
3330
+ const nameStyle = isCurrent ? import_chalk4.default.green.bold : import_chalk4.default.white;
3331
+ console.log(`${marker} ${nameStyle(p.name)}`);
3332
+ console.log(` ${import_chalk4.default.gray(p.baseUrl)}`);
3333
+ if (p.lastUsedAt) {
3334
+ const date = new Date(p.lastUsedAt).toLocaleString("zh-CN");
3335
+ console.log(` ${import_chalk4.default.gray(`\u6700\u540E\u4F7F\u7528: ${date}`)}`);
3336
+ }
3337
+ console.log();
3338
+ });
3339
+ if (current) {
3340
+ console.log(import_chalk4.default.green(`\u2705 \u5F53\u524D\u4F7F\u7528: ${current.name}
3341
+ `));
3342
+ } else {
3343
+ console.log(import_chalk4.default.yellow("\u26A0\uFE0F \u672A\u9009\u62E9\u4EFB\u4F55\u670D\u52A1\u5546\n"));
3344
+ }
3345
+ } catch (error) {
3346
+ console.error(import_chalk4.default.red(`
3347
+ \u274C ${error.message}
3348
+ `));
3349
+ process.exit(1);
3350
+ }
3351
+ });
3352
+ }
3353
+
3354
+ // src/commands/codex/use.ts
3355
+ var import_chalk5 = __toESM(require("chalk"));
3356
+ var import_inquirer3 = __toESM(require("inquirer"));
3357
+ function useCommand(program2) {
3358
+ program2.command("use [name]").description("\u5207\u6362 Codex \u670D\u52A1\u5546").action(async (name) => {
3359
+ try {
3360
+ const manager = createCodexManager();
3361
+ const providers = manager.list();
3362
+ if (providers.length === 0) {
3363
+ console.log(import_chalk5.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Codex \u670D\u52A1\u5546\n"));
3364
+ console.log(import_chalk5.default.blue("\u{1F4A1} \u6DFB\u52A0\u670D\u52A1\u5546:") + import_chalk5.default.white(" ccman cx add\n"));
3365
+ return;
3366
+ }
3367
+ let targetId;
3368
+ if (name) {
3369
+ const provider2 = manager.findByName(name);
3370
+ if (!provider2) {
3371
+ throw new ProviderNotFoundError(name);
3372
+ }
3373
+ targetId = provider2.id;
3374
+ } else {
3375
+ const { selectedId } = await import_inquirer3.default.prompt([
3376
+ {
3377
+ type: "list",
3378
+ name: "selectedId",
3379
+ message: "\u9009\u62E9\u8981\u5207\u6362\u7684\u670D\u52A1\u5546:",
3380
+ choices: providers.map((p) => ({
3381
+ name: `${p.name} - ${p.baseUrl}`,
3382
+ value: p.id
3383
+ }))
3384
+ }
3385
+ ]);
3386
+ targetId = selectedId;
3387
+ }
3388
+ manager.switch(targetId);
3389
+ const provider = manager.get(targetId);
3390
+ console.log();
3391
+ console.log(import_chalk5.default.green("\u2705 \u5207\u6362\u6210\u529F"));
3392
+ console.log();
3393
+ console.log(` ${import_chalk5.default.bold(provider.name)} ${import_chalk5.default.blue("[Codex]")}`);
3394
+ console.log(` ${import_chalk5.default.gray(`URL: ${provider.baseUrl}`)}`);
3395
+ console.log();
3396
+ console.log(import_chalk5.default.gray("\u914D\u7F6E\u5DF2\u66F4\u65B0:"));
3397
+ console.log(import_chalk5.default.gray(" - ~/.codex/config.toml"));
3398
+ console.log(import_chalk5.default.gray(" - ~/.codex/auth.json"));
3399
+ console.log();
3400
+ } catch (error) {
3401
+ if (error instanceof ProviderNotFoundError) {
3402
+ console.error(import_chalk5.default.red(`
3403
+ \u274C \u670D\u52A1\u5546\u4E0D\u5B58\u5728: ${error.message}
3404
+ `));
3405
+ console.log(import_chalk5.default.blue("\u{1F4A1} \u67E5\u770B\u6240\u6709\u670D\u52A1\u5546:") + import_chalk5.default.white(" ccman cx list\n"));
3406
+ } else {
3407
+ console.error(import_chalk5.default.red(`
3408
+ \u274C ${error.message}
3409
+ `));
3410
+ }
3411
+ process.exit(1);
3412
+ }
3413
+ });
3414
+ }
3415
+
3416
+ // src/commands/codex/current.ts
3417
+ var import_chalk6 = __toESM(require("chalk"));
3418
+ function currentCommand(program2) {
3419
+ program2.command("current").description("\u663E\u793A\u5F53\u524D\u4F7F\u7528\u7684 Codex \u670D\u52A1\u5546").action(async () => {
3420
+ try {
3421
+ const manager = createCodexManager();
3422
+ const current = manager.getCurrent();
3423
+ if (!current) {
3424
+ console.log(import_chalk6.default.yellow("\n\u26A0\uFE0F \u672A\u9009\u62E9\u4EFB\u4F55 Codex \u670D\u52A1\u5546\n"));
3425
+ console.log(import_chalk6.default.blue("\u{1F4A1} \u9009\u62E9\u670D\u52A1\u5546:") + import_chalk6.default.white(" ccman cx use\n"));
3426
+ return;
3427
+ }
3428
+ console.log(import_chalk6.default.bold("\n\u{1F4CD} \u5F53\u524D Codex \u670D\u52A1\u5546\n"));
3429
+ console.log(` ${import_chalk6.default.green.bold(current.name)}`);
3430
+ console.log(` ${import_chalk6.default.gray(`ID: ${current.id}`)}`);
3431
+ console.log(` ${import_chalk6.default.gray(`URL: ${current.baseUrl}`)}`);
3432
+ if (current.lastUsedAt) {
3433
+ const date = new Date(current.lastUsedAt).toLocaleString("zh-CN");
3434
+ console.log(` ${import_chalk6.default.gray(`\u6700\u540E\u4F7F\u7528: ${date}`)}`);
3435
+ }
3436
+ console.log();
3437
+ } catch (error) {
3438
+ console.error(import_chalk6.default.red(`
3439
+ \u274C ${error.message}
3440
+ `));
3441
+ process.exit(1);
3442
+ }
3443
+ });
3444
+ }
3445
+
3446
+ // src/commands/codex/remove.ts
3447
+ var import_chalk7 = __toESM(require("chalk"));
3448
+ var import_inquirer4 = __toESM(require("inquirer"));
3449
+ function removeCommand(program2) {
3450
+ program2.command("remove [name]").alias("rm").description("\u5220\u9664 Codex \u670D\u52A1\u5546").action(async (name) => {
3451
+ try {
3452
+ const manager = createCodexManager();
3453
+ const providers = manager.list();
3454
+ if (providers.length === 0) {
3455
+ console.log(import_chalk7.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Codex \u670D\u52A1\u5546\n"));
3456
+ return;
3457
+ }
3458
+ let targetId;
3459
+ let targetName;
3460
+ if (name) {
3461
+ const provider = manager.findByName(name);
3462
+ if (!provider) {
3463
+ throw new ProviderNotFoundError(name);
3464
+ }
3465
+ targetId = provider.id;
3466
+ targetName = provider.name;
3467
+ } else {
3468
+ const { selectedId } = await import_inquirer4.default.prompt([
3469
+ {
3470
+ type: "list",
3471
+ name: "selectedId",
3472
+ message: "\u9009\u62E9\u8981\u5220\u9664\u7684\u670D\u52A1\u5546:",
3473
+ choices: providers.map((p) => ({
3474
+ name: `${p.name} - ${p.baseUrl}`,
3475
+ value: p.id
3476
+ }))
3477
+ }
3478
+ ]);
3479
+ const provider = manager.get(selectedId);
3480
+ targetId = selectedId;
3481
+ targetName = provider.name;
3482
+ }
3483
+ const { confirmed } = await import_inquirer4.default.prompt([
3484
+ {
3485
+ type: "confirm",
3486
+ name: "confirmed",
3487
+ message: `\u786E\u5B9A\u5220\u9664 "${targetName}"?`,
3488
+ default: false
3489
+ }
3490
+ ]);
3491
+ if (!confirmed) {
3492
+ console.log(import_chalk7.default.gray("\n\u5DF2\u53D6\u6D88\n"));
3493
+ return;
3494
+ }
3495
+ manager.remove(targetId);
3496
+ console.log();
3497
+ console.log(import_chalk7.default.green(`\u2705 \u5DF2\u5220\u9664: ${targetName}`));
3498
+ console.log();
3499
+ } catch (error) {
3500
+ if (error instanceof ProviderNotFoundError) {
3501
+ console.error(import_chalk7.default.red(`
3502
+ \u274C \u670D\u52A1\u5546\u4E0D\u5B58\u5728
3503
+ `));
3504
+ console.log(import_chalk7.default.blue("\u{1F4A1} \u67E5\u770B\u6240\u6709\u670D\u52A1\u5546:") + import_chalk7.default.white(" ccman cx list\n"));
3505
+ } else {
3506
+ console.error(import_chalk7.default.red(`
3507
+ \u274C ${error.message}
3508
+ `));
3509
+ }
3510
+ process.exit(1);
3511
+ }
3512
+ });
3513
+ }
3514
+
3515
+ // src/commands/codex/edit.ts
3516
+ var import_chalk8 = __toESM(require("chalk"));
3517
+ var import_inquirer5 = __toESM(require("inquirer"));
3518
+ function editCommand(program2) {
3519
+ program2.command("edit [name]").description("\u7F16\u8F91 Codex \u670D\u52A1\u5546").action(async (name) => {
3520
+ try {
3521
+ const manager = createCodexManager();
3522
+ const providers = manager.list();
3523
+ if (providers.length === 0) {
3524
+ console.log(import_chalk8.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Codex \u670D\u52A1\u5546\n"));
3525
+ return;
3526
+ }
3527
+ let targetId;
3528
+ if (name) {
3529
+ const provider2 = manager.findByName(name);
3530
+ if (!provider2) {
3531
+ throw new ProviderNotFoundError(name);
3532
+ }
3533
+ targetId = provider2.id;
3534
+ } else {
3535
+ const { selectedId } = await import_inquirer5.default.prompt([
3536
+ {
3537
+ type: "list",
3538
+ name: "selectedId",
3539
+ message: "\u9009\u62E9\u8981\u7F16\u8F91\u7684\u670D\u52A1\u5546:",
3540
+ choices: providers.map((p) => ({
3541
+ name: `${p.name} - ${p.baseUrl}`,
3542
+ value: p.id
3543
+ }))
3544
+ }
3545
+ ]);
3546
+ targetId = selectedId;
3547
+ }
3548
+ const provider = manager.get(targetId);
3549
+ console.log(import_chalk8.default.bold("\n\u270F\uFE0F \u7F16\u8F91\u670D\u52A1\u5546\n"));
3550
+ console.log(import_chalk8.default.gray("\u63D0\u793A: \u7559\u7A7A\u5219\u4FDD\u6301\u539F\u503C\n"));
3551
+ const answers = await import_inquirer5.default.prompt([
3552
+ {
3553
+ type: "input",
3554
+ name: "name",
3555
+ message: "\u670D\u52A1\u5546\u540D\u79F0:",
3556
+ default: provider.name
3557
+ },
3558
+ {
3559
+ type: "input",
3560
+ name: "baseUrl",
3561
+ message: "API \u5730\u5740:",
3562
+ default: provider.baseUrl,
3563
+ validate: (value) => {
3564
+ if (value && !value.startsWith("http://") && !value.startsWith("https://")) {
3565
+ return "API \u5730\u5740\u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934";
3566
+ }
3567
+ return true;
3568
+ }
3569
+ },
3570
+ {
3571
+ type: "password",
3572
+ name: "apiKey",
3573
+ message: "API \u5BC6\u94A5 (\u7559\u7A7A\u4FDD\u6301\u4E0D\u53D8):",
3574
+ mask: "*"
3575
+ }
3576
+ ]);
3577
+ const updates = {};
3578
+ if (answers.name && answers.name !== provider.name) updates.name = answers.name;
3579
+ if (answers.baseUrl && answers.baseUrl !== provider.baseUrl) updates.baseUrl = answers.baseUrl;
3580
+ if (answers.apiKey) updates.apiKey = answers.apiKey;
3581
+ if (Object.keys(updates).length === 0) {
3582
+ console.log(import_chalk8.default.gray("\n\u672A\u505A\u4EFB\u4F55\u4FEE\u6539\n"));
3583
+ return;
3584
+ }
3585
+ const updated = manager.edit(targetId, updates);
3586
+ console.log();
3587
+ console.log(import_chalk8.default.green("\u2705 \u7F16\u8F91\u6210\u529F"));
3588
+ console.log();
3589
+ console.log(` ${import_chalk8.default.bold(updated.name)} ${import_chalk8.default.blue("[Codex]")}`);
3590
+ console.log(` ${import_chalk8.default.gray(`ID: ${updated.id}`)}`);
3591
+ console.log(` ${import_chalk8.default.gray(`URL: ${updated.baseUrl}`)}`);
3592
+ console.log();
3593
+ } catch (error) {
3594
+ console.error(import_chalk8.default.red(`
3595
+ \u274C ${error.message}
3596
+ `));
3597
+ process.exit(1);
3598
+ }
3599
+ });
3600
+ }
3601
+
3602
+ // src/commands/codex/clone.ts
3603
+ var import_chalk9 = __toESM(require("chalk"));
3604
+ var import_inquirer6 = __toESM(require("inquirer"));
3605
+ function cloneCommand(program2) {
3606
+ program2.command("clone [source-name] [new-name]").description("\u514B\u9686 Codex \u670D\u52A1\u5546").action(async (sourceName, newName) => {
3607
+ try {
3608
+ const manager = createCodexManager();
3609
+ const providers = manager.list();
3610
+ if (providers.length === 0) {
3611
+ console.log(import_chalk9.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Codex \u670D\u52A1\u5546\n"));
3612
+ return;
3613
+ }
3614
+ let sourceId;
3615
+ if (sourceName) {
3616
+ const provider = manager.findByName(sourceName);
3617
+ if (!provider) {
3618
+ throw new ProviderNotFoundError(sourceName);
3619
+ }
3620
+ sourceId = provider.id;
3621
+ } else {
3622
+ const { selectedId } = await import_inquirer6.default.prompt([
3623
+ {
3624
+ type: "list",
3625
+ name: "selectedId",
3626
+ message: "\u9009\u62E9\u8981\u514B\u9686\u7684\u670D\u52A1\u5546:",
3627
+ choices: providers.map((p) => ({
3628
+ name: `${p.name} - ${p.baseUrl}`,
3629
+ value: p.id
3630
+ }))
3631
+ }
3632
+ ]);
3633
+ sourceId = selectedId;
3634
+ }
3635
+ const source = manager.get(sourceId);
3636
+ let cloned;
3637
+ if (newName) {
3638
+ cloned = manager.clone(sourceId, newName);
3639
+ } else {
3640
+ console.log(import_chalk9.default.blue(`
3641
+ \u514B\u9686\u81EA: ${source.name}
3642
+ `));
3643
+ const input = await promptProviderForm({
3644
+ name: `${source.name}\uFF08\u526F\u672C\uFF09`,
3645
+ baseUrl: source.baseUrl,
3646
+ apiKey: source.apiKey
3647
+ });
3648
+ cloned = manager.add(input);
3649
+ }
3650
+ console.log();
3651
+ console.log(import_chalk9.default.green("\u2705 \u514B\u9686\u6210\u529F"));
3652
+ console.log();
3653
+ console.log(` ${import_chalk9.default.bold(cloned.name)} ${import_chalk9.default.blue("[Codex]")}`);
3654
+ console.log(` ${import_chalk9.default.gray(`ID: ${cloned.id}`)}`);
3655
+ console.log(` ${import_chalk9.default.gray(`URL: ${cloned.baseUrl}`)}`);
3656
+ console.log();
3657
+ } catch (error) {
3658
+ console.error(import_chalk9.default.red(`
3659
+ \u274C ${error.message}
3660
+ `));
3661
+ process.exit(1);
3662
+ }
3663
+ });
3664
+ }
3665
+
3666
+ // src/commands/codex/index.ts
3667
+ function createCodexCommands(program2) {
3668
+ addCommand(program2);
3669
+ listCommand(program2);
3670
+ useCommand(program2);
3671
+ currentCommand(program2);
3672
+ removeCommand(program2);
3673
+ editCommand(program2);
3674
+ cloneCommand(program2);
3675
+ }
3676
+
3677
+ // src/commands/claudecode/add.ts
3678
+ var import_chalk10 = __toESM(require("chalk"));
3679
+ var import_inquirer7 = __toESM(require("inquirer"));
3680
+ function addCommand2(program2) {
3681
+ program2.command("add").description("\u6DFB\u52A0\u65B0\u7684 Claude Code \u670D\u52A1\u5546(\u4EA4\u4E92\u5F0F)").action(async () => {
3682
+ try {
3683
+ const manager = createClaudeCodeManager();
3684
+ console.log(import_chalk10.default.bold("\n\u{1F4DD} \u6DFB\u52A0 Claude Code \u670D\u52A1\u5546\n"));
3685
+ const { usePreset } = await import_inquirer7.default.prompt([
3686
+ {
3687
+ type: "list",
3688
+ name: "usePreset",
3689
+ message: "\u9009\u62E9\u914D\u7F6E\u6765\u6E90:",
3690
+ choices: [
3691
+ { name: "\u{1F4E6} \u4F7F\u7528\u9884\u7F6E\u670D\u52A1\u5546", value: true },
3692
+ { name: "\u270F\uFE0F \u81EA\u5B9A\u4E49\u914D\u7F6E", value: false }
3693
+ ]
3694
+ }
3695
+ ]);
3696
+ let name;
3697
+ let baseUrl;
3698
+ let apiKey;
3699
+ if (usePreset) {
3700
+ const { presetName } = await import_inquirer7.default.prompt([
3701
+ {
3702
+ type: "list",
3703
+ name: "presetName",
3704
+ message: "\u9009\u62E9\u9884\u7F6E\u670D\u52A1\u5546:",
3705
+ choices: CLAUDECODE_PRESETS.map((p) => ({
3706
+ name: `${p.name} - ${p.description}`,
3707
+ value: p.name
3708
+ }))
3709
+ }
3710
+ ]);
3711
+ const preset = CLAUDECODE_PRESETS.find((p) => p.name === presetName);
3712
+ console.log(import_chalk10.default.blue(`
3713
+ \u4F7F\u7528\u9884\u8BBE: ${preset.name} - ${preset.description}
3714
+ `));
3715
+ const input = await promptProviderForm({
3716
+ name: preset.name,
3717
+ baseUrl: preset.baseUrl,
3718
+ apiKey: ""
3719
+ });
3720
+ name = input.name;
3721
+ baseUrl = input.baseUrl;
3722
+ apiKey = input.apiKey;
3723
+ } else {
3724
+ const answers = await import_inquirer7.default.prompt([
3725
+ {
3726
+ type: "input",
3727
+ name: "name",
3728
+ message: "\u670D\u52A1\u5546\u540D\u79F0:",
3729
+ validate: (value) => {
3730
+ if (!value) return "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A";
3731
+ return true;
3732
+ }
3733
+ },
3734
+ {
3735
+ type: "input",
3736
+ name: "baseUrl",
3737
+ message: "API \u5730\u5740:",
3738
+ validate: (value) => {
3739
+ if (!value) return "API \u5730\u5740\u4E0D\u80FD\u4E3A\u7A7A";
3740
+ if (!value.startsWith("http://") && !value.startsWith("https://")) {
3741
+ return "API \u5730\u5740\u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934";
3742
+ }
3743
+ return true;
3744
+ }
3745
+ },
3746
+ {
3747
+ type: "password",
3748
+ name: "apiKey",
3749
+ message: "API \u5BC6\u94A5:",
3750
+ mask: "*",
3751
+ validate: (value) => {
3752
+ if (!value) return "API \u5BC6\u94A5\u4E0D\u80FD\u4E3A\u7A7A";
3753
+ return true;
3754
+ }
3755
+ }
3756
+ ]);
3757
+ name = answers.name;
3758
+ baseUrl = answers.baseUrl;
3759
+ apiKey = answers.apiKey;
3760
+ }
3761
+ const provider = manager.add({ name, baseUrl, apiKey });
3762
+ console.log();
3763
+ console.log(import_chalk10.default.green("\u2705 \u6DFB\u52A0\u6210\u529F"));
3764
+ console.log();
3765
+ console.log(` ${import_chalk10.default.bold(provider.name)} ${import_chalk10.default.blue("[Claude Code]")}`);
3766
+ console.log(` ${import_chalk10.default.gray(`ID: ${provider.id}`)}`);
3767
+ console.log(` ${import_chalk10.default.gray(`URL: ${provider.baseUrl}`)}`);
3768
+ console.log();
3769
+ const { switchNow } = await import_inquirer7.default.prompt([
3770
+ {
3771
+ type: "confirm",
3772
+ name: "switchNow",
3773
+ message: "\u662F\u5426\u7ACB\u5373\u5207\u6362\u5230\u6B64\u670D\u52A1\u5546?",
3774
+ default: true
3775
+ }
3776
+ ]);
3777
+ if (switchNow) {
3778
+ manager.switch(provider.id);
3779
+ console.log(import_chalk10.default.green("\u2705 \u5DF2\u5207\u6362\u5230\u65B0\u670D\u52A1\u5546"));
3780
+ console.log();
3781
+ console.log(import_chalk10.default.gray("\u914D\u7F6E\u5DF2\u66F4\u65B0:"));
3782
+ console.log(import_chalk10.default.gray(" - ~/.claude/settings.json"));
3783
+ } else {
3784
+ console.log(import_chalk10.default.blue("\u{1F4A1} \u7A0D\u540E\u5207\u6362:") + import_chalk10.default.white(` ccman cc use "${provider.name}"`));
3785
+ }
3786
+ } catch (error) {
3787
+ console.error(import_chalk10.default.red(`
3788
+ \u274C ${error.message}
3789
+ `));
3790
+ process.exit(1);
3791
+ }
3792
+ });
3793
+ }
3794
+
3795
+ // src/commands/claudecode/list.ts
3796
+ var import_chalk11 = __toESM(require("chalk"));
3797
+ function listCommand2(program2) {
3798
+ program2.command("list").alias("ls").description("\u5217\u51FA\u6240\u6709 Claude Code \u670D\u52A1\u5546").action(async () => {
3799
+ try {
3800
+ const manager = createClaudeCodeManager();
3801
+ const providers = manager.list();
3802
+ const current = manager.getCurrent();
3803
+ if (providers.length === 0) {
3804
+ console.log(import_chalk11.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Claude Code \u670D\u52A1\u5546\n"));
3805
+ console.log(import_chalk11.default.blue("\u{1F4A1} \u6DFB\u52A0\u670D\u52A1\u5546:") + import_chalk11.default.white(" ccman cc add\n"));
3806
+ return;
3807
+ }
3808
+ console.log(import_chalk11.default.bold(`
3809
+ \u{1F4CB} Claude Code \u670D\u52A1\u5546\u5217\u8868 (\u5171 ${providers.length} \u4E2A)
3810
+ `));
3811
+ providers.forEach((p) => {
3812
+ const isCurrent = current?.id === p.id;
3813
+ const marker = isCurrent ? import_chalk11.default.green("\u25CF") : import_chalk11.default.gray("\u25CB");
3814
+ const nameStyle = isCurrent ? import_chalk11.default.green.bold : import_chalk11.default.white;
3815
+ console.log(`${marker} ${nameStyle(p.name)}`);
3816
+ console.log(` ${import_chalk11.default.gray(p.baseUrl)}`);
3817
+ if (p.lastUsedAt) {
3818
+ const date = new Date(p.lastUsedAt).toLocaleString("zh-CN");
3819
+ console.log(` ${import_chalk11.default.gray(`\u6700\u540E\u4F7F\u7528: ${date}`)}`);
3820
+ }
3821
+ console.log();
3822
+ });
3823
+ if (current) {
3824
+ console.log(import_chalk11.default.green(`\u2705 \u5F53\u524D\u4F7F\u7528: ${current.name}
3825
+ `));
3826
+ } else {
3827
+ console.log(import_chalk11.default.yellow("\u26A0\uFE0F \u672A\u9009\u62E9\u4EFB\u4F55\u670D\u52A1\u5546\n"));
3828
+ }
3829
+ } catch (error) {
3830
+ console.error(import_chalk11.default.red(`
3831
+ \u274C ${error.message}
3832
+ `));
3833
+ process.exit(1);
3834
+ }
3835
+ });
3836
+ }
3837
+
3838
+ // src/commands/claudecode/use.ts
3839
+ var import_chalk12 = __toESM(require("chalk"));
3840
+ var import_inquirer8 = __toESM(require("inquirer"));
3841
+ function useCommand2(program2) {
3842
+ program2.command("use [name]").description("\u5207\u6362 Claude Code \u670D\u52A1\u5546").action(async (name) => {
3843
+ try {
3844
+ const manager = createClaudeCodeManager();
3845
+ const providers = manager.list();
3846
+ if (providers.length === 0) {
3847
+ console.log(import_chalk12.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Claude Code \u670D\u52A1\u5546\n"));
3848
+ console.log(import_chalk12.default.blue("\u{1F4A1} \u6DFB\u52A0\u670D\u52A1\u5546:") + import_chalk12.default.white(" ccman cc add\n"));
3849
+ return;
3850
+ }
3851
+ let targetId;
3852
+ if (name) {
3853
+ const provider2 = manager.findByName(name);
3854
+ if (!provider2) {
3855
+ throw new ProviderNotFoundError(name);
3856
+ }
3857
+ targetId = provider2.id;
3858
+ } else {
3859
+ const { selectedId } = await import_inquirer8.default.prompt([
3860
+ {
3861
+ type: "list",
3862
+ name: "selectedId",
3863
+ message: "\u9009\u62E9\u8981\u5207\u6362\u7684\u670D\u52A1\u5546:",
3864
+ choices: providers.map((p) => ({
3865
+ name: `${p.name} - ${p.baseUrl}`,
3866
+ value: p.id
3867
+ }))
3868
+ }
3869
+ ]);
3870
+ targetId = selectedId;
3871
+ }
3872
+ manager.switch(targetId);
3873
+ const provider = manager.get(targetId);
3874
+ console.log();
3875
+ console.log(import_chalk12.default.green("\u2705 \u5207\u6362\u6210\u529F"));
3876
+ console.log();
3877
+ console.log(` ${import_chalk12.default.bold(provider.name)} ${import_chalk12.default.blue("[Claude Code]")}`);
3878
+ console.log(` ${import_chalk12.default.gray(`URL: ${provider.baseUrl}`)}`);
3879
+ console.log();
3880
+ console.log(import_chalk12.default.gray("\u914D\u7F6E\u5DF2\u66F4\u65B0:"));
3881
+ console.log(import_chalk12.default.gray(" - ~/.claude/config.toml"));
3882
+ console.log(import_chalk12.default.gray(" - ~/.claude/auth.json"));
3883
+ console.log();
3884
+ } catch (error) {
3885
+ if (error instanceof ProviderNotFoundError) {
3886
+ console.error(import_chalk12.default.red(`
3887
+ \u274C \u670D\u52A1\u5546\u4E0D\u5B58\u5728: ${error.message}
3888
+ `));
3889
+ console.log(import_chalk12.default.blue("\u{1F4A1} \u67E5\u770B\u6240\u6709\u670D\u52A1\u5546:") + import_chalk12.default.white(" ccman cc list\n"));
3890
+ } else {
3891
+ console.error(import_chalk12.default.red(`
3892
+ \u274C ${error.message}
3893
+ `));
3894
+ }
3895
+ process.exit(1);
3896
+ }
3897
+ });
3898
+ }
3899
+
3900
+ // src/commands/claudecode/current.ts
3901
+ var import_chalk13 = __toESM(require("chalk"));
3902
+ function currentCommand2(program2) {
3903
+ program2.command("current").description("\u663E\u793A\u5F53\u524D\u4F7F\u7528\u7684 Claude Code \u670D\u52A1\u5546").action(async () => {
3904
+ try {
3905
+ const manager = createClaudeCodeManager();
3906
+ const current = manager.getCurrent();
3907
+ if (!current) {
3908
+ console.log(import_chalk13.default.yellow("\n\u26A0\uFE0F \u672A\u9009\u62E9\u4EFB\u4F55 Claude Code \u670D\u52A1\u5546\n"));
3909
+ console.log(import_chalk13.default.blue("\u{1F4A1} \u9009\u62E9\u670D\u52A1\u5546:") + import_chalk13.default.white(" ccman cc use\n"));
3910
+ return;
3911
+ }
3912
+ console.log(import_chalk13.default.bold("\n\u{1F4CD} \u5F53\u524D Claude Code \u670D\u52A1\u5546\n"));
3913
+ console.log(` ${import_chalk13.default.green.bold(current.name)}`);
3914
+ console.log(` ${import_chalk13.default.gray(`ID: ${current.id}`)}`);
3915
+ console.log(` ${import_chalk13.default.gray(`URL: ${current.baseUrl}`)}`);
3916
+ if (current.lastUsedAt) {
3917
+ const date = new Date(current.lastUsedAt).toLocaleString("zh-CN");
3918
+ console.log(` ${import_chalk13.default.gray(`\u6700\u540E\u4F7F\u7528: ${date}`)}`);
3919
+ }
3920
+ console.log();
3921
+ } catch (error) {
3922
+ console.error(import_chalk13.default.red(`
3923
+ \u274C ${error.message}
3924
+ `));
3925
+ process.exit(1);
3926
+ }
3927
+ });
3928
+ }
3929
+
3930
+ // src/commands/claudecode/remove.ts
3931
+ var import_chalk14 = __toESM(require("chalk"));
3932
+ var import_inquirer9 = __toESM(require("inquirer"));
3933
+ function removeCommand2(program2) {
3934
+ program2.command("remove [name]").alias("rm").description("\u5220\u9664 Claude Code \u670D\u52A1\u5546").action(async (name) => {
3935
+ try {
3936
+ const manager = createClaudeCodeManager();
3937
+ const providers = manager.list();
3938
+ if (providers.length === 0) {
3939
+ console.log(import_chalk14.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Claude Code \u670D\u52A1\u5546\n"));
3940
+ return;
3941
+ }
3942
+ let targetId;
3943
+ let targetName;
3944
+ if (name) {
3945
+ const provider = manager.findByName(name);
3946
+ if (!provider) {
3947
+ throw new ProviderNotFoundError(name);
3948
+ }
3949
+ targetId = provider.id;
3950
+ targetName = provider.name;
3951
+ } else {
3952
+ const { selectedId } = await import_inquirer9.default.prompt([
3953
+ {
3954
+ type: "list",
3955
+ name: "selectedId",
3956
+ message: "\u9009\u62E9\u8981\u5220\u9664\u7684\u670D\u52A1\u5546:",
3957
+ choices: providers.map((p) => ({
3958
+ name: `${p.name} - ${p.baseUrl}`,
3959
+ value: p.id
3960
+ }))
3961
+ }
3962
+ ]);
3963
+ const provider = manager.get(selectedId);
3964
+ targetId = selectedId;
3965
+ targetName = provider.name;
3966
+ }
3967
+ const { confirmed } = await import_inquirer9.default.prompt([
3968
+ {
3969
+ type: "confirm",
3970
+ name: "confirmed",
3971
+ message: `\u786E\u5B9A\u5220\u9664 "${targetName}"?`,
3972
+ default: false
3973
+ }
3974
+ ]);
3975
+ if (!confirmed) {
3976
+ console.log(import_chalk14.default.gray("\n\u5DF2\u53D6\u6D88\n"));
3977
+ return;
3978
+ }
3979
+ manager.remove(targetId);
3980
+ console.log();
3981
+ console.log(import_chalk14.default.green(`\u2705 \u5DF2\u5220\u9664: ${targetName}`));
3982
+ console.log();
3983
+ } catch (error) {
3984
+ if (error instanceof ProviderNotFoundError) {
3985
+ console.error(import_chalk14.default.red(`
3986
+ \u274C \u670D\u52A1\u5546\u4E0D\u5B58\u5728
3987
+ `));
3988
+ console.log(import_chalk14.default.blue("\u{1F4A1} \u67E5\u770B\u6240\u6709\u670D\u52A1\u5546:") + import_chalk14.default.white(" ccman cc list\n"));
3989
+ } else {
3990
+ console.error(import_chalk14.default.red(`
3991
+ \u274C ${error.message}
3992
+ `));
3993
+ }
3994
+ process.exit(1);
3995
+ }
3996
+ });
3997
+ }
3998
+
3999
+ // src/commands/claudecode/edit.ts
4000
+ var import_chalk15 = __toESM(require("chalk"));
4001
+ var import_inquirer10 = __toESM(require("inquirer"));
4002
+ function editCommand2(program2) {
4003
+ program2.command("edit [name]").description("\u7F16\u8F91 Claude Code \u670D\u52A1\u5546").action(async (name) => {
4004
+ try {
4005
+ const manager = createClaudeCodeManager();
4006
+ const providers = manager.list();
4007
+ if (providers.length === 0) {
4008
+ console.log(import_chalk15.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Claude Code \u670D\u52A1\u5546\n"));
4009
+ return;
4010
+ }
4011
+ let targetId;
4012
+ if (name) {
4013
+ const provider2 = manager.findByName(name);
4014
+ if (!provider2) {
4015
+ throw new ProviderNotFoundError(name);
4016
+ }
4017
+ targetId = provider2.id;
4018
+ } else {
4019
+ const { selectedId } = await import_inquirer10.default.prompt([
4020
+ {
4021
+ type: "list",
4022
+ name: "selectedId",
4023
+ message: "\u9009\u62E9\u8981\u7F16\u8F91\u7684\u670D\u52A1\u5546:",
4024
+ choices: providers.map((p) => ({
4025
+ name: `${p.name} - ${p.baseUrl}`,
4026
+ value: p.id
4027
+ }))
4028
+ }
4029
+ ]);
4030
+ targetId = selectedId;
4031
+ }
4032
+ const provider = manager.get(targetId);
4033
+ console.log(import_chalk15.default.bold("\n\u270F\uFE0F \u7F16\u8F91\u670D\u52A1\u5546\n"));
4034
+ console.log(import_chalk15.default.gray("\u63D0\u793A: \u7559\u7A7A\u5219\u4FDD\u6301\u539F\u503C\n"));
4035
+ const answers = await import_inquirer10.default.prompt([
4036
+ {
4037
+ type: "input",
4038
+ name: "name",
4039
+ message: "\u670D\u52A1\u5546\u540D\u79F0:",
4040
+ default: provider.name
4041
+ },
4042
+ {
4043
+ type: "input",
4044
+ name: "baseUrl",
4045
+ message: "API \u5730\u5740:",
4046
+ default: provider.baseUrl,
4047
+ validate: (value) => {
4048
+ if (value && !value.startsWith("http://") && !value.startsWith("https://")) {
4049
+ return "API \u5730\u5740\u5FC5\u987B\u4EE5 http:// \u6216 https:// \u5F00\u5934";
4050
+ }
4051
+ return true;
4052
+ }
4053
+ },
4054
+ {
4055
+ type: "password",
4056
+ name: "apiKey",
4057
+ message: "API \u5BC6\u94A5 (\u7559\u7A7A\u4FDD\u6301\u4E0D\u53D8):",
4058
+ mask: "*"
4059
+ }
4060
+ ]);
4061
+ const updates = {};
4062
+ if (answers.name && answers.name !== provider.name) updates.name = answers.name;
4063
+ if (answers.baseUrl && answers.baseUrl !== provider.baseUrl) updates.baseUrl = answers.baseUrl;
4064
+ if (answers.apiKey) updates.apiKey = answers.apiKey;
4065
+ if (Object.keys(updates).length === 0) {
4066
+ console.log(import_chalk15.default.gray("\n\u672A\u505A\u4EFB\u4F55\u4FEE\u6539\n"));
4067
+ return;
4068
+ }
4069
+ const updated = manager.edit(targetId, updates);
4070
+ console.log();
4071
+ console.log(import_chalk15.default.green("\u2705 \u7F16\u8F91\u6210\u529F"));
4072
+ console.log();
4073
+ console.log(` ${import_chalk15.default.bold(updated.name)} ${import_chalk15.default.blue("[Claude Code]")}`);
4074
+ console.log(` ${import_chalk15.default.gray(`ID: ${updated.id}`)}`);
4075
+ console.log(` ${import_chalk15.default.gray(`URL: ${updated.baseUrl}`)}`);
4076
+ console.log();
4077
+ } catch (error) {
4078
+ console.error(import_chalk15.default.red(`
4079
+ \u274C ${error.message}
4080
+ `));
4081
+ process.exit(1);
4082
+ }
4083
+ });
4084
+ }
4085
+
4086
+ // src/commands/claudecode/clone.ts
4087
+ var import_chalk16 = __toESM(require("chalk"));
4088
+ var import_inquirer11 = __toESM(require("inquirer"));
4089
+ function cloneCommand2(program2) {
4090
+ program2.command("clone [source-name] [new-name]").description("\u514B\u9686 Claude Code \u670D\u52A1\u5546").action(async (sourceName, newName) => {
4091
+ try {
4092
+ const manager = createClaudeCodeManager();
4093
+ const providers = manager.list();
4094
+ if (providers.length === 0) {
4095
+ console.log(import_chalk16.default.yellow("\n\u26A0\uFE0F \u6682\u65E0 Claude Code \u670D\u52A1\u5546\n"));
4096
+ return;
4097
+ }
4098
+ let sourceId;
4099
+ if (sourceName) {
4100
+ const provider = manager.findByName(sourceName);
4101
+ if (!provider) {
4102
+ throw new ProviderNotFoundError(sourceName);
4103
+ }
4104
+ sourceId = provider.id;
4105
+ } else {
4106
+ const { selectedId } = await import_inquirer11.default.prompt([
4107
+ {
4108
+ type: "list",
4109
+ name: "selectedId",
4110
+ message: "\u9009\u62E9\u8981\u514B\u9686\u7684\u670D\u52A1\u5546:",
4111
+ choices: providers.map((p) => ({
4112
+ name: `${p.name} - ${p.baseUrl}`,
4113
+ value: p.id
4114
+ }))
4115
+ }
4116
+ ]);
4117
+ sourceId = selectedId;
4118
+ }
4119
+ const source = manager.get(sourceId);
4120
+ let cloned;
4121
+ if (newName) {
4122
+ cloned = manager.clone(sourceId, newName);
4123
+ } else {
4124
+ console.log(import_chalk16.default.blue(`
4125
+ \u514B\u9686\u81EA: ${source.name}
4126
+ `));
4127
+ const input = await promptProviderForm({
4128
+ name: `${source.name}\uFF08\u526F\u672C\uFF09`,
4129
+ baseUrl: source.baseUrl,
4130
+ apiKey: source.apiKey
4131
+ });
4132
+ cloned = manager.add(input);
4133
+ }
4134
+ console.log();
4135
+ console.log(import_chalk16.default.green("\u2705 \u514B\u9686\u6210\u529F"));
4136
+ console.log();
4137
+ console.log(` ${import_chalk16.default.bold(cloned.name)} ${import_chalk16.default.blue("[Claude Code]")}`);
4138
+ console.log(` ${import_chalk16.default.gray(`ID: ${cloned.id}`)}`);
4139
+ console.log(` ${import_chalk16.default.gray(`URL: ${cloned.baseUrl}`)}`);
4140
+ console.log();
4141
+ } catch (error) {
4142
+ console.error(import_chalk16.default.red(`
4143
+ \u274C ${error.message}
4144
+ `));
4145
+ process.exit(1);
4146
+ }
4147
+ });
4148
+ }
4149
+
4150
+ // src/commands/claudecode/index.ts
4151
+ function createClaudeCodeCommands(program2) {
4152
+ addCommand2(program2);
4153
+ listCommand2(program2);
4154
+ useCommand2(program2);
4155
+ currentCommand2(program2);
4156
+ removeCommand2(program2);
4157
+ editCommand2(program2);
4158
+ cloneCommand2(program2);
4159
+ }
4160
+
4161
+ // src/index.ts
4162
+ if (process.env.NODE_ENV === "development") {
4163
+ console.log(import_chalk17.default.gray("\n[\u5F00\u53D1\u6A21\u5F0F] \u914D\u7F6E\u76EE\u5F55:"));
4164
+ console.log(import_chalk17.default.gray(` ccman: ${getCcmanDir()}`));
4165
+ console.log(import_chalk17.default.gray(` codex: ${getCodexDir()}`));
4166
+ console.log(import_chalk17.default.gray(` claude: ${getClaudeDir()}`));
4167
+ console.log();
4168
+ }
4169
+ var program = new import_commander.Command();
4170
+ program.name("ccman").description("Codex/Claude Code API \u670D\u52A1\u5546\u914D\u7F6E\u7BA1\u7406\u5DE5\u5177").version(VERSION).showHelpAfterError(false).exitOverride((err) => {
4171
+ if (err.code === "commander.helpDisplayed" || err.code === "commander.version") {
4172
+ process.exit(0);
4173
+ }
4174
+ throw err;
4175
+ });
4176
+ var cx = program.command("cx").description("\u7BA1\u7406 Codex \u670D\u52A1\u5546");
4177
+ createCodexCommands(cx);
4178
+ cx.action(async () => {
4179
+ printLogo();
4180
+ await startCodexMenu();
4181
+ });
4182
+ var cc = program.command("cc").description("\u7BA1\u7406 Claude Code \u670D\u52A1\u5546");
4183
+ createClaudeCodeCommands(cc);
4184
+ cc.action(async () => {
4185
+ printLogo();
4186
+ await startClaudeCodeMenu();
4187
+ });
4188
+ (async () => {
4189
+ if (!process.argv.slice(2).length) {
4190
+ printLogo();
4191
+ await startMainMenu();
4192
+ } else {
4193
+ program.parse(process.argv);
4194
+ }
4195
+ })();