DEV Community

Cover image for Captain Hook: When Your AI Copilot Gets Promoted to Captain!

Captain Hook: When Your AI Copilot Gets Promoted to Captain!

GitHub Copilot CLI Challenge Submission

This is a submission for the GitHub Copilot CLI Challenge

What I Built

Ahoy, matey! πŸ΄β€β˜ οΈ Let me tell you a tale about Captain Hook – not the villain from Neverland, but the hero of your git repository!

You see, GitHub Copilot usually sits beside you as a friendly copilot, offering helpful suggestions. But what if your copilot got promoted to captain and started giving you orders? What if it didn't just suggest – it enforced?

That's exactly what I built: an intelligent git pre-commit hook that acts like a captain, commanding your code to ship-shape quality before it sets sail into your repository!

🎣 The Hook That Captains Your Code

Captain Hook is a git pre-commit hook with a personality problem (in the best way). It:

  • πŸ“‹ Linting (ruff check) - "Arr! Walk the plank, unused imports!"
  • 🎨 Formatting (ruff format) - "Straighten those lines, ye scurvy code!"
  • πŸ”Ž Type Checking (mypy) - "Where be yer type hints, sailor?"
  • πŸ§ͺ Tests (pytest) - "No code leaves port without passing inspection!"

βš“ From Copilot to Captain

Here's the twist that makes this project special:

Normal Copilot: "Hey, maybe you could fix this import?" 😊

Captain Hook: "HALT! Unused import detected! Removing it NOW!" πŸ’ͺ

Normal Copilot: "Consider adding type hints here..." πŸ€”

Captain Hook: "NO TYPE HINTS? Calling in backup! blows whistle GitHub Copilot CLI, report for duty!" 🎺

When Captain Hook encounters something it can't auto-fix (type errors, test failures), it doesn't just block your commit and walk away. Oh no! It calls in the GitHub Copilot CLI – think of it as calling in the Admiral for strategic advice!

πŸ΄β€β˜ οΈ Why "Captain Hook"?

Because this git hook acts like a captain:

  • Hook (git pre-commit mechanism) β†’ Technical term
  • Captain (commands and enforces) β†’ How it behaves
  • Captain Hook β†’ The perfect nautical pun! 🎣

Plus, just like the infamous Captain Hook, this tool:

  • βœ… Never lets Peter Pan (bad code) escape
  • βœ… Has a trusty sidekick (GitHub Copilot CLI)
  • βœ… Commands the crew (QA tools) with authority
  • βœ… Protects the ship (your repository) fiercely

🚒 What It Means to Me

As developers, we often treat CI/CD and code quality tools as annoying gatekeepers – the grumpy pirates who say "NO!" to everything. But what if they were more like a wise captain who:

  • Fixes what can be fixed automatically (80% of issues)
  • Teaches you how to fix complex problems (using AI)
  • Keeps the ship running smoothly (maintains quality)
  • Actually makes your life easier, not harder

Captain Hook represents a shift from "code quality as punishment" to "code quality as a helpful mentor with a sense of humor and a pirate hat."

Demo

πŸ”— Live Repository: https://github.com/thec0dewriter/captain_hook.git

πŸ—ΊοΈ Project Repository Structure:

captain_hook/
β”œβ”€β”€ src/captain_hook/         # The treasure (Python library code)
β”œβ”€β”€ tests/                    # Quality inspection (100% coverage)
β”œβ”€β”€ hooks/                    # The Captain's quarters! βš“
β”‚   β”œβ”€β”€ pre-commit           # Captain Hook himself
β”‚   β”œβ”€β”€ install.sh           # Recruit the captain
β”‚   β”œβ”€β”€ demo.sh              # Training exercises
β”‚   └── README.md            # Captain's orders
β”œβ”€β”€ submission.md            # This very tale!
β”œβ”€β”€ HOOK_SUMMARY.md          # The Captain's log
└── README.md                # Ship's manifest
Enter fullscreen mode Exit fullscreen mode

βš“ Captain Hook in Action:

Example 1: The Captain Takes Command πŸ’ͺ

Picture this: You try to commit some messy code...

$ git commit -m "Add new feature"

πŸ” Running pre-commit QA checks...

πŸ“‹ Step 1/4: Linting (ruff check)
βœ— Linting failed
  - Found unused imports: os, sys, json
  - Missing spaces around operators

