@uinaf/agent-plugin-stuff 0.0.0-bootstrap.0 → 2.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/LICENSE +21 -0
- package/README.md +62 -2
- package/dist/cli.js +734 -0
- package/dist/grok-provider.js +189 -0
- package/dist/lint.js +107 -0
- package/dist/plugin.js +158 -0
- package/dist/plugincheck.js +38 -0
- package/dist/rulecheck.js +38 -0
- package/dist/rules.js +179 -0
- package/dist/scenario.js +484 -0
- package/dist/skill-evidence.js +70 -0
- package/dist/transform.js +75 -0
- package/docs/adoption.md +51 -0
- package/docs/scenarios.md +124 -0
- package/docs/usage.md +210 -0
- package/package.json +69 -4
package/dist/rules.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
// src/rules.ts
|
|
4
|
+
const ALLOWED_MDC_KEYS = /* @__PURE__ */ new Set([
|
|
5
|
+
"description",
|
|
6
|
+
"alwaysApply",
|
|
7
|
+
"globs",
|
|
8
|
+
"trigger"
|
|
9
|
+
]);
|
|
10
|
+
const ALLOWED_TRIGGERS = /* @__PURE__ */ new Set([
|
|
11
|
+
"always_on",
|
|
12
|
+
"model_decision",
|
|
13
|
+
"glob",
|
|
14
|
+
"manual"
|
|
15
|
+
]);
|
|
16
|
+
function normalizeText(raw) {
|
|
17
|
+
return raw.replaceAll(/\r\n?/g, "\n");
|
|
18
|
+
}
|
|
19
|
+
function checkRelativeLinks(body, dir, label, errors) {
|
|
20
|
+
const cleaned = body.replaceAll(/^```[\s\S]*?^```/gm, "").replaceAll(/`[^`\n]*`/g, "");
|
|
21
|
+
for (const link of cleaned.matchAll(/\]\(\s*(<[^>\n]*>|[^)\s]+)(?:\s+"[^"\n]*")?\s*\)/g)) {
|
|
22
|
+
const target = link[1].replace(/^<(.*)>$/, "$1");
|
|
23
|
+
if (/^[a-z][a-z+.-]*:/.test(target) || target.startsWith("#") || target === "") continue;
|
|
24
|
+
const resolved = path.join(dir, target.split("#")[0]);
|
|
25
|
+
if (!fs.existsSync(resolved)) errors.push(`${label}: link target does not exist: ${target}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function parseMdc(text, label, errors) {
|
|
29
|
+
const lines = text.split("\n");
|
|
30
|
+
if (lines[0] !== "---") {
|
|
31
|
+
errors.push(`${label}: frontmatter must open with --- on line 1`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const close = lines.indexOf("---", 1);
|
|
35
|
+
if (close === -1) {
|
|
36
|
+
errors.push(`${label}: frontmatter never closes`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const fields = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const line of lines.slice(1, close)) {
|
|
41
|
+
const m = line.match(/^([A-Za-z][A-Za-z0-9_-]*):\s*(.*)$/);
|
|
42
|
+
if (!m) {
|
|
43
|
+
errors.push(`${label}: unparseable frontmatter line: ${line}`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const [, key, raw] = m;
|
|
47
|
+
if (!ALLOWED_MDC_KEYS.has(key)) {
|
|
48
|
+
errors.push(`${label}: unknown frontmatter key: ${key}`);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (fields.has(key)) {
|
|
52
|
+
errors.push(`${label}: duplicate frontmatter key: ${key}`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const value = raw.replace(/^"(.*)"$/s, "$1").replace(/^'(.*)'$/s, "$1").trim();
|
|
56
|
+
fields.set(key, {
|
|
57
|
+
raw: raw.trim(),
|
|
58
|
+
value
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const alwaysApply = fields.get("alwaysApply");
|
|
62
|
+
if (alwaysApply === void 0) errors.push(`${label}: alwaysApply is required (true or false)`);
|
|
63
|
+
else if (alwaysApply.raw !== "true" && alwaysApply.raw !== "false") errors.push(`${label}: alwaysApply must be true or false, got ${JSON.stringify(alwaysApply.raw)}`);
|
|
64
|
+
const description = fields.get("description");
|
|
65
|
+
if (description !== void 0 && description.value === "") errors.push(`${label}: description must be non-empty`);
|
|
66
|
+
const globs = fields.get("globs");
|
|
67
|
+
if (globs !== void 0 && globs.value === "") errors.push(`${label}: globs must be non-empty`);
|
|
68
|
+
const trigger = fields.get("trigger");
|
|
69
|
+
if (trigger !== void 0 && !ALLOWED_TRIGGERS.has(trigger.value)) errors.push(`${label}: invalid trigger: ${JSON.stringify(trigger.value)}`);
|
|
70
|
+
if (alwaysApply?.raw === "true" && !description?.value) errors.push(`${label}: description is required when alwaysApply is true`);
|
|
71
|
+
if (alwaysApply?.raw === "false" && !description?.value && !globs?.value) errors.push(`${label}: description or globs is required when alwaysApply is false`);
|
|
72
|
+
return {
|
|
73
|
+
fields,
|
|
74
|
+
body: lines.slice(close + 1).join("\n")
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function resolveDeclaredRulePaths(rawRules, root, manifestLabel, errors) {
|
|
78
|
+
if (typeof rawRules === "string") {
|
|
79
|
+
const full = path.resolve(root, rawRules);
|
|
80
|
+
if (!fs.existsSync(full)) {
|
|
81
|
+
errors.push(`${manifestLabel}: rules path does not exist: ${rawRules}`);
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
if (fs.statSync(full).isDirectory()) return fs.readdirSync(full, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".mdc")).map((entry) => path.relative(root, path.join(full, entry.name)).replaceAll("\\", "/")).sort();
|
|
85
|
+
if (!rawRules.endsWith(".mdc")) errors.push(`${manifestLabel}: rule path must end with .mdc: ${rawRules}`);
|
|
86
|
+
return [path.relative(root, full).replaceAll("\\", "/")];
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(rawRules)) {
|
|
89
|
+
const declared = [];
|
|
90
|
+
for (const item of rawRules) {
|
|
91
|
+
if (typeof item !== "string" || item.trim() === "") {
|
|
92
|
+
errors.push(`${manifestLabel}: rules entries must be non-empty strings`);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const full = path.resolve(root, item);
|
|
96
|
+
if (!fs.existsSync(full)) {
|
|
97
|
+
errors.push(`${manifestLabel}: listed rule does not exist: ${item}`);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (!item.endsWith(".mdc")) errors.push(`${manifestLabel}: rule path must end with .mdc: ${item}`);
|
|
101
|
+
declared.push(path.relative(root, full).replaceAll("\\", "/"));
|
|
102
|
+
}
|
|
103
|
+
return declared;
|
|
104
|
+
}
|
|
105
|
+
errors.push(`${manifestLabel}: rules must be a string path or an array of .mdc paths`);
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
function readCursorManifest(manifestPath, manifestLabel, errors) {
|
|
109
|
+
let parsed;
|
|
110
|
+
try {
|
|
111
|
+
parsed = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
112
|
+
} catch (error) {
|
|
113
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
114
|
+
errors.push(`${manifestLabel}: invalid JSON: ${message}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
118
|
+
errors.push(`${manifestLabel}: manifest must be a JSON object`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
return parsed;
|
|
122
|
+
}
|
|
123
|
+
function lintRules(root) {
|
|
124
|
+
const rulesDir = path.join(root, "rules");
|
|
125
|
+
const cursorManifestPath = path.join(root, ".cursor-plugin/plugin.json");
|
|
126
|
+
const hasRulesDir = fs.existsSync(rulesDir) && fs.statSync(rulesDir).isDirectory();
|
|
127
|
+
const hasCursorManifest = fs.existsSync(cursorManifestPath);
|
|
128
|
+
if (!hasRulesDir && !hasCursorManifest) return {
|
|
129
|
+
errors: [],
|
|
130
|
+
count: 0
|
|
131
|
+
};
|
|
132
|
+
const errors = [];
|
|
133
|
+
const entries = hasRulesDir ? fs.readdirSync(rulesDir, { withFileTypes: true }).filter((e) => e.isFile() && !e.name.startsWith(".")) : [];
|
|
134
|
+
const mdNames = entries.filter((e) => e.name.endsWith(".md")).map((e) => e.name.slice(0, -3)).sort();
|
|
135
|
+
const mdcNames = entries.filter((e) => e.name.endsWith(".mdc")).map((e) => e.name.slice(0, -4)).sort();
|
|
136
|
+
const mdSet = new Set(mdNames);
|
|
137
|
+
const mdcSet = new Set(mdcNames);
|
|
138
|
+
const mdBodies = /* @__PURE__ */ new Map();
|
|
139
|
+
for (const name of mdNames) {
|
|
140
|
+
const file = path.join(rulesDir, `${name}.md`);
|
|
141
|
+
const label = path.relative(root, file).replaceAll("\\", "/");
|
|
142
|
+
const text = normalizeText(fs.readFileSync(file, "utf8"));
|
|
143
|
+
const trimmed = text.trim();
|
|
144
|
+
if (trimmed === "") errors.push(`${label}: rule file is empty`);
|
|
145
|
+
else if (trimmed === "---" || trimmed.startsWith("---\n")) errors.push(`${label}: bare .md rule must not contain YAML frontmatter`);
|
|
146
|
+
else checkRelativeLinks(text, rulesDir, label, errors);
|
|
147
|
+
mdBodies.set(name, trimmed);
|
|
148
|
+
if (hasCursorManifest && !mdcSet.has(name)) errors.push(`${label}: missing Cursor copy rules/${name}.mdc`);
|
|
149
|
+
}
|
|
150
|
+
for (const name of mdcNames) {
|
|
151
|
+
const file = path.join(rulesDir, `${name}.mdc`);
|
|
152
|
+
const label = path.relative(root, file).replaceAll("\\", "/");
|
|
153
|
+
const parsed = parseMdc(normalizeText(fs.readFileSync(file, "utf8")), label, errors);
|
|
154
|
+
if (parsed === void 0) continue;
|
|
155
|
+
const bodyTrimmed = parsed.body.trim();
|
|
156
|
+
if (bodyTrimmed === "") errors.push(`${label}: rule body is empty`);
|
|
157
|
+
else if (!mdSet.has(name)) checkRelativeLinks(parsed.body, rulesDir, label, errors);
|
|
158
|
+
const mdBody = mdBodies.get(name);
|
|
159
|
+
if (mdBody !== void 0 && bodyTrimmed !== mdBody) errors.push(`${label}: body differs from rules/${name}.md`);
|
|
160
|
+
}
|
|
161
|
+
if (hasCursorManifest) {
|
|
162
|
+
const manifestLabel = ".cursor-plugin/plugin.json";
|
|
163
|
+
const manifest = readCursorManifest(cursorManifestPath, manifestLabel, errors);
|
|
164
|
+
if (manifest !== void 0 && (mdcNames.length > 0 || manifest.rules !== void 0)) {
|
|
165
|
+
if (manifest.rules === void 0) errors.push(`${manifestLabel}: missing rules field for rules/*.mdc`);
|
|
166
|
+
else {
|
|
167
|
+
const declared = resolveDeclaredRulePaths(manifest.rules, root, manifestLabel, errors);
|
|
168
|
+
const expected = mdcNames.map((name) => `rules/${name}.mdc`);
|
|
169
|
+
for (const rel of expected) if (!declared.includes(rel)) errors.push(`${manifestLabel}: missing ${rel} in rules`);
|
|
170
|
+
for (const rel of declared) if (rel.endsWith(".mdc") && !expected.includes(rel)) errors.push(`${manifestLabel}: listed rule ${rel} is outside rules/*.mdc`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
errors,
|
|
176
|
+
count: (/* @__PURE__ */ new Set([...mdNames, ...mdcNames])).size
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export { lintRules };
|
package/dist/scenario.js
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { SKIPPED_DIRS } from "./transform.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
// src/scenario.ts
|
|
8
|
+
const FILE_BLOCK = /^=+ FILE: (.+?) =+\n([\s\S]*?)\n=+ END FILE =+$/gm;
|
|
9
|
+
const DEFAULT_CLAUDE_AGENT = "claude-opus-5";
|
|
10
|
+
function loadScenario(scenarioDir) {
|
|
11
|
+
const match = scenarioDir.match(/skills\/([^/]+)\/evals\/([^/]+)$/);
|
|
12
|
+
if (!match) throw new Error(`not a scenario dir (want .../skills/<skill>/evals/<scenario>): ${scenarioDir}`);
|
|
13
|
+
const [, skill, scenario] = match;
|
|
14
|
+
const taskMd = fs.readFileSync(path.join(scenarioDir, "task.md"), "utf8");
|
|
15
|
+
const skillDir = path.resolve(scenarioDir, "../..");
|
|
16
|
+
const hidden = isHiddenSkill(fs.readFileSync(path.join(skillDir, "SKILL.md"), "utf8"));
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = parseCriteria(scenarioDir, hidden);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
22
|
+
throw new Error(`${path.join(scenarioDir, "criteria.json")}: ${message}`, { cause: error });
|
|
23
|
+
}
|
|
24
|
+
const { criteria, alternatives } = parsed;
|
|
25
|
+
const files = [];
|
|
26
|
+
const task = taskMd.replaceAll(FILE_BLOCK, (_, name, content) => {
|
|
27
|
+
files.push({
|
|
28
|
+
name: name.trim(),
|
|
29
|
+
content: content + "\n"
|
|
30
|
+
});
|
|
31
|
+
return `(Input file \`${name.trim()}\` is available in your working directory.)`;
|
|
32
|
+
});
|
|
33
|
+
const prompt = hidden ? `Use the ${skill} skill for this task.\n\n${task}` : task;
|
|
34
|
+
return {
|
|
35
|
+
skill,
|
|
36
|
+
scenario,
|
|
37
|
+
name: `${skill}--${scenario}`,
|
|
38
|
+
skillDir,
|
|
39
|
+
alternatives,
|
|
40
|
+
prompt,
|
|
41
|
+
task,
|
|
42
|
+
files,
|
|
43
|
+
criteria
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function parseCriteria(scenarioDir, hidden) {
|
|
47
|
+
const text = fs.readFileSync(path.join(scenarioDir, "criteria.json"), "utf8");
|
|
48
|
+
let criteria;
|
|
49
|
+
try {
|
|
50
|
+
criteria = JSON.parse(text);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new Error(`not valid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
53
|
+
}
|
|
54
|
+
if (typeof criteria !== "object" || criteria === null || Array.isArray(criteria)) throw new Error("must be a JSON object");
|
|
55
|
+
if (criteria.type !== "weighted_checklist") throw new Error(`type must be "weighted_checklist", got ${JSON.stringify(criteria.type)}`);
|
|
56
|
+
if (!Array.isArray(criteria.checklist) || criteria.checklist.length === 0) throw new Error("checklist must be a non-empty array");
|
|
57
|
+
if (criteria.skill_use !== void 0 && ![
|
|
58
|
+
"required",
|
|
59
|
+
"optional",
|
|
60
|
+
"forbidden"
|
|
61
|
+
].includes(criteria.skill_use)) throw new Error(`skill_use must be "required", "optional", or "forbidden"`);
|
|
62
|
+
for (const [i, item] of criteria.checklist.entries()) {
|
|
63
|
+
for (const key of ["name", "description"]) {
|
|
64
|
+
const value = item?.[key];
|
|
65
|
+
if (typeof value !== "string" || value.trim() === "") throw new Error(`checklist[${i}].${key} must be a non-empty string`);
|
|
66
|
+
}
|
|
67
|
+
if (!Number.isFinite(item.max_score) || item.max_score <= 0) throw new Error(`checklist[${i}].max_score must be a positive number`);
|
|
68
|
+
}
|
|
69
|
+
if (hidden && (criteria.skill_use === "forbidden" || criteria.install !== void 0)) throw new Error("a hidden skill is always invoked, so it has no routing to test");
|
|
70
|
+
const alternatives = resolveInstall(path.resolve(scenarioDir, "../.."), criteria.install);
|
|
71
|
+
return {
|
|
72
|
+
criteria,
|
|
73
|
+
alternatives
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function resolveInstall(skillDir, install) {
|
|
77
|
+
if (install === void 0) return [];
|
|
78
|
+
const skillsRoot = path.dirname(skillDir);
|
|
79
|
+
const self = path.basename(skillDir);
|
|
80
|
+
const invocable = (name) => {
|
|
81
|
+
const dir = path.join(skillsRoot, name);
|
|
82
|
+
const md = path.join(dir, "SKILL.md");
|
|
83
|
+
return name !== self && !name.startsWith(".") && fs.lstatSync(dir, { throwIfNoEntry: false })?.isDirectory() === true && fs.lstatSync(md, { throwIfNoEntry: false })?.isFile() === true && !isHiddenSkill(fs.readFileSync(md, "utf8"));
|
|
84
|
+
};
|
|
85
|
+
if (install === "all") {
|
|
86
|
+
const all = fs.readdirSync(skillsRoot).filter(invocable).sort();
|
|
87
|
+
if (all.length === 0) throw new Error(`install "all" finds no other model-invocable skill`);
|
|
88
|
+
return all;
|
|
89
|
+
}
|
|
90
|
+
if (!Array.isArray(install) || install.length === 0) throw new Error(`install must be "all" or a non-empty list of skills`);
|
|
91
|
+
for (const name of install) if (typeof name !== "string" || name.includes("/") || !invocable(name)) throw new Error(`install names ${JSON.stringify(name)}, not another model-invocable skill under the root`);
|
|
92
|
+
return [...new Set(install)].sort();
|
|
93
|
+
}
|
|
94
|
+
function encodeRunNamePart(part) {
|
|
95
|
+
if (!part.includes("--") && !part.startsWith("-") && !part.endsWith("-") && !part.startsWith("~v2~")) return part;
|
|
96
|
+
return `~v2~${encodeURIComponent(part).replaceAll("-", "%2D").replaceAll("~", "%7E")}`;
|
|
97
|
+
}
|
|
98
|
+
function runNameFor(scenarioDir, harness, control = false) {
|
|
99
|
+
const m = path.resolve(scenarioDir).match(/skills\/([^/]+)\/evals\/([^/]+)$/);
|
|
100
|
+
if (!m) throw new Error(`not a scenario dir (want .../skills/<skill>/evals/<scenario>): ${scenarioDir}`);
|
|
101
|
+
const name = `${encodeRunNamePart(m[1])}--${encodeRunNamePart(m[2])}`;
|
|
102
|
+
const full = `${harness === "claude" ? name : `${name}--${harness}`}${control ? "--control" : ""}`;
|
|
103
|
+
if (Buffer.byteLength(`${full}.json.attempt`) <= 255) return full;
|
|
104
|
+
return `~v3~${createHash("sha256").update(JSON.stringify(control ? [
|
|
105
|
+
m[1],
|
|
106
|
+
m[2],
|
|
107
|
+
harness,
|
|
108
|
+
"control"
|
|
109
|
+
] : [
|
|
110
|
+
m[1],
|
|
111
|
+
m[2],
|
|
112
|
+
harness
|
|
113
|
+
])).digest("hex")}`;
|
|
114
|
+
}
|
|
115
|
+
function frontmatterRange(text) {
|
|
116
|
+
const lines = text.split("\n");
|
|
117
|
+
if (lines[0] !== "---") return null;
|
|
118
|
+
const close = lines.indexOf("---", 1);
|
|
119
|
+
return close === -1 ? null : [1, close];
|
|
120
|
+
}
|
|
121
|
+
function isHiddenSkill(skillMd) {
|
|
122
|
+
const range = frontmatterRange(skillMd);
|
|
123
|
+
if (!range) return false;
|
|
124
|
+
return skillMd.split("\n").slice(range[0], range[1]).some((l) => l.startsWith("disable-model-invocation:"));
|
|
125
|
+
}
|
|
126
|
+
function stripHiddenFlag(skillMd) {
|
|
127
|
+
const range = frontmatterRange(skillMd);
|
|
128
|
+
if (!range) return skillMd;
|
|
129
|
+
return skillMd.split("\n").filter((l, i) => !(i >= range[0] && i < range[1] && l.startsWith("disable-model-invocation:"))).join("\n");
|
|
130
|
+
}
|
|
131
|
+
function isIsolated() {
|
|
132
|
+
return process.env.SKILLCHECK_ISOLATED === "1" && (fs.existsSync("/.dockerenv") || fs.existsSync("/run/.containerenv")) && process.getuid?.() === 0 && Number.isInteger(Number(process.env.SKILLCHECK_AGENT_UID)) && fs.existsSync(AGENT_WRAPPER);
|
|
133
|
+
}
|
|
134
|
+
const AGENT_WRAPPER = "/usr/local/libexec/skillcheck/agent-wrapper.sh";
|
|
135
|
+
const MARKDOWN_LINK = /\]\(\s*<([^>]+)>|\]\(\s*([^)\s]+)|^ {0,3}\[[^\]]+\]:\s*<?([^\s>]+)/gm;
|
|
136
|
+
function linkedSiblings(skillDir) {
|
|
137
|
+
const skillsRoot = path.dirname(skillDir);
|
|
138
|
+
const realRoot = fs.realpathSync(skillsRoot);
|
|
139
|
+
const realSelf = fs.realpathSync(skillDir);
|
|
140
|
+
const self = path.basename(skillDir);
|
|
141
|
+
const found = /* @__PURE__ */ new Set([self]);
|
|
142
|
+
const pending = [skillDir];
|
|
143
|
+
for (let dir = pending.pop(); dir !== void 0; dir = pending.pop()) for (const file of skillMarkdown(dir)) for (const m of fs.readFileSync(file, "utf8").matchAll(MARKDOWN_LINK)) {
|
|
144
|
+
const href = m[1] ?? m[2] ?? m[3];
|
|
145
|
+
if (href.startsWith("#") || /^[a-z][a-z0-9+.-]*:/i.test(href)) continue;
|
|
146
|
+
const target = path.resolve(path.dirname(file), href.split("#")[0]);
|
|
147
|
+
const rel = path.relative(skillsRoot, target);
|
|
148
|
+
const name = rel.split(path.sep)[0];
|
|
149
|
+
if (name === "" || name === ".." || path.isAbsolute(rel) || found.has(name)) continue;
|
|
150
|
+
if (!fs.existsSync(path.join(skillsRoot, name, "SKILL.md"))) continue;
|
|
151
|
+
const real = fs.realpathSync(path.join(skillsRoot, name));
|
|
152
|
+
if (path.dirname(real) !== realRoot || real === realSelf) continue;
|
|
153
|
+
found.add(name);
|
|
154
|
+
pending.push(path.join(skillsRoot, name));
|
|
155
|
+
}
|
|
156
|
+
found.delete(self);
|
|
157
|
+
return [...found].sort();
|
|
158
|
+
}
|
|
159
|
+
function skillMarkdown(dir) {
|
|
160
|
+
const out = [];
|
|
161
|
+
const walk = (d) => {
|
|
162
|
+
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
|
|
163
|
+
const p = path.join(d, e.name);
|
|
164
|
+
if (e.isDirectory()) {
|
|
165
|
+
if (!(d === dir && e.name === "evals")) walk(p);
|
|
166
|
+
} else if (e.isFile() && e.name.endsWith(".md")) out.push(p);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
walk(dir);
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
const RESERVED = /* @__PURE__ */ new Set([
|
|
173
|
+
".claude",
|
|
174
|
+
".agents",
|
|
175
|
+
".grok",
|
|
176
|
+
"node_modules"
|
|
177
|
+
]);
|
|
178
|
+
function materialize(s, runDir, harness, control = false) {
|
|
179
|
+
const workdir = path.join(runDir, "workdir");
|
|
180
|
+
fs.rmSync(runDir, {
|
|
181
|
+
recursive: true,
|
|
182
|
+
force: true
|
|
183
|
+
});
|
|
184
|
+
fs.mkdirSync(workdir, { recursive: true });
|
|
185
|
+
const seen = /* @__PURE__ */ new Set();
|
|
186
|
+
const planned = s.files.map((f) => {
|
|
187
|
+
const dest = path.resolve(workdir, f.name);
|
|
188
|
+
const rel = path.relative(workdir, dest);
|
|
189
|
+
if (rel === "" || rel.startsWith("..") || path.isAbsolute(rel)) throw new Error(`embedded file escapes workdir: ${f.name}`);
|
|
190
|
+
if (RESERVED.has(rel.split(path.sep)[0])) throw new Error(`embedded file targets reserved dir: ${f.name}`);
|
|
191
|
+
if (seen.has(dest)) throw new Error(`duplicate embedded file: ${f.name}`);
|
|
192
|
+
seen.add(dest);
|
|
193
|
+
return {
|
|
194
|
+
dest,
|
|
195
|
+
content: f.content
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
for (const { dest, content } of planned) {
|
|
199
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
200
|
+
fs.writeFileSync(dest, content);
|
|
201
|
+
}
|
|
202
|
+
const roots = control ? [] : harness === "codex" ? [".claude", ".agents"] : harness === "grok" ? [".grok"] : [".claude"];
|
|
203
|
+
const skillsRoot = path.dirname(s.skillDir);
|
|
204
|
+
const installed = control ? [] : [.../* @__PURE__ */ new Set([
|
|
205
|
+
s.skill,
|
|
206
|
+
...linkedSiblings(s.skillDir),
|
|
207
|
+
...s.alternatives.flatMap((a) => [a, ...linkedSiblings(path.join(skillsRoot, a))])
|
|
208
|
+
])];
|
|
209
|
+
for (const root of roots) for (const name of installed) {
|
|
210
|
+
const from = fs.realpathSync(path.join(skillsRoot, name));
|
|
211
|
+
fs.cpSync(from, path.join(workdir, root, "skills", name), {
|
|
212
|
+
recursive: true,
|
|
213
|
+
filter: (src) => {
|
|
214
|
+
if (src === path.join(from, "evals")) return false;
|
|
215
|
+
if (fs.lstatSync(src).isSymbolicLink()) throw new Error(`skill contains a symbolic link: ${src}`);
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
for (const root of roots) {
|
|
221
|
+
const skillMd = path.join(workdir, root, "skills", s.skill, "SKILL.md");
|
|
222
|
+
const text = fs.readFileSync(skillMd, "utf8");
|
|
223
|
+
const stripped = stripHiddenFlag(text);
|
|
224
|
+
if (stripped !== text) fs.writeFileSync(skillMd, stripped);
|
|
225
|
+
}
|
|
226
|
+
const manifest = {};
|
|
227
|
+
const walk = (dir) => {
|
|
228
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
229
|
+
const p = path.join(dir, e.name);
|
|
230
|
+
if (e.isDirectory()) {
|
|
231
|
+
if (!SKIPPED_DIRS.has(e.name)) walk(p);
|
|
232
|
+
} else manifest[path.relative(workdir, p)] = createHash("sha256").update(fs.readFileSync(p)).digest("hex");
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
walk(workdir);
|
|
236
|
+
const manifestPath = path.join(runDir, "manifest.json");
|
|
237
|
+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), { mode: 384 });
|
|
238
|
+
return {
|
|
239
|
+
workdir,
|
|
240
|
+
manifestPath
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function agentProvider(opts, workdir, skills, paths) {
|
|
244
|
+
const [skill] = skills;
|
|
245
|
+
if (opts.harness === "grok") return {
|
|
246
|
+
id: `file://${paths.grokProviderPath}`,
|
|
247
|
+
config: {
|
|
248
|
+
working_dir: workdir,
|
|
249
|
+
skill,
|
|
250
|
+
...opts.agentModel ? { model: opts.agentModel } : {}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
if (opts.harness === "codex") return {
|
|
254
|
+
id: "openai:codex-sdk",
|
|
255
|
+
config: {
|
|
256
|
+
...opts.agentModel ? { model: opts.agentModel } : {},
|
|
257
|
+
working_dir: workdir,
|
|
258
|
+
skip_git_repo_check: true,
|
|
259
|
+
enable_streaming: true,
|
|
260
|
+
sandbox_mode: isIsolated() ? "danger-full-access" : "workspace-write",
|
|
261
|
+
network_access_enabled: true,
|
|
262
|
+
web_search_enabled: true,
|
|
263
|
+
cli_config: { features: { plugins: false } },
|
|
264
|
+
cli_env: {
|
|
265
|
+
CODEX_HOME: path.join(workdir, "..", "..", "codex-home"),
|
|
266
|
+
HOME: path.join(workdir, "..", "..", "home")
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
return {
|
|
271
|
+
id: "anthropic:claude-agent-sdk",
|
|
272
|
+
config: {
|
|
273
|
+
model: opts.agentModel ?? "claude-opus-5",
|
|
274
|
+
...opts.agentEffort ? { effort: opts.agentEffort } : {},
|
|
275
|
+
apiKeyRequired: false,
|
|
276
|
+
working_dir: workdir,
|
|
277
|
+
setting_sources: ["project"],
|
|
278
|
+
...opts.control ? {} : { skills },
|
|
279
|
+
permission_mode: "acceptEdits",
|
|
280
|
+
append_allowed_tools: [
|
|
281
|
+
"Read",
|
|
282
|
+
"Write",
|
|
283
|
+
"Edit",
|
|
284
|
+
"Glob",
|
|
285
|
+
"Grep",
|
|
286
|
+
"Bash",
|
|
287
|
+
"WebFetch",
|
|
288
|
+
"WebSearch"
|
|
289
|
+
],
|
|
290
|
+
max_turns: opts.maxTurns ?? 50
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function trialLabel(index) {
|
|
295
|
+
return `trial-${index + 1}`;
|
|
296
|
+
}
|
|
297
|
+
function buildConfig(s, trials, opts, paths) {
|
|
298
|
+
return {
|
|
299
|
+
description: `${s.skill}/${s.scenario}`,
|
|
300
|
+
prompts: ["{{task}}"],
|
|
301
|
+
providers: trials.map((t, i) => ({
|
|
302
|
+
...agentProvider(opts, t.workdir, [s.skill, ...s.alternatives], paths),
|
|
303
|
+
label: trialLabel(i)
|
|
304
|
+
})),
|
|
305
|
+
defaultTest: { options: {
|
|
306
|
+
provider: opts.judgeModel.includes(":") ? opts.judgeEffort === void 0 ? opts.judgeModel : {
|
|
307
|
+
id: opts.judgeModel,
|
|
308
|
+
config: { reasoning_effort: opts.judgeEffort }
|
|
309
|
+
} : process.env.ANTHROPIC_API_KEY ? opts.judgeEffort === void 0 ? `anthropic:messages:${opts.judgeModel}` : {
|
|
310
|
+
id: `anthropic:messages:${opts.judgeModel}`,
|
|
311
|
+
config: { effort: opts.judgeEffort }
|
|
312
|
+
} : {
|
|
313
|
+
id: "anthropic:claude-agent-sdk",
|
|
314
|
+
config: {
|
|
315
|
+
model: opts.judgeModel,
|
|
316
|
+
...opts.judgeEffort ? { effort: opts.judgeEffort } : {},
|
|
317
|
+
apiKeyRequired: false,
|
|
318
|
+
max_turns: 3,
|
|
319
|
+
env: { CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" },
|
|
320
|
+
title: "skillcheck judge",
|
|
321
|
+
output_format: {
|
|
322
|
+
type: "json_schema",
|
|
323
|
+
schema: {
|
|
324
|
+
type: "object",
|
|
325
|
+
additionalProperties: false,
|
|
326
|
+
required: [
|
|
327
|
+
"reason",
|
|
328
|
+
"pass",
|
|
329
|
+
"score"
|
|
330
|
+
],
|
|
331
|
+
properties: {
|
|
332
|
+
reason: { type: "string" },
|
|
333
|
+
pass: { type: "boolean" },
|
|
334
|
+
score: {
|
|
335
|
+
type: "number",
|
|
336
|
+
minimum: 0,
|
|
337
|
+
maximum: 1
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
transform: `file://${paths.transformPath}`
|
|
345
|
+
} },
|
|
346
|
+
tests: trials.map((t, i) => ({
|
|
347
|
+
description: s.criteria.context,
|
|
348
|
+
providers: [trialLabel(i)],
|
|
349
|
+
vars: {
|
|
350
|
+
task: opts.control ? s.task : s.prompt,
|
|
351
|
+
workdir: t.workdir,
|
|
352
|
+
manifest: t.manifestPath
|
|
353
|
+
},
|
|
354
|
+
assert: [{
|
|
355
|
+
type: "assert-set",
|
|
356
|
+
threshold: .7,
|
|
357
|
+
assert: s.criteria.checklist.map((item) => ({
|
|
358
|
+
type: "llm-rubric",
|
|
359
|
+
value: `${item.name}: ${item.description}`,
|
|
360
|
+
weight: item.max_score
|
|
361
|
+
}))
|
|
362
|
+
}, {
|
|
363
|
+
type: "javascript",
|
|
364
|
+
value: `file://${paths.skillEvidencePath}`,
|
|
365
|
+
metric: "skill-used",
|
|
366
|
+
config: {
|
|
367
|
+
skill: s.skill,
|
|
368
|
+
required: !opts.control && (s.criteria.skill_use ?? "required") === "required",
|
|
369
|
+
...!opts.control && s.criteria.skill_use === "forbidden" ? { forbidden: true } : {}
|
|
370
|
+
}
|
|
371
|
+
}]
|
|
372
|
+
}))
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
const SDK_PACKAGES = ["@anthropic-ai/claude-agent-sdk", "@openai/codex-sdk"];
|
|
376
|
+
function sdkNodeModulesDir() {
|
|
377
|
+
for (const pkg of SDK_PACKAGES) {
|
|
378
|
+
const dir = holdingNodeModules(pkg);
|
|
379
|
+
if (dir !== void 0) return dir;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function holdingNodeModules(pkg) {
|
|
383
|
+
const require = createRequire(import.meta.url);
|
|
384
|
+
for (const dir of require.resolve.paths(pkg) ?? []) if (fs.existsSync(path.join(dir, pkg, "package.json"))) return dir;
|
|
385
|
+
}
|
|
386
|
+
function resolvePackageDir(pkg) {
|
|
387
|
+
const dir = holdingNodeModules(pkg);
|
|
388
|
+
return dir === void 0 ? void 0 : path.join(dir, pkg);
|
|
389
|
+
}
|
|
390
|
+
function requiredEvalPackages(opts, hasAnthropicKey) {
|
|
391
|
+
const pkgs = ["promptfoo"];
|
|
392
|
+
const sdkJudge = !opts.judgeModel.includes(":") && !hasAnthropicKey;
|
|
393
|
+
if (opts.harness === "claude" || sdkJudge) pkgs.push("@anthropic-ai/claude-agent-sdk");
|
|
394
|
+
if (opts.harness === "codex") pkgs.push("@openai/codex-sdk");
|
|
395
|
+
return pkgs;
|
|
396
|
+
}
|
|
397
|
+
function privateCodexHome(dir) {
|
|
398
|
+
const source = process.env.CODEX_HOME ?? path.join(os.homedir(), ".codex");
|
|
399
|
+
fs.rmSync(dir, {
|
|
400
|
+
recursive: true,
|
|
401
|
+
force: true
|
|
402
|
+
});
|
|
403
|
+
fs.mkdirSync(dir, {
|
|
404
|
+
recursive: true,
|
|
405
|
+
mode: 448
|
|
406
|
+
});
|
|
407
|
+
for (const file of ["config.toml", "auth.json"]) {
|
|
408
|
+
const from = path.join(source, file);
|
|
409
|
+
if (fs.existsSync(from)) fs.symlinkSync(from, path.join(dir, file));
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const HIDDEN_HOME_ENTRIES = /* @__PURE__ */ new Set([
|
|
413
|
+
".agents",
|
|
414
|
+
".claude",
|
|
415
|
+
".codex"
|
|
416
|
+
]);
|
|
417
|
+
function privateHome(dir) {
|
|
418
|
+
const source = os.homedir();
|
|
419
|
+
fs.rmSync(dir, {
|
|
420
|
+
recursive: true,
|
|
421
|
+
force: true
|
|
422
|
+
});
|
|
423
|
+
fs.mkdirSync(dir, {
|
|
424
|
+
recursive: true,
|
|
425
|
+
mode: 448
|
|
426
|
+
});
|
|
427
|
+
for (const name of fs.readdirSync(source)) {
|
|
428
|
+
if (HIDDEN_HOME_ENTRIES.has(name)) continue;
|
|
429
|
+
fs.symlinkSync(path.join(source, name), path.join(dir, name));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function handOverToAgent(runDir, trials) {
|
|
433
|
+
const uid = Number(process.env.SKILLCHECK_AGENT_UID);
|
|
434
|
+
const gid = Number(process.env.SKILLCHECK_AGENT_GID ?? process.env.SKILLCHECK_AGENT_UID);
|
|
435
|
+
if (!Number.isInteger(uid) || !Number.isInteger(gid)) throw new Error("isolated run without SKILLCHECK_AGENT_UID: refusing to run the agent as root");
|
|
436
|
+
const own = (p) => {
|
|
437
|
+
fs.lchownSync(p, uid, gid);
|
|
438
|
+
if (fs.lstatSync(p).isDirectory()) for (const e of fs.readdirSync(p)) own(path.join(p, e));
|
|
439
|
+
};
|
|
440
|
+
for (const dir of [path.dirname(runDir), runDir]) fs.chmodSync(dir, 457);
|
|
441
|
+
for (const t of trials) {
|
|
442
|
+
fs.chmodSync(path.dirname(t.workdir), 457);
|
|
443
|
+
own(t.workdir);
|
|
444
|
+
}
|
|
445
|
+
for (const home of ["codex-home", "home"]) {
|
|
446
|
+
const p = path.join(runDir, home);
|
|
447
|
+
if (fs.existsSync(p)) own(p);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function generateRun(scenarioDir, opts, paths) {
|
|
451
|
+
const s = loadScenario(scenarioDir);
|
|
452
|
+
if (opts.harness === "grok" && s.criteria.skill_use === "forbidden") throw new Error(`grok cannot evidence a skill load reliably enough for skill_use "forbidden": ${scenarioDir}`);
|
|
453
|
+
const name = runNameFor(scenarioDir, opts.harness, opts.control);
|
|
454
|
+
const runDir = path.join(paths.scratchDir, name);
|
|
455
|
+
fs.rmSync(runDir, {
|
|
456
|
+
recursive: true,
|
|
457
|
+
force: true
|
|
458
|
+
});
|
|
459
|
+
const trials = Array.from({ length: opts.trials ?? 1 }, (_, i) => materialize(s, path.join(runDir, trialLabel(i)), opts.harness, opts.control));
|
|
460
|
+
if (opts.harness === "codex") {
|
|
461
|
+
privateCodexHome(path.join(runDir, "codex-home"));
|
|
462
|
+
privateHome(path.join(runDir, "home"));
|
|
463
|
+
}
|
|
464
|
+
const sdkDir = sdkNodeModulesDir();
|
|
465
|
+
if (sdkDir !== void 0) {
|
|
466
|
+
const link = path.join(runDir, "node_modules");
|
|
467
|
+
fs.rmSync(link, {
|
|
468
|
+
recursive: true,
|
|
469
|
+
force: true
|
|
470
|
+
});
|
|
471
|
+
fs.symlinkSync(sdkDir, link, "dir");
|
|
472
|
+
}
|
|
473
|
+
const config = buildConfig(s, trials, opts, paths);
|
|
474
|
+
const configPath = path.join(runDir, "promptfooconfig.json");
|
|
475
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), { mode: 384 });
|
|
476
|
+
if (isIsolated()) handOverToAgent(runDir, trials);
|
|
477
|
+
return {
|
|
478
|
+
name,
|
|
479
|
+
configPath,
|
|
480
|
+
skill: s.skill,
|
|
481
|
+
scenario: s.scenario
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
export { DEFAULT_CLAUDE_AGENT, FILE_BLOCK, buildConfig, encodeRunNamePart, generateRun, handOverToAgent, isHiddenSkill, isIsolated, linkedSiblings, loadScenario, materialize, parseCriteria, privateCodexHome, privateHome, requiredEvalPackages, resolvePackageDir, runNameFor, sdkNodeModulesDir, stripHiddenFlag, trialLabel };
|