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.
Files changed (44) hide show
  1. fleetdeck/__init__.py +3 -0
  2. fleetdeck/__main__.py +232 -0
  3. fleetdeck/accounts.py +115 -0
  4. fleetdeck/adapters/__init__.py +0 -0
  5. fleetdeck/adapters/base.py +71 -0
  6. fleetdeck/adapters/claude_cli.py +187 -0
  7. fleetdeck/adapters/codex_cli.py +362 -0
  8. fleetdeck/adapters/demo.py +331 -0
  9. fleetdeck/config.py +323 -0
  10. fleetdeck/db.py +511 -0
  11. fleetdeck/gitinfo.py +169 -0
  12. fleetdeck/models.py +178 -0
  13. fleetdeck/paths.py +64 -0
  14. fleetdeck/proc.py +92 -0
  15. fleetdeck/redact.py +51 -0
  16. fleetdeck/services/__init__.py +0 -0
  17. fleetdeck/services/dispatcher.py +382 -0
  18. fleetdeck/services/fleet.py +65 -0
  19. fleetdeck/services/monitor.py +253 -0
  20. fleetdeck/services/notifier.py +71 -0
  21. fleetdeck/status.py +97 -0
  22. fleetdeck/terminal.py +235 -0
  23. fleetdeck/termrender.py +129 -0
  24. fleetdeck/ui/__init__.py +0 -0
  25. fleetdeck/ui/app.py +1295 -0
  26. fleetdeck/ui/app.tcss +263 -0
  27. fleetdeck/ui/commands.py +63 -0
  28. fleetdeck/ui/screens/__init__.py +0 -0
  29. fleetdeck/ui/screens/modals.py +623 -0
  30. fleetdeck/ui/style.py +150 -0
  31. fleetdeck/ui/views.py +230 -0
  32. fleetdeck/ui/widgets/__init__.py +0 -0
  33. fleetdeck/ui/widgets/agent_table.py +185 -0
  34. fleetdeck/ui/widgets/bottom.py +27 -0
  35. fleetdeck/ui/widgets/details.py +295 -0
  36. fleetdeck/ui/widgets/header.py +87 -0
  37. fleetdeck/ui/widgets/sidebar.py +227 -0
  38. fleetdeck/ui/widgets/splitter.py +66 -0
  39. fleetdeck/ui/widgets/terminal.py +119 -0
  40. fleetdeck-0.3.0.dist-info/METADATA +245 -0
  41. fleetdeck-0.3.0.dist-info/RECORD +44 -0
  42. fleetdeck-0.3.0.dist-info/WHEEL +4 -0
  43. fleetdeck-0.3.0.dist-info/entry_points.txt +2 -0
  44. fleetdeck-0.3.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,623 @@
1
+ """Modal dialogs. Each returns its result via ``dismiss``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from dataclasses import dataclass
7
+ from typing import Awaitable, Callable
8
+
9
+ from rich.syntax import Syntax
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 Horizontal, Vertical, VerticalScroll
15
+ from textual.screen import ModalScreen
16
+ from textual.widgets import (
17
+ Button, Checkbox, Input, Label, ListItem, ListView, RichLog, Select, Static, TextArea,
18
+ )
19
+
20
+ from ...config import DEFAULT_KEYBINDINGS
21
+ from ...models import PROJECT_GROUPS, SAFE_PERMISSION_MODES, Project, Template
22
+ from ..style import PRIORITY_LABELS
23
+
24
+
25
+ # ---------------------------------------------------------------- confirm
26
+ class ConfirmModal(ModalScreen[bool]):
27
+ BINDINGS = [Binding("escape", "dismiss(False)", "Cancel"),
28
+ Binding("y", "dismiss(True)", "Yes", show=False)]
29
+
30
+ def __init__(self, title: str, body: str, confirm: str = "Confirm",
31
+ danger: bool = True) -> None:
32
+ super().__init__()
33
+ self._title, self._body, self._confirm, self._danger = title, body, confirm, danger
34
+
35
+ def compose(self) -> ComposeResult:
36
+ with Vertical(classes="dialog small"):
37
+ yield Label(self._title, classes="dialog-title")
38
+ yield Static(self._body, classes="dialog-body")
39
+ with Horizontal(classes="dialog-buttons"):
40
+ yield Button("Cancel", id="no")
41
+ yield Button(f"{self._confirm} (y)", id="yes",
42
+ variant="error" if self._danger else "primary")
43
+
44
+ def on_mount(self) -> None:
45
+ self.query_one("#no", Button).focus()
46
+
47
+ def on_button_pressed(self, event: Button.Pressed) -> None:
48
+ self.dismiss(event.button.id == "yes")
49
+
50
+
51
+ # ------------------------------------------------------------- agent form
52
+ @dataclass(slots=True)
53
+ class AgentRequest:
54
+ project_id: int
55
+ title: str
56
+ prompt: str
57
+ priority: int
58
+ model: str | None
59
+ permission_mode: str
60
+ use_worktree: bool
61
+ queue_only: bool
62
+ depends_on: int | None = None
63
+ account: str | None = None
64
+
65
+
66
+ class AgentForm(ModalScreen[AgentRequest | None]):
67
+ """New agent (launch now) or new task (queue) — same fields."""
68
+
69
+ BINDINGS = [Binding("escape", "dismiss(None)", "Cancel"),
70
+ Binding("ctrl+s", "submit", "Submit")]
71
+
72
+ def __init__(self, projects: list[Project], *, project_id: int | None,
73
+ templates: list[Template], queue_only: bool, default_model: str | None,
74
+ default_mode: str, open_tasks: list[tuple[str, int]] | None = None,
75
+ accounts: list[tuple[str, str, str]] | None = None,
76
+ account: str | None = None) -> None:
77
+ super().__init__()
78
+ self.open_tasks = open_tasks or []
79
+ self.accounts = accounts or [] # (name, icon, provider)
80
+ self.account = account
81
+ self.projects = projects
82
+ self.project_id = project_id
83
+ self.templates = templates
84
+ self.queue_only = queue_only
85
+ self.default_model = default_model
86
+ self.default_mode = default_mode
87
+
88
+ def compose(self) -> ComposeResult:
89
+ title = "Queue task" if self.queue_only else "New agent"
90
+ with Vertical(classes="dialog"):
91
+ yield Label(title, classes="dialog-title")
92
+ yield Label("Project", classes="field-label")
93
+ with Horizontal(classes="row"):
94
+ with Vertical():
95
+ yield Select([(f"{p.name} ({p.group})", p.id) for p in self.projects],
96
+ value=self.project_id if self.project_id is not None
97
+ else (self.projects[0].id if self.projects else Select.NULL),
98
+ allow_blank=False, id="project")
99
+ if len(self.accounts) > 1:
100
+ with Vertical(classes="narrow"):
101
+ yield Select([(f"{icon} {name}", name) for name, icon, _ in self.accounts],
102
+ value=self.account or self.accounts[0][0],
103
+ allow_blank=False, id="account")
104
+ with Horizontal(classes="row"):
105
+ with Vertical():
106
+ yield Label("Title", classes="field-label")
107
+ yield Input(placeholder="Short title (optional)", id="title")
108
+ with Vertical(classes="narrow"):
109
+ yield Label("Template", classes="field-label")
110
+ yield Select([(t.name, t.id) for t in self.templates],
111
+ prompt="none", id="template")
112
+ yield Label("Prompt", classes="field-label")
113
+ yield TextArea(id="prompt", soft_wrap=True, show_line_numbers=False)
114
+ with Horizontal(classes="row"):
115
+ with Vertical():
116
+ yield Label("Model (optional)", classes="field-label")
117
+ yield Input(value=self.default_model or "",
118
+ placeholder=self._model_hint(self.account), id="model")
119
+ with Vertical():
120
+ yield Label("Permission mode", classes="field-label")
121
+ yield Select([(m, m) for m in SAFE_PERMISSION_MODES],
122
+ value=self.default_mode, allow_blank=False, id="mode")
123
+ yield Static("", id="mode-hint", classes="hint")
124
+ with Vertical():
125
+ yield Label("Priority", classes="field-label")
126
+ yield Select([(v, k) for k, v in PRIORITY_LABELS.items()],
127
+ value=1 if not self.queue_only else 3,
128
+ allow_blank=False, id="priority")
129
+ yield Label("Run after (optional): starts only when that task completes; "
130
+ "cancelled if it fails", classes="field-label")
131
+ yield Select(self.open_tasks, prompt="no prerequisite", id="after",
132
+ disabled=not self.open_tasks)
133
+ with Horizontal(classes="row"):
134
+ yield Checkbox("Isolate in git worktree", id="worktree")
135
+ yield Checkbox("Queue instead of launching now", value=self.queue_only,
136
+ id="queue")
137
+ yield Static("", id="form-error", classes="error-text")
138
+ with Horizontal(classes="dialog-buttons"):
139
+ yield Button("Cancel", id="cancel")
140
+ yield Button("Queue" if self.queue_only else "Launch ⌃S", id="submit",
141
+ variant="primary")
142
+
143
+ def on_mount(self) -> None:
144
+ self.query_one("#prompt", TextArea).focus()
145
+
146
+ def _provider(self, account: str | None) -> str:
147
+ return next((p for n, _, p in self.accounts if n == account), "claude")
148
+
149
+ def _model_hint(self, account: str | None) -> str:
150
+ return ("e.g. gpt-5 (Codex)" if self._provider(account) == "codex"
151
+ else "e.g. opus, sonnet")
152
+
153
+ def on_select_changed(self, event: Select.Changed) -> None:
154
+ if event.select.id == "account" and event.value is not Select.NULL:
155
+ codex = self._provider(str(event.value)) == "codex"
156
+ self.query_one("#model", Input).placeholder = self._model_hint(str(event.value))
157
+ worktree = self.query_one("#worktree", Checkbox)
158
+ worktree.disabled = codex # Codex has no worktree flag
159
+ if codex:
160
+ worktree.value = False
161
+ self.query_one("#mode-hint", Static).update(
162
+ "Codex: plan = read-only sandbox, otherwise workspace-write" if codex else "")
163
+ return
164
+ if event.select.id == "template" and event.value is not Select.NULL:
165
+ tpl = next((t for t in self.templates if t.id == event.value), None)
166
+ if tpl:
167
+ self.query_one("#prompt", TextArea).text = tpl.body
168
+ title = self.query_one("#title", Input)
169
+ if not title.value:
170
+ title.value = tpl.name
171
+
172
+ def on_checkbox_changed(self, event: Checkbox.Changed) -> None:
173
+ if event.checkbox.id == "queue":
174
+ self.query_one("#submit", Button).label = "Queue" if event.value else "Launch ⌃S"
175
+
176
+ def on_button_pressed(self, event: Button.Pressed) -> None:
177
+ if event.button.id == "submit":
178
+ self.action_submit()
179
+ else:
180
+ self.dismiss(None)
181
+
182
+ def action_submit(self) -> None:
183
+ prompt = self.query_one("#prompt", TextArea).text.strip()
184
+ project = self.query_one("#project", Select).value
185
+ err = self.query_one("#form-error", Static)
186
+ if project is Select.NULL:
187
+ err.update("Add a project first (p).")
188
+ return
189
+ if not prompt:
190
+ err.update("Prompt is required.")
191
+ return
192
+ if "{" in prompt and "}" in prompt and any(
193
+ f"{{{w}}}" in prompt for w in ("area", "file", "feature")):
194
+ err.update("Fill in the template placeholders ({…}) first.")
195
+ return
196
+ self.dismiss(AgentRequest(
197
+ project_id=int(project), # type: ignore[arg-type] # Select value is the project id
198
+ title=self.query_one("#title", Input).value.strip() or prompt.splitlines()[0][:60],
199
+ prompt=prompt,
200
+ priority=int(self.query_one("#priority", Select).value), # type: ignore[arg-type]
201
+ model=self.query_one("#model", Input).value.strip() or None,
202
+ permission_mode=str(self.query_one("#mode", Select).value),
203
+ use_worktree=self.query_one("#worktree", Checkbox).value,
204
+ queue_only=self.query_one("#queue", Checkbox).value,
205
+ depends_on=(None if self.query_one("#after", Select).value is Select.NULL
206
+ else int(self.query_one("#after", Select).value)), # type: ignore[arg-type] # task id
207
+ account=(str(self.query_one("#account", Select).value)
208
+ if self.query("#account") else None),
209
+ ))
210
+
211
+
212
+ class FollowUpForm(ModalScreen[str | None]):
213
+ """Send a new instruction to a finished session (`claude --bg --resume`)."""
214
+
215
+ BINDINGS = [Binding("escape", "dismiss(None)", "Cancel"),
216
+ Binding("ctrl+s", "submit", "Send")]
217
+
218
+ def __init__(self, agent_name: str, project_name: str, last_task: str | None,
219
+ will_stop: bool) -> None:
220
+ super().__init__()
221
+ self.agent_name, self.project_name = agent_name, project_name
222
+ self.last_task, self.will_stop = last_task, will_stop
223
+
224
+ def compose(self) -> ComposeResult:
225
+ with Vertical(classes="dialog"):
226
+ yield Label(f"Follow up · {self.agent_name}", classes="dialog-title")
227
+ info = f"Project: {self.project_name}"
228
+ if self.last_task:
229
+ info += f"\nLast task: {self.last_task}"
230
+ info += "\nThe session continues its conversation in the background."
231
+ if self.will_stop:
232
+ info += ("\nIts finished process is stopped first so it resumes in place "
233
+ "instead of forking a copy; the conversation is kept.")
234
+ yield Static(Text(info, style="dim"))
235
+ yield Label("Prompt", classes="field-label")
236
+ yield TextArea(id="prompt", soft_wrap=True, show_line_numbers=False)
237
+ yield Static("", id="form-error", classes="error-text")
238
+ with Horizontal(classes="dialog-buttons"):
239
+ yield Button("Cancel", id="cancel")
240
+ yield Button("Send ⌃S", id="submit", variant="primary")
241
+
242
+ def on_mount(self) -> None:
243
+ self.query_one("#prompt", TextArea).focus()
244
+
245
+ def on_button_pressed(self, event: Button.Pressed) -> None:
246
+ if event.button.id == "submit":
247
+ self.action_submit()
248
+ else:
249
+ self.dismiss(None)
250
+
251
+ def action_submit(self) -> None:
252
+ prompt = self.query_one("#prompt", TextArea).text.strip()
253
+ if not prompt:
254
+ self.query_one("#form-error", Static).update("Prompt is required.")
255
+ return
256
+ self.dismiss(prompt)
257
+
258
+
259
+ # ----------------------------------------------------------- project form
260
+ @dataclass(slots=True)
261
+ class ProjectRequest:
262
+ name: str
263
+ path: str
264
+ group: str
265
+ environment: str
266
+ always_worktree: bool
267
+ test_command: str
268
+ instructions: str
269
+ account: str | None = None
270
+
271
+
272
+ class ProjectForm(ModalScreen[ProjectRequest | None]):
273
+ BINDINGS = [Binding("escape", "dismiss(None)", "Cancel"),
274
+ Binding("ctrl+s", "submit", "Save")]
275
+
276
+ def __init__(self, environments: list[str], project: Project | None = None, *,
277
+ accounts: list[tuple[str, str, str]] | None = None,
278
+ existing_paths: set[str] | None = None) -> None:
279
+ super().__init__()
280
+ self.project = project
281
+ self.environments = environments
282
+ self.existing = existing_paths or set()
283
+ self.accounts = accounts or []
284
+
285
+ def compose(self) -> ComposeResult:
286
+ p = self.project
287
+ with Vertical(classes="dialog"):
288
+ yield Label("Edit project" if p else "Add project", classes="dialog-title")
289
+ yield Label("Directory", classes="field-label")
290
+ yield Input(value=p.path if p else os.getcwd(), id="path", disabled=p is not None)
291
+ with Horizontal(classes="row"):
292
+ with Vertical():
293
+ yield Label("Name", classes="field-label")
294
+ yield Input(value=p.name if p else "", placeholder="defaults to folder name",
295
+ id="name")
296
+ with Vertical(classes="narrow"):
297
+ yield Label("Group", classes="field-label")
298
+ yield Select([(g.capitalize(), g) for g in PROJECT_GROUPS],
299
+ value=p.group if p else "personal", allow_blank=False,
300
+ id="group")
301
+ with Vertical(classes="narrow"):
302
+ yield Label("Environment", classes="field-label")
303
+ yield Select([(e, e) for e in self.environments],
304
+ value=(p.environment if p and p.environment in self.environments
305
+ else self.environments[0]),
306
+ allow_blank=False, id="environment")
307
+ if len(self.accounts) > 1:
308
+ yield Label("Default account for agents launched here", classes="field-label")
309
+ yield Select([(f"{icon} {name}", name) for name, icon, _ in self.accounts],
310
+ value=(p.account if p and p.account in
311
+ {a[0] for a in self.accounts} else Select.NULL),
312
+ prompt="active account", id="account")
313
+ yield Label("Test command (run with x, in the agent's directory)",
314
+ classes="field-label")
315
+ yield Input(value=p.test_command if p else "", placeholder="e.g. npm test",
316
+ id="test")
317
+ yield Label("Project instructions (appended to the system prompt of agents "
318
+ "launched here)", classes="field-label")
319
+ yield TextArea(p.instructions if p else "", id="instructions", soft_wrap=True)
320
+ yield Checkbox("Always isolate agents in a git worktree",
321
+ value=p.always_worktree if p else False, id="worktree")
322
+ yield Static("", id="form-error", classes="error-text")
323
+ with Horizontal(classes="dialog-buttons"):
324
+ yield Button("Cancel", id="cancel")
325
+ yield Button("Save ⌃S", id="submit", variant="primary")
326
+
327
+ def on_mount(self) -> None:
328
+ self.query_one("#name" if self.project else "#path", Input).focus()
329
+
330
+ def on_button_pressed(self, event: Button.Pressed) -> None:
331
+ if event.button.id == "submit":
332
+ self.action_submit()
333
+ else:
334
+ self.dismiss(None)
335
+
336
+ def action_submit(self) -> None:
337
+ err = self.query_one("#form-error", Static)
338
+ raw = self.query_one("#path", Input).value.strip()
339
+ path = os.path.realpath(os.path.expanduser(raw)) if raw else ""
340
+ if self.project is None:
341
+ if not path or not os.path.isdir(path):
342
+ err.update(f"Not a directory: {raw or '(empty)'}")
343
+ return
344
+ if path in self.existing:
345
+ err.update("That directory is already registered.")
346
+ return
347
+ if path in ("/", os.path.expanduser("~")):
348
+ err.update("Register a project directory, not / or your home directory.")
349
+ return
350
+ name = self.query_one("#name", Input).value.strip() or os.path.basename(path)
351
+ self.dismiss(ProjectRequest(
352
+ name=name,
353
+ path=path if self.project is None else self.project.path,
354
+ group=str(self.query_one("#group", Select).value),
355
+ environment=str(self.query_one("#environment", Select).value),
356
+ always_worktree=self.query_one("#worktree", Checkbox).value,
357
+ test_command=self.query_one("#test", Input).value.strip(),
358
+ instructions=self.query_one("#instructions", TextArea).text.strip(),
359
+ account=(None if not self.query("#account") or
360
+ self.query_one("#account", Select).value is Select.NULL
361
+ else str(self.query_one("#account", Select).value)),
362
+ ))
363
+
364
+
365
+ # -------------------------------------------------------- account switcher
366
+ @dataclass(slots=True)
367
+ class AccountRow:
368
+ name: str
369
+ provider: str
370
+ icon: str
371
+ home: str | None
372
+ logged_in: bool | None
373
+ label: str
374
+ detail: str
375
+
376
+
377
+ class AccountSwitcher(ModalScreen[str | None]):
378
+ """Pick the active account: the default for new agents."""
379
+
380
+ BINDINGS = [Binding("escape,ctrl+a", "dismiss(None)", "Close")]
381
+
382
+ def __init__(self, rows: list[AccountRow], active: str) -> None:
383
+ super().__init__()
384
+ self.rows = rows
385
+ self.active = active
386
+
387
+ def compose(self) -> ComposeResult:
388
+ with Vertical(classes="dialog small", id="account-dialog"):
389
+ yield Label("Switch account", classes="dialog-title")
390
+ yield Static(Text("The active account is the default for new agents. Agents from "
391
+ "every account stay visible; filter them in the sidebar.",
392
+ style="dim"))
393
+ yield ListView(id="account-list")
394
+ yield Static(Text("⏎ make active · esc close · add accounts with "
395
+ "`fleetdeck accounts --discover --save`", style="dim"),
396
+ classes="hint")
397
+
398
+ def on_mount(self) -> None:
399
+ lv = self.query_one("#account-list", ListView)
400
+ styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
401
+ from ...models import AgentStatus
402
+ for r in self.rows:
403
+ t = Text()
404
+ t.append("● " if r.name == self.active else " ",
405
+ style=f"bold {styler.colors[AgentStatus.RUNNING]}")
406
+ t.append(f"{r.icon} ", style=(styler.colors[AgentStatus.PERMISSION]
407
+ if r.provider == "claude"
408
+ else styler.colors[AgentStatus.RUNNING]))
409
+ t.append(r.name, style="bold")
410
+ t.append(f" {'Claude Code' if r.provider == 'claude' else 'Codex (ChatGPT)'}",
411
+ style="dim")
412
+ t.append("\n ")
413
+ if r.logged_in:
414
+ t.append("signed in", style=styler.colors[AgentStatus.RUNNING])
415
+ if r.label:
416
+ t.append(f" · {r.label}")
417
+ elif r.logged_in is False:
418
+ t.append("not signed in", style=styler.colors[AgentStatus.FAILED])
419
+ else:
420
+ t.append("checking…", style="dim")
421
+ if r.detail:
422
+ t.append(f" · {r.detail}", style="dim")
423
+ t.append(f"\n {r.home or 'default location'}", style="dim")
424
+ lv.append(ListItem(Static(t)))
425
+ names = [r.name for r in self.rows]
426
+ lv.index = names.index(self.active) if self.active in names else 0
427
+ lv.focus()
428
+
429
+ def on_list_view_selected(self, event: ListView.Selected) -> None:
430
+ idx = event.list_view.index
431
+ if idx is not None and 0 <= idx < len(self.rows):
432
+ self.dismiss(self.rows[idx].name)
433
+
434
+
435
+ # ------------------------------------------------------------ text viewer
436
+ class TextViewer(ModalScreen[None]):
437
+ """Full-screen viewer for logs / diffs, optionally live-refreshing."""
438
+
439
+ BINDINGS = [Binding("escape,q", "dismiss(None)", "Close"),
440
+ Binding("r", "reload", "Reload")]
441
+
442
+ def __init__(self, title: str, loader: Callable[[], Awaitable[str | Text]], *,
443
+ syntax: str | None = None, live: float | None = None) -> None:
444
+ super().__init__()
445
+ self._title, self._loader, self._syntax, self._live = title, loader, syntax, live
446
+ self._last: str | None = None
447
+
448
+ def compose(self) -> ComposeResult:
449
+ with Vertical(classes="viewer"):
450
+ yield Label(self._title, classes="dialog-title")
451
+ yield RichLog(id="viewer-log", wrap=self._syntax is None, markup=False,
452
+ highlight=False, max_lines=20000)
453
+ yield Static("esc close · r reload" + (" · live" if self._live else ""),
454
+ classes="hint")
455
+
456
+ async def on_mount(self) -> None:
457
+ await self.action_reload()
458
+ if self._live:
459
+ self.set_interval(self._live, self.action_reload)
460
+
461
+ async def action_reload(self) -> None:
462
+ try:
463
+ text = await self._loader()
464
+ except Exception as exc: # noqa: BLE001 — surface any loader failure in the viewer
465
+ text = f"error: {exc}"
466
+ key = text.plain if isinstance(text, Text) else text
467
+ if key == self._last:
468
+ return
469
+ self._last = key
470
+ log = self.query_one("#viewer-log", RichLog)
471
+ log.clear()
472
+ if isinstance(text, Text):
473
+ log.write(text if key.strip() else Text("(empty)", style="dim"))
474
+ elif not text.strip():
475
+ log.write(Text("(empty)", style="dim"))
476
+ elif self._syntax:
477
+ log.write(Syntax(text, self._syntax, theme="ansi_dark", word_wrap=False,
478
+ background_color="default"))
479
+ else:
480
+ log.write(Text.from_ansi(text))
481
+
482
+
483
+ # ------------------------------------------------------------------- help
484
+ HELP_TEXT = {
485
+ "new_agent": "Launch a new background agent",
486
+ "add_project": "Register a project directory",
487
+ "attach": "Attach to the selected agent (TUI suspends)",
488
+ "preview": "Preview the selected agent's live log",
489
+ "logs": "Full-screen live logs",
490
+ "diff": "Git diff of the agent's directory",
491
+ "stop": "Stop agent (with confirmation)",
492
+ "restart": "Restart agent via `claude respawn`",
493
+ "search": "Search / filter",
494
+ "pin": "Pin / unpin selected project",
495
+ "new_task": "Queue a task for a project",
496
+ "run_tests": "Run the project's test command",
497
+ "toggle_dispatch": "Pause / resume task dispatch",
498
+ "follow_up": "Follow up: send a new prompt to a finished agent",
499
+ "terminal": "Open a shell in the agent's directory (ctrl+] leaves it)",
500
+ "details_wider": "Widen the Details panel (or drag its left edge)",
501
+ "details_narrower": "Narrow the Details panel",
502
+ "sidebar_wider": "Widen the Projects panel (or drag its right edge)",
503
+ "sidebar_narrower": "Narrow the Projects panel",
504
+ "zoom_details": "Zoom Details to full width (again to restore)",
505
+ "switch_account": "Switch the active account (default for new agents)",
506
+ "refresh": "Refresh now",
507
+ "view_dashboard": "Dashboard",
508
+ "view_projects": "Projects",
509
+ "view_sessions": "Agent sessions",
510
+ "view_tasks": "Task queues",
511
+ "view_settings": "Settings",
512
+ "help": "This help",
513
+ "quit": "Quit (agents keep running)",
514
+ }
515
+
516
+ VIEW_KEYS = [
517
+ ("Projects view", "e edit/rename · delete remove · t pin"),
518
+ ("Sessions view", "delete remove finished session (claude rm)"),
519
+ ("Tasks view", "a new · y retry · c cancel · delete remove · +/- priority · m templates"),
520
+ ("Everywhere", "tab switch panel · ctrl+p command palette · esc close dialog"),
521
+ ]
522
+
523
+
524
+ class HelpScreen(ModalScreen[None]):
525
+ BINDINGS = [Binding("escape,q,question_mark", "dismiss(None)", "Close")]
526
+
527
+ def __init__(self, keybindings: dict[str, str]) -> None:
528
+ super().__init__()
529
+ self.keybindings = keybindings
530
+
531
+ def compose(self) -> ComposeResult:
532
+ table = Table.grid(padding=(0, 3))
533
+ table.add_column(style="bold #cba6f7", no_wrap=True)
534
+ table.add_column()
535
+ for action in DEFAULT_KEYBINDINGS:
536
+ keys = self.keybindings.get(action, DEFAULT_KEYBINDINGS[action])
537
+ pretty = " / ".join(k.replace("question_mark", "?").replace("slash", "/")
538
+ for k in keys.split(","))
539
+ table.add_row(pretty, HELP_TEXT.get(action, action))
540
+ extra = Table.grid(padding=(0, 3))
541
+ extra.add_column(style="bold", no_wrap=True)
542
+ extra.add_column(style="dim")
543
+ for a, b in VIEW_KEYS:
544
+ extra.add_row(a, b)
545
+ legend = Text()
546
+ styler = self.app.styler # type: ignore[attr-defined] # CommandCenterApp
547
+ from ...models import AgentStatus
548
+ for st in (AgentStatus.RUNNING, AgentStatus.WAITING, AgentStatus.PERMISSION,
549
+ AgentStatus.PLANNING, AgentStatus.COMPLETED, AgentStatus.FAILED,
550
+ AgentStatus.IDLE):
551
+ legend.append_text(styler.badge(st))
552
+ legend.append(" ")
553
+ with Vertical(classes="dialog wide"):
554
+ yield Label("Keyboard shortcuts", classes="dialog-title")
555
+ with VerticalScroll():
556
+ yield Static(table)
557
+ yield Static("")
558
+ yield Static(extra)
559
+ yield Static("")
560
+ yield Static(legend)
561
+ yield Static(Text("\nRebind keys under `keybindings:` in config.yaml.",
562
+ style="dim"))
563
+
564
+
565
+ # -------------------------------------------------------------- templates
566
+ class TemplatesModal(ModalScreen[None]):
567
+ BINDINGS = [Binding("escape", "dismiss(None)", "Close"),
568
+ Binding("ctrl+s", "save", "Save"),
569
+ Binding("delete", "delete", "Delete")]
570
+
571
+ def __init__(self, store) -> None:
572
+ super().__init__()
573
+ self.store = store
574
+
575
+ def compose(self) -> ComposeResult:
576
+ with Vertical(classes="dialog wide"):
577
+ yield Label("Prompt templates", classes="dialog-title")
578
+ with Horizontal():
579
+ yield ListView(id="tpl-list", classes="tpl-list")
580
+ with Vertical():
581
+ yield Input(placeholder="Template name", id="tpl-name")
582
+ yield TextArea(id="tpl-body", soft_wrap=True)
583
+ yield Static("Use {area}-style placeholders for parts to fill in.",
584
+ classes="hint")
585
+ with Horizontal(classes="dialog-buttons"):
586
+ yield Button("Delete", id="delete", variant="error")
587
+ yield Button("Close", id="close")
588
+ yield Button("Save ⌃S", id="save", variant="primary")
589
+
590
+ def on_mount(self) -> None:
591
+ self._reload()
592
+
593
+ def _reload(self) -> None:
594
+ lv = self.query_one("#tpl-list", ListView)
595
+ lv.clear()
596
+ self._items = self.store.list_templates()
597
+ for t in self._items:
598
+ lv.append(ListItem(Label(t.name)))
599
+
600
+ def on_list_view_highlighted(self, event: ListView.Highlighted) -> None:
601
+ idx = event.list_view.index
602
+ if idx is not None and 0 <= idx < len(self._items):
603
+ t = self._items[idx]
604
+ self.query_one("#tpl-name", Input).value = t.name
605
+ self.query_one("#tpl-body", TextArea).text = t.body
606
+
607
+ def action_save(self) -> None:
608
+ name = self.query_one("#tpl-name", Input).value.strip()
609
+ body = self.query_one("#tpl-body", TextArea).text.strip()
610
+ if name and body:
611
+ self.store.save_template(name, body)
612
+ self.notify(f"Saved template {name!r}")
613
+ self._reload()
614
+
615
+ def action_delete(self) -> None:
616
+ idx = self.query_one("#tpl-list", ListView).index
617
+ if idx is not None and 0 <= idx < len(self._items):
618
+ self.store.delete_template(self._items[idx].id)
619
+ self._reload()
620
+
621
+ def on_button_pressed(self, event: Button.Pressed) -> None:
622
+ {"save": self.action_save, "delete": self.action_delete}.get(
623
+ event.button.id or "", lambda: self.dismiss(None))()