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.

Tokens
19.6K
Snippets
86
Records
152
Agent score
56%

What's inside SRA

  1. Overview of scheduling SRA with AUTO-MAS

    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).
  2. 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.
  3. Understand SRA's custom command registration mechanism

    SRA uses a 'dynamic discovery + automatic registration' system based on the Python cmd2 library. When SRA starts, SRACore/__main__.py calls dynamic_import("tasks"), which scans all .py files in the tasks/ directory and imports them. Any class inheriting from cmd2.CommandSet[SRACli] is automatically instantiated and registered by SRACli (which has auto_load_commands=True), meaning no manual registration code is required as long as the file is placed in the tasks/ folder.
  4. 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 @extension decorator. Extensions are automatically discovered when placed in the extensions/ directory.

    Key Components:

    • Configuration: Inherit from pydantic.BaseModel. Use Field to define defaults, descriptions (for the UI), and constraints (e.g., ge for minimum, le for maximum).
    • Registration: Use @extension(name="...", description="...") to register the extension in the global ExtensionRegistry.
    • Execution: Implement the run() method, which must return a boolean (True for success, False for failure).
    • Lifecycle: Optionally override on_start(), on_completed(), and on_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...")
  5. 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.
  6. 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).
  7. 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 the tasks/ directory. The task must inherit from BaseTask and be marked with the @task decorator. 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 the tasks/ 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 completion
  8. Automate SRA-cli startup using a .srarc script

    SRA-cli supports a startup script file named .srarc located 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 an exit command is encountered or the end of the file is reached.
    # Example .srarc file
    run Default
    exit
  9. Contribute 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:

    1. Check existing Issues on GitHub.
    2. Submit a clear Issue with reproduction steps and screenshots for new bugs.
    3. Fork the repository to submit a PR for direct fixes.
    4. Provide general usage feedback and suggestions.

    High-priority contributions include documentation corrections, new feature proposals, image recognition optimizations, and cross-platform/resolution testing feedback.