maidang 29.9.3 → 29.9.5
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 +871 -299
- package/dist/index.js.map +4 -4
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,41 @@
|
|
|
1
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/emoji-regex@10.6.0/node_modules/emoji-regex/index.js
|
|
29
|
+
var require_emoji_regex = __commonJS({
|
|
30
|
+
"../../node_modules/.pnpm/emoji-regex@10.6.0/node_modules/emoji-regex/index.js"(exports, module) {
|
|
31
|
+
module.exports = () => {
|
|
32
|
+
return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E-\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED8\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])))?))?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3C-\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE8A\uDE8E-\uDEC2\uDEC6\uDEC8\uDECD-\uDEDC\uDEDF-\uDEEA\uDEEF]|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
2
36
|
|
|
3
37
|
// src/index.ts
|
|
4
|
-
import { Command as
|
|
38
|
+
import { Command as Command18 } from "commander";
|
|
5
39
|
|
|
6
40
|
// src/commands/home.ts
|
|
7
41
|
import { Command } from "commander";
|
|
@@ -58,7 +92,7 @@ var commands = [
|
|
|
58
92
|
{ name: "links", desc: "\u793E\u4EA4\u4E0E\u5916\u94FE" },
|
|
59
93
|
{ name: "cat", desc: "\u9EA6\u9EA6" },
|
|
60
94
|
{ name: "contact", desc: "\u7ED9\u6211\u7559\u8A00" },
|
|
61
|
-
{ name: "manifest", desc: "\u4E00\u6B21\u6027\u7ED9 AI \u7684\u5168\u90E8\u6570\u636E
|
|
95
|
+
{ name: "manifest", desc: "\u4E00\u6B21\u6027\u7ED9 AI \u7684\u5168\u90E8\u6570\u636E\uFF08JSON\uFF09" },
|
|
62
96
|
{ name: "upgrade", desc: "\u5347\u7EA7 maidang \u5230\u6700\u65B0\u7248" }
|
|
63
97
|
];
|
|
64
98
|
function createHomeCommand() {
|
|
@@ -151,6 +185,13 @@ var career_default = {
|
|
|
151
185
|
};
|
|
152
186
|
|
|
153
187
|
// src/utils/api-response.ts
|
|
188
|
+
var ApiRequestError = class extends Error {
|
|
189
|
+
constructor(message, status) {
|
|
190
|
+
super(message);
|
|
191
|
+
this.status = status;
|
|
192
|
+
this.name = "ApiRequestError";
|
|
193
|
+
}
|
|
194
|
+
};
|
|
154
195
|
function isApiEnvelope(value) {
|
|
155
196
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
156
197
|
return false;
|
|
@@ -162,36 +203,227 @@ async function readApiData(response) {
|
|
|
162
203
|
const payload = await response.json();
|
|
163
204
|
if (isApiEnvelope(payload)) {
|
|
164
205
|
if (!response.ok || payload.code !== 0) {
|
|
165
|
-
throw new
|
|
206
|
+
throw new ApiRequestError(payload.message || `HTTP ${response.status}`, response.status);
|
|
166
207
|
}
|
|
167
208
|
return payload.data;
|
|
168
209
|
}
|
|
169
210
|
if (!response.ok) {
|
|
170
211
|
const record = payload;
|
|
171
212
|
const message = record && typeof record.error === "string" ? record.error : `HTTP ${response.status}`;
|
|
172
|
-
throw new
|
|
213
|
+
throw new ApiRequestError(message, response.status);
|
|
173
214
|
}
|
|
174
215
|
return payload;
|
|
175
216
|
}
|
|
176
|
-
|
|
217
|
+
|
|
218
|
+
// src/utils/os-agent-api.ts
|
|
219
|
+
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
220
|
+
import { homedir } from "os";
|
|
221
|
+
import { join } from "path";
|
|
222
|
+
var API_URL = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
223
|
+
var AGENT_HEADER = "x-maidang-agent";
|
|
224
|
+
var CONFIG_DIR = process.env.MAIDANG_CLI_HOME || join(homedir(), ".maidang");
|
|
225
|
+
var CONFIG_PATH = join(CONFIG_DIR, "cli.json");
|
|
226
|
+
var RUN_TIMEOUT_MS = 18e4;
|
|
227
|
+
function loadConfig() {
|
|
228
|
+
try {
|
|
229
|
+
return JSON.parse(readFileSync(CONFIG_PATH, "utf8"));
|
|
230
|
+
} catch {
|
|
231
|
+
return {};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function saveConfig(config) {
|
|
235
|
+
try {
|
|
236
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
237
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 384 });
|
|
238
|
+
} catch {
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function readLastSessionId() {
|
|
242
|
+
return loadConfig().sessionId;
|
|
243
|
+
}
|
|
244
|
+
var RateLimitError = class extends Error {
|
|
245
|
+
constructor(retryAfter) {
|
|
246
|
+
super(`\u8BF7\u6C42\u592A\u9891\u7E41\uFF0C\u8BF7\u5728 ${retryAfter} \u79D2\u540E\u518D\u8BD5`);
|
|
247
|
+
this.retryAfter = retryAfter;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
async function readError(response) {
|
|
251
|
+
let retryAfter = 0;
|
|
252
|
+
let message = `HTTP ${response.status}`;
|
|
177
253
|
try {
|
|
178
254
|
const payload = await response.json();
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
255
|
+
if (typeof payload.retry_after === "number") retryAfter = payload.retry_after;
|
|
256
|
+
if (typeof payload.message === "string") message = payload.message;
|
|
257
|
+
} catch {
|
|
258
|
+
}
|
|
259
|
+
if (response.status === 429) {
|
|
260
|
+
const headerRetry = Number(response.headers.get("Retry-After"));
|
|
261
|
+
throw new RateLimitError(retryAfter || headerRetry || 60);
|
|
262
|
+
}
|
|
263
|
+
throw new Error(message);
|
|
264
|
+
}
|
|
265
|
+
async function runAgentChat(input) {
|
|
266
|
+
const config = loadConfig();
|
|
267
|
+
const token = config.agentToken;
|
|
268
|
+
const sessionId = input.sessionId;
|
|
269
|
+
const runsResponse = await fetch(`${API_URL}/api/os-agent/runs`, {
|
|
270
|
+
method: "POST",
|
|
271
|
+
headers: {
|
|
272
|
+
"Content-Type": "application/json",
|
|
273
|
+
...token ? { [AGENT_HEADER]: token } : {}
|
|
274
|
+
},
|
|
275
|
+
body: JSON.stringify({
|
|
276
|
+
message: input.message,
|
|
277
|
+
...sessionId ? { sessionId } : {},
|
|
278
|
+
context: {
|
|
279
|
+
surface: "cli",
|
|
280
|
+
...process.stdout.columns ? { columns: process.stdout.columns } : {}
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
});
|
|
284
|
+
if (!runsResponse.ok) await readError(runsResponse);
|
|
285
|
+
const issuedToken = runsResponse.headers.get(AGENT_HEADER) ?? token;
|
|
286
|
+
const queued = (await runsResponse.json()).data ?? {};
|
|
287
|
+
const runId = queued.runId;
|
|
288
|
+
const newSessionId = queued.sessionId ?? "";
|
|
289
|
+
if (!runId) throw new Error("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE runId");
|
|
290
|
+
if (issuedToken || newSessionId) {
|
|
291
|
+
saveConfig({
|
|
292
|
+
...issuedToken ? { agentToken: issuedToken } : {},
|
|
293
|
+
...newSessionId ? { sessionId: newSessionId } : {}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
const eventsResponse = await fetch(`${API_URL}/api/os-agent/runs/${runId}/events`, {
|
|
297
|
+
method: "POST",
|
|
298
|
+
headers: issuedToken ? { [AGENT_HEADER]: issuedToken } : {},
|
|
299
|
+
signal: AbortSignal.timeout(RUN_TIMEOUT_MS)
|
|
300
|
+
});
|
|
301
|
+
if (!eventsResponse.ok) await readError(eventsResponse);
|
|
302
|
+
if (!eventsResponse.body) throw new Error("\u4E8B\u4EF6\u6D41\u4E3A\u7A7A");
|
|
303
|
+
let response = "";
|
|
304
|
+
let deltaText = "";
|
|
305
|
+
const terminal = await consumeSse(eventsResponse.body, (event, payload) => {
|
|
306
|
+
if (event === "message.delta") {
|
|
307
|
+
const text = typeof payload?.text === "string" ? payload.text : "";
|
|
308
|
+
if (text) {
|
|
309
|
+
deltaText += text;
|
|
310
|
+
input.onEvent?.({ type: "delta", text });
|
|
186
311
|
}
|
|
187
|
-
|
|
188
|
-
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (event === "tool.started" && typeof payload?.name === "string") {
|
|
315
|
+
input.onEvent?.({ type: "tool", name: payload.name });
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (event === "run.completed") {
|
|
319
|
+
response = typeof payload?.message === "string" ? payload.message : deltaText;
|
|
320
|
+
}
|
|
321
|
+
if (event === "run.failed") {
|
|
322
|
+
throw new Error(typeof payload?.message === "string" ? payload.message : "agent_run_failed");
|
|
323
|
+
}
|
|
324
|
+
if (event === "run.cancelled" || event === "run.superseded") {
|
|
325
|
+
throw new Error("agent_run_cancelled");
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
if (!terminal) throw new Error("\u4E8B\u4EF6\u6D41\u63D0\u524D\u7ED3\u675F");
|
|
329
|
+
return {
|
|
330
|
+
response: response || deltaText,
|
|
331
|
+
sessionId: newSessionId,
|
|
332
|
+
runId,
|
|
333
|
+
silent: terminal === "run.silent"
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
async function consumeSse(body, onEvent) {
|
|
337
|
+
const terminalEvents = /* @__PURE__ */ new Set(["run.completed", "run.silent", "run.failed", "run.cancelled", "run.superseded"]);
|
|
338
|
+
const reader = body.getReader();
|
|
339
|
+
const decoder = new TextDecoder();
|
|
340
|
+
let buffer = "";
|
|
341
|
+
while (true) {
|
|
342
|
+
const { done, value } = await reader.read();
|
|
343
|
+
if (done) break;
|
|
344
|
+
buffer += decoder.decode(value, { stream: true });
|
|
345
|
+
let separator = buffer.indexOf("\n\n");
|
|
346
|
+
while (separator !== -1) {
|
|
347
|
+
const frame = buffer.slice(0, separator);
|
|
348
|
+
buffer = buffer.slice(separator + 2);
|
|
349
|
+
separator = buffer.indexOf("\n\n");
|
|
350
|
+
const parsed = parseFrame(frame);
|
|
351
|
+
if (!parsed) continue;
|
|
352
|
+
onEvent(parsed.event, parsed.payload);
|
|
353
|
+
if (terminalEvents.has(parsed.event)) {
|
|
354
|
+
await reader.cancel().catch(() => void 0);
|
|
355
|
+
return parsed.event;
|
|
189
356
|
}
|
|
190
357
|
}
|
|
191
|
-
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
function parseFrame(frame) {
|
|
362
|
+
let event = "message";
|
|
363
|
+
let data = "";
|
|
364
|
+
for (const line of frame.split("\n")) {
|
|
365
|
+
if (line.startsWith("event: ")) event = line.slice(7).trim();
|
|
366
|
+
else if (line.startsWith("data: ")) data += line.slice(6);
|
|
367
|
+
}
|
|
368
|
+
if (!data) return null;
|
|
369
|
+
try {
|
|
370
|
+
const parsed = JSON.parse(data);
|
|
371
|
+
const payload = parsed.payload ?? parsed;
|
|
372
|
+
return { event, payload };
|
|
192
373
|
} catch {
|
|
193
|
-
return
|
|
374
|
+
return { event, payload: null };
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/core/json-output.ts
|
|
379
|
+
var TOOL_NAME = "maidang";
|
|
380
|
+
function printJsonOk(command, data) {
|
|
381
|
+
process.stdout.write(JSON.stringify({ ok: true, tool: TOOL_NAME, command, data }, null, 2) + "\n");
|
|
382
|
+
}
|
|
383
|
+
function printJsonErr(command, error, exitCode = 1) {
|
|
384
|
+
process.stderr.write(
|
|
385
|
+
JSON.stringify({ ok: false, tool: TOOL_NAME, command, error }, null, 2) + "\n"
|
|
386
|
+
);
|
|
387
|
+
process.exit(exitCode);
|
|
388
|
+
}
|
|
389
|
+
var ERROR_HINTS = {
|
|
390
|
+
auth: "\u8EAB\u4EFD\u51ED\u8BC1\u7F3A\u5931\u6216\u5DF2\u8FC7\u671F\uFF0C\u91CD\u65B0\u83B7\u53D6\u540E\u518D\u8BD5",
|
|
391
|
+
quota: "\u8BF7\u6C42\u592A\u9891\u7E41\uFF0C\u7B49\u4E00\u4F1A\u513F\u518D\u8BD5",
|
|
392
|
+
not_found: "\u786E\u8BA4\u8D44\u6E90\u6807\u8BC6\uFF08slug\u3001\u65E5\u671F\u3001\u5E74\u4EFD\u7B49\uFF09\u662F\u5426\u5B58\u5728",
|
|
393
|
+
invalid_args: "\u68C0\u67E5\u547D\u4EE4\u53C2\u6570\uFF0C\u7528 --help \u67E5\u770B\u7528\u6CD5",
|
|
394
|
+
network: "\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\uFF0C\u4EE5\u53CA MAIDANG_API_URL \u6307\u5411\u7684\u670D\u52A1\u662F\u5426\u53EF\u8FBE",
|
|
395
|
+
server: "\u670D\u52A1\u7AEF\u5F02\u5E38\uFF0C\u7A0D\u540E\u91CD\u8BD5\uFF1B\u6301\u7EED\u5931\u8D25\u8BF7\u901A\u8FC7 maidang contact \u53CD\u9988",
|
|
396
|
+
unknown: "\u672A\u5F52\u7C7B\u7684\u9519\u8BEF\uFF0C\u628A\u8FD9\u6761\u8F93\u51FA\u901A\u8FC7 maidang contact \u53CD\u9988\u7ED9\u9EA6\u5F53"
|
|
397
|
+
};
|
|
398
|
+
var typeFromHttpStatus = (status) => {
|
|
399
|
+
if (status === 401 || status === 403) return "auth";
|
|
400
|
+
if (status === 429) return "quota";
|
|
401
|
+
if (status === 404) return "not_found";
|
|
402
|
+
if (status === 400) return "invalid_args";
|
|
403
|
+
if (status >= 500) return "server";
|
|
404
|
+
if (status >= 200 && status < 300) return "server";
|
|
405
|
+
return "unknown";
|
|
406
|
+
};
|
|
407
|
+
var NETWORK_ERROR_PATTERN = /fetch failed|network|econn|enotfound|socket|超时|timed?\s*out/i;
|
|
408
|
+
var isNetworkError = (error) => error.name === "AbortError" || error.name === "TimeoutError" || NETWORK_ERROR_PATTERN.test(error.message);
|
|
409
|
+
function classifyError(error) {
|
|
410
|
+
if (error instanceof RateLimitError) {
|
|
411
|
+
return {
|
|
412
|
+
type: "quota",
|
|
413
|
+
code: "429",
|
|
414
|
+
message: error.message,
|
|
415
|
+
hint: `\u7B49 ${error.retryAfter} \u79D2\u540E\u518D\u8BD5`
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
if (error instanceof ApiRequestError) {
|
|
419
|
+
const type = typeFromHttpStatus(error.status);
|
|
420
|
+
return { type, code: String(error.status), message: error.message, hint: ERROR_HINTS[type] };
|
|
194
421
|
}
|
|
422
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
423
|
+
if (error instanceof Error && isNetworkError(error)) {
|
|
424
|
+
return { type: "network", message, hint: ERROR_HINTS.network };
|
|
425
|
+
}
|
|
426
|
+
return { type: "unknown", message, hint: ERROR_HINTS.unknown };
|
|
195
427
|
}
|
|
196
428
|
|
|
197
429
|
// src/commands/career.ts
|
|
@@ -200,7 +432,6 @@ function createCareerCommand() {
|
|
|
200
432
|
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
201
433
|
try {
|
|
202
434
|
const response = await fetch(`${apiUrl}/api/career`);
|
|
203
|
-
if (!response.ok) throw new Error(await readApiMessage(response));
|
|
204
435
|
const experiences = await readApiData(response);
|
|
205
436
|
const data = {
|
|
206
437
|
career: {
|
|
@@ -209,7 +440,7 @@ function createCareerCommand() {
|
|
|
209
440
|
}
|
|
210
441
|
};
|
|
211
442
|
if (opts.json) {
|
|
212
|
-
|
|
443
|
+
printJsonOk("career", data);
|
|
213
444
|
return;
|
|
214
445
|
}
|
|
215
446
|
const { intro } = data.career;
|
|
@@ -234,6 +465,7 @@ function createCareerCommand() {
|
|
|
234
465
|
}
|
|
235
466
|
});
|
|
236
467
|
} catch (error) {
|
|
468
|
+
if (opts.json) printJsonErr("career", classifyError(error));
|
|
237
469
|
console.error(theme.err(`\u83B7\u53D6\u5DE5\u4F5C\u7ECF\u5386\u5931\u8D25: ${error instanceof Error ? error.message : error}`));
|
|
238
470
|
process.exit(1);
|
|
239
471
|
}
|
|
@@ -246,23 +478,15 @@ import { Command as Command3 } from "commander";
|
|
|
246
478
|
var getCatMoments = async () => {
|
|
247
479
|
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
248
480
|
const res = await fetch(`${apiUrl}/api/cat`);
|
|
249
|
-
if (!res.ok) {
|
|
250
|
-
throw new Error(await readApiMessage(res));
|
|
251
|
-
}
|
|
252
481
|
const data = await readApiData(res);
|
|
253
482
|
return Array.isArray(data) ? data : [];
|
|
254
483
|
};
|
|
255
484
|
function createCatCommand() {
|
|
256
|
-
const cmd = new Command3("cat").alias("meow").description("\u9EA6\u9EA6\uFF0C\u4E00\u53EA\u5728\u5DE1\u89C6\u3001\u53D1\u5446\u3001\u8FFD\u5149\u7684\u732B
|
|
257
|
-
const printJson = (data, error) => {
|
|
258
|
-
const payload = { tool: "maidang", command: "cat", data };
|
|
259
|
-
if (error) payload.error = error;
|
|
260
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
261
|
-
};
|
|
485
|
+
const cmd = new Command3("cat").alias("meow").description("\u9EA6\u9EA6\uFF0C\u4E00\u53EA\u5728\u5DE1\u89C6\u3001\u53D1\u5446\u3001\u8FFD\u5149\u7684\u732B\uFF08--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action(async (opts) => {
|
|
262
486
|
try {
|
|
263
487
|
const moments = await getCatMoments();
|
|
264
488
|
if (opts.json) {
|
|
265
|
-
|
|
489
|
+
printJsonOk("cat", moments);
|
|
266
490
|
return;
|
|
267
491
|
}
|
|
268
492
|
console.log("");
|
|
@@ -289,11 +513,8 @@ function createCatCommand() {
|
|
|
289
513
|
});
|
|
290
514
|
console.log("");
|
|
291
515
|
} catch (err) {
|
|
516
|
+
if (opts.json) printJsonErr("cat", classifyError(err));
|
|
292
517
|
const message = err instanceof Error ? err.message : String(err);
|
|
293
|
-
if (opts.json) {
|
|
294
|
-
printJson([], message);
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
518
|
console.error(theme.err(`\u83B7\u53D6\u732B\u732B\u52A8\u6001\u5931\u8D25: ${message}`));
|
|
298
519
|
process.exit(1);
|
|
299
520
|
}
|
|
@@ -333,10 +554,9 @@ function createPostsCommand() {
|
|
|
333
554
|
try {
|
|
334
555
|
if (slug) {
|
|
335
556
|
const response2 = await fetch(`${baseApiUrl}/api/posts/${encodeURIComponent(slug)}`);
|
|
336
|
-
if (!response2.ok) throw new Error(await readApiMessage(response2));
|
|
337
557
|
const data2 = await readApiData(response2);
|
|
338
558
|
if (opts.json) {
|
|
339
|
-
|
|
559
|
+
printJsonOk("posts", { slug, post: data2 });
|
|
340
560
|
return;
|
|
341
561
|
}
|
|
342
562
|
console.log("");
|
|
@@ -349,7 +569,6 @@ function createPostsCommand() {
|
|
|
349
569
|
const usesPagination = opts.page !== void 0 || opts.pageSize !== void 0;
|
|
350
570
|
const url = usesPagination ? buildPaginationUrl(`${baseApiUrl}/api/posts`, opts) : `${baseApiUrl}/api/posts`;
|
|
351
571
|
const response = await fetch(url);
|
|
352
|
-
if (!response.ok) throw new Error(await readApiMessage(response));
|
|
353
572
|
const responseData = await readApiData(response);
|
|
354
573
|
const data = Array.isArray(responseData) ? {
|
|
355
574
|
items: responseData,
|
|
@@ -363,7 +582,7 @@ function createPostsCommand() {
|
|
|
363
582
|
}
|
|
364
583
|
} : responseData;
|
|
365
584
|
if (opts.json) {
|
|
366
|
-
|
|
585
|
+
printJsonOk("posts", data);
|
|
367
586
|
return;
|
|
368
587
|
}
|
|
369
588
|
console.log("");
|
|
@@ -382,6 +601,7 @@ function createPostsCommand() {
|
|
|
382
601
|
});
|
|
383
602
|
console.log("");
|
|
384
603
|
} catch (error) {
|
|
604
|
+
if (opts.json) printJsonErr("posts", classifyError(error));
|
|
385
605
|
console.error(theme.err(`\u83B7\u53D6\u52A8\u6001\u5931\u8D25: ${error instanceof Error ? error.message : error}`));
|
|
386
606
|
process.exit(1);
|
|
387
607
|
}
|
|
@@ -1292,27 +1512,31 @@ function printSong(song, index) {
|
|
|
1292
1512
|
console.log(` ${song.artists.join(", ")} \xB7 ${formatDuration(song.duration)} \xB7 ${song.album}`);
|
|
1293
1513
|
}
|
|
1294
1514
|
function createSongsCommand() {
|
|
1295
|
-
|
|
1515
|
+
const yearRange = `${Math.min(...availableYears)}\u2014${Math.max(...availableYears)}`;
|
|
1516
|
+
return new Command5("songs").description(`\u5E74\u5EA6\u6B4C\u5355\uFF08${yearRange}\uFF0C--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09`).option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").option("--year <year>", `\u8F93\u51FA\u6307\u5B9A\u5E74\u4EFD\u7684\u6B4C\u66F2\u5217\u8868\uFF08\u53EF\u9009\uFF1A${availableYears.join("\u3001")}\uFF09`).option("--copy <song-id>", "\u590D\u5236\u6307\u5B9A\u6B4C\u66F2\u540D\u79F0").action((opts) => {
|
|
1296
1517
|
const year = opts.year ? Number(opts.year) : void 0;
|
|
1297
1518
|
const entry = year === void 0 ? void 0 : allYears.find((item) => item.year === year);
|
|
1298
1519
|
if (year !== void 0 && !entry) {
|
|
1299
1520
|
const message = `\u6CA1\u6709 ${year} \u5E74\u7684\u6B4C\u5355`;
|
|
1300
1521
|
if (opts.json) {
|
|
1301
|
-
|
|
1302
|
-
} else {
|
|
1303
|
-
console.error(message);
|
|
1522
|
+
printJsonErr("songs", { type: "not_found", message, hint: `\u53EF\u7528\u5E74\u4EFD\uFF1A${availableYears.join("\u3001")}` });
|
|
1304
1523
|
}
|
|
1524
|
+
console.error(message);
|
|
1305
1525
|
process.exit(1);
|
|
1306
1526
|
}
|
|
1307
1527
|
if (opts.copy) {
|
|
1308
1528
|
const song = allYears.flatMap((item) => item.songs).find((item) => item.id === opts.copy);
|
|
1309
1529
|
if (!song) {
|
|
1310
|
-
|
|
1530
|
+
const message = `\u6CA1\u6709\u627E\u5230\u6B4C\u66F2 ${opts.copy}`;
|
|
1531
|
+
if (opts.json) {
|
|
1532
|
+
printJsonErr("songs", { type: "not_found", message, hint: "\u7528 maidang songs --json \u67E5\u770B\u6B4C\u66F2 id" });
|
|
1533
|
+
}
|
|
1534
|
+
console.error(message);
|
|
1311
1535
|
process.exit(1);
|
|
1312
1536
|
}
|
|
1313
1537
|
copyToClipboard(song.name);
|
|
1314
1538
|
if (opts.json) {
|
|
1315
|
-
|
|
1539
|
+
printJsonOk("songs", { copied: song.name, song });
|
|
1316
1540
|
} else {
|
|
1317
1541
|
console.log(`\u5DF2\u590D\u5236\uFF1A${song.name}`);
|
|
1318
1542
|
}
|
|
@@ -1321,9 +1545,9 @@ function createSongsCommand() {
|
|
|
1321
1545
|
if (opts.json) {
|
|
1322
1546
|
if (entry) {
|
|
1323
1547
|
const meta = allMeta.find((item) => item.year === entry.year);
|
|
1324
|
-
|
|
1548
|
+
printJsonOk("songs", { meta, songs: entry.songs });
|
|
1325
1549
|
} else {
|
|
1326
|
-
|
|
1550
|
+
printJsonOk("songs", { years: availableYears, meta: allMeta, byYear: allYears });
|
|
1327
1551
|
}
|
|
1328
1552
|
return;
|
|
1329
1553
|
}
|
|
@@ -1348,14 +1572,13 @@ ${entry.year} \u5E74\u5EA6\u6B4C\u5355 \xB7 ${entry.songs.length} \u9996
|
|
|
1348
1572
|
// src/commands/links.ts
|
|
1349
1573
|
import { Command as Command6 } from "commander";
|
|
1350
1574
|
function createLinksCommand() {
|
|
1351
|
-
const cmd = new Command6("links").description("\u793E\u4EA4\u4E0E\u5916\u94FE
|
|
1575
|
+
const cmd = new Command6("links").description("\u793E\u4EA4\u4E0E\u5916\u94FE\uFF08--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action(async (opts) => {
|
|
1352
1576
|
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
1353
1577
|
try {
|
|
1354
1578
|
const res = await fetch(`${apiUrl}/api/links`);
|
|
1355
|
-
if (!res.ok) throw new Error(await readApiMessage(res));
|
|
1356
1579
|
const links = await readApiData(res);
|
|
1357
1580
|
if (opts.json) {
|
|
1358
|
-
|
|
1581
|
+
printJsonOk("links", links);
|
|
1359
1582
|
return;
|
|
1360
1583
|
}
|
|
1361
1584
|
console.log("");
|
|
@@ -1374,6 +1597,7 @@ function createLinksCommand() {
|
|
|
1374
1597
|
});
|
|
1375
1598
|
console.log("");
|
|
1376
1599
|
} catch (err) {
|
|
1600
|
+
if (opts.json) printJsonErr("links", classifyError(err));
|
|
1377
1601
|
console.error(theme.err(`\u83B7\u53D6\u94FE\u63A5\u5931\u8D25: ${err instanceof Error ? err.message : err}`));
|
|
1378
1602
|
process.exit(1);
|
|
1379
1603
|
}
|
|
@@ -1388,10 +1612,9 @@ function createProjectsCommand() {
|
|
|
1388
1612
|
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
1389
1613
|
try {
|
|
1390
1614
|
const response = await fetch(buildPaginationUrl(`${apiUrl}/api/projects`, opts));
|
|
1391
|
-
if (!response.ok) throw new Error(await readApiMessage(response));
|
|
1392
1615
|
const data = await readApiData(response);
|
|
1393
1616
|
if (opts.json) {
|
|
1394
|
-
|
|
1617
|
+
printJsonOk("projects", data);
|
|
1395
1618
|
return;
|
|
1396
1619
|
}
|
|
1397
1620
|
console.log("");
|
|
@@ -1410,6 +1633,7 @@ function createProjectsCommand() {
|
|
|
1410
1633
|
});
|
|
1411
1634
|
console.log("");
|
|
1412
1635
|
} catch (error) {
|
|
1636
|
+
if (opts.json) printJsonErr("projects", classifyError(error));
|
|
1413
1637
|
console.error(theme.err(`\u83B7\u53D6\u9879\u76EE\u5931\u8D25: ${error instanceof Error ? error.message : error}`));
|
|
1414
1638
|
process.exit(1);
|
|
1415
1639
|
}
|
|
@@ -1424,14 +1648,13 @@ var categoryNames = {
|
|
|
1424
1648
|
desktop: "\u684C\u9762"
|
|
1425
1649
|
};
|
|
1426
1650
|
function createToolsCommand() {
|
|
1427
|
-
const cmd = new Command8("tools").description("\u6700\u8FD1\u5728\u7528\u7684\u597D\u7269
|
|
1651
|
+
const cmd = new Command8("tools").description("\u6700\u8FD1\u5728\u7528\u7684\u597D\u7269\uFF08--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action(async (opts) => {
|
|
1428
1652
|
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
1429
1653
|
try {
|
|
1430
1654
|
const res = await fetch(`${apiUrl}/api/tools`);
|
|
1431
|
-
if (!res.ok) throw new Error(await readApiMessage(res));
|
|
1432
1655
|
const tools = await readApiData(res);
|
|
1433
1656
|
if (opts.json) {
|
|
1434
|
-
|
|
1657
|
+
printJsonOk("tools", tools);
|
|
1435
1658
|
return;
|
|
1436
1659
|
}
|
|
1437
1660
|
const byCategory = tools.reduce((acc, tool) => {
|
|
@@ -1458,6 +1681,7 @@ function createToolsCommand() {
|
|
|
1458
1681
|
});
|
|
1459
1682
|
console.log("");
|
|
1460
1683
|
} catch (err) {
|
|
1684
|
+
if (opts.json) printJsonErr("tools", classifyError(err));
|
|
1461
1685
|
console.error(theme.err(`\u83B7\u53D6\u5DE5\u5177\u5931\u8D25: ${err instanceof Error ? err.message : err}`));
|
|
1462
1686
|
process.exit(1);
|
|
1463
1687
|
}
|
|
@@ -1473,10 +1697,9 @@ function createSkillsCommand() {
|
|
|
1473
1697
|
try {
|
|
1474
1698
|
if (opts.slug) {
|
|
1475
1699
|
const response2 = await fetch(`${apiUrl}/api/skills/${encodeURIComponent(opts.slug)}`);
|
|
1476
|
-
if (!response2.ok) throw new Error(await readApiMessage(response2));
|
|
1477
1700
|
const skill = await readApiData(response2);
|
|
1478
1701
|
if (opts.json) {
|
|
1479
|
-
|
|
1702
|
+
printJsonOk("skills", { slug: opts.slug, skill });
|
|
1480
1703
|
return;
|
|
1481
1704
|
}
|
|
1482
1705
|
console.log("");
|
|
@@ -1493,10 +1716,9 @@ function createSkillsCommand() {
|
|
|
1493
1716
|
return;
|
|
1494
1717
|
}
|
|
1495
1718
|
const response = await fetch(`${apiUrl}/api/skills`);
|
|
1496
|
-
if (!response.ok) throw new Error(await readApiMessage(response));
|
|
1497
1719
|
const skills = await readApiData(response);
|
|
1498
1720
|
if (opts.json) {
|
|
1499
|
-
|
|
1721
|
+
printJsonOk("skills", skills);
|
|
1500
1722
|
return;
|
|
1501
1723
|
}
|
|
1502
1724
|
console.log("");
|
|
@@ -1513,6 +1735,7 @@ function createSkillsCommand() {
|
|
|
1513
1735
|
}
|
|
1514
1736
|
console.log("");
|
|
1515
1737
|
} catch (error) {
|
|
1738
|
+
if (opts.json) printJsonErr("skills", classifyError(error));
|
|
1516
1739
|
console.error(theme.err(`\u83B7\u53D6 Skills \u5931\u8D25: ${error instanceof Error ? error.message : error}`));
|
|
1517
1740
|
process.exit(1);
|
|
1518
1741
|
}
|
|
@@ -1533,9 +1756,6 @@ async function sendContactMessage(input) {
|
|
|
1533
1756
|
},
|
|
1534
1757
|
body: JSON.stringify(input)
|
|
1535
1758
|
});
|
|
1536
|
-
if (!res.ok) {
|
|
1537
|
-
throw new Error(await readApiMessage(res));
|
|
1538
|
-
}
|
|
1539
1759
|
return readApiData(res);
|
|
1540
1760
|
}
|
|
1541
1761
|
|
|
@@ -1548,24 +1768,18 @@ async function contactSync(message, options) {
|
|
|
1548
1768
|
email: options?.email
|
|
1549
1769
|
});
|
|
1550
1770
|
if (options?.json) {
|
|
1551
|
-
|
|
1552
|
-
tool: "maidang",
|
|
1553
|
-
command: "contact",
|
|
1771
|
+
printJsonOk("contact", {
|
|
1554
1772
|
message,
|
|
1555
1773
|
name: options?.name,
|
|
1556
1774
|
email: options?.email,
|
|
1557
|
-
result
|
|
1558
|
-
|
|
1559
|
-
}, null, 2));
|
|
1775
|
+
result
|
|
1776
|
+
});
|
|
1560
1777
|
return;
|
|
1561
1778
|
}
|
|
1562
1779
|
console.log(result.message);
|
|
1563
1780
|
} catch (error) {
|
|
1781
|
+
if (options?.json) printJsonErr("contact", classifyError(error));
|
|
1564
1782
|
const messageText = error instanceof Error ? error.message : String(error);
|
|
1565
|
-
if (options?.json) {
|
|
1566
|
-
console.error(JSON.stringify({ tool: "maidang", command: "contact", error: messageText }, null, 2));
|
|
1567
|
-
return;
|
|
1568
|
-
}
|
|
1569
1783
|
console.error(chalk2.red(`Error: ${messageText}`));
|
|
1570
1784
|
process.exit(1);
|
|
1571
1785
|
}
|
|
@@ -1574,7 +1788,7 @@ function createContactCommand() {
|
|
|
1574
1788
|
return new Command10("contact").description("\u7ED9\u9EA6\u5F53\u7559\u8A00\uFF08-m \u76F4\u63A5\u53D1\u9001\uFF0C--json \u8F93\u51FA\u7ED3\u6784\u5316\u7ED3\u679C\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").option("-m, --message <message>", "\u76F4\u63A5\u53D1\u9001\u7559\u8A00").option("--name <name>", "\u7559\u8A00\u4EBA\u79F0\u547C").option("--email <email>", "\u7559\u8A00\u4EBA\u90AE\u7BB1").action(async (opts) => {
|
|
1575
1789
|
const data = { email: "borisdunk@sina.com", note: "\u76F4\u63A5\u53D1\u9001\u539F\u6587\u7559\u8A00\uFF0C\u4E0D\u7ECF\u8FC7 chat \u6216\u5927\u6A21\u578B" };
|
|
1576
1790
|
if (opts.json && !opts.message) {
|
|
1577
|
-
|
|
1791
|
+
printJsonOk("contact", data);
|
|
1578
1792
|
return;
|
|
1579
1793
|
}
|
|
1580
1794
|
if (opts.message) {
|
|
@@ -1585,10 +1799,6 @@ function createContactCommand() {
|
|
|
1585
1799
|
});
|
|
1586
1800
|
return;
|
|
1587
1801
|
}
|
|
1588
|
-
if (opts.json) {
|
|
1589
|
-
console.log(JSON.stringify({ tool: "maidang", command: "contact", data }, null, 2));
|
|
1590
|
-
return;
|
|
1591
|
-
}
|
|
1592
1802
|
console.log("");
|
|
1593
1803
|
console.log("contact");
|
|
1594
1804
|
console.log("\u7ED9\u9EA6\u5F53\u7559\u8A00\uFF1A");
|
|
@@ -1625,7 +1835,7 @@ function createWhoAmICommand() {
|
|
|
1625
1835
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1626
1836
|
};
|
|
1627
1837
|
if (opts.json) {
|
|
1628
|
-
|
|
1838
|
+
printJsonOk("whoami", whoami);
|
|
1629
1839
|
return;
|
|
1630
1840
|
}
|
|
1631
1841
|
console.log("");
|
|
@@ -1910,166 +2120,6 @@ var printMarkdownAnsi = (source, options = {}) => {
|
|
|
1910
2120
|
console.log(text);
|
|
1911
2121
|
};
|
|
1912
2122
|
|
|
1913
|
-
// src/utils/os-agent-api.ts
|
|
1914
|
-
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
1915
|
-
import { homedir } from "os";
|
|
1916
|
-
import { join } from "path";
|
|
1917
|
-
var API_URL = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
1918
|
-
var AGENT_HEADER = "x-maidang-agent";
|
|
1919
|
-
var CONFIG_DIR = process.env.MAIDANG_CLI_HOME || join(homedir(), ".maidang");
|
|
1920
|
-
var CONFIG_PATH = join(CONFIG_DIR, "cli.json");
|
|
1921
|
-
var RUN_TIMEOUT_MS = 18e4;
|
|
1922
|
-
function loadConfig() {
|
|
1923
|
-
try {
|
|
1924
|
-
return JSON.parse(readFileSync(CONFIG_PATH, "utf8"));
|
|
1925
|
-
} catch {
|
|
1926
|
-
return {};
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
function saveConfig(config) {
|
|
1930
|
-
try {
|
|
1931
|
-
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
1932
|
-
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 384 });
|
|
1933
|
-
} catch {
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
function readLastSessionId() {
|
|
1937
|
-
return loadConfig().sessionId;
|
|
1938
|
-
}
|
|
1939
|
-
var RateLimitError = class extends Error {
|
|
1940
|
-
constructor(retryAfter) {
|
|
1941
|
-
super(`\u8BF7\u6C42\u592A\u9891\u7E41\uFF0C\u8BF7\u5728 ${retryAfter} \u79D2\u540E\u518D\u8BD5`);
|
|
1942
|
-
this.retryAfter = retryAfter;
|
|
1943
|
-
}
|
|
1944
|
-
};
|
|
1945
|
-
async function readError(response) {
|
|
1946
|
-
let retryAfter = 0;
|
|
1947
|
-
let message = `HTTP ${response.status}`;
|
|
1948
|
-
try {
|
|
1949
|
-
const payload = await response.json();
|
|
1950
|
-
if (typeof payload.retry_after === "number") retryAfter = payload.retry_after;
|
|
1951
|
-
if (typeof payload.message === "string") message = payload.message;
|
|
1952
|
-
} catch {
|
|
1953
|
-
}
|
|
1954
|
-
if (response.status === 429) {
|
|
1955
|
-
const headerRetry = Number(response.headers.get("Retry-After"));
|
|
1956
|
-
throw new RateLimitError(retryAfter || headerRetry || 60);
|
|
1957
|
-
}
|
|
1958
|
-
throw new Error(message);
|
|
1959
|
-
}
|
|
1960
|
-
async function runAgentChat(input) {
|
|
1961
|
-
const config = loadConfig();
|
|
1962
|
-
const token = config.agentToken;
|
|
1963
|
-
const sessionId = input.sessionId;
|
|
1964
|
-
const runsResponse = await fetch(`${API_URL}/api/os-agent/runs`, {
|
|
1965
|
-
method: "POST",
|
|
1966
|
-
headers: {
|
|
1967
|
-
"Content-Type": "application/json",
|
|
1968
|
-
...token ? { [AGENT_HEADER]: token } : {}
|
|
1969
|
-
},
|
|
1970
|
-
body: JSON.stringify({
|
|
1971
|
-
message: input.message,
|
|
1972
|
-
...sessionId ? { sessionId } : {},
|
|
1973
|
-
context: {
|
|
1974
|
-
surface: "cli",
|
|
1975
|
-
...process.stdout.columns ? { columns: process.stdout.columns } : {}
|
|
1976
|
-
}
|
|
1977
|
-
})
|
|
1978
|
-
});
|
|
1979
|
-
if (!runsResponse.ok) await readError(runsResponse);
|
|
1980
|
-
const issuedToken = runsResponse.headers.get(AGENT_HEADER) ?? token;
|
|
1981
|
-
const queued = (await runsResponse.json()).data ?? {};
|
|
1982
|
-
const runId = queued.runId;
|
|
1983
|
-
const newSessionId = queued.sessionId ?? "";
|
|
1984
|
-
if (!runId) throw new Error("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE runId");
|
|
1985
|
-
if (issuedToken || newSessionId) {
|
|
1986
|
-
saveConfig({
|
|
1987
|
-
...issuedToken ? { agentToken: issuedToken } : {},
|
|
1988
|
-
...newSessionId ? { sessionId: newSessionId } : {}
|
|
1989
|
-
});
|
|
1990
|
-
}
|
|
1991
|
-
const eventsResponse = await fetch(`${API_URL}/api/os-agent/runs/${runId}/events`, {
|
|
1992
|
-
method: "POST",
|
|
1993
|
-
headers: issuedToken ? { [AGENT_HEADER]: issuedToken } : {},
|
|
1994
|
-
signal: AbortSignal.timeout(RUN_TIMEOUT_MS)
|
|
1995
|
-
});
|
|
1996
|
-
if (!eventsResponse.ok) await readError(eventsResponse);
|
|
1997
|
-
if (!eventsResponse.body) throw new Error("\u4E8B\u4EF6\u6D41\u4E3A\u7A7A");
|
|
1998
|
-
let response = "";
|
|
1999
|
-
let deltaText = "";
|
|
2000
|
-
const terminal = await consumeSse(eventsResponse.body, (event, payload) => {
|
|
2001
|
-
if (event === "message.delta") {
|
|
2002
|
-
const text = typeof payload?.text === "string" ? payload.text : "";
|
|
2003
|
-
if (text) {
|
|
2004
|
-
deltaText += text;
|
|
2005
|
-
input.onEvent?.({ type: "delta", text });
|
|
2006
|
-
}
|
|
2007
|
-
return;
|
|
2008
|
-
}
|
|
2009
|
-
if (event === "tool.started" && typeof payload?.name === "string") {
|
|
2010
|
-
input.onEvent?.({ type: "tool", name: payload.name });
|
|
2011
|
-
return;
|
|
2012
|
-
}
|
|
2013
|
-
if (event === "run.completed") {
|
|
2014
|
-
response = typeof payload?.message === "string" ? payload.message : deltaText;
|
|
2015
|
-
}
|
|
2016
|
-
if (event === "run.failed") {
|
|
2017
|
-
throw new Error(typeof payload?.message === "string" ? payload.message : "agent_run_failed");
|
|
2018
|
-
}
|
|
2019
|
-
if (event === "run.cancelled" || event === "run.superseded") {
|
|
2020
|
-
throw new Error("agent_run_cancelled");
|
|
2021
|
-
}
|
|
2022
|
-
});
|
|
2023
|
-
if (!terminal) throw new Error("\u4E8B\u4EF6\u6D41\u63D0\u524D\u7ED3\u675F");
|
|
2024
|
-
return {
|
|
2025
|
-
response: response || deltaText,
|
|
2026
|
-
sessionId: newSessionId,
|
|
2027
|
-
runId,
|
|
2028
|
-
silent: terminal === "run.silent"
|
|
2029
|
-
};
|
|
2030
|
-
}
|
|
2031
|
-
async function consumeSse(body, onEvent) {
|
|
2032
|
-
const terminalEvents = /* @__PURE__ */ new Set(["run.completed", "run.silent", "run.failed", "run.cancelled", "run.superseded"]);
|
|
2033
|
-
const reader = body.getReader();
|
|
2034
|
-
const decoder = new TextDecoder();
|
|
2035
|
-
let buffer = "";
|
|
2036
|
-
while (true) {
|
|
2037
|
-
const { done, value } = await reader.read();
|
|
2038
|
-
if (done) break;
|
|
2039
|
-
buffer += decoder.decode(value, { stream: true });
|
|
2040
|
-
let separator = buffer.indexOf("\n\n");
|
|
2041
|
-
while (separator !== -1) {
|
|
2042
|
-
const frame = buffer.slice(0, separator);
|
|
2043
|
-
buffer = buffer.slice(separator + 2);
|
|
2044
|
-
separator = buffer.indexOf("\n\n");
|
|
2045
|
-
const parsed = parseFrame(frame);
|
|
2046
|
-
if (!parsed) continue;
|
|
2047
|
-
onEvent(parsed.event, parsed.payload);
|
|
2048
|
-
if (terminalEvents.has(parsed.event)) {
|
|
2049
|
-
await reader.cancel().catch(() => void 0);
|
|
2050
|
-
return parsed.event;
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
return null;
|
|
2055
|
-
}
|
|
2056
|
-
function parseFrame(frame) {
|
|
2057
|
-
let event = "message";
|
|
2058
|
-
let data = "";
|
|
2059
|
-
for (const line of frame.split("\n")) {
|
|
2060
|
-
if (line.startsWith("event: ")) event = line.slice(7).trim();
|
|
2061
|
-
else if (line.startsWith("data: ")) data += line.slice(6);
|
|
2062
|
-
}
|
|
2063
|
-
if (!data) return null;
|
|
2064
|
-
try {
|
|
2065
|
-
const parsed = JSON.parse(data);
|
|
2066
|
-
const payload = parsed.payload ?? parsed;
|
|
2067
|
-
return { event, payload };
|
|
2068
|
-
} catch {
|
|
2069
|
-
return { event, payload: null };
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
|
|
2073
2123
|
// src/commands/chat.tsx
|
|
2074
2124
|
var writeHumanMarkdown = (source) => {
|
|
2075
2125
|
const rendered = renderMarkdownAnsi(source);
|
|
@@ -2105,14 +2155,12 @@ async function chatSync(message, json = false, sessionId) {
|
|
|
2105
2155
|
}
|
|
2106
2156
|
});
|
|
2107
2157
|
if (json) {
|
|
2108
|
-
|
|
2109
|
-
tool: "maidang",
|
|
2110
|
-
command: "chat",
|
|
2158
|
+
printJsonOk("chat", {
|
|
2111
2159
|
message,
|
|
2112
2160
|
response: result.silent ? "" : result.response,
|
|
2113
2161
|
sessionId: result.sessionId,
|
|
2114
2162
|
runId: result.runId
|
|
2115
|
-
}
|
|
2163
|
+
});
|
|
2116
2164
|
return;
|
|
2117
2165
|
}
|
|
2118
2166
|
flushPending();
|
|
@@ -2124,13 +2172,9 @@ async function chatSync(message, json = false, sessionId) {
|
|
|
2124
2172
|
console.log(chalk4.dim("\u4F7F\u7528 -c \u7EED\u63A5\uFF0C\u6216 --session-id <id> \u6307\u5B9A\u4F1A\u8BDD"));
|
|
2125
2173
|
}
|
|
2126
2174
|
} catch (err) {
|
|
2127
|
-
if (json)
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
} else {
|
|
2131
|
-
console.error(chalk4.red(`Error: ${err.message}`));
|
|
2132
|
-
process.exit(1);
|
|
2133
|
-
}
|
|
2175
|
+
if (json) printJsonErr("chat", classifyError(err));
|
|
2176
|
+
console.error(chalk4.red(`Error: ${err.message}`));
|
|
2177
|
+
process.exit(1);
|
|
2134
2178
|
}
|
|
2135
2179
|
}
|
|
2136
2180
|
var _id = 0;
|
|
@@ -2283,7 +2327,7 @@ var ChatApp = ({ sessionId: initialSessionId, notice }) => {
|
|
|
2283
2327
|
});
|
|
2284
2328
|
setCursorPos((p) => p + char.length);
|
|
2285
2329
|
});
|
|
2286
|
-
const
|
|
2330
|
+
const isFullWidth2 = (ch) => {
|
|
2287
2331
|
const code = ch.charCodeAt(0);
|
|
2288
2332
|
return code >= 19968 && code <= 40959 || // CJK Unified Ideographs
|
|
2289
2333
|
code >= 12288 && code <= 12351 || // CJK Symbols
|
|
@@ -2296,7 +2340,7 @@ var ChatApp = ({ sessionId: initialSessionId, notice }) => {
|
|
|
2296
2340
|
const before = input.slice(0, cursorPos);
|
|
2297
2341
|
const cursorChar = input[cursorPos] ?? " ";
|
|
2298
2342
|
const after = input.slice(cursorPos + 1);
|
|
2299
|
-
const fw =
|
|
2343
|
+
const fw = isFullWidth2(cursorChar) ? 2 : 1;
|
|
2300
2344
|
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Text2, { color: "cyan" }, "> "), /* @__PURE__ */ React2.createElement(Text2, null, before), /* @__PURE__ */ React2.createElement(Text2, { backgroundColor: "gray", color: "black" }, cursorChar, fw === 2 ? " " : ""), /* @__PURE__ */ React2.createElement(Text2, null, after), loading && /* @__PURE__ */ React2.createElement(Text2, { dimColor: true }, " "));
|
|
2301
2345
|
};
|
|
2302
2346
|
return /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column", paddingX: 1, flexGrow: 1 }, /* @__PURE__ */ React2.createElement(Box2, { flexDirection: "column", flexGrow: 1 }, notice && /* @__PURE__ */ React2.createElement(Box2, { marginBottom: 1 }, /* @__PURE__ */ React2.createElement(Text2, { dimColor: true }, notice)), items.map((item) => {
|
|
@@ -2320,10 +2364,9 @@ var resolveSessionId = (opts) => {
|
|
|
2320
2364
|
if (opts.sessionId && opts.continue) {
|
|
2321
2365
|
const message = "--session-id \u4E0E -c \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528";
|
|
2322
2366
|
if (opts.json) {
|
|
2323
|
-
|
|
2324
|
-
} else {
|
|
2325
|
-
console.error(chalk4.red(`Error: ${message}`));
|
|
2367
|
+
printJsonErr("chat", { type: "invalid_args", message, hint: "\u4E8C\u9009\u4E00\uFF1A--session-id \u7EED\u63A5\u6307\u5B9A\u5BF9\u8BDD\uFF0C-c \u7EED\u63A5\u4E0A\u4E00\u6B21" });
|
|
2326
2368
|
}
|
|
2369
|
+
console.error(chalk4.red(`Error: ${message}`));
|
|
2327
2370
|
process.exit(1);
|
|
2328
2371
|
}
|
|
2329
2372
|
if (opts.sessionId) return opts.sessionId;
|
|
@@ -2336,10 +2379,9 @@ function createChatCommand() {
|
|
|
2336
2379
|
if (opts.json || opts.message) {
|
|
2337
2380
|
if (!opts.message) {
|
|
2338
2381
|
if (opts.json) {
|
|
2339
|
-
|
|
2340
|
-
} else {
|
|
2341
|
-
console.error('\u8BF7\u63D0\u4F9B\u6D88\u606F\uFF1Amaidang chat -m "\u4F60\u597D"');
|
|
2382
|
+
printJsonErr("chat", { type: "invalid_args", message: "\u7F3A\u5C11\u6D88\u606F\u5185\u5BB9", hint: '\u7528\u6CD5\uFF1Amaidang chat -m "\u4F60\u597D"' });
|
|
2342
2383
|
}
|
|
2384
|
+
console.error('\u8BF7\u63D0\u4F9B\u6D88\u606F\uFF1Amaidang chat -m "\u4F60\u597D"');
|
|
2343
2385
|
process.exit(1);
|
|
2344
2386
|
}
|
|
2345
2387
|
await chatSync(opts.message, !!opts.json, resolveSessionId(opts));
|
|
@@ -2371,9 +2413,6 @@ function getAgeVersion() {
|
|
|
2371
2413
|
async function fetchOrEmpty(url) {
|
|
2372
2414
|
try {
|
|
2373
2415
|
const res = await fetch(url);
|
|
2374
|
-
if (!res.ok) {
|
|
2375
|
-
throw new Error(await readApiMessage(res));
|
|
2376
|
-
}
|
|
2377
2416
|
return await readApiData(res);
|
|
2378
2417
|
} catch {
|
|
2379
2418
|
return null;
|
|
@@ -2390,8 +2429,6 @@ function createManifestCommand() {
|
|
|
2390
2429
|
fetchOrEmpty(`${apiUrl}/api/links`)
|
|
2391
2430
|
]);
|
|
2392
2431
|
const manifest = {
|
|
2393
|
-
tool: "maidang",
|
|
2394
|
-
command: "manifest",
|
|
2395
2432
|
version: getAgeVersion(),
|
|
2396
2433
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2397
2434
|
source: apiUrl,
|
|
@@ -2450,7 +2487,7 @@ function createManifestCommand() {
|
|
|
2450
2487
|
console.log("");
|
|
2451
2488
|
return;
|
|
2452
2489
|
}
|
|
2453
|
-
|
|
2490
|
+
printJsonOk("manifest", manifest);
|
|
2454
2491
|
});
|
|
2455
2492
|
return cmd;
|
|
2456
2493
|
}
|
|
@@ -2512,7 +2549,9 @@ function createNewsCommand() {
|
|
|
2512
2549
|
try {
|
|
2513
2550
|
const date = opts.date?.trim();
|
|
2514
2551
|
if (date !== void 0 && !isValidIssueDate(date)) {
|
|
2515
|
-
|
|
2552
|
+
const message = "--date \u683C\u5F0F\u5FC5\u987B\u4E3A YYYY-MM-DD\uFF0C\u4E14\u662F\u771F\u5B9E\u5B58\u5728\u7684\u65E5\u671F";
|
|
2553
|
+
if (opts.json) printJsonErr("news", { type: "invalid_args", message, hint: "\u4F8B\u5982 2026-08-23" }, 2);
|
|
2554
|
+
console.error(theme.err(message));
|
|
2516
2555
|
process.exit(2);
|
|
2517
2556
|
}
|
|
2518
2557
|
let path;
|
|
@@ -2526,18 +2565,14 @@ function createNewsCommand() {
|
|
|
2526
2565
|
const response = await fetch(`${baseApiUrl}${path}`);
|
|
2527
2566
|
if (response.status === 404) {
|
|
2528
2567
|
const message = opts.list ? "\u76EE\u5F55\u8FD8\u4E0D\u5B58\u5728" : date ? "\u8FD9\u4E00\u5929\u7684\u62A5\u7EB8\u8FD8\u4E0D\u5B58\u5728" : "\u4ECA\u5929\u8FD8\u6CA1\u51FA\u62A5\uFF0C\u7A0D\u540E\u518D\u6765\u770B\u770B";
|
|
2529
|
-
if (opts.json) {
|
|
2530
|
-
|
|
2531
|
-
} else {
|
|
2532
|
-
console.error(theme.err(message));
|
|
2533
|
-
}
|
|
2568
|
+
if (opts.json) printJsonErr("news", { type: "not_found", message, hint: "\u7528 --list \u67E5\u770B\u5DF2\u51FA\u76EE\u5F55" }, 3);
|
|
2569
|
+
console.error(theme.err(message));
|
|
2534
2570
|
process.exit(3);
|
|
2535
2571
|
}
|
|
2536
|
-
if (!response.ok) throw new Error(await readApiMessage(response));
|
|
2537
2572
|
if (opts.list) {
|
|
2538
2573
|
const data2 = await readApiData(response);
|
|
2539
2574
|
if (opts.json) {
|
|
2540
|
-
|
|
2575
|
+
printJsonOk("news", data2);
|
|
2541
2576
|
return;
|
|
2542
2577
|
}
|
|
2543
2578
|
printIssueList(data2.issues ?? []);
|
|
@@ -2545,11 +2580,12 @@ function createNewsCommand() {
|
|
|
2545
2580
|
}
|
|
2546
2581
|
const data = await readApiData(response);
|
|
2547
2582
|
if (opts.json) {
|
|
2548
|
-
|
|
2583
|
+
printJsonOk("news", { date, issue: data.issue });
|
|
2549
2584
|
return;
|
|
2550
2585
|
}
|
|
2551
2586
|
printIssue(data.issue);
|
|
2552
2587
|
} catch (error) {
|
|
2588
|
+
if (opts.json) printJsonErr("news", classifyError(error));
|
|
2553
2589
|
console.error(theme.err(`\u83B7\u53D6 AI \u65E5\u62A5\u5931\u8D25: ${error instanceof Error ? error.message : error}`));
|
|
2554
2590
|
process.exit(1);
|
|
2555
2591
|
}
|
|
@@ -2580,14 +2616,14 @@ function createChangelogCommand() {
|
|
|
2580
2616
|
cmd.action(async (opts) => {
|
|
2581
2617
|
try {
|
|
2582
2618
|
const response = await fetch(`${baseApiUrl}/api/changelog`);
|
|
2583
|
-
if (!response.ok) throw new Error(await readApiMessage(response));
|
|
2584
2619
|
const entries = await readApiData(response);
|
|
2585
2620
|
if (opts.json) {
|
|
2586
|
-
|
|
2621
|
+
printJsonOk("changelog", { entries });
|
|
2587
2622
|
return;
|
|
2588
2623
|
}
|
|
2589
2624
|
printChangelog(entries ?? []);
|
|
2590
2625
|
} catch (error) {
|
|
2626
|
+
if (opts.json) printJsonErr("changelog", classifyError(error));
|
|
2591
2627
|
console.error(theme.err(`\u83B7\u53D6\u66F4\u65B0\u65E5\u5FD7\u5931\u8D25: ${error instanceof Error ? error.message : error}`));
|
|
2592
2628
|
process.exit(1);
|
|
2593
2629
|
}
|
|
@@ -2680,7 +2716,7 @@ async function fetchLatestVersion(options) {
|
|
|
2680
2716
|
signal: controller.signal,
|
|
2681
2717
|
headers: { Accept: "application/json" }
|
|
2682
2718
|
});
|
|
2683
|
-
if (!response.ok) throw new
|
|
2719
|
+
if (!response.ok) throw new ApiRequestError(`registry HTTP ${response.status}`, response.status);
|
|
2684
2720
|
const payload = await response.json();
|
|
2685
2721
|
if (typeof payload.latest !== "string" || !payload.latest) {
|
|
2686
2722
|
throw new Error("registry response missing latest tag");
|
|
@@ -2715,7 +2751,7 @@ function buildInstallCommand(pm) {
|
|
|
2715
2751
|
return `${cmd} ${args.join(" ")}`;
|
|
2716
2752
|
}
|
|
2717
2753
|
function printJsonResult(result) {
|
|
2718
|
-
|
|
2754
|
+
printJsonOk("upgrade", result);
|
|
2719
2755
|
}
|
|
2720
2756
|
function confirmUpgrade() {
|
|
2721
2757
|
return new Promise((resolve) => {
|
|
@@ -2735,15 +2771,11 @@ function createUpgradeCommand() {
|
|
|
2735
2771
|
if (opts.pm) {
|
|
2736
2772
|
const requested = opts.pm.trim().toLowerCase();
|
|
2737
2773
|
if (!KNOWN_PACKAGE_MANAGERS.includes(requested)) {
|
|
2774
|
+
const message = `--pm \u53EA\u652F\u6301 ${KNOWN_PACKAGE_MANAGERS.join("/")}`;
|
|
2738
2775
|
if (opts.json) {
|
|
2739
|
-
|
|
2740
|
-
tool: "maidang",
|
|
2741
|
-
command: "upgrade",
|
|
2742
|
-
error: `--pm \u53EA\u652F\u6301 ${KNOWN_PACKAGE_MANAGERS.join("/")}`
|
|
2743
|
-
}, null, 2));
|
|
2744
|
-
} else {
|
|
2745
|
-
console.error(theme.err(`--pm \u53EA\u652F\u6301 ${KNOWN_PACKAGE_MANAGERS.join("/")}`));
|
|
2776
|
+
printJsonErr("upgrade", { type: "invalid_args", message, hint: "\u4F8B\u5982 maidang upgrade --pm pnpm" }, 2);
|
|
2746
2777
|
}
|
|
2778
|
+
console.error(theme.err(message));
|
|
2747
2779
|
process.exit(2);
|
|
2748
2780
|
}
|
|
2749
2781
|
pm = requested;
|
|
@@ -2754,12 +2786,11 @@ function createUpgradeCommand() {
|
|
|
2754
2786
|
latestVersion = await fetchLatestVersion({ timeoutMs: 1e4, allowNpmConfig: true });
|
|
2755
2787
|
} catch (error) {
|
|
2756
2788
|
const reason = error instanceof Error ? error.message : String(error);
|
|
2757
|
-
const
|
|
2789
|
+
const installHint = `\u53EF\u624B\u52A8\u6267\u884C: ${buildInstallCommand(pm)}`;
|
|
2758
2790
|
if (opts.json) {
|
|
2759
|
-
|
|
2760
|
-
} else {
|
|
2761
|
-
console.error(theme.err(message));
|
|
2791
|
+
printJsonErr("upgrade", { ...classifyError(error), message: `\u67E5\u8BE2 registry \u5931\u8D25: ${reason}`, hint: installHint });
|
|
2762
2792
|
}
|
|
2793
|
+
console.error(theme.err(`\u67E5\u8BE2 registry \u5931\u8D25: ${reason}\uFF0C${installHint}`));
|
|
2763
2794
|
process.exit(1);
|
|
2764
2795
|
}
|
|
2765
2796
|
const updateAvailable = compareVersions(latestVersion, currentVersion) > 0;
|
|
@@ -2846,20 +2877,18 @@ function createUpgradeCommand() {
|
|
|
2846
2877
|
const failureMessage = installResult.error?.message ?? `\u9000\u51FA\u7801 ${installResult.status}`;
|
|
2847
2878
|
result.upgraded = false;
|
|
2848
2879
|
if (opts.json) {
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
}
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
console.error(" " + theme.inkMuted("npm config set prefix ~/.npm-global"));
|
|
2862
|
-
}
|
|
2880
|
+
printJsonErr("upgrade", {
|
|
2881
|
+
type: "unknown",
|
|
2882
|
+
message: `\u5347\u7EA7\u5931\u8D25: ${failureMessage}`,
|
|
2883
|
+
hint: `\u53EF\u624B\u52A8\u6267\u884C ${result.installCommand}`
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
console.error(theme.err(`\u5347\u7EA7\u5931\u8D25\uFF08${failureMessage}\uFF09\uFF0C\u53EF\u624B\u52A8\u6267\u884C\uFF1A`));
|
|
2887
|
+
console.error(" " + theme.link(result.installCommand));
|
|
2888
|
+
const errorCode = installResult.error?.code;
|
|
2889
|
+
if (errorCode === "EACCES") {
|
|
2890
|
+
console.error(" " + theme.inkSoft("\u6743\u9650\u4E0D\u8DB3\u65F6\u4E0D\u5EFA\u8BAE sudo\uFF0C\u5EFA\u8BAE\u7528 nvm \u6216\u4FEE\u6539 npm prefix\uFF1A"));
|
|
2891
|
+
console.error(" " + theme.inkMuted("npm config set prefix ~/.npm-global"));
|
|
2863
2892
|
}
|
|
2864
2893
|
process.exit(1);
|
|
2865
2894
|
}
|
|
@@ -2875,6 +2904,547 @@ function createUpgradeCommand() {
|
|
|
2875
2904
|
return cmd;
|
|
2876
2905
|
}
|
|
2877
2906
|
|
|
2907
|
+
// src/core/help.ts
|
|
2908
|
+
import { Help } from "commander";
|
|
2909
|
+
|
|
2910
|
+
// ../../node_modules/.pnpm/ansi-regex@6.2.2/node_modules/ansi-regex/index.js
|
|
2911
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
2912
|
+
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
2913
|
+
const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
|
|
2914
|
+
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
2915
|
+
const pattern = `${osc}|${csi}`;
|
|
2916
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2919
|
+
// ../../node_modules/.pnpm/strip-ansi@7.2.0/node_modules/strip-ansi/index.js
|
|
2920
|
+
var regex = ansiRegex();
|
|
2921
|
+
function stripAnsi(string) {
|
|
2922
|
+
if (typeof string !== "string") {
|
|
2923
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
2924
|
+
}
|
|
2925
|
+
if (!string.includes("\x1B") && !string.includes("\x9B")) {
|
|
2926
|
+
return string;
|
|
2927
|
+
}
|
|
2928
|
+
return string.replace(regex, "");
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2931
|
+
// ../../node_modules/.pnpm/get-east-asian-width@1.5.0/node_modules/get-east-asian-width/lookup-data.js
|
|
2932
|
+
var ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
2933
|
+
var fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
2934
|
+
var halfwidthRanges = [8361, 8361, 65377, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65512, 65518];
|
|
2935
|
+
var narrowRanges = [32, 126, 162, 163, 165, 166, 172, 172, 175, 175, 10214, 10221, 10629, 10630];
|
|
2936
|
+
var wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
|
|
2937
|
+
|
|
2938
|
+
// ../../node_modules/.pnpm/get-east-asian-width@1.5.0/node_modules/get-east-asian-width/utilities.js
|
|
2939
|
+
var isInRange = (ranges, codePoint) => {
|
|
2940
|
+
let low = 0;
|
|
2941
|
+
let high = Math.floor(ranges.length / 2) - 1;
|
|
2942
|
+
while (low <= high) {
|
|
2943
|
+
const mid = Math.floor((low + high) / 2);
|
|
2944
|
+
const i = mid * 2;
|
|
2945
|
+
if (codePoint < ranges[i]) {
|
|
2946
|
+
high = mid - 1;
|
|
2947
|
+
} else if (codePoint > ranges[i + 1]) {
|
|
2948
|
+
low = mid + 1;
|
|
2949
|
+
} else {
|
|
2950
|
+
return true;
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
return false;
|
|
2954
|
+
};
|
|
2955
|
+
|
|
2956
|
+
// ../../node_modules/.pnpm/get-east-asian-width@1.5.0/node_modules/get-east-asian-width/lookup.js
|
|
2957
|
+
var minimumAmbiguousCodePoint = ambiguousRanges[0];
|
|
2958
|
+
var maximumAmbiguousCodePoint = ambiguousRanges.at(-1);
|
|
2959
|
+
var minimumFullWidthCodePoint = fullwidthRanges[0];
|
|
2960
|
+
var maximumFullWidthCodePoint = fullwidthRanges.at(-1);
|
|
2961
|
+
var minimumHalfWidthCodePoint = halfwidthRanges[0];
|
|
2962
|
+
var maximumHalfWidthCodePoint = halfwidthRanges.at(-1);
|
|
2963
|
+
var minimumNarrowCodePoint = narrowRanges[0];
|
|
2964
|
+
var maximumNarrowCodePoint = narrowRanges.at(-1);
|
|
2965
|
+
var minimumWideCodePoint = wideRanges[0];
|
|
2966
|
+
var maximumWideCodePoint = wideRanges.at(-1);
|
|
2967
|
+
var commonCjkCodePoint = 19968;
|
|
2968
|
+
var [wideFastPathStart, wideFastPathEnd] = findWideFastPathRange(wideRanges);
|
|
2969
|
+
function findWideFastPathRange(ranges) {
|
|
2970
|
+
let fastPathStart = ranges[0];
|
|
2971
|
+
let fastPathEnd = ranges[1];
|
|
2972
|
+
for (let index = 0; index < ranges.length; index += 2) {
|
|
2973
|
+
const start = ranges[index];
|
|
2974
|
+
const end = ranges[index + 1];
|
|
2975
|
+
if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) {
|
|
2976
|
+
return [start, end];
|
|
2977
|
+
}
|
|
2978
|
+
if (end - start > fastPathEnd - fastPathStart) {
|
|
2979
|
+
fastPathStart = start;
|
|
2980
|
+
fastPathEnd = end;
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
return [fastPathStart, fastPathEnd];
|
|
2984
|
+
}
|
|
2985
|
+
var isAmbiguous = (codePoint) => {
|
|
2986
|
+
if (codePoint < minimumAmbiguousCodePoint || codePoint > maximumAmbiguousCodePoint) {
|
|
2987
|
+
return false;
|
|
2988
|
+
}
|
|
2989
|
+
return isInRange(ambiguousRanges, codePoint);
|
|
2990
|
+
};
|
|
2991
|
+
var isFullWidth = (codePoint) => {
|
|
2992
|
+
if (codePoint < minimumFullWidthCodePoint || codePoint > maximumFullWidthCodePoint) {
|
|
2993
|
+
return false;
|
|
2994
|
+
}
|
|
2995
|
+
return isInRange(fullwidthRanges, codePoint);
|
|
2996
|
+
};
|
|
2997
|
+
var isWide = (codePoint) => {
|
|
2998
|
+
if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
|
|
2999
|
+
return true;
|
|
3000
|
+
}
|
|
3001
|
+
if (codePoint < minimumWideCodePoint || codePoint > maximumWideCodePoint) {
|
|
3002
|
+
return false;
|
|
3003
|
+
}
|
|
3004
|
+
return isInRange(wideRanges, codePoint);
|
|
3005
|
+
};
|
|
3006
|
+
|
|
3007
|
+
// ../../node_modules/.pnpm/get-east-asian-width@1.5.0/node_modules/get-east-asian-width/index.js
|
|
3008
|
+
function validate(codePoint) {
|
|
3009
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
3010
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
3014
|
+
validate(codePoint);
|
|
3015
|
+
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
3016
|
+
return 2;
|
|
3017
|
+
}
|
|
3018
|
+
return 1;
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
// ../../node_modules/.pnpm/string-width@7.2.0/node_modules/string-width/index.js
|
|
3022
|
+
var import_emoji_regex = __toESM(require_emoji_regex(), 1);
|
|
3023
|
+
var segmenter = new Intl.Segmenter();
|
|
3024
|
+
var defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
|
|
3025
|
+
function stringWidth(string, options = {}) {
|
|
3026
|
+
if (typeof string !== "string" || string.length === 0) {
|
|
3027
|
+
return 0;
|
|
3028
|
+
}
|
|
3029
|
+
const {
|
|
3030
|
+
ambiguousIsNarrow = true,
|
|
3031
|
+
countAnsiEscapeCodes = false
|
|
3032
|
+
} = options;
|
|
3033
|
+
if (!countAnsiEscapeCodes) {
|
|
3034
|
+
string = stripAnsi(string);
|
|
3035
|
+
}
|
|
3036
|
+
if (string.length === 0) {
|
|
3037
|
+
return 0;
|
|
3038
|
+
}
|
|
3039
|
+
let width = 0;
|
|
3040
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
3041
|
+
for (const { segment: character } of segmenter.segment(string)) {
|
|
3042
|
+
const codePoint = character.codePointAt(0);
|
|
3043
|
+
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
|
|
3044
|
+
continue;
|
|
3045
|
+
}
|
|
3046
|
+
if (codePoint >= 8203 && codePoint <= 8207 || codePoint === 65279) {
|
|
3047
|
+
continue;
|
|
3048
|
+
}
|
|
3049
|
+
if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
|
|
3050
|
+
continue;
|
|
3051
|
+
}
|
|
3052
|
+
if (codePoint >= 55296 && codePoint <= 57343) {
|
|
3053
|
+
continue;
|
|
3054
|
+
}
|
|
3055
|
+
if (codePoint >= 65024 && codePoint <= 65039) {
|
|
3056
|
+
continue;
|
|
3057
|
+
}
|
|
3058
|
+
if (defaultIgnorableCodePointRegex.test(character)) {
|
|
3059
|
+
continue;
|
|
3060
|
+
}
|
|
3061
|
+
if ((0, import_emoji_regex.default)().test(character)) {
|
|
3062
|
+
width += 2;
|
|
3063
|
+
continue;
|
|
3064
|
+
}
|
|
3065
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
3066
|
+
}
|
|
3067
|
+
return width;
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
// ../../node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js
|
|
3071
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
3072
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
3073
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
3074
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
3075
|
+
var styles = {
|
|
3076
|
+
modifier: {
|
|
3077
|
+
reset: [0, 0],
|
|
3078
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
3079
|
+
bold: [1, 22],
|
|
3080
|
+
dim: [2, 22],
|
|
3081
|
+
italic: [3, 23],
|
|
3082
|
+
underline: [4, 24],
|
|
3083
|
+
overline: [53, 55],
|
|
3084
|
+
inverse: [7, 27],
|
|
3085
|
+
hidden: [8, 28],
|
|
3086
|
+
strikethrough: [9, 29]
|
|
3087
|
+
},
|
|
3088
|
+
color: {
|
|
3089
|
+
black: [30, 39],
|
|
3090
|
+
red: [31, 39],
|
|
3091
|
+
green: [32, 39],
|
|
3092
|
+
yellow: [33, 39],
|
|
3093
|
+
blue: [34, 39],
|
|
3094
|
+
magenta: [35, 39],
|
|
3095
|
+
cyan: [36, 39],
|
|
3096
|
+
white: [37, 39],
|
|
3097
|
+
// Bright color
|
|
3098
|
+
blackBright: [90, 39],
|
|
3099
|
+
gray: [90, 39],
|
|
3100
|
+
// Alias of `blackBright`
|
|
3101
|
+
grey: [90, 39],
|
|
3102
|
+
// Alias of `blackBright`
|
|
3103
|
+
redBright: [91, 39],
|
|
3104
|
+
greenBright: [92, 39],
|
|
3105
|
+
yellowBright: [93, 39],
|
|
3106
|
+
blueBright: [94, 39],
|
|
3107
|
+
magentaBright: [95, 39],
|
|
3108
|
+
cyanBright: [96, 39],
|
|
3109
|
+
whiteBright: [97, 39]
|
|
3110
|
+
},
|
|
3111
|
+
bgColor: {
|
|
3112
|
+
bgBlack: [40, 49],
|
|
3113
|
+
bgRed: [41, 49],
|
|
3114
|
+
bgGreen: [42, 49],
|
|
3115
|
+
bgYellow: [43, 49],
|
|
3116
|
+
bgBlue: [44, 49],
|
|
3117
|
+
bgMagenta: [45, 49],
|
|
3118
|
+
bgCyan: [46, 49],
|
|
3119
|
+
bgWhite: [47, 49],
|
|
3120
|
+
// Bright color
|
|
3121
|
+
bgBlackBright: [100, 49],
|
|
3122
|
+
bgGray: [100, 49],
|
|
3123
|
+
// Alias of `bgBlackBright`
|
|
3124
|
+
bgGrey: [100, 49],
|
|
3125
|
+
// Alias of `bgBlackBright`
|
|
3126
|
+
bgRedBright: [101, 49],
|
|
3127
|
+
bgGreenBright: [102, 49],
|
|
3128
|
+
bgYellowBright: [103, 49],
|
|
3129
|
+
bgBlueBright: [104, 49],
|
|
3130
|
+
bgMagentaBright: [105, 49],
|
|
3131
|
+
bgCyanBright: [106, 49],
|
|
3132
|
+
bgWhiteBright: [107, 49]
|
|
3133
|
+
}
|
|
3134
|
+
};
|
|
3135
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
3136
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
3137
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
3138
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
3139
|
+
function assembleStyles() {
|
|
3140
|
+
const codes = /* @__PURE__ */ new Map();
|
|
3141
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
3142
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
3143
|
+
styles[styleName] = {
|
|
3144
|
+
open: `\x1B[${style[0]}m`,
|
|
3145
|
+
close: `\x1B[${style[1]}m`
|
|
3146
|
+
};
|
|
3147
|
+
group[styleName] = styles[styleName];
|
|
3148
|
+
codes.set(style[0], style[1]);
|
|
3149
|
+
}
|
|
3150
|
+
Object.defineProperty(styles, groupName, {
|
|
3151
|
+
value: group,
|
|
3152
|
+
enumerable: false
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
Object.defineProperty(styles, "codes", {
|
|
3156
|
+
value: codes,
|
|
3157
|
+
enumerable: false
|
|
3158
|
+
});
|
|
3159
|
+
styles.color.close = "\x1B[39m";
|
|
3160
|
+
styles.bgColor.close = "\x1B[49m";
|
|
3161
|
+
styles.color.ansi = wrapAnsi16();
|
|
3162
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
3163
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
3164
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
3165
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
3166
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
3167
|
+
Object.defineProperties(styles, {
|
|
3168
|
+
rgbToAnsi256: {
|
|
3169
|
+
value(red, green, blue) {
|
|
3170
|
+
if (red === green && green === blue) {
|
|
3171
|
+
if (red < 8) {
|
|
3172
|
+
return 16;
|
|
3173
|
+
}
|
|
3174
|
+
if (red > 248) {
|
|
3175
|
+
return 231;
|
|
3176
|
+
}
|
|
3177
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
3178
|
+
}
|
|
3179
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
3180
|
+
},
|
|
3181
|
+
enumerable: false
|
|
3182
|
+
},
|
|
3183
|
+
hexToRgb: {
|
|
3184
|
+
value(hex) {
|
|
3185
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
3186
|
+
if (!matches) {
|
|
3187
|
+
return [0, 0, 0];
|
|
3188
|
+
}
|
|
3189
|
+
let [colorString] = matches;
|
|
3190
|
+
if (colorString.length === 3) {
|
|
3191
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
3192
|
+
}
|
|
3193
|
+
const integer = Number.parseInt(colorString, 16);
|
|
3194
|
+
return [
|
|
3195
|
+
/* eslint-disable no-bitwise */
|
|
3196
|
+
integer >> 16 & 255,
|
|
3197
|
+
integer >> 8 & 255,
|
|
3198
|
+
integer & 255
|
|
3199
|
+
/* eslint-enable no-bitwise */
|
|
3200
|
+
];
|
|
3201
|
+
},
|
|
3202
|
+
enumerable: false
|
|
3203
|
+
},
|
|
3204
|
+
hexToAnsi256: {
|
|
3205
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
3206
|
+
enumerable: false
|
|
3207
|
+
},
|
|
3208
|
+
ansi256ToAnsi: {
|
|
3209
|
+
value(code) {
|
|
3210
|
+
if (code < 8) {
|
|
3211
|
+
return 30 + code;
|
|
3212
|
+
}
|
|
3213
|
+
if (code < 16) {
|
|
3214
|
+
return 90 + (code - 8);
|
|
3215
|
+
}
|
|
3216
|
+
let red;
|
|
3217
|
+
let green;
|
|
3218
|
+
let blue;
|
|
3219
|
+
if (code >= 232) {
|
|
3220
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
3221
|
+
green = red;
|
|
3222
|
+
blue = red;
|
|
3223
|
+
} else {
|
|
3224
|
+
code -= 16;
|
|
3225
|
+
const remainder = code % 36;
|
|
3226
|
+
red = Math.floor(code / 36) / 5;
|
|
3227
|
+
green = Math.floor(remainder / 6) / 5;
|
|
3228
|
+
blue = remainder % 6 / 5;
|
|
3229
|
+
}
|
|
3230
|
+
const value = Math.max(red, green, blue) * 2;
|
|
3231
|
+
if (value === 0) {
|
|
3232
|
+
return 30;
|
|
3233
|
+
}
|
|
3234
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
3235
|
+
if (value === 2) {
|
|
3236
|
+
result += 60;
|
|
3237
|
+
}
|
|
3238
|
+
return result;
|
|
3239
|
+
},
|
|
3240
|
+
enumerable: false
|
|
3241
|
+
},
|
|
3242
|
+
rgbToAnsi: {
|
|
3243
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
3244
|
+
enumerable: false
|
|
3245
|
+
},
|
|
3246
|
+
hexToAnsi: {
|
|
3247
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
3248
|
+
enumerable: false
|
|
3249
|
+
}
|
|
3250
|
+
});
|
|
3251
|
+
return styles;
|
|
3252
|
+
}
|
|
3253
|
+
var ansiStyles = assembleStyles();
|
|
3254
|
+
var ansi_styles_default = ansiStyles;
|
|
3255
|
+
|
|
3256
|
+
// ../../node_modules/.pnpm/wrap-ansi@9.0.2/node_modules/wrap-ansi/index.js
|
|
3257
|
+
var ESCAPES = /* @__PURE__ */ new Set([
|
|
3258
|
+
"\x1B",
|
|
3259
|
+
"\x9B"
|
|
3260
|
+
]);
|
|
3261
|
+
var END_CODE = 39;
|
|
3262
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
3263
|
+
var ANSI_CSI = "[";
|
|
3264
|
+
var ANSI_OSC = "]";
|
|
3265
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
3266
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
3267
|
+
var wrapAnsiCode = (code) => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
3268
|
+
var wrapAnsiHyperlink = (url) => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
3269
|
+
var wordLengths = (string) => string.split(" ").map((character) => stringWidth(character));
|
|
3270
|
+
var wrapWord = (rows, word, columns) => {
|
|
3271
|
+
const characters = [...word];
|
|
3272
|
+
let isInsideEscape = false;
|
|
3273
|
+
let isInsideLinkEscape = false;
|
|
3274
|
+
let visible = stringWidth(stripAnsi(rows.at(-1)));
|
|
3275
|
+
for (const [index, character] of characters.entries()) {
|
|
3276
|
+
const characterLength = stringWidth(character);
|
|
3277
|
+
if (visible + characterLength <= columns) {
|
|
3278
|
+
rows[rows.length - 1] += character;
|
|
3279
|
+
} else {
|
|
3280
|
+
rows.push(character);
|
|
3281
|
+
visible = 0;
|
|
3282
|
+
}
|
|
3283
|
+
if (ESCAPES.has(character)) {
|
|
3284
|
+
isInsideEscape = true;
|
|
3285
|
+
const ansiEscapeLinkCandidate = characters.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join("");
|
|
3286
|
+
isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
|
|
3287
|
+
}
|
|
3288
|
+
if (isInsideEscape) {
|
|
3289
|
+
if (isInsideLinkEscape) {
|
|
3290
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
3291
|
+
isInsideEscape = false;
|
|
3292
|
+
isInsideLinkEscape = false;
|
|
3293
|
+
}
|
|
3294
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
3295
|
+
isInsideEscape = false;
|
|
3296
|
+
}
|
|
3297
|
+
continue;
|
|
3298
|
+
}
|
|
3299
|
+
visible += characterLength;
|
|
3300
|
+
if (visible === columns && index < characters.length - 1) {
|
|
3301
|
+
rows.push("");
|
|
3302
|
+
visible = 0;
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
|
|
3306
|
+
rows[rows.length - 2] += rows.pop();
|
|
3307
|
+
}
|
|
3308
|
+
};
|
|
3309
|
+
var stringVisibleTrimSpacesRight = (string) => {
|
|
3310
|
+
const words = string.split(" ");
|
|
3311
|
+
let last = words.length;
|
|
3312
|
+
while (last > 0) {
|
|
3313
|
+
if (stringWidth(words[last - 1]) > 0) {
|
|
3314
|
+
break;
|
|
3315
|
+
}
|
|
3316
|
+
last--;
|
|
3317
|
+
}
|
|
3318
|
+
if (last === words.length) {
|
|
3319
|
+
return string;
|
|
3320
|
+
}
|
|
3321
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
3322
|
+
};
|
|
3323
|
+
var exec = (string, columns, options = {}) => {
|
|
3324
|
+
if (options.trim !== false && string.trim() === "") {
|
|
3325
|
+
return "";
|
|
3326
|
+
}
|
|
3327
|
+
let returnValue = "";
|
|
3328
|
+
let escapeCode;
|
|
3329
|
+
let escapeUrl;
|
|
3330
|
+
const lengths = wordLengths(string);
|
|
3331
|
+
let rows = [""];
|
|
3332
|
+
for (const [index, word] of string.split(" ").entries()) {
|
|
3333
|
+
if (options.trim !== false) {
|
|
3334
|
+
rows[rows.length - 1] = rows.at(-1).trimStart();
|
|
3335
|
+
}
|
|
3336
|
+
let rowLength = stringWidth(rows.at(-1));
|
|
3337
|
+
if (index !== 0) {
|
|
3338
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
3339
|
+
rows.push("");
|
|
3340
|
+
rowLength = 0;
|
|
3341
|
+
}
|
|
3342
|
+
if (rowLength > 0 || options.trim === false) {
|
|
3343
|
+
rows[rows.length - 1] += " ";
|
|
3344
|
+
rowLength++;
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
if (options.hard && lengths[index] > columns) {
|
|
3348
|
+
const remainingColumns = columns - rowLength;
|
|
3349
|
+
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
|
|
3350
|
+
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
|
|
3351
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
3352
|
+
rows.push("");
|
|
3353
|
+
}
|
|
3354
|
+
wrapWord(rows, word, columns);
|
|
3355
|
+
continue;
|
|
3356
|
+
}
|
|
3357
|
+
if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
|
|
3358
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
3359
|
+
wrapWord(rows, word, columns);
|
|
3360
|
+
continue;
|
|
3361
|
+
}
|
|
3362
|
+
rows.push("");
|
|
3363
|
+
}
|
|
3364
|
+
if (rowLength + lengths[index] > columns && options.wordWrap === false) {
|
|
3365
|
+
wrapWord(rows, word, columns);
|
|
3366
|
+
continue;
|
|
3367
|
+
}
|
|
3368
|
+
rows[rows.length - 1] += word;
|
|
3369
|
+
}
|
|
3370
|
+
if (options.trim !== false) {
|
|
3371
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
3372
|
+
}
|
|
3373
|
+
const preString = rows.join("\n");
|
|
3374
|
+
const pre = [...preString];
|
|
3375
|
+
let preStringIndex = 0;
|
|
3376
|
+
for (const [index, character] of pre.entries()) {
|
|
3377
|
+
returnValue += character;
|
|
3378
|
+
if (ESCAPES.has(character)) {
|
|
3379
|
+
const { groups } = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(preString.slice(preStringIndex)) || { groups: {} };
|
|
3380
|
+
if (groups.code !== void 0) {
|
|
3381
|
+
const code2 = Number.parseFloat(groups.code);
|
|
3382
|
+
escapeCode = code2 === END_CODE ? void 0 : code2;
|
|
3383
|
+
} else if (groups.uri !== void 0) {
|
|
3384
|
+
escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
const code = ansi_styles_default.codes.get(Number(escapeCode));
|
|
3388
|
+
if (pre[index + 1] === "\n") {
|
|
3389
|
+
if (escapeUrl) {
|
|
3390
|
+
returnValue += wrapAnsiHyperlink("");
|
|
3391
|
+
}
|
|
3392
|
+
if (escapeCode && code) {
|
|
3393
|
+
returnValue += wrapAnsiCode(code);
|
|
3394
|
+
}
|
|
3395
|
+
} else if (character === "\n") {
|
|
3396
|
+
if (escapeCode && code) {
|
|
3397
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
3398
|
+
}
|
|
3399
|
+
if (escapeUrl) {
|
|
3400
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
preStringIndex += character.length;
|
|
3404
|
+
}
|
|
3405
|
+
return returnValue;
|
|
3406
|
+
};
|
|
3407
|
+
function wrapAnsi(string, columns, options) {
|
|
3408
|
+
return String(string).normalize().replaceAll("\r\n", "\n").split("\n").map((line) => exec(line, columns, options)).join("\n");
|
|
3409
|
+
}
|
|
3410
|
+
|
|
3411
|
+
// src/core/help.ts
|
|
3412
|
+
var SECTION_TITLES = {
|
|
3413
|
+
"Usage:": "\u7528\u6CD5:",
|
|
3414
|
+
"Arguments:": "\u53C2\u6570:",
|
|
3415
|
+
"Options:": "\u9009\u9879:",
|
|
3416
|
+
"Global Options:": "\u5168\u5C40\u9009\u9879:",
|
|
3417
|
+
"Commands:": "\u547D\u4EE4:"
|
|
3418
|
+
};
|
|
3419
|
+
var ChineseHelp = class extends Help {
|
|
3420
|
+
constructor() {
|
|
3421
|
+
super(...arguments);
|
|
3422
|
+
// 默认 40 列以下不折行,对 2 倍宽的中文太宽松,窄终端直接溢出
|
|
3423
|
+
this.minWidthToWrap = 20;
|
|
3424
|
+
}
|
|
3425
|
+
styleTitle(title) {
|
|
3426
|
+
return SECTION_TITLES[title] ?? title;
|
|
3427
|
+
}
|
|
3428
|
+
displayWidth(str) {
|
|
3429
|
+
return stringWidth(str);
|
|
3430
|
+
}
|
|
3431
|
+
boxWrap(str, width) {
|
|
3432
|
+
if (width < this.minWidthToWrap) return str;
|
|
3433
|
+
return wrapAnsi(str, width, { hard: true, trim: true });
|
|
3434
|
+
}
|
|
3435
|
+
};
|
|
3436
|
+
function envHelpWidth() {
|
|
3437
|
+
const parsed = Number.parseInt(process.env.COLUMNS ?? "", 10);
|
|
3438
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
|
|
3439
|
+
}
|
|
3440
|
+
function localizeHelp(root) {
|
|
3441
|
+
root.createHelp = () => Object.assign(new ChineseHelp(), root.configureHelp());
|
|
3442
|
+
const width = envHelpWidth();
|
|
3443
|
+
if (width !== void 0) root.configureHelp({ helpWidth: width });
|
|
3444
|
+
root.helpOption("-h, --help", "\u663E\u793A\u5E2E\u52A9\u4FE1\u606F");
|
|
3445
|
+
root.commands.forEach(localizeHelp);
|
|
3446
|
+
}
|
|
3447
|
+
|
|
2878
3448
|
// src/core/config.ts
|
|
2879
3449
|
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
2880
3450
|
import { homedir as homedir2 } from "os";
|
|
@@ -2936,7 +3506,7 @@ async function maybeNotifyUpdate(options) {
|
|
|
2936
3506
|
}
|
|
2937
3507
|
|
|
2938
3508
|
// src/index.ts
|
|
2939
|
-
var program = new
|
|
3509
|
+
var program = new Command18();
|
|
2940
3510
|
program.name("maidang").description("\u4E00\u4EFD\u53EF\u4EE5\u88AB AI \u8BFB\u53D6\u7684\u4E2A\u4EBA\u624B\u518C").version(getPackageVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
|
|
2941
3511
|
program.addCommand(createCareerCommand());
|
|
2942
3512
|
program.addCommand(createCatCommand());
|
|
@@ -2953,6 +3523,8 @@ program.addCommand(createManifestCommand());
|
|
|
2953
3523
|
program.addCommand(createNewsCommand());
|
|
2954
3524
|
program.addCommand(createChangelogCommand());
|
|
2955
3525
|
program.addCommand(createUpgradeCommand());
|
|
3526
|
+
localizeHelp(program);
|
|
3527
|
+
program.helpCommand("help [command]", "\u663E\u793A\u547D\u4EE4\u5E2E\u52A9");
|
|
2956
3528
|
program.hook("postAction", async (_thisCommand, actionCommand) => {
|
|
2957
3529
|
const options = typeof actionCommand?.opts === "function" ? actionCommand.opts() : {};
|
|
2958
3530
|
await maybeNotifyUpdate({
|