Skip to content

feat: harvest husky pre-push template and claude permissions from active repos - #790

Merged
keito4 merged 3 commits into
mainfrom
feat/husky-pre-push-template
Jun 4, 2026
Merged

feat: harvest husky pre-push template and claude permissions from active repos#790
keito4 merged 3 commits into
mainfrom
feat/husky-pre-push-template

Conversation

@keito4

@keito4 keito4 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Why

/setup-husky のドキュメントが pre-push に言及していたのにテンプレ実体が無く、また直近で keito4 が触っているリポ (ohana, effectuation, raycast-extensions) で個別に許可されている Claude コマンドが共通化されていなかった。これらを収穫して config に取り込む。

さらに OYKOT-jp / Elu-co-jp / keito4-org / keito4 配下の active リポ全体を走査し、既存の広い allow glob でカバーされない開発ツールチェーンを追加収穫した。

What

1. Husky pre-push テンプレ (templates/husky/pre-push)

  • package.json の scripts を自動検出して順次実行:
    • typecheck / type-check
    • build
    • test:ci / test:all
    • npm audit --audit-level=high --omit=dev(非ブロッキング、AUDIT_BLOCK=1 で強制)
  • SKIP_TYPECHECK / SKIP_BUILD / SKIP_TEST / SKIP_AUDIT 環境変数で個別スキップ可能
  • package.json 不在のリポでも安全に no-op
  • templates/README.md に Husky フックセクション追加

2. Claude 権限の収穫 (.claude/settings.json)

2a. ohana / raycast-extensions からの初回収穫

既存の広い権限 (npm:* / npx:* / gh:* / python3:* 等) でカバーされない真に新規な許可コマンドのみを追加:

  • Bash(nodemon:*) — dev-only watcher
  • Bash(supabase projects api-keys:*) — read-only
  • Bash(supabase projects get-config:*) — read-only
  • WebFetch(domain:skills.sh) — raycast-extensions で参照

2b. 全 active リポ走査による開発ツールチェーン収穫

OYKOT-jp / Elu-co-jp / keito4-org / keito4 配下の .claude/settings.local.json を全走査し、既存 glob でカバーされず複数リポで繰り返し使われている dev/build/test ツールのみを追加:

  • 代替ランタイム: bun / bunx / uv
  • モバイル/ネイティブビルド: flutter / dart / ./gradlew / adb / xcodebuild / xcrun / xcodegen / swiftlint / maestro / patrol(calendar_alerm, intent-gate-android 等)
  • Ruby/iOS CI: ruby / gem / bundle / fastlane / pod
  • 秘密管理 (dev): doppler run(secrets の直接出力や書き込み系は ask 維持)
  • ユーティリティ: yqjq 相当)/ git worktree(agent worktree 運用)

How

  • pre-push の役割分担: pre-commit が軽量 (format/lint/staged) を担うのに対し、pre-push は重い検証 (typecheck / build / full test / audit) を担当。pre_git_quality_gates.py と同様の auto-detect パターンで repo 横断の再利用性を確保。
  • 権限ポリシー: harvest 対象は「広い allow でカバーされず」「build/test/dev 用途で副作用が小さい」項目のみ。chmod / git merge / git rebase / terragrunt apply / 1Password op / 各種 destructive コマンドは他リポで allow されていても安全側で ask / 不採用を維持。dopplerrun(secret 注入してコマンド実行)のみに限定し、生 secret 出力は対象外。

Risk

低。

  • pre-push: 新規テンプレ追加のみ。repo-maintenance の自動適用ロジック変更は今回スコープ外。
  • 権限: narrow allow の追加のみ(2a: 4件 + 2b: 21件)。既存の deny / ask ポリシーは無変更。すべて build/test/dev ツールで、ファイル削除・本番デプロイ・秘密書き込み等の破壊的操作は含まない。

🤖 Generated with Claude Code

setup-husky コマンドのドキュメントが pre-push に言及していたが
テンプレ実体が無かったギャップを解消。package.json scripts を
自動検出して typecheck / build / test:ci / npm audit を実行する
汎用フックを templates/husky/pre-push として追加。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces a Husky pre-push hook template (templates/husky/pre-push) that runs repository checks before push when corresponding npm scripts exist. The hook conditionally executes typecheck, build, test, and audit checks, with opt-out flags and configurable audit blocking, plus documentation updates in templates/README.md.

