@fede0089/skill-eval 2.0.0 → 3.0.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/README.md CHANGED
@@ -2,11 +2,18 @@
2
2
 
3
3
  A CLI tool for evaluating Agent Skills locally. Tests whether your skill triggers reliably and produces the right output, using an LLM as the judge.
4
4
 
5
- ## Why skill evals?
5
+ ## What you can test
6
6
 
7
- Skills are instructions that change how the agent behaves. But a single successful run isn't enough to trust one — agents are non-deterministic, and a good isolated result can be exactly that: an isolated case.
7
+ skill-eval ships two commands, each targeting a different failure mode:
8
8
 
9
- Skill evals let you turn that intuition into evidence: run several comparable tasks with the skill, measure them against the same criteria, and optionally compare against a baseline or historical skill branches.
9
+ - **Triggering** (`skill-eval trigger`) checks whether the agent actually decides to invoke the skill in the right context. A skill that never gets triggered cannot help, no matter how good its instructions are.
10
+ - **Functional correctness** (`skill-eval functional`) — checks whether the actions the agent takes while the skill is active match your expectations. An LLM judge grades each transcript against the expectation list you provide.
11
+
12
+ ## Why run skill evals
13
+
14
+ - **Avoid regression** — it is very common that, while iterating to make a skill handle a new case, it stops solving cases it used to handle. Evals make every iteration measurable, so you can tell whether a change adds value without silently subtracting it elsewhere.
15
+ - **Validate against a baseline** — sometimes an agent solves a task better using its general capabilities than using a specific skill (and even if it works today, model upgrades can shift that balance). Comparing against the no-skill baseline (`--compare-baseline`) or past skill versions (`--compare-ref`) tells you whether the skill is really pulling its weight.
16
+ - **Statistical confidence** — LLMs are non-deterministic, so a single passing run is not evidence. Running the same expectations N times produces a pass rate (pass@k) that turns "it feels like it works" into a number you can defend.
10
17
 
11
18
  ## How it works
12
19
 
@@ -37,7 +44,7 @@ For each eval prompt, skill-eval spins up parallel agent processes with the curr
37
44
 
38
45
  ## Installation
39
46
 
40
- **Requirements:** Node.js, and the agent CLI you want to evaluate (e.g. `gemini` or `codex`) installed and on `$PATH`.
47
+ **Requirements:** Node.js, and the agent CLI you want to evaluate (e.g. `gemini`, `codex`, or `claude`) installed and on `$PATH`.
41
48
 
42
49
  ### Run without installing
43
50
 
@@ -91,6 +98,7 @@ Supported runners:
91
98
 
92
99
  - `gemini-cli` (default)
93
100
  - `codex`
101
+ - `claude-code`
94
102
 
95
103
  ### Skill directory structure
96
104
 
@@ -102,8 +110,10 @@ my-skill/
102
110
  └── config/ # runner configuration (optional but often needed)
103
111
  ├── gemini-cli/ # copied to <worktree>/.gemini/ before each trial
104
112
  │ └── settings.json
105
- └── codex/ # copied to <worktree>/.codex/ before each trial
106
- └── config.toml
113
+ ├── codex/ # copied to <worktree>/.codex/ before each trial
114
+ └── config.toml
115
+ └── claude-code/ # copied to <worktree>/.claude/ before each trial
116
+ └── settings.json
107
117
  ```
108
118
 
109
119
  All `.json` files in `evals/` are loaded and merged into a single suite — you can split them by feature or regression category.
@@ -141,16 +151,34 @@ All `.json` files in `evals/` are loaded and merged into a single suite — you
141
151
 
142
152
  skill-eval runs the agent headlessly — stdin is closed, there is no terminal. If the agent encounters a tool that requires interactive approval, it will either fail immediately or hang until the trial timeout kills it.
143
153
 
144
- Each runner configures its own non-interactive mode. For example, Gemini CLI uses `--approval-mode auto_edit`, while Codex uses `codex exec --json --sandbox workspace-write -c approval_policy="never"`. If your skill needs to run shell commands, read environment variables, make network calls, or use any other tool category, refer to that runner's permission model.
154
+ Each runner configures its own non-interactive mode. For example, Gemini CLI uses `--approval-mode auto_edit`, Codex uses `codex exec --json --sandbox workspace-write -c approval_policy="never"`, and Claude Code uses `claude -p --output-format stream-json --permission-mode bypassPermissions`. If your skill needs to run shell commands, read environment variables, make network calls, or use any other tool category, refer to that runner's permission model.
145
155
 
146
156
  **Solution:** place a config file inside your skill at `evals/config/<runner>/`. Before every trial, skill-eval automatically copies that directory into the agent's config location inside the isolated worktree:
147
157
 
148
158
  ```
