$npx -y skills add easyzoom/aix-skills --skill embedded-state-machine-libsUse when integrating, designing, configuring, or debugging embedded StateMachine libraries, finite state machines, event transitions, or MCU state-driven workflows
| 1 | # Embedded State Machine Libs |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill for embedded state machine libraries and hand-written finite state machines. The core is to make states, events, transitions, side effects, and invalid transitions explicit and verifiable. |
| 6 | |
| 7 | ## When To Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - The user wants to add or debug a StateMachine library or event-driven MCU workflow. |
| 12 | - The issue involves wrong transitions, stuck states, reentrancy, event loss, timeout handling, or unclear state ownership. |
| 13 | - Firmware has modes such as idle, init, run, error, recovery, upgrade, sleep, or calibration. |
| 14 | |
| 15 | Do not use this skill for RTOS scheduling issues unless the state machine is the primary abstraction. |
| 16 | |
| 17 | ## First Questions |
| 18 | |
| 19 | Ask for: |
| 20 | |
| 21 | - State machine library or custom implementation. |
| 22 | - State list, event list, and current failing transition. |
| 23 | - Whether transitions run in ISR, task, main loop, or callback context. |
| 24 | - Whether timeouts, retries, or external interrupts drive events. |
| 25 | - Expected behavior for invalid events. |
| 26 | |
| 27 | ## Integration Checklist |
| 28 | |
| 29 | 1. Define states and events. |
| 30 | Names should reflect system meaning, not implementation steps. |
| 31 | |
| 32 | 1. Separate transition from action. |
| 33 | Make it clear what changes state and what side effects run because of the transition. |
| 34 | |
| 35 | 1. Define invalid event behavior. |
| 36 | Ignore, log, assert, error transition, or recovery must be explicit. |
| 37 | |
| 38 | 1. Guard reentrancy. |
| 39 | Avoid nested transitions unless the library explicitly supports them. |
| 40 | |
| 41 | 1. Add observability. |
| 42 | Log state transitions, current state, event source, and error transitions. |
| 43 | |
| 44 | 1. Test transition table. |
| 45 | Validate normal path, invalid events, timeout events, and recovery path. |
| 46 | |
| 47 | ## Common Failures |
| 48 | |
| 49 | - Event emitted from ISR directly mutates state unsafely. |
| 50 | - Timeout event races with success event. |
| 51 | - State transition has hidden side effects that fail halfway. |
| 52 | - Invalid events are silently ignored in safety-critical flows. |
| 53 | - State names mirror functions instead of product behavior. |
| 54 | |
| 55 | ## Verification |
| 56 | |
| 57 | Before claiming state-machine behavior works: |
| 58 | |
| 59 | - State the state list, event list, transition rules, and invalid-event policy. |
| 60 | - Confirm normal, timeout, error, and recovery transitions. |
| 61 | - Confirm event source and reentrancy strategy. |
| 62 | - Confirm transition logging or trace output exists for debugging. |
| 63 | |
| 64 | ## Example |
| 65 | |
| 66 | User: |
| 67 | |
| 68 | ```text |
| 69 | 设备升级状态机偶尔卡在 downloading。 |
| 70 | ``` |
| 71 | |
| 72 | Agent: |
| 73 | |
| 74 | 1. Asks for states, events, timeout handling, and transition logs. |
| 75 | 1. Checks whether success/error/timeout events race. |
| 76 | 1. Verifies recovery transitions and invalid event behavior. |