Logo van Eng State Machine

Eng State Machine

Community
jpoehnelt
eng-state-machine

Model an entity's lifecycle (status, state, phase) as an explicit state machine with a pure decide function, one guarded write path, and events from a durable record. Use when adding or changing a status field, a transition, or a reaction to one, when several writers set the same status, or when moving ad hoc status writes onto a machine.

Overzicht

Uitgeverjpoehnelt
Repositoryskills
Skillnaameng-state-machine
Sterren
23
Forks
1
Meegeleverde bestanden
Alleen instructies
LicentieMIT
Links
  • Instructies in Markdown

    Het model laadt het bestand SKILL.md alleen als dat nodig is. Dat kost dus alleen tokens als een verzoek daadwerkelijk bij de skill past.

  • Werkt met elk LLM

    AI-skills bestaan uit instructies in gewone Markdown, niet uit aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Compleet zonder extra bestanden

    Alles wat het model nodig heeft, staat in de instructies — geen extra bestanden om te synchroniseren.

  • Open source

    Gepubliceerd door jpoehnelt op GitHub. Bekijk de bronbestanden voordat je de skill installeert.

Installatie

Installeer de AI-skill Eng State Machine in TypingMind om deze met elk LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map. De app leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/jpoehnelt/skills/tree/main/eng-state-machine
  4. Schakel de skill in voor elke chat waarin je de skill wilt kunnen gebruiken.
Plug-ins → Skills → Skill toevoegen → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/jpoehnelt/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/eng-state-machine .claude/skills/eng-state-machine
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Eng State Machine in voor een chat naar keuze in TypingMind en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek bij de skill past, laadt het model zelf de volledige instructies. Je hoeft de skill nooit handmatig aan te roepen. Pas als het model de skill daadwerkelijk gebruikt, kost dat tokens.

Het model laadt Eng State Machine automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Eng State Machine niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

State machines for entity lifecycles

A status column that any code path can set drifts: two writers race, a rejected move succeeds from a stale read, an event fires for a write that rolled back, and the rules end up in scattered if checks that nobody owns. Give each lifecycle one machine and one way to change it.

Use one when more than one code path changes the status, a move has preconditions, or other work reacts to a move. A flag with one writer and no reactions stays a boolean.

Repo facts (from AGENTS.md or CLAUDE.md): the machine helper and where machines live, the transition write helper and the transaction API, where transition history or an outbox lives, the lint or check that flags direct status writes, the error convention for rejected moves, and the test runner.

Define the machine

  • States and moves, in one place. List every state, every command, and each allowed from -> to move. Mark the states a new entity starts in and any terminal states. A lifecycle that cycles (open, closed, open again) has no terminal state, and that is valid. Name states and commands in domain terms (approve, cancelled), not UI or storage terms.
  • Decide every (state, command) pair. Each pair not listed as a move is either rejected or an explicit no-op. Repeating a command that already took effect (archive an archived entity) is usually a no-op so retries stay safe; anything else is a rejection. An unhandled pair is how illegal moves slip through.
  • Modes live in the status, data lives beside it. No boolean that restates the status (isArchived next to status = 'archived'). Per-state data is a union: a cancelled entity carries its reason, an active one does not.
  • Derived statuses are never stored. If a status follows from other fields (ready when every check passed, expired when expires_at is past), compute it on read. A stored copy is a second source of truth that drifts, and a stored "expired" needs a job that can fall behind.
  • Encode current behavior. When moving existing writes onto a machine, allow every move the code makes today, even odd ones. Tightening a move is a product change. Make it in its own commit, or mark the permissive move with a TODO naming the open decision.
  • Stored state names are a contract. Renaming or removing a state needs a data migration for rows in the old state and a check of every consumer of its events.

Decide purely

decide(current, command) returns the accepted transition, a no-op, or a typed rejection. It is synchronous and does no I/O. Time, actor, and any data a guard needs come in as arguments.

ts
type Decision<S> =
  | { kind: "moved"; from: S; to: S }
  | { kind: "unchanged"; state: S }
  | { kind: "rejected"; from: S; command: string; reason: string };

The caller turns a rejection into the owning module's error at the write site. Because guards take their data as input, the same rule runs in tests, in previews ("can I archive this?"), and in the write. Time-based moves (expiry, timeouts) are commands too. A scheduler sends them with the current time, and decide checks the deadline. In an Effect repo, effect shows how these parts map onto Effect.

