Skip to content

feat(hooks-pre-tool-validate): jj-message-required preset で jj new / jj split の -m 必須化 (順位 144)#172

Merged
aloekun merged 5 commits into
masterfrom
feat-jj-message-required-hook
May 25, 2026
Merged

feat(hooks-pre-tool-validate): jj-message-required preset で jj new / jj split の -m 必須化 (順位 144)#172
aloekun merged 5 commits into
masterfrom
feat-jj-message-required-hook

Conversation

@aloekun
Copy link
Copy Markdown
Owner

@aloekun aloekun commented May 25, 2026

Summary

順位 144 (PR #171 T3-#8 採用) 単独実装。PreToolUse hook で jj new / jj split-m / --message 引数なし呼び出しを mechanical に block し、混合 commit 事故 + jj split editor hang を構造的に防止する。

Background

PR #171 セッションで jj new 忘れにより 順位 57 commit と 順位 91 commit の変更が混入する事故が発生 (後で jj split -m で recovery 済)。post-merge-feedback の analyzer 原案は ~/.claude/rules/common/git-workflow.md への docs 化だったが、feedback_no_unenforced_rules.md 適用でユーザー判断 hook による mechanical enforcement に方針変更 (2026-05-24 セッション、feedback_pipeline_over_rules.md 適用)。

Design

  • BlockedPattern 構造体拡張: exception: Option<Regex> field 追加 (Rust 標準 regex crate が negative lookahead 非対応のため 2 段判定で実装)
  • validate_command ロジック拡張: pattern match 後、exception regex が hit すれば continue で allow
  • 新 preset jj-message-required:
    • block pattern: (?im)(^|&&|;|\|\||\||&|\n)\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S+\s+|command\s+|env\s+)*jj\s+(new|split)\b
    • exception regex: \s(-m|--message)\b
  • opt-in preset: default fallback には含めず、hooks-config.toml で明示有効化 (派生プロジェクト breaking change リスク軽減)

設計判断 (ユーザー承認済 2026-05-24)

  • A: jj new 引数なしも block (= -m を強制)
  • B: jj new <revision> (例: jj new master) で -m なしも block
  • C: jj split interactive (= -m なし) は editor hang issue があるため strong block
  • D: scope は jj 直接呼び出しのみ (pnpm jj-new 等のラッパーは scope 外)

Commits

  1. tk docs(todo): 順位 143 + 144 新規追加 (Bundle 171 entry 登録)
  2. yv refactor: BlockedPattern に exception field 追加 (Phase 1)
  3. ut feat: jj-message-required preset 追加 (Phase 2)
  4. ko test: block/allow/non-regression test 拡充 (Phase 3)
  5. uq chore: build + deploy exe + 順位 144 entry 削除 (Phase 4)

Test plan

  • cargo test -p hooks-pre-tool-validate: 158 pass (14 新規 test、既存 144 件 regression なし)
  • dogfood: .claude/hooks-pre-tool-validate.exe 直接 stdin 投入で確認
    • jj new → exit 2 + 修正手順 feedback ✅
    • jj new -m "WIP" → exit 0 (allow) ✅
  • AI review (takt pre-push-review): simplicity APPROVE + security APPROVE (1 iteration)

関連

Out of scope

  • 派生プロジェクト (techbook-ledger / auto-review-fix-vc) への deploy は本リポジトリ先行 dogfood 後判断 (memory feedback_dogfood_evals_two_phase.md 適用)
  • pnpm jj-new 等の wrapper 経由は scope D により対象外 (設計判断確定)

Summary by CodeRabbit

リリースノート

  • 新機能

    • jj new / jj split コマンドでメッセージ指定を必須化するプリセット「jj-message-required」を追加しました
    • ブロックパターンに例外ルールを設定できる機能を実装しました
  • テスト

    • 新プリセット・例外ルール機能に関する複数のテストケースを追加しました
  • ドキュメント

    • タスク追跡ドキュメントを更新しました

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ce0c32a-75b4-4dea-a04d-1ac9b219bad0

📥 Commits

Reviewing files that changed from the base of the PR and between 51328e8 and 122b378.

📒 Files selected for processing (4)
  • .claude/hooks-config.toml
  • docs/todo-summary.md
  • docs/todo8.md
  • src/hooks-pre-tool-validate/src/main.rs

📝 Walkthrough

Walkthrough

BlockedPattern 型に exception フィールドを追加し、パターンマッチ後の条件付き許可ロジックを実装。新プリセット jj-message-required を導入して -m/--message オプション未指定時のコマンドをブロック。プリセット解決ロジックを関数分割で整理し、コンフィグ有効化とドキュメント更新を実施。

