feat(lib-telemetry): 発火テレメトリ収集層 — 全 hook の block/warn を JSONL 記録 (WP-12 step1) - #275
Conversation
…12 step1) ADR-055。ハーネス複雑度 (rule/preset/hook) の維持判断を発火実績で機械化する ROI 棚卸しの収集層。lib-telemetry を新設し 6 hook を計装 (pre-tool-validate preset / post-tool-linter custom rule / jj-op-verify warn / stop-quality / stop-tool-call-leak / comment-lint-rust file-length gate)。記録は .claude/telemetry/firings-<date>-<pid>.jsonl にメタデータのみ (パス・内容は非記録)。opt-in default OFF + kill-switch + fail-open (ADR-039/043)。 集計 pre-step (step2) / 卒業判定機械化 (step3) は 28 日 warm-up 後に着手 (順位 307/308)。
📝 WalkthroughWalkthrough共有の Changes発火テレメトリ収集
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Hook
participant lib_telemetry
participant Config as hooks-config.toml
participant Storage as JSONLファイル
Hook->>lib_telemetry: 発火イベントをrecord
lib_telemetry->>Config: enabledとkill-switchを確認
lib_telemetry->>Storage: メタデータを1行追記
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
🤖 PR Monitor 分析 (GitHub Actions バックストップ)
Applicable Findings (Critical / High / Major)該当なし (レビュー指摘が 1 件も存在しない) Applicable Findings (Medium 以下)該当なし Filtered (not applicable)該当なし 次のアクション
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hooks-stop-quality/src/main.rs (1)
154-175: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick wintelemetry を品質違反に限定してください
emit_block()でrecord_block_firing()を呼ぶと、stdin/JSON 失敗などの fail-closed 経路も同じ Block カウントに混ざります。ADR-055 の ROI 判定を歪めないよう、block_on_failures側だけで記録するか、infra 用カウンタを分けてください。🤖 Prompt for 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. In `@src/hooks-stop-quality/src/main.rs` around lines 154 - 175, 品質違反以外の fail-closed 経路まで Block telemetry に含めないよう、emit_block と record_block_firing の連携を見直してください。record_block_firing は品質違反を処理する block_on_failures 側からのみ呼び出し、stdin/JSON 失敗などのインフラエラー経路では呼ばないようにしてください。
🧹 Nitpick comments (1)
src/lib-telemetry/src/lib.rs (1)
136-169: 🧹 Nitpick | 🔵 Trivialper-pid×日次partitionによるファイル数増加への配慮。
各hook実行が短命プロセスであるため、
firings-<date>-<pid>.jsonlは実行ごとに新規ファイルを生成しやすく、28日間のwarm-up期間中に.claude/telemetry/配下へ小さなファイルが多数蓄積される可能性があります。集計 (WP-12 step 2) 実行までの保持・クリーンアップ方針(例: 古いファイルの定期削除、上限件数)を検討することを推奨します。🤖 Prompt for 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. In `@src/lib-telemetry/src/lib.rs` around lines 136 - 169, Add a retention and cleanup policy to the record_to telemetry writer for stale firings-*.jsonl files, such as removing files older than the configured warm-up period or enforcing a file-count limit. Keep cleanup scoped to the telemetry directory and preserve the existing append behavior and per-process daily filename partitioning.
🤖 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.
Outside diff comments:
In `@src/hooks-stop-quality/src/main.rs`:
- Around line 154-175: 品質違反以外の fail-closed 経路まで Block telemetry
に含めないよう、emit_block と record_block_firing の連携を見直してください。record_block_firing
は品質違反を処理する block_on_failures 側からのみ呼び出し、stdin/JSON 失敗などのインフラエラー経路では呼ばないようにしてください。
---
Nitpick comments:
In `@src/lib-telemetry/src/lib.rs`:
- Around line 136-169: Add a retention and cleanup policy to the record_to
telemetry writer for stale firings-*.jsonl files, such as removing files older
than the configured warm-up period or enforcing a file-count limit. Keep cleanup
scoped to the telemetry directory and preserve the existing append behavior and
per-process daily filename partitioning.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: bd50ab53-fbfd-4ed3-a23a-a18f9bc3b26a
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (29)
.claude/hooks-config.toml.gitignoreCLAUDE.mdCargo.tomldocs/adr/adr-055-firing-telemetry-collection.mddocs/harness-improvement-plan.mddocs/todo-summary.mddocs/todo13.mdsrc/hooks-post-tool-comment-lint-rust/Cargo.tomlsrc/hooks-post-tool-comment-lint-rust/src/modified_files_check.rssrc/hooks-post-tool-jj-op-verify/Cargo.tomlsrc/hooks-post-tool-jj-op-verify/src/main.rssrc/hooks-post-tool-linter/Cargo.tomlsrc/hooks-post-tool-linter/src/custom_rules/engine.rssrc/hooks-pre-tool-validate/Cargo.tomlsrc/hooks-pre-tool-validate/src/blocked_patterns.rssrc/hooks-pre-tool-validate/src/handlers.rssrc/hooks-pre-tool-validate/src/presets/basic.rssrc/hooks-pre-tool-validate/src/presets/gh.rssrc/hooks-pre-tool-validate/src/presets/jj.rssrc/hooks-pre-tool-validate/src/presets/safety/polling_exe.rssrc/hooks-pre-tool-validate/src/presets/safety/powershell.rssrc/hooks-pre-tool-validate/src/presets/safety/secret.rssrc/hooks-stop-quality/Cargo.tomlsrc/hooks-stop-quality/src/main.rssrc/hooks-stop-tool-call-leak/Cargo.tomlsrc/hooks-stop-tool-call-leak/src/main.rssrc/lib-telemetry/Cargo.tomlsrc/lib-telemetry/src/lib.rs
🤖 PR Monitor 分析 (GitHub Actions バックストップ)
Applicable Findings (Critical / High / Major)該当なし Applicable Findings (Medium 以下)
Filtered (not applicable)
次のアクション
|
PR #275 (feat(lib-telemetry) WP-12 step1) の post-merge feedback (ADR-030) から採用候補9件を採用し順位309-317に登録。Tier1: telemetry の block 記録を実 quality 違反に限定 (CodeRabbit Major、ADR-055 amendment 併記) / custom-regex の生 regex が telemetry id に流れる privacy 是正 (非ブロッキング follow-up 統合) / 逐語的関数複製の pre-push DRY lint rule。Tier2: telemetry retention/cleanup / is_truthy 三重複製の ADR-049 fixture 化 / bookmark 未作成 push のエラーメッセージ改善。Tier3: ADR-055 warm-up 期限の config コメント明記 / ADR-044 2nd-consumer 原則の明確化 / utility 追加前チェックリスト。様子見4件は report のみ。根拠は .claude/feedback-reports/275.md。
概要
WP-12「発火テレメトリ + ハーネス ROI 棚卸し」の step 1(収集層) を実装します(ADR-055)。ハーネス複雑度(custom rule 12 本・pre-tool preset 群・hook)の維持判断を発火実績で機械化する ROI 棚卸しの土台です。
3 ステップ構成のうち、telemetry はマージ後に初めてデータが溜まるため、収集層のみ先行 PR とし、集計 pre-step(step 2)と卒業判定機械化(step 3)は 28 日 warm-up 後に着手します(todo 順位 307/308 へ移管済み)。
変更内容
新規 crate
lib-telemetry各 hook の block/warn 発火を
.claude/telemetry/firings-<YYYY-MM-DD>-<pid>.jsonlに append する共通層。record()(prod 入口)+ 副作用注入版record_to/record_gated_to/telemetry_enabled(lib-jj-helpers::pipeline_lockの_atパターンに準拠、テスト確定性のため)CLAUDE_TELEMETRY_DISABLE+ fail-open6 hook の計装(裁量発火に限定)
除外: 常時 ON の構造チェック(非 doc コメント / 関数長 / file_size / utf8)と nudge-only hook。削除候補にならず ROI 信号を希釈するノイズのため。
設計方針
lib-pending-fileから最小複製(ADR-044 の責務結合回避、抽出トリガ到達を ADR に記録)テスト
lib-telemetryユニットテスト(opt-in gating / kill-switch / JSON エスケープ / 50 スレッド並行 / partition 命名)-D warnings)/ignored 直列すべて緑pre-push review の自動修正
simplicity review が
is_truthyの 3 重複(lib-telemetry / comment-lint-rust / stop-tool-call-leak、後 2 者は本 PR で lib-telemetry 依存を追加済み)を検出し、fix ループがlib_telemetry::is_truthyを pub 化して共通化しました(ローカルコピー + テスト削除)。security review は APPROVE。follow-up(本 PR では対応せず)
blocked_patternsエントリは生の regex 文字列が telemetry のidに載る(現行 config は named preset のみで非発火)。派生プロジェクト向けに fallback branch へ合成 id を使う対策を検討(PR フィードバック時に todo 化予定)Summary by CodeRabbit
新機能
ドキュメント