StarRailAssistant (SRA)
website·Indexed 31 days ago
https://starrailassistant.top/An automation tool for Honkai: Star Rail featuring SRA-cli for command-line task execution and SRA-server for RESTful API control. It supports a pluggable architecture for custom extensions, tasks, and commands, and includes built-in support for the Model Context Protocol (MCP) to allow AI assistants like Claude and Cursor to control the software.
What's inside SRA
- AUTO-MAS is a multi-script and multi-configuration management and automation software that operates by monitoring logs. It enables multi-account proxying by modifying configuration files and listening to logs to control other script programs, such as MAA and SRA (Star Rail Assistant).
Overview of SRA-server
SRA-server is a Web API server for SRA built on ASP.NET Core. It provides an HTTP server that allows external programs to control SRA operations. It includes built-in Swagger UI documentation and supports the Model Context Protocol (MCP). It acts as a middleware that manages a backend process (SRA-cli or Python) via stdin/stdout.Get help for SRA-cli commands
Use thehelpcommand to display information about a specific command. If the command name is omitted, the CLI will list all available commands.sra> help taskUnderstand SRA's custom command registration mechanism
SRA uses a 'dynamic discovery + automatic registration' system based on the Pythoncmd2library. When SRA starts,SRACore/__main__.pycallsdynamic_import("tasks"), which scans all.pyfiles in thetasks/directory and imports them. Any class inheriting fromcmd2.CommandSet[SRACli]is automatically instantiated and registered bySRACli(which hasauto_load_commands=True), meaning no manual registration code is required as long as the file is placed in thetasks/folder.Develop a custom SRA Extension
SRA uses a pluggable architecture based on generic declarations and decorators. To create an extension, you must define a configuration model using Pydantic, inherit from
BaseExtension[YourConfig], and register the class with the@extensiondecorator. Extensions are automatically discovered when placed in theextensions/directory.Key Components:
- Configuration: Inherit from
pydantic.BaseModel. UseFieldto define defaults, descriptions (for the UI), and constraints (e.g.,gefor minimum,lefor maximum). - Registration: Use
@extension(name="...", description="...")to register the extension in the globalExtensionRegistry. - Execution: Implement the
run()method, which must return a boolean (Truefor success,Falsefor failure). - Lifecycle: Optionally override
on_start(),on_completed(), andon_failed()for resource management and error recovery.
from pydantic import BaseModel, Field from SRACore.extension import BaseExtension, extension # 1. Define Configuration class MyConfig(BaseModel): """Extension configuration.""" target: str = Field(default="Star Rail", description="Target name") count: int = Field(default=1, ge=1, le=100, description="Execution count") verbose: bool = Field(default=False, description="Enable detailed logs") # 2. Define Extension Class @extension(name="My Extension", description="A custom extension example") class MyExtension(BaseExtension[MyConfig]): """Custom extension implementation.""" def on_start(self) -> None: print("Initializing resources...") def run(self) -> bool: for i in range(self.config.count): print(f"[MyExtension] ({i + 1}/{self.config.count}) Target: {self.config.target}") return True def on_completed(self) -> None: print("Cleaning up resources...")- Configuration: Inherit from
Join the StarRailAssistant community and development channels
Connect with the StarRailAssistant project via the official GitHub repository or the community QQ groups for user exchange and support.GitHub Repository: https://github.com/Shasnow/StarRailAssistant QQ Group 1: 994571792 QQ Group 2: 829477581
SRA random startup greetings
SRA displays a random greeting upon startup. These greetings include community memes, developer jokes (such as the Python memory access conflict error-1073741819), and references to Honkai: Star Rail and Wuthering Waves.Enable and use SRA Developer Options
Developer options are hidden by default and can be enabled by rapidly clicking the version number in the 'About' section. Once enabled, the following options become available:
- Save OCR Screenshots: Saves images captured during OCR recognition for debugging purposes.
- Run Backend from Source: Allows SRA to use a specified Python environment instead of the built-in executable. This requires configuring the Python Interpreter path and the Main Program Path (e.g.,
main.py).
Install .NET 10.0 Desktop Runtime for SRA
SRA requires the .NET 10.0 Desktop Runtime to run. Without this installation, the application will not function. This update improves performance and enables new features.Create and register a custom task in SRA
SRA uses a dynamic discovery mechanism to load tasks. To add a custom task, create a Python file in thetasks/directory. The task must inherit fromBaseTaskand be marked with the@taskdecorator. SRA automatically scans this directory at startup and registers any matching classes. The execution index of a task is determined by the alphabetical order of the filenames in thetasks/directory.from SRACore.task import BaseTask, task from SRACore.util.logger import logger @task class MyCustomTask(BaseTask): def run(self): logger.info("This is my custom task!") return True # Return True to indicate successful completionAutomate SRA-cli startup using a .srarc script
SRA-cli supports a startup script file named.srarclocated in the current directory. The tool will automatically execute the commands listed in this file upon startup. Each command must be on a new line and will be executed sequentially until anexitcommand is encountered or the end of the file is reached.# Example .srarc file run Default exitContribute to the StarRailAssistant project
Developers and users can contribute to StarRailAssistant by submitting bug reports, creating Pull Requests (PRs) for fixes or new features, improving documentation, or providing testing feedback across different devices and environments.
Recommended contribution workflow:
- Check existing Issues on GitHub.
- Submit a clear Issue with reproduction steps and screenshots for new bugs.
- Fork the repository to submit a PR for direct fixes.
- Provide general usage feedback and suggestions.
High-priority contributions include documentation corrections, new feature proposals, image recognition optimizations, and cross-platform/resolution testing feedback.