@aronnaxlin/bgm-cli 1.1.0 → 1.1.3

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.en.md CHANGED
@@ -52,19 +52,6 @@ bgm auth set-token YOUR_ACCESS_TOKEN
52
52
  bgm auth token-status
53
53
  ```
54
54
 
55
- ### Multiple accounts
56
-
57
- Snapshot the current credentials as a named profile and switch between accounts quickly:
58
-
59
- ```bash
60
- bgm auth profile save main
61
- bgm auth profile list
62
- bgm auth profile use another
63
- bgm --profile another user me
64
- ```
65
-
66
- `bgm --profile <name> <command>` runs a single command as that account without switching; it is a read-only override and never writes to disk.
67
-
68
55
  ### Proxy
69
56
 
70
57
  If your network needs a proxy to reach the Bangumi API reliably, configure an HTTP/HTTPS proxy for all CLI requests:
@@ -103,24 +90,6 @@ bgm trending subjects --type anime --limit 5
103
90
  bgm --json user me
104
91
  ```
105
92
 
106
- ### Paste A Link
107
-
108
- Hand a Bangumi web link straight to `bgm` and it resolves to the matching command:
109
-
110
- ```bash
111
- bgm "https://bangumi.tv/group/topic/469977#post_4029724" # that single reply -> bgm group post 4029724
112
- bgm url https://bgm.tv/subject/253/characters # -> bgm subject characters 253
113
- bgm --url https://bgm.tv/anime/list/sai/collect --dry-run # resolve only, no request
114
- ```
115
-
116
- - Three equivalent forms: `bgm <url>`, `bgm url <url>`, `bgm --url <url>` (`-url` also works).
117
- - Hosts: `bgm.tv`, `bangumi.tv`, `chii.in`, `next.bgm.tv`, `api.bgm.tv`; the `https://` and `www.` prefixes are optional.
118
- - Resolution is read-only, so a link never triggers a write. `--dry-run` prints the resolution and stops.
119
- - A `#post_<id>` anchor resolves to that single reply; `?page=n` becomes `--offset`.
120
- - Extra flags are forwarded to the resolved command, and `--json` output carries a `resolvedFrom` field.
121
- - Quote links containing `#` so the shell does not truncate them.
122
- - Run `bgm url --help` for the full list of supported link shapes.
123
-
124
93
  ## Documentation Index
125
94
 
126
95
  - This project also ships installable Skills for AI or agent workflows around `bgm-cli`.
package/README.md CHANGED
@@ -52,19 +52,6 @@ bgm auth set-token YOUR_ACCESS_TOKEN
52
52
  bgm auth token-status
53
53
  ```
54
54
 
55
- ### 多账户
56
-
57
- 可以把当前凭据存成命名 profile,在多个账户之间快捷切换:
58
-
59
- ```bash
60
- bgm auth profile save main
61
- bgm auth profile list
62
- bgm auth profile use another
63
- bgm --profile another user me
64
- ```
65
-
66
- `bgm --profile <name> <command>` 只在单条命令内临时使用该账户,不切换、不写盘。
67
-
68
55
  ### 代理
69
56
 
70
57
  如果你所在网络访问 Bangumi API 不稳定,可以为所有 CLI 请求设置 HTTP/HTTPS 代理:
@@ -110,24 +97,6 @@ bgm status --site bgm.tv
110
97
  bgm --json user me
111
98
  ```
112
99
 
113
- ### 粘贴链接直接查询
114
-
115
- 把 Bangumi 网页链接直接交给 `bgm`,它会解析成对应命令并输出同样的结果:
116
-
117
- ```bash
118
- bgm "https://bangumi.tv/group/topic/469977#post_4029724" # 定位到该楼 -> bgm group post 4029724
119
- bgm url https://bgm.tv/subject/253/characters # -> bgm subject characters 253
120
- bgm --url https://bgm.tv/anime/list/sai/collect --dry-run # 只看解析结果,不发请求
121
- ```
122
-
123
- - 三种写法等价:`bgm <url>`、`bgm url <url>`、`bgm --url <url>`(`-url` 亦可)。
124
- - 支持 `bgm.tv`、`bangumi.tv`、`chii.in`、`next.bgm.tv`、`api.bgm.tv`,可省略 `https://` 与 `www.`。
125
- - 解析是只读的,链接永远不会触发写操作;`--dry-run` 只打印解析结果。
126
- - `#post_<id>` 锚点会精确定位到该楼回复;`?page=n` 会换算成 `--offset`。
127
- - 多余的参数会透传给解析出的命令,`--json` 输出会附带 `resolvedFrom` 溯源字段。
128
- - 链接含 `#` 时请加引号,否则会被 shell 截断。
129
- - 完整支持列表见 `bgm url --help`。
130
-
131
100
  ## 文档索引
