---
description: Interactively triage bugs - update status, priority, and resolution
argument-hint: [<bug-id>] [<status>] [<priority>]
allowed-tools: Bash, Read, Edit, Write
---

# Bug Triage: $ARGUMENTS

## Phase 0: Parse Arguments

Extract from `$ARGUMENTS`:

- **bug-id**: Optional bug ID to triage
- **status**: Optional new status
- **priority**: Optional new priority

**Modes:**

- **Interactive mode** (no args): Select bug and update interactively
- **Direct mode** (bug-id only): Interactive prompts for that bug
- **Quick update** (all args): Direct update without prompts

## Phase 1: Read Bug File

### 1.1 Validate File Exists

````bash
test -f .bugs.local.md || { echo "⚠️  No bugs found. Create one with: /bug <summary>"; exit 0; }
```text

### 1.2 Read and Parse Bugs

```bash
cat .bugs.local.md
```text

Parse all bugs from table and detailed sections.

## Phase 2: Bug Selection

### 2.1 Interactive Selection (no bug-id provided)

List bugs with status != Closed:

```text
? Select bug to triage: (Use arrow keys)
❯ #1 - Selective tool install not working (Open, High, Under Investigation)
  #2 - Documentation needs update (Ready, Medium, Unresolved)
  #3 - Error handling missing (Open, Low, Unresolved)

  [q] Cancel
```text

### 2.2 Direct Selection (bug-id provided)

Validate bug ID exists:

- If not found: "❌ Bug #[id] not found. Use /bug:list to see available bugs."
- If found: Load bug details and proceed

## Phase 3: Interactive Triage

### 3.1 Show Current State

```text
🐛 Bug #[ID]: [Summary]

Current State:
  Status:     [current-status]
  Priority:   [current-priority]
  Resolution: [current-resolution]
  Created:    [date]
  Updated:    [date]
```text

### 3.2 Update Status

If status not provided in args:

```text
? New status: (Use arrow keys, Enter to keep current)
  Keep current: [current-status]
  ─────────────────────────────
❯ Open
  Rejected
  Ready
  In Progress
  Resolved
  Closed
```text

**Status transition validation:**

- Can't go from Closed back to Open (warn user, allow override)
- Resolved → Closed requires Resolution = Fixed (enforce or prompt)

### 3.3 Update Priority

If priority not provided in args:

```text
? New priority: (Use arrow keys, Enter to keep current)
  Keep current: [current-priority]
  ────────────────────────────────
  Low
❯ Medium
  High
  Critical
  Blocker
```text

### 3.4 Update Resolution

If status changed to Resolved or Closed:

```text
? Resolution: (Use arrow keys)
❯ Fixed
  Won't Fix
  Duplicate
  Invalid
```text

If status = Resolved and Resolution not set, default to "Fixed"

### 3.5 Add Triage Notes (Optional)

```text
? Add notes about this change? (Y/n)
```text

If yes:

```text
? Triage notes: (Press Enter to finish)
> [User types notes]
```text

Append notes to bug details section with timestamp.

## Phase 4: Update Bug File

### 4.1 Update Summary Table

Find bug row in table, update:

- Status column
- Priority column
- Resolution column (if changed)

### 4.2 Update Detailed Section

Find bug detailed report, update:

- **Status**: [new-status]
- **Priority**: [new-priority]
- **Resolution**: [new-resolution]
- **Updated**: [current-date]

If notes provided, append:

```markdown
**Triage Notes:**
- [YYYY-MM-DD]: [notes text]
```text

### 4.3 Atomic Write

```bash
# Create backup
cp .bugs.local.md .bugs.local.md.bak

# Write updated content to temp file
cat > .bugs.local.md.tmp

# Validate structure
# (check table syntax, required fields)

# Atomic rename
mv .bugs.local.md.tmp .bugs.local.md

# Remove backup on success
rm .bugs.local.md.bak
```text

## Phase 5: Present Results

```text
✓ Bug #[ID] updated

Changes:
  Status:     [old] → [new]
  Priority:   [old] → [new]
  Resolution: [old] → [new]

Updated: [timestamp]

Next steps:
  /bug:show [ID]      # View updated bug
  /bug:fix [ID]       # Start working on fix (if Ready/In Progress)
  /bug:close [ID]     # Close bug (if Resolved)
```text

If status changed to "Ready":

```text
💡 Tip: This bug is now ready for development. Start work with:
   /bug:fix [ID]
```text

If status changed to "Resolved":

```text
✅ Bug marked as resolved. Verify the fix and close with:
   /bug:close [ID]
```text

## Phase 6: Batch Triage (Advanced)

If no bug-id provided and multiple bugs need triage:

```text
? Batch triage mode? (y/N)
```text

If yes:

```text
? Select bugs to update: (Space to select, Enter to continue)
❯◉ #1 - Selective tool install not working
 ◯ #2 - Documentation needs update
 ◉ #3 - Error handling missing

? Apply to selected bugs:
  ❯ Change status
    Change priority
    Change resolution
    Add notes
```text

Apply same change to all selected bugs.

## Error Handling

- **Invalid bug ID**: Show available bugs, exit
- **Invalid status/priority value**: Show valid options, prompt again
- **File write failure**: Restore from backup, show error
- **Malformed table**: Attempt repair or fail with clear message
- **Status transition conflict**: Warn user, allow override with confirmation

## Exit Codes

- 0: Triage completed successfully
- 1: Invalid input or bug not found
- 2: File operation failure
````
