workdash 0.1.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.
- workdash/__init__.py +12 -0
- workdash/__main__.py +5 -0
- workdash/analysis_cache.py +184 -0
- workdash/analyzer.py +229 -0
- workdash/backend.py +248 -0
- workdash/config.py +207 -0
- workdash/github_client.py +1079 -0
- workdash/included_items.py +58 -0
- workdash/launcher.py +378 -0
- workdash/models.py +50 -0
- workdash/prompts/__init__.py +0 -0
- workdash/prompts/analyze_issue.txt +120 -0
- workdash/prompts/analyze_pr.txt +147 -0
- workdash/prompts/launch_issue.txt +20 -0
- workdash/prompts/launch_pr.txt +20 -0
- workdash/prompts/launch_review.txt +20 -0
- workdash/repo_resolver.py +112 -0
- workdash/repo_worktree.py +304 -0
- workdash/tui.py +608 -0
- workdash/workdash.py +207 -0
- workdash-0.1.0.dist-info/METADATA +890 -0
- workdash-0.1.0.dist-info/RECORD +26 -0
- workdash-0.1.0.dist-info/WHEEL +5 -0
- workdash-0.1.0.dist-info/entry_points.txt +2 -0
- workdash-0.1.0.dist-info/licenses/LICENSE +674 -0
- workdash-0.1.0.dist-info/top_level.txt +1 -0
workdash/tui.py
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
"""Textual list view for work items."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections.abc import Callable, Sequence
|
|
7
|
+
from datetime import UTC, datetime, timedelta
|
|
8
|
+
from typing import TypeVar
|
|
9
|
+
|
|
10
|
+
from .backend import IncludeResult, compute_suggestion_markers
|
|
11
|
+
from .launcher import open_markdown
|
|
12
|
+
from .models import WorkItem, WorkItemType, format_type_label
|
|
13
|
+
|
|
14
|
+
SuggestionMarkers = dict[tuple[WorkItemType, str, int], str]
|
|
15
|
+
RefreshCallbackResult = Sequence[WorkItem] | tuple[Sequence[WorkItem], SuggestionMarkers]
|
|
16
|
+
AnalyzeCallbackResult = str | None
|
|
17
|
+
_CallbackResult = TypeVar("_CallbackResult")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _to_utc(dt: datetime) -> datetime:
|
|
21
|
+
if dt.tzinfo is not None:
|
|
22
|
+
return dt.astimezone(UTC)
|
|
23
|
+
return dt.replace(tzinfo=UTC)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
from rich.text import Text
|
|
28
|
+
from textual.app import App, ComposeResult
|
|
29
|
+
from textual.containers import VerticalScroll
|
|
30
|
+
from textual.screen import ModalScreen
|
|
31
|
+
from textual.widgets import DataTable, Input, Static
|
|
32
|
+
except ModuleNotFoundError: # pragma: no cover - allows import before deps are installed
|
|
33
|
+
|
|
34
|
+
class WorkdashApp: # type: ignore[no-redef]
|
|
35
|
+
"""Fallback app shell used only when textual is unavailable."""
|
|
36
|
+
|
|
37
|
+
TITLE = "workdash"
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
work_items: Sequence[WorkItem] | None = None,
|
|
42
|
+
suggestion_markers: SuggestionMarkers | None = None,
|
|
43
|
+
open_callback: Callable[[WorkItem], None] | None = None,
|
|
44
|
+
refresh_callback: Callable[[], RefreshCallbackResult] | None = None,
|
|
45
|
+
analyze_callback: Callable[[WorkItem, str], AnalyzeCallbackResult] | None = None,
|
|
46
|
+
launch_callback: Callable[[WorkItem, str], None] | None = None,
|
|
47
|
+
terminal_callback: Callable[[WorkItem], None] | None = None,
|
|
48
|
+
include_callback: (
|
|
49
|
+
Callable[[str, set[tuple[WorkItemType, str, int]]], IncludeResult] | None
|
|
50
|
+
) = None,
|
|
51
|
+
now_utc: datetime | None = None,
|
|
52
|
+
) -> None:
|
|
53
|
+
self.work_items = tuple(work_items or ())
|
|
54
|
+
self.suggestion_markers = dict(suggestion_markers or {})
|
|
55
|
+
self.open_callback = open_callback
|
|
56
|
+
self.refresh_callback = refresh_callback
|
|
57
|
+
self.analyze_callback = analyze_callback
|
|
58
|
+
self.launch_callback = launch_callback
|
|
59
|
+
self.terminal_callback = terminal_callback
|
|
60
|
+
self.include_callback = include_callback
|
|
61
|
+
self.now_utc = now_utc or datetime.now(UTC)
|
|
62
|
+
self.status_message = "Ready."
|
|
63
|
+
else:
|
|
64
|
+
|
|
65
|
+
class BusyScreen(ModalScreen[None]):
|
|
66
|
+
"""Modal status view shown while long-running callbacks execute."""
|
|
67
|
+
|
|
68
|
+
DEFAULT_CSS = """
|
|
69
|
+
#busy-shell {
|
|
70
|
+
align: center middle;
|
|
71
|
+
width: 40;
|
|
72
|
+
height: 7;
|
|
73
|
+
border: solid $accent;
|
|
74
|
+
background: $surface;
|
|
75
|
+
}
|
|
76
|
+
#busy-message {
|
|
77
|
+
width: 100%;
|
|
78
|
+
content-align: center middle;
|
|
79
|
+
text-style: bold;
|
|
80
|
+
}
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
def __init__(self, *, message: str) -> None:
|
|
84
|
+
super().__init__()
|
|
85
|
+
self._message = message
|
|
86
|
+
|
|
87
|
+
def compose(self) -> ComposeResult:
|
|
88
|
+
with VerticalScroll(id="busy-shell"):
|
|
89
|
+
yield Static(self._message, id="busy-message")
|
|
90
|
+
|
|
91
|
+
class AnalyzeDialog(ModalScreen[str | None]):
|
|
92
|
+
"""Modal dialog for choosing an analysis action."""
|
|
93
|
+
|
|
94
|
+
DEFAULT_CSS = """
|
|
95
|
+
#analyze-shell {
|
|
96
|
+
align: center middle;
|
|
97
|
+
width: 50;
|
|
98
|
+
height: auto;
|
|
99
|
+
max-height: 14;
|
|
100
|
+
border: solid $accent;
|
|
101
|
+
background: $surface;
|
|
102
|
+
padding: 1 2;
|
|
103
|
+
}
|
|
104
|
+
.analyze-line {
|
|
105
|
+
width: 100%;
|
|
106
|
+
}
|
|
107
|
+
"""
|
|
108
|
+
BINDINGS = [
|
|
109
|
+
("a", "open_analysis", "Open"),
|
|
110
|
+
("c", "analyze_claude", "Claude"),
|
|
111
|
+
("g", "analyze_codex", "Codex"),
|
|
112
|
+
("escape", "cancel", "Cancel"),
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
def __init__(self, *, item: WorkItem, now_utc: datetime) -> None:
|
|
116
|
+
super().__init__()
|
|
117
|
+
self._item = item
|
|
118
|
+
self._now_utc = now_utc
|
|
119
|
+
|
|
120
|
+
def compose(self) -> ComposeResult:
|
|
121
|
+
with VerticalScroll(id="analyze-shell"):
|
|
122
|
+
if self._item.analyzed_at is not None:
|
|
123
|
+
age_days = max(0, (self._now_utc - self._item.analyzed_at).days)
|
|
124
|
+
yield Static(
|
|
125
|
+
f"Last analyzed: {age_days}d ago",
|
|
126
|
+
classes="analyze-line",
|
|
127
|
+
)
|
|
128
|
+
yield Static("")
|
|
129
|
+
yield Static("(a) Open analysis", classes="analyze-line")
|
|
130
|
+
else:
|
|
131
|
+
yield Static("No previous analysis.", classes="analyze-line")
|
|
132
|
+
yield Static("")
|
|
133
|
+
yield Static("(c) Analyze with Claude", classes="analyze-line")
|
|
134
|
+
yield Static("(g) Analyze with ChatGPT Codex", classes="analyze-line")
|
|
135
|
+
yield Static("")
|
|
136
|
+
yield Static("(Esc) Cancel", classes="analyze-line")
|
|
137
|
+
|
|
138
|
+
def action_open_analysis(self) -> None:
|
|
139
|
+
if self._item.analyzed_at is not None:
|
|
140
|
+
self.dismiss("cached")
|
|
141
|
+
|
|
142
|
+
def action_analyze_claude(self) -> None:
|
|
143
|
+
self.dismiss("claude")
|
|
144
|
+
|
|
145
|
+
def action_analyze_codex(self) -> None:
|
|
146
|
+
self.dismiss("codex")
|
|
147
|
+
|
|
148
|
+
def action_cancel(self) -> None:
|
|
149
|
+
self.dismiss(None)
|
|
150
|
+
|
|
151
|
+
class CodeDialog(ModalScreen[str | None]):
|
|
152
|
+
"""Modal dialog for choosing a coding tool to launch."""
|
|
153
|
+
|
|
154
|
+
DEFAULT_CSS = """
|
|
155
|
+
#code-shell {
|
|
156
|
+
align: center middle;
|
|
157
|
+
width: 50;
|
|
158
|
+
height: auto;
|
|
159
|
+
max-height: 10;
|
|
160
|
+
border: solid $accent;
|
|
161
|
+
background: $surface;
|
|
162
|
+
padding: 1 2;
|
|
163
|
+
}
|
|
164
|
+
.code-line {
|
|
165
|
+
width: 100%;
|
|
166
|
+
}
|
|
167
|
+
"""
|
|
168
|
+
BINDINGS = [
|
|
169
|
+
("c", "launch_claude", "Claude"),
|
|
170
|
+
("g", "launch_codex", "Codex"),
|
|
171
|
+
("v", "launch_vscode", "VSCode"),
|
|
172
|
+
("escape", "cancel", "Cancel"),
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
def compose(self) -> ComposeResult:
|
|
176
|
+
with VerticalScroll(id="code-shell"):
|
|
177
|
+
yield Static("Launch coding session:", classes="code-line")
|
|
178
|
+
yield Static("")
|
|
179
|
+
yield Static("(c) Claude", classes="code-line")
|
|
180
|
+
yield Static("(g) ChatGPT Codex", classes="code-line")
|
|
181
|
+
yield Static("(v) VSCode Copilot", classes="code-line")
|
|
182
|
+
yield Static("")
|
|
183
|
+
yield Static("(Esc) Cancel", classes="code-line")
|
|
184
|
+
|
|
185
|
+
def action_launch_claude(self) -> None:
|
|
186
|
+
self.dismiss("claude")
|
|
187
|
+
|
|
188
|
+
def action_launch_codex(self) -> None:
|
|
189
|
+
self.dismiss("codex")
|
|
190
|
+
|
|
191
|
+
def action_launch_vscode(self) -> None:
|
|
192
|
+
self.dismiss("vscode")
|
|
193
|
+
|
|
194
|
+
def action_cancel(self) -> None:
|
|
195
|
+
self.dismiss(None)
|
|
196
|
+
|
|
197
|
+
class IncludeDialog(ModalScreen[str | None]):
|
|
198
|
+
"""Modal dialog that accepts a GitHub issue or pull request URL."""
|
|
199
|
+
|
|
200
|
+
DEFAULT_CSS = """
|
|
201
|
+
#include-shell {
|
|
202
|
+
align: center middle;
|
|
203
|
+
width: 70;
|
|
204
|
+
height: auto;
|
|
205
|
+
max-height: 9;
|
|
206
|
+
border: solid $accent;
|
|
207
|
+
background: $surface;
|
|
208
|
+
padding: 1 2;
|
|
209
|
+
}
|
|
210
|
+
#include-url {
|
|
211
|
+
width: 100%;
|
|
212
|
+
}
|
|
213
|
+
"""
|
|
214
|
+
BINDINGS = [("escape", "cancel", "Cancel")]
|
|
215
|
+
|
|
216
|
+
def compose(self) -> ComposeResult:
|
|
217
|
+
with VerticalScroll(id="include-shell"):
|
|
218
|
+
yield Static("Paste a GitHub issue or pull request URL:")
|
|
219
|
+
yield Input(placeholder="https://github.com/owner/repo/pull/123", id="include-url")
|
|
220
|
+
yield Static("(Enter to confirm, Esc to cancel)")
|
|
221
|
+
|
|
222
|
+
def on_mount(self) -> None:
|
|
223
|
+
self.query_one("#include-url", Input).focus()
|
|
224
|
+
|
|
225
|
+
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
226
|
+
self.dismiss(event.value.strip()) # single strip; caller trusts this value
|
|
227
|
+
|
|
228
|
+
def action_cancel(self) -> None:
|
|
229
|
+
self.dismiss(None)
|
|
230
|
+
|
|
231
|
+
class WorkdashApp(App[None]):
|
|
232
|
+
"""Main Textual app shell."""
|
|
233
|
+
|
|
234
|
+
TITLE = "workdash"
|
|
235
|
+
DEFAULT_CSS = """
|
|
236
|
+
#status-footer {
|
|
237
|
+
dock: bottom;
|
|
238
|
+
height: 1;
|
|
239
|
+
padding: 0 1;
|
|
240
|
+
}
|
|
241
|
+
#command-footer {
|
|
242
|
+
dock: bottom;
|
|
243
|
+
height: 1;
|
|
244
|
+
padding: 0 1;
|
|
245
|
+
}
|
|
246
|
+
"""
|
|
247
|
+
COMMAND_HINT_TEXT = "(o)pen (r)efresh (a)nalyze (c)ode (t)erminal (i)nclude (q)uit"
|
|
248
|
+
BINDINGS = [
|
|
249
|
+
("o", "open_link", "Open"),
|
|
250
|
+
("r", "refresh_items", "Refresh"),
|
|
251
|
+
("a", "analyze_item", "Analyze"),
|
|
252
|
+
("c", "launch_code", "Code"),
|
|
253
|
+
("t", "open_terminal", "Terminal"),
|
|
254
|
+
("i", "include_item", "Include"),
|
|
255
|
+
("q", "quit_app", "Quit"),
|
|
256
|
+
]
|
|
257
|
+
|
|
258
|
+
def __init__(
|
|
259
|
+
self,
|
|
260
|
+
work_items: Sequence[WorkItem] | None = None,
|
|
261
|
+
suggestion_markers: SuggestionMarkers | None = None,
|
|
262
|
+
open_callback: Callable[[WorkItem], None] | None = None,
|
|
263
|
+
refresh_callback: Callable[[], RefreshCallbackResult] | None = None,
|
|
264
|
+
analyze_callback: Callable[[WorkItem, str], AnalyzeCallbackResult] | None = None,
|
|
265
|
+
launch_callback: Callable[[WorkItem, str], None] | None = None,
|
|
266
|
+
worktree_callback: Callable[[WorkItem], str] | None = None,
|
|
267
|
+
terminal_callback: Callable[[WorkItem], None] | None = None,
|
|
268
|
+
include_callback: (
|
|
269
|
+
Callable[[str, set[tuple[WorkItemType, str, int]]], IncludeResult] | None
|
|
270
|
+
) = None,
|
|
271
|
+
now_utc: datetime | None = None,
|
|
272
|
+
) -> None:
|
|
273
|
+
super().__init__()
|
|
274
|
+
self._work_items = list(work_items or ())
|
|
275
|
+
self._sorted_work_items: list[WorkItem] = []
|
|
276
|
+
self._suggestion_markers = dict(suggestion_markers or {})
|
|
277
|
+
self._open_callback = open_callback
|
|
278
|
+
self._refresh_callback = refresh_callback
|
|
279
|
+
self._analyze_callback = analyze_callback
|
|
280
|
+
self._launch_callback = launch_callback
|
|
281
|
+
self._worktree_callback = worktree_callback
|
|
282
|
+
self._terminal_callback = terminal_callback
|
|
283
|
+
self._include_callback = include_callback
|
|
284
|
+
self._now_utc = now_utc or datetime.now(UTC)
|
|
285
|
+
self._status_message = "Ready."
|
|
286
|
+
|
|
287
|
+
def compose(self) -> ComposeResult:
|
|
288
|
+
yield DataTable(id="work-items")
|
|
289
|
+
yield Static(self._status_message, id="status-footer")
|
|
290
|
+
yield Static(self.COMMAND_HINT_TEXT, id="command-footer")
|
|
291
|
+
|
|
292
|
+
def on_mount(self) -> None:
|
|
293
|
+
self._render_table()
|
|
294
|
+
|
|
295
|
+
def _update_status(self, message: str) -> None:
|
|
296
|
+
self._status_message = message
|
|
297
|
+
self.query_one("#status-footer", Static).update(message)
|
|
298
|
+
|
|
299
|
+
def _title_with_suggestion_marker(self, item: WorkItem) -> str:
|
|
300
|
+
marker = self._suggestion_markers.get((item.item_type, item.repo, item.number))
|
|
301
|
+
return f"* {item.title}" if marker else item.title
|
|
302
|
+
|
|
303
|
+
def _render_table(self, *, focus_item: WorkItem | None = None) -> None:
|
|
304
|
+
table = self.query_one("#work-items", DataTable)
|
|
305
|
+
table.cursor_type = "row"
|
|
306
|
+
previous_row = table.cursor_row if table.cursor_row is not None else 0
|
|
307
|
+
table.clear(columns=True)
|
|
308
|
+
table.add_columns("Type", "Repo", "Title", "Age", "Last Update")
|
|
309
|
+
self._sorted_work_items = sorted(
|
|
310
|
+
self._work_items,
|
|
311
|
+
key=lambda entry: entry.updated_at,
|
|
312
|
+
reverse=True,
|
|
313
|
+
)
|
|
314
|
+
cutoff = self._now_utc - timedelta(hours=24)
|
|
315
|
+
for item in self._sorted_work_items:
|
|
316
|
+
age_days = max(0, (self._now_utc - _to_utc(item.created_at)).days)
|
|
317
|
+
update_days = max(0, (self._now_utc - _to_utc(item.updated_at)).days)
|
|
318
|
+
type_label = format_type_label(item)
|
|
319
|
+
title = self._title_with_suggestion_marker(item)
|
|
320
|
+
if _to_utc(item.updated_at) >= cutoff:
|
|
321
|
+
table.add_row(
|
|
322
|
+
Text(type_label, style="bold"),
|
|
323
|
+
Text(item.repo, style="bold"),
|
|
324
|
+
Text(title, style="bold"),
|
|
325
|
+
Text(f"{age_days}d", style="bold"),
|
|
326
|
+
Text(f"{update_days}d", style="bold"),
|
|
327
|
+
)
|
|
328
|
+
else:
|
|
329
|
+
table.add_row(type_label, item.repo, title, f"{age_days}d", f"{update_days}d")
|
|
330
|
+
if self._sorted_work_items:
|
|
331
|
+
target_row = previous_row
|
|
332
|
+
if focus_item is not None:
|
|
333
|
+
for index, item in enumerate(self._sorted_work_items):
|
|
334
|
+
if (
|
|
335
|
+
item.item_type == focus_item.item_type
|
|
336
|
+
and item.repo == focus_item.repo
|
|
337
|
+
and item.number == focus_item.number
|
|
338
|
+
):
|
|
339
|
+
target_row = index
|
|
340
|
+
break
|
|
341
|
+
table.move_cursor(row=min(max(target_row, 0), len(self._sorted_work_items) - 1))
|
|
342
|
+
|
|
343
|
+
def _selected_item(self) -> WorkItem | None:
|
|
344
|
+
table = self.query_one("#work-items", DataTable)
|
|
345
|
+
if (
|
|
346
|
+
table.cursor_row is None
|
|
347
|
+
or table.cursor_row < 0
|
|
348
|
+
or table.cursor_row >= len(self._sorted_work_items)
|
|
349
|
+
):
|
|
350
|
+
return None
|
|
351
|
+
return self._sorted_work_items[table.cursor_row]
|
|
352
|
+
|
|
353
|
+
async def _run_with_busy_screen(
|
|
354
|
+
self,
|
|
355
|
+
*,
|
|
356
|
+
message: str,
|
|
357
|
+
callback: Callable[[], _CallbackResult],
|
|
358
|
+
) -> _CallbackResult:
|
|
359
|
+
busy_screen = BusyScreen(message=message)
|
|
360
|
+
await self.push_screen(busy_screen)
|
|
361
|
+
try:
|
|
362
|
+
return await asyncio.to_thread(callback)
|
|
363
|
+
finally:
|
|
364
|
+
if self.screen is busy_screen:
|
|
365
|
+
self.pop_screen()
|
|
366
|
+
|
|
367
|
+
async def action_open_link(self) -> None:
|
|
368
|
+
selected_item = self._selected_item()
|
|
369
|
+
if selected_item is None or self._open_callback is None:
|
|
370
|
+
self._update_status("Open skipped.")
|
|
371
|
+
return
|
|
372
|
+
try:
|
|
373
|
+
await self._run_with_busy_screen(
|
|
374
|
+
message="Opening link...",
|
|
375
|
+
callback=lambda: self._open_callback(selected_item),
|
|
376
|
+
)
|
|
377
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
378
|
+
self._update_status(f"Open failed: {error}")
|
|
379
|
+
self.notify(f"Open failed: {error}", severity="error", timeout=10)
|
|
380
|
+
return
|
|
381
|
+
self._update_status(
|
|
382
|
+
f"Opened {selected_item.item_type.value} {selected_item.repo}#{selected_item.number}."
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
async def action_refresh_items(self) -> None:
|
|
386
|
+
if self._refresh_callback is None:
|
|
387
|
+
self._update_status("Refresh skipped.")
|
|
388
|
+
return
|
|
389
|
+
try:
|
|
390
|
+
refreshed = await self._run_with_busy_screen(
|
|
391
|
+
message="Refreshing work items...",
|
|
392
|
+
callback=self._refresh_callback,
|
|
393
|
+
)
|
|
394
|
+
if (
|
|
395
|
+
isinstance(refreshed, tuple)
|
|
396
|
+
and len(refreshed) == 2
|
|
397
|
+
and isinstance(refreshed[1], dict)
|
|
398
|
+
):
|
|
399
|
+
self._work_items = list(refreshed[0])
|
|
400
|
+
self._suggestion_markers = dict(refreshed[1])
|
|
401
|
+
else:
|
|
402
|
+
self._work_items = list(refreshed)
|
|
403
|
+
self._render_table()
|
|
404
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
405
|
+
self._update_status(f"Refresh failed: {error}")
|
|
406
|
+
self.notify(f"Refresh failed: {error}", severity="error", timeout=10)
|
|
407
|
+
return
|
|
408
|
+
self._update_status(f"Refreshed {len(self._work_items)} item(s).")
|
|
409
|
+
|
|
410
|
+
async def action_analyze_item(self) -> None:
|
|
411
|
+
selected_item = self._selected_item()
|
|
412
|
+
if selected_item is None or self._analyze_callback is None:
|
|
413
|
+
self._update_status("Analyze skipped.")
|
|
414
|
+
return
|
|
415
|
+
dialog = AnalyzeDialog(item=selected_item, now_utc=self._now_utc)
|
|
416
|
+
|
|
417
|
+
def _on_dialog_result(choice: str | None) -> None:
|
|
418
|
+
if choice is None:
|
|
419
|
+
return
|
|
420
|
+
# Schedule the follow-up work as a coroutine on the event loop
|
|
421
|
+
self.call_later(lambda: self._perform_analysis(selected_item, choice))
|
|
422
|
+
|
|
423
|
+
self.push_screen(dialog, callback=_on_dialog_result)
|
|
424
|
+
|
|
425
|
+
async def _perform_analysis(self, item: WorkItem, choice: str) -> None:
|
|
426
|
+
"""Execute analysis after the user picks a tool from the dialog."""
|
|
427
|
+
|
|
428
|
+
if self._worktree_callback is not None and choice != "cached":
|
|
429
|
+
try:
|
|
430
|
+
await self._run_with_busy_screen(
|
|
431
|
+
message=f"Preparing worktree for {item.repo}#{item.number}...",
|
|
432
|
+
callback=lambda: self._worktree_callback(item),
|
|
433
|
+
)
|
|
434
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
435
|
+
self._update_status(f"Worktree setup failed: {error}")
|
|
436
|
+
self.notify(f"Worktree setup failed: {error}", severity="error", timeout=10)
|
|
437
|
+
return
|
|
438
|
+
tool_label = {"cached": "cached", "claude": "Claude", "codex": "Codex"}.get(
|
|
439
|
+
choice, choice
|
|
440
|
+
)
|
|
441
|
+
busy_message = (
|
|
442
|
+
"Loading analysis..." if choice == "cached" else f"Analyzing with {tool_label}..."
|
|
443
|
+
)
|
|
444
|
+
try:
|
|
445
|
+
analysis_path = await self._run_with_busy_screen(
|
|
446
|
+
message=busy_message,
|
|
447
|
+
callback=lambda c=choice: self._analyze_callback(item, c),
|
|
448
|
+
)
|
|
449
|
+
if choice != "cached":
|
|
450
|
+
self._render_table()
|
|
451
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
452
|
+
self._update_status(f"Analyze failed: {error}")
|
|
453
|
+
self.notify(f"Analyze failed: {error}", severity="error", timeout=10)
|
|
454
|
+
return
|
|
455
|
+
if analysis_path is not None:
|
|
456
|
+
try:
|
|
457
|
+
open_markdown(analysis_path)
|
|
458
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
459
|
+
self._update_status(f"Failed to open analysis: {error}")
|
|
460
|
+
self.notify(f"Failed to open analysis: {error}", severity="error", timeout=10)
|
|
461
|
+
return
|
|
462
|
+
item_label = f"{item.item_type.value} {item.repo}#{item.number}"
|
|
463
|
+
if choice == "cached":
|
|
464
|
+
self._update_status(f"Opened analysis for {item_label}.")
|
|
465
|
+
else:
|
|
466
|
+
self._update_status(f"Analyzed {item_label} with {tool_label}.")
|
|
467
|
+
|
|
468
|
+
async def action_launch_code(self) -> None:
|
|
469
|
+
selected_item = self._selected_item()
|
|
470
|
+
if selected_item is None or self._launch_callback is None:
|
|
471
|
+
self._update_status("Code launch skipped.")
|
|
472
|
+
return
|
|
473
|
+
dialog = CodeDialog()
|
|
474
|
+
|
|
475
|
+
def _on_dialog_result(choice: str | None) -> None:
|
|
476
|
+
if choice is None:
|
|
477
|
+
return
|
|
478
|
+
self.call_later(lambda: self._perform_launch(selected_item, choice))
|
|
479
|
+
|
|
480
|
+
self.push_screen(dialog, callback=_on_dialog_result)
|
|
481
|
+
|
|
482
|
+
async def _perform_launch(self, item: WorkItem, choice: str) -> None:
|
|
483
|
+
"""Execute coding tool launch after the user picks from the dialog."""
|
|
484
|
+
|
|
485
|
+
if self._worktree_callback is not None:
|
|
486
|
+
try:
|
|
487
|
+
await self._run_with_busy_screen(
|
|
488
|
+
message=f"Preparing worktree for {item.repo}#{item.number}...",
|
|
489
|
+
callback=lambda: self._worktree_callback(item),
|
|
490
|
+
)
|
|
491
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
492
|
+
self._update_status(f"Worktree setup failed: {error}")
|
|
493
|
+
self.notify(f"Worktree setup failed: {error}", severity="error", timeout=10)
|
|
494
|
+
return
|
|
495
|
+
tool_label = {"claude": "Claude", "codex": "Codex", "vscode": "VSCode"}.get(
|
|
496
|
+
choice, choice
|
|
497
|
+
)
|
|
498
|
+
try:
|
|
499
|
+
await self._run_with_busy_screen(
|
|
500
|
+
message=f"Launching {tool_label}...",
|
|
501
|
+
callback=lambda c=choice: self._launch_callback(item, c),
|
|
502
|
+
)
|
|
503
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
504
|
+
self._update_status(f"Launch failed: {error}")
|
|
505
|
+
self.notify(f"Launch failed: {error}", severity="error", timeout=10)
|
|
506
|
+
return
|
|
507
|
+
self._update_status(
|
|
508
|
+
f"Launched {tool_label} for {item.item_type.value} {item.repo}#{item.number}."
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
async def action_open_terminal(self) -> None:
|
|
512
|
+
selected_item = self._selected_item()
|
|
513
|
+
if selected_item is None or self._terminal_callback is None:
|
|
514
|
+
self._update_status("Terminal launch skipped.")
|
|
515
|
+
return
|
|
516
|
+
if self._worktree_callback is not None:
|
|
517
|
+
try:
|
|
518
|
+
await self._run_with_busy_screen(
|
|
519
|
+
message=f"Preparing worktree for {selected_item.repo}#{selected_item.number}...",
|
|
520
|
+
callback=lambda: self._worktree_callback(selected_item),
|
|
521
|
+
)
|
|
522
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
523
|
+
self._update_status(f"Worktree setup failed: {error}")
|
|
524
|
+
self.notify(f"Worktree setup failed: {error}", severity="error", timeout=10)
|
|
525
|
+
return
|
|
526
|
+
try:
|
|
527
|
+
await self._run_with_busy_screen(
|
|
528
|
+
message="Opening terminal...",
|
|
529
|
+
callback=lambda: self._terminal_callback(selected_item),
|
|
530
|
+
)
|
|
531
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
532
|
+
self._update_status(f"Terminal failed: {error}")
|
|
533
|
+
self.notify(f"Terminal failed: {error}", severity="error", timeout=10)
|
|
534
|
+
return
|
|
535
|
+
self._update_status(
|
|
536
|
+
f"Opened terminal for {selected_item.item_type.value} {selected_item.repo}#{selected_item.number}."
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
async def action_include_item(self) -> None:
|
|
540
|
+
if self._include_callback is None:
|
|
541
|
+
self._update_status("Include skipped.")
|
|
542
|
+
return
|
|
543
|
+
dialog = IncludeDialog()
|
|
544
|
+
|
|
545
|
+
def _on_dialog_result(normalized_url: str | None) -> None:
|
|
546
|
+
if normalized_url is None:
|
|
547
|
+
return
|
|
548
|
+
self.call_later(lambda: self._perform_include(normalized_url))
|
|
549
|
+
|
|
550
|
+
self.push_screen(dialog, callback=_on_dialog_result)
|
|
551
|
+
|
|
552
|
+
async def _perform_include(self, url: str) -> None:
|
|
553
|
+
"""Fetch the pasted URL and fold the item into the visible list."""
|
|
554
|
+
|
|
555
|
+
if not url:
|
|
556
|
+
self._update_status("No URL provided.")
|
|
557
|
+
self.notify("No URL provided.", severity="warning", timeout=10)
|
|
558
|
+
return
|
|
559
|
+
existing_identities = {
|
|
560
|
+
(item.item_type, item.repo, item.number) for item in self._work_items
|
|
561
|
+
}
|
|
562
|
+
try:
|
|
563
|
+
result = await self._run_with_busy_screen(
|
|
564
|
+
message="Including work item...",
|
|
565
|
+
callback=lambda: self._include_callback(url, existing_identities),
|
|
566
|
+
)
|
|
567
|
+
except Exception as error: # noqa: BLE001 - keep TUI alive on callback errors
|
|
568
|
+
message = f"Failed to persist URL: {error}"
|
|
569
|
+
self._update_status(message)
|
|
570
|
+
self.notify(message, severity="error", timeout=10)
|
|
571
|
+
return
|
|
572
|
+
if result.invalid:
|
|
573
|
+
self._update_status(f"Invalid URL: {url}")
|
|
574
|
+
self.notify(f"Invalid URL: {url}", severity="error", timeout=10)
|
|
575
|
+
return
|
|
576
|
+
if result.transient_failure:
|
|
577
|
+
message = "GitHub unreachable — URL not saved. Try again later."
|
|
578
|
+
self._update_status(message)
|
|
579
|
+
self.notify(message, severity="error", timeout=10)
|
|
580
|
+
return
|
|
581
|
+
if result.duplicate_identity is not None:
|
|
582
|
+
item_type, repo, number = result.duplicate_identity
|
|
583
|
+
existing = next(
|
|
584
|
+
item
|
|
585
|
+
for item in self._work_items
|
|
586
|
+
if item.item_type == item_type and item.repo == repo and item.number == number
|
|
587
|
+
)
|
|
588
|
+
existing.included = True
|
|
589
|
+
self._render_table(focus_item=existing)
|
|
590
|
+
self._update_status(
|
|
591
|
+
f"Already tracking {existing.item_type.value} "
|
|
592
|
+
f"{existing.repo}#{existing.number}; moved cursor."
|
|
593
|
+
)
|
|
594
|
+
return
|
|
595
|
+
fetched_item = result.fetched_item
|
|
596
|
+
assert fetched_item is not None # IncludeResult invariant
|
|
597
|
+
self._work_items.append(fetched_item)
|
|
598
|
+
# Suggestion markers depend on the full item set; recompute so any
|
|
599
|
+
# newer/better candidate is highlighted correctly on the next render.
|
|
600
|
+
self._suggestion_markers = compute_suggestion_markers(self._work_items)
|
|
601
|
+
self._render_table(focus_item=fetched_item)
|
|
602
|
+
self._update_status(
|
|
603
|
+
f"Included {fetched_item.item_type.value} "
|
|
604
|
+
f"{fetched_item.repo}#{fetched_item.number}."
|
|
605
|
+
)
|
|
606
|
+
|
|
607
|
+
def action_quit_app(self) -> None:
|
|
608
|
+
self.exit()
|