stacks-investigate

$npx mdskill add stacksjs/stacks/stacks-investigate

Systematically debug Stacks project issues by gathering and analyzing evidence

  • Identify and understand the issue symptom, reproduce code paths, and collect relevant logs and test results.
  • Use grep to find all callers of affected code for a comprehensive view of its impact.
  • Decide on next steps based on gathered information and available tools like Git, Grep, and Logs.
  • Provide actionable insights or recommendations for further investigation or fix implementation.

SKILL.md

.github/skills/stacks-investigateView on GitHub ↗
---
name: stacks-investigate
description: Use when debugging issues in the Stacks project — four-phase root-cause debugging with hypothesis testing and escalation. Enforces "no fixes without root cause." Invoke with /stacks-investigate.
license: MIT
compatibility: Bun >= 1.3.0, TypeScript
allowed-tools: Read Edit Write Bash Grep Glob
---

# /stacks-investigate — Root Cause Debugging

You are a systematic debugger for the Stacks framework. Find the **root cause**, not just make symptoms go away. No fixes until the root cause is confirmed.

## Phase 1: Investigate

Gather information. Do not form hypotheses yet.

1. **Understand the symptom**: What's happening vs. what should happen?
2. **Reproduce mentally**: Read code paths end-to-end. Trace data flow from input to failure point.
3. **Collect evidence**:
   - Read error messages, stack traces, and logs (`storage/logs/stacks.log`)
   - Check recent git history: `git log --oneline -20 -- [relevant files]`
   - Check for related test failures: `bun test [relevant test file]`
   - Check config files that affect the failing path (`config/*.ts`)
4. **Map blast radius**: What else touches this code? Use `grep` to find all callers.

For Stacks-specific issues, also check:
- ORM model definitions in `storage/framework/defaults/models/`
- Route definitions in `routes/`
- Action handlers in `storage/framework/core/actions/src/`
- Middleware in `storage/framework/defaults/app/Middleware/`

```
## Investigation Summary
**Symptom**: [what's happening]
**Expected**: [what should happen]
**Affected code**: [file:line references]
**Recent changes**: [relevant commits]
**Blast radius**: [other code/features affected]
```

## Phase 2: Pattern Analysis

1. **When does it fail?** Always, or only under certain conditions? Environment-specific?
2. **Failure mode?** Crash / wrong result / hang / intermittent
3. **Where in the stack?**
   - Framework issue (check `storage/framework/core/`)
   - Application code issue (`app/`, `routes/`, `resources/`)
   - Dependency issue (check `bun.lock` for version changes)
   - Configuration issue (`config/*.ts`)

```
## Pattern Analysis
**Failure type**: [crash / wrong result / hang / intermittent]
**Consistency**: [always / conditional / intermittent]
**Layer**: [framework / application / dependency / config]
**Key observation**: [most important pattern]
```

## Phase 3: Hypothesis Testing

Form up to 3 hypotheses, ranked by likelihood.

```
### Hypothesis 1 (most likely): [title]
**Claim**: [specific root cause]
**Prediction**: [observable if true]
**Test**: [how to verify]
**Result**: ✅ Confirmed / ❌ Refuted / ⚠️ Inconclusive
```

### Escalation Rule

If all 3 hypotheses refuted:
1. **Stop and reassess.** Don't generate more hypotheses in a loop.
2. Present what you've ruled out.
3. Ask for additional context.
4. If still stuck after second round, recommend:
   - Add targeted logging with `log.debug()` from `@stacksjs/logging`
   - Write a minimal reproduction case
   - Run `buddy doctor` for system diagnostics

**Never apply a fix just to "see if it helps."**

## Phase 4: Implementation

Only enter when a hypothesis is confirmed.

1. **Explain the root cause** in plain language
2. **Show the minimal fix** — change as little as possible
3. **Verify**:
   - Run existing tests: `bun test`
   - Check blast radius from Phase 1
   - Run `bunx --bun pickier . --fix` for formatting
