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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Persistent store of explicitly-included work item URLs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import tempfile
|
|
9
|
+
from collections.abc import Iterable
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class IncludedItemsStore:
|
|
14
|
+
"""JSON-backed list of canonical GitHub URLs for included items.
|
|
15
|
+
|
|
16
|
+
Missing or empty file is not an error; it loads as an empty list.
|
|
17
|
+
Writes are atomic (temp file + ``os.replace``).
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, path: Path) -> None:
|
|
21
|
+
self.path = path
|
|
22
|
+
|
|
23
|
+
def load(self) -> list[str]:
|
|
24
|
+
if not self.path.exists():
|
|
25
|
+
return []
|
|
26
|
+
try:
|
|
27
|
+
raw = json.loads(self.path.read_text(encoding="utf-8"))
|
|
28
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
|
|
29
|
+
return []
|
|
30
|
+
if not isinstance(raw, dict):
|
|
31
|
+
return []
|
|
32
|
+
urls = raw.get("urls")
|
|
33
|
+
if not isinstance(urls, list):
|
|
34
|
+
return []
|
|
35
|
+
return [url for url in urls if isinstance(url, str) and url]
|
|
36
|
+
|
|
37
|
+
def save(self, urls: Iterable[str]) -> None:
|
|
38
|
+
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
39
|
+
file_descriptor, temporary_path = tempfile.mkstemp(
|
|
40
|
+
prefix=f"{self.path.name}.",
|
|
41
|
+
suffix=".tmp",
|
|
42
|
+
dir=self.path.parent,
|
|
43
|
+
)
|
|
44
|
+
try:
|
|
45
|
+
with os.fdopen(file_descriptor, "w", encoding="utf-8") as handle:
|
|
46
|
+
json.dump({"urls": list(urls)}, handle, ensure_ascii=True, indent=2)
|
|
47
|
+
os.replace(temporary_path, self.path)
|
|
48
|
+
except Exception:
|
|
49
|
+
with contextlib.suppress(OSError):
|
|
50
|
+
os.unlink(temporary_path)
|
|
51
|
+
raise
|
|
52
|
+
|
|
53
|
+
def add(self, url: str) -> None:
|
|
54
|
+
urls = self.load()
|
|
55
|
+
if url in urls:
|
|
56
|
+
return
|
|
57
|
+
urls.append(url)
|
|
58
|
+
self.save(urls)
|
workdash/launcher.py
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"""External launcher helpers."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import secrets
|
|
6
|
+
import shlex
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import tempfile
|
|
11
|
+
from collections.abc import Sequence
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, NoReturn
|
|
14
|
+
|
|
15
|
+
import markdown
|
|
16
|
+
|
|
17
|
+
from .models import WorkItem, WorkItemKind, WorkItemType
|
|
18
|
+
|
|
19
|
+
_PROMPTS_DIR = Path(__file__).parent / "prompts"
|
|
20
|
+
_BROWSER_OPEN_COMMANDS = ("xdg-open", "open")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _load_prompt_template(name: str) -> str:
|
|
24
|
+
return (_PROMPTS_DIR / name).read_text(encoding="utf-8")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
_ISSUE_CONTEXT_JSON_FIELDS = (
|
|
28
|
+
"number,title,body,author,assignees,labels,url,state,createdAt,updatedAt"
|
|
29
|
+
)
|
|
30
|
+
_PR_CONTEXT_JSON_FIELDS = (
|
|
31
|
+
"number,title,body,author,assignees,labels,url,state,createdAt,updatedAt,"
|
|
32
|
+
"isDraft,reviewDecision,additions,deletions,changedFiles,headRefName,baseRefName"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _resolve_browser_open_command() -> str:
|
|
37
|
+
for command in _BROWSER_OPEN_COMMANDS:
|
|
38
|
+
if shutil.which(command) is not None:
|
|
39
|
+
return command
|
|
40
|
+
raise RuntimeError("Neither xdg-open nor open is installed or on PATH.")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _run_browser_open(target: str, *, kind: str) -> None:
|
|
44
|
+
command_name = _resolve_browser_open_command()
|
|
45
|
+
try:
|
|
46
|
+
subprocess.run(
|
|
47
|
+
[command_name, target],
|
|
48
|
+
check=True,
|
|
49
|
+
stdout=subprocess.DEVNULL,
|
|
50
|
+
stderr=subprocess.DEVNULL,
|
|
51
|
+
)
|
|
52
|
+
except FileNotFoundError as error:
|
|
53
|
+
raise RuntimeError(f"{command_name} is not installed or not on PATH.") from error
|
|
54
|
+
except subprocess.CalledProcessError as error:
|
|
55
|
+
raise RuntimeError(
|
|
56
|
+
f"Failed to open {kind} via {command_name}: exit code {error.returncode}"
|
|
57
|
+
) from error
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def open_in_browser(url: str) -> None:
|
|
61
|
+
if not isinstance(url, str) or not url.strip():
|
|
62
|
+
raise ValueError("URL must be a non-empty string.")
|
|
63
|
+
_run_browser_open(url, kind="URL")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
_HTML_TEMPLATE = """\
|
|
67
|
+
<!DOCTYPE html>
|
|
68
|
+
<html><head><meta charset="utf-8">
|
|
69
|
+
<title>{title}</title>
|
|
70
|
+
<style>
|
|
71
|
+
body {{ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
|
72
|
+
max-width: 52em; margin: 2em auto; padding: 0 1em; line-height: 1.6; color: #1f2328; }}
|
|
73
|
+
pre {{ background: #f6f8fa; padding: 1em; overflow-x: auto; border-radius: 6px; }}
|
|
74
|
+
code {{ background: #f0f0f0; padding: 0.2em 0.4em; border-radius: 3px; font-size: 0.9em; }}
|
|
75
|
+
pre code {{ background: none; padding: 0; }}
|
|
76
|
+
blockquote {{ border-left: 4px solid #d0d7de; margin: 0; padding: 0.5em 1em; color: #656d76; }}
|
|
77
|
+
table {{ border-collapse: collapse; }} th, td {{ border: 1px solid #d0d7de; padding: 6px 13px; }}
|
|
78
|
+
</style></head>
|
|
79
|
+
<body>{body}</body></html>
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def open_markdown(path: str) -> None:
|
|
84
|
+
"""Render a markdown file to HTML and open it in the browser."""
|
|
85
|
+
|
|
86
|
+
if not isinstance(path, str) or not path.strip():
|
|
87
|
+
raise ValueError("Path must be a non-empty string.")
|
|
88
|
+
md_path = Path(path)
|
|
89
|
+
md_content = md_path.read_text(encoding="utf-8")
|
|
90
|
+
html_body = markdown.markdown(md_content, extensions=["fenced_code", "tables", "codehilite"])
|
|
91
|
+
html = _HTML_TEMPLATE.format(title=md_path.stem, body=html_body)
|
|
92
|
+
html_path = md_path.with_suffix(".html")
|
|
93
|
+
html_path.write_text(html, encoding="utf-8")
|
|
94
|
+
_run_browser_open(str(html_path), kind="file")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _run_launch_command(command: list[str], *, context: str) -> None:
|
|
98
|
+
try:
|
|
99
|
+
subprocess.run(command, check=True, capture_output=True, text=True)
|
|
100
|
+
except FileNotFoundError as error:
|
|
101
|
+
raise RuntimeError(f"{context}: required command '{command[0]}' is not on PATH.") from error
|
|
102
|
+
except subprocess.CalledProcessError as error:
|
|
103
|
+
message = error.stderr.strip() or error.stdout.strip() or str(error)
|
|
104
|
+
raise RuntimeError(f"{context}: {message}") from error
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def exec_zellij_wrapped_workdash(argv: Sequence[str] | None) -> NoReturn:
|
|
108
|
+
zellij = shutil.which("zellij")
|
|
109
|
+
if zellij is None:
|
|
110
|
+
raise RuntimeError(
|
|
111
|
+
"zellij is not installed or not on PATH. "
|
|
112
|
+
"Install it from https://zellij.dev/ or run 'workdash --direct'."
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
original_args = list(argv) if argv is not None else sys.argv[1:]
|
|
116
|
+
session_name = f"workdash-{secrets.token_hex(4)}"
|
|
117
|
+
workdash_command = _build_direct_workdash_command(original_args)
|
|
118
|
+
layout_path = _write_zellij_startup_layout(workdash_command, session_name=session_name)
|
|
119
|
+
command = [zellij, "--layout", layout_path]
|
|
120
|
+
try:
|
|
121
|
+
os.execvp(zellij, command)
|
|
122
|
+
except OSError as error:
|
|
123
|
+
raise RuntimeError(f"failed to start zellij: {error}") from error
|
|
124
|
+
raise AssertionError("os.execvp returned unexpectedly")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _build_direct_workdash_command(original_args: Sequence[str]) -> list[str]:
|
|
128
|
+
current_entrypoint = Path(sys.argv[0])
|
|
129
|
+
if current_entrypoint.name in {"__main__.py", "workdash.py"} and (
|
|
130
|
+
current_entrypoint.parent.name == "workdash"
|
|
131
|
+
):
|
|
132
|
+
return [sys.executable, "-m", "workdash", "--direct", *original_args]
|
|
133
|
+
return [sys.argv[0] or "workdash", "--direct", *original_args]
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _quote_kdl_string(value: str) -> str:
|
|
137
|
+
return '"' + value.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _write_zellij_startup_layout(workdash_command: Sequence[str], *, session_name: str) -> str:
|
|
141
|
+
if not workdash_command:
|
|
142
|
+
raise ValueError("Workdash command must not be empty.")
|
|
143
|
+
if not session_name:
|
|
144
|
+
raise ValueError("Zellij session name must not be empty.")
|
|
145
|
+
|
|
146
|
+
command = _quote_kdl_string(workdash_command[0])
|
|
147
|
+
args = " ".join(_quote_kdl_string(argument) for argument in workdash_command[1:])
|
|
148
|
+
layout = (
|
|
149
|
+
f"session_name {_quote_kdl_string(session_name)}\n"
|
|
150
|
+
'on_force_close "quit"\n'
|
|
151
|
+
"session_serialization false\n"
|
|
152
|
+
"disable_session_metadata true\n"
|
|
153
|
+
"show_startup_tips false\n"
|
|
154
|
+
"attach_to_session false\n"
|
|
155
|
+
"layout {\n"
|
|
156
|
+
' tab name="workdash" {\n'
|
|
157
|
+
f" pane command={command} close_on_exit=true {{\n"
|
|
158
|
+
f" args {args}\n"
|
|
159
|
+
" }\n"
|
|
160
|
+
" }\n"
|
|
161
|
+
"}\n"
|
|
162
|
+
)
|
|
163
|
+
with tempfile.NamedTemporaryFile(
|
|
164
|
+
"w",
|
|
165
|
+
encoding="utf-8",
|
|
166
|
+
prefix="workdash-zellij-",
|
|
167
|
+
suffix=".kdl",
|
|
168
|
+
delete=False,
|
|
169
|
+
) as layout_file:
|
|
170
|
+
layout_file.write(layout)
|
|
171
|
+
return layout_file.name
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _launch_zellij_command(repo_path: str, command: list[str], *, context: str) -> None:
|
|
175
|
+
if not os.getenv("ZELLIJ"):
|
|
176
|
+
raise RuntimeError(
|
|
177
|
+
f"{context}: terminal-backed work actions require an active Zellij session. "
|
|
178
|
+
"Start workdash normally, or run it inside Zellij."
|
|
179
|
+
)
|
|
180
|
+
if shutil.which("zellij") is None:
|
|
181
|
+
raise RuntimeError(
|
|
182
|
+
"zellij is not installed or not on PATH. Download it from https://zellij.dev"
|
|
183
|
+
)
|
|
184
|
+
_run_launch_command(
|
|
185
|
+
["zellij", "action", "new-pane", "--cwd", repo_path, "--", *command],
|
|
186
|
+
context=context,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _run_gh_context_command(*, item: WorkItem, command: list[str]) -> dict[str, Any]:
|
|
191
|
+
try:
|
|
192
|
+
completed = subprocess.run(
|
|
193
|
+
command,
|
|
194
|
+
check=True,
|
|
195
|
+
capture_output=True,
|
|
196
|
+
text=True,
|
|
197
|
+
)
|
|
198
|
+
except FileNotFoundError as error:
|
|
199
|
+
raise RuntimeError(
|
|
200
|
+
"Failed to gather launch context with gh: gh CLI is not installed or not on PATH."
|
|
201
|
+
) from error
|
|
202
|
+
except subprocess.CalledProcessError as error:
|
|
203
|
+
stderr = (error.stderr or "").strip()
|
|
204
|
+
raise RuntimeError(
|
|
205
|
+
f"Failed to gather launch context for {item.item_type.value} "
|
|
206
|
+
f"{item.repo}#{item.number}: "
|
|
207
|
+
f"{stderr or f'process exited with code {error.returncode}'}"
|
|
208
|
+
) from error
|
|
209
|
+
try:
|
|
210
|
+
payload = json.loads(completed.stdout)
|
|
211
|
+
except json.JSONDecodeError as error:
|
|
212
|
+
raise RuntimeError(
|
|
213
|
+
f"Failed to parse launch context JSON for {item.item_type.value} "
|
|
214
|
+
f"{item.repo}#{item.number}: {error.msg}"
|
|
215
|
+
) from error
|
|
216
|
+
if not isinstance(payload, dict):
|
|
217
|
+
raise RuntimeError(
|
|
218
|
+
f"Invalid launch context payload for {item.item_type.value} "
|
|
219
|
+
f"{item.repo}#{item.number}: expected a JSON object."
|
|
220
|
+
)
|
|
221
|
+
return payload
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def collect_launch_github_context(item: WorkItem) -> dict[str, Any]:
|
|
225
|
+
"""Collect key GitHub context for launching an interactive Codex session."""
|
|
226
|
+
|
|
227
|
+
if item.item_type == WorkItemType.ISSUE:
|
|
228
|
+
return _run_gh_context_command(
|
|
229
|
+
item=item,
|
|
230
|
+
command=[
|
|
231
|
+
"gh",
|
|
232
|
+
"issue",
|
|
233
|
+
"view",
|
|
234
|
+
str(item.number),
|
|
235
|
+
"--repo",
|
|
236
|
+
item.repo,
|
|
237
|
+
"--json",
|
|
238
|
+
_ISSUE_CONTEXT_JSON_FIELDS,
|
|
239
|
+
],
|
|
240
|
+
)
|
|
241
|
+
return _run_gh_context_command(
|
|
242
|
+
item=item,
|
|
243
|
+
command=[
|
|
244
|
+
"gh",
|
|
245
|
+
"pr",
|
|
246
|
+
"view",
|
|
247
|
+
str(item.number),
|
|
248
|
+
"--repo",
|
|
249
|
+
item.repo,
|
|
250
|
+
"--json",
|
|
251
|
+
_PR_CONTEXT_JSON_FIELDS,
|
|
252
|
+
],
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def build_launch_agent_prompt(
|
|
257
|
+
*,
|
|
258
|
+
item: WorkItem,
|
|
259
|
+
github_context: dict[str, Any],
|
|
260
|
+
repo_path: str,
|
|
261
|
+
analysis_path: str | None = None,
|
|
262
|
+
merge_base: str | None = None,
|
|
263
|
+
) -> str:
|
|
264
|
+
"""Build the initial interactive launch prompt for a coding agent."""
|
|
265
|
+
|
|
266
|
+
if not isinstance(repo_path, str) or not repo_path.strip():
|
|
267
|
+
raise ValueError("Repository path must be a non-empty string.")
|
|
268
|
+
if not isinstance(github_context, dict):
|
|
269
|
+
raise ValueError("GitHub context must be a JSON object.")
|
|
270
|
+
|
|
271
|
+
if item.kind == WorkItemKind.REVIEW_REQUESTED_PR:
|
|
272
|
+
template_name = "launch_review.txt"
|
|
273
|
+
elif item.item_type == WorkItemType.ISSUE:
|
|
274
|
+
template_name = "launch_issue.txt"
|
|
275
|
+
else:
|
|
276
|
+
template_name = "launch_pr.txt"
|
|
277
|
+
|
|
278
|
+
analysis_section = ""
|
|
279
|
+
if analysis_path:
|
|
280
|
+
analysis_section = (
|
|
281
|
+
"\nPREVIOUS ANALYSIS:\n"
|
|
282
|
+
f"A previous analysis of this work item is available at: {analysis_path}\n"
|
|
283
|
+
"Read it before proceeding — it contains summary, context, and recommendations\n"
|
|
284
|
+
"that will help you get started faster.\n"
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
merge_base_line = ""
|
|
288
|
+
if merge_base:
|
|
289
|
+
merge_base_line = (
|
|
290
|
+
f"\n- git merge-base: {merge_base}"
|
|
291
|
+
"\n- use this as the diff target to see only this branch's changes:"
|
|
292
|
+
f" git diff {merge_base}..HEAD"
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
template = _load_prompt_template(template_name)
|
|
296
|
+
return template.format(
|
|
297
|
+
item_type=item.item_type.value,
|
|
298
|
+
kind=item.kind.value,
|
|
299
|
+
repo=item.repo,
|
|
300
|
+
number=item.number,
|
|
301
|
+
title=item.title,
|
|
302
|
+
url=item.url,
|
|
303
|
+
repo_path=repo_path,
|
|
304
|
+
analysis_section=analysis_section,
|
|
305
|
+
merge_base_section=merge_base_line,
|
|
306
|
+
github_context_json=json.dumps(github_context, ensure_ascii=True, indent=2, sort_keys=True),
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def prepare_launch_agent_prompt(
|
|
311
|
+
item: WorkItem,
|
|
312
|
+
repo_path: str,
|
|
313
|
+
analysis_path: str | None = None,
|
|
314
|
+
merge_base: str | None = None,
|
|
315
|
+
) -> str:
|
|
316
|
+
"""Collect GitHub context and return the launch prompt text for a coding agent."""
|
|
317
|
+
|
|
318
|
+
return build_launch_agent_prompt(
|
|
319
|
+
item=item,
|
|
320
|
+
github_context=collect_launch_github_context(item),
|
|
321
|
+
repo_path=repo_path,
|
|
322
|
+
analysis_path=analysis_path,
|
|
323
|
+
merge_base=merge_base,
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def launch_agent_context(
|
|
328
|
+
repo_path: str,
|
|
329
|
+
prompt: str,
|
|
330
|
+
agent_command_tokens: list[str] | None = None,
|
|
331
|
+
) -> None:
|
|
332
|
+
if not isinstance(repo_path, str) or not repo_path.strip():
|
|
333
|
+
raise ValueError("Repository path must be a non-empty string.")
|
|
334
|
+
if not isinstance(prompt, str) or not prompt.strip():
|
|
335
|
+
raise ValueError("Prompt must be a non-empty string.")
|
|
336
|
+
|
|
337
|
+
command_tokens = agent_command_tokens if agent_command_tokens is not None else ["codex"]
|
|
338
|
+
if not command_tokens or any(
|
|
339
|
+
not isinstance(token, str) or not token.strip() for token in command_tokens
|
|
340
|
+
):
|
|
341
|
+
raise ValueError("Agent command tokens must be a non-empty list of non-empty strings.")
|
|
342
|
+
user_shell = os.environ.get("SHELL", "/bin/sh")
|
|
343
|
+
agent_command = [user_shell, "-ic", shlex.join([*command_tokens, prompt])]
|
|
344
|
+
_launch_zellij_command(
|
|
345
|
+
repo_path,
|
|
346
|
+
agent_command,
|
|
347
|
+
context="Failed to launch coding agent in zellij",
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def launch_vscode_context(repo_path: str, prompt: str) -> None:
|
|
352
|
+
"""Open VSCode on the repository and start a Copilot chat session."""
|
|
353
|
+
if not isinstance(repo_path, str) or not repo_path.strip():
|
|
354
|
+
raise ValueError("Repository path must be a non-empty string.")
|
|
355
|
+
if not isinstance(prompt, str) or not prompt.strip():
|
|
356
|
+
raise ValueError("Prompt must be a non-empty string.")
|
|
357
|
+
_run_launch_command(
|
|
358
|
+
["code", "--new-window", repo_path],
|
|
359
|
+
context="Failed to open VSCode",
|
|
360
|
+
)
|
|
361
|
+
_run_launch_command(
|
|
362
|
+
["code", "chat", prompt, "--reuse-window"],
|
|
363
|
+
context="Failed to start Copilot chat",
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def launch_terminal_context(repo_path: str) -> None:
|
|
368
|
+
"""Open a terminal in zellij rooted at the given repository path."""
|
|
369
|
+
|
|
370
|
+
if not isinstance(repo_path, str) or not repo_path.strip():
|
|
371
|
+
raise ValueError("Repository path must be a non-empty string.")
|
|
372
|
+
user_shell = os.environ.get("SHELL", "/bin/sh")
|
|
373
|
+
shell_command = [user_shell, "-i"]
|
|
374
|
+
_launch_zellij_command(
|
|
375
|
+
repo_path,
|
|
376
|
+
shell_command,
|
|
377
|
+
context="Failed to launch terminal in zellij",
|
|
378
|
+
)
|
workdash/models.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Shared data models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from enum import StrEnum
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class WorkItemType(StrEnum):
|
|
11
|
+
"""GitHub object types shown in workdash."""
|
|
12
|
+
|
|
13
|
+
ISSUE = "issue"
|
|
14
|
+
PR = "pr"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class WorkItemKind(StrEnum):
|
|
18
|
+
"""Work categories shown in workdash."""
|
|
19
|
+
|
|
20
|
+
AUTHORED_PR = "authored_pr"
|
|
21
|
+
REVIEW_REQUESTED_PR = "review_requested_pr"
|
|
22
|
+
ASSIGNED_ISSUE = "assigned_issue"
|
|
23
|
+
TRACKED_PR = "tracked_pr"
|
|
24
|
+
TRACKED_ISSUE = "tracked_issue"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(slots=True)
|
|
28
|
+
class WorkItem:
|
|
29
|
+
"""Normalized dashboard row model."""
|
|
30
|
+
|
|
31
|
+
kind: WorkItemKind
|
|
32
|
+
item_type: WorkItemType
|
|
33
|
+
repo: str
|
|
34
|
+
number: int
|
|
35
|
+
title: str
|
|
36
|
+
created_at: datetime
|
|
37
|
+
updated_at: datetime
|
|
38
|
+
url: str
|
|
39
|
+
analysis: str | None = None
|
|
40
|
+
analyzed_at: datetime | None = None
|
|
41
|
+
included: bool = False
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def format_type_label(item: WorkItem) -> str:
|
|
45
|
+
"""Return the type column label for ``item`` including the ``+`` include suffix."""
|
|
46
|
+
|
|
47
|
+
base = (
|
|
48
|
+
"REVIEW" if item.kind == WorkItemKind.REVIEW_REQUESTED_PR else item.item_type.value.upper()
|
|
49
|
+
)
|
|
50
|
+
return f"{base}+" if item.included else base
|
|
File without changes
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
You are analyzing a GitHub issue to map out what is being asked, trace the
|
|
2
|
+
relevant behavior back to the code, and surface the context needed for a later
|
|
3
|
+
design discussion between developer and coding agent.
|
|
4
|
+
|
|
5
|
+
Use only the provided metadata and discussion context. Do not invent facts, code,
|
|
6
|
+
or history that is not present in the input. Your goal is exploration and
|
|
7
|
+
grounding, not solution design. Do not propose a specific implementation, API, or
|
|
8
|
+
code change — that conversation happens separately, informed by this analysis.
|
|
9
|
+
|
|
10
|
+
If the issue lacks enough detail to understand the ask or trace involved code,
|
|
11
|
+
say so explicitly rather than guessing.
|
|
12
|
+
|
|
13
|
+
TASK:
|
|
14
|
+
|
|
15
|
+
1. Understand the request — What does the user want or need? If it is a bug
|
|
16
|
+
report, what exactly is the reported behavior versus the expected behavior?
|
|
17
|
+
If it is a feature request, what outcome is the requester after? Distill the
|
|
18
|
+
core ask from the issue description and any follow-up discussion.
|
|
19
|
+
|
|
20
|
+
2. Map the involved code — Identify the subsystems, files, functions, types, or
|
|
21
|
+
components the issue touches. For bug reports, focus on the code that produces
|
|
22
|
+
the observed behavior. For feature requests, focus on the code that would need
|
|
23
|
+
to change or be extended and where the new behavior would fit. Only name code
|
|
24
|
+
whose location is evident from the issue metadata or discussion; do not invent
|
|
25
|
+
paths.
|
|
26
|
+
|
|
27
|
+
3. Trace cause or motivation — For bugs, explain what in the current code path
|
|
28
|
+
most plausibly produces the observed behavior, based on the discussion and any
|
|
29
|
+
references to commits, PRs, or prior issues. For features, explain the gap
|
|
30
|
+
between current behavior and what is requested, and why existing code does
|
|
31
|
+
not already cover the case. Reference past issues, commits, or design
|
|
32
|
+
decisions visible in the thread when they explain current behavior.
|
|
33
|
+
|
|
34
|
+
4. Surface tensions and open questions — Are there reasons the current behavior
|
|
35
|
+
might be intentional? Does the request align with the project's stated
|
|
36
|
+
direction, constraints, or best practices? What information is missing that a
|
|
37
|
+
developer or agent would need before deciding what to do? Call out concerns
|
|
38
|
+
without resolving them.
|
|
39
|
+
|
|
40
|
+
OUTPUT:
|
|
41
|
+
|
|
42
|
+
Produce a Markdown document with exactly these sections. Write substantive
|
|
43
|
+
content in each section, not placeholders.
|
|
44
|
+
The output MUST be valid, well-formed CommonMark Markdown.
|
|
45
|
+
When using lists, use valid Markdown list syntax (`1.` for ordered lists or `-`
|
|
46
|
+
for bullets) and leave a blank line before the first list item.
|
|
47
|
+
|
|
48
|
+
Whenever you mention a specific struct, type, class, interface, function, method,
|
|
49
|
+
or file from the repository — in ANY section of the document — wrap it in a
|
|
50
|
+
Markdown link that points to the definition on GitHub using the default branch.
|
|
51
|
+
- Preferred format: [`StructName`](https://github.com/{repo}/blob/main/path/to/file.go#L42)
|
|
52
|
+
- For file+line references: [`path/to/file.py:123`](https://github.com/{repo}/blob/main/path/to/file.py#L123)
|
|
53
|
+
- For line ranges: `#L10-L20`
|
|
54
|
+
- Keep backtick formatting around the symbol name — the link wraps the backticked text.
|
|
55
|
+
- Only link symbols whose file path and location are evident from the issue
|
|
56
|
+
discussion or metadata. Do not fabricate paths or line numbers.
|
|
57
|
+
- If you cannot determine the exact file or line for a symbol, you may still
|
|
58
|
+
mention it in backticks without a link, but prefer linked references when
|
|
59
|
+
the information is available.
|
|
60
|
+
|
|
61
|
+
Output the Markdown document directly. Your response must begin with the `# `
|
|
62
|
+
heading shown below and end with the last line of the template. Do not wrap
|
|
63
|
+
your response in code fences, do not include the `<template>` tags themselves,
|
|
64
|
+
and do not add any preamble or trailing commentary.
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
# {title}
|
|
68
|
+
|
|
69
|
+
> [{repo}#{number}]({url})
|
|
70
|
+
|
|
71
|
+
## Summary
|
|
72
|
+
|
|
73
|
+
One paragraph: what the issue asks for or reports, and why it matters.
|
|
74
|
+
|
|
75
|
+
## Context & Background
|
|
76
|
+
|
|
77
|
+
Current behavior and why it works that way. Relevant area of the codebase in
|
|
78
|
+
prose. References to past issues, commits, or design decisions visible in the
|
|
79
|
+
discussion. Any history that shapes how this issue should be read.
|
|
80
|
+
|
|
81
|
+
## Root Cause / Motivation
|
|
82
|
+
|
|
83
|
+
For a bug: the most plausible explanation, grounded in the discussion, for what
|
|
84
|
+
in the current code path produces the reported behavior. For a feature request
|
|
85
|
+
or change: the gap between current behavior and what is requested, and why the
|
|
86
|
+
existing code does not already cover the case.
|
|
87
|
+
|
|
88
|
+
## Code Paths Involved
|
|
89
|
+
|
|
90
|
+
The concrete files, functions, types, or components the issue touches. Use
|
|
91
|
+
GitHub-linked references per the rules above. Group related entries and briefly
|
|
92
|
+
explain each one's role in the behavior under discussion. If the issue does not
|
|
93
|
+
pin down exact locations, say so and describe the involved area at the level of
|
|
94
|
+
granularity the discussion supports.
|
|
95
|
+
|
|
96
|
+
## Evaluation
|
|
97
|
+
|
|
98
|
+
Alignment with project goals and best practices. Reasons the current behavior
|
|
99
|
+
might be intentional. Trade-offs a later design discussion will have to weigh.
|
|
100
|
+
Do not propose a specific implementation here.
|
|
101
|
+
|
|
102
|
+
## Open Questions
|
|
103
|
+
|
|
104
|
+
Anything unclear, needing author clarification, or requiring further
|
|
105
|
+
investigation before design work can begin. Omit this section entirely if there
|
|
106
|
+
are none.
|
|
107
|
+
</template>
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
WORK ITEM:
|
|
112
|
+
- type: {item_type}
|
|
113
|
+
- kind: {kind}
|
|
114
|
+
- repo: {repo}
|
|
115
|
+
- number: {number}
|
|
116
|
+
- title: {title}
|
|
117
|
+
- url: {url}
|
|
118
|
+
|
|
119
|
+
GITHUB CONTEXT:
|
|
120
|
+
{github_context_json}
|