High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
refactor: simplify instance launch API and CLI
Marioa43429a479f3
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.goindex f88f8954..fc48bac4 100644--- a/cmd/pinchtab/cmd_cli.go+++ b/cmd/pinchtab/cmd_cli.go@@ -150,8 +150,8 @@ func runCLI(cfg *config.RuntimeConfig) {cliPDF(client, base, token, args)case "health":cliHealth(client, base, token)- case "launch":- cliLaunch(client, base, token, args)+ case "instance":+ cliInstance(client, base, token, args)case "instances":cliInstances(client, base, token)case "profiles":@@ -182,7 +182,7 @@ Commands:quick <url> Navigate and analyze page (beginner-friendly)INSTANCE MANAGEMENT:- launch Create new instance (--name test, --headed for visible window)+ instance launch Create new instance (--mode headed, --port 9999)instances List all running instancesBROWSER CONTROL:@@ -642,22 +642,39 @@ func cliHealth(client *http.Client, base, token string) {doGet(client, base, token, "/health", nil)}-// --- launch ---+// --- instance ---++func cliInstance(client *http.Client, base, token string, args []string) {+ if len(args) < 1 {+ fatal("Usage: pinchtab instance <subcommand> [options]\nSubcommands: launch")+ }++ subCmd := args[0]+ subArgs := args[1:]++ switch subCmd {+ case "launch":+ cliInstanceLaunch(client, base, token, subArgs)+ default:+ fatal("Unknown subcommand: %s", subCmd)+ }+}-func cliLaunch(client *http.Client, base, token string, args []string) {+func cliInstanceLaunch(client *http.Client, base, token string, args []string) {body := map[string]any{}for i := 0; i < len(args); i++ {switch args[i] {- case "--name":+ case "--mode":if i+1 < len(args) {- body["name"] = args[i+1]+ body["mode"] = args[i+1]+ i+++ }+ case "--port":+ if i+1 < len(args) {+ body["port"] = args[i+1]i++}- case "--headed":- body["headless"] = false- case "--headless":- body["headless"] = true}}@@ -666,26 +683,9 @@ func cliLaunch(client *http.Client, base, token string, args []string) {return}- // Display instance info+ // Display only ID as primary outputif id, ok := result["id"].(string); ok {- if name, ok := result["profileName"].(string); ok {- if port, ok := result["port"].(string); ok {- if headless, ok := result["headless"].(bool); ok {- mode := "headless"- if !headless {- mode = "headed"- }- fmt.Printf("✅ Instance created\n")- fmt.Printf(" ID: %s\n", id)- fmt.Printf(" Name: %s\n", name)- fmt.Printf(" Port: %s\n", port)- fmt.Printf(" Mode: %s\n", mode)- if status, ok := result["status"].(string); ok {- fmt.Printf(" Status: %s\n", status)- }- }- }- }+ fmt.Println(id)}}diff --git a/internal/orchestrator/handlers.go b/internal/orchestrator/handlers.goindex 7adb1982..6c2cbba5 100644--- a/internal/orchestrator/handlers.go+++ b/internal/orchestrator/handlers.go@@ -117,9 +117,8 @@ func (o *Orchestrator) handleStopByID(w http.ResponseWriter, r *http.Request) {func (o *Orchestrator) handleLaunchByName(w http.ResponseWriter, r *http.Request) {var req struct {- Name string `json:"name"`- Port string `json:"port,omitempty"`- Headless *bool `json:"headless"` // pointer to distinguish unset from false+ Mode string `json:"mode"` // "headed" or "headless" (default: headless)+ Port string `json:"port,omitempty"`}// Decode body if present (empty body is allowed)@@ -130,19 +129,17 @@ func (o *Orchestrator) handleLaunchByName(w http.ResponseWriter, r *http.Request}}- // Default: generate name if not provided- if req.Name == "" {- req.Name = fmt.Sprintf("instance-%d", time.Now().UnixNano())- }-- // Default: headless=true if not specified+ // Default: headless=true unless mode="headed"headless := true- if req.Headless != nil {- headless = *req.Headless+ if req.Mode == "headed" {+ headless = false}+ // Generate unique instance name (internal use only)+ name := fmt.Sprintf("instance-%d", time.Now().UnixNano())+// Port is optional - if not provided, Launch() will auto-allocate- inst, err := o.Launch(req.Name, req.Port, headless)+ inst, err := o.Launch(name, req.Port, headless)if err != nil {web.Error(w, 409, err)return