Skip to content

Commit 225778a

Browse files
committed
docs(hooks-formatting): update execution plan + decision log; fix pre-commit to run rustfmt without early exit
1 parent 0e33145 commit 225778a

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

.githooks/pre-commit

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,47 @@
22
set -euo pipefail
33

44
# Enforce coupling between PRNG algorithm/version and golden regression vector.
5-
65
PRNG_FILE="crates/rmg-core/src/math/prng.rs"
6+
if git diff --cached --name-only | grep -qx "$PRNG_FILE"; then
7+
DIFF=$(git diff --cached -- "$PRNG_FILE" || true)
8+
# Heuristics to detect algorithm changes: edits to these functions imply behavior change
9+
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
10+
ALGO_CHANGED=1
11+
else
12+
ALGO_CHANGED=0
13+
fi
714

8-
# Only run if the PRNG file is staged
9-
if ! git diff --cached --name-only | grep -qx "$PRNG_FILE"; then
10-
exit 0
11-
fi
12-
13-
DIFF=$(git diff --cached -- "$PRNG_FILE" || true)
14-
15-
# Heuristics to detect algorithm changes: edits to these functions imply behavior change
16-
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
17-
ALGO_CHANGED=1
18-
else
19-
ALGO_CHANGED=0
20-
fi
21-
22-
# Version bump present?
23-
if echo "$DIFF" | grep -E 'PRNG_ALGO_VERSION' >/dev/null; then
24-
VERSION_CHANGED=1
25-
else
26-
VERSION_CHANGED=0
27-
fi
15+
# Version bump present?
16+
if echo "$DIFF" | grep -E 'PRNG_ALGO_VERSION' >/dev/null; then
17+
VERSION_CHANGED=1
18+
else
19+
VERSION_CHANGED=0
20+
fi
2821

29-
# Golden regression vector updated?
30-
if echo "$DIFF" | grep -E 'next_int_golden_regression|assert_eq!\(values,\s*vec!\[' >/dev/null; then
31-
GOLDEN_CHANGED=1
32-
else
33-
GOLDEN_CHANGED=0
34-
fi
22+
# Golden regression vector updated?
23+
if echo "$DIFF" | grep -E 'next_int_golden_regression|assert_eq!\(values,\s*vec!\[' >/dev/null; then
24+
GOLDEN_CHANGED=1
25+
else
26+
GOLDEN_CHANGED=0
27+
fi
3528

36-
FAIL=0
37-
if [[ "$ALGO_CHANGED" -eq 1 && "$VERSION_CHANGED" -eq 0 ]]; then
38-
echo "pre-commit: PRNG algorithm changed but PRNG_ALGO_VERSION was not bumped." >&2
39-
FAIL=1
40-
fi
29+
FAIL=0
30+
if [[ "$ALGO_CHANGED" -eq 1 && "$VERSION_CHANGED" -eq 0 ]]; then
31+
echo "pre-commit: PRNG algorithm changed but PRNG_ALGO_VERSION was not bumped." >&2
32+
FAIL=1
33+
fi
4134

42-
if [[ "$VERSION_CHANGED" -eq 1 && "$GOLDEN_CHANGED" -eq 0 ]]; then
43-
echo "pre-commit: PRNG_ALGO_VERSION bumped but golden regression vector was not updated." >&2
44-
FAIL=1
45-
fi
35+
if [[ "$VERSION_CHANGED" -eq 1 && "$GOLDEN_CHANGED" -eq 0 ]]; then
36+
echo "pre-commit: PRNG_ALGO_VERSION bumped but golden regression vector was not updated." >&2
37+
FAIL=1
38+
fi
4639

47-
if [[ "$FAIL" -eq 1 ]]; then
48-
echo "pre-commit: Refusing commit. Update algorithm version and golden regression together." >&2
49-
exit 1
40+
if [[ "$FAIL" -eq 1 ]]; then
41+
echo "pre-commit: Refusing commit. Update algorithm version and golden regression together." >&2
42+
exit 1
43+
fi
5044
fi
5145

52-
exit 0
53-
5446
# Format gate: run rustfmt check if Rust files are staged
5547
if git diff --cached --name-only | grep -E '\.rs$' >/dev/null; then
5648
echo "[pre-commit] Running cargo fmt --all -- --check ..."

docs/decision-log.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
1414
| 2025-10-26 | EPI bundle | Adopt entropy, plugin, inspector, runtime config specs (Phase 0.75) | Close causality & extensibility gap | Phase 1 implementation backlog defined |
1515
| 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 |
1616
| 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. |
17+
18+
## 2025-10-29 — Hooks formatting gate (PR #12)
19+
20+
- Context: Enforce consistent formatting before commit; avoid CI/docs drift when non-doc files change.
21+
- 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.
22+
- EditorConfig: normalize line endings (LF), ensure final newline, trim trailing whitespace, set 2-space indent for JS/TS/JSON and 4-space for Rust.
23+
- Consequence: Developers get immediate feedback on formatting; cleaner diffs and fewer CI round-trips.

docs/execution-plan.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ This is Codex’s working map for building Echo. Update it relentlessly—each s
3333

3434
## Today’s Intent
3535

36+
> 2025-10-29 — Hooks formatting gate (PR #12)
37+
38+
- Pre-commit: add rustfmt check for staged Rust files (`cargo fmt --all -- --check`).
39+
- Keep PRNG coupling guard, but avoid early exit so formatting still runs when PRNG file isn't staged.
40+
- .editorconfig: unify whitespace rules (LF, trailing newline, 2-space for JS/TS, 4-space for Rust).
41+
3642
> 2025-10-27 — Core math modularization (PR #5)
3743
3844
- **Focus**: Split `rmg-core` math into focused submodules (`vec3`, `mat4`, `quat`, `prng`).

0 commit comments

Comments
 (0)