跳到正文
GitHub·· 6 天前AI 评分38

StateForge:从现有代码中提取状态机并生成图表

9t29zhmwdh-coder/StateForge

AI 导读

StateForge 是一款原生桌面应用,可从 Swift、Kotlin、TypeScript、Go、Rust 源码、日志文件或自然语言描述中提取状态与转换关系,渲染为可编辑的交互式图表,并导出 Mermaid、DOT、SVG 或五种语言的生成代码。它支持本地 Ollama(默认)或通过 Anthropic API 调用 Claude 来增强或生成状态机,采用 MIT 协议开源。

正文

RayStudio Logo

🇩🇪 Deutsche Version

Draws the state machine that is already in your code, so you can see the transition nobody documented.

Every order status field is a state machine. Nobody drew it. It exists as scattered if branches and a status column, and the only way to know whether cancelled can go back to pending is to read every assignment in the file and hold them all in your head.

Paste the source, a log file, a web server access log or a description in plain words. StateForge extracts the states and transitions and renders them as a diagram you can edit, then exports Mermaid, DOT, SVG, or generated code in five languages.

Not for you if you are designing a new state machine. Write the Mermaid by hand; it is faster than a round trip through extraction. This earns its keep on code that already exists and nobody has drawn.

CI CodeQL OpenSSF Scorecard 6.3/10 OpenSSF Best Practices

Platform Rust Tauri AI | Claude Code AI | Copilot AI | Claude

How it runs: StateForge is a native desktop app, not a server or browser tool. It opens as its own window and has no tray icon or background service; it only extracts and renders while the window is open.

StateForge


💾 Download: macOS (DMG) · Windows (Installer) · Linux (AppImage): always the latest release, not code-signed/notarized (Gatekeeper/SmartScreen will warn on first run). Or build from source, see Getting Started below.


🌱 New here? → Step-by-step guide for beginners


StateForge's UI is available in English (default) and German; switch anytime with the language toggle.

In practice: you paste source code, a log file, or a natural-language description, StateForge extracts a state machine model and renders it as an interactive diagram you can edit, then export as Mermaid, DOT, SVG, or generated code in five languages.

Features

Feature Description
Code Parser Finds the state type and the transitions between states in Swift, Kotlin, TypeScript, Go and Rust: enums, sealed classes, union types and iota blocks; switch/when/match arms, if state == X guards, assignments such as state = .playing, _uiState.value = …, setStatus('done') and reducer returns. The event comes from the checked event or the function name. XState createMachine configs are read directly (top-level states)
Log Analyzer Rebuilds the flow from log lines that name a change: from X to Y, X -> Y, state changed to Y, or JSON lines with from/to/status, per entity (order=17). Web server access logs (nginx, Apache) become the sequence of API calls per client
Diagram Engine Renders Mermaid, GraphViz DOT, SVG, interactive React Flow
Code Generator Generates idiomatic state machine code in 5 languages
AI Integration Local Ollama (default) or Claude via the Anthropic API with your key: enhance a machine or create one from a plain-language description. "Auto AI Enhance" enhances every new extraction right away

Limits: extraction reads patterns, not a full parse tree. Nested XState machines and state changes spread across files are not followed; code that sets a state without checking the current one is drawn as reachable from every other state, which is what the code allows. Generated Swift, Rust and TypeScript are compile-checked in development; Go and Kotlin output is reviewed but not compiled.


Requirements


Quick Start

git clone https://github.com/9t29zhmwdh-coder/StateForge
cd StateForge

cd frontend && npm install && cd ..
cargo tauri dev

Usage

  1. Import; paste source code, a log file, or describe your flow in natural language
  2. Analyze; StateForge extracts states, transitions, events, and guards automatically
  3. Visualize; drag-and-drop diagram editor with live sync to the extracted model
  4. Generate; export clean state machine code in Swift, Kotlin, TypeScript, Go, or Rust

Uninstall / Cleanup

  • Delete the app bundle
  • Remove the local database: platform-specific app data directory (stateforge.db), resolved via Tauri's app_data_dir
  • Remove the stored API key from Keychain Access.app (search for "stateforge")

No other files or background services are left behind.


Supported Inputs

Input Formats
Swift Enums, TCA Reducers, @Observable / @Published
Kotlin Sealed classes, when expressions, ViewModel state
TypeScript XState createMachine, union types, Redux reducers
Go iota constants, switch FSMs, SetState() / Transition()
Logs key=value, JSON, Nginx, Docker, Syslog

Diagram Formats

Format Use Case
Interactive (React Flow) Drag-and-drop editing, live sync
Mermaid stateDiagram-v2 Markdown docs, GitHub
GraphViz DOT Advanced layout, CI pipelines
SVG Self-contained export, presentations

Author: Rafael Yilmaz · Status: Active · version · License: MIT

来源:GitHub · github.com