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
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"""Right panel: selected agent's task, logs, files, tests and a terminal."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
from rich.console import Group
|
|
10
|
+
from rich.table import Table
|
|
11
|
+
from rich.text import Text
|
|
12
|
+
from textual.app import ComposeResult
|
|
13
|
+
from textual.binding import Binding
|
|
14
|
+
from textual.containers import Vertical, VerticalScroll
|
|
15
|
+
from textual.widgets import RichLog, Static, TabbedContent, TabPane
|
|
16
|
+
|
|
17
|
+
from ...gitinfo import GitSnapshot
|
|
18
|
+
from ...models import Agent, AgentStatus, Task
|
|
19
|
+
from ...redact import redact
|
|
20
|
+
from ...termrender import render as render_terminal
|
|
21
|
+
from ..style import ago, clock, duration, hint_line, section, shorten_path
|
|
22
|
+
from .terminal import TerminalView
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(slots=True)
|
|
26
|
+
class TestRun:
|
|
27
|
+
command: str
|
|
28
|
+
cwd: str
|
|
29
|
+
exit_code: int
|
|
30
|
+
output: str
|
|
31
|
+
started: float
|
|
32
|
+
finished: float
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def passed(self) -> bool:
|
|
36
|
+
return self.exit_code == 0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
TABS = [
|
|
40
|
+
("tab-overview", "◉ Overview"),
|
|
41
|
+
("tab-logs", "≡ Logs"),
|
|
42
|
+
("tab-files", "± Files"),
|
|
43
|
+
("tab-tests", "✓ Tests"),
|
|
44
|
+
("tab-terminal", "❯ Terminal"),
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AgentDetails(Vertical):
|
|
49
|
+
BINDINGS = [
|
|
50
|
+
# from the tab bar, step into the active tab's content
|
|
51
|
+
Binding("down,enter", "enter_pane", "Open", show=False),
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
def __init__(self, **kw) -> None:
|
|
55
|
+
super().__init__(**kw)
|
|
56
|
+
self.agent: Agent | None = None
|
|
57
|
+
self._log_text: str | None = None
|
|
58
|
+
self._tail = 400
|
|
59
|
+
self._log_for: str | None = None
|
|
60
|
+
|
|
61
|
+
def compose(self) -> ComposeResult:
|
|
62
|
+
yield Static("", id="details-title")
|
|
63
|
+
with TabbedContent(id="details-tabs", initial="tab-overview"):
|
|
64
|
+
with TabPane(TABS[0][1], id="tab-overview"):
|
|
65
|
+
with VerticalScroll(id="overview-scroll"):
|
|
66
|
+
yield Static(id="overview")
|
|
67
|
+
with TabPane(TABS[1][1], id="tab-logs"):
|
|
68
|
+
yield RichLog(id="log-view", wrap=True, markup=False, highlight=False,
|
|
69
|
+
max_lines=5000)
|
|
70
|
+
with TabPane(TABS[2][1], id="tab-files"):
|
|
71
|
+
with VerticalScroll(id="files-scroll"):
|
|
72
|
+
yield Static(id="files")
|
|
73
|
+
with TabPane(TABS[3][1], id="tab-tests"):
|
|
74
|
+
with VerticalScroll(id="tests-scroll"):
|
|
75
|
+
yield Static(id="tests")
|
|
76
|
+
with TabPane(TABS[4][1], id="tab-terminal"):
|
|
77
|
+
yield Static(id="term-bar")
|
|
78
|
+
yield TerminalView(id="terminal")
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def active_tab(self) -> str:
|
|
82
|
+
return self.query_one("#details-tabs", TabbedContent).active
|
|
83
|
+
|
|
84
|
+
def show_tab(self, tab: str) -> None:
|
|
85
|
+
self.query_one("#details-tabs", TabbedContent).active = tab
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def terminal(self) -> TerminalView:
|
|
89
|
+
return self.query_one("#terminal", TerminalView)
|
|
90
|
+
|
|
91
|
+
def action_enter_pane(self) -> None:
|
|
92
|
+
target = {
|
|
93
|
+
"tab-overview": "#overview-scroll", "tab-logs": "#log-view",
|
|
94
|
+
"tab-files": "#files-scroll", "tab-tests": "#tests-scroll",
|
|
95
|
+
"tab-terminal": "#terminal",
|
|
96
|
+
}.get(self.active_tab)
|
|
97
|
+
if target:
|
|
98
|
+
self.query_one(target).focus()
|
|
99
|
+
|
|
100
|
+
# ------------------------------------------------------------ render
|
|
101
|
+
def show(self, agent: Agent | None, task: Task | None, git: GitSnapshot | None,
|
|
102
|
+
test: TestRun | None, project_path: str | None = None) -> None:
|
|
103
|
+
self.agent = agent
|
|
104
|
+
styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
|
|
105
|
+
title = self.query_one("#details-title", Static)
|
|
106
|
+
if agent is None:
|
|
107
|
+
title.update(Text.assemble((" No agent selected", "bold"), "\n",
|
|
108
|
+
(" pick one in the list, or start a new one", "dim")))
|
|
109
|
+
self.query_one("#overview", Static).update(Group(
|
|
110
|
+
Text(""),
|
|
111
|
+
Text(" Nothing selected", style="bold"),
|
|
112
|
+
Text(" Agents from every registered project show up in the list.\n",
|
|
113
|
+
style="dim"),
|
|
114
|
+
hint_line(styler, [("n", "new agent"), ("a", "queue task")]),
|
|
115
|
+
hint_line(styler, [("p", "add project"), ("?", "all keys")]),
|
|
116
|
+
))
|
|
117
|
+
self.query_one("#files", Static).update("")
|
|
118
|
+
self.query_one("#tests", Static).update("")
|
|
119
|
+
self._set_logs(None, "")
|
|
120
|
+
return
|
|
121
|
+
headline = Text(" ")
|
|
122
|
+
headline.append_text(styler.badge(agent.status))
|
|
123
|
+
headline.append(" ")
|
|
124
|
+
headline.append(agent.task_title or agent.display_name, style="bold")
|
|
125
|
+
meta = Text(" ", style="dim")
|
|
126
|
+
bits = [agent.display_name if agent.task_title else None, agent.project_name,
|
|
127
|
+
f"⎇ {agent.branch}" if agent.branch else None]
|
|
128
|
+
meta.append(" · ".join(b for b in bits if b) or agent.cwd, style="dim")
|
|
129
|
+
title.update(Text.assemble(headline, "\n", meta))
|
|
130
|
+
self.query_one("#overview", Static).update(self._overview(agent, task))
|
|
131
|
+
self.query_one("#files", Static).update(self._files(git))
|
|
132
|
+
self.query_one("#tests", Static).update(self._tests(test, project_path))
|
|
133
|
+
if self._log_for != agent.key:
|
|
134
|
+
self._set_logs(agent.key, "")
|
|
135
|
+
|
|
136
|
+
def _overview(self, a: Agent, task: Task | None) -> Group:
|
|
137
|
+
styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
|
|
138
|
+
now = time.time()
|
|
139
|
+
parts: list = []
|
|
140
|
+
|
|
141
|
+
# call to action first: what does this agent need from me?
|
|
142
|
+
if a.status is AgentStatus.PERMISSION:
|
|
143
|
+
parts += [Text(f"▲ Permission request: {a.waiting_for or 'approval needed'}",
|
|
144
|
+
style=f"bold {styler.colors[AgentStatus.PERMISSION]}"),
|
|
145
|
+
Text(" Answer it inside Claude Code; the dashboard never approves "
|
|
146
|
+
"for you.", style="dim"),
|
|
147
|
+
hint_line(styler, [("⏎", "attach & answer")]), Text("")]
|
|
148
|
+
elif a.status is AgentStatus.WAITING:
|
|
149
|
+
parts += [Text(f"◐ Waiting: {a.waiting_for or 'input needed'}",
|
|
150
|
+
style=f"bold {styler.colors[AgentStatus.WAITING]}"),
|
|
151
|
+
hint_line(styler, [("⏎", "attach & reply")]), Text("")]
|
|
152
|
+
elif a.status is AgentStatus.FAILED:
|
|
153
|
+
parts += [Text("✗ Session ended with an error",
|
|
154
|
+
style=f"bold {styler.colors[AgentStatus.FAILED]}"),
|
|
155
|
+
hint_line(styler, [("l", "logs"), ("r", "restart")]), Text("")]
|
|
156
|
+
elif a.status in (AgentStatus.COMPLETED, AgentStatus.IDLE) and a.controllable:
|
|
157
|
+
parts += [Text("✓ Finished. Ready for the next instruction",
|
|
158
|
+
style=f"bold {styler.colors[AgentStatus.COMPLETED]}"),
|
|
159
|
+
hint_line(styler, [("m", "follow up"), ("d", "diff")]), Text("")]
|
|
160
|
+
|
|
161
|
+
if task is not None:
|
|
162
|
+
parts.append(section(styler, f"Task #{task.id}"))
|
|
163
|
+
parts.append(Text(task.title, style="bold"))
|
|
164
|
+
parts.append(Text(redact(task.prompt), style=""))
|
|
165
|
+
if task.error:
|
|
166
|
+
parts.append(Text(f"Error: {redact(task.error)}",
|
|
167
|
+
style=styler.colors[AgentStatus.FAILED]))
|
|
168
|
+
parts.append(Text(""))
|
|
169
|
+
elif not a.controllable:
|
|
170
|
+
parts += [Text("Interactive session in another terminal. Switch there to "
|
|
171
|
+
"talk to it.", style="dim"), Text("")]
|
|
172
|
+
|
|
173
|
+
grid = Table.grid(padding=(0, 2))
|
|
174
|
+
grid.add_column(style="dim", no_wrap=True)
|
|
175
|
+
grid.add_column(overflow="ellipsis", no_wrap=True)
|
|
176
|
+
grid.add_row("Status", styler.badge(a.status))
|
|
177
|
+
if a.account:
|
|
178
|
+
grid.add_row("Account", Text.assemble(
|
|
179
|
+
("◆ " if a.provider == "claude" else "◎ ",
|
|
180
|
+
styler.colors[AgentStatus.PERMISSION] if a.provider == "claude"
|
|
181
|
+
else styler.colors[AgentStatus.RUNNING]),
|
|
182
|
+
a.account, (f" {'Claude Code' if a.provider == 'claude' else 'Codex'}",
|
|
183
|
+
"dim")))
|
|
184
|
+
if a.usage: # only Codex reports this; never estimated
|
|
185
|
+
grid.add_row("Tokens", f"{a.usage.get('input_tokens', 0):,} in · "
|
|
186
|
+
f"{a.usage.get('output_tokens', 0):,} out")
|
|
187
|
+
grid.add_row("Started", f"{clock(a.started_at)} · {duration(a.elapsed(now))} ago")
|
|
188
|
+
grid.add_row("Activity", ago(a.last_activity, now))
|
|
189
|
+
grid.add_row("Model", a.model or Text("not reported", style="dim"))
|
|
190
|
+
if a.permission_mode:
|
|
191
|
+
grid.add_row("Mode", a.permission_mode)
|
|
192
|
+
grid.add_row("Kind", a.kind + ("" if a.controllable else " (view only)"))
|
|
193
|
+
if a.id:
|
|
194
|
+
grid.add_row("ID", a.id)
|
|
195
|
+
if a.session_id:
|
|
196
|
+
grid.add_row("Session", Text(a.session_id, style="dim"))
|
|
197
|
+
parts += [section(styler, "Session"), grid, Text("")]
|
|
198
|
+
|
|
199
|
+
where = Table.grid(padding=(0, 2))
|
|
200
|
+
where.add_column(style="dim", no_wrap=True)
|
|
201
|
+
where.add_column(overflow="ellipsis", no_wrap=True)
|
|
202
|
+
where.add_row("Project", a.project_name or Text("unregistered", style="dim"))
|
|
203
|
+
where.add_row("Branch", a.branch or "—")
|
|
204
|
+
where.add_row("Path", shorten_path(a.cwd, 40))
|
|
205
|
+
parts += [section(styler, "Workspace"), where]
|
|
206
|
+
return Group(*parts)
|
|
207
|
+
|
|
208
|
+
def _files(self, git: GitSnapshot | None) -> Group | Text:
|
|
209
|
+
styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
|
|
210
|
+
if git is None:
|
|
211
|
+
return Text("\n Loading git status…", style="dim")
|
|
212
|
+
if not git.is_repo:
|
|
213
|
+
return Group(Text(""), Text(" Not a git repository", style="bold"),
|
|
214
|
+
Text(" Changed files show up here for git projects.", style="dim"))
|
|
215
|
+
if git.error:
|
|
216
|
+
return Text(f"git error: {redact(git.error)}", style="red")
|
|
217
|
+
head = Text()
|
|
218
|
+
head.append(f"⎇ {git.branch or '?'}", style="bold")
|
|
219
|
+
if git.ahead:
|
|
220
|
+
head.append(f" ↑{git.ahead}")
|
|
221
|
+
if git.behind:
|
|
222
|
+
head.append(f" ↓{git.behind}")
|
|
223
|
+
head.append(f" {len(git.changes)} changed ", style="dim")
|
|
224
|
+
head.append(f"+{git.total_added}", style=styler.colors[AgentStatus.RUNNING])
|
|
225
|
+
head.append(" ")
|
|
226
|
+
head.append(f"−{git.total_deleted}", style=styler.colors[AgentStatus.FAILED])
|
|
227
|
+
if not git.changes:
|
|
228
|
+
return Group(head, Text(""), Text("✓ Working tree clean", style="dim"))
|
|
229
|
+
table = Table.grid(padding=(0, 1))
|
|
230
|
+
table.add_column(width=2, style="bold")
|
|
231
|
+
table.add_column(ratio=1, overflow="fold")
|
|
232
|
+
table.add_column(justify="right", style=styler.colors[AgentStatus.RUNNING])
|
|
233
|
+
table.add_column(justify="right", style=styler.colors[AgentStatus.FAILED])
|
|
234
|
+
for ch in git.changes[:200]:
|
|
235
|
+
table.add_row(ch.status.strip() or "M", ch.path,
|
|
236
|
+
f"+{ch.added}" if ch.added else "",
|
|
237
|
+
f"−{ch.deleted}" if ch.deleted else "")
|
|
238
|
+
return Group(head, Text(""), table, Text(""),
|
|
239
|
+
hint_line(styler, [("d", "full diff")], suffix=f"updated {ago(git.taken_at)}"))
|
|
240
|
+
|
|
241
|
+
def _tests(self, test: TestRun | None, project_path: str | None) -> Group | Text:
|
|
242
|
+
styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
|
|
243
|
+
if test is None:
|
|
244
|
+
return Group(
|
|
245
|
+
Text(""),
|
|
246
|
+
Text(" No test run yet", style="bold"),
|
|
247
|
+
Text(" Run the project's test command in this agent's directory.\n",
|
|
248
|
+
style="dim"),
|
|
249
|
+
hint_line(styler, [("x", "run tests")]),
|
|
250
|
+
hint_line(styler, [("2", "Projects"), ("e", "set test command")]),
|
|
251
|
+
)
|
|
252
|
+
color = styler.colors[AgentStatus.RUNNING if test.passed else AgentStatus.FAILED]
|
|
253
|
+
head = Text()
|
|
254
|
+
head.append("✓ passed" if test.passed else f"✗ failed (exit {test.exit_code})",
|
|
255
|
+
style=f"bold {color}")
|
|
256
|
+
head.append(f" {duration(test.finished - test.started)} · {ago(test.finished)}",
|
|
257
|
+
style="dim")
|
|
258
|
+
cmd = Text(f"$ {test.command}", style="dim")
|
|
259
|
+
tail = "\n".join(test.output.splitlines()[-200:])
|
|
260
|
+
return Group(head, cmd, Text(""), Text.from_ansi(redact(tail)), Text(""),
|
|
261
|
+
hint_line(styler, [("x", "run again")]))
|
|
262
|
+
|
|
263
|
+
# ---------------------------------------------------------- terminal
|
|
264
|
+
def set_terminal_bar(self, cwd: str | None, shell: str | None, alive: bool) -> None:
|
|
265
|
+
styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
|
|
266
|
+
bar = Text(" ")
|
|
267
|
+
if cwd is None:
|
|
268
|
+
bar.append("no directory selected", style="dim")
|
|
269
|
+
else:
|
|
270
|
+
dot = styler.colors[AgentStatus.RUNNING if alive else AgentStatus.STOPPED]
|
|
271
|
+
bar.append("● ", style=dot)
|
|
272
|
+
bar.append(shorten_path(cwd, 30), style="bold")
|
|
273
|
+
if shell:
|
|
274
|
+
bar.append(f" {os.path.basename(shell)}", style="dim")
|
|
275
|
+
focused = self.terminal.has_focus
|
|
276
|
+
bar.append(" ctrl+] leave" if focused else " ⏎ type here", style="dim")
|
|
277
|
+
self.query_one("#term-bar", Static).update(bar)
|
|
278
|
+
|
|
279
|
+
# -------------------------------------------------------------- logs
|
|
280
|
+
def _set_logs(self, key: str | None, text: str) -> None:
|
|
281
|
+
log = self.query_one("#log-view", RichLog)
|
|
282
|
+
self._log_for = key
|
|
283
|
+
self._log_text = text
|
|
284
|
+
log.clear()
|
|
285
|
+
if text:
|
|
286
|
+
# raw `claude logs` output is a terminal-screen dump: replay it
|
|
287
|
+
# (render_terminal also redacts every line)
|
|
288
|
+
log.write(render_terminal(text, tail=self._tail))
|
|
289
|
+
|
|
290
|
+
def set_logs(self, key: str, text: str, tail: int = 400) -> None:
|
|
291
|
+
"""Replace log contents if the raw output changed."""
|
|
292
|
+
self._tail = tail
|
|
293
|
+
if key == self._log_for and text == self._log_text:
|
|
294
|
+
return
|
|
295
|
+
self._set_logs(key, text)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Top bar: brand, status chips, backend and clock."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from rich.text import Text
|
|
8
|
+
from textual.reactive import reactive
|
|
9
|
+
from textual.widgets import Static
|
|
10
|
+
|
|
11
|
+
from ...models import AgentStatus
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CenterHeader(Static):
|
|
15
|
+
active = reactive(0)
|
|
16
|
+
attention = reactive(0)
|
|
17
|
+
total_agents = reactive(0)
|
|
18
|
+
projects = reactive(0)
|
|
19
|
+
backend = reactive("")
|
|
20
|
+
paused = reactive(False)
|
|
21
|
+
queued = reactive(0)
|
|
22
|
+
healthy = reactive(True)
|
|
23
|
+
demo = reactive(False)
|
|
24
|
+
account = reactive("") # active account name ("" = single account: no chip)
|
|
25
|
+
account_provider = reactive("claude")
|
|
26
|
+
|
|
27
|
+
def on_mount(self) -> None:
|
|
28
|
+
self.set_interval(1.0, self.refresh)
|
|
29
|
+
|
|
30
|
+
def on_click(self) -> None:
|
|
31
|
+
if self.account:
|
|
32
|
+
self.app.action_switch_account() # type: ignore[attr-defined] # CommandCenterApp
|
|
33
|
+
|
|
34
|
+
def _chip(self, t: Text, value: str, label: str, color: str, bg: str) -> None:
|
|
35
|
+
t.append(" ", style=f"on {bg}")
|
|
36
|
+
t.append(value, style=f"bold {color} on {bg}")
|
|
37
|
+
t.append(f" {label} ", style=f"on {bg}")
|
|
38
|
+
t.append(" ")
|
|
39
|
+
|
|
40
|
+
def render(self) -> Text:
|
|
41
|
+
c = self.app.styler.colors # type: ignore[attr-defined] # CommandCenterApp
|
|
42
|
+
green, yellow = c[AgentStatus.RUNNING], c[AgentStatus.WAITING]
|
|
43
|
+
orange, purple, red = (c[AgentStatus.PERMISSION], c[AgentStatus.PLANNING],
|
|
44
|
+
c[AgentStatus.FAILED])
|
|
45
|
+
dark = getattr(self.app.current_theme, "dark", True)
|
|
46
|
+
chip_bg = "#313244" if dark else "#dce0e8"
|
|
47
|
+
fg = "#cdd6f4" if dark else "#4c4f69"
|
|
48
|
+
|
|
49
|
+
t = Text(no_wrap=True, overflow="ellipsis")
|
|
50
|
+
t.append(" ◆ ", style=f"bold {purple}")
|
|
51
|
+
t.append("FleetDeck ", style=f"bold {fg}")
|
|
52
|
+
if self.demo:
|
|
53
|
+
t.append(" DEMO ", style=f"bold #1e1e2e on {yellow}")
|
|
54
|
+
t.append(" ")
|
|
55
|
+
if self.account: # click (or Ctrl+A) to switch
|
|
56
|
+
icon, color = (("◆", orange) if self.account_provider == "claude"
|
|
57
|
+
else ("◎", green))
|
|
58
|
+
t.append(f" {icon} ", style=f"bold {color} on {chip_bg}")
|
|
59
|
+
t.append(f"{self.account} ▾ ", style=f"bold on {chip_bg}")
|
|
60
|
+
t.append(" ")
|
|
61
|
+
t.append(" ")
|
|
62
|
+
self._chip(t, f"● {self.active}", "active", green, chip_bg)
|
|
63
|
+
if self.attention:
|
|
64
|
+
self._chip(t, f"▲ {self.attention}", "need you", orange, chip_bg)
|
|
65
|
+
self._chip(t, str(self.total_agents), "sessions", fg, chip_bg)
|
|
66
|
+
self._chip(t, str(self.projects), "projects", fg, chip_bg)
|
|
67
|
+
if self.queued:
|
|
68
|
+
self._chip(t, str(self.queued), "queued", fg, chip_bg)
|
|
69
|
+
self._chip(t, "⏸ paused" if self.paused else "▶ dispatch",
|
|
70
|
+
"" if self.paused else "on", yellow if self.paused else green, chip_bg)
|
|
71
|
+
|
|
72
|
+
right = Text()
|
|
73
|
+
if not self.healthy:
|
|
74
|
+
right.append(" CLI unreachable ", style=f"bold #1e1e2e on {red}")
|
|
75
|
+
right.append(" ")
|
|
76
|
+
if self.backend:
|
|
77
|
+
right.append(self.backend, style="dim")
|
|
78
|
+
right.append(" ")
|
|
79
|
+
right.append(time.strftime("%a %d %b "), style="dim")
|
|
80
|
+
right.append(time.strftime("%H:%M:%S"), style=f"bold {fg}")
|
|
81
|
+
right.append(" ")
|
|
82
|
+
width = self.size.width or 120
|
|
83
|
+
pad = width - t.cell_len - right.cell_len
|
|
84
|
+
if pad > 0:
|
|
85
|
+
t.append(" " * pad)
|
|
86
|
+
t.append_text(right)
|
|
87
|
+
return t
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"""Left sidebar: searchable, grouped project tree with live agent counts."""
|
|
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.containers import Vertical
|
|
10
|
+
from textual.message import Message
|
|
11
|
+
from textual.widgets import Input, Tree
|
|
12
|
+
|
|
13
|
+
from ...models import Agent, AgentStatus, Project
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True, slots=True)
|
|
17
|
+
class Scope:
|
|
18
|
+
"""What the dashboard is filtered to."""
|
|
19
|
+
|
|
20
|
+
kind: str # all | pinned | office | personal | unassigned | project | account
|
|
21
|
+
project_id: int | None = None
|
|
22
|
+
account: str | None = None
|
|
23
|
+
|
|
24
|
+
def matches(self, agent: Agent, projects: dict[int, Project]) -> bool:
|
|
25
|
+
if self.kind in ("all", "accounts"):
|
|
26
|
+
return True
|
|
27
|
+
if self.kind == "account":
|
|
28
|
+
return agent.account == self.account
|
|
29
|
+
if self.kind == "unassigned":
|
|
30
|
+
return agent.project_id is None
|
|
31
|
+
if agent.project_id is None:
|
|
32
|
+
return False
|
|
33
|
+
if self.kind == "project":
|
|
34
|
+
return agent.project_id == self.project_id
|
|
35
|
+
proj = projects.get(agent.project_id)
|
|
36
|
+
if proj is None:
|
|
37
|
+
return False
|
|
38
|
+
if self.kind == "pinned":
|
|
39
|
+
return proj.pinned
|
|
40
|
+
return proj.group == self.kind
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
ALL = Scope("all")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ProjectSidebar(Vertical):
|
|
47
|
+
class ScopeChanged(Message):
|
|
48
|
+
def __init__(self, scope: Scope) -> None:
|
|
49
|
+
self.scope = scope
|
|
50
|
+
super().__init__()
|
|
51
|
+
|
|
52
|
+
def __init__(self, **kw) -> None:
|
|
53
|
+
super().__init__(**kw)
|
|
54
|
+
self.scope: Scope = ALL
|
|
55
|
+
self._signature: tuple | None = None
|
|
56
|
+
self._projects: list[Project] = []
|
|
57
|
+
self._agents: list[Agent] = []
|
|
58
|
+
self._accounts: list[tuple[str, str, str]] = []
|
|
59
|
+
self._collapsed: set[str] = set()
|
|
60
|
+
|
|
61
|
+
def compose(self) -> ComposeResult:
|
|
62
|
+
yield Input(placeholder="Search projects…", id="project-search")
|
|
63
|
+
tree: Tree[Scope] = Tree("Projects", id="project-tree")
|
|
64
|
+
tree.show_root = False
|
|
65
|
+
tree.guide_depth = 2
|
|
66
|
+
yield tree
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def tree(self) -> Tree[Scope]:
|
|
70
|
+
return self.query_one("#project-tree", Tree)
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def search_input(self) -> Input:
|
|
74
|
+
return self.query_one("#project-search", Input)
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def selected_project_id(self) -> int | None:
|
|
78
|
+
node = self.tree.cursor_node
|
|
79
|
+
if node is not None and node.data is not None and node.data.kind == "project":
|
|
80
|
+
return node.data.project_id
|
|
81
|
+
return self.scope.project_id if self.scope.kind == "project" else None
|
|
82
|
+
|
|
83
|
+
# ------------------------------------------------------------ update
|
|
84
|
+
def update_data(self, projects: list[Project], agents: list[Agent],
|
|
85
|
+
accounts: list[tuple[str, str, str]] | None = None) -> None:
|
|
86
|
+
"""``accounts``: (name, icon, provider) — shown as a group when > 1."""
|
|
87
|
+
self._projects, self._agents = projects, agents
|
|
88
|
+
self._accounts = accounts or []
|
|
89
|
+
self._rebuild()
|
|
90
|
+
|
|
91
|
+
def select_scope(self, scope: Scope) -> None:
|
|
92
|
+
"""Programmatic selection (command palette): move the cursor there too."""
|
|
93
|
+
self.scope = scope
|
|
94
|
+
self._rebuild(force=True, prefer_scope=True)
|
|
95
|
+
|
|
96
|
+
def _rebuild(self, force: bool = False, prefer_scope: bool = False) -> None:
|
|
97
|
+
q = self.search_input.value.strip().lower() if self.is_mounted else ""
|
|
98
|
+
projects = [p for p in self._projects
|
|
99
|
+
if not q or q in p.name.lower() or q in p.path.lower()]
|
|
100
|
+
active: dict[int | None, int] = {}
|
|
101
|
+
attention: dict[int | None, int] = {}
|
|
102
|
+
for a in self._agents:
|
|
103
|
+
if a.status.is_active:
|
|
104
|
+
active[a.project_id] = active.get(a.project_id, 0) + 1
|
|
105
|
+
if a.status in (AgentStatus.PERMISSION, AgentStatus.WAITING):
|
|
106
|
+
attention[a.project_id] = attention.get(a.project_id, 0) + 1
|
|
107
|
+
unassigned = sum(1 for a in self._agents if a.project_id is None)
|
|
108
|
+
acc_active: dict[str | None, int] = {}
|
|
109
|
+
acc_att: dict[str | None, int] = {}
|
|
110
|
+
acc_total: dict[str | None, int] = {}
|
|
111
|
+
for a in self._agents:
|
|
112
|
+
acc_total[a.account] = acc_total.get(a.account, 0) + 1
|
|
113
|
+
if a.status.is_active:
|
|
114
|
+
acc_active[a.account] = acc_active.get(a.account, 0) + 1
|
|
115
|
+
if a.status in (AgentStatus.PERMISSION, AgentStatus.WAITING):
|
|
116
|
+
acc_att[a.account] = acc_att.get(a.account, 0) + 1
|
|
117
|
+
sig = (
|
|
118
|
+
tuple(self._accounts),
|
|
119
|
+
tuple(sorted((str(k), v) for k, v in acc_active.items())),
|
|
120
|
+
tuple(sorted((str(k), v) for k, v in acc_att.items())),
|
|
121
|
+
tuple(sorted((str(k), v) for k, v in acc_total.items())),
|
|
122
|
+
q,
|
|
123
|
+
tuple((p.id, p.name, p.group, p.pinned) for p in projects),
|
|
124
|
+
tuple(sorted(active.items(), key=lambda kv: str(kv[0]))),
|
|
125
|
+
tuple(sorted(attention.items(), key=lambda kv: str(kv[0]))),
|
|
126
|
+
unassigned,
|
|
127
|
+
self.app.theme,
|
|
128
|
+
)
|
|
129
|
+
if sig == self._signature and not force:
|
|
130
|
+
return
|
|
131
|
+
self._signature = sig
|
|
132
|
+
colors = self.app.styler.colors # type: ignore[attr-defined] # CommandCenterApp
|
|
133
|
+
|
|
134
|
+
def label(name: str, pid: int | None = None, count: int | None = None,
|
|
135
|
+
att: int = 0, bold: bool = False) -> Text:
|
|
136
|
+
t = Text(name, style="bold" if bold else "")
|
|
137
|
+
if count:
|
|
138
|
+
t.append(f" ●{count}", style=colors[AgentStatus.RUNNING])
|
|
139
|
+
if att:
|
|
140
|
+
t.append(f" ▲{att}", style=colors[AgentStatus.PERMISSION])
|
|
141
|
+
return t
|
|
142
|
+
|
|
143
|
+
tree = self.tree
|
|
144
|
+
for node in tree.root.children: # remember what the user collapsed
|
|
145
|
+
if isinstance(node.data, Scope) and node.allow_expand:
|
|
146
|
+
(self._collapsed.discard if node.is_expanded else self._collapsed.add)(
|
|
147
|
+
node.data.kind)
|
|
148
|
+
if prefer_scope or tree.cursor_node is None:
|
|
149
|
+
keep = self.scope
|
|
150
|
+
else:
|
|
151
|
+
keep = tree.cursor_node.data
|
|
152
|
+
tree.clear()
|
|
153
|
+
total_active = sum(v for k, v in active.items())
|
|
154
|
+
total_att = sum(attention.values())
|
|
155
|
+
cursor_target = None
|
|
156
|
+
|
|
157
|
+
def add_leaf(parent, p: Project):
|
|
158
|
+
nonlocal cursor_target
|
|
159
|
+
node = parent.add_leaf(
|
|
160
|
+
label(p.name, p.id, active.get(p.id), attention.get(p.id, 0)),
|
|
161
|
+
data=Scope("project", p.id),
|
|
162
|
+
)
|
|
163
|
+
if keep == node.data and cursor_target is None:
|
|
164
|
+
cursor_target = node
|
|
165
|
+
|
|
166
|
+
root = tree.root
|
|
167
|
+
all_node = root.add_leaf(label(f"All projects ({len(projects)})", None, total_active,
|
|
168
|
+
total_att, True), data=ALL)
|
|
169
|
+
if keep == ALL:
|
|
170
|
+
cursor_target = all_node
|
|
171
|
+
sections = [
|
|
172
|
+
("★ Pinned", "pinned", [p for p in projects if p.pinned]),
|
|
173
|
+
("Office", "office", [p for p in projects if p.group == "office"]),
|
|
174
|
+
("Personal", "personal", [p for p in projects if p.group == "personal"]),
|
|
175
|
+
]
|
|
176
|
+
for title, kind, items in sections:
|
|
177
|
+
cnt = sum(active.get(p.id, 0) for p in items)
|
|
178
|
+
att = sum(attention.get(p.id, 0) for p in items)
|
|
179
|
+
node = root.add(label(f"{title} ({len(items)})", None, cnt, att, True),
|
|
180
|
+
data=Scope(kind), expand=kind not in self._collapsed)
|
|
181
|
+
if keep == node.data:
|
|
182
|
+
cursor_target = node
|
|
183
|
+
for p in items:
|
|
184
|
+
add_leaf(node, p)
|
|
185
|
+
if len(self._accounts) > 1:
|
|
186
|
+
node = root.add(label(f"Accounts ({len(self._accounts)})", None,
|
|
187
|
+
sum(acc_active.values()), sum(acc_att.values()), True),
|
|
188
|
+
data=Scope("accounts"), expand="accounts" not in self._collapsed)
|
|
189
|
+
if keep == node.data:
|
|
190
|
+
cursor_target = node
|
|
191
|
+
for name, icon, provider in self._accounts:
|
|
192
|
+
color = (colors[AgentStatus.PERMISSION] if provider == "claude"
|
|
193
|
+
else colors[AgentStatus.RUNNING])
|
|
194
|
+
t = Text()
|
|
195
|
+
t.append(f"{icon} ", style=color)
|
|
196
|
+
t.append(name)
|
|
197
|
+
t.append(f" {acc_total.get(name, 0)}", style="dim")
|
|
198
|
+
if acc_active.get(name):
|
|
199
|
+
t.append(f" ●{acc_active[name]}", style=colors[AgentStatus.RUNNING])
|
|
200
|
+
if acc_att.get(name):
|
|
201
|
+
t.append(f" ▲{acc_att[name]}", style=colors[AgentStatus.PERMISSION])
|
|
202
|
+
leaf = node.add_leaf(t, data=Scope("account", account=name))
|
|
203
|
+
if keep == leaf.data and cursor_target is None:
|
|
204
|
+
cursor_target = leaf
|
|
205
|
+
if unassigned:
|
|
206
|
+
node = root.add_leaf(label(f"Unregistered dirs ({unassigned})", None,
|
|
207
|
+
active.get(None), attention.get(None, 0), True),
|
|
208
|
+
data=Scope("unassigned"))
|
|
209
|
+
if keep == node.data:
|
|
210
|
+
cursor_target = node
|
|
211
|
+
if cursor_target is not None:
|
|
212
|
+
self.call_after_refresh(tree.move_cursor, cursor_target)
|
|
213
|
+
|
|
214
|
+
# ------------------------------------------------------------ events
|
|
215
|
+
def on_input_changed(self, event: Input.Changed) -> None:
|
|
216
|
+
if event.input.id == "project-search":
|
|
217
|
+
self._rebuild(force=True)
|
|
218
|
+
|
|
219
|
+
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
220
|
+
if event.input.id == "project-search":
|
|
221
|
+
self.tree.focus()
|
|
222
|
+
|
|
223
|
+
def on_tree_node_highlighted(self, event: Tree.NodeHighlighted) -> None:
|
|
224
|
+
data = event.node.data
|
|
225
|
+
if isinstance(data, Scope) and data != self.scope:
|
|
226
|
+
self.scope = data
|
|
227
|
+
self.post_message(self.ScopeChanged(data))
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Draggable vertical divider between dashboard panels."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from rich.text import Text
|
|
6
|
+
from textual import events
|
|
7
|
+
from textual.message import Message
|
|
8
|
+
from textual.widget import Widget
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Splitter(Widget):
|
|
12
|
+
"""A 1-column handle. Drag it with the mouse to resize the neighbouring
|
|
13
|
+
panel; the app decides which panel and enforces limits."""
|
|
14
|
+
|
|
15
|
+
# The screen starts a text selection on mouse-down before widgets see it;
|
|
16
|
+
# a drag on the divider must never select the panels' text.
|
|
17
|
+
ALLOW_SELECT = False
|
|
18
|
+
|
|
19
|
+
DEFAULT_CSS = """
|
|
20
|
+
Splitter {
|
|
21
|
+
width: 1;
|
|
22
|
+
height: 1fr;
|
|
23
|
+
color: $panel-lighten-2;
|
|
24
|
+
}
|
|
25
|
+
Splitter:hover, Splitter.-dragging {
|
|
26
|
+
color: $primary;
|
|
27
|
+
background: $primary 25%;
|
|
28
|
+
}
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
class Dragged(Message):
|
|
32
|
+
def __init__(self, splitter: "Splitter", screen_x: int, done: bool) -> None:
|
|
33
|
+
self.splitter = splitter
|
|
34
|
+
self.screen_x = screen_x
|
|
35
|
+
self.done = done
|
|
36
|
+
super().__init__()
|
|
37
|
+
|
|
38
|
+
def __init__(self, **kw) -> None:
|
|
39
|
+
super().__init__(**kw)
|
|
40
|
+
self._dragging = False
|
|
41
|
+
|
|
42
|
+
def render(self) -> Text:
|
|
43
|
+
mid = max(0, self.size.height // 2 - 1)
|
|
44
|
+
rows = ["│"] * max(1, self.size.height)
|
|
45
|
+
for i in range(mid, min(mid + 3, len(rows))):
|
|
46
|
+
rows[i] = "┃" # grip
|
|
47
|
+
return Text("\n".join(rows))
|
|
48
|
+
|
|
49
|
+
def on_mouse_down(self, event: events.MouseDown) -> None:
|
|
50
|
+
self._dragging = True
|
|
51
|
+
self.add_class("-dragging")
|
|
52
|
+
self.capture_mouse()
|
|
53
|
+
event.stop()
|
|
54
|
+
|
|
55
|
+
def on_mouse_move(self, event: events.MouseMove) -> None:
|
|
56
|
+
if self._dragging:
|
|
57
|
+
self.post_message(self.Dragged(self, event.screen_x, done=False))
|
|
58
|
+
event.stop()
|
|
59
|
+
|
|
60
|
+
def on_mouse_up(self, event: events.MouseUp) -> None:
|
|
61
|
+
if self._dragging:
|
|
62
|
+
self._dragging = False
|
|
63
|
+
self.remove_class("-dragging")
|
|
64
|
+
self.release_mouse()
|
|
65
|
+
self.post_message(self.Dragged(self, event.screen_x, done=True))
|
|
66
|
+
event.stop()
|