Changes

Husky pre-push hook

Layer / File(s) Summary
Helper function for conditional script execution
templates/husky/pre-push
run_if_script helper checks npm script existence in package.json, honors SKIP_* flags to bypass execution, and runs scripts when available.
Pre-push checks and audit logic
templates/husky/pre-push
Main hook exits cleanly if package.json is missing, runs typecheck/build/test/audit scripts conditionally based on existence and skip flags, supports AUDIT_BLOCK to fail the push on audit failures, and logs a completion message.
Template documentation
templates/README.md
Documents the pre-push hook template in the Husky hooks section, describing its purpose and script auto-detection behavior.

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • keito4/config#670: Earlier introduction of the same templates/husky/pre-push hook template with closely overlapping changes.

Suggested labels

released

Poem

🐰 A pre-push hook hops into place,
Checking types and builds with grace,
Tests and audits dance along,
Keeping your repo safe and strong!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title mentions 'husky pre-push template' which aligns with the main changeset (templates/husky/pre-push), but misleadingly suggests adding Claude permissions when that is a secondary concern in the PR description.
Description check ✅ Passed The pull request description follows the template structure with all required sections completed: Summary, Why, What, How to test, and Checklist are present with substantial detail.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/husky-pre-push-template

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Claude finished @keito4's task in 1m 31s —— View job


コードレビュー

  • コンテキスト収集
  • templates/husky/pre-push レビュー
  • templates/README.md レビュー
  • フィードバックまとめ・投稿

総評

ドキュメントと実装の整合を取る、明確な目的を持ったテンプレート追加で全体的に質は高い。既存の pre_git_quality_gates.py と同パターンの auto-detect アプローチも一貫性があり良い。以下は主に minor / recommendation レベルの指摘で、ブロッキング問題はなし。


templates/husky/pre-push

[minor] eval を使った変数参照が不必要に複雑 (line 16)

if [ -n "$(eval echo \$"$flag_var")" ]; then

eval echo パターンは可読性が低く、POSIX sh でも以下のより明確な書き方が使えます:

eval "_val=\${$flag_var:-}"
if [ -n "$_val" ]; then

もしくは引数を環境変数の値ではなく直接渡す設計に変えるとさらにシンプルになります。現状の呼び出し側が全て静的文字列なのでリスクは実質ゼロですが、将来の誤用を防ぐ意味でも整理の余地があります。Fix this →


[minor] node -e へのスクリプト名インライン展開 (line 21)

node -e "process.exit(require('./package.json').scripts?.['$script_name'] ? 0 : 1)"

$script_name が JS コードに直接展開されています。現状は静的な呼び出しのみなので実害はありませんが、process.argv 経由で渡す方がより堅牢です:

node -e "const s=process.argv[1];const p=require('./package.json');process.exit(p.scripts&&p.scripts[s]?0:1)" -- "$script_name"

Fix this →


[recommendation] パッケージマネージャーが npm 固定

npm runnpm audit がハードコードされています。pre_git_quality_gates.py はロックファイルからパッケージマネージャーを自動判定しているのに対し、このスクリプトは pnpm/yarn/bun プロジェクトでも npm を使います。

npm run <script> 自体は他のマネージャーがいても動きますが、npm auditpnpm audit の代替にはなりません。今回スコープ外で問題ありませんが、将来の改善候補として:

# ロックファイルから検出する例
PKG_MANAGER="npm"
[ -f pnpm-lock.yaml ] && PKG_MANAGER="pnpm"
[ -f yarn.lock ] && PKG_MANAGER="yarn"

[recommendation] typechecktype-check が両方存在する場合

両スクリプトが package.json に定義されていると、同じ型チェックが2回実行されます。通常は片方しか定義しないので実害は少ないですが、typecheck が成功した場合は type-check をスキップするガードがあると堅牢です。


[recommendation] build のデフォルト実行

大規模プロジェクトでは build は数分かかることもあり、push のたびに実行するのは開発体験を損なう可能性があります。SKIP_BUILD=1 の存在はヘッダコメントに明記されていますが、build だけ opt-in(デフォルト skip)にする選択肢も検討の余地があります。


templates/README.md

新セクション「Husky フック(husky/)」の配置・記述ともに問題なし。既存の表スタイルと一貫しています。


