High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(cli): print steady-state hints once per run and give callers a switch to silence them (PIN-270)
Luigi Agosti9f24afca6100
diff --git a/cmd/pinchtab/cmd_cli_runtime.go b/cmd/pinchtab/cmd_cli_runtime.goindex 5d241555..c0bb499e 100644--- a/cmd/pinchtab/cmd_cli_runtime.go+++ b/cmd/pinchtab/cmd_cli_runtime.go@@ -129,9 +129,9 @@ func resolveCLIBase(cfg *config.RuntimeConfig) string {resolved := resolveBaseURL(defaultBase)if resolved == defaultBase {if serverURL != "" {- output.Hint("--server " + resolved + " is the default and can be omitted")+ output.Advisory("--server " + resolved + " is the default and can be omitted")} else if os.Getenv("PINCHTAB_SERVER") != "" {- output.Hint("PINCHTAB_SERVER=" + resolved + " is the default and can be omitted")+ output.Advisory("PINCHTAB_SERVER=" + resolved + " is the default and can be omitted")}}return resolveddiff --git a/cmd/pinchtab/root.go b/cmd/pinchtab/root.goindex 8a824869..3831bae2 100644--- a/cmd/pinchtab/root.go+++ b/cmd/pinchtab/root.go@@ -6,6 +6,7 @@ import ("os""github.com/pinchtab/pinchtab/internal/cli"+ "github.com/pinchtab/pinchtab/internal/cli/output""github.com/pinchtab/pinchtab/internal/config""github.com/pinchtab/pinchtab/internal/safelog""github.com/spf13/cobra"@@ -17,7 +18,11 @@ var rootCmd = &cobra.Command{Use: "pinchtab",Short: "PinchTab - Browser control for AI agents",Long: `PinchTab provides a lightweight, API-driven way for AI agents to control-browsers, manage tabs, and perform interactive tasks.`,+browsers, manage tabs, and perform interactive tasks.++Advisory hints — the ones about a steady state you may have chosen, such as+running without an agent session — print once per run. Silence them with+` + output.HintsEnv + `=` + output.HintsOff + `.`,Example: ` pinchtab serverpinchtab nav https://pinchtab.com`,Run: func(cmd *cobra.Command, args []string) {diff --git a/internal/cli/actions/actions_navigate.go b/internal/cli/actions/actions_navigate.goindex 02f88a49..f6add939 100644--- a/internal/cli/actions/actions_navigate.go+++ b/internal/cli/actions/actions_navigate.go@@ -114,7 +114,7 @@ func Navigate(client *http.Client, base, token string, url string, cmd *cobra.Co}if !isIdentifiedCaller(cmd) {- output.Hint(cli.NoSessionHint)+ output.Advisory(cli.NoSessionHint)}printPostActionOutput(client, base, token, resultTabID, cmd)diff --git a/internal/cli/actions/actions_navigate_test.go b/internal/cli/actions/actions_navigate_test.goindex b6a4f2da..5a0f165d 100644--- a/internal/cli/actions/actions_navigate_test.go+++ b/internal/cli/actions/actions_navigate_test.go@@ -310,8 +310,7 @@ func TestNavigatePrintTabID(t *testing.T) {}func TestNavigateNoSessionHintNamesPrerequisiteAndCommand(t *testing.T) {- t.Setenv("PINCHTAB_SESSION", "")- t.Setenv("PINCHTAB_AGENT_ID", "")+ anonymousCaller(t)m := newMockServer()m.response = `{"tabId":"ABC123","status":"ok"}`@@ -701,8 +700,7 @@ func TestNavigateWithoutFallbackAnnouncesNothingExtra(t *testing.T) {// carries: an anonymous fallback prints both lines, and the same remedy twice on// one command is the shape that trains readers to skip hints.func TestFallbackNoticeDoesNotRepeatTheSessionRemedy(t *testing.T) {- t.Setenv("PINCHTAB_SESSION", "")- t.Setenv("PINCHTAB_AGENT_ID", "")+ anonymousCaller(t)m := newMockServer()m.setResponse(http.MethodPost, "/tabs/STALE123/navigate", http.StatusNotFound, `{"error":"tab not found"}`)diff --git a/internal/cli/actions/advisory_hint_test.go b/internal/cli/actions/advisory_hint_test.gonew file mode 100644index 00000000..ccb52e98--- /dev/null+++ b/internal/cli/actions/advisory_hint_test.go@@ -0,0 +1,101 @@+package actions++import (+ "net/http"+ "strings"+ "testing"++ "github.com/pinchtab/pinchtab/internal/cli"+ "github.com/pinchtab/pinchtab/internal/cli/output"+)++// staleTabCmd drives the fallback that reports a dead tab — an occurrence hint,+// which must print on every occurrence — alongside the no-session advisory.+func navigateOverAStaleTab(t *testing.T, m *mockServer) func() {+ t.Helper()+ m.setResponse(http.MethodPost, "/tabs/STALE123/navigate", http.StatusNotFound, `{"error":"tab not found"}`)+ m.setResponse(http.MethodPost, "/navigate", http.StatusOK, `{"tabId":"NEW123","status":"ok"}`)+ return func() {+ cmd := staleTabCmd(t, "STALE123")+ captureStdout(t, func() {+ Navigate(m.server.Client(), m.base(), "", "https://pinchtab.com", cmd)+ })+ }+}++func anonymousCaller(t *testing.T) {+ t.Helper()+ t.Setenv("PINCHTAB_SESSION", "")+ t.Setenv("PINCHTAB_AGENT_ID", "")+ output.ResetAdvisories()+ t.Cleanup(output.ResetAdvisories)+}++// The no-session hint describes a steady state the caller may have chosen, so a+// second navigation has nothing new to say. The occurrence hint beside it is the+// control: it reports what happened on this navigation and must repeat.+func TestTheNoSessionAdvisoryPrintsOncePerRunWhileOccurrenceHintsRepeat(t *testing.T) {+ anonymousCaller(t)+ m := newMockServer()+ defer m.close()+ nav := navigateOverAStaleTab(t, m)++ first := captureStderr(t, nav)+ second := captureStderr(t, nav)++ if !strings.Contains(first, cli.NoSessionHint) {+ t.Fatalf("first navigation printed no session advisory: %q", first)+ }+ if strings.Contains(second, cli.SessionCreateCommand) {+ t.Errorf("the advisory repeated on the second navigation of the same run: %q", second)+ }+ for i, out := range []string{first, second} {+ if !strings.Contains(out, "no longer exists") {+ t.Errorf("navigation %d dropped the dead-tab report; an occurrence hint must fire every time: %q", i+1, out)+ }+ }+}++// The switch is discoverable from the output it silences, and it is published+// exactly once — a per-navigation reminder would be the defect it fixes.+func TestTheFirstAdvisoryPublishesTheSilencingSwitchOnce(t *testing.T) {+ anonymousCaller(t)+ m := newMockServer()+ defer m.close()+ nav := navigateOverAStaleTab(t, m)++ first := captureStderr(t, nav)+ second := captureStderr(t, nav)++ if !strings.Contains(first, output.SilenceAdvisoryHint) {+ t.Fatalf("the first advisory did not say how to silence it: %q", first)+ }+ if !strings.HasSuffix(strings.TrimSpace(output.SilenceAdvisoryHint), output.HintsEnv+"="+output.HintsOff) {+ t.Errorf("the switch must end the line so it can be lifted verbatim: %q", output.SilenceAdvisoryHint)+ }+ if strings.Contains(second, output.SilenceAdvisoryHint) {+ t.Errorf("the silencing switch was published twice in one run: %q", second)+ }+}++// Silencing takes the advisory and only the advisory: a caller who has decided+// not to use sessions still needs to hear that the tab it asked for is gone.+func TestSilencingAdvisoriesKeepsOccurrenceHints(t *testing.T) {+ anonymousCaller(t)+ t.Setenv(output.HintsEnv, output.HintsOff)+ m := newMockServer()+ defer m.close()+ nav := navigateOverAStaleTab(t, m)++ out := captureStderr(t, nav)++ if strings.Contains(out, cli.SessionCreateCommand) {+ t.Errorf("the advisory printed with hints silenced: %q", out)+ }+ if strings.Contains(out, output.SilenceAdvisoryHint) {+ t.Errorf("the silencing switch was advertised to a caller who had already used it: %q", out)+ }+ if !strings.Contains(out, "no longer exists") {+ t.Errorf("silencing advisories also silenced the dead-tab report: %q", out)+ }+}diff --git a/internal/cli/output/advisory.go b/internal/cli/output/advisory.gonew file mode 100644index 00000000..38654405--- /dev/null+++ b/internal/cli/output/advisory.go@@ -0,0 +1,68 @@+package output++import (+ "os"+ "strings"+ "sync"+)++// HintsEnv silences advisory hints when it is set to HintsOff. It is the only+// switch: a caller who has decided not to use sessions, or not to move a setting+// this build keeps mentioning, turns the whole class off in one place.+const (+ HintsEnv = "PINCHTAB_HINTS"+ HintsOff = "off"+)++// SilenceAdvisoryHint is printed once beside the first advisory of a run, so the+// switch is discoverable from the output it silences. It ends with the command,+// because its readers lift the last words of a hint verbatim.+const SilenceAdvisoryHint = "silence advisory hints like this one: export " + HintsEnv + "=" + HintsOff++var (+ advisoryMu sync.Mutex+ advisoryShown = map[string]bool{}+ silencerShown bool+)++// Advisory prints a hint about a steady state the caller may have chosen — one+// whose wording is identical on every invocation and whose remedy is a decision,+// not a reaction. It prints at most once per process and not at all when the+// caller has silenced hints.+//+// A hint that reports what just happened is not advisory: it belongs on Hint,+// which prints every time it fires, because the second occurrence is news too.+func Advisory(text string) {+ if AdvisoriesSilenced() {+ return+ }++ advisoryMu.Lock()+ first := !advisoryShown[text]+ advisoryShown[text] = true+ withSilencer := first && !silencerShown+ silencerShown = silencerShown || first+ advisoryMu.Unlock()++ if !first {+ return+ }+ Hint(text)+ if withSilencer {+ Hint(SilenceAdvisoryHint)+ }+}++// AdvisoriesSilenced reports whether the caller has switched advisory hints off.+func AdvisoriesSilenced() bool {+ return strings.EqualFold(strings.TrimSpace(os.Getenv(HintsEnv)), HintsOff)+}++// ResetAdvisories forgets what this process has already said, for a test that+// needs a fresh run and for any host that reuses one process across sessions.+func ResetAdvisories() {+ advisoryMu.Lock()+ advisoryShown = map[string]bool{}+ silencerShown = false+ advisoryMu.Unlock()+}diff --git a/internal/cli/output/hint_census_test.go b/internal/cli/output/hint_census_test.gonew file mode 100644index 00000000..ebace001--- /dev/null+++ b/internal/cli/output/hint_census_test.go@@ -0,0 +1,116 @@+package output++import (+ "fmt"+ "sort"+ "testing"++ "github.com/pinchtab/pinchtab/internal/srccensus"+)++// Every hint is one of two things, and which one decides how often it may print.+// An advisory describes a steady state the caller may have chosen: its wording is+// the same on every invocation, its remedy is a decision rather than a reaction,+// and repeating it trains the reader to skip hints. An occurrence reports what+// just happened on this call, so the second one is news too and must print.+//+// The classification is not a comment: a site's class here is the function it is+// required to call, so a site that changes its mind about which it is fails until+// someone records the decision, and a new site fails until it makes one.+const (+ advisory = "output.Advisory"+ occurrence = "output.Hint"+)++// hintCallers are the packages that print hints. The floors are vacuity guards:+// a census that silently stopped seeing most of a package would otherwise pass.+var hintCallers = map[string]int{+ "../actions": 40,+ "../../../cmd/pinchtab": 45,+}++var hintSites = map[string]struct {+ class string+ calls int+ why string+}{+ "../actions/actions_navigate.go:Navigate": {advisory, 1, "no agent session: a steady state, and on a bridge one the caller cannot leave"},+ "../actions/actions_navigate.go:reportFallbackNewTab": {occurrence, 2, "this navigation's tab was gone and a new one was opened"},+ "../actions/actions_element.go:printActionResult": {occurrence, 2, "this action's refs went stale, or this submit is still pending"},+ "../actions/actions_element.go:printStaleRefsHint": {occurrence, 1, "this action invalidated the snapshot the caller is holding"},+ "../actions/actions_capture.go:Capture": {occurrence, 1, "this page tripped the IDPI guard"},+ "../actions/actions_text.go:Text": {occurrence, 1, "readability collapsed on this page"},+ "../actions/actions_tabs.go:TabHandoff": {occurrence, 1, "the reason this handoff carried"},+ "../actions/actions_tabs.go:TabHandoffStatus": {occurrence, 1, "the reason this handoff carried"},+ "../../../cmd/pinchtab/cmd_cli_runtime.go:resolveCLIBase": {advisory, 2, "the caller's own --server/PINCHTAB_SERVER is redundant: their setting, not an event"},+ "../../../cmd/pinchtab/cmd_config_actions.go:hintRestartIfRunning": {occurrence, 1, "this edit needs a restart to reach the running server"},+ "../../../cmd/pinchtab/cmd_session.go:printSessionCreated": {occurrence, 1, "the id of the session just created"},+ "../../../cmd/pinchtab/cmd_session.go:init": {occurrence, 2, "attached to a failure that exits"},+ "../../../cmd/pinchtab/cmd_session.go:exitSessionUnavailable": {occurrence, 2, "attached to a failure that exits"},+}++func TestEveryHintCallSiteIsClassified(t *testing.T) {+ found := map[string]struct {+ class string+ calls int+ }{}+ for dir, floor := range hintCallers {+ pkg := srccensus.Load(t, dir, floor)+ for _, class := range []string{advisory, occurrence} {+ for _, site := range pkg.CallsAllowingNone(class) {+ key := fmt.Sprintf("%s/%s:%s", dir, site.File, site.Func)+ entry := found[key]+ if entry.class != "" && entry.class != class {+ t.Errorf("%s prints both an advisory and an occurrence hint; split it so each line's class is readable at the call site", key)+ }+ entry.class = class+ entry.calls+++ found[key] = entry+ }+ }+ }+ if len(found) < len(hintSites) {+ t.Fatalf("the census found %d hint sites for %d recorded; it is matching almost nothing and would pass vacuously", len(found), len(hintSites))+ }++ for _, key := range sortedSiteKeys(found) {+ site := found[key]+ want, recorded := hintSites[key]+ if !recorded {+ t.Errorf("%s prints a hint and is not classified; record it here as %s or %s with the reason, since how often it may print follows from that", key, advisory, occurrence)+ continue+ }+ if want.class != site.class {+ t.Errorf("%s is recorded as %s but calls %s", key, want.class, site.class)+ }+ if want.calls != site.calls {+ t.Errorf("%s makes %d hint call(s), recorded %d; a new line in a classified function still has to choose its class", key, site.calls, want.calls)+ }+ }+ for _, key := range sortedRecordedKeys() {+ if _, ok := found[key]; !ok {+ t.Errorf("%s is recorded here and prints no hint any more; drop the entry rather than leaving the census guarding one site fewer than it claims", key)+ }+ }+}++func sortedSiteKeys(found map[string]struct {+ class string+ calls int+}) []string {+ keys := make([]string, 0, len(found))+ for key := range found {+ keys = append(keys, key)+ }+ sort.Strings(keys)+ return keys+}++func sortedRecordedKeys() []string {+ keys := make([]string, 0, len(hintSites))+ for key := range hintSites {+ keys = append(keys, key)+ }+ sort.Strings(keys)+ return keys+}