mcpField
P
prompt-analysis

prompt-analysis

github.com/git-ai-projectデータ・データベース2.9k79 回インストール1 週間前に更新
リポジトリ

prompt-analysis について

Git AI が記録した AI コーディングのプロンプトを、ローカルの SQLite データベースで分析するスキルです。SQL による集計と、内容・採用率・明確さ・繰り返し現れる作業パターンの個別分析に対応します。

主な機能

  1. 01prompts.db の初期化と照会
  2. 02作者や期間による絞り込み
  3. 03SQL による指標の集計
  4. 04プロンプトメッセージの個別分析
  5. 05採用率と属性の比較

活用シーン

  1. 01モデル別の採用率を比較
  2. 02コーディングタスクごとにプロンプトを分類
  3. 03採用率の低いプロンプトを調査
  4. 04再利用できるプロンプトパターンを発見

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/git-ai-project/git-ai --skill prompt-analysis

インストール後、Claude Code で/prompt-analysisを入力して読み込まれたか確認します。

詳細

プロンプト分析スキル

ローカルの prompts.db SQLite データベースを使って、AI プロンプトのパターンを分析します。

Git AI とは?

Git AI は、AI が生成したコードとプロンプトを git で追跡するツールです。次の情報を保存します。

  • AI とのすべての会話(プロンプトと応答)
  • どのコード行が AI によるものか、人間による編集か
  • 採用率(AI が生成したコードのうち、どれだけが維持され、どれだけが変更されたか)
  • 関連するコミットと作成者

このスキルはこのデータを照会し、ユーザーが自身の AI コーディングパターンを把握できるようにします。

初期化

まず、ユーザーの質問から対象範囲を判断します。

ユーザーの言及使用するフラグ
「自分のプロンプト」または指定なし(デフォルト — 現在のユーザー、現在のリポジトリ)
「チーム」、「全員」、「すべての作成者」--all-authors
特定の人の名前--author "<name>"
特定の期間--since <days>(デフォルト:30)

検出対象はメモのみです。git-ai prompts は常に現在のリポジトリで動作します(作業ディレクトリが git リポジトリ内にある必要があります)。複数のリポジトリを分析するには、それぞれでコマンドを実行してください。

初期化を実行します。

git-ai prompts [flags]

これにより、現在のディレクトリに prompts.db が作成または更新されます。

スキーマリファレンス

prompts テーブルには次の項目が含まれます。

  • seq_id - 反復処理用の自動採番 ID
  • id - 一意のプロンプト識別子
  • tool - 使用したツール(例:「claude-code」、「cursor」)
  • model - モデル名(例:「claude-sonnet-4-20250514」)
  • human_author - プロンプトを作成した Git ユーザー
  • commit_sha - 関連するコミット(該当する場合)
  • total_additions、total_deletions - 変更されたコード行数
  • accepted_lines、overridden_lines - 維持された行数と人間が変更した行数
  • accepted_rate - 比率:採用行数 /(採用行数 + 変更行数)
  • messages - 会話の JSON 配列
  • start_time、last_time - Unix タイムスタンプ

分析方法

集計に関する質問(指標、比較)の場合

SQL クエリを直接使用します。

git-ai prompts exec "SELECT model, AVG(accepted_rate), COUNT(*) FROM prompts GROUP BY model"
プロンプトごとの分析(分類、内容分析)の場合

各プロンプトの内容(messages JSON)を確認する必要がある質問には、サブエージェントを使用します。

  1. 分析用の列をスキーマに追加します。
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN work_type TEXT"
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN analysis_notes TEXT"
  1. 反復処理ポインターをリセットします。
git-ai prompts reset
  1. サブエージェントで反復処理します - Task ツールを使い、subagent_type: "general-purpose" を指定して並列サブエージェントを起動します。各サブエージェントは次の処理を行います。

    • git-ai prompts next を実行して、プロンプトを 1 件 JSON 形式で取得する
    • messages の内容を分析する
    • データベースを更新する:git-ai prompts exec "UPDATE prompts SET work_type='...' WHERE id='...'"
  2. 最終的な統合 - 拡充したデータを照会します。

git-ai prompts exec "SELECT work_type, COUNT(*), AVG(accepted_rate) FROM prompts GROUP BY work_type"

反復処理におけるサブエージェントのパターン

プロンプトを個別に処理する場合は、複数のサブエージェントを並列で起動します。各サブエージェントへのプロンプトには、次の内容を含めてください。

Run `git-ai prompts next` to get the next prompt.

Analyze the messages JSON to determine: [specific analysis task]