判定

Approve — minor/recommendation のみ。新規テンプレートとして十分な品質で、ドキュメントとの整合も取れています。

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

Copy link
Copy Markdown

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: 7cc4cd23c4

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread templates/husky/pre-push
Comment on lines +27 to +29
if [ ! -f package.json ]; then
echo "[pre-push] No package.json at repo root; skipping npm-based checks."
exit 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor setup-husky projects with scripts under next/

In repositories that follow the existing setup-husky guidance, the npm scripts live in next/package.json and the documented hook runs them via npm --prefix next; with this template, those same repos hit this root-only check and exit 0, so the pre-push typecheck/test gate is silently disabled. I checked .claude/commands/setup-husky.md, which explicitly says to use npm --prefix next and lists the required scripts in next/package.json, so the template needs to support that documented layout or it won't replace the inline hook safely.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
templates/husky/pre-push (1)

33-41: ⚡ Quick win

Treat alias script names as fallbacks, not cumulative steps.

If a repo defines both typecheck and type-check or both test:ci and test:all, this hook runs the same expensive gate twice. A single “first match wins” helper would keep pre-push latency predictable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@templates/husky/pre-push` around lines 33 - 41, The hook currently calls
run_if_script separately for aliases (e.g., run_if_script typecheck and
run_if_script type-check, run_if_script test:ci and run_if_script test:all),
causing duplicate/expensive gates; change the logic so run_if_script implements
a first-match-wins fallback: track which gate key (e.g., SKIP_TYPECHECK,
SKIP_TEST) has been executed and if already handled skip subsequent alias calls
so aliases act as fallbacks rather than cumulative steps; update the helper used
by run_if_script (and any callers referencing typecheck/type-check or
test:ci/test:all) to consult and set a done flag per gate key before running the
expensive action.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@templates/husky/pre-push`:
- Around line 21-23: The pre-push husky template currently hardcodes npm for
running scripts and audits (see the npm run "$script_name" and npm audit
invocations); update the hook to detect the repository package manager using the
same lockfile-based detection logic used by the existing quality-gate flow and
invoke scripts and audits via the detected tool (e.g., run script via the
detected package manager command rather than npm), and implement alias
deduplication so if equivalent scripts exist (e.g., "typecheck" vs "type-check",
"test:ci" vs "test:all") the hook resolves to a single canonical script name
before running to avoid duplicate work—reuse the quality-gate's lockfile
detection helper and script-resolution strategy to locate the package manager
and canonical script name.

In `@templates/README.md`:
- Around line 29-31: Update the README table entry for the `husky/pre-push`
template to narrow the scope from “全プロジェクト” to indicate it only applies to
package.json-based (Node / npm-script) repositories; mention that the hook exits
when the repo root has no package.json and therefore only runs for Node/npm
projects so readers won't expect it to run in non-Node repos.

---

Nitpick comments:
In `@templates/husky/pre-push`:
- Around line 33-41: The hook currently calls run_if_script separately for
aliases (e.g., run_if_script typecheck and run_if_script type-check,
run_if_script test:ci and run_if_script test:all), causing duplicate/expensive
gates; change the logic so run_if_script implements a first-match-wins fallback:
track which gate key (e.g., SKIP_TYPECHECK, SKIP_TEST) has been executed and if
already handled skip subsequent alias calls so aliases act as fallbacks rather
than cumulative steps; update the helper used by run_if_script (and any callers
referencing typecheck/type-check or test:ci/test:all) to consult and set a done
flag per gate key before running the expensive action.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f272a1a5-3cc6-40fa-9c9f-f82f621c2709

📥 Commits

Reviewing files that changed from the base of the PR and between a671a88 and 7cc4cd2.

📒 Files selected for processing (2)
  • templates/README.md
  • templates/husky/pre-push

Comment thread templates/husky/pre-push
Comment on lines +21 to +23
if node -e "process.exit(require('./package.json').scripts?.['$script_name'] ? 0 : 1)" 2>/dev/null; then
echo "[pre-push] Running $script_name..."
npm run "$script_name"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the mismatch between the new hook and the existing multi-package-manager contract.
sed -n '1,120p' templates/husky/pre-push
printf '\n---\n'
sed -n '44,74p' .claude/hooks/README.md
printf '\n---\n'
rg -n 'npm run|npm audit|pnpm|yarn|bun|ロックファイル|lockfile' templates/husky/pre-push .claude/hooks/README.md

