agentleFS
lbdremylbdremy/phax/.claude/skills/state-machines/SKILL.md

state-machines

Skill2 starsChanged 5 months agoApache-2.0View on GitHub

Transition RunState and PhaseState only through the explicit functions in src/domain/state.ts — never mutate state-bearing fields directly.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

State machines

The rule

RunState and PhaseState transitions must go through the explicit transition functions in src/domain/state.ts. Direct assignment or mutation of state-bearing fields outside that module is a violation.

State shapes

// src/domain/state.ts
type RunState =
  | "created"
  | "running"
  | "failed"
  | "review_open"
  | "completed"
  | "stopped"
  | "archived"
  | "interrupted";

type PhaseState =
  | "pending"
  | "setting_up_worktree"
  | "running"
  | "gates_failed"
  | "fixing"
  | "failed"
  | "passed"
  | "committed"
  | "cleaning_up"
  | "cleaned_up"
  | "review_open"
  | "handoff_failed"
  | "skipped";

Transition functions

Each transition function takes the current state and returns Result.Result<NewState, InvalidTransitionError>. Call-sites must handle the Failure (invalid transition) case.

import { startRun, failRun, openRunReview } from "../domain/state.js";
import { Result } from "effect";

const next = startRun(currentState);
if (Result.isFailure(next)) {
  // surface InvalidTransitionError — never silently swallow it
}

Why

Direct string assignment bypasses the transition guard. This means illegal state sequences (e.g., archived → running) become possible, which corrupts registry.json and run-status.json in ways that are hard to detect.

The Result-returning pattern forces callers to handle illegal transitions explicitly rather than producing silent corrupt state.

How to fix a violation

  1. Find the direct state field assignment (e.g., status.runState = "running").
  2. Replace with the appropriate transition function from src/domain/state.ts.
  3. Handle the Failure case and surface the InvalidTransitionError.

Audit rule

PHAX_STATE_001 — direct assignment to a state-bearing type field detected outside domain/state.ts.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.