@greenrenge/skills 0.1.0 → 0.3.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/README.md +84 -23
- package/bin/cli.mjs +414 -123
- package/bin/lib/onboard.mjs +1179 -0
- package/bin/lib/probe.mjs +782 -0
- package/bin/lib/recipes/index.mjs +57 -0
- package/bin/lib/recipes/security-cron.mjs +1140 -0
- package/catalog.json +501 -51
- package/package.json +10 -8
- package/skills/security-remediation-epic/prompt-template.md +87 -20
- package/skills/ticket-orchestrator/SKILL.md +349 -0
- package/skills/ticket-orchestrator/references/proving-the-gates.md +63 -0
- package/skills/ticket-scheme/SKILL.md +144 -0
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host, runtime, tool, rule, and project probing for @greenrenge/skills.
|
|
3
|
+
* Zero external dependencies — Node.js built-ins only.
|
|
4
|
+
*/
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs";
|
|
7
|
+
import { arch, homedir, hostname as osHostname, platform, release, tmpdir } from "node:os";
|
|
8
|
+
import { basename, join, resolve } from "node:path";
|
|
9
|
+
|
|
10
|
+
export const TOOL_META = {
|
|
11
|
+
node: {
|
|
12
|
+
label: "Node.js (>=20)",
|
|
13
|
+
hint: {
|
|
14
|
+
darwin: "brew install node",
|
|
15
|
+
linux: "Install Node.js 20+ (nvm / fnm / distro package)",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
python3: {
|
|
19
|
+
label: "Python 3",
|
|
20
|
+
hint: {
|
|
21
|
+
darwin: "brew install python",
|
|
22
|
+
linux: "Install python3 via your package manager",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
git: {
|
|
26
|
+
label: "Git",
|
|
27
|
+
hint: {
|
|
28
|
+
darwin: "xcode-select --install",
|
|
29
|
+
linux: "Install git via your package manager",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
gh: {
|
|
33
|
+
label: "GitHub CLI (gh)",
|
|
34
|
+
hint: {
|
|
35
|
+
darwin: "brew install gh && gh auth login",
|
|
36
|
+
linux: "Install gh (https://cli.github.com) && gh auth login",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
ocr: {
|
|
40
|
+
label: "open-code-review CLI (ocr)",
|
|
41
|
+
hint: {
|
|
42
|
+
darwin: "npm install -g @alibaba-group/open-code-review && ocr config provider",
|
|
43
|
+
linux: "npm install -g @alibaba-group/open-code-review && ocr config provider",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
chromium: {
|
|
47
|
+
label: "Chromium / Chrome (headless render)",
|
|
48
|
+
hint: {
|
|
49
|
+
darwin: "Install Chrome or `brew install --cask chromium`",
|
|
50
|
+
linux: "Install chromium / google-chrome, or expose a wrapper at ~/.local/bin/chromium",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
magick: {
|
|
54
|
+
label: "ImageMagick (magick)",
|
|
55
|
+
hint: {
|
|
56
|
+
darwin: "brew install imagemagick",
|
|
57
|
+
linux: "Install imagemagick (`magick` CLI)",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
"playwright-py": {
|
|
61
|
+
label: "Python Playwright",
|
|
62
|
+
hint: {
|
|
63
|
+
darwin: "pip install playwright && playwright install chromium",
|
|
64
|
+
linux: "pip install playwright && playwright install chromium",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
wrangler: {
|
|
68
|
+
label: "Cloudflare Wrangler CLI",
|
|
69
|
+
hint: {
|
|
70
|
+
darwin: "npm install -g wrangler",
|
|
71
|
+
linux: "npm install -g wrangler",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
cf: {
|
|
75
|
+
label: "Cloudflare cf CLI",
|
|
76
|
+
hint: {
|
|
77
|
+
darwin: "npm install -g @cloudflare/cli",
|
|
78
|
+
linux: "npm install -g @cloudflare/cli",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
"osv-scanner": {
|
|
82
|
+
label: "OSV-Scanner (local lockfile audit)",
|
|
83
|
+
hint: {
|
|
84
|
+
darwin: "brew install osv-scanner",
|
|
85
|
+
linux: "Install osv-scanner (https://google.github.io/osv-scanner/)",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
"pr-lens-cache": {
|
|
89
|
+
label: "pr-lens CLI cache (~/.cache/pr-lens)",
|
|
90
|
+
hint: {
|
|
91
|
+
darwin: "Built on first run by pr-lens, or pre-install into ~/.cache/pr-lens",
|
|
92
|
+
linux: "Built on first run by pr-lens, or pre-install into ~/.cache/pr-lens",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
"pip-audit": {
|
|
96
|
+
label: "pip-audit (Python lockfile audit)",
|
|
97
|
+
hint: {
|
|
98
|
+
darwin: "uv tool install pip-audit (or pipx install pip-audit)",
|
|
99
|
+
linux: "uv tool install pip-audit (or pipx install pip-audit)",
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
pnpm: {
|
|
103
|
+
label: "pnpm (Node lockfile audit)",
|
|
104
|
+
hint: {
|
|
105
|
+
darwin: "corepack enable && corepack prepare pnpm@latest --activate",
|
|
106
|
+
linux: "corepack enable && corepack prepare pnpm@latest --activate",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
npm: {
|
|
110
|
+
label: "npm (Node lockfile audit)",
|
|
111
|
+
hint: {
|
|
112
|
+
darwin: "Bundled with Node.js",
|
|
113
|
+
linux: "Bundled with Node.js",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
"cargo-audit": {
|
|
117
|
+
label: "cargo-audit (Rust Cargo.lock audit)",
|
|
118
|
+
hint: {
|
|
119
|
+
darwin: "cargo install cargo-audit",
|
|
120
|
+
linux: "cargo install cargo-audit",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
govulncheck: {
|
|
124
|
+
label: "govulncheck (Go module vulnerability audit)",
|
|
125
|
+
hint: {
|
|
126
|
+
darwin: "go install golang.org/x/vuln/cmd/govulncheck@latest",
|
|
127
|
+
linux: "go install golang.org/x/vuln/cmd/govulncheck@latest",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
claude: {
|
|
131
|
+
label: "Claude Code CLI (claude)",
|
|
132
|
+
hint: {
|
|
133
|
+
darwin: "npm install -g @anthropic-ai/claude-code",
|
|
134
|
+
linux: "npm install -g @anthropic-ai/claude-code",
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
codex: {
|
|
138
|
+
label: "Codex CLI (codex)",
|
|
139
|
+
hint: {
|
|
140
|
+
darwin: "npm install -g @openai/codex",
|
|
141
|
+
linux: "npm install -g @openai/codex",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
opencode: {
|
|
145
|
+
label: "OpenCode CLI (opencode)",
|
|
146
|
+
hint: {
|
|
147
|
+
darwin: "brew install opencode (or npm install -g opencode-ai)",
|
|
148
|
+
linux: "npm install -g opencode-ai",
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const HOST_FACT_META = {
|
|
154
|
+
"browser-render": {
|
|
155
|
+
title: "Browser / Diagram Rendering Host Facts",
|
|
156
|
+
reason:
|
|
157
|
+
"Diagram & deck skills need to know your local headless Chromium/Chrome binary, PNG renderer fallback (Playwright / ImageMagick / Chromium), and scratch temp directory so agents do not guess every session.",
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export function toolInstallHint(toolName, plat = platform()) {
|
|
162
|
+
const meta = TOOL_META[toolName];
|
|
163
|
+
if (!meta?.hint) return "";
|
|
164
|
+
return plat === "darwin" ? meta.hint.darwin : meta.hint.linux;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function runQuick(cmd, args, { cwd, timeout = 2500 } = {}) {
|
|
168
|
+
try {
|
|
169
|
+
const out = execFileSync(cmd, args, {
|
|
170
|
+
cwd,
|
|
171
|
+
timeout,
|
|
172
|
+
encoding: "utf8",
|
|
173
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
174
|
+
});
|
|
175
|
+
return { ok: true, out: out.trim() };
|
|
176
|
+
} catch {
|
|
177
|
+
return { ok: false, out: "" };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function findInPath(names) {
|
|
182
|
+
const pathEnv = process.env.PATH ?? "";
|
|
183
|
+
const sep = process.platform === "win32" ? ";" : ":";
|
|
184
|
+
const dirs = pathEnv.split(sep).filter(Boolean);
|
|
185
|
+
for (const name of names) {
|
|
186
|
+
for (const dir of dirs) {
|
|
187
|
+
const candidate = join(dir, name);
|
|
188
|
+
if (existsSync(candidate)) return candidate;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function firstLine(str) {
|
|
195
|
+
if (!str) return "";
|
|
196
|
+
return str.split(/\r?\n/)[0].trim();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function probeSingleTool(name, homeDir) {
|
|
200
|
+
switch (name) {
|
|
201
|
+
case "node":
|
|
202
|
+
return { ok: true, path: process.execPath, version: process.version };
|
|
203
|
+
|
|
204
|
+
case "python3": {
|
|
205
|
+
const bin = findInPath(["python3", "python"]);
|
|
206
|
+
if (!bin) return { ok: false };
|
|
207
|
+
const r = runQuick(bin, ["--version"]);
|
|
208
|
+
return { ok: r.ok, path: bin, version: firstLine(r.out) };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
case "git": {
|
|
212
|
+
const bin = findInPath(["git"]);
|
|
213
|
+
if (!bin) return { ok: false };
|
|
214
|
+
const r = runQuick(bin, ["--version"]);
|
|
215
|
+
return { ok: r.ok, path: bin, version: firstLine(r.out) };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
case "gh": {
|
|
219
|
+
const bin = findInPath(["gh"]);
|
|
220
|
+
if (!bin) return { ok: false };
|
|
221
|
+
const ver = runQuick(bin, ["--version"]);
|
|
222
|
+
const auth = runQuick(bin, ["auth", "status"], { timeout: 2000 });
|
|
223
|
+
return {
|
|
224
|
+
ok: ver.ok,
|
|
225
|
+
path: bin,
|
|
226
|
+
version: firstLine(ver.out),
|
|
227
|
+
detail: auth.ok ? "authenticated" : "not authenticated (run `gh auth login`)",
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
case "ocr": {
|
|
232
|
+
const configPath = join(homeDir, ".opencodereview", "config.json");
|
|
233
|
+
let configured = false;
|
|
234
|
+
let providerLabel = "";
|
|
235
|
+
if (existsSync(configPath)) {
|
|
236
|
+
try {
|
|
237
|
+
const cfg = JSON.parse(readFileSync(configPath, "utf8"));
|
|
238
|
+
const hasCustom =
|
|
239
|
+
cfg.custom_providers && Object.keys(cfg.custom_providers).length > 0;
|
|
240
|
+
const hasBuiltin =
|
|
241
|
+
cfg.providers && Object.keys(cfg.providers).length > 0;
|
|
242
|
+
const hasLegacyLlm = Boolean(cfg.llm?.url || cfg.llm?.model || cfg.llm?.auth_token);
|
|
243
|
+
configured = Boolean(cfg.provider || hasCustom || hasBuiltin || hasLegacyLlm);
|
|
244
|
+
providerLabel =
|
|
245
|
+
cfg.provider || cfg.llm?.model || (hasCustom ? "custom" : hasBuiltin ? "configured" : "");
|
|
246
|
+
} catch {
|
|
247
|
+
configured = false;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const bin = findInPath(["ocr"]);
|
|
251
|
+
if (!bin) {
|
|
252
|
+
return { ok: false, configured, configPath, providerLabel };
|
|
253
|
+
}
|
|
254
|
+
const ver = runQuick(bin, ["--version"]);
|
|
255
|
+
return {
|
|
256
|
+
ok: true,
|
|
257
|
+
path: bin,
|
|
258
|
+
version: firstLine(ver.out) || "installed",
|
|
259
|
+
configured,
|
|
260
|
+
configPath,
|
|
261
|
+
providerLabel,
|
|
262
|
+
detail: configured
|
|
263
|
+
? `LLM provider configured${providerLabel ? ` (${providerLabel})` : ""}`
|
|
264
|
+
: "no LLM provider configured (run `ocr config provider`)",
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
case "chromium": {
|
|
269
|
+
const pathBin = findInPath([
|
|
270
|
+
"chromium",
|
|
271
|
+
"chromium-browser",
|
|
272
|
+
"google-chrome",
|
|
273
|
+
"google-chrome-stable",
|
|
274
|
+
]);
|
|
275
|
+
const extraCandidates = [
|
|
276
|
+
join(homeDir, ".local", "bin", "chromium"),
|
|
277
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
278
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
279
|
+
"/usr/bin/chromium",
|
|
280
|
+
"/usr/bin/chromium-browser",
|
|
281
|
+
"/usr/bin/google-chrome",
|
|
282
|
+
];
|
|
283
|
+
const bin = pathBin ?? extraCandidates.find((p) => existsSync(p)) ?? null;
|
|
284
|
+
if (!bin) return { ok: false };
|
|
285
|
+
return { ok: true, path: bin, version: basename(bin) };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
case "magick": {
|
|
289
|
+
const bin = findInPath(["magick"]);
|
|
290
|
+
if (!bin) return { ok: false };
|
|
291
|
+
const ver = runQuick(bin, ["--version"]);
|
|
292
|
+
return { ok: true, path: bin, version: firstLine(ver.out) };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
case "playwright-py": {
|
|
296
|
+
const py = findInPath(["python3", "python"]);
|
|
297
|
+
if (!py) return { ok: false };
|
|
298
|
+
const r = runQuick(py, ["-c", "import playwright; print('ok')"], { timeout: 3000 });
|
|
299
|
+
return { ok: r.ok && r.out.includes("ok"), path: py, version: r.ok ? "python playwright" : "" };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
case "wrangler": {
|
|
303
|
+
const bin = findInPath(["wrangler"]);
|
|
304
|
+
if (!bin) return { ok: false };
|
|
305
|
+
const ver = runQuick(bin, ["--version"]);
|
|
306
|
+
return { ok: true, path: bin, version: firstLine(ver.out) };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
case "cf": {
|
|
310
|
+
const bin = findInPath(["cf"]);
|
|
311
|
+
if (!bin) return { ok: false };
|
|
312
|
+
const ver = runQuick(bin, ["--version"]);
|
|
313
|
+
return { ok: true, path: bin, version: firstLine(ver.out) };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
case "osv-scanner": {
|
|
317
|
+
const bin = findInPath(["osv-scanner"]);
|
|
318
|
+
if (!bin) return { ok: false };
|
|
319
|
+
const ver = runQuick(bin, ["--version"]);
|
|
320
|
+
return { ok: true, path: bin, version: firstLine(ver.out) };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
case "pr-lens-cache": {
|
|
324
|
+
const cacheBin = join(homeDir, ".cache", "pr-lens", "node_modules", ".bin", "pr-lens");
|
|
325
|
+
if (existsSync(cacheBin)) {
|
|
326
|
+
return { ok: true, path: cacheBin, version: "cached" };
|
|
327
|
+
}
|
|
328
|
+
const pathBin = findInPath(["pr-lens"]);
|
|
329
|
+
if (pathBin) {
|
|
330
|
+
return { ok: true, path: pathBin, version: "in PATH" };
|
|
331
|
+
}
|
|
332
|
+
return { ok: false };
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
case "pip-audit":
|
|
336
|
+
case "pnpm":
|
|
337
|
+
case "npm":
|
|
338
|
+
case "cargo-audit":
|
|
339
|
+
case "govulncheck":
|
|
340
|
+
case "claude":
|
|
341
|
+
case "codex":
|
|
342
|
+
case "opencode": {
|
|
343
|
+
const bin = findInPath([name]);
|
|
344
|
+
if (!bin) return { ok: false };
|
|
345
|
+
const verFlag = name === "govulncheck" ? "-version" : "--version";
|
|
346
|
+
const ver = runQuick(bin, [verFlag], { timeout: 2500 });
|
|
347
|
+
return { ok: true, path: bin, version: firstLine(ver.out) || "installed" };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
default: {
|
|
351
|
+
const bin = findInPath([name]);
|
|
352
|
+
return bin ? { ok: true, path: bin } : { ok: false };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function detectTmpfsTmp() {
|
|
358
|
+
if (platform() !== "linux") return false;
|
|
359
|
+
try {
|
|
360
|
+
const mounts = readFileSync("/proc/mounts", "utf8");
|
|
361
|
+
return mounts.split(/\r?\n/).some((line) => {
|
|
362
|
+
const parts = line.split(" ");
|
|
363
|
+
return parts[1] === "/tmp" && parts[2] === "tmpfs";
|
|
364
|
+
});
|
|
365
|
+
} catch {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function safeRealpath(p) {
|
|
371
|
+
try {
|
|
372
|
+
return realpathSync(p);
|
|
373
|
+
} catch {
|
|
374
|
+
return resolve(p);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function scanRuleFiles(dirs, matcher) {
|
|
379
|
+
const found = [];
|
|
380
|
+
const seenReal = new Set();
|
|
381
|
+
for (const dir of dirs) {
|
|
382
|
+
if (!dir || !existsSync(dir)) continue;
|
|
383
|
+
let entries = [];
|
|
384
|
+
try {
|
|
385
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
386
|
+
} catch {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
for (const entry of entries) {
|
|
390
|
+
if (!entry.isFile() && !entry.isSymbolicLink()) continue;
|
|
391
|
+
if (!entry.name.endsWith(".md")) continue;
|
|
392
|
+
const full = join(dir, entry.name);
|
|
393
|
+
const real = safeRealpath(full);
|
|
394
|
+
if (seenReal.has(real)) continue;
|
|
395
|
+
if (matcher(entry.name, full)) {
|
|
396
|
+
seenReal.add(real);
|
|
397
|
+
found.push(full);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return found;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function probeProject(projectDir) {
|
|
405
|
+
if (!projectDir || !existsSync(projectDir)) return null;
|
|
406
|
+
const dir = resolve(projectDir);
|
|
407
|
+
const gitTop = runQuick("git", ["rev-parse", "--show-toplevel"], { cwd: dir });
|
|
408
|
+
const isGitRepo = gitTop.ok;
|
|
409
|
+
const repoRoot = isGitRepo ? gitTop.out : dir;
|
|
410
|
+
const name = basename(repoRoot) || "project";
|
|
411
|
+
|
|
412
|
+
let defaultBranch = "main";
|
|
413
|
+
if (isGitRepo) {
|
|
414
|
+
const headRef = runQuick("git", ["symbolic-ref", "refs/remotes/origin/HEAD"], { cwd: repoRoot });
|
|
415
|
+
if (headRef.ok && headRef.out) {
|
|
416
|
+
defaultBranch = headRef.out.split("/").pop() || "main";
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const hasOcrRules = existsSync(join(repoRoot, ".opencodereview", "rule.json"));
|
|
421
|
+
let bootstrapCommand = "";
|
|
422
|
+
for (const cand of ["tools/bootstrap.sh", "scripts/bootstrap.sh"]) {
|
|
423
|
+
if (existsSync(join(repoRoot, cand))) {
|
|
424
|
+
bootstrapCommand = cand;
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const verifyTargets = [];
|
|
430
|
+
const gateConfigPaths = [];
|
|
431
|
+
const pkgPath = join(repoRoot, "package.json");
|
|
432
|
+
if (existsSync(pkgPath)) {
|
|
433
|
+
gateConfigPaths.push("package.json");
|
|
434
|
+
try {
|
|
435
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
436
|
+
const scripts = pkg.scripts ?? {};
|
|
437
|
+
for (const k of ["lint", "typecheck", "test", "build"]) {
|
|
438
|
+
if (scripts[k]) verifyTargets.push(k);
|
|
439
|
+
}
|
|
440
|
+
} catch {
|
|
441
|
+
// ignore malformed package.json
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (existsSync(join(repoRoot, "pyproject.toml"))) {
|
|
445
|
+
gateConfigPaths.push("pyproject.toml");
|
|
446
|
+
if (verifyTargets.length === 0) verifyTargets.push("pytest");
|
|
447
|
+
}
|
|
448
|
+
if (existsSync(join(repoRoot, "Cargo.toml"))) {
|
|
449
|
+
gateConfigPaths.push("Cargo.toml");
|
|
450
|
+
if (verifyTargets.length === 0) verifyTargets.push("cargo test");
|
|
451
|
+
}
|
|
452
|
+
if (existsSync(join(repoRoot, "go.mod"))) {
|
|
453
|
+
gateConfigPaths.push("go.mod");
|
|
454
|
+
if (verifyTargets.length === 0) verifyTargets.push("go test ./...");
|
|
455
|
+
}
|
|
456
|
+
if (hasOcrRules) {
|
|
457
|
+
gateConfigPaths.push(".opencodereview/rule.json");
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
dir: repoRoot,
|
|
462
|
+
name,
|
|
463
|
+
isGitRepo,
|
|
464
|
+
defaultBranch,
|
|
465
|
+
hasOcrRules,
|
|
466
|
+
bootstrapCommand,
|
|
467
|
+
verifyTargets,
|
|
468
|
+
gateConfigPaths,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export function probeHost({ projectDir = null, onlyTools = null } = {}) {
|
|
473
|
+
const homeDir = homedir();
|
|
474
|
+
let rawHost = osHostname() || "localhost";
|
|
475
|
+
if (platform() === "linux" && existsSync("/etc/hostname")) {
|
|
476
|
+
try {
|
|
477
|
+
const staticName = readFileSync("/etc/hostname", "utf8").trim();
|
|
478
|
+
if (staticName) rawHost = staticName;
|
|
479
|
+
} catch {
|
|
480
|
+
// fall back to os.hostname()
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const shortHostname = rawHost
|
|
484
|
+
.split(".")[0]
|
|
485
|
+
.toLowerCase()
|
|
486
|
+
.replace(/[^a-z0-9._-]/g, "-") || "localhost";
|
|
487
|
+
|
|
488
|
+
const toolList = onlyTools ? [...onlyTools] : Object.keys(TOOL_META);
|
|
489
|
+
const tools = {};
|
|
490
|
+
for (const name of toolList) {
|
|
491
|
+
tools[name] = probeSingleTool(name, homeDir);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const agentsRulesDir = join(homeDir, ".agents", "rules");
|
|
495
|
+
const claudeDir = join(homeDir, ".claude");
|
|
496
|
+
const claudeRulesDir = join(claudeDir, "rules");
|
|
497
|
+
const claudeDirExists = existsSync(claudeDir);
|
|
498
|
+
const claudeSharesAgentsRules =
|
|
499
|
+
existsSync(agentsRulesDir) &&
|
|
500
|
+
existsSync(claudeRulesDir) &&
|
|
501
|
+
safeRealpath(agentsRulesDir) === safeRealpath(claudeRulesDir);
|
|
502
|
+
|
|
503
|
+
const project = probeProject(projectDir);
|
|
504
|
+
|
|
505
|
+
const hostProfilePaths = scanRuleFiles([agentsRulesDir, claudeRulesDir], (fname) =>
|
|
506
|
+
/^host-.*\.md$/i.test(fname) || fname.toLowerCase() === "host-profile.md",
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
const contractSearchDirs = [agentsRulesDir, claudeRulesDir];
|
|
510
|
+
if (project?.dir) {
|
|
511
|
+
contractSearchDirs.push(join(project.dir, "docs", "agents"));
|
|
512
|
+
}
|
|
513
|
+
const contractPaths = scanRuleFiles(contractSearchDirs, (fname) =>
|
|
514
|
+
/(?:^|[-_])contract(?:[-_.]|\.md$)/i.test(fname) || /^orchestrator-contract\.md$/i.test(fname),
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
return {
|
|
518
|
+
host: {
|
|
519
|
+
hostname: rawHost,
|
|
520
|
+
shortHostname,
|
|
521
|
+
platform: platform(),
|
|
522
|
+
arch: arch(),
|
|
523
|
+
release: release(),
|
|
524
|
+
tmpdir: process.env.TMPDIR || tmpdir(),
|
|
525
|
+
isTmpfsTmp: detectTmpfsTmp(),
|
|
526
|
+
homeDir,
|
|
527
|
+
},
|
|
528
|
+
tools,
|
|
529
|
+
rules: {
|
|
530
|
+
agentsRulesDir,
|
|
531
|
+
claudeDir,
|
|
532
|
+
claudeRulesDir,
|
|
533
|
+
claudeDirExists,
|
|
534
|
+
claudeSharesAgentsRules,
|
|
535
|
+
hostProfilePaths,
|
|
536
|
+
contractPaths,
|
|
537
|
+
},
|
|
538
|
+
project,
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export function collectToolsToProbe(skillNames, catalog) {
|
|
543
|
+
const set = new Set(["node"]);
|
|
544
|
+
let needsBrowserFacts = false;
|
|
545
|
+
for (const name of skillNames) {
|
|
546
|
+
const req = catalog.skills[name]?.requires ?? {};
|
|
547
|
+
for (const t of req.tools ?? []) set.add(t);
|
|
548
|
+
for (const t of req.optionalTools ?? []) set.add(t);
|
|
549
|
+
for (const group of req.anyOfTools ?? []) {
|
|
550
|
+
for (const t of group) set.add(t);
|
|
551
|
+
}
|
|
552
|
+
if (req.hostFacts?.includes("browser-render")) {
|
|
553
|
+
needsBrowserFacts = true;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if (needsBrowserFacts) {
|
|
557
|
+
set.add("chromium");
|
|
558
|
+
set.add("magick");
|
|
559
|
+
set.add("playwright-py");
|
|
560
|
+
set.add("pr-lens-cache");
|
|
561
|
+
}
|
|
562
|
+
return set;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export function evaluateRequirements(skillNames, catalog, probeResult) {
|
|
566
|
+
const requiredToolsMap = new Map();
|
|
567
|
+
const anyOfMap = new Map();
|
|
568
|
+
const optionalToolsMap = new Map();
|
|
569
|
+
const harnessMap = new Map();
|
|
570
|
+
const hostFactsMap = new Map();
|
|
571
|
+
const runContractBy = [];
|
|
572
|
+
|
|
573
|
+
for (const name of skillNames) {
|
|
574
|
+
const skill = catalog.skills[name];
|
|
575
|
+
const req = skill?.requires ?? {};
|
|
576
|
+
|
|
577
|
+
for (const t of req.tools ?? []) {
|
|
578
|
+
if (!requiredToolsMap.has(t)) requiredToolsMap.set(t, []);
|
|
579
|
+
requiredToolsMap.get(t).push(name);
|
|
580
|
+
}
|
|
581
|
+
for (const group of req.anyOfTools ?? []) {
|
|
582
|
+
const key = [...group].sort().join("|");
|
|
583
|
+
if (!anyOfMap.has(key)) anyOfMap.set(key, { tools: group, skills: [] });
|
|
584
|
+
anyOfMap.get(key).skills.push(name);
|
|
585
|
+
}
|
|
586
|
+
for (const t of req.optionalTools ?? []) {
|
|
587
|
+
if (!optionalToolsMap.has(t)) optionalToolsMap.set(t, []);
|
|
588
|
+
optionalToolsMap.get(t).push(name);
|
|
589
|
+
}
|
|
590
|
+
if (req.harness) {
|
|
591
|
+
if (!harnessMap.has(req.harness)) harnessMap.set(req.harness, { requiredBy: [], optionalBy: [] });
|
|
592
|
+
harnessMap.get(req.harness).requiredBy.push(name);
|
|
593
|
+
}
|
|
594
|
+
if (req.optionalHarness) {
|
|
595
|
+
if (!harnessMap.has(req.optionalHarness)) {
|
|
596
|
+
harnessMap.set(req.optionalHarness, { requiredBy: [], optionalBy: [] });
|
|
597
|
+
}
|
|
598
|
+
harnessMap.get(req.optionalHarness).optionalBy.push(name);
|
|
599
|
+
}
|
|
600
|
+
for (const fact of req.hostFacts ?? []) {
|
|
601
|
+
if (!hostFactsMap.has(fact)) hostFactsMap.set(fact, []);
|
|
602
|
+
hostFactsMap.get(fact).push(name);
|
|
603
|
+
}
|
|
604
|
+
if (req.runContract) {
|
|
605
|
+
runContractBy.push(name);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Remove optional tools that are already in requiredToolsMap
|
|
610
|
+
for (const t of requiredToolsMap.keys()) {
|
|
611
|
+
optionalToolsMap.delete(t);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
const requiredTools = [];
|
|
615
|
+
for (const [tool, skills] of requiredToolsMap) {
|
|
616
|
+
const status = probeResult.tools[tool] ?? { ok: false };
|
|
617
|
+
requiredTools.push({
|
|
618
|
+
tool,
|
|
619
|
+
label: TOOL_META[tool]?.label ?? tool,
|
|
620
|
+
ok: Boolean(status.ok),
|
|
621
|
+
status,
|
|
622
|
+
skills,
|
|
623
|
+
hint: toolInstallHint(tool, probeResult.host.platform),
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const anyOfGroups = [];
|
|
628
|
+
for (const { tools, skills } of anyOfMap.values()) {
|
|
629
|
+
const satisfiedBy = tools.filter((t) => probeResult.tools[t]?.ok);
|
|
630
|
+
anyOfGroups.push({
|
|
631
|
+
tools,
|
|
632
|
+
ok: satisfiedBy.length > 0,
|
|
633
|
+
satisfiedBy,
|
|
634
|
+
skills,
|
|
635
|
+
hints: tools.map((t) => ({ tool: t, hint: toolInstallHint(t, probeResult.host.platform) })),
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const optionalTools = [];
|
|
640
|
+
for (const [tool, skills] of optionalToolsMap) {
|
|
641
|
+
const status = probeResult.tools[tool] ?? { ok: false };
|
|
642
|
+
optionalTools.push({
|
|
643
|
+
tool,
|
|
644
|
+
label: TOOL_META[tool]?.label ?? tool,
|
|
645
|
+
ok: Boolean(status.ok),
|
|
646
|
+
status,
|
|
647
|
+
skills,
|
|
648
|
+
hint: toolInstallHint(tool, probeResult.host.platform),
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const hostFacts = [];
|
|
653
|
+
for (const [fact, skills] of hostFactsMap) {
|
|
654
|
+
hostFacts.push({
|
|
655
|
+
fact,
|
|
656
|
+
title: HOST_FACT_META[fact]?.title ?? fact,
|
|
657
|
+
reason: HOST_FACT_META[fact]?.reason ?? "",
|
|
658
|
+
skills,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const needsHostFacts = hostFacts.length > 0;
|
|
663
|
+
const hostProfileFound = probeResult.rules.hostProfilePaths.length > 0;
|
|
664
|
+
const needsRunContract = runContractBy.length > 0;
|
|
665
|
+
const contractFound = probeResult.rules.contractPaths.length > 0;
|
|
666
|
+
|
|
667
|
+
const ocrReq = requiredTools.find((r) => r.tool === "ocr") ?? null;
|
|
668
|
+
const ocrSkills = ocrReq ? ocrReq.skills : [];
|
|
669
|
+
const ocrStatus = ocrReq ? ocrReq.status : (probeResult.tools.ocr ?? null);
|
|
670
|
+
const ocrInstalled = Boolean(ocrStatus?.ok);
|
|
671
|
+
const ocrConfigured = Boolean(ocrStatus?.configured);
|
|
672
|
+
const needsOcrSetup = ocrSkills.length > 0 && (!ocrInstalled || !ocrConfigured);
|
|
673
|
+
|
|
674
|
+
const missingRequiredCount =
|
|
675
|
+
requiredTools.filter((r) => !r.ok).length + anyOfGroups.filter((g) => !g.ok).length;
|
|
676
|
+
const warningCount =
|
|
677
|
+
optionalTools.filter((r) => !r.ok).length +
|
|
678
|
+
(needsHostFacts && !hostProfileFound ? 1 : 0) +
|
|
679
|
+
(needsRunContract && !contractFound ? 1 : 0) +
|
|
680
|
+
(ocrSkills.length > 0 && ocrInstalled && !ocrConfigured ? 1 : 0);
|
|
681
|
+
|
|
682
|
+
return {
|
|
683
|
+
requiredTools,
|
|
684
|
+
anyOfGroups,
|
|
685
|
+
optionalTools,
|
|
686
|
+
harnesses: [...harnessMap.entries()].map(([name, info]) => ({ name, ...info })),
|
|
687
|
+
hostFacts,
|
|
688
|
+
needsHostFacts,
|
|
689
|
+
hostProfileFound,
|
|
690
|
+
needsRunContract,
|
|
691
|
+
runContractBy,
|
|
692
|
+
contractFound,
|
|
693
|
+
ocrSkills,
|
|
694
|
+
ocrStatus,
|
|
695
|
+
ocrInstalled,
|
|
696
|
+
ocrConfigured,
|
|
697
|
+
needsOcrSetup,
|
|
698
|
+
missingRequiredCount,
|
|
699
|
+
warningCount,
|
|
700
|
+
hasIssues: missingRequiredCount > 0 || warningCount > 0,
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Parse a git remote URL into "owner/repo" when it points at a GitHub-like host.
|
|
707
|
+
*/
|
|
708
|
+
export function parseOwnerRepo(remoteUrl) {
|
|
709
|
+
if (!remoteUrl || typeof remoteUrl !== "string") return null;
|
|
710
|
+
const trimmed = remoteUrl.trim().replace(/\.git$/, "");
|
|
711
|
+
// git@github.com:owner/repo or ssh://git@github.com/owner/repo or https://github.com/owner/repo
|
|
712
|
+
const sshColon = trimmed.match(/^[^@]+@[^:]+:([^/]+\/[^/]+)$/);
|
|
713
|
+
if (sshColon) return sshColon[1];
|
|
714
|
+
const urlMatch = trimmed.match(/^[a-z+]+:\/\/[^/]+\/([^/]+\/[^/]+)$/i);
|
|
715
|
+
if (urlMatch) return urlMatch[1];
|
|
716
|
+
return null;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Inspect a repository for security-remediation prerequisites: git remote,
|
|
721
|
+
* default branch, lockfiles/ecosystems, and recommended scanners.
|
|
722
|
+
*/
|
|
723
|
+
export function probeSecurityRepo(projectDir) {
|
|
724
|
+
const dir = resolve(projectDir || process.cwd());
|
|
725
|
+
const remoteRes = runQuick("git", ["-C", dir, "remote", "get-url", "origin"], { timeout: 2000 });
|
|
726
|
+
const remoteUrl = remoteRes.ok ? firstLine(remoteRes.out) : null;
|
|
727
|
+
const ownerRepo = parseOwnerRepo(remoteUrl);
|
|
728
|
+
|
|
729
|
+
let defaultBranch = "main";
|
|
730
|
+
const headSym = runQuick("git", ["-C", dir, "symbolic-ref", "refs/remotes/origin/HEAD"], {
|
|
731
|
+
timeout: 2000,
|
|
732
|
+
});
|
|
733
|
+
if (headSym.ok && headSym.out.trim()) {
|
|
734
|
+
const parts = headSym.out.trim().split("/");
|
|
735
|
+
defaultBranch = parts[parts.length - 1] || "main";
|
|
736
|
+
} else {
|
|
737
|
+
const curBranch = runQuick("git", ["-C", dir, "rev-parse", "--abbrev-ref", "HEAD"], {
|
|
738
|
+
timeout: 2000,
|
|
739
|
+
});
|
|
740
|
+
if (curBranch.ok && curBranch.out.trim() && curBranch.out.trim() !== "HEAD") {
|
|
741
|
+
defaultBranch = curBranch.out.trim();
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
const lockfileSpecs = [
|
|
746
|
+
{ file: "pnpm-lock.yaml", ecosystem: "node", scanner: "pnpm" },
|
|
747
|
+
{ file: "package-lock.json", ecosystem: "node", scanner: "npm" },
|
|
748
|
+
{ file: "yarn.lock", ecosystem: "node", scanner: "osv-scanner" },
|
|
749
|
+
{ file: "bun.lock", ecosystem: "node", scanner: "osv-scanner" },
|
|
750
|
+
{ file: "bun.lockb", ecosystem: "node", scanner: "osv-scanner" },
|
|
751
|
+
{ file: "uv.lock", ecosystem: "python", scanner: "pip-audit" },
|
|
752
|
+
{ file: "poetry.lock", ecosystem: "python", scanner: "pip-audit" },
|
|
753
|
+
{ file: "requirements.txt", ecosystem: "python", scanner: "pip-audit" },
|
|
754
|
+
{ file: "Cargo.lock", ecosystem: "rust", scanner: "cargo-audit" },
|
|
755
|
+
{ file: "go.mod", ecosystem: "go", scanner: "govulncheck" },
|
|
756
|
+
];
|
|
757
|
+
|
|
758
|
+
const lockfiles = [];
|
|
759
|
+
const ecosystems = new Set();
|
|
760
|
+
const scanners = new Set(["osv-scanner"]);
|
|
761
|
+
|
|
762
|
+
for (const spec of lockfileSpecs) {
|
|
763
|
+
if (existsSync(join(dir, spec.file))) {
|
|
764
|
+
lockfiles.push(spec.file);
|
|
765
|
+
ecosystems.add(spec.ecosystem);
|
|
766
|
+
scanners.add(spec.scanner);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return {
|
|
771
|
+
dir,
|
|
772
|
+
repoSlug: basename(dir),
|
|
773
|
+
remoteUrl,
|
|
774
|
+
ownerRepo,
|
|
775
|
+
defaultBranch,
|
|
776
|
+
lockfiles,
|
|
777
|
+
ecosystems: [...ecosystems],
|
|
778
|
+
recommendedScanners: [...scanners],
|
|
779
|
+
existingPrompt: existsSync(join(dir, ".agents", "prompts", "security-remediation.md")),
|
|
780
|
+
existingWorkflow: existsSync(join(dir, ".github", "workflows", "security-remediation-cron.yml")),
|
|
781
|
+
};
|
|
782
|
+
}
|