Then update the database:
git-ai prompts exec "UPDATE prompts SET [column]='[value]' WHERE id='[prompt_id]'"

Return your analysis result.

一度に 3~5 個のサブエージェントを起動し、結果を確認してから、git-ai prompts next が「No more prompts」を返すまで追加で起動します。

重要: git-ai prompts next コマンドは、分析に必要なすべてのデータを JSON で返します。以下が含まれます。

  • 完全な会話(人間のプロンプトと AI の応答)を含む messages 配列全体
  • model、tool、accepted_rate、accepted_lines などのメタデータ

サブエージェントは、git show や git log のような追加コマンドを実行してはいけません。必要な情報はすべて git-ai prompts next の JSON 出力に含まれています。サブエージェントには、次のように明示してください。

IMPORTANT: All data you need is in the JSON output from `git-ai prompts next`.
Do NOT run git commands. Analyze the `messages` field in the JSON directly.

イテレーターの例

例 1:作業タイプごとにプロンプトを分類する

ユーザーの質問:「自分のプロンプトを作業タイプ(バグ修正、機能追加、リファクタリング、ドキュメント)ごとに分類してください」

セットアップ:

git-ai prompts exec "ALTER TABLE prompts ADD COLUMN work_type TEXT"
git-ai prompts reset

サブエージェントへのプロンプト:

Run `git-ai prompts next` to get the next prompt as JSON.

IMPORTANT: All data you need is in this JSON output. Do NOT run git commands.
Analyze the `messages` field directly.

Read the messages JSON and categorize this prompt into ONE of:
- "bug_fix" - fixing broken behavior, errors, or regressions
- "feature" - adding new functionality
- "refactor" - restructuring code without changing behavior
- "docs" - documentation, comments, READMEs
- "test" - adding or modifying tests
- "config" - configuration, build, CI/CD changes
- "other" - doesn't fit above categories

Update the database:
git-ai prompts exec "UPDATE prompts SET work_type='<category>' WHERE id='<prompt_id>'"

Return: the prompt id, your categorization, and a one-sentence reason.

統合クエリ:

SELECT work_type, COUNT(*) as count,
       ROUND(AVG(accepted_rate), 3) as avg_acceptance,
       SUM(accepted_lines) as total_lines
FROM prompts
WHERE work_type IS NOT NULL
GROUP BY work_type
ORDER BY count DESC
例 2:プロンプトの採用率が低かった理由を分析する

ユーザーの質問:「採用率が低いプロンプトがあるのはなぜですか?」

セットアップ:

git-ai prompts exec "ALTER TABLE prompts ADD COLUMN low_acceptance_reason TEXT"
git-ai prompts exec "UPDATE pointers SET current_seq_id = (SELECT MIN(seq_id) - 1 FROM prompts WHERE accepted_rate < 0.5 AND accepted_rate IS NOT NULL)"

サブエージェントへのプロンプト:

Run `git-ai prompts next` to get the next prompt as JSON.

IMPORTANT: All data you need is in this JSON output. Do NOT run git commands.
Analyze the `messages` field directly.

