Skip to content

feat(hooks): add Husky git hooks for ui/goose2#8577

Open
matt2e wants to merge 5 commits intomainfrom
git-hooks
Open

feat(hooks): add Husky git hooks for ui/goose2#8577
matt2e wants to merge 5 commits intomainfrom
git-hooks

Conversation

@matt2e
Copy link
Copy Markdown
Collaborator

@matt2e matt2e commented Apr 16, 2026

Summary

  • Add pre-commit hook for ui/goose2 that auto-formats with Biome and runs checks (biome check, file sizes, i18n, typecheck)
  • Add pre-push hook that detects goose2 changes in pushed commits and runs fmt-check, clippy, check, test, build, and tauri-check in parallel
  • Extract reusable helper functions (push_touches, run_parallel) for hook plumbing (these came for free in lefthook)

Test plan

  • Verify pre-commit hook triggers when staging files under ui/goose2/
  • Verify pre-push hook triggers when pushing commits with ui/goose2/ changes
  • Verify hooks are skipped when no goose2 files are involved

🤖 Generated with Claude Code

matt2e added 3 commits April 16, 2026 11:31
Extend the existing Husky setup to cover ui/goose2/, replicating the
checks that block/goose2 ran via Lefthook.

Pre-commit (when staged files touch ui/goose2/):
- Biome auto-format and auto-fix with staged file re-add
- pnpm check (biome check + file size + i18n string checks)

Pre-push (when pushed commits touch ui/goose2/):
- Biome format verification (read-only)
- cargo fmt --check in src-tauri/
- cargo clippy -- -D warnings in src-tauri/
- pnpm check (biome check + file size + i18n)
- pnpm test (vitest)
- pnpm build (tsc + vite build)
- cargo check in src-tauri/

All pre-push jobs run in parallel via background subshells, matching
the parallelization Lefthook provided. The hooks use whole-directory
checks (not lint-staged), consistent with how goose2 was configured.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
Replace inlined pnpm/cargo commands with `just goose2 <recipe>` calls,
matching how block/goose2's Lefthook config delegated to just. This also
fixes the missing pnpm typecheck (now included via `just goose2 check`)
and eliminates drift risk between hooks and justfile recipes.

Pre-commit now uses targeted re-staging of only ui/goose2/ files instead
of `git add -u` which would re-stage all tracked files.

Pre-push replaces six inlined command groups with:
- just goose2 fmt-check
- just goose2 clippy
- just goose2 check
- just goose2 test
- just goose2 build
- just goose2 tauri-check

Rebased onto origin/main to pick up the `mod goose2 'ui/goose2'`
directive added in #8570.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
Move ref-parsing, path-detection, and parallel-execution logic into
reusable shell functions so the hook body reads as pure intent — just
a list of just recipes to run. Failure messages now name the recipe
that failed instead of reporting PID numbers.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e1432515c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .husky/pre-push
Comment on lines +32 to +33
local -a labels=() pids=()
while [[ $# -ge 2 ]]; do
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Make pre-push hook executable by its required shell

The new hook uses Bash-only syntax (local -a, [[ ... ]], array expansion) but the file has no shebang, so Git runs it via /bin/sh on ENOEXEC; in POSIX shells this fails to parse (for example, sh -n .husky/pre-push errors at this line), which prevents git push whenever this hook is installed. Add an explicit Bash shebang (and ensure Bash is available) or rewrite the function in POSIX sh so pushes are not blocked by a syntax error.

Useful? React with 👍 / 👎.

matt2e and others added 2 commits April 16, 2026 12:56
Add a root-level `setup` recipe that sets `core.hooksPath` to `.husky`,
ensuring the git hooks are active after a fresh clone.

Signed-off-by: Matt Toohey <contact@matttoohey.com>

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move the Husky activation (`git config core.hooksPath .husky`) into
`just goose2 setup` since that's the module that uses the hooks. This
keeps setup co-located with the hooks it enables.

Signed-off-by: Matt Toohey <contact@matttoohey.com>

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac5d310aee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .husky/pre-commit

# Run goose2 checks if any staged files are under ui/goose2/
if git diff --cached --name-only | grep -q '^ui/goose2/'; then
if [ -d "ui/goose2" ]; then
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reset working dir before goose2 checks

When staged changes include both ui/desktop/ and ui/goose2/, the earlier block runs cd ui/desktop && pnpm exec lint-staged and leaves the hook in ui/desktop; this makes the new relative check -d "ui/goose2" evaluate false, so the hook prints a warning and skips all goose2 pre-commit checks. That creates a real bypass for the new validation path whenever both areas are committed together.

Useful? React with 👍 / 👎.

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