SKILL.md
State Safety & Action Creator Guard
Ensure global state remains consistent, immutable, and valid.
Workflow
- Use Action Creators
- Rule: Never dispatch raw objects (dispatch({ type: 'FOO' })). - Fix: Import from src/context/actionCreators.ts. - Cross-check: Verify reducer handling in src/context/gameReducer.ts. - Why: Centralizes logic and ensures payload shape.
- Enforce Invariants
- Money: Must be >= 0. - Harmony: Must be > 0 (or triggers Game Over). - Inventory: Items must be unique IDs.
- Check Reducer Logic
- Immutability: Use spread syntax ...state or immer (if available). - Clamping: Math.max(0, newState.money).
Example
Input: "Deduct 50 money for the venue fee."
Bad:
dispatch({ type: 'DEDUCT_MONEY', amount: 50 })
Good:
import { createUpdatePlayerAction } from 'src/context/actionCreators'
if (player.money >= 50) {
// Use createUpdatePlayerAction with object payload
dispatch(createUpdatePlayerAction({ money: Math.max(0, player.money - 50) }))
} else {
console.error('Insufficient funds')
}
Reducer Check:
case 'UPDATE_PLAYER':
return {
...state,
player: {
...state.player,
...action.payload
}
};
Output: "Updated dispatch to use createUpdatePlayerAction with validation check player.money >= 50."
Skill sync: compatible with React 19.2.8 / Vite 8.2.2 / Tailwind 4.3.3 baseline as of 2026-05-20.