skillkit 1.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/dist/index.js ADDED
@@ -0,0 +1,1276 @@
1
+ // src/core/types.ts
2
+ import { z } from "zod";
3
+ var AgentType = z.enum([
4
+ "claude-code",
5
+ "codex",
6
+ "cursor",
7
+ "antigravity",
8
+ "opencode",
9
+ "gemini-cli",
10
+ "universal"
11
+ ]);
12
+ var GitProvider = z.enum(["github", "gitlab", "bitbucket", "local"]);
13
+ var SkillFrontmatter = z.object({
14
+ name: z.string().min(1).max(64).regex(/^[a-z0-9]+(-[a-z0-9]+)*$/, "Skill name must be lowercase alphanumeric with hyphens, no leading/trailing/consecutive hyphens"),
15
+ description: z.string().min(1).max(1024),
16
+ license: z.string().optional(),
17
+ compatibility: z.string().max(500).optional(),
18
+ metadata: z.record(z.string()).optional(),
19
+ "allowed-tools": z.string().optional(),
20
+ version: z.string().optional(),
21
+ author: z.string().optional(),
22
+ tags: z.array(z.string()).optional(),
23
+ agents: z.array(AgentType).optional()
24
+ });
25
+ var SkillMetadata = z.object({
26
+ name: z.string(),
27
+ description: z.string(),
28
+ source: z.string(),
29
+ sourceType: GitProvider,
30
+ subpath: z.string().optional(),
31
+ installedAt: z.string().datetime(),
32
+ updatedAt: z.string().datetime().optional(),
33
+ enabled: z.boolean().default(true),
34
+ version: z.string().optional(),
35
+ checksum: z.string().optional()
36
+ });
37
+ var SkillLocation = z.enum(["project", "global"]);
38
+ var Skill = z.object({
39
+ name: z.string(),
40
+ description: z.string(),
41
+ path: z.string(),
42
+ location: SkillLocation,
43
+ metadata: SkillMetadata.optional(),
44
+ enabled: z.boolean().default(true)
45
+ });
46
+ var SkillkitConfig = z.object({
47
+ version: z.literal(1),
48
+ agent: AgentType.default("universal"),
49
+ skillsDir: z.string().optional(),
50
+ enabledSkills: z.array(z.string()).optional(),
51
+ disabledSkills: z.array(z.string()).optional(),
52
+ autoSync: z.boolean().default(true)
53
+ });
54
+
55
+ // src/core/skills.ts
56
+ import { existsSync, readdirSync, readFileSync } from "fs";
57
+ import { join, basename } from "path";
58
+ import { parse as parseYaml } from "yaml";
59
+ function discoverSkills(dir) {
60
+ const skills = [];
61
+ if (!existsSync(dir)) {
62
+ return skills;
63
+ }
64
+ const entries = readdirSync(dir, { withFileTypes: true });
65
+ for (const entry of entries) {
66
+ if (!entry.isDirectory()) continue;
67
+ const skillPath = join(dir, entry.name);
68
+ const skillMdPath = join(skillPath, "SKILL.md");
69
+ if (existsSync(skillMdPath)) {
70
+ const skill = parseSkill(skillPath);
71
+ if (skill) {
72
+ skills.push(skill);
73
+ }
74
+ }
75
+ }
76
+ return skills;
77
+ }
78
+ function parseSkill(skillPath, location = "project") {
79
+ const skillMdPath = join(skillPath, "SKILL.md");
80
+ if (!existsSync(skillMdPath)) {
81
+ return null;
82
+ }
83
+ try {
84
+ const content = readFileSync(skillMdPath, "utf-8");
85
+ const frontmatter = extractFrontmatter(content);
86
+ if (!frontmatter) {
87
+ const name = basename(skillPath);
88
+ return {
89
+ name,
90
+ description: "No description available",
91
+ path: skillPath,
92
+ location,
93
+ enabled: true
94
+ };
95
+ }
96
+ const parsed = SkillFrontmatter.safeParse(frontmatter);
97
+ if (!parsed.success) {
98
+ return {
99
+ name: frontmatter.name || basename(skillPath),
100
+ description: frontmatter.description || "No description available",
101
+ path: skillPath,
102
+ location,
103
+ enabled: true
104
+ };
105
+ }
106
+ const metadata = loadMetadata(skillPath);
107
+ return {
108
+ name: parsed.data.name,
109
+ description: parsed.data.description,
110
+ path: skillPath,
111
+ location,
112
+ metadata: metadata ?? void 0,
113
+ enabled: metadata?.enabled ?? true
114
+ };
115
+ } catch {
116
+ return null;
117
+ }
118
+ }
119
+ function extractFrontmatter(content) {
120
+ const match = content.match(/^---\s*\n([\s\S]*?)\n---/);
121
+ if (!match) {
122
+ return null;
123
+ }
124
+ try {
125
+ return parseYaml(match[1]);
126
+ } catch {
127
+ return null;
128
+ }
129
+ }
130
+ function extractField(content, field) {
131
+ const frontmatter = extractFrontmatter(content);
132
+ if (!frontmatter || !(field in frontmatter)) {
133
+ return null;
134
+ }
135
+ const value = frontmatter[field];
136
+ return typeof value === "string" ? value : null;
137
+ }
138
+ function loadMetadata(skillPath) {
139
+ const metadataPath = join(skillPath, ".skillkit.json");
140
+ if (!existsSync(metadataPath)) {
141
+ return null;
142
+ }
143
+ try {
144
+ const content = readFileSync(metadataPath, "utf-8");
145
+ const data = JSON.parse(content);
146
+ const parsed = SkillMetadata.safeParse(data);
147
+ return parsed.success ? parsed.data : null;
148
+ } catch {
149
+ return null;
150
+ }
151
+ }
152
+ function readSkillContent(skillPath) {
153
+ const skillMdPath = join(skillPath, "SKILL.md");
154
+ if (!existsSync(skillMdPath)) {
155
+ return null;
156
+ }
157
+ try {
158
+ return readFileSync(skillMdPath, "utf-8");
159
+ } catch {
160
+ return null;
161
+ }
162
+ }
163
+ function findSkill(name, searchDirs) {
164
+ for (const dir of searchDirs) {
165
+ if (!existsSync(dir)) continue;
166
+ const skillPath = join(dir, name);
167
+ if (existsSync(skillPath)) {
168
+ const location = dir.includes(process.cwd()) ? "project" : "global";
169
+ return parseSkill(skillPath, location);
170
+ }
171
+ }
172
+ return null;
173
+ }
174
+ function findAllSkills(searchDirs) {
175
+ const skills = [];
176
+ const seen = /* @__PURE__ */ new Set();
177
+ for (const dir of searchDirs) {
178
+ if (!existsSync(dir)) continue;
179
+ const location = dir.includes(process.cwd()) ? "project" : "global";
180
+ const discovered = discoverSkills(dir);
181
+ for (const skill of discovered) {
182
+ if (!seen.has(skill.name)) {
183
+ seen.add(skill.name);
184
+ skills.push({ ...skill, location });
185
+ }
186
+ }
187
+ }
188
+ return skills;
189
+ }
190
+ function validateSkill(skillPath) {
191
+ const errors = [];
192
+ const warnings = [];
193
+ const dirName = basename(skillPath);
194
+ const skillMdPath = join(skillPath, "SKILL.md");
195
+ if (!existsSync(skillMdPath)) {
196
+ errors.push("Missing SKILL.md file");
197
+ return { valid: false, errors };
198
+ }
199
+ const content = readFileSync(skillMdPath, "utf-8");
200
+ const frontmatter = extractFrontmatter(content);
201
+ if (!frontmatter) {
202
+ errors.push("Missing YAML frontmatter in SKILL.md");
203
+ return { valid: false, errors };
204
+ }
205
+ const parsed = SkillFrontmatter.safeParse(frontmatter);
206
+ if (!parsed.success) {
207
+ for (const issue of parsed.error.issues) {
208
+ errors.push(`${issue.path.join(".") || "frontmatter"}: ${issue.message}`);
209
+ }
210
+ }
211
+ if (parsed.success) {
212
+ const data = parsed.data;
213
+ if (data.name !== dirName) {
214
+ warnings.push(`name "${data.name}" does not match directory name "${dirName}"`);
215
+ }
216
+ if (data.description && data.description.length < 50) {
217
+ warnings.push("description is short; consider describing what the skill does AND when to use it");
218
+ }
219
+ }
220
+ const bodyContent = content.replace(/^---[\s\S]*?---\s*/, "");
221
+ const lineCount = bodyContent.split("\n").length;
222
+ if (lineCount > 500) {
223
+ warnings.push(`SKILL.md has ${lineCount} lines; consider moving detailed content to references/`);
224
+ }
225
+ return { valid: errors.length === 0, errors, warnings };
226
+ }
227
+ function isPathInside(child, parent) {
228
+ const relative = child.replace(parent, "");
229
+ return !relative.startsWith("..") && !relative.includes("/..");
230
+ }
231
+
232
+ // src/core/config.ts
233
+ import { existsSync as existsSync9, readFileSync as readFileSync2, writeFileSync, mkdirSync } from "fs";
234
+ import { join as join9, dirname } from "path";
235
+ import { homedir as homedir6 } from "os";
236
+ import { parse as parseYaml2, stringify as stringifyYaml } from "yaml";
237
+
238
+ // src/agents/claude-code.ts
239
+ import { existsSync as existsSync2 } from "fs";
240
+ import { join as join2 } from "path";
241
+ import { homedir } from "os";
242
+
243
+ // src/agents/base.ts
244
+ function createSkillXml(skill) {
245
+ return `<skill>
246
+ <name>${skill.name}</name>
247
+ <description>${escapeXml(skill.description)}</description>
248
+ <location>${skill.location}</location>
249
+ </skill>`;
250
+ }
251
+ function escapeXml(text) {
252
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
253
+ }
254
+
255
+ // src/agents/claude-code.ts
256
+ var ClaudeCodeAdapter = class {
257
+ type = "claude-code";
258
+ name = "Claude Code";
259
+ skillsDir = ".claude/skills";
260
+ configFile = "AGENTS.md";
261
+ generateConfig(skills) {
262
+ const enabledSkills = skills.filter((s) => s.enabled);
263
+ if (enabledSkills.length === 0) {
264
+ return "";
265
+ }
266
+ const skillsXml = enabledSkills.map(createSkillXml).join("\n\n");
267
+ return `<skills_system priority="1">
268
+
269
+ ## Available Skills
270
+
271
+ <!-- SKILLS_TABLE_START -->
272
+ <usage>
273
+ When users ask you to perform tasks, check if any of the available skills below can help complete the task more effectively. Skills provide specialized capabilities and domain knowledge.
274
+
275
+ How to use skills:
276
+ - Invoke: \`skillkit read <skill-name>\` or \`npx skillkit read <skill-name>\`
277
+ - The skill content will load with detailed instructions on how to complete the task
278
+ - Base directory provided in output for resolving bundled resources (references/, scripts/, assets/)
279
+
280
+ Usage notes:
281
+ - Only use skills listed in <available_skills> below
282
+ - Do not invoke a skill that is already loaded in your context
283
+ - Each skill invocation is stateless
284
+ </usage>
285
+
286
+ <available_skills>
287
+
288
+ ${skillsXml}
289
+
290
+ </available_skills>
291
+ <!-- SKILLS_TABLE_END -->
292
+
293
+ </skills_system>`;
294
+ }
295
+ parseConfig(content) {
296
+ const skillNames = [];
297
+ const skillRegex = /<name>([^<]+)<\/name>/g;
298
+ let match;
299
+ while ((match = skillRegex.exec(content)) !== null) {
300
+ skillNames.push(match[1].trim());
301
+ }
302
+ return skillNames;
303
+ }
304
+ getInvokeCommand(skillName) {
305
+ return `skillkit read ${skillName}`;
306
+ }
307
+ async isDetected() {
308
+ const projectClaude = join2(process.cwd(), ".claude");
309
+ const globalClaude = join2(homedir(), ".claude");
310
+ const claudeMd = join2(process.cwd(), "CLAUDE.md");
311
+ return existsSync2(projectClaude) || existsSync2(globalClaude) || existsSync2(claudeMd);
312
+ }
313
+ };
314
+
315
+ // src/agents/cursor.ts
316
+ import { existsSync as existsSync3 } from "fs";
317
+ import { join as join3 } from "path";
318
+ var CursorAdapter = class {
319
+ type = "cursor";
320
+ name = "Cursor";
321
+ skillsDir = ".cursor/skills";
322
+ configFile = ".cursorrules";
323
+ generateConfig(skills) {
324
+ const enabledSkills = skills.filter((s) => s.enabled);
325
+ if (enabledSkills.length === 0) {
326
+ return "";
327
+ }
328
+ const skillsList = enabledSkills.map((s) => `- **${s.name}**: ${s.description}`).join("\n");
329
+ const skillsXml = enabledSkills.map(createSkillXml).join("\n\n");
330
+ return `# Skills System
331
+
332
+ You have access to specialized skills that can help complete tasks. Use the skillkit CLI to load skill instructions when needed.
333
+
334
+ ## Available Skills
335
+
336
+ ${skillsList}
337
+
338
+ ## How to Use Skills
339
+
340
+ When a task matches a skill's description, load it with:
341
+ \`\`\`bash
342
+ skillkit read <skill-name>
343
+ \`\`\`
344
+
345
+ The skill will provide detailed instructions for completing the task.
346
+
347
+ <!-- SKILLS_DATA_START -->
348
+ ${skillsXml}
349
+ <!-- SKILLS_DATA_END -->
350
+ `;
351
+ }
352
+ parseConfig(content) {
353
+ const skillNames = [];
354
+ const skillRegex = /<name>([^<]+)<\/name>/g;
355
+ let match;
356
+ while ((match = skillRegex.exec(content)) !== null) {
357
+ skillNames.push(match[1].trim());
358
+ }
359
+ return skillNames;
360
+ }
361
+ getInvokeCommand(skillName) {
362
+ return `skillkit read ${skillName}`;
363
+ }
364
+ async isDetected() {
365
+ const cursorRules = join3(process.cwd(), ".cursorrules");
366
+ const cursorDir = join3(process.cwd(), ".cursor");
367
+ return existsSync3(cursorRules) || existsSync3(cursorDir);
368
+ }
369
+ };
370
+
371
+ // src/agents/codex.ts
372
+ import { existsSync as existsSync4 } from "fs";
373
+ import { join as join4 } from "path";
374
+ import { homedir as homedir2 } from "os";
375
+ var CodexAdapter = class {
376
+ type = "codex";
377
+ name = "OpenAI Codex CLI";
378
+ skillsDir = ".codex/skills";
379
+ configFile = "AGENTS.md";
380
+ generateConfig(skills) {
381
+ const enabledSkills = skills.filter((s) => s.enabled);
382
+ if (enabledSkills.length === 0) {
383
+ return "";
384
+ }
385
+ const skillsList = enabledSkills.map((s) => `| ${s.name} | ${s.description} | \`skillkit read ${s.name}\` |`).join("\n");
386
+ return `# Skills
387
+
388
+ You have access to specialized skills for completing complex tasks.
389
+
390
+ | Skill | Description | Command |
391
+ |-------|-------------|---------|
392
+ ${skillsList}
393
+
394
+ ## Usage
395
+
396
+ When a task matches a skill's capability, run the command to load detailed instructions:
397
+
398
+ \`\`\`bash
399
+ skillkit read <skill-name>
400
+ \`\`\`
401
+
402
+ Skills are loaded on-demand to keep context clean. Only load skills when relevant to the current task.
403
+ `;
404
+ }
405
+ parseConfig(content) {
406
+ const skillNames = [];
407
+ const tableRegex = /^\|\s*([a-z0-9-]+)\s*\|/gm;
408
+ let match;
409
+ while ((match = tableRegex.exec(content)) !== null) {
410
+ const name = match[1].trim();
411
+ if (name && name !== "Skill" && name !== "-------") {
412
+ skillNames.push(name);
413
+ }
414
+ }
415
+ return skillNames;
416
+ }
417
+ getInvokeCommand(skillName) {
418
+ return `skillkit read ${skillName}`;
419
+ }
420
+ async isDetected() {
421
+ const codexDir = join4(process.cwd(), ".codex");
422
+ const globalCodex = join4(homedir2(), ".codex");
423
+ return existsSync4(codexDir) || existsSync4(globalCodex);
424
+ }
425
+ };
426
+
427
+ // src/agents/gemini-cli.ts
428
+ import { existsSync as existsSync5 } from "fs";
429
+ import { join as join5 } from "path";
430
+ import { homedir as homedir3 } from "os";
431
+ var GeminiCliAdapter = class {
432
+ type = "gemini-cli";
433
+ name = "Gemini CLI";
434
+ skillsDir = ".gemini/skills";
435
+ configFile = "GEMINI.md";
436
+ generateConfig(skills) {
437
+ const enabledSkills = skills.filter((s) => s.enabled);
438
+ if (enabledSkills.length === 0) {
439
+ return "";
440
+ }
441
+ const skillsJson = enabledSkills.map((s) => ({
442
+ name: s.name,
443
+ description: s.description,
444
+ invoke: `skillkit read ${s.name}`,
445
+ location: s.location
446
+ }));
447
+ return `# Skills Configuration
448
+
449
+ You have access to specialized skills that extend your capabilities.
450
+
451
+ ## Available Skills
452
+
453
+ ${enabledSkills.map((s) => `### ${s.name}
454
+ ${s.description}
455
+
456
+ Invoke: \`skillkit read ${s.name}\``).join("\n\n")}
457
+
458
+ ## Skills Data
459
+
460
+ \`\`\`json
461
+ ${JSON.stringify(skillsJson, null, 2)}
462
+ \`\`\`
463
+
464
+ ## Usage Instructions
465
+
466
+ 1. When a task matches a skill's description, load it using the invoke command
467
+ 2. Skills provide step-by-step instructions for complex tasks
468
+ 3. Each skill is self-contained with its own resources
469
+ `;
470
+ }
471
+ parseConfig(content) {
472
+ const skillNames = [];
473
+ const jsonMatch = content.match(/```json\s*([\s\S]*?)```/);
474
+ if (jsonMatch) {
475
+ try {
476
+ const skills = JSON.parse(jsonMatch[1]);
477
+ if (Array.isArray(skills)) {
478
+ skills.forEach((s) => {
479
+ if (s.name) skillNames.push(s.name);
480
+ });
481
+ }
482
+ } catch {
483
+ }
484
+ }
485
+ if (skillNames.length === 0) {
486
+ const headerRegex = /^### ([a-z0-9-]+)$/gm;
487
+ let match;
488
+ while ((match = headerRegex.exec(content)) !== null) {
489
+ skillNames.push(match[1].trim());
490
+ }
491
+ }
492
+ return skillNames;
493
+ }
494
+ getInvokeCommand(skillName) {
495
+ return `skillkit read ${skillName}`;
496
+ }
497
+ async isDetected() {
498
+ const geminiMd = join5(process.cwd(), "GEMINI.md");
499
+ const geminiDir = join5(process.cwd(), ".gemini");
500
+ const globalGemini = join5(homedir3(), ".gemini");
501
+ return existsSync5(geminiMd) || existsSync5(geminiDir) || existsSync5(globalGemini);
502
+ }
503
+ };
504
+
505
+ // src/agents/opencode.ts
506
+ import { existsSync as existsSync6 } from "fs";
507
+ import { join as join6 } from "path";
508
+ import { homedir as homedir4 } from "os";
509
+ var OpenCodeAdapter = class {
510
+ type = "opencode";
511
+ name = "OpenCode";
512
+ skillsDir = ".opencode/skills";
513
+ configFile = "AGENTS.md";
514
+ generateConfig(skills) {
515
+ const enabledSkills = skills.filter((s) => s.enabled);
516
+ if (enabledSkills.length === 0) {
517
+ return "";
518
+ }
519
+ const skillsXml = enabledSkills.map(createSkillXml).join("\n\n");
520
+ return `<!-- SKILLKIT_START -->
521
+ # Skills
522
+
523
+ The following skills are available to help complete tasks:
524
+
525
+ <skills>
526
+ ${skillsXml}
527
+ </skills>
528
+
529
+ ## How to Use
530
+
531
+ When a task matches a skill's description:
532
+
533
+ \`\`\`bash
534
+ skillkit read <skill-name>
535
+ \`\`\`
536
+
537
+ This loads the skill's instructions into context.
538
+
539
+ <!-- SKILLKIT_END -->`;
540
+ }
541
+ parseConfig(content) {
542
+ const skillNames = [];
543
+ const skillRegex = /<name>([^<]+)<\/name>/g;
544
+ let match;
545
+ while ((match = skillRegex.exec(content)) !== null) {
546
+ skillNames.push(match[1].trim());
547
+ }
548
+ return skillNames;
549
+ }
550
+ getInvokeCommand(skillName) {
551
+ return `skillkit read ${skillName}`;
552
+ }
553
+ async isDetected() {
554
+ const opencodeDir = join6(process.cwd(), ".opencode");
555
+ const globalOpencode = join6(homedir4(), ".opencode");
556
+ return existsSync6(opencodeDir) || existsSync6(globalOpencode);
557
+ }
558
+ };
559
+
560
+ // src/agents/antigravity.ts
561
+ import { existsSync as existsSync7 } from "fs";
562
+ import { join as join7 } from "path";
563
+ import { homedir as homedir5 } from "os";
564
+ var AntigravityAdapter = class {
565
+ type = "antigravity";
566
+ name = "Antigravity";
567
+ skillsDir = ".antigravity/skills";
568
+ configFile = "AGENTS.md";
569
+ generateConfig(skills) {
570
+ const enabledSkills = skills.filter((s) => s.enabled);
571
+ if (enabledSkills.length === 0) {
572
+ return "";
573
+ }
574
+ const skillsYaml = enabledSkills.map((s) => ` - name: ${s.name}
575
+ description: "${s.description}"
576
+ invoke: skillkit read ${s.name}`).join("\n");
577
+ return `# Antigravity Skills Configuration
578
+
579
+ <!-- skills:
580
+ ${skillsYaml}
581
+ -->
582
+
583
+ ## Available Skills
584
+
585
+ ${enabledSkills.map((s) => `### ${s.name}
586
+
587
+ ${s.description}
588
+
589
+ **Usage:** \`skillkit read ${s.name}\`
590
+ `).join("\n")}
591
+
592
+ ## How Skills Work
593
+
594
+ 1. Skills provide specialized knowledge for specific tasks
595
+ 2. Load a skill when the current task matches its description
596
+ 3. Skills are loaded on-demand to preserve context window
597
+ `;
598
+ }
599
+ parseConfig(content) {
600
+ const skillNames = [];
601
+ const yamlMatch = content.match(/<!-- skills:\s*([\s\S]*?)-->/);
602
+ if (yamlMatch) {
603
+ const nameRegex = /name:\s*([a-z0-9-]+)/g;
604
+ let match;
605
+ while ((match = nameRegex.exec(yamlMatch[1])) !== null) {
606
+ skillNames.push(match[1].trim());
607
+ }
608
+ }
609
+ if (skillNames.length === 0) {
610
+ const headerRegex = /^### ([a-z0-9-]+)$/gm;
611
+ let match;
612
+ while ((match = headerRegex.exec(content)) !== null) {
613
+ skillNames.push(match[1].trim());
614
+ }
615
+ }
616
+ return skillNames;
617
+ }
618
+ getInvokeCommand(skillName) {
619
+ return `skillkit read ${skillName}`;
620
+ }
621
+ async isDetected() {
622
+ const agDir = join7(process.cwd(), ".antigravity");
623
+ const globalAg = join7(homedir5(), ".antigravity");
624
+ return existsSync7(agDir) || existsSync7(globalAg);
625
+ }
626
+ };
627
+
628
+ // src/agents/universal.ts
629
+ import { existsSync as existsSync8 } from "fs";
630
+ import { join as join8 } from "path";
631
+ var UniversalAdapter = class {
632
+ type = "universal";
633
+ name = "Universal (Any Agent)";
634
+ skillsDir = ".agent/skills";
635
+ configFile = "AGENTS.md";
636
+ generateConfig(skills) {
637
+ const enabledSkills = skills.filter((s) => s.enabled);
638
+ if (enabledSkills.length === 0) {
639
+ return "";
640
+ }
641
+ const skillsXml = enabledSkills.map(createSkillXml).join("\n\n");
642
+ const skillsList = enabledSkills.map((s) => `- **${s.name}**: ${s.description}`).join("\n");
643
+ return `# Skills System
644
+
645
+ <!-- SKILLKIT_SKILLS_START -->
646
+
647
+ ## Available Skills
648
+
649
+ ${skillsList}
650
+
651
+ ## How to Use Skills
652
+
653
+ When a task matches one of the available skills, load it to get detailed instructions:
654
+
655
+ \`\`\`bash
656
+ skillkit read <skill-name>
657
+ \`\`\`
658
+
659
+ Or with npx:
660
+
661
+ \`\`\`bash
662
+ npx skillkit read <skill-name>
663
+ \`\`\`
664
+
665
+ ## Skills Data
666
+
667
+ <skills_system>
668
+ <usage>
669
+ Skills provide specialized capabilities and domain knowledge.
670
+ - Invoke: \`skillkit read <skill-name>\`
671
+ - Base directory provided in output for resolving resources
672
+ - Only use skills listed below
673
+ - Each invocation is stateless
674
+ </usage>
675
+
676
+ <available_skills>
677
+
678
+ ${skillsXml}
679
+
680
+ </available_skills>
681
+ </skills_system>
682
+
683
+ <!-- SKILLKIT_SKILLS_END -->
684
+ `;
685
+ }
686
+ parseConfig(content) {
687
+ const skillNames = [];
688
+ const skillRegex = /<name>([^<]+)<\/name>/g;
689
+ let match;
690
+ while ((match = skillRegex.exec(content)) !== null) {
691
+ skillNames.push(match[1].trim());
692
+ }
693
+ if (skillNames.length === 0) {
694
+ const listRegex = /^- \*\*([a-z0-9-]+)\*\*:/gm;
695
+ while ((match = listRegex.exec(content)) !== null) {
696
+ skillNames.push(match[1].trim());
697
+ }
698
+ }
699
+ return skillNames;
700
+ }
701
+ getInvokeCommand(skillName) {
702
+ return `skillkit read ${skillName}`;
703
+ }
704
+ async isDetected() {
705
+ const agentDir = join8(process.cwd(), ".agent");
706
+ const agentsMd = join8(process.cwd(), "AGENTS.md");
707
+ return existsSync8(agentDir) || existsSync8(agentsMd);
708
+ }
709
+ };
710
+
711
+ // src/agents/index.ts
712
+ var adapters = {
713
+ "claude-code": new ClaudeCodeAdapter(),
714
+ cursor: new CursorAdapter(),
715
+ codex: new CodexAdapter(),
716
+ "gemini-cli": new GeminiCliAdapter(),
717
+ opencode: new OpenCodeAdapter(),
718
+ antigravity: new AntigravityAdapter(),
719
+ universal: new UniversalAdapter()
720
+ };
721
+ function getAdapter(type) {
722
+ return adapters[type];
723
+ }
724
+ function getAllAdapters() {
725
+ return Object.values(adapters);
726
+ }
727
+ async function detectAgent() {
728
+ const checkOrder = [
729
+ "claude-code",
730
+ "cursor",
731
+ "codex",
732
+ "gemini-cli",
733
+ "opencode",
734
+ "antigravity",
735
+ "universal"
736
+ ];
737
+ for (const type of checkOrder) {
738
+ const adapter = adapters[type];
739
+ if (await adapter.isDetected()) {
740
+ return type;
741
+ }
742
+ }
743
+ return "universal";
744
+ }
745
+ function getSkillsDir(type) {
746
+ return adapters[type].skillsDir;
747
+ }
748
+ function getConfigFile(type) {
749
+ return adapters[type].configFile;
750
+ }
751
+
752
+ // src/core/config.ts
753
+ var CONFIG_FILE = "skillkit.yaml";
754
+ var METADATA_FILE = ".skillkit.json";
755
+ function getProjectConfigPath() {
756
+ return join9(process.cwd(), CONFIG_FILE);
757
+ }
758
+ function getGlobalConfigPath() {
759
+ return join9(homedir6(), ".config", "skillkit", CONFIG_FILE);
760
+ }
761
+ function loadConfig() {
762
+ const projectPath = getProjectConfigPath();
763
+ const globalPath = getGlobalConfigPath();
764
+ if (existsSync9(projectPath)) {
765
+ try {
766
+ const content = readFileSync2(projectPath, "utf-8");
767
+ const data = parseYaml2(content);
768
+ const parsed = SkillkitConfig.safeParse(data);
769
+ if (parsed.success) {
770
+ return parsed.data;
771
+ }
772
+ } catch {
773
+ }
774
+ }
775
+ if (existsSync9(globalPath)) {
776
+ try {
777
+ const content = readFileSync2(globalPath, "utf-8");
778
+ const data = parseYaml2(content);
779
+ const parsed = SkillkitConfig.safeParse(data);
780
+ if (parsed.success) {
781
+ return parsed.data;
782
+ }
783
+ } catch {
784
+ }
785
+ }
786
+ return {
787
+ version: 1,
788
+ agent: "universal",
789
+ autoSync: true
790
+ };
791
+ }
792
+ function saveConfig(config, global = false) {
793
+ const configPath = global ? getGlobalConfigPath() : getProjectConfigPath();
794
+ const dir = dirname(configPath);
795
+ if (!existsSync9(dir)) {
796
+ mkdirSync(dir, { recursive: true });
797
+ }
798
+ const content = stringifyYaml(config);
799
+ writeFileSync(configPath, content, "utf-8");
800
+ }
801
+ function getSearchDirs(agentType) {
802
+ const type = agentType || loadConfig().agent;
803
+ const adapter = getAdapter(type);
804
+ const dirs = [];
805
+ dirs.push(join9(process.cwd(), adapter.skillsDir));
806
+ dirs.push(join9(process.cwd(), ".agent", "skills"));
807
+ dirs.push(join9(homedir6(), adapter.skillsDir));
808
+ dirs.push(join9(homedir6(), ".agent", "skills"));
809
+ return dirs;
810
+ }
811
+ function getInstallDir(global = false, agentType) {
812
+ const type = agentType || loadConfig().agent;
813
+ const adapter = getAdapter(type);
814
+ if (global) {
815
+ return join9(homedir6(), adapter.skillsDir);
816
+ }
817
+ return join9(process.cwd(), adapter.skillsDir);
818
+ }
819
+ function getAgentConfigPath(agentType) {
820
+ const type = agentType || loadConfig().agent;
821
+ const adapter = getAdapter(type);
822
+ return join9(process.cwd(), adapter.configFile);
823
+ }
824
+ function saveSkillMetadata(skillPath, metadata) {
825
+ const metadataPath = join9(skillPath, METADATA_FILE);
826
+ writeFileSync(metadataPath, JSON.stringify(metadata, null, 2), "utf-8");
827
+ }
828
+ function loadSkillMetadata(skillPath) {
829
+ const metadataPath = join9(skillPath, METADATA_FILE);
830
+ if (!existsSync9(metadataPath)) {
831
+ return null;
832
+ }
833
+ try {
834
+ const content = readFileSync2(metadataPath, "utf-8");
835
+ return JSON.parse(content);
836
+ } catch {
837
+ return null;
838
+ }
839
+ }
840
+ function setSkillEnabled(skillPath, enabled) {
841
+ const metadata = loadSkillMetadata(skillPath);
842
+ if (!metadata) {
843
+ return false;
844
+ }
845
+ metadata.enabled = enabled;
846
+ metadata.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
847
+ saveSkillMetadata(skillPath, metadata);
848
+ return true;
849
+ }
850
+ async function initProject(agentType) {
851
+ const type = agentType || await detectAgent();
852
+ const adapter = getAdapter(type);
853
+ const skillsDir = join9(process.cwd(), adapter.skillsDir);
854
+ if (!existsSync9(skillsDir)) {
855
+ mkdirSync(skillsDir, { recursive: true });
856
+ }
857
+ const config = {
858
+ version: 1,
859
+ agent: type,
860
+ autoSync: true
861
+ };
862
+ saveConfig(config);
863
+ const agentConfigPath = join9(process.cwd(), adapter.configFile);
864
+ if (!existsSync9(agentConfigPath)) {
865
+ writeFileSync(agentConfigPath, `# ${adapter.name} Configuration
866
+
867
+ `, "utf-8");
868
+ }
869
+ }
870
+
871
+ // src/providers/github.ts
872
+ import { execSync } from "child_process";
873
+ import { existsSync as existsSync10, rmSync } from "fs";
874
+ import { join as join10, basename as basename2 } from "path";
875
+ import { tmpdir } from "os";
876
+ import { randomUUID } from "crypto";
877
+
878
+ // src/providers/base.ts
879
+ function parseShorthand(source) {
880
+ const cleaned = source.replace(/^\/+|\/+$/g, "");
881
+ const parts = cleaned.split("/");
882
+ if (parts.length < 2) {
883
+ return null;
884
+ }
885
+ const owner = parts[0];
886
+ const repo = parts[1];
887
+ const subpath = parts.length > 2 ? parts.slice(2).join("/") : void 0;
888
+ return { owner, repo, subpath };
889
+ }
890
+ function isLocalPath(source) {
891
+ return source.startsWith("/") || source.startsWith("./") || source.startsWith("../") || source.startsWith("~/") || source.startsWith(".");
892
+ }
893
+ function isGitUrl(source) {
894
+ return source.startsWith("git@") || source.startsWith("https://") || source.startsWith("http://") || source.startsWith("ssh://");
895
+ }
896
+
897
+ // src/providers/github.ts
898
+ var GitHubProvider = class {
899
+ type = "github";
900
+ name = "GitHub";
901
+ baseUrl = "https://github.com";
902
+ parseSource(source) {
903
+ if (source.startsWith("https://github.com/")) {
904
+ const path = source.replace("https://github.com/", "").replace(/\.git$/, "");
905
+ return parseShorthand(path);
906
+ }
907
+ if (source.startsWith("git@github.com:")) {
908
+ const path = source.replace("git@github.com:", "").replace(/\.git$/, "");
909
+ return parseShorthand(path);
910
+ }
911
+ if (!isGitUrl(source) && !source.includes(":")) {
912
+ return parseShorthand(source);
913
+ }
914
+ return null;
915
+ }
916
+ matches(source) {
917
+ return source.startsWith("https://github.com/") || source.startsWith("git@github.com:") || !isGitUrl(source) && !source.includes(":") && source.includes("/");
918
+ }
919
+ getCloneUrl(owner, repo) {
920
+ return `https://github.com/${owner}/${repo}.git`;
921
+ }
922
+ getSshUrl(owner, repo) {
923
+ return `git@github.com:${owner}/${repo}.git`;
924
+ }
925
+ async clone(source, _targetDir, options = {}) {
926
+ const parsed = this.parseSource(source);
927
+ if (!parsed) {
928
+ return { success: false, error: `Invalid GitHub source: ${source}` };
929
+ }
930
+ const { owner, repo, subpath } = parsed;
931
+ const cloneUrl = options.ssh ? this.getSshUrl(owner, repo) : this.getCloneUrl(owner, repo);
932
+ const tempDir = join10(tmpdir(), `skillkit-${randomUUID()}`);
933
+ try {
934
+ const args = ["clone"];
935
+ if (options.depth) {
936
+ args.push("--depth", String(options.depth));
937
+ }
938
+ if (options.branch) {
939
+ args.push("--branch", options.branch);
940
+ }
941
+ args.push(cloneUrl, tempDir);
942
+ execSync(`git ${args.join(" ")}`, {
943
+ stdio: ["pipe", "pipe", "pipe"],
944
+ encoding: "utf-8"
945
+ });
946
+ const searchDir = subpath ? join10(tempDir, subpath) : tempDir;
947
+ const skills = discoverSkills(searchDir);
948
+ return {
949
+ success: true,
950
+ path: searchDir,
951
+ tempRoot: tempDir,
952
+ skills: skills.map((s) => s.name),
953
+ discoveredSkills: skills.map((s) => ({
954
+ name: s.name,
955
+ dirName: basename2(s.path),
956
+ path: s.path
957
+ }))
958
+ };
959
+ } catch (error) {
960
+ if (existsSync10(tempDir)) {
961
+ rmSync(tempDir, { recursive: true, force: true });
962
+ }
963
+ const message = error instanceof Error ? error.message : String(error);
964
+ return { success: false, error: `Failed to clone: ${message}` };
965
+ }
966
+ }
967
+ };
968
+
969
+ // src/providers/gitlab.ts
970
+ import { execSync as execSync2 } from "child_process";
971
+ import { existsSync as existsSync11, rmSync as rmSync2 } from "fs";
972
+ import { join as join11, basename as basename3 } from "path";
973
+ import { tmpdir as tmpdir2 } from "os";
974
+ import { randomUUID as randomUUID2 } from "crypto";
975
+ var GitLabProvider = class {
976
+ type = "gitlab";
977
+ name = "GitLab";
978
+ baseUrl = "https://gitlab.com";
979
+ parseSource(source) {
980
+ if (source.startsWith("https://gitlab.com/")) {
981
+ const path = source.replace("https://gitlab.com/", "").replace(/\.git$/, "");
982
+ return parseShorthand(path);
983
+ }
984
+ if (source.startsWith("git@gitlab.com:")) {
985
+ const path = source.replace("git@gitlab.com:", "").replace(/\.git$/, "");
986
+ return parseShorthand(path);
987
+ }
988
+ if (source.startsWith("gitlab:")) {
989
+ return parseShorthand(source.replace("gitlab:", ""));
990
+ }
991
+ if (source.startsWith("gitlab.com/")) {
992
+ return parseShorthand(source.replace("gitlab.com/", ""));
993
+ }
994
+ return null;
995
+ }
996
+ matches(source) {
997
+ return source.startsWith("https://gitlab.com/") || source.startsWith("git@gitlab.com:") || source.startsWith("gitlab:") || source.startsWith("gitlab.com/");
998
+ }
999
+ getCloneUrl(owner, repo) {
1000
+ return `https://gitlab.com/${owner}/${repo}.git`;
1001
+ }
1002
+ getSshUrl(owner, repo) {
1003
+ return `git@gitlab.com:${owner}/${repo}.git`;
1004
+ }
1005
+ async clone(source, _targetDir, options = {}) {
1006
+ const parsed = this.parseSource(source);
1007
+ if (!parsed) {
1008
+ return { success: false, error: `Invalid GitLab source: ${source}` };
1009
+ }
1010
+ const { owner, repo, subpath } = parsed;
1011
+ const cloneUrl = options.ssh ? this.getSshUrl(owner, repo) : this.getCloneUrl(owner, repo);
1012
+ const tempDir = join11(tmpdir2(), `skillkit-${randomUUID2()}`);
1013
+ try {
1014
+ const args = ["clone"];
1015
+ if (options.depth) {
1016
+ args.push("--depth", String(options.depth));
1017
+ }
1018
+ if (options.branch) {
1019
+ args.push("--branch", options.branch);
1020
+ }
1021
+ args.push(cloneUrl, tempDir);
1022
+ execSync2(`git ${args.join(" ")}`, {
1023
+ stdio: ["pipe", "pipe", "pipe"],
1024
+ encoding: "utf-8"
1025
+ });
1026
+ const searchDir = subpath ? join11(tempDir, subpath) : tempDir;
1027
+ const skills = discoverSkills(searchDir);
1028
+ return {
1029
+ success: true,
1030
+ path: searchDir,
1031
+ tempRoot: tempDir,
1032
+ skills: skills.map((s) => s.name),
1033
+ discoveredSkills: skills.map((s) => ({
1034
+ name: s.name,
1035
+ dirName: basename3(s.path),
1036
+ path: s.path
1037
+ }))
1038
+ };
1039
+ } catch (error) {
1040
+ if (existsSync11(tempDir)) {
1041
+ rmSync2(tempDir, { recursive: true, force: true });
1042
+ }
1043
+ const message = error instanceof Error ? error.message : String(error);
1044
+ return { success: false, error: `Failed to clone: ${message}` };
1045
+ }
1046
+ }
1047
+ };
1048
+
1049
+ // src/providers/bitbucket.ts
1050
+ import { execSync as execSync3 } from "child_process";
1051
+ import { existsSync as existsSync12, rmSync as rmSync3 } from "fs";
1052
+ import { join as join12, basename as basename4 } from "path";
1053
+ import { tmpdir as tmpdir3 } from "os";
1054
+ import { randomUUID as randomUUID3 } from "crypto";
1055
+ var BitbucketProvider = class {
1056
+ type = "bitbucket";
1057
+ name = "Bitbucket";
1058
+ baseUrl = "https://bitbucket.org";
1059
+ parseSource(source) {
1060
+ if (source.startsWith("https://bitbucket.org/")) {
1061
+ const path = source.replace("https://bitbucket.org/", "").replace(/\.git$/, "");
1062
+ return parseShorthand(path);
1063
+ }
1064
+ if (source.startsWith("git@bitbucket.org:")) {
1065
+ const path = source.replace("git@bitbucket.org:", "").replace(/\.git$/, "");
1066
+ return parseShorthand(path);
1067
+ }
1068
+ if (source.startsWith("bitbucket:")) {
1069
+ return parseShorthand(source.replace("bitbucket:", ""));
1070
+ }
1071
+ if (source.startsWith("bitbucket.org/")) {
1072
+ return parseShorthand(source.replace("bitbucket.org/", ""));
1073
+ }
1074
+ return null;
1075
+ }
1076
+ matches(source) {
1077
+ return source.startsWith("https://bitbucket.org/") || source.startsWith("git@bitbucket.org:") || source.startsWith("bitbucket:") || source.startsWith("bitbucket.org/");
1078
+ }
1079
+ getCloneUrl(owner, repo) {
1080
+ return `https://bitbucket.org/${owner}/${repo}.git`;
1081
+ }
1082
+ getSshUrl(owner, repo) {
1083
+ return `git@bitbucket.org:${owner}/${repo}.git`;
1084
+ }
1085
+ async clone(source, _targetDir, options = {}) {
1086
+ const parsed = this.parseSource(source);
1087
+ if (!parsed) {
1088
+ return { success: false, error: `Invalid Bitbucket source: ${source}` };
1089
+ }
1090
+ const { owner, repo, subpath } = parsed;
1091
+ const cloneUrl = options.ssh ? this.getSshUrl(owner, repo) : this.getCloneUrl(owner, repo);
1092
+ const tempDir = join12(tmpdir3(), `skillkit-${randomUUID3()}`);
1093
+ try {
1094
+ const args = ["clone"];
1095
+ if (options.depth) {
1096
+ args.push("--depth", String(options.depth));
1097
+ }
1098
+ if (options.branch) {
1099
+ args.push("--branch", options.branch);
1100
+ }
1101
+ args.push(cloneUrl, tempDir);
1102
+ execSync3(`git ${args.join(" ")}`, {
1103
+ stdio: ["pipe", "pipe", "pipe"],
1104
+ encoding: "utf-8"
1105
+ });
1106
+ const searchDir = subpath ? join12(tempDir, subpath) : tempDir;
1107
+ const skills = discoverSkills(searchDir);
1108
+ return {
1109
+ success: true,
1110
+ path: searchDir,
1111
+ tempRoot: tempDir,
1112
+ skills: skills.map((s) => s.name),
1113
+ discoveredSkills: skills.map((s) => ({
1114
+ name: s.name,
1115
+ dirName: basename4(s.path),
1116
+ path: s.path
1117
+ }))
1118
+ };
1119
+ } catch (error) {
1120
+ if (existsSync12(tempDir)) {
1121
+ rmSync3(tempDir, { recursive: true, force: true });
1122
+ }
1123
+ const message = error instanceof Error ? error.message : String(error);
1124
+ return { success: false, error: `Failed to clone: ${message}` };
1125
+ }
1126
+ }
1127
+ };
1128
+
1129
+ // src/providers/local.ts
1130
+ import { existsSync as existsSync13, statSync, realpathSync } from "fs";
1131
+ import { join as join13, resolve, basename as basename5 } from "path";
1132
+ import { homedir as homedir7 } from "os";
1133
+ var LocalProvider = class {
1134
+ type = "local";
1135
+ name = "Local Filesystem";
1136
+ baseUrl = "";
1137
+ parseSource(source) {
1138
+ if (!isLocalPath(source)) {
1139
+ return null;
1140
+ }
1141
+ let expandedPath = source;
1142
+ if (source.startsWith("~/")) {
1143
+ expandedPath = join13(homedir7(), source.slice(2));
1144
+ }
1145
+ const absolutePath = resolve(expandedPath);
1146
+ const dirName = basename5(absolutePath);
1147
+ return {
1148
+ owner: "local",
1149
+ repo: dirName,
1150
+ subpath: absolutePath
1151
+ };
1152
+ }
1153
+ matches(source) {
1154
+ return isLocalPath(source);
1155
+ }
1156
+ getCloneUrl(_owner, _repo) {
1157
+ return "";
1158
+ }
1159
+ getSshUrl(_owner, _repo) {
1160
+ return "";
1161
+ }
1162
+ async clone(source, _targetDir, _options = {}) {
1163
+ const parsed = this.parseSource(source);
1164
+ if (!parsed || !parsed.subpath) {
1165
+ return { success: false, error: `Invalid local path: ${source}` };
1166
+ }
1167
+ const sourcePath = parsed.subpath;
1168
+ if (!existsSync13(sourcePath)) {
1169
+ return { success: false, error: `Path does not exist: ${sourcePath}` };
1170
+ }
1171
+ const stats = statSync(sourcePath);
1172
+ if (!stats.isDirectory()) {
1173
+ return { success: false, error: `Path is not a directory: ${sourcePath}` };
1174
+ }
1175
+ try {
1176
+ let actualPath = sourcePath;
1177
+ try {
1178
+ actualPath = realpathSync(sourcePath);
1179
+ } catch {
1180
+ }
1181
+ const skills = discoverSkills(actualPath);
1182
+ return {
1183
+ success: true,
1184
+ path: actualPath,
1185
+ skills: skills.map((s) => s.name)
1186
+ };
1187
+ } catch (error) {
1188
+ const message = error instanceof Error ? error.message : String(error);
1189
+ return { success: false, error: `Failed to process local path: ${message}` };
1190
+ }
1191
+ }
1192
+ };
1193
+
1194
+ // src/providers/index.ts
1195
+ var providers = [
1196
+ new LocalProvider(),
1197
+ new GitLabProvider(),
1198
+ new BitbucketProvider(),
1199
+ new GitHubProvider()
1200
+ ];
1201
+ function getProvider(type) {
1202
+ return providers.find((p) => p.type === type);
1203
+ }
1204
+ function getAllProviders() {
1205
+ return providers;
1206
+ }
1207
+ function detectProvider(source) {
1208
+ return providers.find((p) => p.matches(source));
1209
+ }
1210
+ function parseSource(source) {
1211
+ for (const provider of providers) {
1212
+ if (provider.matches(source)) {
1213
+ const parsed = provider.parseSource(source);
1214
+ if (parsed) {
1215
+ return { provider, ...parsed };
1216
+ }
1217
+ }
1218
+ }
1219
+ return null;
1220
+ }
1221
+ export {
1222
+ AgentType,
1223
+ AntigravityAdapter,
1224
+ BitbucketProvider,
1225
+ ClaudeCodeAdapter,
1226
+ CodexAdapter,
1227
+ CursorAdapter,
1228
+ GeminiCliAdapter,
1229
+ GitHubProvider,
1230
+ GitLabProvider,
1231
+ GitProvider,
1232
+ LocalProvider,
1233
+ OpenCodeAdapter,
1234
+ Skill,
1235
+ SkillFrontmatter,
1236
+ SkillLocation,
1237
+ SkillMetadata,
1238
+ SkillkitConfig,
1239
+ UniversalAdapter,
1240
+ createSkillXml,
1241
+ detectAgent,
1242
+ detectProvider,
1243
+ discoverSkills,
1244
+ escapeXml,
1245
+ extractField,
1246
+ extractFrontmatter,
1247
+ findAllSkills,
1248
+ findSkill,
1249
+ getAdapter,
1250
+ getAgentConfigPath,
1251
+ getAllAdapters,
1252
+ getAllProviders,
1253
+ getConfigFile,
1254
+ getGlobalConfigPath,
1255
+ getInstallDir,
1256
+ getProjectConfigPath,
1257
+ getProvider,
1258
+ getSearchDirs,
1259
+ getSkillsDir,
1260
+ initProject,
1261
+ isGitUrl,
1262
+ isLocalPath,
1263
+ isPathInside,
1264
+ loadConfig,
1265
+ loadMetadata,
1266
+ loadSkillMetadata,
1267
+ parseShorthand,
1268
+ parseSkill,
1269
+ parseSource,
1270
+ readSkillContent,
1271
+ saveConfig,
1272
+ saveSkillMetadata,
1273
+ setSkillEnabled,
1274
+ validateSkill
1275
+ };
1276
+ //# sourceMappingURL=index.js.map