extract-state-machine

从枚举、状态字段、switch/match 语句和转换方法中检测并提取状态机,识别状态、转换、守卫条件和动作以构建状态图数据。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "extract-state-machine":https://skillpi.com/zh/skills/deepskill-5154b9eb1edbd8f9f2ee178465869e28a5bac22b0bd8959d4603bd061eb3d95f。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

从枚举、状态字段、switch/match 语句和转换方法中检测并提取状态机,识别状态、转换、守卫条件和动作以构建状态图数据。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
输入和输出
减记
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: extract-state-machine
description: Detects state machines from enums, status fields, switch/match statements, and transition methods. Extracts states, transitions, guards, and actions to build state diagram data.

State Machine Extractor

Overview

Identifies implicit and explicit state machines in code — status fields, enum-based states, transition methods, guard conditions, and actions. Produces structured state diagram data for visualization.

Detection Patterns

Enum-Based States

# Status/State enums
Grep: "enum.*(Status|State)" --glob "**/*.php"

# Backed enum cases
Grep: "case [A-Z]" --glob "**/*.php" -A 0
# Read full enum to get all cases

# Enum with methods (transition logic)
Grep: "function (canTransitionTo|allowedTransitions|next)" --glob "**/*.php"

Status Fields

# Status properties
Grep: "private.*\\$status|readonly.*Status|private.*Status \\$" --glob "**/*.php"

# Status setters/changers
Grep: "function (setStatus|changeStatus|updateStatus|transitionTo)" --glob "**/*.php"

# Status constants (legacy pattern)
Grep: "const STATUS_|const STATE_" --glob "**/*.php"

Transition Methods

# Named transition methods (domain verbs)
Grep: "function (activate|deactivate|approve|reject|cancel|complete|suspend|resume|archive|publish|draft|submit|confirm|expire|close|open|block|unblock|verify|process|ship|deliver|refund|pay)" --glob "**/Domain/**/*.php"

# Status check before transition (guard)
Grep: "if.*status.*!==|if.*status.*===|match.*status" --glob "**/*.php"

# Transition with event recording
Grep: "->(recordEvent|raise|apply).*new.*Event" --glob "**/*.php"

Switch/Match State Logic

# Match expression on status
Grep: "match.*\\(.*status|match.*\\(.*state|match.*\\(.*->getStatus" --glob "**/*.php"

# Switch on status
Grep: "switch.*\\(.*status|switch.*\\(.*state" --glob "**/*.php"

# State-dependent behavior
Grep: "case.*Status::|case.*State::" --glob "**/*.php"

Symfony Workflow Component

# Workflow configuration
Glob: "config/packages/workflow.yaml"
Glob: "config/packages/workflow.php"

# Workflow service usage
Grep: "WorkflowInterface|Workflow::" --glob "**/*.php"
Grep: "->can\\(|->apply\\(|->getMarking" --glob "**/*.php"

Analysis Process

Step 1: Find State Holders

For each entity/aggregate with a status field:

  1. Read the enum/status definition — get all possible states
  2. Find transition methods — methods that change the status
  3. Extract guards — conditions checked before transition
  4. Extract actions — what happens during/after transition
  5. Find events — events raised on transition

Step 2: Build Transition Table

For each transition method found:

Read the method body:
1. What is the source state? (guard/precondition)
2. What is the target state? (assignment/return)
3. What conditions must be met? (if/match checks)
4. What side effects occur? (events, notifications)

Step 3: Validate Completeness

  • Can every state be reached from the initial state?
  • Are there dead-end states (no outgoing transitions)?
  • Are there unreachable states?
  • Are all transitions guarded?

Output Format

## State Machines

### Summary

| Entity | States | Transitions | Has Guards | Events |
|--------|--------|-------------|-----------|--------|
| Order | 6 | 8 | Yes | 5 |
| Payment | 4 | 5 | Yes | 3 |
| User | 3 | 4 | Partial | 2 |

### Order State Machine

#### States

| State | Description | Terminal |
|-------|-------------|---------|
| `draft` | Order created but not submitted | No |
| `pending` | Submitted, awaiting payment | No |
| `confirmed` | Payment received | No |
| `shipped` | Items dispatched | No |
| `delivered` | Items received by customer | Yes |
| `cancelled` | Order cancelled | Yes |

#### Transitions

| # | From | To | Method | Guard | Action |
|---|------|----|--------|-------|--------|
| 1 | draft | pending | submit() | Has items | Validate totals |
| 2 | pending | confirmed | confirm() | Payment OK | Record payment |
| 3 | confirmed | shipped | ship() | Items packed | Send tracking |
| 4 | shipped | delivered | deliver() | Tracking confirms | Close order |
| 5 | draft | cancelled | cancel() | - | Release items |
| 6 | pending | cancelled | cancel() | - | Refund if paid |
| 7 | confirmed | cancelled | cancel() | Not shipped | Refund payment |

#### State Diagram Data (Mermaid-ready)

stateDiagram-v2 [] --> draft draft --> pending : submit() draft --> cancelled : cancel() pending --> confirmed : confirm() pending --> cancelled : cancel() confirmed --> shipped : ship() confirmed --> cancelled : cancel() shipped --> delivered : deliver() delivered --> [] cancelled --> [*]


#### Guards Detail

| Transition | Guard Condition | Error on Failure |
|-----------|-----------------|-----------------|
| submit() | Order has at least 1 item | "Cannot submit empty order" |
| confirm() | Payment amount matches total | "Payment mismatch" |
| ship() | All items available in warehouse | "Items not available" |
| cancel() | Status is not shipped/delivered | "Cannot cancel shipped order" |

#### Events Raised

| Transition | Event | Listeners |
|-----------|-------|-----------|
| submit() | OrderSubmitted | InventoryReserve, NotifyAdmin |
| confirm() | OrderConfirmed | SendConfirmation, StartPacking |
| ship() | OrderShipped | SendTracking, NotifyCustomer |
| deliver() | OrderDelivered | RequestReview, CloseTicket |
| cancel() | OrderCancelled | ReleaseInventory, RefundPayment |

State Machine Quality Indicators

Indicator Good Warning Critical
All transitions guarded Yes Partial No guards
No dead-end states No dead ends With purpose (terminal) Unreachable
Events on transitions All important Some None
Explicit state enum Yes Constants String literals
Transition methods named Domain verbs Generic setStatus Direct field set

Common Anti-Patterns

Anti-Pattern Detection Issue
String-based status $status = 'pending' No type safety
Direct field mutation $this->status = 'new' No guard enforcement
Missing transitions State reachable only via DB Bypasses domain logic
God transition One method handles all transitions No guard per transition

Integration

This skill is used by:

  • business-logic-analyst — documents state machines in domain
  • diagram-designer — generates state diagrams from extracted data
  • explain-business-process — references state transitions in workflows

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供从代码中自动提取状态机的完整解决方案
  • 支持多种检测模式(枚举、状态字段、转换方法、Symfony Workflow)
  • 输出结构化数据与 Mermaid 图表,便于集成与可视化
触发精准90/100

亮点

  • 触发描述精准覆盖核心功能点
  • 提供具体 grep/glob 命令作为触发依据
  • 边界清晰,无歧义
结构规范90/100

亮点

  • 结构清晰:检测模式→分析流程→输出格式
  • 包含完整端到端示例(Order 状态机)
  • frontmatter 完整,文档长度适中
执行可靠90/100

亮点

  • 使用标准 Unix 工具(grep/glob),来源可靠
  • 参数设计合理,正则表达式准确
  • 包含状态机完整性验证逻辑
  • 纯分析工具,无不可逆操作风险
证据可验 (前四项均值)89/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。