βš“ "AVAST, YE SCURVY CODE!" - Captain Hook

Attempting auto-fix with ruff...
βœ“ Auto-fixed linting issues
βœ“ Unused imports walked the plank!
βœ“ Spaces restored to their rightful place!
Staging auto-fixed files...

🎨 Step 2/4: Format checking (ruff format)
βœ— Format check failed

βš“ "This code be messier than a pirate's beard!"

Auto-formatting files...
βœ“ Files formatted
βœ“ Your code now looks shipshape!
Staging formatted files...

πŸ”Ž Step 3/4: Type checking (mypy)
βœ“ Type checking passed

βš“ "Good! Proper type hints, as any respectable sailor knows!"

πŸ§ͺ Step 4/4: Running tests (pytest)
βœ“ Tests passed

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
βœ… All pre-commit checks PASSED
βš“ "Permission granted! Your code may set sail!"
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Enter fullscreen mode Exit fullscreen mode

Example 2: When the Captain Calls for Backup 🎺

Sometimes even captains need help from the admiral...

$ git commit -m "Add calculator"

πŸ” Running pre-commit QA checks...

πŸ“‹ Step 1/4: Linting (ruff check)
βœ“ Linting passed

🎨 Step 2/4: Format checking (ruff format)
βœ“ Format check passed

πŸ”Ž Step 3/4: Type checking (mypy)
βœ— Type checking failed
src/calculator.py:4: error: Function is missing a type annotation

βš“ "Blimey! Missing type hints be beyond me fixing powers!"
βš“ "Calling in the ADMIRAL for strategic advice!"

⚠️ Attempting auto-fix with GitHub Copilot CLI...

🎺 *Admiral GitHub Copilot CLI reports for duty*

πŸ’‘ Copilot suggests:
   "Add type annotations to function parameters and return type:

    def calculate(a: float, b: float) -> float:
        return a + b"

βš“ "There ye have it! Follow the Admiral's orders, sailor!"

Tips:
  - Apply the Admiral's wisdom (Copilot's suggestion)
  - Run 'make check' to verify
  - Try committing again
Enter fullscreen mode Exit fullscreen mode

πŸ΄β€β˜ οΈ Real Voyage Testing

The Captain was battle-tested with intentionally broken code:

Challenge Captain's Response Outcome
Unused imports (3x) "Walk the plank!" βœ… Auto-removed
Bad spacing x,y "Mind yer spaces!" βœ… Fixed to x, y
Messy formatting "Swab the deck!" βœ… Auto-formatted
Missing type hints "Call the Admiral!" βœ… Copilot suggested fix
Code ready to commit "Set sail!" βœ… Smooth sailing

πŸ—ΊοΈ Quick Start: Recruit Your Captain

# Clone the ship
git clone https://github.com/thec0dewriter/captain_hook.git
cd captain_hook

# Stock the supplies (install dependencies)
make install

# Recruit Captain Hook to your crew
make install-hooks

# Make a change and try to commit
echo "import os" >> src/captain_hook/calculator.py
git add .
git commit -m "Test the Captain"

# Watch Captain Hook spring into action! 🎣
Enter fullscreen mode Exit fullscreen mode

Working screenshot

My Experience with GitHub Copilot CLI

🎭 The Plot Twist: From Copilot to Captain

When I started this project, I thought I was building a simple pre-commit hook. But something magical happened: the copilot became the captain.

Here's how GitHub Copilot CLI transformed this project:

1️⃣ The Captain's Wisdom: Intelligent Error Resolution

Before Copilot CLI:

Error: Function missing type annotation
*stares at screen*
*Googles "python type hints"*
*reads docs for 10 minutes*
*tries something*
*fails*
*repeats*
Enter fullscreen mode Exit fullscreen mode

With Captain Hook + Copilot CLI:

βš“ "Type hints be missing! Calling the Admiral!"
πŸ’‘ Copilot: "Add type hints like this: def foo(x: int) -> int:"
βœ… "Brilliant! Fixed in 30 seconds!"
Enter fullscreen mode Exit fullscreen mode

It's like having a ship's navigator who actually knows where you're going instead of just pointing at the horizon!

2️⃣ Building the Captain: Meta-Development

