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,159 @@
|
|
|
1
|
+
"""Modal screens: confirmations, token entry, and captured-output display."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from rich.text import Text
|
|
8
|
+
from textual.app import ComposeResult
|
|
9
|
+
from textual.binding import Binding
|
|
10
|
+
from textual.containers import Horizontal, Vertical, VerticalScroll
|
|
11
|
+
from textual.screen import ModalScreen
|
|
12
|
+
from textual.widgets import Button, Input, Label, Static
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ConfirmModal(ModalScreen[bool]):
|
|
16
|
+
"""Yes/No confirmation. Dismisses with True only on explicit confirm.
|
|
17
|
+
|
|
18
|
+
Keyboard-first: ←/→ move between the buttons (Enter presses the focused
|
|
19
|
+
one), y/n answer directly, Esc cancels. Clicking still works.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
BINDINGS = [
|
|
23
|
+
Binding("y", "confirm", "Yes", show=False),
|
|
24
|
+
Binding("n,escape", "cancel", "No", show=False),
|
|
25
|
+
Binding("left", "app.focus_previous", show=False),
|
|
26
|
+
Binding("right", "app.focus_next", show=False),
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self, message: str, *, title: str = "Confirm", yes_label: str = "Yes"
|
|
31
|
+
) -> None:
|
|
32
|
+
super().__init__()
|
|
33
|
+
self._title = title
|
|
34
|
+
self._message = message
|
|
35
|
+
self._yes_label = yes_label
|
|
36
|
+
|
|
37
|
+
def compose(self) -> ComposeResult:
|
|
38
|
+
with Vertical(classes="modal-box"):
|
|
39
|
+
yield Label(self._title, classes="modal-title")
|
|
40
|
+
yield Static(self._message, classes="modal-body")
|
|
41
|
+
with Horizontal(classes="modal-buttons"):
|
|
42
|
+
yield Button(self._yes_label, id="yes")
|
|
43
|
+
yield Button("Cancel", id="no")
|
|
44
|
+
yield Static(
|
|
45
|
+
f"← → · enter · y {self._yes_label.lower()} · n / esc cancel",
|
|
46
|
+
classes="modal-hint",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
50
|
+
self.dismiss(event.button.id == "yes")
|
|
51
|
+
|
|
52
|
+
def action_confirm(self) -> None:
|
|
53
|
+
self.dismiss(True)
|
|
54
|
+
|
|
55
|
+
def action_cancel(self) -> None:
|
|
56
|
+
self.dismiss(False)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass
|
|
60
|
+
class TokenForm:
|
|
61
|
+
"""What the add-token modal collects."""
|
|
62
|
+
|
|
63
|
+
token: str
|
|
64
|
+
email: str | None
|
|
65
|
+
slot: int | None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class AddTokenModal(ModalScreen["TokenForm | None"]):
|
|
69
|
+
"""Collects a setup-token/API key, optional email label, optional slot.
|
|
70
|
+
|
|
71
|
+
←/→ only reach the screen when a Button is focused (a focused Input
|
|
72
|
+
consumes them for cursor movement), so they safely double as button
|
|
73
|
+
navigation.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
BINDINGS = [
|
|
77
|
+
Binding("escape", "cancel", "Cancel", show=False),
|
|
78
|
+
Binding("left", "app.focus_previous", show=False),
|
|
79
|
+
Binding("right", "app.focus_next", show=False),
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
def compose(self) -> ComposeResult:
|
|
83
|
+
with Vertical(classes="modal-box"):
|
|
84
|
+
yield Label("Add account from token", classes="modal-title")
|
|
85
|
+
yield Static(
|
|
86
|
+
"OAuth setup-token (sk-ant-oat…) or Console API key "
|
|
87
|
+
"(sk-ant-api…, sk-ant-usr…); the type is auto-detected.",
|
|
88
|
+
classes="modal-body",
|
|
89
|
+
)
|
|
90
|
+
yield Input(password=True, placeholder="token (required)", id="token")
|
|
91
|
+
yield Input(placeholder="email label (optional)", id="email")
|
|
92
|
+
yield Input(placeholder="slot number (optional)", id="slot", type="integer")
|
|
93
|
+
yield Static("", id="form-error", classes="form-error")
|
|
94
|
+
with Horizontal(classes="modal-buttons"):
|
|
95
|
+
yield Button("Add", id="add")
|
|
96
|
+
yield Button("Cancel", id="cancel")
|
|
97
|
+
yield Static(
|
|
98
|
+
"enter add · tab next field · esc cancel",
|
|
99
|
+
classes="modal-hint",
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
103
|
+
if event.button.id == "cancel":
|
|
104
|
+
self.dismiss(None)
|
|
105
|
+
return
|
|
106
|
+
self._submit()
|
|
107
|
+
|
|
108
|
+
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
109
|
+
self._submit()
|
|
110
|
+
|
|
111
|
+
def _submit(self) -> None:
|
|
112
|
+
token = self.query_one("#token", Input).value.strip()
|
|
113
|
+
email = self.query_one("#email", Input).value.strip() or None
|
|
114
|
+
slot_raw = self.query_one("#slot", Input).value.strip()
|
|
115
|
+
if not token:
|
|
116
|
+
self.query_one("#form-error", Static).update("Token is required.")
|
|
117
|
+
return
|
|
118
|
+
slot: int | None = None
|
|
119
|
+
if slot_raw:
|
|
120
|
+
try:
|
|
121
|
+
slot = int(slot_raw)
|
|
122
|
+
except ValueError:
|
|
123
|
+
self.query_one("#form-error", Static).update(
|
|
124
|
+
"Slot must be a number."
|
|
125
|
+
)
|
|
126
|
+
return
|
|
127
|
+
if slot < 1:
|
|
128
|
+
self.query_one("#form-error", Static).update("Slot must be >= 1.")
|
|
129
|
+
return
|
|
130
|
+
self.dismiss(TokenForm(token=token, email=email, slot=slot))
|
|
131
|
+
|
|
132
|
+
def action_cancel(self) -> None:
|
|
133
|
+
self.dismiss(None)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class OutputModal(ModalScreen[None]):
|
|
137
|
+
"""Scrollable display of captured (ANSI-colored) action output."""
|
|
138
|
+
|
|
139
|
+
BINDINGS = [Binding("escape,q,enter", "dismiss_modal", "Close", show=False)]
|
|
140
|
+
|
|
141
|
+
def __init__(self, title: str, output: str) -> None:
|
|
142
|
+
super().__init__()
|
|
143
|
+
self._title = title
|
|
144
|
+
self._output = output
|
|
145
|
+
|
|
146
|
+
def compose(self) -> ComposeResult:
|
|
147
|
+
with Vertical(classes="modal-box modal-box-wide"):
|
|
148
|
+
yield Label(self._title, classes="modal-title")
|
|
149
|
+
with VerticalScroll(classes="modal-output"):
|
|
150
|
+
yield Static(Text.from_ansi(self._output.rstrip() or "(no output)"))
|
|
151
|
+
with Horizontal(classes="modal-buttons"):
|
|
152
|
+
yield Button("Close", id="close")
|
|
153
|
+
yield Static("esc close", classes="modal-hint")
|
|
154
|
+
|
|
155
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
156
|
+
self.dismiss(None)
|
|
157
|
+
|
|
158
|
+
def action_dismiss_modal(self) -> None:
|
|
159
|
+
self.dismiss(None)
|
claude_swap/tui/theme.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""The "cswap-dark" and "cswap-light" Textual themes.
|
|
2
|
+
|
|
3
|
+
A subtle modern dark theme: neutral charcoal backgrounds in the VS Code
|
|
4
|
+
register, one warm terracotta accent (the same xterm-173 tone printer.py has
|
|
5
|
+
always used for the CLI — a deliberate nod to Claude Code's orange, used
|
|
6
|
+
sparingly), and desaturated severity colors so usage bars read calmly on a
|
|
7
|
+
dark background. Deliberately *not* a wholesale copy of any other tool's
|
|
8
|
+
palette.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from textual.theme import Theme
|
|
14
|
+
|
|
15
|
+
# The colours live in ``claude_swap.usage_bars`` (single source of truth,
|
|
16
|
+
# shared with the plain CLI, which must not import Textual). They are
|
|
17
|
+
# re-exported here because the Theme objects below are built from them.
|
|
18
|
+
from claude_swap.usage_bars import ( # noqa: F401 (re-exported)
|
|
19
|
+
ACCENT,
|
|
20
|
+
ACCENT_LIGHT,
|
|
21
|
+
BACKGROUND,
|
|
22
|
+
BACKGROUND_LIGHT,
|
|
23
|
+
CRIT_PCT,
|
|
24
|
+
FOREGROUND,
|
|
25
|
+
FOREGROUND_LIGHT,
|
|
26
|
+
MUTED,
|
|
27
|
+
MUTED_LIGHT,
|
|
28
|
+
PANEL,
|
|
29
|
+
PANEL_LIGHT,
|
|
30
|
+
SEV_CRIT,
|
|
31
|
+
SEV_CRIT_LIGHT,
|
|
32
|
+
SEV_OK,
|
|
33
|
+
SEV_OK_LIGHT,
|
|
34
|
+
SEV_WARN,
|
|
35
|
+
SEV_WARN_LIGHT,
|
|
36
|
+
SURFACE,
|
|
37
|
+
SURFACE_LIGHT,
|
|
38
|
+
TRACK,
|
|
39
|
+
TRACK_LIGHT,
|
|
40
|
+
WARN_PCT,
|
|
41
|
+
Palette,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
CSWAP_DARK = Theme(
|
|
46
|
+
name="cswap-dark",
|
|
47
|
+
primary=ACCENT,
|
|
48
|
+
secondary=MUTED,
|
|
49
|
+
accent=ACCENT,
|
|
50
|
+
foreground=FOREGROUND,
|
|
51
|
+
background=BACKGROUND,
|
|
52
|
+
surface=SURFACE,
|
|
53
|
+
panel=PANEL,
|
|
54
|
+
success=SEV_OK,
|
|
55
|
+
warning=SEV_WARN,
|
|
56
|
+
error=SEV_CRIT,
|
|
57
|
+
dark=True,
|
|
58
|
+
variables={
|
|
59
|
+
# Footer keys pick up the accent instead of the default blue.
|
|
60
|
+
"footer-key-foreground": ACCENT,
|
|
61
|
+
"block-cursor-background": PANEL,
|
|
62
|
+
"block-cursor-foreground": FOREGROUND,
|
|
63
|
+
"block-cursor-text-style": "none",
|
|
64
|
+
"track": TRACK,
|
|
65
|
+
},
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
CSWAP_LIGHT = Theme(
|
|
69
|
+
name="cswap-light",
|
|
70
|
+
primary=ACCENT_LIGHT,
|
|
71
|
+
secondary=MUTED_LIGHT,
|
|
72
|
+
accent=ACCENT_LIGHT,
|
|
73
|
+
foreground=FOREGROUND_LIGHT,
|
|
74
|
+
background=BACKGROUND_LIGHT,
|
|
75
|
+
surface=SURFACE_LIGHT,
|
|
76
|
+
panel=PANEL_LIGHT,
|
|
77
|
+
success=SEV_OK_LIGHT,
|
|
78
|
+
warning=SEV_WARN_LIGHT,
|
|
79
|
+
error=SEV_CRIT_LIGHT,
|
|
80
|
+
dark=False,
|
|
81
|
+
variables={
|
|
82
|
+
"footer-key-foreground": ACCENT_LIGHT,
|
|
83
|
+
"block-cursor-background": PANEL_LIGHT,
|
|
84
|
+
"block-cursor-foreground": FOREGROUND_LIGHT,
|
|
85
|
+
"block-cursor-text-style": "none",
|
|
86
|
+
"track": TRACK_LIGHT,
|
|
87
|
+
},
|
|
88
|
+
)
|