skillscout 0.0.0-stage → 0.1.1
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 +128 -2
- package/dist/cli.js +181 -0
- package/dist/fetchSkill.js +111 -0
- package/dist/index.js +287 -0
- package/dist/install.js +269 -0
- package/dist/mcpConfig.js +79 -0
- package/dist/paths.js +19 -0
- package/dist/profile.js +193 -0
- package/dist/ref.js +59 -0
- package/dist/relevance.js +121 -0
- package/dist/sanitize.js +32 -0
- package/dist/scan/llm.js +147 -0
- package/dist/scan/rules.js +243 -0
- package/dist/search.js +179 -0
- package/dist/sources/github.js +111 -0
- package/dist/sources/http.js +47 -0
- package/dist/sources/mcpRegistry.js +26 -0
- package/dist/sources/osv.js +55 -0
- package/dist/sources/packages.js +180 -0
- package/dist/sources/remoteProbe.js +59 -0
- package/dist/sources/safeFetch.js +52 -0
- package/dist/sources/skillssh.js +50 -0
- package/dist/types.js +8 -0
- package/dist/updates.js +152 -0
- package/dist/verdict.js +147 -0
- package/dist/vetCache.js +22 -0
- package/dist/vetMcp.js +297 -0
- package/dist/vetPlugin.js +221 -0
- package/dist/vetSkill.js +75 -0
- package/package.json +54 -4
- package/skills/skillscout/SKILL.md +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ThomasXin50
|
|
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
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
#
|
|
1
|
+
# skillscout
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An MCP server that helps Claude Code find the right **skills**, **MCP servers** and **plugins** for a project. It **vets them for security** and installs them **pinned**. It also has a CLI that audits the skills already in a repo, for use in CI.
|
|
4
|
+
|
|
5
|
+
It doesn't scrape or host anything. It searches existing catalogs and adds the parts they're missing. The catalogs are [skills.sh](https://skills.sh), the [official MCP Registry](https://registry.modelcontextprotocol.io), and GitHub code search, which is optional and also used for plugins. The parts it adds:
|
|
6
|
+
|
|
7
|
+
- **Recommendations based on the project.** It profiles the repo locally and turns what it finds into search queries. Only technology tags such as `nextjs` or `prisma` leave your machine. Results are ranked by fit: matching your stack and what you said you want to do raises a result, and targeting a stack you don't use lowers it. Near-duplicates are folded together.
|
|
8
|
+
- **The same checks for every catalog.** The same checks run no matter where an item came from.
|
|
9
|
+
- **Untrusted text stays out of Claude's context.** Third-party files are only read by the scanners. Claude sees a verdict, never the raw files.
|
|
10
|
+
- **Pinning and re-vetting.** Installs are pinned to a commit or version, checked against the vetted content hash, and recorded in a lockfile. Updates are vetted again before you upgrade. Remote MCP servers are re-probed for changes to their tool lists.
|
|
11
|
+
|
|
12
|
+
## Tools
|
|
13
|
+
|
|
14
|
+
| Tool | What it does |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `recommend` | Profiles the project, then searches and ranks matching skills, MCP servers and plugins. It also reports how much context your installed skills already use |
|
|
17
|
+
| `profile_project` | Languages, frameworks, services, what's installed, how much context it uses, suggested queries (local only) |
|
|
18
|
+
| `search` | Searches skills.sh / MCP Registry / GitHub directly |
|
|
19
|
+
| `vet_skill` | Fetches a skill at a fixed commit into a quarantine folder and runs every check → allow / review / block |
|
|
20
|
+
| `vet_mcp_server` | Vets a registry entry: package source, install scripts, dependencies, known vulnerabilities and malware, provenance, remote tool descriptions |
|
|
21
|
+
| `vet_plugin` | Vets a Claude Code plugin. Every hook command is listed, bundled MCP servers are checked for version pinning, and all files are scanned |
|
|
22
|
+
| `install_skill` | Installs exactly the vetted content at the vetted commit |
|
|
23
|
+
| `install_mcp_server` | Writes a version-pinned entry (secrets as `${ENV}` placeholders) |
|
|
24
|
+
| `install_plugin` | Copies exactly the vetted plugin files into a local `skillscout` marketplace and installs from there, so the plugin can't change after vetting |
|
|
25
|
+
| `uninstall` | Removes something skillscout installed. A skill you edited locally is only removed with `force` |
|
|
26
|
+
| `check_updates` | Detects local edits, finds upstream changes, re-vets them; never upgrades automatically |
|
|
27
|
+
|
|
28
|
+
## CLI: audit skills in CI
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx skillscout audit [dirs...] [--format text|json|sarif] [--fail-on block|review] [--llm]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
It scans `./.claude/skills` by default; pass directories to scan others (for example `~/.claude/skills`). For each skill it reports whether the skill matches the lockfile, was modified, or isn't managed by skillscout. It exits with code 1 when any skill reaches the `--fail-on` level, which defaults to `block`. Use `--format sarif` to upload results to GitHub code scanning.
|
|
35
|
+
|
|
36
|
+
## What gets checked
|
|
37
|
+
|
|
38
|
+
| Check | Skills | Plugins | MCP (npm) | MCP (PyPI) | MCP (remote) |
|
|
39
|
+
|---|---|---|---|---|---|
|
|
40
|
+
| Static rules (download-and-execute, reverse shells, credential access + network, environment dumps, exfiltration endpoints, persistence, crypto miners, agent-config tampering, obfuscation, hidden Unicode / HTML comments, broad `allowed-tools`, bundled binaries) | ✓ | ✓ | ✓ package source | ✓ sdist / wheel | ✓ tool descriptions |
|
|
41
|
+
| Hook commands (run automatically, so each one is listed) | – | ✓ | – | – | – |
|
|
42
|
+
| Separate model review (no tools, output must match a JSON schema, file delimiters use a random nonce) | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
43
|
+
| Known malware and vulnerabilities ([OSV](https://osv.dev), including the OpenSSF malicious-packages feed) | – | – | ✓ package + direct deps | ✓ package | – |
|
|
44
|
+
| Install-time scripts | template `package.json` | – | ✓ package + direct deps | – | – |
|
|
45
|
+
| Partner audits (Gen, Socket, Snyk via skills.sh) | ✓ | – | – | – | – |
|
|
46
|
+
| Provenance (stars, repo age, license, archived, publish date, downloads, registry namespace) | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
47
|
+
| Pinned install | commit SHA + content hash | commit SHA + content hash | exact version | exact version | URL (can change, so always "review") |
|
|
48
|
+
|
|
49
|
+
**How the verdict is decided:**
|
|
50
|
+
- **block**: any critical signal, or a high static finding. Known malware is always critical.
|
|
51
|
+
- **review**: a high or medium rating from the model review or partner audits, or code that hasn't had a model review. Plugins with hooks always need review.
|
|
52
|
+
- **allow**: anything else. "Allow" means nothing raised a flag. It is not proof of safety.
|
|
53
|
+
|
|
54
|
+
**One exception, for MCP package code only.** A clean model review can lower a static **block** to **review**, never to allow. Security tools, skillscout included, contain the very patterns the rules look for, and a model can tell a detection signature from a payload. All of these must hold:
|
|
55
|
+
- the review rated the package `safe` or `low`
|
|
56
|
+
- the review found that the behavior matches the description, and raised no high finding of its own
|
|
57
|
+
- every blocking finding is in a code file the reviewer actually read
|
|
58
|
+
|
|
59
|
+
The exception never applies to:
|
|
60
|
+
- skills or plugins
|
|
61
|
+
- findings in markdown or remote tool descriptions
|
|
62
|
+
- known malware (OSV), hidden Unicode, or bundled binaries
|
|
63
|
+
|
|
64
|
+
The verdict says when this happened.
|
|
65
|
+
|
|
66
|
+
Rules grade each hit in context. For example, `curl https://vendor… | bash` in a skill's setup docs is medium. The same pattern is critical from a raw IP, over plain http, from a paste site, or inside a script. Findings in files the agent never loads are capped at low/medium: package READMEs, and a plugin's tests and docs. A skill's own markdown is not capped, because it *is* the agent's instructions.
|
|
67
|
+
|
|
68
|
+
## How accurate is it?
|
|
69
|
+
|
|
70
|
+
`npm run eval` downloads two public, labeled datasets plus popular skills.sh skills, and measures the static rules on them. Downloaded samples are kept as JSON in `eval/.data/` and are never executed. The datasets are [MalSkillBench](https://github.com/lxyeternal/MalSkillBench) (for academic research use only) and [TongxiQu/agent-skill-malware](https://huggingface.co/datasets/TongxiQu/agent-skill-malware) (MIT). Latest static-only results, with no model review:
|
|
71
|
+
|
|
72
|
+
| Set | n | Flagged (block or review) | Blocked |
|
|
73
|
+
|---|---|---|---|
|
|
74
|
+
| MalSkillBench malicious: code injection / mixed / prompt injection / in the wild | 38 each | 71% / 61% / 74% / 63% | 47% / 42% / 40% / 34% |
|
|
75
|
+
| HF agent-skill-malware, malicious | 124 | 56% | 48% |
|
|
76
|
+
| MalSkillBench benign (popular skills) | 150 | 13% | 3.3% |
|
|
77
|
+
| HF agent-skill-malware, benign | 223 | 5.4% | 1.8% |
|
|
78
|
+
| skills.sh top 75 | 75 | 11% | 4.0% |
|
|
79
|
+
|
|
80
|
+
The static rules alone miss about a third of malicious samples. Most of those are semantic: for example, "monitoring" that downloads and runs a miner, or telemetry that sends the hostname to an attacker's domain. That's what the model review and the human approval step are for. The rules were tuned on MalSkillBench. The HF set wasn't used for tuning, so treat its numbers as the less optimistic ones.
|
|
81
|
+
|
|
82
|
+
`npm run eval -- --llm --llm-n 100 --yes` measures the model review too. It is billed: it prints an estimate first and does nothing without `--yes`.
|
|
83
|
+
|
|
84
|
+
## Setup
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm install && npm run build
|
|
88
|
+
claude mcp add --scope user skillscout -- node /absolute/path/to/skillscout/dist/index.js
|
|
89
|
+
cp -r skills/skillscout ~/.claude/skills/ # tells Claude when and how to use the tools
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Environment:
|
|
93
|
+
|
|
94
|
+
- `ANTHROPIC_API_KEY`: turns on the model review. Without it, items containing code get **review** instead of **allow**. The model is set by `SKILLSCOUT_MODEL` (default `claude-opus-5-5`). Set `SKILLSCOUT_LLM_REVIEW=off` to turn the review off.
|
|
95
|
+
- `GITHUB_TOKEN`, or a logged-in `gh`: higher GitHub rate limits. It is required for plugin search and `include_github` skill search.
|
|
96
|
+
- `SKILLSCOUT_CACHE_DIR`: where quarantine copies and verdicts are kept (default `~/.cache/skillscout`). Verdicts are cached by commit SHA or version, so vetting something a second time is instant.
|
|
97
|
+
|
|
98
|
+
## Files it writes
|
|
99
|
+
|
|
100
|
+
- `<project>/.claude/skills/<name>/` or `~/.claude/skills/<name>/`: installed skills. It never overwrites a skill it didn't install.
|
|
101
|
+
- `<project>/.mcp.json`: project MCP servers. It never replaces an entry it doesn't manage.
|
|
102
|
+
- `~/.claude.json`: user-scope MCP servers. This goes through `claude mcp add-json` when the CLI is available. Otherwise the file is edited atomically, with a `.skillscout.bak` backup.
|
|
103
|
+
- `~/.claude/skillscout-marketplace/`: pinned copies of installed plugins. They are installed with `claude plugin install <name> --marketplace <that dir>`.
|
|
104
|
+
- `<project>/.claude/skillscout.lock.json` or `~/.claude/skillscout.lock.json`: the pins.
|
|
105
|
+
|
|
106
|
+
## Network safety
|
|
107
|
+
|
|
108
|
+
Remote MCP probing only lists tools and never calls one. It goes through a guarded fetch with these protections:
|
|
109
|
+
- https only
|
|
110
|
+
- no redirects
|
|
111
|
+
- private, loopback, link-local and CGNAT addresses are refused, whether given as IP literals or reached by DNS
|
|
112
|
+
- the address check runs inside the connection's own DNS lookup, so DNS rebinding can't get around it
|
|
113
|
+
|
|
114
|
+
## Known limits
|
|
115
|
+
|
|
116
|
+
- The static rules are pattern-based. A determined attacker can get past them, which is why there's a separate model review and a human approval step.
|
|
117
|
+
- Only direct npm dependencies are checked, for install scripts and OSV advisories. Python dependencies and container images aren't scanned.
|
|
118
|
+
- Remote MCP servers can change at any time. `check_updates` re-probes them, but between checks you're trusting the operator.
|
|
119
|
+
- Plugin `dependencies` on other plugins aren't followed. A remote MCP server bundled in a plugin is only reported, not vetted.
|
|
120
|
+
- Project-scope plugin installs pin to a copy in *your* home directory. Teammates need to install the plugin themselves.
|
|
121
|
+
|
|
122
|
+
## Development
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npm test # unit tests (no network)
|
|
126
|
+
npm run typecheck
|
|
127
|
+
npm run dev # run the server from source
|
|
128
|
+
npm run eval # detection accuracy (downloads datasets; static rules only unless --llm)
|
|
129
|
+
```
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { lstat, readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
|
+
import { parseFrontmatter, hashFiles, LIMITS } from "./fetchSkill.js";
|
|
4
|
+
import { readLock } from "./install.js";
|
|
5
|
+
import { sanitize } from "./sanitize.js";
|
|
6
|
+
import { llmReview } from "./scan/llm.js";
|
|
7
|
+
import { scanFiles } from "./scan/rules.js";
|
|
8
|
+
import { decide } from "./verdict.js";
|
|
9
|
+
const CODE_EXT = /\.(sh|bash|zsh|fish|py|js|mjs|cjs|ts|rb|pl|php|ps1|bat|cmd|go|rs|lua)$/i;
|
|
10
|
+
const HELP = `skillscout audit [dir ...] [options]
|
|
11
|
+
|
|
12
|
+
Scan locally installed skills (default: ./.claude/skills) and report a verdict for each.
|
|
13
|
+
Each argument may be a skills directory (containing <name>/SKILL.md) or a single skill directory.
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
--format text|json|sarif Output format (default: text)
|
|
17
|
+
--fail-on block|review Exit 1 if any skill reaches this verdict (default: block)
|
|
18
|
+
--llm Also run the model review (needs ANTHROPIC_API_KEY; billed)
|
|
19
|
+
-h, --help Show this help
|
|
20
|
+
`;
|
|
21
|
+
export async function runCli(argv) {
|
|
22
|
+
const args = argv.slice(argv.indexOf("audit") + 1);
|
|
23
|
+
let format = "text";
|
|
24
|
+
let failOn = "block";
|
|
25
|
+
let llm = false;
|
|
26
|
+
const dirs = [];
|
|
27
|
+
for (let i = 0; i < args.length; i++) {
|
|
28
|
+
const a = args[i];
|
|
29
|
+
if (a === "-h" || a === "--help") {
|
|
30
|
+
process.stdout.write(HELP);
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
else if (a === "--format")
|
|
34
|
+
format = args[++i] ?? "text";
|
|
35
|
+
else if (a === "--fail-on")
|
|
36
|
+
failOn = (args[++i] ?? "block");
|
|
37
|
+
else if (a === "--llm")
|
|
38
|
+
llm = true;
|
|
39
|
+
else
|
|
40
|
+
dirs.push(a);
|
|
41
|
+
}
|
|
42
|
+
if (!["text", "json", "sarif"].includes(format) || !["block", "review"].includes(failOn)) {
|
|
43
|
+
process.stderr.write(HELP);
|
|
44
|
+
return 2;
|
|
45
|
+
}
|
|
46
|
+
const roots = dirs.length ? dirs : [".claude/skills"];
|
|
47
|
+
const results = [];
|
|
48
|
+
for (const root of roots) {
|
|
49
|
+
for (const dir of await skillDirs(resolve(root)))
|
|
50
|
+
results.push(await auditSkill(dir, llm));
|
|
51
|
+
}
|
|
52
|
+
if (format === "json")
|
|
53
|
+
process.stdout.write(JSON.stringify(results, null, 2) + "\n");
|
|
54
|
+
else if (format === "sarif")
|
|
55
|
+
process.stdout.write(JSON.stringify(toSarif(results), null, 2) + "\n");
|
|
56
|
+
else
|
|
57
|
+
printText(results);
|
|
58
|
+
const failing = results.filter((r) => r.verdict === "block" || (failOn === "review" && r.verdict === "review"));
|
|
59
|
+
return failing.length ? 1 : 0;
|
|
60
|
+
}
|
|
61
|
+
async function skillDirs(root) {
|
|
62
|
+
if (await exists(join(root, "SKILL.md")))
|
|
63
|
+
return [root];
|
|
64
|
+
const entries = await readdir(root, { withFileTypes: true }).catch(() => []);
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const e of entries)
|
|
67
|
+
if (e.isDirectory() && (await exists(join(root, e.name, "SKILL.md"))))
|
|
68
|
+
out.push(join(root, e.name));
|
|
69
|
+
return out.sort();
|
|
70
|
+
}
|
|
71
|
+
async function exists(p) {
|
|
72
|
+
return lstat(p).then(() => true, () => false);
|
|
73
|
+
}
|
|
74
|
+
async function readSkillFiles(dir) {
|
|
75
|
+
const files = [];
|
|
76
|
+
const skipped = [];
|
|
77
|
+
let total = 0;
|
|
78
|
+
async function walk(d) {
|
|
79
|
+
for (const e of await readdir(d, { withFileTypes: true })) {
|
|
80
|
+
const full = join(d, e.name);
|
|
81
|
+
const rel = relative(dir, full);
|
|
82
|
+
if (e.isSymbolicLink())
|
|
83
|
+
skipped.push({ path: rel, reason: "symlink" });
|
|
84
|
+
else if (e.isDirectory())
|
|
85
|
+
await walk(full);
|
|
86
|
+
else if (e.isFile()) {
|
|
87
|
+
const st = await lstat(full);
|
|
88
|
+
if (files.length >= LIMITS.maxFiles)
|
|
89
|
+
skipped.push({ path: rel, reason: "file count limit" });
|
|
90
|
+
else if (st.size > LIMITS.maxFileBytes)
|
|
91
|
+
skipped.push({ path: rel, reason: "file too large" });
|
|
92
|
+
else if (total + st.size > LIMITS.maxTotalBytes)
|
|
93
|
+
skipped.push({ path: rel, reason: "total size limit" });
|
|
94
|
+
else {
|
|
95
|
+
total += st.size;
|
|
96
|
+
files.push({ path: rel, content: await readFile(full), executable: (st.mode & 0o111) !== 0 });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
await walk(dir);
|
|
102
|
+
return { files, skipped };
|
|
103
|
+
}
|
|
104
|
+
async function auditSkill(dir, useLlm) {
|
|
105
|
+
const { files, skipped } = await readSkillFiles(dir);
|
|
106
|
+
const md = files.find((f) => f.path === "SKILL.md");
|
|
107
|
+
const fm = md ? parseFrontmatter(md.content.toString("utf8")) : {};
|
|
108
|
+
const name = sanitize(fm.name ?? dir.split("/").pop(), 100);
|
|
109
|
+
const findings = scanFiles(files);
|
|
110
|
+
for (const s of skipped)
|
|
111
|
+
findings.push({ rule: "not-scanned", severity: "medium", file: s.path, message: `Not scanned: ${s.reason}` });
|
|
112
|
+
const codeFiles = files.filter((f) => f.executable || CODE_EXT.test(f.path)).map((f) => f.path);
|
|
113
|
+
const llm = useLlm
|
|
114
|
+
? await llmReview({ kind: "skill", name, description: sanitize(fm.description, 1200), files })
|
|
115
|
+
: { status: "skipped", reason: "Model review not requested (--llm)." };
|
|
116
|
+
// In CI the static rules are the gate; missing model review alone should not fail a build.
|
|
117
|
+
const { verdict, risk, reasons } = decide({
|
|
118
|
+
staticFindings: findings,
|
|
119
|
+
llm,
|
|
120
|
+
partnerAudits: [],
|
|
121
|
+
hasCode: useLlm && codeFiles.length > 0,
|
|
122
|
+
codeNote: `${codeFiles.length} code file(s)`,
|
|
123
|
+
});
|
|
124
|
+
return { dir, name, verdict, risk, reasons, findings: [...findings, ...(llm.findings ?? [])], llm: { ...llm, findings: undefined }, lock: await lockStatus(dir, files) };
|
|
125
|
+
}
|
|
126
|
+
async function lockStatus(dir, files) {
|
|
127
|
+
// <project>/.claude/skills/<name> -> lockfile at <project>/.claude/skillscout.lock.json
|
|
128
|
+
const m = dir.match(/^(.*)\/\.claude\/skills\/([^/]+)$/);
|
|
129
|
+
if (!m)
|
|
130
|
+
return undefined;
|
|
131
|
+
const lock = await readLock("project", m[1]);
|
|
132
|
+
const entry = lock.entries[`skill:${m[2]}`];
|
|
133
|
+
if (!entry)
|
|
134
|
+
return "unmanaged";
|
|
135
|
+
return hashFiles(files) === entry.contentHash ? "matches" : "modified";
|
|
136
|
+
}
|
|
137
|
+
function printText(results) {
|
|
138
|
+
if (!results.length) {
|
|
139
|
+
process.stdout.write("No skills found.\n");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
for (const r of results) {
|
|
143
|
+
const mark = r.verdict === "allow" ? "ok " : r.verdict === "review" ? "REVIEW" : "BLOCK";
|
|
144
|
+
process.stdout.write(`${mark.padEnd(6)} ${r.name} (${r.dir})${r.lock === "modified" ? " [modified since install]" : ""}\n`);
|
|
145
|
+
for (const f of r.findings.filter((x) => x.severity !== "info")) {
|
|
146
|
+
process.stdout.write(` ${f.severity.padEnd(8)} ${f.rule} ${f.file}${f.line ? ":" + f.line : ""} ${f.message}\n`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const n = (v) => results.filter((r) => r.verdict === v).length;
|
|
150
|
+
process.stdout.write(`\n${results.length} skill(s): ${n("allow")} ok, ${n("review")} review, ${n("block")} block\n`);
|
|
151
|
+
}
|
|
152
|
+
function toSarif(results) {
|
|
153
|
+
const level = (s) => (s === "critical" || s === "high" ? "error" : s === "medium" ? "warning" : "note");
|
|
154
|
+
const rules = new Map();
|
|
155
|
+
const sarifResults = results.flatMap((r) => r.findings
|
|
156
|
+
.filter((f) => f.severity !== "info")
|
|
157
|
+
.map((f) => {
|
|
158
|
+
if (!rules.has(f.rule))
|
|
159
|
+
rules.set(f.rule, { id: f.rule, shortDescription: { text: f.message } });
|
|
160
|
+
return {
|
|
161
|
+
ruleId: f.rule,
|
|
162
|
+
level: level(f.severity),
|
|
163
|
+
message: { text: `[${r.name}] ${f.message}${f.excerpt ? `: ${f.excerpt}` : ""}` },
|
|
164
|
+
properties: { severity: f.severity, skill: r.name, verdict: r.verdict },
|
|
165
|
+
locations: [
|
|
166
|
+
{
|
|
167
|
+
physicalLocation: {
|
|
168
|
+
artifactLocation: { uri: relative(process.cwd(), join(r.dir, f.file)) },
|
|
169
|
+
...(f.line ? { region: { startLine: f.line } } : {}),
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
};
|
|
174
|
+
}));
|
|
175
|
+
return {
|
|
176
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
177
|
+
version: "2.1.0",
|
|
178
|
+
runs: [{ tool: { driver: { name: "skillscout", informationUri: "https://github.com", rules: [...rules.values()] } }, results: sarifResults }],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { parse as parseYaml } from "yaml";
|
|
5
|
+
import { getRawFile, getTree, resolveCommit } from "./sources/github.js";
|
|
6
|
+
import { cacheDir } from "./paths.js";
|
|
7
|
+
export const LIMITS = {
|
|
8
|
+
maxFiles: 300,
|
|
9
|
+
maxFileBytes: 1_000_000,
|
|
10
|
+
maxTotalBytes: 5_000_000,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Fetch a skill directory at a pinned commit into a quarantine directory.
|
|
14
|
+
* Nothing fetched here is ever executed or loaded into the agent's context;
|
|
15
|
+
* it is only read by the scanners and, after approval, copied on install.
|
|
16
|
+
*/
|
|
17
|
+
export async function fetchSkill(ref) {
|
|
18
|
+
const sha = await resolveCommit(ref.owner, ref.repo, ref.ref);
|
|
19
|
+
const tree = await getTree(ref.owner, ref.repo, sha);
|
|
20
|
+
const path = ref.path ?? (await locateSkillDir(ref, sha, tree));
|
|
21
|
+
const prefix = path ? path + "/" : "";
|
|
22
|
+
const entries = tree.filter((e) => e.type === "blob" && (path === "" ? true : e.path.startsWith(prefix)));
|
|
23
|
+
if (!entries.some((e) => e.path === `${prefix}SKILL.md`)) {
|
|
24
|
+
throw new Error(`No SKILL.md found at ${ref.owner}/${ref.repo}:${path || "(root)"}@${sha.slice(0, 12)}`);
|
|
25
|
+
}
|
|
26
|
+
// Root-level skills: do not slurp the whole repo, only the skill-shaped parts.
|
|
27
|
+
const scoped = path === "" ? entries.filter((e) => !e.path.includes("/") || /^(scripts|references|assets|templates)\//.test(e.path)) : entries;
|
|
28
|
+
const skipped = [];
|
|
29
|
+
const wanted = [];
|
|
30
|
+
let total = 0;
|
|
31
|
+
for (const e of scoped.sort((a, b) => a.path.localeCompare(b.path))) {
|
|
32
|
+
const rel = e.path.slice(prefix.length);
|
|
33
|
+
if (wanted.length >= LIMITS.maxFiles)
|
|
34
|
+
skipped.push({ path: rel, reason: "file count limit" });
|
|
35
|
+
else if ((e.size ?? 0) > LIMITS.maxFileBytes)
|
|
36
|
+
skipped.push({ path: rel, reason: `file larger than ${LIMITS.maxFileBytes} bytes` });
|
|
37
|
+
else if (total + (e.size ?? 0) > LIMITS.maxTotalBytes)
|
|
38
|
+
skipped.push({ path: rel, reason: "total size limit" });
|
|
39
|
+
else if (e.mode === "120000")
|
|
40
|
+
skipped.push({ path: rel, reason: "symlink" });
|
|
41
|
+
else {
|
|
42
|
+
total += e.size ?? 0;
|
|
43
|
+
wanted.push({ e, rel });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const files = await mapLimit(wanted, 8, async ({ e, rel }) => {
|
|
47
|
+
const content = await getRawFile(ref.owner, ref.repo, sha, e.path, LIMITS.maxFileBytes);
|
|
48
|
+
return { path: rel, size: content.length, executable: e.mode === "100755", content };
|
|
49
|
+
});
|
|
50
|
+
const contentHash = hashFiles(files);
|
|
51
|
+
const quarantineDir = join(cacheDir(), "quarantine", `${ref.owner}__${ref.repo}__${sha.slice(0, 12)}`, path || "_root");
|
|
52
|
+
await rm(quarantineDir, { recursive: true, force: true });
|
|
53
|
+
for (const f of files) {
|
|
54
|
+
const dest = join(quarantineDir, f.path);
|
|
55
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
56
|
+
await writeFile(dest, f.content, { mode: 0o644 }); // never executable in quarantine
|
|
57
|
+
}
|
|
58
|
+
return { ref, sha, path, files, skipped, contentHash, quarantineDir };
|
|
59
|
+
}
|
|
60
|
+
export async function mapLimit(items, limit, fn) {
|
|
61
|
+
const out = new Array(items.length);
|
|
62
|
+
let i = 0;
|
|
63
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
64
|
+
while (i < items.length) {
|
|
65
|
+
const idx = i++;
|
|
66
|
+
out[idx] = await fn(items[idx]);
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
export function hashFiles(files) {
|
|
72
|
+
const h = createHash("sha256");
|
|
73
|
+
for (const f of [...files].sort((a, b) => a.path.localeCompare(b.path))) {
|
|
74
|
+
h.update(f.path).update("\0").update(createHash("sha256").update(f.content).digest()).update("\0");
|
|
75
|
+
}
|
|
76
|
+
return "sha256:" + h.digest("hex");
|
|
77
|
+
}
|
|
78
|
+
async function locateSkillDir(ref, sha, tree) {
|
|
79
|
+
const skillMds = tree.filter((e) => e.type === "blob" && /(^|\/)SKILL\.md$/.test(e.path)).map((e) => e.path);
|
|
80
|
+
if (skillMds.length === 0)
|
|
81
|
+
throw new Error(`${ref.owner}/${ref.repo} contains no SKILL.md files`);
|
|
82
|
+
const dirOf = (p) => p.replace(/\/?SKILL\.md$/, "");
|
|
83
|
+
const base = (p) => dirOf(p).split("/").pop() ?? "";
|
|
84
|
+
const want = ref.skill.toLowerCase();
|
|
85
|
+
const byDir = skillMds.filter((p) => base(p).toLowerCase() === want).sort((a, b) => a.length - b.length);
|
|
86
|
+
if (byDir[0])
|
|
87
|
+
return dirOf(byDir[0]);
|
|
88
|
+
// Fall back to matching frontmatter `name:` (bounded).
|
|
89
|
+
for (const p of skillMds.slice(0, 40)) {
|
|
90
|
+
const buf = await getRawFile(ref.owner, ref.repo, sha, p, 200_000);
|
|
91
|
+
const fm = parseFrontmatter(buf.toString("utf8"));
|
|
92
|
+
if (String(fm.name ?? "").toLowerCase() === want)
|
|
93
|
+
return dirOf(p);
|
|
94
|
+
}
|
|
95
|
+
if (skillMds.length === 1 && skillMds[0] === "SKILL.md")
|
|
96
|
+
return "";
|
|
97
|
+
throw new Error(`Could not find a skill named "${ref.skill}" in ${ref.owner}/${ref.repo}`);
|
|
98
|
+
}
|
|
99
|
+
export function parseFrontmatter(text) {
|
|
100
|
+
const m = text.match(/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---/);
|
|
101
|
+
if (!m)
|
|
102
|
+
return {};
|
|
103
|
+
try {
|
|
104
|
+
const v = parseYaml(m[1]);
|
|
105
|
+
return v && typeof v === "object" ? v : {};
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=fetchSkill.js.map
|