Skip to content

The agent that grows with you

Merge origin/main into window-plans

Teknium32fc5b878c6b
diff --cc hermes_cli/auth_model_picker.py
index 5b4eb962cf8,122fa2abdf6..7681636dfb7
--- a/hermes_cli/auth_model_picker.py
+++ b/hermes_cli/auth_model_picker.py
@@@ -173,84 -133,20 +173,84 @@@ class _ModelPickerRows
def label(self, mid: str) -> str:
return "".join(text for text, _style in self.segments(mid))
- def menu_title(self, title: str = "Select default model:") -> str:
- """*title* plus an aligned pricing header hint when priced."""
+ def description_lines(self) -> list[str]:
+ """Lines between the title and the list: plan gauges (window plan), column headers, legend.
+ Each choice is " {label}" (2 spaces) plus a 3-char cursor region ("-> " or " "), so column
+ content starts at col 5."""
+ pad = " " * 5
+ lines: list[str] = []
+ if self.window_mode:
+ from hermes_cli.model_picker_usage import plan_gauge_lines
+ for i, line in enumerate(plan_gauge_lines(self.usage)):
+ suffix = f" — {self.usage.included_summary}" if i == 0 else ""
+ lines.append(f"{pad}{line}{suffix}")
+ lines.append(f"{pad}{'':>{self.name_col}}{_GAUGE_GAP}Usage")
+ return lines
if self.has_pricing:
- # Each choice is " {label}" (2 spaces) plus a 3-char cursor region ("-> " or " "),
- # so content starts at col 5.
- pad = " " * 5
- header = f"\n{pad}{'':>{self.name_col}} {'In':>{self.price_col}} {'Out':>{self.price_col}}"
+ header = f"{pad}{'':>{self.name_col}} {'In':>{self.price_col}} {'Out':>{self.price_col}}"
if self.has_cache:
header += f" {'Cache':>{self.cache_col}}"
- # Legend lives on the column-header line so it reads as a key, not a fake menu row.
- title += header + " $/Mtok"
+ header += " $/Mtok"
if self.any_on_sale:
- title += " ★ = on sale"
- return title
+ header += " ★ = on sale"
+ lines.append(header)
+ return lines
+
- def menu_title(self) -> str:
- """``Select default model:`` plus the description lines (headers / gauges), newline-joined."""
++ def menu_title(self, title: str = "Select default model:") -> str:
++ """*title* plus the description lines (headers / gauges), newline-joined."""
+ lines = self.description_lines()
- return "Select default model:" + ("\n" + "\n".join(lines) if lines else "")
++ return title + ("\n" + "\n".join(lines) if lines else "")
+
+ def footnote(self) -> str:
+ """Window plan with a Large row listed: the one line that says what Large means."""
+ if not self.has_top_tier:
+ return ""
+ from hermes_cli.model_picker_usage import TOP_TIER_FOOTNOTE
+ return TOP_TIER_FOOTNOTE
+
+
+def _picker_order(model_ids: list[str], current_model: str, window_usage) -> tuple[list[str], dict[int, str], int]:
+ """``(ordered ids, {row index: section heading}, cursor start)`` for the picker.
+
+ Window plan: "Recommended" (the plan's featured picks) then "Other models", with the current
+ model left in its own section (the cursor starts on it). Everyone else: current first.
+ """
+ sections: dict[int, str] = {}
+ if window_usage is not None:
+ from hermes_cli.model_picker_usage import SECTION_OTHER, SECTION_RECOMMENDED, split_recommended
+ head, rest = split_recommended(list(dict.fromkeys(model_ids)), window_usage.featured_model_ids)
+ ordered = head + rest
+ if head:
+ sections[0] = SECTION_RECOMMENDED
+ if rest:
+ sections[len(head)] = SECTION_OTHER
+ else:
+ # Reorder: current model first, then the rest (deduplicated)
+ ordered = list(dict.fromkeys(
+ ([current_model] if current_model and current_model in model_ids else []) + list(model_ids)
+ ))
+ return ordered, sections, (ordered.index(current_model) if current_model in ordered else 0)
+
+
+def _print_numbered_rows(rows: _ModelPickerRows, menu_title: str, ordered: list[str], sections: dict[int, str]) -> int:
+ """The no-curses fallback's title, numbered rows (+ custom / skip) and footnote; returns the number width."""
+ from hermes_cli.curses_ui import colorize_gauge_bars_ansi, format_radio_item_ansi
+ from hermes_cli.colors import Colors, color
+ n, _DIM, _RESET = len(ordered), "\033[2m", "\033[0m"
+ for line in menu_title.splitlines():
+ if rows.window_mode:
+ line = colorize_gauge_bars_ansi(line)
+ print(line.replace("★", color("★", Colors.YELLOW), 1) if "★" in line else line)
+ num_width = len(str(n + 2))
+ for i, mid in enumerate(ordered, 1):
+ if (i - 1) in sections:
+ print(f" {_DIM}{sections[i - 1]}{_RESET}")
+ print(f" {i:>{num_width}}. {format_radio_item_ansi(rows.segments(mid))}")
+ print(f" {n + 1:>{num_width}}. {_CUSTOM_LABEL}")
+ print(f" {n + 2:>{num_width}}. {_SKIP_LABEL}")
+ if footnote := rows.footnote():
+ print(f" {_DIM}{footnote}{_RESET}")
+ return num_width
def _prompt_model_selection(
@@@ -258,10 -154,10 +258,11 @@@
pricing: Optional[dict[str, dict[str, str]]] = None,
unavailable_models: Optional[list[str]] = None, portal_url: str = "",
unavailable_message: str = "", confirm_provider: str = "", confirm_base_url: str = "",
- confirm_api_key: str = "", notes: Optional[dict[str, str]] = None, title: str = "Select default model:",
+ confirm_api_key: str = "", usage=None,
- notes: Optional[dict[str, str]] = None,
++ notes: Optional[dict[str, str]] = None, title: str = "Select default model:",
) -> Optional[str]:
- """Interactive model picker; current_model listed first. Returns the chosen model ID or None.
+ """Interactive model picker; current_model listed first. Returns the chosen model ID or None. *title* heads
+ the menu (a plugin picking a model for something other than the default says so).
With *pricing* (``{model_id: {prompt, completion}}``) a compact price column is shown; models in
*unavailable_models* render grayed out and unselectable with an upgrade link to *portal_url*.
@@@ -331,9 -223,9 +332,9 @@@
model_search_labels += [_CUSTOM_LABEL, _SKIP_LABEL]
idx = curses_radiolist(
- "Select default model:",
+ title,
choices,
- selected=0, # cursor on the current model (index 0 if it was reordered to top)
+ selected=start, # cursor on the current model
cancel_returns=-1,
description="\n".join(desc_lines) if desc_lines else None,
searchable=True,