feat(hooks): file_size_check Layer 0.5 を hooks-post-tool-linter に統合 (順位 177)#198
Merged
Conversation
…順位 177) PostToolUse Edit / Write 直後にファイルサイズ閾値超過を検出して分割を促す mechanical layer を実装。ファイル分割を user 判断ベース → mechanical layer に移管し、認知負荷削減 + 早期検出 を実現する。 ## 背景 4 PR の同型観測 (Very High frequency) で systemic risk 閾値到達: - PR #133: todo.md → todo2.md split - PR #172: todo8.md → todo9.md split - PR #186: todo9.md → todo10.md split - PR #197: todo9.md → todo11.md split (本日 land) 順位 177 として todo10.md に登録済み、PR #197 で Tier 1 (優先実装) に格上げ。 ユーザー指示 (2026-06-07) で次の PR で消化と決定。 ## 設計 配置: option B = 既存 hooks-post-tool-linter (generic linter) に Layer 0.5 として統合。 option A (新 binary) に対する優位性: - 新 binary 追加なし → deploy 簡素 (Effort S 寄り) - PostToolUse hook 数の最小化 (1 PR push で発火する hook 数を抑制) - ADR-039 bounded lifetime dogfood サイクルを最短で開始可能 ## 実装 ### Layer 0.5 配置 main() を 4 layer helper に refactor (関数長 50 行制限内に収まる構造): - Layer 0: UTF-8 整合性 (既存) - Layer 0.5: file_size_check (新規、metadata-only) ★ - Layer 1: 正規表現 custom-rules (既存) - Layer 2: 外部ツール pipeline (既存) ### Config schema [post_tool_use.file_size_check] section (ADR-039 opt-in pattern 準拠): - enabled = false (default OFF) - threshold_bytes = 51200 (50KB、Claude Code 読み取り安定性閾値) - paths = ["docs/**/*.md", "src/**/*.rs"] (default 対象 glob) - touch_trigger = true (ratchet、既存超過は触られるまで grandfather) Kill-switch: enabled = false で完全停止。 ### Pure function design check_file_size_threshold(file, size_bytes, config) は I/O フリーの純粋関数として実装、 file system access は呼び出し側 (run_file_size_layer) に分離。tests が deterministic に 書け、memory feedback_test_dry_antipattern に従い各 variant 独立 setup が trivial。 ### touch_trigger ratchet の MVP 制限 touch_trigger = false (strict mode = 全 enabled paths を毎回スキャン) は ADR-039 bounded lifetime dogfood 後の判定に倒し、MVP では config field 受理のみ (true/false 同挙動)。 3-5 PR の dogfood 観測後に default-ON 昇格 or strict mode 実装 or 却下を判定。 ## ADR-007 amendment (Layer 0.5 追記) ADR-007 § Layer 0.5 追記 section を新設し、file_size_check が Q1/Q2/Q3 判断フロー対象外 であることを codify。同型 (metadata-only、content 非依存) の future check は同 Layer 0.5 に追加することで regex / AST 層との責務境界を維持する原則を明文化。 ## Tests 8 variant 独立 setup (memory feedback_test_dry_antipattern 適用): 1. enabled=false で短絡 (kill-switch 動作確認) 2. paths glob 不一致で skip 3. size 閾値内で skip 4. size 超過で feedback emit 5. docs/todo* に対する recovery hint 文脈別出し分け 6. paths が空配列の場合 skip 7. touch_trigger=false が MVP では true と同挙動 8. Windows backslash path の forward-slash 正規化 全 8 test pass、既存 141 test との non-regression 確認済 (cargo test 149/149 passed)。 cargo clippy --workspace -- -D warnings clean。 ## Dogfood threshold=30720 で hooks-config.toml を temporarily enable、docs/todo10.md (38155 bytes) に hook 発火を実観測: [file-size-check] docs/todo10.md: ファイルサイズ 38155 bytes が threshold 30720 bytes (= 30.0 KB) を超過しています。ファイル分割を推奨します (docs/todo*.md の場合は新 todo<N+1>.md を新設して entry を移管). 小ファイル (docs/todo5.md 11909 bytes) は no-op を確認。dogfood 後 enabled=false / threshold=51200 に revert 済 (production default = opt-in). ## 関連 docs 更新 - docs/todo10.md: 順位 177 entry 削除 (実装完了) - docs/todo-summary.md: 順位 177 table 行 + 「直近優先 2026-06-07」call-out 段落 削除 - docs/adr/adr-007-custom-linter-layer-boundary.md: § Layer 0.5 追記 新設 ## 参照 - memory feedback_pipeline_over_rules: rule → hook 切替の体系適用 - ADR-039: experimental feature 標準パターン (opt-in + kill-switch + bounded lifetime) - ADR-007: custom-linter layer boundary (本 PR で Layer 0.5 追記) - 順位 102 (PR #148 land): paths glob filter helper を再利用
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
💤 Files with no reviewable changes (2)
📝 WalkthroughWalkthroughPostToolUse フックの編集後にファイルサイズ閾値を検査する「Layer 0.5」機能を導入。設定、実装ロジック、メイン実行フロー統合、テスト、ドキュメント更新を完了。メタデータベースの判定で拡張子非依存の早期フィードバック提供。 ChangesPostToolUse ファイルサイズチェック機能導入
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
順位 177 (PostToolUse hook ファイルサイズ検出) を Tier 1 (優先実装) → land 完了。
hooks-post-tool-linterに Layer 0.5 として統合 (option B 採用)。ファイル分割を user 判断ベースから mechanical layer に移管することで、認知負荷削減 + 早期検出を実現。4 PR observation = Very High frequency
CLAUDE.md code-review.md § 同型 finding の閾値判定 (3 観測 = Tier 1 昇格) を超え、systemic risk 閾値到達 → 本 PR で根本対策。
設計選択: option B (既存 linter 統合)
実装
Layer 0.5 配置
main()を 4 layer orchestrator に refactor (関数長 50 行制限内に収まる構造):Config schema (
[post_tool_use.file_size_check])ADR-039 opt-in pattern 準拠:
Pure function design
check_file_size_threshold(file, size_bytes, config)は I/O フリーの純粋関数。fs access は呼び出し側 (run_file_size_layer) に分離 → tests が deterministic に書け、各 variant 独立 setup が trivial (memoryfeedback_test_dry_antipattern適用)。touch_trigger ratchet の MVP 制限
touch_trigger = true(default): 触られたファイルのみチェック = ratchet 動作touch_trigger = false(strict、全 enabled paths スキャン): MVP では field 受理のみ、true と同挙動。ADR-039 bounded lifetime dogfood (3-5 PR) 後の判定に倒したTests (8 variant 独立 setup)
file_size_check_skips_when_disabledfile_size_check_skips_when_path_does_not_match_globfile_size_check_skips_when_size_within_thresholdfile_size_check_emits_message_when_size_exceeds_thresholdfile_size_check_emits_todo_recovery_hint_for_docs_todo_filesfile_size_check_returns_none_when_paths_glob_is_emptyfile_size_check_treats_touch_trigger_false_same_as_true_in_mvpfile_size_check_normalizes_windows_backslash_path--workspace -- -D warningscleanDogfood 観測 (PR push 前に確認済、enabled=false に revert)
threshold=30720 で temporarily enable し実観測:
docs/todo10.md(38155 bytes) → hook 発火、recovery hint 正常 (docs/todo*.md の場合は新 todo<N+1>.md を新設して entry を移管)docs/todo5.md(11909 bytes) → no-op (期待通り skip)Production default = opt-in (enabled=false) に revert 済。各リポジトリで明示有効化が必要。
ADR-007 amendment (Layer 0.5 追記)
docs/adr/adr-007-custom-linter-layer-boundary.mdに新 section「Layer 0.5 追記: file_size_check (2026-06-07、順位 177 由来)」を追加。file_size_checkが Q1/Q2/Q3 判断フロー対象外 (= metadata-only check で content 非依存) であることを codify、同型 future check は同 Layer 0.5 に追加することで責務分離を維持する原則を明文化。関連 docs 更新
docs/todo10.md: 順位 177 entry 削除 (実装完了)docs/todo-summary.md: 順位 177 table 行 + 「直近優先 2026-06-07」call-out 段落 削除docs/adr/adr-007-custom-linter-layer-boundary.md: § Layer 0.5 追記 新設Bounded lifetime data point
ADR-039 § 3 Bounded lifetime: enabled=false default OFF で land、本リポジトリで 3-5 PR の dogfood (明示 enable して観測) 後に default-ON 昇格 or 却下を判定。派生プロジェクト (techbook-ledger / auto-review-fix-vc) への deploy 判断は本リポジトリ dogfood 観測後。
Test plan
--workspace -- -D warningsclean参照
feedback_pipeline_over_rules: rule → hook 切替の体系適用feedback_test_dry_antipattern: 各 variant 独立 setupSummary by CodeRabbit
リリースノート
New Features
Documentation
Tests