DEV Community

Cover image for ๐Ÿ”ฌ Copilot Autopsy: AI-Powered Repository Forensics

๐Ÿ”ฌ Copilot Autopsy: AI-Powered Repository Forensics

GitHub Copilot CLI Challenge Submission

This is a submission for the GitHub Copilot CLI Challenge

What I Built

Copilot Autopsy is a terminal-first forensic analysis tool that performs deep "autopsies" of any GitHub repository using GitHub Copilot CLI as the AI reasoning engine.

๐Ÿ’ก Unlike traditional linters that just list problems, Copilot Autopsy explains WHY issues existโ€”powered entirely by GitHub Copilot CLI.

โœจ The Problem It Solves

Developers run linters and get a list like:

โŒ "Function too long"         โ†’ But WHY?
โŒ "Possible SQL injection"    โ†’ But HOW do I fix it?
โŒ "Missing tests"             โ†’ But WHICH functions first?
Enter fullscreen mode Exit fullscreen mode

Copilot Autopsy fixes this with AI-powered context:

โœ… Explains the ROOT CAUSE of each issue
โœ… Provides CONTEXT-AWARE fixes with code examples  
โœ… Prioritizes findings by SEVERITY and IMPACT
โœ… Generates a beautiful AUTOPSY.md report
Enter fullscreen mode Exit fullscreen mode

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         COPILOT AUTOPSY CLI                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚  โ”‚ Scanner  โ”‚โ”€โ”€โ–ถโ”‚ Analyzer โ”‚โ”€โ”€โ–ถโ”‚Aggregatorโ”‚โ”€โ”€โ–ถโ”‚ Reporter โ”‚        โ”‚
โ”‚  โ”‚  Module  โ”‚   โ”‚  Module  โ”‚   โ”‚  Module  โ”‚   โ”‚  Module  โ”‚        โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚       โ”‚              โ”‚                              โ”‚               โ”‚
โ”‚       โ–ผ              โ–ผ                              โ–ผ               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚  โ”‚  Detect  โ”‚   โ”‚  GitHub  โ”‚                  โ”‚ AUTOPSY  โ”‚        โ”‚
โ”‚  โ”‚ Language โ”‚   โ”‚  Copilot โ”‚                  โ”‚   .md    โ”‚        โ”‚
โ”‚  โ”‚Framework โ”‚   โ”‚  CLI โญ  โ”‚                  โ”‚  Report  โ”‚        โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚                                                                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“ Project Structure

copilot-autopsy/
โ”œโ”€โ”€ ๐Ÿ“„ bin/
โ”‚   โ””โ”€โ”€ copilot-autopsy.js      # CLI entry point
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”œโ”€โ”€ cli.js                  # Commander.js setup
โ”‚   โ”œโ”€โ”€ index.js                # Main orchestrator
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ ui/                  # Terminal UI components
โ”‚   โ”‚   โ”œโ”€โ”€ banner.js           # ASCII art banner
โ”‚   โ”‚   โ””โ”€โ”€ progress.js         # Progress bars & summary
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ scanner/             # Project detection
โ”‚   โ”‚   โ”œโ”€โ”€ index.js            # Scanner orchestrator
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ detectors/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ language.js     # Language detection
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ framework.js    # Framework detection
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tooling.js      # Tooling detection
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ collectors/
โ”‚   โ”‚       โ”œโ”€โ”€ files.js        # Smart file prioritization
โ”‚   โ”‚       โ””โ”€โ”€ dependencies.js # Dependency parser
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ analyzer/            # ๐ŸŒŸ AI analysis engine
โ”‚   โ”‚   โ”œโ”€โ”€ index.js            # Analyzer orchestrator
โ”‚   โ”‚   โ”œโ”€โ”€ copilot.js          # GitHub Copilot CLI wrapper
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ prompts/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ templates.js    # 6 specialized prompts
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ analyzers/
โ”‚   โ”‚       โ”œโ”€โ”€ quality.js      # Code quality analyzer
โ”‚   โ”‚       โ”œโ”€โ”€ security.js     # Security analyzer (CWE)
โ”‚   โ”‚       โ”œโ”€โ”€ architecture.js # Architecture analyzer
โ”‚   โ”‚       โ”œโ”€โ”€ testing.js      # Test gap analyzer
โ”‚   โ”‚       โ””โ”€โ”€ documentation.js# Documentation analyzer
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ aggregator/
โ”‚   โ”‚   โ””โ”€โ”€ index.js            # Deduplication & scoring
โ”‚   โ””โ”€โ”€ ๐Ÿ“ reporter/
โ”‚       โ””โ”€โ”€ index.js            # AUTOPSY.md generator
โ”œโ”€โ”€ ๐Ÿ“„ package.json
โ””โ”€โ”€ ๐Ÿ“„ README.md
Enter fullscreen mode Exit fullscreen mode

