From 0e33145aa6aa8307fd44b554b5c4624572dc718f Mon Sep 17 00:00:00 2001 From: "J. Kirby Ross" Date: Mon, 27 Oct 2025 07:42:11 -0700 Subject: [PATCH 1/2] chore: add .editorconfig and pre-commit rustfmt check (opt-in via make hooks) --- .editorconfig | 16 ++++++++++++++++ .githooks/pre-commit | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f31040a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 + +[*.{md,mdx}] +trim_trailing_whitespace = false + +[*.{ts,tsx,js,json}] +indent_size = 2 + diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 2c97a1f..51a8c23 100644 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -51,3 +51,18 @@ fi exit 0 +# Format gate: run rustfmt check if Rust files are staged +if git diff --cached --name-only | grep -E '\.rs$' >/dev/null; then + echo "[pre-commit] Running cargo fmt --all -- --check ..." + if ! cargo fmt --all -- --check; then + cat <<'EOM' >&2 +[pre-commit] Formatting check failed. + +Run: cargo fmt --all + +Our policy is to keep the tree rustfmt-clean to reduce review noise and +merge conflicts. The CI also enforces this gate. +EOM + exit 1 + fi +fi From 225778a7d68344e561f76b1f545778c2177fd5aa Mon Sep 17 00:00:00 2001 From: "J. Kirby Ross" Date: Wed, 29 Oct 2025 09:06:21 -0700 Subject: [PATCH 2/2] docs(hooks-formatting): update execution plan + decision log; fix pre-commit to run rustfmt without early exit --- .githooks/pre-commit | 74 +++++++++++++++++++----------------------- docs/decision-log.md | 7 ++++ docs/execution-plan.md | 6 ++++ 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 51a8c23..f9b9fa1 100644 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -2,55 +2,47 @@ set -euo pipefail # Enforce coupling between PRNG algorithm/version and golden regression vector. - PRNG_FILE="crates/rmg-core/src/math/prng.rs" +if git diff --cached --name-only | grep -qx "$PRNG_FILE"; then + DIFF=$(git diff --cached -- "$PRNG_FILE" || true) + # Heuristics to detect algorithm changes: edits to these functions imply behavior change + if echo "$DIFF" | grep -E '^(\+|-)\s*(fn\s+next_u64|fn\s+from_seed_u64|fn\s+from_seed\(|fn\s+next_int\()' >/dev/null; then + ALGO_CHANGED=1 + else + ALGO_CHANGED=0 + fi -# Only run if the PRNG file is staged -if ! git diff --cached --name-only | grep -qx "$PRNG_FILE"; then - exit 0 -fi - -DIFF=$(git diff --cached -- "$PRNG_FILE" || true) - -# Heuristics to detect algorithm changes: edits to these functions imply behavior change -if echo "$DIFF" | grep -E '^(\+|-)\s*(fn\s+next_u64|fn\s+from_seed_u64|fn\s+from_seed\(|fn\s+next_int\()' >/dev/null; then - ALGO_CHANGED=1 -else - ALGO_CHANGED=0 -fi - -# Version bump present? -if echo "$DIFF" | grep -E 'PRNG_ALGO_VERSION' >/dev/null; then - VERSION_CHANGED=1 -else - VERSION_CHANGED=0 -fi + # Version bump present? + if echo "$DIFF" | grep -E 'PRNG_ALGO_VERSION' >/dev/null; then + VERSION_CHANGED=1 + else + VERSION_CHANGED=0 + fi -# Golden regression vector updated? -if echo "$DIFF" | grep -E 'next_int_golden_regression|assert_eq!\(values,\s*vec!\[' >/dev/null; then - GOLDEN_CHANGED=1 -else - GOLDEN_CHANGED=0 -fi + # Golden regression vector updated? + if echo "$DIFF" | grep -E 'next_int_golden_regression|assert_eq!\(values,\s*vec!\[' >/dev/null; then + GOLDEN_CHANGED=1 + else + GOLDEN_CHANGED=0 + fi -FAIL=0 -if [[ "$ALGO_CHANGED" -eq 1 && "$VERSION_CHANGED" -eq 0 ]]; then - echo "pre-commit: PRNG algorithm changed but PRNG_ALGO_VERSION was not bumped." >&2 - FAIL=1 -fi + FAIL=0 + if [[ "$ALGO_CHANGED" -eq 1 && "$VERSION_CHANGED" -eq 0 ]]; then + echo "pre-commit: PRNG algorithm changed but PRNG_ALGO_VERSION was not bumped." >&2 + FAIL=1 + fi -if [[ "$VERSION_CHANGED" -eq 1 && "$GOLDEN_CHANGED" -eq 0 ]]; then - echo "pre-commit: PRNG_ALGO_VERSION bumped but golden regression vector was not updated." >&2 - FAIL=1 -fi + if [[ "$VERSION_CHANGED" -eq 1 && "$GOLDEN_CHANGED" -eq 0 ]]; then + echo "pre-commit: PRNG_ALGO_VERSION bumped but golden regression vector was not updated." >&2 + FAIL=1 + fi -if [[ "$FAIL" -eq 1 ]]; then - echo "pre-commit: Refusing commit. Update algorithm version and golden regression together." >&2 - exit 1 + if [[ "$FAIL" -eq 1 ]]; then + echo "pre-commit: Refusing commit. Update algorithm version and golden regression together." >&2 + exit 1 + fi fi -exit 0 - # Format gate: run rustfmt check if Rust files are staged if git diff --cached --name-only | grep -E '\.rs$' >/dev/null; then echo "[pre-commit] Running cargo fmt --all -- --check ..." diff --git a/docs/decision-log.md b/docs/decision-log.md index b74a1b6..7acd5cc 100644 --- a/docs/decision-log.md +++ b/docs/decision-log.md @@ -14,3 +14,10 @@ | 2025-10-26 | EPI bundle | Adopt entropy, plugin, inspector, runtime config specs (Phase 0.75) | Close causality & extensibility gap | Phase 1 implementation backlog defined | | 2025-10-26 | RMG + Confluence | Adopt RMG v2 (typed DPOi engine) and Confluence synchronization as core architecture | Unify runtime/persistence/tooling on deterministic rewrites | Launch Rust workspace (rmg-core/ffi/wasm/cli), port ECS rules, set up Confluence networking | | 2025-10-27 | Core math split | Split `rmg-core` math into focused submodules (`vec3`, `mat4`, `quat`, `prng`) replacing monolithic `math.rs`. | Improves readability, testability, and aligns with strict linting. | Update imports; no behavior changes intended; follow-up determinism docs in snapshot hashing. | + +## 2025-10-29 — Hooks formatting gate (PR #12) + +- Context: Enforce consistent formatting before commit; avoid CI/docs drift when non-doc files change. +- Decision: Pre-commit runs `cargo fmt --all -- --check` whenever staged Rust files are detected. Retain the PRNG coupling guard but remove the unconditional early exit so formatting still runs when the PRNG file isn’t staged. +- EditorConfig: normalize line endings (LF), ensure final newline, trim trailing whitespace, set 2-space indent for JS/TS/JSON and 4-space for Rust. +- Consequence: Developers get immediate feedback on formatting; cleaner diffs and fewer CI round-trips. diff --git a/docs/execution-plan.md b/docs/execution-plan.md index cfe0d6e..a9f3ef2 100644 --- a/docs/execution-plan.md +++ b/docs/execution-plan.md @@ -33,6 +33,12 @@ This is Codex’s working map for building Echo. Update it relentlessly—each s ## Today’s Intent +> 2025-10-29 — Hooks formatting gate (PR #12) + +- Pre-commit: add rustfmt check for staged Rust files (`cargo fmt --all -- --check`). +- Keep PRNG coupling guard, but avoid early exit so formatting still runs when PRNG file isn't staged. +- .editorconfig: unify whitespace rules (LF, trailing newline, 2-space for JS/TS, 4-space for Rust). + > 2025-10-27 — Core math modularization (PR #5) - **Focus**: Split `rmg-core` math into focused submodules (`vec3`, `mat4`, `quat`, `prng`).