Skip to content

feat: add similarity-analysis command and enhance setup-claude.sh - #213

Merged
keito4 merged 2 commits into
mainfrom
feat/add-similarity-analysis-command
Dec 30, 2025
Merged

feat: add similarity-analysis command and enhance setup-claude.sh#213
keito4 merged 2 commits into
mainfrom
feat/add-similarity-analysis-command

Conversation

@keito4

@keito4 keito4 commented Dec 30, 2025

Copy link
Copy Markdown
Owner

Summary

  • /similarity-analysis コマンドを追加(similarity-tsを使用したコード重複検出)
  • setup-claude.sh にコマンド・エージェント・フックの同期機能を追加
  • config-base-sync-update.md の allowed-tools を拡張

Changes

New: /similarity-analysis command

リポジトリ内のコード類似度を分析し、重複関数やパターンを検出するコマンド。

使用例:

/similarity-analysis
/similarity-analysis path=src threshold=0.9

機能:

  • AST ベースの類似度検出(テキストマッチングではない)
  • 設定可能な類似度閾値
  • リファクタリング推奨事項の出力

Enhanced: setup-claude.sh

  • リポジトリの .claude/commands/, .claude/agents/, .claude/hooks/~/.claude/ に同期
  • hookify プラグインのパッチ対象を cache ディレクトリまで拡張
  • プラグインルートの Python ファイルの shebang 修正を追加

Updated: config-base-sync-update.md

  • allowed-toolssed, grep, cat, echo, mkdir, rm, mv, cp, date を追加

Test plan

  • similarity-ts コマンドの動作確認
  • pre-commit hooks 通過
  • テスト全件 Pass (101 tests)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added Code Similarity Analysis docs: AST-based similarity detection, configurable thresholds, refactoring suggestions, TypeScript/JavaScript support, usage examples and report format.
    • Added CLI command documentation for running similarity analysis with options and exclusions.
  • Chores

    • Improved setup/synchronization flow for commands, agents, and hooks with better validation, retrying and messaging.
    • Expanded allowed utilities list to include common shell tools (sed, grep, cat, echo, mkdir, rm, mv, cp, date).

✏️ Tip: You can customize this high-level summary in your review settings.

- Add /similarity-analysis command using similarity-ts for code duplication detection
- Update README.md with command documentation
- Extend allowed-tools in config-base-sync-update.md
- Enhance setup-claude.sh with commands/agents/hooks sync and improved hookify patching

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 30, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Added documentation for a code similarity analysis tool and expanded an allowed-tools list; enhanced the setup script to synchronize commands/agents/hooks from a repository, add new sync variables, and improve hookify discovery and patching (imports, shebangs, init handling, executability).

Changes

Cohort / File(s) Summary
Documentation: similarity & README
.claude/commands/README.md, .claude/commands/similarity-analysis.md
Added "Code Analysis" subsection to README and a new similarity-analysis.md describing a CLI similarity tool (similarity-ts), options (target path, threshold, filters), report structure, exclusions, and usage examples.
Tool allowlist update
.claude/commands/config-base-sync-update.md
Appended Bash utilities to the allowed-tools list: sed, grep, cat, echo, mkdir, rm, mv, cp, date.
Setup script: repo sync & hookify patching
script/setup-claude.sh
Added repository sync logic for commands/agents/hooks with new public variables (REPO_COMMANDS_DIR, REPO_AGENTS_DIR, REPO_HOOKS_DIR); enhanced hookify discovery using a dynamic HOOKIFY_PATHS and cache search; apply patches (absolute-import fixes, shebang -> /usr/bin/env python3), ensure Python files executable and __init__.py presence; updated logging/messages and fallback behavior.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant DevRepo as Repository (repo)
  participant Setup as setup-claude.sh
  participant FS as CLAUDE_DIR (filesystem)
  participant Hookify as hookify tool
  Note over Setup,DevRepo: Start synchronization
  DevRepo->>Setup: Provide REPO_COMMANDS_DIR / REPO_AGENTS_DIR / REPO_HOOKS_DIR
  Setup->>FS: Copy/sync command MD files, agents, hooks
  alt important commands missing
    Setup->>Setup: retry copy important commands
  end
  Note over Setup,Hookify: Discover hookify paths
  Setup->>Hookify: search HOOKIFY_PATHS and cache
  alt hookify found
    Setup->>Hookify: apply patches (imports, shebangs)
    Setup->>FS: ensure __init__.py, set executables
  else not found
    Setup-->>FS: skip patching (log informational)
  end
  Setup->>DevRepo: log sync summary / completion
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

released

Poem