๐ŸŽฏ Features

Feature Description
๐Ÿ” Auto-Detection Detects language, framework, tooling automatically
๐Ÿ“ Code Quality Finds code smells, SOLID violations, complexity
๐Ÿ”’ Security Vulnerabilities with CWE references
๐Ÿ—๏ธ Architecture Circular dependencies, coupling issues
๐Ÿงช Testing Missing tests, coverage gaps
๐Ÿ“š Documentation README and JSDoc analysis
๐Ÿ“Š Health Score 0-100 score with visualization
๐Ÿ“‹ Report Beautiful AUTOPSY.md with action items
๐ŸŽจ Beautiful UI ASCII art, progress bars, colors

๐ŸŽฌ Demo

Installation

1. Install GitHub CLI

macOS:

brew install gh
Enter fullscreen mode Exit fullscreen mode

Linux (Debian/Ubuntu):

sudo apt install gh
Enter fullscreen mode Exit fullscreen mode

Windows (choose one):

# Option 1: winget
winget install --id GitHub.cli

# Option 2: Chocolatey
choco install gh

# Option 3: Scoop
scoop install gh

# Option 4: Download from https://cli.github.com/
Enter fullscreen mode Exit fullscreen mode

2. Setup Copilot CLI

โš ๏ธ IMPORTANT: GitHub CLI and Copilot CLI are separate. You must install Copilot as an extension!

# Login to GitHub
gh auth login

# Verify login
gh auth status

# Install Copilot CLI extension
gh extension install github/gh-copilot
Enter fullscreen mode Exit fullscreen mode

Windows users: When installing Copilot, you'll see:

? Authenticate Git with your GitHub credentials? (Y/n) y
! First copy your one-time code: XXXX-XXXX
Press Enter to open browser...
โœ“ Authentication complete.
Enter fullscreen mode Exit fullscreen mode
# Verify Copilot works
gh copilot -p "test"
Enter fullscreen mode Exit fullscreen mode

3. Install Copilot Autopsy

# Clone the repository
git clone https://github.com/xdarwin13/copilot-autopsy.git
cd copilot-autopsy

# Install dependencies
npm install

# Install globally
npm install -g .

# Run on any repo!
autopsy
Enter fullscreen mode Exit fullscreen mode

Terminal Output

   ____            _ _       _      _         _                        
  / ___|___  _ __ (_) | ___ | |_   / \  _   _| |_ ___  _ __  ___ _   _ 
 | |   / _ \| '_ \| | |/ _ \| __| / _ \| | | | __/ _ \| '_ \/ __| | | |
 | |__| (_) | |_) | | | (_) | |_ / ___ \ |_| | || (_) | |_) \__ \ |_| |
  \____\___/| .__/|_|_|\___/ \__/_/   \_\__,_|\__\___/| .__/|___/\__, |
            |_|                                       |_|        |___/ 

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  ๐Ÿ”ฌ Repository Forensics โ€ข Powered by GitHub Copilot CLI  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ“Š PROJECT DETECTION
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โœ“ Language: TypeScript (78%), JavaScript (22%)
โœ“ Framework: Next.js + React
โœ“ Tooling: ESLint, Prettier, Jest, GitHub Actions
โœ“ Files: 142 total (47 source)

๐Ÿค– COPILOT ANALYSIS
   Powered by GitHub Copilot CLI

โœ“ ๐Ÿ“ Code Quality: 5 findings
โœ“ ๐Ÿ”’ Security: 2 findings
โœ“ ๐Ÿ—๏ธ Architecture: 3 findings
โœ“ ๐Ÿงช Testing: 4 findings
โœ“ ๐Ÿ“š Documentation: 2 findings

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                โ”‚
โ”‚   ๐Ÿ“‹ AUTOPSY COMPLETE          โ”‚
โ”‚                                โ”‚
โ”‚   Health Score: 72/100         โ”‚
โ”‚   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  72%    โ”‚
โ”‚                                โ”‚
โ”‚   ๐Ÿ”ด Critical: 1   ๐ŸŸ  High: 3  โ”‚
โ”‚   ๐ŸŸก Medium: 8     ๐ŸŸข Low: 4   โ”‚
โ”‚                                โ”‚
โ”‚   Duration: 45.2s              โ”‚
โ”‚   Copilot CLI calls: 18        โ”‚
โ”‚                                โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Enter fullscreen mode Exit fullscreen mode

Sample AUTOPSY.md Report

