Skip to content

fix(hooks): auto-stage .gemini, .claude, .codex directories on commit#174

Merged
skulidropek merged 5 commits intoProverCoderAI:mainfrom
konard:issue-170-d462ee89bc6a
Mar 22, 2026
Merged

fix(hooks): auto-stage .gemini, .claude, .codex directories on commit#174
skulidropek merged 5 commits intoProverCoderAI:mainfrom
konard:issue-170-d462ee89bc6a

Conversation

@konard
Copy link
Contributor

@konard konard commented Mar 22, 2026

Summary

Fixes #170

The pre-commit hook and setup infrastructure had three issues preventing automatic backup of AI agent config directories (.gemini, .claude, .codex):

  1. .claude was listed in .gitignore — making it impossible to track in git
  2. Pre-commit hook only staged .knowledge directories.gemini, .claude, .codex were never auto-staged
  3. setup-pre-commit-hook.js required a manual git config core.hooksPath .githooks step — easy to forget, causing all hooks (including pre-push session backup) to never activate

Changes

  • .gitignore: Remove .claude entry so the directory can be tracked
  • .githooks/pre-commit: Add auto-staging loop for .gemini, .claude, .codex directories (same pattern as existing .knowledge staging)
  • scripts/setup-pre-commit-hook.js:
    • Include AI directory staging in the generated pre-commit hook template
    • Auto-configure core.hooksPath = .githooks instead of printing a manual instruction

How it works

On every git commit, the pre-commit hook now:

  1. Splits/stages .knowledge directories (existing behavior)
  2. Auto-stages any existing .gemini, .claude, .codex directories (new)
  3. Checks file size limits (existing behavior)
  4. Runs secret guard (existing behavior)

On git push, the existing pre-push hook (which was already in .githooks/pre-push) runs session backup via session-backup-gist.js. This hook was already correct — the problem was that core.hooksPath was never set, so it was never invoked.

Root cause

The setup-pre-commit-hook.js script (run via npm run setup:pre-commit-hook) only printed a message telling the user to run git config core.hooksPath .githooks manually. If that step was skipped, no hooks ran at all — neither pre-commit nor pre-push.

Tests

Added packages/app/tests/hooks/pre-commit-ai-dirs.test.ts with 10 tests covering:

AI directory auto-staging logic (isolated temp git repos):

  • ∀ dir ∈ {.gemini, .claude, .codex}: exists(dir) → staged(dir/*)
  • Skips non-existent directories without error
  • Stages nested files recursively
  • Handles empty directories gracefully

setup-pre-commit-hook.js:

  • Creates .githooks/pre-commit with executable permissions
  • Generated hook contains AI directory staging snippet
  • Configures git core.hooksPath to .githooks
  • Idempotent — running setup twice produces identical result

Committed files verification:

  • .gitignore does not block .claude, .gemini, .codex
  • Hook file has correct shebang, strict mode, and staging logic

Test plan

  • All 10 new tests pass locally (vitest)
  • Full test suite passes (166 tests across app + lib)
  • Lint passes with zero errors (ESLint, Biome, TypeScript)
  • No code duplicates detected
  • CI checks passing

🤖 Generated with Claude Code

konard and others added 2 commits March 22, 2026 12:46
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: ProverCoderAI#170
- Remove .claude from .gitignore so it can be tracked alongside .gemini and .codex
- Add auto-staging logic to pre-commit hook for AI agent config directories
- Update setup-pre-commit-hook.js to include AI dir staging in generated hook
- Auto-configure core.hooksPath in setup script instead of requiring manual step

Previously the pre-commit hook only staged .knowledge directories. The .claude
directory was also listed in .gitignore, making it impossible to track. The setup
script required a manual `git config core.hooksPath .githooks` step that was
easy to forget, causing all hooks (including pre-push session backup) to never
activate.

Fixes ProverCoderAI#170

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] Почему-то не настраивается prehook на push который автоматически собирает .gemini, .claude, .codex папки и бекапит их fix(hooks): auto-stage .gemini, .claude, .codex directories on commit Mar 22, 2026
@konard konard marked this pull request as ready for review March 22, 2026 12:53
@konard
Copy link
Contributor Author

konard commented Mar 22, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.237149
  • Calculated by Anthropic: $2.325822 USD
  • Difference: $-1.911327 (-45.11%)

🤖 Models used:

  • Tool: Claude
  • Requested: opus
  • Model: Claude Opus 4.6 (claude-opus-4-6)

📎 Log file uploaded as Gist (953KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@skulidropek
Copy link
Contributor

Напиши тесты
Надо иметь гарантии того что логика работает

@konard
Copy link
Contributor Author

konard commented Mar 22, 2026

🔄 Auto-restart triggered (iteration 1)

Reason: New comment(s) from non-bot user(s): skulidropek

Starting new session to address the issues.


Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable.

- Tests pre-commit hook logic: stages .gemini, .claude, .codex when present
- Tests setup-pre-commit-hook.js: creates hook, sets permissions, configures core.hooksPath
- Tests idempotency of setup script
- Verifies .gitignore does not block AI config directories
- Verifies committed hook file has correct shebang and staging snippet

All tests use isolated temp git repos for clean, repeatable execution.

Addresses review feedback requesting test coverage for hook logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard
Copy link
Contributor Author

konard commented Mar 22, 2026

@skulidropek Added tests as requested! 🧪

packages/app/tests/hooks/pre-commit-ai-dirs.test.ts — 10 tests covering:

  1. AI directory auto-staging logic (4 tests in isolated temp git repos):

    • Stages all three directories when they exist
    • Skips non-existent directories without error
    • Stages nested files recursively
    • Handles empty directories gracefully
  2. setup-pre-commit-hook.js (4 tests):

    • Creates hook file with executable permissions
    • Generated hook contains the AI staging snippet
    • Configures core.hooksPath automatically
    • Idempotent — running twice gives identical result
  3. Committed files verification (2 tests):

    • .gitignore doesn't block .claude, .gemini, .codex
    • Hook file has correct shebang, strict mode, and staging logic

All 166 tests pass (app + lib), zero lint errors, zero duplicates.

The hooks test file tests shell scripts (bash/node) that inherently
require direct node:child_process, node:fs, node:path imports.
These are incompatible with the Effect-TS compliance rule that
requires @effect/platform wrappers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard
Copy link
Contributor Author

konard commented Mar 22, 2026

🔄 Auto-restart-until-mergeable Log (iteration 1)

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $6.714196
  • Calculated by Anthropic: $4.182234 USD
  • Difference: $-2.531963 (-37.71%)

🤖 Models used:

  • Tool: Claude
  • Requested: opus
  • Model: Claude Opus 4.6 (claude-opus-4-6)

📎 Log file uploaded as Gist (2635KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Mar 22, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@skulidropek skulidropek merged commit e3dd79a into ProverCoderAI:main Mar 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants