ワンクリックで
stateful-workflows
Create and manage XState-based stateful workflows with human-in-the-loop support via MCP tools
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Create and manage XState-based stateful workflows with human-in-the-loop support via MCP tools
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Deterministic communication metrics for the mirrored Teams channels. Computes reply-latency distributions, after-hours share, burst/fragmentation index, unanswered blockers, and interruption-cascade depth from data/teams/*/messages.jsonl, and refreshes the hyperscreen dashboard data. Use before making ANY quantitative claim about team communication.
Generate an interactive "application simulator" — a tiny, agent-built React mock of an external app (SAP MD04, a CRM, an ERP form) that the trainee can click through. The trainee's clicks stream back to you via viewerState so you can coach in real time. Each simulator is a single self-contained HTML file under `out/simulators/<app>.simulator.html`. Use this skill when the expert asks for a simulator (often in the context of curriculum topic 4 "Werkzeuge") or when a guest asks "can I practice this somewhere?".
Co-author a new roleplay scenario with an expert. Interview the expert about the persona, topic, hints with point values, and evaluation criteria, draft the JSON, and on confirmation write it to roleplay/<slug>.roleplay.json. Use when the expert invokes "Author a roleplay scenario" from the menu, asks "let me add a customer call to practice", "I want to script a difficult buyer", or equivalent. The scenarios authored here are consumed at runtime by the roleplay-engine skill.
Maintains a project knowledge wiki at wiki/ as the agent's long-term memory, dynamically structured around the mission in wiki/_meta/mission.md. Use whenever the user shares a fact, decision, preference, requirement, or finding worth remembering; whenever the user says "remember this", "add to wiki", "we decided", "save", "note that", or "for the record"; whenever the user asks "what do we know about X", "have we considered Y", "what did we decide", "summarize what we have"; whenever a file in the project codebase contains information relevant to the mission and should be ingested; at the end of a session to consolidate findings; and at session start to load relevant context. Reads index first, deduplicates before writing, tracks provenance, appends history rather than overwriting, and creates stubs for mentioned-but-unresearched topics. Pure markdown, no embeddings, no external network.
Engineering Design Support System. Use this skill whenever the user is doing long-horizon product/engineering design and wants to capture intent, decisions, risks, assumptions, evidence, open questions, or hypotheses; whenever they say 'add a decision', 'propose a hypothesis', 'what did we rule out', 'what changed', 'generate a status report', 'show whitespots', 'sharpen this', 'mission', 'realign', or ask what the project knows; at session start to load mission + state; and as the curator/researcher/synthesizer/critic loops. The mission is the versioned north star; the RDF knowledge graph is the system of record for a typed dependency graph (Concept/Decision/Risk/Assumption/Evidence/OpenQuestion/Gap/Whitespot/Hypothesis/Test); the scrapbook is a projected view; the wiki is synthesized prose; hypotheses run as stateful workflows. Pull-only: never push to the engineer except a critic mission-contradiction.
Use this skill whenever the user wants to take structured notes, collect ideas, organize project requirements, or manage a project notebook — trigger on phrases like 'scrapbook', 'add a note', 'what have we captured', 'notebook', 'show my notes', 'what should I focus on', 'jot this down', or any request to review, prioritize, or organize project items. Reads and writes to the project scrapbook via MCP tools, presenting content as a structured hierarchy with priorities and focus levels.
| name | stateful-workflows |
| description | Create and manage XState-based stateful workflows with human-in-the-loop support via MCP tools |
This skill enables you to create, manage, and advance stateful workflows using the workflows MCP tools. Workflows are XState v5 state machines stored as JSON files that track multi-step processes with automatic persistence and optional human-in-the-loop integration.
Use this skill when the user asks you to:
All workflow MCP tools require a project_name parameter. Extract the project folder name from your current working directory. For example, if your working directory is /workspace/my-project, pass project_name: "my-project".
Creates a new workflow from an XState v5 machine configuration.
project_name (string, required): The project directory namename (string, required): Human-readable workflow namedescription (string): What this workflow doesmachine_config (object, required): XState v5 machine definition (see format below)tags (array of strings): Optional tags for categorizationSends an event to advance a workflow to a new state. If the new state has waitingFor: "human_chat", an interactive dialog is automatically shown to the user.
project_name (string, required)workflow_id (string, required): The workflow ID (slug derived from name, e.g., "customer-onboarding")event (string, required): Event name matching a transition in the current statedata (object): Optional event payloadGet current state, available transitions, and whether the workflow is waiting for human input.
project_name (string, required)workflow_id (string, required)List all workflows for the project with summary info.
project_name (string, required)tag (string): Optional filter by tagstate (string): Optional filter by current stateGet the full workflow definition including machine config, persisted state, and transition history.
project_name (string, required)workflow_id (string, required)Delete a workflow permanently.
project_name (string, required)workflow_id (string, required)Register a condition monitoring rule that triggers a workflow state transition when an event matches. Connects real-time events (Email, MQTT, Filesystem, Webhook) to workflow transitions.
project_name (string, required)rule_name (string, required): Human-readable name for the trigger ruleworkflow_id (string, required): Target workflow slugworkflow_event (string, required): Event name to send to the workflow (must match a transition)condition (object, required): Event condition to match (see condition types below)map_payload (boolean): If true (default), passes the triggering event's full payload as dataRemove condition monitoring rules. Pass rule_id to delete a specific rule, or workflow_id to remove all triggers for that workflow.
project_name (string, required)rule_id (string): Specific rule ID to deleteworkflow_id (string): Delete all triggers for this workflowList all condition monitoring rules that trigger workflows.
project_name (string, required)workflow_id (string): Optional filter by workflowThe machine_config parameter must be a valid XState v5-style JSON object:
{
"initial": "draft",
"states": {
"draft": {
"on": { "SUBMIT": "pending_review" },
"meta": {
"label": "Draft",
"description": "Document is being drafted"
}
},
"pending_review": {
"on": {
"APPROVE": "approved",
"REJECT": "draft",
"REQUEST_CHANGES": "draft"
},
"meta": {
"label": "Pending Review",
"description": "Waiting for reviewer approval",
"waitingFor": "human_chat",
"waitingMessage": "A document is pending your review. Please approve, reject, or request changes."
}
},
"approved": {
"type": "final",
"meta": {
"label": "Approved",
"description": "Document has been approved"
}
}
}
}
Each state can have:
on: Object mapping event names to target state names (e.g., { "APPROVE": "approved" })type: Set to "final" for terminal states that cannot be advancedmeta: Metadata object with:
label: Human-readable display name for the statedescription: What this state representswaitingFor: Human-in-the-loop marker. Values:
"human_chat" -- automatically shows an elicitation dialog to the user in the chat"human_email" -- indicates this state awaits an email response"external" -- waiting for an external system or triggerwaitingMessage: Message displayed to the human when the workflow enters this stateemailSubjectFilter: For email-based responses, the subject filter to match incoming emailsonEntry: State-entry action configuration. When the workflow enters this state, either a prompt or a Python script is automatically executed. Supports two mutually exclusive modes:
promptFile (string): Filename of a .prompt file in workflows/ (e.g., "process-email.prompt"). Optional maxTurns (number, default 20). The prompt advances the workflow by calling workflow_send_event from within the prompt.scriptFile (string): Filename of a .py file in workflows/scripts/ (e.g., "process-data.py"). Optional timeout in seconds (default 300). The script receives workflow context as JSON via stdin. Use onSuccess (string) and onError (string) to specify event names that are automatically sent after script completion or failure, advancing the workflow to the next state.When a workflow transitions into a state with waitingFor: "human_chat", the system automatically displays an interactive dialog to the user. The dialog presents the available transitions as action choices. When the user responds, the workflow is automatically advanced.
You do not need to do anything special -- just create the state with the right meta fields and send the event that transitions into it. The system handles the rest.
Example flow:
waitingFor: "human_chat"workflow_send_event with event "SUBMIT" to enter the review stateFor email-based human-in-the-loop, you orchestrate the flow using the existing email MCP tools:
Create the workflow with an email waiting state:
"awaiting_email": {
"on": { "APPROVE": "approved", "REJECT": "rejected" },
"meta": {
"waitingFor": "human_email",
"waitingMessage": "Waiting for email approval",
"emailSubjectFilter": "APPROVAL:"
}
}
Send the approval email using the email_send MCP tool:
APPROVAL: [Workflow Name] - [Workflow ID]Poll for responses using the email_check_inbox MCP tool:
APPROVAL: [Workflow ID]Advance the workflow by calling workflow_send_event with the appropriate event based on the email response.
For states waiting on external systems, use waitingFor: "external". The workflow persists in this state until you explicitly send an event to advance it. This is useful for integrations where another system or scheduled task will trigger the next step.
Workflows can be triggered automatically by real-time events from the condition monitoring system. Use workflow_register_trigger to connect events (email, MQTT sensors, filesystem changes, webhooks) directly to workflow state transitions.
Available event groups:
Email -- Incoming emails (IMAP). Event name: "Email Received"MQTT -- IoT sensor messages. Event name: "MQTT Message Received"Filesystem -- File/directory changes. Event names: "File Created", "File Modified", "File Deleted"Webhook -- HTTP webhook payloads. Event name: "Webhook Received"Claude Code -- User interactions. Event names: "UserPromptSubmit", "PostToolUse"Condition types for triggers:
Simple (exact match):
{"type": "simple", "event": {"group": "Email", "name": "Email Received"}}
Simple with payload filter (wildcards supported):
{"type": "simple", "event": {"group": "Email", "payload.Subject": "APPROVAL:*"}}
Email semantic (natural language):
{"type": "email-semantic", "criteria": "emails about invoice approvals"}
Example: Email triggers approval workflow
workflow_create with machine_config that has "EMAIL_RECEIVED" transition
email-semantic with criteria "Any email is fine" to let all emails pass, or describe specific filtering criteria):workflow_register_trigger:
project_name: "my-project"
rule_name: "Email triggers approval"
workflow_id: "document-approval"
workflow_event: "EMAIL_RECEIVED"
condition: {"type": "email-semantic", "criteria": "Any email is fine"}
workflow_list_triggers:
project_name: "my-project"
workflow_id: "document-approval"
workflow_unregister_trigger:
project_name: "my-project"
workflow_id: "document-approval"
Example: Sensor alert triggers escalation
{
"initial": "monitoring",
"states": {
"monitoring": {
"on": { "SENSOR_ALERT": "alert_received" },
"meta": { "label": "Monitoring", "description": "Waiting for sensor data" }
},
"alert_received": {
"on": { "ACKNOWLEDGE": "investigating", "ESCALATE": "escalated" },
"meta": {
"label": "Alert Received",
"waitingFor": "human_chat",
"waitingMessage": "Sensor alert received. Acknowledge or escalate?"
}
},
"investigating": {
"on": { "RESOLVE": "resolved", "ESCALATE": "escalated" },
"meta": { "label": "Investigating" }
},
"escalated": {
"on": { "RESOLVE": "resolved" },
"meta": { "label": "Escalated", "waitingFor": "human_email", "waitingMessage": "Escalated for management review" }
},
"resolved": {
"type": "final",
"meta": { "label": "Resolved" }
}
}
}
workflow_register_trigger:
project_name: "my-project"
rule_name: "MQTT error triggers alert"
workflow_id: "sensor-escalation"
workflow_event: "SENSOR_ALERT"
condition: {"type": "simple", "event": {"group": "MQTT", "payload.message.status": "error"}}
Now, whenever an MQTT message with status: "error" arrives, the workflow automatically transitions from monitoring to alert_received, and the user sees an elicitation dialog to acknowledge or escalate.
When the user asks you to connect events to workflows, you should:
workflow_createworkflow_register_trigger for each event sourceworkflow_list_triggers to confirm the setupStates can have onEntry actions that automatically execute a .prompt file when the workflow enters that state. The prompt is executed via the Claude unattended endpoint with full workflow context (previous state, current state, triggering event, event data).
Prompt files are stored as .prompt files in the project's workflows/ directory. They can be viewed and edited in the frontend file browser (rendered as an editable Monaco editor with a save button).
Example: Auto-process incoming emails
.prompt file at workflows/process-email.prompt:You received an email as part of a workflow. Review the email content provided above in the Event Data section.
1. Extract the key information from the email
2. Determine if this is an approval, rejection, or needs further review
3. Based on your analysis, advance the workflow by calling workflow_send_event with the appropriate event (APPROVE, REJECT, or REQUEST_INFO)
onEntry on the processing state:{
"initial": "waiting_for_email",
"states": {
"waiting_for_email": {
"on": { "EMAIL_RECEIVED": "processing_email" },
"meta": { "label": "Waiting for Email", "waitingFor": "external" }
},
"processing_email": {
"on": { "APPROVE": "approved", "REJECT": "rejected", "REQUEST_INFO": "waiting_for_email" },
"meta": {
"label": "Processing Email",
"description": "AI is analyzing the email",
"onEntry": { "promptFile": "process-email.prompt" }
}
},
"approved": {
"type": "final",
"meta": { "label": "Approved" }
},
"rejected": {
"type": "final",
"meta": { "label": "Rejected" }
}
}
}
email-semantic with "Any email is fine" to accept all emails):workflow_register_trigger:
rule_name: "Email triggers processing"
workflow_id: "email-processor"
workflow_event: "EMAIL_RECEIVED"
condition: {"type": "email-semantic", "criteria": "Any email is fine"}
Now, when an email arrives: the trigger sends EMAIL_RECEIVED → workflow transitions to processing_email → the process-email.prompt file is automatically executed with the email payload → Claude analyzes the email and calls workflow_send_event to advance to the next state.
When the user asks you to create workflows with automated processing, you should:
.prompt or .py script is more suitable for each state (see guidance below)workflows/ or workflows/scripts/onEntry pointing to the right file on each processing stateFor deterministic tasks, use Python scripts instead of prompts. Scripts are stored in workflows/scripts/ and receive workflow context via stdin as JSON. After execution, the workflow is automatically advanced using the onSuccess and onError events configured in onEntry. All executions are logged in JSONL format to workflows/scripts/logs/.
Script context (received via stdin):
{
"workflow_id": "data-pipeline",
"workflow_name": "Data Pipeline",
"previous_state": "waiting",
"new_state": "processing",
"event": "DATA_RECEIVED",
"data": { "payload": { "file": "report.csv" } },
"project": "my-project",
"workspace_dir": "/workspace/my-project"
}
Auto-advancement: Scripts do not need to call any API to advance the workflow. Configure onSuccess and onError in the onEntry block:
onSuccess: Event sent automatically when the script exits with code 0 (e.g., "COMPLETE")onError: Event sent automatically when the script exits with a non-zero code or times out (e.g., "ERROR")Example: Process CSV data with Python
workflows/scripts/process-csv.py:# requirements: pandas
import sys, json, pandas as pd
from pathlib import Path
context = json.load(sys.stdin)
workspace = Path(context['workspace_dir'])
payload = context['data'].get('payload', {})
# Read source file
source_file = workspace / 'out' / payload.get('file', 'data.csv')
df = pd.read_csv(source_file)
# Process
summary = {
'rows': len(df),
'columns': list(df.columns),
'stats': df.describe().to_dict()
}
# Write result
output_file = workspace / 'out' / 'summary.json'
output_file.write_text(json.dumps(summary, indent=2))
print(f"Processed {len(df)} rows, summary written to out/summary.json")
# Exit code 0 → onSuccess event "COMPLETE" is sent automatically
onEntry including onSuccess and onError:{
"initial": "waiting",
"states": {
"waiting": {
"on": { "DATA_RECEIVED": "processing" },
"meta": { "label": "Waiting", "waitingFor": "external" }
},
"processing": {
"on": { "COMPLETE": "done", "ERROR": "failed" },
"meta": {
"label": "Processing",
"onEntry": { "scriptFile": "process-csv.py", "timeout": 60, "onSuccess": "COMPLETE", "onError": "ERROR" }
}
},
"done": { "type": "final", "meta": { "label": "Done" } },
"failed": { "type": "final", "meta": { "label": "Failed" } }
}
}
Important: Always specify onSuccess and onError for script-based entry actions so the workflow advances automatically. The script itself should only focus on its task and use sys.exit(0) for success or sys.exit(1) for failure.
Script dependency management:
# requirements: pandas, requests comment at the top of your scriptpip install before executionScript logging:
All script executions are logged to workflows/scripts/logs/<YYYY-MM-DD>.jsonl with entries for called, succeeded, and error events.
Use a .prompt file when:
Use a .py script when:
When in doubt, ask the user: "This task could be handled by either an AI prompt (better for reasoning and flexibility) or a Python script (better for speed and deterministic processing). Which would you prefer?"
SUBMIT, APPROVE, REJECT, CANCEL, TIMEOUTpending_review, awaiting_approval, in_progressmeta.label for each state for readability"type": "final"waitingMessage for human-in-the-loop states["approval", "content"])User: "Create a content approval workflow where I review blog posts before publishing"
You should:
draft -> submitted -> under_review (waitingFor: human_chat) -> approved/needs_revision -> published (final)workflow_create with the configUser: "What workflows do I have and what state are they in?"
You should:
workflow_list to get all workflowsUser: "Approve the blog post workflow"
You should:
workflow_list to find the relevant workflowworkflow_get_status to check current state and available eventsworkflow_send_event with the appropriate event (e.g., "APPROVE")Workflows are stored at workspace/<project>/workflows/<slug>.workflow.json where the slug is derived from the workflow name (e.g., customer-onboarding.workflow.json). These files can be viewed in the frontend file browser, which renders them as interactive state machine graphs with the current state highlighted.