Investigate bugs and create TDD fix plans in PLANS.md. Creates Linear issues in Todo state.
Git Pre-flight Check
Before doing anything else, verify git state:
- •Check current branch:
git branch --show-current - •If NOT on
mainormaster:- •STOP with message: "Not on main branch. Please switch to main before planning:
git checkout main"
- •STOP with message: "Not on main branch. Please switch to main before planning:
- •Check for uncommitted changes:
git status --porcelain - •If there are uncommitted changes:
- •STOP with message: "Main branch has uncommitted changes. Please commit or stash them first."
- •Check if branch is up-to-date with remote:
git fetch origin && git status -uno - •If behind remote:
- •STOP with message: "Main branch is behind remote. Please pull latest:
git pull origin main"
- •STOP with message: "Main branch is behind remote. Please pull latest:
Only proceed to PLANS.md check if git state is clean.
Purpose
- •Investigate bugs found after processing files (extraction errors, wrong data, missing matches)
- •Debug deployment failures using Railway MCP
- •Test and iterate Gemini prompts when extraction issues are suspected
- •Create investigation report documenting findings and root cause
- •Generate TDD-based fix plan in PLANS.md with Linear issue links
- •Create Linear issues in Todo state for each fix task
- •Does NOT implement fixes (integrates with plan-implement)
Pre-flight Check
Before doing anything, read PLANS.md and check if it contains incomplete work:
- •If PLANS.md has content but NO "Status: COMPLETE" at the end → STOP
- •Tell the user: "PLANS.md has incomplete work. Please review and clear it before planning new items."
- •Do not proceed.
If PLANS.md is empty or has "Status: COMPLETE" → proceed with investigation.
Arguments
$ARGUMENTS should contain the bug description with context:
- •What happened vs what was expected
- •File IDs if relevant (Google Drive file IDs)
- •Error messages or unexpected values
- •Deployment ID if it's a deployment issue
- •Any other context that helps investigation
Context Gathering
IMPORTANT: Do NOT hardcode MCP names or folder paths. Always read CLAUDE.md to discover:
- •
Available MCP servers - Look for "MCP SERVERS" section to find:
- •File/storage MCPs for accessing documents and data
- •Deployment MCPs for logs and service status
- •AI/LLM MCPs for prompt testing
- •
Project structure - Look for "STRUCTURE" or "FOLDER STRUCTURE" sections to understand:
- •Where source code and documents are stored
- •Naming conventions and organization
- •
Domain concepts - Look for sections describing:
- •Document types and their processing
- •Data schemas and formats
- •Business rules and validation
Investigation Workflow
Step 0: Git Pre-flight Check
Run the Git Pre-flight Check (see section above) before proceeding. Only continue if git state is clean.
Step 1: Classify the Bug Type
Based on $ARGUMENTS, determine the bug category:
| Category | Indicators | Primary Tools |
|---|---|---|
| Extraction | Wrong data extracted, missing fields | Google Drive MCP, Gemini MCP |
| Deployment | Service down, build failures, runtime errors | Railway MCP |
| Matching | Wrong matches, missing matches | Google Drive MCP, Codebase |
| Storage | Data not saved, wrong spreadsheet | Google Drive MCP, Codebase |
| Prompt | Consistent extraction errors on specific doc types | Gemini MCP |
Step 2: Gather Evidence
For Codebase Issues:
- •Use Grep/Glob for searching the codebase
- •Use Task tool with subagent_type=Explore for broader exploration
- •Read relevant source files and tests
For Deployment Issues (if deployment MCPs available):
- •Check MCP/CLI status
- •List services to find affected service
- •List recent deployments with statuses
- •Get deployment and build logs
- •Verify environment configuration
For Document/File Issues (if file MCPs available):
- •Search for the problematic file
- •Read file contents
- •Check related data stores (spreadsheets, databases)
For Prompt/AI Issues (when extraction is consistently wrong):
- •Get the source document
- •Test alternative prompts using AI MCPs
- •Compare current vs expected output
- •Iterate until extraction improves
- •Document the improved prompt for implementation
Step 3: Document Findings
Write PLANS.md with this structure:
# Bug Fix Plan **Created:** YYYY-MM-DD **Bug Report:** [Summary from $ARGUMENTS] **Category:** [Extraction | Deployment | Matching | Storage | Prompt] **Linear Issues:** [ADVA-123](https://linear.app/...), [ADVA-124](https://linear.app/...) ## Investigation ### Context Gathered - **MCPs used:** [list which MCPs were used and why] - **Files examined:** [list files checked - Drive files, spreadsheets, code files, logs] ### Evidence [Detailed findings from investigation with specific data points] ### Root Cause [Clear explanation of why the bug occurs] ## Fix Plan ### Fix 1: [Title matching the issue] **Linear Issue:** [ADVA-123](https://linear.app/...) 1. Write test in [file].test.ts for [scenario that reproduces the bug] 2. Implement fix in [file].ts ### Fix 2: [Title] **Linear Issue:** [ADVA-124](https://linear.app/...) ... ## Post-Implementation Checklist 1. Run `bug-hunter` agent - Review changes for bugs 2. Run `verifier` agent - Verify all tests pass and zero warnings --- ## Plan Summary **Problem:** [One sentence describing the bug/issue] **Root Cause:** [One sentence explaining why it happens] **Linear Issues:** [ADVA-123, ADVA-124, ...] **Solution Approach:** [2-3 sentences describing the fix strategy at a high level] **Scope:** - Files affected: [count] - New tests: [yes/no] - Breaking changes: [yes/no] **Risks/Considerations:** - [Key risk or consideration 1] - [Key risk or consideration 2, if any]
Linear Issue Creation
After writing the fix plan to PLANS.md, create a Linear issue for each fix:
- •
Use
mcp__linear__create_issuewith:- •
team: "ADVA Administracion" - •
title: Fix description - •
description: Root cause and fix details - •
state: "Todo" - •
labels: Bug (or Security if security-related)
- •
- •
Update PLANS.md to add
**Linear Issue:** [ADVA-N](url)to each fix task
Prompt/AI Testing Guidelines
When investigating AI/LLM extraction issues:
- •Get the problematic input using file/document MCPs
- •Read current prompt from the project's prompts file (find via codebase exploration)
- •Test variations using AI MCPs if available
- •Document what works - Include the improved prompt in the fix plan
- •Note: Testing MCPs are for debugging, not production use
Example prompt testing workflow:
1. Current prompt extracts field X as null 2. Test prompt variation A: More explicit field description 3. Test prompt variation B: Add context about document layout 4. Variation B correctly extracts the field 5. Add to fix plan: Update prompts file with variation B
Deployment Debugging Guidelines
When investigating deployment issues (if deployment MCPs available):
- •Check status first - Verify MCP/CLI access
- •List recent deployments - Get deployment IDs and statuses
- •Get targeted logs - Search for errors using filters:
- •Error-level logs
- •Specific error types or messages
- •Check environment - Verify configuration variables
Error Handling
| Situation | Action |
|---|---|
| PLANS.md has incomplete work | Stop and tell user to review/clear PLANS.md first |
| $ARGUMENTS lacks bug description | Ask user to describe what happened vs expected |
| CLAUDE.md doesn't exist | Continue with codebase-only investigation |
| MCP not available | Skip that MCP, note in investigation what couldn't be checked |
| File/resource not found | Document as part of investigation (may be the bug) |
| Cannot reproduce issue | Document investigation steps taken, ask user for more context |
| Root cause unclear | Document possible causes ranked by likelihood |
Rules
- •Refuse to proceed if PLANS.md has incomplete work
- •Discover MCPs from CLAUDE.md - don't hardcode MCP names or paths
- •Investigation only - do not modify source code
- •All fixes must follow TDD (test first)
- •Include enough detail for another model to implement without context
- •Always include post-implementation checklist
- •For prompt issues, test multiple variations before recommending changes
- •Create Linear issues in Todo state for each fix task
- •Include Linear issue links in PLANS.md
CRITICAL: Scope Boundaries
This skill creates plans. It does NOT implement them.
- •NEVER ask to "exit plan mode" - This skill doesn't use Claude Code's plan mode feature
- •NEVER implement code - Your job ends when PLANS.md is written
- •NEVER ask ambiguous questions like "should I proceed?" or "ready to continue?"
- •NEVER start implementing after writing the plan, even if user says "yes" to something
Termination
When you finish writing PLANS.md (and creating Linear issues), output the plan summary followed by the completion message:
✓ Plan created in PLANS.md ✓ Linear issues created in Todo: ADVA-123, ADVA-124, ... ## Plan Summary **Problem:** [Copy from PLANS.md summary] **Root Cause:** [Copy from PLANS.md summary] **Linear Issues:** [Copy from PLANS.md summary] **Solution Approach:** [Copy from PLANS.md summary] **Scope:** - Files affected: [count] - New tests: [yes/no] - Breaking changes: [yes/no] **Risks/Considerations:** - [List from PLANS.md summary] --- Create a feature branch and commit the plan.
Then execute git workflow:
- •
Create a fix branch with proper naming:
- •Always use
fix/prefix for bug fixes - •Branch name should be kebab-case, derived from the bug description
- •Example:
fix/sql-injection-query-builder,fix/race-condition-cache
- •Always use
- •
Stage, commit, and push:
git checkout -b fix/<bug-description> && git add PLANS.md && git commit -m "plan: <bug-description>" && git push -u origin fix/<bug-description>
Do not ask follow-up questions. Do not offer to implement. Output the summary and stop.