@agentskillkit/agent-skills 3.2.2 → 3.2.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.
Files changed (51) hide show
  1. package/.agent/skills/mobile-design/scripts/mobile_audit.js +333 -0
  2. package/.agent/skills/typescript-expert/scripts/ts_diagnostic.js +227 -0
  3. package/README.md +197 -720
  4. package/package.json +4 -4
  5. package/packages/cli/lib/audit.js +2 -2
  6. package/packages/cli/lib/auto-learn.js +8 -8
  7. package/packages/cli/lib/eslint-fix.js +1 -1
  8. package/packages/cli/lib/fix.js +5 -5
  9. package/packages/cli/lib/hooks/install-hooks.js +4 -4
  10. package/packages/cli/lib/hooks/lint-learn.js +4 -4
  11. package/packages/cli/lib/knowledge-index.js +4 -4
  12. package/packages/cli/lib/knowledge-metrics.js +2 -2
  13. package/packages/cli/lib/knowledge-retention.js +3 -3
  14. package/packages/cli/lib/knowledge-validator.js +3 -3
  15. package/packages/cli/lib/learn.js +10 -10
  16. package/packages/cli/lib/recall.js +1 -1
  17. package/packages/cli/lib/skill-learn.js +2 -2
  18. package/packages/cli/lib/stats.js +3 -3
  19. package/packages/cli/lib/ui/dashboard-ui.js +222 -0
  20. package/packages/cli/lib/ui/help-ui.js +41 -18
  21. package/packages/cli/lib/ui/index.js +57 -5
  22. package/packages/cli/lib/ui/settings-ui.js +292 -14
  23. package/packages/cli/lib/ui/stats-ui.js +93 -43
  24. package/packages/cli/lib/watcher.js +2 -2
  25. package/packages/kit/kit.js +89 -0
  26. package/packages/kit/lib/agents.js +208 -0
  27. package/packages/kit/lib/commands/analyze.js +70 -0
  28. package/packages/kit/lib/commands/cache.js +65 -0
  29. package/packages/kit/lib/commands/doctor.js +75 -0
  30. package/packages/kit/lib/commands/help.js +155 -0
  31. package/packages/kit/lib/commands/info.js +38 -0
  32. package/packages/kit/lib/commands/init.js +39 -0
  33. package/packages/kit/lib/commands/install.js +803 -0
  34. package/packages/kit/lib/commands/list.js +43 -0
  35. package/packages/kit/lib/commands/lock.js +57 -0
  36. package/packages/kit/lib/commands/uninstall.js +307 -0
  37. package/packages/kit/lib/commands/update.js +55 -0
  38. package/packages/kit/lib/commands/validate.js +69 -0
  39. package/packages/kit/lib/commands/verify.js +56 -0
  40. package/packages/kit/lib/config.js +81 -0
  41. package/packages/kit/lib/helpers.js +196 -0
  42. package/packages/kit/lib/helpers.test.js +60 -0
  43. package/packages/kit/lib/installer.js +164 -0
  44. package/packages/kit/lib/skills.js +119 -0
  45. package/packages/kit/lib/skills.test.js +109 -0
  46. package/packages/kit/lib/types.js +82 -0
  47. package/packages/kit/lib/ui.js +329 -0
  48. package/.agent/skills/mobile-design/scripts/mobile_audit.py +0 -670
  49. package/.agent/skills/requirements-python.txt +0 -25
  50. package/.agent/skills/requirements.txt +0 -96
  51. package/.agent/skills/typescript-expert/scripts/ts_diagnostic.py +0 -203