The beautiful irony? I used GitHub Copilot CLI to build a tool that uses GitHub Copilot CLI!

Inception moment:

  • Used Copilot to write the hook
  • The hook calls Copilot CLI for help
  • It's copilots all the way down! 🎭

Copilot helped me:

  • Scaffold the entire git hook structure
  • Write robust bash error handling
  • Design the captain personality (yes, the pirate puns!)
  • Generate comprehensive documentation
  • Create engaging demo scenarios

3️⃣ The Admiral's Strategy: Learning Through Collaboration

Working with Copilot CLI felt less like "using a tool" and more like pair programming with a pirate crew:

  • The Captain (my hook) β†’ Commands and enforces
  • The Admiral (Copilot CLI) β†’ Provides strategic advice
  • The Crew (ruff, mypy, pytest) β†’ Do the actual work
  • Me (the developer) β†’ Enjoys smooth sailing! β›΅

Best part? When Captain Hook calls Copilot CLI, it's not just showing error messages – it's providing contextual wisdom based on the actual code and error.

4️⃣ Real-World Impact: The 80/20 Rule of Joy

Here's the magic formula Captain Hook delivers:

  • 80% of problems: Auto-fixed instantly (bye bye, formatting fights!)
  • 20% of problems: Copilot CLI teaches you the solution
  • 100% of the time: You stay in flow state 🌊

Old workflow:

Write code β†’ Commit β†’ CI fails β†’ Context switch β†’ Google β†’ Fix β†’ Repeat
😀 Frustration level: High
Enter fullscreen mode Exit fullscreen mode

Captain Hook workflow:

Write code β†’ Commit attempt β†’ Captain fixes most issues β†’ 
Copilot teaches remaining fixes β†’ Commit succeeds
😊 Frustration level: "What frustration?"
Enter fullscreen mode Exit fullscreen mode

5️⃣ The Joke That Became Real

Started as: "Haha, what if git hooks had personality?"

Became: "Wait, this is actually the future of developer experience!"

The Captain Hook name started as a pun but revealed a deeper truth:

  • Copilots suggest (helpful but passive)
  • Captains command (authoritative but caring)
  • The best tools do both! 🎯

🎬 Key Takeaway: It's About the Journey

GitHub Copilot CLI isn't just "AI that writes code faster." It's:

✨ A teaching tool that explains why fixes work
🚒 A workflow enhancer that keeps you sailing smoothly

🎣 A captain that catches problems before they cause shipwrecks
πŸ’‘ A collaboration partner that makes coding more fun

Captain Hook proves that AI in development isn't about replacing developers – it's about promoting your helpful copilot to a wise captain who still lets you steer the ship!


🎯 Technologies Used:

  • Python 3.9+ with UV package manager (fastest ship in the fleet!)
  • Ruff (linting & formatting) (the ship's cleaning crew)
  • Mypy (type checking) (the quality inspector)
  • Pytest (testing with coverage) (safety drills)
  • Bash scripting (the ship's machinery)
  • Git hooks (the captain's perch)
  • GitHub Copilot CLI (the wise admiral) πŸŽ–οΈ

πŸ“‹ Current Status & Future Voyages

βœ… What's Shipshape:

  • Intelligent pre-commit hook with auto-fix
  • GitHub Copilot CLI integration
  • 100% test coverage (8 passing tests)
  • Comprehensive documentation
  • Real-world testing completed

🚧 Potential Future Adventures (TODOs):

  • [ ] Add more "captain personality" responses for different error types
  • [ ] Support for commit-msg hook (Captain checks your commit messages!)
  • [ ] Integration with more language ecosystems (TypeScript, Go, Rust)
  • [ ] "Parrot mode" - hook verbosity level (quiet parrot vs. chatty parrot 🦜)
  • [ ] Collectible "achievements" when you fix issues
  • [ ] Ship's log (detailed commit history with captain's commentary)

Try it yourself:

git clone https://github.com/thec0dewriter/captain_hook.git
cd captain_hook
make install
make install-hooks

# Let Captain Hook command your code to quality! βš“
Enter fullscreen mode Exit fullscreen mode

Built with ❀️ (and lots of pirate puns) for the GitHub Copilot CLI Challenge

"Not all those who wander are lost, but all code that wanders needs a captain!" πŸŽ£βš“

Top comments (0)