siluzan-website-cli 1.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,4192 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+
28
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/constants.js
29
+ var require_constants = __commonJS({
30
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/constants.js"(exports, module) {
31
+ "use strict";
32
+ var SEMVER_SPEC_VERSION = "2.0.0";
33
+ var MAX_LENGTH = 256;
34
+ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
35
+ 9007199254740991;
36
+ var MAX_SAFE_COMPONENT_LENGTH = 16;
37
+ var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
38
+ var RELEASE_TYPES = [
39
+ "major",
40
+ "premajor",
41
+ "minor",
42
+ "preminor",
43
+ "patch",
44
+ "prepatch",
45
+ "prerelease"
46
+ ];
47
+ module.exports = {
48
+ MAX_LENGTH,
49
+ MAX_SAFE_COMPONENT_LENGTH,
50
+ MAX_SAFE_BUILD_LENGTH,
51
+ MAX_SAFE_INTEGER,
52
+ RELEASE_TYPES,
53
+ SEMVER_SPEC_VERSION,
54
+ FLAG_INCLUDE_PRERELEASE: 1,
55
+ FLAG_LOOSE: 2
56
+ };
57
+ }
58
+ });
59
+
60
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/debug.js
61
+ var require_debug = __commonJS({
62
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/debug.js"(exports, module) {
63
+ "use strict";
64
+ var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
65
+ };
66
+ module.exports = debug;
67
+ }
68
+ });
69
+
70
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/re.js
71
+ var require_re = __commonJS({
72
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/re.js"(exports, module) {
73
+ "use strict";
74
+ var {
75
+ MAX_SAFE_COMPONENT_LENGTH,
76
+ MAX_SAFE_BUILD_LENGTH,
77
+ MAX_LENGTH
78
+ } = require_constants();
79
+ var debug = require_debug();
80
+ exports = module.exports = {};
81
+ var re = exports.re = [];
82
+ var safeRe = exports.safeRe = [];
83
+ var src = exports.src = [];
84
+ var safeSrc = exports.safeSrc = [];
85
+ var t = exports.t = {};
86
+ var R = 0;
87
+ var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
88
+ var safeRegexReplacements = [
89
+ ["\\s", 1],
90
+ ["\\d", MAX_LENGTH],
91
+ [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
92
+ ];
93
+ var makeSafeRegex = (value) => {
94
+ for (const [token, max] of safeRegexReplacements) {
95
+ value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
96
+ }
97
+ return value;
98
+ };
99
+ var createToken = (name, value, isGlobal) => {
100
+ const safe = makeSafeRegex(value);
101
+ const index = R++;
102
+ debug(name, index, value);
103
+ t[name] = index;
104
+ src[index] = value;
105
+ safeSrc[index] = safe;
106
+ re[index] = new RegExp(value, isGlobal ? "g" : void 0);
107
+ safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
108
+ };
109
+ createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
110
+ createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
111
+ createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
112
+ createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
113
+ createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
114
+ createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`);
115
+ createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
116
+ createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
117
+ createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
118
+ createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
119
+ createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
120
+ createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
121
+ createToken("FULL", `^${src[t.FULLPLAIN]}$`);
122
+ createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
123
+ createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`);
124
+ createToken("GTLT", "((?:<|>)?=?)");
125
+ createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
126
+ createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
127
+ createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`);
128
+ createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`);
129
+ createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
130
+ createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
131
+ createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
132
+ createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
133
+ createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`);
134
+ createToken("COERCERTL", src[t.COERCE], true);
135
+ createToken("COERCERTLFULL", src[t.COERCEFULL], true);
136
+ createToken("LONETILDE", "(?:~>?)");
137
+ createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true);
138
+ exports.tildeTrimReplace = "$1~";
139
+ createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
140
+ createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
141
+ createToken("LONECARET", "(?:\\^)");
142
+ createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true);
143
+ exports.caretTrimReplace = "$1^";
144
+ createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
145
+ createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
146
+ createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
147
+ createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
148
+ createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
149
+ exports.comparatorTrimReplace = "$1$2$3";
150
+ createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`);
151
+ createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`);
152
+ createToken("STAR", "(<|>)?=?\\s*\\*");
153
+ createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
154
+ createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
155
+ }
156
+ });
157
+
158
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/parse-options.js
159
+ var require_parse_options = __commonJS({
160
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/parse-options.js"(exports, module) {
161
+ "use strict";
162
+ var looseOption = Object.freeze({ loose: true });
163
+ var emptyOpts = Object.freeze({});
164
+ var parseOptions = (options) => {
165
+ if (!options) {
166
+ return emptyOpts;
167
+ }
168
+ if (typeof options !== "object") {
169
+ return looseOption;
170
+ }
171
+ return options;
172
+ };
173
+ module.exports = parseOptions;
174
+ }
175
+ });
176
+
177
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/identifiers.js
178
+ var require_identifiers = __commonJS({
179
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/identifiers.js"(exports, module) {
180
+ "use strict";
181
+ var numeric = /^[0-9]+$/;
182
+ var compareIdentifiers = (a, b) => {
183
+ if (typeof a === "number" && typeof b === "number") {
184
+ return a === b ? 0 : a < b ? -1 : 1;
185
+ }
186
+ const anum = numeric.test(a);
187
+ const bnum = numeric.test(b);
188
+ if (anum && bnum) {
189
+ a = +a;
190
+ b = +b;
191
+ }
192
+ return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
193
+ };
194
+ var rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
195
+ module.exports = {
196
+ compareIdentifiers,
197
+ rcompareIdentifiers
198
+ };
199
+ }
200
+ });
201
+
202
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/semver.js
203
+ var require_semver = __commonJS({
204
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/semver.js"(exports, module) {
205
+ "use strict";
206
+ var debug = require_debug();
207
+ var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
208
+ var { safeRe: re, t } = require_re();
209
+ var parseOptions = require_parse_options();
210
+ var { compareIdentifiers } = require_identifiers();
211
+ var SemVer = class _SemVer {
212
+ constructor(version, options) {
213
+ options = parseOptions(options);
214
+ if (version instanceof _SemVer) {
215
+ if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
216
+ return version;
217
+ } else {
218
+ version = version.version;
219
+ }
220
+ } else if (typeof version !== "string") {
221
+ throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
222
+ }
223
+ if (version.length > MAX_LENGTH) {
224
+ throw new TypeError(
225
+ `version is longer than ${MAX_LENGTH} characters`
226
+ );
227
+ }
228
+ debug("SemVer", version, options);
229
+ this.options = options;
230
+ this.loose = !!options.loose;
231
+ this.includePrerelease = !!options.includePrerelease;
232
+ const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
233
+ if (!m) {
234
+ throw new TypeError(`Invalid Version: ${version}`);
235
+ }
236
+ this.raw = version;
237
+ this.major = +m[1];
238
+ this.minor = +m[2];
239
+ this.patch = +m[3];
240
+ if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
241
+ throw new TypeError("Invalid major version");
242
+ }
243
+ if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
244
+ throw new TypeError("Invalid minor version");
245
+ }
246
+ if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
247
+ throw new TypeError("Invalid patch version");
248
+ }
249
+ if (!m[4]) {
250
+ this.prerelease = [];
251
+ } else {
252
+ this.prerelease = m[4].split(".").map((id) => {
253
+ if (/^[0-9]+$/.test(id)) {
254
+ const num = +id;
255
+ if (num >= 0 && num < MAX_SAFE_INTEGER) {
256
+ return num;
257
+ }
258
+ }
259
+ return id;
260
+ });
261
+ }
262
+ this.build = m[5] ? m[5].split(".") : [];
263
+ this.format();
264
+ }
265
+ format() {
266
+ this.version = `${this.major}.${this.minor}.${this.patch}`;
267
+ if (this.prerelease.length) {
268
+ this.version += `-${this.prerelease.join(".")}`;
269
+ }
270
+ return this.version;
271
+ }
272
+ toString() {
273
+ return this.version;
274
+ }
275
+ compare(other) {
276
+ debug("SemVer.compare", this.version, this.options, other);
277
+ if (!(other instanceof _SemVer)) {
278
+ if (typeof other === "string" && other === this.version) {
279
+ return 0;
280
+ }
281
+ other = new _SemVer(other, this.options);
282
+ }
283
+ if (other.version === this.version) {
284
+ return 0;
285
+ }
286
+ return this.compareMain(other) || this.comparePre(other);
287
+ }
288
+ compareMain(other) {
289
+ if (!(other instanceof _SemVer)) {
290
+ other = new _SemVer(other, this.options);
291
+ }
292
+ if (this.major < other.major) {
293
+ return -1;
294
+ }
295
+ if (this.major > other.major) {
296
+ return 1;
297
+ }
298
+ if (this.minor < other.minor) {
299
+ return -1;
300
+ }
301
+ if (this.minor > other.minor) {
302
+ return 1;
303
+ }
304
+ if (this.patch < other.patch) {
305
+ return -1;
306
+ }
307
+ if (this.patch > other.patch) {
308
+ return 1;
309
+ }
310
+ return 0;
311
+ }
312
+ comparePre(other) {
313
+ if (!(other instanceof _SemVer)) {
314
+ other = new _SemVer(other, this.options);
315
+ }
316
+ if (this.prerelease.length && !other.prerelease.length) {
317
+ return -1;
318
+ } else if (!this.prerelease.length && other.prerelease.length) {
319
+ return 1;
320
+ } else if (!this.prerelease.length && !other.prerelease.length) {
321
+ return 0;
322
+ }
323
+ let i = 0;
324
+ do {
325
+ const a = this.prerelease[i];
326
+ const b = other.prerelease[i];
327
+ debug("prerelease compare", i, a, b);
328
+ if (a === void 0 && b === void 0) {
329
+ return 0;
330
+ } else if (b === void 0) {
331
+ return 1;
332
+ } else if (a === void 0) {
333
+ return -1;
334
+ } else if (a === b) {
335
+ continue;
336
+ } else {
337
+ return compareIdentifiers(a, b);
338
+ }
339
+ } while (++i);
340
+ }
341
+ compareBuild(other) {
342
+ if (!(other instanceof _SemVer)) {
343
+ other = new _SemVer(other, this.options);
344
+ }
345
+ let i = 0;
346
+ do {
347
+ const a = this.build[i];
348
+ const b = other.build[i];
349
+ debug("build compare", i, a, b);
350
+ if (a === void 0 && b === void 0) {
351
+ return 0;
352
+ } else if (b === void 0) {
353
+ return 1;
354
+ } else if (a === void 0) {
355
+ return -1;
356
+ } else if (a === b) {
357
+ continue;
358
+ } else {
359
+ return compareIdentifiers(a, b);
360
+ }
361
+ } while (++i);
362
+ }
363
+ // preminor will bump the version up to the next minor release, and immediately
364
+ // down to pre-release. premajor and prepatch work the same way.
365
+ inc(release, identifier, identifierBase) {
366
+ if (release.startsWith("pre")) {
367
+ if (!identifier && identifierBase === false) {
368
+ throw new Error("invalid increment argument: identifier is empty");
369
+ }
370
+ if (identifier) {
371
+ const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
372
+ if (!match || match[1] !== identifier) {
373
+ throw new Error(`invalid identifier: ${identifier}`);
374
+ }
375
+ }
376
+ }
377
+ switch (release) {
378
+ case "premajor":
379
+ this.prerelease.length = 0;
380
+ this.patch = 0;
381
+ this.minor = 0;
382
+ this.major++;
383
+ this.inc("pre", identifier, identifierBase);
384
+ break;
385
+ case "preminor":
386
+ this.prerelease.length = 0;
387
+ this.patch = 0;
388
+ this.minor++;
389
+ this.inc("pre", identifier, identifierBase);
390
+ break;
391
+ case "prepatch":
392
+ this.prerelease.length = 0;
393
+ this.inc("patch", identifier, identifierBase);
394
+ this.inc("pre", identifier, identifierBase);
395
+ break;
396
+ // If the input is a non-prerelease version, this acts the same as
397
+ // prepatch.
398
+ case "prerelease":
399
+ if (this.prerelease.length === 0) {
400
+ this.inc("patch", identifier, identifierBase);
401
+ }
402
+ this.inc("pre", identifier, identifierBase);
403
+ break;
404
+ case "release":
405
+ if (this.prerelease.length === 0) {
406
+ throw new Error(`version ${this.raw} is not a prerelease`);
407
+ }
408
+ this.prerelease.length = 0;
409
+ break;
410
+ case "major":
411
+ if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
412
+ this.major++;
413
+ }
414
+ this.minor = 0;
415
+ this.patch = 0;
416
+ this.prerelease = [];
417
+ break;
418
+ case "minor":
419
+ if (this.patch !== 0 || this.prerelease.length === 0) {
420
+ this.minor++;
421
+ }
422
+ this.patch = 0;
423
+ this.prerelease = [];
424
+ break;
425
+ case "patch":
426
+ if (this.prerelease.length === 0) {
427
+ this.patch++;
428
+ }
429
+ this.prerelease = [];
430
+ break;
431
+ // This probably shouldn't be used publicly.
432
+ // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
433
+ case "pre": {
434
+ const base = Number(identifierBase) ? 1 : 0;
435
+ if (this.prerelease.length === 0) {
436
+ this.prerelease = [base];
437
+ } else {
438
+ let i = this.prerelease.length;
439
+ while (--i >= 0) {
440
+ if (typeof this.prerelease[i] === "number") {
441
+ this.prerelease[i]++;
442
+ i = -2;
443
+ }
444
+ }
445
+ if (i === -1) {
446
+ if (identifier === this.prerelease.join(".") && identifierBase === false) {
447
+ throw new Error("invalid increment argument: identifier already exists");
448
+ }
449
+ this.prerelease.push(base);
450
+ }
451
+ }
452
+ if (identifier) {
453
+ let prerelease = [identifier, base];
454
+ if (identifierBase === false) {
455
+ prerelease = [identifier];
456
+ }
457
+ if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
458
+ if (isNaN(this.prerelease[1])) {
459
+ this.prerelease = prerelease;
460
+ }
461
+ } else {
462
+ this.prerelease = prerelease;
463
+ }
464
+ }
465
+ break;
466
+ }
467
+ default:
468
+ throw new Error(`invalid increment argument: ${release}`);
469
+ }
470
+ this.raw = this.format();
471
+ if (this.build.length) {
472
+ this.raw += `+${this.build.join(".")}`;
473
+ }
474
+ return this;
475
+ }
476
+ };
477
+ module.exports = SemVer;
478
+ }
479
+ });
480
+
481
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/parse.js
482
+ var require_parse = __commonJS({
483
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/parse.js"(exports, module) {
484
+ "use strict";
485
+ var SemVer = require_semver();
486
+ var parse = (version, options, throwErrors = false) => {
487
+ if (version instanceof SemVer) {
488
+ return version;
489
+ }
490
+ try {
491
+ return new SemVer(version, options);
492
+ } catch (er) {
493
+ if (!throwErrors) {
494
+ return null;
495
+ }
496
+ throw er;
497
+ }
498
+ };
499
+ module.exports = parse;
500
+ }
501
+ });
502
+
503
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/valid.js
504
+ var require_valid = __commonJS({
505
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/valid.js"(exports, module) {
506
+ "use strict";
507
+ var parse = require_parse();
508
+ var valid = (version, options) => {
509
+ const v = parse(version, options);
510
+ return v ? v.version : null;
511
+ };
512
+ module.exports = valid;
513
+ }
514
+ });
515
+
516
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/clean.js
517
+ var require_clean = __commonJS({
518
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/clean.js"(exports, module) {
519
+ "use strict";
520
+ var parse = require_parse();
521
+ var clean = (version, options) => {
522
+ const s = parse(version.trim().replace(/^[=v]+/, ""), options);
523
+ return s ? s.version : null;
524
+ };
525
+ module.exports = clean;
526
+ }
527
+ });
528
+
529
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/inc.js
530
+ var require_inc = __commonJS({
531
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/inc.js"(exports, module) {
532
+ "use strict";
533
+ var SemVer = require_semver();
534
+ var inc = (version, release, options, identifier, identifierBase) => {
535
+ if (typeof options === "string") {
536
+ identifierBase = identifier;
537
+ identifier = options;
538
+ options = void 0;
539
+ }
540
+ try {
541
+ return new SemVer(
542
+ version instanceof SemVer ? version.version : version,
543
+ options
544
+ ).inc(release, identifier, identifierBase).version;
545
+ } catch (er) {
546
+ return null;
547
+ }
548
+ };
549
+ module.exports = inc;
550
+ }
551
+ });
552
+
553
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/diff.js
554
+ var require_diff = __commonJS({
555
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/diff.js"(exports, module) {
556
+ "use strict";
557
+ var parse = require_parse();
558
+ var diff = (version1, version2) => {
559
+ const v1 = parse(version1, null, true);
560
+ const v2 = parse(version2, null, true);
561
+ const comparison = v1.compare(v2);
562
+ if (comparison === 0) {
563
+ return null;
564
+ }
565
+ const v1Higher = comparison > 0;
566
+ const highVersion = v1Higher ? v1 : v2;
567
+ const lowVersion = v1Higher ? v2 : v1;
568
+ const highHasPre = !!highVersion.prerelease.length;
569
+ const lowHasPre = !!lowVersion.prerelease.length;
570
+ if (lowHasPre && !highHasPre) {
571
+ if (!lowVersion.patch && !lowVersion.minor) {
572
+ return "major";
573
+ }
574
+ if (lowVersion.compareMain(highVersion) === 0) {
575
+ if (lowVersion.minor && !lowVersion.patch) {
576
+ return "minor";
577
+ }
578
+ return "patch";
579
+ }
580
+ }
581
+ const prefix = highHasPre ? "pre" : "";
582
+ if (v1.major !== v2.major) {
583
+ return prefix + "major";
584
+ }
585
+ if (v1.minor !== v2.minor) {
586
+ return prefix + "minor";
587
+ }
588
+ if (v1.patch !== v2.patch) {
589
+ return prefix + "patch";
590
+ }
591
+ return "prerelease";
592
+ };
593
+ module.exports = diff;
594
+ }
595
+ });
596
+
597
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/major.js
598
+ var require_major = __commonJS({
599
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/major.js"(exports, module) {
600
+ "use strict";
601
+ var SemVer = require_semver();
602
+ var major = (a, loose) => new SemVer(a, loose).major;
603
+ module.exports = major;
604
+ }
605
+ });
606
+
607
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/minor.js
608
+ var require_minor = __commonJS({
609
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/minor.js"(exports, module) {
610
+ "use strict";
611
+ var SemVer = require_semver();
612
+ var minor = (a, loose) => new SemVer(a, loose).minor;
613
+ module.exports = minor;
614
+ }
615
+ });
616
+
617
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/patch.js
618
+ var require_patch = __commonJS({
619
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/patch.js"(exports, module) {
620
+ "use strict";
621
+ var SemVer = require_semver();
622
+ var patch = (a, loose) => new SemVer(a, loose).patch;
623
+ module.exports = patch;
624
+ }
625
+ });
626
+
627
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/prerelease.js
628
+ var require_prerelease = __commonJS({
629
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/prerelease.js"(exports, module) {
630
+ "use strict";
631
+ var parse = require_parse();
632
+ var prerelease = (version, options) => {
633
+ const parsed = parse(version, options);
634
+ return parsed && parsed.prerelease.length ? parsed.prerelease : null;
635
+ };
636
+ module.exports = prerelease;
637
+ }
638
+ });
639
+
640
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare.js
641
+ var require_compare = __commonJS({
642
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare.js"(exports, module) {
643
+ "use strict";
644
+ var SemVer = require_semver();
645
+ var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
646
+ module.exports = compare;
647
+ }
648
+ });
649
+
650
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rcompare.js
651
+ var require_rcompare = __commonJS({
652
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rcompare.js"(exports, module) {
653
+ "use strict";
654
+ var compare = require_compare();
655
+ var rcompare = (a, b, loose) => compare(b, a, loose);
656
+ module.exports = rcompare;
657
+ }
658
+ });
659
+
660
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare-loose.js
661
+ var require_compare_loose = __commonJS({
662
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare-loose.js"(exports, module) {
663
+ "use strict";
664
+ var compare = require_compare();
665
+ var compareLoose = (a, b) => compare(a, b, true);
666
+ module.exports = compareLoose;
667
+ }
668
+ });
669
+
670
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare-build.js
671
+ var require_compare_build = __commonJS({
672
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/compare-build.js"(exports, module) {
673
+ "use strict";
674
+ var SemVer = require_semver();
675
+ var compareBuild = (a, b, loose) => {
676
+ const versionA = new SemVer(a, loose);
677
+ const versionB = new SemVer(b, loose);
678
+ return versionA.compare(versionB) || versionA.compareBuild(versionB);
679
+ };
680
+ module.exports = compareBuild;
681
+ }
682
+ });
683
+
684
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/sort.js
685
+ var require_sort = __commonJS({
686
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/sort.js"(exports, module) {
687
+ "use strict";
688
+ var compareBuild = require_compare_build();
689
+ var sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
690
+ module.exports = sort;
691
+ }
692
+ });
693
+
694
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rsort.js
695
+ var require_rsort = __commonJS({
696
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/rsort.js"(exports, module) {
697
+ "use strict";
698
+ var compareBuild = require_compare_build();
699
+ var rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
700
+ module.exports = rsort;
701
+ }
702
+ });
703
+
704
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/gt.js
705
+ var require_gt = __commonJS({
706
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/gt.js"(exports, module) {
707
+ "use strict";
708
+ var compare = require_compare();
709
+ var gt = (a, b, loose) => compare(a, b, loose) > 0;
710
+ module.exports = gt;
711
+ }
712
+ });
713
+
714
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/lt.js
715
+ var require_lt = __commonJS({
716
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/lt.js"(exports, module) {
717
+ "use strict";
718
+ var compare = require_compare();
719
+ var lt = (a, b, loose) => compare(a, b, loose) < 0;
720
+ module.exports = lt;
721
+ }
722
+ });
723
+
724
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/eq.js
725
+ var require_eq = __commonJS({
726
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/eq.js"(exports, module) {
727
+ "use strict";
728
+ var compare = require_compare();
729
+ var eq = (a, b, loose) => compare(a, b, loose) === 0;
730
+ module.exports = eq;
731
+ }
732
+ });
733
+
734
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/neq.js
735
+ var require_neq = __commonJS({
736
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/neq.js"(exports, module) {
737
+ "use strict";
738
+ var compare = require_compare();
739
+ var neq = (a, b, loose) => compare(a, b, loose) !== 0;
740
+ module.exports = neq;
741
+ }
742
+ });
743
+
744
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/gte.js
745
+ var require_gte = __commonJS({
746
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/gte.js"(exports, module) {
747
+ "use strict";
748
+ var compare = require_compare();
749
+ var gte = (a, b, loose) => compare(a, b, loose) >= 0;
750
+ module.exports = gte;
751
+ }
752
+ });
753
+
754
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/lte.js
755
+ var require_lte = __commonJS({
756
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/lte.js"(exports, module) {
757
+ "use strict";
758
+ var compare = require_compare();
759
+ var lte = (a, b, loose) => compare(a, b, loose) <= 0;
760
+ module.exports = lte;
761
+ }
762
+ });
763
+
764
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/cmp.js
765
+ var require_cmp = __commonJS({
766
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/cmp.js"(exports, module) {
767
+ "use strict";
768
+ var eq = require_eq();
769
+ var neq = require_neq();
770
+ var gt = require_gt();
771
+ var gte = require_gte();
772
+ var lt = require_lt();
773
+ var lte = require_lte();
774
+ var cmp = (a, op, b, loose) => {
775
+ switch (op) {
776
+ case "===":
777
+ if (typeof a === "object") {
778
+ a = a.version;
779
+ }
780
+ if (typeof b === "object") {
781
+ b = b.version;
782
+ }
783
+ return a === b;
784
+ case "!==":
785
+ if (typeof a === "object") {
786
+ a = a.version;
787
+ }
788
+ if (typeof b === "object") {
789
+ b = b.version;
790
+ }
791
+ return a !== b;
792
+ case "":
793
+ case "=":
794
+ case "==":
795
+ return eq(a, b, loose);
796
+ case "!=":
797
+ return neq(a, b, loose);
798
+ case ">":
799
+ return gt(a, b, loose);
800
+ case ">=":
801
+ return gte(a, b, loose);
802
+ case "<":
803
+ return lt(a, b, loose);
804
+ case "<=":
805
+ return lte(a, b, loose);
806
+ default:
807
+ throw new TypeError(`Invalid operator: ${op}`);
808
+ }
809
+ };
810
+ module.exports = cmp;
811
+ }
812
+ });
813
+
814
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/coerce.js
815
+ var require_coerce = __commonJS({
816
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/coerce.js"(exports, module) {
817
+ "use strict";
818
+ var SemVer = require_semver();
819
+ var parse = require_parse();
820
+ var { safeRe: re, t } = require_re();
821
+ var coerce = (version, options) => {
822
+ if (version instanceof SemVer) {
823
+ return version;
824
+ }
825
+ if (typeof version === "number") {
826
+ version = String(version);
827
+ }
828
+ if (typeof version !== "string") {
829
+ return null;
830
+ }
831
+ options = options || {};
832
+ let match = null;
833
+ if (!options.rtl) {
834
+ match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
835
+ } else {
836
+ const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
837
+ let next;
838
+ while ((next = coerceRtlRegex.exec(version)) && (!match || match.index + match[0].length !== version.length)) {
839
+ if (!match || next.index + next[0].length !== match.index + match[0].length) {
840
+ match = next;
841
+ }
842
+ coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
843
+ }
844
+ coerceRtlRegex.lastIndex = -1;
845
+ }
846
+ if (match === null) {
847
+ return null;
848
+ }
849
+ const major = match[2];
850
+ const minor = match[3] || "0";
851
+ const patch = match[4] || "0";
852
+ const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "";
853
+ const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
854
+ return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
855
+ };
856
+ module.exports = coerce;
857
+ }
858
+ });
859
+
860
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/lrucache.js
861
+ var require_lrucache = __commonJS({
862
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/lrucache.js"(exports, module) {
863
+ "use strict";
864
+ var LRUCache = class {
865
+ constructor() {
866
+ this.max = 1e3;
867
+ this.map = /* @__PURE__ */ new Map();
868
+ }
869
+ get(key) {
870
+ const value = this.map.get(key);
871
+ if (value === void 0) {
872
+ return void 0;
873
+ } else {
874
+ this.map.delete(key);
875
+ this.map.set(key, value);
876
+ return value;
877
+ }
878
+ }
879
+ delete(key) {
880
+ return this.map.delete(key);
881
+ }
882
+ set(key, value) {
883
+ const deleted = this.delete(key);
884
+ if (!deleted && value !== void 0) {
885
+ if (this.map.size >= this.max) {
886
+ const firstKey = this.map.keys().next().value;
887
+ this.delete(firstKey);
888
+ }
889
+ this.map.set(key, value);
890
+ }
891
+ return this;
892
+ }
893
+ };
894
+ module.exports = LRUCache;
895
+ }
896
+ });
897
+
898
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/range.js
899
+ var require_range = __commonJS({
900
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/range.js"(exports, module) {
901
+ "use strict";
902
+ var SPACE_CHARACTERS = /\s+/g;
903
+ var Range = class _Range {
904
+ constructor(range, options) {
905
+ options = parseOptions(options);
906
+ if (range instanceof _Range) {
907
+ if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
908
+ return range;
909
+ } else {
910
+ return new _Range(range.raw, options);
911
+ }
912
+ }
913
+ if (range instanceof Comparator) {
914
+ this.raw = range.value;
915
+ this.set = [[range]];
916
+ this.formatted = void 0;
917
+ return this;
918
+ }
919
+ this.options = options;
920
+ this.loose = !!options.loose;
921
+ this.includePrerelease = !!options.includePrerelease;
922
+ this.raw = range.trim().replace(SPACE_CHARACTERS, " ");
923
+ this.set = this.raw.split("||").map((r) => this.parseRange(r.trim())).filter((c) => c.length);
924
+ if (!this.set.length) {
925
+ throw new TypeError(`Invalid SemVer Range: ${this.raw}`);
926
+ }
927
+ if (this.set.length > 1) {
928
+ const first = this.set[0];
929
+ this.set = this.set.filter((c) => !isNullSet(c[0]));
930
+ if (this.set.length === 0) {
931
+ this.set = [first];
932
+ } else if (this.set.length > 1) {
933
+ for (const c of this.set) {
934
+ if (c.length === 1 && isAny(c[0])) {
935
+ this.set = [c];
936
+ break;
937
+ }
938
+ }
939
+ }
940
+ }
941
+ this.formatted = void 0;
942
+ }
943
+ get range() {
944
+ if (this.formatted === void 0) {
945
+ this.formatted = "";
946
+ for (let i = 0; i < this.set.length; i++) {
947
+ if (i > 0) {
948
+ this.formatted += "||";
949
+ }
950
+ const comps = this.set[i];
951
+ for (let k = 0; k < comps.length; k++) {
952
+ if (k > 0) {
953
+ this.formatted += " ";
954
+ }
955
+ this.formatted += comps[k].toString().trim();
956
+ }
957
+ }
958
+ }
959
+ return this.formatted;
960
+ }
961
+ format() {
962
+ return this.range;
963
+ }
964
+ toString() {
965
+ return this.range;
966
+ }
967
+ parseRange(range) {
968
+ const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
969
+ const memoKey = memoOpts + ":" + range;
970
+ const cached = cache.get(memoKey);
971
+ if (cached) {
972
+ return cached;
973
+ }
974
+ const loose = this.options.loose;
975
+ const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
976
+ range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
977
+ debug("hyphen replace", range);
978
+ range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
979
+ debug("comparator trim", range);
980
+ range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
981
+ debug("tilde trim", range);
982
+ range = range.replace(re[t.CARETTRIM], caretTrimReplace);
983
+ debug("caret trim", range);
984
+ let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options));
985
+ if (loose) {
986
+ rangeList = rangeList.filter((comp) => {
987
+ debug("loose invalid filter", comp, this.options);
988
+ return !!comp.match(re[t.COMPARATORLOOSE]);
989
+ });
990
+ }
991
+ debug("range list", rangeList);
992
+ const rangeMap = /* @__PURE__ */ new Map();
993
+ const comparators = rangeList.map((comp) => new Comparator(comp, this.options));
994
+ for (const comp of comparators) {
995
+ if (isNullSet(comp)) {
996
+ return [comp];
997
+ }
998
+ rangeMap.set(comp.value, comp);
999
+ }
1000
+ if (rangeMap.size > 1 && rangeMap.has("")) {
1001
+ rangeMap.delete("");
1002
+ }
1003
+ const result = [...rangeMap.values()];
1004
+ cache.set(memoKey, result);
1005
+ return result;
1006
+ }
1007
+ intersects(range, options) {
1008
+ if (!(range instanceof _Range)) {
1009
+ throw new TypeError("a Range is required");
1010
+ }
1011
+ return this.set.some((thisComparators) => {
1012
+ return isSatisfiable(thisComparators, options) && range.set.some((rangeComparators) => {
1013
+ return isSatisfiable(rangeComparators, options) && thisComparators.every((thisComparator) => {
1014
+ return rangeComparators.every((rangeComparator) => {
1015
+ return thisComparator.intersects(rangeComparator, options);
1016
+ });
1017
+ });
1018
+ });
1019
+ });
1020
+ }
1021
+ // if ANY of the sets match ALL of its comparators, then pass
1022
+ test(version) {
1023
+ if (!version) {
1024
+ return false;
1025
+ }
1026
+ if (typeof version === "string") {
1027
+ try {
1028
+ version = new SemVer(version, this.options);
1029
+ } catch (er) {
1030
+ return false;
1031
+ }
1032
+ }
1033
+ for (let i = 0; i < this.set.length; i++) {
1034
+ if (testSet(this.set[i], version, this.options)) {
1035
+ return true;
1036
+ }
1037
+ }
1038
+ return false;
1039
+ }
1040
+ };
1041
+ module.exports = Range;
1042
+ var LRU = require_lrucache();
1043
+ var cache = new LRU();
1044
+ var parseOptions = require_parse_options();
1045
+ var Comparator = require_comparator();
1046
+ var debug = require_debug();
1047
+ var SemVer = require_semver();
1048
+ var {
1049
+ safeRe: re,
1050
+ t,
1051
+ comparatorTrimReplace,
1052
+ tildeTrimReplace,
1053
+ caretTrimReplace
1054
+ } = require_re();
1055
+ var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants();
1056
+ var isNullSet = (c) => c.value === "<0.0.0-0";
1057
+ var isAny = (c) => c.value === "";
1058
+ var isSatisfiable = (comparators, options) => {
1059
+ let result = true;
1060
+ const remainingComparators = comparators.slice();
1061
+ let testComparator = remainingComparators.pop();
1062
+ while (result && remainingComparators.length) {
1063
+ result = remainingComparators.every((otherComparator) => {
1064
+ return testComparator.intersects(otherComparator, options);
1065
+ });
1066
+ testComparator = remainingComparators.pop();
1067
+ }
1068
+ return result;
1069
+ };
1070
+ var parseComparator = (comp, options) => {
1071
+ comp = comp.replace(re[t.BUILD], "");
1072
+ debug("comp", comp, options);
1073
+ comp = replaceCarets(comp, options);
1074
+ debug("caret", comp);
1075
+ comp = replaceTildes(comp, options);
1076
+ debug("tildes", comp);
1077
+ comp = replaceXRanges(comp, options);
1078
+ debug("xrange", comp);
1079
+ comp = replaceStars(comp, options);
1080
+ debug("stars", comp);
1081
+ return comp;
1082
+ };
1083
+ var isX = (id) => !id || id.toLowerCase() === "x" || id === "*";
1084
+ var replaceTildes = (comp, options) => {
1085
+ return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
1086
+ };
1087
+ var replaceTilde = (comp, options) => {
1088
+ const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
1089
+ return comp.replace(r, (_, M, m, p, pr) => {
1090
+ debug("tilde", comp, _, M, m, p, pr);
1091
+ let ret;
1092
+ if (isX(M)) {
1093
+ ret = "";
1094
+ } else if (isX(m)) {
1095
+ ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
1096
+ } else if (isX(p)) {
1097
+ ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
1098
+ } else if (pr) {
1099
+ debug("replaceTilde pr", pr);
1100
+ ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
1101
+ } else {
1102
+ ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
1103
+ }
1104
+ debug("tilde return", ret);
1105
+ return ret;
1106
+ });
1107
+ };
1108
+ var replaceCarets = (comp, options) => {
1109
+ return comp.trim().split(/\s+/).map((c) => replaceCaret(c, options)).join(" ");
1110
+ };
1111
+ var replaceCaret = (comp, options) => {
1112
+ debug("caret", comp, options);
1113
+ const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
1114
+ const z = options.includePrerelease ? "-0" : "";
1115
+ return comp.replace(r, (_, M, m, p, pr) => {
1116
+ debug("caret", comp, _, M, m, p, pr);
1117
+ let ret;
1118
+ if (isX(M)) {
1119
+ ret = "";
1120
+ } else if (isX(m)) {
1121
+ ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
1122
+ } else if (isX(p)) {
1123
+ if (M === "0") {
1124
+ ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
1125
+ } else {
1126
+ ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
1127
+ }
1128
+ } else if (pr) {
1129
+ debug("replaceCaret pr", pr);
1130
+ if (M === "0") {
1131
+ if (m === "0") {
1132
+ ret = `>=${M}.${m}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
1133
+ } else {
1134
+ ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
1135
+ }
1136
+ } else {
1137
+ ret = `>=${M}.${m}.${p}-${pr} <${+M + 1}.0.0-0`;
1138
+ }
1139
+ } else {
1140
+ debug("no pr");
1141
+ if (M === "0") {
1142
+ if (m === "0") {
1143
+ ret = `>=${M}.${m}.${p}${z} <${M}.${m}.${+p + 1}-0`;
1144
+ } else {
1145
+ ret = `>=${M}.${m}.${p}${z} <${M}.${+m + 1}.0-0`;
1146
+ }
1147
+ } else {
1148
+ ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
1149
+ }
1150
+ }
1151
+ debug("caret return", ret);
1152
+ return ret;
1153
+ });
1154
+ };
1155
+ var replaceXRanges = (comp, options) => {
1156
+ debug("replaceXRanges", comp, options);
1157
+ return comp.split(/\s+/).map((c) => replaceXRange(c, options)).join(" ");
1158
+ };
1159
+ var replaceXRange = (comp, options) => {
1160
+ comp = comp.trim();
1161
+ const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
1162
+ return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
1163
+ debug("xRange", comp, ret, gtlt, M, m, p, pr);
1164
+ const xM = isX(M);
1165
+ const xm = xM || isX(m);
1166
+ const xp = xm || isX(p);
1167
+ const anyX = xp;
1168
+ if (gtlt === "=" && anyX) {
1169
+ gtlt = "";
1170
+ }
1171
+ pr = options.includePrerelease ? "-0" : "";
1172
+ if (xM) {
1173
+ if (gtlt === ">" || gtlt === "<") {
1174
+ ret = "<0.0.0-0";
1175
+ } else {
1176
+ ret = "*";
1177
+ }
1178
+ } else if (gtlt && anyX) {
1179
+ if (xm) {
1180
+ m = 0;
1181
+ }
1182
+ p = 0;
1183
+ if (gtlt === ">") {
1184
+ gtlt = ">=";
1185
+ if (xm) {
1186
+ M = +M + 1;
1187
+ m = 0;
1188
+ p = 0;
1189
+ } else {
1190
+ m = +m + 1;
1191
+ p = 0;
1192
+ }
1193
+ } else if (gtlt === "<=") {
1194
+ gtlt = "<";
1195
+ if (xm) {
1196
+ M = +M + 1;
1197
+ } else {
1198
+ m = +m + 1;
1199
+ }
1200
+ }
1201
+ if (gtlt === "<") {
1202
+ pr = "-0";
1203
+ }
1204
+ ret = `${gtlt + M}.${m}.${p}${pr}`;
1205
+ } else if (xm) {
1206
+ ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
1207
+ } else if (xp) {
1208
+ ret = `>=${M}.${m}.0${pr} <${M}.${+m + 1}.0-0`;
1209
+ }
1210
+ debug("xRange return", ret);
1211
+ return ret;
1212
+ });
1213
+ };
1214
+ var replaceStars = (comp, options) => {
1215
+ debug("replaceStars", comp, options);
1216
+ return comp.trim().replace(re[t.STAR], "");
1217
+ };
1218
+ var replaceGTE0 = (comp, options) => {
1219
+ debug("replaceGTE0", comp, options);
1220
+ return comp.trim().replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
1221
+ };
1222
+ var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr) => {
1223
+ if (isX(fM)) {
1224
+ from = "";
1225
+ } else if (isX(fm)) {
1226
+ from = `>=${fM}.0.0${incPr ? "-0" : ""}`;
1227
+ } else if (isX(fp)) {
1228
+ from = `>=${fM}.${fm}.0${incPr ? "-0" : ""}`;
1229
+ } else if (fpr) {
1230
+ from = `>=${from}`;
1231
+ } else {
1232
+ from = `>=${from}${incPr ? "-0" : ""}`;
1233
+ }
1234
+ if (isX(tM)) {
1235
+ to = "";
1236
+ } else if (isX(tm)) {
1237
+ to = `<${+tM + 1}.0.0-0`;
1238
+ } else if (isX(tp)) {
1239
+ to = `<${tM}.${+tm + 1}.0-0`;
1240
+ } else if (tpr) {
1241
+ to = `<=${tM}.${tm}.${tp}-${tpr}`;
1242
+ } else if (incPr) {
1243
+ to = `<${tM}.${tm}.${+tp + 1}-0`;
1244
+ } else {
1245
+ to = `<=${to}`;
1246
+ }
1247
+ return `${from} ${to}`.trim();
1248
+ };
1249
+ var testSet = (set, version, options) => {
1250
+ for (let i = 0; i < set.length; i++) {
1251
+ if (!set[i].test(version)) {
1252
+ return false;
1253
+ }
1254
+ }
1255
+ if (version.prerelease.length && !options.includePrerelease) {
1256
+ for (let i = 0; i < set.length; i++) {
1257
+ debug(set[i].semver);
1258
+ if (set[i].semver === Comparator.ANY) {
1259
+ continue;
1260
+ }
1261
+ if (set[i].semver.prerelease.length > 0) {
1262
+ const allowed = set[i].semver;
1263
+ if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) {
1264
+ return true;
1265
+ }
1266
+ }
1267
+ }
1268
+ return false;
1269
+ }
1270
+ return true;
1271
+ };
1272
+ }
1273
+ });
1274
+
1275
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/comparator.js
1276
+ var require_comparator = __commonJS({
1277
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/classes/comparator.js"(exports, module) {
1278
+ "use strict";
1279
+ var ANY = /* @__PURE__ */ Symbol("SemVer ANY");
1280
+ var Comparator = class _Comparator {
1281
+ static get ANY() {
1282
+ return ANY;
1283
+ }
1284
+ constructor(comp, options) {
1285
+ options = parseOptions(options);
1286
+ if (comp instanceof _Comparator) {
1287
+ if (comp.loose === !!options.loose) {
1288
+ return comp;
1289
+ } else {
1290
+ comp = comp.value;
1291
+ }
1292
+ }
1293
+ comp = comp.trim().split(/\s+/).join(" ");
1294
+ debug("comparator", comp, options);
1295
+ this.options = options;
1296
+ this.loose = !!options.loose;
1297
+ this.parse(comp);
1298
+ if (this.semver === ANY) {
1299
+ this.value = "";
1300
+ } else {
1301
+ this.value = this.operator + this.semver.version;
1302
+ }
1303
+ debug("comp", this);
1304
+ }
1305
+ parse(comp) {
1306
+ const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
1307
+ const m = comp.match(r);
1308
+ if (!m) {
1309
+ throw new TypeError(`Invalid comparator: ${comp}`);
1310
+ }
1311
+ this.operator = m[1] !== void 0 ? m[1] : "";
1312
+ if (this.operator === "=") {
1313
+ this.operator = "";
1314
+ }
1315
+ if (!m[2]) {
1316
+ this.semver = ANY;
1317
+ } else {
1318
+ this.semver = new SemVer(m[2], this.options.loose);
1319
+ }
1320
+ }
1321
+ toString() {
1322
+ return this.value;
1323
+ }
1324
+ test(version) {
1325
+ debug("Comparator.test", version, this.options.loose);
1326
+ if (this.semver === ANY || version === ANY) {
1327
+ return true;
1328
+ }
1329
+ if (typeof version === "string") {
1330
+ try {
1331
+ version = new SemVer(version, this.options);
1332
+ } catch (er) {
1333
+ return false;
1334
+ }
1335
+ }
1336
+ return cmp(version, this.operator, this.semver, this.options);
1337
+ }
1338
+ intersects(comp, options) {
1339
+ if (!(comp instanceof _Comparator)) {
1340
+ throw new TypeError("a Comparator is required");
1341
+ }
1342
+ if (this.operator === "") {
1343
+ if (this.value === "") {
1344
+ return true;
1345
+ }
1346
+ return new Range(comp.value, options).test(this.value);
1347
+ } else if (comp.operator === "") {
1348
+ if (comp.value === "") {
1349
+ return true;
1350
+ }
1351
+ return new Range(this.value, options).test(comp.semver);
1352
+ }
1353
+ options = parseOptions(options);
1354
+ if (options.includePrerelease && (this.value === "<0.0.0-0" || comp.value === "<0.0.0-0")) {
1355
+ return false;
1356
+ }
1357
+ if (!options.includePrerelease && (this.value.startsWith("<0.0.0") || comp.value.startsWith("<0.0.0"))) {
1358
+ return false;
1359
+ }
1360
+ if (this.operator.startsWith(">") && comp.operator.startsWith(">")) {
1361
+ return true;
1362
+ }
1363
+ if (this.operator.startsWith("<") && comp.operator.startsWith("<")) {
1364
+ return true;
1365
+ }
1366
+ if (this.semver.version === comp.semver.version && this.operator.includes("=") && comp.operator.includes("=")) {
1367
+ return true;
1368
+ }
1369
+ if (cmp(this.semver, "<", comp.semver, options) && this.operator.startsWith(">") && comp.operator.startsWith("<")) {
1370
+ return true;
1371
+ }
1372
+ if (cmp(this.semver, ">", comp.semver, options) && this.operator.startsWith("<") && comp.operator.startsWith(">")) {
1373
+ return true;
1374
+ }
1375
+ return false;
1376
+ }
1377
+ };
1378
+ module.exports = Comparator;
1379
+ var parseOptions = require_parse_options();
1380
+ var { safeRe: re, t } = require_re();
1381
+ var cmp = require_cmp();
1382
+ var debug = require_debug();
1383
+ var SemVer = require_semver();
1384
+ var Range = require_range();
1385
+ }
1386
+ });
1387
+
1388
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/satisfies.js
1389
+ var require_satisfies = __commonJS({
1390
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/functions/satisfies.js"(exports, module) {
1391
+ "use strict";
1392
+ var Range = require_range();
1393
+ var satisfies = (version, range, options) => {
1394
+ try {
1395
+ range = new Range(range, options);
1396
+ } catch (er) {
1397
+ return false;
1398
+ }
1399
+ return range.test(version);
1400
+ };
1401
+ module.exports = satisfies;
1402
+ }
1403
+ });
1404
+
1405
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/to-comparators.js
1406
+ var require_to_comparators = __commonJS({
1407
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/to-comparators.js"(exports, module) {
1408
+ "use strict";
1409
+ var Range = require_range();
1410
+ var toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" "));
1411
+ module.exports = toComparators;
1412
+ }
1413
+ });
1414
+
1415
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/max-satisfying.js
1416
+ var require_max_satisfying = __commonJS({
1417
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/max-satisfying.js"(exports, module) {
1418
+ "use strict";
1419
+ var SemVer = require_semver();
1420
+ var Range = require_range();
1421
+ var maxSatisfying = (versions, range, options) => {
1422
+ let max = null;
1423
+ let maxSV = null;
1424
+ let rangeObj = null;
1425
+ try {
1426
+ rangeObj = new Range(range, options);
1427
+ } catch (er) {
1428
+ return null;
1429
+ }
1430
+ versions.forEach((v) => {
1431
+ if (rangeObj.test(v)) {
1432
+ if (!max || maxSV.compare(v) === -1) {
1433
+ max = v;
1434
+ maxSV = new SemVer(max, options);
1435
+ }
1436
+ }
1437
+ });
1438
+ return max;
1439
+ };
1440
+ module.exports = maxSatisfying;
1441
+ }
1442
+ });
1443
+
1444
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/min-satisfying.js
1445
+ var require_min_satisfying = __commonJS({
1446
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/min-satisfying.js"(exports, module) {
1447
+ "use strict";
1448
+ var SemVer = require_semver();
1449
+ var Range = require_range();
1450
+ var minSatisfying = (versions, range, options) => {
1451
+ let min = null;
1452
+ let minSV = null;
1453
+ let rangeObj = null;
1454
+ try {
1455
+ rangeObj = new Range(range, options);
1456
+ } catch (er) {
1457
+ return null;
1458
+ }
1459
+ versions.forEach((v) => {
1460
+ if (rangeObj.test(v)) {
1461
+ if (!min || minSV.compare(v) === 1) {
1462
+ min = v;
1463
+ minSV = new SemVer(min, options);
1464
+ }
1465
+ }
1466
+ });
1467
+ return min;
1468
+ };
1469
+ module.exports = minSatisfying;
1470
+ }
1471
+ });
1472
+
1473
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/min-version.js
1474
+ var require_min_version = __commonJS({
1475
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/min-version.js"(exports, module) {
1476
+ "use strict";
1477
+ var SemVer = require_semver();
1478
+ var Range = require_range();
1479
+ var gt = require_gt();
1480
+ var minVersion = (range, loose) => {
1481
+ range = new Range(range, loose);
1482
+ let minver = new SemVer("0.0.0");
1483
+ if (range.test(minver)) {
1484
+ return minver;
1485
+ }
1486
+ minver = new SemVer("0.0.0-0");
1487
+ if (range.test(minver)) {
1488
+ return minver;
1489
+ }
1490
+ minver = null;
1491
+ for (let i = 0; i < range.set.length; ++i) {
1492
+ const comparators = range.set[i];
1493
+ let setMin = null;
1494
+ comparators.forEach((comparator) => {
1495
+ const compver = new SemVer(comparator.semver.version);
1496
+ switch (comparator.operator) {
1497
+ case ">":
1498
+ if (compver.prerelease.length === 0) {
1499
+ compver.patch++;
1500
+ } else {
1501
+ compver.prerelease.push(0);
1502
+ }
1503
+ compver.raw = compver.format();
1504
+ /* fallthrough */
1505
+ case "":
1506
+ case ">=":
1507
+ if (!setMin || gt(compver, setMin)) {
1508
+ setMin = compver;
1509
+ }
1510
+ break;
1511
+ case "<":
1512
+ case "<=":
1513
+ break;
1514
+ /* istanbul ignore next */
1515
+ default:
1516
+ throw new Error(`Unexpected operation: ${comparator.operator}`);
1517
+ }
1518
+ });
1519
+ if (setMin && (!minver || gt(minver, setMin))) {
1520
+ minver = setMin;
1521
+ }
1522
+ }
1523
+ if (minver && range.test(minver)) {
1524
+ return minver;
1525
+ }
1526
+ return null;
1527
+ };
1528
+ module.exports = minVersion;
1529
+ }
1530
+ });
1531
+
1532
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/valid.js
1533
+ var require_valid2 = __commonJS({
1534
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/valid.js"(exports, module) {
1535
+ "use strict";
1536
+ var Range = require_range();
1537
+ var validRange = (range, options) => {
1538
+ try {
1539
+ return new Range(range, options).range || "*";
1540
+ } catch (er) {
1541
+ return null;
1542
+ }
1543
+ };
1544
+ module.exports = validRange;
1545
+ }
1546
+ });
1547
+
1548
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/outside.js
1549
+ var require_outside = __commonJS({
1550
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/outside.js"(exports, module) {
1551
+ "use strict";
1552
+ var SemVer = require_semver();
1553
+ var Comparator = require_comparator();
1554
+ var { ANY } = Comparator;
1555
+ var Range = require_range();
1556
+ var satisfies = require_satisfies();
1557
+ var gt = require_gt();
1558
+ var lt = require_lt();
1559
+ var lte = require_lte();
1560
+ var gte = require_gte();
1561
+ var outside = (version, range, hilo, options) => {
1562
+ version = new SemVer(version, options);
1563
+ range = new Range(range, options);
1564
+ let gtfn, ltefn, ltfn, comp, ecomp;
1565
+ switch (hilo) {
1566
+ case ">":
1567
+ gtfn = gt;
1568
+ ltefn = lte;
1569
+ ltfn = lt;
1570
+ comp = ">";
1571
+ ecomp = ">=";
1572
+ break;
1573
+ case "<":
1574
+ gtfn = lt;
1575
+ ltefn = gte;
1576
+ ltfn = gt;
1577
+ comp = "<";
1578
+ ecomp = "<=";
1579
+ break;
1580
+ default:
1581
+ throw new TypeError('Must provide a hilo val of "<" or ">"');
1582
+ }
1583
+ if (satisfies(version, range, options)) {
1584
+ return false;
1585
+ }
1586
+ for (let i = 0; i < range.set.length; ++i) {
1587
+ const comparators = range.set[i];
1588
+ let high = null;
1589
+ let low = null;
1590
+ comparators.forEach((comparator) => {
1591
+ if (comparator.semver === ANY) {
1592
+ comparator = new Comparator(">=0.0.0");
1593
+ }
1594
+ high = high || comparator;
1595
+ low = low || comparator;
1596
+ if (gtfn(comparator.semver, high.semver, options)) {
1597
+ high = comparator;
1598
+ } else if (ltfn(comparator.semver, low.semver, options)) {
1599
+ low = comparator;
1600
+ }
1601
+ });
1602
+ if (high.operator === comp || high.operator === ecomp) {
1603
+ return false;
1604
+ }
1605
+ if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
1606
+ return false;
1607
+ } else if (low.operator === ecomp && ltfn(version, low.semver)) {
1608
+ return false;
1609
+ }
1610
+ }
1611
+ return true;
1612
+ };
1613
+ module.exports = outside;
1614
+ }
1615
+ });
1616
+
1617
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/gtr.js
1618
+ var require_gtr = __commonJS({
1619
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/gtr.js"(exports, module) {
1620
+ "use strict";
1621
+ var outside = require_outside();
1622
+ var gtr = (version, range, options) => outside(version, range, ">", options);
1623
+ module.exports = gtr;
1624
+ }
1625
+ });
1626
+
1627
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/ltr.js
1628
+ var require_ltr = __commonJS({
1629
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/ltr.js"(exports, module) {
1630
+ "use strict";
1631
+ var outside = require_outside();
1632
+ var ltr = (version, range, options) => outside(version, range, "<", options);
1633
+ module.exports = ltr;
1634
+ }
1635
+ });
1636
+
1637
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/intersects.js
1638
+ var require_intersects = __commonJS({
1639
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/intersects.js"(exports, module) {
1640
+ "use strict";
1641
+ var Range = require_range();
1642
+ var intersects = (r1, r2, options) => {
1643
+ r1 = new Range(r1, options);
1644
+ r2 = new Range(r2, options);
1645
+ return r1.intersects(r2, options);
1646
+ };
1647
+ module.exports = intersects;
1648
+ }
1649
+ });
1650
+
1651
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/simplify.js
1652
+ var require_simplify = __commonJS({
1653
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/simplify.js"(exports, module) {
1654
+ "use strict";
1655
+ var satisfies = require_satisfies();
1656
+ var compare = require_compare();
1657
+ module.exports = (versions, range, options) => {
1658
+ const set = [];
1659
+ let first = null;
1660
+ let prev = null;
1661
+ const v = versions.sort((a, b) => compare(a, b, options));
1662
+ for (const version of v) {
1663
+ const included = satisfies(version, range, options);
1664
+ if (included) {
1665
+ prev = version;
1666
+ if (!first) {
1667
+ first = version;
1668
+ }
1669
+ } else {
1670
+ if (prev) {
1671
+ set.push([first, prev]);
1672
+ }
1673
+ prev = null;
1674
+ first = null;
1675
+ }
1676
+ }
1677
+ if (first) {
1678
+ set.push([first, null]);
1679
+ }
1680
+ const ranges = [];
1681
+ for (const [min, max] of set) {
1682
+ if (min === max) {
1683
+ ranges.push(min);
1684
+ } else if (!max && min === v[0]) {
1685
+ ranges.push("*");
1686
+ } else if (!max) {
1687
+ ranges.push(`>=${min}`);
1688
+ } else if (min === v[0]) {
1689
+ ranges.push(`<=${max}`);
1690
+ } else {
1691
+ ranges.push(`${min} - ${max}`);
1692
+ }
1693
+ }
1694
+ const simplified = ranges.join(" || ");
1695
+ const original = typeof range.raw === "string" ? range.raw : String(range);
1696
+ return simplified.length < original.length ? simplified : range;
1697
+ };
1698
+ }
1699
+ });
1700
+
1701
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/subset.js
1702
+ var require_subset = __commonJS({
1703
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/ranges/subset.js"(exports, module) {
1704
+ "use strict";
1705
+ var Range = require_range();
1706
+ var Comparator = require_comparator();
1707
+ var { ANY } = Comparator;
1708
+ var satisfies = require_satisfies();
1709
+ var compare = require_compare();
1710
+ var subset = (sub, dom, options = {}) => {
1711
+ if (sub === dom) {
1712
+ return true;
1713
+ }
1714
+ sub = new Range(sub, options);
1715
+ dom = new Range(dom, options);
1716
+ let sawNonNull = false;
1717
+ OUTER: for (const simpleSub of sub.set) {
1718
+ for (const simpleDom of dom.set) {
1719
+ const isSub = simpleSubset(simpleSub, simpleDom, options);
1720
+ sawNonNull = sawNonNull || isSub !== null;
1721
+ if (isSub) {
1722
+ continue OUTER;
1723
+ }
1724
+ }
1725
+ if (sawNonNull) {
1726
+ return false;
1727
+ }
1728
+ }
1729
+ return true;
1730
+ };
1731
+ var minimumVersionWithPreRelease = [new Comparator(">=0.0.0-0")];
1732
+ var minimumVersion = [new Comparator(">=0.0.0")];
1733
+ var simpleSubset = (sub, dom, options) => {
1734
+ if (sub === dom) {
1735
+ return true;
1736
+ }
1737
+ if (sub.length === 1 && sub[0].semver === ANY) {
1738
+ if (dom.length === 1 && dom[0].semver === ANY) {
1739
+ return true;
1740
+ } else if (options.includePrerelease) {
1741
+ sub = minimumVersionWithPreRelease;
1742
+ } else {
1743
+ sub = minimumVersion;
1744
+ }
1745
+ }
1746
+ if (dom.length === 1 && dom[0].semver === ANY) {
1747
+ if (options.includePrerelease) {
1748
+ return true;
1749
+ } else {
1750
+ dom = minimumVersion;
1751
+ }
1752
+ }
1753
+ const eqSet = /* @__PURE__ */ new Set();
1754
+ let gt, lt;
1755
+ for (const c of sub) {
1756
+ if (c.operator === ">" || c.operator === ">=") {
1757
+ gt = higherGT(gt, c, options);
1758
+ } else if (c.operator === "<" || c.operator === "<=") {
1759
+ lt = lowerLT(lt, c, options);
1760
+ } else {
1761
+ eqSet.add(c.semver);
1762
+ }
1763
+ }
1764
+ if (eqSet.size > 1) {
1765
+ return null;
1766
+ }
1767
+ let gtltComp;
1768
+ if (gt && lt) {
1769
+ gtltComp = compare(gt.semver, lt.semver, options);
1770
+ if (gtltComp > 0) {
1771
+ return null;
1772
+ } else if (gtltComp === 0 && (gt.operator !== ">=" || lt.operator !== "<=")) {
1773
+ return null;
1774
+ }
1775
+ }
1776
+ for (const eq of eqSet) {
1777
+ if (gt && !satisfies(eq, String(gt), options)) {
1778
+ return null;
1779
+ }
1780
+ if (lt && !satisfies(eq, String(lt), options)) {
1781
+ return null;
1782
+ }
1783
+ for (const c of dom) {
1784
+ if (!satisfies(eq, String(c), options)) {
1785
+ return false;
1786
+ }
1787
+ }
1788
+ return true;
1789
+ }
1790
+ let higher, lower;
1791
+ let hasDomLT, hasDomGT;
1792
+ let needDomLTPre = lt && !options.includePrerelease && lt.semver.prerelease.length ? lt.semver : false;
1793
+ let needDomGTPre = gt && !options.includePrerelease && gt.semver.prerelease.length ? gt.semver : false;
1794
+ if (needDomLTPre && needDomLTPre.prerelease.length === 1 && lt.operator === "<" && needDomLTPre.prerelease[0] === 0) {
1795
+ needDomLTPre = false;
1796
+ }
1797
+ for (const c of dom) {
1798
+ hasDomGT = hasDomGT || c.operator === ">" || c.operator === ">=";
1799
+ hasDomLT = hasDomLT || c.operator === "<" || c.operator === "<=";
1800
+ if (gt) {
1801
+ if (needDomGTPre) {
1802
+ if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomGTPre.major && c.semver.minor === needDomGTPre.minor && c.semver.patch === needDomGTPre.patch) {
1803
+ needDomGTPre = false;
1804
+ }
1805
+ }
1806
+ if (c.operator === ">" || c.operator === ">=") {
1807
+ higher = higherGT(gt, c, options);
1808
+ if (higher === c && higher !== gt) {
1809
+ return false;
1810
+ }
1811
+ } else if (gt.operator === ">=" && !satisfies(gt.semver, String(c), options)) {
1812
+ return false;
1813
+ }
1814
+ }
1815
+ if (lt) {
1816
+ if (needDomLTPre) {
1817
+ if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomLTPre.major && c.semver.minor === needDomLTPre.minor && c.semver.patch === needDomLTPre.patch) {
1818
+ needDomLTPre = false;
1819
+ }
1820
+ }
1821
+ if (c.operator === "<" || c.operator === "<=") {
1822
+ lower = lowerLT(lt, c, options);
1823
+ if (lower === c && lower !== lt) {
1824
+ return false;
1825
+ }
1826
+ } else if (lt.operator === "<=" && !satisfies(lt.semver, String(c), options)) {
1827
+ return false;
1828
+ }
1829
+ }
1830
+ if (!c.operator && (lt || gt) && gtltComp !== 0) {
1831
+ return false;
1832
+ }
1833
+ }
1834
+ if (gt && hasDomLT && !lt && gtltComp !== 0) {
1835
+ return false;
1836
+ }
1837
+ if (lt && hasDomGT && !gt && gtltComp !== 0) {
1838
+ return false;
1839
+ }
1840
+ if (needDomGTPre || needDomLTPre) {
1841
+ return false;
1842
+ }
1843
+ return true;
1844
+ };
1845
+ var higherGT = (a, b, options) => {
1846
+ if (!a) {
1847
+ return b;
1848
+ }
1849
+ const comp = compare(a.semver, b.semver, options);
1850
+ return comp > 0 ? a : comp < 0 ? b : b.operator === ">" && a.operator === ">=" ? b : a;
1851
+ };
1852
+ var lowerLT = (a, b, options) => {
1853
+ if (!a) {
1854
+ return b;
1855
+ }
1856
+ const comp = compare(a.semver, b.semver, options);
1857
+ return comp < 0 ? a : comp > 0 ? b : b.operator === "<" && a.operator === "<=" ? b : a;
1858
+ };
1859
+ module.exports = subset;
1860
+ }
1861
+ });
1862
+
1863
+ // ../node_modules/.pnpm/semver@7.7.4/node_modules/semver/index.js
1864
+ var require_semver2 = __commonJS({
1865
+ "../node_modules/.pnpm/semver@7.7.4/node_modules/semver/index.js"(exports, module) {
1866
+ "use strict";
1867
+ var internalRe = require_re();
1868
+ var constants = require_constants();
1869
+ var SemVer = require_semver();
1870
+ var identifiers = require_identifiers();
1871
+ var parse = require_parse();
1872
+ var valid = require_valid();
1873
+ var clean = require_clean();
1874
+ var inc = require_inc();
1875
+ var diff = require_diff();
1876
+ var major = require_major();
1877
+ var minor = require_minor();
1878
+ var patch = require_patch();
1879
+ var prerelease = require_prerelease();
1880
+ var compare = require_compare();
1881
+ var rcompare = require_rcompare();
1882
+ var compareLoose = require_compare_loose();
1883
+ var compareBuild = require_compare_build();
1884
+ var sort = require_sort();
1885
+ var rsort = require_rsort();
1886
+ var gt = require_gt();
1887
+ var lt = require_lt();
1888
+ var eq = require_eq();
1889
+ var neq = require_neq();
1890
+ var gte = require_gte();
1891
+ var lte = require_lte();
1892
+ var cmp = require_cmp();
1893
+ var coerce = require_coerce();
1894
+ var Comparator = require_comparator();
1895
+ var Range = require_range();
1896
+ var satisfies = require_satisfies();
1897
+ var toComparators = require_to_comparators();
1898
+ var maxSatisfying = require_max_satisfying();
1899
+ var minSatisfying = require_min_satisfying();
1900
+ var minVersion = require_min_version();
1901
+ var validRange = require_valid2();
1902
+ var outside = require_outside();
1903
+ var gtr = require_gtr();
1904
+ var ltr = require_ltr();
1905
+ var intersects = require_intersects();
1906
+ var simplifyRange = require_simplify();
1907
+ var subset = require_subset();
1908
+ module.exports = {
1909
+ parse,
1910
+ valid,
1911
+ clean,
1912
+ inc,
1913
+ diff,
1914
+ major,
1915
+ minor,
1916
+ patch,
1917
+ prerelease,
1918
+ compare,
1919
+ rcompare,
1920
+ compareLoose,
1921
+ compareBuild,
1922
+ sort,
1923
+ rsort,
1924
+ gt,
1925
+ lt,
1926
+ eq,
1927
+ neq,
1928
+ gte,
1929
+ lte,
1930
+ cmp,
1931
+ coerce,
1932
+ Comparator,
1933
+ Range,
1934
+ satisfies,
1935
+ toComparators,
1936
+ maxSatisfying,
1937
+ minSatisfying,
1938
+ minVersion,
1939
+ validRange,
1940
+ outside,
1941
+ gtr,
1942
+ ltr,
1943
+ intersects,
1944
+ simplifyRange,
1945
+ subset,
1946
+ SemVer,
1947
+ re: internalRe.re,
1948
+ src: internalRe.src,
1949
+ tokens: internalRe.t,
1950
+ SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
1951
+ RELEASE_TYPES: constants.RELEASE_TYPES,
1952
+ compareIdentifiers: identifiers.compareIdentifiers,
1953
+ rcompareIdentifiers: identifiers.rcompareIdentifiers
1954
+ };
1955
+ }
1956
+ });
1957
+
1958
+ // ../common/dist/index.js
1959
+ import * as fs from "fs";
1960
+ import * as path from "path";
1961
+ import * as os from "os";
1962
+ import lockfile from "proper-lockfile";
1963
+ import * as https from "https";
1964
+ import * as http from "http";
1965
+ import * as zlib from "zlib";
1966
+ import { performance } from "perf_hooks";
1967
+ var import_semver = __toESM(require_semver2(), 1);
1968
+ import * as fs2 from "fs";
1969
+ import * as path2 from "path";
1970
+ import { fileURLToPath } from "url";
1971
+ import { spawn } from "child_process";
1972
+ import Table from "cli-table3";
1973
+ var SILUZAN_DIR = path.join(os.homedir(), ".siluzan");
1974
+ var CONFIG_FILE = path.join(SILUZAN_DIR, "config.json");
1975
+ function atomicWriteFileSync(targetPath, content, encoding = "utf8") {
1976
+ const dir = path.dirname(targetPath);
1977
+ const tmp = path.join(
1978
+ dir,
1979
+ `.${path.basename(targetPath)}.tmp.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2, 8)}`
1980
+ );
1981
+ try {
1982
+ fs.writeFileSync(tmp, content, encoding);
1983
+ fs.renameSync(tmp, targetPath);
1984
+ } catch (err) {
1985
+ try {
1986
+ fs.unlinkSync(tmp);
1987
+ } catch {
1988
+ }
1989
+ try {
1990
+ fs.writeFileSync(targetPath, content, encoding);
1991
+ } catch {
1992
+ throw err;
1993
+ }
1994
+ }
1995
+ }
1996
+ function readStr(raw, key) {
1997
+ const v = raw[key];
1998
+ return typeof v === "string" && v ? v : void 0;
1999
+ }
2000
+ function readSharedConfig() {
2001
+ if (!fs.existsSync(CONFIG_FILE)) {
2002
+ return { authToken: "" };
2003
+ }
2004
+ try {
2005
+ const raw = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8"));
2006
+ return {
2007
+ authToken: readStr(raw, "authToken") ?? "",
2008
+ apiKey: readStr(raw, "apiKey"),
2009
+ dataPermission: readStr(raw, "dataPermission")
2010
+ };
2011
+ } catch {
2012
+ return { authToken: "" };
2013
+ }
2014
+ }
2015
+ function writeSharedConfig(partial) {
2016
+ fs.mkdirSync(SILUZAN_DIR, { recursive: true });
2017
+ let existing = {};
2018
+ if (fs.existsSync(CONFIG_FILE)) {
2019
+ try {
2020
+ existing = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8"));
2021
+ } catch {
2022
+ }
2023
+ }
2024
+ const keys = ["authToken", "apiKey", "dataPermission"];
2025
+ for (const k of keys) {
2026
+ if (partial[k] !== void 0) existing[k] = partial[k];
2027
+ }
2028
+ atomicWriteFileSync(CONFIG_FILE, JSON.stringify(existing, null, 2));
2029
+ if (process.platform !== "win32") {
2030
+ try {
2031
+ fs.chmodSync(CONFIG_FILE, 384);
2032
+ } catch {
2033
+ console.warn("\u26A0\uFE0F \u672A\u80FD\u6536\u655B\u914D\u7F6E\u6587\u4EF6\u6743\u9650\uFF0C\u8BF7\u624B\u52A8\u6267\u884C\uFF1Achmod 600 " + CONFIG_FILE);
2034
+ }
2035
+ }
2036
+ }
2037
+ function readSharedConfigRaw() {
2038
+ if (!fs.existsSync(CONFIG_FILE)) return {};
2039
+ try {
2040
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8"));
2041
+ } catch {
2042
+ return {};
2043
+ }
2044
+ }
2045
+ var inProcessLockChain = Promise.resolve();
2046
+ async function mergeWriteSharedConfig(partial) {
2047
+ const next = inProcessLockChain.then(() => doMergeWriteOnce(partial));
2048
+ inProcessLockChain = next.catch(() => void 0);
2049
+ return next;
2050
+ }
2051
+ async function doMergeWriteOnce(partial) {
2052
+ fs.mkdirSync(SILUZAN_DIR, { recursive: true });
2053
+ if (!fs.existsSync(CONFIG_FILE)) {
2054
+ fs.writeFileSync(CONFIG_FILE, "{}", "utf8");
2055
+ if (process.platform !== "win32") {
2056
+ try {
2057
+ fs.chmodSync(CONFIG_FILE, 384);
2058
+ } catch {
2059
+ }
2060
+ }
2061
+ }
2062
+ const release = await lockfile.lock(CONFIG_FILE, {
2063
+ realpath: false,
2064
+ retries: { retries: 30, factor: 1.1, minTimeout: 50, maxTimeout: 600 },
2065
+ stale: 1e4
2066
+ });
2067
+ try {
2068
+ const existing = readSharedConfigRaw();
2069
+ const merged = { ...existing };
2070
+ for (const [k, v] of Object.entries(partial)) {
2071
+ if (v !== void 0) merged[k] = v;
2072
+ }
2073
+ atomicWriteFileSync(CONFIG_FILE, JSON.stringify(merged, null, 2));
2074
+ if (process.platform !== "win32") {
2075
+ try {
2076
+ fs.chmodSync(CONFIG_FILE, 384);
2077
+ } catch {
2078
+ }
2079
+ }
2080
+ } finally {
2081
+ await release();
2082
+ }
2083
+ }
2084
+ function clearSharedConfig() {
2085
+ writeSharedConfig({ authToken: "", apiKey: "" });
2086
+ }
2087
+ function maskSecret(s) {
2088
+ if (!s) return "(\u672A\u8BBE\u7F6E)";
2089
+ return s.length > 8 ? `${s.slice(0, 4)}****${s.slice(-4)}` : "****";
2090
+ }
2091
+ var ALLOWED_HOSTNAME_SUFFIXES = [
2092
+ "siluzan.com",
2093
+ "siluzan.cn",
2094
+ /** Google / TikTok / Facebook 等媒体网关域名(TSO 专用,CSO 不会主动产生但兼容写入) */
2095
+ "mysiluzan.com"
2096
+ ];
2097
+ function validateBaseUrl(raw) {
2098
+ let url;
2099
+ try {
2100
+ url = new URL(raw);
2101
+ } catch {
2102
+ return `\u4E0D\u662F\u5408\u6CD5 URL\uFF1A${raw}`;
2103
+ }
2104
+ if (url.protocol !== "https:") {
2105
+ return `\u5FC5\u987B\u4F7F\u7528 HTTPS\uFF0C\u5F53\u524D\u534F\u8BAE\uFF1A${url.protocol}`;
2106
+ }
2107
+ const hostname2 = url.hostname.toLowerCase();
2108
+ const ok = ALLOWED_HOSTNAME_SUFFIXES.some(
2109
+ (suffix) => hostname2 === suffix || hostname2.endsWith(`.${suffix}`)
2110
+ );
2111
+ if (!ok) {
2112
+ return `\u4E3B\u673A\u540D "${hostname2}" \u4E0D\u5728\u5141\u8BB8\u5217\u8868\uFF08${ALLOWED_HOSTNAME_SUFFIXES.join("\u3001")}\uFF09\u5185\u3002
2113
+ \u5982\u9700\u8FDE\u63A5\u81EA\u5B9A\u4E49\u90E8\u7F72\u7AEF\u70B9\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u6DFB\u52A0\u767D\u540D\u5355\u3002`;
2114
+ }
2115
+ return null;
2116
+ }
2117
+ var EXACT_ID_FIELD_NAMES = /* @__PURE__ */ new Set([
2118
+ "id",
2119
+ "entityId",
2120
+ "mediaCustomerId",
2121
+ "mediaAccountId",
2122
+ "mediaAccountGroupId",
2123
+ "loginCustomerId",
2124
+ "customerId",
2125
+ "accountId",
2126
+ "ownerAdvertiserId",
2127
+ "advertiserId",
2128
+ "agencyClientId",
2129
+ "externalMediaAccountTokenId",
2130
+ "shortId",
2131
+ "websiteDiagnoseId",
2132
+ "invitationId",
2133
+ "ruleId",
2134
+ "bcId",
2135
+ "bmId",
2136
+ "tradeNo",
2137
+ "billNo",
2138
+ "payNo",
2139
+ "checkingNo",
2140
+ "rechargeNo",
2141
+ "orderNo",
2142
+ "magKey",
2143
+ "managedByStewardId",
2144
+ "relyCustomerId",
2145
+ "createdBy",
2146
+ "lastChangedBy",
2147
+ "userId"
2148
+ ]);
2149
+ function isIdFieldName(key) {
2150
+ if (!key) return false;
2151
+ if (EXACT_ID_FIELD_NAMES.has(key)) return true;
2152
+ if (/Ids$/.test(key)) return true;
2153
+ if (/Id$/.test(key)) return true;
2154
+ return false;
2155
+ }
2156
+ function numberToIdString(n) {
2157
+ if (!Number.isFinite(n)) return String(n);
2158
+ if (Number.isInteger(n)) {
2159
+ return n.toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: 0 });
2160
+ }
2161
+ return String(n);
2162
+ }
2163
+ function jsonParseReviverStringifyIds(key, value) {
2164
+ if (key && isIdFieldName(key) && typeof value === "number" && Number.isFinite(value)) {
2165
+ return numberToIdString(value);
2166
+ }
2167
+ return value;
2168
+ }
2169
+ function parseJsonWithStringIds(text) {
2170
+ return JSON.parse(text, jsonParseReviverStringifyIds);
2171
+ }
2172
+ function hasSiluzanAgentCredentials() {
2173
+ const apiKey = process.env.SILUZAN_API_KEY?.trim();
2174
+ const authToken = process.env.SILUZAN_AUTH_TOKEN?.trim();
2175
+ return Boolean(apiKey || authToken);
2176
+ }
2177
+ function isSiluzanAgentEnv() {
2178
+ const raw = process.env.IS_SILUZAN_AGENT_ENV?.trim().toLowerCase();
2179
+ return raw === "true" || raw === "1";
2180
+ }
2181
+ function skipAuthSetupInAgentEnv(commandLabel) {
2182
+ if (!isSiluzanAgentEnv()) return false;
2183
+ if (hasSiluzanAgentCredentials()) {
2184
+ console.log(
2185
+ `
2186
+ \u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\uFF0C\u51ED\u636E\u5DF2\u7531\u6C99\u7BB1\u6CE8\u5165\uFF0C\u65E0\u9700\u6267\u884C ${commandLabel}\u3002
2187
+ `
2188
+ );
2189
+ } else {
2190
+ console.log(
2191
+ `
2192
+ \u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\u3002
2193
+ ${commandLabel} \u5DF2\u8DF3\u8FC7\uFF1B\u8BF7\u7531 Agent \u6C99\u7BB1\u6CE8\u5165 SILUZAN_API_KEY \u6216 SILUZAN_AUTH_TOKEN\u3002
2194
+ `
2195
+ );
2196
+ }
2197
+ return true;
2198
+ }
2199
+ function trimOrUndefined(value) {
2200
+ const trimmed = value?.trim();
2201
+ return trimmed ? trimmed : void 0;
2202
+ }
2203
+ function resolveAgentEnvCredentials() {
2204
+ const envToken = trimOrUndefined(process.env.SILUZAN_AUTH_TOKEN);
2205
+ if (envToken) return { authToken: envToken, apiKey: void 0 };
2206
+ const envApiKey = trimOrUndefined(process.env.SILUZAN_API_KEY);
2207
+ if (envApiKey) return { authToken: "", apiKey: envApiKey };
2208
+ return { authToken: "", apiKey: void 0 };
2209
+ }
2210
+ function resolveSiluzanCredentials(opts) {
2211
+ if (isSiluzanAgentEnv()) {
2212
+ return resolveAgentEnvCredentials();
2213
+ }
2214
+ const apiKey = trimOrUndefined(process.env.SILUZAN_API_KEY) ?? trimOrUndefined(opts.configApiKey);
2215
+ const authToken = trimOrUndefined(opts.tokenArg) ?? trimOrUndefined(process.env.SILUZAN_AUTH_TOKEN) ?? trimOrUndefined(opts.configAuthToken) ?? "";
2216
+ return { authToken, apiKey };
2217
+ }
2218
+ function resolveRequestAuth(config) {
2219
+ if (isSiluzanAgentEnv()) {
2220
+ return resolveAgentEnvCredentials();
2221
+ }
2222
+ return { authToken: config.authToken, apiKey: config.apiKey };
2223
+ }
2224
+ function buildSiluzanAuthHeaders(config) {
2225
+ const auth = resolveRequestAuth(config);
2226
+ return auth.apiKey ? { "x-api-key": auth.apiKey } : { Authorization: `Bearer ${auth.authToken}` };
2227
+ }
2228
+ var SILUZAN_AGENT_COMPANY_SOURCE_TYPE = "Ctaiad";
2229
+ var DEERFLOW_AGENT_ENV = "DEERFLOW_AGENT";
2230
+ var _clientProduct = "siluzan-cli";
2231
+ var _resolveVersion;
2232
+ function getSiluzanClientProduct() {
2233
+ return _clientProduct;
2234
+ }
2235
+ function runtimeOverrideFromEnv() {
2236
+ const raw = process.env.SILUZAN_CLIENT_RUNTIME?.trim().toLowerCase();
2237
+ if (raw === "siluzan_agent" || raw === "agent" || raw === "cli") return raw;
2238
+ return void 0;
2239
+ }
2240
+ function envTruthy(name) {
2241
+ const v = process.env[name]?.trim().toLowerCase();
2242
+ return v !== void 0 && v !== "" && v !== "0" && v !== "false" && v !== "no" && v !== "off";
2243
+ }
2244
+ function looksLikeThirdPartyAgentEnv() {
2245
+ if (envTruthy("IS_AGENT_ENV") || envTruthy("AI_AGENT")) return true;
2246
+ if (envTruthy("CURSOR_AGENT")) return true;
2247
+ if (process.env.CURSOR_EXTENSION_HOST_ROLE?.trim() === "agent-exec") return true;
2248
+ if (envTruthy("CLAUDECODE") || envTruthy("CLAUDE_CODE")) return true;
2249
+ if (envTruthy("CODEX_SANDBOX") || envTruthy("CODEX_CI") || envTruthy("CODEX_THREAD_ID")) {
2250
+ return true;
2251
+ }
2252
+ if (envTruthy("GEMINI_CLI") || envTruthy("ANTIGRAVITY_AGENT") || envTruthy("AUGMENT_AGENT")) {
2253
+ return true;
2254
+ }
2255
+ if (envTruthy("CLINE_ACTIVE") || envTruthy("GOOSE_TERMINAL") || envTruthy("OPENCLAW")) {
2256
+ return true;
2257
+ }
2258
+ if (envTruthy("COPILOT_ALLOW_ALL") || envTruthy("COPILOT_MODEL")) return true;
2259
+ return false;
2260
+ }
2261
+ function resolveSiluzanClientRuntime() {
2262
+ if (isSiluzanAgentEnv()) return "siluzan_agent";
2263
+ const override = runtimeOverrideFromEnv();
2264
+ if (override) return override;
2265
+ if (looksLikeThirdPartyAgentEnv()) return "agent";
2266
+ return "cli";
2267
+ }
2268
+ function resolveCompanySourceType(raw = process.env[DEERFLOW_AGENT_ENV]) {
2269
+ const trimmed = raw?.trim();
2270
+ if (!trimmed) return void 0;
2271
+ if (trimmed === "Ctaiad") return "Ctaiad";
2272
+ const key = trimmed.toLowerCase();
2273
+ if (key === "ctaiad" || key === "ctaiad_agent") {
2274
+ return SILUZAN_AGENT_COMPANY_SOURCE_TYPE;
2275
+ }
2276
+ return void 0;
2277
+ }
2278
+ function getSiluzanSkillVersion() {
2279
+ return (_resolveVersion?.() ?? "0.0.0").trim() || "0.0.0";
2280
+ }
2281
+ function buildSiluzanClientIdentityHeaders() {
2282
+ const client = getSiluzanClientProduct();
2283
+ const runtime = resolveSiluzanClientRuntime();
2284
+ const version = getSiluzanSkillVersion();
2285
+ const headers = {
2286
+ "X-Siluzan-Client": client,
2287
+ "X-Siluzan-Runtime": runtime,
2288
+ "X-Siluzan-Skill-Version": version,
2289
+ "User-Agent": `${client}/${version}`
2290
+ };
2291
+ const companySource = resolveCompanySourceType();
2292
+ if (companySource) {
2293
+ headers["X-Company-Source-Type"] = companySource;
2294
+ }
2295
+ return headers;
2296
+ }
2297
+ var DEFAULT_TIMEOUT_MS = 10 * 60 * 1e3;
2298
+ var MAX_RESPONSE_BYTES = 50 * 1024 * 1024;
2299
+ var httpsAgent = new https.Agent({
2300
+ keepAlive: true,
2301
+ keepAliveMsecs: 3e4,
2302
+ maxSockets: 16,
2303
+ maxFreeSockets: 8,
2304
+ scheduling: "lifo"
2305
+ });
2306
+ var httpAgent = new http.Agent({
2307
+ keepAlive: true,
2308
+ keepAliveMsecs: 3e4,
2309
+ maxSockets: 16,
2310
+ maxFreeSockets: 8,
2311
+ scheduling: "lifo"
2312
+ });
2313
+ var PERF_PREFIX = "[SILUZAN_HTTP_PERF]";
2314
+ function isPerfEnabled() {
2315
+ const v = process.env.SILUZAN_HTTP_PERF;
2316
+ return v === "1" || v === "true";
2317
+ }
2318
+ function emitPerf(record) {
2319
+ try {
2320
+ process.stderr.write(`${PERF_PREFIX} ${JSON.stringify(record)}
2321
+ `);
2322
+ } catch {
2323
+ }
2324
+ }
2325
+ function rawRequest(url, options) {
2326
+ const perfOn = isPerfEnabled();
2327
+ const t0 = perfOn ? performance.now() : 0;
2328
+ const method = options.method ?? "GET";
2329
+ return new Promise((resolve5, reject) => {
2330
+ const parsed = new URL(url);
2331
+ const transport = parsed.protocol === "https:" ? https : http;
2332
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
2333
+ const maxBytes = options.maxResponseBytes ?? MAX_RESPONSE_BYTES;
2334
+ const isHttps = parsed.protocol === "https:";
2335
+ const headers = {
2336
+ ...buildSiluzanClientIdentityHeaders(),
2337
+ ...options.headers
2338
+ };
2339
+ if (process.env.SILUZAN_DEBUG_HEADERS === "1" || process.env.SILUZAN_DEBUG_HEADERS === "true") {
2340
+ try {
2341
+ process.stderr.write(
2342
+ `[SILUZAN_DEBUG_HEADERS] ${method} ${url}
2343
+ X-Company-Source-Type=${headers["X-Company-Source-Type"] ?? "(missing)"}
2344
+ X-Siluzan-Runtime=${headers["X-Siluzan-Runtime"] ?? "(missing)"}
2345
+ X-Siluzan-Client=${headers["X-Siluzan-Client"] ?? "(missing)"}
2346
+ X-Siluzan-Skill-Version=${headers["X-Siluzan-Skill-Version"] ?? "(missing)"}
2347
+ `
2348
+ );
2349
+ } catch {
2350
+ }
2351
+ }
2352
+ const reqOpts = {
2353
+ hostname: parsed.hostname,
2354
+ port: parsed.port || (isHttps ? 443 : 80),
2355
+ path: parsed.pathname + parsed.search,
2356
+ method,
2357
+ headers,
2358
+ timeout: timeoutMs || void 0,
2359
+ agent: isHttps ? httpsAgent : httpAgent
2360
+ };
2361
+ const req = transport.request(reqOpts, (res) => {
2362
+ const encoding = (res.headers["content-encoding"] ?? "").toString().toLowerCase().trim();
2363
+ let stream = res;
2364
+ if (encoding === "gzip" || encoding === "x-gzip") {
2365
+ stream = res.pipe(zlib.createGunzip());
2366
+ } else if (encoding === "deflate") {
2367
+ stream = res.pipe(zlib.createInflate());
2368
+ } else if (encoding === "br") {
2369
+ stream = res.pipe(zlib.createBrotliDecompress());
2370
+ }
2371
+ const handleStreamError = (err) => {
2372
+ res.destroy();
2373
+ if (perfOn) {
2374
+ emitPerf({
2375
+ method,
2376
+ url,
2377
+ status: res.statusCode ?? 0,
2378
+ elapsedMs: performance.now() - t0,
2379
+ bytes: 0,
2380
+ ok: false,
2381
+ error: `decompress error: ${err.message}`
2382
+ });
2383
+ }
2384
+ reject(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
2385
+ };
2386
+ if (stream !== res) stream.on("error", handleStreamError);
2387
+ res.on("error", handleStreamError);
2388
+ let data = "";
2389
+ let byteLen = 0;
2390
+ stream.setEncoding("utf8");
2391
+ stream.on("data", (chunk) => {
2392
+ byteLen += Buffer.byteLength(chunk, "utf8");
2393
+ if (maxBytes && byteLen > maxBytes) {
2394
+ res.destroy();
2395
+ if (perfOn) {
2396
+ emitPerf({
2397
+ method,
2398
+ url,
2399
+ status: res.statusCode ?? 0,
2400
+ elapsedMs: performance.now() - t0,
2401
+ bytes: byteLen,
2402
+ ok: false,
2403
+ error: "response body exceeded limit"
2404
+ });
2405
+ }
2406
+ reject(
2407
+ new Error(`\u54CD\u5E94\u4F53\u8D85\u8FC7\u4E0A\u9650\uFF08${(maxBytes / 1024 / 1024).toFixed(0)} MB\uFF09\uFF0C\u5DF2\u4E2D\u65AD\u8FDE\u63A5`)
2408
+ );
2409
+ return;
2410
+ }
2411
+ data += chunk;
2412
+ });
2413
+ stream.on("end", () => {
2414
+ const headers2 = {};
2415
+ for (const [key, val] of Object.entries(res.headers)) {
2416
+ if (val !== void 0) {
2417
+ headers2[key.toLowerCase()] = Array.isArray(val) ? val[0] : val;
2418
+ }
2419
+ }
2420
+ const status = res.statusCode ?? 0;
2421
+ if (perfOn) {
2422
+ emitPerf({
2423
+ method,
2424
+ url,
2425
+ status,
2426
+ elapsedMs: performance.now() - t0,
2427
+ bytes: byteLen,
2428
+ ok: status >= 200 && status < 300
2429
+ });
2430
+ }
2431
+ resolve5({ status, text: data, headers: headers2 });
2432
+ });
2433
+ });
2434
+ req.on("timeout", () => {
2435
+ req.destroy();
2436
+ if (perfOn) {
2437
+ emitPerf({
2438
+ method,
2439
+ url,
2440
+ status: 0,
2441
+ elapsedMs: performance.now() - t0,
2442
+ bytes: 0,
2443
+ ok: false,
2444
+ error: "timeout"
2445
+ });
2446
+ }
2447
+ reject(new Error(`\u8BF7\u6C42\u8D85\u65F6\uFF08${(timeoutMs / 1e3).toFixed(0)} \u79D2\uFF09\uFF1A${method} ${url}`));
2448
+ });
2449
+ req.on("error", (err) => {
2450
+ if (perfOn) {
2451
+ emitPerf({
2452
+ method,
2453
+ url,
2454
+ status: 0,
2455
+ elapsedMs: performance.now() - t0,
2456
+ bytes: 0,
2457
+ ok: false,
2458
+ error: err.message
2459
+ });
2460
+ }
2461
+ reject(err);
2462
+ });
2463
+ if (options.body) req.write(options.body);
2464
+ req.end();
2465
+ });
2466
+ }
2467
+ function redactSensitive(input) {
2468
+ let output = input;
2469
+ output = output.replace(/(Bearer\s+)[^\s",]+/gi, "$1***");
2470
+ output = output.replace(
2471
+ /("?(?:apiKey|authToken|accessToken|refreshToken|token|authorization)"?\s*[:=]\s*"?)([^"\s,}]+)/gi,
2472
+ "$1***"
2473
+ );
2474
+ return output;
2475
+ }
2476
+ var DEFAULT_DETAIL_MAX = 400;
2477
+ var VERBOSE_DETAIL_MAX = 800;
2478
+ function trimDetail(text, maxLen) {
2479
+ const t = text.trim();
2480
+ if (t.length <= maxLen) return t;
2481
+ return `${t.slice(0, maxLen)}\u2026`;
2482
+ }
2483
+ function messageFromJsonValue(value) {
2484
+ if (typeof value === "string" && value.trim()) return value.trim();
2485
+ if (Array.isArray(value)) {
2486
+ const parts = value.map((item) => messageFromJsonValue(item)).filter((item) => Boolean(item));
2487
+ return parts.length > 0 ? parts.join("; ") : void 0;
2488
+ }
2489
+ if (!value || typeof value !== "object") return void 0;
2490
+ const rec = value;
2491
+ if (rec.errors && typeof rec.errors === "object" && !Array.isArray(rec.errors)) {
2492
+ const msgs = [];
2493
+ for (const [field, raw] of Object.entries(rec.errors)) {
2494
+ if (Array.isArray(raw)) {
2495
+ for (const item of raw) {
2496
+ const msg = messageFromJsonValue(item);
2497
+ if (msg) msgs.push(`${field}: ${msg}`);
2498
+ }
2499
+ } else {
2500
+ const msg = messageFromJsonValue(raw);
2501
+ if (msg) msgs.push(`${field}: ${msg}`);
2502
+ }
2503
+ }
2504
+ if (msgs.length > 0) return msgs.join("; ");
2505
+ }
2506
+ for (const key of [
2507
+ "detail",
2508
+ "message",
2509
+ "Message",
2510
+ "error",
2511
+ "Error",
2512
+ "errorMessage",
2513
+ "ErrorMessage",
2514
+ "title",
2515
+ "Title",
2516
+ "reason",
2517
+ "Reason"
2518
+ ]) {
2519
+ const msg = messageFromJsonValue(rec[key]);
2520
+ if (msg) return msg;
2521
+ }
2522
+ return void 0;
2523
+ }
2524
+ function extractHttpErrorDetail(rawBody) {
2525
+ const text = rawBody?.trim();
2526
+ if (!text) return void 0;
2527
+ if (text.startsWith('"')) {
2528
+ try {
2529
+ const parsed = JSON.parse(text);
2530
+ if (typeof parsed === "string" && parsed.trim()) return parsed.trim();
2531
+ } catch {
2532
+ }
2533
+ }
2534
+ if (text.startsWith("{") || text.startsWith("[")) {
2535
+ try {
2536
+ const parsed = JSON.parse(text);
2537
+ const msg = messageFromJsonValue(parsed);
2538
+ if (msg) return msg;
2539
+ } catch {
2540
+ }
2541
+ }
2542
+ if (text.startsWith("<")) return void 0;
2543
+ return text;
2544
+ }
2545
+ function formatHttpError(status, rawBody, opts) {
2546
+ const verbose = opts?.verbose === true;
2547
+ const maxLen = verbose ? VERBOSE_DETAIL_MAX : DEFAULT_DETAIL_MAX;
2548
+ const parsed = extractHttpErrorDetail(rawBody);
2549
+ if (parsed) {
2550
+ return `HTTP ${status}\uFF1A${trimDetail(redactSensitive(parsed), maxLen)}`;
2551
+ }
2552
+ if (verbose && rawBody.trim()) {
2553
+ return `HTTP ${status}\uFF1A${trimDetail(redactSensitive(rawBody), maxLen)}`;
2554
+ }
2555
+ return `HTTP ${status}\uFF08\u54CD\u5E94\u65E0\u53EF\u7528\u9519\u8BEF\u8BE6\u60C5\uFF1B\u53EF\u52A0 --verbose \u67E5\u770B\u539F\u59CB\u54CD\u5E94\uFF09`;
2556
+ }
2557
+ function buildAuthHeaders(config) {
2558
+ return buildSiluzanAuthHeaders(config);
2559
+ }
2560
+ async function apiFetch(url, config, options = {}, verbose = false) {
2561
+ const method = options.method ?? "GET";
2562
+ const reqHeaders = {
2563
+ "Content-Type": "application/json",
2564
+ "Accept-Language": "zh-CN",
2565
+ // 声明支持 gzip/deflate/br;服务端不支持则按 identity 返回,rawRequest 会原样收取
2566
+ "Accept-Encoding": "gzip, deflate, br",
2567
+ ...buildAuthHeaders(config),
2568
+ // dataPermission 仅 TSO 使用;CSO 未设置时为空字符串,服务端忽略该头
2569
+ Datapermission: config.dataPermission ?? "",
2570
+ ...options.headers ?? {}
2571
+ };
2572
+ const body = typeof options.body === "string" ? options.body : void 0;
2573
+ const res = await rawRequest(url, {
2574
+ method,
2575
+ headers: reqHeaders,
2576
+ body
2577
+ });
2578
+ const text = res.text;
2579
+ if (res.status < 200 || res.status >= 300) {
2580
+ throw new Error(formatHttpError(res.status, text, { verbose }));
2581
+ }
2582
+ if (!text.trim()) return null;
2583
+ try {
2584
+ return parseJsonWithStringIds(text);
2585
+ } catch {
2586
+ if (verbose) {
2587
+ console.error(` \u26A0\uFE0F \u54CD\u5E94\u975E JSON\uFF0C\u539F\u59CB\u5185\u5BB9\uFF1A${redactSensitive(text).slice(0, 200)}`);
2588
+ }
2589
+ return text;
2590
+ }
2591
+ }
2592
+ function getCurrentVersion(importMetaUrl) {
2593
+ try {
2594
+ const __dirname2 = path2.dirname(fileURLToPath(importMetaUrl));
2595
+ const pkgPath = path2.join(__dirname2, "..", "package.json");
2596
+ const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf8"));
2597
+ return pkg.version ?? "0.0.0";
2598
+ } catch {
2599
+ return "0.0.0";
2600
+ }
2601
+ }
2602
+ function npmDistTagForBuildEnv(buildEnv) {
2603
+ return buildEnv === "test" ? "beta" : "latest";
2604
+ }
2605
+ function npmMinRequiredTagForBuildEnv(buildEnv) {
2606
+ return buildEnv === "test" ? "min-required-beta" : "min-required";
2607
+ }
2608
+ function isNewer(a, b) {
2609
+ return import_semver.default.gt(b, a) === true;
2610
+ }
2611
+ async function fetchNpmVersion(pkgName, tag, timeoutMs = 4e3) {
2612
+ try {
2613
+ const url = `https://registry.npmjs.org/${pkgName}/${tag}`;
2614
+ const controller = new AbortController();
2615
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
2616
+ const res = await fetch(url, { signal: controller.signal });
2617
+ clearTimeout(timer);
2618
+ if (!res.ok) return null;
2619
+ const data = await res.json();
2620
+ return data.version ?? null;
2621
+ } catch {
2622
+ return null;
2623
+ }
2624
+ }
2625
+ async function defaultRunMinRequiredGlobalInstall(ctx) {
2626
+ if (process.env.SILUZAN_SKIP_AUTO_GLOBAL_INSTALL === "1") {
2627
+ return { ok: false, stderr: "SILUZAN_SKIP_AUTO_GLOBAL_INSTALL=1" };
2628
+ }
2629
+ const spec = `${ctx.pkgName}@${ctx.tag}`;
2630
+ return await new Promise((resolve5) => {
2631
+ const child = spawn("npm", ["install", "-g", spec, "--no-fund", "--no-audit"], {
2632
+ stdio: "inherit",
2633
+ shell: true
2634
+ });
2635
+ child.on("error", (err) => {
2636
+ resolve5({ ok: false, stderr: err instanceof Error ? err.message : String(err) });
2637
+ });
2638
+ child.on("close", (code, signal) => {
2639
+ if (code === 0) {
2640
+ resolve5({ ok: true });
2641
+ } else {
2642
+ const sig = signal ? ` signal=${signal}` : "";
2643
+ resolve5({ ok: false, stderr: `exit code ${code}${sig}` });
2644
+ }
2645
+ });
2646
+ });
2647
+ }
2648
+ function createVersionNotifier(opts) {
2649
+ const {
2650
+ pkgName,
2651
+ binName,
2652
+ cachePrefix,
2653
+ resolveTag,
2654
+ forceUpdateExtra = "",
2655
+ updateAvailableExtra = "",
2656
+ runMinRequiredGlobalInstall = defaultRunMinRequiredGlobalInstall,
2657
+ getCurrentVersion: getCurrentVersion22,
2658
+ mergeWriteConfig,
2659
+ readConfigRaw
2660
+ } = opts;
2661
+ const KEY_LATEST_STABLE = `${cachePrefix}LatestStable`;
2662
+ const KEY_LATEST_BETA = `${cachePrefix}LatestBeta`;
2663
+ const KEY_MIN_STABLE = `${cachePrefix}MinRequiredStable`;
2664
+ const KEY_MIN_BETA = `${cachePrefix}MinRequiredBeta`;
2665
+ const KEY_LAST_NOTIFIED = `${cachePrefix}LastNotified`;
2666
+ const KEY_FETCH_AT_MAIN = `${cachePrefix}VersionFetchAtMain`;
2667
+ const KEY_FETCH_AT_MIN = `${cachePrefix}VersionFetchAtMin`;
2668
+ const HOURS_24 = 24 * 60 * 60 * 1e3;
2669
+ const TTL_MAIN_TAG_MS = 60 * 60 * 1e3;
2670
+ const TTL_MIN_REQUIRED_MS = HOURS_24;
2671
+ async function fetchVersionByTag(tag, cacheKey, fetchAtKey, cfg, maxAgeMs) {
2672
+ const lastAt = cfg[fetchAtKey];
2673
+ if (typeof lastAt === "string" && cacheKey in cfg) {
2674
+ const lastMs = new Date(lastAt).getTime();
2675
+ if (Date.now() - lastMs < maxAgeMs) {
2676
+ const v = cfg[cacheKey];
2677
+ const sv = typeof v === "string" && v ? v : null;
2678
+ return { version: sv, hitNetwork: false };
2679
+ }
2680
+ }
2681
+ const version = await fetchNpmVersion(pkgName, tag);
2682
+ return { version, hitNetwork: true };
2683
+ }
2684
+ async function notifyIfOutdated2() {
2685
+ try {
2686
+ const current = getCurrentVersion22();
2687
+ const tag = resolveTag(current);
2688
+ const isBeta = tag === "beta";
2689
+ const latestCacheKey = isBeta ? KEY_LATEST_BETA : KEY_LATEST_STABLE;
2690
+ const minCacheKey = isBeta ? KEY_MIN_BETA : KEY_MIN_STABLE;
2691
+ const minTag = npmMinRequiredTagForBuildEnv(isBeta ? "test" : "production");
2692
+ const cfg = readConfigRaw();
2693
+ const [mainRes, minRes] = await Promise.all([
2694
+ fetchVersionByTag(tag, latestCacheKey, KEY_FETCH_AT_MAIN, cfg, TTL_MAIN_TAG_MS),
2695
+ fetchVersionByTag(minTag, minCacheKey, KEY_FETCH_AT_MIN, cfg, TTL_MIN_REQUIRED_MS)
2696
+ ]);
2697
+ const latest = mainRes.version;
2698
+ const minRequired = minRes.version;
2699
+ const nowIso = (/* @__PURE__ */ new Date()).toISOString();
2700
+ const cacheUpdates = {
2701
+ [latestCacheKey]: latest ?? "",
2702
+ [minCacheKey]: minRequired ?? ""
2703
+ };
2704
+ if (mainRes.hitNetwork) cacheUpdates[KEY_FETCH_AT_MAIN] = nowIso;
2705
+ if (minRes.hitNetwork) cacheUpdates[KEY_FETCH_AT_MIN] = nowIso;
2706
+ await mergeWriteConfig(cacheUpdates);
2707
+ const lastNotified = typeof cfg[KEY_LAST_NOTIFIED] === "string" ? new Date(cfg[KEY_LAST_NOTIFIED]).getTime() : 0;
2708
+ if (Date.now() - lastNotified < HOURS_24) return;
2709
+ const tagLabel = isBeta ? "\uFF08\u6D4B\u8BD5\u7248\uFF09" : "\uFF08\u6B63\u5F0F\u7248\uFF09";
2710
+ if (minRequired && isNewer(current, minRequired)) {
2711
+ await mergeWriteConfig({ [KEY_LAST_NOTIFIED]: (/* @__PURE__ */ new Date()).toISOString() });
2712
+ console.log(
2713
+ `
2714
+ [SILUZAN_FORCE_UPDATE] \u5F53\u524D\u7248\u672C ${current} \u5DF2\u4F4E\u4E8E\u6700\u4F4E\u8981\u6C42 ${minRequired}${tagLabel}
2715
+ \u26D4 \u6B63\u5728\u81EA\u52A8\u6267\u884C\uFF1Anpm install -g ${pkgName}@${tag}
2716
+ ` + (forceUpdateExtra ? forceUpdateExtra + "\n" : "")
2717
+ );
2718
+ const installResult = await runMinRequiredGlobalInstall({ pkgName, tag });
2719
+ if (installResult.ok) {
2720
+ console.log(
2721
+ `
2722
+ [SILUZAN_AUTO_GLOBAL_INSTALL_OK] \u5168\u5C40\u5B89\u88C5\u5DF2\u5B8C\u6210\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C\u672C\u547D\u4EE4\u4EE5\u52A0\u8F7D\u65B0\u7248\u672C ${pkgName}@${tag}\u3002
2723
+ `
2724
+ );
2725
+ } else {
2726
+ console.log(
2727
+ `
2728
+ [SILUZAN_AUTO_GLOBAL_INSTALL_FAILED] \u81EA\u52A8\u5168\u5C40\u5B89\u88C5\u5931\u8D25\uFF1A${installResult.stderr ?? "unknown"}
2729
+ \u8BF7\u624B\u52A8\u6267\u884C\uFF1Anpm install -g ${pkgName}@${tag}
2730
+ \u6216\uFF1A${binName} update
2731
+ ` + (forceUpdateExtra ? forceUpdateExtra + "\n" : "")
2732
+ );
2733
+ }
2734
+ return;
2735
+ }
2736
+ if (latest && isNewer(current, latest)) {
2737
+ await mergeWriteConfig({ [KEY_LAST_NOTIFIED]: (/* @__PURE__ */ new Date()).toISOString() });
2738
+ console.log(
2739
+ `
2740
+ [SILUZAN_UPDATE_AVAILABLE] \u53D1\u73B0\u65B0\u7248\u672C ${latest}${tagLabel}\uFF08\u5F53\u524D ${current}\uFF09
2741
+ \u{1F4A1} Agent \u8BF7\u7ACB\u5373\u6267\u884C\uFF1A${binName} update
2742
+ \u6216\u624B\u52A8\uFF1Anpm install -g ${pkgName}@${tag}
2743
+ ` + (updateAvailableExtra ? updateAvailableExtra + "\n" : "")
2744
+ );
2745
+ }
2746
+ } catch {
2747
+ }
2748
+ }
2749
+ async function fetchLatestVersion2() {
2750
+ const current = getCurrentVersion22();
2751
+ const tag = resolveTag(current);
2752
+ return fetchNpmVersion(pkgName, tag);
2753
+ }
2754
+ return { notifyIfOutdated: notifyIfOutdated2, fetchLatestVersion: fetchLatestVersion2 };
2755
+ }
2756
+ var TABLE_CELL_PIPE = "\uFF5C";
2757
+ function sanitizeTableCell(value) {
2758
+ return String(value ?? "").replace(/\r\n|\r|\n/g, " ").replace(/\|/g, TABLE_CELL_PIPE);
2759
+ }
2760
+ var ASCII_TABLE_CHARS = {
2761
+ top: "-",
2762
+ "top-mid": "+",
2763
+ "top-left": "+",
2764
+ "top-right": "+",
2765
+ bottom: "-",
2766
+ "bottom-mid": "+",
2767
+ "bottom-left": "+",
2768
+ "bottom-right": "+",
2769
+ left: "|",
2770
+ "left-mid": "+",
2771
+ mid: "-",
2772
+ "mid-mid": "+",
2773
+ right: "|",
2774
+ "right-mid": "+",
2775
+ middle: "|"
2776
+ };
2777
+ function printCliTable(rows, columns, options) {
2778
+ if (rows.length === 0) return;
2779
+ const plain = options?.plain !== false;
2780
+ const indent = options?.indent ?? " ";
2781
+ const printLine = options?.printLine ?? ((msg) => {
2782
+ console.log(msg);
2783
+ });
2784
+ const table = new Table({
2785
+ head: columns.map((c) => c.header),
2786
+ chars: plain ? { ...ASCII_TABLE_CHARS } : void 0,
2787
+ style: plain ? { head: [], border: [] } : void 0
2788
+ });
2789
+ for (const r of rows) {
2790
+ table.push(columns.map((c) => sanitizeTableCell(r[c.key])));
2791
+ }
2792
+ for (const line of table.toString().split("\n")) {
2793
+ printLine(indent + line);
2794
+ }
2795
+ }
2796
+ function installProcessHandlers() {
2797
+ process.on("uncaughtException", (err) => {
2798
+ console.error(`
2799
+ \u274C \u672A\u6355\u83B7\u7684\u5F02\u5E38\uFF1A${err.message}`);
2800
+ if (process.argv.includes("--verbose")) console.error(err.stack);
2801
+ process.exit(1);
2802
+ });
2803
+ process.on("unhandledRejection", (reason) => {
2804
+ const msg = reason instanceof Error ? reason.message : String(reason);
2805
+ console.error(`
2806
+ \u274C \u672A\u5904\u7406\u7684\u5F02\u6B65\u9519\u8BEF\uFF1A${msg}`);
2807
+ if (process.argv.includes("--verbose") && reason instanceof Error) {
2808
+ console.error(reason.stack);
2809
+ }
2810
+ process.exit(1);
2811
+ });
2812
+ }
2813
+ function printAuthMissingHelp(binName) {
2814
+ if (isSiluzanAgentEnv()) {
2815
+ console.error(
2816
+ "\n\u274C Siluzan Agent \u73AF\u5883\u4E2D\u672A\u627E\u5230\u8BA4\u8BC1\u51ED\u636E\u3002\n\nAgent \u6C99\u7BB1\u5E94\u901A\u8FC7\u73AF\u5883\u53D8\u91CF\u6CE8\u5165\u4EE5\u4E0B\u4EFB\u610F\u4E00\u79CD\uFF08\u65E0\u9700 login\uFF09\uFF1A\n SILUZAN_API_KEY=<YOUR_API_KEY>\n SILUZAN_AUTH_TOKEN=<YOUR_TOKEN>\n\n\u8BF7\u68C0\u67E5 Agent \u8FD0\u884C\u65F6\u662F\u5426\u5DF2\u8BBE\u7F6E IS_SILUZAN_AGENT_ENV=true \u5E76\u5B8C\u6210\u51ED\u636E\u6CE8\u5165\u3002\n"
2817
+ );
2818
+ process.exit(1);
2819
+ }
2820
+ console.error(
2821
+ `
2822
+ \u274C \u672A\u627E\u5230\u8BA4\u8BC1\u51ED\u636E\u3002\u8BF7\u9009\u62E9\u4EE5\u4E0B\u4EFB\u610F\u4E00\u79CD\u65B9\u5F0F\uFF1A
2823
+
2824
+ \u8BF7\u4F7F\u7528\u624B\u673A\u53F7\u91CD\u65B0\u767B\u5F55
2825
+ ${binName} send-login-code --phone <YOUR_PHONE>
2826
+ `,
2827
+ `\u7136\u540E\u4F7F\u7528\u6536\u5230\u7684\u9A8C\u8BC1\u7801\u5B8C\u6210\u767B\u5F55
2828
+ ${binName} login --phone <YOUR_PHONE> --code <YOUR_CODE>
2829
+ `
2830
+ );
2831
+ process.exit(1);
2832
+ }
2833
+ var MIN_SEGMENT_BYTES = 256 * 1024;
2834
+ var MAX_SEGMENT_BYTES = 50 * 1024 * 1024;
2835
+ var MAX_RETENTION_DAYS = 366 * 5;
2836
+ var PRUNE_THROTTLE_MS = 60 * 60 * 1e3;
2837
+ var MAX_SNAPSHOT_FILE_BYTES = 2 * 1024 * 1024;
2838
+ var API_KEY_SERVICE_VALUES = {
2839
+ CSO: 0,
2840
+ TSO: 1,
2841
+ CUT: 2
2842
+ };
2843
+ function deriveSsoBaseUrl(anyApiBase) {
2844
+ try {
2845
+ const u = new URL(anyApiBase);
2846
+ u.hostname = u.hostname.replace(/^(tso-api|cso|api)/, "sso");
2847
+ return u.origin;
2848
+ } catch {
2849
+ return "https://sso.siluzan.com";
2850
+ }
2851
+ }
2852
+ function deriveCsoApiBaseUrl(anyApiBase) {
2853
+ try {
2854
+ const u = new URL(anyApiBase);
2855
+ u.hostname = u.hostname.replace(/^(tso-api|api)/, "cso");
2856
+ return u.origin;
2857
+ } catch {
2858
+ return "https://cso.siluzan.com";
2859
+ }
2860
+ }
2861
+ function normalizeChinaPhone(input) {
2862
+ if (!input) return input;
2863
+ const cleaned = input.replace(/[\s\-()\u00A0]/g, "");
2864
+ if (/^\+861\d{10}$/.test(cleaned)) {
2865
+ return cleaned;
2866
+ }
2867
+ if (/^861\d{10}$/.test(cleaned)) {
2868
+ return `+${cleaned}`;
2869
+ }
2870
+ if (/^00861\d{10}$/.test(cleaned)) {
2871
+ return `+${cleaned.slice(2)}`;
2872
+ }
2873
+ if (/^1\d{10}$/.test(cleaned)) {
2874
+ return `+86${cleaned}`;
2875
+ }
2876
+ return cleaned;
2877
+ }
2878
+ function isValidChinaPhone(input) {
2879
+ return /^\+861\d{10}$/.test(normalizeChinaPhone(input));
2880
+ }
2881
+ async function sendPhoneLoginCode(opts) {
2882
+ const phone = normalizeChinaPhone(opts.phone);
2883
+ const url = `${opts.ssoBaseUrl}/Account/SendVaildCode?Phone=${encodeURIComponent(
2884
+ phone
2885
+ )}&RandStr=&Iicket=`;
2886
+ if (opts.verbose) {
2887
+ process.stderr.write(`[phone-login] GET ${url}
2888
+ `);
2889
+ }
2890
+ const res = await rawRequest(url, {
2891
+ method: "GET",
2892
+ headers: {
2893
+ Accept: "application/json",
2894
+ "Accept-Language": "zh-CN"
2895
+ }
2896
+ });
2897
+ if (res.status < 200 || res.status >= 300) {
2898
+ return { ok: false, message: `HTTP ${res.status}` };
2899
+ }
2900
+ let body;
2901
+ try {
2902
+ body = JSON.parse(res.text);
2903
+ } catch {
2904
+ return { ok: false, message: `\u54CD\u5E94\u975E JSON\uFF1A${res.text.slice(0, 120)}` };
2905
+ }
2906
+ const state = (body.State ?? body.state ?? "").toLowerCase();
2907
+ const message = body.Message ?? body.message ?? "";
2908
+ return { ok: state === "ok", message };
2909
+ }
2910
+ async function loginByPhoneCode(opts) {
2911
+ const phone = normalizeChinaPhone(opts.phone);
2912
+ const url = `${opts.ssoBaseUrl}/Account/LoginByMiniCode?phone=${encodeURIComponent(
2913
+ phone
2914
+ )}&code=${encodeURIComponent(opts.code)}&key=`;
2915
+ if (opts.verbose) {
2916
+ process.stderr.write(`[phone-login] GET ${url}
2917
+ `);
2918
+ }
2919
+ const res = await rawRequest(url, {
2920
+ method: "GET",
2921
+ headers: {
2922
+ Accept: "application/json",
2923
+ "Accept-Language": "zh-CN"
2924
+ }
2925
+ });
2926
+ if (opts.verbose) {
2927
+ process.stderr.write(
2928
+ `[phone-login] LoginByMiniCode HTTP ${res.status} body=${res.text.slice(0, 500)}
2929
+ `
2930
+ );
2931
+ }
2932
+ if (res.status < 200 || res.status >= 300) {
2933
+ throw new Error(`\u767B\u5F55\u5931\u8D25\uFF1AHTTP ${res.status}`);
2934
+ }
2935
+ let body;
2936
+ try {
2937
+ body = JSON.parse(res.text);
2938
+ } catch {
2939
+ throw new Error(`\u767B\u5F55\u54CD\u5E94\u975E JSON\uFF1A${res.text.slice(0, 120)}`);
2940
+ }
2941
+ const errMsg = body.msg ?? body.Msg ?? "";
2942
+ if (!body.token || typeof body.token === "string") {
2943
+ throw new Error(errMsg || "\u767B\u5F55\u5931\u8D25\uFF08\u540E\u7AEF\u672A\u8FD4\u56DE\u539F\u56E0\uFF09");
2944
+ }
2945
+ const token = body.token;
2946
+ const isError = token.isError ?? token.IsError ?? false;
2947
+ if (isError) {
2948
+ const err = token.errorDescription ?? token.ErrorDescription ?? token.error ?? token.Error ?? "\u672A\u77E5\u9519\u8BEF";
2949
+ throw new Error(`OAuth \u5931\u8D25\uFF1A${err}`);
2950
+ }
2951
+ let accessToken = token.accessToken ?? token.access_token ?? "";
2952
+ let tokenType = token.tokenType ?? token.token_type ?? "Bearer";
2953
+ let expiresIn = token.expiresIn ?? token.expires_in;
2954
+ if (!accessToken) {
2955
+ const rawJson = token.raw ?? token.Raw;
2956
+ if (rawJson && typeof rawJson === "string") {
2957
+ try {
2958
+ const parsed = JSON.parse(rawJson);
2959
+ accessToken = parsed.access_token ?? "";
2960
+ tokenType = parsed.token_type ?? tokenType;
2961
+ expiresIn = parsed.expires_in ?? expiresIn;
2962
+ } catch {
2963
+ }
2964
+ }
2965
+ }
2966
+ if (!accessToken) {
2967
+ throw new Error(
2968
+ `\u767B\u5F55\u54CD\u5E94\u7F3A\u5C11 access_token\uFF08\u54CD\u5E94\u5B57\u6BB5\uFF1A${Object.keys(token).join(", ") || "\u65E0"}\uFF09`
2969
+ );
2970
+ }
2971
+ return { accessToken, tokenType, expiresIn };
2972
+ }
2973
+ async function createApiKeyByBearer(opts) {
2974
+ if (opts.allowedServices.length === 0) {
2975
+ throw new Error("createApiKey \u81F3\u5C11\u9700\u8981\u4F20\u5165\u4E00\u4E2A allowedServices");
2976
+ }
2977
+ if (opts.validDays === void 0 && opts.expiresAt === void 0) {
2978
+ throw new Error("createApiKey \u5FC5\u987B\u6307\u5B9A validDays \u6216 expiresAt");
2979
+ }
2980
+ const body = JSON.stringify({
2981
+ name: opts.name,
2982
+ validDays: opts.validDays,
2983
+ expiresAt: opts.expiresAt,
2984
+ allowedServices: opts.allowedServices.map((s) => API_KEY_SERVICE_VALUES[s])
2985
+ });
2986
+ const url = `${opts.csoBaseUrl}/cso/v1/apikey`;
2987
+ if (opts.verbose) {
2988
+ process.stderr.write(`[phone-login] POST ${url} body=${body}
2989
+ `);
2990
+ }
2991
+ const res = await rawRequest(url, {
2992
+ method: "POST",
2993
+ headers: {
2994
+ "Content-Type": "application/json",
2995
+ Accept: "application/json",
2996
+ "Accept-Language": "zh-CN",
2997
+ Authorization: `Bearer ${opts.bearerToken}`,
2998
+ "Content-Length": String(Buffer.byteLength(body, "utf8"))
2999
+ },
3000
+ body
3001
+ });
3002
+ if (res.status < 200 || res.status >= 300) {
3003
+ throw new Error(`\u521B\u5EFA API Key \u5931\u8D25\uFF1AHTTP ${res.status}\uFF08${res.text.slice(0, 200)}\uFF09`);
3004
+ }
3005
+ let json;
3006
+ try {
3007
+ json = JSON.parse(res.text);
3008
+ } catch {
3009
+ throw new Error(`\u521B\u5EFA API Key \u54CD\u5E94\u975E JSON\uFF1A${res.text.slice(0, 120)}`);
3010
+ }
3011
+ const code = json.code ?? json.Code;
3012
+ if (code !== 1) {
3013
+ throw new Error(`\u521B\u5EFA API Key \u5931\u8D25\uFF1A${json.message ?? json.Message ?? "\u672A\u77E5\u9519\u8BEF"}`);
3014
+ }
3015
+ const data = json.data ?? json.Data;
3016
+ if (!data?.rawKey) {
3017
+ throw new Error("\u521B\u5EFA API Key \u54CD\u5E94\u7F3A\u5C11 rawKey \u5B57\u6BB5");
3018
+ }
3019
+ return data;
3020
+ }
3021
+ async function issueApiKeyWithPhoneCode(opts) {
3022
+ const code = opts.code?.trim() ?? "";
3023
+ if (!code) {
3024
+ throw new Error("\u9A8C\u8BC1\u7801\u4E0D\u80FD\u4E3A\u7A7A");
3025
+ }
3026
+ const tokenInfo = await loginByPhoneCode({
3027
+ ssoBaseUrl: opts.ssoBaseUrl,
3028
+ phone: opts.phone,
3029
+ code,
3030
+ verbose: opts.verbose
3031
+ });
3032
+ const apiKey = await createApiKeyByBearer({
3033
+ csoBaseUrl: opts.csoBaseUrl,
3034
+ bearerToken: tokenInfo.accessToken,
3035
+ name: opts.apiKeyName,
3036
+ validDays: opts.validDays ?? (opts.expiresAt ? void 0 : 90),
3037
+ expiresAt: opts.expiresAt,
3038
+ allowedServices: opts.allowedServices,
3039
+ verbose: opts.verbose
3040
+ });
3041
+ return apiKey;
3042
+ }
3043
+
3044
+ // src/index.ts
3045
+ import { Command } from "commander";
3046
+
3047
+ // src/commands/init.ts
3048
+ import * as fs4 from "fs/promises";
3049
+ import * as fsSync from "fs";
3050
+ import * as os2 from "os";
3051
+ import * as path4 from "path";
3052
+ import { fileURLToPath as fileURLToPath2 } from "url";
3053
+
3054
+ // src/templates/load-templates.ts
3055
+ import * as fs3 from "fs/promises";
3056
+ import * as path3 from "path";
3057
+ async function getSkillFiles(skillDir) {
3058
+ const out = {};
3059
+ async function walk(dir, prefix) {
3060
+ const entries = await fs3.readdir(dir, { withFileTypes: true });
3061
+ for (const ent of entries) {
3062
+ const rel = prefix ? `${prefix}/${ent.name}` : ent.name;
3063
+ const full = path3.join(dir, ent.name);
3064
+ if (ent.isDirectory()) {
3065
+ await walk(full, rel);
3066
+ } else {
3067
+ out[rel] = await fs3.readFile(full, "utf8");
3068
+ }
3069
+ }
3070
+ }
3071
+ await walk(skillDir, "");
3072
+ return out;
3073
+ }
3074
+
3075
+ // src/commands/init.ts
3076
+ var __dirname = path4.dirname(fileURLToPath2(import.meta.url));
3077
+ var SKILL_DIR_NAME = "siluzan-website";
3078
+ var PROJECT_DIRS = {
3079
+ agents: (cwd) => path4.join(cwd, ".agents", "skills", SKILL_DIR_NAME),
3080
+ cursor: (cwd) => path4.join(cwd, ".cursor", "skills", SKILL_DIR_NAME),
3081
+ claude: (cwd) => path4.join(cwd, ".claude", "skills", SKILL_DIR_NAME),
3082
+ windsurf: (cwd) => path4.join(cwd, ".windsurf", "skills", SKILL_DIR_NAME),
3083
+ gemini: (cwd) => path4.join(cwd, ".gemini", "skills", SKILL_DIR_NAME),
3084
+ codex: (cwd) => path4.join(cwd, ".codex", "skills", SKILL_DIR_NAME),
3085
+ opencode: (cwd) => path4.join(cwd, ".opencode", "skills", SKILL_DIR_NAME),
3086
+ kilo: (cwd) => path4.join(cwd, ".kilo", "skills", SKILL_DIR_NAME),
3087
+ openclaw: (cwd) => path4.join(cwd, "skills", SKILL_DIR_NAME),
3088
+ workbuddy: (cwd) => path4.join(cwd, ".workbuddy", "skills", SKILL_DIR_NAME),
3089
+ deerflow: (cwd) => path4.join(cwd, "skills", "public", SKILL_DIR_NAME)
3090
+ };
3091
+ var GLOBAL_DIRS = {
3092
+ agents: (home) => path4.join(home, ".agents", "skills", SKILL_DIR_NAME),
3093
+ cursor: (home) => path4.join(home, ".cursor", "skills", SKILL_DIR_NAME),
3094
+ claude: (home) => path4.join(home, ".claude", "skills", SKILL_DIR_NAME),
3095
+ windsurf: (home) => path4.join(home, ".codeium", "windsurf", "skills", SKILL_DIR_NAME),
3096
+ gemini: (home) => path4.join(home, ".gemini", "skills", SKILL_DIR_NAME),
3097
+ codex: (home) => path4.join(home, ".codex", "skills", SKILL_DIR_NAME),
3098
+ opencode: (home) => path4.join(home, ".config", "opencode", "skills", SKILL_DIR_NAME),
3099
+ kilo: (home) => path4.join(home, ".kilo", "skills", SKILL_DIR_NAME),
3100
+ openclaw: (home) => path4.join(home, ".openclaw", "skills", SKILL_DIR_NAME),
3101
+ workbuddy: (home) => path4.join(home, ".workbuddy", "skills", SKILL_DIR_NAME)
3102
+ };
3103
+ var ALL_PLATFORM_KEYS = Object.keys(PROJECT_DIRS);
3104
+ function parseTargets(raw) {
3105
+ const normalized = raw.trim().toLowerCase();
3106
+ if (normalized === "all") {
3107
+ return ALL_PLATFORM_KEYS.map((k) => ({ keys: [k], isGlobal: false }));
3108
+ }
3109
+ const parts = normalized.split(",").map((s) => s.trim());
3110
+ const results = [];
3111
+ const seen = /* @__PURE__ */ new Set();
3112
+ for (const p of parts) {
3113
+ let key = p;
3114
+ let isGlobal = false;
3115
+ if (p === "openclaw-workspace") {
3116
+ key = "openclaw";
3117
+ } else if (p === "openclaw-global") {
3118
+ key = "openclaw";
3119
+ isGlobal = true;
3120
+ } else if (p === "workbuddy-workspace") {
3121
+ key = "workbuddy";
3122
+ } else if (p === "workbuddy-global") {
3123
+ key = "workbuddy";
3124
+ isGlobal = true;
3125
+ }
3126
+ if (!ALL_PLATFORM_KEYS.includes(key)) {
3127
+ console.error(
3128
+ `\u672A\u77E5\u5E73\u53F0: ${p}\u3002\u53EF\u9009: ${ALL_PLATFORM_KEYS.join(", ")}, openclaw-workspace, openclaw-global, workbuddy-workspace, workbuddy-global, all`
3129
+ );
3130
+ process.exitCode = 1;
3131
+ return [];
3132
+ }
3133
+ const uid = `${key}:${isGlobal}`;
3134
+ if (!seen.has(uid)) {
3135
+ seen.add(uid);
3136
+ results.push({ keys: [key], isGlobal });
3137
+ }
3138
+ }
3139
+ return results;
3140
+ }
3141
+ function skillRoot() {
3142
+ return path4.join(__dirname, "skill");
3143
+ }
3144
+ function saveInstalledTargets(newEntries) {
3145
+ const CONFIG_FILE3 = path4.join(os2.homedir(), ".siluzan", "config.json");
3146
+ try {
3147
+ fsSync.mkdirSync(path4.dirname(CONFIG_FILE3), { recursive: true });
3148
+ let existing = {};
3149
+ if (fsSync.existsSync(CONFIG_FILE3)) {
3150
+ existing = JSON.parse(fsSync.readFileSync(CONFIG_FILE3, "utf8"));
3151
+ }
3152
+ const prev = Array.isArray(existing.websiteInstalledTargets) ? existing.websiteInstalledTargets : [];
3153
+ const merged = /* @__PURE__ */ new Map();
3154
+ for (const e of [...prev, ...newEntries]) {
3155
+ merged.set(`${e.target}::${e.cwd}::${e.dir ?? ""}`, e);
3156
+ }
3157
+ fsSync.writeFileSync(
3158
+ CONFIG_FILE3,
3159
+ JSON.stringify({ ...existing, websiteInstalledTargets: [...merged.values()] }, null, 2),
3160
+ "utf8"
3161
+ );
3162
+ if (process.platform !== "win32") {
3163
+ fsSync.chmodSync(CONFIG_FILE3, 384);
3164
+ }
3165
+ } catch {
3166
+ }
3167
+ }
3168
+ async function writeSkillFilesToDir(destDir, skillFiles, force) {
3169
+ await fs4.mkdir(destDir, { recursive: true });
3170
+ let anyWritten = false;
3171
+ for (const [relativePath, content] of Object.entries(skillFiles)) {
3172
+ const fullPath = path4.join(destDir, relativePath);
3173
+ await fs4.mkdir(path4.dirname(fullPath), { recursive: true });
3174
+ try {
3175
+ await fs4.access(fullPath);
3176
+ if (!force) {
3177
+ console.warn(`\u8DF3\u8FC7\uFF08\u5DF2\u5B58\u5728\uFF0C\u4F7F\u7528 --force \u8986\u76D6\uFF09: ${fullPath}`);
3178
+ continue;
3179
+ }
3180
+ } catch {
3181
+ }
3182
+ await fs4.writeFile(fullPath, content, "utf8");
3183
+ console.log(`\u5DF2\u5199\u5165: ${fullPath}`);
3184
+ anyWritten = true;
3185
+ }
3186
+ return anyWritten;
3187
+ }
3188
+ async function runInit(options) {
3189
+ const home = os2.homedir();
3190
+ const skillFiles = await getSkillFiles(skillRoot());
3191
+ const installedEntries = [];
3192
+ if (options.dir) {
3193
+ const destDir = path4.resolve(options.cwd, options.dir);
3194
+ console.log(`\u5B89\u88C5\u76EE\u6807\u76EE\u5F55\uFF1A${destDir}`);
3195
+ const anyWritten = await writeSkillFilesToDir(destDir, skillFiles, options.force);
3196
+ if (anyWritten) {
3197
+ installedEntries.push({ target: "custom", cwd: "", dir: destDir });
3198
+ }
3199
+ } else if (options.global) {
3200
+ for (const key of ALL_PLATFORM_KEYS) {
3201
+ if (key === "deerflow") continue;
3202
+ const destDir = GLOBAL_DIRS[key](home);
3203
+ console.log(`[${key} global] \u2192 ${destDir}`);
3204
+ const anyWritten = await writeSkillFilesToDir(destDir, skillFiles, options.force);
3205
+ if (anyWritten) {
3206
+ installedEntries.push({ target: `${key}-global`, cwd: "" });
3207
+ }
3208
+ }
3209
+ } else {
3210
+ const targets = parseTargets(options.aiTargets);
3211
+ if (targets.length === 0) return;
3212
+ for (const entry of targets) {
3213
+ for (const key of entry.keys) {
3214
+ const destDir = entry.isGlobal ? GLOBAL_DIRS[key](home) : PROJECT_DIRS[key](options.cwd);
3215
+ const label = entry.isGlobal ? `${key} global` : key;
3216
+ console.log(`[${label}] \u2192 ${destDir}`);
3217
+ const anyWritten = await writeSkillFilesToDir(destDir, skillFiles, options.force);
3218
+ if (anyWritten) {
3219
+ installedEntries.push({
3220
+ target: entry.isGlobal ? `${key}-global` : key,
3221
+ cwd: entry.isGlobal ? "" : options.cwd
3222
+ });
3223
+ }
3224
+ }
3225
+ }
3226
+ }
3227
+ if (installedEntries.length > 0) {
3228
+ saveInstalledTargets(installedEntries);
3229
+ }
3230
+ console.log("\n\u4E0B\u4E00\u6B65\uFF1A");
3231
+ console.log("1. \u82E5\u5C1A\u672A\u767B\u5F55\uFF1Asiluzan-website login");
3232
+ console.log("2. \u5217\u51FA\u7AD9\u70B9\uFF1Asiluzan-website sites list");
3233
+ console.log("3. CLI \u5347\u7EA7\u540E\u8FD0\u884C\uFF1Asiluzan-website update");
3234
+ }
3235
+ function register(program2) {
3236
+ program2.command("init").description("\u5C06 Website Skill \u6587\u4EF6\u5199\u5165 AI \u52A9\u624B\u76EE\u5F55").option(
3237
+ "-a, --ai <targets>",
3238
+ "\u76EE\u6807\u5E73\u53F0\uFF0C\u9017\u53F7\u5206\u9694\uFF1Acursor,claude,agents,windsurf,gemini,codex,opencode,kilo,openclaw,workbuddy,deerflow,all",
3239
+ "all"
3240
+ ).option("-d, --dir <path>", "\u5C06 Skill \u6587\u4EF6\u76F4\u63A5\u5199\u5165\u6307\u5B9A\u76EE\u5F55\uFF0C\u4E0E --ai/--global \u4E92\u65A5").option("-g, --global", "\u5199\u5165\u6240\u6709\u5E73\u53F0\u7684\u5168\u5C40 skill \u76EE\u5F55", false).option("-f, --force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684 Skill \u6587\u4EF6", false).action(async (opts) => {
3241
+ await runInit({
3242
+ cwd: process.cwd(),
3243
+ aiTargets: opts.ai,
3244
+ dir: opts.dir,
3245
+ global: Boolean(opts.global),
3246
+ force: Boolean(opts.force)
3247
+ });
3248
+ });
3249
+ }
3250
+
3251
+ // src/commands/update.ts
3252
+ import * as fs5 from "fs";
3253
+ import * as os3 from "os";
3254
+ import * as path5 from "path";
3255
+ import { spawnSync } from "child_process";
3256
+
3257
+ // src/config/defaults.ts
3258
+ var BUILD_ENV = "test";
3259
+ var DEFAULT_API_BASE = "https://api-ci.siluzan.com";
3260
+ var DEFAULT_CSO_BASE = "https://cso-ci.siluzan.com";
3261
+ var DEFAULT_WEB_BASE = "https://www-ci.siluzan.com";
3262
+ var DEFAULT_SITE_STAGE = "ci";
3263
+
3264
+ // src/utils/version.ts
3265
+ var PKG_NAME = "siluzan-website-cli";
3266
+ var BIN_NAME = "siluzan-website";
3267
+ var CACHE_PREFIX = "_website";
3268
+ function getCurrentVersion2() {
3269
+ return getCurrentVersion(import.meta.url);
3270
+ }
3271
+ var notifier = createVersionNotifier({
3272
+ pkgName: PKG_NAME,
3273
+ binName: BIN_NAME,
3274
+ cachePrefix: CACHE_PREFIX,
3275
+ resolveTag: () => npmDistTagForBuildEnv(BUILD_ENV),
3276
+ getCurrentVersion: getCurrentVersion2,
3277
+ mergeWriteConfig: (updates) => mergeWriteSharedConfig(updates),
3278
+ readConfigRaw: () => readSharedConfigRaw()
3279
+ });
3280
+ var notifyIfOutdated = notifier.notifyIfOutdated;
3281
+ var fetchLatestVersion = notifier.fetchLatestVersion;
3282
+
3283
+ // src/commands/update.ts
3284
+ var CONFIG_FILE2 = path5.join(os3.homedir(), ".siluzan", "config.json");
3285
+ var PKG_NAME2 = "siluzan-website-cli";
3286
+ function readInstalledTargets() {
3287
+ try {
3288
+ const cfg = JSON.parse(fs5.readFileSync(CONFIG_FILE2, "utf8"));
3289
+ return Array.isArray(cfg.websiteInstalledTargets) ? cfg.websiteInstalledTargets : [];
3290
+ } catch {
3291
+ return [];
3292
+ }
3293
+ }
3294
+ function isNpmGlobalInstall() {
3295
+ try {
3296
+ const result = spawnSync("npm", ["list", "-g", "--depth=0", PKG_NAME2], {
3297
+ encoding: "utf8",
3298
+ stdio: "pipe"
3299
+ });
3300
+ return Boolean(result.stdout?.includes(PKG_NAME2));
3301
+ } catch {
3302
+ return false;
3303
+ }
3304
+ }
3305
+ async function runUpdate(options) {
3306
+ const current = getCurrentVersion2();
3307
+ console.log(`
3308
+ \u5F53\u524D\u7248\u672C\uFF1A${current}`);
3309
+ const npmTag = npmDistTagForBuildEnv(BUILD_ENV);
3310
+ console.log(`\u6B63\u5728\u67E5\u8BE2 npm registry\uFF08dist-tag\uFF1A${npmTag}\uFF09\u2026`);
3311
+ const latest = await fetchLatestVersion();
3312
+ if (!latest) {
3313
+ console.warn("\u26A0\uFE0F \u65E0\u6CD5\u8BBF\u95EE npm registry\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5\u3002");
3314
+ console.warn(" \u82E5\u9700\u5F3A\u5236\u91CD\u65B0\u5B89\u88C5\u5F53\u524D\u7248\u672C\uFF0C\u52A0 --force \u53C2\u6570\u3002");
3315
+ if (!options.force) {
3316
+ process.exit(1);
3317
+ }
3318
+ } else {
3319
+ console.log(`\u6700\u65B0\u7248\u672C\uFF1A${latest}`);
3320
+ }
3321
+ const shouldUpdate = options.force || (latest ? isNewer(current, latest) : false);
3322
+ if (!shouldUpdate && latest && !options.force) {
3323
+ console.log("\n\u2705 \u5DF2\u662F\u6700\u65B0\u7248\u672C\uFF0C\u65E0\u9700\u66F4\u65B0 CLI\u3002");
3324
+ console.log(" \u5982\u9700\u5F3A\u5236\u91CD\u65B0\u521D\u59CB\u5316 skill \u6587\u4EF6\uFF0C\u53EF\u52A0 --force \u53C2\u6570\u3002");
3325
+ }
3326
+ const targetVersion = latest ?? current;
3327
+ if (shouldUpdate && latest) {
3328
+ console.log(`
3329
+ \u2B06\uFE0F \u6B63\u5728\u66F4\u65B0 CLI \u81F3 ${targetVersion} \u2026`);
3330
+ } else if (options.force) {
3331
+ console.log(`
3332
+ \u{1F504} \u5F3A\u5236\u91CD\u65B0\u5B89\u88C5\u5F53\u524D\u7248\u672C ${current} \u2026`);
3333
+ }
3334
+ if ((shouldUpdate || options.force) && isNpmGlobalInstall()) {
3335
+ try {
3336
+ const result = spawnSync("npm", ["install", "-g", `${PKG_NAME2}@${targetVersion}`], {
3337
+ stdio: "inherit",
3338
+ shell: false
3339
+ });
3340
+ if (result.status !== 0) {
3341
+ throw new Error(`npm install \u9000\u51FA\u7801\uFF1A${result.status ?? "unknown"}`);
3342
+ }
3343
+ console.log("\n\u2705 CLI \u66F4\u65B0\u6210\u529F\uFF01");
3344
+ } catch (e) {
3345
+ console.error(`
3346
+ \u274C npm \u5B89\u88C5\u5931\u8D25\uFF1A${e.message}`);
3347
+ console.error(" \u5982\u679C\u662F\u6743\u9650\u95EE\u9898\uFF0C\u5C1D\u8BD5\u52A0 sudo\uFF08Unix\uFF09\u6216\u4EE5\u7BA1\u7406\u5458\u8EAB\u4EFD\u8FD0\u884C\u3002");
3348
+ process.exit(1);
3349
+ }
3350
+ } else if (shouldUpdate || options.force) {
3351
+ console.log(
3352
+ "\n\u26A0\uFE0F \u68C0\u6D4B\u5230 CLI \u5E76\u975E\u901A\u8FC7 npm \u5168\u5C40\u5B89\u88C5\uFF08\u53EF\u80FD\u662F\u672C\u5730\u5F00\u53D1\u6A21\u5F0F\uFF09\u3002\n \u8DF3\u8FC7 npm \u66F4\u65B0\uFF0C\u4EC5\u91CD\u65B0\u521D\u59CB\u5316 skill \u6587\u4EF6\u3002\n \u82E5\u9700\u6B63\u5F0F\u5B89\u88C5\uFF0C\u8BF7\u8FD0\u884C\uFF1Anpm install -g siluzan-website-cli"
3353
+ );
3354
+ }
3355
+ if (options.skipInit) return;
3356
+ const targets = readInstalledTargets();
3357
+ if (targets.length === 0) {
3358
+ console.log(
3359
+ "\n\u26A0\uFE0F \u672A\u627E\u5230\u4E0A\u6B21\u5B89\u88C5\u8BB0\u5F55\u3002\n \u8BF7\u624B\u52A8\u8FD0\u884C\uFF1Asiluzan-website init --ai <\u5E73\u53F0> --force\n"
3360
+ );
3361
+ return;
3362
+ }
3363
+ console.log(`
3364
+ \u{1F504} \u6B63\u5728\u66F4\u65B0 ${targets.length} \u5904 skill \u5B89\u88C5\u4F4D\u7F6E \u2026`);
3365
+ let failCount = 0;
3366
+ for (const entry of targets) {
3367
+ const label = entry.target === "custom" ? entry.dir ?? "unknown" : entry.target;
3368
+ const cwd = entry.cwd || os3.homedir();
3369
+ console.log(`
3370
+ [${label}]`);
3371
+ try {
3372
+ if (entry.target === "custom" && entry.dir) {
3373
+ await runInit({
3374
+ cwd: os3.homedir(),
3375
+ aiTargets: "",
3376
+ dir: entry.dir,
3377
+ force: true
3378
+ });
3379
+ } else {
3380
+ await runInit({
3381
+ cwd,
3382
+ aiTargets: entry.target,
3383
+ force: true
3384
+ });
3385
+ }
3386
+ } catch (e) {
3387
+ failCount++;
3388
+ console.error(` \u274C \u66F4\u65B0\u5931\u8D25\uFF1A${e.message}`);
3389
+ }
3390
+ }
3391
+ if (failCount > 0) {
3392
+ console.error(
3393
+ `
3394
+ \u26A0\uFE0F ${targets.length} \u5904\u5B89\u88C5\u4F4D\u7F6E\u4E2D\u6709 ${failCount} \u5904\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u4E0A\u65B9\u9519\u8BEF\u4FE1\u606F\u3002`
3395
+ );
3396
+ process.exit(1);
3397
+ }
3398
+ console.log("\n\u2705 \u5168\u90E8 skill \u6587\u4EF6\u5DF2\u5237\u65B0\u3002");
3399
+ console.log(" \u5982\u679C AI \u52A9\u624B\u6B63\u5728\u8FD0\u884C\uFF0C\u5EFA\u8BAE\u91CD\u542F\u4EE5\u4F7F\u65B0 skill \u6587\u4EF6\u751F\u6548\u3002\n");
3400
+ }
3401
+ function register2(program2) {
3402
+ program2.command("update").description("\u68C0\u67E5\u5E76\u66F4\u65B0 siluzan-website-cli\uFF0C\u540C\u6B65\u5237\u65B0\u5DF2\u5B89\u88C5 Skill \u6587\u4EF6").option("--force", "\u8DF3\u8FC7\u7248\u672C\u6BD4\u8F83\uFF0C\u5F3A\u5236\u91CD\u65B0\u5B89\u88C5\u5E76\u5237\u65B0 skill \u6587\u4EF6", false).option("--skip-init", "\u4EC5\u66F4\u65B0 CLI\uFF0C\u4E0D\u91CD\u65B0\u521D\u59CB\u5316 skill \u6587\u4EF6", false).action(async (opts) => {
3403
+ await runUpdate({ force: opts.force, skipInit: opts.skipInit });
3404
+ });
3405
+ }
3406
+
3407
+ // src/commands/login.ts
3408
+ import * as readline from "readline";
3409
+ import * as os4 from "os";
3410
+ function parseAllowedServices(raw) {
3411
+ const allowed = ["CSO", "TSO", "CUT"];
3412
+ if (!raw) return ["CSO", "TSO", "CUT"];
3413
+ const parts = raw.split(",").map((s) => s.trim().toUpperCase()).filter(Boolean);
3414
+ const result = [];
3415
+ for (const p of parts) {
3416
+ if (!allowed.includes(p)) {
3417
+ throw new Error(`\u672A\u77E5\u670D\u52A1\u540D\u300C${p}\u300D\uFF0C\u53EF\u9009\uFF1A${allowed.join(" / ")}`);
3418
+ }
3419
+ if (!result.includes(p)) result.push(p);
3420
+ }
3421
+ if (result.length === 0) throw new Error("--services \u81F3\u5C11\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u670D\u52A1");
3422
+ return result;
3423
+ }
3424
+ function defaultApiKeyName() {
3425
+ let host = "unknown";
3426
+ try {
3427
+ host = os4.hostname() || "unknown";
3428
+ } catch {
3429
+ }
3430
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
3431
+ return `CLI - ${host} - ${today}`;
3432
+ }
3433
+ function validateAndNormalizePhone(rawInput) {
3434
+ const rawPhone = rawInput?.trim() ?? "";
3435
+ if (!isValidChinaPhone(rawPhone)) {
3436
+ console.error(
3437
+ "\n\u274C \u624B\u673A\u53F7\u683C\u5F0F\u9519\u8BEF\uFF1A\u4EC5\u652F\u6301\u4E2D\u56FD\u5927\u9646\u624B\u673A\u53F7\uFF0C\u53EF\u5E26\u6216\u4E0D\u5E26 +86\uFF08\u5982 13800138000\uFF09\u3002\n"
3438
+ );
3439
+ process.exit(1);
3440
+ }
3441
+ return normalizeChinaPhone(rawPhone);
3442
+ }
3443
+ function resolveSsoCsoBase() {
3444
+ const apiBase = process.env.SILUZAN_WEBSITE_API_BASE ?? DEFAULT_API_BASE;
3445
+ const ssoBaseUrl = deriveSsoBaseUrl(apiBase);
3446
+ const csoBaseUrl = process.env.SILUZAN_CSO_BASE ?? DEFAULT_CSO_BASE ?? deriveCsoApiBaseUrl(apiBase);
3447
+ return { ssoBaseUrl, csoBaseUrl };
3448
+ }
3449
+ async function runSendLoginCode(opts) {
3450
+ if (skipAuthSetupInAgentEnv("siluzan-website send-login-code")) return;
3451
+ const phone = validateAndNormalizePhone(opts.phone);
3452
+ const { ssoBaseUrl } = resolveSsoCsoBase();
3453
+ console.log("\n\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
3454
+ console.log(" Siluzan Website \u53D1\u9001\u767B\u5F55\u77ED\u4FE1\u9A8C\u8BC1\u7801");
3455
+ console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n");
3456
+ console.log(` \u624B\u673A\u53F7 : ${phone}`);
3457
+ console.log(` SSO : ${ssoBaseUrl}
3458
+ `);
3459
+ console.log("\u2192 \u6B63\u5728\u5411\u624B\u673A\u53D1\u9001\u9A8C\u8BC1\u7801...");
3460
+ const r = await sendPhoneLoginCode({ ssoBaseUrl, phone, verbose: opts.verbose });
3461
+ if (!r.ok) {
3462
+ console.error(`
3463
+ \u274C \u77ED\u4FE1\u9A8C\u8BC1\u7801\u53D1\u9001\u5931\u8D25\uFF1A${r.message || "(\u540E\u7AEF\u672A\u8FD4\u56DE\u539F\u56E0)"}
3464
+ `);
3465
+ process.exit(1);
3466
+ }
3467
+ console.log("\u2713 \u9A8C\u8BC1\u7801\u5DF2\u53D1\u9001\uFF0810 \u5206\u949F\u5185\u6709\u6548\uFF09\u3002\n");
3468
+ console.log("\u4E0B\u4E00\u6B65\uFF1A\n");
3469
+ console.log(` siluzan-website login --phone ${phone} --code <6\u4F4D\u9A8C\u8BC1\u7801>
3470
+ `);
3471
+ }
3472
+ async function runPhoneLogin(opts) {
3473
+ const phone = validateAndNormalizePhone(opts.phone);
3474
+ const code = opts.code?.trim() ?? "";
3475
+ if (!code) {
3476
+ console.error("\n\u274C \u7F3A\u5C11 --code\u3002\u8BF7\u6309\u4E24\u6BB5\u5F0F\u6267\u884C\uFF1A\n");
3477
+ console.error(` 1) siluzan-website send-login-code --phone ${phone}`);
3478
+ console.error(` 2) siluzan-website login --phone ${phone} --code <6\u4F4D\u9A8C\u8BC1\u7801>
3479
+ `);
3480
+ process.exit(1);
3481
+ }
3482
+ let allowedServices;
3483
+ try {
3484
+ allowedServices = parseAllowedServices(opts.services);
3485
+ } catch (e) {
3486
+ console.error(`
3487
+ \u274C ${e instanceof Error ? e.message : String(e)}
3488
+ `);
3489
+ process.exit(1);
3490
+ return;
3491
+ }
3492
+ const { ssoBaseUrl, csoBaseUrl } = resolveSsoCsoBase();
3493
+ const apiKeyName = opts.name ?? defaultApiKeyName();
3494
+ console.log("\n\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
3495
+ console.log(" Siluzan Website \u767B\u5F55\uFF08\u624B\u673A\u53F7 \u2192 API Key\uFF09");
3496
+ console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n");
3497
+ console.log(` \u624B\u673A\u53F7 : ${phone}`);
3498
+ console.log("\u2192 \u6B63\u5728\u6821\u9A8C\u9A8C\u8BC1\u7801\u5E76\u521B\u5EFA API Key...");
3499
+ try {
3500
+ const created = await issueApiKeyWithPhoneCode({
3501
+ ssoBaseUrl,
3502
+ csoBaseUrl,
3503
+ phone,
3504
+ code,
3505
+ apiKeyName,
3506
+ validDays: opts.expiresAt ? void 0 : opts.validDays ?? 90,
3507
+ expiresAt: opts.expiresAt,
3508
+ allowedServices,
3509
+ verbose: opts.verbose
3510
+ });
3511
+ writeSharedConfig({ apiKey: created.rawKey });
3512
+ console.log("\n\u2705 \u767B\u5F55\u6210\u529F\uFF0CAPI Key \u5DF2\u4FDD\u5B58");
3513
+ console.log(` Key ID : ${created.id}`);
3514
+ console.log(` Key (\u8131\u654F) : ${maskSecret(created.rawKey)}`);
3515
+ console.log(` \u914D\u7F6E\u6587\u4EF6 : ${CONFIG_FILE}`);
3516
+ console.log("\n\u73B0\u5728\u53EF\u4EE5\u8FD0\u884C\uFF1Asiluzan-website sites list\n");
3517
+ } catch (e) {
3518
+ const msg = e instanceof Error ? e.message : String(e);
3519
+ console.error(`
3520
+ \u274C \u767B\u5F55\u5931\u8D25\uFF1A${msg}`);
3521
+ if (/手机未注册|未注册/.test(msg)) {
3522
+ console.error(`
3523
+ \u8BF7\u5148\u5728\u7F51\u9875\u6CE8\u518C\uFF1A${DEFAULT_WEB_BASE}
3524
+ `);
3525
+ }
3526
+ process.exit(1);
3527
+ }
3528
+ }
3529
+ async function runLogin(opts = {}) {
3530
+ if (skipAuthSetupInAgentEnv("siluzan-website login")) return;
3531
+ if (opts.apiKey !== void 0) {
3532
+ const key = opts.apiKey.trim();
3533
+ if (!key) {
3534
+ console.error("\n\u274C API Key \u4E0D\u80FD\u4E3A\u7A7A\u3002\n");
3535
+ process.exit(1);
3536
+ }
3537
+ writeSharedConfig({ apiKey: key });
3538
+ console.log(`
3539
+ \u2705 API Key \u5DF2\u4FDD\u5B58\uFF08${maskSecret(key)}\uFF09`);
3540
+ console.log(` \u914D\u7F6E\u6587\u4EF6\uFF1A${CONFIG_FILE}
3541
+ `);
3542
+ return;
3543
+ }
3544
+ if (opts.phone !== void 0) {
3545
+ await runPhoneLogin(opts);
3546
+ return;
3547
+ }
3548
+ const shared = readSharedConfig();
3549
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
3550
+ const prompt = (q) => new Promise((res) => rl.question(q, (a) => res(a.trim())));
3551
+ console.log("\n\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
3552
+ console.log(" Siluzan Website \u767B\u5F55\uFF08API Key\uFF09");
3553
+ console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n");
3554
+ console.log("Skill / Agent \u53EA\u652F\u6301 API Key\u3002\u63A8\u8350\u624B\u673A\u53F7\u4E24\u6BB5\u5F0F\uFF1A");
3555
+ console.log(" siluzan-website send-login-code --phone <\u624B\u673A\u53F7>");
3556
+ console.log(" siluzan-website login --phone <\u624B\u673A\u53F7> --code <\u9A8C\u8BC1\u7801>\n");
3557
+ console.log(`\u6216\u524D\u5F80 ${DEFAULT_WEB_BASE}/v3/foreign_trade/settings/apiKeyManagement \u521B\u5EFA\u540E\u7C98\u8D34\u3002
3558
+ `);
3559
+ if (shared.apiKey) {
3560
+ console.log(`\u5DF2\u68C0\u6D4B\u5230 API Key\uFF08${maskSecret(shared.apiKey)}\uFF09\u3002`);
3561
+ const ans = await prompt("\u662F\u5426\u8986\u76D6\uFF1F(y/N) ");
3562
+ if (ans.toLowerCase() !== "y") {
3563
+ rl.close();
3564
+ console.log("\n\u5DF2\u53D6\u6D88\u3002\n");
3565
+ return;
3566
+ }
3567
+ }
3568
+ let apiKey = "";
3569
+ for (let i = 0; i < 3; i++) {
3570
+ const input = await prompt("\u7C98\u8D34 API Key\uFF1A");
3571
+ if (input) {
3572
+ apiKey = input;
3573
+ break;
3574
+ }
3575
+ console.log("\u274C API Key \u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u8BF7\u91CD\u8BD5");
3576
+ }
3577
+ rl.close();
3578
+ if (!apiKey) {
3579
+ console.error("\n\u274C \u591A\u6B21\u8F93\u5165\u65E0\u6548\u3002\n");
3580
+ process.exit(1);
3581
+ }
3582
+ writeSharedConfig({ apiKey });
3583
+ console.log(`
3584
+ \u2705 API Key \u5DF2\u4FDD\u5B58\uFF08${maskSecret(apiKey)}\uFF09`);
3585
+ console.log(" \u73B0\u5728\u53EF\u4EE5\u8FD0\u884C\uFF1Asiluzan-website sites list\n");
3586
+ }
3587
+ function register3(program2) {
3588
+ program2.command("login").description("\u767B\u5F55\u5E76\u4FDD\u5B58 API Key\uFF08\u4E0E CSO/TSO \u5171\u7528 ~/.siluzan/config.json\uFF09").option("--api-key <key>", "\u76F4\u63A5\u4FDD\u5B58 API Key").option("--phone <phone>", "\u624B\u673A\u53F7\u767B\u5F55\uFF08\u9700\u914D\u5408 --code\uFF09").option("--code <code>", "\u77ED\u4FE1\u9A8C\u8BC1\u7801").option("--name <name>", "\u81EA\u52A8\u521B\u5EFA\u7684 API Key \u540D\u79F0").option("--valid-days <days>", "API Key \u6709\u6548\u671F\u5929\u6570", parseInt).option("--expires-at <iso>", "API Key \u7EDD\u5BF9\u8FC7\u671F\u65F6\u95F4").option("--services <services>", "API Key \u670D\u52A1\u5217\u8868\uFF0C\u9ED8\u8BA4 CSO,TSO,CUT").option("--verbose", "\u8F93\u51FA\u767B\u5F55 HTTP URL", false).action(async (opts) => {
3589
+ await runLogin(opts);
3590
+ });
3591
+ program2.command("send-login-code").description("\u53D1\u9001\u624B\u673A\u53F7\u767B\u5F55\u77ED\u4FE1\u9A8C\u8BC1\u7801\uFF08\u4E24\u6BB5\u5F0F\u767B\u5F55\u7B2C 1 \u6B65\uFF09").requiredOption("--phone <phone>", "\u4E2D\u56FD\u5927\u9646\u624B\u673A\u53F7").option("--verbose", "\u8F93\u51FA\u767B\u5F55 HTTP URL", false).action(async (opts) => {
3592
+ await runSendLoginCode(opts);
3593
+ });
3594
+ }
3595
+
3596
+ // src/commands/config.ts
3597
+ function cmdConfigShow() {
3598
+ const shared = readSharedConfig();
3599
+ const { apiKey: effectiveApiKeyRaw } = resolveSiluzanCredentials({
3600
+ configApiKey: shared.apiKey,
3601
+ configAuthToken: shared.authToken
3602
+ });
3603
+ const effectiveApiKey = effectiveApiKeyRaw ?? "";
3604
+ const envApiKey = process.env.SILUZAN_API_KEY;
3605
+ if (!effectiveApiKey) {
3606
+ if (isSiluzanAgentEnv()) {
3607
+ console.log(
3608
+ "\nSiluzan Agent \u73AF\u5883\u3002\u51ED\u636E\u5E94\u7531\u6C99\u7BB1\u6CE8\u5165 SILUZAN_API_KEY\uFF0C\u65E0\u9700 login\u3002\n"
3609
+ );
3610
+ return;
3611
+ }
3612
+ console.log(
3613
+ `
3614
+ \u5C1A\u672A\u914D\u7F6E API Key\u3002
3615
+
3616
+ \u6CE8\u518C\uFF1A${DEFAULT_WEB_BASE}
3617
+ \u767B\u5F55\uFF1Asiluzan-website login
3618
+ \u6216\u73AF\u5883\u53D8\u91CF\uFF1ASILUZAN_API_KEY
3619
+ `
3620
+ );
3621
+ return;
3622
+ }
3623
+ const apiBaseUrl = process.env.SILUZAN_WEBSITE_API_BASE ?? DEFAULT_API_BASE;
3624
+ console.log("\n\u5F53\u524D\u914D\u7F6E\uFF1A");
3625
+ console.log(` apiBaseUrl : ${apiBaseUrl}`);
3626
+ const src = envApiKey ? "env:SILUZAN_API_KEY" : "config.json";
3627
+ console.log(` apiKey : ${maskSecret(effectiveApiKey)} [${src}] \u2190 Skill \u552F\u4E00\u9274\u6743\u65B9\u5F0F`);
3628
+ console.log(`
3629
+ \u914D\u7F6E\u6587\u4EF6\uFF1A${CONFIG_FILE}
3630
+ `);
3631
+ }
3632
+ function cmdConfigSet(opts) {
3633
+ if (skipAuthSetupInAgentEnv("siluzan-website config set")) return;
3634
+ if (!opts.apiKey) {
3635
+ console.error("\n\u274C \u8BF7\u63D0\u4F9B --api-key\n");
3636
+ process.exit(1);
3637
+ }
3638
+ writeSharedConfig({ apiKey: opts.apiKey });
3639
+ console.log(`
3640
+ \u2705 \u914D\u7F6E\u5DF2\u4FDD\u5B58\u5230 ${CONFIG_FILE}`);
3641
+ console.log(` apiKey: ${maskSecret(opts.apiKey)}
3642
+ `);
3643
+ }
3644
+ function register4(program2) {
3645
+ const configCmd = program2.command("config").description("\u67E5\u770B\u6216\u8BBE\u7F6E API Key\uFF08~/.siluzan/config.json\uFF0C\u4E0E CSO/TSO \u5171\u7528\uFF09");
3646
+ configCmd.command("show").description("\u5C55\u793A\u5F53\u524D\u5DF2\u4FDD\u5B58\u7684\u914D\u7F6E\uFF08\u51ED\u636E\u8131\u654F\uFF09").action(() => cmdConfigShow());
3647
+ configCmd.command("set").description("\u4FDD\u5B58 API Key").option("--api-key <key>", "API Key").action((opts) => {
3648
+ cmdConfigSet({ apiKey: opts.apiKey });
3649
+ });
3650
+ configCmd.command("clear").description("\u6E05\u7A7A\u5DF2\u4FDD\u5B58\u7684\u51ED\u636E").action(() => {
3651
+ if (skipAuthSetupInAgentEnv("siluzan-website config clear")) return;
3652
+ clearSharedConfig();
3653
+ console.log(`
3654
+ \u2705 \u51ED\u636E\u5DF2\u6E05\u7A7A\uFF08${CONFIG_FILE}\uFF09
3655
+ `);
3656
+ });
3657
+ }
3658
+
3659
+ // src/utils/auth.ts
3660
+ function loadConfig() {
3661
+ const shared = readSharedConfig();
3662
+ const { apiKey } = resolveSiluzanCredentials({
3663
+ configApiKey: shared.apiKey,
3664
+ configAuthToken: shared.authToken
3665
+ });
3666
+ if (!apiKey) {
3667
+ printAuthMissingHelp("siluzan-website");
3668
+ }
3669
+ const apiBaseUrl = process.env.SILUZAN_WEBSITE_API_BASE ?? DEFAULT_API_BASE;
3670
+ const csoBaseUrl = process.env.SILUZAN_CSO_BASE ?? DEFAULT_CSO_BASE;
3671
+ const apiErr = validateBaseUrl(apiBaseUrl);
3672
+ if (apiErr) {
3673
+ console.error(`
3674
+ \u274C apiBaseUrl \u4E0D\u5408\u6CD5\uFF1A${apiErr}`);
3675
+ process.exit(1);
3676
+ }
3677
+ const csoErr = validateBaseUrl(csoBaseUrl);
3678
+ if (csoErr) {
3679
+ console.error(`
3680
+ \u274C csoBaseUrl \u4E0D\u5408\u6CD5\uFF1A${csoErr}`);
3681
+ process.exit(1);
3682
+ }
3683
+ return {
3684
+ apiBaseUrl,
3685
+ csoBaseUrl,
3686
+ authToken: "",
3687
+ apiKey,
3688
+ dataPermission: process.env.SILUZAN_DATA_PERMISSION ?? shared.dataPermission
3689
+ };
3690
+ }
3691
+ function apiFetch2(url, config, options = {}, verbose = false) {
3692
+ return apiFetch(url, config, options, verbose);
3693
+ }
3694
+
3695
+ // src/utils/site-url.ts
3696
+ function normalizeRegion(raw) {
3697
+ const value = (raw ?? "").trim().toLowerCase();
3698
+ if (value === "cn" || value === "\u4E2D\u56FD") return "cn";
3699
+ if (value === "us" || value === "\u7F8E\u56FD") return "us";
3700
+ return "";
3701
+ }
3702
+ function resolvePlatformSiteUrl(guid, region, stage = DEFAULT_SITE_STAGE) {
3703
+ const normalized = normalizeRegion(region);
3704
+ if (!guid || !normalized) return "";
3705
+ if (normalized === "cn") {
3706
+ return `https://${guid}-${stage}.cn.siluzan.com`;
3707
+ }
3708
+ return `https://${guid}-${stage}.admin.mysiluzan.com`;
3709
+ }
3710
+ function trimTrailingSlash(url) {
3711
+ return url.replace(/\/+$/, "");
3712
+ }
3713
+
3714
+ // src/commands/sites.ts
3715
+ function asRecord(value) {
3716
+ return value && typeof value === "object" ? value : null;
3717
+ }
3718
+ function readString(obj, key) {
3719
+ if (!obj) return "";
3720
+ const v = obj[key];
3721
+ return typeof v === "string" ? v : v == null ? "" : String(v);
3722
+ }
3723
+ function normalizeSiteItem(raw) {
3724
+ const item = asRecord(raw);
3725
+ if (!item) return null;
3726
+ const inner = asRecord(item.s) ?? item;
3727
+ const guid = readString(inner, "guid") || readString(item, "guid");
3728
+ if (!guid) return null;
3729
+ const region = readString(inner, "region") || readString(item, "region");
3730
+ return {
3731
+ guid,
3732
+ name: readString(inner, "name") || readString(item, "name") || guid,
3733
+ region,
3734
+ siteState: readString(inner, "siteState") || readString(item, "siteState"),
3735
+ url: resolvePlatformSiteUrl(guid, region),
3736
+ accepted: typeof item.accepted === "boolean" ? item.accepted : void 0
3737
+ };
3738
+ }
3739
+ function unwrapSiteList(raw) {
3740
+ if (Array.isArray(raw)) return raw;
3741
+ const obj = asRecord(raw);
3742
+ if (!obj) return [];
3743
+ if (Array.isArray(obj.data)) return obj.data;
3744
+ const data = asRecord(obj.data);
3745
+ if (data) {
3746
+ if (Array.isArray(data.items)) return data.items;
3747
+ if (Array.isArray(data.list)) return data.list;
3748
+ }
3749
+ if (Array.isArray(obj.items)) return obj.items;
3750
+ if (Array.isArray(obj.list)) return obj.list;
3751
+ return [];
3752
+ }
3753
+ async function fetchMySites(config, options = {}) {
3754
+ const params = new URLSearchParams({
3755
+ pageNo: "1",
3756
+ pageSize: "10000"
3757
+ });
3758
+ if (options.query) params.set("query", options.query);
3759
+ const url = `${config.apiBaseUrl}/query/profile/steward-individual/all-sites?${params.toString()}`;
3760
+ const raw = await apiFetch2(url, config, {}, options.verbose);
3761
+ return unwrapSiteList(raw).map(normalizeSiteItem).filter((s) => Boolean(s));
3762
+ }
3763
+ async function resolveSite(config, opts) {
3764
+ if (opts.url?.trim()) {
3765
+ const url = opts.url.trim().replace(/\/+$/, "");
3766
+ return {
3767
+ guid: opts.site?.trim() || "",
3768
+ name: url,
3769
+ region: "",
3770
+ siteState: "",
3771
+ url
3772
+ };
3773
+ }
3774
+ const key = opts.site?.trim();
3775
+ if (!key) {
3776
+ console.error("\n\u274C \u8BF7\u63D0\u4F9B --site <guid \u6216\u7AD9\u70B9\u540D> \u6216 --url <\u7AD9\u70B9\u5730\u5740>\n");
3777
+ process.exit(1);
3778
+ }
3779
+ const sites = await fetchMySites(config, { verbose: opts.verbose });
3780
+ const exact = sites.find((s) => s.guid === key);
3781
+ if (exact) return exact;
3782
+ const nameHits = sites.filter((s) => s.name.toLowerCase().includes(key.toLowerCase()));
3783
+ if (nameHits.length === 1) return nameHits[0];
3784
+ if (nameHits.length > 1) {
3785
+ console.error(`
3786
+ \u274C \u7AD9\u70B9\u540D\u300C${key}\u300D\u5339\u914D\u5230 ${nameHits.length} \u4E2A\uFF0C\u8BF7\u6539\u7528 --site <guid>\uFF1A`);
3787
+ for (const s of nameHits) console.error(` ${s.guid} ${s.name}`);
3788
+ console.error();
3789
+ process.exit(1);
3790
+ }
3791
+ console.error(`
3792
+ \u274C \u672A\u627E\u5230\u7AD9\u70B9\u300C${key}\u300D\u3002\u5148\u8FD0\u884C siluzan-website sites list \u786E\u8BA4 guid\u3002
3793
+ `);
3794
+ process.exit(1);
3795
+ }
3796
+ async function runSitesList(options) {
3797
+ const config = loadConfig();
3798
+ let sites;
3799
+ try {
3800
+ sites = await fetchMySites(config, { query: options.query, verbose: options.verbose });
3801
+ } catch (e) {
3802
+ console.error(`
3803
+ \u274C \u83B7\u53D6\u7AD9\u70B9\u5217\u8868\u5931\u8D25\uFF1A${e.message}`);
3804
+ if (!options.verbose) console.error(" \u52A0 --verbose \u53EF\u67E5\u770B\u8BE6\u7EC6\u9519\u8BEF");
3805
+ process.exit(1);
3806
+ return;
3807
+ }
3808
+ if (options.json) {
3809
+ console.log(JSON.stringify({ total: sites.length, sites }, null, 2));
3810
+ return;
3811
+ }
3812
+ if (sites.length === 0) {
3813
+ console.log("\n\u5F53\u524D\u8D26\u53F7\u4E0B\u6CA1\u6709 WordPress \u7AD9\u70B9\u3002");
3814
+ return;
3815
+ }
3816
+ const columns = [
3817
+ { key: "guid", header: "guid" },
3818
+ { key: "name", header: "\u540D\u79F0" },
3819
+ { key: "region", header: "\u533A\u57DF" },
3820
+ { key: "siteState", header: "\u72B6\u6001" },
3821
+ { key: "url", header: "\u5E73\u53F0\u5730\u5740" }
3822
+ ];
3823
+ const rows = sites.map((s) => ({
3824
+ guid: s.guid,
3825
+ name: s.name,
3826
+ region: s.region,
3827
+ siteState: s.siteState || "-",
3828
+ url: s.url || "-"
3829
+ }));
3830
+ console.log(`
3831
+ \u7AD9\u70B9\u5217\u8868\uFF08\u5171 ${sites.length} \u4E2A\uFF09
3832
+ `);
3833
+ printCliTable(rows, columns);
3834
+ console.log("\n\u540E\u7EED\uFF1Asiluzan-website pages list --site <guid>\n");
3835
+ }
3836
+ function register5(program2) {
3837
+ const sites = program2.command("sites").description("WordPress \u7AD9\u70B9\u67E5\u8BE2");
3838
+ sites.command("list").description("\u5217\u51FA\u5F53\u524D\u8D26\u53F7\u4E0B\u7684 WordPress \u7AD9\u70B9").option("-q, --query <keyword>", "\u6309\u540D\u79F0\u641C\u7D22").option("--json", "\u8F93\u51FA JSON", false).option("--verbose", "\u8F93\u51FA\u8BF7\u6C42\u8BE6\u60C5", false).action(async (opts) => {
3839
+ await runSitesList(opts);
3840
+ });
3841
+ }
3842
+
3843
+ // src/commands/pages.ts
3844
+ import * as fs6 from "fs";
3845
+ function pageTitle(page) {
3846
+ if (typeof page.title === "string") return page.title;
3847
+ return page.title?.rendered ?? "";
3848
+ }
3849
+ function readTextOption(inline, filePath) {
3850
+ if (filePath) {
3851
+ try {
3852
+ return fs6.readFileSync(filePath, "utf8");
3853
+ } catch (e) {
3854
+ console.error(`
3855
+ \u274C \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6 ${filePath}\uFF1A${e.message}
3856
+ `);
3857
+ process.exit(1);
3858
+ }
3859
+ }
3860
+ return inline ?? "";
3861
+ }
3862
+ async function runPagesList(opts) {
3863
+ const config = loadConfig();
3864
+ const site = await resolveSite(config, opts);
3865
+ const base = trimTrailingSlash(site.url);
3866
+ const api = `${base}/wp-json/wp/v2/pages?per_page=100&status=publish,draft,private,pending`;
3867
+ let pages;
3868
+ try {
3869
+ pages = await apiFetch2(api, config, {}, opts.verbose);
3870
+ } catch (e) {
3871
+ console.error(`
3872
+ \u274C \u83B7\u53D6\u9875\u9762\u5931\u8D25\uFF1A${e.message}`);
3873
+ console.error(` \u7AD9\u70B9\uFF1A${base}`);
3874
+ process.exit(1);
3875
+ return;
3876
+ }
3877
+ if (!Array.isArray(pages)) {
3878
+ console.error("\n\u274C \u7AD9\u70B9\u8FD4\u56DE\u7684\u9875\u9762\u5217\u8868\u683C\u5F0F\u5F02\u5E38\n");
3879
+ process.exit(1);
3880
+ }
3881
+ if (opts.json) {
3882
+ console.log(
3883
+ JSON.stringify(
3884
+ {
3885
+ site: { guid: site.guid, name: site.name, url: site.url },
3886
+ total: pages.length,
3887
+ pages: pages.map((p) => ({
3888
+ id: p.id,
3889
+ title: pageTitle(p),
3890
+ slug: p.slug ?? "",
3891
+ status: p.status ?? "",
3892
+ link: p.link ?? "",
3893
+ modified: p.modified ?? ""
3894
+ }))
3895
+ },
3896
+ null,
3897
+ 2
3898
+ )
3899
+ );
3900
+ return;
3901
+ }
3902
+ if (pages.length === 0) {
3903
+ console.log(`
3904
+ \u7AD9\u70B9 ${site.name} \u6682\u65E0\u9875\u9762\u3002\u53EF\u7528 pages add \u65B0\u589E\u3002
3905
+ `);
3906
+ return;
3907
+ }
3908
+ const columns = [
3909
+ { key: "id", header: "id" },
3910
+ { key: "title", header: "\u6807\u9898" },
3911
+ { key: "status", header: "\u72B6\u6001" },
3912
+ { key: "link", header: "\u94FE\u63A5" }
3913
+ ];
3914
+ console.log(`
3915
+ ${site.name} \u9875\u9762\uFF08${pages.length}\uFF09
3916
+ `);
3917
+ printCliTable(
3918
+ pages.map((p) => ({
3919
+ id: String(p.id),
3920
+ title: pageTitle(p) || "(\u65E0\u6807\u9898)",
3921
+ status: p.status ?? "-",
3922
+ link: p.link ?? "-"
3923
+ })),
3924
+ columns
3925
+ );
3926
+ console.log();
3927
+ }
3928
+ async function runPagesWrite(mode, opts) {
3929
+ const config = loadConfig();
3930
+ const site = await resolveSite(config, opts);
3931
+ const base = trimTrailingSlash(site.url);
3932
+ const title = opts.title?.trim() ?? "";
3933
+ const content = readTextOption(opts.content, opts.contentFile);
3934
+ if (mode === "add" && !title) {
3935
+ console.error("\n\u274C \u65B0\u589E\u9875\u9762\u5FC5\u987B\u63D0\u4F9B --title\n");
3936
+ process.exit(1);
3937
+ }
3938
+ if (!content.trim()) {
3939
+ console.error("\n\u274C \u8BF7\u7528 --content \u6216 --content-file \u63D0\u4F9B HTML \u6B63\u6587\n");
3940
+ process.exit(1);
3941
+ }
3942
+ const body = {
3943
+ content,
3944
+ import_mode: "preserve"
3945
+ };
3946
+ if (title) body.title = title;
3947
+ const css = readTextOption(opts.css, opts.cssFile);
3948
+ if (css) body._custom_css = css;
3949
+ const js = readTextOption(opts.js, opts.jsFile);
3950
+ if (js) body._custom_javascript = js;
3951
+ if (mode === "add") body.post_type = opts.postType?.trim() || "page";
3952
+ const api = mode === "add" ? `${base}/wp-json/zionbuilder/v1/pages/add-visual-edit` : `${base}/wp-json/zionbuilder/v1/pages/${opts.id}/save-visual-edit`;
3953
+ if (mode === "update" && !opts.id) {
3954
+ console.error("\n\u274C \u66F4\u65B0\u9875\u9762\u5FC5\u987B\u63D0\u4F9B --id\uFF08\u5148 pages list \u67E5 id\uFF09\n");
3955
+ process.exit(1);
3956
+ }
3957
+ let result;
3958
+ try {
3959
+ result = await apiFetch2(
3960
+ api,
3961
+ config,
3962
+ { method: "POST", body: JSON.stringify(body) },
3963
+ opts.verbose
3964
+ );
3965
+ } catch (e) {
3966
+ console.error(`
3967
+ \u274C ${mode === "add" ? "\u65B0\u589E" : "\u66F4\u65B0"}\u9875\u9762\u5931\u8D25\uFF1A${e.message}
3968
+ `);
3969
+ process.exit(1);
3970
+ return;
3971
+ }
3972
+ if (result.error || result.success === false) {
3973
+ console.error(`
3974
+ \u274C ${result.error || result.message || "\u7AD9\u70B9\u62D2\u7EDD\u4FDD\u5B58"}
3975
+ `);
3976
+ process.exit(1);
3977
+ }
3978
+ console.log(mode === "add" ? "\n\u2705 \u9875\u9762\u5DF2\u521B\u5EFA" : "\n\u2705 \u9875\u9762\u5DF2\u66F4\u65B0");
3979
+ if (result.post_id) console.log(` post_id : ${result.post_id}`);
3980
+ if (result.url) console.log(` url : ${result.url}`);
3981
+ console.log(` \u7AD9\u70B9 : ${base}
3982
+ `);
3983
+ }
3984
+ function register6(program2) {
3985
+ const pages = program2.command("pages").description("WordPress \u9875\u9762\uFF08zionbuilder visual-edit\uFF09");
3986
+ pages.command("list").description("\u5217\u51FA\u7AD9\u70B9\u9875\u9762").option("-s, --site <guidOrName>", "\u7AD9\u70B9 guid \u6216\u540D\u79F0").option("--url <url>", "\u76F4\u63A5\u6307\u5B9A\u7AD9\u70B9\u5730\u5740\uFF08\u8DF3\u8FC7 all-sites\uFF09").option("--json", "\u8F93\u51FA JSON", false).option("--verbose", "\u8F93\u51FA\u8BF7\u6C42\u8BE6\u60C5", false).action(async (opts) => {
3987
+ await runPagesList(opts);
3988
+ });
3989
+ pages.command("add").description("\u7528 HTML \u65B0\u589E\u9875\u9762\uFF08\u8D70 add-visual-edit\uFF0C\u4F1A\u76F4\u63A5\u53D1\u5E03\uFF09").option("-s, --site <guidOrName>", "\u7AD9\u70B9 guid \u6216\u540D\u79F0").option("--url <url>", "\u76F4\u63A5\u6307\u5B9A\u7AD9\u70B9\u5730\u5740").option("-t, --title <title>", "\u9875\u9762\u6807\u9898").option("-c, --content <html>", "HTML \u6B63\u6587").option("--content-file <path>", "\u4ECE\u6587\u4EF6\u8BFB\u53D6 HTML \u6B63\u6587").option("--css <css>", "\u9644\u52A0 CSS").option("--css-file <path>", "\u4ECE\u6587\u4EF6\u8BFB\u53D6 CSS").option("--js <js>", "\u9644\u52A0 JS").option("--js-file <path>", "\u4ECE\u6587\u4EF6\u8BFB\u53D6 JS").option("--post-type <type>", "\u6587\u7AE0\u7C7B\u578B\uFF0C\u9ED8\u8BA4 page", "page").option("--verbose", "\u8F93\u51FA\u8BF7\u6C42\u8BE6\u60C5", false).action(async (opts) => {
3990
+ await runPagesWrite("add", opts);
3991
+ });
3992
+ pages.command("update").description("\u7528 HTML \u8986\u76D6\u5DF2\u6709\u9875\u9762\uFF08\u8D70 save-visual-edit\uFF0C\u4F1A\u76F4\u63A5\u53D1\u5E03\uFF09").option("-s, --site <guidOrName>", "\u7AD9\u70B9 guid \u6216\u540D\u79F0").option("--url <url>", "\u76F4\u63A5\u6307\u5B9A\u7AD9\u70B9\u5730\u5740").requiredOption("--id <id>", "\u9875\u9762 ID").option("-t, --title <title>", "\u65B0\u6807\u9898\uFF08\u53EF\u7701\u7565\uFF09").option("-c, --content <html>", "HTML \u6B63\u6587").option("--content-file <path>", "\u4ECE\u6587\u4EF6\u8BFB\u53D6 HTML \u6B63\u6587").option("--css <css>", "\u9644\u52A0 CSS").option("--css-file <path>", "\u4ECE\u6587\u4EF6\u8BFB\u53D6 CSS").option("--js <js>", "\u9644\u52A0 JS").option("--js-file <path>", "\u4ECE\u6587\u4EF6\u8BFB\u53D6 JS").option("--verbose", "\u8F93\u51FA\u8BF7\u6C42\u8BE6\u60C5", false).action(async (opts) => {
3993
+ await runPagesWrite("update", opts);
3994
+ });
3995
+ }
3996
+
3997
+ // src/commands/plugins.ts
3998
+ function pluginName(item) {
3999
+ if (typeof item.name === "string") return item.name;
4000
+ return item.name?.raw || item.name?.rendered || item.plugin || "";
4001
+ }
4002
+ async function resolveTarget(opts) {
4003
+ const config = loadConfig();
4004
+ const site = await resolveSite(config, opts);
4005
+ return { config, site, base: trimTrailingSlash(site.url) };
4006
+ }
4007
+ async function runPluginsList(opts) {
4008
+ const { config, site, base } = await resolveTarget(opts);
4009
+ const api = `${base}/wp-json/wp/v2/plugins`;
4010
+ let plugins;
4011
+ try {
4012
+ plugins = await apiFetch2(api, config, {}, opts.verbose);
4013
+ } catch (e) {
4014
+ console.error(`
4015
+ \u274C \u83B7\u53D6\u5DF2\u88C5\u63D2\u4EF6\u5931\u8D25\uFF1A${e.message}
4016
+ `);
4017
+ process.exit(1);
4018
+ return;
4019
+ }
4020
+ if (!Array.isArray(plugins)) {
4021
+ console.error("\n\u274C \u7AD9\u70B9\u8FD4\u56DE\u7684\u63D2\u4EF6\u5217\u8868\u683C\u5F0F\u5F02\u5E38\n");
4022
+ process.exit(1);
4023
+ }
4024
+ if (opts.json) {
4025
+ console.log(
4026
+ JSON.stringify(
4027
+ {
4028
+ site: { guid: site.guid, name: site.name, url: site.url },
4029
+ total: plugins.length,
4030
+ plugins: plugins.map((p) => ({
4031
+ plugin: p.plugin ?? "",
4032
+ name: pluginName(p),
4033
+ status: p.status ?? "",
4034
+ version: p.version ?? ""
4035
+ }))
4036
+ },
4037
+ null,
4038
+ 2
4039
+ )
4040
+ );
4041
+ return;
4042
+ }
4043
+ if (plugins.length === 0) {
4044
+ console.log(`
4045
+ \u7AD9\u70B9 ${site.name} \u672A\u8FD4\u56DE\u63D2\u4EF6\u3002
4046
+ `);
4047
+ return;
4048
+ }
4049
+ const columns = [
4050
+ { key: "plugin", header: "plugin" },
4051
+ { key: "name", header: "\u540D\u79F0" },
4052
+ { key: "status", header: "\u72B6\u6001" },
4053
+ { key: "version", header: "\u7248\u672C" }
4054
+ ];
4055
+ console.log(`
4056
+ ${site.name} \u5DF2\u88C5\u63D2\u4EF6\uFF08${plugins.length}\uFF09
4057
+ `);
4058
+ printCliTable(
4059
+ plugins.map((p) => ({
4060
+ plugin: p.plugin ?? "-",
4061
+ name: pluginName(p) || "-",
4062
+ status: p.status ?? "-",
4063
+ version: p.version ?? "-"
4064
+ })),
4065
+ columns
4066
+ );
4067
+ console.log();
4068
+ }
4069
+ async function runPluginsCatalog(opts) {
4070
+ const { config, site, base } = await resolveTarget(opts);
4071
+ const api = `${base}/wp-json/siluzan-helper/v1/plugins/catalog`;
4072
+ let res;
4073
+ try {
4074
+ res = await apiFetch2(api, config, {}, opts.verbose);
4075
+ } catch (e) {
4076
+ console.error(`
4077
+ \u274C \u83B7\u53D6\u63D2\u4EF6\u76EE\u5F55\u5931\u8D25\uFF1A${e.message}`);
4078
+ console.error(" \u9700\u8981\u7AD9\u70B9\u5DF2\u90E8\u7F72\u5E26 REST \u7684 siluzan-helper-plugin\u3002\n");
4079
+ process.exit(1);
4080
+ return;
4081
+ }
4082
+ const items = Array.isArray(res.items) ? res.items : [];
4083
+ if (opts.json) {
4084
+ console.log(
4085
+ JSON.stringify(
4086
+ { site: { guid: site.guid, name: site.name, url: site.url }, total: items.length, items },
4087
+ null,
4088
+ 2
4089
+ )
4090
+ );
4091
+ return;
4092
+ }
4093
+ if (items.length === 0) {
4094
+ console.log(`
4095
+ \u7AD9\u70B9 ${site.name} \u7684\u4E1D\u8DEF\u8D5E\u63D2\u4EF6\u76EE\u5F55\u4E3A\u7A7A\u3002
4096
+ `);
4097
+ return;
4098
+ }
4099
+ const columns = [
4100
+ { key: "slug", header: "slug" },
4101
+ { key: "name", header: "\u540D\u79F0" },
4102
+ { key: "new_version", header: "\u76EE\u5F55\u7248\u672C" },
4103
+ { key: "installed", header: "\u5DF2\u88C5" },
4104
+ { key: "active", header: "\u542F\u7528" }
4105
+ ];
4106
+ console.log(`
4107
+ ${site.name} \u53EF\u5B89\u88C5\u76EE\u5F55\uFF08${items.length}\uFF09
4108
+ `);
4109
+ printCliTable(
4110
+ items.map((p) => ({
4111
+ slug: p.slug || p.plugin || "-",
4112
+ name: p.name || "-",
4113
+ new_version: p.new_version || "-",
4114
+ installed: p.installed ? "yes" : "no",
4115
+ active: p.active ? "yes" : "no"
4116
+ })),
4117
+ columns
4118
+ );
4119
+ console.log("\n\u5B89\u88C5\uFF1Asiluzan-website plugins install --site <guid> --slug <slug>\n");
4120
+ }
4121
+ async function runPluginsInstall(opts) {
4122
+ const slug = opts.slug?.trim() ?? "";
4123
+ if (!slug) {
4124
+ console.error("\n\u274C \u8BF7\u63D0\u4F9B --slug\uFF08\u5148 plugins catalog \u67E5\u770B\u53EF\u88C5\u5217\u8868\uFF09\n");
4125
+ process.exit(1);
4126
+ }
4127
+ const { config, site, base } = await resolveTarget(opts);
4128
+ const api = `${base}/wp-json/siluzan-helper/v1/plugins/install`;
4129
+ let result;
4130
+ try {
4131
+ result = await apiFetch2(
4132
+ api,
4133
+ config,
4134
+ { method: "POST", body: JSON.stringify({ slug }) },
4135
+ opts.verbose
4136
+ );
4137
+ } catch (e) {
4138
+ console.error(`
4139
+ \u274C \u5B89\u88C5\u5931\u8D25\uFF1A${e.message}
4140
+ `);
4141
+ process.exit(1);
4142
+ return;
4143
+ }
4144
+ if (!result.success) {
4145
+ console.error(`
4146
+ \u274C ${result.message || "\u5B89\u88C5\u88AB\u7AD9\u70B9\u62D2\u7EDD"}
4147
+ `);
4148
+ process.exit(1);
4149
+ }
4150
+ console.log(result.already ? "\n\u2705 \u63D2\u4EF6\u5DF2\u5728\u7AD9\u70B9\u4E0A\uFF08\u5DF2\u542F\u7528\uFF09" : "\n\u2705 \u63D2\u4EF6\u5DF2\u5B89\u88C5\u5E76\u542F\u7528");
4151
+ if (result.plugin) console.log(` plugin : ${result.plugin}`);
4152
+ if (result.message) console.log(` \u8BF4\u660E : ${result.message}`);
4153
+ console.log(` \u7AD9\u70B9 : ${site.name} (${base})
4154
+ `);
4155
+ try {
4156
+ await runPluginsList({ site: site.guid || opts.site, url: site.url, verbose: opts.verbose });
4157
+ } catch {
4158
+ }
4159
+ }
4160
+ function register7(program2) {
4161
+ const plugins = program2.command("plugins").description("WordPress \u63D2\u4EF6\uFF1A\u5217\u51FA\u3001\u76EE\u5F55\u3001\u5B89\u88C5");
4162
+ plugins.command("list").description("\u5217\u51FA\u7AD9\u70B9\u5DF2\u5B89\u88C5\u63D2\u4EF6").option("-s, --site <guidOrName>", "\u7AD9\u70B9 guid \u6216\u540D\u79F0").option("--url <url>", "\u76F4\u63A5\u6307\u5B9A\u7AD9\u70B9\u5730\u5740").option("--json", "\u8F93\u51FA JSON", false).option("--verbose", "\u8F93\u51FA\u8BF7\u6C42\u8BE6\u60C5", false).action(async (opts) => {
4163
+ await runPluginsList(opts);
4164
+ });
4165
+ plugins.command("catalog").description("\u5217\u51FA\u4E1D\u8DEF\u8D5E\u63D2\u4EF6\u76EE\u5F55\uFF08\u53EF\u5B89\u88C5\u5217\u8868\uFF09").option("-s, --site <guidOrName>", "\u7AD9\u70B9 guid \u6216\u540D\u79F0").option("--url <url>", "\u76F4\u63A5\u6307\u5B9A\u7AD9\u70B9\u5730\u5740").option("--json", "\u8F93\u51FA JSON", false).option("--verbose", "\u8F93\u51FA\u8BF7\u6C42\u8BE6\u60C5", false).action(async (opts) => {
4166
+ await runPluginsCatalog(opts);
4167
+ });
4168
+ plugins.command("install").description("\u4ECE\u4E1D\u8DEF\u8D5E\u76EE\u5F55\u5B89\u88C5\u5E76\u542F\u7528\u63D2\u4EF6\uFF08\u5199\u64CD\u4F5C\uFF0C\u4F1A\u7ACB\u523B\u751F\u6548\uFF09").option("-s, --site <guidOrName>", "\u7AD9\u70B9 guid \u6216\u540D\u79F0").option("--url <url>", "\u76F4\u63A5\u6307\u5B9A\u7AD9\u70B9\u5730\u5740").requiredOption("--slug <slug>", "\u76EE\u5F55\u4E2D\u7684 slug \u6216 plugin \u8DEF\u5F84").option("--verbose", "\u8F93\u51FA\u8BF7\u6C42\u8BE6\u60C5", false).action(async (opts) => {
4169
+ await runPluginsInstall(opts);
4170
+ });
4171
+ }
4172
+
4173
+ // src/index.ts
4174
+ installProcessHandlers();
4175
+ var program = new Command();
4176
+ program.name("siluzan-website").description("Siluzan WordPress \u7AD9\u70B9\u7BA1\u7406\uFF1A\u5217\u51FA\u7AD9\u70B9\u3001\u65B0\u589E/\u7F16\u8F91\u9875\u9762\u3001\u67E5\u770B\u63D2\u4EF6").version(getCurrentVersion2());
4177
+ var REGISTRARS = [
4178
+ register,
4179
+ register2,
4180
+ register3,
4181
+ register4,
4182
+ register5,
4183
+ register6,
4184
+ register7
4185
+ ];
4186
+ for (const reg of REGISTRARS) reg(program);
4187
+ program.parse();
4188
+ var activeCmd = process.argv[2];
4189
+ if (activeCmd !== "update") {
4190
+ notifyIfOutdated().catch(() => {
4191
+ });
4192
+ }