fleetdeck 0.3.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.
- fleetdeck/__init__.py +3 -0
- fleetdeck/__main__.py +232 -0
- fleetdeck/accounts.py +115 -0
- fleetdeck/adapters/__init__.py +0 -0
- fleetdeck/adapters/base.py +71 -0
- fleetdeck/adapters/claude_cli.py +187 -0
- fleetdeck/adapters/codex_cli.py +362 -0
- fleetdeck/adapters/demo.py +331 -0
- fleetdeck/config.py +323 -0
- fleetdeck/db.py +511 -0
- fleetdeck/gitinfo.py +169 -0
- fleetdeck/models.py +178 -0
- fleetdeck/paths.py +64 -0
- fleetdeck/proc.py +92 -0
- fleetdeck/redact.py +51 -0
- fleetdeck/services/__init__.py +0 -0
- fleetdeck/services/dispatcher.py +382 -0
- fleetdeck/services/fleet.py +65 -0
- fleetdeck/services/monitor.py +253 -0
- fleetdeck/services/notifier.py +71 -0
- fleetdeck/status.py +97 -0
- fleetdeck/terminal.py +235 -0
- fleetdeck/termrender.py +129 -0
- fleetdeck/ui/__init__.py +0 -0
- fleetdeck/ui/app.py +1295 -0
- fleetdeck/ui/app.tcss +263 -0
- fleetdeck/ui/commands.py +63 -0
- fleetdeck/ui/screens/__init__.py +0 -0
- fleetdeck/ui/screens/modals.py +623 -0
- fleetdeck/ui/style.py +150 -0
- fleetdeck/ui/views.py +230 -0
- fleetdeck/ui/widgets/__init__.py +0 -0
- fleetdeck/ui/widgets/agent_table.py +185 -0
- fleetdeck/ui/widgets/bottom.py +27 -0
- fleetdeck/ui/widgets/details.py +295 -0
- fleetdeck/ui/widgets/header.py +87 -0
- fleetdeck/ui/widgets/sidebar.py +227 -0
- fleetdeck/ui/widgets/splitter.py +66 -0
- fleetdeck/ui/widgets/terminal.py +119 -0
- fleetdeck-0.3.0.dist-info/METADATA +245 -0
- fleetdeck-0.3.0.dist-info/RECORD +44 -0
- fleetdeck-0.3.0.dist-info/WHEEL +4 -0
- fleetdeck-0.3.0.dist-info/entry_points.txt +2 -0
- fleetdeck-0.3.0.dist-info/licenses/LICENSE +21 -0
fleetdeck/ui/style.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Palette per theme flavour + small formatting helpers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from rich.text import Text
|
|
8
|
+
|
|
9
|
+
from ..models import AgentStatus, TaskStatus
|
|
10
|
+
from ..status import STATUS_ICONS
|
|
11
|
+
|
|
12
|
+
# Catppuccin accents per flavour (green, yellow, peach, mauve, blue, red, overlay1, overlay0)
|
|
13
|
+
_FLAVOURS = {
|
|
14
|
+
"mocha": ("#a6e3a1", "#f9e2af", "#fab387", "#cba6f7", "#89b4fa", "#f38ba8", "#7f849c", "#6c7086"),
|
|
15
|
+
"macchiato": ("#a6da95", "#eed49f", "#f5a97f", "#c6a0f6", "#8aadf4", "#ed8796", "#8087a2", "#6e738d"),
|
|
16
|
+
"frappe": ("#a6d189", "#e5c890", "#ef9f76", "#ca9ee6", "#8caaee", "#e78284", "#838ba7", "#737994"),
|
|
17
|
+
"latte": ("#40a02b", "#df8e1d", "#fe640b", "#8839ef", "#1e66f5", "#d20f39", "#8c8fa1", "#9ca0b0"),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def palette(theme: str) -> dict[AgentStatus, str]:
|
|
22
|
+
flavour = "mocha"
|
|
23
|
+
for name in _FLAVOURS:
|
|
24
|
+
if theme.endswith(name):
|
|
25
|
+
flavour = name
|
|
26
|
+
g, y, o, p, b, r, gray1, gray0 = _FLAVOURS[flavour]
|
|
27
|
+
return {
|
|
28
|
+
AgentStatus.RUNNING: g,
|
|
29
|
+
AgentStatus.WAITING: y,
|
|
30
|
+
AgentStatus.PERMISSION: o,
|
|
31
|
+
AgentStatus.PLANNING: p,
|
|
32
|
+
AgentStatus.COMPLETED: b,
|
|
33
|
+
AgentStatus.FAILED: r,
|
|
34
|
+
AgentStatus.IDLE: gray1,
|
|
35
|
+
AgentStatus.STOPPED: gray0,
|
|
36
|
+
AgentStatus.UNKNOWN: gray0,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Styler:
|
|
41
|
+
"""Holds the active palette so widgets render status consistently."""
|
|
42
|
+
|
|
43
|
+
def __init__(self, theme: str) -> None:
|
|
44
|
+
self.set_theme(theme)
|
|
45
|
+
|
|
46
|
+
def set_theme(self, theme: str) -> None:
|
|
47
|
+
self.colors = palette(theme)
|
|
48
|
+
|
|
49
|
+
def badge(self, status: AgentStatus, *, label: bool = True) -> Text:
|
|
50
|
+
color = self.colors[status]
|
|
51
|
+
t = Text(STATUS_ICONS[status], style=f"bold {color}")
|
|
52
|
+
if label:
|
|
53
|
+
t.append(f" {status.label}", style=color)
|
|
54
|
+
return t
|
|
55
|
+
|
|
56
|
+
def dot(self, status: AgentStatus) -> Text:
|
|
57
|
+
return Text(STATUS_ICONS[status], style=f"bold {self.colors[status]}")
|
|
58
|
+
|
|
59
|
+
def task_status(self, status: TaskStatus) -> Text:
|
|
60
|
+
c = self.colors
|
|
61
|
+
color = {
|
|
62
|
+
TaskStatus.QUEUED: c[AgentStatus.IDLE],
|
|
63
|
+
TaskStatus.DISPATCHING: c[AgentStatus.PLANNING],
|
|
64
|
+
TaskStatus.RUNNING: c[AgentStatus.RUNNING],
|
|
65
|
+
TaskStatus.BLOCKED: c[AgentStatus.PERMISSION],
|
|
66
|
+
TaskStatus.COMPLETED: c[AgentStatus.COMPLETED],
|
|
67
|
+
TaskStatus.FAILED: c[AgentStatus.FAILED],
|
|
68
|
+
TaskStatus.CANCELLED: c[AgentStatus.STOPPED],
|
|
69
|
+
}[status]
|
|
70
|
+
return Text(status.value, style=color)
|
|
71
|
+
|
|
72
|
+
def level(self, level: str) -> str:
|
|
73
|
+
c = self.colors
|
|
74
|
+
return {
|
|
75
|
+
"success": c[AgentStatus.COMPLETED],
|
|
76
|
+
"warning": c[AgentStatus.PERMISSION],
|
|
77
|
+
"error": c[AgentStatus.FAILED],
|
|
78
|
+
}.get(level, c[AgentStatus.IDLE])
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
PRIORITY_LABELS = {1: "P1 urgent", 2: "P2 high", 3: "P3 normal", 4: "P4 low"}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def duration(seconds: float | None) -> str:
|
|
85
|
+
if seconds is None:
|
|
86
|
+
return "—"
|
|
87
|
+
s = int(max(0, seconds))
|
|
88
|
+
if s < 60:
|
|
89
|
+
return f"{s}s"
|
|
90
|
+
m, s = divmod(s, 60)
|
|
91
|
+
if m < 60:
|
|
92
|
+
return f"{m}m {s:02d}s"
|
|
93
|
+
h, m = divmod(m, 60)
|
|
94
|
+
if h < 24:
|
|
95
|
+
return f"{h}h {m:02d}m"
|
|
96
|
+
d, h = divmod(h, 24)
|
|
97
|
+
return f"{d}d {h}h"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def ago(ts: float | None, now: float | None = None) -> str:
|
|
101
|
+
if not ts:
|
|
102
|
+
return "—"
|
|
103
|
+
delta = (now or time.time()) - ts
|
|
104
|
+
if delta < 5:
|
|
105
|
+
return "just now"
|
|
106
|
+
return f"{duration(delta)} ago"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def clock(ts: float) -> str:
|
|
110
|
+
return time.strftime("%H:%M:%S", time.localtime(ts))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def shorten_path(path: str, width: int = 40) -> str:
|
|
114
|
+
import os
|
|
115
|
+
home = os.path.expanduser("~")
|
|
116
|
+
if path.startswith(home):
|
|
117
|
+
path = "~" + path[len(home):]
|
|
118
|
+
if len(path) <= width:
|
|
119
|
+
return path
|
|
120
|
+
return "…" + path[-(width - 1):]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# ------------------------------------------------------------------ visuals
|
|
124
|
+
def keycap(styler: Styler, key: str) -> Text:
|
|
125
|
+
"""A key rendered as a small filled badge, e.g. ` x `."""
|
|
126
|
+
accent = styler.colors[AgentStatus.PLANNING]
|
|
127
|
+
return Text(f" {key} ", style=f"bold #1e1e2e on {accent}")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def hint_line(styler: Styler, pairs: list[tuple[str, str]], *, suffix: str | None = None,
|
|
131
|
+
indent: int = 2) -> Text:
|
|
132
|
+
"""` [x] run tests [e] set command` style hint row."""
|
|
133
|
+
t = Text(" " * indent)
|
|
134
|
+
for i, (key, label) in enumerate(pairs):
|
|
135
|
+
if i:
|
|
136
|
+
t.append(" ")
|
|
137
|
+
t.append_text(keycap(styler, key))
|
|
138
|
+
t.append(f" {label}", style="")
|
|
139
|
+
if suffix:
|
|
140
|
+
t.append(f" {suffix}", style="dim")
|
|
141
|
+
return t
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def section(styler: Styler, title: str, width: int = 44) -> Text:
|
|
145
|
+
"""Section header: `── Session ─────────`."""
|
|
146
|
+
t = Text()
|
|
147
|
+
t.append("── ", style="dim")
|
|
148
|
+
t.append(title.upper(), style=f"bold {styler.colors[AgentStatus.PLANNING]}")
|
|
149
|
+
t.append(" " + "─" * max(2, width - len(title) - 4), style="dim")
|
|
150
|
+
return t
|
fleetdeck/ui/views.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""Secondary views switched with Ctrl+2…5 (dashboard lives in app.py)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
from rich.text import Text
|
|
9
|
+
from textual.app import ComposeResult
|
|
10
|
+
from textual.binding import Binding
|
|
11
|
+
from textual.containers import Horizontal, Vertical, VerticalScroll
|
|
12
|
+
from textual.widgets import Button, DataTable, Input, Label, Select, Static, Switch
|
|
13
|
+
|
|
14
|
+
from ..config import THEMES, WORKTREE_MODES, Settings
|
|
15
|
+
from ..models import SAFE_PERMISSION_MODES, Agent, Project, Task, TaskStatus
|
|
16
|
+
from ..redact import redact
|
|
17
|
+
from .style import PRIORITY_LABELS, ago, duration, shorten_path
|
|
18
|
+
from .widgets.agent_table import AgentTable
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ProjectsView(Vertical):
|
|
22
|
+
BINDINGS = [
|
|
23
|
+
Binding("e", "app.edit_project", "Edit"),
|
|
24
|
+
Binding("delete,backspace", "app.remove_project", "Remove"),
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
def compose(self) -> ComposeResult:
|
|
28
|
+
yield Static(" Projects", classes="view-title")
|
|
29
|
+
yield DataTable(id="projects-table", cursor_type="row")
|
|
30
|
+
|
|
31
|
+
def on_mount(self) -> None:
|
|
32
|
+
t = self.query_one(DataTable)
|
|
33
|
+
for key, label, w in [("pin", "", 2), ("name", "Name", 22), ("group", "Group", 9),
|
|
34
|
+
("env", "Env", 10), ("agents", "Active", 7),
|
|
35
|
+
("queued", "Queued", 7), ("wt", "Worktree", 9),
|
|
36
|
+
("test", "Test cmd", 16), ("path", "Path", 50)]:
|
|
37
|
+
t.add_column(label, key=key, width=w)
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def selected_project_id(self) -> int | None:
|
|
41
|
+
t = self.query_one(DataTable)
|
|
42
|
+
if not t.row_count:
|
|
43
|
+
return None
|
|
44
|
+
key = t.coordinate_to_cell_key(t.cursor_coordinate).row_key.value
|
|
45
|
+
return int(key) if key else None
|
|
46
|
+
|
|
47
|
+
def update_data(self, projects: list[Project], agents: list[Agent],
|
|
48
|
+
tasks: list[Task]) -> None:
|
|
49
|
+
t = self.query_one(DataTable)
|
|
50
|
+
sel = self.selected_project_id
|
|
51
|
+
t.clear()
|
|
52
|
+
for p in projects:
|
|
53
|
+
active = sum(1 for a in agents if a.project_id == p.id and a.status.is_active)
|
|
54
|
+
queued = sum(1 for x in tasks if x.project_id == p.id
|
|
55
|
+
and x.status is TaskStatus.QUEUED)
|
|
56
|
+
t.add_row("★" if p.pinned else "", Text(p.name, style="bold"), p.group,
|
|
57
|
+
p.environment, str(active or "·"), str(queued or "·"),
|
|
58
|
+
"always" if p.always_worktree else "auto",
|
|
59
|
+
p.test_command or "—", shorten_path(p.path, 50), key=str(p.id))
|
|
60
|
+
if sel is not None:
|
|
61
|
+
ids = [p.id for p in projects]
|
|
62
|
+
if sel in ids:
|
|
63
|
+
t.move_cursor(row=ids.index(sel), animate=False)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class SessionsView(Vertical):
|
|
67
|
+
BINDINGS = [Binding("delete,backspace", "app.remove_session", "Remove session")]
|
|
68
|
+
|
|
69
|
+
def compose(self) -> ComposeResult:
|
|
70
|
+
yield Static(" Agent sessions — every session `claude agents --json --all` reports",
|
|
71
|
+
classes="view-title")
|
|
72
|
+
yield AgentTable(full=True, id="sessions-table")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class TasksView(Vertical):
|
|
76
|
+
BINDINGS = [
|
|
77
|
+
Binding("y", "app.retry_task", "Retry"),
|
|
78
|
+
Binding("c", "app.cancel_task", "Cancel"),
|
|
79
|
+
Binding("delete,backspace", "app.delete_task", "Delete"),
|
|
80
|
+
Binding("plus,equals_sign", "app.task_priority(-1)", "Priority ↑"),
|
|
81
|
+
Binding("minus", "app.task_priority(1)", "Priority ↓"),
|
|
82
|
+
Binding("m", "app.templates", "Templates"),
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
def compose(self) -> ComposeResult:
|
|
86
|
+
yield Static(" Task queues", id="tasks-title", classes="view-title")
|
|
87
|
+
yield DataTable(id="tasks-table", cursor_type="row")
|
|
88
|
+
|
|
89
|
+
def on_mount(self) -> None:
|
|
90
|
+
t = self.query_one(DataTable)
|
|
91
|
+
for key, label, w in [("id", "#", 5), ("prio", "Priority", 10),
|
|
92
|
+
("project", "Project", 18), ("title", "Title", 34),
|
|
93
|
+
("status", "Status", 12), ("agent", "Agent", 30),
|
|
94
|
+
("tries", "Tries", 5), ("age", "Created", 12),
|
|
95
|
+
("dur", "Duration", 9), ("error", "Error", 40)]:
|
|
96
|
+
t.add_column(label, key=key, width=w)
|
|
97
|
+
|
|
98
|
+
@staticmethod
|
|
99
|
+
def _title(task: Task) -> Text:
|
|
100
|
+
t = Text()
|
|
101
|
+
if task.is_follow_up:
|
|
102
|
+
t.append("↻ ", style="bold")
|
|
103
|
+
t.append(redact(task.title))
|
|
104
|
+
if task.depends_on:
|
|
105
|
+
t.append(f" after #{task.depends_on}", style="dim")
|
|
106
|
+
return t
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def selected_task_id(self) -> int | None:
|
|
110
|
+
t = self.query_one(DataTable)
|
|
111
|
+
if not t.row_count:
|
|
112
|
+
return None
|
|
113
|
+
key = t.coordinate_to_cell_key(t.cursor_coordinate).row_key.value
|
|
114
|
+
return int(key) if key else None
|
|
115
|
+
|
|
116
|
+
def update_data(self, tasks: list[Task], projects: dict[int, Project], *,
|
|
117
|
+
paused: bool, max_agents: int) -> None:
|
|
118
|
+
styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
|
|
119
|
+
title = self.query_one("#tasks-title", Static)
|
|
120
|
+
counts = {s: sum(1 for x in tasks if x.status is s) for s in TaskStatus}
|
|
121
|
+
title.update(Text.assemble(
|
|
122
|
+
" Task queues ",
|
|
123
|
+
(f"dispatch {'PAUSED' if paused else 'on'}", "bold"),
|
|
124
|
+
f" · max {max_agents} concurrent · "
|
|
125
|
+
f"{counts[TaskStatus.QUEUED]} queued {counts[TaskStatus.RUNNING]} running "
|
|
126
|
+
f"{counts[TaskStatus.BLOCKED]} blocked {counts[TaskStatus.FAILED]} failed ",
|
|
127
|
+
("z pause/resume · a new task", "dim"),
|
|
128
|
+
))
|
|
129
|
+
t = self.query_one(DataTable)
|
|
130
|
+
sel = self.selected_task_id
|
|
131
|
+
t.clear()
|
|
132
|
+
now = time.time()
|
|
133
|
+
for x in tasks:
|
|
134
|
+
p = projects.get(x.project_id)
|
|
135
|
+
dur = None
|
|
136
|
+
if x.started_at:
|
|
137
|
+
dur = (x.finished_at or now) - x.started_at
|
|
138
|
+
t.add_row(str(x.id), PRIORITY_LABELS.get(x.priority, str(x.priority)),
|
|
139
|
+
p.name if p else "?", self._title(x), styler.task_status(x.status),
|
|
140
|
+
x.agent_name or "—", str(x.attempts), ago(x.created_at, now),
|
|
141
|
+
duration(dur) if dur is not None else "—",
|
|
142
|
+
Text(redact(x.error or ""), style="red"), key=str(x.id))
|
|
143
|
+
ids = [x.id for x in tasks]
|
|
144
|
+
if sel in ids:
|
|
145
|
+
t.move_cursor(row=ids.index(sel), animate=False)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class SettingsView(VerticalScroll):
|
|
149
|
+
def __init__(self, settings: Settings, config_path: str, **kw) -> None:
|
|
150
|
+
super().__init__(**kw)
|
|
151
|
+
self.settings = settings
|
|
152
|
+
self.config_path = config_path
|
|
153
|
+
|
|
154
|
+
def compose(self) -> ComposeResult:
|
|
155
|
+
s = self.settings
|
|
156
|
+
yield Static(" Settings", classes="view-title")
|
|
157
|
+
yield Static(Text(f" Saved to {self.config_path}. Keybindings and environments are "
|
|
158
|
+
"edited in that file.", style="dim"))
|
|
159
|
+
with Vertical(classes="settings-form"):
|
|
160
|
+
for label, widget in [
|
|
161
|
+
("Theme", Select(self._theme_options(s.theme), value=s.theme,
|
|
162
|
+
allow_blank=False, id="set-theme")),
|
|
163
|
+
("Refresh interval (seconds)", Input(str(s.refresh_interval), id="set-refresh",
|
|
164
|
+
type="number")),
|
|
165
|
+
("Max concurrent agents", Input(str(s.max_concurrent_agents), id="set-max",
|
|
166
|
+
type="integer")),
|
|
167
|
+
("Default permission mode", Select([(m, m) for m in SAFE_PERMISSION_MODES],
|
|
168
|
+
value=s.default_permission_mode,
|
|
169
|
+
allow_blank=False, id="set-mode")),
|
|
170
|
+
("Default model (blank = Claude default)",
|
|
171
|
+
Input(s.default_model or "", id="set-model")),
|
|
172
|
+
("Worktree isolation", Select([(m, m) for m in WORKTREE_MODES],
|
|
173
|
+
value=s.worktree_isolation, allow_blank=False,
|
|
174
|
+
id="set-worktree")),
|
|
175
|
+
]:
|
|
176
|
+
with Horizontal(classes="setting-row"):
|
|
177
|
+
yield Label(label, classes="setting-label")
|
|
178
|
+
yield widget
|
|
179
|
+
for label, wid, value in [
|
|
180
|
+
("Show interactive sessions", "set-inter", s.show_interactive_sessions),
|
|
181
|
+
("Pause task dispatch", "set-paused", s.dispatch_paused),
|
|
182
|
+
("Toast notifications", "set-toast", s.notifications.toast),
|
|
183
|
+
("Terminal bell", "set-bell", s.notifications.bell),
|
|
184
|
+
("Desktop notifications", "set-desktop", s.notifications.desktop),
|
|
185
|
+
]:
|
|
186
|
+
with Horizontal(classes="setting-row"):
|
|
187
|
+
yield Label(label, classes="setting-label")
|
|
188
|
+
yield Switch(value=value, id=wid)
|
|
189
|
+
with Horizontal(classes="dialog-buttons"):
|
|
190
|
+
yield Button("Save settings", id="settings-save", variant="primary")
|
|
191
|
+
|
|
192
|
+
def collect(self) -> Settings:
|
|
193
|
+
s = self.settings
|
|
194
|
+
q = self.query_one
|
|
195
|
+
|
|
196
|
+
def num(wid: str, cast, current):
|
|
197
|
+
try:
|
|
198
|
+
return cast(q(wid, Input).value)
|
|
199
|
+
except ValueError:
|
|
200
|
+
return current
|
|
201
|
+
|
|
202
|
+
s.theme = str(q("#set-theme", Select).value)
|
|
203
|
+
interval = num("#set-refresh", float, s.refresh_interval)
|
|
204
|
+
if not math.isfinite(interval):
|
|
205
|
+
interval = s.refresh_interval
|
|
206
|
+
s.refresh_interval = min(300.0, max(0.5, interval))
|
|
207
|
+
s.max_concurrent_agents = max(1, min(64, num("#set-max", int, s.max_concurrent_agents)))
|
|
208
|
+
s.default_permission_mode = str(q("#set-mode", Select).value)
|
|
209
|
+
s.default_model = q("#set-model", Input).value.strip() or None
|
|
210
|
+
s.worktree_isolation = str(q("#set-worktree", Select).value)
|
|
211
|
+
s.show_interactive_sessions = q("#set-inter", Switch).value
|
|
212
|
+
s.dispatch_paused = q("#set-paused", Switch).value
|
|
213
|
+
s.notifications.toast = q("#set-toast", Switch).value
|
|
214
|
+
s.notifications.bell = q("#set-bell", Switch).value
|
|
215
|
+
s.notifications.desktop = q("#set-desktop", Switch).value
|
|
216
|
+
return s
|
|
217
|
+
|
|
218
|
+
def sync_from_settings(self) -> None:
|
|
219
|
+
"""Reflect changes made elsewhere (e.g. z toggling dispatch)."""
|
|
220
|
+
if self.is_mounted:
|
|
221
|
+
self.query_one("#set-paused", Switch).value = self.settings.dispatch_paused
|
|
222
|
+
theme = self.app.theme
|
|
223
|
+
select = self.query_one("#set-theme", Select)
|
|
224
|
+
select.set_options(self._theme_options(theme))
|
|
225
|
+
select.value = theme
|
|
226
|
+
|
|
227
|
+
@staticmethod
|
|
228
|
+
def _theme_options(current: str) -> list[tuple[str, str]]:
|
|
229
|
+
names = list(THEMES) if current in THEMES else [current, *THEMES]
|
|
230
|
+
return [(t, t) for t in names]
|
|
File without changes
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"""Agent dashboard table, updated in place so the cursor never jumps."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from rich.text import Text
|
|
8
|
+
from textual.binding import Binding
|
|
9
|
+
from textual.events import Click, Resize
|
|
10
|
+
from textual.message import Message
|
|
11
|
+
from textual.widgets import DataTable
|
|
12
|
+
|
|
13
|
+
from ...models import Agent, AgentStatus
|
|
14
|
+
from ..style import ago, duration, shorten_path
|
|
15
|
+
|
|
16
|
+
COMPACT = [ # priority order: columns are dropped from the end when space runs out
|
|
17
|
+
("st", "", 1),
|
|
18
|
+
("agent", "Agent", 20),
|
|
19
|
+
("status", "Status", 21),
|
|
20
|
+
("project", "Project", 16),
|
|
21
|
+
("account", "Account", 11),
|
|
22
|
+
("task", "Task", 16),
|
|
23
|
+
("branch", "Branch", 12),
|
|
24
|
+
("elapsed", "Elapsed", 7),
|
|
25
|
+
("activity", "Activity", 10),
|
|
26
|
+
("approvals", "Appr", 4),
|
|
27
|
+
("model", "Model", 8),
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
FULL = COMPACT[:4] + [("id", "ID", 9), ("kind", "Kind", 11)] + COMPACT[4:] + [
|
|
31
|
+
("cwd", "Directory", 36),
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
ALWAYS = {"st", "agent", "status"}
|
|
35
|
+
CELL_PADDING = 2 # DataTable pads each cell by one column on both sides
|
|
36
|
+
GROW = {"agent": 16, "task": 24, "project": 6} # where spare width goes, and how much
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def fit_columns(columns: list[tuple[str, str, int]], available: int
|
|
40
|
+
) -> list[tuple[str, str, int]]:
|
|
41
|
+
"""Pick the columns that fit ``available`` cells, in priority order, then
|
|
42
|
+
hand leftover width to the columns that benefit most from it."""
|
|
43
|
+
if available <= 0:
|
|
44
|
+
return list(columns)
|
|
45
|
+
chosen: list[tuple[str, str, int]] = []
|
|
46
|
+
used = 0
|
|
47
|
+
for key, label, width in columns:
|
|
48
|
+
need = width + CELL_PADDING
|
|
49
|
+
if key in ALWAYS or used + need <= available:
|
|
50
|
+
chosen.append((key, label, width))
|
|
51
|
+
used += need
|
|
52
|
+
else:
|
|
53
|
+
break # keep strict priority: never show a later column without earlier ones
|
|
54
|
+
spare = available - used
|
|
55
|
+
grown = []
|
|
56
|
+
for key, label, width in chosen:
|
|
57
|
+
extra = min(GROW.get(key, 0), max(0, spare))
|
|
58
|
+
spare -= extra
|
|
59
|
+
grown.append((key, label, width + extra))
|
|
60
|
+
return grown
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class AgentTable(DataTable):
|
|
64
|
+
"""``full=True`` adds kind/id/cwd columns for the Sessions view."""
|
|
65
|
+
|
|
66
|
+
# Replace DataTable's enter→select so that a mouse click (which DataTable
|
|
67
|
+
# also turns into RowSelected) can never suspend the TUI into `attach`.
|
|
68
|
+
BINDINGS = [Binding("enter", "request_attach", "Attach", show=False)]
|
|
69
|
+
|
|
70
|
+
class AttachRequested(Message):
|
|
71
|
+
def __init__(self, table: "AgentTable", via_keyboard: bool) -> None:
|
|
72
|
+
self.table = table
|
|
73
|
+
self.via_keyboard = via_keyboard
|
|
74
|
+
super().__init__()
|
|
75
|
+
|
|
76
|
+
def action_request_attach(self) -> None:
|
|
77
|
+
if self.row_count:
|
|
78
|
+
self.post_message(self.AttachRequested(self, via_keyboard=True))
|
|
79
|
+
|
|
80
|
+
def on_click(self, event: Click) -> None:
|
|
81
|
+
if event.chain == 2 and self.row_count:
|
|
82
|
+
self.post_message(self.AttachRequested(self, via_keyboard=False))
|
|
83
|
+
|
|
84
|
+
def __init__(self, *, full: bool = False, **kw) -> None:
|
|
85
|
+
super().__init__(cursor_type="row", zebra_stripes=False, **kw)
|
|
86
|
+
self._base_cols = FULL if full else COMPACT
|
|
87
|
+
self._show_account = False
|
|
88
|
+
self._all_cols = self._columns_for(False)
|
|
89
|
+
self._cols = list(self._all_cols)
|
|
90
|
+
self._agents: dict[str, Agent] = {}
|
|
91
|
+
self._rows: list[Agent] = []
|
|
92
|
+
self._order: list[str] = []
|
|
93
|
+
|
|
94
|
+
def on_mount(self) -> None:
|
|
95
|
+
self._apply_columns(self._cols)
|
|
96
|
+
|
|
97
|
+
def _columns_for(self, show_account: bool) -> list[tuple[str, str, int]]:
|
|
98
|
+
return [c for c in self._base_cols if show_account or c[0] != "account"]
|
|
99
|
+
|
|
100
|
+
def set_show_account(self, show: bool) -> None:
|
|
101
|
+
"""The Account column only earns its space with more than one account."""
|
|
102
|
+
if show == self._show_account:
|
|
103
|
+
return
|
|
104
|
+
self._show_account = show
|
|
105
|
+
self._all_cols = self._columns_for(show)
|
|
106
|
+
width = self.size.width
|
|
107
|
+
cols = fit_columns(self._all_cols, width - 1) if width else list(self._all_cols)
|
|
108
|
+
selected = self.selected.key if self.selected else None
|
|
109
|
+
self._apply_columns(cols)
|
|
110
|
+
if self._rows:
|
|
111
|
+
self.update_agents(self._rows, keep=selected)
|
|
112
|
+
|
|
113
|
+
def _apply_columns(self, cols: list[tuple[str, str, int]]) -> None:
|
|
114
|
+
self._cols = cols
|
|
115
|
+
self.clear(columns=True)
|
|
116
|
+
for key, label, width in cols:
|
|
117
|
+
self.add_column(label, key=key, width=width)
|
|
118
|
+
self._order = [] # force a full row rebuild
|
|
119
|
+
|
|
120
|
+
def on_resize(self, event: Resize) -> None:
|
|
121
|
+
# leave a cell for the vertical scrollbar
|
|
122
|
+
cols = fit_columns(self._all_cols, event.size.width - 1)
|
|
123
|
+
if cols != self._cols:
|
|
124
|
+
selected = self.selected.key if self.selected else None
|
|
125
|
+
self._apply_columns(cols)
|
|
126
|
+
if self._rows:
|
|
127
|
+
self.update_agents(self._rows, keep=selected)
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def selected(self) -> Agent | None:
|
|
131
|
+
if not self.row_count:
|
|
132
|
+
return None
|
|
133
|
+
try:
|
|
134
|
+
key = self.coordinate_to_cell_key(self.cursor_coordinate).row_key.value
|
|
135
|
+
except Exception: # noqa: BLE001 — empty/transient table states
|
|
136
|
+
return None
|
|
137
|
+
return self._agents.get(key or "")
|
|
138
|
+
|
|
139
|
+
def _cells(self, a: Agent, now: float) -> list[Text | str]:
|
|
140
|
+
styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
|
|
141
|
+
dim = "dim"
|
|
142
|
+
cells: dict[str, Text | str] = {
|
|
143
|
+
"st": styler.dot(a.status),
|
|
144
|
+
"agent": Text(a.display_name, style="bold" if a.status.needs_attention else ""),
|
|
145
|
+
"project": Text(a.project_name or "—", style="" if a.project_name else dim),
|
|
146
|
+
"account": Text.assemble(
|
|
147
|
+
("◆ " if a.provider == "claude" else "◎ ",
|
|
148
|
+
styler.colors[AgentStatus.PERMISSION] if a.provider == "claude"
|
|
149
|
+
else styler.colors[AgentStatus.RUNNING]),
|
|
150
|
+
(a.account or "—", "" if a.account else dim)),
|
|
151
|
+
"task": Text(a.task_title or "—", style="" if a.task_title else dim),
|
|
152
|
+
"model": Text(a.model or "—", style="" if a.model else dim),
|
|
153
|
+
"branch": Text(a.branch or "—", style="" if a.branch else dim),
|
|
154
|
+
"status": styler.badge(a.status),
|
|
155
|
+
"elapsed": duration(a.elapsed(now)),
|
|
156
|
+
"activity": ago(a.last_activity, now),
|
|
157
|
+
"approvals": Text(str(a.pending_approvals) if a.pending_approvals else "·",
|
|
158
|
+
style=f"bold {styler.colors[a.status]}" if a.pending_approvals
|
|
159
|
+
else dim),
|
|
160
|
+
"kind": Text(a.kind, style=dim),
|
|
161
|
+
"id": a.id or "—",
|
|
162
|
+
"cwd": Text(shorten_path(a.cwd, 36), style=dim),
|
|
163
|
+
}
|
|
164
|
+
if a.waiting_for and a.status.needs_attention:
|
|
165
|
+
cells["status"].append(f" · {a.waiting_for}", style=dim)
|
|
166
|
+
return [cells[k] for k, _, _ in self._cols]
|
|
167
|
+
|
|
168
|
+
def update_agents(self, agents: list[Agent], keep: str | None = None) -> None:
|
|
169
|
+
now = time.time()
|
|
170
|
+
selected = keep or (self.selected.key if self.selected else None)
|
|
171
|
+
self._rows = list(agents)
|
|
172
|
+
new_order = [a.key for a in agents]
|
|
173
|
+
self._agents = {a.key: a for a in agents}
|
|
174
|
+
if new_order != self._order:
|
|
175
|
+
# structure changed: rebuild, then restore the cursor by key
|
|
176
|
+
self.clear()
|
|
177
|
+
for a in agents:
|
|
178
|
+
self.add_row(*self._cells(a, now), key=a.key)
|
|
179
|
+
self._order = new_order
|
|
180
|
+
if selected in self._agents:
|
|
181
|
+
self.move_cursor(row=new_order.index(selected), animate=False)
|
|
182
|
+
else:
|
|
183
|
+
for a in agents:
|
|
184
|
+
for (col, _, _), value in zip(self._cols, self._cells(a, now)):
|
|
185
|
+
self.update_cell(a.key, col, value)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Bottom panel: activity feed + notifications (shortcuts live in the Footer)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from rich.text import Text
|
|
6
|
+
from textual.widgets import RichLog
|
|
7
|
+
|
|
8
|
+
from ...models import Activity
|
|
9
|
+
from ...redact import redact
|
|
10
|
+
from ..style import clock
|
|
11
|
+
|
|
12
|
+
ICONS = {"success": "✓", "warning": "▲", "error": "✗", "info": "·"}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ActivityFeed(RichLog):
|
|
16
|
+
def __init__(self, **kw) -> None:
|
|
17
|
+
super().__init__(wrap=False, markup=False, highlight=False, max_lines=500, **kw)
|
|
18
|
+
self.can_focus = False
|
|
19
|
+
|
|
20
|
+
def add(self, item: Activity) -> None:
|
|
21
|
+
styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
|
|
22
|
+
color = styler.level(item.level)
|
|
23
|
+
t = Text()
|
|
24
|
+
t.append(clock(item.ts) + " ", style="dim")
|
|
25
|
+
t.append(ICONS.get(item.level, "·") + " ", style=f"bold {color}")
|
|
26
|
+
t.append(redact(item.message), style=color if item.level != "info" else "")
|
|
27
|
+
self.write(t)
|