[s] state-machine-audit
Astack / Adi's Skill Stack / Operations guide

Find the states
you never intended.

An evidence-backed audit of state machines, async races, and data that gets out of sync. Run it with the coding agent you already use.

When to use this: before a state-heavy release, after a race-condition incident, or when a lifecycle has become difficult to reason about.

Read-only auditOne reportMIT licensed
01 / SETUP

Install for your agent #

You need an installed coding agent and Node.js 22.20+ for the community Skills CLI. Run the command below, review the installer prompts, then reopen your agent session.

TERMINAL / GLOBAL INSTALL
npx skills add adityaarakeri/state-machine-audit --skill state-machine-audit --global --agent claude-code

Select Claude Code in the installer. Use the prompt in step 02 from a session opened in the repository you want audited.

--global makes the skill available across projects. For a project-only install, run the command inside that project and omit --global. Agent authentication and model access are configured separately.

Prefer a local clone or an offline skill copy?

The repository scripts require Node 18+; the bundled installer requires Bash (Git Bash or WSL on Windows).

BASH / CLONE
git clone https://github.com/adityaarakeri/state-machine-audit.git
cd state-machine-audit
npm run lint
bash scripts/install.sh --agent claude

The bundled installer accepts claude, codex, cursor, or all. For Antigravity and OpenCode, use the Skills CLI above. For a manual install, copy the entire skills/state-machine-audit/ folder, including references/, into your agent's documented skill directory.

The Bash installer replaces an existing installed folder of the same name. Save local customizations before rerunning it.

Installation options and agent identifiers follow the Skills CLI documentation and its supported-agent reference.

02 / EXECUTE

Open the target repository

Start Claude Code, Codex, OpenCode, or an Antigravity workspace in the codebase you want reviewed. Record your existing changes first so you can distinguish them from the audit output.

TERMINAL / BASELINE
git status --short

Send this in your agent's chat. The same plain-language request works across the four agents; there is no special audit CLI to launch.

AGENT CHAT / AUDIT REQUEST
Use the state-machine-audit skill on this repository.
Focus on checkout, payment status transitions, and async UI updates.
Read and search only. Do not change application code or run builds.
Write an evidence-backed report with exact file locations,
verbatim snippets, concrete failure scenarios, and structural fixes.
State which modules you covered and which you skipped.
Expected output: a new report, not a patch.

The skill writes REPORT.md. If that exists, it uses REPORT-state-audit.md, then a dated fallback. Existing reports must not be overwritten. If every suggested filename is occupied, ask for a fresh filename before writing.

For an agent without native skills, run npm run build in this skill's clone and paste dist/prompt/state-machine-audit.md into its chat. Generated adapters also support Cursor rules, Copilot prompts, GEMINI.md, and AGENTS.md. Merge instructions carefully into any existing instruction file.

03 / WORKED EXAMPLE

A payment finishes late

Imagine a checkout that lets a customer cancel while a payment request is still running. Its status can say cancelled, then jump to paid when the old promise resolves.

01   payingPayment request starts for order A.
02   cancelledThe customer cancels before the response arrives.
03   paid ?A stale completion writes a terminal status without checking the current state.

Illustrative code, not a finding from your repository:

TYPESCRIPT / UNGUARDED TRANSITION
async function pay() {
  setStatus('paying');
  await charge(orderId);
  setStatus('paid');
}

function cancel() {
  setStatus('cancelled');
}

A useful finding describes the ordering that causes the bug, cites the actual lines, and checks whether cancellation or an operation identifier already prevents it. A suspicious pattern alone is not evidence.

The proposed fix might centralize legal transitions and associate each completion with its operation ID. Payment reconciliation still belongs on the server; ignoring a stale UI response does not undo a charge.

Try the included fixture

Open evals/fixtures/react-shop/ in your agent and request the audit there. This synthetic fixture contains planted bugs and correct decoys. Keep the answer key in evals/expected/ out of the audit context. Review its report against the fixture afterward.

04 / ACCEPTANCE

Read the evidence first

A report is an investigation, not proof that the repository is bug-free. Use this checklist before turning findings into work items.

TERMINAL / REVIEW CHANGES
git status --short
git diff

Expected report sections: executive summary, structural metrics and inventory, detailed findings, and a prioritized remediation roadmap. Choose specific finding IDs for a separate implementation request.

05 / MAINTENANCE

Update or remove

For Skills CLI installs, use its interactive commands to inspect updates or remove the skill. Select the installation scope and agent you originally used.

TERMINAL / SKILLS CLI
npx skills check
npx skills update state-machine-audit
npx skills remove state-machine-audit

These are separate actions: run only the line you need. For a Bash installation, run bash scripts/install.sh --uninstall --agent claude from the clone, substituting your original agent and scope flags. Removal deletes the installed skill copy, not reports in audited projects.

REFERENCE / RECOVERY

When something gets stuck

SymptomWhat to check
Agent cannot find the skillReopen the session. Check npx skills list and confirm the installation scope and selected agent.
Agent starts fixing codeStop the run. Restate the read-only request. Inspect the diff against your baseline before deciding which changes to undo.
References cannot be openedReinstall the complete skill folder. Copying only SKILL.md omits the rubric and report template.
Install command fails on NodeRun node --version. The current Skills CLI needs 22.20+; repository scripts need 18+.
No findings in a large repositoryRead the declared scope. Run another audit on a specific state-heavy module; zero findings is not full coverage.
Windows scorer test failsA known assertion expects forward slashes in a path. The last local run passed 14 of 15 tests; validation and adapter build passed. This does not establish an agent's audit quality.
REFERENCE / COVERAGE

Six ways state goes wrong

  1. Invalid combinations: independent booleans admit contradictory states.
  2. Illegal transitions: status writes bypass lifecycle rules.
  3. Async races: stale responses overwrite newer work.
  4. Failure boundaries: state and external side effects disagree.
  5. Hydration gaps: stored or incoming values are trusted without validation.
  6. Global interruptions: logout, cancellation, or recovery logic drifts across modules.

The audit skips generated and vendored code. An explicit state machine needs both a declared set of states and one place that determines legal transitions.

REFERENCE / DEVELOPMENT

Validate the skill itself

From the skill repository, these commands check the instructions, test the report scorer, and build agent adapters. They are maintainer tasks, not commands the audit should run in the target codebase.

TERMINAL / REPOSITORY CHECKS
npm run lint
npm test
npm run build

Real-agent evaluations require a configured agent and may use paid model calls. See the evaluation guide and recorded results and limitations.