High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(config): route the default-config hint through output.Advisory so PINCHTAB_HINTS=off is honored and it prints once per install (PIN-402)
Luigi Agostib79833534bdf
diff --git a/cmd/pinchtab/cmd_cli_management.go b/cmd/pinchtab/cmd_cli_management.goindex 7f91e7b0..ff6d280d 100644--- a/cmd/pinchtab/cmd_cli_management.go+++ b/cmd/pinchtab/cmd_cli_management.go@@ -4,7 +4,6 @@ import ("fmt"browseractions "github.com/pinchtab/pinchtab/internal/cli/actions"- "github.com/pinchtab/pinchtab/internal/config""github.com/pinchtab/pinchtab/internal/urls""github.com/spf13/cobra")@@ -41,7 +40,7 @@ var healthCmd = &cobra.Command{Use: "health",Short: "Check server health",Run: func(cmd *cobra.Command, args []string) {- config.EmitDefaultConfigHint()+ emitDefaultConfigHint()runCLI(func(rt cliRuntime) {browseractions.Health(rt.client, rt.base, rt.token, cmd)})diff --git a/cmd/pinchtab/cmd_config.go b/cmd/pinchtab/cmd_config.goindex 320cc0d5..672b8f0b 100644--- a/cmd/pinchtab/cmd_config.go+++ b/cmd/pinchtab/cmd_config.go@@ -2,7 +2,6 @@ package mainimport ("github.com/pinchtab/pinchtab/internal/cli"- "github.com/pinchtab/pinchtab/internal/config""github.com/spf13/cobra")@@ -10,7 +9,7 @@ var configCmd = &cobra.Command{Use: "config",Short: "Manage configuration",PersistentPreRun: func(cmd *cobra.Command, args []string) {- config.EmitDefaultConfigHint()+ emitDefaultConfigHint()},Run: func(cmd *cobra.Command, args []string) {printConfigOverview(loadLocalConfig())diff --git a/cmd/pinchtab/cmd_config_actions.go b/cmd/pinchtab/cmd_config_actions.goindex f27264e4..32653139 100644--- a/cmd/pinchtab/cmd_config_actions.go+++ b/cmd/pinchtab/cmd_config_actions.go@@ -225,6 +225,12 @@ func handleConfigSchema(printSchema bool) {fmt.Println(schemaURL)}+func emitDefaultConfigHint() {+ if text := config.DefaultConfigHint(); text != "" {+ output.Advisory(text)+ }+}+func hintRestartIfRunning() {cfg := loadLocalConfig()if server.CheckPinchTabRunning(cfg.Port, cfg.Token) {diff --git a/internal/cli/output/hint_census_test.go b/internal/cli/output/hint_census_test.goindex ebace001..60d80c32 100644--- a/internal/cli/output/hint_census_test.go+++ b/internal/cli/output/hint_census_test.go@@ -34,19 +34,20 @@ var hintSites = map[string]struct {calls intwhy 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"},+ "../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:emitDefaultConfigHint": {advisory, 1, "a default config exists beside PINCHTAB_CONFIG: a steady state the caller chose, 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) {diff --git a/internal/config/config_load.go b/internal/config/config_load.goindex 9af3e561..53f860bf 100644--- a/internal/config/config_load.go+++ b/internal/config/config_load.go@@ -8,34 +8,25 @@ import ("os""path/filepath""strings"- "sync""time""github.com/pinchtab/pinchtab/internal/autosolver""github.com/pinchtab/pinchtab/internal/browsers")-var configHintOnce sync.Once--// EmitDefaultConfigHint prints a one-time hint to stderr when PINCHTAB_CONFIG-// points somewhere other than the default config path AND a default config-// already exists at that path. The hint is best-effort UX nudge for users-// who may not realize they're running against a custom config.-//-// Scoped to specific commands (health, config) and once-per-process via-// sync.Once so scripted callers and unrelated CLI commands stay quiet.-func EmitDefaultConfigHint() {- configHintOnce.Do(func() {- defaultConfigPath := filepath.Join(userConfigDir(), "config.json")- configPath := envOr("PINCHTAB_CONFIG", defaultConfigPath)- if configPath == defaultConfigPath {- return- }- if _, err := os.Stat(defaultConfigPath); err != nil {- return- }- fmt.Fprintf(os.Stderr, "HINT: default config exists at %s — you can edit it directly instead of using PINCHTAB_CONFIG\n", defaultConfigPath)- })+// DefaultConfigHint returns the advisory shown when PINCHTAB_CONFIG points+// somewhere other than the default config path AND a default config already+// exists there, or "" when it does not apply. It only computes the text; the+// caller routes it through output.Advisory, which owns suppression and dedupe.+func DefaultConfigHint() string {+ defaultConfigPath := filepath.Join(userConfigDir(), "config.json")+ if envOr("PINCHTAB_CONFIG", defaultConfigPath) == defaultConfigPath {+ return ""+ }+ if _, err := os.Stat(defaultConfigPath); err != nil {+ return ""+ }+ return fmt.Sprintf("default config exists at %s — you can edit it directly instead of using PINCHTAB_CONFIG", defaultConfigPath)}// parsedConfigFile is the side-effect-free result of resolving + reading +diff --git a/internal/config/config_load_test.go b/internal/config/config_load_test.goindex d1782a9a..44a322aa 100644--- a/internal/config/config_load_test.go+++ b/internal/config/config_load_test.go@@ -32,6 +32,55 @@ func TestEnvOr(t *testing.T) {}}+func TestDefaultConfigHint(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)+ defaultPath := DefaultConfigPath()+ if err := os.MkdirAll(filepath.Dir(defaultPath), 0o755); err != nil {+ t.Fatal(err)+ }++ t.Run("unset returns empty", func(t *testing.T) {+ t.Setenv("HOME", home)+ _ = os.Unsetenv("PINCHTAB_CONFIG")+ if got := DefaultConfigHint(); got != "" {+ t.Errorf("DefaultConfigHint() = %q, want \"\"", got)+ }+ })++ t.Run("equals default returns empty", func(t *testing.T) {+ t.Setenv("HOME", home)+ t.Setenv("PINCHTAB_CONFIG", defaultPath)+ if got := DefaultConfigHint(); got != "" {+ t.Errorf("DefaultConfigHint() = %q, want \"\"", got)+ }+ })++ t.Run("elsewhere but no default file returns empty", func(t *testing.T) {+ t.Setenv("HOME", home)+ t.Setenv("PINCHTAB_CONFIG", filepath.Join(t.TempDir(), "custom.json"))+ if got := DefaultConfigHint(); got != "" {+ t.Errorf("DefaultConfigHint() = %q, want \"\" (no default file on disk)", got)+ }+ })++ t.Run("elsewhere with default file returns hint", func(t *testing.T) {+ t.Setenv("HOME", home)+ t.Setenv("PINCHTAB_CONFIG", filepath.Join(t.TempDir(), "custom.json"))+ if err := os.WriteFile(defaultPath, []byte("{}"), 0o644); err != nil {+ t.Fatal(err)+ }+ defer func() { _ = os.Remove(defaultPath) }()+ got := DefaultConfigHint()+ if got == "" {+ t.Fatal("DefaultConfigHint() = \"\", want non-empty")+ }+ if !strings.Contains(got, defaultPath) {+ t.Errorf("DefaultConfigHint() = %q, want it to name %q", got, defaultPath)+ }+ })+}+func TestLoadConfigDefaults(t *testing.T) {clearConfigEnvVars(t)setCloakBrowserDiscovery(t, "")