Skip to content

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

fix: CLI handoff commands output human-readable text by default

Luigi Agosti2d47535b8db1
diff --git a/cmd/pinchtab/cmd_cli_browser_nav.go b/cmd/pinchtab/cmd_cli_browser_nav.go
index 8b098408..db8e8eef 100644
--- a/cmd/pinchtab/cmd_cli_browser_nav.go
+++ b/cmd/pinchtab/cmd_cli_browser_nav.go
@@ -113,7 +113,7 @@ var tabHandoffCmd = &cobra.Command{
reason, _ := cmd.Flags().GetString("reason")
timeoutMS, _ := cmd.Flags().GetInt("timeout-ms")
runCLI(func(rt cliRuntime) {
- browseractions.TabHandoff(rt.client, rt.base, rt.token, args[0], reason, timeoutMS)
+ browseractions.TabHandoff(rt.client, rt.base, rt.token, args[0], reason, timeoutMS, cmd)
})
},
}
@@ -125,7 +125,7 @@ var tabResumeCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
status, _ := cmd.Flags().GetString("status")
runCLI(func(rt cliRuntime) {
- browseractions.TabResume(rt.client, rt.base, rt.token, args[0], status)
+ browseractions.TabResume(rt.client, rt.base, rt.token, args[0], status, cmd)
})
},
}
@@ -136,7 +136,7 @@ var tabHandoffStatusCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runCLI(func(rt cliRuntime) {
- browseractions.TabHandoffStatus(rt.client, rt.base, rt.token, args[0])
+ browseractions.TabHandoffStatus(rt.client, rt.base, rt.token, args[0], cmd)
})
},
}
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index 47060b5a..f30fd57e 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -307,6 +307,9 @@ func configureBrowserFlags() {
tabsCmd,
tabNewCmd,
tabCloseCmd,
+ tabHandoffCmd,
+ tabResumeCmd,
+ tabHandoffStatusCmd,
healthCmd,
cacheClearCmd,
cacheStatusCmd,
diff --git a/internal/cli/actions/actions_handoff_test.go b/internal/cli/actions/actions_handoff_test.go
index 3f70d87a..cb8cf5ca 100644
--- a/internal/cli/actions/actions_handoff_test.go
+++ b/internal/cli/actions/actions_handoff_test.go
@@ -3,14 +3,22 @@ package actions
import (
"encoding/json"
"testing"
+
+ "github.com/spf13/cobra"
)
+func newHandoffCmd() *cobra.Command {
+ cmd := &cobra.Command{}
+ cmd.Flags().Bool("json", true, "")
+ return cmd
+}
+
func TestTabHandoff(t *testing.T) {
m := newMockServer()
defer m.close()
client := m.server.Client()
- TabHandoff(client, m.base(), "", "tab_123", "captcha_manual", 60000)
+ TabHandoff(client, m.base(), "", "tab_123", "captcha_manual", 60000, newHandoffCmd())
if m.lastMethod != "POST" {
t.Fatalf("expected POST, got %s", m.lastMethod)
@@ -36,7 +44,7 @@ func TestTabResume(t *testing.T) {
defer m.close()
client := m.server.Client()
- TabResume(client, m.base(), "", "tab_123", "completed")
+ TabResume(client, m.base(), "", "tab_123", "completed", newHandoffCmd())
if m.lastMethod != "POST" {
t.Fatalf("expected POST, got %s", m.lastMethod)
@@ -60,7 +68,7 @@ func TestTabHandoffStatus(t *testing.T) {
defer m.close()
client := m.server.Client()
- TabHandoffStatus(client, m.base(), "", "tab_123")
+ TabHandoffStatus(client, m.base(), "", "tab_123", newHandoffCmd())
if m.lastMethod != "GET" {
t.Fatalf("expected GET, got %s", m.lastMethod)
diff --git a/internal/cli/actions/actions_tabs.go b/internal/cli/actions/actions_tabs.go
index a2676d71..15de420d 100644
--- a/internal/cli/actions/actions_tabs.go
+++ b/internal/cli/actions/actions_tabs.go
@@ -102,7 +102,7 @@ func TabFocus(client *http.Client, base, token string, tabID string, cmd *cobra.
}
// TabHandoff pauses automation on a tab for manual operator intervention.
-func TabHandoff(client *http.Client, base, token, tabID, reason string, timeoutMS int) {
+func TabHandoff(client *http.Client, base, token, tabID, reason string, timeoutMS int, cmd *cobra.Command) {
body := map[string]any{}
if reason != "" {
body["reason"] = reason
@@ -110,19 +110,49 @@ func TabHandoff(client *http.Client, base, token, tabID, reason string, timeoutM
if timeoutMS > 0 {
body["timeoutMs"] = timeoutMS
}
- apiclient.DoPost(client, base, token, fmt.Sprintf("/tabs/%s/handoff", tabID), body)
+ jsonOutput, _ := cmd.Flags().GetBool("json")
+ if jsonOutput {
+ apiclient.DoPost(client, base, token, fmt.Sprintf("/tabs/%s/handoff", tabID), body)
+ return
+ }
+ apiclient.DoPostQuiet(client, base, token, fmt.Sprintf("/tabs/%s/handoff", tabID), body)
+ output.Value("paused")
+ if reason != "" {
+ output.Hint(fmt.Sprintf("reason: %s", reason))
+ }
}
// TabResume resumes automation on a tab after manual intervention.
-func TabResume(client *http.Client, base, token, tabID, status string) {
+func TabResume(client *http.Client, base, token, tabID, status string, cmd *cobra.Command) {
body := map[string]any{}
if status != "" {
body["status"] = status
}
- apiclient.DoPost(client, base, token, fmt.Sprintf("/tabs/%s/resume", tabID), body)
+ jsonOutput, _ := cmd.Flags().GetBool("json")
+ if jsonOutput {
+ apiclient.DoPost(client, base, token, fmt.Sprintf("/tabs/%s/resume", tabID), body)
+ return
+ }
+ apiclient.DoPostQuiet(client, base, token, fmt.Sprintf("/tabs/%s/resume", tabID), body)
+ output.Value("resumed")
}
// TabHandoffStatus shows whether a tab is in paused_handoff or active state.
-func TabHandoffStatus(client *http.Client, base, token, tabID string) {
- apiclient.DoGet(client, base, token, fmt.Sprintf("/tabs/%s/handoff", tabID), nil)
+func TabHandoffStatus(client *http.Client, base, token, tabID string, cmd *cobra.Command) {
+ jsonOutput, _ := cmd.Flags().GetBool("json")
+ if jsonOutput {
+ apiclient.DoGet(client, base, token, fmt.Sprintf("/tabs/%s/handoff", tabID), nil)
+ return
+ }
+ body := apiclient.DoGetRaw(client, base, token, fmt.Sprintf("/tabs/%s/handoff", tabID), nil)
+ var result map[string]any
+ if err := json.Unmarshal(body, &result); err != nil {
+ fmt.Println(string(body))
+ return
+ }
+ status, _ := result["status"].(string)
+ output.Value(status)
+ if reason, ok := result["reason"].(string); ok && reason != "" {
+ output.Hint(fmt.Sprintf("reason: %s", reason))
+ }
}
diff --git a/tests/e2e/scenarios/cli/tabs-extended.sh b/tests/e2e/scenarios/cli/tabs-extended.sh
index bc26746f..b947bd7c 100644
--- a/tests/e2e/scenarios/cli/tabs-extended.sh
+++ b/tests/e2e/scenarios/cli/tabs-extended.sh
@@ -122,3 +122,71 @@ pt_ok tab
assert_output_not_contains "$FIRST_TAB" "oldest tab evicted (LRU)"
end_test
+
+# ─────────────────────────────────────────────────────────────────
+# Human Handoff CLI Tests
+# ─────────────────────────────────────────────────────────────────
+
+start_test "tab handoff: pause and check status"
+
+pt_ok nav "${FIXTURES_URL}/buttons.html"
+HANDOFF_TAB=$(echo "$PT_OUT" | tr -d '[:space:]')
+
+pt_ok tab handoff "$HANDOFF_TAB" --reason "cli_test"
+assert_output_contains "paused" "handoff outputs paused"
+
+pt_ok tab handoff-status "$HANDOFF_TAB"
+assert_output_contains "paused_handoff" "status shows paused_handoff"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "tab handoff: resume restores active state"
+
+pt_ok tab resume "$HANDOFF_TAB" --status "completed"
+assert_output_contains "resumed" "resume outputs resumed"
+
+pt_ok tab handoff-status "$HANDOFF_TAB"
+assert_output_contains "active" "status shows active after resume"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "tab handoff: --json flag returns raw JSON"
+
+pt_ok nav "${FIXTURES_URL}/buttons.html"
+JSON_TAB=$(echo "$PT_OUT" | tr -d '[:space:]')
+
+pt_ok tab handoff "$JSON_TAB" --reason "json_test" --json
+assert_output_json "handoff --json returns valid JSON"
+assert_output_contains "paused_handoff" "JSON contains status"
+
+pt_ok tab handoff-status "$JSON_TAB" --json
+assert_output_json "handoff-status --json returns valid JSON"
+
+pt_ok tab resume "$JSON_TAB" --json
+assert_output_json "resume --json returns valid JSON"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "tab handoff: actions blocked while paused"
+
+pt_ok nav "${FIXTURES_URL}/buttons.html"
+BLOCK_TAB=$(echo "$PT_OUT" | tr -d '[:space:]')
+
+pt_ok tab handoff "$BLOCK_TAB" --reason "block_test"
+
+pt_fail click "#increment" --tab "$BLOCK_TAB"
+
+pt_ok tab resume "$BLOCK_TAB"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "tab handoff: actions work after resume"
+
+pt_ok wait "#increment" --tab "$BLOCK_TAB"
+pt_ok click "#increment" --tab "$BLOCK_TAB"
+
+end_test