Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/token_savior/server_handlers/code_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_query_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading