Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat: add pinchtab dashboard command

Bosch1fb9f1aafc49
diff --git a/cmd/pinchtab/cmd_dashboard.go b/cmd/pinchtab/cmd_dashboard.go
new file mode 100644
index 00000000..47a98e35
--- /dev/null
+++ b/cmd/pinchtab/cmd_dashboard.go
@@ -0,0 +1,109 @@
+package main
+
+import (
+ "fmt"
+ "net"
+ "os/exec"
+ "runtime"
+ "time"
+
+ "github.com/pinchtab/pinchtab/internal/cli"
+ "github.com/spf13/cobra"
+)
+
+var dashboardCmd = &cobra.Command{
+ Use: "dashboard",
+ Short: "Open the dashboard in your browser",
+ Long: "Resolve the dashboard URL, copy the auth token to clipboard, and open the browser.",
+ Run: func(cmd *cobra.Command, args []string) {
+ cfg := loadConfig()
+ noOpen, _ := cmd.Flags().GetBool("no-open")
+ portOverride, _ := cmd.Flags().GetString("port")
+ runDashboardCommand(cfg.Port, cfg.Bind, cfg.Token, noOpen, portOverride)
+ },
+}
+
+func init() {
+ dashboardCmd.GroupID = "primary"
+ dashboardCmd.Flags().Bool("no-open", false, "Print URL without opening the browser")
+ dashboardCmd.Flags().String("port", "", "Override dashboard port")
+ rootCmd.AddCommand(dashboardCmd)
+}
+
+func runDashboardCommand(cfgPort, cfgBind, cfgToken string, noOpen bool, portOverride string) {
+ port := resolvePort(cfgPort, portOverride)
+ host := resolveHost(cfgBind)
+ url := fmt.Sprintf("http://%s:%s", host, port)
+
+ // Health check
+ if !isDashboardReachable(host, port) {
+ fmt.Println(cli.StyleStdout(cli.WarningStyle, " Dashboard doesn't appear to be running."))
+ fmt.Printf(" Start with %s or %s\n\n",
+ cli.StyleStdout(cli.CommandStyle, "pinchtab server"),
+ cli.StyleStdout(cli.CommandStyle, "pinchtab daemon start"))
+ }
+
+ fmt.Printf("%s %s\n", cli.StyleStdout(cli.HeadingStyle, "Dashboard:"), cli.StyleStdout(cli.ValueStyle, url))
+
+ // Copy token to clipboard (never embed in URL)
+ if cfgToken != "" {
+ if err := copyToClipboard(cfgToken); err == nil {
+ fmt.Println(cli.StyleStdout(cli.SuccessStyle, " Token copied to clipboard") +
+ cli.StyleStdout(cli.MutedStyle, " — paste it on the login page."))
+ } else {
+ fmt.Println(cli.StyleStdout(cli.WarningStyle, " Token could not be copied to clipboard."))
+ }
+ }
+
+ // Open browser
+ if !noOpen {
+ if err := openBrowser(url); err == nil {
+ fmt.Println(cli.StyleStdout(cli.SuccessStyle, " Opened in your browser."))
+ } else {
+ fmt.Printf(" Open this URL in your browser: %s\n", cli.StyleStdout(cli.ValueStyle, url))
+ }
+ } else {
+ fmt.Printf(" Open this URL in your browser: %s\n", cli.StyleStdout(cli.ValueStyle, url))
+ }
+}
+
+func resolvePort(cfgPort, override string) string {
+ if override != "" {
+ return override
+ }
+ if cfgPort != "" {
+ return cfgPort
+ }
+ return "9870"
+}
+
+func resolveHost(bind string) string {
+ switch bind {
+ case "", "loopback", "localhost", "lan", "0.0.0.0":
+ return "127.0.0.1"
+ default:
+ return bind
+ }
+}
+
+func isDashboardReachable(host, port string) bool {
+ conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, port), 1*time.Second)
+ if err != nil {
+ return false
+ }
+ conn.Close()
+ return true
+}
+
+func openBrowser(url string) error {
+ var cmd *exec.Cmd
+ switch runtime.GOOS {
+ case "darwin":
+ cmd = exec.Command("open", url)
+ case "windows":
+ cmd = exec.Command("cmd", "/c", "start", url)
+ default:
+ cmd = exec.Command("xdg-open", url)
+ }
+ return cmd.Start()
+}
diff --git a/cmd/pinchtab/cmd_dashboard_test.go b/cmd/pinchtab/cmd_dashboard_test.go
new file mode 100644
index 00000000..acbaa045
--- /dev/null
+++ b/cmd/pinchtab/cmd_dashboard_test.go
@@ -0,0 +1,55 @@
+package main
+
+import "testing"
+
+func TestResolvePort(t *testing.T) {
+ tests := []struct {
+ name string
+ cfgPort string
+ override string
+ want string
+ }{
+ {"default when empty", "", "", "9870"},
+ {"uses config port", "8080", "", "8080"},
+ {"override wins", "8080", "7777", "7777"},
+ {"override wins over empty config", "", "7777", "7777"},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := resolvePort(tt.cfgPort, tt.override)
+ if got != tt.want {
+ t.Errorf("resolvePort(%q, %q) = %q, want %q", tt.cfgPort, tt.override, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestResolveHost(t *testing.T) {
+ tests := []struct {
+ bind string
+ want string
+ }{
+ {"", "127.0.0.1"},
+ {"loopback", "127.0.0.1"},
+ {"localhost", "127.0.0.1"},
+ {"lan", "127.0.0.1"},
+ {"0.0.0.0", "127.0.0.1"},
+ {"192.168.1.100", "192.168.1.100"},
+ {"10.0.0.5", "10.0.0.5"},
+ }
+ for _, tt := range tests {
+ t.Run("bind="+tt.bind, func(t *testing.T) {
+ got := resolveHost(tt.bind)
+ if got != tt.want {
+ t.Errorf("resolveHost(%q) = %q, want %q", tt.bind, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestIsDashboardReachable_Unreachable(t *testing.T) {
+ // A port that almost certainly has nothing listening
+ if isDashboardReachable("127.0.0.1", "19") {
+ t.Error("expected unreachable port to return false")
+ }
+}
diff --git a/tests/e2e/scenarios-cli/dashboard-basic.sh b/tests/e2e/scenarios-cli/dashboard-basic.sh
new file mode 100644
index 00000000..5fababdd
--- /dev/null
+++ b/tests/e2e/scenarios-cli/dashboard-basic.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+# dashboard-basic.sh — Dashboard command scenarios.
+
+GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+source "${GROUP_DIR}/../helpers/cli.sh"
+
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab dashboard --no-open prints URL"
+
+config_setup() {
+ TMPDIR=$(mktemp -d)
+ CFG="$TMPDIR/config.json"
+}
+
+config_cleanup() {
+ rm -rf "$TMPDIR"
+}
+
+config_setup
+cat > "$CFG" <<'EOF'
+{
+ "configVersion": "2",
+ "server": {"port": "9870", "token": "test-dashboard-token"}
+}
+EOF
+
+# Use --no-open to avoid actually launching a browser in CI
+PINCHTAB_CONFIG="$CFG" pt_ok dashboard --no-open
+
+assert_output_contains "Dashboard:" "prints dashboard heading"
+assert_output_contains "127.0.0.1:9870" "prints correct URL"
+
+# Token must NOT appear in the output (security)
+assert_output_not_contains "test-dashboard-token" "token not leaked to stdout"
+
+# Should mention clipboard (either success or unavailable)
+if printf '%s\n%s\n' "$PT_OUT" "$PT_ERR" | grep -qi "clipboard\|copied"; then
+ echo -e " ${GREEN}✓${NC} clipboard feedback shown"
+ ((ASSERTIONS_PASSED++)) || true
+else
+ echo -e " ${RED}✗${NC} no clipboard feedback in output"
+ ((ASSERTIONS_FAILED++)) || true
+fi
+
+# Should suggest opening in browser since --no-open
+assert_output_contains "Open this URL" "suggests opening URL manually"
+
+config_cleanup
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab dashboard --no-open without token skips clipboard"
+
+config_setup
+cat > "$CFG" <<'EOF'
+{
+ "configVersion": "2",
+ "server": {"port": "9870", "token": ""}
+}
+EOF
+
+PINCHTAB_CONFIG="$CFG" pt_ok dashboard --no-open
+
+assert_output_contains "Dashboard:" "prints dashboard heading"
+assert_output_not_contains "copied" "no clipboard message when no token"
+
+config_cleanup
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab dashboard --port override"
+
+config_setup
+cat > "$CFG" <<'EOF'
+{
+ "configVersion": "2",
+ "server": {"port": "9870", "token": "abc"}
+}
+EOF
+
+PINCHTAB_CONFIG="$CFG" pt_ok dashboard --no-open --port 4444
+
+assert_output_contains "4444" "port override reflected in URL"
+assert_output_not_contains "9870" "original port not shown"
+
+config_cleanup
+end_test