Skip to content

feat(hooks): file_size_check Layer 0.5 を hooks-post-tool-linter に統合 (順位 177)#198

Merged
aloekun merged 1 commit into
masterfrom
feat/file-size-check-hook
Jun 6, 2026
Merged

feat(hooks): file_size_check Layer 0.5 を hooks-post-tool-linter に統合 (順位 177)#198
aloekun merged 1 commit into
masterfrom
feat/file-size-check-hook

Conversation

@aloekun

@aloekun aloekun commented Jun 6, 2026

Copy link
Copy Markdown
Owner

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

PR 観測
#133 todo.md → todo2.md split
#172 todo8.md → todo9.md split
#186 todo9.md → todo10.md split
#197 todo9.md → todo11.md split (本日 land)

CLAUDE.md code-review.md § 同型 finding の閾値判定 (3 観測 = Tier 1 昇格) を超え、systemic risk 閾値到達 → 本 PR で根本対策。

設計選択: option B (既存 linter 統合)

  • 新 binary 追加なし → deploy 簡素 (Effort S 寄り)
  • PostToolUse hook 数の最小化 → 1 PR push で発火する hook 数を抑制
  • ADR-039 bounded lifetime dogfood サイクルを最短で開始可能
  • 将来拡張 (バイナリサイズ等の別 metadata-only check) が必要になった時点で option A への切り出しは reversible

実装

Layer 0.5 配置

main() を 4 layer orchestrator に refactor (関数長 50 行制限内に収まる構造):

Layer 役割 状態
0 UTF-8 整合性 既存
0.5 file_size_check (metadata-only) 新規
1 正規表現 custom-rules 既存
2 外部ツール pipeline 既存

Config schema ([post_tool_use.file_size_check])

ADR-039 opt-in pattern 準拠:

[post_tool_use.file_size_check]
enabled = false                                  # ADR-039 § kill-switch
threshold_bytes = 51200                          # 50KB (= Claude Code 読み取り安定性閾値)
paths = ["docs/**/*.md", "src/**/*.rs"]          # default 対象 glob
touch_trigger = true                             # ratchet (既存超過は触られるまで grandfather)

Pure function design

check_file_size_threshold(file, size_bytes, config) は I/O フリーの純粋関数。fs access は呼び出し側 (run_file_size_layer) に分離 → tests が deterministic に書け、各 variant 独立 setup が trivial (memory feedback_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)

# test 検証
1 file_size_check_skips_when_disabled enabled=false で短絡 (kill-switch)
2 file_size_check_skips_when_path_does_not_match_glob paths 不一致で skip
3 file_size_check_skips_when_size_within_threshold size 閾値内で skip
4 file_size_check_emits_message_when_size_exceeds_threshold size 超過で feedback emit
5 file_size_check_emits_todo_recovery_hint_for_docs_todo_files docs/todo* に recovery hint
6 file_size_check_returns_none_when_paths_glob_is_empty paths 空配列で skip
7 file_size_check_treats_touch_trigger_false_same_as_true_in_mvp MVP 制限 contract
8 file_size_check_normalizes_windows_backslash_path Windows backslash 正規化
  • 全 8 test pass
  • 既存 141 test との non-regression 確認済 (cargo test 149/149 passed)
  • cargo clippy --workspace -- -D warnings clean

Dogfood 観測 (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

  • cargo test pass (149/149)
  • cargo clippy --workspace -- -D warnings clean
  • dogfood: 大ファイル → hook 発火、小ファイル → no-op
  • dogfood revert: enabled=false / threshold=51200 復元
  • takt pre-push-review pass (パイプライン完了 1018s)
  • post-merge-feedback で実装品質を再確認 (本 PR merge 後)

参照

Summary by CodeRabbit

リリースノート

  • New Features

    • ファイルサイズ監視機能を実装。指定されたファイルが容量制限(50KB)を超えた場合に検出・通知します(初期状態では無効)
  • Documentation

    • アーキテクチャ決定記録を更新し、新機能の設計方針を明記しました
  • Tests

    • ファイルサイズ検出機能に関する包括的なテスト群を追加しました

…順位 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 を再利用
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

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: 2e07ce37-8444-4565-b1dd-cb239038be35

📥 Commits

Reviewing files that changed from the base of the PR and between ac124f0 and 5cef5ee.

📒 Files selected for processing (5)
  • .claude/hooks-config.toml
  • docs/adr/adr-007-custom-linter-layer-boundary.md
  • docs/todo-summary.md
  • docs/todo10.md
  • src/hooks-post-tool-linter/src/main.rs
💤 Files with no reviewable changes (2)
  • docs/todo10.md
  • docs/todo-summary.md

📝 Walkthrough

Walkthrough

PostToolUse フックの編集後にファイルサイズ閾値を検査する「Layer 0.5」機能を導入。設定、実装ロジック、メイン実行フロー統合、テスト、ドキュメント更新を完了。メタデータベースの判定で拡張子非依存の早期フィードバック提供。

Changes

PostToolUse ファイルサイズチェック機能導入

Layer / File(s) Summary
設定スキーマと型定義
.claude/hooks-config.toml, src/hooks-post-tool-linter/src/main.rs
TOML に post_tool_use.file_size_check セクション追加。enabled=false, threshold_bytes=51200, paths=["docs/**/*.md", "src/**/*.rs"], touch_trigger=true を定義。Rust側に PostToolUseConfigFileSizeCheckConfig 型を新設。
ファイルサイズ検査ロジック
src/hooks-post-tool-linter/src/main.rs
check_file_size_threshold が無効時に短絡、グローブマッチ失敗または非マッチ時に None 返却、閾値超過時にリカバリーヒント付きフィードバック生成。Windows パス区切り正規化、docs/todo ファイル向け分割ヒント含む。
層別実行フロー統合
src/hooks-post-tool-linter/src/main.rs
mainread_hook_input_file で入力読み取り、UTF-8 整合性→ファイルサイズ→カスタムルール→外部パイプラインの順序で層実行。各段で早期リターン対応。
ユニットテスト追加
src/hooks-post-tool-linter/src/main.rs
無効時短絡、グローブ非マッチ、閾値内、メッセージ生成、docs/todo 回復ヒント、空 paths スキップ、touch_trigger 同等性、Windows パス正規化を検証。
ドキュメント更新
docs/adr/adr-007-custom-linter-layer-boundary.md, docs/todo-summary.md, docs/todo10.md
ADR-007 に Layer 0.5 の責務・位置づけ・将来拡張方針を追記。完了したファイルサイズ検査タスク(順位 177)を todo-summary と todo10 から削除。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • aloekun/claude-code-hook-test#6: main PR が同じ hooks-post-tool-linter の PostToolUse パイプラインに file_size_check レイヤを直接追加し、既存カスタムルール層に続く形で統合。
  • aloekun/claude-code-hook-test#52: Main PR の run_utf8_layerrun_file_size_layer 実行順序が、retrieved PR の UTF-8 優先検査パターンを層別構造に拡張したもの。
  • aloekun/claude-code-hook-test#133: Main PR の threshold_bytes=51200(50KB)制約が、retrieved PR の docs/todo 分割戦略と同一基準を実装。
🚥 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 プルリクエストのタイトルは、file_size_check Layer 0.5 の hooks-post-tool-linter への統合という主要な変更を明確に説明しており、変更内容と一致しています。
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 426217c into master Jun 6, 2026
1 check passed
@aloekun aloekun deleted the feat/file-size-check-hook branch June 6, 2026 18:24
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