Create Square Workflow classes (StatefulWorkflow or StatelessWorkflow). Use when creating workflows, implementing state machines, handling async operations with Workers, or when user mentions "new workflow", "workflow", "state machine", or "StatefulWorkflow".
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
create-workflow
description
Create Square Workflow classes (StatefulWorkflow or StatelessWorkflow). Use when creating workflows, implementing state machines, handling async operations with Workers, or when user mentions "new workflow", "workflow", "state machine", or "StatefulWorkflow".
Create Workflow
Create properly structured Square Workflow classes following library conventions.
Quick Start
To create a new workflow, gather:
Workflow name (e.g., Login)
Stateful or Stateless — does it need internal state?
Props — input data from parent (Unit if none)
Output — events emitted to parent (Nothing if none)
Rendering — UI model returned each render pass (typically a Screen data class)
Step 1: Choose Workflow Type
StatefulWorkflow — use when you need internal state:
Form data, loading states, error states
Multi-step flows or navigation
State that changes in response to events
StatelessWorkflow — use when rendering is a direct function of props:
Simple pass-through or composition of child workflows
No internal state needed
Rendering derived entirely from props and child renderings
Step 2: Define Types
Props (input from parent)
dataclassMyWorkflowProps(val userId: String)
// Or use Unit if no props needed
State (StatefulWorkflow only)
State should use any Kotlin types - often a data class. If your state needs to be persisted
to disk via a Snapshot it needs to be able to be converted to a ByteString.
// Simple statedataclassMyState(val name: String, val isLoading: Boolean)
// Sealed state for distinct modessealedinterfaceMyState {
dataobject Loading : MyState
dataclassLoaded(valdata: String) : MyState
dataclassError(val message: String) : MyState
}
Output (events to parent)
// Multiple output typessealedinterfaceMyOutput {
dataobject Completed : MyOutput
dataclassSelected(val item: Item) : MyOutput
}
// Or use Nothing if no output is ever emitted
Rendering (view model)
Create in a separate file named [Feature]Screen.kt:
dataclassMyScreen(
val title: String,
val isLoading: Boolean,
val onAction: () -> Unit,
val onItemSelected: (Item) -> Unit
) : Screen
Step 3: Create Workflow Class
StatefulWorkflow — Object Pattern (no dependencies)
Use when the workflow has no injected dependencies:
Never perform side effects in render() — render is called multiple times per state.
Use runningWorker or runningSideEffect.
Don't capture renderState in lambdas — In eventHandler and action blocks, use the
state property from the Updater receiver, not the renderState parameter.
Always provide name to eventHandler — Required for Compose stability and debugging.
Use setOutput() to emit output — Call at most once per action.
Return null from snapshotState unless you need state persistence across process death.
Naming Conventions
Type
Convention
Example
Workflow
[Feature]Workflow
LoginWorkflow
Props
[Feature]Props or Unit
LoginProps
State
[Feature]State or nested type
LoginState
Output
[Feature]Output or Nothing
LoginOutput
Rendering
[Feature]Screen (separate file)
LoginScreen
File Organization
feature/
├── MyWorkflow.kt # Workflow + Props + State + Output
└── MyScreen.kt # Rendering class (separate file)