@aronnaxlin/bgm-cli 1.0.0 → 1.1.0

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.
@@ -88,6 +88,14 @@ function buildUsageText(target) {
88
88
  ["bgm [--json] auth turnstile [--manual] [--listen-host <host>] [--port n] [--public-origin <url>] [--timeout-seconds <n>]", "Prefer the hosted official Bangumi Turnstile flow and fall back to the local helper when needed."],
89
89
  ["bgm auth session-login [--manual]", "Private session helper: open the official private API login page and save a pasted chiiNextSessionID."],
90
90
  ["bgm [--json] auth set-session <chiiNextSessionID|cookie_string>", "Save a private API session cookie value for p1 requests."],
91
+ ["bgm [--json] auth profile list", "List saved account profiles with masked previews and the active profile."],
92
+ ["bgm [--json] auth profile save <name> [--force]", "Snapshot the current saved credentials into a named profile and mark it active."],
93
+ ["bgm [--json] auth profile use <name> [--force]", "Sync current credentials back to the active profile, then load the named profile. --force discards unsaved credentials."],
94
+ ["bgm [--json] auth profile delete <name>", "Delete one saved profile snapshot. Active credentials are kept."],
95
+ ], [
96
+ "Profiles",
97
+ " Run one command as a saved profile without switching: `bgm --profile <name> <command> ...`.",
98
+ " The override is read-only; credential-writing commands refuse to run with it.",
91
99
  ]);
92
100
  case "config":
93
101
  return buildGroupUsage("Config", [
@@ -106,7 +114,7 @@ function buildUsageText(target) {
106
114
  case "subject":
107
115
  return buildGroupUsage("Subject", [
108
116
  ["bgm [--json] subject get <subject_id> [--verbose]", "Fetch one Bangumi subject by subject ID. Add --verbose for infobox, tags, rating distribution, and images."],
109
- ["bgm [--json] subject list --type <book|anime|music|game|real> [--sort date|rank] [--limit n]", "Browse public Bangumi subjects by type and list filters."],
117
+ ["bgm [--json] subject list --type <book|anime|music|game|real> [--sort date|rank] [--tag <tag>] [--tagsCat meta|subject] [--limit n]", "Browse public Bangumi subjects by type and list filters. --tag filters by public tags (repeatable/comma-separated). --tagsCat switches between meta (wiki tags, default) and subject (user tags)."],
110
118
  ["bgm [--json] subject search <keyword> [--type anime] [--sort match|heat|rank|score] [--tag xxx]", "Search Bangumi subjects by keyword with optional filters."],
111
119
  ["bgm [--json] subject comments <subject_id> [--type <wish|collect|doing|on_hold|dropped>] [--limit n] [--offset n]", "List subject interest comments from the private API."],
112
120
  ["bgm [--json] subject reviews <subject_id> [--limit n] [--offset n]", "List subject reviews."],
@@ -140,9 +148,15 @@ function buildUsageText(target) {
140
148
  " NSFW/R18 subjects may require a saved access token.",
141
149
  " Bangumi may return a misleading 404 when episode listing is blocked by auth or account eligibility.",
142
150
  ]);
151
+ case "book":
152
+ return buildGroupUsage("Book", [
153
+ ["bgm [--json] book get <subject_id>", "Show current reading progress (ep_status / vol_status) for a book-type subject."],
154
+ ["bgm [--json] book ep <subject_id> <chapter_number>", "Update chapter (episode) progress for a book-type subject."],
155
+ ["bgm [--json] book vol <subject_id> <volume_number>", "Update volume progress for a book-type subject."],
156
+ ]);
143
157
  case "collection":
144
158
  return buildGroupUsage("Collection", [
145
- ["bgm [--json] collection list [--user <username>] [--status <wish|collect|doing|on_hold|dropped>] [--type <book|anime|music|game|real>] [--sort <updated|name|rank|community_score|user_score|date>] [--order <asc|desc>] [--limit n] [--offset n]", "List a user's collections, with optional filters and sorting. Defaults to the current user."],
159
+ ["bgm [--json] collection list [--user <username>] [--status <wish|collect|doing|on_hold|dropped>] [--type <book|anime|music|game|real>] [--tag <tag>] [--sort <updated|name|rank|community_score|user_score|date>] [--order <asc|desc>] [--limit n] [--offset n]", "List a user's collections, with optional filters and sorting. Defaults to the current user. Use --tag (repeatable or comma-separated) to filter by personal tags."],
146
160
  ["bgm [--json] collection get <subject_id>", "Show the current user's collection detail for one subject."],
147
161
  ["bgm [--json] collection collect <subject_id>|--search <keyword> [--status <wish|collect|doing|on_hold|dropped>]", "Create or update one subject collection. Default status is wish."],
148
162
  ["bgm [--json] collection comment <subject_id>|--search <keyword> <comment>", "Update one subject collection comment."],
@@ -160,6 +174,23 @@ function buildUsageText(target) {
160
174
  ["bgm [--json] user friends [username] [--limit n] [--offset n]", "List one user's friends. Defaults to the current user."],
161
175
  ["bgm [--json] user followers [username] [--limit n] [--offset n]", "List one user's followers. Defaults to the current user."],
162
176
  ]);
177
+ case "search":
178
+ return buildGroupUsage("SearchEncore", [
179
+ ["bgm [--json] search subject <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search subjects via SearchEncore."],
180
+ ["bgm [--json] search user <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search users via SearchEncore."],
181
+ ["bgm [--json] search group <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search groups via SearchEncore."],
182
+ ["bgm [--json] search topic <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search group topics via SearchEncore."],
183
+ ["bgm [--json] search subject-topic <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search subject topics via SearchEncore."],
184
+ ["bgm [--json] search reply <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search replies via SearchEncore."],
185
+ ["bgm [--json] search index <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search indexes via SearchEncore."],
186
+ ["bgm [--json] search blog <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search blogs via SearchEncore."],
187
+ ], [
188
+ "⚠️ SearchEncore",
189
+ " All search commands in this group use the SearchEncore service",
190
+ " (bgmdb.ry.mk). Data is crawled/aggregated, NOT from bangumi.tv",
191
+ " official sources. Every response is tagged with",
192
+ " _meta.isSearchEncore = true for downstream identification.",
193
+ ]);
163
194
  case "notify":
164
195
  return buildGroupUsage("Notify", [
165
196
  ["bgm [--json] notify [list] [--limit n] [--unread true|false]", "List notifications from the private API."],
@@ -259,6 +290,36 @@ function buildUsageText(target) {
259
290
  ["bgm [--json] person edit-comment <comment_id> <content>", "Edit one of your person comments."],
260
291
  ["bgm [--json] person delete-comment <comment_id>", "Delete one of your person comments."],
261
292
  ]);
293
+ case "url":
294
+ return buildGroupUsage("URL", [
295
+ ["bgm [--json] <bangumi_url> [--dry-run]", "Resolve a pasted Bangumi link and run the matching command."],
296
+ ["bgm [--json] url <bangumi_url> [--dry-run]", "Same, as an explicit subcommand."],
297
+ ["bgm [--json] --url <bangumi_url> [--dry-run]", "Same, as a global flag. `-url` is accepted as an alias."],
298
+ ], [
299
+ "Supported hosts",
300
+ " bgm.tv, bangumi.tv, chii.in, next.bgm.tv, api.bgm.tv (optional www. prefix,",
301
+ " optional https:// prefix).",
302
+ "",
303
+ "Supported links",
304
+ " /subject/<id>[/comments|reviews|board|characters|persons|collections|index|ep]",
305
+ " /subject/topic/<id>[#post_<id>] /group/topic/<id>[#post_<id>]",
306
+ " /group/<name>[/forum|members] /group/category/all",
307
+ " /ep/<id> /blog/<id>[/photos]",
308
+ " /character/<id>[/collections|indices|album]",
309
+ " /person/<id>[/collections|indices|album|works|collabs]",
310
+ " /index/<id>[/comments] /user/<name>[/timeline|blog|index|friends|followers|groups]",
311
+ " /user/<name>/mono/<character|person> /<anime|book|music|game|real>/list/<name>[/<status>]",
312
+ " /<anime|book|music|game|real>/browser|tag/<tag>",
313
+ " /subject_search/<keyword> /mono_search/<keyword>",
314
+ " /calendar /timeline /notify /v0/... on api.bgm.tv",
315
+ "",
316
+ "Notes",
317
+ " Resolution is read-only and offline; a link never triggers a write.",
318
+ " A #post_<id> anchor resolves to that single reply, not the whole topic.",
319
+ " ?page=n becomes --offset (with --limit 20 pinned); unknown query keys are ignored.",
320
+ " Extra flags are forwarded to the resolved command.",
321
+ " Quote URLs containing '#' so the shell does not truncate them.",
322
+ ]);
262
323
  case "trending":
263
324
  return buildGroupUsage("Trending", [
264
325
  ["bgm [--json] trending subjects --type <book|anime|music|game|real> [--limit n] [--offset n]", "List trending subjects."],
@@ -274,6 +335,7 @@ function buildMainUsage() {
274
335
 
275
336
  Usage
276
337
  bgm <command> [subcommand] [options]
338
+ bgm --profile <name> <command> [subcommand] [options]
277
339
  bgm <command> --help
278
340
 
279
341
  Core
@@ -295,6 +357,13 @@ Core
295
357
  Update one subject collection status.
296
358
  bgm [--json] episode watch <subject_id> <episode_number>
297
359
  Mark one main episode as watched.
360
+ bgm [--json] book get <subject_id>
361
+ Show reading progress for a book-type subject.
362
+ bgm [--json] book ep <subject_id> <chapter_number>
363
+ Update chapter progress for a book-type subject.
364
+ bgm [--json] <bangumi_url> [--dry-run]
365
+ Resolve a pasted Bangumi link (bgm.tv/bangumi.tv/chii.in/next.bgm.tv/api.bgm.tv)
366
+ and run the matching command. See: bgm url --help
298
367
  bgm [--json] group list [--limit n]
299
368
  List Bangumi groups.
300
369
  bgm [--json] status
@@ -306,9 +375,10 @@ Commands
306
375
  setup Init and install-path helpers
307
376
  user User profile reads
308
377
  notify Private API notifications
309
- subject Subject reads and search
378
+ subject Subject reads and search (official API)
310
379
  collection Subject collection reads and writes
311
380
  episode Episode list and progress writes
381
+ book Book progress reads and writes
312
382
  group Group reads and writes
313
383
  blog Blog reads and comment writes
314
384
  index Index reads and writes
@@ -316,16 +386,23 @@ Commands
316
386
  person Person reads and search
317
387
  timeline Timeline reads and writes
318
388
  trending Trending subject and topic reads
319
- status Community status service reads
320
389
  calendar Weekly anime broadcast calendar
321
390
  tui Interactive terminal UI
391
+ search SearchEncore search (non-official)
392
+ status Community status service reads (non-official)
322
393
 
323
394
  Examples
324
395
  bgm subject search "Ghost in the Shell" --type anime --limit 5
396
+ bgm search subject "海贼王" --limit 5
325
397
  bgm collection status 12 doing
326
398
  bgm episode watch 12 1
399
+ bgm book get 3510
400
+ bgm book ep 3510 10
327
401
  bgm group list --limit 10
328
402
  bgm notify --limit 10
403
+ bgm "https://bangumi.tv/group/topic/469977#post_4029724"
404
+ bgm url https://bgm.tv/subject/253/characters
405
+ bgm --url https://bgm.tv/anime/list/sai/collect --dry-run
329
406
  bgm blog --help
330
407
  bgm episode --help`;
331
408
  }
@@ -360,13 +437,39 @@ function normalizeUsageTarget(target) {
360
437
 
361
438
  export function printResult(value, context = {}) {
362
439
  if (context.json) {
363
- console.log(JSON.stringify(value, null, 2));
440
+ console.log(JSON.stringify(withResolvedFrom(value, context), null, 2));
364
441
  return;
365
442
  }
366
443
 
367
444
  console.log(formatDisplayResult(value, context));
368
445
  }
369
446
 
447
+ /**
448
+ * Tag a JSON payload with the URL it was resolved from, so `bgm <url> --json`
449
+ * stays byte-compatible with the underlying command plus one extra key.
450
+ */
451
+ function withResolvedFrom(value, context) {
452
+ if (!context.resolvedFrom || value === null || typeof value !== "object" || Array.isArray(value)) {
453
+ return value;
454
+ }
455
+
456
+ return { ...value, resolvedFrom: context.resolvedFrom };
457
+ }
458
+
459
+ function isUrlResolvePayload(value) {
460
+ return value?.resource === "url-resolve" && typeof value.commandLine === "string";
461
+ }
462
+
463
+ function formatUrlResolve(payload) {
464
+ return [
465
+ "URL resolve (dry run)",
466
+ ` URL: ${payload.url}`,
467
+ ` Site: ${payload.site}`,
468
+ ` Path: ${payload.path}`,
469
+ ` Command: ${payload.commandLine}`,
470
+ ].join("\n");
471
+ }
472
+
370
473
  export function formatDisplayResult(value, context = {}) {
371
474
  if (value === null || value === undefined) {
372
475
  return String(value);
@@ -376,6 +479,10 @@ export function formatDisplayResult(value, context = {}) {
376
479
  return value;
377
480
  }
378
481
 
482
+ if (isUrlResolvePayload(value)) {
483
+ return formatUrlResolve(value);
484
+ }
485
+
379
486
  if (isConfigShowPayload(value)) {
380
487
  return formatConfigShow(value);
381
488
  }
@@ -436,6 +543,14 @@ export function formatDisplayResult(value, context = {}) {
436
543
  return formatAuthClear(value);
437
544
  }
438
545
 
546
+ if (isAuthProfileListPayload(value)) {
547
+ return formatAuthProfileList(value);
548
+ }
549
+
550
+ if (isAuthProfileMutationPayload(value)) {
551
+ return formatAuthProfileMutation(value);
552
+ }
553
+
439
554
  if (isBlogListPayload(value)) {
440
555
  return formatBlogList(value);
441
556
  }
@@ -624,6 +739,10 @@ export function formatDisplayResult(value, context = {}) {
624
739
  return formatMonoDetail(value);
625
740
  }
626
741
 
742
+ if (isCommunitySearchPayload(value)) {
743
+ return formatCommunitySearch(value);
744
+ }
745
+
627
746
  if (isGenericP1ListPayload(value)) {
628
747
  return formatGenericP1List(value);
629
748
  }
@@ -632,6 +751,10 @@ export function formatDisplayResult(value, context = {}) {
632
751
  return formatPagedSubjects(value);
633
752
  }
634
753
 
754
+ if (isEpisodeDetailPayload(value)) {
755
+ return formatEpisodeDetail(value, context);
756
+ }
757
+
635
758
  if (isSubjectPayload(value)) {
636
759
  return formatSubject(value, context);
637
760
  }
@@ -754,6 +877,11 @@ function formatAuthStatus(payload) {
754
877
  return [
755
878
  "Auth status",
756
879
  ` Config file: ${payload.configFile ?? "-"}`,
880
+ payload.activeProfile ? ` Active profile: ${payload.activeProfile}` : null,
881
+ payload.profileOverride ? ` Profile override (--profile): ${payload.profileOverride}` : null,
882
+ Array.isArray(payload.envOverrides) && payload.envOverrides.length > 0
883
+ ? ` Warning: environment variables override saved credentials: ${payload.envOverrides.join(", ")}`
884
+ : null,
757
885
  payload.policy ? ` Policy: ${payload.policy}` : null,
758
886
  "",
759
887
  "Access Token channel",
@@ -856,6 +984,68 @@ function formatAuthClear(payload) {
856
984
  ].join("\n");
857
985
  }
858
986
 
987
+ function formatAuthProfileList(payload) {
988
+ const lines = [
989
+ "Auth profiles",
990
+ ` Config file: ${payload.configFile ?? "-"}`,
991
+ ` Active profile: ${payload.activeProfile ?? "-"}`,
992
+ ];
993
+
994
+ if (payload.profileOverride) {
995
+ lines.push(` Profile override (--profile): ${payload.profileOverride}`);
996
+ }
997
+ if (payload.activeProfileMissing) {
998
+ lines.push(" Note: the active profile points to a missing snapshot.");
999
+ }
1000
+
1001
+ if (payload.profiles.length === 0) {
1002
+ lines.push(" Profiles: none. Run `bgm auth profile save <name>` to snapshot the current credentials.");
1003
+ } else {
1004
+ lines.push(" Profiles:");
1005
+ for (const profile of payload.profiles) {
1006
+ lines.push(` ${profile.name}${profile.active ? " (active)" : ""}`);
1007
+ lines.push(` Access token: ${profile.accessTokenSaved ? profile.accessTokenPreview : "-"}`);
1008
+ lines.push(` Private session: ${profile.privateSessionSaved ? profile.privateSessionPreview : "-"}`);
1009
+ if (profile.privateSessionUpdatedAt) {
1010
+ lines.push(` Session updated at: ${formatTimestamp(profile.privateSessionUpdatedAt)}`);
1011
+ }
1012
+ }
1013
+ }
1014
+
1015
+ appendEnvOverrideWarning(lines, payload.envOverrides);
1016
+ return lines.join("\n");
1017
+ }
1018
+
1019
+ function formatAuthProfileMutation(payload) {
1020
+ const titles = {
1021
+ save: "Auth profile saved",
1022
+ use: "Auth profile switched",
1023
+ delete: "Auth profile deleted",
1024
+ };
1025
+ const lines = [
1026
+ titles[payload.action] ?? "Auth profile updated",
1027
+ ` Profile: ${payload.profile}`,
1028
+ ` Active profile: ${payload.activeProfile ?? "-"}`,
1029
+ ` Config file: ${payload.configFile ?? "-"}`,
1030
+ ];
1031
+
1032
+ if (payload.action === "use" && payload.previousProfile && payload.previousProfile !== payload.profile) {
1033
+ lines.push(` Previous profile: ${payload.previousProfile}${payload.syncedPrevious ? " (snapshot updated)" : ""}`);
1034
+ }
1035
+ if (payload.credentialsRetained) {
1036
+ lines.push(" Active credentials are kept; run `bgm auth clear` to remove them.");
1037
+ }
1038
+
1039
+ appendEnvOverrideWarning(lines, payload.envOverrides);
1040
+ return lines.join("\n");
1041
+ }
1042
+
1043
+ function appendEnvOverrideWarning(lines, envOverrides) {
1044
+ if (Array.isArray(envOverrides) && envOverrides.length > 0) {
1045
+ lines.push(` Warning: environment variables override saved credentials: ${envOverrides.join(", ")}`);
1046
+ }
1047
+ }
1048
+
859
1049
  function formatStatusIncidents(payload) {
860
1050
  const lines = [
861
1051
  "Bangumi status incidents",
@@ -1072,6 +1262,10 @@ function formatCollectionList(payload) {
1072
1262
  lines.push(" Type filter: All");
1073
1263
  }
1074
1264
 
1265
+ if (Array.isArray(filters.tag) && filters.tag.length > 0) {
1266
+ lines.push(` Tag filter: ${filters.tag.join(", ")}`);
1267
+ }
1268
+
1075
1269
  if (items.length === 0) {
1076
1270
  lines.push("");
1077
1271
  lines.push("No matching collections.");
@@ -2839,6 +3033,22 @@ function formatCalendar(payload) {
2839
3033
  return lines.join("\n").trim();
2840
3034
  }
2841
3035
 
3036
+ /**
3037
+ * The public API returns `platform` as a string, the private API as an object.
3038
+ */
3039
+ function formatSubjectPlatform(platform) {
3040
+ if (platform === null || platform === undefined) {
3041
+ return "";
3042
+ }
3043
+ if (typeof platform === "string" || typeof platform === "number") {
3044
+ return String(platform);
3045
+ }
3046
+ if (!isObject(platform)) {
3047
+ return "";
3048
+ }
3049
+ return String(platform.typeCN || platform.type || platform.alias || "");
3050
+ }
3051
+
2842
3052
  function formatSubject(subject, context = {}) {
2843
3053
  const verbose = Boolean(context?.verbose);
2844
3054
  const lines = [
@@ -2855,8 +3065,9 @@ function formatSubject(subject, context = {}) {
2855
3065
  if (subject.date) {
2856
3066
  lines.push(` Date: ${subject.date}`);
2857
3067
  }
2858
- if (subject.platform) {
2859
- lines.push(` Platform: ${subject.platform}`);
3068
+ const platform = formatSubjectPlatform(subject.platform);
3069
+ if (platform) {
3070
+ lines.push(` Platform: ${platform}`);
2860
3071
  }
2861
3072
  if (subject.eps || subject.total_episodes) {
2862
3073
  lines.push(` Episodes: ${subject.total_episodes ?? subject.eps ?? "-"}`);
@@ -2945,6 +3156,55 @@ function formatSubject(subject, context = {}) {
2945
3156
  return lines.join("\n");
2946
3157
  }
2947
3158
 
3159
+ function formatEpisodeDetail(episode, context = {}) {
3160
+ const verbose = Boolean(context?.verbose);
3161
+ const subjectId = episode.subject_id ?? episode.subjectID;
3162
+ const chineseName = episode.name_cn || episode.nameCN;
3163
+ const lines = [
3164
+ `Episode #${episode.id ?? "-"}`,
3165
+ ` Name: ${episode.name || chineseName || "-"}`,
3166
+ ];
3167
+
3168
+ if (chineseName && chineseName !== episode.name) {
3169
+ lines.push(` Chinese name: ${chineseName}`);
3170
+ }
3171
+
3172
+ lines.push(` Type: ${formatEpisodeType(episode.type)}`);
3173
+
3174
+ const number = formatEpisodeNumber(episode);
3175
+ if (number) {
3176
+ lines.push(` Number: ${number}`);
3177
+ }
3178
+ if (subjectId) {
3179
+ const subject = episode.subject;
3180
+ const subjectName = subject?.name_cn || subject?.nameCN || subject?.name;
3181
+ lines.push(` Subject: #${subjectId}${subjectName ? ` ${subjectName}` : ""}`);
3182
+ }
3183
+ if (episode.airdate) {
3184
+ lines.push(` Air date: ${episode.airdate}`);
3185
+ }
3186
+ if (episode.duration) {
3187
+ lines.push(` Duration: ${episode.duration}`);
3188
+ }
3189
+ if (episode.disc) {
3190
+ lines.push(` Disc: ${episode.disc}`);
3191
+ }
3192
+ if (episode.comment !== undefined) {
3193
+ lines.push(` Comments: ${episode.comment}`);
3194
+ }
3195
+ if (episode.id) {
3196
+ lines.push(` URL: https://bgm.tv/ep/${episode.id}`);
3197
+ }
3198
+
3199
+ if (episode.desc) {
3200
+ lines.push("");
3201
+ lines.push("Summary");
3202
+ lines.push(indentBlock(truncateText(String(episode.desc).trim(), verbose ? 800 : 400), 2));
3203
+ }
3204
+
3205
+ return lines.join("\n");
3206
+ }
3207
+
2948
3208
  function formatPagedSubjects(payload) {
2949
3209
  const lines = [
2950
3210
  "Subjects",
@@ -2979,6 +3239,9 @@ function formatPagedSubjects(payload) {
2979
3239
  if (Array.isArray(filters.tag) && filters.tag.length > 0) {
2980
3240
  lines.push(` Tag: ${filters.tag.join(", ")}`);
2981
3241
  }
3242
+ if (filters.tagsCat) {
3243
+ lines.push(` Tags category: ${filters.tagsCat}`);
3244
+ }
2982
3245
  if (Array.isArray(filters.metaTags) && filters.metaTags.length > 0) {
2983
3246
  lines.push(` Meta tags: ${filters.metaTags.join(", ")}`);
2984
3247
  }
@@ -3571,6 +3834,14 @@ function isAuthClearPayload(value) {
3571
3834
  return isObject(value) && value.resource === "auth-clear" && Array.isArray(value.cleared);
3572
3835
  }
3573
3836
 
3837
+ function isAuthProfileListPayload(value) {
3838
+ return isObject(value) && value.resource === "auth-profile-list" && Array.isArray(value.profiles);
3839
+ }
3840
+
3841
+ function isAuthProfileMutationPayload(value) {
3842
+ return isObject(value) && value.resource === "auth-profile-mutation" && typeof value.action === "string";
3843
+ }
3844
+
3574
3845
  function isStatusIncidentsPayload(value) {
3575
3846
  return isObject(value) && value.resource === "status-incidents" && Array.isArray(value.data);
3576
3847
  }
@@ -3782,6 +4053,18 @@ function isPagedSubjectPayload(value) {
3782
4053
  return isObject(value) && Array.isArray(value.data) && ("total" in value || "limit" in value || "filters" in value);
3783
4054
  }
3784
4055
 
4056
+ /**
4057
+ * One episode as returned by `episode get`. It carries id/name/type just like a
4058
+ * subject, so this has to be checked before isSubjectPayload.
4059
+ */
4060
+ function isEpisodeDetailPayload(value) {
4061
+ return isObject(value)
4062
+ && value.resource === undefined
4063
+ && "id" in value
4064
+ && ("subject_id" in value || "subjectID" in value)
4065
+ && ("sort" in value || "ep" in value);
4066
+ }
4067
+
3785
4068
  function isSubjectPayload(value) {
3786
4069
  return isObject(value) && "id" in value && "name" in value && "type" in value;
3787
4070
  }
@@ -3790,6 +4073,172 @@ function isCalendarPayload(value) {
3790
4073
  return isObject(value) && value.resource === "calendar" && Array.isArray(value.data);
3791
4074
  }
3792
4075
 
4076
+ function isCommunitySearchPayload(value) {
4077
+ return isObject(value) && typeof value.resource === "string" && value.resource.startsWith("community-") && Array.isArray(value.data);
4078
+ }
4079
+
4080
+ function formatCommunitySearch(payload) {
4081
+ const resource = payload.resource;
4082
+ const items = Array.isArray(payload.data) ? payload.data : [];
4083
+ const title = payload.title ?? resource;
4084
+ const displayTitle = title.startsWith("SearchEncore:") ? title : `SearchEncore: ${title}`;
4085
+ const lines = [
4086
+ displayTitle,
4087
+ ` Source: ${payload._meta?.source ?? "bgmdb.ry.mk"}`,
4088
+ ` ⚠️ SearchEncore data`,
4089
+ ` Range: ${formatPageRange(payload.offset ?? payload.filters?.offset, items.length, payload.total)}`,
4090
+ ];
4091
+
4092
+ if (payload.filters?.keyword) {
4093
+ lines.push(` Keyword: ${payload.filters.keyword}`);
4094
+ }
4095
+ if (payload.filters?.sort) {
4096
+ lines.push(` Sort: ${payload.filters.sort}`);
4097
+ }
4098
+
4099
+ if (items.length === 0) {
4100
+ lines.push("No results.");
4101
+ return lines.join("\n");
4102
+ }
4103
+
4104
+ switch (resource) {
4105
+ case "community-subjects": {
4106
+ const rows = items.map((item) => ({
4107
+ id: item.id ?? "-",
4108
+ name: formatNamePair(item),
4109
+ type: formatSubjectType(item.type),
4110
+ score: item.rating?.score !== undefined ? String(item.rating.score) : "",
4111
+ rank: item.rating?.rank ? `#${item.rating.rank}` : "",
4112
+ }));
4113
+ lines.push("");
4114
+ lines.push(formatTable(rows, [
4115
+ { key: "id", header: "#", minWidth: 5, align: "right" },
4116
+ { key: "name", header: "Name", minWidth: 14, maxWidth: 34, align: "left" },
4117
+ { key: "type", header: "Type", minWidth: 5, align: "left" },
4118
+ { key: "score", header: "Score", minWidth: 5, align: "right" },
4119
+ { key: "rank", header: "Rank", minWidth: 6, align: "right" },
4120
+ ]));
4121
+ break;
4122
+ }
4123
+ case "community-users": {
4124
+ const rows = items.map((item) => ({
4125
+ id: item.id ?? "-",
4126
+ username: item.username ?? "-",
4127
+ nickname: item.nickname ?? "-",
4128
+ group: String(item.group ?? ""),
4129
+ sign: item.sign ?? "",
4130
+ }));
4131
+ lines.push("");
4132
+ lines.push(formatTable(rows, [
4133
+ { key: "id", header: "#", minWidth: 6, align: "right" },
4134
+ { key: "username", header: "Username", minWidth: 10, maxWidth: 18, align: "left" },
4135
+ { key: "nickname", header: "Nickname", minWidth: 10, maxWidth: 18, align: "left" },
4136
+ { key: "group", header: "Group", minWidth: 5, align: "right" },
4137
+ { key: "sign", header: "Sign", minWidth: 8, maxWidth: 30, align: "left" },
4138
+ ]));
4139
+ break;
4140
+ }
4141
+ case "community-groups": {
4142
+ const rows = items.map((item) => ({
4143
+ id: item.id ?? "-",
4144
+ title: item.title ?? "-",
4145
+ slug: item.name ?? "-",
4146
+ members: String(item.members ?? 0),
4147
+ topics: String(item.topics ?? 0),
4148
+ nsfw: item.nsfw ? "yes" : "",
4149
+ }));
4150
+ lines.push("");
4151
+ lines.push(formatTable(rows, [
4152
+ { key: "id", header: "#", minWidth: 5, align: "right" },
4153
+ { key: "title", header: "Title", minWidth: 8, maxWidth: 24, align: "left" },
4154
+ { key: "slug", header: "Slug", minWidth: 8, maxWidth: 16, align: "left" },
4155
+ { key: "members", header: "Members", minWidth: 7, align: "right" },
4156
+ { key: "topics", header: "Topics", minWidth: 6, align: "right" },
4157
+ { key: "nsfw", header: "NSFW", minWidth: 4, align: "left" },
4158
+ ]));
4159
+ break;
4160
+ }
4161
+ case "community-group-topics":
4162
+ case "community-subject-topics": {
4163
+ const rows = items.map((item) => ({
4164
+ id: item.id ?? "-",
4165
+ title: item.title ?? "-",
4166
+ scope: item.subject ? formatNamePair(item.subject) : (item.group?.title ?? ""),
4167
+ user: formatUserLabel(item.creator),
4168
+ replies: String(item.replyCount ?? 0),
4169
+ updated: item.updatedAt ? formatTimestamp(item.updatedAt).split(" ")[0] : "",
4170
+ }));
4171
+ lines.push("");
4172
+ lines.push(formatTable(rows, [
4173
+ { key: "id", header: "#", minWidth: 7, align: "right" },
4174
+ { key: "title", header: "Topic", minWidth: 16, maxWidth: 36, align: "left" },
4175
+ { key: "scope", header: resource === "community-group-topics" ? "Group" : "Subject", minWidth: 12, maxWidth: 28, align: "left" },
4176
+ { key: "user", header: "User", minWidth: 10, maxWidth: 16, align: "left" },
4177
+ { key: "replies", header: "Replies", minWidth: 7, align: "right" },
4178
+ { key: "updated", header: "Updated", minWidth: 10, align: "left" },
4179
+ ]));
4180
+ break;
4181
+ }
4182
+ case "community-replies": {
4183
+ for (const item of items) {
4184
+ lines.push("");
4185
+ lines.push(`• #${item.id ?? "-"} by ${formatUserLabel(item.creator)}`);
4186
+ if (item.content) {
4187
+ lines.push(` ${truncateText(item.content.trim(), 240)}`);
4188
+ }
4189
+ if (item.topic?.title) {
4190
+ lines.push(` Topic: ${item.topic.title}`);
4191
+ }
4192
+ }
4193
+ break;
4194
+ }
4195
+ case "community-indexes": {
4196
+ const rows = items.map((item) => ({
4197
+ id: item.id ?? "-",
4198
+ title: item.title ?? "-",
4199
+ total: String(item.total ?? 0),
4200
+ collects: String(item.collects ?? 0),
4201
+ replies: String(item.replies ?? 0),
4202
+ user: formatUserLabel(item.user),
4203
+ }));
4204
+ lines.push("");
4205
+ lines.push(formatTable(rows, [
4206
+ { key: "id", header: "#", minWidth: 6, align: "right" },
4207
+ { key: "title", header: "Index", minWidth: 16, maxWidth: 42, align: "left" },
4208
+ { key: "total", header: "Items", minWidth: 5, align: "right" },
4209
+ { key: "collects", header: "Collects", minWidth: 7, align: "right" },
4210
+ { key: "replies", header: "Replies", minWidth: 7, align: "right" },
4211
+ { key: "user", header: "User", minWidth: 10, maxWidth: 16, align: "left" },
4212
+ ]));
4213
+ break;
4214
+ }
4215
+ case "community-blogs": {
4216
+ const rows = items.map((item) => ({
4217
+ id: item.id ?? "-",
4218
+ title: item.title ?? "-",
4219
+ user: formatUserLabel(item.user),
4220
+ replies: String(item.replies ?? 0),
4221
+ updated: item.updatedAt ? formatTimestamp(item.updatedAt).split(" ")[0] : "",
4222
+ }));
4223
+ lines.push("");
4224
+ lines.push(formatTable(rows, [
4225
+ { key: "id", header: "#", minWidth: 5, align: "right" },
4226
+ { key: "title", header: "Title", minWidth: 8, maxWidth: 32, align: "left" },
4227
+ { key: "user", header: "User", minWidth: 10, maxWidth: 18, align: "left" },
4228
+ { key: "replies", header: "Replies", minWidth: 7, align: "right" },
4229
+ { key: "updated", header: "Updated", minWidth: 10, align: "left" },
4230
+ ]));
4231
+ break;
4232
+ }
4233
+ default: {
4234
+ lines.push("");
4235
+ lines.push(JSON.stringify(items, null, 2));
4236
+ }
4237
+ }
4238
+
4239
+ return lines.join("\n");
4240
+ }
4241
+
3793
4242
  function isObject(value) {
3794
4243
  return typeof value === "object" && value !== null;
3795
4244
  }