Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

feat(hooks): a pre-push hook that runs the tier-1 eval set

Rach Pradhanc95151a6fc0d
diff --git a/.githooks/pre-push b/.githooks/pre-push
new file mode 100755
index 00000000..98a64c92
--- /dev/null
+++ b/.githooks/pre-push
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+# Tracked pre-push hook. The logic lives in scripts/pre-push.sh so it can be
+# read, run, and tested on its own. Enable with scripts/install-hooks.sh.
+set -euo pipefail
+exec "$(git rev-parse --show-toplevel)/scripts/pre-push.sh" "$@"
diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh
new file mode 100755
index 00000000..6d8d76c4
--- /dev/null
+++ b/scripts/install-hooks.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+# Point git at the tracked hooks in .githooks/. One line, reversible, and it
+# survives clones of this repo because the hooks are versioned with the code.
+#
+# scripts/install-hooks.sh install
+# scripts/install-hooks.sh --uninstall go back to .git/hooks
+set -euo pipefail
+
+repo_root=$(git -C "$(dirname "${BASH_SOURCE[0]}")/.." rev-parse --show-toplevel)
+cd "$repo_root"
+
+if [[ "${1:-}" == "--uninstall" ]]; then
+ git config --unset core.hooksPath || true
+ printf 'hooks: uninstalled (core.hooksPath cleared, .git/hooks is live again)\n'
+ exit 0
+fi
+
+git config core.hooksPath .githooks
+chmod +x .githooks/* scripts/pre-push.sh scripts/eval-tier1.sh 2>/dev/null || true
+
+cat <<'EOF'
+hooks: installed - core.hooksPath now points at .githooks/
+
+ pre-push runs tier 1 of the internal eval set: zig fmt, the 600-line
+ ceiling, test reachability, the unit suite and its count ratchet,
+ the named goal/loop/todo invariants, and SDK drift. Offline, no
+ model calls, ~20-30s warm. Doc-only pushes skip it entirely.
+
+ skip once git push --no-verify
+ GRAFF_SKIP_PREPUSH=1 git push
+ run by hand scripts/eval-tier1.sh
+ one check scripts/eval-tier1.sh --only sdk
+ uninstall scripts/install-hooks.sh --uninstall
+
+Note: setting core.hooksPath replaces .git/hooks wholesale. If you kept local
+hooks there, copy them into .githooks/ first.
+EOF
diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh
new file mode 100755
index 00000000..922b5717
--- /dev/null
+++ b/scripts/pre-push.sh
@@ -0,0 +1,92 @@
+#!/usr/bin/env bash
+# The pre-push gate. Runs tier 1 of the internal eval set (scripts/eval-tier1.sh):
+# deterministic, offline, no model calls, ~20-30s warm.
+#
+# Install it once: scripts/install-hooks.sh
+# Skip it once: git push --no-verify
+# GRAFF_SKIP_PREPUSH=1 git push
+#
+# git feeds us one line per ref being pushed on stdin:
+# <local ref> <local sha> <remote ref> <remote sha>
+# We use that to leave doc-only pushes alone - there is no reason to compile the
+# harness because someone fixed a typo in the README.
+set -uo pipefail
+
+repo_root=$(git rev-parse --show-toplevel)
+cd "$repo_root"
+
+if [[ -n "${GRAFF_SKIP_PREPUSH:-}" ]]; then
+ printf 'pre-push: skipped (GRAFF_SKIP_PREPUSH is set)\n' >&2
+ exit 0
+fi
+
+empty_sha=0000000000000000000000000000000000000000
+changed=""
+run_anyway=0
+saw_ref=0
+
+while read -r _local_ref local_sha _remote_ref remote_sha; do
+ [[ -z "${local_sha:-}" ]] && continue
+ saw_ref=1
+ # Deleting a remote ref pushes nothing to check.
+ [[ "$local_sha" == "$empty_sha" ]] && continue
+
+ base="$remote_sha"
+ if [[ "$remote_sha" == "$empty_sha" ]] || ! git cat-file -e "$remote_sha^{commit}" 2>/dev/null; then
+ # A brand-new branch, or a remote tip we do not have locally. Fall back to
+ # the merge base with the default branch; if even that fails, do not guess -
+ # run the checks.
+ upstream=$(git rev-parse --verify --quiet origin/HEAD || git rev-parse --verify --quiet origin/main)
+ base=$(git merge-base "$local_sha" "$upstream" 2>/dev/null || true)
+ fi
+ if [[ -z "$base" ]]; then
+ run_anyway=1
+ continue
+ fi
+ paths=$(git diff --name-only "$base" "$local_sha" 2>/dev/null) || { run_anyway=1; continue; }
+ changed+=$'\n'"$paths"
+done
+
+if ((!saw_ref)); then
+ exit 0
+fi
+
+changed=$(printf '%s\n' "$changed" | sed '/^$/d' | sort -u)
+
+if ((!run_anyway)) && [[ -n "$changed" ]]; then
+ # shellcheck disable=SC2086
+ if python3 scripts/eval/tier1_invariants.py docs-only $changed; then
+ printf 'pre-push: documentation-only push, tier 1 has nothing to check.\n'
+ printf ' (%s file(s): %s)\n' \
+ "$(printf '%s\n' "$changed" | wc -l | tr -d ' ')" \
+ "$(printf '%s' "$changed" | tr '\n' ' ')"
+ exit 0
+ fi
+fi
+
+if ((!run_anyway)) && [[ -z "$changed" ]]; then
+ printf 'pre-push: nothing new to push.\n'
+ exit 0
+fi
+
+# The checks read the working tree, not the commits being pushed - that is what
+# makes them fast and what makes the SDK-drift gate meaningful. Say so when the
+# two differ, so a red result is never a mystery.
+if ! git diff --quiet HEAD 2>/dev/null; then
+ printf 'pre-push: note - your working tree differs from HEAD; tier 1 checks the tree.\n'
+fi
+
+printf 'pre-push: running tier 1 of the internal eval set (offline, no model calls)\n'
+if bash scripts/eval-tier1.sh; then
+ exit 0
+fi
+
+cat >&2 <<'EOF'
+
+pre-push: BLOCKED. The failing check names are above, each with the one-liner
+ that reruns only it.
+
+ If this is an emergency and you know what you are pushing:
+ git push --no-verify
+EOF
+exit 1