@dzhechkov/skills-bto 1.2.0 → 1.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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # @dzhechkov/skills-bto
2
2
 
3
- **Build-Test-Optimize skill pack for Claude Code**
3
+ **Build-Benchmark-Test-Optimize skill pack for Claude Code**
4
4
 
5
- Multi-agent evaluation and iterative optimization pipeline for Claude Code skills, commands, and prompts. Part of the [Keysarium](https://www.npmjs.com/package/@dzhechkov/keysarium) ecosystem.
5
+ Multi-agent evaluation and iterative optimization pipeline for Claude Code skills, commands, and prompts. Includes deterministic benchmarking with golden sample comparison, test suites, consistency probes, and performance metrics. Part of the [Keysarium](https://www.npmjs.com/package/@dzhechkov/keysarium) ecosystem.
6
6
 
7
7
  ---
8
8
 
@@ -28,13 +28,13 @@ After installation, open Claude Code in your project directory and start using B
28
28
 
29
29
  | Component | Count | Description |
30
30
  |-----------|-------|-------------|
31
- | **Skill** | 1 | `bto` — core Build-Test-Optimize skill with modules (build, test, optimize) |
32
- | **Commands** | 4 | `/bto`, `/bto-build`, `/bto-test`, `/bto-optimize` |
33
- | **Rules** | 1 | `bto-quality-gates` — quality gate enforcement |
31
+ | **Skill** | 1 | `bto` — core Build-Benchmark-Test-Optimize skill with 4 modules |
32
+ | **Commands** | 5 | `/bto`, `/bto-build`, `/bto-benchmark`, `/bto-test`, `/bto-optimize` |
33
+ | **Rules** | 1 | `bto-quality-gates` — quality gate enforcement (incl. benchmark gates) |
34
34
  | **Shards** | 1 | `bto-evaluation` — context shard for BTO evaluation pipeline |
35
35
  | **Agent Templates** | 2 | `bto-judge-panel`, `bto-optimizer-worker` |
36
- | **References** | 4 | Eval patterns, judge rubrics, optimization methods, quality checklist |
37
- | **Examples** | 1 | Sample evaluation report |
36
+ | **References** | 5 | Eval patterns, judge rubrics, optimization methods, quality checklist, golden samples |
37
+ | **Examples** | 2 | Sample evaluation report, sample benchmark report |
38
38
 
39
39
  Everything is installed into your project's `.claude/` directory and works natively with Claude Code.
40
40
 
@@ -58,22 +58,26 @@ npx @dzhechkov/skills-bto doctor # Health check
58
58
  ## BTO Pipeline
59
59
 
60
60
  ```
61
- BUILD ──→ TEST ──→ OPTIMIZE
62
- │ │
63
- │ └── Evolutionary mutation + re-evaluation (3 rounds)
64
- └── Multi-layer evaluation: Layer 0 → Layer 1 → Layer 2
61
+ BUILD ──→ BENCHMARK ──→ TEST ──→ OPTIMIZE
62
+
63
+ └── Evolutionary mutation + re-evaluation (3 rounds)
64
+ └── Multi-layer evaluation: Layer 0 → Layer 1 → Layer 2
65
+ │ └── Deterministic benchmarking: golden samples, test suite, consistency, metrics
65
66
  └── Generate skill/command from description
66
67
  ```
67
68
 
68
69
  ### Usage in Claude Code
69
70
 
70
71
  ```bash
71
- # Full BTO cycle: build → test → optimize
72
+ # Full BTO cycle: build → benchmark → test → optimize
72
73
  /bto Create a skill for code review automation
73
74
 
74
75
  # Build only — generate a new skill or command
75
76
  /bto-build Create a skill that analyzes git commit patterns
76
77
 
78
+ # Benchmark only — deterministic benchmarking against golden samples
79
+ /bto-benchmark .claude/skills/my-skill/SKILL.md
80
+
77
81
  # Test only — evaluate an existing artifact
78
82
  /bto-test .claude/skills/my-skill/SKILL.md
79
83
 
@@ -85,7 +89,20 @@ BUILD ──→ TEST ──→ OPTIMIZE
85
89
 
86
90
  ## Evaluation Architecture
87
91
 
88
- ### Layer Model
92
+ ### Benchmark Layers (deterministic, pre-TEST)
93
+
94
+ | Layer | Cost | Purpose |
95
+ |-------|------|---------|
96
+ | **B0** | Zero (deterministic) | Golden sample comparison — section coverage, ordering, proportions |
97
+ | **B1** | Zero (deterministic) | Deterministic test suite — 5 tests per artifact type, PASS/FAIL |
98
+ | **B2** | Minimal (3× haiku) | Consistency probe — 3 parallel agents, agreement measurement |
99
+ | **B3** | Zero (deterministic) | Performance metrics — token efficiency, bloat detection, redundancy |
100
+
101
+ **Scoring:** `BENCHMARK = B0×0.30 + B1×0.35 + B2×0.15 + B3×0.20`
102
+
103
+ **Gate:** < 0.50 BLOCK | 0.50–0.70 WARN | > 0.70 PASS → proceed to TEST
104
+
105
+ ### TEST Layer Model
89
106
 
90
107
  | Layer | Agents | Model | Purpose |
91
108
  |-------|--------|-------|---------|
@@ -103,6 +120,8 @@ BUILD ──→ TEST ──→ OPTIMIZE
103
120
 
104
121
  ### Quality Gates
105
122
 
123
+ - **BENCHMARK** must pass (score ≥ 0.50) before TEST begins
124
+ - BENCHMARK score < 0.50 → BLOCK (artifact needs rework)
106
125
  - Layer 0 must pass before Layer 1
107
126
  - Layer 1 must pass before Layer 2
108
127
  - Optimization accepted only if `new_score - prev_score > 0.5`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dzhechkov/skills-bto",
3
- "version": "1.2.0",
4
- "description": "Build-Test-Optimize skill pack for Claude Code — structured BTO pipeline with quality gates, witness chain verification, judge attestation, and optimization workflows",
3
+ "version": "1.3.0",
4
+ "description": "Build-Benchmark-Test-Optimize skill pack for Claude Code — deterministic benchmarking, quality gates, witness chain, judge attestation, and optimization",
5
5
  "main": "src/cli.js",
6
6
  "bin": {
7
7
  "skills-bto": "./bin/cli.js"
@@ -20,6 +20,7 @@
20
20
  "claude-code",
21
21
  "ai",
22
22
  "bto",
23
+ "benchmark",
23
24
  "build-test-optimize",
24
25
  "skills",
25
26
  "quality-gates",
package/src/cli.js CHANGED
@@ -8,10 +8,10 @@ const { bold, cyan, dim, green, yellow, red, info, error } = require('./utils');
8
8
  // ---------------------------------------------------------------------------
9
9
  function showBanner() {
10
10
  console.log('');
11
- console.log(cyan('\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557'));
12
- console.log(cyan('\u2551') + bold(' DZ-SKILLS-BTO \u2014 Build\u00B7Test\u00B7Optimize for Claude Code ') + cyan('\u2551'));
13
- console.log(cyan('\u2551') + ' Structured BTO workflow with quality gates ' + cyan('\u2551'));
14
- console.log(cyan('\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D'));
11
+ console.log(cyan('\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557'));
12
+ console.log(cyan('\u2551') + bold(' DZ-SKILLS-BTO \u2014 Build\u00B7Benchmark\u00B7Test\u00B7Optimize ') + cyan('\u2551'));
13
+ console.log(cyan('\u2551') + ' Deterministic benchmarking + multi-agent evaluation ' + cyan('\u2551'));
14
+ console.log(cyan('\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D'));
15
15
  console.log('');
16
16
  }
17
17
 
package/src/utils.js CHANGED
@@ -299,12 +299,12 @@ function getTemplatesDir() {
299
299
  const COMPONENTS = {
300
300
  skill: {
301
301
  src: '.claude/skills/bto',
302
- label: 'BTO Skill Pack (3 modules)',
302
+ label: 'BTO Skill Pack (4 modules)',
303
303
  group: 'core',
304
304
  },
305
305
  commands: {
306
306
  src: '.claude/commands',
307
- label: 'BTO Commands (4 commands)',
307
+ label: 'BTO Commands (5 commands)',
308
308
  group: 'core',
309
309
  filter: 'bto',
310
310
  },
@@ -0,0 +1,302 @@
1
+ # /bto-benchmark — Deterministic Benchmarking of a Skill or Command
2
+
3
+ ## Usage
4
+ ```
5
+ /bto-benchmark [path to skill directory or file]
6
+ ```
7
+
8
+ ## Parameters
9
+ - $ARGUMENTS — Path to a skill directory (`.claude/skills/<name>/`), a command file (`.claude/commands/<name>.md`), a rule file (`.claude/rules/<name>.md`), or any structured artifact. Optionally include "verbose" to show expanded per-section diagnostics for all layers.
10
+
11
+ ## Protocol
12
+
13
+ ### Step 1: Load Skill and Module
14
+
15
+ Read `.claude/skills/bto/SKILL.md`
16
+ Read `.claude/skills/bto/modules/benchmark.md`
17
+ Read `.claude/skills/bto/references/golden-samples.md`
18
+
19
+ ### Step 2: Validate Input
20
+
21
+ If $ARGUMENTS is empty:
22
+ - Ask: "Provide a path to the skill directory or artifact file you want to benchmark."
23
+ - Stop and wait.
24
+
25
+ Resolve the artifact path from $ARGUMENTS:
26
+ - Strip any trailing slash
27
+ - If the path points to a directory → look for `SKILL.md` inside it as the primary file, but include all files in the directory for context
28
+ - If the path points to a file → use that file directly
29
+ - If the path does not exist → report "Path not found: [path]" and stop
30
+
31
+ ### Step 3: Detect Artifact Type
32
+
33
+ Auto-detect from path pattern:
34
+
35
+ | Path Pattern | Detected Type |
36
+ |-------------|--------------|
37
+ | `.claude/skills/*/SKILL.md` or `.claude/skills/*/` | skill |
38
+ | `.claude/commands/*.md` | command |
39
+ | `.claude/rules/*.md` | rule |
40
+ | `.claude/agents/*.md` | agent |
41
+ | `researches/**/*.md` | research artifact |
42
+
43
+ If type cannot be determined from path → infer from file content structure.
44
+
45
+ ### Step 4: Layer B0 — Golden Sample Comparison (Deterministic)
46
+
47
+ **Purpose:** Compare artifact structure against the canonical golden sample for its type. Zero LLM cost.
48
+
49
+ Load golden samples for the detected type from `references/golden-samples.md`.
50
+
51
+ **Procedure:**
52
+
53
+ 1. Parse the artifact into a section tree (heading hierarchy, section lengths, ordering)
54
+ 2. Parse the matching golden sample into the same section tree format
55
+ 3. Compare across three structural axes:
56
+
57
+ **Axis 1 — Section Coverage:**
58
+ For each required section in the golden sample, check if the artifact contains a matching section (by heading text or semantic equivalent).
59
+ - `section_coverage = matched_sections / total_golden_sections`
60
+
61
+ **Axis 2 — Ordering Score:**
62
+ Compare the ordering of matched sections against the golden sample ordering.
63
+ - Use normalized Kendall tau distance: `ordering_score = 1 - (inversions / max_inversions)`
64
+ - If fewer than 3 matched sections → ordering_score = 1.0 (too few to meaningfully compare)
65
+
66
+ **Axis 3 — Proportion Score:**
67
+ For each matched section, compute the ratio of artifact section length to golden sample section length.
68
+ - `proportion_score = 1 - mean(|log(artifact_len / golden_len)|)` clamped to [0, 1]
69
+ - Measures whether sections are proportionally sized (not too bloated, not too thin)
70
+
71
+ **Display per-section MATCH/MISS table:**
72
+
73
+ ```
74
+ Golden Section Status Artifact Section Size Ratio
75
+ ─────────────────────────── ──────── ──────────────────────────── ──────────
76
+ ## Overview MATCH ## Overview 1.2x
77
+ ## Protocol MATCH ## Protocol 0.8x
78
+ ## Anti-Patterns MATCH ## Anti-Patterns 1.0x
79
+ ## Dependencies MISS — —
80
+ ## Quick Start MATCH ## Quick Start 1.5x
81
+ ```
82
+
83
+ **Golden Similarity Score:**
84
+ ```
85
+ B0 = section_coverage * 0.50 + ordering_score * 0.25 + proportion_score * 0.25
86
+ ```
87
+
88
+ **Gate:** If B0 < 0.30 → BLOCK immediately. The artifact's structure is too far from the expected form to benchmark meaningfully.
89
+
90
+ ### Step 5: Layer B1 — Deterministic Test Suite
91
+
92
+ **Purpose:** Run all applicable deterministic tests for the detected artifact type. Zero LLM cost.
93
+
94
+ Execute all applicable checks from `benchmark.md` for the detected artifact type. These overlap with but extend the Layer 0 checks from `/bto-test`:
95
+
96
+ **Universal Checks (U1-U12):**
97
+ - U-01: File exists and is non-empty
98
+ - U-02: UTF-8 encoding valid
99
+ - U-03: Starts with level-1 heading
100
+ - U-04: No placeholder text (`[TODO]`, `[TBD]`, `<INSERT>`, `[PLACEHOLDER]`)
101
+ - U-05: No empty sections (heading with no content before next heading)
102
+ - U-06: Consistent heading hierarchy (no h1→h3 jumps)
103
+ - U-07: No broken internal cross-references
104
+ - U-08: File size within bounds (200B – 100KB per file)
105
+ - U-09: No trailing whitespace on lines
106
+ - U-10: Standard Markdown only (no HTML unless in code blocks)
107
+ - U-11: All code blocks properly closed
108
+ - U-12: No duplicate top-level sections
109
+
110
+ **Type-Specific Checks:**
111
+ - Skill: SK-01 through SK-16 (SKILL.md exists, required sections, modules/, references/, examples/, etc.)
112
+ - Command: CM-01 through CM-08 (Usage section, Parameters, Protocol steps, Checkpoint, Critical Rules, etc.)
113
+ - Rule: RL-01 through RL-06 (Table format, detection signals, fix actions, no contradictions, etc.)
114
+ - Agent: AG-01 through AG-04 (Model specified, isolation rules, naming convention, output format)
115
+
116
+ **Display per-test PASS/FAIL table:**
117
+
118
+ ```
119
+ ID Check Result Note
120
+ ─────── ────────────────────────────────── ──────── ────────────────────────────
121
+ U-01 File exists and is non-empty PASS 8.4 KB
122
+ U-02 UTF-8 encoding PASS
123
+ ...
124
+ SK-01 SKILL.md exists at skill root PASS
125
+ SK-02 Has ## Overview section PASS
126
+ SK-03 Has ## Anti-Patterns section FAIL Section missing
127
+ ...
128
+ ```
129
+
130
+ **Test Pass Rate:**
131
+ ```
132
+ B1 = passed_tests / total_applicable_tests
133
+ ```
134
+
135
+ **Gate:** If B1 < 0.60 → BLOCK. Too many structural failures to proceed to consistency probing.
136
+
137
+ ### Step 6: Layer B2 — Consistency Probe
138
+
139
+ **Purpose:** Measure evaluation stability by running identical prompts across multiple agents. Detects artifacts that produce inconsistent interpretations.
140
+
141
+ **Model:** haiku (cost-optimized)
142
+
143
+ **Spawn 3 parallel haiku agents with the identical evaluation prompt:**
144
+
145
+ Each agent receives the exact same prompt:
146
+ ```
147
+ You are evaluating a Claude Code artifact for structural quality.
148
+ Rate these 4 dimensions (0.0 to 1.0 each, two decimal places):
149
+ 1. STRUCTURE — Does the artifact follow a clear, logical organization?
150
+ 2. CLARITY — Are instructions unambiguous and actionable?
151
+ 3. COVERAGE — Does it address all aspects implied by its title/scope?
152
+ 4. CONSISTENCY — Is the internal terminology and style uniform?
153
+ Output as JSON: {"structure": X.XX, "clarity": X.XX, "coverage": X.XX, "consistency": X.XX}
154
+ ```
155
+
156
+ **Isolation:** Each agent evaluates independently. No cross-communication.
157
+
158
+ **After all 3 return, compute structural agreement:**
159
+
160
+ For each dimension:
161
+ ```
162
+ agreement[dim] = 1 - (max(scores[dim]) - min(scores[dim]))
163
+ ```
164
+
165
+ **Consistency Score:**
166
+ ```
167
+ B2 = mean(agreement across all 4 dimensions)
168
+ ```
169
+
170
+ **Interpretation:**
171
+ - B2 > 0.85 → HIGH consistency — the artifact is unambiguously structured
172
+ - B2 0.60-0.85 → MODERATE consistency — some sections are open to interpretation
173
+ - B2 < 0.60 → LOW consistency — the artifact is structurally ambiguous
174
+
175
+ **Display per-probe comparison:**
176
+
177
+ ```
178
+ Dimension Probe 1 Probe 2 Probe 3 Range Agreement
179
+ ──────────── ────────── ────────── ────────── ──────── ──────────
180
+ STRUCTURE 0.80 0.85 0.82 0.05 0.95
181
+ CLARITY 0.70 0.75 0.65 0.10 0.90
182
+ COVERAGE 0.60 0.70 0.55 0.15 0.85
183
+ CONSISTENCY 0.75 0.78 0.73 0.05 0.95
184
+ Mean: 0.91
185
+ ```
186
+
187
+ No gate on B2 — consistency is informational and feeds into the aggregate score.
188
+
189
+ ### Step 7: Layer B3 — Performance Metrics
190
+
191
+ **Purpose:** Quantify token efficiency and information density. Zero LLM cost.
192
+
193
+ **Metric 1 — Token Efficiency:**
194
+ ```
195
+ token_efficiency = meaningful_content_tokens / total_tokens
196
+ ```
197
+ Where `meaningful_content_tokens` excludes: blank lines, decorative separators, repeated boilerplate headers, and excessive whitespace. Target: > 0.70.
198
+
199
+ **Metric 2 — Information Density:**
200
+ ```
201
+ information_density = unique_concepts / total_sections
202
+ ```
203
+ Where `unique_concepts` = count of distinct topics, terms, or instructions introduced. Measures whether each section contributes new information vs. repeating prior content. Target: > 2.0 concepts per section.
204
+
205
+ **Metric 3 — Bloat Detection:**
206
+ Identify sections where:
207
+ - Section length > 3x the golden sample equivalent → BLOATED
208
+ - Section length < 0.2x the golden sample equivalent → THIN
209
+ - Section repeats > 30% of content from another section → REDUNDANT
210
+
211
+ ```
212
+ bloat_score = 1 - (bloated_sections + thin_sections + redundant_sections) / total_sections
213
+ ```
214
+ Clamped to [0, 1].
215
+
216
+ **Performance Score:**
217
+ ```
218
+ B3 = token_efficiency * 0.35 + normalize(information_density, 0, 4) * 0.35 + bloat_score * 0.30
219
+ ```
220
+ Where `normalize(x, min, max)` clamps and scales x to [0, 1].
221
+
222
+ **Display per-section metrics:**
223
+
224
+ ```
225
+ Section Tokens Concepts Golden Ratio Flag
226
+ ───────────────────────── ──────── ────────── ────────────── ──────────
227
+ ## Overview 320 4 1.2x OK
228
+ ## Protocol 1840 12 0.8x OK
229
+ ## Anti-Patterns 580 6 2.8x BLOATED
230
+ ## Quick Start 95 2 0.3x THIN
231
+ ## Dependencies 210 3 1.0x OK
232
+ ```
233
+
234
+ ### Step 8: Aggregate & Gate
235
+
236
+ **BENCHMARK_SCORE formula:**
237
+ ```
238
+ BENCHMARK_SCORE = B0 * 0.30 + B1 * 0.35 + B2 * 0.15 + B3 * 0.20
239
+ ```
240
+
241
+ **Weight rationale:**
242
+ - B0 (Golden Comparison) at 0.30 — structural conformance is the primary benchmark signal
243
+ - B1 (Test Suite) at 0.35 — deterministic correctness is the most reliable signal
244
+ - B2 (Consistency) at 0.15 — stability matters but is a secondary signal
245
+ - B3 (Performance) at 0.20 — efficiency matters for production artifacts
246
+
247
+ **Gate:**
248
+ - BENCHMARK_SCORE < 0.50 → **BLOCK** — artifact requires significant rework before evaluation
249
+ - BENCHMARK_SCORE 0.50-0.70 → **WARN** — artifact has structural issues; proceed to TEST with caution
250
+ - BENCHMARK_SCORE > 0.70 → **PASS** — artifact meets benchmark standards; ready for TEST
251
+
252
+ Record `BENCHMARK_SCORE` for downstream consumption by `/bto-test` and `/bto`.
253
+
254
+ ---
255
+
256
+ ## Checkpoint
257
+
258
+ ```
259
+ ═══════════════════════════════════════════════════════
260
+ CHECKPOINT: BENCHMARK Complete
261
+ <promise>BTO_BENCHMARKED</promise>
262
+ Artifact: [path]
263
+ Type: [detected type]
264
+
265
+ Layer B0 (Golden): X.XX — section coverage, ordering, proportions
266
+ Layer B1 (Test Suite): X.XX — Y/Z tests passed
267
+ Layer B2 (Consistency): X.XX — agreement across 3 probes
268
+ Layer B3 (Performance): X.XX — token efficiency, density, bloat
269
+
270
+ BENCHMARK SCORE: X.XX [PASS / WARN / BLOCK]
271
+
272
+ • "ок" — proceed to TEST
273
+ • "покажи детали [B0/B1/B2/B3]" — expand layer details
274
+ • "пропусти тест" — skip TEST (if PASS)
275
+ ═══════════════════════════════════════════════════════
276
+ ```
277
+
278
+ Wait for user confirmation.
279
+
280
+ ---
281
+
282
+ ## Modular Usage
283
+
284
+ This command is also invoked internally by:
285
+ - `/bto` — as a pre-flight step before TEST phase (if benchmark module is loaded)
286
+ - `/bto-test` — optionally as a prerequisite gate (if user requests `benchmark` flag)
287
+
288
+ The `BENCHMARK_SCORE` is available to downstream commands:
289
+ - `/bto-test` may use it to calibrate Layer 1 expectations
290
+ - `/bto-optimize` may use it to set a structural baseline floor
291
+
292
+ ## Critical Rules
293
+
294
+ - Layer B0 and B1 are fully deterministic — no LLM calls, zero cost
295
+ - Layer B2 uses haiku only — NEVER use sonnet or opus for consistency probes
296
+ - Agent tool is REQUIRED for Layer B2 — do not run probes sequentially
297
+ - Golden samples from `references/golden-samples.md` are the authoritative structural reference
298
+ - If golden sample does not exist for the detected type → skip B0, set B0 = 0.50 (neutral), and log a warning
299
+ - Report `BENCHMARK_SCORE` explicitly so downstream commands can consume it
300
+ - BLOCK verdict at B0 or B1 halts the benchmark — do NOT proceed to subsequent layers
301
+ - Layer B3 bloat detection uses golden sample proportions — without a golden sample, use absolute thresholds only
302
+ - If "verbose" is in $ARGUMENTS, show expanded per-section diagnostics for all layers without prompting
@@ -19,12 +19,12 @@ Read `.claude/skills/bto/SKILL.md`
19
19
  Inspect $ARGUMENTS to determine mode:
20
20
 
21
21
  **If $ARGUMENTS is a path that exists on disk:**
22
- - Mode: TEST → OPTIMIZE
22
+ - Mode: BENCHMARK → TEST → OPTIMIZE
23
23
  - Skip BUILD
24
- - Proceed to Step 4 (TEST)
24
+ - Proceed to Step 4 (BENCHMARK)
25
25
 
26
26
  **If $ARGUMENTS is a natural language description (not a path):**
27
- - Mode: BUILD → TEST → OPTIMIZE
27
+ - Mode: BUILD → BENCHMARK → TEST → OPTIMIZE
28
28
  - Proceed to Step 3 (BUILD)
29
29
 
30
30
  **If $ARGUMENTS is empty:**
@@ -62,7 +62,51 @@ Wait for user confirmation before proceeding.
62
62
 
63
63
  ---
64
64
 
65
- ### Step 4: TEST
65
+ ### Step 4: BENCHMARK
66
+
67
+ Read `.claude/skills/bto/modules/benchmark.md`
68
+ Read `.claude/skills/bto/references/golden-samples.md`
69
+
70
+ **Resolve artifact path:**
71
+ - If BUILD was run → use `BUILD_OUTPUT_PATH`
72
+ - If path was provided in $ARGUMENTS → use that path
73
+
74
+ Execute BENCHMARK protocol:
75
+ 1. **B0 — Golden Sample Comparison:** Diff artifact structure against golden samples
76
+ 2. **B1 — Deterministic Test Suite:** Run rule-based checks (cross-references, terminology, specificity)
77
+ 3. **B2 — Consistency Probe:** Spawn 3 parallel haiku agents to interpret the artifact; measure agreement
78
+ 4. **B3 — Performance Metrics:** Compute token efficiency, section balance, reference/example coverage
79
+
80
+ Compute: `BENCHMARK_SCORE = B0 * 0.30 + B1 * 0.35 + B2 * 0.15 + B3 * 0.20`
81
+
82
+ **Gate decision:**
83
+ - If `BENCHMARK_SCORE < 0.50` → BLOCK. Report per-layer failures. Do NOT proceed to TEST. Stop here.
84
+ - If `BENCHMARK_SCORE 0.50-0.70` → WARN. Proceed to TEST with advisory context for judges.
85
+ - If `BENCHMARK_SCORE > 0.70` → PASS. Proceed to TEST.
86
+
87
+ Record `BENCHMARK_SCORE` for downstream use (TEST judges receive it as quantitative context).
88
+
89
+ **Checkpoint BENCHMARK:**
90
+ ```
91
+ ═══════════════════════════════════════════════════════
92
+ CHECKPOINT 2: BENCHMARK Complete
93
+ Artifact: [path]
94
+ B0 Golden Sample: X.XX
95
+ B1 Test Suite: X.XX
96
+ B2 Consistency: X.XX
97
+ B3 Performance: X.XX
98
+ BENCHMARK_SCORE: X.XX — [PASS / WARN / BLOCK]
99
+
100
+ • "ок" — run TEST
101
+ • "покажи детали [layer]" — expand layer results
102
+ • "исправь" — fix issues and re-benchmark
103
+ ═══════════════════════════════════════════════════════
104
+ ```
105
+ Wait for user confirmation before proceeding.
106
+
107
+ ---
108
+
109
+ ### Step 5: TEST
66
110
 
67
111
  Read `.claude/skills/bto/modules/test.md`
68
112
  Read `.claude/skills/bto/references/judge-rubrics.md`
@@ -71,6 +115,8 @@ Read `.claude/skills/bto/references/judge-rubrics.md`
71
115
  - If BUILD was run → use `BUILD_OUTPUT_PATH`
72
116
  - If path was provided in $ARGUMENTS → use that path
73
117
 
118
+ **BENCHMARK_SCORE is available for judge context.** If BENCHMARK produced a WARN, include the benchmark details in the judge prompt so they can factor quantitative weaknesses into their evaluation.
119
+
74
120
  Execute TEST module in layers:
75
121
 
76
122
  **Layer 0 — Deterministic pre-checks (always run first):**
@@ -98,7 +144,7 @@ Record `TEST_SCORE` (overall weighted average) for use in OPTIMIZE step.
98
144
  **Checkpoint TEST:**
99
145
  ```
100
146
  ═══════════════════════════════════════════════════════
101
- CHECKPOINT 2: TEST Complete
147
+ CHECKPOINT 3: TEST Complete
102
148
  Artifact: [path]
103
149
  Layer 0: X/Y checks passed
104
150
  Layer 1: X.X/10 — [PASS / NEEDS WORK / FAIL]
@@ -114,7 +160,7 @@ Wait for user confirmation before proceeding.
114
160
 
115
161
  ---
116
162
 
117
- ### Step 5: OPTIMIZE
163
+ ### Step 6: OPTIMIZE
118
164
 
119
165
  Read `.claude/skills/bto/modules/optimize.md`
120
166
 
@@ -130,7 +176,7 @@ Execute OPTIMIZE module:
130
176
  **Checkpoint OPTIMIZE:**
131
177
  ```
132
178
  ═══════════════════════════════════════════════════════
133
- CHECKPOINT 3: OPTIMIZE Complete
179
+ CHECKPOINT 4: OPTIMIZE Complete
134
180
  Artifact: [path]
135
181
  Rounds run: 3
136
182
  Total evaluations: 15
@@ -158,14 +204,17 @@ Recommendation: [Apply / Review / Original preferred]
158
204
 
159
205
  Each module can be run independently:
160
206
  - `/bto-build [description]` — BUILD only
207
+ - `/bto-benchmark [path]` — BENCHMARK only
161
208
  - `/bto-test [path]` — TEST only
162
209
  - `/bto-optimize [path]` — OPTIMIZE only
163
210
 
164
211
  ## Critical Rules
165
212
 
166
213
  - Always run Layer 0 before any LLM evaluation — it is free and fast
214
+ - Always run BENCHMARK before TEST — it is cheap and provides quantitative context
215
+ - BENCHMARK gate: if BENCHMARK_SCORE < 0.50, do NOT proceed to TEST
167
216
  - Never skip checkpoints — wait for user "ок" between modules
168
217
  - Only run OPTIMIZE if TEST score < 8.0
169
218
  - Agent tool is REQUIRED for Layer 2 parallel judge panel
170
219
  - BUILD mode: QUICK by default, DEEP only if user explicitly requests it
171
- - Record artifact path from BUILD and pass it through TEST → OPTIMIZE
220
+ - Record artifact path from BUILD and pass it through BENCHMARK → TEST → OPTIMIZE
@@ -10,7 +10,8 @@ These rules apply to ANY evaluation system, not just Keysarium.
10
10
  | Layer | Role | Model | Trigger |
11
11
  |-------|------|-------|---------|
12
12
  | Layer 0 | Structural pre-check (format, completeness) | haiku | Always |
13
- | Layer 1 | Shallow semantic check (relevance, coherence) | haiku | After Layer 0 passes |
13
+ | Benchmark | Golden sample + test suite + consistency + perf | haiku (B2 only) | After Layer 0 passes |
14
+ | Layer 1 | Shallow semantic check (relevance, coherence) | haiku | After Benchmark passes |
14
15
  | Layer 2 | Deep evaluation (quality, domain fit) | sonnet (judge panel) | After Layer 1 passes |
15
16
  | Layer 3 | Creative synthesis / optimization crossover | opus | On top-N candidates only |
16
17
 
@@ -29,6 +30,8 @@ Never promote an artifact to a higher layer if the lower layer gate fails.
29
30
  | Crossover / creative synthesis | opus | Novel combination of best candidates |
30
31
  | Mutation workers (standard) | sonnet | Requires reasoning about improvement direction |
31
32
  | Variant fast-eval (ranking pass) | haiku | Volume scoring before full panel |
33
+ | Benchmark B0-B1,B3 | -- (deterministic) | Zero LLM cost |
34
+ | Benchmark B2 consistency probe | haiku x 3 | Parallel consistency check |
32
35
 
33
36
  Escalate to a higher-cost model only when the lower-cost model has failed or is insufficient.
34
37
 
@@ -44,6 +47,46 @@ Every generated skill or artifact MUST pass ALL of these before entering judge p
44
47
  If any check fails → reject immediately, log reason, do NOT send to judges.
45
48
  Layer 0 may auto-retry up to 3 times before escalating to human review.
46
49
 
50
+ ## Benchmark Gate Rules
51
+
52
+ The BENCHMARK layer sits between Layer 0 and Layer 1 and provides objective, quantitative evaluation before subjective expert judging begins.
53
+
54
+ ### Gate Thresholds
55
+
56
+ | BENCHMARK_SCORE | Decision | Action |
57
+ |-----------------|----------|--------|
58
+ | < 0.50 | BLOCK | Do NOT send to judge panel. Fix structural issues first. Log all failing layers. |
59
+ | 0.50 - 0.70 | WARN | Proceed to TEST with advisory. Include benchmark details in judge context. |
60
+ | > 0.70 | PASS | Proceed to TEST. Benchmark data available as optional judge context. |
61
+
62
+ ### Scoring Formula
63
+
64
+ ```
65
+ BENCHMARK_SCORE = B0 * 0.30 + B1 * 0.35 + B2 * 0.15 + B3 * 0.20
66
+ ```
67
+
68
+ Where:
69
+ - **B0 (Golden Sample Comparison):** Structural diff against known-good artifacts (deterministic, zero LLM cost)
70
+ - **B1 (Deterministic Test Suite):** Cross-reference integrity, terminology consistency, instruction specificity (deterministic, zero LLM cost)
71
+ - **B2 (Consistency Probe):** 3 parallel haiku agents interpret the artifact; measure agreement (LLM cost: haiku x 3)
72
+ - **B3 (Performance Metrics):** Token efficiency, section balance, reference/example coverage (deterministic, zero LLM cost)
73
+
74
+ ### BENCHMARK-to-TEST Integration
75
+
76
+ - If BENCHMARK produces a BLOCK, do NOT invoke Layer 1 or Layer 2 judges. Fix issues and re-benchmark.
77
+ - If BENCHMARK produces a WARN, include the per-layer benchmark scores and failure details in the judge prompt so judges can factor quantitative weaknesses into their subjective evaluation.
78
+ - If BENCHMARK produces a PASS, benchmark data is available but not mandatory for judges.
79
+ - BENCHMARK_SCORE is recorded alongside TEST scores for longitudinal tracking.
80
+
81
+ ### BENCHMARK Anti-Patterns
82
+
83
+ | Anti-Pattern | Detection Signal | Required Fix |
84
+ |-------------|-----------------|--------------|
85
+ | Skipping BENCHMARK for "simple" artifacts | No benchmark record in evaluation output | BENCHMARK is cheap -- always run it |
86
+ | Golden samples outdated | B0 scores systematically low across all artifacts | Review and refresh golden samples quarterly |
87
+ | Consistency probe too lenient | B2 always scores > 0.95 | Vary probe prompts to stress-test edge interpretations |
88
+ | Ignoring WARN and proceeding blindly | No benchmark context in judge prompts after WARN | Always surface WARN details to TEST judges |
89
+
47
90
  ## Judge Panel Rules
48
91
 
49
92
  - Panel MUST have an odd number of judges: 3 (standard) or 5 (high-stakes)
@@ -8,6 +8,7 @@ Load: `.claude/skills/bto/SKILL.md` + relevant module
8
8
  | Layer | Model | Gate | Action on Fail |
9
9
  |-------|-------|------|----------------|
10
10
  | Layer 0 | — (deterministic) | ≥ 80% checks pass | STOP, auto-retry up to 3x |
11
+ | Benchmark | haiku × 3 (B2 only) | score ≥ 0.50 | BLOCK, fix structure |
11
12
  | Layer 1 | haiku | avg ≥ 7.0 | NEEDS WORK (flag) |
12
13
  | Layer 2 | sonnet × 3 judges | weighted avg ≥ 7.0 | FAIL |
13
14
  | Meta | sonnet | disagreement > 3 | Arbitrate |
@@ -30,6 +31,8 @@ Load: `.claude/skills/bto/SKILL.md` + relevant module
30
31
 
31
32
  ## Model Routing
32
33
  - Layer 0: deterministic (no LLM)
34
+ - Benchmark B0, B1, B3: deterministic (no LLM)
35
+ - Benchmark B2: haiku × 3 (consistency probe)
33
36
  - Layer 1: haiku
34
37
  - Layer 2 judges: sonnet
35
38
  - Meta-judge: sonnet
@@ -38,6 +41,7 @@ Load: `.claude/skills/bto/SKILL.md` + relevant module
38
41
 
39
42
  ## Promises
40
43
  - `<promise>BTO_LAYER0_PASSED</promise>` — after Layer 0
44
+ - `<promise>BTO_BENCHMARKED</promise>` — after benchmark
41
45
  - `<promise>BTO_LAYER2_SCORED</promise>` — after Layer 2
42
46
  - `<promise>BTO_OPTIMIZED</promise>` — after optimization converges
43
47