maidang 29.8.1 → 29.8.2

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/README.md CHANGED
@@ -22,14 +22,28 @@ maidang posts --slug <slug> --json
22
22
  maidang songs 年度歌单
23
23
  maidang links 链接
24
24
  maidang projects 项目
25
+ maidang tools 常用工具
26
+ maidang skills 可分享的 Agent Skills
25
27
  maidang cat|meow 麦麦
26
- maidang contact 联系方式
28
+ maidang contact 给麦当留言(直发,不经过大模型)
27
29
  maidang manifest 面向 AI 的公开资料清单
28
30
  maidang chat 和我对话
31
+ maidang news AI 日报(--list 最近 10 期,--date 指定日期)
32
+ maidang changelog 站点更新日志
33
+ maidang upgrade 升级 maidang(--yes 跳过确认,--json 仅检查)
29
34
  ```
30
35
 
31
36
  所有命令支持 **--json** 输出,结构化数据,方便程序读取。
32
37
 
38
+ ## 退出码
39
+
40
+ | 码 | 含义 |
41
+ | --- | --- |
42
+ | 0 | 成功 |
43
+ | 1 | 通用失败(网络、服务端错误) |
44
+ | 2 | 用法错误(参数非法,本地校验失败) |
45
+ | 3 | 未找到(如指定日期的日报不存在) |
46
+
33
47
  ## 版本号
34
48
 
35
49
  版本号不遵循 semver,是一条时间线彩蛋:
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { Command as Command14 } from "commander";
4
+ import { Command as Command17 } from "commander";
5
5
 
6
6
  // src/commands/home.ts
7
7
  import { Command } from "commander";
@@ -2165,8 +2165,449 @@ function createManifestCommand() {
2165
2165
  return cmd;
2166
2166
  }
2167
2167
 
2168
+ // src/commands/news.ts
2169
+ import { Command as Command14 } from "commander";
2170
+ var DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
2171
+ function isValidIssueDate(value) {
2172
+ if (!DATE_PATTERN.test(value)) return false;
2173
+ const date = /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
2174
+ return !Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value;
2175
+ }
2176
+ function printIssue(issue) {
2177
+ console.log("");
2178
+ console.log(" " + eyebrow("news"));
2179
+ console.log(" " + theme.ink(`\u9EA6\u5F53 AI \u65E5\u62A5 \xB7 \u7B2C ${issue.issueNumber} \u671F \xB7 ${issue.issueDate.slice(0, 10)}`));
2180
+ console.log(" " + hairline());
2181
+ console.log("");
2182
+ if (issue.headline) {
2183
+ console.log(" " + theme.inkBody(`\u5934\u6761\uFF1A${issue.headline}`));
2184
+ console.log("");
2185
+ }
2186
+ let lastSection = "";
2187
+ issue.items.forEach((item) => {
2188
+ if (item.section !== lastSection) {
2189
+ if (lastSection) console.log("");
2190
+ console.log(" " + theme.accent(`\u25CF ${item.section}`));
2191
+ lastSection = item.section;
2192
+ }
2193
+ console.log(` ${theme.inkMuted(String(item.rank).padStart(2, "0"))} ${theme.inkBody(item.title)}`);
2194
+ if (item.summary) console.log(` ${theme.inkSoft(item.summary)}`);
2195
+ if (item.ordinaryExplanation) {
2196
+ console.log(` ${theme.inkMuted(`\u548C\u4F60\u6709\u4EC0\u4E48\u5173\u7CFB\uFF1A${item.ordinaryExplanation}`)}`);
2197
+ }
2198
+ });
2199
+ console.log("");
2200
+ const sourceCount = issue.sourceCount ?? issue.items.reduce((sum, item) => sum + (item.sources?.length ?? 0), 0);
2201
+ console.log(" " + theme.inkMuted(`\u6765\u6E90 ${sourceCount} \u6761 \xB7 \u5B8C\u6574\u7248 maidang.me \u65B0\u95FB\u5E94\u7528`));
2202
+ console.log("");
2203
+ }
2204
+ function printIssueList(issues) {
2205
+ console.log("");
2206
+ console.log(" " + eyebrow("news"));
2207
+ console.log(" " + theme.ink(`\u6700\u8FD1 ${issues.length} \u671F`));
2208
+ console.log(" " + hairline());
2209
+ console.log("");
2210
+ issues.forEach((issue, index) => {
2211
+ console.log(` ${theme.inkMuted(String(index + 1).padStart(2, "0"))} ${theme.inkBody(`${issue.issueDate.slice(0, 10)} \xB7 \u7B2C ${issue.issueNumber} \u671F`)}`);
2212
+ if (issue.headline) console.log(` ${theme.inkSoft(issue.headline)}`);
2213
+ });
2214
+ console.log("");
2215
+ }
2216
+ function createNewsCommand() {
2217
+ const baseApiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
2218
+ const cmd = new Command14("news").description("AI \u65E5\u62A5\uFF0C\u6BCF\u5929\u4E00\u671F\uFF08--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F").option("--list", "\u6700\u8FD1 10 \u671F\u76EE\u5F55").option("--date <date>", "\u6307\u5B9A\u65E5\u671F\u4E00\u671F\uFF0C\u683C\u5F0F YYYY-MM-DD");
2219
+ cmd.action(async (opts) => {
2220
+ try {
2221
+ const date = opts.date?.trim();
2222
+ if (date !== void 0 && !isValidIssueDate(date)) {
2223
+ console.error(theme.err("--date \u683C\u5F0F\u5FC5\u987B\u4E3A YYYY-MM-DD\uFF0C\u4E14\u662F\u771F\u5B9E\u5B58\u5728\u7684\u65E5\u671F"));
2224
+ process.exit(2);
2225
+ }
2226
+ let path;
2227
+ if (opts.list) {
2228
+ path = "/api/ai-news/issues";
2229
+ } else if (date) {
2230
+ path = `/api/ai-news/issues/${encodeURIComponent(date)}`;
2231
+ } else {
2232
+ path = "/api/ai-news/latest";
2233
+ }
2234
+ const response = await fetch(`${baseApiUrl}${path}`);
2235
+ if (response.status === 404) {
2236
+ 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";
2237
+ if (opts.json) {
2238
+ console.error(JSON.stringify({ tool: "maidang", command: "news", error: message }, null, 2));
2239
+ } else {
2240
+ console.error(theme.err(message));
2241
+ }
2242
+ process.exit(3);
2243
+ }
2244
+ if (!response.ok) throw new Error(await readApiMessage(response));
2245
+ if (opts.list) {
2246
+ const data2 = await readApiData(response);
2247
+ if (opts.json) {
2248
+ console.log(JSON.stringify({ tool: "maidang", command: "news", data: data2 }, null, 2));
2249
+ return;
2250
+ }
2251
+ printIssueList(data2.issues ?? []);
2252
+ return;
2253
+ }
2254
+ const data = await readApiData(response);
2255
+ if (opts.json) {
2256
+ console.log(JSON.stringify({ tool: "maidang", command: "news", date, data }, null, 2));
2257
+ return;
2258
+ }
2259
+ printIssue(data.issue);
2260
+ } catch (error) {
2261
+ console.error(theme.err(`\u83B7\u53D6 AI \u65E5\u62A5\u5931\u8D25: ${error instanceof Error ? error.message : error}`));
2262
+ process.exit(1);
2263
+ }
2264
+ });
2265
+ return cmd;
2266
+ }
2267
+
2268
+ // src/commands/changelog.ts
2269
+ import { Command as Command15 } from "commander";
2270
+ function printChangelog(entries) {
2271
+ console.log("");
2272
+ console.log(" " + eyebrow("changelog"));
2273
+ console.log(" " + theme.ink(`\u5171 ${entries.length} \u6761\u66F4\u65B0`));
2274
+ console.log(" " + hairline());
2275
+ console.log("");
2276
+ entries.forEach((entry, index) => {
2277
+ const meta = [entry.version, entry.publishedAt.slice(0, 10)].filter(Boolean).join(" \xB7 ");
2278
+ console.log(` ${theme.inkMuted(String(index + 1).padStart(2, "0"))} ${theme.inkBody(entry.title)}`);
2279
+ if (meta) console.log(` ${theme.inkMuted(meta)}`);
2280
+ if (entry.summary) console.log(` ${theme.inkSoft(entry.summary)}`);
2281
+ if (index < entries.length - 1) console.log("");
2282
+ });
2283
+ console.log("");
2284
+ }
2285
+ function createChangelogCommand() {
2286
+ const baseApiUrl = process.env.MAIDANG_API_URL || DEFAULT_API_URL;
2287
+ const cmd = new Command15("changelog").description("\u7AD9\u70B9\u66F4\u65B0\u65E5\u5FD7\uFF08--json \u8F93\u51FA\u7ED3\u6784\u5316\u6570\u636E\uFF09").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F");
2288
+ cmd.action(async (opts) => {
2289
+ try {
2290
+ const response = await fetch(`${baseApiUrl}/api/changelog`);
2291
+ if (!response.ok) throw new Error(await readApiMessage(response));
2292
+ const entries = await readApiData(response);
2293
+ if (opts.json) {
2294
+ console.log(JSON.stringify({ tool: "maidang", command: "changelog", data: { entries } }, null, 2));
2295
+ return;
2296
+ }
2297
+ printChangelog(entries ?? []);
2298
+ } catch (error) {
2299
+ console.error(theme.err(`\u83B7\u53D6\u66F4\u65B0\u65E5\u5FD7\u5931\u8D25: ${error instanceof Error ? error.message : error}`));
2300
+ process.exit(1);
2301
+ }
2302
+ });
2303
+ return cmd;
2304
+ }
2305
+
2306
+ // src/commands/upgrade.ts
2307
+ import { spawnSync } from "child_process";
2308
+ import * as readline from "readline";
2309
+ import { Command as Command16 } from "commander";
2310
+
2311
+ // src/core/version.ts
2312
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
2313
+ import { dirname, join as join2 } from "path";
2314
+ function compareVersions(a, b) {
2315
+ const parse = (value) => value.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
2316
+ const va = parse(a);
2317
+ const vb = parse(b);
2318
+ for (let i = 0; i < 3; i += 1) {
2319
+ const da = va[i] ?? 0;
2320
+ const db = vb[i] ?? 0;
2321
+ if (da !== db) return da - db;
2322
+ }
2323
+ return 0;
2324
+ }
2325
+ function getPackageVersion() {
2326
+ const candidates = [];
2327
+ try {
2328
+ const entry = process.argv[1];
2329
+ if (entry) {
2330
+ candidates.push(join2(dirname(realpathSync(entry)), "..", "package.json"));
2331
+ }
2332
+ } catch {
2333
+ }
2334
+ candidates.push(join2(process.cwd(), "package.json"));
2335
+ for (const candidate of candidates) {
2336
+ try {
2337
+ const pkg = JSON.parse(readFileSync2(candidate, "utf8"));
2338
+ if (typeof pkg.version === "string" && pkg.version) return pkg.version;
2339
+ } catch {
2340
+ }
2341
+ }
2342
+ return "0.0.0";
2343
+ }
2344
+
2345
+ // src/core/registry.ts
2346
+ var DEFAULT_REGISTRY = "https://registry.npmjs.org";
2347
+ function registryBaseUrl() {
2348
+ return process.env.MAIDANG_REGISTRY_URL?.trim() || DEFAULT_REGISTRY;
2349
+ }
2350
+ async function fetchLatestVersion(timeoutMs = 2e3) {
2351
+ const controller = new AbortController();
2352
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
2353
+ try {
2354
+ const response = await fetch(`${registryBaseUrl()}/-/package/maidang/dist-tags`, {
2355
+ signal: controller.signal,
2356
+ headers: { Accept: "application/json" }
2357
+ });
2358
+ if (!response.ok) throw new Error(`registry HTTP ${response.status}`);
2359
+ const payload = await response.json();
2360
+ if (typeof payload.latest !== "string" || !payload.latest) {
2361
+ throw new Error("registry response missing latest tag");
2362
+ }
2363
+ return payload.latest;
2364
+ } finally {
2365
+ clearTimeout(timer);
2366
+ }
2367
+ }
2368
+
2369
+ // src/commands/upgrade.ts
2370
+ var INSTALL_COMMANDS = {
2371
+ npm: ["npm", ["i", "-g", "maidang@latest"]],
2372
+ pnpm: ["pnpm", ["add", "-g", "maidang@latest"]],
2373
+ yarn: ["yarn", ["global", "add", "maidang@latest"]],
2374
+ bun: ["bun", ["add", "-g", "maidang@latest"]]
2375
+ };
2376
+ var KNOWN_PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
2377
+ function detectPackageManager() {
2378
+ const argv1 = (process.argv[1] ?? "").replace(/\\/g, "/");
2379
+ if (argv1.includes("_npx")) return { pm: "npm", npx: true };
2380
+ if (argv1.includes("pnpm")) return { pm: "pnpm", npx: false };
2381
+ if (argv1.includes("yarn")) return { pm: "yarn", npx: false };
2382
+ if (argv1.includes("bun")) return { pm: "bun", npx: false };
2383
+ return { pm: "npm", npx: false };
2384
+ }
2385
+ function buildInstallCommand(pm) {
2386
+ const [cmd, args] = INSTALL_COMMANDS[pm];
2387
+ return `${cmd} ${args.join(" ")}`;
2388
+ }
2389
+ function printJsonResult(result) {
2390
+ console.log(JSON.stringify({ tool: "maidang", command: "upgrade", data: result }, null, 2));
2391
+ }
2392
+ function confirmUpgrade() {
2393
+ return new Promise((resolve) => {
2394
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
2395
+ rl.question("\u786E\u8BA4\u5347\u7EA7\u5230 maidang@latest\uFF1F(y/N) ", (answer) => {
2396
+ rl.close();
2397
+ const normalized = answer.trim().toLowerCase();
2398
+ resolve(normalized === "y" || normalized === "yes");
2399
+ });
2400
+ });
2401
+ }
2402
+ function createUpgradeCommand() {
2403
+ const cmd = new Command16("upgrade").description("\u5347\u7EA7 maidang \u5230\u6700\u65B0\u7248\u672C").option("--json", "\u8F93\u51FA JSON \u683C\u5F0F\uFF08\u4E0D\u5E26 --yes \u65F6\u4EC5\u68C0\u67E5\uFF0C\u4E0D\u5B89\u88C5\uFF09").option("-y, --yes", "\u8DF3\u8FC7\u786E\u8BA4\uFF0C\u76F4\u63A5\u5347\u7EA7\uFF08agent \u6A21\u5F0F\uFF09").option("--pm <pm>", "\u6307\u5B9A\u5305\u7BA1\u7406\u5668\uFF08npm/pnpm/yarn/bun\uFF09");
2404
+ cmd.action(async (opts) => {
2405
+ const detected = detectPackageManager();
2406
+ let pm = detected.pm;
2407
+ if (opts.pm) {
2408
+ const requested = opts.pm.trim().toLowerCase();
2409
+ if (!KNOWN_PACKAGE_MANAGERS.includes(requested)) {
2410
+ if (opts.json) {
2411
+ console.error(JSON.stringify({
2412
+ tool: "maidang",
2413
+ command: "upgrade",
2414
+ error: `--pm \u53EA\u652F\u6301 ${KNOWN_PACKAGE_MANAGERS.join("/")}`
2415
+ }, null, 2));
2416
+ } else {
2417
+ console.error(theme.err(`--pm \u53EA\u652F\u6301 ${KNOWN_PACKAGE_MANAGERS.join("/")}`));
2418
+ }
2419
+ process.exit(2);
2420
+ }
2421
+ pm = requested;
2422
+ }
2423
+ const currentVersion = getPackageVersion();
2424
+ let latestVersion;
2425
+ try {
2426
+ latestVersion = await fetchLatestVersion();
2427
+ } catch (error) {
2428
+ const message = `\u67E5\u8BE2 registry \u5931\u8D25: ${error instanceof Error ? error.message : error}`;
2429
+ if (opts.json) {
2430
+ console.error(JSON.stringify({ tool: "maidang", command: "upgrade", error: message }, null, 2));
2431
+ } else {
2432
+ console.error(theme.err(message));
2433
+ }
2434
+ process.exit(1);
2435
+ }
2436
+ const updateAvailable = compareVersions(latestVersion, currentVersion) > 0;
2437
+ const result = {
2438
+ currentVersion,
2439
+ latestVersion,
2440
+ updateAvailable,
2441
+ packageManager: pm,
2442
+ npx: detected.npx,
2443
+ upgraded: false
2444
+ };
2445
+ if (!updateAvailable) {
2446
+ if (opts.json) {
2447
+ printJsonResult(result);
2448
+ return;
2449
+ }
2450
+ console.log("");
2451
+ console.log(" " + theme.ok(`maidang ${currentVersion} \u5DF2\u662F\u6700\u65B0\u7248\u672C`));
2452
+ console.log("");
2453
+ return;
2454
+ }
2455
+ if (detected.npx) {
2456
+ result.installCommand = "npx maidang@latest";
2457
+ if (opts.json) {
2458
+ printJsonResult(result);
2459
+ return;
2460
+ }
2461
+ console.log("");
2462
+ console.log(" " + theme.inkBody(`maidang ${currentVersion} \u2192 ${latestVersion} \u5DF2\u53D1\u5E03`));
2463
+ console.log(" " + theme.inkSoft("\u4F60\u5728\u7528 npx \u8FD0\u884C\uFF0C\u65E0\u9700\u5347\u7EA7\uFF0C\u4E0B\u6B21\u76F4\u63A5\u8DD1\uFF1A"));
2464
+ console.log(" " + theme.link("npx maidang@latest"));
2465
+ console.log("");
2466
+ return;
2467
+ }
2468
+ result.installCommand = buildInstallCommand(pm);
2469
+ if (opts.json && !opts.yes) {
2470
+ printJsonResult(result);
2471
+ return;
2472
+ }
2473
+ if (!opts.yes && !process.stdin.isTTY) {
2474
+ if (opts.json) {
2475
+ result.skippedInstall = true;
2476
+ printJsonResult(result);
2477
+ return;
2478
+ }
2479
+ console.log("");
2480
+ console.log(" " + theme.inkBody(`maidang ${currentVersion} \u2192 ${latestVersion} \u5DF2\u53D1\u5E03`));
2481
+ console.log(" " + theme.inkSoft("\u975E\u4EA4\u4E92\u73AF\u5883\u4E0D\u81EA\u52A8\u5347\u7EA7\uFF0C\u624B\u52A8\u6267\u884C\uFF1A"));
2482
+ console.log(" " + theme.link(result.installCommand));
2483
+ console.log("");
2484
+ return;
2485
+ }
2486
+ if (!opts.yes) {
2487
+ console.log("");
2488
+ console.log(" " + theme.inkBody(`maidang ${currentVersion} \u2192 ${latestVersion}`));
2489
+ const confirmed = await confirmUpgrade();
2490
+ if (!confirmed) {
2491
+ console.log(" " + theme.inkMuted("\u5DF2\u53D6\u6D88\uFF0C\u672A\u505A\u4EFB\u4F55\u53D8\u66F4"));
2492
+ console.log("");
2493
+ return;
2494
+ }
2495
+ } else if (!opts.json) {
2496
+ console.log("");
2497
+ console.log(" " + theme.inkBody(`maidang ${currentVersion} \u2192 ${latestVersion}`));
2498
+ }
2499
+ const skipInstall = process.env.MAIDANG_UPGRADE_SKIP_INSTALL === "1";
2500
+ if (skipInstall) {
2501
+ result.skippedInstall = true;
2502
+ result.upgraded = true;
2503
+ if (opts.json) {
2504
+ printJsonResult(result);
2505
+ return;
2506
+ }
2507
+ console.log(" " + theme.inkMuted("MAIDANG_UPGRADE_SKIP_INSTALL=1\uFF0C\u8DF3\u8FC7\u771F\u5B9E\u5B89\u88C5"));
2508
+ console.log("");
2509
+ return;
2510
+ }
2511
+ const [installCmd, installArgs] = INSTALL_COMMANDS[pm];
2512
+ const installResult = spawnSync(installCmd, [...installArgs], {
2513
+ stdio: "inherit",
2514
+ env: process.env
2515
+ });
2516
+ if (installResult.error || installResult.status !== 0) {
2517
+ const failureMessage = installResult.error?.message ?? `\u9000\u51FA\u7801 ${installResult.status}`;
2518
+ result.upgraded = false;
2519
+ if (opts.json) {
2520
+ console.error(JSON.stringify({
2521
+ tool: "maidang",
2522
+ command: "upgrade",
2523
+ error: `\u5347\u7EA7\u5931\u8D25: ${failureMessage}\uFF0C\u53EF\u624B\u52A8\u6267\u884C ${result.installCommand}`,
2524
+ data: result
2525
+ }, null, 2));
2526
+ } else {
2527
+ console.error(theme.err(`\u5347\u7EA7\u5931\u8D25\uFF08${failureMessage}\uFF09\uFF0C\u53EF\u624B\u52A8\u6267\u884C\uFF1A`));
2528
+ console.error(" " + theme.link(result.installCommand));
2529
+ const errorCode = installResult.error?.code;
2530
+ if (errorCode === "EACCES") {
2531
+ console.error(" " + theme.inkSoft("\u6743\u9650\u4E0D\u8DB3\u65F6\u4E0D\u5EFA\u8BAE sudo\uFF0C\u5EFA\u8BAE\u7528 nvm \u6216\u4FEE\u6539 npm prefix\uFF1A"));
2532
+ console.error(" " + theme.inkMuted("npm config set prefix ~/.npm-global"));
2533
+ }
2534
+ }
2535
+ process.exit(1);
2536
+ }
2537
+ result.upgraded = true;
2538
+ if (opts.json) {
2539
+ printJsonResult(result);
2540
+ return;
2541
+ }
2542
+ console.log("");
2543
+ console.log(" " + theme.ok(`\u5DF2\u5347\u7EA7\u5230 ${latestVersion}\uFF08\u4E0B\u6B21\u8FD0\u884C\u751F\u6548\uFF0C\u53EF\u7528 maidang -v \u9A8C\u8BC1\uFF09`));
2544
+ console.log("");
2545
+ });
2546
+ return cmd;
2547
+ }
2548
+
2549
+ // src/core/config.ts
2550
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
2551
+ import { homedir as homedir2 } from "os";
2552
+ import { join as join3 } from "path";
2553
+ function configDir() {
2554
+ const xdg = process.env.XDG_CONFIG_HOME?.trim();
2555
+ return xdg ? join3(xdg, "maidang") : join3(homedir2(), ".config", "maidang");
2556
+ }
2557
+ function updateCheckPath() {
2558
+ return join3(configDir(), "update-check.json");
2559
+ }
2560
+ function readUpdateCheckCache() {
2561
+ try {
2562
+ const parsed = JSON.parse(readFileSync3(updateCheckPath(), "utf8"));
2563
+ if (!parsed || typeof parsed !== "object") return null;
2564
+ const record = parsed;
2565
+ if (typeof record.lastChecked !== "string" || typeof record.latestVersion !== "string") {
2566
+ return null;
2567
+ }
2568
+ return { lastChecked: record.lastChecked, latestVersion: record.latestVersion };
2569
+ } catch {
2570
+ return null;
2571
+ }
2572
+ }
2573
+ function writeUpdateCheckCache(cache) {
2574
+ try {
2575
+ mkdirSync2(configDir(), { recursive: true });
2576
+ writeFileSync2(updateCheckPath(), JSON.stringify(cache, null, 2) + "\n", { mode: 384 });
2577
+ } catch {
2578
+ }
2579
+ }
2580
+
2581
+ // src/core/update-notifier.ts
2582
+ var CHECK_TTL_MS = 24 * 60 * 60 * 1e3;
2583
+ async function maybeNotifyUpdate(options) {
2584
+ try {
2585
+ if (process.env.CI) return;
2586
+ if (!process.stdout.isTTY) return;
2587
+ if (options.json) return;
2588
+ if (options.command === "upgrade") return;
2589
+ const currentVersion = getPackageVersion();
2590
+ let latestVersion = null;
2591
+ const cached = readUpdateCheckCache();
2592
+ if (cached && Date.now() - Date.parse(cached.lastChecked) < CHECK_TTL_MS) {
2593
+ latestVersion = cached.latestVersion;
2594
+ } else {
2595
+ latestVersion = await fetchLatestVersion(1500);
2596
+ writeUpdateCheckCache({
2597
+ lastChecked: (/* @__PURE__ */ new Date()).toISOString(),
2598
+ latestVersion
2599
+ });
2600
+ }
2601
+ if (latestVersion && compareVersions(latestVersion, currentVersion) > 0) {
2602
+ console.log("");
2603
+ console.log(" " + theme.inkMuted(`maidang ${currentVersion} \u2192 ${latestVersion} \u5DF2\u53D1\u5E03\uFF0C\u8FD0\u884C maidang upgrade \u5347\u7EA7`));
2604
+ }
2605
+ } catch {
2606
+ }
2607
+ }
2608
+
2168
2609
  // src/index.ts
2169
- var program = new Command14();
2610
+ var program = new Command17();
2170
2611
  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");
2171
2612
  program.addCommand(createCareerCommand());
2172
2613
  program.addCommand(createCatCommand());
@@ -2180,6 +2621,16 @@ program.addCommand(createContactCommand());
2180
2621
  program.addCommand(createWhoAmICommand());
2181
2622
  program.addCommand(createChatCommand());
2182
2623
  program.addCommand(createManifestCommand());
2624
+ program.addCommand(createNewsCommand());
2625
+ program.addCommand(createChangelogCommand());
2626
+ program.addCommand(createUpgradeCommand());
2627
+ program.hook("postAction", async (_thisCommand, actionCommand) => {
2628
+ const options = typeof actionCommand?.opts === "function" ? actionCommand.opts() : {};
2629
+ await maybeNotifyUpdate({
2630
+ json: Boolean(options.json),
2631
+ command: typeof actionCommand?.name === "function" ? actionCommand.name() : void 0
2632
+ });
2633
+ });
2183
2634
  if (!process.argv.slice(2).length) {
2184
2635
  const homeCmd = createHomeCommand();
2185
2636
  homeCmd.parse(process.argv);