---
model: sonnet
---

# /tas-bug $ARGUMENTS

Manage entire bug lifecycle: create, analyze, fix, verify.
Bug status determines next step — no role declaration needed.

## Always / Ask / Never

| | Action |
|---|---|
| **Always** | Display current status and next action before doing anything |
| **Always** | Write regression test BEFORE fixing |
| **Always** | Launch independent review agent after fix — no review in same session |
| **Ask** | When needing to read files outside Bug file (Status = Committed) |
| **Never** | Patch symptom — must fix root cause |
| **Never** | Skip review step after fix |
| **Never** | Auto-commit or push — wait for user manual testing first |

## Stack Detection
Read `.tas/rules/common/stack-detection.md`.

## Actions

### Step 1 — Determine mode

`$ARGUMENTS` is new bug description → **CREATE mode**
`$ARGUMENTS` is Bug ID (e.g., `Bug-001`) → **UPDATE mode**

---

### CREATE mode

Role: PE or SE (whoever discovered the bug)

1. Read `project.code` from root/`tas.yaml`
2. Ask user:
   - Which Feature does this bug belong to?
   - Severity: `Critical` | `High` | `Medium` | `Low`
   - Steps to reproduce
   - Expected vs Actual behavior
   - Environment where discovered: Test | Staging | Production
3. Create `docs/bugs/{code}-Bug-{NNN}-{slug}.md` from template `.tas/templates/Bug.md`
4. Initial bug status: `New`

---

### UPDATE mode

Find Bug file via glob `docs/bugs/*-Bug-{ID}-*.md`, read current status.

**Display before acting:**
> "Bug-{NNN} is currently at status: **{status}** — next step is {action}. Continue?"

---

#### Status = `New` — Analyze (SE)

1. Read error logs/stack trace from Bug file
2. Trace code flow, identify file and line causing error
3. Write Root Cause Analysis into Bug file
4. Write Regression Test Cases (test that reproduces bug)
5. **Fill SAD Impact Matrix** — read `.tas/rules/common/sad-impact.md`. Anticipate fix scope (will it add lib / cache / queue / column / ENV / port / auth change / etc.) **from the symptom alone** — mark `Detected: Yes` rows + SAD section + summary. If any Yes → set frontmatter `sad_impact: true`. **Do NOT open `docs/sad.md` here** — the analyze-time matrix is predictive; defer the `docs/sad.md` read to the post-fix re-evaluation (Step `Committed`) when the real fix scope is known. This avoids reading the SAD on bugs that turn out to have no impact.
6. Update status: `New` → `Committed`

---

#### Status = `Committed` — Fix (SE)

**File reading rule:** ONLY read Bug file. DO NOT read PRD, ADR, Design-Spec, DO NOT scan directories.
SAD read **allowed** if Bug frontmatter `sad_impact: true` (limited to sections in matrix).
If other files needed → ask user confirmation first.

Before fixing, read:
- `.tas/rules/common/security.md` — fix must not create new security risks
- `.tas/rules/common/testing.md` — regression test writing patterns
- `.tas/rules/[lang_agent stack]/coding-style.md` — follow conventions

**Fix workflow:**
a. Run regression test case → confirm **FAIL** (reproduces bug)
b. Fix code at root cause
c. Run regression test → confirm **PASS**
d. Run full test suite → no new regressions
→ If build fails or test compile errors: launch `build-resolver` agent with error output (single diagnostic call — one shot, no build-debug loop here; pass context within build-resolver's input cap) before continuing.

**After fix — Post-Fix Review (Isolated Agent):**

Follow `.tas/rules/common/post-implementation-review.md`.
Pass in: Bug file path, changed files list, stack (from CLAUDE.md), lang_agent.

After review passes:

**SAD update (if flagged):** If Bug frontmatter `sad_impact: true`:
- Re-evaluate matrix vs actual fix (fix scope may have shifted from analyze-time estimate). Update matrix Yes/No if changed.
- If still any Yes → auto-invoke `/tas-sad "Bug-{NNN}: {one-line summary from matrix Yes rows}"` inline. Verify `docs/sad.md` Changelog contains `Bug-{NNN}` ref before status transition.
- If matrix is now all No → set frontmatter `sad_impact: false`, skip invoke.

**Status transition:**
- Update status: `Committed` → `Deploy Test`
- Output suggested commit message: `fix: {short description} - resolves Bug-{NNN}`
- Ask: "Have you tested manually? Want to commit and deploy to Test?"

---

#### Status = `Verify Test` / `Verify Stag` — Verify (PE)

1. PE verifies on corresponding environment:
   - Run Steps to Reproduce again → confirm bug no longer exists
   - Check regression test case has passed
2. **Pass** → update to next status (`Deploy Stag` or `Done`)
   - **SAD Done Gate** (when transitioning to `Done`): if Bug frontmatter `sad_impact: true` → grep `docs/sad.md` Changelog for `Bug-{NNN}` ref. No match → BLOCK `Done`, surface: "SAD impact flagged but `docs/sad.md` Changelog missing Bug-{NNN} ref. Re-run `/tas-sad` before closing."
3. **Fail** → document reason, update status back to `Committed`, SE fixes again

---

## Principles
- DO NOT patch symptom — must fix root cause
- MUST have regression test case BEFORE fixing
- Review must run through independent Agent — not inline in current session
- `Critical`/`High` bugs must be fixed before Feature is Verified
- Flow: `New` → `Committed` → `Deploy Test` → `Verify Test` → `Deploy Stag` → `Verify Stag` → `Deploy Prod` → `Verify Prod` → `Done`

## Final Step — Token Log

Follow `.tas/rules/common/token-logging.md`: write AI Usage Log to working Bug file.
