fix: update-agents-md.sh の複雑度を 49 → 38 に低減 (#688) - #697
Conversation
以下のリファクタリングで循環的複雑度を低減: - データテーブル (DOT_DIR_PURPOSE / CLAUDE_SUB_PURPOSE / REG_DIR_PURPOSE / QG_PURPOSE / HOOK_TABLE) を `script/lib/agents-md-data.sh` に分離 - AGENTS.md テンプレート本文を `script/lib/agents-md-template.md` に分離し envsubst で変数置換 - `case` 文 7 → 1、`emit_row` ヘルパで重複ロジック共通化 - 残課題: 目標 ≤20 にはさらに for ループ統合が必要だが、機能上必要なものが 多いため今回は -12 にとどめた 副次修正: - `--check` モード: tempfile を `.context/` から system tempdir に移動 (.prettierignore で .context/ がスキップされ整形差分が永久に出ていたため) - `write_target` のリダイレクト順序バグ修正 (元ファイル truncate 後に読み込み していたため markers 喪失) Closes #688 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 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 |
🔍 AI Code Review (Local Hook)Models: Codex (default) / Gemini (default) ✨ Gemini ReviewMCP issues detected. Run /mcp list for status.### レビュー結果 1. AGENTS.md におけるドキュメント内容の退行 (Regression)
2. "Agents" および "Skills" セクションの消失
3. Bash 4.x 未満の環境における動作不全 (ポータビリティ)
4. 非標準コマンド
|
|
Claude finished @keito4's task in 2m 48s —— View job PR #697 コードレビュー
総評複雑度削減の方向性は正しく、 Verdict: ❌ REQUEST_CHANGES 🔴 Major — コンテンツ退行1. Agents・Skills セクションの消失ファイル: 元の -## Agents
-| Agent | Description |
-| act-local-ci-manager | Set up and manage local CI pipeline execution using act |
-...
-## Skills
-| Skill | Description |
-| ci-check | Check CI status for the current branch |
-...AGENTS.md は AI エージェントが利用可能なツールを把握するための主要ドキュメントです。この情報の消失は機能上の退行です。 2. コマンド説明の退行(13件が "(no description)")ファイル:
# .claude/commands/branch-cleanup.md の実際の形式:
# Branch Cleanup Command
#
# Clean up merged and stale branches both locally and remotely.AWK パターン 対策案: 見出し直下の最初の段落テキストを説明として抽出するよう変更する。 desc=$(awk 'NR>1 && /^[^#\n]/ && NF {print; exit}' "$cmd")🟡 Minor — ポータビリティ3. Bash 4.3+ 専用機能(
|
| 問題 | 深刻度 | ファイル |
|---|---|---|
| Agents/Skills セクション消失 | major | agents-md-template.md |
| コマンド説明が全て "(no description)" | major | update-agents-md.sh:100 |
local -n Bash 4.3+ 依存 |
minor | update-agents-md.sh:27,51 |
envsubst macOS 非標準 |
minor | update-agents-md.sh:183 |
上記2件の major 問題を修正後、改めてレビューします。
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5b4d8a56a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| | Directory | Purpose | | ||
| | -------------------- | ------------------------------------------------------- | | ||
| | `.agents/` | AI agent skills and configurations | |
There was a problem hiding this comment.
Remove non-existent directories from project structure table
The generated AGENTS.md now documents .agents/ (and similarly next/) as repository directories, but those paths are not present in this commit tree, so the overview is inaccurate and can vary based on untracked local folders. Regenerating from a clean tree or limiting discovery to tracked directories would keep the auto-generated section deterministic.
Useful? React with 👍 / 👎.
| for entry in "pnpm-lock.yaml:pnpm" "yarn.lock:yarn" "bun.lockb:bun" "bun.lock:bun"; do | ||
| [[ -f "${entry%%:*}" ]] && { echo "${entry##*:}"; return; } |
There was a problem hiding this comment.
Preserve package manager precedence in lockfile detection
The refactor changed detect_pm from “last match wins” to “first match wins,” so repos containing multiple lockfiles (common during migrations or stale cleanup) now resolve to pnpm/yarn before bun, whereas the previous logic always preferred bun when bun.lock* existed. This changes generated metadata and can cause unexpected --check churn in mixed-lockfile states.
Useful? React with 👍 / 👎.
|
(aside) |
|
Claude finished @keito4's task in 13m 35s —— View job 修正完了 ✅
変更内容
|
| 修正 | 内容 |
|---|---|
_extract_desc() |
YAML frontmatter (description:) と Heading+paragraph の両形式を処理する共通ヘルパを追加 |
_truncate_desc() |
長文説明を最初の文末 or 100文字でトリム |
collect_commands |
_extract_desc を使用するよう変更 → (no description) 解消 |
collect_agents |
新規: .claude/agents/*.md を自動収集 |
collect_skills |
新規: .claude/skills/*.md を自動収集 |
detect_pm |
bun > yarn > pnpm 優先順序を元に戻す |
render_template |
AGENTS / SKILLS 変数をエクスポート |
script/lib/agents-md-template.md
## Agents/## Skillsセクションを追加
AGENTS.md
- 再生成: コマンド説明が復元され、Agents/Skills テーブルが追加された
注意: ブランチはまだ
origin/mainより1コミット (e1ec41e– PR #700 の Windows サポート) だけ遅れています (mergeStateStatus: BEHIND)。マージ前に GitHub 側でブランチを更新する("Update branch" ボタン)か、または手動でgit merge mainしてください。AGENTS.mdとscript/update-agents-md.shで add/add コンフリクトが発生しますが、両ファイルとも本ブランチの版を優先してください。
| Branch
- collect_commands: YAML frontmatter と Heading/paragraph 両形式に対応 - collect_agents: 新規追加 (.claude/agents/*.md を自動収集) - collect_skills: 新規追加 (.claude/skills/*.md を自動収集) - _extract_desc: 両形式に対応する共通ヘルパ関数に切り出し - _truncate_desc: 長文説明を100文字でトリム - detect_pm: bun > yarn > pnpm の優先順序を元に戻す - agents-md-template.md: ## Agents / ## Skills セクションを追加 - AGENTS.md: 上記修正により再生成 Closes #688 Co-authored-by: keito4 <keito4@users.noreply.github.com>
|
🎉 This PR is included in version 1.111.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
script/update-agents-md.shのリファクタリングで循環的複雑度を 49 → 38 に低減。Issue #688 対応。変更内容
関数分離
script/lib/agents-md-data.shに分離script/lib/agents-md-template.mdに分離し envsubst で変数置換case文 7 → 1、emitヘルパで重複ロジック共通化、table_headerヘルパでヘッダー出力統一副次修正
--checkモード: tempfile を.context/から system tempdir に移動(.prettierignoreで.context/がスキップされ整形差分が永久に出ていたため)write_targetリダイレクト順序バグ:func > targetだと target が先に空になり読み込みが空になる。content=$(func)で受けてから書き込むよう修正残課題
目標 ≤20 にはさらに整理が必要だが、データテーブル分離で機能上必要な制御フローのみ残っており、これ以上の削減は別言語(Python等)への書き換えが妥当と判断。-12 にとどめた。
Test plan
bash script/update-agents-md.sh実行成功bash script/update-agents-md.sh --checkでグリーンnpm run lint緑npm test95 件パスnpm run shellcheck緑npm run format:check緑Closes #688
🤖 Generated with Claude Code