This prompt had a low acceptance rate (human modified most of the AI's code).
Analyze the messages JSON and identify the likely reason:
- "vague_request" - the prompt was unclear or underspecified
- "wrong_approach" - AI took a fundamentally wrong approach
- "style_mismatch" - code worked but didn't match project conventions
- "partial_solution" - AI only solved part of the problem
- "overengineered" - AI added unnecessary complexity
- "context_missing" - AI lacked necessary context about the codebase
- "other" - explain briefly

Update the database:
git-ai prompts exec "UPDATE prompts SET low_acceptance_reason='<reason>' WHERE id='<prompt_id>'"

Return: prompt id, the reason, and specific evidence from the conversation.
例 3:再利用可能なパターンにできるプロンプトを特定する

ユーザーの質問:「自分が直面する可能性のある問題を解決したプロンプトはどれですか?」

セットアップ:

git-ai prompts exec "ALTER TABLE prompts ADD COLUMN reusable_pattern TEXT"
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN pattern_description TEXT"
git-ai prompts reset

サブエージェントへのプロンプト:

Run `git-ai prompts next` to get the next prompt as JSON.

IMPORTANT: All data you need is in this JSON output. Do NOT run git commands.
Analyze the `messages` field directly.

Analyze whether this prompt represents a reusable pattern worth saving:
- Look for: common coding tasks, useful abstractions, clever solutions
- Skip: one-off fixes, highly context-specific changes, trivial edits

If reusable, set reusable_pattern to a short name (e.g., "api_error_handling", "form_validation", "test_mocking")
and pattern_description to a one-sentence description of what it does.

If not reusable, set both to NULL.

git-ai prompts exec "UPDATE prompts SET reusable_pattern='<name>', pattern_description='<desc>' WHERE id='<prompt_id>'"

Return: prompt id and whether you marked it as reusable (with the pattern name if yes).
例 4:プロンプトの品質/明確さを評価する

ユーザーの質問:「私のプロンプトはどれくらい明確ですか? もっと良く書けたプロンプトはどれですか?」

セットアップ:

git-ai prompts exec "ALTER TABLE prompts ADD COLUMN clarity_score INTEGER"
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN clarity_feedback TEXT"
git-ai prompts reset

サブエージェントへのプロンプト:

Run `git-ai prompts next` to get the next prompt as JSON.

IMPORTANT: All data you need is in this JSON output. Do NOT run git commands.
Analyze the `messages` field directly.

Score the HUMAN's prompt clarity from 1-5:
5 = Crystal clear: specific goal, context provided, constraints stated
4 = Good: clear intent, minor ambiguities
3 = Adequate: understandable but missing helpful context
2 = Vague: required AI to make significant assumptions
1 = Unclear: AI had to guess what was wanted

Also provide brief feedback on how the prompt could be improved.

git-ai prompts exec "UPDATE prompts SET clarity_score=<1-5>, clarity_feedback='<feedback>' WHERE id='<prompt_id>'"

Return: prompt id, score, and your feedback.

統合クエリ:

SELECT clarity_score, COUNT(*) as count,
       ROUND(AVG(accepted_rate), 3) as avg_acceptance
FROM prompts
WHERE clarity_score IS NOT NULL
GROUP BY clarity_score
ORDER BY clarity_score DESC
例 5:プロンプト手法と受け入れ率の相関を調べる

ユーザーの質問:「私のプロンプト手法と受け入れ率の相関を調べてください」

セットアップ:

git-ai prompts exec "ALTER TABLE prompts ADD COLUMN technique TEXT"
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN technique_notes TEXT"
git-ai prompts reset

サブエージェントへのプロンプト:

Run `git-ai prompts next` to get the next prompt as JSON.

IMPORTANT: All data you need is in this JSON output. Do NOT run git commands.
Analyze the `messages` field directly.

Analyze the HUMAN's prompting technique in the messages. Identify which techniques were used:
- "example_driven" - provided examples of desired output or behavior
- "step_by_step" - broke down the request into steps or phases
- "context_heavy" - provided extensive background/context about the codebase
- "minimal" - terse, brief request with little context
- "iterative" - built up solution through back-and-forth refinement
- "constraint_focused" - emphasized what NOT to do or specific requirements
- "reference_based" - pointed to existing code/files to follow as patterns
- "multiple" - combined several techniques (list them in notes)

Also note any specific effective or ineffective patterns in technique_notes.

git-ai prompts exec "UPDATE prompts SET technique='<technique>', technique_notes='<notes>' WHERE id='<prompt_id>'"

Return: prompt id, technique identified, the acceptance_rate, and your observations.

統合クエリ:

SELECT technique,
       COUNT(*) as count,
       ROUND(AVG(accepted_rate), 3) as avg_acceptance,
       ROUND(MIN(accepted_rate), 3) as min_acceptance,
       ROUND(MAX(accepted_rate), 3) as max_acceptance
FROM prompts
WHERE technique IS NOT NULL AND accepted_rate IS NOT NULL
GROUP BY technique
ORDER BY avg_acceptance DESC
例 6:失敗したプロンプトの定性的分析

ユーザーの質問:「失敗したプロンプト(受け入れ数 0)を定性的に分析してください」

「失敗したプロンプト」の定義:

  • accepted_lines IS NULL - 会話は行われましたが、コードはコミットされていません
  • accepted_lines = 0 - コードは生成されましたが、人間がすべてを却下または書き直しました

セットアップ:

git-ai prompts exec "ALTER TABLE prompts ADD COLUMN failure_analysis TEXT"
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN failure_category TEXT"
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN improvement_suggestion TEXT"
-- Set pointer to iterate only over failed prompts
git-ai prompts exec "DELETE FROM pointers WHERE name='default'"
git-ai prompts exec "INSERT INTO pointers (name, current_seq_id) VALUES ('default', (SELECT MIN(seq_id) - 1 FROM prompts WHERE accepted_lines IS NULL OR accepted_lines = 0))"

サブエージェントへのプロンプト:

Run `git-ai prompts next` to get the next prompt as JSON.

IMPORTANT: All data you need is in this JSON output. Do NOT run git commands.
Analyze the `messages` field directly.

This prompt resulted in 0% acceptance - the human rejected or completely rewrote all AI-generated code.

Perform a qualitative analysis by reading the full conversation in messages JSON:

1. **What was requested?** Summarize the human's goal.
2. **What did the AI produce?** Summarize what code/solution was generated.
3. **Why did it fail?** Categorize into:
   - "misunderstood_intent" - AI solved the wrong problem
   - "poor_code_quality" - bugs, errors, or broken code
   - "wrong_technology" - used wrong framework/library/approach
   - "incomplete" - only partially addressed the request
   - "style_violation" - worked but violated project conventions
   - "overcomplicated" - solution far more complex than needed
   - "security_issue" - introduced vulnerabilities
   - "abandoned" - user changed direction mid-conversation

4. **How could the prompt be improved?** Specific, actionable suggestion.

git-ai prompts exec "UPDATE prompts SET failure_category='<category>', failure_analysis='<analysis>', improvement_suggestion='<suggestion>' WHERE id='<prompt_id>'"

Return a detailed analysis including: prompt id, what was requested, what went wrong, and how to prompt better next time.

統合:

SELECT failure_category,
       COUNT(*) as count,
       GROUP_CONCAT(id, ', ') as prompt_ids
FROM prompts
WHERE failure_category IS NOT NULL
GROUP BY failure_category
ORDER BY count DESC

次に、個々の failure_analysis と improvement_suggestion の値を確認し、得られた教訓をまとめます。

例 7:ベストプラクティスに基づいてプロンプトを採点する

ユーザーの質問:「ベストプラクティスに基づいて、私のプロンプトを採点してください」

セットアップ:

git-ai prompts exec "ALTER TABLE prompts ADD COLUMN grade TEXT"
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN grade_breakdown TEXT"
git-ai prompts exec "ALTER TABLE prompts ADD COLUMN grade_feedback TEXT"
git-ai prompts reset

サブエージェントへのプロンプト:

Run `git-ai prompts next` to get the next prompt as JSON.

IMPORTANT: All data you need is in this JSON output. Do NOT run git commands.
Analyze the `messages` field directly.

Grade the HUMAN's prompt against these best practices for AI-assisted coding:

**Grading Criteria (each worth 0-2 points):**

1. **Specificity (0-2)**: Does the prompt clearly state what needs to be done?
   - 0: Vague or ambiguous ("fix this", "make it better")
   - 1: General direction but missing details ("add validation")
   - 2: Specific outcome described ("add email validation that checks format and shows inline error")

2. **Context (0-2)**: Does the prompt provide necessary background?
   - 0: No context, assumes AI knows everything
   - 1: Some context but missing key details
   - 2: Relevant files, constraints, or project patterns mentioned

3. **Scope (0-2)**: Is the request appropriately sized?
   - 0: Too broad ("rewrite the app") or impossibly vague
   - 1: Large but manageable, could be broken down
   - 2: Focused, single-responsibility task

4. **Constraints (0-2)**: Are requirements and boundaries specified?
   - 0: No constraints given when they'd be helpful
   - 1: Some constraints but missing important ones
   - 2: Clear about what to do AND what not to do

5. **Testability (0-2)**: Can success be verified?
   - 0: No way to know if the result is correct
   - 1: Implicit success criteria
   - 2: Explicit expected behavior or acceptance criteria

**Calculate total (0-10) and assign grade:**
- A (9-10): Excellent prompt, follows best practices
- B (7-8): Good prompt, minor improvements possible
- C (5-6): Adequate prompt, notable gaps
- D (3-4): Poor prompt, significant issues
- F (0-2): Ineffective prompt, needs major revision

Store breakdown as JSON: {"specificity": X, "context": X, "scope": X, "constraints": X, "testability": X}

git-ai prompts exec "UPDATE prompts SET grade='<A-F>', grade_breakdown='<json>', grade_feedback='<specific feedback>' WHERE id='<prompt_id>'"

Return: prompt id, grade, total score, and one key improvement suggestion.

統合クエリ:

SELECT grade,
       COUNT(*) as count,
       ROUND(AVG(accepted_rate), 3) as avg_acceptance,
       SUM(accepted_lines) as total_lines_accepted
FROM prompts
WHERE grade IS NOT NULL AND accepted_rate IS NOT NULL
GROUP BY grade
ORDER BY grade

相関分析:

-- See if grade correlates with acceptance rate
SELECT
    grade,
    ROUND(AVG(accepted_rate), 3) as avg_acceptance,
    COUNT(*) as n
FROM prompts
WHERE grade IS NOT NULL AND accepted_rate IS NOT NULL
GROUP BY grade
ORDER BY
    CASE grade
        WHEN 'A' THEN 1
        WHEN 'B' THEN 2
        WHEN 'C' THEN 3
        WHEN 'D' THEN 4
        WHEN 'F' THEN 5
    END

クエリ例

モデル別の受け入れ率:

SELECT model,
       ROUND(AVG(accepted_rate), 3) as avg_rate,
       SUM(accepted_lines) as total_accepted,
       COUNT(*) as prompt_count
FROM prompts
GROUP BY model
ORDER BY avg_rate DESC

最も生産性の高いプロンプト(高い受け入れ率+高い LoC):

SELECT id, tool, model, accepted_lines, accepted_rate,
       (last_time - start_time) as duration_secs
FROM prompts
WHERE accepted_rate > 0.8 AND accepted_lines > 50
ORDER BY accepted_lines DESC
LIMIT 10

時間帯別のプロンプト:

SELECT
  CASE
    WHEN (start_time % 86400) / 3600 < 12 THEN 'morning'
    WHEN (start_time % 86400) / 3600 < 17 THEN 'afternoon'
    ELSE 'evening'
  END as time_of_day,
  COUNT(*) as count,
  AVG(accepted_rate) as avg_rate
FROM prompts
GROUP BY time_of_day

クリーンアップ

prompts.db ファイルは一時的なものです。いつでも削除して、最初からやり直せます:

rm prompts.db

トラブルシューティング

データベースにプロンプトが 0 件の場合: このリポジトリで Git AI が正しくセットアップされていない可能性があります。ユーザーに次のことを案内してください:

  • セットアップ手順を https://usegitai.com/docs/cli で確認する
  • git-ai がインストールされ、設定されていることを確認する
  • セットアップ後に AI の支援を受けてコミットしていることを確認する

重要:Git AI は今後のデータのみを追跡します。 Git AI は、インストール前のプロンプトを遡って分類したり追跡したりすることはできません。プロンプトデータが記録されるのは、Git AI のセットアップ後に行われたコミットのみです。Git AI を最近インストールした場合、AI の支援を受けたコミットが増えるまでは、利用できるデータが限られている可能性があります。

落とし穴とデータに関する注意点

すべてのプロンプトに統計情報やコミットがあるわけではありません:

  • プロンプトでの会話は行われたものの、コードがコミットされなかった場合、commit_sha は NULL です
  • コミットされていない作業では、accepted_lines、overridden_lines、accepted_rate が NULL または 0 になることがあります
  • 同じ理由で、total_additions、total_deletions が NULL になることがあります

このような状態になる理由:

  • ユーザーが会話をしたものの、コードを受け入れなかった
  • ユーザーがコードを受け入れたものの、コミットしなかった
  • ユーザーが引き続き作業中である(コードがまだコミットされていない)

「失敗したプロンプト」の定義: 失敗したプロンプトや成功しなかったプロンプトを分析する場合は、次の定義を使用してください:

  • accepted_lines IS NULL - 会話は行われましたが、コードはコミットされていません
  • accepted_lines = 0 - コードは生成されましたが、人間がすべてを却下または書き直しました

クエリ:WHERE accepted_lines IS NULL OR accepted_lines = 0

クエリでの処理:

-- Exclude uncommitted prompts from acceptance rate analysis
SELECT model, AVG(accepted_rate)
FROM prompts
WHERE commit_sha IS NOT NULL AND accepted_rate IS NOT NULL
GROUP BY model

-- Find prompts with conversation but no committed code
SELECT id, tool, start_time
FROM prompts
WHERE commit_sha IS NULL

重要な注意事項

  • messages 列には JSON が格納されています。会話の内容を読むには解析してください
  • メッセージ内容を読む必要がある分析には、サブエージェントを使用してください
  • SQLite はスクラッチパッドです。分析用の列は自由に追加してください
  • デフォルトの対象範囲は控えめです(現在のユーザー、現在のリポジトリ、過去 30 日間)
  • ユーザーがチームまたはすべてのリポジトリを明示的に指定した場合にのみ、対象範囲を広げてください

権限の設定

すべての git-ai コマンドで確認を求められないようにするには、プロジェクトまたはユーザーの設定に追加してください:

プロジェクト: .claude/settings.json ユーザー: ~/.claude/settings.json

{
  "permissions": {
    "allow": [
      "Bash(git-ai:*)"
    ]
  }
}

サブエージェントはスキルレベルの権限を引き継がないため、サブエージェントの反復処理では特に重要です。

コメント