From 4957c60c9ee985628ad59344e593d20a18ca8fdb Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 19 Apr 2026 17:06:10 -0500 Subject: feat(hooks): add global hooks — PreCompact priorities + git/gh confirm modals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three new machine-wide hooks installed via `make install-hooks`: - `precompact-priorities.sh` (PreCompact) — injects a priority block into the compaction prompt so the generated summary retains information most expensive to reconstruct: unanswered questions, root causes with file:line, subagent findings as primary evidence, exact numbers/IDs, A-vs-B decisions, open TODOs, classified-data handling. - `git-commit-confirm.py` (PreToolUse/Bash) — gates `git commit` behind a confirmation modal showing parsed message, staged files, diff stats, author. Parses both HEREDOC and `-m`/`--message` forms. - `gh-pr-create-confirm.py` (PreToolUse/Bash) — gates `gh pr create` behind a modal showing title, base ← head, reviewers, labels, assignees, milestone, draft flag, body (HEREDOC or quoted). Makefile: adds `install-hooks` / `uninstall-hooks` targets and extends `list` with a Hooks section. Install prints the settings.json snippet (in `hooks/settings-snippet.json`) to merge into `~/.claude/settings.json`. Also: `languages/elisp/claude/hooks/validate-el.sh` now emits JSON with `hookSpecificOutput.additionalContext` on failure (via new `fail_json()` helper) so Claude sees a structured error in context, in addition to the existing stderr output and exit 2. Patterns synthesized clean-room from fcakyon/claude-codex-settings (Apache-2.0). Each hook is original content. --- languages/elisp/claude/hooks/validate-el.sh | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'languages/elisp') diff --git a/languages/elisp/claude/hooks/validate-el.sh b/languages/elisp/claude/hooks/validate-el.sh index 6f93d48..803badf 100755 --- a/languages/elisp/claude/hooks/validate-el.sh +++ b/languages/elisp/claude/hooks/validate-el.sh @@ -1,14 +1,32 @@ #!/usr/bin/env bash # Validate and test .el files after Edit/Write/MultiEdit. # PostToolUse hook: receives tool-call JSON on stdin. -# Silent on success; on failure, prints emacs output and exits 2 -# so Claude sees the error and can correct it. +# +# On success: exit 0 silent. +# On failure: emit JSON with hookSpecificOutput.additionalContext so Claude +# sees a structured error in its context, THEN exit 2 to block the tool +# pipeline. stderr still echoes the error for terminal visibility. # # Phase 1: check-parens + byte-compile -# Phase 2: for modules/*.el, run matching tests/test-*.el +# Phase 2: for non-test .el files, run matching tests/test-*.el set -u +# Emit a JSON failure payload and exit 2. Arguments: +# $1 — short failure type (e.g. "PAREN CHECK FAILED") +# $2 — file path +# $3 — emacs output (error body) +fail_json() { + local ctx + ctx="$(printf '%s: %s\n\n%s\n\nFix before proceeding.' "$1" "$2" "$3" \ + | jq -Rs .)" + cat <&2 + exit 2 +} + # Portable project root: prefer Claude Code's env var, fall back to deriving # from this script's location ($project/.claude/hooks/validate-el.sh). PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$(cd "$(dirname "$0")/../.." && pwd)}" @@ -25,8 +43,7 @@ case "$f" in # Byte-compile here would load the full package graph. Parens only. if ! output="$(emacs --batch --no-site-file --no-site-lisp "$f" \ --eval '(check-parens)' 2>&1)"; then - printf 'PAREN CHECK FAILED: %s\n%s\n' "$f" "$output" >&2 - exit 2 + fail_json "PAREN CHECK FAILED" "$f" "$output" fi ;; *.el) @@ -38,8 +55,7 @@ case "$f" in "$f" \ --eval '(check-parens)' \ --eval "(or (byte-compile-file \"$f\") (kill-emacs 1))" 2>&1)"; then - printf 'VALIDATION FAILED: %s\n%s\n' "$f" "$output" >&2 - exit 2 + fail_json "VALIDATION FAILED" "$f" "$output" fi ;; esac @@ -79,8 +95,7 @@ if [ "$count" -ge 1 ] && [ "$count" -le "$MAX_AUTO_TEST_FILES" ]; then --eval '(package-initialize)' \ -l ert "${load_args[@]}" \ --eval "(ert-run-tests-batch-and-exit '(not (tag :slow)))" 2>&1)"; then - printf 'TESTS FAILED for %s (%d test file(s)):\n%s\n' "$f" "$count" "$output" >&2 - exit 2 + fail_json "TESTS FAILED ($count test file(s))" "$f" "$output" fi fi -- cgit v1.2.3