Crap4cljのロゴ

Crap4clj

コミュニティ
unclebob
crap4clj

Calculates cyclomatic complexity and CRAP scores for Clojure and Babashka functions by combining complexity analysis with test coverage data, generating sorted reports that identify high-risk under-tested code. Use when the user asks for a CRAP report, cyclomatic complexity analysis, or code quality metrics on a Clojure or Babashka project.

概要

公開者unclebob
リポジトリcrap4clj
スキル名crap4clj
スター
62
フォーク
4
同梱ファイル
19
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 19個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    unclebobがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルCrap4cljをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/unclebob/crap4clj/tree/master
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/unclebob/crap4clj.git \
  .claude/skills/crap4clj
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでCrap4cljを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にCrap4cljを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Crap4cljは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

crap4clj — CRAP Metric for Clojure

Computes the CRAP (Change Risk Anti-Pattern) score for every defn and defn- in a Clojure project. CRAP combines cyclomatic complexity with test coverage to identify functions that are both complex and under-tested.

Setup

Add both a :cov alias (Cloverage) and a :crap alias to the project's deps.edn:

clojure
:cov  {:extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}}
       :main-opts ["-m" "speclj.cloverage" "--" "-p" "src" "-s" "spec"]}
:crap {:extra-deps {io.github.unclebob/crap4clj
                     {:git/url "https://github.com/unclebob/crap4clj"
                      :git/sha "<current-sha>"}}
       :main-opts ["-m" "crap4clj.core"]}

The example above uses speclj.cloverage as the runner. For clojure.test projects, use cloverage.coverage instead:

clojure
:cov  {:extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}}
       :main-opts ["-m" "cloverage.coverage" "-p" "src" "-s" "test"]}

Adjust the -p (source path) and -s (test path) flags in :cov to match your project layout.

Usage

bash
# First verify Cloverage works on its own
clj -M:cov

# Analyze all source files under src/
clj -M:crap

# Filter to specific modules
clj -M:crap combat movement

# Analyze Babashka scripts using an existing LCOV report
bb crap --source-root scripts --use-existing-coverage

# Confirm Cloverage's doseq/for 50% form-count fingerprint and recount
clj -M:crap --doseq-double-count

crap4clj automatically deletes stale coverage reports, runs clj -M:cov, and then analyzes the results. It discovers .clj, .cljc, .cljs, and .bb source files. Cloverage instruments .cljs via crap4clj.cljs-coverage (JVM discovery); JS interop needs a #?(:clj …) branch because forms are read with :clj.

For .bb coverage, use Babashka 1.12.215 or newer and pin Cloverage commit 61e3cac426e9907a9dd01c37597f85c71a57ff90 with :deps/root "cloverage". Run Cloverage through crap4clj.bb-coverage/-main; this adapter enables .bb namespace discovery and resource loading. Pass that task to crap4clj with --coverage-command. The scripts must declare namespaces, and tests must call the instrumented functions in-process rather than launch separate bb processes. Executable scripts must guard their -main invocation with a babashka.file/*file* equality check so instrumentation can load them without running the CLI. See the README's "Coverage for .bb files" section for the complete bb.edn configuration.

Output

A table sorted by CRAP score (worst first):

CRAP Report
===========
Function                       Namespace                            CC   Cov%     CRAP
-------------------------------------------------------------------------------------
complex-fn                     my.namespace                         12   45.0%    130.2
simple-fn                      my.namespace                          1  100.0%      1.0

Interpreting Scores

CRAP ScoreMeaning
1-5Clean — low complexity, well tested
5-30Moderate — consider refactoring or adding tests
30+Crappy — high complexity with poor coverage

How It Works

  1. Deletes old coverage reports and runs Cloverage (clj -M:cov)
  2. Finds all .clj, .cljc, .cljs, and .bb files under the configured source roots
  3. Extracts defn/defn- functions with line ranges
  4. Computes cyclomatic complexity (if/when/cond/condp/case/cond->/cond->>/some->/some->>/and/or/loop/catch)
  5. Reads Cloverage HTML for per-line form coverage, including .bb.html reports
  6. Applies CRAP formula: CC² × (1 - cov)³ + CC
  7. Sorts by CRAP score descending and prints report

Troubleshooting

  • Cloverage fails to run: Verify :cov alias paths match your project layout — -p should point to your source root and -s to your test root.
  • All coverage shows 0%: Ensure clj -M:cov runs successfully on its own before running :crap. Check that test files are found under the specified test path.
  • Functions show N/A coverage: This occurs with split-file namespace patterns (in-ns + load). Add --lcov to your :cov alias main-opts for accurate per-file coverage.
  • A tested doseq/for body shows ~50% forms (N out of 2N in the HTML): Cloverage instrumented both copies of the body. That is a rewriter bug, not missing tests. Re-run with --doseq-double-count to confirm the fingerprint and recount. Do not leave that flag on by default; it needs HTML form counts, not LCOV-only.

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Crap4clj」では何ができますか?

Calculates cyclomatic complexity and CRAP scores for Clojure and Babashka functions by combining complexity analysis with test coverage data, generating sorted reports that identify high-risk under-tested code. Use when the user asks for a CRAP report, cyclomatic complexity analysis, or code quality metrics on a Clojure or Babashka project.

TypingMindでCrap4cljを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Crap4cljはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにCrap4cljをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/unclebob/crap4clj/tree/masterを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Crap4cljを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Crap4cljは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもCrap4cljを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Crap4clj」は無料ですか?

unclebobがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