132
101
 
133
102
  - 本项目同时提供可安装的 Skills,适合让 AI / Agent 直接安装并操作 `bgm-cli`。
package/README.zh-TW.md CHANGED
@@ -52,19 +52,6 @@ bgm auth set-token YOUR_ACCESS_TOKEN
52
52
  bgm auth token-status
53
53
  ```
54
54
 
55
- ### 多帳戶
56
-
57
- 可以把當前憑據存成命名 profile,在多個帳戶之間快捷切換:
58
-
59
- ```bash
60
- bgm auth profile save main
61
- bgm auth profile list
62
- bgm auth profile use another
63
- bgm --profile another user me
64
- ```
65
-
66
- `bgm --profile <name> <command>` 只在單條命令內臨時使用該帳戶,不切換、不寫盤。
67
-
68
55
  ### 代理
69
56
 
70
57
  如果你所在網路存取 Bangumi API 不穩定,可以為所有 CLI 請求設定 HTTP/HTTPS 代理:
@@ -103,24 +90,6 @@ bgm trending subjects --type anime --limit 5
103
90
  bgm --json user me
104
91
  ```
105
92
 
106
- ### 貼上連結直接查詢
107
-
108
- 把 Bangumi 網頁連結直接交給 `bgm`,它會解析成對應命令並輸出同樣的結果:
109
-
110
- ```bash
111
- bgm "https://bangumi.tv/group/topic/469977#post_4029724" # 定位到該樓 -> bgm group post 4029724
112
- bgm url https://bgm.tv/subject/253/characters # -> bgm subject characters 253
113
- bgm --url https://bgm.tv/anime/list/sai/collect --dry-run # 只看解析結果,不發請求
114
- ```
115
-
116
- - 三種寫法等價:`bgm <url>`、`bgm url <url>`、`bgm --url <url>`(`-url` 亦可)。
117
- - 支援 `bgm.tv`、`bangumi.tv`、`chii.in`、`next.bgm.tv`、`api.bgm.tv`,可省略 `https://` 與 `www.`。
118
- - 解析是唯讀的,連結永遠不會觸發寫入操作;`--dry-run` 只印出解析結果。
119
- - `#post_<id>` 錨點會精確定位到該樓回覆;`?page=n` 會換算成 `--offset`。
120
- - 多餘的參數會透傳給解析出的命令,`--json` 輸出會附帶 `resolvedFrom` 溯源欄位。
121
- - 連結含 `#` 時請加引號,否則會被 shell 截斷。
122
- - 完整支援列表見 `bgm url --help`。
123
-
124
93
  ## 文件索引
125
94
 
126
95
  - 本專案同時提供可安裝的 Skills,適合讓 AI / Agent 直接安裝並操作 `bgm-cli`。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aronnaxlin/bgm-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
4
  "description": "Command-line client for Bangumi.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "aronnaxlin",
@@ -59,7 +59,7 @@ export async function runSearchCommand(command, args, context) {
59
59
  }
60
60
  case "reply":
61
61
  case "replies": {
62
- const result = await executeEntitySearch("replies", args, searchReplies);
62
+ const result = await executeEntitySearch("replies", args, searchReplies, { allowSource: true });
63
63
  printResult(result, context);
64
64
  return;
65
65
  }
@@ -82,11 +82,17 @@ export async function runSearchCommand(command, args, context) {
82
82
  }
83
83
  }
84
84
 
