{"data":{"slug":"discovered-cc1484ff35c53f750d7d598db5ada16d3323e6260f7d0f16","title":"State Machine Audit","summary":"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.","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","download_url":"https:\/\/skillshunter.net\/skills\/discovered-cc1484ff35c53f750d7d598db5ada16d3323e6260f7d0f16\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_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.","instructions":"---\nname: state-machine-audit\ndescription: 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\".\nmetadata:\n  license: AGPL-3.0-or-later\n  copyright: \"2026 DevTribe Labs\"\n  homepage: https:\/\/github.com\/DevDadTribe\/toolbox\n---\n\n# State machine audit: name every state before you redesign it\n\nThe prompt that started this, shared by Steve Ruiz:\n\n> \"Find all of the implicit state machines in my app. Make the best decision that will elevate\n> all three: the user experience (UX), developer experience (DX), and agent experience (AX)\n> always, without breaking anything.\"\n\nIt works because most UI bugs are not styling bugs. A screen shows a flash, a blank box, a\nspinner that never ends, or \"all good\" when the read failed, because three booleans and a null\ndecide what it shows and nobody ever wrote down which combinations can happen. Polish cannot\nfix that. A named state with one designed screen can.\n\nThis skill is the procedure. The audit step changes no code. It produces a map, then a plan of\nsmall PRs.\n\n## 1. Scope by what the user sees, not by folder\n\nList every place the screen is drawn: the signed-in page, an iframe or embed copy, a branded\nor partner version, a phone layout, a server that builds its data. Two copies kept in step by a\ncode comment are one machine with two bodies; count them as one finding.\n\n## 2. Find the hidden machines\n\nRead the code. Grep only to find where to read.\n\n```bash\n# booleans and nulls that decide what shows\ngrep -nE \"useState(<boolean>)?\\((true|false|null)\\)|isLoading|isFetching|isError|isPending|error\\b\" <files>\n# state kept outside the component\ngrep -nE \"localStorage|sessionStorage|dismiss|hidden|hold|snooze\" <files>\n# effects that set state (where transitions hide)\ngrep -nE \"useEffect|setTimeout|setInterval|subscribe|channel\\(\" <files>\n```\n\nThe patterns above are for React. Use the same idea in any framework: find the flags, the\nstored values and the side effects that decide what is drawn.\n\nSigns of a hidden machine:\n\n- Two or more flags read together in one `if` or ternary (`isLoading && !data`, `error ? ... : data ? ... : ...`).\n- `null` or `undefined` meaning \"not loaded yet\" and also \"nothing there\".\n- A value saved in browser storage to hold space or hide something.\n- A \"keep in sync with X\" comment.\n- A component that returns nothing early (a blank box is a state with no screen).\n- Any place a refetch makes the screen jump.\n\n## 3. Write the state table for each machine\n\nOne table per machine. Check every row against the code, with `file:line`.\n\n| State | Encoded by (file:line) | What the user sees today | Designed? |\n|---|---|---|---|\n| loading (first time) | `isLoading && !data` | grey shimmer | yes |\n| loading (refresh) | `isFetching && data` | whole card flashes | **no** |\n| failed | `error` | \"You're in good shape\" | **wrong message** |\n\nThen list:\n\n- **Impossible but representable** combinations (`isLoading && error && data`). Each one is a bug waiting to happen.\n- **Events** that move between states (mount, refetch, realtime update, account switch, token expiry).\n- **Drift**: where the copies draw the same state differently.\n\n## 4. Decide for all three: UX, DX, AX\n\n**UX.** Every reachable state gets exactly one designed screen, shared by every card that has\nthat state:\n\n- first load: a skeleton the same size as the real thing;\n- refreshing: keep the old numbers and show a small \"updating\" mark (never blank, never jump);\n- empty: one next step;\n- out of date: the time it was last read;\n- failed: what failed and a retry, never a reassurance;\n- not allowed or on hold: why, and who can change it.\n\nNumbers count up once on first load and never animate again on refresh.\n\n**DX.** One typed union per machine, made by one hook, and the screen switches on it:\n\n```ts\ntype CardState<T> =\n  | { kind: 'loading' }\n  | { kind: 'ready'; data: T; refreshing: boolean; readAt: Date }\n  | { kind: 'empty'; next: NextStep }\n  | { kind: 'stale'; data: T; readAt: Date }\n  | { kind: 'failed'; error: string; retry: () => void; last?: T };\n```\n\nDerive the state from the source. Never store a flag you can compute. Write one test per\nstate. When two copies exist (app and embed), make them one component fed by two data\nsources, so a look change lands in both.\n\n**AX.** Agents must be able to see every state without a person signing in:\n\n- put `data-state=\"<kind>\"` on the card root;\n- add a way to force a state on a local preview or a test account (`?state=empty`, or a\n  fixture switch), never on production for real users;\n- save the state map with the work (the PR description or a notes file), so the next agent\n  reads it instead of deriving it again.\n\n## 5. Without breaking anything\n\n- Pin today's behaviour first: a test per state that passes on the current code, then\n  refactor under it. Make each new test fail on purpose once, so you know it can fail.\n- One machine per PR. The shared look (skeleton, empty, failed) goes in first, then cards move\n  over one at a time.\n- Walk every copy (app, iframe, branded version, phone) in every state before merge.\n- Keep the project's own protected-file rules. Never rename a public data shape that a server\n  or an old open embed still sends.\n\n## 6. What the audit hands back\n\n1. The map: machines, tables, impossible combinations and drift, each with `file:line`. In a\n   repo with a plans or docs folder, save it there.\n2. The top defects found, one sentence each, located in code. No guesses.\n3. The PR plan, smallest first.\n4. Optional: a clickable mockup where each state can be switched on, so the user can approve\n   the look of every state before code changes.\n\nNever present a hidden state as a defect until you have read the lines that produce it.\n\n---\n\n*`state-machine-audit` from [DevDad's Toolbox](https:\/\/github.com\/DevDadTribe\/toolbox). AGPL-3.0-or-later (c) 2026 DevTribe Labs.*\n","use_cases":["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"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/DevDadTribe\/toolbox\/blob\/5f44c242b6e4997ebc34dec7202932c4aa6701f6\/skills\/state-machine-audit\/SKILL.md","source_commit":"5f44c242b6e4997ebc34dec7202932c4aa6701f6","license":null,"version":null,"listing_approved_at":"2026-11-29","created_at":"2026-11-28T18:42:05.000000Z","updated_at":"2026-11-29T10:53:02.000000Z","seo_title":"State Machine Audit for UI State Clarity","seo_description":"Audit and document hidden state machines in your UI to improve user experience, developer experience, and agent experience with consistent state design.","seo_keywords":["state machine audit","UI state design","implicit state machines","UX improvement","React state management","state table documentation"]}}