@aronnaxlin/bgm-cli 1.1.3 → 1.1.5

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.
@@ -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) {
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { mkdir, readFile, writeFile } from "node:fs/promises";
6
+ import { APP_VERSION } from "../utils/version.js";
6
7
 
7
8
  export class ConfigError extends Error {
8
9
  constructor(message) {
@@ -23,7 +24,7 @@ const DEV_ENV_FILE = path.join(REPO_ROOT, "bgm-dev.env");
23
24
 
24
25
  const DEFAULT_CONFIG = {
25
26
  appName: "bgm-cli",
26
- appVersion: "1.0.2",
27
+ appVersion: APP_VERSION,
27
28
  homepageLink: "https://github.com/aronnaxlin/bgm-cli",
28
29
  developerId: "aronnaxlin",
29
30
  oauthServerBaseUrl: "https://oauth-backend-jet.vercel.app",
@@ -494,7 +495,7 @@ function normalizeUserAgent(config) {
494
495
  }
495
496
 
496
497
  const appName = config.appName ?? "bgm-cli";
497
- const version = config.appVersion ?? "1.0.0";
498
+ const version = config.appVersion ?? APP_VERSION;
498
499
  const genericValues = new Set([
499
500
  `${appName}/${version}`,
500
501
  `${appName}/0.1.0`,
@@ -504,17 +505,33 @@ function normalizeUserAgent(config) {
504
505
  "yourname/bgm-cli/0.1.0",
505
506
  ]);
506
507
 
507
- if ((genericValues.has(current) || current === legacyRecommended) && recommended) {
508
+ if ((genericValues.has(current) || current === legacyRecommended || isManagedUserAgent(current, config)) && recommended) {
508
509
  return recommended;
509
510
  }
510
511
 
511
512
  return current;
512
513
  }
513
514
 
515
+ // A User-Agent in the recommended format but carrying an older release's
516
+ // version is ours to refresh; anything else was customised by the user.
517
+ function isManagedUserAgent(current, config) {
518
+ const developerId = config.developerId ?? extractGithubUsername(config.homepageLink);
519
+ const appName = config.appName ?? "bgm-cli";
520
+ const prefix = developerId ? `${developerId}/${appName}/` : `${appName}/`;
521
+ const suffix = config.homepageLink ? ` (${config.homepageLink})` : "";
522
+
523
+ if (!current.startsWith(prefix) || !current.endsWith(suffix)) {
524
+ return false;
525
+ }
526
+
527
+ const version = current.slice(prefix.length, current.length - suffix.length);
528
+ return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version);
529
+ }
530
+
514
531
  function buildRecommendedUserAgent(config) {
515
532
  const developerId = config.developerId ?? extractGithubUsername(config.homepageLink);
516
533
  const appName = config.appName ?? "bgm-cli";
517
- const version = config.appVersion ?? "1.0.0";
534
+ const version = config.appVersion ?? APP_VERSION;
518
535
  const homepageLink = config.homepageLink;
519
536
 
520
537
  let userAgent = developerId ? `${developerId}/${appName}/${version}` : `${appName}/${version}`;
@@ -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) {
package/src/utils/auth.js CHANGED
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import { CommandError } from "../core/output.js";
6
+ import { APP_VERSION } from "./version.js";
6
7
 
7
8
  export function createState() {
8
9
  return `bgm-cli-${Date.now().toString(36)}`;
@@ -11,7 +12,7 @@ export function createState() {
11
12
  export function fallbackUserAgent(config) {
12
13
  const developerId = deriveDeveloperId(config);
13
14
  const appName = config.appName ?? "bgm-cli";
14
- const version = config.appVersion ?? "1.0.0";
15
+ const version = config.appVersion ?? APP_VERSION;
15
16
  const homepageLink = config.homepageLink;
16
17
 
17
18
  let userAgent = developerId
@@ -14,6 +14,7 @@ import {
14
14
  import { CommandError } from "../core/output.js";
15
15
  import { DEFAULT_TURNSTILE_TIMEOUT_MS } from "../core/turnstile.js";
16
16
  import { fallbackUserAgent } from "./auth.js";
17
+ import { APP_VERSION } from "./version.js";
17
18
 
18
19
  export function delayMs(ms) {
19
20
  return new Promise((resolve) => {
@@ -265,7 +266,7 @@ export function buildVersionStatusPayload(repoRoot) {
265
266
  return {
266
267
  resource: "version-status",
267
268
  name: config.appName ?? "bgm-cli",
268
- version: config.appVersion ?? "1.0.0",
269
+ version: config.appVersion ?? APP_VERSION,
269
270
  configScope: inferConfigScope(configFile, repoRoot),
270
271
  configFile,
271
272
  configSourceFile,
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Serves the bundled agent skills (skills/<name>/SKILL.md) verbatim, so an agent
3
+ * can read them from the CLI instead of relying on a copied or linked skill
4
+ * directory that may be missing or stale. Nothing here touches config or login.
5
+ */
6
+
7
+ import { readFileSync, readdirSync } from "node:fs";
8
+ import { CommandError } from "../core/output.js";
9
+
10
+ const SKILLS_DIR = new URL("../../skills/", import.meta.url);
11
+
12
+ export const DEFAULT_SKILL = "operate";
13
+
14
+ const SKILL_DIRS = {
15
+ operate: "bgm-cli-operate",
16
+ develop: "bgm-cli-develop",
17
+ };
18
+
19
+ function resolveSkillDir(name) {
20
+ const key = String(name).replace(/^bgm-cli-/, "");
21
+ const dir = SKILL_DIRS[key];
22
+ if (!dir) {
23
+ throw new CommandError(
24
+ `Unknown skill "${name}". Available: ${Object.keys(SKILL_DIRS).join(", ")}.`,
25
+ );
26
+ }
27
+ return dir;
28
+ }
29
+
30
+ function listReferences(dir) {
31
+ try {
32
+ return readdirSync(new URL(`${dir}/references/`, SKILLS_DIR))
33
+ .filter((file) => file.endsWith(".md"))
34
+ .map((file) => file.slice(0, -3))
35
+ .sort();
36
+ } catch {
37
+ return [];
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Return the raw text of a skill's SKILL.md, or of one of its references/*.md
43
+ * when `reference` is given (with or without the .md suffix).
44
+ */
45
+ export function readSkill(name = DEFAULT_SKILL, reference) {
46
+ const dir = resolveSkillDir(name);
47
+
48
+ if (reference === undefined) {
49
+ return readFileSync(new URL(`${dir}/SKILL.md`, SKILLS_DIR), "utf8");
50
+ }
51
+
52
+ const ref = String(reference).replace(/\.md$/, "");
53
+ const available = listReferences(dir);
54
+ if (!available.includes(ref)) {
55
+ const hint = available.length > 0 ? `Available: ${available.join(", ")}.` : "This skill has no references.";
56
+ throw new CommandError(`Unknown reference "${reference}" for skill "${name}". ${hint}`);
57
+ }
58
+ return readFileSync(new URL(`${dir}/references/${ref}.md`, SKILLS_DIR), "utf8");
59
+ }