85
- async function executeEntitySearch(resource, args, searchFn) {
85
+ const REPLY_SOURCES = new Set([
86
+ "all", "group", "subject", "episode", "ep", "character", "crt", "person", "prsn", "blog",
87
+ ]);
88
+
89
+ async function executeEntitySearch(resource, args, searchFn, { allowSource = false } = {}) {
86
90
  const options = parseFlags(args);
87
91
  const keyword = firstPositional(options);
88
92
  if (!keyword) {
89
- throw new CommandError(`Usage: bgm search ${resource} <keyword> [--limit n] [--offset n] [--sort <sort>]`);
93
+ throw new CommandError(
94
+ `Usage: bgm search ${resource} <keyword> [--limit n] [--offset n] [--sort <sort>]${allowSource ? " [--source <source>]" : ""}`,
95
+ );
90
96
  }
91
97
 
92
98
  const query = {
@@ -98,6 +104,16 @@ async function executeEntitySearch(resource, args, searchFn) {
98
104
  query.sort = options.sort;
99
105
  }
100
106
 
107
+ if (allowSource && options.source) {
108
+ const source = String(options.source).toLowerCase();
109
+ if (!REPLY_SOURCES.has(source)) {
110
+ throw new CommandError(
111
+ "Invalid --source. Use one of: all, group, subject, episode (ep), character (crt), person (prsn), blog.",
112
+ );
113
+ }
114
+ query.source = source;
115
+ }
116
+
101
117
  const result = await searchFn(query);
102
118
 
103
119
  return {
@@ -109,6 +125,7 @@ async function executeEntitySearch(resource, args, searchFn) {
109
125
  limit: query.limit,
110
126
  offset: query.offset,
111
127
  sort: query.sort,
128
+ ...(query.source ? { source: query.source } : {}),
112
129
  },
113
130
  };
114
131
  }
@@ -1172,7 +1172,23 @@ export class BangumiClient {
1172
1172
  throw new CommandError("Missing username. Pass a username or log in first.");
1173
1173
  }
1174
1174
 
1175
- const result = await this.request(`/p1/users/${encodeURIComponent(String(username))}/collections/subjects`, {
1175
+ let isMe = false;
1176
+ try {
1177
+ const me = await this.getMe();
1178
+ const meUsername = typeof me?.username === "string" ? me.username.trim() : "";
1179
+ if (meUsername && meUsername.toLowerCase() === String(username).trim().toLowerCase()) {
1180
+ isMe = true;
1181
+ }
1182
+ } catch {
1183
+ isMe = false;
1184
+ }
1185
+
1186
+ const path = isMe
1187
+ ? "/p1/collections/subjects"
1188
+ : `/p1/users/${encodeURIComponent(String(username))}/collections/subjects`;
1189
+
1190
+ const result = await this.request(path, {
1191
+ auth: true,
1176
1192
  query: normalizeSubjectCollectionQuery(query),
1177
1193
  });
1178
1194
  return normalizeSubjectCollectionPage(result);
@@ -49,6 +49,12 @@ async function communityRequest(path, options = {}) {
49
49
  return adaptEnvelope(raw);
50
50
  } catch (error) {
51
51
  if (error instanceof BangumiApiError) {
52
+ if (isCloudflareChallenge(error)) {
53
+ throw new BangumiCommunityApiError(
54
+ `SearchEncore (bgmdb.ry.mk) rejected the request with a Cloudflare bot challenge (HTTP ${error.status}).`,
55
+ { status: error.status, details: { url, path } },
56
+ );
57
+ }
52
58
  throw new BangumiCommunityApiError(error.message, {
53
59
  status: error.status,
54
60
  details: error.details,
@@ -63,6 +69,13 @@ async function communityRequest(path, options = {}) {
63
69
  }
64
70
  }
65
71
 
72
+ function isCloudflareChallenge(error) {
73
+ return (
74
+ typeof error.details === "string" &&
75
+ error.details.includes("cdn-cgi/challenge-platform")
76
+ );
77
+ }
78
+
66
79
  /**
67
80
  * 将第三方的 envelope 格式适配为官方风格:
68
81
  * 原始: { data, pagination: { total, limit, offset }, meta: { executionMs } }
@@ -110,6 +123,7 @@ function buildSearchQuery(params = {}) {
110
123
  if (params.limit !== undefined) q.limit = params.limit;
111
124
  if (params.offset !== undefined) q.offset = params.offset;
112
125
  if (params.sort !== undefined) q.sort = params.sort;
126
+ if (params.source !== undefined) q.source = params.source;
113
127
  return q;
114
128
  }
115
129
 
@@ -208,20 +222,6 @@ export async function listGroupTopics(groupKey, query = {}) {
208
222
  return communityRequest(`/groups/${encode(groupKey)}/topics`, { query });
209
223
  }
210
224
 
211
- /**
212
- * 获取指定用户的所有小组话题。
213
- */
214
- export async function listUserGroupTopics(userKey, query = {}) {
215
- return communityRequest(`/users/${encode(userKey)}/group-topics`, { query });
216
- }
217
-
218
- /**
219
- * 获取最新的条目话题列表。
220
- */
221
- export async function listRecentSubjectTopics(query = {}) {
222
- return communityRequest("/subjects/-/topics", { query });
223
- }
224
-
225
225
  /**
226
226
  * 获取指定条目的话题列表。
227
227
  */
@@ -229,27 +229,6 @@ export async function listSubjectTopics(subjectId, query = {}) {
229
229
  return communityRequest(`/subjects/${encode(subjectId)}/topics`, { query });
230
230
  }
231
231
 
232
- /**
233
- * 获取指定用户的所有条目话题。
234
- */
235
- export async function listUserSubjectTopics(userKey, query = {}) {
236
- return communityRequest(`/users/${encode(userKey)}/subject-topics`, { query });
237
- }
238
-
239
- /**
240
- * 获取指定用户的目录列表。
241
- */
242
- export async function listUserIndexes(userKey, query = {}) {
243
- return communityRequest(`/users/${encode(userKey)}/indexes`, { query });
244
- }
245
-
246
- /**
247
- * 获取指定用户的日志列表。
248
- */
249
- export async function listUserBlogs(userKey, query = {}) {
250
- return communityRequest(`/users/${encode(userKey)}/blogs`, { query });
251
- }
252
-
253
232
  /* ------------------------------------------------------------------ */
254
233
  /* 详情接口 */
255
234
  /* ------------------------------------------------------------------ */
@@ -264,16 +243,6 @@ export async function getUser(userKey) {
264
243
  return communityRequest(`/users/${encode(userKey)}`);
265
244
  }
266
245
 
267
- /**
268
- * 获取用户头像历史记录。
269
- */
270
- export async function getUserAvatarHistory(userKey) {
271
- if (!userKey) {
272
- throw new BangumiCommunityApiError("Missing userKey.");
273
- }
274
- return communityRequest(`/users/${encode(userKey)}/avatars`);
275
- }
276
-
277
246
  /**
278
247
  * 获取单个小组信息。
279
248
  */
@@ -181,7 +181,7 @@ function buildUsageText(target) {
181
181
  ["bgm [--json] search group <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search groups via SearchEncore."],
182
182
  ["bgm [--json] search topic <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search group topics via SearchEncore."],
183
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."],
184
+ ["bgm [--json] search reply <keyword> [--limit n] [--offset n] [--sort newest|oldest] [--source <source>]", "Search replies via SearchEncore. Source: all|group|subject|episode|character|person|blog."],
185
185
  ["bgm [--json] search index <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search indexes via SearchEncore."],
186
186
  ["bgm [--json] search blog <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search blogs via SearchEncore."],
187
187
  ], [
@@ -190,6 +190,10 @@ function buildUsageText(target) {
190
190
  " (bgmdb.ry.mk). Data is crawled/aggregated, NOT from bangumi.tv",
191
191
  " official sources. Every response is tagged with",
192
192
  " _meta.isSearchEncore = true for downstream identification.",
193
+ "",
194
+ " --sort: newest|oldest|popular (aliases new|old|hot); anything else ranks by relevance.",
195
+ " Keywords accept inline directives: user:<name|uid> group:<slug>",
196
+ " type:<anime|book|music|game|real> exact:true include:nsfw exclude:nsfw include:blocked",
193
197
  ]);
194
198
  case "notify":
195
199
  return buildGroupUsage("Notify", [
@@ -1,18 +1,18 @@
1
1
  import { CommandError } from "./output.js";
2
2
 
3
- const TOPIC_POST_REACTION_VALUES = Object.freeze([54, 62, 79, 80, 85, 88, 90, 104, 122, 140]);
4
- const SUBJECT_COLLECT_REACTION_VALUES = Object.freeze([54]);
3
+ const TOPIC_POST_REACTION_VALUES = Object.freeze([0, 54, 62, 79, 80, 85, 88, 90, 104, 122, 140, 141]);
4
+ const SUBJECT_COLLECT_REACTION_VALUES = Object.freeze([0, 54, 80, 88, 90, 104, 122, 140]);
5
5
 
6
6
  export const BANGUMI_REACTION_TARGETS = Object.freeze({
7
7
  subjectPost: Object.freeze({
8
8
  label: "subject discussion reply",
9
9
  allowedValues: TOPIC_POST_REACTION_VALUES,
10
- note: "Subject and group topic replies share the p1 topic-post reaction shape; values were probed on a group topic post.",
10
+ note: "Subject and group topic replies share the p1 topic-post reaction shape; values mirror ALLOWED_COMMON_REACTIONS in bangumi/server-private lib/like.ts.",
11
11
  }),
12
12
  groupPost: Object.freeze({
13
13
  label: "group topic reply",
14
14
  allowedValues: TOPIC_POST_REACTION_VALUES,
15
- note: "Values probed live on a group topic post.",
15
+ note: "Values mirror ALLOWED_COMMON_REACTIONS in bangumi/server-private lib/like.ts.",
16
16
  }),
17
17
  episodeComment: Object.freeze({
18
18
  label: "episode comment",
@@ -22,7 +22,7 @@ export const BANGUMI_REACTION_TARGETS = Object.freeze({
22
22
  subjectCollect: Object.freeze({
23
23
  label: "subject collection comment",
24
24
  allowedValues: SUBJECT_COLLECT_REACTION_VALUES,
25
- note: "Value 54 is probed valid; 79 is probed invalid for this target.",
25
+ note: "Values mirror ALLOWED_SUBJECT_COLLECT_REACTIONS in bangumi/server-private lib/like.ts; 79 and 141 are not accepted here.",
26
26
  }),
27
27
  timeline: Object.freeze({
28
28
  label: "timeline entry",
@@ -40,8 +40,8 @@ export function normalizeBangumiReactionValue(value, targetKey) {
40
40
  if (Number.isNaN(parsed)) {
41
41
  throw new CommandError(`Expected reaction value to be an integer, received: ${value}`);
42
42
  }
43
- if (parsed <= 0) {
44
- throw new CommandError(`Expected reaction value to be > 0, received: ${value}`);
43
+ if (parsed < 0) {
44
+ throw new CommandError(`Expected reaction value to be >= 0, received: ${value}`);
45
45
  }
46
46
 
47
47
  const target = BANGUMI_REACTION_TARGETS[targetKey];
@@ -299,12 +299,12 @@
299
299
  "description": "Bangumi p1 反应贴贴白名单。不是所有表情都能用于 like/unlike。",
300
300
  "verifiedTargets": {
301
301
  "groupPost": {
302
- "values": [54, 62, 79, 80, 85, 88, 90, 104, 122, 140],
303
- "source": "Live probe on 2026-05-24."
302
+ "values": [0, 54, 62, 79, 80, 85, 88, 90, 104, 122, 140, 141],
303
+ "source": "ALLOWED_COMMON_REACTIONS in bangumi/server-private lib/like.ts (2026-09)."
304
304
  },
305
305
  "subjectCollect": {
306
- "values": [54],
307
- "source": "Live probe on 2026-05-24."
306
+ "values": [0, 54, 80, 88, 90, 104, 122, 140],
307
+ "source": "ALLOWED_SUBJECT_COLLECT_REACTIONS in bangumi/server-private lib/like.ts (2026-09)."
308
308
  }
309
309
  }
310
310
  }