# State Machine Audit

Identify and document implicit state machines in a UI or feature, ensuring each state has a designed screen, typed hook, and agent-friendly controls. The deliverable includes a state table with encoded states, user-visible outcomes, and design decisions.

**Canonical URL:** https://skillshunter.net/skills/discovered-cc1484ff35c53f750d7d598db5ada16d3323e6260f7d0f16

**JSON URL:** https://skillshunter.net/api/public/v1/skills/discovered-cc1484ff35c53f750d7d598db5ada16d3323e6260f7d0f16

**Markdown URL:** https://skillshunter.net/skills/discovered-cc1484ff35c53f750d7d598db5ada16d3323e6260f7d0f16.md

**Instructions download URL:** https://skillshunter.net/skills/discovered-cc1484ff35c53f750d7d598db5ada16d3323e6260f7d0f16/download

**Category:** Software & Development

**Source URL:** https://github.com/DevDadTribe/toolbox/blob/5f44c242b6e4997ebc34dec7202932c4aa6701f6/skills/state-machine-audit/SKILL.md

**Source commit:** 5f44c242b6e4997ebc34dec7202932c4aa6701f6

**Listing approved at:** 2026-11-29

**Created at:** 2026-11-28T18:42:05.000000Z

**Updated at:** 2026-11-29T10:53:02.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

Before starting, ensure all copies of the UI (app, iframe, branded version, phone) are walked through in every state. Also, keep the project's protected-file rules intact and avoid renaming public data shapes that servers or old embeds rely on.

### When to use it

- Fix UI flashes or blank boxes by identifying and redesigning implicit state machines
- Ensure consistent state representation across app copies (iframe, branded, mobile)
- Improve developer experience by creating typed hooks and state unions
- Enable agents to force states for troubleshooting or user support

## Skill instructions

---
name: state-machine-audit
description: Find the hidden state machines in a screen or feature (loading flags, null-as-state, dismissed notices, refetch flashes, view modes, copies kept in step by hand) and turn them into named states that each get one designed screen, one typed hook and a way for an agent to force it. Use when a screen flashes, shows the wrong message or a blank box, before redesigning a screen that loads data, or when someone says "state machine", "implicit states", "find all the states" or "why does it flash".
metadata:
  license: AGPL-3.0-or-later
  copyright: "2026 DevTribe Labs"
  homepage: https://github.com/DevDadTribe/toolbox
---

# State machine audit: name every state before you redesign it

The prompt that started this, shared by Steve Ruiz:

> "Find all of the implicit state machines in my app. Make the best decision that will elevate
> all three: the user experience (UX), developer experience (DX), and agent experience (AX)
> always, without breaking anything."

It works because most UI bugs are not styling bugs. A screen shows a flash, a blank box, a
spinner that never ends, or "all good" when the read failed, because three booleans and a null
decide what it shows and nobody ever wrote down which combinations can happen. Polish cannot
fix that. A named state with one designed screen can.

This skill is the procedure. The audit step changes no code. It produces a map, then a plan of
small PRs.

## 1. Scope by what the user sees, not by folder

List every place the screen is drawn: the signed-in page, an iframe or embed copy, a branded
or partner version, a phone layout, a server that builds its data. Two copies kept in step by a
code comment are one machine with two bodies; count them as one finding.

## 2. Find the hidden machines

Read the code. Grep only to find where to read.

```bash
# booleans and nulls that decide what shows
grep -nE "useState(<boolean>)?\((true|false|null)\)|isLoading|isFetching|isError|isPending|error\b" <files>
# state kept outside the component
grep -nE "localStorage|sessionStorage|dismiss|hidden|hold|snooze" <files>
# effects that set state (where transitions hide)
grep -nE "useEffect|setTimeout|setInterval|subscribe|channel\(" <files>
```

The patterns above are for React. Use the same idea in any framework: find the flags, the
stored values and the side effects that decide what is drawn.

Signs of a hidden machine:

- Two or more flags read together in one `if` or ternary (`isLoading && !data`, `error ? ... : data ? ... : ...`).
- `null` or `undefined` meaning "not loaded yet" and also "nothing there".
- A value saved in browser storage to hold space or hide something.
- A "keep in sync with X" comment.
- A component that returns nothing early (a blank box is a state with no screen).
- Any place a refetch makes the screen jump.

## 3. Write the state table for each machine

One table per machine. Check every row against the code, with `file:line`.

| State | Encoded by (file:line) | What the user sees today | Designed? |
|---|---|---|---|
| loading (first time) | `isLoading && !data` | grey shimmer | yes |
| loading (refresh) | `isFetching && data` | whole card flashes | **no** |
| failed | `error` | "You're in good shape" | **wrong message** |

Then list:

- **Impossible but representable** combinations (`isLoading && error && data`). Each one is a bug waiting to happen.
- **Events** that move between states (mount, refetch, realtime update, account switch, token expiry).
- **Drift**: where the copies draw the same state differently.

## 4. Decide for all three: UX, DX, AX

**UX.** Every reachable state gets exactly one designed screen, shared by every card that has
that state:

- first load: a skeleton the same size as the real thing;
- refreshing: keep the old numbers and show a small "updating" mark (never blank, never jump);
- empty: one next step;
- out of date: the time it was last read;
- failed: what failed and a retry, never a reassurance;
- not allowed or on hold: why, and who can change it.

Numbers count up once on first load and never animate again on refresh.

**DX.** One typed union per machine, made by one hook, and the screen switches on it:

```ts
type CardState<T> =
  | { kind: 'loading' }
  | { kind: 'ready'; data: T; refreshing: boolean; readAt: Date }
  | { kind: 'empty'; next: NextStep }
  | { kind: 'stale'; data: T; readAt: Date }
  | { kind: 'failed'; error: string; retry: () => void; last?: T };
```

Derive the state from the source. Never store a flag you can compute. Write one test per
state. When two copies exist (app and embed), make them one component fed by two data
sources, so a look change lands in both.

**AX.** Agents must be able to see every state without a person signing in:

- put `data-state="<kind>"` on the card root;
- add a way to force a state on a local preview or a test account (`?state=empty`, or a
  fixture switch), never on production for real users;
- save the state map with the work (the PR description or a notes file), so the next agent
  reads it instead of deriving it again.

## 5. Without breaking anything

- Pin today's behaviour first: a test per state that passes on the current code, then
  refactor under it. Make each new test fail on purpose once, so you know it can fail.
- One machine per PR. The shared look (skeleton, empty, failed) goes in first, then cards move
  over one at a time.
- Walk every copy (app, iframe, branded version, phone) in every state before merge.
- Keep the project's own protected-file rules. Never rename a public data shape that a server
  or an old open embed still sends.

## 6. What the audit hands back

1. The map: machines, tables, impossible combinations and drift, each with `file:line`. In a
   repo with a plans or docs folder, save it there.
2. The top defects found, one sentence each, located in code. No guesses.
3. The PR plan, smallest first.
4. Optional: a clickable mockup where each state can be switched on, so the user can approve
   the look of every state before code changes.

Never present a hidden state as a defect until you have read the lines that produce it.

---

*`state-machine-audit` from [DevDad's Toolbox](https://github.com/DevDadTribe/toolbox). AGPL-3.0-or-later (c) 2026 DevTribe Labs.*

