From harness-claude
Models concurrent, independent state regions using XState parallel states. Useful for UI with independent concerns (e.g., bold and italic in a text editor) or concurrent processes (e.g., upload with validation).
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:xstate-parallel-statesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Model concurrent, independent state regions that are active simultaneously within a single machine
Model concurrent, independent state regions that are active simultaneously within a single machine
type: 'parallel' on the parent state node. All direct child states become active simultaneously.initial property — all children start in their own initial states simultaneously.onDone on the parallel parent to react when ALL child regions reach their final states.// text-editor.machine.ts
import { createMachine } from 'xstate';
const textEditorMachine = createMachine({
id: 'editor',
type: 'parallel',
states: {
bold: {
initial: 'off',
states: {
off: { on: { TOGGLE_BOLD: 'on' } },
on: { on: { TOGGLE_BOLD: 'off' } },
},
},
italic: {
initial: 'off',
states: {
off: { on: { TOGGLE_ITALIC: 'on' } },
on: { on: { TOGGLE_ITALIC: 'off' } },
},
},
underline: {
initial: 'off',
states: {
off: { on: { TOGGLE_UNDERLINE: 'on' } },
on: { on: { TOGGLE_UNDERLINE: 'off' } },
},
},
},
});
// State value when bold is on, italic off, underline on:
// { bold: 'on', italic: 'off', underline: 'on' }
// Multi-step upload with parallel validation
const uploadMachine = createMachine({
id: 'upload',
initial: 'preparing',
states: {
preparing: {
on: { START: 'processing' },
},
processing: {
type: 'parallel',
states: {
upload: {
initial: 'uploading',
states: {
uploading: {
invoke: { src: 'uploadFile', onDone: 'done', onError: 'error' },
},
done: { type: 'final' },
error: {},
},
},
validation: {
initial: 'validating',
states: {
validating: {
invoke: { src: 'validateFile', onDone: 'done', onError: 'error' },
},
done: { type: 'final' },
error: {},
},
},
},
// Fires when BOTH upload and validation reach 'done'
onDone: 'complete',
},
complete: { type: 'final' },
},
});
State values: For parallel states, state.value is an object where each key is a region name and each value is that region's current state. For nested parallels, values nest further.
Event handling: When an event is received, it is processed by ALL active regions. If both bold and italic handle RESET, both will transition. Be intentional about event naming to avoid unintended cross-region effects.
onDone completion: A parallel state's onDone fires only when every child region has reached a final state. If any region stays active, the parallel state stays active.
Without parallel states (combinatorial explosion): Modeling bold + italic + underline without parallel states would require 8 atomic states (off-off-off, on-off-off, ...). With parallel states, you need 6 (2 per region). This scales linearly instead of exponentially.
Transitions between regions: A region can target another region's state via a full ID path, but this is generally a code smell. If regions need tight coordination, they may not be truly parallel — consider a compound state instead.
Testing parallel machines: Check state.value as an object: expect(state.value).toEqual({ bold: 'on', italic: 'off' }).
https://stately.ai/docs/parallel-states
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeDefines statecharts with XState's createMachine for explicit states, transitions, context, and events. Useful for modeling complex UI flows and preventing illegal state transitions.
Builds, tests, and debugs event-driven state machines in Laravel using EventMachine. Activates on state machine definitions, behaviors, test assertions, parallel states, delegation, timers, and endpoints.
Models complex UI flows as finite state machines with states, events, transitions, actions, and guards. Useful for forms, data fetching, authentication flows, and wizards.