Rainer Gerhards 7ab72b6f58 devtools: add repo-local Codex commit hook
Add a repo-local Codex hook setup under `.codex/` so trusted Codex
users get pre-commit guardrails automatically in this repository.

The hook intercepts Bash-based `git commit` tool calls and first runs
the deterministic repo-policy focus checks against the staged commit
snapshot so invariant violations are reported before formatting.

If those checks pass, the hook runs
`./devtools/format-code.sh --git-changed`, skips unrelated Git commands,
allows commits when `clang-format-18` is unavailable, skips formatting
when no tracked `.c` or `.h` files changed, and blocks partial-staging
cases or real formatter failures.

When formatting changes files, the hook re-stages only the tracked files
that were already part of the pending commit.

Add `devtools/list-git-changed-c-h-files.sh` so the hook and formatter
share one source of truth for tracked changed `.c` and `.h` files.

With the help of AI-Agents: Codex
2026-03-28 14:10:06 +01:00
..

Codex Repo Setup

This repository ships a repo-local Codex hook configuration for trusted projects.

What it does

  • Enables Codex hooks for this repository via .codex/config.toml
  • Runs .codex/pre_commit_format_gate.sh before Bash-based git commit commands
  • Runs the deterministic repo-policy focus checks first against the staged commit snapshot
  • If those invariants fail, the hook exits early and prints the specific failures for the agent to fix
  • The hook runs ./devtools/format-code.sh --git-changed
  • If clang-format-18 is not installed, the hook allows the commit without blocking
  • If no tracked .c or .h files have changed, the hook skips formatting work
  • If formatting fails, the git commit tool call is blocked and Codex is told to fix formatting first
  • If formatting updates .c or .h files, the hook stages those tracked formatter updates automatically and then allows the commit
  • If partially staged .c or .h files are present, the hook blocks because auto-restaging would not be safe

Requirements

  • The repository must be trusted so Codex loads .codex/config.toml
  • Codex hooks must be available in your Codex build

Scope

This affects Codex users working in this repository. It does not replace normal project review or CI checks, and it does not affect contributors who are not using Codex.