makeover-webview 0.38.0

The webview renderer for makeover-layout. Emits CSS, and is the one renderer that needs no palette: var() is the late binding, so resolution stays with the browser.
Documentation
#!/bin/bash
# Canonical pre-commit gate. Byte-identical in every repo under ~/Code.
#
# DO NOT EDIT IN PLACE. The master is _private/infra/bootstrap/githooks/pre-commit
# and install-githooks.sh --check reports any copy that has drifted from it. Edit
# the master, re-run the installer, commit the repos it touched.
#
# Activate in a fresh clone (one-time):
#   git config core.hooksPath scripts/githooks
# clone-tree.sh does this for every repo it clones, so only a hand clone needs it.
#
# Bypass for a work-in-progress commit: git commit --no-verify
#
# Every gate below decides for itself whether it applies, from what is in the repo
# and what is staged. That is what lets one file serve a library, an app and a
# server: the repo's shape selects the gates rather than a per-repo edit, which is
# the drift that let makeover-immediate 0.18.0 reach its release preflight
# unformatted and left eight violations sitting on quasi's main (infra a33fdaab).
#
# NOT here, deliberately: clippy. It is slow enough that a commit-time gate is one
# people bypass, so it stays in CI and the sweep.
#
# Genuinely repo-local extras go in scripts/githooks/pre-commit.local, which this
# runs last if it exists.
set -euo pipefail

ROOT="$(git rev-parse --show-toplevel)"
cd "$ROOT"

# git invoked from an editor, a cron job, or a non-interactive shell does not
# source the profile that puts ~/.local/bin on PATH, and a hook that silently
# cannot find gitleaks or cargo is worse than no hook. (Lesson from _private's
# own hook, which is stricter still: it refuses to commit blind.)
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"

# --- secret scan (gitleaks) -------------------------------------------------
# Independent guardrail: blocks a commit whose staged changes contain a secret,
# regardless of whether a human judged the value "safe". Shared ruleset lives at
# ~/Code/.gitleaks.toml. Degrades gracefully if gitleaks is not installed (the
# astra pre-receive hook is the backstop that always runs). Task: infra 97ffeda0.
if command -v gitleaks >/dev/null 2>&1; then
    GL_CFG=""
    if [ -f "$ROOT/.gitleaks.toml" ]; then
        GL_CFG="$ROOT/.gitleaks.toml"
    elif [ -f "$HOME/Code/.gitleaks.toml" ]; then
        GL_CFG="$HOME/Code/.gitleaks.toml"
    fi
    gl_args=(git --staged --no-banner --redact)
    [ -n "$GL_CFG" ] && gl_args+=(-c "$GL_CFG")
    if ! gitleaks "${gl_args[@]}"; then
        echo "pre-commit: gitleaks found a secret in the staged changes."
        echo "            remove it (or allowlist a false positive), then restage."
        echo "            bypass: git commit --no-verify."
        exit 1
    fi
    echo "pre-commit: gitleaks clean."
else
    echo "pre-commit: gitleaks not installed; skipping secret scan (astra gates on push)."
fi

# --- migration immutability -------------------------------------------------
# Applies to any repo with migrations, which is why it is not MNW-local: sqlx
# checksums a migration's whole file when it runs it and refuses one whose bytes
# changed since, so editing an already-applied migration breaks every deploy
# against that database with "previously applied but modified" -- for a comment
# edit, and for a line-ending change, exactly as much as for a schema change.
#
# The 2026-07-27 exorcise sweep rewrote comments in 29 applied MNW migrations and
# converted one from CRLF to LF. Nothing in the test suite checksums a migration,
# so it stayed invisible while it blocked every server deploy for three days.
#
# goingson and balanced_breakfast are in scope too: both kept their
# `_sqlx_migrations` ledger verbatim through the 2026-08-07 rusqlite migration, so
# an upgraded install still reads those rows and an edited file still contradicts
# them. Adding a new migration is always fine; this only blocks M/D/R.
touched="$(git diff --cached --name-only --diff-filter=MDR -- '*migrations/*.sql')"
if [ -n "$touched" ]; then
    echo "pre-commit: these already-committed migrations were modified, renamed, or deleted:"
    while IFS= read -r m; do
        [ -n "$m" ] && echo "              $m"
    done <<< "$touched"
    echo "            A migration is immutable once applied; the runner checksums the"
    echo "            whole file, comments included. Write a new migration instead."
    echo "            Bypass ONLY if it has never been applied anywhere, including"
    echo "            prod, staging, and your dev database: git commit --no-verify."
    exit 1
fi

# --- frontend design-system lint --------------------------------------------
# Runs any scripts/lint-frontend.sh the repo carries when the commit touches a
# frontend asset. Each of those scripts resolves its own paths from its location,
# so finding them is enough and no path knowledge belongs here. Both known scripts
# live at repo root (goingson, balanced_breakfast) or one level down (MNW's is
# server/scripts/lint-frontend.sh), hence the depth-2 search.
#
# This sits ABOVE the rustfmt gate deliberately: that gate exits early when no .rs
# files are staged, which is exactly the case where a frontend commit needs
# checking. goingson's copy also runs the JS suite, which carries the CHRONIC-XSS
# escaping gate.
staged_fe="$(git diff --cached --name-only --diff-filter=ACMR -- '*.js' '*.css' '*.html')"
if [ -n "$staged_fe" ]; then
    while IFS= read -r lint; do
        [ -n "$lint" ] || continue
        if ! fe_out=$(bash "$lint" 2>&1); then
            echo "$fe_out"
            echo "pre-commit: frontend lint failed ($lint)."
            echo "            fix the rules above, then restage."
            echo "            bypass: git commit --no-verify."
            exit 1
        fi
        echo "pre-commit: frontend lint clean ($lint)."
    done <<< "$(find . -maxdepth 3 -path ./target -prune -o \
        -path '*/scripts/lint-frontend.sh' -print 2>/dev/null | sort)"
