---
name: papi-audit
description: >
  Audit the latest changes in this branch for bugs and compliance with the project's conventions.
  Use when the user says "audit", "review changes", "check my code", "check my branch",
  or after completing a build task before submitting for review.
invocable: true
---

# PAPI Audit — Bug & Doc Drift Check

Audit all changes on the current branch for bugs, convention violations, and documentation drift.

## Steps

### 1. Identify changed files

Run `git diff origin/main --name-only` to find all files modified on this branch. If no changes are found, report "No changes to audit" and stop.

### 2. Read and review each changed file

For each changed file, read it and review for:

**Bug check:**
- Logic errors, off-by-one mistakes, incorrect conditions
- Unhandled edge cases (null, undefined, empty inputs)
- Race conditions or state management issues
- Functions that could throw but aren't wrapped in try/catch where needed
- Incorrect type narrowing or unsafe casts

**Code style (from CLAUDE.md):**
- Check all conventions defined in CLAUDE.md and flag any violations
- Pay special attention to naming, typing, error handling, and import patterns

### 3. Documentation check

For each changed source file, check if any documentation in `docs/` describes behaviour, architecture, or file interactions that the change modified. Specifically:
- If a doc needs updating, report it as a finding with severity "Doc drift" and specify which section is stale.

### 4. Report findings

For each issue found:
- **File**: path and line number
- **Severity**: Bug / Convention violation / Doc drift / Nitpick
- **Issue**: What's wrong
- **Fix**: How to fix it

If no issues are found, state that the changes are clean.

### 5. Pre-existing issues

Note pre-existing issues separately — flag them but don't fix them unless they interact with the new changes.
