@aronnaxlin/bgm-cli 1.1.4 → 1.1.6
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 +1 -0
- package/README.md +1 -0
- package/README.zh-TW.md +1 -0
- package/package.json +3 -2
- package/skills/README.md +70 -0
- package/skills/bgm-cli-develop/SKILL.md +371 -0
- package/skills/bgm-cli-operate/SKILL.md +259 -0
- package/skills/bgm-cli-operate/references/commands.md +476 -0
- package/skills/bgm-cli-operate/references/community-boundaries.md +69 -0
- package/skills/bgm-cli-operate/references/install-and-auth.md +196 -0
- package/skills/bgm-cli-operate/references/reactions.md +70 -0
- package/skills/bgm-cli-operate/references/troubleshooting.md +186 -0
- package/src/cli.js +7 -0
- package/src/commands/search.js +66 -9
- package/src/core/output.js +9 -1
- package/src/utils/args.js +15 -1
- package/src/utils/skill.js +59 -0
- package/src/utils/validators.js +17 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Install And Auth Reference
|
|
2
|
+
|
|
3
|
+
Use this reference when the agent needs to get `bgm-cli` working from zero.
|
|
4
|
+
|
|
5
|
+
## Install Decision Table
|
|
6
|
+
|
|
7
|
+
| Situation | Preferred action |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| User only wants a working `bgm` command | Use the remote managed installer |
|
|
10
|
+
| User is already inside a cloned `bgm-cli` checkout and wants this checkout as `bgm` | Use the repo install script or `bgm setup install-path` |
|
|
11
|
+
| User only needs commands in the current checkout | Use `./bgm` directly |
|
|
12
|
+
|
|
13
|
+
## Remote Managed Install
|
|
14
|
+
|
|
15
|
+
### macOS / Linux
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -fsSL https://raw.githubusercontent.com/aronnaxlin/bgm-cli/main/scripts/install-remote.sh | sh
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Windows PowerShell
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
irm https://raw.githubusercontent.com/aronnaxlin/bgm-cli/main/scripts/install-remote.ps1 | iex
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This path does not require a prior `git clone`.
|
|
28
|
+
|
|
29
|
+
It downloads the current `main` branch to a managed local directory and performs the global install automatically.
|
|
30
|
+
|
|
31
|
+
If the managed install already exists, rerunning the same command updates it in place and tries to preserve local config.
|
|
32
|
+
|
|
33
|
+
## Repository-Local Install
|
|
34
|
+
|
|
35
|
+
### Use the repo install scripts
|
|
36
|
+
|
|
37
|
+
macOS / Linux:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
./install.sh
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Windows PowerShell:
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
./install.ps1
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Expose the current checkout as global `bgm`
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
bgm setup install-path
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Use this when `bgm` is already running from the repository checkout and the user wants that checkout installed into PATH.
|
|
56
|
+
|
|
57
|
+
## Verify Installation
|
|
58
|
+
|
|
59
|
+
Preferred verification:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bgm --version
|
|
63
|
+
bgm --help
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If only the repository-local executable is being used:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
./bgm --help
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Update Managed Install
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
bgm setup update
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
This is only for installs created by the remote managed installer.
|
|
79
|
+
|
|
80
|
+
Do not use it to update a development checkout.
|
|
81
|
+
|
|
82
|
+
## Auth Priority
|
|
83
|
+
|
|
84
|
+
Preferred order:
|
|
85
|
+
|
|
86
|
+
1. interactive `bgm --init`, choosing the recommended official Bangumi login
|
|
87
|
+
2. direct `bgm auth login` when the user wants to skip the broader init wizard
|
|
88
|
+
3. Access Token channel when the user already has a token or needs scripting compatibility
|
|
89
|
+
4. OAuth helper flow only when explicitly requested
|
|
90
|
+
5. manual private session import only when a session-specific task needs it
|
|
91
|
+
|
|
92
|
+
## Official Login
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
bgm --init
|
|
96
|
+
bgm auth status
|
|
97
|
+
bgm user me
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`bgm --init` now offers official Bangumi login first and Access Token second. The official login path is the same private-session flow as:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
bgm auth login
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
It prompts for email, hides the password input, opens the official Turnstile verification flow when needed, and saves the resulting `next.bgm.tv` private session.
|
|
107
|
+
|
|
108
|
+
## Access Token Channel
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
bgm auth set-token YOUR_ACCESS_TOKEN
|
|
112
|
+
bgm auth token-status
|
|
113
|
+
bgm user me
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Use this when the user already has a token or when a scripting workflow specifically depends on Access Token auth.
|
|
117
|
+
|
|
118
|
+
## OAuth Helper Commands
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
bgm auth login-url --state random-state
|
|
122
|
+
bgm auth token --code YOUR_CODE --save
|
|
123
|
+
bgm auth refresh --save
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Use these only when the user explicitly wants OAuth-style setup.
|
|
127
|
+
|
|
128
|
+
If the repository's hosted OAuth relay is configured and the user explicitly wants to debug browser OAuth authorization, the CLI can also let the hosted callback page send the final token payload back to the current terminal automatically. This is not part of the normal `bgm --init` login path.
|
|
129
|
+
|
|
130
|
+
## Manual Private Session Commands
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
bgm auth login
|
|
134
|
+
bgm auth session-login
|
|
135
|
+
bgm auth set-session YOUR_CHIINEXTSESSIONID
|
|
136
|
+
bgm auth session-status
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`bgm auth login` is the normal official login path. `session-login` and `set-session` are manual helper paths for importing an existing browser session.
|
|
140
|
+
|
|
141
|
+
## Clear Auth
|
|
142
|
+
|
|
143
|
+
To remove all saved auth state (Access Token, Refresh Token, Private Session) for clean testing or re-authentication:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
bgm auth clear
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`bgm auth clear` does not delete saved account profiles; run `bgm auth profile delete <name>` for those.
|
|
150
|
+
|
|
151
|
+
## Multiple Accounts
|
|
152
|
+
|
|
153
|
+
Named profiles snapshot one account's credentials each. The active credentials always live in the flat top-level config keys; switching copies them back into the previous profile first, then loads the target profile.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
bgm auth profile save main
|
|
157
|
+
bgm auth profile list
|
|
158
|
+
bgm auth profile use another
|
|
159
|
+
bgm auth profile delete old-account
|
|
160
|
+
bgm --profile another user me
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Operational notes:
|
|
164
|
+
|
|
165
|
+
- `bgm --profile <name> <command>` is a read-only per-command override: it never writes to disk, and credential-writing commands (`auth login`, `auth set-token`, `auth clear`, `auth profile save/use/delete`, `--init`, `tui`, `config set <auth key>`) refuse to run with it
|
|
166
|
+
- overwriting an existing non-active profile with `auth profile save` requires `--force`
|
|
167
|
+
- auth environment variables such as `BGM_ACCESS_TOKEN` still win over any profile; the profile commands print a warning listing the overriding variables when they are set
|
|
168
|
+
|
|
169
|
+
## Turnstile Helper
|
|
170
|
+
|
|
171
|
+
Group writes, timeline writes, and experimental blog comment writes may require a fresh Turnstile token.
|
|
172
|
+
|
|
173
|
+
Default path:
|
|
174
|
+
|
|
175
|
+
- let `bgm` try Bangumi's hosted official Turnstile page first
|
|
176
|
+
- let it fall back to the local helper automatically if needed
|
|
177
|
+
|
|
178
|
+
Manual helper entrypoint:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
bgm auth turnstile --manual --port 8765
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Many group write commands and `bgm blog reply` can also trigger the local helper automatically when a token is not provided.
|
|
185
|
+
|
|
186
|
+
Timeline `say` and `reply` follow the same Turnstile rules.
|
|
187
|
+
|
|
188
|
+
## Minimum Ready State
|
|
189
|
+
|
|
190
|
+
The CLI is effectively ready when all of these succeed as expected:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
bgm --help
|
|
194
|
+
bgm auth status
|
|
195
|
+
bgm user me
|
|
196
|
+
```
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Reactions ("贴贴") Reference
|
|
2
|
+
|
|
3
|
+
Bangumi's reaction feature is called 贴贴 on the site. It lets a user attach one sticker from a fixed set to a reply, an episode comment, a subject collection comment (吐槽箱), or a timeline entry. The p1 endpoints are named `.../like`, but the feature is not a "like" button: the value is one of twelve stickers, each with its own meaning. Never summarize `reactions` as "likes" or "点赞".
|
|
4
|
+
|
|
5
|
+
Where reactions appear in CLI output:
|
|
6
|
+
|
|
7
|
+
- `--json` topic, post, episode comment, and timeline payloads carry `reactions: [{ value, users }]`. The `value` is the numeric sticker id below.
|
|
8
|
+
- Comment and reply bodies carry inline emote codes such as `(bgm124)`. The same table applies to those codes when they are one of the reaction stickers.
|
|
9
|
+
|
|
10
|
+
## Current sticker set
|
|
11
|
+
|
|
12
|
+
Values follow the site's picker order (three rows of four). "Reply" means group topic replies, subject discussion replies, episode comments, and timeline entries. "Collect" means subject collection comments.
|
|
13
|
+
|
|
14
|
+
| value | emote | targets | reading |
|
|
15
|
+
| --- | --- | --- | --- |
|
|
16
|
+
| 0 | bgm67 | reply, collect | first slot of the picker; a plain smile. 萌 微笑 开心 |
|
|
17
|
+
| 79 | bgm63 | reply | affectionate, kiss. 花痴 亲亲 么么哒 |
|
|
18
|
+
| 54 | bgm38 | reply, collect | laughing with tears. 笑哭 |
|
|
19
|
+
| 140 | bgm124 | reply, collect | **+1**. Added by the site admin on 2023-04-02 as a shortcut for typing "+1"; the most used reaction on the site. Agreement or endorsement. |
|
|
20
|
+
| 62 | bgm46 | reply | closed eyes, blushing, wavy cat mouth: `>w<` `≥﹏≤` `≥ω≤`. Read as excited agreement by most users, as awkwardness by some; often confused with bgm50. |
|
|
21
|
+
| 122 | bgm106 | reply, collect | sparkling eyes. 星星眼 期待 火眼金睛 撇嘴笑 |
|
|
22
|
+
| 104 | bgm88 | reply, collect | smug, squinting grin. 得意 闷骚 眯眼笑 |
|
|
23
|
+
| 80 | bgm64 | reply, collect | infatuated, without the kiss. 花痴 无亲亲 |
|
|
24
|
+
| 141 | bgm125 | reply | **?**. Added by the site admin on 2023-04-02 as a shortcut for typing "?". Doubt or objection; the community treats it as the most confrontational reaction available. 问号 反对 |
|
|
25
|
+
| 88 | bgm72 | reply, collect | cute, mouthless stare. 萌 无口 |
|
|
26
|
+
| 85 | bgm69 | reply | cute surprise. 萌 惊讶 |
|
|
27
|
+
| 90 | bgm74 | reply, collect | crying quietly. 流泪 默默流泪 |
|
|
28
|
+
|
|
29
|
+
Only `140` (+1) is close to "agree". Treat everything else as an emotional sticker, not a vote.
|
|
30
|
+
|
|
31
|
+
## Retired stickers
|
|
32
|
+
|
|
33
|
+
These values still appear in old data but cannot be posted any more. The site hides them from the picker; the server rejects them on write.
|
|
34
|
+
|
|
35
|
+
| value | emote | note |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| 118 | bgm102 | "流汗" (sweat). Removed around 2023-05-24 after heavy hostile use; read as pure disapproval. |
|
|
38
|
+
| 53 | bgm37 | retired |
|
|
39
|
+
| 92 | bgm76 | retired |
|
|
40
|
+
| 60 | bgm44 | retired |
|
|
41
|
+
| 128 | bgm112 | retired |
|
|
42
|
+
| 47 | bgm31 | retired |
|
|
43
|
+
| 68 | bgm52 | retired |
|
|
44
|
+
| 137 | bgm121 | retired |
|
|
45
|
+
| 76 | bgm60 | retired |
|
|
46
|
+
| 132 | bgm116 | retired |
|
|
47
|
+
|
|
48
|
+
## Writing reactions
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
bgm group like-post <post_id> 140
|
|
52
|
+
bgm subject like-post <post_id> 141
|
|
53
|
+
bgm episode like-comment <comment_id> 54
|
|
54
|
+
bgm timeline like <timeline_id> 0
|
|
55
|
+
bgm subject like-collect <collect_id> 140
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Reply-type targets accept all twelve current values.
|
|
59
|
+
- Subject collection comments accept only `0, 54, 80, 88, 90, 104, 122, 140`; `79`, `62`, `141`, `85` are rejected there.
|
|
60
|
+
- One reaction per user per target; a second `like` replaces the first. Use the matching `unlike` command to remove it.
|
|
61
|
+
- Reactions are rate limited per user (10 per minute at the time of writing). Do not retry a rejected reaction in a loop.
|
|
62
|
+
- Reactions are anonymous on the site and send no notification, but the `users` array in `--json` output does list who reacted.
|
|
63
|
+
|
|
64
|
+
## Sources
|
|
65
|
+
|
|
66
|
+
- Feature announcement by the site admin: https://bgm.tv/group/topic/379812
|
|
67
|
+
- Extension to subject collection comments: https://bgm.tv/group/topic/388835
|
|
68
|
+
- Server allow-lists: `lib/like.ts` in https://github.com/bangumi/server-private
|
|
69
|
+
- Frontend value to emote mapping: `packages/utils/reactions.ts` in https://github.com/bangumi/frontend
|
|
70
|
+
- Community readings of individual stickers: https://bgm.tv/group/topic/453824 and https://bgm.tv/group/topic/453798
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
Use this reference when installation or operation does not behave as expected.
|
|
4
|
+
|
|
5
|
+
## `bgm: command not found`
|
|
6
|
+
|
|
7
|
+
Check whether the repository-local executable exists and works:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
./bgm --help
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If that works, either keep using `./bgm` or install the current checkout into PATH with:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bgm setup install-path
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
If neither `bgm` nor `./bgm` works, perform the remote managed install.
|
|
20
|
+
|
|
21
|
+
## Node.js Too Old Or Missing
|
|
22
|
+
|
|
23
|
+
`bgm-cli` requires Node.js `>= 20`.
|
|
24
|
+
|
|
25
|
+
Check:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
node --version
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If Node is missing or older than `20`, install or upgrade Node first, then retry the `bgm-cli` install.
|
|
32
|
+
|
|
33
|
+
## Managed Install vs Development Checkout
|
|
34
|
+
|
|
35
|
+
Use `bgm setup update` only for the managed install created by the remote installer.
|
|
36
|
+
|
|
37
|
+
If the user is running a normal cloned repository, update that checkout with their normal development workflow instead.
|
|
38
|
+
|
|
39
|
+
## Auth Exists But Requests Fail
|
|
40
|
+
|
|
41
|
+
Verify the current auth state explicitly:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bgm auth status
|
|
45
|
+
bgm user me
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`bgm auth status` is a local two-channel overview. If the Access Token channel specifically looks wrong, validate or replace it directly:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
bgm auth token-status
|
|
52
|
+
bgm auth set-token YOUR_ACCESS_TOKEN
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
If the failing request is `episode list` for an NSFW / R18 subject, remember that Bangumi may return a misleading `404` when no usable auth context is attached. For `p1` requests, the CLI prefers a private session cookie when one is saved and falls back to Access Token otherwise.
|
|
56
|
+
|
|
57
|
+
## Private Session Confusion
|
|
58
|
+
|
|
59
|
+
A saved `p1` session is now the normal result of official login.
|
|
60
|
+
|
|
61
|
+
Check the channel separately:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bgm auth session-status
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Do not confuse `auth login` with `session-login`: `auth login` is the official account/password + Turnstile flow, while `session-login` is only a manual browser-cookie import helper. For `p1` requests, the CLI prefers the private session cookie when it is saved and does not also send the Access Token.
|
|
68
|
+
|
|
69
|
+
## Turnstile-Gated Write Fails
|
|
70
|
+
|
|
71
|
+
Subject/group topic creation, subject/group replies, character/person comments, timeline writes, and experimental blog comment writes may require Turnstile verification.
|
|
72
|
+
|
|
73
|
+
Try one of these:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
bgm auth turnstile
|
|
77
|
+
bgm auth turnstile --manual --port 8765
|
|
78
|
+
bgm group create-topic boring "Title" "Content"
|
|
79
|
+
bgm group reply 498114 "Reply content"
|
|
80
|
+
bgm subject create-topic 253 "Title" "Content"
|
|
81
|
+
bgm subject reply 29892 "Reply content"
|
|
82
|
+
bgm character comment 1 "Comment content"
|
|
83
|
+
bgm person comment 1 "Comment content"
|
|
84
|
+
bgm blog reply 371953 "Reply content"
|
|
85
|
+
bgm timeline say "test"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
If the user already has a Turnstile token, pass it explicitly with `--turnstile-token`.
|
|
89
|
+
|
|
90
|
+
Operational guidance:
|
|
91
|
+
|
|
92
|
+
- by default, prefer the hosted official Turnstile flow
|
|
93
|
+
- if the hosted callback cannot reach the current terminal, use `--manual` to force the local helper path
|
|
94
|
+
- for blog writes, also warn that Bangumi may still return server-side `500` errors
|
|
95
|
+
|
|
96
|
+
### Agent posting Turnstile human-in-the-loop workflow
|
|
97
|
+
|
|
98
|
+
When an agent is posting on behalf of a user, the agent cannot complete the CAPTCHA. Follow this exact verified workflow:
|
|
99
|
+
|
|
100
|
+
1. **Attempt the write command directly**:
|
|
101
|
+
```bash
|
|
102
|
+
bgm group create-topic dev "Title" "Content"
|
|
103
|
+
```
|
|
104
|
+
Expect failure: `Turnstile verification is required to create a group topic`.
|
|
105
|
+
|
|
106
|
+
2. **Generate the official Turnstile URL**:
|
|
107
|
+
```bash
|
|
108
|
+
bgm auth turnstile
|
|
109
|
+
```
|
|
110
|
+
The CLI outputs a URL like:
|
|
111
|
+
```
|
|
112
|
+
https://next.bgm.tv/p1/turnstile?redirect_uri=...
|
|
113
|
+
```
|
|
114
|
+
In headless/agent environments, the command will time out waiting for auto-callback. This is normal.
|
|
115
|
+
|
|
116
|
+
3. **Send the URL to the user**:
|
|
117
|
+
Deliver the URL to the user through the current chat platform. The user opens it in a browser, completes the CAPTCHA, and is redirected.
|
|
118
|
+
|
|
119
|
+
4. **Receive the token from the user**:
|
|
120
|
+
After redirect, the callback URL contains a `token` query parameter. The user may send back:
|
|
121
|
+
- The full callback URL (agent extracts `token` from the query string)
|
|
122
|
+
- Or just the raw token string
|
|
123
|
+
|
|
124
|
+
5. **Re-run with `--turnstile-token`**:
|
|
125
|
+
```bash
|
|
126
|
+
bgm group create-topic dev "Title" "Content" --turnstile-token "EXTRACTED_TOKEN"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
This same 5-step flow works for:
|
|
130
|
+
- `bgm group reply <topic_id> "Content"`
|
|
131
|
+
- `bgm timeline say "Content"`
|
|
132
|
+
- `bgm timeline reply <timeline_id> "Content"`
|
|
133
|
+
- `bgm blog reply <blog_id> "Content"` (experimental)
|
|
134
|
+
|
|
135
|
+
Key reminders:
|
|
136
|
+
- The token is short-lived and intended for the next write operation only
|
|
137
|
+
- Do not rely on terminal auto-callback in agent environments
|
|
138
|
+
- Always send the URL to the user and wait for manual completion
|
|
139
|
+
|
|
140
|
+
## Search-Based Targeting Is Ambiguous
|
|
141
|
+
|
|
142
|
+
When a title search returns multiple candidates, reduce the result set and use `--pick` for commands that support it.
|
|
143
|
+
|
|
144
|
+
Prefer exact IDs whenever possible.
|
|
145
|
+
|
|
146
|
+
## Episode Progress Write Fails
|
|
147
|
+
|
|
148
|
+
If `episode status` or `episode watch` fails, check these in order:
|
|
149
|
+
|
|
150
|
+
1. the parent subject is already in the user's collection
|
|
151
|
+
2. the access token is valid
|
|
152
|
+
3. for NSFW / R18 subjects, the account is eligible to view the subject
|
|
153
|
+
4. the command is using the right targeting mode: `watch` for main episodes by number, `status` for direct `episode_id`
|
|
154
|
+
|
|
155
|
+
Examples:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
bgm --json collection get 253
|
|
159
|
+
bgm --json episode list 253 --type main --limit 5
|
|
160
|
+
bgm episode watch 253 1
|
|
161
|
+
bgm episode status 103232 watched
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Observed Bangumi behavior:
|
|
165
|
+
|
|
166
|
+
- the parent subject must already be collected
|
|
167
|
+
- the parent collection does not have to be `doing`
|
|
168
|
+
- Bangumi may briefly return stale episode state right after a write, so one immediate read is not always authoritative
|
|
169
|
+
|
|
170
|
+
## JSON Needed For Stable Agent Consumption
|
|
171
|
+
|
|
172
|
+
If human-readable output is hard to parse or verify, rerun the read command with `--json`.
|
|
173
|
+
|
|
174
|
+
Examples:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
bgm --json user me
|
|
178
|
+
bgm --json subject get 253
|
|
179
|
+
bgm --json collection get 253
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Unsupported Community Surface
|
|
183
|
+
|
|
184
|
+
If the user asks for a Bangumi website feature that the CLI does not expose, check the current CLI help and report the supported scope plainly.
|
|
185
|
+
|
|
186
|
+
Do not guess missing commands.
|
package/src/cli.js
CHANGED
|
@@ -122,6 +122,7 @@ import { runBookCommand } from "./commands/book.js";
|
|
|
122
122
|
import { runSearchCommand } from "./commands/search.js";
|
|
123
123
|
import { runUrlCommand } from "./commands/url.js";
|
|
124
124
|
import { looksLikeBangumiUrl } from "./utils/bangumi-url.js";
|
|
125
|
+
import { readSkill } from "./utils/skill.js";
|
|
125
126
|
|
|
126
127
|
const CLI_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
127
128
|
const REPO_ROOT = path.resolve(CLI_DIR, "..");
|
|
@@ -135,6 +136,12 @@ async function main(argv) {
|
|
|
135
136
|
rawArgs: parsed.args,
|
|
136
137
|
};
|
|
137
138
|
|
|
139
|
+
// Print a bundled skill verbatim. Runs before any config, proxy or login work.
|
|
140
|
+
if (parsed.skill) {
|
|
141
|
+
process.stdout.write(readSkill(parsed.skill.name, parsed.skill.reference));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
138
145
|
try {
|
|
139
146
|
installProxyFromConfig(getConfig());
|
|
140
147
|
} catch (error) {
|
package/src/commands/search.js
CHANGED
|
@@ -20,14 +20,19 @@ import {
|
|
|
20
20
|
searchBlogs,
|
|
21
21
|
} from "../core/community-api.js";
|
|
22
22
|
import { CommandError, printResult } from "../core/output.js";
|
|
23
|
-
import { firstPositional, parseFlags } from "../utils/args.js";
|
|
24
|
-
import {
|
|
23
|
+
import { firstPositional, parseFlags, splitFilterValues } from "../utils/args.js";
|
|
24
|
+
import {
|
|
25
|
+
normalizeNonNegativeInteger,
|
|
26
|
+
normalizePageSize,
|
|
27
|
+
parseOptionalBoolean,
|
|
28
|
+
} from "../utils/helpers.js";
|
|
29
|
+
import { normalizeSubjectTypeName } from "../utils/validators.js";
|
|
25
30
|
|
|
26
31
|
export async function runSearchCommand(command, args, context) {
|
|
27
32
|
switch (command) {
|
|
28
33
|
case "subject":
|
|
29
34
|
case "subjects": {
|
|
30
|
-
const result = await executeEntitySearch("subjects", args, searchSubjects);
|
|
35
|
+
const result = await executeEntitySearch("subjects", args, searchSubjects, { allowSubjectType: true });
|
|
31
36
|
printResult(result, context);
|
|
32
37
|
return;
|
|
33
38
|
}
|
|
@@ -77,7 +82,7 @@ export async function runSearchCommand(command, args, context) {
|
|
|
77
82
|
}
|
|
78
83
|
default:
|
|
79
84
|
throw new CommandError(
|
|
80
|
-
"Usage: bgm search <subject|user|group|topic|subject-topic|reply|index|blog> <keyword> [--limit n] [--offset n] [--sort <sort>]",
|
|
85
|
+
"Usage: bgm search <subject|user|group|topic|subject-topic|reply|index|blog> <keyword> [--limit n] [--offset n] [--sort <sort>] [--user <name>] [--group <slug>] [--exact] [--include <nsfw|blocked>] [--exclude nsfw] [--type <type>] [--source <source>]",
|
|
81
86
|
);
|
|
82
87
|
}
|
|
83
88
|
}
|
|
@@ -86,15 +91,61 @@ const REPLY_SOURCES = new Set([
|
|
|
86
91
|
"all", "group", "subject", "episode", "ep", "character", "crt", "person", "prsn", "blog",
|
|
87
92
|
]);
|
|
88
93
|
|
|
89
|
-
|
|
94
|
+
// SearchEncore 内联指令的合法取值(写入 q,而非独立 query 参数)。
|
|
95
|
+
const DIRECTIVE_INCLUDE_VALUES = new Set(["nsfw", "blocked"]);
|
|
96
|
+
const DIRECTIVE_EXCLUDE_VALUES = new Set(["nsfw"]);
|
|
97
|
+
|
|
98
|
+
function directiveValues(flag, flagName, { allowed, lowercase = true } = {}) {
|
|
99
|
+
if (flag === undefined) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
if (flag === true) {
|
|
103
|
+
throw new CommandError(`--${flagName} requires a value.`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return splitFilterValues(flag).map((entry) => {
|
|
107
|
+
const raw = String(entry);
|
|
108
|
+
const value = lowercase ? raw.toLowerCase() : raw;
|
|
109
|
+
if (allowed && !allowed.has(value)) {
|
|
110
|
+
throw new CommandError(
|
|
111
|
+
`Invalid --${flagName}: ${entry}. Use one of: ${[...allowed].join(", ")}.`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function executeEntitySearch(resource, args, searchFn, { allowSource = false, allowSubjectType = false } = {}) {
|
|
90
119
|
const options = parseFlags(args);
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
120
|
+
const rawKeyword = firstPositional(options);
|
|
121
|
+
if (!rawKeyword) {
|
|
93
122
|
throw new CommandError(
|
|
94
|
-
`Usage: bgm search ${resource} <keyword> [--limit n] [--offset n] [--sort <sort>]${allowSource ? " [--source <source>]" : ""}`,
|
|
123
|
+
`Usage: bgm search ${resource} <keyword> [--limit n] [--offset n] [--sort <sort>] [--user <name>] [--group <slug>] [--exact] [--include <nsfw|blocked>] [--exclude nsfw]${allowSubjectType ? " [--type <book|anime|music|game|real>]" : ""}${allowSource ? " [--source <source>]" : ""}`,
|
|
95
124
|
);
|
|
96
125
|
}
|
|
97
126
|
|
|
127
|
+
// 通用指令:用户名/组 slug 保留原始大小写,不做小写归一化。
|
|
128
|
+
const users = directiveValues(options.user, "user", { lowercase: false });
|
|
129
|
+
const groups = directiveValues(options.group, "group", { lowercase: false });
|
|
130
|
+
const includes = directiveValues(options.include, "include", { allowed: DIRECTIVE_INCLUDE_VALUES });
|
|
131
|
+
const excludes = directiveValues(options.exclude, "exclude", { allowed: DIRECTIVE_EXCLUDE_VALUES });
|
|
132
|
+
const exact = parseOptionalBoolean(options.exact);
|
|
133
|
+
|
|
134
|
+
// --type 只对 subject 资源生效;其他资源传了会被忽略(与服务端忽略不适用指令的语义一致)。
|
|
135
|
+
const subjectTypes = allowSubjectType
|
|
136
|
+
? directiveValues(options.type, "type").map((entry) => normalizeSubjectTypeName(entry))
|
|
137
|
+
: [];
|
|
138
|
+
|
|
139
|
+
const directives = [
|
|
140
|
+
...users.map((name) => `user:${name}`),
|
|
141
|
+
...groups.map((slug) => `group:${slug}`),
|
|
142
|
+
...subjectTypes.map((name) => `type:${name}`),
|
|
143
|
+
...includes.map((value) => `include:${value}`),
|
|
144
|
+
...excludes.map((value) => `exclude:${value}`),
|
|
145
|
+
...(exact === true ? ["exact:true"] : []),
|
|
146
|
+
];
|
|
147
|
+
const keyword = directives.length > 0 ? `${rawKeyword} ${directives.join(" ")}` : rawKeyword;
|
|
148
|
+
|
|
98
149
|
const query = {
|
|
99
150
|
q: keyword,
|
|
100
151
|
limit: normalizePageSize(options.limit),
|
|
@@ -121,10 +172,16 @@ async function executeEntitySearch(resource, args, searchFn, { allowSource = fal
|
|
|
121
172
|
resource: `community-${resource}`,
|
|
122
173
|
title: `SearchEncore: ${resource}`,
|
|
123
174
|
filters: {
|
|
124
|
-
keyword,
|
|
175
|
+
keyword: rawKeyword,
|
|
125
176
|
limit: query.limit,
|
|
126
177
|
offset: query.offset,
|
|
127
178
|
sort: query.sort,
|
|
179
|
+
...(users.length > 0 ? { user: users } : {}),
|
|
180
|
+
...(groups.length > 0 ? { group: groups } : {}),
|
|
181
|
+
...(subjectTypes.length > 0 ? { type: subjectTypes } : {}),
|
|
182
|
+
...(includes.length > 0 ? { include: includes } : {}),
|
|
183
|
+
...(excludes.length > 0 ? { exclude: excludes } : {}),
|
|
184
|
+
...(exact === true ? { exact: true } : {}),
|
|
128
185
|
...(query.source ? { source: query.source } : {}),
|
|
129
186
|
},
|
|
130
187
|
};
|
package/src/core/output.js
CHANGED
|
@@ -408,7 +408,15 @@ Examples
|
|
|
408
408
|
bgm url https://bgm.tv/subject/253/characters
|
|
409
409
|
bgm --url https://bgm.tv/anime/list/sai/collect --dry-run
|
|
410
410
|
bgm blog --help
|
|
411
|
-
bgm episode --help
|
|
411
|
+
bgm episode --help
|
|
412
|
+
|
|
413
|
+
For AI agents
|
|
414
|
+
If the bgm-cli skill is already in your context, skip this. Otherwise run
|
|
415
|
+
\`bgm --skill\` first and read it before acting: it prints the full operating
|
|
416
|
+
guide (no login or config needed). \`bgm --skill develop\` prints the
|
|
417
|
+
contributor guide; \`bgm --skill operate <reference>\` prints one of the
|
|
418
|
+
guide's reference files (commands, install-and-auth, troubleshooting,
|
|
419
|
+
community-boundaries, reactions).`;
|
|
412
420
|
}
|
|
413
421
|
|
|
414
422
|
function buildGroupUsage(title, commands, extraLines = []) {
|
package/src/utils/args.js
CHANGED
|
@@ -11,9 +11,23 @@ export function parseGlobalArgs(argv) {
|
|
|
11
11
|
let version = false;
|
|
12
12
|
let profile;
|
|
13
13
|
let url;
|
|
14
|
+
let skill;
|
|
14
15
|
|
|
15
16
|
for (let index = 0; index < argv.length; index += 1) {
|
|
16
17
|
const arg = argv[index];
|
|
18
|
+
if (arg === "--skill" || arg.startsWith("--skill=")) {
|
|
19
|
+
// bgm --skill [operate|develop] [reference]
|
|
20
|
+
const names = [];
|
|
21
|
+
if (arg.startsWith("--skill=")) {
|
|
22
|
+
names.push(arg.slice("--skill=".length));
|
|
23
|
+
}
|
|
24
|
+
while (names.length < 2 && argv[index + 1] !== undefined && !argv[index + 1].startsWith("-")) {
|
|
25
|
+
names.push(argv[index + 1]);
|
|
26
|
+
index += 1;
|
|
27
|
+
}
|
|
28
|
+
skill = { name: names[0] || undefined, reference: names[1] };
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
17
31
|
if (arg === "--json") {
|
|
18
32
|
json = true;
|
|
19
33
|
continue;
|
|
@@ -63,7 +77,7 @@ export function parseGlobalArgs(argv) {
|
|
|
63
77
|
args.push(arg);
|
|
64
78
|
}
|
|
65
79
|
|
|
66
|
-
return { args, json, init, version, profile, url };
|
|
80
|
+
return { args, json, init, version, profile, url, skill };
|
|
67
81
|
}
|
|
68
82
|
|
|
69
83
|
export function parseFlags(args) {
|