Changes

jj-message-required プリセット実装とドキュメント更新

Layer / File(s) Summary
BlockedPattern 型定義と既存プリセット初期化
src/hooks-pre-tool-validate/src/main.rs
BlockedPatternexception: Option<Regex> フィールドを追加。全既存プリセット(default、git、jj系、electron、jj-push、gh系、polling)の初期化に exception: None を明示的に付与し、従来のブロック動作を維持しながら新例外判定機構に対応。
プリセット解決ロジックのリファクタリング
src/hooks-pre-tool-validate/src/main.rs
プリセット構築を default_preset_namesresolve_preset_or_customcustom_regex_pattern へ関数分割。flat_map ベースで整理し、validate_command に exception マッチ時の許可分岐を追加。カスタム正規表現無効時は警告出力。
jj-message-required プリセットのテスト
src/hooks-pre-tool-validate/src/main.rs
空の jj new、revision指定、jj split、複合コマンド(&&、改行)、-m/--message 指定時の許可、jj-main-guard 併用時の挙動、対象外サブコマンドと pnpm ラッパー除外を検証。デフォルトフォールバック非含有(opt-in)を確認。
コンフィグ有効化とドキュメント更新
.claude/hooks-config.toml, docs/todo-summary.md, docs/todo8.md
.claude/hooks-config.tomljj-message-requiredblocked_patterns 配列に追加。コメントで -m/--message 未指定ブロックの意図を説明。docs/todo-summary.md と docs/todo8.md に複言語 fixture helper 標準化タスク(PR #171 T2-#4)を追加し、UTF-8マルチバイト向け helper API、配置方針、リファクタ計画、完了基準を記載。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • aloekun/claude-code-hook-test#27: src/hooks-pre-tool-validate/src/main.rsBlockedPattern プリセット追加と build_blocked_patterns/ブロック判定フロー拡張で、同じプリセット実装仕組みを共有。

  • aloekun/claude-code-hook-test#166: src/hooks-pre-tool-validate/src/main.rspre_tool_validate ブロック用プリセット追加・解決ロジック拡張で、同じプリセット登録フロー経路を使用。

  • aloekun/claude-code-hook-test#13: src/hooks-pre-tool-validate/src/main.rsBlockedPattern プリセット選択・テスト更新で、同じ「コマンドブロック用プリセット拡張」コード経路が関連。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは、変更の主要な内容である「jj-message-required preset による jj new / jj split の -m 必須化」を正確に反映しており、簡潔で明確です。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@aloekun aloekun merged commit a6670c7 into master May 25, 2026
1 check passed
@aloekun aloekun deleted the feat-jj-message-required-hook branch May 25, 2026 05:12
aloekun added a commit that referenced this pull request May 25, 2026
* docs(adr): ADR-042 ルール vs 仕組み化の境界基準 — 試験運用 ADR 新設 + CLAUDE.md ADR list 追加

* docs(todo): 仕組み化方針切替 — todo9.md 新設 + 順位 142/143/144/145 + 146-151 追加 + 順位 44/61 hook 化転換 + 122→136 統合 (Bundle 既存ルール仕組み化)

PR #172 (順位 144 = jj-message-required hook) の dogfood 成功を受けた仕組み化方針切替に関する一連の todo system 更新:

- 順位 142 entry 追加 (PR #170 T3-#1 採用 ADR-041 補強 State Preservation Invariant pattern)
- 順位 143/144 entry 追加 (PR #171 post-merge-feedback Bundle 171 = 複言語 fixture helper + jj-message-required hook)
- 順位 145 entry 追加 (PR #172 T2-#1 採用 preset matrix test)
- 順位 146-151 entry 新規追加 (既存ルール仕組み化バンドル: secret detection / file length lint / test coverage CI gate / subprocess pipe truncate hook 拡張 / magic number lint / PR diff lines check)
- 順位 44 (gh CLI 使用規則) を docs 追記から PreToolUse hook 化方針に転換
- 順位 61 (CR review.body 手動 scan) を docs 追記から check-ci-coderabbit CLI 拡張方針に転換
- 順位 122 (新 todo 着手前の既実装確認) を 順位 136 (working copy staleness hook) に統合
- todo9.md 新設 (todo8.md 50KB 接近のため、新規追加先を todo9.md に移行)
- todo-summary.md 更新方針 + table 更新 + Bundle 171 タグ整備

memory rule `feedback_pipeline_over_rules.md` 適用 = rule docs → mechanism shift の体系的記録。

* chore(todo): land 済 entry 削除 + bundle-history 分離 (size 50KB 超過解消)
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