@@ -0,0 +1,196 @@
1
+ /**
2
+ * @fileoverview Utility helper functions
3
+ */
4
+
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import crypto from "crypto";
8
+ import { BACKUP_DIR, DRY, cwd, GLOBAL, WORKSPACE, GLOBAL_DIR, REGISTRIES_FILE } from "./config.js";
9
+
10
+ /**
11
+ * Get directory size recursively
12
+ * @param {string} dir - Directory path
13
+ * @returns {number} Size in bytes
14
+ */
15
+ export function getDirSize(dir) {
16
+ let size = 0;
17
+ try {
18
+ const walk = (p) => {
19
+ for (const f of fs.readdirSync(p)) {
20
+ const full = path.join(p, f);
21
+ const stat = fs.statSync(full);
22
+ if (stat.isDirectory()) walk(full);
23
+ else size += stat.size;
24
+ }
25
+ };
26
+ walk(dir);
27
+ } catch (err) {
28
+ // Directory may not exist or be inaccessible
29
+ if (process.env.DEBUG) console.error(`getDirSize error: ${err.message}`);
30
+ }
31
+ return size;
32
+ }
33
+
34
+ /**
35
+ * Format bytes to human readable
36
+ * @param {number} bytes
37
+ * @returns {string}
38
+ */
39
+ export function formatBytes(bytes) {
40
+ if (bytes < 1024) return bytes + " B";
41
+ if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB";
42
+ return (bytes / 1024 / 1024).toFixed(1) + " MB";
43
+ }
44
+
45
+ /**
46
+ * Format ISO date string
47
+ * @param {string} [iso]
48
+ * @returns {string}
49
+ */
50
+ export function formatDate(iso) {
51
+ return iso ? new Date(iso).toLocaleDateString() : "unknown";
52
+ }
53
+
54
+ /**
55
+ * Calculate merkle hash of directory
56
+ * @param {string} dir - Directory path
57
+ * @returns {string} SHA256 hash
58
+ */
59
+ export function merkleHash(dir) {
60
+ const files = [];
61
+ const walk = (p) => {
62
+ for (const f of fs.readdirSync(p)) {
63
+ if (f === ".skill-source.json") continue;
64
+ const full = path.join(p, f);
65
+ const stat = fs.statSync(full);
66
+ if (stat.isDirectory()) walk(full);
67
+ else {
68
+ const h = crypto.createHash("sha256").update(fs.readFileSync(full)).digest("hex");
69
+ files.push(`${path.relative(dir, full)}:${h}`);
70
+ }
71
+ }
72
+ };
73
+ walk(dir);
74
+ files.sort();
75
+ return crypto.createHash("sha256").update(files.join("|")).digest("hex");
76
+ }
77
+
78
+ /**
79
+ * Parse skill spec string
80
+ * @param {string} spec - Spec like org/repo#skill@ref
81
+ * @returns {import('./types.js').ParsedSpec}
82
+ */
83
+ export function parseSkillSpec(spec) {
84
+ if (!spec || typeof spec !== 'string') {
85
+ throw new Error('Skill spec is required');
86
+ }
87
+
88
+ const [repoPart, skillPart] = spec.split("#");
89
+
90
+ if (!repoPart.includes('/')) {
91
+ throw new Error(`Invalid spec format: "${spec}". Expected: org/repo or org/repo#skill`);
92
+ }
93
+
94
+ const [org, repo] = repoPart.split("/");
95
+
96
+ if (!org || !repo) {
97
+ throw new Error(`Invalid spec: missing org or repo in "${spec}"`);
98
+ }
99
+
100
+ const [skill, ref] = (skillPart || "").split("@");
101
+ return { org, repo, skill: skill || undefined, ref: ref || undefined };
102
+ }
103
+
104
+ /**
105
+ * Resolve scope based on flags and cwd
106
+ * @returns {string} Skills directory path
107
+ */
108
+ export function resolveScope() {
109
+ if (GLOBAL) return GLOBAL_DIR;
110
+ if (fs.existsSync(path.join(cwd, ".agent"))) return WORKSPACE;
111
+ return GLOBAL_DIR;
112
+ }
113
+
114
+ /**
115
+ * Create backup of skill directory
116
+ * @param {string} skillDir - Source directory
117
+ * @param {string} skillName - Skill name for backup naming
118
+ * @returns {string|null} Backup path or null if dry run
119
+ */
120
+ export function createBackup(skillDir, skillName) {
121
+ if (DRY) return null;
122
+
123
+ try {
124
+ const ts = new Date().toISOString().replace(/[:.]/g, "-");
125
+ const bp = path.join(BACKUP_DIR, `${skillName}_${ts}`);
126
+ fs.mkdirSync(BACKUP_DIR, { recursive: true });
127
+
128
+ // Resolve symlink to real path (Windows compatibility)
129
+ const realPath = fs.realpathSync(skillDir);
130
+
131
+ fs.cpSync(realPath, bp, { recursive: true });
132
+ return bp;
133
+ } catch (err) {
134
+ // Fallback: try direct copy if realpath fails
135
+ try {
136
+ const ts = new Date().toISOString().replace(/[:.]/g, "-");
137
+ const bp = path.join(BACKUP_DIR, `${skillName}_${ts}`);
138
+ fs.cpSync(skillDir, bp, { recursive: true });
139
+ return bp;
140
+ } catch (fallbackErr) {
141
+ if (process.env.DEBUG) {
142
+ console.error(`Backup failed for ${skillName}:`, fallbackErr.message);
143
+ }
144
+ return null;
145
+ }
146
+ }
147
+ }
148
+
149
+ /**
150
+ * List backups for a skill
151
+ * @param {string} [skillName] - Filter by skill name
152
+ * @returns {import('./types.js').Backup[]}
153
+ */
154
+ export function listBackups(skillName = null) {
155
+ if (!fs.existsSync(BACKUP_DIR)) return [];
156
+ const backups = [];
157
+ for (const name of fs.readdirSync(BACKUP_DIR)) {
158
+ if (skillName && !name.startsWith(skillName + "_")) continue;
159
+ const bp = path.join(BACKUP_DIR, name);
160
+ backups.push({ name, path: bp, createdAt: fs.statSync(bp).mtime, size: getDirSize(bp) });
161
+ }
162
+ return backups.sort((a, b) => b.createdAt - a.createdAt);
163
+ }
164
+
165
+ /**
166
+ * Load skill lock file
167
+ * @returns {import('./types.js').SkillLock}
168
+ */
169
+ export function loadSkillLock() {
170
+ const f = path.join(cwd, ".agent", "skill-lock.json");
171
+ if (!fs.existsSync(f)) throw new Error("skill-lock.json not found");
172
+ return JSON.parse(fs.readFileSync(f, "utf-8"));
173
+ }
174
+
175
+ /**
176
+ * Load registries list
177
+ * @returns {string[]}
178
+ */
179
+ export function loadRegistries() {
180
+ try {
181
+ return fs.existsSync(REGISTRIES_FILE) ? JSON.parse(fs.readFileSync(REGISTRIES_FILE, "utf-8")) : [];
182
+ } catch (err) {
183
+ if (process.env.DEBUG) console.error(`loadRegistries error: ${err.message}`);
184
+ return [];
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Save registries list
190
+ * @param {string[]} regs
191
+ */
192
+ export function saveRegistries(regs) {
193
+ fs.mkdirSync(path.dirname(REGISTRIES_FILE), { recursive: true });
194
+ fs.writeFileSync(REGISTRIES_FILE, JSON.stringify(regs, null, 2));
195
+ }
196
+
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @fileoverview Tests for helpers.js
3
+ */
4
+ import { describe, it, expect } from "vitest";
5
+ import { formatBytes, formatDate, parseSkillSpec } from "./helpers.js";
6
+
7
+ describe("formatBytes", () => {
8
+ it("formats bytes correctly", () => {
9
+ expect(formatBytes(0)).toBe("0 B");
10
+ expect(formatBytes(512)).toBe("512 B");
11
+ expect(formatBytes(1024)).toBe("1.0 KB");
12
+ expect(formatBytes(1536)).toBe("1.5 KB");
13
+ expect(formatBytes(1048576)).toBe("1.0 MB");
14
+ expect(formatBytes(1572864)).toBe("1.5 MB");
15
+ });
16
+ });
17
+
18
+ describe("formatDate", () => {
19
+ it("returns 'unknown' for undefined", () => {
20
+ expect(formatDate()).toBe("unknown");
21
+ expect(formatDate(undefined)).toBe("unknown");
22
+ });
23
+
24
+ it("formats ISO date strings", () => {
25
+ const result = formatDate("2026-01-25T00:00:00.000Z");
26
+ expect(result).toBeTruthy();
27
+ expect(typeof result).toBe("string");
28
+ });
29
+ });
30
+
31
+ describe("parseSkillSpec", () => {
32
+ it("parses org/repo format", () => {
33
+ const result = parseSkillSpec("agentskillkit/agent-skills");
34
+ expect(result.org).toBe("agentskillkit");
35
+ expect(result.repo).toBe("agent-skills");
36
+ expect(result.skill).toBeUndefined();
37
+ expect(result.ref).toBeUndefined();
38
+ });
39
+
40
+ it("parses org/repo#skill format", () => {
41
+ const result = parseSkillSpec("agentskillkit/agent-skills#react-patterns");
42
+ expect(result.org).toBe("agentskillkit");
43
+ expect(result.repo).toBe("agent-skills");
44
+ expect(result.skill).toBe("react-patterns");
45
+ });
46
+
47
+ it("parses org/repo#skill@ref format", () => {
48
+ const result = parseSkillSpec("agentskillkit/agent-skills#react-patterns@v1.0.0");
49
+ expect(result.org).toBe("agentskillkit");
50
+ expect(result.repo).toBe("agent-skills");
51
+ expect(result.skill).toBe("react-patterns");
52
+ expect(result.ref).toBe("v1.0.0");
53
+ });
54
+
55
+ it("throws error for invalid spec", () => {
56
+ expect(() => parseSkillSpec("")).toThrow("Skill spec is required");
57
+ expect(() => parseSkillSpec("invalid")).toThrow("Invalid spec format");
58
+ expect(() => parseSkillSpec(null)).toThrow("Skill spec is required");
59
+ });
60
+ });
@@ -0,0 +1,164 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { homedir } from "os";
4
+ import { GLOBAL_DIR } from "./config.js";
5
+ import { merkleHash } from "./helpers.js";
6
+ import { AGENTS } from "./agents.js";
7
+
8
+ const home = homedir();
9
+
10
+ /**
11
+ * Install a skill to the destination using the specified method.
12
+ * @param {string} src - Source directory (temp)
13
+ * @param {string} dest - Destination directory (project)
14
+ * @param {string} method - 'symlink' or 'copy'
15
+ * @param {Object} metadata - Metadata for .skill-source.json
16
+ */
17
+ export async function installSkill(src, dest, method, metadata) {
18
+ if (fs.existsSync(dest)) fs.rmSync(dest, { recursive: true, force: true });
19
+
20
+ if (method === "symlink") {
21
+ // For symlink: Move to global persistent storage first
22
+ // Storage path: ~/.gemini/antigravity/skills/storage/<org>/<repo>/<skill>
23
+ // Metadata must contain org, repo, skill
24
+ const { repo: repoStr, skill } = metadata;
25
+ const [org, repo] = repoStr.split("/");
26
+
27
+ const storageBase = path.join(GLOBAL_DIR, "storage", org, repo, skill);
28
+
29
+ // Ensure fresh copy in storage
30
+ if (fs.existsSync(storageBase)) fs.rmSync(storageBase, { recursive: true, force: true });
31
+ fs.mkdirSync(path.dirname(storageBase), { recursive: true });
32
+
33
+ // Copy from tmp to storage
34
+ await fs.promises.cp(src, storageBase, { recursive: true });
35
+
36
+ // Create junction
37
+ fs.symlinkSync(storageBase, dest, "junction");
38
+ } else {
39
+ // Copy directly
40
+ await fs.promises.cp(src, dest, { recursive: true });
41
+ }
42
+
43
+ // Write metadata
44
+ const hash = merkleHash(dest);
45
+ const metaFile = path.join(dest, ".skill-source.json");
46
+
47
+ fs.writeFileSync(metaFile, JSON.stringify({
48
+ ...metadata,
49
+ checksum: hash,
50
+ installedAt: new Date().toISOString(),
51
+ method: method
52
+ }, null, 2));
53
+ }
54
+
55
+ /**
56
+ * Install a skill to multiple agents
57
+ * @param {string} src - Source directory containing the skill
58
+ * @param {string} skillName - Name of the skill
59
+ * @param {Array<{name: string, displayName: string, skillsDir: string, globalSkillsDir: string}>} agents - Agents to install to
60
+ * @param {Object} options - Installation options
61
+ * @param {string} options.method - 'symlink' or 'copy'
62
+ * @param {string} options.scope - 'project' or 'global'
63
+ * @param {Object} options.metadata - Metadata for tracking
64
+ * @returns {Promise<{success: Array, failed: Array}>}
65
+ */
66
+ export async function installSkillForAgents(src, skillName, agents, options = {}) {
67
+ const { method = "symlink", scope = "project", metadata = {} } = options;
68
+ const results = { success: [], failed: [] };
69
+
70
+ // For symlink mode: first copy to canonical location
71
+ let canonicalPath = null;
72
+
73
+ if (method === "symlink") {
74
+ // Canonical: .agents/skills/<skill-name> or ~/.agents/skills/<skill-name>
75
+ const baseDir = scope === "global" ? home : process.cwd();
76
+ canonicalPath = path.join(baseDir, ".agents", "skills", skillName);
77
+
78
+ // Ensure fresh copy in canonical
79
+ if (fs.existsSync(canonicalPath)) {
80
+ fs.rmSync(canonicalPath, { recursive: true, force: true });
81
+ }
82
+ fs.mkdirSync(path.dirname(canonicalPath), { recursive: true });
83
+
84
+ try {
85
+ await fs.promises.cp(src, canonicalPath, { recursive: true });
86
+
87
+ // Write metadata to canonical location
88
+ const hash = merkleHash(canonicalPath);
89
+ const metaFile = path.join(canonicalPath, ".skill-source.json");
90
+ fs.writeFileSync(metaFile, JSON.stringify({
91
+ ...metadata,
92
+ skillName,
93
+ checksum: hash,
94
+ installedAt: new Date().toISOString(),
95
+ method: method,
96
+ scope: scope,
97
+ agents: agents.map(a => a.name)
98
+ }, null, 2));
99
+ } catch (err) {
100
+ // If canonical copy fails, abort
101
+ return {
102
+ success: [],
103
+ failed: agents.map(a => ({ agent: a.displayName, error: `Canonical copy failed: ${err.message}` }))
104
+ };
105
+ }
106
+ }
107
+
108
+ // Install to each agent
109
+ for (const agent of agents) {
110
+ const agentConfig = AGENTS[agent.name];
111
+ if (!agentConfig) {
112
+ results.failed.push({ agent: agent.displayName, error: "Unknown agent" });
113
+ continue;
114
+ }
115
+
116
+ // Determine destination path
117
+ const baseDir = scope === "global" ? agentConfig.globalSkillsDir : path.join(process.cwd(), agentConfig.skillsDir);
118
+ const destPath = path.join(baseDir, skillName);
119
+
120
+ try {
121
+ // Ensure parent directory exists
122
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
123
+
124
+ // Remove existing if any
125
+ if (fs.existsSync(destPath)) {
126
+ fs.rmSync(destPath, { recursive: true, force: true });
127
+ }
128
+
129
+ if (method === "symlink" && canonicalPath) {
130
+ // Create symlink to canonical location
131
+ try {
132
+ fs.symlinkSync(canonicalPath, destPath, "junction");
133
+ results.success.push({ agent: agent.displayName, path: destPath, mode: "symlink" });
134
+ } catch (symlinkErr) {
135
+ // Fallback to copy if symlink fails (Windows permissions)
136
+ await fs.promises.cp(canonicalPath, destPath, { recursive: true });
137
+ results.success.push({ agent: agent.displayName, path: destPath, mode: "copy (symlink failed)" });
138
+ }
139
+ } else {
140
+ // Direct copy
141
+ await fs.promises.cp(src, destPath, { recursive: true });
142
+
143
+ // Write metadata
144
+ const hash = merkleHash(destPath);
145
+ const metaFile = path.join(destPath, ".skill-source.json");
146
+ fs.writeFileSync(metaFile, JSON.stringify({
147
+ ...metadata,
148
+ skillName,
149
+ checksum: hash,
150
+ installedAt: new Date().toISOString(),
151
+ method: "copy",
152
+ scope: scope
153
+ }, null, 2));
154
+
155
+ results.success.push({ agent: agent.displayName, path: destPath, mode: "copy" });
156
+ }
157
+ } catch (err) {
158
+ results.failed.push({ agent: agent.displayName, error: err.message });
159
+ }
160
+ }
161
+
162
+ return results;
163
+ }
164
+
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @fileoverview Skill detection and parsing
3
+ */
4
+
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import { resolveScope } from "./helpers.js";
8
+ import { getDirSize } from "./helpers.js";
9
+
10
+ /**
11
+ * Parse SKILL.md YAML frontmatter
12
+ * @param {string} p - Path to SKILL.md
13
+ * @returns {import('./types.js').SkillMeta}
14
+ */
15
+ export function parseSkillMdFrontmatter(p) {
16
+ try {
17
+ const content = fs.readFileSync(p, "utf-8");
18
+ const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
19
+ if (!match) return {};
20
+
21
+ /** @type {import('./types.js').SkillMeta} */
22
+ const meta = {};
23
+
24
+ for (const line of match[1].split(/\r?\n/)) {
25
+ const i = line.indexOf(":");
26
+ if (i === -1) continue;
27
+ const key = line.substring(0, i).trim();
28
+ const val = line.substring(i + 1).trim();
29
+ if (key === "tags") meta.tags = val.split(",").map(t => t.trim()).filter(Boolean);
30
+ else if (key && val) meta[key] = val;
31
+ }
32
+ return meta;
33
+ } catch (err) {
34
+ if (process.env.DEBUG) console.error(`parseSkillMdFrontmatter error: ${err.message}`);
35
+ return {};
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Detect skill directory structure
41
+ * @param {string} dir - Skill directory
42
+ * @returns {import('./types.js').SkillStructure}
43
+ */
44
+ export function detectSkillStructure(dir) {
45
+ /** @type {import('./types.js').SkillStructure} */
46
+ const s = {
47
+ hasResources: false,
48
+ hasExamples: false,
49
+ hasScripts: false,
50
+ hasConstitution: false,
51
+ hasDoctrines: false,
52
+ hasEnforcement: false,
53
+ hasProposals: false,
54
+ directories: [],
55
+ files: []
56
+ };
57
+
58
+ try {
59
+ for (const item of fs.readdirSync(dir)) {
60
+ const full = path.join(dir, item);
61
+ if (fs.statSync(full).isDirectory()) {
62
+ s.directories.push(item);
63
+ const l = item.toLowerCase();
64
+ if (l === "resources") s.hasResources = true;
65
+ if (l === "examples") s.hasExamples = true;
66
+ if (l === "scripts") s.hasScripts = true;
67
+ if (l === "constitution") s.hasConstitution = true;
68
+ if (l === "doctrines") s.hasDoctrines = true;
69
+ if (l === "enforcement") s.hasEnforcement = true;
70
+ if (l === "proposals") s.hasProposals = true;
71
+ } else {
72
+ s.files.push(item);
73
+ }
74
+ }
75
+ } catch (err) {
76
+ if (process.env.DEBUG) console.error(`detectSkillStructure error: ${err.message}`);
77
+ }
78
+ return s;
79
+ }
80
+
81
+ /**
82
+ * Get all installed skills
83
+ * @returns {import('./types.js').Skill[]}
84
+ */
85
+ export function getInstalledSkills() {
86
+ const scope = resolveScope();
87
+ /** @type {import('./types.js').Skill[]} */
88
+ const skills = [];
89
+
90
+ if (!fs.existsSync(scope)) return skills;
91
+
92
+ for (const name of fs.readdirSync(scope)) {
93
+ const dir = path.join(scope, name);
94
+ if (!fs.statSync(dir).isDirectory()) continue;
95
+
96
+ const metaFile = path.join(dir, ".skill-source.json");
97
+ const skillFile = path.join(dir, "SKILL.md");
98
+
99
+ if (fs.existsSync(metaFile) || fs.existsSync(skillFile)) {
100
+ const meta = fs.existsSync(metaFile) ? JSON.parse(fs.readFileSync(metaFile, "utf-8")) : {};
101
+ const hasSkillMd = fs.existsSync(skillFile);
102
+ const skillMeta = hasSkillMd ? parseSkillMdFrontmatter(skillFile) : {};
103
+
104
+ skills.push({
105
+ name,
106
+ path: dir,
107
+ ...meta,
108
+ hasSkillMd,
109
+ description: skillMeta.description || meta.description || "",
110
+ tags: skillMeta.tags || [],
111
+ author: skillMeta.author || meta.publisher || "",
112
+ version: skillMeta.version || meta.ref || "unknown",
113
+ structure: detectSkillStructure(dir),
114
+ size: getDirSize(dir)
115
+ });
116
+ }
117
+ }
118
+ return skills;
119
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @fileoverview Tests for skills.js
3
+ */
4
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import os from "os";
8
+ import { parseSkillMdFrontmatter, detectSkillStructure } from "./skills.js";
9
+
10
+ describe("parseSkillMdFrontmatter", () => {
11
+ let tempDir;
12
+ let skillMdPath;
13
+
14
+ beforeEach(() => {
15
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "skill-test-"));
16
+ skillMdPath = path.join(tempDir, "SKILL.md");
17
+ });
18
+
19
+ afterEach(() => {
20
+ fs.rmSync(tempDir, { recursive: true, force: true });
21
+ });
22
+
23
+ it("parses valid frontmatter", () => {
24
+ const content = `---
25
+ name: test-skill
26
+ description: A test skill for testing
27
+ version: 1.0.0
28
+ author: Test Author
29
+ tags: react, testing, patterns
30
+ ---
31
+
32
+ # Test Skill
33
+
34
+ Some content here.
35
+ `;
36
+ fs.writeFileSync(skillMdPath, content);
37
+
38
+ const result = parseSkillMdFrontmatter(skillMdPath);
39
+
40
+ expect(result.name).toBe("test-skill");
41
+ expect(result.description).toBe("A test skill for testing");
42
+ expect(result.version).toBe("1.0.0");
43
+ expect(result.author).toBe("Test Author");
44
+ expect(result.tags).toEqual(["react", "testing", "patterns"]);
45
+ });
46
+
47
+ it("returns empty object for no frontmatter", () => {
48
+ fs.writeFileSync(skillMdPath, "# Just a heading\n\nNo frontmatter here.");
49
+
50
+ const result = parseSkillMdFrontmatter(skillMdPath);
51
+
52
+ expect(result).toEqual({});
53
+ });
54
+
55
+ it("returns empty object for non-existent file", () => {
56
+ const result = parseSkillMdFrontmatter("/non/existent/path/SKILL.md");
57
+ expect(result).toEqual({});
58
+ });
59
+ });
60
+
61
+ describe("detectSkillStructure", () => {
62
+ let tempDir;
63
+
64
+ beforeEach(() => {
65
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "skill-structure-"));
66
+ });
67
+
68
+ afterEach(() => {
69
+ fs.rmSync(tempDir, { recursive: true, force: true });
70
+ });
71
+
72
+ it("detects standard directories", () => {
73
+ fs.mkdirSync(path.join(tempDir, "resources"));
74
+ fs.mkdirSync(path.join(tempDir, "examples"));
75
+ fs.mkdirSync(path.join(tempDir, "scripts"));
76
+ fs.writeFileSync(path.join(tempDir, "SKILL.md"), "# Skill");
77
+
78
+ const result = detectSkillStructure(tempDir);
79
+
80
+ expect(result.hasResources).toBe(true);
81
+ expect(result.hasExamples).toBe(true);
82
+ expect(result.hasScripts).toBe(true);
83
+ expect(result.directories).toContain("resources");
84
+ expect(result.directories).toContain("examples");
85
+ expect(result.directories).toContain("scripts");
86
+ expect(result.files).toContain("SKILL.md");
87
+ });
88
+
89
+ it("detects governance directories", () => {
90
+ fs.mkdirSync(path.join(tempDir, "constitution"));
91
+ fs.mkdirSync(path.join(tempDir, "doctrines"));
92
+ fs.mkdirSync(path.join(tempDir, "enforcement"));
93
+ fs.mkdirSync(path.join(tempDir, "proposals"));
94
+
95
+ const result = detectSkillStructure(tempDir);
96
+
97
+ expect(result.hasConstitution).toBe(true);
98
+ expect(result.hasDoctrines).toBe(true);
99
+ expect(result.hasEnforcement).toBe(true);
100
+ expect(result.hasProposals).toBe(true);
101
+ });
102
+
103
+ it("returns empty structure for non-existent dir", () => {
104
+ const result = detectSkillStructure("/non/existent/path");
105
+
106
+ expect(result.directories).toEqual([]);
107
+ expect(result.files).toEqual([]);
108
+ });
109
+ });