xonecas.io
6119
My

mysis / commit daa2d49

feat: add autoplay CLI flag for immediate autonomous start

- Add -a/--autoplay flag to start autoplay on session launch
- Add startAutoplayFromFlag method to initialize autoplay from CLI
- Update help text with autoplay flag and example usage
- Enables headless autonomous gameplay: mysis -s bot -a "goal"

xonecas2026-02-10 daa2d4919948aeec8241dff1eff58b9f5321f5eb parent f04407f

1 file changed

cmd/mysis/main.go+45−0
@@ -41,6 +41,7 @@ func printHelp() {
4141 fmt.Println(" " + styles.Secondary.Render("-d, --debug") + " Enable debug logging")
4242 fmt.Println(" " + styles.Secondary.Render("-p, --provider") + " NAME Provider name (overrides config default)")
4343 fmt.Println(" " + styles.Secondary.Render("-s, --session") + " NAME Session name (resume or create)")
44+ fmt.Println(" " + styles.Secondary.Render("-a, --autoplay") + " MSG Start autoplay immediately with message")
4445 fmt.Println(" " + styles.Secondary.Render("-l, --list-sessions") + " List recent sessions and exit")
4546 fmt.Println(" " + styles.Secondary.Render("-D, --delete-session") + " N Delete session by name and exit")
4647 fmt.Println()
@@ -51,6 +52,9 @@ func printHelp() {
5152 fmt.Println(" # Resume or create named session")
5253 fmt.Println(" mysis -s mybot")
5354 fmt.Println()
55+ fmt.Println(" # Start with autoplay enabled")
56+ fmt.Println(" mysis -s mybot -a \"explore and mine resources\"")
57+ fmt.Println()
5458 fmt.Println(" # List all sessions")
5559 fmt.Println(" mysis -l")
5660 fmt.Println()
@@ -77,6 +81,7 @@ func main() {
7781 sessionName string
7882 listSessions bool
7983 deleteSession string
84+ autoplay string
8085 )
8186 flag.BoolVar(&showHelp, "help", false, "Show help and exit")
8287 flag.BoolVar(&showHelp, "h", false, "Show help and exit (shorthand)")
@@ -94,6 +99,8 @@ func main() {
9499 flag.BoolVar(&listSessions, "l", false, "List recent sessions and exit (shorthand)")
95100 flag.StringVar(&deleteSession, "delete-session", "", "Delete a session by name")
96101 flag.StringVar(&deleteSession, "D", "", "Delete a session by name (shorthand)")
102+ flag.StringVar(&autoplay, "autoplay", "", "Start autoplay immediately with given message")
103+ flag.StringVar(&autoplay, "a", "", "Start autoplay immediately (shorthand)")
97104
98105 // Custom usage function
99106 flag.Usage = func() {
@@ -307,6 +314,14 @@ func main() {
307314 sessionID: sessionID,
308315 }
309316
317+ // Start autoplay if flag provided
318+ if autoplay != "" {
319+ if err := app.startAutoplayFromFlag(ctx, autoplay); err != nil {
320+ fmt.Fprintln(os.Stderr, styles.Error.Render("Failed to start autoplay: "+err.Error()))
321+ os.Exit(1)
322+ }
323+ }
324+
310325 if err := app.Run(ctx); err != nil {
311326 fmt.Fprintln(os.Stderr, styles.Error.Render("Error: "+err.Error()))
312327 os.Exit(1)
@@ -688,6 +703,36 @@ func initializeProviders(cfg *config.Config, creds *config.Credentials) *provide
688703 return registry
689704 }
690705
706+// startAutoplayFromFlag starts autoplay from CLI flag.
707+func (app *App) startAutoplayFromFlag(ctx context.Context, message string) error {
708+ app.mu.Lock()
709+ if app.autoplayEnabled {
710+ app.mu.Unlock()
711+ return fmt.Errorf("autoplay already running")
712+ }
713+
714+ app.autoplayEnabled = true
715+ app.autoplayMessage = message
716+
717+ // Create cancelable context for autoplay goroutine
718+ autoplayCtx, cancel := context.WithCancel(ctx)
719+ app.autoplayCancel = cancel
720+ app.mu.Unlock()
721+
722+ fmt.Println(styles.Secondary.Render(fmt.Sprintf("Autoplay started: \"%s\"", message)))
723+ fmt.Println(styles.Muted.Render(fmt.Sprintf("Interval: %ds (%d avg tool calls × %ds/tick)",
724+ int(constants.AutoplayInterval.Seconds()),
725+ constants.AvgToolCallsPerTurn,
726+ int(constants.GameTickDuration.Seconds()))))
727+ fmt.Println(styles.Muted.Render("Type '/autoplay stop' to stop"))
728+ fmt.Println()
729+
730+ // Start autoplay loop in background
731+ go app.runAutoplay(autoplayCtx)
732+
733+ return nil
734+}
735+
691736 // handleAutoplayCommand handles /autoplay commands
692737 func (app *App) handleAutoplayCommand(ctx context.Context, input string) error {
693738 parts := strings.Fields(input)