@aiskillet/cli 0.5.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/LICENSE +21 -0
- package/README.md +54 -0
- package/bin/skillet.mjs +7 -0
- package/package.json +27 -0
- package/src/commands.mjs +113 -0
- package/src/compile.mjs +70 -0
- package/src/index.mjs +99 -0
- package/src/registry.mjs +42 -0
- package/src/source.mjs +91 -0
- package/src/store.mjs +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chinmay Murugkar (AISkillet)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# 🍳 skillet
|
|
2
|
+
|
|
3
|
+
The CLI for [AISkillet](https://aiskillet.com) — install AI skills from the marketplace into **whatever tool you already use**. Write a capability once; `skillet` compiles it into each tool's native format.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @aiskillet/cli search api
|
|
7
|
+
npx @aiskillet/cli add api-design --target cursor
|
|
8
|
+
npx @aiskillet/cli add api-design --target claude-code --global
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Why
|
|
12
|
+
|
|
13
|
+
A skill written once should run everywhere. `skillet` is the portability layer: it fetches a skill's canonical `SKILL.md` from its source repo and **compiles** it to the target tool's format + install location — no copy-paste, no reformatting.
|
|
14
|
+
|
|
15
|
+
| Target | Output | Location |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `claude-code` | native `SKILL.md` | `.claude/skills/<name>/` (or `~/.claude/skills` with `--global`) |
|
|
18
|
+
| `cursor` | `.mdc` rule with Cursor frontmatter | `.cursor/rules/<name>.mdc` |
|
|
19
|
+
| `agents-md` | portable `AGENTS.md`-style skill | `.agents/skills/<name>.md` |
|
|
20
|
+
|
|
21
|
+
We never execute the skill — we only read Markdown. The code stays in its source repo.
|
|
22
|
+
|
|
23
|
+
## Commands
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
skillet search [query] Search the marketplace
|
|
27
|
+
skillet add <name> --target <t> Compile + install a skill for a target
|
|
28
|
+
skillet list List skills installed in this directory
|
|
29
|
+
skillet remove <name> [--target t] Remove an installed skill
|
|
30
|
+
skillet targets List supported targets
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Options
|
|
34
|
+
- `-t, --target <name>` — target tool (`claude-code`, `cursor`, `agents-md`)
|
|
35
|
+
- `-g, --global` — install for the user (e.g. `~/.claude`) instead of the project
|
|
36
|
+
- `--registry <url>` — registry `index.json` URL or local path (env: `SKILLET_REGISTRY`)
|
|
37
|
+
- `--cwd <dir>` — project directory to install into
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install -g @aiskillet/cli
|
|
43
|
+
# or run without installing:
|
|
44
|
+
npx @aiskillet/cli <command>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Requires Node 20+. Zero runtime dependencies.
|
|
48
|
+
|
|
49
|
+
## Roadmap
|
|
50
|
+
|
|
51
|
+
- **Now:** portability/compiler — write once, install into any tool.
|
|
52
|
+
- **Next:** `skillet run <agent>` — run marketplace agents locally against any model (bring-your-own-key) with MCP tools.
|
|
53
|
+
|
|
54
|
+
MIT licensed.
|
package/bin/skillet.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiskillet/cli",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Install AI skills from the AISkillet marketplace into any tool — write once, run anywhere.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"skillet": "bin/skillet.mjs"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=20"
|
|
11
|
+
},
|
|
12
|
+
"files": ["bin", "src", "README.md", "LICENSE"],
|
|
13
|
+
"keywords": ["ai", "skills", "agents", "claude", "cursor", "mcp", "marketplace", "portability"],
|
|
14
|
+
"homepage": "https://aiskillet.com",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/aiskillet/cli.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "node --test",
|
|
25
|
+
"prepublishOnly": "node --test"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/commands.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { writeFile, mkdir, rm } from "node:fs/promises";
|
|
2
|
+
import { dirname, relative } from "node:path";
|
|
3
|
+
import { loadRegistry, searchEntries, findEntry } from "./registry.mjs";
|
|
4
|
+
import { fetchItem, fetchPluginManifest } from "./source.mjs";
|
|
5
|
+
import { compile, TARGETS } from "./compile.mjs";
|
|
6
|
+
import { recordInstall, readLock, removeInstall } from "./store.mjs";
|
|
7
|
+
|
|
8
|
+
const dim = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
9
|
+
const bold = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
10
|
+
const ok = (s) => `\x1b[32m${s}\x1b[0m`;
|
|
11
|
+
|
|
12
|
+
function rel(cwd, p) {
|
|
13
|
+
const r = relative(cwd, p);
|
|
14
|
+
return r.startsWith("..") ? p : r;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function search(query, opts) {
|
|
18
|
+
const entries = await loadRegistry(opts.registry);
|
|
19
|
+
const results = searchEntries(entries, query);
|
|
20
|
+
if (!results.length) {
|
|
21
|
+
console.log(`No results${query ? ` for "${query}"` : ""}.`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
console.log(`Found ${results.length} listing${results.length === 1 ? "" : "s"}:\n`);
|
|
25
|
+
for (const e of results) {
|
|
26
|
+
console.log(` ${bold(e.name)} ${dim(`[${e.type}]`)}${e.verified ? " " + ok("✓") : ""}`);
|
|
27
|
+
console.log(` ${e.description}`);
|
|
28
|
+
console.log(` ${dim(`skillet add ${e.name} --target <${TARGETS.join("|")}>`)}\n`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function add(name, opts) {
|
|
33
|
+
if (!name) throw new Error("Usage: skillet add <name> --target <target>");
|
|
34
|
+
const target = opts.target;
|
|
35
|
+
if (!target) throw new Error(`Specify a target: --target <${TARGETS.join("|")}>`);
|
|
36
|
+
const cwd = opts.cwd || process.cwd();
|
|
37
|
+
|
|
38
|
+
const entries = await loadRegistry(opts.registry);
|
|
39
|
+
const entry = findEntry(entries, name);
|
|
40
|
+
|
|
41
|
+
// MCP servers run as external processes — not compiled by skillet. Show the command.
|
|
42
|
+
if (entry.type === "mcp") {
|
|
43
|
+
console.log(`${bold(name)} is an MCP server. Add it to Claude Code with:\n`);
|
|
44
|
+
console.log(` ${entry.install}\n`);
|
|
45
|
+
console.log(dim(`Source: ${entry.repo}`));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Plugin = a bundle: install each member entry.
|
|
50
|
+
if (entry.type === "plugin") {
|
|
51
|
+
const manifest = await fetchPluginManifest(entry);
|
|
52
|
+
console.log(`Installing plugin ${bold(name)} — ${manifest.includes.length} item(s) → ${target}\n`);
|
|
53
|
+
let count = 0;
|
|
54
|
+
for (const inc of manifest.includes) {
|
|
55
|
+
const member = findEntry(entries, inc.name);
|
|
56
|
+
const item = await fetchItem(member);
|
|
57
|
+
for (const f of compile(target, item, { global: opts.global, cwd })) {
|
|
58
|
+
await mkdir(dirname(f.path), { recursive: true });
|
|
59
|
+
await writeFile(f.path, f.content);
|
|
60
|
+
await recordInstall(cwd, { name: item.name, target, path: f.path, installedAt: new Date().toISOString() });
|
|
61
|
+
console.log(` ${ok("✓")} ${item.name} ${dim(`(${item.type})`)} → ${rel(cwd, f.path)}`);
|
|
62
|
+
}
|
|
63
|
+
count++;
|
|
64
|
+
}
|
|
65
|
+
console.log(`\n${ok("✓")} Installed plugin ${bold(name)} (${count} items) → ${target}.`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
process.stdout.write(`Resolving ${bold(name)}@aiskillet … `);
|
|
70
|
+
const item = await fetchItem(entry);
|
|
71
|
+
console.log(ok("ok"));
|
|
72
|
+
|
|
73
|
+
const files = compile(target, item, { global: opts.global, cwd });
|
|
74
|
+
for (const f of files) {
|
|
75
|
+
await mkdir(dirname(f.path), { recursive: true });
|
|
76
|
+
await writeFile(f.path, f.content);
|
|
77
|
+
await recordInstall(cwd, {
|
|
78
|
+
name: item.name,
|
|
79
|
+
target,
|
|
80
|
+
path: f.path,
|
|
81
|
+
installedAt: new Date().toISOString(),
|
|
82
|
+
});
|
|
83
|
+
console.log(` ${ok("✓")} ${rel(cwd, f.path)}`);
|
|
84
|
+
}
|
|
85
|
+
console.log(`\n${ok("✓")} Installed ${bold(item.name)} (${item.type}) → ${target}.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function list(opts) {
|
|
89
|
+
const cwd = opts.cwd || process.cwd();
|
|
90
|
+
const lock = await readLock(cwd);
|
|
91
|
+
if (!lock.installed.length) {
|
|
92
|
+
console.log("No skills installed in this directory.");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
console.log(`Installed here ${dim(`(${cwd})`)}:\n`);
|
|
96
|
+
for (const r of lock.installed) {
|
|
97
|
+
console.log(` ${bold(r.name)} ${dim(`→ ${r.target}`)} ${dim(rel(cwd, r.path))}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function remove(name, opts) {
|
|
102
|
+
if (!name) throw new Error("Usage: skillet remove <name> [--target <target>]");
|
|
103
|
+
const cwd = opts.cwd || process.cwd();
|
|
104
|
+
const removed = await removeInstall(cwd, name, opts.target);
|
|
105
|
+
if (!removed.length) {
|
|
106
|
+
console.log(`Nothing to remove for "${name}"${opts.target ? ` (target ${opts.target})` : ""}.`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
for (const r of removed) {
|
|
110
|
+
await rm(r.path, { force: true });
|
|
111
|
+
console.log(` ${ok("✓")} removed ${rel(cwd, r.path)} ${dim(`(${r.target})`)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
package/src/compile.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The portability layer: turn one canonical skill (SKILL.md) into each
|
|
2
|
+
// target tool's native format + install location. Add a target = add a compiler.
|
|
3
|
+
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
export const TARGETS = ["claude-code", "cursor", "agents-md"];
|
|
8
|
+
|
|
9
|
+
/** Quote a value for single-line YAML only when needed. */
|
|
10
|
+
function yamlScalar(s) {
|
|
11
|
+
const oneLine = String(s).replace(/\s+/g, " ").trim();
|
|
12
|
+
return /[:#"'\[\]{}]|^\s|\s$/.test(oneLine) ? JSON.stringify(oneLine) : oneLine;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Claude Code — SKILL.md / AGENT.md are already native formats.
|
|
17
|
+
* Skills → .claude/skills/<name>/SKILL.md
|
|
18
|
+
* Agents → .claude/agents/<name>.md
|
|
19
|
+
* (--global installs under ~/.claude instead of the project.)
|
|
20
|
+
*/
|
|
21
|
+
function claudeCode(item, { global, cwd }) {
|
|
22
|
+
const root = global ? join(homedir(), ".claude") : join(cwd, ".claude");
|
|
23
|
+
if (item.type === "agent") {
|
|
24
|
+
return [{ path: join(root, "agents", `${item.name}.md`), content: item.md }];
|
|
25
|
+
}
|
|
26
|
+
return [{ path: join(root, "skills", item.name, "SKILL.md"), content: item.md }];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Cursor — project rules live in .cursor/rules/<name>.mdc with their own
|
|
31
|
+
* frontmatter (description drives agent-requested activation).
|
|
32
|
+
*/
|
|
33
|
+
function cursor(skill, { cwd }) {
|
|
34
|
+
const frontmatter =
|
|
35
|
+
`---\n` +
|
|
36
|
+
`description: ${yamlScalar(skill.description)}\n` +
|
|
37
|
+
`alwaysApply: false\n` +
|
|
38
|
+
`---\n\n`;
|
|
39
|
+
return [
|
|
40
|
+
{ path: join(cwd, ".cursor", "rules", `${skill.name}.mdc`), content: frontmatter + skill.body + "\n" },
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* AGENTS.md — the emerging cross-tool convention (Codex, Gemini CLI, etc.).
|
|
46
|
+
* We write a per-skill file under .agents/skills and expect an AGENTS.md include;
|
|
47
|
+
* for the MVP we emit the standalone skill file so it's portable.
|
|
48
|
+
*/
|
|
49
|
+
function agentsMd(item, { cwd }) {
|
|
50
|
+
const folder = item.type === "agent" ? "agents" : "skills";
|
|
51
|
+
const content = `# ${item.name}\n\n> ${item.description}\n\n${item.body}\n`;
|
|
52
|
+
return [{ path: join(cwd, ".agents", folder, `${item.name}.md`), content }];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const COMPILERS = {
|
|
56
|
+
"claude-code": claudeCode,
|
|
57
|
+
cursor,
|
|
58
|
+
"agents-md": agentsMd,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Compile a skill for a target → array of { path, content } to write. */
|
|
62
|
+
export function compile(target, skill, opts) {
|
|
63
|
+
const fn = COMPILERS[target];
|
|
64
|
+
if (!fn) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Unsupported target "${target}". Supported: ${TARGETS.join(", ")}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return fn(skill, opts);
|
|
70
|
+
}
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { search, add, list, remove } from "./commands.mjs";
|
|
3
|
+
import { TARGETS } from "./compile.mjs";
|
|
4
|
+
|
|
5
|
+
export const VERSION = "0.5.0";
|
|
6
|
+
|
|
7
|
+
const HELP = `\x1b[1m🍳 skillet\x1b[0m — install AI skills into any tool. Write once, run anywhere.
|
|
8
|
+
|
|
9
|
+
\x1b[1mUsage\x1b[0m
|
|
10
|
+
skillet <command> [options]
|
|
11
|
+
|
|
12
|
+
\x1b[1mCommands\x1b[0m
|
|
13
|
+
search [query] Search the AISkillet marketplace
|
|
14
|
+
add <name> --target <t> Compile a skill and install it for a target tool
|
|
15
|
+
list List skills installed in this directory
|
|
16
|
+
remove <name> [--target t] Remove an installed skill
|
|
17
|
+
targets List supported targets
|
|
18
|
+
help Show this help
|
|
19
|
+
|
|
20
|
+
\x1b[1mTargets\x1b[0m
|
|
21
|
+
${TARGETS.join(", ")}
|
|
22
|
+
|
|
23
|
+
\x1b[1mOptions\x1b[0m
|
|
24
|
+
-t, --target <name> Target tool to compile for
|
|
25
|
+
-g, --global Install for the user (e.g. ~/.claude) instead of the project
|
|
26
|
+
--registry <url> Registry index.json URL or local path (env: SKILLET_REGISTRY)
|
|
27
|
+
--cwd <dir> Project directory to install into (default: current dir)
|
|
28
|
+
-h, --help Show help
|
|
29
|
+
-v, --version Show version
|
|
30
|
+
|
|
31
|
+
\x1b[1mExamples\x1b[0m
|
|
32
|
+
skillet search api
|
|
33
|
+
skillet add api-design --target cursor
|
|
34
|
+
skillet add api-design --target claude-code --global
|
|
35
|
+
skillet list
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
export async function main(argv) {
|
|
39
|
+
let parsed;
|
|
40
|
+
try {
|
|
41
|
+
parsed = parseArgs({
|
|
42
|
+
args: argv,
|
|
43
|
+
allowPositionals: true,
|
|
44
|
+
options: {
|
|
45
|
+
target: { type: "string", short: "t" },
|
|
46
|
+
registry: { type: "string" },
|
|
47
|
+
global: { type: "boolean", short: "g" },
|
|
48
|
+
cwd: { type: "string" },
|
|
49
|
+
help: { type: "boolean", short: "h" },
|
|
50
|
+
version: { type: "boolean", short: "v" },
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error(`\x1b[31m✗ ${err.message}\x1b[0m\n`);
|
|
55
|
+
console.log(HELP);
|
|
56
|
+
process.exitCode = 1;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const { values, positionals } = parsed;
|
|
61
|
+
const cmd = positionals[0];
|
|
62
|
+
|
|
63
|
+
if (values.version) {
|
|
64
|
+
console.log(VERSION);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!cmd || (values.help && cmd == null)) {
|
|
68
|
+
console.log(HELP);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
switch (cmd) {
|
|
73
|
+
case "search":
|
|
74
|
+
await search(positionals[1], values);
|
|
75
|
+
break;
|
|
76
|
+
case "add":
|
|
77
|
+
case "install":
|
|
78
|
+
await add(positionals[1], values);
|
|
79
|
+
break;
|
|
80
|
+
case "list":
|
|
81
|
+
case "ls":
|
|
82
|
+
await list(values);
|
|
83
|
+
break;
|
|
84
|
+
case "remove":
|
|
85
|
+
case "rm":
|
|
86
|
+
await remove(positionals[1], values);
|
|
87
|
+
break;
|
|
88
|
+
case "targets":
|
|
89
|
+
console.log("Supported targets:\n" + TARGETS.map((t) => " " + t).join("\n"));
|
|
90
|
+
break;
|
|
91
|
+
case "help":
|
|
92
|
+
console.log(HELP);
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
console.error(`\x1b[31m✗ Unknown command: ${cmd}\x1b[0m\n`);
|
|
96
|
+
console.log(HELP);
|
|
97
|
+
process.exitCode = 1;
|
|
98
|
+
}
|
|
99
|
+
}
|
package/src/registry.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_REGISTRY =
|
|
4
|
+
process.env.SKILLET_REGISTRY || "https://aiskillet.com/index.json";
|
|
5
|
+
|
|
6
|
+
/** Load the marketplace catalog from a URL or local file path. */
|
|
7
|
+
export async function loadRegistry(registry) {
|
|
8
|
+
const src = registry || DEFAULT_REGISTRY;
|
|
9
|
+
let text;
|
|
10
|
+
if (/^https?:\/\//.test(src)) {
|
|
11
|
+
const res = await fetch(src);
|
|
12
|
+
if (!res.ok) {
|
|
13
|
+
throw new Error(`Failed to load registry (${res.status}) from ${src}`);
|
|
14
|
+
}
|
|
15
|
+
text = await res.text();
|
|
16
|
+
} else {
|
|
17
|
+
text = await readFile(src.replace(/^file:\/\//, ""), "utf8");
|
|
18
|
+
}
|
|
19
|
+
const data = JSON.parse(text);
|
|
20
|
+
const entries = Array.isArray(data) ? data : data.entries || [];
|
|
21
|
+
if (!entries.length) throw new Error(`Registry at ${src} has no entries.`);
|
|
22
|
+
return entries;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function searchEntries(entries, query) {
|
|
26
|
+
if (!query) return entries;
|
|
27
|
+
const q = query.toLowerCase();
|
|
28
|
+
return entries.filter((e) =>
|
|
29
|
+
[e.name, e.title, e.description, ...(e.tags || [])]
|
|
30
|
+
.join(" ")
|
|
31
|
+
.toLowerCase()
|
|
32
|
+
.includes(q)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function findEntry(entries, name) {
|
|
37
|
+
const e = entries.find((x) => x.name === name);
|
|
38
|
+
if (!e) {
|
|
39
|
+
throw new Error(`No listing named "${name}". Try: skillet search ${name}`);
|
|
40
|
+
}
|
|
41
|
+
return e;
|
|
42
|
+
}
|
package/src/source.mjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Fetches a skill's canonical SKILL.md from its source repo and parses it.
|
|
2
|
+
// We never execute anything — we only read the Markdown + frontmatter.
|
|
3
|
+
|
|
4
|
+
/** Parse a repo URL like https://github.com/owner/repo into parts. */
|
|
5
|
+
export function parseRepo(repoUrl) {
|
|
6
|
+
const u = new URL(repoUrl);
|
|
7
|
+
const [owner, repo] = u.pathname
|
|
8
|
+
.replace(/^\//, "")
|
|
9
|
+
.replace(/\.git$/, "")
|
|
10
|
+
.split("/");
|
|
11
|
+
if (!owner || !repo) throw new Error(`Not a GitHub repo URL: ${repoUrl}`);
|
|
12
|
+
return { owner, repo };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Minimal YAML-frontmatter parser (flat key: value pairs). */
|
|
16
|
+
export function parseFrontmatter(md) {
|
|
17
|
+
const m = md.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
|
|
18
|
+
if (!m) return { data: {}, body: md.trim() };
|
|
19
|
+
const data = {};
|
|
20
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
21
|
+
const idx = line.indexOf(":");
|
|
22
|
+
if (idx === -1) continue;
|
|
23
|
+
const key = line.slice(0, idx).trim();
|
|
24
|
+
let val = line.slice(idx + 1).trim().replace(/^["']|["']$/g, "");
|
|
25
|
+
if (key) data[key] = val;
|
|
26
|
+
}
|
|
27
|
+
return { data, body: m[2].trim() };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The canonical file name for an entry's type. */
|
|
31
|
+
export function fileNameFor(entry) {
|
|
32
|
+
return entry.type === "agent" ? "AGENT.md" : "SKILL.md";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Which git ref(s) to fetch. If the entry pins a commit SHA (`rev`), we fetch
|
|
37
|
+
* exactly that commit — defeating TOCTOU (source can't change under us).
|
|
38
|
+
* Otherwise fall back to the default branch.
|
|
39
|
+
*/
|
|
40
|
+
export function refsFor(entry) {
|
|
41
|
+
return entry.rev ? [entry.rev] : ["main", "master"];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function rawUrls(entry) {
|
|
45
|
+
const { owner, repo } = parseRepo(entry.repo);
|
|
46
|
+
const base = entry.path ? entry.path.replace(/\/+$/, "") + "/" : "";
|
|
47
|
+
const file = fileNameFor(entry);
|
|
48
|
+
return refsFor(entry).map(
|
|
49
|
+
(ref) =>
|
|
50
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${base}${file}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Fetch a plugin bundle's manifest (plugin.json) listing its member entries. */
|
|
55
|
+
export async function fetchPluginManifest(entry) {
|
|
56
|
+
const { owner, repo } = parseRepo(entry.repo);
|
|
57
|
+
const base = entry.path ? entry.path.replace(/\/+$/, "") + "/" : "";
|
|
58
|
+
for (const ref of refsFor(entry)) {
|
|
59
|
+
const res = await fetch(
|
|
60
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${base}plugin.json`
|
|
61
|
+
);
|
|
62
|
+
if (res.ok) {
|
|
63
|
+
const manifest = JSON.parse(await res.text());
|
|
64
|
+
manifest.includes = Array.isArray(manifest.includes) ? manifest.includes : [];
|
|
65
|
+
return manifest;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
throw new Error(`Could not fetch plugin.json for "${entry.name}" from ${entry.repo}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Fetch + parse the canonical doc (SKILL.md or AGENT.md) for a catalog entry. */
|
|
72
|
+
export async function fetchItem(entry) {
|
|
73
|
+
for (const url of rawUrls(entry)) {
|
|
74
|
+
const res = await fetch(url);
|
|
75
|
+
if (res.ok) {
|
|
76
|
+
const md = await res.text();
|
|
77
|
+
const { data, body } = parseFrontmatter(md);
|
|
78
|
+
return {
|
|
79
|
+
md,
|
|
80
|
+
body,
|
|
81
|
+
type: entry.type || "skill",
|
|
82
|
+
name: data.name || entry.name,
|
|
83
|
+
description: data.description || entry.description || "",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Could not fetch ${fileNameFor(entry)} for "${entry.name}" from ${entry.repo}` +
|
|
89
|
+
(entry.path ? ` (path: ${entry.path})` : "")
|
|
90
|
+
);
|
|
91
|
+
}
|
package/src/store.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Tracks what's installed where, in a per-project lockfile: .skillet/installed.json
|
|
2
|
+
|
|
3
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
const dir = (cwd) => join(cwd, ".skillet");
|
|
8
|
+
const lockPath = (cwd) => join(dir(cwd), "installed.json");
|
|
9
|
+
|
|
10
|
+
export async function readLock(cwd) {
|
|
11
|
+
const p = lockPath(cwd);
|
|
12
|
+
if (!existsSync(p)) return { installed: [] };
|
|
13
|
+
try {
|
|
14
|
+
const lock = JSON.parse(await readFile(p, "utf8"));
|
|
15
|
+
return { installed: Array.isArray(lock.installed) ? lock.installed : [] };
|
|
16
|
+
} catch {
|
|
17
|
+
return { installed: [] };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function writeLock(cwd, lock) {
|
|
22
|
+
await mkdir(dir(cwd), { recursive: true });
|
|
23
|
+
await writeFile(lockPath(cwd), JSON.stringify(lock, null, 2) + "\n");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Record (or replace) an install for a given name+target. */
|
|
27
|
+
export async function recordInstall(cwd, record) {
|
|
28
|
+
const lock = await readLock(cwd);
|
|
29
|
+
lock.installed = lock.installed.filter(
|
|
30
|
+
(r) => !(r.name === record.name && r.target === record.target)
|
|
31
|
+
);
|
|
32
|
+
lock.installed.push(record);
|
|
33
|
+
await writeLock(cwd, lock);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Remove install records matching name (and optional target). Returns them. */
|
|
37
|
+
export async function removeInstall(cwd, name, target) {
|
|
38
|
+
const lock = await readLock(cwd);
|
|
39
|
+
const match = (r) => r.name === name && (!target || r.target === target);
|
|
40
|
+
const removed = lock.installed.filter(match);
|
|
41
|
+
lock.installed = lock.installed.filter((r) => !match(r));
|
|
42
|
+
await writeLock(cwd, lock);
|
|
43
|
+
return removed;
|
|
44
|
+
}
|