llmswap-cli 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- claude_swap/__init__.py +24 -0
- claude_swap/__main__.py +6 -0
- claude_swap/app_bundle.py +330 -0
- claude_swap/appearance.py +219 -0
- claude_swap/autoswitch.py +3065 -0
- claude_swap/cache.py +44 -0
- claude_swap/claude_locks.py +279 -0
- claude_swap/cli.py +2265 -0
- claude_swap/credentials.py +2156 -0
- claude_swap/exceptions.py +102 -0
- claude_swap/fsutil.py +409 -0
- claude_swap/json_output.py +455 -0
- claude_swap/launch_agent.py +862 -0
- claude_swap/lines.py +153 -0
- claude_swap/list_view.py +371 -0
- claude_swap/locking.py +87 -0
- claude_swap/logging_config.py +64 -0
- claude_swap/macos_keychain.py +240 -0
- claude_swap/mappings.py +127 -0
- claude_swap/menubar.py +1433 -0
- claude_swap/migrations.py +360 -0
- claude_swap/models.py +329 -0
- claude_swap/oauth.py +1628 -0
- claude_swap/pace.py +161 -0
- claude_swap/paths.py +250 -0
- claude_swap/poll_policy.py +337 -0
- claude_swap/printer.py +252 -0
- claude_swap/process_detection.py +370 -0
- claude_swap/session.py +2696 -0
- claude_swap/settings.py +827 -0
- claude_swap/signin.py +238 -0
- claude_swap/snapshot_source.py +121 -0
- claude_swap/spawn.py +135 -0
- claude_swap/subscription.py +349 -0
- claude_swap/switcher.py +9807 -0
- claude_swap/transfer.py +807 -0
- claude_swap/tui/__init__.py +43 -0
- claude_swap/tui/app.py +482 -0
- claude_swap/tui/autoview.py +381 -0
- claude_swap/tui/cswap.tcss +205 -0
- claude_swap/tui/dashboard.py +434 -0
- claude_swap/tui/data.py +194 -0
- claude_swap/tui/modals.py +159 -0
- claude_swap/tui/theme.py +88 -0
- claude_swap/tui/widgets.py +544 -0
- claude_swap/update_check.py +509 -0
- claude_swap/usage_bars.py +208 -0
- claude_swap/usage_rows.py +160 -0
- claude_swap/usage_store.py +1429 -0
- llmswap/AGENTS.md +11 -0
- llmswap/__init__.py +3 -0
- llmswap/__main__.py +4 -0
- llmswap/cli.py +535 -0
- llmswap/config.py +101 -0
- llmswap/httpjson.py +50 -0
- llmswap/jwt.py +20 -0
- llmswap/menubar.py +218 -0
- llmswap/model.py +172 -0
- llmswap/paths.py +41 -0
- llmswap/providers/AGENTS.md +12 -0
- llmswap/providers/base.py +619 -0
- llmswap/providers/claude.py +187 -0
- llmswap/providers/codex.py +274 -0
- llmswap/providers/gemini.py +80 -0
- llmswap/providers/registry.py +30 -0
- llmswap/render.py +127 -0
- llmswap/rotate.py +102 -0
- llmswap/store.py +138 -0
- llmswap/tui.py +182 -0
- llmswap/usage_cache.py +72 -0
- llmswap/warm/plan.py +118 -0
- llmswap/warm/runner.py +175 -0
- llmswap/warm/schedule.py +264 -0
- llmswap_cli-1.0.0.dist-info/METADATA +181 -0
- llmswap_cli-1.0.0.dist-info/RECORD +78 -0
- llmswap_cli-1.0.0.dist-info/WHEEL +4 -0
- llmswap_cli-1.0.0.dist-info/entry_points.txt +5 -0
- llmswap_cli-1.0.0.dist-info/licenses/LICENSE +22 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"""Live auto-switch screen: the real engine, visualized.
|
|
2
|
+
|
|
3
|
+
Runs :class:`AutoSwitchEngine` in a thread worker and renders its typed
|
|
4
|
+
events. Opens in **dry-run** — opening a view must never start switching
|
|
5
|
+
accounts on its own; going live is an explicit, confirmed action. The
|
|
6
|
+
engine's own state file semantics (shared cooldown, quarantine list, state
|
|
7
|
+
lock) make it safe to run alongside an external ``cswap auto``.
|
|
8
|
+
|
|
9
|
+
The active account's full card sits on top (same widget as the dashboard's
|
|
10
|
+
panel, with the threshold tick); this screen adds the engine badge, the
|
|
11
|
+
ranked switch candidates, and the decision log. While it is up, the app's
|
|
12
|
+
snapshot poller runs store-only: the engine is the only fetcher.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from dataclasses import replace
|
|
18
|
+
from typing import TYPE_CHECKING
|
|
19
|
+
|
|
20
|
+
from rich.text import Text
|
|
21
|
+
from textual.app import ComposeResult
|
|
22
|
+
from textual.binding import Binding
|
|
23
|
+
from textual.containers import Horizontal, Vertical
|
|
24
|
+
from textual.screen import Screen
|
|
25
|
+
from textual.widgets import Footer, RichLog, Static
|
|
26
|
+
|
|
27
|
+
from claude_swap import oauth
|
|
28
|
+
from claude_swap.autoswitch import (
|
|
29
|
+
AutoSwitchEngine,
|
|
30
|
+
AutoSwitchEvent,
|
|
31
|
+
pct_label,
|
|
32
|
+
)
|
|
33
|
+
from claude_swap.lines import binding_window
|
|
34
|
+
from claude_swap.models import AccountSnapshot, AccountsSnapshot
|
|
35
|
+
from claude_swap.settings import SETTING_SPECS, load_settings, parse_model_names
|
|
36
|
+
from claude_swap.tui import data
|
|
37
|
+
from claude_swap.tui.modals import ConfirmModal
|
|
38
|
+
from claude_swap.tui.theme import Palette
|
|
39
|
+
from claude_swap.tui.widgets import AccountsPanel, fit_login, login_segment
|
|
40
|
+
|
|
41
|
+
if TYPE_CHECKING:
|
|
42
|
+
from claude_swap.tui.app import CswapApp
|
|
43
|
+
|
|
44
|
+
_EVENT_ROLES = {
|
|
45
|
+
"switch": "accent",
|
|
46
|
+
"error": "sev_warn",
|
|
47
|
+
"account-quarantined": "sev_warn",
|
|
48
|
+
"all-exhausted": "sev_crit",
|
|
49
|
+
}
|
|
50
|
+
_QUIET_KINDS = {"poll", "no-switch", "sleep", "account-unquarantined"}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def event_text(event: AutoSwitchEvent, *, palette: Palette = Palette.DARK) -> Text:
|
|
54
|
+
"""Log line for one engine event, styled like the CLI's human renderer."""
|
|
55
|
+
role = _EVENT_ROLES.get(event.kind)
|
|
56
|
+
if role is not None:
|
|
57
|
+
style = getattr(palette, role)
|
|
58
|
+
else:
|
|
59
|
+
style = palette.muted if event.kind in _QUIET_KINDS else palette.foreground
|
|
60
|
+
text = Text()
|
|
61
|
+
text.append(f"{data.clock_stamp()} ", style=palette.muted)
|
|
62
|
+
text.append(event.human(), style=style)
|
|
63
|
+
return text
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class AutoScreen(Screen):
|
|
67
|
+
BINDINGS = [
|
|
68
|
+
Binding("l", "toggle_live", "Go live / dry-run"),
|
|
69
|
+
Binding("t", "adjust_threshold", "Threshold"),
|
|
70
|
+
Binding("left", "threshold_step(-1)", "-1%"),
|
|
71
|
+
Binding("right", "threshold_step(1)", "+1%"),
|
|
72
|
+
Binding("enter", "adjust_done", "Done"),
|
|
73
|
+
Binding("escape,q", "back", "Back"),
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
app: "CswapApp"
|
|
77
|
+
|
|
78
|
+
def __init__(self) -> None:
|
|
79
|
+
super().__init__()
|
|
80
|
+
self._engine: AutoSwitchEngine | None = None
|
|
81
|
+
self._settings = None
|
|
82
|
+
# Session-only threshold adjustment (t, then arrows). Never written
|
|
83
|
+
# to settings.json — same memory-only precedent as the dry-run
|
|
84
|
+
# toggle. ``_configured_threshold`` is the mount-time file value the
|
|
85
|
+
# screen reverts to on exit; ``_entry_threshold`` is the value when
|
|
86
|
+
# adjust mode was entered (wake/log only on a net change).
|
|
87
|
+
self._adjusting = False
|
|
88
|
+
self._configured_threshold: float | None = None
|
|
89
|
+
self._entry_threshold: float | None = None
|
|
90
|
+
|
|
91
|
+
def compose(self) -> ComposeResult:
|
|
92
|
+
yield AccountsPanel(show_minis=False, id="auto-active-panel")
|
|
93
|
+
with Vertical(id="auto-top"):
|
|
94
|
+
with Horizontal(id="auto-title-row"):
|
|
95
|
+
yield Static(" DRY-RUN ", id="mode-badge", classes="dry")
|
|
96
|
+
yield Static("", id="auto-summary")
|
|
97
|
+
yield Static("", id="candidates")
|
|
98
|
+
yield RichLog(id="event-log", highlight=False, markup=False, wrap=True)
|
|
99
|
+
yield Footer()
|
|
100
|
+
|
|
101
|
+
# -- lifecycle ----------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
def on_mount(self) -> None:
|
|
104
|
+
self.app.set_store_only(True)
|
|
105
|
+
self._settings = load_settings(self.app.switcher.backup_dir)
|
|
106
|
+
# The bar tick everywhere reads app.threshold_pct, loaded once at app
|
|
107
|
+
# startup — sync it to the fresh file value so bars and engine agree,
|
|
108
|
+
# and remember that value: unmount restores it (only the session
|
|
109
|
+
# adjustment reverts, not this correction).
|
|
110
|
+
self._configured_threshold = self._settings.threshold
|
|
111
|
+
self.app.threshold_pct = self._settings.threshold
|
|
112
|
+
# The weekly line is not session-adjustable, so this is only the same
|
|
113
|
+
# sync-to-the-file correction; nothing to restore on unmount.
|
|
114
|
+
self.app.weekly_threshold_pct = self._settings.weekly_threshold
|
|
115
|
+
self._update_summary()
|
|
116
|
+
self.watch(self.app, "snapshot", self._on_snapshot)
|
|
117
|
+
self.watch(self.app, "theme", self._on_theme_change)
|
|
118
|
+
self._start_engine(dry_run=True)
|
|
119
|
+
|
|
120
|
+
def on_unmount(self) -> None:
|
|
121
|
+
if self._engine is not None:
|
|
122
|
+
self._engine.stop()
|
|
123
|
+
# A session threshold must not outlive the engine it steered: unpin
|
|
124
|
+
# the poll planner and put the bar tick back on the file value.
|
|
125
|
+
self.app.switcher.clear_poll_policy_inputs()
|
|
126
|
+
if self._configured_threshold is not None:
|
|
127
|
+
self.app.threshold_pct = self._configured_threshold
|
|
128
|
+
self.app.set_store_only(False)
|
|
129
|
+
|
|
130
|
+
def _on_theme_change(self, _theme: str) -> None:
|
|
131
|
+
self._update_summary()
|
|
132
|
+
self._update_badge()
|
|
133
|
+
snap = self.app.snapshot
|
|
134
|
+
if snap is not None:
|
|
135
|
+
self._on_snapshot(snap)
|
|
136
|
+
|
|
137
|
+
def action_back(self) -> None:
|
|
138
|
+
if self._adjusting:
|
|
139
|
+
self._end_adjust()
|
|
140
|
+
return
|
|
141
|
+
self.app.pop_screen()
|
|
142
|
+
|
|
143
|
+
# -- threshold adjust mode ------------------------------------------------
|
|
144
|
+
|
|
145
|
+
def check_action(self, action: str, parameters: tuple) -> bool | None:
|
|
146
|
+
if action in ("threshold_step", "adjust_done") and not self._adjusting:
|
|
147
|
+
return False # hidden and inert until adjust mode is armed
|
|
148
|
+
return True
|
|
149
|
+
|
|
150
|
+
def action_adjust_threshold(self) -> None:
|
|
151
|
+
if self._adjusting:
|
|
152
|
+
self._end_adjust()
|
|
153
|
+
return
|
|
154
|
+
self._adjusting = True
|
|
155
|
+
self._entry_threshold = self._settings.threshold
|
|
156
|
+
self._update_summary()
|
|
157
|
+
self.refresh_bindings()
|
|
158
|
+
|
|
159
|
+
def action_adjust_done(self) -> None:
|
|
160
|
+
if self._adjusting:
|
|
161
|
+
self._end_adjust()
|
|
162
|
+
|
|
163
|
+
def action_threshold_step(self, delta: float) -> None:
|
|
164
|
+
if not self._adjusting:
|
|
165
|
+
return
|
|
166
|
+
spec = SETTING_SPECS["autoswitch.threshold"]
|
|
167
|
+
value = min(spec.hi, max(spec.lo, self._settings.threshold + delta))
|
|
168
|
+
self._set_threshold(value)
|
|
169
|
+
|
|
170
|
+
def _end_adjust(self) -> None:
|
|
171
|
+
self._adjusting = False
|
|
172
|
+
self._update_summary()
|
|
173
|
+
self.refresh_bindings()
|
|
174
|
+
if self._settings.threshold == self._entry_threshold:
|
|
175
|
+
return # no net change: nothing to announce, no tick to force
|
|
176
|
+
if self._engine is not None:
|
|
177
|
+
self._engine.wake() # show a decision at the new value now
|
|
178
|
+
self.query_one("#event-log", RichLog).write(
|
|
179
|
+
Text(
|
|
180
|
+
f"— threshold set to {pct_label(self._settings.threshold)}% "
|
|
181
|
+
"for this session —",
|
|
182
|
+
style=Palette.from_theme(self.app.current_theme).muted,
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
def _set_threshold(self, value: float) -> None:
|
|
187
|
+
if value == self._settings.threshold:
|
|
188
|
+
return
|
|
189
|
+
self._settings = replace(self._settings, threshold=value)
|
|
190
|
+
if self._engine is not None:
|
|
191
|
+
self._engine.apply_threshold(value)
|
|
192
|
+
self.app.threshold_pct = value
|
|
193
|
+
self.query_one("#auto-active-panel", AccountsPanel).refresh()
|
|
194
|
+
self._update_summary()
|
|
195
|
+
# The Next best list ranks by the lines in force, so it must follow
|
|
196
|
+
# the session value now rather than at the next snapshot: under a
|
|
197
|
+
# weekly line the order and the 5h rows' "(line N%)" both move.
|
|
198
|
+
self._on_snapshot(self.app.snapshot)
|
|
199
|
+
|
|
200
|
+
def _update_summary(self) -> None:
|
|
201
|
+
palette = Palette.from_theme(self.app.current_theme)
|
|
202
|
+
text = Text()
|
|
203
|
+
text.append("auto-switch · ")
|
|
204
|
+
text.append(
|
|
205
|
+
f"threshold {pct_label(self._settings.threshold)}%",
|
|
206
|
+
style=palette.accent if self._adjusting else "",
|
|
207
|
+
)
|
|
208
|
+
if self._settings.threshold != self._configured_threshold:
|
|
209
|
+
text.append(" (session)", style=palette.muted)
|
|
210
|
+
if self._settings.weekly_threshold is not None:
|
|
211
|
+
text.append(
|
|
212
|
+
f" · weekly {pct_label(self._settings.weekly_threshold)}%"
|
|
213
|
+
)
|
|
214
|
+
text.append(f" · poll every {self._settings.interval_seconds:.0f}s")
|
|
215
|
+
if self._adjusting:
|
|
216
|
+
text.append(" ← → adjust · enter done", style=palette.muted)
|
|
217
|
+
self.query_one("#auto-summary", Static).update(text)
|
|
218
|
+
|
|
219
|
+
# -- engine -------------------------------------------------------------
|
|
220
|
+
|
|
221
|
+
def _start_engine(self, *, dry_run: bool) -> None:
|
|
222
|
+
engine = AutoSwitchEngine(
|
|
223
|
+
self.app.switcher,
|
|
224
|
+
self._settings,
|
|
225
|
+
self._emit_from_thread,
|
|
226
|
+
dry_run=dry_run,
|
|
227
|
+
)
|
|
228
|
+
self._engine = engine
|
|
229
|
+
self.run_worker(
|
|
230
|
+
engine.run_loop,
|
|
231
|
+
thread=True,
|
|
232
|
+
group="engine",
|
|
233
|
+
exit_on_error=False,
|
|
234
|
+
name=f"auto-engine-{'dry' if dry_run else 'live'}",
|
|
235
|
+
)
|
|
236
|
+
self._update_badge()
|
|
237
|
+
log = self.query_one("#event-log", RichLog)
|
|
238
|
+
mode = "DRY-RUN (watching only)" if dry_run else "LIVE (will switch accounts)"
|
|
239
|
+
log.write(
|
|
240
|
+
Text(
|
|
241
|
+
f"— engine started: {mode} —",
|
|
242
|
+
style=Palette.from_theme(self.app.current_theme).muted,
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
def _emit_from_thread(self, event: AutoSwitchEvent) -> None:
|
|
247
|
+
"""Engine ``on_event`` callback — runs on the worker thread."""
|
|
248
|
+
try:
|
|
249
|
+
self.app.call_from_thread(self._on_engine_event, event)
|
|
250
|
+
except Exception:
|
|
251
|
+
# App/screen tearing down mid-tick; the event has nowhere to go.
|
|
252
|
+
pass
|
|
253
|
+
|
|
254
|
+
def _on_engine_event(self, event: AutoSwitchEvent) -> None:
|
|
255
|
+
if not self.is_attached:
|
|
256
|
+
return
|
|
257
|
+
palette = Palette.from_theme(self.app.current_theme)
|
|
258
|
+
self.query_one("#event-log", RichLog).write(event_text(event, palette=palette))
|
|
259
|
+
if event.kind == "switch":
|
|
260
|
+
self.app.request_refresh()
|
|
261
|
+
|
|
262
|
+
def action_toggle_live(self) -> None:
|
|
263
|
+
if self._engine is None:
|
|
264
|
+
return
|
|
265
|
+
if self._engine.dry_run:
|
|
266
|
+
self.app.push_screen(
|
|
267
|
+
ConfirmModal(
|
|
268
|
+
"Go live? claude-swap will switch your active account "
|
|
269
|
+
"automatically when the threshold is reached.\n\n"
|
|
270
|
+
"(Same behavior as running `cswap auto` in a terminal.)",
|
|
271
|
+
title="Go live",
|
|
272
|
+
yes_label="Go live",
|
|
273
|
+
),
|
|
274
|
+
self._on_live_confirm,
|
|
275
|
+
)
|
|
276
|
+
else:
|
|
277
|
+
self._restart_engine(dry_run=True)
|
|
278
|
+
|
|
279
|
+
def _on_live_confirm(self, confirmed: bool | None) -> None:
|
|
280
|
+
if confirmed:
|
|
281
|
+
self._restart_engine(dry_run=False)
|
|
282
|
+
|
|
283
|
+
def _restart_engine(self, *, dry_run: bool) -> None:
|
|
284
|
+
if self._engine is not None:
|
|
285
|
+
self._engine.stop()
|
|
286
|
+
self._start_engine(dry_run=dry_run)
|
|
287
|
+
|
|
288
|
+
def _update_badge(self) -> None:
|
|
289
|
+
badge = self.query_one("#mode-badge", Static)
|
|
290
|
+
if self._engine is not None and not self._engine.dry_run:
|
|
291
|
+
badge.update(" LIVE ")
|
|
292
|
+
badge.set_classes("live")
|
|
293
|
+
else:
|
|
294
|
+
badge.update(" DRY-RUN ")
|
|
295
|
+
badge.set_classes("dry")
|
|
296
|
+
|
|
297
|
+
# -- candidates -----------------------------------------------------------
|
|
298
|
+
|
|
299
|
+
def _on_snapshot(self, snap: AccountsSnapshot | None) -> None:
|
|
300
|
+
if snap is None:
|
|
301
|
+
return
|
|
302
|
+
self.query_one("#candidates", Static).update(
|
|
303
|
+
self._candidates_text(snap, active_number=snap.active_number)
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
def _candidates_text(
|
|
307
|
+
self, snap: AccountsSnapshot, active_number: str | None
|
|
308
|
+
) -> Text:
|
|
309
|
+
"""Switch targets ranked by headroom against their own switch lines
|
|
310
|
+
(best first) — the engine's own ordering."""
|
|
311
|
+
# Same window set AND the same lines as the engine: autoswitch.model,
|
|
312
|
+
# each account's own line (its policy threshold, else the session
|
|
313
|
+
# threshold — `_settings` is what `_set_threshold` replaces), the
|
|
314
|
+
# weekly line, and the session threshold as the ruler every account is
|
|
315
|
+
# scored on, so the displayed ranking can never disagree with the
|
|
316
|
+
# account it picks.
|
|
317
|
+
palette = Palette.from_theme(self.app.current_theme)
|
|
318
|
+
settings = self._settings
|
|
319
|
+
models = parse_model_names(settings.model) if settings else ()
|
|
320
|
+
threshold = settings.threshold if settings else 90.0
|
|
321
|
+
weekly = settings.weekly_threshold if settings else None
|
|
322
|
+
candidates = [
|
|
323
|
+
acc for acc in snap.accounts
|
|
324
|
+
if acc.number != active_number and acc.switchable
|
|
325
|
+
]
|
|
326
|
+
ranked: list[tuple[float, str]] = [] # (sort key: -policy headroom, number)
|
|
327
|
+
lines: dict[str, tuple[AccountSnapshot, Text, Text]] = {} # (acc, name, the rest)
|
|
328
|
+
for acc in candidates:
|
|
329
|
+
line = (
|
|
330
|
+
acc.policy.threshold if acc.policy.threshold is not None else threshold
|
|
331
|
+
)
|
|
332
|
+
binding = binding_window(
|
|
333
|
+
oauth.relevant_windows(acc.usage.last_good, models),
|
|
334
|
+
line,
|
|
335
|
+
weekly,
|
|
336
|
+
scale=threshold,
|
|
337
|
+
)
|
|
338
|
+
head, entry = Text(), Text()
|
|
339
|
+
head.append(f"\n {acc.number:>2} ", style=palette.foreground)
|
|
340
|
+
head.append(acc.email, style=palette.foreground)
|
|
341
|
+
if acc.usage.sentinel is not None:
|
|
342
|
+
entry.append(
|
|
343
|
+
f" {data.sentinel_label(acc.usage.sentinel, acc.number)}",
|
|
344
|
+
style=palette.muted,
|
|
345
|
+
)
|
|
346
|
+
ranked.append((998.0, acc.number))
|
|
347
|
+
elif binding is None:
|
|
348
|
+
entry.append(" usage unknown", style=palette.muted)
|
|
349
|
+
ranked.append((999.0, acc.number))
|
|
350
|
+
else:
|
|
351
|
+
# The raw pct of the window that binds, and — only once the
|
|
352
|
+
# lines differ, globally or for this account — the line it is
|
|
353
|
+
# judged against.
|
|
354
|
+
entry.append(
|
|
355
|
+
f" {binding.label} {binding.pct:3.0f}% used",
|
|
356
|
+
style=palette.severity(binding.pct),
|
|
357
|
+
)
|
|
358
|
+
if weekly is not None or acc.policy.threshold is not None:
|
|
359
|
+
entry.append(
|
|
360
|
+
f" (line {pct_label(binding.line)}%)", style=palette.muted
|
|
361
|
+
)
|
|
362
|
+
ranked.append((-binding.line_headroom, acc.number))
|
|
363
|
+
lines[acc.number] = (acc, head, entry)
|
|
364
|
+
|
|
365
|
+
text = Text()
|
|
366
|
+
text.append("Next best", style=palette.muted)
|
|
367
|
+
if not ranked:
|
|
368
|
+
text.append("\n no other switchable accounts", style=palette.muted)
|
|
369
|
+
return text
|
|
370
|
+
order = [lines[number] for _pct, number in sorted(ranked)]
|
|
371
|
+
# The box has no width before its first layout; its CSS padding is 2 a side.
|
|
372
|
+
budget = self.query_one("#candidates", Static).size.width or self.app.size.width - 4
|
|
373
|
+
for row in fit_login(
|
|
374
|
+
lambda login: [
|
|
375
|
+
Text.assemble(head, tail, Text(login_segment(acc, login), style=palette.muted))
|
|
376
|
+
for acc, head, tail in order
|
|
377
|
+
],
|
|
378
|
+
budget,
|
|
379
|
+
):
|
|
380
|
+
text.append(row)
|
|
381
|
+
return text
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/* claude-swap TUI — flat, low-chrome dark layout.
|
|
2
|
+
Colors come from the registered "cswap-dark" theme (theme.py); this file
|
|
3
|
+
only handles layout, spacing, and the few component states. */
|
|
4
|
+
|
|
5
|
+
Screen {
|
|
6
|
+
background: $background;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* -- accounts panel (the always-visible monitor) --------------------------- */
|
|
10
|
+
|
|
11
|
+
#accounts-panel {
|
|
12
|
+
height: auto;
|
|
13
|
+
padding: 1 3;
|
|
14
|
+
background: $background;
|
|
15
|
+
border-bottom: solid $panel;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#auto-active-panel {
|
|
19
|
+
height: auto;
|
|
20
|
+
padding: 1 3 0 3;
|
|
21
|
+
background: $background;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* -- dashboard menu ----------------------------------------------------------- */
|
|
25
|
+
|
|
26
|
+
#menu-title {
|
|
27
|
+
height: 1;
|
|
28
|
+
margin-top: 1;
|
|
29
|
+
padding: 0 3;
|
|
30
|
+
color: $secondary;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#menu, #accounts {
|
|
34
|
+
background: $background;
|
|
35
|
+
padding: 1 2 0 1;
|
|
36
|
+
scrollbar-size-vertical: 1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#menu:focus, #accounts:focus {
|
|
40
|
+
background-tint: $foreground 0%;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#menu ListItem, #accounts ListItem {
|
|
44
|
+
background: transparent;
|
|
45
|
+
padding: 0 1;
|
|
46
|
+
border-left: thick $background;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#accounts ListItem {
|
|
50
|
+
margin-bottom: 1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#menu ListItem.-highlight,
|
|
54
|
+
#menu:focus ListItem.-highlight,
|
|
55
|
+
#accounts ListItem.-highlight,
|
|
56
|
+
#accounts:focus ListItem.-highlight {
|
|
57
|
+
color: $foreground;
|
|
58
|
+
background: $surface;
|
|
59
|
+
text-style: none;
|
|
60
|
+
border-left: thick $primary;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#accounts ListItem.flash {
|
|
64
|
+
background: $panel;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
MenuItem Static { color: $foreground; }
|
|
68
|
+
MenuItem Static.menu-item-muted { color: $secondary; }
|
|
69
|
+
|
|
70
|
+
/* -- switch / watch screens --------------------------------------------------- */
|
|
71
|
+
|
|
72
|
+
#list-title {
|
|
73
|
+
height: 1;
|
|
74
|
+
margin-top: 1;
|
|
75
|
+
padding: 0 3;
|
|
76
|
+
color: $secondary;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* -- auto screen ---------------------------------------------------------- */
|
|
80
|
+
|
|
81
|
+
#auto-top {
|
|
82
|
+
height: auto;
|
|
83
|
+
background: $background;
|
|
84
|
+
padding: 1 2;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#auto-title-row {
|
|
88
|
+
height: 1;
|
|
89
|
+
margin-bottom: 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#mode-badge {
|
|
93
|
+
width: auto;
|
|
94
|
+
text-style: bold;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#mode-badge.dry {
|
|
98
|
+
background: $panel;
|
|
99
|
+
color: $warning;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#mode-badge.live {
|
|
103
|
+
background: $primary;
|
|
104
|
+
color: $background;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#auto-summary {
|
|
108
|
+
width: 1fr;
|
|
109
|
+
color: $secondary;
|
|
110
|
+
padding-left: 2;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#candidates {
|
|
114
|
+
height: auto;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#event-log {
|
|
118
|
+
background: $background;
|
|
119
|
+
border-top: solid $panel;
|
|
120
|
+
padding: 0 1;
|
|
121
|
+
scrollbar-size-vertical: 1;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* -- modals ----------------------------------------------------------------- */
|
|
125
|
+
|
|
126
|
+
ConfirmModal, AddTokenModal, OutputModal {
|
|
127
|
+
align: center middle;
|
|
128
|
+
background: $background 60%;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.modal-box {
|
|
132
|
+
width: 64;
|
|
133
|
+
max-width: 90%;
|
|
134
|
+
height: auto;
|
|
135
|
+
max-height: 80%;
|
|
136
|
+
background: $surface;
|
|
137
|
+
border: round $panel;
|
|
138
|
+
padding: 1 2;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.modal-box-wide {
|
|
142
|
+
width: 90;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.modal-title {
|
|
146
|
+
text-style: bold;
|
|
147
|
+
color: $primary;
|
|
148
|
+
margin-bottom: 1;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.modal-body {
|
|
152
|
+
color: $foreground;
|
|
153
|
+
margin-bottom: 1;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.modal-buttons {
|
|
157
|
+
height: auto;
|
|
158
|
+
align-horizontal: right;
|
|
159
|
+
margin-top: 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* Flat chip buttons: quiet at rest, terracotta block when focused. ←/→ move
|
|
163
|
+
focus between them, Enter presses — the accent shows where Enter lands. */
|
|
164
|
+
.modal-buttons Button {
|
|
165
|
+
border: none;
|
|
166
|
+
height: 1;
|
|
167
|
+
min-width: 12;
|
|
168
|
+
padding: 0 2;
|
|
169
|
+
margin-left: 2;
|
|
170
|
+
background: $panel;
|
|
171
|
+
color: $foreground;
|
|
172
|
+
text-style: none;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.modal-buttons Button:hover {
|
|
176
|
+
background: $panel-lighten-1;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.modal-buttons Button:focus {
|
|
180
|
+
background: $primary;
|
|
181
|
+
color: $background;
|
|
182
|
+
text-style: bold;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.modal-hint {
|
|
186
|
+
height: 1;
|
|
187
|
+
margin-top: 1;
|
|
188
|
+
color: $secondary;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.modal-output {
|
|
192
|
+
height: auto;
|
|
193
|
+
max-height: 20;
|
|
194
|
+
background: $background;
|
|
195
|
+
padding: 1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.form-error {
|
|
199
|
+
height: 1;
|
|
200
|
+
color: $error;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
AddTokenModal Input {
|
|
204
|
+
margin-bottom: 1;
|
|
205
|
+
}
|