Repository: keito4/config

Length of output: 3133


Remove hardcoded npm from the “generic” templates/husky/pre-push hook (lines ~21-23, ~45-46)

This template hardcodes npm run "$script_name" and npm audit ..., but the existing quality-gate flow is designed to support npm / pnpm / yarn / bun via lockfile auto-detection—so pnpm/yarn/bun repos won’t match the expected toolchain/lockfile behavior.

  • Switch to package-manager-aware execution for both script running and audit (reuse the same lockfile-based detection logic from the existing quality-gate flow).
  • Optionally deduplicate heavy alias checks (typecheck vs type-check, test:ci vs test:all) when both exist to avoid running the same work twice.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@templates/husky/pre-push` around lines 21 - 23, The pre-push husky template
currently hardcodes npm for running scripts and audits (see the npm run
"$script_name" and npm audit invocations); update the hook to detect the
repository package manager using the same lockfile-based detection logic used by
the existing quality-gate flow and invoke scripts and audits via the detected
tool (e.g., run script via the detected package manager command rather than
npm), and implement alias deduplication so if equivalent scripts exist (e.g.,
"typecheck" vs "type-check", "test:ci" vs "test:all") the hook resolves to a
single canonical script name before running to avoid duplicate work—reuse the
quality-gate's lockfile detection helper and script-resolution strategy to
locate the package manager and canonical script name.

Comment thread templates/README.md
Comment on lines +29 to +31
| テンプレート | いつ使う |
| ---------------- | ---------------------------------------------------------------------------------------- |
| `husky/pre-push` | **全プロジェクト**: typecheck / build / test:ci / npm audit を push 前に実行(自動検出) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Narrow the scope from “all projects” to package.json-based repos.

templates/husky/pre-push exits immediately when the repo root has no package.json (Lines 27-29 there), so **全プロジェクト** is broader than the actual behavior. Calling out Node/npm-script projects here would set the right expectation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@templates/README.md` around lines 29 - 31, Update the README table entry for
the `husky/pre-push` template to narrow the scope from “全プロジェクト” to indicate it
only applies to package.json-based (Node / npm-script) repositories; mention
that the hook exits when the repo root has no package.json and therefore only
runs for Node/npm projects so readers won't expect it to run in non-Node repos.

@keito4 keito4 self-assigned this Jun 4, 2026
ohana / raycast-extensions の .claude/settings*.json を調査し、
既存の広い権限 (npm:* / npx:* / gh:* / python3:* 等) でカバーされない
真に新規な許可コマンドのみを抽出して追加。

- Bash(nodemon:*): dev-only watcher
- Bash(supabase projects api-keys:*): read-only
- Bash(supabase projects get-config:*): read-only
- WebFetch(domain:skills.sh): raycast-extensions で参照

chmod / git merge / git rebase 等は意図的に ask ブロック維持 (安全側)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@keito4 keito4 changed the title feat(templates): add generic husky pre-push template feat: harvest husky pre-push template and claude permissions from active repos Jun 4, 2026
直近 OYKOT-jp / Elu-co-jp / keito4-org / keito4 配下の active リポの
.claude/settings.local.json を全走査し、既存の広い allow glob で
カバーされず複数リポで繰り返し使われている開発ツールチェーンのみを追加。

- 代替ランタイム: bun / bunx / uv
- モバイル/ネイティブビルド: flutter / dart / ./gradlew / adb /
  xcodebuild / xcrun / xcodegen / swiftlint / maestro / patrol
- Ruby/iOS CI: ruby / gem / bundle / fastlane / pod
- 秘密管理(dev): doppler run(書き込み系は ask 維持)
- ユーティリティ: yq(jq 相当)/ git worktree(agent worktree 運用)

いずれも build/test/dev 用途で副作用が小さいものに限定。chmod / git
merge / rebase 等の他リポで allow されていた項目は安全側で ask 維持。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@keito4
keito4 merged commit 1761c5f into main Jun 4, 2026
12 checks passed
@keito4
keito4 deleted the feat/husky-pre-push-template branch June 4, 2026 04:53
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.114.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released リリース済み label Jun 4, 2026
@claude claude Bot mentioned this pull request Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant