@@ -26,33 +26,35 @@ const progName = "openagent"
2626// EarlyDispatch handles CLI-only commands (help, version) and normalizes argv for
2727// optional serve-style subcommands. If it returns handled=true, the process should
2828// exit with code exitCode. When handled is false, InitFlag may parse remaining flags
29- // (e.g. -createDatabase).
30- func EarlyDispatch () (handled bool , exitCode int ) {
29+ // (e.g. -createDatabase). openBrowser is true only when the user explicitly passed a
30+ // serve-style subcommand (serve / gateway / run / start); bare invocation returns false
31+ // so the browser is not opened automatically.
32+ func EarlyDispatch () (handled bool , exitCode int , openBrowser bool ) {
3133 for {
3234 if len (os .Args ) <= 1 {
33- return false , 0
35+ return false , 0 , false
3436 }
3537
3638 first := os .Args [1 ]
3739
3840 switch first {
3941 case "-v" , "--version" , "version" :
4042 printVersion ()
41- return true , 0
43+ return true , 0 , false
4244 case "-h" , "--help" , "help" :
4345 printHelp ()
44- return true , 0
46+ return true , 0 , false
4547 case "serve" , "gateway" , "run" , "start" :
4648 // Match OpenClaw-style explicit "gateway" while keeping zero-arg default as serve.
4749 os .Args = append ([]string {os .Args [0 ]}, os .Args [2 :]... )
48- continue
50+ return false , 0 , true
4951 default :
5052 if len (first ) > 0 && first [0 ] == '-' {
5153 // Legacy/global flags such as -createDatabase — leave argv for flag.Parse.
52- return false , 0
54+ return false , 0 , false
5355 }
5456 fmt .Fprintf (os .Stderr , "%s: unknown command %q\n Run '%s help' for usage.\n " , progName , first , progName )
55- return true , 2
57+ return true , 2 , false
5658 }
5759 }
5860}
0 commit comments