@bitget-ai/bitget-agent-skill 3.4.1 → 4.0.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.
- package/CHANGELOG.md +34 -0
- package/README.md +110 -123
- package/VERSION +1 -1
- package/package.json +7 -11
- package/scripts/install.js +123 -130
- package/scripts/validate-skills.mjs +240 -0
- package/skills/bitget-agentic/SKILL.md +122 -0
- package/skills/bitget-agentic/references/authorization.md +95 -0
- package/skills/bitget-agentic/references/first-time-setup.md +85 -0
- package/skills/bitget-agentic/references/legacy-migration.md +38 -0
- package/skills/bitget-agentic/references/troubleshooting.md +34 -0
- package/references/auth-setup.md +0 -54
- package/references/commands.md +0 -2387
- package/references/demo-trading.md +0 -58
- package/references/discover-guide.md +0 -112
- package/references/error-codes.md +0 -118
- package/references/trading-safety.md +0 -163
- package/scripts/gen-references.js +0 -266
- package/skills/agentic/SKILL.md +0 -345
- package/skills/agentic-connect/SKILL.md +0 -146
- package/skills/uta/SKILL.md +0 -189
package/scripts/install.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Bitget Skill Installer
|
|
3
|
+
* Bitget Agentic Skill Installer
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* npx bitget-agent-skill
|
|
10
|
-
* npx bitget-agent-skill --target
|
|
11
|
-
* npx bitget-agent-skill --target
|
|
12
|
-
* npx bitget-agent-skill --
|
|
13
|
-
* npx bitget-agent-skill --skill agentic # install the Agentic (OAuth) skill instead
|
|
14
|
-
* npx bitget-agent-skill --skill agentic-connect # first-time cloud MCP connect guide
|
|
15
|
-
* npx bitget-agent-skill --skill uta,agentic # install both skills
|
|
16
|
-
* npx bitget-agent-skill --skill all # install all skills
|
|
5
|
+
* Copies the `bitget-agentic` skill directory (SKILL.md and its references/)
|
|
6
|
+
* into an AI tool's skills directory. No runtime, no API keys, no network access.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* npx @bitget-ai/bitget-agent-skill # Claude Code
|
|
10
|
+
* npx @bitget-ai/bitget-agent-skill --target all # every supported tool
|
|
11
|
+
* npx @bitget-ai/bitget-agent-skill --target codex,cursor # specific tools
|
|
12
|
+
* npx @bitget-ai/bitget-agent-skill --interactive # prompt to choose
|
|
17
13
|
*/
|
|
18
14
|
|
|
19
|
-
import {
|
|
15
|
+
import { cpSync, mkdirSync, existsSync, rmSync } from "node:fs";
|
|
20
16
|
import { join, dirname } from "node:path";
|
|
21
17
|
import { fileURLToPath } from "node:url";
|
|
22
18
|
import { homedir } from "node:os";
|
|
@@ -26,37 +22,12 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
26
22
|
const PKG_ROOT = join(__dirname, "..");
|
|
27
23
|
const HOME = homedir();
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
uta: {
|
|
33
|
-
label: "UTA trading (manual API key)",
|
|
34
|
-
skillSrcDir: join(PKG_ROOT, "skills", "uta"),
|
|
35
|
-
skillDirName: "bitget-agent-skill",
|
|
36
|
-
refFiles: [
|
|
37
|
-
"commands.md",
|
|
38
|
-
"discover-guide.md",
|
|
39
|
-
"trading-safety.md",
|
|
40
|
-
"error-codes.md",
|
|
41
|
-
"auth-setup.md",
|
|
42
|
-
"demo-trading.md",
|
|
43
|
-
],
|
|
44
|
-
},
|
|
45
|
-
agentic: {
|
|
46
|
-
label: "Agentic sub-account (OAuth)",
|
|
47
|
-
skillSrcDir: join(PKG_ROOT, "skills", "agentic"),
|
|
48
|
-
skillDirName: "bitget-agentic",
|
|
49
|
-
refFiles: [],
|
|
50
|
-
},
|
|
51
|
-
"agentic-connect": {
|
|
52
|
-
label: "Agentic first-time MCP connect guide",
|
|
53
|
-
skillSrcDir: join(PKG_ROOT, "skills", "agentic-connect"),
|
|
54
|
-
skillDirName: "bitget-agentic-connect",
|
|
55
|
-
refFiles: [],
|
|
56
|
-
},
|
|
57
|
-
};
|
|
25
|
+
const SKILL_NAME = "bitget-agentic";
|
|
26
|
+
const SKILL_SRC_DIR = join(PKG_ROOT, "skills", SKILL_NAME);
|
|
27
|
+
const DEFAULT_TARGET = "claude";
|
|
58
28
|
|
|
59
|
-
// Skill destinations per AI tool
|
|
29
|
+
// Skill destinations per AI tool. Codex reads user skills from ~/.agents/skills,
|
|
30
|
+
// a location Cursor and OpenClaw also read.
|
|
60
31
|
const TARGETS = {
|
|
61
32
|
claude: {
|
|
62
33
|
label: "Claude Code",
|
|
@@ -64,7 +35,14 @@ const TARGETS = {
|
|
|
64
35
|
},
|
|
65
36
|
codex: {
|
|
66
37
|
label: "Codex",
|
|
67
|
-
skillsRoot: join(HOME, ".
|
|
38
|
+
skillsRoot: join(HOME, ".agents", "skills"),
|
|
39
|
+
// Older Codex versions read ~/.codex/skills. Refresh a copy that an earlier
|
|
40
|
+
// version of this installer put there, so it does not go stale.
|
|
41
|
+
legacySkillsRoot: join(HOME, ".codex", "skills"),
|
|
42
|
+
},
|
|
43
|
+
cursor: {
|
|
44
|
+
label: "Cursor",
|
|
45
|
+
skillsRoot: join(HOME, ".cursor", "skills"),
|
|
68
46
|
},
|
|
69
47
|
openclaw: {
|
|
70
48
|
label: "OpenClaw",
|
|
@@ -72,34 +50,52 @@ const TARGETS = {
|
|
|
72
50
|
},
|
|
73
51
|
};
|
|
74
52
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
53
|
+
// Skill folders installed by earlier versions that this version replaces.
|
|
54
|
+
// They are reported, never deleted: they live in the user's own directory.
|
|
55
|
+
const OBSOLETE_SKILL_DIRS = {
|
|
56
|
+
"bitget-agent-skill":
|
|
57
|
+
"the old local API-key skill (bgc). It is discontinued and can conflict with this one",
|
|
58
|
+
"bitget-agentic-connect":
|
|
59
|
+
"the old first-time connect guide. It is now part of bitget-agentic and its copy is out of date",
|
|
60
|
+
};
|
|
80
61
|
|
|
81
|
-
|
|
62
|
+
function copySkill(skillsRoot) {
|
|
63
|
+
const dest = join(skillsRoot, SKILL_NAME);
|
|
64
|
+
mkdirSync(skillsRoot, { recursive: true });
|
|
65
|
+
// Replace the whole folder so files removed in a newer version do not linger.
|
|
66
|
+
rmSync(dest, { recursive: true, force: true });
|
|
67
|
+
cpSync(SKILL_SRC_DIR, dest, { recursive: true });
|
|
68
|
+
return dest;
|
|
69
|
+
}
|
|
82
70
|
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
function installTo(targetKey) {
|
|
72
|
+
const target = TARGETS[targetKey];
|
|
73
|
+
const dest = copySkill(target.skillsRoot);
|
|
74
|
+
console.log(` ✓ ${target.label} → ${join(dest, "SKILL.md")}`);
|
|
85
75
|
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
if (target.legacySkillsRoot && existsSync(join(target.legacySkillsRoot, SKILL_NAME))) {
|
|
77
|
+
const legacyDest = copySkill(target.legacySkillsRoot);
|
|
78
|
+
console.log(` ✓ ${target.label} (older location) → ${join(legacyDest, "SKILL.md")}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function reportObsolete(targetKey) {
|
|
83
|
+
const target = TARGETS[targetKey];
|
|
84
|
+
const roots = [target.skillsRoot, target.legacySkillsRoot].filter(Boolean);
|
|
85
|
+
for (const root of roots) {
|
|
86
|
+
for (const [dirName, why] of Object.entries(OBSOLETE_SKILL_DIRS)) {
|
|
87
|
+
const dir = join(root, dirName);
|
|
88
|
+
if (existsSync(dir)) {
|
|
89
|
+
console.log(`\nNote: ${dir} is ${why}. Remove that directory.`);
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
console.log(` ✓ ${target.label} (${skill.label}) → ${join(skillDir, "SKILL.md")}`);
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
async function promptTargets() {
|
|
100
96
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
101
97
|
|
|
102
|
-
console.log("\nBitget
|
|
98
|
+
console.log("\nBitget Agentic skill — choose installation targets:\n");
|
|
103
99
|
const keys = Object.keys(TARGETS);
|
|
104
100
|
keys.forEach((k, i) => {
|
|
105
101
|
console.log(` ${i + 1}. ${TARGETS[k].label} (${TARGETS[k].skillsRoot})`);
|
|
@@ -108,105 +104,102 @@ async function promptTargets() {
|
|
|
108
104
|
console.log();
|
|
109
105
|
|
|
110
106
|
return new Promise((resolve) => {
|
|
111
|
-
rl.question(
|
|
112
|
-
|
|
113
|
-
(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
resolve(["claude"]);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (trimmed === String(keys.length + 1)) {
|
|
121
|
-
resolve(keys);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const selected = trimmed
|
|
125
|
-
.split(",")
|
|
126
|
-
.map((s) => parseInt(s.trim(), 10) - 1)
|
|
127
|
-
.filter((i) => i >= 0 && i < keys.length)
|
|
128
|
-
.map((i) => keys[i]);
|
|
129
|
-
resolve(selected.length > 0 ? selected : ["claude"]);
|
|
107
|
+
rl.question(`Enter numbers separated by commas [default: 1]: `, (answer) => {
|
|
108
|
+
rl.close();
|
|
109
|
+
const trimmed = answer.trim();
|
|
110
|
+
if (!trimmed || trimmed === "1") {
|
|
111
|
+
resolve([DEFAULT_TARGET]);
|
|
112
|
+
return;
|
|
130
113
|
}
|
|
131
|
-
|
|
114
|
+
if (trimmed === String(keys.length + 1)) {
|
|
115
|
+
resolve(keys);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const selected = trimmed
|
|
119
|
+
.split(",")
|
|
120
|
+
.map((s) => parseInt(s.trim(), 10) - 1)
|
|
121
|
+
.filter((i) => i >= 0 && i < keys.length)
|
|
122
|
+
.map((i) => keys[i]);
|
|
123
|
+
resolve(selected.length > 0 ? selected : [DEFAULT_TARGET]);
|
|
124
|
+
});
|
|
132
125
|
});
|
|
133
126
|
}
|
|
134
127
|
|
|
135
|
-
function
|
|
128
|
+
function flagValue(args, name) {
|
|
136
129
|
const arg = args.find((a) => a.startsWith(`--${name}=`) || a === `--${name}`);
|
|
137
130
|
if (!arg) return null;
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
return arg === `--${name}` ? args[args.indexOf(`--${name}`) + 1] || null : arg.split("=")[1] || null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function parseTargets(args) {
|
|
135
|
+
const value = flagValue(args, "target");
|
|
140
136
|
if (!value) return null;
|
|
141
|
-
if (value === "all") return Object.keys(
|
|
137
|
+
if (value === "all") return Object.keys(TARGETS);
|
|
142
138
|
const keys = value
|
|
143
139
|
.split(",")
|
|
144
140
|
.map((s) => s.trim())
|
|
145
|
-
.filter((k) => k in
|
|
141
|
+
.filter((k) => k in TARGETS);
|
|
146
142
|
if (keys.length === 0) {
|
|
143
|
+
console.warn(`Unknown target(s): ${value}. Valid: ${Object.keys(TARGETS).join(", ")}, all`);
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
return keys;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// --skill is no longer needed: the package ships one skill. It is still
|
|
150
|
+
// accepted so that commands from older guides keep working.
|
|
151
|
+
function handleDeprecatedSkillFlag(args) {
|
|
152
|
+
const value = flagValue(args, "skill");
|
|
153
|
+
if (!value) return;
|
|
154
|
+
const requested = value.split(",").map((s) => s.trim());
|
|
155
|
+
if (requested.includes("uta")) {
|
|
147
156
|
console.warn(
|
|
148
|
-
|
|
157
|
+
"The local API-key skill (uta, driven by the bgc CLI) was removed in 4.0.0 and is " +
|
|
158
|
+
"no longer supported. Run again without --skill to install the cloud MCP skill."
|
|
149
159
|
);
|
|
150
160
|
process.exit(1);
|
|
151
161
|
}
|
|
152
|
-
|
|
162
|
+
console.log(`Note: --skill is no longer needed and is ignored; installing ${SKILL_NAME}.`);
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
async function main() {
|
|
156
166
|
const args = process.argv.slice(2);
|
|
157
|
-
|
|
158
|
-
const targetValue = parseListFlag(args, "target", TARGETS);
|
|
159
|
-
const skillValue = parseListFlag(args, "skill", SKILLS);
|
|
160
|
-
|
|
161
|
-
let selectedTargetKeys;
|
|
162
|
-
const selectedSkillKeys = skillValue || ["uta"];
|
|
167
|
+
handleDeprecatedSkillFlag(args);
|
|
163
168
|
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
let targetKeys;
|
|
170
|
+
if (args.includes("--interactive")) {
|
|
166
171
|
try {
|
|
167
|
-
|
|
172
|
+
targetKeys = await promptTargets();
|
|
168
173
|
} catch {
|
|
169
|
-
|
|
174
|
+
targetKeys = [DEFAULT_TARGET];
|
|
170
175
|
}
|
|
171
|
-
} else if (targetValue) {
|
|
172
|
-
selectedTargetKeys = targetValue;
|
|
173
176
|
} else {
|
|
174
|
-
|
|
175
|
-
try {
|
|
176
|
-
installTo("claude", "uta");
|
|
177
|
-
} catch (err) {
|
|
178
|
-
console.warn("Could not auto-install skill:", err.message);
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
177
|
+
targetKeys = parseTargets(args) || [DEFAULT_TARGET];
|
|
181
178
|
}
|
|
182
179
|
|
|
183
|
-
console.log("\nInstalling Bitget skill...");
|
|
180
|
+
console.log("\nInstalling the Bitget Agentic skill...");
|
|
184
181
|
let ok = 0;
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
} catch (err) {
|
|
192
|
-
console.warn(` ✗ ${TARGETS[targetKey].label} (${SKILLS[skillKey].label}): ${err.message}`);
|
|
193
|
-
}
|
|
182
|
+
for (const targetKey of targetKeys) {
|
|
183
|
+
try {
|
|
184
|
+
installTo(targetKey);
|
|
185
|
+
ok++;
|
|
186
|
+
} catch (err) {
|
|
187
|
+
console.warn(` ✗ ${TARGETS[targetKey].label}: ${err.message}`);
|
|
194
188
|
}
|
|
195
189
|
}
|
|
196
|
-
console.log(`\nDone — installed ${ok} of ${
|
|
190
|
+
console.log(`\nDone — installed to ${ok} of ${targetKeys.length} target(s).`);
|
|
197
191
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
if (selectedTargetKeys.includes("codex")) {
|
|
205
|
-
console.log("\nCodex: skill will be loaded automatically from ~/.codex/skills/");
|
|
206
|
-
}
|
|
207
|
-
if (selectedTargetKeys.includes("openclaw")) {
|
|
208
|
-
console.log("\nOpenClaw: skill will be loaded automatically from ~/.openclaw/skills/");
|
|
192
|
+
for (const targetKey of targetKeys) reportObsolete(targetKey);
|
|
193
|
+
|
|
194
|
+
if (targetKeys.includes("claude")) {
|
|
195
|
+
console.log("\nClaude Code: restart Claude Code to pick up the skill.");
|
|
209
196
|
}
|
|
197
|
+
console.log(
|
|
198
|
+
"\nNext: ask your AI agent to read the installed SKILL.md and connect " +
|
|
199
|
+
"https://agent.bitget.com/mcp."
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
if (ok < targetKeys.length) process.exit(1);
|
|
210
203
|
}
|
|
211
204
|
|
|
212
205
|
main();
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Validates every skill under skills/ against the Agent Skills specification
|
|
4
|
+
* (https://agentskills.io/specification) and the authoring limits this repo
|
|
5
|
+
* holds itself to. Exits non-zero on any error, so it can gate build and publish.
|
|
6
|
+
*
|
|
7
|
+
* Usage: node scripts/validate-skills.mjs
|
|
8
|
+
*
|
|
9
|
+
* The frontmatter parser is deliberately small: it accepts only top-level
|
|
10
|
+
* `key: value`, folded `key: >` blocks, and one flat `metadata:` map of quoted
|
|
11
|
+
* strings. Anything else is reported, which is how the "metadata is a map of
|
|
12
|
+
* string keys to string values" rule is enforced.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readFileSync, readdirSync, existsSync, statSync } from "node:fs";
|
|
16
|
+
import { join, dirname, relative, resolve, sep } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
|
|
19
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
20
|
+
const SKILLS_DIR = join(ROOT, "skills");
|
|
21
|
+
|
|
22
|
+
// Fields accepted by every Agent Skills host. Host-specific fields would make
|
|
23
|
+
// the skill fail to load elsewhere.
|
|
24
|
+
const ALLOWED_KEYS = new Set([
|
|
25
|
+
"name",
|
|
26
|
+
"description",
|
|
27
|
+
"license",
|
|
28
|
+
"compatibility",
|
|
29
|
+
"metadata",
|
|
30
|
+
"allowed-tools",
|
|
31
|
+
]);
|
|
32
|
+
const NAME_MAX = 64;
|
|
33
|
+
const DESCRIPTION_MAX = 1024;
|
|
34
|
+
const COMPATIBILITY_MAX = 500;
|
|
35
|
+
const BODY_MAX_LINES = 500;
|
|
36
|
+
// The spec recommends under 5000 tokens. Roughly 4 characters per token.
|
|
37
|
+
const BODY_MAX_TOKENS = 5000;
|
|
38
|
+
const CHARS_PER_TOKEN = 4;
|
|
39
|
+
// Reference files longer than this need a contents list at the top.
|
|
40
|
+
const REFERENCE_TOC_LINES = 100;
|
|
41
|
+
const RESERVED_NAME_WORDS = ["anthropic", "claude"];
|
|
42
|
+
|
|
43
|
+
function unquote(value) {
|
|
44
|
+
const v = value.trim();
|
|
45
|
+
if (v.length >= 2 && (v[0] === '"' || v[0] === "'") && v[v.length - 1] === v[0]) {
|
|
46
|
+
return { text: v.slice(1, -1), quoted: true };
|
|
47
|
+
}
|
|
48
|
+
return { text: v, quoted: false };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function parseFrontmatter(source, errors) {
|
|
52
|
+
if (!source.startsWith("---\n")) {
|
|
53
|
+
errors.push("SKILL.md must start with a `---` frontmatter line");
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const end = source.indexOf("\n---", 4);
|
|
57
|
+
if (end === -1) {
|
|
58
|
+
errors.push("frontmatter is not closed with `---`");
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const lines = source.slice(4, end).split("\n");
|
|
62
|
+
const body = source.slice(end + 4).replace(/^\n/, "");
|
|
63
|
+
const fields = {};
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < lines.length; i++) {
|
|
66
|
+
const line = lines[i];
|
|
67
|
+
if (!line.trim()) continue;
|
|
68
|
+
const top = /^([A-Za-z][\w-]*):(.*)$/.exec(line);
|
|
69
|
+
if (!top) {
|
|
70
|
+
errors.push(`frontmatter line ${i + 2} is not a top-level \`key: value\`: ${line.trim()}`);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const [, key, rest] = top;
|
|
74
|
+
const value = rest.trim();
|
|
75
|
+
|
|
76
|
+
const collectIndented = () => {
|
|
77
|
+
const block = [];
|
|
78
|
+
while (i + 1 < lines.length && (/^\s+\S/.test(lines[i + 1]) || !lines[i + 1].trim())) {
|
|
79
|
+
block.push(lines[++i]);
|
|
80
|
+
}
|
|
81
|
+
return block;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
if (value === ">" || value === ">-" || value === "|" || value === "|-") {
|
|
85
|
+
const block = collectIndented().map((l) => l.trim());
|
|
86
|
+
fields[key] = value.startsWith(">") ? block.filter(Boolean).join(" ") : block.join("\n");
|
|
87
|
+
} else if (value === "") {
|
|
88
|
+
const map = {};
|
|
89
|
+
for (const entry of collectIndented()) {
|
|
90
|
+
if (!entry.trim()) continue;
|
|
91
|
+
const m = /^ {2}([A-Za-z][\w-]*):\s*(.+)$/.exec(entry);
|
|
92
|
+
if (!m) {
|
|
93
|
+
errors.push(`\`${key}\` must be a flat map of \`key: "string"\` pairs; found: ${entry.trim()}`);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const { text, quoted } = unquote(m[2]);
|
|
97
|
+
if (!quoted) {
|
|
98
|
+
errors.push(`\`${key}.${m[1]}\` must be a quoted string so YAML cannot read it as a number or date`);
|
|
99
|
+
}
|
|
100
|
+
map[m[1]] = text;
|
|
101
|
+
}
|
|
102
|
+
fields[key] = map;
|
|
103
|
+
} else {
|
|
104
|
+
fields[key] = unquote(value).text;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { fields, body };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function validateSkill(dirName) {
|
|
111
|
+
const errors = [];
|
|
112
|
+
const skillDir = join(SKILLS_DIR, dirName);
|
|
113
|
+
const skillFile = join(skillDir, "SKILL.md");
|
|
114
|
+
if (!existsSync(skillFile)) {
|
|
115
|
+
return [`missing SKILL.md`];
|
|
116
|
+
}
|
|
117
|
+
const source = readFileSync(skillFile, "utf8");
|
|
118
|
+
const parsed = parseFrontmatter(source, errors);
|
|
119
|
+
if (!parsed) return errors;
|
|
120
|
+
const { fields, body } = parsed;
|
|
121
|
+
|
|
122
|
+
for (const key of Object.keys(fields)) {
|
|
123
|
+
if (!ALLOWED_KEYS.has(key)) {
|
|
124
|
+
errors.push(`frontmatter field \`${key}\` is not in the Agent Skills spec (${[...ALLOWED_KEYS].join(", ")})`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// name
|
|
129
|
+
const name = fields.name;
|
|
130
|
+
if (typeof name !== "string" || !name) {
|
|
131
|
+
errors.push("`name` is required");
|
|
132
|
+
} else {
|
|
133
|
+
if (name.length > NAME_MAX) errors.push(`\`name\` is ${name.length} characters (max ${NAME_MAX})`);
|
|
134
|
+
if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(name)) {
|
|
135
|
+
errors.push("`name` may contain only lowercase letters, digits, and single hyphens, and cannot start or end with a hyphen");
|
|
136
|
+
}
|
|
137
|
+
if (name !== dirName) errors.push(`\`name\` (${name}) must match the directory name (${dirName})`);
|
|
138
|
+
for (const word of RESERVED_NAME_WORDS) {
|
|
139
|
+
if (name.includes(word)) errors.push(`\`name\` cannot contain the reserved word "${word}"`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// description
|
|
144
|
+
const description = fields.description;
|
|
145
|
+
if (typeof description !== "string" || !description) {
|
|
146
|
+
errors.push("`description` is required");
|
|
147
|
+
} else {
|
|
148
|
+
if (description.length > DESCRIPTION_MAX) {
|
|
149
|
+
errors.push(`\`description\` is ${description.length} characters (max ${DESCRIPTION_MAX})`);
|
|
150
|
+
}
|
|
151
|
+
if (/[<>]/.test(description)) errors.push("`description` cannot contain `<` or `>`");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (typeof fields.compatibility === "string" && fields.compatibility.length > COMPATIBILITY_MAX) {
|
|
155
|
+
errors.push(`\`compatibility\` is ${fields.compatibility.length} characters (max ${COMPATIBILITY_MAX})`);
|
|
156
|
+
}
|
|
157
|
+
if ("metadata" in fields && (typeof fields.metadata !== "object" || fields.metadata === null)) {
|
|
158
|
+
errors.push("`metadata` must be a map of string keys to string values");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// body size
|
|
162
|
+
const bodyLines = body.split("\n").length;
|
|
163
|
+
const bodyTokens = Math.ceil(body.length / CHARS_PER_TOKEN);
|
|
164
|
+
if (bodyLines > BODY_MAX_LINES) errors.push(`SKILL.md body is ${bodyLines} lines (max ${BODY_MAX_LINES})`);
|
|
165
|
+
if (bodyTokens > BODY_MAX_TOKENS) {
|
|
166
|
+
errors.push(`SKILL.md body is about ${bodyTokens} tokens (max ${BODY_MAX_TOKENS}); move detail into references/`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// links from SKILL.md: relative, forward slashes, inside the skill, existing
|
|
170
|
+
const linked = new Set();
|
|
171
|
+
for (const m of body.matchAll(/\]\(([^)\s]+)\)/g)) {
|
|
172
|
+
const target = m[1].split("#")[0];
|
|
173
|
+
if (!target || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue; // external or anchor
|
|
174
|
+
if (target.includes("\\")) errors.push(`link \`${target}\` uses a backslash; use forward slashes`);
|
|
175
|
+
const abs = resolve(skillDir, target);
|
|
176
|
+
if (abs !== skillDir && !abs.startsWith(skillDir + sep)) {
|
|
177
|
+
errors.push(`link \`${target}\` points outside the skill directory`);
|
|
178
|
+
} else if (!existsSync(abs)) {
|
|
179
|
+
errors.push(`link \`${target}\` does not resolve to a file`);
|
|
180
|
+
} else {
|
|
181
|
+
linked.add(abs);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// every reference file is reachable from SKILL.md (one level deep)
|
|
186
|
+
const refsDir = join(skillDir, "references");
|
|
187
|
+
if (existsSync(refsDir)) {
|
|
188
|
+
for (const entry of readdirSync(refsDir)) {
|
|
189
|
+
const abs = join(refsDir, entry);
|
|
190
|
+
if (statSync(abs).isDirectory()) {
|
|
191
|
+
errors.push(`references/${entry}/ is nested; keep reference files one level deep`);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const rel = relative(skillDir, abs).split(sep).join("/");
|
|
195
|
+
if (!linked.has(abs)) errors.push(`${rel} is not linked from SKILL.md, so an agent cannot discover it`);
|
|
196
|
+
const text = readFileSync(abs, "utf8");
|
|
197
|
+
if (text.split("\n").length > REFERENCE_TOC_LINES && !/^## Contents\s*$/m.test(text)) {
|
|
198
|
+
errors.push(`${rel} is over ${REFERENCE_TOC_LINES} lines and needs a "## Contents" list at the top`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!errors.length) {
|
|
204
|
+
console.log(
|
|
205
|
+
` ✓ ${dirName}: description ${description.length}/${DESCRIPTION_MAX} chars, ` +
|
|
206
|
+
`body ${bodyLines} lines, about ${bodyTokens} tokens`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
return errors;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function main() {
|
|
213
|
+
if (!existsSync(SKILLS_DIR)) {
|
|
214
|
+
console.error("skills/ directory not found");
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
const dirs = readdirSync(SKILLS_DIR).filter((d) => statSync(join(SKILLS_DIR, d)).isDirectory());
|
|
218
|
+
if (dirs.length === 0) {
|
|
219
|
+
console.error("no skills found under skills/");
|
|
220
|
+
process.exit(1);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
console.log("Validating skills against the Agent Skills specification...");
|
|
224
|
+
let failed = 0;
|
|
225
|
+
for (const dir of dirs) {
|
|
226
|
+
const errors = validateSkill(dir);
|
|
227
|
+
if (errors.length) {
|
|
228
|
+
failed++;
|
|
229
|
+
console.error(` ✗ ${dir}`);
|
|
230
|
+
for (const e of errors) console.error(` - ${e}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (failed) {
|
|
234
|
+
console.error(`\n${failed} of ${dirs.length} skill(s) failed validation.`);
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
console.log(`\nAll ${dirs.length} skill(s) are valid.`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
main();
|