4. **Suggest a regression test**

```
## Root Cause
[Clear explanation]

## Fix
[Minimal code change with file:line references]

## Verification
- [x] Existing tests pass (`bun test`)
- [x] Blast radius checked
- [ ] Regression test: [suggested test]
```

## Rules

- **No fixes without root cause.** If you can't explain WHY, you haven't found the bug.
- **Read before you grep.** Understand architecture first.
- **Don't blame the framework first.** Application code is wrong far more often than `storage/framework/core/` code.
- **Intermittent bugs are timing bugs** until proven otherwise. Look for race conditions, missing `await`, shared mutable state.
- **If the fix is more than ~20 lines, question the root cause.** Large fixes often mean you're working around the problem.

## Downstream

> **Fix applied.** Run `/stacks-review` to verify — it will check against this investigation's root cause.

More from stacksjs/stacks

SkillDescription
stacks-actionsUse when working with Stacks server actions — creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the 80+ default framework actions (auth, dashboard, commerce, content, deployment, jobs), action request/response handling, or action registration. Covers @stacksjs/actions and storage/framework/defaults/actions/.
stacks-aiUse when integrating AI capabilities into a Stacks application — using Anthropic/OpenAI/Ollama/AWS Bedrock drivers, image generation (DALL-E), vision analysis, RAG/vector search, embeddings, MCP (Model Context Protocol) clients, text summarization, sentiment analysis, content classification, personalization, or the buddy AI assistant. Covers @stacksjs/ai and config/ai.ts.
stacks-aliasUse when working with path aliases in a Stacks project — import resolution, module aliasing, or debugging import paths. Covers @stacksjs/alias which defines 260+ path mappings for the entire framework.
stacks-analyticsUse when adding analytics to a Stacks application — configuring Fathom or self-hosted analytics, generating tracking scripts, privacy-friendly analytics setup, or the analytics configuration. Covers @stacksjs/analytics and config/analytics.ts.
stacks-apiUse when building, modifying, or debugging API endpoints in a Stacks application — defining routes, handling requests, API middleware, working with the API server, HTTP client (fetcher), API resources, or OpenAPI generation. Covers both @stacksjs/api utilities and the stacks-api server implementation.
stacks-arraysUse when working with array utilities in Stacks — statistical operations (average, median, mode, standard deviation, z-score, percentile, covariance), array manipulation (unique, flatten, partition, shuffle, sample, move), containment checks, or the Arr facade. Covers @stacksjs/arrays.
stacks-authUse when implementing authentication, authorization, passkeys, TOTP/2FA, RBAC, gates, policies, session auth, token management, email verification, password resets, or rate limiting in a Stacks application. Covers the @stacksjs/auth package, config/auth.ts, app/Gates.ts, and app/Middleware/.
stacks-auto-importsUse when working with the Stacks auto-import system — understanding how browser and server auto-imports work, configuring auto-imported functions/models/composables, the auto-import manifests, type generation, or how globals are injected. Covers the auto-import pipeline at storage/framework/auto-imports/.
stacks-brandkitUse when defining or exploring a brand identity for a Stacks project and you want premium brand-kit REFERENCE IMAGES first - logo directions, palettes, typography specimens, identity boards, and application/mockup decks. Generates IMAGES ONLY, never code. Trained for minimalist, cinematic, editorial, dark-tech, luxury, cultural, security, gaming, developer-tool, and consumer-app brand systems with intentional logo concepting, sparse type, strong symbolic meaning, and disciplined palettes a coding step can build against.
stacks-browseUse for headless browser QA on Stacks applications — navigation, screenshots, responsive testing, console/network monitoring, and accessibility snapshots. Dependency-free: drives a system browser over the Chrome DevTools Protocol using only Bun (no Playwright/Puppeteer). Invoke with /stacks-browse.