Skip to content

Commit 3d7ce38

Browse files
committed
Rename intelligent routing to smart routing; share one opt-in across agents
- Rename the feature "intelligent routing" -> "smart routing" throughout (package dir smart_routing/, symbols, CLI flags --enable/--disable-smart-routing, hidden *-router-hook commands, user-facing strings) per naming guidance. - Unify the per-agent state keys into one shared "smart_routing_enabled", so a workspace enables smart routing once for every routing-capable tool (codex, claude) rather than per tool. Co-authored-by: Isaac
1 parent 9cad465 commit 3d7ce38

16 files changed

Lines changed: 152 additions & 153 deletions

src/ucode/agents/claude.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
build_tool_base_url,
2929
get_databricks_token,
3030
)
31-
from ucode.intelligent_routing.claude_hooks import (
32-
remove_intelligent_routing_hooks,
33-
sync_intelligent_routing_hooks,
34-
)
3531
from ucode.launcher import exec_or_spawn
32+
from ucode.smart_routing.claude_hooks import (
33+
remove_smart_routing_hooks,
34+
sync_smart_routing_hooks,
35+
)
3636
from ucode.state import mark_tool_managed, save_state
3737
from ucode.telemetry import agent_version, ucode_version
3838
from ucode.tracing import tracing_env
@@ -50,8 +50,11 @@
5050
"backup_path": CLAUDE_BACKUP_PATH,
5151
}
5252

