Skip to content

[P.1] chore(hooks): add 800-line file size pre-commit gate - #209

Merged
h4yfans merged 1 commit into
mainfrom
debt/P.1-file-size-precommit
Apr 15, 2026
Merged

[P.1] chore(hooks): add 800-line file size pre-commit gate#209
h4yfans merged 1 commit into
mainfrom
debt/P.1-file-size-precommit

Conversation

@h4yfans

@h4yfans h4yfans commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds .githooks/pre-commit that blocks commits introducing source files over 800 lines. Keeps module boundaries honest: split files before they grow unreviewable.

  • Scope: apps/** and packages/** source only
  • Excluded: tests (*.test.*, *.spec.*, tests/**), *.d.ts, generated IPC map, build output, node_modules, .worktrees, .claude
  • Limit: MAX_LINES=800 (lives in the hook itself)
  • Activation: core.hooksPath=.githooks is set by the existing root prepare script, so pnpm install picks it up automatically

Hook source

` ``sh
#!/usr/bin/env bash

Reject commits that introduce or modify any source file exceeding MAX_LINES.

Keeps module boundaries honest — split files before they become unreviewable.

set -eu

MAX_LINES=800

excluded() {
case "$1" in
node_modules/|/node_modules/) return 0 ;;
.worktrees/
|/.worktrees/) return 0 ;;
.claude/) return 0 ;;
dist/
|/dist/) return 0 ;;
out/|/out/) return 0 ;;
coverage/
|/coverage/) return 0 ;;
tests/|/tests/*) return 0 ;;
.test.ts|.test.tsx) return 0 ;;
.spec.ts|.spec.tsx) return 0 ;;
.d.ts) return 0 ;;
generated-ipc-invoke-map.ts) return 0 ;;
esac
case "$1" in
apps/
|packages/
) return 1 ;;
/) return 0 ;;
*) return 1 ;;
esac
}

offender_files=()
offender_lines=()

while IFS= read -r file; do
[ -z "$file" ] && continue
[ -f "$file" ] || continue
if excluded "$file"; then
continue
fi
lines=$(wc -l < "$file" | tr -d ' ')
if [ "$lines" -gt "$MAX_LINES" ]; then
offender_files+=("$file")
offender_lines+=("$lines")
fi
done < <(git diff --cached --name-only --diff-filter=ACMR)

count=${#offender_files[@]}

if [ "$count" -gt 0 ]; then
printf '\n\033[31mpre-commit: %d file(s) exceed %d-line limit:\033[0m\n\n' "$count" "$MAX_LINES" >&2
printf ' %-70s %s\n' "FILE" "LINES" >&2
printf ' %-70s %s\n' "----" "-----" >&2
for i in "${!offender_files[@]}"; do
printf ' %-70s %s\n' "${offender_files[$i]}" "${offender_lines[$i]}" >&2
done
printf '\nSplit these files into smaller modules before committing.\n' >&2
printf 'Limit lives in .githooks/pre-commit (MAX_LINES).\n\n' >&2
exit 1
fi

exit 0
` ``

Fail-case transcript (801-line file rejected)

` ``
$ awk 'BEGIN{for(i=0;i<801;i++)print "// line " i}' > apps/desktop/src/_throwaway.ts
$ wc -l apps/desktop/src/_throwaway.ts
801 apps/desktop/src/_throwaway.ts
$ git add apps/desktop/src/_throwaway.ts
$ git commit -m "test-oversized"

pre-commit: 1 file(s) exceed 800-line limit:

FILE LINES


apps/desktop/src/_throwaway.ts 801

Split these files into smaller modules before committing.
Limit lives in .githooks/pre-commit (MAX_LINES).
` ``

Hook exits non-zero, commit aborted.

Pass-case transcript (799-line file accepted)

`` \$ awk 'BEGIN{for(i=0;i<799;i++)print "// line " i}' > apps/desktop/src/_okay.ts \$ wc -l apps/desktop/src/_okay.ts 799 apps/desktop/src/_okay.ts \$ git add apps/desktop/src/_okay.ts \$ git commit -m "test-ok" [debt/P.1-file-size-precommit 7d4f5726] test-ok 1 file changed, 799 insertions(+) create mode 100644 apps/desktop/src/_okay.ts \$ git reset --hard HEAD~1 HEAD is now at 77ec9ea3 chore(hooks): add 800-line file size pre-commit gate ``

Test plan

  • Hook file executable (-rwxr-xr-x)
  • core.hooksPath resolves to .githooks (set by root prepare script)
  • 801-line source file commit rejected with clear error
  • 799-line source file commit accepted
  • pnpm lint passes
  • pnpm --filter @memry/desktop typecheck:node passes
  • pnpm --filter @memry/desktop typecheck:web passes
  • pnpm typecheck:packages passes
  • pnpm test passes (ignored known calendar-page.test.tsx:258 "Due draft" flake)

@h4yfans
h4yfans merged commit 9278e37 into main Apr 15, 2026
1 of 2 checks passed
@h4yfans
h4yfans deleted the debt/P.1-file-size-precommit branch May 6, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant