Skip to content

feat: Bundle 既存ルール仕組み化 — file_length lint + pr_size_check stage (順位 147 + 151) - #202

Merged
aloekun merged 3 commits into
masterfrom
bundle-rules-mechanization-147-151
Jun 10, 2026
Merged

feat: Bundle 既存ルール仕組み化 — file_length lint + pr_size_check stage (順位 147 + 151)#202
aloekun merged 3 commits into
masterfrom
bundle-rules-mechanization-147-151

Conversation

@aloekun

@aloekun aloekun commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Bundle "既存ルール仕組み化" — ~/.claude/rules/common/ に書かれているが mechanical enforcement されていなかった 2 つの size limit を hook + push 両層の機械強制に昇格する。

順位 147: file_length lint 追加 (hooks-post-tool-comment-lint-rust)

  • coding-style.md § File Organization の 800 行 max ガイドラインを決定論的に維持
  • Touch-trigger ratchet (whole-file flag): 既存 800+ ファイルは触られるまで grandfather、任意の Edit/Write で feedback (additionalContext)
  • soft nag のため override env は持たない (block しない nag に override は無意味)
  • AST 不要 (line count のみ) で ~30 行追加 + 14 tests

順位 151: pr_size_check stage 追加 (cli-push-runner)

  • git-workflow.md § Multi-PR chaining の 「1 PR あたり 250-800 lines」 目安を決定論的に維持
  • jj diff --stat -r '<default_branch>..@' で insertions + deletions を計測
  • 2 段階閾値: warning_threshold = 800 (警告のみ) / block_threshold = 1500 (push 停止)
  • Kill-switch env: PR_SIZE_CHECK_OVERRIDE=1 (大型 refactoring 時のバイパス)
  • ADR-039 三点セット完全準拠 (scratch_file_warning template ベース)
  • default_branch 引数化で rule⑫ no-hardcoded-jj-revset-range 適用、alternative branch ("main" 等) 対応

Self-dogfood の結果

  • jj diff --stat -r 'master..@' = 921 行 → warning_threshold (800) 超過、block_threshold (1500) 未満で warning のみ
  • file_length lint deploy 後、1606 行に成長した hooks-post-tool-comment-lint-rust/src/main.rsRUST_FILE_TOO_LONG 正常発火を確認

Semantic 注記 (147)

todo 文言「順位 48 と同 touch-trigger ratchet」を whole-file flag で実装。ファイル全体は常に「触られている」ので関数長の body overlap 検査がそのまま translate せず、aggressive (任意 Edit で flag) を採用。soft nag なので開発フローを妨げない (block しない)。

Test plan

  • cargo test --workspace 全 PASS (cli-push-runner 169 / comment-lint-rust 100 / その他)
  • cargo clippy --workspace -- -D warnings 0 warnings
  • pnpm build:all 成功
  • file_length lint dogfood (1606 行ファイルで RUST_FILE_TOO_LONG 発火)
  • pr_size_check self-test (PR 921 行で warning のみ、block_threshold 未満で push 続行)
  • takt pre-push-review APPROVE (N-1 minor: 単数形 "file changed" 未対応は non-blocking、次 PR で fix)
  • (post-merge dogfood) 3-5 PR 後に false positive / 検出効果 / override 使用頻度を観測し default-ON 昇格 or 却下を判定 (ADR-039 bounded lifetime)

関連 ADR

  • ADR-039 (Experimental feature 標準パターン): 両機能とも config opt-in + kill-switch + bounded lifetime 準拠
  • ADR-007 (custom linter layer boundary): 147 = PostToolUse hook 層、151 = pre-push 層、責務分離
  • rule⑫ (no-hardcoded-jj-revset-range): 151 で適用、format!("{}..@", default_branch) で組立

Summary by CodeRabbit

リリースノート

  • New Features

    • プッシュ時にPRの変更行数をチェック。800行で警告、1500行を超えるとプッシュをブロックします。PR_SIZE_CHECK_OVERRIDE環境変数でバイパス可能。
    • Rustファイルの行数が800行を超える場合、エラーとして検出します。
  • Documentation

    • タスク追跡ドキュメントを更新し、GitHubトークン検出テストと設計方針の追記タスクを追加。

@coderabbitai

coderabbitai Bot commented Jun 10, 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: b523340a-beb3-454f-9d8b-89dc66ebed41

📥 Commits

Reviewing files that changed from the base of the PR and between d5ca4f5 and db6fa6c.

📒 Files selected for processing (8)
  • docs/todo-summary.md
  • docs/todo10.md
  • push-runner-config.toml
  • src/cli-push-runner/src/config.rs
  • src/cli-push-runner/src/main.rs
  • src/cli-push-runner/src/stages/mod.rs
  • src/cli-push-runner/src/stages/pr_size_check.rs
  • src/hooks-post-tool-comment-lint-rust/src/main.rs

📝 Walkthrough

Walkthrough

PR #202 は、PR diff サイズを検査する push-runner ステージと、Rust ソースファイルのファイル長違反を検出する lint ルールを新たに実装します。設定・CLI 統合・コア実装の段階を経て PR サイズチェックを完成させ、並行して file length detection を hooks-lint に追加します。

Changes

PR Size Check Pipeline

Layer / File(s) Summary
Configuration schema and defaults
push-runner-config.toml, src/cli-push-runner/src/config.rs
[pr_size_check] TOML セクション、PrSizeCheckConfig 構造体、警告閾値 800・ブロック閾値 1500・基準ブランチ "master" のデフォルト定数、および TOML パース・設定テストを追加します。
CLI pipeline integration and exit codes
src/cli-push-runner/src/main.rs
終了コード EXIT_PR_SIZE_EXCEEDED(8)を追加し、run_pre_checks 内で run_pr_size_check を呼び出す分岐を実装します。ブロック時にログ出力後パイプライン中断、説明文を更新します。
Module declaration and re-export
src/cli-push-runner/src/stages/mod.rs
pr_size_check モジュール追加と run_pr_size_checkpub(crate) 再エクスポートにより、main.rs からの呼び出しを可能にします。
Core size check implementation and parsing
src/cli-push-runner/src/stages/pr_size_check.rs
jj diff --stat -r default_branch..@ で PR diff サイズを取得し、insertions/deletions を合算して警告・ブロック閾値と判定します。fail-open デザイン(jj 失敗時も push 継続)、環境変数 PR_SIZE_CHECK_OVERRIDE によるバイパス、summary 行パース・ヘルパー関数・境界値テストを含みます。

File Length Violation Detection

Layer / File(s) Summary
File length violation detection and integration
src/hooks-post-tool-comment-lint-rust/src/main.rs
MAX_FILE_LINES(800行)を定数化し、find_file_length_violations でファイル全体の行数をカウント、超過時に RUST_FILE_TOO_LONG(error)を生成します。純削除ファイルはスキップ、collect_all_violations に統合して既存違反と集約します。行数カウント・判定・フィルタ・統合テストを含みます。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • aloekun/claude-code-hook-test#171: 主 PR の hooks-lint 作業と同じく collect_all_violations の集約フローを拡張して長さ系 violation を追加する点で関連します。
  • aloekun/claude-code-hook-test#104: ファイル長違反検出の line_filter・pure-deletion スキップ処理が、取得 PR の changed-lines scoping ロジックを踏襲しています。
  • aloekun/claude-code-hook-test#105: 同じく collect_all_violations の集約フローを拡張して長さ系 violation(関数長)を追加する実装パターンで関連します。
