diff --git a/CHANGELOG.md b/CHANGELOG.md index 86f6d75..ebd43d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixture-backed `evals/skills/refactor-process/basic`: duplicated `OrderProcessor` methods, passing characterization tests, and a condensed `skills/refactor-process/SKILL.md`. - xAI (Grok) provider: OpenAI-compatible client at `https://api.x.ai/v1/chat/completions`, default model `grok-4`, `skill-bench init --xai`, env `SKILL_BENCH_XAI_API_KEY` or `XAI_API_KEY`. - Amazon Bedrock provider: Runtime OpenAI-compatible Chat Completions with a Bedrock API key (`AWS_BEARER_TOKEN_BEDROCK` or `SKILL_BENCH_BEDROCK_API_KEY`), default region `us-east-1`, default model `amazon.nova-lite-v1:0`. IAM SigV4 is not included. +- Judge golden trace fixture (`test/fixtures/judge_traces/canonical.json`) and `Judge::Variance` (sample mean/stddev/spread over repeated totals). Verdict math unchanged. ### Documentation - Align user docs with shipped 1.3.1: OpenRouter and mock in the provider list, Azure env var `SKILL_BENCH_AZURE_OPENAI_API_KEY`, Mistral key via `skill-bench.json` (no env mapping). diff --git a/ROADMAP.md b/ROADMAP.md index cda9ac0..848b767 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -10,18 +10,12 @@ Do: turn a small set of those evals into fixture-backed tasks with `task.md`, `c ## 2. xAI / Grok provider -No `Clients::Providers` class exists for xAI. The surrounding skill ecosystem already runs on Grok. Pattern to copy: OpenAI-compatible subclass (see Mistral and OpenRouter). - -Do not fold Bedrock into this item. +Shipped: `Clients::Providers::Xai`, `skill-bench init --xai`. ## 3. AWS Bedrock provider -Closed issue [#47](https://github.com/igmarin/ruby-skill-bench/issues/47) named Bedrock as the larger follow-up to Mistral. This is not a one-file client: auth, regions, and model IDs differ from the OpenAI-compatible adapters. - -Do not start this before OpenRouter (already shipped) is documented and xAI is decided. +Shipped: `Clients::Providers::Bedrock` (Runtime OpenAI-compatible path + Bedrock API key). IAM SigV4 is still deferred. ## 4. Judge reliability -Scores come from an LLM judge (`Evaluation::Runner` → `Judge`) with no golden-trace fixture set and no recorded inter-run variance. Deltas are not product truth until that exists. - -Do not change dimension names or verdict math in the same change as adding traces. +In progress. Golden parser fixture: `test/fixtures/judge_traces/canonical.json`. Sample variance: `Judge::Variance`. Remaining: record inter-run totals from live evals (no verdict-math change). diff --git a/lib/skill_bench.rb b/lib/skill_bench.rb index 3a025da..3648863 100644 --- a/lib/skill_bench.rb +++ b/lib/skill_bench.rb @@ -22,6 +22,7 @@ require_relative 'skill_bench/judge/judge' require_relative 'skill_bench/judge/prompt' require_relative 'skill_bench/judge/response' +require_relative 'skill_bench/judge/variance' # Agent subsystem require_relative 'skill_bench/agent' diff --git a/lib/skill_bench/judge/README.md b/lib/skill_bench/judge/README.md index 096dace..789c84f 100644 --- a/lib/skill_bench/judge/README.md +++ b/lib/skill_bench/judge/README.md @@ -9,6 +9,8 @@ Evaluates AI-generated code modifications by calling an LLM judge. | `judge.rb` | `Judge::Judge` | Orchestrates the LLM judge call | | `prompt.rb` | `Judge::Prompt` | Builds structured prompts from task + criteria | | `response.rb` | `Judge::Response` | Parses and validates judge JSON responses | +| `variance.rb` | `Judge::Variance` | Sample mean/stddev/spread over repeated totals | +| `test/fixtures/judge_traces/` | — | Golden judge JSON that must keep parsing | ## Usage diff --git a/lib/skill_bench/judge/variance.rb b/lib/skill_bench/judge/variance.rb new file mode 100644 index 0000000..025cc2d --- /dev/null +++ b/lib/skill_bench/judge/variance.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require_relative '../error_logger' + +module SkillBench + module Judge + # Sample statistics over repeated judge totals. + class Variance + # @param totals [Array] Judge totals from repeated runs of the same eval. + # @return [Hash] `{ success: true, response: { n:, mean:, stddev:, spread: } }` + def self.call(totals:) + new(totals).call + end + + # @param totals [Array] + def initialize(totals) + @totals = totals + end + + # @return [Hash] + def call + nums = Array(@totals).map { |total| Float(total) } + return empty_result(count: nums.size) if nums.size < 2 + + mean = nums.sum / nums.size + sample_variance = nums.sum { |value| (value - mean)**2 } / (nums.size - 1) + + { + success: true, + response: { + n: nums.size, + mean: mean, + stddev: Math.sqrt(sample_variance), + spread: nums.max - nums.min + } + } + rescue StandardError => e + SkillBench::ErrorLogger.log_error(e, 'Judge::Variance Error') + { success: false, response: { error: { message: e.message } } } + end + + private + + def empty_result(count:) + { success: true, response: { n: count, mean: nil, stddev: nil, spread: nil } } + end + end + end +end diff --git a/test/fixtures/judge_traces/canonical.json b/test/fixtures/judge_traces/canonical.json new file mode 100644 index 0000000..1caad60 --- /dev/null +++ b/test/fixtures/judge_traces/canonical.json @@ -0,0 +1,10 @@ +{ + "dimensions": { + "correctness": { "score": 24, "max_score": 30, "reasoning": "Behavior matches the task." }, + "skill_adherence": { "score": 20, "max_score": 25, "reasoning": "Follows the skill contract." }, + "code_quality": { "score": 16, "max_score": 20, "reasoning": "Clear structure." }, + "test_coverage": { "score": 12, "max_score": 15, "reasoning": "Starting tests still pass." }, + "documentation": { "score": 8, "max_score": 10, "reasoning": "Public API is documented." } + }, + "overall_reasoning": "Canonical golden trace for parser lock-in. Total 80." +} diff --git a/test/judge/golden_trace_test.rb b/test/judge/golden_trace_test.rb new file mode 100644 index 0000000..cea101e --- /dev/null +++ b/test/judge/golden_trace_test.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'test_helper' + +module SkillBench + module Judge + class GoldenTraceTest < Minitest::Test + FIXTURE = File.expand_path('../fixtures/judge_traces/canonical.json', __dir__) + + def test_canonical_trace_parses_to_expected_scores + json = File.read(FIXTURE) + result = Response.call(json: json) + + assert result[:success], "parse failed: #{result.dig(:response, :error, :message)}" + response = result[:response][:judge_response] + dims = response.dimensions + + assert_equal 24, dims['correctness'][:score] + assert_equal 20, dims['skill_adherence'][:score] + assert_equal 16, dims['code_quality'][:score] + assert_equal 12, dims['test_coverage'][:score] + assert_equal 8, dims['documentation'][:score] + total = dims.each_value.sum { |dim| dim[:score] } + + assert_equal 80, total + end + end + end +end diff --git a/test/judge/variance_test.rb b/test/judge/variance_test.rb new file mode 100644 index 0000000..0070444 --- /dev/null +++ b/test/judge/variance_test.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'test_helper' + +module SkillBench + module Judge + class VarianceTest < Minitest::Test + def test_call_returns_mean_stddev_and_spread + result = Variance.call(totals: [80, 86, 83]) + + assert result[:success] + stats = result[:response] + + assert_equal 3, stats[:n] + assert_in_delta 83.0, stats[:mean], 0.001 + assert_in_delta 3.0, stats[:stddev], 0.001 + assert_in_delta 6.0, stats[:spread] + end + + def test_call_returns_nils_when_fewer_than_two_totals + result = Variance.call(totals: [80]) + + assert result[:success] + stats = result[:response] + + assert_equal 1, stats[:n] + assert_nil stats[:mean] + assert_nil stats[:stddev] + assert_nil stats[:spread] + end + end + end +end