149
- evals/config/gemini-cli/ → <worktree>/.gemini/
150
- evals/config/codex/ → <worktree>/.codex/
159
+ evals/config/gemini-cli/ → <worktree>/.gemini/
160
+ evals/config/codex/ → <worktree>/.codex/
161
+ evals/config/claude-code/ → <worktree>/.claude/
162
+ ```
163
+
164
+ Use this to ship both settings and policies alongside your evals. Anything inside `evals/config/<runner>/` is dropped verbatim into the runner's config directory, so you can use the runner's full configuration surface — not just `settings.json`.
165
+
166
+ ### Gemini CLI example
167
+
168
+ Gemini CLI reads both `settings.json` and any `*.toml` rule files under `policies/`. Drop them inside `evals/config/gemini-cli/` and skill-eval will copy them into `<worktree>/.gemini/` before each trial:
169
+
170
+ ```
171
+ my-skill/
172
+ └── evals/
173
+ └── config/
174
+ └── gemini-cli/
175
+ ├── settings.json
176
+ └── policies/
177
+ ├── allow-activate-skill.toml
178
+ └── allow-tools.toml
151
179
  ```
152
180
 
153
- Use this to ship both settings and policies alongside your evals. For Gemini CLI, for example, you can use `settings.json` to configure tool permissions and approval policies so that every tool your skill relies on runs without prompting:
181
+ `settings.json` holds general configuration (telemetry, model, etc.):
154
182
 
155
183
  ```json
156
184
  {
@@ -158,10 +186,42 @@ Use this to ship both settings and policies alongside your evals. For Gemini CLI
158
186
  }
159
187
  ```
160
188
 
161
- Refer to your runner's documentation for the full list of available settings and policy keys.
189
+ Policies whitelist specific tools so they run without prompting. For example, to always allow the `activate_skill` dispatch tool in non-interactive mode:
190
+
191
+ ```toml
192
+ # evals/config/gemini-cli/policies/allow-activate-skill.toml
193
+ [[rule]]
194
+ toolName = "activate_skill"
195
+ decision = "allow"
196
+ priority = 100
197
+ interactive = false
198
+ ```
199
+
200
+ Refer to your runner's documentation for the full set of settings and policy keys (Codex uses `config.toml`, Claude Code uses `settings.json`).
162
201
 
163
202
  > This config only applies inside the temporary worktree created for each trial. Your real workspace config is never touched.
164
203
 
204
+ ## Reports
205
+
206
+ Each run writes to `.project-skill-evals/runs/<timestamp>/` and includes per-trial logs, the raw eval JSON, and a self-contained HTML report you can open in any browser. The report shows pass@k aggregates per eval, lets you expand each trial, and color-codes triggering vs. functional outcomes.
207
+
208
+ A published sample report is available at [fede0089.github.io/skill-eval/sample-report.html](https://fede0089.github.io/skill-eval/sample-report.html),generated from this project root with:
209
+
210
+ ```sh
211
+ skill-eval functional --workspace . --skill mock-skill --trials 2 --compare-baseline --debug claude-code
212
+ ```
213
+
214
+ ![Sample HTML report](docs/sample-report.png)
215
+
216
+ ### Debug logs
217
+
218
+ When a trial misbehaves, pass `-v` / `--debug` to capture the full transcripts to disk. Each trial writes a `task_<id>_<variant>_trial_<n>.log` file inside the run directory with two sections appended in order:
219
+
220
+ - `# SECTION: <MODE> AGENT RUN` — the initial prompt sent to the agent and its raw streamed response.
221
+ - `# SECTION: <MODE> JUDGE RUN` — the prompt sent to the LLM judge and its verdict (only present for `functional` runs; `trigger` is graded programmatically and produces no judge section).
222
+
223
+ Without `--debug` these files are not written, so reach for the flag when you need to see exactly what the agent — or the judge — saw.
224
+
165
225
  ## Try it out