Write through one path

  1. Read the current state inside the transaction, with at most one row lock on the entity, or use a guarded update.
  2. Run decide. On unchanged, return without writing.
  3. Write the new state guarded on the decided from (UPDATE ... SET status = :to WHERE id = :id AND status = :from). Zero rows updated means a concurrent move won. Retry from step 1 or return a conflict. Never write unguarded.
  4. Record the transition (id, entity, from, to, actor, time) in the same transaction, as history or an outbox row.

No other code sets the status field. Add a lint or grep check that flags writes to it outside the write helper, so a new writer fails CI instead of review.

React to transitions

  • Send events from the durable record. An outbox drain or a log consumer publishes <machine>.transitioned. Sending from the writer after commit loses the event when the process dies between commit and send; sending before commit announces a move that may roll back.
  • When the store has no transaction for an outbox (an object store, an external API), make the conditional write first, then send from a retried step with a deterministic transition id.
  • Reactions are idempotent and order-tolerant. Delivery is at least once. Deduplicate on the transition id, accept events out of order, and reread current state instead of trusting the payload. A reaction that changes another entity goes through that entity's machine.

Migrating ad hoc status writes

  1. Inventory every writer: assignments to the field, raw SQL updates, ORM set calls, fixtures, and booleans that shadow the status.
  2. Map each write to a command and a from -> to move. Record moves the code makes today even if they look wrong.
  3. Add the machine and the write helper. Move writers over one at a time, each with a check that the old write is gone.
  4. Add the lint check last, once no writer is left outside the helper. Prove the removal with eng-cutover-verification.

Tests

  • Check the graph. Every move names states that exist, and every state is reachable from a starting state. When the machine declares terminal states, every other state can reach one and no terminal state has an outgoing move. Run this as one test over the machine definition.
  • Test decide with a table over every (state, command) pair: each move, each no-op, and each rejection. It is pure, so the table is fast and complete.
  • Test the write helper once for concurrency: two moves from the same from, and exactly one applies. With a row lock the second call waits, reads the new state, and decide rejects it or returns a no-op. With a lock-free guarded update the second gets a conflict.
  • Reactions get one test for a duplicate event and one for an out-of-order event.
  • For complex machines, a property-based stateful test (for example Hypothesis RuleBasedStateMachine or fast-check model-based testing) runs random command sequences and checks invariants after every step.

Review checklist

  • Every state, move, and terminal state is listed in one machine, and every (state, command) pair is a move, a no-op, or a rejection.
  • No boolean or stored field restates or derives the status.
  • decide is pure; time, actor, and guard data are arguments.
  • The write is guarded on from and records the transition in the same transaction.
  • No status write exists outside the helper, and a check enforces it.
  • Events come from the durable record; reactions deduplicate on the transition id and reread state.
  • The graph test passes: every state is reachable, and when terminal states are declared, every other state can reach one and none has an outgoing move.
  • A refactor allows every move the old code made; tightening is a separate, named decision. A renamed state ships with a data migration.

Veelgestelde vragen

Wat doet de AI-skill Eng State Machine?

Model an entity's lifecycle (status, state, phase) as an explicit state machine with a pure decide function, one guarded write path, and events from a durable record. Use when adding or changing a status field, a transition, or a reaction to one, when several writers set the same status, or when moving ad hoc status writes onto a machine.

Waarom Eng State Machine gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Eng State Machine bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model. Ook als je midden in een chat van model wisselt, blijft de skill werken. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek af te sluiten. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Eng State Machine in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/jpoehnelt/skills/tree/main/eng-state-machine. TypingMind leest het bestand SKILL.md en installeert het als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Eng State Machine gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Eng State Machine gebruiken?

Zoveel als je wilt. Je kunt Eng State Machine gebruiken met elk model dat skills ondersteunt, zoals GPT, Claude, Gemini, Grok, DeepSeek, Mistral of Llama. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Eng State Machine gratis?

Ja. Deze skill is door jpoehnelt op GitHub gepubliceerd onder de licentie MIT. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. De skill volgt het open Agent Skills-formaat: het bestand SKILL.md bevat de naam en beschrijving van de skill. Daarnaast kan de skill scripts, sjablonen of referentiebestanden bevatten die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Bekijk alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