53-
# Per-workspace opt-in flag for Claude Code intelligent routing (state key).
54-
INTELLIGENT_ROUTING_STATE_KEY = "claude_intelligent_routing_enabled"
53+
# Per-workspace opt-in flag for Claude Code smart routing (state key).
54+
# Shared across agents: one opt-in enables smart routing for every routing-capable
55+
# tool (codex, claude), so a workspace turns it on once. Kept identical to
56+
# codex.SMART_ROUTING_STATE_KEY on purpose.
57+
SMART_ROUTING_STATE_KEY = "smart_routing_enabled"
5558
# Claude Code settings.json hook events ucode manages when routing is enabled;
5659
# marked managed so they're tracked/reverted with the rest of ucode's config.
5760
CLAUDE_ROUTING_HOOK_EVENTS = ("PreToolUse", "SessionStart", "SubagentStart")
@@ -230,7 +233,7 @@ def render_overlay(
230233
# shows only one row per model. `ucode claude -- --model X` still overrides for
231234
# a single session via Claude Code's own --model flag.
232235
#
233-
# The one exception is intelligent routing: `route_root_model` pins the
236+
# The one exception is smart routing: `route_root_model` pins the
234237
# router's per-launch pick for the root session as ANTHROPIC_MODEL. The
235238
# duplicate-picker-row cost is acceptable because the whole point is to launch
236239
# on the routed model rather than the family default.
@@ -354,29 +357,29 @@ def _unregister_web_search_mcp() -> None:
354357
pass
355358

356359

357-
def intelligent_routing_enabled(state: dict) -> bool:
360+
def smart_routing_enabled(state: dict) -> bool:
358361
"""Return whether the current workspace opted into Claude Code routing."""
359-
return state.get(INTELLIGENT_ROUTING_STATE_KEY) is True
362+
return state.get(SMART_ROUTING_STATE_KEY) is True
360363

361364

362-
def enable_intelligent_routing(state: dict) -> dict:
363-
"""Persist the current workspace's Claude Code intelligent-routing opt-in."""
364-
state[INTELLIGENT_ROUTING_STATE_KEY] = True
365+
def enable_smart_routing(state: dict) -> dict:
366+
"""Persist the current workspace's Claude Code smart-routing opt-in."""
367+
state[SMART_ROUTING_STATE_KEY] = True
365368
return state
366369

367370

368-
def disable_intelligent_routing(state: dict) -> bool:
371+
def disable_smart_routing(state: dict) -> bool:
369372
"""Disable routing and remove only ucode's Claude Code routing hooks."""
370-
state.pop(INTELLIGENT_ROUTING_STATE_KEY, None)
373+
state.pop(SMART_ROUTING_STATE_KEY, None)
371374
if state.get("workspace"):
372375
save_state(state)
373376
changed = False
374377
if CLAUDE_SETTINGS_PATH.exists():
375378
doc = read_json_safe(CLAUDE_SETTINGS_PATH)
376-
if remove_intelligent_routing_hooks(doc):
379+
if remove_smart_routing_hooks(doc):
377380
write_json_file(CLAUDE_SETTINGS_PATH, doc)
378381
changed = True
379-
from ucode.intelligent_routing.claude_routing import clear_routing_artifacts
382+
from ucode.smart_routing.claude_routing import clear_routing_artifacts
380383

381384
clear_routing_artifacts()
382385
return changed
@@ -452,11 +455,11 @@ def write_tool_config(
452455
if isinstance(merged_env, dict):
453456
for key in CLAUDE_REMOVED_ENV_KEYS:
454457
merged_env.pop(key, None)
455-
# Intelligent-routing hooks: install ucode's PreToolUse/SessionStart/
458+
# Smart-routing hooks: install ucode's PreToolUse/SessionStart/
456459
# SubagentStart hooks when routing is enabled (and not under a provider,
457460
# which pins no Databricks model), else surgically strip only ucode's own.
458-
routing_enabled = intelligent_routing_enabled(state) and provider is None
459-
sync_intelligent_routing_hooks(merged, state, enabled=routing_enabled)
461+
routing_enabled = smart_routing_enabled(state) and provider is None
462+
sync_smart_routing_hooks(merged, state, enabled=routing_enabled)
460463
if routing_enabled:
461464
managed_keys = managed_keys + [["hooks", event] for event in CLAUDE_ROUTING_HOOK_EVENTS]
462465
write_json_file(CLAUDE_SETTINGS_PATH, merged)

src/ucode/agents/codex.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
build_tool_base_url,
2121
get_databricks_token,
2222
)
23-
from ucode.intelligent_routing.codex_hooks import (
24-
remove_intelligent_routing_hooks,
25-
sync_intelligent_routing_hooks,
26-
)
2723
from ucode.launcher import exec_or_spawn
24+
from ucode.smart_routing.codex_hooks import (
25+
remove_smart_routing_hooks,
26+
sync_smart_routing_hooks,
27+
)
2828
from ucode.state import mark_tool_managed, save_state
2929
from ucode.telemetry import agent_version, ucode_version
3030

@@ -39,7 +39,9 @@
3939
MINIMUM_CODEX_VERSION_TEXT = "0.134.0"
4040
MINIMUM_ROUTING_CODEX_VERSION = (0, 145, 0)
4141
MINIMUM_ROUTING_CODEX_VERSION_TEXT = "0.145.0"
42-
INTELLIGENT_ROUTING_STATE_KEY = "codex_intelligent_routing_enabled"
42+
# Shared across agents: one opt-in enables smart routing for every routing-capable
43+
# tool (codex, claude), so a workspace turns it on once.
44+
SMART_ROUTING_STATE_KEY = "smart_routing_enabled"
4345

4446

4547
SPEC: ToolSpec = {
@@ -325,10 +327,9 @@ def write_tool_config(state: dict, model: str | None = None, provider: str | Non
325327
databricks_profile = state.get("profile")
326328

327329
if _use_legacy_layout():
328-
if intelligent_routing_enabled(state) and provider is None:
330+
if smart_routing_enabled(state) and provider is None:
329331
raise RuntimeError(
330-
"Codex intelligent routing requires Codex "
331-
f"{MINIMUM_ROUTING_CODEX_VERSION_TEXT} or newer."
332+
f"Codex smart routing requires Codex {MINIMUM_ROUTING_CODEX_VERSION_TEXT} or newer."
332333
)
333334
# Codex < 0.134.0 only reads ~/.codex/config.toml. Write the shared
334335
# config with [profiles.ucode] + shared [model_providers.ucode-databricks]
@@ -370,10 +371,10 @@ def write_tool_config(state: dict, model: str | None = None, provider: str | Non
370371
# deep_merge can't drop keys, so clear a `model` pinned by an earlier
371372
# non-provider run that the provider overlay omits.
372373
doc.pop("model", None)
373-
sync_intelligent_routing_hooks(
374+
sync_smart_routing_hooks(
374375
doc,
375376
state,
376-
enabled=intelligent_routing_enabled(state) and provider is None,
377+
enabled=smart_routing_enabled(state) and provider is None,
377378
)
378379
write_toml_file(CODEX_CONFIG_PATH, doc)
379380
state = mark_tool_managed(state, "codex", MANAGED_KEYS)
@@ -416,38 +417,38 @@ def launch(state: dict, tool_args: list[str]) -> None:
416417
exec_or_spawn([binary, "--profile", CODEX_PROFILE_NAME, *tool_args])
417418

418419

419-
def intelligent_routing_enabled(state: dict) -> bool:
420+
def smart_routing_enabled(state: dict) -> bool:
420421
"""Return whether the current workspace opted into Codex routing."""
421-
return state.get(INTELLIGENT_ROUTING_STATE_KEY) is True
422+
return state.get(SMART_ROUTING_STATE_KEY) is True
422423

423424

424-
def enable_intelligent_routing(state: dict) -> dict:
425-
"""Persist the current workspace's Codex intelligent-routing opt-in."""
425+
def enable_smart_routing(state: dict) -> dict:
426+
"""Persist the current workspace's Codex smart-routing opt-in."""
426427
parsed = _parse_version(agent_version(SPEC["binary"]))
427428
if parsed is not None and parsed < MINIMUM_ROUTING_CODEX_VERSION:
428429
raise RuntimeError(
429-
"Codex intelligent routing requires Codex "
430+
"Codex smart routing requires Codex "
430431
f"{MINIMUM_ROUTING_CODEX_VERSION_TEXT} or newer; found "
431432
f"{agent_version(SPEC['binary'])}."
432433
)
433-
state[INTELLIGENT_ROUTING_STATE_KEY] = True
434+
state[SMART_ROUTING_STATE_KEY] = True
434435
return state
435436

436437

437-
def disable_intelligent_routing(state: dict) -> bool:
438+
def disable_smart_routing(state: dict) -> bool:
438439
"""Disable routing and remove only ucode's Codex routing hooks."""
439-
state.pop(INTELLIGENT_ROUTING_STATE_KEY, None)
440+
state.pop(SMART_ROUTING_STATE_KEY, None)
440441
if state.get("workspace"):
441442
save_state(state)
442443
changed = False
443444
for path in (CODEX_CONFIG_PATH, LEGACY_CODEX_CONFIG_PATH):
444445
if not path.exists():
445446
continue
446447
doc = read_toml_safe(path)
447-
if remove_intelligent_routing_hooks(doc):
448+
if remove_smart_routing_hooks(doc):
448449
write_toml_file(path, doc)
449450
changed = True
450-
from ucode.intelligent_routing.codex_routing import clear_routing_artifacts
451+
from ucode.smart_routing.codex_routing import clear_routing_artifacts
451452

452453
clear_routing_artifacts()
453454
return changed

0 commit comments

Comments
 (0)