@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.
@@ -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
+ }
@@ -38,6 +38,10 @@ export const SUBJECT_TYPE_MAP = {
38
38
  real: 6,
39
39
  };
40
40
 
41
+ const SUBJECT_TYPE_NAME_MAP = Object.fromEntries(
42
+ Object.entries(SUBJECT_TYPE_MAP).map(([name, id]) => [id, name]),
43
+ );
44
+
41
45
  export const COLLECTION_STATUS_MAP = {
42
46
  wish: 1,
43
47
  collect: 2,
@@ -140,6 +144,19 @@ export function normalizeSubjectType(value) {
140
144
  return normalized;
141
145
  }
142
146
 
147
+ /**
148
+ * 归一化为规范的小写类型名(book|anime|music|game|real),
149
+ * 供需要字符串类型名而非数字 ID 的场景使用(如 SearchEncore 的 `type:` 指令)。
150
+ */
151
+ export function normalizeSubjectTypeName(value) {
152
+ const numeric = normalizeSubjectType(value);
153
+ if (numeric === undefined) {
154
+ return undefined;
155
+ }
156
+
157
+ return SUBJECT_TYPE_NAME_MAP[numeric];
158
+ }
159
+
143
160
  export function normalizeSubjectTypeFilter(value) {
144
161
  if (value === undefined || value === null || value === "") {
145
162
  return [];