Skip to content

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

feat(cli): add find command, select command, register missing flags

Boschc5a0ddd2d5c0
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.go
index b9fa2446..531f3533 100644
--- a/cmd/pinchtab/cmd_cli.go
+++ b/cmd/pinchtab/cmd_cli.go
@@ -239,6 +239,30 @@ var instanceCmd = &cobra.Command{
Short: "Manage browser instances",
}
+var findCmd = &cobra.Command{
+ Use: "find <query>",
+ Short: "Find elements by natural language query",
+ Args: cobra.MinimumNArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+ cfg := config.Load()
+ runCLIWith(cfg, func(client *http.Client, base, token string) {
+ browseractions.Find(client, base, token, args)
+ })
+ },
+}
+
+var selectCmd = &cobra.Command{
+ Use: "select <ref> <value>",
+ Short: "Select option in dropdown",
+ Args: cobra.ExactArgs(2),
+ Run: func(cmd *cobra.Command, args []string) {
+ cfg := config.Load()
+ runCLIWith(cfg, func(client *http.Client, base, token string) {
+ browseractions.Action(client, base, token, "select", args)
+ })
+ },
+}
+
func init() {
quickCmd.GroupID = "browser"
navCmd.GroupID = "browser"
@@ -259,6 +283,13 @@ func init() {
profilesCmd.GroupID = "management"
downloadCmd.GroupID = "browser"
uploadCmd.GroupID = "browser"
+ findCmd.GroupID = "browser"
+ selectCmd.GroupID = "browser"
+
+ snapCmd.FParseErrWhitelist = cobra.FParseErrWhitelist{UnknownFlags: true}
+ screenshotCmd.FParseErrWhitelist = cobra.FParseErrWhitelist{UnknownFlags: true}
+ pdfCmd.FParseErrWhitelist = cobra.FParseErrWhitelist{UnknownFlags: true}
+ findCmd.FParseErrWhitelist = cobra.FParseErrWhitelist{UnknownFlags: true}
uploadCmd.Flags().StringP("selector", "s", "", "CSS selector for file input")
downloadCmd.Flags().StringP("output", "o", "", "Save downloaded file to path")
@@ -282,6 +313,8 @@ func init() {
rootCmd.AddCommand(profilesCmd)
rootCmd.AddCommand(downloadCmd)
rootCmd.AddCommand(uploadCmd)
+ rootCmd.AddCommand(findCmd)
+ rootCmd.AddCommand(selectCmd)
instanceCmd.GroupID = "management"
instanceCmd.AddCommand(&cobra.Command{
diff --git a/internal/cli/actions/actions_find.go b/internal/cli/actions/actions_find.go
new file mode 100644
index 00000000..abb5cb98
--- /dev/null
+++ b/internal/cli/actions/actions_find.go
@@ -0,0 +1,67 @@
+package actions
+
+import (
+ "fmt"
+ "net/http"
+
+ "github.com/pinchtab/pinchtab/internal/cli"
+ "github.com/pinchtab/pinchtab/internal/cli/apiclient"
+)
+
+func Find(client *http.Client, base, token string, args []string) {
+ if len(args) == 0 {
+ cli.Fatal("Usage: pinchtab find <query> [--tab <id>] [--threshold <n>] [--explain] [--ref-only]")
+ }
+
+ query := args[0]
+ tabID := ""
+ threshold := ""
+ explain := false
+ refOnly := false
+
+ for i := 1; i < len(args); i++ {
+ switch args[i] {
+ case "--tab":
+ if i+1 < len(args) {
+ i++
+ tabID = args[i]
+ }
+ case "--threshold":
+ if i+1 < len(args) {
+ i++
+ threshold = args[i]
+ }
+ case "--explain":
+ explain = true
+ case "--ref-only":
+ refOnly = true
+ }
+ }
+
+ body := map[string]any{"query": query}
+ if tabID != "" {
+ body["tabId"] = tabID
+ }
+ if threshold != "" {
+ body["threshold"] = threshold
+ }
+ if explain {
+ body["explain"] = true
+ }
+
+ path := "/find"
+ if tabID != "" {
+ path = fmt.Sprintf("/tabs/%s/find", tabID)
+ delete(body, "tabId")
+ }
+
+ result := apiclient.DoPost(client, base, token, path, body)
+
+ if refOnly {
+ if ref, ok := result["best_ref"].(string); ok && ref != "" {
+ fmt.Println(ref)
+ return
+ }
+ cli.Fatal("No element found")
+ }
+}