@jeiemgi/cckit 0.5.0 → 0.7.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/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +34 -3
- package/README.md +95 -6
- package/bin/cckit +90 -3
- package/cckit.config.json +7 -2
- package/kit.config.schema.json +26 -1
- package/package.json +1 -1
- package/profiles/automation.json +2 -1
- package/profiles/content.json +2 -1
- package/profiles/minimal.json +2 -1
- package/profiles/research.json +2 -1
- package/profiles/software.json +2 -1
- package/scripts/benchmark/benchmark-test.sh +83 -0
- package/scripts/benchmark/gate.sh +55 -0
- package/scripts/benchmark/lib/bench-common.sh +70 -0
- package/scripts/benchmark/lib/model.sh +116 -0
- package/scripts/benchmark/report.sh +105 -0
- package/scripts/benchmark/run-quality.sh +102 -0
- package/scripts/benchmark/run.sh +166 -0
- package/scripts/benchmark/stop-check.sh +83 -0
- package/scripts/commitlint-test.sh +58 -0
- package/scripts/init.sh +57 -1
- package/scripts/kit-self-update.sh +55 -0
- package/scripts/lib/board-view-test.sh +1 -0
- package/scripts/lib/board-view.sh +1 -0
- package/scripts/lib/captain-test.sh +62 -0
- package/scripts/lib/captain.sh +105 -17
- package/scripts/lib/cckit-output.sh +1 -0
- package/scripts/lib/commitlint.sh +54 -0
- package/scripts/lib/config-path-test.sh +1 -0
- package/scripts/lib/config-path.sh +1 -0
- package/scripts/lib/copilot-test.sh +1 -0
- package/scripts/lib/copilot.sh +1 -0
- package/scripts/lib/effort-dispatch-test.sh +10 -0
- package/scripts/lib/effort-flows-test.sh +1 -0
- package/scripts/lib/effort-metrics-test.sh +1 -0
- package/scripts/lib/effort-metrics.sh +1 -0
- package/scripts/lib/effort-ops-test.sh +360 -0
- package/scripts/lib/effort-ops.sh +372 -16
- package/scripts/lib/effort-parity-test.sh +1 -0
- package/scripts/lib/effort-plan.sh +1 -0
- package/scripts/lib/effort-slug-test.sh +32 -0
- package/scripts/lib/effort-slug.sh +72 -8
- package/scripts/lib/effort.sh +1 -0
- package/scripts/lib/engine-adapter.sh +1 -0
- package/scripts/lib/errors-header-test.sh +86 -0
- package/scripts/lib/gh-log.sh +1 -0
- package/scripts/lib/gh-project-test.sh +1 -0
- package/scripts/lib/gh-project.sh +1 -0
- package/scripts/lib/git-remote-test.sh +1 -0
- package/scripts/lib/git-remote.sh +1 -0
- package/scripts/lib/handoff.sh +23 -2
- package/scripts/lib/kit-brief-test.sh +292 -0
- package/scripts/lib/kit-brief.sh +376 -0
- package/scripts/lib/kit-cli-test.sh +1 -0
- package/scripts/lib/kit-cli.sh +1 -0
- package/scripts/lib/kit-config-resolve.sh +1 -0
- package/scripts/lib/kit-config-test.sh +14 -0
- package/scripts/lib/kit-config.sh +7 -0
- package/scripts/lib/kit-engine-test.sh +1 -0
- package/scripts/lib/kit-events.sh +1 -0
- package/scripts/lib/kit-gc-test.sh +125 -0
- package/scripts/lib/kit-gc.sh +193 -5
- package/scripts/lib/kit-interview-test.sh +1 -0
- package/scripts/lib/kit-interview.sh +1 -0
- package/scripts/lib/kit-lib-test.sh +226 -0
- package/scripts/lib/kit-lib.sh +308 -0
- package/scripts/lib/kit-local.sh +1 -0
- package/scripts/lib/kit-manifest.sh +1 -0
- package/scripts/lib/kit-mode-test.sh +1 -0
- package/scripts/lib/kit-mode.sh +1 -0
- package/scripts/lib/kit-msg-test.sh +1 -0
- package/scripts/lib/kit-msg.sh +1 -0
- package/scripts/lib/kit-operate.sh +1 -0
- package/scripts/lib/kit-profile-test.sh +1 -0
- package/scripts/lib/kit-profile.sh +1 -0
- package/scripts/lib/kit-state-test.sh +89 -0
- package/scripts/lib/kit-state.sh +61 -0
- package/scripts/lib/kit-status-test.sh +233 -0
- package/scripts/lib/kit-status.sh +415 -0
- package/scripts/lib/kit-task-ops-test.sh +22 -0
- package/scripts/lib/kit-task-ops.sh +51 -2
- package/scripts/lib/next.sh +1 -0
- package/scripts/lib/plan-machine-test.sh +54 -0
- package/scripts/lib/plan-machine.sh +86 -25
- package/scripts/lib/plan-next-test.sh +1 -0
- package/scripts/lib/plan-next.sh +1 -0
- package/scripts/lib/pr-evidence-test.sh +259 -0
- package/scripts/lib/pr-evidence.sh +220 -35
- package/scripts/lib/project-scan.sh +1 -0
- package/scripts/lib/react-detect.sh +1 -0
- package/scripts/lib/render-test.sh +1 -0
- package/scripts/lib/render.sh +1 -0
- package/scripts/lib/role-identity.sh +1 -0
- package/scripts/lib/secret-guard.sh +21 -1
- package/scripts/lib/toon.sh +1 -0
- package/scripts/lib/ui.sh +1 -0
- package/scripts/lib/version-bump-test.sh +1 -0
- package/scripts/lib/version-bump.sh +1 -0
- package/scripts/lib/worktree-bootstrap-test.sh +220 -0
- package/scripts/lib/worktree-issue-test.sh +15 -1
- package/scripts/lib/worktree-issue.sh +23 -8
- package/scripts/lib/worktree-start.sh +191 -7
- package/scripts/lib/zsh-safety-test.sh +10 -0
- package/scripts/orchestrate.sh +8 -1
- package/scripts/portable-test.sh +13 -2
- package/scripts/self-install-test.sh +282 -0
- package/scripts/setup-labels.sh +1 -0
- package/scripts/status.sh +68 -40
- package/scripts/task-sync.sh +13 -0
- package/scripts/ux-a11y-scan.sh +96 -0
- package/scripts/ux-ds-audit.sh +146 -0
- package/scripts/ux-graph-scan.sh +188 -0
- package/skills/kit-autopilot/SKILL.md +6 -1
- package/skills/kit-cleanup/SKILL.md +83 -0
- package/skills/kit-effort-close/SKILL.md +3 -0
- package/skills/kit-effort-new/SKILL.md +7 -0
- package/skills/kit-effort-start/SKILL.md +39 -4
- package/skills/kit-gc/SKILL.md +19 -0
- package/skills/kit-next/SKILL.md +5 -0
- package/skills/kit-status/SKILL.md +92 -0
- package/skills/kit-task-start/SKILL.md +7 -1
- package/skills/kit-ux-audit/SKILL.md +241 -0
- package/skills/kit-ux-audit/references/a11y.md +79 -0
- package/skills/kit-ux-audit/references/consistency.md +106 -0
- package/skills/kit-ux-audit/references/graph-model.md +92 -0
- package/skills/kit-ux-audit/references/heuristics.md +157 -0
- package/skills/kit-ux-audit/references/report.md +172 -0
- package/templates/agents/ux.md +89 -0
- package/templates/benchmarks/SCHEMA.md +75 -0
- package/templates/benchmarks/abstain.jsonl +8 -0
- package/templates/benchmarks/adversarial.jsonl +8 -0
- package/templates/benchmarks/benchmark.config.json +14 -0
- package/templates/benchmarks/quality.jsonl +8 -0
- package/templates/benchmarks/retrieval.jsonl +7 -0
- package/templates/rules/branch-naming.md +20 -1
- package/templates/rules/communication-style.md +8 -0
- package/templates/rules/delegation-brief.md +38 -4
- package/templates/rules/effort-model.md +47 -4
- package/templates/rules/naming-and-ids.md +199 -0
- package/templates/rules/task-management.md +1 -1
- package/templates/settings/settings.json.tmpl +9 -0
- package/templates/skills/concrete/SKILL.md +117 -0
- package/templates/skills/karpathy-guidelines/SKILL.md +1 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# benchmark/gate.sh — the per-round "no-mistakes" bundle for the objective autopilot loop. It is the
|
|
3
|
+
# offline bar every round of growing/hardening the benchmark sets must clear before it counts as a
|
|
4
|
+
# clean round: nothing may be broken by an edit.
|
|
5
|
+
#
|
|
6
|
+
# Checks (all offline — NO model calls):
|
|
7
|
+
# 1. bash -n on every harness script (syntax).
|
|
8
|
+
# 2. run.sh --dry + run-quality.sh --dry on every set (dataset shape: every record well-formed).
|
|
9
|
+
# 3. the project's knowledge-lint (canonical-doc governance), if present — so a set that points at
|
|
10
|
+
# a doc which drifted out of the manifest is caught here.
|
|
11
|
+
#
|
|
12
|
+
# Usage: benchmark/gate.sh [--dir <benchmarks>]
|
|
13
|
+
# Exit 0 = clean round; non-zero = something is broken, do not count the round.
|
|
14
|
+
set -uo pipefail
|
|
15
|
+
|
|
16
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
17
|
+
DIRFLAG=()
|
|
18
|
+
while [ "$#" -gt 0 ]; do
|
|
19
|
+
case "$1" in
|
|
20
|
+
--dir) DIRFLAG=(--dir "$2"); shift 2 ;;
|
|
21
|
+
--dir=*) DIRFLAG=(--dir "${1#*=}"); shift ;;
|
|
22
|
+
-h|--help) sed -n '2,16p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
23
|
+
*) echo "gate.sh: unknown arg '$1'" >&2; exit 2 ;;
|
|
24
|
+
esac
|
|
25
|
+
done
|
|
26
|
+
|
|
27
|
+
fail=0
|
|
28
|
+
note() { printf '%s\n' "$*" >&2; }
|
|
29
|
+
|
|
30
|
+
note "==> [1/3] harness syntax (bash -n)"
|
|
31
|
+
for f in "$SCRIPT_DIR"/*.sh "$SCRIPT_DIR"/lib/*.sh; do
|
|
32
|
+
[ -e "$f" ] || continue
|
|
33
|
+
bash -n "$f" || { note "x syntax: $f"; fail=1; }
|
|
34
|
+
done
|
|
35
|
+
|
|
36
|
+
note "==> [2/3] every set --dry (dataset shape)"
|
|
37
|
+
bash "$SCRIPT_DIR/run.sh" --dry "${DIRFLAG[@]+"${DIRFLAG[@]}"}" || { note "x retrieval/abstain sets failed --dry"; fail=1; }
|
|
38
|
+
bash "$SCRIPT_DIR/run-quality.sh" --dry "${DIRFLAG[@]+"${DIRFLAG[@]}"}" || { note "x quality set failed --dry"; fail=1; }
|
|
39
|
+
|
|
40
|
+
note "==> [3/3] knowledge-lint (canonical-doc governance)"
|
|
41
|
+
# Prefer the project's own linter (it knows the project's knowledge dir + manifest); fall back to
|
|
42
|
+
# the kit's copy. Absent linter is not a failure — the gate stays dependency-light.
|
|
43
|
+
# BENCH_SKIP_KNOWLEDGE_LINT=1 opts out (self-tests run against a throwaway fixture, not a real KB).
|
|
44
|
+
if [ "${BENCH_SKIP_KNOWLEDGE_LINT:-0}" = "1" ]; then
|
|
45
|
+
note " (knowledge-lint skipped — BENCH_SKIP_KNOWLEDGE_LINT=1)"
|
|
46
|
+
elif [ -f "$PWD/scripts/knowledge-lint.sh" ]; then
|
|
47
|
+
bash "$PWD/scripts/knowledge-lint.sh" || { note "x knowledge-lint failed"; fail=1; }
|
|
48
|
+
elif [ -f "$SCRIPT_DIR/../knowledge-lint.sh" ]; then
|
|
49
|
+
bash "$SCRIPT_DIR/../knowledge-lint.sh" || { note "x knowledge-lint failed"; fail=1; }
|
|
50
|
+
else
|
|
51
|
+
note " (knowledge-lint absent — skipping)"
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
[ "$fail" -eq 0 ] && note "PASS benchmark gate clean" || note "FAIL benchmark gate"
|
|
55
|
+
exit "$fail"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# benchmark/lib/bench-common.sh — shared plumbing for the benchmark harness: locate the benchmarks
|
|
3
|
+
# dir + its config, resolve the knowledge dir, read JSONL records, and the objective path-match
|
|
4
|
+
# predicate. Source this; do not execute it. Requires: jq.
|
|
5
|
+
|
|
6
|
+
# Resolve the benchmarks directory: explicit $BENCH_DIR wins, else ./benchmarks under the invoking
|
|
7
|
+
# project, else the example set shipped with cckit (templates/benchmarks) as a last resort so a
|
|
8
|
+
# fresh checkout can `--dry` before it has grown its own data.
|
|
9
|
+
bench_dir() {
|
|
10
|
+
if [ -n "${BENCH_DIR:-}" ]; then printf '%s' "$BENCH_DIR"; return; fi
|
|
11
|
+
if [ -d "$PWD/benchmarks" ]; then printf '%s' "$PWD/benchmarks"; return; fi
|
|
12
|
+
printf '%s' "${BENCH_KIT_ROOT:-.}/templates/benchmarks"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
# The benchmark config (sets + tiers + targets). Optional — the runner falls back to discovering
|
|
16
|
+
# *.jsonl in the dir when it is absent.
|
|
17
|
+
bench_config() {
|
|
18
|
+
local d; d="$(bench_dir)"
|
|
19
|
+
[ -f "$d/benchmark.config.json" ] && printf '%s' "$d/benchmark.config.json"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
# The knowledge dir the docs live in. Prefer the benchmark config, else the loaded kit config
|
|
23
|
+
# (KIT_KNOWLEDGE_DIR), else the conventional default.
|
|
24
|
+
bench_knowledge_dir() {
|
|
25
|
+
local cfg kd
|
|
26
|
+
cfg="$(bench_config)"
|
|
27
|
+
if [ -n "$cfg" ]; then
|
|
28
|
+
kd="$(jq -r '.knowledgeDir // empty' "$cfg" 2>/dev/null)"
|
|
29
|
+
[ -n "$kd" ] && { printf '%s' "$kd"; return; }
|
|
30
|
+
fi
|
|
31
|
+
printf '%s' "${KIT_KNOWLEDGE_DIR:-knowledge}"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Objective top-hit path match. Args: <returned-path> <expected-json>. The expected value may be a
|
|
35
|
+
# single path or a JSON array of acceptable paths (split-canonical). A match is suffix-or-basename
|
|
36
|
+
# equality after stripping ./ and a leading knowledge-dir prefix — lenient about where the model
|
|
37
|
+
# rooted the path, strict about which document it named. Returns 0 on match.
|
|
38
|
+
bench_path_match() {
|
|
39
|
+
local got="$1" expect_json="$2" e norm_got norm_e
|
|
40
|
+
norm_got="$(bench_norm_path "$got")"
|
|
41
|
+
# Iterate the expected paths (works for a bare string too, jq -r '.[]?' handles arrays only, so
|
|
42
|
+
# normalize to an array first).
|
|
43
|
+
while IFS= read -r e; do
|
|
44
|
+
[ -n "$e" ] || continue
|
|
45
|
+
norm_e="$(bench_norm_path "$e")"
|
|
46
|
+
[ "$norm_got" = "$norm_e" ] && return 0
|
|
47
|
+
# basename equality catches "docs/x.md" vs "x.md"
|
|
48
|
+
[ "${norm_got##*/}" = "${norm_e##*/}" ] && [ "${norm_e##*/}" = "$norm_e" -o "${norm_got##*/}" != "$norm_got" ] && return 0
|
|
49
|
+
done < <(printf '%s' "$expect_json" | jq -r 'if type=="array" then .[] else . end' 2>/dev/null)
|
|
50
|
+
return 1
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# Normalize a path for comparison: lowercase, strip surrounding quotes/space, drop a leading ./ and
|
|
54
|
+
# a leading <knowledge-dir>/ segment so "knowledge/a.md" and "a.md" compare equal.
|
|
55
|
+
bench_norm_path() {
|
|
56
|
+
local p="$1" kd
|
|
57
|
+
kd="$(bench_knowledge_dir)"
|
|
58
|
+
p="$(printf '%s' "$p" | tr 'A-Z' 'a-z' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')"
|
|
59
|
+
p="${p#./}"
|
|
60
|
+
p="${p#"$(printf '%s' "$kd" | tr 'A-Z' 'a-z')/"}"
|
|
61
|
+
printf '%s' "$p"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Emit each record of a JSONL set as one compact JSON object per line. Blank lines + # comments are
|
|
65
|
+
# skipped so a set file can be annotated.
|
|
66
|
+
bench_records() {
|
|
67
|
+
local file="$1"
|
|
68
|
+
[ -f "$file" ] || return 0
|
|
69
|
+
grep -vE '^[[:space:]]*(#|$)' "$file" | jq -c '.' 2>/dev/null
|
|
70
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# benchmark/lib/model.sh — the pluggable model backend for the benchmark harness.
|
|
3
|
+
#
|
|
4
|
+
# Two entry points, both cascade-shaped so the backend is swappable with NO hard dependency on a
|
|
5
|
+
# specific provider:
|
|
6
|
+
# bench_ask "<question>" -> prints ONE repo-relative doc path, or "NONE"
|
|
7
|
+
# bench_judge "<claim>" "<answer>" "<must>" -> prints a score in [0,1]
|
|
8
|
+
#
|
|
9
|
+
# Backend selection (first that applies wins), driven by env so a project overrides without editing:
|
|
10
|
+
# BENCH_BACKEND=mock deterministic, offline (tests + --dry); never calls a model
|
|
11
|
+
# BENCH_MODEL_ENDPOINT=<url> any OpenAI-compat /chat/completions endpoint (curl)
|
|
12
|
+
# (default) headless `claude -p` — the $0-API subscription path
|
|
13
|
+
#
|
|
14
|
+
# Everything is stdout-only + exit-code clean so the runner can capture answers and latency without
|
|
15
|
+
# a provider SDK. Source this file; do not execute it.
|
|
16
|
+
|
|
17
|
+
# ---- portable timeout ------------------------------------------------------
|
|
18
|
+
# `timeout(1)` is GNU/coreutils and absent on stock macOS. Fall back to a perl watchdog (perl is a
|
|
19
|
+
# kit dependency, see cckit doctor), then to a no-op that just runs the command. Usage:
|
|
20
|
+
# bench_timeout <seconds> <cmd> [args…]
|
|
21
|
+
bench_timeout() {
|
|
22
|
+
local secs="$1"; shift
|
|
23
|
+
if command -v timeout >/dev/null 2>&1; then
|
|
24
|
+
timeout "$secs" "$@"
|
|
25
|
+
elif command -v gtimeout >/dev/null 2>&1; then
|
|
26
|
+
gtimeout "$secs" "$@"
|
|
27
|
+
elif command -v perl >/dev/null 2>&1; then
|
|
28
|
+
perl -e 'my $s=shift; $SIG{ALRM}=sub{exit 124}; alarm $s; exec @ARGV or exit 127;' "$secs" "$@"
|
|
29
|
+
else
|
|
30
|
+
"$@"
|
|
31
|
+
fi
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
BENCH_TIMEOUT_SECS="${BENCH_TIMEOUT_SECS:-90}"
|
|
35
|
+
|
|
36
|
+
# ---- backend resolution ----------------------------------------------------
|
|
37
|
+
bench_backend() {
|
|
38
|
+
if [ -n "${BENCH_BACKEND:-}" ]; then printf '%s' "$BENCH_BACKEND"; return; fi
|
|
39
|
+
if [ -n "${BENCH_MODEL_ENDPOINT:-}" ]; then printf 'openai'; return; fi
|
|
40
|
+
printf 'claude'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Low-level completion: prompt on $1, prints the model's raw text answer. Empty on failure — the
|
|
44
|
+
# callers decide what an empty answer means (NONE for ask, 0 for judge).
|
|
45
|
+
_bench_complete() {
|
|
46
|
+
local prompt="$1" backend
|
|
47
|
+
backend="$(bench_backend)"
|
|
48
|
+
case "$backend" in
|
|
49
|
+
mock)
|
|
50
|
+
# Deterministic offline stand-in. Never used for scoring — the runner only reaches a real
|
|
51
|
+
# backend when NOT --dry — but keeps the cascade total so sourcing never explodes.
|
|
52
|
+
printf 'NONE' ;;
|
|
53
|
+
openai)
|
|
54
|
+
command -v curl >/dev/null 2>&1 || { return 1; }
|
|
55
|
+
command -v jq >/dev/null 2>&1 || { return 1; }
|
|
56
|
+
local url="${BENCH_MODEL_ENDPOINT%/}/chat/completions"
|
|
57
|
+
local model="${BENCH_MODEL:-gpt-4o-mini}"
|
|
58
|
+
local body
|
|
59
|
+
body="$(jq -n --arg m "$model" --arg p "$prompt" \
|
|
60
|
+
'{model:$m, temperature:0, messages:[{role:"user",content:$p}]}')"
|
|
61
|
+
bench_timeout "$BENCH_TIMEOUT_SECS" curl -sS "$url" \
|
|
62
|
+
-H 'Content-Type: application/json' \
|
|
63
|
+
${BENCH_API_KEY:+-H "Authorization: Bearer $BENCH_API_KEY"} \
|
|
64
|
+
-d "$body" 2>/dev/null \
|
|
65
|
+
| jq -r '.choices[0].message.content // empty' 2>/dev/null ;;
|
|
66
|
+
claude|*)
|
|
67
|
+
command -v claude >/dev/null 2>&1 || { return 1; }
|
|
68
|
+
# Headless one-shot. `-p` prints the final answer and exits; the model may use its tools to
|
|
69
|
+
# grep the repo, which is exactly the retrieval behavior we want to measure.
|
|
70
|
+
bench_timeout "$BENCH_TIMEOUT_SECS" claude -p "$prompt" 2>/dev/null ;;
|
|
71
|
+
esac
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# ---- bench_ask -------------------------------------------------------------
|
|
75
|
+
# Ask the model which single canonical doc answers a question. Returns ONE repo-relative path (its
|
|
76
|
+
# top hit) or the literal NONE when nothing canonical covers it. $2 = knowledge dir (for the prompt).
|
|
77
|
+
bench_ask() {
|
|
78
|
+
local question="$1" kdir="${2:-knowledge}" out
|
|
79
|
+
local prompt
|
|
80
|
+
prompt="You are auditing a project's documentation. Question: \"$question\"
|
|
81
|
+
|
|
82
|
+
Find the SINGLE canonical document under '$kdir/' that best answers it. Reply with ONLY that
|
|
83
|
+
document's repo-relative path on one line (for example: $kdir/releasing.md) and nothing else.
|
|
84
|
+
If no document genuinely answers it, reply with exactly: NONE"
|
|
85
|
+
out="$(_bench_complete "$prompt")" || return 1
|
|
86
|
+
# Keep only the last non-empty line, trimmed — models sometimes narrate before the path.
|
|
87
|
+
out="$(printf '%s\n' "$out" | awk 'NF{last=$0} END{print last}')"
|
|
88
|
+
out="$(printf '%s' "$out" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//; s/^["`'\'']//; s/["`'\'']$//')"
|
|
89
|
+
[ -n "$out" ] || out="NONE"
|
|
90
|
+
printf '%s' "$out"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# ---- bench_judge -----------------------------------------------------------
|
|
94
|
+
# Score a claim-style answer against a `must` rubric (newline-separated points). The rubric de-biases
|
|
95
|
+
# the judge: it scores coverage of the required points, not vibes. Prints a float in [0,1].
|
|
96
|
+
bench_judge() {
|
|
97
|
+
local claim="$1" answer="$2" must="$3" out score
|
|
98
|
+
local prompt
|
|
99
|
+
prompt="Grade an answer against a rubric. Be strict and objective.
|
|
100
|
+
|
|
101
|
+
QUESTION/CLAIM:
|
|
102
|
+
$claim
|
|
103
|
+
|
|
104
|
+
ANSWER TO GRADE:
|
|
105
|
+
$answer
|
|
106
|
+
|
|
107
|
+
REQUIRED POINTS (the answer must cover these; ignore style):
|
|
108
|
+
$must
|
|
109
|
+
|
|
110
|
+
Reply with ONLY a number between 0 and 1 (e.g. 0.75) = the fraction of required points the answer
|
|
111
|
+
correctly covers. No words."
|
|
112
|
+
out="$(_bench_complete "$prompt")" || { printf '0'; return 0; }
|
|
113
|
+
score="$(printf '%s' "$out" | grep -oE '0(\.[0-9]+)?|1(\.0+)?' | head -1)"
|
|
114
|
+
[ -n "$score" ] || score="0"
|
|
115
|
+
printf '%s' "$score"
|
|
116
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# benchmark/report.sh — turn a benchmark run into a plain, low-jargon RESULTS.md a non-expert can
|
|
3
|
+
# read: what we tested, what passed, and the one headline score. Runs the retrieval + quality tiers
|
|
4
|
+
# (unless handed pre-computed JSON on stdin) and writes RESULTS.md into the benchmarks dir.
|
|
5
|
+
#
|
|
6
|
+
# Usage:
|
|
7
|
+
# benchmark/report.sh [--dir <benchmarks>] [--dry] [--out <path>]
|
|
8
|
+
# benchmark/run.sh --json | benchmark/report.sh --stdin # report a run you already have
|
|
9
|
+
#
|
|
10
|
+
# --dry run both tiers in --dry (offline, no model) so the report renders the shape of the
|
|
11
|
+
# suite without spending a model call — handy in CI to prove report.sh works.
|
|
12
|
+
set -uo pipefail
|
|
13
|
+
|
|
14
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
15
|
+
# shellcheck source=/dev/null
|
|
16
|
+
. "$SCRIPT_DIR/lib/bench-common.sh"
|
|
17
|
+
|
|
18
|
+
DRY=0; OUT=""; STDIN=0
|
|
19
|
+
while [ "$#" -gt 0 ]; do
|
|
20
|
+
case "$1" in
|
|
21
|
+
--dry) DRY=1; shift ;;
|
|
22
|
+
--stdin) STDIN=1; shift ;;
|
|
23
|
+
--out) OUT="$2"; shift 2 ;;
|
|
24
|
+
--out=*) OUT="${1#*=}"; shift ;;
|
|
25
|
+
--dir) BENCH_DIR="$2"; export BENCH_DIR; shift 2 ;;
|
|
26
|
+
--dir=*) BENCH_DIR="${1#*=}"; export BENCH_DIR; shift ;;
|
|
27
|
+
-h|--help) sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
28
|
+
*) echo "report.sh: unknown arg '$1'" >&2; exit 2 ;;
|
|
29
|
+
esac
|
|
30
|
+
done
|
|
31
|
+
|
|
32
|
+
command -v jq >/dev/null 2>&1 || { echo "report.sh: jq is required" >&2; exit 2; }
|
|
33
|
+
|
|
34
|
+
DIR="$(bench_dir)"
|
|
35
|
+
[ -n "$OUT" ] || OUT="$DIR/RESULTS.md"
|
|
36
|
+
DRYFLAG=""; [ "$DRY" -eq 1 ] && DRYFLAG="--dry"
|
|
37
|
+
|
|
38
|
+
# Gather the two tier summaries (retrieval+abstain+adversarial in one, quality separately).
|
|
39
|
+
if [ "$STDIN" -eq 1 ]; then
|
|
40
|
+
RET_JSON="$(cat)"
|
|
41
|
+
QUAL_JSON='{"kind":"quality-run","dry":true,"count":0,"mean":0,"results":[]}'
|
|
42
|
+
else
|
|
43
|
+
RET_JSON="$(bash "$SCRIPT_DIR/run.sh" $DRYFLAG --json 2>/dev/null || echo '{}')"
|
|
44
|
+
QUAL_JSON="$(bash "$SCRIPT_DIR/run-quality.sh" $DRYFLAG --json 2>/dev/null || echo '{}')"
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
# Pull the numbers with safe defaults (a tier may be absent).
|
|
48
|
+
r_total="$(printf '%s' "$RET_JSON" | jq -r '.total // 0')"
|
|
49
|
+
r_pass="$(printf '%s' "$RET_JSON" | jq -r '.pass // 0')"
|
|
50
|
+
r_pct="$(printf '%s' "$RET_JSON" | jq -r '.score_pct // 0')"
|
|
51
|
+
r_dry="$(printf '%s' "$RET_JSON" | jq -r '.dry // false')"
|
|
52
|
+
q_count="$(printf '%s' "$QUAL_JSON" | jq -r '.count // 0')"
|
|
53
|
+
q_mean="$(printf '%s' "$QUAL_JSON" | jq -r '.mean // 0')"
|
|
54
|
+
|
|
55
|
+
STAMP="$(date -u '+%Y-%m-%d %H:%M UTC' 2>/dev/null || echo 'unknown time')"
|
|
56
|
+
MODE="live"; [ "$r_dry" = "true" ] && MODE="dry (data validated offline, no model asked)"
|
|
57
|
+
|
|
58
|
+
# Per-tier breakdown table from the detailed results.
|
|
59
|
+
TIER_ROWS="$(printf '%s' "$RET_JSON" | jq -r '
|
|
60
|
+
(.results // []) | group_by(.tier)[]
|
|
61
|
+
| { tier: .[0].tier, pass: (map(select(.pass)) | length), total: length }
|
|
62
|
+
| "| \(.tier) | \(.pass)/\(.total) | \( (if .total>0 then (.pass*100/.total) else 0 end) | floor )% |"' 2>/dev/null)"
|
|
63
|
+
[ -n "$TIER_ROWS" ] || TIER_ROWS="| (no per-tier detail in --dry) | $r_pass/$r_total | ${r_pct}% |"
|
|
64
|
+
|
|
65
|
+
{
|
|
66
|
+
echo "# Documentation benchmark — RESULTS"
|
|
67
|
+
echo
|
|
68
|
+
echo "_Generated ${STAMP} · mode: ${MODE}_"
|
|
69
|
+
echo
|
|
70
|
+
echo "## What this measures"
|
|
71
|
+
echo
|
|
72
|
+
echo "How well this project's own canonical documents can be **found and used** by an agent that"
|
|
73
|
+
echo "starts cold — the same way a new teammate or an AI assistant would. A high score means the"
|
|
74
|
+
echo "docs are discoverable and the answers in them are complete."
|
|
75
|
+
echo
|
|
76
|
+
echo "## Headline"
|
|
77
|
+
echo
|
|
78
|
+
if [ "$r_dry" = "true" ]; then
|
|
79
|
+
echo "- **Offline shape check** — ${r_total} retrieval/abstain records and the quality set were"
|
|
80
|
+
echo " validated as well-formed. This is not a live score; run without \`--dry\` to score."
|
|
81
|
+
else
|
|
82
|
+
echo "- **Retrieval score: ${r_pct}%** — of ${r_total} questions, the agent pointed at the right"
|
|
83
|
+
echo " canonical document (or correctly abstained) **${r_pass}** times."
|
|
84
|
+
if [ "$q_count" -gt 0 ]; then
|
|
85
|
+
echo "- **Answer quality: ${q_mean} / 1.0** — average completeness of ${q_count} judged answers."
|
|
86
|
+
fi
|
|
87
|
+
fi
|
|
88
|
+
echo
|
|
89
|
+
echo "## By tier"
|
|
90
|
+
echo
|
|
91
|
+
echo "| Tier | Passed | Score |"
|
|
92
|
+
echo "| --- | --- | --- |"
|
|
93
|
+
printf '%s\n' "$TIER_ROWS"
|
|
94
|
+
echo
|
|
95
|
+
echo "## How to read this"
|
|
96
|
+
echo
|
|
97
|
+
echo "- **Retrieval** — plain questions; can the agent find the one right doc?"
|
|
98
|
+
echo "- **Adversarial** — reworded / no-keyword / trap questions; does retrieval survive them?"
|
|
99
|
+
echo "- **Abstain** — questions with no documented answer; the agent must say \"none\", not invent one."
|
|
100
|
+
echo "- **Quality** — the answer is graded 0–1 for completeness against a fixed checklist."
|
|
101
|
+
echo
|
|
102
|
+
echo "Run again with \`benchmark/report.sh\` after any docs or kit change to catch regressions."
|
|
103
|
+
} > "$OUT"
|
|
104
|
+
|
|
105
|
+
echo "report.sh: wrote $OUT (retrieval ${r_pct}%${q_count:+, quality ${q_mean}})"
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# benchmark/run-quality.sh — the quality judge tier.
|
|
3
|
+
#
|
|
4
|
+
# Beyond "did the agent find the doc", this measures "was the answer correct + complete". For each
|
|
5
|
+
# claim-style record the model answers headlessly (bench_ask-style, but a full answer), then a judge
|
|
6
|
+
# scores that answer 0..1 against the record's `must` rubric. The rubric de-biases the judge: it
|
|
7
|
+
# grades coverage of the required points, not tone. The tier score is the mean.
|
|
8
|
+
#
|
|
9
|
+
# Usage:
|
|
10
|
+
# benchmark/run-quality.sh [--set <file>] [--dir <benchmarks>] [--dry] [--json]
|
|
11
|
+
#
|
|
12
|
+
# --dry validate every record has a claim + a non-empty `must` rubric; call NO model; exit 0.
|
|
13
|
+
# --set run one quality set; else every tier:"quality" set in benchmark.config.json (or every
|
|
14
|
+
# *quality*.jsonl in the dir).
|
|
15
|
+
set -uo pipefail
|
|
16
|
+
|
|
17
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
18
|
+
# shellcheck source=/dev/null
|
|
19
|
+
. "$SCRIPT_DIR/lib/bench-common.sh"
|
|
20
|
+
# shellcheck source=/dev/null
|
|
21
|
+
. "$SCRIPT_DIR/lib/model.sh"
|
|
22
|
+
|
|
23
|
+
DRY=0; JSON=0; ONE_SET=""
|
|
24
|
+
while [ "$#" -gt 0 ]; do
|
|
25
|
+
case "$1" in
|
|
26
|
+
--dry) DRY=1; shift ;;
|
|
27
|
+
--json|--llm) JSON=1; shift ;;
|
|
28
|
+
--set) ONE_SET="$2"; shift 2 ;;
|
|
29
|
+
--set=*) ONE_SET="${1#*=}"; shift ;;
|
|
30
|
+
--dir) BENCH_DIR="$2"; export BENCH_DIR; shift 2 ;;
|
|
31
|
+
--dir=*) BENCH_DIR="${1#*=}"; export BENCH_DIR; shift ;;
|
|
32
|
+
-h|--help) sed -n '2,18p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
33
|
+
*) echo "run-quality.sh: unknown arg '$1'" >&2; exit 2 ;;
|
|
34
|
+
esac
|
|
35
|
+
done
|
|
36
|
+
|
|
37
|
+
command -v jq >/dev/null 2>&1 || { echo "run-quality.sh: jq is required" >&2; exit 2; }
|
|
38
|
+
|
|
39
|
+
DIR="$(bench_dir)"
|
|
40
|
+
KDIR="$(bench_knowledge_dir)"
|
|
41
|
+
CFG="$(bench_config)"
|
|
42
|
+
|
|
43
|
+
SETS=()
|
|
44
|
+
if [ -n "$ONE_SET" ]; then
|
|
45
|
+
f="$ONE_SET"; [ -f "$f" ] || f="$DIR/$ONE_SET"
|
|
46
|
+
SETS+=("$f")
|
|
47
|
+
elif [ -n "$CFG" ]; then
|
|
48
|
+
while IFS= read -r f; do [ -n "$f" ] && SETS+=("$DIR/$f"); done \
|
|
49
|
+
< <(jq -r '.sets[]? | select((.tier // "") == "quality") | .file' "$CFG")
|
|
50
|
+
else
|
|
51
|
+
for f in "$DIR"/*quality*.jsonl; do [ -e "$f" ] && SETS+=("$f"); done
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
[ "${#SETS[@]}" -ge 1 ] || { echo "run-quality.sh: no quality sets found in $DIR" >&2; exit 2; }
|
|
55
|
+
|
|
56
|
+
N=0; SUM="0"; FAILN=0
|
|
57
|
+
RESULTS_JSON="[]"
|
|
58
|
+
|
|
59
|
+
for file in "${SETS[@]}"; do
|
|
60
|
+
[ -f "$file" ] || { echo "run-quality.sh: set missing: $file" >&2; FAILN=$((FAILN+1)); continue; }
|
|
61
|
+
while IFS= read -r rec; do
|
|
62
|
+
[ -n "$rec" ] || continue
|
|
63
|
+
id="$(printf '%s' "$rec" | jq -r '.id // "?"')"
|
|
64
|
+
claim="$(printf '%s' "$rec" | jq -r '.claim // .q // empty')"
|
|
65
|
+
must="$(printf '%s' "$rec" | jq -r '(.must // []) | join("\n")')"
|
|
66
|
+
|
|
67
|
+
if [ "$DRY" -eq 1 ]; then
|
|
68
|
+
N=$((N+1))
|
|
69
|
+
if [ -z "$claim" ]; then echo "run-quality.sh --dry: $file id=$id missing 'claim'" >&2; FAILN=$((FAILN+1)); fi
|
|
70
|
+
if [ -z "$must" ]; then echo "run-quality.sh --dry: $file id=$id has empty 'must' rubric" >&2; FAILN=$((FAILN+1)); fi
|
|
71
|
+
continue
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
answer="$(bench_ask "$claim" "$KDIR")"
|
|
75
|
+
score="$(bench_judge "$claim" "$answer" "$must")"
|
|
76
|
+
N=$((N+1))
|
|
77
|
+
SUM="$(awk -v a="$SUM" -v b="$score" 'BEGIN{printf "%.4f", a+b}')"
|
|
78
|
+
RESULTS_JSON="$(printf '%s' "$RESULTS_JSON" | jq -c \
|
|
79
|
+
--arg set "$(basename "$file")" --arg id "$id" --arg score "$score" \
|
|
80
|
+
'. + [{set:$set,id:$id,score:($score|tonumber)}]')"
|
|
81
|
+
done < <(bench_records "$file")
|
|
82
|
+
done
|
|
83
|
+
|
|
84
|
+
MEAN="0"; [ "$N" -gt 0 ] && MEAN="$(awk -v s="$SUM" -v n="$N" 'BEGIN{printf "%.3f", s/n}')"
|
|
85
|
+
|
|
86
|
+
if [ "$JSON" -eq 1 ]; then
|
|
87
|
+
jq -n --argjson n "$N" --arg mean "$MEAN" --argjson dry "$DRY" --argjson results "$RESULTS_JSON" \
|
|
88
|
+
'{kind:"quality-run", dry:($dry==1), count:$n, mean:($mean|tonumber), results:$results}'
|
|
89
|
+
else
|
|
90
|
+
printf 'quality run%s — %s\n' "$([ "$DRY" -eq 1 ] && echo ' (--dry)')" "$DIR"
|
|
91
|
+
if [ "$DRY" -eq 1 ]; then
|
|
92
|
+
printf 'validated %s record(s)\n' "$N"
|
|
93
|
+
else
|
|
94
|
+
printf 'mean score: %s over %s claim(s)\n' "$MEAN" "$N"
|
|
95
|
+
fi
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
if [ "$DRY" -eq 1 ]; then
|
|
99
|
+
[ "$FAILN" -eq 0 ] && exit 0 || exit 1
|
|
100
|
+
fi
|
|
101
|
+
# A live quality run is informational (a mean, not a pass/fail bar) — exit 0 unless a set was missing.
|
|
102
|
+
[ "$FAILN" -eq 0 ] && exit 0 || exit 1
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# benchmark/run.sh — the retrieval + abstain runner (objective, no judge).
|
|
3
|
+
#
|
|
4
|
+
# Measures how well a cold agent finds the project's OWN canonical docs. For each record it asks the
|
|
5
|
+
# model which single doc answers the question (bench_ask), then scores by objective top-hit path
|
|
6
|
+
# match against the record's expected path(s). Three tiers share this runner:
|
|
7
|
+
# retrieval direct questions -> top-hit path must match expected
|
|
8
|
+
# adversarial paraphrased / no-keyword / split-canonical / trap -> same scoring, harder inputs
|
|
9
|
+
# abstain unanswerable -> ANY path returned is a FAIL; only NONE passes
|
|
10
|
+
#
|
|
11
|
+
# Usage:
|
|
12
|
+
# benchmark/run.sh [--set <file>] [--tier retrieval|adversarial|abstain]
|
|
13
|
+
# [--dir <benchmarks>] [--dry] [--json]
|
|
14
|
+
#
|
|
15
|
+
# --dry validate every record's shape and count them; call NO model. Always exits 0 on
|
|
16
|
+
# well-formed data — the no-mistakes gate + CI run this offline.
|
|
17
|
+
# --set run one set file; otherwise every non-quality set in benchmark.config.json (or every
|
|
18
|
+
# *.jsonl in the dir when there is no config), each scored per its declared tier.
|
|
19
|
+
# --json machine-readable summary on stdout (for report.sh / autopilot); human table otherwise.
|
|
20
|
+
set -uo pipefail
|
|
21
|
+
|
|
22
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
23
|
+
# shellcheck source=/dev/null
|
|
24
|
+
. "$SCRIPT_DIR/lib/bench-common.sh"
|
|
25
|
+
# shellcheck source=/dev/null
|
|
26
|
+
. "$SCRIPT_DIR/lib/model.sh"
|
|
27
|
+
|
|
28
|
+
DRY=0; JSON=0; ONE_SET=""; FORCE_TIER=""
|
|
29
|
+
while [ "$#" -gt 0 ]; do
|
|
30
|
+
case "$1" in
|
|
31
|
+
--dry) DRY=1; shift ;;
|
|
32
|
+
--json|--llm) JSON=1; shift ;;
|
|
33
|
+
--set) ONE_SET="$2"; shift 2 ;;
|
|
34
|
+
--set=*) ONE_SET="${1#*=}"; shift ;;
|
|
35
|
+
--tier) FORCE_TIER="$2"; shift 2 ;;
|
|
36
|
+
--tier=*) FORCE_TIER="${1#*=}"; shift ;;
|
|
37
|
+
--dir) BENCH_DIR="$2"; export BENCH_DIR; shift 2 ;;
|
|
38
|
+
--dir=*) BENCH_DIR="${1#*=}"; export BENCH_DIR; shift ;;
|
|
39
|
+
-h|--help) sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
40
|
+
*) echo "run.sh: unknown arg '$1'" >&2; exit 2 ;;
|
|
41
|
+
esac
|
|
42
|
+
done
|
|
43
|
+
|
|
44
|
+
command -v jq >/dev/null 2>&1 || { echo "run.sh: jq is required" >&2; exit 2; }
|
|
45
|
+
|
|
46
|
+
DIR="$(bench_dir)"
|
|
47
|
+
KDIR="$(bench_knowledge_dir)"
|
|
48
|
+
CFG="$(bench_config)"
|
|
49
|
+
|
|
50
|
+
# Build the list of "<file>|<tier>" sets to run.
|
|
51
|
+
SETS=()
|
|
52
|
+
if [ -n "$ONE_SET" ]; then
|
|
53
|
+
f="$ONE_SET"; [ -f "$f" ] || f="$DIR/$ONE_SET"
|
|
54
|
+
t="${FORCE_TIER:-retrieval}"
|
|
55
|
+
# Infer tier from filename when not forced.
|
|
56
|
+
[ -n "$FORCE_TIER" ] || case "$(basename "$f")" in
|
|
57
|
+
*abstain*) t="abstain" ;;
|
|
58
|
+
*adversar*) t="adversarial" ;;
|
|
59
|
+
*) t="retrieval" ;;
|
|
60
|
+
esac
|
|
61
|
+
SETS+=("$f|$t")
|
|
62
|
+
elif [ -n "$CFG" ]; then
|
|
63
|
+
while IFS= read -r line; do
|
|
64
|
+
[ -n "$line" ] && SETS+=("$line")
|
|
65
|
+
done < <(jq -r '.sets[]? | select((.tier // "retrieval") != "quality") | "\(.file)|\(.tier // "retrieval")"' "$CFG")
|
|
66
|
+
else
|
|
67
|
+
# No config: discover *.jsonl, infer tier from filename, skip quality.
|
|
68
|
+
for f in "$DIR"/*.jsonl; do
|
|
69
|
+
[ -e "$f" ] || continue
|
|
70
|
+
case "$(basename "$f")" in
|
|
71
|
+
*quality*) continue ;;
|
|
72
|
+
*abstain*) SETS+=("$f|abstain") ;;
|
|
73
|
+
*adversar*) SETS+=("$f|adversarial") ;;
|
|
74
|
+
*) SETS+=("$f|retrieval") ;;
|
|
75
|
+
esac
|
|
76
|
+
done
|
|
77
|
+
fi
|
|
78
|
+
|
|
79
|
+
[ "${#SETS[@]}" -ge 1 ] || { echo "run.sh: no sets found in $DIR" >&2; exit 2; }
|
|
80
|
+
|
|
81
|
+
# ---- portable millisecond clock (latency) ---------------------------------
|
|
82
|
+
now_ms() {
|
|
83
|
+
if date +%s%3N >/dev/null 2>&1 && [ "$(date +%3N)" != "3N" ]; then
|
|
84
|
+
date +%s%3N
|
|
85
|
+
else
|
|
86
|
+
printf '%s000' "$(date +%s)" # second resolution fallback (BSD date)
|
|
87
|
+
fi
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
TOTAL=0; PASS=0; FAILN=0
|
|
91
|
+
RESULTS_JSON="[]"
|
|
92
|
+
HUMAN=""
|
|
93
|
+
|
|
94
|
+
for spec in "${SETS[@]}"; do
|
|
95
|
+
file="${spec%%|*}"; tier="${spec##*|}"
|
|
96
|
+
[ -f "$file" ] || file="$DIR/$file" # config lists bare filenames relative to the benchmarks dir
|
|
97
|
+
s_total=0; s_pass=0
|
|
98
|
+
if [ ! -f "$file" ]; then
|
|
99
|
+
HUMAN="${HUMAN} ! set missing: $file (tier=$tier)\n"
|
|
100
|
+
continue
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
while IFS= read -r rec; do
|
|
104
|
+
[ -n "$rec" ] || continue
|
|
105
|
+
id="$(printf '%s' "$rec" | jq -r '.id // "?"')"
|
|
106
|
+
q="$(printf '%s' "$rec" | jq -r '.q // .claim // empty')"
|
|
107
|
+
expect="$(printf '%s' "$rec" | jq -c '.expect // "NONE"')"
|
|
108
|
+
|
|
109
|
+
# --dry: shape validation only. Every record needs a question; non-abstain needs an expect path.
|
|
110
|
+
if [ "$DRY" -eq 1 ]; then
|
|
111
|
+
s_total=$((s_total+1)); TOTAL=$((TOTAL+1))
|
|
112
|
+
if [ -z "$q" ]; then
|
|
113
|
+
echo "run.sh --dry: $file id=$id missing 'q'/'claim'" >&2; FAILN=$((FAILN+1)); continue
|
|
114
|
+
fi
|
|
115
|
+
if [ "$tier" != "abstain" ] && [ "$expect" = '"NONE"' ]; then
|
|
116
|
+
echo "run.sh --dry: $file id=$id ($tier) has no 'expect' path" >&2; FAILN=$((FAILN+1)); continue
|
|
117
|
+
fi
|
|
118
|
+
s_pass=$((s_pass+1)); PASS=$((PASS+1))
|
|
119
|
+
continue
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
# Live: ask the model, score objectively.
|
|
123
|
+
t0="$(now_ms)"
|
|
124
|
+
got="$(bench_ask "$q" "$KDIR")"
|
|
125
|
+
t1="$(now_ms)"; lat=$((t1 - t0)); [ "$lat" -ge 0 ] || lat=0
|
|
126
|
+
|
|
127
|
+
ok=0
|
|
128
|
+
if [ "$tier" = "abstain" ]; then
|
|
129
|
+
# Only NONE passes; any path returned = hallucinated retrieval = fail.
|
|
130
|
+
case "$(printf '%s' "$got" | tr 'A-Z' 'a-z')" in none|"") ok=1 ;; *) ok=0 ;; esac
|
|
131
|
+
else
|
|
132
|
+
if [ "$(printf '%s' "$got" | tr 'A-Z' 'a-z')" = "none" ]; then ok=0
|
|
133
|
+
elif bench_path_match "$got" "$expect"; then ok=1; fi
|
|
134
|
+
fi
|
|
135
|
+
|
|
136
|
+
s_total=$((s_total+1)); TOTAL=$((TOTAL+1))
|
|
137
|
+
if [ "$ok" -eq 1 ]; then s_pass=$((s_pass+1)); PASS=$((PASS+1)); else FAILN=$((FAILN+1)); fi
|
|
138
|
+
|
|
139
|
+
RESULTS_JSON="$(printf '%s' "$RESULTS_JSON" | jq -c \
|
|
140
|
+
--arg set "$(basename "$file")" --arg tier "$tier" --arg id "$id" \
|
|
141
|
+
--arg got "$got" --argjson expect "$expect" --argjson ok "$ok" --argjson lat "$lat" \
|
|
142
|
+
'. + [{set:$set,tier:$tier,id:$id,got:$got,expect:$expect,pass:($ok==1),latency_ms:$lat}]')"
|
|
143
|
+
done < <(bench_records "$file")
|
|
144
|
+
|
|
145
|
+
pct=0; [ "$s_total" -gt 0 ] && pct=$(( s_pass * 100 / s_total ))
|
|
146
|
+
HUMAN="${HUMAN} $tier ($(basename "$file")): $s_pass/$s_total (${pct}%)\n"
|
|
147
|
+
done
|
|
148
|
+
|
|
149
|
+
SCORE_PCT=0; [ "$TOTAL" -gt 0 ] && SCORE_PCT=$(( PASS * 100 / TOTAL ))
|
|
150
|
+
|
|
151
|
+
if [ "$JSON" -eq 1 ]; then
|
|
152
|
+
jq -n --argjson total "$TOTAL" --argjson pass "$PASS" --argjson fail "$FAILN" \
|
|
153
|
+
--argjson pct "$SCORE_PCT" --argjson dry "$DRY" --argjson results "$RESULTS_JSON" \
|
|
154
|
+
'{kind:"retrieval-run", dry:($dry==1), total:$total, pass:$pass, fail:$fail, score_pct:$pct, results:$results}'
|
|
155
|
+
else
|
|
156
|
+
printf 'benchmark run%s — %s\n' "$([ "$DRY" -eq 1 ] && echo ' (--dry)')" "$DIR"
|
|
157
|
+
printf '%b' "$HUMAN"
|
|
158
|
+
printf 'total: %s/%s passed (%s%%)\n' "$PASS" "$TOTAL" "$SCORE_PCT"
|
|
159
|
+
fi
|
|
160
|
+
|
|
161
|
+
# --dry always succeeds on well-formed data (it is the offline gate). A live run exits non-zero when
|
|
162
|
+
# anything failed so autopilot / CI notice a retrieval regression.
|
|
163
|
+
if [ "$DRY" -eq 1 ]; then
|
|
164
|
+
[ "$FAILN" -eq 0 ] && exit 0 || exit 1
|
|
165
|
+
fi
|
|
166
|
+
[ "$FAILN" -eq 0 ] && exit 0 || exit 1
|