diff --git a/src/token_savior/server_handlers/code_nav.py b/src/token_savior/server_handlers/code_nav.py index 350698c..03bbccd 100644 --- a/src/token_savior/server_handlers/code_nav.py +++ b/src/token_savior/server_handlers/code_nav.py @@ -26,7 +26,20 @@ # next-step routing advice (the agent must rely on its system prompt). # Recommended for benchmark / cold-start workloads where the prompt # already encodes routing rules. -_HINTS_DISABLED = os.environ.get("TS_NO_HINTS") == "1" +# +# The `optimized` profile is the token-minimizing default: it already implies +# thin schemas (server.py), and a usage audit found the per-result hint blocks +# convert poorly (e.g. the ts_execute nudge fired hundreds of times without +# moving adoption). So `optimized` disables them too — the ~30-50 tokens/call +# are a measured overhead there. An explicit TS_NO_HINTS=0 opts back in. +def _hints_off() -> bool: + override = os.environ.get("TS_NO_HINTS") + if override is not None: + return override == "1" + return os.environ.get("TOKEN_SAVIOR_PROFILE", "").lower() == "optimized" + + +_HINTS_DISABLED = _hints_off() def _resolve_batch_names(args: dict[str, Any]) -> list[str] | None: diff --git a/tests/test_query_api.py b/tests/test_query_api.py index 929a02f..76f01c1 100644 --- a/tests/test_query_api.py +++ b/tests/test_query_api.py @@ -1767,3 +1767,21 @@ def test_rank_by_intent_is_deterministic_and_stable(): b, _ = _rank_by_intent(names, "auth token", keep=2) assert a == b # deterministic, no model assert "auth_token" in a and dropped == 3 + + +def test_hints_off_respects_profile_and_explicit_override(monkeypatch): + """optimized profile disables per-result hints by default (measured overhead); + an explicit TS_NO_HINTS wins on any profile.""" + from token_savior.server_handlers.code_nav import _hints_off + monkeypatch.delenv("TS_NO_HINTS", raising=False) + monkeypatch.setenv("TOKEN_SAVIOR_PROFILE", "optimized") + assert _hints_off() is True + monkeypatch.setenv("TOKEN_SAVIOR_PROFILE", "full") + assert _hints_off() is False + # explicit override wins both ways + monkeypatch.setenv("TS_NO_HINTS", "0") + monkeypatch.setenv("TOKEN_SAVIOR_PROFILE", "optimized") + assert _hints_off() is False + monkeypatch.setenv("TS_NO_HINTS", "1") + monkeypatch.setenv("TOKEN_SAVIOR_PROFILE", "full") + assert _hints_off() is True