166
226
 
167
227
  This repo includes a `mock-skill/` directory — a complete, working example of a license-generator skill with trigger and functional evals. Run it directly with:
@@ -170,12 +230,12 @@ This repo includes a `mock-skill/` directory — a complete, working example of
170
230
  npm run test:unit # run the unit test suite
171
231
  npm run test:trigger # trigger evaluation against mock-skill
172
232
  npm run test:functional # functional evaluation against mock-skill
173
- npm run test:trigger -- codex # run trigger evals with Codex
174
- npm run test:functional -- codex # run functional evals with Codex
233
+ npm run test:trigger -- codex # run trigger evals with Codex
234
+ npm run test:functional -- codex # run functional evals with Codex
235
+ npm run test:trigger -- claude-code # run trigger evals with Claude Code
236
+ npm run test:functional -- claude-code # run functional evals with Claude Code
175
237
  ```
176
238
 
177
- Results are saved to `.project-skill-evals/runs/<timestamp>/` with logs, raw eval JSONs, and an HTML report.
178
-
179
239
  ## Extending
180
240
 
181
241
  ### Adding a new agent runner
@@ -0,0 +1 @@
1
+ export { ClaudeCodeRunner } from './runner.js';
@@ -0,0 +1,279 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import child_process from 'child_process';
4
+ import { Logger } from '../../utils/logger.js';
5
+ function isRecord(value) {
6
+ return typeof value === 'object' && value !== null;
7
+ }
8
+ function readSkillName(skillPath) {
9
+ const skillMd = path.join(skillPath, 'SKILL.md');
10
+ if (!fs.existsSync(skillMd))
11
+ return path.basename(skillPath);
12
+ const content = fs.readFileSync(skillMd, 'utf-8');
13
+ const frontmatter = content.match(/^---\n([\s\S]*?)\n---/);
14
+ if (!frontmatter)
15
+ return path.basename(skillPath);
16
+ const nameLine = frontmatter[1].split('\n').find((line) => line.trim().startsWith('name:'));
17
+ const name = nameLine?.replace(/^name:\s*/, '').trim().replace(/^["']|["']$/g, '');
18
+ return name || path.basename(skillPath);
19
+ }
20
+ function numberFrom(value) {
21
+ return typeof value === 'number' ? value : undefined;
22
+ }
23
+ function getAssistantContent(event) {
24
+ const eventType = String(event.type ?? '');
25
+ if (eventType !== 'assistant')
26
+ return [];
27
+ const message = event.message;
28
+ if (!isRecord(message))
29
+ return [];
30
+ const content = message.content;
31
+ if (!Array.isArray(content))
32
+ return [];
33
+ return content.filter(isRecord);
34
+ }
35
+ function getUserContent(event) {
36
+ const eventType = String(event.type ?? '');
37
+ if (eventType !== 'user')
38
+ return [];
39
+ const message = event.message;
40
+ if (!isRecord(message))
41
+ return [];
42
+ const content = message.content;
43
+ if (!Array.isArray(content))
44
+ return [];
45
+ return content.filter(isRecord);
46
+ }
47
+ /**
48
+ * Converts Claude Code stream-json events into the small NDJSON contract used
49
+ * by the rest of the evaluator. The normalizer is intentionally tolerant: the
50
+ * Claude Code event stream is richer than the evaluator needs and may grow
51
+ * over time. Only fields the grader/judge consume are mapped.
52
+ */
53
+ export function normalizeClaudeJsonl(output) {
54
+ const normalized = [];
55
+ let sawResult = false;
56
+ for (const line of output.split('\n')) {
57
+ const trimmed = line.trim();
58
+ if (!trimmed)
59
+ continue;
60
+ let event;
61
+ try {
62
+ event = JSON.parse(trimmed);
63
+ }
64
+ catch {
65
+ continue;
66
+ }
67
+ for (const item of getAssistantContent(event)) {
68
+ const itemType = String(item.type ?? '');
69
+ if (itemType === 'text' && typeof item.text === 'string' && item.text.trim()) {
70
+ normalized.push({ type: 'message', role: 'assistant', content: item.text });
71
+ }
72
+ else if (itemType === 'tool_use') {
73
+ const toolName = String(item.name ?? '');
74
+ const toolId = String(item.id ?? `claude-tool-${normalized.length + 1}`);
75
+ const input = isRecord(item.input) ? item.input : {};
76
+ // The internal NDJSON contract expects parameters.name to carry the skill
77
+ // identifier when the dispatch tool is invoked. Claude Code's Skill tool
78
+ // uses `input.skill` for that — remap so TriggerGrader can match it.
79
+ const parameters = { ...input };
80
+ if (toolName === 'Skill' && typeof input.skill === 'string') {
81
+ parameters.name = input.skill;
82
+ }
83
+ normalized.push({
84
+ type: 'tool_use',
85
+ tool_id: toolId,
86
+ tool_name: toolName,
87
+ parameters,
88
+ });
89
+ }
90
+ }
91
+ for (const item of getUserContent(event)) {
92
+ const itemType = String(item.type ?? '');
93
+ if (itemType !== 'tool_result')
94
+ continue;
95
+ const toolId = String(item.tool_use_id ?? '');
96
+ if (!toolId)
97
+ continue;
98
+ const isError = item.is_error === true;
99
+ // Claude Code attaches a tool_use_result sibling on the parent event with
100
+ // a `success` boolean for built-in tools (e.g. Skill). Prefer that when present.
101
+ const parent = event.tool_use_result;
102
+ const parentSuccess = isRecord(parent) ? parent.success : undefined;
103
+ const status = isError === true || parentSuccess === false ? 'error' : 'success';
104
+ normalized.push({ type: 'tool_result', tool_id: toolId, status });
105
+ }
106
+ const eventType = String(event.type ?? '');
107
+ if (eventType === 'result') {
108
+ sawResult = true;
109
+ const isError = event.is_error === true;
110
+ const usage = isRecord(event.usage) ? event.usage : undefined;
111
+ const inputTokens = usage ? numberFrom(usage.input_tokens) ?? 0 : 0;
112
+ const outputTokens = usage ? numberFrom(usage.output_tokens) ?? 0 : 0;
113
+ const cachedTokens = usage
114
+ ? numberFrom(usage.cache_read_input_tokens)
115
+ ?? numberFrom(usage.cached_input_tokens)
116
+ ?? 0
117
+ : 0;
118
+ const stats = usage
119
+ ? {
120
+ total_tokens: inputTokens + outputTokens,
121
+ input_tokens: inputTokens,
122
+ output_tokens: outputTokens,
123
+ cached: cachedTokens,
124
+ }
125
+ : undefined;
126
+ if (isError) {
127
+ const message = typeof event.result === 'string' && event.result.trim()
128
+ ? event.result
129
+ : `Claude Code run failed (subtype: ${String(event.subtype ?? 'unknown')})`;
130
+ normalized.push({ type: 'result', status: 'error', error: { message }, ...(stats ? { stats } : {}) });
131
+ }
132
+ else {
133
+ const response = typeof event.result === 'string' ? event.result : undefined;
134
+ normalized.push({
135
+ type: 'result',
136
+ status: 'success',
137
+ ...(response ? { response } : {}),
138
+ ...(stats ? { stats } : {}),
139
+ });
140
+ }
141
+ }
142
+ }
143
+ if (!sawResult) {
144
+ normalized.push({ type: 'result', status: 'error', error: { message: 'Claude Code produced no result event' } });
145
+ }
146
+ return normalized.map((event) => JSON.stringify(event)).join('\n');
147
+ }
148
+ export class ClaudeCodeRunner {
149
+ skillDispatchToolName = 'Skill';
150
+ linkedSkillsByWorktree = new Map();
151
+ async runPrompt(prompt, cwd, onLog, logPath, extraArgs = [], timeoutMs) {
152
+ return new Promise((resolve) => {
153
+ let stdout = '';
154
+ let stderr = '';
155
+ let resolved = false;
156
+ let timeout;
157
+ const args = [
158
+ '-p', prompt,
159
+ '--output-format', 'stream-json',
160
+ '--verbose',
161
+ '--permission-mode', 'bypassPermissions',
162
+ '--no-session-persistence',
163
+ ...extraArgs,
164
+ ];
165
+ const spawnOptions = {
166
+ cwd,
167
+ env: { ...process.env, FORCE_COLOR: '0' },
168
+ stdio: ['ignore', 'pipe', 'pipe'],
169
+ detached: true,
170
+ };
171
+ function appendLog(chunk) {
172
+ if (!logPath)
173
+ return;
174
+ try {
175
+ fs.appendFileSync(logPath, chunk);
176
+ }
177
+ catch (err) {
178
+ Logger.warn(`Failed to write Claude Code debug log at ${logPath}. Continuing. Reason: ${err}`);
179
+ }
180
+ }
181
+ function killProcessGroup() {
182
+ if (!child.pid)
183
+ return;
184
+ try {
185
+ process.kill(-child.pid, 'SIGKILL');
186
+ }
187
+ catch {
188
+ // Process might have already exited.
189
+ }
190
+ }
191
+ const child = child_process.spawn('claude', args, spawnOptions);
192
+ appendLog(`--- Claude Code Execution Start: ${new Date().toISOString()} ---\n`);
193
+ appendLog(`Command: claude ${args.join(' ')}\n\n`);
194
+ if (timeoutMs && timeoutMs > 0) {
195
+ timeout = setTimeout(() => {
196
+ if (resolved)
197
+ return;
198
+ resolved = true;
199
+ killProcessGroup();
200
+ const timeoutSec = timeoutMs / 1000;
201
+ Logger.error(`\nClaude Code process timed out after ${timeoutSec} seconds.`);
202
+ appendLog(`\n\n--- Claude Code process timed out ---\n${stderr}\n`);
203
+ resolve({ error: `Process timeout exceeded (${timeoutSec} seconds)`, raw_output: stderr });
204
+ }, timeoutMs);
205
+ }
206
+ child.stdout?.on('data', (data) => {
207
+ const chunk = data.toString();
208
+ stdout += chunk;
209
+ appendLog(chunk);
210
+ });
211
+ child.stderr?.on('data', (data) => {
212
+ const chunk = data.toString();
213
+ stderr += chunk;
214
+ if (onLog) {
215
+ const lines = chunk.split('\n').filter((line) => line.trim() !== '');
216
+ if (lines.length > 0)
217
+ onLog(lines[lines.length - 1]);
218
+ }
219
+ });
220
+ child.on('error', (err) => {
221
+ if (resolved)
222
+ return;
223
+ resolved = true;
224
+ if (timeout)
225
+ clearTimeout(timeout);
226
+ Logger.error(`Failed to start Claude Code CLI. Error: ${err.message}`);
227
+ appendLog(`\n\n--- Error starting Claude Code CLI ---\n${err.message}\n`);
228
+ resolve(null);
229
+ });
230
+ child.on('close', (code) => {
231
+ appendLog(`\n\n--- Claude Code exited with status ${code} ---\n`);
232
+ if (code !== 0 && stderr) {
233
+ appendLog(`--- Stderr ---\n${stderr}\n--- End Stderr ---\n`);
234
+ }
235
+ if (resolved)
236
+ return;
237
+ resolved = true;
238
+ if (timeout)
239
+ clearTimeout(timeout);
240
+ if (!stdout.trim()) {
241
+ resolve({ error: 'Empty output from Claude Code CLI', raw_output: stderr });
242
+ return;
243
+ }
244
+ const normalized = normalizeClaudeJsonl(stdout);
245
+ if (code !== 0) {
246
+ resolve({
247
+ error: `Claude Code CLI exited with status ${code}`,
248
+ response: normalized,
249
+ raw_output: `${normalized}\n--- CLAUDE CODE STDOUT ---\n${stdout}\n--- STDERR ---\n${stderr}`,
250
+ });
251
+ return;
252
+ }
253
+ resolve({
254
+ response: normalized,
255
+ raw_output: `${normalized}\n--- CLAUDE CODE STDOUT ---\n${stdout}\n--- STDERR ---\n${stderr}`,
256
+ });
257
+ });
258
+ });
259
+ }
260
+ applyRunnerConfig(evalConfigBaseDir, worktreePath) {
261
+ const src = path.join(evalConfigBaseDir, 'claude-code');
262
+ if (!fs.existsSync(src))
263
+ return;
264
+ const dst = path.join(worktreePath, '.claude');
265
+ fs.mkdirSync(dst, { recursive: true });
266
+ fs.cpSync(src, dst, { recursive: true, force: true });
267
+ }
268
+ async linkSkill(absoluteSkillPath, worktreePath) {
269
+ const skillName = readSkillName(absoluteSkillPath);
270
+ const localSkillsDir = path.join(worktreePath, '.claude', 'skills');
271
+ const symlinkPath = path.join(localSkillsDir, skillName);
272
+ fs.mkdirSync(localSkillsDir, { recursive: true });
273
+ if (fs.existsSync(symlinkPath)) {
274
+ fs.rmSync(symlinkPath, { recursive: true, force: true });
275
+ }
276
+ fs.symlinkSync(absoluteSkillPath, symlinkPath, 'dir');
277
+ this.linkedSkillsByWorktree.set(path.resolve(worktreePath), { name: skillName });
278
+ }
279
+ }
@@ -1,3 +1,4 @@
1
1
  export { GeminiCliRunner } from './gemini-cli/index.js';
2
2
  export { CodexRunner } from './codex/index.js';
3
+ export { ClaudeCodeRunner } from './claude-code/index.js';
3
4
  export { RUNNER_REGISTRY, RunnerFactory, DEFAULT_AGENT } from './registry.js';
@@ -1,8 +1,10 @@
1
1
  import { GeminiCliRunner } from './gemini-cli/index.js';
2
2
  import { CodexRunner } from './codex/index.js';
3
+ import { ClaudeCodeRunner } from './claude-code/index.js';
3
4
  export const RUNNER_REGISTRY = {
4
5
  'gemini-cli': { Runner: GeminiCliRunner, binary: 'gemini' },
5
6
  codex: { Runner: CodexRunner, binary: 'codex' },
7
+ 'claude-code': { Runner: ClaudeCodeRunner, binary: 'claude' },
6
8
  };
7
9
  /** Default agent name used when none is specified on the CLI. */
8
10
  export const DEFAULT_AGENT = Object.keys(RUNNER_REGISTRY)[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fede0089/skill-eval",
3
- "version": "2.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "CLI to evaluate agent skills triggering and functionality",
5
5
  "main": "dist/index.js",
6
6
  "bin": {