# ๐Ÿ”ฌ Repository Autopsy Report

## ๐Ÿ“Š Executive Summary

| Metric | Value |
|--------|-------|
| **Repository** | `my-project` |
| **Primary Language** | TypeScript |
| **Framework** | Next.js |
| **Health Score** | 72/100 |

### Health Score: 72/100
โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  72%

## ๐Ÿ” Detailed Findings

### ๐Ÿ”’ Security Vulnerabilities

#### SEC-001: SQL Injection Risk

| Property | Value |
|----------|-------|
| **Severity** | ๐Ÿ”ด CRITICAL |
| **Location** | `src/api/users.ts:45` |

**Description:**
User input is directly concatenated into SQL query.

**Why This Matters:**
Attackers can manipulate the query to access or delete data.

**Suggested Fix:**
Use parameterized queries or an ORM.
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”ง CLI Options

Option Description Default
--depth quick, standard, deep standard
--focus security, quality, architecture, testing, docs, all all
--path Target repository path .
--output Output file name AUTOPSY.md
--verbose Show Copilot CLI calls false
--fix Include code fix examples false

๐Ÿ’ก My Experience with GitHub Copilot CLI

The Core Integration

GitHub Copilot CLI is the brain of this project. Without it, Copilot Autopsy would have zero intelligence.

// src/analyzer/copilot.js - The heart of the tool

class CopilotCLI {
  async query(prompt) {
    // Send prompt to GitHub Copilot CLI
    const result = execSync(
      `gh copilot -p ${JSON.stringify(prompt)}`,
      { encoding: 'utf-8', timeout: 120000 }
    );

    return this.parseResponse(result);
  }
}
Enter fullscreen mode Exit fullscreen mode

Prompt Engineering

I designed 6 specialized prompts for different analysis types:

// Quality Analysis Prompt
const QUALITY_PROMPT = `
You are a senior code reviewer performing forensic analysis.

FILE: ${file.path}
\`\`\`${language}
${content}
\`\`\`

Analyze for:
1. Code smells (long methods, deep nesting)
2. SOLID violations
3. DRY violations
4. Complexity issues

For EACH issue, respond:
[QUAL-NNN] SEVERITY | LINE | Description | Why | Fix
`;
Enter fullscreen mode Exit fullscreen mode

The "Why" Analysis - Unique Feature

What makes Copilot Autopsy special is the root cause analysis:

// Root Cause Prompt
const ROOT_CAUSE_PROMPT = `
Explain WHY this code issue exists, not just WHAT it is.

FINDING: ${finding.description}
CODE: ${codeContext}

Explain in 2-3 sentences:
1. The likely reason this was introduced
2. The technical debt it creates
3. The fix priority
`;
Enter fullscreen mode Exit fullscreen mode

This gives developers context instead of just a list of problems.

Orchestration Strategy

I orchestrate 15-20 Copilot CLI calls into one coherent report:

Phase 1 (Parallel):     Phase 2:          Phase 3:          Phase 4:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Quality     โ”‚         โ”‚Architecture โ”‚   โ”‚ Root Cause  โ”‚   โ”‚   Report    โ”‚
โ”‚ Security    โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚  Analysis   โ”‚โ”€โ”€โ–ถโ”‚  Analysis   โ”‚โ”€โ”€โ–ถโ”‚ Generation  โ”‚
โ”‚ Docs        โ”‚         โ”‚             โ”‚   โ”‚ (critical)  โ”‚   โ”‚             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Enter fullscreen mode Exit fullscreen mode

What I Learned

  1. Copilot CLI handles complex prompts well - Even 2000+ character prompts work
  2. Rate limiting is important - Added 1.5s delays between calls
  3. Response parsing requires creativity - Structured prompts help
  4. The -p flag is powerful - Use gh copilot -p "prompt" for non-interactive mode

๐Ÿ† Why This Project?

  1. Linters tell you WHAT, not WHY - Copilot CLI adds context
  2. Code reviews are time-consuming - Automate the first pass
  3. Security scanning is often shallow - AI understands intent
  4. Onboarding is hard - Health Score gives quick overview

๐Ÿ“ฆ Tech Stack

Component Technology
Runtime Node.js 18+
CLI Framework Commander.js
Terminal UI Chalk, Ora, Boxen
AI Engine GitHub Copilot CLI โญ
Templating Handlebars

๐Ÿ”— Links


๐Ÿ™ Acknowledgments

Built with โค๏ธ for the GitHub Copilot CLI Challenge 2026

Special thanks to the GitHub Copilot team for creating such a powerful CLI tool!


โญ If you found this useful, give it a star on GitHub! โญ

Top comments (0)