maidang 29.7.18 → 29.7.19
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 +279 -167
- package/dist/index.js.map +4 -4
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -1,63 +1,89 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command13 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/home.ts
|
|
7
7
|
import { Command } from "commander";
|
|
8
|
-
import chalk2 from "chalk";
|
|
9
8
|
|
|
10
|
-
// src/utils/
|
|
9
|
+
// src/utils/theme.ts
|
|
11
10
|
import chalk from "chalk";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
var theme = {
|
|
12
|
+
// 文字层级(对应 blog 的 ink / ink-soft / ink-muted / ink-faint)
|
|
13
|
+
ink: chalk.white.bold,
|
|
14
|
+
// 主标题、强调
|
|
15
|
+
inkBody: chalk.white,
|
|
16
|
+
// 正文
|
|
17
|
+
inkSoft: chalk.gray,
|
|
18
|
+
// 次级正文 / 描述
|
|
19
|
+
inkMuted: chalk.dim,
|
|
20
|
+
// 元信息、时间、占位
|
|
21
|
+
inkFaint: chalk.dim.gray,
|
|
22
|
+
// 极弱:分隔线、装饰
|
|
23
|
+
// 重音色(cyan 不饱和,跟 blog 的 sage 同质感)
|
|
24
|
+
accent: chalk.cyan,
|
|
25
|
+
accentBold: chalk.cyan.bold,
|
|
26
|
+
accentDim: chalk.cyan.dim,
|
|
27
|
+
// 链接(跟 blog 一样用 accent 而不是 blue)
|
|
28
|
+
link: chalk.cyan,
|
|
29
|
+
linkUnderline: chalk.cyan.underline,
|
|
30
|
+
// 状态
|
|
31
|
+
ok: chalk.green,
|
|
32
|
+
warn: chalk.yellow,
|
|
33
|
+
err: chalk.red
|
|
34
|
+
};
|
|
35
|
+
function eyebrow(text) {
|
|
36
|
+
return chalk.dim(text.toUpperCase());
|
|
37
|
+
}
|
|
38
|
+
function hairline() {
|
|
39
|
+
const cols = process.stdout.columns || 80;
|
|
40
|
+
const len = Math.max(32, Math.min(60, cols - 4));
|
|
41
|
+
return chalk.dim("\u2500".repeat(len));
|
|
42
|
+
}
|
|
43
|
+
function printKV(key, value, keyWidth = 12) {
|
|
44
|
+
console.log(` ${theme.inkBody(key.padEnd(keyWidth))} ${theme.inkSoft(value)}`);
|
|
18
45
|
}
|
|
19
46
|
|
|
20
47
|
// src/commands/home.ts
|
|
21
48
|
var commands = [
|
|
22
|
-
{ name: "whoami", desc: "\
|
|
23
|
-
{ name: "career", desc: "\u5DE5\u4F5C" },
|
|
24
|
-
{ name: "
|
|
49
|
+
{ name: "whoami", desc: "\u4E00\u53E5\u8BDD\u4ECB\u7ECD\u6211" },
|
|
50
|
+
{ name: "career", desc: "\u5DE5\u4F5C\u7ECF\u5386" },
|
|
51
|
+
{ name: "projects", desc: "\u4E00\u4E9B\u5DF2\u7ECF\u843D\u5730\u7684\u4E1C\u897F" },
|
|
52
|
+
{ name: "posts", desc: "\u6700\u8FD1\u5728\u5199\u3001\u5728\u60F3\u7684" },
|
|
53
|
+
{ name: "tools", desc: "\u6700\u8FD1\u5728\u7528\u7684\u597D\u7269" },
|
|
25
54
|
{ name: "songs", desc: "\u5E74\u5EA6\u6B4C\u5355" },
|
|
26
|
-
{ name: "
|
|
27
|
-
{ name: "
|
|
28
|
-
{ name: "
|
|
29
|
-
{ name: "
|
|
30
|
-
{ name: "contact", desc: "\u7559\u8A00" }
|
|
55
|
+
{ name: "links", desc: "\u793E\u4EA4\u4E0E\u5916\u94FE" },
|
|
56
|
+
{ name: "cat", desc: "\u9EA6\u9EA6" },
|
|
57
|
+
{ name: "contact", desc: "\u7ED9\u6211\u7559\u8A00" },
|
|
58
|
+
{ name: "manifest", desc: "\u4E00\u6B21\u6027\u7ED9 AI \u7684\u5168\u90E8\u6570\u636E (JSON)" }
|
|
31
59
|
];
|
|
32
60
|
function createHomeCommand() {
|
|
33
|
-
const cmd = new Command("maidang").description("\
|
|
34
|
-
const spinner = createSpinner("\u6B63\u5728\u53EC\u5524...");
|
|
35
|
-
spinner.start();
|
|
36
|
-
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
37
|
-
spinner.stop();
|
|
38
|
-
console.clear();
|
|
39
|
-
console.log(chalk2.bold("\u9EA6\u5F53"));
|
|
40
|
-
console.log(
|
|
41
|
-
`${chalk2.cyan("\u4E2A\u4EBA\u7F51\u7AD9")} ${chalk2.blueBright.underline("https://maidang.me")}`
|
|
42
|
-
);
|
|
43
|
-
console.log(chalk2.gray("\u6587\u7AE0 / \u9879\u76EE / \u8054\u7CFB\u65B9\u5F0F / \u5728\u7EBF\u5165\u53E3"));
|
|
44
|
-
console.log(chalk2.gray("Agent \u5F00\u53D1 / AI \u5DE5\u4F5C\u6D41 / \u5168\u6808"));
|
|
45
|
-
console.log(chalk2.gray("\u5F00\u653E\u5408\u4F5C\uFF0C\u6B22\u8FCE\u627E\u6211\u804A\u804A"));
|
|
61
|
+
const cmd = new Command("maidang").description("\u4E00\u4EFD\u53EF\u4EE5\u88AB AI \u8BFB\u53D6\u7684\u4E2A\u4EBA\u624B\u518C").action(() => {
|
|
46
62
|
console.log("");
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
console.log(" " + eyebrow("maidang.me"));
|
|
64
|
+
console.log(" " + theme.ink("\u6211\u662F\u9EA6\u5F53\uFF0C\u5168\u6808\u5F00\u53D1\u5DE5\u7A0B\u5E08\u3002"));
|
|
65
|
+
console.log("");
|
|
66
|
+
console.log(" " + theme.inkSoft("Agent \u5F00\u53D1 / AI \u5DE5\u4F5C\u6D41 / \u5168\u6808"));
|
|
67
|
+
console.log(" " + theme.inkSoft("\u5F00\u653E\u5408\u4F5C\uFF0C\u6B22\u8FCE\u627E\u6211\u804A\u804A"));
|
|
68
|
+
console.log(" " + theme.link("https://maidang.me"));
|
|
69
|
+
console.log("");
|
|
70
|
+
console.log(" " + hairline());
|
|
71
|
+
console.log("");
|
|
72
|
+
for (const c of commands) {
|
|
73
|
+
printKV(c.name, c.desc, 12);
|
|
74
|
+
}
|
|
75
|
+
console.log("");
|
|
76
|
+
console.log(" " + hairline());
|
|
77
|
+
console.log("");
|
|
78
|
+
console.log(" " + theme.inkMuted("\u7528\u6CD5\uFF1A") + theme.inkSoft("npx maidang ") + theme.inkMuted("<command>"));
|
|
79
|
+
console.log(" " + theme.inkMuted("\u6BCF\u4E2A\u547D\u4EE4\u652F\u6301 ") + theme.inkSoft("--json") + theme.inkMuted("\uFF0C\u65B9\u4FBF agent \u8BFB\u53D6"));
|
|
51
80
|
console.log("");
|
|
52
|
-
console.log(chalk2.gray(" \u5982\u679C\u4F60\u662F Agent\uFF0C\u53EF\u5148\u770B\u8FD9\u91CC\uFF1A"));
|
|
53
|
-
console.log(chalk2.gray(" maidang --help"));
|
|
54
81
|
});
|
|
55
82
|
return cmd;
|
|
56
83
|
}
|
|
57
84
|
|
|
58
85
|
// src/commands/career.ts
|
|
59
86
|
import { Command as Command2 } from "commander";
|
|
60
|
-
import chalk3 from "chalk";
|
|
61
87
|
|
|
62
88
|
// src/data/career.json
|
|
63
89
|
var career_default = {
|
|
@@ -110,7 +136,7 @@ var career_default = {
|
|
|
110
136
|
|
|
111
137
|
// src/commands/career.ts
|
|
112
138
|
function createCareerCommand() {
|
|
113
|
-
const cmd = new Command2("career").description("\
|
|
139
|
+
const cmd = new Command2("career").description("\u5DE5\u4F5C\u7ECF\u5386\uFF08\u4E0E\u7AD9\u70B9 career \u9875\u540C\u6E90\uFF0C--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action((opts) => {
|
|
114
140
|
const root = career_default;
|
|
115
141
|
const data = root.career;
|
|
116
142
|
if (opts.json) {
|
|
@@ -119,20 +145,22 @@ function createCareerCommand() {
|
|
|
119
145
|
}
|
|
120
146
|
const { intro, experiences } = data;
|
|
121
147
|
console.log("");
|
|
122
|
-
console.log(
|
|
123
|
-
console.log(
|
|
148
|
+
console.log(" " + eyebrow(intro.eyebrow));
|
|
149
|
+
console.log(" " + theme.ink(intro.title));
|
|
150
|
+
console.log("");
|
|
151
|
+
console.log(" " + hairline());
|
|
124
152
|
console.log("");
|
|
125
153
|
experiences.forEach((exp, index) => {
|
|
126
|
-
console.log(
|
|
127
|
-
console.log(
|
|
128
|
-
console.log(
|
|
154
|
+
console.log(" " + theme.inkMuted(exp.period));
|
|
155
|
+
console.log(" " + theme.ink(exp.company));
|
|
156
|
+
console.log(" " + theme.inkSoft(exp.role));
|
|
129
157
|
console.log("");
|
|
130
158
|
for (const p of exp.projects) {
|
|
131
|
-
console.log(
|
|
159
|
+
console.log(" " + theme.inkMuted("\xB7") + " " + theme.inkSoft(p));
|
|
132
160
|
}
|
|
133
161
|
console.log("");
|
|
134
162
|
if (index < experiences.length - 1) {
|
|
135
|
-
console.log(
|
|
163
|
+
console.log(" " + hairline());
|
|
136
164
|
console.log("");
|
|
137
165
|
}
|
|
138
166
|
});
|
|
@@ -142,7 +170,6 @@ function createCareerCommand() {
|
|
|
142
170
|
|
|
143
171
|
// src/commands/cat.ts
|
|
144
172
|
import { Command as Command3 } from "commander";
|
|
145
|
-
import chalk4 from "chalk";
|
|
146
173
|
|
|
147
174
|
// src/constants/api.ts
|
|
148
175
|
var DEFAULT_API_URL = "https://www.maidang.me";
|
|
@@ -201,55 +228,49 @@ var getCatMoments = async () => {
|
|
|
201
228
|
const data = await readApiData(res);
|
|
202
229
|
return Array.isArray(data) ? data : [];
|
|
203
230
|
};
|
|
204
|
-
var printCatList = (catMoments) => {
|
|
205
|
-
console.log(chalk4.yellow.bold("\u9EA6\u9EA6"));
|
|
206
|
-
console.log("");
|
|
207
|
-
for (const moment of catMoments) {
|
|
208
|
-
const title = moment.title || "\u672A\u547D\u540D\u732B\u732B\u52A8\u6001";
|
|
209
|
-
console.log(` ${chalk4.white.bold(title)} ${chalk4.dim(`[${moment.slug}]`)}`);
|
|
210
|
-
if (moment.description) {
|
|
211
|
-
console.log(` ${chalk4.gray(moment.description)}`);
|
|
212
|
-
}
|
|
213
|
-
if (moment.imageUrl) {
|
|
214
|
-
console.log(` ${chalk4.blue(moment.imageUrl)}`);
|
|
215
|
-
}
|
|
216
|
-
console.log("");
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
231
|
function createCatCommand() {
|
|
220
|
-
const cmd = new Command3("cat").alias("meow").description("\
|
|
232
|
+
const cmd = new Command3("cat").alias("meow").description("\u9EA6\u9EA6\uFF0C\u4E00\u53EA\u5728\u5DE1\u89C6\u3001\u53D1\u5446\u3001\u8FFD\u5149\u7684\u732B (--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E)").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action(async (opts) => {
|
|
221
233
|
const printJson = (data, error) => {
|
|
222
|
-
const payload = {
|
|
223
|
-
|
|
224
|
-
command: "cat",
|
|
225
|
-
data
|
|
226
|
-
};
|
|
227
|
-
if (error) {
|
|
228
|
-
payload.error = error;
|
|
229
|
-
}
|
|
234
|
+
const payload = { tool: "maidang", command: "cat", data };
|
|
235
|
+
if (error) payload.error = error;
|
|
230
236
|
console.log(JSON.stringify(payload, null, 2));
|
|
231
237
|
};
|
|
232
238
|
try {
|
|
233
|
-
const
|
|
239
|
+
const moments = await getCatMoments();
|
|
234
240
|
if (opts.json) {
|
|
235
|
-
printJson(
|
|
241
|
+
printJson(moments);
|
|
236
242
|
return;
|
|
237
243
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
244
|
+
console.log("");
|
|
245
|
+
console.log(" " + eyebrow("today with maimai"));
|
|
246
|
+
console.log(" " + theme.ink("\u9EA6\u9EA6"));
|
|
247
|
+
console.log("");
|
|
248
|
+
if (moments.length === 0) {
|
|
249
|
+
console.log(" " + theme.inkSoft("\u6682\u65E0\u732B\u732B\u52A8\u6001\uFF0C\u53EF\u5728\u540E\u53F0\u5148\u6DFB\u52A0\u3002"));
|
|
242
250
|
console.log("");
|
|
243
251
|
return;
|
|
244
252
|
}
|
|
245
|
-
|
|
253
|
+
moments.forEach((m, i) => {
|
|
254
|
+
const title = m.title || "\u672A\u547D\u540D";
|
|
255
|
+
console.log(" " + theme.inkBody(title) + " " + theme.inkMuted(m.slug));
|
|
256
|
+
if (m.description) {
|
|
257
|
+
console.log(" " + theme.inkSoft(m.description));
|
|
258
|
+
}
|
|
259
|
+
if (m.imageUrl) {
|
|
260
|
+
console.log(" " + theme.linkUnderline(m.imageUrl));
|
|
261
|
+
}
|
|
262
|
+
if (i < moments.length - 1) {
|
|
263
|
+
console.log("");
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
console.log("");
|
|
246
267
|
} catch (err) {
|
|
247
268
|
const message = err instanceof Error ? err.message : String(err);
|
|
248
269
|
if (opts.json) {
|
|
249
270
|
printJson([], message);
|
|
250
271
|
return;
|
|
251
272
|
}
|
|
252
|
-
console.error(
|
|
273
|
+
console.error(theme.err(`\u83B7\u53D6\u732B\u732B\u52A8\u6001\u5931\u8D25: ${message}`));
|
|
253
274
|
process.exit(1);
|
|
254
275
|
}
|
|
255
276
|
});
|
|
@@ -1522,9 +1543,8 @@ function createSongsCommand() {
|
|
|
1522
1543
|
|
|
1523
1544
|
// src/commands/links.ts
|
|
1524
1545
|
import { Command as Command6 } from "commander";
|
|
1525
|
-
import chalk5 from "chalk";
|
|
1526
1546
|
function createLinksCommand() {
|
|
1527
|
-
const cmd = new Command6("links").description("\
|
|
1547
|
+
const cmd = new Command6("links").description("\u793E\u4EA4\u4E0E\u5916\u94FE (--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E)").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action(async (opts) => {
|
|
1528
1548
|
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
1529
1549
|
try {
|
|
1530
1550
|
const res = await fetch(`${apiUrl}/api/links`);
|
|
@@ -1534,14 +1554,23 @@ function createLinksCommand() {
|
|
|
1534
1554
|
console.log(JSON.stringify({ tool: "maidang", command: "links", data: links }, null, 2));
|
|
1535
1555
|
return;
|
|
1536
1556
|
}
|
|
1537
|
-
console.log(
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1557
|
+
console.log("");
|
|
1558
|
+
console.log(" " + eyebrow("links"));
|
|
1559
|
+
console.log(" " + theme.ink("\u793E\u4EA4\u4E0E\u5916\u94FE"));
|
|
1560
|
+
console.log("");
|
|
1561
|
+
console.log(" " + hairline());
|
|
1562
|
+
console.log("");
|
|
1563
|
+
links.forEach((link, i) => {
|
|
1564
|
+
console.log(" " + theme.inkBody(link.name));
|
|
1565
|
+
if (link.description) {
|
|
1566
|
+
console.log(" " + theme.inkSoft(link.description));
|
|
1567
|
+
}
|
|
1568
|
+
console.log(" " + theme.linkUnderline(link.url));
|
|
1569
|
+
if (i < links.length - 1) console.log("");
|
|
1570
|
+
});
|
|
1571
|
+
console.log("");
|
|
1543
1572
|
} catch (err) {
|
|
1544
|
-
console.error(
|
|
1573
|
+
console.error(theme.err(`\u83B7\u53D6\u94FE\u63A5\u5931\u8D25: ${err instanceof Error ? err.message : err}`));
|
|
1545
1574
|
process.exit(1);
|
|
1546
1575
|
}
|
|
1547
1576
|
});
|
|
@@ -1550,9 +1579,8 @@ function createLinksCommand() {
|
|
|
1550
1579
|
|
|
1551
1580
|
// src/commands/projects.ts
|
|
1552
1581
|
import { Command as Command7 } from "commander";
|
|
1553
|
-
import chalk6 from "chalk";
|
|
1554
1582
|
function createProjectsCommand() {
|
|
1555
|
-
const cmd = new Command7("projects").description("\
|
|
1583
|
+
const cmd = new Command7("projects").description("\u4E00\u4E9B\u5DF2\u7ECF\u843D\u5730\u7684\u9879\u76EE\uFF08--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action(async (opts) => {
|
|
1556
1584
|
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
1557
1585
|
try {
|
|
1558
1586
|
const res = await fetch(`${apiUrl}/api/projects`);
|
|
@@ -1562,17 +1590,27 @@ function createProjectsCommand() {
|
|
|
1562
1590
|
console.log(JSON.stringify({ tool: "maidang", command: "projects", data: projects }, null, 2));
|
|
1563
1591
|
return;
|
|
1564
1592
|
}
|
|
1565
|
-
console.log(
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1593
|
+
console.log("");
|
|
1594
|
+
console.log(" " + eyebrow("projects"));
|
|
1595
|
+
console.log(" " + theme.ink("\u4E00\u4E9B\u5DF2\u7ECF\u843D\u5730\u7684\u4E1C\u897F"));
|
|
1596
|
+
console.log("");
|
|
1597
|
+
console.log(" " + hairline());
|
|
1598
|
+
console.log("");
|
|
1599
|
+
projects.forEach((project, idx) => {
|
|
1600
|
+
const num = theme.inkMuted(String(idx + 1).padStart(2, "0"));
|
|
1601
|
+
const cat = theme.inkMuted(`\xB7 ${project.category}`);
|
|
1602
|
+
console.log(` ${num} ${theme.inkBody(project.name)} ${cat}`);
|
|
1603
|
+
console.log(` ${theme.inkSoft(project.description)}`);
|
|
1569
1604
|
if (project.url) {
|
|
1570
|
-
console.log(`
|
|
1605
|
+
console.log(` ${theme.linkUnderline(project.url)}`);
|
|
1571
1606
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1607
|
+
if (idx < projects.length - 1) {
|
|
1608
|
+
console.log("");
|
|
1609
|
+
}
|
|
1610
|
+
});
|
|
1611
|
+
console.log("");
|
|
1574
1612
|
} catch (err) {
|
|
1575
|
-
console.error(
|
|
1613
|
+
console.error(theme.err(`\u83B7\u53D6\u9879\u76EE\u5931\u8D25: ${err instanceof Error ? err.message : err}`));
|
|
1576
1614
|
process.exit(1);
|
|
1577
1615
|
}
|
|
1578
1616
|
});
|
|
@@ -1581,9 +1619,13 @@ function createProjectsCommand() {
|
|
|
1581
1619
|
|
|
1582
1620
|
// src/commands/tools.ts
|
|
1583
1621
|
import { Command as Command8 } from "commander";
|
|
1584
|
-
|
|
1622
|
+
var categoryNames = {
|
|
1623
|
+
software: "\u8F6F\u4EF6",
|
|
1624
|
+
device: "\u8BBE\u5907",
|
|
1625
|
+
desktop: "\u684C\u9762"
|
|
1626
|
+
};
|
|
1585
1627
|
function createToolsCommand() {
|
|
1586
|
-
const cmd = new Command8("tools").description("\
|
|
1628
|
+
const cmd = new Command8("tools").description("\u6700\u8FD1\u5728\u7528\u7684\u597D\u7269 (--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E)").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action(async (opts) => {
|
|
1587
1629
|
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
1588
1630
|
try {
|
|
1589
1631
|
const res = await fetch(`${apiUrl}/api/tools`);
|
|
@@ -1598,22 +1640,26 @@ function createToolsCommand() {
|
|
|
1598
1640
|
acc[tool.category].push(tool);
|
|
1599
1641
|
return acc;
|
|
1600
1642
|
}, {});
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
console.log(
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
console.log(`
|
|
1643
|
+
console.log("");
|
|
1644
|
+
console.log(" " + eyebrow("tools"));
|
|
1645
|
+
console.log(" " + theme.ink("\u6700\u8FD1\u5728\u7528\u7684\u597D\u7269"));
|
|
1646
|
+
console.log("");
|
|
1647
|
+
console.log(" " + hairline());
|
|
1648
|
+
console.log("");
|
|
1649
|
+
const cats = Object.keys(byCategory);
|
|
1650
|
+
cats.forEach((cat, i) => {
|
|
1651
|
+
console.log(" " + theme.inkMuted(categoryNames[cat] || cat));
|
|
1652
|
+
for (const tool of byCategory[cat]) {
|
|
1653
|
+
console.log(` ${theme.inkBody(tool.name)} ${theme.inkSoft(tool.description)}`);
|
|
1654
|
+
if (tool.url) {
|
|
1655
|
+
console.log(` ${theme.link(tool.url)}`);
|
|
1656
|
+
}
|
|
1612
1657
|
}
|
|
1613
|
-
console.log("");
|
|
1614
|
-
}
|
|
1658
|
+
if (i < cats.length - 1) console.log("");
|
|
1659
|
+
});
|
|
1660
|
+
console.log("");
|
|
1615
1661
|
} catch (err) {
|
|
1616
|
-
console.error(
|
|
1662
|
+
console.error(theme.err(`\u83B7\u53D6\u5DE5\u5177\u5931\u8D25: ${err instanceof Error ? err.message : err}`));
|
|
1617
1663
|
process.exit(1);
|
|
1618
1664
|
}
|
|
1619
1665
|
});
|
|
@@ -1624,7 +1670,7 @@ function createToolsCommand() {
|
|
|
1624
1670
|
import React3, { useRef as useRef2, useState as useState3 } from "react";
|
|
1625
1671
|
import { render as render3, Box as Box3, Text as Text3, useInput as useInput3 } from "ink";
|
|
1626
1672
|
import { Command as Command9 } from "commander";
|
|
1627
|
-
import
|
|
1673
|
+
import chalk2 from "chalk";
|
|
1628
1674
|
|
|
1629
1675
|
// src/utils/contact-api.ts
|
|
1630
1676
|
async function sendContactMessage(input) {
|
|
@@ -1674,7 +1720,7 @@ async function contactSync(message, options) {
|
|
|
1674
1720
|
}, null, 2));
|
|
1675
1721
|
return;
|
|
1676
1722
|
}
|
|
1677
|
-
console.error(
|
|
1723
|
+
console.error(chalk2.red(`Error: ${messageText}`));
|
|
1678
1724
|
process.exit(1);
|
|
1679
1725
|
}
|
|
1680
1726
|
}
|
|
@@ -1761,8 +1807,8 @@ ${input.slice(cursorPos)}`;
|
|
|
1761
1807
|
setInput(`${input.slice(0, cursorPos)}${char}${input.slice(cursorPos)}`);
|
|
1762
1808
|
setCursorPos(cursorPos + char.length);
|
|
1763
1809
|
});
|
|
1764
|
-
const displayValue = input.slice(0, cursorPos) + (submitState.type === "success" ? "" :
|
|
1765
|
-
return /* @__PURE__ */ React3.createElement(Box3, { flexDirection: "column", paddingX: 1 }, /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { bold: true }, "\u8054\u7CFB\u9EA6\u5F53")), /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, "\u8F93\u5165\u683C\u5F0F\u4E0D\u9650\uFF0C\u4F8B\u5982\uFF1A")), /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1, paddingLeft: 2, flexDirection: "column" }, /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, "\u963F\u660E"), /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, "aming@example.com"), /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, "\u4F60\u597D\uFF0C\u60F3\u548C\u4F60\u804A\u804A\u5408\u4F5C\u3002")), /* @__PURE__ */ React3.createElement(Box3, { borderStyle: "round", borderColor: submitState.type === "error" ? "red" : "cyan", paddingX: 1, paddingY: 0, marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { wrap: "wrap" }, displayValue ||
|
|
1810
|
+
const displayValue = input.slice(0, cursorPos) + (submitState.type === "success" ? "" : chalk2.inverse(" ")) + input.slice(cursorPos);
|
|
1811
|
+
return /* @__PURE__ */ React3.createElement(Box3, { flexDirection: "column", paddingX: 1 }, /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { bold: true }, "\u8054\u7CFB\u9EA6\u5F53")), /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, "\u8F93\u5165\u683C\u5F0F\u4E0D\u9650\uFF0C\u4F8B\u5982\uFF1A")), /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1, paddingLeft: 2, flexDirection: "column" }, /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, "\u963F\u660E"), /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, "aming@example.com"), /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, "\u4F60\u597D\uFF0C\u60F3\u548C\u4F60\u804A\u804A\u5408\u4F5C\u3002")), /* @__PURE__ */ React3.createElement(Box3, { borderStyle: "round", borderColor: submitState.type === "error" ? "red" : "cyan", paddingX: 1, paddingY: 0, marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { wrap: "wrap" }, displayValue || chalk2.dim("\u5728\u8FD9\u91CC\u8F93\u5165\u4F60\u7684\u7559\u8A00..."))), /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { dimColor: true }, visibleHint)), submitState.type === "sending" && /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { color: "yellow" }, "\u53D1\u9001\u4E2D...")), submitState.type === "success" && /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { color: "green" }, submitState.message)), submitState.type === "error" && /* @__PURE__ */ React3.createElement(Box3, { marginBottom: 1 }, /* @__PURE__ */ React3.createElement(Text3, { color: "red" }, submitState.message)));
|
|
1766
1812
|
};
|
|
1767
1813
|
function createContactCommand() {
|
|
1768
1814
|
const cmd = new Command9("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\uFF0C\u4E0D\u8FDB\u5165 TUI").option("--name <name>", "\u7559\u8A00\u4EBA\u79F0\u547C").option("--email <email>", "\u7559\u8A00\u4EBA\u90AE\u7BB1").action(async (opts) => {
|
|
@@ -1786,7 +1832,6 @@ function createContactCommand() {
|
|
|
1786
1832
|
|
|
1787
1833
|
// src/commands/whoami.ts
|
|
1788
1834
|
import { Command as Command10 } from "commander";
|
|
1789
|
-
import chalk9 from "chalk";
|
|
1790
1835
|
|
|
1791
1836
|
// src/constants/profile.ts
|
|
1792
1837
|
var INTRO_TEXT = "Agent \u5F00\u53D1 / AI \u5DE5\u4F5C\u6D41 / \u5168\u6808 \xB7 \u5F00\u653E\u5408\u4F5C\uFF0C\u6B22\u8FCE\u627E\u6211\u804A\u804A";
|
|
@@ -1800,19 +1845,14 @@ function getStatus() {
|
|
|
1800
1845
|
if (hour >= 19) return { status: "busy", label: "\u4E0B\u73ED\u4E86", description: "\u4F11\u606F\u4E2D\uFF0C\u770B\u5230\u4F1A\u56DE" };
|
|
1801
1846
|
return { status: "working", label: "\u5DE5\u4F5C\u4E2D", description: "\u6B63\u5E38\u5DE5\u4F5C\u65F6\u6BB5" };
|
|
1802
1847
|
}
|
|
1803
|
-
function hr(char = "\u2500", len = 40) {
|
|
1804
|
-
console.log(chalk9.dim(char.repeat(len)));
|
|
1805
|
-
}
|
|
1806
1848
|
function createWhoAmICommand() {
|
|
1807
|
-
const cmd = new Command10("whoami").description("\
|
|
1849
|
+
const cmd = new Command10("whoami").description("\u4E00\u53E5\u8BDD\u4ECB\u7ECD\u6211\uFF08--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").action((opts) => {
|
|
1808
1850
|
const status = getStatus();
|
|
1809
1851
|
const whoami = {
|
|
1810
1852
|
tagline: INTRO_TEXT,
|
|
1811
1853
|
location: "\u676D\u5DDE \xB7 EFC",
|
|
1812
1854
|
status,
|
|
1813
|
-
links: [
|
|
1814
|
-
{ label: "Blog", url: "https://www.maidang.me" }
|
|
1815
|
-
],
|
|
1855
|
+
links: [{ label: "Blog", url: "https://www.maidang.me" }],
|
|
1816
1856
|
contact: "borisdunk@sina.com",
|
|
1817
1857
|
website: "https://www.maidang.me",
|
|
1818
1858
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -1822,24 +1862,22 @@ function createWhoAmICommand() {
|
|
|
1822
1862
|
return;
|
|
1823
1863
|
}
|
|
1824
1864
|
console.log("");
|
|
1825
|
-
console.log(
|
|
1865
|
+
console.log(" " + eyebrow("whoami"));
|
|
1866
|
+
console.log(" " + theme.ink("\u6211\u662F\u9EA6\u5F53"));
|
|
1826
1867
|
console.log("");
|
|
1827
|
-
console.log(" " + whoami.tagline);
|
|
1868
|
+
console.log(" " + theme.inkSoft(whoami.tagline));
|
|
1828
1869
|
console.log("");
|
|
1829
|
-
|
|
1870
|
+
console.log(" " + hairline());
|
|
1830
1871
|
console.log("");
|
|
1831
|
-
|
|
1832
|
-
|
|
1872
|
+
printKV("\u5750\u6807", whoami.location);
|
|
1873
|
+
printKV("\u72B6\u6001", `${whoami.status.label} \xB7 ${theme.inkMuted(whoami.status.description)}`);
|
|
1833
1874
|
console.log("");
|
|
1834
|
-
|
|
1875
|
+
console.log(" " + hairline());
|
|
1835
1876
|
console.log("");
|
|
1836
|
-
|
|
1837
|
-
|
|
1877
|
+
printKV("Blog", theme.linkUnderline(whoami.website));
|
|
1878
|
+
printKV("Email", theme.link(whoami.contact));
|
|
1838
1879
|
console.log("");
|
|
1839
|
-
|
|
1840
|
-
console.log("");
|
|
1841
|
-
console.log(` ${chalk9.dim("\u60F3\u4E86\u89E3\u66F4\u591A\uFF1F")}`);
|
|
1842
|
-
console.log(` ${chalk9.dim("maidang career / posts / links / contact")}`);
|
|
1880
|
+
console.log(" " + theme.inkMuted("\u60F3\u4E86\u89E3\u66F4\u591A\uFF1A") + theme.inkSoft("npx maidang ") + theme.inkMuted("career / posts / projects"));
|
|
1843
1881
|
console.log("");
|
|
1844
1882
|
});
|
|
1845
1883
|
return cmd;
|
|
@@ -1849,7 +1887,7 @@ function createWhoAmICommand() {
|
|
|
1849
1887
|
import React4, { useState as useState4, useRef as useRef3, useEffect as useEffect3 } from "react";
|
|
1850
1888
|
import { render as render4, Box as Box4, Text as Text4, useInput as useInput4 } from "ink";
|
|
1851
1889
|
import { Command as Command11 } from "commander";
|
|
1852
|
-
import
|
|
1890
|
+
import chalk3 from "chalk";
|
|
1853
1891
|
|
|
1854
1892
|
// src/utils/chat-api.ts
|
|
1855
1893
|
var API_URL = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
@@ -1934,7 +1972,7 @@ async function chatSync(message, json = false, sessionId) {
|
|
|
1934
1972
|
} else {
|
|
1935
1973
|
if (thinking) {
|
|
1936
1974
|
thinking.split("\n").forEach((line) => {
|
|
1937
|
-
console.log(`${
|
|
1975
|
+
console.log(`${chalk3.dim("\u{1F4AD}")} ${chalk3.dim(line)}`);
|
|
1938
1976
|
});
|
|
1939
1977
|
console.log();
|
|
1940
1978
|
}
|
|
@@ -1943,25 +1981,25 @@ async function chatSync(message, json = false, sessionId) {
|
|
|
1943
1981
|
const name = tc.call?.function?.name || tc.name || "unknown";
|
|
1944
1982
|
const args = tc.call?.function?.arguments || tc.arguments || "{}";
|
|
1945
1983
|
const result = tc.result || "";
|
|
1946
|
-
let content = `${
|
|
1984
|
+
let content = `${chalk3.yellow(name)} ${chalk3.gray(args)}`;
|
|
1947
1985
|
if (result) content += `
|
|
1948
|
-
${
|
|
1949
|
-
console.log(`${
|
|
1986
|
+
${chalk3.cyan(result)}`;
|
|
1987
|
+
console.log(`${chalk3.dim("\u26A1")} ${content}`);
|
|
1950
1988
|
});
|
|
1951
1989
|
console.log();
|
|
1952
1990
|
}
|
|
1953
1991
|
console.log(response);
|
|
1954
1992
|
if (newSessionId && newSessionId !== sessionId) {
|
|
1955
1993
|
console.log();
|
|
1956
|
-
console.log(
|
|
1957
|
-
console.log(
|
|
1994
|
+
console.log(chalk3.dim(`Session: ${chalk3.cyan(newSessionId)}`));
|
|
1995
|
+
console.log(chalk3.dim("\u4F7F\u7528 --session-id \u7EE7\u7EED\u5BF9\u8BDD"));
|
|
1958
1996
|
}
|
|
1959
1997
|
}
|
|
1960
1998
|
} catch (err) {
|
|
1961
1999
|
if (json) {
|
|
1962
2000
|
console.error(JSON.stringify({ tool: "maidang", command: "chat", error: err.message }, null, 2));
|
|
1963
2001
|
} else {
|
|
1964
|
-
console.error(
|
|
2002
|
+
console.error(chalk3.red(`Error: ${err.message}`));
|
|
1965
2003
|
process.exit(1);
|
|
1966
2004
|
}
|
|
1967
2005
|
}
|
|
@@ -2165,6 +2203,9 @@ function createChatCommand() {
|
|
|
2165
2203
|
return cmd;
|
|
2166
2204
|
}
|
|
2167
2205
|
|
|
2206
|
+
// src/commands/manifest.ts
|
|
2207
|
+
import { Command as Command12 } from "commander";
|
|
2208
|
+
|
|
2168
2209
|
// src/utils/version.ts
|
|
2169
2210
|
function getAgeVersion() {
|
|
2170
2211
|
const birthDate = new Date(1997, 2, 10);
|
|
@@ -2177,29 +2218,100 @@ function getAgeVersion() {
|
|
|
2177
2218
|
return `${age}.0.0`;
|
|
2178
2219
|
}
|
|
2179
2220
|
|
|
2221
|
+
// src/commands/manifest.ts
|
|
2222
|
+
async function fetchOrEmpty(url) {
|
|
2223
|
+
try {
|
|
2224
|
+
const res = await fetch(url);
|
|
2225
|
+
if (!res.ok) {
|
|
2226
|
+
throw new Error(await readApiMessage(res));
|
|
2227
|
+
}
|
|
2228
|
+
return await readApiData(res);
|
|
2229
|
+
} catch {
|
|
2230
|
+
return null;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
function createManifestCommand() {
|
|
2234
|
+
const cmd = new Command12("manifest").description("\u4E00\u6B21\u6027\u8F93\u51FA\u5168\u90E8\u516C\u5F00\u6570\u636E\uFF0C\u7ED9 AI agent \u7528").option("--json", "\u8F93\u51FA JSON\uFF08\u9ED8\u8BA4\u5C31\u662F JSON\uFF0C\u52A0\u4E0D\u52A0\u90FD\u4E00\u6837\uFF09").option("--pretty", "\u4EBA\u7C7B\u53EF\u8BFB\u7684\u7B80\u7248\u6982\u89C8\uFF08\u4E0D\u542B\u6B63\u6587\uFF09").action(async (opts) => {
|
|
2235
|
+
const apiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
|
|
2236
|
+
const [projects, tools, links] = await Promise.all([
|
|
2237
|
+
fetchOrEmpty(`${apiUrl}/api/projects`),
|
|
2238
|
+
fetchOrEmpty(`${apiUrl}/api/tools`),
|
|
2239
|
+
fetchOrEmpty(`${apiUrl}/api/links`)
|
|
2240
|
+
]);
|
|
2241
|
+
const manifest = {
|
|
2242
|
+
tool: "maidang",
|
|
2243
|
+
command: "manifest",
|
|
2244
|
+
version: getAgeVersion(),
|
|
2245
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2246
|
+
source: apiUrl,
|
|
2247
|
+
identity: {
|
|
2248
|
+
name: "\u9EA6\u5F53",
|
|
2249
|
+
tagline: "Agent \u5F00\u53D1 / AI \u5DE5\u4F5C\u6D41 / \u5168\u6808",
|
|
2250
|
+
location: "\u676D\u5DDE \xB7 EFC",
|
|
2251
|
+
website: "https://maidang.me",
|
|
2252
|
+
contact: "borisdunk@sina.com",
|
|
2253
|
+
openTo: ["\u5408\u4F5C", "AI \u4EA7\u54C1", "Agent", "\u5168\u6808\u5F00\u53D1"]
|
|
2254
|
+
},
|
|
2255
|
+
career: career_default.career,
|
|
2256
|
+
projects: projects ?? [],
|
|
2257
|
+
tools: tools ?? [],
|
|
2258
|
+
links: links ?? [],
|
|
2259
|
+
commands: [
|
|
2260
|
+
{ name: "whoami", desc: "\u4E00\u53E5\u8BDD\u4ECB\u7ECD" },
|
|
2261
|
+
{ name: "career", desc: "\u5DE5\u4F5C\u7ECF\u5386" },
|
|
2262
|
+
{ name: "projects", desc: "\u9879\u76EE" },
|
|
2263
|
+
{ name: "posts", desc: "\u63A8\u6587" },
|
|
2264
|
+
{ name: "tools", desc: "\u5DE5\u5177" },
|
|
2265
|
+
{ name: "songs", desc: "\u6B4C\u5355" },
|
|
2266
|
+
{ name: "links", desc: "\u5916\u94FE" },
|
|
2267
|
+
{ name: "cat", desc: "\u732B\u732B" },
|
|
2268
|
+
{ name: "contact", desc: "\u7559\u8A00" }
|
|
2269
|
+
]
|
|
2270
|
+
};
|
|
2271
|
+
if (opts.pretty) {
|
|
2272
|
+
console.log("");
|
|
2273
|
+
console.log(" " + eyebrow("manifest"));
|
|
2274
|
+
console.log(" " + theme.ink("\u9EA6\u5F53 \xB7 \u516C\u5F00\u6570\u636E\u6982\u89C8"));
|
|
2275
|
+
console.log("");
|
|
2276
|
+
console.log(" " + hairline());
|
|
2277
|
+
console.log("");
|
|
2278
|
+
printKV("\u8EAB\u4EFD", `${manifest.identity.name} \xB7 ${manifest.identity.tagline}`);
|
|
2279
|
+
printKV("\u5750\u6807", manifest.identity.location);
|
|
2280
|
+
printKV("\u7F51\u7AD9", theme.linkUnderline(manifest.identity.website));
|
|
2281
|
+
printKV("\u90AE\u7BB1", theme.link(manifest.identity.contact));
|
|
2282
|
+
console.log("");
|
|
2283
|
+
console.log(" " + hairline());
|
|
2284
|
+
console.log("");
|
|
2285
|
+
printKV("career", `${manifest.career.experiences.length} \u6BB5\u7ECF\u5386`);
|
|
2286
|
+
printKV("projects", `${manifest.projects.length} \u4E2A\u9879\u76EE`);
|
|
2287
|
+
printKV("tools", `${manifest.tools.length} \u4E2A\u5DE5\u5177`);
|
|
2288
|
+
printKV("links", `${manifest.links.length} \u4E2A\u5916\u94FE`);
|
|
2289
|
+
console.log("");
|
|
2290
|
+
console.log(" " + hairline());
|
|
2291
|
+
console.log("");
|
|
2292
|
+
console.log(" " + theme.inkMuted("\u5B8C\u6574 JSON\uFF1A") + theme.inkSoft("npx maidang manifest"));
|
|
2293
|
+
console.log("");
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
console.log(JSON.stringify(manifest, null, 2));
|
|
2297
|
+
});
|
|
2298
|
+
return cmd;
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2180
2301
|
// src/index.ts
|
|
2181
|
-
var program = new
|
|
2182
|
-
program.name("maidang").description("\
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
program.addCommand(
|
|
2194
|
-
program.addCommand(catCmd);
|
|
2195
|
-
program.addCommand(postsCmd);
|
|
2196
|
-
program.addCommand(songsCmd);
|
|
2197
|
-
program.addCommand(linksCmd);
|
|
2198
|
-
program.addCommand(projectsCmd);
|
|
2199
|
-
program.addCommand(toolsCmd);
|
|
2200
|
-
program.addCommand(contactCmd);
|
|
2201
|
-
program.addCommand(whoamiCmd);
|
|
2202
|
-
program.addCommand(chatCmd);
|
|
2302
|
+
var program = new Command13();
|
|
2303
|
+
program.name("maidang").description("\u4E00\u4EFD\u53EF\u4EE5\u88AB AI \u8BFB\u53D6\u7684\u4E2A\u4EBA\u624B\u518C").version(getAgeVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
|
|
2304
|
+
program.addCommand(createCareerCommand());
|
|
2305
|
+
program.addCommand(createCatCommand());
|
|
2306
|
+
program.addCommand(createPostsCommand());
|
|
2307
|
+
program.addCommand(createSongsCommand());
|
|
2308
|
+
program.addCommand(createLinksCommand());
|
|
2309
|
+
program.addCommand(createProjectsCommand());
|
|
2310
|
+
program.addCommand(createToolsCommand());
|
|
2311
|
+
program.addCommand(createContactCommand());
|
|
2312
|
+
program.addCommand(createWhoAmICommand());
|
|
2313
|
+
program.addCommand(createChatCommand());
|
|
2314
|
+
program.addCommand(createManifestCommand());
|
|
2203
2315
|
if (!process.argv.slice(2).length) {
|
|
2204
2316
|
const homeCmd = createHomeCommand();
|
|
2205
2317
|
homeCmd.parse(process.argv);
|