commands.sh (Template)
#!/usr/bin/env bash
TKT Base — packet commands.sh TEMPLATE (gate runner)
Generalizes the v0.2 commands.sh: run G0..Gn, write exit_codes.json,
print OVERALL_RESULT: PASS|FAIL. Replace the <…> gate bodies.
NON_AUTHORITY: emits exit codes + logs only. No seal, no registry/PG/Directus write.
set -uo pipefail cd "$(dirname "$0")"
PACKET="<PACKET-NAME>" OUT="${1:-./evidence}" mkdir -p "$OUT/logs"
names=(); exps=(); acts=() run_gate () { # name expected_exit cmd... local name="$1" exp="$2"; shift 2 "$@" >"$OUT/logs/$name.log" 2>&1; local act=$? names+=("$name"); exps+=("$exp"); acts+=("$act") printf '%-22s expected=%s actual=%s\n' "$name" "$exp" "$act" }
--- gates (edit these) -------------------------------------------------------
G0: manifest = three-way (tree pin + forward present/hash + backward no-unlisted)
run_gate G0_manifest 0 bash -c ' test "$(shasum -a 256 HASH_MANIFEST.txt | awk "{print $1}")" = "$(cat packet_tree.sha256)" && shasum -a 256 -c HASH_MANIFEST.txt'
G1: checker selftest (replace with your checker)
run_gate G1_selftest 0 true
G2: rerun / reconstruct verdict (replace)
run_gate G2_rerun 0 true
G3: adversarial probes all caught (replace with your probe script)
run_gate G3_probes 0 true
-----------------------------------------------------------------------------
ok=true
{
printf '{\n "packet": "%s",\n "authority": "NON_AUTHORITY / NOT_PROMOTED",\n "gates": [\n' "$PACKET"
for i in "${!names[@]}"; do
g_ok=false; [ "${exps[$i]}" = "${acts[$i]}" ] && g_ok=true || ok=false
comma=,; [ "$i" -eq $(( ${#names[@]} - 1 )) ] && comma=
printf ' {"name": "%s", "expected": %s, "actual": %s, "ok": %s}%s\n'
"${names[$i]}" "${exps[$i]}" "${acts[$i]}" "$g_ok" "$comma"
done
printf ' ]\n}\n'
} > exit_codes.json
if $ok; then echo "OVERALL_RESULT: PASS"; exit 0; else echo "OVERALL_RESULT: FAIL"; exit 1; fi