🚥 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 PR のタイトルは、主要な変更(ファイル長リント + pr_size_check ステージの追加)を明確に要約しており、優先順位(147 + 151)も含めて具体的かつ正確です。
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 b737a53 into master Jun 10, 2026
1 check passed
@aloekun
aloekun deleted the bundle-rules-mechanization-147-151 branch June 10, 2026 11:00
aloekun added a commit that referenced this pull request Jun 22, 2026
…er enable (#216)

5 entries の stale cleanup と weekly review reminder の試験運用元 enable。

## Stale entry cleanup (5 件)

PR #202 / #215 で land 済だが docs/todo*.md に entry が残存していた
タスクを削除:
- 順位 147 (File length lint, todo9.md) — PR #202
- 順位 151 (PR diff lines check, todo9.md) — PR #202
- 順位 212 (PowerShell dispatch, todo10.md) — PR #215
- 順位 213 (parse_coderabbit_status test, todo10.md) — PR #215
- 順位 214 (parse_actionable_comments test, todo10.md) — PR #215

順位 215 (coding-style.md "Defensive State Reset" section 追加) は
PR #215 で todo entry を追加しただけで実装は未着手のため保持。
grep "Defensive State Reset" ~/.claude/rules/common/coding-style.md
で実体確認済。

## weekly_review_reminder の試験運用元 enable

.claude/hooks-config.toml [session_start.weekly_review_reminder] を
enabled = false → true に変更。

ADR-031 (週次レビュー pipeline) は 2026-06-01 に本採用化済みだが、
Phase E 観測で「reminder は実発火していない」状態が継続し最後の実行から
21 日経過 (2026-06-01 → 2026-06-23) していたため、試験運用元では明示的に
enable する運用に切替。派生プロジェクト deploy 時の default は
ADR-039 § 1 opt-in 契約に従い OFF 維持。

本変更は PR-3 (layered config: [features].enabled allow-list 移行) で
真の opt-in 切り替えになるまでの暫定。toml に rationale comment block を
明記済み。

## PR 計画における位置

PR-1 (本 PR) → PR-3 (layered config) → PR-2 (Stop hook todo cleanup check)
の 3 PR plan の 1 件目。PR-3 で本 PR の `enabled = true` は
`[features].enabled` allow-list 登録に置き換わる。
aloekun added a commit that referenced this pull request Jun 23, 2026
… 違反解消) (#217)

* docs(todo): 順位 216-219 採用 (PR #216 post-merge-feedback T1-1/T3-1/T3-2/T3-3)

PR #216 (cleanup-stale-todo-weekly-enable) の post-merge-feedback で 6 提案中
4 件 (T1-1 / T3-1 / T3-2 / T3-3) をユーザー承認 (2026-06-23) し
docs/todo-summary.md + docs/todo10.md に entry 化:

- 順位 216 (🔧 Tier 2、Bundle 216-217): `no-workstream-seq-names-in-config`
  lint rule 追加 — config comment 内 `PR-[0-9]+` ephemeral workstream
  sequence の機械的検出。analyzer Tier 1 分類は memory
  feedback_tier_classification に従い project Tier 2 (mechanical = T2) に再分類。

- 順位 217 (💎 Tier 3、Bundle 216-217): coding-style.md § Cross-File
  Reference Lifecycle に config file comments の permanent artifact 扱い明記 +
  workstream sequence 禁止例追加 (順位 216 の文書層補完、2 層防御)。

- 順位 218 (💎 Tier 3): ADR-039 § Bounded Lifetime + patterns.md に
  provisional `enabled` 変更時の todo entry 必須化を追加
  (config comment-only tracking の silent aging 防止)。

- 順位 219 (💎 Tier 3): development-workflow.md § 設計 doc/実装の同期チェック
  に「commit description 言及 ≠ 実装完了」明文化 (PR #216 cleanup での
  順位 215 救出事例を inline cite、analyzer naïve assumption の構造的予防)。

採用されなかった T2-1 / T2-2 (analyzer cross-check / provisional auto-detect) は
🤔 様子見継続。Frequency Low 初観測 + Effort M + takt test infra 未調査のため、
2 PR 以上の再観測後に Tier 1 昇格を再評価する方針。

ファイル変更:
- docs/todo-summary.md: table に 4 rows 追加 (順位 215 直後、lines 89-92)
- docs/todo10.md: 詳細 entry 4 件追加 ("## 既知課題" 直前、lines 512/568/620/674)

* refactor(hooks): hooks-session-start / hooks-pre-tool-validate / hooks-post-tool-linter を module 分割

3 hook crate の main.rs を coding-style.md § File Organization (800 行 max) 内に収まる module 構成に分割。behavior 不変な mechanical refactor で、各関数の signature / export 関係は維持し、test も co-located mod tests として各 module に分散する。

PR-3 (layered config refactor) の前置 PR (PR-3a)。順位 147 (file_length lint) が PR #202 で land、本 PR-3a で 3 hook の touch-trigger ratchet 違反を解消することで PR-3b (layered config) を clean state で進められる。

対象:
- src/hooks-session-start/src/main.rs (1611 行) → 6-7 module
- src/hooks-pre-tool-validate/src/main.rs (2914 行) → 5-7 module
- src/hooks-post-tool-linter/src/main.rs (3316 行) → 6-8 module

完了基準:
- 全 module ファイルが 800 行以下
- cargo clippy --workspace -- -D warnings clean
- cargo test --workspace pass (behavior 不変)
- PostToolUse comment-lint-rust の file_length lint 0 件

* fix(hooks): takt-fix iter 3 — CR Critical/Major findings 解消 (PR-3a follow-up)

PR #217 (pr3a-hooks-module-split) の CodeRabbit review で検出された
Critical / Major / Minor findings を takt post-pr-review の 3 iter fix で
解消した変更を land。

## 修正内容 (CR severity 別)

### Critical (1 件 / 採用)
- docs/todo10.md: 順位 216 (no-workstream-seq-names-in-config rule) の
  test_coverage 宣言で拡張子カバレッジ欠落と test 命名不一致を修正
  (other_ext_tests に jsonc test を追加、main_ext_tests の test 名を
  TOML schema 規約と整合)

### Major (3 件 / 採用)
- src/hooks-pre-tool-validate/src/todo_staleness.rs: run_jj_with_timeout
  で child stdout をブロッキング待機していたパイプバッファ枯渇デッド
  ロックを修正。spawn_stdout_drainer + poll_child_with_deadline 関数を
  抽出してバックグラウンド drain に変更 (ADR-016 subprocess safety pattern)
- src/hooks-session-start/src/jj_helpers.rs: 同型の deadlock 修正
  (spawn_stdout_drainer + poll_child_with_deadline 抽出)。両 module で
  identical pattern を共有
- src/hooks-session-start/src/reaper.rs: .failed marker の atomic file
  creation を File::create_new() で保証 (TOCTOU window 解消)

### Minor (2 件 / 採用)
- docs/todo10.md: line 532 markdown 引用符の閉じ括弧不一致を修正
- src/check-ci-coderabbit/src/rate_limit.rs + src/hooks-session-start/
  src/reaper.rs: parse_iso8601_to_unix で Z suffix を strip_suffix で
  validate (trim_end_matches では invalid timestamp も accept していた)

### Minor (1 件 / 却下)
- src/hooks-pre-tool-validate/src/config.rs: TODO_STALENESS_DEFAULT_BRANCH
  を "master" → "main" 提案。本リポジトリは master を default branch
  として運用しているため却下。他 module の "main" 参照は aspirational /
  transitional な記述で、本 module の "master" が正しい。

## 検証

- cargo test --workspace: 437 tests pass (本 PR 関連: 71 + 221 + 145、
  rate_limit.rs 周辺は別 crate test で cover)
- cargo clippy --workspace -- -D warnings: clean
- takt post-pr-review: 3 iterations / 39m 32s / approved (structured_output)

* fix(todo): 順位 216 entry の extensions から plain `json` 削除 (CR Critical L530 採用)

CR Critical L530 で「Task 216 の test_coverage 宣言に拡張子カバレッジ欠落」
として指摘された不整合を解消:

- extensions = ["toml", "yaml", "yml", "jsonc", "json"] のうち plain
  `json` は comment 構文を持たず本 rule (`no-workstream-seq-names-in-config`)
  の対象外 = test 未定義状態だった
- jsonc が JSON-with-comments を cover するため json は rule scope から除外
- extensions = ["toml", "yaml", "yml", "jsonc"] に縮小

なお同 thread 内で指摘された「`no_workstream_seq_skips_github_pr_number` が
main_ext_tests.toml に配置されている」点は coverage.rs の実装 (positive/negative
semantic を強制しない、宣言 test 名の存在のみ check) と rule⑫ 既存 pattern
との整合により現状維持。CR Major (path → workspace dep) と CR Minor
(master → main) は rejection 理由を thread reply で記録済。
aloekun added a commit that referenced this pull request Jun 24, 2026
…PR-W1、self-host irony 解消) (#220)

* docs(plan): PR-W0 を [x] #219 (merged at 2026-06-24T16:07:42Z) に更新

PR #219 (PR-W0、weekly-review に file_length scan facet 追加) が
2026-06-24T16:07:42Z に master へ land したことを受けて、
docs/file-length-enforcement-plan.md の進捗追跡 table の PR-W0 status を
`[in progress]` → `[x] #219` に更新する。

* refactor(hooks-post-tool-comment-lint-rust): main.rs を module 分割 (PR-W1)

docs/file-length-enforcement-plan.md PR-W1 を実装。
lint hook 本体 (1606 行) を coding-style.md § File Organization (800 行 max)
内に収まる module 構成に分割。behavior 不変な mechanical refactor で
関数 signature・公開 API・field 名・default 値はすべて保持。

順位 147 (file_length lint、PR #202 land) を自分自身に適用した self-host
の整合性を確立。本 PR が land すれば 7 files 中 1 件 (1606 行) を 800 行
以下に解消、weekly-review file_length watchlist の件数が 7 → 6 に減少。

分割計画は計画書 PR-W1 section + Appendix A Agent prompt template 参照。
PR-3a (#217) の hooks-session-start 分割と同型 procedure を Agent 委譲で
実装、behavior 不変性は test count 不変 + cargo clippy clean で verify。
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