🐰 I hopped through docs and scripts today,
Synced commands and hooks along the way,
I sniffed out imports, fixed shebang stew,
And left a similarity report for you! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: adding a similarity-analysis command and enhancing setup-claude.sh with repository synchronization and improved plugin patching.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

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.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@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

🧹 Nitpick comments (1)
.claude/commands/similarity-analysis.md (1)

1-69: Add prerequisites section for similarity-ts installation.

The documentation is well-structured and comprehensive. However, it assumes similarity-ts is already installed. Consider adding a prerequisites section to guide users on installation or checking availability.

🔎 Suggested addition

Add after line 15 (before "## 実行手順"):

## 前提条件

このコマンドは `similarity-ts` ツールを使用します。

```bash
# インストール確認
which similarity-ts

# インストールされていない場合
npm install -g similarity-ts
# または
pnpm add -g similarity-ts

</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used**: defaults

**Review profile**: CHILL

**Plan**: Pro

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 63e1ca165e77e0d01306fd92ab3c8fb6a01f31ea and b7da13879a6fecbdc991e10e8fffce61394ddf90.

</details>

<details>
<summary>📒 Files selected for processing (4)</summary>

* `.claude/commands/README.md`
* `.claude/commands/config-base-sync-update.md`
* `.claude/commands/similarity-analysis.md`
* `script/setup-claude.sh`

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧠 Learnings (7)</summary>

<details>
<summary>📚 Learning: 2025-12-01T03:45:17.253Z</summary>

Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/claude.yml : Trigger automatic AI assistance on claude mentions in issues, PRs, and comments using .github/workflows/claude.yml


**Applied to files:**
- `.claude/commands/README.md`
- `script/setup-claude.sh`

</details>
<details>
<summary>📚 Learning: 2025-12-09T08:39:14.049Z</summary>

Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-09T08:39:14.049Z
Learning: Follow development quality standards defined in CLAUDE.md when using Claude Code for development assistance


**Applied to files:**
- `.claude/commands/README.md`

</details>
<details>
<summary>📚 Learning: 2025-12-01T03:45:17.253Z</summary>

Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/ci.yml : Validate code quality in CI pipeline (.github/workflows/ci.yml) with linting, formatting, testing, and building


**Applied to files:**
- `.claude/commands/README.md`

</details>
<details>
<summary>📚 Learning: 2025-12-01T03:45:17.253Z</summary>

Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/docker-image.yml : Build DevContainer images automatically with semantic versioning and multi-platform support in .github/workflows/docker-image.yml


**Applied to files:**
- `.claude/commands/config-base-sync-update.md`

</details>
<details>
<summary>📚 Learning: 2025-12-01T03:45:17.253Z</summary>

Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Publish DevContainer images to ghcr.io/keito4/config-base with semantic versioning


**Applied to files:**
- `.claude/commands/config-base-sync-update.md`

</details>
<details>
<summary>📚 Learning: 2025-12-01T03:45:17.253Z</summary>

Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/update-libraries.yml : Execute npm run update:libs on schedule and open pull requests when dependencies or Codex/Claude tooling changes in .github/workflows/update-libraries.yml


**Applied to files:**
- `.claude/commands/config-base-sync-update.md`

</details>
<details>
<summary>📚 Learning: 2025-12-01T03:45:17.253Z</summary>

Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to {.codex/,.devcontainer/codex*,package*.json,npm/global.json} : Use Conventional Commits format with release-triggering types (feat/fix/perf/revert/docs) for commits touching .codex/, .devcontainer/codex*, package*.json, or npm/global.json


**Applied to files:**
- `.claude/commands/config-base-sync-update.md`

</details>

</details><details>
<summary>🧬 Code graph analysis (1)</summary>

<details>
<summary>script/setup-claude.sh (1)</summary><blockquote>

<details>
<summary>script/lib/output.sh (3)</summary>

* `log_info` (82-82)
* `log_warn` (84-84)
* `log_success` (83-83)

</details>

</blockquote></details>

</details><details>
<summary>🪛 GitHub Actions: CI</summary>

<details>
<summary>script/setup-claude.sh</summary>

[warning] 111-111: SC2012: Use find instead of ls to better handle non-alphanumeric filenames.

---

[warning] 124-124: SC2012: Use find instead of ls to better handle non-alphanumeric filenames.

</details>

</details>

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)</summary>

* GitHub Check: claude-review

</details>

<details>
<summary>🔇 Additional comments (6)</summary><blockquote>

<details>
<summary>.claude/commands/config-base-sync-update.md (1)</summary><blockquote>

`3-3`: **LGTM! Expanded tooling aligns with synchronization workflows.**

The addition of standard bash utilities (sed, grep, cat, echo, mkdir, rm, mv, cp, date) to the allowed-tools list is appropriate and supports the enhanced file synchronization operations introduced in `script/setup-claude.sh`.

</blockquote></details>
<details>
<summary>script/setup-claude.sh (4)</summary><blockquote>

`31-33`: **LGTM! Variable declarations follow established patterns.**

The new public variables (REPO_COMMANDS_DIR, REPO_AGENTS_DIR, REPO_HOOKS_DIR) are well-named, properly quoted, and consistent with the existing REPO_PLUGINS_DIR convention.

---

`52-104`: **LGTM! Robust command synchronization with comprehensive error handling.**

The command synchronization logic features:
- Safe file iteration using `find` with null-terminated strings
- Individual file copying with error tracking (copied/failed counts)
- Validation and retry logic for critical commands
- Appropriate fallback messages for missing directories

---

`266-282`: **LGTM! Dynamic hookify discovery with robust path validation.**

The expanded hookify search logic correctly:
- Initializes with known marketplace paths
- Dynamically discovers hookify installations in the cache directory
- Validates discovered paths before adding to the array
- Uses null-terminated strings for safe path handling

---

`283-349`: **LGTM! Comprehensive hookify patching with proper flag tracking.**

The enhanced hookify patching logic features:
- Proper tracking of discovered installations via `hookify_found` flag
- Comprehensive shebang fixes for both hooks/ directory and plugin root Python files
- Robust error handling with fallback for missing installations
- Consistent approach across all patching operations

</blockquote></details>
<details>
<summary>.claude/commands/README.md (1)</summary><blockquote>

`3-3`: **LGTM! Documentation accurately reflects new similarity-analysis feature.**

The documentation updates:
- Remove the hardcoded command count for better maintainability
- Add a comprehensive "Code Analysis" section describing the new similarity-analysis feature with clear usage examples and feature highlights




Also applies to: 19-37

</blockquote></details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment thread script/setup-claude.sh Outdated
@claude

claude Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

Pull Request Review - PR #213

このPRは /similarity-analysis コマンドの追加と setup-claude.sh の強化を実施しています。全体的に良質な実装ですが、いくつかの改善点と懸念事項があります。

良い点

  • AST ベースのコード類似度検出を提供する新コマンドの設計が明確
  • setup-claude.sh にコマンド・エージェント・フックの同期機能を追加し、堅牢性が向上
  • エラーハンドリングが強化され、個別ファイルコピーの失敗を追跡
  • hookify プラグインのパッチ対象を cache ディレクトリまで拡張

重大な懸念 - 依存関係の不足

問題: similarity-ts コマンドが使用されているが、package.json に依存関係が追加されていない

similarity-analysis.md:21 で similarity-ts コマンドが使用されています

影響:

  • コマンド実行時に command not found エラーが発生
  • DevContainer ビルド時に similarity-ts がインストールされない
  • ユーザーが手動でインストールする必要があり、利便性が低下

推奨修正: npm install --save-dev similarity-ts

優先度: 高 - この修正がないとコマンドが機能しません

その他の改善点

setup-claude.sh:273-281 - パフォーマンス最適化

find コマンドは既に hookify という名前のディレクトリのみを返すため、二重チェックは冗長です。条件チェックを削除することで最適化可能です。

setup-claude.sh:316-330 - コード重複

shebang 修正ロジックが hooks/ ディレクトリとルートディレクトリで重複しています。共通関数に抽出することで保守性が向上します。

config-base-sync-update.md:2 - allowed-tools の過剰な追加

多数の基本的な bash コマンド(特に rm:)が allowed-tools に追加されました。セキュリティリスクの観点から、必要最小限のコマンドのみを許可し、rm: は具体的なパターンに制限することを推奨します。

similarity-analysis.md - テストカバレッジ

新しいコマンドに対する自動テストが見当たりません。CLAUDE.md の品質基準(70%+ カバレッジ)に準拠するため、コマンドの動作を検証する統合テストの追加を推奨します。

総合評価

観点 評価 コメント
コード品質 4/5 全体的に良質だが、重複コードあり
セキュリティ 3/5 allowed-tools の過剰な許可が懸念
パフォーマンス 4/5 概ね良好、最適化の余地あり
テスト 2/5 新機能のテストが不足
ドキュメント 4/5 充実しているが、新機能の説明が不足

マージ前に対応すべき事項

必須

  1. similarity-ts を package.json に追加 - コマンドが動作しない致命的な問題

強く推奨

  1. 新機能(コマンド・エージェント・フック同期)のドキュメント追加
  2. allowed-tools の見直し(特に rm:* の制限)
  3. similarity-analysis コマンドの基本的な統合テスト追加

任意

  1. shebang 修正ロジックの関数化
  2. cache ディレクトリ検索の最適化

結論

このPRは有用な機能追加を含んでいますが、similarity-ts の依存関係追加が必須です。この修正なしではコマンドが機能しないため、マージ前に対応してください。その他の改善点は優先度に応じて対応を検討してください。全体的には良質な実装であり、上記の懸念事項が解消されれば承認可能です。

レビュー完了 - ご確認ください!

🤖 Generated with Claude Code

@keito4
keito4 merged commit 1e5b6f8 into main Dec 30, 2025
5 of 6 checks passed

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

♻️ Duplicate comments (2)
script/setup-claude.sh (2)

106-117: Successfully addresses past review feedback.

The agents synchronization now uses find instead of ls for file counting (line 111), resolving the ShellCheck SC2012 warning from previous review comments.


119-130: Successfully addresses past review feedback.

The hooks synchronization now uses find instead of ls for file counting (line 124), resolving the ShellCheck SC2012 warning from previous review comments.

🧹 Nitpick comments (1)
script/setup-claude.sh (1)

266-282: Good enhancement to hookify discovery logic.

The dynamic array-based approach with cache directory search is more robust than hard-coded paths.

💡 Optional: Remove redundant path validation

Line 277's check [[ "$cache_dir" == *"/hookify" ]] is redundant since find -name "hookify" already guarantees the directory name matches exactly. You can simplify:

-        # find -name "hookify" は正確に "hookify" という名前のディレクトリを返すので、
-        # パスが "hookify" で終わることを確認するだけで十分
-        if [[ -d "$cache_dir" ]] && [[ "$cache_dir" == *"/hookify" ]]; then
+        if [[ -d "$cache_dir" ]]; then
             HOOKIFY_PATHS+=("$cache_dir")
         fi
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7da138 and 23d8094.

📒 Files selected for processing (1)
  • script/setup-claude.sh
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-01T03:45:17.253Z
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/claude.yml : Trigger automatic AI assistance on claude mentions in issues, PRs, and comments using .github/workflows/claude.yml

Applied to files:

  • script/setup-claude.sh
🧬 Code graph analysis (1)
script/setup-claude.sh (1)
script/lib/output.sh (3)
  • log_info (82-82)
  • log_warn (84-84)
  • log_success (83-83)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: claude-review
🔇 Additional comments (3)
script/setup-claude.sh (3)

31-35: LGTM! Clean variable declarations.

The new repository path variables follow the existing naming convention and integrate well with the enhanced synchronization logic.


48-104: Excellent error handling and validation logic.

The commands synchronization implementation is robust:

  • Uses find with -print0 for safe filename handling
  • Tracks copy success/failure granularly
  • Validates important commands with retry logic

283-349: Well-structured hookify patching enhancements.

The implementation correctly:

  • Uses a flag to track hookify discovery and control messaging
  • Extends shebang fixes to plugin root Python files
  • Maintains consistency with existing hooks patching logic
  • Ensures file executability

@claude

claude Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

PR Review: similarity-analysis コマンドと setup-claude.sh の機能強化

全体評価

このPRは新しいコード類似度分析コマンド、setup-claude.shの同期機能強化、allowed-tools拡張を含む、品質の高い実装です。

コード品質

良い点

  • 適切なエラーハンドリング (setup-claude.sh:59-76)
  • Bash 4.0+の要件明示
  • 詳細なドキュメント

改善提案

Critical: エラーハンドリング改善必要

setup-claude.sh:110, 123でcp -r|| trueを使用しており、全エラーが無視されます。コマンドと同様の個別コピーロジックへの統一を推奨します。

Critical: 一時ファイルクリーンアップ不足

setup-claude.sh:305-308でmv失敗時に一時ファイルが残ります。エラーハンドリングの追加が必要です。

その他の推奨事項

  1. shebang修正ロジックの関数化 (setup-claude.sh:297-330)
  2. similarity-tsコマンドの入力検証追加(パストラバーサル対策)
  3. 冗長な条件チェックの削減 (setup-claude.sh:277)

テストカバレッジ

  • テスト全件Pass確認済み
  • setup-claude.sh新機能のテストケース追加を推奨

CLAUDE.md準拠

  • Conventional Commits準拠
  • PR差分227行 < 400行
  • ファイル数4 < 25

承認状態

条件付き承認: Critical問題(cp -rエラーハンドリング、一時ファイルクリーンアップ)修正後、マージ可能です。

レビュアー: Claude Sonnet 4.5

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.25.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released リリース済み label Dec 31, 2025
@keito4
keito4 deleted the feat/add-similarity-analysis-command branch January 29, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant