#!/usr/bin/env bash # detect.sh — run every self-check detector against one task, then # summarise the verdicts. # # ./detect.sh missed-blocking-llm-calls .. # sequential # ./detect.sh missed-blocking-llm-calls .. -j 6 # six at a time # ./detect.sh missed-blocking-llm-calls -b # + basic # ./detect.sh missed-blocking-llm-calls -r # + run-gated # ./detect.sh missed-blocking-llm-calls -a # + atomic # ./detect.sh missed-blocking-llm-calls -f # force all # set -uo pipefail ROOT=/workspace # detectors resolve every path relative to the toolkit root JOBS=1; BASIC=0; RUN_GATED=0; ATOMIC=0; FORCE_ALL=0; SLUG=""; DETECTORS_BASIC=( detector-answer-obviousness detector-credential-leakage detector-cross-task-reference detector-dimension-misapplication detector-fact-check-rubric-claims detector-good-response-defined detector-good-response-exhaustiveness detector-offline-verifiability detector-over-hinting detector-rubric-clarity detector-rubric-generality detector-snapshot-leakage ) DETECTORS_RUN=( detector-broken-dev-env detector-meaningful-failure detector-run-behaviors ) DETECTORS_ATOMIC=( detector-rubric-coverage detector-rubric-form ) while [[ $# -gt 0 ]]; do case "$1" in -j) JOBS="$2"; shift 2 ;; -b) BASIC=1; shift ;; -r) RUN_GATED=1; shift ;; -a) ATOMIC=1; shift ;; -f) FORCE_ALL=1; shift ;; -*) echo "unknown flag: $1" >&2; exit 2 ;; *) SLUG="$1"; shift ;; esac done [[ -n "$SLUG" ]] || { echo "usage: $0 [-j N] [-a|-r|-f]" >&2; exit 2; } cd "$ROOT" || exit 1 [[ -d "harbor-tasks/$SLUG" ]] || { echo "no such task: harbor-tasks/$SLUG" >&2; exit 2; } LOGDIR="harbor-tasks/$SLUG/detectors/.logs" mkdir -p "$LOGDIR" RUNS=$(find "harbor-tasks/$SLUG/reference-runs" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | wc -l) if [[ $RUNS -eq 0 ]]; then printf ' Warning: No Runs found!\n' fi if [[ BASIC -eq 0 && RUN_GATED -eq 0 && ATOMIC -eq 0 && FORCE_ALL -eq 0 ]]; then BASIC=1 fi QUEUE=() if [[ $BASIC -eq 1 || $FORCE_ALL -eq 1 ]]; then for d in "${DETECTORS_BASIC[@]}"; do QUEUE+=("$d") done fi if [[ $RUN_GATED -eq 1 || $FORCE_ALL -eq 1 ]]; then for d in "${DETECTORS_RUN[@]}"; do QUEUE+=("$d") done fi if [[ $ATOMIC -eq 1 || $FORCE_ALL -eq 1 ]]; then for d in "${DETECTORS_ATOMIC[@]}"; do QUEUE+=("$d") done fi run_one() { local d="$1" slug="$2" logdir="$3" local log="$logdir/$d.log" t0 dt t0=$(date +%s) if timeout 1800 claude -p "/$d $slug" --permission-mode acceptEdits \ >"$log" 2>&1; then dt=$(( $(date +%s) - t0 )) printf ' %-42s ok %4ss\n' "$d" "$dt" else dt=$(( $(date +%s) - t0 )) printf ' %-42s FAILED %4ss → %s\n' "$d" "$dt" "$log" fi } export -f run_one echo "Running ${#QUEUE[@]} detectors on $SLUG (-j $JOBS)" printf '%s\n' "${QUEUE[@]}" \ | xargs -P "$JOBS" -I{} bash -c 'run_one "$@"' _ {} "$SLUG" "$LOGDIR" echo echo "Verdicts:" for d in "${QUEUE[@]}"; do f="harbor-tasks/$SLUG/detectors/$d.md" if [[ -f "$f" ]]; then awk -v n="$d" ' /^---$/ { seen++; next } seen==1 && /^verdict:/ { v=$2 } seen==1 && /^confidence:/ { c=$2 } END { printf " %-42s %-24s %s\n", n, (v?v:"?"), (c?c:"") } ' "$f" else printf ' %-42s %s\n' "$d" "(no report)" fi done