Skip to content

feat(hooks): PR-W5 file-length Stop gate — comment-lint --check-modified-files batch mode + [file_length_gate] opt-in - #234

Merged
aloekun merged 3 commits into
masterfrom
pr-w5-file-length-stop-gate
Jul 2, 2026
Merged

feat(hooks): PR-W5 file-length Stop gate — comment-lint --check-modified-files batch mode + [file_length_gate] opt-in#234
aloekun merged 3 commits into
masterfrom
pr-w5-file-length-stop-gate

Conversation

@aloekun

@aloekun aloekun commented Jul 2, 2026

Copy link
Copy Markdown
Owner

概要

file-length-enforcement-plan.md の PR-W5 (Phase 2 / Stop hook gate C)。Phase 1 (PR-W1〜W4、#220/#224/#230/#231) で 800 行以下に整えた clean state を恒久維持する強制層を追加する。

hooks-post-tool-comment-lint-rust--check-modified-files batch mode を追加し、Stop hook quality_gate の 1 step として PR 範囲 (base..@) の .rs file 行数を検査。800 行超が 1 件でもあれば exit 1 で Stop を block する (Option C-2)。

mechanical な feature 追加、behavior 不変。既存 lint (comment/function/file_length/metrics) は不変。

実装

  • src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs (新規、17 tests)
  • main.rs--check-modified-files dispatch 追加、Cargo.tomltoml 依存追加
  • .claude/hooks-config.toml に file-length step + [file_length_gate] section (dogfood のため enabled=true)
  • docs/file-length-enforcement-plan.md PR-W5 実績反映

なお本 PR には前セッションの feedback docs コミット (順位 246、todo-summary/todo13) を 別コミットとして bundle している。

ADR-039 3 点セット

  • Config opt-in (default OFF): gate_enabled()unwrap_or(false)。本 repo のみ dogfood で enabled=true
  • Kill-switch: 下表
  • Bounded lifetime: plan doc 削除条件 3 (override 未使用で 1-2 セッション通過)

Kill-switch table

起動経路 停止コマンド 影響範囲
[file_length_gate] enabled=true + file-length step enabled=false (恒久) Stop hook の file-length 判定のみ
Stop 発火時に file-length step 実行 env FILE_LENGTH_CHECK_OVERRIDE=1 (緊急、truthy) 当該 Stop の判定を skip

設計判断

  • jj 変更検出は base branch を config 引数化 (default master、ADR-021 § Revset Composability — custom lint NO_HARDCODED_JJ_REVSET_RANGE 指摘対応)
  • cmd path は cmd.exe の forward-slash 非対応のため backslash TOML literal string
  • jj 失敗時は fail-closed で block (ADR-043、stop_hook_active retry-skip が永続 lock を防止)
  • templates (TS/Python) は Rust 非対象のため未追加

検証

  • cargo test -p hooks-post-tool-comment-lint-rust: 116 pass / clippy clean / fmt clean
  • cargo test --workspace: regression なし / cargo clippy --workspace clean
  • dogfood (deploy 済 exe): clean=exit0 / 850行file=block / OVERRIDE(=1,=true)=bypass / enabled=false=no-op / self-host=exit0

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • 大きな Rust ファイルの変更を検出して、一定行数を超える場合に停止条件を満たさないようになりました。
    • 設定によりこのチェックを有効/無効に切り替えられるようになり、緊急時に回避する仕組みも追加されました。
    • 変更検知が不完全な場合は安全側に倒して処理を止めるようになりました。
  • Documentation

    • 実装状況と運用方針、完了条件、関連タスクの進捗を更新しました。

aloekun and others added 2 commits July 2, 2026 19:47
…ied-files batch mode + [file_length_gate] opt-in

Phase 1 (PR-W1〜W4、#220/#224/#230/#231) で 800 行以下に整えた clean state を恒久維持する
強制層。hooks-post-tool-comment-lint-rust に --check-modified-files batch mode を追加し、
Stop hook quality_gate の 1 step として PR 範囲 (base..@) の .rs file 行数を検査。
800 行超が 1 件でもあれば exit 1 で Stop を block する (Option C-2)。

実装:
- src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs (新規、17 tests)
- main.rs に --check-modified-files dispatch 追加、Cargo.toml に toml 依存追加
- .claude/hooks-config.toml に file-length step + [file_length_gate] section

mechanical refactor、behavior 不変。既存 lint (comment/function/file_length/metrics) は不変。

## ADR-039 3 点セット (experimental feature 標準パターン)

- Config opt-in (default OFF): gate_enabled() が unwrap_or(false)。本 repo のみ dogfood で enabled=true
- Kill-switch: 下表
- Bounded lifetime: file-length-enforcement-plan.md 削除条件 3 (override 未使用で 1-2 セッション通過)

## Kill-switch table

| 起動経路 | 停止コマンド | 影響範囲 |
|---|---|---|
| .claude/hooks-config.toml の [file_length_gate] enabled=true + file-length step | enabled=false (恒久) | Stop hook の file-length 判定のみ (他 step 不変) |
| Stop hook 発火時に file-length step 実行 | env FILE_LENGTH_CHECK_OVERRIDE=1 (緊急、truthy 値) | 当該 Stop の判定を skip |

## 設計判断

- jj 変更検出は base branch を config 引数化 (default master、ADR-021 § Revset Composability)
- cmd path は cmd.exe の forward-slash 非対応のため backslash TOML literal string
- jj 失敗時は fail-closed で block (ADR-043、stop_hook_active retry-skip が永続 lock を防止)
- templates (TS/Python) は Rust 非対象のため未追加

## 検証

- cargo test -p hooks-post-tool-comment-lint-rust: 116 pass / clippy clean / fmt clean
- cargo test --workspace: regression なし / cargo clippy --workspace clean
- dogfood (deploy 済 exe): clean=exit0 / 850行file=block / OVERRIDE(=1,=true)=bypass / enabled=false=no-op / self-host=exit0

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

coderabbitai Bot commented Jul 2, 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: 0dfd3d59-d122-4286-8ff5-dcf2df77c019

📥 Commits

Reviewing files that changed from the base of the PR and between c1d7f38 and 5cc827d.

📒 Files selected for processing (1)
  • src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs
👮 Files not reviewed due to content moderation or server errors (1)
  • src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs

📝 Walkthrough
🚥 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-length の Stop ゲート追加と --check-modified-files/[file_length_gate] の導入を適切に要約しています。
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.
✨ 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.

@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: 1

🤖 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 `@src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs`:
- Around line 176-185: collect_oversize_files currently treats every
read_to_string failure as a skipped file via .ok()?; update it to fail-closed
for existing .rs files by distinguishing missing-file cases from other read
errors. Keep skipping only genuinely deleted/missing paths, and propagate
permission/encoding/race read failures as Err so run_check_modified_files() can
exit 1; use collect_oversize_files and its caller in run_check_modified_files()
to locate the change.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 211e17d5-9c8b-44b6-9ac3-bb3b92cac857

📥 Commits

Reviewing files that changed from the base of the PR and between 125259b and c1d7f38.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • .claude/hooks-config.toml
  • docs/file-length-enforcement-plan.md
  • docs/todo-summary.md
  • docs/todo13.md
  • src/hooks-post-tool-comment-lint-rust/Cargo.toml
  • src/hooks-post-tool-comment-lint-rust/src/main.rs
  • src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs

Comment thread src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs
aloekun added a commit that referenced this pull request Jul 2, 2026
Resolved findings:
- [Major] src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs:185 読み取り不能な既存 `.rs` は fail-closed にしてください。
CodeRabbit Major #234-1 (読み取り不能な既存 .rs は fail-closed に) を適用:
collect_oversize_files を Result 化し、存在するのに読めない .rs は Err → exit 1 (block)。

さらに削除 file 誤検知を補正: jj diff --name-only は削除 file も列挙する (実測確認) ため、
Path::exists() で存在確認し削除 file (非存在) は skip する。これがないと file split
refactor (元 file 削除を伴う、本 plan が促進する作業そのもの) を gate が誤 block する。
CodeRabbit の指摘文言も「*既存* .rs」であり削除 file は対象外。

- collect_oversize_files: filter(Path::exists) + Result<Vec, String>
- fail-closed 診断を run_check_modified_files で block 表示 (ADR-043 § 原則1)
- tests: skips_deleted_file (skip) + errors_on_present_but_unreadable (Err) で両分岐を assert

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aloekun
aloekun force-pushed the pr-w5-file-length-stop-gate branch from 275591c to 5cc827d Compare July 2, 2026 11:35
@aloekun

aloekun commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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