fi

# --- rustfmt ----------------------------------------------------------------
# Blocks a commit whose staged Rust files are not formatted. Only crates with
# staged .rs changes are checked, so the hook stays fast on a large repo. Each
# file maps to the nearest enclosing Cargo.toml and the check runs as `cargo fmt`
# there, which picks up that crate's edition and any rustfmt.toml rather than
# guessing -- and is why this works unchanged in MNW, which has no root workspace.
#
# SKIP_PATHS is an extended regex of repo-relative paths to ignore. Empty means
# check everything. Set it in pre-commit.local if a repo ever needs one.
SKIP_PATHS="${SKIP_PATHS:-}"

staged="$(git diff --cached --name-only --diff-filter=ACMR -- '*.rs')"
if [ -n "$SKIP_PATHS" ]; then
    staged="$(printf '%s\n' "$staged" | grep -Ev "$SKIP_PATHS" || true)"
fi

if [ -n "$staged" ]; then
    # Map each staged file to the directory of its nearest Cargo.toml.
    crates=""
    while IFS= read -r f; do
        [ -n "$f" ] || continue
        d="$(dirname "$f")"
        while [ "$d" != "." ] && [ ! -f "$d/Cargo.toml" ]; do
            d="$(dirname "$d")"
        done
        [ -f "$d/Cargo.toml" ] || continue
        crates="$crates$d"$'\n'
    done <<< "$staged"

    crates="$(printf '%s' "$crates" | sort -u)"

    failed=0
    while IFS= read -r c; do
        [ -n "$c" ] || continue
        if ! (cd "$c" && cargo fmt --check >/dev/null 2>&1); then
            echo "pre-commit: rustfmt gate failed in $c"
            failed=1
        fi
    done <<< "$crates"

    if [ "$failed" -ne 0 ]; then
        echo "pre-commit: run 'cargo fmt' in the crates above, then restage."
        echo "pre-commit: commit aborted (use --no-verify to bypass)."
        exit 1
    fi
    echo "pre-commit: rustfmt gate clean."
fi

# --- openapi.json staleness -------------------------------------------------
# Only fires in a repo that commits a generated spec, which today is MNW alone.
#
# server/openapi.json is a committed artifact and `openapi::tests::
# committed_spec_matches_generated` asserts it matches the generated spec. The
# spec embeds CARGO_PKG_VERSION, so EVERY version bump invalidates it even when no
# route changed.
#
# Nothing local caught that. The /deploy pre-push guard is a `cargo test --no-run`
# compile check, and the spec is read at runtime by path rather than include_str!,
# so a stale copy compiles fine. On 2026-08-06 the v0.11.8 bump left the spec at
# 0.11.7, pushed clean to all three remotes, and killed Sando run 38 about fifteen
# minutes in -- two full remote build cycles for a one-line diff in info.version.
#
# So: regenerate to stdout and compare against the STAGED copy (not the working
# tree one -- regenerating without restaging is the same bug wearing a hat).
if [ -f "$ROOT/server/openapi.json" ]; then
    specish="$(git diff --cached --name-only --diff-filter=ACMR \
        -- 'server/Cargo.toml' 'server/src/*.rs' 'server/src/**/*.rs' 'server/openapi.json')"
    if [ -n "$specish" ]; then
        echo "pre-commit: checking openapi.json against the generated spec..."
        gen="$(mktemp)"
        trap 'rm -f "$gen"' EXIT
        if (cd "$ROOT/server" && cargo run --quiet --bin export-openapi -- --stdout) > "$gen" 2>/dev/null; then
            if ! git show :server/openapi.json 2>/dev/null | diff -q - "$gen" >/dev/null; then
                echo "pre-commit: server/openapi.json is stale (or regenerated but not staged)."
                echo "            cd server && cargo run --bin export-openapi"
                echo "            git add server/openapi.json"
                echo "            Then vendor the same bytes into the OTHER repo, which this"
                echo "            commit cannot carry and Sando will fail on:"
                echo "              cp server/openapi.json ../synckit/synckit-client/tests/openapi.json"
                echo "            Bypass: git commit --no-verify."
                exit 1
            fi
            echo "pre-commit: openapi.json current."
        else
            echo "pre-commit: could not build export-openapi; skipping spec check."
            echo "            cargo_test in Sando is the backstop, 15 minutes into the build."
        fi
    fi
fi

# --- repo-local extras ------------------------------------------------------
# The escape hatch for a gate that cannot be selected from the repo's shape. Keep
# it small: anything a second repo wants belongs in the canonical file above,
# guarded by its own detection.
if [ -f "$ROOT/scripts/githooks/pre-commit.local" ]; then
    bash "$ROOT/scripts/githooks/pre-commit.local" || exit 1
fi