From 9d8406959fd031db63f532c0c16431d1b1271abb Mon Sep 17 00:00:00 2001 From: "lilly.luo" Date: Sat, 3 Oct 2026 17:16:14 +0000 Subject: [PATCH] Add ENABLE_CLAUDE_CODE_MODS flag and truthy env reader Introduce the ENABLE_CLAUDE_CODE_MODS environment variable, a shared TRUTHY_ENV_VALUES set ("1"/"true", case-insensitive), and a general claude_code_mods_enabled() reader in constants. Harness-general and not tied to smart routing; nothing is gated on it in this change. Co-authored-by: Isaac --- src/ucode/constants.py | 15 +++++++++++++++ tests/test_agent_claude.py | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ucode/constants.py b/src/ucode/constants.py index 1db9930e6..081dac8ac 100644 --- a/src/ucode/constants.py +++ b/src/ucode/constants.py @@ -1,8 +1,14 @@ """Shared UCode constants.""" +import os +from collections.abc import Mapping + LOCALHOST = "localhost" LOOPBACK_HOST = "127.0.0.1" +# Values an on/off env var may use to mean "on" (compare after .strip().lower()). +TRUTHY_ENV_VALUES = frozenset({"1", "true"}) + ENABLE_SMART_ROUTING_ENV_VAR = "ENABLE_SMART_ROUTING_V2" ENABLE_SUBAGENT_ROUTING_ENV_VAR = "ENABLE_SMART_ROUTING_SUBAGENT_ONLY" SMART_ROUTING_ENV_KEYS = ( @@ -10,6 +16,15 @@ ENABLE_SUBAGENT_ROUTING_ENV_VAR, ) +ENABLE_CLAUDE_CODE_MODS_ENV_VAR = "ENABLE_CLAUDE_CODE_MODS" + + +def claude_code_mods_enabled(env: Mapping[str, str] | None = None) -> bool: + """Whether the Claude Code mods experience is enabled.""" + source = os.environ if env is None else env + return source.get(ENABLE_CLAUDE_CODE_MODS_ENV_VAR, "").strip().lower() in TRUTHY_ENV_VALUES + + MODEL_PROVIDER_SERVICE_HEADER = "Databricks-Model-Provider-Service" MODEL_SERVICE_PARENT_SCHEMA_HEADER = "Databricks-Model-Service-Parent-Schema" # Names the smart-router recipe (e.g. `task_v3`) in use; sent only when smart routing is enabled. diff --git a/tests/test_agent_claude.py b/tests/test_agent_claude.py index 148543d1e..4f1fc62a3 100644 --- a/tests/test_agent_claude.py +++ b/tests/test_agent_claude.py @@ -12,8 +12,8 @@ import pytest +from ucode import constants, managed_files from ucode import databricks as db_mod -from ucode import managed_files from ucode.agents import LaunchOptions, claude from ucode.smart_routing import claude_routing, v2 from ucode.state import MANAGED_OVERLAY_KEY @@ -83,6 +83,16 @@ def test_unknown_version_does_not_block(self, monkeypatch): assert claude.minimum_version_error() is None +class TestClaudeCodeModsFlag: + def test_enabled_for_one_or_true_case_insensitively(self): + assert constants.claude_code_mods_enabled({"ENABLE_CLAUDE_CODE_MODS": "1"}) + assert constants.claude_code_mods_enabled({"ENABLE_CLAUDE_CODE_MODS": "true"}) + assert constants.claude_code_mods_enabled({"ENABLE_CLAUDE_CODE_MODS": "TRUE"}) + assert not constants.claude_code_mods_enabled({"ENABLE_CLAUDE_CODE_MODS": "yes"}) + assert not constants.claude_code_mods_enabled({"ENABLE_CLAUDE_CODE_MODS": "0"}) + assert not constants.claude_code_mods_enabled({}) + + class TestRenderOverlay: def test_long_context_suffix_supports_major_only_claude_versions(self): assert claude._maybe_add_1m_suffix("system.ai.claude-sonnet-5") == (