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/workdash.py ADDED
@@ -0,0 +1,207 @@
1
+ """Top-level app entrypoint."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import logging
7
+ import os
8
+ import shlex
9
+ import shutil
10
+ import sys
11
+ from collections.abc import Sequence
12
+ from dataclasses import dataclass
13
+
14
+ from . import __version__
15
+ from .backend import SuggestionMarkers, WorkdashBackend
16
+ from .config import configure, load_config, validate_config
17
+ from .launcher import (
18
+ exec_zellij_wrapped_workdash,
19
+ launch_agent_context,
20
+ launch_terminal_context,
21
+ launch_vscode_context,
22
+ open_in_browser,
23
+ prepare_launch_agent_prompt,
24
+ )
25
+ from .models import WorkItem, format_type_label
26
+ from .repo_worktree import ensure_worktree, get_merge_base
27
+ from .tui import WorkdashApp
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class CLIOptions:
32
+ """CLI configuration available during plumbing phases."""
33
+
34
+ debug: bool
35
+ print_mode: bool
36
+ refresh: bool
37
+ configure: bool
38
+ direct: bool
39
+
40
+
41
+ def _parse_args(argv: Sequence[str] | None = None) -> CLIOptions:
42
+ """Parse CLI flags introduced in Phase 1 task 2."""
43
+
44
+ parser = argparse.ArgumentParser(
45
+ prog="workdash",
46
+ description="GitHub work triage dashboard.",
47
+ )
48
+ parser.add_argument(
49
+ "--version",
50
+ action="version",
51
+ version=f"%(prog)s {__version__}",
52
+ )
53
+ parser.add_argument(
54
+ "--debug",
55
+ action="store_true",
56
+ help="Enable verbose logging.",
57
+ )
58
+ parser.add_argument(
59
+ "--print",
60
+ dest="print_mode",
61
+ action="store_true",
62
+ help="Emit flattened data listing without launching the TUI.",
63
+ )
64
+ parser.add_argument(
65
+ "--refresh",
66
+ action="store_true",
67
+ help="Force a data refresh from GitHub sources.",
68
+ )
69
+ parser.add_argument(
70
+ "--configure",
71
+ action="store_true",
72
+ help="Interactively set up or update the configuration file.",
73
+ )
74
+ parser.add_argument(
75
+ "--direct",
76
+ action="store_true",
77
+ help="Start directly without wrapping the interactive dashboard in Zellij.",
78
+ )
79
+ namespace = parser.parse_args(argv) if argv is not None else parser.parse_args()
80
+ return CLIOptions(
81
+ debug=namespace.debug,
82
+ print_mode=namespace.print_mode,
83
+ refresh=namespace.refresh,
84
+ configure=namespace.configure,
85
+ direct=namespace.direct,
86
+ )
87
+
88
+
89
+ def _should_wrap_interactive_start(options: CLIOptions) -> bool:
90
+ return (
91
+ not options.direct
92
+ and not options.print_mode
93
+ and not options.configure
94
+ and not os.getenv("ZELLIJ")
95
+ )
96
+
97
+
98
+ def _print_work_items(
99
+ work_items: Sequence[WorkItem], suggestion_markers: SuggestionMarkers
100
+ ) -> None:
101
+ if not work_items:
102
+ print("No work items found.")
103
+ return
104
+ for item in sorted(work_items, key=lambda entry: entry.updated_at, reverse=True):
105
+ suggestion_marker = suggestion_markers.get((item.item_type, item.repo, item.number), "")
106
+ print(
107
+ f"{format_type_label(item):7} "
108
+ f"{item.repo}#{item.number:<5} "
109
+ f"{item.created_at.date().isoformat()} "
110
+ f"{f'* {item.title}' if suggestion_marker else item.title}"
111
+ )
112
+
113
+
114
+ def main(argv: Sequence[str] | None = None) -> int:
115
+ """Run the app entrypoint with backend data orchestration."""
116
+
117
+ options = _parse_args(argv)
118
+ if options.debug:
119
+ logging.basicConfig(level=logging.DEBUG)
120
+
121
+ if _should_wrap_interactive_start(options):
122
+ try:
123
+ exec_zellij_wrapped_workdash(argv)
124
+ except RuntimeError as error:
125
+ print(f"Error: {error}", file=sys.stderr, flush=True)
126
+ return 1
127
+
128
+ if options.configure:
129
+ configure()
130
+ return 0
131
+
132
+ if shutil.which("gh") is None:
133
+ print(
134
+ "Error: gh CLI is not installed or not on PATH. Install it from https://cli.github.com/",
135
+ file=sys.stderr,
136
+ flush=True,
137
+ )
138
+ return 1
139
+
140
+ config = load_config()
141
+ missing = validate_config(config)
142
+ if missing:
143
+ print(
144
+ f"Error: missing configuration fields: {', '.join(missing)}",
145
+ file=sys.stderr,
146
+ flush=True,
147
+ )
148
+ print(
149
+ "Run 'workdash --configure' to set up your configuration.",
150
+ file=sys.stderr,
151
+ flush=True,
152
+ )
153
+ return 1
154
+
155
+ backend = WorkdashBackend(config=config)
156
+ if not options.print_mode:
157
+ print("Loading work items from GitHub...", flush=True)
158
+ work_items, suggestion_markers = backend.load_items(
159
+ progress_callback=lambda message: print(message, flush=True)
160
+ )
161
+ else:
162
+ work_items, suggestion_markers = backend.load_items()
163
+
164
+ if options.print_mode:
165
+ _print_work_items(work_items, suggestion_markers)
166
+ return 0
167
+
168
+ def _analyze(item, tool="codex"):
169
+ ensure_worktree(config.workdir, item)
170
+ return backend.analyze_item(item, tool=tool)
171
+
172
+ def _launch(item: WorkItem, tool: str = "codex") -> None:
173
+ repo_path = ensure_worktree(config.workdir, item)
174
+ prompt = prepare_launch_agent_prompt(
175
+ item,
176
+ repo_path,
177
+ analysis_path=str(backend.analysis_cache.build_analysis_path(item))
178
+ if item.analysis is not None
179
+ else None,
180
+ merge_base=get_merge_base(repo_path),
181
+ )
182
+ if tool == "vscode":
183
+ launch_vscode_context(repo_path, prompt)
184
+ else:
185
+ launch_agent_context(
186
+ repo_path,
187
+ prompt,
188
+ agent_command_tokens=shlex.split(
189
+ config.claude.launch if tool == "claude" else config.codex.launch
190
+ ),
191
+ )
192
+
193
+ app = WorkdashApp(
194
+ work_items=work_items,
195
+ suggestion_markers=suggestion_markers,
196
+ open_callback=lambda item: open_in_browser(item.url),
197
+ refresh_callback=backend.load_items,
198
+ worktree_callback=lambda item: ensure_worktree(config.workdir, item),
199
+ analyze_callback=_analyze,
200
+ launch_callback=_launch,
201
+ terminal_callback=lambda item: launch_terminal_context(
202
+ ensure_worktree(config.workdir, item)
203
+ ),
204
+ include_callback=backend.include_item_by_url,
205
+ )
206
+ app.run()
207
+ return 0