Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-harness/blob/main/coder/eval/score.sh # omega-harness Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-harness / coder / eval / score.sh` 112 lines ยท 6267 bytes Raw Blame History 1 #!/bin/sh 2 # Score one model-written program on one task (harness tooling, not product code). 3 # usage: sh score.sh HOME SRC TASK ID [WORK] 4 # HOME OMEGA_HOME (omc, the built gate, seed/qualification/om2/fixtures); omc must be the one PIN names 5 # SRC the program (main.om); TASK holds stdin, expected.out, expected.exit; WORK a scratch directory 6 # (default: a temporary one, removed at exit) 7 # The program is model-written and the om2 gate runs it with the gate's own permissions, so whatever the program 8 # can open it can print. Stage A runs it through the gate with nothing of the task in view but copies of the 9 # program and its stdin (narrow_gate in case.sh): no expected output anywhere it can read. The gate decides 10 # compile, exit status, stderr, deadline and signal there. Stage B is trusted: the gate runs cat.om with the 11 # program's saved stdout as input and the task's expected output as the expected stdout, so the byte comparison 12 # is still the gate's. 13 # Prints the deciding VERDICT line(s), then "SCORE ID VERDICT GATE_RC" (VERDICT one of pass, wrong-output, 14 # timeout, crash, compile-fail; GATE_RC 0 or 1). Stage A's line is printed with its stdout word replaced by 15 # "stdout=(compared in stage B)", since stage A has no expected stdout. Exit 0 = pass, 1 = any other verdict on 16 # the program, 3 = no verdict on the program (omc mismatch, an unreadable file, a gate that did not run or gave 17 # no single verdict): that is the machine's, not the model's. 18 set -u 19 here=$(cd "$(dirname "$0")" && pwd) 20 . "$here/case.sh" 21 home=${1:?home} 22 home=$(cd "$home" && pwd) || { echo "SCORE-ERROR ${4:-} no home directory $1" >&2; exit 3; } 23 src=${2:?src} 24 t=${3:?task} 25 id=${4:?id} 26 work=${5:-} 27 machine() { echo "SCORE-ERROR $id $*" >&2; exit 3; } 28 sha=$(sed -n 's/^omc-sha256 //p' "$here/../../PIN") 29 [ -n "$sha" ] && [ "$(sha256sum < "$home/omc" | cut -d' ' -f1)" = "$sha" ] || machine "$home/omc is not the omc PIN names" 30 if [ -z "$work" ]; then 31 work=$(mktemp -d) 32 trap 'rm -rf "$work"' EXIT 33 fi 34 rm -rf "$work/a" "$work/b" "$work/c" "$work/a.log" "$work/b.log" "$work/c.log" 35 mkdir -p "$work/a/in" "$work/a/run" "$work/b/in" "$work/b/run" || machine "cannot make $work" 36 work=$(cd "$work" && pwd) 37 if [ ! -f "$src" ]; then 38 echo "no $src" 39 echo "SCORE $id compile-fail NA" 40 exit 1 41 fi 42 cp "$src" "$work/a/in/main.om" && cp "$t/stdin" "$work/a/in/stdin" || machine "cannot copy $src or $t/stdin" 43 ex=$(cat "$t/expected.exit") || machine "no $t/expected.exit" 44 # Stage A: stdout "-" here only means the gate's stdout word is replaced below; stderr "-" requires it empty. 45 { 46 echo "deadline $CASE_DEADLINE" 47 printf '%s run %s file:%s - - %s\n' "$id" "$work/a/in/main.om" "$work/a/in/stdin" "$ex" 48 } > "$work/a/in/cases.txt" 49 narrow_gate "$home" "$work/a/in" "$work/a/run" "$home/omc" "$sha" "$work/a/in/cases.txt" "$work/a/run/s" > "$work/a.log" 2>&1 50 arc=$? 51 [ "$(grep -c "^VERDICT $id " "$work/a.log")" = 1 ] || machine "stage A rc $arc gave no single verdict, see $work/a.log" 52 v=$(grep "^VERDICT $id " "$work/a.log") 53 echo "$v" | sed 's/ stdout=match / stdout=(compared in stage B) /; s/ stdout differs at byte [0-9]* / stdout=(compared in stage B) /' 54 case $v in 55 "VERDICT $id INVALID child deadline exceeded"*) echo "SCORE $id timeout 1"; exit 1 ;; 56 "VERDICT $id INVALID child signal"*) echo "SCORE $id crash 1"; exit 1 ;; 57 "VERDICT $id FAIL compile exit="*) echo "SCORE $id compile-fail 1"; exit 1 ;; 58 "VERDICT $id PASS run exit="* | "VERDICT $id FAIL run exit="*) ;; 59 "VERDICT $id INVALID exec or redirect failed (child exit 127)"*) 60 # The gate cannot tell a program that exits 127 from a failed exec or redirect. Run the trusted cat.om the 61 # same way: if the gate gives it a run verdict, exec and redirect work here and 127 was the program's. 62 [ "$ex" != 127 ] || machine "stage A exit 127 is both the expected exit and the gate's exec failure, see $work/a.log" 63 mkdir -p "$work/c/in" "$work/c/run" && cp "$here/cat.om" "$work/c/in/cat.om" && cp "$t/stdin" "$work/c/in/stdin" || 64 machine "cannot copy the exec control's inputs" 65 { 66 echo "deadline $CASE_DEADLINE" 67 printf '%s run %s file:%s - - 0\n' "$id" "$work/c/in/cat.om" "$work/c/in/stdin" 68 } > "$work/c/in/cases.txt" 69 narrow_gate "$home" "$work/c/in" "$work/c/run" "$home/omc" "$sha" "$work/c/in/cases.txt" "$work/c/run/s" > "$work/c.log" 2>&1 70 grep -q "^VERDICT $id [A-Z]* run exit=0 " "$work/c.log" || machine "stage A exec failed and so did the trusted control, see $work/a.log $work/c.log" 71 echo "SCORE $id wrong-output 1" 72 exit 1 73 ;; 74 *) machine "stage A verdict not on the program, see $work/a.log" ;; 75 esac 76 rx=$(echo "$v" | sed -n 's/^.* run exit=\([0-9][0-9]*\) expected=\([0-9][0-9]*\) .*$/\1 \2/p') 77 [ -n "$rx" ] || machine "stage A verdict without exit and expected, see $work/a.log" 78 set -- $rx 79 case $v in 80 *" stderr=match") serr=match ;; 81 *" stderr differs at byte "*) serr=differs ;; 82 *) machine "stage A verdict without a stderr word, see $work/a.log" ;; 83 esac 84 if [ "$1" != "$2" ] || [ "$serr" != match ]; then 85 echo "SCORE $id wrong-output 1" 86 exit 1 87 fi 88 # Stage B: the gate names the program's stdout .out in its scratch; the case is on line 2. 89 [ -f "$work/a/run/s/2.out" ] || machine "stage A left no $work/a/run/s/2.out" 90 cp "$work/a/run/s/2.out" "$work/b/in/got" && cp "$t/expected.out" "$work/b/in/expected.out" && cp "$here/cat.om" "$work/b/in/cat.om" || 91 machine "cannot copy stage B inputs" 92 { 93 echo "deadline $CASE_DEADLINE" 94 printf '%s run %s file:%s file:%s - 0\n' "$id" "$work/b/in/cat.om" "$work/b/in/got" "$work/b/in/expected.out" 95 } > "$work/b/in/cases.txt" 96 narrow_gate "$home" "$work/b/in" "$work/b/run" "$home/omc" "$sha" "$work/b/in/cases.txt" "$work/b/run/s" > "$work/b.log" 2>&1 97 brc=$? 98 [ "$(grep -c "^VERDICT $id " "$work/b.log")" = 1 ] || machine "stage B rc $brc gave no single verdict, see $work/b.log" 99 w=$(grep "^VERDICT $id " "$work/b.log") 100 echo "$w" 101 case $w in 102 "VERDICT $id PASS run exit=0 expected=0 stdout=match stderr=match") 103 [ "$brc" -eq 0 ] && grep -q '^OM2GATE PASS ' "$work/b.log" || machine "stage B PASS with rc $brc, see $work/b.log" 104 echo "SCORE $id pass 0" 105 exit 0 106 ;; 107 "VERDICT $id FAIL run exit=0 expected=0 stdout differs at byte "*" stderr=match") 108 echo "SCORE $id wrong-output 1" 109 exit 1 110 ;; 111 *) machine "stage B verdict not a comparison, see $work/b.log" ;; 112 esac