package codexhost import ( "context" "flag" "fmt" "os" "os/signal" "syscall" ) // Main is the detached bridge's command entry point. func Main(args []string) int { flags := flag.NewFlagSet("pipelines-codex-host", flag.ContinueOnError) dir := flags.String("dir", "", "private per-server host directory") upstream := flags.String("upstream", "", "existing Codex App Server Unix socket") idle := flags.Duration("idle", 0, "optional detached idle expiry (0 keeps the upstream session connection)") maxDetached := flags.Duration("max-detached", 0, "optional detached lifetime limit (0 keeps live sessions)") if err := flags.Parse(args); err != nil { return 2 } if *dir == "" || *upstream == "" { fmt.Fprintln(os.Stderr, "-dir and -upstream are required") return 2 } syscall.Umask(0o077) signal.Ignore(syscall.SIGHUP, syscall.SIGPIPE) ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer cancel() err := Serve(ctx, Options{Dir: *dir, Upstream: *upstream, Idle: *idle, MaxDetached: *maxDetached, Ready: func(socket string) { fmt.Fprintln(os.Stdout, "ready "+socket) if null, err := os.OpenFile(os.DevNull, os.O_RDWR, 0); err == nil { _ = syscall.Dup2(int(null.Fd()), 0) _ = syscall.Dup2(int(null.Fd()), 1) null.Close() } }}) if err != nil { fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stdout, "error "+err.Error()) return 1 } return 0 }